ソースを参照

[Administration] Distribution > export commandes CSV #1352

feature/souke
Guillaume Bourgeois 1年前
コミット
790dc6aa98
8個のファイルの変更130行の追加59行の削除
  1. +3
    -3
      common/components/BusinessLogic.php
  2. +7
    -1
      common/helpers/CSV.php
  3. +26
    -24
      common/logic/Distribution/Distribution/Service/DistributionReport2CsvGenerator.php
  4. +1
    -1
      common/logic/Distribution/Distribution/Service/DistributionReportCsvGenerator.php
  5. +1
    -1
      common/logic/Distribution/Distribution/Service/DistributionReportTotalProductCsvGenerator.php
  6. +37
    -23
      common/logic/Order/Order/Service/OrderSolver.php
  7. +44
    -3
      common/logic/Order/ProductOrder/Service/ProductOrderSolver.php
  8. +11
    -3
      common/logic/Product/Product/Service/ProductSolver.php

+ 3
- 3
common/components/BusinessLogic.php ファイルの表示

$this->getProductDistributionModule(), $this->getProductDistributionModule(),
$this->getProductCategoryModule(), $this->getProductCategoryModule(),
$this->getProductPointSaleModule(), $this->getProductPointSaleModule(),
$this->getProductOrderModule(),
$this->getProductPriceModule(), $this->getProductPriceModule(),
$this->getProductSubscriptionModule(), $this->getProductSubscriptionModule(),
$this->getTicketUserModule(), $this->getTicketUserModule(),
$this->getTicketMessageModule(), $this->getTicketMessageModule(),
$this->getTicketModule(), $this->getTicketModule(),
$this->getPointSaleModule(),
$this->getProductModule(),
$this->getProductOrderModule(),
$this->getQuotationModule(), $this->getQuotationModule(),
$this->getInvoiceModule(), $this->getInvoiceModule(),
$this->getDeliveryNoteModule(), $this->getDeliveryNoteModule(),
$this->getDocumentModule(), $this->getDocumentModule(),
$this->getPointSaleModule(),
$this->getProductModule(),
$this->getSubscriptionModule(), $this->getSubscriptionModule(),
$this->getDistributionModule(), $this->getDistributionModule(),
$this->getProducerModule(), $this->getProducerModule(),

+ 7
- 1
common/helpers/CSV.php ファイルの表示

header("Content-Transfer-Encoding: binary"); header("Content-Transfer-Encoding: binary");
} }


public static function formatPrice($price)
public static function formatPrice($price): string
{ {
return str_replace('.', ',', $price); return str_replace('.', ',', $price);
} }

public static function formatPhone($phone): string
{
return "'".$phone;
}

} }

+ 26
- 24
common/logic/Distribution/Distribution/Service/DistributionReport2CsvGenerator.php ファイルの表示

use common\logic\Order\Order\Repository\OrderRepository; use common\logic\Order\Order\Repository\OrderRepository;
use common\logic\Order\Order\Service\OrderBuilder; use common\logic\Order\Order\Service\OrderBuilder;
use common\logic\Order\Order\Service\OrderSolver; use common\logic\Order\Order\Service\OrderSolver;
use common\logic\Order\ProductOrder\Service\ProductOrderSolver;
use common\logic\PointSale\PointSale\Model\PointSale; use common\logic\PointSale\PointSale\Model\PointSale;
use common\logic\PointSale\PointSale\Repository\PointSaleRepository; use common\logic\PointSale\PointSale\Repository\PointSaleRepository;
use common\logic\Producer\Producer\Repository\ProducerRepository;
use common\logic\Producer\Producer\Service\ProducerSolver; use common\logic\Producer\Producer\Service\ProducerSolver;
use common\logic\Product\Product\Model\Product;
use common\logic\Product\Product\Repository\ProductRepository;
use common\logic\Product\Product\Service\ProductSolver; use common\logic\Product\Product\Service\ProductSolver;


