Example #1
0
 public function cloneDocument(Document $document)
 {
     $auth = $this->getServiceLocator()->get('zfcuser_auth_service');
     if ($auth->hasIdentity()) {
         $user = $auth->getIdentity();
     }
     if ($document instanceof Document\Invoice) {
         $newDocument = new Document\Invoice();
     }
     $newDocument->setDeadlineDays($document->getDeadlineDays());
     $newDocument->setCustomer($document->getCustomer());
     $newDocument->setPaymentType($document->getPaymentType());
     $newDocument->setCreatedBy($user);
     $newDocument->setAmountTax($document->getAmountTax());
     $newDocument->setTaxAmount($document->getAmountTax());
     $newDocument->setAmount($document->getAmount());
     $newDocument->setDocumentDate(new \DateTime());
     $newDocument->setComment($document->getComment());
     $newDocument->setDelayPercent($document->getDelayPercent());
     $newDocument->setPrefix($document->getPrefix());
     $newDocument->setVat($document->getVat());
     $newDocument = $this->saveObject($newDocument);
     foreach ($document->getRows() as $row) {
         /* @var $row \Application\Entity\Document\Row */
         if ($row) {
             $newRow = new Document\Row();
             $newRow->setVat($row->getVat());
             $newRow->setWarehouse($row->getWarehouse());
             $newRow->setAmount($row->getAmount());
             $newRow->setArticle($row->getArticle());
             $newRow->setBarCode($row->getBarCode());
             $newRow->setCode($row->getCode());
             $newRow->setDescription($row->getDescription());
             $newRow->setName($row->getName());
             $newRow->setPrice($row->getPrice());
             $newRow->setQuantity($row->getQuantity());
             $newRow->setUom($row->getUom());
             $newRow->setDocument($newDocument);
             $this->saveObject($newRow);
         }
     }
     return $newDocument;
 }
Example #2
0
 private function saveInvoiceRows(Document $invoice, array $data)
 {
     if (isset($data['names'])) {
         foreach ($data['names'] as $key => $value) {
             if ($data['rowIds'][$key] > 0) {
                 $row = $this->getRowById($data['rowIds'][$key]);
             } else {
                 $row = new Row();
             }
             if (!$row->getDocument()) {
                 $row->setDocument($invoice);
             }
             $row->setName($value);
             if (isset($data['articleIds'][$key])) {
                 $article = $this->articleService->getArticleById($data['articleIds'][$key]);
                 if ($article) {
                     $row->setArticle($article);
                 }
             }
             if (isset($data['uomIds'][$key])) {
                 $uom = $this->settingsService->getUomById($data['uomIds'][$key]);
                 if ($uom) {
                     $row->setUom($uom);
                 }
             }
             if (isset($data['vatIds'][$key])) {
                 $vat = $this->settingsService->getVatById($data['vatIds'][$key]);
                 if ($vat) {
                     $row->setVat($vat);
                 }
             }
             if (isset($data['quantities'][$key])) {
                 $row->setQuantity($data['quantities'][$key]);
             }
             if (isset($data['prices'][$key])) {
                 $row->setPrice($data['prices'][$key]);
             }
             if (isset($data['totals'][$key])) {
                 $row->setAmount($data['totals'][$key]);
             }
             if (isset($data['vatAmounts'][$key])) {
                 $row->setVatAmount($data['vatAmounts'][$key]);
             }
             if (isset($data['vatValues'][$key])) {
                 $row->setVatValue($data['vatValues'][$key]);
             }
             if (!$data['rowIds'][$key] > 0) {
                 $invoice->addRow($row);
             }
         }
     }
     return $this->saveInvoice($invoice);
 }