<div class="modal fade none-border" id="cash_till_modal" tabindex="-1" role="dialog" aria-labelledby="Cash Register" aria-hidden="true">
    <div class="modal-dialog modal-lg" style="width:100%;">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title">Cash Till Status For <span id="cashTillDate"><?php echo date('d-m-Y'); ?></span></h4>
                <input type="hidden" id='dbformatdate'>
            </div>
            <div class="modal-body">
                
                <div class="row">
                    
                    <center><strong>Cash Till Transfer Form</strong></center>
                    
                    <br>
                    
                    <div class="col-lg-12">
                        <table class="table table-bordered">
                            <thead>
                                <tr>
                                    <th colspan="6"></th>
                                    <th colspan="6" class='text-success' style="text-align: center">Transfer To</th>
                                    <th></th>
                                        
                                </tr>
                                <tr>
                                    <th>Account Head</th>
                                    <th>Yesterday's Till Amount</th>
                                    <th class='text-success' style="text-align: right;">System Cash Total</th>
                                    <th class='text-success' style="text-align: right;">System Cash Less CCTips</th>
                                    <th class='text-success' style="text-align: right;">Opening Amount</th>
                                    <th class='text-success' style="text-align: right;">You Should Have</th>
                                    <th style="text-align: right;">Your Denomination Total</th>
                                    <th style="text-align: right;">Extra Cash In Hand</th>
                                    <th style="text-align: right;">Missing Cash</th>
                                    
                                    <th class='text-success'  style="text-align: right;">CC Tip Payable</th>
                                    <th class='text-success' style="text-align: right;">Leave In Till (Tomorrow's Opening)</th>
                                    <th class='text-success' style="text-align: right;">To 'Missing Cash' Expense</th>
                                    <th class='text-success' style="text-align: right;">To 'UnAccounted For' Income</th>
                                    <th class='text-success' style="text-align: right;">To Cash In Hand</th>
                                    <th class='text-success' style="text-align: right;">To Bank</th>
                                    
                                    
                                    <th class='text-success' style="text-align: right;">Action</th>
                                </tr>
                            </thead>
                            <tbody>
                                
                                <tr>
                                    <form method="post" action="<?php echo base_url();?>cashtill_controller/cashtillpost">
                                        
                                        <td style="width: 15%"><span id="accounttillcash">Cash</span></td>
                                        <td style="text-align: right;" ><span id="totalyesterdaytill">0.00</span></td>
                                        <td style="text-align: right;" ><span id="totaltillcash">0.00</span></td>
                                        <td style="text-align: right;" ><span id="totaltillcashcc">0.00</span></td>
                                        <td style="text-align: right;" ><span id="totaltillopeningamount">0.00</span></td>
                                        <td style="text-align: right;" ><strong><span id="totalshouldhave">0.00</span></strong></td>
                                        <td style="text-align: right;" ><span id="totaldenominations">0.00</span></td>
                                        <td style="text-align: right;" ><span id="extra">0.00</span></td>
                                        <td style="text-align: right;" ><span id="missing">0.00</span></td>

                                        <td  ><input style="text-align: right; width:80px;" id="cctip" class="form-control" readonly="readonly" name="cctip" value="0"></td>
                                        <td  ><input style="text-align: right; width:80px;" class="form-control" readonly="readonly" name="tomorrowtill" id="tomorrowtill" value="0"></td>
                                        <td  ><input style="text-align: right; width:80px;" class="form-control" readonly="readonly" name="missingexpense" id="missingexpense" value="0"></td>
                                        <td  ><input style="text-align: right; width:80px;" class="form-control" readonly="readonly" name="unaccounted" id="unaccounted" value="0"></td>
                                        
                                        <td style="text-align: right;" >
                                            
                                            <input type="hidden" id="systemtillcash" name="systemtillcash" value="">
                                            <input type="hidden" id="yesterdaytill" name="yesterdaytill" value="">
                                            <input type="hidden" id="denominationcash" name="denominationcash" value="">
                                            <input type="hidden" id="openingcash" name="openingcash" value="">
                                            <input type="hidden" id="tilldate" name="tilldate" value="">
                                            <input type="hidden" id="calanderdate" name="calanderdate" value="">
                                            <input type="hidden" id="id_cash_register" name="id_cash_register" value="">
                                            
                                            <input class="form-control" style='text-align: right; width:80px;' id="cihamount" name="cihamount" onchange="verifytotal('cihamount')" value='0'>
                                            <select class='form-control' id='cashaccount' name='cashaccount'>

                                            </select>
                                        </td>
                                        <td style="text-align: right;" > 
                                            <input class="form-control" style='text-align: right; width:80px;' id="bankamount" name="bankamount" onchange="verifytotal('bankamount')" value='0'>
                                            <select class='form-control' id='bankaccount' name='bankaccount'>

                                            </select>
                                        </td>
                                        
                                        <td ><button type="submit" title="Bank Transfer" class="btn btn-warning btn-sm" style="widhth: 120px; white-space: normal; word-wrap: break-word" ><i class="fa fa-bank"></i> Create Transfer Voucher</button></td>
                                    </form>
                                </tr>
                                <tr >
                                     <td ><span id="accounttillcard">Card</span></td>
                                    <td style="text-align: right;"><span id="totaltillcard">0.00</span></td>
                                    <td style="text-align: right;"><span id="totaltillcard">0.00</span></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                </tr>
                                <tr >
                                     <td ><span id="accounttillcheck">Check</span></td>
                                    <td style="text-align: right;"><span id="totaltillcheck">0.00</span></td>
                                    <td style="text-align: right;"><span id="totaltillcheck">0.00</span></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                </tr>
                                <tr >
                                    <td ><span id="accounttillvoucher">Voucher</span></td>
                                    <td style="text-align: right;"><span id="totaltillvoucher">0.00</span></td>
                                    <td style="text-align: right;"><span id="totaltillvoucher">0.00</span></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                </tr>
                                
                                
                                <tr><td colspan="13"></td></tr>

                            </tbody>
                        </table>
                       
                        
                    </div>
                    
             
                    
                </div>
                
            </div>
        </div>
    </div>
</div>
<script>
    function verifytotal(elem){
        
        //var totalcash = (parseFloat($("#totaltillcash").html()) + parseFloat($("#extra").html())) - (parseFloat($("#missing").html()) + parseFloat($("#cctip").val()));
        
        //totalcash = parseFloat($('#totaldenominations').html());
       
        totalcash= parseFloat($('#totaldenominations').html()) - parseFloat($("#tomorrowtill").val() );//- parseFloat($("#cctip").val()
       
        console.log(totalcash);
        if(parseFloat($("#cihamount").val()) > totalcash){
            $("#cihamount").val(totalcash);
            $("#bankamount").val("0");
        } else if(parseFloat($("#bankamount").val()) > totalcash){
            $("#bankamount").val(totalcash);
            $("#cihamount").val("0");
        }
        var temp=0;
        if(elem == 'cihamount' && parseFloat($("#cihamount").val()) <= totalcash){
            temp = totalcash - parseFloat($("#cihamount").val());
            $("#bankamount").val(temp);
        } else if(elem == 'bankamount' && parseFloat($("#bankamount").val()) <= totalcash){
            temp = totalcash - parseFloat($("#bankamount").val());
            $("#cihamount").val(temp);
        }
        
    }
</script>    