Fixed delivery note's invoice deadline date description
[fa-stable.git] / gl / inquiry / gl_trial_balance.php
index 6bf807cd83416d131df584c1c31a188ad6435bca..c0a3e56ab1c15108466eb271e9c8250a5bf252eb 100644 (file)
@@ -9,13 +9,14 @@
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
     See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
 ***********************************************************************/
-$page_security = 8;
+$page_security = 'SA_GLANALYTIC';
 $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/date_functions.inc");
+include_once($path_to_root . "/admin/db/fiscalyears_db.inc");
 include_once($path_to_root . "/includes/data_checks.inc");
 
 include_once($path_to_root . "/gl/includes/gl_db.inc");
@@ -24,7 +25,7 @@ $js = "";
 if ($use_date_picker)
        $js = get_js_date_picker();
 
-page(_("Trial Balance"), false, false, "", $js);
+page(_($help_context = "Trial Balance"), false, false, "", $js);
 
 //----------------------------------------------------------------------------------------------------
 // Ajax updates
@@ -37,16 +38,21 @@ if (get_post('Show'))
 
 function gl_inquiry_controls()
 {
+       $dim = get_company_pref('use_dimension');
     start_form();
 
-    start_table("class='tablestyle_noborder'");
+    start_table(TABLESTYLE_NOBORDER);
 
     date_cells(_("From:"), 'TransFromDate', '', null, -30);
        date_cells(_("To:"), 'TransToDate');
+       if ($dim >= 1)
+               dimensions_list_cells(_("Dimension")." 1:", 'Dimension', null, true, " ", false, 1);
+       if ($dim > 1)
+               dimensions_list_cells(_("Dimension")." 2:", 'Dimension2', null, true, " ", false, 2);
        check_cells(_("No zero values"), 'NoZero', null);
        check_cells(_("Only balances"), 'Balance', null);
 
-       submit_cells('Show',_("Show"),'','', true);
+       submit_cells('Show',_("Show"),'','', 'default');
     end_table();
     end_form();
 }
@@ -55,10 +61,24 @@ function gl_inquiry_controls()
 
 function display_trial_balance()
 {
-       global $table_style, $path_to_root;
+       global $path_to_root;
 
+       if (isset($_POST['TransFromDate']))
+       {
+               $row = get_current_fiscalyear();
+               if (date1_greater_date2($_POST['TransFromDate'], sql2date($row['end'])))
+               {
+                       display_error(_("The from date cannot be bigger than the fiscal year end."));
+                       set_focus('TransFromDate');
+                       return;
+               }       
+       }       
        div_start('balance_tbl');
-       start_table($table_style);
+       if (!isset($_POST['Dimension']))
+               $_POST['Dimension'] = 0;
+       if (!isset($_POST['Dimension2']))
+               $_POST['Dimension2'] = 0;
+       start_table(TABLESTYLE);
        $tableheader =  "<tr>
         <td rowspan=2 class='tableheader'>" . _("Account") . "</td>
         <td rowspan=2 class='tableheader'>" . _("Account Name") . "</td>
@@ -87,14 +107,14 @@ function display_trial_balance()
        
        while ($account = db_fetch($accounts))
        {
-               $prev = get_balance($account["account_code"], 0, 0, $begin, $_POST['TransFromDate'], false, false);
-               $curr = get_balance($account["account_code"], 0, 0, $_POST['TransFromDate'], $_POST['TransToDate'], true, true);
-               $tot = get_balance($account["account_code"], 0, 0, $begin, $_POST['TransToDate'], false, true);
+               $prev = get_balance($account["account_code"], $_POST['Dimension'], $_POST['Dimension2'], $begin, $_POST['TransFromDate'], false, false);
+               $curr = get_balance($account["account_code"], $_POST['Dimension'], $_POST['Dimension2'], $_POST['TransFromDate'], $_POST['TransToDate'], true, true);
+               $tot = get_balance($account["account_code"], $_POST['Dimension'], $_POST['Dimension2'], $begin, $_POST['TransToDate'], false, true);
                if (check_value("NoZero") && !$prev['balance'] && !$curr['balance'] && !$tot['balance'])
                        continue;
                alt_table_row_color($k);
 
-               $url = "<a href='$path_to_root/gl/inquiry/gl_account_inquiry.php?" . SID . "TransFromDate=" . $_POST["TransFromDate"] . "&TransToDate=" . $_POST["TransToDate"] . "&account=" . $account["account_code"] . "'>" . $account["account_code"] . "</a>";
+               $url = "<a href='$path_to_root/gl/inquiry/gl_account_inquiry.php?TransFromDate=" . $_POST["TransFromDate"] . "&TransToDate=" . $_POST["TransToDate"] . "&account=" . $account["account_code"] . "&Dimension=" . $_POST["Dimension"] . "&Dimension2=" . $_POST["Dimension2"] . "'>" . $account["account_code"] . "</a>";
 
                label_cell($url);
                label_cell($account["account_name"]);
@@ -149,6 +169,8 @@ function display_trial_balance()
        end_row();
 
        end_table(1);
+       if (($pbal = round2($pbal, user_price_dec()))  != 0)
+               display_warning(_("The Opening Balance is not in balance, probably due to a non closed Previous Fiscalyear."));
        div_end();
 }