<style>
     tr.strikethrough > td {text-decoration:line-through !important; color:red;} 
      /* enable absolute positioning */
    .inner-addon { 
        position: relative; 
    }

    /* style icon */
    .inner-addon .glyphicon {
        position: absolute;
        padding: 10px;
        pointer-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;
    }
</style>
<div class="wrapper">
            <div class="container">
                <!-- Page-Title -->
                <div class="row">
                    <div class="col-sm-12">
                        <div class="btn-group pull-right m-t-15">
                            <form target="_blank"  method="post" action="<?php echo base_url(); ?>franchise_controller/new_order">
                                <input type="hidden" name="csrf_test_name" id="accounts_add_csrf" value=""/>
                                <button type="submit" onclick="$('#accounts_add_csrf').val($('#cook').val());" class="btn btn-custom waves-effect waves-light" >Add New Order<span class="m-l-5"><i class="fa fa-plus"></i></span></button>
                            </form>
                        </div>
                        <h4 class="page-title">Franchise Orders</h4>
                    </div>
                </div>
                
                 <div class="row">
                    <div class="col-sm-12">
                        <div class="card-box">
                            <h4 class="header-title m-t-0 m-b-30">Select The Franchise</h4>
                            <form method="post" action = "<?php echo base_url();?>franchise_controller/franchise_orders">
                                <div class="row">
                                    <div class="col-md-2">
                                        <select class="form-control" id="selected_franchise" name='selected_franchise'>
                                            <option value="all">All</option>
                                            <?php foreach ($franchises as $franchise){?>
                                                
                                                <option <?php if($franchise['id_franchises']==$selected_franchise){echo "selected='selected'";} ?> value='<?php echo $franchise['id_franchises'];?>'><?php echo $franchise['franchise_name']. ' | '. $franchise['franchise_owner'];?></option>
                                            <?php } ?>
                                        </select>
                                    </div>
                                    <div class="col-lg-2">
                                        <input style="background-color: white;" class="form-control" type="text" name="startdate" id="startdate" value="<?php if(isset($startdate)){echo $startdate;}?>"/>                                
                                    </div>
                                    <div class="col-lg-2">
                                        <input style="background-color: white;" class="form-control" type="text" name="enddate" id="enddate" value="<?php if(isset($enddate)){echo $enddate;}?>"/>
                                    </div>
                                    
                                    <div class="col-md-2">
                                        <select class="form-control" id="order_status" name='order_status'>
                                            <option <?php if($selected_status==='all'){echo "selected='selected'";}?> value='all'>All</option>
                                            <option <?php if($selected_status==='Open'){echo "selected='selected'";}?> value='Open'>Open</option>
                                            <option <?php if($selected_status==='Invoiced'){echo "selected='selected'";}?> value='Invoiced'>Invoiced</option>
                                            <option <?php if($selected_status==='Paid'){echo "selected='selected'";}?> value='Paid'>Received</option>
                                            <option <?php if($selected_status==='Cancelled'){echo "selected='selected'";}?> value='Cancelled'>Cancelled</option>
                                        </select>
                                    </div>
                                    <div class="col-md-2">
                                        <select class="form-control" id="dtype" name='dtype'>
                                            <option <?php if($selected_dtype==='created'){echo "selected='selected'";}?> value='created'>Created date</option>
                                            <option <?php if($selected_dtype==='order'){echo "selected='selected'";}?> value='order'>Order date</option>
                                            <option <?php if($selected_dtype==='invoice'){echo "selected='selected'";}?> value='invoice'>Invoice date</option>
                                            
                                        </select>
                                    </div>
                                    <div class="col-md-2">
                                        <input type="hidden" name="run_franchise_orders" id="voucher_add_csrf" value=""/>
                                        <button type="submit"  onclick="$('#run_franchise_orders').val($('#cook').val());" class="btn btn-pink btn-bordred waves-effect w-md waves-light m-b-5">Run</button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                 </div>
                
                 <div class="row">
                    <div class="col-sm-12">
                        <div class="card-box table-responsive">
                            <h4 class="header-title m-t-0 m-b-30">Orders</h4>
                            <table id="tblfranchiseorders" class="table table-striped table-bordered dt-responsive nowrap">
                                <thead>
                                    <tr>
                                        <th>ID</th>
                                        <th>Franchise</th>
                                        <th >NTN</th>
                                        <th>Order Status</th>
                                        <th>Created By</th>
                                        <th>Created On</th>
                                        <th>Order Date</th>
                                        <th>Invoice Date</th>
                                        <th style="text-align: right">Order Value</th>
                                        <th style="text-align: right">Invoice Number</th>
                                        <th style="text-align: right">Invoice Discount</th>
                                        <th style="text-align: right">Invoice Other Charges</th>
                                        <th style="text-align: right">Invoiced Sales Tax</th>
                                        <th style="text-align: right">Invoiced Value</th>
                                        <th style="text-align: right">Receivable</th>
                                        <th>Cancel/Edit</th>                                       
                                        <th>Invoice</th>
                                        <th>Receiving</th>
                                        <th>Product Return</th>
                                        <th>Print Voucher</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php if(isset($orders)){ $totaltax=0; $totalrec=0; $totaltax=0; $totalbal=0;  $x=0; foreach($orders as $order){?>
                                    <tr <?php if($order['order_status']=='Cancelled'){echo "class='strikethrough'";}?> >
                                        <td><?php echo $order['id_franchise_orders'];?></td>
                                        <td><?php echo $order['franchise_name'].' ('.$order['franchise_order_extra'].') '.$order['order_month'].'/'.$order['order_year'] ;?></td>
                                        <td><?php echo $order['franchise_ntn'] ;?></td>
                                        <td><?php echo $order['order_status'];?></td>
                                        <td><?php echo $order['created_by'];?></td>
                                        <td><?php echo $order['created_on'];?></td>
                                        <td><?php echo $order['order_date'];?></td>
                                        <td><?php echo $order['invoice_date'];?></td>
                                        <td style="text-align: right"><?php if($order['franchise_order_value']!=null) {echo number_format($order['franchise_order_value'],2);}?></td>
                                        <td style="text-align: right"><?php echo $order['invoice_number'];?></td>
                                        <td style="text-align: right"><?php if($order['invoice_discount']!=null) {echo number_format($order['invoice_discount'],2);}?></td>
                                        <td style="text-align: right"><?php if($order['invoice_other_charges']!=null) {echo number_format($order['invoice_other_charges'],2);}?></td>
                                        <td style="text-align: right"><?php if($order['invoice_sales_tax']!=null) {echo number_format($order['invoice_sales_tax'],2);} $totaltax+=$order['invoice_sales_tax'];?></td>
                                        <td style="text-align: right"><?php if($order['invoice_total_receivable']!=null) {echo number_format($order['invoice_total_receivable'],2);} $totalrec+=$order['invoice_total_receivable'];?></td>
                                        <td style="text-align: right"><?php if($order[0]['balance']!=null) {echo number_format($order[0]['balance'],2); } $totalbal+=$order[0]['balance']?></td>
                                        
                                        <td>
                                            <div style="display:inline-block">
                                            <?php if($order['order_status']=='Open'){?>
                                            <form style="display:inline-block;" method="post" action='<?php echo base_url();?>franchise_controller/cancel_order'>
                                                <input type="hidden" name="csrf_test_name" id="order_cancel_csrf<?php echo $order['id_franchise_orders'];?>" value=""/>
                                                <input type="hidden" name='order_id' value='<?php echo $order['id_franchise_orders'];?>'>
                                                <input type="hidden" name='selected_franchise' value='<?php echo $order['franchise_id'];?>'>
                                                <button type="submit" onclick="$('#order_cancel_csrf<?php echo $order['id_franchise_orders'];?>').val($('#cook').val());" class="btn btn-sm btn-icon waves-effect waves-light btn-danger m-r-5"> <i class="fa fa-trash"></i> </button>  
                                            </form>
                                            <?php } ?>
                                            <?php if($order['order_status']=='Open'){?>    
                                            <form style="display:inline-block;" method="post" action='<?php echo base_url();?>franchise_controller/new_order'>
                                                <input type="hidden" name="csrf_test_name" id="order_edit_csrf<?php echo $order['id_franchise_orders'];?>" value=""/>                                                
                                                <input type="hidden" name='order_id' value='<?php echo $order['id_franchise_orders'];?>'>
                                                <input type="hidden" name='selected_franchise' value='<?php echo $order['franchise_id'];?>'>
                                                <button type="submit" onclick="$('#order_edit_csrf<?php echo $order['id_franchise_orders'];?>').val($('#cook').val());" class="btn btn-sm btn-icon waves-effect waves-light btn-info "> <i class="fa fa-keyboard-o"></i> </button>  
                                            </form>
                                            </div>
                                            <?php } ?>
                                        </td>
                                        
                                        <td>
                                            
                                            <form target="_blank"  method="post" action='<?php echo base_url();?>franchise_controller/new_order_invoice'>
                                                <input type="hidden" name="csrf_test_name" id="invoice_csrf<?php echo $order['id_franchise_orders'];?>" value=""/>

                                                <input type="hidden" name='order_id' value='<?php echo $order['id_franchise_orders'];?>'>
                                                <input type="hidden" name='selected_franchise' value='<?php echo $order['franchise_id'];?>'>
                                                <button type="submit" onclick="$('#invoice_csrf<?php echo $order['id_franchise_orders'];?>').val($('#cook').val());" class="btn btn-sm btn-icon waves-effect waves-light btn-pink m-l-5"> <i class="fa fa-dollar"></i> Invoice </button>  
                                            </form>
                                            
                                        </td>
                                        <td>    
                                             
                                                 <form target="_blank"  method="post" action='<?php echo base_url();?>franchise_controller/receiving_note'>
                                                    <input type="hidden" name="csrf_test_name" id="receiving_csrf<?php echo $order['id_franchise_orders'];?>" value=""/>

                                                    <input type="hidden" name='order_id' value='<?php echo $order['id_franchise_orders'];?>'>
                                                    <input type="hidden" name='selected_franchise' value='<?php echo $order['franchise_id'];?>'>
                                                    <button type="submit" onclick="$('#receiving_csrf<?php echo $order['id_franchise_orders'];?>').val($('#cook').val());" class="btn btn-sm btn-icon waves-effect waves-light btn-warning m-l-5"> <i class="fa fa-dollar"></i> Payment </button>  
                                                </form>
                                            
                                        </td>
                                        <td>
                                            <?php if($order['order_status']=='Invoiced' ||$order['order_status']=='Paid'){?>
                                                <form target="_blank"  method="post" action='<?php echo base_url();?>franchise_controller/franchise_product_return'>
                                                    <input type="hidden" name="csrf_test_name" id="return_csrf<?php echo $order['id_franchise_orders'];?>" value=""/>
                                                    <input type="hidden" name='order_id' value='<?php echo $order['id_franchise_orders'];?>'>
                                                    <input type="hidden" name='selected_franchise' value='<?php echo $order['franchise_id'];?>'>
                                                    <button type="submit" onclick="$('#return_csrf<?php echo $order['id_franchise_orders'];?>').val($('#cook').val());" class="btn btn-sm btn-icon waves-effect waves-light btn-danger m-l-5"> Returned</button>  
                                                </form>
                                            <?php } ?>
                                        </td>
                                        <td>
                                            <?php if($order['order_status']=='Invoiced'){?>
                                                
                                                <form target="_blank"  method="post" action='<?php echo base_url();?>franchise_controller/print_receiving'>
                                                    <input type="hidden" name="csrf_test_name" id="receiving_csrf<?php echo $order['id_franchise_orders'];?>" value=""/>

                                                    <input type="hidden" name='order_id' value='<?php echo $order['id_franchise_orders'];?>'>
                                                    <input type="hidden" name='selected_franchise' value='<?php echo $order['franchise_id'];?>'>
                                                    <button type="submit" onclick="$('#receiving_csrf<?php echo $order['id_franchise_orders'];?>').val($('#cook').val());" class="btn btn-sm btn-icon waves-effect waves-light btn-primary m-l-5"> <i class="fa fa-print"></i> Receiving</button>  
                                                </form>
                                            <?php }else if($order['order_status']=='Paid'){?>
                                                <form method="post" action='<?php echo base_url();?>franchise_controller/print_receiving'>
                                                    <input type="hidden" name="csrf_test_name" id="receiving_csrf<?php echo $order['id_franchise_orders'];?>" value=""/>

                                                    <input type="hidden" name='order_id' value='<?php echo $order['id_franchise_orders'];?>'>
                                                    <input type="hidden" name='selected_franchise' value='<?php echo $order['franchise_id'];?>'>
                                                    <button type="submit" onclick="$('#receiving_csrf<?php echo $order['id_franchise_orders'];?>').val($('#cook').val());" class="btn btn-sm btn-icon waves-effect waves-light btn-primary m-l-5"> <i class="fa fa-print"></i> Receiving </button>  
                                                </form>
                                            <?php }?>
                                        </td>
                                    </tr>
                                    <?php $x++;} }?>
                                    
                                </tbody>
                                <tfoot>
                                    <tr>
                                        <th colspan="12"></th>
                                        <th style="text-align:right;"><?php if($totaltax!=null){echo number_format($totaltax,2);}?></th>
                                        <th style="text-align:right;"><?php if($totalrec!=null){echo number_format($totalrec,2);}?></th>
                                        <th style="text-align:right;"><?php if($totalbal!=null){echo number_format($totalbal,2);}?></th>
                                        <th style="text-align:right;" colspan="5"></th>
                                    </tr>
                                </tfoot>
                            </table>
                        </div>
                    </div>
                 </div>
                
            </div> <!-- End Container-->
            
<script>
    var startdate = '';
     var enddate = '';
     
    $(document).ready(function() {
        
        $("#selected_franchise").select2();
        
         $('#tblfranchiseorders').DataTable({
            lengthMenu: [[10, 25, 50, -1], [10, 25, 50, "All"]],
            stateSave: true,
            <?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: !0
        });
        
        
         $("#startdate").datepicker({autoclose:true, format:'yyyy-mm-dd'});
        $("#enddate").datepicker({autoclose:true, format:'yyyy-mm-dd'});


        
    });

</script>