Parcourir la source

Merge branch 'develop'

master
Guillaume il y a 4 ans
Parent
révision
3aeedbd323
8 fichiers modifiés avec 134 ajouts et 54 suppressions
  1. +1
    -37
      ShopBundle/Controller/Backend/ProductFamilyController.php
  2. +5
    -1
      ShopBundle/Resources/translations/lcshop.fr.yaml
  3. +7
    -0
      ShopBundle/Resources/views/backend/default/list.html.twig
  4. +2
    -4
      ShopBundle/Resources/views/backend/productfamily/panel_stock.html.twig
  5. +58
    -11
      ShopBundle/Services/CsvGenerator.php
  6. +12
    -1
      ShopBundle/Services/Price/OrderProductPriceUtils.php
  7. +10
    -0
      ShopBundle/Services/Price/OrderShopPriceUtils.php
  8. +39
    -0
      ShopBundle/Services/Utils.php

+ 1
- 37
ShopBundle/Controller/Backend/ProductFamilyController.php Voir le fichier

@@ -331,7 +331,7 @@ class ProductFamilyController extends AdminController
'entity' => $entity,
'delete_form' => $deleteForm->createView(),
'sortableProductsField' => $sortableProductsField,
'totalProductOrdered' => $this->getTotalProductOrdered($entity)
'totalProductOrdered' => $this->orderUtils->getTotalProductOrderedLastWeeks($entity)
];

return $this->executeDynamicMethod('render<EntityName>Template', ['edit', $this->entity['templates']['edit'], $parameters]);
@@ -413,42 +413,6 @@ class ProductFamilyController extends AdminController
}


public function getTotalProductOrdered($entity)
{
$orderShopRepo = $this->em->getRepository(OrderShopInterface::class);
$totalProductOrdered = array();
$currentWeekNumber = $this->orderUtils->getWeekNumberCurrentOrder();
$totalProductOrdered['total'][$currentWeekNumber +1] = 0;
$totalProductOrdered['total'][$currentWeekNumber ] = 0;

foreach ($entity->getProducts() as $product) {
//Les commandes sont ouvertes ont récupèrent les commandes en cours et celle de la semaine dernière
if ($this->orderUtils->isOpenSale()) {
$totalProductOrdered[$product->getId()][$currentWeekNumber +1] = $orderShopRepo->countValidOrderProductsOfWeekByProduct($currentWeekNumber +1, $product->getId());
$totalProductOrdered[$product->getId()][$currentWeekNumber] = $orderShopRepo->countValidOrderProductsOfWeekByProduct($currentWeekNumber, $product->getId());

if ($entity->getBehaviorCountStock() == ProductFamily::BEHAVIOR_COUNT_STOCK_BY_MEASURE) {
$ratioByMeasure = $product->getQuantity() / $product->getUnitInherited()->getCoefficient();
$totalProductOrdered['total'][$currentWeekNumber +1] += $orderShopRepo->countValidOrderProductsOfWeekByProduct($currentWeekNumber +1, $product->getId()) * $ratioByMeasure;
$totalProductOrdered['total'][$currentWeekNumber] += $orderShopRepo->countValidOrderProductsOfWeekByProduct($currentWeekNumber, $product->getId()) * $ratioByMeasure;
} else {
$totalProductOrdered['total'][$currentWeekNumber +1] += $orderShopRepo->countValidOrderProductsOfWeekByProduct($currentWeekNumber+1, $product->getId());
$totalProductOrdered['total'][$currentWeekNumber] += $orderShopRepo->countValidOrderProductsOfWeekByProduct($currentWeekNumber, $product->getId());
}

} else {
$totalProductOrdered[$product->getId()][$currentWeekNumber +1] = $orderShopRepo->countValidOrderProductsOfWeekByProduct($currentWeekNumber+1, $product->getId());
if ($entity->getBehaviorCountStock() == ProductFamily::BEHAVIOR_COUNT_STOCK_BY_MEASURE) {
$ratioByMeasure = $product->getQuantity() / $product->getUnitInherited()->getCoefficient();
$totalProductOrdered['total'][$currentWeekNumber+1] += $orderShopRepo->countValidOrderProductsOfWeekByProduct($currentWeekNumber+1, $product->getId()) * $ratioByMeasure;
}else{
$totalProductOrdered['total'][$currentWeekNumber+1] += $orderShopRepo->countValidOrderProductsOfWeekByProduct($currentWeekNumber+1, $product->getId());
}
}

}
return $totalProductOrdered;
}

}


