示例#1
0
 /**
  * Add doc
  *
  * @param Doc $doc
  *
  * @return Docgroupsyst
  */
 public function addDoc(Doc $doc)
 {
     $this->docs[] = $doc;
     $doc->addGroupsyst($this);
     return $this;
 }
示例#2
0
 /**
  * Add doc
  *
  * @param Doc $doc
  *
  * @return Transaction
  */
 public function addDoc(Doc $doc)
 {
     $this->docs[] = $doc;
     $doc->addTransaction($this);
     return $this;
 }
示例#3
0
 /**
  *
  * @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('_admin_company_list');
     }
     $em = $this->getEntityManager();
     try {
         $customer = $em->getRepository('AcfDataBundle:Customer')->find($uid);
         if (null == $customer) {
             $this->flashMsgSession('warning', $this->translate('Customer.edit.notfound'));
         } else {
             $traces = $em->getRepository('AcfDataBundle:Trace')->getAllByEntityId($customer->getId(), Trace::AE_CUSTOMER);
             $this->gvars['traces'] = array_reverse($traces);
             $customerUpdateForm = $this->createForm(CustomerUpdateTForm::class, $customer);
             $customerUpdateDocsForm = $this->createForm(CustomerUpdateDocsTForm::class, $customer, array('company' => $customer->getCompany()));
             $doc = new Doc();
             $doc->setCompany($customer->getCompany());
             $docNewForm = $this->createForm(DocNewTForm::class, $doc, array('company' => $customer->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();
             $cloneCustomer = clone $customer;
             if (isset($reqData['CustomerUpdateForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $customerUpdateForm->handleRequest($request);
                 if ($customerUpdateForm->isValid()) {
                     $em->persist($customer);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Customer.edit.success', array('%customer%' => $customer->getLabel())));
                     $this->traceEntity($cloneCustomer, $customer);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($customer);
                     $this->flashMsgSession('error', $this->translate('Customer.edit.failure', array('%customer%' => $customer->getLabel())));
                 }
             } elseif (isset($reqData['DocNewForm'])) {
                 $this->gvars['tabActive'] = 3;
                 $this->getSession()->set('tabActive', 3);
                 $this->gvars['stabActive'] = 1;
                 $this->getSession()->set('stabActive', 1);
                 $docNewForm->handleRequest($request);
                 if ($docNewForm->isValid()) {
                     $docs = array();
                     $docFiles = $docNewForm['fileName']->getData();
                     $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($customer->getCompany());
                         $doc->setFileName($fileName);
                         $doc->setOriginalName($originalName);
                         $doc->setSize($size);
                         $doc->setMimeType($mimeType);
                         $doc->setMd5($md5);
                         $doc->setDescription($docNewForm['description']->getData());
                         $em->persist($doc);
                         $customer->addDoc($doc);
                         $docNames .= $doc->getOriginalName() . ' ';
                         $docs[] = $doc;
                     }
                     $em->persist($customer);
                     $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 = $customer->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($cloneCustomer, $customer);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($customer);
                     $this->flashMsgSession('error', $this->translate('Doc.add.failure'));
                 }
             } elseif (isset($reqData['CustomerUpdateDocsForm'])) {
                 $this->gvars['tabActive'] = 3;
                 $this->getSession()->set('tabActive', 3);
                 $this->gvars['stabActive'] = 2;
                 $this->getSession()->set('stabActive', 2);
                 $customerUpdateDocsForm->handleRequest($request);
                 if ($customerUpdateDocsForm->isValid()) {
                     $em->persist($customer);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Customer.edit.success', array('%customer%' => $customer->getLabel())));
                     $this->gvars['stabActive'] = 3;
                     $this->getSession()->set('stabActive', 3);
                     $this->traceEntity($cloneCustomer, $customer);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($customer);
                     $this->flashMsgSession('error', $this->translate('Customer.edit.failure', array('%customer%' => $customer->getLabel())));
                 }
             }
             $this->gvars['customer'] = $customer;
             $this->gvars['doc'] = $doc;
             $this->gvars['CustomerUpdateForm'] = $customerUpdateForm->createView();
             $this->gvars['CustomerUpdateDocsForm'] = $customerUpdateDocsForm->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.customer.edit', array('%customer%' => $customer->getLabel()));
             $this->gvars['pagetitle_txt'] = $this->translate('pagetitle.customer.edit.txt', array('%customer%' => $customer->getLabel()));
             return $this->renderResponse('AcfAdminBundle:Customer:edit.html.twig', $this->gvars);
         }
     } catch (\Exception $e) {
         $logger = $this->getLogger();
         $logger->addCritical($e->getLine() . ' ' . $e->getMessage() . ' ' . $e->getTraceAsString());
     }
     return $this->redirect($urlFrom);
 }
示例#4
0
 /**
  * Add doc
  *
  * @param Doc $doc
  *
  * @return Docgroupcomptable
  */
 public function addDoc(Doc $doc)
 {
     $this->docs[] = $doc;
     $doc->addGroupcomptable($this);
     return $this;
 }
 /**
  *
  * @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 {
         $docgroupperso = $em->getRepository('AcfDataBundle:Docgroupperso')->find($uid);
         if (null == $docgroupperso) {
             $this->flashMsgSession('warning', $this->translate('Docgroupperso.edit.notfound'));
         } else {
             $sc = $this->getSecurityTokenStorage();
             $user = $sc->getToken()->getUser();
             $company = $docgroupperso->getCompany();
             $companyUser = $em->getRepository('AcfDataBundle:CompanyUser')->findOneBy(array('company' => $company, 'user' => $user));
             if (null == $companyUser || $companyUser->getEditDocgroupPersos() == 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();
             $docgrouppersoUpdateDocsForm = $this->createForm(DocgrouppersoUpdateDocsTForm::class, $docgroupperso, array('company' => $docgroupperso->getCompany()));
             $doc = new Doc();
             $doc->setCompany($docgroupperso->getCompany());
             $docNewForm = $this->createForm(DocNewTForm::class, $doc, array('company' => $docgroupperso->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();
             $cloneDocgroupperso = clone $docgroupperso;
             if (isset($reqData['DocNewForm'])) {
                 $this->gvars['tabActive'] = 3;
                 $this->getSession()->set('tabActive', 3);
                 $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($docgroupperso->getCompany());
                         $doc->setFileName($fileName);
                         $doc->setOriginalName($originalName);
                         $doc->setSize($size);
                         $doc->setMimeType($mimeType);
                         $doc->setMd5($md5);
                         $doc->setDescription($docNewForm['description']->getData());
                         $em->persist($doc);
                         $docgroupperso->addDoc($doc);
                         $docs[] = $doc;
                         $docNames .= $doc->getOriginalName() . ' ';
                     }
                     $em->persist($docgroupperso);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Doc.add.success', array('%doc%' => $docNames)));
                     $this->newDocNotifyAdmin($docgroupperso, $docs);
                     $this->gvars['stabActive'] = 3;
                     $this->getSession()->set('stabActive', 3);
                     $this->traceEntity($cloneDocgroupperso, $docgroupperso);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($docgroupperso);
                     $this->flashMsgSession('error', $this->translate('Doc.add.failure'));
                 }
             } elseif (isset($reqData['DocgrouppersoUpdateDocsForm'])) {
                 $this->gvars['tabActive'] = 3;
                 $this->getSession()->set('tabActive', 3);
                 $this->gvars['stabActive'] = 2;
                 $this->getSession()->set('stabActive', 2);
                 $docgrouppersoUpdateDocsForm->handleRequest($request);
                 if ($docgrouppersoUpdateDocsForm->isValid()) {
                     $em->persist($docgroupperso);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Docgroupperso.edit.success', array('%docgroupperso%' => $docgroupperso->getLabel())));
                     $this->gvars['stabActive'] = 3;
                     $this->getSession()->set('stabActive', 3);
                     $this->traceEntity($cloneDocgroupperso, $docgroupperso);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($docgroupperso);
                     $this->flashMsgSession('error', $this->translate('Docgroupperso.edit.failure', array('%docgroupperso%' => $docgroupperso->getLabel())));
                 }
             }
             $this->gvars['docgroupperso'] = $docgroupperso;
             $this->gvars['doc'] = $doc;
             $this->gvars['DocgrouppersoUpdateDocsForm'] = $docgrouppersoUpdateDocsForm->createView();
             $this->gvars['DocNewForm'] = $docNewForm->createView();
             $this->gvars['pagetitle'] = $this->translate('pagetitle.docgroupperso.edit', array('%docgroupperso%' => $docgroupperso->getLabel()));
             $this->gvars['pagetitle_txt'] = $this->translate('pagetitle.docgroupperso.edit.txt', array('%docgroupperso%' => $docgroupperso->getLabel()));
             return $this->renderResponse('AcfClientBundle:Docgroupperso:edit.html.twig', $this->gvars);
         }
     } catch (\Exception $e) {
         $logger = $this->getLogger();
         $logger->addCritical($e->getLine() . ' ' . $e->getMessage() . ' ' . $e->getTraceAsString());
     }
     return $this->redirect($urlFrom);
 }
示例#6
0
 /**
  *
  * @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 {
         $buy = $em->getRepository('AcfDataBundle:Buy')->find($uid);
         if (null == $buy) {
             $this->flashMsgSession('warning', $this->translate('Buy.edit.notfound'));
         } else {
             $sc = $this->getSecurityTokenStorage();
             $user = $sc->getToken()->getUser();
             $company = $buy->getMonthlyBalance()->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();
             $buyUpdateNumberForm = $this->createForm(BuyUpdateNumberTForm::class, $buy);
             $buyUpdateDtActivationForm = $this->createForm(BuyUpdateDtActivationTForm::class, $buy);
             $buyUpdateBillForm = $this->createForm(BuyUpdateBillTForm::class, $buy);
             $buyUpdateRelationForm = $this->createForm(BuyUpdateRelationTForm::class, $buy, array('monthlybalance' => $buy->getMonthlyBalance()));
             $buyUpdateLabelForm = $this->createForm(BuyUpdateLabelTForm::class, $buy);
             $buyUpdateDeviseForm = $this->createForm(BuyUpdateDeviseTForm::class, $buy);
             $buyUpdateConversionRateForm = $this->createForm(BuyUpdateConversionRateTForm::class, $buy);
             $buyUpdateVatForm = $this->createForm(BuyUpdateVatTForm::class, $buy);
             $buyUpdateVatDeviseForm = $this->createForm(BuyUpdateVatDeviseTForm::class, $buy);
             $buyUpdateStampForm = $this->createForm(BuyUpdateStampTForm::class, $buy);
             $buyUpdateStampDeviseForm = $this->createForm(BuyUpdateStampDeviseTForm::class, $buy);
             $buyUpdateBalanceTtcForm = $this->createForm(BuyUpdateBalanceTtcTForm::class, $buy);
             $buyUpdateBalanceTtcDeviseForm = $this->createForm(BuyUpdateBalanceTtcDeviseTForm::class, $buy);
             $buyUpdateRegimeForm = $this->createForm(BuyUpdateRegimeTForm::class, $buy);
             $buyUpdateWithholdingForm = $this->createForm(BuyUpdateWithholdingTForm::class, $buy, array('monthlybalance' => $buy->getMonthlyBalance()));
             $buyUpdateBalanceNetForm = $this->createForm(BuyUpdateBalanceNetTForm::class, $buy);
             $buyUpdateBalanceNetDeviseForm = $this->createForm(BuyUpdateBalanceNetDeviseTForm::class, $buy);
             $buyUpdatePaymentTypeForm = $this->createForm(BuyUpdatePaymentTypeTForm::class, $buy);
             $buyUpdateTransactionStatusForm = $this->createForm(BuyUpdateTransactionStatusTForm::class, $buy);
             $buyUpdateAccountForm = $this->createForm(BuyUpdateAccountTForm::class, $buy, array('monthlybalance' => $buy->getMonthlyBalance()));
             $buyUpdateNatureForm = $this->createForm(BuyUpdateNatureTForm::class, $buy, array('monthlybalance' => $buy->getMonthlyBalance()));
             $buyUpdateOtherInfosForm = $this->createForm(BuyUpdateOtherInfosTForm::class, $buy);
             $buyUpdateDocsForm = $this->createForm(BuyUpdateDocsTForm::class, $buy, array('company' => $buy->getCompany()));
             $doc = new Doc();
             $doc->setCompany($buy->getCompany());
             $docNewForm = $this->createForm(DocNewTForm::class, $doc, array('company' => $buy->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();
             $cloneBuy = clone $buy;
             if (isset($reqData['BuyUpdateNumberForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $buyUpdateNumberForm->handleRequest($request);
                 if ($buyUpdateNumberForm->isValid()) {
                     $em->persist($buy);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Buy.edit.success', array('%buy%' => $buy->getNumber())));
                     $this->traceEntity($cloneBuy, $buy);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($buy);
                     $this->flashMsgSession('error', $this->translate('Buy.edit.failure', array('%buy%' => $buy->getNumber())));
                 }
             } elseif (isset($reqData['BuyUpdateDtActivationForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $buyUpdateDtActivationForm->handleRequest($request);
                 if ($buyUpdateDtActivationForm->isValid()) {
                     $em->persist($buy);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Buy.edit.success', array('%buy%' => $buy->getNumber())));
                     $this->traceEntity($cloneBuy, $buy);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($buy);
                     $this->flashMsgSession('error', $this->translate('Buy.edit.failure', array('%buy%' => $buy->getNumber())));
                 }
             } elseif (isset($reqData['BuyUpdateBillForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $buyUpdateBillForm->handleRequest($request);
                 if ($buyUpdateBillForm->isValid()) {
                     $em->persist($buy);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Buy.edit.success', array('%buy%' => $buy->getNumber())));
                     $this->traceEntity($cloneBuy, $buy);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($buy);
                     $this->flashMsgSession('error', $this->translate('Buy.edit.failure', array('%buy%' => $buy->getNumber())));
                 }
             } elseif (isset($reqData['BuyUpdateRelationForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $buyUpdateRelationForm->handleRequest($request);
                 if ($buyUpdateRelationForm->isValid()) {
                     $em->persist($buy);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Buy.edit.success', array('%buy%' => $buy->getNumber())));
                     $this->traceEntity($cloneBuy, $buy);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($buy);
                     $this->flashMsgSession('error', $this->translate('Buy.edit.failure', array('%buy%' => $buy->getNumber())));
                 }
             } elseif (isset($reqData['BuyUpdateLabelForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $buyUpdateLabelForm->handleRequest($request);
                 if ($buyUpdateLabelForm->isValid()) {
                     $em->persist($buy);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Buy.edit.success', array('%buy%' => $buy->getNumber())));
                     $this->traceEntity($cloneBuy, $buy);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($buy);
                     $this->flashMsgSession('error', $this->translate('Buy.edit.failure', array('%buy%' => $buy->getNumber())));
                 }
             } elseif (isset($reqData['BuyUpdateNatureForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $buyUpdateNatureForm->handleRequest($request);
                 if ($buyUpdateNatureForm->isValid()) {
                     $em->persist($buy);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Buy.edit.success', array('%buy%' => $buy->getNumber())));
                     $this->traceEntity($cloneBuy, $buy);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($buy);
                     $this->flashMsgSession('error', $this->translate('Buy.edit.failure', array('%buy%' => $buy->getNumber())));
                 }
             } elseif (isset($reqData['BuyUpdateDeviseForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $buyUpdateDeviseForm->handleRequest($request);
                 if ($buyUpdateDeviseForm->isValid()) {
                     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());
                     }
                     $em->persist($buy);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Buy.edit.success', array('%buy%' => $buy->getNumber())));
                     $this->traceEntity($cloneBuy, $buy);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($buy);
                     $this->flashMsgSession('error', $this->translate('Buy.edit.failure', array('%buy%' => $buy->getNumber())));
                 }
             } elseif (isset($reqData['BuyUpdateConversionRateForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $buyUpdateConversionRateForm->handleRequest($request);
                 if ($buyUpdateConversionRateForm->isValid()) {
                     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());
                     }
                     $em->persist($buy);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Buy.edit.success', array('%buy%' => $buy->getNumber())));
                     $this->traceEntity($cloneBuy, $buy);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($buy);
                     $this->flashMsgSession('error', $this->translate('Buy.edit.failure', array('%buy%' => $buy->getNumber())));
                 }
             } elseif (isset($reqData['BuyUpdateVatForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $buyUpdateVatForm->handleRequest($request);
                 if ($buyUpdateVatForm->isValid()) {
                     $buy->setConversionRate(1);
                     $buy->setVatDevise($buy->getVat());
                     $em->persist($buy);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Buy.edit.success', array('%buy%' => $buy->getNumber())));
                     $this->traceEntity($cloneBuy, $buy);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($buy);
                     $this->flashMsgSession('error', $this->translate('Buy.edit.failure', array('%buy%' => $buy->getNumber())));
                 }
             } elseif (isset($reqData['BuyUpdateVatDeviseForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $buyUpdateVatDeviseForm->handleRequest($request);
                 if ($buyUpdateVatDeviseForm->isValid()) {
                     $buy->setVat($buy->getVatDevise() * $buy->getConversionRate());
                     $em->persist($buy);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Buy.edit.success', array('%buy%' => $buy->getNumber())));
                     $this->traceEntity($cloneBuy, $buy);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($buy);
                     $this->flashMsgSession('error', $this->translate('Buy.edit.failure', array('%buy%' => $buy->getNumber())));
                 }
             } elseif (isset($reqData['BuyUpdateStampForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $buyUpdateStampForm->handleRequest($request);
                 if ($buyUpdateStampForm->isValid()) {
                     $buy->setConversionRate(1);
                     $buy->setStampDevise($buy->getStamp());
                     $em->persist($buy);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Buy.edit.success', array('%buy%' => $buy->getNumber())));
                     $this->traceEntity($cloneBuy, $buy);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($buy);
                     $this->flashMsgSession('error', $this->translate('Buy.edit.failure', array('%buy%' => $buy->getNumber())));
                 }
             } elseif (isset($reqData['BuyUpdateStampDeviseForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $buyUpdateStampDeviseForm->handleRequest($request);
                 if ($buyUpdateStampDeviseForm->isValid()) {
                     $buy->setStamp($buy->getStampDevise() * $buy->getConversionRate());
                     $em->persist($buy);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Buy.edit.success', array('%buy%' => $buy->getNumber())));
                     $this->traceEntity($cloneBuy, $buy);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($buy);
                     $this->flashMsgSession('error', $this->translate('Buy.edit.failure', array('%buy%' => $buy->getNumber())));
                 }
             } elseif (isset($reqData['BuyUpdateBalanceTtcForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $buyUpdateBalanceTtcForm->handleRequest($request);
                 if ($buyUpdateBalanceTtcForm->isValid()) {
                     $buy->setConversionRate(1);
                     $buy->setBalanceTtcDevise($buy->getBalanceTtc());
                     $em->persist($buy);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Buy.edit.success', array('%buy%' => $buy->getNumber())));
                     $this->traceEntity($cloneBuy, $buy);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($buy);
                     $this->flashMsgSession('error', $this->translate('Buy.edit.failure', array('%buy%' => $buy->getNumber())));
                 }
             } elseif (isset($reqData['BuyUpdateBalanceTtcDeviseForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $buyUpdateBalanceTtcDeviseForm->handleRequest($request);
                 if ($buyUpdateBalanceTtcDeviseForm->isValid()) {
                     $buy->setBalanceTtc($buy->getBalanceTtcDevise() * $buy->getConversionRate());
                     $em->persist($buy);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Buy.edit.success', array('%buy%' => $buy->getNumber())));
                     $this->traceEntity($cloneBuy, $buy);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($buy);
                     $this->flashMsgSession('error', $this->translate('Buy.edit.failure', array('%buy%' => $buy->getNumber())));
                 }
             } elseif (isset($reqData['BuyUpdateRegimeForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $buyUpdateRegimeForm->handleRequest($request);
                 if ($buyUpdateRegimeForm->isValid()) {
                     $em->persist($buy);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Buy.edit.success', array('%buy%' => $buy->getNumber())));
                     $this->traceEntity($cloneBuy, $buy);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($buy);
                     $this->flashMsgSession('error', $this->translate('Buy.edit.failure', array('%buy%' => $buy->getNumber())));
                 }
             } elseif (isset($reqData['BuyUpdateWithholdingForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $buyUpdateWithholdingForm->handleRequest($request);
                 if ($buyUpdateWithholdingForm->isValid()) {
                     $em->persist($buy);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Buy.edit.success', array('%buy%' => $buy->getNumber())));
                     $this->traceEntity($cloneBuy, $buy);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($buy);
                     $this->flashMsgSession('error', $this->translate('Buy.edit.failure', array('%buy%' => $buy->getNumber())));
                 }
             } elseif (isset($reqData['BuyUpdateBalanceNetForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $buyUpdateBalanceNetForm->handleRequest($request);
                 if ($buyUpdateBalanceNetForm->isValid()) {
                     $buy->setConversionRate(1);
                     $buy->setBalanceNetDevise($buy->getBalanceNet());
                     $em->persist($buy);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Buy.edit.success', array('%buy%' => $buy->getNumber())));
                     $this->traceEntity($cloneBuy, $buy);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($buy);
                     $this->flashMsgSession('error', $this->translate('Buy.edit.failure', array('%buy%' => $buy->getNumber())));
                 }
             } elseif (isset($reqData['BuyUpdateBalanceNetDeviseForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $buyUpdateBalanceNetDeviseForm->handleRequest($request);
                 if ($buyUpdateBalanceNetDeviseForm->isValid()) {
                     $buy->setBalanceNet($buy->getBalanceNetDevise() * $buy->getConversionRate());
                     $em->persist($buy);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Buy.edit.success', array('%buy%' => $buy->getNumber())));
                     $this->traceEntity($cloneBuy, $buy);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($buy);
                     $this->flashMsgSession('error', $this->translate('Buy.edit.failure', array('%buy%' => $buy->getNumber())));
                 }
             } elseif (isset($reqData['BuyUpdatePaymentTypeForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $buyUpdatePaymentTypeForm->handleRequest($request);
                 if ($buyUpdatePaymentTypeForm->isValid()) {
                     $em->persist($buy);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Buy.edit.success', array('%buy%' => $buy->getNumber())));
                     $this->traceEntity($cloneBuy, $buy);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($buy);
                     $this->flashMsgSession('error', $this->translate('Buy.edit.failure', array('%buy%' => $buy->getNumber())));
                 }
             } elseif (isset($reqData['BuyUpdateTransactionStatusForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $buyUpdateTransactionStatusForm->handleRequest($request);
                 if ($buyUpdateTransactionStatusForm->isValid()) {
                     $em->persist($buy);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Buy.edit.success', array('%buy%' => $buy->getNumber())));
                     $this->traceEntity($cloneBuy, $buy);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($buy);
                     $this->flashMsgSession('error', $this->translate('Buy.edit.failure', array('%buy%' => $buy->getNumber())));
                 }
             } elseif (isset($reqData['BuyUpdateAccountForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $buyUpdateAccountForm->handleRequest($request);
                 if ($buyUpdateAccountForm->isValid()) {
                     $em->persist($buy);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Buy.edit.success', array('%buy%' => $buy->getNumber())));
                     $this->traceEntity($cloneBuy, $buy);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($buy);
                     $this->flashMsgSession('error', $this->translate('Buy.edit.failure', array('%buy%' => $buy->getNumber())));
                 }
             } elseif (isset($reqData['BuyUpdateNatureForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $buyUpdateNatureForm->handleRequest($request);
                 if ($buyUpdateNatureForm->isValid()) {
                     $em->persist($buy);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Buy.edit.success', array('%buy%' => $buy->getNumber())));
                     $this->traceEntity($cloneBuy, $buy);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($buy);
                     $this->flashMsgSession('error', $this->translate('Buy.edit.failure', array('%buy%' => $buy->getNumber())));
                 }
             } elseif (isset($reqData['BuyUpdateOtherInfosForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $buyUpdateOtherInfosForm->handleRequest($request);
                 if ($buyUpdateOtherInfosForm->isValid()) {
                     $em->persist($buy);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Buy.edit.success', array('%buy%' => $buy->getNumber())));
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($buy);
                     $this->flashMsgSession('error', $this->translate('Buy.edit.failure', array('%buy%' => $buy->getNumber())));
                 }
             } elseif (isset($reqData['DocNewForm'])) {
                 $this->gvars['tabActive'] = 3;
                 $this->getSession()->set('tabActive', 3);
                 $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($buy->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);
                         $docs[] = $doc;
                         $docNames .= $doc->getOriginalName() . ' ';
                     }
                     $em->persist($buy);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Doc.add.success', array('%doc%' => $docNames)));
                     $this->newDocNotifyAdmin($buy, $docs);
                     $this->gvars['stabActive'] = 3;
                     $this->getSession()->set('stabActive', 3);
                     $this->traceEntity($cloneBuy, $buy);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($buy);
                     $this->flashMsgSession('error', $this->translate('Doc.add.failure'));
                 }
             } elseif (isset($reqData['BuyUpdateDocsForm'])) {
                 $this->gvars['tabActive'] = 3;
                 $this->getSession()->set('tabActive', 3);
                 $this->gvars['stabActive'] = 2;
                 $this->getSession()->set('stabActive', 2);
                 $buyUpdateDocsForm->handleRequest($request);
                 if ($buyUpdateDocsForm->isValid()) {
                     $em->persist($buy);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Buy.edit.success', array('%buy%' => $buy->getNumber())));
                     $this->gvars['stabActive'] = 3;
                     $this->getSession()->set('stabActive', 3);
                     $this->traceEntity($cloneBuy, $buy);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($buy);
                     $this->flashMsgSession('error', $this->translate('Buy.edit.failure', array('%buy%' => $buy->getNumber())));
                 }
             }
             $this->gvars['buy'] = $buy;
             $this->gvars['doc'] = $doc;
             $this->gvars['BuyUpdateNumberForm'] = $buyUpdateNumberForm->createView();
             $this->gvars['BuyUpdateDtActivationForm'] = $buyUpdateDtActivationForm->createView();
             $this->gvars['BuyUpdateBillForm'] = $buyUpdateBillForm->createView();
             $this->gvars['BuyUpdateRelationForm'] = $buyUpdateRelationForm->createView();
             $this->gvars['BuyUpdateLabelForm'] = $buyUpdateLabelForm->createView();
             $this->gvars['BuyUpdateDeviseForm'] = $buyUpdateDeviseForm->createView();
             $this->gvars['BuyUpdateConversionRateForm'] = $buyUpdateConversionRateForm->createView();
             $this->gvars['BuyUpdateVatForm'] = $buyUpdateVatForm->createView();
             $this->gvars['BuyUpdateVatDeviseForm'] = $buyUpdateVatDeviseForm->createView();
             $this->gvars['BuyUpdateStampForm'] = $buyUpdateStampForm->createView();
             $this->gvars['BuyUpdateStampDeviseForm'] = $buyUpdateStampDeviseForm->createView();
             $this->gvars['BuyUpdateBalanceTtcForm'] = $buyUpdateBalanceTtcForm->createView();
             $this->gvars['BuyUpdateBalanceTtcDeviseForm'] = $buyUpdateBalanceTtcDeviseForm->createView();
             $this->gvars['BuyUpdateRegimeForm'] = $buyUpdateRegimeForm->createView();
             $this->gvars['BuyUpdateWithholdingForm'] = $buyUpdateWithholdingForm->createView();
             $this->gvars['BuyUpdateBalanceNetForm'] = $buyUpdateBalanceNetForm->createView();
             $this->gvars['BuyUpdateBalanceNetDeviseForm'] = $buyUpdateBalanceNetDeviseForm->createView();
             $this->gvars['BuyUpdatePaymentTypeForm'] = $buyUpdatePaymentTypeForm->createView();
             $this->gvars['BuyUpdateTransactionStatusForm'] = $buyUpdateTransactionStatusForm->createView();
             $this->gvars['BuyUpdateAccountForm'] = $buyUpdateAccountForm->createView();
             $this->gvars['BuyUpdateNatureForm'] = $buyUpdateNatureForm->createView();
             $this->gvars['BuyUpdateOtherInfosForm'] = $buyUpdateOtherInfosForm->createView();
             $this->gvars['BuyUpdateDocsForm'] = $buyUpdateDocsForm->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.buy.edit', array('%buy%' => $buy->getNumber()));
             $this->gvars['pagetitle_txt'] = $this->translate('pagetitle.buy.edit.txt', array('%buy%' => $buy->getNumber()));
             return $this->renderResponse('AcfClientBundle:Buy:edit.html.twig', $this->gvars);
         }
     } catch (\Exception $e) {
         $logger = $this->getLogger();
         $logger->addCritical($e->getLine() . ' ' . $e->getMessage() . ' ' . $e->getTraceAsString());
     }
     return $this->redirect($urlFrom);
 }
 /**
  *
  * @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);
 }
示例#8
0
 /**
  *
  * @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 {
         $mpaye = $em->getRepository('AcfDataBundle:MPaye')->find($uid);
         if (null == $mpaye) {
             $this->flashMsgSession('warning', $this->translate('MPaye.edit.notfound'));
         } else {
             $msalaryImportForm = $this->createForm(MSalaryImportTForm::class);
             $doc = new Doc();
             $doc->setCompany($mpaye->getCompany());
             $docNewForm = $this->createForm(DocNewTForm::class, $doc, array('company' => $mpaye->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();
             if (isset($reqData['MSalaryImportForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $this->gvars['stabActive'] = 1;
                 $this->getSession()->set('stabActive', 1);
                 $msalaryImportForm->handleRequest($request);
                 if ($msalaryImportForm->isValid()) {
                     $lineDel = 0;
                     foreach ($mpaye->getSalaries() as $oldSalary) {
                         $em->remove($oldSalary);
                         $lineDel++;
                     }
                     $em->flush();
                     ini_set('memory_limit', '1024M');
                     ini_set('max_execution_time', '0');
                     $extension = $msalaryImportForm['excel']->getData()->guessExtension();
                     if ($extension == 'zip') {
                         $extension = 'xlsx';
                     }
                     $filename = uniqid() . '.' . $extension;
                     $msalaryImportForm['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);
                     $worksheet = $excelObj->getActiveSheet();
                     $highestRow = $worksheet->getHighestRow();
                     $lineRead = 0;
                     $msalaryNew = 0;
                     $lineUnprocessed = 0;
                     $lineError = 0;
                     for ($row = 2; $row <= $highestRow; $row++) {
                         $lineRead++;
                         $haserror = false;
                         $col = 0;
                         // A
                         $matricule = $worksheet->getCellByColumnAndRow($col, $row)->getValue();
                         $col++;
                         // B
                         $nom = $worksheet->getCellByColumnAndRow($col, $row)->getValue();
                         $col++;
                         // C
                         $prenom = $worksheet->getCellByColumnAndRow($col, $row)->getValue();
                         $col++;
                         // D
                         $actif = $worksheet->getCellByColumnAndRow($col, $row)->getValue();
                         $col++;
                         // E
                         $fonction = $worksheet->getCellByColumnAndRow($col, $row)->getValue();
                         $col++;
                         // F
                         $regime = $worksheet->getCellByColumnAndRow($col, $row)->getValue();
                         $col++;
                         // G
                         $dtStartContrat = $worksheet->getCellByColumnAndRow($col, $row)->getValue();
                         $col++;
                         // H
                         $dtEndContrat = $worksheet->getCellByColumnAndRow($col, $row)->getValue();
                         $col++;
                         // I
                         $departement = $worksheet->getCellByColumnAndRow($col, $row)->getValue();
                         $col++;
                         // J
                         $categorie = $worksheet->getCellByColumnAndRow($col, $row)->getValue();
                         $col++;
                         // K
                         $echelon = $worksheet->getCellByColumnAndRow($col, $row)->getValue();
                         $col++;
                         // L
                         $cin = $worksheet->getCellByColumnAndRow($col, $row)->getValue();
                         $col++;
                         // M
                         $cnss = $worksheet->getCellByColumnAndRow($col, $row)->getValue();
                         $col++;
                         // N
                         $birthday = $worksheet->getCellByColumnAndRow($col, $row)->getValue();
                         $col++;
                         // O
                         $adresse = $worksheet->getCellByColumnAndRow($col, $row)->getValue();
                         $col++;
                         // P
                         $tel = $worksheet->getCellByColumnAndRow($col, $row)->getValue();
                         $col++;
                         // Q
                         $email = $worksheet->getCellByColumnAndRow($col, $row)->getValue();
                         $col++;
                         // R
                         $banque = $worksheet->getCellByColumnAndRow($col, $row)->getValue();
                         $col++;
                         // S
                         $rib = $worksheet->getCellByColumnAndRow($col, $row)->getValue();
                         $col++;
                         // T
                         $familyChef = $worksheet->getCellByColumnAndRow($col, $row)->getValue();
                         $col++;
                         // U
                         $familySituation = $worksheet->getCellByColumnAndRow($col, $row)->getValue();
                         $col++;
                         // V
                         $handicap = $worksheet->getCellByColumnAndRow($col, $row)->getValue();
                         $col++;
                         // W
                         $childWoBourse = $worksheet->getCellByColumnAndRow($col, $row)->getValue();
                         $col++;
                         // X
                         $nbrDaysWork = $worksheet->getCellByColumnAndRow($col, $row)->getValue();
                         $col++;
                         // Y
                         $nbrDaysAbs = $worksheet->getCellByColumnAndRow($col, $row)->getValue();
                         $col++;
                         // Z
                         $nbrDaysFerry = $worksheet->getCellByColumnAndRow($col, $row)->getValue();
                         $col++;
                         // AA
                         $nbrH075Sup = $worksheet->getCellByColumnAndRow($col, $row)->getValue();
                         $col++;
                         // AB
                         $nbrH100Sup = $worksheet->getCellByColumnAndRow($col, $row)->getValue();
                         $col++;
                         // AC
                         $nbrDSup = $worksheet->getCellByColumnAndRow($col, $row)->getValue();
                         $col++;
                         // AD
                         $remboursement = $worksheet->getCellByColumnAndRow($col, $row)->getValue();
                         $col++;
                         // AE
                         $buysFromCompany = $worksheet->getCellByColumnAndRow($col, $row)->getValue();
                         $col++;
                         // AF
                         $salaryAdvance = $worksheet->getCellByColumnAndRow($col, $row)->getValue();
                         $col++;
                         // AG
                         $salaryBrut = $worksheet->getCellByColumnAndRow($col, $row)->getValue();
                         $col++;
                         // AH
                         $salaryNet = $worksheet->getCellByColumnAndRow($col, $row)->getValue();
                         $col++;
                         // AI
                         $advantageNature = $worksheet->getCellByColumnAndRow($col, $row)->getValue();
                         $col++;
                         // AJ
                         $ticketResto = $worksheet->getCellByColumnAndRow($col, $row)->getValue();
                         $col++;
                         // AK
                         $ticketCadeau = $worksheet->getCellByColumnAndRow($col, $row)->getValue();
                         $col++;
                         // AL
                         $lifeAssurance = $worksheet->getCellByColumnAndRow($col, $row)->getValue();
                         $col++;
                         // AM
                         $ceaAccount = $worksheet->getCellByColumnAndRow($col, $row)->getValue();
                         $col++;
                         // AN
                         $others = $worksheet->getCellByColumnAndRow($col, $row)->getValue();
                         if (null == $matricule || $matricule == '') {
                             $haserror = true;
                             $log .= 'ligne ' . $lineRead . ", erreur : Matricule<br>";
                         }
                         if (null == $nom || $nom == '') {
                             $haserror = true;
                             $log .= 'ligne ' . $lineRead . ", erreur : Nom<br>";
                         }
                         if (null == $prenom || $prenom == '') {
                             $haserror = true;
                             $log .= 'ligne ' . $lineRead . ", erreur : Prenom<br>";
                         }
                         if ($haserror == false) {
                             $msalaryNew++;
                             $msalary = new MSalary();
                             $msalary->setPaye($mpaye);
                             $msalary->setMatricule($matricule);
                             $msalary->setNom($nom);
                             $msalary->setPrenom($prenom);
                             $msalary->setActif($actif);
                             $msalary->setFonction($fonction);
                             $msalary->setRegime($regime);
                             $msalary->setDtStartContrat($dtStartContrat);
                             $msalary->setDtEndContrat($dtEndContrat);
                             $msalary->setDepartement($departement);
                             $msalary->setCategorie($categorie);
                             $msalary->setEchelon($echelon);
                             $msalary->setCin($cin);
                             $msalary->setCnss($cnss);
                             $msalary->setBirthday($birthday);
                             $msalary->setAdresse($adresse);
                             $msalary->setTel($tel);
                             $msalary->setEmail($email);
                             $msalary->setBanque($banque);
                             $msalary->setRib($rib);
                             $msalary->setFamilyChef($familyChef);
                             $msalary->setFamilySituation($familySituation);
                             $msalary->setHandicap($handicap);
                             $msalary->setChildWoBourse($childWoBourse);
                             $msalary->setNbrDaysWork($nbrDaysWork);
                             $msalary->setNbrDaysAbs($nbrDaysAbs);
                             $msalary->setNbrDaysFerry($nbrDaysFerry);
                             $msalary->setNbrH075Sup($nbrH075Sup);
                             $msalary->setNbrH100Sup($nbrH100Sup);
                             $msalary->setNbrDSup($nbrDSup);
                             $msalary->setRemboursement($remboursement);
                             $msalary->setBuysFromCompany($buysFromCompany);
                             $msalary->setSalaryAdvance($salaryAdvance);
                             $msalary->setSalaryBrut($salaryBrut);
                             $msalary->setSalaryNet($salaryNet);
                             $msalary->setAdvantageNature($advantageNature);
                             $msalary->setTicketResto($ticketResto);
                             $msalary->setTicketCadeau($ticketCadeau);
                             $msalary->setLifeAssurance($lifeAssurance);
                             $msalary->setCeaAccount($ceaAccount);
                             $msalary->setOthers($others);
                             $em->persist($msalary);
                             $em->persist($mpaye);
                         } else {
                             $lineError++;
                             $log .= 'la ligne ' . $lineRead . ' contient des erreurs<br>';
                         }
                     }
                     $em->flush();
                     $log .= '<br>';
                     $log .= $lineDel . ' anciennes fiches supprimées<br>';
                     $log .= $lineRead . ' lignes lues<br>';
                     $log .= $msalaryNew . ' nouvelles fiches de paye<br>';
                     $log .= $lineUnprocessed . ' Fiche déjà dans la base<br>';
                     $log .= $lineError . ' lignes contenant des erreurs<br>';
                     // */
                     $from = $this->getParameter('mail_from');
                     $fromName = $this->getParameter('mail_from_name');
                     $subject = $this->translate('_mail.newmpaye.subject', array(), 'messages');
                     $user = $this->getSecurityTokenStorage()->getToken()->getUser();
                     $company = $mpaye->getCompany();
                     $admins = $company->getAdmins();
                     if (\count($admins) != 0) {
                         $mvars = array();
                         $mvars['mpaye'] = $mpaye;
                         $mvars['user'] = $user;
                         $mvars['company'] = $company;
                         $message = \Swift_Message::newInstance();
                         $message->setFrom($from, $fromName);
                         foreach ($admins as $admin) {
                             $message->addTo($admin->getEmail(), $admin->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('AcfPayrollBundle:Mail:MPayenew.html.twig', $mvars), 'text/html');
                         $this->sendmail($message);
                     }
                     $this->flashMsgSession('log', $log);
                     $this->flashMsgSession('success', $this->translate('MSalary.import.success'));
                     $this->gvars['tabActive'] = 1;
                     $this->getSession()->set('tabActive', 1);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($mpaye);
                     $this->flashMsgSession('error', $this->translate('MSalary.import.failure'));
                 }
             } elseif (isset($reqData['DocNewForm'])) {
                 $this->gvars['tabActive'] = 3;
                 $this->getSession()->set('tabActive', 3);
                 $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($mpaye->getCompany());
                         $doc->setFileName($fileName);
                         $doc->setOriginalName($originalName);
                         $doc->setSize($size);
                         $doc->setMimeType($mimeType);
                         $doc->setMd5($md5);
                         $doc->setDescription($docNewForm['description']->getData());
                         $em->persist($doc);
                         $mpaye->addDoc($doc);
                         $docNames .= $doc->getOriginalName() . ' ';
                         $docs[] = $doc;
                     }
                     $em->persist($mpaye);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Doc.add.success', array('%doc%' => $docNames)));
                     $this->gvars['stabActive'] = 3;
                     $this->getSession()->set('stabActive', 3);
                     $from = $this->getParameter('mail_from');
                     $fromName = $this->getParameter('mail_from_name');
                     $subject = $this->translate('_mail.newdocsMP.subject', array(), 'messages');
                     $user = $this->getSecurityTokenStorage()->getToken()->getUser();
                     $company = $mpaye->getCompany();
                     $admins = $company->getAdmins();
                     if (\count($admins) != 0) {
                         $mvars = array();
                         $mvars['mpaye'] = $mpaye;
                         $mvars['user'] = $user;
                         $mvars['company'] = $company;
                         $mvars['docs'] = $docs;
                         $message = \Swift_Message::newInstance();
                         $message->setFrom($from, $fromName);
                         foreach ($admins as $admin) {
                             $message->addTo($admin->getEmail(), $admin->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('AcfPayrollBundle:Mail:MPayenewdoc.html.twig', $mvars), 'text/html');
                         $this->sendmail($message);
                     }
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($mpaye);
                     $this->flashMsgSession('error', $this->translate('Doc.add.failure'));
                 }
             }
             $this->gvars['mpaye'] = $mpaye;
             $this->gvars['doc'] = $doc;
             $this->gvars['MSalaryImportForm'] = $msalaryImportForm->createView();
             $this->gvars['DocNewForm'] = $docNewForm->createView();
             $this->gvars['pagetitle'] = $this->translate('pagetitle.mpaye.edit', array('%mpaye%' => $mpaye->getRef()));
             $this->gvars['pagetitle_txt'] = $this->translate('pagetitle.mpaye.edit.txt', array('%mpaye%' => $mpaye->getRef()));
             return $this->renderResponse('AcfPayrollBundle:MPaye:edit.html.twig', $this->gvars);
         }
     } catch (\Exception $e) {
         $logger = $this->getLogger();
         $logger->addCritical($e->getLine() . ' ' . $e->getMessage() . ' ' . $e->getTraceAsString());
     }
     return $this->redirect($urlFrom);
 }
