浏览代码

[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 查看文件

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

+ 7
- 1
common/helpers/CSV.php 查看文件

@@ -110,8 +110,14 @@ class CSV
header("Content-Transfer-Encoding: binary");
}

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

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

}

+ 26
- 24
common/logic/Distribution/Distribution/Service/DistributionReport2CsvGenerator.php 查看文件

@@ -9,35 +9,31 @@ use common\logic\Order\Order\Model\Order;
use common\logic\Order\Order\Repository\OrderRepository;
use common\logic\Order\Order\Service\OrderBuilder;
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\Repository\PointSaleRepository;
use common\logic\Producer\Producer\Repository\ProducerRepository;
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;

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

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

public function generateCsv(Distribution $distribution)
@@ -70,24 +66,30 @@ class DistributionReport2CsvGenerator extends AbstractGenerator
public function addOrder(Order $order, PointSale $pointSale = null)
{
$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 查看文件

@@ -90,7 +90,7 @@ class DistributionReportCsvGenerator extends AbstractGenerator

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

+ 1
- 1
common/logic/Distribution/Distribution/Service/DistributionReportTotalProductCsvGenerator.php 查看文件

@@ -34,7 +34,7 @@ class DistributionReportTotalProductCsvGenerator extends AbstractGenerator
foreach($productsArray as $product) {
$datas[] = [
$this->productSolver->getNameExport($product),
$this->orderSolver->getProductQuantityPieces($product, $ordersArray)
$this->orderSolver->getProductQuantityPiecesByOrders($product, $ordersArray)
];
}


+ 37
- 23
common/logic/Order/Order/Service/OrderSolver.php 查看文件

@@ -7,6 +7,7 @@ use common\logic\AbstractService;
use common\logic\Document\Document\Model\Document;
use common\logic\Document\Document\Service\DocumentSolver;
use common\logic\Order\Order\Model\Order;
use common\logic\Order\ProductOrder\Service\ProductOrderSolver;
use common\logic\Payment\Model\Payment;
use common\logic\Payment\Service\PaymentSolver;
use common\logic\PointSale\PointSale\Model\PointSale;
@@ -24,6 +25,7 @@ class OrderSolver extends AbstractService implements SolverInterface
protected DocumentSolver $documentSolver;
protected PaymentSolver $paymentSolver;
protected ProducerSolver $producerSolver;
protected ProductOrderSolver $productOrderSolver;

public function loadDependencies(): void
{
@@ -31,6 +33,7 @@ class OrderSolver extends AbstractService implements SolverInterface
$this->userSolver = $this->loadService(UserSolver::class);
$this->paymentSolver = $this->loadService(PaymentSolver::class);
$this->producerSolver = $this->loadService(ProducerSolver::class);
$this->productOrderSolver = $this->loadService(ProductOrderSolver::class);
}

public function getFieldNameAmount($typeTotal = Order::AMOUNT_TOTAL, string $typeField = ''): string
@@ -198,22 +201,16 @@ class OrderSolver extends AbstractService implements SolverInterface
return 0;
}

public function getProductQuantityPieces(Product $product, array $orders): float
public function getProductQuantityPiecesByOrders(Product $product, array $ordersArray): float
{
$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);
}
}
}
@@ -226,19 +223,18 @@ class OrderSolver extends AbstractService implements SolverInterface
/**
* 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;

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;
}
}
}
@@ -493,4 +489,22 @@ class OrderSolver extends AbstractService implements SolverInterface

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 查看文件

@@ -6,13 +6,54 @@ use common\helpers\Price;
use common\logic\AbstractService;
use common\logic\Order\Order\Model\Order;
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;

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)
{
return Price::getPriceWithTax($productOrder->price, $productOrder->taxRate->value);

+ 11
- 3
common/logic/Product/Product/Service/ProductSolver.php 查看文件

@@ -22,6 +22,14 @@ class ProductSolver extends AbstractService implements SolverInterface
$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
{
$specificPriceArray = $product->productPrice;
@@ -233,7 +241,7 @@ class ProductSolver extends AbstractService implements SolverInterface
{
$productArrayFilter = [];

if($pointSale) {
if ($pointSale) {
foreach ($productArray as $product) {
if ($this->isAvailableOnPointSale($product, $pointSale)) {
$productArrayFilter[] = $product;
@@ -248,7 +256,7 @@ class ProductSolver extends AbstractService implements SolverInterface
{
$potentialRevenues = 0;

foreach($productsArray as $product) {
foreach ($productsArray as $product) {
if (isset($product['productDistribution'][0]) && $product['productDistribution'][0]['active'] && $product['productDistribution'][0]['quantity_max']) {
$potentialRevenues += $product['productDistribution'][0]['quantity_max'] * $product['price'];
}
@@ -261,7 +269,7 @@ class ProductSolver extends AbstractService implements SolverInterface
{
$potentialWeight = 0;

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

正在加载...
取消
保存