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


PHP suppledger函数代码示例

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


在下文中一共展示了suppledger函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: confirm_list


//.........这里部分代码省略.........
        } else {
            $bank = pg_fetch_array($rslt);
        }
        db_connect();
        # Supplier name
        $sql = "SELECT supid,supno,supname,deptid FROM suppliers WHERE supid = '{$supid}' AND div = '" . USER_DIV . "'";
        $supRslt = db_exec($sql);
        $sup = pg_fetch_array($supRslt);
        db_conn("exten");
        # get debtors control account
        $sql = "SELECT credacc FROM departments WHERE deptid ='{$sup['deptid']}' AND div = '" . USER_DIV . "'";
        $deptRslt = db_exec($sql);
        $dept = pg_fetch_array($deptRslt);
        # date format
        $sdate = $date;
        $cheqnum = 0 + $cheqnum;
        $pay = "";
        $accdate = $sdate;
        # Paid invoices
        $invidsers = "";
        $rinvids = "";
        $amounts = "";
        $invprds = "";
        $out = "";
        $reference = "";
        db_conn("cubit");
        pglib_transaction("BEGIN");
        $all = 0;
        if ($all == 0) {
            $ids2 = "";
            $purids = "";
            $pamounts = "";
            $pdates = "";
            if (isset($invids)) {
                foreach ($invids as $key => $value) {
                    #debt invoice info
                    $sql = "SELECT id,pdate FROM suppurch WHERE purid ='{$invids[$key]}' AND div = '" . USER_DIV . "' ORDER BY balance LIMIT 1";
                    $invRslt = db_exec($sql) or errDie("Unable to retrieve invoice details from database.");
                    if (pg_numrows($invRslt) < 1) {
                        return "<li class=err>Invalid Invoice Number.";
                    }
                    $pur = pg_fetch_array($invRslt);
                    # reduce the money that has been paid
                    $sql = "UPDATE suppurch SET balance = (balance - '{$paidamt[$key]}'::numeric(13,2)) WHERE purid = '{$invids[$key]}' AND div = '" . USER_DIV . "' AND id='{$pur['id']}'";
                    $payRslt = db_exec($sql) or errDie("Unable to update Invoice information in Cubit.", SELF);
                    $ids2 .= "|{$pur['id']}";
                    $purids .= "|{$invids[$key]}";
                    $pamounts .= "|{$paidamt[$key]}";
                    $pdates .= "|{$pur['pdate']}";
                }
            }
            $samount = $amt - $amt * 2;
            if ($out > 0) {
                recordDT($out, $sup['supid'], $sdate);
            }
            $Sl = "INSERT INTO sup_stmnt(supid, amount, edate, descript,ref,cacc, div) VALUES('{$sup['supid']}','{$samount}','{$sdate}', 'Payment','{$cheqnum}','{$bank['accnum']}', '" . USER_DIV . "')";
            $Rs = db_exec($Sl) or errDie("Unable to insert statement record in Cubit.", SELF);
            db_connect();
            # Update the supplier (make balance less)
            $sql = "UPDATE suppliers SET balance = (balance - '{$amt}'::numeric(13,2)) WHERE supid = '{$sup['supid']}'";
            $rslt = db_exec($sql) or errDie("Unable to update invoice in Cubit.", SELF);
            suppledger($sup['supid'], $bank['accnum'], $sdate, $cheqnum, "Payment for purchases", $amt, "d");
            db_connect();
            # Record the payment record
            $sql = "INSERT INTO cashbook(bankid, trantype, date, name, descript, cheqnum, amount, banked, accinv, supid, ids, purids, pamounts, pdates, reference, div) VALUES ('{$bankid}', 'withdrawal', '{$sdate}', '{$sup['supno']} - {$sup['supname']}', 'Supplier Payment to {$sup['supname']}', '{$cheqnum}', '{$amt}', 'no', '{$dept['credacc']}', '{$sup['supid']}', '{$ids2}', '{$purids}', '{$pamounts}', '{$pdates}', '{$reference}', '" . USER_DIV . "')";
            $Rslt = db_exec($sql) or errDie("Unable to add bank payment to database.", SELF);
            $refnum = getrefnum($accdate);
            db_conn('core');
            $Sl = "SELECT * FROM bankacc WHERE accid='{$bankid}'";
            $Rx = db_exec($Sl) or errDie("Uanble to get bank acc.");
            if (pg_numrows($Rx) < 1) {
                return "Invalid bank acc.";
            }
            $link = pg_fetch_array($Rx);
            $link['accnum'] = $bank['accnum'];
            writetrans($dept['credacc'], $link['accnum'], $accdate, $refnum, $amt, "Supplier Payment to {$sup['supname']}");
            db_conn('cubit');
        }
        $Sl = "DELETE FROM suppurch WHERE balance=0::numeric(13,2)";
        $Rx = db_exec($Sl);
        #add the supplier purchase entry ?
        $purch_sql = "\n\t\t\t\t\t\tINSERT INTO suppurch \n\t\t\t\t\t\t\t(supid,purid,intpurid,pdate,div,npurid,balance,fcid,fbalance) \n\t\t\t\t\t\tVALUES \n\t\t\t\t\t\t\t('{$sup['supid']}','0','0','{$date}','" . USER_DIV . "','0','-{$amt}','0','0.00')";
        $run_purch = db_exec($purch_sql) or errDie("Unable to update supplier purchase information.");
        db_conn('contract');
        $upd_sql = "UPDATE supp_creditor_run_cheques SET remarks = '{$remark[$id]}' WHERE id = '{$id}'";
        $run_upd = db_exec($upd_sql) or errDie("Unable to update contract remittance.");
        #also update the run listing
        $upd2_sql = "UPDATE credit_runs SET remarks = '{$remark[$id]}' WHERE entry_id = '{$id}'";
        $run_upd2 = db_exec($upd2_sql) or errDie("Unable to update creditor run information.");
        pglib_transaction("COMMIT");
    }
    ##PTH/CUBIT
    //	db_conn ("contract");
    //	#process the remarks
    //	foreach ($conid AS $each => $own){
    //		$upd_sql = "UPDATE contract_recs SET remarks = '$remark[$each]' WHERE conid = '$own' AND remit = '$remit[$each]'";
    //		$run_upd = db_exec($upd_sql) or errDie("Unable to update contract remittance.");
    //	}
    return get_list($_POST, "<li class='err'>Cheques Have been recorded.</li>");
}
开发者ID:kumarsivarajan,项目名称:accounting-123,代码行数:101,代码来源:supp-payment-list.php

示例2: write


//.........这里部分代码省略.........
        $Ri = db_exec($Sl);
    }
    $vd = pg_fetch_array($Ri);
    if ($vd['zero'] == "Yes") {
        $excluding = "y";
    } else {
        $excluding = "";
    }
    $vr = vatcalc($pur['shipchrg'], $pur['vatinc'], $excluding, 0, $vd['vat_amount']);
    $vrs = explode("|", $vr);
    $ivat_tmp = $vrs[0];
    $iamount_tmp = $vrs[1];
    vatr($vd['id'], $td, "INPUT", $vd['code'], $refnum, "VAT Paid for Purchase No. {$pur['purnum']} from Supplier : {$pur['supname']}.", sprint(-$iamount_tmp), -$ivat_tmp);
    ####################################################
    /* - Start Hooks - */
    $vatacc = gethook("accnum", "salesacc", "name", "VAT");
    $cvacc = gethook("accnum", "pchsacc", "name", "Cost Variance");
    /* - End Hooks - */
    # Record the payment on the statement
    db_connect();
    $sdate = date("Y-m-d");
    $DAte = date("Y-m-d");
    # update the supplier (make balance more)
    $sql = "UPDATE suppliers SET balance = (balance + '{$TOTAL}') WHERE supid = '{$pur['supid']}' AND div = '" . USER_DIV . "'";
    $rslt = db_exec($sql) or errDie("Unable to update invoice in Cubit.", SELF);
    //$pur['pdate'] -> $td
    $sql = "\n\t\t\tINSERT INTO sup_stmnt (\n\t\t\t\tsupid, edate, cacc, amount, descript, \n\t\t\t\tref, ex, div\n\t\t\t) VALUES (\n\t\t\t\t'{$pur['supid']}', '{$td}', '{$wh['conacc']}', '{$TOTAL}', 'Stock Received - Purchase {$pur['purnum']} Inv:{$supinv}', \n\t\t\t\t'{$refnum}', '{$pur['purnum']}', '" . USER_DIV . "'\n\t\t\t)";
    $stmntRslt = db_exec($sql) or errDie("Unable to insert statement record in Cubit.", SELF);
    # Debit Stock Control and Credit Creditors control
    writetrans($wh['conacc'], $dept['credacc'], $td, $refnum, sprint($SUBTOT + $del), "Invoice Received for Purchase No. {$pur['purnum']} from Supplier : {$pur['supname']}.");
    # Transfer vat
    writetrans($vatacc, $dept['credacc'], $td, $refnum, $VAT, "VAT Paid for Purchase No. {$pur['purnum']} from Supplier : {$pur['supname']}.");
    # Ledger Records
    suppledger($pur['supid'], $wh['conacc'], $td, $pur['purid'], "Purchase No. {$pur['purnum']} received.", $TOTAL, 'c');
    /* End Transactions */
    /* Make transaction record  for age analysis */
    db_connect();
    # update the supplier age analysis (make balance less)
    if (ext_ex2("suppurch", "purid", $pur['purnum'], "supid", $pur['supid'])) {
        # Found? Make amount less
        $sql = "\n\t\t\t\t\tUPDATE suppurch \n\t\t\t\t\tSET balance = (balance + '{$TOTAL}') \n\t\t\t\t\tWHERE supid = '{$pur['supid']}' AND purid = '{$pur['purnum']}' AND div = '" . USER_DIV . "'";
        $rslt = db_exec($sql) or errDie("Unable to update invoice in Cubit.", SELF);
    } else {
        //$pur['pdate'] -> $td
        /* Make transaction record for age analysis */
        $sql = "\n\t\t\t\t\tINSERT INTO suppurch (\n\t\t\t\t\t\tsupid, purid, pdate, balance, div\n\t\t\t\t\t) VALUES (\n\t\t\t\t\t\t'{$pur['supid']}', '{$pur['purnum']}', '{$td}', '{$TOTAL}', '" . USER_DIV . "'\n\t\t\t\t\t)";
        $purcRslt = db_exec($sql) or errDie("Unable to update Order information in Cubit.", SELF);
    }
    /* Make transaction record  for age analysis */
    # commit updating
    $sql = "UPDATE purchases SET iamount = iamount+'{$TOTAL}',ivat=ivat+'{$VAT}' WHERE purid = '{$purid}' AND div = '" . USER_DIV . "'";
    $rslt = db_exec($sql) or errDie("Unable to update Order status in Cubit.", SELF);
    $sql = "SELECT * FROM purchases WHERE purid = '{$purid}' AND div = '" . USER_DIV . "'";
    $purRslt = db_exec($sql) or errDie("Unable to get purchase information");
    $p = pg_fetch_array($purRslt);
    //pglib_transaction ("COMMIT") or errDie("Unable to commit a database transaction.",SELF);
    $sql = "SELECT SUM(iqty) FROM pur_items  WHERE purid = '{$purid}' AND div = '" . USER_DIV . "'";
    $stktRslt = db_exec($sql);
    $data = pg_fetch_array($stktRslt);
    $left = $data['sum'];
    if ($left == 0) {
        /* Start moving if purchase */
        if ($pur['received'] == "y") {
            if (strlen($pur['appdate']) < 8) {
                $pur['appdate'] = date("Y-m-d");
            }
开发者ID:andrecoetzee,项目名称:accounting-123.com,代码行数:67,代码来源:purch-recinvcd.php

示例3: write


//.........这里部分代码省略.........
            # keep records for transactions
            if (isset($totstkamt[$stkacc[$keys]])) {
                $totstkamt[$stkacc[$keys]] += $amt[$keys];
            } else {
                $totstkamt[$stkacc[$keys]] = $amt[$keys];
            }
        }
    }
    /* Transactions */
    /* - Start Hooks - */
    $vatacc = gethook("accnum", "salesacc", "name", "VAT");
    $refnum = getrefnum();
    $sdate = $pur["pdate"];
    //$ddate;
    /* - End Hooks - */
    # record transaction  from data
    foreach ($totstkamt as $stkacc => $wamt) {
        # Debit Stock and Credit Suppliers control
        writetrans($supacc, $stkacc, date("d-m-Y"), $refnum, $wamt, "Non-Stock Purchase No. {$pur['purnum']} Returned to Supplier {$sup['supname']}.");
    }
    db_connect();
    $Sl = "SELECT * FROM vatcodes WHERE id='{$pur['cusid']}'";
    $Ri = db_exec($Sl);
    if (pg_num_rows($Ri) < 1) {
        return "Please select the vatcode for all your stock.";
    }
    $vd = pg_fetch_array($Ri);
    if ($retax > 0) {
        writetrans($supacc, $vatacc, date("d-m-Y"), $refnum, $retax, "Returned, Non-Stock Purchase Vat paid on Non-Stock Order No. {$pur['purnum']}.");
    }
    $retot = sprint(array_sum($amt) + $retax);
    vatr($vd['id'], $pur['pdate'], "INPUT", $vd['code'], $refnum, "Returned, Non-Stock Purchase Vat paid on Non-Stock Order No. {$pur['purnum']}.", $retot, $retax);
    $fretot = sprint(array_sum($famt) + array_sum($ftaxes));
    suppledger($sup['supid'], $stkacc, $sdate, $pur['purid'], "Returned, Non-Stock Purchase No. {$pur['purnum']} received.", $retot, 'd');
    db_connect();
    # update the supplier (make balance more)
    $sql = "UPDATE suppliers SET balance = (balance - '{$retot}'), fbalance = (fbalance - '{$fretot}') WHERE supid = '{$sup['supid']}' AND div = '" . USER_DIV . "'";
    $rslt = db_exec($sql) or errDie("Unable to update invoice in Cubit.", SELF);
    $sql = "INSERT INTO sup_stmnt(supid, edate, cacc, amount, descript,ref,ex,div) VALUES('{$sup['supid']}','{$sdate}', '{$dept['credacc']}', '-{$fretot}','Returned, Non Stock Purchase No. {$pur['purnum']} Received', '{$refnum}', '{$pur['purnum']}','" . USER_DIV . "')";
    $stmntRslt = db_exec($sql) or errDie("Unable to insert statement record in Cubit.", SELF);
    db_connect();
    # make transaction record for age analysis
    $sql = "INSERT INTO suppurch(supid, purid, pdate, fcid, balance, fbalance, div) VALUES('{$sup['supid']}', '{$pur['purnum']}', '{$sdate}', '{$pur['fcid']}', '-{$retot}', '-{$fretot}', '" . USER_DIV . "')";
    $purcRslt = db_exec($sql) or errDie("Unable to update int Orders information in Cubit.", SELF);
    # Commit updating
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    db_conn($prd);
    # check if there are any outstanding items
    $sql = "SELECT * FROM nons_purint_items WHERE purid = '{$purid}' AND (qty - rqty) > '0' AND div = '" . USER_DIV . "'";
    $stkdRslt = db_exec($sql);
    # if none the set to received
    if (pg_numrows($stkdRslt) < 1) {
        # update surch_int(received = 'y')
        $sql = "UPDATE nons_purch_int SET received = 'y' WHERE purid = '{$purid}' AND div = '" . USER_DIV . "'";
        //$rslt = db_exec($sql) or errDie("Unable to update international Orders in Cubit.",SELF);
    }
    # Update Order on the DB
    $sql = "UPDATE nons_purch_int SET refno = '{$refno}' WHERE purid = '{$purid}' AND div = '" . USER_DIV . "'";
    //$rslt = db_exec($sql) or errDie("Unable to update Order in Cubit.",SELF);
    /* End Transactions */
    /* Start moving if Order received */
    db_conn($prd);
    # begin updating
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    $sql = "SELECT * FROM nons_purch_int WHERE purid = '{$purid}' AND div = '" . USER_DIV . "'";
    $purRslt = db_exec($sql) or errDie("Unable to get Order information");
