<?php
/**********************************************************************
***********************************************************************/

//$path_to_root = "..";

include_once($path_to_root . "/includes/ui.inc");
include_once($path_to_root . "/includes/ui/ui_lists.inc");
include_once($path_to_root . "/includes/ui/items_cart.inc");
include_once($path_to_root . "/includes/ui/ui_input.inc");
include_once($path_to_root . "/includes/ui/ui_msgs.inc");
include_once($path_to_root . "/includes/ui/items_cart.inc");
include_once($path_to_root . "/sales/includes/sales_db.inc");
include_once($path_to_root . "/sales/includes/cart_class.inc");
include_once($path_to_root . "/projects/includes/db/tasks_db.inc");
include_once($path_to_root . "/includes/db/approval_functions_db.inc");
//--------------------------------------------------------------------------------


function display_stock_count_header($stock_count_id)
{
    global $stock_counting_statuses;
    
    $header_row = get_stock_count_header($stock_count_id);      

	start_table(TABLESTYLE2, "width=50%"); // outer table
//        table_section(1);
            start_row();
            label_cells(_("Project"), $header_row['project_description'], "class='tableheader2'");
            label_cells(_("Reference"), $header_row['reference'], "class='tableheader2'");
            label_cells(_("Date"), $header_row['tran_date'], "class='tableheader2'");

            start_row();
            label_cells(_("Budget"), $header_row['task_description'], "class='tableheader2'");
            label_cells(_("Location"), $header_row['location_name'], "class='tableheader2'");
            label_cells(_("Status"), $stock_counting_statuses[$header_row['status_id']], "class='tableheader2'");
            end_row();
            
            start_row();
            label_cells(_("Total Adjustement Value"), $header_row['total_adj_value'], "class='tableheader2'");
            label_cells(_("Comments"), $header_row['comments'], "class='tableheader2'", '', "colspan=2");
            end_row();

    end_table(1);     
    

    
    hidden('stock_count_id', $stock_count_id);

}


//function display_order_header(&$order) 
//{
//	global $Refs;
//        
//        start_outer_table(TABLESTYLE2, "width=50%"); // outer table
//        table_section(1);
//        if(!isset($_SESSION['stock_counts']->status_id))
//        {
//            project_list_row(_("Project:"), 'project_id', null, _('New project'), true);
//            tasks_list_row(_("Task:"), 'task_id', $_POST['project_id'], null, _('Select a task'), true);
//            if ($_POST['task_id'] != -1)
//            {
//                $result = get_task_approval_path($_POST['task_id']);
//                label_row(_("Approval Path:"), $result['approval_path_name']);
//            }
//            else {
//                label_row(_("Approval Path:"),"");
//            }
//        }
//        
//        else 
//        {
//            
//            if(isset($_POST['project_id'])){
//                $order->project_id  = $_POST["project_id"];
//            }
//            if(isset($_POST['task_id'])){
//                $order->task_id  = $_POST["task_id"];
//            }
//            $order->task_id;
//            $order->approval_path_id = 0;
//            $order->approval_path_description = '';
//
//
//            project_list_row(_("Select a project:"), 'project_id', $order->project_id,FALSE,TRUE);
//            tasks_list_row(_("Select a task:"), 'task_id', $order->project_id, $order->task_id,false, TRUE);
//
//            if(isset($_POST['task_id'])){
//                $order->task_id  = $_POST["task_id"];
//                $approval_path = get_approval_path($order->task_id);
//                if($approval_path){
//                    $order->approval_path_id = $approval_path['approval_path_id'];
//                    $order->approval_path_description = $approval_path['approval_path_description'];
//                }
//            }
//
//            label_row("Approval Path:", $order->approval_path_description);
//        }
//        
//        
//	table_section(2);
//        if ((isset($order->status_id)) && $order->status_id > SC_COUNTING){
//            label_row(_("Reference:"), $order->reference);
//            label_row(_("Location:"), $order->location);
//        }
//        else {
//            if (!isset($order->reference)){
//                   ref_row(_("Reference:"), 'reference', '', $Refs->get_next(ST_STOCK_COUNT));
//            }
//            else
//            {
//                ref_row(_("Reference:"), 'reference', '', $order->reference);
//            }
//            
//            if (!isset($order->location))
//                   locations_list_row(_("Location:"), 'Location', null, false, false);
//            else
//            {
//                locations_list_row(_("Location:"), 'Location', $order->loc_code, false, false);
//            }
//        }
//        
//	table_section(3);
//        
//        if ((isset($order->status_id)) && $order->status_id > SC_COUNTING){
//            label_row(_("Date:"), $order->tran_date);
//            
//        }
//        else {
//            if (!isset($order->tran_date)){
//                date_row(_("Date:"), 'tran_date', '', true);
//            }
//            else{
//                $_POST['tran_date'] = sql2date($order->tran_date);
//                date_row(_("Date:"), 'tran_date' );
//            } 
//        }
//            
//        check_status($order);
//
//        stock_count_status_list_cells(_("Status:"), 'sid', $order->status_id, false);
//
//	end_outer_table(1); // outer table
//}


