<?php

//Report Version For Sika

include 'function.inc.php';

session_start();
header("Content-type: text/html; charset=".$_SESSION['encodingmode']);
//$_SESSION['dbName'] = 'dajcom_acc2010';
if($_SESSION['dbName']==""){
header("location:../index.php");
}
		
		
		
include("config.inc.php");
$hide=$_GET['hide'];



print <<< HERE
<HTML>
<HEAD>
<TITLE> Transfer Report </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">

<style type="text/css">

table.master th { font-size: 14px; 
                  font-weight: bold;
                  font-family:Times-New-Roman;
                }				 
table.master td { font-size: 14px;
                  font-family:Times-New-Roman;
                 }
table.detail th { font-size: 14px; 
                  font-weight: bold;
                  font-family:Times-New-Roman;
                }				 
				 
table.detail td { font-size: 12px; 
                  font-family:Times-New-Roman;
                 }				 
				 
table.detail td.sr  { font-size: 10px; 
					  font-style: italic; 
                      font-family:Times-New-Roman;
                    }
				 
table.totals td.labels { font-size: 14px; 
                         font-weight: bold;
                         font-family:Times-New-Roman;
						 border-width: 1px;
						 border-style: none solid solid solid;
  						 border-color: #666666;
                       }					  
table.totals td.amounts { font-size: 14px; 
                          font-family:Times-New-Roman;
						  border-width: 1px;
						  border-style: none none solid none;
  						  border-color: #666666;
				        }
table.totals td.totalborder {
								font-size: 14px; 
								font-family:Times-New-Roman;
								border-width: 1px;
								border-style: none solid solid none;
								border-color: #666666;
							}	
							
				 
.bigfont{
	font-size: 150%; 
}
div.relative {
	position: relative;
	height:1300px;
	

}

div.absolute {
	border-top:solid 1px black;
	#border:solid 1px black;
    position: absolute;
    bottom: 0px;
	height: 80px;
	
	width:100%;
}
   
   
   .headerheight{
	height:180px;
}
				 
h4 { border-top-style: double; 
	 border-top-color: black; 
	 border-top-width: 1px;
   }
   
h3 { border-top-style: double; 
	 border-top-color: black; 
	 border-top-width: 2px;
	 width: 150px;
   } 
   
   .inlinetable{
	display: inline-table;
}
   .midfont{
	  font-size: 100%;
   }
   
   .headerheight{
	height:200px;
}

html {
  height: 100%;
  box-sizing: border-box;
}

*,
*:before,
*:after {
  box-sizing: inherit;
}

body {
  position: relative;
  margin: 0;
  padding-bottom: 6rem;
  min-height: 100%;
  //font-family: "Helvetica Neue", Arial, sans-serif;
}

.demo {
  margin: 0 auto;
  padding-top: 64px;
  width: 100%;
}



/**
 * Footer Styles
 */

.footer {
position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  padding: 1rem;
  background-color: #efefef;
  text-align: center;
  
}
.footer table{
	font-size:11px;
}


.horizantalline{
	border-top:solid 1px black;
}
</style>


</HEAD>

<BODY>
HERE;


$connection = mysql_connect($config['dbServer'],$config['dbUser'],$config['dbPass'])
		or die("Could not connect to 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);
}
mysql_select_db($_SESSION['dbName'],$connection) or die("Could not find DB");

	//Read From Module Table
$querymodule="Select ifNull(Module_TransferWithOneWh,0) As Module_TransferWithOneWh From Module";
$resultmodule=mysql_query($querymodule,$connection) or die(mysql_error());
while($rowmodule=mysql_fetch_array($resultmodule)){
	extract($rowmodule);
}


	$now=current_server_time($connection);
$dt=split(" ",$now[0]);
$printdate=split("-",$dt[0]);


