Example #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;
 }
Example #2
0
 public function testGetGrossAmount()
 {
     $item = new Item();
     $tax = new Tax();
     $tax->setValue(20);
     $item->setUnitaryCost(80);
     $item->setQuantity(1);
     $item->addTax($tax);
     $this->assertEquals(96, $item->getGrossAmount());
 }
Example #3
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;
 }
 protected function addItemsAndTaxes(AbstractInvoice $invoice, array $row, \PDO $dbh)
 {
     $itemsSth = $dbh->prepare('SELECT * FROM item WHERE common_id=:id');
     $itemsSth->bindValue(':id', $row['id']);
     $itemsSth->execute();
     foreach ($itemsSth->fetchAll(\PDO::FETCH_ASSOC) as $itemRow) {
         $item = new Item();
         $item->setDescription($itemRow['description']);
         $item->setUnitaryCost($itemRow['unitary_cost']);
         $item->setQuantity($itemRow['quantity']);
         $item->setDiscount($itemRow['discount']);
         if ($itemRow['product_id']) {
             $item->setProduct($this->mapping['products'][$itemRow['product_id']]);
         }
         $itemTaxesSth = $dbh->prepare('SELECT * FROM item_tax WHERE item_id=:id');
         $itemTaxesSth->bindValue(':id', $itemRow['id']);
         $itemTaxesSth->execute();
         foreach ($itemTaxesSth->fetchAll(\PDO::FETCH_ASSOC) as $itemTaxRow) {
             $item->addTax($this->mapping['taxes'][$itemTaxRow['tax_id']]);
         }
         $invoice->addItem($item);
     }
 }