<?php 
	$header_file=APPPATH.'views/include/header.php';
	require($header_file);
?>
<!-- BEGIN: Content-->
    <div class="app-content content">
      <div class="content-overlay"></div>
      <div class="content-wrapper">
        <div class="content-header row">
          <div class="content-header-left col-md-12 col-12 mb-2 breadcrumb-new">
            <h3 class="content-header-title mb-0 d-inline-block">Voucher Generation</h3>
            <div class="row breadcrumbs-top d-inline-block">
              <div class="breadcrumb-wrapper col-12">
                <ol class="breadcrumb">
                  <li class="breadcrumb-item"><a href="#">Home</a>
                  </li>
                  <li class="breadcrumb-item"><a href="#">Vendor</a>
                  </li>
                  <li class="breadcrumb-item active">Vendor Ledger
                  </li>
                </ol>
              </div>
            </div>
          </div>
        
        </div>
        <div class="content-body"><!-- Zero configuration table -->
<section id="configuration">
    <div class="row">
        <div class="col-md-12">
            <div class="card">
                <!--<div class="card-header">
                    <h4 class="card-title">Stock Movement</h4>
                    <a class="heading-elements-toggle"><i class="la la-ellipsis-v font-medium-3"></i></a>
                    <div class="heading-elements">
                        <ul class="list-inline mb-0">
                            <li><a data-action="collapse"><i class="ft-minus"></i></a></li>
                            <li><a data-action="reload"><i class="ft-rotate-cw"></i></a></li>
                            <li><a data-action="expand"><i class="ft-maximize"></i></a></li>
                            <li><a data-action="close"><i class="ft-x"></i></a></li>
                        </ul>
                    </div>
                </div>-->
                <div class="card-content collapse show">
                    <div class="card-body card-dashboard">
					<?php //foreach($vendor as $vnd) ?>
						<form method="post" autocomplete="off" action="<?php echo site_url('StockManagement/generateVoucher/');?>" method="POST" enctype="multipart/form-data">
                        	<div class="row justify-content-md-center">
								<div class="col-md-4">
									<div class="form-group">
										<label for="eventInput1">Vendor</label>
										<input class="form-control" type="text" name="vendor_name" id="vendor_name" value="<?php echo $vname; ?>" readonly >
									</div>
								</div>
								<div class="col-md-4">
									<div class="form-group">
										<label for="eventInput1">Credit Period</label>
										<?php 
											$vnm = $vname;
											$q1 = $this->db->query("select * from vendor_creation where company_name='$vnm' group by company_name");
											$row = $q1->row_array();
										?>
										<input type="text" class="form-control" name="credit" id="credit" value="<?php echo $row['cr_prd']; ?>" readonly >
										<input type="hidden" class="form-control" name="ph_no" id="ph_no" value="<?php echo $row['contact_no']; ?>" readonly >
										<input type="hidden" class="form-control" name="email_id" id="email_id" value="<?php echo $row['email_id']; ?>" readonly >
										<input type="hidden" class="form-control" name="address" id="address" value="<?php echo $row['address']; ?>" readonly >
										<input type="hidden" class="form-control" name="address1" id="address1" value="<?php echo $row['address1']; ?>" readonly >
									</div>
								</div>
							</div>
						
						<div class="table-responsive">
							<?php
								$count1 = 0;
								$count2 = 0;
								foreach($grn as $grow)
								{
									if(($grow->payment_status == 'Closed'))
									{	
										$count2++;	
									}
									$count1++;
								}
							?>
							 <table class="table table-striped table-bordered">
								<thead>
									<th>Chk</th>
									<th>GRN Date</th>
									<th>GRN No</th>
									<th>Invoice No</th>
									<th>Pending Cr Prd</th>
									<th>GRN Value</th>
									<th>Rejected Amt</th>
									<th>Final Value</th>
									<th>View</th>
								</thead>
								<tbody>
								<?php 
									$i = 0;
									foreach($grn_detail as $data) {
										$cdate = date('Y-m-d',strtotime($data->grn_date. '+' .$row['cr_prd']. 'days'));
										$tdate = date('Y-m-d');
										$cdate1 = date_create($cdate);
										//$cdate1 = date_create('2018-11-28');
										$tdate1 = date_create($tdate);
										$cr_prd = date_diff($tdate1,$cdate1);
								?>
									<tr>
										<?php if($data->payment_status == 'Pending') { ?>
										<td><input type="checkbox" class="grnchk" name="grn_chk[]" id="grn_chk" value="<?php echo $i; ?>" ></td>
										<?php } else { ?>
										<td><input type="checkbox" class="grnchk" name="grn_chk[]" id="grn_chk" value="<?php echo $i; ?>" disabled ></td>
										<?php } ?>
										<td><input type="hidden" name="grn_date[]" id="grn_date" value="<?php echo $data->grn_date; ?>"><?php echo $data->grn_date; ?></td>
										<td><input type="hidden" name="grn_id[]" id="grn_id" value="<?php echo $data->gnr_id; ?>"><input type="hidden" name="grn_no[]" id="grn_no" value="<?php echo $data->grn_no; ?>"><input type="hidden" name="invoice_no[]" id="invoice_no" value="<?php echo $data->invoice_no; ?>"><input type="hidden" name="invoice_date[]" id="invoice_date" value="<?php echo $data->invoice_date; ?>"><input class="branch" type="hidden" name="branch[]" id="branch" value="<?php echo $data->branchname; ?>"><?php echo $data->grn_no; ?></td>
										<td><?php echo $data->invoice_no; ?></td>
										<td><?php if($cdate <= $tdate) {
										echo '0'; 
										} else {
										echo $cr_prd->format("%a");
										}
										?></td>
										<td><?php echo $data->total_amount; ?></td>
										<td><?php echo round(($data->total_amount - $data->reject_amt),2); ?></td>
										<td><input type="hidden" class="pay_amt" name="grn_pay_amt[]" id="grn_pay_amt" value="<?php echo $data->reject_amt; ?>"><input type="hidden" class="pay_status" name="pay_status[]" id="pay_status" value="<?php echo $data->payment_status; ?>"><?php echo round($data->reject_amt,2); ?></td>
										<td><!--<a href="grn_view_list.php?mid=<?php //echo $row['gnr_id']; ?>&page_id=vendor-ledger" target="_blank" id="view" name="view" ><i class="material-icons md-24">&#xE8F4;</i></a>-->
										<a href="<?php echo site_url('Purchase/Accgrn_view/'.$data->gnr_id.''); ?>" id="view" name="view" class="btn btn-sm btn-primary" target="_blank">View</a></td>
									</tr>
									<?php
										$i++;
										} ?>
								</tbody>
							</table>
					    </div>
						
						<input type="hidden" name="rs_count" id="rs_count" value="<?php echo $i; ?>">
						<input class="br" type="hidden" name="br" id="br" >
						
						<div class="row">
							<div class="col-md-5 ">
								<div class="form-group" style="margin-top: 9px;">
									<label for="inputPassword3" >Payment mode<span class="redText"></span></label>
									<label class="radio-inline">
										<input type="radio" name="pay_mode" id="cash" value="Cash" required />Cash
									</label>
									<label class="radio-inline">
										<input type="radio" name="pay_mode" id="cheque" value="Cheque" />Cheque 
									</label>
									<label class="radio-inline">
										<input type="radio" name="pay_mode" id="neft" value="NEFT/RTGS" checked />NEFT/RTGS 
									</label>
								</div>
							</div>
							<div class="col-md-2 ">
								<div class="form-group">
									<input type="text" class="form-control qty" name="total_pay_amt" id="total_pay_amt" placeholder="Total Amount" readonly >
								</div>
							</div>
							<div class="col-md-2 ">
								<div class="form-group">
									<input type="text" class="form-control" name="roundoff" id="roundoff" placeholder="Round Off" >
								</div>
							</div>
							<div class="col-md-2 ">
								<div class="form-group">
									<input type="text" class="form-control qty" name="total_payamt" id="total_payamt" placeholder="Total Amount" readonly >
								</div>
							</div>
						</div>
						
						<div class="row">
							<div class="col-md-3" id="bank_acc" style="display:block;">
								<div class="form-group">
									<select id="bname" name="bname" class="select2" >
										<option value="">Select Bank</option>
									</select>
								</div>
							</div>
							<div class="col-md-2" id="trno" style="display:block;">
								<div class="form-group">
									<input type="text" class="form-control" name="trans_no" id="trans_no" placeholder="Cheque No" required >
								</div>
							</div>
							<div class="col-md-3">
								<div class="form-group">
									<input type="file" name="chq_upload" id="chq_upload" class="form-control image_file" />
									<div id="errfn2" ></div>
								</div>
							</div>
							<div class="col-xs-2">
								<div class="form-group">
									<input type="submit" name="submit" class="btn btn-primary" value="Generate Voucher">
								</div>
							</div>
						</div>
					</form>	
                    </div>
                </div>
                
				<div class="doc_viewer">
					<!--<iframe id="viewer" frameborder="0" scrolling="yes" width="950" height="500"></iframe>-->
					<img id="viewer" />
				</div>
            </div>
            
            <form method="post" action="<?php echo site_url('StockManagement/export_vgrnlist/');?>">
						<div class="uk-width-medium-1-4">
							<div class="uk-input-group">
								<input class="form-control" type="hidden" name="from_date1" value="<?php echo $fr_date; ?>">
								<input class="form-control" type="hidden" name="to_date1" value="<?php echo $to_date; ?>">
								<input class="form-control" type="hidden" name="vname1" value="<?php echo $vname; ?>">
								<input type="submit" name="exportvg" class="btn btn-info" value="Export">
							</div>
						</div>
					</form>
        </div>
    </div>
