<?php

//Report Version For Dajcom
session_start();

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

$Title = 'Items Jour';
$HeaderTitle = ucfirst(strtolower($Title)).' Report';

$actionmode=$_GET['actionmode'];

 if($actionmode =='excel'){
	$filename = "Rep-AmortizationPreview_Excel_" . date('Y/m/d') . ".xls";
	header("Content-Disposition: attachment; filename=\"$filename\"");
	header("Content-Type: application/vnd.ms-excel");
}
  


print <<< HERE
<HTML>
<HEAD>
<TITLE> $HeaderTitle </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.subdetail th { font-size: 12px; 
                     font-weight: bold;
                     font-family:Times-New-Roman;
                   }				 
				 
table.subdetail td { font-size: 11px; 
                     font-family:Times-New-Roman;
                   }				 
				 

</style>


</HEAD>

<BODY>
HERE;

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

$connection = mysql_connect($config['dbServer'],$config['dbUser'],$config['dbPass']) or die("Could not connect to DB");
mysql_select_db($_SESSION['dbName'],$connection) or die("Could not find DB");

//Read From Setup Table							
$querysetup= " select DecimalBase, DecimalBase1, DecimalBase2, base1, base2, grid_color1, grid_color2  from setup ";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rowsetup=mysql_fetch_array($resultsetup)){
	extract($rowsetup);
}

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

	

$MainCompanyName=explode('_',$_SESSION['dbName']);  
$QueryDir = " Select Date_Format(StartFinancialDate,'%Y-%m-%d'),Date_Format(EndFinancialDate,'%Y-%m-%d') , Concat(CompanyName, '_', DirYear) As DirSchema ".
			" ,Date_Format(EndFinancialDate,'%d/%m/%Y') ".
			" From ".$_SESSION['dbLabel'].".Directories ". 	
			" Where  Upper(CompanyName) = Upper('".$MainCompanyName[0]."') ".
			" and Upper(Diryear) = Upper('".$MainCompanyName[1]."') ".
			" Order By DirYear ";

$ResultDir=mysql_query($QueryDir,$connection) or die(mysql_error());   
$RowsDir=mysql_fetch_row($ResultDir);
$StartFinancialDate = $RowsDir[0];
$EndFinancialDate = $RowsDir[1];
$EndFinancialDate1 = $RowsDir[3];
$DateTimePickerCloseYear = $EndFinancialDate;
	
$now=current_server_time($connection);
$dt=split(" ",$now[0]);
$printdate=split("-",$dt[0]);

$query="select base1,base2 from setup";
$result=mysql_query($query,$connection);
extract($result);
	 echo "<table border=0 width=100% cellspacing=0 cellpadding=0>
			<tr>
				<td align='left'>
					<table border=0 width='1100px' cellspacing=2 cellpadding=0 class='master' style='table-layout:fixed;' >
						  <col width=70>
						  <col width=60>
						  <col width=60>
						  <tr>
							<td align='center' colspan='3'><b><font size=5>$Title </font></td>
							<td align='right' colspan=2 ><font size='2'><b>Printed&nbsp;Date&nbsp;&amp;&nbsp;Time:</b>&nbsp;&nbsp;";
