Bläddra i källkod

CreditUtils

feature/export_comptable
Guillaume 4 år sedan
förälder
incheckning
9204a07c05
1 ändrade filer med 66 tillägg och 12 borttagningar
  1. +66
    -12
      ShopBundle/Services/CreditUtils.php

+ 66
- 12
ShopBundle/Services/CreditUtils.php Visa fil

@@ -74,32 +74,86 @@ class CreditUtils
return $this->updateCreditActive($user, $merchant, false) ;
}

public function createCreditHistory($user, $amount, $meanPayment, $comment = null, $merchant = null)
public function checkCreditActive(UserMerchantInterface $userMerchant)
{
if(!$userMerchant || ($userMerchant && !$userMerchant->isCreditActive())) {
throw new \ErrorException("L'utilisateur n'a pas de compte prépayé activé pour ce marchand.") ;
}

return true ;
}

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

public function initCreditHistory($type, $user, $params = [])
{
$merchant = isset($params['merchant']) ? $params['merchant'] : null ;
$userMerchant = $this->getUserMerchant($user, $merchant) ;
$checkCreditActive = $this->checkCreditActive($userMerchant) ;

if($checkCreditActive) {
$amount = isset($params['amount']) ? $params['amount'] : null ;
$meanPayment = isset($params['meanPayment']) ? $params['meanPayment'] : null ;
$reference = isset($params['reference']) ? $params['reference'] : null ;
$comment = isset($params['comment']) ? $params['comment'] : null ;
$orderPayment = isset($params['orderPayment']) ? $params['orderPayment'] : null ;
$orderRefund = isset($params['orderRefund']) ? $params['orderRefund'] : null ;

if($userMerchant && $userMerchant->isCreditActive()) {
// credit history
$classCreditHistory = $this->em->getClassMetadata(CreditHistoryInterface::class)->getName();

$creditHistory = new $classCreditHistory ;
$creditHistory->setType($type) ;
$creditHistory->setUserMerchant($userMerchant) ;
$creditHistory->setAmount($amount) ;
$creditHistory->setMeanPayment($meanPayment) ;
$creditHistory->setReference($reference) ;
$creditHistory->setComment($comment) ;
$creditHistory->setOrderPayment($orderPayment) ;
$creditHistory->setOrderRefund($orderRefund) ;

return $creditHistory ;
}

return $creditHistory ;
return false ;
}

public function addCredit($user, $amount, $merchant = null)
public function saveCreditHistory($creditHistory)
{
$merchant = $this->getMerchant($merchant) ;
}
public function removeCredit($user, $amount, $merchant = null)
{
$merchant = $this->getMerchant($merchant) ;
if($creditHistory) {
$userMerchant = $creditHistory->getUserMerchant() ;
$checkCreditActive = $this->checkCreditActive() ;

if($checkCreditActive) {
$this->em->persist($creditHistory) ;
$this->em->flush() ;

if($creditHistory->getType() == CreditHistory::TYPE_CREDIT) {
$userMerchantAmount = $userMerchant->getCredit() + $creditHistory->getAmountInherited() ;
}
elseif($creditHistory->getType() == CreditHistory::TYPE_DEBIT) {
$userMerchantAmount = $userMerchant->getCredit() - $creditHistory->getAmountInherited() ;
}
if(isset($userMerchantAmount)) {
$this->updateCredit($userMerchant, $userMerchantAmount) ;
}

return true ;
}
}

return false ;
}

public function setCredit($user, $amount, $merchant = null)
public function updateCredit($userMerchant, $amount, $merchant = null)
{

$userMerchant->setAmount($amount) ;
$this->em->persist($userMerchant) ;
$this->em->flush() ;
}

public function getMerchant($merchant)

Laddar…
Avbryt
Spara