/** * * @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); }
/** * * @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 { $secondaryVat = $em->getRepository('AcfDataBundle:SecondaryVat')->find($uid); if (null == $secondaryVat) { $this->flashMsgSession('warning', $this->translate('SecondaryVat.edit.notfound')); } else { $traces = $em->getRepository('AcfDataBundle:Trace')->getAllByEntityId($secondaryVat->getId(), Trace::AE_SECONDARYVAT); $this->gvars['traces'] = array_reverse($traces); $secondaryVatUpdateVatForm = $this->createForm(SecondaryVatUpdateVatTForm::class, $secondaryVat); $secondaryVatUpdateBalanceTtcForm = $this->createForm(SecondaryVatUpdateBalanceTtcTForm::class, $secondaryVat); $secondaryVatUpdateVatInfoForm = $this->createForm(SecondaryVatUpdateVatInfoTForm::class, $secondaryVat); $secondaryVatUpdateBalanceNetForm = $this->createForm(SecondaryVatUpdateBalanceNetTForm::class, $secondaryVat); $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(); $cloneSecondaryVat = clone $secondaryVat; if (isset($reqData['SecondaryVatUpdateVatInfoForm'])) { $this->gvars['tabActive'] = 2; $this->getSession()->set('tabActive', 2); $secondaryVatUpdateVatInfoForm->handleRequest($request); if ($secondaryVatUpdateVatInfoForm->isValid()) { $em->persist($secondaryVat); $em->flush(); $this->flashMsgSession('success', $this->translate('SecondaryVat.edit.success', array('%sale%' => $secondaryVat->getSale()->getLabel(), '%secondaryVat%' => $this->translate('SecondaryVat.vatInfo.' . $secondaryVat->getVatInfo())))); $this->traceEntity($cloneSecondaryVat, $secondaryVat); return $this->redirect($urlFrom); } else { $em->refresh($secondaryVat); $this->flashMsgSession('error', $this->translate('SecondaryVat.edit.failure', array('%sale%' => $secondaryVat->getSale()->getLabel(), '%secondaryVat%' => $this->translate('SecondaryVat.vatInfo.' . $secondaryVat->getVatInfo())))); } } elseif (isset($reqData['SecondaryVatUpdateVatForm'])) { $this->gvars['tabActive'] = 2; $this->getSession()->set('tabActive', 2); $secondaryVatUpdateVatForm->handleRequest($request); if ($secondaryVatUpdateVatForm->isValid()) { $em->persist($secondaryVat); $em->flush(); $this->flashMsgSession('success', $this->translate('SecondaryVat.edit.success', array('%sale%' => $secondaryVat->getSale()->getLabel(), '%secondaryVat%' => $this->translate('SecondaryVat.vatInfo.' . $secondaryVat->getVatInfo())))); $this->traceEntity($cloneSecondaryVat, $secondaryVat); return $this->redirect($urlFrom); } else { $em->refresh($secondaryVat); $this->flashMsgSession('error', $this->translate('SecondaryVat.edit.failure', array('%sale%' => $secondaryVat->getSale()->getLabel(), '%secondaryVat%' => $this->translate('SecondaryVat.vatInfo.' . $secondaryVat->getVatInfo())))); } } elseif (isset($reqData['SecondaryVatUpdateBalanceTtcForm'])) { $this->gvars['tabActive'] = 2; $this->getSession()->set('tabActive', 2); $secondaryVatUpdateBalanceTtcForm->handleRequest($request); if ($secondaryVatUpdateBalanceTtcForm->isValid()) { $em->persist($secondaryVat); $em->flush(); $this->flashMsgSession('success', $this->translate('SecondaryVat.edit.success', array('%sale%' => $secondaryVat->getSale()->getLabel(), '%secondaryVat%' => $this->translate('SecondaryVat.vatInfo.' . $secondaryVat->getVatInfo())))); $this->traceEntity($cloneSecondaryVat, $secondaryVat); return $this->redirect($urlFrom); } else { $em->refresh($secondaryVat); $this->flashMsgSession('error', $this->translate('SecondaryVat.edit.failure', array('%sale%' => $secondaryVat->getSale()->getLabel(), '%secondaryVat%' => $this->translate('SecondaryVat.vatInfo.' . $secondaryVat->getVatInfo())))); } } elseif (isset($reqData['SecondaryVatUpdateBalanceNetForm'])) { $this->gvars['tabActive'] = 2; $this->getSession()->set('tabActive', 2); $secondaryVatUpdateBalanceNetForm->handleRequest($request); if ($secondaryVatUpdateBalanceNetForm->isValid()) { $em->persist($secondaryVat); $em->flush(); $this->flashMsgSession('success', $this->translate('SecondaryVat.edit.success', array('%sale%' => $secondaryVat->getSale()->getLabel(), '%secondaryVat%' => $this->translate('SecondaryVat.vatInfo.' . $secondaryVat->getVatInfo())))); $this->traceEntity($cloneSecondaryVat, $secondaryVat); return $this->redirect($urlFrom); } else { $em->refresh($secondaryVat); $this->flashMsgSession('error', $this->translate('SecondaryVat.edit.failure', array('%sale%' => $secondaryVat->getSale()->getLabel(), '%secondaryVat%' => $this->translate('SecondaryVat.vatInfo.' . $secondaryVat->getVatInfo())))); } } $this->gvars['secondaryVat'] = $secondaryVat; $this->gvars['SecondaryVatUpdateVatForm'] = $secondaryVatUpdateVatForm->createView(); $this->gvars['SecondaryVatUpdateBalanceTtcForm'] = $secondaryVatUpdateBalanceTtcForm->createView(); $this->gvars['SecondaryVatUpdateVatInfoForm'] = $secondaryVatUpdateVatInfoForm->createView(); $this->gvars['SecondaryVatUpdateBalanceNetForm'] = $secondaryVatUpdateBalanceNetForm->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.secondaryVat.edit', array('%sale%' => $secondaryVat->getSale()->getLabel(), '%secondaryVat%' => $this->translate('SecondaryVat.vatInfo.' . $secondaryVat->getVatInfo()))); $this->gvars['pagetitle_txt'] = $this->translate('pagetitle.secondaryVat.edit.txt', array('%sale%' => $secondaryVat->getSale()->getLabel(), '%secondaryVat%' => $this->translate('SecondaryVat.vatInfo.' . $secondaryVat->getVatInfo()))); return $this->renderResponse('AcfAdminBundle:SecondaryVat: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 \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 { $secondaryVat = $em->getRepository('AcfDataBundle:SecondaryVat')->find($uid); if (null == $secondaryVat) { $this->flashMsgSession('warning', $this->translate('SecondaryVat.edit.notfound')); } else { $sc = $this->getSecurityTokenStorage(); $user = $sc->getToken()->getUser(); $company = $secondaryVat->getSale()->getMonthlyBalance()->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(); $secondaryVatUpdateVatForm = $this->createForm(SecondaryVatUpdateVatTForm::class, $secondaryVat); $secondaryVatUpdateBalanceTtcForm = $this->createForm(SecondaryVatUpdateBalanceTtcTForm(), $secondaryVat); $secondaryVatUpdateVatInfoForm = $this->createForm(SecondaryVatUpdateVatInfoTForm::class, $secondaryVat); $secondaryVatUpdateBalanceNetForm = $this->createForm(SecondaryVatUpdateBalanceNetTForm::class, $secondaryVat); $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(); $cloneSecondaryVat = clone $secondaryVat; if (isset($reqData['SecondaryVatUpdateVatInfoForm'])) { $this->gvars['tabActive'] = 2; $this->getSession()->set('tabActive', 2); $secondaryVatUpdateVatInfoForm->handleRequest($request); if ($secondaryVatUpdateVatInfoForm->isValid()) { $em->persist($secondaryVat); $em->flush(); $this->flashMsgSession('success', $this->translate('SecondaryVat.edit.success', array('%sale%' => $secondaryVat->getSale()->getNumber(), '%secondaryVat%' => $this->translate('SecondaryVat.vatInfo.' . $secondaryVat->getVatInfo())))); $this->traceEntity($cloneSecondaryVat, $secondaryVat); return $this->redirect($urlFrom); } else { $em->refresh($secondaryVat); $this->flashMsgSession('error', $this->translate('SecondaryVat.edit.failure', array('%sale%' => $secondaryVat->getSale()->getNumber(), '%secondaryVat%' => $this->translate('SecondaryVat.vatInfo.' . $secondaryVat->getVatInfo())))); } } elseif (isset($reqData['SecondaryVatUpdateVatForm'])) { $this->gvars['tabActive'] = 2; $this->getSession()->set('tabActive', 2); $secondaryVatUpdateVatForm->handleRequest($request); if ($secondaryVatUpdateVatForm->isValid()) { $em->persist($secondaryVat); $em->flush(); $this->flashMsgSession('success', $this->translate('SecondaryVat.edit.success', array('%sale%' => $secondaryVat->getSale()->getNumber(), '%secondaryVat%' => $this->translate('SecondaryVat.vatInfo.' . $secondaryVat->getVatInfo())))); $this->traceEntity($cloneSecondaryVat, $secondaryVat); return $this->redirect($urlFrom); } else { $em->refresh($secondaryVat); $this->flashMsgSession('error', $this->translate('SecondaryVat.edit.failure', array('%sale%' => $secondaryVat->getSale()->getNumber(), '%secondaryVat%' => $this->translate('SecondaryVat.vatInfo.' . $secondaryVat->getVatInfo())))); } } elseif (isset($reqData['SecondaryVatUpdateBalanceTtcForm'])) { $this->gvars['tabActive'] = 2; $this->getSession()->set('tabActive', 2); $secondaryVatUpdateBalanceTtcForm->handleRequest($request); if ($secondaryVatUpdateBalanceTtcForm->isValid()) { $em->persist($secondaryVat); $em->flush(); $this->flashMsgSession('success', $this->translate('SecondaryVat.edit.success', array('%sale%' => $secondaryVat->getSale()->getNumber(), '%secondaryVat%' => $this->translate('SecondaryVat.vatInfo.' . $secondaryVat->getVatInfo())))); $this->traceEntity($cloneSecondaryVat, $secondaryVat); return $this->redirect($urlFrom); } else { $em->refresh($secondaryVat); $this->flashMsgSession('error', $this->translate('SecondaryVat.edit.failure', array('%sale%' => $secondaryVat->getSale()->getNumber(), '%secondaryVat%' => $this->translate('SecondaryVat.vatInfo.' . $secondaryVat->getVatInfo())))); } } elseif (isset($reqData['SecondaryVatUpdateBalanceNetForm'])) { $this->gvars['tabActive'] = 2; $this->getSession()->set('tabActive', 2); $secondaryVatUpdateBalanceNetForm->handleRequest($request); if ($secondaryVatUpdateBalanceNetForm->isValid()) { $em->persist($secondaryVat); $em->flush(); $this->flashMsgSession('success', $this->translate('SecondaryVat.edit.success', array('%sale%' => $secondaryVat->getSale()->getNumber(), '%secondaryVat%' => $this->translate('SecondaryVat.vatInfo.' . $secondaryVat->getVatInfo())))); $this->traceEntity($cloneSecondaryVat, $secondaryVat); return $this->redirect($urlFrom); } else { $em->refresh($secondaryVat); $this->flashMsgSession('error', $this->translate('SecondaryVat.edit.failure', array('%sale%' => $secondaryVat->getSale()->getNumber(), '%secondaryVat%' => $this->translate('SecondaryVat.vatInfo.' . $secondaryVat->getVatInfo())))); } } $this->gvars['secondaryVat'] = $secondaryVat; $this->gvars['SecondaryVatUpdateVatForm'] = $secondaryVatUpdateVatForm->createView(); $this->gvars['SecondaryVatUpdateBalanceTtcForm'] = $secondaryVatUpdateBalanceTtcForm->createView(); $this->gvars['SecondaryVatUpdateVatInfoForm'] = $secondaryVatUpdateVatInfoForm->createView(); $this->gvars['SecondaryVatUpdateBalanceNetForm'] = $secondaryVatUpdateBalanceNetForm->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.secondaryVat.edit', array('%sale%' => $secondaryVat->getSale()->getNumber(), '%secondaryVat%' => $this->translate('SecondaryVat.vatInfo.' . $secondaryVat->getVatInfo()))); $this->gvars['pagetitle_txt'] = $this->translate('pagetitle.secondaryVat.edit.txt', array('%sale%' => $secondaryVat->getSale()->getNumber(), '%secondaryVat%' => $this->translate('SecondaryVat.vatInfo.' . $secondaryVat->getVatInfo()))); return $this->renderResponse('AcfClientBundle:SecondaryVat: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 \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 integer $year * @param string $uid * * @return unknown|\Symfony\Component\HttpFoundation\RedirectResponse */ public function excelYearAction($year, $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 { $mbpurchases = $em->getRepository('AcfDataBundle:MBPurchase')->getAllByYearCompany($year, $company); $buys = array(); foreach ($mbpurchases as $mbpurchase) { $buys = array_merge($buys, $mbpurchase->getTransactions()->toArray()); } $phpExcelObject = $this->get('phpexcel')->createPHPExcelObject(); $phpExcelObject->getProperties()->setCreator('Salah Abdelkader Seif Eddine')->setLastModifiedBy($this->getSecurityTokenStorage()->getToken()->getUser()->getFullname())->setTitle($this->translate('pagetitle.buy.list'))->setSubject($this->translate('pagetitle.buy.list'))->setDescription($this->translate('pagetitle.buy.list'))->setKeywords($this->translate('pagetitle.buy.list'))->setCategory('ACEF buy'); $phpExcelObject->setActiveSheetIndex(0); $workSheet = $phpExcelObject->getActiveSheet(); $workSheet->setTitle($this->translate('pagetitle.buy.listExcel', array('%mbpurchase%' => $year))); $workSheet->setCellValue('A1', $this->translate('Buy.number.label')); $workSheet->getStyle('A1')->getFont()->setBold(true); $workSheet->setCellValue('B1', $this->translate('Buy.dtActivation.label')); $workSheet->getStyle('B1')->getFont()->setBold(true); $workSheet->setCellValue('C1', $this->translate('Buy.bill.label')); $workSheet->getStyle('C1')->getFont()->setBold(true); $workSheet->setCellValue('D1', $this->translate('Buy.relation.label')); $workSheet->getStyle('D1')->getFont()->setBold(true); $workSheet->setCellValue('E1', $this->translate('Buy.relation.number')); $workSheet->getStyle('E1')->getFont()->setBold(true); $workSheet->setCellValue('F1', $this->translate('Buy.label.label')); $workSheet->getStyle('F1')->getFont()->setBold(true); $workSheet->setCellValue('G1', $this->translate('Buy.balanceHt.label')); $workSheet->getStyle('G1')->getFont()->setBold(true); $workSheet->setCellValue('H1', $this->translate('Buy.vat.label')); $workSheet->getStyle('H1')->getFont()->setBold(true); $workSheet->setCellValue('I1', $this->translate('Buy.stamp.label')); $workSheet->getStyle('I1')->getFont()->setBold(true); $workSheet->setCellValue('J1', $this->translate('Buy.balanceTtc.label')); $workSheet->getStyle('J1')->getFont()->setBold(true); $workSheet->setCellValue('K1', $this->translate('Buy.regime.label')); $workSheet->getStyle('K1')->getFont()->setBold(true); $workSheet->setCellValue('L1', $this->translate('Buy.withholding.label')); $workSheet->getStyle('L1')->getFont()->setBold(true); $workSheet->setCellValue('M1', $this->translate('Buy.withholding.value.label')); $workSheet->getStyle('M1')->getFont()->setBold(true); $workSheet->setCellValue('N1', $this->translate('Buy.balanceNet.label')); $workSheet->getStyle('N1')->getFont()->setBold(true); $workSheet->setCellValue('O1', $this->translate('Buy.paymentType.label')); $workSheet->getStyle('O1')->getFont()->setBold(true); $workSheet->setCellValue('P1', $this->translate('Buy.dtPayment.label')); $workSheet->getStyle('P1')->getFont()->setBold(true); $workSheet->setCellValue('Q1', $this->translate('Buy.account.label')); $workSheet->getStyle('Q1')->getFont()->setBold(true); $workSheet->setCellValue('R1', $this->translate('Buy.nature.label')); $workSheet->getStyle('R1')->getFont()->setBold(true); $workSheet->setCellValue('S1', $this->translate('Buy.transactionStatus.label')); $workSheet->getStyle('S1')->getFont()->setBold(true); $workSheet->setCellValue('T1', $this->translate('Buy.otherInfos.label')); $workSheet->getStyle('T1')->getFont()->setBold(true); $workSheet->getStyle('A1:T1')->applyFromArray(array('fill' => array('type' => \PHPExcel_Style_Fill::FILL_SOLID, 'color' => array('rgb' => '94ccdf')))); $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; $i = 1; // $currencyFormatter = new \NumberFormatter($this->getRequest()->getLocale(), \NumberFormatter::CURRENCY); // $balance = $currencyFormatter->formatCurrency($balance, 'TND'); foreach ($buys as $buy) { $i++; $workSheet->setCellValue('A' . $i, $buy->getNumber(), \PHPExcel_Cell_DataType::TYPE_STRING2); $workSheet->setCellValue('B' . $i, \PHPExcel_Shared_Date::PHPToExcel($buy->getDtActivation()), \PHPExcel_Cell_DataType::TYPE_NUMERIC); $workSheet->getStyle('B' . $i)->getNumberFormat()->setFormatCode('dd/mm/yyyy'); $workSheet->setCellValue('C' . $i, $buy->getBill(), \PHPExcel_Cell_DataType::TYPE_STRING2); $workSheet->setCellValue('D' . $i, $buy->getRelation()->getLabel(), \PHPExcel_Cell_DataType::TYPE_STRING2); $numb = $suppliersPrefix . $buy->getRelation()->getNumberFormated(); $workSheet->setCellValueExplicit('E' . $i, $numb, \PHPExcel_Cell_DataType::TYPE_STRING2); $workSheet->setCellValue('F' . $i, $buy->getLabel(), \PHPExcel_Cell_DataType::TYPE_STRING2); $balanceHt = $buy->getBalanceTtc() - $buy->getStamp() - $buy->getVat(); // $balanceHt = $currencyFormatter->formatCurrency($balanceHt, 'TND'); $workSheet->setCellValue('G' . $i, $balanceHt); $workSheet->getStyle('G' . $i)->getNumberFormat()->setFormatCode('#,##0.000'); $workSheet->setCellValue('H' . $i, $buy->getVat()); $workSheet->getStyle('H' . $i)->getNumberFormat()->setFormatCode('#,##0.000'); $workSheet->setCellValue('I' . $i, $buy->getStamp()); $workSheet->getStyle('I' . $i)->getNumberFormat()->setFormatCode('#,##0.000'); $workSheet->setCellValue('J' . $i, $buy->getBalanceTtc()); $workSheet->getStyle('J' . $i)->getNumberFormat()->setFormatCode('#,##0.000'); $workSheet->setCellValue('K' . $i, $this->translate('Buy.regime.' . $buy->getRegime()), \PHPExcel_Cell_DataType::TYPE_STRING2); $withholding = $buy->getBalanceTtc() - $buy->getBalanceNet(); $workSheet->setCellValue('L' . $i, $withholding); $workSheet->getStyle('L' . $i)->getNumberFormat()->setFormatCode('#,##0.000'); $workSheet->setCellValue('M' . $i, $buy->getWithholding()->getValue() / 100); $workSheet->getStyle('M' . $i)->getNumberFormat()->setFormatCode('#,##0.00%'); $workSheet->setCellValue('N' . $i, $buy->getBalanceNet()); $workSheet->getStyle('N' . $i)->getNumberFormat()->setFormatCode('#,##0.000'); $workSheet->setCellValue('O' . $i, $this->translate('Transaction.paymentType.' . $buy->getPaymentType()), \PHPExcel_Cell_DataType::TYPE_STRING2); $workSheet->setCellValue('P' . $i, \PHPExcel_Shared_Date::PHPToExcel($buy->getDtPayment()), \PHPExcel_Cell_DataType::TYPE_NUMERIC); $workSheet->getStyle('P' . $i)->getNumberFormat()->setFormatCode('dd/mm/yyyy'); $workSheet->setCellValue('Q' . $i, $buy->getAccount()->getLabel(), \PHPExcel_Cell_DataType::TYPE_STRING2); if (null == $buy->getNature()) { $workSheet->setCellValue('R' . $i, 'ACHATS DE MARCHANDISES', \PHPExcel_Cell_DataType::TYPE_STRING2); } else { $workSheet->setCellValue('R' . $i, $buy->getNature()->getLabel(), \PHPExcel_Cell_DataType::TYPE_STRING2); } $workSheet->setCellValue('S' . $i, $this->translate('Transaction.transactionStatus.' . $buy->getTransactionStatus()), \PHPExcel_Cell_DataType::TYPE_STRING2); $workSheet->setCellValue('T' . $i, $buy->getOtherInfos(), \PHPExcel_Cell_DataType::TYPE_STRING2); if ($i % 2 == 1) { $workSheet->getStyle('A' . $i . ':T' . $i)->applyFromArray(array('fill' => array('type' => \PHPExcel_Style_Fill::FILL_SOLID, 'color' => array('rgb' => 'd8f1f5')))); } else { $workSheet->getStyle('A' . $i . ':T' . $i)->applyFromArray(array('fill' => array('type' => \PHPExcel_Style_Fill::FILL_SOLID, 'color' => array('rgb' => 'bfbfbf')))); } } $workSheet->getColumnDimension('A')->setAutoSize(true); $workSheet->getColumnDimension('B')->setAutoSize(true); $workSheet->getColumnDimension('C')->setAutoSize(true); $workSheet->getColumnDimension('D')->setAutoSize(true); $workSheet->getColumnDimension('E')->setAutoSize(true); $workSheet->getColumnDimension('F')->setAutoSize(true); $workSheet->getColumnDimension('G')->setAutoSize(true); $workSheet->getColumnDimension('H')->setAutoSize(true); $workSheet->getColumnDimension('I')->setAutoSize(true); $workSheet->getColumnDimension('J')->setAutoSize(true); $workSheet->getColumnDimension('K')->setAutoSize(true); $workSheet->getColumnDimension('L')->setAutoSize(true); $workSheet->getColumnDimension('M')->setAutoSize(true); $workSheet->getColumnDimension('N')->setAutoSize(true); $workSheet->getColumnDimension('O')->setAutoSize(true); $workSheet->getColumnDimension('P')->setAutoSize(true); $workSheet->getColumnDimension('Q')->setAutoSize(true); $workSheet->getColumnDimension('R')->setAutoSize(true); $workSheet->getColumnDimension('S')->setAutoSize(true); $workSheet->getColumnDimension('T')->setAutoSize(true); $writer = $this->get('phpexcel')->createWriter($phpExcelObject, 'Excel2007'); $response = $this->get('phpexcel')->createStreamedResponse($writer); $response->headers->set('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet; charset=utf-8'); $filename = $this->normalize($this->translate('pagetitle.buy.listByYear', array('%year%' => $year, '%company%' => $mbpurchase->getCompany()->getCorporateName()))); $filename = str_ireplace('"', '|', $filename); $filename = str_ireplace(' ', '_', $filename); $response->headers->set('Content-Disposition', 'attachment;filename=' . $filename . '.xlsx'); $response->headers->set('Pragma', 'public'); $response->headers->set('Cache-Control', 'maxage=1'); return $response; } } catch (\Exception $e) { $logger = $this->getLogger(); $logger->addCritical($e->getLine() . ' ' . $e->getMessage() . ' ' . $e->getTraceAsString()); } return $this->redirect($urlFrom); }
/** * * @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 { $customer = $em->getRepository('AcfDataBundle:Customer')->find($uid); if (null == $customer) { $this->flashMsgSession('warning', $this->translate('Customer.edit.notfound')); } else { $sc = $this->getSecurityTokenStorage(); $user = $sc->getToken()->getUser(); $company = $customer->getCompany(); $companyUser = $em->getRepository('AcfDataBundle:CompanyUser')->findOneBy(array('company' => $company, 'user' => $user)); if (null == $companyUser || $companyUser->getEditCustomers() == 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(); $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()) { $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($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); $docs[] = $doc; $docNames .= $doc->getOriginalName() . ' '; } $em->persist($customer); $em->flush(); $this->flashMsgSession('success', $this->translate('Doc.add.success', array('%doc%' => $docNames))); $this->newDocNotifyAdmin($customer, $docs); $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('AcfClientBundle:Customer: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 unknown|\Symfony\Component\HttpFoundation\RedirectResponse */ public function withholdingExcelAction($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); $withholdings = $company->getWithholdings(); $phpExcelObject = $this->get('phpexcel')->createPHPExcelObject(); $phpExcelObject->getProperties()->setCreator('Salah Abdelkader Seif Eddine')->setLastModifiedBy($this->getSecurityTokenStorage()->getToken()->getUser()->getFullname())->setTitle($this->translate('pagetitle.withholding.list'))->setSubject($this->translate('pagetitle.withholding.list'))->setDescription($this->translate('pagetitle.withholding.list'))->setKeywords($this->translate('pagetitle.withholding.list'))->setCategory('ACEF withholding'); $phpExcelObject->setActiveSheetIndex(0); $workSheet = $phpExcelObject->getActiveSheet(); $workSheet->setTitle($this->translate('pagetitle.withholding.list')); $workSheet->setCellValue('A1', $this->translate('Withholding.label.label')); $workSheet->getStyle('A1')->getFont()->setBold(true); $workSheet->setCellValue('B1', $this->translate('Withholding.number.label')); $workSheet->getStyle('B1')->getFont()->setBold(true); $workSheet->setCellValue('C1', $this->translate('Withholding.value.label')); $workSheet->getStyle('C1')->getFont()->setBold(true); $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; $workSheet->getStyle('A1:C1')->applyFromArray(array('fill' => array('type' => \PHPExcel_Style_Fill::FILL_SOLID, 'color' => array('rgb' => '94ccdf')))); $i = 1; foreach ($withholdings as $withholding) { $i++; $workSheet->setCellValue('A' . $i, $withholding->getLabel(), \PHPExcel_Cell_DataType::TYPE_STRING2); $numb = $withholdingsPrefix . $withholding->getNumberFormated(); $workSheet->setCellValueExplicit('B' . $i, $numb, \PHPExcel_Cell_DataType::TYPE_STRING2); $workSheet->setCellValue('C' . $i, $withholding->getValue() . '%', \PHPExcel_Cell_DataType::TYPE_STRING2); if ($i % 2 == 1) { $workSheet->getStyle('A' . $i . ':C' . $i)->applyFromArray(array('fill' => array('type' => \PHPExcel_Style_Fill::FILL_SOLID, 'color' => array('rgb' => 'd8f1f5')))); } else { $workSheet->getStyle('A' . $i . ':C' . $i)->applyFromArray(array('fill' => array('type' => \PHPExcel_Style_Fill::FILL_SOLID, 'color' => array('rgb' => 'bfbfbf')))); } } $workSheet->getColumnDimension('A')->setAutoSize(true); $workSheet->getColumnDimension('B')->setAutoSize(true); $workSheet->getColumnDimension('C')->setAutoSize(true); $writer = $this->get('phpexcel')->createWriter($phpExcelObject, 'Excel2007'); $response = $this->get('phpexcel')->createStreamedResponse($writer); $response->headers->set('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet; charset=utf-8'); $filename = $this->normalize($this->translate('pagetitle.withholding.listByCompany', array('%company%' => $company->getCorporateName()))); $filename = str_ireplace('"', '|', $filename); $filename = str_ireplace(' ', '_', $filename); $response->headers->set('Content-Disposition', 'attachment;filename=' . $filename . '.xlsx'); $response->headers->set('Pragma', 'public'); $response->headers->set('Cache-Control', 'maxage=1'); return $response; } catch (\Exception $e) { $logger = $this->getLogger(); $logger->addCritical($e->getLine() . ' ' . $e->getMessage() . ' ' . $e->getTraceAsString()); } return $this->redirect($urlFrom); }
/** * * @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 { $withholding = $em->getRepository('AcfDataBundle:Withholding')->find($uid); if (null == $withholding) { $this->flashMsgSession('warning', $this->translate('Withholding.edit.notfound')); } else { $traces = $em->getRepository('AcfDataBundle:Trace')->getAllByEntityId($withholding->getId(), Trace::AE_WHITHHOLDING); $this->gvars['traces'] = array_reverse($traces); $withholdingUpdateLabelForm = $this->createForm(WithholdingUpdateLabelTForm::class, $withholding); $withholdingUpdateNumberForm = $this->createForm(WithholdingUpdateNumberTForm::class, $withholding); $withholdingUpdateValueForm = $this->createForm(WithholdingUpdateValueTForm::class, $withholding); $withholdingUpdateOtherInfosForm = $this->createForm(WithholdingUpdateOtherInfosTForm::class, $withholding); $this->gvars['tabActive'] = $this->getSession()->get('tabActive', 2); $this->getSession()->remove('tabActive'); $request = $this->getRequest(); $reqData = $request->request->all(); $cloneWithholding = clone $withholding; if (isset($reqData['WithholdingUpdateLabelForm'])) { $this->gvars['tabActive'] = 2; $this->getSession()->set('tabActive', 2); $withholdingUpdateLabelForm->handleRequest($request); if ($withholdingUpdateLabelForm->isValid()) { $em->persist($withholding); $em->flush(); $this->flashMsgSession('success', $this->translate('Withholding.edit.success', array('%withholding%' => $withholding->getLabel()))); $this->traceEntity($cloneWithholding, $withholding); return $this->redirect($urlFrom); } else { $em->refresh($withholding); $this->flashMsgSession('error', $this->translate('Withholding.edit.failure', array('%withholding%' => $withholding->getLabel()))); } } elseif (isset($reqData['WithholdingUpdateNumberForm'])) { $this->gvars['tabActive'] = 2; $this->getSession()->set('tabActive', 2); $withholdingUpdateNumberForm->handleRequest($request); if ($withholdingUpdateNumberForm->isValid()) { $em->persist($withholding); $em->flush(); $this->flashMsgSession('success', $this->translate('Withholding.edit.success', array('%withholding%' => $withholding->getLabel()))); $this->traceEntity($cloneWithholding, $withholding); return $this->redirect($urlFrom); } else { $em->refresh($withholding); $this->flashMsgSession('error', $this->translate('Withholding.edit.failure', array('%withholding%' => $withholding->getLabel()))); } } elseif (isset($reqData['WithholdingUpdateValueForm'])) { $this->gvars['tabActive'] = 2; $this->getSession()->set('tabActive', 2); $withholdingUpdateValueForm->handleRequest($request); if ($withholdingUpdateValueForm->isValid()) { $em->persist($withholding); $em->flush(); $this->flashMsgSession('success', $this->translate('Withholding.edit.success', array('%withholding%' => $withholding->getLabel()))); $this->traceEntity($cloneWithholding, $withholding); return $this->redirect($urlFrom); } else { $em->refresh($withholding); $this->flashMsgSession('error', $this->translate('Withholding.edit.failure', array('%withholding%' => $withholding->getLabel()))); } } elseif (isset($reqData['WithholdingUpdateOtherInfosForm'])) { $this->gvars['tabActive'] = 2; $this->getSession()->set('tabActive', 2); $withholdingUpdateOtherInfosForm->handleRequest($request); if ($withholdingUpdateOtherInfosForm->isValid()) { $em->persist($withholding); $em->flush(); $this->flashMsgSession('success', $this->translate('Withholding.edit.success', array('%withholding%' => $withholding->getLabel()))); $this->traceEntity($cloneWithholding, $withholding); return $this->redirect($urlFrom); } else { $em->refresh($withholding); $this->flashMsgSession('error', $this->translate('Withholding.edit.failure', array('%withholding%' => $withholding->getLabel()))); } } $this->gvars['withholding'] = $withholding; $this->gvars['WithholdingUpdateLabelForm'] = $withholdingUpdateLabelForm->createView(); $this->gvars['WithholdingUpdateNumberForm'] = $withholdingUpdateNumberForm->createView(); $this->gvars['WithholdingUpdateValueForm'] = $withholdingUpdateValueForm->createView(); $this->gvars['WithholdingUpdateOtherInfosForm'] = $withholdingUpdateOtherInfosForm->createView(); $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.withholding.edit', array('%withholding%' => $withholding->getLabel())); $this->gvars['pagetitle_txt'] = $this->translate('pagetitle.withholding.edit.txt', array('%withholding%' => $withholding->getLabel())); return $this->renderResponse('AcfAdminBundle:Withholding: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 \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); }