<style>

    .table tr .bifurcate >td{
        border-top:2px solid #eee;
    }
</style>
<div class="wrapper">
    <div class="container-full">
        <div class="row m-t-20">
            <div class="col-md-12">
                <div class="panel panel-default m-t-20">
                    <div class="panel-body">
                        <div class="row">
                            <div class="pull-left" >
                                <h3 class="logo invoice-logo"><?php
                                    if (isset($business)) {
                                        echo "<img src='" . base_url() . 'assets/images/business/' . $business[0]['business_logo'] . "' alt='" . $business[0]['business_name'] . "' class='img-responsive' />";
                                    } else {
                                        echo 'SkedWise';
                                    }
                                    ?></h3>
                            </div>
                            <div class="pull-right m-t-20" >
                                <div class="col-md-9 hidden-print m-t-20">
                                    <form id="Sheet-Form" method="POST" action='<?php echo base_url(); ?>checkcustomerstaffhistory'>
                                        <input type="hidden" name="csrf_test_name" id="daily_sheet_csrf" value=""/>
                                        <div class="row">
                                            <div class="col-md-12">
                                                <div class="col-md-5">
                                                    <label>For</label>

                                                </div>
                                                
                                                <div class="col-md-2">
                                                    <label>Run</label>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="row">
                                            <div class="col-md-12">
                                                <div class="col-md-5">

                                                   
                                                </div>
                                                
                                                <div class="col-md-2">
                                                    <button type='submit' onclick="$('#daily_sheet_csrf').val($('#cook').val());" class="btn btn-pink btn-bordred waves-effect w-md waves-light m-b-5">Run</button>
                                                </div>
                                            </div>
                                        </div>
                                    </form>
                                </div>
                                <div class="col-md-3 hidden-print m-t-20">
                                    <div class="row">
                                        <div class="col-md-12"><label>&nbsp;</label></div>
                                    </div>
                                    <div class="row">
                                        <div class="col-md-12">
                                        <?php if(DOWNLOAD == true || $this->session->userdata('role') == 'Admin' || $this->session->userdata('role')=='Super User'){ ?>
                                            <a class="btn btn-warning m-l-10" onclick="tableToExcel('sheet1', 'StaffDaySheet')" style="float:right">Export to Excel</a>
                                            <a href="javascript:window.print()" class="btn btn-inverse waves-effect waves-light hidden-print pull-right" id="btnprint"><i class="fa fa-print"></i></a>
                                        <?php } ?>
                                        </div>
                                    </div>
                                    <!--<a class="btn btn-warning m-l-10" onclick="tableToExcel('sheet1', 'Marketing Sheet')" style="float:right">Export to Excel</a>-->
<!--                                    <a class="btn btn-warning m-l-10" href="<?php //echo base_url('marketing_controller/marketing_excell'.'/'.$date);                                                      ?>" style="float:right">Export to Excel</a>
                                    <a href="javascript:window.print()" class="btn btn-inverse waves-effect waves-light hidden-print pull-right" id="btnprint"><i class="fa fa-print"></i></a>-->
                                </div>
                            </div>
                            <div class="clearfix"></div>
                        </div>
                        <!-- end row -->

                        <div class="row">
                            <table class="table m-t-10 table-bordered"  id='sheet1'>
                                <tr>
                                    <td colspan="5"><strong>Customer Staff History</td>
                                </tr>
                                <tr>
                                    <td></td>
                                </tr>
                                <tr>
                                    <td colspan="5">
                                        <table class="table table-bordered"  id='datatable-buttons1'>
                                            <thead>
                                                <tr>
                                                    <th>Staff</th>
                                                    <th>Invoice</th>
                                                    <th>Customer</th>
                                                    <th>Service / Product</th>
                                                   
                                                    <th>Comments</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                
                                                <?php

                                                if (isset($customerStaff) && !empty($customerStaff)) {
                                                    
                                                    $staff_name = "";
                                                     $invoice= 0;
                                                    foreach ($customerStaff as $row){?>
                                                            <tr class="<?php if($invoice !==  $row['invoice_id']){echo "bifurcate";}?>">
                                                                <?php if($invoice !==  $row['invoice_id']){?>
                                                                <td <?php if($invoice !==  $row['id_invoice']){echo "style='border-top:2px solid #000;'";}?>>
                                                                    <?php echo $row['staff_name']; ?>
                                                                </td>
                                                                 <?php } else {?>
                                                                <td></td>
                                                                <?php } ?>
                                                                <?php if($invoice !==  $row['invoice_id']){?>
                                                                <td <?php if($invoice !==  $row['id_invoice']){echo "style='border-top:2px solid #000;'";}?>>
                                                                   <a target="_blank" href="<?php echo base_url();?>existinginvoice/<?php echo ($row['id_invoice']); ?>"><?php echo ($row['id_invoice']); ?></a>
                                                                </td>
                                                                <?php } else {?>
                                                                <td></td>
                                                                <?php } ?>
                                                                <?php if($invoice !==  $row['invoice_id']){?>
                                                                <td <?php if($invoice !==  $row['id_invoice']){echo "style='border-top:2px solid #000;'";}?>>
                                                                    <a target="blank" href="<?php echo base_url().'checkcustomerstaffhistory/'.$row['customer_id'].'/'.$row['staff_id']; ?>"><?php echo $row['customer_name']; ?></a>
                                                                </td>
                                                                <?php } else {?>
                                                                <td></td>
                                                                <?php } ?>
                                                                <td <?php if($invoice !==  $row['id_invoice']){echo "style='border-top:2px solid #000;'";}?>>
                                                                <?php echo $row['service_name']; ?>
                                                                </td>
                                                                <td <?php if($invoice !==  $row['id_invoice']){echo "style='border-top:2px solid #000;'";}?>>
                                                                    <?php echo $row['invoice_Date']; ?>
                                                                </td>
                                                            </tr>
                                                            <?php $staff_name=$row['staff_name'];$invoice= $row['id_invoice'];}?>
                                                </tbody>
                                                <tfoot>
                                                </tfoot>
                                                <?php } ?>
                                        </table>
                                    </td>
                                </tr>

                            </table>
                        </div>
                        <!-- end row -->
                    </div>
                </div>

                <script>
                    

var tableToExcel = (function () {
          //  application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
            var uri = 'data:application/vnd.ms-excel;base64,'
              , template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--><meta http-equiv="content-type" content="text/plain; charset=UTF-8"/></head><body><table>{table}</table></body></html>'
              , base64 = function (s) { return window.btoa(unescape(encodeURIComponent(s))) }
              , format = function (s, c) { return s.replace(/{(\w+)}/g, function (m, p) { return c[p]; }) }
            return function (table, name) {
                if (!table.nodeType) table = document.getElementById(table)
                var ctx = { worksheet: name || 'Worksheet', table: table.innerHTML }
                var link = document.createElement("a");
                
                var d = new Date();
                var datestring = ("0" + d.getDate()).slice(-2) + "-" + ("0"+(d.getMonth()+1)).slice(-2) + "-" +
                d.getFullYear() + " " + ("0" + d.getHours()).slice(-2) + ":" + ("0" + d.getMinutes()).slice(-2);
    
                var datestring = $("#namedate").html();
                link.download = ctx.worksheet + ' ' + datestring;
                link.href = uri + base64(format(template, ctx));
                link.click();
                //window.location.href = uri + base64(format(template, ctx))
            }
        })()
     
                </script>