|
- <?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()
- {
-
- }
- }
|