+ 5
- 1
ShopBundle/Resources/translations/lcshop.fr.yaml Voir le fichier

@@ -223,6 +223,7 @@ field:
isPublic: Publique
isDepository: Dépôt
productCategories: Catégories
currentStock: Stock en cours
category: Catégorie
parent: Parent
date: Date
@@ -286,7 +287,9 @@ field:
priceByRefUnit: Prix de vente / unité de référence
buyingPriceByRefUnit: Prix d'achat / unité de référence
availableQuantity: Quantité disponible
availableQuantityDefault: Quantité disponible par défaut
currentStock: Stock actuel
totalOrdered: Historique des commandes
availableQuantityDefault: Quantité par défaut
quantity: Quantité
behaviorCountStock: Gestion du stock
differentSupplierTaxRate: TVA différente pour le producteur
@@ -335,6 +338,7 @@ field:
exportNote: Note à l'export
quantityLabel: Label quantité
quantityLabelHelp: Volumes / Poids .. (utiliser dans les caractéristiques du produit)
actions: Actions
Reduction:
usersActive: Filtrer sur les utilisateurs
groupUsersActive: Filtrer sur les groupes d'utilisateurs

+ 7
- 0
ShopBundle/Resources/views/backend/default/list.html.twig Voir le fichier

@@ -141,6 +141,13 @@
</a>
{% endif %}

{% if _entity_config['list']['btn_download_purchase_order_archive'] is defined %}
<a class="float-right btn-sm btn-success"
href="{{ path('easyadmin', { entity: 'Supplier', action: 'exportOrderPurchasesAsArchive' }) }}">
<i class="fa fa-download"></i> Télécharger tous les bons de commande
</a>
{% endif %}

{% if _entity_config['list']['edit_position'] is defined %}
<a class="float-right btn-sm btn-success action-sort"
href="{{ path('easyadmin', _request_parameters|merge({ action: 'sort' })) }}">

+ 2
- 4
ShopBundle/Resources/views/backend/productfamily/panel_stock.html.twig Voir le fichier

@@ -61,10 +61,8 @@
{{ form_help(form.availableQuantityDefault) }}
</div>
</div>
<p v-show="behaviorCountStock == '{{ constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY') }}' ">
{% for quantityProductsOrder in totalProductOrdered %}
{{ product_family_macros.total_order_product(quantityProductsOrder) }}
{% endfor %}
<p v-show="behaviorCountStock == '{{ constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY') }}' || behaviorCountStock == '{{ constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_COUNT_STOCK_BY_MEASURE') }}' ">
{{ product_family_macros.total_order_product_family(totalProductOrdered['total'], entity) }}
</p>
</div>


+ 58
- 11
ShopBundle/Services/CsvGenerator.php Voir le fichier

@@ -26,34 +26,72 @@ class CsvGenerator
protected $columns;
protected $titleDocument;

protected $convertEncoding ;
protected $fromEncoding ;
protected $toEncoding ;


public function __construct()
{
$this->arrayToExport = array();
$this->titleDocument = 'csv_file';
$this->convertEncoding = false ;
$this->fromEncoding = 'UTF-8' ;
$this->toEncoding = 'ISO-8859-1' ;
}

public function enableConvertEncoding($toEncoding, $fromEncoding = null)
{
$this->convertEncoding = true ;
$this->toEncoding = $toEncoding ;

if(!is_null($fromEncoding)) {
$this->fromEncoding = $fromEncoding ;
}
}

public function encode($value)
{
if($this->convertEncoding) {
return mb_convert_encoding($value, $this->toEncoding, $this->fromEncoding) ;
}

return $value ;
}

public function encodeArray($array)
{
return array_map(function($value) {
return $this->encode($value) ;
}, $array) ;
}

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

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

