<?php
/**********************************************************************
***********************************************************************/
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 . "/inventory/includes/stock_class.inc");
//--------------------------------------------------------------------------------


function add_stock_order(&$order, $new_item, $new_item_qty, $location, $des, $status, $created_on, $row_id, $standard_cost)
{
	$kit = get_item_kit($new_item);
	$item_num = db_num_rows($kit);
          $item = db_fetch($kit);
          
          
          $a = $item['stock_id'];
		// check duplicate stock item
          $check_duplicate = 0;
		foreach ($order->line_items as $order_item)
		{
			if ($order_item->stock_id == $item['stock_id'])
			{
                                $check_duplicate++;
				break;
			}
                        
		}
                
                if($check_duplicate>0){
                    display_error("This item is already on this document");
		
                }  else {
                    $order->add_to_cart (count($order->line_items),$item['stock_id'], $new_item_qty, $standard_cost,
                                            $comment = null, $description=null, $created_on,
                                            $line_comment=null, $row_id = 0, $issued_qty = 0, $requested_qty = 0,
                                            $stock_category_id = 0, $price = 0, $location, $status);
                           
                }

}

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

function display_order_header(&$order) 
{
	start_outer_table(TABLESTYLE2, "width=50%"); // outer table
        table_section(1);
        
        label_row(_("Project:"), $order->project_description);
        label_row(_("Task:"), $order->task_description);
        label_row(_("Approval Path:"), $order->approval_path_description);
        
	table_section(2);

        label_row(_("Reference:"), $order->reference);
        label_row(_("Location:"), $order->location);
             
	table_section(3);
        

        label_row(_("Date:"), $order->tran_date);
        stock_count_status_list_cells(_("Status:"), 'sid', $order->status_id, false);
       
	end_outer_table(1); // outer table
}


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

function display_order_summary($title, &$order, $editable_items=false)
{
	global $SysPrefs;

	display_heading($title);

        div_start('items_table');
	
        
        if($order->status_id > SC_COUNTING){
                $width = 70;
                $th = array(_("Item Code"), _("Description"), _("Units"), 
                            _("Counted Qty"), _("System Qty"), _("Difference"), _("Unit Cost"));
        }
        else{
                $width = 50;
                $th = array(_("Item Code"), _("Description"), _("Units"), 
                            _("Counted Qty")); 
        }
        
        start_outer_table(TABLESTYLE, "width=$width%", 10);

        start_table(TABLESTYLE, "colspan=7 width=90%");
	table_header($th);

	$k = 0;  //row colour counter

	foreach ($order->line_items as $line_no=>$stock_item)
	{
                    $result = get_stock_count_complete_details($order->order_no, $stock_item->stock_id);
                    $myrow = db_fetch($result);
                    alt_table_row_color($k);
                    view_stock_status_cell($stock_item->stock_id);
                    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($order->status_id > SC_COUNTING){
                        qty_cell($myrow['system_qty'], false, $dec);
                        qty_cell($stock_item->quantity - $myrow['system_qty'], false, $dec);
                        qty_cell($myrow['standard_cost'], false, $dec);
                    }

        }
        end_table(1);
        
        end_outer_table(1, false);
        
    div_end();
}

?>