<div class="wrapper">
    <div class="container">
        <!-- Page-Title -->
        <div class="row">
            <div class="col-sm-12">
                <h4 class="page-title">Franchise Order Payment</h4>
            </div>
        </div>
        <?php if ($this->session->flashdata('Success') && $this->session->flashdata('Success') != "") { ?>
            <div class="row">
                <div class="col-sm-12">
                    <div class="alert alert-success">
                        <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
                        <strong>Success!</strong> <?php echo $this->session->flashdata('Success'); ?>
                    </div>
                </div>
            </div>
        <?php } ?>
        <?php if ($this->session->flashdata('Error') && $this->session->flashdata('Error') != "") { ?>
            <div class="row">
                <div class="col-sm-12">
                    <div class="alert alert-danger">
                        <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
                        <strong>Error!</strong> <?php echo $this->session->flashdata('Error'); ?>
                    </div>
                </div>
            </div>
        <?php } ?>
          <div class="row">
            <div class="col-sm-12">
                <div class="card-box">
                    <h4 class="header-title m-t-0 m-b-30"></h4>
                    <form class="form-horizontal" method="post" action="<?php echo base_url(); ?>franchise_controller/updatereceiving_note">
                        <input type="hidden" name="csrf_test_name" id="supplier_payment_csrf" value=""/>

                        <div class="divider"></div>
                        <div class="row">
                            <div class="col-lg-12">
                                <strong>Franchise Sale Order #: <?php echo $order[0]['id_franchise_orders']; ?></strong></h3>
                            </div>
                        </div>
                        <div class="row m-t-20">                                 
                            <div class="form-group">
                                <label for="txtfranchisename" class="col-md-2 control-label">Franchise Name</label>
                                <div class="col-md-10">
                                    <input tabindex="1" readonly="readonly" type="text" class="form-control" placeholder="Franchise Name" id="txtfranchisename" name="txtfranchisename" value="<?php if (isset($order)) {echo $order[0]['franchise_name'];} ?>" required="required">
                                    <input type="hidden" class="form-control" placeholder="Supplier ID" id="txtfranchiseid" name="txtfranchiseid" value="<?php if (isset($order)) {echo $order[0]['franchise_id'];} ?>">
                                    <input type="hidden" class="form-control" placeholder="PO ID" id="txtorderid" name="txtorderid" value="<?php if (isset($order)) {echo $order[0]['id_franchise_orders'];} ?>">
                                </div>
                            </div>
                        </div>
                         <div class="form-group" id="div_rec_pay">
                            <div class="col-md-2">
                            </div>
                            <div class="col-md-10">
                                <div class="col-md-3" >
                                   <div class="radio radio-info radio-inline">
                                       <input type="radio" onclick="showhidebank();" value="Bank" required="required" name="voucher_payment_mode" >
                                        <label for="voucher_payment_mode"> Bank </label>
                                    </div>
                                </div>
                                <div class="col-md-3 m-b-10">
                                  <div class="radio radio-info radio-inline">
                                        <input type="radio" onclick="showhidebank();" value="Cash" required="required" name="voucher_payment_mode">
                                        <label for="voucher_payment_mode"> Cash </label>
                                    </div>
                                </div>
                                <div class="col-md-3 m-b-10">
                                  <div class="radio radio-info radio-inline">
                                        <input type="radio" onclick="showhidebank();" value="Card" required="required" name="voucher_payment_mode">
                                        <label for="voucher_payment_mode"> Card </label>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="form-group" id="showbank" style="display:none">
                            
                                <label class="control-label col-md-2">Select Bank</label>
                            
                            <div class="col-md-10">    

                                <select class="form-control" name="bank_accounts">
                                    
                                    <?php foreach($bank_accounts as $ba){?>
                                    <option value="<?php echo $ba['id_account_heads'];?>"><?php echo $ba['account_head'];?></option>
                                    <?php } ?>
                                </select>
                            </div>
                        </div>
                        <div class="form-group" id="showcash" style="display:none">
                            
                                <label class="control-label col-md-2">Select Cash Account</label>
                            
                            <div class="col-md-10">    

                                <select class="form-control" name="cash_accounts">
                                    
                                    <?php foreach($cash_accounts as $ca){?>
                                    <option value="<?php echo $ca['id_account_heads'];?>"><?php echo $ca['account_head'];?></option>
                                    <?php } ?>
                                </select>
                            </div>
                        </div>
                        <div class="form-group" id="showcard" style="display:none">
                            
                                <label class="control-label col-md-2">Select Card</label>
                            
                            <div class="col-md-10">    

                                <select class="form-control" name="card_accounts">
                                    
                                    <?php foreach($card_accounts as $carda){?>
                                    <option value="<?php echo $carda['id_account_heads'];?>"><?php echo $carda['account_head'];?></option>
                                    <?php } ?>
                                </select>
                            </div>
                        </div>
                        <div class="row">
                            <div class="form-group">
                            <!--Instrument Number-->
                                <label class="col-md-2  control-label">Instrument #</label>
                                <div class="col-md-10">
                                    <input class="form-control numeric" name="instrument_number" id="instrument_number" value = "">
                                </div>
                            </div>
                        </div>
                        <div class="row">                                 
                            <div class="form-group">
                                <label for="account_voucher_date" class="col-md-2 control-label">Receiving Date</label>
                                <div class="col-md-10">
                                    <input class="form-control" required="required" id="account_voucher_date" name="account_voucher_date">                                           
                                </div>
                            </div>
                        </div>
                        <hr>
                        <div class="row">                                 
                            <div class="form-group">
                                <label for="txtreceivable" class="col-md-2 control-label">Receivable</label>
                                <div class="col-md-6">
                                    <input class="form-control decimal" id="txtreceivable" readonly="readonly" name="txtreceivable" value="<?php echo $receivings;?>">                                           
                                </div>
                            </div>
                        </div>
                        <div class="row">                                 
                            <div class="form-group">
                                <label for="txtreceivednow" class="col-md-2 control-label">Received Now</label>
                                <div class="col-md-6">
                                    <input  onchange="calculate_withholding();" class="decimal" style="font-size: 20px; font-weight: bold; text-align: right"  id="txtreceivednow"  name="txtreceivednow" value="0">                                           
                                </div>
                            </div>
                        </div>
                        <div class="row">                                 
                            <div class="form-group">
                                <label for="txtwithholding" class="col-md-2 control-label">Withholding Tax</label>
                                <div class="col-md-6">
                                    <input onchange="calculate_receivednow();" class="decimal" style="font-size: 20px; font-weight: bold; text-align: right"  id="txtwithholding"  name="txtwithholding" value="0">                                           
                                </div>
                            </div>
                        </div>
                        
                        <div class="divider"></div>
                       
                        <div class="form-group">
                            <div class="col-md-2">
                                <label class="control-label">Description</label>
                            </div>
                            <div class="col-md-10">
                                <textarea type="" class='form-control' required="required"  id="description" name='description'><?php echo 'Received Amount against Franchise Sale Order # ' . $order[0]['id_franchise_orders'] . ' From ' . $order[0]['franchise_name'] ; ?></textarea>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-md-2">
                                <label class="control-label">Business Partner Name</label>
                            </div>
                            <div class="col-md-10">
                                <input class='form-control' readonly="readonly" name='business_partner' id='business_partner' value="<?php echo $order[0]['franchise_name']; ?>"/>
                                <input type='hidden' class='form-control' name='business_partner_id' id='business_partner_id' value="<?php echo $order[0]['franchise_id']; ?>"/>
                            </div>
                            
                            
                            
                        </div>
                        <div class="form-group">    
                            <!--Cost Center Type-->
                            <div class="col-md-2">
                                <label class="control-label">Cost Center Type</label>
                            </div>
                            <div class="col-md-10">
                                
                                <select onchange="costcentertypechange();" class="form-control" name="cost_center_type" id="cost_center_type">
                                    <option value="0">Select</option>
                                    <?php foreach($cost_center_types as $cct){?>
                                    <?php if($cct['account_cost_center']!=='Staff'){;?>
                                    <option value="<?php echo $cct['id_account_cost_center'];?>"><?php echo $cct['account_cost_center'];?></option>
                                    <?php }} ?>
                                </select>
                             </div>
                        </div>
                        <div class="form-group">    
                            <!--Cost Center-->
                            <div class="col-md-2">
                                <label class="control-label">Cost Center</label>
                            </div>
                            <div class="col-md-10">
                                <input class="form-control" name="cost_center" required="required"  id="cost_center" value=""/>
                            </div>
                            
                        </div>
                        
                        <div class="divider"></div>
                         <div class="form-group m-b-0">
                            <div class="col-sm-offset-11 col-sm-12">
                                <button style="display: none;" id="btn_submit"  type="submit" onclick='$("#supplier_payment_csrf").val($("#cook").val());' class="btn btn-info waves-effect waves-light">Receive Now</button>
                            </div>
                        </div>
                        
                        
                    </form>
                </div>
            </div>
          </div>
    </div>
    
    
    
    <script>
