本文整理汇总了PHP中gethook函数的典型用法代码示例。如果您正苦于以下问题:PHP gethook函数的具体用法?PHP gethook怎么用?PHP gethook使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了gethook函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: update
function update($_POST)
{
# Get Vars ( banked[] )
extract($_POST);
# check if anything is selected
if (!isset($banked)) {
$err = "<li class='err'> Please Select at least one entry to update.";
return cashbook($_POST, $err);
}
/* - Start Hooks - */
$vatacc = gethook("accnum", "salesacc", "name", "VAT");
/* - End Hooks - */
$refnum = getrefnum();
/*refnum*/
db_conn('core');
$rid = pglib_lastid("save_bank_recon", "id");
$rid++;
# Record all trans
foreach ($banked as $key => $cashid) {
# Connect to database
db_Connect();
$sql = "SELECT * FROM cashbook WHERE cashid='{$cashid}' AND div = '" . USER_DIV . "'";
$cashRslt = db_exec($sql) or errDie("ERROR: Unable to retrieve details from database.", SELF);
$cash = pg_fetch_array($cashRslt);
# Set record as banked
db_connect();
$sql = "UPDATE cashbook SET banked = 'yes',rid='{$rid}' WHERE cashid='{$cashid}' AND div = '" . USER_DIV . "'";
$Rslt = db_exec($sql) or errDie("Unable to set bank deposit as banked in Cubit.", SELF);
}
// Connect to database
db_connect();
$sql = "SELECT * FROM cashbook WHERE bankid = '{$bankid}' AND banked = 'no' AND div = '" . USER_DIV . "' ORDER BY date DESC";
$cashRslt = db_exec($sql) or errDie("ERROR: Unable to retrieve bank transactions from database.", SELF);
$sql = "SELECT * FROM bankacct WHERE bankid= '{$bankid}' AND div = '" . USER_DIV . "'";
$bankRslt = db_exec($sql);
$bank = pg_fetch_array($bankRslt);
$cur = CUR;
$amtd = "amount";
if ($bank['btype'] == 'int') {
$currs = getSymbol($bank['fcid']);
$cur = $currs['symbol'];
$amtd = "famount";
}
$tot = 0;
$totr = 0;
$totp = 0;
$recpts = "";
$paymnts = "";
while ($cash = pg_fetch_array($cashRslt)) {
if ($cash['trantype'] == "deposit") {
$recpts .= "\n\t\t\t\t<tr>\n\t\t\t\t\t<td>{$cash['date']}</td>\n\t\t\t\t\t<td>{$cash['descript']}</td>\n\t\t\t\t\t<td align='right'>{$cur} {$cash[$amtd]}</td>\n\t\t\t\t</tr>";
$totr += $cash[$amtd];
} else {
$paymnts .= "\n\t\t\t\t<tr>\n\t\t\t\t\t<td>{$cash['date']}</td>\n\t\t\t\t\t<td>{$cash['descript']}</td>\n\t\t\t\t\t<td align='right'>{$cur} {$cash[$amtd]}</td>\n\t\t\t\t</tr>";
$totp += $cash[$amtd];
}
$tot += $cash[$amtd];
}
$reconbal = sprint($cbal + ($totr - $totp));
# 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.";
}
$banklnk = pg_fetch_array($rslt);
# Get bank balance
$sql = "SELECT (debit - credit) as bal FROM trial_bal WHERE period='12' AND accid = '{$banklnk['accnum']}' AND div = '" . USER_DIV . "'";
$brslt = db_exec($sql) or errDie("Unable to retrieve bank account link from Cubit", SELF);
$bal = pg_fetch_array($brslt);
if ($bank['btype'] == 'int') {
$bal['bal'] = $bank['fbalance'];
}
$diff = sprint($reconbal - $bal['bal']);
$derr = "";
if ($diff != 0) {
$derr = "\n\t\t\t<tr>\n\t\t\t\t<td colspan='2'><b class='err'>Bank statement and computer balance not balancing by</b></td>\n\t\t\t\t<td align='right'>{$cur} {$diff}</td>\n\t\t\t</tr>";
}
$totp = sprint($totp);
// Layout
$update = "\n\t\t<center>\n\t\t<h3>Bank Reconciliation Output</h3>\n\t\t<form action='" . SELF . "' method='POST' name='form1'>\n\t\t\t<input type='hidden' name='key' value='save'>\n\t\t\t<input type='hidden' name='bankid' value='{$bankid}'>\n\t\t<table cellpadding='2' cellspacing='0' border=0 bordercolor='#000000' width='80%'>\n\t\t\t<tr>\n\t\t\t\t<td colspan='10'>\n\t\t\t\t\t<table cellpadding='2' cellspacing='0' border=0 bordercolor='#000000' width=100%>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td><b>Bank Account : </b>{$bank['accname']}</td>\n\t\t\t\t\t\t\t<td></td>\n\t\t\t\t\t\t\t<td align='right'><b>Prepared By : </b>" . USER_NAME . "</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><b>Closing Balance As per Bank Statement : </b>{$cur} {$cbal}</td>\n\t\t\t\t\t\t\t<td></td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t</table>\n\t\t\t\t</td>\n\t\t\t</tr>\n\t\t\t<tr><td><br><br></td></tr>\n\t\t\t<tr>\n\t\t\t\t<td><b>Plus Outstanding Receipts :</b></td>\n\t\t\t</tr>\n\t\t\t<!--<tr><th>Date</th><th>Reference</th><th>Amount</th></tr>-->\n\t\t\t{$recpts}\n\t\t\t<tr>\n\t\t\t\t<td colspan='2'><br></td>\n\t\t\t\t<td align='right'>____________</td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td colspan='2' align='right'><b>Sub Total</b></td>\n\t\t\t\t<td align='right'>{$cur} {$totr}</td>\n\t\t\t</tr>\n\t\t\t<tr><td><br><br></td></tr>\n\t\t\t<tr>\n\t\t\t\t<td><b>Less Outstanding Payments :</b></td>\n\t\t\t</tr>\n\t\t\t<!--<tr><th>Date</th><th>Reference</th><th>Amount</th></tr>-->\n\t\t\t{$paymnts}\n\t\t\t<tr>\n\t\t\t\t<td colspan='2'><br></td>\n\t\t\t\t<td align='right'>____________</td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td colspan='2' align='right'><b>Sub Total</b></td>\n\t\t\t\t<td align='right'>{$cur} {$totp}</td>\n\t\t\t</tr>\n\t\t\t<tr><td><br><td></tr>\n\t\t\t{$derr}\n\t\t\t<tr><td><br><td></tr>\n\t\t\t<tr>\n\t\t\t\t<td colspan='2'><br></td>\n\t\t\t\t<td align='right'>____________</td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td colspan='2'><b>Reconciled Bank Balance</b></td>\n\t\t\t\t<td align='right'>{$cur} {$reconbal}</td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td colspan='2'><b>Computer Bank Balance</b></td>\n\t\t\t\t<td align='right'>{$cur} {$bal['bal']}</td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td colspan='2'><br></td>\n\t\t\t\t<td align='right'>____________</td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td colspan='2'><b>Diff</b></td>\n\t\t\t\t<td align='right'>{$cur} {$diff}</td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td colspan='2'><br></td>\n\t\t\t\t<td align='right'>____________</td>\n\t\t\t</tr>";
$upcode = base64_encode($update);
$button = "</table></form>";
core_connect();
$gendate = date("Y-m-d");
$sql = "\n\t\tINSERT INTO save_bank_recon (\n\t\t\tbankid, gendate, recon, div\n\t\t) VALUES (\n\t\t\t'{$bankid}', '{$gendate}', '{$upcode}', '" . USER_DIV . "'\n\t\t)";
$saveRslt = db_exec($sql) or errDie("Unable to save bank recon to database", SELF);
$update .= $button;
$OUTPUT = $update;
require "../tmpl-print.php";
}
示例2: add
function add()
{
core_connect();
# Get Petty cash account
$cashacc = gethook("accnum", "bankacc", "name", "Petty Cash");
# Get account name for thy lame User's Sake
$accRslt = get("core", "*", "accounts", "accid", $cashacc);
if (pg_numrows($accRslt) < 1) {
return "<li class='err'> Petty Cash Account not found.</li>";
}
$acc = pg_fetch_array($accRslt);
# Check available funds
$cashacc = gethook("accnum", "bankacc", "name", "Petty Cash");
core_connect();
$sql = "SELECT (debit - credit) as bal FROM trial_bal WHERE month='" . PRD_DB . "' AND accid = '{$cashacc}' AND div = '" . USER_DIV . "'";
$accbRslt = db_exec($sql);
if (pg_numrows($accbRslt) < 1) {
return "<li class='err'> Petty Cash Account not found.</li>";
}
$accb = pg_fetch_array($accbRslt);
$accb['bal'] = sprint($accb['bal']);
# mourn if the is no money
if ($accb['bal'] < 1) {
return "\n\t\t\t<li class='err'> There are no Petty Cash funds available.</li>\n\t\t\t<p>\n\t\t\t<table " . TMPL_tblDflts . ">\n\t\t\t\t<tr>\n\t\t\t\t\t<th>Quick Links</th>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td><a href='petty-trans.php'>Transfer funds to petty cash account</a></td>\n\t\t\t\t</tr>\n\t\t\t\t<script>document.write(getQuicklinkSpecial());</script>\n\t\t\t</table>";
}
// Layout
$add = "\n\t\t<h3>Funds transfer to Bank</h3>\n\t\t<table " . TMPL_tblDflts . " width='300'>\n\t\t<form action='" . SELF . "' method='POST' name='form'>\n\t\t\t<input type='hidden' name='key' value='confirm'>\n\t\t\t<tr>\n\t\t\t\t<th>Field</th>\n\t\t\t\t<th>Value</th>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>Bank Account</td>\n\t\t\t\t<td valign='center'>\n\t\t\t\t\t<select name='bankid'>";
db_connect();
$sql = "SELECT * FROM bankacct WHERE btype != 'int' AND div = '" . USER_DIV . "'";
$banks = db_exec($sql);
if (pg_numrows($banks) < 1) {
return "<li class='err'> There are no accounts held at the selected Bank.</li>\n\t\t<p><input type='button' onClick='JavaScript:history.back();' value='« Correct Selection'>";
}
while ($bacc = pg_fetch_array($banks)) {
$add .= "<option value='{$bacc['bankid']}'>({$bacc['acctype']}) {$bacc['accname']} - {$bacc['bankname']}</option>";
}
if (!isset($date_day)) {
$trans_date_setting = getCSetting("USE_TRANSACTION_DATE");
if (isset($trans_date_setting) and $trans_date_setting == "yes") {
$trans_date_value = getCSetting("TRANSACTION_DATE");
$date_arr = explode("-", $trans_date_value);
$date_year = $date_arr[0];
$date_month = $date_arr[1];
$date_day = $date_arr[2];
} else {
$date_year = date("Y");
$date_month = date("m");
$date_day = date("d");
}
}
$add .= "\n\t\t\t\t\t</select>\n\t\t\t\t</td>\n\t\t\t</tr>\n\t <tr class='" . bg_class() . "'>\n\t \t<td>Date</td>\n\t \t<td>" . mkDateSelect("date", $date_year, $date_month, $date_day) . "</td>\n\t </tr>\n\t <tr class='" . bg_class() . "'>\n\t \t<td>Received from</td>\n\t \t<td valign='center'><input size='20' name='name' value='Petty Cash'></td>\n\t </tr>\n\t <tr class='" . bg_class() . "'>\n\t \t<td>Description</td>\n\t \t<td valign='center'><textarea cols='18' rows='2' name='descript'></textarea></td>\n\t </tr>\n\t <tr class='" . bg_class() . "'>\n\t \t<td>Cheque Number</td>\n\t \t<td valign='center'><input size='10' name='cheqnum'></td>\n\t </tr>\n\t <tr class='" . bg_class() . "'>\n\t \t<td>Amount</td>\n\t \t<td valign='center'>" . CUR . " <input type='text' size='10' name='amount'> Max : " . CUR . " {$accb['bal']}<input type='hidden' name='max' value='{$accb['bal']}'></td>\n\t </tr>\n\t <tr class='" . bg_class() . "'>\n\t \t<td>Petty Cash Account</td>\n\t \t<td><input type='hidden' name='accinv' value='{$acc['accid']}'>{$acc['topacc']}/{$acc['accnum']} - {$acc['accname']}</td>\n\t </tr>\n\t\t\t<tr><td><br></td></tr>\n\t\t\t<tr>\n\t\t\t\t<td><input type='button' value='< Cancel' onClick='javascript:history.back();'></td>\n\t\t\t\t<td valign='center'><input type='submit' value='Confirm >'></td>\n\t\t\t</tr>\n\t\t</table>";
# main table (layout with menu)
$OUTPUT = "\n\t\t\t<center>\n\t <table width='100%'>\n\t\t\t\t<tr>\n\t\t\t\t\t<td width='65%' align='left'>{$add}</td>\n\t\t\t\t\t<td valign='top' align='center'>\n\t\t\t\t\t\t<table " . TMPL_tblDflts . " width='65%'>\n\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t<th>Quick Links</th>\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t<script>document.write(getQuicklinkSpecial());</script>\n\t\t\t\t\t\t</table>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\t </table>";
return $OUTPUT;
}
示例3: add
function add()
{
# Suppliers Drop down selections
db_connect();
$sql = "SELECT cusnum,cusname,surname FROM customers WHERE location != 'int' AND div = '" . USER_DIV . "' ORDER BY surname,cusname";
$cusRslt = db_exec($sql);
$numrows = pg_numrows($cusRslt);
if (empty($numrows)) {
return "<li> There are no Debtors in Cubit.</li>";
}
$cust = "<select name='cusid'>";
while ($cus = pg_fetch_array($cusRslt)) {
$cust .= "<option value='{$cus['cusnum']}'>{$cus['cusname']} {$cus['surname']}</option>";
}
$cust .= "</select>";
core_connect();
# Get Petty cash account
$cashacc = gethook("accnum", "bankacc", "name", "Petty Cash");
# Get account name for thy lame User's Sake
$accRslt = get("core", "*", "accounts", "accid", $cashacc);
if (pg_numrows($accRslt) < 1) {
return "<li class='err'> Petty Cash Account not found.</li>";
}
$acc = pg_fetch_array($accRslt);
# Check available funds
$cashacc = gethook("accnum", "bankacc", "name", "Petty Cash");
core_connect();
$sql = "SELECT (debit - credit) as bal FROM trial_bal WHERE month='" . PRD_DB . "' AND accid = '{$cashacc}' AND div = '" . USER_DIV . "'";
$accbRslt = db_exec($sql);
if (pg_numrows($accbRslt) < 1) {
return "<li class='err'> Petty Cash Account not found.</li>";
}
$accb = pg_fetch_array($accbRslt);
$accb['bal'] = sprint($accb['bal']);
if (!isset($date_day)) {
$trans_date_setting = getCSetting("USE_TRANSACTION_DATE");
if (isset($trans_date_setting) and $trans_date_setting == "yes") {
$trans_date_value = getCSetting("TRANSACTION_DATE");
$date_arr = explode("-", $trans_date_value);
$date_year = $date_arr[0];
$date_month = $date_arr[1];
$date_day = $date_arr[2];
} else {
$date_year = date("Y");
$date_month = date("m");
$date_day = date("d");
}
}
// layout
$add = "\n\t\t<h3>New Petty Cash Payment</h3>\n\t\t<table " . TMPL_tblDflts . " width='100%'>\n\t\t<form action='" . SELF . "' method='POST' name='form'>\n\t\t\t<input type='hidden' name='key' value='confirm'>\n\t\t\t<input type='hidden' name='cashacc' value='{$cashacc}'>\n\t\t\t<tr>\n\t\t\t\t<th>Field</th>\n\t\t\t\t<th>Value</th>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>Petty Cash Account</td>\n\t\t\t\t<td valign='center'>{$acc['topacc']}/{$acc['accnum']} {$acc['accname']}</td>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>Available Funds</td>\n\t\t\t\t<td>" . CUR . " {$accb['bal']}<input type='hidden' name='max' value='{$accb['bal']}'></td>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>" . REQ . "Date</td>\n\t\t\t\t<td>" . mkDateSelect("date", $date_year, $date_month, $date_day) . "</td>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>" . REQ . "Customer paid to</td>\n\t\t\t\t<td valign='center'>{$cust}</td>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>Description</td>\n\t\t\t\t<td valign='center'><textarea col='20' rows='5' name='descript'></textarea></td>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>" . REQ . "Amount</td>\n\t\t\t\t<td valign='center'>" . CUR . " <input type='text' size='10' name='amount'></td>\n\t\t\t</tr>\n\t\t\t<tr><td><br></td></tr>\n\t\t\t<tr>\n\t\t\t\t<td><input type='button' value='« Cancel' onClick='javascript:history.back();'></td>\n\t\t\t\t<td valign='center'><input type='submit' value='Add »'></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='100%'>\n\t\t\t<tr>\n\t\t\t\t<td width='65%' align='left'>{$add}</td>\n\t\t\t\t<td valign='top' align='center'>\n\t\t\t\t\t<table " . TMPL_tblDflts . " width='65%'>\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<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;
}
示例4: getactual
function getactual()
{
# get petty cash account
$pcacc = gethook("accnum", "bankacc", "name", "Petty Cash");
core_connect();
$pcbalRs = db_exec("SELECT sum(credit) as credit, sum(debit) as debit FROM trial_bal WHERE period='" . PRD_DB . "' AND accid = '{$pcacc}'");
$pcbal = pg_fetch_array($pcbalRs);
$bankct = $pcbal['credit'];
$bankdt = $pcbal['debit'];
# get bank balances
db_connect();
$sql = "SELECT bankid FROM bankacct WHERE div = '" . USER_DIV . "'";
$bankRslt = db_exec($sql) or errDie("ERROR: Unable to retrieve bank account details from database.", SELF);
while ($bnk = pg_fetch_array($bankRslt)) {
$bacc = gethook("accnum", "bankacc", "accid", $bnk['bankid']);
core_connect();
$bbalRs = db_exec("SELECT sum(credit) as credit, sum(debit) as debit FROM trial_bal WHERE accid = '{$bacc}'");
$bbal = pg_fetch_array($bbalRs);
$bankct += $bbal['credit'];
$bankdt += $bbal['debit'];
}
# get cash on hand
db_conn("exten");
$sql = "SELECT pca FROM departments WHERE div = '" . USER_DIV . "'";
$deptRslt = db_exec($sql) or errDie("ERROR: Unable to retrieve departments from database.", SELF);
while ($dept = pg_fetch_array($deptRslt)) {
core_connect();
$deptbalRs = db_exec("SELECT sum(credit) as credit, sum(debit) as debit FROM trial_bal WHERE accid = '{$dept['pca']}'");
$deptbal = pg_fetch_array($deptbalRs);
$bankct += $deptbal['credit'];
$bankdt += $deptbal['debit'];
}
$ret['debit'] = sprint($bankdt);
$ret['credit'] = sprint($bankct);
return $ret;
}
示例5: write
function write($_POST)
{
extract($_POST);
if (isset($back)) {
unset($_POST["back"]);
return enter($_POST);
}
# CHECK IF THIS DATE IS IN THE BLOCKED RANGE
$blocked_date_from = getCSetting("BLOCKED_FROM");
$blocked_date_to = getCSetting("BLOCKED_TO");
# validate input
require_lib("validate");
$v = new validate();
$v->isOk($bankid, "num", 1, 20, "Invalid Bank ID.");
foreach ($amount as $key => $value) {
# check all vars
$v->isOk($to[$key], "string", 1, 255, "Invalid receipient/depositor.");
$v->isOk($trantype[$key], "string", 1, 20, "Invalid transaction type.");
$v->isOk($descript[$key], "string", 0, 255, "Invalid description.");
$v->isOk($ref[$key], "string", 0, 255, "Invalid reference <b>[{$key}]</b>.");
$v->isOk($cheqnum[$key], "num", 0, 20, "Invalid cheque number <b>[{$key}]</b>.");
$v->isOk($amount[$key], "float", 1, 8, "Invalid amount <b>[{$key}]</b>.");
$v->isOk($accinv[$key], "num", 1, 20, "Invalid account involved <b>[{$key}]</b>.");
$v->isOk($date[$key], "date", 1, 15, "Invalid date <b>[{$key}]</b>.");
if (strtotime($date[$key]) >= strtotime($blocked_date_from) and strtotime($date[$key]) <= strtotime($blocked_date_to) and !user_is_admin(USER_ID)) {
return "<li class='err'>Period Range Is Blocked. Only an administrator can process entries within this period.</li>";
}
}
# 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;
}
# Processes
db_connect();
# Begin Transaction
pglib_transaction("BEGIN");
# Some info
$bankacc = getbankaccid($bankid);
$vatacc = gethook("accnum", "salesacc", "name", "VAT");
foreach ($amount as $key => $amt) {
$totamt = $amount[$key];
if ($chrgvat[$key] == "exc") {
$totamt += $vat[$key];
} elseif ($chrgvat[$key] == "inc") {
$amount[$key] -= $vat[$key];
} else {
$vat[$key] = "No VAT";
}
if ($cheqnum[$key] == '') {
$cheqnum[$key] = 0;
}
if (!isset($batch)) {
$refnum = getrefnum();
if (strtolower($trantype[$key]) == 'deposit') {
$vatacc = gethook("accnum", "salesacc", "name", "VAT", "1");
writetrans($bankacc, $accinv[$key], $date[$key], $refnum, $amount[$key], $descript[$key]);
if ($vat[$key] != 0) {
# DT(Bank), CT(VAT)
$vat[$key] += 0;
writetrans($bankacc, $vatacc, $date[$key], $refnum, $vat[$key], $descript[$key] . " VAT");
db_conn('cubit');
$Sl = "SELECT * FROM vatcodes WHERE id='{$vatcode[$key]}'";
$Rt = db_exec($Sl) or errDie("Unable to get data.");
$vd = pg_fetch_array($Rt);
vatr($vatcode[$key], $date[$key], "OUTPUT", $vd['code'], $refnum, $descript[$key] . " VAT", $totamt, $vat[$key]);
}
} else {
$vatacc = gethook("accnum", "salesacc", "name", "VAT");
writetrans($accinv[$key], $bankacc, $date[$key], $refnum, $amount[$key], $descript[$key]);
if ($vat[$key] != 0) {
# DT(Bank), CT(VAT)
$vat[$key] += 0;
writetrans($vatacc, $bankacc, $date[$key], $refnum, $vat[$key], $descript[$key] . " VAT");
db_conn('cubit');
$Sl = "SELECT * FROM vatcodes WHERE id='{$vatcode[$key]}'";
$Rt = db_exec($Sl) or errDie("Unable to get data.");
$vd = pg_fetch_array($Rt);
vatr($vatcode[$key], $date[$key], "INPUT", $vd['code'], $refnum, $descript[$key] . " VAT", -$totamt, -$vat[$key]);
}
}
$vat[$key] += 0;
db_connect();
$sql = "\n\t\t\t\tINSERT INTO cashbook (\n\t\t\t\t\tbankid, trantype, date, name, descript, cheqnum, \n\t\t\t\t\tamount, banked, accinv, div,chrgvat,vat,reference\n\t\t\t\t) VALUES (\n\t\t\t\t\t'{$bankid}', lower('{$trantype[$key]}'), '{$date[$key]}', '{$to[$key]}', '{$descript[$key]}', '{$cheqnum[$key]}', \n\t\t\t\t\t'{$totamt}', 'no', '{$accinv[$key]}', '" . USER_DIV . "','{$chrgvat[$key]}', '{$vat[$key]}','{$ref[$key]}'\n\t\t\t\t)";
$Rslt = db_exec($sql) or errDie("Unable to add bank payment to database.", SELF);
} else {
db_connect();
$vat[$key] += 0;
$sql = "\n\t\t\t\tINSERT INTO batch_cashbook (\n\t\t\t\t\tbankid, trantype, date, name, descript, cheqnum, \n\t\t\t\t\tamount, banked, accinv, div, chrgvat, vat, vatcode, \n\t\t\t\t\treference\n\t\t\t\t) VALUES (\n\t\t\t\t\t'{$bankid}', lower('{$trantype[$key]}'), '{$date[$key]}', '{$to[$key]}', '{$descript[$key]}', '{$cheqnum[$key]}', \n\t\t\t\t\t'{$totamt}', 'no', '{$accinv[$key]}', '" . USER_DIV . "','{$chrgvat[$key]}','{$vat[$key]}','{$vatcode[$key]}', \n\t\t\t\t\t'{$ref[$key]}'\n\t\t\t\t)";
$Rslt = db_exec($sql) or errDie("Unable to add bank payment to database.", SELF);
}
}
# Get bank details
$bankAccRslt = get("cubit", "*", "bankacct", "bankid", $bankid);
$bankacc = pg_fetch_array($bankAccRslt);
//.........这里部分代码省略.........
示例6: write
function write($_POST)
{
# Processes
db_connect();
# Get vars
extract($_POST);
if (isset($back)) {
unset($_POST["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($name, "string", 1, 255, "Invalid Person/Business paid to/received from.");
$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.");
foreach ($accinv as $key => $vaccid) {
$v->isOk($vaccid, "num", 1, 20, "Invalid Account (account involved).");
$v->isOk($accamt[$key], "float", 1, 10, "Invalid amount.");
$v->isOk($chrgvat[$key], "string", 1, 4, "Invalid VAT option.");
}
# display errors, if any
if ($v->isError()) {
$confirm = "";
$errors = $v->getErrors();
foreach ($errors as $e) {
$confirm .= "<li class=err>" . $e["msg"];
}
$confirm .= "<p><input type=button onClick='JavaScript:history.back();' value='« Correct submission'>";
return $confirm;
}
/* -- Start Hooks -- */
$vatacc = gethook("accnum", "salesacc", "name", "VAT");
# 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.";
}
$banklnk = pg_fetch_array($rslt);
/* -- End Hooks -- */
# Refnum
$refnum = getrefnum();
$amounts = "";
$accids = "";
$vats = "";
$chrgvats = "";
$vatcodes = "";
$gamt = 0;
pglib_transaction("BEGIN");
foreach ($accinv as $key => $vaccid) {
db_conn('cubit');
$Sl = "SELECT * FROM vatcodes WHERE id='{$vatcode[$key]}'";
$Ri = db_exec($Sl) or errDie("Unable to get data.");
$vd = pg_fetch_array($Ri);
$vatp = $vd['vat_amount'];
# Start Rattling vat
$totamt = $accamt[$key];
$vat = $getvat[$key];
if ($chrgvat[$key] == "exc") {
// $vat = sprint(($vatp/100) * $accamt[$key]);
$totamt += $vat;
} elseif ($chrgvat[$key] == "inc") {
// $vat = sprint(($accamt[$key]/(100 + $vatp)) * $vatp);
$accamt[$key] -= $vat;
} else {
// $vat = 0;
}
$totamt = sprint($totamt);
$amounts .= "|{$totamt}";
$vatcodes .= "|{$vatcode[$key]}";
$accids .= "|{$vaccid}";
$vats .= "|{$vat}";
$chrgvats .= "|{$chrgvat[$key]}";
$gamt = sprint($gamt + $totamt);
}
# Date format
$date = explode("-", $date);
$date = $date[2] . "-" . $date[1] . "-" . $date[0];
$cheqnum = 0 + $cheqnum;
db_connect();
$sql = "UPDATE batch_cashbook SET bankid = '{$bankid}', trantype = 'withdrawal', date = '{$date}', name = '{$name}',";
$sql .= "descript = '{$descript}', cheqnum = '{$cheqnum}', amount = '{$gamt}', banked = 'no', accids = '{$accids}',";
$sql .= "amounts = '{$amounts}', chrgvats = '{$chrgvats}', vats = '{$vats}', div = '" . USER_DIV . "',";
$sql .= "vatcodes = '{$vatcodes}', reference = '{$reference}' WHERE cashid = '{$id}'";
$Rslt = db_exec($sql) or errDie("Unable to add bank payment to database.", SELF);
pglib_transaction("COMMIT");
# Status report
$write = "\n\t<table " . TMPL_tblDflts . ">\n\t\t<tr>\n\t\t\t<th>Bank Payment</th>\n\t\t</tr>\n\t\t<tr class='datacell'>\n\t\t\t<td>Bank Payment added to cash book.</td>\n\t\t</tr>\n\t</table>\n\t<p>\n\t<table " . TMPL_tblDflts . ">\n\t\t<tr>\n\t\t\t<th>Quick Links</th>\n\t\t</tr>\n\t\t<tr class='" . bg_class() . "'>\n\t\t\t<td><a href='cashbook-view.php'>View Cash Book</a></td>\n\t\t</tr>\n\t\t<script>document.write(getQuicklinkSpecial());</script>\n\t</table>";
return $write;
}
示例7: 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>";
//.........这里部分代码省略.........
示例8: details
function details($_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;
}
db_connect();
# Get invoice info
$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 "<i class='err'>Not Found</i>";
}
$inv = pg_fetch_array($invRslt);
# format date
$inv['odate'] = explode("-", $inv['odate']);
$inv['odate'] = $inv['odate'][2] . "-" . $inv['odate'][1] . "-" . $inv['odate'][0];
/* --- Start Products Display --- */
# Products layout
$products = "";
$disc = 0;
# get selected stock in this invoice
db_connect();
$sql = "SELECT * FROM nons_inv_items WHERE invid = '{$invid}' AND div = '" . USER_DIV . "'";
$stkdRslt = db_exec($sql);
# Put in product
while ($stk = pg_fetch_array($stkdRslt)) {
$Sl = "SELECT * FROM vatcodes WHERE id='{$stk['vatex']}'";
$Ri = db_exec($Sl);
$vd = pg_fetch_array($Ri);
if ($vd['zero'] == "Yes") {
$stk['vatex'] = "y";
}
if ($stk['vatex'] == 'y') {
$ex = "#";
} else {
$ex = " ";
}
$products .= "\r\n\t\t\t<tr valign='top'>\r\n\t\t\t\t<td style='border-right: 2px solid #000' nowrap>{$ex} {$stk['description']}</td>\r\n\t\t\t\t<td style='border-right: 2px solid #000' align='right'>{$stk['qty']}</td>\r\n\t\t\t\t<td style='border-right: 2px solid #000' align='right'>{$stk['unitcost']}</td>\r\n\t\t\t\t<td align='right'>" . CUR . " {$stk['amt']}</td>\r\n\t\t\t</tr>";
}
/* --- Start Some calculations --- */
# Subtotal
$SUBTOT = sprint($inv['subtot']);
$VAT = sprint($inv['vat']);
$TOTAL = sprint($inv['total']);
/* --- End Some calculations --- */
/* - Start Hooks - */
$vatacc = gethook("accnum", "salesacc", "name", "VAT");
/* - End Hooks - */
# todays date
$date = date("d-m-Y");
$sdate = date("Y-m-d");
$refnum = getrefnum();
/*refnum*/
/* --- Updates ---- */
db_connect();
# 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>";
if ($inv['chrgvat'] == "yes") {
$inv['chrgvat'] = "Inclusive";
} elseif ($inv['chrgvat'] == "no") {
$inv['chrgvat'] = "Exclusive";
} else {
$inv['chrgvat'] = "No vat";
}
$table_borders = "\r\n\t\tborder-top: 2px solid #000000;\r\n\t\tborder-left: 2px solid #000000;\r\n\t\tborder-right: 2px solid #000000;\r\n\t\tborder-bottom: none;";
/* -- Final Layout -- */
$details = "\r\n\t\t<center>\r\n\t\t<table cellpadding='0' cellspacing='0' width='85%' style='{$table_borders}'>\r\n\t\t\t<tr><td>\r\n\t\t\t<table border='0' cellpadding='2' cellspacing='2' width='100%'>\r\n\t\t\t\t<tr>\r\n\t\t\t\t\t<td align='left'><img src='compinfo/getimg.php' width='230' height='47'>{$barcode}</td>\r\n\t\t\t\t\t<td align='left'><font size='5'><b>" . COMP_NAME . "</b></font></td>\r\n\t\t\t\t\t<td align='right'><font size='5'><b>Quote</b></font></td>\r\n\t\t\t\t</tr>\r\n\t\t\t</table>\r\n\t\t\t</td></tr>\r\n\t\t</table>\r\n\r\n\t\t<table cellpadding='0' cellspacing='0' width='85%' style='{$table_borders}'>\r\n\t\t\t<tr><td valign='top'>\r\n\t\t\t<table cellpadding='2' cellspacing='0' border='0' width='100%'>\r\n\t\t\t\t<tr>\r\n\t\t\t\t\t<td style='border-right: 2px solid #000'>" . COMP_ADDRESS . " </td>\r\n\t\t\t\t</tr>\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</tr>\r\n\t\t\t\t<tr>\r\n\t\t\t\t\t<td style='border-right: 2px solid #000'><b>REG:</b> " . COMP_REGNO . "</b> </td>\r\n\t\t\t\t</tr>\r\n\t\t\t\t<tr>\r\n\t\t\t\t\t<td style='border-right: 2px solid #000'><b>VAT REG:</b> " . COMP_VATNO . " </td>\r\n\t\t\t\t</tr>\r\n\t\t\t\t<tr>\r\n\t\t\t\t\t<td style='border-right: 2px solid #000'><b>Tel:</b> " . COMP_TEL . " </td>\r\n\t\t\t\t</tr>\r\n\t\t\t\t<tr>\r\n\t\t\t\t\t<td style='border-right: 2px solid #000'><b>Fax:</b> " . COMP_FAX . " </td>\r\n\t\t\t\t</tr>\r\n\t\t\t</table>\r\n\t\t\t</td><td valign='top'>\r\n\t\t\t<table cellpadding='2' cellspacing='0' border='0' width='100%'>\r\n\t\t\t\t<tr>\r\n\t\t\t\t\t<td><b>Date</b></td>\r\n\t\t\t\t</tr>\r\n\t\t\t\t<tr>\r\n\t\t\t\t\t<td>{$inv['odate']}</td>\r\n\t\t\t\t</tr>\r\n\t\t\t\t<tr>\r\n\t\t\t\t\t<td style='border-bottom: 2px solid #000'> </td>\r\n\t\t\t\t</tr>\r\n\t\t\t\t<tr>\r\n\t\t\t\t\t<td colspan='2'><b>Quote No:</b> {$inv['invid']}</td>\r\n\t\t\t\t</tr>\r\n\t\t\t\t{$sp}\r\n\t\t\t</table>\r\n\t\t\t</td></tr>\r\n\t\t</table>\r\n\r\n\t\t<table cellpadding='0' cellspacing='0' width='85%' style='{$table_borders}'>\r\n\t\t\t<tr><td>\r\n\t\t\t<table cellpadding='2' cellspacing='0' border='0' width='100%'>\r\n\t\t\t\t<tr>\r\n\t\t\t\t\t<td align='center'><font size='4'><b>Quote To:</b></font></td>\r\n\t\t\t\t</tr>\r\n\t\t\t</table>\r\n\t\t\t</td></tr>\r\n\t\t</table>\r\n\r\n\t\t<table cellpadding='0' cellspacing='0' width='85%' style='{$table_borders}'>\r\n\t\t\t<tr><td>\r\n\t\t\t<table cellpadding='2' cellspacing='0' border='0' width='100%'>\r\n\t\t\t\t<tr>\r\n\t\t\t\t\t<td width='33%' style='border-right: 2px solid #000'><b>{$inv['cusname']}</b></td>\r\n\t\t\t\t\t<td width='33%'><b>Address</b></td>\r\n\t\t\t\t</tr>\r\n\t\t\t\t<tr>\r\n\t\t\t\t\t<td style='border-right: 2px solid #000' valign='bottom'><b>Customer VAT No:</b> {$inv['cusvatno']}</td>\r\n\t\t\t\t\t<td>" . nl2br($inv["cusaddr"]) . "</td>\r\n\t\t\t\t</tr>\r\n\t\t\t\t<tr>\r\n\t\t\t\t\t<td style='border-right: 2px solid #000'><b>VAT:</b> {$inv['chrgvat']}</td>\r\n\t\t\t\t</tr>\r\n\t\t\t</table>\r\n\t\t\t</td></tr>\r\n\t\t</table>\r\n\r\n\t\t<table cellpadding='0' cellspacing='0' width='85%' style='{$table_borders}'>\r\n\t\t\t<tr><td>\r\n\t\t\t<table cellpadding='2' cellspacing='0' border='0' width='100%'>\r\n\t\t\t\t<tr>\r\n\t\t\t\t\t<td style='border-bottom: 2px solid #000; border-right: 2px solid #000;'><b>Description</b></td>\r\n\t\t\t\t\t<td style='border-bottom: 2px solid #000; border-right: 2px solid #000;' align='right'><b>Qty</b></td>\r\n\t\t\t\t\t<td style='border-bottom: 2px solid #000; border-right: 2px solid #000;' align='right'><b>Unit Price</b></td>\r\n\t\t\t\t\t<td style='border-bottom: 2px solid #000' align='right'><b>Amount</b></td>\r\n\t\t\t\t</tr>\r\n\t\t\t\t{$products}\r\n\t\t\t</table>\r\n\t\t\t</td></tr>\r\n\t\t</table>\r\n\r\n\t\t<table cellpadding='0' cellspacing='0' width='85%' style='{$table_borders}'>\r\n\t\t\t<tr><td>\r\n\t\t\t<table cellpadding='2' cellspacing='0' border='0' width='100%'>\r\n\t\t\t\t<tr>\r\n\t\t\t\t\t<td><i>VAT Exempt Indicator: #</i></td>\r\n\t\t\t\t</tr>\r\n\t\t\t\t<tr>\r\n\t\t\t\t\t<td>{$inv['remarks']}</td>\r\n\t\t\t\t</tr>\r\n\t\t\t</table>\r\n\t\t</table>\r\n\r\n\t\t<table cellpadding='0' cellspacing='0' width='85%' style='border: 2px solid #000000'>\r\n\t\t\t<tr><td>\r\n\t\t\t<table cellpadding='2' cellspacing='0' border='0' width='100%'>\r\n\t\t\t\t<tr>\r\n\t\t\t\t\t<td style='border-right: 2px solid #000' width='60%'> </td>\r\n\t\t\t\t\t<td><b>Subtotal:</b></td>\r\n\t\t\t\t\t<td align='right' nowrap><b>" . CUR . " {$inv['subtot']}</b></td>\r\n\t\t\t\t</tr>\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><b>VAT @ " . TAX_VAT . "%:</b></td>\r\n\t\t\t\t\t<td align='right' nowrap><b>" . CUR . " {$inv['vat']}</b></td>\r\n\t\t\t\t</tr>\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><b>Total Incl VAT:</b></td>\r\n\t\t\t\t\t<td align='right' nowrap><b>" . CUR . " {$inv['total']}</b></td>\r\n\t\t\t\t</tr>\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></td>\r\n\t\t\t\t\t<td nowrap></td>\r\n\t\t\t</table>\r\n\t\t</table>";
$OUTPUT = $details;
require "tmpl-print.php";
}
示例9: update
function update($_POST)
{
# Get Vars ( banked[] )
foreach ($_POST as $key => $value) {
${$key} = $value;
}
# Check if anything is selected
if (!isset($banked)) {
$err = "<li class=err> Please Select at least one entry to update.";
return cashbook($_POST, $err);
}
/* - Start Hooks - */
$vatacc = gethook("accnum", "salesacc", "name", "VAT");
/* - End Hooks - */
$refnum = getrefnum();
/*refnum*/
# Record all trans
$tot = 0;
$totr = 0;
$totp = 0;
$recpts = "";
$paymnts = "";
foreach ($banked as $key => $cashid) {
// Connect to database
db_Connect();
$sql = "SELECT * FROM cashbook WHERE cashid='{$cashid}' AND div = '" . USER_DIV . "'";
$cashRslt = db_exec($sql) or errDie("ERROR: Unable to retrieve details from database.", SELF);
$cash = pg_fetch_array($cashRslt);
# Set record as banked
db_connect();
$sql = "UPDATE cashbook SET banked = 'yes' WHERE cashid='{$cashid}' AND div = '" . USER_DIV . "'";
$Rslt = db_exec($sql) or errDie("Unable to set bank deposit as banked in Cubit.", SELF);
}
// Connect to database
db_Connect();
$sql = "SELECT * FROM cashbook WHERE bankid = '{$bankid}' AND banked = 'no' AND div = '" . USER_DIV . "' ORDER BY date DESC";
$cashRslt = db_exec($sql) or errDie("ERROR: Unable to retrieve bank transactions from database.", SELF);
$tot = 0;
$totr = 0;
$totp = 0;
$recpts = "";
$paymnts = "";
while ($cash = pg_fetch_array($cashRslt)) {
if ($cash['trantype'] == "deposit") {
$recpts .= "<tr><td>{$cash['date']}</td><td>{$cash['descript']}</td><td align=right>" . CUR . " {$cash['amount']}</td></tr>";
$totr += $cash['amount'];
} else {
$paymnts .= "<tr><td>{$cash['date']}</td><td>{$cash['descript']}</td><td align=right>" . CUR . " {$cash['amount']}</td></tr>";
$totp += $cash['amount'];
}
$tot += $cash['amount'];
}
$reconbal = sprint($cbal + ($totr - $totp));
# Get account name for bank account
db_connect();
$sql = "SELECT accname, bankname FROM bankacct WHERE bankid= '{$bankid}' AND div = '" . USER_DIV . "'";
$bankRslt = db_exec($sql);
$bank = pg_fetch_array($bankRslt);
# 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.";
}
$banklnk = pg_fetch_array($rslt);
# Get bank balance
$sql = "SELECT (debit - credit) as bal FROM trial_bal WHERE period='" . PRD_DB . "' AND accid = '{$banklnk['accnum']}' AND div = '" . USER_DIV . "'";
$brslt = db_exec($sql) or errDie("Unable to retrieve bank account link from Cubit", SELF);
$bal = pg_fetch_array($brslt);
$diff = $reconbal - $bal['bal'];
$derr = "";
if ($diff != 0) {
$derr = "<tr><td colspan=2><b class=err>Bank statement and computer balance not balancing by</b></td><td align=right>" . CUR . " {$diff}</td></tr>";
}
// Layout
$update = "<table border=1>\n\t<tr><th colspan=3><h3>Bank Reconciliation Output</h3></th></tr>\n\t<tr><td></td></tr>\n\t<tr><td colspan=3>\n\t\t<table cellpadding='2' cellspacing='0' border=0 bordercolor='#000000' width=100%>\n\t\t\t<tr><td><b>Bank Account : </b>{$bank['accname']}</td><td></td><td align=right><b>Prepared By : </b>" . USER_NAME . "</td></tr>\n\t\t\t<tr><td><b>Closing Balance As per Bank Statement : </b>" . CUR . " {$cbal}</td><td></td></tr>\n\t\t</table>\n\t</td></tr>\n\t<tr><td><br><br></td></tr>\n\t<tr><td colspan=3><b>Plus Outstanding Receipts :</b></td></tr>\n\t<tr><th>Date</th><th>Reference</th><th>Amount</th></tr>\n\t{$recpts}\n\t<tr><td colspan=2><br></td><td align=right>____________</td></tr>\n\t<tr><td colspan=2 align=right><b>Sub Total</b></td><td align=right>" . CUR . " {$totr}</td></tr>\n\t<tr><td><br><br></td></tr>\n\t<tr><td colspan=3><b>Less Outstanding Payments :</b></td></tr>\n\t<tr><th>Date</th><th>Reference</th><th>Amount</th></tr>\n\t{$paymnts}\n\t<tr><td colspan=2><br></td><td align=right>____________</td></tr>\n\t<tr><td colspan=2 align=right><b>Sub Total</b></td><td align=right>" . CUR . " {$totp}</td></tr>\n\t<tr><td><br><td></tr>\n\t{$derr}\n\t<tr><td><br><td></tr>\n\t<tr><td colspan=2><br></td><td align=right>____________</td></tr>\n\t<tr><td colspan=2><b>Reconciled Bank Balance</b></td><td align=right>" . CUR . " {$reconbal}</td></tr>\n\t<tr><td colspan=2><b>Computer Bank Balance</b></td><td align=right>" . CUR . " {$bal['bal']}</td></tr>\n\t<tr><td colspan=2><br></td><td align=right>____________</td></tr>\n\t<tr><td colspan=2><b>Diff</b></td><td align=right>" . CUR . " {$diff}</td></tr>\n\t<tr><td colspan=2><br></td><td align=right>____________</td></tr>\n\t</table>";
# Send the stream
include "temp.xls.php";
return Stream("BankRecon", $update);
}
示例10: write
function write($_POST)
{
# Get vars
foreach ($_POST as $key => $value) {
${$key} = $value;
}
# validate input
require_lib("validate");
$v = new validate();
$v->isOk($purid, "num", 1, 20, "Invalid Order number.");
$v->isOk($refno, "string", 0, 255, "Invalid Delivery Reference No.");
$v->isOk($remarks, "string", 0, 255, "Invalid Remarks.");
$v->isOk($supinv, "string", 0, 255, "Invalid supp inv.");
# used to generate errors
$error = "asa@";
# display errors, if any
$err = "";
if ($v->isError()) {
$errors = $v->getErrors();
foreach ($errors as $e) {
$err .= "<li class=err>" . $e["msg"];
}
return details($_POST, $err);
}
pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
# Get purchase info
db_connect();
$sql = "SELECT * FROM purchases WHERE purid = '{$purid}' AND div = '" . USER_DIV . "'";
$purRslt = db_exec($sql) or errDie("Unable to get purchase information");
if (pg_numrows($purRslt) < 1) {
return "<li>- purchase Not Found</li>";
}
$pur = pg_fetch_array($purRslt);
$td = $pur['pdate'];
# check if purchase has been received
if ($pur['invcd'] == "y") {
$error = "<li class=err> Error : purchase number <b>{$pur['purnum']}</b> has already been invoiced.";
$error .= "<p><input type=button onClick='JavaScript:history.back();' value='« Correct submission'>";
return $error;
}
# Get selected supplier info
db_connect();
$sql = "SELECT * FROM suppliers WHERE supid = '{$pur['supid']}' AND div = '" . USER_DIV . "'";
$supRslt = db_exec($sql) or errDie("Unable to get customer information");
if (pg_numrows($supRslt) < 1) {
// code here
} else {
$sup = pg_fetch_array($supRslt);
}
# Get department info
db_conn("exten");
$sql = "SELECT * FROM departments WHERE deptid = '{$pur['deptid']}' AND div = '" . USER_DIV . "'";
$deptRslt = db_exec($sql);
if (pg_numrows($deptRslt) < 1) {
$dept['deptname'] = "<i class=err> - Not Found</i>";
} else {
$dept = pg_fetch_array($deptRslt);
}
# Get warehouse name
db_conn("exten");
$sql = "SELECT * FROM warehouses WHERE div = '" . USER_DIV . "'";
$whRslt = db_exec($sql);
$wh = pg_fetch_array($whRslt);
//pglib_transaction ("BEGIN") or errDie("Unable to start a database transaction.",SELF);
# get selected stock in this purchase
db_connect();
$sql = "SELECT * FROM pur_items WHERE purid = '{$purid}' AND div = '" . USER_DIV . "'";
$Ri = db_exec($sql);
$refnum = getrefnum();
while ($id = pg_fetch_array($Ri)) {
db_connect();
# get selamt from selected stock
$sql = "SELECT * FROM stock WHERE stkid = '{$id['stkid']}' AND div = '" . USER_DIV . "'";
$stkRslt = db_exec($sql);
$stk = pg_fetch_array($stkRslt);
$Sl = "SELECT * FROM vatcodes WHERE id='{$stk['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 ($id['svat'] == 0) {
$exvat = "y";
} else {
$exvat = "";
}
$vr = pvatcalc($id['amt'], $pur['vatinc'], $exvat);
$vrs = explode("|", $vr);
$ivat = $vrs[0];
$iamount = $vrs[1];
vatr($vd['id'], $pur['pdate'], "INPUT", $vd['code'], $refnum, "Purchase {$pur['purnum']} Supplier : {$pur['supname']}.", $iamount, $ivat);
}
/* - Start Hooks - */
$vatacc = gethook("accnum", "salesacc", "name", "VAT");
$cvacc = gethook("accnum", "pchsacc", "name", "Cost Variance");
/* - End Hooks - */
# Record the payment on the statement
db_connect();
$sdate = date("Y-m-d");
$DAte = date("Y-m-d");
//.........这里部分代码省略.........
示例11: bwrite
//.........这里部分代码省略.........
# Update Order items
$sql = "\n\t\t\t\t\tUPDATE nons_pur_items \n\t\t\t\t\tSET rqty = (rqty + '{$qtys[$keys]}'), accid = '{$stkacc[$keys]}' \n\t\t\t\t\tWHERE id = '{$ids[$keys]}' AND purid='{$purid}' AND div = '" . USER_DIV . "'";
$rslt = db_exec($sql) or errDie("Unable to insert Order items to Cubit.", SELF);
# keep records for transactions
if (isset($totstkamt[$stkacc[$keys]])) {
$totstkamt[$stkacc[$keys]] += $amt[$keys];
} else {
$totstkamt[$stkacc[$keys]] = $amt[$keys];
}
# check if there are any outstanding items
$sql = "SELECT * FROM nons_pur_items WHERE purid = '{$purid}' AND (qty - rqty) > '0' AND div = '" . USER_DIV . "'";
$stkdRslt = db_exec($sql);
# if none the set to received
if (pg_numrows($stkdRslt) < 1) {
# update surch_int(received = 'y')
$sql = "\n\t\t\t\t\t\tUPDATE nons_purchases \n\t\t\t\t\t\tSET received = 'y', supplier = '{$pur['supplier']}', supaddr = '{$pur['supaddr']}' \n\t\t\t\t\t\tWHERE purid = '{$purid}' AND div = '" . USER_DIV . "'";
$rslt = db_exec($sql) or errDie("Unable to update international Orders in Cubit.", SELF);
}
}
}
# Update Order on the DB
if ($pur['part'] == 'y') {
# Update Order on the DB
$sql = "\n\t\t\t\tUPDATE nons_purchases \n\t\t\t\tSET ctyp = '{$ctyp}', typeid = '{$typeid}', refno = '{$refno}', remarks = '{$remarks}' \n\t\t\t\tWHERE purid = '{$purid}' AND div = '" . USER_DIV . "'";
$rslt = db_exec($sql) or errDie("Unable to update Order in Cubit.", SELF);
} else {
# Update Order on the DB
$sql = "\n\t\t\t\tUPDATE nons_purchases \n\t\t\t\tSET ctyp = '{$ctyp}', typeid = '{$typeid}', refno = '{$refno}', remarks = '{$remarks}' \n\t\t\t\tWHERE purid = '{$purid}' AND div = '" . USER_DIV . "'";
$rslt = db_exec($sql) or errDie("Unable to update Order in Cubit.", SELF);
}
/* Transactions */
$refnum = getrefnum(date("d-m-Y"));
/* - Start Hooks - */
$vatacc = gethook("accnum", "salesacc", "name", "VAT");
/* - End Hooks - */
$detadd = "";
if (isset($supid)) {
$detadd = " from Supplier {$sup['supname']}";
}
$sdate = $pur['pdate'];
$tpp = 0;
$ccamt = 0;
# record transaction from data
foreach ($totstkamt as $stkacc => $wamt) {
# Debit Stock and Credit Suppliers control
writetrans($stkacc, $supacc, date("d-m-Y"), $refnum, $wamt, "Non-Stock Purchase No. {$pur['purnum']} Received {$detadd}.");
pettyrec($supacc, $sdate, "ct", "Non-Stock Purchase No. {$pur['purnum']} Received {$detadd}.", $wamt, "Cash Order");
}
# vat
$vatamt = $revat;
# Add vat if not included
if ($pur['vatinc'] == 'no') {
$retot = $resub + $vatamt;
} elseif ($pur['vatinc'] == "novat") {
$retot = $resub;
$vatamt = 0;
} else {
$retot = $resub;
}
if (isset($supid)) {
# Ledger Records
$DAte = $pur['pdate'];
suppledger($sup['supid'], $stkacc, $DAte, $pur['purid'], "Non-Stock Purchase No. {$pur['purnum']} received.", $retot, 'c');
}
if ($vatamt != 0) {
# Debit bank and credit the account involved
示例12: write
function write($_POST)
{
extract($_POST);
if (isset($back)) {
unset($_POST["back"]);
return alloc($_POST);
}
require_lib("validate");
$v = new validate();
$v->isOk($all, "num", 1, 1, "Invalid allocation.");
$v->isOk($bankid, "num", 1, 30, "Invalid Bank Account.");
$v->isOk($date, "date", 1, 14, "Invalid Date.");
$v->isOk($out, "float", 1, 40, "Invalid out amount.");
$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($amt, "float", 1, 40, "Invalid amount.");
$v->isOk($setamt, "float", 1, 40, "Invalid Settlement Amount.");
$v->isOk($setvat, "string", 1, 10, "Invalid Settlement VAT Option.");
$v->isOk($setvatcode, "string", 1, 40, "Invalid Settlement VAT code");
$v->isOk($cusid, "num", 1, 40, "Invalid customer number.");
$v->isOk($out1, "float", 0, 40, "Invalid paid amount(current).");
$v->isOk($out2, "float", 0, 40, "Invalid paid amount(30).");
$v->isOk($out3, "float", 0, 40, "Invalid paid amount(60).");
$v->isOk($out4, "float", 0, 40, "Invalid paid amount(90).");
$v->isOk($out5, "float", 0, 40, "Invalid paid amount(120).");
$v->isOk($overpay, "float", 1, 20, "Invalid Overpay Amount.");
if (isset($invids)) {
foreach ($invids as $key => $value) {
$v->isOk($invids[$key], "num", 1, 50, "Invalid Invoice No.");
$v->isOk($paidamt[$key], "float", 1, 40, "Invalid amount to be paid.");
$v->isOk($stock_setamt[$key], "float", 1, 40, "Invalid Settlement Discount Amount");
}
}
if ($v->isError()) {
$confirm = $v->genErrors();
return $confirm . confirm($_POST);
}
/* get bank account id of cash on hand account IF this entry is cash */
if (($bank_acc = getbankaccid($bankid)) === false or $bankid == "0") {
//old function didnt check if cash is selected ... if(($bank_acc = getbankaccid($bankid)) === false) {
$sql = "SELECT accid FROM core.accounts WHERE accname='Cash on Hand'";
$rslt = db_exec($sql);
if (pg_num_rows($rslt) < 1) {
if ($bankid == 0) {
return "There is no 'Cash on Hand' account, there was one, but\n\t\t\t\t\tits not there now, you must have deleted it, if you want\n\t\t\t\t\tto use cash functionality please create a 'Cash on Hand' account.";
} else {
return "Invalid bank acc.";
}
}
$bank_acc = pg_fetch_result($rslt, 0);
}
$cus = qryCustomer($cusid, "cusnum, deptid, cusname, surname");
$dept = qryDepartment($cus["deptid"], "debtacc");
$refnum = getrefnum();
pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
# date format
$sdate = explode("-", $date);
$_SESSION["global_day"] = $sdate[2];
$_SESSION["global_month"] = $sdate[1];
$_SESSION["global_year"] = $sdate[0];
// $sdate = $sdate[2]."-".$sdate[1]."-".$sdate[0];
$sdate = "{$date_year}-{$date_month}-{$date_day}";
$cheqnum = 0 + $cheqnum;
$pay = "";
$accdate = $sdate;
// $accdate = "$date_year-$date_month-$date_day";
/* Paid invoices */
$invidsers = "";
$rinvids = "";
$amounts = "";
$invprds = "";
$rages = "";
$setamts = "";
#get settlement accid
$get_setacc = "SELECT accid FROM accounts WHERE accname = 'Debtors Settlement Discount'";
$run_setacc = db_exec($get_setacc) or errDie("Unable to get settlement account information");
$setaccid = pg_fetch_result($run_setacc, 0, 0);
$vatacc = gethook("accnum", "salesacc", "name", "VAT", "VAT");
$amt += $overpay;
/* OPTION 3 : ALLOCATE TO EACH INVOICE (confirm) */
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);
//.........这里部分代码省略.........
示例13: write
function write($_POST)
{
# get vars
extract($_POST);
# validate input
require_lib("validate");
$v = new validate();
$v->isOk($bankid, "num", 1, 30, "Invalid Bank Account.");
$v->isOk($from_day, "num", 1, 2, "Invalid Day for the 'From' date.");
$v->isOk($from_month, "num", 1, 2, "Invalid month for the 'From' date..");
$v->isOk($from_year, "num", 1, 4, "Invalid year for the 'From' date..");
$v->isOk($to_day, "num", 1, 2, "Invalid Day for the 'To' date.");
$v->isOk($to_month, "num", 1, 2, "Invalid month for the 'To' date..");
$v->isOk($to_year, "num", 1, 4, "Invalid year for the 'To' date..");
# lets mix the date
$from = $from_day . "-" . $from_month . "-" . $from_year;
$to = $to_day . "-" . $to_month . "-" . $to_year;
# 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;
}
pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
# Get bank details
$bankRslt = get("cubit", "accname,bankname,fcid", "bankacct", "bankid", $bankid);
$bank = pg_fetch_array($bankRslt);
$Sl = "SELECT * FROM currency WHERE fcid='{$bank['fcid']}'";
$Ry = db_exec($Sl) or errDie("Unable to get currency");
if (pg_numrows($Ry) > 0) {
$curdata = pg_fetch_array($Ry);
$fc = $curdata['symbol'];
}
$s1 = "";
$s2 = "";
$s3 = "";
$s4 = "";
$s5 = "";
$order = "order by date desc, cheqnum asc";
if (isset($order)) {
if ($order == "order by date desc, cheqnum asc") {
$s2 = "selected";
} elseif ($order == "order by date desc, cheqnum desc") {
$s3 = "selected";
} elseif ($order == "order by cheqnum asc") {
$s4 = "selected";
} elseif ($order == "order by cheqnum desc") {
$s5 = "selected";
} else {
$s1 = "selected";
}
} else {
$s1 = "selected";
}
// Set up table to display in
# Receipts
$OUTPUT = "\n\t<center>\n\t<h3>Batch Cash Book Entries<br><br>Account : {$bank['accname']} - {$bank['bankname']}<br>Period : {$from} to {$to}</h3>\n\t<table " . TMPL_tblDflts . ">\n\t<form action='" . SELF . "' method='POST' name='form'>\n\t\t<input type='hidden' name='key' value='viewcash'>\n\t\t<input type='hidden' name='bankid' value='{$bankid}'>\n\t\t<input type='hidden' name='from_day' value='{$from_day}'>\n\t\t<input type='hidden' name='from_month' value='{$from_month}'>\n\t\t<input type='hidden' name='from_year' value='{$from_year}'>\n\t\t<input type='hidden' name='to_day' value='{$to_day}'>\n\t\t<input type='hidden' name='to_month' value='{$to_month}'>\n\t\t<input type='hidden' name='to_year' value='{$to_year}'>\n\t</table>\n\t<p>\n\t<table " . TMPL_tblDflts . " width='95%'>\n\t\t<tr>\n\t\t\t<td colspan='7'><h4>Receipts</h4></td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<th> Date</th>\n\t\t\t<th>Bank Account Name</th>\n\t\t\t<th>Cheque Number</th>\n\t\t\t<th>Received From : </th>\n\t\t\t<th>Description</th>\n\t\t\t<th>Ledger Account</th>\n\t\t\t<th>Amount</th>\n\t\t</tr>";
$rtotal = 0;
// Received total amount
// Connect to database
db_Connect();
# date format
$from = explode("-", $from);
$from = $from[2] . "-" . $from[1] . "-" . $from[0];
$to = explode("-", $to);
$to = $to[2] . "-" . $to[1] . "-" . $to[0];
$vatacc = gethook("accnum", "salesacc", "name", "VAT");
# 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.";
}
$banklnk = pg_fetch_array($rslt);
db_Connect();
$sql = "SELECT * FROM batch_cashbook WHERE date >= '{$from}' AND date <= '{$to}' AND trantype='deposit' AND bankid='{$bankid}' AND div = '" . USER_DIV . "' {$order}";
$accntRslt = db_exec($sql) or errDie("ERROR: Unable to retrieve bank deposits details from database.", SELF);
$numrows = pg_numrows($accntRslt);
if ($numrows < 1) {
//$OUTPUT .= "<tr><td colspan='7' align='center'><li class='err'>There are no batch Payments/cheques received for the selected period.</td></tr>";
} else {
for ($i = 0; $i < $numrows; $i++) {
$accnt = pg_fetch_array($accntRslt, $i);
if (!isset($pro[$accnt['cashid']])) {
continue;
}
// if($accnt['bt']=="receipt") {
$refnum = getrefnum();
if (strlen($accnt['accids']) > 0) {
$accids = explode("|", $accnt['accids']);
$vatcodes = explode("|", $accnt['vatcodes']);
$amounts = explode("|", $accnt['amounts']);
$vats = explode("|", $accnt['vats']);
$chrgvats = explode("|", $accnt['chrgvats']);
//.........这里部分代码省略.........
示例14: write
//.........这里部分代码省略.........
$xi['vatcode'] += 0;
$xi['account'] += 0;
$xi['del'] += 0;
$cols = grp(m("invid", $x["invid"]), m("whid", $xi["whid"]), m("stkid", $xi["stkid"]), m("qty", $xi["qty"]), m("unitcost", $xi["unitcost"]), m("amt", $xi["amt"]), m("disc", $xi["disc"]), m("discp", $xi["discp"]), m("vatcode", $xi["vatcode"]), m("account", $xi["account"]), m("description", $xi["description"]), m("del", $xi["del"]), m("noted", $xi["noted"]), m("serno", $xi["serno"]), m("div", USER_DIV));
$dbobj->setTable("inv_items", $prd);
$dbobj->setOpt($cols);
$dbobj->run();
$dbobj->free();
}
/* remove invoice from cubit schema */
$dbobj = new dbDelete("invoices", "cubit", wgrp(m("invid", $x["invid"]), m("div", USER_DIV)));
$dbobj->run();
$dbobj->setTable("inv_items", "cubit");
$dbobj->run();
}
/* start moving invoices */
// move invoices that are fully paid
$sql = "SELECT * FROM cubit.invoices WHERE balance=0 AND printed = 'y' AND done = 'y' AND div = '" . USER_DIV . "'";
$invbRslt = db_exec($sql) or errDie("Unable to update Invoice information in Cubit.", SELF);
while ($x = pg_fetch_array($invbRslt)) {
if (($prd = $x['prd']) == "0") {
$prd = PRD_DB;
}
// move invoice
$cols = grp(m("invid", $x["invid"]), m("invnum", $x["invnum"]), m("deptid", $x["deptid"]), m("cusnum", $x["cusnum"]), m("deptname", $x["deptname"]), m("cusacc", $x["cusacc"]), m("cusname", $x["cusname"]), m("surname", $x["surname"]), m("cusaddr", $x["cusaddr"]), m("cusvatno", $x["cusvatno"]), m("cordno", $x["cordno"]), m("ordno", $x["ordno"]), m("chrgvat", $x["chrgvat"]), m("terms", $x["terms"]), m("traddisc", $x["traddisc"]), m("salespn", $x["salespn"]), m("odate", $x["odate"]), m("delchrg", $x["delchrg"]), m("subtot", $x["subtot"]), m("vat", $x["vat"]), m("total", $x["total"]), m("age", $x["age"]), m("comm", $x["comm"]), m("discount", $x["discount"]), m("delivery", $x["delivery"]), m("docref", $x["docref"]), m("prd", $x["prd"]), m("delvat", $x["delvat"]), m("balance", 0), m("printed", "y"), m("done", "y"), m("username", USER_NAME), m("div", USER_DIV));
$dbobj = new dbUpdate("invoices", $prd, $cols);
$dbobj->run(DB_INSERT);
$dbobj->free();
// record movement
$cols = grp(m("invtype", "inv"), m("invnum", $x["invnum"]), m("prd", $x["prd"]), m("docref", $x["docref"]), m("div", USER_DIV));
$dbobj->setTable("movinv", "cubit");
$dbobj->setOpt($cols);
$dbobj->run();
$dbobj->free();
// move invoice items
$inv_items = new dbSelect("inv_items", "cubit", grp(m("where", wgrp(m("invid", $x["invid"]), m("div", USER_DIV)))));
$inv_items->run();
while ($xi = $inv_items->fetch_array()) {
$xi['vatcode'] += 0;
$xi['account'] += 0;
$xi['del'] += 0;
$cols = grp(m("invid", $x["invid"]), m("whid", $xi["whid"]), m("stkid", $xi["stkid"]), m("qty", $xi["qty"]), m("unitcost", $xi["unitcost"]), m("amt", $xi["amt"]), m("disc", $xi["disc"]), m("discp", $xi["discp"]), m("vatcode", $xi["vatcode"]), m("account", $xi["account"]), m("description", $xi["description"]), m("del", $xi["del"]), m("noted", $xi["noted"]), m("serno", $xi["serno"]), m("div", USER_DIV));
$dbobj->setTable("inv_items", $prd);
$dbobj->setOpt($cols);
$dbobj->run();
$dbobj->free();
}
/* remove invoice from cubit schema */
$dbobj = new dbDelete("invoices", "cubit", wgrp(m("invid", $x["invid"]), m("div", USER_DIV)));
$dbobj->run();
$dbobj->setTable("inv_items", "cubit");
$dbobj->run();
}
#do journal for the settlement discount here ... now ...
if ($setamt[$t] > 0) {
db_conn('core');
#get settlement accid
$get_setacc = "SELECT accid FROM accounts WHERE accname = 'Debtors Settlement Discount'";
$run_setacc = db_exec($get_setacc) or errDie("Unable to get settlement account information");
$setaccid = pg_fetch_result($run_setacc, 0, 0);
#calculate the settlement vat ... and amt
if (isset($setvat[$t]) and $setvat[$t] == 'inc') {
db_connect();
$get_vcode = "SELECT * FROM vatcodes WHERE id = '{$setvatcode[$t]}' LIMIT 1";
$run_vcode = db_exec($get_vcode) or errDie("Unable to get vatcode informtion.");
if (pg_numrows($run_vcode) < 1) {
return "<li class='err'>Settlement Discount VAT Code Not Set.</li>";
}
$vd = pg_fetch_array($run_vcode);
#vat inc ... recalculate the amts
$setvatamt = sprint($setamt[$t] * ($vd['vat_amount'] / (100 + $vd['vat_amount'])));
$setamt[$t] = sprint($setamt[$t] - $setvatamt);
$vatacc = gethook("accnum", "salesacc", "name", "VAT", "VAT");
$svattot = sprint($setamt[$t] + $setvatamt - ($setamt[$t] + $setvatamt) * 2);
$svatamt = sprint($setvatamt - $setvatamt * 2);
#process the vat amt ...
writetrans($vatacc, $dept['debtacc'], $accdate[$t], $refnum, $setvatamt, "VAT Received on Settlement Discount for Customer : {$cus['cusname']} {$cus['surname']}");
vatr($vd['id'], $accdate[$t], "OUTPUT", $vd['code'], $refnum, "VAT for Settlement Discount for Customer : {$cus['cusname']} {$cus['surname']}", $svattot, $svatamt);
} else {
#no vat for set amt ... do nothing
$setvatamt = 0;
$svattot = 0;
$svatamt = 0;
}
writetrans($setaccid, $dept['debtacc'], $accdate[$t], $refnum, sprint($setamt[$t]), "Settlement Discount For {$cus['cusname']} {$cus['surname']}");
custledger($cus['cusnum'], $bank_acc[$t], $sdate[$t], "{$refnum}", "Payment Settlement Discount Received.", sprint($setamt[$t] + $setvatamt), "c");
$sql = "\n\t\t\t\tINSERT INTO cubit.stmnt (\n\t\t\t\t\tcusnum, invid, amount, date, \n\t\t\t\t\ttype, div, allocation_date\n\t\t\t\t) VALUES (\n\t\t\t\t\t'{$cus['cusnum']}', '0', '" . $svattot . "', '{$sdate[$t]}', \n\t\t\t\t\t'Settlement Discount for Payment. Ref {$refnum}', '" . USER_DIV . "', '{$accdate[$t]}'\n\t\t\t\t)";
$stmntRslt = db_exec($sql) or errDie("Unable to insert statement record in Cubit.", SELF);
db_connect();
#record this paid settlement discount for reporting ...
$settl_sql = "\n\t\t\t\tINSERT INTO settlement_cus (\n\t\t\t\t\tcustomer, amt, setamt, setvatamt, setvat, \n\t\t\t\t\tsetvatcode, tdate, sdate, refnum\n\t\t\t\t) VALUES (\n\t\t\t\t\t'{$cus['cusnum']}', '{$amt[$t]}', '{$setamt[$t]}', '{$setvatamt}', '{$setvat[$t]}', \n\t\t\t\t\t'{$setvatcode[$t]}', '{$accdate[$t]}', 'now', '{$refnum[$t]}'\n\t\t\t\t)";
$run_settl = db_exec($settl_sql) or errDie("Unable to get debtor settlement information.");
}
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 Receipt</th>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>Bank Receipt added to cash book.</td>\n\t\t\t</tr>\n\t\t</table>";
$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'>" . mkQuickLinks(ql("bank-pay-add.php", "Add Bank Payment"), ql("bank-recpt-add.php", "Add Bank Receipt"), ql("bank-recpt-inv.php", "Add Customer Payment"), ql("cashbook-view.php", "View Cash Book")) . "\n\t\t\t\t</td>\n\t\t\t</tr>\n\t\t</table>";
return $OUTPUT;
}
示例15: write
function write($_POST)
{
#get vars
extract($_POST);
# validate input
require_lib("validate");
$v = new validate();
$v->isOk($purid, "num", 1, 20, "Invalid Order number.");
$v->isOk($refno, "string", 0, 255, "Invalid Delivery Reference number.");
$v->isOk($remarks, "string", 0, 255, "Invalid Remarks.");
# used to generate errors
$error = "asa@";
# display errors, if any
$err = "";
if ($v->isError()) {
$errors = $v->getErrors();
foreach ($errors as $e) {
$err .= "<li class='err'>" . $e["msg"] . "</li>";
}
return details($_POST, $err);
}
# Get Order info
db_connect();
$sql = "SELECT * FROM purch_int WHERE purid = '{$purid}' AND div = '" . USER_DIV . "'";
$purRslt = db_exec($sql) or errDie("Unable to get Order information");
if (pg_numrows($purRslt) < 1) {
return "<li>- Order Not Found</li>";
}
$pur = pg_fetch_array($purRslt);
# CHECK IF THIS DATE IS IN THE BLOCKED RANGE
$blocked_date_from = getCSetting("BLOCKED_FROM");
$blocked_date_to = getCSetting("BLOCKED_TO");
if (strtotime($pur['pdate']) >= strtotime($blocked_date_from) and strtotime($pur['pdate']) <= strtotime($blocked_date_to) and !user_is_admin(USER_ID)) {
return "<li class='err'>Period Range Is Blocked. Only an administrator can process entries within this period.</li>";
}
# check if Order has been received
if ($pur['invcd'] == "y") {
$error = "<li class='err'> Error : purchase number <b>{$pur['purnum']}</b> has already been invoiced.</li>";
$error .= "<p><input type='button' onClick='JavaScript:history.back();' value='« Correct submission'>";
return $error;
}
# Get selected supplier info
db_connect();
$sql = "SELECT * FROM suppliers WHERE supid = '{$pur['supid']}' AND div = '" . USER_DIV . "'";
$supRslt = db_exec($sql) or errDie("Unable to get customer information");
if (pg_numrows($supRslt) < 1) {
// code here
} else {
$sup = pg_fetch_array($supRslt);
}
# get department
db_conn("exten");
$sql = "SELECT * FROM departments WHERE deptid = '{$pur['deptid']}' AND div = '" . USER_DIV . "'";
$deptRslt = db_exec($sql);
if (pg_numrows($deptRslt) < 1) {
$dept['deptname'] = "<i class=err>Not Found</i>";
} else {
$dept = pg_fetch_array($deptRslt);
}
# Get warehouse name
db_conn("exten");
$sql = "SELECT * FROM warehouses WHERE div = '" . USER_DIV . "'";
$whRslt = db_exec($sql);
$wh = pg_fetch_array($whRslt);
# insert Order to DB
db_connect();
# begin updating
pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
/* --- Transactions --- */
db_conn(PRD_DB);
$refnum = getrefnum();
/* - Start Hooks - */
$vatacc = gethook("accnum", "salesacc", "name", "VAT");
$cvacc = gethook("accnum", "pchsacc", "name", "Cost Variance");
/* - End Hooks - */
# Record the payment on the statement
db_connect();
$sdate = date("Y-m-d");
$taxamt = $pur['tax'] * -1;
$ltotal = sprint($pur['total'] * $pur['xrate']);
$ltax = sprint($pur['tax'] * $pur['xrate']);
db_connect();
# update all supplies xchange rate first
xrate_update($pur['fcid'], $pur['xrate'], "suppurch", "id");
sup_xrate_update($pur['fcid'], $pur['xrate']);
db_connect();
# Update the supplier (make balance more)
$sql = "UPDATE suppliers SET balance = (balance + '{$ltotal}'), fbalance = (fbalance + '{$pur['total']}') WHERE supid = '{$pur['supid']}' AND div = '" . USER_DIV . "'";
$rslt = db_exec($sql) or errDie("Unable to update invoice in Cubit.", SELF);
$DAte = date("Y-m-d");
$sql = "INSERT INTO sup_stmnt(supid, edate, cacc, amount, descript, ref, ex, div) VALUES('{$pur['supid']}','{$pur['pdate']}', '{$dept['credacc']}','{$pur['total']}','International - Stock Received', '{$refnum}','{$pur['purnum']}', '" . USER_DIV . "')";
$stmntRslt = db_exec($sql) or errDie("Unable to insert statement record in Cubit.", SELF);
$Sl = "SELECT * FROM vatcodes WHERE id='{$pur['jobnum']}'";
$Ri = db_exec($Sl);
if (pg_num_rows($Ri) < 1) {
return "Please select the vatcode for all your stock.";
}
$vd = pg_fetch_array($Ri);
vatr($vd['id'], $pur['pdate'], "INPUT", $vd['code'], $refnum, "VAT for Purchase No. {$pur['purnum']}", -($ltotal + $ltax), -$ltax);
# Debit Stock Control and Credit Creditors control
//.........这里部分代码省略.........