Ejemplo n.º 1
0
 /**
  * Initializes invoice data.
  * This method is equivalent to the old getInvoice()
  */
 protected function _initData()
 {
     $invoices = new SimpleInvoices_Db_Table_Invoices();
     $invoiceItems = new SimpleInvoices_Db_Table_InvoiceItems();
     $payments = new SimpleInvoices_Db_Table_Payment();
     $this->_data = $invoices->getInvoice($this->_id);
     if (!is_array($this->_data)) {
         require_once 'SimpleInvoices/Exception.php';
         throw new SimpleInvoices_Exception('Invalid invoice identifier.');
     }
     // I unset the ID as I don't want it to be present in inserts or updates.
     unset($this->_data['id']);
     $this->_outData = array();
     $this->_outData['calc_date'] = date('Y-m-d', strtotime($this->_data['date']));
     $this->_outData['date'] = siLocal::date($this->_data['date']);
     $this->_outData['total'] = $invoiceItems->getInvoiceTotal($this->_id);
     $this->_outData['gross'] = $invoiceItems->getGrossForInvoice($this->_id);
     $this->_outData['paid'] = $payments->getPaidAmountForInvoice($this->_id);
     $this->_outData['owing'] = $this->_outData['total'] - $this->_outData['paid'];
     if (isset($this->_data['inv_status'])) {
         // This seems to be a thing of the past.
         // I think we could delete the whole "if".
         $this->_outData['status'] = $this->_data['inv_status'];
     } else {
         $this->_outData['status'] = '';
     }
     #invoice total tax
     $result = $invoiceItems->getTotals($this->_id);
     //$invoice['total'] = number_format($result['total'],2);
     $this->_outData['total_tax'] = $result['total_tax'];
     $this->_outData['tax_grouped'] = taxesGroupedForInvoice($id);
 }