</section>
<!--/ Zero configuration table -->



<!--/ Language - Comma decimal place table -->

        </div>
      </div>
    </div>
    <!-- END: Content-->

   <?php //require('include/theme_customizer.php');?>
 <?php 
  $footer_file=APPPATH.'views/include/footer.php';
	require($footer_file);
	?>
			
<script>
	$('.grnchk').click(function() {
		var ind = $(this).parent().find('.grnchk').val();
		var total = $('#total_pay_amt').val();
		var pay_amt = $('.pay_amt').eq(ind).val();
		if(total == '')
		{
			total = 0;
		}
		if($(this).is(':checked'))
		{
			//alert(ind);
			var total_pay_amt = (parseFloat(total) + parseFloat(pay_amt)).toFixed(2);
			$('#total_pay_amt').val(total_pay_amt);
			$('#total_payamt').val(total_pay_amt);
		}
		else
		{
			var total_pay_amt = (parseFloat(total) - parseFloat(pay_amt)).toFixed(2);
			$('#total_pay_amt').val(total_pay_amt);
			$('#total_payamt').val(total_pay_amt);
		}
	});
	
	$('.grnchk').click(function() {
		var ind = $(this).parent().find('.grnchk').val();
		var branch = $('.branch').eq(ind).val();
		var checked = $("input[type=checkbox]:checked").length;
		var c_count = $('#rs_count').val();
		if(checked > 0)
		{
			if(branch == 'CW3')
			{
				branch = 'CW';
			}
			else if(branch == 'CMS-STR')
			{
				branch = 'CW';
			}
			
			if(branch == 'CW')
			{
				//$('#bname').val('(CW)Karnataka Bank Ltd. PSOD 108');
				$('#bname').empty();
				$('#bname').append('<option value="">Select Bank</option><option value="KARNATAKA BANK PSOD - 108">KARNATAKA BANK PSOD - 108</option><option value="AXIS BANK C/A - 84612287">AXIS BANK C/A - 84612287</option><option value="HDFC BANK A/C NO - 12262560001482">HDFC BANK A/C NO - 12262560001482</option>');
				$('#br').val(branch);
			}
			else if(branch == 'ESH')
			{
				//$('#bname').val('(ESH)Karnataka Bank Ltd. PSOD 108');
				$('#bname').empty();
				$('#bname').append('<option value="">Select Bank</option><option value="KARNATAKA BANK PSOD - 107">KARNATAKA BANK PSOD - 107</option><option value="AXIS BANK C/A - 85719688">AXIS BANK C/A - 85719688</option><option value="HDFC BANK A/C NO - 12262560001613">HDFC BANK A/C NO - 12262560001613</option>');
				$('#br').val('ESHY');
			}
			else if(branch == 'CW4')
			{
				//$('#bname').val('(MC)Karnataka Bank Ltd. PSOD 108');
				$('#bname').empty();
				$('#bname').append('<option value="">Select Bank</option><option value="KARNATAKA BANK C/A 2107">KARNATAKA BANK C/A 2107</option><option value="KARNATAKA BANK PSOD 1987>KARNATAKA BANK PSOD 1987</option>');
				$('#br').val('MC');
			}
			else if(branch == 'CW5')
			{
				//$('#bname').val('(MC)Karnataka Bank Ltd. PSOD 108');
				$('#bname').empty();
				//$('#bname').append('<option value="">Select Bank</option><option value="KARNATAKA BANK C/A 2107">KARNATAKA BANK C/A 2107</option><option value="KARNATAKA BANK PSOD 1987>KARNATAKA BANK PSOD 1987</option>');
				$('#br').val('CW5');
			}
			for(var i=0;i<c_count;i++)
			{
			    var br = $('.branch').eq(i).val();
				if(br == 'CW3')
				{
					br = 'CW';
				}
				else if(br == 'CMS-STR')
    			{
    				br = 'CW';
    			}
				if(br != branch)
				{
					var br1 = $(".brname"+i).val();
					$('.grnchk').eq(i).prop('disabled',true);	
				}
			}
		}
		else
		{
			for(var i=0;i<c_count;i++)
			{
				var pstatus = $('.pay_status').eq(i).val();
				if(pstatus == 'Closed')
				{
					$('.grnchk').eq(i).prop('disabled',true);
				}
				else
				{
					$('.grnchk').eq(i).prop('disabled',false);
				}
			}
		}
	});
	
		
	$("input[name='pay_mode']").click(function() {
		if($('#cash').is(':checked'))
		{
			$('#bank_acc').hide();
			$('#trno').hide();
			$("#bname").prop('disabled', true);
			$("#trans_no").prop('disabled', true);
			//$("#bname").val('');
			//$("#trans_no").val('0');
		}
		else if($('#neft').is(':checked'))
		{
			$('#bank_acc').show();
			$('#trno').show();
			$("#bname").prop('disabled', false);
			$("#trans_no").prop('disabled', false);
		}
		else if($('#cheque').is(':checked'))
		{
			$('#bank_acc').show();
			$('#trno').show();
			$("#bname").prop('disabled', false);
			$("#trans_no").prop('disabled', false);
		}
	});
		
	$(document).ready(function () {
		$('#submit').click(function() {
			checked = $("input[type=checkbox]:checked").length;
			
			if(!checked)
			{
				alert("Select the GRN you want settlement");
				return false;
			}
		});
	});
	
	$('.qty').keypress(function(e) {
		var a = [];
		var k = e.which;
		a.push(8);
		for (i = 46; i < 58; i++)
		a.push(i);
		if (!($.inArray(k,a)>=0))
		e.preventDefault();
	});	
