$dr_acc = $v_cash_acc_id; $cr_acc = $account_code; } else { //Payment //Debit - $account_code //Credit - Cash Account (Cash in hand) $dr_acc = $account_code; $cr_acc = $v_cash_acc_id; } if (strlen($cash_book_id) > 0) { $voucher_id = getValue("voucher_id", "voucher_detail", "voucher_id = (SELECT voucher_id FROM cash_book WHERE cb_id = {$cash_book_id})", true); d_mysql_query("UPDATE voucher_detail SET debit_amount = {$cash_book_ammount}, account_ref_id = {$dr_acc} WHERE voucher_id = {$voucher_id} AND remarks = 'Debit'"); d_mysql_query("UPDATE voucher_detail SET credit_amount = {$cash_book_ammount}, account_ref_id = {$cr_acc} WHERE voucher_id = {$voucher_id} AND remarks = 'Credit'"); d_mysql_query("UPDATE voucher_master SET voucher_remarks = '{$remarks}' WHERE voucher_id = {$voucher_id}"); } else { $createVoucher = createVoucher($selected_company_id, $year_id, $dr_acc, $cr_acc, $cash_book_ammount, $remarks, $parent_key, 'CR', $cash_book_date, $_SESSION['user_id']); dump($createVoucher); } } } } dump($data); $mysqli->close(); $json = new Services_JSON(); $output = $json->encode($data); print $output; $out = ob_get_contents(); ob_end_clean(); if (!isLive()) { $fp = fopen('cash_book_cud.htm', 'w'); fwrite($fp, "<html><head><title>CASH BOOK CUD</title></head><body>");
$dr_acc = getValue("code", "sys_codes", "description = 'Cash in Hand' AND company_ref_id = {$selected_company_id}", true); $cr_acc = getValue("code", "sys_codes", "description = 'Cash Sales' AND company_ref_id = {$selected_company_id}", true); } else { //Credit Sale //Debit - Party //Credit - Credit Sales $dr_acc = getValue("account_ref_id", "party", "party_code = {$_POST['sales_party_hidden']}", true); $cr_acc = getValue("code", "sys_codes", "description = 'Credit Sales' AND company_ref_id = {$selected_company_id}", true); } if ($_POST['oper'] == 'update') { $voucher_id = getValue("voucher_id", "sales_master", "sale_master_id = {$_POST['sales_id']}", true); d_mysql_query("UPDATE voucher_detail SET debit_amount = {$sale}, account_ref_id = {$dr_acc} WHERE voucher_id = {$voucher_id} AND remarks = 'Debit'"); d_mysql_query("UPDATE voucher_detail SET credit_amount = {$sale}, account_ref_id = {$cr_acc} WHERE voucher_id = {$voucher_id} AND remarks = 'Credit'"); d_mysql_query("UPDATE voucher_master SET voucher_date = '" . my_sql_date($_POST['sales_date']) . "', voucher_remarks = '{$_POST['sales_remarks']}' WHERE voucher_id = {$voucher_id}"); } else { $createVoucher = createVoucher($selected_company_id, $year_id, $dr_acc, $cr_acc, $sale, $_POST['sales_remarks'], $parent_key, 'S', my_sql_date($_POST['sales_date']), $_SESSION['user_id']); dump($createVoucher); $mysqli->close(); } $voucher_id = getValue("voucher_id", "sales_master", "sale_master_id = {$parent_key}", true); d_mysql_query("UPDATE voucher_detail SET debit_amount = {$sum} WHERE voucher_id = {$voucher_id} AND remarks = 'Debit'"); d_mysql_query("UPDATE voucher_detail SET debit_amount = {$disc} WHERE voucher_id = {$voucher_id} AND remarks = 'Discount'"); //reset all taxes d_mysql_query("UPDATE voucher_detail SET credit_amount = 0 WHERE voucher_id = {$voucher_id} AND remarks = 'Tax'"); if ($tax > 0) { $taxes = array(); $counter = $_POST['counter'] * 1; for ($i = 1; $i <= $counter; $i++) { $i_code = $_POST["item_" . $i . "_hidden"]; if (strlen($i_code) < 1) { continue;
$sum = getValue("sum(pr_qty * pr_rate) amt", "purchase_return_detail", "pur_ret_master_id = {$parent_key}"); $voucher_id = getValue("voucher_id", "purchase_return_master", "pur_ret_master_id = {$parent_key}"); dd_mysql_query("UPDATE voucher_detail SET debit_amount = {$sum} WHERE voucher_id = {$voucher_id} AND debit_amount > 0"); dd_mysql_query("UPDATE voucher_detail SET credit_amount = {$sum} WHERE voucher_id = {$voucher_id} AND credit_amount > 0"); if ($_POST['purchase_return_type'] == 'C') { $v_cash_acc_id = getValue("code", "sys_codes", "description = 'CASH ACCOUNT'"); $v_ch_pur_acc_id = getValue("code", "sys_codes", "description = 'PURCHASE RETURN'"); dd_mysql_query("UPDATE voucher_detail SET account_code = {$v_cash_acc_id}, remarks = '0' WHERE voucher_id = {$voucher_id} AND debit_amount > 0"); dd_mysql_query("UPDATE voucher_detail SET account_code = {$v_ch_pur_acc_id}, remarks = '1' WHERE voucher_id = {$voucher_id} AND credit_amount > 0"); } else { $v_cr_pur_acc_id = getValue("code", "sys_codes", "description = 'CREDIT PURCHASE'"); $v_party_acc_code = getValue("account_code", "party", "party_code = {$_POST['purchase_return_party_hidden']}"); dd_mysql_query("UPDATE voucher_detail SET account_code = {$v_cr_pur_acc_id}, remarks = '2-1' WHERE voucher_id = {$voucher_id} AND debit_amount > 0"); dd_mysql_query("UPDATE voucher_detail SET account_code = {$v_party_acc_code}, remarks = '3-1' WHERE voucher_id = {$voucher_id} AND credit_amount > 0"); } } else { $sum = getValue("sum(pr_qty * pr_rate) amt", "purchase_return_detail", "pur_ret_master_id = {$parent_key}"); $v_ch_pur_acc_id = getValue("code", "sys_codes", "description = 'PURCHASE RETURN'"); $v_cash_acc_id = getValue("code", "sys_codes", "description = 'CASH ACCOUNT'"); $v_party_acc_code = getValue("account_code", "party", "party_code = {$_POST['purchase_return_party_hidden']}"); require_once '../includes/connecti.php'; if ($_POST['purchase_return_type'] == 'C') { createVoucher($selected_company_id, $year_id, $v_cash_acc_id, $v_ch_pur_acc_id, $sum, $_POST['purchase_return_remarks'], $parent_key, 'PR', my_sql_date($_POST['purchase_return_date'])); } else { createVoucher($selected_company_id, $year_id, $v_ch_pur_acc_id, $v_party_acc_code, $sum, $_POST['purchase_return_remarks'], $parent_key, 'PR', my_sql_date($_POST['purchase_return_date'])); } $mysqli->close(); } $url = "../transaction/purchase_return.php?purchase_return_id={$parent_key}"; //echo "<a href='$url'>$url</a><br/>"; header("Location: {$url}");
$dr_acc = getValue("code", "sys_codes", "description = 'Purchase Return' AND company_ref_id = {$selected_company_id}", true); $cr_acc = getValue("code", "sys_codes", "description = 'Cash in Hand' AND company_ref_id = {$selected_company_id}", true); } else { //Credit Purchase Return //Debit - Party //Credit - Purchase Return $dr_acc = getValue("account_ref_id", "party", "party_code = {$_POST['purchase_return_party_hidden']}", true); $cr_acc = getValue("code", "sys_codes", "description = 'Purchase Return' AND company_ref_id = {$selected_company_id}", true); } if ($_POST['oper'] == 'update') { $voucher_id = getValue("voucher_id", "purchase_return_master", "pur_ret_master_id = {$parent_key}", true); d_mysql_query("UPDATE voucher_detail SET debit_amount = {$sum}, account_ref_id = {$dr_acc} WHERE voucher_id = {$voucher_id} AND remarks = 'Debit'"); d_mysql_query("UPDATE voucher_detail SET credit_amount = {$sum}, account_ref_id = {$cr_acc} WHERE voucher_id = {$voucher_id} AND remarks = 'Credit'"); d_mysql_query("UPDATE voucher_master SET voucher_date = '" . my_sql_date($_POST['purchase_return_date']) . "', voucher_remarks = '{$_POST['purchase_return_remarks']}' WHERE voucher_id = {$voucher_id}"); } else { createVoucher($selected_company_id, $year_id, $dr_acc, $cr_acc, $sum, $_POST['purchase_return_remarks'], $parent_key, 'PR', my_sql_date($_POST['purchase_return_date']), $_SESSION['user_id']); $mysqli->close(); } $voucher_id = getValue("voucher_id", "purchase_return_master", "pur_ret_master_id = {$parent_key}", true); d_mysql_query("UPDATE voucher_detail SET credit_amount = {$purchase} WHERE voucher_id = {$voucher_id} AND remarks = 'Credit'"); //reset all taxes d_mysql_query("UPDATE voucher_detail SET debit_amount = 0 WHERE voucher_id = {$voucher_id} AND remarks = 'Tax'"); if ($tax > 0) { $taxes = array(); $counter = $_POST['counter'] * 1; for ($i = 1; $i <= $counter; $i++) { $i_code = $_POST["item_" . $i . "_hidden"]; if (strlen($i_code) < 1) { continue; } $purchase_value = stripFormat($_POST["inp2_{$i}"]) * stripFormat($_POST["inp3_{$i}"]);
if (!isset($rows[$account_ref_id])) { $rows[$account_ref_id] = (double) 0; } $rows[$account_ref_id] += $row['amt'] * 1; } $totalExpenses = (double) 0; foreach ($rows as $account_ref_id => $amt) { $createVoucher = createVoucher($_GET['company'], $data['year'], $data['sl_code'], $account_ref_id, $amt, 'Account Closing Individual Exp', null, 'CO', date("Y-m-d"), $_SESSION['user_id']); //dump($createVoucher); $totalExpenses += $amt; } dump($totalExpenses); $sql = "" . "SELECT sum(vd.credit_amount - vd.debit_amount) amt\n" . " FROM voucher_detail vd\n" . " INNER JOIN voucher_master vm ON vm.voucher_id = vd.voucher_id\n" . " WHERE vd.account_ref_id = {$data['sl_code']}\n" . " AND vm.year_id = {$data['year']}"; $result = $mysqli->query($sql); if ($row = $result->fetch_assoc()) { $createVoucher = createVoucher($_GET['company'], $data['year'], $data['sl_code'], $data['re_code'], $row['amt'] * 1, 'Account Closing Retained Earning', null, 'CO', date("Y-m-d"), $_SESSION['user_id']); dump($createVoucher); } $sql = "DELETE FROM temp"; dump($sql); $result = mysql_query($sql); $data['r1'] = $result; $sql = "insert into temp(id)\n" . "SELECT vm.voucher_id\n" . " FROM voucher_master vm\n" . " INNER JOIN voucher_detail vd ON vd.voucher_id = vm.voucher_id\n" . " WHERE vm.company_ref_id = {$_GET['company']} AND vm.voucher_type <> 'CO' \n" . " AND vm.voucher_date >= (SELECT y.start_date FROM sys_financial_year y WHERE y.company_ref_id = vm.company_ref_id AND y.is_active = 'Yes')\n" . dump($sql); $result = mysql_query($sql); $data['r2'] = $result; $sql = "UPDATE voucher_master vm SET vm.year_id = {$data['year_id']} WHERE vm.voucher_id IN (SELECT t.id FROM temp t)"; dump($sql); $result = mysql_query($sql); $data['r6'] = $result; $sql = "" . "INSERT INTO account_opening_balance(account_ref_id, opening_balance, year_id)\n" . "SELECT x.account_ref_id, SUM(x.bal), {$data['year_id']}\n" . " FROM vu_account_open_bal x\n" . " WHERE x.company_ref_id = {$_GET['company']}\n" . " AND x.year_id = {$data['year']}\n" . "GROUP BY x.account_ref_id"; dump($sql);
$v_cr_sal_acc_id = getValue("code", "sys_codes", "description = 'CREDIT SALES'"); $v_party_acc_code = getValue("account_code", "party", "party_code = {$_POST['sales_party_hidden']}"); dd_mysql_query("UPDATE voucher_detail SET account_code = {$v_party_acc_code}, remarks = '2-1' WHERE voucher_id = {$voucher_id} AND debit_amount > 0"); dd_mysql_query("UPDATE voucher_detail SET account_code = {$v_cr_sal_acc_id}, remarks = '3-1' WHERE voucher_id = {$voucher_id} AND credit_amount > 0"); } dd_mysql_query("UPDATE voucher_master SET voucher_date = '" . my_sql_date($_POST['sales_date']) . "' WHERE voucher_id = {$voucher_id}"); } else { $v_ch_sale_acc_id = getValue("code", "sys_codes", "description = 'CASH SALES'"); $v_cash_acc_id = getValue("code", "sys_codes", "description = 'CASH ACCOUNT'"); $v_cr_sale_acc_id = getValue("code", "sys_codes", "description = 'CREDIT SALES'"); $v_party_acc_code = getValue("account_code", "party", "party_code = {$_POST['sales_party_hidden']}"); require_once '../includes/connecti.php'; if (isset($_POST['sales_type']) && $_POST['sales_type'] == 'C') { createVoucher($selected_company_id, $year_id, $v_cash_acc_id, $v_ch_sale_acc_id, $sum, $_POST['sales_remarks'], $parent_key, 'S', my_sql_date($_POST['sales_date'])); } else { createVoucher($selected_company_id, $year_id, $v_party_acc_code, $v_cr_sale_acc_id, $sum, $_POST['sales_remarks'], $parent_key, 'S', my_sql_date($_POST['sales_date'])); } $mysqli->close(); } $url .= "?sales_id={$parent_key}"; } echo "<a href='{$url}'>{$url}</a><br/>"; $json = new Services_JSON(); $output = $json->encode($data); print $output; $out = ob_get_contents(); ob_end_clean(); if (!isLive()) { $fp = fopen('sales_cud.htm', 'w'); fwrite($fp, "<html><head><title>SALES CUD</title></head><body>"); fwrite($fp, $out);
} } $finalcurd = $firstpart . $colval . $lastpart; if (strlen($finalcurd) > 0) { dumpFile($finalcurd, 'Final SQL', 'a'); $result = mysql_query($finalcurd); dumpFile($result, 'Final Result'); $error = mysql_error(); dumpFile($error, 'Final Error'); if ($table == 'cheque_post' && $_POST['cheque_status'] == 'Clear') { include_once 'connecti.php'; $master = $_POST['id']; if ($oper == 'add') { $master = mysql_insert_id(); } $voucher_id = getValue("voucher_id", "cheque_post", "cheque_post_id = {$master}"); if (strlen($voucher_id) > 0) { $db = "UPDATE voucher_detail SET debit_amount = {$_POST['cheque_amount']}, account_ref_id = {$_POST['bank_ref_id']} WHERE voucher_id = {$voucher_id} AND remarks = 'Debit'"; dumpFile($db, 'Debit', 'a'); mysql_query($db); $cr = "UPDATE voucher_detail SET credit_amount = {$_POST['cheque_amount']}, account_ref_id = {$_POST['party_ref_id']} WHERE voucher_id = {$voucher_id} AND remarks = 'Credit'"; dumpFile($cr, 'Credit', 'a'); mysql_query($cr); } else { $year_id = getValue("year_id", "sys_financial_year", "company_ref_id = {$_GET['comp']} AND is_active = 'Yes'"); $debug = createVoucher($_GET['comp'], $year_id, $_POST['bank_ref_id'], $_POST['party_ref_id'], $_POST['cheque_amount'], 'Cheque Cleared', $master, 'CQ', $_POST['cheque_date'], $_SESSION['user_id']); dumpFile($debug, 'Create Voucher', 'a'); } } } }
} if ($oper == 'add') { $data['seq'] = getSequenceNextVal('purchase_master', 3); $sql = "" . "INSERT INTO purchase_master(shipping_date,party_code,godown_code,p_remarks,receive_date,year_id,purchase_import,company_ref_id,seq,sale_master_id,is_cash,billno)\n" . "SELECT sm.sale_date, 634, 3, 'Purchased from MERAJ', sm.sale_date, {$year_id}, 'No', 3, {$data['seq']}, {$_GET['sales_master_id']}, sm.is_cash, billno FROM sales_master sm WHERE sm.sale_master_id = {$_GET['sales_master_id']}"; $mysqli->query($sql); $data['purchase_id'] = $mysqli->insert_id; $sql = "" . "INSERT INTO purchase_detail(i_code,ship_quantity,ship_rate,p_id,cost_rate)\n" . "SELECT (SELECT im.i_code FROM item_master im WHERE im.cno = (SELECT i.cno FROM item_master i WHERE i.i_code = sd.i_code AND i.company_ref_id = 1) AND im.company_ref_id = 3), sd.sales_qty, sd.sales_rate, {$data['purchase_id']}, 0 FROM sales_detail sd WHERE sd.sale_master_id = {$_GET['sales_master_id']}"; $mysqli->query($sql); $ship_date = getIVal("shipping_date", "purchase_master", "p_id = {$data['purchase_id']}", true); $purchase = getIVal("sum(ship_quantity * ship_rate) amt", "purchase_detail", "p_id = {$data['purchase_id']}", true); $sum = getIVal("sum((ship_quantity * ship_rate) - IFNULL(discount_rate, 0)) amt", "purchase_detail", "p_id = {$data['purchase_id']}", true); $dr_acc = getIVal("code", "sys_codes", "description = 'Credit Purchase' AND company_ref_id = 3", true); $cr_acc = getIVal("account_ref_id", "party", "party_code = 634", true); dump($purchase); dump($sum); $createVoucher = createVoucher(3, $year_id, $dr_acc, $cr_acc, $purchase, 'Purchased from MERAJ', $data['purchase_id'], 'P', $ship_date, $_SESSION['user_id']); dump($createVoucher); $voucher_id = getIVal("voucher_id", "purchase_master", "p_id = {$data['purchase_id']}", true); if ($sum == $purchase) { $mysqli->query("UPDATE voucher_detail SET debit_amount = 0 WHERE voucher_id = {$voucher_id} AND remarks = 'Discount'"); } /* start auditing on add, update, delete */ $voucher_aud_id = d_mysql_query("INSERT INTO voucher_master_aud SELECT NULL, vm.*, '{$oper}', {$_SESSION['user_id']}, now() FROM voucher_master vm WHERE vm.voucher_id = {$voucher_id}", true); d_mysql_query("INSERT INTO voucher_detail_aud SELECT NULL, vd.*, {$voucher_aud_id} FROM voucher_detail vd WHERE vd.voucher_id = {$voucher_id}"); $purchase_aud_id = d_mysql_query("INSERT INTO purchase_master_aud SELECT NULL, pm.*, {$voucher_aud_id}, '{$oper}', {$_SESSION['user_id']}, now() FROM purchase_master pm WHERE p_id = {$data['purchase_id']}", true); d_mysql_query("INSERT INTO purchase_detail_aud SELECT NULL, pd.*, {$purchase_aud_id} FROM purchase_detail pd WHERE pd.p_id = {$data['purchase_id']}"); /* end auditing on add, update, delete */ } else { if ($oper == 'update') { //do nothing in case of update }
$v_acc = $row['account_code']; $v_bal = $row['bal'] * 1; $v_dr = $v_cr = ""; if ($v_bal > 0) { $v_cr = $v_acc; $v_dr = $data['code']; } else { if ($v_bal < 0) { $v_cr = $data['code']; $v_dr = $v_acc; $v_bal *= -1; } else { continue; } } $createVoucher = createVoucher($_GET['company'], $_GET['year'], $v_dr, $v_cr, $v_bal, "Account Closing - {$row['account_code']}", null, 'CO', date("Y-m-d")); dump($createVoucher); } $sql = "" . "INSERT INTO account_opening_balance(account_code, opening_balance, year_id)\n" . "SELECT coa.account_code, sum(vd.debit_amount - vd.credit_amount), (SELECT y.year_id FROM sys_financial_year y WHERE y.is_active = 'Yes' AND y.company_ref_id = coa.company_ref_id)\n" . " FROM chart_of_account coa\n" . " INNER JOIN voucher_detail vd ON vd.account_code = coa.account_code\n" . " WHERE coa.company_ref_id = {$_GET['company']}\n" . " AND substring(coa.account_code, 1, 1) IN ('1', '2', '3')\n" . " AND coa.is_trans = 'Yes'\n" . "GROUP BY coa.account_code"; dump($sql); $result = mysql_query($sql); $data['r1'] = $result; $sql = "" . "INSERT INTO item_opening_balance(item_code, opening_balance, year_id, g_code, rate)\n" . "SELECT s.i_code, sum(s.rec_qty - s.iss_qty), (SELECT y.year_id FROM sys_financial_year y WHERE y.is_active = 'Yes' AND y.company_ref_id = s.company_ref_id), s.g_code, s.cost_rate\n" . " FROM vu_stock s\n" . " WHERE s.company_ref_id = {$_GET['company']}\n" . "GROUP BY s.i_code, s.g_code"; dump($sql); $result = mysql_query($sql); $data['r2'] = $result; $sql = "UPDATE sys_financial_year SET is_close = 'Yes' WHERE year_id = {$_GET['year']}"; dump($sql); $result = mysql_query($sql); $data['r3'] = $result; }
$sql = "account_code = '{$account_code}', cb_date = '{$cash_book_date}', cb_type = '{$cash_book_type}', cb_amount = '{$cash_book_ammount}', cb_remarks = '{$remarks}'"; if (strlen($cash_book_id) > 0) { $sql = " UPDATE cash_book SET {$sql} WHERE cb_id = {$cash_book_id}"; } else { $sql = " INSERT INTO cash_book SET company_ref_id = {$selected_company_id}, year_id = {$year_id}, {$sql}"; } $result = mysql_query($sql) or die("Couldn t execute query." . mysql_error()); $parent_key = -1; if (strlen($cash_book_id) > 0) { $parent_key = $cash_book_id; } else { $parent_key = mysql_insert_id(); } if (strlen($cash_book_id) > 0) { $voucher_id = getValue("voucher_id", "voucher_detail", "voucher_id = (SELECT voucher_id FROM cash_book WHERE cb_id = {$cash_book_id})"); dd_mysql_query("DELETE FROM voucher_detail WHERE voucher_id = {$voucher_id}"); dd_mysql_query("DELETE FROM voucher_master WHERE voucher_id = {$voucher_id}"); } $v_cash_acc_id = getValue("code", "sys_codes", "description = 'CASH ACCOUNT'"); if ($cash_book_type == 'R') { createVoucher($selected_company_id, $year_id, $v_cash_acc_id, $account_code, $cash_book_ammount, $remarks, $parent_key, 'CR', $cash_book_date); } else { createVoucher($selected_company_id, $year_id, $account_code, $v_cash_acc_id, $cash_book_ammount, $remarks, $parent_key, 'CR', $cash_book_date); } } } } $mysqli->close(); $url = "../transaction/cash_book.php?cash_date=" . locale_date($cash_book_date); //echo "<a href='$url'>$url</a><br/>"; header("Location: {$url}");
//Credit Purchase //Debit - Credit Purchase //Credit - Party $dr_acc = getValue("code", "sys_codes", "description = 'Credit Purchase' AND company_ref_id = {$selected_company_id}", true); $cr_acc = getValue("account_ref_id", "party", "party_code = {$_POST['purchase_supplier_hidden']}", true); } $voucherDate = my_sql_date($_POST['purchase_shipping_date']); if ($_POST['oper'] == 'update') { $voucher_id = getValue("voucher_id", "purchase_master", "p_id = {$_POST['purchase_id']}", true); if (strlen($voucher_id) > 0) { d_mysql_query("UPDATE voucher_detail SET debit_amount = {$purchase}, account_ref_id = {$dr_acc} WHERE voucher_id = {$voucher_id} AND remarks = 'Debit'"); d_mysql_query("UPDATE voucher_detail SET credit_amount = {$purchase}, account_ref_id = {$cr_acc} WHERE voucher_id = {$voucher_id} AND remarks = 'Credit'"); d_mysql_query("UPDATE voucher_master SET voucher_date = '{$voucherDate}', voucher_remarks = '{$_POST['purchase_remarks']}' WHERE voucher_id = {$voucher_id}"); } } else { $createVoucher = createVoucher($selected_company_id, $year_id, $dr_acc, $cr_acc, $purchase, $_POST['purchase_remarks'], $parent_key, 'P', $voucherDate, $_SESSION['user_id']); dump($createVoucher); } $voucher_id = getValue("voucher_id", "purchase_master", "p_id = {$parent_key}", true); d_mysql_query("UPDATE voucher_detail SET credit_amount = {$sum} WHERE voucher_id = {$voucher_id} AND remarks = 'Credit'"); d_mysql_query("UPDATE voucher_detail SET credit_amount = {$discount} WHERE voucher_id = {$voucher_id} AND remarks = 'Discount'"); //reset all taxes d_mysql_query("UPDATE voucher_detail SET debit_amount = 0 WHERE voucher_id = {$voucher_id} AND remarks = 'Tax'"); if ($tax > 0) { $taxes = array(); $counter = $_POST['counter'] * 1; for ($i = 1; $i <= $counter; $i++) { $i_code = $_POST["item_" . $i . "_hidden"]; if (strlen($i_code) < 1) { continue; }