<?php
 
 session_start();
 header("Content-type: text/html; charset=".$_SESSION['encodingmode']);
 if($_SESSION['dbName']==""){
    header("location:../index.php");
 }

include("config.inc.php");
include("functions_items.php");

$connection = mysql_connect($config['dbServer'],$config['dbUser'],$config['dbPass'],true,65536) or die("Could not connect to DB");
mysql_select_db($_SESSION['dbName'],$connection) or die("Could not find DB");
if(	$_SESSION['encodingmode'] == 'utf8' || $_SESSION['encodingmode'] == 'utf-8'){
	mysql_query("SET NAMES 'utf8'"); 
	mysql_query('SET CHARACTER SET utf8'); 
	mysql_set_charset('utf8', $connection);
}

$item_id = $_GET['itemCode'];

$query_login="select ifNull(FI_ItemsApp,0) as FI_ItemsApp,ifNull(FI_ItemsMod,0) as FI_ItemsMod,ifNull(FI_ItemsDel,0) as FI_ItemsDel,FI_SellingPriceInItems as FI_SellingPriceInItems,
			FI_CostPriceInItems as FI_CostPriceInItems,RI_SatementofItems as RI_SatementofItems,language
			from ".$_SESSION['dbLabel'].".login where user_account='".$_SESSION['useraccount']."' and Upper(Login_Schema) = Upper('".$_SESSION['dbName']."')  ";
$resultlogin=mysql_query($query_login,$connection) or die(mysql_error());
 

 
while($rows=mysql_fetch_array($resultlogin)){
	extract($rows);
}

$querylang="select 
        language, code as code_label, vat as vat_label, currency as currency_label, activedate as activeat, inactivedate as inactiveat,
        creationdate, createdby, longdesc, 
        item_group, description_arabic, subgroup, description, costcenter, supplier, project, remark,
        warehouse, package, lastprice, minimumprice, fixedcost, category, discount, reducer, retarder, 
        Gloss, Adhesion, Alkali, Scuff, Shade, Strength, Packing, Viscositydirect, Viscosityreduced, name,
        sellingprice, qtyexist, lastcostusd, aubroupsupplier, disporder, minqty, maxqty, subseq, avgcost,
        wholeunit, gweight, netweight, volume, reverseprodu, nonstock_item as nonstock_item_label, item_serialno, evaluateqtyunit, 
        codeexp, exp_ar, exp_en, exp_fr, production, ttcinclude, print_item, pack, promotion, color, upload,
        picture, barcode1, barcode2, barcode3, generate_barcode2, Quantity, additem_unit, History, Transfer,
        modifyingsellpr as modifying, lastcost as lastcost_label, sellingngn, sellingusd, attribute, value as value_label, unit, quantityproduced, item as item_label, 
        Cost as cost_label, Stage, Barcode, FromDate, ToDate, Qty, reference, NGN, Chg, QtyRet, chg_r, USD, Price, perunit,
        warehousecode, qty_producedin, qtyproduceout, qty_entered, qtydelivered, qty_sold,
        qty_p_ordered, qty_sordered, qty_availabe, rangefrom, rangeto, rebate, Promotion_Qty,description_french,
        average_cost,
        currency_item,item_date,wh,discount_abr,expire,additem,attribut_param,
            search_att, total, tab1, tab2, tab3, tab4, tab5, tab6, tab7, tab8, tab9,history
        from ".$_SESSION['dbLabel'].".items_label 
        where 
        language='$language';";

//echo $querylang;
$resultlang=mysql_query($querylang,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultlang)){
    extract($rows);
		
}

