5 include_once($path_to_root . "/includes/session.inc");
8 include_once($path_to_root . "/includes/date_functions.inc");
9 include_once($path_to_root . "/includes/ui.inc");
10 include_once($path_to_root . "/includes/data_checks.inc");
12 include_once($path_to_root . "/gl/includes/gl_db.inc");
16 if ($use_popup_windows)
17 $js .= get_js_open_window(800, 500);
19 $js .= get_js_date_picker();
21 page(_("Tax Inquiry"), false, false, '', $js);
23 //----------------------------------------------------------------------------------------------------
28 $Ajax->activate('trans_tbl');
31 if (get_post('TransFromDate') == "" && get_post('TransToDate') == "")
34 $row = get_company_prefs();
35 $edate = add_months($date, -$row['tax_last']);
36 $edate = end_month($edate);
37 $bdate = add_months($edate, -$row['tax_prd'] + 1);
38 $_POST["TransFromDate"] = begin_month($bdate);
39 $_POST["TransToDate"] = $edate;
42 //----------------------------------------------------------------------------------------------------
44 function get_tax_types()
46 $sql = "SELECT * FROM ".TB_PREF."tax_types ORDER BY id";
47 return db_query($sql,"No transactions were returned");
50 function tax_inquiry_controls()
56 //start_table($table_style2);
57 start_table("class='tablestyle_noborder'");
60 date_cells(_("from:"), 'TransFromDate', '', null, -30);
61 date_cells(_("to:"), 'TransToDate');
62 submit_cells('Show',_("Show"),'','', true);
71 //----------------------------------------------------------------------------------------------------
73 function show_results()
75 global $path_to_root, $table_style;
77 $taxes = get_tax_types();
79 /*Now get the transactions */
80 div_start('trans_tbl');
81 start_table($table_style);
83 $th = array(_("Type"), _("Description"), _("Amount"));
87 $bdate = date2sql($_POST['TransFromDate']);
88 $edate = date2sql($_POST['TransToDate']);
89 while ($tx = db_fetch($taxes))
91 if ($tx['sales_gl_code'] == $tx['purchasing_gl_code'])
93 $sql = "SELECT SUM(IF(amount >= 0, amount, 0)) AS payable, SUM(IF(amount < 0, -amount, 0)) AS collectible
94 FROM ".TB_PREF."gl_trans WHERE account = '".$tx['sales_gl_code']."' AND tran_date >= '$bdate' AND tran_date <= '$edate'";
95 $result = db_query($sql, "Error retrieving tax inquiry");
96 $row = db_fetch($result);
97 $payable = -$row['payable'];
98 $collectible.= -$row['collectible'];
102 $sql = "SELECT SUM(amount) AS collectible
103 FROM ".TB_PREF."gl_trans WHERE account = '".$tx['sales_gl_code']."' AND tran_date >= '$bdate' AND tran_date <= '$edate'";
104 $result = db_query($sql, "Error retrieving tax inquiry");
105 $row = db_fetch($result);
106 $collectible = -$row['collectible'];
107 $sql = "SELECT SUM(amount) AS payable
108 FROM ".TB_PREF."gl_trans WHERE account = '".$tx['purchasing_gl_code']."' AND tran_date >= '$bdate' AND tran_date <= '$edate'";
109 $result = db_query($sql, "Error retrieving tax inquiry");
110 $row = db_fetch($result);
111 $payable = -$row['payable'];
113 $net = $collectible + $payable;
115 alt_table_row_color($k);
116 label_cell($tx['name'] . " " . $tx['rate'] . "%");
117 label_cell(_("Charged on sales") . " (" . _("Output Tax")."):");
118 amount_cell($collectible);
120 alt_table_row_color($k);
121 label_cell($tx['name'] . " " . $tx['rate'] . "%");
122 label_cell(_("Paid on purchases") . " (" . _("Input Tax")."):");
123 amount_cell($payable);
125 alt_table_row_color($k);
126 label_cell($tx['name'] . " " . $tx['rate'] . "%");
127 label_cell(_("Net payable or collectible") . ":");
128 amount_cell($net, true);
131 alt_table_row_color($k);
133 label_cell("<b>"._("Total payable or refund") . ":</b>");
134 amount_cell($total, true);
141 //----------------------------------------------------------------------------------------------------
143 tax_inquiry_controls();
147 //----------------------------------------------------------------------------------------------------