<?php
$page_security = 'SA_RECEIVE_PETTY_CASH_ITEMS';
$path_to_root = "../..";

include_once($path_to_root . "/includes/session.inc");
include_once($path_to_root . "/includes/ui/ui_input.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 . "/petty_cash/includes/db/i_owe_you_expenses_db.inc");
include_once($path_to_root . "/inventory/includes/petty_cash_item_receive_ui.inc");
include_once($path_to_root . "/inventory/includes/db/petty_cash_item_receive_db.inc");

include_once($path_to_root . "/includes/project_cost_functions.inc"); 
//include_once($path_to_root . "/includes/project_cost_functions.inc");



$js = "";
if ($SysPrefs->use_popup_windows)
    $js .= get_js_open_window(900, 500);
if (user_use_date_picker())
    $js .= get_js_date_picker();

simple_page_mode(true);

$help_context = "Receive Petty Cash Stock Items";
page(_($help_context), true, false, false, $js);



global $selected_id, $Ajax;

$boq_item_id = 0;
$detail_type_code = '';
$primary_type = 0;

if (isset($_GET["strn_no"]))
{
	$_POST["strn_no"] = $_GET["strn_no"];
}


if (isset($_GET["stype"]))
{
	$_POST["stype"] = $_GET["stype"];
}

if (isset($_GET["sd_id"]))
{
	$_POST["sd_id"] = $_GET["sd_id"];
}

switch ($_POST["stype"]) {
    case ST_I_OWE_YOU_BATCH:
        $type = ST_PETTY_CASH_ITEM_RECEIPT;
        break;

    default:
        break;
}

if(isset($_POST['PROCESS_ALL_ITEMS']) && $selected_id < 0)
{
    handle_process_petty_cash_item_receive($_POST["stype"], $_POST["strn_no"], $_POST["sd_id"], $type);
}

if(isset($_POST['ADD_BOQ_ITEM_MATERIAL']) && $selected_id < 0)
{
    handle_new_petty_cash_item_receive($selected_id, $type);
}

if(isset($_POST['UPDATE_BOQ_ITEM_MATERIAL']) && $selected_id > 0)
{
    handle_update_petty_cash_item_receive($selected_id);
}

$delete_petty_cash_item_id  = find_submit("Delete_petty_cash_item");
if ($delete_petty_cash_item_id > 0)
{
    handle_delete_petty_cash_stock_item($selected_id, $delete_petty_cash_item_id);
	
}

if(isset($_POST['Cancel_Edit']))
{
    clear_boq_item_material_data();
//    $Mode = 'RESET';
    $selected_id = -1;
}

$Ajax->Activate('detail_type_code'); 
$Ajax->Activate('primary_type');


start_form();

//
//hidden('trans_no', $boq_item_id);
//hidden('dtype', $detail_type_code);
//hidden('ptype', $primary_type);


start_table(TABLESTYLE, "width=40%");
//$th = array(_("Lot Reference"), _("Available Qty"),_("Qty"));
//table_header($th);


end_table(1);

br();
        
$Ajax->Activate('test'); 
div_start('test');

//        display_project_boq_material_page($selected_id, $Mode, $boq_item_id, get_post('detail_type_code'));
        
display_petty_cash_item_receiving_location($_POST["stype"], $_POST["sd_id"]);
display_petty_cash_item_receiving_items($_POST["stype"], $_POST["sd_id"]);
display_petty_cash_item_receiving_edit_controls($selected_id, $Mode);
        
div_end();
//inactive_control_row($th);

br(2);

echo "<center>";
//submit("Submit", "submit");
echo "<input type='button' name='cancel' class='inputsubmit' onclick='goBack()' value='Close'/>";
echo "</center>";
end_form(2);

//js_get_data_in_parent("guid","parent_guid");
//js_get_data_in_parent($parent,"parent_item_qty");
//js_get_data_in_parent($parent_unit,"parent_unit");
//show_quantity("parent_item_qty");
end_page();
