<?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_GOODS_RETURN_FORM';
$path_to_root = "../../..";
include($path_to_root . "/includes/session.inc");
add_access_extensions();
page(_($help_context = "Print Goods Return Form"));

include($path_to_root . "/includes/ui.inc");
include($path_to_root . "/modules/diligent/includes/form_db.inc");
include_once($path_to_root . "/reporting/includes/reporting.inc");

simple_page_mode(true);
//------------------------------------------------------------------------------------------------

if ($Mode == 'ADD_ITEM' ) {
    //initialise no input errors assumed initially before we test
    $input_error = 0;

    if (strlen($_POST['facilitated_by']) == 0) {
        $input_error = 1;
        display_error(_("Please select The Facilitator"));
        set_focus('facilitated_by');
    }
    if (strlen($_POST['requested_by']) == 0) {
        $input_error = 1;
        display_error(_("Please fill requested by field"));
        set_focus('requested_by');
    }
    if (strlen($_POST['person_id']) == 0) {
        $input_error = 1;
        display_error(_("Please select Customer"));
        set_focus('person_id');
    }
    
    if ($input_error != 1) {
        add_form($_POST['facilitated_by'], $_POST['requested_by'], $_POST['person_id'],
                $_POST['description'],'GOODS_RETURN_FORM',ST_CUSTOMER,$_SESSION["wa_current_user"]->user);
        $form_id = db_insert_id();

        $def_orientation = (user_def_print_orientation() == 1 ? 1 : 0);
        $ar = array(
                    'PARAM_0' => $form_id,
                    'PARAM_1' => $def_orientation, 
                    'PARAM_2' => 0);
        
        display_notification(_('Goods Return From Created SucessFully'));
        display_notification_centered(print_link(_("Print This Form"), '_goods_return_form', $ar, "", false, 'printlink', 'PrintGoodsReturnForm'));
        $Mode = 'RESET';
    }
}

//------------------------------------------------------------------------------------------------
if ($Mode == 'RESET') {
    unset($_POST);
}

start_form();

start_table(TABLESTYLE2);
$sql = "SELECT id, user_id FROM " . TB_PREF . "users";
label_row("Facilitated By", combo_input("facilitated_by", '', $sql, 'id', 'user_id', array('spec_option' => _("Select User"), 'spec_id' => ALL_NUMERIC)));
text_row_ex(_("Requested By:"), 'requested_by', 50);
customer_list_row(_("Select Customer"), "person_id", null, "Select Customer", false);
textarea_row(_("Comments:"), "description", null, 20, 5);
end_table(1);

submit_add_or_update_center(true, '', 'both');

end_form();

end_page();

