<?php
header("Content-type: text/html; charset=windows-1256");

//Report Version For Tiba
session_start();
if($_SESSION['dbName']==""){
header("location:../index.php");
}

print <<< HERE
<HTML>
<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> User Access Report </TITLE>

<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: 13px; 
                  font-weight: bold;
                  font-family:Times-New-Roman;
				  border-top:1px solid black;
				  border-bottom:1px solid black;
				  border-left:1px solid black;
                }				 
				 
table.detail td { font-size: 12px; 
                  font-family:Times-New-Roman;
				  border-left:1px solid black;
                 }				 
				 
				
				 

</style>


</HEAD>

<BODY>
HERE;

include("config.inc.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");

$connection1 = mysql_connect($config['dbServer'],$config['dbUser'],$config['dbPass'],true,65536)	or die("Could not connect to DB");
mysql_select_db($config['dbName_log'],$connection1) or die("Could not find DB");


//mysql_set_charset('utf8',$connection);

//Read From 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, Company_NameF, Company_Memo, Company_MemoF, Company_Capital, Company_CapitalF ".
			 " from setup ";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rowsetup=mysql_fetch_array($resultsetup)){
	extract($rowsetup);
}

//Read From PurchaseSetup Table
$queryPurchaseSetup="Select PurchaseTTC From PurchaseSetup";
$resultPurchaseSetup=mysql_query($queryPurchaseSetup,$connection) or die(mysql_error());
while($rowPurchaseSetup=mysql_fetch_array($resultPurchaseSetup)){
	extract($rowPurchaseSetup);
}

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

	