$query_items="select items.Item_Code,Item_Unit,Item_Barcode,items.Ledger_Number,Item_Barcode2,items.Group_code,Item_Barcode3,items.SubGroup_Code,Item_tax,item_printed,items.Project_Code,
				Item_tax1,Item_TTCinclude,items.CostCent_Code,Item_tax2,Item_tax3,ITEM_ACTIVE,Item_tax4,Item_Remark,items.Currency_code,Item_tax5,Item_Package,Item_Vat,Item_Description,
				project_name,group_name,ledger_name,Costcent_name,subgroup_name,item_longdescription,Item_CostMethod,item_id,Item_UnitSalesDesc,item_picture,
				Item_SellingPrice1,	Item_SellingPrice2,	Item_SellingPrice3,	Item_SellingPrice4,	Item_SellingPrice5,	Item_SellingPrice6,
				item_pack,Item_ReverseProduction,Item_Production,item_promotion,Item_NonStock,
				Item_Weight,ITEM_MINQTY,ITEM_MAXQTY,date_Format(Item_LastDatePurchase,'%d-%m-%Y'),item_withserialno,Item_ModifySellingPrice,EvaluateQtyUnit,
				Item_SellingPrice1Base1,Item_SellingPrice1Base2,Item_SellingPrice2Base1,Item_SellingPrice2Base2,Item_SellingPrice3Base1,Item_SellingPrice3Base2,
				Item_SellingPrice4Base1,Item_SellingPrice4Base2,Item_SellingPrice5Base1,Item_SellingPrice5Base2,Item_SellingPrice6Base1,Item_SellingPrice6Base2,
				item_transfer,item_barcode,item_barcode2,item_barcode3,items.category_code,category.category_name,date_Format(item_inactivedate,'%d-%m-%Y'),Item_SemiFinished,
				ifNull(Item_QtyToBeProduced,0),  Item_Volume, Item_UnitPurchaseDesc, item_descriptionf1, item_descriptionf2, Items.Item_WarehouseCode, warehouse.Warehouse_Name, Item_NetWeight, 
				Item_Color, item_lastcostprice, Item_DispOrder, Item_MinimumPrice, item_vattype, item_discountper
				,item_codeexport,item_descriptionexporten,item_descriptionexportar,item_descriptionexportfr, item_reducer, item_retarder,
				item_Shade,item_Strength,item_Packing,item_ViscosityDirect,item_ViscosityReduced,item_gloss,Item_Adhesion,item_Alkali,item_scuff, Item_SubSequence, date_format(Item_SysDateTime,'%d-%m-%Y'), 
				item_createdBy, item_fixedcost , last_SubItemSeq, Item_showInSalesReport ,item_sgan
				from items 
				left join project on project.project_code=items.project_code
				left join costcent on costcent.costcent_code=items.costcent_code
				left join grouping on grouping.group_code=items.group_code
				left join suppliers on suppliers.ledger_number=items.ledger_number
				left join subgroup on subgroup.subgroup_code=items.subgroup_code
				left join category on category.category_code=items.category_code
				left join warehouse on warehouse.warehouse_code=items.Item_WarehouseCode
                where items.item_id='".$item_id."'";
                
$result_items=mysql_query($query_items,$connection);
while($row_item=mysql_fetch_row($result_items)){

        $item_code=$row_item[0];
        
        $currency=$row_item[19];
        
        $item_description=$row_item[23];
}

$querydflcostcent="select costcent_code from ".$_SESSION['dbLabel'].".loginstk where user_account='".$_SESSION['useraccount']."' and default_costcenter=1 ";	
//echo$querydflcostcent;
$resultdflcostcent=mysql_query($querydflcostcent,$connection) or die(mysql_error());
$rowcount=mysql_num_rows($resultdflcostcent);
if($rowcount==0 || $rowcount > 1){
    //echo"inside";
    $usercostcent="null";
}
else{
    $rowscostcent=mysql_fetch_array($resultdflcostcent);
    extract($rowscostcent);
    if($costcent_code != '') 
        $usercostcent="'".$costcent_code."'";
}

$querysetup= " select grid_color1, grid_color2,maxperpage,base1,base2,DecimalBase,DecimalBase1,DecimalBase2,maxperpage, ifnull(costcentminimum,0) as costcentminimum,
				ifNull(Setup_VatPercentage,0) as Setup_VatPercentage, ifnull(Project_FromItems,0) as Project_FromItems, ifnull(subgroup_autoIncrement,0) as subgroup_autoIncrement
				from setup ";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rowsetup=mysql_fetch_array($resultsetup)){
	extract($rowsetup);
}

