function create_dummy($deptid) { db_connect(); # Insert purchase to DB $sql = "INSERT INTO nons_invoices(cusname, cusaddr, cusvatno, chrgvat, sdate, subtot, balance, vat,\n\t\t\ttotal, done, username, prd, invnum, div)"; $sql .= " VALUES('', '', '', 'yes', CURRENT_DATE, 0, 0, 0, 0, 'n', '" . USER_NAME . "', '" . PRD_DB . "',\n\t\t\t0,'" . USER_DIV . "')"; $rslt = db_exec($sql) or errDie("Unable to create template Non-Stock Invoice.", SELF); # Get next ordnum $invid = lastinvid(); return $purid; }
function invoice() { extract($_REQUEST); pglib_transaction("BEGIN"); $invnum = divlastid("inv"); $sql = "INSERT INTO cubit.invoices(deptid, chrgvat, odate, printed, done, \n\t\t\t\tusername, prd, invnum, div, systime, pslip_sordid, cusnum, ordno)\n\t\t\tVALUES ('" . USER_DIV . "', 'inc', current_date, 'n', 'n',\n\t\t\t\t'" . USER_NAME . "', '" . PRD_DB . "', '{$invnum}', '" . USER_DIV . "',\n\t\t\t\tcurrent_date, '{$sordid}', '{$cusnum}', '{$sordid}')"; $inv_rslt = db_exec($sql) or errDie("Unable to retrieve invoice."); $invid = lastinvid(); $sql = "SELECT stock.stkid, stock.whid, qty, sorders_items.vatcode, amt, unitcost\n\t\t\tFROM cubit.sorders_items\n\t\t\t\tLEFT JOIN cubit.stock ON sorders_items.stkid=stock.stkid\n\t\t\tWHERE sordid='{$sordid}'"; $stock_rslt = db_exec($sql) or errDie("Unable to retrieve stock."); while (list($stkid, $whid, $qty, $vatcode, $amt, $unitcost) = pg_fetch_array($stock_rslt)) { $sql = "INSERT INTO cubit.inv_items (invid, whid, stkid, qty, div,\n\t\t\t\t\tvatcode, amt, unitcost)\n\t\t\t\tVALUES ('{$invid}', '{$whid}', '{$stkid}', '{$qty}', '" . USER_DIV . "',\n\t\t\t\t\t'{$vatcode}', '{$amt}', '{$unitcost}')"; db_exec($sql) or errDie("Unable to add inventory items."); } $OUTPUT = "\n\t<script>\n\t\tmove(\"../cust-credit-stockinv-no-neg.php?invid={$invid}&cont=true\");\n\t</script>"; pglib_transaction("COMMIT"); return $OUTPUT; }
function create_dummy($deptid) { $trans_date_setting = getCSetting("USE_TRANSACTION_DATE"); if (isset($trans_date_setting) and $trans_date_setting == "yes") { $trans_date_value = getCSetting("TRANSACTION_DATE"); $date_arr = explode("-", $trans_date_value); $date_year = $date_arr[0]; $date_month = $date_arr[1]; $date_day = $date_arr[2]; } else { $date_year = date("Y"); $date_month = date("m"); $date_day = date("d"); } $odate = "{$date_year}-{$date_month}-{$date_day}"; db_connect(); # Insert purchase to DB $sql = "\n\t\tINSERT INTO nons_invoices (\n\t\t\tcusname, cusaddr, cusvatno, chrgvat, sdate, odate, subtot, balance, vat, total, done, username, prd, invnum, \n\t\t\ttyp, div, multiline \n\t\t) VALUES (\n\t\t\t'', '', '', 'yes', CURRENT_DATE, '{$odate}', 0, 0, 0, 0, 'n', '" . USER_NAME . "', '" . PRD_DB . "', 0, \n\t\t\t'quo', '" . USER_DIV . "', 'yes'\n\t\t)"; $rslt = db_exec($sql) or errDie("Unable to create template Non-Stock Quote.", SELF); return lastinvid(); }
function create_dummy($deptid) { db_connect(); # Dummy Vars $cusnum = 0; $salespn = ""; $comm = ""; $salespn = ""; $chrgvat = getSetting("SELAMT_VAT"); // $odate = date("Y-m-d"); $ordno = ""; $delchrg = "0.00"; $cordno = ""; $terms = 0; $traddisc = 0; $SUBTOT = 0; $vat = 0; $total = 0; $vatnum = ""; $cusacc = ""; $telno = ""; $trans_date_setting = getCSetting("USE_TRANSACTION_DATE"); if (isset($trans_date_setting) and $trans_date_setting == "yes") { $trans_date_value = getCSetting("TRANSACTION_DATE"); $date_arr = explode("-", $trans_date_value); $date_year = $date_arr[0]; $date_month = $date_arr[1]; $date_day = $date_arr[2]; } else { $date_year = date("Y"); $date_month = date("m"); $date_day = date("d"); } $odate = "{$date_year}-{$date_month}-{$date_day}"; // $invid = divlastid('pinv', USER_DIV); # insert invoice to DB $sql = "\n\t\tINSERT INTO cubit.pinvoices (\n\t\t\tdeptid, cusnum, cordno, ordno, chrgvat, terms, traddisc, salespn, odate, \n\t\t\tdelchrg, subtot, vat, total, balance, comm, username, printed, done, prd, \n\t\t\tvatnum, cusacc, telno, div\n\t\t) VALUES (\n\t\t\t'{$deptid}', '{$cusnum}', '{$cordno}', '{$ordno}', '{$chrgvat}', '{$terms}', '{$traddisc}', '{$salespn}', '{$odate}', \n\t\t\t'{$delchrg}', '{$SUBTOT}', '{$vat}' , '{$total}', '{$total}', '{$comm}', '" . USER_NAME . "', 'n', 'n', '" . PRD_DB . "', \n\t\t\t'{$vatnum}', '{$cusacc}', '{$telno}', '" . USER_DIV . "'\n\t\t)"; $rslt = db_exec($sql) or errDie("Unable to insert invoice to Cubit.", SELF); # get next ordnum $invid = lastinvid(); return $invid; }
/** * @ignore */ function fintInvoice($cusnum, $total, $rate) { $ftotal = sprint($total * $rate); db_connect(); $sql = "SELECT * FROM customers WHERE cusnum = '{$cusnum}' AND div = '" . USER_DIV . "'"; $custRslt = db_exec($sql) or errDie("Unable to view customer"); $cus = pg_fetch_array($custRslt); $curr = getSymbol($cus['fcid']); $xrate = getRate($cus['fcid']); # Default data $sdate = date("Y-m-d"); $invnum = divlastid('inv', USER_DIV); db_connect(); # Insert purchase to DB $sql = "\n\t\tINSERT INTO nons_invoices (\n\t\t\tcusid, cusname, cusaddr, cusvatno, chrgvat, \n\t\t\tfcid, currency, xrate, sdate, subtot, \n\t\t\tbalance, fbalance, vat, total, done, \n\t\t\tusername, prd, invnum, typ, ctyp, \n\t\t\ttval, location, descrip, div, odate\n\t\t) VALUES (\n\t\t\t'{$cus['cusnum']}', '{$cus['cusname']} {$cus['surname']}', '{$cus['addr1']}', '{$cus['vatnum']}', 'none', \n\t\t\t'{$cus['fcid']}', '{$curr['symbol']}', '{$xrate}', '{$sdate}', '{$total}', \n\t\t\t'{$ftotal}', '{$total}', 0, '{$total}', 'y', \n\t\t\t'" . USER_NAME . "', '" . PRD_DB . "', '{$invnum}', 'inv', 's', \n\t\t\t'{$cusnum}', 'int', 'Interest Charged', '" . USER_DIV . "', '{$sdate}'\n\t\t)"; $rslt = db_exec($sql) or errDie("Unable to create Interest Invoice.", SELF); # Get next ordnum $invid = lastinvid(); # Insert purchase items $sql = "\n\t\tINSERT INTO nons_inv_items (\n\t\t\tinvid, qty, amt, cunitcost, unitcost, \n\t\t\tdescription, div\n\t\t) VALUES (\n\t\t\t'{$invid}', '1', '{$total}', '{$ftotal}', '{$total}', \n\t\t\t'Interest on Outstanding Invoices.', '" . USER_DIV . "'\n\t\t)"; $rslt = db_exec($sql) or errDie("Unable to insert invoice items to Cubit.", SELF); return $invnum; }
function accept($_POST) { extract($_POST); # Validate input require_lib("validate"); $v = new validate(); $v->isOk($invid, "num", 1, 20, "Invalid Sales Order number."); # display errors, if any if ($v->isError()) { $err = ""; $errors = $v->getErrors(); foreach ($errors as $e) { $err .= "<li class=err>" . $e["msg"]; } $confirm .= "<p><input type=button onClick='JavaScript:history.back();' value='« Correct submission'>"; return $confirm; } # Get Sales Order info db_connect(); $sql = "SELECT * FROM nons_invoices WHERE invid = '{$invid}' AND div = '" . USER_DIV . "'"; $invRslt = db_exec($sql) or errDie("Unable to get -sorder- information"); if (pg_numrows($invRslt) < 1) { return "<i class=err>Not Found</i>"; } $inv = pg_fetch_array($invRslt); db_connect(); /* - Start Copying - */ pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF); $sql = "INSERT INTO nons_invoices(cusname,cusaddr,cusvatno,chrgvat,sdate,odate,done,username,\n\t\t\t\tprd,invnum,div,remarks,cusid,age,typ,subtot,balance,vat,total,descrip,ctyp,\n\t\t\t\taccid,tval,docref,jobid,jobnum,labid,location,fcid,currency,xrate,fbalance,\n\t\t\t\tfsubtot)\n\tVALUES('{$inv['cusname']}','{$inv['cusaddr']}','{$inv['cusvatno']}','{$inv['chrgvat']}','{$inv['sdate']}',\n\t\t\t'{$inv['odate']}', '{$inv['done']}','{$inv['username']}','{$inv['prd']}','{$inv['invnum']}','{$inv['div']}',\n\t\t\t'{$inv['remarks']}','{$inv['cusid']}','{$inv['age']}','inv','{$inv['subtot']}','{$inv['balance']}',\n\t\t\t'{$inv['vat']}','{$inv['total']}','{$inv['descrip']}', '{$inv['ctyp']}','{$inv['accid']}','{$inv['tval']}',\n\t\t\t'{$inv['docref']}','{$inv['jobid']}','{$inv['jobnum']}','{$inv['labid']}','{$inv['location']}',\n\t\t\t'{$inv['fcid']}','{$inv['currency']}','{$inv['xrate']}','{$inv['fbalance']}', '{$inv['fsubtot']}')"; $upRslt = db_exec($sql) or errDie("Unable to update -sorder- information"); # get next ordnum $ninvid = lastinvid(); # Get selected stock in this Sales Order db_connect(); $sql = "SELECT * FROM nons_inv_items WHERE invid = '{$invid}' AND div = '" . USER_DIV . "'"; $stkdRslt = db_exec($sql); while ($stkd = pg_fetch_array($stkdRslt)) { $stkd['cunitcost'] += 0; $sql = "INSERT INTO nons_inv_items(invid, qty, description, div, amt, unitcost, accid, rqty, vatex, cunitcost)\n\t\tVALUES('{$ninvid}', '{$stkd['qty']}', '{$stkd['description']}', '{$stkd['div']}', '{$stkd['amt']}', '{$stkd['unitcost']}', '{$stkd['accid']}', '{$stkd['rqty']}', '{$stkd['vatex']}', '{$stkd['cunitcost']}')"; $upRslt = db_exec($sql) or errDie("Unable to update -sorder- information"); } # Set to not serialised $sql = "UPDATE nons_invoices SET done = 'y' WHERE invid = '{$invid}' AND div = '" . USER_DIV . "'"; $rslt = db_exec($sql) or errDie("Unable to update -sorder-s in Cubit.", SELF); /* - End Copying - */ pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF); header("Location: nons-invoice-new.php?invid={$ninvid}&cont=1"); exit; # Final Laytout $write = "\n\t<table border=0 cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "'>\n\t\t<tr><th>Non-Stock Sales Orders accepted</th></tr>\n\t\t<tr class='bg-even'><td>Non-Stock Sales Orders for Customer <b>{$inv['cusname']}</b> has been accepted.</td></tr>\n\t</table>\n\t<p>\n\t<table border=0 cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "'>\n\t\t<tr><th>Quick Links</th></tr>\n\t\t<tr class='bg-odd'><td><a href='nons-sorder-view.php'>View Non-Stock Sales Orders</a></td></tr>\n\t\t<script>document.write(getQuicklinkSpecial());</script>\n\t</table>"; return $write; }
function write($_POST) { # Get vars foreach ($_POST as $key => $value) { ${$key} = $value; } # validate input require_lib("validate"); $v = new validate(); $v->isOk($quoid, "num", 1, 20, "Invalid Quote number."); $v->isOk($cusnum, "num", 1, 20, "Invalid Customer number."); $v->isOk($cordno, "string", 0, 20, "Invalid Customer order number."); # display errors, if any $err = ""; if ($v->isError()) { $errors = $v->getErrors(); foreach ($errors as $e) { $err .= "<li class=err>" . $e["msg"]; } return $err; } # Get quote info db_connect(); $sql = "SELECT * FROM pos_quotes WHERE quoid = '{$quoid}' AND div = '" . USER_DIV . "'"; $quoRslt = db_exec($sql) or errDie("Unable to get quote information"); if (pg_numrows($quoRslt) < 1) { return "<li class=err>Quote Not Found</li>"; } $quo = pg_fetch_array($quoRslt); # Get Customer info db_connect(); $sql = "SELECT * FROM customers WHERE cusnum = '{$cusnum}' AND div = '" . USER_DIV . "'"; $cusRslt = db_exec($sql) or errDie("Unable to get customer information"); if (pg_numrows($cusRslt) < 1) { return "<i class=err>Customer Not Found</i>"; } $cus = pg_fetch_array($cusRslt); /* - Start Copying - */ pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF); db_connect(); # Insert invoice to DB $sql = "INSERT INTO pinvoices(deptid, cusnum, deptname, cusacc, cusname, surname, cusaddr, cusvatno, cordno, ordno, chrgvat, terms, traddisc, salespn, odate, delchrg, subtot, vat, total, balance, comm, printed, done, prd, div)"; $sql .= " VALUES('{$quo['deptid']}', '{$cus['cusnum']}', '{$quo['deptname']}', '{$cus['accno']}', '{$cus['cusname']}', '{$cus['surname']}', '{$cus['addr1']}', '{$cus['vatnum']}', '{$cordno}', '{$quo['ordno']}', '{$quo['chrgvat']}', '{$quo['terms']}', '{$quo['traddisc']}', '{$quo['salespn']}', '{$quo['odate']}', '{$quo['delchrg']}', '{$quo['subtot']}', '{$quo['vat']}' , '{$quo['total']}', '{$quo['total']}', '{$quo['comm']}', 'n', 'y', '" . PRD_DB . "', '" . USER_DIV . "')"; $rslt = db_exec($sql) or errDie("Unable to insert invoice to Cubit.", SELF); # get next ordnum $invid = lastinvid(); # get selected stock in this quote db_connect(); $sql = "SELECT * FROM pos_quote_items WHERE quoid = '{$quoid}' AND div = '" . USER_DIV . "'"; $stkdRslt = db_exec($sql); /* while($stkd = pg_fetch_array($stkdRslt)){ # Insert one by one per quantity if(ext_isSerial("stock", "stkid", $stkd['stkid'])){ $stkd['amt'] = sprint($stkd['amt']/$stkd['qty']); for($i = 0; $i < $stkd['qty']; $i++){ # insert invoice items $sql = "INSERT INTO inv_items(invid, whid, stkid, qty, unitcost, amt, disc, discp, div) VALUES('$invid', '$stkd[whid]', '$stkd[stkid]', '1', '$stkd[unitcost]', '$stkd[amt]', '$stkd[disc]', '$stkd[discp]', '".USER_DIV."')"; $rslt = db_exec($sql) or errDie("Unable to insert invoice items to Cubit.",SELF); } }else{ # insert invoice items $sql = "INSERT INTO inv_items(invid, whid, stkid, qty, unitcost, amt, disc, discp, div) VALUES('$invid', '$stkd[whid]', '$stkd[stkid]', '$stkd[qty]', '$stkd[unitcost]', '$stkd[amt]', '$stkd[disc]', '$stkd[discp]', '".USER_DIV."')"; $rslt = db_exec($sql) or errDie("Unable to insert invoice items to Cubit.",SELF); } # update stock(alloc + qty) $sql = "UPDATE stock SET alloc = (alloc + '$stkd[qty]') WHERE stkid = '$stkd[stkid]' AND div = '".USER_DIV."'"; $rslt = db_exec($sql) or errDie("Unable to update stock to Cubit.",SELF); } # Get selected stock in this quote db_connect(); # Remove access data $sql = "DELETE FROM pos_quotes WHERE quoid = '$quoid' AND div = '".USER_DIV."'"; $rslt = db_exec($sql) or errDie("Unable to update quotes in Cubit.",SELF); $sql = "DELETE FROM pos_quote_items WHERE quoid = '$quoid' AND div = '".USER_DIV."'"; $rslt = db_exec($sql) or errDie("Unable to update quotes in Cubit.",SELF); /* - End Copying - */ pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF); // Final Laytout $write = "\n\t<table border=0 cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "'>\n\t\t<tr><th>Quote accepted</th></tr>\n\t\t<tr class='bg-even'><td>Quote for customer <b>{$cus['cusname']} {$cus['surname']}</b> has been accepted</td></tr>\n\t</table>\n\t<p>\n\t<table border=0 cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "'>\n\t\t<tr><th>Quick Links</th></tr>\n\t\t<tr class='bg-odd'><td><a href='pos-quote-view.php'>View Pos Quotes</a></td></tr>\n\t\t<script>document.write(getQuicklinkSpecial());</script>\n\t</table>"; return $write; }
function write($_POST) { # Set mas execution time to 12 hours ini_set("max_execution_time", 43200); extract($_POST); # validate input require_lib("validate"); $v = new validate(); foreach ($invids as $key => $invid) { $v->isOk($invid, "num", 1, 20, "Invalid recuring invoice number."); $odate[$key] = mkdate($o_year[$key], $o_month[$key], $o_day[$key]); $v->isOk($odate[$key], "date", 1, 1, "Invalid Invoice Date for invoice: {$invid}."); } # display errors, if any $err = ""; if ($v->isError()) { $err = $v->genErrors(); return $err; } pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF); $i = 0; $recinv = new dbSelect("rnons_invoices", "cubit"); $recinv_i = new dbSelect("rnons_inv_items", "cubit"); $newinv = new dbUpdate("nons_invoices", "cubit"); $newinv_i = new dbUpdate("nons_inv_items", "cubit"); foreach ($invids as $key => $invid) { /* fetch recurring invoice info */ $recinv->setOpt(grp(m("where", "invid='{$invid}' AND div='" . USER_DIV . "'"))); $recinv->run(); if ($recinv->num_rows() <= 0) { continue; } $inv = $recinv->fetch_array(); /* create new invoice from recurring invoice */ $cols = grp(m("accepted", " "), m("sdate", raw("CURRENT_DATE")), m("typ", "inv"), m("cusid", $inv["cusid"]), m("cusname", $inv["cusname"]), m("cusaddr", $inv["cusaddr"]), m("cusvatno", $inv["cusvatno"]), m("cordno", $inv["cordno"]), m("chrgvat", $inv["chrgvat"]), m("terms", $inv["terms"]), m("odate", $odate[$key]), m("subtot", $inv["subtot"]), m("vat", $inv["vat"]), m("total", $inv["total"]), m("balance", $inv["total"]), m("done", "n"), m("prd", PRD_DB), m("div", USER_DIV), m("ctyp", $inv["ctyp"]), m("tval", $inv["tval"]), m("jobid", $invid), m("remarks", $inv["remarks"])); $newinv->setOpt($cols); $newinv->run(DB_INSERT); /* fetch last invoice id */ $invid = lastinvid(); /* fetch recurring invoice items */ $recinv_i->setOpt(grp(m("where", "invid='{$inv['invid']}' AND div='" . USER_DIV . "'"))); $recinv_i->run(); /* add items to new non stock invoice */ while ($stkd = $recinv_i->fetch_array()) { $cols = grp(m("invid", $invid), m("qty", $stkd["qty"]), m("unitcost", $stkd["unitcost"]), m("amt", $stkd["amt"]), m("accid", $stkd["account"]), m("description", $stkd["description"]), m("vatex", $stkd["vatex"]), m("div", USER_DIV)); $newinv_i->setOpt($cols); $newinv_i->run(DB_INSERT); } } pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF); $OUT = "\n\t\t<table " . TMPL_tblDflts . ">\n\t\t\t<tr>\n\t\t\t\t<th>Recurring Non-stock Invoices Processed</th>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>New non-stock Invoices have been created from Recurring Invoices</td>\n\t\t\t</tr>\n\t\t</table>\n\t\t<p>\n\t\t<table " . TMPL_tblDflts . ">\n\t\t\t<tr>\n\t\t\t\t<th>Quick Links</th>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td><a href='rec-invoice-view.php'>View Recurring Invoices</a></td>\n\t\t\t</tr>\n\t\t\t<script>document.write(getQuicklinkSpecial());</script>\n\t\t</table>"; return $OUT; }
function create_dummy($deptid) { db_connect(); # Dummy Vars $cusnum = 0; $salespn = ""; $comm = ""; $salespn = ""; $chrgvat = getSetting("SELAMT_VAT"); $odate = date("Y-m-d"); $ordno = ""; $delchrg = "0.00"; $cordno = ""; $terms = 0; $traddisc = 0; $SUBTOT = 0; $vat = 0; $total = 0; $branch = 0; $del_addr = ""; $bankid = cust_bank_id($cusnum); //lock(1); $fcid = getDef_fcid(); # Insert invoice to DB $sql = "\n\t\tINSERT INTO invoices (\n\t\t\tdeptid, cusnum, cordno, ordno, chrgvat, terms, \n\t\t\ttraddisc, salespn, odate, delchrg, subtot, vat, \n\t\t\ttotal, balance, comm, username, printed, done, \n\t\t\tprd, branch, fcid, del_addr, bankid, div\n\t\t) VALUES (\n\t\t\t'{$deptid}', '{$cusnum}', '{$cordno}', '{$ordno}', '{$chrgvat}', '{$terms}', \n\t\t\t'{$traddisc}', '{$salespn}', '{$odate}', '{$delchrg}', '{$SUBTOT}', '{$vat}', \n\t\t\t'{$total}', '{$total}', '{$comm}', '" . USER_NAME . "', 'n', 'n', \n\t\t\t'" . PRD_DB . "','{$branch}', '{$fcid}', '{$del_addr}', '{$bankid}', '" . USER_DIV . "'\n\t\t)"; $rslt = db_exec($sql) or errDie("Unable to insert invoice to Cubit.", SELF); return lastinvid(); }
function invoice() { if (isset($_REQUEST["btn_back"])) { return enter(); } extract($_REQUEST); // Retrieve asset $sql = "SELECT * FROM cubit.assets WHERE id='{$asset_id}'"; $asset_rslt = db_exec($sql) or errDie("Unable to retrieve asset."); $asset_data = pg_fetch_array($asset_rslt); // Retrieve asset group $sql = "SELECT * FROM cubit.assetgrp WHERE grpid='{$asset_data['grpid']}'"; $grp_rslt = db_exec($sql) or errDie("Unable to retrieve asset group."); $grp_data = pg_fetch_array($grp_rslt); // Retrieve customer $sql = "SELECT * FROM cubit.customers WHERE cusnum='{$cust_id}'"; $cust_rslt = db_exec($sql) or errDie("Unable to retrieve customer."); $cust_data = pg_fetch_array($cust_rslt); if ($cust_id > 0) { $ctyp = "s"; $tval = $cust_id; } else { if ($cust_id == "-1") { $ctyp = "c"; $tval = "2"; $cust_data["surname"] = "Cash Sale"; } else { if ($cust_id == "-2") { $ctyp = "ac"; $tval = ""; $cust_data["surname"] = "Cash Sale"; } else { return enter("<li class='err'>Invalid sale option selected.</li>"); } } } $acc = "0"; $vatchrg = $vatinc == "exc" ? "no" : "yes"; $vcd = qryVatcode($vatcode); $va = vatcalca($price * $qty, $vatchrg, "no", 0, $vcd["vat_amount"]); pglib_transaction("BEGIN"); if ($cust_data["surname"] == "Cash Sale") { $cust_data["paddr1"] = ""; $cust_data["vatnum"] = ""; } $sql = "INSERT INTO cubit.nons_invoices(cusname, cusaddr, cusvatno, chrgvat,\r\n\t\t\t\tsdate, odate, subtot, balance, vat, total, done, username, prd,\r\n\t\t\t\tinvnum, typ, ctyp, tval, div, accid, salespn)\r\n\t\t\tVALUES ('{$cust_data['surname']}', '{$cust_data['paddr1']}',\r\n\t\t\t\t'{$cust_data['vatnum']}', '{$vatchrg}', CURRENT_DATE, '{$date}', '{$va['subtotal']}', 0,\r\n\t\t\t\t'{$va['vat']}', '{$va['total']}', 'n', '" . USER_NAME . "', '" . extractMonth($date) . "', 0, \r\n\t\t\t\t'inv', '{$ctyp}', '{$tval}', '" . USER_DIV . "', '{$acc}', 'General')"; db_exec($sql) or errDie("Unable to create invoice"); $ni_id = lastinvid(); $asset_saleacc = gethook("accnum", "salesacc", "name", "saleofassets"); $price_all = $price * $qty; $sql = "INSERT INTO cubit.nons_inv_items (invid, qty, description, div,\r\n\t\t\t\tamt, unitcost, accid, rqty, vatex, cunitcost, asset_id)\r\n\t\t\tVALUES ('{$ni_id}', '{$qty}', '{$asset_data['des']}', '" . USER_DIV . "',\r\n\t\t\t\t'{$price_all}', '{$price}', '{$asset_saleacc}', '0', \r\n\t\t\t\t'{$vatcode}', '0', '{$asset_id}')"; db_exec($sql) or errDie("Unable to create invoice."); pglib_transaction("COMMIT"); header("Location: asset-invoice-print.php?invid={$ni_id}&printpage=t"); exit; }
function create_dummy($deptid, $cusnum) { # Get selected customer info db_connect(); $sql = "SELECT * FROM customers WHERE cusnum = '{$cusnum}' AND div = '" . USER_DIV . "'"; $custRslt = db_exec($sql) or errDie("Unable to get customer information"); $cust = pg_fetch_array($custRslt); $curr = getSymbol($cust['fcid']); $xrate = getRate($cust['fcid']); $trans_date_setting = getCSetting("USE_TRANSACTION_DATE"); if (isset($trans_date_setting) and $trans_date_setting == "yes") { $trans_date_value = getCSetting("TRANSACTION_DATE"); $date_arr = explode("-", $trans_date_value); $date_year = $date_arr[0]; $date_month = $date_arr[1]; $date_day = $date_arr[2]; } else { $date_year = date("Y"); $date_month = date("m"); $date_day = date("d"); } $odate = "{$date_year}-{$date_month}-{$date_day}"; db_connect(); # Insert purchase to DB $sql = "\n\t\tINSERT INTO nons_invoices (\n\t\t\tcusname, cusaddr, cusvatno, chrgvat, fcid, currency, \n\t\t\txrate, odate, sdate, subtot, balance, vat, total, done, username, prd, invnum, typ, ctyp, \n\t\t\ttval, location, div\n\t\t) VALUES (\n\t\t\t'{$cust['cusname']} {$cust['surname']}', '{$cust['addr1']}', '{$cust['vatnum']}', 'yes', '{$cust['fcid']}', '{$curr['symbol']}', \n\t\t\t'{$xrate}', '{$odate}', CURRENT_DATE, 0, 0, 0, 0, 'n', '" . USER_NAME . "', '" . PRD_DB . "', 0, 'inv', 's', \n\t\t\t'{$cusnum}', 'int', '" . USER_DIV . "'\n\t\t)"; $rslt = db_exec($sql) or errDie("Unable to create template Non-Stock Invoice.", SELF); # Get next ordnum $invid = lastinvid(); return $invid; }
function run() { extract($_REQUEST); pglib_transaction("BEGIN"); // Retrieve outstanding rentals $sql = "\n\tSELECT id, user_id, username, order_num, subtotal, vat, total, discount,\n\t\tdelivery, customers.cusnum, surname, addr1, addr2, addr3, accno,\n\t\tvatnum, tel, discount_perc, timestamp, deposit\n\tFROM cubit.hire_trans\n\t\tLEFT JOIN cubit.customers ON hire_trans.cusnum=customers.cusnum\n\t\tLEFT JOIN cubit.users ON hire_trans.user_id=users.userid\n\tWHERE user_id='{$user_id}' AND done='y'"; $rental_rslt = db_exec($sql) or errDie("Unable to retrieve rentals."); $hire_nums = array(); while ($rental_data = pg_fetch_array($rental_rslt)) { $deptid = 2; $time = strtotime($rental_data["timestamp"]); $sql = "SELECT deptname FROM exten.departments WHERE deptid='{$deptid}'"; $deptname_rslt = db_exec($sql) or errDie("Unable to retrieve department."); $deptname = pg_fetch_result($deptname_rslt, 0); // Create hire note $sql = "\n\t\tINSERT INTO hire.hire_invoices (deptid, cusnum, cordno, ordno,\n\t\t\tchrgvat, terms, salespn, odate, printed, comm, done, username,\n\t\t\tdeptname, cusacc, cusname, surname, cusaddr, cusordno, cusvatno,\n\t\t\tprd, invnum, div, prints, disc, discp, delchrg, subtot, traddisc,\n\t\t\tbalance, vat, total, discount, delivery, nbal, rdelchrg, serd,\n\t\t\tpcash, pcheque, pcc, rounding, pchange, delvat, pcredit, vatnum,\n\t\t\ttelno, systime, deposit_type, deposit_amt, custom_txt, collection,\n\t\t\tbranch_addr, timestamp, hire_invid, revision)\n\t\tVALUES ('{$deptid}', '{$rental_data['cusnum']}', '', '', 'inc', '0', '2',\n\t\t\t'" . date("Y-m-d", $time) . "', 'y', '', 'y', '{$rental_data['username']}',\n\t\t\t'{$deptname}', '{$rental_data['accno']}', '', '{$rental_data['surname']}',\n\t\t\t'{$rental_data['addr1']}', '{$rental_data['order_num']}',\n\t\t\t'{$rental_data['vatnum']}', '" . PRD_DB . "', '{$rental_data['id']}',\n\t\t\t'" . USER_DIV . "', '0', '{$rental_data['discount']}',\n\t\t\t'{$rental_data['discount_perc']}', '{$rental_data['delivery']}',\n\t\t\t'{$rental_data['subtotal']}', '{$rental_data['discount']}', '0.00',\n\t\t\t'{$rental_data['vat']}', '{$rental_data['total']}',\n\t\t\t'{$rental_data['discount']}', '{$rental_data['delivery']}', '0.00', '0.00',\n\t\t\t'', '100', '100', '100', '100', '100', '0', '0.00',\n\t\t\t'{$rental_data['vatnum']}', '{$rental_data['tel']}',\n\t\t\t'{$rental_data['timestamp']}', 'CSH', '{$rental_data['deposit']}', '',\n\t\t\t'Client Collect', '0', current_timestamp, '0', '0')"; db_exec($sql) or errDie("Unable to create hire note."); $invid = pglib_lastid("hire.hire_invoices", "invid"); $hire_nums[$rental_data["id"]] = $invid; // Do deposit transaction if required if ($rental_data["deposit"] > 0) { $cash_on_hand = qryAccountsNum("7200", "000"); $cash_on_hand = $cash_on_hand["accid"]; $cust_control = qryAccountsNum("6400", "000"); $cust_control = $cust_control["accid"]; $refnum = getRefnum(); writetrans($cash_on_hand, $cust_control, date("Y-m-d", $time), $refnum, $rental_data["deposit"], "Cash Receipt for " . CUR . "{$rental_data['deposit']} from " . "{$rental_data['surname']} for Deposit on Hire Note {$rental_data['id']}"); $sql = "\n\t\t\tINSERT INTO hire.cash (invid, cash)\n\t\t\tVALUES ('{$invid}', '{$rental_data['deposit']}')"; db_exec($sql) or errDie("Unable to add cash to hire."); // Make ledger record custledger($rental_data["cusnum"], $cust_control, date("Y-m-d", $time), $invid, "Cash Receipt for " . CUR . "{$rental_data['deposit']} from " . "{$rental_data['surname']} for Deposit on Hire Note {$rental_data['id']}", $rental_data["deposit"], "c"); custCT($rental_data["deposit"], $rental_data["cusnum"], date("Y-m-d", $time)); // Turn the amount around to a negative $stmnt_amt = $rental_data["deposit"] - $rental_data["deposit"] * 2; // Record the payment on the statement $sql = "\n\t\t\tINSERT INTO cubit.stmnt(cusnum, invid, docref, amount, date, type,\n\t\t\t\tdiv)\n\t\t\tVALUES('{$rental_data['cusnum']}', '{$invid}', '{$rental_data['id']}',\n\t\t\t\t'{$stmnt_amt}', '" . date("Y-m-d", $time) . "',\n\t\t\t\t'Cash Receipt for " . CUR . "{$rental_data['deposit']} from " . "{$rental_data['surname']} for Deposit on Hire Note {$rental_data['id']}',\n\t\t\t\t'" . USER_DIV . "')"; $stmntRslt = db_exec($sql) or errDie("Unable to add deposit to statement"); // Update customer balance $sql = "\n\t\t\tUPDATE cubit.customers SET balance=balance-'{$rental_data['deposit']}'\n\t\t\tWHERE cusnum='{$rental_data['cusnum']}'"; db_exec($sql) or errDie("Unable to update customer balance."); $sql = "\n\t\t\tUPDATE hire.hire_invoices SET deposit_amt='0'\n\t\t\tWHERE invid='{$invid}'"; db_exec($sql) or errDie("Unable to retrieve hire invoices."); } // Retrieve items on this invoice $sql = "\n\t\tSELECT asset_id, basis, from_date, to_date, half_day, qty,\n\t\t\tweekends, total_days, total\n\t\tFROM cubit.hire_trans_items\n\t\tWHERE hire_id='{$rental_data['id']}'"; $item_rslt = db_exec($sql) or errDie("Unable to retrieve items."); while ($item_data = pg_fetch_array($item_rslt)) { $unitcost = $item_data["total"] / $item_data["qty"]; // Decide which basis to use $hours = 0; $weeks = 0; $days = 0; $months = 0; $total_days = 0; switch ($item_data["basis"]) { case "per_hour": $hours = $item_data["total_days"]; break; case "per_day": $days = $item_data["total_days"]; $total_days = $item_data["total_days"]; break; case "per_week": $week = $item_data["total_days"]; break; case "per_month": $months = $item_data["total_days"]; break; } // Convert booleans into something we can use $half_day = $item_data["half_day"] == "t" ? 1 : 0; $weekends = $item_data["weekends"] == "t" ? 1 : 0; $sql = "\n\t\t\tINSERT INTO hire.hire_invitems (invid, qty, amt, unitcost,\n\t\t\t\tfrom_date, to_date, asset_id, basis, hours, weeks, days,\n\t\t\t\tmonths, half_day, weekends, total_days)\n\t\t\tVALUES ('{$invid}', '{$item_data['qty']}', '{$item_data['total']}',\n\t\t\t\t'{$unitcost}', '{$item_data['from_date']}', '{$item_data['to_date']}',\n\t\t\t\t'{$item_data['asset_id']}', '{$item_data['basis']}', '{$hours}',\n\t\t\t\t'{$weeks}', '{$days}', '{$months}', '{$half_day}', '{$weekends}',\n\t\t\t\t'{$total_days}')"; db_exec($sql) or errDie("Unable to create rental items."); $item_id = pglib_lastid("hire.hire_invitems", "id"); $sql = "\n\t\t\tINSERT INTO hire.assets_hired (invid, asset_id, qty, hired_time,\n\t\t\t\tcust_id, item_id, invnum, value, basis, discount, weekends)\n\t\t\tVALUES ('{$invid}', '{$item_data['asset_id']}', '{$item_data['qty']}',\n\t\t\t\t'{$rental_data['timestamp']}', '{$rental_data['cusnum']}', '{$item_id}',\n\t\t\t\t'{$rental_data['id']}', '{$item_data['total']}', '{$item_data['basis']}',\n\t\t\t\t'0.00', '{$weekends}')"; db_exec($sql) or errDie("Unable to add to assets hired."); } } // Run invoices ---------------------------------------------------------- $sql = "\n\tSELECT id, hire_id, customers.cusnum, order_num, discount_perc, discount,\n\t\tsubtotal, total, vat, timestamp, user_id, surname, addr1, vatnum,\n\t\tusername, delivery\n\tFROM cubit.hire_invoice_trans\n\t\tLEFT JOIN cubit.customers ON hire_invoice_trans.cusnum=customers.cusnum\n\t\tLEFT JOIN cubit.users ON hire_invoice_trans.user_id=users.userid\n\tWHERE done='y' AND user_id='{$user_id}' AND hire_id > 0"; $inv_rslt = db_exec($sql) or errDie("Unable to retrieve invoices."); while ($inv_data = pg_fetch_array($inv_rslt)) { $hire_sales = qryAccountsNum("1050", "000"); $cust_control = qryAccountsNum("6400", "000"); $cash_on_hand = qryAccountsNum("7200", "000"); $hire_sales = $hire_sales["accid"]; $cust_control = $cust_control["accid"]; $cash_on_hand = $cash_on_hand["accid"]; $time = strtotime($inv_data["timestamp"]); $sql = "\n\t\tINSERT INTO cubit.nons_invoices (cusname, cusaddr, cusvatno,\n\t\t\tchrgvat, sdate, done, username, prd, invnum, div, remarks, cusid,\n\t\t\tage, typ, subtot, balance, vat, total, descrip, ctyp, accid,\n\t\t\tfbalance, fsubtot, cordno, terms, odate, systime, bankid,\n\t\t\tcusordno, ncdate, cusnum, discount, delivery, hire_invid,\n\t\t\tcash, cheque, credit)\n\t\tVALUES ('{$inv_data['surname']}', '{$inv_data['addr1']}', '{$inv_data['vatnum']}',\n\t\t\t'yes', '" . date("Y-m-d", $time) . "', 'y', '{$inv_data['username']}',\n\t\t\t'" . PRD_DB . "', '{$inv_data['id']}', '" . USER_DIV . "', '',\n\t\t\t'{$inv_data['cusnum']}', '0', 'inv', '{$inv_data['subtotal']}',\n\t\t\t'{$inv_data['total']}', '{$inv_data['vat']}', '{$inv_data['total']}', '', 's',\n\t\t\t'{$hire_sales}', '0.00', '0.00', '{$inv_data['order_num']}', '0',\n\t\t\t'" . date("Y-m-d", $time) . "', current_timestamp,\n\t\t\t'" . cust_bank_id($inv_data["cusnum"]) . "', '{$inv_data['order_num']}',\n\t\t\t'" . date("Y-m-d", $time) . "', '{$inv_data['cusnum']}',\n\t\t\t'{$inv_data['discount']}', '{$inv_data['delivery']}',\n\t\t\t'" . $hire_nums[$inv_data["hire_id"]] . "', '{$inv_data['total']}', '0', '0')"; db_exec($sql) or errDie("Unable to create non stock invoice."); $invid = lastinvid(); $sql = "\n\t\tSELECT hire_invoice_items_trans.id, asset_id, basis, from_date,\n\t\t\tto_date, half_day, qty, weekends, total_days, total,\n\t\t\tserial, des, grpid\n\t\tFROM cubit.hire_invoice_items_trans\n\t\t\tLEFT JOIN cubit.assets\n\t\t\t\tON hire_invoice_items_trans.asset_id=assets.id\n\t\tWHERE trans_id='{$inv_data['id']}'"; $item_rslt = db_exec($sql) or errDie("Unable to retrieve items."); while ($item_data = pg_fetch_array($item_rslt)) { $unitcost = $item_data["total"] / $item_data["qty"]; $item_id = 0; $sql = "\n\t\t\tSELECT {$item_data['basis']} FROM hire.basis_prices\n\t\t\tWHERE assetid='{$item_data['asset_id']}'"; $rate_rslt = db_exec($sql) or errDie("Unable to retrieve rate."); $rate = pg_fetch_result($rate_rslt, 0); $rate = empty($rate) ? 0.0 : $rate; $sql = "\n\t\t\tSELECT serial, des FROM cubit.assets\n\t\t\tWHERE id='{$item_data['asset_id']}'"; $asset_rslt = db_exec($sql) or errDie("Unable to retrieve assets."); $asset_data = pg_fetch_array($asset_rslt); $sql = "\n\t\t\tINSERT INTO hire.hire_nons_inv_items (invid, qty, description, div,\n\t\t\t\tamt, unitcost, accid, vatex, cunitcost, asset_id, item_id,\n\t\t\t\thired_days, rate)\n\t\t\tVALUES ('{$invid}', '{$item_data['qty']}', '({$asset_data['serial']}) " . "{$asset_data['des']} hired from {$item_data['from_date']} to " . "{$item_data['to_date']}.', '" . USER_DIV . "', '{$item_data['total']}',\n\t\t\t\t'{$unitcost}', '{$hire_sales}', '2', '{$unitcost}',\n\t\t\t\t'{$item_data['asset_id']}', '{$item_id}', '{$item_data['total_days']}',\n\t\t\t\t'{$rate}')"; db_exec($sql) or errDie("Unable to create invoice item."); // Add up revenue $sql = "\n\t\t\tINSERT INTO hire.revenue (group_id, asset_id, total, discount,\n\t\t\t\thire_invnum, inv_invnum, cusname)\n\t\t\tVALUES ('{$item_data['grpid']}', '{$item_data['asset_id']}',\n\t\t\t\t'{$item_data['total']}', '0', '0',\n\t\t\t\t'0', '{$inv_data['surname']}')"; db_exec($sql) or errDie("Unable to update revenue"); $sql = "\n\t\t\tUPDATE hire.assets_hired SET return_time=CURRENT_TIMESTAMP\n\t\t\t\tWHERE item_id='{$item_data['id']}'"; db_exec($sql) or errDie("Unable to update hired assets."); $sql = "\n\t\t\tSELECT serial2 FROM cubit.assets\n\t\t\tWHERE id='{$item_data['asset_id']}'"; $asset_rslt = db_exec($sql) or errDie("Unable to retrieve asset"); $asset_data = pg_fetch_array($asset_rslt); if (!isSerialized($item_data["asset_id"])) { $new_qty = $asset_data["serial2"] + $item_data["qty"]; $sql = "\n\t\t\t\tUPDATE cubit.assets SET serial2=(serial2::numeric + '{$item_data['qty']}')\n\t\t\t\tWHERE id='{$item_data['asset_id']}'"; db_exec($sql) or errDie("Unable to update asset qty."); } } $refnum = getRefnum(); writetrans($cust_control, $hire_sales, date("Y-m-d", $time), $refnum, $inv_data["total"], "Non Stock Sales on invoice No. {$inv_data['id']} " . "customer {$inv_data['surname']}"); // Sales record $sql = "\n\t\tINSERT INTO cubit.salesrec(edate, invid, invnum, debtacc, vat, total,\n\t\t\ttyp, div)\n\t\tVALUES('" . date("Y-m-d", $time) . "', '{$invid}', '{$inv_data['id']}',\n\t\t\t'{$cust_control}', '{$inv_data['vat']}', '{$inv_data['total']}', 'non',\n\t\t\t'" . USER_DIV . "')"; db_exec($sql) or errDie("Unable to create sales record."); // Vat record vatr(2, date("Y-m-d", $time), "OUTPUT", '01', $refnum, "Non-Stock Sales, invoice No.{$inv_data['id']}", $inv_data["total"], $inv_data["vat"]); // Add to statement $sql = "\n\t\tINSERT INTO cubit.stmnt (cusnum, invid, docref, amount, date, type, div)\n\t\tVALUES ('{$inv_data['cusnum']}', '{$invid}', '{$inv_data['order_num']}',\n\t\t\t'{$inv_data['total']}', '" . date("Y-m-d", $time) . "',\n\t\t\t'Hire Invoice {$inv_data['id']}', '" . USER_DIV . "')"; db_exec($sql) or errDie("Unable to add to statement."); // Update customer balance $sql = "\n\t\tUPDATE customers SET balance = (balance + '{$inv_data['total']}')\n\t\tWHERE cusnum='{$inv_data['cusnum']}' AND div='" . USER_DIV . "'"; db_exec($sql) or errDie("Unable to update customer balance."); custledger($inv_data["cusnum"], $hire_sales, date("Y-m-d", $time), $invid, "Hire Invoice No. {$inv_data['id']}", $inv_data["total"], "d"); custDT($inv_data["total"], $inv_data["cusnum"], date("Y-m-d", $time)); } // Clear outstanding tables $sql = "DELETE FROM cubit.hire_trans"; db_exec($sql) or errDie("Unable to remove outstanding (1)"); $sql = "DELETE FROM cubit.hire_trans_items"; db_exec($sql) or errDie("Unable to remove outstanding (2)"); $sql = "DELETE FROM cubit.hire_invoice_trans"; db_exec($sql) or errDie("Unable to remove outstanding (3)"); $sql = "DELETE FROM cubit.hire_invoice_items_trans"; db_exec($sql) or errDie("Unable to remove outstanding (4)"); pglib_transaction("COMMIT"); return enter(); }
function create_dummy($deptid, $ctyp, $tval, $acc) { db_connect(); # Insert purchase to DB $sql = "INSERT INTO nons_invoices(cusname, cusaddr, cusvatno, chrgvat, sdate, odate, subtot,\r\n\t\t\t\tbalance, vat, total, done, username, prd, invnum, typ, ctyp, tval, div,accid)"; $sql .= " VALUES('', '', '', 'yes', CURRENT_DATE, CURRENT_DATE, 0, 0, 0, 0, 'n', '" . USER_NAME . "', '" . PRD_DB . "',\r\n\t\t\t0, 'inv', '{$ctyp}','{$tval}','" . USER_DIV . "','{$acc}')"; $rslt = db_exec($sql) or errDie("Unable to create template Non-Stock Invoice.", SELF); return lastinvid(); }
function invoice() { extract($_REQUEST); $invnum = divlastid("inv"); $sql = "INSERT INTO cubit.invoices(deptid, chrgvat, odate, printed, done, \n\t\t\t\tusername, prd, invnum, div, systime, barcode, pickslip_id)\n\t\t\tVALUES ('" . USER_DIV . "', 'inc', current_date, 'n', 'n',\n\t\t\t\t'" . USER_NAME . "', '" . PRD_DB . "', '{$invnum}', '" . USER_DIV . "',\n\t\t\t\tcurrent_date, '{$barcode}', '{$slip_id}')"; $inv_rslt = db_exec($sql) or errDie("Unable to retrieve invoice."); $invid = lastinvid(); $sql = "SELECT stkid, whid, qty, vatcode FROM cubit.pickslip_stk\n\t\t\t\tLEFT JOIN cubit.stock ON pickslip_stk.stock_id=stock.stkid\n\t\t\t\tLEFT JOIN cubit.vatcodes WHERE stock.vatcode=vatcodes.code\n\t\t\tWHERE pickslip_id='{$slip_id}'"; $stock_rslt = db_exec($sql) or errDie("Unable to retrieve stock."); while (list($stkid, $whid, $qty, $vatcode) = pg_fetch_array($stock_rslt)) { $sql = "INSERT INTO cubit.inv_items (invid, whid, stkid, qty, div,\n\t\t\t\t\tvatcode)\n\t\t\t\tVALUES ('{$invid}', '{$whid}', '{$stkid}', '{$qty}', '" . USER_DIV . "',\n\t\t\t\t\t'{$vatcode}')"; db_exec($sql) or errDie("Unable to add inventory items."); } $OUTPUT = "\n\t<script>\n\t\tpopupOpen(\"cust-credit-stockinv.php?invid={$invid}&cont=true\");\n\t\tmove(\"" . SELF . "\");\n\t</script>"; return $OUTPUT; }
function write($_POST) { #get vars foreach ($_POST as $key => $value) { ${$key} = $value; } # validate input require_lib("validate"); $v = new validate(); $v->isOk($quoid, "num", 1, 20, "Invalid quote number."); # display errors, if any $err = ""; if ($v->isError()) { $errors = $v->getErrors(); foreach ($errors as $e) { $err .= "<li class=err>" . $e["msg"]; } return $err; } # Get quote info db_connect(); $sql = "SELECT * FROM quotes WHERE quoid = '{$quoid}'"; $quoRslt = db_exec($sql) or errDie("Unable to get quote information"); if (pg_numrows($quoRslt) < 1) { return "<li class=err>Quote Not Found</li>"; } $quo = pg_fetch_array($quoRslt); db_connect(); /* - Start Copying - */ pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF); # insert invoice to DB $sql = "INSERT INTO invoices(deptid, cusnum, cordno, ordno, chrgvat, terms, traddisc, salespn, odate, delchrg, subtot, vat, total, balance, comm, printed)"; $sql .= " VALUES('{$quo['deptid']}', '{$quo['cusnum']}', '{$quo['cordno']}', '{$quo['ordno']}', '{$quo['chrgvat']}', '{$quo['terms']}', '{$quo['traddisc']}', '{$quo['salespn']}', '{$quo['odate']}', '{$quo['delchrg']}', '{$quo['subtot']}', '{$quo['vat']}' , '{$quo['total']}', '{$quo['total']}', '{$quo['comm']}', 'n')"; $rslt = db_exec($sql) or errDie("Unable to insert invoice to Cubit.", SELF); # get next ordnum $invid = lastinvid(); # get selected stock in this quote db_connect(); $sql = "SELECT * FROM quote_items WHERE quoid = '{$quoid}'"; $stkdRslt = db_exec($sql); while ($stkd = pg_fetch_array($stkdRslt)) { # insert invoice items $sql = "INSERT INTO inv_items(invid, whid, stkid, qty, unitcost, amt, disc, discp) VALUES('{$invid}', '{$stkd['whid']}', '{$stkd['stkid']}', '{$stkd['qty']}', '{$stkd['unitcost']}', '{$stkd['amt']}', '{$stkd['disc']}', '{$stkd['discp']}')"; $rslt = db_exec($sql) or errDie("Unable to insert invoice items to Cubit.", SELF); # update stock(alloc + qty) # $sql = "UPDATE stock SET alloc = (alloc + '$stkd[qty]') WHERE stkid = '$stkd[stkid]'"; # $rslt = db_exec($sql) or errDie("Unable to update stock to Cubit.",SELF); } # get selected stock in this quote db_connect(); $sql = "SELECT * FROM quote_data WHERE quoid = '{$quoid}'"; $dataRslt = db_exec($sql); $data = pg_fetch_array($dataRslt); $sql = "INSERT INTO inv_data(invid, dept, customer, addr1, addr2, addr3) VALUES('{$invid}', '{$data['dept']}', '{$data['customer']}', '{$data['addr1']}', '{$data['addr2']}', '{$data['addr3']}')"; $rslt = db_exec($sql) or errDie("Unable to insert invoice data to Cubit.", SELF); $sql = "UPDATE quotes SET accepted = 'y' WHERE quoid = '{$quoid}'"; $rslt = db_exec($sql) or errDie("Unable to update quotes in Cubit.", SELF); pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF); /* - End Copying - */ }
function create_dummy($deptid) { db_connect(); # Dummy Vars $cusnum = 0; $salespn = ""; $comm = ""; $salespn = ""; $chrgvat = getSetting("SELAMT_VAT"); $odate = date("Y-m-d"); $ordno = ""; $delchrg = "0.00"; $cordno = ""; $terms = 0; $traddisc = 0; $SUBTOT = 0; $vat = 0; $total = 0; $fcid = getDef_fcid(); $curr = getSymbol($fcid); $xrate = getRate($fcid); # insert invoice to DB $sql = "\n\t\tINSERT INTO invoices (\n\t\t\tdeptid, cusnum, cordno, ordno, chrgvat, fcid, currency, xrate, terms, \n\t\t\ttraddisc, salespn, odate, delchrg, subtot, vat, total, balance, comm, \n\t\t\tusername, location, printed, done, prd, div\n\t\t) VALUES (\n\t\t\t'{$deptid}', '{$cusnum}', '{$cordno}', '{$ordno}', '{$chrgvat}', '{$fcid}', '{$curr['symbol']}', '{$xrate}', '{$terms}', \n\t\t\t'{$traddisc}', '{$salespn}', '{$odate}', '{$delchrg}', '{$SUBTOT}', '{$vat}' , '{$total}', '{$total}', '{$comm}', \n\t\t\t'" . USER_NAME . "', 'int', 'n', 'n', '" . PRD_DB . "', '" . USER_DIV . "'\n\t\t)"; $rslt = db_exec($sql) or errDie("Unable to insert invoice to Cubit.", SELF); # get next ordnum $invid = lastinvid(); return $invid; }
function run() { extract($_REQUEST); // Update returns $sql = "\r\n\tSELECT id, item_id, timestamp, asset_id, qty\r\n\tFROM cubit.hire_trans_returned WHERE processed='f'"; $return_rslt = db_exec($sql) or errDie("Unable to retrieve returned items"); while ($return_data = pg_fetch_array($return_rslt)) { $sql = "\r\n\t\tSELECT max(id) FROM hire.assets_hired\r\n\t\tWHERE asset_id='{$return_data['asset_id']}' AND return_time IS NULL"; $ahid_rslt = db_exec($sql) or errDie("Unable to retrieve last rental."); $ahid = pg_fetch_result($ahid_rslt, 0); if (!empty($ahid)) { $sql = "\r\n\t\t\tUPDATE hire.assets_hired SET return_time='{$return_data['timestamp']}',\r\n\t\t\t\treturned_qty='{$return_data['qty']}'\r\n\t\t\tWHERE id='{$ahid}'"; db_exec($sql) or errDie("Unable to update returns."); } $sql = "DELETE FROM hire.hire_invitems WHERE asset_id='{$return_data['asset_id']}'"; db_exec($sql) or errDie("Unable to remove item."); $sql = "\r\n\t\tUPDATE cubit.hire_trans_returned SET processed='t'\r\n\t\tWHERE id='{$return_data['id']}'"; db_exec($sql) or errDie("Unable to update processed"); } $sql = "\r\n\tSELECT id, customers.cusnum, customers.surname, customers.paddr1,\r\n\t\tcustomers.vatnum, customers.bankid, customers.accno, customers.addr1,\r\n\t\tcustomers.tel, order_num, timestamp, discount, discount_perc, user_id,\r\n\t\tsubtotal, vat,\ttotal, deposit, delivery, departments.deptname,\r\n\t\tdepartments.debtacc, users.username\r\n\tFROM cubit.hire_trans\r\n\t\tLEFT JOIN cubit.customers ON hire_trans.cusnum=customers.cusnum\r\n\t\tLEFT JOIN exten.departments ON customers.deptid=departments.deptid\r\n\t\tLEFT JOIN cubit.users ON hire_trans.user_id=users.userid\r\n\tWHERE done='t' AND user_id='{$user_id}' AND customers.cusnum > 0 AND processed='0'"; $trans_rslt = db_exec($sql) or errDie("Unable to retrieve transactions."); $hire_nums = array(); while ($trans_data = pg_fetch_array($trans_rslt)) { $deptid = 2; $time = strtotime($trans_data["timestamp"]); $sql = "SELECT deptname FROM exten.departments WHERE deptid='{$deptid}'"; $deptname_rslt = db_exec($sql) or errDie("Unable to retrieve department"); $deptname = pg_fetch_result($deptname_rslt, 0); // Create hire note $sql = "\r\n\t\tINSERT INTO hire.hire_invoices (deptid, cusnum, cordno, ordno,\r\n\t\t\tchrgvat, terms, salespn, odate, printed, comm, done, username,\r\n\t\t\tdeptname, cusacc, cusname, surname, cusaddr, cusordno, cusvatno,\r\n\t\t\tprd, invnum, div, prints, disc, discp, delchrg, subtot, traddisc,\r\n\t\t\tbalance, vat, total, discount, delivery, nbal, rdelchrg, serd,\r\n\t\t\tpcash, pcheque, pcc, rounding, pchange, delvat, pcredit, vatnum,\r\n\t\t\ttelno, systime, deposit_type, deposit_amt, custom_txt, collection,\r\n\t\t\tbranch_addr, timestamp, hire_invid, revision)\r\n\t\tVALUES ('{$deptid}', '{$trans_data['cusnum']}', '', '', 'inc', '0', '2',\r\n\t\t\t'" . date("Y-m-d", $time) . "', 'y', '', 'y', '{$trans_data['username']}',\r\n\t\t\t'{$deptname}', '{$trans_data['accno']}', '', '{$trans_data['surname']}',\r\n\t\t\t'{$trans_data['addr1']}', '{$trans_data['order_num']}',\r\n\t\t\t'{$trans_data['vatnum']}', '" . PRD_DB . "', '{$trans_data['id']}',\r\n\t\t\t'" . USER_DIV . "', '0', '{$trans_data['discount']}',\r\n\t\t\t'{$trans_data['discount_perc']}', '{$trans_data['delivery']}',\r\n\t\t\t'{$trans_data['subtotal']}', '{$trans_data['discount']}', '0.00',\r\n\t\t\t'{$trans_data['vat']}', '{$trans_data['total']}',\r\n\t\t\t'{$trans_data['discount']}', '{$trans_data['delivery']}', '0.00', '0.00',\r\n\t\t\t'', '100', '100', '100', '100', '100', '0', '0.00',\r\n\t\t\t'{$trans_data['vatnum']}', '{$trans_data['tel']}',\r\n\t\t\t'{$trans_data['timestamp']}', 'CSH', '{$trans_data['deposit']}', '',\r\n\t\t\t'Client Collect', '0', current_timestamp, '0', '0')"; db_exec($sql) or errDie("Unable to create hire note."); $hire_invid = pglib_lastid("hire.hire_invoices", "invid"); $hire_nums[$trans_data["id"]] = $hire_invid; $sql = "\r\n\t\tSELECT count(id) FROM cubit.hire_trans_items\r\n\t\tWHERE hire_id='{$trans_data['id']}'"; $count_rslt = db_exec($sql) or errDie("Unable to retrieve rental count."); $count_rental = pg_fetch_result($count_rslt, 0); $sql = "\r\n\t\tSELECT count(id) FROM cubit.video_stock_items\r\n\t\tWHERE hire_id='{$trans_data['id']}'"; $count_rslt = db_exec($sql) or errDie("Unable to retrieve stock count."); $count_stock = pg_fetch_result($count_rslt, 0); $sql = "\r\n\t\tSELECT count(id) FROM cubit.hire_trans_contracts\r\n\t\tWHERE hire_id='{$trans_data['id']}'"; $count_rslt = db_exec($sql) or errDie("Unable to retrieve contract count."); $count_contract = pg_fetch_result($count_rslt, 0); $count = $count_rental + $count_stock + $count_contract; if (empty($count)) { $sql = "DELETE FROM cubit.hire_trans WHERE id='{$trans_data['id']}'"; db_exec($sql) or errDie("Unable to remove empty transaction."); continue; } pglib_transaction("BEGIN"); // Create invoice $invnum = divlastid("inv", USER_DIV); $accid = qryAccountsNum(1050, 00); $accid = $accid["accid"]; $sql = "\r\n\t\tINSERT INTO cubit.nons_invoices (cusname, cusaddr, cusvatno, chrgvat,\r\n\t\t\tsdate, done, username, prd, invnum, div, cusid, typ, subtot,\r\n\t\t\tbalance, vat, total, ctyp, accid, tval, cordno, odate, salespn,\r\n\t\t\tsystime, bankid, ncdate, cusnum, discount, cash)\r\n\t\tVALUES ('{$trans_data['surname']}', '{$trans_data['paddr1']}',\r\n\t\t\t'{$trans_data['vatnum']}', 'yes', '{$trans_data['timestamp']}', 'n',\r\n\t\t\t'{$user_id}', '" . PRD_DB . "', '{$invnum}', '" . USER_DIV . "',\r\n\t\t\t'{$trans_data['cusnum']}', 'inv', '{$trans_data['subtotal']}',\r\n\t\t\t'{$trans_data['total']}', '{$trans_data['vat']}', '{$trans_data['total']}',\r\n\t\t\t's', '{$accid}', '2', '{$trans_data['order_num']}',\r\n\t\t\t'{$trans_data['timestamp']}', 'General', '{$trans_data['timestamp']}',\r\n\t\t\t'{$trans_data['bankid']}', '{$trans_data['timestamp']}',\r\n\t\t\t'{$trans_data['cusnum']}', '{$trans_data['discount']}' ,\r\n\t\t\t'{$trans_data['total']}')"; db_exec($sql) or errDie("Unable to create new non stock invoice."); // Retrieve invoice id $invid = lastinvid(); // Retrieve individual items $sql = "\r\n\t\tSELECT hire_trans_items.id, asset_id, basis, from_date, to_date, qty, total_days, total,\r\n\t\t\tdiscount_perc, assets.des AS asset_name, returned, grpid\r\n\t\tFROM cubit.hire_trans_items\r\n\t\t\tLEFT JOIN cubit.assets ON hire_trans_items.asset_id=assets.id\r\n\t\tWHERE hire_id='{$trans_data['id']}'"; $items_rslt = db_exec($sql) or errDie("Unable to retrieve items."); $stkaccs = array(); while ($items_data = pg_fetch_array($items_rslt)) { $description = "{$items_data['asset_name']} Rented Out"; $unitcost = $items_data["total"] / $items_data["qty"]; // Add to hire note $sql = "\r\n\t\t\tINSERT INTO hire.hire_invitems (invid, qty, amt, unitcost,\r\n\t\t\t\tfrom_date, to_date, asset_id, basis, hours, weeks, days,\r\n\t\t\t\tmonths, half_day, total_days)\r\n\t\t\tVALUES ('{$hire_invid}', '{$items_data['qty']}', '{$items_data['total']}',\r\n\t\t\t\t'{$unitcost}', '{$items_data['from_date']}', '{$items_data['to_date']}',\r\n\t\t\t\t'{$items_data['asset_id']}', '{$items_data['basis']}', '0',\r\n\t\t\t\t'0', '{$items_data['total_days']}', '0', '0', '{$items_data['total_days']}')"; db_exec($sql) or errDie("Unable to create rental items."); $item_id = pglib_lastid("hire.hire_invitems", "id"); // Add to assets hired $sql = "\r\n\t\t\tINSERT INTO hire.assets_hired (invid, asset_id, qty, hired_time,\r\n\t\t\t\tcust_id, item_id, invnum, value, basis, discount, weekends)\r\n\t\t\tVALUES ('{$hire_invid}', '{$items_data['asset_id']}', '{$items_data['qty']}',\r\n\t\t\t\t'{$trans_data['timestamp']}', '{$trans_data['cusnum']}', '{$item_id}',\r\n\t\t\t\t'{$trans_data['id']}', '{$items_data['total']}', '{$items_data['basis']}',\r\n\t\t\t\t'0.00', '0')"; db_exec($sql) or errDie("Unable to add to assets hired."); // Add to non stock invoice $sql = "\r\n\t\t\tINSERT INTO cubit.nons_inv_items (invid, qty, description, div,\r\n\t\t\t\tamt, unitcost, accid, vatex)\r\n\t\t\tVALUES ('{$invid}', '{$items_data['qty']}', '{$description}',\r\n\t\t\t\t'" . USER_DIV . "', '{$items_data['total']}', '{$unitcost}', '{$accid}',\r\n\t\t\t\t'2')"; db_exec($sql) or errDie("Unable to create non stock item."); $id = pglib_lastid("cubit.nons_inv_items", "id"); $stkaccs[$id] = $accid; $sql = "\r\n\t\t\tSELECT {$items_data['basis']} FROM hire.basis_prices\r\n\t\t\tWHERE assetid='{$items_data['asset_id']}'"; $rate_rslt = db_exec($sql) or errDie("Unable to retrieve rate."); $rate = pg_fetch_result($rate_rslt, 0); $rate = empty($rate) ? 0.0 : $rate; $sql = "\r\n\t\t\tSELECT serial, des FROM cubit.assets\r\n\t\t\tWHERE id='{$items_data['asset_id']}'"; $asset_rslt = db_exec($sql) or errDie("Unable to retrieve assets."); $asset_data = pg_fetch_array($asset_rslt); $sql = "\r\n\t\t\tINSERT INTO hire.hire_nons_inv_items (invid, qty, description, div,\r\n\t\t\t\tamt, unitcost, accid, vatex, cunitcost, asset_id, item_id,\r\n\t\t\t\thired_days, rate)\r\n\t\t\tVALUES ('{$hire_invid}', '{$items_data['qty']}', '({$asset_data['serial']}) " . "{$asset_data['des']} hired from {$items_data['from_date']} to " . "{$items_data['to_date']}.', '" . USER_DIV . "', '{$items_data['total']}',\r\n\t\t\t\t'{$unitcost}', '{$accid}', '2', '{$unitcost}',\r\n\t\t\t\t'{$items_data['asset_id']}', '{$item_id}', '{$items_data['total_days']}',\r\n\t\t\t\t'{$rate}')"; db_exec($sql) or errDie("Unable to create invoice item."); // Add up revenue $sql = "\r\n\t\t\tINSERT INTO hire.revenue (group_id, asset_id, total, discount,\r\n\t\t\t\thire_invnum, inv_invnum, cusname)\r\n\t\t\tVALUES ('{$items_data['grpid']}', '{$items_data['asset_id']}',\r\n\t\t\t\t'{$items_data['total']}', '0', '0',\r\n\t\t\t\t'0', '{$trans_data['surname']}')"; db_exec($sql) or errDie("Unable to update revenue"); // Flag as processed # $sql = " # UPDATE cubit.hire_trans_returned SET processed=true # WHERE item_id='$items_data[id]'"; # db_exec($sql) or errDie("Unable to process returned item."); } $sql = "\r\n\t\tSELECT id, stock_id, stkcod, stkdes, qty, unitprice, total, cost_price\r\n\t\tFROM cubit.video_stock_items\r\n\t\t\tLEFT JOIN cubit.stock ON video_stock_items.stock_id=stock.stkid\r\n\t\tWHERE hire_id='{$trans_data['id']}'"; $stock_rslt = db_exec($sql) or errDie("Unable to retrieve stock."); $cost_prices = array(); while ($stock_data = pg_fetch_array($stock_rslt)) { $inventory_acc = qryAccountsNum(6350, 00); $inventory_acc = $inventory_acc["accid"]; $description = "({$stock_data['stkcod']}) {$stock_data['stkdes']} Sold"; $sql = "\r\n\t\t\tINSERT INTO cubit.nons_inv_items (invid, qty, description, div,\r\n\t\t\t\tamt, unitcost, accid, vatex)\r\n\t\t\tVALUES ('{$invid}', '{$stock_data['qty']}', '{$description}',\r\n\t\t\t\t'" . USER_DIV . "', '{$stock_data['total']}', '{$stock_data['unitprice']}',\r\n\t\t\t\t'{$inventory_acc}', '2')"; db_exec($sql) or errDie("Unable to create non stock item."); $nonsinv_id = pglib_lastid("cubit.nons_inv_items", "id"); $cost_prices[$nonsinv_id] = $stock_data["cost_price"]; // Update stock balance $sql = "\r\n\t\t\tUPDATE cubit.stock SET units=(units-'{$stock_data['qty']}')\r\n\t\t\tWHERE stkid='{$stock_data['stock_id']}'"; db_exec($sql) or errDie("Unable to update stock balance."); } $sql = "\r\n\t\tSELECT id, stock_id, hire_id, qty, unitprice, total, cost_price, hire_trans_contracts.units\r\n\t\tFROM cubit.hire_trans_contracts\r\n\t\t\tLEFT JOIN cubit.stock ON hire_trans_contracts.stock_id=stock.stkid\r\n\t\tWHERE hire_id='{$trans_data['id']}'"; $contract_rslt = db_exec($sql) or errDie("Unable to retrieve contracts."); while ($contract_data = pg_fetch_array($contract_rslt)) { $hs_acc = qryAccountsNum(1050, 00); $hs_acc = $hs_acc["accid"]; $description = "Contract {$stock_data['stkdes']} Sold"; $sql = "\r\n\t\t\tINSERT INTO cubit.nons_inv_items (invid, qty, description, div, amt,\r\n\t\t\t\tunitcost, accid, vatex)\r\n\t\t\tVALUES ('{$invid}', '{$contract_data['qty']}', '{$description}', '" . USER_DIV . "',\r\n\t\t\t\t'{$contract_data['total']}', '{$contract_data['unitprice']}', '{$hs_acc}', '2')"; db_exec($sql) or errDie("Unable to create non stock item."); // Update stock balance $sql = "\r\n\t\t\tUPDATE cubit.stock SET units=(units-'{$contract_data['qty']}')\r\n\t\t\tWHERE stkid='{$contract_data['stock_id']}'"; db_exec($sql) or errDie("Unable to update stock balance."); } print cwrite(array("invid" => $invid, "ctyp" => "s", "cusnum" => $trans_data["cusnum"], "stkaccs" => $stkaccs, "cost_prices" => $cost_prices)); $sql = "UPDATE cubit.hire_trans SET processed='1' WHERE id='{$trans_data['id']}'"; db_exec($sql) or errDie("Unable to update transaction item."); #$sql = "DELETE FROM cubit.hire_trans WHERE id='$trans_data[id]'"; #db_exec($sql) or errDie("Unable to remove transaction item."); } pglib_transaction("COMMIT"); return enter(); }
function create_dummy($deptid) { db_connect(); # Dummy Vars $cusnum = 0; $salespn = ""; $comm = ""; $salespn = ""; $chrgvat = getSetting("SELAMT_VAT"); $odate = date("Y-m-d"); $ordno = ""; $delchrg = "0.00"; $cordno = ""; $terms = 0; $traddisc = 0; $SUBTOT = 0; $vat = 0; $total = 0; # Insert invoice to DB $sql = "INSERT INTO invoices(deptid, cusnum, cordno, ordno, chrgvat, terms, traddisc, salespn, odate, delchrg, subtot, vat, total, balance, comm, username, printed, done, prd, div)"; $sql .= " VALUES('{$deptid}', '{$cusnum}', '{$cordno}', '{$ordno}', '{$chrgvat}', '{$terms}', '{$traddisc}', '{$salespn}', '{$odate}', '{$delchrg}', '{$SUBTOT}', '{$vat}' , '{$total}', '{$total}', '{$comm}', '" . USER_NAME . "', 'n', 'n', '" . PRD_DB . "', '" . USER_DIV . "')"; $rslt = db_exec($sql) or errDie("Unable to insert invoice to Cubit.", SELF); # get next ordnum $invid = lastinvid(); return $invid; }
function write($_POST) { # Get vars extract($_POST); # validate input require_lib("validate"); $v = new validate(); $v->isOk($sordid, "num", 1, 20, "Invalid Sales Order number."); # display errors, if any $err = ""; if ($v->isError()) { $errors = $v->getErrors(); foreach ($errors as $e) { $err .= "<li class='err'>" . $e["msg"] . "</li>"; } return $err; } # Get Sales Order info db_connect(); $sql = "SELECT * FROM sorders WHERE sordid = '{$sordid}' AND div = '" . USER_DIV . "'"; $sordRslt = db_exec($sql) or errDie("Unable to get Sales Order information"); if (pg_numrows($sordRslt) < 1) { return "<li class='err'>Sales Order Not Found</li>"; } $sord = pg_fetch_array($sordRslt); /* - Start Copying - */ pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF); db_connect(); # Insert invoice to DB $sql = "\n\t\tINSERT INTO invoices (\n\t\t\tdeptid, cusnum, deptname, cusacc, cusname, surname, \n\t\t\tcusaddr, cusvatno, cordno, ordno, chrgvat, terms, \n\t\t\ttraddisc, salespn, odate, delchrg, subtot, vat, \n\t\t\tdiscount, delivery, total, balance, comm, printed, \n\t\t\tdone, serd, prd, div, docref, delvat\n\t\t) VALUES (\n\t\t\t'{$sord['deptid']}', '{$sord['cusnum']}', '{$sord['deptname']}', '{$sord['cusacc']}', '{$sord['cusname']}', '{$sord['surname']}', \n\t\t\t'{$sord['cusaddr']}', '{$sord['cusvatno']}', '{$sord['cordno']}', '{$sord['ordno']}', '{$sord['chrgvat']}', '{$sord['terms']}', \n\t\t\t'{$sord['traddisc']}', '{$sord['salespn']}', '{$sord['odate']}', '{$sord['delchrg']}', '{$sord['subtot']}', '{$sord['vat']}' , \n\t\t\t'{$sord['discount']}', '{$sord['delivery']}', '{$sord['total']}', '{$sord['total']}', '{$sord['comm']}', 'n', \n\t\t\t'y', 'n', '" . PRD_DB . "', '" . USER_DIV . "', '{$sord['pinvnum']}', '{$sord['delvat']}'\n\t\t)"; $rslt = db_exec($sql) or errDie("Unable to insert invoice to Cubit.", SELF); # get next ordnum $invid = lastinvid(); # get selected stock in this Sales Order db_connect(); $sql = "SELECT *, qty - iqty AS rqty FROM sorders_items WHERE sordid = '{$sordid}' AND div = '" . USER_DIV . "'"; $stkdRslt = db_exec($sql); $serd = "y"; while ($stkd = pg_fetch_array($stkdRslt)) { $sord_itemid = $stkd['id']; $iqty[$sord_itemid] = sprint3($iqty[$sord_itemid]); if (!isset($iqty[$sord_itemid]) or $iqty[$sord_itemid] <= 0 or strlen($iqty[$sord_itemid]) < 1) { continue; } if ($iqty[$sord_itemid] > $stkd['rqty']) { pglib_transaction("ROLLBACK") or errDie("Unable to complete transaction."); return details(array("sordid" => $sordid), "<li class='err'>Invalid Qty To Invoice.</li>"); } # Insert one by one per quantity if (ext_isSerial("stock", "stkid", $stkd['stkid'])) { $stkd['amt'] = sprint($stkd['amt'] / $stkd['qty']); $serd = "n"; for ($i = 0; $i < $stkd['qty']; $i++) { # insert invoice items $stkd['vatcode'] += 0; $stkd['account'] += 0; $sql = "\n\t\t\t\t\tINSERT INTO inv_items (\n\t\t\t\t\t\tinvid, whid, stkid, qty, unitcost, amt, \n\t\t\t\t\t\tdisc, discp, div, vatcode, description, account\n\t\t\t\t\t) VALUES (\n\t\t\t\t\t\t'{$invid}', '{$stkd['whid']}', '{$stkd['stkid']}', '1', '{$stkd['unitcost']}', '{$stkd['amt']}', \n\t\t\t\t\t\t'{$stkd['disc']}', '{$stkd['discp']}', '" . USER_DIV . "', '{$stkd['vatcode']}', '{$stkd['description']}', '{$stkd['account']}'\n\t\t\t\t\t)"; $rslt = db_exec($sql) or errDie("Unable to insert invoice items to Cubit.", SELF); } } else { $stkd['vatcode'] += 0; $stkd['account'] += 0; # insert invoice items $sql = "\n\t\t\t\tINSERT INTO inv_items (\n\t\t\t\t\tinvid, whid, stkid, qty, unitcost, amt, \n\t\t\t\t\tdisc, discp, div, vatcode, description, account\n\t\t\t\t) VALUES (\n\t\t\t\t\t'{$invid}', '{$stkd['whid']}', '{$stkd['stkid']}', '{$iqty[$sord_itemid]}', '{$stkd['unitcost']}', '{$stkd['amt']}', \n\t\t\t\t\t'{$stkd['disc']}', '{$stkd['discp']}', '" . USER_DIV . "', '{$stkd['vatcode']}', '{$stkd['description']}', '{$stkd['account']}'\n\t\t\t\t)"; $rslt = db_exec($sql) or errDie("Unable to insert invoice items to Cubit.", SELF); # update the sales order information $upd_sql = "UPDATE sorders_items SET iqty = iqty + '{$iqty[$sord_itemid]}' WHERE sordid = '{$stkd['sordid']}' AND id = '{$sord_itemid}'"; $run_upd = db_exec($upd_sql) or errDie("Unable to update sales order information."); } } # get selected stock in this Sales Order db_connect(); $sql = "SELECT * FROM sord_data WHERE sordid = '{$sordid}' AND div = '" . USER_DIV . "'"; $dataRslt = db_exec($sql); $data = pg_fetch_array($dataRslt); $sql = "INSERT INTO inv_data (invid, dept, customer, addr1, div) VALUES ('{$invid}', '{$data['dept']}', '{$data['customer']}', '{$data['addr1']}', '" . USER_DIV . "')"; $rslt = db_exec($sql) or errDie("Unable to insert invoice data to Cubit.", SELF); # check if there is anything still left $get_check = "SELECT * FROM sorders_items WHERE sordid = '{$sordid}' AND (qty - iqty) > 0"; $run_check = db_exec($get_check) or errDie("Unable to check sales order completed status."); if (pg_numrows($run_check) <= 0) { # set to accepted $sql = "UPDATE sorders SET accepted = 'y' WHERE sordid = '{$sordid}' AND div = '" . USER_DIV . "'"; $rslt = db_exec($sql) or errDie("Unable to update quotes in Cubit.", SELF); } # set to not serialised $sql = "UPDATE invoices SET serd = '{$serd}' WHERE invid = '{$invid}' AND div = '" . USER_DIV . "'"; $rslt = db_exec($sql) or errDie("Unable to update quotes in Cubit.", SELF); /* remove access data $sql = "DELETE FROM sorders WHERE sordid = '$sordid' AND div = '".USER_DIV."'"; $rslt = db_exec($sql) or errDie("Unable to update Sales Orders on Cubit.",SELF); $sql = "DELETE FROM sorders_items WHERE sordid = '$sordid' AND div = '".USER_DIV."'"; $rslt = db_exec($sql) or errDie("Unable to update Sales Orders in Cubit.",SELF); $sql = "DELETE FROM sord_data WHERE sordid = '$sordid' AND div = '".USER_DIV."'"; $rslt = db_exec($sql) or errDie("Unable to update Sales Orders in Cubit.",SELF); */ # End updates pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF); header("Location: cust-credit-stockinv.php?invid={$invid}&cont=true&letters=&done="); exit; /* - End Copying - */ // Final Laytout $write = "\n\t\t<table " . TMPL_tblDflts . ">\n\t\t\t<tr>\n\t\t\t\t<th>Sales Order accepted</th>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>Sales Order for customer <b>{$sord['cusname']} {$sord['surname']}</b> has been accepted</td>\n\t\t\t</tr>\n\t\t</table>\n\t\t<p>\n\t\t<table " . TMPL_tblDflts . ">\n\t\t\t<tr>\n\t\t\t\t<th>Quick Links</th>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td><a href='sorder-view.php'>View Sales Orders</a></td>\n\t\t\t</tr>\n\t\t\t<script>document.write(getQuicklinkSpecial());</script>\n\t\t</table>"; return $write; }
function newPos() { extract($_REQUEST); $deptid = 2; $salespn = ""; $comm = ""; $salespn = ""; $chrgvat = getSetting("SELAMT_VAT"); $odate = date("Y-m-d"); $ordno = ""; $delchrg = "0.00"; $cordno = ""; $terms = 0; $traddisc = 0; $SUBTOT = 0; $vat = 0; $total = 0; $vatnum = ""; $cusacc = ""; $telno = ""; $sql = "\r\n\t\tINSERT INTO cubit.pinvoices (\r\n\t\t\tdeptid, cusnum, cordno, ordno, chrgvat, terms, traddisc, salespn, odate, delchrg, \r\n\t\t\tsubtot, vat, total, balance, comm, username, printed, done, prd, \r\n\t\t\tvatnum, cusacc, telno, div\r\n\t\t) VALUES (\r\n\t\t\t'{$deptid}', '{$cusnum}', '{$cordno}', '{$ordno}', '{$chrgvat}', '{$terms}', '{$traddisc}', '{$salespn}', '{$odate}', \r\n\t\t\t'{$delchrg}', '{$SUBTOT}', '{$vat}' , '{$total}', '{$total}', '{$comm}', '" . USER_NAME . "', 'n', 'n', '" . PRD_DB . "', \r\n\t\t\t'{$vatnum}', '{$cusacc}', '{$telno}', '" . USER_DIV . "'\r\n\t\t)"; $rslt = db_exec($sql) or errDie("Unable to insert invoice to Cubit.", SELF); # get next ordnum $invid = lastinvid(); header("Location: payment.php?cusnum={$cusnum}"); }
function write($_POST) { # Set mas execution time to 12 hours ini_set("max_execution_time", 43200); # Get vars extract($_POST); # validate input require_lib("validate"); $v = new validate(); foreach ($invids as $key => $invid) { $v->isOk($invid, "num", 1, 20, "Invalid recuring invoice number."); $odate[$key] = $o_year[$key] . "-" . $o_month[$key] . "-" . $o_day[$key]; if (!checkdate($o_month[$key], $o_day[$key], $o_year[$key])) { $v->isOk($odate[$key], "num", 1, 1, "Invalid Invoice Date."); } } # display errors, if any $err = ""; if ($v->isError()) { $errors = $v->getErrors(); foreach ($errors as $e) { $err .= "<li class='err'>" . $e["msg"] . "</li>"; } return $err; } $i = 0; foreach ($invids as $key => $invid) { # Get recuring invoice info db_connect(); $sql = "SELECT * FROM rec_invoices WHERE invid = '{$invid}' AND div = '" . USER_DIV . "'"; $invRslt = db_exec($sql) or errDie("Unable to get recuring invoice information"); if (pg_numrows($invRslt) < 1) { return "<i class='err'>Not Found</i>"; } $inv = pg_fetch_array($invRslt); /* - Start Copying - */ pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF); # Insert invoice to DB $sql = "\n\t\t\t\tINSERT INTO invoices (\n\t\t\t\t\tdeptid, cusnum, deptname, cusacc, cusname, surname, \n\t\t\t\t\tcusaddr, cusvatno, cordno, ordno, chrgvat, terms, \n\t\t\t\t\ttraddisc, salespn, odate, delchrg, subtot, vat, \n\t\t\t\t\tdiscount, delivery, total, balance, comm, printed, \n\t\t\t\t\tdone, prd, serd, div, jobid\n\t\t\t\t) VALUES (\n\t\t\t\t\t'{$inv['deptid']}', '{$inv['cusnum']}', '{$inv['deptname']}', '{$inv['cusacc']}', '{$inv['cusname']}', '{$inv['surname']}', \n\t\t\t\t\t'{$inv['cusaddr']}', '{$inv['cusvatno']}', '{$inv['cordno']}', '{$inv['ordno']}', '{$inv['chrgvat']}', '{$inv['terms']}', \n\t\t\t\t\t'{$inv['traddisc']}', '{$inv['salespn']}', '{$odate[$key]}', '{$inv['delchrg']}', '{$inv['subtot']}', '{$inv['vat']}' , \n\t\t\t\t\t'{$inv['discount']}', '{$inv['delivery']}', '{$inv['total']}', '{$inv['total']}', '{$inv['comm']}', 'n', 'y', '" . PRD_DB . "', \n\t\t\t\t\t'n', '" . USER_DIV . "', '{$invid}'\n\t\t\t\t)"; $rslt = db_exec($sql) or errDie("Unable to insert invoice to Cubit.", SELF); # get next ordnum $invid = lastinvid(); # get selected stock in this recuring invoice db_connect(); $sql = "SELECT * FROM recinv_items WHERE invid = '{$inv['invid']}' AND div = '" . USER_DIV . "'"; $stkdRslt = db_exec($sql); $serd = "y"; while ($stkd = pg_fetch_array($stkdRslt)) { # Insert one by one per quantity if (ext_isSerial("stock", "stkid", $stkd['stkid'])) { $stkd['amt'] = sprint($stkd['amt'] / $stkd['qty']); $serd = "n"; for ($i = 0; $i < $stkd['qty']; $i++) { # insert invoice items $sql = "\n\t\t\t\t\t\t\tINSERT INTO inv_items (\n\t\t\t\t\t\t\t\tinvid, whid, stkid, qty, unitcost, amt, \n\t\t\t\t\t\t\t\tdisc, discp, div, vatcode, account, \n\t\t\t\t\t\t\t\tdescription\n\t\t\t\t\t\t\t) VALUES (\n\t\t\t\t\t\t\t\t'{$invid}', '{$stkd['whid']}', '{$stkd['stkid']}', '1', '{$stkd['unitcost']}', '{$stkd['amt']}', \n\t\t\t\t\t\t\t\t'{$stkd['disc']}', '{$stkd['discp']}', '" . USER_DIV . "', '{$stkd['vatcode']}', '{$stkd['account']}', \n\t\t\t\t\t\t\t\t'{$stkd['description']}'\n\t\t\t\t\t\t\t)"; $rslt = db_exec($sql) or errDie("Unable to insert invoice items to Cubit.", SELF); } } else { # insert invoice items $sql = "\n\t\t\t\t\t\tINSERT INTO inv_items (\n\t\t\t\t\t\t\tinvid, whid, stkid, qty, unitcost, amt, \n\t\t\t\t\t\t\tdisc, discp, div, vatcode, account, \n\t\t\t\t\t\t\tdescription\n\t\t\t\t\t\t) VALUES (\n\t\t\t\t\t\t\t'{$invid}', '{$stkd['whid']}', '{$stkd['stkid']}', '{$stkd['qty']}', '{$stkd['unitcost']}', '{$stkd['amt']}', \n\t\t\t\t\t\t\t'{$stkd['disc']}', '{$stkd['discp']}', '" . USER_DIV . "', '{$stkd['vatcode']}', '{$stkd['account']}', \n\t\t\t\t\t\t\t'{$stkd['description']}'\n\t\t\t\t\t\t)"; $rslt = db_exec($sql) or errDie("Unable to insert invoice items to Cubit.", SELF); } # update stock(alloc + qty) $sql = "UPDATE stock SET alloc = (alloc + '{$stkd['qty']}') WHERE stkid = '{$stkd['stkid']}' AND div = '" . USER_DIV . "'"; $rslt = db_exec($sql) or errDie("Unable to update stock to Cubit.", SELF); } # set to not serialised $sql = "UPDATE invoices SET serd = '{$serd}' WHERE invid = '{$invid}' AND div = '" . USER_DIV . "'"; $rslt = db_exec($sql) or errDie("Unable to update quotes in Cubit.", SELF); pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF); /* - End Copying - */ } // Final Laytout $write = "\n\t\t<table " . TMPL_tblDflts . ">\n\t\t\t<tr>\n\t\t\t\t<th>Recurring Invoices Proccesed</th>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>New Invoices have been created from Recurring Invoices</td>\n\t\t\t</tr>\n\t\t</table>\n\t\t<p>\n\t\t<table " . TMPL_tblDflts . ">\n\t\t\t<tr>\n\t\t\t\t<th>Quick Links</th>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td><a href='invoice-view.php'>View Invoices</a></td>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td><a href='rec-invoice-view.php'>View Recurring Invoices</a></td>\n\t\t\t</tr>\n\t\t\t<script>document.write(getQuicklinkSpecial());</script>\n\t\t</table>"; return $write; }
function write($_POST) { # Get vars extract($_POST); # validate input require_lib("validate"); $v = new validate(); $v->isOk($quoid, "num", 1, 20, "Invalid Quote number."); # display errors, if any $err = ""; if ($v->isError()) { $errors = $v->getErrors(); foreach ($errors as $e) { $err .= "<li class='err'>" . $e["msg"] . "</li>"; } return $err; } # Get quote info db_connect(); $sql = "SELECT * FROM pos_quotes WHERE quoid = '{$quoid}' AND div = '" . USER_DIV . "'"; $quoRslt = db_exec($sql) or errDie("Unable to get quote information"); if (pg_numrows($quoRslt) < 1) { return "<li class='err'>Quote Not Found</li>"; } $quo = pg_fetch_array($quoRslt); /* - Start Copying - */ pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF); db_connect(); $Sl = "SELECT * FROM posround"; $Ri = db_exec($Sl); $data = pg_fetch_array($Ri); $TOTAL = $quo['total']; if ($data['setting'] == "5cent") { if (sprint(floor(sprint($TOTAL / 0.05))) != sprint($TOTAL / 0.05)) { $otot = $TOTAL; $nTOTAL = sprint(sprint(floor($TOTAL / 0.05)) * 0.05); $rounding = $otot - $nTOTAL; } else { $rounding = 0; } } else { $rounding = 0; } # Insert invoice to DB $sql = "INSERT INTO pinvoices(deptid, deptname, cusname, surname, cusaddr, ordno, chrgvat, terms, traddisc, salespn, odate, delchrg, subtot, vat, total, balance, comm, printed, done, prd, div,rounding,delvat)"; $sql .= " VALUES('{$quo['deptid']}', '{$quo['deptname']}', '{$quo['cusname']}', '{$quo['surname']}', '{$quo['cusaddr']}', '{$quo['ordno']}', '{$quo['chrgvat']}', '{$quo['terms']}', '{$quo['traddisc']}', '{$quo['salespn']}', '{$quo['odate']}', '{$quo['delchrg']}', '{$quo['subtot']}', '{$quo['vat']}' , '{$quo['total']}', '{$quo['total']}', '{$quo['comm']}', 'n', 'y', '" . PRD_DB . "', '" . USER_DIV . "','{$rounding}', '{$quo['delvat']}')"; $rslt = db_exec($sql) or errDie("Unable to insert invoice to Cubit.", SELF); # get next ordnum $invid = lastinvid(); # get selected stock in this quote db_connect(); $sql = "SELECT * FROM pos_quote_items WHERE quoid = '{$quoid}' AND div = '" . USER_DIV . "'"; $stkdRslt = db_exec($sql); while ($stkd = pg_fetch_array($stkdRslt)) { # insert invoice items $stkd['vatcode'] += 0; $stkd['account'] += 0; $sql = "INSERT INTO pinv_items(invid, whid, stkid, qty, unitcost, amt, disc, discp, div,vatcode,description,account) VALUES('{$invid}', '{$stkd['whid']}', '{$stkd['stkid']}', '{$stkd['qty']}', '{$stkd['unitcost']}', '{$stkd['amt']}', '{$stkd['disc']}', '{$stkd['discp']}', '" . USER_DIV . "','{$stkd['vatcode']}','{$stkd['description']}','{$stkd['account']}')"; $rslt = db_exec($sql) or errDie("Unable to insert invoice items to Cubit.", SELF); # update stock(alloc + qty) $sql = "UPDATE stock SET alloc = (alloc + '{$stkd['qty']}') WHERE stkid = '{$stkd['stkid']}' AND div = '" . USER_DIV . "'"; $rslt = db_exec($sql) or errDie("Unable to update stock to Cubit.", SELF); } db_connect(); # set to accepted $sql = "UPDATE pos_quotes SET accepted = 'y' WHERE quoid = '{$quoid}' AND div = '" . USER_DIV . "'"; $rslt = db_exec($sql) or errDie("Unable to update quotes in Cubit.", SELF); /* Remove access data $sql = "DELETE FROM pos_quotes WHERE quoid = '$quoid' AND div = '".USER_DIV."'"; $rslt = db_exec($sql) or errDie("Unable to update quotes in Cubit.",SELF); $sql = "DELETE FROM pos_quote_items WHERE quoid = '$quoid' AND div = '".USER_DIV."'"; $rslt = db_exec($sql) or errDie("Unable to update quotes in Cubit.",SELF); */ /* - End Copying - */ pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF); #redirect to pos invoice screen ... header("Location: pos-invoice-new.php?invid={$invid}&cont=1"); // Final Laytout $write = "\n\t\t\t\t<table " . TMPL_tblDflts . ">\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<th>Quote accepted</th>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t<td>Quote for customer <b>{$quo['cusname']}</b> has been accepted</td>\n\t\t\t\t\t</tr>\n\t\t\t\t</table>\n\t\t\t\t<p>\n\t\t\t\t<table " . TMPL_tblDflts . ">\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<th>Quick Links</th>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t<td><a href='pos-quote-view.php'>View Pos Quotes</a></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<script>document.write(getQuicklinkSpecial());</script>\n\t\t\t\t</table>"; // return $write; }
function write($_POST) { # Get vars foreach ($_POST as $key => $value) { ${$key} = $value; } # validate input require_lib("validate"); $v = new validate(); $v->isOk($sordid, "num", 1, 20, "Invalid Sales Order number."); # display errors, if any $err = ""; if ($v->isError()) { $errors = $v->getErrors(); foreach ($errors as $e) { $err .= "<li class=err>" . $e["msg"]; } return $err; } # Get Sales Order info db_connect(); $sql = "SELECT * FROM sorders WHERE sordid = '{$sordid}' AND div = '" . USER_DIV . "'"; $sordRslt = db_exec($sql) or errDie("Unable to get Sales Order information"); if (pg_numrows($sordRslt) < 1) { return "<li class=err>Sales Order Not Found</li>"; } $sord = pg_fetch_array($sordRslt); /* - Start Copying - */ pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF); db_connect(); # Insert invoice to DB $sql = "INSERT INTO invoices(deptid, cusnum, deptname, cusacc, cusname, surname, cusaddr, cusvatno, cordno, ordno, chrgvat, fcid, currency, xrate, terms, traddisc, salespn, odate, delchrg, subtot, vat, total, balance, comm, location, printed, done, serd, prd, div)"; $sql .= " VALUES('{$sord['deptid']}', '{$sord['cusnum']}', '{$sord['deptname']}', '{$sord['cusacc']}', '{$sord['cusname']}', '{$sord['surname']}', '{$sord['cusaddr']}', '{$sord['cusvatno']}', '{$sord['cordno']}', '{$sord['ordno']}', '{$sord['chrgvat']}', '{$sord['fcid']}', '{$sord['currency']}', '{$sord['xrate']}', '{$sord['terms']}', '{$sord['traddisc']}', '{$sord['salespn']}', '{$sord['odate']}', '{$sord['delchrg']}', '{$sord['subtot']}', '{$sord['vat']}' , '{$sord['total']}', '{$sord['total']}', '{$sord['comm']}', '{$sord['location']}', 'n', 'y', 'n', '" . PRD_DB . "', '" . USER_DIV . "')"; $rslt = db_exec($sql) or errDie("Unable to insert invoice to Cubit.", SELF); # get next ordnum $invid = lastinvid(); # get selected stock in this Sales Order db_connect(); $sql = "SELECT * FROM sorders_items WHERE sordid = '{$sordid}' AND div = '" . USER_DIV . "'"; $stkdRslt = db_exec($sql); $serd = "y"; while ($stkd = pg_fetch_array($stkdRslt)) { # Insert one by one per quantity if (ext_isSerial("stock", "stkid", $stkd['stkid'])) { $stkd['amt'] = sprint($stkd['amt'] / $stkd['qty']); $serd = "n"; for ($i = 0; $i < $stkd['qty']; $i++) { # insert invoice items $sql = "INSERT INTO inv_items(invid, whid, stkid, qty, unitcost, funitcost, amt, famt, disc, discp, div) VALUES('{$invid}', '{$stkd['whid']}', '{$stkd['stkid']}', '1', '{$stkd['unitcost']}', '{$stkd['funitcost']}', '{$stkd['amt']}', '{$stkd['famt']}', '{$stkd['disc']}', '{$stkd['discp']}', '" . USER_DIV . "')"; $rslt = db_exec($sql) or errDie("Unable to insert invoice items to Cubit.", SELF); } } else { # insert invoice items $sql = "INSERT INTO inv_items(invid, whid, stkid, qty, unitcost, funitcost, amt, famt, disc, discp, div) VALUES('{$invid}', '{$stkd['whid']}', '{$stkd['stkid']}', '{$stkd['qty']}', '{$stkd['unitcost']}', '{$stkd['funitcost']}', '{$stkd['amt']}', '{$stkd['famt']}', '{$stkd['disc']}', '{$stkd['discp']}', '" . USER_DIV . "')"; $rslt = db_exec($sql) or errDie("Unable to insert invoice items to Cubit.", SELF); } } # get selected stock in this Sales Order db_connect(); $sql = "SELECT * FROM sord_data WHERE sordid = '{$sordid}' AND div = '" . USER_DIV . "'"; $dataRslt = db_exec($sql); $data = pg_fetch_array($dataRslt); $sql = "INSERT INTO inv_data(invid, dept, customer, addr1, div) VALUES('{$invid}', '{$data['dept']}', '{$data['customer']}', '{$data['addr1']}', '" . USER_DIV . "')"; $rslt = db_exec($sql) or errDie("Unable to insert invoice data to Cubit.", SELF); # set to accepted $sql = "UPDATE sorders SET accepted = 'y' WHERE sordid = '{$sordid}' AND div = '" . USER_DIV . "'"; $rslt = db_exec($sql) or errDie("Unable to update quotes in Cubit.", SELF); # set to not serialised $sql = "UPDATE invoices SET serd = '{$serd}' WHERE invid = '{$invid}' AND div = '" . USER_DIV . "'"; $rslt = db_exec($sql) or errDie("Unable to update quotes in Cubit.", SELF); // # remove access data // $sql = "DELETE FROM sorders WHERE sordid = '$sordid' AND div = '".USER_DIV."'"; // $rslt = db_exec($sql) or errDie("Unable to update Sales Orders in Cubit.",SELF); // $sql = "DELETE FROM sorders_items WHERE sordid = '$sordid' AND div = '".USER_DIV."'"; // $rslt = db_exec($sql) or errDie("Unable to update Sales Orders in Cubit.",SELF); // $sql = "DELETE FROM sord_data WHERE sordid = '$sordid' AND div = '".USER_DIV."'"; // $rslt = db_exec($sql) or errDie("Unable to update Sales Orders in Cubit.",SELF); # End updates pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF); header("Location: intinvoice-new.php?invid={$invid}&cont=true&letters=&done="); exit; /* - End Copying - */ // Final Laytout $write = "\n\t<table border=0 cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "'>\n\t\t<tr><th>International Sales Order accepted</th></tr>\n\t\t<tr class='bg-even'><td>Sales Order for customer <b>{$sord['cusname']} {$sord['surname']}</b> has been accepted</td></tr>\n\t</table>\n\t<p>\n\t<table border=0 cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "'>\n\t\t<tr><th>Quick Links</th></tr>\n\t\t<tr class='bg-odd'><td><a href='sorder-view.php'>View Sales Orders</a></td></tr>\n\t\t<script>document.write(getQuicklinkSpecial());</script>\n\t</table>"; return $write; }