$TotalQty = 0;


	$query = " Select Purchase_ID, Purchase_Reference, Date_Format(Purchase_Date,'%d/%m/%Y') As Purchase_Date, Purchase_Date As InvoiceDate, ".
			 " Date_Format(Journaldt_valuedate,'%d/%m/%Y') As MaturityDate, Purchases.Currency_code As CurrencyCode, Purchase_ChargeAccountAmt AS ChargeAccountAmt,".
			 " Purchase_Remark, Purchase_InvoiceNo, Journal.Journal_RefGovernment, Purchases.Project_Code As ProjectCode, Purchases.Costcent_code As CostcentCode,  ".
			 " Purchases.Supplier_code As SupplierCode,	Suppliers.Ledger_name As SupplierName,	Suppliers.Ledger_nameF As SupplierNameF, Supplier_PaymentTerms,  ".
			 " Supplier_Representative As SupplierContact, Supplier_Address As SupplierAddress, Supplier_VAT, Supplier_VatNo As SupplierVatNo,  ".
			 " Round(Purchase_Taxable, ".$DecimalBase.") As PurchaseTaxable, Round(Purchase_NoneTaxable, ".$DecimalBase."), ".
			 " Round(Purchase_Total, ".$DecimalBase.") As GrossTotal, ".
			 " Round(Purchase_DiscountPer, ".$DecimalBase.") As PurchaseDiscountPer, Round(Purchase_DiscountAmount, ".$DecimalBase.") As PurchaseDiscountAmount,  ".
			 " Round(Purchase_VAT, ".$DecimalBase.") As Purchase_VAT, Round(Purchase_VATBase1, ".$DecimalBase.") As Purchase_VATBase1, ".
			 " Round((Purchase_Total + IfNull(Purchase_VAT,0) - IfNull(Purchase_DiscountAmount,0) + (ifNull(Purchase_Tax1,0) + ifNull(Purchase_Tax2,0) + ifNull(Purchase_Tax3,0) + ifNull(Purchase_Tax4,0) + ifNull(Purchase_Tax5,0))), ".$DecimalBase.") As Purchase_NetTotal,  ".
			 " Round((Purchase_TotalBase2 + IfNull(Purchase_VATBase2,0) - IfNull(Purchase_DiscountBase2,0) + (ifNull(Purchase_Tax1Base2,0) + ifNull(Purchase_Tax2Base2,0) + ifNull(Purchase_Tax3Base2,0) + ifNull(Purchase_Tax4Base2,0) + ifNull(Purchase_Tax5Base2,0))), ".$DecimalBase.") As Purchase_NetTotalBase2,  ".
			 " Round((Purchase_TotalBase1 + IfNull(Purchase_VATBase1,0) - IfNull(Purchase_DiscountBase1,0) + (ifNull(Purchase_Tax1Base1,0) + ifNull(Purchase_Tax2Base1,0) + ifNull(Purchase_Tax3Base1,0) + ifNull(Purchase_Tax4Base1,0) + ifNull(Purchase_Tax5Base1,0))), ".$DecimalBase.") As Purchase_NetTotalBase1,  ".
			 " Round(Purchase_Charges, ".$DecimalBase.") As PurchaseCharges, Round(Purchase_ChargesBase1, ".$DecimalBase.") As PurchaseChargesBase1, Round(Purchase_ChargesBase2, ".$DecimalBase.") As PurchaseChargesBase2, ".
			 " Purchase_DebitAccount As PurchaseDebitAccount, if(Purchase_Mode=0, 'Credit', if(Purchase_Mode=1,'Cash', 'Check')) As PurchaseMode, ".
			 " Round((ifNull(Purchase_Tax1,0) + ifNull(Purchase_Tax2,0) + ifNull(Purchase_Tax3,0) + ifNull(Purchase_Tax4,0) + ifNull(Purchase_Tax5,0)), ".$DecimalBase.") As Purchase_TotalTaxes  ".
			 " From Purchases ".
			 " Left Join Suppliers on Purchases.Supplier_code = Suppliers.Ledger_Number ".
			 " Left Join Journal on Purchases.Journal_Id = Journal.Journal_Id ";
			
			 
		 
	$result=mysql_query($query,$connection) or die(mysql_error());
	while($rows=mysql_fetch_array($result)){
		extract($rows);
	}
	
		

	
	echo "<table border='0' width='635px' cellspacing=0 cellpadding=0 class='master' style='table-layout:fixed;' >
		  <col width=250>
		  <col width=160>
		  <col width=225>";
	echo "<tr>";
	echo "	<td align='left' valign='top' style='font-size:18px; font-style:italic; font-weight:bold;'>".nl2br($Company_Name)."</td>";
	
	if($_GET['PLang'] != 'AR') {
		echo "	<td align='center' rowspan='3'><img src='LogoFile.php' width='140px' height='80px' /></td>";
	} else {
		echo "	<td align='center' rowspan='3'><img src='LogoFile1.php' width='140px' height='80px' /></td>";
	}	
	
	echo "	<td align='right' valign='top' style='font-size:18px; font-style:italic; font-weight:bold;'>".nl2br($Company_NameF)."</td>";
	echo "</tr>";
	echo "<tr>";
	echo "	<td align='left' style='font-size:11px;'>".nl2br($Company_Capital)."</td>";
	echo "	<td align='right' style='font-size:11px;'>".nl2br($Company_CapitalF)."</td>";
	echo "</tr>";
	echo "<tr>";
	echo "	<td align='left' style='font-size:10px;'>".nl2br($Company_Memo)."</td>";
	echo "	<td align='right' style='font-size:10px;'>".nl2br($Company_MemoF)."</td>";
	echo "</tr>";
	echo "<tr><td align='left' colspan='3' style='height:20px;'>&nbsp;</td></tr>";
	
	if($_GET['PLang'] != 'AR') {
		echo "<tr>";
		echo "	<td align='left' colspan='2' style='font-size:14px; font-weight:bold; border-bottom:3px solid black;'>VAT NUMBER: ".$Setup_vatno."</td>";
		echo "	<td align='center' style='font-size:14px; font-style:italic;'>REPORT BUDGET</td>";
		echo "</tr>";
	} else {
		echo "<tr>";
		echo "	<td align='left' colspan='2' style='font-size:14px; font-weight:bold; border-bottom:3px solid black;'>VAT NUMBER: ".$Setup_vatno."</td>";
		echo "	<td align='center' style='font-size:18px;'>شراء</td>";
		echo "</tr>";
	}
	
	echo "</table>";
print <<< HERE

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