当前位置: 首页>>代码示例>>PHP>>正文


PHP pglib_lastid函数代码示例

本文整理汇总了PHP中pglib_lastid函数的典型用法代码示例。如果您正苦于以下问题:PHP pglib_lastid函数的具体用法?PHP pglib_lastid怎么用?PHP pglib_lastid使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了pglib_lastid函数的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";
}
开发者ID:andrecoetzee,项目名称:accounting-123.com,代码行数:93,代码来源:bank-recon.php

示例2: enterDeduct

function enterDeduct()
{
    # connect to db
    db_connect();
    # get last inserted id for new ref no
    // a little hack to make stoopid postgres not return a 1 as last id, when there is no last id
    if (pg_numrows(db_exec("SELECT 1 FROM salded")) < 1) {
        $lastid = 1;
    } else {
        $lastid = pglib_lastid("salded", "id") + 1;
    }
    $refno = "saldeduct" . sprintf("%02d", $lastid);
    $Tp = array("No" => "No", "Yes" => "Yes");
    $taxables = extlib_cpsel("taxable", $Tp, "No");
    $arrtype = array("Amount" => "Amount", "Percentage" => "Percentage");
    $seltype = extlib_cpsel("type", $arrtype, "Percentage");
    $check1 = "";
    $check2 = "";
    if (isset($type) and $type == "Percentage") {
        $check2 = "checked='yes'";
    } else {
        $check1 = "checked='yes'";
    }
    $enterDeduct = "\n\t\t<script>\n\t\t\tfunction inHouse() {\n\t\t\t\tfrm = getObjectById('dedfrm');\n\t\t\t\tfrm.creditor.value='In House';\n\t\t\t\tfrm.details.value='In House';\n\t\t\t}\n\t\t</script>\n\t\t<h3>New salary deduction</h3>\n\t\t<table " . TMPL_tblDflts . ">\n\t\t<form id='dedfrm' action='" . SELF . "' method='POST'>\n\t\t\t<input type='hidden' name='key' value='confirm'>\n\t\t\t<input type='hidden' name='refno' value='{$refno}'>\n\t\t\t<input type='hidden' name='catid' value='B10'>\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>Name of deduction</td>\n\t\t\t\t<td align='center'><input type='text' size='20' name='deduction'></td>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>Creditor name</td>\n\t\t\t\t<td align='center'><input type='text' size='20' name='creditor'></td>\n\t\t\t\t<td><input type='button' value='In House' onClick='inHouse();'></td>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>Reference no.</td>\n\t\t\t\t<td align='center'>{$refno}</td>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>Creditor Details/In House</td>\n\t\t\t\t<td align='center'><input type='text' size='20' name='details'></td>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>Before PAYE: Tax Deductable</td>\n\t\t\t\t<td align='center'>{$taxables}</td>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>Deduction Type</td>\n\t\t\t\t<td>\n\t\t\t\t\t<input type='radio' name='type' value='Amount' {$check1}> Amount\n\t\t\t\t\t<input type='radio' name='type' value='Percentage' {$check2}> Percent\n\t\t\t\t</td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td colspan='2' align='right'><input type='submit' value='Confirm &raquo;'></td>\n\t\t\t</tr>\n\t\t</form>\n\t\t</table>" . mkQuickLinks(ql("../admin-employee-add.php", "Add Employee"), ql("../admin-employee-view.php", "View Employees"));
    return $enterDeduct;
}
开发者ID:andrecoetzee,项目名称:accounting-123.com,代码行数:26,代码来源:salded-add.php

示例3: fromQuote

function fromQuote()
{
    extract($_REQUEST);
    $sql = "INSERT INTO cubit.pick_slips (user_id) VALUES ('" . USER_ID . "')";
    $ps_rslt = db_exec($sql) or errDie("Unable to retrieve slips.");
    $ps_id = pglib_lastid("cubit.pick_slips", "id");
    $sql = "SELECT * FROM cubit.quote_items WHERE quoid='{$quoid}'";
    $quote_rslt = db_exec($sql) or errDie("Unable to retrieve quote items.");
    while ($quote_data = pg_fetch_array($quote_rslt)) {
        $sql = "INSERT INTO cubit.pickslip_stk (pickslip_id, stock_id, qty)\n\t\t\t\tVALUES ('{$ps_id}', '{$quote_data['stkid']}', '{$quote_data['qty']}')";
        db_exec($sql) or errDie("Unable to add pickslip.");
    }
    header("Location: " . SELF . "?key=print&slip_id={$ps_id}");
}
开发者ID:andrecoetzee,项目名称:accounting-123.com,代码行数:14,代码来源:picking_slip.php

示例4: import_file

