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

include_once($path_to_root . "/includes/ui/ui_lists.inc");

$_search_button = "<input %s type='submit' class='combo_submit' style='border:0;background:url($path_to_root/themes/"
	."%s/images/locate.png) no-repeat;%s' aspect='fallback' name='%s' value=' ' title='"._("Set filter")."'> ";

$_select_button = "<input %s type='submit' class='combo_select' style='border:0;background:url($path_to_root/themes/"
	."%s/images/button_ok.png) no-repeat;%s' aspect='fallback' name='%s' value=' ' title='"._("Select")."'> ";

$all_items = ALL_TEXT;

//----------------------------------------------------------------------------
//	Universal sql combo generator
//	$sql must return selector values and selector texts in columns 0 & 1
//	Options are merged with defaults.


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

//----------------------------------------------------------------------------
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
// Amended lists from the original ui_lists
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
//----------------------------------------------------------------------------

function supplier_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false,
	$all=false, $editkey = false)
{
	global $SysPrefs;

        $sql = "SELECT supplier_id, supp_ref, supp_name, curr_code, inactive FROM ".TB_PREF."suppliers ";

	$mode = get_company_pref('no_supplier_list');

	if ($editkey)
		set_editor('supplier', $name, $editkey);

	$ret = combo_input($name, $selected_id, $sql, 'supplier_id', 'supp_name',
	array(
		'format' => 'format_suppliers',
	    'order' => array('supp_ref'),
		'search_box' => $mode!=0,
		'type' => 1,
        'search' => array("supp_ref","supp_name","gst_no"),        
		'spec_option' => $spec_option === true ? _("All Suppliers") : $spec_option,
		'spec_id' => ALL_NUMERIC,
		'select_submit'=> $submit_on_change,
		'async' => false,
		'sel_hint' => $mode ? _('Press Space tab to filter by name fragment') :
		_('Select supplier'),
		'show_inactive'=>$all,
		'editlink' => $editkey ? add_edit_combo('supplier') : false
		), "supplier");
	return $ret;
}

function supplier_list_cells($label, $name, $selected_id=null, $all_option=false, 
	$submit_on_change=false, $all=false, $editkey = false)
{
	if ($label != null)
		echo "<td>$label</td>\n";
	echo "<td>";	
	echo supplier_list($name, $selected_id, $all_option, $submit_on_change, 
		$all, $editkey);
	echo "</td>\n";
}

function supplier_list_row($label, $name, $selected_id=null, $all_option = false, 
	$submit_on_change=false, $all=false, $editkey = false)
{
	echo "<tr><td class='label'>$label</td><td>";
	echo supplier_list($name, $selected_id, $all_option, $submit_on_change,
		$all, $editkey);
	echo "</td></tr>\n";
}

function format_suppliers($row)
{

        return $row[1] . "&nbsp;-&nbsp;" . $row[2];
			
}


function locations_list($name, $selected_id=null, $all_option=false, $submit_on_change=false, $show_all_location = false)
{
	global $all_items;

    if($show_all_location){
        $sql = "SELECT l.loc_code, l.location_name, l.inactive FROM ".TB_PREF."locations l";
    }
    else{
        $sql = "SELECT l.loc_code, l.location_name, l.inactive
                FROM 0_locations l 
                    LEFT JOIN 0_locations pl ON 
                            l.loc_code = pl.reservation_loc_code 
                WHERE pl.loc_code IS NULL";
    }

return combo_input($name, $selected_id, $sql, 'l.loc_code', 'l.location_name',
	array(
		'spec_option' => $all_option === true ? _("All Locations") : $all_option,
		'spec_id' => $all_items,
		'select_submit'=> $submit_on_change
	) );
}

function locations_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false, $show_all_location = false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo locations_list($name, $selected_id, $all_option, $submit_on_change, $show_all_location);
	echo "</td>\n";
}

function locations_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=true, $show_all_location = false)
{
	echo "<tr><td class='label'>$label</td>";
	locations_list_cells(null, $name, $selected_id, $all_option, $submit_on_change, $show_all_location);
	echo "</tr>\n";
}




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

function customer_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false, 
	$show_inactive=false, $editkey = false)
{
	global $SysPrefs;

        $sql = "SELECT debtor_no, debtor_ref, value_name, name, curr_code, dm.inactive 
            FROM ".TB_PREF."debtors_master dm 
                    LEFT JOIN ".TB_PREF."list_values lv ON 
                            dm.debtor_type = lv.id"; 
        
	$mode = get_company_pref('no_customer_list');

	if ($editkey)
		set_editor('customer', $name, $editkey);

	$ret = combo_input($name, $selected_id, $sql, 'debtor_no', 'debtor_ref',
	array(
	    'format' => '_format_debtors',
	    'order' => array('debtor_ref'),
		'search_box' => $mode!=0,
		'type' => 1,
		'size' => 20,
        'search' => array("debtor_ref","name","tax_id"),        
		'spec_option' => $spec_option === true ? _("All Customers") : $spec_option,
		'spec_id' => ALL_TEXT,
		'select_submit'=> $submit_on_change,
		'async' => false,
		'sel_hint' => $mode ? _('Press Space tab to filter by name fragment; F2 - entry new customer') :
		_('Select customer'),
		'show_inactive' => $show_inactive,
		'editlink' => $editkey ? add_edit_combo('customer') : false
	), "customer" );
	return $ret;
}

function customer_list_cells($label, $name, $selected_id=null, $all_option=false, 
	$submit_on_change=false, $show_inactive=false, $editkey = false)
{
	if ($label != null)
		echo "<td>$label</td>\n";
	echo "<td nowrap>";
	echo customer_list($name, $selected_id, $all_option, $submit_on_change,
		$show_inactive, $editkey);
	echo "</td>\n";
}

function customer_list_row($label, $name, $selected_id=null, $all_option = false, 
	$submit_on_change=false, $show_inactive=false, $editkey = false)
{

	echo "<tr><td class='label'>$label</td><td nowrap>";
	echo customer_list($name, $selected_id, $all_option, $submit_on_change,
		$show_inactive, $editkey);
	echo "</td>\n</tr>\n";
}

function _format_debtors($row)
{
	return ($row[1] . " - ". $row[3]);
}


//----------------------------------------------------------------------------
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
// New lists
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
//---------------------------------------------------------------------------=

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

function movement_types_list($name, $inventory_movement_type, $selected_id=null, $all_option = false, $submit_on_change=false)
{
	$sql = "SELECT id, name FROM ".TB_PREF."movement_types WHERE type =".$inventory_movement_type;
	return combo_input($name, $selected_id, $sql, 'id', 'name', 
	array(
        'select_submit'=> $submit_on_change,
		'spec_option' => $all_option === true ? _("All Plants") : $all_option
	) );
}

function movement_types_list_cells($label, $name, $inventory_movement_type, $selected_id=null, $all_option = false, $submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo movement_types_list($name, $inventory_movement_type, $selected_id, $all_option, $submit_on_change);
	echo "</td>\n";
}

function movement_types_list_row($label, $name, $inventory_movement_type, $selected_id=null, $all_option = false, $submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	movement_types_list_cells(null, $name, $inventory_movement_type, $selected_id, $all_option, $submit_on_change);
	echo "</tr>\n";
}

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


function stock_item_types_list_cells($label, $name, $selected_id=null, $enabled=true, $none_option=false, $submit_on_change=true)
{
	global $stock_types;

	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";

	echo array_selector($name, $selected_id, $stock_types, 
		array( 
			'select_submit'=> $submit_on_change, 
			'disabled' => !$enabled, 
    		'spec_option' => $none_option));
	echo "</td>\n";
}


function loyalty_members_list($name, $selected_id=null, $all_option=false, 
	$submit_on_change=false, $opts=array(), $editkey = false)
{
	global $all_items;
        
        $sql = "select member_no , member_name , value_code  
                FROM ".TB_PREF."member_master m, ".TB_PREF."list_values l 
                WHERE l.id = m.status_id " ;
        

	if ($editkey)
		set_editor('item', $name, $editkey);

	$ret = combo_input($name, $selected_id, $sql, 'member_no', 'member_name',
	array_merge(
	  array(
		'format' => '_format_loyalty_members',
		'spec_option' => $all_option===true ?  _("All Items") : $all_option,
		'spec_id' => $all_items,
		'search_box' => true,
		'search' => array("member_no", "member_name"),
                //'search' => array("stock_id", "c.description","s.description"),
		'search_submit' => 0,
		'size'=>10,
		'select_submit'=> $submit_on_change,
		'category' => 2,
		'order' => array('value_code','member_no')
	  ), $opts) );
	if ($editkey)
		$ret .= add_edit_combo('item');		
	return $ret;
	  
}

function _format_loyalty_members($row)
{
	return (user_show_codes() ?  ($row[0] . "&nbsp;-&nbsp;") : "") . $row[1];
}

function loyalty_members_list_cells($label, $name, $selected_id=null, $all_option=false, 
	$submit_on_change=false, $all=false, $editkey = false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo loyalty_members_list($name, $selected_id, $all_option, $submit_on_change,
		array('cells'=>true, 'show_inactive'=>$all), $editkey);
}


function loyalty_members_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	loyalty_members_list_cells('', $name, $selected_id, $all_option, $submit_on_change);
	echo "</tr>\n";
}

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

function lists_list($name, $list_type = "", $selected_id=null, $none_option=false, $submit_on_change=false)
{
	$sql = "SELECT list_code, CONCAT(list_name, ' (', list_code,')') description FROM ".TB_PREF."lists ";
                //. "WHERE list_type = ".db_escape($list_type);

	return combo_input($name, $selected_id, $sql, 'list_code', 'description',
	array(
		'spec_option' => $none_option,
		'spec_id' => ALL_NUMERIC,
		'select_submit'=> $submit_on_change,
		'async' => false,
        'order' => array('list_name')
	) );
}

