<style>
    body{font-family: sans-serif;}
</style>

<div class="wrapper" style="color:#000 !important">
            <div class="container">
                <!-- Page-Title -->
                
               <?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'] =='Cancelled'){?>
               <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-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(isset($invoice[0]['reference_invoice_number'])){if($invoice[0]['reference_invoice_number']!==""){?>
                                            <br><?php $reference = explode('-',$invoice[0]['reference_invoice_number']);?>                                            
                                            <?php } }?>
                                            <?php if($invoice[0]['invoice_status'] =='Cancelled'){?>
                                            <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="">Invoice Number #:
                                            <?php if(isset($invoice[0]['invoice_number'])){ echo sprintf("%04s", $invoice[0]['invoice_number']);}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 " >
                                            <label>Receipt #: <?php echo $invoice[0]['id_program_invoices']; ?></label>    
                                            <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_program_invoices']; ?>"/>
                                            <address>
                                              <strong><?php echo $invoice[0]['customer_name']; ?></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>
                                              
                                            </address>
                                        </div>
                                        <div class="pull-right m-t-10">                                            
                                            <p class="m-t-0" id="modep"><strong>Payment: </strong> <span id="mode"><?php echo $invoice[0]['payment_mode']; ?></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>Service ID</th>
                                                        <th>Description</th>                                                    
                                                        <th>Number of Sessions </th>                                                        
                                                        <th >Session Rate</th>
                                                        <th>Total</th>
                                                    
                                                </tr>
                                                </thead>
                                                <tbody style="color:#000 !important">
                                                    <?php $x=1; if(isset($invoice)){
                                                        foreach($invoice as $invoicedetail){?>
                                                        <tr>
                                                            <td><?php echo $x;?></td>
                                                            <td><?php echo $invoicedetail['service_id']; ?></td>
                                                            <td><?php echo $invoicedetail['service_name']; ?></td>
                                                            <td><?php echo $invoicedetail['number_of_sessions']; ?></td>    
                                                            <td><?php echo $invoicedetail['per_session']; ?></td>    
                                                            <td><?php echo $invoicedetail['per_session']*$invoicedetail['number_of_sessions']; ?></td>    
                                                        </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 $invoice[0]['invoiced_amount'];?></b> </p>
                                        <p class="text-right m-t-0">Discount:   <?php echo CURRENCY_CODE;?>. <?php echo $invoice[0]['invoice_discount'];?></p>
                                        <p class="text-right m-t-0">Other Charges:   <?php echo CURRENCY_CODE;?>. <?php echo $invoice[0]['invoice_other_charges'];?></p>                                        
                                        <?php if((Float)$invoice[0]['cc_charge']>0){?><p class="text-right m-t-0">Card Fee:   <?php echo CURRENCY_CODE;?>. <?php echo $invoice[0]['cc_charge'];?></p><?php } ?>
                                        <p class="text-right m-t-0">Gross Total:   <?php echo CURRENCY_CODE;?>. <?php $grosstotal = $invoice[0]['invoiced_amount']+$invoice[0]['invoice_other_charges']+$invoice[0]['cc_charge']; echo $grosstotal;?></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 $tax['invoice_tax'];?></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 $invoice[0]['salestax'];?></p>
                                        <?php } ?>
                                        </div>
                                        <?php if($invoice[0]['cc_charge']>0){?>
                                            <p class="text-right m-t-0"><span>CC Fee:</span> :  <?php echo CURRENCY_CODE;?>. <?php echo $invoice[0]['cc_charge'];?></p>
                                        <?php } ?>
                                            <p class="text-right m-t-0">Rounding Adjustment: <?php echo $invoice[0]['rounding_adjustment'];?></p>
                                        <hr>
                                        <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 $grosswithtax=$grosstotal+$invoice[0]['salestax']+$invoice[0]['rounding_adjustment']; echo $grosswithtax;?></b></p>
                                        
                                        <p class="text-right m-t-0" <?php if($invoice[0]['invoice_status'] =='Cancelled'){?> 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'] =='Cancelled'){?> text-decoration: line-through;<?php }?>" id="paid" readonly  name="paid" value="<?php echo $invoice[0]['paid_amount'] >0 ? ($invoice[0]['paid_amount'] + $invoice[0]['return_amount']) : 0; ?>"/></b></p>
                                        <p class="text-right m-t-0" <?php if($invoice[0]['invoice_status'] =='Cancelled'){?> style="text-decoration: line-through;"<?php }?>>  <b>Returned <?php echo CURRENCY_CODE;?>. <input class="numeric" style="text-align: right; width: 95px; border: none; <?php if($invoice[0]['invoice_status'] =='Cancelled'){?> text-decoration: line-through;<?php }?>" id="return" readonly  name="return" value="<?php echo $invoice[0]['return_amount']; ?>"/></b></p>
                                        <hr>
                                        <p class="text-right m-t-0">  Advance <?php echo CURRENCY_CODE;?>. <input class="numeric" style="text-align: right; width: 95px; border: none;" id="advance_used" readonly  name="advance_used" value="<?php echo ($invoice[0]['advance_used']); ?>"/></p>
                                        <p class="text-right m-t-0">  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']); ?>"/></p>
                                        <p class="text-right m-t-0">  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']); ?>"/></p>
                                        <p class="text-right m-t-0">  Bank (online) <?php echo CURRENCY_CODE;?>. <input class="numeric" style="text-align: right; width: 95px; border: none;" id="paidcheck" readonly  name="paidcard" value="<?php echo ($invoice[0]['paid_check']); ?>"/></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 $balance =$grosswithtax-$invoice[0]['paid_amount']; echo $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">
                                        <a href="javascript:window.print()" class="btn btn-inverse waves-effect waves-light" id="btnprint" ><i class="fa fa-print"></i></a>
                                    </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>