|
|
@@ -88,16 +88,13 @@ class CreditUtils |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function isCreditActive(UserInterface $user, MerchantInterface $merchant = null){ |
|
|
|
public function isCreditActiveByUser(UserInterface $user, MerchantInterface $merchant = null){ |
|
|
|
$userMerchant = $this->getUserMerchant($user, $merchant); |
|
|
|
if($userMerchant && $userMerchant->isCreditActive()) { |
|
|
|
return true; |
|
|
|
}else{ |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
return $this->isCreditActive($userMerchant); |
|
|
|
} |
|
|
|
|
|
|
|
public function checkCreditActive(UserMerchantInterface $userMerchant = null){ |
|
|
|
public function isCreditActive(UserMerchantInterface $userMerchant = null){ |
|
|
|
|
|
|
|
if(!$userMerchant || ($userMerchant && !$userMerchant->isCreditActive())) { |
|
|
|
return false ; |
|
|
@@ -106,9 +103,9 @@ class CreditUtils |
|
|
|
return true ; |
|
|
|
} |
|
|
|
|
|
|
|
public function checkCreditSufficientToPay($userMerchant, $amount) |
|
|
|
public function isCreditSufficientToPay($userMerchant, $amount) |
|
|
|
{ |
|
|
|
if($this->checkCreditActive($userMerchant) && $userMerchant->getCredit() >= $amount) { |
|
|
|
if($this->isCreditActive($userMerchant) && $userMerchant->getCredit() >= $amount) { |
|
|
|
return true ; |
|
|
|
} |
|
|
|
|
|
|
@@ -125,9 +122,9 @@ class CreditUtils |
|
|
|
{ |
|
|
|
$merchant = isset($params['merchant']) ? $params['merchant'] : null ; |
|
|
|
$userMerchant = $this->getUserMerchant($user, $merchant) ; |
|
|
|
$checkCreditActive = $this->checkCreditActive($userMerchant) ; |
|
|
|
$isCreditActive = $this->isCreditActive($userMerchant) ; |
|
|
|
|
|
|
|
if($checkCreditActive) { |
|
|
|
if($isCreditActive) { |
|
|
|
$amount = isset($params['amount']) ? $params['amount'] : null ; |
|
|
|
$meanPayment = isset($params['meanPayment']) ? $params['meanPayment'] : null ; |
|
|
|
$reference = isset($params['reference']) ? $params['reference'] : null ; |
|
|
@@ -158,9 +155,9 @@ class CreditUtils |
|
|
|
{ |
|
|
|
if($creditHistory) { |
|
|
|
$userMerchant = $creditHistory->getUserMerchant() ; |
|
|
|
$checkCreditActive = $this->checkCreditActive($userMerchant) ; |
|
|
|
$isCreditActive = $this->isCreditActive($userMerchant) ; |
|
|
|
|
|
|
|
if($checkCreditActive) { |
|
|
|
if($isCreditActive) { |
|
|
|
$this->em->persist($creditHistory) ; |
|
|
|
$this->em->flush() ; |
|
|
|
|
|
|
@@ -170,11 +167,13 @@ class CreditUtils |
|
|
|
elseif($creditHistory->getType() == CreditHistory::TYPE_DEBIT) { |
|
|
|
$userMerchantAmount = $userMerchant->getCredit() - $creditHistory->getAmountInherited() ; |
|
|
|
} |
|
|
|
if(isset($userMerchantAmount)) { |
|
|
|
if($this->isCreditSufficientToPay($userMerchant,$userMerchantAmount)) { |
|
|
|
$this->updateCredit($userMerchant, $userMerchantAmount) ; |
|
|
|
return true ; |
|
|
|
}else{ |
|
|
|
$this->utils->addFlash('success', 'error.credit.notEnoughCredit'); |
|
|
|
return false ; |
|
|
|
} |
|
|
|
|
|
|
|
return true ; |
|
|
|
} |
|
|
|
} |
|
|
|
|