<form action="" method="post">
<table width="100%" border="0" cellspacing="0" cellpadding="3">
  <tr class="row1">
    <td width="12%" align="right">Branch</td>
    <td width="35%"><select name="site" id="site" >
<?php 
  $site_sql=DB_query("Select loccode,prefix, locationname from locations",$db); 
while($site_row=DB_fetch_array($site_sql)){
?>
<option value="<?php echo $site_row['loccode'];?>"<?php echo ($_REQUEST['site']==$site_row['loccode']?'selected':'');?>><?php echo $site_row['locationname'];?></option>
<?php } ?>
</select></td>   
    <td width="20%" align="right">Year</td>
    <td><select name="payyear"  >
 <?php
 
 for($i=date('Y');$i>2000;$i--)
 {
 	$p='';
 	if( $i==$_REQUEST['payyear'])
	$p='selected';
 ?><option value="<?php echo $i;?>" <?php echo $p;?>><?php echo $i;?></option>
 <?php 
 }
 ?></select></td>
 </tr>  
  <tr class="row1">
    <td colspan="4" style="text-align:center;"><input type="submit" name="Search" class="search" value="Search"/></td>
    </tr>
</table>
	
</form>
<p align="right"><a href="AnnexureReportPrint.php" class="search">Export</a></p>

<div style="width:1250px; margin:auto; overflow:auto;">
<table width="2500" border="0" cellspacing="0" cellpadding="3" class="thborder">
  <tr>
    <th width="3%">C01</th>
    <th width="4%">Year &amp; (Month or Quarter) (YYYYMM or YYYYQQ) (C02)</th>
    <th width="4%">Seller’s TIN (C03)</th>
    <th width="4%">Seller’s Name (C04)</th>
    <th width="4%">Import from Outside India (C05)</th>
    <th width="4%">High Seas Purchase (C06)</th>
    <th width="4%">Own Goods Received Back after job work against F-Form (C07)</th>
    <th>Purchase from Unregistered Dealer/Composition Dealer/Non Creditable Goods/Against Retail Invoices/Tax free Goods/Labour &amp; Services related to work contract/Tax invoices not eligible for ITC/Delhi dealers against Form-H/Capital Goods(Used for manufacturing of non-creditable goods) (C08)</th>
    <th width="4%">Other Dealer Received for job work against F-form (C09)</th>
    <th width="4%">Capital Goods Purchase Against C-Form (C10)</th>
    <th width="4%">Goods (Other than capital goods) purchased against C-Forms (C11)</th>
    <th width="4%">Inter state Purchase against H-Form (other than Delhi dealers) (C12)</th>
    <th width="4%">Inter state Purchase without Forms (C13)</th>
    <th width="4%">Inward Stock Transfer (Branch) against F-Form (C14)</th>
    <th width="4%">Inward Stock Transfer (Consignment) against F-Form (C15)</th>
    <th width="4%">Local Purchase eligible-Capital Goods-Rate of Tax (C16)</th>
    <th width="4%">Local Purchase eligible-Capital Goods-Purchase Amount (C17)</th>
    <th width="4%">Local Purchase eligible-Capital Goods-Input Tax Paid (C18)</th>
    <th width="4%">Local Purchase eligible-Capital Goods-Total Purchase including Tax (C19)</th>
    <th width="4%">Type of Purchase (C20)</th>
    <th width="4%">Local Purchase eligible-Others-Rate of Tax (C21)</th>
    <th width="4%">Local Purchase eligible-Others-Purchase Amount (C22)</th>
    <th width="3%">Local Purchase eligible-Others-Input Tax Paid (23)</th>
    <th width="3%">Local Purchase eligible-Others-Total Purchase including Tax (C24)</th>
    <th width="3%">Rate of Tax on the Item under Delhi Value Added Tax Act,2004(C25)</th>
    <th width="3%">Does this purchase pertain to dispatches made by seller is previous Quarter? (Yes,No) (C26)</th>
  </tr>
  <?php 
