<style>
    body{font-family: sans-serif;}
</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_order_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">
                    <div class="col-md-12">
                        <div class="panel panel-default">
                            <!-- <div class="panel-heading">
                                <h4>Invoice</h4>
                            </div> -->
                            <div class="panel-body">
                                <div class="row">
                                    <div class="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 'SalonPK';}?>
                                            <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="pull-right">
                                        <h4>Invoice # <br>
                                            <strong id="invoicenumber"><?php echo $invoice[0]['invoice_number'];?></strong>
                                            <?php if($invoice[0]['invoice_status'] !=='valid'){?>
                                            <br><h1 class="text-danger">CANCELLED</h1>
                                            <?php } ?>
                                        </h4>
                                    </div>
                                </div>
                                <div class="row" style="color:#000 !important" >
                                    <div class="col-md-12">
                                        <div class="pull-left m-t-10 ">
                                            <input name="customerid" id="customerid" type="hidden" value="<?php echo $invoice[0]['customer_id']; ?>"/>
                                            <input name="txtinvoiceid" id="customerid" 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 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><br>
                                              <abbr title="Phone">P:</abbr> <?php 
                                                    if( $this->session->userdata('hide_cell') && $this->session->userdata('hide_cell') == "No"){ 
                                                        echo $invoice[0]['customer_cell']; 
                                                    } 
                                                    ?><br>
                                                    
                                              </address>
                                            
                                        </div>
                                        <div class="pull-right m-t-10">
                                            <p class="m-t-0"><strong>Invoice Date: </strong> <?php echo $invoice[0]['invoice_date']; ?></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">Agent: <?php echo $invoice[0]['created_by']; ?></p>
                                        </div>
                                    </div><!-- end col -->
                                </div>
                                <!-- end row -->
                                <div class="row">
                                    <div class="col-md-12">
                                        <div class="table">
                                            <table class="table m-t-5" id="tblservices">
                                                <thead style="color:#000 !important">
                                                    <th class="hidden-sm hidden-xs">#</th>
                                                    <th class="hidden-sm hidden-xs">Brand</th>
                                                    <th>Item</th>
                                                    <th class="hidden-sm hidden-xs">Batch</th>
                                                    <th class="hidden-sm hidden-xs">Sold by</th>
                                                    <th>Qty.</th>
                                                    <th>Unit </th>       
                                                    
                                                    <th>Disc. </th>
                                                    <th>Total </th>
                                                    <th class="hidden-sm hidden-xs">Tax </th>                                                    
                                                    <th class="hidden-sm hidden-xs">Price</th>
                                                </tr>
                                            </thead>
                                                <tbody style="color:#000 !important">
                                                    <?php $exclusive_tax=0; $x=1; if(isset($invoiceproducts)){
                                                        foreach($invoiceproducts as $invoiceproduct){?>
                                                        <tr>
                                                            <td class="hidden-sm hidden-xs"><?php echo $x;?></td>
                                                            <td class="hidden-sm hidden-xs"><?php echo $invoiceproduct['brand_name']; ?></td>
                                                            <td><?php echo $invoiceproduct['product_name']. ' '.$invoiceproduct['category']; ?></td>
                                                            <td class="hidden-sm hidden-xs"><?php echo $invoiceproduct['batch']; ?></td>
                                                            <td class="hidden-sm hidden-xs"><?php echo $invoiceproduct['staff_name']; ?></td>
                                                            <td><?php echo $invoiceproduct['invoice_qty']; ?></td>
                                                            <td><?php echo $invoiceproduct['price'] + $invoiceproduct['service_addition']/$invoiceproduct['invoice_qty']; ?></td>
                                                            
                                                            <td><?php echo $invoiceproduct['discount']; ?></td>  
                                                            <td><?php echo $invoiceproduct['discounted_price']; $exclusive_tax += $invoiceproduct['discounted_price'];  ?></td>  
                                                            <td class="hidden-sm hidden-xs"><?php echo $invoiceproduct['taxes']; ?></td>  
                                                            <td class="hidden-sm hidden-xs"><span id="unitcost"><?php echo $invoiceproduct['final_price']; ?></span></td>
                                                           
                                                        </tr>
                                                        <?php $x++;}} ?>

                                                </tbody>
                                            </table>
                                        </div>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-md-6 col-lg-6 hidden-sm hidden-xs" style="color:#000 !important">
<!--                                        <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-6 col-lg-6 col-sm-12 col-xs-12 col-md-offset-6" style="color:#000 !important">
                                        <p class="text-right m-t-0"><b><?php //if(isset($taxes)&& sizeof($taxes)>=1){?>Value Exclusive of Tax<?php //echo $taxes[0]['invoice_tax_name'].' ';} ?>:   <?php echo CURRENCY_CODE;?>. <?php echo $exclusive_tax;?></b></p>
                                        <div class="m-t-5 " id="divtaxes" style="display: <?php echo count($taxes) > 0 ? 'block' : 'none'; ?>;">
                                        <?php $totaltax=0; if(isset($taxes)){$x=0;foreach ($taxes as $tax) {?>
                                            <p class="text-right m-t-0 m-b-5"><?php if(isset($taxes)&& sizeof($taxes)>=1){?>Amount of <?php } ?><span><?php echo $tax['invoice_tax_name'].' '; ?></span> :  <?php echo CURRENCY_CODE;?>. <?php echo $tax['invoice_tax']; $totaltax+=$tax['invoice_tax'];?></p>
                                        <?php $x++;}}?>
                                        </div>
                                        <p class="text-right m-t-0"><strong>Value Inclusive of Tax:</strong> <b><?php echo CURRENCY_CODE;?>. <?php echo $exclusive_tax + $totaltax; ?></b></p>
                                        
                                        <?php if((Float)$invoice[0]['discount']>0){?><p class="text-right m-t-0">Discount:   <?php echo CURRENCY_CODE;?>. <?php echo $invoice[0]['discount'];?></p><?php } ?>
                                        <!--<p class="text-right m-t-0">Other Charges:   <?php //echo CURRENCY_CODE;?>. <?php //echo $invoice[0]['other_charges'];?></p>-->
                                        <?php if((Float)$invoice[0]['cctip']>0){?><p class="text-right m-t-0">Tip Charged on Card:   <?php echo CURRENCY_CODE;?>. <?php echo $invoice[0]['cctip'];?></p><?php } ?>
                                        
                                        <?php if($invoice[0]['cc_charge']>0){?>
                                            <p class="text-right m-t-0 m-b-5"><span>CC Fee:</span> <?php echo CURRENCY_CODE;?>. <?php echo $invoice[0]['cc_charge'];?></p>
                                        <?php } ?>
                                        <p class="text-right m-t-0"><strong>Total Payable Amount: </strong><b><?php echo CURRENCY_CODE;?>. <?php echo $invoice[0]['total_payable']; ?></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 $invoice[0]['paid_earlier']; ?>"/></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 ($invoice[0]['paid_amount'] + $invoice[0]['balance']); ?>"/></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 ? ($invoice[0]['paid_amount'] + $invoice[0]['returnamount']) : 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 ($invoice[0]['paid_cash']); ?>"/></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 ($invoice[0]['paid_card']); ?>"/></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 $invoice[0]['advance_amount']; ?>"/></p>
                                        <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 $invoice[0]['returnamount']; ?>"></p>
                                        <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 $invoice[0]['balance'];?>"/></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 }} ?>
                                </div>
                                <hr>
                                <div class="hidden-print">
                                    <div class="pull-right">
                                    <button onclick="element = document.getElementById('printwrapper'); element.scrollIntoView(); 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>
                    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>