本文整理汇总了PHP中pglib_transaction函数的典型用法代码示例。如果您正苦于以下问题:PHP pglib_transaction函数的具体用法?PHP pglib_transaction怎么用?PHP pglib_transaction使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pglib_transaction函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: pretake_update
function pretake_update()
{
extract($_REQUEST);
pglib_transaction("BEGIN");
$page = page_number($offset);
if (isset($new) && $new) {
$sql = "DELETE FROM cubit.stock_take";
db_exec($sql) or errDie("Unable to remove old stock take.");
}
$sql = "SELECT stkid FROM cubit.stock \n\t\t\tORDER BY stkcod ASC LIMIT {$limit} OFFSET {$offset}";
$stock_rslt = db_exec($sql) or errDie("Unable to retrieve stock.");
while (list($stkid) = pg_fetch_array($stock_rslt)) {
$sql = "INSERT INTO cubit.stock_take (stkid, page)\n\t\t\t\tVALUES ('{$stkid}', '{$page}')";
db_exec($sql) or errDie("Unable to add to stock take.");
}
$sql = "SELECT stkid FROM cubit.stock\n\t\t\tORDER BY stkcod ASC LIMIT {$limit} OFFSET {$offset}";
db_exec($sql) or errDie("Unable to retrieve stock take.");
$next_page = $page + 1;
$next_offset = page_offset($next_page);
if ($next_page <= total_pages()) {
$button = "<input type='submit' value='Page {$next_page}' />";
} else {
$button = "\n\t\t<input type='button' value='Post Stock Take'\n\t\tonclick='javascript:move(\"stock_take_post.php\")' />";
}
pglib_transaction("COMMIT");
$OUTPUT = "\n\t<script>\n\t\tprinter(\"" . SELF . "?key=pretake_print&offset={$offset}&limit={$limit}\");\n\t</script>\n\t<center>\n\t<h3>Pre Stock Take</h3>\n\t<form method='post' action='" . SELF . "'>\n\t<input type='hidden' name='key' value='pretake_update' />\n\t<input type='hidden' name='limit' value='{$limit}' />\n\t<input type='hidden' name='offset' value='{$next_offset}' />\n\t{$button}\n\t</form>\n\t</center>";
return $OUTPUT;
}
示例2: write
function write()
{
extract($_REQUEST);
pglib_transaction("BEGIN");
$sql = "DELETE FROM cubit.forecasts WHERE id='{$forecast_id}'";
db_exec($sql) or errDie("Unable to remove forecasts.");
$sql = "DELETE FROM cubit.forecast_items WHERE forecast_id='{$forecast_id}'";
db_exec($sql) or errDie("Unable to remove forecast items.");
pglib_transaction("COMMIT");
$OUTPUT = "<h3>Remove Saved Sales Forecast</h3>\n\t<table " . TMPL_tblDflts . ">\n\t\t<tr>\n\t\t\t<th>Remove</th>\n\t\t</tr>\n\t\t<tr class='" . bg_class() . "'>\n\t\t\t<td><li>Saved sales forecast removed successfully.</li></td>\n\t\t</tr>\n\t</table>";
return $OUTPUT;
}
示例3: select
function select()
{
global $ePRDMON;
pglib_transaction("BEGIN");
$sql = "SELECT * FROM cubit.employees";
mdbg($sql);
$rslt = db_exec($sql);
print "<xmp>";
print "employees to process: " . pg_num_rows($rslt) . "\n";
$empnum = 0;
while ($emp = pg_fetch_assoc($rslt)) {
print "processing employee number: " . ++$empnum . "\n";
flush();
ob_flush();
$sql = "SELECT * FROM \"3\".empledger WHERE empid='{$emp['empnum']}'";
mdbg($sql);
$ybrslt = db_exec($sql);
if (pg_num_rows($ybrslt) > 0) {
$yb = pg_fetch_assoc($ybrslt);
$p_dbal = $yb["dbalance"];
$p_cbal = $yb["cbalance"];
} else {
$p_dbal = 0;
$p_cbal = 0;
}
/* create the balance transactions */
for ($i = 1; $i <= 12; ++$i) {
$month = $ePRDMON[$i];
$sql = "SELECT * FROM \"{$month}\".empledger \n\t\t\t\t\tWHERE empid='{$emp['empnum']}'\n\t\t\t\t\tORDER BY edate,id";
$elrslt = db_exec($sql);
if (pg_num_rows($elrslt) <= 0) {
$sql = "INSERT INTO \"{$month}\".empledger (empid, contra, edate, ref, des,\n\t\t\t\t\t\t\tdebit, credit, dbalance, cbalance, sdate, div)\n\t\t\t\t\t\tVALUES('{$emp['empnum']}', '0', CURRENT_DATE, 0, 'Balance', '0', '0', \n\t\t\t\t\t\t\t'{$p_dbal}', '{$p_cbal}', CURRENT_DATE, 2)";
db_exec($sql);
} else {
while ($row = pg_fetch_assoc($elrslt)) {
$p_dbal += $row["debit"];
$p_cbal += $row["credit"];
if ($p_dbal >= $p_cbal) {
$p_dbal = $p_dbal - $p_cbal;
$p_cbal = 0;
} else {
$p_cbal = $p_cbal - $p_dbal;
$p_dbal = 0;
}
}
}
}
}
print "\nDone.";
print "</xmp>";
mdbg(false);
pglib_transaction("COMMIT");
}
示例4: complete
function complete()
{
extract($_REQUEST);
pglib_transaction("BEGIN");
$datetime = date("Y-m-d G:i:s");
$sql = "SELECT stkid, qty FROM cubit.stock_take";
$stock_rslt = db_exec($sql) or errDie("Unable to retrieve stock.");
while (list($stkid, $qty) = pg_fetch_array($stock_rslt)) {
$sql = "INSERT INTO cubit.stock_take_report (timestamp, stkid, qty)\n\t\t\t\tVALUES ('{$datetime}', '{$stkid}', '{$qty}')";
db_exec($sql) or errDie("Unable to add to report.");
}
$sql = "DELETE FROM cubit.stock_take";
db_exec($sql) or errDie("Unable to remove from stock take.");
pglib_transaction("COMMIT");
$OUTPUT = "\n\t<h3>Stock Take</h3>\n\t<table " . TMPL_tblDflts . ">\n\t\t<tr><th>Complete</th></tr>\n\t\t<tr class='" . bg_class() . "'>\n\t\t\t<td><li>Stock Take has successfully been completed.</td></li>\n\t\t</tr>\n\t</table>";
return $OUTPUT;
}
示例5: posttake_update
function posttake_update()
{
extract($_REQUEST);
pglib_transaction("BEGIN");
foreach ($qty as $stkid => $value) {
$sql = "SELECT stkid FROM cubit.stock_take WHERE stkid='{$stkid}'";
$stktake_rslt = db_exec($sql) or errDie("Unable to retrieve stock take.");
if (is_numeric($qty[$stkid])) {
if (pg_num_rows($stktake_rslt)) {
$sql = "UPDATE cubit.stock_take SET qty='{$qty[$stkid]}' WHERE stkid='{$stkid}'";
}
}
db_exec($sql) or errDie("Unable to add to stock take.");
}
pglib_transaction("COMMIT");
return posttake_display();
}
示例6: invoice
function invoice()
{
extract($_REQUEST);
pglib_transaction("BEGIN");
$invnum = divlastid("inv");
$sql = "INSERT INTO cubit.invoices(deptid, chrgvat, odate, printed, done, \n\t\t\t\tusername, prd, invnum, div, systime, pslip_sordid, cusnum, ordno)\n\t\t\tVALUES ('" . USER_DIV . "', 'inc', current_date, 'n', 'n',\n\t\t\t\t'" . USER_NAME . "', '" . PRD_DB . "', '{$invnum}', '" . USER_DIV . "',\n\t\t\t\tcurrent_date, '{$sordid}', '{$cusnum}', '{$sordid}')";
$inv_rslt = db_exec($sql) or errDie("Unable to retrieve invoice.");
$invid = lastinvid();
$sql = "SELECT stock.stkid, stock.whid, qty, sorders_items.vatcode, amt, unitcost\n\t\t\tFROM cubit.sorders_items\n\t\t\t\tLEFT JOIN cubit.stock ON sorders_items.stkid=stock.stkid\n\t\t\tWHERE sordid='{$sordid}'";
$stock_rslt = db_exec($sql) or errDie("Unable to retrieve stock.");
while (list($stkid, $whid, $qty, $vatcode, $amt, $unitcost) = pg_fetch_array($stock_rslt)) {
$sql = "INSERT INTO cubit.inv_items (invid, whid, stkid, qty, div,\n\t\t\t\t\tvatcode, amt, unitcost)\n\t\t\t\tVALUES ('{$invid}', '{$whid}', '{$stkid}', '{$qty}', '" . USER_DIV . "',\n\t\t\t\t\t'{$vatcode}', '{$amt}', '{$unitcost}')";
db_exec($sql) or errDie("Unable to add inventory items.");
}
$OUTPUT = "\n\t<script>\n\t\tmove(\"../cust-credit-stockinv-no-neg.php?invid={$invid}&cont=true\");\n\t</script>";
pglib_transaction("COMMIT");
return $OUTPUT;
}
示例7: save
function save()
{
extract($_REQUEST);
pglib_transaction("BEGIN");
if (isset($asset)) {
foreach ($asset as $id) {
$sql = "SELECT id FROM hire.basis_prices WHERE assetid='{$id}'";
$bp_rslt = db_exec($sql) or errDie("Unable to retrieve basis.");
if (pg_num_rows($bp_rslt)) {
$bp_id = pg_fetch_result($bp_rslt, 0);
$sql = "UPDATE hire.basis_prices SET per_hour='{$hour[$id]}',\r\n\t\t\t\t\t\t\tper_day='{$day[$id]}', per_week='{$week[$id]}'\r\n\t\t\t\t\t\t\tWHERE id='{$bp_id}'";
} else {
$sql = "INSERT INTO hire.basis_prices (assetid, per_hour,\r\n\t\t\t\t\t\t\tper_day, per_week)\r\n\t\t\t\t\t\t\tVALUES ('{$id}', '{$hour[$id]}', '{$day[$id]}',\r\n\t\t\t\t\t\t\t\t'{$week[$id]}')";
}
db_exec($sql) or errDie("Unable to update basis prices.");
}
}
pglib_transaction("COMMIT");
$msg = "<tr class='" . bg_class() . "'>\r\n\t\t<td colspan='6'><li>Successfully saved the default basis prices.</li>\r\n\t</tr>";
return display($msg);
}
示例8: save
function save()
{
extract($_REQUEST);
print "<xmp>";
print_r($_REQUEST);
print "</xmp>";
pglib_transaction("BEGIN");
if (isset($blocked)) {
foreach ($blocked as $stkid) {
$sql = "UPDATE cubit.stock SET blocked='y' WHERE stkid='{$stkid}'";
db_exec($sql) or errDie("Unable to update stock.");
}
}
if (isset($count)) {
foreach ($count as $stkid => $value) {
$sql = "UPDATE cubit.stock SET units='{$value}' WHERE stkid='{$stkid}'";
db_exec($sql) or errDie("Unable to update stock.");
}
}
pglib_transaction("COMMIT");
return display();
}
示例9: save
function save()
{
extract($_REQUEST);
pglib_transaction("BEGIN");
foreach ($days as $asset_id => $days) {
$sql = "UPDATE cubit.assets SET days='{$days}' WHERE id='{$asset_id}'";
db_exec($sql) or errDie("Unable to update service days.");
$secs = $days * 60 * 60 * 24;
$svdate = date("Y-m-d", time() + $days);
$sql = "SELECT * FROM cubit.asset_svdates\r\n\t\t\t\tWHERE asset_id='{$asset_id}'";
$svdate_rslt = db_exec($sql) or errDie("Unable to retrieve days.");
if (!pg_num_rows($svdate_rslt)) {
$sql = "INSERT INTO cubit.asset_svdates (asset_id, svdate, des)\r\n\t\t\t\t\tVALUES ('{$asset_id}', '{$svdate}', '{$description[$asset_id]}')";
} else {
$sv_data = pg_fetch_array($svdate_rslt);
$sql = "UPDATE cubit.asset_svdates SET svdate='{$svdate}',\r\n\t\t\t\t\t\tdescription='{$description[$asset_id]}'\r\n\t\t\t\t\tWHERE id='{$sv_data['id']}'";
}
}
db_exec($sql) or errDie("Unable to update service history.");
pglib_transaction("COMMIT");
$message = "<li class='yay'>\r\n\t\t\t\t\tSuccessfully saved service days.\r\n\t\t\t\t</li>";
return display($message);
}
示例10: write
function write()
{
extract($_REQUEST);
pglib_transaction("BEGIN");
if (is_uploaded_file($_FILES["file"]["tmp_name"])) {
$file = "";
$fp = fopen($_FILES["file"]["tmp_name"], "rb");
while (!feof($fp)) {
// fread is binary safe
$file .= fread($fp, 1024);
}
fclose($fp);
# base 64 encoding
$file = base64_encode($file);
$sql = "DELETE FROM hire.unsigned_hirenotes WHERE id='{$uh_id}'";
db_exec($sql) or errDie("Unable to remove from unsigned hirenotes.");
$sql = "INSERT INTO hire.signed_hirenotes (invid, file_name, file_type, file)\r\n\t\t\t\tVALUES ('{$invid}', '" . $_FILES["file"]["name"] . "',\r\n\t\t\t\t\t'" . $_FILES["file"]["type"] . "', '{$file}')";
db_exec($sql) or errDie("Unable to retrieve scanned signed hire notes.");
}
pglib_transaction("COMMIT");
$OUTPUT = "\r\n\t<script>\r\n\t\tparent.document.reload();\r\n\t</script>\r\n\t<h3>Signed Hire Note</h3>\r\n\t<table " . TMPL_tblDflts . ">\r\n\t\t<tr>\r\n\t\t\t<th>Write</th>\r\n\t\t</tr>\r\n\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t<td><li>Successfully saved signed hire note</li></td>\r\n\t\t</tr>\r\n\t</table>";
return $OUTPUT;
}
示例11: write
//.........这里部分代码省略.........
$error = "<li class=err> Error : Invoice number <b>{$invid}</b> has already been printed.";
$error .= "<p><input type=button onClick='JavaScript:history.back();' value='« Correct submission'>";
return $error;
}
# Get selected customer info
db_connect();
$sql = "SELECT * FROM customers WHERE cusnum = '{$cusnum}' AND div = '" . USER_DIV . "'";
$custRslt = db_exec($sql) or errDie("Unable to get customer information");
if (pg_numrows($custRslt) < 1) {
$sql = "SELECT * FROM inv_data WHERE invid = '{$invid}' AND div = '" . USER_DIV . "'";
$custRslt = db_exec($sql) or errDie("Unable to get customer information data");
$cust = pg_fetch_array($custRslt);
$cust['cusname'] = $cust['customer'];
$cust['surname'] = "";
$cust['addr1'] = "";
} else {
$cust = pg_fetch_array($custRslt);
}
# get department
db_conn("exten");
$sql = "SELECT * FROM departments WHERE deptid = '{$inv['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);
}
# fix those nasty zeros
$traddisc += 0;
$delchrg += 0;
# insert invoice to DB
db_connect();
# begin updating
pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
/* -- Start remove old items -- */
# get selected stock in this invoice
db_connect();
$sql = "SELECT * FROM inv_items WHERE invid = '{$invid}' AND div = '" . USER_DIV . "'";
$stktRslt = db_exec($sql);
while ($stkt = pg_fetch_array($stktRslt)) {
# update stock(alloc + qty)
$sql = "UPDATE stock SET alloc = (alloc - '{$stkt['qty']}') WHERE stkid = '{$stkt['stkid']}' AND div = '" . USER_DIV . "'";
$rslt = db_exec($sql) or errDie("Unable to update stock to Cubit.", SELF);
}
# remove old items
$sql = "DELETE FROM inv_items WHERE invid='{$invid}' AND div = '" . USER_DIV . "'";
$rslt = db_exec($sql) or errDie("Unable to update invoice items in Cubit.", SELF);
/* -- End remove old items -- */
$taxex = 0;
if (isset($stkids)) {
foreach ($stkids as $keys => $value) {
if (isset($remprod)) {
if (in_array($keys, $remprod)) {
# skip product (wonder if $keys still align)
$amt[$keys] = 0;
continue;
} else {
# get selamt from selected stock
$sql = "SELECT * FROM stock WHERE stkid = '{$stkids[$keys]}' AND div = '" . USER_DIV . "'";
$stkRslt = db_exec($sql);
$stk = pg_fetch_array($stkRslt);
# Calculate the Discount discount
if ($disc[$keys] < 1) {
if ($discp[$keys] > 0) {
$disc[$keys] = $discp[$keys] / 100 * $unitcost[$keys];
}
示例12: 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>";
//.........这里部分代码省略.........
示例13: write
//.........这里部分代码省略.........
$sql = "SELECT * FROM departments WHERE deptid = '{$sup['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);
}
$supacc = $dept['credacc'];
}
} elseif (isset($deptid)) {
db_conn("exten");
$sql = "SELECT * FROM departments WHERE deptid = '{$deptid}'";
$deptRslt = db_exec($sql) or errDie("Unable to view customers");
if (pg_numrows($deptRslt) < 1) {
$error = "<li class='err'> Department not Found.";
$confirm .= "{$error}<p><input type='button' onClick='JavaScript:history.back();' value='« Correct submission'>";
return $confirm;
} else {
$dept = pg_fetch_array($deptRslt);
$supacc = $dept['pca'];
}
}
# check if purchase has been received
if ($pur['received'] == "y") {
$error = "<li class='err'> Error : purchase number <b>{$purid}</b> has already been received.</li>";
$error .= "<p><input type='button' onClick='JavaScript:history.back();' value='« Correct submission'>";
return $error;
}
$vatacc = gethook("accnum", "salesacc", "name", "VAT");
$cvacc = gethook("accnum", "pchsacc", "name", "Cost Variance");
# Insert purchase to DB
db_connect();
# begin updating
pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
$refnum = getrefnum();
/*refnum*/
db_connect();
if (isset($qtys)) {
# amount of stock in
$totstkamt = array();
$resub = 0;
# Get subtotal
foreach ($qtys as $keys => $value) {
# Skip zeros
if ($qtys[$keys] < 1) {
continue;
}
$amt[$keys] = $qtys[$keys] * $unitcost[$keys];
}
$SUBTOTAL = array_sum($amt);
$revat = 0;
foreach ($qtys as $keys => $value) {
# Get selected stock line
$sql = "SELECT * FROM nons_pur_items WHERE cod = '{$cod[$keys]}' AND purid = '{$purid}' AND div = '" . USER_DIV . "'";
$stkdRslt = db_exec($sql);
$stkd = pg_fetch_array($stkdRslt);
# Calculate cost amount bought
$amt[$keys] = $qtys[$keys] * $unitcost[$keys];
/* delivery charge */
# Calculate percentage from subtotal
$perc[$keys] = $amt[$keys] / $SUBTOTAL * 100;
# Get percentage from shipping charges
$shipc[$keys] = $perc[$keys] / 100 * $shipchrg;
# add delivery charges
$amt[$keys] += $shipc[$keys];
/* end delivery charge */
示例14: write_data
function write_data($_POST)
{
# get vars
extract($_POST);
# validate input
require_lib("validate");
$v = new validate();
$v->isOk($id, "num", 1, 9, "ID Field (hidden)");
$v->isOk($surname, "string", 1, 100, "Last name");
$v->isOk($name, "string", 0, 100, "First name");
$v->isOk($account_id, "num", 0, 9, "Account ID (hidden)");
$v->isOk($account_type, "string", 0, 100, "Account type (hidden)");
$v->isOk($lead_source, "string", 0, 100, "Lead Source");
$v->isOk($title, "string", 0, 100, "Title");
$v->isOk($department, "string", 0, 100, "Department");
$v->isOk($tell, "string", 0, 100, "Home Phone");
$v->isOk($cell, "string", 0, 100, "Mobile Phone");
$v->isOk($fax, "string", 0, 100, "Fax");
$v->isOk($tell_office, "string", 0, 100, "Office Phone");
$v->isOk($tell_other, "string", 0, 100, "Other Phone");
$v->isOk($email, "string", 0, 100, "Email");
$v->isOk($email_other, "string", 0, 100, "Other Email");
$v->isOk($assistant, "string", 0, 100, "Assistant");
$v->isOk($assistant_phone, "string", 0, 100, "Assistant Phone");
$v->isOk($padd, "string", 0, 250, "Physical Address");
$v->isOk($padd_city, "string", 0, 100, "Physical Address: City");
$v->isOk($padd_state, "string", 0, 100, "Physical Address: State/Province");
$v->isOk($padd_code, "string", 0, 100, "Physical Address: Postal Code");
$v->isOk($padd_country, "string", 0, 100, "Physical Address: Country");
$v->isOk($hadd, "string", 0, 250, "Postal Address");
$v->isOk($hadd_city, "string", 0, 100, "Postal Address: City");
$v->isOk($hadd_state, "string", 0, 100, "Postal Address: State/Province");
$v->isOk($hadd_code, "string", 0, 100, "Postal Address: Postal Code");
$v->isOk($hadd_country, "string", 0, 100, "Postal Address: Country");
$v->isOk($description, "string", 0, 100, "Description");
$v->isOk($website, "string", 0, 255, "Website");
$v->isOk($religion, "string", 0, 100, "Religion");
$v->isOk($race, "string", 0, 100, "Race");
$v->isOk($gender, "string", 0, 6, "Gender");
$v->isOk($Con, "string", 2, 3, "Invalid private.");
$v->isOk($salespn, "num", 1, 9, "Sales person.");
$v->isOk($team_id, "num", 1, 9, "Team");
if (!empty($ncdate_day) || !empty($ncdate_month) || !empty($ncdate_year)) {
$v->isOk($ncdate_day, "num", 1, 2, "Next contact date (Day)");
$v->isOk($ncdate_month, "num", 1, 2, "Next contact date (Month)");
$v->isOk($ncdate_year, "num", 4, 4, "Next contact date (Year)");
$ncdate = ", ncdate = '{$ncdate_year}-{$ncdate_month}-{$ncdate_day}'";
} else {
$ncdate = "";
}
$birthdate = "{$bf_year}-{$bf_month}-{$bf_day}";
if ($v->isOk($birthdate, "string", 1, 100, "Birthdate")) {
if (!checkdate($bf_month, $bf_day, $bf_year)) {
$v->addError("_OTHER", "Invalid birthdate. No such date exists.");
}
}
$birthdate_description = date("d F Y", mktime(0, 0, 0, $bf_day, $bf_month, $bf_year));
# display errors, if any
if ($v->isError()) {
$err = "The following field value errors occured:<br>";
$errors = $v->getErrors();
foreach ($errors as $e) {
if ($e["value"] == "_OTHER") {
$err .= "<li class='err'>{$e['msg']}</li>";
} else {
$err .= "<li class='err'>Invalid characters: {$e['msg']}</li>";
}
}
return get_data($_POST, $err);
}
db_conn('crm');
if (!pglib_transaction("BEGIN")) {
return "<li class='err'>Unable to edit lead(TB)</li>";
}
$Sl = "SELECT * FROM leads WHERE id='{$id}'";
$Ry = db_exec($Sl) or errDie("Unable to get lead details.");
if (pg_num_rows($Ry) < 1) {
return "Invalid lead.";
}
$cdata = pg_fetch_array($Ry);
if ($account_type == "Customer") {
db_conn("cubit");
$sql = "SELECT surname FROM customers WHERE cusnum='{$account_id}'";
$rslt = db_exec($sql) or errDie("Error reading account name (customers)");
if (pg_num_rows($rslt) > 0) {
$accountname = pg_fetch_result($rslt, 0, 0);
} else {
$account_id = 0;
$accountname = "";
$account_type = "";
}
} else {
if ($account_type == "Supplier") {
db_conn("cubit");
$sql = "SELECT supname FROM suppliers WHERE supid='{$account_id}'";
$rslt = db_exec($sql) or errDie("Error reading account name (suppliers)");
if (pg_num_rows($rslt) > 0) {
$accountname = pg_fetch_result($rslt, 0, 0);
} else {
$account_id = 0;
//.........这里部分代码省略.........
示例15: write
function write($_POST)
{
#get vars
foreach ($_POST as $key => $value) {
${$key} = $value;
}
# validate input
require_lib("validate");
$v = new validate();
$v->isOk($sordid, "num", 1, 20, "Invalid Sales Order number.");
# display errors, if any
$err = "";
if ($v->isError()) {
$errors = $v->getErrors();
foreach ($errors as $e) {
$err .= "<li class=err>" . $e["msg"];
}
return $err;
}
# Get Sales Order info
db_connect();
$sql = "SELECT * FROM corders WHERE sordid = '{$sordid}' AND accepted != 'c' AND div = '" . USER_DIV . "'";
$sordRslt = db_exec($sql) or errDie("Unable to get Sales Order information");
if (pg_numrows($sordRslt) < 1) {
return "<li class=err>Sales Order Not Found</li>";
}
$sord = pg_fetch_array($sordRslt);
# Get selected customer info
db_connect();
$sql = "SELECT * FROM customers WHERE cusnum = '{$sord['cusnum']}' AND div = '" . USER_DIV . "'";
$custRslt = db_exec($sql) or errDie("Unable to get customer information");
if (pg_numrows($custRslt) < 1) {
$sql = "SELECT * FROM cord_data WHERE sordid = '{$sordid}' AND div = '" . USER_DIV . "'";
$custRslt = db_exec($sql) or errDie("Unable to get customer information data");
$cust = pg_fetch_array($custRslt);
$cust['cusname'] = $cust['customer'];
$cust['surname'] = "";
$cust['addr1'] = "";
} else {
$cust = pg_fetch_array($custRslt);
}
/* - Start Copying - */
pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
# todays date (sql formatted)
$date = date("Y-m-d");
# get selected stock in this Sales Order
db_connect();
$sql = "SELECT * FROM corders_items WHERE sordid = '{$sordid}' AND div = '" . USER_DIV . "'";
$stkdRslt = db_exec($sql);
while ($stkd = pg_fetch_array($stkdRslt)) {
# update stock(alloc - qty)
$sql = "UPDATE stock SET alloc = (alloc - '{$stkd['qty']}') WHERE stkid = '{$stkd['stkid']}' AND div = '" . USER_DIV . "'";
$rslt = db_exec($sql) or errDie("Unable to update stock to Cubit.", SELF);
}
# remove the Sales Order
$sql = "DELETE FROM corders WHERE sordid = '{$sordid}' AND div = '" . USER_DIV . "'";
$rslt = db_exec($sql) or errDie("Unable to remove Sales Order from Cubit.", SELF);
#record (sordid, username, date)
$sql = "INSERT INTO cancelled_cord(sordid, deptid, username, date, deptname, div) VALUES('{$sordid}', '{$sord['deptid']}', '" . USER_NAME . "', '{$date}','{$sord['deptname']}', '" . USER_DIV . "')";
$rslt = db_exec($sql) or errDie("Unable to insert Sales Order record to Cubit.", SELF);
/* - End Copying - */
pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
// Final Laytout
$write = "\n\t<table border=0 cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "'>\n\t\t<tr><th>Consignement Order Cancelled</th></tr>\n\t\t<tr class='bg-even'><td>Consignment Order for customer <b>{$cust['cusname']} {$cust['surname']}</b> has been cancelled.</td></tr>\n\t</table>\n\t<p>\n\t<table border=0 cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "'>\n\t\t<tr><th>Quick Links</th></tr>\n\t\t<tr class='bg-odd'><td><a href='corder-view.php'>View Consignment Orders</a></td></tr>\n\t\t<script>document.write(getQuicklinkSpecial());</script>\n\t</table>";
return $write;
}