protected $translator; | protected $translator; | ||||
public function __construct(Security $security, UserManagerInterface $userManager, EntityManagerInterface $em, | public function __construct(Security $security, UserManagerInterface $userManager, EntityManagerInterface $em, | ||||
MailjetTransport $mailjetTransport,UtilsManager $utilsManager, TranslatorInterface $translator) | |||||
MailjetTransport $mailjetTransport, UtilsManager $utilsManager, TranslatorInterface $translator) | |||||
{ | { | ||||
$this->security = $security; | $this->security = $security; | ||||
$this->userManager = $userManager; | $this->userManager = $userManager; |
use Lc\ShopBundle\Model\OrderStatus; | use Lc\ShopBundle\Model\OrderStatus; | ||||
use Lc\ShopBundle\Services\CreditUtils; | use Lc\ShopBundle\Services\CreditUtils; | ||||
use Lc\ShopBundle\Services\Utils; | use Lc\ShopBundle\Services\Utils; | ||||
use Lc\ShopBundle\Services\UtilsManager; | |||||
use Mailjet\MailjetSwiftMailer\SwiftMailer\MailjetTransport; | use Mailjet\MailjetSwiftMailer\SwiftMailer\MailjetTransport; | ||||
use Proxies\__CG__\App\Entity\OrderProduct; | use Proxies\__CG__\App\Entity\OrderProduct; | ||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType; | use Symfony\Bridge\Doctrine\Form\Type\EntityType; | ||||
{ | { | ||||
protected $creditUtils; | protected $creditUtils; | ||||
public function __construct(Security $security, UserManagerInterface $userManager, EntityManagerInterface $em, Utils $utils, MerchantUtilsInterface $merchantUtils, MailjetTransport $mailjetTransport, OrderUtilsInterface $orderUtils, TranslatorInterface $translator, CreditUtils $creditUtils) | |||||
public function __construct(Security $security, UserManagerInterface $userManager, EntityManagerInterface $em, MailjetTransport $mailjetTransport, UtilsManager $utilsManager, TranslatorInterface $translator) | |||||
{ | { | ||||
parent::__construct($security, $userManager, $em, $utils, $merchantUtils, $mailjetTransport, $orderUtils, $translator); | |||||
$this->creditUtils = $creditUtils; | |||||
$this->creditUtils = $utilsManager->getCreditUtils(); | |||||
parent::__construct($security, $userManager, $em, $mailjetTransport, $utilsManager, $translator); | |||||
} | } | ||||
protected function createListQueryBuilder($entityClass, $sortDirection, $sortField = null, $dqlFilter = null) | protected function createListQueryBuilder($entityClass, $sortDirection, $sortField = null, $dqlFilter = null) | ||||
return $this->createOrderAjaxReponse($orderShop); | return $this->createOrderAjaxReponse($orderShop); | ||||
} | } | ||||
public function orderProductsAction() | |||||
{ | |||||
$orderShop = $this->getOrderShopEntity(); | |||||
$formOrderProducts = $this->createForm(OrderProductsType::class, $orderShop); | |||||
$formOrderProducts->handleRequest($this->request); | |||||
if ($formOrderProducts->isSubmitted() && $formOrderProducts->isValid()) { | |||||
$error = false; | |||||
// dump($formOrderProducts->get('orderProducts')->getData()); | |||||
foreach ($orderShop->getOrderProducts() as $orderProduct) { | |||||
if($orderProduct->isRedelivery() === false) { | |||||
//TODO s'assurer que la commande n'est pas négativce | |||||
if ($this->orderUtils->isProductAvailable($orderProduct->getProduct(), $orderProduct->getQuantityOrder())) { | |||||
if ($orderProduct->getQuantityOrder() <= 0) { | |||||
$this->em->remove($orderProduct); | |||||
} else { | |||||
$this->em->persist($orderProduct); | |||||
} | |||||
} else { | |||||
$error = true; | |||||
$this->utils->addFlash('error', 'error.order.productUnavailable'); | |||||
} | |||||
} | |||||
} | |||||
if (!$error) { | |||||
$this->em->flush(); | |||||
$this->utils->addFlash('success', 'success.order.editQuantity'); | |||||
} | |||||
} else { | |||||
$this->utils->addFlash('error', 'error.form.submitted'); | |||||
} | |||||
return $this->createOrderAjaxReponse($orderShop); | |||||
} | |||||
public function orderInvoiceAddressAction() | public function orderInvoiceAddressAction() |
*/ | */ | ||||
protected $taxRate; | protected $taxRate; | ||||
/** | |||||
* @ORM\Column(type="float", nullable=true) | |||||
*/ | |||||
protected $buyingPrice; | |||||
public function getPriceInherited(): ?float | public function getPriceInherited(): ?float | ||||
{ | { | ||||
return $this->getPrice() ; | return $this->getPrice() ; | ||||
return $this->getTaxRate() ; | return $this->getTaxRate() ; | ||||
} | } | ||||
public function getBuyingPrice(): ?float | |||||
{ | |||||
return $this->buyingPrice; | |||||
} | |||||
public function setBuyingPrice(?float $buyingPrice): self | |||||
{ | |||||
$this->buyingPrice = $buyingPrice; | |||||
return $this; | |||||
} | |||||
public function getPrice(): ?float | public function getPrice(): ?float | ||||
{ | { |
{ | { | ||||
use PriceTrait ; | use PriceTrait ; | ||||
/** | |||||
* @ORM\Column(type="float", nullable=true) | |||||
*/ | |||||
protected $buyingPrice; | |||||
/** | /** | ||||
* @ORM\Column(type="float", nullable=true) | * @ORM\Column(type="float", nullable=true) | ||||
*/ | */ | ||||
protected $propertyExpirationDate; | protected $propertyExpirationDate; | ||||
public function getBuyingPrice(): ?float | |||||
{ | |||||
return $this->buyingPrice; | |||||
} | |||||
public function setBuyingPrice(?float $buyingPrice): self | |||||
{ | |||||
$this->buyingPrice = $buyingPrice; | |||||
return $this; | |||||
} | |||||
public function getBuyingPriceByRefUnit(): ?float | public function getBuyingPriceByRefUnit(): ?float | ||||
{ | { |
.todo-list > li .tools {position: absolute; top: 4px; right: 15px; } | .todo-list > li .tools {position: absolute; top: 4px; right: 15px; } | ||||
#addTicketMessageForm{margin-top: 30px; border-top:2px dotted #eee; padding-top: 30px} | #addTicketMessageForm{margin-top: 30px; border-top:2px dotted #eee; padding-top: 30px} | ||||
#dashboard .list-btn-statistic{display: flex; flex-wrap: wrap; justify-content: center;} | |||||
#dashboard .btn-statistic{ width: 120px; height: 70px; text-align: center; border: 1px solid black; line-height: 1rem; } | |||||
#dashboard .btn-statistic small{margin-bottom: 10px; display: block;} | |||||
#dashboard .btn-statistic .value{display: block;} |
<ul class="todo-list ui-sortable" data-widget="todo-list"> | |||||
{% for reminder in reminders %} | |||||
<li class=""> | |||||
<label class="big form-check-label"> | |||||
<input type="checkbox" name="" value="1" | |||||
class="form-check-input checkbox-valid-reminder" | |||||
data-url="{{ path('easyadmin', { action: 'setReminderDone', entity: 'Reminder', id: reminder.id }) }}"> | |||||
<span class="checkmark"></span> | |||||
</label> | |||||
<span class="text">{{ reminder.title }}</span> | |||||
{% if reminder.dateReminder %} | |||||
<small class="badge badge-info"> | |||||
<i class="far fa-clock"></i> | |||||
{{ reminder.dateReminder|date('d-m-Y') }} | |||||
</small> | |||||
{% endif %} | |||||
<div class="tools"> | |||||
<button type="button" class="btn-sm btn-success" data-toggle="modal" | |||||
data-target="#modal-reminder-{{ reminder.id }}"> | |||||
<i class="fas fa-eye"></i> | |||||
</button> | |||||
<button type="button" class="btn-sm btn-info btn-edit-reminder" | |||||
data-url="{{ path('easyadmin', { action: 'edit', entity: 'Reminder', id: reminder.id }) }}"> | |||||
<i class="fas fa-edit"></i> | |||||
</button> | |||||
</div> | |||||
{% include '@LcShop/backend/default/modal/show_reminder.twig' %} | |||||
</li> | |||||
{% endfor %} | |||||
<ul class="todo-list ui-sortable" data-widget="todo-list"> | |||||
{% for reminder in reminders %} | |||||
<li class=""> | |||||
<label class="big form-check-label"> | |||||
<input type="checkbox" name="" value="1" | |||||
class="form-check-input checkbox-valid-reminder" | |||||
data-url="{{ path('easyadmin', { action: 'setReminderDone', entity: 'Reminder', id: reminder.id }) }}"> | |||||
<span class="checkmark"></span> | |||||
</label> | |||||
<span class="text">{{ reminder.title }}</span> | |||||
{% if reminder.dateReminder %} | |||||
<small class="badge badge-info"> | |||||
<i class="far fa-clock"></i> | |||||
{{ reminder.dateReminder|date('d-m-Y') }} | |||||
</small> | |||||
{% endif %} | |||||
<div class="tools"> | |||||
<button type="button" class="btn-sm btn-success" data-toggle="modal" | |||||
data-target="#modal-reminder-{{ reminder.id }}"> | |||||
<i class="fas fa-eye"></i> | |||||
</button> | |||||
<button type="button" class="btn-sm btn-info btn-edit-reminder" | |||||
data-url="{{ path('easyadmin', { action: 'edit', entity: 'Reminder', id: reminder.id }) }}"> | |||||
<i class="fas fa-edit"></i> | |||||
</button> | |||||
</div> | |||||
{% include '@LcShop/backend/default/modal/show_reminder.twig' %} | |||||
</li> | |||||
{% endfor %} | |||||
</ul> | |||||
</ul> | |||||
<th> | <th> | ||||
<span>Prix TTC à l'unité </span> | <span>Prix TTC à l'unité </span> | ||||
</th> | </th> | ||||
<th> | |||||
<span>Marge </span> | |||||
</th> | |||||
<th> | <th> | ||||
<span>Disponibilité</span> | <span>Disponibilité</span> | ||||
</th> | </th> | ||||
<td> | <td> | ||||
{% verbatim %}{{orderProduct.priceWithTax}}{% endverbatim %}€ | {% verbatim %}{{orderProduct.priceWithTax}}{% endverbatim %}€ | ||||
</td> | </td> | ||||
<td> | |||||
{% verbatim %}{{orderProduct.buyingPrice}}{% endverbatim %}€ <br /> | |||||
{% verbatim %}{{orderProduct.totalMargin}}{% endverbatim %}€ / | |||||
{% verbatim %}{{orderProduct.marginPercent}}{% endverbatim %}% | |||||
</td> | |||||
<td> | <td> | ||||
{% verbatim %}{{orderProduct.availableQuantity}}{% endverbatim %} | {% verbatim %}{{orderProduct.availableQuantity}}{% endverbatim %} | ||||
</td> | </td> |
$orderProductAdd->setTitle($orderProductAdd->getTitleOrderShop()); | $orderProductAdd->setTitle($orderProductAdd->getTitleOrderShop()); | ||||
$orderProductAdd->setPrice($this->priceUtils->getPrice($orderProductAdd->getProduct())); | $orderProductAdd->setPrice($this->priceUtils->getPrice($orderProductAdd->getProduct())); | ||||
$orderProductAdd->setBuyingPrice($this->priceUtils->getBuyingPrice($orderProductAdd->getProduct())); | |||||
$orderProductAdd->setUnit($orderProductAdd->getProduct()->getUnitInherited()); | $orderProductAdd->setUnit($orderProductAdd->getProduct()->getUnitInherited()); | ||||
$orderProductAdd->setTaxRate($orderProductAdd->getProduct()->getTaxRateInherited()); | $orderProductAdd->setTaxRate($orderProductAdd->getProduct()->getTaxRateInherited()); | ||||
$orderProductAdd->setQuantityProduct($orderProductAdd->getProduct()->getQuantityInherited()); | $orderProductAdd->setQuantityProduct($orderProductAdd->getProduct()->getQuantityInherited()); |
return $orderProduct->getPrice(); | return $orderProduct->getPrice(); | ||||
} | } | ||||
public function getBuyingPrice(OrderProductInterface $orderProduct) | |||||
{ | |||||
return $orderProduct->getBuyingPrice(); | |||||
} | |||||
public function getPriceWithTax(OrderProductInterface $orderProduct) | public function getPriceWithTax(OrderProductInterface $orderProduct) | ||||
{ | { | ||||
return $this->applyTax( | return $this->applyTax( | ||||
} | } | ||||
public function getPriceWithReduction(OrderProductInterface $orderProduct) | |||||
{ | |||||
return $this->applyReductionCatalog( | |||||
$orderProduct, | |||||
$this->getPrice($orderProduct), | |||||
$this->getPriceWithTax($orderProduct), | |||||
null, | |||||
false | |||||
); | |||||
} | |||||
public function getTotal(OrderProductInterface $orderProduct) | public function getTotal(OrderProductInterface $orderProduct) | ||||
{ | { | ||||
return $orderProduct->getQuantityOrder() * $this->getPrice($orderProduct); | return $orderProduct->getQuantityOrder() * $this->getPrice($orderProduct); | ||||
} | } | ||||
public function getMargin(OrderProductInterface $orderProduct) | |||||
{ | |||||
return $this->getPriceWithReduction($orderProduct) - $this->getBuyingPrice($orderProduct); | |||||
} | |||||
public function getMarginPercent(OrderProductInterface $orderProduct) | |||||
{ | |||||
if($this->getBuyingPrice($orderProduct)) { | |||||
return ($this->getMargin($orderProduct) / $this->getBuyingPrice($orderProduct)) * 100; | |||||
}else{ | |||||
return 0; | |||||
} | |||||
} | |||||
public function getTotalMargin(OrderProductInterface $orderProduct) | |||||
{ | |||||
return $orderProduct->getQuantityOrder() * $this->getMargin($orderProduct); | |||||
} | |||||
public function getTotalWithReduction(OrderProductInterface $orderProduct) | public function getTotalWithReduction(OrderProductInterface $orderProduct) | ||||
{ | { | ||||
return $this->applyReductionCatalog( | return $this->applyReductionCatalog( |
return $total; | return $total; | ||||
} | } | ||||
//Inclus les ReductionCatalog des OrderProducts | |||||
public function getMarginOrderProducts(OrderShopInterface $orderShop):float | |||||
{ | |||||
// A tester calculer ce montant en faisant TotalOrderWithTax - TotalOrderTaxes | |||||
$total = 0; | |||||
foreach ($orderShop->getOrderProducts() as $orderProduct) { | |||||
$total += $this->orderProductPriceUtils->getTotalMargin($orderProduct); | |||||
} | |||||
return $total; | |||||
} | |||||
public function getTotalOrderProductsWithTax(OrderShopInterface $orderShop):float | public function getTotalOrderProductsWithTax(OrderShopInterface $orderShop):float | ||||
{ | { | ||||
return $this->getTotalOrderProductsWithTaxByOrderProducts($orderShop->getOrderProducts()) ; | return $this->getTotalOrderProductsWithTaxByOrderProducts($orderShop->getOrderProducts()) ; | ||||
} | } | ||||
public function getTotalOrderProductsWithTaxByOrderProducts($orderProducts):float | public function getTotalOrderProductsWithTaxByOrderProducts($orderProducts):float | ||||
{ | { | ||||
$total = 0; | $total = 0; | ||||
} | } | ||||
public function getMarginOrderProductsWithReductions(OrderShopInterface $orderShop):float | |||||
{ | |||||
$total = $this->getMarginOrderProducts($orderShop) ; | |||||
$totalReductionAmount = 0 ; | |||||
foreach ($orderShop->getOrderReductionCarts() as $orderReductionCart) { | |||||
$totalReductionAmount += $this->getOrderProductsReductionCartAmountWithoutTax($orderShop,$orderReductionCart); | |||||
} | |||||
foreach ($orderShop->getOrderReductionCredits() as $orderReductionCredit) { | |||||
$totalReductionAmount += $this->getOrderProductsReductionCreditAmountWithoutTax($orderShop,$orderReductionCredit); | |||||
} | |||||
$total -= $totalReductionAmount ; | |||||
return $total ; | |||||
} | |||||
public function getTotalOrderProductsWithTaxAndReductions(OrderShopInterface $orderShop) | public function getTotalOrderProductsWithTaxAndReductions(OrderShopInterface $orderShop) | ||||
{ | { | ||||
$total = $this->getTotalOrderProductsWithTax($orderShop) ; | $total = $this->getTotalOrderProductsWithTax($orderShop) ; |
elseif ($product->getBehaviorPriceInherited() == 'by-reference-unit') { | elseif ($product->getBehaviorPriceInherited() == 'by-reference-unit') { | ||||
if ($product->getQuantityInherited() > 0) { | if ($product->getQuantityInherited() > 0) { | ||||
return $product->getPriceByRefUnitInherited() * ($product->getQuantityInherited() / $product->getUnitInherited()->getCoefficient()); | return $product->getPriceByRefUnitInherited() * ($product->getQuantityInherited() / $product->getUnitInherited()->getCoefficient()); | ||||
}else{ | |||||
return 0; | |||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
public function getBuyingPrice(ProductPropertyInterface $product) | |||||
{ | |||||
if ($product->getBehaviorPriceInherited() == 'by-piece') { | |||||
return $product->getBuyingPriceInherited(); | |||||
} | |||||
elseif ($product->getBehaviorPriceInherited() == 'by-reference-unit') { | |||||
if ($product->getQuantityInherited() > 0) { | |||||
return $product->getBuyingPriceByRefUnitInherited() * ($product->getQuantityInherited() / $product->getUnitInherited()->getCoefficient()); | |||||
}else{ | |||||
return 0; | |||||
} | |||||
} | |||||
} | |||||
} | } | ||||
use Lc\ShopBundle\Context\OrderUtilsInterface; | use Lc\ShopBundle\Context\OrderUtilsInterface; | ||||
use Lc\ShopBundle\Context\PriceUtilsInterface; | use Lc\ShopBundle\Context\PriceUtilsInterface; | ||||
use Lc\ShopBundle\Context\ProductFamilyUtilsInterface; | use Lc\ShopBundle\Context\ProductFamilyUtilsInterface; | ||||
use Lc\ShopBundle\Context\Services\StatisticsUtilsInterface; | |||||
class UtilsManager | class UtilsManager | ||||
{ | { | ||||
protected $documentUtils ; | protected $documentUtils ; | ||||
protected $mailUtils ; | protected $mailUtils ; | ||||
protected $ticketUtils ; | protected $ticketUtils ; | ||||
protected $statisticsUtils; | |||||
public function __construct( | public function __construct( | ||||
Utils $utils, | Utils $utils, | ||||
{ | { | ||||
return $this->ticketUtils ; | return $this->ticketUtils ; | ||||
} | } | ||||
} | } |