Exemplo n.º 1
0
 /**
  * @param Form $form
  */
 public function configure(Form $form)
 {
     $entity = $form->data;
     $form->addGroup('Supplier');
     $form->addManyToOne('supplier', 'person')->addRule($form::FILLED);
     $form->addGroup('Customer');
     $form->addManyToOne('customer', 'person')->addRule($form::FILLED);
     $form->addGroup('Billing information');
     $form->addText('identification', 'Identification');
     $form->addText('amount', 'Amount')->addRule($form::FILLED)->addRule($form::FLOAT);
     $form->addManyToOne('payment', 'Payment');
     $form->addSelect('type', 'Type')->setItems(InvoiceEntity::getTypes());
     $form->addSelect('state', 'State')->setItems(InvoiceEntity::getStates());
     $form->addText('constantSymbol', 'Constant sb.');
     $form->addText('variableSymbol', 'Variable sb.');
     $form->addText('specificSymbol', 'Specific sb.');
     $group = $form->addGroup('Items');
     $recipients = $form->addMany('items', function (Container $container) use($group, $form) {
         $container->setCurrentGroup($group);
         $container->addText('name', 'Name')->addRule($form::FILLED);
         $container->addText('unitValue', 'Unit value')->addRule($form::FILLED)->addRule($form::FLOAT);
         $container->addText('units', 'Units')->addRule($form::FILLED)->addRule($form::INTEGER);
         $container->addText('qUnit', 'Quantity unit')->addRule($form::FILLED);
         $container->addText('tax', 'Tax')->addRule($form::FLOAT);
         $container->addCheckbox('unitValueIsTaxed', 'Value is taxed');
         $container->addSubmit('remove', 'Remove')->addRemoveOnClick();
     }, function () use($entity) {
         return new ItemEntity($entity);
     });
     $recipients->setCurrentGroup($group);
     $recipients->addSubmit('add', 'Add item')->addCreateOnClick();
     $form->setCurrentGroup();
     $form->addSaveButton('Save');
 }
 public function invoke()
 {
     $translator = $this->translator;
     $admin = new AdminGrid($this->invoiceRepository);
     $table = $admin->getTable();
     $table->setTranslator($this->translator);
     $table->setDefaultSort(array('date' => 'DESC'));
     $table->addColumnText('identification', 'ID');
     $table->addColumnText('revisionCounter', 'Revision');
     $table->addColumnDate('date', 'Date');
     $table->addColumnText('supplier', 'Supplier')->setCustomRender(function (InvoiceEntity $invoiceEntity) {
         return $invoiceEntity->getSupplier()->getAccount()->getPerson();
     });
     $table->addColumnText('customer', 'Customer')->setCustomRender(function (InvoiceEntity $invoiceEntity) {
         return $invoiceEntity->getCustomer();
     });
     $table->addColumnText('amount', 'Amount');
     $table->addColumnText('state', 'State')->setCustomRender(function (InvoiceEntity $invoiceEntity) use($translator) {
         $states = InvoiceEntity::getStates();
         return $translator->translate($states[$invoiceEntity->getState()]);
     });
     $table->addAction('generate', 'Generate ID')->setCustomRender(function (InvoiceEntity $invoiceEntity, $element) {
         if ($invoiceEntity->getIdentification()) {
             $element->class[] = 'disabled';
         }
         return $element;
     })->onClick[] = $this->generateClick;
     $table->addAction('generatePdf', 'Generate PDF')->onClick[] = $this->generatePdfClick;
     $table->addAction('downloadPdf', 'Download PDF')->setCustomRender(function (InvoiceEntity $invoiceEntity, $element) {
         if (!count($invoiceEntity->revisions)) {
             $element->class[] = 'disabled';
         }
         return $element;
     })->onClick[] = $this->downloadPdfClick;
     $table->addAction('show', 'Preview')->onClick[] = $this->showClick;
     $table->addAction('pdf', 'PDF')->onClick[] = $this->pdfClick;
     $table->addAction('edit', 'Edit')->getElementPrototype()->class[] = 'ajax';
     $form = $admin->createForm($this->invoiceFormFactory, 'Payment', NULL, \CmsModule\Components\Table\Form::TYPE_FULL);
     $admin->connectFormWithAction($form, $table->getAction('edit'), $admin::MODE_PLACE);
     // Toolbar
     $toolbar = $admin->getNavbar();
     $toolbar->addSection('new', 'Create', 'file');
     $admin->connectFormWithNavbar($form, $toolbar->getSection('new'), $admin::MODE_PLACE);
     $table->addAction('delete', 'Delete')->setCustomRender(function (InvoiceEntity $invoiceEntity, $element) {
         $element->class[] = 'ajax';
         if ($invoiceEntity->getState() !== InvoiceEntity::STATE_NEW) {
             $element->class[] = 'disabled';
         }
         return $element;
     });
     $admin->connectActionAsDelete($table->getAction('delete'));
     return $admin;
 }