<?php ob_start();
session_name('CAKEPHP'); session_start();
include("reportconfig.php");
$data='';
$data.="<table width='100%' border='0' cellspacing='1' cellpadding='0' style='border:1px solid #ccc; background-color:#FFF'>";
$data.="<tr>";
    	      $data.="<td><table width='100%' border='0' cellspacing='0' cellpadding='5'>
    	        <tr>";
                 if($_SESSION['client']!=''){
                 	$data.="<td width='10%'><strong>Party Name</strong></td>";
    	          $data.="<td width='22%'>";
    	          $p=mysqli_query($con, "Select c_name from clientmaster where id='".$_SESSION['client']."'");
    	          	$pRes=mysqli_fetch_array($p); $pRes['c_name'];
    	          	$data.="</td>"; } 
    	          	 if($_SESSION['item']!='' ){    	          	 	
	                    $itemString1="'".implode("','",$_SESSION['item'])."'";  
					$itemstr=explode(',',$itemString1);					
					if(count($itemstr)<=1) {
						$data.="<td width='10%'><strong>Item Name</strong></td><td>";
    	        	   	$pp=mysqli_query($con, "select item_name from item_master where StockID=$itemString1");
    	          	$pResp=mysqli_fetch_array($pp); echo $pResp['item_name'];
					$data.=$pResp['item_name']."</td>";
    	          	 } }
                  $data.="</tr>";
  	        $data.="</table></td></tr>";
    	    $data.="<tr>";
    	      $data.="<td><table width='100%' border='0' cellspacing='1' cellpadding='1'>";
    	        $data.="<tr>";
	  $data.="<th scope='col'>Invoice No. </th>";
	  $data.="<th scope='col'>Invoice Date</th>";
	  $data.="<th scope='col'>Party Name</th>";
	  $data.="<th scope='col'>Basic Amt</th>";
	 $data.="<th scope='col'>Discounted Amt</th>";
	  $data.="<th scope='col'>Pkg Charges<br /></th>";
	  $data.="<th scope='col'>Excise Duty Amt </th>";
	  $data.="<th scope='col'>E-Cess</th>";
	  $data.="<th scope='col'>SAH- E Cess</th>";
	  $data.="<th scope='col'>Tax Amt</th>";
	  $data.="<th scope='col'>Freight Charges</th>";
	  $data.="<th scope='col'>Other Amt</th>";
	  $data.="<th scope='col'>Gross Amt</th>"; 
      $data.="</tr>";   
	 		$sql1=$_SESSION['data1'];
        $result1 = mysqli_query($con, $sql1);
        $k=1;
    
while($row1=mysqli_fetch_array($result1))
{ 	          
    $data.="<tr bgcolor='#FFFFFF'>"; 
    $data.="<td>".$row1['invoiceNo']."</td>";
	$data.="<td>".$row1['invoiceDate']."</td>";
	  $data.="<td>".$s->getField('clientmaster','id',$row1['client_id'],'c_name')."</td>";
	 $data.="<td>".$row1['Amount']."</td>";
	 $data.="<td>".$row1['discount']."</td>";
	 $data.="<td>".$row1['packagingCharges']."</td>";
	$data.="<td>".$row1['exciseValue']."</td>";
	$data.="<td>".$row1['ECessValue']."</td>";
	$data.="<td>".$row1['SAHCessValue']."</td>";
	$data.="<td>".$row1['VatCstValue']."</td>";
	 $data.="<td>".$row1['freightValue']."</td>";
	 $data.="<td>".$row1['additionalCharges']."</td>";
	 $data.="<td>".$row1['grandTotal']."</td>";
   $data.="</tr>";
    $k++; 	}                  
  	          	$t=0;
			   $totalQty=0;
			   $totalWeight=0;
			   $totalPacketNo=0;
			   $totalPieces=0;
			   $totalPieces1=0;$totalPieces2=0;$totalPieces3=0;$totalPieces4=0;$totalPieces5=0;$totalPieces6=0;
			   $result12=mysqli_query($con, $sql1);
			   while($row1=mysqli_fetch_array($result12))
                 {                 	
                 if(!empty($_SESSION['item'])){ 	 
  	          	$totalQty=$totalQty+$row1['Amount'];					 
  	          	}
				 else {
					  $totalQty=$totalQty+$row1['basicAmount'];
				 }
					
  	          	$totalWeight=$totalWeight+$row1['discount'];
				$totalPacketNo=$totalPacketNo+$row1['packagingCharges'];
				$totalPieces=$totalPieces+$row1['exciseValue'];
				$totalPieces1=$totalPieces1+$row1['ECessValue'];
				$totalPieces2=$totalPieces2+$row1['SAHCessValue'];
				$totalPieces3=$totalPieces3+$row1['VatCstValue'];
				$totalPieces4=$totalPieces4+$row1['freightValue'];
				$totalPieces5=$totalPieces5+$row1['additionalCharges'];
				$totalPieces6=$totalPieces6+$row1['grandTotal'];
  	          	 }
				 
    	        $data.="<tr  bgcolor='#f2f2f2'>";
    	          $data.="<td>&nbsp;</td>";
    	          $data.="<td>&nbsp;</td>";
    	          
    	         $data.="<td align='right' style='text-align:right;'><strong>Total:</strong></td>";    	          
    	          $data.="<td><strong>".round($totalQty,2)."</strong></td>";
    	           $data.="<td><strong>".round($totalWeight,2)."</strong></td>";
    	            $data.="<td><strong>".round($totalPacketNo,2)."</strong></td>";
    	            $data.="<td><strong>".round($totalPieces,2)."</strong></td>";
    	            $data.="<td><strong>".round($totalPieces1,2)."</strong></td>";
    	            $data.="<td><strong>".round($totalPieces2,2)."</strong></td>";
    	           $data.="<td><strong>".round($totalPieces3,2)."</strong></td>";
    	            $data.="<td><strong>".round($totalPieces4,2)."</strong></td>";
    	            $data.="<td><strong>".round($totalPieces5,2)."</strong></td>";
    	            $data.="<td><strong>".round($totalPieces6,2)."</strong></td>";
  	          $data.="</tr>";	
  	        $data.="</table></td></tr></td></tr></table></td></tr></table>";  	     
			$header=''; 
  	   header("Content-type: application/x-msdownload"); 
header("Content-Disposition: attachment; filename=data1.xls"); 
header("Pragma: no-cache"); 
header("Expires: 0"); 
print "$header\n$data";  
?>