开发者ID:andrecoetzee,项目名称:accounting-123.com,代码行数:67,代码来源:nons-purch-int-return.php

示例4: write


//.........这里部分代码省略.........
    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>";
    }
    if (isset($chrgvat) and $chrgvat == "yes") {
        db_connect();
        #get selected vatcode
        $get_vatcode = "SELECT * FROM vatcodes WHERE id = '{$vatcode}' LIMIT 1";
        $run_vatcode = db_exec($get_vatcode) or errDie("Unable to get vat code information.");
        if (pg_numrows($run_vatcode) < 1) {
            #vatcode not found ....
            return "<li class='err'>Unable to get vat code information.</li>";
        }
        $vd = pg_fetch_array($run_vatcode);
        if ($vatinc == "inc") {
            #vat inc ...  recalc value
            $vatamt = sprint($amount * ($vd['vat_amount'] / (100 + $vd['vat_amount'])));
            $amount = sprint($amount - $vatamt);
        } else {
            #vat excl
            $amount = sprint($amount);
            $vatamt = sprint($amount / 100 * $vd['vat_amount']);
        }
    } else {
        #vat not set
        $amount = sprint($amount);
        $vatamt = sprint(0);
    }
    $date = "{$datea['2']}-{$datea['1']}-{$datea['0']}";
    # Accounts details
    $accRs = get("core", "*", "accounts", "accid", $accid);
    $acc = pg_fetch_array($accRs);
    # Select supplier
    db_connect();
    $sql = "SELECT * FROM suppliers WHERE supid = '{$supid}' AND div = '" . USER_DIV . "'";
    $suppRslt = db_exec($sql) or errDie("Unable to access databse.", SELF);
    if (pg_numrows($suppRslt) < 1) {
        return "<li class='err'>Invalid supplier ID, or supplier has been blocked</li>";
    } else {
        $supp = pg_fetch_array($suppRslt);
    }
    # Get department
    db_conn("exten");
    $sql = "SELECT * FROM departments WHERE deptid = '{$supp['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);
    }
    $supp['supname'] = remval($supp['supname']);
    #get vat acc ...
    //	$vatacc = gethook("accnum", "salesacc", "name", "VAT","VAT");
    $vatacc = gethook("accnum", "salesacc", "name", "VAT", "");
    # Begin updates
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # Probe tran type
    if ($entry == "CT") {
        # Write transaction  (debit contra account, credit debtors control)
        writetrans($accid, $dept['credacc'], $date, $refnum, $amount, $details . " - Supplier {$supp['supname']}");
        $tran = "\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>{$acc['topacc']}/{$acc['accnum']} - {$acc['accname']}</td>\n\t\t\t\t<td>{$supp['supno']} - {$supp['supname']}</td>\n\t\t\t</tr>";
        $samount = $amount - $amount * 2;
        $svatamount = $vatamt - $vatamt * 2;
        recordCT(-$amount, $supp['supid'], $date);
        $type = 'c';
        if (isset($chrgvat) and $chrgvat == "yes") {
            writetrans($vatacc, $dept['credacc'], $date, $refnum, $vatamt, "VAT for Transaction: {$refnum} for Supplier : {$supp['supname']}");
            vatr($vd['id'], $date, "INPUT", $vd['code'], $refnum, "VAT for Transaction: {$refnum} for Supplier : {$supp['supname']}", $samount + $svatamount, $svatamount);
        }
        $balamt = sprint($amount + $vatamt);
    } else {
        # Write transaction  (debit debtors control, credit contra account)
        writetrans($dept['credacc'], $accid, $date, $refnum, $amount, $details . " - Supplier {$supp['supname']}");
        $tran = "\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>{$supp['supno']} - {$supp['supname']}</td>\n\t\t\t\t<td>{$acc['topacc']}/{$acc['accnum']} - {$acc['accname']}</td>\n\t\t\t</tr>";
        $samount = $amount;
        $svatamount = $vatamt;
        recordDT($amount, $supp['supid'], $date);
        $type = 'd';
        if (isset($chrgvat) and $chrgvat == "yes") {
            //			writetrans($vatacc, $dept['credacc'], $date, $refnum, $vatamt, "VAT for Transaction: $refnum for Supplier : $supp[supname]");
            writetrans($dept['credacc'], $vatacc, $date, $refnum, $vatamt, "VAT for Transaction: {$refnum} for Supplier : {$supp['supname']}");
            vatr($vd['id'], $date, "INPUT", $vd['code'], $refnum, "VAT for Transaction: {$refnum} for Supplier : {$supp['supname']}", $samount + $svatamount, $svatamount);
        }
        $balamt = sprint($amount - $amount * 2 + ($vatamt - $vatamt * 2));
    }
    db_connect();
    $edate = date("Y-m-d");
    # record the payment on the statement
    $sql = "\n\t\tINSERT INTO sup_stmnt (\n\t\t\tsupid, edate, ref, cacc, descript, amount, div\n\t\t) VALUES (\n\t\t\t'{$supp['supid']}', '{$date}', '0', '{$accid}', '{$details}', '" . sprint($balamt) . "', '" . USER_DIV . "'\n\t\t)";
    $stmntRslt = db_exec($sql) or errDie("Unable to Insert statement record in Cubit.", SELF);
    # update the supplier (make balance more)
    $sql = "UPDATE suppliers SET balance = (balance + '{$balamt}') WHERE supid = '{$supp['supid']}' AND div = '" . USER_DIV . "'";
    $rslt = db_exec($sql) or errDie("Unable to update supplier in Cubit.", SELF);
    # Ledger Records
    suppledger($supp['supid'], $accid, $date, $refnum, $details, sprint($amount + $vatamt), $type);
    # Commit updates
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    // Start layout
    $write = "\n\t\t<h3>Supplier Journal transaction has been recorded</h3>\n\t\t<table " . TMPL_tblDflts . ">\n\t\t\t<tr>\n\t\t\t\t<td width='50%'><h3>Debit</h3></td>\n\t\t\t\t<td width='50%'><h3>Credit</h3></td>\n\t\t\t</tr>\n\t\t\t{$tran}\n\t\t\t" . TBL_BR . "\n\t\t\t<tr colspan='2'>\n\t\t\t\t<td><h4>Amount</h4></td>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td colspan='2'><b>" . CUR . " {$amount}</b></td>\n\t\t\t</tr>\n\t\t</table>\n\t\t<P>\n\t\t<table " . TMPL_tblDflts . " width='25%'>\n\t\t\t<tr>\n\t\t\t\t<th>Quick Links</th>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td align='center'><a href='trans-new.php'>Journal Transactions</td>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td align='center'><a href='../supp-view.php'>View Suppliers</a></td>\n\t\t\t</tr>\n\t\t\t<script>document.write(getQuicklinkSpecial());</script>\n\t\t</table>";
    return $write;
}
开发者ID:andrecoetzee,项目名称:accounting-123.com,代码行数:101,代码来源:supp-trans.php

示例5: bwrite