$(document).ready(function() {
    $(".numeric").keypress(function(e) {
        //if the letter is not digit then display error and don't type anything
        if (e.which != 13 && e.which != 8 && e.which != 0  && e.which != 46 && (e.which < 48 || e.which > 57)) {
            return false;
        }
    });
    
    $(".decimal").keypress(function(e) {
        //if the letter is not digit then display error and don't type anything
        if (e.which != 13 && e.which != 8 && e.which != 0  && e.which != 46 && (e.which < 48 || e.which > 57) ) {

            return false;
        }
    });

    $('#account_voucher_date').datepicker({
        autoclose: true,
        todayHighlight: true,
        format: 'yyyy-mm-dd'
    });

});

    function showhidebank(){
       
        if($('input[name=voucher_payment_mode]:checked').val()=="Bank"){
            
            $("#showbank").show();
            $("#showcash").hide();
            $("#showcard").hide();
            $("#payment_mode").val("Bank");
        } else if($('input[name=voucher_payment_mode]:checked').val()=="Cash"){ 
            $("#showbank").hide();
            $("#showcash").show();
            $("#showcard").hide();
            $("#payment_mode").val("Cash");
        } else if($('input[name=voucher_payment_mode]:checked').val()=="Card"){ 
            $("#showbank").hide();
            $("#showcash").hide();
            $("#showcard").show();
            $("#payment_mode").val("Card");
        }
        
    }
    
    function costcentertypechange(){
        if($("#cost_center_type option:selected").text()!=="Staff"){
            $("#cost_center").select2('destroy'); 
            $("#cost_center").val($("#cost_center_type option:selected").text()); 
        } else {
            enable_costcenterstaff();
        }
            
    }
    function enable_costcenterstaff(){
       $("#cost_center").select2({
            ajax: {
              url: '<?php echo base_url();?>staff_controller/searchnameforstaff',
              dataType: 'json',
              quietMillis: 1000,
              data: function (term, page) {
                  
                return {
                    staffname: term, // search term
                    page_limit: 30, // page size
                    page: page // page number
                };
              },
              results: function (data, page) {
                 
                    var more = (page * 30) < data.length;
                    return {results: data, more: more};
                }
              },
            escapeMarkup: function (m) { return m; }, // let our custom formatter work
            minimumInputLength: 1,
            formatResult: function (option) {
               return option.staff_fullname+" | "+option.staff_cell ;
            },
            formatSelection: function (option) {
                
                return option.staff_fullname+" | "+option.staff_cell;
            }
          });
         
    }
    
    function calculate_withholding(){
//        console.log('onchange');
//        var receivable = parseFloat($("#txtreceivable").val());
//        var received = parseFloat($("#txtreceivednow").val());
//        var withholding = receivable - received;
//        
//        $("#txtwithholding").val(withholding);
        if($("#txtreceivednow").val()>0){
            $("#btn_submit").show();
        }else{
            $("#btn_submit").hide();
        }
    }
    
    function calculate_receivednow(){
//        console.log('onchange');
//        var receivable = parseFloat($("#txtreceivable").val());
//        var withholding = parseFloat($("#txtwithholding").val());
//        var received = receivable - withholding;
//        
//        $("#txtreceivednow").val(received);
        
    }
</script>