<?php
require_once("../includes/config.php");

if($_POST['save']){ 
  
if($_POST['approval']){ 
 
foreach($_POST['approval'] as $value){

   $sql="update collect_data set status='".$_POST['action']."' where collect_id='".$value."'";
  mysqli_query($link1,$sql) or die(mysqli_error($link1));

  if($_POST['action'] =="Approved"){
$sql_cl="select * from collect_data where collect_id='".$value."'";
$rs_cl= mysqli_query($link1,$sql_cl) or die(mysqli_error($link1));
$row_cl=mysqli_fetch_array($rs_cl);
$collect_id=$value;
$retailer_code=$row_cl['retailer_code'];
$collection_amt=$row_cl['collect_amt'];
$collection_date=$row_cl['collect_date'];

    $wh_row=mysqli_fetch_assoc(mysqli_query($link1,"select wh_location from map_wh_location where status='Y' and location_code='".$retailer_code."'"));
if($wh_row['wh_location']!=''){
$wh_loc=$wh_row['wh_location'];
}else{
	$wh_loc="FIX00017";
}

    $account_no="510030110000111";
    echo "insert into bank_account_ledger set location_code='".$wh_loc."',account_no='".$account_no."',amount='".$collection_amt."',ref_no='".$collect_id."',remark='APP Collection',month_year='".date('m-Y')."',crdr='CR',entry_date='".$collection_date."',challan_no='".$collect_id."'";
			mysqli_query($link1,"insert into bank_account_ledger set location_code='".$wh_loc."',account_no='".$account_no."',amount='".$collection_amt."',ref_no='".$collect_id."',remark='APP Collection',month_year='".date('m-Y')."',crdr='CR',entry_date='".$collection_date."',challan_no='".$collect_id."'") or die(mysqli_error($link1));
		
            $res_ac_ledger = mysqli_query($link1,"INSERT INTO party_account_ledger set party='".$retailer_code."',location_code='".$wh_loc."',entry_date='".$collection_date."',remark='APP Collection',transaction_no='".$collect_id."',ref_no='".$collect_id."', transaction_type = 'APP Collection',month_year='".date("m-Y")."',crdr='CR',amount='".$collection_amt."'");




  }

}

echo $msg="collection update completed";
}

header("Location:collection_update.php?msg=".$msg);


}

?>
<!DOCTYPE html>
<html>
<head>
 <meta charset="utf-8">
 <meta name="viewport" content="width=device-width, initial-scale=1">
 <link rel="shortcut icon" href="../images/titleimg.png" type="image/png">
 <link href="../css/font-awesome.min.css" rel="stylesheet">
 <link href="../css/abc.css" rel="stylesheet">
 <script src="../js/jquery.js"></script>
 <script src="../js/bootstrap.min.js"></script>
 <link href="../css/abc2.css" rel="stylesheet">
 <link rel="stylesheet" href="../css/bootstrap.min.css">
 <link rel="stylesheet" href="../css/jquery.dataTables.min.css">


 
    <link rel="stylesheet" href="//cdn.datatables.net/1.10.18/css/jquery.dataTables.min.css">
<script src="//cdn.datatables.net/1.10.18/js/jquery.dataTables.min.js"></script>
<link rel="stylesheet" href="https://cdn.datatables.net/buttons/1.5.2/css/buttons.dataTables.min.css">

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"> </script>
<script type="text/javascript" language="javascript" src="https://cdn.datatables.net/buttons/1.5.2/js/dataTables.buttons.min.js"></script>
<script type="text/javascript" language="javascript" src="https://cdn.datatables.net/buttons/1.5.2/js/buttons.flash.min.js"></script>
<script type="text/javascript" language="javascript" src="https://cdn.datatables.net/buttons/1.5.2/js/buttons.html5.min.js"></script>
<script type="text/javascript" language="javascript" src="https://cdn.datatables.net/buttons/1.5.2/js/buttons.print.min.js"></script>

 
 <script type="text/javascript" language="javascript" >
