Esempio n. 1
0
 protected function traceEntity(Buy $cloneBuy, Buy $buy)
 {
     $curUser = $this->getSecurityTokenStorage()->getToken()->getUser();
     $trace = new Trace();
     $trace->setActionId($buy->getId());
     $trace->setActionType(Trace::AT_UPDATE);
     $trace->setUserId($curUser->getId());
     $trace->setCompanyId($buy->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_BUY);
     $trace->setActionId2($buy->getMonthlyBalance()->getCompany()->getId());
     $trace->setActionEntity2(Trace::AE_COMPANY);
     $trace->setActionId3($buy->getMonthlyBalance()->getId());
     $trace->setActionEntity2(Trace::AE_MBPURCHASE);
     $msg = '';
     if ($cloneBuy->getNumber() != $buy->getNumber()) {
         $msg .= '<tr><td>' . $this->translate('Buy.number.label') . '</td><td>';
         if ($cloneBuy->getNumber() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneBuy->getNumberFormated();
         }
         $msg .= '</td><td>';
         if ($buy->getNumber() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $buy->getNumberFormated();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneBuy->getDtActivation() != $buy->getDtActivation()) {
         $msg .= '<tr><td>' . $this->translate('Buy.dtActivation.label') . '</td><td>';
         if ($cloneBuy->getDtActivation() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneBuy->getDtActivation()->format('Y-m-d');
         }
         $msg .= '</td><td>';
         if ($buy->getDtActivation() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $buy->getDtActivation()->format('Y-m-d');
         }
         $msg .= '</td></tr>';
     }
     if ($cloneBuy->getBill() != $buy->getBill()) {
         $msg .= '<tr><td>' . $this->translate('Buy.bill.label') . '</td><td>';
         if ($cloneBuy->getBill() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneBuy->getBill();
         }
         $msg .= '</td><td>';
         if ($buy->getBill() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $buy->getBill();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneBuy->getRelation() != $buy->getRelation()) {
         $msg .= '<tr><td>' . $this->translate('Buy.relation.label') . '</td><td>';
         if ($cloneBuy->getRelation() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneBuy->getRelation()->getLabel();
         }
         $msg .= '</td><td>';
         if ($buy->getRelation() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $buy->getRelation()->getLabel();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneBuy->getLabel() != $buy->getLabel()) {
         $msg .= '<tr><td>' . $this->translate('Buy.label.label') . '</td><td>';
         if ($cloneBuy->getLabel() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneBuy->getLabel();
         }
         $msg .= '</td><td>';
         if ($buy->getLabel() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $buy->getLabel();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneBuy->getDevise() != $buy->getDevise()) {
         $msg .= '<tr><td>' . $this->translate('Buy.devise.label') . '</td><td>';
         if ($cloneBuy->getDevise() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneBuy->getDevise();
         }
         $msg .= '</td><td>';
         if ($buy->getDevise() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $buy->getDevise();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneBuy->getConversionRate() != $buy->getConversionRate()) {
         $msg .= '<tr><td>' . $this->translate('Buy.conversionRate.label') . '</td><td>';
         if ($cloneBuy->getConversionRate() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneBuy->getConversionRate();
         }
         $msg .= '</td><td>';
         if ($buy->getConversionRate() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $buy->getConversionRate();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneBuy->getVat() != $buy->getVat()) {
         $msg .= '<tr><td>' . $this->translate('Buy.vat.label') . '</td><td>';
         if ($cloneBuy->getVat() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneBuy->getVat();
         }
         $msg .= '</td><td>';
         if ($buy->getVat() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $buy->getVat();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneBuy->getStamp() != $buy->getStamp()) {
         $msg .= '<tr><td>' . $this->translate('Buy.stamp.label') . '</td><td>';
         if ($cloneBuy->getStamp() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneBuy->getStamp();
         }
         $msg .= '</td><td>';
         if ($buy->getStamp() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $buy->getStamp();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneBuy->getBalanceTtc() != $buy->getBalanceTtc()) {
         $msg .= '<tr><td>' . $this->translate('Buy.balanceTtc.label') . '</td><td>';
         if ($cloneBuy->getBalanceTtc() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneBuy->getBalanceTtc();
         }
         $msg .= '</td><td>';
         if ($buy->getBalanceTtc() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $buy->getBalanceTtc();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneBuy->getBalanceNet() != $buy->getBalanceNet()) {
         $msg .= '<tr><td>' . $this->translate('Buy.balanceNet.label') . '</td><td>';
         if ($cloneBuy->getBalanceNet() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneBuy->getBalanceNet();
         }
         $msg .= '</td><td>';
         if ($buy->getBalanceNet() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $buy->getBalanceNet();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneBuy->getVatDevise() != $buy->getVatDevise()) {
         $msg .= '<tr><td>' . $this->translate('Buy.vatDevise.label') . '</td><td>';
         if ($cloneBuy->getVatDevise() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneBuy->getVatDevise();
         }
         $msg .= '</td><td>';
         if ($buy->getVatDevise() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $buy->getVatDevise();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneBuy->getStampDevise() != $buy->getStampDevise()) {
         $msg .= '<tr><td>' . $this->translate('Buy.stampDevise.label') . '</td><td>';
         if ($cloneBuy->getStampDevise() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneBuy->getStampDevise();
         }
         $msg .= '</td><td>';
         if ($buy->getStampDevise() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $buy->getStampDevise();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneBuy->getBalanceTtcDevise() != $buy->getBalanceTtcDevise()) {
         $msg .= '<tr><td>' . $this->translate('Buy.balanceTtcDevise.label') . '</td><td>';
         if ($cloneBuy->getBalanceTtcDevise() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneBuy->getBalanceTtcDevise();
         }
         $msg .= '</td><td>';
         if ($buy->getBalanceTtcDevise() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $buy->getBalanceTtcDevise();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneBuy->getBalanceNetDevise() != $buy->getBalanceNetDevise()) {
         $msg .= '<tr><td>' . $this->translate('Buy.balanceNetDevise.label') . '</td><td>';
         if ($cloneBuy->getBalanceNetDevise() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneBuy->getBalanceNetDevise();
         }
         $msg .= '</td><td>';
         if ($buy->getBalanceNetDevise() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $buy->getBalanceNetDevise();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneBuy->getVatInfo() != $buy->getVatInfo()) {
         $msg .= '<tr><td>' . $this->translate('Buy.vatInfo.label') . '</td><td>';
         if ($cloneBuy->getVatInfo() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $this->translate('Buy.vatInfo.' . $cloneBuy->getVatInfo());
         }
         $msg .= '</td><td>';
         if ($buy->getVatInfo() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $this->translate('Buy.vatInfo.' . $buy->getVatInfo());
         }
         $msg .= '</td></tr>';
     }
     if ($cloneBuy->getRegime() != $buy->getRegime()) {
         $msg .= '<tr><td>' . $this->translate('Buy.regime.label') . '</td><td>';
         if ($cloneBuy->getRegime() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $this->translate('Buy.regime.' . $cloneBuy->getRegime());
         }
         $msg .= '</td><td>';
         if ($buy->getRegime() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $this->translate('Buy.regime.' . $buy->getRegime());
         }
         $msg .= '</td></tr>';
     }
     if ($cloneBuy->getWithholding() != $buy->getWithholding()) {
         $msg .= '<tr><td>' . $this->translate('Buy.withholding.label') . '</td><td>';
         if ($cloneBuy->getWithholding() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneBuy->getWithholding()->getLabel();
         }
         $msg .= '</td><td>';
         if ($buy->getWithholding() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $buy->getWithholding()->getLabel();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneBuy->getPaymentType() != $buy->getPaymentType()) {
         $msg .= '<tr><td>' . $this->translate('Buy.paymentType.label') . '</td><td>';
         if ($cloneBuy->getPaymentType() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $this->translate('Transaction.paymentType.' . $cloneBuy->getPaymentType());
         }
         $msg .= '</td><td>';
         if ($buy->getPaymentType() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $this->translate('Transaction.paymentType.' . $buy->getPaymentType());
         }
         $msg .= '</td></tr>';
     }
     if ($cloneBuy->getDtPayment() != $buy->getDtPayment()) {
         $msg .= '<tr><td>' . $this->translate('Buy.dtPayment.label') . '</td><td>';
         if ($cloneBuy->getDtPayment() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneBuy->getDtPayment()->format('Y-m-d');
         }
         $msg .= '</td><td>';
         if ($buy->getDtPayment() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $buy->getDtActivation()->format('Y-m-d');
         }
         $msg .= '</td></tr>';
     }
     if ($cloneBuy->getAccount() != $buy->getAccount()) {
         $msg .= '<tr><td>' . $this->translate('Buy.account.label') . '</td><td>';
         if ($cloneBuy->getAccount() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneBuy->getAccount()->getLabel();
         }
         $msg .= '</td><td>';
         if ($buy->getAccount() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $buy->getAccount()->getLabel();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneBuy->getNature() != $buy->getNature()) {
         $msg .= '<tr><td>' . $this->translate('Buy.nature.label') . '</td><td>';
         if ($cloneBuy->getNature() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneBuy->getNature()->getLabel();
         }
         $msg .= '</td><td>';
         if ($buy->getNature() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $buy->getNature()->getLabel();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneBuy->getTransactionStatus() != $buy->getTransactionStatus()) {
         $msg .= '<tr><td>' . $this->translate('Buy.transactionStatus.label') . '</td><td>';
         if ($cloneBuy->getTransactionStatus() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $this->translate('Transaction.transactionStatus.' . $cloneBuy->getTransactionStatus());
         }
         $msg .= '</td><td>';
         if ($buy->getTransactionStatus() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $this->translate('Transaction.transactionStatus.' . $buy->getTransactionStatus());
         }
         $msg .= '</td></tr>';
     }
     if ($cloneBuy->getValidated() != $buy->getValidated()) {
         $msg .= '<tr><td>' . $this->translate('Buy.validated.label') . '</td><td>';
         if ($cloneBuy->getValidated() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $this->translate('Transaction.validated.' . $cloneBuy->getValidated());
         }
         $msg .= '</td><td>';
         if ($buy->getValidated() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $this->translate('Transaction.validated.' . $buy->getValidated());
         }
         $msg .= '</td></tr>';
     }
     if ($cloneBuy->getOtherInfos() != $buy->getOtherInfos()) {
         $msg .= '<tr><td>' . $this->translate('Buy.otherInfos.label') . '</td><td>';
         if ($cloneBuy->getOtherInfos() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneBuy->getOtherInfos();
         }
         $msg .= '</td><td>';
         if ($buy->getOtherInfos() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $buy->getOtherInfos();
         }
         $msg .= '</td></tr>';
     }
     if (\count(\array_diff($buy->getDocs()->toArray(), $cloneBuy->getDocs()->toArray())) != 0 || \count(\array_diff($cloneBuy->getDocs()->toArray(), $buy->getDocs()->toArray())) != 0) {
         $msg .= '<tr><td>' . $this->translate('Buy.docs.label') . '</td><td>';
         if (\count($cloneBuy->getDocs()) == 0) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= '<ul>';
             foreach ($cloneBuy->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($buy->getDocs()) == 0) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= '<ul>';
             foreach ($buy->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 ($msg != '') {
         $msg = $tableBegin . $msg . $tableEnd;
         $trace->setMsg($this->translate('Buy.traceEdit', array('%buy%' => $buy->getLabel(), '%mbpurchase%' => $buy->getMonthlyBalance()->getRef(), '%company%' => $buy->getCompany()->getCorporateName())) . $msg);
         $trace->setDtCrea(new \DateTime('now'));
         $em = $this->getEntityManager();
         $em->persist($trace);
         $em->flush();
     }
 }
 /**
  * Form builder
  *
  * @param FormBuilderInterface $builder
  * @param array $options
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->add('validated', ChoiceType::class, array('label' => 'Buy.validated.label', 'choices_as_values' => true, 'choices' => Buy::choiceValidated(), 'expanded' => true, '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 {
         $mbpurchase = $em->getRepository('AcfDataBundle:MBPurchase')->find($uid);
         if (null == $mbpurchase) {
             $this->flashMsgSession('warning', $this->translate('MBPurchase.edit.notfound'));
         } else {
             $traces = $em->getRepository('AcfDataBundle:Trace')->getAllByEntityId($mbpurchase->getId(), Trace::AE_MBPURCHASE);
             $this->gvars['traces'] = array_reverse($traces);
             $mbpurchaseUpdateCountForm = $this->createForm(MBPurchaseUpdateCountTForm::class, $mbpurchase);
             $buy = new Buy();
             $buy->setMonthlyBalance($mbpurchase);
             $buyNewForm = $this->createForm(BuyNewTForm::class, $buy, array('monthlybalance' => $mbpurchase));
             $buyImportForm = $this->createForm(BuyImportTForm::class);
             $mbpurchaseUpdateDocsForm = $this->createForm(MBPurchaseUpdateDocsTForm::class, $mbpurchase, array('company' => $mbpurchase->getCompany()));
             $doc = new Doc();
             $doc->setCompany($mbpurchase->getCompany());
             $docNewForm = $this->createForm(DocNewTForm::class, $doc, array('company' => $mbpurchase->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();
             $cloneMBPurchase = clone $mbpurchase;
             if (isset($reqData['BuyImportForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $this->gvars['stabActive'] = 1;
                 $this->getSession()->set('stabActive', 1);
                 $buyImportForm->handleRequest($request);
                 if ($buyImportForm->isValid()) {
                     ini_set('memory_limit', '4096M');
                     ini_set('max_execution_time', '0');
                     $extension = $buyImportForm['excel']->getData()->guessExtension();
                     if ($extension == 'zip') {
                         $extension = 'xlsx';
                     }
                     $filename = uniqid() . '.' . $extension;
                     $buyImportForm['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);
                     $suppliersConstStr = $em->getRepository('AcfDataBundle:ConstantStr')->findOneBy(array('name' => 'suppliersPrefix'));
                     if (null == $suppliersConstStr) {
                         $suppliersConstStr = new ConstantStr();
                         $suppliersConstStr->setName('suppliersPrefix');
                         $suppliersConstStr->setValue('401');
                         $em->persist($suppliersConstStr);
                         $em->flush();
                     }
                     $suppliersPrefix = $suppliersConstStr->getValue();
                     $suppliersPrefixNum = \intval($suppliersPrefix) * 1000000000;
                     $worksheet = $excelObj->getActiveSheet();
                     $highestRow = $worksheet->getHighestRow();
                     $lineRead = 0;
                     $buysNew = 0;
                     $lineUnprocessed = 0;
                     $lineError = 0;
                     $company = $mbpurchase->getCompany();
                     $accounts = $em->getRepository('AcfDataBundle:Account')->getAllByCompany($company);
                     $suppliers = $em->getRepository('AcfDataBundle:Supplier')->getAllByCompany($company);
                     $companyNatures = $em->getRepository('AcfDataBundle:CompanyNature')->getAllByCompany($company);
                     $withholdings = $em->getRepository('AcfDataBundle:Withholding')->getAllByCompany($company);
                     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()));
                         $supplierNum = \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());
                         $regime = \trim(\strval($worksheet->getCellByColumnAndRow(10, $row)->getValue()));
                         $withholdingValue = \trim(\strval($worksheet->getCellByColumnAndRow(12, $row)->getValue() * 100));
                         $balanceNet = \floatval($worksheet->getCellByColumnAndRow(13, $row)->getValue());
                         $paymentType = \trim(\strval($worksheet->getCellByColumnAndRow(14, $row)->getValue()));
                         $dtPayment = \PHPExcel_Shared_Date::ExcelToPHPObject($worksheet->getCellByColumnAndRow(15, $row)->getValue());
                         $accountLabel = \trim(\strval($worksheet->getCellByColumnAndRow(16, $row)->getValue()));
                         $natureLabel = \trim(\strval($worksheet->getCellByColumnAndRow(17, $row)->getValue()));
                         $status = \trim(\strval($worksheet->getCellByColumnAndRow(18, $row)->getValue()));
                         $otherInfos = \trim(\strval($worksheet->getCellByColumnAndRow(19, $row)->getValue()));
                         if ($supplierNum != '' && \is_numeric($supplierNum)) {
                             $supplierNum = \intval($supplierNum) - $suppliersPrefixNum;
                         }
                         $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 ($supplierNum == '' || $supplierNum <= 0) {
                             $haserror = true;
                             $oldsuppnum = $worksheet->getCellByColumnAndRow(4, $row)->getValue();
                             $log .= 'ligne ' . $lineRead . ', erreur : Numéro Fournisseur (' . $oldsuppnum . ')<br>';
                         } else {
                             $supplier = null;
                             $knownSupplier = false;
                             foreach ($suppliers as $s) {
                                 if ($s->getNumber() == $supplierNum) {
                                     $knownSupplier = true;
                                     $supplier = $s;
                                 }
                             }
                             if ($knownSupplier == false) {
                                 $haserror = true;
                                 $log .= 'ligne ' . $lineRead . ', erreur : Fournisseur 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 ($regime == $this->translate('Buy.regime.0')) {
                             $regime = 0;
                         } elseif ($regime == $this->translate('Buy.regime.1')) {
                             $regime = 1;
                         } elseif ($regime == $this->translate('Buy.regime.2')) {
                             $regime = 2;
                         } elseif ($regime == $this->translate('Buy.regime.3')) {
                             $regime = 3;
                         } elseif ($regime == $this->translate('Buy.regime.4')) {
                             $regime = 4;
                         } elseif ($regime == $this->translate('Buy.regime.5')) {
                             $regime = 5;
                         } else {
                             $regime = 0;
                             $log .= 'ligne ' . $lineRead . ', erreur (ignorée) : Régime inconnu => ' . $this->translate('Buy.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 à Payer<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 de Paiement inconnu => ' . $this->translate('Transaction.paymentType.0') . '<br>';
                         }
                         if (null == $dtPayment) {
                             $haserror = true;
                             $log .= 'ligne ' . $lineRead . ', erreur : Date de paiement<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>';
                         }
                         $nature = null;
                         foreach ($companyNatures as $n) {
                             if ($n->getLabel() == $natureLabel) {
                                 $nature = $n;
                             }
                         }
                         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) {
                             $buy = $em->getRepository('AcfDataBundle:Buy')->findOneBy(array('monthlyBalance' => $mbpurchase, 'bill' => $bill));
                             $exist = false;
                             if (null == $buy) {
                                 $buysNew++;
                                 $buy = new Buy();
                             } else {
                                 $lineUnprocessed++;
                                 $log .= "l'Achat à la ligne " . $lineRead . ' existe déjà et sera donc remplacé<br>';
                                 $exist = true;
                             }
                             $buy->setMonthlyBalance($mbpurchase);
                             if (!$exist) {
                                 $buy->setNumber($mbpurchase->getCount());
                             }
                             $buy->setDtActivation($dtActivation);
                             $buy->setBill($bill);
                             $buy->setRelation($supplier);
                             $buy->setLabel($label);
                             $buy->setVat($vat);
                             $buy->setVatDevise($vat);
                             $buy->setStamp($stamp);
                             $buy->setStampDevise($stamp);
                             $buy->setBalanceTtc($balanceTtc);
                             $buy->setBalanceTtcDevise($balanceTtc);
                             $buy->setRegime($regime);
                             $buy->setWithholding($withholding);
                             $buy->setBalanceNet($balanceNet);
                             $buy->setBalanceNetDevise($balanceNet);
                             $buy->setPaymentType($paymentType);
                             $buy->setDtPayment($dtPayment);
                             $buy->setAccount($account);
                             $buy->setNature($nature);
                             $buy->setTransactionStatus($status);
                             $buy->setOtherInfos($otherInfos);
                             $em->persist($buy);
                             if (!$exist) {
                                 $mbpurchase->updateCount();
                             }
                             $em->persist($mbpurchase);
                         } else {
                             $lineError++;
                             $log .= 'la ligne ' . $lineRead . ' contient des erreurs<br>';
                         }
                     }
                     $em->flush();
                     $log .= $lineRead . ' lignes lues<br>';
                     $log .= $buysNew . ' nouveaux Achat<br>';
                     $log .= $lineUnprocessed . ' Achats déjà dans la base<br>';
                     $log .= $lineError . ' lignes contenant des erreurs<br>';
                     // */
                     $this->flashMsgSession('log', $log);
                     $this->flashMsgSession('success', $this->translate('Buy.import.success'));
                     $this->gvars['tabActive'] = 1;
                     $this->getSession()->set('tabActive', 1);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($mbpurchase);
                     $this->flashMsgSession('error', $this->translate('Buy.import.failure'));
                 }
             } elseif (isset($reqData['BuyNewForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $this->gvars['stabActive'] = 2;
                 $this->getSession()->set('stabActive', 2);
                 $buyNewForm->handleRequest($request);
                 if ($buyNewForm->isValid()) {
                     $buy->setNumber($mbpurchase->getCount());
                     if ($buy->getDevise() == 'TND') {
                         $buy->setConversionRate(1);
                         $buy->setVatDevise($buy->getVat());
                         $buy->setStampDevise($buy->getStamp());
                         $buy->setBalanceTtcDevise($buy->getBalanceTtc());
                         $buy->setBalanceNetDevise($buy->getBalanceNet());
                     } else {
                         $buy->setVat($buy->getVatDevise() * $buy->getConversionRate());
                         $buy->setStamp($buy->getStampDevise() * $buy->getConversionRate());
                         $buy->setBalanceTtc($buy->getBalanceTtcDevise() * $buy->getConversionRate());
                         $buy->setBalanceNet($buy->getBalanceNetDevise() * $buy->getConversionRate());
                     }
                     foreach ($buyNewForm->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($mbpurchase->getCompany());
                         $doc->setFileName($fileName);
                         $doc->setOriginalName($originalName);
                         $doc->setSize($size);
                         $doc->setMimeType($mimeType);
                         $doc->setMd5($md5);
                         $doc->setDescription($docNewForm['description']->getData());
                         $em->persist($doc);
                         $buy->addDoc($doc);
                     }
                     $em->persist($buy);
                     $em->flush();
                     $mbpurchase->updateCount();
                     $em->persist($mbpurchase);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Buy.add.success', array('%buy%' => $buy->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($mbpurchase);
                     $this->flashMsgSession('error', $this->translate('Buy.add.failure'));
                 }
             } elseif (isset($reqData['MBPurchaseUpdateCountForm'])) {
                 $this->gvars['tabActive'] = 3;
                 $this->getSession()->set('tabActive', 3);
                 $mbpurchaseUpdateCountForm->handleRequest($request);
                 if ($mbpurchaseUpdateCountForm->isValid()) {
                     $em->persist($mbpurchase);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('MBPurchase.edit.success', array('%mbpurchase%' => $mbpurchase->getRef())));
                     $this->traceEntity($cloneMBPurchase, $mbpurchase);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($mbpurchase);
                     $this->flashMsgSession('error', $this->translate('MBPurchase.edit.failure', array('%mbpurchase%' => $mbpurchase->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($mbpurchase->getCompany());
                         $doc->setFileName($fileName);
                         $doc->setOriginalName($originalName);
                         $doc->setSize($size);
                         $doc->setMimeType($mimeType);
                         $doc->setMd5($md5);
                         $doc->setDescription($docNewForm['description']->getData());
                         $em->persist($doc);
                         $mbpurchase->addDoc($doc);
                         $docNames .= $doc->getOriginalName() . ' ';
                         $docs[] = $doc;
                     }
                     $em->persist($mbpurchase);
                     $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 = $mbpurchase->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($cloneMBPurchase, $mbpurchase);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($mbpurchase);
                     $this->flashMsgSession('error', $this->translate('Doc.add.failure'));
                 }
             } elseif (isset($reqData['MBPurchaseUpdateDocsForm'])) {
                 $this->gvars['tabActive'] = 4;
                 $this->getSession()->set('tabActive', 4);
                 $this->gvars['stabActive'] = 2;
                 $this->getSession()->set('stabActive', 2);
                 $mbpurchaseUpdateDocsForm->handleRequest($request);
                 if ($mbpurchaseUpdateDocsForm->isValid()) {
                     $em->persist($mbpurchase);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('MBPurchase.edit.success', array('%mbpurchase%' => $mbpurchase->getRef())));
                     $this->gvars['stabActive'] = 3;
                     $this->getSession()->set('stabActive', 3);
                     $this->traceEntity($cloneMBPurchase, $mbpurchase);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($mbpurchase);
                     $this->flashMsgSession('error', $this->translate('MBPurchase.edit.failure', array('%mbpurchase%' => $mbpurchase->getRef())));
                 }
             }
             $this->gvars['mbpurchase'] = $mbpurchase;
             $this->gvars['buy'] = $buy;
             $this->gvars['doc'] = $doc;
             $this->gvars['BuyNewForm'] = $buyNewForm->createView();
             $this->gvars['BuyImportForm'] = $buyImportForm->createView();
             $this->gvars['MBPurchaseUpdateCountForm'] = $mbpurchaseUpdateCountForm->createView();
             $this->gvars['MBPurchaseUpdateDocsForm'] = $mbpurchaseUpdateDocsForm->createView();
             $this->gvars['DocNewForm'] = $docNewForm->createView();
             $suppliersConstStr = $em->getRepository('AcfDataBundle:ConstantStr')->findOneBy(array('name' => 'suppliersPrefix'));
             if (null == $suppliersConstStr) {
                 $suppliersConstStr = new ConstantStr();
                 $suppliersConstStr->setName('suppliersPrefix');
                 $suppliersConstStr->setValue('401');
                 $em->persist($suppliersConstStr);
                 $em->flush();
             }
             $suppliersPrefix = $suppliersConstStr->getValue();
             $this->gvars['suppliersPrefix'] = $suppliersPrefix;
             $this->gvars['pagetitle'] = $this->translate('pagetitle.mbpurchase.edit', array('%mbpurchase%' => $mbpurchase->getRef()));
             $this->gvars['pagetitle_txt'] = $this->translate('pagetitle.mbpurchase.edit.txt', array('%mbpurchase%' => $mbpurchase->getRef()));
             return $this->renderResponse('AcfAdminBundle:MBPurchase: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('paymentType', ChoiceType::class, array('label' => 'Buy.paymentType.label', 'choices_as_values' => true, 'choices' => Buy::choicePaymentType(), 'attr' => array('choice_label_trans' => true)));
 }
 /**
  * Form builder
  *
  * @param FormBuilderInterface $builder
  * @param array $options
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->add('transactionStatus', ChoiceType::class, array('label' => 'Buy.transactionStatus.label', 'choices_as_values' => true, 'choices' => Buy::choiceTransactionStatus(), 'expanded' => true, 'attr' => array('choice_label_trans' => true)));
     $builder->add('dtPayment', DateType::class, array('label' => 'Buy.dtPayment.label', 'widget' => 'single_text', 'format' => 'yyyy-MM-dd'));
 }
 /**
  *
  * @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 {
         $mbpurchase = $em->getRepository('AcfDataBundle:MBPurchase')->find($uid);
         if (null == $mbpurchase) {
             $this->flashMsgSession('warning', $this->translate('MBPurchase.edit.notfound'));
         } else {
             $sc = $this->getSecurityTokenStorage();
             $user = $sc->getToken()->getUser();
             $company = $mbpurchase->getCompany();
             $companyUser = $em->getRepository('AcfDataBundle:CompanyUser')->findOneBy(array('company' => $company, 'user' => $user));
             if (null == $companyUser || $companyUser->getEditBuys() == 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();
             $buy = new Buy();
             $buy->setMonthlyBalance($mbpurchase);
             $buyNewForm = $this->createForm(BuyNewTForm::class, $buy, array('monthlybalance' => $mbpurchase));
             $mbpurchaseUpdateDocsForm = $this->createForm(MBPurchaseUpdateDocsTForm::class, $mbpurchase, array('company' => $mbpurchase->getCompany()));
             $doc = new Doc();
             $doc->setCompany($mbpurchase->getCompany());
             $docNewForm = $this->createForm(DocNewTForm::class, $doc, array('company' => $mbpurchase->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();
             $cloneMBPurchase = clone $mbpurchase;
             if (isset($reqData['BuyNewForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $this->gvars['stabActive'] = 2;
                 $this->getSession()->set('stabActive', 2);
                 $buyNewForm->handleRequest($request);
                 if ($buyNewForm->isValid()) {
                     $buy->setNumber($mbpurchase->getCount());
                     if ($buy->getDevise() == 'TND') {
                         $buy->setConversionRate(1);
                         $buy->setVatDevise($buy->getVat());
                         $buy->setStampDevise($buy->getStamp());
                         $buy->setBalanceTtcDevise($buy->getBalanceTtc());
                         $buy->setBalanceNetDevise($buy->getBalanceNet());
                     } else {
                         $buy->setVat($buy->getVatDevise() * $buy->getConversionRate());
                         $buy->setStamp($buy->getStampDevise() * $buy->getConversionRate());
                         $buy->setBalanceTtc($buy->getBalanceTtcDevise() * $buy->getConversionRate());
                         $buy->setBalanceNet($buy->getBalanceNetDevise() * $buy->getConversionRate());
                     }
                     foreach ($buyNewForm->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($mbpurchase->getCompany());
                         $doc->setFileName($fileName);
                         $doc->setOriginalName($originalName);
                         $doc->setSize($size);
                         $doc->setMimeType($mimeType);
                         $doc->setMd5($md5);
                         $doc->setDescription($docNewForm['description']->getData());
                         $em->persist($doc);
                         $buy->addDoc($doc);
                     }
                     $em->persist($buy);
                     $em->flush();
                     $mbpurchase->updateCount();
                     $em->persist($mbpurchase);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Buy.add.success', array('%buy%' => $buy->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($mbpurchase);
                     $this->flashMsgSession('error', $this->translate('Buy.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($mbpurchase->getCompany());
                         $doc->setFileName($fileName);
                         $doc->setOriginalName($originalName);
                         $doc->setSize($size);
                         $doc->setMimeType($mimeType);
                         $doc->setMd5($md5);
                         $doc->setDescription($docNewForm['description']->getData());
                         $em->persist($doc);
                         $mbpurchase->addDoc($doc);
                         $docs[] = $doc;
                         $docNames .= $doc->getOriginalName() . ' ';
                     }
                     $em->persist($mbpurchase);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Doc.add.success', array('%doc%' => $docNames)));
                     $this->newDocNotifyAdmin($mbpurchase, $docs);
                     $this->gvars['stabActive'] = 3;
                     $this->getSession()->set('stabActive', 3);
                     $this->traceEntity($cloneMBPurchase, $mbpurchase);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($mbpurchase);
                     $this->flashMsgSession('error', $this->translate('Doc.add.failure'));
                 }
             } elseif (isset($reqData['MBPurchaseUpdateDocsForm'])) {
                 $this->gvars['tabActive'] = 4;
                 $this->getSession()->set('tabActive', 4);
                 $this->gvars['stabActive'] = 2;
                 $this->getSession()->set('stabActive', 2);
                 $mbpurchaseUpdateDocsForm->handleRequest($request);
                 if ($mbpurchaseUpdateDocsForm->isValid()) {
                     $em->persist($mbpurchase);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('MBPurchase.edit.success', array('%mbpurchase%' => $mbpurchase->getRef())));
                     $this->gvars['stabActive'] = 3;
                     $this->getSession()->set('stabActive', 3);
                     $this->traceEntity($cloneMBPurchase, $mbpurchase);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($mbpurchase);
                     $this->flashMsgSession('error', $this->translate('MBPurchase.edit.failure', array('%mbpurchase%' => $mbpurchase->getRef())));
                 }
             }
             $this->gvars['mbpurchase'] = $mbpurchase;
             $this->gvars['buy'] = $buy;
             $this->gvars['doc'] = $doc;
             $this->gvars['BuyNewForm'] = $buyNewForm->createView();
             $this->gvars['MBPurchaseUpdateDocsForm'] = $mbpurchaseUpdateDocsForm->createView();
             $this->gvars['DocNewForm'] = $docNewForm->createView();
             $suppliersConstStr = $em->getRepository('AcfDataBundle:ConstantStr')->findOneBy(array('name' => 'suppliersPrefix'));
             if (null == $suppliersConstStr) {
                 $suppliersConstStr = new ConstantStr();
                 $suppliersConstStr->setName('suppliersPrefix');
                 $suppliersConstStr->setValue('401');
                 $em->persist($suppliersConstStr);
                 $em->flush();
             }
             $suppliersPrefix = $suppliersConstStr->getValue();
             $this->gvars['suppliersPrefix'] = $suppliersPrefix;
             $this->gvars['pagetitle'] = $this->translate('pagetitle.mbpurchase.edit', array('%mbpurchase%' => $mbpurchase->getRef()));
             $this->gvars['pagetitle_txt'] = $this->translate('pagetitle.mbpurchase.edit.txt', array('%mbpurchase%' => $mbpurchase->getRef()));
             return $this->renderResponse('AcfClientBundle:MBPurchase:edit.html.twig', $this->gvars);
         }
     } catch (\Exception $e) {
         $logger = $this->getLogger();
         $logger->addCritical($e->getLine() . ' ' . $e->getMessage() . ' ' . $e->getTraceAsString());
     }
     return $this->redirect($urlFrom);
 }
Esempio n. 7
0
 /**
  * Form builder
  *
  * @param FormBuilderInterface $builder
  * @param array $options
  *
  * @return null
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $this->mbpurchase = $options['monthlybalance'];
     if (null == $this->mbpurchase) {
         $builder->add('monthlyBalance', EntityType::class, array('label' => 'Buy.monthlyBalance.label', 'class' => 'AcfDataBundle:MBPurchase', 'query_builder' => function (MBPurchaseRepository $mbsr) {
             return $mbsr->createQueryBuilder('mbs')->orderBy('mbs.ref', 'ASC');
         }, 'choice_label' => 'ref', 'multiple' => false, 'by_reference' => true, 'required' => true));
     } else {
         $mbpurchaseId = $this->mbpurchase->getId();
         $builder->add('monthlyBalance', EntityidType::class, array('label' => 'Buy.monthlyBalance.label', 'class' => 'AcfDataBundle:MBPurchase', 'query_builder' => function (MBPurchaseRepository $mbsr) use($mbpurchaseId) {
             return $mbsr->createQueryBuilder('mbs')->where('mbs.id = :id')->setParameter('id', $mbpurchaseId)->orderBy('mbs.ref', 'ASC');
         }, 'choice_label' => 'id', 'multiple' => false, 'by_reference' => true, 'required' => true));
     }
     $builder->add('dtActivation', DateType::class, array('label' => 'Buy.dtActivation.label', 'widget' => 'single_text', 'format' => 'yyyy-MM-dd'));
     $builder->add('bill', TextType::class, array('label' => 'Buy.bill.label', 'required' => false));
     if (null == $this->mbpurchase) {
         $builder->add('relation', EntityType::class, array('label' => 'Buy.relation.label', 'class' => 'AcfDataBundle:Supplier', 'query_builder' => function (SupplierRepository $sr) {
             return $sr->createQueryBuilder('s')->orderBy('s.label', 'ASC');
         }, 'choice_label' => 'label', 'multiple' => false, 'by_reference' => true, 'required' => true));
     } else {
         $companyId = $this->mbpurchase->getCompany()->getId();
         $builder->add('relation', EntityType::class, array('label' => 'Buy.relation.label', 'class' => 'AcfDataBundle:Supplier', 'query_builder' => function (SupplierRepository $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' => 'Buy.label.label'));
     $builder->add('devise', CurrencyType::class, array('label' => 'Buy.devise.label'));
     $builder->add('conversionRate', NumberType::class, array('label' => 'Buy.conversionRate.label'));
     $builder->add('vat', NumberType::class, array('label' => 'Buy.vat.label', 'required' => false));
     $builder->add('stamp', NumberType::class, array('label' => 'Buy.stamp.label', 'required' => false));
     $builder->add('balanceTtc', NumberType::class, array('label' => 'Buy.balanceTtc.label', 'required' => false));
     $builder->add('balanceNet', NumberType::class, array('label' => 'Buy.balanceNet.label', 'required' => false));
     $builder->add('vatDevise', NumberType::class, array('label' => 'Buy.vatDevise.label', 'required' => false));
     $builder->add('stampDevise', NumberType::class, array('label' => 'Buy.stampDevise.label', 'required' => false));
     $builder->add('balanceTtcDevise', NumberType::class, array('label' => 'Buy.balanceTtcDevise.label', 'required' => false));
     $builder->add('balanceNetDevise', NumberType::class, array('label' => 'Buy.balanceNetDevise.label', 'required' => false));
     $builder->add('regime', ChoiceType::class, array('label' => 'Buy.regime.label', 'choices_as_values' => true, 'choices' => Buy::choiceRegime(), 'attr' => array('choice_label_trans' => true)));
     if (null == $this->mbpurchase) {
         $builder->add('withholding', EntityType::class, array('label' => 'Buy.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->mbpurchase->getCompany()->getId();
         $builder->add('withholding', EntityType::class, array('label' => 'Buy.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));
     }
     if (null == $this->mbpurchase) {
         $builder->add('nature', EntityType::class, array('label' => 'Buy.nature.label', 'class' => 'AcfDataBundle:CompanyNature', 'query_builder' => function (CompanyNatureRepository $cnr) {
             return $cnr->createQueryBuilder('cn')->orderBy('cn.label', 'ASC');
         }, 'choice_label' => 'label', 'multiple' => false, 'by_reference' => true, 'required' => true));
     } else {
         $companyId = $this->mbpurchase->getCompany()->getId();
         $builder->add('nature', EntityType::class, array('label' => 'Buy.nature.label', 'class' => 'AcfDataBundle:CompanyNature', 'query_builder' => function (CompanyNatureRepository $cnr) use($companyId) {
             return $cnr->createQueryBuilder('cn')->join('cn.company', 'c')->where('c.id = :cid')->setParameter('cid', $companyId)->orderBy('cn.label', 'ASC');
         }, 'choice_label' => 'label', 'multiple' => false, 'by_reference' => true, 'required' => true));
     }
     $builder->add('paymentType', ChoiceType::class, array('label' => 'Buy.paymentType.label', 'choices_as_values' => true, 'choices' => Buy::choicePaymentType(), 'attr' => array('choice_label_trans' => true)));
     $builder->add('transactionStatus', ChoiceType::class, array('label' => 'Buy.transactionStatus.label', 'choices_as_values' => true, 'choices_as_values' => true, 'choices' => Buy::choiceTransactionStatus(), 'expanded' => true, 'attr' => array('choice_label_trans' => true)));
     $builder->add('dtPayment', DateType::class, array('label' => 'Buy.dtPayment.label', 'widget' => 'single_text', 'format' => 'yyyy-MM-dd', 'required' => false));
     if (null == $this->mbpurchase) {
         $builder->add('account', EntityType::class, array('label' => 'Buy.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->mbpurchase->getCompany()->getId();
         $builder->add('account', EntityType::class, array('label' => 'Buy.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' => 'Buy.docs.label', 'entry_type' => BuyDocTForm::class, 'allow_add' => true, 'allow_delete' => true, 'by_reference' => false, 'mapped' => false, 'constraints' => new Valid()));
     $builder->add('otherInfos', TextareaType::class, array('label' => 'Buy.otherInfos.label', 'required' => false));
 }