function write_data($_POST) { extract($_POST); if (isset($back)) { return enter_data2($_POST); } db_conn('core'); $Sl = "SELECT accnum FROM salesacc WHERE name='VATIN'"; $Ri = db_exec($Sl); if (pg_num_rows($Ri) > 0) { $vd = pg_fetch_array($Ri); $vatin = $vd['accnum']; } else { $vatin = 0; } $Sl = "SELECT accnum FROM salesacc WHERE name='VATOUT'"; $Ri = db_exec($Sl); if (pg_num_rows($Ri) > 0) { $vd = pg_fetch_array($Ri); $vatout = $vd['accnum']; } else { $vatout = 0; } db_conn('cubit'); $Sl = "SELECT * FROM vatcodes WHERE del='Yes'"; $Ri = db_exec($Sl); if (pg_num_rows($Ri) < 1) { $Sl = "SELECT * FROM vatcodes WHERE zero='Yes'"; $Ri = db_exec($Sl); if (pg_num_rows($Ri) < 1) { return "Please set up your vatcodes first."; } } $vcd = pg_fetch_array($Ri); db_conn('exten'); $Sl = "SELECT debtacc FROM departments"; $Ri = db_exec($Sl); $dd = pg_fetch_array($Ri); $cc = $dd['debtacc']; db_conn('core'); $Sl = "SELECT * FROM accounts WHERE accname='Opening Balances / Suspense Account'"; $Ri = db_exec($Sl) or errDie("Unable to get account."); if (pg_num_rows($Ri) < 1) { return "<li class='err'>There is no account called 'Opening Balances / Suspense Account'. <br>\n\t\tI Need that account.<br>\n\t\tPlease create it. <br><br>\n\t\tThank you.</li>"; } $ad = pg_fetch_array($Ri); $bala = $ad['accid']; db_conn(PRD_DB); # get last ref number pglib_transaction("BEGIN"); $refnum = getrefnum(); /* check for main accounts whose sub accounts add up to same total, then clear main account check for main accounts whose sub accounts dont add up, then unblock main accounts */ $sql = "SELECT * FROM cubit.import_data"; $rslt = db_exec($sql) or errDie("Error validating data."); $acsub = $acmain = array(); while ($fd = pg_fetch_array($rslt)) { $n = explode("/", $fd["des1"]); if (!isset($n[1]) || $n[1] == "000") { $n[1] = "000"; } $a = array("num" => $fd["des1"], "name" => $fd["des2"], "dt" => $fd["des3"], "ct" => $fd["des4"]); if ($n[1] == "000") { $acmain["{$n['0']}"] = $a; } else { if (!isset($acsub[$n[0]])) { $acsub[$n[0]] = array(); } $acsub[$n[0]][] = $a; } } /* match subs with mains */ $unblock_main = false; foreach ($acmain as $k => $v) { $totdt = 0; $totct = 0; if (isset($acsub[$k])) { foreach ($acsub[$k] as $sk => $sv) { $totdt += $sv["dt"]; $totct += $sv["ct"]; } if ($totdt - $totct != $v["dt"] - $v["ct"]) { $unblock_main = true; } else { $sql = "UPDATE cubit.import_data SET des3='0', des4='0'\n\t\t\t\t\t\tWHERE des1='{$v['num']}' AND des2='{$v['name']}'"; $rslt = db_exec($sql) or errDie("Error balancing main account with sub accounts: {$v['num']} - {$v['name']} with {$sv['num']} - {$sv['name']}."); } } } if ($unblock_main) { $sql = "UPDATE cubit.set SET value = 'nuse', descript = 'Dont block main accounts'\n\t\t\t\tWHERE label = 'BLOCK' AND div = '" . USER_DIV . "'"; $rslt = db_exec($sql) or errDie("Error unblocking main accounts."); } /* continue importing (validated/fixed) data */ db_conn('cubit'); $Sl = "SELECT * FROM import_data"; $Ri = db_exec($Sl); $i = 0; $tot_debit = 0; $tot_credit = 0; $date = mkdate(getYearOfFinMon($prd), $prd, 1); db_conn('core'); while ($fd = pg_fetch_array($Ri)) { $fid = $fd['id']; $accs = explode('/', $fd['des1']); $topacc = $accs[0]; $topacc = str_pad($topacc, 4, "0"); if (isset($accs[1])) { $accnum = $accs[1]; } else { $accnum = "000"; } db_conn('core'); if ($accounts[$fid] == 0) { $catss = explode(":", $cat[$fid]); if ($catss[0] == "other_income" || $catss[0] == "sales") { $catT = "I10"; $type = "I"; } elseif ($catss[0] == "expenses" || $catss[0] == "cost_of_sales") { $catT = "E10"; $type = "E"; } else { $catT = "B10"; $type = "B"; } $Sl = "\n\t\t\t\tINSERT INTO accounts (\n\t\t\t\t\ttopacc, accnum, catid, accname, vat, \n\t\t\t\t\tdiv, toptype, acctype\n\t\t\t\t) VALUES (\n\t\t\t\t\t'{$topacc}', '{$accnum}', '{$catT}', '{$fd['des2']}', 'f', \n\t\t\t\t\t'" . USER_DIV . "', '{$catss['0']}', '{$type}'\n\t\t\t\t)"; $Rl = db_exec($Sl); $accname = $fd['des2']; $accid = pglib_lastid("accounts", "accid"); // $query = "INSERT INTO trial_bal(accid, topacc, accnum, accname, div) VALUES('$accid', '$topacc', '$accnum', '$fd[des2]', '".USER_DIV."')"; // $trialRslt = db_exec($query); global $MONPRD; insert_trialbal($accid, $topacc, $accnum, $accname, $type, 'f', USER_DIV); for ($i = 1; $i <= 12; $i++) { $periodname = getMonthName($i); $sql = "INSERT INTO " . YR_DB . ".{$periodname} (accid, topacc, accnum, accname,\n\t\t\t\t\t\t\tdebit, credit, div)\n\t\t\t\t\t\tSELECT accid, topacc, accnum, accname, debit, credit, div\n\t\t\t\t\t\tFROM core.trial_bal WHERE month='{$i}' AND accid='{$accid}'"; db_exec($sql) or die($sql); $sql = "INSERT INTO \"{$i}\".openbal (accid, accname, debit, credit, div)\n\t\t\t\t\t\tSELECT accid, accname, debit, credit, div\n\t\t\t\t\t\tFROM core.trial_bal WHERE month='{$i}' AND accid='{$accid}'"; db_exec($sql) or die($sql); $sql = "INSERT INTO \"{$i}\".ledger (acc, contra, edate, eref, descript,\n\t\t\t\t\t\t\tcredit, debit, div, caccname, ctopacc, caccnum, cbalance, dbalance)\n\t\t\t\t\t\tSELECT accid, accid, CURRENT_DATE, '0', 'Balance', '0', '0', div,\n\t\t\t\t\t\t\taccname, topacc, accnum, credit, debit\n\t\t\t\t\t\tFROM core.trial_bal WHERE month='{$i}' AND accid='{$accid}'"; db_exec($sql) or die($sql); } $accounts[$fid] = $accid; } else { $Sl = "UPDATE accounts SET topacc='{$topacc}',accnum='{$accnum}',accname='{$fd['des2']}' WHERE accid='{$accounts[$fid]}'"; $Rl = db_exec($Sl); $Sl = "UPDATE trial_bal SET topacc='{$topacc}',accnum='{$accnum}',accname='{$fd['des2']}' WHERE accid='{$accounts[$fid]}'"; $Rl = db_exec($Sl); } $Sl = "SELECT accid,accname FROM accounts WHERE accid='{$accounts[$fid]}'"; $Rx = db_exec($Sl); $ad = pg_fetch_array($Rx); $i++; $debit = $fd['des3']; $credit = $fd['des4']; if ($debit > 0) { writetrans($ad['accid'], $bala, $date, $refnum, sprint($debit), "Opening balance imported"); } if ($credit > 0) { writetrans($bala, $ad['accid'], $date, $refnum, sprint($credit), "Opening balance imported"); } $tot_debit += $fd['des3']; $tot_credit += $fd['des4']; if ($ad['accid'] == $vatin) { vatr($vcd['id'], $date, "INPUT", $vcd['code'], $refnum, "Opening balance VAT imported", sprint($credit - $debit), sprint($credit - $debit)); } if ($ad['accid'] == $vatout) { vatr($vcd['id'], $date, "OUTPUT", $vcd['code'], $refnum, "Opening balance VAT imported", sprint($credit - $debit), sprint($credit - $debit)); } } $tot_debit = sprint($tot_debit); $tot_credit = sprint($tot_credit); if ($cc_tot > 0) { $tot = array_sum($cbalance); if (sprint($cc_tot) != sprint($tot)) { return enter_data2($_POST) . "<li class='err'>The total amount for balances for customers you entered is: " . CUR . " {$tot}, the\n\t\t\ttotal for the control account is: " . sprint($cc_tot) . ". These need to be the same.</li>"; } db_conn('cubit'); $Sl = "SELECT cusnum,accno,surname FROM customers ORDER BY surname"; $Ri = db_exec($Sl); if (pg_num_rows($Ri) < 1) { return "<li class='err'>If you want to import your customer control account you need to add customers first</li>"; } $tot = 0; while ($cd = pg_fetch_array($Ri)) { $cid = $cd['cusnum']; $cbalance[$cid] = sprint($cbalance[$cid]); if ($cbalance[$cid] > 0) { db_conn('cubit'); # Update the customer (make balance more) $sql = "UPDATE customers SET balance = (balance + '{$cbalance[$cid]}') WHERE cusnum = '{$cid}' AND div = '" . USER_DIV . "'"; $rslt = db_exec($sql) or errDie("Unable to update invoice in Cubit.", SELF); $sql = "\n\t\t\t\t\tINSERT INTO stmnt (\n\t\t\t\t\t\tcusnum, invid, amount, date, type, \n\t\t\t\t\t\tst, div\n\t\t\t\t\t) VALUES (\n\t\t\t\t\t\t'{$cid}', '0', '{$cbalance[$cid]}', '{$date}', 'Opening Balance Imported', \n\t\t\t\t\t\t'n', '" . USER_DIV . "'\n\t\t\t\t\t)"; $stmntRslt = db_exec($sql) or errDie("Unable to Insert statement record in Cubit.", SELF); $sql = "\n\t\t\t\t\tINSERT INTO open_stmnt (\n\t\t\t\t\t\tcusnum, invid, amount, balance, date, \n\t\t\t\t\t\ttype, st, div\n\t\t\t\t\t) VALUES (\n\t\t\t\t\t\t'{$cid}', '0', '{$cbalance[$cid]}', '{$cbalance[$cid]}', '{$date}', \n\t\t\t\t\t\t'Opening Balance Imported', 'n', '" . USER_DIV . "'\n\t\t\t\t\t)"; $stmntRslt = db_exec($sql) or errDie("Unable to Insert statement record in Cubit.", SELF); crecordDT($cbalance[$cid], $cid, $date); custledger($cid, $bala, $date, 0, "Opening Balance Imported", $cbalance[$cid], "d"); } elseif ($cbalance[$cid] < 0) { db_conn('cubit'); # Update the customer (make balance more) $sql = "UPDATE customers SET balance = (balance + '{$cbalance[$cid]}') WHERE cusnum = '{$cid}' AND div = '" . USER_DIV . "'"; $rslt = db_exec($sql) or errDie("Unable to update invoice in Cubit.", SELF); $sql = "\n\t\t\t\t\tINSERT INTO stmnt (\n\t\t\t\t\t\tcusnum, invid, amount, date, type, \n\t\t\t\t\t\tst, div\n\t\t\t\t\t) VALUES (\n\t\t\t\t\t\t'{$cid}', '0', '{$cbalance[$cid]}', '{$date}', 'Opening Balance Imported', \n\t\t\t\t\t\t'n', '" . USER_DIV . "'\n\t\t\t\t\t)"; $stmntRslt = db_exec($sql) or errDie("Unable to Insert statement record in Cubit.", SELF); $sql = "\n\t\t\t\t\tINSERT INTO open_stmnt (\n\t\t\t\t\t\tcusnum, invid, amount, balance, date, \n\t\t\t\t\t\ttype, st, div\n\t\t\t\t\t) VALUES (\n\t\t\t\t\t\t'{$cid}', '0', '{$cbalance[$cid]}', '{$cbalance[$cid]}', '{$date}', \n\t\t\t\t\t\t'Opening Balance Imported', 'n', '" . USER_DIV . "'\n\t\t\t\t\t)"; $stmntRslt = db_exec($sql) or errDie("Unable to Insert statement record in Cubit.", SELF); crecordCT(-$cbalance[$cid], $cid, $date); custledger($cid, $bala, $date, 0, "Opening Balance Imported", -$cbalance[$cid], "c"); } $i++; $tot += $cbalance[$cid]; } } if ($sc_tot > 0) { db_conn('cubit'); $Sl = "SELECT supid,supno,supname FROM suppliers ORDER BY supname"; $Ri = db_exec($Sl); if (pg_num_rows($Ri) < 1) { return "<li class='err'>If you want to import your supplier control account you need to add suppliers first</li>"; } $tot = 0; while ($cd = pg_fetch_array($Ri)) { $sid = $cd['supid']; $sbalance[$sid] += 0; if ($sbalance[$sid] > 0) { db_conn('cubit'); $sql = "UPDATE suppliers SET balance = (balance + '{$sbalance[$sid]}') WHERE supid = '{$sid}' AND div = '" . USER_DIV . "'"; $rslt = db_exec($sql) or errDie("Unable to update supplier in Cubit.", SELF); $sql = "\n\t\t\t\t\tINSERT INTO sup_stmnt (\n\t\t\t\t\t\tsupid, edate, ref, cacc, descript, \n\t\t\t\t\t\tamount, div\n\t\t\t\t\t) VALUES (\n\t\t\t\t\t\t'{$sid}', '{$date}', '0', '{$bala}', 'Opening balance imported', \n\t\t\t\t\t\t'{$sbalance[$sid]}', '" . USER_DIV . "'\n\t\t\t\t\t)"; $stmntRslt = db_exec($sql) or errDie("Unable to Insert statement record in Cubit.", SELF); recordCT(-$sbalance[$sid], $sid, $date); suppledger($sid, $bala, $date, $refnum, "Opening balance imported", $sbalance[$sid], "c"); } elseif ($sbalance[$sid] < 0) { db_conn('cubit'); $sql = "UPDATE suppliers SET balance = (balance + '{$sbalance[$sid]}') WHERE supid = '{$sid}' AND div = '" . USER_DIV . "'"; $rslt = db_exec($sql) or errDie("Unable to update supplier in Cubit.", SELF); $sql = "\n\t\t\t\t\tINSERT INTO sup_stmnt (\n\t\t\t\t\t\tsupid, edate, ref, cacc, descript, amount, div\n\t\t\t\t\t) VALUES (\n\t\t\t\t\t\t'{$sid}', '{$date}', '0', '{$bala}', 'Opening balance imported', \n\t\t\t\t\t\t'{$sbalance[$sid]}', '" . USER_DIV . "'\n\t\t\t\t\t)"; $stmntRslt = db_exec($sql) or errDie("Unable to Insert statement record in Cubit.", SELF); recordDT(-$sbalance[$sid], $sid, $date); suppledger($sid, $bala, $date, $refnum, "Opening balance imported", $sbalance[$sid], "d"); } $i++; $tot += $sbalance[$sid]; } if (sprint($sc_tot) != sprint($tot)) { return enter_data2($_POST) . "<li class='err'>The total amount for balances for suppliers you entered is: " . CUR . " {$tot}, the\n\t\t\ttotal for the control account is: " . sprint($sc_tot) . ". These need to be the same.</li>"; } } if ($sal_tot > 0) { db_conn('cubit'); $Sl = "SELECT empnum,enum,sname,fnames FROM employees ORDER BY sname,fnames"; $Ri = db_exec($Sl); if (pg_num_rows($Ri) < 1) { return "<li class='err'>If you want to import your employee control account you need to add employees first</li>"; } $tot = 0; while ($cd = pg_fetch_array($Ri)) { $eid = $cd['empnum']; if (!isset($ebalance[$eid])) { $ebalance[$eid] = ""; } $ebalance[$eid] = sprint($ebalance[$eid]); db_conn('cubit'); $Sl = "UPDATE employees SET balance=balance+'{$ebalance[$eid]}' WHERE empnum = '{$eid}' AND div = '" . USER_DIV . "'"; $Rt = db_exec($Sl) or errDie("Unable to get employee details."); if ($ebalance[$eid] > 0) { empledger($eid, $bala, $date, $refnum, "Opening balance imported", $ebalance[$eid], "c"); } else { empledger($eid, $bala, $date, $refnum, "Opening balance imported", abs($ebalance[$eid]), "d"); } $i++; $tot += $ebalance[$eid]; } if (sprint($sal_tot) != sprint($tot)) { return enter_data2($_POST) . "<li class='err'>The total amount for balances for employees you entered is: " . CUR . " {$tot}, the\n\t\t\ttotal for the control account is: " . sprint($sal_tot) . ". These need to be the same.</li>"; } } if ($i_tot > 0) { db_conn('cubit'); $Sl = "SELECT stkid,stkcod,stkdes FROM stock ORDER BY stkcod"; $Ri = db_exec($Sl); if (pg_num_rows($Ri) < 1) { return "<li class='err'>If you want to import your inventory control account you need to add stock first</li>"; } $tot = 0; while ($cd = pg_fetch_array($Ri)) { $iid = $cd['stkid']; if (!isset($ibalance[$iid])) { $ibalance[$iid] = ""; } if ($ibalance[$iid] > 0) { $unitnum = $units[$iid]; db_connect(); $sql = "UPDATE stock SET csamt = (csamt + '{$ibalance[$iid]}'), units = (units + '{$unitnum}') WHERE stkid = '{$iid}' AND div = '" . USER_DIV . "'"; $rslt = db_exec($sql) or errDie("Unable to insert stock to Cubit.", SELF); stockrec($cd['stkid'], $cd['stkcod'], $cd['stkdes'], 'dt', $date, $unitnum, $ibalance[$iid], "Inventory balance imported"); db_connect(); $cspric = sprint($ibalance[$iid] / $unitnum); //$cspric = sprint(0); $sql = "\n\t\t\t\t\tINSERT INTO stockrec (\n\t\t\t\t\t\tedate, stkid, stkcod, stkdes, trantype, qty, \n\t\t\t\t\t\tcsprice, csamt, details, div\n\t\t\t\t\t) VALUES (\n\t\t\t\t\t\t'{$date}', '{$cd['stkid']}', '{$cd['stkcod']}', '{$cd['stkdes']}', 'inc', '{$unitnum}', \n\t\t\t\t\t\t'{$ibalance[$iid]}', '{$cspric}', 'Inventory balance imported', '" . USER_DIV . "'\n\t\t\t\t\t)"; $recRslt = db_exec($sql); db_connect(); $sql = "SELECT * FROM stock WHERE stkid = '{$iid}' AND div = '" . USER_DIV . "'"; $stkRslt = db_exec($sql) or errDie("Unable to access databse.", SELF); if (pg_numrows($stkRslt) < 1) { return "<li> Invalid Stock ID.</li>"; } else { $stk = pg_fetch_array($stkRslt); } if ($stk['units'] != 0) { $sql = "UPDATE stock SET csprice = (csamt/units) WHERE stkid = '{$iid}' AND div = '" . USER_DIV . "'"; $rslt = db_exec($sql) or errDie("Unable to insert stock to Cubit.", SELF); } else { $sql = "UPDATE stock SET csprice = '{$csprice}' WHERE stkid = '{$iid}' AND div = '" . USER_DIV . "'"; $rslt = db_exec($sql) or errDie("Unable to insert stock to Cubit.", SELF); } } $tot += $ibalance[$iid]; $i++; } if (sprint($i_tot) != sprint($tot)) { return enter_data2($_POST) . "<li class='err'>The total amount for balances for inventory you entered is: " . CUR . " {$tot}, the\n\t\t\ttotal for the control account is: " . sprint($sal_tot) . ". These need to be the same.</li>"; } } $out = "\n\t\t<table " . TMPL_tblDflts . " width='50%'>\n\t\t\t<tr>\n\t\t\t\t<th>Data Imported</th>\n\t\t\t</tr>\n\t\t\t<tr class='datacell'>\n\t\t\t\t<td>Trial balance, has been successfully imported.</td>\n\t\t\t</tr>\n\t\t</table>"; pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF); block(); return $out; }
function write($_POST) { extract($_POST); if (isset($back)) { unset($_POST["back"]); return slctCat($_POST); } require_lib("validate"); $v = new validate(); $v->isOk($type, "string", 1, 2, "Invalid category type."); $v->isOk($tab, "string", 1, 14, "Invalid category type."); $v->isOk($accname, "string", 1, 50, "Invalid account name."); $v->isOk($catid, "string", 1, 50, "Invalid category Id/name."); $v->isOk($topacc, "num", 4, 4, "Invalid account number."); $v->isOk($accnum, "num", 1, 3, "Invalid account number."); $v->isOk($toptype, "string", 1, 255, "Invalid category type."); if ($v->isError()) { $err = $v->genErrors(); return $err; } core_connect(); $sql = "SELECT * FROM accounts WHERE accname = '{$accname}' AND div = '" . USER_DIV . "'"; $checkRslt = db_exec($sql) or errDie("Unable to retrieve Account details from database."); if (pg_numrows($checkRslt) > 0) { $confirm = "\n\t\t\t<tr>\n\t\t\t\t<td colspan='2' class='err'>Account name already exist.</td>\n\t\t\t</tr>"; return slctCaterr($type, $tab, $accname, $catid, $topacc, $accnum, $confirm); exit; } # Check Account Number core_connect(); $sql = "SELECT * FROM accounts WHERE topacc = '{$topacc}' AND accnum = '{$accnum}' AND div = '" . USER_DIV . "'"; $checkRslt = db_exec($sql) or errDie("Unable to retrieve Account details from database."); $check = pg_numrows($checkRslt); if (pg_numrows($checkRslt) > 0) { $confirm = "\n\t\t\t<tr>\n\t\t\t\t<td colspan='2' class='err'>The Account number is already in use.</td>\n\t\t\t</tr>"; return slctCaterr($type, $tab, $accname, $catid, $topacc, $accnum, $confirm); exit; } # Begin sql transaction pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF); // Get the db value of toptype $toptype_db = explode(":", $toptype); $toptype_db = $toptype_db[0]; # write to DB $sql = "\n\t\tINSERT INTO accounts (\n\t\t\ttopacc, accnum, accname, acctype, catid, div, toptype\n\t\t) VALUES (\n\t\t\t'{$topacc}', '{$accnum}', '{$accname}','{$type}', '{$catid}', '" . USER_DIV . "', '{$toptype_db}'\n\t\t)"; $catRslt = db_exec($sql) or errDie("Unable to add Account to Database.", SELF); # get last inserted id for new acc $accid = pglib_lastid("accounts", "accid"); global $MONPRD; $month_names = array(0, "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); # insert account into trial Balance insert_trialbal($accid, $topacc, $accnum, $accname, $type, 'f', USER_DIV); for ($i = 1; $i <= 12; $i++) { $periodname = getMonthName($i); $sql = "\n\t\t\tINSERT INTO " . YR_DB . ".{$periodname} (\n\t\t\t\taccid, topacc, accnum, accname, debit, credit, div\n\t\t\t) SELECT accid, topacc, accnum, accname, debit, credit, div FROM core.trial_bal WHERE month='{$i}' AND accid='{$accid}'"; db_exec($sql) or die($sql); $sql = "\n\t\t\tINSERT INTO \"{$i}\".openbal (\n\t\t\t\taccid, accname, debit, credit, div\n\t\t\t) SELECT accid, accname, debit, credit, div FROM core.trial_bal WHERE month='{$i}' AND accid='{$accid}'"; db_exec($sql) or die($sql); $sql = "\n\t\t\tINSERT INTO \"{$i}\".ledger (\n\t\t\t\tacc, contra, edate, eref, descript, credit, debit, div, caccname, ctopacc, caccnum, cbalance, dbalance\n\t\t\t) SELECT accid, accid, CURRENT_DATE, '0', 'Balance', '0', '0', div, accname, topacc, accnum, credit, debit \n\t\t\tFROM core.trial_bal \n\t\t\tWHERE month='{$i}' AND accid='{$accid}'"; db_exec($sql) or die($sql); } pglib_transaction("COMMIT") or errDie("Unable to start a database transaction.", SELF); block(); // print " // <script> // window.opener.location.reload(); // window.close(); // </script>"; if (isset($update_parent) and $update_parent == "yes") { #do something to reload the parent window ... print "\n\t\t\t<script>\n\t\t\t\twindow.opener.document.form.key.value='{$set_key}';\n\t\t\t\twindow.opener.document.form.submit ();\n\t\t\t\twindow.close();\n\t\t\t</script>"; } else { #do normal return # status report $write = "\n\t\t\t<table " . TMPL_tblDflts . " width='50%'>\n\t\t\t\t<tr>\n\t\t\t\t\t<th>New Account</th>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='datacell'>\n\t\t\t\t\t<td>New Account, <b>({$topacc}/{$accnum}) - {$accname}</b> was successfully added to Cubit.</td>\n\t\t\t\t</tr>\n\t\t\t</table><br>" . mkQuickLinks(ql("../reporting/allcat.php", "List All Accounts (New Window)", true), ql("acc-view.php", "View Accounts"), ql("acc-new2.php", "Add Account")); return $write; } }
/** * @ignore */ function newacc($topacc, $accnum, $accname, $acctype, $vat, $ttype = false) { global $catids; if ($ttype === false) { $ttype = "NULL"; } else { $ttype = "'{$ttype}'"; } pglib_transaction("BEGIN") or errDie("Unable to start transaction"); $sql = "\n\t\t\tINSERT INTO core.accounts (\n\t\t\t\ttopacc, accnum, accname, acctype, \n\t\t\t\tcatid, vat, div, toptype\n\t\t\t) VALUES (\n\t\t\t\t'{$topacc}', '{$accnum}', '{$accname}', '{$acctype}', \n\t\t\t\t'{$catids[$acctype]}', '{$vat}', '" . USER_DIV . "', {$ttype}\n\t\t\t)"; $rslt = db_exec($sql) or errDie("Unable to add account: {$topacc}/{$accnum} {$accname}."); $accid = pglib_lastid("core.accounts", "accid"); insert_trialbal($accid, $topacc, $accnum, $accname, $acctype, $vat, USER_DIV); pglib_transaction("COMMIT") or errDie("Unable to complete transaction."); return $accid; }