<style>
    body{font-family: sans-serif;}
    hr{margin-top:5px;
       margin-bottom: 5px;}
</style>

<div class="wrapper" id="printwrapper" style="color:#000 !important; font-family: 'Roboto', sans-serif !important; font-size: 14px; ">
            <div class="container">
                <!-- Page-Title -->
                
                 <?php if($invoice[0]['balance'] > 0 && $invoice[0]['is_recovery']==='Yes'){?>
                <div class="row hidden-print" >
                    <div class="col-sm-12" >
                        <div class="alert alert-danger">
                            <h3 >
                                This Invoice has BALANCE pending for a SUM of : <?php echo CURRENCY_CODE;?>. <?php echo number_format($invoice[0]['balance']);?>
                                <a class="btn btn-danger waves-effect waves-light m-b-5 btn-sm"  href="<?php echo base_url().'open_recovery_invoice/'.$invoice[0]['id_invoice'].'/'.$invoice[0]['visit_id']; ?>">Create Recovery Invoices?</a>
                            </h3>
                        </div>
                    </div>
                </div>
                <?php } ?>
                
               <?php if($invoice[0]['remarks'] !==''){?>
               <div class="row hidden-print" >
                    <div class="col-sm-12" >
                        <div class="alert alert-warning">
                            <h3 >
                                <?php echo $invoice[0]['remarks'];?>
                            </h3>
                        </div>
                    </div>
                </div>     
                    
               <?php } ?>
                
                <?php if($invoice[0]['invoice_status'] !=='valid'){?>
               <div class="row hidden-print" >
                    <div class="col-sm-12" >
                        <div class="alert alert-warning">
                            <h3 >
                                <?php echo $invoice[0]['cancelreason'];?>
                            </h3>
                        </div>
                    </div>
                </div>     
                    
               <?php } ?>
                <div class="row hidden-print">
                    <div class="col-md-12">
                        <div class="btn-group pull-right m-t-15 m-b-10" >
                            <form style="display:inline-block" target="_blank" method="Post" action="<?php echo base_url();?>pos_view">
                                <input type="hidden" name="customerid" value="<?php echo $invoice[0]['customer_id']; ?>">
                                <button type="submit" class="btn btn-warning waves-effect waves-light" >Retail <span class="m-l-5"><i class="ti ti-spray"></i></span></button>
                            </form>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-12">
                        <div class="panel panel-default">
                            <div class="panel-body" style="padding:10px !important;">
                                <div class="row">
                                    <div class="col-sm-12 col-md-6 pull-left">
                                        <div ><?php if(isset($business)){ echo "<img width='180px' src='".base_url().'assets/images/business/'.$business[0]['business_logo']."' alt='".$business[0]['business_name']."' class='img-responsive' />";} else {echo 'SkedWise';}?>
                                            <span ><?php if(isset($business)){ echo $business[0]['business_address'];} ?></span>
                                            <span ><?php if(isset($business)){ echo $business[0]['business_phone1'];} ?></span>
                                        </div>
                                    </div>
                                    <div class="<?php if(isset($business[0]['invoicenumber'])){if($business[0]['invoicenumber']=='No'){echo "hidden-sm hidden-xs";}} ?> pull-right" style="">
                                        <h4 >Invoice # <br>
                                            <strong id="invoicenumber"><?php echo $invoice[0]['invoice_number'];?></strong>
                                            <?php if(isset($invoice[0]['imsfiscal_invoice_number'])){ if($invoice[0]['imsfiscal_invoice_number']!==null && $invoice[0]['imsfiscal_invoice_number']!==''){?>
                                            <br><?php echo $invoice[0]['imsfiscal_invoice_number'];?>
                                            <?php } }?>
                                            <?php if($invoice[0]['reference_invoice_number']!==""){?>
                                            <br><?php $reference = explode('-',$invoice[0]['reference_invoice_number']);?>
                                            <a href="<?php if($invoice[0]['invoice_type']=='service'){echo base_url().'existinginvoice/'.$reference[2];}else {echo base_url().'existingorderinvoice/'.$invoice[0]['reference_invoice_number'];} ?>" target="_blank" ><strong id="invoicereference"><?php echo $invoice[0]['reference_invoice_number']; ?></strong></a>
                                            <?php } ?>
                                            <?php if($invoice[0]['invoice_status'] !=='valid'){?>
                                            <br><h1 class="text-danger">CANCELLED</h1>
                                            <?php } ?>
                                        </h4>
                                        
                                    </div>
                                   <div class="pull-right <?php if(isset($business[0]['invoicenumber'])){if($business[0]['invoicenumber']=='No'){echo "hidden-sm hidden-xs";}} ?>">
                                        <span class="">Visit #:
                                            <?php if(isset($invoice[0]['visit_id'])){ echo sprintf("%04s", $invoice[0]['visit_id']);}else{echo '00001';} ?>
                                        </span>
                                       
                                    </div>
                                </div>
                                
                                <div class="row" style="color:#000 !important">
                                    <div class="col-md-12">
                                        
                                        <div class="pull-left m-t-10 " >
                                            <?php if($invoice[0]['invoice_seq']>0){?>
                                            <label>Receipt #: <?php echo $invoice[0]['invoice_seq']; ?></label>    
                                            <?php } ?>
                                            <input name="customerid" id="customerid" type="hidden" value="<?php echo $invoice[0]['customer_id']; ?>"/>
                                            <input name="txtinvoiceid" id="txtinvoiceid" type="hidden" value="<?php echo $invoice[0]['id_invoice']; ?>"/>
                                            <address>
                                              <strong><?php echo $invoice[0]['customer_name']; ?> <?php echo $invoice[0]['invoice_extra']; ?></strong><br>
                                              <span ><abbr class="hidden-sm hidden-xs" title="Phone">P:</abbr> <?php 
                                                    if( $this->session->userdata('hide_cell') && $this->session->userdata('hide_cell') == "No"){ 
                                                        echo $invoice[0]['customer_cell']; 
                                                    } 
                                              ?></span><br>
                                              <span class="hidden-sm hidden-xs"><?php echo $invoice[0]['customer_address']; ?></span><br>
                                              <span class="hidden-sm hidden-xs"><?php echo $invoice[0]['customer_email']; ?></span>
                                              <?php if($invoice[0]['discount_remarks']!==""){?><br><span class=""><?php echo $invoice[0]['discount_remarks']; ?></span><?php } ?>
                                            </address>
                                        </div>
                                        <div class="pull-right m-t-10">
                                            <p><strong><?php if($invoice[0]['reference_invoice_number']!==""){?>Recovery:<?php }else{?>Invoice Date:<?php } ?> </strong> <?php echo $invoice[0]['invoice_date']; ?></p>
                                            <p class="m-t-0"><strong>Time:</strong> <?php echo $invoice[0]['invoice_time']; ?></p>
                                            <p class="m-t-0" id="modep"><strong>Payment: </strong> <span id="mode"><?php echo $invoice[0]['payment_mode']; ?></span></p>
                                            <p style="<?php if($invoice[0]['instrument_number']==''){ echo "display:none;";}else{} ?>" class="m-t-0" id="instrument"><strong>Instrument#: </strong> <span id="mode"><?php echo $invoice[0]['instrument_number']; ?></span></p>
                                            <p class="m-t-0"><strong>Agent:</strong><span> <?php echo $invoice[0]['created_by']; ?></span></p>
                                        </div>
                                    </div><!-- end col -->
                                </div>
                                <!-- end row -->
                                <div class="row" style="color:#000 !important">
                                    <div class="col-md-12">
                                        <div class="">
                                            <table class="table " id="tblservices" style="color:#000 !important">
                                                <thead style="color:#000 !important">
                                                    <tr ><th>#</th>
                                                    <th>Item</th>
                                                    <th>Description</th>                                                    
                                                    <th <?php if(isset($business[0]['invoice_staff'])){if($business[0]['invoice_staff']==='Y'){}else{echo 'class="hidden-sm hidden-xs"';}} ?> >Staff</th>
                                                    <th class="hidden_md hidden-sm hidden-xs">Requested(staff)</th>
                                                    <th class="hidden_md hidden-sm hidden-xs">Products</th>
                                                    <th class="hidden_md hidden-sm hidden-xs">Addition</th>
                                                    <th >Discount</th>
                                                    <th style="text-align: right;">Total</th>
                                                    
                                                </tr>
                                                </thead>
                                                <tbody style="color:#000 !important">
                                                    <?php $x=1; if(isset($invoicedetails)){
                                                        foreach($invoicedetails as $invoicedetail){?>
                                                        <tr>
                                                            <td><?php echo $x;?></td>
                                                            <td><?php echo $invoicedetail['service_category']; ?></td>
                                                            <td><?php echo $invoicedetail['service_name']; ?></td>
                                                            
                                                            <td <?php if(isset($business[0]['invoice_staff'])){if($business[0]['invoice_staff']!=='Y') {echo 'class="hidden-sm hidden-xs"';} } ?> >
                                                                    <?php foreach($invoicestaff as $invs){
                                                                       if($invs['invoice_detail_id']==$invoicedetail['id_invoice_details']) {
                                                                           echo $invs['staff_name'].'<br>';
                                                                       }
                                                                    }?>
                                                            </td>
                                                            <td class="hidden_md hidden-sm hidden-xs"><?php foreach($invoicestaff as $invs){
                                                                       if($invs['invoice_detail_id']==$invoicedetail['id_invoice_details']) {
                                                                           echo $invs['requested'].'<br>';
                                                                       }
                                                                    }?></td>
                                                            <td class="hidden_md hidden-sm hidden-xs"><?php if(null !=$invoicedetail['products']){ echo str_replace('|','<br> ',$invoicedetail['products']); } ?></td>
                                                            <td class="hidden_md hidden-sm hidden-xs"><?php echo number_format($invoicedetail['service_addition'],2); ?></td>
                                                            <td> <?php echo number_format($invoicedetail['discount'],2); ?></td>
                                                             <?php if(isset($invoicedetail['service_flag'])){?>
                                                                <?php if($invoicedetail['service_flag']=='servicetype' && $invoicedetail['membership']=='No'){?>
                                                                <td style="text-align: right;"><span class="hidden-print"><?php echo CURRENCY_CODE;?>.</span><span><?php echo  number_format(($invoicedetail['price']+ $invoicedetail['service_addition']) - $invoicedetail['discount'],2); ?></span></td>
                                                                <?php } else if($invoicedetail['service_flag']=='servicetype' && $invoicedetail['membership']=='Yes'){?>
                                                                <td >Membership</td>
                                                                <?php } else { ?><td>Deal</td><?php }?>
                                                             <?php } else {?>
                                                                <td style="text-align: right;"><span class="hidden-print"><?php echo CURRENCY_CODE;?>.</span><span><?php echo number_format(($invoicedetail['price']+ $invoicedetail['service_addition']) - $invoicedetail['discount'],2);  //$invoicedetail['price']-$invoicedetail['discount']; ?></span></td>
                                                             <?php }?>
                                                        </tr>
                                                        <?php $x++;}} ?>

                                                </tbody>
                                            </table>
                                        </div>
                                    </div>
                                </div>
                                <div class="row" style="color:#000 !important">
                                    <div class="col-md-6 col-lg-6 hidden-sm hidden-xs">
