function slct($_GET) { # Get vars extract($_GET); # validate input require_lib("validate"); $v = new validate(); $v->isOk($invid, "num", 1, 20, "Invalid Invoice number."); # display errors, if any if ($v->isError()) { $err = ""; $errors = $v->getErrors(); foreach ($errors as $e) { $err .= "<li class='err'>" . $e["msg"] . "</li>"; } $confirm .= "<p><input type='button' onClick='JavaScript:history.back();' value='« Correct submission'>"; return $confirm; } if (isset($letters)) { $letters = remval($letters); $whe = "AND lower(surname) LIKE lower('%{$letters}%')"; } else { $letters = ""; $whe = ""; } # Get invoice info db_connect(); $sql = "SELECT * FROM nons_invoices WHERE invid = '{$invid}' AND div = '" . USER_DIV . "'"; $invRslt = db_exec($sql) or errDie("Unable to get invoice information"); if (pg_numrows($invRslt) < 1) { return "<li class='err'>Invoice Not Found</li>"; } $inv = pg_fetch_array($invRslt); if ($inv['ctyp'] == 's') { $VARS['invid'] = $invid; $VARS['ctyp'] = 's'; $VARS['cusnum'] = $inv['tval']; return cdetails($VARS); } elseif ($inv['ctyp'] == 'c') { $VARS['invid'] = $invid; $VARS['ctyp'] = 'c'; $VARS['deptid'] = $inv['tval']; return cdetails($VARS); } elseif ($inv['ctyp'] == 'cb') { $VARS['invid'] = $invid; $VARS['ctyp'] = 'cb'; $VARS['deptid'] = 0; return cdetails($VARS); } elseif ($inv['ctyp'] == 'ac') { $VARS['invid'] = $invid; $VARS['ctyp'] = 'ac'; $VARS['deptid'] = $inv['tval']; return acdetails($VARS); } db_connect(); $sql = "SELECT * FROM customers WHERE div = '" . USER_DIV . "' {$whe} ORDER BY cusnum ASC"; $cusRslt = db_exec($sql) or errDie("Could not retrieve Customers Information from the Database.", SELF); if (pg_numrows($cusRslt) < 1) { $custs = "No customers\r\n\t\t<input type='hidden' name='cusnum' value='#'>"; } else { $custs = "<select name='cusnum'>"; while ($cus = pg_fetch_array($cusRslt)) { $custs .= "<option value='{$cus['cusnum']}'>{$cus['cusname']} {$cus['surname']}</option>"; } $custs .= "</select>"; } db_conn("exten"); $sql = "SELECT * FROM departments WHERE div = '" . USER_DIV . "' ORDER BY deptname ASC"; $deptRslt = db_exec($sql); $depts = "<select name='deptid'>"; if (pg_numrows($deptRslt) < 1) { $depts .= "<option value='-S'></option>"; } while ($dept = pg_fetch_array($deptRslt)) { $depts .= "<option value='{$dept['deptid']}'>{$dept['deptname']}</option>"; } $depts .= "</select>"; $details = "\r\n\t\t\t\t\t<center>\r\n\t\t\t\t\t<h3>Print Non-Stock Invoices</h3>\r\n\t\t\t\t\t<h4>Customer Details</h4>\r\n\t\t\t\t\t<form action='" . SELF . "' method='POST' name='form'>\r\n\t\t\t\t\t\t<input type='hidden' name='key' value='slct'>\r\n\t\t\t\t\t\t<input type='hidden' name='invid' value='{$invid}'>\r\n\t\t\t\t\t\t<input type='hidden' name='starting' value=''>\r\n\t\t\t\t\t<table " . TMPL_tblDflts . ">\r\n\t\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t\t<th colspan='2'> Invoice Details </th>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "' " . ass("Select when selling non stock goods to your customers") . ">\r\n\t\t\t\t\t\t\t<td><input type='radio' name='ctyp' value='s' checked='yes'> Select Customer</td>\r\n\t\t\t\t\t\t\t<td>{$custs}</td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "' " . ass("Select when the sale of non stock goods is a cash sale") . ">\r\n\t\t\t\t\t\t\t<td><input type='radio' name='ctyp' value='c'>Cash Sale</td>\r\n\t\t\t\t\t\t\t<td>{$depts}</td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "' " . ass("Select when the sale of non stock goods is not a cash sale") . ">\r\n\t\t\t\t\t\t\t<td><input type='radio' name='ctyp' value='ac'>Ledger Accounts Sale</td>\r\n\t\t\t\t\t\t\t<td></td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr><td><br></td></tr>\r\n\t\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t\t<th colspan='2'>Search by surname</th>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t<td><input type='text' size='10' name='letters' value='{$letters}'></td>\r\n\t\t\t\t\t\t\t<td><input type='submit' value='Search »'></td>\r\n\t\t\t\t\t\t\t</td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr><td><br></td></tr>\r\n\t\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t\t<td></td>\r\n\t\t\t\t\t\t\t<td align='center'><input type='submit' value='Continue »' name='button'></td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t</table>\r\n\t\t\t\t\t</form>"; return $details; }
case "cprewrite": $OUTPUT = cprewrite(); break; case "cwrite": $OUTPUT = cwrite($_POST); break; default: if (isset($_GET["invid"])) { $OUTPUT = cdetails($_GET); } else { $OUTPUT = "<li class=err>Invalid use of module."; } } } else { if (isset($_GET["invid"])) { $OUTPUT = cdetails($_GET); } else { $OUTPUT = "<li class=err>Invalid use of module."; } } # get templete require "template.php"; # Customer details function cdetails($_GET) { # get vars extract($_GET); # validate input require_lib("validate"); $v = new validate(); $v->isOk($invid, "num", 1, 20, "Invalid Invoice number.");
function recvpayment_write() { if (isset($_POST["btn_back"])) { return details($_POST); } extract($_POST); $bank_acc = qryAccountsName("Cash on Hand"); $bank_acc = $bank_acc["accid"]; $cred_acc = qryAccountsName("POS Credit Card Control"); $cred_acc = $cred_acc["accid"]; $v = new validate(); $v->isOk($cusnum, "num", 1, 10, "Invalid customer id."); $v->isOk($bank_acc, "num", 1, 10, "Invalid cash account selected."); $v->isOk($pcc, "float", 1, 40, "Invalid credit card amount."); $v->isOk($pcash, "float", 1, 40, "Invalid cash amount."); $v->isOk($pcheque, "float", 1, 40, "Invalid cheque amount."); $v->isOk($amt, "float", 1, 40, "Invalid total received amount."); $v->isOk($date, "date", 1, 1, "Invalid invoice date."); if ($v->isError()) { return details($_POST, $v->genErrors()); } $sdate = $date; $cus = qryCustomer($cusnum); $dept = qryDepartment($cus["deptid"], "debtacc"); $refnum = getrefnum(); pglib_transaction("BEGIN"); /* do the calculations/recordings */ # update the customer (make balance less) $sql = "UPDATE cubit.customers SET balance = (balance - '{$amt}'::numeric(13,2))\r\n\t\t\tWHERE cusnum = '{$cus['cusnum']}' AND div = '" . USER_DIV . "'"; $rslt = db_exec($sql) or errDie("Unable to update invoice in Cubit.", SELF); $sql = "SELECT prd,invnum,descrip,age FROM cubit.nons_invoices\r\n\t\t\tWHERE invid ='{$invid}' AND div = '" . USER_DIV . "'"; $invRslt = db_exec($sql) or errDie("Unable to retrieve invoice details from database."); if (pg_numrows($invRslt) < 1) { return "<li class=err>Invalid Invoice Number."; } $inv = pg_fetch_array($invRslt); $inv['invnum'] += 0; # reduce the money that has been paid if ($amt) { $sql = "UPDATE cubit.nons_invoices\r\n\t\t\t\tSET balance = (balance - {$amt}::numeric(13,2))\r\n\t\t\t\tWHERE invid = '{$invid}' AND div = '" . USER_DIV . "'"; $payRslt = db_exec($sql) or errDie("Unable to update Invoice information in Cubit.", SELF); $sql = "UPDATE cubit.open_stmnt\r\n\t\t\t\tSET balance = (balance - {$amt}::numeric(13,2))\r\n\t\t\t\tWHERE invid = '{$inv['invnum']}' AND div = '" . USER_DIV . "'"; $payRslt = db_exec($sql) or errDie("Unable to update Invoice information in Cubit.", SELF); # record the payment on the statement $sql = "INSERT INTO cubit.stmnt(cusnum, invid, amount, date, type, div)\r\n\t\t\t\tVALUES('{$cus['cusnum']}','{$inv['invnum']}',\r\n\t\t\t\t'" . ($amt - $amt * 2) . "','{$sdate}',\r\n\t\t\t\t'Payment for Hire Invoice No. {$inv['invnum']}',\r\n\t\t\t\t'" . USER_DIV . "')"; $stmntRslt = db_exec($sql) or errDie("Unable to insert statement record in Cubit.", SELF); $cash_amt = $pcash + $pcheque; $cred_amt = $pcc; custledger($cus['cusnum'], $bank_acc, $sdate, $inv['invnum'], "Payment for Hire Invoice No. {$inv['invnum']}", $cash_amt, "c"); custledger($cus["cusnum"], $cred_acc, $sdate, $inv["invnum"], "Payment for Hire Invoice No. {$inv['invnum']}", $cred_amt, "c"); custCT($amt, $cus["cusnum"], $sdate); //recordCT($amt, $cus['cusnum'],$inv['age'],$sdate); } if (!isset($invids[$key])) { $invids[$key] = 0; } if (!isset($rinvids)) { $rinvids = 0; } if (!isset($amounts)) { $amounts = 0; } if (!isset($invprds)) { $invprds = 0; } if (!isset($rages)) { $rages = 0; } if (!isset($invidsers)) { $invidsers = 0; } $rinvids .= "|{$invids[$key]}"; $amounts .= "|{$amt}"; $invprds .= "|0"; $rages .= "|{$inv['age']}"; $invidsers .= " - {$inv['invnum']}"; $sql = "SELECT * FROM core.accounts WHERE topacc='6400' AND accnum='000'"; $acc_rslt = db_exec($sql); $deptacc = pg_fetch_result($acc_rslt, 0); if ((double) $pcash) { writetrans($bank_acc, $deptacc, $sdate, $refnum, $pcash, "Payment for Invoice {$inv['invnum']} from customer {$cus['cusname']} {$cus['surname']}"); } if ((double) $pcc) { $sql = "SELECT accid FROM core.accounts WHERE topacc='7300' AND accnum='000'"; $acc_rslt = db_exec($sql); $accid = pg_fetch_result($acc_rslt, 0); writetrans($accid, $deptacc, $sdate, $refnum, $pcc, "Payment for Invoice {$invidsers} from customer {$cus['cusname']} {$cus['surname']}"); } if ((double) $pcheque) { $sql = "SELECT accid FROM core.accounts WHERE topacc='7200' AND accnum='000'"; $acc_rslt = db_exec($sql); $accid = pg_fetch_result($acc_rslt, 0); writetrans($accid, $deptacc, $sdate, $refnum, $pcheque, "Payment for Invoice {$invidsers} from customer {$cus['cusname']} {$cus['surname']}"); } db_conn('cubit'); pglib_transaction("COMMIT"); $_POST["pcc"] = $_POST["pcheque"] = $_POST["pcash"] = "0.00"; return cdetails($_POST, "<li class='err'>Payment received successfully</li>"); }