コード例 #1
0
function alloc($_POST, $err = "")
{
    extract($_POST);
    if (isset($back)) {
        if (isset($e)) {
            header("Location: cashbook-entry.php");
            exit;
        }
        return sel_cus($_POST);
    }
    if (isset($print_recpt) and strlen($print_recpt) > 0) {
        $send_print = "<input type='hidden' name='print_recpt' value='{$print_recpt}'>";
    } else {
        $send_print = "";
    }
    if (isset($bulk_pay) and strlen($bulk_pay) > 0) {
        $send_bulk = "<input type='hidden' name='bulk_pay' value='yes'>";
    } else {
        $send_bulk = "";
    }
    $all = 0;
    $date_arr = explode("-", $tdate);
    $date_year = $date_arr[0];
    $date_month = $date_arr[1];
    $date_day = $date_arr[2];
    require_lib("validate");
    $v = new validate();
    $v->isOk($bankid, "num", 1, 30, "Select Bank Account.");
    $v->isOk($date_day, "num", 1, 2, "Invalid Date day.");
    $v->isOk($all, "num", 1, 1, "Invalid allocation.");
    $v->isOk($date_month, "num", 1, 2, "Invalid Date month.");
    $v->isOk($date_year, "num", 1, 4, "Invalid Date Year.");
    $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($cusid, "num", 1, 10, "Invalid customer number.");
    if (strlen($date_year) != 4) {
        $v->isOk($bankname, "num", 1, 1, "Invalid Date year.");
    }
    if ($amt < 0.01) {
        $v->addError($amt, "Amount too small.");
    }
    $date = $date_day . "-" . $date_month . "-" . $date_year;
    if (!checkdate($date_month, $date_day, $date_year)) {
        $v->isOk($date, "num", 1, 1, "Invalid date.");
    }
    if ($v->isError()) {
        $confirm = $v->genErrors();
        $confirm .= "<br>" . "<input type='button' onClick='history.back();' value='&laquo Correction'>";
        return $confirm;
        //.alloc($_POST);
    }
    # CHECK IF THIS DATE IS IN THE BLOCKED RANGE
    $blocked_date_from = getCSetting("BLOCKED_FROM");
    $blocked_date_to = getCSetting("BLOCKED_TO");
    if (strtotime($date) >= strtotime($blocked_date_from) and strtotime($date) <= 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>";
    }
    // bank account name
    if ($bankid == "0" or ($bank = qryBankAcct($bankid, "accname, bankname")) === false) {
        $bank['accname'] = "Cash";
        $bank['bankname'] = "";
    }
    // customer name
    $cus = qryCustomer($cusid, "cusname, surname");
    if ($print_recpt == "yes") {
        $show_print_recpt = "Yes";
    } else {
        $show_print_recpt = "No";
    }
    $confirm = "\n\t\t<h3>New Bank Receipt</h3>\n\t\t{$err}\n\t\t<form action='" . SELF . "' method='POST'>\n\t\t\t<input type='hidden' name='key' value='confirm'>\n\t\t\t<input type='hidden' name='accnum' value=''>\n\t\t\t<input type='hidden' name='bankid' value='{$bankid}'>\n\t\t\t<input type='hidden' name='date' value='{$date}'>\n\t\t\t<input type='hidden' name='all' value='{$all}'>\n\t\t\t<input type='hidden' name='cusid' value='{$cusid}'>\n\t\t\t<input type='hidden' name='date_day' value='{$date_day}'>\n\t\t\t<input type='hidden' name='date_month' value='{$date_month}'>\n\t\t\t<input type='hidden' name='date_year' value='{$date_year}'>\n\t\t\t<input type='hidden' name='descript' value='{$descript}'>\n\t\t\t<input type='hidden' name='reference' value='{$reference}'>\n\t\t\t<input type='hidden' name='cheqnum' value='{$cheqnum}'>\n\t\t\t<input type='hidden' name='amt' value='{$amt}'>\n\t\t\t{$send_bulk}\n\t\t\t{$send_print}\n\t\t<table " . TMPL_tblDflts . ">\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>Account</td>\n\t\t\t\t<td>{$bank['accname']} - {$bank['bankname']}</td>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>Date</td>\n\t\t\t\t<td valign='center'>{$date}</td>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>Received from</td>\n\t\t\t\t<td valign='center'>{$cus['cusname']} {$cus['surname']}</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'>" . nl2br($descript) . "</td>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>Reference</td>\n\t\t\t\t<td valign='center'>{$reference}</td>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>Cheque Number</td>\n\t\t\t\t<td valign='center'>{$cheqnum}</td>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>Amount</td>\n\t\t\t\t<td valign='center'>" . CUR . " {$amt}</td>\n\t\t\t</tr>\n\t\t\t" . TBL_BR . "\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>Print Receipt</td>\n\t\t\t\t<td>{$show_print_recpt}</td>\n\t\t\t</tr>";
    /* OPTION 1 : AUTO ALLOCATE (allocate) */
    #we need a new why of allocating this ... stock,nonstock,pos order is counter productive
    #so, we get them all into an array, and sort that ...
    if ($all == 0) {
        $out = $amt;
        $invs_arr = array();
        // Connect to database
        db_connect();
        #####################[ GET OUTSTANDING INVOICES ]######################
        $sql = "SELECT invnum, invid, balance, terms, odate FROM invoices WHERE cusnum = '{$cusid}' AND printed = 'y' AND balance>0 AND div = '" . USER_DIV . "' ORDER BY odate ASC";
        $prnInvRslt = db_exec($sql);
        while (($inv = pg_fetch_array($prnInvRslt)) && $out > 0) {
            $invs_arr[] = array("s", $inv['odate'], "{$inv['invid']}", "{$inv['balance']}");
        }
        #####################[ GET OUTSTANDING NON STOCK INVOICES ]######################
        $sql = "SELECT invnum, invid, balance, odate FROM nons_invoices WHERE cusid='{$cusid}' AND done='y' AND balance>0 AND div='" . USER_DIV . "' ORDER BY odate ASC";
        $prnInvRslt = db_exec($sql);
        while (($inv = pg_fetch_array($prnInvRslt)) && $out > 0) {
            $invs_arr[] = array("n", $inv['odate'], "{$inv['invid']}", "{$inv['balance']}");
        }
        $out = sprint($out);
        #####################[ GET OUTSTANDING POS INVOICES ]######################
        $sqls = array();
        for ($i = 1; $i <= 12; ++$i) {
            $sqls[] = "\n\t\t\t\tSELECT invnum, invid, balance, odate \n\t\t\t\tFROM \"{$i}\".pinvoices \n\t\t\t\tWHERE cusnum='{$cusid}' AND done='y' AND balance > 0 AND div='" . USER_DIV . "'";
        }
        $sql = implode(" UNION ", $sqls);
        $prnInvRslt = db_exec($sql);
        while ($inv = pg_fetch_array($prnInvRslt)) {
            $invs_arr[] = array("p", $inv['odate'], "{$inv['invid']}", "{$inv['balance']}");
        }
        if (isset($invs_arr) and is_array($invs_arr)) {
            $confirm .= "\n\t\t\t\t<tr><td><br></td></tr>\n\t\t\t\t<tr>\n\t\t\t\t\t<th>Type</th>\n\t\t\t\t\t<th>Invoice</th>\n\t\t\t\t\t<th>Outstanding Amount</th>\n\t\t\t\t\t<th></th>\n\t\t\t\t\t<th>Date</th>\n\t\t\t\t\t<th>Amount</th>\n\t\t\t\t</tr>";
        }
        #compile results into an array we can sort by date
        $search_arr = array();
        foreach ($invs_arr as $key => $array) {
            $search_arr[$key] = $array[1];
        }
        #sort array by date
        asort($search_arr);
        #add sorted invoices to payment listing
        foreach ($search_arr as $key => $date) {
            $arr = $invs_arr[$key];
            if ($arr[0] == "s") {
                $get_sql = "SELECT invnum, invid, balance, terms, odate FROM invoices WHERE cusnum = '{$cusid}' AND printed = 'y' AND balance>0 AND div = '" . USER_DIV . "' AND invid = '{$arr['2']}'  LIMIT 1";
                $run_sql = db_exec($get_sql) or errDie("Unable to get stock invoice information.");
                if (pg_numrows($run_sql) > 0) {
                    $inv = pg_fetch_array($run_sql);
                    $invid = $inv['invid'];
                    $val = allocamt($out, $inv["balance"]);
                    $confirm .= "\n\t\t\t\t\t\t<input type='hidden' name='paidamt[{$invid}]' size='10' value='{$val}'>\n\t\t\t\t\t\t<input type='hidden' size='20' name='invids[{$invid}]' value='{$inv['invid']}'>\n\t\t\t\t\t\t<tr bgcolor='" . bgcolor($i) . "'>\n\t\t\t\t\t\t\t<td>Stock Invoice</td>\n\t\t\t\t\t\t\t<td>{$inv['invnum']}</td>\n\t\t\t\t\t\t\t<td>" . CUR . " {$inv['balance']}</td>\n\t\t\t\t\t\t\t<td>{$inv['terms']} days</td>\n\t\t\t\t\t\t\t<td>{$inv['odate']}</td>\n\t\t\t\t\t\t\t<td>" . CUR . " {$val}</td>\n\t\t\t\t\t\t</tr>";
                }
            } elseif ($arr[0] == "n") {
                //sdate as
                $get_sql = "SELECT invnum, invid, balance, odate FROM nons_invoices WHERE cusid='{$cusid}' AND done='y' AND balance>0 AND div='" . USER_DIV . "' AND invid = '{$arr['2']}' LIMIT 1";
                $run_sql = db_exec($get_sql) or errDie("Unable to get non stock information.");
                if (pg_numrows($run_sql) > 0) {
                    $inv = pg_fetch_array($run_sql);
                    $invid = $inv['invid'];
                    $val = allocamt($out, $inv["balance"]);
                    $confirm .= "\n\t\t\t\t\t\t<input type='hidden' name='paidamt[{$invid}]' value='{$val}'>\n\t\t\t\t\t\t<input type='hidden' name='itype[{$invid}]' value='Yes'>\n\t\t\t\t\t\t<tr bgcolor='" . bgcolor($i) . "'>\n\t\t\t\t\t\t\t<td>Non Stock Invoice</td>\n\t\t\t\t\t\t\t<td><input type='hidden' size='20' name='invids[{$invid}]' value='{$inv['invid']}'>{$inv['invnum']}</td>\n\t\t\t\t\t\t\t<td>" . CUR . " {$inv['balance']}</td>\n\t\t\t\t\t\t\t<td></td>\n\t\t\t\t\t\t\t<td>{$inv['odate']}</td>\n\t\t\t\t\t\t\t<td>" . CUR . " {$val}</td>\n\t\t\t\t\t\t</tr>";
                }
            } else {
                $sqls = array();
                for ($i = 1; $i <= 12; ++$i) {
                    $sqls[] = "\n\t\t\t\t\t\tSELECT invnum, invid, balance, odate \n\t\t\t\t\t\tFROM \"{$i}\".pinvoices \n\t\t\t\t\t\tWHERE cusnum='{$cusid}' AND done='y' AND balance > 0 AND div='" . USER_DIV . "' AND invid = '{$arr['2']}'";
                }
                $get_sql = implode(" UNION ", $sqls);
                $run_sql = db_exec($get_sql) or errDie("Unable to get pos invoice information.");
                if (pg_numrows($run_sql) > 0) {
                    $inv = pg_fetch_array($run_sql);
                    $invid = $inv['invid'];
                    $val = allocamt($out, $inv["balance"]);
                    $confirm .= "\n\t\t\t\t\t\t<input type='hidden' size='20' name='invids[{$invid}]' value='{$inv['invid']}'>\n\t\t\t\t\t\t<input type='hidden' name='paidamt[{$invid}]' size='10' value='{$val}'>\n\t\t\t\t\t\t<input type='hidden' name='ptype[{$invid}]' value='YnYn'>\n\t\t\t\t\t\t<tr bgcolor='" . bgcolor($i) . "'>\n\t\t\t\t\t\t\t<td>POS Invoice</td>\n\t\t\t\t\t\t\t<td>{$inv['invnum']}</td>\n\t\t\t\t\t\t\t<td>" . CUR . " {$inv['balance']}</td>\n\t\t\t\t\t\t\t<td></td>\n\t\t\t\t\t\t\t<td>{$inv['odate']}</td>\n\t\t\t\t\t\t\t<td>" . CUR . " {$val}</td>\n\t\t\t\t\t\t</tr>";
                }
            }
        }
        #if there is any amount unallocated, it goes to general transaction
        $confirm .= "\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td colspan='6'><b>A general transaction will credit the client's account with " . CUR . " {$out} </b></td>\n\t\t\t</tr>";
    }
    vsprint($out);
    $confirm .= "\n\t\t\t<input type='hidden' name='out' value='{$out}'>\n\t\t\t<tr>\n\t\t\t\t<td><input type='submit' name='back' value='&laquo; Correction'></td>\n\t\t\t\t<td align='right'><input type='submit' value='Confirm &raquo'></td>\n\t\t\t</tr>\n\t\t</table>\n\t\t</form>" . mkQuickLinks(ql("../core/trans-new.php", "Journal Transactions"), ql("../customers-view.php", "View Customers"));
    return $confirm;
}
コード例 #2
0
function alloc($_POST)
{
    extract($_POST);
    if (isset($back)) {
        if (isset($e)) {
            header("Location: cashbook-entry.php");
            exit;
        }
        return sel_cus($_POST);
    }
    $passon = "";
    require_lib("validate");
    $v = new validate();
    $v->isOk($all, "num", 1, 1, "Invalid allocation.");
    for ($i = 0; $i < $rec_amount; $i++) {
        if (!isset($descript[$i]) or !isset($reference[$i]) or !isset($setamt[$i]) or empty($descript[$i]) or empty($reference[$i]) or empty($setamt[$i])) {
            continue;
        }
        $v->isOk($bankid[$i], "num", 1, 30, "Select Bank Account.");
        $v->isOk($date_day[$i], "num", 1, 2, "Invalid Date day.");
        $v->isOk($date_month[$i], "num", 1, 2, "Invalid Date month.");
        $v->isOk($date_year[$i], "num", 1, 4, "Invalid Date Year.");
        $v->isOk($descript[$i], "string", 0, 255, "Invalid Description.");
        $v->isOk($reference[$i], "string", 0, 50, "Invalid Reference Name/Number.");
        $v->isOk($cheqnum[$i], "num", 0, 30, "Invalid Cheque number.");
        $v->isOk($amt[$i], "float", 1, 40, "Invalid amount.");
        $v->isOk($setamt[$i], "float", 1, 40, "Invalid Settlement Amount.");
        $v->isOk($setvat[$i], "string", 1, 10, "Invalid Settlement VAT Option.");
        $v->isOk($setvatcode[$i], "string", 1, 40, "Invalid Settlement VAT code");
        $v->isOk($cusid[$i], "num", 1, 10, "Invalid customer number.");
        if (strlen($date_year[$i]) != 4) {
            $v->isOk($bankname, "num", 1, 1, "Invalid Date year.");
        }
        if ($amt < 0.01) {
            $v->addError($amt[$i], "Amount too small.");
        }
        $date[$i] = $date_day[$i] . "-" . $date_month[$i] . "-" . $date_year[$i];
        if (!checkdate($date_month[$i], $date_day[$i], $date_year[$i])) {
            $v->isOk($date[$i], "num", 1, 1, "Invalid date.");
        }
        // bank account name
        if (($bank = qryBankAcct($bankid[$i], "accname, bankname")) === false) {
            $bank[$i]['accname'] = "Cash";
            $bank[$i]['bankname'] = "";
        }
        // customer name
        $cus[$i] = qryCustomer($cusid[$i], "cusnum, cusname, surname");
    }
    if ($v->isError()) {
        $confirm = $v->genErrors();
        return $confirm . method($_POST);
    }
    //	<input type='hidden' name='bankid' value='$bankid'>
    $cust_arr = array();
    $confirm = "\n\t\t<h3>New Bank Receipt</h3>\n\t\t<form action='" . SELF . "' method='POST'>\n\t\t\t<input type='hidden' name='key' value='confirm'>\n\t\t\t<input type='hidden' name='accnum' value=''>\n\t\t\t<input type='hidden' name='rec_amount' value='{$rec_amount}'>\n\t\t\t<input type='hidden' name='all' value='{$all}'>\n\t\t<table " . TMPL_tblDflts . ">";
    for ($t = 0; $t < $rec_amount; $t++) {
        if (!isset($descript[$t]) or !isset($reference[$t]) or !isset($setamt[$t]) or empty($descript[$t]) or empty($reference[$t]) or empty($setamt[$t])) {
            continue;
        }
        $cus0 = $cus[$t]['cusnum'];
        $cus1 = $cus[$t]['cusname'];
        $cus2 = $cus[$t]['surname'];
        // we dont do this ...
        //		$amt[$t] = $amt[$t] + $setamt[$t];
        $amt[$t] = sprint($amt[$t]);
        $setamt[$t] = sprint($setamt[$t]);
        if ($setvat[$t] == "inc") {
            $showsetvat = "VAT Inclusive";
        } else {
            $showsetvat = "No VAT";
        }
        $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>Account</td>\n\t\t\t\t<td>{$bank['accname']} - {$bank['bankname']}</td>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>Date</td>\n\t\t\t\t<td valign='center'>{$date[$t]}</td>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>Received from</td>\n\t\t\t\t<td valign='center'>{$cus1} {$cus2}</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'>" . nl2br($descript[$t]) . "</td>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>Reference</td>\n\t\t\t\t<td valign='center'>{$reference[$t]}</td>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>Cheque Number</td>\n\t\t\t\t<td valign='center'>{$cheqnum[$t]}</td>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>Amount</td>\n\t\t\t\t<td valign='center'>" . CUR . " {$amt[$t]}</td>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>Settlement Discount</td>\n\t\t\t\t<td valign='center'>" . CUR . " {$setamt[$t]} {$showsetvat}</td>\n\t\t\t</tr>";
        /* OPTION 1 : AUTO ALLOCATE (allocate) */
        if ($all == 0) {
            $out[$t] = $amt[$t];
            $invs_arr = array();
            // Connect to database
            db_connect();
            #####################[ GET OUTSTANDING INVOICES ]######################
            $sql = "SELECT invnum, invid, balance, terms, odate FROM invoices WHERE cusnum = '{$cusid[$t]}' AND printed = 'y' AND balance>0 AND div = '" . USER_DIV . "' ORDER BY odate ASC";
            $prnInvRslt = db_exec($sql);
            while (($inv = pg_fetch_array($prnInvRslt)) && $out > 0) {
                $invs_arr[] = array("s", $inv['odate'], "{$inv['invid']}", "{$inv['balance']}");
            }
            #####################[ GET OUTSTANDING NON STOCK INVOICES ]######################
            $sql = "SELECT invnum, invid, balance, odate FROM nons_invoices WHERE cusid='{$cusid[$t]}' AND done='y' AND balance>0 AND div='" . USER_DIV . "' ORDER BY odate ASC";
            $prnInvRslt = db_exec($sql);
            while (($inv = pg_fetch_array($prnInvRslt)) && $out > 0) {
                $invs_arr[] = array("n", $inv['odate'], "{$inv['invid']}", "{$inv['balance']}");
            }
            #####################[ GET OUTSTANDING POS INVOICES ]######################
            $sqls = array();
            for ($i = 1; $i <= 12; ++$i) {
                $sqls[] = "\n\t\t\t\t\tSELECT invnum, invid, balance, odate \n\t\t\t\t\tFROM \"{$i}\".pinvoices \n\t\t\t\t\tWHERE cusnum='{$cusid[$t]}' AND done='y' AND balance > 0 AND div='" . USER_DIV . "'";
            }
            $sql = implode(" UNION ", $sqls);
            $prnInvRslt = db_exec($sql);
            while ($inv = pg_fetch_array($prnInvRslt)) {
                $invs_arr[] = array("p", $inv['odate'], "{$inv['invid']}", "{$inv['balance']}");
            }
            if (isset($invs_arr) and is_array($invs_arr)) {
                $confirm .= "\n\t\t\t\t\t<tr><td><br></td></tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<th>Type</th>\n\t\t\t\t\t\t<th>Invoice</th>\n\t\t\t\t\t\t<th>Outstanding Amount</th>\n\t\t\t\t\t\t<th></th>\n\t\t\t\t\t\t<th>Date</th>\n\t\t\t\t\t\t<th>Amount</th>\n\t\t\t\t\t</tr>";
            }
            #compile results into an array we can sort by date
            $search_arr = array();
            foreach ($invs_arr as $key => $array) {
                $search_arr[$key] = $array[1];
            }
            #sort array by date
            asort($search_arr);
            #add sorted invoices to payment listing
            foreach ($search_arr as $key => $date_arr) {
                $arr = $invs_arr[$key];
                if ($arr[0] == "s") {
                    $get_sql = "SELECT invnum, invid, balance, terms, odate FROM invoices WHERE cusnum = '{$cusid[$t]}' AND printed = 'y' AND balance>0 AND div = '" . USER_DIV . "' AND invid = '{$arr['2']}'  LIMIT 1";
                    $run_sql = db_exec($get_sql) or errDie("Unable to get stock invoice information.");
                    if (pg_numrows($run_sql) > 0) {
                        $inv = pg_fetch_array($run_sql);
                        $invid = $inv['invid'];
                        if (in_array($invid, $cust_arr[$cus0])) {
                            continue;
                        } else {
                            $val = allocamt($out[$t], $inv["balance"]);
                            if ($val > 0) {
                                $cust_arr[$cus0][] = $invid;
                            } else {
                                continue;
                            }
                        }
                        $confirm .= "\n\t\t\t\t\t\t\t<input type='hidden' name='paidamt[{$t}][{$invid}]' size='10' value='{$val}'>\n\t\t\t\t\t\t\t<input type='hidden' size='20' name='invids[{$t}][{$invid}]' value='{$inv['invid']}'>\n\t\t\t\t\t\t\t<tr bgcolor='" . bgcolor($i) . "'>\n\t\t\t\t\t\t\t\t<td>Stock Invoice</td>\n\t\t\t\t\t\t\t\t<td>{$inv['invnum']}</td>\n\t\t\t\t\t\t\t\t<td>" . CUR . " {$inv['balance']}</td>\n\t\t\t\t\t\t\t\t<td>{$inv['terms']} days</td>\n\t\t\t\t\t\t\t\t<td>{$inv['odate']}</td>\n\t\t\t\t\t\t\t\t<td>" . CUR . " {$val}</td>\n\t\t\t\t\t\t\t</tr>";
                    }
                } elseif ($arr[0] == "n") {
                    $get_sql = "SELECT invnum, invid, balance, odate FROM nons_invoices WHERE cusid='{$cusid[$t]}' AND done='y' AND balance>0 AND div='" . USER_DIV . "' AND invid = '{$arr['2']}' LIMIT 1";
                    $run_sql = db_exec($get_sql) or errDie("Unable to get non stock information.");
                    if (pg_numrows($run_sql) > 0) {
                        $inv = pg_fetch_array($run_sql);
                        $invid = $inv['invid'];
                        if (in_array($invid, $cust_arr[$cus0])) {
                            continue;
                        } else {
                            $val = allocamt($out[$t], $inv["balance"]);
                            if ($val > 0) {
                                $cust_arr[$cus0][] = $invid;
                            } else {
                                continue;
                            }
                        }
                        $confirm .= "\n\t\t\t\t\t\t\t<input type='hidden' name='paidamt[{$t}][{$invid}]' value='{$val}'>\n\t\t\t\t\t\t\t<input type='hidden' name='itype[{$t}][{$invid}]' value='Yes'>\n\t\t\t\t\t\t\t<tr bgcolor='" . bgcolor($i) . "'>\n\t\t\t\t\t\t\t\t<td>Non Stock Invoice</td>\n\t\t\t\t\t\t\t\t<td><input type='hidden' size='20' name='invids[{$t}][{$invid}]' value='{$inv['invid']}'>{$inv['invnum']}</td>\n\t\t\t\t\t\t\t\t<td>" . CUR . " {$inv['balance']}</td>\n\t\t\t\t\t\t\t\t<td></td>\n\t\t\t\t\t\t\t\t<td>{$inv['odate']}</td>\n\t\t\t\t\t\t\t\t<td>" . CUR . " {$val}</td>\n\t\t\t\t\t\t\t</tr>";
                    }
                } else {
                    $sqls = array();
                    for ($i = 1; $i <= 12; ++$i) {
                        $sqls[] = "\n\t\t\t\t\t\t\tSELECT invnum, invid, balance, odate \n\t\t\t\t\t\t\tFROM \"{$i}\".pinvoices \n\t\t\t\t\t\t\tWHERE cusnum='{$cusid[$t]}' AND done='y' AND balance > 0 AND div='" . USER_DIV . "' AND invid = '{$arr['2']}'";
                    }
                    $get_sql = implode(" UNION ", $sqls);
                    $run_sql = db_exec($get_sql) or errDie("Unable to get pos invoice information.");
                    if (pg_numrows($run_sql) > 0) {
                        $inv = pg_fetch_array($run_sql);
                        $invid = $inv['invid'];
                        if (in_array($invid, $cust_arr[$cus0])) {
                            continue;
                        } else {
                            $val = allocamt($out[$t], $inv["balance"]);
                            if ($val > 0) {
                                $cust_arr[$cus0][] = $invid;
                            } else {
                                continue;
                            }
                        }
                        $confirm .= "\n\t\t\t\t\t\t\t<input type='hidden' size='20' name='invids[{$t}][{$invid}]' value='{$inv['invid']}'>\n\t\t\t\t\t\t\t<input type='hidden' name='paidamt[{$t}][{$invid}]' size='10' value='{$val}'>\n\t\t\t\t\t\t\t<input type='hidden' name='ptype[{$t}][{$invid}]' value='YnYn'>\n\t\t\t\t\t\t\t<tr bgcolor='" . bgcolor($i) . "'>\n\t\t\t\t\t\t\t\t<td>POS Invoice</td>\n\t\t\t\t\t\t\t\t<td>{$inv['invnum']}</td>\n\t\t\t\t\t\t\t\t<td>" . CUR . " {$inv['balance']}</td>\n\t\t\t\t\t\t\t\t<td></td>\n\t\t\t\t\t\t\t\t<td>{$inv['odate']}</td>\n\t\t\t\t\t\t\t\t<td>" . CUR . " {$val}</td>\n\t\t\t\t\t\t\t</tr>";
                    }
                    $out[$t] = sprint($out[$t]);
                }
            }
        }
        if ($out[$t] > 0) {
            $out[$t] = sprint($out[$t]);
            $confirm .= "\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td colspan='4'><b>A general transaction will credit the client's account with " . CUR . " {$out[$t]} </b></td>\n\t\t\t\t</tr>";
        }
        $confirm .= TBL_BR . TBL_BR . TBL_BR;
    }
    for ($i = 0; $i < $rec_amount; $i++) {
        $passon .= "\n\t\t\t<input type='hidden' name='bankid[{$i}]' value='{$bankid[$i]}'>\n\t\t\t<input type='hidden' name='date[{$i}]' value='{$date[$i]}'>\n\t\t\t<input type='hidden' name='cusid[{$i}]' value='{$cusid[$i]}'>\n\t\t\t<input type='hidden' name='date_day[{$i}]' value='{$date_day[$i]}'>\n\t\t\t<input type='hidden' name='date_month[{$i}]' value='{$date_month[$i]}'>\n\t\t\t<input type='hidden' name='date_year[{$i}]' value='{$date_year[$i]}'>\n\t\t\t<input type='hidden' name='descript[{$i}]' value='{$descript[$i]}'>\n\t\t\t<input type='hidden' name='reference[{$i}]' value='{$reference[$i]}'>\n\t\t\t<input type='hidden' name='cheqnum[{$i}]' value='{$cheqnum[$i]}'>\n\t\t\t<input type='hidden' name='amt[{$i}]' value='{$amt[$i]}'>\n\t\t\t<input type='hidden' name='setamt[{$i}]' value='{$setamt[$i]}'>\n\t\t\t<input type='hidden' name='setvat[{$i}]' value='{$setvat[$i]}'>\n\t\t\t<input type='hidden' name='setvatcode[{$i}]' value='{$setvatcode[$i]}'>\n\t\t\t<input type='hidden' name='out[{$i}]' value='{$out[$i]}'>";
    }
    $confirm .= "\n\t\t\t{$passon}\n\t\t\t<tr>\n\t\t\t\t<td><input type='submit' name='back' value='&laquo; Correction'></td>\n\t\t\t\t<td align='right'><input type='submit' value='Confirm &raquo'></td>\n\t\t\t</tr>\n\t\t</table>\n\t\t</form>" . mkQuickLinks(ql("trans-new.php", "Journal Transactions"), ql("../customers-view.php", "View Customers"));
    return $confirm;
}
コード例 #3
0
                $OUTPUT = alloc($_POST);
            }
            break;
        case "write":
            $OUTPUT = write($_POST);
            break;
        default:
            $OUTPUT = sel_cus($_POST);
    }
} elseif (isset($_GET["cusnum"])) {
    # Display default output
    $OUTPUT = alloc($_GET);
    //method($_GET["cusnum"]);
} else {
    # Display default output
    $OUTPUT = sel_cus($_POST);
}
# get templete
require "../template.php";
# Insert details
function sel_cus($_POST)
{
    extract($_POST);
    // customers Drop down selections
    db_connect();
    $cust = "<select name='cusid'>";
    $sql = "SELECT accno, cusnum, cusname, surname FROM customers WHERE 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>" . mkQuickLinks(ql("../core/trans-new.php", "Journal Transactions"), ql("../customers-view.php", "View Customers"));
コード例 #4
0
function alloc($_POST)
{
    # get vars
    extract($_POST);
    if (isset($back)) {
        return sel_cus($_POST);
    }
    # validate input
    require_lib("validate");
    $v = new validate();
    $v->isOk($bankid, "num", 1, 30, "Invalid Bank Account.");
    $v->isOk($day, "num", 1, 2, "Invalid Date day.");
    $v->isOk($all, "num", 1, 1, "Invalid allocation.");
    $v->isOk($mon, "num", 1, 2, "Invalid Date month.");
    $v->isOk($year, "num", 1, 4, "Invalid Date Year.");
    if (strlen($year) != 4) {
        $v->isOk($bankname, "num", 1, 1, "Invalid Date year.");
    }
    $v->isOk($descript, "string", 0, 255, "Invalid Description.");
    $v->isOk($cheqnum, "num", 0, 30, "Invalid Cheque number.");
    $v->isOk($amt, "float", 1, 10, "Invalid amount.");
    if ($amt < 0.01) {
        $v->isOk($amt, "float", 5, 1, "Amount too small.");
    }
    $v->isOk($cusid, "num", 1, 10, "Invalid customer number.");
    $date = $day . "-" . $mon . "-" . $year;
    if (!checkdate($mon, $day, $year)) {
        $v->isOk($date, "num", 1, 1, "Invalid date.");
    }
    # 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='&laquo; Correct submission'>";
        return $confirm . "</li>" . method($cusid);
    }
    $amt = sprint($amt);
    $out = 0;
    $confirm = "\n\t\t\t\t\t<h3>New Bank Receipt</h3>\n\t\t\t\t\t<table " . TMPL_tblDflts . ">\n\t\t\t\t\t<form action='" . SELF . "' method='POST'>\n\t\t\t\t\t\t<input type='hidden' name='key' value='confirm'>\n\t\t\t\t\t\t<input type='hidden' name='accnum' value=''>\n\t\t\t\t\t\t<input type='hidden' name='bankid' value='{$bankid}'>\n\t\t\t\t\t\t<input type='hidden' name='date' value='{$date}'>\n\t\t\t\t\t\t<input type='hidden' name='all' value='{$all}'>\n\t\t\t\t\t\t<input type='hidden' name='cusid' value='{$cusid}'>\n\t\t\t\t\t\t<input type='hidden' name='day' value='{$day}'>\n\t\t\t\t\t\t<input type='hidden' name='mon' value='{$mon}'>\n\t\t\t\t\t\t<input type='hidden' name='year' value='{$year}'>\n\t\t\t\t\t\t<input type='hidden' name='descript' value='{$descript}'>\n\t\t\t\t\t\t<input type='hidden' name='cheqnum' value='{$cheqnum}'>\n\t\t\t\t\t\t<input type='hidden' name='amt' value='{$amt}'>";
    $i = 0;
    # Get bank account name
    db_connect();
    $sql = "SELECT accname,bankname FROM bankacct WHERE bankid = '{$bankid}' AND div = '" . USER_DIV . "'";
    $bankRslt = db_exec($sql);
    $bank = pg_fetch_array($bankRslt);
    # Customer name
    $sql = "SELECT cusname,surname FROM customers WHERE cusnum = '{$cusid}' AND div = '" . USER_DIV . "'";
    $cusRslt = db_exec($sql);
    $cus = pg_fetch_array($cusRslt);
    $confirm .= "\n        \t\t\t\t<tr>\n        \t\t\t\t\t<th>Field</th>\n        \t\t\t\t\t<th>Value</th>\n        \t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td>Account</td>\n\t\t\t\t\t\t\t<td>{$bank['accname']} - {$bank['bankname']}</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td>Date</td>\n\t\t\t\t\t\t\t<td valign='center'>{$date}</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td>Received from</td>\n\t\t\t\t\t\t\t<td valign='center'>{$cus['cusname']} {$cus['surname']}</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td>Description</td>\n\t\t\t\t\t\t\t<td valign='center'>" . nl2br($descript) . "</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td>Cheque Number</td>\n\t\t\t\t\t\t\t<td valign='center'>{$cheqnum}</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td>Amount</td>\n\t\t\t\t\t\t\t<td valign='center'>" . CUR . " {$amt}</td>\n\t\t\t\t\t\t</tr>";
    if ($all == 0) {
        $out = $amt;
        // Connect to database
        db_connect();
        $sql = "SELECT invnum,invid,balance,terms,odate FROM invoices WHERE cusnum = '{$cusid}' AND printed = 'y' AND balance>0 AND div = '" . USER_DIV . "' ORDER BY odate ASC";
        $prnInvRslt = db_exec($sql);
        $i = 0;
        while ($inv = pg_fetch_array($prnInvRslt) and $out > 0) {
            if ($i == 0) {
                $confirm .= "\n\t\t\t\t\t\t\t\t<tr><td colspan='2'><br></td></tr>\n\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t<td colspan='2'><h3>Outstanding Invoices</h3></td>\n\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t<th>Invoice</th>\n\t\t\t\t\t\t\t\t\t<th>Outstanding Amount</th>\n\t\t\t\t\t\t\t\t\t<th>Terms</th>\n\t\t\t\t\t\t\t\t\t<th>Date</th>\n\t\t\t\t\t\t\t\t\t<th>Amount</th>\n\t\t\t\t\t\t\t\t</tr>";
            }
            $invid = $inv['invid'];
            $confirm .= "\n\t\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t\t<td><input type='hidden' size='20' name='invids[]' value='{$inv['invid']}'>{$inv['invnum']}</td>\n\t\t\t\t\t\t\t\t<td>" . CUR . " {$inv['balance']}</td>\n\t\t\t\t\t\t\t\t<td>{$inv['terms']} days</td>\n\t\t\t\t\t\t\t\t<td>{$inv['odate']}</td>";
            if ($out >= $inv['balance']) {
                $val = $inv['balance'];
                $out = $out - $inv['balance'];
            } else {
                $val = $out;
                $out = 0;
            }
            $i++;
            $val = sprint($val);
            $confirm .= "<td><input type=hidden name='paidamt[{$invid}]' size=10 value='{$val}'>" . CUR . " {$val}</td></tr>";
        }
        $sql = "SELECT invnum,invid,balance,sdate as odate FROM nons_invoices WHERE cusid = '{$cusid}' AND done = 'y' AND balance>0 AND div = '" . USER_DIV . "' ORDER BY odate ASC";
        $prnInvRslt = db_exec($sql);
        while ($inv = pg_fetch_array($prnInvRslt) and $out > 0) {
            if ($i == 0) {
                $confirm .= "\n\t\t\t\t\t\t\t\t<tr><td colspan='2'><br></td></tr>\n\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t<td colspan='2'><h3>Outstanding Invoices</h3></td>\n\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t<th>Invoice</th>\n\t\t\t\t\t\t\t\t\t<th>Outstanding Amount</th>\n\t\t\t\t\t\t\t\t\t<th></th>\n\t\t\t\t\t\t\t\t\t<th>Date</th>\n\t\t\t\t\t\t\t\t\t<th>Amount</th>\n\t\t\t\t\t\t\t\t</tr>";
            }
            $invid = $inv['invid'];
            $confirm .= "\n\t\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t\t<td><input type='hidden' size='20' name='invids[]' value='{$inv['invid']}'>{$inv['invnum']}</td>\n\t\t\t\t\t\t\t\t<td>" . CUR . " {$inv['balance']}</td>\n\t\t\t\t\t\t\t\t<td></td>\n\t\t\t\t\t\t\t\t<td>{$inv['odate']}</td>";
            if ($out >= $inv['balance']) {
                $val = $inv['balance'];
                $out = $out - $inv['balance'];
            } else {
                $val = $out;
                $out = 0;
            }
            $i++;
            $val = sprint($val);
            $confirm .= "<td><input type=hidden name='paidamt[{$invid}]' value='{$val}'><input type=hidden name=itype[{$invid}] value='Yes'>" . CUR . " {$val}</td></tr>";
        }
        $out = sprint($out);
        if ($out > 0) {
            /* START OPEN ITEMS */
            $ox = "";
            db_conn('cubit');
            $Sl = "SELECT * FROM open_stmnt WHERE balance>0 AND cusnum='{$cusid}' ORDER BY date";
            $Ri = db_exec($Sl) or errDie("Unable to get open items.");
            $open_out = $out;
            $i = 0;
            while ($od = pg_fetch_array($Ri)) {
                if ($open_out == 0) {
                    continue;
                }
                $oid = $od['id'];
                if ($open_out >= $od['balance']) {
                    $open_amount[$oid] = $od['balance'];
                    $open_out = sprint($open_out - $od['balance']);
                    $ox .= "\n\t\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t\t<td><input type=hidden size=20 name=open[{$oid}] value='{$oid}'>{$od['type']}</td>\n\t\t\t\t\t\t\t\t<td>" . CUR . " {$od['balance']}</td>\n\t\t\t\t\t\t\t\t<td>{$od['date']}</td>\n\t\t\t\t\t\t\t\t<td><input type=hidden name='open_amount[{$oid}]' value='{$open_amount[$oid]}'>" . CUR . " {$open_amount[$oid]}</td>\n\t\t\t\t\t\t\t</tr>";
                } elseif ($open_out < $od['balance']) {
                    $open_amount[$oid] = $open_out;
                    $open_out = 0;
                    $ox .= "\n\t\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t\t<td><input type=hidden size=20 name=open[{$oid}] value='{$od['id']}'>{$od['type']}</td>\n\t\t\t\t\t\t\t\t<td>" . CUR . " {$od['balance']}</td>\n\t\t\t\t\t\t\t\t<td>{$od['date']}</td>\n\t\t\t\t\t\t\t\t<td><input type=hidden name='open_amount[{$oid}]' value='{$open_amount[$oid]}'>" . CUR . " {$open_amount[$oid]}</td>\n\t\t\t\t\t\t\t</tr>";
                }
                $i++;
            }
            if (open()) {
                $confirm .= "<tr><td colspan=2><br></td></tr>\n\t\t\t\t<tr><td colspan=2><h3>Outstanding Transactions</h3></td></tr>\n\t\t\t\t<tr><th>Description</th><th>Outstanding Amount</th><th>Date</th><th>Amount</th></tr>";
                $confirm .= $ox;
                $bout = $out;
                $out = $open_out;
                if ($out > 0) {
                    $confirm .= "<tr class='bg-even'><td colspan=4><b>A general transaction will credit the client's account with " . CUR . " {$out} </b></td></tr>";
                }
                $out = $bout;
            } else {
                $confirm .= "<tr class='bg-even'><td colspan=4><b>A general transaction will credit the client's account with " . CUR . " {$out} </b></td></tr>";
            }
        }
    }
    if ($all == 1) {
        $confirm .= "<tr><td><table border=0 cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "'>\n\t\t<tr><td><br></td></tr>\n\t\t<tr><th>Current</th><th>30 days</th><th>60 days</th><th>90 days</th><th>120 days</th><th>Total Outstanding</th></tr>";
        $curr = age($cusid, 29);
        $age30 = age($cusid, 59);
        $age60 = age($cusid, 89);
        $age90 = age($cusid, 119);
        $age120 = age($cusid, 149);
        # Customer total
        $custtot = $curr + $age30 + $age60 + $age90 + $age120;
        if (!isset($OUT1)) {
            $OUT1 = "";
            $OUT2 = "";
            $OUT3 = "";
            $OUT4 = "";
            $OUT5 = "";
        }
        $confirm .= "<tr class='bg-odd'><td>" . CUR . " {$curr}</td><td>" . CUR . " {$age30}</td><td>" . CUR . " {$age60}</td><td>" . CUR . " {$age90}</td><td>" . CUR . " {$age120}</td><td>" . CUR . " {$custtot}</td></tr>";
        $confirm .= "<tr class='bg-odd'><td><input type=text size=7 name=out1 value='{$OUT1}'></td><td><input type=text size=7 name=out2 value='{$OUT2}'></td><td><input type=text size=7 name=out3 value='{$OUT3}'></td><td><input type=text size=7 name=out4 value='{$OUT4}'></td><td><input type=text size=7 name=out5 value='{$OUT5}'></td><td></td></tr>";
        $confirm .= "<tr><td><br></td></tr></table></td></tr>";
    }
    if ($all == 2) {
        // Connect to database
        db_connect();
        $sql = "SELECT invnum,invid,balance,terms,odate FROM invoices WHERE cusnum = '{$cusid}' AND printed = 'y' AND balance>0 AND div = '" . USER_DIV . "'";
        $prnInvRslt = db_exec($sql);
        $tempi = pg_numrows($prnInvRslt);
        if (pg_numrows($prnInvRslt) < 1) {
            $sql = "SELECT invnum FROM nons_invoices WHERE cusid = '{$cusid}' AND done = 'y' AND balance>0 AND div = '" . USER_DIV . "'";
            $prnInvRslt = db_exec($sql);
            if (open()) {
                if (pg_numrows($prnInvRslt) < 1) {
                    $Sl = "SELECT * FROM open_stmnt WHERE balance>0 AND cusnum='{$cusid}' ORDER BY date";
                    $Ri = db_exec($Sl) or errDie("Unable to get open items.");
                    if (pg_numrows($Ri) < 1) {
                        return "<li class=err> There are no outstanding invoices for the selected debtor in Cubit.<br>\n\t\t\t\t\t\tTo make a payment in advance please select Auto Allocation</li>" . method($cusid);
                    }
                }
            } else {
                return "<li class=err> There are no outstanding invoices for the selected debtor in Cubit.<br>\n\t\t\t\tTo make a payment in advance please select Auto Allocation</li>" . method($cusid);
            }
        } elseif ($tempi > 0) {
            $confirm .= "<tr><td colspan=2><br></td></tr>\n\t\t\t<tr><td colspan=2><h3>Outstanding Invoices</h3></td></tr>\n\t\t\t<tr><th>Invoice</th><th>Outstanding Amount</th><th>Terms</th><th>Date</th><th>Amount</th></tr>";
            $i = 0;
            while ($inv = pg_fetch_array($prnInvRslt)) {
                $invid = $inv['invid'];
                $confirm .= "<tr class='" . bg_class() . "'><td><input type=hidden size=20 name=invids[] value='{$inv['invid']}'>{$inv['invnum']}</td><td>" . CUR . " {$inv['balance']}</td><td>{$inv['terms']} days</td><td>{$inv['odate']}</td>";
                $val = '';
                if (pg_numrows($prnInvRslt) == 1) {
                    $val = $amt;
                }
                if (isset($paidamt[$i])) {
                    $val = $paidamt[$i];
                }
                $confirm .= "<td><input type=text name='paidamt[{$invid}]' size=10 value='{$val}'></td></tr>";
                $i++;
            }
        }
        $sql = "SELECT invnum,invid,balance,sdate as odate FROM nons_invoices WHERE cusid = '{$cusid}' AND done = 'y' AND balance>0 AND div = '" . USER_DIV . "'";
        $prnInvRslt = db_exec($sql);
        if (pg_numrows($prnInvRslt) > 0) {
            $confirm .= "<tr><td colspan=2><br></td></tr>\n\t\t\t<tr><td colspan=2><h3>Outstanding Invoices</h3></td></tr>\n\t\t\t<tr><th>Invoice</th><th>Outstanding Amount</th><th></th><th>Date</th><th>Amount</th></tr>";
            while ($inv = pg_fetch_array($prnInvRslt)) {
                $invid = $inv['invid'];
                $confirm .= "<tr class='" . bg_class() . "'><td><input type=hidden size=20 name=invids[] value='{$inv['invid']}'>{$inv['invnum']}</td><td>" . CUR . " {$inv['balance']}</td><td></td><td>{$inv['odate']}</td>";
                $val = '';
                if (pg_numrows($prnInvRslt) == 1) {
                    $val = $amt;
                }
                if (isset($paidamt[$i])) {
                    $val = $paidamt[$i];
                }
                $confirm .= "<td><input type=text name='paidamt[{$invid}]' size=10 value='{$val}'><input type=hidden name=itype[{$invid}] value='YnYn'></td></tr>";
                $i++;
            }
        }
        if (open()) {
            db_conn('cubit');
            $Sl = "SELECT * FROM open_stmnt WHERE balance>0 AND cusnum='{$cusid}' ORDER BY date";
            $Ri = db_exec($Sl) or errDie("Unable to get open items.");
            //$open_out=$out;
            $ox = "";
            $i = 0;
            while ($od = pg_fetch_array($Ri)) {
                $oid = $od['id'];
                if (!isset($open_amount[$oid])) {
                    $open_amount[$oid] = "";
                }
                $ox .= "<tr class='" . bg_class() . "'><td><input type=hidden size=20 name=open[{$oid}] value='{$oid}'>{$od['type']}</td>\n\t\t\t\t<td>" . CUR . " {$od['balance']}</td><td>{$od['date']}</td><td><input type=text name='open_amount[{$oid}]' value='{$open_amount[$oid]}'>\n\t\t\t\t</td></tr>";
                $i++;
            }
            $confirm .= "<tr><td colspan=2><br></td></tr>\n\t\t\t<tr><td colspan=2><h3>Outstanding Transactions</h3></td></tr>\n\t\t\t<tr><th>Description</th><th>Outstanding Amount</th><th>Date</th><th>Amount</th></tr>{$ox}";
        }
    }
    $confirm .= "<input type=hidden name=out value='{$out}'>\n\t<tr><td><input type=submit name=back value='&laquo; Correction'></td><td align=right><input type=submit value='Confirm &raquo'></td></tr>\n        </form></table>\n        <p>\n\t\t<table border=0 cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "'>\n\t\t<tr><th>Quick Links</th></tr>\n\t\t<script>document.write(getQuicklinkSpecial());</script>\n\t\t<script>document.write(getQuicklinkSpecial());</script>\n\t\t<tr class='bg-odd'><td><a href='../main.php'>Main Menu</a></td></tr>\n\t\t</table>";
    return $confirm;
}