function enter(&$frm) { if (!isset($_REQUEST["id"])) { invalid_use(); } $frm->settitle("Supplier Stock Codes"); $frm->setmsg("Please enter the stock codes each of your suppliers use for the\n\t\tselected stock item.<br /><br />\n\t\t<li class='err'>To remove an item from supplier, simply leave field blank.</li>"); $frm->setkey("confirm"); $frm->add_hidden("id", $_REQUEST["id"], "num"); $qry = new dbSelect("suppliers", "cubit"); $qry->run(); $frm->add_heading("Details"); while ($si = $qry->fetch_array()) { $stkcod = suppStkcod($si["supid"], $_REQUEST["id"]); $stkdes = suppStkdes($si["supid"], $_REQUEST["id"]); $supdisp = "({$si['supno']}) {$si['supname']}"; $frm->add_text($supdisp, "stkcod[{$si['supid']}]", $stkcod, "string", "0:50"); $frm->add_text("Description", "stkdes[{$si['supid']}]", $stkdes, "string", "0:50"); } return $frm->getfrm_input(); }
/** * alias for suppStkCod() * * @ignore */ function trhSuppStkcod($suppid, $stkid) { return suppStkcod($suppid, $stkid); }
function write($_POST) { #get vars extract($_POST); # validate input require_lib("validate"); $v = new validate(); $v->isOk($purid, "num", 1, 9, "Invalid Order ID"); $v->isOk($supinv, "string", 0, 50, "Invalid supplier inv num."); $v->isOk($letters, "string", 0, 5, "Invalid First 3 Letters."); $v->isOk($ordernum, "string", 0, 20, "Invalid order number."); $v->isOk($supid, "num", 1, 20, "Please Select Supplier."); $v->isOk($terms, "num", 1, 5, "Invalid terms days."); $v->isOk($pur_day, "num", 1, 2, "Invalid Date day."); $v->isOk($pur_month, "num", 1, 2, "Invalid Date month."); $v->isOk($pur_year, "num", 1, 5, "Invalid Date year."); $v->isOk($shipchrg, "float", 0, 20, "Invalid Delivery Charges."); $v->isOk($remarks, "string", 0, 255, "Invalid Remarks."); $pdate = $pur_year . "-" . $pur_month . "-" . $pur_day; $pur_year += 0; $pur_month += 0; $pur_day += 0; if (!checkdate($pur_month, $pur_day, $pur_year)) { $v->isOk($pdate, "num", 1, 1, "Invalid Date."); } # used to generate errors $error = "asa@"; # check quantities if (isset($qtys)) { foreach ($qtys as $keys => $qty) { $v->isOk($qty, "float", 1, 15, "Invalid Quantity for product number : <b>" . ($keys + 1) . "</b>"); $v->isOk($upack[$keys], "num", 1, 20, "Invalid Units Per Pack for product number : <b>" . ($keys + 1) . "</b>."); $v->isOk($ppack[$keys], "float", 1, 20, "Invalid Price Per Pack for product number : <b>" . ($keys + 1) . "</b>."); // $v->isOk ($unitcost[$keys], "float", 1, 20, "Invalid Unit Price for product number : <b>".($keys+1)."</b>."); if ($qty <= 0) { $v->isOk($qty, "num", 0, 0, "Error : Item Quantity must be more than zero. Product number : <b>" . ($keys + 1) . "</b>"); } if ($upack[$keys] < 1) { $v->isOk($upack[$keys], "num", 0, 0, "Error : Units Per Pack must be at least one. Product number : <b>" . ($keys + 1) . "</b>"); } if (!isset($novat[$keys])) { $v->isOk($svat[$keys], "float", 0, 20, "Invalid vat amount. Product number : <b>" . ($keys + 1) . "</b>"); } // if(($vatcodes[$keys] == "0") OR ($vatcodes[$keys] == "00")){ // $v->addError($vatcodes[$keys],"Invalid Vat Percentage"); // } # Validate ddate[] $v->isOk($d_day[$keys], "num", 1, 2, "Invalid Delivery Date day."); $v->isOk($d_month[$keys], "num", 1, 2, "Invalid Delivery Date month."); $v->isOk($d_year[$keys], "num", 1, 5, "Invalid Delivery Date year."); $ddate[$keys] = $d_year[$keys] . "-" . $d_month[$keys] . "-" . $d_day[$keys]; if (!checkdate($d_month[$keys], $d_day[$keys], $d_year[$keys])) { $v->isOk($ddate[$keys], "num", 1, 1, "Invalid Delivery Date."); } } } # check whids if (isset($whids)) { foreach ($whids as $keys => $whid) { $v->isOk($whid, "num", 1, 10, "Invalid Store number, please enter all details."); } } # check stkids if (isset($stkids)) { foreach ($stkids as $keys => $stkid) { $v->isOk($stkid, "num", 1, 10, "Invalid Stock number, please enter all details."); } } # check amt if (isset($amt)) { foreach ($amt as $keys => $amount) { $v->isOk($amount, "float", 1, 20, "Invalid Amount, please enter all details."); } } # display errors, if any $err = ""; if ($v->isError()) { $errors = $v->getErrors(); foreach ($errors as $e) { $err .= "<li class='err'>" . $e["msg"] . "</li>"; } $_POST['done'] = ""; return details($_POST, $err); } # Get Order info db_connect(); $sql = "SELECT * FROM purchases WHERE purid = '{$purid}' AND div = '" . USER_DIV . "'"; $purRslt = db_exec($sql) or errDie("Unable to get Order information"); if (pg_numrows($purRslt) < 1) { return "<li>- Order Not Found</li>"; } $pur = pg_fetch_array($purRslt); # check if Order has been printed if ($pur['received'] == "y") { $error = "<li class='err'> Error : Order number <b>{$purid}</b> has already been received.</li>"; $error .= "<p><input type='button' onClick='JavaScript:history.back();' value='« Correct submission'>"; return $error; } # Get selected customer info db_connect(); $sql = "SELECT * FROM suppliers WHERE supid = '{$supid}' AND div = '" . USER_DIV . "'"; $supRslt = db_exec($sql) or errDie("Unable to get customer information"); if (pg_numrows($supRslt) < 1) { // code here } else { $sup = pg_fetch_array($supRslt); } $pur['deptid'] = $sup['deptid']; # Get department db_conn("exten"); $sql = "SELECT * FROM departments WHERE deptid = '{$pur['deptid']}' AND div = '" . USER_DIV . "'"; $deptRslt = db_exec($sql); if (pg_numrows($deptRslt) < 1) { $dept['deptname'] = "<i class='err'>Not Found</i>"; } else { $dept = pg_fetch_array($deptRslt); } # Vat percantege $VATP = TAX_VAT; # Fix those nasty zeros $shipchrg += 0; # insert Order to DB db_connect(); $showvat = TRUE; # Begin updating pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF); /* -- Start remove old items -- */ # get selected stock in this purchase db_connect(); $sql = "SELECT * FROM pur_items WHERE purid = '{$purid}' AND div = '" . USER_DIV . "'"; $stktRslt = db_exec($sql); while ($stkt = pg_fetch_array($stktRslt)) { # update stock(ordered - qty) $sql = "UPDATE stock SET ordered = (ordered - '{$stkt['qty']}') WHERE stkid = '{$stkt['stkid']}' AND div = '" . USER_DIV . "'"; $rslt = db_exec($sql) or errDie("Unable to update stock to Cubit.", SELF); } # remove old items $sql = "DELETE FROM pur_items WHERE purid='{$purid}' AND div = '" . USER_DIV . "'"; $rslt = db_exec($sql) or errDie("Unable to update Order items in Cubit.", SELF); /* -- End remove old items -- */ $taxex = 0; if (isset($qtys)) { foreach ($qtys as $keys => $value) { if (isset($remprod) && in_array($keys, $remprod)) { } elseif (isset($accounts[$keys]) && $accounts[$keys] != 0) { # get selamt from selected stock db_conn('core'); $Sl = "SELECT * FROM accounts WHERE accid='{$accounts[$keys]}'"; $Ri = db_exec($Sl) or errDie("Unable to get account data."); $ad = pg_fetch_array($Ri); db_conn('cubit'); $Sl = "SELECT * FROM vatcodes WHERE id='{$vatcodes[$keys]}'"; $Ri = db_exec($Sl); if (pg_num_rows($Ri) < 1) { // return "Please select the vatcode for all your stock."; $_POST['done'] = ""; return details($_POST, "<li class='err'>Please select the vatcode for all your items.</li>"); } $vd = pg_fetch_array($Ri); $VATP = $vd['vat_amount']; if (TAX_VAT != $vd['vat_amount'] and $vd['vat_amount'] != "0.00") { $showvat = FALSE; } # Calculate amount //$amt[$keys] = ($qtys[$keys] * $ppack[$keys]); if ($udiscount[$keys] > 0) { $discps = round($udiscount[$keys] / 100 * $ppack[$keys], 2); } else { $discps = 0; } $amt[$keys] = sprint($qtys[$keys] * ($ppack[$keys] - $discps)); # auto $qpack[$keys] = $qtys[$keys]; $unitcost[$keys] = sprint($ppack[$keys] / $upack[$keys]); $qtys[$keys] = $upack[$keys] * $qpack[$keys]; $stk['exvat'] = ""; if (isset($novat[$keys])) { # Check Tax Excempt if ($stk['exvat'] != 'yes' && $vd['zero'] != "Yes") { # If vat is not included if ($vatinc == "no") { $vat[$keys] = sprintf("%01.2f", $VATP / 100 * $amt[$keys]); } elseif ($vatinc == "yes") { $vat[$keys] = sprintf("%01.2f", $amt[$keys] / ($VATP + 100) * $VATP); } else { $vat[$keys] = 0; } } else { $vat[$keys] = 0; } } elseif (isset($svat[$keys]) && strlen($svat[$keys]) < 1) { # Check Tax Excempt if ($stk['exvat'] != 'yes' && $vd['zero'] != "Yes") { # If vat is not included if ($vatinc == "no") { $vat[$keys] = sprintf("%01.2f", $VATP / 100 * $amt[$keys]); } elseif ($vatinc == "yes") { $vat[$keys] = sprintf("%01.2f", $amt[$keys] / (100 + $VATP) * $VATP); } else { $vat[$keys] = 0; } } else { $vat[$keys] = 0; } } elseif ($vatinc == "novat") { $vat[$keys] = 0; } else { if ($stk['exvat'] != 'yes' && $vd['zero'] != "Yes") { $vat[$keys] = $svat[$keys]; } else { $vat[$keys] = 0; } } if ($vatinc != "novat") { # Track Vat Changes if ($stk['exvat'] != 'yes' && $vd['zero'] != "Yes") { # If vat is not included if ($vatinc == "no") { $vatc[$keys] = sprintf("%01.2f", $VATP / 100 * $amt[$keys]); } else { $vatc[$keys] = sprintf("%01.2f", $amt[$keys] / ($VATP + 100) * $VATP); } } else { $vatc[$keys] = 0; } if ($vat[$keys] != $vatc[$keys]) { $_POST["vatc"][$keys] = "yes"; } } # ddate $ddate[$keys] = "{$d_year[$keys]}-{$d_month[$keys]}-{$d_day[$keys]}"; $wtd = $whids[$keys]; # insert Order items $sql = "\n\t\t\t\t\t\tINSERT INTO pur_items (\n\t\t\t\t\t\t\tpurid, whid, stkid, qty, iqty, unitcost, \n\t\t\t\t\t\t\tamt, ddate, qpack, upack, ppack, svat, \n\t\t\t\t\t\t\tdiv, vatcode, description, account, \n\t\t\t\t\t\t\tudiscount\n\t\t\t\t\t\t) VALUES (\n\t\t\t\t\t\t\t'{$purid}', '{$whids[$keys]}', '{$stkids[$keys]}', '{$qtys[$keys]}', '{$qtys[$keys]}', '{$unitcost[$keys]}', \n\t\t\t\t\t\t\t'{$amt[$keys]}', '{$ddate[$keys]}', '{$qpack[$keys]}', '{$upack[$keys]}', '{$ppack[$keys]}', '{$vat[$keys]}', \n\t\t\t\t\t\t\t'" . USER_DIV . "', '{$vatcodes[$keys]}', '{$descriptions[$keys]}', '{$accounts[$keys]}', \n\t\t\t\t\t\t\t'{$udiscount[$keys]}'\n\t\t\t\t\t\t)"; $rslt = db_exec($sql) or errDie("Unable to insert Order items to Cubit.", SELF); # update stock(ordered + qty) //$sql = "UPDATE stock SET ordered = (ordered + '$qtys[$keys]') WHERE stkid = '$stkids[$keys]' AND div = '".USER_DIV."'"; //$rslt = db_exec($sql) or errDie("Unable to update stock to Cubit.",SELF); } else { # get selamt from selected stock $sql = "SELECT * FROM stock WHERE stkid = '{$stkids[$keys]}' AND div = '" . USER_DIV . "'"; $stkRslt = db_exec($sql); $stk = pg_fetch_array($stkRslt); $Sl = "SELECT * FROM vatcodes WHERE id='{$vatcodes[$keys]}'"; $Ri = db_exec($Sl); if (pg_num_rows($Ri) < 1) { // return "Please select the vatcode for all your stock."; $_POST['done'] = ""; return details($_POST, "<li class='err'>Please select the vatcode for all your items.</li>"); } $vd = pg_fetch_array($Ri); $VATP = $vd['vat_amount']; if (TAX_VAT != $vd['vat_amount'] and $vd['vat_amount'] != "0.00") { $showvat = FALSE; } # Calculate amount //$amt[$keys] = ($qtys[$keys] * $ppack[$keys]); if ($udiscount[$keys] > 0) { $discps = round($udiscount[$keys] / 100 * $ppack[$keys], 2); } else { $discps = 0; } $amt[$keys] = sprint($qtys[$keys] * ($ppack[$keys] - $discps)); # auto $qpack[$keys] = $qtys[$keys]; $unitcost[$keys] = sprint($ppack[$keys] / $upack[$keys]); $qtys[$keys] = $upack[$keys] * $qpack[$keys]; if (isset($novat[$keys])) { # Check Tax Excempt if ($stk['exvat'] != 'yes' && $vd['zero'] != "Yes") { # If vat is not included if ($vatinc == "no") { $vat[$keys] = sprintf("%01.2f", $VATP / 100 * $amt[$keys]); } elseif ($vatinc == "yes") { $vat[$keys] = sprintf("%01.2f", $amt[$keys] / ($VATP + 100) * $VATP); } else { $vat[$keys] = 0; } } else { $vat[$keys] = 0; } } elseif (isset($svat[$keys]) && strlen($svat[$keys]) < 1) { # Check Tax Excempt if ($stk['exvat'] != 'yes' && $vd['zero'] != "Yes") { # If vat is not included if ($vatinc == "no") { $vat[$keys] = sprintf("%01.2f", $VATP / 100 * $amt[$keys]); } elseif ($vatinc == "yes") { $vat[$keys] = sprintf("%01.2f", $amt[$keys] / (100 + $VATP) * $VATP); } else { $vat[$keys] = 0; } } else { $vat[$keys] = 0; } } elseif ($vatinc == "novat") { $vat[$keys] = 0; } else { if ($stk['exvat'] != 'yes' && $vd['zero'] != "Yes") { $vat[$keys] = $svat[$keys]; } else { $vat[$keys] = 0; } } if ($vatinc != "novat") { # Track Vat Changes if ($stk['exvat'] != 'yes' && $vd['zero'] != "Yes") { # If vat is not included if ($vatinc == "no") { $vatc[$keys] = sprintf("%01.2f", $VATP / 100 * $amt[$keys]); } else { $vatc[$keys] = sprintf("%01.2f", $amt[$keys] / ($VATP + 100) * $VATP); } } else { $vatc[$keys] = 0; } if ($vat[$keys] != $vatc[$keys]) { $_POST["vatc"][$keys] = "yes"; } } # ddate $ddate[$keys] = "{$d_year[$keys]}-{$d_month[$keys]}-{$d_day[$keys]}"; $wtd = $whids[$keys]; # insert Order items $sql = "\n\t\t\t\t\t\tINSERT INTO pur_items (\n\t\t\t\t\t\t\tpurid, whid, stkid, qty, iqty, unitcost, \n\t\t\t\t\t\t\tamt, ddate, qpack, upack, ppack, svat, \n\t\t\t\t\t\t\tdiv, vatcode, sup_stkcod, \n\t\t\t\t\t\t\tudiscount\n\t\t\t\t\t\t) VALUES (\n\t\t\t\t\t\t\t'{$purid}', '{$whids[$keys]}', '{$stkids[$keys]}', '{$qtys[$keys]}', '{$qtys[$keys]}', '{$unitcost[$keys]}', \n\t\t\t\t\t\t\t'{$amt[$keys]}', '{$ddate[$keys]}', '{$qpack[$keys]}', '{$upack[$keys]}', '{$ppack[$keys]}', '{$vat[$keys]}', \n\t\t\t\t\t\t\t'" . USER_DIV . "','{$vatcodes[$keys]}', '" . suppStkcod($supid, $stkids[$keys]) . "', \n\t\t\t\t\t\t\t'{$udiscount[$keys]}'\n\t\t\t\t\t\t)"; $rslt = db_exec($sql) or errDie("Unable to insert Order items to Cubit.", SELF); # update stock(ordered + qty) $sql = "UPDATE stock SET ordered = (ordered + '{$qtys[$keys]}') WHERE stkid = '{$stkids[$keys]}' AND div = '" . USER_DIV . "'"; $rslt = db_exec($sql) or errDie("Unable to update stock to Cubit.", SELF); } # everything is set place done button if (trhSupplierEnabled($supid)) { $trh_done = "<input name='trhSend' type='submit' value='Send with Transheks' />"; } else { $trh_done = ""; } $_POST["done"] = " {$trh_done} | <input name='doneBtn' type='submit' value='Done'> \n\t\t\t\t\t | <input name='invoice' type='submit' value='Receive & Record Invoice'> | <input type='button' onClick=\"window.open('purch-print.php?purid={$purid}', 'popup_purch_print','scrollbars=yes, statusbar=no, width=800, height= 600');\" value='Print'> | <input type='submit' name='donePrnt' value='Done, Print and make another'>"; } } else { $_POST["done"] = ""; } /* --- Clac --- */ # calculate subtot if (isset($amt)) { $SUBTOT = array_sum($amt); } else { $SUBTOT = 0.0; } db_conn('cubit'); $Sl = "SELECT * FROM vatcodes WHERE id='{$delvat}'"; $Ri = db_exec($Sl); if (pg_num_rows($Ri) < 1) { $Sl = "SELECT * FROM vatcodes"; $Ri = db_exec($Sl); } $vd = pg_fetch_array($Ri); $VATP = $vd['vat_amount']; if (TAX_VAT != $vd['vat_amount'] and $vd['vat_amount'] != "0.00") { $showvat = FALSE; } $_POST['showvat'] = $showvat; if ($vd['zero'] != "Yes") { # If vat is not included (delchrg) //$VATP = TAX_VAT; if ($vatinc == "no") { $svat = sprint($VATP / 100 * $shipchrg); $shipexvat = $shipchrg; } elseif ($vatinc == "yes") { $svat = sprint($shipchrg / ($VATP + 100) * $VATP); $shipexvat = $shipchrg - $svat; } else { $svat = 0; $shipexvat = $shipchrg; } } else { $svat = 0; $shipexvat = $shipchrg; } # If there vatable items if (isset($vat)) { $VAT = array_sum($vat); } else { $VAT = 0; } # Total $TOTAL = $SUBTOT + $shipexvat; # If vat is not included if ($vatinc == "no") { $TOTAL = $TOTAL + $VAT + $svat; } else { $TOTAL = $TOTAL + $svat; $SUBTOT -= $VAT; } $VAT += $svat; /* --- End Clac --- */ # Insert Order to DB $sql = "\n\t\tUPDATE purchases \n\t\tSET delvat='{$delvat}', supid='{$supid}', supinv='{$supinv}', supname='{$sup['supname']}', supaddr='{$sup['supaddr']}', \n\t\t\tsupno='{$sup['supno']}', terms='{$terms}', pdate='{$pdate}', shipchrg='{$shipchrg}', subtot='{$SUBTOT}', total='{$TOTAL}', \n\t\t\tbalance='{$TOTAL}', vatinc='{$vatinc}', vat='{$VAT}', shipping='{$shipexvat}', ordernum='{$ordernum}', \n\t\t\tremarks='{$remarks}', deptid = '{$dept['deptid']}' \n\t\tWHERE purid = '{$purid}' "; $rslt = db_exec($sql) or errDie("Unable to update Order in Cubit.", SELF); # commit updating pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF); if (isset($invoice)) { header("Location: purch-recv.php?purid={$purid}&invoice=no"); exit; } // Was the Done, Print and make another button pressed? if (isset($donePrnt)) { $sql = "UPDATE purchases SET done='y' WHERE purid='{$purid}' AND div='" . USER_DIV . "'"; $rslt = db_exec($sql) or errDie("Unable to update Order status in Cubit"); $OUTPUT = "\n\t\t\t<script>\n\t\t\t\tprinter('purch-print.php?purid={$purid}');move('purchase-new.php');\n\t\t\t</script>"; return $OUTPUT; } if (!(isset($doneBtn) || isset($trhSend))) { if (isset($wtd)) { $_POST['wtd'] = $wtd; } return details($_POST); } else { # insert Order to DB $sql = "UPDATE purchases SET done = 'y' WHERE purid = '{$purid}' AND div = '" . USER_DIV . "'"; $rslt = db_exec($sql) or errDie("Unable to update Order status in Cubit.", SELF); if (isset($trhSend)) { header("Location: transheks/order_send.php?key=send&id={$purid}"); exit; } // Final Laytout $write = "\n\t\t\t<table " . TMPL_tblDflts . ">\n\t\t\t\t<tr>\n\t\t\t\t\t<th colspan='2'>New Order</th>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Order from Supplier <b>{$sup['supname']}</b> has been recorded.</td>\n\t\t\t\t\t<td><a href='javascript: printer(\"purch-print.php?purid={$purid}\");'>Print Order</a></td>\n\t\t\t\t</tr>\n\t\t\t</table>\n\t\t\t<p>\n\t\t\t<table " . TMPL_tblDflts . ">\n\t\t\t\t<tr>\n\t\t\t\t\t<th>Quick Links</th>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td><a href='purchase-view.php'>View Orders</a></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td><a href='main.php'>Main Menu</a></td>\n\t\t\t\t</tr>\n\t\t\t</table>"; return $write; } }