예제 #1
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);
 }