if($displayHeader){
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 setColumns($columns, $displayLegend = true) {
$this->columns = array_fill_keys(array_keys($columns), null);
if($displayLegend) $this->row($columns);
}

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

public function row($values = null, $row = false){

$values = $this->encodeArray($values) ;

if(!$row){
if($values)$this->arrayToExport[] = array_merge($this->columns, $values);
else $this->arrayToExport[] = array();
@@ -61,21 +99,30 @@ class CsvGenerator
if($values)$this->arrayToExport[$row] = array_merge($this->columns, $values);
else $this->arrayToExport[$row] = array();
}
}

public function emptyRow()
{
$this->row([]) ;
}

public function dump(){
dump($this->arrayToExport);
}

public function createCsv($path)
{
$handle = fopen($path, 'w+');

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

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

foreach ($this->arrayToExport as $line) {
fputcsv($handle, $line, ';', ' ');
}
fclose($handle);
$this->createCsv('php://output');
});

$response->headers->set('Content-Type', 'application/force-download');

+ 12
- 1
ShopBundle/Services/Price/OrderProductPriceUtils.php Voir le fichier

@@ -68,7 +68,10 @@ class OrderProductPriceUtils
return $orderProduct->getQuantityOrder() * $this->getPrice($orderProduct);
}


public function getTotalBuyingPrice(OrderProductInterface $orderProduct)
{
return $orderProduct->getQuantityOrder() * $this->getBuyingPrice($orderProduct);
}

public function getMargin(OrderProductInterface $orderProduct)
{
@@ -120,6 +123,14 @@ class OrderProductPriceUtils
);
}

public function getTotalBuyingPriceWithTax(OrderProductInterface $orderProduct)
{
return $this->applyTax(
$this->getTotalBuyingPrice($orderProduct),
$orderProduct->getTaxRateInherited()->getValue()
);
}

//inclus toujours les réductions catalogues
public function getTotalTaxes(OrderProductInterface $orderProduct){
return $this->getTotalWithTaxAndReduction($orderProduct) - $this->getTotalWithReduction($orderProduct);

+ 10
- 0
ShopBundle/Services/Price/OrderShopPriceUtils.php Voir le fichier

@@ -49,6 +49,16 @@ class OrderShopPriceUtils implements OrderShopPriceUtilsInterface
return $this->getTotalOrderProductsWithTaxByOrderProducts($orderShop->getOrderProducts()) ;
}

public function getTotalBuyingPriceOrderProductsWithTax($orderProducts):float
{
$total = 0;

foreach ($orderProducts as $orderProduct) {
$total += $this->orderProductPriceUtils->getTotalBuyingPriceWithTax($orderProduct);
}

return $total;
}

public function getTotalOrderProductsWithTaxByOrderProducts($orderProducts):float
{

+ 39
- 0
ShopBundle/Services/Utils.php Voir le fichier

@@ -394,4 +394,43 @@ class Utils
}
return $reminders;
}

public function removeDir($dir) {
$files = array_diff(scandir($dir), array('.','..'));
foreach ($files as $file) {
(is_dir("$dir/$file")) ? $this->removeDir("$dir/$file") : unlink("$dir/$file");
}
return rmdir($dir);
}

function folderToZip($folder, &$zipFile, $subfolder = null) {
if ($zipFile == null) {
// no resource given, exit
return false;
}
// we check if $folder has a slash at its end, if not, we append one
$tabFolder = str_split($folder) ;
$tabSubFolder = str_split($subfolder) ;
$folder .= end($tabFolder) == "/" ? "" : "/";
$subfolder .= end($tabSubFolder) == "/" ? "" : "/";
// we start by going through all files in $folder
$handle = opendir($folder);
while ($f = readdir($handle)) {
if ($f != "." && $f != "..") {
if (is_file($folder . $f)) {
// if we find a file, store it
// if we have a subfolder, store it there
if ($subfolder != null)
$zipFile->addFile($folder . $f, $subfolder . $f);
else
$zipFile->addFile($folder . $f);
} elseif (is_dir($folder . $f)) {
// if we find a folder, create a folder in the zip
$zipFile->addEmptyDir($f);
// and call the function again
folderToZip($folder . $f, $zipFile, $f);
}
}
}
}
}

Chargement…
Annuler
Enregistrer