//.........这里部分代码省略.........
        $sql = "\n\t\t\t\tUPDATE nons_purchases \n\t\t\t\tSET ctyp = '{$ctyp}', typeid = '{$typeid}', refno = '{$refno}', remarks = '{$remarks}' \n\t\t\t\tWHERE purid = '{$purid}' AND div = '" . USER_DIV . "'";
        $rslt = db_exec($sql) or errDie("Unable to update Order in Cubit.", SELF);
    }
    /* Transactions */
    $refnum = getrefnum(date("d-m-Y"));
    /* - Start Hooks - */
    $vatacc = gethook("accnum", "salesacc", "name", "VAT");
    /* - End Hooks - */
    $detadd = "";
    if (isset($supid)) {
        $detadd = " from Supplier {$sup['supname']}";
    }
    $sdate = $pur['pdate'];
    $tpp = 0;
    $ccamt = 0;
    # record transaction  from data
    foreach ($totstkamt as $stkacc => $wamt) {
        # Debit Stock and Credit Suppliers control
        writetrans($stkacc, $supacc, date("d-m-Y"), $refnum, $wamt, "Non-Stock Purchase No. {$pur['purnum']} Received {$detadd}.");
        pettyrec($supacc, $sdate, "ct", "Non-Stock Purchase No. {$pur['purnum']} Received {$detadd}.", $wamt, "Cash Order");
    }
    # vat
    $vatamt = $revat;
    # Add vat if not included
    if ($pur['vatinc'] == 'no') {
        $retot = $resub + $vatamt;
    } elseif ($pur['vatinc'] == "novat") {
        $retot = $resub;
        $vatamt = 0;
    } else {
        $retot = $resub;
    }
    if (isset($supid)) {
        # Ledger Records
        $DAte = $pur['pdate'];
        suppledger($sup['supid'], $stkacc, $DAte, $pur['purid'], "Non-Stock Purchase No. {$pur['purnum']} received.", $retot, 'c');
    }
    if ($vatamt != 0) {
        # Debit bank and credit the account involved
        writetrans($vatacc, $supacc, date("d-m-Y"), $refnum, $vatamt, "Non-Stock Purchase VAT paid on Non-Stock Order No. {$pur['purnum']} {$detadd}.");
        pettyrec($supacc, $sdate, "ct", "Non-Stock Purchase No. {$pur['purnum']} Received {$detadd}.", $vatamt, "Cash Order VAT");
        # Record the payment on the statement
        db_connect();
        $sdate = $pur['pdate'];
    }
    if (isset($supid)) {
        $DAte = $pur['pdate'];
        db_connect();
        # update the supplier (make balance more)
        $sql = "UPDATE suppliers SET balance = (balance + '{$retot}') WHERE supid = '{$sup['supid']}' AND div = '" . USER_DIV . "'";
        $rslt = db_exec($sql) or errDie("Unable to update invoice in Cubit.", SELF);
        $sql = "\n\t\t\t\tINSERT INTO sup_stmnt (\n\t\t\t\t\tsupid, edate, cacc, amount, descript, ref, ex, div\n\t\t\t\t) VALUES (\n\t\t\t\t\t'{$sup['supid']}','{$DAte}', '{$dept['credacc']}', '{$retot}', 'Non Stock Purchase No. {$pur['purnum']} Received', '{$refnum}', '{$pur['purnum']}', '" . USER_DIV . "'\n\t\t\t\t)";
        $stmntRslt = db_exec($sql) or errDie("Unable to insert statement record in Cubit.", SELF);
        db_connect();
        # update the supplier age analysis (make balance less)
        /* Make transaction record for age analysis */
        $sql = "\n\t\t\t\tINSERT INTO suppurch (\n\t\t\t\t\tsupid, purid, pdate, balance, div\n\t\t\t\t) VALUES (\n\t\t\t\t\t'{$sup['supid']}', '{$pur['purnum']}', '{$DAte}', '{$retot}', '" . USER_DIV . "'\n\t\t\t\t)";
        $purcRslt = db_exec($sql) or errDie("Unable to update int Orders information in Cubit.", SELF);
    }
    # commit updating
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    /* End Transactions */
    /* Start moving if Order received */
    # Get Order info
    db_connect();
    $sql = "SELECT * FROM nons_purchases WHERE purid = '{$purid}' AND div = '" . USER_DIV . "'";
    $purRslt = db_exec($sql) or errDie("Unable to get Order information");
    if (pg_numrows($purRslt) < 1) {
        return "<li>- Order Not Found</li>";
    }
    $pur = pg_fetch_array($purRslt);
    if ($pur['received'] == "y") {
        # copy Order
        db_conn($pur['prd']);
        $sql = "\n\t\t\t\tINSERT INTO nons_purchases (\n\t\t\t\t\tpurid, deptid, supplier, supaddr, terms, pdate, ddate, \n\t\t\t\t\tshipchrg, shipping, subtot, total, balance, vatinc, vat, \n\t\t\t\t\tremarks, refno, received, done, ctyp, typeid, div, purnum\n\t\t\t\t) VALUES (\n\t\t\t\t\t'{$purid}', '{$pur['deptid']}', '{$pur['supplier']}',  '{$pur['supaddr']}', '{$pur['terms']}', '{$pur['pdate']}', '{$pur['ddate']}', \n\t\t\t\t\t'{$pur['shipchrg']}', '{$pur['shipping']}', '{$pur['subtot']}', '{$pur['total']}', '0', '{$pur['vatinc']}', '{$pur['vat']}', \n\t\t\t\t\t'{$pur['remarks']}', '{$pur['refno']}', 'y', 'y', '{$pur['ctyp']}', '{$pur['typeid']}', '" . USER_DIV . "', '{$pur['purnum']}'\n\t\t\t\t)";
        $rslt = db_exec($sql) or errDie("Unable to insert Non-Stock Order to Cubit.", SELF);
        db_connect();
        # Get selected stock
        $sql = "SELECT * FROM nons_pur_items WHERE purid = '{$purid}' AND div = '" . USER_DIV . "'";
        $stktcRslt = db_exec($sql);
        while ($stktc = pg_fetch_array($stktcRslt)) {
            # Insert Order items
            db_conn($pur['prd']);
            $sql = "\n\t\t\t\t\tINSERT INTO nons_pur_items (\n\t\t\t\t\t\tpurid, cod, des, qty, unitcost, amt, \n\t\t\t\t\t\tsvat, ddate, accid, div\n\t\t\t\t\t) VALUES (\n\t\t\t\t\t\t'{$purid}', '{$stktc['cod']}', '{$stktc['des']}', '{$stktc['qty']}', '{$stktc['unitcost']}', '{$stktc['amt']}', \n\t\t\t\t\t\t'{$stktc['svat']}', '{$stktc['ddate']}', '{$stktc['accid']}', '" . USER_DIV . "'\n\t\t\t\t\t)";
            $rslt = db_exec($sql) or errDie("Unable to insert Order items to Cubit.", SELF);
        }
        db_connect();
        # Remove the Order from running DB
        $sql = "DELETE FROM nons_purchases WHERE purid = '{$purid}' AND div = '" . USER_DIV . "'";
        $delRslt = db_exec($sql) or errDie("Unable to update int Orders information in Cubit.", SELF);
        # Remove those Order items from running DB
        $sql = "DELETE FROM nons_pur_items WHERE purid = '{$purid}' AND div = '" . USER_DIV . "'";
        $delRslt = db_exec($sql) or errDie("Unable to update int Orders information in Cubit.", SELF);
    }
    /* End moving Order received */
    $cc = "<script> CostCenter('ct', 'Non-Stock Purchase', '{$pur['pdate']}', 'Non Stock Purchase No.{$pur['purnum']}', '" . ($retot - $vatamt) . "', ''); </script>";
    // Final Layout
    $write = "\n\t\t{$cc}\n\t\t<table " . TMPL_tblDflts . ">\n\t\t\t<tr>\n\t\t\t\t<th>Non-Stock Order received</th>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>Non-Stock Order receipt has been recorded.</td>\n\t\t\t</tr>\n\t\t</table>\n\t\t<p>\n\t\t<table " . TMPL_tblDflts . ">\n\t\t\t<tr>\n\t\t\t\t<th>Quick Links</th>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td><a href='nons-purchase-view.php'>View Orders</a></td>\n\t\t\t</tr>\n\t\t\t<script>document.write(getQuicklinkSpecial());</script>\n\t\t</table>";
    return $write;
}
开发者ID:andrecoetzee,项目名称:accounting-123.com,代码行数:101,代码来源:nons-purch-return.php

示例6: write