/*$(document).ready(function(){
    $('#myTable').dataTable();
});*/

$(document).ready(function() {
	var dataTable = $('#product-grid').DataTable( {
		"processing": true,
		"serverSide": true,
		"order": [[ 0, "asc" ]],




		"ajax":{
			url :"../pagination/collectioncheque-grid-data.php", // json datasource
			data: { "pid": "<?=$_REQUEST['pid']?>", "hid": "<?=$_REQUEST['hid']?>" , "party_code": "<?=$_REQUEST['party_code']?>","daterange": "<?=$_REQUEST['daterange']?>"},
			type: "post",  // method  , by default get
			error: function(){  // error handling
				$(".product-grid-error").html("");
				$("#product-grid").append('<tbody class="product-grid-error"><tr><th colspan="4">No data found in the server</th></tr></tbody>');
				$("#product-grid_processing").css("display","none");
			}
		},

    dom: 'Bfrtip',
    
        
        buttons: [
            {
                extend: 'excelHtml5',
                title: 'stock Ledger Product'
            },
            {
                extend: 'pdfHtml5',
                title: 'stock Ledger'
            }
        ]
	} );
} );
</script>
<script type="text/javascript" src="../js/moment.js"></script>
<link href="../css/abc2.css" rel="stylesheet">
<link rel="stylesheet" href="../css/bootstrap.min.css">

 <link rel="stylesheet" href="../css/bootstrap-select.min.css">

 
