コード例 #1
0
 /**
  * @Route("/new", name="invoice_add")
  * @Template("SiwappInvoiceBundle:Invoice:edit.html.twig")
  */
 public function newAction(Request $request)
 {
     $em = $this->getDoctrine()->getManager();
     $invoice = new Invoice();
     $invoice->addItem(new Item());
     $terms = $em->getRepository('SiwappConfigBundle:Property')->get('legal_terms');
     if ($terms) {
         $invoice->setTerms($terms);
     }
     $form = $this->createForm('Siwapp\\InvoiceBundle\\Form\\InvoiceType', $invoice, ['action' => $this->generateUrl('invoice_add')]);
     $form->handleRequest($request);
     if ($form->isValid()) {
         if ($request->request->has('save_draft')) {
             $invoice->setStatus(Invoice::DRAFT);
         } elseif ($request->request->has('save')) {
             $invoice->setStatus(Invoice::OPENED);
         }
         $em->persist($invoice);
         $em->flush();
         $this->addTranslatedMessage('flash.added');
         return $this->redirect($this->generateUrl('invoice_edit', array('id' => $invoice->getId())));
     }
     return array('form' => $form->createView(), 'entity' => $invoice, 'currency' => $em->getRepository('SiwappConfigBundle:Property')->get('currency'));
 }
コード例 #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;
 }
コード例 #3
0
ファイル: InvoiceTest.php プロジェクト: siwapp/siwapp-sf3
 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());
 }
コード例 #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;
 }
コード例 #5
0
 public function findByInvoice(Invoice $invoice)
 {
     $qb = $this->getEntityManager()->createQueryBuilder();
     $qb->select('ri')->from(RecurringInvoice::class, 'ri')->join('ri.invoices', 'i')->where('i.id = ?1')->setParameter(1, $invoice->getId());
     return $qb->getQuery()->getResult();
 }