<?php 
$PageSecurity = 11;
include('includes/DefinePOClass.php');
include('includes/DefineSerialItems.php');
include('includes/SQL_CommonFunctions.inc');
include('cocoon_config.php');
setlocale(LC_MONETARY,'en_IN');
?>

<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<h1>CDNR</h1>
<form action="" name="main_account" method="post" onsubmit="return validate()">
<table width="100%" border="0" cellpadding="3" cellspacing="0">
<tr class="row1"> 
  <td width="13%" align="right">Branch</td>
  <td><select name="branch" id="branch">
                <option value="0">All</option>
                 <?php  
                    $sql_locations=DB_query("select loccode,locationname from locations order by locationname",$db);
                    while($result_locations=DB_fetch_array($sql_locations))
                    {
                      ?>
                     <option value="<?php echo $result_locations['loccode']; ?>" <?php if($_REQUEST['branch']==$result_locations['loccode']){ ?> selected="selected" <?php } ?>><?php echo $result_locations['locationname']; ?></option>
                  <?php } ?>
             </select>
  </td>
  <td width="13%" align="right">From Date</td>
  <td width="20%"><input name="fromdate"  id="fromdate" type="text" readonly  class="datepicker"  value="<?php if($_REQUEST['fromdate']!='') { echo $_REQUEST['fromdate']; } else { echo ConvertSQLDate($_SESSION['financialYrStart']); } ?>"/></td>
  <td width="13%" align="right">To Date</td>
  <td width="20%"><input name="todate" id="todate" type="text"  class="datepicker" readonly value="<?php if($_REQUEST['todate']!='') { echo $_REQUEST['todate']; } else { echo ConvertSQLDate($_SESSION['financialYrEnd']); } ?>" onchange="return date_check();" /></td>  
</tr>
<tr class="row1"> 
  <td colspan="6" style="text-align:center;"><input name="Search" type="submit" class="search"   value="Search"/></td>
</tr>
</table>
</form>
<br>
<!-- <div>
  <p align="right"><a href="gst_sales_summary_print.php" class="search" target="_blank">Print</a>
  <a href="gst_sales_summary_export.php" class="search" target="_blank">Export</a></p> </div> -->
<div style="width:100%; height:320px; float:left; overflow:auto;">
<table width="100%" border="0" cellspacing="0" cellpadding="3" class="thborder">
<thead>
  <tr>
    <th>GSTIN/UIN of Recipient</th>
    <th width="8%" style="text-align:center;">Invoice / Advance Receipt Number</th>
    <th width="8%" style="text-align:center;">Invoice / Advance Receipt Date</th>
    <th width="8%" style="text-align:center;">Note / Refund Voucher No.</th>
    <th width="8%" style="text-align:center;">Note / Refund Voucher Date</th>
    <th width="12%" style="text-align:center;">Document Type</th>
    <th width="12%" style="text-align:center;">Reason for Issuing Document</th>
    <th width="12%" style="text-align:center;">Place of Supply</th>
    <th width="8%" style="text-align:center;">Note/Refund Voucher Value</th>
   <!--  <th style="text-align:center;">Rate</th> -->
    <th width="8%" style="text-align:center;">Taxable Value</th>
    <th width="8%" style="text-align:center;">Cess Amount</th>
    <th width="8%" style="text-align:center;">Pre GST</th>
  </tr>
 
  </thead>
  <tbody><?php 
  if($_REQUEST['Search'])
  { 
    unset($_SESSION['gst_cdnr']);
    $filter=array();
    
    $fromdate1=explode("/",$_REQUEST['fromdate']);
    $fromdate=$fromdate1[2]."-".$fromdate1[1]."-".$fromdate1[0];
    
    $todate1=explode("/",$_REQUEST['todate']);
    $todate=$todate1[2]."-".$todate1[1]."-".$todate1[0];

    //$fromdate=ConvertSQLDate($_REQUEST['fromdate']);
    //$todate=ConvertSQLDate($_REQUEST['todate']);
    //$fromdate1=explode("/")
    if($_REQUEST['branch']!='0')
    {
      $filter2[]="Branch='".$_REQUEST['branch']."'";
    }

    if($_REQUEST['fromdate']!='' && $_REQUEST['todate']!='')
    {
      $filter2[]="Dates between '".$fromdate."' and '".$todate."'";
    }


      if(!empty($filter2))
     {
       $filter3=implode(" and ",$filter2);
     }
     else
     {
      $filter3="1=1";
     }
    $_SESSION['filter3']=$filter3;
    
    $GetRecord="select * from account_book where $filter3 and Vprefix in(12,16) group by Voucher_NO";
    $result=DB_query($GetRecord,$db);
    $i=1;
    if(DB_num_rows($result)>0)
    {
    while($rs=DB_fetch_array($result))
     {
       
           $vendor_id=$s->GetFieldValue('purchase_billbook',"id='".$rs['trans_type_id']."'",'vendor');
           $gst_no=$s->GetFieldValue('suppliers',"id='".$vendor_id."'",'gst_no');        
       ?>
  	<tr>
     <td><?php echo $gst_no; ?></td>
     <td><?php echo $s->GetFieldValue('purchase_billbook',"id='".$rs['trans_type_id']."'",'bill_book_no'); ?></td>
     <td style="text-align:right;"><?php $bill_date=$s->GetFieldValue('purchase_billbook',"id='".$rs['trans_type_id']."'",'bill_book_date'); if($bill_date!='') { echo ConvertSQLDate($bill_date); }  ?></td>
    <td style="text-align:center;"><?php echo $rs['Voucher_NO']; ?></td>
     <td style="text-align:center;"><?php echo ConvertSQLDate($rs['Dates']); ?></td>
      <td style="text-align:right;">D</td>
       <td style="text-align:right;"><?php echo $rs['narration']; ?></td>
       <td style="text-align:right;"><?php $place_supply_id=$s->GetFieldValue('purchase_billbook',"id='".$rs['trans_type_id']."'",'place_supply'); echo $s->GetFieldValue('state_master',"id='".$place_supply_id."'",'state'); ?></td>
       <td style="text-align:right;"><?php echo $rs['total_dramount']; $voucher_total[]=$rs['total_dramount']; ?></td>
       <td style="text-align:right;"><?php echo $rs['total_dramount']; $voucher_total[]=$rs['total_dramount']; ?></td>
       <!-- <td style="text-align:right;"></td> -->
       <td style="text-align:right;">0.00</td>
     <td style="text-align:right;">N</td>
  	</tr><?php $i++; } ?>
    <tr>
     <td colspan="8" style="text-align:right;"><strong>Total</strong></td>
     <td style="text-align:right;"><strong><strong><?php if(!empty($voucher_total)) { echo money_format('%!i',array_sum($voucher_total)); } else { echo "0.00"; } ?></strong></td>
       <td style="text-align:right;"><strong><strong><?php if(!empty($voucher_total)) { echo money_format('%!i',array_sum($voucher_total)); } else { echo "0.00"; } ?></strong></td>
    </tr>
    <?php }  else { ?>
     <tr>
       <td colspan="6"><strong>No Records Found</strong></td>
    </tr>
   
    <?php }}  ?>
     

  </tbody>
	</table>

</div>
</div>
<script>
function validate()
{
 
   if(document.getElementById('todate').value=='')
  {
    alert("please Enter From Date");
    document.getElementById('todate').focus();
    return false;
  }

  if(document.getElementById('fromdate').value=='')
  {
    alert("please Enter To Date");
    document.getElementById('fromdate').focus();
    return false;
  }
}
</script>