//.........这里部分代码省略.........
        $ids = "";
        $purids = "";
        $fpamounts = "";
        $pamounts = "";
        $pdates = "";
        # Begin updates
        # pglib_transaction ("BEGIN") or errDie("Unable to start a database transaction.",SELF);
        if (isset($invids)) {
            foreach ($invids as $key => $value) {
                $lpaidamt[$key] = sprint($paidamt[$key] * $rate);
                #debt invoice info
                $sql = "SELECT id,pdate FROM suppurch WHERE purid ='{$invids[$key]}' AND div = '" . USER_DIV . "' ORDER BY fbalance LIMIT 1";
                $invRslt = db_exec($sql) or errDie("Unable to retrieve invoice details from database.");
                if (pg_numrows($invRslt) < 1) {
                    return "<li class='err'>Invalid Invoice Number.</li>";
                }
                $pur = pg_fetch_array($invRslt);
                # reduce the money that has been paid
                $sql = "UPDATE suppurch SET balance = (balance - '{$lpaidamt[$key]}'::numeric(13,2)), fbalance = (fbalance - '{$paidamt[$key]}'::numeric(13,2)) WHERE purid = '{$invids[$key]}' AND div = '" . USER_DIV . "' AND id='{$pur['id']}'";
                $payRslt = db_exec($sql) or errDie("Unable to update Invoice information in Cubit.", SELF);
                $ids .= "|{$pur['id']}";
                $purids .= "|{$invids[$key]}";
                $fpamounts .= "|{$paidamt[$key]}";
                $pamounts .= "|{$lpaidamt[$key]}";
                $pdates .= "|{$pur['pdate']}";
            }
        }
        $samount = $amt - $amt * 2;
        if ($out > 0) {
            recordDT($out, $sup['supid']);
        }
        $Sl = "INSERT INTO sup_stmnt(supid, amount, edate, descript,ref,cacc, div) VALUES('{$sup['supid']}','{$samount}','{$sdate}', 'Payment','{$cheqnum}','{$bank['accnum']}', '" . USER_DIV . "')";
        $Rs = db_exec($Sl) or errDie("Unable to insert statement record in Cubit.", SELF);
        suppledger($sup['supid'], $bank['accnum'], $sdate, $cheqnum, "Payment for purchases", $lamt, "d");
        db_connect();
        # Update the supplier (make fbalance less)
        $sql = "UPDATE suppliers SET balance = (balance - '{$lamt}'::numeric(13,2)), fbalance = (fbalance - '{$amt}'::numeric(13,2)) WHERE supid = '{$sup['supid']}'";
        $rslt = db_exec($sql) or errDie("Unable to update invoice in Cubit.", SELF);
        # Record the payment record
        // $sql = "INSERT INTO cashbook(bankid, trantype, date, name, descript, cheqnum, amount, banked, accinv, supid, ids, purids, pamounts, pdates, div) VALUES ('$bankid', 'withdrawal', '$sdate', '$sup[supno] - $sup[supname]', 'Supplier Payment to $sup[supname]', '$cheqnum', '$lamt', 'no', '$dept[credacc]', '$sup[supid]', '$ids', '$purids', '$pamounts', '$pdates', '".USER_DIV."')";
        //2 $sql = "INSERT INTO cashbook(bankid, trantype, date, name, descript, cheqnum, amount, famount, banked, accinv, supid, ids, purids, pamounts, pdates, div) VALUES ('$bankid', 'withdrawal', '$sdate', '$sup[supno] - $sup[supname]', 'Supplier Payment to $sup[supname]', '$cheqnum', '$lamt', '$amt', 'no', '$dept[credacc]', '$sup[supid]', '$ids', '$purids', '$pamounts', '$pdates', '".USER_DIV."')";
        $sql = "INSERT INTO cashbook(bankid, trantype, date, name, descript, cheqnum, amount, famount, banked, accinv, supid, ids, purids, pamounts, fpamounts, pdates, fcid, currency, location, div) VALUES ('{$bankid}', 'withdrawal', '{$sdate}', '{$sup['supno']} - {$sup['supname']}', 'Supplier Payment to {$sup['supname']}', '{$cheqnum}', '{$lamt}', '{$amt}', 'no', '{$dept['credacc']}', '{$sup['supid']}', '{$ids}', '{$purids}', '{$pamounts}', '{$fpamounts}', '{$pdates}', '{$sup['fcid']}', '{$sup['currency']}', '{$sup['location']}', '" . USER_DIV . "')";
        $Rslt = db_exec($sql) or errDie("Unable to add bank payment to database.", SELF);
        # Update the bankacct table (make fbalance less) [used for cashbook fc value]
        $sql = "UPDATE bankacct SET balance = (balance - '{$lamt}'::numeric(13,2)), fbalance = (fbalance - '{$amt}'::numeric(13,2)) WHERE bankid = '{$bankid}' AND div = '" . USER_DIV . "'";
        $rslt = db_exec($sql) or errDie("Unable to update invoice in Cubit.", SELF);
        $refnum = getrefnum($accdate);
        db_conn('core');
        $Sl = "SELECT * FROM bankacc WHERE accid='{$bankid}'";
        $Rx = db_exec($Sl) or errDie("Uanble to get bank acc.");
        if (pg_numrows($Rx) < 1) {
            return "Invalid bank acc.";
        }
        $link = pg_fetch_array($Rx);
        writetrans($dept['credacc'], $link['accnum'], $accdate, $refnum, $lamt, "Supplier Payment to {$sup['supname']}");
        db_conn('cubit');
        # Commit updates
        # pglib_transaction ("COMMIT") or errDie("Unable to commit a database transaction.",SELF);
    }
    if ($all == 1) {
        $ids = "";
        $purids = "";
        $fpamounts = "";
        $pamounts = "";
        $pdates = "";
        # Begin updates
开发者ID:andrecoetzee,项目名称:accounting-123.com,代码行数:67,代码来源:bank-pay-supp-int.php

示例7: do_trans

function do_trans($_POST)
{
    extract($_POST);
    global $complete;
    #use the perm file we saved in the previous function ...
    $filename_path = $filename_path . "1";
    #now parse it into $complete
    parseXML($filename_path);
    db_connect();
    //print "<pre>";
    //var_dump($complete);
    //print "</pre>";
    pglib_transaction("BEGIN") or errDie("Unable to start transaction.");
    if (isset($complete["DEBTOR"]) and is_array($complete["DEBTOR"])) {
        foreach ($complete["DEBTOR"] as $jobjs) {
            $parms = $jobjs->cols;
            $debtor = $complete["DEBTOR"][$parms["iid"]]->cols;
            if (!isset($debtadd[$parms["accno"]]) or strlen($debtadd[$parms["accno"]]) < 1) {
                continue;
            }
            #this debtor is checked for adding ... so add it
            $ins_sql = "\n\t\t\t\tINSERT INTO customers (\n\t\t\t\t\taccno,surname,title,init,category,class,paddr1,addr1,contname,bustel,tel,cellno,fax,email,saleterm,traddisc,setdisc,pricelist,chrgint,overdue,chrgvat,credterm,odate,credlimit,blocked,deptid,vatnum,div,url,ddiv,intrate,balance,day30,day60,day90,day120,classname,catname,deptname,fbalance,fcid,location,currency,lead_source,comments,del_addr1,sales_rep,bankname,branname,brancode,bankaccno,bankaccname,team_id,registration,bankacctype\n\t\t\t\t) VALUES (\n\t\t\t\t\t'{$parms['accno']}','{$parms['surname']}','{$parms['title']}','{$parms['init']}','{$parms['category']}','{$parms['class']}','{$parms['paddr1']}','{$parms['addr1']}','{$parms['contname']}','{$parms['bustel']}','{$parms['tel']}','{$parms['cellno']}','{$parms['fax']}','{$parms['email']}','{$parms['saleterm']}','{$parms['traddisc']}','{$parms['setdisc']}','{$parms['pricelist']}','{$parms['chrgint']}','{$parms['overdue']}','{$parms['chrgvat']}','{$parms['credterm']}','{$parms['odate']}','{$parms['credlimit']}','{$parms['blocked']}','{$parms['deptid']}','{$parms['vatnum']}','{$parms['div']}','{$parms['url']}','{$parms['ddiv']}','{$parms['intrate']}','{$parms['balance']}','{$parms['day30']}','{$parms['day60']}','{$parms['day90']}','{$parms['day120']}','{$parms['classname']}','{$parms['catname']}','{$parms['deptname']}','{$parms['fbalance']}','{$parms['fcid']}','{$parms['location']}','{$parms['currency']}','{$parms['lead_source']}','{$parms['comments']}','{$parms['del_addr1']}','{$parms['sales_rep']}','{$parms['bankname']}','{$parms['branname']}','{$parms['brancode']}','{$parms['bankaccno']}','{$parms['bankaccname']}','{$parms['team_id']}','{$parms['registration']}','{$parms['bankacctype']}'\n\t\t\t\t)";
            $run_ins = db_exec($ins_sql) or errDie("Unable to add debtor information.");
        }
    }
    if (isset($complete["CREDITOR"]) and is_array($complete["CREDITOR"])) {
        foreach ($complete["CREDITOR"] as $jobjs) {
            $parms = $jobjs->cols;
            $creditor = $complete["CREDITOR"][$parms["iid"]]->cols;
            if (!isset($suppadd[$parms["supno"]]) or strlen($suppadd[$parms["supno"]]) < 1) {
                continue;
            }
            #this creditor is checked for adding ... so add it
            $ins_sql = "\n\t\t\t\tINSERT INTO suppliers (\n\t\t\t\t\tsupno,supname,supaddr,contname,tel,fax,email,bankname,branname,brancode,bankaccno,deptid,vatnum,div,url,ddiv,balance,listid,fbalance,fcid,location,currency,lead_source,comments,branch,groupid,reference,bee_status,team_id,registration,bankaccname,bankacctype\n\t\t\t\t) VALUES (\n\t\t\t\t\t'{$parms['supno']}','{$parms['supname']}','{$parms['supaddr']}','{$parms['contname']}','{$parms['tel']}','{$parms['fax']}','{$parms['email']}','{$parms['bankname']}','{$parms['branname']}','{$parms['brancode']}','{$parms['bankaccno']}','{$parms['deptid']}','{$parms['vatnum']}','{$parms['div']}','{$parms['url']}','{$parms['ddiv']}','{$parms['balance']}','{$parms['listid']}','{$parms['fbalance']}','{$parms['fcid']}','{$parms['location']}','{$parms['currency']}','{$parms['lead_source']}','{$parms['comments']}','{$parms['branch']}','{$parms['groupid']}','{$parms['reference']}','{$parms['bee_status']}','{$parms['team_id']}','{$parms['registration']}','{$parms['bankaccname']}','{$parms['bankacctype']}'\n\t\t\t\t)";
            $run_ins = db_exec($ins_sql) or errDie("Unable to add supplier information.");
        }
    }
    $sdate = date("Y-m-d");
    if (isset($complete["JOURNAL"]) and is_array($complete["JOURNAL"])) {
        foreach ($complete["JOURNAL"] as $jobjs) {
            $parms = $jobjs->cols;
            $doid = $jobjs->id;
            #check if we should run this transaction
            if (!isset($replay[$doid]) or strlen($replay[$doid]) < 1) {
                continue;
            }
            if (!isset($parms["debitacc"])) {
                $parms["debitacc"] = "0";
            }
            db_connect();
            switch ($jobjs->type) {
                case "DEBTOR":
                    $debtor = $complete["DEBTOR"][$parms["iid"]]->cols;
                    if (!isset($parms['creditacc'])) {
                        $parms['creditacc'] = "0";
                    }
                    if ($parms['debitacc'] == '0' and $parms['creditacc'] == '0') {
                        #its not 1 of the custom saves ... so do generic ...
                        # record the payment on the statement
                        $sql = "\n\t\t\t\t\t\t\tINSERT INTO stmnt (\n\t\t\t\t\t\t\t\tcusnum, invid, amount, date, type, st, div, allocation_date\n\t\t\t\t\t\t\t) VALUES (\n\t\t\t\t\t\t\t\t'{$parms['iid']}', '0', '{$parms['amount']}', '{$parms['date']}', '{$parms['details']}', 'n', '" . USER_DIV . "', '{$parms['date']}'\n\t\t\t\t\t\t\t)";
                        $stmntRslt = db_exec($sql) or errDie("Unable to Insert statement record in Cubit.", SELF);
                        $sql = "INSERT INTO open_stmnt(cusnum, invid, amount, balance, date, type, st, div) VALUES('{$parms['iid']}', '0', '{$parms['amount']}', '{$parms['amount']}', '{$parms['date']}', '{$parms['details']}', 'n', '" . USER_DIV . "')";
                        $stmntRslt = db_exec($sql) or errDie("Unable to Insert statement record in Cubit.", SELF);
                        # update the customer (make balance more)
                        $sql = "UPDATE customers SET balance = (balance + '{$parms['amount']}') WHERE cusnum = '{$parms['iid']}' AND div = '" . USER_DIV . "'";
                        $rslt = db_exec($sql) or errDie("Unable to update customer in Cubit.", SELF);
                    } else {
                        if ($parms['debitacc'] == '0') {
                            if ($parms['creditacc'] == '1') {
                                recordCT($parms['amount'], $parms['iid'], $parms['date']);
                            } else {
                                custledger($parms['iid'], $parms['creditacc'], $parms['date'], $parms['refno'], $parms['details'], $parms['amount'], 'c');
                            }
                        } elseif ($parms['creditacc'] == '0') {
                            if ($parms['debitacc'] == '1') {
                                recordDT($parms['amount'], $parms['iid'], $parms['date']);
                            } else {
                                custledger($parms['iid'], $parms['creditacc'], $parms['date'], $parms['refno'], $parms['details'], $parms['amount'], 'd');
                            }
                        }
                    }
                    break;
                case "CREDITOR":
                    $creditor = $complete["CREDITOR"][$parms["iid"]]->cols;
                    if ($parms['debitacc'] == '0') {
                        if ($parms['creditacc'] == '1') {
                            recordCT(-$parms['amount'], $parms['iid'], $parms['date']);
                        } else {
                            suppledger($parms['iid'], $parms['creditacc'], $parms['date'], $parms['refno'], $parms['details'], $parms['amount'], 'c');
                        }
                    } elseif ($parms['creditacc'] == '0') {
                        if ($parms['debitacc'] == '1') {
                            recordDT($parms['amount'], $parms['iid'], $parms['date']);
                        } else {
                            suppledger($parms['iid'], $parms['debitacc'], $parms['date'], $parms['refno'], $parms['details'], $parms['amount'], 'd');
                        }
                    } elseif ($parms['debitacc'] == "9999" or $parms['creditacc'] == "9999") {
                        # record the payment on the statement
                        $sql = "INSERT INTO sup_stmnt(supid, edate, ref, cacc, descript, amount, div) VALUES('{$parms['iid']}', '{$parms['date']}', '0', '{$parms['refno']}', '{$parms['details']}', '{$parms['amount']}', '" . USER_DIV . "')";
                        $stmntRslt = db_exec($sql) or errDie("Unable to Insert statement record in Cubit.", SELF);
//.........这里部分代码省略.........
开发者ID:andrecoetzee,项目名称:accounting-123.com,代码行数:101,代码来源:replay-file-trans.php

示例8: write

function write($_POST)
{
    # Processes
    db_connect();
    # Get vars
    extract($_POST);
    if (isset($back)) {
        return add($_POST);
    }
    # validate input
    require_lib("validate");
    $v = new validate();
    $v->isOk($bankid, "num", 1, 30, "Invalid Bank Account.");
    $v->isOk($date, "date", 1, 10, "Invalid Date Entry.");
    $v->isOk($descript, "string", 0, 255, "Invalid Description.");
    $v->isOk($reference, "string", 0, 50, "Invalid Reference Name/Number.");
    $v->isOk($cheqnum, "num", 0, 30, "Invalid Cheque number.");
    $v->isOk($amount, "float", 1, 10, "Invalid amount.");
    $v->isOk($supid, "num", 1, 20, "Invalid Supplier account.");
    # Display errors, if any
    if ($v->isError()) {
        $confirm = "";
        $errors = $v->getErrors();
        foreach ($errors as $e) {
            $confirm .= "<li class='err'>" . $e["msg"] . "</li>";
        }
        $confirm .= "<p><input type='button' onClick='JavaScript:history.back();' value='&laquo; Correct submission'>";
        return $confirm;
    }
    # 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>";
    }
    # Date format
    $date = explode("-", $date);
    $date = $date[2] . "-" . $date[1] . "-" . $date[0];
    $cheqnum = 0 + $cheqnum;
    # 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);
    # Get account name
    $supRslt = get("cubit", "*", "suppliers", "supid", $supid);
    $sup = pg_fetch_array($supRslt);
    $bankaccid = getbankaccid($bankid);
    db_conn("exten");
    # Get debtors control account
    $sql = "SELECT credacc FROM departments WHERE deptid ='{$sup['deptid']}' AND div = '" . USER_DIV . "'";
    $deptRslt = db_exec($sql);
    $dept = pg_fetch_array($deptRslt);
    pglib_transaction("BEGIN");
    db_connect();
    $Sl = "INSERT INTO sup_stmnt(supid, amount, edate, descript,ref,cacc, div) VALUES('{$supid}','{$amount}','{$date}', '{$descript}','{$cheqnum}','{$bankaccid}', '" . USER_DIV . "')";
    $Rs = db_exec($Sl) or errDie("Unable to insert statement record in Cubit.", SELF);
    # Update the supplier (make balance less)
    $sql = "UPDATE suppliers SET balance = (balance + '{$amount}') WHERE supid = '{$supid}' AND div = '" . USER_DIV . "'";
    $rslt = db_exec($sql) or errDie("Unable to update invoice in Cubit.", SELF);
    suppCT($amount, $supid, $date);
    # record the payment record
    db_connect();
    $sql = "INSERT INTO cashbook(bankid, trantype, date, name, descript, cheqnum, amount, banked, accinv, suprec, reference, div) VALUES ('{$bankid}', 'deposit', '{$date}', '{$sup['supno']} - {$sup['supname']}', '{$descript}', '{$cheqnum}', '{$amount}', 'no', '{$dept['credacc']}', '{$supid}', '{$reference}', '" . USER_DIV . "')";
    $Rslt = db_exec($sql) or errDie("Unable to add bank payment to database.", SELF);
    $refnum = getrefnum();
    # DT(account involved), CT(bank)
    writetrans($bankaccid, $dept['credacc'], $date, $refnum, $amount, $descript);
    suppledger($supid, $bankaccid, $date, 0, $descript, $amount, 'c');
    pglib_transaction("COMMIT");
    # Status report
    $write = "\n\t\t\t\t<table " . TMPL_tblDflts . " width='100%'>\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<th>Bank Receipt</th>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr class='datacell'>\n\t\t\t\t\t\t<td>Bank Receipt from supplier : {$sup['supname']} added to cash book.</td>\n\t\t\t\t\t</tr>\n\t\t\t\t</table>";
    # main table (layout with menu)
    $OUTPUT = "\n\t\t\t\t<center>\n\t\t\t\t<table width='90%'>\n\t\t\t\t\t<tr valign='top'>\n\t\t\t\t\t\t<td width='50%'>{$write}</td>\n\t\t\t\t\t\t<td align='center'>\n\t\t\t\t\t\t\t<table " . TMPL_tblDflts . " width='80%'>\n\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t<th>Quick Links</th>\n\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t\t\t<td><a href='bank-pay-add.php'>Add Bank Payment</a></td>\n\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t\t\t<td><a href='bank-recpt-add.php'>Add Bank Receipt</a></td>\n\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t\t\t<td><a href='cashbook-view.php'>View Cash Book</a></td>\n\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t</table>\n\t\t\t\t\t\t</td>\n\t\t\t\t\t</tr>\n\t\t\t\t</table>";
    return $OUTPUT;
}
开发者ID:andrecoetzee,项目名称:accounting-123.com,代码行数:76,代码来源:bank-recpt-supp.php

示例9: write


//.........这里部分代码省略.........
        if (isset($invids)) {
            db_connect();
            foreach ($invids as $key => $value) {
                # Get debt invoice info
                $sql = "SELECT id,pdate FROM suppurch WHERE purid ='{$invids[$key]}' AND div = '" . USER_DIV . "' ORDER BY balance LIMIT 1";
                $invRslt = db_exec($sql) or errDie("Unable to retrieve invoice details from database.");
                if (pg_numrows($invRslt) < 1) {
                    return "<li class='err'>Invalid Invoice Number.</li>";
                }
                $pur = pg_fetch_array($invRslt);
                # reduce the money that has been paid
                $sql = "UPDATE suppurch SET balance = (balance - '{$paidamt[$key]}'::numeric(13,2)) WHERE purid = '{$invids[$key]}' AND div = '" . USER_DIV . "' AND id='{$pur['id']}'";
                $payRslt = db_exec($sql) or errDie("Unable to update Invoice information in Cubit.", SELF);
                $samount = $paidamt[$key] - $paidamt[$key] * 2;
                $Sl = "\n\t\t\t\t\t\tINSERT INTO sup_stmnt (\n\t\t\t\t\t\t\tsupid, amount, edate, \n\t\t\t\t\t\t\tdescript, ref, cacc, \n\t\t\t\t\t\t\tdiv\n\t\t\t\t\t\t) VALUES (\n\t\t\t\t\t\t\t'{$sup['supid']}', '{$samount}', '{$sdate}', \n\t\t\t\t\t\t\t'Payment - Purchase: {$invids[$key]}', '{$cheqnum}', '{$bank['accnum']}', \n\t\t\t\t\t\t\t'" . USER_DIV . "'\n\t\t\t\t\t\t)";
                $Rs = db_exec($Sl) or errDie("Unable to insert statement record in Cubit.", SELF);
                #record the settlement discount on the statement
                #we record the total settlement below with a negative (correct?) amount ...
                #why do this here ??? -> so we have individual amount on statement ...
                #rather use this ... but with negative amount ... (fixed)
                if ($stock_setamt[$key] > 0) {
                    db_conn('core');
                    #get settlement accid
                    $get_setacc = "SELECT accid FROM accounts WHERE accname = 'Creditors Settlement Discount'";
                    $run_setacc = db_exec($get_setacc) or errDie("Unable to get settlement account information");
                    $setaccid = pg_fetch_result($run_setacc, 0, 0);
                    db_connect();
                    $sql = "\n\t\t\t\t\t\t\tINSERT INTO sup_stmnt (\n\t\t\t\t\t\t\t\tsupid, amount, edate, \n\t\t\t\t\t\t\t\tdescript, \n\t\t\t\t\t\t\t\tref, cacc, div\n\t\t\t\t\t\t\t) VALUES (\n\t\t\t\t\t\t\t\t'{$sup['supid']}', '" . sprint($stock_setamt[$key] - 2 * $stock_setamt[$key]) . "', '{$sdate}', \n\t\t\t\t\t\t\t\t'Settlement Discount for Invoice (Ref. {$reference}): {$invids[$key]}', \n\t\t\t\t\t\t\t\t'{$cheqnum}','{$setaccid}', '" . USER_DIV . "'\n\t\t\t\t\t\t\t)";
                    $stmntRslt = db_exec($sql) or errDie("Unable to insert statement record in Cubit.", SELF);
                    # reduce the money (settlement) that has been paid
                    $sql = "UPDATE suppurch SET balance = (balance - '{$stock_setamt[$key]}'::numeric(13,2)) WHERE purid = '{$invids[$key]}' AND div = '" . USER_DIV . "' AND id='{$pur['id']}'";
                    $payRslt = db_exec($sql) or errDie("Unable to update Invoice information in Cubit.", SELF);
                    #record settlement discount in supp ledger
                    suppledger($sup['supid'], $setaccid, $sdate, $invids[$key], "Settlement Discount On Payment for Purchase No. {$invids[$key]}", $stock_setamt[$key], "d");
                }
                db_connect();
                # Update the supplier (make balance less)
                $sql = "UPDATE suppliers SET balance = (balance - '{$stock_setamt[$key]}'::numeric(13,2)) WHERE supid = '{$sup['supid']}' AND div = '" . USER_DIV . "'";
                $rslt = db_exec($sql) or errDie("Unable to update invoice in Cubit.", SELF);
                #record purchase in supp ledger
                suppledger($sup['supid'], $bank['accnum'], $sdate, $invids[$key], "Payment for Purchase No. {$invids[$key]}", $paidamt[$key], "d");
                db_connect();
                # record the payment on the statement
                $ids .= "|{$pur['id']}";
                $purids .= "|{$invids[$key]}";
                $pamounts .= "|{$paidamt[$key]}";
                $pdates .= "|{$pur['pdate']}";
                #record this for printing ...
                $save_sql2 = "\n\t\t\t\t\t\t\tINSERT INTO supp_payment_print_items (\n\t\t\t\t\t\t\t\tpayment_id, supid, purchase, tdate, sdate, \n\t\t\t\t\t\t\t\tpaid_amt, sett_amt\n\t\t\t\t\t\t\t) VALUES (\n\t\t\t\t\t\t\t\t'{$supp_pay_id}', '{$supid}', '{$invids[$key]}', '{$date}', 'now', \n\t\t\t\t\t\t\t\t'{$paidamt[$key]}','{$stock_setamt[$key]}'\n\t\t\t\t\t\t\t)";
                $run_save2 = db_exec($save_sql2) or errDie("Unable to record item information.");
            }
        }
        $samount = $amt - $amt * 2;
        #handle overpay ...
        if ($overpay > 0) {
            $sql = "\n\t\t\t\tINSERT INTO sup_stmnt (\n\t\t\t\t\tsupid, amount, edate, \n\t\t\t\t\tdescript, \n\t\t\t\t\tref, cacc, div\n\t\t\t\t) VALUES (\n\t\t\t\t\t'{$sup['supid']}', '-{$overpay}', '{$sdate}', \n\t\t\t\t\t'Payment  (Ref. {$reference})', \n\t\t\t\t\t'{$cheqnum}','{$bank['accnum']}', '" . USER_DIV . "'\n\t\t\t\t)";
            $stmntRslt = db_exec($sql) or errDie("Unable to insert statement record in Cubit.", SELF);
            $sql = "UPDATE suppliers SET balance = (balance - '{$overpay}'::numeric(13,2)) WHERE supid = '{$sup['supid']}' AND div = '" . USER_DIV . "'";
            $rslt = db_exec($sql) or errDie("Unable to update invoice in Cubit.", SELF);
            #record general transaction in supp ledger
            suppledger($sup['supid'], $bank['accnum'], $sdate, "General Transaction", "Unallocated Payment for Supplier", $overpay, "d");
            db_connect();
            $sql = "\n\t\t\t\tINSERT INTO suppurch (\n\t\t\t\t\tsupid, purid, pdate, balance, div\n\t\t\t\t) VALUES (\n\t\t\t\t\t'{$sup['supid']}', '0', '{$date}', '-{$overpay}', '" . USER_DIV . "'\n\t\t\t\t)";
            $purcRslt = db_exec($sql) or errDie("Unable to update int purchases information in Cubit.", SELF);
        }
        db_conn('cubit');
开发者ID:andrecoetzee,项目名称:accounting-123.com,代码行数:67,代码来源:bank-pay-supp-write.php

示例10: write


//.........这里部分代码省略.........
    $sup = pg_fetch_array($supRslt);
    # Get department info
    db_conn("exten");
    $sql = "SELECT * FROM departments WHERE deptid = '{$pur['deptid']}' AND div = '" . USER_DIV . "'";
    $deptRslt = db_exec($sql);
    if (pg_numrows($deptRslt) < 1) {
        $dept['deptname'] = "<i class='err'>Not Found</i>";
    } else {
        $dept = pg_fetch_array($deptRslt);
    }
    # Insert purchase to DB
    db_connect();
    $d = date("Y-m-d");
    # Begin updating
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    db_conn('cubit');
    $Sl = "INSERT INTO dnotes (purid,date,sub,vat,tot) VALUES ('{$purid}','{$d}','{$subtot}','{$vat}','{$total}')";
    $Ri = db_exec($Sl) or errDie("Unable insert data.");
    # Get warehouse name
    db_conn("exten");
    $sql = "SELECT * FROM warehouses WHERE div = '" . USER_DIV . "'";
    $whRslt = db_exec($sql);
    $wh = pg_fetch_array($whRslt);
    # Update purchase on the DB
    db_conn($prd);
    $sql = "UPDATE purchases SET noted = 'y', rsubtot = 0, remarks = '{$remarks}' WHERE purid = '{$purid}'";
    $rslt = db_exec($sql) or errDie("Unable to update purchase in Cubit.", SELF);
    /* - Start Hooks - */
    $refnum = getrefnum();
    $vatacc = gethook("accnum", "salesacc", "name", "VAT");
    $cvacc = gethook("accnum", "pchsacc", "name", "Cost Variance");
    /* - End Hooks - */
    $retot = sprint($subtot + $vat);
    $sdate = $pdate;
    //date("Y-m-d");
    # Debit Supplier control, credit inv control
    //	writetrans($dept['credacc'], $vatacc, date("d-m-Y"), $refnum, $vat, "Credit Note for VAT return on Purchase No. $pur[purnum] from Supplier : $sup[supname].");
    //	writetrans($dept['credacc'], $wh['conacc'], date("d-m-Y"), $refnum, $subtot, "Credit Note for Stock return on Purchase No. $pur[purnum] from Supplier : $sup[supname].");
    writetrans($dept['credacc'], $vatacc, $pur['pdate'], $refnum, $vat, "Credit Note for VAT return on Purchase No. {$pur['purnum']} from Supplier : {$sup['supname']}.");
    writetrans($dept['credacc'], $wh['conacc'], $pur['pdate'], $refnum, $subtot, "Credit Note for Stock return on Purchase No. {$pur['purnum']} from Supplier : {$sup['supname']}.");
    db_conn('cubit');
    $Sl = "SELECT * FROM vatcodes ORDER BY code";
    $Ri = db_exec($Sl);
    $f = 0;
    while ($vd = pg_fetch_array($Ri)) {
        $vid = $vd['id'];
        if ($rvat[$vid] < 0.01) {
            continue;
        }
        if ($f == 0) {
            $AM = sprint($subtot + $vat);
        } else {
            $AM = 0;
        }
        //$vd.="<tr><td><input type=hidden name='rvat[$vid]' value='$rvat[$vid]'></td></tr>";
        vatr($vd['id'], date("Y-m-d"), "INPUT", $vd['code'], $refnum, "Return VAT for Purchase No. {$pur['purnum']}", $AM, $rvat[$vid]);
        $f++;
    }
    db_connect();
    # Update the supplier (make balance less)
    $sql = "UPDATE suppliers SET balance = (balance - '{$retot}') WHERE supid = '{$pur['supid']}' AND div = '" . USER_DIV . "'";
    $rslt = db_exec($sql) or errDie("Unable to update invoice in Cubit.", SELF);
    # Update the supplier age analysis (make balance less)
    if (ext_ex2("suppurch", "purid", $pur['purnum'], "supid", $pur['supid'])) {
        # Found? Make amount less
        $sql = "\n\t\t\t\tUPDATE suppurch \n\t\t\t\tSET balance = (balance - '{$retot}') \n\t\t\t\tWHERE supid = '{$pur['supid']}' AND purid = '{$pur['purnum']}' AND div = '" . USER_DIV . "'";
        $rslt = db_exec($sql) or errDie("Unable to update invoice in Cubit.", SELF);
    } else {
        # Make transaction record for age analysis
        $sql = "\n\t\t\t\tINSERT INTO suppurch (\n\t\t\t\t\tsupid, purid, pdate, balance, div\n\t\t\t\t) VALUES (\n\t\t\t\t\t'{$pur['supid']}', '{$pur['purnum']}', '{$pdate}', '-{$retot}', '" . USER_DIV . "'\n\t\t\t\t)";
        $purcRslt = db_exec($sql) or errDie("Unable to update int purchases information in Cubit.", SELF);
    }
    # Remove all empty entries
    $sql = "DELETE FROM suppurch WHERE balance = 0::numeric(13,2) AND fbalance = 0::numeric(13,2) AND div = '" . USER_DIV . "'";
    $rs = db_exec($sql);
    $sql = "\n\t\t\tINSERT INTO sup_stmnt (\n\t\t\t\tsupid, edate, cacc, amount, descript, ref, ex, div\n\t\t\t) VALUES (\n\t\t\t\t'{$pur['supid']}', '{$pdate}', '{$dept['credacc']}', '-{$retot}', 'Stock Returned', '{$refnum}', '{$pur['purnum']}', '" . USER_DIV . "'\n\t\t\t)";
    $stmntRslt = db_exec($sql) or errDie("Unable to insert statement record in Cubit.", SELF);
    # Ledger Records
    suppledger($pur['supid'], $wh['conacc'], $sdate, $pur['purid'], "Stock Purchase No. {$pur['purnum']} returned.", $retot, 'd');
    /*-- Cost varience -- */
    if ($pur['rsubtot'] > $subtot) {
        $diff = sprint($pur['rsubtot'] - $subtot);
        # Debit Stock Control and Credit Creditors control
        writetrans($cvacc, $wh['conacc'], $sdate, $refnum, $diff, "Cost Variance for Stock Return on Purchase No. {$pur['purnum']} from Supplier : {$sup['supname']}.");
    } elseif ($subtot > $pur['rsubtot']) {
        $diff = sprint($subtot - $pur['rsubtot']);
        # Debit Stock Control and Credit Creditors control
        writetrans($wh['conacc'], $cvacc, $sdate, $refnum, $diff, "Cost Variance for Stock Return on Purchase No. {$pur['purnum']} from Supplier : {$sup['supname']}.");
    }
    /*-- End Cost varience -- */
    /* End Transactions */
    db_conn($prd);
    $sql = "UPDATE pur_items SET ctqty = '0' WHERE purid = '{$purid}' AND ctqty > 0 AND div = '" . USER_DIV . "'";
    $stkdRslt = db_exec($sql);
    # Commit updating
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    // Final Layout
    $write = "\n\t\t<table " . TMPL_tblDflts . ">\n\t\t\t<tr>\n\t\t\t\t<th>Stock Return Credit Note</th>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>Stock Return Credit note from Supplier <b>{$sup['supname']}</b> has been recorded.</td>\n\t\t\t</tr>\n\t\t</table>\n\t\t<p>\n\t\t<table " . TMPL_tblDflts . ">\n\t\t\t<tr>\n\t\t\t\t<th>Quick Links</th>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td><a href='purchase-view.php'>View purchases</a></td>\n\t\t\t</tr>\n\t\t\t<script>document.write(getQuicklinkSpecial());</script>\n\t\t</table>";
    return $write;
}
开发者ID:andrecoetzee,项目名称:accounting-123.com,代码行数:101,代码来源:purch-recnote.php

示例11: process_entries


//.........这里部分代码省略.........
                        db_connect();
                        $sql = "SELECT * FROM nons_purchases WHERE purid = '{$purid}' AND div = '" . USER_DIV . "'";
                        $purRslt = db_exec($sql) or errDie("Unable to get Order information");
                        if (pg_numrows($purRslt) < 1) {
                            return "<li>- Order Not Found</li>";
                        }
                        $pur = pg_fetch_array($purRslt);
                        $sid = $pur['supid'];
                        $purnum = $pur['purnum'];
                        if ($pur['received'] == "y") {
                            if (isset($bankid)) {
                                $sid = $bankid;
                                $sid += 0;
                            }
                            ### DATA SET 2 ...
                            $detadd = "";
                            if (isset($sid)) {
                                $detadd = " from Supplier {$pur['supplier']}";
                            }
                            $sdate = $pdate;
                            $tpp = 0;
                            $ccamt = 0;
                            # record transaction  from data
                            if (isset($BA)) {
                                $supacc = $BA;
                            }
                            foreach ($totstkamt as $stkacc => $wamt) {
                                writetrans($stkacc, $supacc, $td, $refnum, $wamt, "Non-Stock Purchase No. {$purnum} Received {$detadd}.");
                                pettyrec($supacc, $sdate, "ct", "Non-Stock Purchase No. {$purnum} Received {$detadd}.", $wamt, "Cash Order");
                            }
                            # vat
                            $vatamt = $revat;
                            # Add vat if not included
                            $retot = $resub;
                            if (isset($sid)) {
                                db_connect();
                                # update the supplier (make balance more)
                                $sql = "UPDATE suppliers SET balance = (balance + '{$retot}') WHERE supid = '{$pur['supid']}' AND div = '" . USER_DIV . "'";
                                $rslt = db_exec($sql) or errDie("Unable to update invoice in Cubit.", SELF);
                            }
                            if (isset($sid)) {
                                # Ledger Records
                                $DAte = $pur['pdate'];
                                suppledger($sup['supid'], $stkacc, $DAte, $purid, "Non-Stock Purchase No. {$purnum} received.", $retot, 'c');
                            }
                            if ($vatamt != 0) {
                                # Debit bank and credit the account involved
                                writetrans($vatacc, $supacc, $td, $refnum, $vatamt, "Non-Stock Purchase VAT paid on Non-Stock Order No. {$purnum} {$detadd}.");
                                pettyrec($supacc, $sdate, "ct", "Non-Stock Purchase No. {$purnum} Received {$detadd}.", $vatamt, "Cash Order VAT");
                                # Record the payment on the statement
                                db_connect();
                                $sdate = $pdate;
                            }
                            //								if(isset($bankid)) {
                            //									db_connect();
                            //									$sql = "INSERT INTO cashbook(bankid, trantype, date, name, descript, cheqnum, amount, vat, chrgvat, banked, accinv, div) VALUES ('$bankid', 'withdrawal', '$sdate', '$pur[supplier]', 'Non-Stock Purchase No. $pur[purnum] received', '0', '$retot', '$vatamt', '$pur[vatinc]', 'no', '$stkacc', '".USER_DIV."')";
                            //									$Rslt = db_exec ($sql) or errDie ("Unable to add bank payment to database.",SELF);
                            //								}
                            if (isset($sid)) {
                                db_connect();
                                $DAte = $pdate;
                                $sql = "\n\t\t\t\t\t\t\t\t\t\tINSERT INTO sup_stmnt (\n\t\t\t\t\t\t\t\t\t\t\tsupid, edate, cacc, amount, \n\t\t\t\t\t\t\t\t\t\t\tdescript, ref, ex, div\n\t\t\t\t\t\t\t\t\t\t) VALUES (\n\t\t\t\t\t\t\t\t\t\t\t'{$pur['supid']}', '{$pur['pdate']}', '{$stkacc}', '{$retot}', \n\t\t\t\t\t\t\t\t\t\t\t'Non Stock Purchase No. {$purnum} Received', '{$refnum}', '{$purnum}', '" . USER_DIV . "'\n\t\t\t\t\t\t\t\t\t\t)";
                                $stmntRslt = db_exec($sql) or errDie("Unable to insert statement record in Cubit.", SELF);
                                db_connect();
                                # update the supplier age analysis (make balance less)
                                /* Make transaction record for age analysis */
                                $sql = "\n\t\t\t\t\t\t\t\t\t\tINSERT INTO suppurch (\n\t\t\t\t\t\t\t\t\t\t\tsupid, purid, pdate, balance, div\n\t\t\t\t\t\t\t\t\t\t) VALUES (\n\t\t\t\t\t\t\t\t\t\t\t'{$pur['supid']}', '{$purnum}', '{$pur['pdate']}', '{$retot}', '" . USER_DIV . "'\n\t\t\t\t\t\t\t\t\t\t)";
                                $purcRslt = db_exec($sql) or errDie("Unable to update int Orders information in Cubit.", SELF);
                            }
                            ###
                            # copy Order
                            db_conn(PRD_DB);
                            $sql = "\n\t\t\t\t\t\t\t\t\tINSERT INTO nons_purchases (\n\t\t\t\t\t\t\t\t\t\tpurid, deptid, supplier, supaddr, terms, \n\t\t\t\t\t\t\t\t\t\tpdate, ddate, shipchrg, shipping, subtot, \n\t\t\t\t\t\t\t\t\t\ttotal, balance, vatinc, vat, remarks, \n\t\t\t\t\t\t\t\t\t\trefno, received, done, ctyp, typeid, \n\t\t\t\t\t\t\t\t\t\tdiv, purnum, supid, mpurid, is_asset, supinv\n\t\t\t\t\t\t\t\t\t) VALUES (\n\t\t\t\t\t\t\t\t\t\t'{$purid}', '{$pur['deptid']}', '{$pur['supplier']}',  '{$pur['supaddr']}', '{$pur['terms']}', \n\t\t\t\t\t\t\t\t\t\t'{$pur['pdate']}', '{$pur['ddate']}', '{$pur['shipchrg']}', '{$pur['shipping']}', '{$pur['subtot']}', \n\t\t\t\t\t\t\t\t\t\t'{$pur['total']}', '0', '{$pur['vatinc']}', '{$pur['vat']}', '{$pur['remarks']}', \n\t\t\t\t\t\t\t\t\t\t'{$pur['refno']}', 'y', 'y', '{$pur['ctyp']}', '{$pur['typeid']}', \n\t\t\t\t\t\t\t\t\t\t'" . USER_DIV . "', '{$pur['purnum']}','{$sid}', '{$supacc}', '{$pur['is_asset']}', '{$pur['supinv']}'\n\t\t\t\t\t\t\t\t\t)";
                            $rslt = db_exec($sql) or errDie("Unable to insert Non-Stock Order to Cubit.", SELF);
                            db_connect();
                            # Get selected stock
                            $sql = "SELECT * FROM nons_pur_items WHERE purid = '{$purid}' AND div = '" . USER_DIV . "'";
                            $stktcRslt = db_exec($sql);
                            while ($stktc = pg_fetch_array($stktcRslt)) {
                                # Insert Order items
                                db_conn($pur['prd']);
                                $sql = "\n\t\t\t\t\t\t\t\t\t\tINSERT INTO nons_pur_items (\n\t\t\t\t\t\t\t\t\t\t\tpurid, cod, des, qty, unitcost, \n\t\t\t\t\t\t\t\t\t\t\tamt, svat, ddate, accid, \n\t\t\t\t\t\t\t\t\t\t\tdiv, vatcode\n\t\t\t\t\t\t\t\t\t\t) VALUES (\n\t\t\t\t\t\t\t\t\t\t\t'{$purid}', '{$stktc['cod']}', '{$stktc['des']}', '{$stktc['qty']}', '{$stktc['unitcost']}', \n\t\t\t\t\t\t\t\t\t\t\t'{$stktc['amt']}', '{$stktc['svat']}', '{$stktc['ddate']}', '{$stktc['accid']}', \n\t\t\t\t\t\t\t\t\t\t\t'" . USER_DIV . "', '{$stktc['vatcode']}'\n\t\t\t\t\t\t\t\t\t\t)";
                                $rslt = db_exec($sql) or errDie("Unable to insert Order items to Cubit.", SELF);
                            }
                            db_connect();
                            # Remove the Order from running DB
                            $sql = "DELETE FROM nons_purchases WHERE purid = '{$purid}' AND div = '" . USER_DIV . "'";
                            $delRslt = db_exec($sql) or errDie("Unable to update int Orders information in Cubit.", SELF);
                            # Remove those Order items from running DB
                            $sql = "DELETE FROM nons_pur_items WHERE purid = '{$purid}' AND div = '" . USER_DIV . "'";
                            $delRslt = db_exec($sql) or errDie("Unable to update int Orders information in Cubit.", SELF);
                        }
                    }
                }
            }
        }
    }
    pglib_transaction("COMMIT") or errDie("Unable to complete transaction.");
    return "\n\t\t<table " . TMPL_tblDflts . ">\n\t\t\t<tr>\n\t\t\t\t<th>Processing Completed</th>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>All Selected Transactions Completed</td>\n\t\t\t</tr>\n\t\t</table>\n\t\t<br>\n\t\t" . mkQuickLinks(ql("nons-purch-batch-add.php", "Batch Creditors Non-Stock Invoices Add"), ql("purchase-new.php", "Add Purchase"), ql("purchase-view.php", "View Purchases"), ql("nons-purchase-new.php", "Add Non-Stock Purchase"), ql("nons-purchase-view.php", "View Non-Stock Purchases"));
}
开发者ID:andrecoetzee,项目名称:accounting-123.com,代码行数:101,代码来源:nons-purch-batch-add.php

