/** * 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); }
public function select($id, $domain_id = '') { global $logger; if (!empty($domain_id)) { $this->domain_id = $domain_id; } $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 LEFT JOIN \n\t\t\t\t\t" . TB_PREFIX . "preferences p \n\t\t\t\t\t\tON (i.preference_id = p.pref_id AND i.domain_id = p.domain_id)\n WHERE \n i.domain_id = :domain_id \n AND \n\t\t\t\t\ti.id = :id"; $sth = dbQuery($sql, ':id', $id, ':domain_id', $this->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'], $domain_id); $invoice['gross'] = $this->getInvoiceGross($invoice['id'], $this->domain_id); $invoice['paid'] = calc_invoice_paid($invoice['id'], $domain_id); $invoice['owing'] = $invoice['total'] - $invoice['paid']; $invoice['invoice_items'] = $this->getInvoiceItems($id, $this->domain_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 AND domain_id = :domain_id"; $sth2 = dbQuery($sql2, ':id', $id, ':domain_id', $this->domain_id); $result2 = $sth2->fetch(); //$invoice['total'] = number_format($result['total'],2); $invoice['total_tax'] = $result2['total_tax']; $invoice['tax_grouped'] = taxesGroupedForInvoice($id); return $invoice; }
public function check_reorder_level() { global $db; global $auth_session; $domain_id = domain_id::get($this->domain_id); //sellect qty and reorder level $inventory = new product(); $sth = $inventory->select_all('count'); $inventory_all = $sth->fetchAll(PDO::FETCH_ASSOC); $email = ""; foreach ($inventory_all as $row) { if ($row['quantity'] <= $row['reorder_level']) { $message = "The quantity of Product: " . $row['description'] . " is " . siLocal::number($row['quantity']) . ", which is equal to or below its reorder level of " . $row['reorder_level']; $return['row_' . $row['id']]['message'] = $message; $email_message .= $message . "<br />\n"; } } //print_r($return); #$attachment = file_get_contents('./tmp/cache/' . $pdf_file_name); $email = new email(); $email->notes = $email_message; $email->from = $email->get_admin_email(); $email->to = $email->get_admin_email(); #$email -> bcc = "justin@localhost"; $email->subject = "Simple Invoices reorder level email"; $email->send(); return $return; }
function smarty_function_total($params, &$smarty) { $subtotal = 0; foreach ($params['cost'] as $key => $value) { if ($value['product']['custom_field1'] == $params['group']) { $subtotal = $value['total'] + $subtotal; } } $subtotal = siLocal::number($subtotal); return $subtotal; }
/** * Initialize payment data. * replaces method getPayment($id) */ protected function _initData() { $tbl_prefix = SimpleInvoices_Db_Table_Abstract::getTablePrefix(); $select = new Zend_Db_Select($this->_db); $select->from($tbl_prefix . 'payment'); $select->joinInner($tbl_prefix . 'invoices', $tbl_prefix . "payment.ac_inv_id = " . $tbl_prefix . "invoices.id", NULL); $select->joinInner($tbl_prefix . 'customers', $tbl_prefix . "invoices.customer_id = " . $tbl_prefix . "customers.id", array('customer_id' => $tbl_prefix . "customers.id", 'customer' => $tbl_prefix . "customers.name")); $select->joinInner($tbl_prefix . 'biller', $tbl_prefix . "invoices.biller_id = " . $tbl_prefix . "biller.id", array('biller_id' => $tbl_prefix . "biller.id", 'biller' => $tbl_prefix . "biller.name")); $select->where($tbl_prefix . 'payment.id=?', $this->_id); $this->_data = $this->_db->fetchRow($select); $this->_data['date'] = siLocal::date($payment['ac_date']); }
public static function number_trim($number) { global $config; $formatted_number = siLocal::number($number); //get the precision and add 1 - for the decimal place and reverse the sign $position = ($config->local->precision + 1) * -1; if (substr($formatted_number, $position, '1') == ".") { $formatted_number = rtrim(trim($formatted_number, '0'), '.'); } if (substr($formatted_number, $position, '1') == ",") { $formatted_number = rtrim(trim($formatted_number, '0'), ','); /* Added to deal with "," */ } return $formatted_number; }
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; }
header("Content-type: text/xml"); //$start = (isset($_POST['start'])) ? $_POST['start'] : "0" ; $dir = isset($_POST['sortorder']) ? $_POST['sortorder'] : "DESC"; $sort = isset($_POST['sortname']) ? $_POST['sortname'] : "id"; $rp = isset($_POST['rp']) ? $_POST['rp'] : "25"; $page = isset($_POST['page']) ? $_POST['page'] : "1"; //$sql = "SELECT * FROM ".TB_PREFIX."invoices LIMIT $start, $limit"; $inventory = new inventory(); $inventory->sort = $sort; $inventory_all = $inventory->select_all('', $dir, $rp, $page); $sth_count_rows = $inventory->select_all('count', $dir, $rp, $page); $xml = ""; $count = $sth_count_rows; $xml .= "<rows>"; $xml .= "<page>{$page}</page>"; $xml .= "<total>{$count}</total>"; foreach ($inventory_all as $row) { $xml .= "<row id='" . $row['id'] . "'>"; $xml .= "<cell><![CDATA[\n\t\t<a class='index_table' title='{$LANG['view']} " . $row['name'] . "' href='index.php?module=inventory&view=view&id={$row['id']}'><img src='images/common/view.png' height='16' border='-5px' padding='-4px' valign='bottom' /></a>\n\t\t<a class='index_table' title='{$LANG['edit']} " . $row['name'] . "' href='index.php?module=inventory&view=edit&id={$row['id']}'><img src='images/common/edit.png' height='16' border='-5px' padding='-4px' valign='bottom' /></a>\n\t\t]]></cell>"; $xml .= "<cell><![CDATA[" . $row['date'] . "]]></cell>"; $xml .= "<cell><![CDATA[" . $row['description'] . "]]></cell>"; $xml .= "<cell><![CDATA[" . siLocal::number($row['quantity']) . "]]></cell>"; $xml .= "<cell><![CDATA[" . siLocal::number($row['cost']) . "]]></cell>"; $xml .= "<cell><![CDATA[" . siLocal::number($row['total_cost']) . "]]></cell>"; $xml .= "</row>"; } $xml .= "</rows>"; echo $xml; ?>
$sth = sql('', $dir, $start, $sort, $rp, $page); $sth_count_rows = sql('count',$dir, $start, $sort, $rp, $page); $tax = $sth->fetchAll(PDO::FETCH_ASSOC); $count = $sth_count_rows->rowCount(); $xml .= "<rows>"; $xml .= "<page>$page</page>"; $xml .= "<total>$count</total>"; foreach ($tax as $row) { $xml .= "<row id='".$row['tax_id']."'>"; $xml .= "<cell><![CDATA[ <a class='index_table' title='$LANG[view] $LANG[tax_rate] ".$row['tax_description']."' href='index.php?module=tax_rates&view=details&id=$row[tax_id]&action=view'><img src='" . $baseUrl . "images/common/view.png' height='16' border='-5px' padding='-4px' valign='bottom' /></a> <a class='index_table' title='$LANG[edit] $LANG[tax_rate] ".$row['tax_description']."' href='index.php?module=tax_rates&view=details&id=$row[tax_id]&action=edit'><img src='" . $baseUrl . "images/common/edit.png' height='16' border='-5px' padding='-4px' valign='bottom' /></a> ]]></cell>"; $xml .= "<cell><![CDATA[".$row['tax_description']."]]></cell>"; $xml .= "<cell><![CDATA[".siLocal::number($row['tax_percentage'])." ".$row['type']."]]></cell>"; if ($row['enabled']==$LANG['enabled']) { $xml .= "<cell><![CDATA[<img src='" . $baseUrl . "images/common/tick.png' alt='".utf8_encode($row['enabled'])."' title='".utf8_encode($row['enabled'])."' />]]></cell>"; } else { $xml .= "<cell><![CDATA[<img src='" . $baseUrl . "images/common/cross.png' alt='".utf8_encode($row['enabled'])."' title='".utf8_encode($row['enabled'])."' />]]></cell>"; } $xml .= "</row>"; } $xml .= "</rows>"; echo $xml;
if ($row['status'] && $row['owing'] > 0) { // Real Invoice Has Owing - Process payment $xml .= "<!--6 Payment --><a title='" . $LANG['process_payment_for'] . " " . $row['preference'] . " " . $row['index_id'] . "' class='index_table' href='index.php?module=payments&view=process&id=" . $row['id'] . "&op=pay_selected_invoice'><img src='images/common/money_dollar.png' class='action' /></a>"; } elseif ($row['status']) { // Real Invoice Payment Details if not Owing (get different color payment icon) $xml .= "<!--6 Payment --><a title='" . $LANG['process_payment_for'] . " " . $row['preference'] . " " . $row['index_id'] . "' class='index_table' href='index.php?module=payments&view=details&id=" . $row['id'] . "&action=view'><img src='images/common/money_dollar.png' class='action' /></a>"; } else { // Draft Invoice Just Image to occupy space till blank or greyed out icon becomes available $xml .= "<!--6 Payment --><img src='images/common/money_dollar.png' class='action' />"; } $xml .= "<!--7 Email --><a title='" . $LANG['email'] . " " . $row['preference'] . " " . $row['index_id'] . "' class='index_table' href='index.php?module=invoices&view=email&stage=1&id=" . $row['id'] . "'><img src='images/common/mail-message-new.png' class='action' /></a>\n\t\t\t]]>\n\t\t\t\t</cell>"; $xml .= "<cell><![CDATA[" . $row['index_name'] . "]]></cell>"; $xml .= "<cell><![CDATA[" . $row['biller'] . "]]></cell>"; $xml .= "<cell><![CDATA[" . $row['customer'] . "]]></cell>"; $xml .= "<cell><![CDATA[" . siLocal::date($row['date']) . "]]></cell>"; $xml .= "<cell><![CDATA[" . siLocal::number($row['invoice_total']) . "]]></cell>"; if ($row['status']) { $xml .= "<cell><![CDATA[" . siLocal::number($row['owing']) . "]]></cell>"; $xml .= "<cell><![CDATA[" . $row['aging'] . "]]></cell>"; } else { $xml .= "<cell><![CDATA[ ]]></cell>"; $xml .= "<cell><![CDATA[ ]]></cell>"; } $xml .= "<cell><![CDATA[" . $row['preference'] . "]]></cell>"; $xml .= "</row>"; } $xml .= "</rows>"; echo $xml; ?>
} return $result; } $sth = sql('', $dir, $sort, $rp, $page); $sth_count_rows = sql('count', $dir, $sort, $rp, $page); $customers = $sth->fetchAll(PDO::FETCH_ASSOC); $count = $sth_count_rows->rowCount(); //echo sql2xml($customers, $count); $xml .= "<rows>"; $xml .= "<page>{$page}</page>"; $xml .= "<total>{$count}</total>"; foreach ($customers as $row) { $status_wording = $row['status'] == 1 ? $LANG['paid'] : $LANG['not_paid']; $xml .= "<row id='" . $row['iso'] . "'>"; $xml .= "<cell><![CDATA[\n\t\t\t<a class='index_table' title='{$LANG['view']} " . $row['description'] . "' href='index.php?module=expense&view=details&id=" . $row['id'] . "&action=view'><img src='images/common/view.png' height='16' border='-5px' padding='-4px' valign='bottom' /></a>\n\t\t\t<a class='index_table' title='{$LANG['edit']} " . $row['description'] . "' href='index.php?module=expense&view=details&id=" . $row['id'] . "&action=edit'><img src='images/common/edit.png' height='16' border='-5px' padding='-4px' valign='bottom' /></a>\n\t\t]]></cell>"; $xml .= "<cell><![CDATA[" . siLocal::date($row['date']) . "]]></cell>"; $xml .= "<cell><![CDATA[" . siLocal::number_trim($row['amount']) . "]]></cell>"; $xml .= "<cell><![CDATA[" . siLocal::number_trim($row['tax']) . "]]></cell>"; $xml .= "<cell><![CDATA[" . siLocal::number_trim($row['amount'] + $row['tax']) . "]]></cell>"; $xml .= "<cell><![CDATA[" . $row['expense_account'] . "]]></cell>"; $xml .= "<cell><![CDATA[" . $row['biller'] . "]]></cell>"; $xml .= "<cell><![CDATA[" . $row['customer'] . "]]></cell>"; $xml .= "<cell><![CDATA[" . $row['invoice'] . "]]></cell>"; $xml .= "<cell><![CDATA[" . $status_wording . "]]></cell>"; $xml .= "</row>"; } $xml .= "</rows>"; echo $xml; ?>
$sql = "SELECT \n\t\t\t\t\tc.id as CID, \n\t\t\t\t\tc.name as name, \n\t\t\t\t\t(SELECT (CASE WHEN c.enabled = 0 THEN 'Disabled' ELSE 'Enabled' END )) AS enabled,\n\t\t\t\t\t(\n\t\t\t\t\t\tSELECT\n\t\t\t\t coalesce(sum(ii.total), 0) AS total \n\t\t\t\t FROM\n\t\t\t\t " . TB_PREFIX . "invoice_items ii INNER JOIN\n\t\t\t\t " . TB_PREFIX . "invoices iv ON (iv.id = ii.invoice_id)\n\t\t\t\t WHERE \n\t\t\t\t iv.customer_id = CID ) as customer_total,\n\t\t( SELECT MAX(id)\n\t\t\tFROM\n\t\t\t\t" . TB_PREFIX . "invoices \n\t\t\tWHERE\tcustomer_id = CID) AS last_invoice, (\n \n\t SELECT \n\t coalesce(sum(ap.ac_amount), 0) AS amount \n\t FROM\n\t " . TB_PREFIX . "payment ap INNER JOIN\n\t " . TB_PREFIX . "invoices iv ON (iv.id = ap.ac_inv_id)\n\t WHERE \n\t iv.customer_id = CID) AS paid,\n\t ( select customer_total - paid ) AS owing\n\t\n\t\t\t\tFROM \n\t\t\t\t\t" . TB_PREFIX . "customers c \n\t\t\t\tWHERE c.domain_id = :domain_id\n\t\t\t\t\t{$where}\n\t\t\t\tORDER BY \n\t\t\t\t\t{$sort} {$dir} \n\t\t\t\t{$limit}"; if (empty($query)) { $result = dbQuery($sql, ':domain_id', $auth_session->domain_id); } else { $result = dbQuery($sql, ':domain_id', $auth_session->domain_id, ':query', "%{$query}%"); } return $result; } $sth = sql('', $dir, $sort, $rp, $page); $sth_count_rows = sql('count', $dir, $sort, $rp, $page); $customers = $sth->fetchAll(PDO::FETCH_ASSOC); $count = $sth_count_rows->rowCount(); $xml .= "<rows>"; $xml .= "<page>{$page}</page>"; $xml .= "<total>{$count}</total>"; foreach ($customers as $row) { $xml .= "<row id='" . $row['CID'] . "'>"; $xml .= "<cell><![CDATA[\n\t\t\t<a class='index_table' title='{$LANG['view']} {$LANG['customer']} " . utf8_encode($row['name']) . "' href='index.php?module=customers&view=details&id={$row['CID']}&action=view'><img src='images/common/view.png' class='action' /></a>\n\t\t\t<a class='index_table' title='{$LANG['edit']} {$LANG['customer']} " . utf8_encode($row['name']) . "' href='index.php?module=customers&view=details&id={$row['CID']}&action=edit'><img src='images/common/edit.png' class='action' /></a>\n\t\t\t<a class='index_table' title='{$LANG['new_invoice']} {$LANG['for']} {$LANG['customer']} " . utf8_encode($row['name']) . "' href='index.php?module=invoices&view=usedefault&customer_id={$row['CID']}&action=edit'><img src='images/famfam/page_add.png' class='action' /></a>\n\t\t]]></cell>"; $xml .= "<cell><![CDATA[" . $row['CID'] . "]]></cell>"; $xml .= "<cell><![CDATA[" . utf8_encode($row['name']) . "]]></cell>"; $xml .= "<cell><![CDATA[<a class='index_table' title='quick view' href='index.php?module=invoices&view=quick_view&id=" . utf8_encode($row['last_invoice']) . "'>" . utf8_encode($row['last_invoice']) . "</a>]]></cell>"; $xml .= "<cell><![CDATA[" . utf8_encode(siLocal::number($row['customer_total'])) . "]]></cell>"; $xml .= "<cell><![CDATA[" . utf8_encode(siLocal::number($row['owing'])) . "]]></cell>"; $xml .= "<cell><![CDATA[" . utf8_encode($row['enabled']) . "]]></cell>"; $xml .= "</row>"; } $xml .= "</rows>"; echo $xml; ?>
$defaults = getSystemDefaults(); $smarty->assign("defaults", $defaults); $products = new product(); $sth = $products->select_all('', $dir, $sort, $rp, $page); $sth_count_rows = $products->select_all('count', $dir, $sort, $rp, $page); $products_all = $sth->fetchAll(PDO::FETCH_ASSOC); $count = $sth_count_rows->rowCount(); //echo sql2xml($customers, $count); $xml .= "<rows>"; $xml .= "<page>{$page}</page>"; $xml .= "<total>{$count}</total>"; foreach ($products_all as $row) { $xml .= "<row id='" . $row['iso'] . "'>"; $xml .= "<cell><![CDATA[\r\n\t\t\t<a class='index_table' title='{$LANG['view']} " . $row['description'] . "' href='index.php?module=products&view=details&id=" . $row['id'] . "&action=view'><img src='images/common/view.png' height='16' border='-5px' padding='-4px' valign='bottom' /></a>\r\n\t\t\t<a class='index_table' title='{$LANG['edit']} " . $row['description'] . "' href='index.php?module=products&view=details&id=" . $row['id'] . "&action=edit'><img src='images/common/edit.png' height='16' border='-5px' padding='-4px' valign='bottom' /></a>\r\n\t\t]]></cell>"; $xml .= "<cell><![CDATA[" . $row['description'] . "]]></cell>"; $xml .= "<cell><![CDATA[" . siLocal::number_clean($row['unit_price']) . "]]></cell>"; if ($defaults['inventory'] == '1') { $xml .= "<cell><![CDATA[" . siLocal::number_trim($row['quantity']) . "]]></cell>"; } if ($row['enabled'] == $LANG['enabled']) { $xml .= "<cell><![CDATA[<img src='images/common/tick.png' alt='" . $row['enabled'] . "' title='" . $row['enabled'] . "' />]]></cell>"; } else { $xml .= "<cell><![CDATA[<img src='images/common/cross.png' alt='" . $row['enabled'] . "' title='" . $row['enabled'] . "' />]]></cell>"; } $xml .= "</row>"; } $xml .= "</rows>"; echo $xml; ?>
function getCustomerInvoices($id, $domain_id = '') { global $config; $domain_id = domain_id::get($domain_id); // tested for MySQL $sql = "SELECT\t\n\t\tiv.id, \n\t\tiv.index_id, \n\t\tiv.date, \n\t\tiv.type_id, \n\t\t(SELECT SUM( COALESCE(ii.total, 0)) FROM " . TB_PREFIX . "invoice_items ii WHERE ii.invoice_id = iv.id AND ii.domain_id = iv.domain_id) AS invd,\n\t\t(SELECT SUM( COALESCE(ap.ac_amount, 0)) FROM " . TB_PREFIX . "payment ap WHERE ap.ac_inv_id = iv.id AND ap.domain_id = iv.domain_id) AS pmt,\n\t\t(SELECT COALESCE(invd, 0)) As total, \n\t\t(SELECT COALESCE(pmt, 0)) As paid, \n\t\t(select (total - paid)) as owing,\n\t\tpr.status,\n\t\tpr.pref_inv_wording\n\tFROM \n\t\t" . TB_PREFIX . "invoices iv\n\t\tLEFT JOIN " . TB_PREFIX . "preferences pr ON (pr.pref_id = iv.preference_id AND pr.domain_id = iv.domain_id)\n\tWHERE \n\t\tiv.customer_id = :id\n\tAND iv.domain_id = :domain_id\n\tORDER BY \n\t\tiv.id DESC;"; $sth = dbQuery($sql, ':id', $id, ':domain_id', $domain_id); $invoices = null; while ($invoice = $sth->fetch()) { $invoice['calc_date'] = date('Y-m-d', strtotime($invoice['date'])); $invoice['date'] = siLocal::date($invoice['date']); $invoices[] = $invoice; } return $invoices; }
if($_GET['id']) { //sleep(2); $sql = sprintf('SELECT cost FROM '.TB_PREFIX.'products WHERE id = %d LIMIT 1', $_GET['id']); $states = dbQuery($sql); // $output = ''; if($states->rowCount() > 0) { $row = $states->fetch(); // print_r($row); // $output .= '<input id="state" class="field select two-third addr" value="'.$row['unit_price'].'"/>'; /*Format with decimal places with precision as defined in config.ini*/ $output['cost'] = siLocal::number_formatted($row['cost']); // $output .= $_POST['id']; } else { $output .= ''; } echo json_encode($output); exit(); } else { echo ""; }
global $dbh; $sqlTotal = "SELECT count(id) AS count FROM ".TB_PREFIX."invoices"; $tth = dbQuery($sqlTotal) or die(end($dbh->errorInfo())); $resultCount = $tth->fetch(); $count = $resultCount[0]; //echo sql2xml($invoices, $count); $xml .= "<rows>"; $xml .= "<page>$page</page>"; $xml .= "<total>$count</total>"; foreach ($invoices as $row) { $xml .= "<row id='".$row['id']."'>"; $xml .= "<action><![CDATA[<a href='index.php?module=invoices&view=quick_view&invoice=".$row['id']."'>".utf8_encode($row['id'])."</a>]]></action>"; $xml .= "<customer><![CDATA[".utf8_encode($row['customer'])."]]></customer>"; $xml .= "<date><![CDATA[".utf8_encode($row['date'])."]]></date>"; $xml .= "<invoice_total><![CDATA[".utf8_encode(siLocal::number($row['invoice_total']))."]]></invoice_total>"; $xml .= "</row>"; } $xml .= "</rows>"; echo $xml; ?>
function getCustomerInvoices($id) { global $dbh; global $config; global $auth_session; // tested for MySQL $sql = "SELECT\t\n\t\ti.id, \n\t\ti.date, \n\t\ti.type_id, \n\t\t(SELECT sum( COALESCE(ii.total, 0)) FROM " . TB_PREFIX . "invoice_items ii where ii.invoice_id = i.id) As invd,\n\t\t(SELECT sum( COALESCE(ap.ac_amount, 0)) FROM " . TB_PREFIX . "payment ap where ap.ac_inv_id = i.id) As pmt,\n\t\t(SELECT COALESCE(invd, 0)) As total, \n\t\t(SELECT COALESCE(pmt, 0)) As paid, \n\t\t(select (total - paid)) as owing \n\tFROM \n\t\t" . TB_PREFIX . "invoices i \n\tWHERE \n\t\ti.customer_id = :id\n\t\tand\n\t\ti.domain_id = :domain_id\n\tORDER BY \n\t\ti.id DESC;"; $sth = dbQuery($sql, ':id', $id, ':domain_id', $auth_session->domain_id) or die(htmlsafe(end($dbh->errorInfo()))); $invoices = null; while ($invoice = $sth->fetch()) { $invoice['calc_date'] = date('Y-m-d', strtotime($invoice['date'])); $invoice['date'] = siLocal::date($invoice['date']); $invoices[] = $invoice; } return $invoices; }
<?php if ($_GET['id']) { //sleep(2); $sql = sprintf('SELECT unit_price, default_tax_id, default_tax_id_2 FROM si_products WHERE id = %d LIMIT 1', $_GET['id']); $states = dbQuery($sql); // $output = ''; if ($states->rowCount() > 0) { $row = $states->fetch(); // print_r($row); // $output .= '<input id="state" class="field select two-third addr" value="'.$row['unit_price'].'"/>'; /*Format with decimal places with precision as defined in config.ini*/ $output['unit_price'] = siLocal::number_clean($row['unit_price']); $output['default_tax_id'] = $row['default_tax_id']; $output['default_tax_id_2'] = $row['default_tax_id_2']; // $output .= $_POST['id']; } else { $output .= ''; } echo json_encode($output); exit; } else { echo ""; } // Perform teh Queries! //$sql = 'SELECT * FROM si_products'; //$country = mysqlQuery($sql) or die('Query Failed:' . mysql_error());
} $sth = sql('', $dir, $sort, $rp, $page); $sth_count_rows = sql('count', $dir, $sort, $rp, $page); $payments = $sth->fetchAll(PDO::FETCH_ASSOC); $count = $sth_count_rows->rowCount(); /* $sqlTotal = "SELECT count(id) AS count FROM ".TB_PREFIX."payment"; $tth = dbQuery($sqlTotal) or die(end($dbh->errorInfo())); $resultCount = $tth->fetch(); $count = $resultCount[0]; //echo sql2xml($customers, $count); */ $xml = "<rows>"; $xml .= "<page>{$page}</page>"; $xml .= "<total>{$count}</total>"; foreach ($payments as $row) { $notes = si_truncate($row['ac_notes'], '13', '...'); $xml .= "<row id='" . $row['id'] . "'>"; $xml .= "<cell><![CDATA[\n\t<a class='index_table' title='{$LANG['view']} " . $row['name'] . "' href='index.php?module=payments&view=details&id={$row['id']}&action=view'><img src='images/common/view.png' height='16' border='-5px' padding='-4px' valign='bottom' /></a>\n\t<a class='index_table' title='{$LANG['print_preview_tooltip']} " . $row['id'] . "' href='index.php?module=payments&view=print&id={$row['id']}'><img src='images/common/printer.png' height='16' border='-5px' padding='-4px' valign='bottom' /></a>\n\t]]></cell>"; $xml .= "<cell><![CDATA[" . $row['id'] . "]]></cell>"; $xml .= "<cell><![CDATA[" . $row['index_name'] . "]]></cell>"; $xml .= "<cell><![CDATA[" . $row['cname'] . "]]></cell>"; $xml .= "<cell><![CDATA[" . $row['bname'] . "]]></cell>"; $xml .= "<cell><![CDATA[" . siLocal::number($row['ac_amount']) . "]]></cell>"; $xml .= "<cell><![CDATA[" . $notes . "]]></cell>"; $xml .= "<cell><![CDATA[" . $row['description'] . "]]></cell>"; $xml .= "<cell><![CDATA[" . siLocal::date($row['date']) . "]]></cell>"; $xml .= "</row>"; } $xml .= "</rows>"; echo $xml;