2 /**********************************************************************
3 Copyright (C) FrontAccounting, LLC.
4 Released under the terms of the GNU Affero General Public License,
5 AGPL, as published by the Free Software Foundation, either version
6 3 of the License, or (at your option) any later version.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License here <http://www.gnu.org/licenses/agpl-3.0.html>.
11 ***********************************************************************/
13 $path_to_root="../..";
14 include_once($path_to_root . "/includes/session.inc");
17 include_once($path_to_root . "/includes/date_functions.inc");
18 include_once($path_to_root . "/includes/ui.inc");
19 include_once($path_to_root . "/includes/data_checks.inc");
21 include_once($path_to_root . "/gl/includes/gl_db.inc");
25 if ($use_popup_windows)
26 $js .= get_js_open_window(800, 500);
28 $js .= get_js_date_picker();
30 page(_("Tax Inquiry"), false, false, '', $js);
32 //----------------------------------------------------------------------------------------------------
37 $Ajax->activate('trans_tbl');
40 if (get_post('TransFromDate') == "" && get_post('TransToDate') == "")
43 $row = get_company_prefs();
44 $edate = add_months($date, -$row['tax_last']);
45 $edate = end_month($edate);
46 $bdate = add_months($edate, -$row['tax_prd'] + 1);
47 $_POST["TransFromDate"] = begin_month($bdate);
48 $_POST["TransToDate"] = $edate;
51 //----------------------------------------------------------------------------------------------------
53 function get_tax_types()
55 $sql = "SELECT * FROM ".TB_PREF."tax_types ORDER BY id";
56 return db_query($sql,"No transactions were returned");
59 function tax_inquiry_controls()
65 //start_table($table_style2);
66 start_table("class='tablestyle_noborder'");
69 date_cells(_("from:"), 'TransFromDate', '', null, -30);
70 date_cells(_("to:"), 'TransToDate');
71 submit_cells('Show',_("Show"),'','', true);
80 //----------------------------------------------------------------------------------------------------
82 function show_results()
84 global $path_to_root, $table_style;
86 $taxes = get_tax_types();
88 /*Now get the transactions */
89 div_start('trans_tbl');
90 start_table($table_style);
92 $th = array(_("Type"), _("Description"), _("Amount"));
96 $bdate = date2sql($_POST['TransFromDate']);
97 $edate = date2sql($_POST['TransToDate']);
98 while ($tx = db_fetch($taxes))
100 if ($tx['sales_gl_code'] == $tx['purchasing_gl_code'])
102 $sql = "SELECT SUM(IF(amount >= 0, amount, 0)) AS payable, SUM(IF(amount < 0, -amount, 0)) 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 $payable = -$row['payable'];
107 $collectible.= -$row['collectible'];
111 $sql = "SELECT SUM(amount) AS collectible
112 FROM ".TB_PREF."gl_trans WHERE account = '".$tx['sales_gl_code']."' AND tran_date >= '$bdate' AND tran_date <= '$edate'";
113 $result = db_query($sql, "Error retrieving tax inquiry");
114 $row = db_fetch($result);
115 $collectible = -$row['collectible'];
116 $sql = "SELECT SUM(amount) AS payable
117 FROM ".TB_PREF."gl_trans WHERE account = '".$tx['purchasing_gl_code']."' AND tran_date >= '$bdate' AND tran_date <= '$edate'";
118 $result = db_query($sql, "Error retrieving tax inquiry");
119 $row = db_fetch($result);
120 $payable = -$row['payable'];
122 $net = $collectible + $payable;
124 alt_table_row_color($k);
125 label_cell($tx['name'] . " " . $tx['rate'] . "%");
126 label_cell(_("Charged on sales") . " (" . _("Output Tax")."):");
127 amount_cell($collectible);
129 alt_table_row_color($k);
130 label_cell($tx['name'] . " " . $tx['rate'] . "%");
131 label_cell(_("Paid on purchases") . " (" . _("Input Tax")."):");
132 amount_cell($payable);
134 alt_table_row_color($k);
135 label_cell("<b>".$tx['name'] . " " . $tx['rate'] . "%</b>");
136 label_cell("<b>"._("Net payable or collectible") . ":</b>");
137 amount_cell($net, true);
140 alt_table_row_color($k);
142 label_cell("<b>"._("Total payable or refund") . ":</b>");
143 amount_cell($total, true);
150 //----------------------------------------------------------------------------------------------------
152 tax_inquiry_controls();
156 //----------------------------------------------------------------------------------------------------