/**
  * Render invoice PDF
  *
  * @param void
  * @return null
  */
 function pdf()
 {
     if ($this->active_invoice->isNew()) {
         $this->httpError(HTTP_ERR_NOT_FOUND);
     }
     // if
     if ($this->active_invoice->getStatus() == INVOICE_STATUS_DRAFT) {
         $this->httpError(HTTP_ERR_NOT_FOUND);
     }
     // if
     require_once INVOICING_MODULE_PATH . '/models/InvoicePdf.class.php';
     InvoicePDF::download($this->active_invoice, lang('#:invoice_id.pdf', array('invoice_id' => $this->active_invoice->getName())));
     die;
 }
Пример #2
0
 public function encodeInvoice(Invoice $invoice)
 {
     $data = ['id' => $invoice->getId(), 'number' => $invoice->getNumber(), 'name' => $invoice->getName(), 'created' => $invoice->getCreated(), 'delivered' => $invoice->getDelivered(), 'due' => $invoice->getDue(), 'status' => $invoice->getStatus(), 'variable_symbol' => $invoice->getVariableSymbol(), 'constant_symbol' => $invoice->getConstantSymbol(), 'description' => $invoice->getDescription(), 'items' => $this->encodeItems($invoice->getItems()), 'price' => $invoice->getPrice(), 'price_total' => $invoice->getPriceTotal(), 'currency' => $invoice->getCurrency()];
     if ($invoice->getClient()) {
         $data['client'] = $this->encodeClient($invoice->getClient());
     }
     if ($invoice->getShippingAddress()) {
         $data['shipping_address'] = $this->encodeAddress($invoice->getShippingAddress());
     }
     if ($invoice->getDiscount() && $invoice->getDiscount()->getType() != 'none') {
         $data['discount'] = ['type' => $invoice->getDiscount()->getType(), 'value' => $invoice->getDiscount()->getValue()];
     }
     return json_encode(['invoice' => $data]);
 }
 public function executeCommission(sfWebRequest $request)
 {
     $requestparams = $request->getParameter("invoice");
     $day = $requestparams["date"]["day"];
     $month = $requestparams["date"]["month"];
     $year = $requestparams["date"]["year"];
     //if no date, date is today. else date is date given
     if (!$year or !$month or !$day) {
         $date = MyDateTime::today();
     } else {
         $date = new MyDateTime($year, $month, $day, 0, 0, 0);
     }
     $invoice = new Invoice();
     $invoice->setDate($date->getstartofmonth()->tomysql());
     $purchase = new Purchase();
     $purchase->setDate($date->getendofmonth()->tomysql());
     $this->date = $date;
     $this->form = new InvoiceForm($invoice);
     $this->toform = new PurchaseForm($purchase);
     //set up an array of employees indexed by employee id
     $this->rawemployees = Doctrine_Query::create()->from('Employee e')->where('e.commission > 0 ')->execute();
     $this->employees = array();
     foreach ($this->rawemployees as $employee) {
         $this->employees[$employee->getId()] = $employee;
     }
     $this->empinvoices = array();
     foreach ($this->employees as $employee) {
         $this->empinvoices[$employee->getId()] = Doctrine_Query::create()->from('Invoice i, i.Employee e, i.Invoicedetail id, id.Product p')->where('i.salesman_id=' . $employee->getId())->andwhere('i.date >= "' . $invoice->getDate() . '"')->andwhere('i.date <=  "' . $purchase->getDate() . '"')->orWhere('i.technician_id=' . $employee->getId())->andwhere('i.date >= "' . $invoice->getDate() . '"')->andwhere('i.date <=  "' . $purchase->getDate() . '"')->orderBy('i.invno')->execute();
     }
     $commissiontotals = array();
     foreach ($this->empinvoices as $empid => $employeedata) {
         $totalcommission = 0;
         foreach ($employeedata as $invoice) {
             if ($invoice->getStatus() == "Paid") {
                 $totalcommission += $invoice->getCommissionTotal($this->employees[$empid]);
             }
         }
         $commissiontotals[$empid] = $totalcommission;
     }
     $this->commissiontotals = $commissiontotals;
     $this->grandtotalcommission = 0;
     foreach ($commissiontotals as $total) {
         $this->grandtotalcommission += $total;
     }
 }
 /**
  * Set invoice
  *
  * @param Invoice $invoice
  * @return void
  */
 function setInvoice($invoice)
 {
     $this->invoice = $invoice;
     $this->invoice_label = $this->invoice->getStatus() == INVOICE_STATUS_DRAFT ? lang('PRO FORMA :num', array('num' => $this->invoice->getName(true)), true, $this->invoice->getLanguage()) : lang('INVOICE :num', array('num' => $this->invoice->getName(true)), true, $this->invoice->getLanguage());
 }