示例#9
0
 /**
  * Add doc
  *
  * @param Doc $doc
  *
  * @return MonthlyBalance
  */
 public function addDoc(Doc $doc)
 {
     $this->docs[] = $doc;
     $doc->addMonthlyBalance($this);
     return $this;
 }
示例#10
0
 /**
  *
  * @param string $uid
  * @return unknown|\Symfony\Component\HttpFoundation\RedirectResponse
  */
 public function editPostAction($uid)
 {
     $urlFrom = $this->getReferer();
     if (null == $urlFrom || trim($urlFrom) == '') {
         $urlFrom = $this->generateUrl('_admin_company_list');
     }
     $em = $this->getEntityManager();
     try {
         $company = $em->getRepository('AcfDataBundle:Company')->find($uid);
         if (null == $company) {
             $this->flashMsgSession('warning', $this->translate('Company.edit.notfound'));
         } else {
             $sc = $this->getSecurityTokenStorage();
             $ac = $this->getSecurityAuthorizationChecker();
             $user = $sc->getToken()->getUser();
             if ($ac->isGranted('ROLE_SUPERADMIN', $user)) {
                 $traces = $em->getRepository('AcfDataBundle:Trace')->getAllByCompany($company, true);
                 $this->gvars['traces'] = array_reverse($traces);
             } else {
                 $traces = $em->getRepository('AcfDataBundle:Trace')->getAllByCompany($company, false);
                 $this->gvars['traces'] = array_reverse($traces);
             }
             $achatMarchNature = $em->getRepository('AcfDataBundle:CompanyNature')->findOneBy(array('company' => $company, 'label' => 'ACHATS DE MARCHANDISES'));
             if (null == $achatMarchNature) {
                 $achatMarchNature = new CompanyNature();
                 $achatMarchNature->setCompany($company);
                 $achatMarchNature->setLabel('ACHATS DE MARCHANDISES');
                 $em->persist($achatMarchNature);
                 $em->flush();
             }
             $em->getRepository('AcfDataBundle:Buy')->updateCompanyNatureNullByCompany($company, $achatMarchNature);
             $em->flush();
             $companyUpdateTypeForm = $this->createForm(CompanyUpdateTypeTForm::class, $company);
             $companyUpdateCorporateNameForm = $this->createForm(CompanyUpdateCorporateNameTForm::class, $company);
             $companyUpdateRefForm = $this->createForm(CompanyUpdateRefTForm::class, $company);
             $companyUpdateFiscForm = $this->createForm(CompanyUpdateFiscTForm::class, $company);
             $companyUpdateTribunalForm = $this->createForm(CompanyUpdateTribunalTForm::class, $company);
             $companyUpdatePhysicaltypeForm = $this->createForm(CompanyUpdatePhysicaltypeTForm::class, $company);
             $companyUpdateCnssForm = $this->createForm(CompanyUpdateCnssTForm::class, $company);
             $companyUpdateCnssBureauForm = $this->createForm(CompanyUpdateCnssBureauTForm::class, $company);
             $companyUpdateSectorsForm = $this->createForm(CompanyUpdateSectorsTForm::class, $company);
             $companyUpdatePhoneForm = $this->createForm(CompanyUpdatePhoneTForm::class, $company);
             $companyUpdateMobileForm = $this->createForm(CompanyUpdateMobileTForm::class, $company);
             $companyUpdateFaxForm = $this->createForm(CompanyUpdateFaxTForm::class, $company);
             $companyUpdateEmailForm = $this->createForm(CompanyUpdateEmailTForm::class, $company);
             $companyUpdateAdrForm = $this->createForm(CompanyUpdateAdrTForm::class, $company);
             $companyUpdateOtherInfosForm = $this->createForm(CompanyUpdateOtherInfosTForm::class, $company);
             $companyUpdateActionvnForm = $this->createForm(CompanyUpdateActionvnTForm::class, $company);
             $stock = new Stock();
             $stock->setCompany($company);
             $stockNewForm = $this->createForm(StockNewTForm::class, $stock, array('company' => $company));
             $address = new Address();
             $address->setCompany($company);
             $addressNewForm = $this->createForm(AddressNewTForm::class, $address, array('company' => $company));
             $phone = new Phone();
             $phone->setCompany($company);
             $phoneNewForm = $this->createForm(PhoneNewTForm::class, $phone, array('company' => $company));
             $companyFrame = new CompanyFrame();
             $companyFrame->setCompany($company);
             $companyFrameNewForm = $this->createForm(CompanyFrameNewTForm::class, $companyFrame, array('company' => $company));
             $companyNature = new CompanyNature();
             $companyNature->setCompany($company);
             $companyNatureNewForm = $this->createForm(CompanyNatureNewTForm::class, $companyNature, array('company' => $company));
             $companyNatureImportForm = $this->createForm(CompanyNatureImportTForm::class);
             $doc = new Doc();
             $doc->setCompany($company);
             $docNewForm = $this->createForm(DocNewTForm::class, $doc, array('company' => $company));
             $pilot = new Pilot();
             $pilot->setCompany($company);
             $pilotNewForm = $this->createForm(PilotNewTForm::class, $pilot, array('company' => $company));
             $companyUser = new CompanyUser();
             $companyUser->setCompany($company);
             $companyUserNewForm = $this->createForm(CompanyUserNewTForm::class, $companyUser, array('company' => $company));
             $companyAdmin = new CompanyAdmin();
             $companyAdmin->setCompany($company);
             $companyAdminNewForm = $this->createForm(CompanyAdminNewTForm::class, $companyAdmin, array('company' => $company));
             $companyLabel = new CompanyLabel();
             $companyLabel->setCompany($company);
             $companyLabelNewForm = $this->createForm(CompanyLabelNewTForm::class, $companyLabel, array('company' => $company));
             $companyLabelImportForm = $this->createForm(CompanyLabelImportTForm::class);
             $customer = new Customer();
             $customer->setCompany($company);
             $customerNewForm = $this->createForm(CustomerNewTForm::class, $customer, array('company' => $company));
             $customerImportForm = $this->createForm(CustomerImportTForm::class);
             $supplier = new Supplier();
             $supplier->setCompany($company);
             $supplierNewForm = $this->createForm(SupplierNewTForm::class, $supplier, array('company' => $company));
             $supplierImportForm = $this->createForm(SupplierImportTForm::class);
             $bank = new Bank();
             $bank->setCompany($company);
             $bankNewForm = $this->createForm(BankNewTForm::class, $bank, array('company' => $company));
             $bankImportForm = $this->createForm(BankImportTForm::class);
             $fund = new Fund();
             $fund->setCompany($company);
             $fundNewForm = $this->createForm(FundNewTForm::class, $fund, array('company' => $company));
             $fundImportForm = $this->createForm(FundImportTForm::class);
             $withholding = new Withholding();
             $withholding->setCompany($company);
             $withholdingNewForm = $this->createForm(WithholdingNewTForm::class, $withholding, array('company' => $company));
             $withholdingImportForm = $this->createForm(WithholdingImportTForm::class);
             $mbsale = new MBSale();
             $mbsale->setCompany($company);
             $mbsaleNewForm = $this->createForm(MBSaleNewTForm::class, $mbsale, array('company' => $company));
             $mbsaleNewYearForm = $this->createForm(MBSaleNewYearTForm::class, $mbsale, array('company' => $company));
             $mbpurchase = new MBPurchase();
             $mbpurchase->setCompany($company);
             $mbpurchaseNewForm = $this->createForm(MBPurchaseNewTForm::class, $mbpurchase, array('company' => $company));
             $mbpurchaseNewYearForm = $this->createForm(MBPurchaseNewYearTForm::class, $mbpurchase, array('company' => $company));
             $mpaye = new MPaye();
             $mpaye->setCompany($company);
             $mpayeNewForm = $this->createForm(MPayeNewTForm::class, $mpaye, array('company' => $company));
             $mpayeNewYearForm = $this->createForm(MPayeNewYearTForm::class, $mpaye, array('company' => $company));
             $docgroupcomptable = new Docgroupcomptable();
             $docgroupcomptable->setCompany($company);
             $docgroupcomptableNewForm = $this->createForm(DocgroupcomptableNewTForm::class, $docgroupcomptable, array('company' => $company));
             $docgroup = new Docgroup();
             $docgroup->setCompany($company);
             $docgroupNewForm = $this->createForm(DocgroupNewTForm::class, $docgroup, array('company' => $company));
             $shareholder = new Shareholder();
             $shareholder->setCompany($company);
             $shareholderNewForm = $this->createForm(ShareholderNewTForm::class, $shareholder, array('company' => $company));
             $docgroupfiscal = new Docgroupfiscal();
             $docgroupfiscal->setCompany($company);
             $docgroupfiscalNewForm = $this->createForm(DocgroupfiscalNewTForm::class, $docgroupfiscal, array('company' => $company));
             $docgroupperso = new Docgroupperso();
             $docgroupperso->setCompany($company);
             $docgrouppersoNewForm = $this->createForm(DocgrouppersoNewTForm::class, $docgroupperso, array('company' => $company));
             $docgroupsyst = new Docgroupsyst();
             $docgroupsyst->setCompany($company);
             $docgroupsystNewForm = $this->createForm(DocgroupsystNewTForm::class, $docgroupsyst, array('company' => $company));
             $docgroupaudit = new Docgroupaudit();
             $docgroupaudit->setCompany($company);
             $docgroupauditNewForm = $this->createForm(DocgroupauditNewTForm::class, $docgroupaudit, array('company' => $company));
             $docgroupbank = new Docgroupbank();
             $docgroupbank->setCompany($company);
             $docgroupbankNewForm = $this->createForm(DocgroupbankNewTForm::class, $docgroupbank, array('company' => $company));
             $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();
             $cloneCompany = clone $company;
             if (isset($reqData['CompanyUpdateTypeForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $companyUpdateTypeForm->handleRequest($request);
                 if ($companyUpdateTypeForm->isValid()) {
                     $em->persist($company);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Company.edit.success', array('%company%' => $company->getCorporateName())));
                     $this->traceEntity($cloneCompany, $company);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('Company.edit.failure', array('%company%' => $company->getCorporateName())));
                 }
             } elseif (isset($reqData['CompanyUpdateCorporateNameForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $companyUpdateCorporateNameForm->handleRequest($request);
                 if ($companyUpdateCorporateNameForm->isValid()) {
                     $em->persist($company);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Company.edit.success', array('%company%' => $company->getCorporateName())));
                     $this->traceEntity($cloneCompany, $company);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('Company.edit.failure', array('%company%' => $company->getCorporateName())));
                 }
             } elseif (isset($reqData['CompanyUpdateRefForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $companyUpdateRefForm->handleRequest($request);
                 if ($companyUpdateRefForm->isValid()) {
                     $em->persist($company);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Company.edit.success', array('%company%' => $company->getCorporateName())));
                     $this->traceEntity($cloneCompany, $company);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('Company.edit.failure', array('%company%' => $company->getCorporateName())));
                 }
             } elseif (isset($reqData['CompanyUpdateFiscForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $companyUpdateFiscForm->handleRequest($request);
                 if ($companyUpdateFiscForm->isValid()) {
                     $em->persist($company);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Company.edit.success', array('%company%' => $company->getCorporateName())));
                     $this->traceEntity($cloneCompany, $company);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('Company.edit.failure', array('%company%' => $company->getCorporateName())));
                 }
             } elseif (isset($reqData['CompanyUpdateTribunalForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $companyUpdateTribunalForm->handleRequest($request);
                 if ($companyUpdateTribunalForm->isValid()) {
                     $em->persist($company);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Company.edit.success', array('%company%' => $company->getCorporateName())));
                     $this->traceEntity($cloneCompany, $company);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('Company.edit.failure', array('%company%' => $company->getCorporateName())));
                 }
             } elseif (isset($reqData['CompanyUpdatePhysicaltypeForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $companyUpdatePhysicaltypeForm->handleRequest($request);
                 if ($companyUpdatePhysicaltypeForm->isValid()) {
                     $em->persist($company);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Company.edit.success', array('%company%' => $company->getCorporateName())));
                     $this->traceEntity($cloneCompany, $company);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('Company.edit.failure', array('%company%' => $company->getCorporateName())));
                 }
             } elseif (isset($reqData['CompanyUpdateCnssForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $companyUpdateCnssForm->handleRequest($request);
                 if ($companyUpdateCnssForm->isValid()) {
                     $em->persist($company);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Company.edit.success', array('%company%' => $company->getCorporateName())));
                     $this->traceEntity($cloneCompany, $company);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('Company.edit.failure', array('%company%' => $company->getCorporateName())));
                 }
             } elseif (isset($reqData['CompanyUpdateCnssBureauForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $companyUpdateCnssBureauForm->handleRequest($request);
                 if ($companyUpdateCnssBureauForm->isValid()) {
                     $em->persist($company);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Company.edit.success', array('%company%' => $company->getCorporateName())));
                     $this->traceEntity($cloneCompany, $company);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('Company.edit.failure', array('%company%' => $company->getCorporateName())));
                 }
             } elseif (isset($reqData['CompanyUpdateSectorsForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $companyUpdateSectorsForm->handleRequest($request);
                 if ($companyUpdateSectorsForm->isValid()) {
                     $em->persist($company);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Company.edit.success', array('%company%' => $company->getCorporateName())));
                     $this->traceEntity($cloneCompany, $company);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('Company.edit.failure', array('%company%' => $company->getCorporateName())));
                 }
             } elseif (isset($reqData['CompanyUpdatePhoneForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $companyUpdatePhoneForm->handleRequest($request);
                 if ($companyUpdatePhoneForm->isValid()) {
                     $em->persist($company);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Company.edit.success', array('%company%' => $company->getCorporateName())));
                     $this->traceEntity($cloneCompany, $company);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('Company.edit.failure', array('%company%' => $company->getCorporateName())));
                 }
             } elseif (isset($reqData['CompanyUpdateMobileForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $companyUpdateMobileForm->handleRequest($request);
                 if ($companyUpdateMobileForm->isValid()) {
                     $em->persist($company);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Company.edit.success', array('%company%' => $company->getCorporateName())));
                     $this->traceEntity($cloneCompany, $company);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('Company.edit.failure', array('%company%' => $company->getCorporateName())));
                 }
             } elseif (isset($reqData['CompanyUpdateFaxForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $companyUpdateFaxForm->handleRequest($request);
                 if ($companyUpdateFaxForm->isValid()) {
                     $em->persist($company);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Company.edit.success', array('%company%' => $company->getCorporateName())));
                     $this->traceEntity($cloneCompany, $company);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('Company.edit.failure', array('%company%' => $company->getCorporateName())));
                 }
             } elseif (isset($reqData['CompanyUpdateEmailForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $companyUpdateEmailForm->handleRequest($request);
                 if ($companyUpdateEmailForm->isValid()) {
                     $em->persist($company);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Company.edit.success', array('%company%' => $company->getCorporateName())));
                     $this->traceEntity($cloneCompany, $company);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('Company.edit.failure', array('%company%' => $company->getCorporateName())));
                 }
             } elseif (isset($reqData['CompanyUpdateAdrForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $companyUpdateAdrForm->handleRequest($request);
                 if ($companyUpdateAdrForm->isValid()) {
                     $em->persist($company);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Company.edit.success', array('%company%' => $company->getCorporateName())));
                     $this->traceEntity($cloneCompany, $company);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('Company.edit.failure', array('%company%' => $company->getCorporateName())));
                 }
             } elseif (isset($reqData['CompanyUpdateOtherInfosForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $companyUpdateOtherInfosForm->handleRequest($request);
                 if ($companyUpdateOtherInfosForm->isValid()) {
                     $em->persist($company);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Company.edit.success', array('%company%' => $company->getCorporateName())));
                     $this->traceEntity($cloneCompany, $company);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('Company.edit.failure', array('%company%' => $company->getCorporateName())));
                 }
             } elseif (isset($reqData['CompanyUpdateActionvnForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $companyUpdateActionvnForm->handleRequest($request);
                 if ($companyUpdateActionvnForm->isValid()) {
                     $em->persist($company);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Company.edit.success', array('%company%' => $company->getCorporateName())));
                     $this->traceEntity($cloneCompany, $company);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('Company.edit.failure', array('%company%' => $company->getCorporateName())));
                 }
             } elseif (isset($reqData['StockNewForm'])) {
                 $this->gvars['tabActive'] = 3;
                 $this->getSession()->set('tabActive', 3);
                 $stockNewForm->handleRequest($request);
                 if ($stockNewForm->isValid()) {
                     $em->persist($stock);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Stock.add.success', array('%stock%' => $stock->getYear())));
                     $this->gvars['stabActive'] = 2;
                     $this->getSession()->set('stabActive', 2);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('Address.add.failure'));
                 }
             } elseif (isset($reqData['AddressNewForm'])) {
                 $this->gvars['tabActive'] = 4;
                 $this->getSession()->set('tabActive', 4);
                 $addressNewForm->handleRequest($request);
                 if ($addressNewForm->isValid()) {
                     $em->persist($address);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Address.add.success', array('%address%' => $address->getLabel())));
                     $this->gvars['stabActive'] = 2;
                     $this->getSession()->set('stabActive', 2);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('Address.add.failure'));
                 }
             } elseif (isset($reqData['PhoneNewForm'])) {
                 $this->gvars['tabActive'] = 5;
                 $this->getSession()->set('tabActive', 5);
                 $phoneNewForm->handleRequest($request);
                 if ($phoneNewForm->isValid()) {
                     $em->persist($phone);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Phone.add.success', array('%phone%' => $phone->getLabel())));
                     $this->gvars['stabActive'] = 2;
                     $this->getSession()->set('stabActive', 2);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('Phone.add.failure'));
                 }
             } elseif (isset($reqData['CompanyFrameNewForm'])) {
                 $this->gvars['tabActive'] = 6;
                 $this->getSession()->set('tabActive', 6);
                 $companyFrameNewForm->handleRequest($request);
                 if ($companyFrameNewForm->isValid()) {
                     $em->persist($companyFrame);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('CompanyFrame.add.success', array('%companyFrame%' => $companyFrame->getFullName())));
                     $this->gvars['stabActive'] = 2;
                     $this->getSession()->set('stabActive', 2);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('CompanyFrame.add.failure'));
                 }
             } elseif (isset($reqData['CompanyNatureNewForm'])) {
                 $this->gvars['tabActive'] = 7;
                 $this->getSession()->set('tabActive', 7);
                 $this->gvars['stabActive'] = 1;
                 $this->getSession()->set('stabActive', 1);
                 $companyNatureNewForm->handleRequest($request);
                 if ($companyNatureNewForm->isValid()) {
                     $em->persist($companyNature);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('CompanyNature.add.success', array('%companyNature%' => $companyNature->getLabel())));
                     $this->gvars['stabActive'] = 3;
                     $this->getSession()->set('stabActive', 3);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('CompanyNature.add.failure'));
                 }
             } elseif (isset($reqData['CompanyNatureImportForm'])) {
                 $this->gvars['tabActive'] = 8;
                 $this->getSession()->set('tabActive', 8);
                 $this->gvars['stabActive'] = 2;
                 $this->getSession()->set('stabActive', 2);
                 $companyNatureImportForm->handleRequest($request);
                 if ($companyNatureImportForm->isValid()) {
                     ini_set('memory_limit', '4096M');
                     ini_set('max_execution_time', '0');
                     $extension = $companyNatureImportForm['excel']->getData()->guessExtension();
                     if ($extension == 'zip') {
                         $extension = 'xlsx';
                     }
                     $filename = uniqid() . '.' . $extension;
                     $companyNatureImportForm['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);
                     $worksheet = $excelObj->getActiveSheet();
                     $highestRow = $worksheet->getHighestRow();
                     $lineRead = 0;
                     $companyNaturesNew = 0;
                     $lineUnprocessed = 0;
                     $lineError = 0;
                     for ($row = 1; $row <= $highestRow; $row++) {
                         $lineRead++;
                         $label = \trim(\strval($worksheet->getCellByColumnAndRow(0, $row)->getValue()));
                         $color = \trim(\strval($worksheet->getCellByColumnAndRow(1, $row)->getValue()));
                         if ($label != '') {
                             $companyNature = $em->getRepository('AcfDataBundle:CompanyNature')->findOneBy(array('company' => $company, 'label' => $label));
                             if (null == $companyNature) {
                                 $companyNaturesNew++;
                                 $companyNature = new CompanyNature();
                                 $companyNature->setCompany($company);
                                 $companyNature->setLabel($label);
                                 $companyNature->setColor($color);
                                 $em->persist($companyNature);
                             } else {
                                 $lineUnprocessed++;
                                 $log .= "la Nature d'Achat " . $lineRead . ' existe déjà<br>';
                             }
                         } else {
                             $lineError++;
                             $log .= 'la ligne ' . $lineRead . ' contient des erreurs<br>';
                         }
                     }
                     $em->flush();
                     $log .= $lineRead . ' lignes lues<br>';
                     $log .= $companyNaturesNew . " nouvelles Natures d'Achat<br>";
                     $log .= $lineUnprocessed . " Natures d'Achat déjà dans la base<br>";
                     $log .= $lineError . ' lignes contenant des erreurs<br>';
                     $this->flashMsgSession('log', $log);
                     $this->flashMsgSession('success', $this->translate('CompanyNature.import.success'));
                     $this->gvars['stabActive'] = 3;
                     $this->getSession()->set('stabActive', 3);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('CompanyNature.import.failure'));
                 }
             } elseif (isset($reqData['DocNewForm'])) {
                 $this->gvars['tabActive'] = 8;
                 $this->getSession()->set('tabActive', 8);
                 $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($company);
                         $doc->setFileName($fileName);
                         $doc->setOriginalName($originalName);
                         $doc->setSize($size);
                         $doc->setMimeType($mimeType);
                         $doc->setMd5($md5);
                         $doc->setDescription($docNewForm['description']->getData());
                         $em->persist($doc);
                         $docNames .= $doc->getOriginalName() . ' ';
                         $docs[] = $doc;
                     }
                     $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');
                     $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'] = 2;
                     $this->getSession()->set('stabActive', 2);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('Doc.add.failure'));
                 }
             } elseif (isset($reqData['PilotNewForm'])) {
                 $this->gvars['tabActive'] = 9;
                 $this->getSession()->set('tabActive', 9);
                 $pilotNewForm->handleRequest($request);
                 if ($pilotNewForm->isValid()) {
                     $em->persist($pilot);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Pilot.add.success', array('%pilot%' => $pilot->getMission())));
                     $this->gvars['stabActive'] = 2;
                     $this->getSession()->set('stabActive', 2);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('Pilot.add.failure'));
                 }
             } elseif (isset($reqData['CompanyUserNewForm'])) {
                 $this->gvars['tabActive'] = 10;
                 $this->getSession()->set('tabActive', 10);
                 $companyUserNewForm->handleRequest($request);
                 if ($companyUserNewForm->isValid()) {
                     $user = $companyUser->getUser();
                     $hasClientRole = false;
                     foreach ($user->getUserRoles() as $role) {
                         if ($role->getName() == 'ROLE_CLIENT1') {
                             $hasClientRole = true;
                         }
                     }
                     if (!$hasClientRole) {
                         $roleClient = $em->getRepository('AcfDataBundle:Role')->findOneBy(array('name' => 'ROLE_CLIENT1'));
                         if (null == $roleClient) {
                             $roleClient = new Role();
                             $roleClient->setName('ROLE_CLIENT1');
                         }
                         $user->addUserRole($roleClient);
                         $em->persist($user);
                     }
                     $em->persist($companyUser);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('CompanyUser.add.success', array('%company%' => $companyUser->getCompany()->getCorporateName(), '%user%' => $companyUser->getUser()->getFullName())));
                     $this->gvars['stabActive'] = 2;
                     $this->getSession()->set('stabActive', 2);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('CompanyUser.add.failure'));
                 }
             } elseif (isset($reqData['CompanyAdminNewForm'])) {
                 $this->gvars['tabActive'] = 11;
                 $this->getSession()->set('tabActive', 11);
                 $companyAdminNewForm->handleRequest($request);
                 if ($companyAdminNewForm->isValid()) {
                     $user = $companyAdmin->getUser();
                     $hasClientRole = false;
                     foreach ($user->getUserRoles() as $role) {
                         if ($role->getName() == 'ROLE_ADMIN') {
                             $hasClientRole = true;
                         }
                     }
                     if (!$hasClientRole) {
                         $roleAdmin = $em->getRepository('AcfDataBundle:Role')->findOneBy(array('name' => 'ROLE_ADMIN'));
                         if (null == $roleAdmin) {
                             $roleAdmin = new Role();
                             $roleAdmin->setName('ROLE_ADMIN');
                         }
                         $user->addUserRole($roleAdmin);
                         $em->persist($user);
                     }
                     $em->persist($companyAdmin);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('CompanyAdmin.add.success', array('%company%' => $companyAdmin->getCompany()->getCorporateName(), '%user%' => $companyAdmin->getUser()->getFullName())));
                     $this->gvars['stabActive'] = 2;
                     $this->getSession()->set('stabActive', 2);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('CompanyAdmin.add.failure'));
                 }
             } elseif (isset($reqData['CompanyLabelNewForm'])) {
                 $this->gvars['tabActive'] = 21;
                 $this->getSession()->set('tabActive', 21);
                 $this->gvars['stabActive'] = 1;
                 $this->getSession()->set('stabActive', 1);
                 $companyLabelNewForm->handleRequest($request);
                 if ($companyLabelNewForm->isValid()) {
                     $em->persist($companyLabel);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('CompanyLabel.add.success', array('%companyLabel%' => $companyLabel->getName())));
                     $this->gvars['stabActive'] = 3;
                     $this->getSession()->set('stabActive', 3);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('CompanyLabel.add.failure'));
                 }
             } elseif (isset($reqData['CompanyLabelImportForm'])) {
                 $this->gvars['tabActive'] = 21;
                 $this->getSession()->set('tabActive', 21);
                 $this->gvars['stabActive'] = 2;
                 $this->getSession()->set('stabActive', 2);
                 $companyLabelImportForm->handleRequest($request);
                 if ($companyLabelImportForm->isValid()) {
                     ini_set('memory_limit', '4096M');
                     ini_set('max_execution_time', '0');
                     $extension = $companyLabelImportForm['excel']->getData()->guessExtension();
                     if ($extension == 'zip') {
                         $extension = 'xlsx';
                     }
                     $filename = uniqid() . '.' . $extension;
                     $companyLabelImportForm['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);
                     $worksheet = $excelObj->getActiveSheet();
                     $highestRow = $worksheet->getHighestRow();
                     $lineRead = 1;
                     $companyLabelsNew = 0;
                     $lineUnprocessed = 0;
                     $lineError = 0;
                     for ($row = 2; $row <= $highestRow; $row++) {
                         $lineRead++;
                         $name = \trim(\strval($worksheet->getCellByColumnAndRow(0, $row)->getValue()));
                         $abrev = \trim(\strval($worksheet->getCellByColumnAndRow(1, $row)->getValue()));
                         if ($abrev != '' && $name != '') {
                             $companyLabel = $em->getRepository('AcfDataBundle:CompanyLabel')->findOneBy(array('company' => $company, 'abrev' => $abrev));
                             if (null == $companyLabel) {
                                 $companyLabelsNew++;
                                 $companyLabel = new CompanyLabel();
                                 $companyLabel->setCompany($company);
                                 $companyLabel->setAbrev($abrev);
                                 $companyLabel->setName($name);
                                 $em->persist($companyLabel);
                             } else {
                                 $lineUnprocessed++;
                                 $log .= 'le Code Journal à la ligne ' . $lineRead . ' existe déjà<br>';
                             }
                         } else {
                             $lineError++;
                             $log .= 'la ligne ' . $lineRead . ' contient des erreurs<br>';
                         }
                     }
                     $em->flush();
                     $log .= $lineRead . ' lignes lues<br>';
                     $log .= $companyLabelsNew . ' nouveaux Journaux<br>';
                     $log .= $lineUnprocessed . ' Journaux déjà dans la base<br>';
                     $log .= $lineError . ' lignes contenant des erreurs<br>';
                     $this->flashMsgSession('log', $log);
                     $this->flashMsgSession('success', $this->translate('CompanyLabel.import.success'));
                     $this->gvars['stabActive'] = 3;
                     $this->getSession()->set('stabActive', 3);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('CompanyLabel.import.failure'));
                 }
             } elseif (isset($reqData['CustomerNewForm'])) {
                 $this->gvars['tabActive'] = 22;
                 $this->getSession()->set('tabActive', 22);
                 $this->gvars['stabActive'] = 1;
                 $this->getSession()->set('stabActive', 1);
                 $customerNewForm->handleRequest($request);
                 if ($customerNewForm->isValid()) {
                     $em->persist($customer);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Customer.add.success', array('%customer%' => $customer->getLabel())));
                     $this->gvars['stabActive'] = 3;
                     $this->getSession()->set('stabActive', 3);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('Customer.add.failure'));
                 }
             } elseif (isset($reqData['CustomerImportForm'])) {
                 $this->gvars['tabActive'] = 22;
                 $this->getSession()->set('tabActive', 22);
                 $this->gvars['stabActive'] = 2;
                 $this->getSession()->set('stabActive', 2);
                 $customerImportForm->handleRequest($request);
                 if ($customerImportForm->isValid()) {
                     ini_set('memory_limit', '4096M');
                     ini_set('max_execution_time', '0');
                     $extension = $customerImportForm['excel']->getData()->guessExtension();
                     if ($extension == 'zip') {
                         $extension = 'xlsx';
                     }
                     $filename = uniqid() . '.' . $extension;
                     $customerImportForm['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 la 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 = 1;
                     $customersNew = 0;
                     $lineUnprocessed = 0;
                     $lineError = 0;
                     for ($row = 2; $row <= $highestRow; $row++) {
                         $lineRead++;
                         $xlsLabel = \trim(\strval($worksheet->getCellByColumnAndRow(0, $row)->getValue()));
                         $xlsNumber = \trim(\strval($worksheet->getCellByColumnAndRow(1, $row)->getValue()));
                         $xlsMatricule = \trim(\strval($worksheet->getCellByColumnAndRow(2, $row)->getValue()));
                         $xlsAddress = \trim(\strval($worksheet->getCellByColumnAndRow(4, $row)->getValue()));
                         $xlsRc = \trim(\strval($worksheet->getCellByColumnAndRow(5, $row)->getValue()));
                         if ($xlsNumber != '' && \is_numeric($xlsNumber)) {
                             $xlsNumber = \intval($xlsNumber) - $customersPrefixNum;
                         }
                         if ($xlsNumber != '' && $xlsNumber > 0 && $xlsLabel != '') {
                             $customer1 = $em->getRepository('AcfDataBundle:Customer')->findOneBy(array('company' => $company, 'number' => $xlsNumber));
                             $customer2 = $em->getRepository('AcfDataBundle:Customer')->findOneBy(array('company' => $company, 'label' => $xlsLabel));
                             if (null == $customer1 && null == $customer2) {
                                 $customersNew++;
                                 $customer = new Customer();
                                 $customer->setCompany($company);
                                 $customer->setLabel($xlsLabel);
                                 $customer->setNumber($xlsNumber);
                                 $customer->setFisc($xlsMatricule);
                                 $customer->setCin($xlsMatricule);
                                 $customer->setAddress($xlsAddress);
                                 $customer->setCommercialRegister($xlsRc);
                                 $em->persist($customer);
                             } else {
                                 $lineUnprocessed++;
                                 $log .= 'le Client à la ligne ' . $lineRead . ' existe déjà<br>';
                             }
                         } else {
                             $lineError++;
                             $log .= 'la ligne ' . $lineRead . ' contient des erreurs (COL A : ' . $xlsLabel . ', COL B: ' . $xlsNumber . ')<br>';
                         }
                     }
                     $em->flush();
                     $log .= $lineRead . ' lignes lues<br>';
                     $log .= $customersNew . ' nouveaux Clients<br>';
                     $log .= $lineUnprocessed . ' Clients déjà dans la base<br>';
                     $log .= $lineError . ' lignes contenant des erreurs<br>';
                     $this->flashMsgSession('log', $log);
                     $this->flashMsgSession('success', $this->translate('Customer.import.success'));
                     $this->gvars['stabActive'] = 3;
                     $this->getSession()->set('stabActive', 3);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('Customer.import.failure'));
                 }
             } elseif (isset($reqData['SupplierNewForm'])) {
                 $this->gvars['tabActive'] = 23;
                 $this->getSession()->set('tabActive', 23);
                 $this->gvars['stabActive'] = 1;
                 $this->getSession()->set('stabActive', 1);
                 $supplierNewForm->handleRequest($request);
                 if ($supplierNewForm->isValid()) {
                     $em->persist($supplier);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Supplier.add.success', array('%supplier%' => $supplier->getLabel())));
                     $this->gvars['stabActive'] = 3;
                     $this->getSession()->set('stabActive', 3);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('Supplier.add.failure'));
                 }
             } elseif (isset($reqData['SupplierImportForm'])) {
                 $this->gvars['tabActive'] = 23;
                 $this->getSession()->set('tabActive', 23);
                 $this->gvars['stabActive'] = 2;
                 $this->getSession()->set('stabActive', 2);
                 $supplierImportForm->handleRequest($request);
                 if ($supplierImportForm->isValid()) {
                     ini_set('memory_limit', '4096M');
                     ini_set('max_execution_time', '0');
                     $extension = $supplierImportForm['excel']->getData()->guessExtension();
                     if ($extension == 'zip') {
                         $extension = 'xlsx';
                     }
                     $filename = uniqid() . '.' . $extension;
                     $supplierImportForm['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 = 1;
                     $suppliersNew = 0;
                     $lineUnprocessed = 0;
                     $lineError = 0;
                     for ($row = 2; $row <= $highestRow; $row++) {
                         $lineRead++;
                         $xlsLabel = \trim(\strval($worksheet->getCellByColumnAndRow(0, $row)->getValue()));
                         $xlsNumber = \trim(\strval($worksheet->getCellByColumnAndRow(1, $row)->getValue()));
                         $xlsMatricule = \trim(\strval($worksheet->getCellByColumnAndRow(2, $row)->getValue()));
                         $xlsAddress = \trim(\strval($worksheet->getCellByColumnAndRow(3, $row)->getValue()));
                         $xlsRc = \trim(\strval($worksheet->getCellByColumnAndRow(4, $row)->getValue()));
                         if ($xlsNumber != '' && \is_numeric($xlsNumber)) {
                             $xlsNumber = \intval($xlsNumber) - $suppliersPrefixNum;
                         }
                         if ($xlsNumber != '' && $xlsNumber > 0 && $xlsLabel != '') {
                             $supplier1 = $em->getRepository('AcfDataBundle:Supplier')->findOneBy(array('company' => $company, 'number' => $xlsNumber));
                             $supplier2 = $em->getRepository('AcfDataBundle:Supplier')->findOneBy(array('company' => $company, 'label' => $xlsLabel));
                             if (null == $supplier1 && null == $supplier2) {
                                 $suppliersNew++;
                                 $supplier = new Supplier();
                                 $supplier->setCompany($company);
                                 $supplier->setLabel($xlsLabel);
                                 $supplier->setNumber($xlsNumber);
                                 $supplier->setFisc($xlsMatricule);
                                 $supplier->setCin($xlsMatricule);
                                 $supplier->setAddress($xlsAddress);
                                 $supplier->setCommercialRegister($xlsRc);
                                 $em->persist($supplier);
                             } else {
                                 $lineUnprocessed++;
                                 $log .= 'le Fournisseur à la ligne ' . $lineRead . ' existe déjà<br>';
                             }
                         } else {
                             $lineError++;
                             $log .= 'la ligne ' . $lineRead . ' contient des erreurs (COL A : ' . $xlsLabel . ', COL B: ' . $xlsNumber . ')<br>';
                         }
                     }
                     $em->flush();
                     $log .= $lineRead . ' lignes lues<br>';
                     $log .= $suppliersNew . ' nouveaux Fournisseurs<br>';
                     $log .= $lineUnprocessed . ' Fournisseurs déjà dans la base<br>';
                     $log .= $lineError . ' lignes contenant des erreurs<br>';
                     $this->flashMsgSession('log', $log);
                     $this->flashMsgSession('success', $this->translate('Supplier.import.success'));
                     $this->gvars['stabActive'] = 3;
                     $this->getSession()->set('stabActive', 3);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('Supplier.import.failure'));
                 }
             } elseif (isset($reqData['BankNewForm'])) {
                 $this->gvars['tabActive'] = 24;
                 $this->getSession()->set('tabActive', 24);
                 $this->gvars['stabActive'] = 1;
                 $this->getSession()->set('stabActive', 1);
                 $bankNewForm->handleRequest($request);
                 if ($bankNewForm->isValid()) {
                     $em->persist($bank);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Bank.add.success', array('%bank%' => $bank->getLabel())));
                     $this->gvars['stabActive'] = 3;
                     $this->getSession()->set('stabActive', 3);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('Bank.add.failure'));
                 }
             } elseif (isset($reqData['BankImportForm'])) {
                 $this->gvars['tabActive'] = 24;
                 $this->getSession()->set('tabActive', 24);
                 $this->gvars['stabActive'] = 2;
                 $this->getSession()->set('stabActive', 2);
                 $bankImportForm->handleRequest($request);
                 if ($bankImportForm->isValid()) {
                     ini_set('memory_limit', '4096M');
                     ini_set('max_execution_time', '0');
                     $extension = $bankImportForm['excel']->getData()->guessExtension();
                     if ($extension == 'zip') {
                         $extension = 'xlsx';
                     }
                     $filename = uniqid() . '.' . $extension;
                     $bankImportForm['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);
                     $banksConstStr = $em->getRepository('AcfDataBundle:ConstantStr')->findOneBy(array('name' => 'banksPrefix'));
                     if (null == $banksConstStr) {
                         $banksConstStr = new ConstantStr();
                         $banksConstStr->setName('banksPrefix');
                         $banksConstStr->setValue('532');
                         $em->persist($banksConstStr);
                         $em->flush();
                     }
                     $banksPrefix = $banksConstStr->getValue();
                     $banksPrefixNum = \intval($banksPrefix) * 1000000000;
                     $worksheet = $excelObj->getActiveSheet();
                     $highestRow = $worksheet->getHighestRow();
                     $lineRead = 1;
                     $banksNew = 0;
                     $lineUnprocessed = 0;
                     $lineError = 0;
                     for ($row = 2; $row <= $highestRow; $row++) {
                         $lineRead++;
                         $label = \trim(\strval($worksheet->getCellByColumnAndRow(0, $row)->getValue()));
                         $number = \trim(\strval($worksheet->getCellByColumnAndRow(1, $row)->getValue()));
                         $agence = \trim(\strval($worksheet->getCellByColumnAndRow(2, $row)->getValue()));
                         $rib = \trim(\strval($worksheet->getCellByColumnAndRow(3, $row)->getValue()));
                         $contact = \trim(\strval($worksheet->getCellByColumnAndRow(4, $row)->getValue()));
                         $tel = \trim(\strval($worksheet->getCellByColumnAndRow(5, $row)->getValue()));
                         $fax = \trim(\strval($worksheet->getCellByColumnAndRow(6, $row)->getValue()));
                         $email = \trim(\strval($worksheet->getCellByColumnAndRow(7, $row)->getValue()));
                         if ($number != '' && \is_numeric($number)) {
                             $number = \intval($number) - $banksPrefixNum;
                         }
                         if ($number != '' && $number > 0 && $label != '') {
                             $bank = $em->getRepository('AcfDataBundle:Bank')->findOneBy(array('company' => $company, 'number' => $number));
                             $bank1 = $em->getRepository('AcfDataBundle:Bank')->findOneBy(array('company' => $company, 'label' => $label));
                             if (null == $bank && null == $bank1) {
                                 $banksNew++;
                                 $bank = new Bank();
                                 $bank->setCompany($company);
                                 $bank->setLabel($label);
                                 $bank->setNumber($number);
                                 $bank->setAgency($agence);
                                 $bank->setRib($rib);
                                 $bank->setContact($contact);
                                 $bank->setTel($tel);
                                 $bank->setFax($fax);
                                 $bank->setEmail($email);
                                 $em->persist($bank);
                             } else {
                                 $lineUnprocessed++;
                                 $log .= 'la Banque à la ligne ' . $lineRead . ' existe déjà<br>';
                             }
                         } else {
                             $lineError++;
                             $log .= 'la ligne ' . $lineRead . ' contient des erreurs<br>';
                         }
                     }
                     $em->flush();
                     $log .= $lineRead . ' lignes lues<br>';
                     $log .= $banksNew . ' nouveaux Banques<br>';
                     $log .= $lineUnprocessed . ' Banques déjà dans la base<br>';
                     $log .= $lineError . ' lignes contenant des erreurs<br>';
                     $this->flashMsgSession('log', $log);
                     $this->flashMsgSession('success', $this->translate('Bank.import.success'));
                     $this->gvars['stabActive'] = 3;
                     $this->getSession()->set('stabActive', 3);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('Bank.import.failure'));
                 }
             } elseif (isset($reqData['FundNewForm'])) {
                 $this->gvars['tabActive'] = 25;
                 $this->getSession()->set('tabActive', 25);
                 $this->gvars['stabActive'] = 1;
                 $this->getSession()->set('stabActive', 1);
                 $fundNewForm->handleRequest($request);
                 if ($fundNewForm->isValid()) {
                     $em->persist($fund);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Fund.add.success', array('%fund%' => $fund->getLabel())));
                     $this->gvars['stabActive'] = 3;
                     $this->getSession()->set('stabActive', 3);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('Fund.add.failure'));
                 }
             } elseif (isset($reqData['FundImportForm'])) {
                 $this->gvars['tabActive'] = 25;
                 $this->getSession()->set('tabActive', 25);
                 $this->gvars['stabActive'] = 2;
                 $this->getSession()->set('stabActive', 2);
                 $fundImportForm->handleRequest($request);
                 if ($fundImportForm->isValid()) {
                     ini_set('memory_limit', '4096M');
                     ini_set('max_execution_time', '0');
                     $extension = $fundImportForm['excel']->getData()->guessExtension();
                     if ($extension == 'zip') {
                         $extension = 'xlsx';
                     }
                     $filename = uniqid() . '.' . $extension;
                     $fundImportForm['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);
                     $fundsConstStr = $em->getRepository('AcfDataBundle:ConstantStr')->findOneBy(array('name' => 'fundsPrefix'));
                     if (null == $fundsConstStr) {
                         $fundsConstStr = new ConstantStr();
                         $fundsConstStr->setName('fundsPrefix');
                         $fundsConstStr->setValue('540');
                         $em->persist($fundsConstStr);
                         $em->flush();
                     }
                     $fundsPrefix = $fundsConstStr->getValue();
                     $fundsPrefixNum = \intval($fundsPrefix) * 1000000000;
                     $worksheet = $excelObj->getActiveSheet();
                     $highestRow = $worksheet->getHighestRow();
                     $lineRead = 1;
                     $fundsNew = 0;
                     $lineUnprocessed = 0;
                     $lineError = 0;
                     for ($row = 2; $row <= $highestRow; $row++) {
                         $lineRead++;
                         $label = \trim(\strval($worksheet->getCellByColumnAndRow(0, $row)->getValue()));
                         $number = \trim(\strval($worksheet->getCellByColumnAndRow(1, $row)->getValue()));
                         if ($number != '' && \is_numeric($number)) {
                             $number = \intval($number) - $fundsPrefixNum;
                         }
                         if ($number != '' && $number > 0 && $label != '') {
                             $fund = $em->getRepository('AcfDataBundle:Fund')->findOneBy(array('company' => $company, 'number' => $number));
                             $fund1 = $em->getRepository('AcfDataBundle:Fund')->findOneBy(array('company' => $company, 'label' => $label));
                             if (null == $fund && null == $fund1) {
                                 $fundsNew++;
                                 $fund = new Fund();
                                 $fund->setCompany($company);
                                 $fund->setLabel($label);
                                 $fund->setNumber($number);
                                 $em->persist($fund);
                             } else {
                                 $lineUnprocessed++;
                                 $log .= 'la Caisse à la ligne ' . $lineRead . ' existe déjà<br>';
                             }
                         } else {
                             $lineError++;
                             $log .= 'la ligne ' . $lineRead . ' contient des erreurs<br>';
                         }
                     }
                     $em->flush();
                     $log .= $lineRead . ' lignes lues<br>';
                     $log .= $fundsNew . ' nouvelles Caisses<br>';
                     $log .= $lineUnprocessed . ' Caisses déjà dans la base<br>';
                     $log .= $lineError . ' lignes contenant des erreurs<br>';
                     $this->flashMsgSession('log', $log);
                     $this->flashMsgSession('success', $this->translate('Fund.import.success'));
                     $this->gvars['stabActive'] = 3;
                     $this->getSession()->set('stabActive', 3);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('Fund.import.failure'));
                 }
             } elseif (isset($reqData['WithholdingNewForm'])) {
                 $this->gvars['tabActive'] = 26;
                 $this->getSession()->set('tabActive', 26);
                 $this->gvars['stabActive'] = 1;
                 $this->getSession()->set('stabActive', 1);
                 $withholdingNewForm->handleRequest($request);
                 if ($withholdingNewForm->isValid()) {
                     $em->persist($withholding);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Withholding.add.success', array('%withholding%' => $withholding->getLabel())));
                     $this->gvars['stabActive'] = 3;
                     $this->getSession()->set('stabActive', 3);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('Withholding.add.failure'));
                 }
             } elseif (isset($reqData['WithholdingImportForm'])) {
                 $this->gvars['tabActive'] = 26;
                 $this->getSession()->set('tabActive', 26);
                 $this->gvars['stabActive'] = 2;
                 $this->getSession()->set('stabActive', 2);
                 $withholdingImportForm->handleRequest($request);
                 if ($withholdingImportForm->isValid()) {
                     ini_set('memory_limit', '4096M');
                     ini_set('max_execution_time', '0');
                     $extension = $withholdingImportForm['excel']->getData()->guessExtension();
                     if ($extension == 'zip') {
                         $extension = 'xlsx';
                     }
                     $filename = uniqid() . '.' . $extension;
                     $withholdingImportForm['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);
                     $withholdingsConstStr = $em->getRepository('AcfDataBundle:ConstantStr')->findOneBy(array('name' => 'withholdingsPrefix'));
                     if (null == $withholdingsConstStr) {
                         $withholdingsConstStr = new ConstantStr();
                         $withholdingsConstStr->setName('withholdingsPrefix');
                         $withholdingsConstStr->setValue('432');
                         $em->persist($withholdingsConstStr);
                         $em->flush();
                     }
                     $withholdingsPrefix = $withholdingsConstStr->getValue();
                     $withholdingsPrefixNum = \intval($withholdingsPrefix) * 1000000000;
                     $worksheet = $excelObj->getActiveSheet();
                     $highestRow = $worksheet->getHighestRow();
                     $lineRead = 1;
                     $withholdingsNew = 0;
                     $lineUnprocessed = 0;
                     $lineError = 0;
                     for ($row = 2; $row <= $highestRow; $row++) {
                         $lineRead++;
                         $label = \trim(\strval($worksheet->getCellByColumnAndRow(0, $row)->getValue()));
                         $number = \trim(\strval($worksheet->getCellByColumnAndRow(1, $row)->getValue()));
                         $xlsValue = \trim(\strval($worksheet->getCellByColumnAndRow(2, $row)->getValue()));
                         if ($number != '' && \is_numeric($number)) {
                             $number = \intval($number) - $withholdingsPrefixNum;
                         }
                         if ($number != '' && $number > 0 && $label != '') {
                             $withholding1 = $em->getRepository('AcfDataBundle:Withholding')->findOneBy(array('company' => $company, 'number' => $number));
                             $withholding2 = $em->getRepository('AcfDataBundle:Withholding')->findOneBy(array('company' => $company, 'label' => $label));
                             if (null == $withholding1 && null == $withholding2) {
                                 $withholdingsNew++;
                                 $withholding = new Withholding();
                                 $withholding->setCompany($company);
                                 $withholding->setNumber($number);
                                 $withholding->setLabel($label);
                                 if ($this->endswith($xlsValue, '%')) {
                                     $value = \intval(\substr($xlsValue, 0, -1));
                                 } else {
                                     $value = \intval($xlsValue);
                                 }
                                 $withholding->setValue($value);
                                 $em->persist($withholding);
                             } else {
                                 $lineUnprocessed++;
                                 $log .= 'la Retenue à la ligne ' . $lineRead . ' existe déjà<br>';
                             }
                         } else {
                             $lineError++;
                             $log .= 'la ligne ' . $lineRead . ' contient des erreurs<br>';
                         }
                     }
                     $em->flush();
                     $log .= $lineRead . ' lignes lues<br>';
                     $log .= $withholdingsNew . ' nouvelles Retenues<br>';
                     $log .= $lineUnprocessed . ' Retenues déjà dans la base<br>';
                     $log .= $lineError . ' lignes contenant des erreurs<br>';
                     $this->flashMsgSession('log', $log);
                     $this->flashMsgSession('success', $this->translate('Withholding.import.success'));
                     $this->gvars['stabActive'] = 3;
                     $this->getSession()->set('stabActive', 3);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('Withholding.import.failure'));
                 }
             } elseif (isset($reqData['MBSaleNewForm'])) {
                 $this->gvars['tabActive'] = 27;
                 $this->getSession()->set('tabActive', 27);
                 $mbsaleNewForm->handleRequest($request);
                 if ($mbsaleNewForm->isValid()) {
                     $mbsale->generateRef();
                     $em->persist($mbsale);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('MBSale.add.success', array('%mbsale%' => $mbsale->getRef())));
                     $this->gvars['stabActive'] = 3;
                     $this->getSession()->set('stabActive', 3);
                     return $this->redirect($urlFrom);
                 } else {
                     $this->gvars['stabActive'] = 1;
                     $this->getSession()->set('stabActive', 1);
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('MBSale.add.failure'));
                 }
             } elseif (isset($reqData['MBSaleNewYearForm'])) {
                 $this->gvars['tabActive'] = 27;
                 $this->getSession()->set('tabActive', 27);
                 $mbsaleNewYearForm->handleRequest($request);
                 if ($mbsaleNewYearForm->isValid()) {
                     $year = $mbsaleNewYearForm['year']->getData();
                     foreach (MBSale::choiceMonthCallback() as $month) {
                         $mbsale = $em->getRepository('AcfDataBundle:MBSale')->findOneBy(array('company' => $company, 'year' => $year, 'month' => $month));
                         if (null == $mbsale) {
                             $mbsale = new MBSale();
                             $mbsale->setCompany($company);
                             $mbsale->setYear($year);
                             $mbsale->setMonth($month);
                             $mbsale->generateRef();
                             $em->persist($mbsale);
                             $this->flashMsgSession('success', $this->translate('MBSale.add.success', array('%mbsale%' => $mbsale->getRef())));
                         }
                     }
                     $em->flush();
                     $this->gvars['stabActive'] = 3;
                     $this->getSession()->set('stabActive', 3);
                     return $this->redirect($urlFrom);
                 } else {
                     $this->gvars['stabActive'] = 2;
                     $this->getSession()->set('stabActive', 2);
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('MBSale.add.failure'));
                 }
             } elseif (isset($reqData['MBPurchaseNewForm'])) {
                 $this->gvars['tabActive'] = 28;
                 $this->getSession()->set('tabActive', 28);
                 $mbpurchaseNewForm->handleRequest($request);
                 if ($mbpurchaseNewForm->isValid()) {
                     $mbpurchase->generateRef();
                     $em->persist($mbpurchase);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('MBPurchase.add.success', array('%mbpurchase%' => $mbpurchase->getRef())));
                     $this->gvars['stabActive'] = 3;
                     $this->getSession()->set('stabActive', 3);
                     return $this->redirect($urlFrom);
                 } else {
                     $this->gvars['stabActive'] = 2;
                     $this->getSession()->set('stabActive', 2);
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('MBPurchase.add.failure'));
                 }
             } elseif (isset($reqData['MBPurchaseNewYearForm'])) {
                 $this->gvars['tabActive'] = 28;
                 $this->getSession()->set('tabActive', 28);
                 $mbpurchaseNewYearForm->handleRequest($request);
                 if ($mbpurchaseNewYearForm->isValid()) {
                     $year = $mbpurchaseNewYearForm['year']->getData();
                     foreach (MBPurchase::choiceMonthCallback() as $month) {
                         $mbpurchase = $em->getRepository('AcfDataBundle:MBPurchase')->findOneBy(array('company' => $company, 'year' => $year, 'month' => $month));
                         if (null == $mbpurchase) {
                             $mbpurchase = new MBPurchase();
                             $mbpurchase->setCompany($company);
                             $mbpurchase->setYear($year);
                             $mbpurchase->setMonth($month);
                             $mbpurchase->generateRef();
                             $em->persist($mbpurchase);
                             $this->flashMsgSession('success', $this->translate('MBPurchase.add.success', array('%mbpurchase%' => $mbpurchase->getRef())));
                         }
                     }
                     $em->flush();
                     $this->gvars['stabActive'] = 3;
                     $this->getSession()->set('stabActive', 3);
                     return $this->redirect($urlFrom);
                 } else {
                     $this->gvars['stabActive'] = 2;
                     $this->getSession()->set('stabActive', 2);
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('MBPurchase.add.failure'));
                 }
             } elseif (isset($reqData['DocgroupcomptableNewForm'])) {
                 $this->gvars['tabActive'] = 29;
                 $this->getSession()->set('tabActive', 29);
                 $docgroupcomptableNewForm->handleRequest($request);
                 if ($docgroupcomptableNewForm->isValid()) {
                     $dgtoclone = null;
                     $oldDocgroupcomptables = null;
                     if (null != $docgroupcomptableNewForm['clone']->getData()) {
                         $dgtoclone = $docgroupcomptableNewForm['clone']->getData();
                         $oldDocgroupcomptables = $em->getRepository('AcfDataBundle:Docgroupcomptable')->getAllChilds($dgtoclone);
                     }
                     $em->persist($docgroupcomptable);
                     $em->flush();
                     if (null != $dgtoclone && null != $oldDocgroupcomptables && \count($oldDocgroupcomptables) != 0) {
                         $docgroupcomptablesCloneArray = array();
                         foreach ($oldDocgroupcomptables as $oldDocgroupcomptable) {
                             $ndocgroupcomptable = new Docgroupcomptable();
                             $ndocgroupcomptable->setCompany($company);
                             $ndocgroupcomptable->setLabel($oldDocgroupcomptable->getLabel());
                             $ndocgroupcomptable->setOtherInfos($oldDocgroupcomptable->getOtherInfos());
                             if (null != $oldDocgroupcomptable->getParent() && $oldDocgroupcomptable->getParent()->getId() != $dgtoclone->getId()) {
                                 $parentId = $oldDocgroupcomptable->getParent()->getId();
                                 $ndocgroupcomptable->setParent($docgroupcomptablesCloneArray[$parentId]);
                             } else {
                                 $ndocgroupcomptable->setParent($docgroupcomptable);
                             }
                             $docgroupcomptablesCloneArray[$oldDocgroupcomptable->getId()] = $ndocgroupcomptable;
                             $em->persist($ndocgroupcomptable);
                         }
                     }
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Docgroupcomptable.add.success', array('%docgroupcomptable%' => $docgroupcomptable->getLabel())));
                     $this->gvars['stabActive'] = 2;
                     $this->getSession()->set('stabActive', 2);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('Docgroupcomptable.add.failure'));
                 }
             } elseif (isset($reqData['DocgroupbankNewForm'])) {
                 $this->gvars['tabActive'] = 30;
                 $this->getSession()->set('tabActive', 30);
                 $docgroupbankNewForm->handleRequest($request);
                 if ($docgroupbankNewForm->isValid()) {
                     $dgtoclone = null;
                     $oldDocgroupbanks = null;
                     if (null != $docgroupbankNewForm['clone']->getData()) {
                         $dgtoclone = $docgroupbankNewForm['clone']->getData();
                         $oldDocgroupbanks = $em->getRepository('AcfDataBundle:Docgroupbank')->getAllChilds($dgtoclone);
                     }
                     $em->persist($docgroupbank);
                     $em->flush();
                     if (null != $dgtoclone && null != $oldDocgroupbanks && \count($oldDocgroupbanks) != 0) {
                         $docgroupbanksCloneArray = array();
                         foreach ($oldDocgroupbanks as $oldDocgroupbank) {
                             $ndocgroupbank = new Docgroupbank();
                             $ndocgroupbank->setCompany($company);
                             $ndocgroupbank->setLabel($oldDocgroupbank->getLabel());
                             $ndocgroupbank->setOtherInfos($oldDocgroupbank->getOtherInfos());
                             if (null != $oldDocgroupbank->getParent() && $oldDocgroupbank->getParent()->getId() != $dgtoclone->getId()) {
                                 $parentId = $oldDocgroupbank->getParent()->getId();
                                 $ndocgroupbank->setParent($docgroupbanksCloneArray[$parentId]);
                             } else {
                                 $ndocgroupbank->setParent($docgroupbank);
                             }
                             $docgroupbanksCloneArray[$oldDocgroupbank->getId()] = $ndocgroupbank;
                             $em->persist($ndocgroupbank);
                         }
                     }
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Docgroupbank.add.success', array('%docgroupbank%' => $docgroupbank->getLabel())));
                     $this->gvars['stabActive'] = 2;
                     $this->getSession()->set('stabActive', 2);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('Docgroupbank.add.failure'));
                 }
             } elseif (isset($reqData['DocgroupNewForm'])) {
                 $this->gvars['tabActive'] = 41;
                 $this->getSession()->set('tabActive', 41);
                 $docgroupNewForm->handleRequest($request);
                 if ($docgroupNewForm->isValid()) {
                     $dgtoclone = null;
                     $oldDocgroups = null;
                     if (null != $docgroupNewForm['clone']->getData()) {
                         $dgtoclone = $docgroupNewForm['clone']->getData();
                         $oldDocgroups = $em->getRepository('AcfDataBundle:Docgroup')->getAllChilds($dgtoclone);
                     }
                     $em->persist($docgroup);
                     $em->flush();
                     if (null != $dgtoclone && null != $oldDocgroups && \count($oldDocgroups) != 0) {
                         $docgroupsCloneArray = array();
                         foreach ($oldDocgroups as $oldDocgroup) {
                             $ndocgroup = new Docgroup();
                             $ndocgroup->setCompany($company);
                             $ndocgroup->setLabel($oldDocgroup->getLabel());
                             $ndocgroup->setOtherInfos($oldDocgroup->getOtherInfos());
                             if (null != $oldDocgroup->getParent() && $oldDocgroup->getParent()->getId() != $dgtoclone->getId()) {
                                 $parentId = $oldDocgroup->getParent()->getId();
                                 $ndocgroup->setParent($docgroupsCloneArray[$parentId]);
                             } else {
                                 $ndocgroup->setParent($docgroup);
                             }
                             $docgroupsCloneArray[$oldDocgroup->getId()] = $ndocgroup;
                             $em->persist($ndocgroup);
                         }
                     }
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Docgroup.add.success', array('%docgroup%' => $docgroup->getLabel())));
                     $this->gvars['stabActive'] = 2;
                     $this->getSession()->set('stabActive', 2);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('Docgroup.add.failure'));
                 }
             } elseif (isset($reqData['ShareholderNewForm'])) {
                 $this->gvars['tabActive'] = 42;
                 $this->getSession()->set('tabActive', 42);
                 $shareholderNewForm->handleRequest($request);
                 if ($shareholderNewForm->isValid()) {
                     $em->persist($shareholder);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Shareholder.add.success', array('%shareholder%' => $shareholder->getName())));
                     $this->gvars['stabActive'] = 2;
                     $this->getSession()->set('stabActive', 2);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('Shareholder.add.failure'));
                 }
             } elseif (isset($reqData['DocgroupfiscalNewForm'])) {
                 $this->gvars['tabActive'] = 51;
                 $this->getSession()->set('tabActive', 51);
                 $docgroupfiscalNewForm->handleRequest($request);
                 if ($docgroupfiscalNewForm->isValid()) {
                     $dgtoclone = null;
                     $oldDocgroupfiscals = null;
                     if (null != $docgroupfiscalNewForm['clone']->getData()) {
                         $dgtoclone = $docgroupfiscalNewForm['clone']->getData();
                         $oldDocgroupfiscals = $em->getRepository('AcfDataBundle:Docgroupfiscal')->getAllChilds($dgtoclone);
                     }
                     $em->persist($docgroupfiscal);
                     $em->flush();
                     if (null != $dgtoclone && null != $oldDocgroupfiscals && \count($oldDocgroupfiscals) != 0) {
                         $docgroupfiscalsCloneArray = array();
                         foreach ($oldDocgroupfiscals as $oldDocgroupfiscal) {
                             $ndocgroupfiscal = new Docgroupfiscal();
                             $ndocgroupfiscal->setCompany($company);
                             $ndocgroupfiscal->setLabel($oldDocgroupfiscal->getLabel());
                             $ndocgroupfiscal->setOtherInfos($oldDocgroupfiscal->getOtherInfos());
                             if (null != $oldDocgroupfiscal->getParent() && $oldDocgroupfiscal->getParent()->getId() != $dgtoclone->getId()) {
                                 $parentId = $oldDocgroupfiscal->getParent()->getId();
                                 $ndocgroupfiscal->setParent($docgroupfiscalsCloneArray[$parentId]);
                             } else {
                                 $ndocgroupfiscal->setParent($docgroupfiscal);
                             }
                             $docgroupfiscalsCloneArray[$oldDocgroupfiscal->getId()] = $ndocgroupfiscal;
                             $em->persist($ndocgroupfiscal);
                         }
                     }
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Docgroupfiscal.add.success', array('%docgroupfiscal%' => $docgroupfiscal->getLabel())));
                     $this->gvars['stabActive'] = 2;
                     $this->getSession()->set('stabActive', 2);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('Docgroupfiscal.add.failure'));
                 }
             } elseif (isset($reqData['DocgrouppersoNewForm'])) {
                 $this->gvars['tabActive'] = 61;
                 $this->getSession()->set('tabActive', 61);
                 $docgrouppersoNewForm->handleRequest($request);
                 if ($docgrouppersoNewForm->isValid()) {
                     $dgtoclone = null;
                     $oldDocgrouppersos = null;
                     if (null != $docgrouppersoNewForm['clone']->getData()) {
                         $dgtoclone = $docgrouppersoNewForm['clone']->getData();
                         $oldDocgrouppersos = $em->getRepository('AcfDataBundle:Docgroupperso')->getAllChilds($dgtoclone);
                     }
                     $em->persist($docgroupperso);
                     $em->flush();
                     if (null != $dgtoclone && null != $oldDocgrouppersos && \count($oldDocgrouppersos) != 0) {
                         $docgrouppersosCloneArray = array();
                         foreach ($oldDocgrouppersos as $oldDocgroupperso) {
                             $ndocgroupperso = new Docgroupperso();
                             $ndocgroupperso->setCompany($company);
                             $ndocgroupperso->setLabel($oldDocgroupperso->getLabel());
                             $ndocgroupperso->setOtherInfos($oldDocgroupperso->getOtherInfos());
                             if (null != $oldDocgroupperso->getParent() && $oldDocgroupperso->getParent()->getId() != $dgtoclone->getId()) {
                                 $parentId = $oldDocgroupperso->getParent()->getId();
                                 $ndocgroupperso->setParent($docgrouppersosCloneArray[$parentId]);
                             } else {
                                 $ndocgroupperso->setParent($docgroupperso);
                             }
                             $docgrouppersosCloneArray[$oldDocgroupperso->getId()] = $ndocgroupperso;
                             $em->persist($ndocgroupperso);
                         }
                     }
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Docgroupperso.add.success', array('%docgroupperso%' => $docgroupperso->getLabel())));
                     $this->gvars['stabActive'] = 2;
                     $this->getSession()->set('stabActive', 2);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('Docgroupperso.add.failure'));
                 }
             } elseif (isset($reqData['DocgroupsystNewForm'])) {
                 $this->gvars['tabActive'] = 71;
                 $this->getSession()->set('tabActive', 71);
                 $docgroupsystNewForm->handleRequest($request);
                 if ($docgroupsystNewForm->isValid()) {
                     $dgtoclone = null;
                     $oldDocgroupsysts = null;
                     if (null != $docgroupsystNewForm['clone']->getData()) {
                         $dgtoclone = $docgroupsystNewForm['clone']->getData();
                         $oldDocgroupsysts = $em->getRepository('AcfDataBundle:Docgroupsyst')->getAllChilds($dgtoclone);
                     }
                     $em->persist($docgroupsyst);
                     $em->flush();
                     if (null != $dgtoclone && null != $oldDocgroupsysts && \count($oldDocgroupsysts) != 0) {
                         $docgroupsystsCloneArray = array();
                         foreach ($oldDocgroupsysts as $oldDocgroupsyst) {
                             $ndocgroupsyst = new Docgroupsyst();
                             $ndocgroupsyst->setCompany($company);
                             $ndocgroupsyst->setLabel($oldDocgroupsyst->getLabel());
                             $ndocgroupsyst->setOtherInfos($oldDocgroupsyst->getOtherInfos());
                             if (null != $oldDocgroupsyst->getParent() && $oldDocgroupsyst->getParent()->getId() != $dgtoclone->getId()) {
                                 $parentId = $oldDocgroupsyst->getParent()->getId();
                                 $ndocgroupsyst->setParent($docgroupsystsCloneArray[$parentId]);
                             } else {
                                 $ndocgroupsyst->setParent($docgroupsyst);
                             }
                             $docgroupsystsCloneArray[$oldDocgroupsyst->getId()] = $ndocgroupsyst;
                             $em->persist($ndocgroupsyst);
                         }
                     }
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Docgroupsyst.add.success', array('%docgroupsyst%' => $docgroupsyst->getLabel())));
                     $this->gvars['stabActive'] = 2;
                     $this->getSession()->set('stabActive', 2);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('Docgroupsyst.add.failure'));
                 }
             } elseif (isset($reqData['DocgroupauditNewForm'])) {
                 $this->gvars['tabActive'] = 81;
                 $this->getSession()->set('tabActive', 81);
                 $docgroupauditNewForm->handleRequest($request);
                 if ($docgroupauditNewForm->isValid()) {
                     $dgtoclone = null;
                     $oldDocgroupaudits = null;
                     if (null != $docgroupauditNewForm['clone']->getData()) {
                         $dgtoclone = $docgroupauditNewForm['clone']->getData();
                         $oldDocgroupaudits = $em->getRepository('AcfDataBundle:Docgroupaudit')->getAllChilds($dgtoclone);
                     }
                     $em->persist($docgroupaudit);
                     $em->flush();
                     if (null != $dgtoclone && null != $oldDocgroupaudits && \count($oldDocgroupaudits) != 0) {
                         $docgroupauditsCloneArray = array();
                         foreach ($oldDocgroupaudits as $oldDocgroupaudit) {
                             $ndocgroupaudit = new Docgroupaudit();
                             $ndocgroupaudit->setCompany($company);
                             $ndocgroupaudit->setLabel($oldDocgroupaudit->getLabel());
                             $ndocgroupaudit->setOtherInfos($oldDocgroupaudit->getOtherInfos());
                             if (null != $oldDocgroupaudit->getParent() && $oldDocgroupaudit->getParent()->getId() != $dgtoclone->getId()) {
                                 $parentId = $oldDocgroupaudit->getParent()->getId();
                                 $ndocgroupaudit->setParent($docgroupauditsCloneArray[$parentId]);
                             } else {
                                 $ndocgroupaudit->setParent($docgroupaudit);
                             }
                             $docgroupauditsCloneArray[$oldDocgroupaudit->getId()] = $ndocgroupaudit;
                             $em->persist($ndocgroupaudit);
                         }
                     }
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Docgroupaudit.add.success', array('%docgroupaudit%' => $docgroupaudit->getLabel())));
                     $this->gvars['stabActive'] = 2;
                     $this->getSession()->set('stabActive', 2);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('Docgroupaudit.add.failure'));
                 }
             } elseif (isset($reqData['MPayeNewForm'])) {
                 $this->gvars['tabActive'] = 101;
                 $this->getSession()->set('tabActive', 101);
                 $mpayeNewForm->handleRequest($request);
                 if ($mpayeNewForm->isValid()) {
                     $mpaye->generateRef();
                     $em->persist($mpaye);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('MPaye.add.success', array('%mpaye%' => $mpaye->getRef())));
                     $this->gvars['stabActive'] = 3;
                     $this->getSession()->set('stabActive', 3);
                     return $this->redirect($urlFrom);
                 } else {
                     $this->gvars['stabActive'] = 2;
                     $this->getSession()->set('stabActive', 2);
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('MPaye.add.failure'));
                 }
             } elseif (isset($reqData['MPayeNewYearForm'])) {
                 $this->gvars['tabActive'] = 101;
                 $this->getSession()->set('tabActive', 101);
                 $mpayeNewYearForm->handleRequest($request);
                 if ($mpayeNewYearForm->isValid()) {
                     $year = $mpayeNewYearForm['year']->getData();
                     foreach (MPaye::choiceMonthCallback() as $month) {
                         $mpaye = $em->getRepository('AcfDataBundle:MPaye')->findOneBy(array('company' => $company, 'year' => $year, 'month' => $month));
                         if (null == $mpaye) {
                             $mpaye = new MPaye();
                             $mpaye->setCompany($company);
                             $mpaye->setYear($year);
                             $mpaye->setMonth($month);
                             $mpaye->generateRef();
                             $em->persist($mpaye);
                             $this->flashMsgSession('success', $this->translate('MPaye.add.success', array('%mpaye%' => $mpaye->getRef())));
                         }
                     }
                     $em->flush();
                     $this->gvars['stabActive'] = 3;
                     $this->getSession()->set('stabActive', 3);
                     return $this->redirect($urlFrom);
                 } else {
                     $this->gvars['stabActive'] = 2;
                     $this->getSession()->set('stabActive', 2);
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('MPaye.add.failure'));
                 }
             }
             $sector = new Sector();
             $sectorNewForm = $this->createForm(SectorNewTForm::class, $sector);
             $this->gvars['sector'] = $sector;
             $this->gvars['SectorNewForm'] = $sectorNewForm->createView();
             $this->gvars['company'] = $company;
             $this->gvars['stock'] = $stock;
             $this->gvars['address'] = $address;
             $this->gvars['phone'] = $phone;
             $this->gvars['companyFrame'] = $companyFrame;
             $this->gvars['companyNature'] = $companyNature;
             $this->gvars['doc'] = $doc;
             $this->gvars['pilot'] = $pilot;
             $this->gvars['companyUser'] = $companyUser;
             $this->gvars['companyAdmin'] = $companyAdmin;
             $this->gvars['companyLabel'] = $companyLabel;
             $this->gvars['customer'] = $customer;
             $this->gvars['supplier'] = $supplier;
             $this->gvars['bank'] = $bank;
             $this->gvars['fund'] = $fund;
             $this->gvars['withholding'] = $withholding;
             $this->gvars['docgroupcomptable'] = $docgroupcomptable;
             $this->gvars['shareholder'] = $withholding;
             $this->gvars['docgroup'] = $docgroup;
             $this->gvars['docgroupfiscal'] = $docgroupfiscal;
             $this->gvars['docgroupperso'] = $docgroupperso;
             $this->gvars['docgroupsyst'] = $docgroupsyst;
             $this->gvars['docgroupaudit'] = $docgroupaudit;
             $this->gvars['docgroupbank'] = $docgroupbank;
             $this->gvars['docgroupcomptables'] = $em->getRepository('AcfDataBundle:Docgroupcomptable')->getRoots($company);
             $this->gvars['docgroups'] = $em->getRepository('AcfDataBundle:Docgroup')->getRoots($company);
             $this->gvars['docgroupfiscals'] = $em->getRepository('AcfDataBundle:Docgroupfiscal')->getRoots($company);
             $this->gvars['docgrouppersos'] = $em->getRepository('AcfDataBundle:Docgroupperso')->getRoots($company);
             $this->gvars['docgroupsysts'] = $em->getRepository('AcfDataBundle:Docgroupsyst')->getRoots($company);
             $this->gvars['docgroupbanks'] = $em->getRepository('AcfDataBundle:Docgroupbank')->getRoots($company);
             $this->gvars['docgroupaudits'] = $em->getRepository('AcfDataBundle:Docgroupaudit')->getRoots($company);
             $this->gvars['CompanyUpdateTypeForm'] = $companyUpdateTypeForm->createView();
             $this->gvars['CompanyUpdateCorporateNameForm'] = $companyUpdateCorporateNameForm->createView();
             $this->gvars['CompanyUpdateFiscForm'] = $companyUpdateFiscForm->createView();
             $this->gvars['CompanyUpdateTribunalForm'] = $companyUpdateTribunalForm->createView();
             $this->gvars['CompanyUpdatePhysicaltypeForm'] = $companyUpdatePhysicaltypeForm->createView();
             $this->gvars['CompanyUpdateCnssForm'] = $companyUpdateCnssForm->createView();
             $this->gvars['CompanyUpdateCnssBureauForm'] = $companyUpdateCnssBureauForm->createView();
             $this->gvars['CompanyUpdateSectorsForm'] = $companyUpdateSectorsForm->createView();
             $this->gvars['CompanyUpdatePhoneForm'] = $companyUpdatePhoneForm->createView();
             $this->gvars['CompanyUpdateMobileForm'] = $companyUpdateMobileForm->createView();
             $this->gvars['CompanyUpdateFaxForm'] = $companyUpdateFaxForm->createView();
             $this->gvars['CompanyUpdateEmailForm'] = $companyUpdateEmailForm->createView();
             $this->gvars['CompanyUpdateAdrForm'] = $companyUpdateAdrForm->createView();
             $this->gvars['CompanyUpdateOtherInfosForm'] = $companyUpdateOtherInfosForm->createView();
             $this->gvars['CompanyUpdateActionvnForm'] = $companyUpdateActionvnForm->createView();
             $this->gvars['CompanyUpdateRefForm'] = $companyUpdateRefForm->createView();
             $this->gvars['StockNewForm'] = $stockNewForm->createView();
             $this->gvars['AddressNewForm'] = $addressNewForm->createView();
             $this->gvars['PhoneNewForm'] = $phoneNewForm->createView();
             $this->gvars['CompanyFrameNewForm'] = $companyFrameNewForm->createView();
             $this->gvars['CompanyNatureNewForm'] = $companyNatureNewForm->createView();
             $this->gvars['CompanyNatureImportForm'] = $companyNatureImportForm->createView();
             $this->gvars['DocNewForm'] = $docNewForm->createView();
             $this->gvars['PilotNewForm'] = $pilotNewForm->createView();
             $this->gvars['CompanyUserNewForm'] = $companyUserNewForm->createView();
             $this->gvars['CompanyAdminNewForm'] = $companyAdminNewForm->createView();
             $this->gvars['CompanyLabelNewForm'] = $companyLabelNewForm->createView();
             $this->gvars['CompanyLabelImportForm'] = $companyLabelImportForm->createView();
             $this->gvars['CustomerNewForm'] = $customerNewForm->createView();
             $this->gvars['CustomerImportForm'] = $customerImportForm->createView();
             $this->gvars['SupplierNewForm'] = $supplierNewForm->createView();
             $this->gvars['SupplierImportForm'] = $supplierImportForm->createView();
             $this->gvars['BankNewForm'] = $bankNewForm->createView();
             $this->gvars['BankImportForm'] = $bankImportForm->createView();
             $this->gvars['FundNewForm'] = $fundNewForm->createView();
             $this->gvars['FundImportForm'] = $fundImportForm->createView();
             $this->gvars['WithholdingNewForm'] = $withholdingNewForm->createView();
             $this->gvars['WithholdingImportForm'] = $withholdingImportForm->createView();
             $this->gvars['MBSaleNewForm'] = $mbsaleNewForm->createView();
             $this->gvars['MBPurchaseNewForm'] = $mbpurchaseNewForm->createView();
             $this->gvars['MBSaleNewYearForm'] = $mbsaleNewYearForm->createView();
             $this->gvars['MBPurchaseNewYearForm'] = $mbpurchaseNewYearForm->createView();
             $this->gvars['MPayeNewForm'] = $mpayeNewForm->createView();
             $this->gvars['MPayeNewYearForm'] = $mpayeNewYearForm->createView();
             $this->gvars['DocgroupcomptableNewForm'] = $docgroupcomptableNewForm->createView();
             $this->gvars['DocgroupNewForm'] = $docgroupNewForm->createView();
             $this->gvars['ShareholderNewForm'] = $shareholderNewForm->createView();
             $this->gvars['DocgroupfiscalNewForm'] = $docgroupfiscalNewForm->createView();
             $this->gvars['DocgrouppersoNewForm'] = $docgrouppersoNewForm->createView();
             $this->gvars['DocgroupsystNewForm'] = $docgroupsystNewForm->createView();
             $this->gvars['DocgroupauditNewForm'] = $docgroupauditNewForm->createView();
             $this->gvars['DocgroupbankNewForm'] = $docgroupbankNewForm->createView();
             $mbsaleYears = $em->getRepository('AcfDataBundle:MBSale')->getAllYearByCompany($company);
             $mbpurchaseYears = $em->getRepository('AcfDataBundle:MBPurchase')->getAllYearByCompany($company);
             $mpayeYears = $em->getRepository('AcfDataBundle:MPaye')->getAllYearByCompany($company);
             $this->gvars['mbsaleYears'] = $mbsaleYears;
             $this->gvars['mbpurchaseYears'] = $mbpurchaseYears;
             $this->gvars['mpayeYears'] = $mpayeYears;
             $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;
             $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;
             $banksConstStr = $em->getRepository('AcfDataBundle:ConstantStr')->findOneBy(array('name' => 'banksPrefix'));
             if (null == $banksConstStr) {
                 $banksConstStr = new ConstantStr();
                 $banksConstStr->setName('banksPrefix');
                 $banksConstStr->setValue('532');
                 $em->persist($banksConstStr);
                 $em->flush();
             }
             $banksPrefix = $banksConstStr->getValue();
             $this->gvars['banksPrefix'] = $banksPrefix;
             $fundsConstStr = $em->getRepository('AcfDataBundle:ConstantStr')->findOneBy(array('name' => 'fundsPrefix'));
             if (null == $fundsConstStr) {
                 $fundsConstStr = new ConstantStr();
                 $fundsConstStr->setName('fundsPrefix');
                 $fundsConstStr->setValue('540');
                 $em->persist($fundsConstStr);
                 $em->flush();
             }
             $fundsPrefix = $fundsConstStr->getValue();
             $this->gvars['fundsPrefix'] = $fundsPrefix;
             $withholdingsConstStr = $em->getRepository('AcfDataBundle:ConstantStr')->findOneBy(array('name' => 'withholdingsPrefix'));
             if (null == $withholdingsConstStr) {
                 $withholdingsConstStr = new ConstantStr();
                 $withholdingsConstStr->setName('withholdingsPrefix');
                 $withholdingsConstStr->setValue('432');
                 $em->persist($withholdingsConstStr);
                 $em->flush();
             }
             $withholdingsPrefix = $withholdingsConstStr->getValue();
             $this->gvars['withholdingsPrefix'] = $withholdingsPrefix;
             $this->gvars['pagetitle'] = $this->translate('pagetitle.company.edit', array('%company%' => $company->getCorporateName()));
             $this->gvars['pagetitle_txt'] = $this->translate('pagetitle.company.edit.txt', array('%company%' => $company->getCorporateName()));
             return $this->renderResponse('AcfAdminBundle:Company:edit.html.twig', $this->gvars);
         }
     } catch (\Exception $e) {
         $logger = $this->getLogger();
         $logger->addCritical($e->getLine() . ' ' . $e->getMessage() . ' ' . $e->getTraceAsString());
     }
     return $this->redirect($urlFrom);
 }
