src\Controller\EDIController.php line 42

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\JOURNAL;
  4. use App\Entity\SAGE\GACCDUDATE;
  5. use App\Entity\SAGE\GACCENTRYA;
  6. use App\Entity\SAGE\GACCENTRY as sageGaccentries;
  7. use App\Entity\SAGE\GACCENTRYD as sageGaccentryd;
  8. use App\Entity\Bpartner;
  9. use App\Entity\Gaccentry as outputGaccentries;
  10. use App\Entity\CompteTier;
  11. use App\Entity\Gaccentryd;
  12. use App\Entity\Genratenum;
  13. use App\Entity\Partenaire;
  14. use Psr\Log\LoggerInterface;
  15. use Doctrine\DBAL\Connection;
  16. use Doctrine\ORM\Query\Expr\Join;
  17. use App\Service\ConnectionService;
  18. use Doctrine\DBAL\Driver\Exception;
  19. use Doctrine\Persistence\ManagerRegistry;
  20. use Symfony\Component\HttpFoundation\Request;
  21. use Symfony\Component\HttpFoundation\Response;
  22. use Symfony\Component\Routing\Annotation\Route;
  23. use Symfony\Component\HttpFoundation\JsonResponse;
  24. use Symfony\Contracts\HttpClient\HttpClientInterface;
  25. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  26. class EDIController extends AbstractController
  27. {
  28.     private $em;
  29.     private $client;
  30.     public function __construct(ConnectionService $em,HttpClientInterface $client)
  31.     {
  32.         $this->em $em;
  33.         $this->client $client;
  34.     }
  35.     #[Route('/edi'name'app_edi')]
  36.     public function index(): Response
  37.     {
  38.         return $this->render('edi/index.html.twig', [
  39.             'controller_name' => 'EDIController',
  40.         ]);
  41.     }
  42.     #[Route('/getCodeAdonix'name'app_getCodeAdonix')]
  43.     public function getCodeAdonix(): Response
  44.     {
  45.         $results $this->em->getEntity()->getRepository(outputGaccentries::class)->findByDate(); // Adjust the method to match your repository
  46.         // dd($results);
  47.         foreach ($results as $entry) {
  48.             $num $entry->getNum();
  49.     
  50.             // Use $num in your SQL query
  51.             $searchAdonix $this->em->getSage()->fetchAllAssociative("SELECT REF_0, NUM_0 FROM HCZ.GACCENTRY WHERE REF_0 = '".$num."' ");
  52.             
  53.             if ($searchAdonix) {
  54.                 $entry->setObservationFczFlag6($searchAdonix[0]['NUM_0']);
  55.                 $entry->setFczFlag6(8);
  56.                 $this->em->getEntity()->persist($entry);
  57.                 
  58.             }
  59.         }
  60.         $this->em->getEntity()->flush();
  61.         return new Response('ok');
  62.     }
  63.     #[Route('/sage/accnum'name'app_sage_accnum')]
  64.     public function accnum()
  65.     {
  66.         try {
  67.             $this->em->getInterface()->beginTransaction();
  68.             // Get the last account number (type is used as the account number here)
  69.             $accnum $this->em->getEntity()->getRepository(Genratenum::class)->findLastAccnum();
  70.             // Get the list of pieces to process
  71.             $pieceCaImport $this->em->getEntity()->getRepository(outputGaccentries::class)->findCaAccnum();
  72.         
  73.             // Iterate through each piece in the import
  74.             foreach ($pieceCaImport as $piece) {
  75.                 // dd($piece);
  76.                 $piece->setFczFlag3(1);
  77.                 $Gaccentryds $piece->getGaccentryds();
  78.         
  79.                 foreach ($Gaccentryds as $det) {
  80.                     $accnum++; // Increment account number
  81.                     $det->setPcg($accnum); // Set Pcg with the current account number
  82.                     $accnum++; // Increment account number again
  83.                     $det->setPca($accnum); // Set Pca with the current account number
  84.                 }
  85.             }
  86.         
  87.             $this->em->getEntity()->flush(); // Save all changes to the database
  88.             
  89.             $updateAccnum $this->em->getInterface()->fetchAssociative("UPDATE genratenum SET type = '".$accnum."' WHERE id = 810699");    
  90.             
  91.             $this->em->getInterface()->commit();
  92.     
  93.         } catch (Exception $e) {
  94.                 if ($this->em->getInterface()->isTransactionActive()) {
  95.                     $this->em->getInterface()->rollBack();
  96.                 }
  97.                 
  98.                 return new JsonResponse("Error: " $e->getMessage());
  99.         }
  100.             // return new JsonResponse($accnum);
  101.             return new JsonResponse("ok");
  102.     }
  103.     #[Route('/anomalie'name'app_anomalie')]
  104.     public function anomalie(Request $request): Response
  105.     {
  106.         // Construire la requĂȘte Doctrine pour chercher les anomalies
  107.         $queryBuilder $this->em->getEntity()->createQueryBuilder()
  108.         ->select('g.typ''g.num''g.accdat''g.desvcr''g.observation_fcz_flag6')
  109.         ->from(outputGaccentries::class, 'g')
  110.         ->where('g.fcz_flag6 = 9')
  111.         ->andWhere('g.fczFlag5 = 1')
  112.         ->andWhere('g.fczFlag3 = 0');
  113.         // Execute the main query
  114.         $results $queryBuilder->getQuery()->getResult();
  115.         foreach ($results as &$row) {
  116.             $row['accdat'] = $row['accdat']->format('Y-m-d'); // Adjust format as needed
  117.         }
  118.         // Return the response
  119.         return new JsonResponse($results);
  120.     }
  121.     
  122.     #[Route('/anomalie/observationPiece'name'app_anomalie_observationPiece')]
  123.     public function observationPiece(Request $request): JsonResponse
  124.     {
  125.         $qb $this->em->getEntity()->createQueryBuilder();
  126.         $qb->select('DISTINCT CASE
  127.                                 WHEN o.observation_fcz_flag6 LIKE :date THEN :dateLabel
  128.                                 WHEN o.observation_fcz_flag6 LIKE :fournisseur THEN :fournisseurLabel
  129.                                 WHEN o.observation_fcz_flag6 LIKE :client THEN :clientLabel
  130.                                 WHEN o.observation_fcz_flag6 LIKE :type THEN :typeLabel
  131.                                 WHEN o.observation_fcz_flag6 LIKE :desequilibrees THEN :desequilibreesLabel
  132.                                 WHEN o.observation_fcz_flag6 LIKE :det THEN :detLabel
  133.                                 WHEN o.observation_fcz_flag6 LIKE :acc THEN :cmpLabel
  134.                                 ELSE :otherLabel 
  135.                             END AS Observ')
  136.             ->from('App\Entity\Gaccentry''o')
  137.             ->where('o.fczFlag3 = :fczFlag3')
  138.             ->andWhere('o.fcz_flag6 = :fczFlag6')
  139.             ->andWhere('o.fczFlag5 = :fczFlag2')
  140.             ->setParameter('date''%DATE%')
  141.             ->setParameter('dateLabel''DATE')
  142.             ->setParameter('fournisseur''%FOURNISSEUR%')
  143.             ->setParameter('fournisseurLabel''FOURNISSEUR')
  144.             ->setParameter('client''%CLIENT%')
  145.             ->setParameter('clientLabel''CLIENT')
  146.             ->setParameter('acc''%ACC N EXISTE%')
  147.             ->setParameter('cmpLabel''compte')
  148.             ->setParameter('type''%TYPE%')
  149.             ->setParameter('typeLabel''TYPE')
  150.             ->setParameter('desequilibrees''%DESEQUILIBREES%')
  151.             ->setParameter('desequilibreesLabel''PIECE DESEQUILIBREES')
  152.             ->setParameter('det''%DET%')
  153.             ->setParameter('detLabel''SANS DET')
  154.             ->setParameter('otherLabel''OTHER')
  155.             ->setParameter('fczFlag3'0)
  156.             ->setParameter('fczFlag6'9)
  157.             ->setParameter('fczFlag2'1);
  158.         $observationFlags $qb->getQuery()->getResult();
  159.         $options = [];
  160.         foreach ($observationFlags as $flag) {
  161.             $options[] = $flag['Observ'];
  162.         }
  163.     
  164.         return new JsonResponse($options);
  165.     }
  166.     #[Route('/suivi/returnPiece'name'app_suivi_returnPiece')]
  167.     public function suiviReturnPiece(Request $request): Response
  168.     {
  169.         // Step 1: Retrieve the $num parameter from the query string
  170.         $num $request->query->get('num');
  171.         
  172.         // Step 2: Check if $num is present; return an error if it's missing
  173.         if (!$num) {
  174.             return new JsonResponse(['error' => 'Missing num parameter'], 400);
  175.         }
  176.         // Step 3: Perform the database queries using $num
  177.         $queryBuilderGaccentry $this->em->getEntity()->createQueryBuilder()
  178.             ->select('g.num''g.desvcr''g.accdat''g.observation_fcz_flag6','g.id')
  179.             ->from(outputGaccentries::class, 'g')
  180.             ->where('g.num = :num')
  181.             ->setParameter('num'$num);
  182.         $queryBuilderGaccentryd $this->em->getEntity()->createQueryBuilder()
  183.             ->select('d.typ0''d.cce0''d.acc''d.bpr''d.amtcur''d.acc''d.sns''d.lin''d.id')
  184.             ->from(outputGaccentries::class, 'd')
  185.             ->where('d.num = :num')
  186.             ->setParameter('num'$num);
  187.         // Step 4: Execute the queries
  188.         $outputGaccentry $queryBuilderGaccentry->getQuery()->getResult();
  189.         $outputGaccentryd $queryBuilderGaccentryd->getQuery()->getResult();
  190.         // Step 5: Format the accdat field in the result
  191.         foreach ($outputGaccentry as &$entry) {
  192.             if ($entry['accdat'] instanceof \DateTime) {
  193.                 // Format the DateTime object to 'Y-m-d H:i:s.u' format
  194.                 $entry['accdat'] = $entry['accdat']->format('Y-m-d H:i:s');  // Example: '2024-01-02 00:00:00.0'
  195.             }
  196.         }
  197.         // Step 6: Prepare the data for the response
  198.         $data = [
  199.             'outputGaccentry' => $outputGaccentry,
  200.             'outputGaccentryd' => $outputGaccentryd,
  201.         ];
  202.         // Step 3: Send the formatted data as a JSON response
  203.         return new JsonResponse($data);
  204.     }
  205.     #[Route('/bpsupplier'name'opp_bpsupplier')]
  206.     public function bpsupplier(Request $request): JsonResponse
  207.     {
  208.         $bpsupplierAdonix $this->em->getSage()->fetchAllAssociative("SELECT BPSNUM_0 , ENAFLG_0 FROM HCZ.BPSUPPLIER");
  209.         // Fetching all existing suppliers of type 'SUPPLIER' in one query
  210.         $bPartnerRepository $this->em->getEntity()->getRepository(Bpartner::class);
  211.         $existingSuppliers  $bPartnerRepository->findBy(['type' => 'SUPPLIER']);
  212.         // Creating a map of existing suppliers for fast lookup
  213.         $existingSuppliersMap = [];
  214.         foreach ($existingSuppliers as $supplier) {
  215.             $existingSuppliersMap[$supplier->getPartner()] = $supplier;
  216.         }
  217.         // Processing the bpsupplierAdonix data
  218.         foreach ($bpsupplierAdonix as $bpsupplier) {
  219.             $partner $bpsupplier["BPSNUM_0"];
  220.             $active $bpsupplier["ENAFLG_0"];
  221.             if (isset($existingSuppliersMap[$partner])) {
  222.                 $supplier $existingSuppliersMap[$partner];
  223.                 if ($supplier->getActive() !== $active) {
  224.                     $supplier->setActive($active);
  225.                     $this->em->getEntity()->persist($supplier); // Persist only when there's a change
  226.                 }
  227.             } else {
  228.                 $creationSupplier = new Bpartner();
  229.                 $creationSupplier->setPartner($partner);
  230.                 $creationSupplier->setActive($active);
  231.                 $creationSupplier->setType("SUPPLIER");
  232.                 $this->em->getEntity()->persist($creationSupplier);
  233.             }
  234.         }
  235.         // Flush all changes at once
  236.         $this->em->getEntity()->flush();
  237.         return new JsonResponse(['message' => 'Process supplier completed successfully']);
  238.     }
  239.     #[Route('/bpcustomer'name'app_bpcustomer')]
  240.     public function bpcustomer(Request $request): Response
  241.     {
  242.         $bpcustomerAdonix $this->em->getSage()->fetchAllAssociative("SELECT BPCNUM_0 , BPCSTA_0 FROM HCZ.BPCUSTOMER");
  243.         // Fetching all existing customers of type 'SUPPLIER' in one query
  244.         $bPartnerRepository $this->em->getEntity()->getRepository(Bpartner::class);
  245.         $existingCustomers $bPartnerRepository->findBy(['type' => 'CUSTOMER']);
  246.         // Creating a map of existing customers for fast lookup
  247.         $existingCustomersMap = [];
  248.         foreach ($existingCustomers as $customer) {
  249.             $existingCustomersMap[$customer->getPartner()] = $customer;
  250.         }
  251.         // Processing the bpcustomerAdonix data
  252.         foreach ($bpcustomerAdonix as $bpcustomer) {
  253.             $partner $bpcustomer["BPCNUM_0"];
  254.             $active $bpcustomer["BPCSTA_0"];
  255.             if (isset($existingCustomersMap[$partner])) {
  256.                 $customer $existingCustomersMap[$partner];
  257.                 if ($customer->getActive() !== $active) {
  258.                     $customer->setActive($active);
  259.                     $this->em->getEntity()->persist($customer); // Persist only when there's a change
  260.                 }
  261.             } else {
  262.                 $creationCustomer = new Bpartner();
  263.                 $creationCustomer->setPartner($partner);
  264.                 $creationCustomer->setActive($active);
  265.                 $creationCustomer->setType("CUSTOMER");
  266.                 $this->em->getEntity()->persist($creationCustomer);
  267.             }
  268.         }
  269.         // Flush all changes at once
  270.         $this->em->getEntity()->flush();
  271.         return new JsonResponse(['message' => 'Process customer completed successfully']);
  272.     }
  273.     #[Route('/PieceControle'name'app_PieceControle')]
  274.     public function PieceControle(): Response
  275.     {
  276.         $conditionMet false;
  277.         $Gaccentries  $this->em->getEntity()->getRepository(outputGaccentries::class)->findPieceValid();
  278.         // dd($Gaccentries);
  279.             $sumArray = [];
  280.             foreach ($Gaccentries as $key => $Gac) {
  281.                 // fcz_flag6 = 8 Is Exsit In Table ComptabilitĂ© sage
  282.                 $num $Gac->getNum();
  283.                 $RefCheck $this->em->getSage()->fetchAllAssociative("SELECT REF_0,NUM_0 FROM HCZ.GACCENTRY WHERE REF_0 = '".$num."' ");
  284.                 foreach ($RefCheck as $key => $value) {
  285.                     if ($RefCheck) {
  286.                         $Gac->setObservationFczFlag6($value['NUM_0']);
  287.                         $Gac->setFczFlag6(8);
  288.                         $conditionMet true;
  289.                     }
  290.                 }
  291.             // fcz_flag6 = 4 Is Exsit In dbcom 
  292.                 $NumCheck $this->em->getDbcom()->fetchAllAssociative("SELECT NUM_0,NUMX3_0 FROM YGAS WHERE NUM_0 = '".$num."' ");
  293.                 // dd($NumCheck);
  294.                 foreach ($NumCheck as $key => $value) {
  295.                     if ($NumCheck) {
  296.                         $Gac->setObservationFczFlag6(empty($value['NUMX3_0']) ? $value['NUM_0'] : $Gac->getObservationFczFlag6());
  297.                         $Gac->setFczFlag6(4);
  298.                         $Gac->setFczFlag3(1);
  299.                         $conditionMet true;
  300.                     }
  301.                 }
  302.             // fcz_flag6 = 9 Piece a Probleme 
  303.                 $jouCheck          $Gac->getJou();
  304.                 $matchingJournals  $this->em->getEntity()->getRepository(JOURNAL::class)->findJournal($jouCheck);
  305.                 if (!$matchingJournals) {
  306.                     $Gac->setObservationFczFlag6('JOURNAL N EXISTE PAS DANS SAGE' ' ' $jouCheck);
  307.                     $Gac->setFczFlag6(9);
  308.                     $conditionMet true;
  309.                 } 
  310.                 $cpy1Check    $Gac->getCpy1();
  311.                 $matchingCpy  $this->em->getEntity()->getRepository(Partenaire::class)->findCpy($cpy1Check);
  312.                 if (!$matchingCpy) {
  313.                     $Gac->setObservationFczFlag6('DOSSIER N EXISTE PAS DANS SAGE' ' ' $cpy1Check);
  314.                     $Gac->setFczFlag6(9);
  315.                     $conditionMet true;
  316.                 } 
  317.                 $fcy1Check    $Gac->getFcy1();
  318.                 $matchingFcy  $this->em->getEntity()->getRepository(Partenaire::class)->findFcy($fcy1Check);
  319.                 if (!$matchingFcy) {
  320.                     $Gac->setObservationFczFlag6('SOUS DOSSIER N EXISTE PAS DANS SAGE' ' ' $fcy1Check);
  321.                     $Gac->setFczFlag6(9);
  322.                     $conditionMet true;
  323.                 } 
  324.                 if (strlen($Gac->getBprvcr()) > 20) {
  325.                     $Gac->setObservationFczFlag6('BPRVCR PLUS QUE 20: ' $Gac->getBprvcr());
  326.                     $Gac->setFczFlag6(9);
  327.                     $conditionMet true;
  328.                 }
  329.                 if ($Gac->getCur() != 'MAD') {
  330.                     $Gac->setObservationFczFlag6('DEVISE NON MAD' ' ' $Gac->getCur());
  331.                     $Gac->setFczFlag6(9);
  332.                     $conditionMet true;
  333.                 }
  334.                 
  335.                 $Year = (int) $Gac->getAccdat()->format('Y');
  336.                 // if ($Year < 2023 || $Year > 2025 || $Year == 2023) {
  337.                 if ($Year 2024 || $Year 2025 || $Year == 2024) {
  338.                     $Gac->setObservationFczFlag6('DIFFÉRENCE DE DATE DE 2025');
  339.                     $Gac->setFczFlag6(9);
  340.                     $conditionMet true;
  341.                 }
  342.                 if ($Gac->getDesvcr() && strpos($Gac->getDesvcr(), ';') !== false) {
  343.                     $Gac->setObservationFczFlag6('DÉSIGNATION AVEC POINT-VIRGULE');
  344.                     $Gac->setFczFlag6(9);
  345.                     $conditionMet true;
  346.                 }
  347.                 if ($Gac->getAccdat()->format('Y-m-d H:i:s') !== $Gac->getDuddat()->format('Y-m-d H:i:s') || $Gac->getAccdat()->format('Y-m-d H:i:s') !== $Gac->getRatdat()->format('Y-m-d H:i:s') ) {
  348.                     // dd($Gac->getAccdat(),$Gad->getAccdat());
  349.                     $Gac->setObservationFczFlag6('DIFFÉRENCE DATE');
  350.                     $Gac->setFczFlag6(9);
  351.                     $conditionMet true;
  352.                 }
  353.                 $typCheck $Gac->getTyp1();
  354.                 $sum "0";
  355.                 $matchingType  $this->em->getEntity()->getRepository(JOURNAL::class)->findType($typCheck);
  356.                 if ($matchingType) {
  357.                     $Gaccentryds  $Gac->getGaccentryds();
  358.                     // dd($Gaccentryds);
  359.                     if ($Gaccentryds->isEmpty()) {
  360.                         $Gac->setObservationFczFlag6('PIÈCE SANS DET');
  361.                         $Gac->setFczFlag6(9);
  362.                         $conditionMet true;
  363.                     }else {
  364.                         foreach ($Gaccentryds as $key => $Gad) {
  365.                             // dd($Gad);
  366.                             if ($Gac->getTyp1() !== $Gad->getTyp0()) {
  367.                                 $Gac->setObservationFczFlag6('TYPES NE SONT PAS LES MÊMES' ' ' .$Gac->getTyp1() . ' ' $Gad->getTyp0() );
  368.                                 $Gac->setFczFlag6(9);
  369.                                 $conditionMet true;
  370.                             }                        
  371.                             if ($Gac->getAccdat()->format('Y-m-d H:i:s') !== $Gad->getAccdat()->format('Y-m-d H:i:s')) {
  372.                                 // dd($Gac->getAccdat(),$Gad->getAccdat());
  373.                                 $Gac->setObservationFczFlag6('DIFFÉRENCE DE 2024');
  374.                                 $Gac->setFczFlag6(9);
  375.                                 $conditionMet true;
  376.                             }
  377.                             
  378.                             // dd("Hi date");
  379.                             if ($Gad->getAmtcur() < 0) {   
  380.                                 $Gac->setObservationFczFlag6('MONTANT NÉGATIF' ' ' $Gad->getAmtcur());
  381.                                 $Gac->setFczFlag6(9);
  382.                                 $conditionMet true;
  383.                             }
  384.                             if ($Gad->getSns() !== && $Gad->getSns() !== -1  ) {
  385.                                 $Gac->setObservationFczFlag6('SENS DIFFÉRENCE DE 1 ET -1' ' ' $Gad->getSns());
  386.                                 $Gac->setFczFlag6(9);
  387.                                 $conditionMet true;
  388.                             }
  389.                             $cceCheck     $Gad->getCce0();
  390.                             $matchingCce  $this->em->getEntity()->getRepository(Partenaire::class)->findCce($cceCheck);
  391.                             if (!$matchingCce) {
  392.                                 $Gac->setObservationFczFlag6('CCE N EXISTE PAS DANS SAGE' ' ' $cceCheck);
  393.                                 $Gac->setFczFlag6(9);
  394.                                 $conditionMet true;
  395.                             } 
  396.                             $accCheck     $Gad->getAcc();
  397.                             $cleanaccCheck str_replace(array("\r""\n"), ''$accCheck);
  398.                             $matchingAcc  $this->em->getEntity()->getRepository(CompteTier::class)->findAccByAcc($cleanaccCheck);
  399.                             if (!$matchingAcc) {
  400.                                 $Gac->setObservationFczFlag6('ACC N EXISTE PAS DANS SAGE' ' ' $Gad->getAcc());
  401.                                 $Gac->setFczFlag6(9);
  402.                                 $conditionMet true;
  403.                             } 
  404.                             foreach ($matchingAcc as $key => $value) {
  405.                                 if ($value['sac'] == '2') {
  406.                                     if (substr($Gad->getAcc(), 01) == '3') {
  407.                                         if ($Gad->getBpr()) {
  408.                                             $customerCheck $Gad->getBpr();
  409.                                             $cleanaccCheckCustomer str_replace(array("\r""\n"), ''$customerCheck);
  410.                                             $matchingCustomer  $this->em->getEntity()->getRepository(Bpartner::class)->findCustomer($cleanaccCheckCustomer);
  411.                                             if (!$matchingCustomer) {
  412.                                                 $Gac->setObservationFczFlag6('CLIENT N EXISTE PAS DANS SAGE ' ' ' $Gad->getBpr());
  413.                                                 $Gac->setFczFlag6(9);
  414.                                                 $conditionMet true;
  415.                                                 // if ($matchingCustomer->getActive() == 1) {
  416.                                                 //     // dd($matchingSupplier);
  417.                                                 //     $Gac->setObservationFczFlag6('CUSTOMER NOT ACTIVE IN SAGE' . ' ' . $Gad->getBpr());
  418.                                                 //     $Gac->setFczFlag6(9);
  419.                                                 //     $conditionMet = true;
  420.                                                 // }
  421.                                                 
  422.                                             }
  423.                                             elseif ($matchingCustomer?->getActive() === 1) {
  424.                                                 // dd($matchingCustomer);
  425.                                                 $Gac->setObservationFczFlag6('CLIENT NON ACTIF DANS SAGE' ' ' $Gad->getBpr());
  426.                                                 $Gac->setFczFlag6(9);
  427.                                                 $conditionMet true;
  428.                                             }
  429.                                         }else {
  430.                                             $Gac->setObservationFczFlag6('COMPTE CLIENT COLLECTIF SANS TIER' ' ' $Gad->getAcc());
  431.                                             $Gac->setFczFlag6(9);
  432.                                             $conditionMet true;
  433.                                         }
  434.                                     }if (substr($Gad->getAcc(), 01) == '4') {
  435.                                         if ($Gad->getBpr()) {
  436.                                             $supplierCheck    $Gad->getBpr();
  437.                                             $cleanaccCheckSupplier str_replace(array("\r""\n"), ''$supplierCheck);
  438.                                             $matchingSupplier $this->em->getEntity()->getRepository(Bpartner::class)->findSupplier($cleanaccCheckSupplier);
  439.                                             if (!$matchingSupplier) {
  440.                                                 $Gac->setObservationFczFlag6('FOURNISSEUR N EXISTE PAS DANS SAGE' ' ' $Gad->getBpr());
  441.                                                 $Gac->setFczFlag6(9);
  442.                                                 $conditionMet true;
  443.                                             }
  444.                                             elseif ($matchingSupplier->getActive() == 1) {
  445.                                                 $Gac->setObservationFczFlag6('FOURNISSEUR NON ACTIF DANS SAGE' ' ' $Gad->getBpr());
  446.                                                 $Gac->setFczFlag6(9);
  447.                                                 $conditionMet true;
  448.                                             }
  449.                                             //     dd($matchingSupplier);
  450.                                             // if ($matchingSupplier->getActive() == 1) {
  451.                                             //     // dd($matchingSupplier);
  452.                                             //     $Gac->setObservationFczFlag6('SUPPLIER NOT ACTIVE IN SAGE' . ' ' . $Gad->getBpr());
  453.                                             //     $Gac->setFczFlag6(9);
  454.                                             //     $conditionMet = true;
  455.                                             // }
  456.                                             // elseif($matchingSupplier->getActive() == null) {
  457.                                             //     $Gac->setObservationFczFlag6('SUPPLIER IS NUL' . ' ' . $Gad->getBpr());
  458.                                             //     $Gac->setFczFlag6(9);
  459.                                             //     $conditionMet = true;
  460.                                             // }
  461.                                         }else {
  462.                                             $Gac->setObservationFczFlag6('COMPTE FOURNISSEUR COLLECTIF SANS TIER' ' ' $Gad->getAcc());
  463.                                             $Gac->setFczFlag6(9);
  464.                                             $conditionMet true;
  465.                                         }
  466.                                     }
  467.                                 }
  468.                                 $all_acc substr($Gad->getAcc(), 01);
  469.                                 if ($all_acc == '5' || $all_acc == '6' || $all_acc == '7' || $all_acc == '2' || $all_acc == '1') {
  470.                                     if ($Gad->getBpr()) {
  471.                                         // dd($Gac->getBpr());
  472.                                         $Gac->setObservationFczFlag6('COMPTE' $Gad->getAcc() . 'AVEC TIER ' $Gad->getBpr());
  473.                                         $Gac->setFczFlag6(9);
  474.                                         $conditionMet true;
  475.                                     }
  476.                                 }
  477.                                 // if ($all_acc == '7' || $all_acc == '2' || $all_acc == '1') {
  478.                                 //     if ($Gad->getBpr()) {
  479.                                 //         $Gac->setObservationFczFlag6('ACC ' . $Gad->getAcc() . ' HAS TIER '. $Gad->getBpr());
  480.                                 //         $Gac->setFczFlag6(9);
  481.                                 //         $conditionMet = true;
  482.                                 //     }
  483.                                 // }
  484.                             }
  485.                             // $amtcur = round($Gad->getAmtcur(), 2);
  486.                             // if ($Gad->getSns() === -1) {
  487.                             //     $amtcur = -$amtcur;
  488.                             // }
  489.                         
  490.                             // $sum += $amtcur;
  491.                             // $amtcurFormatted = number_format($amtcur, 2, '.', ''); // Format as a number with two decimal places.
  492.                             // array_push($sumArray, $amtcurFormatted);
  493.                             $amtcur $Gad->getAmtcur();
  494.                             $sens $Gad->getSns();
  495.             
  496.                             $montant =$amtcur $sens;
  497.                             $sum += $montant;
  498.                         }
  499.                 }
  500.                 $finalBalance round($sum2); // Round to 2 decimal places for final balance
  501.                     if ($finalBalance != || $finalBalance != -) {
  502.                         $Gac->setObservationFczFlag6('PIECE DESEQUILIBREES' ' ' $finalBalance);
  503.                         $Gac->setFczFlag6(9);
  504.                         $conditionMet true;
  505.                     }
  506.                 }else {
  507.                     $Gac->setObservationFczFlag6('TYPE DOES NOT EXIST' ' ' $typCheck);
  508.                     $Gac->setFczFlag6(9);
  509.                     $conditionMet true;
  510.                 }
  511.                 // fcz_flag6 = 2 Piece Sans Probleme 
  512.                 if (!$conditionMet) {
  513.                     $Gac->setObservationFczFlag6('CONTROLLE DONE');
  514.                     $Gac->setFczFlag6(2);
  515.                 }
  516.                 $this->em->getEntity()->persist($Gac);
  517.             }
  518.             $this->em->getEntity()->flush();
  519.         return new Response('ok');
  520.     }
  521.     #[Route('/sage/inserted'name'app_sage_inserted')]
  522.     public function inserted()
  523.     {
  524.         try {
  525.             $this->em->getSage()->beginTransaction();
  526.             $this->em->getInterface()->beginTransaction();
  527.             $pieceCaImport $this->em->getEntity()->getRepository(outputGaccentries::class)->findCAUgouv();
  528.             // dd($pieceCaImport);
  529.             if ($pieceCaImport) {
  530.                 foreach ($pieceCaImport as $piece) {
  531.                     $piece->setFczFlag5(1);
  532.                     $piece->setFczFlag3(7);
  533.                     $piece->setFczFlag6(2);
  534.                     $adonixGaccentry = new sageGaccentries();
  535.                         $adonixGaccentry->setUPDTICK0("1");
  536.                         $adonixGaccentry->setTYP0($piece->getTyp());
  537.                         $adonixGaccentry->setNUM0($piece->getNum());
  538.                         $adonixGaccentry->setCPY0($piece->getCpy1());
  539.                         $adonixGaccentry->setFCY0($piece->getFcy1());
  540.                         $adonixGaccentry->setJOU0($piece->getJou());
  541.                         $adonixGaccentry->setFIY0(11);
  542.                         $adonixGaccentry->setPER0(12);
  543.                         $adonixGaccentry->setBOLLATO0('');
  544.                         $adonixGaccentry->setYREFE30('');
  545.                         $adonixGaccentry->setYREFE20('');
  546.                         $adonixGaccentry->setYREFE10('');
  547.                         $adonixGaccentry->setYREFE0($piece->getId());
  548.                         $adonixGaccentry->setACCDAT0($this->dateString($piece->getAccdat()));
  549.                         $adonixGaccentry->setENTDAT0($this->dateString($piece->getAccdat()));
  550.                         $adonixGaccentry->setVALDAT0($this->dateString($piece->getAccdat()));
  551.                         $adonixGaccentry->setDUDDAT0($this->dateString($piece->getAccdat()));
  552.                         $adonixGaccentry->setBANDAT0($this->dateString($piece->getAccdat()));
  553.                         $adonixGaccentry->setRATDAT0($this->dateString($piece->getAccdat()));
  554.                         $adonixGaccentry->setCAT0(1);
  555.                         $adonixGaccentry->setSTA0(1);
  556.                         $adonixGaccentry->setFNLPSTDAT0('1753-01-01 00:00:00.000');
  557.                         $adonixGaccentry->setORIMOD0(2);
  558.                         $adonixGaccentry->setDACDIA0('STDCO');
  559.                         $adonixGaccentry->setFLGDAS0(1);
  560.                         $adonixGaccentry->setFLGFUP0(1);
  561.                         $adonixGaccentry->setFLGPAZ0(4);
  562.                         $adonixGaccentry->setFLGREP0(1);
  563.                         $adonixGaccentry->setFLGGEN0(1);
  564.                         $adonixGaccentry->setTYPDUD0(2);
  565.                         $adonixGaccentry->setBANCIB0('');
  566.                         $adonixGaccentry->setCUR0('MAD');
  567.                         $adonixGaccentry->setTYPRAT0(1);
  568.                         $adonixGaccentry->setLED0('RFG');
  569.                         $adonixGaccentry->setLED1('RFA');
  570.                         $adonixGaccentry->setLED2('');
  571.                         $adonixGaccentry->setLED3('');
  572.                         $adonixGaccentry->setLED4('');
  573.                         $adonixGaccentry->setLED5('');
  574.                         $adonixGaccentry->setLED6('');
  575.                         $adonixGaccentry->setLED7('');
  576.                         $adonixGaccentry->setLED8('');
  577.                         $adonixGaccentry->setLED9('');
  578.                         $adonixGaccentry->setCURLED0('MAD');
  579.                         $adonixGaccentry->setCURLED1('MAD');
  580.                         $adonixGaccentry->setCURLED2('');
  581.                         $adonixGaccentry->setCURLED3('');
  582.                         $adonixGaccentry->setCURLED4('');
  583.                         $adonixGaccentry->setCURLED5('');
  584.                         $adonixGaccentry->setCURLED6('');
  585.                         $adonixGaccentry->setCURLED7('');
  586.                         $adonixGaccentry->setCURLED8('');
  587.                         $adonixGaccentry->setCURLED9('');
  588.                         $adonixGaccentry->setRATMLT0(1);
  589.                         $adonixGaccentry->setRATMLT1(0);
  590.                         $adonixGaccentry->setRATMLT2(0);
  591.                         $adonixGaccentry->setRATMLT3(0);
  592.                         $adonixGaccentry->setRATMLT4(0);
  593.                         $adonixGaccentry->setRATMLT5(0);
  594.                         $adonixGaccentry->setRATMLT6(0);
  595.                         $adonixGaccentry->setRATMLT7(0);
  596.                         $adonixGaccentry->setRATMLT8(0);
  597.                         $adonixGaccentry->setRATMLT9(0);
  598.                         $adonixGaccentry->setRATDIV0(1);
  599.                         $adonixGaccentry->setRATDIV1(0);
  600.                         $adonixGaccentry->setRATDIV2(0);
  601.                         $adonixGaccentry->setRATDIV3(0);
  602.                         $adonixGaccentry->setRATDIV4(0);
  603.                         $adonixGaccentry->setRATDIV5(0);
  604.                         $adonixGaccentry->setRATDIV6(0);
  605.                         $adonixGaccentry->setRATDIV7(0);
  606.                         $adonixGaccentry->setRATDIV8(0);
  607.                         $adonixGaccentry->setRATDIV9(0);
  608.                         $adonixGaccentry->setDESVCR0($piece->getDesvcr());
  609.                         $adonixGaccentry->setREF0($piece->getRef());
  610.                         $adonixGaccentry->setBPRVCR0('');
  611.                         $adonixGaccentry->setBPRDATVCR0('1753-01-01 00:00:00.000');
  612.                         $adonixGaccentry->setREFSIM0('');
  613.                         $adonixGaccentry->setREFINT0('');
  614.                         $adonixGaccentry->setNUMDCL0(0);
  615.                         $adonixGaccentry->setRVS0(0);
  616.                         $adonixGaccentry->setRVSDAT0('1753-01-01 00:00:00.000');
  617.                         $adonixGaccentry->setRVSORITYP0('');
  618.                         $adonixGaccentry->setRVSORINUM0('');
  619.                         $adonixGaccentry->setEXPNUM0(1);
  620.                         $adonixGaccentry->setCREDAT0((new \DateTime())->format('Y-m-d'));
  621.                         $adonixGaccentry->setCREUSR0('AHAZ');
  622.                         $adonixGaccentry->setUPDDAT0((new \DateTime())->format('Y-m-d'));
  623.                         $adonixGaccentry->setUPDUSR0('AHAZ');
  624.                         $adonixGaccentry->setORIGIN0(3);
  625.                         $adonixGaccentry->setCREDATTIM0((new \DateTime())->format('Y-m-d H:i:s'));  // For current date and time
  626.                         $adonixGaccentry->setUPDDATTIM0((new \DateTime())->format('Y-m-d H:i:s'));
  627.                         $adonixGaccentry->setAUUID0(3);
  628.                         $adonixGaccentry->setFNLPSTNUM0('');
  629.                         $adonixGaccentry->setFNLPSTNUM1('');
  630.                         $adonixGaccentry->setFNLPSTNUM2('');
  631.                         $adonixGaccentry->setFNLPSTNUM3('');
  632.                         $adonixGaccentry->setFNLPSTNUM4('');
  633.                         $adonixGaccentry->setFNLPSTNUM5('');
  634.                         $adonixGaccentry->setFNLPSTNUM6('');
  635.                         $adonixGaccentry->setFNLPSTNUM7('');
  636.                         $adonixGaccentry->setFNLPSTNUM8('');
  637.                         $adonixGaccentry->setFNLPSTNUM9('');
  638.                         $adonixGaccentry->setPJT0('');
  639.                         $adonixGaccentry->setORICOD0("YGASANA");
  640.                         $adonixGaccentry->setYPCNUM0($piece->getCode());
  641.                         $adonixGaccentry->setYFLG0(0);
  642.                     $this->em->getAdonix()->persist($adonixGaccentry);
  643.                     foreach ($piece->getGaccentryds() as $key => $det) {
  644.                         $adonixGaccentrydPcg = new sageGaccentryd();
  645.                             $adonixGaccentrydPcg->setUPDTICK0(1);
  646.                             $adonixGaccentrydPcg->setTYP0($det->getTyp0());
  647.                             $adonixGaccentrydPcg->setNUM0($det->getNum());
  648.                             $adonixGaccentrydPcg->setLIN0($det->getLin());
  649.                             $adonixGaccentrydPcg->setLEDTYP0(1);
  650.                             $adonixGaccentrydPcg->setLED0('RFG');
  651.                             $adonixGaccentrydPcg->setACCNUM0($det->getPcg());
  652.                             $adonixGaccentrydPcg->setCHRNUM0('');
  653.                             $adonixGaccentrydPcg->setIDTLIN0($det->getLin());
  654.                             $adonixGaccentrydPcg->setCPY0($piece->getCpy1());
  655.                             $adonixGaccentrydPcg->setFCYLIN0($piece->getFcy1());
  656.                             $adonixGaccentrydPcg->setACCDAT0($this->dateString($piece->getAccdat()));
  657.                             $adonixGaccentrydPcg->setFIY0(11);
  658.                             $adonixGaccentrydPcg->setPER0(12);
  659.                             $adonixGaccentrydPcg->setCOA0('PCG');
  660.                             $adonixGaccentrydPcg->setSAC0($det->getSac() ?? '');
  661.                             $adonixGaccentrydPcg->setACC0($det->getAcc());
  662.                             $adonixGaccentrydPcg->setBPR0($det->getBpr() ?? '');
  663.                             $adonixGaccentrydPcg->setDSP0('');
  664.                             $adonixGaccentrydPcg->setSNS0($det->getSns());
  665.                             $adonixGaccentrydPcg->setCUR0('MAD');
  666.                             $adonixGaccentrydPcg->setAMTCUR0($det->getamtcur());
  667.                             $adonixGaccentrydPcg->setCURLED0('MAD');
  668.                             $adonixGaccentrydPcg->setAMTLED0($det->getamtcur());
  669.                             $adonixGaccentrydPcg->setAMTFLG0(0);
  670.                             $adonixGaccentrydPcg->setAMTLED10(0);
  671.                             $adonixGaccentrydPcg->setUOM0('');
  672.                             $adonixGaccentrydPcg->setQTY0(1);
  673.                             $adonixGaccentrydPcg->setDES0($det->getDes());
  674.                             $adonixGaccentrydPcg->setREFINTLIN0('');
  675.                             $adonixGaccentrydPcg->setOFFACC0('');
  676.                             $adonixGaccentrydPcg->setCSLCOD0('');
  677.                             $adonixGaccentrydPcg->setCSLFLO0('');
  678.                             $adonixGaccentrydPcg->setSTT10('');
  679.                             $adonixGaccentrydPcg->setSTT20('');
  680.                             $adonixGaccentrydPcg->setSTT30('');
  681.                             $adonixGaccentrydPcg->setMTC0('');
  682.                             $adonixGaccentrydPcg->setMTCDAT0('1753-01-01 00:00:00');
  683.                             $adonixGaccentrydPcg->setMTCDATMIN0('1753-01-01 00:00:00');
  684.                             $adonixGaccentrydPcg->setMTCDATMAX0('1753-01-01 00:00:00');
  685.                             $adonixGaccentrydPcg->setFLGMTC0(0);
  686.                             $adonixGaccentrydPcg->setFREREF0($det->getFreref0() ?? '');
  687.                             $adonixGaccentrydPcg->setCHK0('');
  688.                             $adonixGaccentrydPcg->setCHKDAT0('1753-01-01 00:00:00');
  689.                             $adonixGaccentrydPcg->setMRK0('');
  690.                             $adonixGaccentrydPcg->setTAX0('');
  691.                             $adonixGaccentrydPcg->setTAX20('');
  692.                             $adonixGaccentrydPcg->setTAX30('');
  693.                             $adonixGaccentrydPcg->setAMTVAT0(0);
  694.                             $adonixGaccentrydPcg->setINDEDVAT0(0);
  695.                             $adonixGaccentrydPcg->setEXPNUM0(1);
  696.                             $adonixGaccentrydPcg->setACCNUMORI0(0);
  697.                             $adonixGaccentrydPcg->setACCNUMDOE0(0);
  698.                             $adonixGaccentrydPcg->setCAPFLOTYP0('');
  699.                             $adonixGaccentrydPcg->setVATRAT0(0);
  700.                             $adonixGaccentrydPcg->setVATDEDRAT0(0);
  701.                             $adonixGaccentrydPcg->setCREDATTIM0((new \DateTime())->format('Y-m-d H:i:s'));
  702.                             $adonixGaccentrydPcg->setUPDDATTIM0((new \DateTime())->format('Y-m-d H:i:s'));
  703.                             $adonixGaccentrydPcg->setAUUID0(3);
  704.                             $adonixGaccentrydPcg->setCREUSR0('AHAZ');
  705.                             $adonixGaccentrydPcg->setUPDUSR0('AHAZ');
  706.                             $adonixGaccentrydPcg->setCSLBPR0('');
  707.                             $adonixGaccentrydPcg->setPJTLIN0('');
  708.                             $adonixGaccentrydPcg->setPCCCOD0('');
  709.                             $adonixGaccentrydPcg->setBSITRS0('');
  710.                             $adonixGaccentrydPcg->setYLETTR0('');
  711.                             $adonixGaccentrydPcg->setYBPCANC0('');
  712.                             $adonixGaccentrydPcg->setYREFE0($piece->getId());
  713.                             $adonixGaccentrydPcg->setYREFE10($det->getId());
  714.                             $adonixGaccentrydPcg->setYREFE20('');
  715.                             $adonixGaccentrydPcg->setYREFE30(mb_substr($det->getFczAccLibelle() ?? ''055));
  716.                             $adonixGaccentrydPcg->setAMTCURHIS0(0);
  717.                             $adonixGaccentrydPcg->setHISACC0($det->getAcc());
  718.                         $this->em->getAdonix()->persist($adonixGaccentrydPcg);
  719.                         $adonixGaccentrydPca = clone $adonixGaccentrydPcg;
  720.                             $adonixGaccentrydPca->setBPR0('');
  721.                             $adonixGaccentrydPca->setSAC0('');
  722.                             $adonixGaccentrydPca->setLED0('RFA');
  723.                             $adonixGaccentrydPca->setCOA0('PCA');
  724.                             $adonixGaccentrydPca->setACCNUM0($det->getPca());
  725.                             $adonixGaccentrydPca->setLEDTYP0(2);
  726.                         $this->em->getAdonix()->persist($adonixGaccentrydPca);
  727.                         $adonixGaccentrya = new GACCENTRYA();
  728.                             $adonixGaccentrya->setUPDTICK0(1);
  729.                             $adonixGaccentrya->setTYP0($det->getTyp0());
  730.                             $adonixGaccentrya->setNUM0($det->getNum());
  731.                             $adonixGaccentrya->setLIN0($det->getLin());
  732.                             $adonixGaccentrya->setLEDTYP0(2);
  733.                             $adonixGaccentrya->setANALIN0(1);
  734.                             $adonixGaccentrya->setIDTLIN0($det->getLin());
  735.                             $adonixGaccentrya->setLED0('RFA');
  736.                             $adonixGaccentrya->setCPY0($piece->getCpy1());
  737.                             $adonixGaccentrya->setFCYLIN0($piece->getFcy1());
  738.                             $adonixGaccentrya->setACCDAT0($this->dateString($piece->getAccdat()));
  739.                             $adonixGaccentrya->setACCNUM0($det->getPca());
  740.                             $adonixGaccentrya->setCOA0('PCA');
  741.                             $adonixGaccentrya->setACC0($det->getAcc());
  742.                             $adonixGaccentrya->setBPR0('');
  743.                             $adonixGaccentrya->setDIE0('CCT');
  744.                             $adonixGaccentrya->setDIE1('');
  745.                             $adonixGaccentrya->setDIE2('');
  746.                             $adonixGaccentrya->setDIE3('');
  747.                             $adonixGaccentrya->setDIE4('');
  748.                             $adonixGaccentrya->setDIE5('');
  749.                             $adonixGaccentrya->setDIE6('');
  750.                             $adonixGaccentrya->setDIE7('');
  751.                             $adonixGaccentrya->setDIE8('');
  752.                             $adonixGaccentrya->setCCE0($det->getcce0());
  753.                             $adonixGaccentrya->setCCE1('');
  754.                             $adonixGaccentrya->setCCE2('');
  755.                             $adonixGaccentrya->setCCE3('');
  756.                             $adonixGaccentrya->setCCE4('');
  757.                             $adonixGaccentrya->setCCE5('');
  758.                             $adonixGaccentrya->setCCE6('');
  759.                             $adonixGaccentrya->setCCE7('');
  760.                             $adonixGaccentrya->setCCE8('');
  761.                             $adonixGaccentrya->setSNS0($det->getSns());
  762.                             $adonixGaccentrya->setCUR0('MAD');
  763.                             $adonixGaccentrya->setAMTCUR0($det->getamtcur());
  764.                             $adonixGaccentrya->setCURLED0('MAD');
  765.                             $adonixGaccentrya->setAMTLED0($det->getamtcur());
  766.                             $adonixGaccentrya->setUOM0('');
  767.                             $adonixGaccentrya->setQTY0(0);
  768.                             $adonixGaccentrya->setACCNUMDOE0(0);
  769.                             $adonixGaccentrya->setCREDATTIM0((new \DateTime())->format('Y-m-d H:i:s'));
  770.                             $adonixGaccentrya->setUPDDATTIM0((new \DateTime())->format('Y-m-d H:i:s'));
  771.                             $adonixGaccentrya->setAUUID0(3);
  772.                             $adonixGaccentrya->setCREUSR0('ADMIN');
  773.                             $adonixGaccentrya->setUPDUSR0('ADMIN');
  774.                             $adonixGaccentrya->setYREFE0(0);
  775.                             $adonixGaccentrya->setYREFE10(0);
  776.                             $adonixGaccentrya->setYREFE20('');
  777.                             $adonixGaccentrya->setYREFE30('');
  778.                             $adonixGaccentrya->setAMTCURHIS0(0);
  779.                             $adonixGaccentrya->setHISACC0('');
  780.                         $this->em->getAdonix()->persist($adonixGaccentrya);
  781.                         if (!empty($det->getBpr())) {
  782.                             // dd("gaccdudate");
  783.                             $ACCNUM1 $det->getPcg();
  784.                             $A7 "1";
  785.                             $NUMDUD_0 $ACCNUM1 '/' $A7;
  786.                             $adonixGaccdudate = new GACCDUDATE();
  787.                                 $adonixGaccdudate->setUPDTICK0(1);
  788.                                 $adonixGaccdudate->setTYP0($det->getTyp0());
  789.                                 $adonixGaccdudate->setNUM0($det->getNum());
  790.                                 $adonixGaccdudate->setLIG0($det->getLin());
  791.                                 $adonixGaccdudate->setDUDLIG0(1);
  792.                                 $adonixGaccdudate->setACCNUM0($det->getPcg());
  793.                                 $adonixGaccdudate->setCPY0($piece->getCpy1());
  794.                                 $adonixGaccdudate->setFCY0($piece->getFcy1());
  795.                                 $adonixGaccdudate->setCUR0('MAD');
  796.                                 $adonixGaccdudate->setSAC0($det->getSac());
  797.                                 $adonixGaccdudate->setBPR0($det->getBpr());
  798.                                 $adonixGaccdudate->setBPRTYP0(2);
  799.                                 $adonixGaccdudate->setBPRPAY0($det->getBpr());
  800.                                 $adonixGaccdudate->setBPAPAY0('A01');
  801.                                 $adonixGaccdudate->setDUDDAT0($this->dateString($piece->getAccdat()));
  802.                                 $adonixGaccdudate->setPAM0('CHQ');
  803.                                 $adonixGaccdudate->setPAMTYP0(1);
  804.                                 $adonixGaccdudate->setDEP0('');
  805.                                 $adonixGaccdudate->setSNS0($det->getSns());
  806.                                 $adonixGaccdudate->setAMTCUR0($det->getAmtcur());
  807.                                 $adonixGaccdudate->setAMTLOC0($det->getAmtcur());
  808.                                 $adonixGaccdudate->setPAYCUR0(0);
  809.                                 $adonixGaccdudate->setPAYLOC0(0);
  810.                                 $adonixGaccdudate->setTMPCUR0(0);
  811.                                 $adonixGaccdudate->setTMPLOC0(0);
  812.                                 $adonixGaccdudate->setFLGFUP0(0);
  813.                                 $adonixGaccdudate->setLEVFUP0(0);
  814.                                 $adonixGaccdudate->setDATFUP0('1753-01-01 00:00:00');
  815.                                 $adonixGaccdudate->setDPTCOD0('');
  816.                                 $adonixGaccdudate->setFLGPAZ0(4);
  817.                                 $adonixGaccdudate->setSOI0(1);
  818.                                 $adonixGaccdudate->setSOINUM0('');
  819.                                 $adonixGaccdudate->setDUDSTA0(2);
  820.                                 $adonixGaccdudate->setDINAMT0(0);
  821.                                 $adonixGaccdudate->setIBDAMT0(0);
  822.                                 $adonixGaccdudate->setVAT0(0);
  823.                                 $adonixGaccdudate->setFIY0(11);
  824.                                 $adonixGaccdudate->setPER0(12);
  825.                                 $adonixGaccdudate->setEXPSENDAT0('1753-01-01 00:00:00');
  826.                                 $adonixGaccdudate->setSENDAT0('1753-01-01 00:00:00');
  827.                                 $adonixGaccdudate->setSENINS0(0);
  828.                                 $adonixGaccdudate->setBPRFCT0('');
  829.                                 $adonixGaccdudate->setFCTVCR0('');
  830.                                 $adonixGaccdudate->setFLGCLE0(1);
  831.                                 $adonixGaccdudate->setPAYDAT0('1753-01-01 00:00:00');
  832.                                 $adonixGaccdudate->setTYPDUD0(3);
  833.                                 $adonixGaccdudate->setNUMDUD0($NUMDUD_0);
  834.                                 $adonixGaccdudate->setCREDAT0((new \DateTime())->format('Y-m-d'));
  835.                                 $adonixGaccdudate->setCREUSR0('AHAZ');
  836.                                 $adonixGaccdudate->setCREDATTIM0((new \DateTime())->format('Y-m-d H:i:s'));
  837.                                 $adonixGaccdudate->setUPDDATTIM0((new \DateTime())->format('Y-m-d H:i:s'));
  838.                                 $adonixGaccdudate->setAUUID0(3);
  839.                                 $adonixGaccdudate->setUPDUSR0('AHAZ');
  840.                                 $adonixGaccdudate->setUMRNUM0('');
  841.                                 $adonixGaccdudate->setBELVCS0('');
  842.                                 $adonixGaccdudate->setBIDNUMMAN0('');
  843.                                 $adonixGaccdudate->setBADBTRULE0(0);
  844.                                 $adonixGaccdudate->setYREFE0(0);
  845.                                 $adonixGaccdudate->setYREFE10(0);
  846.                                 $adonixGaccdudate->setYREFE20('');
  847.                                 $adonixGaccdudate->setYREFE30('');
  848.                                 $adonixGaccdudate->setAMTCURHIS0(0);
  849.                                 $adonixGaccdudate->setHISACC0('');
  850.                             $this->em->getAdonix()->persist($adonixGaccdudate);
  851.                             // dd("gaccdudateHi");
  852.                         }else {
  853.                             continue;
  854.                         }
  855.                     }
  856.                 }
  857.             }
  858.             // dd($adonixGaccdudate);
  859.             $this->em->getAdonix()->flush();
  860.             $this->em->getEntity()->flush();
  861.             $this->em->getInterface()->commit();
  862.         } catch (Exception $e) {
  863.             // dd($e);
  864.             $this->em->getInterface()->rollBack();
  865.             return new JsonResponse("Error: " $e->getMessage());
  866.         }
  867.         return new JsonResponse('ok');
  868.     }
  869.     function dateString($date){
  870.                 
  871.         if($date)
  872.             if ($date->format('Y') == '-0001' )  return '';
  873.             else return $date->format('Y-m-d') ;
  874.         else return '';
  875.     }
  876. }