Added Tax Inquiry in Banking and General Ledger tab.
authorJoe Hunt <joe.hunt.consulting@gmail.com>
Sat, 15 Nov 2008 00:53:38 +0000 (00:53 +0000)
committerJoe Hunt <joe.hunt.consulting@gmail.com>
Sat, 15 Nov 2008 00:53:38 +0000 (00:53 +0000)
CHANGELOG.txt
applications/generalledger.php
gl/inquiry/tax_inquiry.php [new file with mode: 0644]

index a60246b81747e78ba20a0e43be6fec9218889fc4..b1ac91c32c775727d8d24f81e9fb9eb0c565e63f 100644 (file)
@@ -19,6 +19,11 @@ Legend:
 ! -> Note
 $ -> Affected files
 
+15-Nov-2008 Joe Hunt
++ Added Tax Inquiry in Banking and General Ledger tab.
+$ /applications/generalledger.php
+  /gl/inquiry/tax_inquiry.php (new file)
+  
 14-Nov-2008 Joe Hunt
 + Added Sales Groups and Recurrent Invoices.
 $ /applications/customers.php
index 9b02b2a5bbb57fe84323a519c08f0e74a6ba0e42..6e3c48ca96f7be9cf7fa84894421a97ffe60a1c2 100644 (file)
@@ -18,8 +18,8 @@
                        $this->add_module(_("Inquiries and Reports"));
                        $this->add_lapp_function(1, _("Bank Account &Inquiry"),"gl/inquiry/bank_inquiry.php?");
                        $this->add_lapp_function(1, _("GL Account &Inquiry"),"gl/inquiry/gl_account_inquiry.php?");
-                       $this->add_lapp_function(1, "","");
                        $this->add_lapp_function(1, _("Trial &Balance"),"gl/inquiry/gl_trial_balance.php?");
+                       $this->add_lapp_function(1, _("Ta&x Inquiry"),"gl/inquiry/tax_inquiry.php?");
 
                        $this->add_rapp_function(1, _("Banking &Reports"),"reporting/reports_main.php?Class=5");
                        $this->add_rapp_function(1, _("General Ledger &Reports"),"reporting/reports_main.php?Class=6");
diff --git a/gl/inquiry/tax_inquiry.php b/gl/inquiry/tax_inquiry.php
new file mode 100644 (file)
index 0000000..1de4896
--- /dev/null
@@ -0,0 +1,151 @@
+<?php
+
+$page_security = 8;
+$path_to_root="../..";
+include_once($path_to_root . "/includes/session.inc");
+
+
+include_once($path_to_root . "/includes/date_functions.inc");
+include_once($path_to_root . "/includes/ui.inc");
+include_once($path_to_root . "/includes/data_checks.inc");
+
+include_once($path_to_root . "/gl/includes/gl_db.inc");
+
+$js = '';
+set_focus('account');
+if ($use_popup_windows)
+       $js .= get_js_open_window(800, 500);
+if ($use_date_picker)
+       $js .= get_js_date_picker();
+
+page(_("Tax Inquiry"), false, false, '', $js);
+
+//----------------------------------------------------------------------------------------------------
+// Ajax updates
+//
+if (get_post('Show')) 
+{
+       $Ajax->activate('trans_tbl');
+}
+
+if (get_post('TransFromDate') == "" && get_post('TransToDate') == "")
+{
+       $date = Today();
+       $row = get_company_prefs();
+       $edate = add_months($date, -$row['tax_last']);
+       $edate = end_month($edate);
+       $bdate = add_months($edate, -$row['tax_prd'] + 1);
+       $_POST["TransFromDate"] = begin_month($bdate);
+       $_POST["TransToDate"] = $edate;
+}      
+
+//----------------------------------------------------------------------------------------------------
+
+function get_tax_types()
+{
+       $sql = "SELECT * FROM ".TB_PREF."tax_types ORDER BY id";
+    return db_query($sql,"No transactions were returned");
+}
+
+function tax_inquiry_controls()
+{
+       global $table_style2;
+
+    start_form();
+
+    //start_table($table_style2);
+    start_table("class='tablestyle_noborder'");
+       start_row();
+
+       date_cells(_("from:"), 'TransFromDate', '', null, -30);
+       date_cells(_("to:"), 'TransToDate');
+       submit_cells('Show',_("Show"),'','', true);
+
+    end_row();
+
+       end_table();
+
+    end_form();
+}
+
+//----------------------------------------------------------------------------------------------------
+
+function show_results()
+{
+       global $path_to_root, $table_style;
+
+       $taxes = get_tax_types();
+
+    /*Now get the transactions  */
+       div_start('trans_tbl');
+       start_table($table_style);
+
+       $th = array(_("Type"), _("Description"), _("Amount"));
+       table_header($th);
+       $k = 0;
+       $total = 0;
+       $bdate = date2sql($_POST['TransFromDate']);
+       $edate  = date2sql($_POST['TransToDate']);
+       while ($tx = db_fetch($taxes))
+       {
+               if ($tx['sales_gl_code'] == $tx['purchasing_gl_code'])
+               {
+                       $sql = "SELECT SUM(IF(amount >= 0, amount, 0)) AS payable, SUM(IF(amount < 0, -amount, 0)) AS collectible
+                               FROM ".TB_PREF."gl_trans WHERE account = '".$tx['sales_gl_code']."' AND tran_date >= '$bdate' AND tran_date <= '$edate'";
+                       $result = db_query($sql, "Error retrieving tax inquiry");
+                       $row = db_fetch($result);
+                       $payable = -$row['payable'];
+                       $collectible.= -$row['collectible'];
+               }
+               else
+               {
+                       $sql = "SELECT SUM(amount) AS collectible
+                               FROM ".TB_PREF."gl_trans WHERE account = '".$tx['sales_gl_code']."' AND tran_date >= '$bdate' AND tran_date <= '$edate'";
+                       $result = db_query($sql, "Error retrieving tax inquiry");
+                       $row = db_fetch($result);
+                       $collectible = -$row['collectible'];
+                       $sql = "SELECT SUM(amount) AS payable
+                               FROM ".TB_PREF."gl_trans WHERE account = '".$tx['purchasing_gl_code']."' AND tran_date >= '$bdate' AND tran_date <= '$edate'";
+                       $result = db_query($sql, "Error retrieving tax inquiry");
+                       $row = db_fetch($result);
+                       $payable = -$row['payable'];
+               }
+               $net = $collectible + $payable;
+               $total += $net;
+               alt_table_row_color($k);
+               label_cell($tx['name'] . " " . $tx['rate'] . "%");
+               label_cell(_("Charged on sales") . " (" . _("Output Tax")."):");
+               amount_cell($collectible);
+               end_row();
+               alt_table_row_color($k);
+               label_cell($tx['name'] . " " . $tx['rate'] . "%");
+               label_cell(_("Paid on purchases") . " (" . _("Input Tax")."):");
+               amount_cell($payable);
+               end_row();
+               alt_table_row_color($k);
+               label_cell($tx['name'] . " " . $tx['rate'] . "%");
+               label_cell(_("Net payable or collectible") . ":");
+               amount_cell($net, true);
+               end_row();
+       }       
+       alt_table_row_color($k);
+       label_cell("");
+       label_cell("<b>"._("Total payable or refund") . ":</b>");
+       amount_cell($total, true);
+       end_row();
+
+       end_table(2);
+       div_end();
+}
+
+//----------------------------------------------------------------------------------------------------
+
+tax_inquiry_controls();
+
+show_results();
+
+//----------------------------------------------------------------------------------------------------
+
+end_page();
+
+?>