Esempio n. 1
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());
 }
Esempio n. 2
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;
 }
Esempio n. 3
0
 public function testCheckAmounts()
 {
     $invoice = new Invoice();
     $item = new Item();
     $item->setUnitaryCost(80);
     $item->setQuantity(1);
     $invoice->addItem($item);
     // test amounts calculation
     $invoice->checkAmounts();
     $this->assertEquals(80, $invoice->getBaseAmount());
     $this->assertEquals(80, $invoice->getNetAmount());
     $this->assertEquals(0, $invoice->getTaxAmount());
     $this->assertEquals(80, $invoice->getGrossAmount());
     // Add the same item again.
     $invoice->addItem($item);
     $invoice->checkAmounts();
     $this->assertEquals(0, $invoice->getTaxAmount());
     $this->assertEquals(160, $invoice->getGrossAmount());
 }
Esempio n. 4
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;
 }
 public function findByItem(Item $item)
 {
     $qb = $this->getEntityManager()->createQueryBuilder();
     $qb->select('i')->from($this->getEntityName(), 'i')->join('i.items', 'ii')->where('ii.id = ?1')->setParameter(1, $item->getId());
     return $qb->getQuery()->getResult();
 }
Esempio n. 6
0
 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);
     }
 }