示例12: write

function write($_POST)
{
    # Get vars
    extract($_POST);
    # validate input
    require_lib("validate");
    $v = new validate();
    $v->isOk($purid, "num", 1, 20, "Invalid purchase number.");
    $v->isOk($remarks, "string", 0, 255, "Invalid Remarks.");
    $v->isOk($prd, "num", 1, 20, "Invalid period Database number.");
    // $v->isOk ($refno, "string", 0, 255, "Invalid Delivery Reference No.");
    $pdate = $p_year . "-" . $p_month . "-" . $p_day;
    if (!checkdate($p_month, $p_day, $p_year)) {
        $v->isOk($date, "num", 1, 1, "Invalid Date.");
    }
    $v->isOk($subtot, "float", 1, 20, "Invalid Subtotal.");
    $v->isOk($tax, "float", 0, 20, "Invalid Tax.");
    $v->isOk($total, "float", 1, 20, "Invalid total.");
    # display errors, if any
    $err = "";
    if ($v->isError()) {
        $errors = $v->getErrors();
        foreach ($errors as $e) {
            $err .= "<li class='err'>" . $e["msg"] . "</li>";
        }
        return details($_POST, $err);
    }
    # Get purchase info
    db_conn($prd);
    $sql = "SELECT * FROM purch_int WHERE purid = '{$purid}' AND div = '" . USER_DIV . "'";
    $purRslt = db_exec($sql) or errDie("Unable to get purchase information");
    if (pg_numrows($purRslt) < 1) {
        return "<li>- purchase Not Found</li>";
    }
    $pur = pg_fetch_array($purRslt);
    # Get selected supplier info
    db_connect();
    $sql = "SELECT * FROM suppliers WHERE supid = '{$pur['supid']}' AND div = '" . USER_DIV . "'";
    $supRslt = db_exec($sql) or errDie("Unable to get customer information");
    $sup = pg_fetch_array($supRslt);
    # Get department info
    db_conn("exten");
    $sql = "SELECT * FROM departments WHERE deptid = '{$pur['deptid']}' AND div = '" . USER_DIV . "'";
    $deptRslt = db_exec($sql);
    if (pg_numrows($deptRslt) < 1) {
        $dept['deptname'] = "<i class='err'>Not Found</i>";
    } else {
        $dept = pg_fetch_array($deptRslt);
    }
    # Insert purchase to DB
    db_connect();
    # Begin updating
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # Get warehouse name
    db_conn("exten");
    $sql = "SELECT * FROM warehouses WHERE div = '" . USER_DIV . "'";
    $whRslt = db_exec($sql);
    $wh = pg_fetch_array($whRslt);
    # Update purchase on the DB
    db_conn($prd);
    $sql = "UPDATE purch_int SET noted = 'y', rsubtot = 0, rtax = 0, remarks = '{$remarks}' WHERE purid = '{$purid}'";
    $rslt = db_exec($sql) or errDie("Unable to update purchase in Cubit.", SELF);
    /* - Start Hooks - */
    $refnum = getrefnum();
    $vatacc = gethook("accnum", "salesacc", "name", "VAT");
    $cvacc = gethook("accnum", "pchsacc", "name", "Cost Variance");
    /* - End Hooks - */
    $retot = sprint($subtot + $tax);
    $sdate = date("Y-m-d");
    $lsubtot = sprint($subtot * $pur['xrate']);
    $ltax = sprint($tax * $pur['xrate']);
    $lretot = sprint($retot * $pur['xrate']);
    # Debit Supplier control, credit inv control
    //date("d-m-Y")
    writetrans($dept['credacc'], $vatacc, $pdate, $refnum, $ltax, "Credit Note for Vat return on Purchase No. {$pur['purnum']} from Supplier : {$sup['supname']}.");
    writetrans($dept['credacc'], $wh['conacc'], $pdate, $refnum, $lsubtot, "Credit Note for Stock return on Purchase No. {$pur['purnum']} from Supplier : {$sup['supname']}.");
    db_connect();
    # update the supplier (make balance less)
    $sql = "UPDATE suppliers SET fbalance = (fbalance - '{$retot}'), balance = (balance - '{$lretot}') WHERE supid = '{$pur['supid']}' AND div = '" . USER_DIV . "'";
    $rslt = db_exec($sql) or errDie("Unable to update invoice in Cubit.", SELF);
    # update the supplier age analysis (make balance less)
    if (ext_ex2("suppurch", "purid", $pur['purnum'], "supid", $pur['supid'])) {
        # Found? Make amount less
        $sql = "UPDATE suppurch SET fbalance = (fbalance - '{$retot}'), balance = (balance - '{$lretot}') WHERE supid = '{$pur['supid']}' AND purid = '{$pur['purnum']}' AND div = '" . USER_DIV . "'";
        $rslt = db_exec($sql) or errDie("Unable to update invoice in Cubit.", SELF);
    } else {
        /* Make transaction record for age analysis */
        $sql = "INSERT INTO suppurch(supid, purid, pdate, balance, fbalance, div) VALUES('{$pur['supid']}', '{$pur['purnum']}', '{$sdate}', '-{$lretot}', '-{$retot}', '" . USER_DIV . "')";
        $purcRslt = db_exec($sql) or errDie("Unable to update int purchases information in Cubit.", SELF);
    }
    $Date = date("Y-m-d");
    $sql = "INSERT INTO sup_stmnt(supid, edate, cacc, amount, descript, ref, ex, div) VALUES('{$pur['supid']}','{$Date}', '{$dept['credacc']}', '-{$retot}', 'Stock Returned', '{$refnum}', '{$pur['purnum']}', '" . USER_DIV . "')";
    $stmntRslt = db_exec($sql) or errDie("Unable to insert statement record in Cubit.", SELF);
    # Ledger Records
    suppledger($pur['supid'], $wh['stkacc'], $Date, $pur['purid'], "Stock Purchase No. {$pur['purnum']} returned.", $lretot, 'd');
    /*-- Cost varience -- */
    //date("d-m-Y")
    if ($pur['rsubtot'] > $subtot) {
        $diff = sprint($pur['rsubtot'] - $subtot);
        # Debit Stock Control and Credit Creditors control
//.........这里部分代码省略.........
开发者ID:andrecoetzee,项目名称:accounting-123.com,代码行数:101,代码来源:purch-int-recnote.php

示例13: write


//.........这里部分代码省略.........
        $Sl = "SELECT * FROM vatcodes WHERE id='{$pur['delvat']}'";
        $Ri = db_exec($Sl);
        if (pg_num_rows($Ri) < 1) {
            $Sl = "SELECT * FROM vatcodes";
            $Ri = db_exec($Sl);
        }
        $vd = pg_fetch_array($Ri);
        if ($vd['zero'] == "Yes") {
            $excluding = "y";
        } else {
            $excluding = "";
        }
        $vr = vatcalc($shipchrg, $pur['vatinc'], $excluding, 0, $vd['vat_amount']);
        $vrs = explode("|", $vr);
        $ivat_tmp = $vrs[0];
        $iamount_tmp = $vrs[1];
        vatr($vd['id'], $td, "INPUT", $vd['code'], $refnum, "VAT Paid for Purchase No. {$pur['purnum']} from Supplier : {$pur['supname']}.", sprint(-$iamount_tmp), -$scvat);
        ####################################################
        db_conn("exten");
        $sql = "SELECT * FROM warehouses WHERE div = '" . USER_DIV . "'";
        $whRslt = db_exec($sql);
        $wh = pg_fetch_array($whRslt);
        db_connect();
        # update the supplier (make balance more)
        $sql = "UPDATE suppliers SET balance = (balance + '{$itotal}') WHERE supid = '{$pur['supid']}' AND div = '" . USER_DIV . "'";
        $rslt = db_exec($sql) or errDie("Unable to update invoice in Cubit.", SELF);
        $sql = "\n\t\t\tINSERT INTO sup_stmnt (\n\t\t\t\tsupid, edate, cacc, amount, descript, ref, ex, div\n\t\t\t) VALUES (\n\t\t\t\t'{$pur['supid']}', '{$pur['pdate']}', '{$wh['conacc']}', '{$itotal}', \n\t\t\t\t'Stock Received - Purchase {$pur['purnum']} Inv:{$pur['supinv']}', '{$refnum}', '{$pur['purnum']}', '" . USER_DIV . "'\n\t\t\t)";
        $stmntRslt = db_exec($sql) or errDie("Unable to insert statement record in Cubit.", SELF);
        # Debit Stock Control and Credit Creditors control
        writetrans($wh['conacc'], $dept['credacc'], $td, $refnum, $isubtot, "Invoice Received for Purchase No. {$pur['purnum']} from Supplier : {$pur['supname']}.");
        # Transfer vat
        writetrans($vatacc, $dept['credacc'], $td, $refnum, $ivat, "VAT Paid for Purchase No. {$pur['purnum']} from Supplier : {$pur['supname']}.");
        # Ledger Records
        suppledger($pur['supid'], $wh['conacc'], $td, $pur['purid'], "Purchase No. {$pur['purnum']} received.", $itotal, 'c');
        db_connect();
        /* End Transactions */
        /* Make transaction record  for age analysis */
        db_connect();
        # update the supplier age analysis (make balance less)
        if (ext_ex2("suppurch", "purid", $pur['purnum'], "supid", $pur['supid'])) {
            # Found? Make amount less
            $sql = "UPDATE suppurch SET balance = (balance + '{$itotal}') WHERE supid = '{$pur['supid']}' AND purid = '{$pur['purnum']}' AND div = '" . USER_DIV . "'";
            $rslt = db_exec($sql) or errDie("Unable to update invoice in Cubit.", SELF);
        } else {
            /* Make transaction record for age analysis */
            $sql = "\n\t\t\t\t\tINSERT INTO suppurch (\n\t\t\t\t\t\tsupid, purid, pdate, balance, div\n\t\t\t\t\t) VALUES (\n\t\t\t\t\t\t'{$pur['supid']}', '{$pur['purnum']}', '{$pur['pdate']}', '{$itotal}', '" . USER_DIV . "'\n\t\t\t\t\t)";
            $purcRslt = db_exec($sql) or errDie("Unable to update Order information in Cubit.", SELF);
        }
        /* Make transaction record  for age analysis */
        # commit updating
        $sql = "UPDATE purchases SET iamount = iamount+'{$itotal}',ivat=ivat+'{$ivat}' WHERE purid = '{$purid}' AND div = '" . USER_DIV . "'";
        $rslt = db_exec($sql) or errDie("Unable to update Order status in Cubit.", SELF);
        $sql = "SELECT SUM(iqty) FROM pur_items  WHERE purid = '{$purid}' AND div = '" . USER_DIV . "'";
        $stktRslt = db_exec($sql);
        $data = pg_fetch_array($stktRslt);
        $left = $data['sum'];
        if ($left == 0) {
            /* Start moving if purchase */
            if ($pur['received'] == "y") {
                if (strlen($pur['appdate']) < 8) {
                    $pur['appdate'] = date("Y-m-d");
                }
                # copy purchase
                db_conn($pur['prd']);
                $sql = "\n\t\t\t\t\tINSERT INTO purchases (\n\t\t\t\t\t\tpurid, deptid, supid, supname, supaddr, supno, \n\t\t\t\t\t\tterms, pdate, ddate, shipchrg, subtot, total, \n\t\t\t\t\t\tbalance, vatinc, vat, shipping, remarks, refno, received, done, \n\t\t\t\t\t\tdiv, purnum, supinv, ordernum, appname, appdate\n\t\t\t\t\t) VALUES (\n\t\t\t\t\t\t'{$purid}', '{$pur['deptid']}', '{$pur['supid']}',  '{$pur['supname']}', '{$pur['supaddr']}', '{$pur['supno']}', \n\t\t\t\t\t\t'{$pur['terms']}', '{$pur['pdate']}', '{$pur['ddate']}', '{$pur['shipchrg']}', '{$pur['subtot']}', '{$pur['total']}', \n\t\t\t\t\t\t'0', '{$pur['vatinc']}', '{$pur['vat']}', '{$pur['shipping']}', '{$remarks}', '{$pur['refno']}', 'y', 'y', \n\t\t\t\t\t\t'" . USER_DIV . "', '{$pur['purnum']}', '{$supinv}', '{$pur['ordernum']}', '{$pur['appname']}', '{$pur['appdate']}'\n\t\t\t\t\t)";
                $rslt = db_exec($sql) or errDie("Unable to insert Order to Cubit.", SELF);
开发者ID:andrecoetzee,项目名称:accounting-123.com,代码行数:67,代码来源:purch-recv.php

示例14: write

function write($_POST)
{
    # Processes
    db_connect();
    # Get vars
    extract($_POST);
    # validate input
    require_lib("validate");
    $v = new validate();
    $v->isOk($cashacc, "num", 1, 30, "Invalid Petty Cash Account.");
    $v->isOk($date, "date", 1, 10, "Invalid Date Entry.");
    $v->isOk($descript, "string", 0, 255, "Invalid Description.");
    $v->isOk($amount, "float", 1, 10, "Invalid amount.");
    $v->isOk($supid, "num", 1, 20, "Invalid Supplier account.");
    # Display errors, if any
    if ($v->isError()) {
        $confirm = "";
        $errors = $v->getErrors();
        foreach ($errors as $e) {
            $confirm .= "<li class='err'>" . $e["msg"] . "</li>";
        }
        $confirm .= "<p><input type='button' onClick='JavaScript:history.back();' value='&laquo; Correct submission'>";
        return $confirm;
    }
    # Date format
    $date = explode("-", $date);
    $date = $date[2] . "-" . $date[1] . "-" . $date[0];
    # Get account name
    $supRslt = get("cubit", "*", "suppliers", "supid", $supid);
    $sup = pg_fetch_array($supRslt);
    db_conn("exten");
    # Get debtors control account
    $sql = "SELECT credacc FROM departments WHERE deptid ='{$sup['deptid']}' AND div = '" . USER_DIV . "'";
    $deptRslt = db_exec($sql);
    $dept = pg_fetch_array($deptRslt);
    pglib_transaction("BEGIN");
    db_connect();
    $Sl = "\n\t\tINSERT INTO sup_stmnt (\n\t\t\tsupid, amount, edate, descript, ref, cacc, div\n\t\t) VALUES (\n\t\t\t'{$supid}', '-{$amount}', '{$date}', 'Cash Payment', '0', '{$cashacc}', '" . USER_DIV . "'\n\t\t)";
    $Rs = db_exec($Sl) or errDie("Unable to insert statement record in Cubit.", SELF);
    # Update the supplier (make balance less)
    $sql = "UPDATE suppliers SET balance = (balance - '{$amount}'::numeric(13,2)) WHERE supid = '{$supid}' AND div = '" . USER_DIV . "'";
    $rslt = db_exec($sql) or errDie("Unable to update invoice in Cubit.", SELF);
    suppledger($supid, $cashacc, $date, 0, "Cash Payment", $amount, "d");
    suppDT($amount, $supid);
    # Record tranfer for patty cash report
    $sql = "\n\t\tINSERT INTO pettyrec (\n\t\t\tdate, type, det, amount, name, div\n\t\t) VALUES (\n\t\t\t'{$date}', 'Req', '{$descript}', '-{$amount}', 'Paid to supplier: {$sup['supname']}', '" . USER_DIV . "'\n\t\t)";
    $Rslt = db_exec($sql) or errDie("Unable to add bank payment to database.", SELF);
    $refnum = getrefnum();
    writetrans($dept['credacc'], $cashacc, $date, $refnum, $amount, $descript);
    pglib_transaction("COMMIT");
    # Status report
    $write = "\n\t\t<table " . TMPL_tblDflts . " width='100%'>\n\t\t\t<tr>\n\t\t\t\t<th>Petty Cash Payment</th>\n\t\t\t</tr>\n\t\t\t<tr class='datacell'>\n\t\t\t\t<td>Petty Cash Payment to supplier : {$sup['supname']} added to petty cash book.</td>\n\t\t\t</tr>\n\t\t</table>";
    # main table (layout with menu)
    $OUTPUT = "\n\t\t<center>\n\t\t<table width='90%'>\n\t\t\t<tr valign='top'>\n\t\t\t\t<td width='50%'>{$write}</td>\n\t\t\t\t<td align='center'>\n\t\t\t\t\t<table " . TMPL_tblDflts . " width='80%'>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<th>Quick Links</th>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td><a href='bank-pay-add.php'>Add Petty Cash Payment</a></td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td><a href='bank-recpt-add.php'>Add Petty Cash Receipt</a></td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td><a href='cashbook-view.php'>View Cash Book</a></td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t</table>\n\t\t\t\t</td>\n\t\t\t</tr>\n\t\t</table>";
    return $OUTPUT;
}
开发者ID:andrecoetzee,项目名称:accounting-123.com,代码行数:56,代码来源:petty-pay-supp.php

示例15: write

function write($_POST)
{
    # Get vars
    extract($_POST);
    # validate input
    require_lib("validate");
    $v = new validate();
    $v->isOk($purid, "num", 1, 20, "Invalid purchase number.");
    $v->isOk($remarks, "string", 0, 255, "Invalid Remarks.");
    $v->isOk($refno, "string", 0, 255, "Invalid Delivery Reference No.");
    $v->isOk($subtot, "float", 1, 20, "Invalid Sub Total.");
    $v->isOk($shipping, "float", 1, 20, "Invalid Delivery Charges.");
    $v->isOk($vat, "float", 1, 20, "Invalid VAT");
    $v->isOk($total, "float", 1, 20, "Invalid Total");
    # used to generate errors
    $error = "asa@";
    # display errors, if any
    $err = "";
    if ($v->isError()) {
        $errors = $v->getErrors();
        foreach ($errors as $e) {
            $err .= "<li class='err'>" . $e["msg"] . "</li>";
        }
        return details($_POST, $err);
    }
    # Get purchase info
    db_connect();
    $sql = "SELECT * FROM purchases WHERE purid = '{$purid}' AND div = '" . USER_DIV . "'";
    $purRslt = db_exec($sql) or errDie("Unable to get purchase information");
    if (pg_numrows($purRslt) < 1) {
        return "<li>- purchase Not Found</li>";
    }
    $pur = pg_fetch_array($purRslt);
    # 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='&laquo; Correct submission'>";
        return $error;
    }
    # Get selected supplier info
    db_connect();
    $sql = "SELECT * FROM suppliers WHERE supid = '{$pur['supid']}' AND div = '" . USER_DIV . "'";
    $supRslt = db_exec($sql) or errDie("Unable to get customer information");
    if (pg_numrows($supRslt) < 1) {
        // code here
    } else {
        $sup = pg_fetch_array($supRslt);
    }
    # Get department info
    db_conn("exten");
    $sql = "SELECT * FROM departments WHERE deptid = '{$pur['deptid']}' AND div = '" . USER_DIV . "'";
    $deptRslt = db_exec($sql);
    if (pg_numrows($deptRslt) < 1) {
        $dept['deptname'] = "<i class='err'> - Not Found</i>";
    } else {
        $dept = pg_fetch_array($deptRslt);
    }
    $sdate = date("Y-m-d");
    $date = $pur["pdate"];
    $refnum = getrefnum();
    # Get warehouse name
    db_conn("exten");
    $sql = "SELECT * FROM warehouses WHERE div = '" . USER_DIV . "'";
    $whRslt = db_exec($sql);
    $wh = pg_fetch_array($whRslt);
    $subtot = sprint($subtot);
    $shipping = sprint($shipping);
    $vat = sprint($vat);
    $total = sprint($total);
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # get selected stock in this purchase
    db_connect();
    $sql = "SELECT * FROM pur_items  WHERE purid = '{$purid}' AND div = '" . USER_DIV . "'";
    $stktRslt = db_exec($sql);
    while ($stkt = pg_fetch_array($stktRslt)) {
        $cqty = $stkt['qty'] - $stkt['rqty'];
        # update stock(ordered - qty)
        $sql = "UPDATE stock SET ordered = (ordered - '{$cqty}')  WHERE stkid = '{$stkt['stkid']}' AND div = '" . USER_DIV . "'";
        $rslt = db_exec($sql) or errDie("Unable to update stock to Cubit.", SELF);
    }
    /* - Start Hooks - */
    $vatacc = gethook("accnum", "salesacc", "name", "VAT");
    $cvacc = gethook("accnum", "pchsacc", "name", "Cost Variance");
    /* - End Hooks - */
    # Record the payment on the statement
    db_connect();
    db_connect();
    # update the supplier (make balance more)
    $sql = "UPDATE suppliers SET balance = (balance + '{$total}') WHERE supid = '{$pur['supid']}' AND div = '" . USER_DIV . "'";
    $rslt = db_exec($sql) or errDie("Unable to update invoice in Cubit.", SELF);
    $sql = "\n\t\t\tINSERT INTO sup_stmnt (\n\t\t\t\tsupid, edate, cacc, amount, descript, ref, ex, div\n\t\t\t) VALUES (\n\t\t\t\t'{$pur['supid']}', '{$date}', '{$dept['credacc']}', '{$total}', 'Stock Received - Purchase {$pur['purnum']}', '{$refnum}','{$pur['purnum']}','" . USER_DIV . "'\n\t\t\t)";
    $stmntRslt = db_exec($sql) or errDie("Unable to insert statement record in Cubit.", SELF);
    # Debit Stock Control and Credit Creditors control
    writetrans($wh['conacc'], $dept['credacc'], $date, $refnum, $total - $vat, "Invoice Received for Purchase No. {$pur['purnum']} from Supplier : {$pur['supname']}.");
    # Transfer vat
    writetrans($vatacc, $dept['credacc'], $date, $refnum, $vat, "Vat Paid for Purchase No. {$pur['purnum']} from Supplier : {$pur['supname']}.");
    # Ledger Records
    suppledger($pur['supid'], $wh['conacc'], $date, $pur['purid'], "Purchase No. {$pur['purnum']} received.", $total, 'c');
    db_connect();
    /* End Transactions */
//.........这里部分代码省略.........
开发者ID:andrecoetzee,项目名称:accounting-123.com,代码行数:101,代码来源:purch-complete.php


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