<!--                                    <div class="clearfix m-t-40">
                                            <h5 class="small text-inverse font-600">PAYMENT TERMS AND POLICIES</h5>
                                            <small>
                                                <?php //echo $business[0]['payment_terms'];?>
                                            </small>
                                        </div>-->
                                    </div>
                                    <div class="col-md-3 col-sm-12 col-xs-12 col-md-offset-3" style="color:#000 !important">
                                        <p class="text-right m-t-0"><b><?php if(isset($taxes)&& sizeof($taxes)>=1){?>Value Exclusive of <?php echo $taxes[0]['invoice_tax_name'].' ';} ?>:  <?php echo CURRENCY_CODE;?>. <?php echo number_format($invoice[0]['sub_total'],2);?></b> </p>
                                        <p class="text-right m-t-0">Discount:   <?php echo CURRENCY_CODE;?>. <?php echo number_format($invoice[0]['discount'],2);?></p>
                                        <p class="text-right m-t-0">Other Charges:   <?php echo CURRENCY_CODE;?>. <?php echo number_format($invoice[0]['other_charges'],2);?></p>
                                        <p class="text-right m-t-0">Gross Total:   <?php echo CURRENCY_CODE;?>. <?php if($invoice[0]['gross_wo_tax'] == null){echo '0.00';}else{ echo number_format($invoice[0]['gross_wo_tax'],2);}?></p>
                                        
                                        <div class="m-t-10 m-b-5" id="divtaxes" style="display: <?php echo count($taxes) > 0 ? 'block' : 'block'; ?>;">
                                        <?php if(isset($taxes) && sizeof($taxes)>1){$x=0;foreach ($taxes as $tax) {?>
                                            <p class="text-right m-t-0 m-b-5"><span><?php echo $tax['invoice_tax_name'].' '; ?></span> :  <?php echo CURRENCY_CODE;?>. <?php echo number_format($tax['invoice_tax'],2);?></p>
                                        <?php $x++;}} else { ?>                                        
                                            <p class="text-right m-t-0 m-b-5"><span><?php if(isset($taxes)&& sizeof($taxes)>=1){?>Amount of <?php echo $taxes[0]['invoice_tax_name'].' '; }?></span> :  <?php echo CURRENCY_CODE;?>. <?php echo number_format($invoice[0]['tax_total'],2);?></p>
                                        <?php } ?>
                                        </div>                                       
                                        
                                        <p class="text-right m-t-0"><?php if(isset($taxes)&& sizeof($taxes)>=1){?><strong>Value Inclusive of</strong> <?php echo $taxes[0]['invoice_tax_name'].' '; } ?> <b><?php echo CURRENCY_CODE;?>. <?php echo number_format($invoice[0]['total_payable'],2); //$invoice[0]['net_amount']+$invoice[0]['advance_amount']; ?></b></p>
                                        <hr>                                    
                                        <?php if((Float)$invoice[0]['cctip']>0){?><p class="text-right m-t-0">Tip Charged on <?php echo $invoice[0]['payment_mode']; ?>:   <?php echo CURRENCY_CODE;?>. <?php echo number_format($invoice[0]['cctip'],2);?></p><?php } ?>
                                        <?php if((Float)$invoice[0]['cc_charge']>0){?><p class="text-right m-t-0">Card Fee:   <?php echo CURRENCY_CODE;?>. <?php echo number_format($invoice[0]['cc_charge'],2);?></p><?php } ?>
                                        <p class="text-right m-t-0"><strong>Total Payable: </strong><b><?php echo CURRENCY_CODE;?>. <?php echo number_format($invoice[0]['total_payable']+$invoice[0]['cc_charge']+$invoice[0]['cctip'],2); //$invoice[0]['net_amount']+$invoice[0]['advance_amount']; ?></b></p>
                                        <hr>
                                        <?php if($invoice[0]['reference_invoice_number']!==''){?>
                                        <p class="text-right m-t-0">  <b>Recovered <input class="numeric" style="text-align: right; width: 95px; border: none;" id="recovered" readonly  name="recovered" value="<?php echo number_format($invoice[0]['paid_earlier'],2); ?>"/></b></p>
                                        <p class="text-right m-t-0">  <b>Recoverable <input class="numeric" style="text-align: right; width: 95px; border: none;" id="recoverable" readonly  name="recoverable" value="<?php echo number_format($invoice[0]['paid_amount'] + $invoice[0]['balance'],2); ?>"/></b></p>
                                        <?php } ?>
                                        <p class="text-right m-t-0" <?php if($invoice[0]['invoice_status'] !=='valid'){?> style="text-decoration: line-through;"<?php }?>>  <b>Paid <?php echo CURRENCY_CODE;?>. <input class="numeric" style="text-align: right; width: 95px; border: none; <?php if($invoice[0]['invoice_status'] !=='valid'){?> text-decoration: line-through;<?php }?>" id="paid" readonly  name="paid" value="<?php echo $invoice[0]['paid_amount'] >0 ? number_format($invoice[0]['paid_amount'] + $invoice[0]['returnamount'],2) : 0; ?>"/></b></p>
                                        <?php if($invoice[0]['payment_mode']=="Mixed"){?>
                                        <p class="text-right m-t-0">  <b>Cash <?php echo CURRENCY_CODE;?>. <input class="numeric" style="text-align: right; width: 95px; border: none;" id="paidcash" readonly  name="paidcash" value="<?php echo number_format($invoice[0]['paid_cash'],2); ?>"/></b></p>
                                        <p class="text-right m-t-0">  <b>Card <?php echo CURRENCY_CODE;?>. <input class="numeric" style="text-align: right; width: 95px; border: none;" id="paidcard" readonly  name="paidcard" value="<?php echo number_format($invoice[0]['paid_card'],2); ?>"/></b></p>
                                        <?php } ?>
                                        <p class="text-right m-t-0">  Advance Payment <input class="numeric" style="text-align: right; width: 95px; border: none;" readonly="readonly" id="advance_amount"  name="advance_amount" value="<?php echo number_format($invoice[0]['advance_amount'],2); ?>"/></p>
                                        
                                        <?php  if($invoice[0]['retained_amount'] > 0) {?>
                                        <p class="text-right m-t-0"> Retained <?php echo CURRENCY_CODE;?>. <input class="numeric" style="text-align: right; width: 95px; border: none;" readonly="readonly"  name="retainamount" value="<?php echo number_format($invoice[0]['retained_amount'],2); ?>"></p>
                                        <?php } else { ?>
                                        <p class="text-right m-t-0"> Return <?php echo CURRENCY_CODE;?>. <input class="numeric" style="text-align: right; width: 95px; border: none;" readonly="readonly"  name="returnamount" value="<?php echo number_format($invoice[0]['returnamount'],2); ?>"></p>
                                        <?php } ?>
                                        <p class="text-right m-t-0">  Balance <?php echo CURRENCY_CODE;?>. <input class="numeric" style="text-align: right; width: 95px; border: none;" readonly="readonly" id="balanceamount"  name="balanceamount" value="<?php echo number_format($invoice[0]['balance'],2); ?>"/></p>
                                        
                                    </div>
                                    <div style="font-size:14px; text-align: center">
                                        <?php if(isset($business[0]['fineprint']) && $business[0]['fineprint'] == 'Yes'){?>
                                        <p><strong style="color:#000">THANK YOU FOR YOUR VISIT</strong></p>
                                        <?php } ?>
                                    </div>
                                    <?php if(isset($business[0]['invoice_terms'])){ if ($business[0]['invoice_terms']=='Yes'){?>
                                    <div class="col-md-12 clearfix m-t-10" style="font-size:12px; text-align: left">                                         
                                        <?php echo $business[0]['payment_terms'];?>
                                    </div>
                                    <?php }} ?>
                                    
                                    <?php if(isset($invoice[0]['imsfiscal_invoice_number'])){ if($invoice[0]['imsfiscal_invoice_number']!==null && $invoice[0]['imsfiscal_invoice_number']!==''){?>
                                    <div class="col-md-12 clearfix m-t-10" >
                                       
                                        <div class="row">
                                            <div id="qrcode" class="col-lg-4 col-md-4 col-sm-6 col-xs-12 qrcode">                              
                                           
                                            </div>
                                        </div>
                                        <div class="row">
                                            <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
                                                <?php echo $invoice[0]['imsfiscal_invoice_number'];?>
                                            </div>
                                        </div>
                                        <div class="row">
                                            <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
                                                <span class="text-sm"></span>
                                            </div>
                                        </div>
                                    </div>
                                    <?php } }?>
                                    
                                </div>                                
                                <hr>
                                
                                <div class="hidden-print">

                                    <div class="pull-right">
                                        <button onclick="window.print();" class="btn btn-inverse waves-effect waves-light" id="btnprint" ><i class="fa fa-print"></i></button>
                                    </div>
                                     <div class="pull-right">
                                        <a onclick="sendEmail(<?php echo $invoice[0]['customer_id']; ?>);" data-toggle="tooltip" data-placement="top" data-original-title="Email this" href="javascript:void(0);" class="btn btn-default waves-effect waves-light" id="btnprint"><i class="fa fa-envelope"></i></a>
                                    </div>                                   
                                </div>
                            </div>
                        </div>

                    </div>

                </div>
                <!-- end row -->
                
                <div class="modal fade none-border" id="eventview" tabindex="-1" role="dialog" aria-labelledby="Event View" aria-hidden="true">
                    <div class="modal-dialog">
                        <div class="modal-content">
                            <div class="modal-header">
                                <button type="button" class="close" onclick="$('#eventview').modal('hide');" aria-hidden="true">×</button>
                                <h4 class="modal-title">Send Email</h4>
                            </div>
                            <div class="modal-body">
                                <label class="" for="email">Customer Email</label>
                                <input class="form-control" type="email" id="email" placeholder="Enter Customer Email e.g. example@abc.com">
                                
                                <div class="pull-right">
                                    <label for="default" style="margin-top: 10px;">
                                        <input type="checkbox" id="default" checked="checked"> Default
                                    </label>
                                </div>
                                <div class="clearfix"></div>
                                
                                <hr>
                                
                                <div class="pull-right">
                                    <button onclick="sendEmailDo(<?php echo $invoice[0]['customer_id']; ?>);" class="btn btn-sm btn-primary">Send <i class="fa fa-send"></i></button>
                                </div>
                                
                                <div class="clearfix"></div>
                            </div>
                        </div><!-- /.modal-content -->
                    </div><!-- /.modal-dialog -->
                </div>
                
                <script src="<?php echo base_url();?>assets/plugins/qrcode/qrcode.js"></script>
    
                <script type="text/javascript">
                    $(document).ready(function(){

                        var qrcode = new QRCode("qrcode", {
                        text: "<?php echo "https://e.pra.punjab.gov.pk/IMSFiscalReport/SearchPOSInvoice_Report.aspx?PRAInvNo=".$invoice[0]['imsfiscal_invoice_number'];?>",
                        width: 150,
                        height: 150,
                        colorDark : "#000000",
                        colorLight : "#ffffff",
                        correctLevel : QRCode.CorrectLevel.H
                        });


                        //new QRCode(document.getElementById("qrcode"), qrcode);
                    });
                    
                </script>
                                    

                <script>
                    function sendEmailDo(id){
                        var email = $('#email').val();
                        var invoiceid = $('#txtinvoiceid').val();
                        var senddefault = $('#default:checkbox:checked').val() === 'on' ? 'yes' : 'no';
                        
                        if(email === ""){
                            swal({
                                title: "Empty field found!",
                                text: "Email should not be empty.",
                                type: "error",
                                confirmButtonText: 'OK!'
                            });
                            return false;
                        }
                        $.ajax({
                            url: '<?php echo base_url().'Customer_controller/sendEmailDo'; ?>',
                            type: 'POST',
                            data: {
                                customerid : id,
                                email : email,
                                invoiceid : invoiceid,
                                senddefault : senddefault 
                            },
                            success: function(result){
                                $('#eventview').modal('hide');
                                toastr.success('Email sent!', 'Done!');
                            }
                        });
                    }
                    
                    function sendEmail(id){
                        $.ajax({
                            url: '<?php echo base_url().'Customer_controller/sendEmail'; ?>',
                            type: 'POST',
                            data: { customerid : id },
                            success: function(result){
                                
                                if(result === "empty"){
                                    $('#email').val('');
                                    $('#empty').val('yes');
                                } else{
                                    $('#email').val(result);
                                    $('#empty').val('no');
                                }
                                
                                $('#eventview').modal({
                                    backdrop:'static',
                                    keyboard:false,
                                    show:true
                                });
                                
                            }
                        });
                    }
                </script>