//Read From Module Table
$querymodule=" Select ifNull(Module_Project,0) As Module_Project, ifNull(Module_Costcenter,0) As Module_CostCenter , Module_ShowLayoutProj , Module_ShowLayoutCost From Module ";
$resultmodule=mysql_query($querymodule,$connection) or die(mysql_error());
while($rowmodule=mysql_fetch_array($resultmodule)){
	extract($rowmodule);
}

$ModuleProject=$Module_Project;
$ModuleCostCenter=$Module_CostCenter;

//read fro setup table
$querysetup= " select DecimalBase, DecimalBase1, DecimalBase2, base1, base2, grid_color1, grid_color2, Setup_vatno, ".
             " Date_Format(Setup_VatStartDate,'%Y%m%d') As Setup_VatStartDate, ifNull(Setup_VatPercentage,0) As Setup_VatPercentage, ".
			 " Company_Name as CompanyName,Company_Memo as CompanyMemo, Company_NameF, Company_Memo, Company_MemoF, Company_Capital, Company_CapitalF,
			 company_telephone,company_city,company_fax,company_country,company_address,company_phone2,company_phone3
			 ,company_address2,company_city2,company_city_arabic,company_address_arabic,company_address2_arabic,
			 company_city_arabic,company_city2_arabic,company_country_arabic,company_name_arabic,company_memo_arabic,company_phone4,company_city3,company_city4,company_phone2_city3
			 ,company_phone1_city3,company_telephone_city3 ,company_phone2_city4
			 ,company_phone1_city4,company_telephone_city4,website,company_email".
			 " from setup ";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rowsetup=mysql_fetch_array($resultsetup)){
	extract($rowsetup);
}

		
				
				if ($hide=='0'){
		echo "<div class='demo' >";
		echo "<table><thead>";
		echo "<table border=0 width=100% cellspacing=0 cellpadding=0>";
	echo "<tr><td align='left' ><table border='0' width='270px'> <col width=10><col width=10>";
	echo "<tr><td align='left'><table><tr><td align='center' class='bigfont'><b><pre>".str_replace( '\n', '<br>', $CompanyName)."<pre></b></td></tr>
		<tr><td align='center' class='midfont'><pre>".str_replace( '\n', '<br>', $CompanyMemo)."<pre></td></tr></table></td>";
		
		
	
	echo "</table></td>";
	echo "<td height='60' align='center'><img src='LogoFile.php' width='100' height='100' /></td>";
	
	echo "<td align='right'><table border='0'> <col width=10><col width=10>";
	echo "<tr><td align='right' ><table border='0'  width='270'><tr><td align='center' class='bigfont'><b><pre>".str_replace( '\n', '<br>', $company_name_arabic)."<pre></b></td></tr>
		<tr><td align='center' class='midfont'><pre>".str_replace( '\n', '<br>', $company_memo_arabic)."<pre></td></tr></table></td>";
	echo "</table></td>
		
	</tr></thead><tr height=10px></tr>";
	}
		else echo "<div class='headerheight'></div>";
		echo "<tr height='40'><td></td><td align='center' ><b><font size=5>نقل مواد</font></td><td></td></tr>";
	echo "<table border=0 width=100% cellspacing=0 cellpadding=0><tr><td align='left'>";
	echo "<table border=0 width=100% cellspacing=2 cellpadding=0 class='master' style='table-layout:fixed;' >
		  ";
		
	
	echo  "<tr height='20'></tr>";
	echo "<tr>
	          
		</tr></table></td></tr>";

