$addCreditHistoryForm = $this->createForm(CreditHistoryType::class, $creditHistory); | $addCreditHistoryForm = $this->createForm(CreditHistoryType::class, $creditHistory); | ||||
$addCreditHistoryForm->handleRequest($this->request); | $addCreditHistoryForm->handleRequest($this->request); | ||||
if ($addCreditHistoryForm->isSubmitted() && $addCreditHistoryForm->isValid()) { | if ($addCreditHistoryForm->isSubmitted() && $addCreditHistoryForm->isValid()) { | ||||
if($this->creditUtils->saveCreditHistory()){ | |||||
$creditHistory->setUserMerchant($userMerchant); | |||||
dump($creditHistory); | |||||
if($this->creditUtils->saveCreditHistory($creditHistory)){ | |||||
$this->utils->addFlash('warning', 'success.credit.added'); | $this->utils->addFlash('warning', 'success.credit.added'); | ||||
}else{ | }else{ | ||||
$this->utils->addFlash('warning', 'error.credit.notAdded'); | $this->utils->addFlash('warning', 'error.credit.notAdded'); |
return $this->type; | return $this->type; | ||||
} | } | ||||
public function setType(string $meanPayment): self | |||||
public function setType(string $type): self | |||||
{ | { | ||||
$this->meanPayment = $meanPayment; | |||||
$this->type = $type; | |||||
return $this; | return $this; | ||||
} | } |
use Lc\ShopBundle\Context\MerchantUtilsInterface; | use Lc\ShopBundle\Context\MerchantUtilsInterface; | ||||
use Lc\ShopBundle\Context\UserInterface; | use Lc\ShopBundle\Context\UserInterface; | ||||
use Lc\ShopBundle\Context\UserMerchantInterface; | use Lc\ShopBundle\Context\UserMerchantInterface; | ||||
use Lc\ShopBundle\Model\CreditHistory; | |||||
class CreditUtils | class CreditUtils | ||||
{ | { | ||||
{ | { | ||||
if($creditHistory) { | if($creditHistory) { | ||||
$userMerchant = $creditHistory->getUserMerchant() ; | $userMerchant = $creditHistory->getUserMerchant() ; | ||||
$checkCreditActive = $this->checkCreditActive() ; | |||||
$checkCreditActive = $this->checkCreditActive($userMerchant) ; | |||||
if($checkCreditActive) { | if($checkCreditActive) { | ||||
$this->em->persist($creditHistory) ; | $this->em->persist($creditHistory) ; | ||||
return false ; | return false ; | ||||
} | } | ||||
public function updateCredit($userMerchant, $amount, $merchant = null) | |||||
public function updateCredit($userMerchant, $amount) | |||||
{ | { | ||||
$userMerchant->setAmount($amount) ; | |||||
$userMerchant->setCredit($amount) ; | |||||
$this->em->persist($userMerchant) ; | $this->em->persist($userMerchant) ; | ||||
$this->em->flush() ; | $this->em->flush() ; | ||||
} | } |