src/Listener/ProspectOnStoreQualificationWorkflowListener.php line 81

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: bertrand
  5.  * Date: 29/03/2019
  6.  * Time: 13:53
  7.  */
  8. namespace App\Listener;
  9. use App\Entity\Enum\ProspectOnStoreCreationModeEnum;
  10. use App\Entity\Freelancer;
  11. use App\Entity\ProspectOnStore;
  12. use App\Entity\ProspectQualification;
  13. use App\Repository\AcquisitionModeRepository;
  14. use App\Service\DeliveryService;
  15. use App\Service\ProspectOnStoreQualificationService;
  16. use App\Service\ProspectService;
  17. use Psr\Log\LoggerInterface;
  18. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  19. use Symfony\Component\Workflow\Event\Event;
  20. class ProspectOnStoreQualificationWorkflowListener implements EventSubscriberInterface
  21. {
  22.     private LoggerInterface $logger;
  23.     private DeliveryService $deliveryService;
  24.     private ProspectService $prospectService;
  25.     private AcquisitionModeRepository $acquisitionModeRepository;
  26.     /**
  27.      * ProspectQualificationWorkflowListener constructor.
  28.      * @param DeliveryService $deliveryService
  29.      * @param ProspectService $prospectService
  30.      * @param ProspectOnStoreQualificationService $prospectOnStoreQualificationService
  31.      * @param AcquisitionModeRepository $acquisitionModeRepository
  32.      * @param LoggerInterface $logger
  33.      */
  34.     public function __construct(
  35.         DeliveryService $deliveryService,
  36.         ProspectService $prospectService,
  37.         ProspectOnStoreQualificationService $prospectOnStoreQualificationService,
  38.         AcquisitionModeRepository $acquisitionModeRepository,
  39.         LoggerInterface $logger)
  40.     {
  41.         $this->logger $logger;
  42.         $this->deliveryService $deliveryService;
  43.         $this->prospectService $prospectService;
  44.         $this->acquisitionModeRepository $acquisitionModeRepository;
  45.     }
  46.     public static function getSubscribedEvents(): array
  47.     {
  48.         return [
  49.             'workflow.prospectOnStoreQualification.completed.validate' => 'onValidate',
  50.             'workflow.prospectOnStoreQualification.completed.reject' => 'onReject',
  51.             'workflow.prospectOnStoreQualification.completed.unreach' => 'onUnreach',
  52.         ];
  53.     }
  54.     public function onValidate(Event $event)
  55.     {
  56.         $this->logger->info('ProspectOnStoreQualificationWorflowListener onValidate');
  57.         $prospectOnStoreQualification $event->getSubject();
  58.         $prospectOnStore $prospectOnStoreQualification->getProspectOnStore();
  59.         $this->logger->info('ProspectOnStoreQualificationWorflowListener.onValidate POS: ' $prospectOnStore->getId());
  60.         $prospectOnStoreQualification->setEndedAt(new \DateTime());
  61.         //set validation date
  62.         $prospectOnStoreQualification->setValidatedAt(new \DateTime());
  63.         //deliver prospect
  64.         if ($prospectOnStore->isWaitingQualification()) {
  65.             $this->logger->info('POS was waiting qualification->deliver');
  66.             $this->logger->info('deliver this POS');
  67.             $this->deliveryService->deliver($prospectOnStore);
  68.         }
  69.     }
  70.     public function onReject(Event $event)
  71.     {
  72.         $prospectOnStoreQualification $event->getSubject();
  73.         $prospectOnStore $prospectOnStoreQualification->getProspectOnStore();
  74.         $this->logger->info('ProspectOnStoreQualificationWorflowListener.onReject POS: ' $prospectOnStore->getId());
  75.         $prospectOnStoreQualification->setEndedAt(new \DateTime());
  76.     }
  77.     /**
  78.      * Manage prospect unreachable
  79.      * @param Event $event
  80.      */
  81.     public function onUnReach(Event $event)
  82.     {
  83.         $prospectOnStoreQualification $event->getSubject();
  84.         $prospectOnStore $prospectOnStoreQualification->getProspectOnStore();
  85.         $this->logger->info('ProspectOnStoreQualificationWorflowListener.onUnReach POS: ' $prospectOnStore->getId());
  86.         $prospectOnStoreQualification->setEndedAt(new \DateTime());
  87.         $this->redeliverOnCondition($prospectOnStore);
  88.     }
  89.     private function redeliverOnCondition(ProspectOnStore $prospectOnStore)
  90.     {
  91.         $this->logger->info('redeliverOnCondition: '.$prospectOnStore->getId());
  92.         //AcquisitionMode ' . $prospectOnStore->getAcquisitionMode() . ' : ' . $prospectOnStore->getAcquisitionMode()->isRedeliverOnUnReach());
  93.         $this->logger->info('searching with mode='.$prospectOnStore->getAcquisitionMode().' and base='.$prospectOnStore->getAcquisitionBase());
  94.         $acquisitionMode $this->acquisitionModeRepository->findAcquisitionModeOfPos($prospectOnStore);
  95.         $this->logger->info($acquisitionMode?'acquisitionMode id='.$acquisitionMode->getId():' none find');
  96.         if ($acquisitionMode && $acquisitionMode->isRedeliverOnUnReach()) {
  97.             $this->logger->info('acquisitionMode is isRedeliverOnUnReach');
  98.             $this->prospectService->deliverProspectOnStoreBelongingToADifferentPartner($prospectOnStore->getProspect(), ProspectOnStoreCreationModeEnum::UNREACH);
  99.         }else{
  100.             $this->logger->info('acquisitionMode prevent from delivering');
  101.         }
  102.     }
  103. }