Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

OrderUtilsPaymentTrait.php 2.7KB

3 anos atrás
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace Lc\ShopBundle\Services\Order;
  3. use App\Entity\CreditHistory;
  4. use App\Factory\Order\OrderPaymentFactory;
  5. use Lc\ShopBundle\Context\OrderPaymentInterface;
  6. use Lc\ShopBundle\Services\Utils;
  7. trait OrderUtilsPaymentTrait
  8. {
  9. public function createOrderPayment($params = [])
  10. {
  11. $orderPayment = $this->factoryManager->createEntity(OrderPaymentFactory::class, $params);
  12. if(isset($params['meanPayment']) && $params['meanPayment'] == Utils::MEAN_PAYMENT_CREDIT) {
  13. $this->creditUtils->createCreditHistory(CreditHistory::TYPE_DEBIT, $this->security->getUser(), [
  14. 'orderPayment' => $orderPayment
  15. ]);
  16. }
  17. $this->em->create($orderPayment) ;
  18. $this->em->flush() ;
  19. return $orderPayment ;
  20. }
  21. public function isOrderPaid($order, $mergeComplementaryOrderShop = false)
  22. {
  23. $totalOrderPayments = $this->getTotalOrderPayments($order, $mergeComplementaryOrderShop) ;
  24. $totalOrder = $this->priceUtils->getTotalWithTax($order) ;
  25. if ( (abs($totalOrderPayments - $totalOrder) < 0.00001
  26. || $totalOrderPayments >= $totalOrder)
  27. && $totalOrder > 0) {
  28. return true;
  29. }
  30. else {
  31. return false;
  32. }
  33. }
  34. public function getTotalOrderPayments($order, $mergeComplementaryOrderShop = false): float
  35. {
  36. $totalAmount = floatval(0);
  37. foreach ($order->getOrderPayments() as $orderPayment) {
  38. $totalAmount = $orderPayment->getAmount() + $totalAmount;
  39. }
  40. if($mergeComplementaryOrderShop) {
  41. foreach ($order->getComplementaryOrderShops() as $complementaryOrderShop) {
  42. foreach ($complementaryOrderShop->getOrderPayments() as $orderPayment) {
  43. $totalAmount = $orderPayment->getAmount() + $totalAmount;
  44. }
  45. }
  46. }
  47. return $totalAmount;
  48. }
  49. public function getTotalRemainingToBePaid($order)
  50. {
  51. return $this->priceUtils->getTotalWithTax($order) - $this->getTotalOrderPayments($order) ;
  52. }
  53. public function isOrderShopPositiveAmountRemainingToBePaid($orderShop)
  54. {
  55. return $this->getTotalRemainingToBePaid($orderShop) > 0 ;
  56. }
  57. public function addPayment()
  58. {
  59. }
  60. }