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; }
public function getCustomerById($id) { return $this->entityManager->getRepository(Customer::getClass())->findOneBy(array('id' => $id)); }
public function getInDepthClientsAndSums(User $user) { $result = array(); $rawArray = $this->entityManager->getRepository(Invoice::getClass())->getInDepthClientsAndSums($user); foreach ($rawArray as $ar) { $res = array(); $client = $this->entityManager->getRepository(Customer::getClass())->findOneBy(array('id' => $ar['id'])); if ($client) { $res['client'] = $client; $res['sum'] = $ar['unpaid']; $result[] = $res; } } return $result; }