namespace common\logic; | namespace common\logic; | ||||
use yii\base\ErrorException; | |||||
class BaseManager | class BaseManager | ||||
{ | { | ||||
protected ContainerInterface $container; | protected ContainerInterface $container; | ||||
); | ); | ||||
} | } | ||||
} | } | ||||
throw new ErrorException('La méthode '.$method.' est introuvable dans les services du container '.get_class($this->container)); | |||||
} | } | ||||
public function setContainer(ContainerInterface $container): void | |||||
protected function setContainer(ContainerInterface $container): void | |||||
{ | { | ||||
$this->container = $container; | $this->container = $container; | ||||
} | } |
// initInvoicePrices | // initInvoicePrices | ||||
// updateInvoicePrices | // updateInvoicePrices | ||||
public function updateOrderInvoicePrices(Order $order, $params = []): void | |||||
public function updateOrderInvoicePrices(Order $order, array $params = []): void | |||||
{ | { | ||||
foreach ($order->productOrder as $productOrder) { | foreach ($order->productOrder as $productOrder) { | ||||
if ($productOrder->product) { | if ($productOrder->product) { |
namespace common\logic\Order\Order; | namespace common\logic\Order\Order; | ||||
use common\logic\BaseManager; | use common\logic\BaseManager; | ||||
use common\logic\Distribution\Distribution\Distribution; | |||||
use common\logic\Product\Product\Product; | |||||
use common\logic\User\User\User; | |||||
/** | /** | ||||
* @method Order instanciateOrder(Distribution $distribution) | |||||
* @method bool isStateDelivered(Order $order) | |||||
* > Solver | |||||
* @method string getFieldNameAmount($typeTotal = Order::AMOUNT_TOTAL, string $typeField = '') | |||||
* @method float getOrderTotalVat(Order $order, string $typeTotal = Order::AMOUNT_TOTAL) | |||||
* @method ?string getPaymentStatus(Order $order) | |||||
* @method string getPointSaleSummary(Order $order) | |||||
* @method string getOrderUsername(Order $order) | |||||
* @method bool isLinkedToValidDocument(Order $order) | |||||
* @method string getCommentReport(Order $order) | |||||
* @method string getDateAsHtml(Order $order) | |||||
* @method countProducts(Order $order): int | |||||
* @method int getProductQuantityPieces(Product $product, array $orders) | |||||
* @method int getProductQuantity(Product $product, array $orders, bool $ignoreCancel = false, string $unit = null) | |||||
* @method string getHistoryClass(Order $order) | |||||
* @method string getHistorySummary(Order $order) | |||||
* @method string getLabelOrigin(Order $order, bool $withLabel = false) | |||||
* @method float getOrderAmount(Order $order, string $type = Order::AMOUNT_TOTAL, bool $format = false) | |||||
* @method float getOrderAmountWithTax(Order $order, string $type = Order::AMOUNT_TOTAL, bool $format = false) | |||||
* @method bool isOrderStateOpen(Order $order) | |||||
* @method bool isOrderStatePreparation(Order $order) | |||||
* @method bool isOrderStateDelivered(Order $order) | |||||
* @method bool isOrderBelongsToUser(Order $order, User $user = null) | |||||
* @method string getDataJson(Order $order) | |||||
* | |||||
* Repository | |||||
* | |||||
* Builder | |||||
* | |||||
* Utils | |||||
* | |||||
*/ | */ | ||||
class OrderManager extends BaseManager | class OrderManager extends BaseManager | ||||
{ | { |
]; | ]; | ||||
} | } | ||||
public function getOneById(int $id) | |||||
public function findOneById(int $id) | |||||
{ | { | ||||
return Order::searchOne(['order.id' => $id]);; | return Order::searchOne(['order.id' => $id]);; | ||||
} | } | ||||
/** | /** | ||||
* Recherche et initialise des commandes. | * Recherche et initialise des commandes. | ||||
*/ | */ | ||||
public function searchBy($params = [], $options = []) | |||||
// searchBy | |||||
public function findBy($params = [], $options = []) | |||||
{ | { | ||||
$orders = Order::searchBy($params, $options); | $orders = Order::searchBy($params, $options); | ||||
return false; | return false; | ||||
} | } | ||||
public function getByDistribution(Distribution $distribution, string $conditionAppend = '') | |||||
public function findByDistribution(Distribution $distribution, string $conditionAppend = '') | |||||
{ | { | ||||
return Order::searchAll([ | return Order::searchAll([ | ||||
'distribution.date' => $distribution->date, | 'distribution.date' => $distribution->date, | ||||
return ['incoming' => $queryIncoming, 'passed' => $queryPassed]; | return ['incoming' => $queryIncoming, 'passed' => $queryPassed]; | ||||
} | } | ||||
/** | |||||
* Retourne les informations relatives à la commande au format JSON. | |||||
*/ | |||||
public function getDataJson(Order $order): string | |||||
{ | |||||
$jsonOrder = []; | |||||
if ($order) { | |||||
$jsonOrder = [ | |||||
'products' => [], | |||||
'amount' => $order->amount, | |||||
'str_amount' => $order->getAmountWithTax(Order::AMOUNT_TOTAL, true), | |||||
'paid_amount' => $order->getAmount(Order::AMOUNT_PAID), | |||||
'comment' => $order->comment, | |||||
]; | |||||
foreach ($order->productOrder as $productOrder) { | |||||
$jsonOrder['products'][$productOrder->id_product] = $productOrder->quantity; | |||||
} | |||||
} | |||||
return json_encode($jsonOrder); | |||||
} | |||||
/** | /** | ||||
* Retourne le résumé du panier au format HTML. | * Retourne le résumé du panier au format HTML. | ||||
*/ | */ |
$this->userSolver = $this->loadService(UserSolver::class); | $this->userSolver = $this->loadService(UserSolver::class); | ||||
} | } | ||||
public function getFieldNameAmount($typeTotal = Order::AMOUNT_TOTAL, $typeField = ''): string | |||||
public function getFieldNameAmount($typeTotal = Order::AMOUNT_TOTAL, string $typeField = ''): string | |||||
{ | { | ||||
$fieldName = 'amount'; | $fieldName = 'amount'; | ||||
if ($typeTotal == Order::INVOICE_AMOUNT_TOTAL) { | if ($typeTotal == Order::INVOICE_AMOUNT_TOTAL) { | ||||
return $fieldName; | return $fieldName; | ||||
} | } | ||||
public function getOrderTotalVat(Order $order, $typeTotal = Order::AMOUNT_TOTAL): float | |||||
public function getOrderTotalVat(Order $order, string $typeTotal = Order::AMOUNT_TOTAL): float | |||||
{ | { | ||||
$fieldName = $this->getFieldNameAmount($typeTotal, 'vat'); | $fieldName = $this->getFieldNameAmount($typeTotal, 'vat'); | ||||
$totalVat = 0; | $totalVat = 0; | ||||
/** | /** | ||||
* Retourne le nombre de produits commandés. | * Retourne le nombre de produits commandés. | ||||
*/ | */ | ||||
public function countProducts(Order $order) | |||||
public function countProducts(Order $order): int | |||||
{ | { | ||||
if ($order->productOrder && is_array($order->productOrder)) { | if ($order->productOrder && is_array($order->productOrder)) { | ||||
return count($order->productOrder); | return count($order->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, $ignoreCancel = false, $unit = null): int | |||||
public function getProductQuantity(Product $product, array $orders, bool $ignoreCancel = false, string $unit = null): int | |||||
{ | { | ||||
$quantity = 0; | $quantity = 0; | ||||
* Retourne l'origine de la commande (client, automatique ou admin) sous forme texte ou HTML. | * Retourne l'origine de la commande (client, automatique ou admin) sous forme texte ou HTML. | ||||
*/ | */ | ||||
// getStrOrigin | // getStrOrigin | ||||
public function getLabelOrigin(Order $order, $withLabel = false): string | |||||
public function getLabelOrigin(Order $order, bool $withLabel = false): string | |||||
{ | { | ||||
$classLabel = ''; | $classLabel = ''; | ||||
$str = ''; | $str = ''; | ||||
* Retourne le montant de la commande (total, payé, restant, ou en surplus). | * Retourne le montant de la commande (total, payé, restant, ou en surplus). | ||||
*/ | */ | ||||
// getAmount | // getAmount | ||||
public function getOrderAmount(Order $order, string $type = Order::AMOUNT_TOTAL, $format = false) | |||||
public function getOrderAmount(Order $order, string $type = Order::AMOUNT_TOTAL, bool $format = false): float | |||||
{ | { | ||||
$amount = $order->amount; | $amount = $order->amount; | ||||
if ($type == Order::INVOICE_AMOUNT_TOTAL && $order->invoice_amount) { | if ($type == Order::INVOICE_AMOUNT_TOTAL && $order->invoice_amount) { | ||||
} | } | ||||
// getAmountWithTax | // getAmountWithTax | ||||
public function getOrderAmountWithTax(Order $order, string $type = Order::AMOUNT_TOTAL, $format = false) | |||||
public function getOrderAmountWithTax(Order $order, string $type = Order::AMOUNT_TOTAL, bool $format = false): float | |||||
{ | { | ||||
$amount = $order->amount + $this->getOrderTotalVat($order, $type); | $amount = $order->amount + $this->getOrderTotalVat($order, $type); | ||||
if ($type == Order::INVOICE_AMOUNT_TOTAL && $order->invoice_amount) { | if ($type == Order::INVOICE_AMOUNT_TOTAL && $order->invoice_amount) { | ||||
{ | { | ||||
return $order->id_user == $user->id; | return $order->id_user == $user->id; | ||||
} | } | ||||
/** | |||||
* Retourne les informations relatives à la commande au format JSON. | |||||
*/ | |||||
public function getDataJson(Order $order): string | |||||
{ | |||||
$jsonOrder = []; | |||||
if ($order) { | |||||
$jsonOrder = [ | |||||
'products' => [], | |||||
'amount' => $order->amount, | |||||
'str_amount' => $order->getAmountWithTax(Order::AMOUNT_TOTAL, true), | |||||
'paid_amount' => $order->getAmount(Order::AMOUNT_PAID), | |||||
'comment' => $order->comment, | |||||
]; | |||||
foreach ($order->productOrder as $productOrder) { | |||||
$jsonOrder['products'][$productOrder->id_product] = $productOrder->quantity; | |||||
} | |||||
} | |||||
return json_encode($jsonOrder); | |||||
} | |||||
} | } |
{ | { | ||||
$distribution = $this->getDistributionContainer()->getRepository()->getOneById(1); | $distribution = $this->getDistributionContainer()->getRepository()->getOneById(1); | ||||
$orderManager = $this->getOrderManager(); | $orderManager = $this->getOrderManager(); | ||||
$orderManager->instanciateOrder($distribution); | |||||
$order = $orderManager->instanciateOrder($distribution); | |||||
$orderManager->getOrderTotalVat($order); | |||||
return $this->render('index', [ | return $this->render('index', [ | ||||
'producerDemoAccount' => $this->getLogic()->getProducerContainer() | 'producerDemoAccount' => $this->getLogic()->getProducerContainer() |