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;
 }
Beispiel #2
0
 public function setFormValues(Company $company)
 {
     if ($company) {
         $this->get('name')->setValue($company->getName());
         $this->get('regNo')->setValue($company->getRegNo());
         $this->get('kmkrNo')->setValue($company->getKmkrNo());
         $this->get('address')->setValue($company->getAddress());
         $this->get('zip')->setValue($company->getZip());
         $this->get('country')->setValue($company->getCountry());
         $this->get('city')->setValue($company->getZip());
         $this->get('url')->setValue($company->getUrl());
         $this->get('phone')->setValue($company->getPhone());
         $this->get('email')->setValue($company->getEmail());
         $this->get('mob')->setValue($company->getMob());
     }
     return $this;
 }
 public function assembleBanksArrayFromCompany(Company $company)
 {
     $bankRowsArray = array();
     if (count($company->getBanks()) > 0) {
         foreach ($company->getBanks() as $bank) {
             /* @var $bank \Application\Entity\Bank */
             $bankRowsArray[] = $this->createBankArrayFromBank($bank);
         }
     }
     return $bankRowsArray;
 }
Beispiel #4
0
 private function getBankCodeByIban($data, Company $company = null)
 {
     $ibanValidator = new Iban();
     $ibanValidator->setCountryCode('EE');
     $iban = '';
     $bankCode = null;
     foreach ($company->getBanks() as $bank) {
         /* @var $bank \Application\Entity\Bank */
         if (isset($data[12])) {
             $iban = $data[12];
             if (!$ibanValidator->isValid($iban)) {
                 $iban = IbanConverter::bban2iban($iban);
             }
             if ($iban == $bank->getIban()) {
                 $bankCode = Bank::BANK_KREDIIDIPANK;
                 return $bankCode;
             }
         }
         $iban = $data[0];
         if (!$ibanValidator->isValid($iban)) {
             $iban = IbanConverter::bban2iban($iban);
         }
         if ($iban == $bank->getIban()) {
             $bankCode = $bank->getCode();
             return $bankCode;
         }
     }
     return $bankCode;
 }