function lists_list_cells($label, $name, $list_type = "", $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo lists_list($name, $list_type, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function lists_list_row($label, $name, $list_type = "", $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	lists_list_cells(null, $name, $list_type, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}




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

function value_list_grouped($name, $list_code, $selected_id=null, $none_option=false, $submit_on_change=false, $display_type=1)
{
	$sql = "SELECT lv.id, lv.value_code, gn.value_name, lv.value_name   
            FROM ".TB_PREF."list_values lv 
                        LEFT JOIN ".TB_PREF."list_values gn ON 
                                lv.group_value_id = gn.id  
            WHERE lv.inactive = 0 AND lv.list_code = ".db_escape($list_code);

	global $all_items;
//    $opts = array();
//    $editkey = null;
    $mode = 0;
    $show_inactive = 0;

	$ret = combo_input($name, $selected_id, $sql, 'lv.value_code', 'lv.value_name',
	array(
	    'format' => '_format_list_values_'.$display_type,
	    'order' => array('gn.value_name', 'lv.display_order', 'lv.value_name'),
        'search' => array( "lv.value_code", "lv.value_name"),
//		'search_box' => $mode != 0,
//		'type' => 1,
//		'size' => 20,
        'category' => 2,
		'spec_option' => $none_option === true ? _("All Projects") : $none_option,
//		'spec_id' => $all_items,
		'select_submit'=> $submit_on_change,
		'async' => false,
		'show_inactive' => $show_inactive
	) );
	return $ret;
}

function _format_list_values_1($row)
{
	return ($row[1] . " - ". $row[3]);
}

function _format_list_values_2($row)
{
	return ($row[3]);
}

function value_list_ungrouped($name, $list_code, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	$sql = "SELECT id, value_name, list_code, value_code,  value_description  "
                . "FROM ".TB_PREF."list_values "
                . "WHERE inactive = 0 AND list_code = ".db_escape($list_code);

	return combo_input($name, $selected_id, $sql, 'id', 'value_name',
	array(
		'spec_option' => $none_option,
		'spec_id' => ALL_NUMERIC,
		'select_submit'=> $submit_on_change,
		'async' => false,
                'order' => array('display_order', 'value_name'),
	) );
}

function value_list($name, $list_code, $selected_id=null, $none_option=false, $submit_on_change=false)
{
    global $path_to_root;
    
    include_once($path_to_root . "/admin/db/list_values_db.inc");
    
    $list = get_list($list_code);
    if($list['display_type'] == 0){
        return value_list_ungrouped($name, $list_code, $selected_id, $none_option, $submit_on_change);
    }
    elseif($list['display_type'] == 1 || $list['display_type'] == 2){
        return value_list_grouped($name, $list_code, $selected_id, $none_option, $submit_on_change, $list['display_type']);
    }

}

function value_list_cells($label, $name, $list_code, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo value_list($name, $list_code, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function value_list_row($label, $name, $list_code, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	value_list_cells(null, $name, $list_code, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}


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

function value_list_code($name, $list_code, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	$sql = "SELECT value_code, value_name, value_description  "
                . "FROM ".TB_PREF."list_values "
                . "WHERE inactive = 0 AND list_code = ".db_escape($list_code);

	return combo_input($name, $selected_id, $sql, 'value_code', 'value_name',
	array(
		'spec_option' => $none_option,
		'spec_id' => ALL_NUMERIC,
		'select_submit'=> $submit_on_change,
		'async' => false,
	) );
}

function value_list_code_cells($label, $name, $list_code, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo value_list_code($name, $list_code, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function value_list_code_row($label, $name, $list_code, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	value_list_code_cells(null, $name, $list_code, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}

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

function promotions_list($name, $selected_id=null, $all_option=false, 
	$submit_on_change=false, $opts=array(), $editkey = false)
{
	global $all_items;

	$sql = "SELECT promotion_code, promotion_name, sequence_no FROM ".TB_PREF."promotion_master ";

	if ($editkey)
		set_editor('item', $name, $editkey);

	$ret = combo_input($name, $selected_id, $sql, 'promotion_code', 'promotion_name',
	array_merge(
	  array(
		'format' => '_format_promotions',
		'spec_option' => $all_option===true ?  _("All Items") : $all_option,
		'spec_id' => $all_items,
		'search_box' => true,
		'search' => array("promotion_code", "promotion_name","sequence_no"),
		'search_submit' => 0,
		'size'=>10,
		'select_submit'=> $submit_on_change,
		'category' => 2,
		'order' => array('sequence_no','promotion_code')
	  ), $opts) );
	if ($editkey)
		$ret .= add_edit_combo('item');		
	return $ret;

	
}

function _format_promotions($row)
{
	return (user_show_codes() ?  ($row[0] . "&nbsp;-&nbsp;") : "") . $row[1];
}

function promotions_list_cells($label, $name, $selected_id=null, $all_option=false, 
	$submit_on_change=false, $all=false, $editkey = false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo promotions_list($name, $selected_id, $all_option, $submit_on_change,
		array('cells'=>true, 'show_inactive'=>$all), $editkey);
        
}

function promotions_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false, $search_box = true)
{
	echo "<tr>\n";
	promotions_list_cells($label, $name, $selected_id, $all_option, $submit_on_change, false, false);
	echo "</tr>\n";
}

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


function promotions_list_simple($name, $selected_id=null, $blank_item=false, $submit_on_change=false,
	$show_inactive = false)
{
	global $all_items;

	$sql = "SELECT promotion_code, promotion_name FROM ".TB_PREF."promotion_master ";

return combo_input($name, $selected_id, $sql, 'promotion_code', 'promotion_name',
	array(
		'spec_option'=>$blank_item ? _("") : false,
		'spec_id' => '',
		'select_submit'=> $submit_on_change,
		'show_inactive' => $show_inactive
	) );
}

function promotions_list_cells_simple($label, $name, $selected_id=null, $blank_item=false, $submit_on_change=false,
	$show_inactive = false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo promotions_list_simple($name, $selected_id, $blank_item, $submit_on_change, $show_inactive);
	echo "</td>\n";
}

function promotions_list_row_simple($label, $name, $selected_id=null, $blank_item=false, $submit_on_change=false,
	$show_inactive = false)
{
	echo "<tr><td class='label'>$label</td>";
	promotions_list_cells_simple(null, $name, $selected_id, $blank_item, $submit_on_change, $show_inactive);
	echo "</tr>\n";
}

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

function qty_value_list($name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
{
	$items = array();
	$items['Q'] = strlen($name_no) ? $name_no : _("Qty");
	$items['V'] = strlen($name_yes) ? $name_yes : _("Value");

	return array_selector($name, $selected_id, $items, 
		array( 
			'select_submit'=> $submit_on_change,
			'async' => false ) ); // FIX?
}

function qty_value_list_cells($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo qty_value_list($name, $selected_id, $name_yes, $name_no, $submit_on_change);
	echo "</td>\n";
}

function qty_value_list_row($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	qty_value_list_cells(null, $name, $selected_id, $name_yes, $name_no, $submit_on_change);
	echo "</tr>\n";
}

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


function once_multiples_list($name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
{
	$items = array();
	$items['O'] = strlen($name_no) ? $name_no : _("Once Only");
	$items['M'] = strlen($name_yes) ? $name_yes : _("Multiple Times");

	return array_selector($name, $selected_id, $items, 
		array( 
			'select_submit'=> $submit_on_change,
			'async' => false ) ); // FIX?
}

function once_multiples_list_cells($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo once_multiples_list($name, $selected_id, $name_yes, $name_no, $submit_on_change);
	echo "</td>\n";
}

function once_multiples_list_row($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	once_multiples_list_cells(null, $name, $selected_id, $name_yes, $name_no, $submit_on_change);
	echo "</tr>\n";
}

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


function value_points_list($name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
{
	$items = array();
	$items['V'] = strlen($name_no) ? $name_no : _("Invoice Full Value");
	$items['P'] = strlen($name_yes) ? $name_yes : _("Points Redeemed");

	return array_selector($name, $selected_id, $items, 
		array( 
			'select_submit'=> $submit_on_change,
			'async' => false ) ); // FIX?
}

function value_points_list_cells($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo value_points_list($name, $selected_id, $name_yes, $name_no, $submit_on_change);
	echo "</td>\n";
}

function value_points_list_row($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	value_points_list_cells(null, $name, $selected_id, $name_yes, $name_no, $submit_on_change);
	echo "</tr>\n";
}

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



function value_percentage_list($name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
{
	$items = array();
	$items['V'] = strlen($name_no) ? $name_no : _("Value");
	$items['P'] = strlen($name_yes) ? $name_yes : _("Percentage");

	return array_selector($name, $selected_id, $items, 
		array( 
			'select_submit'=> $submit_on_change,
			'async' => false ) ); // FIX?
}

function value_percentage_list_cells($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo value_percentage_list($name, $selected_id, $name_yes, $name_no, $submit_on_change);
	echo "</td>\n";
}

function value_percentage_list_row($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	value_percentage_list_cells(null, $name, $selected_id, $name_yes, $name_no, $submit_on_change);
	echo "</tr>\n";
}


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


function total_benefit_list($name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
{
	$items = array();
	$items['T'] = strlen($name_no) ? $name_no : _("Total Qty");
	$items['B'] = strlen($name_yes) ? $name_yes : _("Benefit Qty");

	return array_selector($name, $selected_id, $items, 
		array( 
			'select_submit'=> $submit_on_change,
			'async' => false ) ); // FIX?
}

function total_benefit_list_cells($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo total_benefit_list($name, $selected_id, $name_yes, $name_no, $submit_on_change);
	echo "</td>\n";
}

function total_benefit_list_row($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	total_benefit_list_cells(null, $name, $selected_id, $name_yes, $name_no, $submit_on_change);
	echo "</tr>\n";
}

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

function loyalty_cards_list1($name, $selected_id=null, $all_option=false, 
	$submit_on_change=false, $opts=array(), $editkey = false,  $search_box = true)
{
	global $all_items;

	//$sql = "SELECT card_no, card_no, card_no FROM ".TB_PREF."loyalty_cards_master ";
        $sql = "SELECT card_no, card_no, lv.value_name card_type_name 
                FROM ".TB_PREF."loyalty_cards_master lcm, ".TB_PREF."list_values lv 
                WHERE lv.id = lcm.card_type_id AND 
                    inactive = 0 AND list_code = 'L_CARD_TYPES'"; 

	if ($editkey)
		set_editor('item', $name, $editkey);

	$ret = combo_input($name, $selected_id, $sql, 'card_no', 'card_no',
	array_merge(
	  array(
		'format' => '_format_loyalty_cards',
		'spec_option' => $all_option===true ?  _("All Items") : $all_option,
		'spec_id' => $all_items,
		'search_box' => $search_box,
		'search' => array("card_no", "card_no","card_no"),
		'search_submit' => get_company_pref('no_item_list')!=0,
		'size'=>10,
		'select_submit'=> $submit_on_change,
		'category' => 2,
		'order' => array('card_no')
	  ), $opts) );
	if ($editkey)
		$ret .= add_edit_combo('item');		
	return $ret;
	  
}

function _format_loyalty_cards($row)
{
	return (user_show_codes() ?  ($row[0] . "&nbsp;-&nbsp;") : "") . $row[1];
}

function loyalty_cards_list_cells1($label, $name, $selected_id=null, $all_option=false, 
	$submit_on_change=false, $all=false, $editkey = false, $search_box = true)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo loyalty_cards_list1($name, $selected_id, $all_option, $submit_on_change,
		array('cells'=>true, 'show_inactive'=>$all), $editkey, $search_box);
}
/*
function stock_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
{
	echo "<tr>\n";
	stock_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
	echo "</tr>\n";
}
*/
//------------------------------------------------------------------------------------


function loyalty_cards_list($name, $selected_id=null, $new_item=false, $submit_on_change=false,
	$show_inactive = false)
{
	global $all_items;

//	$sql = "SELECT card_no, card_no, lv.value_name card_type_name 
//                FROM ".TB_PREF."loyalty_cards_master lcm, ".TB_PREF."list_values lv 
//                WHERE lv.id = lcm.card_type_id AND 
//                    inactive = 0 AND list_code = 'L_CARD_TYPES'"; 
        
        	$sql = "SELECT card_no, card_no 
                        FROM ".TB_PREF."loyalty_cards_master "; 

//return combo_input($name, $selected_id, $sql, 'card_no', 'card_no',
//	array(
//		'spec_option'=>$new_item ? _($new_item) : false,
//		'spec_id' => '',
//		'select_submit'=> $submit_on_change,
//		'show_inactive' => $show_inactive
//	) );
                
                return combo_input($name, $selected_id, $sql, 'card_no', 'card_no',
	array(
		'spec_option'=>$new_item ? _($new_item) : false,
                'select_submit'=> $submit_on_change
	) );
}

function loyalty_cards_list_cells($label, $name, $selected_id=null, $new_item=false, $submit_on_change=false,
	$show_inactive = false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo loyalty_cards_list($name, $selected_id, $new_item, $submit_on_change, $show_inactive);
	echo "</td>\n";
}

function loyalty_cards_list_row($label, $name, $selected_id=null, $new_item=false, $submit_on_change=false,
	$show_inactive = false)
{
	echo "<tr><td class='label'>$label</td>";
	loyalty_cards_list_cells(null, $name, $selected_id, $new_item, $submit_on_change, $show_inactive);
	echo "</tr>\n";
}

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

function bank_transaction_types_list($name, $value=null, $spec_opt=false, $all_option = false, $submit_on_change=false)
{
	global $bank_transaction_types;

        asort($bank_transaction_types);

	return array_selector($name, $value, $bank_transaction_types, 
		array( 
			'spec_option'=> $spec_opt,
			'spec_id' => ALL_NUMERIC,
			'select_submit'=> $submit_on_change,
			'async' => false,
            'spec_option'=>$all_option,
			)
	);
}

function bank_transaction_types_list_cells($label, $name, $value=null, $all_option = false, $submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo bank_transaction_types_list($name, $value, false, $all_option, $submit_on_change);
	echo "</td>\n";
}

function bank_transaction_types_list_row($label, $name, $value=null, $all_option = false, $submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	bank_transaction_types_list_cells(null, $name, $value, $all_option, $submit_on_change);
	echo "</tr>\n";
}


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

function non_stock_items_list($name, $selected_id=null,
	$all_option=false, $submit_on_change=false)
{
	return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
		array('where'=>array("mb_flag='D'")));
}

function non_stock_items_list_cells($label, $name, $selected_id=null, 
	$all_option=false, $submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
		array('where'=>array("mb_flag='D'"), 'cells'=>true));
}

function non_stock_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
{
	echo "<tr>";
	if ($label != null)
		echo "<td class='label'>$label</td>\n";
	echo "<td>";
	echo stock_costable_items_list_cells(null, $name, $selected_id, $all_option, $submit_on_change);
	echo "</td></tr>";
}





function emoplyees_list($name, $selected_id=null, $all_option=false, 
	$submit_on_change=false, $opts=array(), $editkey = false)
{
	global $all_items;

	$sql = "SELECT employee_code, em.last_name, lv.value_name,  em.initials, em.inactive, em.first_name, em.employee_reference   
			FROM ".TB_PREF."employee_master em, ".TB_PREF."list_values lv 
                        WHERE em.employee_type_id = lv.id";
//    
//    $sql = "SELECT employee_code, em.last_name, lv.value_name,  em.first_name, em.inactive 
//			FROM ".TB_PREF."employee_master em, ".TB_PREF."list_values lv 
//                        WHERE em.employee_type_id = lv.id";
        
	if ($editkey)
		set_editor('item', $name, $editkey);

	$ret = combo_input($name, $selected_id, $sql, 'employee_code', 'em.last_name',
	array_merge(
	  array(
		'format' => '_format_emoplyees',
		'spec_option' => $all_option===true ?  _("All Items") : $all_option,
		'spec_id' => $all_items,
//		'search_box' => true,
		'search' => array("employee_code", "lv.value_name","em.last_name"),
		'search_submit' => get_company_pref('no_employee_list')!=0,
		'size'=>10,
        'type' => 2,
		'select_submit'=> $submit_on_change,
		'category' => 2,
		'order' => array('lv.value_name', 'employee_code')
	  ), $opts) );
	if ($editkey)
		$ret .= add_edit_combo('item');		
	return $ret;
	  
}

function _format_emoplyees($row)
{
	return (user_show_codes() ?  ($row[6] . "&nbsp;-&nbsp;") : "") . $row[3]." ".$row[1]." (".$row[5].")";
}

function emoplyees_list_cells($label, $name, $selected_id=null, $all_option=false, 
	$submit_on_change=false, $all=false, $editkey = false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo emoplyees_list($name, $selected_id, $all_option, $submit_on_change,
		array('cells'=>true, 'show_inactive'=>$all), $editkey);
}

function emoplyees_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
        //echo "<tr>\n";
	emoplyees_list_cells('', $name, $selected_id, $all_option, $submit_on_change);
	echo "</tr>\n";
}

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


function two_value_list($name, $selected_id=null, $name_yes="", $name_no="", $code_yes="", $code_no="",$submit_on_change=false, $all_option = false)
{
	$items = array();
	$items[$code_no] = strlen($name_no) ? $name_no : _("Male");
	$items[$code_yes] = strlen($name_yes) ? $name_yes : _("Female");

	return array_selector($name, $selected_id, $items, 
		array( 
			'select_submit'=> $submit_on_change,
                        'spec_option' => $all_option===true ?  _("All Items") : $all_option,
			'async' => false ) ); // FIX?
}

function two_value_list_cells($label, $name, $selected_id=null, $name_yes="", $name_no="", $code_yes="", $code_no="", $submit_on_change=false, $all_option = false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo two_value_list($name, $selected_id, $name_yes, $name_no, $code_yes, $code_no, $submit_on_change, $all_option);
	echo "</td>\n";
}

function two_value_list_row($label, $name, $selected_id=null, $name_yes="", $name_no="", $code_yes="", $code_no="", $submit_on_change=false, $all_option = false)
{
	echo "<tr><td class='label'>$label</td>";
	two_value_list_cells(null, $name, $selected_id, $name_yes, $name_no, $code_yes, $code_no,$submit_on_change, $all_option);
	echo "</tr>\n";
}


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



function three_value_list($name, $selected_id=null, $name1="", $code1="", $name2="", $code2="", $name3="", $code3="",$submit_on_change=false, $all_option = false)
{
	$items = array();
	$items[$code1] = strlen($name1) ? $name1 : _($name1);
	$items[$code2] = strlen($name2) ? $name2 : _($name2);
        $items[$code3] = strlen($name3) ? $name3 : _($name3);

	return array_selector($name, $selected_id, $items, 
		array( 
			'select_submit'=> $submit_on_change,
            'spec_option' => $all_option===true ?  _("All Items") : $all_option,
			'async' => false ) ); // FIX?
}

function three_value_list_cells($label, $name, $selected_id=null,  $name1="", $code1="", $name2="", $code2="", $name3="", $code3="", $submit_on_change=false, $all_option = false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo three_value_list($name, $selected_id, $name1, $code1, $name2, $code2, $name3, $code3, $submit_on_change, $all_option);
	echo "</td>\n";
}

function three_value_list_row($label, $name, $selected_id=null,  $name1="", $code1="", $name2="", $code2="", $name3="", $code3="", $submit_on_change=false, $all_option = false)
{
	echo "<tr><td class='label'>$label</td>";
	three_value_list_cells(null, $name, $selected_id,  $name1, $code1, $name2, $code2, $name3, $code3,$submit_on_change, $all_option);
	echo "</tr>\n";
}

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

function assigned_leave_list($name, $employee_code, $selected_id=null, $none_option=false, $submit_on_change=false)
{
        global $all_items;
        
        $spec_option = false;
        $enabled =  false;

	$sql = "SELECT DISTINCT le.id,  CONCAT(value_name, ' from ',from_date, ' to ',to_date) leave_type_name
                FROM 
                    ".TB_PREF."leave_entitlements le,
                    ".TB_PREF."list_values lv  
		WHERE 	
                    le.leave_type_id = lv.id AND 
                    le.closed = 0 AND 
                    le.employee_code = ".db_escape($employee_code) ;

	$where = $enabled ? array("disable_trans = 0") : array();
	$ret = combo_input($name, $selected_id, $sql, 'leave_type_id', 'value_name',
	array(
		'where' => $where,
		'order' => array('value_name'),
		'spec_option' => $none_option === true ? _('All branches') : $none_option,
		'spec_id' => $all_items,
		'select_submit'=> $submit_on_change,
		'sel_hint' => _('Select customer branch')
	) );
	
	return $ret;      

}

function assigned_leave_list_cells($label, $name, $employee_code, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo assigned_leave_list($name, $employee_code, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function assigned_leave_list_row($label, $name, $employee_code, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	assigned_leave_list_cells(null, $name, $employee_code, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}


//---------------------------------------------------------------------------------------------------
function stock_manufactured_items_list_cells2($label, $name, $selected_id=null, 
	$all_option=false, $submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
		array('where'=>array("mb_flag='M'"), 'cells'=>true));
}
//------------------------------------------------------------------------------------------------


function custom_sql_list($name, $sql_string, $selected_id=null )
{
	global $all_items;

        $all_option=false; $submit_on_change=false;
                
	$sql = $sql_string;

        return combo_input($name, $selected_id, $sql, null, null,
                array(
                        'spec_option' => $all_option === true ? _("All Locations") : $all_option,
                        'spec_id' => $all_items,
                        'select_submit'=> $submit_on_change
                ) );
}

function custom_sql_list_cells($label, $name, $sql_string, $selected_id=null)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo custom_sql_list($name, $sql_string, $selected_id);
	echo "</td>\n";
}

function custom_sql_list_row($label, $name, $sql_string, $selected_id=null)
{
	echo "<tr><td class='label'>$label</td>";
	custom_sql_list_cells(null, $name, $sql_string, $selected_id);
	echo "</tr>\n";
}

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


function system_users_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	$sql = "SELECT id, real_name  "
                . "FROM ".TB_PREF."users "
                . "WHERE inactive = 0 ";

	return combo_input($name, $selected_id, $sql, 'id', 'real_name',
	array(
		'spec_option' => $none_option,
		'spec_id' => ALL_NUMERIC,
		'select_submit'=> $submit_on_change,
		'async' => false,
	) );
}

function system_users_list_cells($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo system_users_list($name, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function system_users_list_row($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	system_users_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}

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


function stock_counts_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	$sql = "SELECT stock_count_no, CONCAT(stock_count_no,' - ', reference, ' - ', loc_code) description  "
                . "FROM ".TB_PREF."stock_counts ";

	return combo_input($name, $selected_id, $sql, 'stock_count_no', 'description',
	array(
		'spec_option' => $none_option,
		'spec_id' => ALL_NUMERIC,
		'select_submit'=> $submit_on_change,
		'async' => false,
	) );
}

function stock_counts_list_cells($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo stock_counts_list($name, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function stock_counts_list_row($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	stock_counts_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}

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

function member_type_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	$sql = "SELECT id, member_type, description  "
                . "FROM ".TB_PREF."member_types "
                . "WHERE inactive = 0 ";

	return combo_input($name, $selected_id, $sql, 'id', 'member_type',
	array(
		'spec_option' => $none_option,
		'spec_id' => ALL_NUMERIC,
		'select_submit'=> $submit_on_change,
		'async' => false,
	) );
}

function member_type_list_cells($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo member_type_list($name, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function member_type_list_row($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	member_type_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}

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

function shift_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	$sql = "SELECT id, shift_name  "
                . "FROM ".TB_PREF."shifts "
                . "WHERE inactive = 0 ";

	return combo_input($name, $selected_id, $sql, 'id', 'shift_name',
	array(
		'spec_option' => $none_option,
		'spec_id' => ALL_NUMERIC,
		'select_submit'=> $submit_on_change,
		'async' => false,
	) );
}

function shift_list_cells($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo shift_list($name, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function shift_list_row($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	shift_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}

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

function payroll_run_list($name, $selected_id=null, $none_option=false, $submit_on_change=false, $approved = null)
{
	$sql = "SELECT id, CONCAT(period_start_date, ' - ', period_end_date, ' - ',description) abc  
                FROM ".TB_PREF."payroll_runs 
                WHERE ";

    if($approved === 1){
        //$sql .= "status IN('R')";
        $sql .= "status IN('N','U','C','L','S','R')";
    }
    elseif($approved === 0){
        $sql .= "status IN('N','U','C','L','S')";
    }
    else{
        $sql .= " 1 ";
    }

	return combo_input($name, $selected_id, $sql, 'id', 'abc',
	array(
		'spec_option' => $none_option,
		'spec_id' => ALL_NUMERIC,
		'select_submit'=> $submit_on_change,
		'async' => false,
	) );
}

function payroll_run_list_cells($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false, $approved = null)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo payroll_run_list($name, $selected_id, $none_option, $submit_on_change, $approved);
	echo "</td>\n";
}

function payroll_run_list_row($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false, $approved = null)
{
	echo "<tr><td class='label'>$label</td>";
	payroll_run_list_cells(null, $name, $selected_id, $none_option, $submit_on_change, $approved);
	echo "</tr>\n";
}

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

function raw_material_issue_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	$sql = "SELECT rmi_no, CONCAT(location, ' - ', rmi_no, ' - ', tran_date) abc  "
                . "FROM ".TB_PREF."raw_material_issues "
                . "WHERE 1 ";

	return combo_input($name, $selected_id, $sql, 'rmi_no', 'location, rmi_no',
	array(
		'spec_option' => $none_option,
		'spec_id' => ALL_NUMERIC,
		'select_submit'=> $submit_on_change,
		'async' => false,
	) );
}

function raw_material_issue_list_cells($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo raw_material_issue_list($name, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function raw_material_issue_list_row($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	raw_material_issue_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}

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

function raw_material_return_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	$sql = "SELECT rmr_no, CONCAT(location, ' - ', rmr_no, ' - ', tran_date) abc  "
                . "FROM ".TB_PREF."raw_material_returns "
                . "WHERE 1 ";

	return combo_input($name, $selected_id, $sql, 'rmr_no', 'location, rmr_no',
	array(
		'spec_option' => $none_option,
		'spec_id' => ALL_NUMERIC,
		'select_submit'=> $submit_on_change,
		'async' => false,
	) );
}

function raw_material_return_list_cells($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo raw_material_return_list($name, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function raw_material_return_list_row($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	raw_material_return_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}


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

function production_receipts_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	$sql = "SELECT production_receipt_no, CONCAT(receiving_location, ' - ', production_receipt_no, ' - ', tran_date) abc  "
                . "FROM ".TB_PREF."production_receipts "
                . "WHERE 1 ";

	return combo_input($name, $selected_id, $sql, 'production_receipt_no', 'receiving_location, production_receipt_no',
	array(
		'spec_option' => $none_option,
		'spec_id' => ALL_NUMERIC,
		'select_submit'=> $submit_on_change,
		'async' => false,
	) );
}

function production_receipts_list_cells($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo production_receipts_list($name, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function production_receipts_list_row($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	production_receipts_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}


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

function production_returns_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	$sql = "SELECT production_return_no, CONCAT(location, ' - ', production_return_no, ' - ', tran_date) abc  "
                . "FROM ".TB_PREF."production_returns "
                . "WHERE 1 ";

	return combo_input($name, $selected_id, $sql, 'production_return_no', 'location, production_return_no',
	array(
		'spec_option' => $none_option,
		'spec_id' => ALL_NUMERIC,
		'select_submit'=> $submit_on_change,
		'async' => false,
	) );
}

function production_returns_list_cells($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo production_returns_list($name, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function production_returns_list_row($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	production_returns_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}


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


function manufacturing_transactions_list_cell($name, $selected=null)
{
	global $all_items;

	echo "<td>\n";
	$allocs = array( 
		$all_items=>_("All Types"),
		'61'=>_("Raw Material Issues"),
		'62'=> _("Manufacturing Receipts"),
		'65'=> _("Raw Material Returns"),
		'66' => _("Manufacturing Returns"),
		'26' => _("Work Orders")
	);

	echo array_selector($name, $selected, $allocs);
	echo "</td>\n";
}

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

function material_transfer_requisitions_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	$sql = "SELECT mtr_no, CONCAT(mtr_no, ' - ', requesting_location, ' - ',issuing_location, ' - ', mtr_date) abc  "
                . "FROM ".TB_PREF."material_transfer_requisitions "
                . "WHERE 1 ";

	return combo_input($name, $selected_id, $sql, 'mtr_no', 'abc',
	array(
		'spec_option' => $none_option,
		'spec_id' => ALL_NUMERIC,
		'select_submit'=> $submit_on_change,
		'async' => false,
        'order' => array('mtr_no DESC')
	) );
}


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


function material_requisition_transfers_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	$sql = "SELECT mrt_no, CONCAT(mrt_no, ' - ', issuing_location, ' - ',receiving_location, ' - ', created_on) abc  "
                . "FROM ".TB_PREF."material_requisition_transfers "
                . "WHERE 1 ";

	return combo_input($name, $selected_id, $sql, 'mtr_no', 'abc',
	array(
		'spec_option' => $none_option,
		'spec_id' => ALL_NUMERIC,
		'select_submit'=> $submit_on_change,
		'async' => false,
                'order' => array('mrt_no DESC')
	) );
}


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


function inventory_transactions_list_cell($name, $selected=null, $none_option=false, $submit_on_change=false)
{
	global $inventory_transaction_types;

	echo "<td>\n";

	echo array_selector($name, $selected, $inventory_transaction_types, 
		array( 
            'spec_option' => $none_option,
			'select_submit'=> $submit_on_change,
			'async' => false ) ); // FIX?
	echo "</td>\n";
}

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


function weekdays_list($name, $selected_id=null, $submit_on_change=false)
{
	$items = array();
	$items["M"] = "Monday";
	$items["T"] = "Tuesday";
        $items["W"] = "Wednesday";
        $items["H"] = "Thursday";
	$items["F"] = "Friday";
        $items["S"] = "Satureday";
        $items["N"] = "Sunday";
        
	return array_selector($name, $selected_id, $items, 
		array( 
			'select_submit'=> $submit_on_change,
			'async' => false ) ); // FIX?
}

function weekdays_list_cells($label, $name, $selected_id=null,  $submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo weekdays_list($name, $selected_id, $submit_on_change);
	echo "</td>\n";
}

function weekdays_list_row($label, $name, $selected_id=null,  $submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	weekdays_list_cells(null, $name, $selected_id,  $submit_on_change);
	echo "</tr>\n";
}

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

function weekend_work_time_list($name, $selected_id=null, $submit_on_change=false)
{
	$items = array();
	$items["0"] = "Shift hours";
	$items["1"] = "4 hours";
    $items["2"] = "Half of shift hours";
    $items["3"] = "8 hours";
    $items["4"] = "Zero hours";
    $items["5"] = "5 hours";
        
	return array_selector($name, $selected_id, $items, 
		array( 
			'select_submit'=> $submit_on_change,
			'async' => false ) ); // FIX?
}

function weekend_work_time_list_cells($label, $name, $selected_id=null,  $submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo weekend_work_time_list($name, $selected_id, $submit_on_change);
	echo "</td>\n";
}

function weekend_work_time_list_row($label, $name, $selected_id=null,  $submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	weekend_work_time_list_cells(null, $name, $selected_id,  $submit_on_change);
	echo "</tr>\n";
}

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

//----------- jobs ---------------

//----- plants---


function plants_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
{
	global $all_items;

	$sql = "SELECT plant_code, plant_name FROM ".TB_PREF."plant";


return combo_input($name, $selected_id, $sql, 'plant_code', 'plant_name',
	array(
		'spec_option' => $all_option === true ? _("All Plants") : $all_option,
		'spec_id' => $all_items,
		'select_submit'=> $submit_on_change
	) );
}

function plants_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo plants_list($name, $selected_id, $all_option, $submit_on_change);
	echo "</td>\n";
}

function plants_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	plants_list_cells(null, $name, $selected_id, $all_option, $submit_on_change);
	echo "</tr>\n";
}


//---- job types ---


function jobs_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
{
	global $all_items;

	$sql = "SELECT job_code, job_name FROM ".TB_PREF."job_type";


return combo_input($name, $selected_id, $sql, 'job_code', 'job_name',
	array(
		'spec_option' => $all_option === true ? _("All Job Types") : $all_option,
		'spec_id' => $all_items,
		'select_submit'=> $submit_on_change
	) );
}

function jobs_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo jobs_list($name, $selected_id, $all_option, $submit_on_change);
	echo "</td>\n";
}

function jobs_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	jobs_list_cells(null, $name, $selected_id, $all_option, $submit_on_change);
	echo "</tr>\n";
}

function stock_count_status_list_cells($label, $name, $selected_id=null, $enabled=false, $all_option=false, $submit_on_change=false)
{
	global $stock_counting_statuses;

	//echo "<tr>";
	if ($label != null)
		echo "<td class='label'>$label</td>\n";
	echo "<td>";

	echo array_selector($name, $selected_id, $stock_counting_statuses, 
		array( 
			'select_submit'=> true, 
			'disabled' => !$enabled) );
	echo "</td>\n";
}

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

//function project_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
//{
//	$sql = "SELECT project_id, CONCAT(project_code,' - ',project_name, ' - ',description) as description  "
//                . "FROM ".TB_PREF."projects_master ";
//
//	return combo_input($name, $selected_id, $sql, 'project_id', 'description',
//	array(
//		'spec_option' => $none_option,
//		'spec_id' => ALL_NUMERIC,
//		'select_submit'=> $submit_on_change,
//		'async' => false,
//	) );
//}
//
//function project_list_cells($label, $name, $selected_id=null, $none_option=false,
//	$submit_on_change=false)
//{
//	if ($label != null)
//		echo "<td class='label-light'>$label</td>\n";
//	echo "<td>";
//	echo project_list($name, $selected_id, $none_option, $submit_on_change);
//	echo "</td>\n";
//}
//
//function project_list_row($label, $name, $selected_id=null, $none_option=false,
//	$submit_on_change=false)
//{
//	echo "<tr><td class='label'>$label</td>";
//	project_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
//	echo "</tr>\n";
//}
//-----------------------------------------------------------------------------------------------
function approval_group_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
{
	$sql = "SELECT approval_group_id, approval_group_description FROM ".TB_PREF."approval_group";
	return combo_input($name, $selected_id, $sql, 'approval_group_id', 'approval_group_description',
 	array('order'=>'approval_group_description',
		'spec_option' => $spec_opt,
		'spec_id' => -1,
 		'select_submit'=> $submit_on_change,
 		'async' => true
 	));
}

function approval_group_list_cells($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo approval_group_list($name, $selected_id, $spec_opt, $submit_on_change);
	echo "</td>\n";
}

function approval_group_list_row($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	approval_group_list_cells(null, $name, $selected_id, $spec_opt, $submit_on_change);
	echo "</tr>\n";
}
//-----------------------------------------------------------------------------------------------
function approval_path_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
{
	$sql = "SELECT approval_path_id, approval_path_name FROM ".TB_PREF."approval_path";
	return combo_input($name, $selected_id, $sql, 'approval_path_id', 'approval_path_name',
 	array('order'=>'approval_path_name',
		'spec_option' => $spec_opt,
		'spec_id' => -1,
 		'select_submit'=> $submit_on_change,
 		'async' => true
 	));
}

function approval_path_list_cells($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo approval_path_list($name, $selected_id, $spec_opt, $submit_on_change);
	echo "</td>\n";
}

function approval_path_list_row($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	approval_path_list_cells(null, $name, $selected_id, $spec_opt, $submit_on_change);
	echo "</tr>\n";
}
//-----------------------------------------------------------------------------------------------
function email_template_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
{
	$sql = "SELECT template_id, template_description FROM ".TB_PREF."email_template";
	return combo_input($name, $selected_id, $sql, 'template_id', 'template_description',
 	array('order'=>'template_id',
		'spec_option' => $spec_opt,
		'spec_id' => -1,
 		'select_submit'=> $submit_on_change,
 		'async' => true
 	));
}

function email_template_list_cells($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo email_template_list($name, $selected_id, $spec_opt, $submit_on_change);
	echo "</td>\n";
}

function email_template_list_row($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	email_template_list_cells(null, $name, $selected_id, $spec_opt, $submit_on_change);
	echo "</tr>\n";
}
//-----------------------------------------------------------------------------------------------
//function user_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
//{
//	$sql = "SELECT user_id, real_name FROM ".TB_PREF."users";
//	return combo_input($name, $selected_id, $sql, 'user_id', 'real_name',
// 	array('order'=>'user_id',
//		'spec_option' => $spec_opt,
//		'spec_id' => -1,
// 		'select_submit'=> $submit_on_change,
// 		'async' => true
// 	));
//}
//
//function user_list_cells($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
//{
//	if ($label != null)
//		echo "<td class='label-light'>$label</td>\n";
//	echo "<td>";
//	echo user_list($name, $selected_id, $spec_opt, $submit_on_change);
//	echo "</td>\n";
//}
//
//function user_list_row($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
//{
//	echo "<tr><td class='label'>$label</td>";
//	user_list_cells(null, $name, $selected_id, $spec_opt, $submit_on_change);
//	echo "</tr>\n";
//}

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

//function user_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
//{
//	$sql = "SELECT id, real_name FROM ".TB_PREF."users";
//	return combo_input($name, $selected_id, $sql, 'id', 'name', 
//            array(
//                    'order' => 'id',
//                    'spec_option' => $none_option,
//                    'spec_id' => ALL_NUMERIC,
//                    'select_submit'=> $submit_on_change,
//                    'async' => false 
//            ) );
//    
//    		
//}

function user_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false,
	$all=false)
{
	global $all_items;

	$sql = "SELECT id, real_name, inactive  FROM ".TB_PREF."users"; 

//	$mode = get_company_pref('no_supplier_list');
        $mode = 0;	
		
	$ret = combo_input($name, $selected_id, $sql, 'id', 'real_name',
	array(
                'order' => array('real_name'),
		'search_box' => $mode!=0,
		'type' => 1,
//                'category' => 2,
		'spec_option' => $spec_option === true ? _("All Users") : $spec_option,
		'spec_id' => $all_items,
		'select_submit'=> $submit_on_change,
		'async' => false,
//		'sel_hint' => $mode ? _('Press Space tab to filter by name fragment') : _('Select supplier'),
		'show_inactive'=>$all
		));
//	if ($editkey)
//		$ret .= add_edit_combo('supplier');		
	return $ret;
}

function user_list_cells($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false, $all=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo user_list($name, $selected_id, $none_option, $submit_on_change, $all);
	echo "</td>\n";
}

function user_list_row($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	user_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}

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

function tasks_list($name, $project_id, $selected_id=null, $none_option=false, $submit_on_change=false)
{
//	$sql = "SELECT pt.task_id, CONCAT(pt.description, ' (', pt.task_code,')') description   
//            FROM ".TB_PREF."project_tasks pt                     
//            WHERE project_id = $project_id ";
//
//	return combo_input($name, $selected_id, $sql, 'task_id', 'description',
//	array(
//		'spec_option' => $none_option,
//		'spec_id' => ALL_NUMERIC,
//		'select_submit'=> $submit_on_change,
//		'async' => false,
//	) );
//}


    $sql = "SELECT pt.task_id, pt.task_code, boqg.description, pt.description, pt.budget, pt.budget_used, pt.budget_allocated  
            FROM ".TB_PREF."project_tasks pt 
                    LEFT JOIN ".TB_PREF."project_task_groups ptg ON 
                        pt.task_group_id = ptg.id 
                    LEFT JOIN ".TB_PREF."project_boq_item_groups boqg ON 
                        ptg.boq_group_id = boqg.id 
            WHERE pt.project_id = ".db_escape($project_id);

            
//	$sql = "SELECT pt.task_id, pt.task_code, boqg.description, pt.description   
//            FROM ".TB_PREF."project_tasks pt      
//                    LEFT JOIN ".TB_PREF."project_boq_item_groups boqg ON 
//                            pt.group_id = boqg.id 
//            WHERE pt.project_id = ".db_escape($project_id);

	global $all_items;
    $opts = array();
    $editkey = null;
    $mode = 0;
    $show_inactive = 0;
    
//    if ($_SESSION["wa_current_user"]->can_access("SA_VIEW_PROJECT_BUDGETS")){
    if (user_view_available_budget()){
        $format_function = "_format_budgets_show_values";
    }
    else{
        $format_function = "_format_budgets_hide_values";
    }

	$ret = combo_input($name, $selected_id, $sql, 'pt.description', 'pt.task_code',
	array(
	    'format' => $format_function,
	    'order' => array('boqg.position', 'boqg.display_order', 'pt.task_code'),
            'search' => array( "pt.description", "pt.task_code"),
            'search_box' => $mode != 0,
            'type' => 1,
            'size' => 20,
            'category' => 2,
            'spec_option' => $none_option === true ? _("All Budgets") : $none_option,
            'spec_id' => $all_items,
            'select_submit'=> $submit_on_change,
            'async' => false,
            'sel_hint' => $mode ? _('Press Space tab to filter by name fragment') : _('Select a Budget'),
            'show_inactive' => $show_inactive
	) );
	if ($editkey){
		$ret .= add_edit_combo('customer');
    }
    
//    $search = viewer_link('', 'projects/manage/tasks_list.php?popup=1&parent='.$name.'&project_id='.$project_id, '', '',  ICON_VIEW);
//    
//    $pos = strpos($ret, '</td>', 0);
//    $ret = substr_replace($ret, $search, $pos, 0);
	return $ret;

}

function _format_budgets_show_values($row)
{
    $budget_available = $row[4] - $row[5] - $row[6];
	return $row[1]." (".number_format($budget_available, 2).") ".$row[3];
}

function _format_budgets_hide_values($row)
{
//    $budget_available = $row[4] - $row[5] - $row[6];
	return $row[1]." - ".$row[3];
}



function tasks_list_cells($label, $name, $project_id, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo tasks_list($name, $project_id, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function tasks_list_row($label, $name, $project_id, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	tasks_list_cells(null, $name, $project_id, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}
//-----------------------------------------------------------------------------------------------

function project_serial_category_list($name, $selected_id=null, $none_option=false, $submit_on_change=false, $category_id=0)
{
	$sql = "SELECT category_code, description FROM ".TB_PREF."project_serial_numbers 
                WHERE category_id = $category_id ";

	return combo_input($name, $selected_id, $sql, 'project_id', 'description',
	array(
		'spec_option' => $none_option,
		'spec_id' => ALL_NUMERIC,
		'select_submit'=> $submit_on_change,
		'async' => false,
	) );
}

function project_serial_category_list_cells($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false, $category_id=0)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo project_serial_category_list($name, $selected_id, $none_option, $submit_on_change, $category_id);
	echo "</td>\n";
}

function project_serial_category_list_row($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false, $category_id=0)
{
	echo "<tr><td class='label'>$label</td>";
	project_serial_category_list_cells(null, $name, $selected_id, $none_option, $submit_on_change, $category_id);
	echo "</tr>\n";
}
//-----------------------------------------------------------------------------------------------

function customer_code_list($name, $selected_id=null, $none_option=false, $submit_on_change=false, $category_id=0)
{
	$sql = "SELECT category_code, description FROM ".TB_PREF."project_serial_numbers 
                WHERE category_id = $category_id ";

	return combo_input($name, $selected_id, $sql, 'project_id', 'description',
	array(
		'spec_option' => $none_option,
		'spec_id' => ALL_NUMERIC,
		'select_submit'=> $submit_on_change,
		'async' => false,
	) );
}

function customer_code_list_cells($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false, $category_id=0)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo customer_code_list($name, $selected_id, $none_option, $submit_on_change, $category_id);
	echo "</td>\n";
}

function customer_code_list_row($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false, $category_id=0)
{
	echo "<tr><td class='label'>$label</td>";
	customer_code_list_cells(null, $name, $selected_id, $none_option, $submit_on_change, $category_id);
	echo "</tr>\n";
}
//-----------------------------------------------------------------------------------------------

function project_code_list($name, $selected_id=null, $none_option=false, $submit_on_change=false, $category_id=0)
{
	$sql = "SELECT category_code, description FROM ".TB_PREF."project_serial_numbers 
                WHERE category_id = $category_id ";

	return combo_input($name, $selected_id, $sql, 'project_id', 'description',
	array(
		'spec_option' => $none_option,
		'spec_id' => ALL_NUMERIC,
		'select_submit'=> $submit_on_change,
		'async' => false,
	) );
}

function project_code_list_cells($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false, $category_id=0)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo project_code_list($name, $selected_id, $none_option, $submit_on_change, $category_id);
	echo "</td>\n";
}

function project_code_list_row($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false, $category_id=0)
{
	echo "<tr><td class='label'>$label</td>";
	project_code_list_cells(null, $name, $selected_id, $none_option, $submit_on_change, $category_id);
	echo "</tr>\n";
}
//--------------------------------------------------------------------------

function asset_types_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	global $asset_types, $all_items;
		
	return array_selector($name, $selected_id, $asset_types, 
		array( 
                        'spec_option' => $none_option,
                        'spec_id' => $all_items,
			'select_submit'=> $submit_on_change
			) );
}

function asset_types_list_cells($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo asset_types_list($name, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function asset_types_list_row($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	asset_types_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}

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

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

function asset_categories_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
{
     $sql = "SELECT id, description  "
                . "FROM ".TB_PREF."asset_catergories ";

	return combo_input($name, $selected_id, $sql, 'id', 'description',
	array(
		'spec_option' => $none_option,
		'spec_id' => ALL_NUMERIC,
		'select_submit'=> $submit_on_change,
		'async' => false,
	    ) );
//	global $asset_types;
//		
//	echo array_selector($name, $selected_id, $asset_types, 
//		array( 
//			'select_submit'=> $submit_on_change
//			) );
}

function asset_categories_list_cells($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
   
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo asset_categories_list($name, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function asset_categoris_list_row($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	asset_categories_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}

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

function tool_list($name, $selected_id=null, $all_option=false, $submit_on_change=false, $asset_type = AT_TOOL, $opts=array(), $editkey = false)
{
	global $all_items;

	$sql = "SELECT a.asset_id, a.description, g.description, a.asset_code, a.inactive  
			FROM ".TB_PREF."asset_master a 
                    JOIN ".TB_PREF."asset_groups g ON 
                            a.group_id = g.id 
                    WHERE a.type = ". db_escape($asset_type);

	if ($editkey){
		set_editor('item', $name, $editkey);
        }

	$ret = combo_input($name, $selected_id, $sql, 'a.asset_id', 'a.description',
	array_merge(
	  array(
		'format' => '_format_asset_tools',
		'spec_option' => $all_option===true ?  _("All Items") : $all_option,
		'spec_id' => $all_items,
		'search_box' => true,
		'search' => array("a.asset_id", "a.asset_code", "a.description"),
		'search_submit' => true,
		'size'=>10,
		'select_submit'=> $submit_on_change,
		'category' => 2,
		'order' => array('g.description', 'a.description', 'a.asset_code')
	  ), $opts) );
    
	if ($editkey){
		//$ret .= add_edit_combo('item');	
                $ret .= add_edit_combo('item');
    }
    
    if(isset($opts['where'])){
        $search = viewer_link('', 'assets/manage/tool_list.php?popup=1&parent='.$name."&asset_type=$asset_type", '', '',  ICON_VIEW);
    }
    else{
        $search = viewer_link('', 'assets/manage/tool_list.php?popup=1&parent='.$name."&asset_type=$asset_type", '', '',  ICON_VIEW);
    }
    
    $pos = strpos($ret, '</td>', 0);
    $ret = substr_replace($ret, $search, $pos, 0);
    
	return $ret;

	  
}

function _format_asset_tools($row)
{
	return $row[1] . "&nbsp;-&nbsp;"  . $row[3]. " - (".$row[0].")" ;
}

function tool_list_cells($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false, $asset_type = AT_TOOL, $all=false, $editkey = false)
{
	if ($label != null){
		echo "<td class='label-light'>$label</td>\n";
    }
	echo tool_list($name, $selected_id, $none_option, $submit_on_change, $asset_type,
		array('cells'=>true, 'show_inactive'=>$all), $editkey);
}

function tool_list_row($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false, $asset_type = AT_TOOL)
{
	echo "<tr><td class='label'>$label</td>";
        //echo "<tr>\n";
        tool_list_cells('', $name, $selected_id, $none_option, $submit_on_change, $asset_type);
	echo "</tr>\n";
}


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


function asset_list($name, $selected_id=null, $all_option=false, $submit_on_change=false, $asset_type = null, $opts=array(), $editkey = false)
{
	global $all_items;

	$sql = "SELECT a.asset_id, a.description, g.description, a.asset_code, a.inactive  
                    FROM ".TB_PREF."asset_master a 
                        LEFT JOIN ".TB_PREF."asset_groups g ON 
                            a.group_id = g.id";

	if ($editkey){
		set_editor('item', $name, $editkey);
        }

	$ret = combo_input($name, $selected_id, $sql, 'a.asset_id', 'a.description',
	array_merge(
	  array(
		'format' => '_format_assets',
		'spec_option' => $all_option===true ?  _("All Items") : $all_option,
		'spec_id' => $all_items,
		'search_box' => true,
		'search' => array("a.asset_id", "a.asset_code", "a.description"),
		'search_submit' => true,
		'size'=>10,
		'select_submit'=> $submit_on_change,
		'category' => 2,
		'order' => array('g.description', 'a.description', 'a.asset_code')
	  ), $opts) );
    
	if ($editkey){
		//$ret .= add_edit_combo('item');	
                $ret .= add_edit_combo('item');
    }
    
    if(isset($opts['where'])){
        $search = viewer_link('', 'assets/manage/asset_list.php?popup=1&parent='.$name, '', '',  ICON_VIEW);
    }
    else{
        $search = viewer_link('', 'assets/manage/asset_list.php?popup=1&parent='.$name, '', '',  ICON_VIEW);
    }
    
    $pos = strpos($ret, '</td>', 0);
    $ret = substr_replace($ret, $search, $pos, 0);
    
	return $ret;

	  
}

function _format_assets($row)
{
	return $row[1] . "&nbsp;-&nbsp;"  . $row[3]. " - (".$row[0].")" ;
}

function asset_list_cells($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false, $asset_type = null, $all=false, $editkey = false)
{
	if ($label != null){
		echo "<td class='label-light'>$label</td>\n";
    }
	echo asset_list($name, $selected_id, $none_option, $submit_on_change, $asset_type,
		array('cells'=>true, 'show_inactive'=>$all), $editkey);
}

function asset_list_row($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false, $asset_type = null)
{
	echo "<tr><td class='label'>$label</td>";
        //echo "<tr>\n";
    asset_list_cells('', $name, $selected_id, $none_option, $submit_on_change, $asset_type);
	echo "</tr>\n";
}


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

function pr_list($name, $po_no, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	$sql = "SELECT DISTINCT r.requisition_id, r.requisition_id
                FROM ".TB_PREF."purchase_requisition_details as r , ".TB_PREF."purch_order_details as p 
                WHERE r.po_line_id = p.po_detail_item AND
                        (p.quantity_ordered - p.quantity_received) > 0 AND 
                                p.order_no = $po_no ";

	return combo_input($name, $selected_id, $sql, 'r.requisition_id', 'r.requisition_id',
	array(
		'spec_option' => $none_option,
		'spec_id' => ALL_NUMERIC,
		'select_submit'=> $submit_on_change,
		'async' => false,
	) );
}

function pr_list_cells($label, $name, $po_no, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo pr_list($name, $po_no, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function pr_list_row($label, $name, $po_no, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	pr_list_cells(null, $name, $po_no, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}


function tasks_all_list($name, $selected_id=null, $all_option=false, $submit_on_change=false, $all=false)
{
    $sql = "SELECT  t.task_id, p.description as project_name, tn.value_name, p.project_id  
			FROM ".TB_PREF."project_tasks t,"
                    .TB_PREF."projects_master p, "
                    .TB_PREF."list_values tn 
			WHERE t.project_id = p.project_id AND 
                    t.type_id = tn.id ";

    
	return combo_input($name, $selected_id, $sql, 't.task_id', 'tn.value_name',
	array(
		'format' => '_format_task',
		'spec_option' => $all_option===true ?  _("") : $all_option,
		'spec_id' => '',
		'type' => 2,
		'order' => array('p.project_id','t.task_id'),
		'search_box' => false,
			'search_submit' => false,
			'size' => 12,
			'max' => 20,
			'cells' => true,
		'select_submit'=> $submit_on_change,
		'async' => false,
		'category' => 1,
		'show_inactive' => $all
	) );

}

function _format_task($row)
{
		//return $row[0] .  "&nbsp;&nbsp;&nbsp;&nbsp;" . $row[1];
        return $row[2] ;
}

function tasks_all_list_cells($label, $name, $selected_id=null, 
	$all_option = false, $submit_on_change=false, $all=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo tasks_all_list($name, $selected_id, $all_option, $submit_on_change, $all);
	echo "</td>\n";
}

function tasks_all_list_row($label, $name, $selected_id=null, $all_option=false)
{
	echo "<tr><td class='label'>$label</td>";
	tasks_all_list_cells(null, $name, $selected_id, $all_option);
	echo "</tr>\n";
}

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

function rate_category_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	$sql = "SELECT id, description FROM ".TB_PREF."employee_rates 
                 ";

	return combo_input($name, $selected_id, $sql, 'id', 'description',
	array(
		'spec_option' => $none_option,
		'spec_id' => ALL_NUMERIC,
		'select_submit'=> $submit_on_change,
		'async' => false,
	) );
}

function rate_category_list_cells($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo rate_category_list($name, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function rate_category_list_row($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	rate_category_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}

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

function bank_branch_list($name, $bank_id, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	$sql = "SELECT id, CONCAT(branch_name, ' (', branch_code, ')') branch_name  
            FROM ".TB_PREF."bank_branches WHERE bank_id = ".db_escape($bank_id);

	return combo_input($name, $selected_id, $sql, 'id', 'branch_name',
	array(
		'spec_option' => $none_option,
		'spec_id' => ALL_NUMERIC,
		'select_submit'=> $submit_on_change,
		'async' => false        
	) );
}

function bank_branch_list_cells($label, $name, $bank_id, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo bank_branch_list($name, $bank_id, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function bank_branch_list_row($label, $name, $bank_id, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	bank_branch_list_cells(null, $name, $bank_id, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}

function salary_components_list($name, $selected_id=null, $salary_components_lists = null, $all_option=false, $submit_on_change=false, $all=false)
{    
    $sql = "SELECT  t.task_id, p.description as project_name, t.description, p.project_id  
			FROM ".TB_PREF."project_tasks t,".TB_PREF."projects_master p
			WHERE t.project_id= p.project_id";
    
    $sql = "SELECT  lv.id, l.list_name as list_name, lv.value_name, l.list_id  
            FROM ".TB_PREF."list_values lv, ".TB_PREF."lists l 
            WHERE lv.list_code = l.list_code AND 
                    l.list_code IN(".$salary_components_lists.")";

    
	return combo_input($name, $selected_id, $sql, 'lv.id', 'lv.value_name',
	array(
		'format' => '_format_salary_components_list',
		'spec_option' => $all_option===true ?  _("") : $all_option,
		'spec_id' => '',
		'type' => 2,
		'order' => array('l.list_id','lv.id'),
		'search_box' => false,
			'search_submit' => false,
			'size' => 12,
			'max' => 20,
			'cells' => true,
		'select_submit'=> $submit_on_change,
		'async' => false,
		'category' => 1,
		'show_inactive' => $all
	) );

}

function _format_salary_components_list($row)
{
		//return $row[0] .  "&nbsp;&nbsp;&nbsp;&nbsp;" . $row[1];
        return $row[2] ;
}

function salary_components_list_cells($label, $name, $selected_id=null, $salary_components_lists = null,
	$all_option = false, $submit_on_change=false, $all=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo salary_components_list($name, $selected_id, $salary_components_lists, $all_option, $submit_on_change, $all);
	echo "</td>\n";
}

function salary_components_list_row($label, $name, $selected_id=null, $salary_components_lists = null, $all_option=false)
{
	echo "<tr><td class='label'>$label</td>";
	salary_components_list_cells(null, $name, $selected_id, $salary_components_lists, $all_option);
	echo "</tr>\n";
}

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

function units_list($name, $stock_id, $selected_id=null, $none_option=false, $submit_on_change=false)
{
  
        $sql = "SELECT au.alternate_unit, iu.name 
                FROM ".TB_PREF."alternate_units au,
                        ".TB_PREF."item_units iu  
                WHERE au.alternate_unit = iu.abbr AND 
                        au.stock_id = ".db_escape($stock_id)." AND au.inactive = 0";

	return combo_input($name, $selected_id, $sql,  'alternate_unit',  'name',
	array(
		'spec_option' => $none_option,
		'spec_id' => ALL_NUMERIC,
		'select_submit'=> $submit_on_change,
		'async' => false,
	) );
}

function units_list_cells($label, $name, $stock_id, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo units_list($name, $stock_id, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function units_list_row($label, $name, $stock_id, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	units_list_cells(null, $name, $stock_id, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}

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

function approved_payroll_run_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	$sql = "SELECT id, CONCAT(period_start_date, ' - ', period_end_date, ' - ',description) abc  "
                . "FROM ".TB_PREF."payroll_runs "
                . "WHERE status = 'R'";

	return combo_input($name, $selected_id, $sql, 'id', 'abc',
	array(
		'spec_option' => $none_option,
		'spec_id' => ALL_NUMERIC,
		'select_submit'=> $submit_on_change,
		'async' => false,
	) );
}
//-----------------------------------------------------------------------------------------------
function inventory_movement_types_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
{
	global $inventory_movement_types;

	//echo "<tr>";
//	if ($label != null)
//		echo "<td class='label'>$label</td>\n";
	//echo "<td>";

	echo array_selector($name, $selected_id, $inventory_movement_types, 
		array( 
			'select_submit'=> true) );
	//echo "</td>\n";
}

function inventory_movement_types_list_cells($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo inventory_movement_types_list($name, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function inventory_movement_types_list_row($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	inventory_movement_types_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}

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

function lot_cotrolled_items_list($name, $selected_id=null,
	$all_option=false, $submit_on_change=false)
{
	return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
		array('where'=>array("stock_control_method = 1")));
}

function lot_cotrolled_items_cells($label, $name, $selected_id=null, 
	$all_option=false, $submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo lot_cotrolled_items_list($name, $selected_id, $all_option, $submit_on_change);
}

function lot_cotrolled_items_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
{
	echo "<tr>";
	if ($label != null)
		echo "<td class='label'>$label</td>\n";
	echo "<td>";
	echo lot_cotrolled_items_cells(null, $name, $selected_id, $all_option, $submit_on_change);
	echo "</td></tr>";
}

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

function lots_list($name, $selected_id=null, $none_option=false, $submit_on_change=false, $stock_id = null)
{
//       $sql = "SELECT id, reference 
//                FROM ".TB_PREF."lots
//                WHERE  stock_id = ".db_escape($stock_id)."  
//                        "; 
            $sql = "SELECT id, CONCAT (lot_reference, '(',IFNULL(lb.balance_qty,0),')') reference 
                    FROM ".TB_PREF."lots l  
                        LEFT JOIN ".TB_PREF."vw_lot_balance lb ON
                            l.stock_id = lb.stock_id AND
                            l.id= lb.lot_id
                    
                    WHERE  l.stock_id = ".db_escape($stock_id)." "; 

	return combo_input($name, $selected_id, $sql, 'id', 'reference',
	array(
		'spec_option' => $none_option,
		'spec_id' => ALL_NUMERIC,
		'select_submit'=> $submit_on_change,
		'async' => false,
	) );
}

function lots_list_cells($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false, $stock_id = null)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo lots_list($name, $selected_id, $none_option, $submit_on_change, $stock_id);
	echo "</td>\n";
}

function lots_list_row($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false, $stock_id = null)
{
	echo "<tr><td class='label'>$label</td>";
	lots_list_cells(null, $name, $selected_id, $none_option, $submit_on_change, $stock_id);
	echo "</tr>\n";
}

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

function serial_no_list($name, $selected_id=null, $none_option=false, $submit_on_change=false, $stock_id = null)
{
       $sql = "SELECT id, serial_no 
                FROM ".TB_PREF."serial_nos
                WHERE  stock_id = ".db_escape($stock_id)."  
                        "; 

	return combo_input($name, $selected_id, $sql, 'id', 'serial_no',
	array(
		'spec_option' => $none_option,
		'spec_id' => ALL_NUMERIC,
		'select_submit'=> $submit_on_change,
		'async' => false,
	) );
}

function serial_no_list_cells($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false, $stock_id = null)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo serial_no_list($name, $selected_id, $none_option, $submit_on_change, $stock_id);
	echo "</td>\n";
}

function serial_no_list_row($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false, $stock_id = null)
{
	echo "<tr><td class='label'>$label</td>";
	serial_no_list_cells(null, $name, $selected_id, $none_option, $submit_on_change, $stock_id);
	echo "</tr>\n";
}
    
function serial_no_cotrolled_items_list($name, $selected_id=null,
	$all_option=false, $submit_on_change=false)
{
	return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
		array('where'=>array("stock_control_method = 2")));
}

function serial_no_cotrolled_items_cells($label, $name, $selected_id=null, 
	$all_option=false, $submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo serial_no_cotrolled_items_list($name, $selected_id, $all_option, $submit_on_change);
}

function serial_no_cotrolled_items_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
{
	echo "<tr>";
	if ($label != null)
		echo "<td class='label'>$label</td>\n";
	echo "<td>";
	echo serial_no_cotrolled_items_cells(null, $name, $selected_id, $all_option, $submit_on_change);
	echo "</td></tr>";
}


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

function project_sites_list($name, $project_id, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	$sql = "SELECT id, description  "
                . "FROM ".TB_PREF."project_sites "
                . "WHERE project_id = ". db_escape($project_id);

	return combo_input($name, $selected_id, $sql, 'id', 'description',
	array('order'=>'description',
		'spec_option' => $none_option,
		'spec_id' => ALL_NUMERIC,
		'select_submit'=> $submit_on_change,
		'async' => false,
	) );
}

function project_sites_list_cells($label, $name, $project_id, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo project_sites_list($name, $project_id, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function project_sites_list_row($label, $name, $project_id, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	project_sites_list_cells(null, $name, $project_id, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}

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

function employees_simple_list($name, $selected_id=null, $all_option = false, $submit_on_change=false)
{
	$sql = "SELECT employee_code, 
                    CONCAT(employee_code, ' - ', initials, ' ', last_name) name 
            FROM ".TB_PREF."employee_master ";
    
	return combo_input($name, $selected_id, $sql, 'employee_code', 'name', 
	array(
		'spec_option' => $all_option === true ? _("") : $all_option,
        'select_submit'=> $submit_on_change 
	) );
}

function employees_simple_list_cells($label, $name, $selected_id=null, $all_option = false, $submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo employees_simple_list($name, $selected_id, $all_option, $submit_on_change);
	echo "</td>\n";
}

function employees_simple_list_row($label, $name, $selected_id=null, $all_option = false, $submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	employees_simple_list_cells(null, $name, $selected_id, $all_option, $submit_on_change);
	echo "</tr>\n";
}

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

function employees_simple_list_2($name, $selected_id=null, $all_option = false, $submit_on_change=false, $emp_type_array=array())
{
	$sql = "SELECT em.employee_code, 
                    CONCAT(em.employee_reference, ' - ', em.initials, ' ', em.last_name, ' (', em.employee_code, ')') name 
                FROM ".TB_PREF."employee_master em 
                    JOIN ".TB_PREF."list_values lv 
                        ON em.employee_type_id = lv.id 
                WHERE lv.list_code = 'EMPLOYEE_TYPE' 
                    AND lv.value_code IN (".implode(',', $emp_type_array).")";
    
	return combo_input($name, $selected_id, $sql, 'employee_code', 'name', 
	array(
		'spec_option' => $all_option === true ? _("") : $all_option,
                'select_submit'=> $submit_on_change 
	) );
}

function employees_simple_list_cells_2($label, $name, $selected_id=null, $all_option = false, $submit_on_change=false, $emp_type_array=array())
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo employees_simple_list_2($name, $selected_id, $all_option, $submit_on_change, $emp_type_array);
	echo "</td>\n";
}

function employees_simple_list_row_2($label, $name, $selected_id=null, $all_option = false, $submit_on_change=false, $emp_type_array=array())
{
	echo "<tr><td class='label'>$label</td>";
	employees_simple_list_cells_2(null, $name, $selected_id, $all_option, $submit_on_change, $emp_type_array);
	echo "</tr>\n";
}

//-----------------------------------------------------------------------------------------------
function inventory_movement_type_linked_fields_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
{
	global $inventory_movement_type_linked_fields;

	//echo "<tr>";
//	if ($label != null)
//		echo "<td class='label'>$label</td>\n";
	//echo "<td>";

	echo array_selector($name, $selected_id, $inventory_movement_type_linked_fields, 
		array( 
                'spec_option' => $all_option,
                'select_submit'=> $submit_on_change) );
	//echo "</td>\n";
}

function inventory_movement_type_linked_fields_list_cells($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo inventory_movement_type_linked_fields_list($name, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function inventory_movement_type_linked_fields_list_row($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	inventory_movement_type_linked_fields_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}
//-----------------------------------------------------------------------------------------------

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

function payroll_salary_components_list($name, $selected_id=null, $all_option=false, $submit_on_change=false, $all=false)
{
    $sql = "SELECT  t.task_id, p.description as project_name, tn.value_name, p.project_id  
			FROM ".TB_PREF."project_tasks t,"
                    .TB_PREF."projects_master p, "
                    .TB_PREF."list_values tn 
			WHERE t.project_id = p.project_id AND 
                    t.type_id = tn.id ";

    $sql = 	"SELECT lv.id,  l.list_name, lv.value_name, lv.value_code "
                . "FROM ".TB_PREF."list_values lv, "
                            .TB_PREF."lists l "
                . "WHERE lv.list_code = l.list_code AND lv.inactive = 0 AND lv.list_code IN (".PAYROLL_LISTS.")";
    
	return combo_input($name, $selected_id, $sql, 'lv.id', 'lv.value_name',
	array(
		'format' => '_format_payroll_salary_component',
		'spec_option' => $all_option===true ?  _("") : $all_option,
		'spec_id' => '',
		'type' => 2,
		'order' => array('l.list_name','lv.value_name'),
		'search_box' => false,
			'search_submit' => false,
			'size' => 12,
			'max' => 20,
			'cells' => true,
		'select_submit'=> $submit_on_change,
		'async' => false,
		'category' => 1,
		'show_inactive' => $all
	) );

}

function _format_payroll_salary_component($row)
{
		//return $row[0] .  "&nbsp;&nbsp;&nbsp;&nbsp;" . $row[1];
        return $row[2] ;
}

function payroll_salary_components_list_cells($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo payroll_salary_components_list($name, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function payroll_salary_components_list_row($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	payroll_salary_components_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}

//-----------------------------------------------------------------------------------------------
function inventory_adjustment_types_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
{
	global $inventory_adjustment_types;

	//echo "<tr>";
//	if ($label != null)
//		echo "<td class='label'>$label</td>\n";
	//echo "<td>";

	echo array_selector($name, $selected_id, $inventory_adjustment_types, 
		array( 
			'select_submit'=> $submit_on_change,
            'spec_option' => $all_option===true ?  _("") : $all_option
            ));
	//echo "</td>\n";
}

function inventory_adjustment_types_list_cells($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo inventory_adjustment_types_list($name, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function inventory_adjustment_types_list_row($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	inventory_adjustment_types_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}



//-----------------------------------------------------------------------------------------------
function document_approval_statuses_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
{
	global $document_approval_statuses;

	//echo "<tr>";
//	if ($label != null)
//		echo "<td class='label'>$label</td>\n";
	//echo "<td>";

	return array_selector($name, $selected_id, $document_approval_statuses, 
		array( 
                'spec_option' => $all_option,
                'spec_id' => -1,
                'select_submit'=> $submit_on_change) );
	//echo "</td>\n";
}

function document_approval_statuses_list_cells($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo document_approval_statuses_list($name, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function document_approval_statuses_list_row($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	document_approval_statuses_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}
//-----------------------------------------------------------------------------------------------

function bom_processes_list($name, $parent, $selected_id=null, $none_option=false, $submit_on_change=false)
{
  
        $sql = "SELECT id, CONCAT(sequence, ' - ', description) des   
                FROM ".TB_PREF."bom_processes 
                WHERE parent  = ".db_escape($parent);

	return combo_input($name, $selected_id, $sql,  'id',  'des',
	array(
		'spec_option' => $none_option,
		'spec_id' => ALL_NUMERIC,
		'select_submit'=> $submit_on_change,
		'async' => false,
	) );
}

function bom_processes_list_cells($label, $name, $parent, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo bom_processes_list($name, $parent, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function bom_processes_list_row($label, $name, $parent, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	bom_processes_list_cells(null, $name, $parent, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}

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

function month_names_list($name, $selected_id=null, $all_option = false, $submit_on_change=false)
{
	$months = array();
	$months[1] = "January";
	$months[2] = "February";
    $months[3] = "March";
    $months[4] = "April";
    $months[5] = "May";
    $months[6] = "June";
    $months[7] = "July";
    $months[8] = "August";
    $months[9] = "September";
    $months[10] = "October";
    $months[11] = "November";
    $months[12] = "December";

	return array_selector($name, $selected_id, $months, 
		array( 
			'select_submit'=> $submit_on_change,
            'spec_option' => $all_option===true ?  _("All Items") : $all_option,
            'select_submit'=> $submit_on_change,
			'async' => false ) ); // FIX?
}

function month_names_list_cells($label, $name, $selected_id=null,  $all_option = false, $submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo month_names_list_list($name, $selected_id, $all_option, $submit_on_change);
	echo "</td>\n";
}

function month_names_list_row($label, $name, $selected_id=null, $all_option = false, $submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	month_names_list_cells(null, $name, $selected_id, $all_option, $submit_on_change);
	echo "</tr>\n";
}

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

function months_list($name, $selected_id=null, $all_option = false, $submit_on_change=false)
{
        $sql = "SELECT id, description    
                FROM ".TB_PREF."months ";

	return combo_input($name, $selected_id, $sql,  'id',  'description',
	array(
		'spec_option' => $all_option,
		'spec_id' => ALL_NUMERIC,
		'select_submit'=> $submit_on_change,
		'async' => false,
                'order' => array('display_order DESC'),
	) );
}

function months_list_cells($label, $name, $selected_id=null,  $all_option = false, $submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo months_list($name, $selected_id, $all_option, $submit_on_change);
	echo "</td>\n";
}

function months_list_row($label, $name, $selected_id=null, $all_option = false, $submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	months_list_cells(null, $name, $selected_id, $all_option, $submit_on_change);
	echo "</tr>\n";
}

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

function workorder_processes_list($name, $workorder_id, $selected_id=null, $none_option=false, $submit_on_change=false)
{
  
        $sql = "SELECT id, CONCAT(sequence, ' - ', description) des   
                FROM ".TB_PREF."wo_processes 
                WHERE workorder_id = ".db_escape($workorder_id);

	return combo_input($name, $selected_id, $sql,  'id',  'des',
	array(
		'spec_option' => $none_option,
		'spec_id' => ALL_NUMERIC,
		'select_submit'=> $submit_on_change,
		'async' => false,
	) );
}

function workorder_processes_list_cells($label, $name, $workorder_id, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo workorder_processes_list($name, $workorder_id, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function workorder_processes_list_row($label, $name, $workorder_id, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	workorder_processes_list_cells(null, $name, $workorder_id, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}

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

function workorder_process_work_type_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
{
  
    global $workorder_process_work_types;

    return array_selector($name, $selected_id, $workorder_process_work_types, 
		array( 
			'select_submit'=> $submit_on_change,
            'spec_option' => $none_option===true ?  _("") : $none_option,
            'select_submit'=> $submit_on_change,
			'async' => false ) ); // FIX?

}

function workorder_process_work_type_list_cells($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo workorder_process_work_type_list($name, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function workorder_process_work_type_list_row($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	workorder_process_work_type_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}

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


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

function production_schedule_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	$sql = "SELECT id, CONCAT(period_start_date, ' - ', period_end_date, ' - ',description) abc  
                FROM ".TB_PREF."production_schedule 
                WHERE 1 ";

    

	return combo_input($name, $selected_id, $sql, 'id', 'abc',
	array(
		'spec_option' => $none_option,
		'spec_id' => ALL_NUMERIC,
		'select_submit'=> $submit_on_change,
		'async' => false,
	) );
}

function production_schedule_list_cells($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo production_schedule_list($name, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function production_schedule_list_row($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	production_schedule_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}

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

function batch_i_owe_you_list($name, $batch_no = 0, $iou_id = 0, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	$sql = "SELECT id, CONCAT(id, ' - ', amount, ' - ', tran_date) abc  
                FROM ".TB_PREF."i_owe_you  
                WHERE ";
    if($iou_id > 0){
        $sql .= " batch_no = ".db_escape($batch_no)." OR id = ".db_escape($iou_id);
    }
    else{
         $sql .= " batch_no = ".db_escape($batch_no);
    }
    
//    $sql .= " ORDER BY id";

    

	return combo_input($name, $selected_id, $sql, 'id', 'abc',
	array(
		'spec_option' => $none_option,
		'spec_id' => ALL_NUMERIC,
		'select_submit'=> $submit_on_change,
		'async' => false,
	) );
}

function batch_i_owe_you_list_cells($label, $name, $batch_no = 0, $iou_id = 0, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo batch_i_owe_you_list($name, $batch_no, $iou_id, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function batch_i_owe_you_list_row($label, $name, $batch_no = 0, $iou_id = 0, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	batch_i_owe_you_list_cells(null, $name, $batch_no, $iou_id,$selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}

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



function custom_values_list($name, $values_array, $selected_id=null ,$all_option = false, $submit_on_change=false)
{
	return array_selector($name, $selected_id, $values_array, 
		array( 
			'select_submit'=> $submit_on_change,
            'spec_option' => $all_option===true ?  _("All Items") : $all_option,
			'async' => false ) ); // FIX?
}

function custom_values_list_cells($label, $name, $values_array, $selected_id=null,  $all_option = false, $submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo custom_values_list($name, $values_array, $selected_id, $all_option, $submit_on_change);
	echo "</td>\n";
}

function custom_values_list_row($label, $name, $values_array, $selected_id=null, $all_option = false, $submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	custom_values_list_cells(null, $name, $values_array, $selected_id, $all_option, $submit_on_change);
	echo "</tr>\n";
}

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

function vehicle_packages_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	$sql = "SELECT id, CONCAT(description,' (Rs.',cost,')') display_description  "
                . "FROM ".TB_PREF."vehicle_packages ";

	return combo_input($name, $selected_id, $sql, 'id','display_description',
	array(
		'spec_option' => $none_option,
		'spec_id' => ALL_NUMERIC,
		'select_submit'=> $submit_on_change,
		'async' => false,
	) );
}

function vehicle_packages_list_cells($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo vehicle_packages_list($name, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function vehicle_packages_list_row($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	vehicle_packages_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}


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

function vehicle_requests_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	$sql = "SELECT vr.id, vp.description, vr.from_date_time, vr.to_date_time  
                FROM ".TB_PREF."vehicle_requests vr, "
                        .TB_PREF."vehicle_packages vp  
                WHERE  vr.package_id = vp.id  
                        AND vr.closed = 0 AND approval_status = ".AS_APPROVED;

	return combo_input($name, $selected_id, $sql, 'vr.id','vr.package_id',
	array(
        'format' => '_format_vehicle_request',
		'spec_option' => $none_option,
		'spec_id' => ALL_NUMERIC,
		'select_submit'=> $submit_on_change,
		'async' => false,
        'order' => array('vr.from_date_time')
	) );
}


function _format_vehicle_request($row)
{
	return $row[1]." (from ". substr($row[2],0,16)." - to ".substr($row[3],0,16).")";
}


function vehicle_requests_list_cells($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo vehicle_requests_list($name, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function vehicle_requests_list_row($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	vehicle_requests_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}


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

function vehicle_allocations_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	$sql = "SELECT va.id, vp.description, va.from_date_time, va.to_date_time, u.real_name   
                FROM ".TB_PREF."vehicle_allocations va, "
                        .TB_PREF."vehicle_packages vp, "
                        .TB_PREF."users u 
                WHERE  va.package_id = vp.id  
                        AND va.closed = 0 
                        AND va.created_by = u.id ";

	return combo_input($name, $selected_id, $sql, 'va.id','va.vehicle_type_id',
	array(
        'format' => '_format_vehicle_allocation',
		'spec_option' => $none_option,
		'spec_id' => ALL_NUMERIC,
		'select_submit'=> $submit_on_change,
		'async' => false,
        'order' => array('va.from_date_time')
	) );
}


function _format_vehicle_allocation($row)
{
	return $row[0]." - ".$row[1]." - ".$row[4]." (from ". substr($row[2],0,16)." - to ".substr($row[3],0,16).")";
}


function vehicle_allocations_list_cells($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo vehicle_allocations_list($name, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function vehicle_allocations_list_row($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	vehicle_allocations_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}

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

function asset_depreciation_run_list($name, $selected_id=null, $none_option=false, $submit_on_change=false, $approved = null)
{
	$sql = "SELECT id, CONCAT(period_end_date, ' - ',description, ' (',id, ')') abc  
                FROM ".TB_PREF."asset_depreciation_runs 
                WHERE ";

    if($approved === 1){
        //$sql .= "status IN('R')";
        $sql .= "status IN('N','U','C','L','S','R')";
    }
    elseif($approved === 0){
        $sql .= "status IN('N','U','C','L','S')";
    }
    else{
        $sql .= " 1 ";
    }

	return combo_input($name, $selected_id, $sql, 'id', 'abc',
	array(
		'spec_option' => $none_option,
		'spec_id' => ALL_NUMERIC,
		'select_submit'=> $submit_on_change,
		'async' => false,
	) );
}

function asset_depreciation_run_list_cells($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false, $approved = null)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo asset_depreciation_run_list($name, $selected_id, $none_option, $submit_on_change, $approved);
	echo "</td>\n";
}


function asset_depreciation_run_list_row($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false, $approved = null)
{
	echo "<tr><td class='label'>$label</td>";
	asset_depreciation_run_list_cells(null, $name, $selected_id, $none_option, $submit_on_change, $approved);
	echo "</tr>\n";
}
//--------------------------------------------------------------------------

function supplier_types_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	global $supplier_types;
		
	echo array_selector($name, $selected_id, $supplier_types, 
		array( 
			'select_submit'=> $submit_on_change
			) );
}

function supplier_types_list_cells($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo supplier_types_list($name, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function supplier_types_list_row($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	supplier_types_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}

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


function credit_facilities_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	$sql = "SELECT id, name  "
                . "FROM ".TB_PREF."credit_facilities ";

	return combo_input($name, $selected_id, $sql, 'id','name',
	array(
		'spec_option' => $none_option,
		'spec_id' => ALL_NUMERIC,
		'select_submit'=> $submit_on_change,
		'async' => false,
	) );
}

function credit_facilities_list_cells($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo credit_facilities_list($name, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function credit_facilities_list_row($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	credit_facilities_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}

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

function bonds_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	$sql = "SELECT id, description  "
                . "FROM ".TB_PREF."bonds ";

	return combo_input($name, $selected_id, $sql, 'id','description',
	array(
		'spec_option' => $none_option,
		'spec_id' => ALL_NUMERIC,
		'select_submit'=> $submit_on_change,
		'async' => false,
	) );
}

function bonds_list_cells($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo bonds_list($name, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function bonds_list_row($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	bonds_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}

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

function insured_items_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	$sql = "SELECT id, name  "
                . "FROM ".TB_PREF."insured_items ";

	return combo_input($name, $selected_id, $sql, 'id','name',
	array(
		'spec_option' => $none_option,
		'spec_id' => ALL_NUMERIC,
		'select_submit'=> $submit_on_change,
		'async' => false,
	) );
}

function insured_items_list_cells($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo insured_items_list($name, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function insured_items_list_row($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	credit_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}

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


function company_loans_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	$sql = "SELECT id, description  "
                . "FROM ".TB_PREF."company_loans ";

	return combo_input($name, $selected_id, $sql, 'id','description',
	array(
		'spec_option' => $none_option,
		'spec_id' => ALL_NUMERIC,
		'select_submit'=> $submit_on_change,
		'async' => false,
	) );
}

function company_loans_list_cells($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo company_loans_list($name, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function company_loans_list_row($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	company_loans_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}

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


function petty_cash_floats_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	$sql = "SELECT id, name  "
                . "FROM ".TB_PREF."petty_cash_floats ";

	return combo_input($name, $selected_id, $sql, 'id','name',
	array(
		'spec_option' => $none_option,
		'spec_id' => ALL_NUMERIC,
		'select_submit'=> $submit_on_change,
		'async' => false,
	) );
}

function petty_cash_floats_list_cells($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo petty_cash_floats_list($name, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function petty_cash_floats_list_row($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	petty_cash_floats_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}

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

function project_list1($name, $selected_id=null, $spec_option=false, $submit_on_change=false)
{
//function tasks_list($name, $project_id, $selected_id=null, $all_option=false, $submit_on_change=false)
//{
    $user_id = $_SESSION['wa_current_user']->user;
    
    $sql = "SELECT project_id, project_code, value_name, description, project_name  
            FROM ".TB_PREF."projects_master pm 
                    INNER JOIN ".TB_PREF."user_data_access_groups udag ON
                            pm.dag_id = udag.dag_id  
                    LEFT JOIN ".TB_PREF."list_values lv ON 
                            pm.department_id = lv.id 
            WHERE pm.inactive = 0 AND udag.user_id =".$user_id;

	global $all_items;
    $opts = array();
    $editkey = null;
    $mode = 0;
    $show_inactive = 0;

	$ret = combo_input($name, $selected_id, $sql, 'project_code', 'description',
	array(
	    'format' => '_format_projects',
	    'order' => array('value_name', 'pm.description'),
        'search' => array( "project_name", "project_code","description", "value_name"),
		'search_box' => $mode != 0,
		'type' => 1,
		'size' => 20,
        'category' => 2,
		'spec_option' => $spec_option === true ? _("All Projects") : $spec_option,
		'spec_id' => $all_items,
		'select_submit'=> $submit_on_change,
		'async' => false,
		'sel_hint' => $mode ? _('Press Space tab to filter by name fragment') :
		_('Select a Project'),
		'show_inactive' => $show_inactive
	) );
	if ($editkey)
		$ret .= add_edit_combo('customer');
	return $ret;

	  
}

function project_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
{
	$user_id = $_SESSION['wa_current_user']->user;
    
    $sql = "SELECT project_id, project_code, value_name, description, project_name  
            FROM ".TB_PREF."projects_master pm 
                    INNER JOIN ".TB_PREF."user_data_access_groups udag ON
                            pm.dag_id = udag.dag_id  
                    LEFT JOIN ".TB_PREF."list_values lv ON 
                            pm.department_id = lv.id 
            WHERE pm.inactive = 0 AND udag.user_id =".$user_id;

    global $all_items;
    $opts = array();
    $editkey = null;
    $mode = 0;
    $show_inactive = 0;
    
    $ret = combo_input($name, $selected_id, $sql, 'pm.project_id', 'pm.description',
    array_merge(
      array(
            'format' => '_format_projects',
            'spec_option' => $all_option===true ?  _("All Items") : $all_option,
            'spec_id' => $all_items,
            'search_box' => true,
            'search' => array("project_id", "description", "value_name"),
            'search_submit' => true,
            'size'=>10,
            'select_submit'=> $submit_on_change,
            'category' => 2,
            'order' => array('value_name', 'pm.description')
      ), $opts) );
    
    if ($editkey){
            //$ret .= add_edit_combo('item');	
            $ret .= add_edit_combo('item');
    }
    
    if(isset($opts['where'])){
        $search = viewer_link('', 'projects/manage/projects_list.php?popup=1&parent='.$name, '', '',  ICON_VIEW);
    }
    else{
        $search = viewer_link('', 'projects/manage/projects_list.php?popup=1&parent='.$name, '', '',  ICON_VIEW);
    }
    
    $pos = strpos($ret, '</td>', 0);
    $ret = substr_replace($ret, $search, $pos, 0);
    
	return $ret;

	  
}


function _format_projects($row)
{
	return ($row[3] . " - (".$row[0].") - ". $row[1]);
}


function project_list_cells($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo project_list($name, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
        
//        if(isset($_POST["_".$name."_edit"]) && $_POST["_".$name."_edit"] > 0){
//            $_POST[$name] = $_POST["_".$name."_edit"];
//        }
}

function project_list_row($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	project_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}
//---------------------------------------------------------------------------------------------------


function project_boq_item_groups_list($name, $project_id, $selected_id=null,
	$none_option=false, $submit_on_change=false)
{
	$sql = "SELECT id, CONCAT(code, ' - ' ,description) xyz, depth 
               FROM ".TB_PREF."project_boq_item_groups
                WHERE project_id=". db_escape($project_id);                  
        

	return combo_input($name, $selected_id, $sql, 'id', 'xyz',
	array(
//		'order' => 'id',
        'format' => '_format_boq_item_groups',
		'spec_option' => $none_option,
		'spec_id' => ALL_NUMERIC,
		'select_submit'=> $submit_on_change,
		'async' => false,
        'order' => array('position'),
	) );
}

function _format_boq_item_groups($row)
{
	return spaces(5*($row[2]-1)).$row[1];
}

function project_boq_item_groups_list_cells($label, $name, $project_id, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo project_boq_item_groups_list($name, $project_id, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function project_boq_item_groups_list_row($label, $name, $project_id, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	project_boq_item_groups_list_cells(null, $name, $project_id, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}


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

function project_invoicing_item_gropus_list($name, $project_id, $selected_id=null,
	$none_option=false, $submit_on_change=false)
{
	$sql = "SELECT id, description FROM ".TB_PREF."project_invoicing_items
                WHERE type = 1 AND
                      project_id=". db_escape($project_id);                  
        

	return combo_input($name, $selected_id, $sql, 'id', 'description',
	array(
		'order' => 'id',
		'spec_option' => $none_option,
		'spec_id' => ALL_NUMERIC,
		'select_submit'=> $submit_on_change,
		'async' => false,
	) );
}

function project_invoicing_item_gropus_list_cells($label, $name, $project_id, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo project_invoicing_item_gropus_list($name, $project_id, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function project_invoicing_item_gropus_list_row($label, $name, $project_id, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	project_invoicing_item_gropus_list_cells(null, $name, $project_id, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}

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



function project_billing_types_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	global $project_billing_types;
		
	echo array_selector($name, $selected_id, $project_billing_types, 
		array( 
			'select_submit'=> $submit_on_change,
            'spec_option' => $none_option 
			) );
}

function project_billing_types_list_cells($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo project_billing_types_list($name, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function project_billing_types_list_row($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	project_billing_types_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}

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

function vehicles_list($name, $selected_id=null, $none_option=false, $submit_on_change=false, $own_vehicles_only = false)
{
	$sql = "SELECT id, CONCAT(plate_number, ' - ', description) description 
            FROM ".TB_PREF."vehicles ";
    
    if($own_vehicles_only){
        $sql .= " WHERE hired = 0";
    }

	return combo_input($name, $selected_id, $sql, 'id', 'description',
	array(
		'spec_option' => $none_option,
		'spec_id' => ALL_NUMERIC,
		'select_submit'=> $submit_on_change,
		'async' => false,
	) );
}

function vehicles_list_cells($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false, $own_vehicles_only = false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo vehicles_list($name, $selected_id, $none_option, $submit_on_change, $own_vehicles_only);
	echo "</td>\n";
}

function vehicles_list_row($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false, $own_vehicles_only = false)
{
	echo "<tr><td class='label'>$label</td>";
	vehicles_list_cells(null, $name, $selected_id, $none_option, $submit_on_change, $own_vehicles_only);
	echo "</tr>\n";
}

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

function asset_vehicles_list($name, $selected_id=null, $none_option=false, $submit_on_change=false, $own_vehicles_only = false)
{
	$sql = "SELECT asset_id, CONCAT(asset_code, ' - ', description) description 
            FROM ".TB_PREF."asset_master 
            WHERE type = ". db_escape("V");
    
    if($own_vehicles_only){
        $sql .= " WHERE is_hired = 0";
    }

	return combo_input($name, $selected_id, $sql, 'asset_id', 'description',
	array(
		'spec_option' => $none_option,
		'spec_id' => ALL_NUMERIC,
		'select_submit'=> $submit_on_change,
		'async' => false,
	) );
}

function asset_vehicles_list_cells($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false, $own_vehicles_only = false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo asset_vehicles_list($name, $selected_id, $none_option, $submit_on_change, $own_vehicles_only);
	echo "</td>\n";
}

function asset_vehicles_list_row($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false, $own_vehicles_only = false)
{
	echo "<tr><td class='label'>$label</td>";
	asset_vehicles_list_cells(null, $name, $selected_id, $none_option, $submit_on_change, $own_vehicles_only);
	echo "</tr>\n";
}

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


function drivers_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	$sql = "SELECT id, name FROM ".TB_PREF."drivers ";

	return combo_input($name, $selected_id, $sql, 'id', 'name',
	array(
		'spec_option' => $none_option,
		'spec_id' => ALL_NUMERIC,
		'select_submit'=> $submit_on_change,
		'async' => false,
	) );
}

function drivers_list_cells($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo drivers_list($name, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function drivers_list_row($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	drivers_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}

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


function project_invoicing_items_list($name, $project_id, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	$sql = "SELECT id, code 
                FROM ".TB_PREF."project_invoicing_items 
                WHERE project_id=".db_escape($project_id)." AND type = 0";                               

	return combo_input($name, $selected_id, $sql, 'id', 'code',
	array(
		'order' => 'display_order',
        'spec_option' => $none_option,
		'spec_id' => ALL_NUMERIC,
		'select_submit'=> $submit_on_change,
		'async' => false,
	) );
}

function project_invoicing_items_list_cells($label, $name, $project_id, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo project_invoicing_items_list($name, $project_id, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function project_invoicing_items_list_row($label, $name, $project_id, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	project_invoicing_items_list_cells(null, $name, $project_id, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}


function vehicle_type_packages_packages_list($name, $vehicle_type, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	$sql = "SELECT id, CONCAT(description,' (Rs.',cost,')') display_description  "
                . "FROM ".TB_PREF."vehicle_packages WHERE 1 ";
        if($vehicle_type != '-1')
        {
            $sql .= " AND vehicle_type_id =".$vehicle_type;
        }
//WHERE $vehicle_type
	return combo_input($name, $selected_id, $sql, 'id','display_description',
	array(
		'spec_option' => $none_option,
		'spec_id' => ALL_NUMERIC,
		'select_submit'=> $submit_on_change,
		'async' => false,
	) );
}

function vehicle_type_packages_list_cells($label, $name,$vehicle_type, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo vehicle_type_packages_packages_list($name,$vehicle_type, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function vehicle_type_packages_list_row($label, $name, $vehicle_type, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	vehicle_type_packages_list_cells(null, $name, $vehicle_type,$selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}



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

function vehicle_type_vehicles_list($name, $vehicle_type, $selected_id=null, $none_option=false, $submit_on_change=false, $own_vehicles_only = false)
{
	$sql = "SELECT id, CONCAT(plate_number, ' - ', description) description 
            FROM ".TB_PREF."vehicles WHERE 1";
        if($vehicle_type != '-1')
        {
            $sql .= " AND vehicle_type =".$vehicle_type;
        }
    // WHERE $vehicle_type
    if($own_vehicles_only){
        $sql .= " WHERE hired = 0";
    }

	return combo_input($name, $selected_id, $sql, 'id', 'description',
	array(
		'spec_option' => $none_option,
		'spec_id' => ALL_NUMERIC,
		'select_submit'=> $submit_on_change,
		'async' => false,
	) );
}

function vehicle_type_vehicles_list_cells($label, $name,$vehicle_type, $selected_id=null, $none_option=false,
	$submit_on_change=false, $own_vehicles_only = false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo vehicle_type_vehicles_list($name,$vehicle_type, $selected_id, $none_option, $submit_on_change, $own_vehicles_only);
	echo "</td>\n";
}

function vehicle_type_vehicles_list_row($label, $name, $vehicle_type, $selected_id=null, $none_option=false,
	$submit_on_change=false, $own_vehicles_only = false)
{
	echo "<tr><td class='label'>$label</td>";
	vehicle_type_vehicles_list_cells(null, $name, $vehicle_type, $selected_id, $none_option, $submit_on_change, $own_vehicles_only);
	echo "</tr>\n";
}


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



function asset_groups_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	$sql = "SELECT id, description, inactive FROM ".TB_PREF."asset_groups";

// default to the company currency
return combo_input($name, $selected_id, $sql, 'id', 'description',
	array(
        'spec_option' => $none_option,
		'select_submit'=> $submit_on_change,
		'async' => false
	) );
}

function asset_groups_list_cells($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo asset_groups_list($name, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function asset_groups_list_row($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	asset_groups_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}

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

function customer_types_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	global $customer_types;
		
	echo array_selector($name, $selected_id, $customer_types, 
		array( 
			'select_submit'=> $submit_on_change
			) );
}

function customer_types_list_cells($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo customer_types_list($name, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function customer_types_list_row($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	customer_types_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}


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


function project_invoice_line_types_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	global $project_invoice_line_types;
		
	echo array_selector($name, $selected_id, $project_invoice_line_types, 
		array( 
			'select_submit'=> $submit_on_change
			) );
}

function project_invoice_line_types_list_cells($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo project_invoice_line_types_list($name, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function project_invoice_line_types_list_row($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	project_invoice_line_types_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}


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



function project_payment_applications_list($name, $project_id, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	$sql = "SELECT order_no, CONCAT(order_no, ' - ', total, ' (', ord_date, ')') pa_details 
            FROM ".TB_PREF."project_payment_applications 
            WHERE project_id = ". db_escape($project_id);

// default to the company currency
return combo_input($name, $selected_id, $sql, 'order_no', 'pa_details',
	array(
        'spec_option' => $none_option,
		'select_submit'=> $submit_on_change,
		'default' => 1,
		'async' => false
	) );
}

function project_payment_applications_list_cells($label, $name, $project_id, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo project_payment_applications_list($name, $project_id, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function project_payment_applications_list_row($label, $name, $project_id, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	project_payment_applications_list_cells(null, $name, $project_id, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}

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

function project_boq_item_primary_types_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	global $project_boq_item_component_primary_types;
		
	return array_selector($name, $selected_id, $project_boq_item_component_primary_types, 
		array( 
			'select_submit'=> $submit_on_change
			) );
}

function project_boq_item_primary_types_list_cells($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo project_boq_item_primary_types_list($name, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function project_boq_item_primary_types_list_row($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	project_boq_item_primary_types_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}

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

function asset_subgroups_list($name, $asset_group_id, $selected_id=null, $none_option=false, $submit_on_change=false)
{
     $sql = "SELECT id, description  
             FROM ".TB_PREF."asset_subgroups 
            WHERE group_id = ".db_escape($asset_group_id);

	return combo_input($name, $selected_id, $sql, 'id', 'description',
	array(
		'spec_option' => $none_option,
		'spec_id' => ALL_NUMERIC,
		'select_submit'=> $submit_on_change,
		'async' => false,
	    ) );

}

function asset_subgroups_list_cells($label, $name, $asset_group_id, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
   
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo asset_subgroups_list($name, $asset_group_id, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function asset_subgroups_list_row($label, $name, $asset_group_id, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	asset_subgroups_list_cells(null, $name, $asset_group_id, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}

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


function group_boq_items_list($name, $project_id, $boq_group_id, $selected_id=null,
	$none_option=false, $submit_on_change=false)
{
    if(!($boq_group_id>0)){
        $boq_group_id = 0;
    }
    
	$sql = "SELECT id, CONCAT(code, ' - ' ,description) xyz
               FROM ".TB_PREF."project_boq_items
                WHERE project_id=". db_escape($project_id)." AND 
                        group_id=". db_escape($boq_group_id);                          
        

	return combo_input($name, $selected_id, $sql, 'id', 'xyz',
	array(
		'order' => 'code',
		'spec_option' => $none_option,
		'spec_id' => ALL_NUMERIC,
		'select_submit'=> $submit_on_change,
		'async' => false,
        'order' => array('code'),
	) );
}

function group_boq_items_list_cells($label, $name, $project_id, $boq_group_id, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo group_boq_items_list($name, $project_id, $boq_group_id, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function group_boq_items_list_row($label, $name, $project_id, $boq_group_id, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	group_boq_items_list_cells(null, $name, $project_id, $boq_group_id, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}


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



function group_task_groups_list($name, $project_id, $boq_group_id, $selected_id=null,
	$none_option=false, $submit_on_change=false)
{
	$sql = "SELECT id, CONCAT(code, ' - ' ,description) xyz
               FROM ".TB_PREF."project_task_groups 
                WHERE project_id=". db_escape($project_id)." AND 
                        boq_group_id =". db_escape($boq_group_id);                          
        

	return combo_input($name, $selected_id, $sql, 'id', 'xyz',
	array(
		'spec_option' => $none_option,
		'spec_id' => ALL_NUMERIC,
		'select_submit'=> $submit_on_change,
		'async' => false,
        'order' => array('code'),
	) );
}

function group_task_groups_list_cells($label, $name, $project_id, $boq_group_id, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo group_task_groups_list($name, $project_id, $boq_group_id, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function group_task_groups_list_row($label, $name, $project_id, $boq_group_id, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	group_task_groups_list_cells(null, $name, $project_id, $boq_group_id, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}


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


function credit_facility_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	$sql = "SELECT id, name  "
                . "FROM ".TB_PREF."credit_facilities ";

	return combo_input($name, $selected_id, $sql, 'id','name',
	array(
		'spec_option' => $none_option,
		'spec_id' => ALL_NUMERIC,
		'select_submit'=> $submit_on_change,
		'async' => false,
	) );
}

function credit_facility_list_cells($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo credit_facility_list($name, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function credit_facility_list_row($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	credit_facility_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}

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



function credit_facility_bank_accounts_list($name, $credit_facility_id, $selected_id=null, $submit_on_change=false, $spec_option=false)
{
	$sql = "SELECT cfs.id, 
                        CONCAT(ba.bank_account_name,' - ',bnk.value_name) acc_full_name, ba.bank_curr_code, ba.inactive
                    
                FROM ".TB_PREF."credit_facility_sublimits cfs 
                    
                        INNER JOIN ".TB_PREF."bank_accounts ba ON 
                            cfs.bank_account_id = ba.id
                      
                       LEFT JOIN ".TB_PREF."list_values bnk ON 
                            ba.bank_id = bnk.id
                            
                WHERE cfs.credit_facility_id=".db_escape($credit_facility_id);

	return combo_input($name, $selected_id, $sql, 'cfs.id', 'acc_full_name',
	array(
		'format' => '_format_add_curr',
		'select_submit'=> $submit_on_change,
		'spec_option' => $spec_option,
		'spec_id' => '',
		'async' => false
            ));
}

function credit_facility_bank_accounts_list_cells($label, $name, $credit_facility_id, $selected_id=null, $submit_on_change=false, $none_option=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo credit_facility_bank_accounts_list($name, $credit_facility_id, $selected_id, $submit_on_change,$none_option);
	echo "</td>\n";
}

function credit_facility_bank_accounts_list_row($label, $name, $credit_facility_id, $selected_id=null, $submit_on_change=false,$none_option=false)
{
	echo "<tr><td class='label'>$label</td>";
	credit_facility_bank_accounts_list_cells(null, $name, $credit_facility_id, $selected_id, $submit_on_change, $none_option);
	echo "</tr>\n";
}

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

function insuree_types_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	global $insuree_types;
		
	return array_selector($name, $selected_id, $insuree_types, 
		array( 
			'select_submit'=> $submit_on_change
			) );
}

function insuree_types_list_cells($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo insuree_types_list($name, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function insuree_types_list_row($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	insuree_types_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}


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


function project_pa_boq_item_groups_list($name, $project_id, $pa_id, $selected_id=null,
	$none_option=false, $submit_on_change=false)
{
	$sql = "SELECT g.id, CONCAT(g.code, ' - ' ,g.description) xyz, g.depth, pag.boq_group_id pa_boq_group_id 
               FROM ".TB_PREF."project_boq_item_groups g 
                    LEFT JOIN ".TB_PREF."project_payment_application_boq_item_groups pag ON 
                            g.id = pag.boq_group_id AND 
                            pag.pa_id = ". db_escape($pa_id)." 
                WHERE g.project_id=". db_escape($project_id);                  
        

	return combo_input($name, $selected_id, $sql, 'id', 'xyz',
	array(
//		'order' => 'id',
        'format' => '_format_pa_boq_item_groups',
		'spec_option' => $none_option,
		'spec_id' => ALL_NUMERIC,
		'select_submit'=> $submit_on_change,
		'async' => false,
        'order' => array('position'),
	) );
}

function _format_pa_boq_item_groups($row)
{
    if(isset($row['pa_boq_group_id']) && $row['pa_boq_group_id'] > 0){
        return spaces(5*($row[2]-1)).$row[1];
    }
    else{
        return spaces(5*($row[2]-1))."____".$row[1];
    }
	
}

function project_pa_boq_item_groups_list_cells($label, $name, $project_id, $pa_id, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo project_pa_boq_item_groups_list($name, $project_id, $pa_id, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function project_pa_boq_item_groups_list_row($label, $name, $project_id, $pa_id, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	project_pa_boq_item_groups_list_cells(null, $name, $project_id, $pa_id, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}

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


function project_sales_orders_list($name, $project_id, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	$sql = "SELECT order_no, CONCAT(order_no, ' - ', po_reference, ' - ', total) pso_details 
            FROM ".TB_PREF."project_sales_orders 
            WHERE project_id = ". db_escape($project_id);

// default to the company currency
return combo_input($name, $selected_id, $sql, 'order_no', 'pso_details',
	array(
        'spec_option' => $none_option,
		'select_submit'=> $submit_on_change,
		'default' => 1,
		'async' => false
	) );
}

function project_sales_orders_list_cells($label, $name, $project_id, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo project_sales_orders_list($name, $project_id, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function project_sales_orders_list_row($label, $name, $project_id, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	project_sales_orders_list_cells(null, $name, $project_id, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}

//-----------------------------------------------------------------------------------------------
function supplier_invoice_source_types_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
{
	global $supplier_invoice_source_types;

	//echo "<tr>";
//	if ($label != null)
//		echo "<td class='label'>$label</td>\n";
	//echo "<td>";

	echo array_selector($name, $selected_id, $supplier_invoice_source_types, 
		array( 
                'spec_option' => $all_option,
                'select_submit'=> $submit_on_change) );
	//echo "</td>\n";
}

function supplier_invoice_source_types_list_cells($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo supplier_invoice_source_types_list($name, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function supplier_invoice_source_types_list_row($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	supplier_invoice_source_types_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}



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


function supplier_transport_invoices_list($name, $supplier_id, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	$sql = "SELECT id, CONCAT(id, ' - ',tran_date, ' - ', supp_inv_ref, ' - ', total) sti_details 
            FROM ".TB_PREF."supplier_transport_invoices 
            WHERE supplier_id = ". db_escape($supplier_id);

// default to the company currency
return combo_input($name, $selected_id, $sql, 'id', 'sti_details',
	array(
        'spec_option' => $none_option,
		'select_submit'=> $submit_on_change,
		'default' => 1,
		'async' => false
	) );
}

function supplier_transport_invoices_list_cells($label, $name, $supplier_id, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo supplier_transport_invoices_list($name, $supplier_id, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function supplier_transport_invoices_list_row($label, $name, $supplier_id, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	supplier_transport_invoices_list_cells(null, $name, $supplier_id, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}

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

function direct_petty_cash_payment_expense_sources_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
{
	global $direct_petty_cash_payment_expense_sources;

	//echo "<tr>";
//	if ($label != null)
//		echo "<td class='label'>$label</td>\n";
	//echo "<td>";

	echo array_selector($name, $selected_id, $direct_petty_cash_payment_expense_sources, 
		array( 
                'spec_option' => $all_option,
                'select_submit'=> $submit_on_change) );
	//echo "</td>\n";
}

function direct_petty_cash_payment_expense_sources_list_cells($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo direct_petty_cash_payment_expense_sources_list($name, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function direct_petty_cash_payment_expense_sources_list_row($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	direct_petty_cash_payment_expense_sources_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}



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

function system_payment_types_list_cells($label, $name, $value=null, $submit_on_change=false)
{
	global $system_payment_types;

	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";

//	$items = $systypes_array;
//
//	// exclude quotes, orders and dimensions
//	foreach (array(ST_PURCHORDER, ST_SALESORDER, ST_DIMENSION, ST_SALESQUOTE, ST_LOCTRANSFER) as $excl)
//			unset($items[$excl]);
	
	echo array_selector($name, $value, $system_payment_types, 
		array( 
			'spec_option'=> _("All"),
			'spec_id' => -1,
			'select_submit'=> $submit_on_change,
			'async' => false
			)
	);
	echo "</td>\n";
}



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



function fixed_deposit_security_type_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
{
	global $fixed_deposit_security_type;

	//echo "<tr>";
//	if ($label != null)
//		echo "<td class='label'>$label</td>\n";
	//echo "<td>";

	echo array_selector($name, $selected_id, $fixed_deposit_security_type, 
		array( 
                'spec_option' => $all_option,
                'select_submit'=> $submit_on_change) );
	//echo "</td>\n";
}

function fixed_deposit_security_type_list_cells($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo fixed_deposit_security_type_list($name, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function fixed_deposit_security_type_list_row($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	fixed_deposit_security_type_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}


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


function stock_count_sheets_list($name, $stock_count_id, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	$sql = "SELECT DISTINCT sheet_no, sheet_no   
            FROM ".TB_PREF."stock_count_details  
            WHERE stock_count_no = ". db_escape($stock_count_id);

// default to the company currency
return combo_input($name, $selected_id, $sql, 'sheet_no', 'sheet_no',
	array(
        'spec_option' => $none_option,
		'select_submit'=> $submit_on_change,
		'default' => 1,
		'async' => false
	) );
}

function stock_count_sheets_list_cells($label, $name, $stock_count_id, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo stock_count_sheets_list($name, $stock_count_id, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function stock_count_sheets_list_row($label, $name, $stock_count_id, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	stock_count_sheets_list_cells(null, $name, $stock_count_id, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}

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


function unpaid_vehicle_running_chart_entries_list($name, $supplier_id, $selected_id=null, $none_option=false, $submit_on_change=false)
{
    $sql = "SELECT vr.id, CONCAT(vr.id, ' - ', vh.description, ' - ', vr.plate_no, ' - ', vr.start_date_time, ' - ', vr.route) uvrc_details  
            FROM ".TB_PREF."vehicle_running_chart vr 
                    JOIN ".TB_PREF."vehicles vh ON 
                            vr.vehicle_id = vh.id 
            WHERE vr.supplier_id = ".db_escape($supplier_id)." AND 
                    vr.batch_no > 0 AND vr.inv_no = 0 AND vr.payment_source_no = 0";
            
            
// default to the company currency
    return combo_input($name, $selected_id, $sql, 'id', 'uvrc_details',
                        array(
                            'spec_option' => $none_option,
                            'select_submit'=> $submit_on_change,
                            'default' => 1,
                            'async' => false,
                            'order' => array('vh.description') 
                        ) 
            );
}

function unpaid_vehicle_running_chart_entries_list_cells($label, $name, $supplier_id, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo unpaid_vehicle_running_chart_entries_list($name, $supplier_id, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function unpaid_vehicle_running_chart_entries_list_row($label, $name, $supplier_id, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	unpaid_vehicle_running_chart_entries_list_cells(null, $name, $supplier_id, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}

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


function advance_paid_vehicle_allocations_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
{            
    $sql = "SELECT va.id, CONCAT(va.id, ' - ', vh.description, ' - ', DATE_FORMAT(va.from_date_time, '%Y %m %d %k:%i'), ' - ', va.route, ' - ', paid_amount) va_details   
            FROM  ".TB_PREF."vehicle_allocations AS va 
                    JOIN ".TB_PREF."vehicles AS vh ON 
                           va.vehicle_id = vh.id 
            WHERE va.payment_source_no > 0 AND 
                    va.transport_inv_no = 0 AND va.settled_vrc_entry_no = 0";
    
            
// default to the company currency
    return combo_input($name, $selected_id, $sql, 'id', 'va_details',
                        array(
                            'spec_option' => $none_option,
                            'select_submit'=> $submit_on_change,
                            'default' => 1,
                            'async' => false,
                            'order' => array('vh.description', 'va.from_date_time', 'va.paid_amount') 
                        ) 
            );
}

function advance_paid_vehicle_allocations_list_cells($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo advance_paid_vehicle_allocations_list($name, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function advance_paid_vehicle_allocations_list_row($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	advance_paid_vehicle_allocations_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}

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

function unpaid_vehicle_allocations_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	$sql = "SELECT va.id, vp.description, va.from_date_time, va.to_date_time, u.real_name   
                FROM ".TB_PREF."vehicle_allocations va, "
                        .TB_PREF."vehicle_packages vp, "
                        .TB_PREF."users u 
                WHERE  va.package_id = vp.id  
                        AND va.closed = 0 
                        AND va.payment_source_no = 0 
                        AND va.created_by = u.id ";

	return combo_input($name, $selected_id, $sql, 'va.id','va.vehicle_type_id',
	array(
        'format' => '_format_unpaid_vehicle_allocation',
		'spec_option' => $none_option,
		'spec_id' => ALL_NUMERIC,
		'select_submit'=> $submit_on_change,
		'async' => false,
        'order' => array('va.from_date_time')
	) );
}


function _format_unpaid_vehicle_allocation($row)
{
	return $row[0]." - ".$row[1]." - ".$row[4]." (from ". substr($row[2],0,16)." - to ".substr($row[3],0,16).")";
}


function unpaid_vehicle_allocations_list_cells($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo unpaid_vehicle_allocations_list($name, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function unpaid_vehicle_allocations_list_row($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	unpaid_vehicle_allocations_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}

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

function order_categories_list($name, $tran_type, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	$sql = "SELECT id, name   
                FROM ".TB_PREF."order_categories                        
                WHERE type = ". db_escape($tran_type);

	return combo_input($name, $selected_id, $sql, 'id','name',
	array(
		'spec_option' => $none_option,
		'spec_id' => ALL_NUMERIC,
		'select_submit'=> $submit_on_change,
		'async' => false,
        'order' => array('display_order', 'name')
	) );
}

function order_categories_list_cells($label, $name, $tran_type, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo order_categories_list($name, $tran_type, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function order_categories_list_row($label, $name, $tran_type, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	order_categories_list_cells(null, $name, $tran_type, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}

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

function order_category_types_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
{
	global $order_category_types;

	//echo "<tr>";
//	if ($label != null)
//		echo "<td class='label'>$label</td>\n";
	//echo "<td>";

	echo array_selector($name, $selected_id, $order_category_types, 
		array( 
                'spec_option' => $all_option,
                'select_submit'=> $submit_on_change));
	//echo "</td>\n";
}

function order_category_types_list_cells($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo order_category_types_list($name, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function order_category_types_list_row($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	order_category_types_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}



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

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



function tool_rate_category_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	$sql = "SELECT id, description FROM ".TB_PREF."tool_rates ";

// default to the company currency
return combo_input($name, $selected_id, $sql, 'id', 'description',
	array(
        'spec_option' => $none_option,
		'select_submit'=> $submit_on_change,
		'async' => false
	) );
}

function tool_rate_category_list_cells($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo tool_rate_category_list($name, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function tool_rate_category_list_row($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	tool_rate_category_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}


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



function grn_non_stock_items_list($name, $grn_no, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	$sql = "SELECT grni.id, CONCAT(sm.stock_id,' - ', sm.description) item_description 
            FROM ".TB_PREF."grn_items grni 
                    JOIN ".TB_PREF."stock_master sm ON 
                            grni.item_code = sm.stock_id 
            WHERE grni.grn_batch_id = ".db_escape($grn_no);

// default to the company currency
return combo_input($name, $selected_id, $sql, 'grni.id', 'item_description',
	array(
        'spec_option' => $none_option,
		'select_submit'=> $submit_on_change,
		'async' => false
	) );
}

function grn_non_stock_items_list_cells($label, $name, $grn_no, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo grn_non_stock_items_list($name, $grn_no, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function grn_non_stock_items_list_row($label, $name, $grn_no, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	grn_non_stock_items_list_cells(null, $name, $grn_no, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}

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

function project_sales_order_item_types_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
{
	global $project_sales_order_item_types;

	//echo "<tr>";
//	if ($label != null)
//		echo "<td class='label'>$label</td>\n";
	//echo "<td>";

	echo array_selector($name, $selected_id, $project_sales_order_item_types, 
		array( 
                'spec_option' => $all_option,
                'select_submit'=> $submit_on_change));
	//echo "</td>\n";
}

function project_sales_order_item_types_list_cells($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo project_sales_order_item_types_list($name, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function project_sales_order_item_types_list_row($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	project_sales_order_item_types_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}


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



function utility_expense_types_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	$sql = "SELECT id, description 
            FROM ".TB_PREF."utility_expense_types";

// default to the company currency
return combo_input($name, $selected_id, $sql, 'id', 'description',
	array(
        'spec_option' => $none_option,
		'select_submit'=> $submit_on_change,
		'async' => false
	) );
}

function utility_expense_types_list_cells($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo utility_expense_types_list($name, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function utility_expense_types_list_row($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	utility_expense_types_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}

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


function group_tasks_list($name, $project_id, $boq_group_id, $selected_id=null,
	$none_option=false, $submit_on_change=false)
{
    if(!($boq_group_id>0)){
        $boq_group_id = 0;
    } 
        
        $sql = "SELECT pt.task_id, pt.task_code, pt.description, pt.budget, pt.budget_used, pt.budget_allocated 
                FROM ".TB_PREF."project_tasks pt  
                        INNER JOIN ".TB_PREF."project_task_groups tg ON 
                                pt.task_group_id = tg.id 
                    WHERE pt.project_id=". db_escape($project_id)." AND 
                        tg.boq_group_id=". db_escape($boq_group_id);      
        

//        if ($_SESSION["wa_current_user"]->can_access("SA_VIEW_PROJECT_BUDGETS")){
//        $cc = user_view_available_budget();
        if (user_view_available_budget()){
            $format_function = "_format_boq_group_budgets_show_values";
        }
        else{
            $format_function = "_format_boq_group_budgets_hide_values";
        }
        
	return combo_input($name, $selected_id, $sql, 'pt.task_id', 'pt.description',
	array('format' => $format_function,
		'order' => 'pt.task_code',
		'spec_option' => $none_option,
		'spec_id' => ALL_NUMERIC,
		'select_submit'=> $submit_on_change,
		'async' => false,
                'order' => array('pt.task_code'),
	) );
}

function _format_boq_group_budgets_show_values($row)
{
        $budget_available = $row[3] - $row[4] - $row[5];
	return $row[0]." - ".$row[1]." (".number_format($budget_available, 2).") ".$row[2];
}

function _format_boq_group_budgets_hide_values($row)
{
//        $budget_available = $row[3] - $row[4] - $row[5];
	return $row[0]." - ".$row[1]." - ".$row[2];
}

function group_tasks_list_cells($label, $name, $project_id, $boq_group_id, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo group_tasks_list($name, $project_id, $boq_group_id, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function group_tasks_list_row($label, $name, $project_id, $boq_group_id, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	group_tasks_list_cells(null, $name, $project_id, $boq_group_id, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}


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

function subcontractor_invoice_item_types_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
{
	global $subconractor_invoice_item_types;

	//echo "<tr>";
//	if ($label != null)
//		echo "<td class='label'>$label</td>\n";
	//echo "<td>";

	echo array_selector($name, $selected_id, $subconractor_invoice_item_types, 
		array( 
                'spec_option' => $all_option,
                'select_submit'=> $submit_on_change));
	//echo "</td>\n";
}

function subcontractor_invoice_item_types_list_cells($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo subcontractor_invoice_item_types_list($name, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function subcontractor_invoice_item_types_list_row($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	subcontractor_invoice_item_types_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}


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


function supplier_purchase_orders_list($name, $supplier_id, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	$sql = "SELECT po.order_no, CONCAT(po.order_no, ' - ',po.reference, ' - ', po.ord_date, ' - ', po.total, ' - ', pm.description) po_details 
                FROM ".TB_PREF."purch_orders po 
                        JOIN ".TB_PREF."projects_master pm  ON 
                                po.project_id = pm.project_id 
                WHERE supplier_id = ". db_escape($supplier_id);

// default to the company currency
return combo_input($name, $selected_id, $sql, 'order_no', 'po_details',
	array(
        'spec_option' => $none_option,
		'select_submit'=> $submit_on_change,
		'default' => 1,
		'async' => false,
                'order' => 'po.order_no DESC' 
	) );
}

function supplier_purchase_orders_list_cells($label, $name, $supplier_id, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo supplier_purchase_orders_list($name, $supplier_id, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function supplier_purchase_orders_list_row($label, $name, $supplier_id, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	supplier_purchase_orders_list_cells(null, $name, $supplier_id, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}

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

/*
function subcontractor_invoice_list($name, $project_id, $selected_id=null,
                                    $none_option=false, $submit_on_change=false)
{
	$sql = "SELECT order_no, CONCAT(order_no, ' - ', reference, ' - ', ord_date, ' - ', total) description  
               FROM ".TB_PREF."subcontractor_invoices
                WHERE project_id=". db_escape($project_id);                  
        

	return combo_input($name, $selected_id, $sql, 'order_no', 'description',
	array(
		'spec_option' => $none_option,
		'spec_id' => ALL_NUMERIC,
		'select_submit'=> $submit_on_change,
		'async' => false,
        'order' => array('order_no'),
	) );
}


function subcontractor_invoice_list_cells($label, $name, $project_id, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo subcontractor_invoice_list($name, $project_id, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function subcontractor_invoice_list_row($label, $name, $project_id, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	subcontractor_invoice_list_cells(null, $name, $project_id, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}
*/
//-------------------------------------------------------------------------------------------------

function subcontractor_credit_note_item_types_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
{
	global $subconractor_credit_note_item_types;

	//echo "<tr>";
//	if ($label != null)
//		echo "<td class='label'>$label</td>\n";
	//echo "<td>";

	echo array_selector($name, $selected_id, $subconractor_credit_note_item_types, 
		array( 
                'spec_option' => $all_option,
                'select_submit'=> $submit_on_change));
	//echo "</td>\n";
}

function subcontractor_credit_note_item_types_list_cells($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo subcontractor_credit_note_item_types_list($name, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function subcontractor_credit_note_item_types_list_row($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	subcontractor_credit_note_item_types_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}

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

function sc_invoice_details_list($name, $sc_inv_no, $selected_id=null,
                            $none_option=false, $submit_on_change=false)
{
	$sql = "SELECT scid.id, 
                        CONCAT(IF(boqi.description IS NOT NULL, 'BOQ Item: ', 'Text: '),
                        IF(boqi.description IS NOT NULL, CONCAT(boqi.code, ' - ', boqi.description), scid.description),
                        ', Unit: ',
                        scid.unit,
                        ', Qty: ',
                        scid.quantity,
                        ', Rate: ',
                        scid.rate) description  
                        
               FROM ".TB_PREF."subcontractor_invoice_details scid 
                        LEFT JOIN ".TB_PREF."project_boq_items boqi ON 
                                scid.item_id = boqi.id
                WHERE scid.order_no =".db_escape($sc_inv_no);      

	return combo_input($name, $selected_id, $sql, 'scid.id', 'description',
	array(
		'spec_option' => $none_option,
		'spec_id' => ALL_NUMERIC,
		'select_submit'=> $submit_on_change,
		'async' => false,
                'order' => array('scid.id'),
	) );
}


function sc_invoice_details_list_cells($label, $name, $sc_inv_no, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo sc_invoice_details_list($name, $sc_inv_no, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function sc_invoice_details_list_row($label, $name, $sc_inv_no, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	sc_invoice_details_list_cells(null, $name, $sc_inv_no, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}

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

function subcontractor_invoice_list($name, $supplier_id, $project_id = 0, $selected_id=null,
                                    $none_option=false, $submit_on_change=false, $approved_only=false)
{
	$sql = "SELECT order_no, CONCAT(order_no, ' - ', reference, ' - ', ord_date, ' - ', total) description  
                FROM ".TB_PREF."subcontractor_invoices                                  
                WHERE  supplier_id=".db_escape($supplier_id);    
            
            if($project_id > 0){
                $sql .= " AND project_id=".db_escape($project_id);
            }
            
            if($approved_only){
                $sql .= " AND approval_status IN (".AS_APPROVED.")";  
            }              
        

	return combo_input($name, $selected_id, $sql, 'order_no', 'description',
	array(
		'spec_option' => $none_option,
		'spec_id' => ALL_NUMERIC,
		'select_submit'=> $submit_on_change,
		'async' => false,
        'order' => array('order_no'),
	) );
}


function subcontractor_invoice_list_cells($label, $name, $supplier_id, $project_id = 0, $selected_id=null, 
                                            $none_option=false, $submit_on_change=false, $approved_only = false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo subcontractor_invoice_list($name, $supplier_id, $project_id, $selected_id, $none_option, $submit_on_change, $approved_only);
	echo "</td>\n";
}

function subcontractor_invoice_list_row($label, $name, $supplier_id, $project_id = 0, $selected_id=null, 
                                            $none_option=false, $submit_on_change=false, $approved_only = false)
{
	echo "<tr><td class='label'>$label</td>";
	subcontractor_invoice_list_cells(null, $name, $supplier_id, $project_id, $selected_id, $none_option, $submit_on_change, $approved_only);
	echo "</tr>\n";
}

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


function project_invoices_list($name, $project_id, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	$sql = "SELECT order_no, CONCAT(order_no, ' - ', reference, ' - ', ord_date, ' - ', total) description "
                . "FROM ".TB_PREF."project_invoices "
                . "WHERE project_id=".db_escape($project_id);

	return combo_input($name, $selected_id, $sql, 'order_no', 'description',
	array(
		'spec_option' => $none_option,
		'spec_id' => ALL_NUMERIC,
		'select_submit'=> $submit_on_change,
		'async' => false,
	) );
}

function project_invoices_list_cells($label, $name, $project_id, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo project_invoices_list($name, $project_id, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function project_invoices_list_row($label, $name, $project_id, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	project_invoices_list_cells(null, $name, $project_id, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}


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



function material_groups_list($name, $selected_id=null,
	$none_option=false, $submit_on_change=false)
{
	$sql = "SELECT id, CONCAT(code, ' - ', description, ' - ', unit, ' - ', cost) 
                FROM ".TB_PREF."material_groups
                WHERE 1=1";                   
        

	return combo_input($name, $selected_id, $sql, 'id', 'description',
	array(
		'order' => 'id',
		'spec_option' => $none_option,
		'spec_id' => ALL_NUMERIC,
		'select_submit'=> $submit_on_change,
		'async' => false,
	) );
}

function material_groups_list_cells($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo material_groups_list($name, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function material_groups_list_row($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	material_groups_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}


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

function department_project_list($name, $department_id, $selected_id=null, $spec_option=false, $submit_on_change=false)
{
//function tasks_list($name, $project_id, $selected_id=null, $all_option=false, $submit_on_change=false)
//{
    $user_id = $_SESSION['wa_current_user']->user;
    
    $sql = "SELECT project_id, project_code, value_name, description, project_name  
            FROM ".TB_PREF."projects_master pm 
                    INNER JOIN ".TB_PREF."user_data_access_groups udag ON
                            pm.dag_id = udag.dag_id  
                    LEFT JOIN ".TB_PREF."list_values lv ON 
                            pm.department_id = lv.id 
            WHERE pm.inactive = 0 AND udag.user_id =".$user_id." AND pm.department_id =".$department_id;

	global $all_items;
    $opts = array();
    $editkey = null;
    $mode = 0;
    $show_inactive = 0;

	$ret = combo_input($name, $selected_id, $sql, 'project_code', 'description',
	array(
	    'format' => '_format_projects',
	    'order' => array('value_name', 'pm.description'),
        'search' => array( "project_name", "project_code","description", "value_name"),
		'search_box' => $mode != 0,
		'type' => 1,
		'size' => 20,
        'category' => 2,
		'spec_option' => $spec_option === true ? _("All Projects") : $spec_option,
		'spec_id' => $all_items,
		'select_submit'=> $submit_on_change,
		'async' => false,
		'sel_hint' => $mode ? _('Press Space tab to filter by name fragment') :
		_('Select a Project'),
		'show_inactive' => $show_inactive
	) );
	if ($editkey)
		$ret .= add_edit_combo('customer');
	return $ret;

	  
}


function department_project_list_cells($label, $name, $department_id, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo department_project_list($name, $department_id, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function department_project_list_row($label, $name, $department_id, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	department_project_list_cells(null, $name, $department_id, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}
//---------------------------------------------------------------------------------------------------


function other_currency_suppliers_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false,
	$all=false, $editkey = false)
{
	global $all_items;

        $home_curr = get_company_pref('curr_default');
        
	$sql = "SELECT supplier_id, supp_ref,  supp_name, curr_code, s.inactive 
                FROM ".TB_PREF."suppliers s 
                WHERE  curr_code <> ". db_escape($home_curr); 

	//$mode = get_company_pref('no_supplier_list');
        $mode = 0;

	if ($editkey){
		set_editor('supplier', $name, $editkey);
    }
		
	$ret = combo_input($name, $selected_id, $sql, 'supplier_id', 'supp_name',
	array(
		'format' => '_format_other_currency_suppliers',
	    'order' => array('supp_ref'),
		'search_box' => $mode!=0,
		'type' => 1,
        //'category' => 2,
		'spec_option' => $spec_option === true ? _("All Suppliers") : $spec_option,
		'spec_id' => $all_items,
		'select_submit'=> $submit_on_change,
		'async' => false,
		'sel_hint' => $mode ? _('Press Space tab to filter by name fragment') :
		_('Select supplier'),
		'show_inactive'=>$all
		));
	if ($editkey)
		$ret .= add_edit_combo('supplier');		
	return $ret;
}

function _format_other_currency_suppliers($row)
{
	return ($row[1] . " - (". $row[3].") - ". $row[2]);
}

function other_currency_suppliers_list_cells($label, $name, $selected_id=null, $all_option=false, 
	$submit_on_change=false, $all=false, $editkey = false)
{
	if ($label != null)
		echo "<td>$label</td><td>\n";
		echo other_currency_suppliers_list($name, $selected_id, $all_option, $submit_on_change, 
		$all, $editkey);
		echo "</td>\n";
}

function other_currency_suppliers_list_row($label, $name, $selected_id=null, $all_option = false, 
	$submit_on_change=false, $all=false, $editkey = false)
{
	echo "<tr><td class='label'>$label</td><td>";
	echo other_currency_suppliers_list($name, $selected_id, $all_option, $submit_on_change,
		$all, $editkey);
	echo "</td></tr>\n";
}

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

function assigned_period_leave_list($name, $employee_code, $from_date, $to_date, $selected_id=null, $none_option=false, $submit_on_change=false)
{
        global $all_items;
        
        $spec_option = false;
        $enabled =  false;

	$sql = "SELECT DISTINCT le.id,  CONCAT(value_name, ' from ',from_date, ' to ',to_date) leave_type_name
                FROM 
                    ".TB_PREF."leave_entitlements le,
                    ".TB_PREF."list_values lv  
		WHERE 	
                    le.leave_type_id = lv.id AND 
                    le.closed = 0 AND 
                    le.employee_code = ".db_escape($employee_code)." AND 
                    le.from_date <= ".db_escape(date2sql($to_date))." AND 
                    le.to_date >= ".db_escape(date2sql($from_date));

	$where = $enabled ? array("disable_trans = 0") : array();
	$ret = combo_input($name, $selected_id, $sql, 'leave_type_id', 'value_name',
	array(
		'where' => $where,
		'order' => array('value_name'),
		'spec_option' => $none_option === true ? _('All branches') : $none_option,
		'spec_id' => $all_items,
		'select_submit'=> $submit_on_change,
		'sel_hint' => _('Select customer branch')
	) );
	
	return $ret;      

}

function assigned_period_leave_list_cells($label, $name, $employee_code, $from_date, $to_date, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	if ($label != null)
		echo "<td>$label</td>\n";
	echo "<td>";
	echo assigned_period_leave_list($name, $employee_code, $from_date, $to_date, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function assigned_period_leave_list_row($label, $name, $employee_code, $from_date, $to_date, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	assigned_period_leave_list_cells(null, $name, $employee_code, $from_date, $to_date, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}


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

function asset_locations_list($name, $selected_id=null, $all_option=false, $submit_on_change=false, $show_all_location = false)
{
	global $all_items;

    if($show_all_location){
        $sql = "SELECT l.loc_code, l.location_name, l.inactive FROM ".TB_PREF."asset_locations l";
    }
    else{
        $sql = "SELECT l.loc_code, l.location_name, l.inactive
                FROM ".TB_PREF."asset_locations l  
                WHERE l.inactive = 0";
    }

    return combo_input($name, $selected_id, $sql, 'l.loc_code', 'l.location_name',
	array(
		'spec_option' => $all_option === true ? _("All Locations") : $all_option,
		'spec_id' => $all_items,
		'select_submit'=> $submit_on_change
	) );
}

function asset_locations_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false, $show_all_location = false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo asset_locations_list($name, $selected_id, $all_option, $submit_on_change, $show_all_location);
	echo "</td>\n";
}

function asset_locations_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=true, $show_all_location = false)
{
	echo "<tr><td class='label'>$label</td>";
	asset_locations_list_cells(null, $name, $selected_id, $all_option, $submit_on_change, $show_all_location);
	echo "</tr>\n";
}


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


function customer_sales_orders_list($name, $debtor_no, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	$sql = "SELECT so.order_no, CONCAT(so.order_no, ' - ',so.reference, ' - ', so.ord_date, ' - ', so.total) so_details 
                FROM ".TB_PREF."sales_orders so  
                WHERE so.debtor_no = ". db_escape($debtor_no);

        // default to the company currency
        return combo_input($name, $selected_id, $sql, 'order_no', 'so_details',
                array(
                'spec_option' => $none_option,
                        'select_submit'=> $submit_on_change,
                        'default' => 1,
                        'async' => false,
                        'order' => 'so.order_no DESC' 
                ) );
}

function customer_sales_orders_list_cells($label, $name, $debtor_no, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo customer_sales_orders_list($name, $debtor_no, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function customer_sales_orders_list_row($label, $name, $debtor_no, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	customer_sales_orders_list_cells(null, $name, $debtor_no, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}

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

function customer_transaction_types_list($name, $value=null, $spec_opt=false, $submit_on_change=false, $exclude=array(), $all_option = false){
    global $customer_transaction_types;

    asort($customer_transaction_types);
    // emove non-voidable transactions if needed
    $systypes = array_diff_key($customer_transaction_types, array_flip($exclude));
    return array_selector($name, $value, $systypes, 
        array(  'spec_option'=> $spec_opt,
                'spec_id' => ALL_NUMERIC,
                'select_submit'=> $submit_on_change,
                'async' => false,
                'spec_option'=>$all_option,)
            );
}

function customer_transaction_types_list_cells($label, $name, $value=null, $submit_on_change=false, $exclude=array(), $all_option = false){
    if ($label != null)
            echo "<td class='label-light'>$label</td>\n";
    echo "<td>";
    echo customer_transaction_types_list($name, $value, false, $submit_on_change, $exclude, $all_option);
    echo "</td>\n";
}

function customer_transaction_types_list_row($label, $name, $value=null, $submit_on_change=false, $exclude=array(), $all_option = false){
    echo "<tr><td class='label'>$label</td>";
    customer_transaction_types_list_cells(null, $name, $value, $submit_on_change, $exclude, $all_option);
    echo "</tr>\n";
}

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

function import_payment_terms_list($name, $selected_id=null, $special_option = false, $submit_on_change=false){
    
    $sql = "SELECT id, description, inactive FROM ".TB_PREF."import_payment_terms";
    return combo_input($name, $selected_id, $sql, 'id', 'description', 
        array(
                'spec_option' => $special_option===true ? _("All Payment Terms") : $special_option,
                'spec_id' => 0,
                'select_submit'=> $submit_on_change 
            )
        );
}

function import_payment_terms_list_cells($label, $name, $selected_id=null, $all_option = false, $submit_on_change=false){
    if($label != null)
        echo "<td class='label-light'>$label</td>\n";
    echo "<td>";
    echo import_payment_terms_list($name, $selected_id, $all_option, $submit_on_change);
    echo "</td>\n";
}

function import_payment_terms_list_row($label, $name, $selected_id=null, $all_option = false, $submit_on_change=false){
    echo "<tr><td class='label'>$label</td>";
    import_payment_terms_list_cells(null, $name, $selected_id, $all_option, $submit_on_change);
    echo "</tr>\n";
}


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

function approval_path_approval_groups_list($name, $approval_path_id, $selected_id=null, $spec_opt=false, $submit_on_change=false)
{
	$sql = "SELECT apc.approval_group_id, ag.approval_group_description 
                FROM ".TB_PREF."approval_path_configuration apc   
                    JOIN ".TB_PREF."approval_group ag 
                        ON ag.approval_group_id = apc.approval_group_id 
                WHERE apc.approval_path_id = ". db_escape($approval_path_id);
        
	return combo_input($name, $selected_id, $sql, 'apc.approval_group_id', 'ag.approval_group_description',
            array('spec_option' => $spec_opt,
                    'spec_id' => -1,
                    'select_submit'=> $submit_on_change,
                    'async' => true,
                    'order' => 'apc.position_seq_no'
            )
        );
}

function approval_path_approval_groups_list_cells($label, $name, $approval_path_id, $selected_id=null, $spec_opt=false, $submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo approval_path_approval_groups_list($name, $approval_path_id, $selected_id, $spec_opt, $submit_on_change);
	echo "</td>\n";
}

function approval_path_approval_groups_list_row($label, $name, $approval_path_id, $selected_id=null, $spec_opt=false, $submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	approval_path_approval_groups_list_cells(null, $name, $approval_path_id, $selected_id, $spec_opt, $submit_on_change);
	echo "</tr>\n";
}


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

function project_types_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
{
	global $project_types;
        
	echo array_selector($name, $selected_id, $project_types, 
		array( 
                'spec_option' => $all_option,
                'select_submit'=> $submit_on_change));
	//echo "</td>\n";
}

function project_types_list_cells($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo project_types_list($name, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function project_types_list_row($label, $name, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	project_types_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}


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

function project_sections_list($name, $project_id, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	$sql = "SELECT id, section_name "
                . "FROM ".TB_PREF."project_sections "
                . "WHERE project_id = ". db_escape($project_id);

	return combo_input($name, $selected_id, $sql, 'id', 'section_name',
	array('order'=>'section_name',
		'spec_option' => $none_option,
		'spec_id' => ALL_NUMERIC,
		'select_submit'=> $submit_on_change,
		'async' => false,
	) );
}

function project_sections_list_cells($label, $name, $project_id, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo project_sections_list($name, $project_id, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function project_sections_list_row($label, $name, $project_id, $selected_id=null, $none_option=false,
	$submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	project_sections_list_cells(null, $name, $project_id, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}


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


function filtered_value_list($name, $list_codes_in, $group_codes_in, $selected_id=null, $none_option=false, $submit_on_change=false) 
{
    $sql = "SELECT lv.id, lv.value_code, gn.value_name, lv.value_name   
            FROM ".TB_PREF."list_values lv 
                JOIN ".TB_PREF."list_values gn 
                    ON lv.group_value_id = gn.id  
            WHERE lv.inactive = 0 AND lv.list_code IN ( ".$list_codes_in." )";
    
            if (strlen($group_codes_in) > 0) {
                $sql .= " AND gn.value_code IN ( ".$group_codes_in." ) ";
            }

    $show_inactive = 0;

	$ret = combo_input($name, $selected_id, $sql, 'lv.value_code', 'lv.value_name',
	array( 
	    'format' => '_format_filtered_value_list',
	    'order' => array('gn.value_name', 'lv.value_code'),
            'search' => array( "lv.value_code", "lv.value_name"),
            'category' => 2,
            'spec_option' => $none_option === true ? _("All Projects") : $none_option,
            'select_submit'=> $submit_on_change,
            'async' => false,
            'show_inactive' => $show_inactive
	));
        
	return $ret;
}

function _format_filtered_value_list($row)
{
	return ($row[3]);
}

function filtered_value_list_cells($label, $name, $list_codes_in, $group_codes_in, $selected_id=null, $none_option=false, $submit_on_change=false) {
    if ($label != null)
        echo "<td class='label-light'>$label</td>\n";
    echo "<td>";
        echo filtered_value_list($name, $list_codes_in, $group_codes_in, $selected_id, $none_option, $submit_on_change);
    echo "</td>\n";
}

function filtered_value_list_row($label, $name, $list_codes_in, $group_codes_in, $selected_id=null, $none_option=false, $submit_on_change=false) {
    echo "<tr><td class='label'>$label</td>";
	filtered_value_list_cells(null, $name, $list_codes_in, $group_codes_in, $selected_id, $none_option, $submit_on_change);
    echo "</tr>\n";
}


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

function asset_verification_count_sheets_list($name, $asset_verification_count_id, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	$sql = "SELECT DISTINCT sheet_no, sheet_no   
                FROM ".TB_PREF."asset_verification_count_details  
                WHERE asset_verification_count_no = ". db_escape($asset_verification_count_id);

return combo_input($name, $selected_id, $sql, 'sheet_no', 'sheet_no',
	array(
        'spec_option' => $none_option,
		'select_submit'=> $submit_on_change,
		'default' => 1,
		'async' => false
	) );
}

function asset_verification_count_sheets_list_cells($label, $name, $asset_verification_count_id, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo asset_verification_count_sheets_list($name, $asset_verification_count_id, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function asset_verification_count_sheets_list_row($label, $name, $asset_verification_count_id, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	asset_verification_count_sheets_list_cells(null, $name, $asset_verification_count_id, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}


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

function contacts_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false)
{
	global $all_items;

	$sql = "SELECT id, initials, last_name, nic , first_name  
            FROM ".TB_PREF."contacts "; 

//	$mode = get_company_pref('no_customer_list');
        $mode = 0;

        

	$ret = combo_input($name, $selected_id, $sql, 'id', 'last_name',
	array(
	    'format' => '_format_contacts',
	    'order' => array('last_name', 'initials'),
            'search_box' => $mode!=0,
            'type' => 1,
            'size' => 20,
//            'category' => 2,
            'spec_option' => $spec_option === true ? _("All Contacts") : $spec_option,
            'spec_id' => $all_items,
            'select_submit'=> $submit_on_change,
            'async' => false 
	) );
	 
	return $ret;
}

function _format_contacts($row)
{
	return ($row[2] . ", ". $row[1]. " (". $row[4]. ") ". $row[3]."");
}

function contacts_list_cells($label, $name, $selected_id=null, $all_option=false, 
	$submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td nowrap>";
	echo contacts_list($name, $selected_id, $all_option, $submit_on_change);
	echo "</td>\n";
}

function contacts_list_row($label, $name, $selected_id=null, $all_option = false, $submit_on_change=false)
{
	global $path_to_root;

	echo "<tr><td class='label'>$label</td><td nowrap>";
	echo contacts_list($name, $selected_id, $all_option, $submit_on_change);
	echo "</td>\n</tr>\n";
}


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

function cheque_printing_trans_types_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
{
    global $systypes_array;
    
	$values_array = array();
	$values_array[ST_BANKPAYMENT] = $systypes_array[ST_BANKPAYMENT];
        $values_array[ST_BANKTRANSFER] = $systypes_array[ST_BANKTRANSFER];
        $values_array[ST_SUPPAYMENT] = $systypes_array[ST_SUPPAYMENT];
        $values_array[ST_PETTY_CASH_FLOAT_REIMBUR] = $systypes_array[ST_PETTY_CASH_FLOAT_REIMBUR];

	return array_selector($name, $selected_id, $values_array, 
		array( 
			'select_submit'=> $submit_on_change,
                        'spec_option' => $none_option===true ?  _("All Items") : $none_option,
			'async' => false ) ); // FIX?
}

function cheque_printing_trans_types_list_cells($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo cheque_printing_trans_types_list($name, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function cheque_printing_trans_types_list_row($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	asset_verification_count_sheets_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}

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

function all_stock_items_list_cells($label, $name, $selected_id=null, $all_option=false, 
	$submit_on_change=false, $all=false, $editkey = false)
{
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
		array('cells'=>true, 'show_inactive'=>$all, 'all_items_list'=>true), $editkey);
}

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

function all_budgets_list($name, $project_id, $selected_id=null, $none_option=false, $submit_on_change=false) {
    $sql = "SELECT pt.task_id, pt.task_code, boqg.description, pt.description, pt.budget, pt.budget_used, pt.budget_allocated  
            FROM ".TB_PREF."project_tasks pt 
                    LEFT JOIN ".TB_PREF."project_task_groups ptg ON 
                        pt.task_group_id = ptg.id 
                    LEFT JOIN ".TB_PREF."project_boq_item_groups boqg ON 
                        ptg.boq_group_id = boqg.id 
            WHERE pt.project_id = ".db_escape($project_id);

    global $all_items;
    $opts = array();
    $editkey = null;
    $mode = 0;
    $show_inactive = 0;
    
    if (user_view_available_budget()){
        $format_function = "_format_budgets_show_values";
    }
    else{
        $format_function = "_format_budgets_hide_values";
    }

	$ret = combo_input($name, $selected_id, $sql, 'pt.description', 'pt.task_code',
	array(
	    'format' => $format_function,
	    'order' => array('boqg.position', 'boqg.display_order', 'pt.task_code'),
            'search' => array( "pt.description", "pt.task_code"),
            'search_box' => $mode != 0,
            'type' => 1,
            'size' => 20,
            'category' => 2,
            'spec_option' => $none_option === true ? _("All Budgets") : $none_option,
            'spec_id' => $all_items,
            'select_submit'=> $submit_on_change,
            'async' => false,
            'sel_hint' => $mode ? _('Press Space tab to filter by name fragment') : _('Select a Budget'),
            'show_inactive' => $show_inactive
	) );
	if ($editkey){
		$ret .= add_edit_combo('customer');
    }
    
	return $ret;
}

function all_budgets_list_cells($label, $name, $project_id, $selected_id=null, $none_option=false, $submit_on_change=false) {
    if ($label != null)
            echo "<td class='label-light'>$label</td>\n";
    echo "<td>";
	echo all_budgets_list($name, $project_id, $selected_id, $none_option, $submit_on_change);
    echo "</td>\n";
}

function all_budgets_list_row($label, $name, $project_id, $selected_id=null, $none_option=false, $submit_on_change=false) {
    echo "<tr><td class='label'>$label</td>";
	all_budgets_list_cells(null, $name, $project_id, $selected_id, $none_option, $submit_on_change);
    echo "</tr>\n";
}


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

function all_project_sites_list($name, $project_id, $selected_id=null, $none_option=false, $submit_on_change=false) {
	$sql = "SELECT id, description  "
                . "FROM ".TB_PREF."project_sites "
                . "WHERE project_id = ". db_escape($project_id);

	return combo_input($name, $selected_id, $sql, 'id', 'description',
	array('order'=>'description',
		'spec_option' => $none_option,
		'spec_id' => ALL_NUMERIC,
		'select_submit'=> $submit_on_change,
		'async' => false,
	) );
}

function all_project_sites_list_cells($label, $name, $project_id, $selected_id=null, $none_option=false, $submit_on_change=false) {
	if ($label != null)
		echo "<td class='label-light'>$label</td>\n";
	echo "<td>";
	echo all_project_sites_list($name, $project_id, $selected_id, $none_option, $submit_on_change);
	echo "</td>\n";
}

function all_project_sites_list_row($label, $name, $project_id, $selected_id=null, $none_option=false, $submit_on_change=false) {
    echo "<tr><td class='label'>$label</td>";
	all_project_sites_list_cells(null, $name, $project_id, $selected_id, $none_option, $submit_on_change);
    echo "</tr>\n";
}

function employee_search_list($name, $selected_id=null, $all_option=false, $submit_on_change=false, $opts=array(), $editkey = false)
{
//    global $all_items;

//	$sql = "SELECT employee_code, em.last_name, lv.value_name,  em.initials, em.inactive, em.first_name   
//			FROM ".TB_PREF."employee_master em, ".TB_PREF."list_values lv 
//                        WHERE em.employee_type_id = lv.id";
////    
////    $sql = "SELECT employee_code, em.last_name, lv.value_name,  em.first_name, em.inactive 
////			FROM ".TB_PREF."employee_master em, ".TB_PREF."list_values lv 
////                        WHERE em.employee_type_id = lv.id";
//        
//	if ($editkey)
//		set_editor('item', $name, $editkey);
//
//	$ret = combo_input($name, $selected_id, $sql, 'employee_code', 'em.last_name',
//	array_merge(
//	  array(
//		'format' => '_format_emoplyees',
//		'spec_option' => $all_option===true ?  _("All Items") : $all_option,
//		'spec_id' => $all_items,
//		'search_box' => true,
//		'search' => array("employee_code", "lv.value_name","em.last_name"),
//		'search_submit' => get_company_pref('no_employee_list')!=0,
//		'size'=>10,
//        'type' => 2,
//		'select_submit'=> $submit_on_change,
//		'category' => 2,
//		'order' => array('lv.value_name', 'employee_code')
//	  ), $opts) );
//	if ($editkey)
//		$ret .= add_edit_combo('item');		
//	return $ret;
    
    
    
    
	global $all_items;

	$sql = "SELECT employee_code, lv.value_name, em.last_name,  em.initials, em.inactive, em.first_name, em.employee_reference 
			FROM ".TB_PREF."employee_master em, ".TB_PREF."list_values lv 
                        WHERE em.employee_type_id = lv.id";

	if ($editkey){
		set_editor('item', $name, $editkey);
        }

	$ret = combo_input($name, $selected_id, $sql, 'employee_code', 'em.last_name',
	array_merge(
	  array(
		'format' => '_format_employee_search',
		'spec_option' => $all_option===true ?  _("All Items") : $all_option,
		'spec_id' => $all_items,
//		'search_box' => true,
		'search' => array("em.employee_code", "em.first_name", "em.last_name", 'lv.value_name', 'em.employee_reference'),
		'search_submit' => true,
		'size'=>10,
		'select_submit'=> $submit_on_change,
		'category' => 1,
		'order' => array('lv.value_name, employee_code')
	  ), $opts) );
    
	if ($editkey){
		//$ret .= add_edit_combo('item');	
                $ret .= add_edit_combo('item');
    }
    
    if(isset($opts['where'])){
        $search = viewer_link('', 'assets/manage/asset_list.php?popup=1&parent='.$name, '', '',  ICON_VIEW);
    }
    else{
        $search = viewer_link('', 'assets/manage/asset_list.php?popup=1&parent='.$name, '', '',  ICON_VIEW);
    }
    
    $pos = strpos($ret, '</td>', 0);
//    $ret = substr_replace($ret, $search, $pos, 0);
    
	return $ret;

	  
}

function _format_employee_search($row)
{
	return $row[6] . ' - '.$row[2] . "&nbsp;-&nbsp;"  . $row[3]. " - (".$row[5].")" ;
}

function employee_search_list_cells($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false, $all=false, $editkey = false)
{
	if ($label != null){
		echo "<td class='label-light'>$label</td>\n";
    }
	echo employee_search_list($name, $selected_id, $none_option, $submit_on_change, array('cells'=>true, 'show_inactive'=>$all), $editkey);
}

function employee_search_list_row($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
        //echo "<tr>\n";
    employee_search_list_cells('', $name, $selected_id, $none_option, $submit_on_change);
	echo "</tr>\n";
}

function stock_and_manufacture_items_list($name, $selected_id=null, $all_option=false, $submit_on_change=false) {
    return stock_items_list($name, $selected_id, $all_option, $submit_on_change, array('where'=>array("mb_flag='B'")));
}

function stock_and_manufacture_items_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false) {
    if ($label != null)
            echo "<td class='label-light'>$label</td>\n";
    echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
            array('where'=>array("mb_flag='MB'"), 'cells'=>true));
}

function stock_and_manufacture_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false) {
    echo "<tr>";
	if ($label != null)
		echo "<td class='label'>$label</td>\n";
	echo "<td>";
	echo stock_and_manufacture_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
    echo "</td></tr>";
}

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

function project_boq_items_list($name, $project_id, $selected_id=null, $none_option=false, $submit_on_change=false) {
    $sql = "SELECT boq.id, boq.code, boqg.description, boq.description 
            FROM ".TB_PREF."project_boq_items boq 
                LEFT JOIN ".TB_PREF."project_boq_item_groups boqg 
                    ON boq.group_id = boqg.id 
            WHERE boq.project_id = ".db_escape($project_id);

	global $all_items;
    $opts = array();
    $editkey = null;
    $mode = 0;
    $show_inactive = 0;
    
        $format_function = "_format_budgets_hide_values";

	$ret = combo_input($name, $selected_id, $sql, 'boq.description', 'boq.code',
            array(
                'format' => $format_function,
                'order' => array('boqg.position', 'boqg.display_order', 'boq.code'),
                'search' => array( "boq.description", "boq.code"),
                'search_box' => $mode != 0,
                'type' => 1,
                'size' => 20,
                'category' => 2,
                'spec_option' => $none_option === true ? _("All Boq items") : $none_option,
                'spec_id' => $all_items,
                'select_submit'=> $submit_on_change,
                'async' => false,
                'sel_hint' => $mode ? _('Press Space tab to filter by name fragment') : _('Select a Budget'),
                'show_inactive' => $show_inactive
            ) );
        
	if ($editkey){
            $ret .= add_edit_combo('customer');
        }
    
	return $ret;
}

function project_boq_items_list_cells($label, $name, $project_id, $selected_id=null, $none_option=false, $submit_on_change=false) {
    if ($label != null) {
        echo "<td class='label-light'>$label</td>\n";
    }
        
    echo "<td>";
        echo project_boq_items_list($name, $project_id, $selected_id, $none_option, $submit_on_change);
    echo "</td>\n";
}

function project_boq_items_list_row($label, $name, $project_id, $selected_id=null, $none_option=false, $submit_on_change=false) {
    echo "<tr><td class='label'>$label</td>";
	project_boq_items_list_cells(null, $name, $project_id, $selected_id, $none_option, $submit_on_change);
    echo "</tr>\n";
}

function list_updated_date($name)
{
	return isset($_POST['_'.$name.'_changed']);
}