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