class DistributionReport2CsvGenerator extends AbstractGenerator class DistributionReport2CsvGenerator extends AbstractGenerator
{ {
protected ProducerRepository $producerRepository;
protected ProductRepository $productRepository;
protected ProductSolver $productSolver; protected ProductSolver $productSolver;
protected OrderRepository $orderRepository; protected OrderRepository $orderRepository;
protected OrderSolver $orderSolver; protected OrderSolver $orderSolver;
protected PointSaleRepository $pointSaleRepository; protected PointSaleRepository $pointSaleRepository;
protected OrderBuilder $orderBuilder; protected OrderBuilder $orderBuilder;
protected ProducerSolver $producerSolver; protected ProducerSolver $producerSolver;
protected ProductOrderSolver $productOrderSolver;


public function loadDependencies(): void public function loadDependencies(): void
{ {
$this->producerRepository = $this->loadService(ProducerRepository::class);
$this->productRepository = $this->loadService(ProductRepository::class);
$this->productSolver = $this->loadService(ProductSolver::class); $this->productSolver = $this->loadService(ProductSolver::class);
$this->orderRepository = $this->loadService(OrderRepository::class); $this->orderRepository = $this->loadService(OrderRepository::class);
$this->orderSolver = $this->loadService(OrderSolver::class); $this->orderSolver = $this->loadService(OrderSolver::class);
$this->pointSaleRepository = $this->loadService(PointSaleRepository::class); $this->pointSaleRepository = $this->loadService(PointSaleRepository::class);
$this->orderBuilder = $this->loadService(OrderBuilder::class); $this->orderBuilder = $this->loadService(OrderBuilder::class);
$this->producerSolver = $this->loadService(ProducerSolver::class); $this->producerSolver = $this->loadService(ProducerSolver::class);
$this->productOrderSolver = $this->loadService(ProductOrderSolver::class);
} }


public function generateCsv(Distribution $distribution) public function generateCsv(Distribution $distribution)
public function addOrder(Order $order, PointSale $pointSale = null) public function addOrder(Order $order, PointSale $pointSale = null)
{ {
$datas = []; $datas = [];
$datas[] = [
$pointSale ? $pointSale->name : '',
$this->orderSolver->getOrderUsername($order),
1,
$this->productSolver->getNameExport($order->productOrder[0]->product),
$order->user ? "'".$order->user->phone : '',
$this->orderRepository->getPaymentLabelPaid($order),
str_replace('.',',',$this->orderSolver->getOrderAmountWithTax($order))
];


foreach($order->productOrder as $key => $productOrder) {
if ($key !== array_key_first($order->productOrder)) {
$datas[] = [
'',
'',
1,
$this->productSolver->getNameExport($productOrder->product),
];
if(isset($order->productOrder[0])) {
$firstProductOrder = $order->productOrder[0];
$datas[] = [
$pointSale ? $pointSale->name : '',
$this->orderSolver->getOrderUsername($order),
$this->productOrderSolver->getQuantityPriorityPieces($firstProductOrder),
$this->productSolver->getNameExport($firstProductOrder->product),
$this->productSolver->getWeightAsString($firstProductOrder->product),
$this->orderSolver->hasPhone($order) ? CSV::formatPhone($this->orderSolver->getPhone($order)) : '',
$this->orderRepository->getPaymentLabelPaid($order),
CSV::formatPrice($this->orderSolver->getOrderAmountWithTax($order))
];

foreach($order->productOrder as $key => $productOrder) {
if ($key !== array_key_first($order->productOrder)) {
$datas[] = [
'',
'',
$this->productOrderSolver->getQuantityPriorityPieces($productOrder),
$this->productSolver->getNameExport($productOrder->product),
$this->productSolver->getWeightAsString($productOrder->product),
];
}
} }
} }



+ 1
- 1
common/logic/Distribution/Distribution/Service/DistributionReportCsvGenerator.php ファイルの表示



if ($optionCsvExportByPiece) { if ($optionCsvExportByPiece) {
foreach ($order->productOrder as $productOrder) { foreach ($order->productOrder as $productOrder) {
$orderLine[$productsIndexArray[$productOrder->id_product]] = $this->orderSolver->getProductQuantityPieces(
$orderLine[$productsIndexArray[$productOrder->id_product]] = $this->orderSolver->getProductQuantityPiecesByOrders(
$productOrder->product, $productOrder->product,
[$order] [$order]
); );

+ 1
- 1
common/logic/Distribution/Distribution/Service/DistributionReportTotalProductCsvGenerator.php ファイルの表示

foreach($productsArray as $product) { foreach($productsArray as $product) {
$datas[] = [ $datas[] = [
$this->productSolver->getNameExport($product), $this->productSolver->getNameExport($product),
$this->orderSolver->getProductQuantityPieces($product, $ordersArray)
$this->orderSolver->getProductQuantityPiecesByOrders($product, $ordersArray)
]; ];
} }



+ 37
- 23
common/logic/Order/Order/Service/OrderSolver.php ファイルの表示

use common\logic\Document\Document\Model\Document; use common\logic\Document\Document\Model\Document;
use common\logic\Document\Document\Service\DocumentSolver; use common\logic\Document\Document\Service\DocumentSolver;
use common\logic\Order\Order\Model\Order; use common\logic\Order\Order\Model\Order;
use common\logic\Order\ProductOrder\Service\ProductOrderSolver;
use common\logic\Payment\Model\Payment; use common\logic\Payment\Model\Payment;
use common\logic\Payment\Service\PaymentSolver; use common\logic\Payment\Service\PaymentSolver;
use common\logic\PointSale\PointSale\Model\PointSale; use common\logic\PointSale\PointSale\Model\PointSale;
protected DocumentSolver $documentSolver; protected DocumentSolver $documentSolver;
protected PaymentSolver $paymentSolver; protected PaymentSolver $paymentSolver;
protected ProducerSolver $producerSolver; protected ProducerSolver $producerSolver;
protected ProductOrderSolver $productOrderSolver;


public function loadDependencies(): void public function loadDependencies(): void
{ {
$this->userSolver = $this->loadService(UserSolver::class); $this->userSolver = $this->loadService(UserSolver::class);
$this->paymentSolver = $this->loadService(PaymentSolver::class); $this->paymentSolver = $this->loadService(PaymentSolver::class);
$this->producerSolver = $this->loadService(ProducerSolver::class); $this->producerSolver = $this->loadService(ProducerSolver::class);
$this->productOrderSolver = $this->loadService(ProductOrderSolver::class);
} }


public function getFieldNameAmount($typeTotal = Order::AMOUNT_TOTAL, string $typeField = ''): string public function getFieldNameAmount($typeTotal = Order::AMOUNT_TOTAL, string $typeField = ''): string
return 0; return 0;
} }


public function getProductQuantityPieces(Product $product, array $orders): float
public function getProductQuantityPiecesByOrders(Product $product, array $ordersArray): float
{ {
$quantity = 0; $quantity = 0;


if (isset($orders) && is_array($orders) && count($orders)) {
foreach ($orders as $c) {
if (is_null($c->date_delete)) {
foreach ($c->productOrder as $po) {
if ($po->id_product == $product->id) {
if ($po->unit == 'piece') {
$quantity += $po->quantity;
} else {
if (isset($po->product) && $po->product->weight > 0) {
$quantity += ($po->quantity * Product::$unitsArray[$po->unit]['coefficient']) / $po->product->weight;
}
}
if (count($ordersArray)) {
foreach ($ordersArray as $order) {
if (is_null($order->date_delete)) {
foreach ($order->productOrder as $productOrder) {
if ($productOrder->id_product == $product->id) {
$quantity += $this->productOrderSolver->getQuantityPieces($productOrder);
} }
} }
} }
/** /**
* Retourne la quantité d'un produit donné de plusieurs commandes. * Retourne la quantité d'un produit donné de plusieurs commandes.
*/ */
public function getProductQuantity(Product $product, array $orders, bool $ignoreCancel = false, string $unit = null): float
public function getProductQuantity(Product $product, array $ordersArray, bool $ignoreCancel = false, string $unit = null): float
{ {
$quantity = 0; $quantity = 0;


if (isset($orders) && is_array($orders) && count($orders)) {
foreach ($orders as $c) {
if (is_null($c->date_delete) || $ignoreCancel) {
foreach ($c->productOrder as $po) {
if ($po->id_product == $product->id &&
((is_null($unit) && $po->product->unit == $po->unit) || (!is_null($unit) && strlen(
$unit
) && $po->unit == $unit))) {
$quantity += $po->quantity;
if (count($ordersArray)) {
foreach ($ordersArray as $order) {
if (is_null($order->date_delete) || $ignoreCancel) {
foreach ($order->productOrder as $productOrder) {
if ($productOrder->id_product == $product->id &&
((is_null($unit) && $productOrder->product->unit == $productOrder->unit)
|| (!is_null($unit) && strlen($unit) && $productOrder->unit == $unit))) {
$quantity += $productOrder->quantity;
} }
} }
} }


return null; return null;
} }

public function hasPhone(Order $order): bool
{
if($order->user && $order->user->phone) {
return true;
}

return false;
}

public function getPhone(Order $order): string
{
if($this->hasPhone($order)) {
return $order->user->phone;
}

return '';
}
} }

+ 44
- 3
common/logic/Order/ProductOrder/Service/ProductOrderSolver.php ファイルの表示

use common\logic\AbstractService; use common\logic\AbstractService;
use common\logic\Order\Order\Model\Order; use common\logic\Order\Order\Model\Order;
use common\logic\Order\ProductOrder\Model\ProductOrder; use common\logic\Order\ProductOrder\Model\ProductOrder;
use common\logic\Product\Product\Model\Product;
use common\logic\Product\Product\Service\ProductSolver;
use common\logic\SolverInterface; use common\logic\SolverInterface;


class ProductOrderSolver extends AbstractService implements SolverInterface class ProductOrderSolver extends AbstractService implements SolverInterface
{ {
/**
* Retourne le prix du produit avec taxe
*/
protected ProductSolver $productSolver;

public function loadDependencies(): void
{
$this->productSolver = $this->loadService(ProductSolver::class);
}

public function getQuantityPriorityPieces(ProductOrder $productOrder): string
{
$quantityPieces = $this->getQuantityPiecesStrict($productOrder);
if($quantityPieces) {
return $quantityPieces;
}
else {
return $this->getQuantityWithUnit($productOrder);
}
}

public function getQuantityWithUnit(ProductOrder $productOrder): string
{
return $productOrder->quantity.' '.$this->productSolver->strUnit($productOrder->unit);
}

public function getQuantityPiecesStrict(ProductOrder $productOrder): float
{
if ($productOrder->unit == 'piece') {
return $productOrder->quantity;
}
else {
if ($productOrder->product && $productOrder->product->weight > 0) {
return $this->getQuantityCoefficientBase($productOrder) / $productOrder->product->weight;
}
}

return 0;
}

public function getQuantityCoefficientBase(ProductOrder $productOrder): float
{
return $productOrder->quantity * Product::$unitsArray[$productOrder->unit]['coefficient'];
}

public function getPriceWithTax(ProductOrder $productOrder) public function getPriceWithTax(ProductOrder $productOrder)
{ {
return Price::getPriceWithTax($productOrder->price, $productOrder->taxRate->value); return Price::getPriceWithTax($productOrder->price, $productOrder->taxRate->value);

+ 11
- 3
common/logic/Product/Product/Service/ProductSolver.php ファイルの表示

$this->pointSaleSolver = $this->loadService(PointSaleSolver::class); $this->pointSaleSolver = $this->loadService(PointSaleSolver::class);
} }


public function getWeightAsString(Product $product): string
{
if ($product->weight) {
return $product->weight . ' g';
}
return '';
}

public function getPrice(Product $product, array $params = []): ?float public function getPrice(Product $product, array $params = []): ?float
{ {
$specificPriceArray = $product->productPrice; $specificPriceArray = $product->productPrice;
{ {
$productArrayFilter = []; $productArrayFilter = [];


if($pointSale) {
if ($pointSale) {
foreach ($productArray as $product) { foreach ($productArray as $product) {
if ($this->isAvailableOnPointSale($product, $pointSale)) { if ($this->isAvailableOnPointSale($product, $pointSale)) {
$productArrayFilter[] = $product; $productArrayFilter[] = $product;
{ {
$potentialRevenues = 0; $potentialRevenues = 0;


foreach($productsArray as $product) {
foreach ($productsArray as $product) {
if (isset($product['productDistribution'][0]) && $product['productDistribution'][0]['active'] && $product['productDistribution'][0]['quantity_max']) { if (isset($product['productDistribution'][0]) && $product['productDistribution'][0]['active'] && $product['productDistribution'][0]['quantity_max']) {
$potentialRevenues += $product['productDistribution'][0]['quantity_max'] * $product['price']; $potentialRevenues += $product['productDistribution'][0]['quantity_max'] * $product['price'];
} }
{ {
$potentialWeight = 0; $potentialWeight = 0;


foreach($productsArray as $product) {
foreach ($productsArray as $product) {
if (isset($product['productDistribution'][0]) && $product['productDistribution'][0]['active'] && $product['productDistribution'][0]['quantity_max']) { if (isset($product['productDistribution'][0]) && $product['productDistribution'][0]['active'] && $product['productDistribution'][0]['quantity_max']) {
$potentialWeight += $product['productDistribution'][0]['quantity_max'] * $product['weight'] / 1000; $potentialWeight += $product['productDistribution'][0]['quantity_max'] * $product['weight'] / 1000;
} }

読み込み中…
キャンセル
保存