echo 							$printdate[2]."/".$printdate[1]."/".$printdate[0];
echo 							"<br>".$dt[1]." ".$dt[2];
echo 							"</font>
							</td>
						  </tr>
						  <tr height=50px></tr>
						  <tr>
							<td>"; //fuck you
							$headertablestyle="align='center' style='font-size:18px; font-weight:bold; font-family:serif; color:white; background-color:#4d8bac;'";
							$tdstyle="align='center' style='font-size:16px; font-weight:bold; font-family:serif;'";
							
							
								// Display all item jour
						$sub_query4="select  itemjour.Ledger_Number as itemjour_ledgernumber
											,ledger.ledger_name as ledger_ledgername
											,journal.journal_folio as journal_folio
											,journal.Journal_refgovernment as journal_refgov
											,itemjour.ItemJour_prcnt as itemjour_per
											,ItemJour_Code as itemjour_code
											,itemjour_barcode as itemjour_barcode
											,ItemJour_Description as itemjour_desc
											,date_format(itemjour.JournalDt_ValueDate,'%d/%m/%Y') as itemjour_valuedate
											,itemjour_location as itemjour_location
											,itemjour.Currency_Code as itemjour_curr
											,ItemJour_amount as itemjour_amount
											,ItemJour_amount1 as itemjour_amount1
											,ItemJour_amount2 as itemjour_amount2
											,date_format(ItemJour_PreviousDate,'%d/%m/%Y') as itemjour_prevdate
											,ifnull(ItemJour_PreviousAmount,0) as itemjour_prevamount
											,ifnull(ItemJour_PreviousAmount1,0) as itemjour_prevamount1
											,ifnull(ItemJour_PreviousAmount2,0) as itemjour_prevamount2
											,date_format(ItemJour_DateAmortized,'%Y-%m-%d') as itemjourdateamortized
											,date_format(ItemJour_DateAmortized,'%d/%m/%Y') as itemjour_dateamortized
											,itemjour.costcent_code as itemjour_costcentcode
											,costcent.costcent_name as costcent_costcentname
											,itemjour.project_code as itemjour_project_code
											,project.project_name as project_project_name
											,Ledger_Debit.Ledger_Name as ledgerdb_ledgername
											,Ledger_Credit.Ledger_Name as ledgercr_ledgername
											,costcent_credit.costcent_name as costcentcr_costcentname
											,project_credit.project_name as projectcr_projctname
											,itemjour.Ledger_NumberDebit as itemjour_ledgernumberdb
											,itemjour.Ledger_NumberCredit as itemjour_ledgernumbercr
											,itemjour.costcent_codecredit as itemjour_costcentcodecr
											,itemjour.project_codecredit as itemjour_projectcodecr
											,date_format(itemjour.ItemJour_SaleDate,'%d/%m/%Y') as itemjour_saledate
											,Ledger_NumberCash as ledger_numbercash
											,CostCent_CodeCash as costcent_codecash
											,Project_CodeCash as project_codecash
											,ItemJour_CashAmount as itemjour_cashamount
											,ItemJour_CashAmount1 as itemjour_cashamount1
											,ItemJour_CashAmount2 as itemjour_cashamount2
											,Ledger_NumberProfit as ledgernumber_prof
											,Ledger_Profit.Ledger_Name as ledgerprofit_ledgername
											,Ledger_NumberLost as ledgernumber_lost
											,Ledger_Lost.Ledger_Name as ledgerlost_ledgername
											,project_credit.project_name as projectcr_projectname
											,itemjour.ItemJour_Sold as itemjour_sold
											,Ledger_Cash.Ledger_Name as ledgercash_ledgername
											,itemjour.itemjour_remark as itemjour_remark
											,itemjour.autoincrement as itemjour_autoincrement
											
											
											 from itemjour left join project on project.project_code=itemjour.project_code
											left join costcent on costcent.costcent_code=itemjour.costcent_code             
											left join costcent as costcent_credit on costcent_credit.costcent_code=itemjour.costcent_codecredit             
											left join project as project_credit on project_credit.project_code=itemjour.project_codecredit             
											left join ledger on ledger.ledger_number=itemjour.Ledger_Number
											left join ledger as Ledger_Debit on Ledger_Debit.ledger_number=itemjour.Ledger_NumberCredit
											left join ledger as Ledger_Credit on Ledger_Credit.ledger_number=itemjour.Ledger_NumberDebit
											left join ledger as Ledger_Profit on Ledger_Profit.ledger_number=itemjour.Ledger_NumberProfit
											left join ledger as Ledger_Lost on Ledger_Lost.ledger_number=itemjour.Ledger_NumberLost
											left join ledger as Ledger_Cash on Ledger_Cash.ledger_number=itemjour.Ledger_NumberCash
											left join journaldt on journaldt.journaldt_id=itemjour.journaldt_id
											left join journal on journal.journal_id=journaldt.journal_id
											where ifnull(itemjour.ledger_number,'') like '%%'
											order by itemjour.Ledger_Number,itemjour.Currency_Code,itemjour.JournalDt_ValueDate,itemjour.ItemJour_Description ";
											//echo $sub_query4;
											
								$sub_result4=mysql_query($sub_query4,$connection) or die(mysql_error());	
								