function import_file()
{
    extract($_REQUEST);
    $sql = "SELECT * FROM cubit.import_assets";
    $import_rslt = db_exec($sql) or errDie("Unable to retrieve import assets.");
    $counter = 0;
    while ($row = pg_fetch_array($import_rslt)) {
        $sql = "\r\n\t\t\tINSERT INTO cubit.assets (\r\n\t\t\t\tserial, locat, des, date, bdate, \r\n\t\t\t\tamount, div, grpid, accdep, dep_perc, \r\n\t\t\t\tdep_month, serial2, team_id, puramt, conacc, \r\n\t\t\t\tsaledate, saleamt, invid, autodepr_date, \r\n\t\t\t\tsdate, temp_asset, nonserial, type_id, \r\n\t\t\t\tsplit_from, days, on_hand, svdate\r\n\t\t\t) VALUES (\r\n\t\t\t\t'{$row['serial']}', '{$row['locat']}', '{$row['des']}', '{$row['date']}', '{$row['bdate']}', \r\n\t\t\t\t'{$row['amount']}', '{$row['div']}', '{$row['grpid']}', '{$row['accdep']}', '{$row['dep_perc']}', \r\n\t\t\t\t'{$row['dep_month']}', '{$row['serial2']}', '{$row['team_id']}', '{$row['puramt']}', '{$row['conacc']}', \r\n\t\t\t\t'{$row['saledate']}', '{$row['saleamt']}', '{$row['invid']}', '{$row['autodepr_date']}', \r\n\t\t\t\t'{$row['sdate']}', '{$row['temp_asset']}', '{$row['nonserial']}', '{$row['type_id']}', \r\n\t\t\t\t'{$row['split_from']}', '{$row['days']}', '{$row['on_hand']}', '{$row['svdate']}'\r\n\t\t\t)";
        db_exec($sql) or errDie("Unable to add asset.");
        $asset_id = pglib_lastid("cubit.assets", "id");
        $sql = "\r\n\t\t\tINSERT INTO hire.basis_prices (\r\n\t\t\t\tassetid, per_day, \r\n\t\t\t\tper_hour, per_week\r\n\t\t\t) VALUES (\r\n\t\t\t\t'{$asset_id}', '" . $per_day[$row["id"]] . "', \r\n\t\t\t\t'" . $per_hour[$row["id"]] . "', '" . $per_week[$row["id"]] . "'\r\n\t\t\t)";
        db_exec($sql) or errDie("Unable to add price.");
        $counter++;
    }
    return "{$counter} Assets Have Been Imported.";
}
开发者ID:andrecoetzee,项目名称:accounting-123.com,代码行数:16,代码来源:asset-import.php

示例5: write

function write()
{
    extract($_REQUEST);
    if (!preg_match("/(png|jpg|gif)\$/", $_FILES["file"]["name"])) {
        $msg = "<li class='err'>We only accept images of type png, jpg or gif</li>";
        return enter($sorder_num, $msg);
    }
    $fp = fopen($_FILES["file"]["tmp_name"], "rb");
    $buf = "";
    while (!feof($fp)) {
        $buf .= fread($fp, 1024);
    }
    $file = base64_encode($buf);
    $sql = "INSERT INTO cubit.pslip_signed_files (file) VALUES ('{$file}')";
    db_exec($sql) or errDie("Unable to add signed invoice.");
    $id = pglib_lastid("cubit.pslip_signed_files", "id");
    $sql = "\n\t\tINSERT INTO cubit.pslip_signed_index (\n\t\t\tid, file_name, file_type, sordid\n\t\t) VALUES (\n\t\t\t'{$id}', '" . $_FILES["file"]["name"] . "', '" . $_FILES["file"]["type"] . "', '{$sordid}'\n\t\t)";
    db_exec($sql) or errDie("Unable to add signed invoice index.");
    $OUTPUT = "\n\t\t<h3>Signed Invoice</h3>\n\t\t<table " . TMPL_tblDflts . ">\n\t\t\t<tr>\n\t\t\t\t<th>Write</th>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td><li>Signed Invoice Successfully Added.</li></td>\n\t\t\t</tr>\n\t\t</table>";
    return $OUTPUT;
}
开发者ID:andrecoetzee,项目名称:accounting-123.com,代码行数:21,代码来源:signed_invoices.php

示例6: enter

