/** * Form builder * * @param FormBuilderInterface $builder * @param array $options * * @return null */ public function buildForm(FormBuilderInterface $builder, array $options) { $this->invoice = $options['invoice']; if (null == $this->invoice) { $builder->add('invoice', EntityType::class, array('label' => 'InvoiceDocument.invoice.label', 'class' => 'AcfDataBundle:OnlineInvoice', 'query_builder' => function (OnlineInvoiceRepository $ir) { return $ir->createQueryBuilder('i')->orderBy('i.dtCrea', 'ASC'); }, 'choice_label' => 'ref', 'multiple' => false, 'by_reference' => true, 'required' => true)); } else { $invoiceId = $this->invoice->getId(); $builder->add('invoice', EntityidType::class, array('label' => 'InvoiceDocument.invoice.label', 'class' => 'AcfDataBundle:OnlineInvoice', 'query_builder' => function (OnlineInvoiceRepository $br) use($invoiceId) { return $br->createQueryBuilder('i')->where('i.id = :id')->setParameter('id', $invoiceId)->orderBy('i.dtCrea', 'ASC'); }, 'choice_label' => 'id', 'multiple' => false, 'by_reference' => true, 'required' => true)); } $builder->add('fileName', FileType::class, array('label' => 'InvoiceDocument.fileName.label')); $builder->add('visible', ChoiceType::class, array('label' => 'InvoiceDocument.visible.label', 'choices_as_values' => true, 'choices' => OnlineInvoiceDocument::choiceVisible(), 'attr' => array('choice_label_trans' => true))); }
/** * * @param string $uid * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response */ public function editPostAction($uid) { if (!$this->hasRole('ROLE_SUPERADMIN')) { return $this->redirect($this->generateUrl('_admin_homepage')); } $urlFrom = $this->getReferer(); if (null == $urlFrom || trim($urlFrom) == '') { return $this->redirect($this->generateUrl('_admin_invoice_list')); } $em = $this->getEntityManager(); try { $invoice = $em->getRepository('AcfDataBundle:OnlineInvoice')->find($uid); if (null == $invoice) { $this->flashMsgSession('warning', $this->translate('Invoice.edit.notfound')); } else { $invoiceUpdateStatusForm = $this->createForm(InvoiceUpdateStatusTForm::class, $invoice); $invoiceUpdatePaymentTypeForm = $this->createForm(InvoiceUpdatePaymentTypeTForm::class, $invoice); $invoiceUpdateOrderToForm = $this->createForm(InvoiceUpdateOrderToTForm::class, $invoice); $invoiceUpdateRefForm = $this->createForm(InvoiceUpdateRefTForm::class, $invoice); $invoiceDoc = new OnlineInvoiceDocument(); $invoiceDoc->setInvoice($invoice); $invoiceDocumentNewForm = $this->createForm(InvoiceDocumentNewTForm::class, $invoiceDoc, array('invoice' => $invoice)); $this->gvars['tabActive'] = $this->getSession()->get('tabActive', 2); $this->getSession()->remove('tabActive'); $request = $this->getRequest(); $reqData = $request->request->all(); if (isset($reqData['InvoiceUpdateStatusForm'])) { $this->gvars['tabActive'] = 2; $this->getSession()->set('tabActive', 2); $invoiceUpdateStatusForm->handleRequest($request); if ($invoiceUpdateStatusForm->isValid()) { $em->persist($invoice); $em->flush(); $this->flashMsgSession('success', $this->translate('Invoice.edit.success', array('%invoice%' => $invoice->getRef()))); return $this->redirect($urlFrom); } else { $em->refresh($invoice); $this->flashMsgSession('error', $this->translate('Invoice.edit.failure', array('%invoice%' => $invoice->getRef()))); } } elseif (isset($reqData['InvoiceUpdatePaymentTypeForm'])) { $this->gvars['tabActive'] = 2; $this->getSession()->set('tabActive', 2); $invoiceUpdatePaymentTypeForm->handleRequest($request); if ($invoiceUpdatePaymentTypeForm->isValid()) { $em->persist($invoice); $em->flush(); $this->flashMsgSession('success', $this->translate('Invoice.edit.success', array('%invoice%' => $invoice->getRef()))); return $this->redirect($urlFrom); } else { $em->refresh($invoice); $this->flashMsgSession('error', $this->translate('Invoice.edit.failure', array('%invoice%' => $invoice->getRef()))); } } elseif (isset($reqData['InvoiceUpdateOrderToForm'])) { $this->gvars['tabActive'] = 2; $this->getSession()->set('tabActive', 2); $invoiceUpdateOrderToForm->handleRequest($request); if ($invoiceUpdateOrderToForm->isValid()) { $em->persist($invoice); $em->flush(); $this->flashMsgSession('success', $this->translate('Invoice.edit.success', array('%invoice%' => $invoice->getRef()))); return $this->redirect($urlFrom); } else { $em->refresh($invoice); $this->flashMsgSession('error', $this->translate('Invoice.edit.failure', array('%invoice%' => $invoice->getRef()))); } } elseif (isset($reqData['InvoiceUpdateRefForm'])) { $this->gvars['tabActive'] = 2; $this->getSession()->set('tabActive', 2); $invoiceUpdateRefForm->handleRequest($request); if ($invoiceUpdateRefForm->isValid()) { $em->persist($invoice); $em->flush(); $this->flashMsgSession('success', $this->translate('Invoice.edit.success', array('%invoice%' => $invoice->getRef()))); return $this->redirect($urlFrom); } else { $em->refresh($invoice); $this->flashMsgSession('error', $this->translate('Invoice.edit.failure', array('%invoice%' => $invoice->getRef()))); } } elseif (isset($reqData['InvoiceDocumentNewForm'])) { $this->gvars['tabActive'] = 3; $this->getSession()->set('tabActive', 3); $invoiceDocumentNewForm->handleRequest($request); if ($invoiceDocumentNewForm->isValid()) { $invoiceDocumentFile = $invoiceDocumentNewForm['fileName']->getData(); $invoiceDocumentDir = $this->getParameter('kernel.root_dir') . '/../web/res/invoiceDocuments'; $originalName = $invoiceDocumentFile->getClientOriginalName(); $fileName = sha1(uniqid(mt_rand(), true)) . '.' . strtolower($invoiceDocumentFile->getClientOriginalExtension()); $mimeType = $invoiceDocumentFile->getMimeType(); $invoiceDocumentFile->move($invoiceDocumentDir, $fileName); $size = filesize($invoiceDocumentDir . '/' . $fileName); $md5 = md5_file($invoiceDocumentDir . '/' . $fileName); $invoiceDoc->setFileName($fileName); $invoiceDoc->setOriginalName($originalName); $invoiceDoc->setSize($size); $invoiceDoc->setMimeType($mimeType); $invoiceDoc->setMd5($md5); $em->persist($invoiceDoc); $em->flush(); $this->flashMsgSession('success', $this->translate('InvoiceDocument.add.success', array('%invoiceDocument%' => $invoiceDoc->getOriginalName()))); return $this->redirect($urlFrom); } else { $em->refresh($invoice); $this->flashMsgSession('error', $this->translate('InvoiceDocument.add.failure')); } } $this->gvars['invoice'] = $invoice; $this->gvars['InvoiceUpdateStatusForm'] = $invoiceUpdateStatusForm->createView(); $this->gvars['InvoiceUpdatePaymentTypeForm'] = $invoiceUpdatePaymentTypeForm->createView(); $this->gvars['InvoiceUpdateOrderToForm'] = $invoiceUpdateOrderToForm->createView(); $this->gvars['InvoiceUpdateRefForm'] = $invoiceUpdateRefForm->createView(); $this->gvars['invoiceDocument'] = $invoiceDoc; $this->gvars['InvoiceDocumentNewForm'] = $invoiceDocumentNewForm->createView(); $this->gvars['pagetitle'] = $this->translate('pagetitle.invoice.edit', array('%invoice%' => $invoice->getRef())); $this->gvars['pagetitle_txt'] = $this->translate('pagetitle.invoice.edit.txt', array('%invoice%' => $invoice->getRef())); return $this->renderResponse('AcfAdminBundle:Invoice:edit.html.twig', $this->gvars); } } catch (\Exception $e) { $logger = $this->getLogger(); $logger->addCritical($e->getLine() . ' ' . $e->getMessage() . ' ' . $e->getTraceAsString()); } return $this->redirect($urlFrom); }
/** * Form builder * * @param FormBuilderInterface $builder * @param array $options */ public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('visible', ChoiceType::class, array('label' => 'InvoiceDocument.visible.label', 'choices_as_values' => true, 'choices' => OnlineInvoiceDocument::choiceVisible(), 'attr' => array('choice_label_trans' => true))); }
public function editPostAction($uid) { $urlFrom = $this->getReferer(); if (null == $urlFrom || trim($urlFrom) == '') { $urlFrom = $this->generateUrl('_security_myInvoices'); } $sc = $this->getSecurityTokenStorage(); $user = $sc->getToken()->getUser(); $em = $this->getEntityManager(); try { $invoice = $em->getRepository('AcfDataBundle:OnlineInvoice')->find($uid); if (null == $invoice || null == $invoice->getUser() || $invoice->getUser()->getId() != $user->getId()) { return $this->redirect($urlFrom); } else { $invoiceDoc = new OnlineInvoiceDocument(); $invoiceDoc->setInvoice($invoice); $invoiceDoc->setVisible(OnlineInvoiceDocument::ST_OK); $invoiceDocumentNewForm = $this->createForm(NewInvoiceDocumentTForm::class, $invoiceDoc, array('invoice' => $invoice)); $request = $this->getRequest(); $reqData = $request->request->all(); if (isset($reqData['NewInvoiceDocumentForm'])) { $this->gvars['tabActive'] = 3; $this->getSession()->set('tabActive', 3); $invoiceDocumentNewForm->handleRequest($request); if ($invoiceDocumentNewForm->isValid()) { $invoiceDocumentFile = $invoiceDocumentNewForm['fileName']->getData(); $invoiceDocumentDir = $this->getParameter('kernel.root_dir') . '/../web/res/invoiceDocuments'; $originalName = $invoiceDocumentFile->getClientOriginalName(); $fileName = sha1(uniqid(mt_rand(), true)) . '.' . strtolower($invoiceDocumentFile->getClientOriginalExtension()); $mimeType = $invoiceDocumentFile->getMimeType(); $invoiceDocumentFile->move($invoiceDocumentDir, $fileName); $size = filesize($invoiceDocumentDir . '/' . $fileName); $md5 = md5_file($invoiceDocumentDir . '/' . $fileName); $invoiceDoc->setFileName($fileName); $invoiceDoc->setOriginalName($originalName); $invoiceDoc->setSize($size); $invoiceDoc->setMimeType($mimeType); $invoiceDoc->setMd5($md5); $em->persist($invoiceDoc); $em->flush(); $from = $this->getParameter('mail_from'); $fromName = $this->getParameter('mail_from_name'); $subject = $this->translate('_mail.invoicedoc.subject', array('%invoice%' => $invoiceDoc->getInvoice()->getRef(), '%invoiceDocument%' => $invoiceDoc->getOriginalName()), 'messages'); $mvars = array(); $mvars['invoiceDoc'] = $invoiceDoc; $admins = $this->getParameter('mailtos'); $message = \Swift_Message::newInstance(); $message->setFrom($from, $fromName); foreach ($admins as $admin) { $message->addTo($admin['email'], $admin['name']); } $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('AcfSecurityBundle:Mail:newdoc.html.twig', $mvars), 'text/html'); $this->sendmail($message); $this->flashMsgSession('success', $this->translate('InvoiceDocument.add.success', array('%invoiceDocument%' => $invoiceDoc->getOriginalName()))); return $this->redirect($urlFrom); } else { $em->refresh($invoice); $this->flashMsgSession('error', $this->translate('InvoiceDocument.add.failure')); } } $this->gvars['invoice'] = $invoice; $this->gvars['InvoiceDocumentNewForm'] = $invoiceDocumentNewForm->createView(); $this->gvars['docs'] = $em->getRepository('AcfDataBundle:OnlineInvoiceDocument')->getAllByInvoice($invoice); $this->gvars['pagetitle'] = $this->translate('pagetitle.myinvoice.edit', array('%invoice%' => $invoice->getRef())); $this->gvars['pagetitle_txt'] = $this->translate('pagetitle.myinvoice.edit.txt', array('%invoice%' => $invoice->getRef())); return $this->renderResponse('AcfSecurityBundle:MyInvoice:edit.html.twig', $this->gvars); } } catch (\Exception $e) { $logger = $this->getLogger(); $logger->addCritical($e->getLine() . ' ' . $e->getMessage() . ' ' . $e->getTraceAsString()); } return $this->redirect($urlFrom); }
/** * Add doc * * @param OnlineInvoiceDocument $doc * * @return OnlineInvoice */ public function addDoc(OnlineInvoiceDocument $doc) { $this->docs[] = $doc; $doc->setInvoice($this); return $this; }