示例#11
0
 /**
  * Add doc
  *
  * @param Doc $doc
  *
  * @return Account
  */
 public function addDoc(Doc $doc)
 {
     $this->docs[] = $doc;
     $doc->addAccount($this);
     return $this;
 }
示例#12
0
 protected function traceEntity(Doc $cloneDoc, Doc $doc)
 {
     $curUser = $this->getSecurityTokenStorage()->getToken()->getUser();
     $trace = new Trace();
     $trace->setActionId($doc->getId());
     $trace->setActionType(Trace::AT_UPDATE);
     $trace->setUserId($curUser->getId());
     $trace->setCompanyId($doc->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_DOC);
     $trace->setActionId2($doc->getCompany()->getId());
     $trace->setActionEntity2(Trace::AE_COMPANY);
     $msg = '';
     if ($cloneDoc->getFileName() != $doc->getFileName()) {
         $msg .= '<tr><td>' . $this->translate('Doc.fileName.label') . '</td><td>';
         if ($cloneDoc->getFileName() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneDoc->getFileName();
         }
         $msg .= '</td><td>';
         if ($doc->getFileName() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $doc->getFileName();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneDoc->getSize() != $doc->getSize()) {
         $msg .= '<tr><td>' . $this->translate('Doc.size.label') . '</td><td>';
         if ($cloneDoc->getSize() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneDoc->getSize();
         }
         $msg .= '</td><td>';
         if ($doc->getSize() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $doc->getSize();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneDoc->getMimeType() != $doc->getMimeType()) {
         $msg .= '<tr><td>' . $this->translate('Doc.mimeType.label') . '</td><td>';
         if ($cloneDoc->getMimeType() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneDoc->getMimeType();
         }
         $msg .= '</td><td>';
         if ($doc->getMimeType() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $doc->getMimeType();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneDoc->getMd5() != $doc->getMd5()) {
         $msg .= '<tr><td>' . $this->translate('Doc.md5.label') . '</td><td>';
         if ($cloneDoc->getMd5() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneDoc->getMd5();
         }
         $msg .= '</td><td>';
         if ($doc->getMd5() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $doc->getMd5();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneDoc->getOriginalName() != $doc->getOriginalName()) {
         $msg .= '<tr><td>' . $this->translate('Doc.originalName.label') . '</td><td>';
         if ($cloneDoc->getOriginalName() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneDoc->getOriginalName();
         }
         $msg .= '</td><td>';
         if ($doc->getOriginalName() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $doc->getOriginalName();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneDoc->getDescription() != $doc->getDescription()) {
         $msg .= '<tr><td>' . $this->translate('Doc.description.label') . '</td><td>';
         if ($cloneDoc->getDescription() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneDoc->getDescription();
         }
         $msg .= '</td><td>';
         if ($doc->getDescription() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $doc->getDescription();
         }
         $msg .= '</td></tr>';
     }
     if ($msg != '') {
         $msg = $tableBegin . $msg . $tableEnd;
         $trace->setMsg($this->translate('Doc.traceEdit', array('%doc%' => $doc->getOriginalName(), '%company%' => $doc->getCompany()->getCorporateName())) . $msg);
         $trace->setDtCrea(new \DateTime('now'));
         $em = $this->getEntityManager();
         $em->persist($trace);
         $em->flush();
     }
 }
示例#13
0
 /**
  * Add doc
  *
  * @param Doc $doc
  *
  * @return MPaye
  */
 public function addDoc(Doc $doc)
 {
     $this->docs[] = $doc;
     $doc->addMpaye($this);
     return $this;
 }
示例#14
0
 /**
  *
  * @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 {
         $company = $em->getRepository('AcfDataBundle:Company')->find($uid);
         if (null == $company) {
             $this->flashMsgSession('warning', $this->translate('Company.edit.notfound'));
         } else {
             $sc = $this->getSecurityTokenStorage();
             $user = $sc->getToken()->getUser();
             $companyUser = $em->getRepository('AcfDataBundle:CompanyUser')->findOneBy(array('company' => $company, 'user' => $user));
             if (null == $companyUser) {
                 return $this->redirect($this->generateUrl('_client_homepage'));
             }
             $this->gvars['companyUser'] = $companyUser;
             $this->gvars['menu_active'] = 'client' . $company->getId();
             $companyUpdateTypeForm = $this->createForm(CompanyUpdateTypeTForm::class, $company);
             $companyUpdateCorporateNameForm = $this->createForm(CompanyUpdateCorporateNameTForm::class, $company);
             $companyUpdateFiscForm = $this->createForm(CompanyUpdateFiscTForm::class, $company);
             $companyUpdateTribunalForm = $this->createForm(CompanyUpdateTribunalTForm::class, $company);
             $companyUpdatePhysicaltypeForm = $this->createForm(CompanyUpdatePhysicaltypeTForm::class, $company);
             $companyUpdateCnssForm = $this->createForm(CompanyUpdateCnssTForm::class, $company);
             $companyUpdateCnssBureauForm = $this->createForm(CompanyUpdateCnssBureauTForm::class, $company);
             $companyUpdateSectorsForm = $this->createForm(CompanyUpdateSectorsTForm::class, $company);
             $companyUpdatePhoneForm = $this->createForm(CompanyUpdatePhoneTForm::class, $company);
             $companyUpdateMobileForm = $this->createForm(CompanyUpdateMobileTForm::class, $company);
             $companyUpdateFaxForm = $this->createForm(CompanyUpdateFaxTForm::class, $company);
             $companyUpdateEmailForm = $this->createForm(CompanyUpdateEmailTForm::class, $company);
             $companyUpdateAdrForm = $this->createForm(CompanyUpdateAdrTForm::class, $company);
             $companyUpdateOtherInfosForm = $this->createForm(CompanyUpdateOtherInfosTForm::class, $company);
             $companyUpdateActionvnForm = $this->createForm(CompanyUpdateActionvnTForm::class, $company);
             $address = new Address();
             $address->setCompany($company);
             $addressNewForm = $this->createForm(AddressNewTForm::class, $address, array('company' => $company));
             $phone = new Phone();
             $phone->setCompany($company);
             $phoneNewForm = $this->createForm(PhoneNewTForm::class, $phone, array('company' => $company));
             $companyFrame = new CompanyFrame();
             $companyFrame->setCompany($company);
             $companyFrameNewForm = $this->createForm(CompanyFrameNewTForm::class, $companyFrame, array('company' => $company));
             $doc = new Doc();
             $doc->setCompany($company);
             $docNewForm = $this->createForm(DocNewTForm::class, $doc, array('company' => $company));
             $customer = new Customer();
             $customer->setCompany($company);
             $customerNewForm = $this->createForm(CustomerNewTForm::class, $customer, array('company' => $company));
             $supplier = new Supplier();
             $supplier->setCompany($company);
             $supplierNewForm = $this->createForm(SupplierNewTForm::class, $supplier, array('company' => $company));
             $mbsale = new MBSale();
             $mbsale->setCompany($company);
             $mbsaleNewForm = $this->createForm(MBSaleNewTForm::class, $mbsale, array('company' => $company));
             $mbpurchase = new MBPurchase();
             $mbpurchase->setCompany($company);
             $mbpurchaseNewForm = $this->createForm(MBPurchaseNewTForm::class, $mbpurchase, array('company' => $company));
             $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();
             $cloneCompany = clone $company;
             if (isset($reqData['CompanyUpdateTypeForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $companyUpdateTypeForm->handleRequest($request);
                 if ($companyUpdateTypeForm->isValid()) {
                     $em->persist($company);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Company.edit.success', array('%company%' => $company->getCorporateName())));
                     $this->traceEntity($cloneCompany, $company);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('Company.edit.failure', array('%company%' => $company->getCorporateName())));
                 }
             } elseif (isset($reqData['CompanyUpdateCorporateNameForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $companyUpdateCorporateNameForm->handleRequest($request);
                 if ($companyUpdateCorporateNameForm->isValid()) {
                     $em->persist($company);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Company.edit.success', array('%company%' => $company->getCorporateName())));
                     $this->traceEntity($cloneCompany, $company);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('Company.edit.failure', array('%company%' => $company->getCorporateName())));
                 }
             } elseif (isset($reqData['CompanyUpdateFiscForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $companyUpdateFiscForm->handleRequest($request);
                 if ($companyUpdateFiscForm->isValid()) {
                     $em->persist($company);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Company.edit.success', array('%company%' => $company->getCorporateName())));
                     $this->traceEntity($cloneCompany, $company);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('Company.edit.failure', array('%company%' => $company->getCorporateName())));
                 }
             } elseif (isset($reqData['CompanyUpdateTribunalForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $companyUpdateTribunalForm->handleRequest($request);
                 if ($companyUpdateTribunalForm->isValid()) {
                     $em->persist($company);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Company.edit.success', array('%company%' => $company->getCorporateName())));
                     $this->traceEntity($cloneCompany, $company);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('Company.edit.failure', array('%company%' => $company->getCorporateName())));
                 }
             } elseif (isset($reqData['CompanyUpdatePhysicaltypeForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $companyUpdatePhysicaltypeForm->handleRequest($request);
                 if ($companyUpdatePhysicaltypeForm->isValid()) {
                     $em->persist($company);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Company.edit.success', array('%company%' => $company->getCorporateName())));
                     $this->traceEntity($cloneCompany, $company);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('Company.edit.failure', array('%company%' => $company->getCorporateName())));
                 }
             } elseif (isset($reqData['CompanyUpdateCnssForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $companyUpdateCnssForm->handleRequest($request);
                 if ($companyUpdateCnssForm->isValid()) {
                     $em->persist($company);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Company.edit.success', array('%company%' => $company->getCorporateName())));
                     $this->traceEntity($cloneCompany, $company);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('Company.edit.failure', array('%company%' => $company->getCorporateName())));
                 }
             } elseif (isset($reqData['CompanyUpdateCnssBureauForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $companyUpdateCnssBureauForm->handleRequest($request);
                 if ($companyUpdateCnssBureauForm->isValid()) {
                     $em->persist($company);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Company.edit.success', array('%company%' => $company->getCorporateName())));
                     $this->traceEntity($cloneCompany, $company);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('Company.edit.failure', array('%company%' => $company->getCorporateName())));
                 }
             } elseif (isset($reqData['CompanyUpdateSectorsForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $companyUpdateSectorsForm->handleRequest($request);
                 if ($companyUpdateSectorsForm->isValid()) {
                     $em->persist($company);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Company.edit.success', array('%company%' => $company->getCorporateName())));
                     $this->traceEntity($cloneCompany, $company);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('Company.edit.failure', array('%company%' => $company->getCorporateName())));
                 }
             } elseif (isset($reqData['CompanyUpdatePhoneForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $companyUpdatePhoneForm->handleRequest($request);
                 if ($companyUpdatePhoneForm->isValid()) {
                     $em->persist($company);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Company.edit.success', array('%company%' => $company->getCorporateName())));
                     $this->traceEntity($cloneCompany, $company);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('Company.edit.failure', array('%company%' => $company->getCorporateName())));
                 }
             } elseif (isset($reqData['CompanyUpdateMobileForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $companyUpdateMobileForm->handleRequest($request);
                 if ($companyUpdateMobileForm->isValid()) {
                     $em->persist($company);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Company.edit.success', array('%company%' => $company->getCorporateName())));
                     $this->traceEntity($cloneCompany, $company);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('Company.edit.failure', array('%company%' => $company->getCorporateName())));
                 }
             } elseif (isset($reqData['CompanyUpdateFaxForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $companyUpdateFaxForm->handleRequest($request);
                 if ($companyUpdateFaxForm->isValid()) {
                     $em->persist($company);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Company.edit.success', array('%company%' => $company->getCorporateName())));
                     $this->traceEntity($cloneCompany, $company);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('Company.edit.failure', array('%company%' => $company->getCorporateName())));
                 }
             } elseif (isset($reqData['CompanyUpdateEmailForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $companyUpdateEmailForm->handleRequest($request);
                 if ($companyUpdateEmailForm->isValid()) {
                     $em->persist($company);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Company.edit.success', array('%company%' => $company->getCorporateName())));
                     $this->traceEntity($cloneCompany, $company);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('Company.edit.failure', array('%company%' => $company->getCorporateName())));
                 }
             } elseif (isset($reqData['CompanyUpdateAdrForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $companyUpdateAdrForm->handleRequest($request);
                 if ($companyUpdateAdrForm->isValid()) {
                     $em->persist($company);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Company.edit.success', array('%company%' => $company->getCorporateName())));
                     $this->traceEntity($cloneCompany, $company);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('Company.edit.failure', array('%company%' => $company->getCorporateName())));
                 }
             } elseif (isset($reqData['CompanyUpdateOtherInfosForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $companyUpdateOtherInfosForm->handleRequest($request);
                 if ($companyUpdateOtherInfosForm->isValid()) {
                     $em->persist($company);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Company.edit.success', array('%company%' => $company->getCorporateName())));
                     $this->traceEntity($cloneCompany, $company);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('Company.edit.failure', array('%company%' => $company->getCorporateName())));
                 }
             } elseif (isset($reqData['CompanyUpdateActionvnForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $companyUpdateActionvnForm->handleRequest($request);
                 if ($companyUpdateActionvnForm->isValid()) {
                     $em->persist($company);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Company.edit.success', array('%company%' => $company->getCorporateName())));
                     $this->traceEntity($cloneCompany, $company);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('Company.edit.failure', array('%company%' => $company->getCorporateName())));
                 }
             } elseif (isset($reqData['AddressNewForm'])) {
                 $this->gvars['tabActive'] = 3;
                 $this->getSession()->set('tabActive', 3);
                 $addressNewForm->handleRequest($request);
                 if ($addressNewForm->isValid()) {
                     $em->persist($address);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Address.add.success', array('%address%' => $address->getLabel())));
                     $this->gvars['stabActive'] = 2;
                     $this->getSession()->set('stabActive', 2);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('Address.add.failure'));
                 }
             } elseif (isset($reqData['PhoneNewForm'])) {
                 $this->gvars['tabActive'] = 4;
                 $this->getSession()->set('tabActive', 4);
                 $phoneNewForm->handleRequest($request);
                 if ($phoneNewForm->isValid()) {
                     $em->persist($phone);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Phone.add.success', array('%phone%' => $phone->getLabel())));
                     $this->gvars['stabActive'] = 2;
                     $this->getSession()->set('stabActive', 2);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('Phone.add.failure'));
                 }
             } elseif (isset($reqData['CompanyFrameNewForm'])) {
                 $this->gvars['tabActive'] = 5;
                 $this->getSession()->set('tabActive', 5);
                 $companyFrameNewForm->handleRequest($request);
                 if ($companyFrameNewForm->isValid()) {
                     $em->persist($companyFrame);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('CompanyFrame.add.success', array('%companyFrame%' => $companyFrame->getFullName())));
                     $this->gvars['stabActive'] = 2;
                     $this->getSession()->set('stabActive', 2);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('CompanyFrame.add.failure'));
                 }
             } elseif (isset($reqData['DocNewForm'])) {
                 $this->gvars['tabActive'] = 7;
                 $this->getSession()->set('tabActive', 7);
                 $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($company);
                         $doc->setFileName($fileName);
                         $doc->setOriginalName($originalName);
                         $doc->setSize($size);
                         $doc->setMimeType($mimeType);
                         $doc->setMd5($md5);
                         $doc->setDescription($docNewForm['description']->getData());
                         $em->persist($doc);
                         $docs[] = $doc;
                         $docNames .= $doc->getOriginalName() . ' ';
                     }
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Doc.add.success', array('%doc%' => $docNames)));
                     $this->newDocNotifyAdmin($company, $docs);
                     $this->gvars['stabActive'] = 2;
                     $this->getSession()->set('stabActive', 2);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('Doc.add.failure'));
                 }
             } elseif (isset($reqData['CustomerNewForm'])) {
                 $this->gvars['tabActive'] = 22;
                 $this->getSession()->set('tabActive', 22);
                 $this->gvars['stabActive'] = 1;
                 $this->getSession()->set('stabActive', 1);
                 $customerNewForm->handleRequest($request);
                 if ($customerNewForm->isValid()) {
                     $em->persist($customer);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Customer.add.success', array('%customer%' => $customer->getLabel())));
                     $this->gvars['stabActive'] = 3;
                     $this->getSession()->set('stabActive', 3);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('Customer.add.failure'));
                 }
             } elseif (isset($reqData['SupplierNewForm'])) {
                 $this->gvars['tabActive'] = 23;
                 $this->getSession()->set('tabActive', 23);
                 $this->gvars['stabActive'] = 1;
                 $this->getSession()->set('stabActive', 1);
                 $supplierNewForm->handleRequest($request);
                 if ($supplierNewForm->isValid()) {
                     $em->persist($supplier);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Supplier.add.success', array('%supplier%' => $supplier->getLabel())));
                     $this->gvars['stabActive'] = 3;
                     $this->getSession()->set('stabActive', 3);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('Supplier.add.failure'));
                 }
             } elseif (isset($reqData['MBSaleNewForm'])) {
                 $this->gvars['tabActive'] = 27;
                 $this->getSession()->set('tabActive', 27);
                 $mbsaleNewForm->handleRequest($request);
                 if ($mbsaleNewForm->isValid()) {
                     $mbsale->generateRef();
                     $em->persist($mbsale);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('MBSale.add.success', array('%mbsale%' => $mbsale->getRef())));
                     $this->gvars['stabActive'] = 2;
                     $this->getSession()->set('stabActive', 2);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('MBSale.add.failure'));
                 }
             } elseif (isset($reqData['MBPurchaseNewForm'])) {
                 $this->gvars['tabActive'] = 28;
                 $this->getSession()->set('tabActive', 28);
                 $mbpurchaseNewForm->handleRequest($request);
                 if ($mbpurchaseNewForm->isValid()) {
                     $mbpurchase->generateRef();
                     $em->persist($mbpurchase);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('MBPurchase.add.success', array('%mbpurchase%' => $mbpurchase->getRef())));
                     $this->gvars['stabActive'] = 2;
                     $this->getSession()->set('stabActive', 2);
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($company);
                     $this->flashMsgSession('error', $this->translate('MBPurchase.add.failure'));
                 }
             }
             $this->gvars['company'] = $company;
             $this->gvars['address'] = $address;
             $this->gvars['phone'] = $phone;
             $this->gvars['companyFrame'] = $companyFrame;
             $this->gvars['doc'] = $doc;
             $this->gvars['customer'] = $customer;
             $this->gvars['supplier'] = $supplier;
             $this->gvars['docgroupcomptables'] = $em->getRepository('AcfDataBundle:Docgroupcomptable')->getRoots($company);
             $this->gvars['docgroups'] = $em->getRepository('AcfDataBundle:Docgroup')->getRoots($company);
             $this->gvars['docgroupfiscals'] = $em->getRepository('AcfDataBundle:Docgroupfiscal')->getRoots($company);
             $this->gvars['docgrouppersos'] = $em->getRepository('AcfDataBundle:Docgroupperso')->getRoots($company);
             $this->gvars['docgroupsysts'] = $em->getRepository('AcfDataBundle:Docgroupsyst')->getRoots($company);
             $this->gvars['docgroupbanks'] = $em->getRepository('AcfDataBundle:Docgroupbank')->getRoots($company);
             $this->gvars['docgroupaudits'] = $em->getRepository('AcfDataBundle:Docgroupaudit')->getRoots($company);
             $this->gvars['CompanyUpdateTypeForm'] = $companyUpdateTypeForm->createView();
             $this->gvars['CompanyUpdateCorporateNameForm'] = $companyUpdateCorporateNameForm->createView();
             $this->gvars['CompanyUpdateFiscForm'] = $companyUpdateFiscForm->createView();
             $this->gvars['CompanyUpdateTribunalForm'] = $companyUpdateTribunalForm->createView();
             $this->gvars['CompanyUpdatePhysicaltypeForm'] = $companyUpdatePhysicaltypeForm->createView();
             $this->gvars['CompanyUpdateCnssForm'] = $companyUpdateCnssForm->createView();
             $this->gvars['CompanyUpdateCnssBureauForm'] = $companyUpdateCnssBureauForm->createView();
             $this->gvars['CompanyUpdateSectorsForm'] = $companyUpdateSectorsForm->createView();
             $this->gvars['CompanyUpdatePhoneForm'] = $companyUpdatePhoneForm->createView();
             $this->gvars['CompanyUpdateMobileForm'] = $companyUpdateMobileForm->createView();
             $this->gvars['CompanyUpdateFaxForm'] = $companyUpdateFaxForm->createView();
             $this->gvars['CompanyUpdateEmailForm'] = $companyUpdateEmailForm->createView();
             $this->gvars['CompanyUpdateAdrForm'] = $companyUpdateAdrForm->createView();
             $this->gvars['CompanyUpdateOtherInfosForm'] = $companyUpdateOtherInfosForm->createView();
             $this->gvars['CompanyUpdateActionvnForm'] = $companyUpdateActionvnForm->createView();
             $this->gvars['AddressNewForm'] = $addressNewForm->createView();
             $this->gvars['PhoneNewForm'] = $phoneNewForm->createView();
             $this->gvars['CompanyFrameNewForm'] = $companyFrameNewForm->createView();
             $this->gvars['DocNewForm'] = $docNewForm->createView();
             $this->gvars['CustomerNewForm'] = $customerNewForm->createView();
             $this->gvars['SupplierNewForm'] = $supplierNewForm->createView();
             $this->gvars['MBSaleNewForm'] = $mbsaleNewForm->createView();
             $this->gvars['MBPurchaseNewForm'] = $mbpurchaseNewForm->createView();
             $mbsaleYears = $em->getRepository('AcfDataBundle:MBSale')->getAllYearByCompany($company);
             $mbpurchaseYears = $em->getRepository('AcfDataBundle:MBPurchase')->getAllYearByCompany($company);
             $this->gvars['mbsaleYears'] = $mbsaleYears;
             $this->gvars['mbpurchaseYears'] = $mbpurchaseYears;
             $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;
             $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;
             $banksConstStr = $em->getRepository('AcfDataBundle:ConstantStr')->findOneBy(array('name' => 'banksPrefix'));
             if (null == $banksConstStr) {
                 $banksConstStr = new ConstantStr();
                 $banksConstStr->setName('banksPrefix');
                 $banksConstStr->setValue('532');
                 $em->persist($banksConstStr);
                 $em->flush();
             }
             $banksPrefix = $banksConstStr->getValue();
             $this->gvars['banksPrefix'] = $banksPrefix;
             $fundsConstStr = $em->getRepository('AcfDataBundle:ConstantStr')->findOneBy(array('name' => 'fundsPrefix'));
             if (null == $fundsConstStr) {
                 $fundsConstStr = new ConstantStr();
                 $fundsConstStr->setName('fundsPrefix');
                 $fundsConstStr->setValue('540');
                 $em->persist($fundsConstStr);
                 $em->flush();
             }
             $fundsPrefix = $fundsConstStr->getValue();
             $this->gvars['fundsPrefix'] = $fundsPrefix;
             $withholdingsConstStr = $em->getRepository('AcfDataBundle:ConstantStr')->findOneBy(array('name' => 'withholdingsPrefix'));
             if (null == $withholdingsConstStr) {
                 $withholdingsConstStr = new ConstantStr();
                 $withholdingsConstStr->setName('withholdingsPrefix');
                 $withholdingsConstStr->setValue('432');
                 $em->persist($withholdingsConstStr);
                 $em->flush();
             }
             $withholdingsPrefix = $withholdingsConstStr->getValue();
             $this->gvars['withholdingsPrefix'] = $withholdingsPrefix;
             $this->gvars['pagetitle'] = $this->translate('pagetitle.company.edit', array('%company%' => $company->getCorporateName()));
             $this->gvars['pagetitle_txt'] = $this->translate('pagetitle.company.edit.txt', array('%company%' => $company->getCorporateName()));
             return $this->renderResponse('AcfClientBundle:Company:edit.html.twig', $this->gvars);
         }
     } catch (\Exception $e) {
         $logger = $this->getLogger();
         $logger->addCritical($e->getLine() . ' ' . $e->getMessage() . ' ' . $e->getTraceAsString());
     }
     return $this->redirect($urlFrom);
 }
示例#15
0
 /**
  *
  * @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);
 }