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;
 }