/** * Form builder * * @param FormBuilderInterface $builder * @param array $options * * @return null */ public function buildForm(FormBuilderInterface $builder, array $options) { $this->mbpurchase = $options['monthlybalance']; if (null == $this->mbpurchase) { $builder->add('withholding', EntityType::class, array('label' => 'Buy.withholding.label', 'class' => 'AcfDataBundle:Withholding', 'query_builder' => function (WithholdingRepository $wr) { return $wr->createQueryBuilder('w')->orderBy('w.label', 'ASC'); }, 'choice_label' => 'label', 'multiple' => false, 'by_reference' => true, 'required' => true)); } else { $companyId = $this->mbpurchase->getCompany()->getId(); $builder->add('withholding', EntityType::class, array('label' => 'Buy.withholding.label', 'class' => 'AcfDataBundle:Withholding', 'query_builder' => function (WithholdingRepository $wr) use($companyId) { return $wr->createQueryBuilder('w')->join('w.company', 'c')->where('c.id = :cid')->setParameter('cid', $companyId)->orderBy('w.label', 'ASC'); }, 'choice_label' => 'label', 'multiple' => false, 'by_reference' => true, 'required' => true)); } }
protected function traceEntity(MBPurchase $cloneMBPurchase, MBPurchase $mbpurchase) { $curUser = $this->getSecurityTokenStorage()->getToken()->getUser(); $trace = new Trace(); $trace->setActionId($mbpurchase->getId()); $trace->setActionType(Trace::AT_UPDATE); $trace->setUserId($curUser->getId()); $trace->setCompanyId($mbpurchase->getCompany()->getId()); $trace->setUserFullname($curUser->getFullName()); if (!$this->hasRole('ROLE_SUPERADMIN')) { if (!$this->hasRole('ROLE_ADMIN')) { $trace->setUserType(Trace::UT_CLIENT); } else { $trace->setUserType(Trace::UT_ADMIN); } } else { $trace->setUserType(Trace::UT_SUPERADMIN); } $tableBegin = ': <br><table class="table table-bordered table-condensed table-hover table-striped">'; $tableBegin .= '<thead><tr><th class="text-left">' . $this->translate('Entity.field') . '</th>'; $tableBegin .= '<th class="text-left">' . $this->translate('Entity.oldVal') . '</th>'; $tableBegin .= '<th class="text-left">' . $this->translate('Entity.newVal') . '</th></tr></thead><tbody>'; $tableEnd = '</tbody></table>'; $trace->setActionEntity(Trace::AE_MBPURCHASE); $trace->setActionId2($mbpurchase->getCompany()->getId()); $trace->setActionEntity2(Trace::AE_COMPANY); $msg = ''; if ($cloneMBPurchase->getCount() != $mbpurchase->getCount()) { $msg .= '<tr><td>' . $this->translate('MBPurchase.count.label') . '</td><td>'; if ($cloneMBPurchase->getCount() == null) { $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>'; } else { $msg .= $cloneMBPurchase->getCount(); } $msg .= '</td><td>'; if ($mbpurchase->getCount() == null) { $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>'; } else { $msg .= $mbpurchase->getCount(); } $msg .= '</td></tr>'; } if (\count(\array_diff($mbpurchase->getDocs()->toArray(), $cloneMBPurchase->getDocs()->toArray())) != 0 || \count(\array_diff($cloneMBPurchase->getDocs()->toArray(), $mbpurchase->getDocs()->toArray())) != 0) { $msg .= '<tr><td>' . $this->translate('MBPurchase.docs.label') . '</td><td>'; if (\count($cloneMBPurchase->getDocs()) == 0) { $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>'; } else { $msg .= '<ul>'; foreach ($cloneMBPurchase->getDocs() as $doc) { $msg .= '<li><a href="' . $this->generateUrl('_admin_doc_editGet', array('uid' => $doc->getId())) . '">' . $doc->getOriginalName() . '</a></li>'; } $msg .= '<ul>'; } $msg .= '</td><td>'; if (\count($mbpurchase->getDocs()) == 0) { $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>'; } else { $msg .= '<ul>'; foreach ($mbpurchase->getDocs() as $doc) { $msg .= '<li><a href="' . $this->generateUrl('_admin_doc_editGet', array('uid' => $doc->getId())) . '">' . $doc->getOriginalName() . '</a></li>'; } $msg .= '<ul>'; } $msg .= '</td></tr>'; } if ($msg != '') { $msg = $tableBegin . $msg . $tableEnd; $trace->setMsg($this->translate('MBPurchase.traceEdit', array('%mbpurchase%' => $mbpurchase->getRef(), '%company%' => $mbpurchase->getCompany()->getCorporateName())) . $msg); $trace->setDtCrea(new \DateTime('now')); $em = $this->getEntityManager(); $em->persist($trace); $em->flush(); } }
/** * Form builder * * @param FormBuilderInterface $builder * @param array $options * * @return null */ public function buildForm(FormBuilderInterface $builder, array $options) { $this->mbpurchase = $options['monthlybalance']; if (null == $this->mbpurchase) { $builder->add('monthlyBalance', EntityType::class, array('label' => 'Buy.monthlyBalance.label', 'class' => 'AcfDataBundle:MBPurchase', 'query_builder' => function (MBPurchaseRepository $mbsr) { return $mbsr->createQueryBuilder('mbs')->orderBy('mbs.ref', 'ASC'); }, 'choice_label' => 'ref', 'multiple' => false, 'by_reference' => true, 'required' => true)); } else { $mbpurchaseId = $this->mbpurchase->getId(); $builder->add('monthlyBalance', EntityidType::class, array('label' => 'Buy.monthlyBalance.label', 'class' => 'AcfDataBundle:MBPurchase', 'query_builder' => function (MBPurchaseRepository $mbsr) use($mbpurchaseId) { return $mbsr->createQueryBuilder('mbs')->where('mbs.id = :id')->setParameter('id', $mbpurchaseId)->orderBy('mbs.ref', 'ASC'); }, 'choice_label' => 'id', 'multiple' => false, 'by_reference' => true, 'required' => true)); } $builder->add('dtActivation', DateType::class, array('label' => 'Buy.dtActivation.label', 'widget' => 'single_text', 'format' => 'yyyy-MM-dd')); $builder->add('bill', TextType::class, array('label' => 'Buy.bill.label', 'required' => false)); if (null == $this->mbpurchase) { $builder->add('relation', EntityType::class, array('label' => 'Buy.relation.label', 'class' => 'AcfDataBundle:Supplier', 'query_builder' => function (SupplierRepository $sr) { return $sr->createQueryBuilder('s')->orderBy('s.label', 'ASC'); }, 'choice_label' => 'label', 'multiple' => false, 'by_reference' => true, 'required' => true)); } else { $companyId = $this->mbpurchase->getCompany()->getId(); $builder->add('relation', EntityType::class, array('label' => 'Buy.relation.label', 'class' => 'AcfDataBundle:Supplier', 'query_builder' => function (SupplierRepository $sr) use($companyId) { return $sr->createQueryBuilder('s')->join('s.company', 'c')->where('c.id = :cid')->setParameter('cid', $companyId)->orderBy('s.label', 'ASC'); }, 'choice_label' => 'label', 'multiple' => false, 'by_reference' => true, 'required' => true)); } $builder->add('label', TextType::class, array('label' => 'Buy.label.label')); $builder->add('devise', CurrencyType::class, array('label' => 'Buy.devise.label')); $builder->add('conversionRate', NumberType::class, array('label' => 'Buy.conversionRate.label')); $builder->add('vat', NumberType::class, array('label' => 'Buy.vat.label', 'required' => false)); $builder->add('stamp', NumberType::class, array('label' => 'Buy.stamp.label', 'required' => false)); $builder->add('balanceTtc', NumberType::class, array('label' => 'Buy.balanceTtc.label', 'required' => false)); $builder->add('balanceNet', NumberType::class, array('label' => 'Buy.balanceNet.label', 'required' => false)); $builder->add('vatDevise', NumberType::class, array('label' => 'Buy.vatDevise.label', 'required' => false)); $builder->add('stampDevise', NumberType::class, array('label' => 'Buy.stampDevise.label', 'required' => false)); $builder->add('balanceTtcDevise', NumberType::class, array('label' => 'Buy.balanceTtcDevise.label', 'required' => false)); $builder->add('balanceNetDevise', NumberType::class, array('label' => 'Buy.balanceNetDevise.label', 'required' => false)); $builder->add('regime', ChoiceType::class, array('label' => 'Buy.regime.label', 'choices_as_values' => true, 'choices' => Buy::choiceRegime(), 'attr' => array('choice_label_trans' => true))); if (null == $this->mbpurchase) { $builder->add('withholding', EntityType::class, array('label' => 'Buy.withholding.label', 'class' => 'AcfDataBundle:Withholding', 'query_builder' => function (WithholdingRepository $wr) { return $wr->createQueryBuilder('w')->orderBy('w.label', 'ASC'); }, 'choice_label' => 'label', 'multiple' => false, 'by_reference' => true, 'required' => true)); } else { $companyId = $this->mbpurchase->getCompany()->getId(); $builder->add('withholding', EntityType::class, array('label' => 'Buy.withholding.label', 'class' => 'AcfDataBundle:Withholding', 'query_builder' => function (WithholdingRepository $wr) use($companyId) { return $wr->createQueryBuilder('w')->join('w.company', 'c')->where('c.id = :cid')->setParameter('cid', $companyId)->orderBy('w.label', 'ASC'); }, 'choice_label' => 'label', 'multiple' => false, 'by_reference' => true, 'required' => true)); } if (null == $this->mbpurchase) { $builder->add('nature', EntityType::class, array('label' => 'Buy.nature.label', 'class' => 'AcfDataBundle:CompanyNature', 'query_builder' => function (CompanyNatureRepository $cnr) { return $cnr->createQueryBuilder('cn')->orderBy('cn.label', 'ASC'); }, 'choice_label' => 'label', 'multiple' => false, 'by_reference' => true, 'required' => true)); } else { $companyId = $this->mbpurchase->getCompany()->getId(); $builder->add('nature', EntityType::class, array('label' => 'Buy.nature.label', 'class' => 'AcfDataBundle:CompanyNature', 'query_builder' => function (CompanyNatureRepository $cnr) use($companyId) { return $cnr->createQueryBuilder('cn')->join('cn.company', 'c')->where('c.id = :cid')->setParameter('cid', $companyId)->orderBy('cn.label', 'ASC'); }, 'choice_label' => 'label', 'multiple' => false, 'by_reference' => true, 'required' => true)); } $builder->add('paymentType', ChoiceType::class, array('label' => 'Buy.paymentType.label', 'choices_as_values' => true, 'choices' => Buy::choicePaymentType(), 'attr' => array('choice_label_trans' => true))); $builder->add('transactionStatus', ChoiceType::class, array('label' => 'Buy.transactionStatus.label', 'choices_as_values' => true, 'choices_as_values' => true, 'choices' => Buy::choiceTransactionStatus(), 'expanded' => true, 'attr' => array('choice_label_trans' => true))); $builder->add('dtPayment', DateType::class, array('label' => 'Buy.dtPayment.label', 'widget' => 'single_text', 'format' => 'yyyy-MM-dd', 'required' => false)); if (null == $this->mbpurchase) { $builder->add('account', EntityType::class, array('label' => 'Buy.account.label', 'class' => 'AcfDataBundle:Account', 'query_builder' => function (AccountRepository $ar) { return $ar->createQueryBuilder('a')->orderBy('a.label', 'ASC'); }, 'choice_label' => 'label', 'multiple' => false, 'by_reference' => true, 'required' => true)); } else { $companyId = $this->mbpurchase->getCompany()->getId(); $builder->add('account', EntityType::class, array('label' => 'Buy.account.label', 'class' => 'AcfDataBundle:Account', 'query_builder' => function (AccountRepository $ar) use($companyId) { return $ar->createQueryBuilder('a')->join('a.company', 'c')->where('c.id = :cid')->setParameter('cid', $companyId)->orderBy('a.label', 'ASC'); }, 'choice_label' => 'label', 'multiple' => false, 'by_reference' => true, 'required' => true)); } $builder->add('docs', CollectionType::class, array('label' => 'Buy.docs.label', 'entry_type' => BuyDocTForm::class, 'allow_add' => true, 'allow_delete' => true, 'by_reference' => false, 'mapped' => false, 'constraints' => new Valid())); $builder->add('otherInfos', TextareaType::class, array('label' => 'Buy.otherInfos.label', 'required' => false)); }