Example #1
0
 public function generateIdentification(InvoiceEntity $invoiceEntity)
 {
     $date = new \DateTime();
     $account = $invoiceEntity->getSupplier();
     $format = $account->getIdentificationFormat();
     $dateFrom = new \DateTime();
     if ($account->getIdentificationInterval() === AccountEntity::INTERVAL_YEAR) {
         $dateFrom->setTime(0, 0, 0);
         $dateFrom->setDate($dateFrom->format('Y'), 1, 1);
         $dateTo = \DateTime::createFromFormat('Y-m-d', intval($dateFrom->format('Y')) + 1 . '-01-01');
         $dateTo->setTime(0, 0, 0);
     } elseif ($account->getIdentificationInterval() === AccountEntity::INTERVAL_MONTH) {
         $dateFrom->setTime(0, 0, 0);
         $dateFrom->setDate($dateFrom->format('Y'), $dateFrom->format('m'), 1);
         $year = intval($dateFrom->format('Y'));
         $month = intval($dateFrom->format('m')) + 1;
         if ($month > 12) {
             $month = $month - 12;
             $year++;
         }
         $dateTo = \DateTime::createFromFormat('Y-m-d', $year . '-' . $month . '-01');
         $dateTo->setTime(0, 0, 0);
     } elseif ($account->getIdentificationInterval() === AccountEntity::INTERVAL_QUARTER) {
         $month = intval($dateFrom->format('m'));
         $year = intval($dateFrom->format('Y'));
         $dateFrom->setTime(0, 0, 0);
         $dateFrom->setDate($year, $month % 4 * 4, 0);
         $month = $month + 4;
         if ($month > 12) {
             $month = $month - 12;
             $year++;
         }
         $dateTo = \DateTime::createFromFormat('Y-m-d', $year . '-' . $month % 4 * 4 . '-01');
         $dateTo->setTime(0, 0, 0);
     }
     $qb = $this->invoiceRepository->createQueryBuilder('a')->select('COUNT(a.id)')->andWhere('a.identification IS NOT NULL')->andWhere('a.supplier = :supplier')->setParameter('supplier', $account->id);
     if (isset($dateTo)) {
         $qb = $qb->andWhere('a.date >= :dateFrom')->setParameter('dateFrom', $dateFrom)->andWhere('a.date < :dateTo')->setParameter('dateTo', $dateTo);
     }
     $identification = intval($qb->getQuery()->getSingleScalarResult()) + 1;
     if (preg_match_all('/\\?(\\d+)/is', $format, $matches)) {
         $number = $matches[1][0];
         $format = str_replace('?' . $number, sprintf('%0' . $number . 'd', $identification), $format);
     }
     $exDate = clone $date;
     $exDate->modify('+' . $account->getDue() . ' days');
     $invoiceEntity->setDate($date);
     $invoiceEntity->setExpirationDate($exDate);
     $invoiceEntity->setIdentification($date->format($format));
     $this->invoiceRepository->save($invoiceEntity);
 }
 /**
  * @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;
 }