public function testGetDiscountAmount() { $item = new Item(); $item->setUnitaryCost(80); $item->setQuantity(1); $this->assertEquals(0, $item->getDiscountAmount()); $item->setDiscount(10); $this->assertEquals(8, $item->getDiscountAmount()); $item->setDiscount(2); $this->assertEquals(1.6, $item->getDiscountAmount()); }
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; }
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); } }