<style>
     tr.strikethrough > td {text-decoration:line-through !important; color:red;} 
     tr.sale > td {font-weight:bold !important; color:blue;} 
</style>
<div class="wrapper">
    <div class="full-container">
        <!-- Page-Title -->
        <div class="row">
            <div class="col-sm-12">

                <h4 class="page-title">Sequenced Invoices Report</h4>
            </div>
        </div>
        
         <div class="row">
            <div class="col-md-12">
                <div class="card-box ">
                    <div class="row">
                            <div class="pull-left m-t-20 m-b-20" >
                                <h3 >
                                    <?php echo "Selected Month: ". $month. " - " . $year;?>
                                
                                </h3>
                                
                               
                            </div>
                            <div class="pull-right m-t-20" >
                                <div class="col-md-6 hidden-print m-t-20">
                                    <form method="POST" action='<?php echo base_url(); ?>sequenced_invoice_report'>
                                        <input type="hidden" name="csrf_test_name" id="daily_sheet_csrf" value=""/>
                                        <div class="col-md-10">
                                            <input type="month" autocomplete="off" class="form-control inline m-r-5" name="calendar_date" id="datepicker-autoclose1">
                                        </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>
                                    </form>
                                </div>
                                <div class="col-md-6 hidden-print m-t-20">
                                    <!--<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">
                        <div class="col-md-12">
                      <table id="tblinvoice" class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%">
                        <thead>
                        <tr>
                            <th>Day Seq.</th>
                            <th>Invoice #</th>
                            <th>Invoice Date</th>                            
                            <th>Customer</th>                                        
                            <th>Customer Cell</th>                                       
                            <th>Balance</th>                            
                            <th>Paid Amount</th>
                            <th>Advance Adjusted</th>
                            <th>Sub Total</th>
                            <th>Other Charges</th>
                            <th>Discount</th>

                            <th>Taxes</th>

                            <th>Total Payable</th>
                            <th>CC Charge</th>
                            <th>Payment Mode</th>
                            <th>Type</th>
                            <th>Recovery</th>
                            <th>Instrument</th>                                        
                            <th>Discount Remarks</th>
                            <th>Status</th>

                        </tr>
                    </thead>
                         <tbody>
                        <?php 
                            $balance = 0;
                            $netamount = 0;
                            $grossamount = 0;
                            $subtotal = 0;
                            $discount = 0;
                            $taxes = 0;
                            $paidamount = 0;
                            $cc_charge=0;
                            $totalshadow=0;
                            $totalshadowservice=0;
                            $totalshadowretail=0;

                            $actualtotalservice=0;
                            $actualtotalretail=0;
                            $actualtotal=0;

                            $advance=0;
                        ?>
                        <?php foreach ($invoices as $invoice){?>

                        <tr class="<?php if($invoice['invoice_status']!=='valid'){echo 'strikethrough';}  if($invoice['invoice_type']=='sale'){echo "sale";}?>">
                            <td><?php echo $invoice['invoice_seq']; ?></td>
                            <?php if($invoice['invoice_type']=='service'){ ?>
                            <td><a href="<?php echo base_url().'existinginvoice/'.$invoice['id_invoice']; ?>" target="_blank"><?php echo $invoice['invoice_number']; ?></a></td>
                            <?php } else { ?>
                            <td><a href="<?php echo base_url().'existingorderinvoice/'.$invoice['id_invoice']; ?>" target="_blank"><?php echo $invoice['invoice_number']; ?></a></td>
                            <?php } ?>                            
                            <td><?php echo $invoice['invoice_date']; ?></td>
                           
                            <td class="text-custom"><?php echo $invoice['customer_name']; ?></td>
                            <td>
                                <?php 
                                    if( $this->session->userdata('hide_cell') && $this->session->userdata('hide_cell') == "No"){
                                        echo $invoice['customer_cell']; 
                                    } 
                                ?>
                            </td>

                            <td class="text-danger"><?php echo $invoice['balance']; if($invoice['invoice_status']=='valid'){$balance+=$invoice['balance'];}?></td>
                            
                            <td><?php echo $invoice['paid_amount']; if($invoice['invoice_status']=='valid'){$paidamount += $invoice['paid_amount'];}?></td>
                            <td><?php echo $invoice['advance_amount']; $advance += $invoice['advance_amount'];?></td>
                            <td><?php echo $invoice['sub_total']; if($invoice['invoice_status']=='valid'){$subtotal += $invoice['sub_total'];}?></td>
                            <td><?php echo $invoice['other_charges']; ?></td>
                            <td><?php echo $invoice['discount']; if($invoice['invoice_status']=='valid'){$discount += $invoice['discount'];}?></td>

                            <td><?php echo $invoice['tax_total']; if($invoice['invoice_status']=='valid'){$taxes += $invoice['tax_total'];}?></td>

                            <td><?php echo $invoice['total_payable']; if($invoice['invoice_status']=='valid' && $invoice['invoice_seq']>0){$totalshadow += $invoice['total_payable'];} $actualtotal+=$invoice['total_payable'];?></td>
                            

                            
                            <td><?php echo $invoice['cc_charge']; if($invoice['invoice_status']=='valid'){$cc_charge += $invoice['cc_charge'];}?></td>
                            <td><?php echo $invoice['payment_mode']; ?></td>
                            <td><?php echo $invoice['invoice_type']; ?></td>
                            <td><?php echo $invoice['reference_invoice_number'] !== "" ? "<label class='label label-info'>Recovery</label>" : ""; ?></td>
                            <td><?php echo $invoice['instrument_number']; ?></td>

                            <td><?php echo $invoice['discount_remarks']; ?></td>
                            <td><?php echo $invoice['invoice_status']; ?></td>

                        </tr>

                        <?php } ?>
                    </tbody>

                        <tfoot>
                        <tr>
                            <th></th>
                            
                            <th></th>
                            <th></th>
                            <th><?php //echo $subtotal ? $subtotal : 0; ?></th>
                            <th><?php //echo $discount ? $discount : 0; ?></th>
                            <th class="text-right"><strong>Total:</strong></th>
                            <th class="text-right"><?php echo $paidamount ? $paidamount : 0; ?></th>
                            <th class="text-right"><?php echo $advance ? $advance : 0; ?></th>


                            <th ><?php //echo $grossamount ? $grossamount : 0; ?></th>
                            <th><?php //echo $taxes ? $taxes : 0; ?></th>
                            <th><?php //echo $netamount ? $netamount : 0; ?></th>
                            <th class="text-right"><?php echo $taxes ? $taxes : 0; ?></th>
                            <th class="text-right"><?php echo $actualtotal ? $actualtotal : 0; ?></th> 

                            <th></th>
                            <th></th>
                            <th></th>
                            <th></th>
                            <th></th>
                            <th></th>
                            <th></th>

                        </tr>
                    </tfoot>
                </table>
                            </div>
                        </div>
                </div>
            </div>
         </div>
    </div>
</div>

<script>
    $(document).ready(function() {
            
             $('#datepicker-autoclose').datepicker({
                autoclose: true,
                todayHighlight: true,
                format: 'yyyy-mm-dd'
            });
            
            $('#tblinvoice').DataTable({
                lengthMenu: [[10, 25, 50, -1], [10, 25, 50, "All"]],
                stateSave: true,
                fixedHeader: {header: true},
                dom: "Bfrtlip",
                    buttons: [{extend: "copy", className: "btn-sm btn-custom btn-trans"}, {extend: "csv", className: "btn-sm btn-pink btn-trans", footer: true}, {
                            extend: "excel",
                            className: "btn-sm btn-warning btn-trans"
                        }, {extend: "pdf", className: "btn-sm btn-purple btn-trans", footer: true}
                    , {extend: "print", className: "btn-sm btn-primary btn-trans", footer: true}],
                    responsive: !0,
                    "ordering": false
                    //"scrollX": true,
            });

            

        });
</script>