if($_REQUEST['Search'])
{
    $month_array=array("01"=>"04","02"=>"04","03"=>"04","04"=>"01","05"=>"01","06"=>"01","07"=>"02","08"=>"02","09"=>"03","10"=>"03","11"=>"03","12"=>"03");
   $paystatus=true;  
   $site=$_REQUEST['site'];
   $years=$_REQUEST['payyear'];
   $month=$_REQUEST['paymonth'];


 $filter='';
 if($site!='All' )
   $filter[]=" site='".$site."' ";
 if($years!='All' )
   $filter[]=" year(bill_book_date)='".$years."' ";
if(!empty($filter))
{
    $filter1=implode(" and ",$filter);
}
 
   
 
   
  
    $query1="select  * from purchase_billbook  where $filter1 group by vendor  order by bill_book_date desc,vendor ASC";

//$_SESSION['Annexure']=$query1;
    $result1=DB_query($query1,$db);
    $numrows = DB_num_rows($result1);
    $assess_array=array();
    $charge_array=array();
    $gtotal_array=array();
    $i=1;           
    if($numrows>0)
    {
        while($myrow=DB_fetch_array($result1) )
        {
      
         $time=strtotime($myrow['bill_book_date']);
         $month=date("m",$time);
         if($month)
         $year=date("Y",$time).$month_array[$month];    
         $yeardata[]=$year;
         $vendor_type=$s->getField('suppliers','id',$myrow['vendor'],'vendor_type');
         if($vendor_type=='International')
         $C05=$s->GetFieldValue("purchase_billbook","vendor='".$myrow['vendor']."'","sum(GrandTotal)"); 
         else $C05='0.00';
         $C06='0.00';
         // $C07 values will be come from job work bill
         $C07="0.00";    
         $vendorid[]=$myrow['vendor'];     
         $tinno=$s->getField('suppliers','id',$myrow['vendor'],'tin_no');
         $vendor_name=$s->getField('suppliers','id',$myrow['vendor'],'vendor_name');
         if($tinno=='')
         $C08=$s->GetFieldValue("purchase_billbook","vendor='".$myrow['vendor']."'","sum(GrandTotal)");   
         else $C08='0.00';
         $C09='0.00';
         $cform=$s->getField('form_type_master','form_name','FORM C','id');
         $hform=$s->getField('form_type_master','form_name','FORM H','id');
         $Wform=$s->getField('form_type_master','form_name','NONE','id');
         $C10=$s->GetFieldValue("purchase_billbook","vendor='".$myrow['vendor']."' and po_cat='AT' and form_type='".$cform."'","sum(GrandTotal)"); 
         if($C10=='') $C10='0.00';
         $C11=$s->GetFieldValue("purchase_billbook","vendor='".$myrow['vendor']."' and po_cat='MT' and form_type='".$cform."'","sum(GrandTotal)");    
         if($C11=='') $C11='0.00';
          $vendor_state=$s->GetFieldValue("suppliers","id='".$myrow['vendor']."' ","state");    
         $state=$s->GetFieldValue("state_master","id='".$vendor_state."' ","state");
         if($state!='DELHI') 
         {   
         $C12=$s->GetFieldValue("purchase_billbook","vendor='".$myrow['vendor']."'  and form_type='".$cform."'","sum(GrandTotal)");    
         }
         if($C12=='') $C12='0.00';
          if($state!='DELHI') 
         {   
         $C13=$s->GetFieldValue("purchase_billbook","vendor='".$myrow['vendor']."'  and form_type!='".$cform."'","sum(GrandTotal)");    
         }
         if($C13=='') $C13='0.00';
         $C14='0.00';
         $C15='0.00';
         $vatcst_asset=$s->GetFieldValue("purchase_billbook","vendor='".$myrow['vendor']."' and po_cat='AT' and form_type='".$Wform."'","vat_cst");
         $C16=$s->getField('sales_tax_master','salestax_id',$vatcst_asset,'taxrate');
         $C17=$s->GetFieldValue("purchase_billbook","vendor='".$myrow['vendor']."' and po_cat='AT' and form_type='".$Wform."'","sum(tot_tax_amt)");
           if($C17=='') $C17='0.00';
         $C18=$s->GetFieldValue("purchase_billbook","vendor='".$myrow['vendor']."' and po_cat='AT' and form_type='".$Wform."'","sum(taxvalue)");
           if($C18=='') $C18='0.00';
         $C19=$C17+$C18;
         if($tinno!='' && $myrow['po_cat']='MT') { $C20='GD';} else if($tinno=='' && $myrow['po_cat']='MT') { $C20='PUR';}
         $vatcst_material=$s->GetFieldValue("purchase_billbook","vendor='".$myrow['vendor']."' and po_cat='MT' and form_type='".$Wform."'","vat_cst");
         $C21=$s->getField('sales_tax_master','salestax_id',$vatcst_material,'taxrate');
         $C22=$s->GetFieldValue("purchase_billbook","vendor='".$myrow['vendor']."' and po_cat='MT' and form_type='".$Wform."' ","sum(tot_tax_amt)");
           if($C22=='') $C22='0.00';
         $C23=$s->GetFieldValue("purchase_billbook","vendor='".$myrow['vendor']."' and po_cat='MT' and form_type='".$Wform."'","sum(taxvalue)");
           if($C23=='') $C23='0.00';
         $C24=$C22+$C23;
         if($tinno!='' && $myrow['po_cat']='MT') { $C25='GD';} else if($tinno=='' && $myrow['po_cat']='MT') { $C25='PUR';}

        $data_array[$year][]=array("year"=>$year,"TIN"=>$tinno,"vendor_name"=>$vendor_name,"C05"=>$C05,"C06"=>$C06,"C07"=>$C07,"C08"=>$C08,"C09"=>$C09,"C10"=>$C10,"C11"=>$C11,"C12"=>$C12,"C13"=>$C13,"C14"=>$C14,"C15"=>$C15,"C16"=>$C16,"C17"=>$C17,"C18"=>$C18,"C19"=>$C19,"C20"=>$C20,"C21"=>$C21,"C22"=>$C22,"C23"=>$C23,"C24"=>$C24,"C25"=>$C25);


       }

   
 //echo "<pre>";
  /// print_r($data_array);

?>
<?php 
$i=0;
foreach($yeardata as $y=>$v)
{

    ?>
  <tr>
    <td><?php echo ($i+1); ?></td>     
    <td><?php echo $data_array[$v][$i][year]; ?></td>
    <td><?php echo $data_array[$v][$i][TIN]; ?></td>
    <td><?php echo $data_array[$v][$i][vendor_name]; ?></td>
    <td><?php echo $C05_data[]=$data_array[$v][$i][C05]; ?></td>
    <td><?php echo $C06_data[]=$data_array[$v][$i][C06]; ?></td>
    <td><?php echo $C07_data[]=$data_array[$v][$i][C07]; ?></td>
    <td><?php echo $C08_data[]=$data_array[$v][$i][C08]; ?></td>
    <td><?php echo $C09_data[]=$data_array[$v][$i][C09]; ?></td>
    <td><?php echo $C10_data[]=$data_array[$v][$i][C10]; ?></td>
    <td><?php echo $C11_data[]=$data_array[$v][$i][C11]; ?></td>
    <td><?php echo $C12_data[]=$data_array[$v][$i][C12]; ?></td>
    <td><?php echo $C13_data[]=$data_array[$v][$i][C13]; ?></td>
    <td><?php echo $C14_data[]=$data_array[$v][$i][C14]; ?></td>
    <td><?php echo $C15_data[]=$data_array[$v][$i][C15]; ?></td>
    <td><?php echo $C16_data[]=$data_array[$v][$i][C16]; ?></td>
    <td><?php echo $C17_data[]=$data_array[$v][$i][C17]; ?></td>
   <td><?php echo $C18_data[]=$data_array[$v][$i][C18]; ?></td>
   <td><?php echo $C19_data[]=$data_array[$v][$i][C19]; ?></td>
   <td><?php echo $data_array[$v][$i][C20]; ?></td>
   <td><?php echo $C21_data[]=$data_array[$v][$i][C21]; ?></td>
   <td><?php echo $C22_data[]=$data_array[$v][$i][C22]; ?></td>
   <td><?php echo $C23_data[]=$data_array[$v][$i][C23]; ?></td>
   <td><?php echo $data_array[$v][$i][C24]; ?></td>
   <td><?php echo $C25_data[]=$data_array[$v][$i][C25]; ?></td>
   <td><?php echo $C26_data[]=$data_array[$v][$i][C26]; ?></td>
  </tr>
   <?php $i++; } ?>
  <tr>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td><?php if(!empty($C05_data)) echo array_sum($C05_data); ?></td>
    <td><?php if(!empty($C06_data)) echo array_sum($C06_data); ?></td>
     <td><?php if(!empty($C07_data)) echo array_sum($C07_data); ?></td>
    <td><?php if(!empty($C08_data)) echo array_sum($C08_data); ?></td>
    <td><?php if(!empty($C09_data)) echo array_sum($C09_data); ?></td>
     <td><?php if(!empty($C10_data)) echo array_sum($C10_data); ?></td>
     <td><?php if(!empty($C11_data)) echo array_sum($C11_data); ?></td>
     <td><?php if(!empty($C12_data)) echo array_sum($C12_data); ?></td>
     <td><?php if(!empty($C13_data)) echo array_sum($C13_data); ?></td>
     <td><?php if(!empty($C14_data)) echo array_sum($C14_data); ?></td>
    <td><?php if(!empty($C15_data)) echo array_sum($C15_data); ?></td>
     <td><?php if(!empty($C16_data)) echo array_sum($C16_data); ?></td>
     <td><?php if(!empty($C17_data)) echo array_sum($C17_data); ?></td>
    <td><?php if(!empty($C18_data)) echo array_sum($C18_data); ?></td>
     <td><?php if(!empty($C19_data)) echo array_sum($C19_data); ?></td>
    <td>0.00</td>
     <td><?php if(!empty($C21_data)) echo array_sum($C21_data); ?></td>
     <td><?php if(!empty($C22_data)) echo array_sum($C22_data); ?></td>
     <td><?php if(!empty($C23_data)) echo array_sum($C23_data); ?></td>     
    <td>0.00</td>
     <td><?php if(!empty($C25_data)) echo array_sum($C25_data); ?></td>
      <td><?php if(!empty($C26_data)) echo array_sum($C26_data); ?></td>
  </tr>
  <?php 
$_SESSION['Annexure_purchase']=$data_array;
$_SESSION['Annexure_year']=$yeardata;
} else { ?>
 <tr ><td colspan="26">No Records</td></tr>
   <?php } }?>
</table>
</div>




 