本文整理汇总了PHP中custledger函数的典型用法代码示例。如果您正苦于以下问题:PHP custledger函数的具体用法?PHP custledger怎么用?PHP custledger使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了custledger函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: write
function write($_POST)
{
# processes
db_connect();
# Get vars
extract($_POST);
if (isset($back)) {
return add($_POST);
}
# validate input
require_lib("validate");
$v = new validate();
$v->isOk($bankid, "num", 1, 30, "Invalid Bank Account.");
$v->isOk($date, "date", 1, 10, "Invalid Date Entry.");
$v->isOk($cusnum, "num", 1, 20, "Invalid Customer account.");
$v->isOk($descript, "string", 0, 255, "Invalid Description.");
$v->isOk($reference, "string", 0, 50, "Invalid Reference Name/Number.");
$v->isOk($cheqnum, "num", 0, 30, "Invalid Cheque number.");
$v->isOk($amount, "float", 1, 10, "Invalid amount.");
# display errors, if any
if ($v->isError()) {
$confirm = "";
$errors = $v->getErrors();
foreach ($errors as $e) {
$confirm .= "<li class='err'>" . $e["msg"] . "</li>";
}
$confirm .= "<p><input type='button' onClick='JavaScript:history.back();' value='« Correct submission'>";
return $confirm;
}
# date format
$date = explode("-", $date);
$date = $date[2] . "-" . $date[1] . "-" . $date[0];
# refnum
$refnum = getrefnum();
# cheq number
$cheqnum = 0 + $cheqnum;
# Get customer
$custRslt = get("cubit", "*", "customers", "cusnum", $cusnum);
$cust = pg_fetch_array($custRslt);
# Get department
db_conn("exten");
$sql = "SELECT * FROM departments WHERE deptid = '{$cust['deptid']}' AND div = '" . USER_DIV . "'";
$deptRslt = db_exec($sql);
if (pg_numrows($deptRslt) < 1) {
return "<i class='err'>Department Not Found</i>";
} else {
$dept = pg_fetch_array($deptRslt);
}
# Get hook account number
core_connect();
$sql = "SELECT * FROM bankacc WHERE accid = '{$bankid}' AND div = '" . USER_DIV . "'";
$rslt = db_exec($sql) or errDie("Unable to retrieve bank account link from Cubit", SELF);
# Check if link exists
if (pg_numrows($rslt) < 1) {
return "<li class='err'> ERROR : The bank account that you selected doesn't appear to have an account linked to it.</li>";
}
$banklnk = pg_fetch_array($rslt);
# Begin updates
pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
# DT(customer control), CT(bank)
writetrans($dept['debtacc'], $banklnk['accnum'], $date, $refnum, $amount, $descript);
recordDT($amount, $cust['cusnum'], $date);
# Record the payment record
db_connect();
$sql = "\n\t\t\tINSERT INTO cashbook (\n\t\t\t\tbankid, trantype, date, cusnum, name, descript, \n\t\t\t\tcheqnum, amount, vat, chrgvat, banked, accinv, reference, div\n\t\t\t) VALUES (\n\t\t\t\t'{$bankid}', 'withdrawal', '{$date}', '{$cusnum}', '({$cust['accno']}) {$cust['cusname']} {$cust['surname']}', '{$descript}', \n\t\t\t\t'{$cheqnum}', '{$amount}', '0', 'no', 'no', '{$dept['debtacc']}', '{$reference}', '" . USER_DIV . "'\n\t\t\t)";
$Rslt = db_exec($sql) or errDie("Unable to add bank payment to database.", SELF);
# record the payment on the statement
$sql = "\n\t\t\tINSERT INTO stmnt (\n\t\t\t\tcusnum, invid, amount, date, type, st, div, allocation_date\n\t\t\t) VALUES (\n\t\t\t\t'{$cust['cusnum']}', '0', '{$amount}', '{$date}', '{$descript}', 'n', '" . USER_DIV . "', '{$date}'\n\t\t\t)";
$stmntRslt = db_exec($sql) or errDie("Unable to Insert statement record in Cubit.", SELF);
# record the payment on the statement
$sql = "\n\t\t\tINSERT INTO open_stmnt (\n\t\t\t\tcusnum, invid, amount, date, type, st, div, balance\n\t\t\t) VALUES (\n\t\t\t\t'{$cust['cusnum']}', '0', '{$amount}', '{$date}', '{$descript}', 'n', '" . USER_DIV . "', '{$amount}'\n\t\t\t)";
$stmntRslt = db_exec($sql) or errDie("Unable to Insert statement record in Cubit.", SELF);
# update the customer (make balance more)
$sql = "UPDATE customers SET balance = (balance + '{$amount}') WHERE cusnum = '{$cust['cusnum']}' AND div = '" . USER_DIV . "'";
$rslt = db_exec($sql) or errDie("Unable to update customer in Cubit.", SELF);
# Make ledge record
custledger($cust['cusnum'], $banklnk['accnum'], $date, $refnum, $descript, $amount, "d");
# Commit updates
pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
# Status report
$write = "\n\t\t<table " . TMPL_tblDflts . " width='100%'>\n\t\t\t<tr>\n\t\t\t\t<th>Bank Payment</th>\n\t\t\t</tr>\n\t\t\t<tr class='datacell'>\n\t\t\t\t<td>Bank Payment added to cash book.</td>\n\t\t\t</tr>\n\t\t</table>";
# Main table (layout with menu)
$OUTPUT = "\n\t\t<center>\n\t\t<table width='90%'>\n\t\t\t<tr valign='top'>\n\t\t\t\t<td width='50%'>{$write}</td>\n\t\t\t\t<td align='center'>\n\t\t\t\t\t<table " . TMPL_tblDflts . " width='80%'>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<th>Quick Links</th>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='datacell'>\n\t\t\t\t\t\t\t<td align='center'><a target=_blank href='../core/acc-new2.php'>Add account (New Window)</a></td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td><a href='bank-pay-add.php'>Add Bank Payment</a></td></tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td><a href='bank-recpt-add.php'>Add Bank Receipt</a></td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td><a href='cashbook-view.php'>View Cash Book</a></td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<script>document.write(getQuicklinkSpecial());</script>\n\t\t\t\t\t</table>\n\t\t\t\t</td>\n\t\t\t</tr>\n\t\t</table>";
return $OUTPUT;
}
示例2: recvpayment_write
function recvpayment_write()
{
if (isset($_POST["btn_back"])) {
return details($_POST);
}
extract($_POST);
$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($out, "float", 1, 40, "Invalid unallocated amount.");
$v->isOk($descript, "string", 1, 255, "Invalid description.");
$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))\n\t\t\tWHERE cusnum = '{$cus['cusnum']}' AND div = '" . USER_DIV . "'";
$rslt = db_exec($sql) or errDie("Unable to update invoice in Cubit.", SELF);
if (isset($invids)) {
foreach ($invids as $key => $value) {
$ii = $invids[$key];
/* OPTION 1: STOCK INVOICES */
if (!isset($itype[$ii]) && !isset($ptype[$ii])) {
$sql = "SELECT prd,invnum,odate FROM cubit.invoices\n\t\t\t\t\t\tWHERE invid ='{$invids[$key]}' 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 invoice balance
$sql = "UPDATE cubit.invoices\n\t\t\t\t\t\tSET balance = (balance - {$paidamt[$key]}::numeric(13,2))\n\t\t\t\t\t\tWHERE invid = '{$invids[$key]}' AND div = '" . USER_DIV . "'";
$payRslt = db_exec($sql) or errDie("Unable to update Invoice information in Cubit.", SELF);
$sql = "UPDATE cubit.open_stmnt\n\t\t\t\t\t\tSET balance = (balance - {$paidamt[$key]}::numeric(13,2))\n\t\t\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 = "\n\t\t\t\t\tINSERT INTO cubit.stmnt \n\t\t\t\t\t\t(cusnum, invid, amount, date, type, div, allocation_date) \n\t\t\t\t\tVALUES \n\t\t\t\t\t\t('{$cus['cusnum']}','{$inv['invnum']}', '" . ($paidamt[$key] - $paidamt[$key] * 2) . "','{$sdate}', 'Payment for Invoice No. {$inv['invnum']}', '" . USER_DIV . "', '{$inv['odate']}')";
$stmntRslt = db_exec($sql) or errDie("Unable to insert statement record in Cubit.", SELF);
custledger($cus['cusnum'], $bank_acc, $sdate, $inv['invnum'], "Payment for Invoice No. {$inv['invnum']}", $paidamt[$key], "c");
$rinvids .= "|{$invids[$key]}";
$amounts .= "|{$paidamt[$key]}";
if ($inv['prd'] == "0") {
$inv['prd'] = PRD_DB;
}
$invprds .= "|{$inv['prd']}";
$rages .= "|0";
$invidsers .= " - {$inv['invnum']}";
/* OPTION 1: NONS STOCK INVOICES */
} else {
if (!isset($ptype[$ii])) {
$sql = "SELECT prd,invnum,descrip,age,odate FROM cubit.nons_invoices\n\t\t\t\t\t\tWHERE invid ='{$invids[$key]}' 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
$sql = "UPDATE cubit.nons_invoices\n\t\t\t\t\t\tSET balance = (balance - {$paidamt[$key]}::numeric(13,2))\n\t\t\t\t\t\tWHERE invid = '{$invids[$key]}' AND div = '" . USER_DIV . "'";
$payRslt = db_exec($sql) or errDie("Unable to update Invoice information in Cubit.", SELF);
$sql = "UPDATE cubit.open_stmnt\n\t\t\t\t\t\tSET balance = (balance - {$paidamt[$key]}::numeric(13,2))\n\t\t\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 = "\n\t\t\t\t\tINSERT INTO cubit.stmnt \n\t\t\t\t\t\t(cusnum, invid, amount, date, type, div, allocation_date) \n\t\t\t\t\tVALUES \n\t\t\t\t\t\t('{$cus['cusnum']}','{$inv['invnum']}', '" . ($paidamt[$key] - $paidamt[$key] * 2) . "','{$sdate}', 'Payment for Non Stock Invoice No. {$inv['invnum']} - {$inv['descrip']}', '" . USER_DIV . "', '{$inv['odate']}')";
$stmntRslt = db_exec($sql) or errDie("Unable to insert statement record in Cubit.", SELF);
custledger($cus['cusnum'], $bank_acc, $sdate, $inv['invnum'], "Payment for Non Stock Invoice No. {$inv['invnum']} - {$inv['descrip']}", $paidamt[$key], "c");
recordCT($paidamt[$key], $cus['cusnum'], $inv['age'], $sdate);
$rinvids .= "|{$invids[$key]}";
$amounts .= "|{$paidamt[$key]}";
$invprds .= "|0";
$rages .= "|{$inv['age']}";
$invidsers .= " - {$inv['invnum']}";
} else {
/* pos invoices */
$sql = "SELECT * FROM cubit.prd_pinvoices\n\t\t\t\t\t\tWHERE invid='{$invids[$key]}' 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.</li>";
}
$inv = pg_fetch_array($invRslt);
// reduce the invoice balance
$sql = "UPDATE \"{$inv['iprd']}\".pinvoices\n\t\t\t\t\t\tSET balance = (balance - {$paidamt[$key]}::numeric(13,2))\n\t\t\t\t\t\tWHERE invid = '{$invids[$key]}' AND div = '" . USER_DIV . "'";
$payRslt = db_exec($sql) or errDie("Unable to update Invoice information in Cubit.", SELF);
$sql = "UPDATE cubit.open_stmnt\n\t\t\t\t\t\tSET balance = (balance - {$paidamt[$key]}::numeric(13,2))\n\t\t\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 = "\n\t\t\t\t\tINSERT INTO cubit.stmnt\n\t\t\t\t\t\t(cusnum, invid, amount, date, type, div, allocation_date) \n\t\t\t\t\tVALUES \n\t\t\t\t\t\t('{$cus['cusnum']}','{$inv['invnum']}', '" . ($paidamt[$key] - $paidamt[$key] * 2) . "','{$sdate}', 'Payment for Non Stock Invoice No. {$inv['invnum']}', '" . USER_DIV . "', '{$inv['odate']}')";
$stmntRslt = db_exec($sql) or errDie("Unable to insert statement record in Cubit.", SELF);
custledger($cus['cusnum'], $bank_acc, $sdate, $inv['invnum'], "Payment for Non Stock Invoice No. {$inv['invnum']}", $paidamt[$key], "c");
recordCT($paidamt[$key], $cus['cusnum'], 0, $sdate);
//.........这里部分代码省略.........
示例3: write
function write()
{
extract($_REQUEST);
require_lib("validate");
$v = new validate();
$v->isOk($invid, "num", 1, 20, "Invalid invoice number.");
$sndate = "{$ninv_year}-{$ninv_month}-{$ninv_day}";
if (!checkdate($ninv_month, $ninv_day, $ninv_year)) {
$v->addError($sdate, "Invalid Date.");
}
pglib_transaction("BEGIN");
// Get invoice info
$sql = "SELECT * FROM cubit.nons_invoices WHERE invid='{$invid}' AND div='" . USER_DIV . "'";
$inv_rslt = db_exec($sql) or errDie("Unable to get invoice information");
if (pg_numrows($inv_rslt) < 1) {
return "<i class='err'>Not Found</i>";
}
$inv = pg_fetch_array($inv_rslt);
$TOTAL = $inv["subtot"] + $inv["vat"];
$notenum = pglib_lastid("cubit.nons_inv_notes", "noteid");
$notenum++;
// Add to the non stock credit notes
$sql = "\r\n\t\tINSERT INTO cubit.nons_inv_notes (\r\n\t\t\tinvid, invnum, cusname, cusaddr, cusvatno, chrgvat, \r\n\t\t\tdate, subtot, vat, total, username, prd, notenum, ctyp, \r\n\t\t\tremarks, div\r\n\t\t) VALUES (\r\n\t\t\t'{$inv['invid']}', '{$inv['invnum']}', '{$inv['cusname']}', '{$inv['cusaddr']}', '{$inv['cusvatno']}', '{$inv['chrgvat']}', \r\n\t\t\t'{$sndate}', '{$inv['subtot']}', '{$inv['vat']}', '{$TOTAL}', '" . USER_NAME . "', '" . PRD_DB . "', '{$notenum}', '{$inv['ctyp']}', \r\n\t\t\t'{$inv['remarks']}', '" . USER_DIV . "'\r\n\t\t)";
db_exec($sql) or errDie("Unable to save credit note.");
$noteid = pglib_lastid("cubit.nons_inv_notes", "noteid");
$sql = "SELECT count(id) FROM cubit.nons_inv_items WHERE invid='{$invid}'";
$count_rslt = db_exec($sql) or errDie("Unable to retrieve amount of items.");
$item_count = pg_fetch_result($count_rslt, 0);
$i = 0;
$page = 0;
foreach ($ids as $key => $id) {
$sql = "SELECT * FROM cubit.nons_inv_items WHERE invid='{$invid}' AND id='{$id}'";
$item_rslt = db_exec($sql) or errDie("Unable to retrieve item.");
$item_data = pg_fetch_array($item_rslt);
if ($item_data['vatex'] == 'y') {
$ex = "#";
} else {
$ex = " ";
}
// Time for a new page ??
if ($i >= 25) {
$page++;
$i = 0;
}
$products[$page][] = "\r\n\t\t\t<tr valign='top'>\r\n\t\t\t\t<td style='border-right: 2px solid #000'>\r\n\t\t\t\t\t{$ex} {$item_data['description']} \r\n\t\t\t\t</td>\r\n\t\t\t\t<td style='border-right: 2px solid #000'>\r\n\t\t\t\t\t{$item_data['qty']} \r\n\t\t\t\t</td>\r\n\t\t\t\t<td style='border-right: 2px solid #000' align='right' nowrap>\r\n\t\t\t\t\t" . CUR . " {$item_data['unitcost']} \r\n\t\t\t\t</td>\r\n\t\t\t\t<td align='right' nowrap>" . CUR . " {$item_data['amt']} </td>\r\n\t\t\t</tr>";
$i++;
// Create credit note item
$sql = "\r\n\t\t\tINSERT INTO cubit.nons_note_items (\r\n\t\t\t\tnoteid, qty, description, amt, unitcost, \r\n\t\t\t\tvatcode\r\n\t\t\t) VALUES (\r\n\t\t\t\t'{$noteid}', '{$qtys[$key]}', '{$item_data['description']}', '{$amts[$key]}', '{$item_data['unitcost']}', \r\n\t\t\t\t'{$item_data['vatex']}'\r\n\t\t\t)";
db_exec($sql) or errDie("Unable to create credit note item.");
$sql = "SELECT grpid FROM cubit.assets WHERE id='{$item_data['asset_id']}'";
$group_rslt = db_exec($sql) or errDie("Unable to retrieve group.");
$group_id = pg_fetch_result($group_rslt, 0);
$discount = $inv["discount"] / $item_count;
$amt = $item_data["amt"];
// Update royalty report and detail report
$sql = "\r\n\t\t\tINSERT INTO hire.revenue (\r\n\t\t\t\tgroup_id, asset_id, total, discount, credit\r\n\t\t\t) VALUES (\r\n\t\t\t\t'{$group_id}', '{$item_data['asset_id']}', '-{$amt}', '-{$discount}', '1'\r\n\t\t\t)";
db_exec($sql) or errDie("Unable to update revenue.");
$i++;
}
$blank_lines = 25;
foreach ($products as $key => $val) {
$bl = $blank_lines - count($products[$key]);
for ($i = 0; $i <= $bl; $i++) {
$products[$key][] = "\r\n\t\t\t\t<tr>\r\n\t\t\t\t\t<td style='border-right: 2px solid #000'> </td>\r\n\t\t\t\t\t<td style='border-right: 2px solid #000'> </td>\r\n\t\t\t\t\t<td style='border-right: 2px solid #000'> </td>\r\n\t\t\t\t\t<td> </td>\r\n\t\t\t\t</tr>";
}
}
// Retrieve customer debt account
$sql = "\r\n\t\tSELECT debtacc FROM exten.departments \r\n\t\t\tLEFT JOIN cubit.customers ON departments.deptid=customers.deptid\r\n\t\tWHERE cusnum='{$inv['cusid']}'";
$dept_rslt = db_exec($sql) or errDie("Unable to retrieve departments.");
$debtacc = pg_fetch_result($dept_rslt, 0);
$hireacc = $inv["accid"];
$vatacc = gethook("accnum", "salesacc", "name", "VAT", "vat");
$refnum = getrefnum();
writetrans($hireacc, $debtacc, $sndate, $refnum, $inv["subtot"], "Non-Stock Invoice No. {$inv['invnum']} Credit Note No. {$noteid} Customer\r\n\t\t{$inv['cusname']}");
if ($inv["vat"] != 0) {
writetrans($vatacc, $debtacc, $sndate, $refnum, $inv["vat"], "Non-Stock Invoice No. {$inv['invnum']} Credit Note No. {$noteid} VAT.\r\n\t\tCustomer {$inv['cusname']}");
}
// Record on the statement
$sql = "\r\n\t\tINSERT INTO cubit.stmnt (\r\n\t\t\tcusnum, invid, amount, date, type, \r\n\t\t\tdiv\r\n\t\t) VALUES (\r\n\t\t\t'{$inv['cusid']}', '{$noteid}', '-{$TOTAL}', '{$sndate}', 'Non-Stock Credit Note, for invoice {$inv['invnum']}', \r\n\t\t\t'" . USER_DIV . "'\r\n\t\t)";
db_exec($sql) or errDie("Unable to insert to customer statement.");
// Update the customer (Make the balance less)
$sql = "UPDATE cubit.customers SET balance=(balance-'{$TOTAL}') WHERE cusnum='{$inv['cusid']}'";
db_exec($sql) or errDie("Unable to update customer balance.");
// Update the customer (Make the balance less)
$sql = "UPDATE cubit.open_stmnt SET balance=(balance-'{$TOTAL}') WHERE cusnum='{$inv['cusid']}'";
db_exec($sql) or errDie("Unable to update customer balance.");
// Create ledger record
custledger($inv["cusid"], $hireacc, $sndate, $noteid, "Non-Stock Credit Note {$noteid}", $TOTAL, "c");
custCT($inv["total"], $inv["cusid"], $inv["odate"]);
// Update non-stock invoice
$sql = "UPDATE cubit.nons_invoices SET balance=(balance-'{$TOTAL}') WHERE invid='{$invid}'";
db_exec($sql) or errDie("Unable to update non-stock invoice.");
$sql = "\r\n\t\tINSERT INTO cubit.salesrec (\r\n\t\t\tedate, invid, invnum, debtacc, vat, total, typ, div\r\n\t\t) VALUES (\r\n\t\t\t'{$sndate}', '{$noteid}', '{$notenum}', '0', '{$inv['vat']}', '{$TOTAL}', 'nnon', '" . USER_DIV . "'\r\n\t\t)";
db_exec($sql) or errDie("Unable to record in sales.");
$sql = "\r\n\t\tINSERT INTO cubit.sj (\r\n\t\t\tcid, name, des, date, \r\n\t\t\texl, vat, inc, div\r\n\t\t) VALUES (\r\n\t\t\t'{$inv['cusid']}', '{$inv['cusname']}', 'Credit Note: {$noteid} Invoice {$inv['invnum']}', '{$sndate}', \r\n\t\t\t'-" . ($TOTAL - $inv["vat"]) . "', '{$inv['vat']}', '" . -sprint($TOTAL) . "', '" . USER_DIV . "'\r\n\t\t)";
db_exec($sql) or errDie("Unable to record in sj.");
$sql = "UPDATE cubit.nons_invoices SET accepted='note' WHERE invid='{$invid}'";
db_exec($sql) or errDie("Unable to update invoice.");
com_invoice($inv["salespn"], -($TOTAL - $inv["vat"]), 0, $inv["invnum"], $sndate);
$cc = "\r\n\t\t<script>\r\n\t\t\tCostCenter('ct', 'Credit Note', '{$sndate}',\r\n\t\t\t'Non Stock Credit Note No.{$noteid}', '" . ($TOTAL - $inv["vat"]) . "', '');\r\n\t </script>";
//.........这里部分代码省略.........
示例4: write
//.........这里部分代码省略.........
$accid = $parr['contra_account'];
$refnum = $parr['ref_num'];
$details = $parr['description'];
if (isset($chrgvat) and $chrgvat == "yes") {
db_connect();
#get selected vatcode
$get_vatcode = "SELECT * FROM vatcodes WHERE id = '{$vatcode}' LIMIT 1";
$run_vatcode = db_exec($get_vatcode) or errDie("Unable to get vat code information.");
if (pg_numrows($run_vatcode) < 1) {
#vatcode not found ....
return "<li class='err'>Unable to get vat code information.</li>";
}
$vd = pg_fetch_array($run_vatcode);
if ($vatinc == "inc") {
#vat inc ... recalc value
$vatamt = sprint($amount * ($vd['vat_amount'] / (100 + $vd['vat_amount'])));
$amount = sprint($amount - $vatamt);
} else {
#vat excl
$amount = sprint($amount);
$vatamt = sprint($amount / 100 * $vd['vat_amount']);
}
} else {
#vat not set
$amount = sprint($amount);
$vatamt = sprint(0);
}
// $date = "$datea[2]-$datea[1]-$datea[0]";
# Accounts details
$accRs = get("core", "*", "accounts", "accid", $accid);
$acc = pg_fetch_array($accRs);
# Select customer
db_connect();
$sql = "SELECT * FROM customers WHERE cusnum = '{$cusnum}' AND div = '" . USER_DIV . "'";
$custRslt = db_exec($sql) or errDie("Unable to access databse.", SELF);
if (pg_numrows($custRslt) < 1) {
return slctacc($_POST, "<li class='err'>Invalid customer ID, or customer has been blocked.</li>");
} else {
$cust = pg_fetch_array($custRslt);
}
# Get department
db_conn("exten");
$sql = "SELECT * FROM departments WHERE deptid = '{$cust['deptid']}' AND div = '" . USER_DIV . "'";
$deptRslt = db_exec($sql);
if (pg_numrows($deptRslt) < 1) {
return slctacc($_POST, "<i class='err'>Department Not Found</i>");
} else {
$dept = pg_fetch_array($deptRslt);
}
#get vat acc ...
$vatacc = gethook("accnum", "salesacc", "name", "VAT", "VAT");
# Begin updates
pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
# Probe tran type
if ($entry == "CT") {
# Write transaction (debit contra account, credit debtors control)
writetrans($accid, $dept['debtacc'], $date, $refnum, $amount, $details . " - Customer {$cust['cusname']} {$cust['surname']}");
$tran = "\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t <td>{$acc['topacc']}/{$acc['accnum']} - {$acc['accname']}</td>\n\t\t\t\t <td>{$cust['accno']} - {$cust['cusname']} {$cust['surname']}</td>\n\t\t\t </tr>";
$samount = $amount - $amount * 2;
$svatamt = $vatamt - $vatamt * 2;
recordCT($samount, $cust['cusnum'], $date);
$type = 'c';
if (isset($chrgvat) and $chrgvat == "yes") {
writetrans($vatacc, $dept['debtacc'], $date, $refnum, $vatamt, "VAT for Transaction: {$refnum} for Customer : {$cust['cusname']} {$cust['surname']}");
vatr($vd['id'], $date, "OUTPUT", $vd['code'], $refnum, "VAT for Transaction: {$refnum} for Customer : {$cust['cusname']} {$cust['surname']}", $samount + $svatamt, $svatamt);
}
} else {
# Write transaction (debit debtors control, credit contra account)
writetrans($dept['debtacc'], $accid, $date, $refnum, $amount, $details . " - Customer {$cust['cusname']} {$cust['surname']}");
$tran = "\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>{$cust['accno']} - {$cust['cusname']} {$cust['surname']}</td>\n\t\t\t\t\t<td>{$acc['topacc']}/{$acc['accnum']} - {$acc['accname']}</td>\n\t\t\t\t</tr>";
$samount = $amount;
$svatamt = $vatamt;
recordDT($samount, $cust['cusnum'], $date);
$type = 'd';
if (isset($chrgvat) and $chrgvat == "yes") {
writetrans($dept['debtacc'], $vatacc, $date, $refnum, $vatamt, "VAT for Transaction: {$refnum} for Customer : {$cust['cusname']} {$cust['surname']}");
vatr($vd['id'], $date, "OUTPUT", $vd['code'], $refnum, "VAT for Transaction: {$refnum} for Customer : {$cust['cusname']} {$cust['surname']}", $amount + $vatamt, $vatamt);
}
}
db_connect();
$sdate = date("Y-m-d");
# record the payment on the statement
$sql = "\n\t\t\tINSERT INTO stmnt (\n\t\t\t\tcusnum, invid, amount, date, type, st, div, allocation_date\n\t\t\t) VALUES (\n\t\t\t\t'{$cust['cusnum']}', '0', '" . sprint($samount + $svatamt) . "', '{$date}', '{$details}', 'n', '" . USER_DIV . "', '{$date}'\n\t\t\t)";
$stmntRslt = db_exec($sql) or errDie("Unable to Insert statement record in Cubit.", SELF);
$sql = "\n\t\t\tINSERT INTO open_stmnt (\n\t\t\t\tcusnum, invid, amount, balance, date, type, st, div\n\t\t\t) VALUES (\n\t\t\t\t'{$cust['cusnum']}', '0', '" . sprint($samount + $svatamt) . "', '" . sprint($samount + $svatamt) . "', '{$date}', '{$details}', 'n', '" . USER_DIV . "'\n\t\t\t)";
$stmntRslt = db_exec($sql) or errDie("Unable to Insert statement record in Cubit.", SELF);
# update the customer (make balance more)
$sql = "UPDATE customers SET balance = (balance + '{$samount}') WHERE cusnum = '{$cust['cusnum']}' AND div = '" . USER_DIV . "'";
$rslt = db_exec($sql) or errDie("Unable to update customer in Cubit.", SELF);
# Make ledge record
// custledger($cust['cusnum'], $accid, $date, $refnum, $details, $amount, $type);
custledger($cust['cusnum'], $accid, $date, $refnum, $details, sprint($amount + $vatamt), $type);
db_connect();
$rem_batch = "DELETE FROM cust_trans_batch WHERE id = '{$procid}'";
$run_batch = db_exec($rem_batch) or errDie("Unable to remove customer batch transaction information.");
# Commit updates
pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
}
return slctacc($_POST, "<li class='yay'>Transaction(s) Have Been Processed.</li><br>");
}
示例5: write
function write($_POST)
{
# processes
db_connect();
# Get vars
extract($_POST);
# validate input
require_lib("validate");
$v = new validate();
$v->isOk($bankid, "num", 1, 30, "Invalid Bank Account.");
$v->isOk($date, "date", 1, 10, "Invalid Date Entry.");
$v->isOk($descript, "string", 0, 255, "Invalid Description.");
$v->isOk($cheqnum, "num", 0, 30, "Invalid Cheque number.");
$v->isOk($amount, "float", 1, 10, "Invalid amount.");
$v->isOk($cusid, "num", 1, 20, "Invalid customer account.");
# Display errors, if any
if ($v->isError()) {
$confirm = "";
$errors = $v->getErrors();
foreach ($errors as $e) {
$confirm .= "<li class='err'>" . $e["msg"] . "</li>";
}
$confirm .= "<p><input type='button' onClick='JavaScript:history.back();' value='« Correct submission'>";
return $confirm;
}
# date format
$date = explode("-", $date);
$date = $date[2] . "-" . $date[1] . "-" . $date[0];
$cheqnum = 0 + $cheqnum;
core_connect();
$sql = "SELECT * FROM bankacc WHERE accid = '{$bankid}' AND div = '" . USER_DIV . "'";
$rslt = db_exec($sql) or errDie("Unable to retrieve bank account link from Cubit", SELF);
# Check if link exists
if (pg_numrows($rslt) < 1) {
return "<li class='err'> ERROR : The bank account that you selected doesn't appear to have an account linked to it.</li>";
}
$bank = pg_fetch_array($rslt);
# get account name
$supRslt = get("cubit", "*", "customers", "cusnum", $cusid);
$cus = pg_fetch_array($supRslt);
db_conn("exten");
# get debtors control account
$sql = "SELECT debtacc FROM departments WHERE deptid ='{$cus['deptid']}' AND div = '" . USER_DIV . "'";
$deptRslt = db_exec($sql);
$dept = pg_fetch_array($deptRslt);
db_connect();
$Sl = "\n\t\tINSERT INTO stmnt \n\t\t\t(cusnum, invid, amount, date, type, div, allocation_date) \n\t\tVALUES \n\t\t\t('{$cusid}','0','{$amount}', '{$date}','{$descript}','" . USER_DIV . "', '{$date}')";
$Rs = db_exec($Sl) or errDie("Unable to insert statement record in Cubit.", SELF);
$Sl = "INSERT INTO open_stmnt (cusnum, invid, amount, date, type, div,balance) VALUES ('{$cusid}','0','{$amount}', '{$date}','{$descript}','" . USER_DIV . "','{$amount}')";
$Rs = db_exec($Sl) or errDie("Unable to insert statement record in Cubit.", SELF);
$sql = "UPDATE customers SET balance = (balance + '{$amount}') WHERE cusnum = '{$cus['cusnum']}' AND div = '" . USER_DIV . "'";
$rslt = db_exec($sql) or errDie("Unable to update invoice in Cubit.", SELF);
custledger($cusid, $bank['accnum'], $date, '0', "Payment to Customer", $amount, "d");
custDT($amount, $cus['cusnum']);
# record the payment record
db_connect();
$sql = "INSERT INTO cashbook(bankid, trantype, date, name, descript, cheqnum, amount, banked, accinv, suprec, div) VALUES ('{$bankid}', 'withdrawal', '{$date}', '{$cus['cusname']} {$cus['surname']}', '{$descript}', '{$cheqnum}', '{$amount}', 'no', '{$dept['debtacc']}', '{$cusid}', '" . USER_DIV . "')";
$Rslt = db_exec($sql) or errDie("Unable to add bank payment to database.", SELF);
$refnum = getrefnum();
writetrans($dept['debtacc'], $bank['accnum'], $date, $refnum, $amount, $descript);
# status report
$write = "\n\t\t\t\t<table " . TMPL_tblDflts . " width='100%'>\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<th>Bank Payment</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>Bank Payment to customer : {$cus['surname']} added to cash book.</td>\n\t\t\t\t\t</tr>\n\t\t\t\t</table>\n\t\t\t";
# main table (layout with menu)
$OUTPUT = "\n\t\t\t\t<center>\n\t\t\t\t<table " . TMPL_tblDflts . ">\n\t\t\t\t\t<tr valign='top'>\n\t\t\t\t\t\t<td width='50%'>{$write}</td>\n\t\t\t\t\t\t<td align='center'>\n\t\t\t\t\t\t\t<table " . TMPL_tblDflts . " width='80%'>\n\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t<th>Quick Links</th>\n\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t\t\t<td><a href='bank-pay-add.php'>Add Bank Payment</a></td>\n\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t\t\t<td><a href='bank-recpt-add.php'>Add Bank Receipt</a></td>\n\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t\t\t<td><a href='cashbook-view.php'>View Cash Book</a></td>\n\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t</table>\n\t\t\t\t\t\t</td>\n\t\t\t\t\t</tr>\n\t\t\t\t</table>\n\t\t\t";
return $OUTPUT;
}
示例6: write
//.........这里部分代码省略.........
$sdate = date("Y-m-d");
# record transaction from data
foreach ($totstkamt as $stkacc => $wamt) {
# Debit Customer and Credit stock
$tot_post += $wamt;
writetrans($stkacc, $cusacc, $td, $refnum, $wamt, "Non-Stock invoice No. {$inv['invnum']} Credit note No.{$real_noteid}.");
pettyrec($cusacc, $td, "dt", "Non-Stock invoice No. {$inv['invnum']} Credit note No.{$real_noteid}.", $wamt, "Account Sale Credit note");
}
# Debit bank and credit the account involved
$tot_post += $VAT;
writetrans($vatacc, $cusacc, $td, $refnum, $VAT, "Non-Stock invoice No. {$inv['invnum']} Credit note No.{$real_noteid} VAT.");
pettyrec($cusacc, $td, "dt", "Non-Stock invoice No. {$inv['invnum']} Credit note No.{$real_noteid} VAT.", $VAT, "Account Sale Credit note VAT");
$tot_dif = sprint($tot_post - $TOTAL);
if ($tot_dif > 0) {
writetrans($cusacc, $varacc, $td, $refnum, $tot_dif, "Sales Variance on Credit note No.{$real_noteid}");
} elseif ($tot_dif < 0) {
$tot_dif = $tot_dif * -1;
writetrans($varacc, $cusacc, $td, $refnum, $tot_dif, "Sales Variance on Credit note No.{$real_noteid}");
}
}
$sdate = date("Y-m-d");
db_connect();
if ($inv['ctyp'] == 's') {
# Record the payment on the statement
$sql = "\r\n\t\t\tINSERT INTO stmnt \r\n\t\t\t\t(cusnum, invid, amount, date, type, div, allocation_date) \r\n\t\t\tVALUES \r\n\t\t\t\t('{$inv['cusid']}', '{$real_noteid}', '-{$TOTAL}','{$td}', 'Non Stock Credit Note, for invoice {$inv['invnum']}', '" . USER_DIV . "', '{$inv['odate']}')";
$stmntRslt = db_exec($sql) or errDie("Unable to insert statement record in Cubit.", SELF);
# Update the customer (make balance less)
$sql = "UPDATE customers SET balance = (balance - '{$TOTAL}'::numeric(13,2)) WHERE cusnum = '{$inv['cusid']}' AND div = '" . USER_DIV . "'";
$rslt = db_exec($sql) or errDie("Unable to update invoice in Cubit.", SELF);
# Update the customer (make balance less)
$sql = "UPDATE open_stmnt SET balance = (balance - '{$TOTAL}'::numeric(13,2)) WHERE invid = '{$inv['invnum']}' AND div = '" . USER_DIV . "'";
$rslt = db_exec($sql) or errDie("Unable to update invoice in Cubit.", SELF);
# Make ledge record
custledger($inv['cusid'], $stkacc, $td, $real_noteid, "Non Stock Credit note {$real_noteid}", $TOTAL, "c");
#record entry for age analysis ...
#this function seems a little ... broken
//custfCT($TOTAL, $inv['cusid'], $inv['age']);
#lets rather use the system wide function and send it the invoice transaction date to do the entry for that age
custCT($TOTAL, $inv['cusid'], $inv['odate']);
} elseif ($inv['ctyp'] == 'cb') {
$date = date("Y-m-d");
# Record the Receipt record
db_connect();
$sql = "INSERT INTO cashbook(bankid, trantype, date, name, descript, cheqnum, amount, banked, accids, amounts, chrgvats, vats, div,accinv) VALUES ('{$inv['jobid']}', 'withdrawal', '{$td}', '{$inv['cusname']}', 'Nons Stock Credit note for invoice {$inv['invnum']}', '0', '{$TOTAL}', 'no', '', '0', '{$inv['chrgvat']}', '0', '" . USER_DIV . "','{$stkacc}')";
die($sql);
$Rslt = db_exec($sql) or errDie("Unable to add bank Receipt to database.", SELF);
}
db_connect();
$sql = "UPDATE hire.hire_nons_invoices SET balance = (balance - '{$TOTAL}'::numeric(13,2)) WHERE invid = '{$invid}' AND div = '" . USER_DIV . "'";
$upRslt = db_exec($sql) or errDie("Unable to update invoice information");
# write note
$sql = "INSERT INTO hire.hire_nons_inv_notes(invid, invnum, cusname, cusaddr, cusvatno, chrgvat, date, subtot, vat, total, username, prd, notenum, ctyp, remarks, div)";
$sql .= " VALUES('{$inv['invid']}', '{$inv['invnum']}', '{$inv['cusname']}', '{$inv['cusaddr']}', '{$inv['cusvatno']}', '{$inv['chrgvat']}', '{$td}', {$SUBTOT}, {$VAT}, {$TOTAL}, '" . USER_NAME . "', '" . PRD_DB . "', '{$real_noteid}', '{$inv['ctyp']}', '{$remarks}', '" . USER_DIV . "')";
$rslt = db_exec($sql) or errDie("Unable to create template Non-Stock Invoice.", SELF);
# write note items
foreach ($ids as $key => $id) {
$sql = "SELECT * FROM hire.hire_nons_inv_items WHERE invid = '{$invid}' AND id = '{$id}' AND div = '" . USER_DIV . "'";
$stkdRslt = db_exec($sql);
$nstk = pg_fetch_array($stkdRslt);
}
$sql = "INSERT INTO salesrec(edate, invid, invnum, debtacc, vat, total, typ, div)\r\n\tVALUES('{$td}', '{$noteid}', '{$real_noteid}', '0', '{$VAT}', '{$TOTAL}', 'nnon', '" . USER_DIV . "')";
$recRslt = db_exec($sql);
$Sl = "INSERT INTO sj(cid,name,des,date,exl,vat,inc,div) VALUES\r\n\t('{$inv['cusid']}','{$inv['cusname']}','Credit Note: {$real_noteid}, Invoice {$inv['invnum']}','{$td}','" . -sprint($TOTAL - $VAT) . "','-{$VAT}','" . -sprint($TOTAL) . "','" . USER_DIV . "')";
$Ri = db_exec($Sl);
com_invoice($inv['salespn'], -($TOTAL - $VAT), 0, $inv['invnum'], $td);
# Commit updates
示例7: write
//.........这里部分代码省略.........
if ($all == 2) {
$sql = "UPDATE cubit.customers SET balance = (balance - '{$amt}'::numeric(16,2)) WHERE cusnum = '{$cus['cusnum']}' AND div = '" . USER_DIV . "'";
$rslt = db_exec($sql) or errDie("Unable to update invoice in Cubit.", SELF);
if (isset($invids)) {
foreach ($invids as $key => $value) {
$ii = $invids[$key];
# some logic ...
# because the customer account should be 0 when paid fully, we need
# to also deduct the settlement amount ...
$paidamt[$key] = $paidamt[$key] + $stock_setamt[$key];
# with the amount added to the paid amount, we tract it using a new
# seperate setamt db column
if (!isset($itype[$key]) && !isset($ptype[$key])) {
$sql = "SELECT prd,invnum,odate FROM cubit.invoices WHERE invid ='{$invids[$key]}' 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.</li>";
}
$inv = pg_fetch_array($invRslt);
// reduce invoice balance
$sql = "\n\t\t\t\t\t\tUPDATE cubit.invoices\n\t\t\t\t\t\tSET balance = (balance - {$paidamt[$key]}::numeric(16,2))\n\t\t\t\t\t\tWHERE invid = '{$invids[$key]}' AND div = '" . USER_DIV . "'";
$payRslt = db_exec($sql) or errDie("Unable to update Invoice information in Cubit.", SELF);
$sql = "\n\t\t\t\t\t\tUPDATE cubit.open_stmnt\n\t\t\t\t\t\tSET balance = (balance - {$paidamt[$key]}::numeric(16,2))\n\t\t\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 = "\n\t\t\t\t\t\tINSERT INTO cubit.stmnt (\n\t\t\t\t\t\t\tcusnum, invid, \n\t\t\t\t\t\t\tamount, date, type, div, allocation_date, docref, \n\t\t\t\t\t\t\tallocation_balance\n\t\t\t\t\t\t) VALUES (\n\t\t\t\t\t\t\t'{$cus['cusnum']}', '{$inv['invnum']}', \n\t\t\t\t\t\t\t'" . ($paidamt[$key] - $stock_setamt[$key] - ($paidamt[$key] - $stock_setamt[$key]) * 2) . "', \n\t\t\t\t\t\t\t'{$sdate}', 'Payment for Invoice No. {$inv['invnum']}', '" . USER_DIV . "', '{$inv['odate']}', '{$reference}', \n\t\t\t\t\t\t\t'" . abs($paidamt[$key] - $stock_setamt[$key] - ($paidamt[$key] - $stock_setamt[$key]) * 2) . "'\n\t\t\t\t\t\t)";
$stmntRslt = db_exec($sql) or errDie("Unable to insert statement record in Cubit.", SELF);
#record the settlement discount on the statement
if ($stock_setamt[$key] > 0) {
$sql = "\n\t\t\t\t\t\t\tINSERT INTO cubit.stmnt (\n\t\t\t\t\t\t\t\tcusnum, invid, amount, \n\t\t\t\t\t\t\t\tdate, type, \n\t\t\t\t\t\t\t\tdiv, allocation_date, docref, allocation_balance\n\t\t\t\t\t\t\t) VALUES (\n\t\t\t\t\t\t\t\t'{$cus['cusnum']}', '{$inv['invnum']}', '" . ($stock_setamt[$key] - $stock_setamt[$key] * 2) . "', \n\t\t\t\t\t\t\t\t'{$sdate}', 'Settlement Discount for Invoice No.{$inv['invnum']} Ref. {$refnum}', \n\t\t\t\t\t\t\t\t'" . USER_DIV . "', '{$inv['odate']}', '{$reference}', '" . abs($stock_setamt[$key] - $stock_setamt[$key] * 2) . "'\n\t\t\t\t\t\t\t)";
$stmntRslt = db_exec($sql) or errDie("Unable to insert statement record in Cubit.", SELF);
}
#deduct setamt for records ...
custledger($cus['cusnum'], $bank_acc, $sdate, $inv['invnum'], "Payment for Invoice No. {$inv['invnum']}", $paidamt[$key] - $stock_setamt[$key], "c");
db_connect();
$rinvids .= "|{$invids[$key]}";
$amounts .= "|{$paidamt[$key]}";
if ($inv['prd'] == "0") {
$inv['prd'] = PRD_DB;
}
$invprds .= "|{$inv['prd']}";
$rages .= "|0";
$invidsers .= " - {$inv['invnum']}";
$setamts .= "|{$stock_setamt[$key]}";
} elseif (!isset($ptype[$key])) {
$sql = "\n\t\t\t\t\t\tSELECT prd,invnum,descrip,age,odate \n\t\t\t\t\t\tFROM cubit.nons_invoices \n\t\t\t\t\t\tWHERE invid ='{$invids[$key]}' 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.</li>";
}
$inv = pg_fetch_array($invRslt);
// reduce the invoice balance
$sql = "\n\t\t\t\t\t\tUPDATE cubit.nons_invoices \n\t\t\t\t\t\tSET balance = (balance - {$paidamt[$key]}::numeric(16,2)) \n\t\t\t\t\t\tWHERE invid = '{$invids[$key]}' AND div = '" . USER_DIV . "'";
$payRslt = db_exec($sql) or errDie("Unable to update Invoice information in Cubit.", SELF);
$sql = "\n\t\t\t\t\t\tUPDATE cubit.open_stmnt \n\t\t\t\t\t\tSET balance = (balance - {$paidamt[$key]}::numeric(16,2)) \n\t\t\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);
if (!isset($inv['odate']) or strlen($inv['odate']) < 1) {
$inv['odate'] = $sdate;
}
// add payment to statement
$sql = "\n\t\t\t\t\t\tINSERT INTO cubit.stmnt (\n\t\t\t\t\t\t\tcusnum, invid, \n\t\t\t\t\t\t\tamount, \n\t\t\t\t\t\t\tdate, type, \n\t\t\t\t\t\t\tdiv, allocation_date, docref, allocation_balance\n\t\t\t\t\t\t) VALUES (\n\t\t\t\t\t\t\t'{$cus['cusnum']}', '{$inv['invnum']}', \n\t\t\t\t\t\t\t'" . ($paidamt[$key] - $stock_setamt[$key] - ($paidamt[$key] - $stock_setamt[$key]) * 2) . "', \n\t\t\t\t\t\t\t'{$sdate}', 'Payment for Non Stock Invoice No. {$inv['invnum']} - {$inv['descrip']}', \n\t\t\t\t\t\t\t'" . USER_DIV . "', '{$inv['odate']}', '{$reference}', '" . abs($paidamt[$key] - $stock_setamt[$key] - ($paidamt[$key] - $stock_setamt[$key]) * 2) . "'\n\t\t\t\t\t\t)";
$stmntRslt = db_exec($sql) or errDie("Unable to insert statement record in Cubit.", SELF);
#record the settlement discount on the statement
if ($stock_setamt[$key] > 0) {
$sql = "\n\t\t\t\t\t\t\tINSERT INTO cubit.stmnt (\n\t\t\t\t\t\t\t\tcusnum, invid, amount, \n\t\t\t\t\t\t\t\tdate, type, \n\t\t\t\t\t\t\t\tdiv, allocation_date, docref, allocation_balance\n\t\t\t\t\t\t\t) VALUES (\n\t\t\t\t\t\t\t\t'{$cus['cusnum']}', '{$inv['invnum']}', '" . ($stock_setamt[$key] - $stock_setamt[$key] * 2) . "', \n\t\t\t\t\t\t\t\t'{$sdate}', 'Settlement Discount for Invoice No.{$inv['invnum']} Ref. {$refnum}', \n\t\t\t\t\t\t\t\t'" . USER_DIV . "', '{$inv['odate']}', '{$reference}', '" . abs($stock_setamt[$key] - $stock_setamt[$key] * 2) . "'\n\t\t\t\t\t\t\t)";
$stmntRslt = db_exec($sql) or errDie("Unable to insert statement record in Cubit.", SELF);
示例8: cwrite
//.........这里部分代码省略.........
$totstkamt[$stkacc] += vats($stk['amt'], $inv['chrgvat'], $vd['vat_amount']);
$va = sprint($stk['amt'] - vats($stk['amt'], $inv['chrgvat'], $vd['vat_amount']));
if ($inv['chrgvat'] == "no") {
$va = sprint($stk['amt'] * $VATP / 100);
}
}
} else {
if ($stk['vatex'] == "y") {
$totstkamt[$stkacc] = $stk['amt'];
$inv['chrgvat'] = "";
$va = 0;
} else {
$totstkamt[$stkacc] = vats($stk['amt'], $inv['chrgvat'], $vd['vat_amount']);
$va = sprint($stk['amt'] - vats($stk['amt'], $inv['chrgvat'], $vd['vat_amount']));
if ($inv['chrgvat'] == "no") {
$va = sprint($stk['amt'] * $VATP / 100);
}
}
}
$f = vats($stk['amt'], $inv['chrgvat'], $vd['vat_amount']);
$f = $f * $inv['xrate'];
$va = $va * $inv['xrate'];
vatr($vd['id'], $td, "OUTPUT", $vd['code'], $refnum, "Non-Stock Sales, invoice No.{$real_invid}", $f + $va, $va);
$inv['chrgvat'] = $t;
$sql = "UPDATE nons_inv_items SET accid = '{$stkacc}' WHERE id = '{$stk['id']}'";
$sRslt = db_exec($sql);
$products .= "<tr valign=top><td>{$stk['description']}</td><td>{$stk['qty']}</td><td>{$inv['currency']} {$stk['unitcost']}</td><td>{$inv['currency']} {$stk['amt']}</td></tr>";
}
/* --- Start Some calculations --- */
# Subtotal
$SUBTOT = sprint($inv['subtot']);
$VAT = sprint($inv['vat']);
$TOTAL = sprint($inv['total']);
$LVAT = sprint($VAT * $inv['xrate']);
$LTOTAL = sprint($TOTAL * $inv['xrate']);
/* --- End Some calculations --- */
/* - Start Hooks - */
$vatacc = gethook("accnum", "salesacc", "name", "VAT", "non");
/* - End Hooks - */
# todays date
$date = date("d-m-Y");
$sdate = date("Y-m-d");
# Get department
db_conn("exten");
$sql = "SELECT * FROM departments WHERE deptid = '{$cus['deptid']}' AND div = '" . USER_DIV . "'";
$deptRslt = db_exec($sql);
if (pg_numrows($deptRslt) < 1) {
$dept['deptname'] = "<li class=err>Department not Found.";
} else {
$dept = pg_fetch_array($deptRslt);
}
# record transaction from data
foreach ($totstkamt as $stkacc => $wamt) {
# Debit Customer and Credit stock
writetrans($dept['debtacc'], $stkacc, $td, $refnum, $wamt * $inv['xrate'], "Non-Stock Sales on invoice No.{$real_invid} customer {$cus['surname']}.");
}
# Debit bank and credit the account involved
writetrans($dept['debtacc'], $vatacc, $td, $refnum, $LVAT, "Non-Stock Sales VAT received on invoice No.{$real_invid} customer {$cus['surname']}.");
$sdate = date("Y-m-d");
db_connect();
$sql = "UPDATE nons_invoices SET cusid = '{$cusnum}', done = 'y', invnum = '{$real_invid}' WHERE invid = '{$invid}' AND div = '" . USER_DIV . "'";
$upRslt = db_exec($sql) or errDie("Unable to update invoice information");
# Record the payment on the statement
$sql = "\n\t\tINSERT INTO stmnt \n\t\t\t(cusnum, invid, docref, amount, date, type, div, allocation_date) \n\t\tVALUES \n\t\t\t('{$cusnum}', '{$real_invid}', '{$inv['docref']}', '{$TOTAL}','{$inv['sdate']}', 'Non-Stock Invoice', '" . USER_DIV . "', '{$inv['odate']}')";
$stmntRslt = db_exec($sql) or errDie("Unable to insert statement record in Cubit.", SELF);
# Record the payment on the statement
$sql = "INSERT INTO open_stmnt(cusnum, invid, docref, amount, balance, date, type, div) VALUES('{$cusnum}', '{$real_invid}', '{$inv['docref']}', '{$TOTAL}', '{$TOTAL}','{$inv['sdate']}', 'Non-Stock Invoice', '" . USER_DIV . "')";
$stmntRslt = db_exec($sql) or errDie("Unable to insert statement record in Cubit.", SELF);
# Update the customer (make balance more)
$sql = "UPDATE customers SET balance = (balance + '{$LTOTAL}'::numeric(13,2)), fbalance = (fbalance + '{$TOTAL}'::numeric(13,2)) WHERE cusnum = '{$cusnum}' AND div = '" . USER_DIV . "'";
$rslt = db_exec($sql) or errDie("Unable to update invoice in Cubit.", SELF);
# Make ledge record
custledger($cusnum, $dept['incacc'], $td, $real_invid, "Non Stock Invoice No. {$real_invid}", $LTOTAL, "d");
frecordDT($TOTAL, $cusnum, $inv['xrate'], $inv['fcid'], $inv['sdate']);
db_connect();
$sql = "INSERT INTO salesrec(edate, invid, invnum, debtacc, vat, total, typ, div)\n\tVALUES('{$inv['sdate']}', '{$invid}', '{$real_invid}', '{$dept['debtacc']}', '{$LVAT}', '{$LTOTAL}', 'non', '" . USER_DIV . "')";
$recRslt = db_exec($sql);
db_conn('cubit');
$Sl = "INSERT INTO sj(cid,name,des,date,exl,vat,inc,div) VALUES\n\t('{$cusnum}','{$na}','Non-stock International Invoice {$real_invid}','{$inv['sdate']}','" . sprint($LTOTAL - $LVAT) . "','{$LVAT}','" . sprint($LTOTAL) . "','" . USER_DIV . "')";
$Ri = db_exec($Sl);
# Commit updates
pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
# Get selected stock in this invoice
$sql = "SELECT * FROM nons_inv_items WHERE invid = '{$invid}' AND div = '" . USER_DIV . "'";
# $stkdRslt = db_exec($sql);
/* -- Format the remarks boxlet -- */
$inv["remarks"] = "<table border=1><tr><td>Remarks:<br>{$inv['remarks']}</td></tr></table>";
$cc = "<script> CostCenter('dt', 'Sales', '{$td}', 'Non Stock Invoice No.{$real_invid}', '" . ($LTOTAL - $LVAT) . "', ''); </script>";
if ($inv['chrgvat'] == "yes") {
$inv['chrgvat'] = "Inclusive";
} elseif ($inv['chrgvat'] == "no") {
$inv['chrgvat'] = "Exclusive";
} else {
$inv['chrgvat'] = "No vat";
}
/* -- Final Layout -- */
$details = "\n\t\t\t\t<center>\n\t\t\t\t{$cc}\n\t\t\t\t<h2>Tax Invoice</h2>\n\t\t\t\t<table cellpadding='0' cellspacing='4' border=0 width='750'>\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td valign='top' width='30%'>\n\t\t\t\t\t\t\t<table " . TMPL_tblDflts . ">\n\t\t\t\t\t\t\t\t{$details}\n\t\t\t\t\t\t\t</table>\n\t\t\t\t\t\t</td>\n\t\t\t\t\t\t<td valign='top' width='30%'>\n\t\t\t\t\t\t\t" . COMP_NAME . "<br>\n\t\t\t\t\t\t\t" . COMP_ADDRESS . "<br>\n\t\t\t\t\t\t\t" . COMP_TEL . "<br>\n\t\t\t\t\t\t\t" . COMP_FAX . "<br>\n\t\t\t\t\t\t\tReg No. " . COMP_REGNO . "<br>\n\t\t\t\t\t\t\tVAT No. " . COMP_VATNO . "\n\t\t\t\t\t\t</td>\n\t\t\t\t\t\t<td width='20%'><img src='compinfo/getimg.php' width='230' height='47'></td>\n\t\t\t\t\t\t<td valign='bottom' align='right' width='20%'>\n\t\t\t\t\t\t\t<table cellpadding='2' cellspacing='0' border='1' bordercolor='#000000'>\n\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t<td><b>Invoice No.</b></td>\n\t\t\t\t\t\t\t\t\t<td valign='center'>{$real_invid}</td>\n\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t<td><b>Proforma Inv No.</b></td>\n\t\t\t\t\t\t\t\t\t<td valign='center'>{$inv['docref']}</td>\n\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t<td><b>Invoice Date</b></td>\n\t\t\t\t\t\t\t\t\t<td valign='center'>{$inv['sdate']}</td>\n\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t<td><b>VAT</b></td>\n\t\t\t\t\t\t\t\t\t<td valign='center'>{$inv['chrgvat']}</td>\n\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t</table>\n\t\t\t\t\t\t</td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t" . TBL_BR . "\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td colspan='4'>\n\t\t\t\t\t\t\t<table cellpadding='5' cellspacing='0' border='1' width='100%' bordercolor='#000000'>\n\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t<th width='65%'>DESCRIPTION</th>\n\t\t\t\t\t\t\t\t\t<th width='10%'>QTY</th>\n\t\t\t\t\t\t\t\t\t<th width='10%'>UNIT PRICE</th>\n\t\t\t\t\t\t\t\t\t<th width='10%'>AMOUNT</th>\n\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t{$products}\n\t\t\t\t\t\t\t</table>\n\t\t\t\t\t\t</td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td>{$inv['remarks']}</td>\n\t\t\t\t\t\t<td>" . BNK_BANKDET . "</td>\n\t\t\t\t\t\t<td align='right' colspan='2'>\n\t\t\t\t\t\t\t<table cellpadding='5' cellspacing='0' border=1 width=50% bordercolor='#000000'>\n\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t<td><b>SUBTOTAL</b></td>\n\t\t\t\t\t\t\t\t\t<td align='right'>{$inv['currency']} {$SUBTOT}</td>\n\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t<td><b>VAT @ " . TAX_VAT . "%</b></td>\n\t\t\t\t\t\t\t\t\t<td align='right'>{$inv['currency']} {$VAT}</td>\n\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t<th><b>GRAND TOTAL<b></th>\n\t\t\t\t\t\t\t\t\t<td align='right'>{$inv['currency']} {$TOTAL}</td>\n\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t</table>\n\t\t\t\t\t\t</td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t" . TBL_BR . "\n\t\t\t\t</table>\n\t\t\t\t</center>\n\t\t\t";
$OUTPUT = $details;
require "tmpl-print.php";
}
示例9: write_data
//.........这里部分代码省略.........
vatr($vcd['id'], $date, "INPUT", $vcd['code'], $refnum, "Opening balance VAT imported", sprint($credit - $debit), sprint($credit - $debit));
}
if ($ad['accid'] == $vatout) {
vatr($vcd['id'], $date, "OUTPUT", $vcd['code'], $refnum, "Opening balance VAT imported", sprint($credit - $debit), sprint($credit - $debit));
}
}
$tot_debit = sprint($tot_debit);
$tot_credit = sprint($tot_credit);
if ($cc_tot > 0) {
$tot = array_sum($cbalance);
if (sprint($cc_tot) != sprint($tot)) {
return enter_data2($_POST) . "<li class='err'>The total amount for balances for customers you entered is: " . CUR . " {$tot}, the\n\t\t\ttotal for the control account is: " . sprint($cc_tot) . ". These need to be the same.</li>";
}
db_conn('cubit');
$Sl = "SELECT cusnum,accno,surname FROM customers ORDER BY surname";
$Ri = db_exec($Sl);
if (pg_num_rows($Ri) < 1) {
return "<li class='err'>If you want to import your customer control account you need to add customers first</li>";
}
$tot = 0;
while ($cd = pg_fetch_array($Ri)) {
$cid = $cd['cusnum'];
$cbalance[$cid] = sprint($cbalance[$cid]);
if ($cbalance[$cid] > 0) {
db_conn('cubit');
# Update the customer (make balance more)
$sql = "UPDATE customers SET balance = (balance + '{$cbalance[$cid]}') WHERE cusnum = '{$cid}' AND div = '" . USER_DIV . "'";
$rslt = db_exec($sql) or errDie("Unable to update invoice in Cubit.", SELF);
$sql = "\n\t\t\t\t\tINSERT INTO stmnt (\n\t\t\t\t\t\tcusnum, invid, amount, date, type, \n\t\t\t\t\t\tst, div\n\t\t\t\t\t) VALUES (\n\t\t\t\t\t\t'{$cid}', '0', '{$cbalance[$cid]}', '{$date}', 'Opening Balance Imported', \n\t\t\t\t\t\t'n', '" . USER_DIV . "'\n\t\t\t\t\t)";
$stmntRslt = db_exec($sql) or errDie("Unable to Insert statement record in Cubit.", SELF);
$sql = "\n\t\t\t\t\tINSERT INTO open_stmnt (\n\t\t\t\t\t\tcusnum, invid, amount, balance, date, \n\t\t\t\t\t\ttype, st, div\n\t\t\t\t\t) VALUES (\n\t\t\t\t\t\t'{$cid}', '0', '{$cbalance[$cid]}', '{$cbalance[$cid]}', '{$date}', \n\t\t\t\t\t\t'Opening Balance Imported', 'n', '" . USER_DIV . "'\n\t\t\t\t\t)";
$stmntRslt = db_exec($sql) or errDie("Unable to Insert statement record in Cubit.", SELF);
crecordDT($cbalance[$cid], $cid, $date);
custledger($cid, $bala, $date, 0, "Opening Balance Imported", $cbalance[$cid], "d");
} elseif ($cbalance[$cid] < 0) {
db_conn('cubit');
# Update the customer (make balance more)
$sql = "UPDATE customers SET balance = (balance + '{$cbalance[$cid]}') WHERE cusnum = '{$cid}' AND div = '" . USER_DIV . "'";
$rslt = db_exec($sql) or errDie("Unable to update invoice in Cubit.", SELF);
$sql = "\n\t\t\t\t\tINSERT INTO stmnt (\n\t\t\t\t\t\tcusnum, invid, amount, date, type, \n\t\t\t\t\t\tst, div\n\t\t\t\t\t) VALUES (\n\t\t\t\t\t\t'{$cid}', '0', '{$cbalance[$cid]}', '{$date}', 'Opening Balance Imported', \n\t\t\t\t\t\t'n', '" . USER_DIV . "'\n\t\t\t\t\t)";
$stmntRslt = db_exec($sql) or errDie("Unable to Insert statement record in Cubit.", SELF);
$sql = "\n\t\t\t\t\tINSERT INTO open_stmnt (\n\t\t\t\t\t\tcusnum, invid, amount, balance, date, \n\t\t\t\t\t\ttype, st, div\n\t\t\t\t\t) VALUES (\n\t\t\t\t\t\t'{$cid}', '0', '{$cbalance[$cid]}', '{$cbalance[$cid]}', '{$date}', \n\t\t\t\t\t\t'Opening Balance Imported', 'n', '" . USER_DIV . "'\n\t\t\t\t\t)";
$stmntRslt = db_exec($sql) or errDie("Unable to Insert statement record in Cubit.", SELF);
crecordCT(-$cbalance[$cid], $cid, $date);
custledger($cid, $bala, $date, 0, "Opening Balance Imported", -$cbalance[$cid], "c");
}
$i++;
$tot += $cbalance[$cid];
}
}
if ($sc_tot > 0) {
db_conn('cubit');
$Sl = "SELECT supid,supno,supname FROM suppliers ORDER BY supname";
$Ri = db_exec($Sl);
if (pg_num_rows($Ri) < 1) {
return "<li class='err'>If you want to import your supplier control account you need to add suppliers first</li>";
}
$tot = 0;
while ($cd = pg_fetch_array($Ri)) {
$sid = $cd['supid'];
$sbalance[$sid] += 0;
if ($sbalance[$sid] > 0) {
db_conn('cubit');
$sql = "UPDATE suppliers SET balance = (balance + '{$sbalance[$sid]}') WHERE supid = '{$sid}' AND div = '" . USER_DIV . "'";
$rslt = db_exec($sql) or errDie("Unable to update supplier in Cubit.", SELF);
$sql = "\n\t\t\t\t\tINSERT INTO sup_stmnt (\n\t\t\t\t\t\tsupid, edate, ref, cacc, descript, \n\t\t\t\t\t\tamount, div\n\t\t\t\t\t) VALUES (\n\t\t\t\t\t\t'{$sid}', '{$date}', '0', '{$bala}', 'Opening balance imported', \n\t\t\t\t\t\t'{$sbalance[$sid]}', '" . USER_DIV . "'\n\t\t\t\t\t)";
示例10: recvpayment_write
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>");
}
示例11: cwrite
//.........这里部分代码省略.........
writetrans($dept['pca'], $stkacc, $td, $refnum, $wamt, "Non-Stock Sales on invoice No.{$real_invid} customer {$cust['surname']}.");
}
if (isset($bankid)) {
db_connect();
$bankid += 0;
$sql = "INSERT INTO cashbook(bankid, trantype, date, name, descript, cheqnum, amount, vat, chrgvat, banked, accinv, div) VALUES ('{$bankid}', 'deposit', '{$td}', '{$inv['cusname']}', 'Non-Stock Sales on invoice No.{$real_invid} customer {$inv['cusname']}', '0', '{$TOTAL}', '{$VAT}', '{$inv['chrgvat']}', 'no', '{$stkacc}', '" . USER_DIV . "')";
$Rslt = db_exec($sql) or errDie("Unable to add bank payment to database.", SELF);
$sql = "UPDATE nons_invoices SET jobid='{$bankid}' WHERE invid = '{$invid}' AND div = '" . USER_DIV . "'";
$upRslt = db_exec($sql) or errDie("Unable to update invoice information");
}
# Debit bank and credit the account involved
if ($VAT != 0) {
$tot_post += $VAT;
writetrans($dept['pca'], $vatacc, $td, $refnum, $VAT, "Non-Stock Sales VAT received on invoice No.{$real_invid} customer {$cust['surname']}.");
}
$sdate = date("Y-m-d");
$asset_dtacc = $dept["pca"];
}
$tot_post = sprint($tot_post);
db_connect();
if ($ctyp == 's') {
$sql = "UPDATE nons_invoices SET balance = total, cusid = '{$cusnum}', ctyp = '{$ctyp}', cusname = '{$cus['surname']}', cusaddr = '{$cus['addr1']}', cusvatno = '{$cus['vatnum']}', done = 'y', invnum = '{$real_invid}' WHERE invid = '{$invid}' AND div = '" . USER_DIV . "'";
$upRslt = db_exec($sql) or errDie("Unable to update invoice information");
# Record the payment on the statement
$sql = "INSERT INTO stmnt(cusnum, invid, docref, amount, date, type, div) VALUES('{$cusnum}', '{$real_invid}', '{$inv['docref']}', '{$TOTAL}','{$inv['odate']}', 'Non-Stock Invoice', '" . USER_DIV . "')";
$stmntRslt = db_exec($sql) or errDie("Unable to insert statement record in Cubit.", SELF);
# Record the payment on the statement
$sql = "INSERT INTO open_stmnt(cusnum, invid, docref, amount, balance, date, type, div) VALUES('{$cusnum}', '{$real_invid}', '{$inv['docref']}', '{$TOTAL}', '{$TOTAL}','{$inv['sdate']}', 'Non-Stock Invoice', '" . USER_DIV . "')";
$stmntRslt = db_exec($sql) or errDie("Unable to insert statement record in Cubit.", SELF);
# Update the customer (make balance more)
$sql = "UPDATE customers SET balance = (balance + '{$TOTAL}'::numeric(13,2)) WHERE cusnum = '{$cusnum}' AND div = '" . USER_DIV . "'";
$rslt = db_exec($sql) or errDie("Unable to update invoice in Cubit.", SELF);
# Make ledge record
custledger($cusnum, $stkacc, $td, $real_invid, "Non Stock Invoice No. {$real_invid}", $TOTAL, "d");
custDT($TOTAL, $cusnum, $td);
$tot_dif = sprint($tot_post - $TOTAL);
if ($tot_dif > 0) {
writetrans($varacc, $dept['debtacc'], $td, $refnum, $tot_dif, "Sales Variance on invoice {$real_invid}");
} elseif ($tot_dif < 0) {
$tot_dif = $tot_dif * -1;
writetrans($dept['debtacc'], $varacc, $td, $refnum, $tot_dif, "Sales Variance on invoice {$real_invid}");
}
} else {
$date = date("Y-m-d");
$sql = "UPDATE nons_invoices SET balance=total, cusname = '{$cust['surname']}', accid = '{$dept['pca']}', ctyp = '{$ctyp}', cusaddr = '{$cust['addr1']}', done = 'y', invnum = '{$real_invid}' WHERE invid = '{$invid}' AND div = '" . USER_DIV . "'";
$upRslt = db_exec($sql) or errDie("Unable to update invoice information");
$tot_dif = sprint($tot_post - $TOTAL);
if ($tot_dif > 0) {
writetrans($varacc, $dept['pca'], $td, $refnum, $tot_dif, "Sales Variance on invoice {$real_invid}");
} elseif ($tot_dif < 0) {
$tot_dif = $tot_dif * -1;
writetrans($dept['pca'], $varacc, $td, $refnum, $tot_dif, "Sales Variance on invoice {$real_invid}");
}
}
$sql = "SELECT * FROM cubit.nons_inv_items WHERE invid='{$invid}'";
$nii_rslt = db_exec($sql) or errDie("Unable to retrieve items.");
while ($nii_data = pg_fetch_array($nii_rslt)) {
if ($nii_data["asset_id"] > 0) {
$asset_vatamt = $asset_vat[$nii_data["id"]];
if ($inv['chrgvat'] == "yes") {
$asset_amt = sprint($nii_data["amt"] - $asset_vatamt);
} else {
if ($inv['chrgvat'] == "no") {
$asset_amt = $nii_data["amt"];
}
}
示例12: do_trans
function do_trans($_POST)
{
extract($_POST);
global $complete;
#use the perm file we saved in the previous function ...
$filename_path = $filename_path . "1";
#now parse it into $complete
parseXML($filename_path);
db_connect();
//print "<pre>";
//var_dump($complete);
//print "</pre>";
pglib_transaction("BEGIN") or errDie("Unable to start transaction.");
if (isset($complete["DEBTOR"]) and is_array($complete["DEBTOR"])) {
foreach ($complete["DEBTOR"] as $jobjs) {
$parms = $jobjs->cols;
$debtor = $complete["DEBTOR"][$parms["iid"]]->cols;
if (!isset($debtadd[$parms["accno"]]) or strlen($debtadd[$parms["accno"]]) < 1) {
continue;
}
#this debtor is checked for adding ... so add it
$ins_sql = "\n\t\t\t\tINSERT INTO customers (\n\t\t\t\t\taccno,surname,title,init,category,class,paddr1,addr1,contname,bustel,tel,cellno,fax,email,saleterm,traddisc,setdisc,pricelist,chrgint,overdue,chrgvat,credterm,odate,credlimit,blocked,deptid,vatnum,div,url,ddiv,intrate,balance,day30,day60,day90,day120,classname,catname,deptname,fbalance,fcid,location,currency,lead_source,comments,del_addr1,sales_rep,bankname,branname,brancode,bankaccno,bankaccname,team_id,registration,bankacctype\n\t\t\t\t) VALUES (\n\t\t\t\t\t'{$parms['accno']}','{$parms['surname']}','{$parms['title']}','{$parms['init']}','{$parms['category']}','{$parms['class']}','{$parms['paddr1']}','{$parms['addr1']}','{$parms['contname']}','{$parms['bustel']}','{$parms['tel']}','{$parms['cellno']}','{$parms['fax']}','{$parms['email']}','{$parms['saleterm']}','{$parms['traddisc']}','{$parms['setdisc']}','{$parms['pricelist']}','{$parms['chrgint']}','{$parms['overdue']}','{$parms['chrgvat']}','{$parms['credterm']}','{$parms['odate']}','{$parms['credlimit']}','{$parms['blocked']}','{$parms['deptid']}','{$parms['vatnum']}','{$parms['div']}','{$parms['url']}','{$parms['ddiv']}','{$parms['intrate']}','{$parms['balance']}','{$parms['day30']}','{$parms['day60']}','{$parms['day90']}','{$parms['day120']}','{$parms['classname']}','{$parms['catname']}','{$parms['deptname']}','{$parms['fbalance']}','{$parms['fcid']}','{$parms['location']}','{$parms['currency']}','{$parms['lead_source']}','{$parms['comments']}','{$parms['del_addr1']}','{$parms['sales_rep']}','{$parms['bankname']}','{$parms['branname']}','{$parms['brancode']}','{$parms['bankaccno']}','{$parms['bankaccname']}','{$parms['team_id']}','{$parms['registration']}','{$parms['bankacctype']}'\n\t\t\t\t)";
$run_ins = db_exec($ins_sql) or errDie("Unable to add debtor information.");
}
}
if (isset($complete["CREDITOR"]) and is_array($complete["CREDITOR"])) {
foreach ($complete["CREDITOR"] as $jobjs) {
$parms = $jobjs->cols;
$creditor = $complete["CREDITOR"][$parms["iid"]]->cols;
if (!isset($suppadd[$parms["supno"]]) or strlen($suppadd[$parms["supno"]]) < 1) {
continue;
}
#this creditor is checked for adding ... so add it
$ins_sql = "\n\t\t\t\tINSERT INTO suppliers (\n\t\t\t\t\tsupno,supname,supaddr,contname,tel,fax,email,bankname,branname,brancode,bankaccno,deptid,vatnum,div,url,ddiv,balance,listid,fbalance,fcid,location,currency,lead_source,comments,branch,groupid,reference,bee_status,team_id,registration,bankaccname,bankacctype\n\t\t\t\t) VALUES (\n\t\t\t\t\t'{$parms['supno']}','{$parms['supname']}','{$parms['supaddr']}','{$parms['contname']}','{$parms['tel']}','{$parms['fax']}','{$parms['email']}','{$parms['bankname']}','{$parms['branname']}','{$parms['brancode']}','{$parms['bankaccno']}','{$parms['deptid']}','{$parms['vatnum']}','{$parms['div']}','{$parms['url']}','{$parms['ddiv']}','{$parms['balance']}','{$parms['listid']}','{$parms['fbalance']}','{$parms['fcid']}','{$parms['location']}','{$parms['currency']}','{$parms['lead_source']}','{$parms['comments']}','{$parms['branch']}','{$parms['groupid']}','{$parms['reference']}','{$parms['bee_status']}','{$parms['team_id']}','{$parms['registration']}','{$parms['bankaccname']}','{$parms['bankacctype']}'\n\t\t\t\t)";
$run_ins = db_exec($ins_sql) or errDie("Unable to add supplier information.");
}
}
$sdate = date("Y-m-d");
if (isset($complete["JOURNAL"]) and is_array($complete["JOURNAL"])) {
foreach ($complete["JOURNAL"] as $jobjs) {
$parms = $jobjs->cols;
$doid = $jobjs->id;
#check if we should run this transaction
if (!isset($replay[$doid]) or strlen($replay[$doid]) < 1) {
continue;
}
if (!isset($parms["debitacc"])) {
$parms["debitacc"] = "0";
}
db_connect();
switch ($jobjs->type) {
case "DEBTOR":
$debtor = $complete["DEBTOR"][$parms["iid"]]->cols;
if (!isset($parms['creditacc'])) {
$parms['creditacc'] = "0";
}
if ($parms['debitacc'] == '0' and $parms['creditacc'] == '0') {
#its not 1 of the custom saves ... so do generic ...
# record the payment on the statement
$sql = "\n\t\t\t\t\t\t\tINSERT INTO stmnt (\n\t\t\t\t\t\t\t\tcusnum, invid, amount, date, type, st, div, allocation_date\n\t\t\t\t\t\t\t) VALUES (\n\t\t\t\t\t\t\t\t'{$parms['iid']}', '0', '{$parms['amount']}', '{$parms['date']}', '{$parms['details']}', 'n', '" . USER_DIV . "', '{$parms['date']}'\n\t\t\t\t\t\t\t)";
$stmntRslt = db_exec($sql) or errDie("Unable to Insert statement record in Cubit.", SELF);
$sql = "INSERT INTO open_stmnt(cusnum, invid, amount, balance, date, type, st, div) VALUES('{$parms['iid']}', '0', '{$parms['amount']}', '{$parms['amount']}', '{$parms['date']}', '{$parms['details']}', 'n', '" . USER_DIV . "')";
$stmntRslt = db_exec($sql) or errDie("Unable to Insert statement record in Cubit.", SELF);
# update the customer (make balance more)
$sql = "UPDATE customers SET balance = (balance + '{$parms['amount']}') WHERE cusnum = '{$parms['iid']}' AND div = '" . USER_DIV . "'";
$rslt = db_exec($sql) or errDie("Unable to update customer in Cubit.", SELF);
} else {
if ($parms['debitacc'] == '0') {
if ($parms['creditacc'] == '1') {
recordCT($parms['amount'], $parms['iid'], $parms['date']);
} else {
custledger($parms['iid'], $parms['creditacc'], $parms['date'], $parms['refno'], $parms['details'], $parms['amount'], 'c');
}
} elseif ($parms['creditacc'] == '0') {
if ($parms['debitacc'] == '1') {
recordDT($parms['amount'], $parms['iid'], $parms['date']);
} else {
custledger($parms['iid'], $parms['creditacc'], $parms['date'], $parms['refno'], $parms['details'], $parms['amount'], 'd');
}
}
}
break;
case "CREDITOR":
$creditor = $complete["CREDITOR"][$parms["iid"]]->cols;
if ($parms['debitacc'] == '0') {
if ($parms['creditacc'] == '1') {
recordCT(-$parms['amount'], $parms['iid'], $parms['date']);
} else {
suppledger($parms['iid'], $parms['creditacc'], $parms['date'], $parms['refno'], $parms['details'], $parms['amount'], 'c');
}
} elseif ($parms['creditacc'] == '0') {
if ($parms['debitacc'] == '1') {
recordDT($parms['amount'], $parms['iid'], $parms['date']);
} else {
suppledger($parms['iid'], $parms['debitacc'], $parms['date'], $parms['refno'], $parms['details'], $parms['amount'], 'd');
}
} elseif ($parms['debitacc'] == "9999" or $parms['creditacc'] == "9999") {
# record the payment on the statement
$sql = "INSERT INTO sup_stmnt(supid, edate, ref, cacc, descript, amount, div) VALUES('{$parms['iid']}', '{$parms['date']}', '0', '{$parms['refno']}', '{$parms['details']}', '{$parms['amount']}', '" . USER_DIV . "')";
$stmntRslt = db_exec($sql) or errDie("Unable to Insert statement record in Cubit.", SELF);
//.........这里部分代码省略.........
示例13: details
//.........这里部分代码省略.........
$run_addr = db_exec($get_addr);
if (pg_numrows($run_addr) < 1) {
$address = "";
} else {
$barr = pg_fetch_array($run_addr);
$address = " - {$barr['branch_name']}";
}
} else {
$address = "";
}
/* --- Updates ---- */
db_connect();
$Sql = "UPDATE invoices SET printed = 'y', done = 'y', invnum='{$invnum}' WHERE invid = '{$invid}' AND div = '" . USER_DIV . "'";
$upRslt = db_exec($Sql) or errDie("Unable to update invoice information");
//dont make consignment order from invoice if customer number is entered ...
// if (isset($inv['cordno']) AND strlen($inv['cordno']) > 0){
// $inv_type = "Consignment Order";
// }else {
$inv_type = "Invoice";
// }
# Record the payment on the statement
$sql = "\n\t\t\tINSERT INTO stmnt (\n\t\t\t\tcusnum, invid, docref, amount, date, \n\t\t\t\ttype, branch, div, allocation_date, \n\t\t\t\tallocation_balance\n\t\t\t) VALUES (\n\t\t\t\t'{$inv['cusnum']}', '{$invnum}', '{$inv['docref']}', '{$inv['total']}', '{$inv['odate']}', \n\t\t\t\t'{$inv_type}', '{$address}', '" . USER_DIV . "', '{$inv['odate']}', \n\t\t\t\t'" . abs($inv['total']) . "'\n\t\t\t)";
$stmntRslt = db_exec($sql) or errDie("Unable to insert statement record in Cubit.", SELF);
# Record the payment on the statement
$sql = "\n\t\t\tINSERT INTO open_stmnt (\n\t\t\t\tcusnum, invid, docref, amount, balance, \n\t\t\t\tdate, type, div\n\t\t\t) VALUES (\n\t\t\t\t'{$inv['cusnum']}', '{$invnum}', '{$inv['docref']}', '{$inv['total']}','{$inv['total']}', \n\t\t\t\t'{$inv['odate']}', '{$inv_type}', '" . USER_DIV . "'\n\t\t\t)";
$stmntRslt = db_exec($sql) or errDie("Unable to insert statement record in Cubit.", SELF);
# Save invoice discount
$sql = "\n\t\t\tINSERT INTO inv_discs (\n\t\t\t\tcusnum, invid, traddisc, itemdisc, inv_date, delchrg, \n\t\t\t\tdiv, total\n\t\t\t) VALUES (\n\t\t\t\t'{$inv['cusnum']}', '{$invnum}', '{$traddiscm}', '{$disc}', '{$inv['odate']}', '{$inv['delchrg']}', \n\t\t\t\t'" . USER_DIV . "', ({$SUBTOT}+{$inv['delchrg']})\n\t\t\t)";
$stmntRslt = db_exec($sql) or errDie("Unable to insert statement record in Cubit.", SELF);
# Update the customer (make balance more)
$sql = "UPDATE customers SET balance = (balance + '{$inv['total']}') WHERE cusnum = '{$inv['cusnum']}' AND div = '" . USER_DIV . "'";
$rslt = db_exec($sql) or errDie("Unable to update invoice in Cubit.", SELF);
# Make ledge record
custledger($inv['cusnum'], $dept['incacc'], $inv['odate'], $invnum, "Invoice No. {$invnum}", $inv['total'], "d");
db_connect();
# get selected stock in this invoice
$sql = "SELECT * FROM inv_items WHERE invid = '{$invid}' AND div = '" . USER_DIV . "'";
$stkdRslt = db_exec($sql);
$tcosamt = 0;
$sdate = date("Y-m-d");
$nsp = 0;
while ($stkd = pg_fetch_array($stkdRslt)) {
$stkd['account'] += 0;
if ($stkd['account'] == 0) {
db_connect();
# get selamt from selected stock
$sql = "SELECT * FROM stock WHERE stkid = '{$stkd['stkid']}' AND div = '" . USER_DIV . "'";
$stkRslt = db_exec($sql);
$stk = pg_fetch_array($stkRslt);
if ($stk['units'] - $stkd['qty'] < 0) {
if ($stk['units'] <= 0) {
$cosamt = 0;
$cosamt2 = 0;
} else {
$cosamt = round($stk['units'] * $stk['csprice'], 2);
$cosamt2 = round($stk['units'] * $stk['csprice'], 4);
}
} else {
$cosamt = round($stkd['qty'] * $stk['csprice'], 2);
$cosamt2 = round($stkd['qty'] * $stk['csprice'], 4);
}
# update stock(alloc - qty)
$sql = "\n\t\t\t\t\tUPDATE stock \n\t\t\t\t\tSET csamt = (csamt - '{$cosamt}'),units = (units - '{$stkd['qty']}'), alloc=(alloc - '{$stkd['qty']}') \n\t\t\t\t\tWHERE stkid = '{$stkd['stkid']}' AND div = '" . USER_DIV . "'";
$rslt = db_exec($sql) or errDie("Unable to update stock to Cubit.", SELF);
if ($inv["pslip_sordid"] > 0) {
$sql = "UPDATE stock SET alloc = (alloc - '{$stkd['qty']}') WHERE stkid='{$stkd['stkid']}'";
示例14: details
//.........这里部分代码省略.........
$inv['delchrg'] = sprint($inv['delchrg']);
$FSUBTOT = sprint($inv['subtot'] * $inv['xrate']);
$FVAT = sprint($inv['vat'] * $inv['xrate']);
$FTOTAL = sprint($inv['total'] * $inv['xrate']);
$fdelchrg = sprint($inv['delchrg'] * $inv['xrate']);
$ftraddiscm = sprint($inv['discount'] * $inv['xrate']);
com_invoice($inv['salespn'], $FTOTAL, $commision * $inv['xrate'], $invnum, $td);
/* --- End Some calculations --- */
/* - Start Hooks - */
$vatacc = gethook("accnum", "salesacc", "name", "VAT", "int");
/* - End Hooks - */
# Todays date
$date = date("d-m-Y");
$sdate = date("Y-m-d");
$refnum = getrefnum();
/*$refnum*/
/* --- Updates ---- */
db_connect();
$Sql = "UPDATE invoices SET printed ='y', done ='y', invnum='{$invnum}' WHERE invid = '{$invid}' AND div = '" . USER_DIV . "'";
$upRslt = db_exec($Sql) or errDie("Unable to update invoice information");
# Record the payment on the statement
$sql = "\n\t\tINSERT INTO stmnt (\n\t\t\tcusnum, invid, amount, date, type, div, allocation_date\n\t\t) VALUES (\n\t\t\t'{$inv['cusnum']}','{$invnum}', '{$TOTAL}', '{$inv['odate']}', 'Invoice', '" . USER_DIV . "', '{$inv['odate']}'\n\t\t)";
$stmntRslt = db_exec($sql) or errDie("Unable to insert statement record in Cubit.", SELF);
# Record the payment on the statement
$sql = "\n\t\tINSERT INTO open_stmnt (\n\t\t\tcusnum, invid, amount, balance, date, type, div\n\t\t) VALUES (\n\t\t\t'{$inv['cusnum']}', '{$invnum}', '{$TOTAL}', '{$TOTAL}', '{$inv['odate']}', 'Invoice', '" . USER_DIV . "'\n\t\t)";
$stmntRslt = db_exec($sql) or errDie("Unable to insert statement record in Cubit.", SELF);
# Save invoice discount
$sql = "\n\t\tINSERT INTO inv_discs (\n\t\t\tcusnum, invid, traddisc, itemdisc, inv_date, delchrg, div, \n\t\t\ttotal\n\t\t) VALUES (\n\t\t\t'{$inv['cusnum']}', '{$invnum}', '{$ftraddiscm}', '{$disc}', '{$inv['odate']}', '{$fdelchrg}', '" . USER_DIV . "', \n\t\t\t({$FSUBTOT}+{$fdelchrg})\n\t\t)";
$stmntRslt = db_exec($sql) or errDie("Unable to insert statement record in Cubit.", SELF);
# Update the customer (make balance more)
$sql = "UPDATE customers SET balance = (balance + '{$FTOTAL}'), fbalance = (fbalance + '{$TOTAL}') WHERE cusnum = '{$inv['cusnum']}' AND div = '" . USER_DIV . "'";
$rslt = db_exec($sql) or errDie("Unable to update invoice in Cubit.", SELF);
# Make ledge record
custledger($inv['cusnum'], $dept['incacc'], $td, $invnum, "Invoice No. {$invnum}", $FTOTAL, "d");
db_connect();
# get selected stock in this invoice
$sql = "SELECT * FROM inv_items WHERE invid = '{$invid}' AND div = '" . USER_DIV . "'";
$stkdRslt = db_exec($sql);
$tcosamt = 0;
while ($stkd = pg_fetch_array($stkdRslt)) {
db_connect();
# get selamt from selected stock
$sql = "SELECT * FROM stock WHERE stkid = '{$stkd['stkid']}' AND div = '" . USER_DIV . "'";
$stkRslt = db_exec($sql);
$stk = pg_fetch_array($stkRslt);
# cost amount
$cosamt = round($stkd['qty'] * $stk['csprice'], 2);
# update stock(alloc - qty)
$sql = "UPDATE stock SET csamt = (csamt - '{$cosamt}'),units = (units - '{$stkd['qty']}'),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);
###################VAT CALCS#######################
$Sl = "SELECT * FROM vatcodes WHERE id='{$stkd['vatcode']}'";
$Ri = db_exec($Sl);
if (pg_num_rows($Ri) < 1) {
return "Please select the vatcode for all your stock.";
}
$vd = pg_fetch_array($Ri);
if ($stk['exvat'] == 'yes' || $vd['zero'] == "Yes") {
$excluding = "y";
} else {
$excluding = "";
}
if (TAX_VAT != $vd['vat_amount'] and $vd['vat_amount'] != "0.00") {
$showvat = FALSE;
}
$vr = vatcalc($stkd['amt'], $inv['chrgvat'], $excluding, $inv['traddisc'], $vd['vat_amount']);
示例15: write
//.........这里部分代码省略.........
$inv['chrgvat'] = "";
} else {
$totstkamt[$stkacc] = vats($amts[$key], $inv['chrgvat']);
$va = sprint($amts[$key] - vats($amts[$key], $inv['chrgvat']));
if ($inv['chrgvat'] == "no") {
$va = sprint($amts[$key] * $VATP / 100);
}
}
}
$f = -vats($amts[$key], $inv['chrgvat']);
$f = $f * $inv['xrate'];
$va = $va * $inv['xrate'];
vatr($vd['id'], $td, "OUTPUT", $vd['code'], $refnum, "Non-Stock invoice No. {$inv['invnum']} Credit note No.{$real_noteid} Customer {$inv['cusname']}.", $f - $va, -$va);
$inv['chrgvat'] = $t;
$sql = "UPDATE nons_inv_items SET rqty = (rqty + '{$qtys[$key]}') WHERE id = '{$stkd['id']}'";
$sRslt = db_exec($sql);
$products .= "\n\t\t\t\t\t\t<tr valign='top'>\n\t\t\t\t\t\t\t<td>{$stkd['description']}</td>\n\t\t\t\t\t\t\t<td>{$qtys[$key]}</td>\n\t\t\t\t\t\t\t<td>{$inv['currency']} {$stkd['unitcost']}</td>\n\t\t\t\t\t\t\t<td>{$inv['currency']} {$amts[$key]}</td>\n\t\t\t\t\t\t</tr>";
}
/* --- Start Some calculations --- */
# Subtotal
$SUBTOT = sprint($subtot);
$VAT = sprint($vat);
$TOTAL = sprint($total);
$LVAT = sprint($VAT * $inv['xrate']);
$LTOTAL = sprint($TOTAL * $inv['xrate']);
/* --- End Some calculations --- */
/* - Start Hooks - */
$vatacc = gethook("accnum", "salesacc", "name", "VAT", "VAT");
/* - End Hooks - */
# todays date
db_connect();
$sql = "SELECT * FROM customers WHERE cusnum = '{$inv['cusid']}' AND div = '" . USER_DIV . "'";
$custRslt = db_exec($sql) or errDie("Unable to view customer");
if (pg_numrows($custRslt) < 1) {
return "<li class='err'>Error : Customer not Found.</li>";
}
$cus = pg_fetch_array($custRslt);
$na = $cus['surname'];
# Get department
db_conn("exten");
$sql = "SELECT * FROM departments WHERE deptid = '{$cus['deptid']}' AND div = '" . USER_DIV . "'";
$deptRslt = db_exec($sql);
if (pg_numrows($deptRslt) < 1) {
return "<li class='err'>Department not Found.</li>";
} else {
$dept = pg_fetch_array($deptRslt);
}
$wtot = array_sum($totstkamt) + $va;
$lwtot = sprint($wtot * $inv['xrate']);
$lva = sprint($va * $inv["xrate"]);
$tpp = 0;
# record transaction from data
foreach ($totstkamt as $stkacc => $wamt) {
writetrans($stkacc, $dept['debtacc'], $sndate, $refnum, $lwtot, "Non-Stock invoice No. {$inv['invnum']} Credit note No.{$real_noteid} Customer {$inv['cusname']}.");
}
if ($lva != 0) {
writetrans($vatacc, $dept['debtacc'], $sndate, $refnum, $lva, "Non-Stock invoice No. {$inv['invnum']} Credit note No.{$real_noteid} Vat. Customer {$inv['cusname']}.");
}
db_connect();
# Record the payment on the statement
$sql = "\n\t\tINSERT INTO stmnt \n\t\t\t(cusnum, invid, amount, date, type, div, allocation_date) \n\t\tVALUES \n\t\t\t('{$inv['cusid']}', '{$real_noteid}', '-{$wtot}','{$sndate}', 'Non Stock Credit Note, for invoice {$inv['invnum']}', '" . USER_DIV . "', '{$sndate}')";
$stmntRslt = db_exec($sql) or errDie("Unable to insert statement record in Cubit.", SELF);
# Update the customer (make balance less)
$sql = "UPDATE customers \n\t\t\tSET balance = (balance - '{$lwtot}'::numeric(13,2)), \n\t\t\t\tfbalance = (fbalance - '{$wtot}'::numeric(13,2)) WHERE cusnum = '{$inv['cusid']}' AND div = '" . USER_DIV . "'";
$rslt = db_exec($sql) or errDie("Unable to update invoice in Cubit.", SELF);
# Make ledge record
custledger($inv['cusid'], $dept['incacc'], $sndate, $real_noteid, "Non Stock Credit note {$real_noteid}", $lwtot, "c");
frecordCT($wtot, $inv['cusid'], $inv['xrate'], $inv['fcid'], $sndate);
// custCT($TOTAL, $inv['cusid']);
db_connect();
$sql = "UPDATE nons_invoices \n\t\t\tSET balance = (balance - '{$lwtot}'::numeric(13,2)), \n\t\t\t\tfbalance = (fbalance - '{$wtot}'::numeric(13,2)) WHERE invid = '{$invid}' AND div = '" . USER_DIV . "'";
$upRslt = db_exec($sql) or errDie("Unable to update invoice information");
# write note
$sql = "INSERT INTO nons_inv_notes(invid, invnum, cusname, cusaddr, cusvatno, chrgvat, location, currency, date, subtot, vat, total, username, prd, notenum, ctyp, div)";
$sql .= " VALUES('{$inv['invid']}', '{$inv['invnum']}', '{$inv['cusname']}', '{$inv['cusaddr']}', '{$inv['cusvatno']}', '{$inv['chrgvat']}', 'int', '{$inv['currency']}', '{$sndate}', '" . sprint($wtot - $va) . "', {$va}, {$wtot}, '" . USER_NAME . "', '" . PRD_DB . "', '{$real_noteid}', '{$inv['ctyp']}', '" . USER_DIV . "')";
$rslt = db_exec($sql) or errDie("Unable to create template Non-Stock Invoice.", SELF);
$noteid = pglib_lastid("nons_inv_notes", "noteid");
# write note items
foreach ($ids as $key => $id) {
$sql = "SELECT * FROM nons_inv_items WHERE invid = '{$invid}' AND id = '{$id}' AND div = '" . USER_DIV . "'";
$stkdRslt = db_exec($sql);
$nstk = pg_fetch_array($stkdRslt);
$sql = "INSERT INTO nons_note_items(noteid, qty, description, amt, unitcost) \n\t\t\t\tVALUES('{$noteid}', '{$qtys[$key]}', '{$nstk['description']}', '{$amts[$key]}', \n\t\t\t\t\t'{$nstk['unitcost']}')";
$stkdRslt = db_exec($sql);
}
$sql = "INSERT INTO salesrec(edate, invid, invnum, debtacc, vat, total, typ, div)\n\tVALUES('{$sndate}', '{$noteid}', '{$real_noteid}', '0', '{$lva}', '{$lwtot}', 'nnon', '" . USER_DIV . "')";
$recRslt = db_exec($sql);
db_conn('cubit');
$Sl = "INSERT INTO sj(cid,name,des,date,exl,vat,inc,div) VALUES\n\t('{$inv['cusid']}','{$na}','Credit note: {$real_noteid}, Non-stock International Invoice {$inv['invnum']} ','{$sndate}','" . -sprint($lwtot - $lva) . "','-{$lva}','" . -sprint($lwtot) . "','" . USER_DIV . "')";
$Ri = db_exec($Sl);
# Commit updates
pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
/* -- Format the remarks boxlet -- */
$inv["remarks"] = "<table border=1><tr><td>Remarks:<br>{$inv['remarks']}</td></tr></table>";
$cc = "<script> CostCenter('ct', 'Credit Note', '{$sndate}', 'Non Stock Credit Note No.{$real_noteid}', '" . ($LTOTAL - $LVAT) . "', ''); </script>";
/* -- Final Layout -- */
$details = "\n\t\t\t\t\t{$cc}\n\t\t\t\t\t<center>\n\t\t\t\t\t<h2>Credit Note</h2>\n\t\t\t\t\t<table cellpadding='0' cellspacing='4' border='0' width='750'>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td valign='top' width='30%'>\n\t\t\t\t\t\t\t\t<table " . TMPL_tblDflts . ">\n\t\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t\t<td>{$inv['cusname']}</td>\n\t\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t\t<td>" . nl2br($inv['cusaddr']) . "</td>\n\t\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t\t<td>(Vat No. {$inv['cusvatno']})</td>\n\t\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t</table>\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t<td valign='top' width='30%'>\n\t\t\t\t\t\t\t\t" . COMP_NAME . "<br>\n\t\t\t\t\t\t\t\t" . COMP_ADDRESS . "<br>\n\t\t\t\t\t\t\t\t" . COMP_TEL . "<br>\n\t\t\t\t\t\t\t\t" . COMP_FAX . "<br>\n\t\t\t\t\t\t\t\tReg No. " . COMP_REGNO . "<br>\n\t\t\t\t\t\t\t\tVat No. " . COMP_VATNO . "\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t<td width='20%'><img src='compinfo/getimg.php' width=230 height=47></td>\n\t\t\t\t\t\t\t<td valign='bottom' align='right' width='20%'>\n\t\t\t\t\t\t\t\t<table cellpadding='2' cellspacing='0' border=1 bordercolor='#000000'>\n\t\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t\t<td><b>Credit Note No.</b></td>\n\t\t\t\t\t\t\t\t\t\t<td valign='center'>{$real_noteid}</td>\n\t\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t\t<td><b>Invoice No.</b></td>\n\t\t\t\t\t\t\t\t\t\t<td valign='center'>{$inv['invnum']}</td>\n\t\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t\t<td><b>Date</b></td>\n\t\t\t\t\t\t\t\t\t\t<td valign='center'>{$sndate}</td>\n\t\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t</table>\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr><td><br></td></tr>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td colspan='4'>\n\t\t\t\t\t\t\t\t<table cellpadding='5' cellspacing='0' border=1 width=100% bordercolor='#000000'>\n\t\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t\t<th width='65%'>DESCRIPTION</th>\n\t\t\t\t\t\t\t\t\t\t<th width='10%'>QTY</th>\n\t\t\t\t\t\t\t\t\t\t<th width='10%'>UNIT PRICE</th>\n\t\t\t\t\t\t\t\t\t\t<th width='10%'>AMOUNT</th>\n\t\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t{$products}\n\t\t\t\t\t\t\t\t</table>\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td>{$inv['remarks']}</td>\n\t\t\t\t\t\t\t<td align='right' colspan='3'>\n\t\t\t\t\t\t\t\t<table cellpadding='5' cellspacing='0' border=1 width=50% bordercolor='#000000'>\n\t\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t\t<td><b>SUBTOTAL</b></td>\n\t\t\t\t\t\t\t\t\t\t<td align='right'>{$inv['currency']} {$SUBTOT}</td>\n\t\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t\t<td><b>VAT @ " . TAX_VAT . "%</b></td>\n\t\t\t\t\t\t\t\t\t\t<td align='right'>{$inv['currency']} {$VAT}</td>\n\t\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t\t<th><b>GRAND TOTAL<b></th>\n\t\t\t\t\t\t\t\t\t\t<td align='right'>{$inv['currency']} {$TOTAL}</td>\n\t\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t</table>\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr><td><br></td></tr>\n\t\t\t\t\t</table>\n\t\t\t\t\t</center>";
$OUTPUT = $details;
require "tmpl-print.php";
}