Browse Source

Système de compte prépayé

feature/export_comptable
Guillaume 4 years ago
parent
commit
19a4c1f2ef
3 changed files with 25 additions and 4 deletions
  1. +9
    -0
      ShopBundle/Repository/CreditHistoryRepository.php
  2. +10
    -1
      ShopBundle/Services/CreditUtils.php
  3. +6
    -3
      ShopBundle/Services/Order/OrderUtils.php

+ 9
- 0
ShopBundle/Repository/CreditHistoryRepository.php View File

{ {
return CreditHistoryInterface::class; return CreditHistoryInterface::class;
} }

public function findAllByUserMerchant($userMerchant)
{
return $this->createQueryBuilder('e')
->andWhere('e.userMerchant = :userMerchant')
->setParameter('userMerchant', $userMerchant)
->addOrderBy('e.createdAt', 'DESC')
->getQuery()->getResult();
}
} }

+ 10
- 1
ShopBundle/Services/CreditUtils.php View File

} }
} }


public function checkCreditActive(UserMerchantInterface $userMerchant){
public function checkCreditActive(UserMerchantInterface $userMerchant = null){


if(!$userMerchant || ($userMerchant && !$userMerchant->isCreditActive())) { if(!$userMerchant || ($userMerchant && !$userMerchant->isCreditActive())) {
return false ; return false ;
return true ; return true ;
} }


public function checkCreditSufficientToPay($userMerchant, $amount)
{
if($this->checkCreditActive($userMerchant) && $userMerchant->getCredit() >= $amount) {
return true ;
}

return false;
}

public function createCreditHistory($type, $user, $params = []) public function createCreditHistory($type, $user, $params = [])
{ {
$creditHistory = $this->initCreditHistory($type, $user, $params) ; $creditHistory = $this->initCreditHistory($type, $user, $params) ;

+ 6
- 3
ShopBundle/Services/Order/OrderUtils.php View File



public function getOrderDatas($order = null) public function getOrderDatas($order = null)
{ {

$data = []; $data = [];
if (!$order) { if (!$order) {
$order = $this->getCartCurrent(); $order = $this->getCartCurrent();
return $orderProductsByProductFamily; 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(); $classOrderPayment = $this->em->getClassMetadata(OrderPaymentInterface::class)->getName();
$orderPayment = new $classOrderPayment; $orderPayment = new $classOrderPayment;


$orderPayment->setOrderShop($orderShop); $orderPayment->setOrderShop($orderShop);
$orderPayment->setType($type);
$orderPayment->setMeanPayment($meanPayment);
$orderPayment->setAmount($amount); $orderPayment->setAmount($amount);
$orderPayment->setReference($reference); $orderPayment->setReference($reference);
$orderPayment->setComment($comment); $orderPayment->setComment($comment);
$orderPayment->setEditable(false);

if ($paidAt) { if ($paidAt) {
$orderPayment->setPaidAt($paidAt); $orderPayment->setPaidAt($paidAt);
} else { } else {


$this->em->persist($orderPayment); $this->em->persist($orderPayment);
$this->em->flush(); $this->em->flush();

return $orderPayment ;
} }


public function isOrderPaid($order) public function isOrderPaid($order)

Loading…
Cancel
Save