/** * 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); }
function getInvoice($id) { global $dbh; global $config; global $auth_session; $SI_INVOICES = new SimpleInvoices_Db_Table_Invoices(); $SI_INVOICE_ITEMS = new SimpleInvoices_Db_Table_InvoiceItems(); $invoice = $SI_INVOICES->getInvoice($id); $invoice['calc_date'] = date('Y-m-d', strtotime( $invoice['date'] ) ); $invoice['date'] = siLocal::date( $invoice['date'] ); $invoice['total'] = $SI_INVOICE_ITEMS->getInvoiceTotal($invoice['id']); $invoice['gross'] = invoice::getInvoiceGross($invoice['id']); $invoice['paid'] = calc_invoice_paid($invoice['id']); $invoice['owing'] = $invoice['total'] - $invoice['paid']; if (isset($invoice['inv_status'])) { // This seems to be a thing of the past. // I think we could delete the whole "if". $invoice['status'] = $invoice['inv_status']; } else { $invoice['status'] = ''; } #invoice total tax $result = $SI_INVOICE_ITEMS->getTotals($id); //$invoice['total'] = number_format($result['total'],2); $invoice['total_tax'] = $result['total_tax']; $invoice['tax_grouped'] = taxesGroupedForInvoice($id); return $invoice; }