function confirm($_POST) { # Get vars global $_FILES, $DOCLIB_DOCTYPES; foreach ($_POST as $key => $value) { ${$key} = $value; } # Validate input require_lib("validate"); $v = new validate(); $v->isOk($typeid, "string", 1, 20, "Invalid type code."); if (isset($xin)) { $v->isOk($xin, "string", 1, 20, "Invalid {$DOCLIB_DOCTYPES[$typeid]} number."); } $v->isOk($docname, "string", 1, 255, "Invalid Document name."); $v->isOk($docref, "string", 0, 255, "Invalid Document reference."); $date = $day . "-" . $mon . "-" . $year; if (!checkdate($mon, $day, $year)) { $v->isOk($date, "num", 1, 1, "Invalid date."); } // $v->isOk ($docname, "string", 1, 255, "Invalid Document name."); $v->isOk($descrip, "string", 0, 255, "Invalid Document Description."); # Display errors, if any if ($v->isError()) { $confirm = ""; $errors = $v->enterErrors(); foreach ($errors as $e) { $confirm .= "<li class=err>" . $e["msg"]; } // $confirm .= "<p><input type=button onClick='JavaScript:history.back();' value='« Correct submission'>"; return enter($_POST, $confirm); } if (!isset($xin)) { $typRs = enter('cubit', "*", "doctypes", "typeid", $typeid); $typ = pg_fetch_array($typRs); $typename = "({$typ['typeref']}) {$typ['typename']}"; $xinc = ""; } else { $typename = $DOCLIB_DOCTYPES[$typeid]; $xinc = xinc($typeid, $xin); } # Deal with uploaded file if (empty($_FILES["doc"])) { return enter($_POST, "<li class=err> Please select a document to upload from your hard drive."); } if (is_uploaded_file($_FILES["doc"]["tmp_name"])) { $doctyp = $_FILES["doc"]["type"]; $filename = $_FILES["doc"]["name"]; # Open file in "read, binary" mode $docu = ""; $file = fopen($_FILES['doc']['tmp_name'], "rb"); while (!feof($file)) { # fread is binary safe $docu .= fread($file, 1024); } fclose($file); # Compress and encode the file $docu = doclib_encode($docu, 9); } else { return enter($_POST, "<li class=err> Unable to upload file, Please check file permissions."); } $confirm = "<h3>Confirm Document</h3>\r\n\t<form action='" . SELF . "' method=post>\r\n\t<table cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "'>\r\n\t<input type=hidden name=key value=write>\r\n\t<input type=hidden name=typeid value='{$typeid}'>\r\n\t<input type=hidden name=docname value='{$docname}'>\r\n\t<input type=hidden name=docref value='{$docref}'>\r\n\t<input type=hidden name=day value='{$day}'>\r\n\t<input type=hidden name=mon value='{$mon}'>\r\n\t<input type=hidden name=year value='{$year}'>\r\n\t<input type=hidden name=descrip value='{$descrip}'>\r\n \t<input type=hidden name=docu value='{$docu}'>\r\n\t<input type=hidden name=filename value='{$filename}'>\r\n\t<input type=hidden name=doctyp value='{$doctyp}'>\r\n\t<tr><th>Field</th><th>Value</th></tr>\r\n\t<tr class='bg-odd'><td>Type</td><td>{$typename}</td></tr>\r\n\t{$xinc}\r\n\t<tr class='bg-even'><td>Document Name</td><td>{$docname}</td></tr>\r\n\t<tr class='bg-odd'><td>Ref</td><td>{$docref}</td></tr>\r\n\t<tr class='bg-even'><td>Date</td><td align=center>{$date}</td></tr>\r\n\t<tr class='bg-odd'><td>File</td><td>{$filename}</td></tr>\r\n\t<tr class='bg-even'><td>Description</td><td>{$descrip}</td></tr>\r\n\t<tr><td><br></td></tr>\r\n\t<tr><td align=right></td><td valign=left><input type=submit value='Write »'></td></tr>\r\n\t</table></form>\r\n\t<p>\r\n\t<table border=0 cellpadding='2' cellspacing='1'>\r\n\t\t<tr><th>Quick Links</th></tr>\r\n\t\t<tr class='bg-odd'><td><a href='tdocview.php'>View Documents</a></td></tr>\r\n\t\t<tr class='bg-odd'><td><a href='docman-index.php'>Document Management</a></td></tr>\r\n\t</table>"; return $confirm; }
function write($_POST) { # Get vars global $_FILES; foreach ($_POST as $key => $value) { ${$key} = $value; } $vatcode += 0; # Validate input require_lib("validate"); $v = new validate(); $v->isOk($cashid, "num", 1, 4, "Invalid Reference number."); $v->isOk($refno, "string", 0, 255, "Invalid Receipt/Ref No."); $v->isOk($ret, "float", 0, 10, "Invalid Returned/Change amount."); $vatret += 0; # Display errors, if any if ($v->isError()) { $confirm = ""; $errors = $v->getErrors(); foreach ($errors as $e) { $confirm .= "<li class=err>" . $e["msg"]; } $confirm .= "<p><input type=button onClick='JavaScript:history.back();' value='« Correct submission'>"; return $confirm; } $date = DATE_STD; if (is_uploaded_file($_FILES["doc"]["tmp_name"])) { $doctyp = $_FILES["doc"]["type"]; $filename = $_FILES["doc"]["name"]; # Open file in "read, binary" mode $docu = ""; $file = fopen($_FILES['doc']['tmp_name'], "rb"); while (!feof($file)) { # fread is binary safe $docu .= fread($file, 1024); } fclose($file); # Compress and encode the file $docu = doclib_encode($docu, 9); } # Connect to database db_Connect(); $sql = "SELECT * FROM pettycashbook WHERE cashid = '{$cashid}' AND div = '" . USER_DIV . "'"; $cashRslt = db_exec($sql) or errDie("ERROR: Unable to retrieve cashbook entry details from database.", SELF); $cash = pg_fetch_array($cashRslt); # Mourn if the is not sufficient money if ($ret > $cash['amount']) { return "<li class=err>Error : Returned/Change amount is more than the requisistion amount.</li>\n\t\t<p><input type=button onClick='JavaScript:history.back();' value='« Correct submission'>"; } # Ya Nasty zero $ret += 0; $refnum = getrefnum($date); # Check available funds $cashacc = gethook("accnum", "bankacc", "name", "Petty Cash"); db_conn('cubit'); $Sl = "SELECT * FROM vatcodes WHERE id='{$vatcode}' AND zero='Yes'"; $Ri = db_exec($Sl) or errDie("Unable to get vat codes"); if (pg_num_rows($Ri) > 0) { $cash['chrgvat'] = "exc"; } db_conn('cubit'); $Sl = "SELECT * FROM vatcodes WHERE id='{$vatcode}'"; $Ri = db_exec($Sl) or errDie("Unable to get vat codes"); $vd = pg_fetch_array($Ri); # if amount is not equal to zero, write tran if ($ret != 0) { # If subtract vat if ($cash['chrgvat'] == "inc") { # Get vat account $vatacc = gethook("accnum", "salesacc", "name", "VAT"); $VATP = TAX_VAT; //$vatret = sprint(($VATP/($VATP + 100)) * $ret); $sret = $ret - $vatret; # Write returning transaction writetrans($cashacc, $cash['accid'], date("Y-m-d"), $refnum, $sret, "Petty Cash Change"); # Write VAT returning transaction writetrans($cashacc, $vatacc, date("Y-m-d"), $refnum, $vatret, "VAT return, " . $cash['det']); vatr($vd['id'], date("Y-m-d"), "INPUT", $vd['code'], $refnum, "VAT return, " . $cash['det'], $sret + $vatret, $vatret); /* # Record vat statement db_connect(); $sql = "INSERT INTO svatrec(edate, ref, amount, descript, div) VALUES('".date("Y-m-d")."', '$refnum', '$vatret', 'VAT returned on Petty Cash Change.', '".USER_DIV."')"; $stmntRslt = db_exec($sql) or errDie("Unable to insert statement record in Cubit.",SELF); */ } elseif ($cash['chrgvat'] == "exc") { # Get vat account $vatacc = gethook("accnum", "salesacc", "name", "VAT"); $VATP = TAX_VAT; //$vatret = sprint(($VATP/100) * $ret); $sret = $ret; $ret += $vatret; # Write returning transaction writetrans($cashacc, $cash['accid'], date("Y-m-d"), $refnum, $sret, "Petty Cash Change"); # Write VAT returning transaction writetrans($cashacc, $vatacc, date("Y-m-d"), $refnum, $vatret, "VAT return, " . $cash['det']); vatr($vd['id'], date("Y-m-d"), "INPUT", $vd['code'], $refnum, "VAT return, " . $cash['det'], $sret + $vatret, $vatret); /* # Record vat statement db_connect(); $sql = "INSERT INTO svatrec(edate, ref, amount, descript, div) VALUES('".date("Y-m-d")."', '$refnum', '$vatret', 'VAT returned on Petty Cash Change.', '".USER_DIV."')"; $stmntRslt = db_exec($sql) or errDie("Unable to insert statement record in Cubit.",SELF); */ } else { # Write returning transaction writetrans($cashacc, $cash['accid'], date("Y-m-d"), $refnum, $ret, "Petty Cash Change"); $sret = $ret; } # Record tranfer for patty cash report db_connect(); $date = date("Y-m-d"); $sql = "INSERT INTO pettyrec(date, type, det, amount, name, div) VALUES ('{$date}', 'Change', 'Petty Cash Change', '{$ret}', 'Cash Received From : {$cash['name']}', '" . USER_DIV . "')"; $Rslt = db_exec($sql) or errDie("Unable to add bank payment to database.", SELF); } if (!isset($sret)) { $sret = 0; } # Update db_connect(); $sql = "UPDATE pettycashbook SET refno = '{$refno}', amount = (amount - '{$ret}'), reced = 'yes' WHERE cashid='{$cashid}' AND div = '" . USER_DIV . "'"; $Rslt = db_exec($sql) or errDie("Unable to cancel cheque.", SELF); if (isset($docu)) { db_conn(YR_DB); $sql = "INSERT INTO documents(typeid, typename, xin, docref, docdate, docname, filename, mimetype, descrip, docu, div) VALUES ('prec', 'Petty Cash Receipt', '{$refno}', '{$refno}', '{$date}', '{$filename}', '{$filename}', '{$doctyp}', 'Receipt from {$cash['name']}', '{$docu}', '" . USER_DIV . "')"; $docRslt = db_exec($sql) or errDie("Unable to add {$docname} to system.", SELF); } if (cc_TranTypeAcc($cashacc, $cash['accid']) != false) { $cc_trantype = cc_TranTypeAcc($cashacc, $cash['accid']); $cc = "<script> CostCenter('{$cc_trantype}', 'Petty Cash Receipt', '{$date}', '{$cash['det']}', '{$sret}', '../'); </script>"; } else { $cc = ""; } # Status report $write = "{$cc}\n\t<table border=0 cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "' width='30%'>\n\t\t<tr><th>Petty Cash Requisition Approved</th></tr>\n\t\t<tr class=datacell><td>Petty Cash Requisition has been approved .</td></tr>\n\t</table>\n\t<p>\n\t<table border=0 cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "' width=15%>\n\t\t<tr><th>Quick Links</th></tr>\n\t\t<tr class='bg-odd'><td><a href='petty-req-add.php'>Add Petty Cash Requisition</a></td></tr>\n\t\t<tr class='bg-odd'><td><a href='pettycashbook-view.php'>View Petty Cash Requisitions</a></td></tr>\n\t\t<tr class='bg-odd'><td><a href='../main.php'>Main Menu</a></td></tr>\n\t</table>"; return $write; }