/** * returns the last purid value from core.purchasesids_seq; */ function lastpurid() { $qry = new dbQuery(DB_SQL, "SELECT last_value FROM core.purchasesids_seq"); $qry->run(); if ($qry->num_rows() < 1) { return 0; } return $qry->fetch_result(); }
function printPurch($_POST, $pure = false) { extract($_POST); require_lib("validate"); $v = new validate(); $v->isOk($from_day, "num", 1, 2, "Invalid from Date day."); $v->isOk($from_month, "num", 1, 2, "Invalid from Date month."); $v->isOk($from_year, "num", 1, 4, "Invalid from Date Year."); $v->isOk($to_day, "num", 1, 2, "Invalid to Date day."); $v->isOk($to_month, "num", 1, 2, "Invalid to Date month."); $v->isOk($to_year, "num", 1, 4, "Invalid to Date Year."); $fromdate = $from_year . "-" . $from_month . "-" . $from_day; $todate = $to_year . "-" . $to_month . "-" . $to_day; if (!checkdate($from_month, $from_day, $from_year)) { $v->isOk($fromdate, "num", 1, 1, "Invalid from date."); } if (!checkdate($to_month, $to_day, $to_year)) { $v->isOk($todate, "num", 1, 1, "Invalid to date."); } if ($v->isError()) { return $v->genErrors(); } require_lib("docman"); $OUT = ""; if (!$pure) { $OUT .= "\n\t\t<center>\n\t\t<h3>Received Stock Orders</h3>"; } $OUT .= "\n\t\t<table " . TMPL_tblDflts . ">\n\t\t\t<tr>\n\t\t\t\t<th>Purchase No.</th>\n\t\t\t\t<th>Order No.</th>\n\t\t\t\t<th>Supp Inv No.</th>\n\t\t\t\t<th>Order Date</th>\n\t\t\t\t<th>Received Date</th>\n\t\t\t\t<th>Supplier</th>\n\t\t\t\t<th>Sub Total</th>\n\t\t\t\t<th>Delivery Charges</th>\n\t\t\t\t<th>VAT</th>\n\t\t\t\t<th>Total</th>\n\t\t\t\t<th>Delivery Reference No.</th>\n\t\t\t\t<th>Documents</th>\n\t\t\t\t<th colspan='5'>Options</th>\n\t\t\t</tr>"; $i = 0; $tot1 = 0; $tot2 = 0; $tot3 = 0; $tot4 = 0; $supsql = ""; if (isset($supplier) and $supplier != 0) { $supsql = " AND supid = '{$supplier}'"; } /* build the sql */ $queries = array(); for ($i = 1; $i <= 12; $i++) { $schema = (int) $i; $queries[] = "SELECT *,'{$schema}' AS query_schema FROM \"{$schema}\".purchases WHERE pdate >= '{$fromdate}' AND pdate <= '{$todate}' AND done = 'y' AND div = '" . USER_DIV . "' {$supsql}"; } $sql = implode(" UNION ", $queries) . " ORDER BY pdate DESC"; $qry = new dbQuery(DB_SQL, $sql); $qry->run(); if ($qry->num_rows() < 1) { return "<li class='err'> No Received Stock Orders found.</li><br>"; } while ($stkp = $qry->fetch_array()) { $prd = $stkp["query_schema"]; /* calculate the subtotal */ $stkp['total'] = sprint($stkp['total']); $stkp['shipchrg'] = sprint($stkp['shipping']); $subtot = $stkp['subtot']; $subtot = sprint($subtot); /* add the totals */ $tot1 = sprint($tot1 + $subtot); $tot2 = sprint($tot2 + $stkp['shipchrg']); $tot3 = sprint($tot3 + $stkp['total']); $tot4 = sprint($tot4 + $stkp["vat"]); $docs = doclib_getdocs("pur", $stkp['purnum']); $docs .= " <a href='#' onClick=\"printer('purch-recv.php?key=recv_print&purid={$stkp['purid']}');\">GRN</a>"; $OUT .= "\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>{$stkp['purnum']}</td>\n\t\t\t\t<td>{$stkp['ordernum']}</td>\n\t\t\t\t<td>{$stkp['supinv']}</td>\n\t\t\t\t<td>{$stkp['pdate']}</td>\n\t\t\t\t<td>{$stkp['ddate']}</td>\n\t\t\t\t<td>{$stkp['supname']}</td>\n\t\t\t\t<td align='right' nowrap>" . CUR . " {$subtot}</td>\n\t\t\t\t<td align='right' nowrap>" . CUR . " {$stkp['shipchrg']}</td>\n\t\t\t\t<td align='right' nowrap>" . CUR . " {$stkp['vat']}</td>\n\t\t\t\t<td align='right' nowrap>" . CUR . " {$stkp['total']}</td>\n\t\t\t\t<td>{$stkp['refno']}</td>\n\t\t\t\t<td>{$docs}</td>"; if ($stkp['returned'] != 'y') { $OUT .= "<td><a href='purch-return.php?purid={$stkp['purid']}&prd={$prd}'>Return</a></td>"; } else { $OUT .= "<td> </td>"; } if ($stkp['rsubtot'] > 0) { $OUT .= "<td><a href='purch-recnote.php?purid={$stkp['purid']}&prd={$prd}'>Record Credit Note</a></td>"; } else { $OUT .= "<td> </td>"; } $OUT .= "\n\t\t\t\t<td><a href='purch-det-prd.php?purid={$stkp['purid']}&prd={$prd}'>Details</a></td>\n\t\t\t\t<td><a target='_blank' href='purch-recv-print.php?purid={$stkp['purid']}&prd={$prd}'>Print</a></td>\n\t\t\t</tr>"; } $OUT .= "\n\t\t<tr class='" . bg_class() . "'>\n\t\t\t<td colspan='6'>Totals</td>\n\t\t\t<td align='right' nowrap>" . CUR . " {$tot1}</td>\n\t\t\t<td align='right' nowrap>" . CUR . " {$tot2}</td>\n\t\t\t<td align='right' nowrap>" . CUR . " {$tot4}</td>\n\t\t\t<td align='right' nowrap>" . CUR . " {$tot3}</td>\n\t\t</tr>"; if (!$pure) { $OUT .= "\n\t\t\t" . TBL_BR . "\n\t\t\t<form action='" . SELF . "' method='POST'>\n\t\t\t\t<input type='hidden' name='key' value='export' />\n\t\t\t\t<input type='hidden' name='prd' value='{$prd}' />\n\t\t\t\t<input type='hidden' name='from_day' value='{$from_day}' />\n\t\t\t\t<input type='hidden' name='from_month' value='{$from_month}' />\n\t\t\t\t<input type='hidden' name='from_year' value='{$from_year}' />\n\t\t\t\t<input type='hidden' name='to_day' value='{$to_day}' />\n\t\t\t\t<input type='hidden' name='to_month' value='{$to_month}' />\n\t\t\t\t<input type='hidden' name='to_year' value='{$to_year}' />\n\t\t\t\t<tr>\n\t\t\t\t\t<td colspan='4'><input type='submit' value='Export to Spreadsheet'></td>\n\t\t\t\t</tr>\n\t\t\t</form>"; } $OUT .= "</table>"; return $OUT; }