//function check_status(&$order){}

//----------------------------FROM SALES ORDER   DISPLAY ADJUSMENT ITEMS-----------------------------------------------------

//function display_order_summary($title, &$order, $editable_items=false)
//{
//	global $SysPrefs;
//
//	display_heading($title);
//
//    div_start('items_table');
//	start_table(TABLESTYLE, "colspan=7 width=90%");
//$th = array(_("Item Code"), _("Description"), _("Units"), _("Quantity"), "");
//
//	if (count($order->line_items))
//	     $th[]= '';
//
//	table_header($th);
//
//	$total = 0;
//	$k = 0;  //row colour counter
//
//	$id = find_submit('Edit');
//	$has_marked = false;
//
//	foreach ($order->line_items as $line_no=>$stock_item)
//	{
//		$qoh_msg = '';
//		if (!$editable_items || $id != $line_no)
//		{
//			
//			
//				alt_table_row_color($k);
//			$_POST['comment'] = "";
//
//			view_stock_status_cell($stock_item->stock_id);
//
//			//label_cell($stock_item->item_description, "nowrap" );
//                        
//			label_cell($stock_item->item_description );
//			$dec = get_qty_dec($stock_item->stock_id);
//                        label_cell($stock_item->units);
//			qty_cell($stock_item->quantity, false, $dec);
//
//			if ($editable_items)
//			{
//				edit_button_cell("Edit$line_no", _("Edit"),
//				_('Edit document line'));
//				delete_button_cell("Delete$line_no", _("Delete"),
//				_('Remove line from document'));
//			}
//			end_row();
//		}
//		else
//		{
//			sales_order_item_controls($order, $k,  $line_no);
//		}
//                     
//		//$total += $line_total;
//	}
//
//	if ($id==-1 && $editable_items)
//		sales_order_item_controls($order, $k);
//
//        end_table(1);
//    div_end();
//}

///------------FROM SALES ORDER SALES ORDER ITEM CONTROLS-----

//function sales_order_item_controls(&$order, &$rowcounter, $line_no=-1)
//{
//    global $Ajax;
//
//	alt_table_row_color($rowcounter);
//
//	$id = find_submit('Edit');
//	if ($line_no!=-1 && $line_no == $id) // edit old line
//	{
//		$dec = get_qty_dec($_POST['stock_id']);
//		$_POST['qty'] = number_format2($order->line_items[$id]->quantity, $dec);
//		$units = $order->line_items[$id]->units;
//		$_POST['item_description'] = $order->line_items[$id]->item_description;
//		hidden('stock_id', $_POST['stock_id']);
//		label_cell($_POST['stock_id']);
//                label_cell($_POST['item_description']);
//                
//                $Ajax->activate('items_table');
//	}
//	else	// prepare new line
//	{
//                stock_costable_items_list_cells(null, 'stock_id', null, false, true);
//		//sales_items_list_cells(null,'stock_id', null, false, true, true);
//		if (list_updated('stock_id')) {
//			    $Ajax->activate('price');
//			    $Ajax->activate('units');
//			    $Ajax->activate('qty');
//			    $Ajax->activate('line_total');
//		}
//
//		$item_info = get_item_edit_info($_POST['stock_id']);
//		$units = $item_info["units"];
//		$dec = $item_info['decimals'];
//		$_POST['qty'] = number_format2(0, $dec);
//	}
//        label_cell($units, '', 'units');
//	qty_cells(null, 'qty', $_POST['qty'], null, null, $dec);
//
//
//
//	if ($id!=-1)
//	{
//		button_cell('UpdateItem', _("Update"),
//				_('Confirm changes'), ICON_UPDATE);
//		button_cell('CancelItemChanges', _("Cancel"),
//				_('Cancel changes'), ICON_CANCEL);
//		hidden('LineNo', $line_no);
//		set_focus('qty');
//	}
//	else
//	{
//		submit_cells('AddItem', _("Add Item"), "colspan=2 align='center'",
//		    _('Add new item to document'), true);
//	}
//
//	end_row();
//}

function display_stock_count_comments($comments)
{

	  echo "<br>";
	  start_table();

	  textarea_row(_("Comments"), 'comments', $comments, 50, 3);

	  end_table(1);
}

function processing_start()
{
	page_processing(false);
    processing_end();
    $_SESSION['Processing'] = $_SERVER['PHP_SELF'];
}

function processing_end()
{
	page_processing(true);
    unset($_SESSION['Processing']);
    if ( isset($_SESSION['adj_items']) ) {
		unset($_SESSION['adj_items']->line_items);
		unset($_SESSION['adj_items']);
    }
}

?>