|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <?php
-
- namespace Lc\ShopBundle\Services\Order;
-
-
- use App\Entity\CreditHistory;
- use App\Factory\Order\OrderPaymentFactory;
- use Lc\ShopBundle\Context\OrderPaymentInterface;
- use Lc\ShopBundle\Services\Utils;
-
- trait OrderUtilsPaymentTrait
- {
-
- public function createOrderPayment($params = [])
- {
- $orderPayment = $this->factoryManager->createEntity(OrderPaymentFactory::class, $params);
-
- if(isset($params['meanPayment']) && $params['meanPayment'] == Utils::MEAN_PAYMENT_CREDIT) {
- $this->creditUtils->createCreditHistory(CreditHistory::TYPE_DEBIT, $this->security->getUser(), [
- 'orderPayment' => $orderPayment
- ]);
- }
-
- $this->em->create($orderPayment) ;
- $this->em->flush() ;
-
- return $orderPayment ;
- }
-
- public function isOrderPaid($order, $mergeComplementaryOrderShop = false)
- {
- $totalOrderPayments = $this->getTotalOrderPayments($order, $mergeComplementaryOrderShop) ;
- $totalOrder = $this->priceUtils->getTotalWithTax($order) ;
-
- if ( (abs($totalOrderPayments - $totalOrder) < 0.00001
- || $totalOrderPayments >= $totalOrder)
- && $totalOrder > 0) {
-
- return true;
- }
- else {
- return false;
- }
- }
-
- public function getTotalOrderPayments($order, $mergeComplementaryOrderShop = false): float
- {
- $totalAmount = floatval(0);
- foreach ($order->getOrderPayments() as $orderPayment) {
- $totalAmount = $orderPayment->getAmount() + $totalAmount;
- }
- if($mergeComplementaryOrderShop) {
- foreach ($order->getComplementaryOrderShops() as $complementaryOrderShop) {
- foreach ($complementaryOrderShop->getOrderPayments() as $orderPayment) {
- $totalAmount = $orderPayment->getAmount() + $totalAmount;
- }
- }
- }
- return $totalAmount;
- }
-
- public function getTotalRemainingToBePaid($order)
- {
- return $this->priceUtils->getTotalWithTax($order) - $this->getTotalOrderPayments($order) ;
- }
-
- public function isOrderShopPositiveAmountRemainingToBePaid($orderShop)
- {
- return $this->getTotalRemainingToBePaid($orderShop) > 0 ;
- }
-
- public function addPayment()
- {
-
- }
- }
|