echo"							<table border=1 width='9000px' cellspacing=0 cellpadding=0 class='master' style='table-layout:fixed;' >
									<col width=150><col width=120><col width=100><col width=100><col width=100><col width=100>
									<col width=120><col width=100><col width=150><col width=120><col width=120><col width=120>
									<col width=120><col width=120><col width=120><col width=120><col width=120><col width=120>
									<col width=120><col width=120><col width=120><col width=120><col width=120><col width=120>
									<col width=120><col width=120><col width=120><col width=120><col width=120><col width=120>
									<col width=120><col width=120><col width=120><col width=120><col width=120><col width=120>
									<col width=120><col width=120><col width=120><col width=120><col width=120><col width=120>
									<col width=120><col width=120><col width=120><col width=120><col width=120><col width=120>
									<col width=120><col width=120><col width=120><col width=120><col width=120><col width=120>
									<col width=120><col width=120><col width=120><col width=120><col width=120>
									<tr>
										<td $headertablestyle>Account Number</td>
										<td $headertablestyle>Account Name</td>
										<td $headertablestyle>Folio</td>
										<td $headertablestyle>Jv. No</td>
										<td $headertablestyle>Per (%)</td>
										<td $headertablestyle>Item Code</td>
										<td $headertablestyle>Barcode</td>
										<td $headertablestyle>Description</td>
										<td $headertablestyle>Value Date</td>
										<td $headertablestyle>Location</td>
										<td $headertablestyle>Currency</td>
										<td $headertablestyle>Amount</td>
										<td $headertablestyle>Amount $base1</td>
										<td $headertablestyle>Amount $base2</td>
										<td $headertablestyle>Previous Date</td>
										<td $headertablestyle>Previous Amount</td>
										<td $headertablestyle>Previous Amount $base1</td>
										<td $headertablestyle>Previous Amount $base2</td>
										<td $headertablestyle>Amortny Manual</td>
										<td $headertablestyle>Amortny 1 Manual</td>
										<td $headertablestyle>Amortny 2 Manual</td>
										<td $headertablestyle>Amortny</td>
										<td $headertablestyle>Amortny 1</td>
										<td $headertablestyle>Amortny 2</td>
										<td $headertablestyle>Amort N</td>
										<td $headertablestyle>Amort N $base1</td>
										<td $headertablestyle>Amort N $base2</td>
										<td $headertablestyle>Last Amortization</td>
										<td $headertablestyle>Amount Amort</td>
										<td $headertablestyle>Amount Amort $base1</td>
										<td $headertablestyle>Amount Amort $base2</td>
										<td $headertablestyle>Remain Amount </td>
										<td $headertablestyle>Remain Amount $base1</td>
										<td $headertablestyle>Remain Amount $base2</td>
										<td $headertablestyle>Costcent Code</td>
										<td $headertablestyle>Costcent Name</td>
										<td $headertablestyle>Project Code</td>
										<td $headertablestyle>Project Name</td>
										<td $headertablestyle>Ledger Number (Db)</td>
										<td $headertablestyle>Ledger Name (Db)</td>
										<td $headertablestyle>Ledger Number (Cr)</td>
										<td $headertablestyle>Leder Name (Cr)</td>
										<td $headertablestyle>Costcent Code (Cr)</td>
										<td $headertablestyle>Costcent Name (Cr)</td>
										<td $headertablestyle>Project Code (Cr)</td>
										<td $headertablestyle>Project Name (Cr)</td>
										<td $headertablestyle>P:Prepares S:Sold</td>
										<td $headertablestyle>Sale Date</td>
										<td $headertablestyle>Number (Cash)</td>
										<td $headertablestyle>Name (Cash)</td>
										<td $headertablestyle>Costcenter Code (cash)</td>
										<td $headertablestyle>ProjectCode (Cash)</td>
										<td $headertablestyle>Cash Amount</td>
										<td $headertablestyle>Cash Amount $base1</td>
										<td $headertablestyle>Cash Amount $base2</td>
										<td $headertablestyle>Number (Profit)</td>
										<td $headertablestyle>Name (Profit)</td>
										<td $headertablestyle>Number (Lost)</td>
										<td $headertablestyle>Name (Lost)</td>
										<td $headertablestyle>Remark</td>
									</tr>";
								$DateTimePickerCloseYear = strtotime(($DateTimePickerCloseYear));		  
								while ($row=mysql_fetch_array($sub_result4)){
										extract($row); 
								
								$ValidDay=0;
								$convert = 1;
								$valuedate = strtotime(changedateformat($itemjour_valuedate));
								
								$dateamortized = strtotime($itemjourdateamortized);
								$previousdate = strtotime($itemjour_prevdate);
									
								if ($itemjour_per<>0) 
									$ValidDay =( ($valuedate/ 86400) - ($dateamortized/ 86400))+ ((100/$itemjour_per)*365)  ;
								
								if ($ValidDay>0)  {
									$Days=round(($dateamortized-$valuedate)/ 86400,0);
									$Days = round($Days,0);
								   
									if ($Days>0) { 
										$itemjour2amountamortized  = (($itemjour_amount*$itemjour_per)/100)/365*($Days);
										$itemjour2amountamortized1 = (($itemjour_amount1*$itemjour_per)/100)/365*($Days);
										$itemjour2amountamortized2 = (($itemjour_amount2*$itemjour_per)/100)/365*($Days);
									} else {
										$itemjour2amountamortized  = 0;
										$itemjour2amountamortized1 = 0;
										$itemjour2amountamortized2 = 0;
									}
								} else {
									$itemjour2amountamortized   = $itemjour_amount;
									$itemjour2amountamortized1  = $itemjour_amount1;
									$itemjour2amountamortized2  = $itemjour_amount2;
								} 
								
								if (($previousdate<>'') and ($previousdate <= $dateamortized)) {
								   if ($itemjour_prevamount<=$itemjour2amountamortized) {
										$ItemJour2AmountRemain=$itemjour_amount-$itemjour2amountamortized;
										$ItemJour2AmountRemain1=$itemjour_amount1-$itemjour2amountamortized1;
										$ItemJour2AmountRemain2=$itemjour_amount2-$itemjour2amountamortized2;
								   } else {
										$ItemJour2AmountRemain=$itemjour_amount-$itemjour_prevamount;
										$ItemJour2AmountRemain1=$itemjour_amount1-$itemjour_prevamount1;
										$ItemJour2AmountRemain2=$itemjour_amount2-$itemjour_prevamount2;
								   }
								} else {
									$ItemJour2AmountRemain=$itemjour_amount-$itemjour2amountamortized;
									$ItemJour2AmountRemain1=$itemjour_amount1-$itemjour2amountamortized1;
									$ItemJour2AmountRemain2=$itemjour_amount2-$itemjour2amountamortized2;
								}
								
								if ($itemjour2amountamortized > $itemjour_prevamount) {
									$ItemJour2Amortn = $itemjour2amountamortized - $itemjour_prevamount;
								}
								else {
									$ItemJour2Amortn = 0;
									$itemjour2amountamortized = $itemjour_prevamount;
								}
								if ($itemjour2amountamortized1 > $itemjour_prevamount1 )
									$ItemJour2AmortnBase1 = $itemjour2amountamortized1-$itemjour_prevamount1;
								else {
									$ItemJour2AmortnBase1 = 0;
									$itemjour2amountamortized1=$itemjour_prevamount1;
								}
								if ($itemjour2amountamortized2>$itemjour_prevamount2 )
									$ItemJour2AmortnBase2=$itemjour2amountamortized2-$itemjour_prevamount2;
								else {
									$ItemJour2AmortnBase2=0;
									$itemjour2amountamortized2=$itemjour_prevamount2;
								}
								
								$itemjour2amountamortized=Round($itemjour2amountamortized*100)/100;
								$itemjour2amountamortized1=Round($itemjour2amountamortized1*100)/100;
								$itemjour2amountamortized2=Round($itemjour2amountamortized2*100)/100;
								$ItemJour2AmountRemain=Round($ItemJour2AmountRemain*100)/100;
								$ItemJour2AmountRemain1=Round($ItemJour2AmountRemain1*100)/100;
								$ItemJour2AmountRemain2=Round($ItemJour2AmountRemain2*100)/100;
								
							$ValidDay = 0;
							if ($itemjour_per<>0) 
							   if ($convert==1) 
								 $ValidDay=($valuedate/86400)+((100/$itemjour_per)*365) - $DateTimePickerCloseYear;
							   else
								$ValidDay=($valuedate/86400)+((100/$itemjour_per)*365) -  ($dateamortized/ 86400);
								
							if ($ValidDay>0) {
							   if ($convert==1) 
								  $Days=round(($DateTimePickerCloseYear/86400) - ($valuedate/86400),0);
							   else
								  $Days=round(($dateamortized/ 86400)-($valuedate/86400),0);
								 
							
					   
							   if ($Days>0) { 
								  $itemjour2amountamort=(($itemjour_amount*$itemjour_per)/100)/365*($Days);
								  $itemjour2amountamort1=(($itemjour_amount1*$itemjour_per)/100)/365*($Days);
								  $itemjour2amountamort2=(($itemjour_amount2*$itemjour_per)/100)/365*($Days);
							   } else {
								  $itemjour2amountamort=0;
								  $itemjour2amountamort1=0;
								  $itemjour2amountamort2=0;
							   }
							} else {
							   $itemjour2amountamort=$itemjour_amount;
							   $itemjour2amountamort1=$itemjour_amount1;
							   $itemjour2amountamort2=$itemjour_amount2;
							}
							
							if ($itemjour2amountamort>$itemjour_prevamount )
								$ItemJour2Amortn2=round(($itemjour2amountamort-$itemjour_prevamount)*100)/100;
							else {
								$ItemJour2Amortn2 = 0;
								$itemjour2amountamort = $itemjour_prevamount;
							}
							
							if ($itemjour2amountamort1 > $itemjour_prevamount1 )
								$ItemJour2Amortn2Base1 = round(($itemjour2amountamort1-$itemjour_prevamount1)*100)/100;
							else {
								$ItemJour2Amortn2Base1 = 0;
								$itemjour2amountamort1 = $itemjour_prevamount1;
							}
							
							if ($itemjour2amountamort2 > $itemjour_prevamount2 )
								$ItemJour2Amortn2Base2 = round(($itemjour2amountamort2-$itemjour_prevamount2)*100)/100;
							else {
								$ItemJour2Amortn2Base2 = 0;
								$itemjour2amountamort2 = $itemjour_prevamount2;
							}
							
							$itemjour2amountamort = Round($itemjour2amountamortized*100)/100;
						    $itemjour2amountamort1 = Round($itemjour2amountamortized1*100)/100;
						    $itemjour2amountamort2 = Round($itemjour2amountamortized2*100)/100;
							
							$amtny = $itemjour_amount*$itemjour_per/100;
							$amtny1 = $itemjour_amount1*$itemjour_per/100;
							$amtny2 = $itemjour_amount2*$itemjour_per/100;
							$Days=0;
							
							if ($valuedate > strtotime($StartFinancialDate)) {
							  $Days=round(($valuedate/86400 - strtotime($StartFinancialDate)/86400),0) ;
							}
							
							$amtny=$amtny-($amtny/365*$Days);
							$amtny1=$amtny1-($amtny1/365*$Days);
							$amtny2=$amtny2-($amtny2/365*$Days);

							$amtny=round($amtny*100)/100;
							$amtny1=round($amtny1*100)/100;
							$amtny2=round($amtny2*100)/100;
							
						if ($amtny > $ItemJour2AmountRemain)
							$ItemJour2Amortny = $ItemJour2AmountRemain;
						else
							$ItemJour2Amortny = $amtny;
						
						if ($amtny1>$ItemJour2AmountRemain1)
							$itemjour2amortny1 = $ItemJour2AmountRemain1;
						else
							$itemjour2amortny1 = $amtny1;

						if ($amtny2 > $ItemJour2AmountRemain2)
							$itemjour2amortny2 = $ItemJour2AmountRemain2;
						else
							$itemjour2amortny2 = $amtny2;

						if (strtotime($StartFinancialDate) > $valuedate)  
							$DaysB=( strtotime($StartFinancialDate)/86400 - $valuedate/86400) ;
						else
							$DaysB=1;
						
						$DaysC = ($DateTimePickerCloseYear)/86400 + 1 - $valuedate/86400;
						$DaysD=0;
						
						if ($itemjour_per<>0 ) 
							$DaysD = ($itemjour_amount/(($itemjour_amount*$itemjour_per/100)/365))+1;
						
						if ($DaysB>$DaysD) 
							 $Days=0;
							 
						else if ($DaysC>$DaysD) 
							 $Days=$DaysD-$DaysB;
						else
							 $Days=$DaysC-$DaysB;
				
						if ($Days>0) { 
							$itemjour2amortnymanual  = (($itemjour_amount* $itemjour_per)/100)/365*($Days);
							$itemjour2amortny1manual = (($itemjour_amount1* $itemjour_per)/100)/365*($Days);
							$itemjour2amortny2Manual = (($itemjour_amount2* $itemjour_per)/100)/365*($Days);
						}
						else {
							$itemjour2amortnymanual  = '0';
							$itemjour2amortny1manual = '0';
							$itemjour2amortny2Manual = '0';
						}
						
//echo $Days."<br>";
									
									
								
echo "								<tr>
										<td $tdstyle>$itemjour_ledgernumber</td>
										<td $tdstyle>$ledger_ledgername</td>
										<td $tdstyle>$journal_folio</td>
										<td $tdstyle>$journal_refgov</td>
										<td $tdstyle>$itemjour_per</td>
										<td $tdstyle>$itemjour_code</td>
										<td $tdstyle>$itemjour_barcode</td>
										<td $tdstyle>$itemjour_desc</td>
										<td $tdstyle>$itemjour_valuedate</td>
										<td $tdstyle>$itemjour_location</td>
										<td $tdstyle>$itemjour_curr</td>
										<td $tdstyle>".round($itemjour_amount,$DecimalBase)."</td>
										<td $tdstyle>".round($itemjour_amount1,$DecimalBase)."</td>
										<td $tdstyle>".round($itemjour_amount2,$DecimalBase)."</td>
										<td $tdstyle>$itemjour_prevdate</td>
										<td $tdstyle>".round($itemjour_prevamount,$DecimalBase)."</td>
										<td $tdstyle>".round($itemjour_prevamount1,$DecimalBase)."</td>
										<td $tdstyle>".round($itemjour_prevamount2,$DecimalBase)."</td>
										<td $tdstyle>".round($itemjour2amortnymanual,$DecimalBase)."</td>
										<td $tdstyle>".round($itemjour2amortny1manual,$DecimalBase)."</td>
										<td $tdstyle>".round($itemjour2amortny2Manual,$DecimalBase)."</td>
										<td $tdstyle>".round($ItemJour2Amortny,$DecimalBase)."</td>
										<td $tdstyle>".round($itemjour2amortny1,$DecimalBase)."</td>
										<td $tdstyle>".round($itemjour2amortny2,$DecimalBase)."</td>
										<td $tdstyle>".round($ItemJour2Amortn,$DecimalBase)."</td>
										<td $tdstyle>".round($ItemJour2AmortnBase1,$DecimalBase)."</td>
										<td $tdstyle>".round($ItemJour2AmortnBase2,$DecimalBase)."</td>
										<td $tdstyle>$itemjour_dateamortized</td>
										<td $tdstyle>".round($itemjour2amountamortized,$DecimalBase)."</td>
										<td $tdstyle>".round($itemjour2amountamortized1,$DecimalBase)."</td>
										<td $tdstyle>".round($itemjour2amountamortized2,$DecimalBase)."</td>
										<td $tdstyle>".round($ItemJour2AmountRemain,$DecimalBase)."</td>
										<td $tdstyle>".round($ItemJour2AmountRemain1,$DecimalBase)."</td>
										<td $tdstyle>".round($ItemJour2AmountRemain2,$DecimalBase)."</td>
										<td $tdstyle>$itemjour_costcentcode</td>
										<td $tdstyle>$costcent_costcentname</td>
										<td $tdstyle>$itemjour_project_code</td>
										<td $tdstyle>$project_project_name</td>
										<td $tdstyle>$itemjour_ledgernumberdb</td>
										<td $tdstyle>$ledgerdb_ledgername</td>
										<td $tdstyle>$itemjour_ledgernumbercr</td>
										<td $tdstyle>$ledgercr_ledgername</td>
										<td $tdstyle>$itemjour_costcentcodecr</td>
										<td $tdstyle>$costcentcr_costcentname</td>
										<td $tdstyle>$itemjour_projectcodecr</td>
										<td $tdstyle>$projectcr_projectname</td>
										<td $tdstyle>$itemjour_sold</td>
										<td $tdstyle>$itemjour_saledate</td>
										<td $tdstyle>$ledger_numbercash</td>
										<td $tdstyle>$ledgercash_ledgername</td>
										<td $tdstyle>$costcent_codecash</td>
										<td $tdstyle>$project_codecash</td>
										<td $tdstyle>$itemjour_cashamount</td>
										<td $tdstyle>$itemjour_cashamount1</td>
										<td $tdstyle>$itemjour_cashamount2</td>
										<td $tdstyle>$ledgernumber_prof</td>
										<td $tdstyle>$ledgerprofit_ledgername</td>
										<td $tdstyle>$ledgernumber_lost</td>
										<td $tdstyle>$ledgerlost_ledgername</td>
										<td $tdstyle>$itemjour_remark</td>
									</tr>";
									}
echo"							</table>
							</td>
						 </tr>
					</table>
				</td>
			</tr>
		</table>";
						




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;
}

function format_currency($amount, $DecimalBase) { 

    if($amount < 0) 
        return "(".number_format(abs($amount),$DecimalBase).")"; 
 
    else return number_format($amount, $DecimalBase); 
} 
function changedateformat($data){
		$data = substr($data, 6, 4) . substr($data, 3, 2) . substr($data, 0, 2);
		return substr($data, 0, 4) ."-". substr($data, 4, 2) ."-".substr($data, 6, 2);
}

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

?>

