public static function select($id) { global $logger; global $db; global $auth_session; $sql = "SELECT \n i.*,\n\t\t i.date as date_original, \n (SELECT CONCAT(p.pref_inv_wording,' ',i.index_id)) as index_name,\n p.pref_inv_wording AS preference,\n p.status\n FROM \n " . TB_PREFIX . "invoices i, \n " . TB_PREFIX . "preferences p \n WHERE \n i.domain_id = :domain_id \n and\n i.preference_id = p.pref_id\n and \n i.id = :id"; $sth = $db->query($sql, ':id', $id, ':domain_id', $auth_session->domain_id); $invoice = $sth->fetch(); $invoice['calc_date'] = date('Y-m-d', strtotime($invoice['date'])); $invoice['date'] = siLocal::date($invoice['date']); $invoice['total'] = getInvoiceTotal($invoice['id']); $invoice['gross'] = invoice::getInvoiceGross($invoice['id']); $invoice['paid'] = calc_invoice_paid($invoice['id']); $invoice['owing'] = $invoice['total'] - $invoice['paid']; $invoice['invoice_items'] = invoice::getInvoiceItems($id); #invoice total tax $sql2 = "SELECT SUM(tax_amount) AS total_tax, SUM(total) AS total FROM " . TB_PREFIX . "invoice_items WHERE invoice_id = :id"; $sth2 = dbQuery($sql2, ':id', $id) or die(htmlsafe(end($dbh->errorInfo()))); $result2 = $sth2->fetch(); //$invoice['total'] = number_format($result['total'],2); $invoice['total_tax'] = $result2['total_tax']; $invoice['tax_grouped'] = taxesGroupedForInvoice($id); return $invoice; }
function getInvoice($id, $domain_id = '') { global $config; $domain_id = domain_id::get($domain_id); $sql = "SELECT * FROM " . TB_PREFIX . "invoices WHERE id = :id AND domain_id = :domain_id"; $sth = dbQuery($sql, ':id', $id, ':domain_id', $domain_id); $invoice = $sth->fetch(); $invoice['calc_date'] = date('Y-m-d', strtotime($invoice['date'])); $invoice['date'] = siLocal::date($invoice['date']); $invoice['total'] = getInvoiceTotal($invoice['id']); $invoiceobj = new invoice(); $invoiceobj->domain_id = $domain_id; $invoice['gross'] = $invoiceobj->getInvoiceGross($invoice['id']); $invoice['paid'] = calc_invoice_paid($invoice['id']); $invoice['owing'] = $invoice['total'] - $invoice['paid']; #invoice total tax $sql = "SELECT SUM(tax_amount) AS total_tax, SUM(total) AS total FROM " . TB_PREFIX . "invoice_items WHERE invoice_id = :id AND domain_id = :domain_id"; $sth = dbQuery($sql, ':id', $id, ':domain_id', $domain_id); $result = $sth->fetch(); //$invoice['total'] = number_format($result['total'],2); $invoice['total_tax'] = $result['total_tax']; $invoice['tax_grouped'] = taxesGroupedForInvoice($id); return $invoice; }
function getInvoice($id) { global $dbh; global $config; global $auth_session; $sql = "SELECT * FROM " . TB_PREFIX . "invoices WHERE id = :id and domain_id = :domain_id"; //echo $sql; $sth = dbQuery($sql, ':id', $id, ':domain_id', $auth_session->domain_id) or die(htmlsafe(end($dbh->errorInfo()))); //print_r($query); $invoice = $sth->fetch(); //print_r($invoice); //exit(); $invoice['calc_date'] = date('Y-m-d', strtotime($invoice['date'])); $invoice['date'] = siLocal::date($invoice['date']); $invoice['total'] = getInvoiceTotal($invoice['id']); $invoice['gross'] = invoice::getInvoiceGross($invoice['id']); $invoice['paid'] = calc_invoice_paid($invoice['id']); $invoice['owing'] = $invoice['total'] - $invoice['paid']; #invoice total tax $sql = "SELECT SUM(tax_amount) AS total_tax, SUM(total) AS total FROM " . TB_PREFIX . "invoice_items WHERE invoice_id = :id"; $sth = dbQuery($sql, ':id', $id) or die(htmlsafe(end($dbh->errorInfo()))); $result = $sth->fetch(); //$invoice['total'] = number_format($result['total'],2); $invoice['total_tax'] = $result['total_tax']; $invoice['tax_grouped'] = taxesGroupedForInvoice($id); return $invoice; }
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; }