<style>
    /* enable absolute positioning */
    .inner-addon { 
        position: relative; 
    }

    /* style icon */
    .inner-addon .glyphicon {
        position: absolute;
        padding: 10px;
        pointvaler-events: none;
    }

    /* align icon */
    .left-addon .glyphicon  { left:  0px;}
    .right-addon .glyphicon { right: 0px;}

    /* add padding  */
    .left-addon input  { padding-left:  30px; }
    .right-addon input { padding-right: 30px; }

    .loader {
        position: fixed;
        left: 0px;
        top: 0px;
        width: 100%;
        height: 100%;
        z-index: 9999;
        background: url('<?php echo base_url(); ?>assets/images/page-loader-1.gif') 50% 50% no-repeat ;
        display: none;
    }


    table.dataTable tr.group td{font-weight:bold;background-color:#e0e0e0}
    
     table.dataTable tr.group,
        tr.group:hover {
            background-color: #ddd !important;
        }
    
</style>

<div class="wrapper">
    <div class="container-full">
        <!-- Page-Title -->
        <div class="row">
            <div class="col-sm-12">
                <div class="btn-group pull-right m-t-15">
                    
                </div>
                <h4 class="page-title">Cash Registers Status (<?php echo $business[0]['business_name'];?>):</h4>
            </div>
        </div>

        <div class="row" id="divselection">
            <div class="col-sm-12">
                <div class="card-box ">
                    <h4 class="header-title m-t-0 m-b-10">Filters:</h4>
                    <div class="row m-b-10" id="div-filters">
                        <div class="col-lg-12">
                            <div class="row">
                                <div class="col-lg-6">
                                    <label class="control-label">Select Ending date of the week</label>
                                </div>
                                <div class="col-lg-4">
                                    <label class="control-label">Filter Status</label>
                                </div>
                                <div class="col-lg-2"></div>    
                            </div>
                        </div>
                        <div class="row">
                            <form method="post" action="<?php echo base_url();?>cashregister_listing">
                                <input type="hidden" name="csrf_test_name" id="cash_register_csrf" value=""/>
<!--                                <div class="col-lg-3">
                                    <input style="background-color: white;" readonly class="form-control" type="text" name="startdate" id="startdate" value="<?php if(isset($startdate)){echo $startdate;}?>"/>                                
                                </div>-->
                                <div class="col-lg-6">
                                    <input style="background-color: white;" readonly class="form-control" type="text" name="enddate" id="enddate" value="<?php if(isset($enddate)){echo $enddate;}?>"/>
                                </div>
                                <div class="col-lg-4">
                                    <select class="form-control" id="cashregister_status" name="cashregister_status">
                                        
                                        <option <?php if(isset($selectedstatus)){if($selectedstatus== 'open'){echo " selected='selected' ";}}?> value="open">Open</option>
                                        <option <?php if(isset($selectedstatus)){if($selectedstatus== 'All'){echo " selected='selected' ";}}?> value="All">All</option>                                        
                                        <option <?php if(isset($selectedstatus)){if($selectedstatus== 'closed'){echo " selected='selected' ";}}?> value="closed">Closed</option>
                                    </select>
                                </div>
                                <div class="col-lg-2"><button type="submit" onclick="$('#cash_register_csrf').val($('#cook').val());" class="btn btn-pink btn-bordred waves-effect w-md waves-light m-b-5">Run</button></div>
                            </form>
                        </div>
                    </div>
                    
                    <div class="row">
                        <div class="col-lg-12">
                            <h4 class="header-title m-t-30 m-b-10">Cash Resister Entries:</h4>
                            <?php echo $selectedstatus; ?>
                            <table id="datatable-buttons" class="table table-bordered table-responsive" cellspacing="0">
                                <thead>
                                    <tr>
                                        <th>WorkDate</th>
                                        
                                        <th>Service Sale</th>
                                        <th>Product Sale</th>
                                        
                                        <th>+ Advance</th>
                                        <th>+ Recovery</th>
                                        <th>+ Retained</th>
                                        <th>- Balance</th>
                                        
                                        <th>Vouchers Used</th>
                                        <th>Advance Adjusted</th>
                                        
                                        <th>CC Charge</th>
                                        <th>Sales Tax</th>
                                        
                                        <th>Check Invoices</th>
                                        <th>Card Invoices</th>
                                        <th>Cash Invoices</th>
                                        
                                        
                                       <th>- Till Expense</th>
                                       <th>- CC Tips</th>
                                       
                                        <th>Till Denominations</th>
                                        <th class="text-danger">Difference</th>
                                        
                                        <th>Yesterday's Till</th>
                                        <th>Additional Amount</th>
                                        <th>Tomorrow's Till</th>
                                        <th>Status</th>
                                        <th>Remarks</th>
                                        
                                        <th>Action</th>
                                
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php $totalcash=0; $totalcard=0; $totalcashinhand=0; $totaldifference=0;?>
                                    <?php $index=0; foreach($transactions as $transaction){ 
                                        
                                        $register_status=$denominations[$index]->register_status;
                                        $idcashregister=$denominations[$index]->id_cash_register;
                                        $remarks= $denominations[$index]->remarks;
                                        
                                        $checks=$transaction->Checks;
                                        
                                        $totalchecks=0; 
                                        $totalCash = $transaction->totalCash ;
                                        $totalService = $transaction->totalService ;
                                        $totalRetail = $transaction->totalRetail ;
                                        $totalSale=$totalService+$totalRetail;
                                        $advanceAdj= $transaction->AdvAdj;
                                        
                                        
                                        $totalBalance = $transaction->totalBalance ;
                                        $totalRecovery = $transaction->totalRecovery ;
                                        $totalAdvance = $transaction->totalAdvance ;
                                        $totalService = $transaction->totalService;
                                        $totalRetail = $transaction->totalRetail;
                                        $totalExpense = $expenses[$index]->today_expenses;
                                        $cctip = $transaction->cctip;
                                        $other_charges= $transaction->other_charges;
                                        $tax_total = $transaction->tax_total;
                                        $cccharge= $transaction->cccharge;
                                        
                                        $totalVoucher = $vouchers[$index]->totalVoucherAmount ;
                                        $Cash = floatval($transaction->Cash);
                                        $Card = $transaction->Card ;
                                        $Checks = $transaction->Checks ;

                                        $Voucher = $transaction->totalVoucher;

                                        
                                        $totalVoucherCash = $vouchers[$index]->Cash;
                                        $totalVoucherCard = $vouchers[$index]->Card;
                                        $totalVoucherChecks = $vouchers[$index]->Checks;
                                        $yestertill = $yesterdaytill[$index]->till_amounts;
                                        $totaltillamounts = $denominations[$index]->till_amounts;
                                        $additionalamount= $denominations[$index]->cash_addition ;
                                        $totalRetained= $transaction->totalRetained;
                                        $calCash=floatval(intval($Cash) + intval($totalVoucherCash) );
                                        $totalCash = floatval($calCash - intval($totalExpense)) ;
                                        $totalSale = floatval(intval($totalSale) + intval($totalVoucher)) ;

                                        $cashInHand= $denominations[$index]->cash;
                                        $difference= $denominations[$index]->diff ;

                                        $diff=((floatval(intval($cashInHand) - intval($yestertill) - intval($additionalamount)) - intval($totalCash)) );

                                        $paymentCash = (floatval(intval($Cash) + intval($totalVoucherCash)) );
                                        $paymentCard = (floatval(intval($Card) + intval($totalVoucherCard)) );
                                        $paymentChecks = (floatval(intval($Checks) + intval($totalVoucherChecks)) );

                                        $totalTransaction=floatval((floatval($totalSale)+floatval($totalAdvance)+floatval($totalRecovery)+floatval($totalRetained))-(floatval($totalBalance)+floatval($totalExpense))) ;
                                ?>
                                <?php if($selectedstatus==$register_status || $selectedstatus=="All" ){?>
                                
                                    <tr>
                                       
                                            <td style="border-top:1px solid #000"><?php echo $transaction->passeddate; ?></td>
                                            
                                            <td style="border-top:1px solid #000"><?php echo $totalService; ?></td>
                                            <td style="border-top:1px solid #000"><?php echo $totalRetail; ?></td>
                                           
                                            
                                            <td style="border-top:1px solid #000"><?php echo $totalAdvance; ?></td>
                                            <td style="border-top:1px solid #000"><?php echo $totalRecovery; ?></td>
                                            <td style="border-top:1px solid #000"><?php echo $totalRetained; ?></td>
                                            
                                            <td  style="border-top:1px solid #000;"><?php echo $totalBalance; ?></td>                                            
                                             <td  style="border-top:1px solid #000"><?php echo $Voucher; ?></td>
                                             <td  style="border-top:1px solid #000"><?php echo $advanceAdj; ?></td>
                                             <td  style="border-top:1px solid #000"><?php echo $cccharge; ?></td>
                                              <td  style="border-top:1px solid #000"><?php echo $tax_total; ?></td>
                                             
                                            
                                            <td style="border-top:1px solid #000"><?php echo $paymentChecks; ?></td>
                                             <?php $totalchecks= round($totalchecks + (float)$paymentChecks,2);?>
                                            <td style="border-top:1px solid #000"><?php echo $paymentCard; ?></td>
                                             <?php $totalcard= round($totalcard + (float)$paymentCard,2);?>
                                           <td style="border-top:1px solid #000"><?php echo $paymentCash; ?></td>
                                            <?php $totalcash= round($totalcash + (float)$paymentCash,2);?>
                                            
                                           <td  style="border-top:1px solid #000; font-weight: bold;"><?php echo $totalExpense; ?></td>
                                           <td  style="border-top:1px solid #000; font-weight: bold;"><?php echo $cctip; ?></td>
                                            
                                            <td style="border-top:1px solid #000"><?php echo $cashInHand; ?></td>
                                            <?php $totalcashinhand= round($totalcashinhand + (float)$cashInHand,2);?>
                                            
                                            <td class="<?php if($diff>0){echo "text-success";}else if($diff<0){echo "text-danger";}?>" style="border-top:1px solid #000"><?php echo $diff; ?></td>
                                            
                                            <?php $totaldifference= round($totaldifference + (float)$diff,2);?>
                                            <td style="border-top:1px solid #000" class="text-info"><?php echo $yestertill; ?></td>
                                            <td style="border-top:1px solid #000" class="text-info"><?php echo $additionalamount; ?></td>
                                            <td style="border-top:1px solid #000" class="text-info"><?php echo $totaltillamounts; ?></td>
                                            <td style="border-top:1px solid #000"><?php echo $register_status; ?></td>
                                            <td style="border-top:1px solid #000">
                                             <?php if($register_status!=='' || $register_status!==null){?>   
                                                <?php echo $remarks; ?>
                                             <?php } else { ?>    
                                                (Denominations not Saved by Reception)
                                             <?php } ?>
                                            </td>
                                            
                                            
                                            <td style="border-top:1px solid #000" class='noprintval'> 
                                                <?php if($register_status=='open'){?>
                                                    <button class="btn " onclick="openprocess('<?php echo $idcashregister;?>','<?php echo $transaction->passeddate; ?>','<?php echo $totalService; ?>','<?php echo $totalRetail; ?>','<?php echo $paymentCash; ?>','<?php echo $paymentCard; ?>','<?php echo $totalExpense; ?>');" >Process </button>
                                                <?php } else if($register_status=='closed') { ?>
                                                    This Day Vouchers Have Already Been Generated!
                                                <?php } else { ?>
                                                    Cash Register not Saved by Reception for this day!
                                                <?php } ?>
                                            </td>
                                        
                                            
                                    </tr>
                                <?php } $index++; }?>
                                </tbody>
                                <tfoot>
                                    <th colspan="11" ></th>
                                    <th><?php echo $totalchecks;?></th>
                                    <th><?php echo $totalcard;?></th>
                                   <th><?php echo $totalcash;?></th>
                                   <th></th>
                                   <th></th>
                                    <th><?php echo $totalcashinhand;?></th>
                                    <th class="text-danger"><?php echo $totaldifference;?></th>
                                    
                                    <th colspan="6"></th>
                                   
                                </tfoot>
                            </table>
                            
                        </div>
                    </div>
                </div>
            </div>
        </div>    
    </div>
</div>

 <!--Modals-->

        <!--Process Cash Register Modal-->
        <div id="processcash" class="modal fade in" tabindex="-1" role="dialog" aria-labelledby="processcash" aria-hidden="true" style="display: none;">
            <div class="modal-dialog modal-lg">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                        <h4 class="modal-title" id="custom-width-modalLabel">Create Vouchers for Cash:</h4>
                    </div>
                    <div class="modal-body">
                        <div class="row">
                            <div class="form-horizontal" role="form">
                                 <div class="form-group">
                                    <label class="col-md-2 control-label"   for="mId">Cash Register ID:</label>
                                    <div class="col-md-10">
                                        <input type="text" readonly="readonly" id="mId" name="mId" class="form-control" >
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-md-2 control-label"  for="mDate">Date:</label>
                                    <div class="col-md-10">
                                        <input type="text" readonly="readonly" id="mDate" name="mDate" class="form-control" >
                                    </div>
                                   
                                </div>
                                
                                <div class="form-group">
                                    <div class="col-md-2"></div>
                                    <div class="col-md-8">
                                        <div class="col-md-4" style="text-align: center;">Debit</div>
                                         <div class="col-md-4" style="text-align: center;">Credit</div>
                                    </div>
                                    <div class="col-md-2"></div>
                                        
                                </div>
                                
                                
                                <div class="form-group">
                                    <label class="col-md-2 control-label"  for="mProductSale">Retail Sale:</label>
                                    <div class="col-md-8">
                                        <div class="col-md-4" style="text-align: center;"><input type="text" readonly="readonly" id="mProductSale" name="mProductSale" class="form-control" ></div>
                                         <div class="col-md-4" style="text-align: center;"></div>
                                        
                                        
                                    </div>
                                     <div class="col-md-2">
                                         
                                        <select class="form-control" id="postcash">
                                            <option class="text-success" value="Yes">Post</option>
                                            <option class="text-danger" value="No">Do Not Post</option>                                            
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-md-2 control-label"  for="mServiceSale">Service Sale:</label>
                                    <div class="col-md-8">
                                        <div class="col-md-4" style="text-align: center;"><input type="text" readonly="readonly" id="mServiceSale" name="mServiceSale" class="form-control" ></div>
                                         <div class="col-md-4" style="text-align: center;"></div>
                                        
                                    </div>
                                     <div class="col-md-2">
                                        <select class="form-control" id="postservicesale">
                                            <option class="text-success" value="Yes">Post</option>
                                            <option class="text-danger" value="No">Do Not Post</option>                                            
                                        </select>
                                    </div>
                                </div>
                                <div class="seperator">
                                    <hr/>
                                </div>
                                
                                <div class="form-group">
                                    <label class="col-md-2 control-label"  for="mCash">Cash Income:</label>
                                    <div class="col-md-8">
                                        <input type="text" readonly="readonly" id="mCash" name="mCash" class="form-control" >
                                    </div>
                                     <div class="col-md-2">
                                        <select class="form-control" id="postcash">
                                            <option class="text-success" value="Yes">Post</option>
                                            <option class="text-danger" value="No">Do Not Post</option>                                            
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-md-2 control-label"  for="mCard">Sale Card:</label>
                                    <div class="col-md-8">
                                        <input type="text" readonly="readonly" id="mCard" name="mCard" class="form-control" >
                                    </div>
                                     <div class="col-md-2">
                                        <select class="form-control" id="postcard">
                                            <option class="text-success" value="Yes">Post</option>
                                            <option class="text-danger" value="No">Do Not Post</option>                                            
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-md-2 control-label"  for="mCard">Till Expense:</label>
                                    <div class="col-md-8">
                                        <input type="text" readonly="readonly" id="mExpense" name="mExpense" class="form-control" >
                                    </div>
                                     <div class="col-md-2">
                                        <select class="form-control" id="postexpense">
                                            <option class="text-success" value="Yes">Post</option>
                                            <option class="text-danger" value="No">Do Not Post</option>                                            
                                        </select>
                                    </div>
                                </div>
                                </hr>
                                
                            </div>
                            
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default waves-effect" data-dismiss="modal">Close</button>
                        <button onclick="update();" type="button" class="btn btn-custom waves-effect waves-light">Save</button>
                    </div>
                </div><!-- /.modal-content -->
            </div><!-- /.modal-dialog -->
        </div>

<script>
    $(document).ready(function() {
        
        $("#startdate").datepicker({autoclose:true, format:'yyyy-mm-dd'});
        $("#enddate").datepicker({autoclose:true, format:'yyyy-mm-dd'});


        $('#datatable-buttons').DataTable({
            lengthMenu: [[25, 50, -1], [25, 50, "All"]],
            stateSave: true,            
            ordering:false,
            <?php if(DOWNLOAD == true || $this->session->userdata('role') == 'Admin' || $this->session->userdata('role')=='Super User'){ ?>
                dom: "Bfrtlip",
                buttons: [{extend: "copy", className: "btn-sm btn-custom btn-trans"}, {extend: "csv", className: "btn-sm btn-pink btn-trans"}, {
                    extend: "excel",
                    className: "btn-sm btn-warning btn-trans"
                }, {extend: "pdf", className: "btn-sm btn-purple btn-trans"}],
            <?php } else { ?>
                    dom: "frtlip",
            <?php } ?> 
            responsive: true
            
        });
        
        toastr.options = {
            "closeButton": true,
            "debug": true,
            "newestOnTop": true,
            "progressBar": true,
            "positionClass": "toast-bottom-center",
            "preventDuplicates": true,
            "onclick": null,
            "showDuration": "300",
            "hideDuration": "1000",
            "timeOut": "5000",
            "extendedTimeOut": "1000",
            "showEasing": "swing",
            "hideEasing": "linear",
            "showMethod": "fadeIn",
            "hideMethod": "fadeOut"
        }

        $(".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 < 48 || e.which > 57)) {
                return false;
            }
        });
    });


    function openprocess(id,date, servicesale, productsale, cash,card ,expense){
        $("#mId").val(id);
        $("#mDate").val(date);
        
        $("#mServiceSale").val(servicesale);
        $("#mProductSale").val(productsale);
        
        $("#mCash").val(cash);
        $("#mCard").val(card);
        $("#mExpense").val(expense);
        
        $("#processcash").modal('show');
        
    }

</script>