print <<<HERE
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Select Items</title>
<link rel="stylesheet" type="text/css" media="all" href="js/grid/UI_DataGrid_V1.css">
<script type="text/javascript" src="js/grid/UI_DataGrid.js"></script>
<script type="text/javascript" src="js/grid/jquery-1.9.1.js"></script>

<style type="text/css">
<!--
body,td,th {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 14px;
}
.style1 {
	color: #333333;
	font-weight: bold;
}
.style2 {
	color: #999999;
	font-weight: bold;
	font-size: 11px;
}
.style3 {color: #999999}
.style4{
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 11px;
}
-->
</style>

</head>

<body>
    <form id='form1' name='form1' method='post' action=''>
HERE;

echo"<table border='0'  align='center' valign='top' width=100% >
		<col width=100>
		<col width=100>
		<col width=130>
		<col width=140>
		<col width=130>
		<col width=130>
		<col width=100>
		<col width=130>
		<col width=130>";
		
echo"   <tr><td  align='left' colspan=3>
		<table border=0><tr><td><span class='style1'>$code_label</span></td>
		<td><input type='text' name='item_code' value='$item_code' readonly style='width:150px;'></td>
		<td><span class='style1'>$currency_item</span></td>
		<td><input type='text' name='currency' value='$currency' readonly style='width:100px;'></td>
		<td><span class='style1'>$description</span></td>
		<td><input type='text' name='item_description' value='$item_description' readonly style='width:270px;'></td></tr>
		</table>
		</td></tr>";
		
echo"   <tr bgcolor='#f0f0f0'>
		<td align='center'><span class='style1'>$warehouse $code_label</span></td>
		<td align='center'><span class='style1'>$qtyexist</span></td>
		<td align='center'><span class='style1'>$qty_producedin</span></td>
		<td align='center'><span class='style1'>$qtyproduceout</span></td>
		<td align='center'><span class='style1'>$qty_entered</span></td>
		<td align='center'><span class='style1'>$qtydelivered</span></td>
		<td align='center'><span class='style1'>$qty_sold</span></td>
		<td align='center'><span class='style1'>$qty_p_ordered</span></td>
		<td align='center'><span class='style1'>$qty_sordered</span></td>
		<td align='center'><span class='style1'>$qty_availabe</span></td>
		<td align='center'><span class='style1'>cost1</span></td>
		<td align='center'><span class='style1'>cost2</span></td>
		<td align='center'><span class='style1'>cost3</span></td></tr>";
		
		
		if($item_code!=''){
			//fbegin();
			$subquery="call ItemsPerWarehouseViewPerCostCent('".$item_code."','%%',now(),0,0,0,0,$usercostcent)";
			//$subquery="call ItemsPerWarehouseView('".$item_code."','%%',now(),0,0,0,0)   ";
			// echo$subquery;
			$resultsub=mysql_query($subquery,$connection) ;
			
			while($rowsub=mysql_fetch_row($resultsub)){
				$ct+=1;
				if($ct%2==0)
					$Color="style='background-color:".$grid_color1."'";
				else			
					$Color="style='background-color:".$grid_color2."'";	
				
				echo"<tr ".$Color." height='20px'>";
				echo"<td align='left'>".$rowsub[0]."</td>";
				echo"<td align='right'>".$rowsub[1]."</td>";
				echo"<td align='right'>".$rowsub[2]."</td>";
				echo"<td align='right'>".$rowsub[3]."</td>";
				echo"<td align='right'>".$rowsub[4]."</td>";
				echo"<td align='right'>".$rowsub[5]."</td>";
				echo"<td align='right'>".$rowsub[6]."</td>";
				echo"<td align='right'>".$rowsub[7]."</td>";
				echo"<td align='right'>".$rowsub[8]."</td>";
				echo"<td align='right'>".$rowsub[9]."</td>";
				echo"<td align='right'>".$rowsub[10]."</td>";
				echo"<td align='right'>".$rowsub[11]."</td>";
				echo"<td align='right'>".$rowsub[12]."</td>";
				echo"</tr>";
			
			}
			//fcommit();
		}
echo"</table>
    </form>
    </body>
</html>";
?>