function enter()
{
    extract($_REQUEST);
    $sql = "SELECT * FROM hire.hire_invoices WHERE invid='{$_REQUEST['invid']}'";
    $inv_rslt = db_exec($sql) or errDie("Unable to retrieve invoices.");
    $inv_data = pg_fetch_array($inv_rslt);
    $sql = "SELECT * FROM cubit.customers WHERE cusnum='{$inv_data['cusnum']}'";
    $cust_rslt = db_exec($sql) or errDie("Unable to retrieve customers.");
    $cust_data = pg_fetch_array($cust_rslt);
    $sql = "SELECT invid FROM hire.unsigned_hirenotes WHERE invid='{$invid}'";
    $uh_rslt = db_exec($sql) or errDie("Unable to retrieve unsinged hirenotes.");
    if (!pg_num_rows($uh_rslt)) {
        $sql = "INSERT INTO hire.unsigned_hirenotes (invid, trans_date, invnum,\r\n\t\t\t\t\tcusnum)\r\n\t\t\t\tVALUES ('{$inv_data['invid']}', '{$inv_data['odate']}',\r\n\t\t\t\t\t'" . getHirenum($inv_data["invid"]) . "', '{$inv_data['cusnum']}')";
        db_exec($sql) or errDie("Unable to create unsigned hire note.");
        $uh_id = pglib_lastid("hire.unsigned_hirenotes", "id");
    } else {
        $uh_id = pg_fetch_result($uh_rslt, 0);
    }
    $OUTPUT = "<h3>Signed Hire Note</h3>\r\n\t<form method='post' action='" . SELF . "' enctype='multipart/form-data'>\r\n\t<input type='hidden' name='key' value='write' />\r\n\t<input type='hidden' name='invid' value='{$invid}' />\r\n\t<input type='hidden' name='uh_id' value='{$uh_id}' />\r\n\t<table " . TMPL_tblDflts . ">\r\n\t\t<tr>\r\n\t\t\t<th colspan='2'>Details</th>\r\n\t\t</tr>\r\n\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t<td>Hire No.</td>\r\n\t\t\t<td>H" . getHirenum($inv_data["invid"], 1) . "</td>\r\n\t\t</tr>\r\n\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t<td>Customer</td>\r\n\t\t\t<td>{$cust_data['cusname']} {$cust_data['surname']}</td>\r\n\t\t</tr>\r\n\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t<td>Signed Hire Note</td>\r\n\t\t\t<td><input type='file' name='file' /></td>\r\n\t\t</tr>\r\n\t\t<tr>\r\n\t\t\t<td colspan='2' align='right'>\r\n\t\t\t\t<input type='submit' value='Write &raquo' />\r\n\t\t\t</td>\r\n\t\t</tr>\r\n\t</table>\r\n\t</form>";
    return $OUTPUT;
}
开发者ID:andrecoetzee,项目名称:accounting-123.com,代码行数:21,代码来源:signed_hirenote_save.php

示例7: display

function display()
{
    extract($_REQUEST);
    $doc_output = "\n\t<div style='width: 95%; background: #fff; border: 1px solid #000'>\n\t\t{$bodydata}\n\t</div>";
    $size = sizeof($bodydata);
    $document = base64_encode($bodydata);
    if (!$id) {
        $sql = "INSERT INTO cubit.documents (title, filename, status, team_id, wordproc)\n\t\tVALUES ('{$title}', '{$title}.html', 'active', '{$team_id}', 1)";
        db_exec($sql) or errDie("Unable to save document.");
        db_conn("cubit");
        $docid = pglib_lastid("documents", "docid");
    } else {
        $sql = "UPDATE cubit.documents\n\t\t\t\tSET title='{$title}', filename='{$title}.html', team_id='{$team_id}'\n\t\t\t\tWHERE docid='{$id}'";
        $doc_rslt = db_exec($sql) or errDie("Unable to save document.");
        $docid = $id;
    }
    $sql = "INSERT INTO cubit.document_files (doc_id, filename, file, size)\n\tVALUES ('{$docid}', '{$title}.html', '{$document}', '{$size}')";
    db_exec($sql) or errDie("Unable to save document.");
    $OUTPUT = "\n\tDocument Successfully Saved<br />\n\t{$doc_output}";
    return $OUTPUT;
}
开发者ID:kumarsivarajan,项目名称:accounting-123,代码行数:21,代码来源:word_proc.php

示例8: create_dummy

function create_dummy($deptid, $spurnum, $spurtype, $spurprd)
{
    db_connect();
    # Dummy Vars
    $remarks = "";
    $supaddr = "";
    $terms = "0";
    $total = 0;
    $subtot = 0;
    $pdate = date("Y-m-d");
    $ddate = date("Y-m-d");
    $shipchrg = "0.00";
    $purnum = divlastid("pur", USER_DIV);
    # Insert purchase to DB
    $sql = "INSERT INTO nons_purchases(deptid, supplier, supaddr, terms, pdate, ddate, shipchrg, subtot, total, balance, vatinc, vat, remarks, received, done, prd, div, purnum, spurnum, spurtype, spurprd)";
    $sql .= " VALUES('{$deptid}', '',  '{$supaddr}', '{$terms}', '{$pdate}', '{$ddate}', '{$shipchrg}', '{$subtot}', '{$total}', '{$total}', 'yes', '0', '{$remarks}', 'n', 'n', '" . PRD_DB . "', '" . USER_DIV . "', '{$purnum}', '{$spurnum}', '{$spurtype}', '{$spurprd}')";
    $rslt = db_exec($sql) or errDie("Unable to insert Non-Stock Purchase to Cubit.", SELF);
    # Get next ordnum
    $purid = pglib_lastid("nons_purchases", "purid");
    return $purid;
}
开发者ID:andrecoetzee,项目名称:accounting-123.com,代码行数:21,代码来源:lnons-purch-new-b.php

