예제 #1
0
 public function generate(Estimate $estimate)
 {
     $invoice = new Invoice();
     $invoice->setCustomerName($estimate->getCustomerName());
     $invoice->setCustomerEmail($estimate->getCustomerEmail());
     $invoice->setCustomerIdentification($estimate->getCustomerIdentification());
     $invoice->setContactPerson($estimate->getContactPerson());
     $invoice->setInvoicingAddress($estimate->getInvoicingAddress());
     $invoice->setShippingAddress($estimate->getShippingAddress());
     $invoice->setSeries($estimate->getSeries());
     foreach ($estimate->getItems() as $item) {
         $invoiceItem = new Item();
         $invoiceItem->setDescription($item->getDescription());
         $invoiceItem->setQuantity($item->getQuantity());
         $invoiceItem->setDiscount($item->getDiscount());
         $invoiceItem->setUnitaryCost($item->getUnitaryCost());
         foreach ($item->getTaxes() as $tax) {
             $invoiceItem->addTax($tax);
         }
         $invoice->addItem($invoiceItem);
     }
     $invoice->setNotes($estimate->getNotes());
     $invoice->setTerms($estimate->getTerms());
     $this->em->persist($invoice);
     $this->em->flush();
     return $invoice;
 }
예제 #2
0
 public function generatePending(RecurringInvoice $recurring)
 {
     $generated = 0;
     while ($recurring->countPendingInvoices($recurring) > 0) {
         $invoice = new Invoice();
         $invoice->setCustomerName($recurring->getCustomerName());
         $invoice->setCustomerEmail($recurring->getCustomerEmail());
         $invoice->setCustomerIdentification($recurring->getCustomerIdentification());
         $invoice->setContactPerson($recurring->getContactPerson());
         $invoice->setInvoicingAddress($recurring->getInvoicingAddress());
         $invoice->setShippingAddress($recurring->getShippingAddress());
         $invoice->setSeries($recurring->getSeries());
         foreach ($recurring->getItems() as $item) {
             $invoiceItem = new Item();
             $invoiceItem->setDescription($item->getDescription());
             $invoiceItem->setQuantity($item->getQuantity());
             $invoiceItem->setDiscount($item->getDiscount());
             $invoiceItem->setUnitaryCost($item->getUnitaryCost());
             foreach ($item->getTaxes() as $tax) {
                 $invoiceItem->addTax($tax);
             }
             $invoice->addItem($invoiceItem);
         }
         $invoice->setNotes($recurring->getNotes());
         $invoice->setTerms($recurring->getTerms());
         if ($d = $recurring->getDaysToDue()) {
             $invoice->setDueDate(new \DateTime('+ ' . $d . ' days'));
         }
         $recurring->addInvoice($invoice);
         $generated++;
     }
     $recurring->setLastExecutionDate(new \DateTime());
     $this->em->persist($recurring);
     $this->em->flush();
     return $generated;
 }