*** empty log message ***
[fa-stable.git] / gl / inquiry / tax_inquiry.php
1 <?php
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 ***********************************************************************/
12 $page_security = 8;
13 $path_to_root="../..";
14 include_once($path_to_root . "/includes/session.inc");
15
16
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");
20
21 include_once($path_to_root . "/gl/includes/gl_db.inc");
22
23 $js = '';
24 set_focus('account');
25 if ($use_popup_windows)
26         $js .= get_js_open_window(800, 500);
27 if ($use_date_picker)
28         $js .= get_js_date_picker();
29
30 page(_("Tax Inquiry"), false, false, '', $js);
31
32 //----------------------------------------------------------------------------------------------------
33 // Ajax updates
34 //
35 if (get_post('Show')) 
36 {
37         $Ajax->activate('trans_tbl');
38 }
39
40 if (get_post('TransFromDate') == "" && get_post('TransToDate') == "")
41 {
42         $date = Today();
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;
49 }       
50
51 //----------------------------------------------------------------------------------------------------
52
53 function get_tax_types()
54 {
55         $sql = "SELECT * FROM ".TB_PREF."tax_types ORDER BY id";
56     return db_query($sql,"No transactions were returned");
57 }
58
59 function tax_inquiry_controls()
60 {
61         global $table_style2;
62
63     start_form();
64
65     //start_table($table_style2);
66     start_table("class='tablestyle_noborder'");
67         start_row();
68
69         date_cells(_("from:"), 'TransFromDate', '', null, -30);
70         date_cells(_("to:"), 'TransToDate');
71         submit_cells('Show',_("Show"),'','', true);
72
73     end_row();
74
75         end_table();
76
77     end_form();
78 }
79
80 //----------------------------------------------------------------------------------------------------
81
82 function show_results()
83 {
84         global $path_to_root, $table_style;
85
86     /*Now get the transactions  */
87         div_start('trans_tbl');
88         start_table($table_style);
89
90         $th = array(_("Type"), _("Description"), _("Amount"), _("Outputs")."/"._("Inputs"));
91         table_header($th);
92         $k = 0;
93         $total = 0;
94         $bdate = date2sql($_POST['TransFromDate']);
95         $edate  = date2sql($_POST['TransToDate']);
96
97         $taxes = get_tax_summary($_POST['TransFromDate'], $_POST['TransToDate']);
98
99         while ($tx = db_fetch($taxes))
100         {
101
102                 $payable = $tx['payable'];
103                 $collectible = $tx['collectible'];
104                 $net = $collectible + $payable;
105                 $total += $net;
106                 alt_table_row_color($k);
107                 label_cell($tx['name'] . " " . $tx['rate'] . "%");
108                 label_cell(_("Charged on sales") . " (" . _("Output Tax")."):");
109                 amount_cell($payable);
110                 amount_cell($tx['net_output']);
111                 end_row();
112                 alt_table_row_color($k);
113                 label_cell($tx['name'] . " " . $tx['rate'] . "%");
114                 label_cell(_("Paid on purchases") . " (" . _("Input Tax")."):");
115                 amount_cell($collectible);
116                 amount_cell($tx['net_input']);
117                 end_row();
118                 alt_table_row_color($k);
119                 label_cell("<b>".$tx['name'] . " " . $tx['rate'] . "%</b>");
120                 label_cell("<b>"._("Net payable or collectible") . ":</b>");
121                 amount_cell($net, true);
122                 end_row();
123         }       
124         alt_table_row_color($k);
125         label_cell("");
126         label_cell("<b>"._("Total payable or refund") . ":</b>");
127         amount_cell($total, true);
128         end_row();
129
130         end_table(2);
131         div_end();
132 }
133
134 //----------------------------------------------------------------------------------------------------
135
136 tax_inquiry_controls();
137
138 show_results();
139
140 //----------------------------------------------------------------------------------------------------
141
142 end_page();
143
144 ?>