src/App/EventListener/Custom/Ilas/PostListener.php line 43

Open in your IDE?
  1. <?php
  2. namespace App\EventListener\Custom\Ilas;
  3. use App\Entity\Central\Client\Client;
  4. use App\Entity\Client\PointOfSale\PointOfSaleMove;
  5. use App\Entity\Client\Store\StoreCentral;
  6. use App\Entity\Client\Store\StoreHeader;
  7. use App\Entity\Client\Store\StoreMove;
  8. use App\EventListener\GenericEvent;
  9. use App\Model\ShellExec;
  10. use App\Service\Client\Store\StoreStockManager;
  11. use App\Service\ShellExecManager;
  12. use Custom\Base\IlasBase;
  13. class PostListener
  14. {
  15.     private $shellExecManager;
  16.     private $storeStockManager;
  17.     
  18.     public function __construct(ShellExecManager $shellExecManagerStoreStockManager $storeStockManager)
  19.     {
  20.         $this->storeStockManager $storeStockManager;
  21.         $this->shellExecManager $shellExecManager;
  22.     }
  23.     public function postStoreHeaderCreate(GenericEvent $genericEvent)
  24.     {
  25.         /** @var StoreHeader $entity */
  26.         $entity $genericEvent->getSubject();
  27.         $this->isClient($genericEvent->getAppManager()->getClient());
  28.         if (!$entity instanceof StoreHeader || $entity->getType() !== StoreHeader::STORE_HEADER_CUSTOMER_RECEIPT){
  29.             return;
  30.         }
  31. //        $shellExec = new ShellExec('ilas:export:store_header', '--id='.$entity->getId().' --kernel=custom');
  32. //        $this->shellExecManager->runShellExec($shellExec, true);
  33.     }
  34.     public function postInventoryCreate(GenericEvent $genericEvent)
  35.     {
  36.         /** @var StoreMove $entity */
  37.         $entity $genericEvent->getSubject();
  38.         $appManager $genericEvent->getAppManager();
  39.         if($entity->getType() !== StoreMove::STORE_MOVE_INVENTORY || $entity->getNote() === 'helios'){
  40.             return;
  41.         }
  42.         $this->isClient($appManager->getClient());
  43.         $storeStock $this->storeStockManager->getStoreStock($entity->getProduct());
  44.         $storeStock->setUserInventory($storeStock->getUserInventory() + $entity->getStoreInventory()->getQuantity());
  45.         $appManager->persist($storeStock);
  46.     }
  47.     public function postPointOfSaleMoveCreate(GenericEvent $genericEvent)
  48.     {
  49.         /** @var PointOfSaleMove $entity */
  50.         $entity $genericEvent->getSubject();
  51.         if (!$entity instanceof PointOfSaleMove) {
  52.             return;
  53.         }
  54.         $this->isClient($genericEvent->getAppManager()->getClient());
  55.         $shellExec = new ShellExec('ilas:export:point_of_sale_move''--id='.$entity->getId().' --kernel=custom');
  56.         $this->shellExecManager->runShellExec($shellExectrue);
  57.     }
  58.     public function postStoreCentralCreate(GenericEvent $genericEvent)
  59.     {
  60.         /** @var StoreCentral $entity */
  61.         $entity $genericEvent->getSubject();
  62.         if (!$entity instanceof StoreCentral) {
  63.             return;
  64.         }
  65.         $this->isClient($genericEvent->getAppManager()->getClient());
  66.         $shellExec = new ShellExec('ilas:export:full_store_central''--id='.$entity->getId().' --kernel=custom');
  67.         $this->shellExecManager->runShellExec($shellExectrue);
  68.     }
  69.     private function isClient($client)
  70.     {
  71.         if (!$client instanceof Client || $client->getCode() !== IlasBase::getClientCode()){
  72.             throw new \Exception('Bad client');
  73.         }
  74.     }
  75. }