<?php
/**********************************************************************
***********************************************************************/
include_once($path_to_root . "/includes/ui.inc");
include_once($path_to_root . "/includes/ui/items_cart.inc");
include_once($path_to_root . "/asset_register/includes/db/asset_booking_request_db.inc");
//--------------------------------------------------------------------------------

function add_mio_to_cart(&$order, $new_item, $new_item_qty, $required_date, $line_comment)
{
    if ($order->find_cart_item($new_item))
    {
        display_error(_("For Part :") . $new_item . " " . "This item is already on this material requisition.  You can change the quantity requested of the existing line if necessary.");
    }
    else
    {
        $order->add_to_cart(count($order->line_items), $new_item, $new_item_qty, null, null, $required_date, $line_comment);
    }
}

//--------------------------------------------------------------------------------

function display_ab_header(&$order)
{
	global $Refs;

    start_outer_table(TABLESTYLE2, "width=65%");

    table_section(1);
    label_row(_("Requisition No:"), $order->order_id, "class='tableheader2'");
    label_row(_("Requisition Reference:"), $order->reference, "class='tableheader2'");
    label_row(_("Project Description:"), $order->project_description, "class='tableheader2'");
    label_row(_("Task Description:"), $order->task_description, "class='tableheader2'");
//    label_row(_("Approval Path Description:"), $order->approval_path_description, "class='tableheader2'");
    label_row(_("Required Date:"), $order->required_date, "class='tableheader2'");


    table_section(2, "30%");
    //label_row(_("Requesting Location:"), $order->receiving_location, "class='tableheader2'");
    label_row(_("Issuing Location:"), $order->location_name, "class='tableheader2'");
    label_row(_("Requestor:"), $order->requestor_name, "class='tableheader2'");
    table_section(3, "25%");
    label_row(_("Requisition Comment:"), $order->memo_, "class='tableheader2'");

    end_outer_table(1);


    start_outer_table(TABLESTYLE2, "width=50%"); // outer table
    table_section(1);
    ref_row(_("Reference:"), 'iab_reference', '', $Refs->get_next(104));
    table_section(2, "50%");
    yesno_list_row("Make Requisition Complete:", "iab_complete",$order->mr_complete);
    
    end_outer_table(1); // outer table
}

//---------------------------------------------------------------------------------

function display_ab_items($title, &$order)
{
	global $path_to_root;

	display_heading($title);
    div_start('items_table');
	start_table(TABLESTYLE, "width=80%");
	$th = array(_("Asset"), _("Required From"), _("Required To"),_("Comment"),_("Issuing Date"),_("Checked"));
	//if ( count($order->line_items)) $th[] = '';

	table_header($th);
	$total = 0;
	$k = 0;  //row colour counter

	$id = find_submit('Edit');
	if($order->line_items != 0)
        {
            foreach ($order->line_items as $line_no=>$stock_item)
            {

                if ($id != $line_no)
                {
                    alt_table_row_color($k);

                    $result = get_iab_details($stock_item->row_id);
                    $myrow = db_fetch($result);
                    label_cell($myrow['asset_name']);
                    $_POST['required_from_date'] = $myrow['required_from_date'];

                    label_cell($stock_item->required_from_date);
                    label_cell($stock_item->required_to_date);
                    label_cell($stock_item->line_comment);
                    date_cells('', $stock_item->row_id."_issuing_date");
                    check_cells("", $stock_item->row_id."_check", null, false);
//                    qty_cells(null, $stock_item->row_id."_qty", 0, null, null, $dec);


                    end_row();
                }
            }
        }

    end_table();
	div_end();
}

//---------------------------------------------------------------------------------

function ab_options_controls()
{
	  echo "<br>";
	  start_table();

	  textarea_row(_("Asset Issue Comment:"), 'memo_', null, 50, 3);

	  end_table(1);
}


//---------------------------------------------------------------------------------

function view_requisition_transfer_header($mrt_no, $suppress_view_link=false)
{
    $myrow = get_material_issue_header($mrt_no);

    if (strlen($myrow[0]) == 0)
    {
    	display_note(_("The material requisition transfer sent is not valid."));
    	exit;
    }

   	start_table(TABLESTYLE, "width=80%");

	$th = array(_("#"), _("Reference"), _("Issuing Location"), _("Receiving Location"),
			_("Source MR No"), _("Date"), _("Issued By"));

	table_header($th);
	start_row();
	if ($suppress_view_link)
		label_cell($myrow["mrt_no"]);
	else
		//label_cell(get_trans_view_str(ST_MATERIAL_ISSUE, $myrow["mrt_no"]));
            label_cell(get_inventory_trans_view_str(ST_MATERIAL_ISSUE, $myrow["mrt_no"]), "class='tableheader2'");
        
	label_cell($myrow["reference"]);
	label_cell($myrow["issuing_location_name"]);
	//view_stock_status_cell($myrow["stock_id"], $myrow["StockItemName"]);
	label_cell($myrow["receiving_location_name"]);
        label_cell(get_trans_view_str(ST_MATERIAL_REQ, $myrow["source_mtr_no"]));
	label_cell(sql2date($myrow["created_on"]));
        label_cell($myrow["created_user_name"]);

	end_row();

	comments_display_row(ST_MATERIAL_ISSUE, $mrt_no);

	end_table();

}

//---------------------------------------------------------------------------------

function view_material_requisition_transfer_details($mrt_no, $suppress_view_link=false)
{
    $result = get_material_issue_details($mrt_no, ST_REQTRANSFER);

   	start_table(TABLESTYLE, "width=80%");

	$th = array(_("Itemcode"), _("Item Description"), _("Qualtity"));

	table_header($th);
        
        while ($myrow = db_fetch($result)){
            if($myrow["qty"] > 0){
                start_row();

                label_cell($myrow["stock_id"]);
                view_stock_status_cell($myrow["stock_id"], $myrow["description"]);

                $quantity = $myrow["qty"];

                $dec = get_qty_dec($myrow["stock_id"]);
                qty_cell($quantity, false, $dec);


                end_row();
            }
        }


	end_table();

}


//--------------------------------------------------------------------------------------


?>