src/Services/IctocoinService.php line 53

Open in your IDE?
  1. <?php
  2. namespace App\Services;
  3. use App\Entity\IctoMouvement;
  4. use App\Entity\IctusPharmacie;
  5. use App\Entity\User;
  6. use App\Repository\IctoMouvementRepository;
  7. use App\Repository\IctoParamgeneralRepository;
  8. use App\Repository\IctoParampovRepository;
  9. use App\Repository\IctoTypemouvementRepository;
  10. use App\Repository\IctoValeurRepository;
  11. use App\Repository\IctusPharmacieRepository;
  12. use App\Repository\PaysRepository;
  13. use Doctrine\ORM\EntityManagerInterface;
  14. use Symfony\Component\Form\Util\StringUtil;
  15. use Symfony\Component\Security\Core\Security;
  16. class IctocoinService
  17. {
  18.     private $pharmacieRepo;
  19.     private $typeMouvementRepo;
  20.     private $ictoParamPovRepo;
  21.     private $ictoParamGeneralRepo;
  22.     private $em;
  23.     private $security;
  24.     private $pays;
  25.     private $ictoValeurRepo;
  26.     private $ictoMouvementRepo;
  27.     public function __construct(
  28.         Security $security,
  29.         EntityManagerInterface $em,
  30.         IctusPharmacieRepository $pharmacieRepo,
  31.         IctoTypemouvementRepository $typeMouvementRepo,
  32.         IctoParampovRepository $ictoParampovRepo,
  33.         IctoParamgeneralRepository $ictoParamgeneralRepo,
  34.         PaysRepository $paysRepo,
  35.         IctoValeurRepository $ictoValeurRepo,
  36.         IctoMouvementRepository $ictoMouvementRepo
  37.     ) {
  38.         $this->security             $security;
  39.         $this->em                   $em;
  40.         $this->pharmacieRepo        $pharmacieRepo;
  41.         $this->typeMouvementRepo    $typeMouvementRepo;
  42.         $this->ictoParamPovRepo     $ictoParampovRepo;
  43.         $this->ictoParamGeneralRepo $ictoParamgeneralRepo;
  44.         $this->ictoValeurRepo       $ictoValeurRepo;
  45.         $this->ictoMouvementRepo    $ictoMouvementRepo;
  46.         $wherePays = array(
  47.             "codepays" => "MG"
  48.         );
  49.         $this->pays                 $paysRepo->findOneBy($wherePays);
  50.     }
  51.     public function debiter($pharmacie$montant$raison)
  52.     {
  53.         $ictocoin = new IctoMouvement();
  54.         $typeMouvement $this->typeMouvementRepo->find(2);
  55.         if (!($pharmacie instanceof IctusPharmacie)) {
  56.             $pharmacie $this->pharmacieRepo->find($pharmacie);
  57.         }
  58.         $ictocoin->setPharmacie($pharmacie)->setMontant(-$montant)->setRaison($raison)->setTypemouvement($typeMouvement);
  59.         $this->em->persist($ictocoin);
  60.         $this->em->flush();
  61.         if ($ictocoin->getId() !== null) {
  62.             return true;
  63.         }
  64.         return null;
  65.     }
  66.     public function crediter($pharmacie$montant$raison)
  67.     {
  68.         $ictocoin = new IctoMouvement();
  69.         $typeMouvement $this->typeMouvementRepo->find(1);
  70.         if (!($pharmacie instanceof IctusPharmacie)) {
  71.             $pharmacie $this->pharmacieRepo->find($pharmacie);
  72.         }
  73.         $ictocoin->setPharmacie($pharmacie)->setMontant($montant)->setRaison($raison)->setTypemouvement($typeMouvement);
  74.         $this->em->persist($ictocoin);
  75.         $this->em->flush();
  76.         if ($ictocoin->getId() !== null) {
  77.             return true;
  78.         }
  79.         return null;
  80.     }
  81.     public function getSolde($pharmacie)
  82.     {
  83.         $solde = array("reel" => 0"du" => 0"gain" => 0);
  84.         if (!($pharmacie instanceof IctusPharmacie)) {
  85.             $pharmacie $this->pharmacieRepo->find($pharmacie);
  86.         }
  87.         $result $this->ictoMouvementRepo->getSoldeByPharmacie($pharmacie)[0]["solde"];
  88.         if ($result 0) {
  89.             $solde["reel"] = $result;
  90.             $solde["du"] = abs($result);
  91.             $solde["gain"] = 0;
  92.         } else if ($result 0) {
  93.             $solde["reel"] = $result;
  94.             $solde["du"] = 0;
  95.             $solde["gain"] = $result;
  96.         }
  97.         return $solde;
  98.     }
  99.     public function getSoldeIctus()
  100.     {
  101.         $solde = array("reel" => 0"du" => 0"gain" => 0);
  102.         $result $this->ictoMouvementRepo->getSoldeIctus()[0]["solde"];
  103.         if ($result 0) {
  104.             $solde["reel"] = $result;
  105.             $solde["du"] = $result;
  106.             $solde["gain"] = 0;
  107.         } else if ($result 0) {
  108.             $solde["reel"] = $result;
  109.             $solde["du"] = 0;
  110.             $solde["gain"] = abs($result);
  111.         }
  112.         return $solde;
  113.     }
  114.     //societe livraison
  115.     public function debiterSocieteLivraison($societelivraison$montant$raison)
  116.     {
  117.         $ictocoin = new IctoMouvement();
  118.         $typeMouvement $this->typeMouvementRepo->find(2);
  119.         $ictocoin->setPharmacie(null)
  120.             ->setSocieteLivraison($societelivraison)
  121.             ->setMontant(-$montant)
  122.             ->setRaison($raison)
  123.             ->setTypemouvement($typeMouvement);
  124.         $this->em->persist($ictocoin);
  125.         $this->em->flush();
  126.         if ($ictocoin->getId() !== null) {
  127.             return true;
  128.         }
  129.         return null;
  130.     }
  131.     public function crediterSocieteLivraison($societelivraison$montant$raison)
  132.     {
  133.         $ictocoin = new IctoMouvement();
  134.         $typeMouvement $this->typeMouvementRepo->find(1);
  135.         $ictocoin->setPharmacie(null)
  136.             ->setSocieteLivraison($societelivraison)
  137.             ->setMontant(-$montant)
  138.             ->setRaison($raison)
  139.             ->setTypemouvement($typeMouvement);
  140.         $this->em->persist($ictocoin);
  141.         $this->em->flush();
  142.         if ($ictocoin->getId() !== null) {
  143.             return true;
  144.         }
  145.         return null;
  146.     }
  147.     public function getSoldeSocieteLivraison($societeLivraison)
  148.     {
  149.         $solde = array("reel" => 0"du" => 0"gain" => 0);
  150.         $result $this->ictoMouvementRepo->getSoldeSocieteLivraison($societeLivraison)[0]["solde"];
  151.         if ($result 0) {
  152.             $solde["reel"] = $result;
  153.             $solde["du"] = $result;
  154.             $solde["gain"] = 0;
  155.         } else if ($result 0) {
  156.             $solde["reel"] = $result;
  157.             $solde["du"] = 0;
  158.             $solde["gain"] = abs($result);
  159.         }
  160.         return $solde;
  161.     }
  162.     //Patient
  163.     public function debiterPatient($user$montant$raison)
  164.     {
  165.         $ictocoin = new IctoMouvement();
  166.         $typeMouvement $this->typeMouvementRepo->find(2);
  167.         if (!($user instanceof User)) {
  168.             $user $this->pharmacieRepo->find($user);
  169.         }
  170.         $ictocoin->setUser($user)->setMontant(-$montant)->setRaison($raison)->setTypemouvement($typeMouvement);
  171.         $this->em->persist($ictocoin);
  172.         $this->em->flush();
  173.         if ($ictocoin->getId() !== null) {
  174.             return true;
  175.         }
  176.         return null;
  177.     }
  178.     public function crediterPatient($user$montant$raison)
  179.     {
  180.         $ictocoin = new IctoMouvement();
  181.         $typeMouvement $this->typeMouvementRepo->find(1);
  182.         if (!($user instanceof User)) {
  183.             $user $this->pharmacieRepo->find($user);
  184.         }
  185.         $ictocoin->setPharmacie($user)->setMontant($montant)->setRaison($raison)->setTypemouvement($typeMouvement);
  186.         $this->em->persist($ictocoin);
  187.         $this->em->flush();
  188.         if ($ictocoin->getId() !== null) {
  189.             return true;
  190.         }
  191.         return null;
  192.     }
  193.     public function getSoldePatient($user)
  194.     {
  195.         $solde = array("reel" => 0"du" => 0"gain" => 0);
  196.         if (!($user instanceof User)) {
  197.             $user $this->pharmacieRepo->find($user);
  198.         }
  199.         $result $this->ictoMouvementRepo->getSoldeByUser($user)[0]["solde"];
  200.         if ($result 0) {
  201.             $solde["reel"] = $result;
  202.             $solde["du"] = abs($result);
  203.             $solde["gain"] = 0;
  204.         } else if ($result 0) {
  205.             $solde["reel"] = $result;
  206.             $solde["du"] = 0;
  207.             $solde["gain"] = $result;
  208.         }
  209.         return $solde;
  210.     }
  211.     public function getMouvementSoldeSocieteLivraison($societeLivraison$offset 0$limit 10)
  212.     {
  213.         return $this->ictoMouvementRepo->getMouvementSocieteLivraison($societeLivraison$offset$limit);
  214.     }
  215.     public function getCountAllMouvementSocieteLivraison($societelivraison)
  216.     {
  217.         return $this->ictoMouvementRepo->getCountAllMouvementSocietelivraison($societelivraison)[0]["nb"];
  218.     }
  219.     public function getMouvementSolde($pharmacie$offset 0$limit 10$mouvementAll$dated null$datef null)
  220.     {
  221.         return $this->ictoMouvementRepo->getMouvement($pharmacie$offset$limit$mouvementAll$dated$datef);
  222.     }
  223.     public function getMouvementSoldeIctus($offset 0$limit 10)
  224.     {
  225.         return $this->ictoMouvementRepo->getMouvementIctus($offset$limit);
  226.     }
  227.     public function getCountAllMouvement($pharmacie$mouvementAll 0$dateDebut null$dateFin null)
  228.     {
  229.         return $this->ictoMouvementRepo->getCountAllMouvement($pharmacie$mouvementAll$dateDebut$dateFin)[0]["nb"];
  230.     }
  231.     public function getCountAllMouvementIctus()
  232.     {
  233.         return $this->ictoMouvementRepo->getCountAllMouvementIctus()[0]["nb"];
  234.     }
  235.     public function montantIctocoin($pharmacie$montantCommande$pays null)
  236.     {
  237.         $pourcentage 0;
  238.         $valeurIctocoin 0;
  239.         $pays $pays ?? $this->pays;
  240.         if (!($pharmacie instanceof IctusPharmacie)) {
  241.             $pharmacie $this->pharmacieRepo->find($pharmacie);
  242.         }
  243.         $findOffreSpecial $this->ictoParamPovRepo->findOffreSpecial($pharmacie);
  244.         if ($findOffreSpecial) {
  245.             $result $this->ictoParamPovRepo->getPourcentageByPharmacie($pharmacie$montantCommande);
  246.             if ($result) {
  247.                 $pourcentage $result["0"]["pourcentage"];
  248.             }
  249.         } else {
  250.             $result $this->ictoParamGeneralRepo->getPourcentageByMontant($montantCommande$pays);
  251.             if ($result) {
  252.                 $pourcentage $result["0"]["pourcentage"];
  253.             }
  254.         }
  255.         $whereVI = array(
  256.             "currency" => $pays->getCurrency()
  257.         );
  258.         $getValeur $this->ictoValeurRepo->findOneBy($whereVI);
  259.         if ($getValeur) {
  260.             $valeurIctocoin $getValeur->getValeur();
  261.         }
  262.         return $montantCommande $valeurIctocoin $pourcentage 100;
  263.     }
  264. }