Beispiel #1
0
 /**
  * Form builder
  *
  * @param FormBuilderInterface $builder
  * @param array $options
  *
  * @return null
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $this->sale = $options['sale'];
     if (null == $this->sale) {
         $builder->add('sale', EntityType::class, array('label' => 'SecondatVat.sale.label', 'class' => 'AcfDataBundle:Sale', 'query_builder' => function (SaleRepository $sr) {
             return $sr->createQueryBuilder('s')->orderBy('s.number', 'ASC');
         }, 'choice_label' => 'number', 'multiple' => false, 'by_reference' => true, 'required' => true));
     } else {
         $saleId = $this->sale->getId();
         $builder->add('sale', EntityidType::class, array('label' => 'SecondatVat.sale.label', 'class' => 'AcfDataBundle:Sale', 'query_builder' => function (SaleRepository $sr) use($saleId) {
             return $sr->createQueryBuilder('s')->where('s.id = :id')->setParameter('id', $saleId)->orderBy('s.number', 'ASC');
         }, 'choice_label' => 'id', 'multiple' => false, 'by_reference' => true, 'required' => true));
     }
     $builder->add('vat', NumberType::class, array('label' => 'SecondaryVat.vat.label'));
     $builder->add('balanceTtc', NumberType::class, array('label' => 'SecondaryVat.balanceTtc.label'));
     $builder->add('balanceNet', NumberType::class, array('label' => 'SecondaryVat.balanceNet.label'));
     $builder->add('vatInfo', ChoiceType::class, array('label' => 'SecondaryVat.vatInfo.label', 'choices_as_values' => true, 'choices' => SecondaryVat::choiceVatInfo(), 'attr' => array('choice_label_trans' => true)));
 }
 /**
  * Form builder
  *
  * @param FormBuilderInterface $builder
  * @param array $options
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->add('validated', ChoiceType::class, array('label' => 'Sale.validated.label', 'choices_as_values' => true, 'choices' => Sale::choiceValidated(), 'expanded' => true, 'attr' => array('choice_label_trans' => true)));
 }
 /**
  * Form builder
  *
  * @param FormBuilderInterface $builder
  * @param array $options
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->add('paymentType', ChoiceType::class, array('label' => 'Sale.paymentType.label', 'choices_as_values' => true, 'choices' => Sale::choicePaymentType(), 'attr' => array('choice_label_trans' => true)));
 }
 /**
  *
  * @param string $uid
  *
  * @return Response
  *
  */
 public function editPostAction($uid)
 {
     $urlFrom = $this->getReferer();
     if (null == $urlFrom || trim($urlFrom) == '') {
         $urlFrom = $this->generateUrl('_admin_company_list');
     }
     $em = $this->getEntityManager();
     try {
         $mbsale = $em->getRepository('AcfDataBundle:MBSale')->find($uid);
         if (null == $mbsale) {
             $this->flashMsgSession('warning', $this->translate('MBSale.edit.notfound'));
         } else {
             $traces = $em->getRepository('AcfDataBundle:Trace')->getAllByEntityId($mbsale->getId(), Trace::AE_MBSALE);
             $this->gvars['traces'] = array_reverse($traces);
             $mbsaleUpdateCountForm = $this->createForm(MBSaleUpdateCountTForm::class, $mbsale);
             $sale = new Sale();
             $sale->setMonthlyBalance($mbsale);
             $saleNewForm = $this->createForm(SaleNewTForm::class, $sale, array('monthlybalance' => $mbsale));
             $saleImportForm = $this->createForm(SaleImportTForm::class);
             $mbsaleUpdateDocsForm = $this->createForm(MBSaleUpdateDocsTForm::class, $mbsale, array('company' => $mbsale->getCompany()));
             $doc = new Doc();
             $doc->setCompany($mbsale->getCompany());
             $docNewForm = $this->createForm(DocNewTForm::class, $doc, array('company' => $mbsale->getCompany()));
             $this->gvars['tabActive'] = $this->getSession()->get('tabActive', 2);
             $this->getSession()->remove('tabActive');
             $this->gvars['stabActive'] = $this->getSession()->get('stabActive', 1);
             $this->getSession()->remove('stabActive');
             $request = $this->getRequest();
             $reqData = $request->request->all();
             $cloneMBSale = clone $mbsale;
             if (isset($reqData['SaleImportForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $this->gvars['stabActive'] = 1;
                 $this->getSession()->set('stabActive', 1);
                 $saleImportForm->handleRequest($request);
                 if ($saleImportForm->isValid()) {
                     ini_set('memory_limit', '4096M');
                     ini_set('max_execution_time', '0');
                     $extension = $saleImportForm['excel']->getData()->guessExtension();
                     if ($extension == 'zip') {
                         $extension = 'xlsx';
                     }
                     $filename = uniqid() . '.' . $extension;
                     $saleImportForm['excel']->getData()->move($this->getParameter('adapter_files'), $filename);
                     $fullfilename = $this->getParameter('adapter_files');
                     $fullfilename .= '/' . $filename;
                     $excelObj = $this->get('phpexcel')->createPHPExcelObject($fullfilename);
                     $log = '';
                     $iterator = $excelObj->getWorksheetIterator();
                     $activeSheetIndex = -1;
                     $i = 0;
                     foreach ($iterator as $worksheet) {
                         $worksheetTitle = $worksheet->getTitle();
                         $highestRow = $worksheet->getHighestRow();
                         // e.g. 10
                         $highestColumn = $worksheet->getHighestColumn();
                         // e.g 'F'
                         $highestColumnIndex = \PHPExcel_Cell::columnIndexFromString($highestColumn);
                         $log .= "Feuille : '" . $worksheetTitle . "' trouvée contenant " . $highestRow . ' lignes et ' . $highestColumnIndex . ' colonnes avec comme plus grand index ' . $highestColumn . ' <br>';
                         if (\trim($worksheetTitle) == 'Sage') {
                             $activeSheetIndex = $i;
                         }
                         $i++;
                     }
                     if ($activeSheetIndex == -1) {
                         $log .= "Aucune Feuille de Titre 'Sage' trouvée tentative d'import depuis le première Feuille<br>";
                         $activeSheetIndex = 0;
                     }
                     $excelObj->setActiveSheetIndex($activeSheetIndex);
                     $customersConstStr = $em->getRepository('AcfDataBundle:ConstantStr')->findOneBy(array('name' => 'customersPrefix'));
                     if (null == $customersConstStr) {
                         $customersConstStr = new ConstantStr();
                         $customersConstStr->setName('customersPrefix');
                         $customersConstStr->setValue('411');
                         $em->persist($customersConstStr);
                         $em->flush();
                     }
                     $customersPrefix = $customersConstStr->getValue();
                     $customersPrefixNum = \intval($customersPrefix) * 1000000000;
                     $worksheet = $excelObj->getActiveSheet();
                     $highestRow = $worksheet->getHighestRow();
                     $lineRead = 0;
                     $salesNew = 0;
                     $lineUnprocessed = 0;
                     $lineError = 0;
                     $company = $mbsale->getCompany();
                     $accounts = $em->getRepository('AcfDataBundle:Account')->getAllByCompany($company);
                     $customers = $em->getRepository('AcfDataBundle:Customer')->getAllByCompany($company);
                     $withholdings = $em->getRepository('AcfDataBundle:Withholding')->getAllByCompany($company);
                     $prevbill = null;
                     $haspreverror = false;
                     for ($row = 1; $row <= $highestRow; $row++) {
                         $lineRead++;
                         $dtActivation = \PHPExcel_Shared_Date::ExcelToPHPObject($worksheet->getCellByColumnAndRow(1, $row)->getValue());
                         $bill = \trim(\strval($worksheet->getCellByColumnAndRow(2, $row)->getValue()));
                         $customerNum = \intval($worksheet->getCellByColumnAndRow(4, $row)->getValue());
                         $label = \trim(\strval($worksheet->getCellByColumnAndRow(5, $row)->getValue()));
                         $vat = \floatval($worksheet->getCellByColumnAndRow(7, $row)->getValue());
                         $stamp = \floatval($worksheet->getCellByColumnAndRow(8, $row)->getValue());
                         $balanceTtc = \floatval($worksheet->getCellByColumnAndRow(9, $row)->getValue());
                         $vatInfo = \trim(\strval($worksheet->getCellByColumnAndRow(10, $row)->getValue()));
                         $regime = \trim(\strval($worksheet->getCellByColumnAndRow(11, $row)->getValue()));
                         $withholdingValue = \trim(\strval($worksheet->getCellByColumnAndRow(13, $row)->getValue() * 100));
                         $balanceNet = \floatval($worksheet->getCellByColumnAndRow(14, $row)->getValue());
                         $paymentType = \trim(\strval($worksheet->getCellByColumnAndRow(15, $row)->getValue()));
                         $dtPayment = \PHPExcel_Shared_Date::ExcelToPHPObject($worksheet->getCellByColumnAndRow(16, $row)->getValue());
                         $accountLabel = \trim(\strval($worksheet->getCellByColumnAndRow(17, $row)->getValue()));
                         $status = \trim(\strval($worksheet->getCellByColumnAndRow(18, $row)->getValue()));
                         $otherInfos = \trim(\strval($worksheet->getCellByColumnAndRow(19, $row)->getValue()));
                         if ($customerNum != '' && \is_numeric($customerNum)) {
                             $customerNum = \intval($customerNum) - $customersPrefixNum;
                         }
                         $haserror = false;
                         if (null == $dtActivation) {
                             $haserror = true;
                             $log .= 'ligne ' . $lineRead . ", erreur : Date d'activation<br>";
                         }
                         if ($bill == '') {
                             $haserror = true;
                             $log .= 'ligne ' . $lineRead . ', erreur : Numéro Facture<br>';
                         }
                         if ($customerNum == '' || $customerNum <= 0) {
                             $haserror = true;
                             $oldcustomnum = $worksheet->getCellByColumnAndRow(4, $row)->getValue();
                             $log .= 'ligne ' . $lineRead . ', erreur : Numéro Client (' . $oldcustomnum . ')<br>';
                         } else {
                             $customer = null;
                             $knownCustomer = false;
                             foreach ($customers as $s) {
                                 if ($s->getNumber() == $customerNum) {
                                     $knownCustomer = true;
                                     $customer = $s;
                                 }
                             }
                             if ($knownCustomer == false) {
                                 $haserror = true;
                                 $log .= 'ligne ' . $lineRead . ', erreur : Client Inconnu<br>';
                             }
                         }
                         if ($label == '') {
                             $haserror = true;
                             $log .= 'ligne ' . $lineRead . ', erreur : Libélé<br>';
                         }
                         if ($vat < 0) {
                             $haserror = true;
                             $log .= 'ligne ' . $lineRead . ', erreur : TVA<br>';
                         }
                         if ($stamp < 0) {
                             $haserror = true;
                             $log .= 'ligne ' . $lineRead . ', erreur : Timbre<br>';
                         }
                         if ($balanceTtc < 0) {
                             $haserror = true;
                             $log .= 'ligne ' . $lineRead . ', erreur : TTC<br>';
                         }
                         if ($vatInfo == $this->translate('Transaction.vatInfo.0')) {
                             $vatInfo = 0;
                         } elseif ($vatInfo == $this->translate('Transaction.vatInfo.6')) {
                             $vatInfo = 6;
                         } elseif ($vatInfo == $this->translate('Transaction.vatInfo.12')) {
                             $vatInfo = 12;
                         } elseif ($vatInfo == $this->translate('Transaction.vatInfo.18')) {
                             $vatInfo = 18;
                         } else {
                             $vatInfo = 0;
                             $log .= 'ligne ' . $lineRead . ', erreur (ignorée) : TVA PR INFO inconnu => ' . $this->translate('Transaction.vatInfo.0') . '<br>';
                         }
                         if ($regime == $this->translate('Sale.regime.0')) {
                             $regime = 0;
                         } elseif ($regime == $this->translate('Sale.regime.1')) {
                             $regime = 1;
                         } elseif ($regime == $this->translate('Sale.regime.2')) {
                             $regime = 2;
                         } elseif ($regime == $this->translate('Sale.regime.3')) {
                             $regime = 3;
                         } else {
                             $regime = 0;
                             $log .= 'ligne ' . $lineRead . ', erreur (ignorée) : Régime inconnu => ' . $this->translate('Sale.regime.0') . '<br>';
                         }
                         $withholding = null;
                         $knownWithholding = false;
                         foreach ($withholdings as $w) {
                             if ($w->getValue() == $withholdingValue || $w->getLabel() == $withholdingValue) {
                                 $knownWithholding = true;
                                 $withholding = $w;
                             }
                         }
                         if ($knownWithholding == false) {
                             $haserror = true;
                             $log .= 'ligne ' . $lineRead . ', erreur : Retenue Inconnue ' . $withholdingValue . '<br>';
                         }
                         if ($balanceNet < 0) {
                             $haserror = true;
                             $log .= 'ligne ' . $lineRead . ', erreur : Net à Encaisser<br>';
                         }
                         if ($paymentType == $this->translate('Transaction.paymentType.0')) {
                             $paymentType = 0;
                         } elseif ($paymentType == $this->translate('Transaction.paymentType.1')) {
                             $paymentType = 1;
                         } elseif ($paymentType == $this->translate('Transaction.paymentType.2')) {
                             $paymentType = 2;
                         } elseif ($paymentType == $this->translate('Transaction.paymentType.3')) {
                             $paymentType = 3;
                         } elseif ($paymentType == $this->translate('Transaction.paymentType.4')) {
                             $paymentType = 4;
                         } else {
                             $paymentType = 0;
                             $log .= 'ligne ' . $lineRead . ", erreur (ignorée) : Type d'Encaissement inconnu => " . $this->translate('Transaction.paymentType.0') . '<br>';
                         }
                         if (null == $dtPayment) {
                             $haserror = true;
                             $log .= 'ligne ' . $lineRead . ", erreur : Date d'Encaissement<br>";
                         }
                         $account = null;
                         $knownAccount = false;
                         foreach ($accounts as $a) {
                             if ($a->getLabel() == $accountLabel) {
                                 $knownAccount = true;
                                 $account = $a;
                             }
                         }
                         if ($knownAccount == false) {
                             $haserror = true;
                             $log .= 'ligne ' . $lineRead . ', erreur : Banque/Caisse Inconnue<br>';
                         }
                         if ($status == $this->translate('Transaction.transactionStatus.0')) {
                             $status = 0;
                         } elseif ($status == $this->translate('Transaction.transactionStatus.1')) {
                             $status = 1;
                         } elseif ($status == $this->translate('Transaction.transactionStatus.10')) {
                             $status = 10;
                         } else {
                             $status = 0;
                             $log .= 'ligne ' . $lineRead . ', erreur (ignorée) : Etat inconnu => ' . $this->translate('Transaction.transactionStatus.0') . '<br>';
                         }
                         if ($haserror == false) {
                             if ($bill != $prevbill) {
                                 $sale = $em->getRepository('AcfDataBundle:Sale')->findOneBy(array('monthlyBalance' => $mbsale, 'bill' => $bill));
                                 if (null == $sale) {
                                     $salesNew++;
                                     $sale = new Sale();
                                     $sale->setMonthlyBalance($mbsale);
                                     $sale->setNumber($mbsale->getCount());
                                     $sale->setDtActivation($dtActivation);
                                     $sale->setBill($bill);
                                     $sale->setRelation($customer);
                                     $sale->setLabel($label);
                                     $sale->setVat($vat);
                                     $sale->setVatDevise($vat);
                                     $sale->setStamp($stamp);
                                     $sale->setStampDevise($stamp);
                                     $sale->setBalanceTtc($balanceTtc);
                                     $sale->setBalanceTtcDevise($balanceTtc);
                                     $sale->setVatInfo($vatInfo);
                                     $sale->setRegime($regime);
                                     $sale->setWithholding($withholding);
                                     $sale->setBalanceNet($balanceNet);
                                     $sale->setBalanceNetDevise($balanceNet);
                                     $sale->setPaymentType($paymentType);
                                     $sale->setDtPayment($dtPayment);
                                     $sale->setAccount($account);
                                     $sale->setTransactionStatus($status);
                                     $sale->setOtherInfos($otherInfos);
                                     $em->persist($sale);
                                     $mbsale->updateCount();
                                     $em->persist($mbsale);
                                     $haspreverror = false;
                                 } else {
                                     $lineUnprocessed++;
                                     $log .= "l'Achat à la ligne " . $lineRead . ' existe déjà<br>';
                                     $haspreverror = true;
                                 }
                             } else {
                                 if ($haspreverror == false) {
                                     $secondaryVat = new SecondaryVat();
                                     $secondaryVat->setSale($sale);
                                     $secondaryVat->setBalanceNet($balanceNet);
                                     $secondaryVat->setBalanceTtc($balanceTtc);
                                     $secondaryVat->setVat($vat);
                                     $secondaryVat->setVatInfo($vatInfo);
                                     $em->persist($secondaryVat);
                                 } else {
                                     $lineUnprocessed++;
                                     $log .= "l'Achat à la ligne " . $lineRead . ' existe déjà<br>';
                                     $haspreverror = true;
                                 }
                             }
                         } else {
                             $lineError++;
                             $log .= 'la ligne ' . $lineRead . ' contient des erreurs<br>';
                         }
                         $prevbill = $bill;
                     }
                     $em->flush();
                     $log .= $lineRead . ' lignes lues<br>';
                     $log .= $salesNew . ' nouvelles Ventes<br>';
                     $log .= $lineUnprocessed . ' Ventes déjà dans la base<br>';
                     $log .= $lineError . ' lignes contenant des erreurs<br>';
                     // */
                     $this->flashMsgSession('log', $log);
                     $this->flashMsgSession('success', $this->translate('Sale.import.success'));
                     $this->gvars['tabActive'] = 1;
                     $this->getSession()->set('tabActive', 1);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($mbsale);
                     $this->flashMsgSession('error', $this->translate('Sale.import.failure'));
                 }
             } elseif (isset($reqData['SaleNewForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $this->gvars['stabActive'] = 2;
                 $this->getSession()->set('stabActive', 2);
                 $saleNewForm->handleRequest($request);
                 if ($saleNewForm->isValid()) {
                     $sale->setNumber($mbsale->getCount());
                     if ($sale->getDevise() == 'TND') {
                         $sale->setConversionRate(1);
                         $sale->setVatDevise($sale->getVat());
                         $sale->setStampDevise($sale->getStamp());
                         $sale->setBalanceTtcDevise($sale->getBalanceTtc());
                         $sale->setBalanceNetDevise($sale->getBalanceNet());
                     } else {
                         $sale->setVat($sale->getVatDevise() * $sale->getConversionRate());
                         $sale->setStamp($sale->getStampDevise() * $sale->getConversionRate());
                         $sale->setBalanceTtc($sale->getBalanceTtcDevise() * $sale->getConversionRate());
                         $sale->setBalanceNet($sale->getBalanceNetDevise() * $sale->getConversionRate());
                     }
                     foreach ($saleNewForm->get('docs') as $docNewForm) {
                         $docFile = $docNewForm['fileName']->getData();
                         $docDir = $this->getParameter('kernel.root_dir') . '/../web/res/docs';
                         $originalName = $docFile->getClientOriginalName();
                         $fileName = sha1(uniqid(mt_rand(), true)) . '.' . strtolower($docFile->getClientOriginalExtension());
                         $mimeType = $docFile->getMimeType();
                         $docFile->move($docDir, $fileName);
                         $size = filesize($docDir . '/' . $fileName);
                         $md5 = md5_file($docDir . '/' . $fileName);
                         $doc = $docNewForm->getData();
                         $doc->setCompany($mbsale->getCompany());
                         $doc->setFileName($fileName);
                         $doc->setOriginalName($originalName);
                         $doc->setSize($size);
                         $doc->setMimeType($mimeType);
                         $doc->setMd5($md5);
                         $doc->setDescription($docNewForm['description']->getData());
                         $em->persist($doc);
                         $sale->addDoc($doc);
                     }
                     $em->persist($sale);
                     foreach ($saleNewForm->get('secondaryVats') as $secondaryVatNewForm) {
                         $secondaryVat = $secondaryVatNewForm->getData();
                         $secondaryVat->setSale($sale);
                         $sale->addSecondaryVat($secondaryVat);
                         $em->persist($secondaryVat);
                         $em->persist($sale);
                     }
                     $em->flush();
                     $mbsale->updateCount();
                     $em->persist($mbsale);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Sale.add.success', array('%sale%' => $sale->getNumber())));
                     $this->gvars['tabActive'] = 1;
                     $this->getSession()->set('tabActive', 1);
                     $this->gvars['stabActive'] = 1;
                     $this->getSession()->set('stabActive', 1);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($mbsale);
                     $this->flashMsgSession('error', $this->translate('Sale.add.failure'));
                 }
             } elseif (isset($reqData['MBSaleUpdateCountForm'])) {
                 $this->gvars['tabActive'] = 3;
                 $this->getSession()->set('tabActive', 3);
                 $mbsaleUpdateCountForm->handleRequest($request);
                 if ($mbsaleUpdateCountForm->isValid()) {
                     $em->persist($mbsale);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('MBSale.edit.success', array('%mbsale%' => $mbsale->getRef())));
                     $this->traceEntity($cloneMBSale, $mbsale);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($mbsale);
                     $this->flashMsgSession('error', $this->translate('MBSale.edit.failure', array('%mbsale%' => $mbsale->getRef())));
                 }
             } elseif (isset($reqData['DocNewForm'])) {
                 $this->gvars['tabActive'] = 4;
                 $this->getSession()->set('tabActive', 4);
                 $this->gvars['stabActive'] = 1;
                 $this->getSession()->set('stabActive', 1);
                 $docNewForm->handleRequest($request);
                 if ($docNewForm->isValid()) {
                     $docFiles = $docNewForm['fileName']->getData();
                     $docs = array();
                     $docDir = $this->getParameter('kernel.root_dir') . '/../web/res/docs';
                     $docNames = '';
                     foreach ($docFiles as $docFile) {
                         $originalName = $docFile->getClientOriginalName();
                         $fileName = sha1(uniqid(mt_rand(), true)) . '.' . strtolower($docFile->getClientOriginalExtension());
                         $mimeType = $docFile->getMimeType();
                         $docFile->move($docDir, $fileName);
                         $size = filesize($docDir . '/' . $fileName);
                         $md5 = md5_file($docDir . '/' . $fileName);
                         $doc = new Doc();
                         $doc->setCompany($mbsale->getCompany());
                         $doc->setFileName($fileName);
                         $doc->setOriginalName($originalName);
                         $doc->setSize($size);
                         $doc->setMimeType($mimeType);
                         $doc->setMd5($md5);
                         $doc->setDescription($docNewForm['description']->getData());
                         $em->persist($doc);
                         $mbsale->addDoc($doc);
                         $docNames .= $doc->getOriginalName() . ' ';
                         $docs[] = $doc;
                     }
                     $em->persist($mbsale);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Doc.add.success', array('%doc%' => $docNames)));
                     $from = $this->getParameter('mail_from');
                     $fromName = $this->getParameter('mail_from_name');
                     $subject = $this->translate('_mail.newdocsCloud.subject', array(), 'messages');
                     $company = $mbsale->getCompany();
                     $acfCloudRole = $em->getRepository('AcfDataBundle:Role')->findOneBy(array('name' => 'ROLE_CLIENT1'));
                     $users = array();
                     foreach ($company->getUsers() as $user) {
                         if ($user->hasRole($acfCloudRole)) {
                             $users[] = $user;
                         }
                     }
                     if (\count($users) != 0) {
                         foreach ($users as $user) {
                             $mvars = array();
                             $mvars['company'] = $company;
                             $mvars['docs'] = $docs;
                             $message = \Swift_Message::newInstance();
                             $message->setFrom($from, $fromName);
                             $message->addTo($user->getEmail(), $user->getFullname());
                             $message->setSubject($subject);
                             $mvars['logo'] = $message->embed(\Swift_Image::fromPath($this->getParameter('kernel.root_dir') . '/../web/bundles/acfres/images/logo_acf.jpg'));
                             $message->setBody($this->renderView('AcfAdminBundle:Doc:sendmail.html.twig', $mvars), 'text/html');
                             $this->sendmail($message);
                         }
                     }
                     $this->gvars['stabActive'] = 3;
                     $this->getSession()->set('stabActive', 3);
                     $this->traceEntity($cloneMBSale, $mbsale);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($mbsale);
                     $this->flashMsgSession('error', $this->translate('Doc.add.failure'));
                 }
             } elseif (isset($reqData['MBSaleUpdateDocsForm'])) {
                 $this->gvars['tabActive'] = 4;
                 $this->getSession()->set('tabActive', 4);
                 $this->gvars['stabActive'] = 2;
                 $this->getSession()->set('stabActive', 2);
                 $mbsaleUpdateDocsForm->handleRequest($request);
                 if ($mbsaleUpdateDocsForm->isValid()) {
                     $em->persist($mbsale);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('MBSale.edit.success', array('%mbsale%' => $mbsale->getRef())));
                     $this->gvars['stabActive'] = 3;
                     $this->getSession()->set('stabActive', 3);
                     $this->traceEntity($cloneMBSale, $mbsale);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($mbsale);
                     $this->flashMsgSession('error', $this->translate('MBSale.edit.failure', array('%mbsale%' => $mbsale->getRef())));
                 }
             }
             $this->gvars['mbsale'] = $mbsale;
             $this->gvars['sale'] = $sale;
             $this->gvars['doc'] = $doc;
             $this->gvars['SaleNewForm'] = $saleNewForm->createView();
             $this->gvars['SaleImportForm'] = $saleImportForm->createView();
             $this->gvars['MBSaleUpdateCountForm'] = $mbsaleUpdateCountForm->createView();
             $this->gvars['MBSaleUpdateDocsForm'] = $mbsaleUpdateDocsForm->createView();
             $this->gvars['DocNewForm'] = $docNewForm->createView();
             $customersConstStr = $em->getRepository('AcfDataBundle:ConstantStr')->findOneBy(array('name' => 'customersPrefix'));
             if (null == $customersConstStr) {
                 $customersConstStr = new ConstantStr();
                 $customersConstStr->setName('customersPrefix');
                 $customersConstStr->setValue('411');
                 $em->persist($customersConstStr);
                 $em->flush();
             }
             $customersPrefix = $customersConstStr->getValue();
             $this->gvars['customersPrefix'] = $customersPrefix;
             $this->gvars['pagetitle'] = $this->translate('pagetitle.mbsale.edit', array('%mbsale%' => $mbsale->getRef()));
             $this->gvars['pagetitle_txt'] = $this->translate('pagetitle.mbsale.edit.txt', array('%mbsale%' => $mbsale->getRef()));
             return $this->renderResponse('AcfAdminBundle:MBSale:edit.html.twig', $this->gvars);
         }
     } catch (\Exception $e) {
         $logger = $this->getLogger();
         $logger->addCritical($e->getLine() . ' ' . $e->getMessage() . ' ' . $e->getTraceAsString());
     }
     return $this->redirect($urlFrom);
 }
 /**
  * Form builder
  *
  * @param FormBuilderInterface $builder
  * @param array $options
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->add('transactionStatus', ChoiceType::class, array('label' => 'Sale.transactionStatus.label', 'choices_as_values' => true, 'choices' => Sale::choiceTransactionStatus(), 'expanded' => true, 'attr' => array('choice_label_trans' => true)));
     $builder->add('dtPayment', DateType::class, array('label' => 'Sale.dtPayment.label', 'widget' => 'single_text', 'format' => 'yyyy-MM-dd'));
 }
Beispiel #6
0
 /**
  * Form builder
  *
  * @param FormBuilderInterface $builder
  * @param array $options
  *
  * @return null
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $this->mbsale = $options['monthlybalance'];
     if (null == $this->mbsale) {
         $builder->add('monthlyBalance', EntityType::class, array('label' => 'Sale.monthlyBalance.label', 'class' => 'AcfDataBundle:MBSale', 'query_builder' => function (MBSaleRepository $mbsr) {
             return $mbsr->createQueryBuilder('mbs')->orderBy('mbs.ref', 'ASC');
         }, 'choice_label' => 'ref', 'multiple' => false, 'by_reference' => true, 'required' => true));
     } else {
         $mbsaleId = $this->mbsale->getId();
         $builder->add('monthlyBalance', EntityidType::class, array('label' => 'Sale.monthlyBalance.label', 'class' => 'AcfDataBundle:MBSale', 'query_builder' => function (MBSaleRepository $mbsr) use($mbsaleId) {
             return $mbsr->createQueryBuilder('mbs')->where('mbs.id = :id')->setParameter('id', $mbsaleId)->orderBy('mbs.ref', 'ASC');
         }, 'choice_label' => 'id', 'multiple' => false, 'by_reference' => true, 'required' => true));
     }
     $builder->add('dtActivation', DateType::class, array('label' => 'Sale.dtActivation.label', 'widget' => 'single_text', 'format' => 'yyyy-MM-dd'));
     $builder->add('bill', TextType::class, array('label' => 'Sale.bill.label'));
     if (null == $this->mbsale) {
         $builder->add('relation', EntityType::class, array('label' => 'Sale.relation.label', 'class' => 'AcfDataBundle:Customer', 'query_builder' => function (CustomerRepository $sr) {
             return $sr->createQueryBuilder('s')->orderBy('s.label', 'ASC');
         }, 'choice_label' => 'label', 'multiple' => false, 'by_reference' => true, 'required' => true));
     } else {
         $companyId = $this->mbsale->getCompany()->getId();
         $builder->add('relation', EntityType::class, array('label' => 'Sale.relation.label', 'class' => 'AcfDataBundle:Customer', 'query_builder' => function (CustomerRepository $sr) use($companyId) {
             return $sr->createQueryBuilder('s')->join('s.company', 'c')->where('c.id = :cid')->setParameter('cid', $companyId)->orderBy('s.label', 'ASC');
         }, 'choice_label' => 'label', 'multiple' => false, 'by_reference' => true, 'required' => true));
     }
     $builder->add('label', TextType::class, array('label' => 'Sale.label.label'));
     $builder->add('devise', CurrencyType::class, array('label' => 'Sale.devise.label'));
     $builder->add('conversionRate', NumberType::class, array('label' => 'Sale.conversionRate.label'));
     $builder->add('vat', NumberType::class, array('label' => 'Sale.vat.label'));
     $builder->add('stamp', NumberType::class, array('label' => 'Sale.stamp.label'));
     $builder->add('balanceTtc', NumberType::class, array('label' => 'Sale.balanceTtc.label'));
     $builder->add('balanceNet', NumberType::class, array('label' => 'Sale.balanceNet.label'));
     $builder->add('vatDevise', NumberType::class, array('label' => 'Sale.vatDevise.label'));
     $builder->add('stampDevise', NumberType::class, array('label' => 'Sale.stampDevise.label'));
     $builder->add('balanceTtcDevise', NumberType::class, array('label' => 'Sale.balanceTtcDevise.label'));
     $builder->add('balanceNetDevise', NumberType::class, array('label' => 'Sale.balanceNetDevise.label'));
     $builder->add('vatInfo', ChoiceType::class, array('label' => 'Sale.vatInfo.label', 'choices_as_values' => true, 'choices' => Sale::choiceVatInfo(), 'attr' => array('choice_label_trans' => true)));
     $builder->add('regime', ChoiceType::class, array('label' => 'Sale.regime.label', 'choices_as_values' => true, 'choices' => Sale::choiceRegime(), 'attr' => array('choice_label_trans' => true)));
     if (null == $this->mbsale) {
         $builder->add('withholding', EntityType::class, array('label' => 'Sale.withholding.label', 'class' => 'AcfDataBundle:Withholding', 'query_builder' => function (WithholdingRepository $wr) {
             return $wr->createQueryBuilder('w')->orderBy('w.label', 'ASC');
         }, 'choice_label' => 'label', 'multiple' => false, 'by_reference' => true, 'required' => true));
     } else {
         $companyId = $this->mbsale->getCompany()->getId();
         $builder->add('withholding', EntityType::class, array('label' => 'Sale.withholding.label', 'class' => 'AcfDataBundle:Withholding', 'query_builder' => function (WithholdingRepository $wr) use($companyId) {
             return $wr->createQueryBuilder('w')->join('w.company', 'c')->where('c.id = :cid')->setParameter('cid', $companyId)->orderBy('w.label', 'ASC');
         }, 'choice_label' => 'label', 'multiple' => false, 'by_reference' => true, 'required' => true));
     }
     $builder->add('paymentType', ChoiceType::class, array('label' => 'Sale.paymentType.label', 'choices_as_values' => true, 'choices' => Sale::choicePaymentType(), 'attr' => array('choice_label_trans' => true)));
     $builder->add('transactionStatus', ChoiceType::class, array('label' => 'Sale.transactionStatus.label', 'choices_as_values' => true, 'choices' => Sale::choiceTransactionStatus(), 'expanded' => true, 'attr' => array('choice_label_trans' => true)));
     $builder->add('dtPayment', DateType::class, array('label' => 'Sale.dtPayment.label', 'widget' => 'single_text', 'format' => 'yyyy-MM-dd'));
     if (null == $this->mbsale) {
         $builder->add('account', EntityType::class, array('label' => 'Sale.account.label', 'class' => 'AcfDataBundle:Account', 'query_builder' => function (AccountRepository $ar) {
             return $ar->createQueryBuilder('a')->orderBy('a.label', 'ASC');
         }, 'choice_label' => 'label', 'multiple' => false, 'by_reference' => true, 'required' => true));
     } else {
         $companyId = $this->mbsale->getCompany()->getId();
         $builder->add('account', EntityType::class, array('label' => 'Sale.account.label', 'class' => 'AcfDataBundle:Account', 'query_builder' => function (AccountRepository $ar) use($companyId) {
             return $ar->createQueryBuilder('a')->join('a.company', 'c')->where('c.id = :cid')->setParameter('cid', $companyId)->orderBy('a.label', 'ASC');
         }, 'choice_label' => 'label', 'multiple' => false, 'by_reference' => true, 'required' => true));
     }
     $builder->add('docs', CollectionType::class, array('label' => 'Sale.docs.label', 'entry_type' => SaleDocTForm::class, 'allow_add' => true, 'allow_delete' => true, 'by_reference' => false, 'mapped' => false, 'constraints' => new Valid()));
     $builder->add('secondaryVats', CollectionType::class, array('label' => 'Sale.secondaryVats.label', 'entry_type' => SaleSecondaryVatTForm::class, 'allow_add' => true, 'allow_delete' => true, 'by_reference' => false, 'mapped' => false));
     $builder->add('otherInfos', TextareaType::class, array('label' => 'Sale.otherInfos.label', 'required' => false));
     $builder->add('validated', ChoiceType::class, array('label' => 'Sale.validated.label', 'choices_as_values' => true, 'choices' => Sale::choiceValidated(), 'expanded' => true, 'attr' => array('choice_label_trans' => true)));
 }
Beispiel #7
0
 protected function traceEntity(Sale $cloneSale, Sale $sale)
 {
     $curUser = $this->getSecurityTokenStorage()->getToken()->getUser();
     $trace = new Trace();
     $trace->setActionId($sale->getId());
     $trace->setActionType(Trace::AT_UPDATE);
     $trace->setUserId($curUser->getId());
     $trace->setCompanyId($sale->getCompany()->getId());
     $trace->setUserFullname($curUser->getFullName());
     if (!$this->hasRole('ROLE_SUPERADMIN')) {
         if (!$this->hasRole('ROLE_ADMIN')) {
             $trace->setUserType(Trace::UT_CLIENT);
         } else {
             $trace->setUserType(Trace::UT_ADMIN);
         }
     } else {
         $trace->setUserType(Trace::UT_SUPERADMIN);
     }
     $tableBegin = ': <br><table class="table table-bordered table-condensed table-hover table-striped">';
     $tableBegin .= '<thead><tr><th class="text-left">' . $this->translate('Entity.field') . '</th>';
     $tableBegin .= '<th class="text-left">' . $this->translate('Entity.oldVal') . '</th>';
     $tableBegin .= '<th class="text-left">' . $this->translate('Entity.newVal') . '</th></tr></thead><tbody>';
     $tableEnd = '</tbody></table>';
     $trace->setActionEntity(Trace::AE_SALE);
     $trace->setActionId2($sale->getMonthlyBalance()->getCompany()->getId());
     $trace->setActionEntity2(Trace::AE_COMPANY);
     $trace->setActionId3($sale->getMonthlyBalance()->getId());
     $trace->setActionEntity2(Trace::AE_MBSALE);
     $msg = '';
     if ($cloneSale->getNumber() != $sale->getNumber()) {
         $msg .= '<tr><td>' . $this->translate('Sale.number.label') . '</td><td>';
         if ($cloneSale->getNumber() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneSale->getNumberFormated();
         }
         $msg .= '</td><td>';
         if ($sale->getNumber() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $sale->getNumberFormated();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneSale->getDtActivation() != $sale->getDtActivation()) {
         $msg .= '<tr><td>' . $this->translate('Sale.dtActivation.label') . '</td><td>';
         if ($cloneSale->getDtActivation() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneSale->getDtActivation()->format('Y-m-d');
         }
         $msg .= '</td><td>';
         if ($sale->getDtActivation() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $sale->getDtActivation()->format('Y-m-d');
         }
         $msg .= '</td></tr>';
     }
     if ($cloneSale->getBill() != $sale->getBill()) {
         $msg .= '<tr><td>' . $this->translate('Sale.bill.label') . '</td><td>';
         if ($cloneSale->getBill() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneSale->getBill();
         }
         $msg .= '</td><td>';
         if ($sale->getBill() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $sale->getBill();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneSale->getRelation() != $sale->getRelation()) {
         $msg .= '<tr><td>' . $this->translate('Sale.relation.label') . '</td><td>';
         if ($cloneSale->getRelation() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneSale->getRelation()->getLabel();
         }
         $msg .= '</td><td>';
         if ($sale->getRelation() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $sale->getRelation()->getLabel();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneSale->getLabel() != $sale->getLabel()) {
         $msg .= '<tr><td>' . $this->translate('Sale.label.label') . '</td><td>';
         if ($cloneSale->getLabel() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneSale->getLabel();
         }
         $msg .= '</td><td>';
         if ($sale->getLabel() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $sale->getLabel();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneSale->getDevise() != $sale->getDevise()) {
         $msg .= '<tr><td>' . $this->translate('Sale.devise.label') . '</td><td>';
         if ($cloneSale->getDevise() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneSale->getDevise();
         }
         $msg .= '</td><td>';
         if ($sale->getDevise() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $sale->getDevise();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneSale->getConversionRate() != $sale->getConversionRate()) {
         $msg .= '<tr><td>' . $this->translate('Sale.conversionRate.label') . '</td><td>';
         if ($cloneSale->getConversionRate() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneSale->getConversionRate();
         }
         $msg .= '</td><td>';
         if ($sale->getConversionRate() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $sale->getConversionRate();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneSale->getVat() != $sale->getVat()) {
         $msg .= '<tr><td>' . $this->translate('Sale.vat.label') . '</td><td>';
         if ($cloneSale->getVat() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneSale->getVat();
         }
         $msg .= '</td><td>';
         if ($sale->getVat() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $sale->getVat();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneSale->getStamp() != $sale->getStamp()) {
         $msg .= '<tr><td>' . $this->translate('Sale.stamp.label') . '</td><td>';
         if ($cloneSale->getStamp() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneSale->getStamp();
         }
         $msg .= '</td><td>';
         if ($sale->getStamp() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $sale->getStamp();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneSale->getBalanceTtc() != $sale->getBalanceTtc()) {
         $msg .= '<tr><td>' . $this->translate('Sale.balanceTtc.label') . '</td><td>';
         if ($cloneSale->getBalanceTtc() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneSale->getBalanceTtc();
         }
         $msg .= '</td><td>';
         if ($sale->getBalanceTtc() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $sale->getBalanceTtc();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneSale->getBalanceNet() != $sale->getBalanceNet()) {
         $msg .= '<tr><td>' . $this->translate('Sale.balanceNet.label') . '</td><td>';
         if ($cloneSale->getBalanceNet() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneSale->getBalanceNet();
         }
         $msg .= '</td><td>';
         if ($sale->getBalanceNet() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $sale->getBalanceNet();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneSale->getVatDevise() != $sale->getVatDevise()) {
         $msg .= '<tr><td>' . $this->translate('Sale.vatDevise.label') . '</td><td>';
         if ($cloneSale->getVatDevise() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneSale->getVatDevise();
         }
         $msg .= '</td><td>';
         if ($sale->getVatDevise() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $sale->getVatDevise();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneSale->getStampDevise() != $sale->getStampDevise()) {
         $msg .= '<tr><td>' . $this->translate('Sale.stampDevise.label') . '</td><td>';
         if ($cloneSale->getStampDevise() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneSale->getStampDevise();
         }
         $msg .= '</td><td>';
         if ($sale->getStampDevise() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $sale->getStampDevise();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneSale->getBalanceTtcDevise() != $sale->getBalanceTtcDevise()) {
         $msg .= '<tr><td>' . $this->translate('Sale.balanceTtcDevise.label') . '</td><td>';
         if ($cloneSale->getBalanceTtcDevise() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneSale->getBalanceTtcDevise();
         }
         $msg .= '</td><td>';
         if ($sale->getBalanceTtcDevise() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $sale->getBalanceTtcDevise();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneSale->getBalanceNetDevise() != $sale->getBalanceNetDevise()) {
         $msg .= '<tr><td>' . $this->translate('Sale.balanceNetDevise.label') . '</td><td>';
         if ($cloneSale->getBalanceNetDevise() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneSale->getBalanceNetDevise();
         }
         $msg .= '</td><td>';
         if ($sale->getBalanceNetDevise() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $sale->getBalanceNetDevise();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneSale->getVatInfo() != $sale->getVatInfo()) {
         $msg .= '<tr><td>' . $this->translate('Sale.vatInfo.label') . '</td><td>';
         if ($cloneSale->getVatInfo() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $this->translate('Sale.vatInfo.' . $cloneSale->getVatInfo());
         }
         $msg .= '</td><td>';
         if ($sale->getVatInfo() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $this->translate('Sale.vatInfo.' . $sale->getVatInfo());
         }
         $msg .= '</td></tr>';
     }
     if ($cloneSale->getRegime() != $sale->getRegime()) {
         $msg .= '<tr><td>' . $this->translate('Sale.regime.label') . '</td><td>';
         if ($cloneSale->getRegime() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $this->translate('Sale.regime.' . $cloneSale->getRegime());
         }
         $msg .= '</td><td>';
         if ($sale->getRegime() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $this->translate('Sale.regime.' . $sale->getRegime());
         }
         $msg .= '</td></tr>';
     }
     if ($cloneSale->getWithholding() != $sale->getWithholding()) {
         $msg .= '<tr><td>' . $this->translate('Sale.withholding.label') . '</td><td>';
         if ($cloneSale->getWithholding() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneSale->getWithholding()->getLabel();
         }
         $msg .= '</td><td>';
         if ($sale->getWithholding() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $sale->getWithholding()->getLabel();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneSale->getPaymentType() != $sale->getPaymentType()) {
         $msg .= '<tr><td>' . $this->translate('Sale.paymentType.label') . '</td><td>';
         if ($cloneSale->getPaymentType() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $this->translate('Transaction.paymentType.' . $cloneSale->getPaymentType());
         }
         $msg .= '</td><td>';
         if ($sale->getPaymentType() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $this->translate('Transaction.paymentType.' . $sale->getPaymentType());
         }
         $msg .= '</td></tr>';
     }
     if ($cloneSale->getDtPayment() != $sale->getDtPayment()) {
         $msg .= '<tr><td>' . $this->translate('Sale.dtPayment.label') . '</td><td>';
         if ($cloneSale->getDtPayment() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneSale->getDtPayment()->format('Y-m-d');
         }
         $msg .= '</td><td>';
         if ($sale->getDtPayment() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $sale->getDtActivation()->format('Y-m-d');
         }
         $msg .= '</td></tr>';
     }
     if ($cloneSale->getAccount() != $sale->getAccount()) {
         $msg .= '<tr><td>' . $this->translate('Sale.account.label') . '</td><td>';
         if ($cloneSale->getAccount() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneSale->getAccount()->getLabel();
         }
         $msg .= '</td><td>';
         if ($sale->getAccount() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $sale->getAccount()->getLabel();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneSale->getNature() != $sale->getNature()) {
         $msg .= '<tr><td>' . $this->translate('Sale.nature.label') . '</td><td>';
         if ($cloneSale->getNature() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneSale->getNature()->getLabel();
         }
         $msg .= '</td><td>';
         if ($sale->getNature() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $sale->getNature()->getLabel();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneSale->getTransactionStatus() != $sale->getTransactionStatus()) {
         $msg .= '<tr><td>' . $this->translate('Sale.transactionStatus.label') . '</td><td>';
         if ($cloneSale->getTransactionStatus() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $this->translate('Transaction.transactionStatus.' . $cloneSale->getTransactionStatus());
         }
         $msg .= '</td><td>';
         if ($sale->getTransactionStatus() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $this->translate('Transaction.transactionStatus.' . $sale->getTransactionStatus());
         }
         $msg .= '</td></tr>';
     }
     if ($cloneSale->getValidated() != $sale->getValidated()) {
         $msg .= '<tr><td>' . $this->translate('Sale.validated.label') . '</td><td>';
         if ($cloneSale->getValidated() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $this->translate('Transaction.validated.' . $cloneSale->getValidated());
         }
         $msg .= '</td><td>';
         if ($sale->getValidated() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $this->translate('Transaction.validated.' . $sale->getValidated());
         }
         $msg .= '</td></tr>';
     }
     if ($cloneSale->getOtherInfos() != $sale->getOtherInfos()) {
         $msg .= '<tr><td>' . $this->translate('Sale.otherInfos.label') . '</td><td>';
         if ($cloneSale->getOtherInfos() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneSale->getOtherInfos();
         }
         $msg .= '</td><td>';
         if ($sale->getOtherInfos() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $sale->getOtherInfos();
         }
         $msg .= '</td></tr>';
     }
     if (\count(\array_diff($sale->getDocs()->toArray(), $cloneSale->getDocs()->toArray())) != 0 || \count(\array_diff($cloneSale->getDocs()->toArray(), $sale->getDocs()->toArray())) != 0) {
         $msg .= '<tr><td>' . $this->translate('Sale.docs.label') . '</td><td>';
         if (\count($cloneSale->getDocs()) == 0) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= '<ul>';
             foreach ($cloneSale->getDocs() as $doc) {
                 $msg .= '<li><a href="' . $this->generateUrl('_admin_doc_editGet', array('uid' => $doc->getId())) . '">' . $doc->getOriginalName() . '</a></li>';
             }
             $msg .= '<ul>';
         }
         $msg .= '</td><td>';
         if (\count($sale->getDocs()) == 0) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= '<ul>';
             foreach ($sale->getDocs() as $doc) {
                 $msg .= '<li><a href="' . $this->generateUrl('_admin_doc_editGet', array('uid' => $doc->getId())) . '">' . $doc->getOriginalName() . '</a></li>';
             }
             $msg .= '<ul>';
         }
         $msg .= '</td></tr>';
     }
     if (\count(\array_diff($sale->getSecondaryVats()->toArray(), $cloneSale->getSecondaryVats()->toArray())) != 0 || \count(\array_diff($cloneSale->getSecondaryVats()->toArray(), $sale->getSecondaryVats()->toArray())) != 0) {
         $msg .= '<tr><td>' . $this->translate('Sale.secondaryVats.label') . '</td><td>';
         if (\count($cloneSale->getSecondaryVats()) == 0) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= '<ul>';
             foreach ($cloneSale->getSecondaryVats() as $secondaryVat) {
                 $msg .= '<li><a href="' . $this->generateUrl('_admin_secondaryVat_editGet', array('uid' => $secondaryVat->getId())) . '">' . $secondaryVat->getVat() . '</a></li>';
             }
             $msg .= '<ul>';
         }
         $msg .= '</td><td>';
         if (\count($sale->getSecondaryVats()) == 0) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= '<ul>';
             foreach ($sale->getSecondaryVats() as $secondaryVat) {
                 $msg .= '<li><a href="' . $this->generateUrl('_admin_secondaryVat_editGet', array('uid' => $secondaryVat->getId())) . '">' . $secondaryVat->getVat() . '</a></li>';
             }
             $msg .= '<ul>';
         }
         $msg .= '</td></tr>';
     }
     if ($msg != '') {
         $msg = $tableBegin . $msg . $tableEnd;
         $trace->setMsg($this->translate('Sale.traceEdit', array('%sale%' => $sale->getLabel(), '%mbsale%' => $sale->getMonthlyBalance()->getRef(), '%company%' => $sale->getCompany()->getCorporateName())) . $msg);
         $trace->setDtCrea(new \DateTime('now'));
         $em = $this->getEntityManager();
         $em->persist($trace);
         $em->flush();
     }
 }
 /**
  *
  * @param string $uid
  * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
  */
 public function editPostAction($uid)
 {
     $urlFrom = $this->getReferer();
     if (null == $urlFrom || trim($urlFrom) == '') {
         $urlFrom = $this->generateUrl('_client_homepage');
     }
     $em = $this->getEntityManager();
     try {
         $mbsale = $em->getRepository('AcfDataBundle:MBSale')->find($uid);
         if (null == $mbsale) {
             $this->flashMsgSession('warning', $this->translate('MBSale.edit.notfound'));
         } else {
             $sc = $this->getSecurityTokenStorage();
             $user = $sc->getToken()->getUser();
             $company = $mbsale->getCompany();
             $companyUser = $em->getRepository('AcfDataBundle:CompanyUser')->findOneBy(array('company' => $company, 'user' => $user));
             if (null == $companyUser || $companyUser->getEditSales() == CompanyUser::CANT) {
                 $this->flashMsgSession('error', $this->translate('CompanyUser.accessForbidden'));
                 return $this->redirect($this->generateUrl('_client_homepage'));
             }
             $this->gvars['companyUser'] = $companyUser;
             $this->gvars['menu_active'] = 'client' . $company->getId();
             $sale = new Sale();
             $sale->setMonthlyBalance($mbsale);
             $saleNewForm = $this->createForm(SaleNewTForm::class, $sale, array('monthlybalance' => $mbsale));
             $mbsaleUpdateDocsForm = $this->createForm(MBSaleUpdateDocsTForm::class, $mbsale, array('company' => $mbsale->getCompany()));
             $doc = new Doc();
             $doc->setCompany($mbsale->getCompany());
             $docNewForm = $this->createForm(DocNewTForm::class, $doc, array('company' => $mbsale->getCompany()));
             $this->gvars['tabActive'] = $this->getSession()->get('tabActive', 2);
             $this->getSession()->remove('tabActive');
             $this->gvars['stabActive'] = $this->getSession()->get('stabActive', 1);
             $this->getSession()->remove('stabActive');
             $request = $this->getRequest();
             $reqData = $request->request->all();
             $cloneMBSale = clone $mbsale;
             if (isset($reqData['SaleNewForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $this->gvars['stabActive'] = 2;
                 $this->getSession()->set('stabActive', 2);
                 $saleNewForm->handleRequest($request);
                 if ($saleNewForm->isValid()) {
                     $sale->setNumber($mbsale->getCount());
                     if ($sale->getDevise() == 'TND') {
                         $sale->setConversionRate(1);
                         $sale->setVatDevise($sale->getVat());
                         $sale->setStampDevise($sale->getStamp());
                         $sale->setBalanceTtcDevise($sale->getBalanceTtc());
                         $sale->setBalanceNetDevise($sale->getBalanceNet());
                     } else {
                         $sale->setVat($sale->getVatDevise() * $sale->getConversionRate());
                         $sale->setStamp($sale->getStampDevise() * $sale->getConversionRate());
                         $sale->setBalanceTtc($sale->getBalanceTtcDevise() * $sale->getConversionRate());
                         $sale->setBalanceNet($sale->getBalanceNetDevise() * $sale->getConversionRate());
                     }
                     foreach ($saleNewForm->get('docs') as $docNewForm) {
                         $docFile = $docNewForm['fileName']->getData();
                         $docDir = $this->getParameter('kernel.root_dir') . '/../web/res/docs';
                         $originalName = $docFile->getClientOriginalName();
                         $fileName = sha1(uniqid(mt_rand(), true)) . '.' . strtolower($docFile->getClientOriginalExtension());
                         $mimeType = $docFile->getMimeType();
                         $docFile->move($docDir, $fileName);
                         $size = filesize($docDir . '/' . $fileName);
                         $md5 = md5_file($docDir . '/' . $fileName);
                         $doc = $docNewForm->getData();
                         $doc->setCompany($mbsale->getCompany());
                         $doc->setFileName($fileName);
                         $doc->setOriginalName($originalName);
                         $doc->setSize($size);
                         $doc->setMimeType($mimeType);
                         $doc->setMd5($md5);
                         $doc->setDescription($docNewForm['description']->getData());
                         $em->persist($doc);
                         $sale->addDoc($doc);
                     }
                     $em->persist($sale);
                     foreach ($saleNewForm->get('secondaryVats') as $secondaryVatNewForm) {
                         $secondaryVat = $secondaryVatNewForm->getData();
                         $secondaryVat->setSale($sale);
                         $sale->addSecondaryVat($secondaryVat);
                         $em->persist($secondaryVat);
                         $em->persist($sale);
                     }
                     $em->flush();
                     $mbsale->updateCount();
                     $em->persist($mbsale);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Sale.add.success', array('%sale%' => $sale->getNumber())));
                     $this->gvars['tabActive'] = 1;
                     $this->getSession()->set('tabActive', 1);
                     $this->gvars['stabActive'] = 1;
                     $this->getSession()->set('stabActive', 1);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($mbsale);
                     $this->flashMsgSession('error', $this->translate('Sale.add.failure'));
                 }
             } elseif (isset($reqData['DocNewForm'])) {
                 $this->gvars['tabActive'] = 4;
                 $this->getSession()->set('tabActive', 4);
                 $this->gvars['stabActive'] = 1;
                 $this->getSession()->set('stabActive', 1);
                 $docNewForm->handleRequest($request);
                 if ($docNewForm->isValid()) {
                     $docFiles = $docNewForm['fileName']->getData();
                     $docs = array();
                     $docDir = $this->getParameter('kernel.root_dir') . '/../web/res/docs';
                     $docNames = '';
                     foreach ($docFiles as $docFile) {
                         $originalName = $docFile->getClientOriginalName();
                         $fileName = sha1(uniqid(mt_rand(), true)) . '.' . strtolower($docFile->getClientOriginalExtension());
                         $mimeType = $docFile->getMimeType();
                         $docFile->move($docDir, $fileName);
                         $size = filesize($docDir . '/' . $fileName);
                         $md5 = md5_file($docDir . '/' . $fileName);
                         $doc = new Doc();
                         $doc->setCompany($mbsale->getCompany());
                         $doc->setFileName($fileName);
                         $doc->setOriginalName($originalName);
                         $doc->setSize($size);
                         $doc->setMimeType($mimeType);
                         $doc->setMd5($md5);
                         $doc->setDescription($docNewForm['description']->getData());
                         $em->persist($doc);
                         $mbsale->addDoc($doc);
                         $docs[] = $doc;
                         $docNames .= $doc->getOriginalName() . ' ';
                     }
                     $em->persist($mbsale);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Doc.add.success', array('%doc%' => $docNames)));
                     $this->newDocNotifyAdmin($mbsale, $docs);
                     $this->gvars['stabActive'] = 3;
                     $this->getSession()->set('stabActive', 3);
                     $this->traceEntity($cloneMBSale, $mbsale);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($mbsale);
                     $this->flashMsgSession('error', $this->translate('Doc.add.failure'));
                 }
             } elseif (isset($reqData['MBSaleUpdateDocsForm'])) {
                 $this->gvars['tabActive'] = 4;
                 $this->getSession()->set('tabActive', 4);
                 $this->gvars['stabActive'] = 2;
                 $this->getSession()->set('stabActive', 2);
                 $mbsaleUpdateDocsForm->handleRequest($request);
                 if ($mbsaleUpdateDocsForm->isValid()) {
                     $em->persist($mbsale);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('MBSale.edit.success', array('%mbsale%' => $mbsale->getRef())));
                     $this->gvars['stabActive'] = 3;
                     $this->getSession()->set('stabActive', 3);
                     $this->traceEntity($cloneMBSale, $mbsale);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($mbsale);
                     $this->flashMsgSession('error', $this->translate('MBSale.edit.failure', array('%mbsale%' => $mbsale->getRef())));
                 }
             }
             $this->gvars['mbsale'] = $mbsale;
             $this->gvars['sale'] = $sale;
             $this->gvars['doc'] = $doc;
             $this->gvars['SaleNewForm'] = $saleNewForm->createView();
             $this->gvars['MBSaleUpdateDocsForm'] = $mbsaleUpdateDocsForm->createView();
             $this->gvars['DocNewForm'] = $docNewForm->createView();
             $customersConstStr = $em->getRepository('AcfDataBundle:ConstantStr')->findOneBy(array('name' => 'customersPrefix'));
             if (null == $customersConstStr) {
                 $customersConstStr = new ConstantStr();
                 $customersConstStr->setName('customersPrefix');
                 $customersConstStr->setValue('411');
                 $em->persist($customersConstStr);
                 $em->flush();
             }
             $customersPrefix = $customersConstStr->getValue();
             $this->gvars['customersPrefix'] = $customersPrefix;
             $this->gvars['pagetitle'] = $this->translate('pagetitle.mbsale.edit', array('%mbsale%' => $mbsale->getRef()));
             $this->gvars['pagetitle_txt'] = $this->translate('pagetitle.mbsale.edit.txt', array('%mbsale%' => $mbsale->getRef()));
             return $this->renderResponse('AcfClientBundle:MBSale:edit.html.twig', $this->gvars);
         }
     } catch (\Exception $e) {
         $logger = $this->getLogger();
         $logger->addCritical($e->getLine() . ' ' . $e->getMessage() . ' ' . $e->getTraceAsString());
     }
     return $this->redirect($urlFrom);
 }