示例9: enterDeduct

function enterDeduct()
{
    # connect to db
    core_connect();
    $dedcat = "<select name='catid'>";
    $sql = "SELECT * FROM balance WHERE div = '" . USER_DIV . "'";
    $catRslt = db_exec($sql);
    if (pg_numrows($catRslt) < 1) {
        return "<li> There are no Balance Accounts categories yet in Cubit.";
    } else {
        while ($cat = pg_fetch_array($catRslt)) {
            if ($cat["catname"] == "Balance") {
                $selected = "selected";
            } else {
                $selected = "";
            }
            $dedcat .= "<option value='{$cat['catid']}' {$selected}>{$cat['catname']}</option>";
        }
    }
    $dedcat .= "</select>";
    # connect to db
    db_connect();
    # get last inserted id for new ref no
    // a little hack to make stoopid postgres not return a 1 as last id, when there is no last id
    if (pg_numrows(db_exec("SELECT 1 FROM salded")) < 1) {
        $lastid = 1;
    } else {
        $lastid = pglib_lastid("salded", "id") + 1;
    }
    $refno = "saldeduct" . sprintf("%02d", $lastid);
    $Tp = array("No" => "No", "Yes" => "Yes");
    $taxables = extlib_cpsel("taxable", $Tp, "No");
    $arrtype = array("Amount" => "Amount", "Percentage" => "Percentage");
    $seltype = extlib_cpsel("type", $arrtype, "Percentage");
    $enterDeduct = "<h3>New salary deduction</h3>\n        <table cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "'>\n        <form action='" . SELF . "' method=post>\n        <input type=hidden name=key value=confirm>\n        <input type=hidden name=refno value='{$refno}'>\n        <tr><th>Field</th><th>Value</th></tr>\n        <tr class='bg-odd'><td>Name of deduction</td><td align=center><input type=text size=20 name=deduction></td></tr>\n        <tr class='bg-even'><td>Creditor name</td><td align=center><input type=text size=20 name=creditor></td></tr>\n        <tr class='bg-odd'><td>Reference no.</td><td align=center>{$refno}</td></tr>\n\t<tr class='bg-even'><td>Account Category</td><td align=center>{$dedcat}</td></tr>\n\t<tr class='bg-odd'><td>Creditor details</td><td align=center><input type=text size=20 name=details></td></tr>\n\t<tr class='bg-even'><td>Deduct Before PAYE</td><td align=center>{$taxables}</td></tr>\n\t<tr class='bg-odd'><td>Deduction Type</td><td>{$seltype}</td></tr>\n\n\t<tr><td colspan=2 align=right><input type=submit value='Confirm &raquo;'></td></tr>\n        </form></table>" . mkQuickLinks(ql("../admin-employee-add.php", "Add Employee"), ql("../admin-employee-view.php", "View Employees"));
    return $enterDeduct;
}
开发者ID:andrecoetzee,项目名称:accounting-123.com,代码行数:37,代码来源:fringe-add.php

示例10: create

function create($topacc, $accnum, $accname, $catid, $acctype, $vat)
{
    # Check Account name on selected type and category
    $sql = "SELECT * FROM accounts WHERE topacc = '{$topacc}' AND accnum = '{$accnum}'";
    $cRslt = db_exec($sql) or errDie("Unable to retrieve Account details from database.");
    if (pg_numrows($cRslt) > 0) {
        return 1;
    }
    $sql = "SELECT * FROM accounts WHERE accname = '{$accname}'";
    $cRslt = db_exec($sql) or errDie("Unable to retrieve Account details from database.");
    if (pg_numrows($cRslt) > 0) {
        return 2;
    }
    # write to DB
    $Sql = "INSERT INTO accounts (topacc, accnum, accname, acctype, catid, vat) VALUES ('{$topacc}', '{$accnum}', '{$accname}', '{$acctype}', '{$catid}', '{$vat}')";
    $accRslt = db_exec($Sql) or errDie("Unable to add Account to Database.", SELF);
    # get last inserted id for new acc
    $accid = pglib_lastid("accounts", "accid");
    # insert account into trial Balance
    $query = "INSERT INTO trial_bal(accid, topacc, accnum, accname, vat) VALUES('{$accid}', '{$topacc}', '{$accnum}', '{$accname}', '{$vat}')";
    $trialRslt = db_exec($query);
    # return Zero on success
    return 0;
}
开发者ID:andrecoetzee,项目名称:accounting-123.com,代码行数:24,代码来源:create.php

