<?php 
error_reporting(0);
$curdate= date('Y-m-d');
$curYear= date('Y');
$curMonth	= date('n');

$curYear	= $curYear-($curMonth<=2 ? 1 : 0);		// till Feb, working in Last-to-Cur Year. From March, working in Cur-to-Next Year. => Financial Year Begin eg 2011 for 2011-2012
$curYear	= $curYear . '-' . ($curYear+1);	

$curLogMonth= (($curMonth+8) % 12) + 1;	



$first_day_this_month = date('Y-m-01'); 
$last_day_this_month  = date('Y-m-t');
$uptoday =date('j');
$totdays = cal_days_in_month(CAL_GREGORIAN, date('m'), date('Y'));
		
?>
<link href="./jQuery/themes/sunny/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script src="./jQuery/jquery-1.7-min.js"></script>
<script src="./jQuery/jqueryui-8.16-min.js"></script>
		
<table width="100%" cellspacing="0" cellpadding="0" class="content-border" border="1" style='border-collapse:collapse'>
	<tr>
		<td><h1>Dispatch Report As On <?php echo date('d-m-Y H:i'); ?></h1>
		<form style="padding-left:1075px;">
			<input type="text" name="DailyDispatchReportDate" id="DailyDispatchReportDate" />
			<input type="button" Value="View" onclick="ShowDailyDispatchReport();" />
		</form>
		<div width="50%" class="" style="margin-top:-50px" >
		<br/><br/>
		<h3>01. Todays Dispatch</h3>
		<table width="60%" cellspacing="1" cellpadding="5" border="1" style="border-collapse:collapse;" class="grid report">
			<tr style="background-color:#94D4E9">
				<th rowspan="2" align="center" width="12%">Product</th>
				<th rowspan="2" align="left" width="4%">Company Target</th>
				<th rowspan="2" align="left" width="4%">Today Dispatch</th>
				<th rowspan="2" align="center" width="5%">Up to Dispatch</th>
				<th rowspan="2" align="center" width="5%">POsition Tar/ Disp</th>
				<th rowspan="2" align="center" width="5%">Positon Tar/Disp %</th>	
				<th colspan="4">Order Status</th>
			</tr>
			<tr style="background-color:#94D4E9">
				<th align="center" width="5%">App</th>	
				<th align="center" width="5%">Pen</th>	
				<th align="center" width="5%">Unapp</th>	
				<th align="center" width="5%">G.Total</th>	
			</tr>
		
		<?php 
		$preitemtype='';
		$curitemtype='';
		$totcomtarget=$tottodaytarget=$totuptodistarget=$totposition=$totpositionper=0;
		$totOrderStatusApp=$totOrderStatusPen=$totOrderStatusUnApp= $GtotalorderstatusExp=0;
		
		$itemCdList='';
			foreach($listData as $curRow) {
			$ProductId= $curRow['ProductId'];
			$ItemCd= $curRow['ItemCd'];
			$itemCdList= $itemCdList.",".$ItemCd;
			$POType= $curRow['POType'];
			$Divide= $curRow['DividedBy'];
			
			$curitemtype =$curRow['ItemType'];
			//echo $ItemCd;
			$sql = "SELECT TargetQty From so_company_target where ProductId=$ProductId and year='$curYear' and month='$curLogMonth'";
			$compTarget = $objSolarCustomer->execSelectQuery($sql);
			
			$sqltd = "SELECT sum(A.DespatchedQty) as DespatchedQty From so_expdet_magazine_item A JOIN so_expdet B ON A.IdExpDet= B.IdExpDet JOIN
			so_expdet_magazine C ON A.IdExpDet= C.IdExpdet and A.MagazineCd=C.MagazineCd WHERE  A.ItemCd IN ($ItemCd) 
			and StatusCd IN ('C', 'B') and DATE(C.SAPInvDate)='$curdate'" ;
			$TodayDisp = $objSolarCustomer->execSelectQuery($sqltd);
			
			$sqluptd = "SELECT sum(A.DespatchedQty) as DespatchedQty From so_expdet_magazine_item A JOIN so_expdet B ON A.IdExpDet= B.IdExpDet JOIN
			so_expdet_magazine C ON A.IdExpDet= C.IdExpdet and A.MagazineCd=C.MagazineCd WHERE  A.ItemCd IN ($ItemCd) 
			and StatusCd IN ('C', 'B') and DATE(C.SAPInvDate) between '$first_day_this_month' and '$last_day_this_month'" ;
			$UptoDisp = $objSolarCustomer->execSelectQuery($sqluptd);
			
			$sqlosa = "SELECT sum(A.OrderQty) as OrderQty From so_expdet_magazine_item A JOIN so_expdet B ON A.IdExpDet= B.IdExpDet 
			WHERE  A.ItemCd IN ($ItemCd) and StatusCd IN ('A') " ;
			$OrderApp = $objSolarCustomer->execSelectQuery($sqlosa);
			
			$sqlosp = "SELECT sum(A.OrderQty) as OrderQty From so_expdet_magazine_item A JOIN so_expdet B ON A.IdExpDet= B.IdExpDet 
			WHERE  A.ItemCd IN ($ItemCd) and StatusCd IN ('W') " ;
			$OrderPending = $objSolarCustomer->execSelectQuery($sqlosp);
			
			$sqlosu = "SELECT sum(A.OrderQty) as OrderQty From so_expdet_magazine_item A JOIN so_expdet B ON A.IdExpDet= B.IdExpDet 
			WHERE  A.ItemCd IN ($ItemCd) and StatusCd IN ('U')" ;
			$OrderUnapp = $objSolarCustomer->execSelectQuery($sqlosu);
			
			$comtarget=$compTarget[0]['TargetQty'];
			$todaydis=($TodayDisp[0]['DespatchedQty'])/$Divide;
			$uptodis=($UptoDisp[0]['DespatchedQty'])/$Divide;
			$position= -($comtarget/$totdays)*$uptoday+$uptodis;
			$positionper=($position*100)/$comtarget;
			
			$OrderStatusApp=$OrderApp[0]['OrderQty']/$Divide;
			$OrderStatusPending=$OrderPending[0]['OrderQty']/$Divide;
			$OrderStatusUnApp=$OrderUnapp[0]['OrderQty']/$Divide;
			$Gtotal = $OrderStatusApp +$OrderStatusPending + $OrderStatusUnApp;
		
			if($preitemtype!='' && $curitemtype!=$preitemtype){
		
			?>
			<tr align='right' style='font-weight:bold'>
				<td align="left" width="5%">Tot Exp</td>
				<td width="5%"><?php echo sprintf('%.3f', $totcomtarget); ?></td>
				<td width="5%"><?php echo sprintf('%.3f',$tottodaytarget); ?></td>
				<td width="5%"><?php echo sprintf('%.3f',$totuptodistarget); ?></td>
				<td width="5%"><?php echo sprintf('%.2f', $totposition); ?></td>
				<td width="5%"><?php echo sprintf('%.2f', $totpositionper); ?></td>
				
				<td width="5%" width="5%"><?php echo sprintf("%.3f", $totOrderStatusApp); ?></td>
				<td width="5%" width="5%"><?php echo sprintf("%.3f", $totOrderStatusPending); ?></td>
				<td width="5%" width="5%"><?php echo sprintf("%.3f", $totOrderStatusUnApp); ?></td>
				<td width="5%" width="5%"><?php echo sprintf("%.3f", $GtotalorderstatusExp); ?></td>
			</tr>
			
			<tr align="right">
				<td align="left" width="5%"><?php echo $curRow['ProductName']; ?></td>
				<td width="5%"><?php echo sprintf("%.3f", $comtarget); ?></td>
				<td width="5%"><?php echo sprintf("%.3f",$todaydis); ?></td>
				<td width="5%"><?php echo sprintf("%.3f",$uptodis); ?></td>
				<td width="5%"><?php echo sprintf("%.2f", $position); ?></td>
				<td width="5%"><?php echo sprintf("%.2f", $positionper); ?></td>
				
				<td width="5%"><?php echo sprintf("%.3f", $OrderStatusApp); ?></td>
				<td width="5%"><?php echo sprintf("%.3f", $OrderStatusPending); ?></td>
				<td width="5%"><?php echo sprintf("%.3f", $OrderStatusUnApp); ?></td>
				<td width="5%"><?php echo sprintf("%.3f", $Gtotal); ?></td>
			</tr>
			<?php 
			
			}else{ 
				if($POType==1){
					$sqltd = "SELECT sum(TotalMtr) as DespatchedQty From so_accessory WHERE  AccessoryCtgCd  IN ('7', '6' ) and StatusCd IN ('S', 'A')
					and DATE(SAPInvDate)='$curdate'" ;
					$TodayDisp = $objSolarCustomer->execSelectQuery($sqltd);
					
					$sqluptd = "SELECT sum(TotalMtr) as DespatchedQty From so_accessory WHERE  AccessoryCtgCd IN ('7', '6') and StatusCd IN ('S', 'A')
					and DATE(SAPInvDate) between '$first_day_this_month' and '$last_day_this_month'";
					$UptoDisp = $objSolarCustomer->execSelectQuery($sqluptd);
			
					$todaydis=($TodayDisp[0]['DespatchedQty'])/$Divide;
					$uptodis=($UptoDisp[0]['DespatchedQty'])/$Divide;
					$position= -($comtarget/$totdays)*$uptoday+$uptodis;
					$positionper=($position*100)/$comtarget;
				
				}
			
			?>
			<tr align="right">
				<td align="left" width="5%"><?php echo $curRow['ProductName']; ?></td>
				<td width="5%"><?php echo sprintf('%.3f', $comtarget); ?></td>
				<td width="5%"><?php echo sprintf('%.3f', $todaydis); ?></td>
				<td width="5%"><?php echo sprintf('%.3f', $uptodis); ?></td>
				<td width="5%"><?php echo sprintf('%.2f', $position); ?></td>
				<td width="5%"><?php echo sprintf('%.2f', $positionper); ?></td>
				
				<td width="5%"><?php echo sprintf('%.3f', $OrderStatusApp); ?></td>
				<td width="5%"><?php echo sprintf('%.3f', $OrderStatusPending); ?></td>
				<td width="5%"><?php echo sprintf('%.3f', $OrderStatusUnApp); ?></td>
				<td width="5%"><?php echo sprintf('%.3f', $Gtotal); ?></td>
			</tr>
			<?php
				}
				
			$totcomtarget=$totcomtarget+$comtarget;
			$tottodaytarget=$tottodaytarget+$todaydis;
			$totuptodistarget=$totuptodistarget+$uptodis;
			$totposition=$totposition+$position;
			$totpositionper=$totpositionper+$positionper;
			
			$totOrderStatusApp=$totOrderStatusApp+$OrderStatusApp;
			$totOrderStatusPen=$totOrderStatusPen+$OrderStatusPending;
			$totOrderStatusUnApp=$totOrderStatusUnApp+$OrderStatusUnApp;
			
			$GtotalorderstatusExp= $totOrderStatusApp+$totOrderStatusPending +$totOrderStatusUnApp;
			
				$preitemtype=$curitemtype;
				}
			?>
			</table>
			<br/><br/><br/>
			<h3>02. Pending van detail</h3>
			<table width="20%" cellspacing="1" cellpadding="5" border="1" style='border-collapse:collapse' class="grid report">
				<tr>
					<th width="5%">Van</th>
					<th width="5%">Total</th>
					<th width="5%">Dispatch</th>
					<th width="5%">Pending</th>
				</tr>
			<?php 
			$totalvan=0;
				$sqlpv = "SELECT count(distinct(A.IdVan)) as novanspen  FROM 
				(SELECT A.* FROM scm_solar_sc.vm_gate_tran A INNER JOIN 
				(SELECT A.IdVan, MAX(A.DateTime) AS DateTime FROM scm_solar_sc.vm_gate_tran A WHERE A.PlantCd=1 GROUP BY A.IdVan	) B 
				ON A.IdVan=B.IdVan AND A.DateTime=B.DateTime ) A
				LEFT OUTER JOIN scm_solar_sc.vm_gate_tran_customer B ON A.GateCd=B.GateCd AND A.IsGateIn=B.IsGateIn AND A.GateTranNo=B.GateTranNo
				LEFT OUTER JOIN scm_solar_sc.vm_van_status_m D ON A.VanStatusCd=D.VanStatusCd
				INNER JOIN scm_solar_sc.vm_gate_m E ON A.GateCd=E.GateCd AND E.PlantCd=1
				WHERE (!D.IsFinal OR DATE_FORMAT(A.DateTime,'%d-%m-%Y')=DATE_FORMAT(NOW(),'%d-%m-%Y')) and A.SectorCd='T' and A.GateCd='1' and A.VanStatusCd='2' order by A.DateTime";
				$noofvanspen = $objSolarCustomer->execSelectQuery($sqlpv);
				
			//	$sqldv = "SELECT count(distinct(A.IdVan)) as novansdis  FROM 
			//	(SELECT A.* FROM scm_solar_sc.vm_gate_tran A INNER JOIN 
			//	(SELECT A.IdVan, MAX(A.DateTime) AS DateTime FROM scm_solar_sc.vm_gate_tran A WHERE A.PlantCd=1 GROUP BY A.IdVan	) B 
			//	ON A.IdVan=B.IdVan AND A.DateTime=B.DateTime ) A
			//	LEFT OUTER JOIN scm_solar_sc.vm_gate_tran_customer B ON A.GateCd=B.GateCd AND A.IsGateIn=B.IsGateIn AND A.GateTranNo=B.GateTranNo
			//	LEFT OUTER JOIN scm_solar_sc.vm_van_status_m D ON A.VanStatusCd=D.VanStatusCd
			//	INNER JOIN scm_solar_sc.vm_gate_m E ON A.GateCd=E.GateCd AND E.PlantCd=1
			//	WHERE (!D.IsFinal OR DATE_FORMAT(A.DateTime,'%d-%m-%Y')=DATE_FORMAT(NOW(),'%d-%m-%Y')) and A.SectorCd='T'  and A.VanStatusCd IN ('3', '4','9')";
			//	$noofvansdis = $objSolarCustomer->execSelectQuery($sqldv);
			
				$sqldv = "SELECT *  FROM so_comparty_van_dispatch_plan WHERE  DispatchPlanDate= '$curdate'";
				$noofvansdis = $objSolarCustomer->execSelectQuery($sqldv);
				
				$vanspen= $noofvanspen[0]['novanspen'];
				$vansdis= $noofvansdis[0]['PartyVan'];
				
				$totalvan=$vansdis+$vanspen;
				
			//	$sqlcomPending= "SELECT count(distinct(VehicleNo)) as ComPendingvan FROM `so_expdet` WHERE `StatusCd`='A' and `DespatchMode`='F'";
			//	$ComPending = $objSolarCustomer->execSelectQuery($sqlcomPending);
				
			/*	$sqlcomDisp= "SELECT count(distinct(A.IdVan)) as ComDispatchvan  FROM 
				(SELECT A.* FROM scm_solar_sc.vm_gate_tran A INNER JOIN 
				(SELECT A.IdVan, MAX(A.DateTime) AS DateTime FROM scm_solar_sc.vm_gate_tran A WHERE A.PlantCd=1 GROUP BY A.IdVan	) B 
				ON A.IdVan=B.IdVan AND A.DateTime=B.DateTime ) A
				LEFT OUTER JOIN scm_solar_sc.vm_gate_tran_customer B ON A.GateCd=B.GateCd AND A.IsGateIn=B.IsGateIn AND A.GateTranNo=B.GateTranNo
				LEFT OUTER JOIN scm_solar_sc.vm_van_status_m D ON A.VanStatusCd=D.VanStatusCd
				INNER JOIN scm_solar_sc.vm_gate_m E ON A.GateCd=E.GateCd AND E.PlantCd=1
				INNER JOIN scm_solar_sc.vm_van_m F ON A.IdVan=F.IdVan AND F.TransporterTypeCd=1
				WHERE (!D.IsFinal OR DATE_FORMAT(A.DateTime,'%d-%m-%Y')=DATE_FORMAT(NOW(),'%d-%m-%Y')) AND F.TransporterTypeCd=1 and A.SectorCd='T'  and A.VanStatusCd IN ('3', '4','9')";
				$ComDispatch = $objSolarCustomer->execSelectQuery($sqlcomDisp);
				*/
			//	$sqlcomDisp= "SELECT count(Distinct(A.VehicleNo)) AS `ComDispatchvan` FROM so_expdet A 
			//			INNER JOIN so_vehicle_m B ON A.VehicleNo=B.VehicleNo
			//			INNER JOIN so_customer_m C ON A.CustomerCd=C.CustomerCd
			//			WHERE (B.IsDummyCompanyVan=1 OR B.CustomerCd='1800') AND C.SectorCd='T'
			///			AND A.DespatchMode='F' AND A.StatusCd='A'";
			//	$ComDispatch = $objSolarCustomer->execSelectQuery($sqlcomDisp);
			//	$comdisp= $ComDispatch[0]['ComDispatchvan'];
				
				//$compen= $ComPending[0]['ComPendingvan'];
				$comdisp= $noofvansdis[0]['CompanyVan'];
				$totalcom= $noofvansdis[0]['TotalCompanyVanProg'];
				$compen=$totalcom-$comdisp;
				//$totalcom= $compen+$comdisp;
			?>	
				<tr align='center'>
				<td align="left" width="5%"><b>Party</b></td>
				<td width="5%"><?php echo $totalvan; ?></td>
				<td width="5%"><?php echo $vansdis; ?></td>
				<td width="5%"><?php echo $vanspen; ?></td>
				</tr>
				<tr align='center'>
				<td align="left" width="5%"><b>Company</b></td>
				<td width="5%"><?php echo $totalcom; ?></td>
				<td width="5%"><?php echo $comdisp; ?></td>
				<td width="5%"><?php echo $compen; ?></td>
				</tr>
			</table>
			<br/><br/><br/>
			<h3>03. AED Sold and Stock position</h3>
			<table width="18%" cellspacing="1" cellpadding="5" border="1" style='border-collapse:collapse' class="grid report">
					<tr>
						<th width="6%">Com.</th>
						<th width="6%">SIIL</th>
						<th width="6%">EEL</th>
					</tr>
					<?php 
					$sqlaeds = "SELECT SUM(B.Stock) as Stock From scm_solar_sc.scm_stock_sales A JOIN 
					scm_solar_sc.scm_stock_sales_item B ON A.StockSalesID= B.StockSalesID WHERE A.CompanyCd='1800' and DateAdded='$curdate' and SectorCd='T' and B.ItemCd IN ('20000120', '20000121')" ;
					$queryaeds = $objSolarCustomer->execSelectQuery($sqlaeds);
					$SAED = isset($queryaeds[0]['Stock']) ? (($queryaeds[0]['Stock'])*1500)/100000 : 0;
					
					$sqlaed30 = "SELECT SUM(B.Stock) as Stock From scm_solar_sc.scm_stock_sales A JOIN 
					scm_solar_sc.scm_stock_sales_item B ON A.StockSalesID= B.StockSalesID WHERE A.CompanyCd='1800' and DateAdded='$curdate' and SectorCd='T' and B.ItemCd IN ('20005315')" ;
					$queryaed30 = $objSolarCustomer->execSelectQuery($sqlaed30);
					$SAED30 = isset($queryaed30[0]['Stock']) ? (($queryaed30[0]['Stock'])*1000)/100000 : 0;
					
					$SAED = $SAED + $SAED30;
					
					$sqleed = "SELECT SUM(B.Stock) as Stock From scm_solar_sc.scm_stock_sales A JOIN scm_solar_sc.scm_stock_sales_item B ON A.StockSalesID= B.StockSalesID
					 WHERE A.CompanyCd='1100' and DateAdded='$curdate' and SectorCd='T' and B.ItemCd IN ('20001340', '20001341',  '20009157')" ;
					$queryeed = $objSolarCustomer->execSelectQuery($sqleed);
					$SEED = isset($queryeed[0]['Stock']) ? (($queryeed[0]['Stock'])*1500)/100000 : 0;
					
					$sqleed30 = "SELECT SUM(B.Stock) as Stock From scm_solar_sc.scm_stock_sales A JOIN scm_solar_sc.scm_stock_sales_item B ON A.StockSalesID= B.StockSalesID
					 WHERE A.CompanyCd='1100' and DateAdded='$curdate' and SectorCd='T' and B.ItemCd IN ('20002672')" ;
					$queryeed30 = $objSolarCustomer->execSelectQuery($sqleed30);
					$SEED30 = isset($queryeed30[0]['Stock']) ? (($queryeed30[0]['Stock'])*1000)/100000 : 0;
					
					$SEED = $SEED+$SEED30;
					
					$sqlA1 = "SELECT Sum(A.OrderQty) as A1  From so_expdet_magazine_item A JOIN 
					so_expdet B ON A.IdExpDet= B.IdExpdet WHERE A.ItemCd IN ('20000120', '20000121', '20005315') and StatusCd IN ('A', 'W', 'U')" ;
					$queryArrA1 = $objSolarCustomer->execSelectQuery($sqlA1);
					$siilsold= ($queryArrA1[0]['A1'])/100000;
					
					$sqlA2 = "SELECT  Sum(OrderQty) as A2 From so_expdet_magazine_item A JOIN 
					so_expdet B ON A.IdExpDet= B.IdExpdet WHERE A.ItemCd IN('20001340', '20001341', '20002672', '20009157') and StatusCd IN ('A', 'W', 'U')" ;
					$queryArrA2 = $objSolarCustomer->execSelectQuery($sqlA2);
					$eelsold= ($queryArrA2[0]['A2'])/100000;
					
					$sqlTDS = "SELECT Sum(A.OrderQty) as A1  From so_expdet_magazine_item A JOIN so_expdet B 
					ON A.IdExpDet= B.IdExpdet JOIN so_expdet_magazine C ON A.IdExpDet = C.IdExpDet AND A.MagazineCd = C.MagazineCd
					WHERE A.ItemCd IN ('20000120', '20000121', '20005315') and B.StatusCd IN ('C') AND C.SAPInvDate = '$curdate'" ;
					$queryArrTDS = $objSolarCustomer->execSelectQuery($sqlTDS);
					$siilTodayDisp= ($queryArrTDS[0]['A1'])/100000;
					
					$sqlTDE = "SELECT Sum(A.OrderQty) as A1  From so_expdet_magazine_item A JOIN so_expdet B 
					ON A.IdExpDet= B.IdExpdet JOIN so_expdet_magazine C ON A.IdExpDet = C.IdExpDet AND A.MagazineCd = C.MagazineCd
					WHERE A.ItemCd IN ('20001340', '20001341', '20002672', '20009157') and B.StatusCd IN ('C') AND C.SAPInvDate = '$curdate'" ;
					$queryArrTDE = $objSolarCustomer->execSelectQuery($sqlTDE);
					$eelTodayDisp= ($queryArrTDE[0]['A1'])/100000;
					
					
					?>
					<tr>
						<td align='left' width="6%"><b>Stock</b></td>
						<td align='center' width="6%"><?php echo sprintf('%.3f', $SAED); ?></td>
						<td align='center' width="6%"><?php echo sprintf('%.3f', $SEED); ?></td>
					</tr>
					<tr>
						<td align='left' width="6%"><b>Today Disp</b></td>
						<td align='center' width="6%"><?php echo sprintf('%.3f', $siilTodayDisp); ?></td>
						<td align='center' width="6%"><?php echo sprintf('%.3f', $eelTodayDisp); ?></td>
					</tr>
					<tr>
						<td align='left' width="6%"><b>Sold</b></td>
						<td align='center' width="6%"><?php echo sprintf('%.3f', $siilsold); ?></td>
						<td align='center' width="6%"><?php echo sprintf('%.3f', $eelsold); ?></td>
					</tr>
					<tr>
						<td align='left' width="6%"><b>Position</b></td>
						<td align='center' width="6%"><?php echo sprintf('%.3f', $possiil= $SAED-$siilTodayDisp-$siilsold); ?></td>
						<td align='center' width="6%"><?php echo sprintf('%.3f', $poseel=$SEED-$eelTodayDisp-$eelsold); ?></td>
					</tr>
					<tr>
						<td align='left' width="6%"><b>G. Position</b></td>
						<td align='center' colspan="2"><?php echo sprintf('%.3f', $Gposition= $possiil+$poseel); ?></td>
						
					</tr>
					
					
			</table>
			<br/><br/>
			
			<?php
				$sqlvanplanning = "SELECT A.DateTime, G.Descript,  F.VanNo, G.StateCd  FROM 
				(SELECT A.* FROM scm_solar_sc.vm_gate_tran A INNER JOIN 
				(SELECT A.IdVan, MAX(A.DateTime) AS DateTime FROM scm_solar_sc.vm_gate_tran A WHERE A.PlantCd=1 GROUP BY A.IdVan	) B 
				ON A.IdVan=B.IdVan AND A.DateTime=B.DateTime ) A
				LEFT OUTER JOIN scm_solar_sc.vm_gate_tran_customer B ON A.GateCd=B.GateCd AND A.IsGateIn=B.IsGateIn AND A.GateTranNo=B.GateTranNo
				LEFT OUTER JOIN scm_solar_sc.vm_van_status_m D ON A.VanStatusCd=D.VanStatusCd
				INNER JOIN scm_solar_sc.vm_gate_m E ON A.GateCd=E.GateCd AND E.PlantCd=1
				INNER JOIN scm_solar_sc.vm_van_m F ON A.IdVan=F.Idvan
				INNER JOIN scm_solar_sc.scm_party_m G ON B.CustomerCd=G.PartyCd
				WHERE (!D.IsFinal OR DATE_FORMAT(A.DateTime,'%d-%m-%Y')=DATE_FORMAT(NOW(),'%d-%m-%Y')) and A.SectorCd='T' and A.GateCd='1' and A.VanStatusCd='2' order by A.DateTime ASC Limit 1" ;
				$query = $objSolarCustomer->execSelectQuery($sqlvanplanning);
					
					$date= $query[0]['DateTime'];
					$customer= $query[0]['Descript'];
					$State= $query[0]['StateCd'];
					$VanNo= $query[0]['VanNo'];
					
					$date= date('d-m-Y', strtotime($date));
			?>
		Tomorrow First van- Dated - <?php  echo $date.", <b>".$customer .", ". $State ." </b>Vehicle No.<b>". $VanNo; ?></b>
			<br/><br/><br/>
			<h3>04. State wise Pending vans</h3>
			<table width="45%" cellspacing="1" cellpadding="5" border="1" style='border-collapse:collapse' class="grid report">
				<tr>
					<th width="5%">State</th>
					<th width="5%">No of Vans</th>
					<?php foreach($listData as $curRow) {
						$ProductName = $curRow['ProductName'];
						$ProductId = $curRow['ProductId'];
						if($ProductId !='7'){
							echo "<th width='5%'>".$ProductName ."</th>";
						}
						}
					?>
					</tr>
				<?php
				$totvans=0;
				$scmstate = "SELECT distinct(C.StateCd) as StateCd  FROM 
				(SELECT A.* FROM scm_solar_sc.vm_gate_tran A INNER JOIN 
				(SELECT A.IdVan, MAX(A.DateTime) AS DateTime FROM scm_solar_sc.vm_gate_tran A WHERE A.PlantCd=1 GROUP BY A.IdVan	) B 
				ON A.IdVan=B.IdVan AND A.DateTime=B.DateTime ) A
				LEFT OUTER JOIN scm_solar_sc.vm_gate_tran_customer B ON A.GateCd=B.GateCd AND A.IsGateIn=B.IsGateIn AND A.GateTranNo=B.GateTranNo
                LEFT OUTER JOIN scm_solar_sc.scm_party_m C ON B.CustomerCd= C.PartyCd
				LEFT OUTER JOIN scm_solar_sc.vm_van_status_m D ON A.VanStatusCd=D.VanStatusCd
				INNER JOIN scm_solar_sc.vm_gate_m E ON A.GateCd=E.GateCd AND E.PlantCd=1
				JOIN b2b_solar_sc.so_state_m F ON C.StateCd = F.StateCd 
				WHERE (!D.IsFinal OR DATE_FORMAT(A.DateTime,'%d-%m-%Y')=DATE_FORMAT(NOW(),'%d-%m-%Y')) and A.SectorCd='T' and A.GateCd='1' and A.VanStatusCd='2' and C.StateCd!='' order by F.DispOrder, A.DateTime";
				$statelist = $objSolarCustomer->execSelectQuery($scmstate);
				foreach($statelist as $state){
					$statecd=$state['StateCd'];
					$sqlwaiting = "SELECT count(distinct(A.IdVan)) as novanspen  FROM 
				(SELECT A.* FROM scm_solar_sc.vm_gate_tran A INNER JOIN 
				(SELECT A.IdVan, MAX(A.DateTime) AS DateTime FROM scm_solar_sc.vm_gate_tran A WHERE A.PlantCd=1 GROUP BY A.IdVan	) B 
				ON A.IdVan=B.IdVan AND A.DateTime=B.DateTime ) A
				LEFT OUTER JOIN scm_solar_sc.vm_gate_tran_customer B ON A.GateCd=B.GateCd AND A.IsGateIn=B.IsGateIn AND A.GateTranNo=B.GateTranNo AND A.SectorCd= B.SectorCd
                LEFT OUTER JOIN scm_solar_sc.scm_party_m C ON B.CustomerCd= C.PartyCd
				LEFT OUTER JOIN scm_solar_sc.vm_van_status_m D ON A.VanStatusCd=D.VanStatusCd
				INNER JOIN scm_solar_sc.vm_gate_m E ON A.GateCd=E.GateCd AND E.PlantCd=1
				WHERE (!D.IsFinal OR DATE_FORMAT(A.DateTime,'%d-%m-%Y')=DATE_FORMAT(NOW(),'%d-%m-%Y')) and A.SectorCd='T' and A.GateCd='1' and A.VanStatusCd='2'  and C.StateCd='$statecd'";
					$waitingvans = $objSolarCustomer->execSelectQuery($sqlwaiting);
					$pendvans= $waitingvans[0]['novanspen'];
					$totvans=$pendvans+$totvans;
					
				$sqlwaitingPO = "SELECT distinct(B.PONo)  FROM 
				(SELECT A.* FROM scm_solar_sc.vm_gate_tran A INNER JOIN 
				(SELECT A.IdVan, MAX(A.DateTime) AS DateTime FROM scm_solar_sc.vm_gate_tran A WHERE A.PlantCd=1 GROUP BY A.IdVan	) B 
				ON A.IdVan=B.IdVan AND A.DateTime=B.DateTime ) A
				LEFT OUTER JOIN scm_solar_sc.vm_gate_tran_customer B ON A.GateCd=B.GateCd AND A.IsGateIn=B.IsGateIn AND A.GateTranNo=B.GateTranNo AND A.SectorCd= B.SectorCd
                LEFT OUTER JOIN scm_solar_sc.scm_party_m C ON B.CustomerCd= C.PartyCd
				LEFT OUTER JOIN scm_solar_sc.vm_van_status_m D ON A.VanStatusCd=D.VanStatusCd
				INNER JOIN scm_solar_sc.vm_gate_m E ON A.GateCd=E.GateCd AND E.PlantCd=1
				WHERE (!D.IsFinal OR DATE_FORMAT(A.DateTime,'%d-%m-%Y')=DATE_FORMAT(NOW(),'%d-%m-%Y')) and A.SectorCd='T' and A.GateCd='1' and A.VanStatusCd='2'  and C.StateCd='$statecd'";
				$waitingvanspo = $objSolarCustomer->execSelectQuery($sqlwaitingPO);
				$statepolist='';
					foreach($waitingvanspo as $POlist) {
						$PONo= $POlist['PONo'];	
						$statepolist  = $PONo.", ".$statepolist;
					}
					$statepolist=substr($statepolist,0, -2);
			
				?>	
				<tr align='center'>
					<td align="" width="5%"><b><?php echo $statecd; ?></b></td>
					<td align="" width="5%"><?php echo $pendvans; ?></td>
					<?php 
						$StateProdSum = 0;
						foreach($listData as $curRow) {
							$ItemCd = $curRow['ItemCd'];
							$ProductId = $curRow['ProductId'];
							$Divide= $curRow['DividedBy'];
							$ItemType= $curRow['ItemType'];
							
							$sqlcountPO = "SELECT sum(OrderQty)as OrderQty  FROM so_expdet_magazine_item where IdExpDet IN ($statepolist) and ItemCd IN ($ItemCd)";
							$orderboxpo = $objSolarCustomer->execSelectQuery($sqlcountPO);
							$OrderQty= $orderboxpo[0]['OrderQty']/$Divide;
							if($ItemType =='Deto')
							{
								$OrderQty = sprintf('%.3f', $OrderQty);								
							}
							$StateProdSum = 'Tot_'.$ProductId;
							$$StateProdSum +=  $OrderQty;
							if($ProductId !='7'){
								echo "<td width='5%'>".$OrderQty ."</td>";
							}
						}
					?>
					
				</tr>
				<?php
				
				}
				?>
				<tr align='center'>
					<td  width="5%"><b>Total Van</b></td>
					<td  width="5%"><b><?php echo $totvans; ?></b></td>
					<?php 
					$ProductId = 1;
					foreach($listData as $curRow) {
							$ItemCd = $curRow['ItemCd'];
							$ProductId = $curRow['ProductId'];
							$TotalProd = 'Tot_'.$ProductId;
							if($ProductId!='7'){
							echo "<td width='5%'><b>".$$TotalProd."</b></td>";
							}
							$ProductId++;
						}
					?>
				
				</tr>
			</table>
			<br/><br/><br/>
			<h3>05. State wise todays dispatch</h3>
			<table width="50%" cellspacing="1" cellpadding="5" border="1" style="border-collapse:collapse;" class="grid report">
			<?php 
				$itemCdList= substr(trim($itemCdList), '1');
				
				$droptemp = "DROP TABLE IF EXISTS dispreport";
				$droptemptable = $objSolarCustomer->execSelectQuery($droptemp);

				$createtemp = "CREATE TABLE dispreport (StateCd varchar(5))";
				$temptable = $objSolarCustomer->execSelectQuery($createtemp);
				
				$insertdisprep= "INSERT INTO dispreport (StateCd) SELECT Distinct(D.StateCd) as StateCd From so_expdet_magazine_item A JOIN so_expdet B  ON A.IdExpDet = B.IdExpDet JOIN so_expdet_magazine C ON A.IdExpDet = C.IdExpDet
				JOIN so_customer_m D ON D.CustomerCd= B.CustomerCd WHERE A.ItemCd IN ($itemCdList) and DATE(C.SAPInvDate)='$curdate'";
				
				$list = $objSolarCustomer->execUpdateQuery($insertdisprep);
				
				$sqlstate = " INSERT INTO dispreport (StateCd)  SELECT Distinct(B.StateCd) as StateCd From so_accessory A JOIN so_customer_m B  ON A.CustomerCd = B.CustomerCd
					WHERE A.AccessoryCtgCd IN ('7', '6') and StatusCd IN ('A', 'S') and DATE(A.SAPInvDate)='$curdate'";
				
				$liststate = $objSolarCustomer->execUpdateQuery($sqlstate);
				
			//	$sqlstate ="select distinct(StateCd) as StateCd from dispreport A  JOIN so_state_m B ON A.StateCd = B.StateCd order by B.DispOrder ASC";
				$sqlstate ="select distinct(A.StateCd) as StateCd from dispreport A  JOIN so_state_m B  ON A.StateCd= B.StateCd where 1 order By B.DispOrder ";
				$listofstate = $objSolarCustomer->execSelectQuery($sqlstate);
				
				?>
			<tr>
				<th align="center" width="5%">Product</th>
				<?php foreach($listofstate as $StateCdlist)
				{
					echo "<th  align='center' width='5%'> ".$StateCdlist['StateCd']."</th>";
				}
				?>
				<th align="center" width="5%">Total</th>
				<th align="center" width="5%">CUMU</th>
				<th align="center" width="5%">AVG</th>	
			</tr>
			<?php 
			$preitemtype='';
			$tottar=$totcumutar=0;
			$Exploitemlist='';
			foreach($listData as $curRow) {
			$ProductId= $curRow['ProductId'];
			$ItemCd= $curRow['ItemCd'];
			$POType= $curRow['POType'];
			$Divide= $curRow['DividedBy'];
			
			if($curRow['ItemType']=='Explo'){
				$Exploitemlist=$Exploitemlist.",".$ItemCd;
			}
			$itemCdList= $itemCdList.",".$ItemCd;
		
			$curitemtype =$curRow['ItemType'];
			
			$sqluptd = "SELECT sum(A.DespatchedQty) as DespatchedQty From so_expdet_magazine_item A JOIN so_expdet B ON A.IdExpDet= B.IdExpDet JOIN
			so_expdet_magazine C ON A.IdExpDet= C.IdExpdet and A.MagazineCd=C.MagazineCd WHERE  A.ItemCd IN ($ItemCd) 
			and StatusCd IN ('C', 'B') and DATE(C.SAPInvDate) between '$first_day_this_month' and '$last_day_this_month'" ;
			if($POType=='1'){
				$sqluptd = "SELECT sum(A.TotalMtr) as DespatchedQty From so_accessory A JOIN so_customer_m B ON A.CustomerCd= B.CustomerCd 
				WHERE  A.AccessoryCtgCd IN ('7', '6') and StatusCd IN ('A', 'S') and DATE(A.SAPInvDate) between '$first_day_this_month' and '$last_day_this_month' 
				" ;
			}
			
			$UptoDisp = $objSolarCustomer->execSelectQuery($sqluptd);
			$uptodis=$UptoDisp[0]['DespatchedQty']/$Divide;
			$avg= $uptodis/$uptoday;
			
			
			
			if($preitemtype!='' && $curitemtype!=$preitemtype){
		
			?>
			<tr align='right' style='font-weight:bold'>
				<td align="left" width="5%">Tot Exp</td>
				<?php 
					$Exploitemlist= substr(trim($Exploitemlist), '1');
				foreach($listofstate as $StateCdlist) {
				$StateCd=$StateCdlist['StateCd'];
			
				$sqltot = "SELECT sum(A.DespatchedQty) as DespatchedQty From so_expdet_magazine_item A JOIN so_expdet B ON A.IdExpDet= B.IdExpDet JOIN
				so_expdet_magazine C ON A.IdExpDet= C.IdExpdet and A.MagazineCd=C.MagazineCd JOIN so_customer_m D ON D.CustomerCd= B.CustomerCd
				WHERE  A.ItemCd IN ($Exploitemlist) and StatusCd IN ('C', 'B') and DATE(C.SAPInvDate)='$curdate' and D.StateCd='$StateCd'" ;
				$stateDisptot = $objSolarCustomer->execSelectQuery($sqltot);
				
				echo "<td width='5%'>".$stateDisptot[0]['DespatchedQty']."</td>";
				}
				?>
				<td width="5%"><?php echo sprintf('%.3f', $tottar); ?></td>
				<td width="5%"><?php echo sprintf('%.3f', $totcumutar); ?></td>
				<td width="5%"></td>
			</tr>
			
			<tr align="right">
				<td align="left" width="5%"><?php echo $curRow['ProductName']; ?></td>
				<?php
				$totalstatedis=0;
				foreach($listofstate as $StateCdlist) {
			
				$StateCd=$StateCdlist['StateCd'];
				$sqlstd = "SELECT sum(A.DespatchedQty) as DespatchedQty From so_expdet_magazine_item A JOIN so_expdet B ON A.IdExpDet= B.IdExpDet JOIN
				so_expdet_magazine C ON A.IdExpDet= C.IdExpdet and A.MagazineCd=C.MagazineCd JOIN so_customer_m D ON D.CustomerCd= B.CustomerCd
				WHERE  A.ItemCd IN ($ItemCd) and StatusCd IN ('C', 'B') and DATE(C.SAPInvDate)='$curdate' and D.StateCd='$StateCd'" ;
				$TodayDispSt = $objSolarCustomer->execSelectQuery($sqlstd);
				
				$todaydisst=$TodayDispSt[0]['DespatchedQty']/$Divide;
				$totalstatedis=$totalstatedis+$todaydisst;
			
			?>
				<td width="5%"><?php echo $todaydisst; ?></td>
			<?php }
			?>
				<td width="5%"><?php if($totalstatedis!=0){ echo sprintf('%.3f', $totalstatedis); } else echo ''; ?></td>
				<td width="5%"><?php if($uptodis!=0){ echo sprintf('%.3f', $uptodis); } else echo ''; ?></td>
				<td width="5%"><?php echo sprintf('%.3f', $avg); ?></td>
			</tr>
			<?php 
			$preitemtype= $curitemtype;
			
			}else{ ?>
			<tr align="right">
				<td align="left" width="5%"><?php echo $curRow['ProductName']; ?></td>
			<?php
			$totalstatedis=0;
			foreach($listofstate as $StateCdlist) {
			
			$StateCd=$StateCdlist['StateCd'];
			$sqlstd = "SELECT sum(A.DespatchedQty) as DespatchedQty From so_expdet_magazine_item A JOIN so_expdet B ON A.IdExpDet= B.IdExpDet JOIN
			so_expdet_magazine C ON A.IdExpDet= C.IdExpdet and A.MagazineCd=C.MagazineCd JOIN so_customer_m D ON D.CustomerCd= B.CustomerCd
			WHERE  A.ItemCd IN ($ItemCd) and StatusCd IN ('C', 'B') and DATE(C.SAPInvDate)='$curdate' and D.StateCd='$StateCd'" ;
			$TodayDispSt = $objSolarCustomer->execSelectQuery($sqlstd);
			
			if($POType==1){
				$sqlstd = "SELECT sum(A.TotalMtr) as DespatchedQty From so_accessory A JOIN so_customer_m B ON A.CustomerCd= B.CustomerCd 
				WHERE  A.AccessoryCtgCd IN ('7', '6') and StatusCd IN ('A', 'S') and DATE(A.SAPInvDate)='$curdate' and B.StateCd='$StateCd'" ;
				$TodayDispSt = $objSolarCustomer->execSelectQuery($sqlstd);
			}
			
			$todaydisst=$TodayDispSt[0]['DespatchedQty']/$Divide;
			$totalstatedis=$totalstatedis+$todaydisst;
			
			?>
				<td width="5%"><?php echo $todaydisst; ?></td>
			<?php }
			?>
				<td width="5%"><?php if($totalstatedis!=0){ echo sprintf('%.3f', $totalstatedis); } else echo ''; ?></td>
				<td width="5%"><?php if($uptodis!=0){ echo sprintf('%.3f', $uptodis); } else echo ''; ?></td>
				<td width="5%"><?php echo sprintf('%.3f', $avg); ?></td>
			</tr>
			<?php
			
			}
			$tottar=$tottar+$totalstatedis;
			$totcumutar=$totcumutar+$uptodis;
			$preitemtype=$curitemtype;
			
			}
			
			?>
		</table>
		<br/><br/><br/>
		<h3>06. State wise cumulative Sale </h3>
			<table width="50%" cellspacing="1" cellpadding="5" border="1" style="border-collapse:collapse;" class="grid report">
			<?php 
				$itemCdList= substr(trim($itemCdList), '1');
				
				$droptemp = "DROP TABLE IF EXISTS dispreport1";
				$droptemptable = $objSolarCustomer->execSelectQuery($droptemp);

				$createtemp = "CREATE TABLE dispreport1 (StateCd varchar(5))";
				$temptable = $objSolarCustomer->execSelectQuery($createtemp);
				
				$insertdisprep= "INSERT INTO dispreport1 (StateCd) SELECT Distinct(D.StateCd) as StateCd From so_expdet_magazine_item A JOIN so_expdet B  ON A.IdExpDet = B.IdExpDet JOIN so_expdet_magazine C ON A.IdExpDet = C.IdExpDet
				JOIN so_customer_m D ON D.CustomerCd= B.CustomerCd WHERE A.ItemCd IN ($itemCdList)  and DATE(C.SAPInvDate) between '$first_day_this_month' and '$last_day_this_month' ";
				
				$list = $objSolarCustomer->execUpdateQuery($insertdisprep);
				
				$sqlstate = " INSERT INTO dispreport1 (StateCd)  SELECT Distinct(B.StateCd) as StateCd From so_accessory A JOIN so_customer_m B  ON A.CustomerCd = B.CustomerCd
					WHERE A.AccessoryCtgCd IN ('7', '6') and StatusCd IN ('A', 'S') ";
				
				$liststate = $objSolarCustomer->execUpdateQuery($sqlstate);
				
				$sqlstate ="select distinct(A.StateCd) as StateCd from dispreport1 A  JOIN so_state_m B  ON A.StateCd= B.StateCd Where 1 order By B.DispOrder ";
				$listofstate = $objSolarCustomer->execSelectQuery($sqlstate);
				
				?>
			<tr>
				<th align="center" width="5%">Product</th>
				<?php foreach($listofstate as $StateCdlist)
				{
					echo "<th  align='center' width='5%'> ".$StateCdlist['StateCd']."</th>";
				}
				?>
				<th align="center" width="5%">Total</th>
				
			</tr>
			<?php 
			$preitemtype='';
			$tottar=$totcumutar=0;
			$Exploitemlist='';
			foreach($listData as $curRow) {
			$ProductId= $curRow['ProductId'];
			$ItemCd= $curRow['ItemCd'];
			$POType= $curRow['POType'];
			$Divide= $curRow['DividedBy'];
			
			if($curRow['ItemType']=='Explo'){
				$Exploitemlist=$Exploitemlist.",".$ItemCd;
			}
			$itemCdList= $itemCdList.",".$ItemCd;
		
			$curitemtype =$curRow['ItemType'];
			
			$sqluptd = "SELECT sum(A.DespatchedQty) as DespatchedQty From so_expdet_magazine_item A JOIN so_expdet B ON A.IdExpDet= B.IdExpDet JOIN
			so_expdet_magazine C ON A.IdExpDet= C.IdExpdet and A.MagazineCd=C.MagazineCd WHERE  A.ItemCd IN ($ItemCd) 
			and StatusCd IN ('C', 'B')  and DATE(C.SAPInvDate) between '$first_day_this_month' and '$last_day_this_month'" ;
			if($POType=='1'){
				$sqluptd = "SELECT sum(A.TotalMtr) as DespatchedQty From so_accessory A JOIN so_customer_m B ON A.CustomerCd= B.CustomerCd 
				WHERE  A.AccessoryCtgCd IN ('7', '6') and StatusCd IN ('A', 'S') and DATE(SAPInvDate) between '$first_day_this_month' and '$last_day_this_month'" ;
			}
			
			$UptoDisp = $objSolarCustomer->execSelectQuery($sqluptd);
			$uptodis=($UptoDisp[0]['DespatchedQty'])/$Divide;
			$avg= $uptodis/$uptoday;
			
			
			
			if($preitemtype!='' && $curitemtype!=$preitemtype){
		
			?>
			<tr align='right' style='font-weight:bold'>
				<td align="left" width="5%">Tot Exp</td>
				<?php 
				$Exploitemlist= substr(trim($Exploitemlist), '1');
				foreach($listofstate as $StateCdlist) {
				$StateCd=$StateCdlist['StateCd'];
				
				$sqltot = "SELECT sum(A.DespatchedQty) as DespatchedQty From so_expdet_magazine_item A JOIN so_expdet B ON A.IdExpDet= B.IdExpDet JOIN
				so_expdet_magazine C ON A.IdExpDet= C.IdExpdet and A.MagazineCd=C.MagazineCd JOIN so_customer_m D ON D.CustomerCd= B.CustomerCd
				WHERE  A.ItemCd IN ($Exploitemlist) and StatusCd IN ('C', 'B') and D.StateCd='$StateCd' and DATE(C.SAPInvDate) between '$first_day_this_month' and '$last_day_this_month'" ;
				$stateDisptot = $objSolarCustomer->execSelectQuery($sqltot);
				
				echo "<td width='5%'>".sprintf('%.3f',$stateDisptot[0]["DespatchedQty"])."</td>";
				}
				?>
				<td width="5%"><?php echo sprintf('%.3f', $tottar); ?></td>
				
			</tr>
			
			<tr align="right">
				<td align="left" width="5%"><?php echo $curRow['ProductName']; ?></td>
				<?php
				$totalstatedis=0;
				foreach($listofstate as $StateCdlist) {
			
				$StateCd=$StateCdlist['StateCd'];
				$sqlstd = "SELECT sum(A.DespatchedQty) as DespatchedQty From so_expdet_magazine_item A JOIN so_expdet B ON A.IdExpDet= B.IdExpDet JOIN
				so_expdet_magazine C ON A.IdExpDet= C.IdExpdet and A.MagazineCd=C.MagazineCd JOIN so_customer_m D ON D.CustomerCd= B.CustomerCd
				WHERE  A.ItemCd IN ($ItemCd) and StatusCd IN ('C', 'B')  and D.StateCd='$StateCd' and D.StateCd='$StateCd' and DATE(C.SAPInvDate) between '$first_day_this_month' and '$last_day_this_month'" ;
				$TodayDispSt = $objSolarCustomer->execSelectQuery($sqlstd);
				
				$todaydisst=$TodayDispSt[0]['DespatchedQty']/$Divide;
				$totalstatedis=$totalstatedis+$todaydisst;
			
			?>
				<td width="5%"><?php echo sprintf('%.3f', $todaydisst); ?></td>
			<?php }
			?>
				<td width="5%"><?php if($totalstatedis!=0){ echo sprintf('%.3f', $totalstatedis); } else echo ''; ?></td>
				
			</tr>
			<?php 
			$preitemtype= $curitemtype;
			
			}else{ ?>
			<tr align="right">
				<td align="left" width="5%"><?php echo $curRow['ProductName']; ?></td>
			<?php
			$totalstatedis=0;
			foreach($listofstate as $StateCdlist) {
			
			$StateCd=$StateCdlist['StateCd'];
			$sqlstd = "SELECT sum(A.DespatchedQty) as DespatchedQty From so_expdet_magazine_item A JOIN so_expdet B ON A.IdExpDet= B.IdExpDet JOIN
			so_expdet_magazine C ON A.IdExpDet= C.IdExpdet and A.MagazineCd=C.MagazineCd JOIN so_customer_m D ON D.CustomerCd= B.CustomerCd
			WHERE  A.ItemCd IN ($ItemCd) and StatusCd IN ('C', 'B')  and D.StateCd='$StateCd' and D.StateCd='$StateCd' and DATE(C.SAPInvDate) between '$first_day_this_month' and '$last_day_this_month'" ;
			$TodayDispSt = $objSolarCustomer->execSelectQuery($sqlstd);
			
			if($POType==1){
				$sqlstd = "SELECT sum(A.TotalMtr) as DespatchedQty From so_accessory A JOIN so_customer_m B ON A.CustomerCd= B.CustomerCd 
				WHERE  A.AccessoryCtgCd IN ('7', '6') and StatusCd IN ('A', 'S')  and B.StateCd='$StateCd' and DATE(SAPInvDate) between '$first_day_this_month' and '$last_day_this_month'" ;
				$TodayDispSt = $objSolarCustomer->execSelectQuery($sqlstd);
			}
			
			$todaydisst=$TodayDispSt[0]['DespatchedQty']/$Divide;
			$totalstatedis=$totalstatedis+$todaydisst;
			
			?>
				<td width="5%"><?php echo sprintf('%.3f', $todaydisst); ?></td>
			<?php }
			?>
				<td width="5%"><?php if($totalstatedis!=0){ echo sprintf('%.3f', $totalstatedis); } else echo ''; ?></td>
				
			</tr>
			<?php
			
			}
			$tottar=$tottar+$totalstatedis;
			$totcumutar=$totcumutar+$uptodis;
			$preitemtype=$curitemtype;
			
			}
			?>
		</table>
		</div>
		
		</td>
		</tr>
		<tr>
		<td>
			<table cellspacing="0" cellpadding="0"><tr><td class="button-left-bg"></td><td class="button-center-bg"><a href ="special/senddailydispatchreport.php" ><input type="button" id="btnDownload" name="btnDownload" value="Send Report"></td><td class="button-right-bg"></td></tr></table>
		</td>
	</tr>
</table>
<script type="Text/javascript">

$(function() {
	$("#DailyDispatchReportDate").datepicker({ dateFormat: 'dd-mm-yy',  minDate: '12-06-2016', maxDate: '-1' });
});


function ShowDailyDispatchReport() {
	var DailyDispatchReportDate = $('#DailyDispatchReportDate').val();
	alert(DailyDispatchReportDate);
	window.open('http://solarexplosives.com/B2B/upload/DailyDispatchReport/DailyDispatchReport_'+DailyDispatchReportDate+'.pdf', 'mywindow', 'status=0,width=1002,height=600');
}
</script>
<?php
//$droptable= "DROP TABLE dispreport";
//$droptable = $objSolarCustomer->execSelectQuery($droptable);

//$droptable1= "DROP TABLE dispreport1";
//$droptable1 = $objSolarCustomer->execSelectQuery($droptable1);
include('includes/footer.php');
?>