</script>
<script type="text/javascript">
	$(document).ready(function () {
		$('.image_file').change(function () {
			var val = $(this).val().toLowerCase();
			var regex = new RegExp("(.*?)\.(jpg|png|jpeg|JPG)$");
			if(!(regex.test(val))) {
				$(this).val('');
				//alert('Please select correct file format');
				document.getElementById('errfn2').innerHTML="Please upload only image file";
			} }); });
</script> 
<script type="text/javascript">
	 $(document).ready(function () {
		 $('.image_file').change(function () {
	// function PreviewImage() {
			pdffile=document.getElementById("chq_upload").files[0];
			pdffile_url=URL.createObjectURL(pdffile);
			$('#viewer').attr('src',pdffile_url);
	   // }
		 });
	 });
</script>
<script type="text/javascript">
	$('#roundoff').keyup(function () {
		var rnd = $('#roundoff').val();
		var tamt = $('#total_pay_amt').val();
		if(rnd == '')
		{
			//rnd = 0;
			$('#total_payamt').val(tamt);
		}
		else
		{
    		var final_amt = (parseFloat(tamt) + parseFloat(rnd)).toFixed();
    		$('#total_payamt').val(final_amt);
		}
	});
</script>

  </body>
  <!-- END: Body-->

<!-- Mirrored from pixinvent.com/modern-admin-clean-bootstrap-4-dashboard-html-template/html/ltr/vertical-modern-menu-template/form-layout-basic.html by HTTrack Website Copier/3.x [XR&CO'2014], Mon, 27 Apr 2020 09:38:02 GMT -->
</html>