示例11: scan

function scan()
{
    // Check setting
    $sql = "SELECT set FROM cubit.picking_slip_setting";
    $setting_rslt = db_exec($sql) or errDie("Unable to retrieve setting.");
    $setting = pg_fetch_result($setting_rslt, 0);
    if ($setting == "n") {
        header("Location: picking_slip_settings.php");
    }
    $invoice = array("invoice" => "Scan Invoice");
    list($barcode) = array_values(flashRed($invoice));
    $sordid = decrypt_barcode($barcode);
    if (empty($sordid) || !is_numeric($sordid)) {
        $sordid = 0;
    }
    // Has this invoice been scanned before
    $sql = "SELECT id FROM cubit.pslip_scans WHERE sordid='{$sordid}'";
    $scan_rslt = db_exec($sql) or errDie("Unable to retrieve scans.");
    $sql = "SELECT sordid FROM cubit.sorders WHERE sordid='{$sordid}'";
    $sorder_rslt = db_exec($sql) or errDie("Unable to retrieve sales order.");
    if (pg_num_rows($sorder_rslt)) {
        $reason = "";
        if (pg_num_rows($scan_rslt)) {
            $reason = "DUPLICATE (No reason)";
        }
        $sql = "\n\t\t\tINSERT INTO cubit.pslip_scans (\n\t\t\t\tsordid, timestamp, userid, reason\n\t\t\t) VALUES (\n\t\t\t\t'{$sordid}', current_timestamp, '" . USER_ID . "', '{$reason}'\n\t\t\t)";
        db_exec($sql) or errDie("Unable to record scan.");
    } else {
        return scan_error();
    }
    if (pg_num_rows($scan_rslt)) {
        $scan_id = pglib_lastid("cubit.pslip_scans", "id");
        return reason($scan_id);
    }
    return dispatch($sordid);
}
开发者ID:andrecoetzee,项目名称:accounting-123.com,代码行数:36,代码来源:dispatch.php

示例12: write_sets


