コード例 #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
 /**
  * @Route("/add", name="estimate_add")
  * @Template("SiwappEstimateBundle:Estimate:edit.html.twig")
  */
 public function addAction(Request $request)
 {
     $em = $this->getDoctrine()->getManager();
     $estimate = new Estimate();
     $estimate->addItem(new Item());
     $terms = $em->getRepository('SiwappConfigBundle:Property')->get('legal_terms');
     if ($terms) {
         $estimate->setTerms($terms);
     }
     $form = $this->createForm(EstimateType::class, $estimate, ['action' => $this->generateUrl('estimate_add')]);
     $form->handleRequest($request);
     if ($form->isValid()) {
         $em->persist($estimate);
         $em->flush();
         $this->addTranslatedMessage('flash.added');
         return $this->redirect($this->generateUrl('estimate_edit', array('id' => $estimate->getId())));
     }
     return array('form' => $form->createView(), 'entity' => $estimate, 'currency' => $em->getRepository('SiwappConfigBundle:Property')->get('currency'));
 }