Browse Source

Merge branch 'develop'

master
Fab 4 years ago
parent
commit
d63e8c9636
4 changed files with 89 additions and 16 deletions
  1. +20
    -0
      ShopBundle/Repository/OrderShopRepository.php
  2. +1
    -0
      ShopBundle/Resources/translations/lcshop.fr.yaml
  3. +7
    -6
      ShopBundle/Resources/views/backend/default/block/form_address.html.twig
  4. +61
    -10
      ShopBundle/Services/CsvGenerator.php

+ 20
- 0
ShopBundle/Repository/OrderShopRepository.php View File

@@ -120,6 +120,10 @@ class OrderShopRepository extends BaseRepository implements DefaultRepositoryInt
$query->select('count(e.id)');
}

if (isset($params['select'])) {
$query->select( $params['select']);
}

if (isset($params['dateStart']) || isset($params['dateEnd'])) {
$params['dateField'] = isset($params['dateField']) ? $params['dateField'] : 'validationDate';
}
@@ -161,6 +165,18 @@ class OrderShopRepository extends BaseRepository implements DefaultRepositoryInt
$query->andWhere('e.deliveryAddress = :address OR e.invoiceAddress = :address')->setParameter('address', $params['address']);
}

if(isset($params['weekDeliveryTruck'])) {
$query->andWhere('e.weekDeliveryTruck = :weekDeliveryTruck')->setParameter('weekDeliveryTruck', $params['weekDeliveryTruck']);
}

if(isset($params['deliveryDate'])) {
$query->andWhere('e.deliveryDate >= :deliveryDateStart');
$query->andWhere('e.deliveryDate < :deliveryDateEnd');
$date = clone $params['deliveryDate'];
$query->setParameter('deliveryDateStart', $date->format('Y-m-d 00:00:00'));
$query->setParameter('deliveryDateEnd', $date->modify('+1 day')->format('Y-m-d 00:00:00'));
}

if (isset($params['mergeComplementaryOrderShops'])) {
$query->andWhere('e.mainOrderShop IS NULL');
$query->leftJoin('e.complementaryOrderShops', 'complementaryOrderShops');
@@ -229,6 +245,10 @@ class OrderShopRepository extends BaseRepository implements DefaultRepositoryInt
}


if (isset($params['groupBy'])) {
$query->groupBy( $params['groupBy']);
}

if (isset($params['count']) && $params['count']) {
return $query->getQuery()->getSingleScalarResult();
} else {

+ 1
- 0
ShopBundle/Resources/translations/lcshop.fr.yaml View File

@@ -381,6 +381,7 @@ field:
quantityProduct: Quantité (en rapport à l'unité)
unit: Unité
OrderShop:
deliveryTruck: Véhicule de livraison
createdAt: Date de création
updatedAt: Date de modification
save: Sauvegarder

+ 7
- 6
ShopBundle/Resources/views/backend/default/block/form_address.html.twig View File

@@ -45,17 +45,18 @@
<div class="col-6">
{{ form_row(form.tva) }}
</div>
<div class="col-6">
{{ form_row(form.latitude) }}
</div>
<div class="col-6">
{{ form_row(form.longitude) }}
</div>

</div>
</div>
<div class="col-12">
{{ form_row(form.deliveryInfos) }}
</div>
<div class="col-6">
{{ form_row(form.latitude) }}
</div>
<div class="col-6">
{{ form_row(form.longitude) }}
</div>

{{ form_row(form.country) }}


+ 61
- 10
ShopBundle/Services/CsvGenerator.php View File

@@ -16,33 +16,84 @@ use Lc\ShopBundle\Context\UserPointSaleInterface;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\HttpFoundation\ParameterBag;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\HttpFoundation\StreamedResponse;
use Symfony\Contracts\Translation\TranslatorInterface;

class CsvGenerator
{
protected $em ;
protected $parameterBag ;
protected $merchantUtils ;
protected $session;
protected $translator;
protected $configManager;

protected $arrayToExport;
protected $columns;
protected $titleDocument;


public function __construct()
{
$this->arrayToExport = array();
$this->titleDocument = 'csv_file';
}

public function setTitle($title, $displayHeader = false){

$this->titleDocument = $this->formatTitle($title);

if($displayHeader){
array_unshift($this->arrayToExport, array(''));
array_unshift($this->arrayToExport, array($title));
}
}

public function setColumns($columns, $displayLegend = true){
$this->columns =array_fill_keys(array_keys($columns), null);;
if($displayLegend)$this->arrayToExport[] = $columns;
}

public function cell($column, $value){
$this->arrayToExport[] = array_merge($this->columns, array($column =>$value));
}

public function setColumns($columns){
$this->columns = $columns;
public function row($values = null, $row = false){

if(!$row){
if($values)$this->arrayToExport[] = array_merge($this->columns, $values);
else $this->arrayToExport[] = array();
}else{
if($values)$this->arrayToExport[$row] = array_merge($this->columns, $values);
else $this->arrayToExport[$row] = array();
}

}

public function setCell($row, $column, $value){
$this->arrayToExport[$row][$column] = $value;
public function dump(){
dump($this->arrayToExport);
}

public function getReponse(){
$response = new StreamedResponse(function () {
$handle = fopen('php://output', 'r+');

foreach ($this->arrayToExport as $line) {
fputcsv($handle, $line, ';', ' ');
}
fclose($handle);
});

$response->headers->set('Content-Type', 'application/force-download');
$response->headers->set('Content-Disposition', 'attachment; filename="'.$this->titleDocument.'.csv"');
return $response;
}
private function formatTitle($str) {
$str = str_replace("-", ' ', $str);
$str = preg_replace('/\s+/', '_',$str);;
//$str = str_replace(" ", '_', $str);
$str = iconv('UTF-8', 'ASCII//TRANSLIT', $str);

return $str;
}






}

Loading…
Cancel
Save