<?php
defined('BASEPATH') OR exit('No direct script access allowed');
if($rsrcid>0) { $totalamt =  $info4edit->fld_amount; } else {
$totalamt = $this->main_model->getdayoffsale($this->outletid,$this->userid);
}
?>

      <div class="main my-0">
        <div class="row mt-3 mx-0">
          <div class="col-md-6">
            <h3>Day Close Receipt</h3>
          </div>
          <div class="col-md-5 text-right">
            &nbsp;
          </div>
        </div>
        
        <div class="container_fluid mt-2 px-3">
		<form name="frmgeneral" method="post" action="outlet/<?php echo $mgmtname;?>/managedata?<?php echo $_SERVER['QUERY_STRING'];?>" enctype="multipart/form-data" onsubmit="return validateFrm();">
		<input type="hidden" name="rsrcid" value="<?php echo $rsrcid;?>">                
        <table class="webforms mt-0 table-responsive-sm">
      
         <tr>
          <td width="20%"><label>Biller Name:</label></td>
          <td width="80%"><?php echo $billerinfo->fld_name;?></td>
         </tr> 
           <tr>
          <td width="20%"><label>Total Amount:</label></td>
          <td width="80%"><input type="text" name="totalamt" id="totalamt" value="<?php  echo $totalamt;?>" required readonly></td>
         </tr> 
         <tr>
          <td width="100%" colspan="2"><h5>Payment Info:</h5><span id="errormsg"></span></td>

         </tr> 
 <tr>
          <td width="20%"><label>Credit Card Slips:</label></td>
          <td width="80%"><input type="text" name="cc" id="cc" value="<?php if($info4edit) { echo $info4edit->fld_cc; }?>" required onblur="calcAmount();" onkeypress='return event.charCode >= 48 && event.charCode <= 57 || event.charCode==46'></td>
         </tr> 

         <tr>
          <td width="20%"><label>UPI:</label></td>
          <td width="80%"><input type="text" name="upi" id="upi" value="<?php if($info4edit) { echo $info4edit->fld_upi; }?>" required onblur="calcAmount();" onkeypress='return event.charCode >= 48 && event.charCode <= 57 || event.charCode==46'></td>
         </tr> 
         <tr>
          <td width="20%"><label>Name Account:</label></td>
          <td width="80%"><input type="text" name="nameaccount" id="nameaccount" value="<?php if($info4edit) { echo $info4edit->fld_nameaccount; }?>" required onblur="calcAmount();" onkeypress='return event.charCode >= 48 && event.charCode <= 57 || event.charCode==46'></td>
         </tr> 

          <tr id="trnaremarks" <?php if($info4edit->fld_nameaccount<1){?>style="display:none;"<?php } ?>>
          <td width="20%"><label>Remarks (Name Account):</label></td>
          <td width="80%">
		  <textarea name="naremarks" id="naremarks" rows="3" cols="8" placeholder="Remarks"><?php if($info4edit) { echo $info4edit->fld_naremarks; }?></textarea>		
		  </td>
         </tr>        		
         <tr>
          <td width="20%"><label>Cash:</label></td>
          <td width="80%"><input type="text" name="cash" id="cash" value="<?php if($info4edit) { echo $info4edit->fld_cash; }else { echo 0;}?>" required onblur="calcAmount();" onkeypress='return event.charCode >= 48 && event.charCode <= 57 || event.charCode==46' readonly></td>
         </tr> 

        		

		 <tr>
             <td></td>
             <td><button class="btn btn-danger">Submit</button></td>
         </tr>
         </table>
         </form> 
	         <div class="clearfix"></div>          
        </div>
       </div>
<script>
$(document).ready(
    function() {

		$("#nameaccount").blur(function() {
			
			nameaccount = $("#nameaccount").val();
			nameaccount = parseInt(nameaccount);
			
			if(nameaccount>0)
			{
				$("#trnaremarks").show("slow");
				$("#naremarks").attr("required","required");
				
			}
			else
			{
				$("#trnaremarks").hide("slow");
				$("#naremarks").removeAttr("required","required");
			}
   });
		     
    });
	function calcAmount()
	{	
		var totalamt = $("#totalamt").val();
		totalamt = parseInt(totalamt);
		var cash = $("#cash").val();
		cash = parseInt(cash);
		var cc = $("#cc").val();
		cc = parseInt(cc);
		var upi = $("#upi").val();
		upi = parseInt(upi);
		nameaccount = $("#nameaccount").val();
		nameaccount = parseInt(nameaccount);
			if(cc>=0 && nameaccount>=0 && upi>=0)
			{
				totclc = (cc+nameaccount+upi);
				totclc = parseInt(totclc);
				cash = (totalamt-totclc);
				cash = parseInt(cash);
				$("#cash").val(cash);			
			}

	}
function validateFrm()
{
		erroralert = 1;
		var totalamt = $("#totalamt").val();
		totalamt = parseInt(totalamt);
		var cash = $("#cash").val();
		cash = parseInt(cash);
		var cc = $("#cc").val();
		cc = parseInt(cc);
		var upi = $("#upi").val();
		upi = parseInt(upi);
		nameaccount = $("#nameaccount").val();
		nameaccount = parseInt(nameaccount);		
		
		totclc = (cash+cc+upi+nameaccount);
		totclc = parseInt(totclc);
		
		if(totalamt==0)
		{
				alert("You have no bills for day off");
				$("#errormsg").html('You have no bills for day off');
				$('#errormsg').css('color', 'red');
				$('#errormsg').css('border-color', 'red');
				setTimeout(function(){
				$("#errormsg").html("");
				$('#errormsg').css('color', '');
				$('#errormsg').css('border-color', '');
				},4000);
			return false;
		}
		if(cash<0)
		{
				alert("Payment info. should match total amount");
				$("#errormsg").html('Payment info. should match total amount');
				$('#errormsg').css('color', 'red');
				$('#errormsg').css('border-color', 'red');
				setTimeout(function(){
				$("#errormsg").html("");
				$('#errormsg').css('color', '');
				$('#errormsg').css('border-color', '');
				},4000);
			return false;
		}
		if(totclc!=totalamt)
		{
				alert("Payment info. should match total amount");
				$("#errormsg").html('Payment info. should match total amount');
				$('#errormsg').css('color', 'red');
				$('#errormsg').css('border-color', 'red');
				setTimeout(function(){
				$("#errormsg").html("");
				$('#errormsg').css('color', '');
				$('#errormsg').css('border-color', '');
				},4000);
			return false;
		}




}
</script>