<?php
/**********************************************************************
    Copyright (C) FrontAccounting, LLC.
	Released under the terms of the GNU General Public License, GPL, 
	as published by the Free Software Foundation, either version 3 
	of the License, or (at your option) any later version.
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
    See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
***********************************************************************/
$page_security = 'SA_GLANALYTIC';

$path_to_root = "../..";
include_once($path_to_root . "/includes/session.inc");
include_once($path_to_root . "/includes/ui.inc");
include_once($path_to_root . "/gl/includes/ui/profit_loss_details.inc"); 
include_once($path_to_root . "/gl/includes/gl_db.inc");
include_once($path_to_root . "/admin/db/fiscalyears_db.inc");

$js = "";
$js .= get_js_open_window(900, 500);
$js .= get_js_date_picker();

page(_($help_context = "Profit & Loss View"), false, false, "", $js);

$compare_types = array(
	_("Accumulated"),
	_("Period Y-1"),
	_("Budget")
);

if (get_post('Show')) 
{
	$Ajax->activate('pl_tbl');
}

start_form();

    display_profit_loss_details_selecting_parameters();
    
    div_start('pft_los_details');
    
    $fy_row = get_fiscalyear_record_by_from_date_to_date($_POST['from_date'], $_POST['to_date']);
        if (! is_array($fy_row)) {
            $Ajax->activate('pft_los_details');
            
            display_note('Both dates should be within one financial year.', 1, 1);
        } else {
            $fina_yer_begin_ = sql2date($fy_row['begin']); 
            $fina_yer_end_ = sql2date($fy_row['end']);
            
            display_profit_and_loss_details($_POST['from_date'], $_POST['to_date'], $fina_yer_begin_, $fina_yer_end_);
        }

    div_end();

end_form(2);

end_page();

?>