if($transfer_id!='')
{
$query = "SELECT TRANSFER_REFERENCE , date_format(transfer.TRANSFER_DATE,'%d/%m/%Y') as TRANSFER_DATE, Transfer_Remark , transfer.Project_code1 , transfer.Project_code2 , 
			Costcenter_Code , if((Transfer_Warehousefrom is null or Transfer_Warehousefrom = '') ,TransferDt_WarehouseFrom,Transfer_WarehouseFrom) Transfer_WarehouseFrom, 
			if((Transfer_WarehouseTo is null or Transfer_WarehouseTo = ''),TransferDt_WarehouseTo, Transfer_WarehouseTo)    Transfer_WarehouseTo
			, Driver_Name , Vehicle_No ,ToCostcenter_Code ,Document_RefNo,transferdt_warehousefrom,transferdt_warehouseto,Requestedby as authorized
			from transfer 
			left join transferdt on transferdt.transfer_id = transfer.transfer_id
			
			where transfer.transfer_id = ".$transfer_id."
			group by transfer.TRANSFER_REFERENCE , transfer.TRANSFER_DATE , transfer.Transfer_Remark , transfer.Project_code1 ,
			transfer.Project_code2 , transfer.Costcenter_Code , Transfer_WarehouseFrom ,
			Transfer_WarehouseTo , Driver_Name , Vehicle_No
			";
			
//echo $query;

$result=mysql_query($query,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($result)){
extract($rows);
}
$account="select User_account from transfer Where transfer_id = ".$transfer_id;
	$resulta=mysql_query($account,$connection) or die(mysql_error());
	if($rw=mysql_fetch_row($resulta)){
		$account=$rw[0];
	}
	//echo $account;
	$query_user = "select User_Name as preparedBy from ".$_SESSION['dbLabel'].".users where User_account = '".$account."'";
	$result_user = mysql_query($query_user, $connection);
	$rows_user = mysql_fetch_array($result_user);
	extract($rows_user);
$warehouse1="select warehouse_name from warehouse Where warehouse_code = '$Transfer_WarehouseFrom'";
//echo $warehouse1;
	$resulta1=mysql_query($warehouse1,$connection) or die(mysql_error());
	if($rw1=mysql_fetch_row($resulta1)){
		$warehouse_name1=$rw1[0];
	}
	$warehouse2="select warehouse_name from warehouse Where warehouse_code = '$Transfer_WarehouseTo'";
	$resulta2=mysql_query($warehouse2,$connection) or die(mysql_error());
	if($rw2=mysql_fetch_row($resulta2)){
		$warehouse_name2=$rw2[0];
	}
		
		
		$projectcode_name1="select project_name from project where project_code=$Project_code1";
		$projectcode_name2="select project_name from project where project_code=$Project_code2";
		$project_name1res=mysql_query($projectcode_name1);
		$project_name2res=mysql_query($projectcode_name2);
		if($prname1=mysql_fetch_array($project_name1res)){
			$project_name1=$prname1[0];
		}
		if($prname2=mysql_fetch_array($project_name2res)){
			$project_name2=$prname2[0];
		}
		
		echo  "<tr height='20'></tr>";
				echo "<tr><td colspan='4' >
				<div style='position:relative; float:right; width:100%; margin-top:5px; '>
				<table border='0'  style='float:right' >
				<col width=400>
				
				<col width=120>
				<col width=400>
				<col width=120>";
				//<col width=400>
				//<col width=120>
				
					echo "	<tr><td align='right' colspan='3'>$TRANSFER_DATE </td><td align='right' bgcolor=#D8D8D8>التاريخ</td></tr>
						<tr><td align='right' colspan='3'>$Driver_Name </td><td align='right' bgcolor=#D8D8D8>اسم المهندس</td></tr>
						<tr><td align='right' colspan='3' ></td><td align='right' bgcolor=#D8D8D8>تلفون</td></tr>
						<tr>
						
						<td align='right'>$warehouse_name2 </td><td align='right' bgcolor=#D8D8D8>&nbsp;الى مستودع</td>
						<td align='right'>$warehouse_name1 </td><td align='right' bgcolor=#D8D8D8>&nbsp;من مستودع</td></tr>
						<tr>
						<td align='right'>$ToCostcenter_Code </td><td align='right' bgcolor=#D8D8D8>&nbsp;الى مركز</td>
						<td align='right'>$Costcenter_Code </td><td align='right' bgcolor=#D8D8D8> &nbsp;من مركز </td></tr>
						
						<tr>
						<td align='right' >$project_name2 - $Project_code2</td>
						<td bgcolor=#D8D8D8 align='right'>الى مشروع</td>
						<td align='right'>$project_name1 - $Project_code1</td>
						<td align='right' bgcolor=#D8D8D8>من مشروع</td>
						</tr>";
						
					
						
					echo "	</table></td>";
			echo "</div></td></tr>";
				echo "<tr>";
				echo"<tr height='10'><td colspan=5><h4></td></tr>";
				//echo "<tr height='5'><td colspan=6><h4></td></tr>";



if ($detail==0) {
$query = "select transferdt.Item_CodeFinished as Item_code, transferdt.Item_Barcode Item_Barcode, ifnull(Transferdt.Item_qtyPacked,0) as TransferDt_Quantity, TransferDt_PriceBase1 , Transferdt_remark , Item_description , transferdt_id,  count(*) as itemscount
			 ,TransferDt_WarehouseTo from transferdt , items
			where items.item_code = transferdt.Item_CodeFinished
			And transferdt.Item_CodeFinished Is Not Null
			and transfer_id = ".$transfer_id."
			group by Transferdt.Item_CodeFinished, Transferdt.TransferDt_WarehouseTo 
			Union
			select transferdt.Item_CodeSemiFinished Item_code, transferdt.Item_Barcode Item_Barcode, ifnull(Transferdt.Item_qtyPacked,0) as TransferDt_Quantity, TransferDt_PriceBase1 , Transferdt_remark , Item_description , transferdt_id , count(*) as itemscount
			 ,TransferDt_WarehouseTo
			 from transferdt , items
			where items.item_code = transferdt.Item_CodeSemiFinished
			And transferdt.Item_CodeSemiFinished Is Not Null
			and transfer_id = ".$transfer_id."
			group by Transferdt.Item_CodeSemiFinished, Transferdt.TransferDt_WarehouseTo 
			union
			select transferdt.Item_code Item_code, transferdt.Item_Barcode Item_Barcode, TransferDt_Quantity as TransferDt_Quantity, TransferDt_PriceBase1 , Transferdt_remark , Item_description , transferdt_id , 1 as itemscount
			,TransferDt_WarehouseTo,Item_UnitSalesDesc
			from transferdt , items
			where items.item_code = transferdt.item_code
			And transferdt.Item_CodeSemiFinished Is Null
			And transferdt.Item_CodeFinished Is Null
			and transfer_id = ".$transfer_id;}
else {
$query = "select transferdt.Item_code Item_code, transferdt.Item_Barcode Item_Barcode, TransferDt_Quantity as TransferDt_Quantity, TransferDt_PriceBase1 , Transferdt_remark , Item_description , transferdt_id
			,TransferDt_WarehouseTo ,Item_UnitSalesDesc from transferdt , items
			where items.item_code = transferdt.item_code
			and transfer_id = ".$transfer_id;
			}
//echo $query;
$pquery = "select serialno_code from purchasesserialno ";
$result=mysql_query($query,$connection) or die(mysql_error());
//echo "<tr><td align='left'>";
echo "<td colspan='4' >
				<div style='position:relative; float:right; width:100%; margin-top:5px; '>
				<table border='0'  style='float:right' class='detail' width=100%; style='table-layout:fixed;'>
				<col width=200>
				<col width=200>
				<col width=400>
				<col width=200>
						<tr bgcolor=#D8D8D8><td align='center'>الوحدة</td>
							<td align='center'>الكمية</td>
							<td align='center'>الوصف</td>
							<td align='center'>البند</td>
						</tr>";
						echo"<tr height='10'><td colspan=5><h4></td></tr>";
						while($rows=mysql_fetch_array($result)){
						extract($rows);
						echo "
						<tr>
						<td align='center'>$Item_UnitSalesDesc </td>
						<td align='center'>$TransferDt_Quantity </td>
						<td align='center'>$Item_description </td>
						<td align='center'>$Item_code </td>
						</tr>";
						echo"<tr height='10'><td colspan=5><h4></td></tr>";
						}
						
						echo "</table></td>";
			echo "</div></td>
				
				</tr>";
						
	

	
	echo "<tr><td align='center'>";
	echo "<table border=0 width='635' cellspacing=0 cellpadding=1  class='master' style='table-layout:fixed;' >
		  <col width=235>
		  <col width=175>
		  <col width=235>";
	
	echo "<tr height='100'>";
	echo "  <td align='left' colspan='3'>&nbsp;</td>";
	echo "</tr>";	
	
	echo "<tr height='5'>";
	echo "  <td align='center'><h3></td>";
	echo "  <td align='center'><h3></td>";
	echo "  <td align='center'>&nbsp;</td>";
	echo "</tr>";	
	
	echo "<tr height='40'>";
	echo "  <td align='center' valign='top'>PREPARED BY<br> $preparedBy </td>";
	echo "  <td align='center' valign='top'>AUTHORIZED BY<br>$authorized</td>";
	echo "  <td align='center' valign='top'>&nbsp;</td>";
	echo "  <td align='center' valign='top'>&nbsp;</td>";
	echo "</tr>";	
	
	
	
	echo "</table>";
	echo "<br>";
	
	
	
	
	
	

}
else
echo"Please Choose a Transfer";
//echo "<tr><td align='center'>";

if ($hide=='0'){
	//echo "<div class='absolute' '><br>";
echo "</div>";
echo "<div class='footer'>";
echo "<div class='horizantalline'></div>";
echo "<table border='0' class='inlinetable'><col width=150px><col width=150px><col width=150px><col width=150px><col width=150px><tr><td align='center'>";

echo "<table border='0'><tr><td><i>$website</i></td></tr><tr><td><i>$company_email</i></td></tr></table> </td>";

echo "<td><table border=0><col width='70'><col width=100><tr><th colspan='2'><i>
$company_city</i></th></tr><tr><td align='right'>phone:</td><td><i>$company_telephone</i></td></tr><tr><td></td><td><i>$company_phone2</i></td></tr><tr><td align='right'>fax:</td><td><i>$company_phone4</i></td></tr></table></td>
<td><table><tr><th colspan='2'><i> $company_city3  </i></th></tr><tr><td align='right'>phone:</td><td><i>$company_telephone_city3</i></td></tr><tr><td></td><td><i>$company_phone1_city3</i></td></tr><tr><td align='right'>fax:</td><td><i>$company_phone2_city3</i></td></tr></table></td>
<td><table border='0'><tr><th colspan='2'><i> $company_city4 </i></th></tr><tr><td align='right'>phone:</td><td><i>$company_telephone_city4</i></td></tr><tr><td></td><td><i>$company_phone1_city4</i></td></tr><tr><td align='right'>fax:</td><td><i>$company_phone2_city4</i></td></tr></table></td>
<td valign='top'><table border='0'><tr><th colspan='2'><i> $company_city2 </i> </th></tr><tr><td>phone:</td><td><i>$company_phone3</i></td></tr></table></td></tr>";
echo "<tr><td></td></tr>";
echo "</table><tfoot></table>";
echo "</div>";

}


function current_server_time($connection){

  $string="Select date_format(NOW(),'%Y-%m-%d %h:%i %p') ";
  $result=mysql_query($string,$connection) or die(mysql_error());
  $now=mysql_fetch_row($result);

  return $now;
}


print <<< HERE

<script language=javascript>
if (typeof(window.print) != 'undefined')
{
    window.print();
}
</script>
</BODY>
</HTML>
HERE;
?>