<script type="text/javascript" language="javascript" >
$(document).ready(function(){
$('input[name="daterange"]').daterangepicker({
locale: {
format: 'YYYY-MM-DD'
}
});
});
;
////// checkbox selection condition/////////////////////////////
$(document).ready(function()
{
$("#pending").change(function() {
if ($(this).is(":checked")) {
$("#pending").show();
$("#dt_range").hide();	
$("#st").hide();	
$("#subst").hide();
$("#stat").hide();
$("#loc").hide();
$("#prod").hide();
$("#brnd").hide();
$("#mdl").hide();
$("#rpt_frm_dt").hide();
} 
else
{
$("#dt_range").show();	
$("#st").show();	
$("#subst").show();		
$("#stat").show();
$("#loc").show();
$("#prod").show();
$("#brnd").show();
$("#mdl").show();
$("#rpt_frm_dt").show();
}
});
});
$(document).ready(function(){
if($("#pending").is(":checked")){
$("#dt_range").hide();	
$("#st").hide();	
$("#subst").hide();	
$("#stat").hide();
$("#loc").hide();
$("#prod").hide();
$("#brnd").hide();
$("#mdl").hide();
$("#rpt_frm_dt").hide();
}
});
</script>
<!-- Include Date Range Picker -->
<script type="text/javascript" src="../js/daterangepicker.js"></script>
<link rel="stylesheet" type="text/css" href="../css/daterangepicker.css"/>
<!-- Include Date Picker -->
<link rel="stylesheet" href="../css/datepicker.css">
<!-- Include multiselect -->
<script type="text/javascript" src="../js/bootstrap-multiselect.js"></script>
<link rel="stylesheet" href="../css/bootstrap-multiselect.css" type="text/css"/>
<script src="../js/bootstrap-datepicker.js"></script>
<title><?=siteTitle?></title>
</head>
<body>
<div class="container-fluid">
  <div class="row content">
	<?php 
    include("../includes/leftnav2.php");
    ?>
    <div class="<?=$screenwidth?> tab-pane fade in active" id="home">
      <h2 align="center"><i class="fa fa-suitcase"></i> Collection Master</h2>
      <?php if($_REQUEST['msg']){?>
        <div class="alert alert-<?=$_REQUEST['chkflag']?> alert-dismissible" role="alert">
            <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                <span aria-hidden="true">&times;</span>
              </button>
            <strong>Success!</strong>&nbsp;&nbsp;<?=$_REQUEST['msg']?>.
        </div>
        <?php }?> 
	  <form class="form-horizontal" role="form" name="form1" action="" method="get"> 
	    <div class="form-group">
         <div id= "dt_range" class="col-md-6">
            <label class="col-md-5 control-label">Date Range</label>
            <div class="col-md-6 input-append date" align="left">
              <input type="text" name="daterange" id="date_rng" class="form-control" value="<?=$_REQUEST['daterange']?>" />
            </div>
          </div>
		   <div class="col-md-6"><label class="col-md-5 control-label">Sale Person Name</label>
            <div class="col-md-6">
              <select name="party_code" id="party_code" class="form-control">
              <option value=''>--Please Select-</option>
                <?php
                $res_maploc = mysqli_query($link1,"select * from admin_users where utype='Sale Person'"); 
                while($row_maploc = mysqli_fetch_assoc($res_maploc)){
					$locname = getAnyDetails($row_maploc['username'],"name","username","admin_users",$link1);
					?>
                <option value="<?=$row_maploc['collect_by']?>" <?php if($_REQUEST['collect_by'] == $row_maploc['username']) { echo 'selected'; }?>><?=$locname." (".$row_maploc['username'].")"?></option>
                <?php } ?>
              </select>
            </div>
	      </div>
	    </div><!--close form group-->
      <div class="form-group">
          <div class="col-md-6"><label class="col-md-5 control-label"></label>
            <div class="col-md-5">
               <input name="pid" id="pid" type="hidden" value="<?=$_REQUEST['pid']?>"/>
               <input name="hid" id="hid" type="hidden" value="<?=$_REQUEST['hid']?>"/>
               <input name="Submit" type="submit" class="btn<?=$btncolor?>" value="GO"  title="Go!">
            </div>
          </div>
		  <div class="col-md-6"><label class="col-md-5 control-label"></label>	  
			<div class="col-md-5" align="left">
               <?php
			    //// get excel process id ////
				//$processid=getExlCnclProcessid("Admin Users",$link1);
			    ////// check this user have right to export the excel report
			    //if(getExcelRight($_SESSION['userid'],$processid,$link1)==1){
			   ?>
               <a href="excelexport.php?rname=<?=base64_encode("collectionmaster")?>&rheader=<?=base64_encode("Collection Master")?>&daterange=<?=$_REQUEST['daterange']?>&status=<?=base64_encode($_GET['status'])?>&rdate=<?=$_REQUEST['date_type']?>" title="Export product details in excel"><i class="fa fa-file-excel-o fa-2x faicon" title="Export product details in excel"></i></a>
               <?php
				//}
				?>
            </div>
          </div>
	    </div><!--close form group-->
		</form>
      <form class="form-horizontal" role="form" id="app_form" name="app_form" action="" method="POST">
        
        <div class="form-group"  id="page-wrap" style="margin-left:10px;"><br/><br/>
      <!--<div class="form-group table-responsive"  id="page-wrap" style="margin-left:10px;"><br/><br/>-->
       <table  width="100%" id="product-grid" class="display" align="center" cellpadding="4" cellspacing="0" border="1">
          <thead>
            <tr class="<?=$tableheadcolor?>">
              <th>S.No</th>
              <th>Collection ID</th>
			  <th>Retailer Name</th>
              <th>Collection Mode</th>
               <th>Collection Sub Mode</th>
              <th>Product</th>
              <th>Collection Amount</th>
              <th>Collection By</th>
              <th>Collection Date</th>
              <th>Approval</th>
            </tr>
          </thead>
          </table>
          <select name="action" id="action" class="form-control required" style="width: 200px;">
         <option value="">please select</option>
         <option value="Approved">Approve</option>
         <option value="Rejected">Reject</option>

          </select>
          <input type="submit" name="save" value="save" id="save" class="btn btn-primary" style="width: 120px;"/>
          </div>
      
      </form>
    </div>
    
  </div>
</div>
<?php
include("../includes/footer.php");
include("../includes/connection_close.php");
?>
</body>

</html>