
<style>
    .datepicker-dropdown {top:190px !important;}
</style>
<div class="wrapper">
    <div class="container">
        <!-- Page-Title -->
        <div class="row">
            <div class="col-sm-12">
                <h4 class="page-title">Cash Till Transfer: (closing)</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" id="divselection">
            <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(); ?>insert_till_transfer">
                        <input type="hidden" name="csrf_test_name" id="till_transfer_csrf" value=""/>

                        <div class="divider"></div>
                        <div class="row">
                            <div class="col-lg-12">
                                <strong>Date: <?php echo date('Y-m-d'); ?></strong></h3>
                            </div>
                        </div>

                        <div class="row m-t-20">                                 
                            <div class="form-group">
                                <label for="txtsuppliername" class="col-md-2 control-label">Today's Cash (Till)</label>
                                <div class="col-md-10">
                                    <input tabindex="1" readonly="readonly" type="text" class="form-control" placeholder="" id="txtcashtill" name="txtcashtill" value="<?php if (isset($cash_till)) {echo $cash_till[0]['cash'];} ?>">                                    
                                    
                                </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">Payment 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="txtpayable" class="col-md-2 control-label">Payable</label>
                                <div class="col-md-6">
                                    <input class="form-control decimal" id="txtpayable" readonly="readonly" name="txtpayable" value="<?php echo $payable;?>">                                           
                                </div>
                            </div>
                        </div>
                        <?php if(isset($purchasediscountaccount)){?>
                            <div class="row">                                 
                                <div class="form-group">
                                    <label for="txtdiscount" class="col-md-2 control-label">Discount</label>
                                    <div class="col-md-6">
                                        <input onchange="calculate_total();" type= "number" min="0" value="0" style="text-align: right; width: 60px;  display: inline-block" class="form-control hidden-print text-custom" id="disc_perc"><span class="hidden-print">%</span>
                                        <input  style="border:none; font-size: 20px; font-weight: bold; text-align: right" readonly="readonly" class="decimal text-danger" id="txtdiscount"  name="txtdiscount" value="0">                                           
                                    </div>
                                </div>
                            </div>
                        
                        <?php } ?>
                        <hr>
                        <div class="row">                                 
                            <div class="form-group">
                                <label for="txtdiscountedprice" class="col-md-2 control-label">Discounted Price:</label>
                                <div class="col-md-10">
                                    <input style="width:60px; display:inline-block" readonly="readonly" class="form-control" style="border:none;"/>&nbsp;&nbsp;&nbsp;
                                    <input class="decimal text-custom" style="border:none; font-size: 20px; font-weight: bold; text-align: right;" readonly="readonly" id="txtdiscountedprice" name="txtdiscountedprice" value="<?php echo $payable; ?>">                                           
                                </div>
                            </div>
                        </div>
                        
                        <?php if(isset($salestaxaccount)){?>
                        <div class="row">                                 
                            <div class="form-group">
                                <label for="txtsalestax" class="col-md-2 control-label">Salex Tax</label>
                                <div class="col-md-6">
                                    <input onchange="calculate_total();" type= "number" min="0" value="0" style="text-align: right; width: 60px; display: inline-block" class="form-control hidden-print text-custom" id="salestax_perc"><span style="text-align: left;" class="hidden-print">%</span>
                                    <input class="decimal" style="border:none; font-size: 20px; font-weight: bold; text-align: right" id="txtsalestax"  name="txtsalestax" readonly="readonly" value="0">                                           
                                </div>
                            </div>
                        </div>
                        
                        <?php } ?>
                        
                        <?php if(isset($withhodlingtaxaccount)){?>
                            <div class="row">                                 
                                <div class="form-group">
                                    <label for="txtwithholdingtax" class="col-md-2 control-label">Withholding Tax</label>
                                    <div class="col-md-6">
                                        <input onchange="calculate_total();" type= "number" min="0" value="0" style="text-align: right; width: 60px; display: inline-block" class="form-control hidden-print text-custom" id="withholdingtax_perc"><span class="hidden-print">%</span>
                                        <input class="decimal" style="border:none; font-size: 20px; font-weight: bold; text-align: right" readonly="readonly" id="txtwithholdingtax"  name="txtwithholdingtax" value="0">                                           
                                    </div>
                                </div>
                            </div>
                        
                        <?php } ?>
                        <hr>
                        <div class="row">                                 
                            <div class="form-group">
                                <label for="txtfinalprice" class="col-md-2 control-label">Final Price:</label>
                                <div class="col-md-10">
                                    <input style="width:60px; display:inline-block" readonly="readonly" class="form-control" style="border:none;"/>&nbsp;&nbsp;&nbsp;
                                    <input class="decimal text-success" style="border:none; font-size: 20px; font-weight: bold; text-align: right;" readonly="readonly" id="txtfinalprice" name="txtfinalprice" value="<?php echo $payable;?>">                                           
                                </div>
                            </div>
                        </div>
                        
<!--                        <div class="row">                                 
                            <div class="form-group">
                                <label for="txtpaymentamount" class="col-md-2 control-label">Paying Now:</label>
                                <div class="col-md-6">
                                    <input class="form-control decimal" id="txtpaymentamount" required="required" name="txtpaymentamount">                                           
                                </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 'Payment against ' . $purchase_order[0]['purchase_order_number'] . ' to ' . $purchase_order[0]['supplier_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 $purchase_order[0]['supplier_name']; ?>"/>
                                <input type='hidden' class='form-control' name='business_partner_id' id='business_partner_id' value="<?php echo $purchase_order[0]['supplier_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 type="submit" onclick='$("#supplier_payment_csrf").val($("#cook").val());' class="btn btn-info waves-effect waves-light">Pay Now</button>
                            </div>
                        </div>
                    </form>
                </div>
            </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_total(){
            
            var saletaxperc = 0;
            var withholdingtaxperc = 0;
            var discountperc = 0;
            var total_payable =  parseFloat($("#txtpayable").val());
           
           <?php  if(isset($purchasediscountaccount)){?>
                discountperc = $("#disc_perc").val();
           <?php } ?>
           
           <?php  if(isset($salestaxaccount)){?>
                saletaxperc =  $("#salestax_perc").val();
           <?php } ?>
               
           <?php  if(isset($withhodlingtaxaccount)){?>    
                withholdingtaxperc =  $("#withholdingtax_perc").val();
           <?php } ?>
           
            var discount = ($("#txtpayable").val() * discountperc)/100;           
            var salestax = ($("#txtpayable").val() * saletaxperc)/100;
            var withholdingtax = ($("#txtpayable").val() * withholdingtaxperc)/100;
           
           var discounted_price = total_payable-discount;
           
           $("#txtdiscountedprice").val(discounted_price);
           $('#txtdiscount').val(discount); 
           $('#txtsalestax').val(salestax); 
           $('#txtwithholdingtax').val(withholdingtax); 
           
          
            var finalprice = discounted_price +salestax - withholdingtax;
           $("#txtfinalprice").val(finalprice.toFixed(2));
        }
    
</script>