@@ -17,4 +17,13 @@ class CreditHistoryRepository extends BaseRepository implements DefaultRepositor | |||
{ | |||
return CreditHistoryInterface::class; | |||
} | |||
public function findAllByUserMerchant($userMerchant) | |||
{ | |||
return $this->createQueryBuilder('e') | |||
->andWhere('e.userMerchant = :userMerchant') | |||
->setParameter('userMerchant', $userMerchant) | |||
->addOrderBy('e.createdAt', 'DESC') | |||
->getQuery()->getResult(); | |||
} | |||
} |
@@ -97,7 +97,7 @@ class CreditUtils | |||
} | |||
} | |||
public function checkCreditActive(UserMerchantInterface $userMerchant){ | |||
public function checkCreditActive(UserMerchantInterface $userMerchant = null){ | |||
if(!$userMerchant || ($userMerchant && !$userMerchant->isCreditActive())) { | |||
return false ; | |||
@@ -106,6 +106,15 @@ class CreditUtils | |||
return true ; | |||
} | |||
public function checkCreditSufficientToPay($userMerchant, $amount) | |||
{ | |||
if($this->checkCreditActive($userMerchant) && $userMerchant->getCredit() >= $amount) { | |||
return true ; | |||
} | |||
return false; | |||
} | |||
public function createCreditHistory($type, $user, $params = []) | |||
{ | |||
$creditHistory = $this->initCreditHistory($type, $user, $params) ; |
@@ -270,7 +270,6 @@ class OrderUtils | |||
public function getOrderDatas($order = null) | |||
{ | |||
$data = []; | |||
if (!$order) { | |||
$order = $this->getCartCurrent(); | |||
@@ -384,16 +383,18 @@ class OrderUtils | |||
return $orderProductsByProductFamily; | |||
} | |||
public function createOrderPayment($orderShop, $type, $amount, $reference = null, $comment = null, $paidAt = null) | |||
public function createOrderPayment($orderShop, $meanPayment, $amount, $reference = null, $comment = null, $paidAt = null) | |||
{ | |||
$classOrderPayment = $this->em->getClassMetadata(OrderPaymentInterface::class)->getName(); | |||
$orderPayment = new $classOrderPayment; | |||
$orderPayment->setOrderShop($orderShop); | |||
$orderPayment->setType($type); | |||
$orderPayment->setMeanPayment($meanPayment); | |||
$orderPayment->setAmount($amount); | |||
$orderPayment->setReference($reference); | |||
$orderPayment->setComment($comment); | |||
$orderPayment->setEditable(false); | |||
if ($paidAt) { | |||
$orderPayment->setPaidAt($paidAt); | |||
} else { | |||
@@ -402,6 +403,8 @@ class OrderUtils | |||
$this->em->persist($orderPayment); | |||
$this->em->flush(); | |||
return $orderPayment ; | |||
} | |||
public function isOrderPaid($order) |