require "settings.php"; require "core-settings.php"; # decide what to do if (isset($_POST["key"])) { switch ($_POST["key"]) { case "confirm": $OUTPUT = confirm($_POST); break; case "write": $OUTPUT = write($_POST); break; case "details": if (isset($_POST['details'])) { $OUTPUT = details($_POST); } else { $OUTPUT = details2($_POST); } break; default: if (isset($_GET['cusnum'])) { $OUTPUT = slctacc($_GET); } else { $OUTPUT = "<li> - Invalid use of module"; } } } else { if (isset($_GET['cusnum'])) { $OUTPUT = slctacc($_GET); } else { $OUTPUT = "<li> - Invalid use of module"; }
function write($_POST) { extract($_POST); $vatcode += 0; if (isset($back)) { unset($_POST["back"]); if ($chrgvat == "yes") { return slctVatacc($_POST); } elseif (isset($details)) { return details($_POST); } else { return details2($_POST); } } # validate input require_lib("validate"); $v = new validate(); $v->isOk($ctaccid, "num", 1, 50, "Invalid Account to be Credited."); $v->isOk($dtaccid, "num", 1, 50, "Invalid Account to be Debited."); $v->isOk($refnum, "num", 1, 10, "Invalid Reference number."); $v->isOk($amount, "float", 1, 20, "Invalid Amount."); $v->isOk($details, "string", 0, 255, "Invalid Details."); $v->isOk($author, "string", 1, 30, "Invalid Authorising person name."); $v->isOk($chrgvat, "string", 1, 4, "Invalid charge vat option."); if ($chrgvat == 'yes') { $v->isOk($vataccid, "num", 1, 50, "Invalid VAT Account number."); $v->isOk($vatdedacc, "num", 1, 50, "Invalid VAT Deductable Account number."); $v->isOk($vatamt, "float", 1, 11, "Invalid VAT Amount."); $v->isOk($vatinc, "string", 1, 3, "Invalid VAT inclusive selection."); } if ($v->isError()) { $err = $v->genErrors(); return confirm($_POST, $err); } pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF); # Accounts details $dtaccRs = get("core", "*", "accounts", "accid", $dtaccid); $dtacc = pg_fetch_array($dtaccRs); $ctaccRs = get("core", "*", "accounts", "accid", $ctaccid); $ctacc = pg_fetch_array($ctaccRs); if ($chrgvat == 'yes') { if ($vatinc == 'yes') { # Calculate amount $amt = sprint($amount - $vatamt); $totamt = sprint($amount); } else { # Calculate amount $amt = sprint($amount); $totamt = sprint($amount + $vatamt); } $datea = explode("-", $date); // $cdate="$datea[2]-$datea[1]-$datea[0]"; $cdate = $date; # Check VAt Deductable account if ($vatdedacc == $dtaccid) { db_connect(); $Sl = "SELECT * FROM vatcodes WHERE id='{$vatcode}'"; $Ri = db_exec($Sl); if (pg_num_rows($Ri) < 1) { return "Please select the vatcode"; } $vd = pg_fetch_array($Ri); ## PROCESS THIS VAT //vatr($vd['id'],$cdate,"INPUT",$vd['code'],$refnum,"$details VAT",-$totamt,-$vatamt); recordtrans('journal', '0', '0', $cdate, $refnum, -$totamt, -$vatamt, "{$details} VAT" . "|{$vd['id']}|INPUT|{$vd['code']}", '0'); ## PROCESS THIS WRITETRANS recordtrans('journal', $vataccid, $ctaccid, $date, $refnum, $vatamt, '0', $details . " VAT"); //writetrans($vataccid, $ctaccid, $date, $refnum, $vatamt, $details." VAT"); ## PROCESS THIS WRITETRANS recordtrans('journal', $dtaccid, $ctaccid, $date, $refnum, $amt, '0', $details); //writetrans($dtaccid, $ctaccid, $date, $refnum, $amt, $details); } elseif ($vatdedacc == $ctaccid) { db_connect(); $Sl = "SELECT * FROM vatcodes WHERE id='{$vatcode}'"; $Ri = db_exec($Sl); if (pg_num_rows($Ri) < 1) { return "Please select the vatcode"; } $vd = pg_fetch_array($Ri); ## PROCESS THIS VAT //vatr($vd['id'],$cdate,"OUTPUT",$vd['code'],$refnum,"$details. VAT",$totamt,$vatamt); recordtrans('journal', '0', '0', $cdate, $refnum, $totamt, $vatamt, "{$details} VAT" . "|{$vd['id']}|OUTPUT|{$vd['code']}"); ## PROCESS THIS WRITETRANS recordtrans('journal', $dtaccid, $vataccid, $date, $refnum, $vatamt, '0', $details . " VAT"); //writetrans($dtaccid, $vataccid, $date, $refnum, $vatamt, $details." VAT"); ## PROCESS THIS WRITETRANS recordtrans('journal', $dtaccid, $ctaccid, $date, $refnum, $amt, $details); //writetrans($dtaccid, $ctaccid, $date, $refnum, $amt, $details); } } else { $totamt = sprint($amount); # Write normal transaction recordtrans('journal', $dtaccid, $ctaccid, $date, $refnum, $totamt, '0', $details); //writetrans($dtaccid,$ctaccid, $date, $refnum, $totamt, $details); } if ($chrgvat == 'yes') { $vataccRs = get("core", "*", "accounts", "accid", $vataccid); $vatacc = pg_fetch_array($vataccRs); $vataccnum = "\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td>VAT Amount</td>\n\t\t\t\t\t\t\t<td>{$vatamt}</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>Total Transaction Amount</td>\n\t\t\t\t\t\t\t<td><b>{$totamt}</b></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>VAT Account</td>\n\t\t\t\t\t\t\t<td>{$vatacc['topacc']}/{$vatacc['accnum']} - {$vatacc['accname']}</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t"; $amt = $totamt - $vatamt; } else { $vataccnum = ""; $amt = $amount; } if (cc_TranTypeAcc($dtaccid, $ctaccid) != false) { $cc_trantype = cc_TranTypeAcc($dtaccid, $ctaccid); $cc = "<script> CostCenter('{$cc_trantype}', 'Journal Entry', '{$date}', '{$details}', '{$amt}', '../'); </script>"; } else { $cc = ""; } pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF); // Start layout $write = "\n\t\t\t\t<center>\n\t\t\t\t{$cc}\n\t\t\t\t<script>\n\t\t\t\t\tparent.window.reload;\n\t\t\t\t</script>\n\t\t\t\t<h3>Journal transaction has been recorded</h3>\n\t\t\t\t<table " . TMPL_tblDflts . " width='500'>\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td width='50%'><h3>Debit</h3></td>\n\t\t\t\t\t\t<td width='50%'><h3>Credit</h3></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t<td>{$dtacc['topacc']}/{$dtacc['accnum']} - {$dtacc['accname']}</td>\n\t\t\t\t\t\t<td>{$ctacc['topacc']}/{$ctacc['accnum']} - {$ctacc['accname']}</td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t" . TBL_BR . "\n\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t<td>Amount</td>\n\t\t\t\t\t\t<td><b>{$amount}</b></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t{$vataccnum}\n\t\t\t\t</table>" . mkQuickLinks(ql("../reporting/index-reports.php", "Financials"), ql("../core/trans-new.php", "Journal Transactions")); return $write; }
function write($_POST) { # Get vars extract($_POST); if (isset($back)) { if ($type == 1) { return details($_POST); } else { $_POST["accnum"] = $ac; return details2($_POST); } } # validate input require_lib("validate"); $v = new validate(); $v->isOk($cusnum, "num", 1, 50, "Invalid Customer number."); $v->isOk($accid, "num", 1, 50, "Invalid Contra Account."); $v->isOk($refnum, "num", 1, 10, "Invalid Reference number."); $v->isOk($amount, "float", 1, 20, "Invalid Amount."); $v->isOk($details, "string", 0, 255, "Invalid Details."); $v->isOk($author, "string", 1, 30, "Invalid Authorising person name."); $datea = explode("-", $date); if (count($datea) == 3) { if (!checkdate($datea[1], $datea[0], $datea[2])) { $v->isOk($date, "num", 1, 1, "Invalid date."); } } else { $v->isOk($date, "num", 1, 1, "Invalid date."); } # display errors, if any if ($v->isError()) { $write = ""; $errors = $v->getErrors(); foreach ($errors as $e) { $write .= "<li class='err'>" . $e["msg"] . "</li>"; } $write .= "<p><input type='button' onClick='JavaScript:history.back();' value='« Correct submission'>"; return $write; } $date = "{$datea['2']}-{$datea['1']}-{$datea['0']}"; # Accounts details $accRs = get("core", "*", "accounts", "accid", $accid); $acc = pg_fetch_array($accRs); # Select customer db_connect(); $sql = "SELECT * FROM customers WHERE cusnum = '{$cusnum}' AND div = '" . USER_DIV . "'"; $custRslt = db_exec($sql) or errDie("Unable to access databse.", SELF); if (pg_numrows($custRslt) < 1) { return "<li class='err'>Invalid customer ID, or customer has been blocked.</li>"; } else { $cust = pg_fetch_array($custRslt); } # Get department db_conn("exten"); $sql = "SELECT * FROM departments WHERE deptid = '{$cust['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); } // $cust['cusname'] = remval($cust['cusname']); // $cust['surname'] = remval($cust['surname']); # Probe tran type if ($entry == "CT") { # Write transaction (debit contra account, credit debtors control) recordtrans('journal', $accid, $dept['debtacc'], $date, $refnum, $amount, '0', $details . " - Customer {$cust['cusname']} {$cust['surname']}"); //PROCESS THIS WRITETRANS //writetrans($accid, $dept['debtacc'], $date, $refnum, $amount, $details." - Customer $cust[cusname] $cust[surname]"); $tran = "\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td>{$acc['topacc']}/{$acc['accnum']} - {$acc['accname']}</td>\n\t\t\t\t\t\t\t<td>{$cust['accno']} - {$cust['cusname']} {$cust['surname']}</td>\n\t\t\t\t\t\t</tr>"; $samount = $amount - $amount * 2; recordtrans('debtor', '0', '1', $date, '0', $samount, '0', $details . " - Customer {$cust['cusname']} {$cust['surname']}", $cust['cusnum']); //PROCESS THIS ENTRY //recordCT($samount, $cust['cusnum'],$date); $type = 'c'; } else { # Write transaction (debit debtors control, credit contra account) recordtrans('journal', $dept['debtacc'], $accid, $date, $refnum, $amount, '0', $details . " - Customer {$cust['cusname']} {$cust['surname']}"); //PROCESS THIS WRITETRANS //writetrans($dept['debtacc'], $accid, $date, $refnum, $amount, $details." - Customer $cust[cusname] $cust[surname]"); $tran = "\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td>{$cust['accno']} - {$cust['cusname']} {$cust['surname']}</td>\n\t\t\t\t\t\t\t<td>{$acc['topacc']}/{$acc['accnum']} - {$acc['accname']}</td>\n\t\t\t\t\t\t</tr>"; $samount = $amount; recordtrans('debtor', '1', '0', $date, '0', $samount, '0', $details . " - Customer {$cust['cusname']} {$cust['surname']}", $cust['cusnum']); //PROCESS THIS ENTRY //recordDT($samount, $cust['cusnum'],$date); $type = 'd'; } db_connect(); # Begin updates pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF); $sdate = date("Y-m-d"); # record the payment on the statement $sql = "\n\t\t\t\tINSERT INTO stmnt \n\t\t\t\t\t(cusnum, invid, amount, date, type, st, div, allocation_date) \n\t\t\t\tVALUES \n\t\t\t\t\t('{$cust['cusnum']}', '0', '{$samount}', '{$date}', '{$details}', 'n', '" . USER_DIV . "', '{$date}')"; // $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('{$cust['cusnum']}', '0', '{$samount}', '{$samount}', '{$date}', '{$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 + '{$samount}') WHERE cusnum = '{$cust['cusnum']}' AND div = '" . USER_DIV . "'"; // $rslt = db_exec($sql) or errDie("Unable to update customer in Cubit.",SELF); # Commit updates pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF); switch ($type) { case "d": recordtrans('debtor', $accid, '0', $date, $refnum, $amount, '0', $details, $cust['cusnum']); break; case "c": recordtrans('debtor', '0', $accid, $date, $refnum, $amount, '0', $details, $cust['cusnum']); break; default: } # Make ledge record //PROCESS THIS ENTRY //custledger($cust['cusnum'], $accid, $date, $refnum, $details, $amount, $type); // Start layout $write = "\n \t\t\t<h3>Journal transaction has been recorded</h3>\n\t\t\t <table " . TMPL_tblDflts . " width='500'>\n\t\t\t \t<tr>\n\t\t\t \t\t<td width='50%'><h3>Debit</h3></td>\n\t\t\t \t\t<td width='50%'><h3>Credit</h3></td>\n\t\t\t \t</tr>\n\t\t\t \t{$tran}\n\t\t\t \t<tr><td><br></td></tr>\n\t\t\t \t<tr colspan='2'>\n\t\t\t \t\t<td><h4>Amount</h4></td>\n\t\t\t \t</tr>\n\t\t\t \t<tr class='" . bg_class() . "'>\n\t\t\t \t\t<td colspan='2'><b>" . CUR . " {$amount}</b></td>\n\t\t\t \t</tr>\n\t\t\t </table>" . mkQuickLinks(ql("../core/trans-new.php", "Journal Transactions"), ql("../customers-view.php", "View Customers")); return $write; }
function write($_POST) { # Get vars extract($_POST); if (isset($back)) { if ($type == 1) { return details($_POST); } else { $_POST["accnum"] = $ac; return details2($_POST); } } # validate input require_lib("validate"); $v = new validate(); $v->isOk($cusnum, "num", 1, 50, "Invalid Customer number."); $v->isOk($accid, "num", 1, 50, "Invalid Contra Account."); $v->isOk($refnum, "num", 1, 10, "Invalid Reference number."); $v->isOk($amount, "float", 1, 20, "Invalid Amount."); $v->isOk($details, "string", 0, 255, "Invalid Details."); $v->isOk($author, "string", 1, 30, "Invalid Authorising person name."); $datea = explode("-", $date); if (count($datea) == 3) { if (!checkdate($datea[1], $datea[0], $datea[2])) { $v->isOk($date, "num", 1, 1, "Invalid date."); } } else { $v->isOk($date, "num", 1, 1, "Invalid date."); } $v->isOk($chrgvat, "string", 1, 10, "Invalid Charge VAT Option."); $v->isOk($vatinc, "string", 1, 10, "Invalid VAT Inclusive Exclusive Option."); $v->isOk($vatcode, "num", 1, 5, "Invalid Vat Code Option."); # display errors, if any if ($v->isError()) { $write = ""; $errors = $v->getErrors(); foreach ($errors as $e) { $write .= "<li class='err'>" . $e["msg"] . "</li>"; } $write .= "<p><input type='button' onClick='JavaScript:history.back();' value='« Correct submission'>"; return $write; } # 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>"; } 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 customer db_connect(); $sql = "SELECT * FROM customers WHERE cusnum = '{$cusnum}' AND div = '" . USER_DIV . "'"; $custRslt = db_exec($sql) or errDie("Unable to access databse.", SELF); if (pg_numrows($custRslt) < 1) { return "<li class='err'>Invalid customer ID, or customer has been blocked.</li>"; } else { $cust = pg_fetch_array($custRslt); } # Get department db_conn("exten"); $sql = "SELECT * FROM departments WHERE deptid = '{$cust['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); } #get vat acc ... $vatacc = gethook("accnum", "salesacc", "name", "VAT", "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['debtacc'], $date, $refnum, $amount, $details . " - Customer {$cust['cusname']} {$cust['surname']}"); $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>{$cust['accno']} - {$cust['cusname']} {$cust['surname']}</td>\n\t\t\t</tr>"; $samount = $amount - $amount * 2; $svatamt = $vatamt - $vatamt * 2; recordCT($samount, $cust['cusnum'], $date); $type = 'c'; if (isset($chrgvat) and $chrgvat == "yes") { writetrans($vatacc, $dept['debtacc'], $date, $refnum, $vatamt, "VAT for Transaction: {$refnum} for Customer : {$cust['cusname']} {$cust['surname']}"); vatr($vd['id'], $date, "OUTPUT", $vd['code'], $refnum, "VAT for Transaction: {$refnum} for Customer : {$cust['cusname']} {$cust['surname']}", $samount + $svatamt, $svatamt); } } else { # Write transaction (debit debtors control, credit contra account) writetrans($dept['debtacc'], $accid, $date, $refnum, $amount, $details . " - Customer {$cust['cusname']} {$cust['surname']}"); $tran = "\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>{$cust['accno']} - {$cust['cusname']} {$cust['surname']}</td>\n\t\t\t\t<td>{$acc['topacc']}/{$acc['accnum']} - {$acc['accname']}</td>\n\t\t\t</tr>"; $samount = $amount; $svatamt = $vatamt; recordDT($samount, $cust['cusnum'], $date); $type = 'd'; if (isset($chrgvat) and $chrgvat == "yes") { writetrans($dept['debtacc'], $vatacc, $date, $refnum, $vatamt, "VAT for Transaction: {$refnum} for Customer : {$cust['cusname']} {$cust['surname']}"); vatr($vd['id'], $date, "OUTPUT", $vd['code'], $refnum, "VAT for Transaction: {$refnum} for Customer : {$cust['cusname']} {$cust['surname']}", $amount + $vatamt, $vatamt); } } db_connect(); $sdate = date("Y-m-d"); # record the payment on the statement $sql = "\n\t\tINSERT INTO stmnt (\n\t\t\tcusnum, invid, amount, date, type, st, div, allocation_date\n\t\t) VALUES (\n\t\t\t'{$cust['cusnum']}', '0', '" . sprint($samount + $svatamt) . "', '{$date}', '{$details}', 'n', '" . USER_DIV . "', '{$date}'\n\t\t)"; $stmntRslt = db_exec($sql) or errDie("Unable to Insert statement record in Cubit.", SELF); $sql = "\n\t\tINSERT INTO open_stmnt (\n\t\t\tcusnum, invid, amount, balance, date, type, st, div\n\t\t) VALUES (\n\t\t\t'{$cust['cusnum']}', '0', '" . sprint($samount + $svatamt) . "', '" . sprint($samount + $svatamt) . "', '{$date}', '{$details}', 'n', '" . USER_DIV . "'\n\t\t)"; $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 + '{$samount}') WHERE cusnum = '{$cust['cusnum']}' AND div = '" . USER_DIV . "'"; $rslt = db_exec($sql) or errDie("Unable to update customer in Cubit.", SELF); # Make ledge record // custledger($cust['cusnum'], $accid, $date, $refnum, $details, $amount, $type); custledger($cust['cusnum'], $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>Customer Journal transaction has been recorded</h3>\n <table " . TMPL_tblDflts . " width='500'>\n \t<tr>\n \t\t<td width='50%'><h3>Debit</h3></td>\n \t\t<td width='50%'><h3>Credit</h3></td>\n \t</tr>\n \t{$tran}\n \t<tr><td><br></td></tr>\n \t<tr colspan='2'>\n \t\t<td><h4>Amount</h4></td>\n \t</tr>\n \t<tr class='" . bg_class() . "'>\n \t\t<td colspan='2'><b>" . CUR . " {$amount}</b></td>\n \t</tr>\n </table>" . mkQuickLinks(ql("trans-new.php", "Journal Transactions"), ql("../customers-view.php", "View Customers")); return $write; }