//.........这里部分代码省略.........
    $firstmonth = $smonth;
    $activeyear = $yrname;
    $sql = "\n\t\tINSERT INTO core.range (\n\t\t\t\"start\", \"end\", div\n\t\t) VALUES (\n\t\t\t'{$smonth}', '{$endmon}', '" . USER_DIV . "'\n\t\t)";
    $Rslt = db_exec($sql) or errDie("Unable to insert year range", SELF);
    $sql = "SELECT * FROM core.year WHERE yrname='{$yrname}'";
    $yrs = db_exec($sql);
    $yr = pg_fetch_array($yrs);
    if ($yr['closed'] == 'y') {
        return "<center><li class='err'>ERROR : The Selected Financial year : <b>{$yrname}</b> has been closed.\n\t\t<p><input type='button' onClick='JavaScript:history.back();' value='&laquo; Correct submission'>";
    }
    $yrdb = $yr['yrdb'];
    $sql = "SELECT * FROM core.range";
    $Rslt = db_exec($sql);
    if (pg_numrows($Rslt) < 1) {
        $OUTPUT = "<center><li class='err'>ERROR : The Financial year Period range was not found on Database, Please make sure that everything is set during instalation.</li>";
        require "template.php";
    }
    $range = Pg_fetch_array($Rslt);
    // Months array
    $months = array("dummy", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
    $sql = "INSERT INTO core.active (yrdb, yrname, prddb, prdname, div) VALUES ('{$yrdb}', '{$yrname}', '{$range['start']}', '" . $months[$range['start']] . "', '" . USER_DIV . "')";
    $rslt = db_exec($sql) or errDie("Could not Set Next Year Database and Name", SELF);
    db_conn("exten");
    $sql = "INSERT INTO departments (deptno, deptname, incacc, debtacc, credacc, pia, pca, div) VALUES ('1', 'Ledger 1', '{$sales_account}', '{$deptors_account}', '{$creditors_account}', '{$pos_sales_account}', '{$pos_cash_account}', '" . USER_DIV . "')";
    $deptRslt = db_exec($sql) or errDie("Unable to add deparment to system.", SELF);
    $sql = "INSERT INTO salespeople (salespno, salesp, div) VALUES ('1', 'General', '" . USER_DIV . "')";
    $salespRslt = db_exec($sql) or errDie("Unable to add warehouse to system.", SELF);
    $sql = "INSERT INTO  categories (category, div) VALUES ('General', '" . USER_DIV . "')";
    $catRslt = db_exec($sql) or errDie("Unable to add category to system.", SELF);
    $sql = "INSERT INTO  class (classname, div) VALUES ('General', '" . USER_DIV . "')";
    $catRslt = db_exec($sql) or errDie("Unable to add fringe benefit to system.", SELF);
    $sql = "INSERT INTO warehouses (whno, whname, stkacc, cosacc, conacc, div) VALUES ('1', 'Store 1', '{$stock_account}', '{$cost_account}', '{$stock_control}', '" . USER_DIV . "')";
    $whouseRslt = db_exec($sql) or errDie("Unable to add warehouse to system.", SELF);
    $whid = pglib_lastid("warehouses", "whid");
    $sql = "INSERT INTO  pricelist (listname, div) VALUES ('Standard', '" . USER_DIV . "')";
    db_exec($sql) or errDie("Unable to price list to system.", SELF);
    $sql = "INSERT INTO cubit.stockcat (catcod, cat, descript, div) VALUES('1', 'General', 'General Stock Category', '" . USER_DIV . "')";
    db_exec($sql) or errDie("Unable to insert stock category to Cubit.", SELF);
    $sql = "INSERT INTO cubit.stockclass (classcode, classname, div) VALUES ('1', 'General', '" . USER_DIV . "')";
    db_exec($sql) or errDie("Unable to add class to system.", SELF);
    $sql = "SELECT label FROM cubit.set WHERE label = 'DEF_WH' AND div = '" . USER_DIV . "'";
    $rslt = db_exec($sql) or errDie("Unable to check database for existing settings.");
    if (pg_num_rows($rslt) > 0) {
        $sql = "UPDATE cubit.set SET value = '{$whid}', type = 'Default Warehouse' WHERE label = 'DEF_WH' AND div = '" . USER_DIV . "'";
    } else {
        $sql = "INSERT INTO cubit.set (type, label, value, descript, div) VALUES('Default Warehouse', 'DEF_WH', '{$whid}', '1 &nbsp;&nbsp;&nbsp; Store1', '" . USER_DIV . "')";
    }
    db_exec($sql) or errDie("Unable to insert settings to Cubit.");
    $sql = "SELECT label FROM cubit.set WHERE label = 'SELAMT_VAT' AND div = '" . USER_DIV . "'";
    $rslt = db_exec($sql) or errDie("Unable to check database for existing settings.");
    if (pg_num_rows($rslt) > 0) {
        $sql = "UPDATE cubit.set SET value = 'inc', descript = 'Vat Inclusive' WHERE label = 'SELAMT_VAT' AND div = '" . USER_DIV . "'";
    } else {
        $sql = "INSERT INTO cubit.set (type, label, value, descript, div) VALUES('Vat type on stock selling price', 'SELAMT_VAT', 'inc', 'Vat Inclusive', '" . USER_DIV . "')";
    }
    db_exec($sql) or errDie("Unable to insert settings to Cubit.");
    $sql = "INSERT INTO cubit.currency (symbol,curcode,descrip,rate,def) VALUES ('R','ZAR', 'Rand',0.00,'')";
    db_exec($sql) or errDie("Unable to insert currency.");
    $sql = "\n\t\tINSERT INTO cubit.bankacct (\n\t\t\tacctype, bankname, branchname, branchcode, accname, \n\t\t\taccnum, details, div, btype, \n\t\t\tfcid, currency\n\t\t) VALUES (\n\t\t\t'Cheque', 'Bank', 'Branch', '000000', 'Account Name', \n\t\t\t'000000000000', 'Default bank Account', '" . USER_DIV . "', 'loc', \n\t\t\t(SELECT fcid FROM cubit.currency WHERE curcode='ZAR' LIMIT 1), 'Rand'\n\t\t)";
    db_exec($sql) or errDie("Unable to add bank account to database.");
    $accid = pglib_lastid("cubit.bankacct", "bankid");
    $sql = "INSERT INTO cubit.set (type, label, value, descript, div)\n\t\t\tVALUES('Banking Details Account', 'BANK_DET', '3', 'Bank Account: Account Name - Bank', '" . USER_DIV . "')";
    db_exec($sql) or errDie("Unable to set default bank account.");
    $hook = "INSERT INTO core.bankacc (accid, accnum, div) VALUES('{$accid}', '{$bank_account}', '" . USER_DIV . "')";
    $Rlst = db_exec($hook) or errDie("Unable to add link for for new bank account", SELF);
    $sql = "INSERT INTO crm.links (name,script) VALUES ('Add Client','../customers-new.php')";
开发者ID:andrecoetzee,项目名称:accounting-123.com,代码行数:67,代码来源:setup.php

示例13: write

function write($_POST)
{
    # Get vars
    foreach ($_POST as $key => $value) {
        ${$key} = $value;
    }
    # validate input
    require_lib("validate");
    $v = new validate();
    $v->isOk($budname, "string", 1, 255, "Invalid Budget Name.");
    $v->isOk($budtype, "string", 1, 20, "Invalid Budget type.");
    $v->isOk($budfor, "string", 1, 20, "Invalid Budget for option.");
    $v->isOk($fromprd, "string", 1, 20, "Invalid Budget period.");
    $v->isOk($toprd, "string", 1, 20, "Invalid Budget period.");
    if ($budfor == 'acc') {
        if (isset($accids)) {
            foreach ($accids as $akey => $accid) {
                $v->isOk($accid, "num", 1, 50, "Invalid Account number.");
                foreach ($amts[$accid] as $skey => $amtr) {
                    $v->isOk($amts[$accid][$skey], "float", 1, 20, "Invalid Budget amount.");
                }
            }
        } else {
            $v->isOk("#", "num", 0, 0, "Error : please select at least one account.");
        }
    } elseif ($budfor == 'cost') {
        if (isset($ccids)) {
            foreach ($ccids as $akey => $ccid) {
                $v->isOk($ccid, "num", 1, 50, "Invalid Cost Center.");
                foreach ($amts[$ccid] as $skey => $amtr) {
                    $v->isOk($amts[$ccid][$skey], "float", 1, 20, "Invalid Budget amount.");
                }
            }
        } else {
            $v->isOk("#", "num", 0, 0, "Error : please select at least one cost center.");
        }
    }
    # display errors, if any
    if ($v->isError()) {
        $confirm = "";
        $errors = $v->getErrors();
        foreach ($errors as $e) {
            $confirm .= "<li class=err>{$e['msg']}</li>";
        }
        return details($_POST, $confirm);
    }
    global $BUDFOR, $TYPES, $PERIODS;
    $vbudfor = $BUDFOR[$budfor];
    $vbudtype = $TYPES[$budtype];
    $vfromprd = $PERIODS[$fromprd];
    $vtoprd = $PERIODS[$toprd];
    db_conn("cubit");
    $sql = "SELECT * FROM budgets WHERE budname='{$budname}' AND budfor='{$budfor}' AND budtype='{$budtype}'";
    $rslt = db_exec($sql) or errDie("Unable to retrieve budgets from Cubit.");
    $bud_data = pg_fetch_array($rslt);
    if (!pg_num_rows($rslt)) {
        db_connect();
        $sql = "INSERT INTO budgets(budname, budtype, budfor, fromprd, toprd, edate, div) VALUES('{$budname}', '{$budtype}', '{$budfor}', '{$fromprd}', '{$toprd}', now(), '" . USER_DIV . "')";
        $inRs = db_exec($sql);
        $budid = pglib_lastid("budgets", "budid");
    } else {
        $budid = $bud_data["budid"];
    }
    if ($budfor == 'acc') {
        foreach ($accids as $akey => $id) {
            foreach ($amts[$id] as $sprd => $amt) {
                $sql = "INSERT INTO buditems(budid, id, prd, amt) VALUES('{$budid}', '{$id}', '{$sprd}', '{$amt}')";
                $itRs = db_exec($sql);
            }
        }
    } else {
        foreach ($ccids as $akey => $id) {
            foreach ($amts[$id] as $sprd => $amt) {
                $sql = "INSERT INTO buditems(budid, id, prd, amt) VALUES('{$budid}', '{$id}', '{$sprd}', '{$amt}')";
                $itRs = db_exec($sql);
            }
        }
    }
    // Start layout
    $write = "<center>\n\t<table border=0 cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "' width=500>\n\t\t<tr>\n\t\t\t<th colspan=2>New Monthly Budget created</th>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td class='bg-odd' colspan=2>New Monthly Budget <b>{$budname}</b> has been created.</td>\n\t\t</tr>\n\t</table>\n\t<p>\n\t<table border=0 cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "' width=25%>\n\t\t<tr>\n\t\t\t<th>Quick Links</th>\n\t\t</tr>\n\t\t<tr class='bg-odd'>\n\t\t\t<td align=center><a href='budget-view.php'>View Budgets</td>\n\t\t</tr>\n\t\t<tr class='bg-odd'>\n\t\t\t<td align=center><a href='../main.php'>Main Menu</td>\n\t\t</tr>\n\t</table>";
    return $write;
}
开发者ID:kumarsivarajan,项目名称:accounting-123,代码行数:82,代码来源:budget-new.php

示例14: write

function write($_POST)
{
    # Get vars
    foreach ($_POST as $key => $value) {
        ${$key} = $value;
    }
    if (isset($back)) {
        return view($_POST);
    }
    # Validate input
    require_lib("validate");
    $v = new validate();
    $v->isOk($brancod, "string", 0, 50, "Invalid branch code.");
    $v->isOk($branname, "string", 1, 255, "Invalid branch name.");
    $v->isOk($brandet, "string", 0, 255, "Invalid branch details.");
    # Display errors, if any
    if ($v->isError()) {
        $confirm = "";
        $errors = $v->getErrors();
        foreach ($errors as $e) {
            $confirm .= "<li class=err>{$e['msg']}</li>";
        }
        $confirm .= "</li><p><input type=button onClick='JavaScript:history.back();' value='&laquo; Correct submission'>";
        return $confirm;
    }
    # Check stock code
    db_connect();
    $sql = "SELECT branname FROM branches WHERE lower(branname) = lower('{$branname}')";
    $cRslt = db_exec($sql);
    if (pg_numrows($cRslt) > 0) {
        $error = "<li class=err>Branch name : <b>{$branname}</b> already exists.</li>";
        $error .= "<p><input type=button onClick='JavaScript:history.back();' value='&laquo; Correct submission'>";
        return $error;
    }
    // Insert into stock
    db_connect();
    $sql = "INSERT INTO branches(brancod, branname, brandet) VALUES('{$brancod}', '{$branname}', '{$brandet}')";
    $rslt = db_exec($sql) or errDie("Unable to insert branch to Cubit.", SELF);
    $div = pglib_lastid("branches", "div");
    /*
    // Insert sequences
    $sql = "INSERT INTO seq(type, last_value, div) VALUES('inv', '0', '$div')";
    $rslt = db_exec($sql) or errDie("Unable to insert branch to Cubit.",SELF);
    $sql = "INSERT INTO seq(type, last_value, div) VALUES('pur', '0', '$div')";
    $rslt = db_exec($sql) or errDie("Unable to insert branch to Cubit.",SELF);
    $sql = "INSERT INTO seq(type, last_value, div) VALUES('note', '0', '$div')";
    $rslt = db_exec($sql) or errDie("Unable to insert branch to Cubit.",SELF);
    */
    # Create Default Accounts
    // Profit/Loss account (999/999)
    $catid = createcat("Profit/Loss", $div, "B");
    if (createacc("9999", "999", "Profit/Loss account", $catid, "B", "n", $div) > 0) {
        return "<li class=err>Failed to create default accounts</li>";
    }
    // Total Income account (199/999)
    $catid = createcat("Total Income", $div, "I");
    if (createacc("1999", "999", "Total Income account", $catid, "I", "n", $div) > 0) {
        return "<li class=err>Failed to create default accounts</li>";
    }
    // Total Expenses account (499/999)
    $catid = createcat("Total Expenses", $div, "E");
    if (createacc("4999", "999", "Total Expenses account", $catid, "E", "n", $div) > 0) {
        return "<li class=err>Failed to create default accounts</li>";
    }
    // Layout
    $write = "\r\n\t<table border=0 cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "' width='50%'>\r\n\t<tr><th>New Branch added to database</th></tr>\r\n\t<tr class=datacell><td>New Branch, {$branname} ({$brancod}) has been successfully added to Cubit.</td></tr>\r\n\t</table>\r\n\t<p>\r\n\t<table border=0 cellpadding='2' cellspacing='1'>\r\n\t\t<tr><th>Quick Links</th></tr>\r\n\t\t<tr class='bg-odd'><td><a href='admin-branview.php'>View Branches</a></td></tr>\r\n\t\t<tr class='bg-odd'><td><a href='main.php'>Main Menu</a></td></tr>\r\n\t</table>";
    return $write;
}
开发者ID:andrecoetzee,项目名称:accounting-123.com,代码行数:68,代码来源:admin-branadd-b.php

示例15: 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 = "&nbsp;&nbsp;";
        }
        // 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']}&nbsp;\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']}&nbsp;\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']}&nbsp;\r\n\t\t\t\t</td>\r\n\t\t\t\t<td align='right' nowrap>" . CUR . " {$item_data['amt']}&nbsp;</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'>&nbsp;</td>\r\n\t\t\t\t\t<td style='border-right: 2px solid #000'>&nbsp;</td>\r\n\t\t\t\t\t<td style='border-right: 2px solid #000'>&nbsp;</td>\r\n\t\t\t\t\t<td>&nbsp;</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>";
//.........这里部分代码省略.........
开发者ID:andrecoetzee,项目名称:accounting-123.com,代码行数:101,代码来源:hire-invoice-note.php


注:本文中的pglib_lastid函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。