Exemplo n.º 1
0
 public function saveInvoice(Document\Invoice $invoice, Parameters $data = null, $layout = null)
 {
     $auth = $this->getServiceLocator()->get('zfcuser_auth_service');
     if ($auth->hasIdentity()) {
         $user = $auth->getIdentity();
     }
     $invoice->setCreatedBy($user);
     if ($data !== null) {
         $opencart = isset($data->opencart);
         $invoice->setOpencart($opencart);
         $invoice->setDocumentDate(\DateTime::createFromFormat('d.m.Y', $data->docDate));
         $invoice->setReferenceNumber($data->referenceNr);
         $invoice->setDeadlineDays($data->deadlineDays);
         $invoice->setDelayPercent($data->delayPercent);
         $invoice->setAmount($data->amount);
         $invoice->setComment($data->comment);
         $invoice->setPaymentType($data->paymentType);
         $company = $this->getOneObjectByField(Company::getClass(), 'id', $data->company);
         $invoice->setCompany($company);
         $invoice->setTaxAmount($data->taxAmount);
         $invoice->setAmountTax($data->amountTax);
         $warehouse = $this->getOneObjectByField(Vat::getClass(), 'id', $data->warehouse);
         $invoice->setWarehouse($warehouse);
         $customer = $this->getOneObjectByField(Customer::getClass(), 'id', $data->customer);
         $vat = $this->getOneObjectByField(Vat::getClass(), 'id', $data->vat);
         $invoice->setCustomer($customer);
         $invoice->setVat($vat);
         $this->saveObject($invoice);
         if (isset($data->saveAndConfirm) || isset($data->confirmedOutgoing)) {
             $type = $opencart ? Document\Number::TYPE_OPENCART_INVOICE : Document\Number::TYPE_INVOICE;
             $number = $this->getOneObjectByField(Document\Number::getClass(), 'type', $type);
             $invoice->setPrefix($number->getPrefix());
             $invoice->setDocumentNumber($this->generateInvoiceNo($opencart));
             if ($customer->getRegNo() !== null && $customer->getRegNo() !== '') {
                 $invoice->setReferenceNumber(BankLink::generateReferenceNumber($customer->getRegNo()) . $invoice->getId());
             } else {
                 $invoice->setReferenceNumber(BankLink::generateReferenceNumber($customer->getId()) . $invoice->getId());
             }
             $invoice->setConfirmed(true);
             $invoice->setStatus(Document\Invoice::STATUS_CONFIRMED);
             $this->saveInvoiceFile($invoice, $layout);
         }
     }
     $this->entityManager->persist($invoice);
     $this->entityManager->flush($invoice);
     return $invoice;
 }
Exemplo n.º 2
0
 public function testGetReferenceNumber()
 {
     $this->assertEquals('1234561', BankLink::generateReferenceNumber('123456'));
     $this->assertEquals('6543215', BankLink::generateReferenceNumber('654321'));
 }