<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Libre+Barcode+128+Text&display=swap" rel="stylesheet">

<style>
  
    .mouse-cursor{
        
    }
</style>  
<div class="wrapper">
            <div class="container" style="color:#000 !important">
                <!-- Page-Title -->
                <div class="row hidden-print">
                    <div class="col-sm-12">
                        <div class="btn-group pull-right m-t-15">
                            
                            <button style="display:none;" id="btncolor" onclick="opencolor();" type="button" class ="btn btn-pink waves-effect waves-light">Color</button>
                            <button style="display:none;" id="btneyelash" onclick="openeyelash();" type="button" class ="btn btn-pink waves-effect waves-light">EyeLash</button>
                            <button style="display:none;" id="btnfacial" onclick="openfacial();" type="button" class ="btn btn-pink waves-effect waves-light m-r-5">Facial</button><!-- comment -->
                            
                            <form style="display:inline-block" target="_blank" method="Post" action="<?php echo base_url();?>pos_view">
                                <input type="hidden" name="customerid" value="<?php echo $visit[0]['id_customers']; ?>">
                                <button type="submit" class="m-r-15 btn btn-warning waves-effect waves-light" >Retail <span class="m-l-5"><i class="ti ti-spray"></i></span></button>
                            </form>
                            <button style="display: inline-block" type="button" class="btn btn-custom dropdown-toggle waves-effect waves-light" data-toggle="dropdown" aria-expanded="false">Taxes <span class="m-l-5"><i class="fa fa-cog"></i></span></button>
                            <ul class="dropdown-menu" role="menu">
                                <?php if(isset($business[0]['imsfiscal'])){                                    
                                    if($business[0]['imsfiscal']=='Yes'){                                         
                                        if($this->session->userdata('role')=="Admin" || $this->session->userdata('role')=="Super User"){?>
                                            <li><a href="javascript:void(0);" onclick="enabletaxes('yes');">Enable Taxes</a></li>
                                            <li><a href="javascript:void(0);" onclick="enabletaxes('no');">Disable Taxes</a></li>
                                    <?php } else { ?>
                                        <li>This function is disabled by your Admin</li>
                                    <?php } ?>
                                <?php } else { ?>
                                    <li><a href="javascript:void(0);" onclick="enabletaxes('yes');">Enable Taxes</a></li>
                                    <li><a href="javascript:void(0);" onclick="enabletaxes('no');">Disable Taxes</a></li>
                                
                                <?php }} else { ?>
                                    <li><a href="javascript:void(0);" onclick="enabletaxes('yes');">Enable Taxes</a></li>
                                    <li><a href="javascript:void(0);" onclick="enabletaxes('no');">Disable Taxes</a></li>
                                <?php } ?>`
                            </ul>
                            
                            
                        </div>
                        
                        <h4 class="page-title">Invoice </h4>
                    </div>
                    <?php if(isset($balance)){ if(sizeof($balance)>0 ){?>
                    <div class="row hidden-print" >
                        <div class="col-sm-12" >
                            <div class="alert alert-danger">
                                <h3 >
                                    There are BALANCES pending for <?php echo $visit[0]['customer_name'];?> : 
                                    <?php  foreach($balance as $b){ ?>
                                        <?php  if($b['invoice_type']=="service"){ ?>
                                            <a class="btn btn-danger waves-effect waves-light m-l-5 m-b-5 btn-sm"  href="<?php echo base_url().'open_recovery_invoice/'.$b['id_invoice'].'/'.$b['visit_id']; ?>"><?php echo CURRENCY_CODE;?>. <?php echo number_format($b['totalbalance']);?></a>
                                        <?php } else {?>
                                            <a class="btn btn-danger waves-effect waves-light m-l-5 m-b-5 btn-sm"  href="<?php echo base_url().'open_recovery_order_invoice/'.$b['id_invoice'].'/'.$b['visit_id']; ?>"><?php echo CURRENCY_CODE;?>. <?php echo number_format($b['totalbalance']);?></a>
                                        <?php } ?>
                                    <?php } ?>
                                </h3>
                            </div>
                        </div>
                    </div>
                    <?php } }?>
                    <?php if(isset($advance_comments)){if(sizeof($advance_comments)>0 ){ foreach($advance_comments as $ac){?>
                    <?php if(isset($ac['advance_remarks']) && $ac['advance_remarks']!==""){?>
                    <div class="row hidden-print" >
                        <div class="col-sm-12" >
                            <div class="alert alert-info" >
                                <h4 >
                                    <?php echo $ac['advance_remarks'];?>
                                </h4>
                            </div>
                        </div>
                    </div>
                    <?php }}} }?>
                    <?php if(isset($visit[0]['advance_comment']) && $visit[0]['advance_comment']!==null){
                       ?>
                        <div class="row hidden-print">
                            <div class="col-sm-12" >
                                <div class="alert alert-warning"  style="color:#000 !important">
                                   
                                        <?php echo $visit[0]['advance_comment'];?>
                                    
                                </div>
                            </div>
                        </div>
                    <?php } ?>
                </div>
                <div class="row">
                    <div class="col-md-12">
                        <div class="panel panel-default">
                            <div class="panel-body">
                                <div class="row">
                                    <div class="pull-left">
                                        <h3 class="logo invoice-logo"><?php if(isset($business)){ echo "<img src='".base_url().'assets/images/business/'.$business[0]['business_logo']."' alt='".$business[0]['business_name']."' class='img-responsive' />";} else {echo 'SalonPK';}?></h3>
                                    </div>
                                    <div class="pull-right">
                                        <!-- style="font-family: 'Libre Barcode 128 Text', cursive; font-size:62px;"  -->
                                        <h4 class="img-">Visit # <br>
                                            <strong id="invoicenumber" ><?php echo  date("Y").'-'.date("m").'-'; if(isset($visit[0]['id_customer_visits'])){ echo sprintf("%04s", $visit[0]['id_customer_visits']);}else{echo '00001';} ?></strong>
                                        </h4>
                                        <p class="hidden-lg hidden-md hidden-sm">Work Slip By: <?php echo $this->session->userdata('username');?></p>
                                    </div>
                                </div>
                               
                                <div class="row">
                                    <div class="col-md-12">
                                        <div class="pull-left m-t-10">
                                            <input name="visitid" id="visitid" type="hidden" value="<?php echo $visit[0]['id_customer_visits']; ?>"/>
                                            
                                            <input name="customerid" id="customerid" type="hidden" value="<?php echo $visit[0]['id_customers']; ?>">
                                            <input name="customername" id="customername" type="hidden" value="<?php echo $visit[0]['customer_name']; ?>">
                                            <input name="customercell" id="customercell" type="hidden" value="<?php echo $visit[0]['customer_cell']; ?>">
                                            <input name="visit_extra" id="visit_extra" type="hidden" value="<?php echo $visit[0]['visit_extra']; ?>">
                                            
                                            <input name="txtinvoiceid" id="txtinvoiceid" type="hidden" value=""/>
                                            <input name="loyaltypoints" id="loyaltypoints" type="hidden" value="<?php if(isset($customer_points)&& sizeof($customer_points)>0){ echo $customer_points[0]['loyalty_points'];} else {echo '0';} ?>"/>
                                            
                                            <?php if($services[0]['loyalty_service']=='Y' && $visit[0]['id_customers']>1) {?>
                                            Loyalty Customer Free Service : Points used <input name="loyaltyused" id="loyaltyused" readonly="readonly" style="border:none" value="<?php echo $loyalty_service[0]['required_points']; ?>"/>
                                            <?php } else { ?>
                                                <input name="loyaltyused" id="loyaltyused" type="hidden" value="0"/>
                                            <?php } ?>
                                            
                                            <input name="loyaltyrate" id="loyaltyrate" type="hidden" value="<?php echo $business[0]['l_point_discount']; ?>"/>
                                            <input name="loyaltyvalue" id="loyaltyvalue" type="hidden" value="<?php echo $business[0]['l_point_value']; ?>"/>
                                            <input name="loyaltyenabled" id="loyaltyenabled" type="hidden" value="<?php echo $business[0]['loyalty_enable']; ?>"/>
                                            <input name="sloyaltyenabled" id="sloyaltyenabled" type="hidden" value="<?php echo $business[0]['s_loyalty']; ?>"/>
                                            <input name="rloyaltyenabled" id="rloyaltyenabled" type="hidden" value="<?php echo $business[0]['r_loyalty_enable']; ?>"/>
                                            <input name="loyaltymode" id="loyaltymode" type="hidden" value="<?php echo $business[0]['loyalty_mode']; ?>"/>
                                            
                                            
                                            <input name="customeradvance" id="customeradvance" type="hidden" value="<?php if(isset($customer_points)&& sizeof($customer_points)>0){  echo $customer_points[0]['retained']; } else {echo '0';} ?>"/>
                                            <input name="retainedused" id="retainedused" type="hidden" value="No"/>
                                            <input name="retainedamountused" id="retainedamountused" type="hidden" value="0"/>
                                            <input name="remainingretained" id="remainingretained" type="hidden" value="<?php if(isset($customer_points)&& sizeof($customer_points)>0){  echo $customer_points[0]['retained']; } else {echo '0';} ?>"/>
                                            <input name="discount_pw" id="discount_pw" type="hidden" value="<?php if(isset($business[0]['discount_pw'])){ echo $business[0]['discount_pw'];}else{echo "N";} ?>" >
                                            Discount Password Verified: <input style="border:none;"  name="passwordverified" id="passwordverified" type="text" readonly value="No">
                                            <select style="display:none;" id="discountpw_list">
                                                <?php foreach($discount_pw as $d){?>
                                                <option value="<?php echo $d['password'];?>"><?php echo $d['username'];?></option>
                                                <?php } ?>
                                            </select>
                                            
                                            <address>
                                              <strong><?php echo $visit[0]['customer_name']; ?> <?php echo $visit[0]['visit_extra']; ?></strong><br>
                                              <?php echo $visit[0]['customer_address']; ?><br>
                                              <?php echo $visit[0]['customer_email']; ?><br>
                                              <abbr title="Phone">P:</abbr> <?php 
                                                    if( $this->session->userdata('hide_cell') && $this->session->userdata('hide_cell') == "No"){ 
                                                        echo $visit[0]['customer_cell']; 
                                                    } 
                                              ?>
                                              </address>
                                        </div>
                                        <div class="pull-right m-t-10">
                                            <p><strong>Date: </strong> <span id="invoice_date"><?php 
                                            //echo date('Y-m-d H:i:s');
                                            echo str_replace('T', ' ', $visit[0]['visit_service_start']);  ?></span></p>
                                            <?php if($services[0]['membership']=='Yes'){ ?>
                                                Membership Included Services
                                            <?php } ?>
                                        </div>
                                    </div><!-- end col -->
                                </div>
                                <!-- end row -->

                                
                                <?php $exist_product = array(); ?>
                                <div class="row">
                                    <div class="col-md-12">
                                        <div class="">
                                            <table class="table table-sm m-t-10" id="tblservices" >
                                                <thead>
                                                    <tr>
                                                        <th class="hidden-print">#</th>
                                                        <th class="hidden-print">Item</th>
                                                        <th>Description</th>
                                                        <th>Staff</th>
                                                        <th class="hidden-print">Requested</th>
                                                        <th class="hidden-print">Products</th>
                                                        <th class="hidden-print">Discount(Type)</th>
                                                        <th>Discount(<?php echo CURRENCY_CODE;?>)</th>
                                                        <th class="hidden-print">Discount(%)</th>                                                        
                                                        <th class="hidden-print">Addition</th>
                                                        <th>Service Cost</th>
                                                        <th class="hidden">price</th>
                                                    </tr>
                                                </thead>
                                                <tbody style="color:#000 !important">
                                                    <?php
                                                    $subtotal=0; if(isset($services)){
                                                        $x=1; $i=0;
                                                        foreach($services as $service){
                                                            $str= $service['service_name']; if(strpos($str, '(nc)')==false){ 
                                                            $subtotal=$subtotal+ $service['service_rate'];
                                                            }
                                                        ?>
                                                    <tr id="idtr">
                                                        <td class="hidden-print"><?php if(STICKY_VISITS==false){?><button onclick="removeservice(<?php echo $service['id_visit_services']; ?>,'<?php echo $service['service_name']; ?>');" class="btn btn-sm btn-danger"><i class="fa fa-remove text-white"></i></button> <?php } else {echo $x;}?></td>
                                                            <td class="hidden-print"><?php echo $service['service_category']; ?></td>
                                                            <td>
                                                                <input type="hidden" name="service_ids" value="<?php echo $service['id_business_services']; ?>">
                                                                <input type="hidden" name="visit_service_ids" value="<?php echo $service['id_visit_services']; ?>">
                                                                <input type="hidden" name="service_flag" value="<?php echo $service['service_flag']; ?>">
                                                                <input type="hidden" name="service_membership" value="<?php echo $service['membership']; ?>">
                                                                <?php echo $service['service_name']; ?>
                                                            </td>
                                                            <td>
                                                                <?php
                                                                $staff_names = ''; $requested='No';
                                                                
                                                                foreach($staffs as $staff){
                                                                    if($service['id_visit_services'] === $staff['visit_service_id']){
                                                                        $staff_names .= $staff['staff_name']."<br>";
                                                                    }
                                                                    if($staff['requested'] === 'Yes'){$requested='Yes';} 
                                                                }
                                                                echo $staff_names;
                                                                ?>
                                                            </td>
                                                            <td class="hidden-print">
                                                                <input type="checkbox" name="requested" class="checkbox checkbox-primary" <?php if($requested==='Yes'){echo 'checked="checked"';}?>  /> 
                                                            </td>
                                                            <td class="hidden-print" style="cursor: pointer;" id="<?php echo $service['id_business_services']."_".$x; ?>">
                                                                <select class="form-control input-sm service_products" id="service_products<?php echo $service['id_business_services']."_".$x; ?>" name="service_products" style="border:none; width:150px;" multiple="multiple">
                                                                <?php foreach($products as $product){
                                                                    if($service['id_visit_services'] === $product['visit_service_id']){
                                                                        echo "<option selected='selected' value='". $product['product_id'] ."'>".$product['product_name']."</option>";
                                                                    }
                                                                }   ?>
                                                                </select>
                                                               
                                                            </td>
                                                            <?php if($service['loyalty_service']=='N' && $service['membership']=='No'){?>
                                                            <td class="hidden-print">
                                                                <div class="col-lg-12">
                                                                    <div class="form-inline">
                                                                        <select onchange="Math.round($('#discount_by_service<?php echo $service['id_business_services']."_".$x; ?>').val(parseFloat($(this).children('option:selected').attr('perc'))*parseFloat($('#orignal_service_rate<?php echo $service['id_business_services']."_".$x; ?>').val())/100)*100)/100; calculate_discount(<?php echo $service['id_business_services'];?>,<?php echo $x;?>, <?php echo $service['service_rate'];?>);  " class="form-control input-sm" service_id="<?php echo $service['id_business_services']; ?>" name="discount_type" id="discount_type_<?php echo $service['id_business_services']."_".$x; ?>">
                                                                            <option perc="0" value=""></option>
                                                                            <?php if(sizeof($discount_types)>1){?>
                                                                                <?php foreach($discount_types as $dt){ ?>
                                                                                <option perc="<?php echo $dt['discount_perc']; ?>" value="<?php echo $dt['discount_reason']; ?>"><?php echo $dt['discount_reason'].' '.round($dt['discount_perc'],2).'%'; ?></option>
                                                                                <?php } ?>
                                                                            <?php }else { ?>
                                                                                <option perc="0" value="Normal">Normal</option>
                                                                                <option perc="0" value="Promotion">Promotion</option>
                                                                                <option perc="0" value="Promotion">Lapse</option>
                                                                                <option perc="0" value="Birthday">Birthday</option>
                                                                                <option perc="0" value="New Customer">New Customer</option>
                                                                            <?php } ?>
                                                                        </select>
                                                                    </div>
                                                                </div>
                                                            </td>
                                                            <td>
                                                                <div class="col-lg-12">
                                                                    <div class="form-inline">
                                                                        <input <?php if(isset($business[0]['discount_pw'])){if($business[0]['discount_pw']=='Y'){echo "readonly='readonly'";}}?> onclick="single_discount_pass('<?php echo $service['id_business_services']; ?>');" style="border:none; width: 60px;" onkeyup="$('#addition_by_service<?php echo $service['id_business_services']."_".$x; ?>').val('0'); if(this.value > <?php echo $service['service_rate']; ?> || this.value==''){this.value=0;}; javascript:discount_by_service(this.value, '<?php echo $service['id_business_services']."_".$x; ?>');" class="numeric discount_by_service" type="text" name="discount_by_service" id="discount_by_service<?php echo $service['id_business_services']."_".$x; ?>" value="0"  />                                                                    
                                                                    </div>
                                                                </div>
                                                            </td>
                                                            <td class="hidden-print">
                                                                <div class="col-lg-12">
                                                                    <div class="form-inline">
                                                                        <input <?php if(isset($business[0]['discount_pw'])){if($business[0]['discount_pw']=='Y'){echo "readonly='readonly'";}}?> onclick="single_discount_pass('<?php echo $service['id_business_services']; ?>');" style="border:none; width: 40px;" onchange="$('#addition_by_service<?php echo $service['id_business_services']."_".$x; ?>').val('0'); if(this.value > 100 || this.value==''){this.value=0;}; javascript:perc_discount_service(this.value, '<?php echo $service['id_business_services']."_".$x; ?>');" class="numeric perc_discount_service" type="text" name="perc_discount_service" service_id="<?php echo $service['id_business_services'];?>" id="perc_discount_service<?php echo $service['id_business_services']."_".$x; ?>" value="0"  />
                                                                    </div>
                                                                </div>
                                                            </td>
                                                            
                                                            
                                                            <td class="hidden-print">
                                                                <div class="col-lg-12">
                                                                    <div class="form-inline">
                                                                        <input  style="border:none; width: 60px;" onkeyup="$('#discount_by_service<?php echo $service['id_business_services']."_".$x; ?>').val('0'); if(this.value==''){ this.value=0; };  javascript:discount_by_service('0', '<?php echo $service['id_business_services']."_".$x; ?>');" class="numeric addition_by_service" type="text" name="addition_by_service" id="addition_by_service<?php echo $service['id_business_services']."_".$x; ?>" value="0" />
                                                                    </div>
                                                                </div>
                                                            </td>
                                                            
                                                            <?php $str= $service['service_name']; if(strpos($str, '(nc)')!==false){  ?>
                                                                <td ><?php echo CURRENCY_CODE;?>.<span class="combat" id="unitcost<?php echo $service['id_business_services']."_".$x; ?>"><?php echo '0.00'; ?></span></td>
                                                                <td class="hidden hidden-print"> <input type="hidden" name="orignal_service_rate" id="orignal_service_rate<?php echo $service['id_business_services']."_".$x; ?>" value="<?php echo '0.00'; ?>" /></td>
                                                            <?php } else { ?>
                                                                <td ><?php echo CURRENCY_CODE;?>.<span class="combat" id="unitcost<?php echo $service['id_business_services']."_".$x; ?>"><?php echo $service['service_rate']; ?></span></td>
                                                                <td class="hidden hidden-print"> <input type="hidden" name="orignal_service_rate" id="orignal_service_rate<?php echo $service['id_business_services']."_".$x; ?>" value="<?php echo $service['service_rate']; ?>" /></td>
                                                            <?php } ?>
                                                            
                                                            <?php } else { ?>
                                                            <td class="hidden-print"><input readonly='readonly' style="border:none; width: 60px;" class="numeric discount_by_service" type="text" name="discount_by_service" id="discount_by_service<?php echo $service['id_business_services']."_".$x; ?>" value="0"   /></td>
                                                            <td class="hidden-print"></td>
                                                            <td class=""><input style='width: 150px; border:none; background: transparent;' readonly='readyonly' name="discount_type" id="discount_type_<?php echo $service['id_business_services']."_".$x; ?>" value='Membership'></td>
                                                            <td class="hidden-print"><input readonly='readonly' style="border:none; width: 60px; background: transparent;" class="numeric addition_by_service" type="text" name="addition_by_service" id="addition_by_service<?php echo $service['id_business_services']."_".$x; ?>" value="0" /></td>
                                                            <?php $str= $service['service_name']; if(strpos($str, '(nc)')!==false){  ?>
                                                                <td ><?php echo CURRENCY_CODE;?>.<span class="combat" id="unitcost<?php echo $service['id_business_services']."_".$x; ?>"><?php echo '0.00'; ?></span><input type="hidden" name="orignal_service_rate" id="orignal_service_rate<?php echo $service['id_business_services']."_".$x; ?>" value="0.00" /></td>
                                                                <td class="hidden hidden-print" ></td>
                                                            <?php } else { ?>
                                                                <td ><?php echo CURRENCY_CODE;?>.<span class="combat" id="unitcost<?php echo $service['id_business_services']."_".$x; ?>"><?php echo $service['service_rate']; ?></span><input type="hidden" name="orignal_service_rate" id="orignal_service_rate<?php echo $service['id_business_services']."_".$x; ?>" value="<?php echo $service['service_rate']; ?>" /></td>
                                                                <td class="hidden hidden-print" ></td>
                                                            <?php } ?>
                                                            
                                                            <?php } ?>
                                                        </tr>
                                                        <?php $x++; $i++;}} ?>

                                                </tbody>
                                            </table>
                                        </div>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-md-6 col-lg-6 hidden-sm hidden-xs">
                                        <div class="clearfix m-t-40">
                                            <h5 class="text-inverse font-600">Remarks:</h5>
                                            <textarea id="txtremarks" class="form-control" ></textarea>
                                        </div>
                                        
                                        <div class="clearfix m-t-10 form-group">
                                            <h5 class="text-inverse font-600">Coupon:</h5>
                                            <div class="col-md-10">
                                                <input id="txtcoupon" class="form-control" />
                                            </div>
                                            <div class="col-md-2">                                                
                                                <button onclick="applycoupondiscount();" class="btn btn-pink">Apply</button>
                                            </div>
                                        </div>
                                    </div>
                                    
                                    <div style="color:#000 !important" class="col-md-4 col-sm-12 col-xs-12 col-md-offset-2 <?php if(isset($business[0]['workslipamount'])){ if($business[0]['workslipamount']=='No'){ echo 'hidden-print';}}?>">
                                        
                                        <?php if($service['loyalty_service']=='N' && $service['membership']=='No'){?>
                                        <p class="text-right"><b>Total Before Discount:</b>   <?php echo CURRENCY_CODE;?>.<input id="txt_org_subtotal" class="form-inline" readonly="readonly" style="width: 80px; border: none;" value='<?php echo round((float)$subtotal*100)/100;?>'>
                                        <p class="text-right"><b>After Service Discounts:</b>   <?php echo CURRENCY_CODE;?>. <input id="txtsubtotal" class="form-inline" readonly="readonly" style="width: 80px; border: none;" value='<?php echo round((float)$subtotal*100)/100;?>'></p>
                                        <p class="text-right">Discount %: <input <?php if(isset($business[0]['discount_pw'])){if($business[0]['discount_pw']=='Y'){echo "readonly='readonly'";}}?>  class="numeric" id="txtdiscountperc" onkeyup="if(this.value > 100 || this.value==''){this.value=0;}" onchange="calcdiscount_perc();" class="form-inline " style="width: 80px; border: none;" value="0"/></p>
                                        <p class="text-right form-inline">
                                               
                                                <select onchange="$('#txtdiscount').val(Math.round(parseFloat($(this).children('option:selected').attr('perc')) * parseFloat($('#txtsubtotal').val())/100)); updatetotal();"  style="width:130px; height: 25px; border:#fefefe 1px solid;" class="hidden-print" name="invoice_discount_type" id="invoice_discount_type">
                                                    <?php if(sizeof($discount_types)>1){?>
                                                        <option perc="0" value=""></option>
                                                        <?php foreach($discount_types as $discount_reason){ ?>
                                                        <option <?php if($visit[0]['discount_reason'] == $discount_reason['discount_reason'].' '. round($discount_reason['discount_perc'],2).'%'){echo "selected='selected'";}?> perc="<?php echo $discount_reason['discount_perc']; ?>" value="<?php echo $discount_reason['discount_reason']; ?>"><?php echo $discount_reason['discount_reason'].' '. round($discount_reason['discount_perc'],2).'%'; ?></option>
                                                        <?php } ?>
                                                    <?php }else { ?>
                                                    <option value="Normal" perc="0">Normal</option>
                                                    <option value="Promotion" perc="0">Promotion</option>
                                                    <option value="Lapse" perc="0">Lapse</option>
                                                    <option value="Birthday" perc="0">Birthday</option>
                                                    <option value="New Customer" perc="0">New Customer</option>
                                                    <?php } ?>
                                                </select>
                                            
                                            Discount <span id="txtloyalty"></span> <?php echo CURRENCY_CODE;?>.: <input <?php if(isset($business[0]['discount_pw'])){if($business[0]['discount_pw']=='Y'){echo "readonly='readonly'";}}?>  class="numeric" id="txtdiscount" onkeyup="if(this.value > parseFloat($('#txtsubtotal').val()) || this.value==''){this.value=0;}" onchange="updatetotal();" class="form-inline " style="width: 80px; border: none;" value="<?php echo round((float)$visit[0]['discount']); ?>"/></p>
                                        <?php } else { ?>
                                        <?php if($service['loyalty_service']=='Y' && $service['membership']=='No'){?> 
                                        <p class="text-right"><b>Total Before Discount:</b>   <?php echo CURRENCY_CODE;?>.<input id="txt_org_subtotal" class="form-inline" readonly="readonly" style="width: 80px; border: none;" value='<?php echo round((float)$subtotal);?>'>
                                        <?php } else { ?>
                                            <p class="text-right"><b>Total Before Discount:</b>   <?php echo CURRENCY_CODE;?>.<input id="txt_org_subtotal" class="form-inline" readonly="readonly" style="width: 80px; border: none;" value='0.00'>
                                        <?php } ?>
                                        <p class="text-right"><b>After Service Discount:</b>   <?php echo CURRENCY_CODE;?>. <input id="txtsubtotal" class="form-inline"  style="width: 80px; border: none;" value='0.00'></p>
                                        <p class="text-right">Discount %: <input <?php if(isset($business[0]['discount_pw'])){if($business[0]['discount_pw']=='Y'){echo "readonly='readonly'";}}?> class="numeric"  id="txtdiscountperc" onkeyup="$('#txtothercharges').val(0); if(this.value > 100 || this.value==''){this.value=0;}" class="form-inline " style="width: 80px; border: none;" value="0"/></p>
                                        <p class="text-right">Discount <span id="txtloyalty"></span> <?php echo CURRENCY_CODE;?>.: <input <?php if(isset($business[0]['discount_pw'])){if($business[0]['discount_pw']=='Y'){echo "readonly='readonly'";}}?> onkeyup=" $('#txtothercharges').val(0); if(this.value > parseFloat($('#txtsubtotal').val()) || this.value==''){this.value=0;}" class="numeric" id="txtdiscount" class="form-inline " style="width: 80px; border: none;" value="0"/></p>
                                        <?php } ?>
                                        <p class="text-right">Other Charges <?php echo CURRENCY_CODE;?>.: <input class="numeric" onchange="$('#txtdiscountperc').val(0); $('#txtdiscount').val(0); updateothercharges()" id="txtothercharges" class="form-inline " style="width: 80px; border: none;" value="0"/></p>
                                        
                                        <p class="text-right">Gross Total:   <?php echo CURRENCY_CODE;?>. <input id="txtgross" readonly="readonly" class="form-inline " style="width: 80px; border: none;"/></p>
                                        <p class="text-right text-danger" id="cctip" style="display:none;">C-Card Tip <?php echo CURRENCY_CODE;?>.: <input class="numeric" onchange="updateothercharges()" id="txtcctip" name="cctip" class="form-inline " style="width: 80px; border: none;" value="0"/></p>
                                        <div class="m-t-10 m-b-10" id="divtaxes" style="display:none">
                                        <?php if(isset($taxes)){$x=0;foreach ($taxes as $tax) {?>
                                            
                                            <p class="text-right"><span  id="txttaxname<?php echo $x; ?>" ><?php echo $tax['tax_name'].' '; ?></span><input class="numeric" class="taxperc" style="width: 20px; border: none;" readonly="readonly" id="taxperc<?php echo $x;?>" value="<?php if(isset($tax['tax_percentage']) ||$tax['tax_percentage']!=""){ echo $tax['tax_percentage'];}?>">% :  <?php echo CURRENCY_CODE;?>. <input class="tax" mode="<?php echo $tax['tax_payment_mode']; ?>" readonly="readonly" class="form-inline " style="width: 80px; border: none;" value="0"/></p>
                                        <?php $x++;}}?>                                            
                                        </div>
                                        <div class="m-t-10 m-b-10" id="divcccharge" style="display:none">

                                            <p class="text-right">
                                                <span >CC Fee @ <input id="cc_charge" class="form-inline" style="width: 20px; border: none;" value="<?php echo $business[0]['cc_charge'];?>"> %</span> :  <?php echo CURRENCY_CODE;?>. 
                                                <input class="cccharge" id="txtcc_charge" name="txtcc_charge"  class="form-inline " style="width: 80px; border: none;" value="0" />
                                            </p>
                                            
                                        </div>
                                        
                                        <p class="text-right">Total Payable Amount:   <?php echo CURRENCY_CODE;?>. <input id="txttotalpayable" readonly="readonly" class="form-inline " style="width: 80px; border: none;"/></p>
                                        <hr>
                                        
                                        <h4 class="text-right text-custom">Advance <?php echo CURRENCY_CODE;?>. <input class="numeric" style="text-align: right; width: 95px; border: none;" readonly="readonly"  id="txtadvance"  name="txtadvance" value="<?php if(isset($advances)){if(!empty($advances)){ echo number_format((float)$advances[0]['advance_amount'], 2, '.', '');}else{echo '0';}}else{echo '0';}?>"/></h4>
                                        <h4 class="text-right hidden-print">Rounding Adjustment. <input class="numeric" style="text-align: right; width: 95px; border: none;" readonly="readonly"  id="txtroundadj"  name="txtroundadj"/></h4>
                                        <h3 class="text-right text-success">  <?php echo CURRENCY_CODE;?>. <input class="numeric" style="text-align: right; width: 100px; border: none;" readonly="readonly" id="grandtotal"  name="grandtotal"/></h3>
                                        
                                        <h4 class="text-right hidden-print">Paying Now <?php echo CURRENCY_CODE;?>. <input class="numeric" style="text-align: right; width: 95px; border: none;" onchange="updatetotal();" onclick="$(this).select();" id="paid"  name="paid" value="0"/></h4>
                                        <h4 id="payingcard" class="text-right hidden-print" style="display:none;">Card <?php echo CURRENCY_CODE;?>. <input class="numeric" style="text-align: right; width: 95px; border: none;" onkeyup="if(this.value==''){this.value=0}" onchange="updatetotal();" onclick="$(this).select();" id="cardpaid"  name="cardpaid" value="0"/></h4>
                                        <h4 id="payingcash" class="text-right hidden-print" style="display:none;">Cash <?php echo CURRENCY_CODE;?>. <input class="numeric" style="text-align: right; width: 95px; border: none;" onkeyup="if(this.value==''){this.value=0}" onchange="updatetotal(true);" onclick="$(this).select();" id="cashpaid"  name="cashpaid" value="0"/></h4>
                                        
                                        
                                        
                                        <h4 class="text-right text-primary hidden-print"><input id="keepadv" type="checkbox" <?php if($visit[0]['id_customers']<=1){ echo 'disabled="disabled"';} ?>> <span>Retain?</span> Return <?php echo CURRENCY_CODE;?>. <input class="numeric" style="text-align: right; width: 95px; border: none;" readonly="readonly" id="returnamount"  name="returnamount" value="0"></h4>
                                        <h4 class="text-right text-danger hidden-print">  Balance <?php echo CURRENCY_CODE;?>. <input class="numeric" style="text-align: right; width: 95px; border: none;" readonly="readonly" id="balanceamount"  name="balanceamount" value="0"></h4>
                                        <hr>
                                        <div class="text-right hidden-print">
                                            <p id="modep"><strong>Payment Mode: </strong><abbr> <span id="mode">Cash</span></abbr></p>
                                            <input id="input_payment_mode" value="Cash" type="hidden">
                                            <p id="ccp" style="display:none;"><abbr title="Bank Instrument"> <strong>C-Card#: </strong><abbr> <input class="numeric" style="width: 120px; border: none;" id="ccno"  name="ccno"/></abbr></p>
                                            <p id="checkp" style="display:none;"><abbr title="Bank Instrument"> <strong>Instrument#: </strong><input class="numeric" style="width: 120px; border: none;" id="checkno"  name="checkno"/></abbr></p>
                                            <p id="voucherp" style="display:none;">
                                                <abbr title="Voucher"> <strong>Voucher#: C</strong> 
                                                <input class="numeric" style="width: 100px; border: none;" id="voucherno" name="voucherno">
                                                <button class="btn btn-success btn-xs" onclick="validateVouchers();">Verify</button>
                                                </abbr>
                                            </p>
                                        </div>
                                    </div>
                                </div>
                                <hr>
                                <div class="hidden-print">
                                    <div class="pull-left">
                                        <?php if($visit[0]['id_customers']>1){ ?>
                                        <span name="txtcustomeradvance" style="<?php if(isset($customer_points) && sizeof($customer_points)>0){ if((Float)$customer_points[0]['retained']<=0){ echo 'display:none;'; }}else {echo 'display:none';}?> font-weight: bold;" class="text-custom" id="txtcustomeradvance">Customer's Retained Amount Available: <?php if(isset($customer_points)&& sizeof($customer_points)>0){ echo $customer_points[0]['retained'];} else {echo '0';} ?>&nbsp;&nbsp;&nbsp;&nbsp;</span>
                                        <a style='<?php if(isset($customer_points)&& sizeof($customer_points)>0){if((Float)$customer_points[0]['retained']<=0){ echo 'display:none;'; }}else{echo 'display:none';}?>' href="javascript:void(0);" onclick="usecustomeradvance();" class="btn btn-custom waves-effect waves-light" id="btncustomeradvance">Use</a>
                                        <?php } ?>
                                    </div>
                                    <div class="pull-right">
                                        <?php if($visit[0]['id_customers']>1){ ?>
                                            <span   name="txtloyaltypoints" style="<?php if($business[0]['loyalty_enable']==='N'){ echo 'display:none;'; }?> font-weight: bold;" class="text-success" id="txtloyaltypoints">Customer's Loyalty Points: <?php if(isset($customer_points)&& sizeof($customer_points)>0){echo $customer_points[0]['loyalty_points'];}else {echo 0;} ?>&nbsp;&nbsp;&nbsp;&nbsp;</span>
                                            <a style='<?php if($business[0]['loyalty_enable']==='N' || $services[0]['loyalty_service']=='Y'){ echo 'display:none;'; }?>' href="javascript:void(0);" onclick="loyaltydiscount('<?php echo $business[0]['loyalty_mode'];?>')" class="btn btn-success waves-effect waves-light" id="btnloyalty">Redeem Loyalty</a>
                                        <?php } ?>
                                        <div class="btn-group m-r-10 dropup">
                                            <button type="button" class="btn btn-custom dropdown-toggle waves-effect waves-light" data-toggle="dropdown" aria-expanded="false">Payment mode <span class="m-l-5"><i class="fa fa-money"></i></span></button>
                                            <ul class="dropdown-menu" role="menu">
                                                <li><a href="javascript:void(0);" onclick="opencash();">Cash</a></li>
                                                <li><a href="javascript:void(0);" onclick="opencc();">Credit Card</a></li>
                                                
                                                <li><a href="javascript:void(0);" onclick="opendc();">Debit Card</a></li>
                                                
                                                <li><a href="javascript:void(0);" onclick="openbank('Check');">Check</a></li>
                                                <li><a href="javascript:void(0);" onclick="openonline('Online');">Online</a></li>
                                                <li><a href="javascript:void(0);" onclick="openvoucher('Voucher');">Voucher</a></li>
                                                <li><a href="javascript:void(0);" onclick="openmixed('Mixed');">Mixed</a></li>
                                                <!--<li><a href="javascript:void(0);" onclick="openbalance('Balance');">Balance</a></li>-->
                                            </ul>
                                        </div>
                                        <a href="javascript:window.print()" class="btn btn-inverse waves-effect waves-light" id="btnprint" ><i class="fa fa-print"></i></a>
                                        <a href="javascript:void(0);" onclick="createinvoice();" class="btn btn-primary disabled waves-effect waves-light" id="btnsubmit">Submit</a>
                                        
                                    </div>
                                </div>
                            </div>
                        </div>

                    </div>

                </div>
                <!-- end row -->
                <!--invoice password start-->
                <div id="invoicepass" class="modal fade in" tabindex="-1" data-backdrop="static" data-keyboard="false" role="dialog" aria-labelledby="invoicepass" aria-hidden="true" style="display: none;">
                    <form id="discountForm" action="<?php echo base_url('invoice_controller/discount_login'); ?>" method="POST" enctype="multipart/form-data">
                        <div class="modal-dialog">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <!--<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>-->
                                    <h4 class="modal-title" id="custom-width-modalLabel">Invoice Discount Password</h4>
                                </div>
                                <div class="modal-body">
                                    <div class="row">
                                        <div class="col-lg-12">
                                            <div class="row">
                                                <div class="col-md-12">
                                                    <div class="form-group">
                                                        <label>Remarks</label>
                                                        <input type="text" name="discount_remarks" id="discount_remarks" class="form-control" />
                                                    </div> 
                                                </div> 
                                                
                                            </div>
                                            
                                            <div class="row">
                                                <div class="col-md-6">
                                                    <div class="form-group">
                                                        <label>Username</label>
                                                        <input required type="text" name="discount_username" id="discount_username" class="form-control" />
                                                    </div> 
                                                </div> 
                                                <div class="col-md-6">
                                                    <div class="form-group">
                                                        <label>Password</label>
                                                        <input required type="password" name="discount_password" id="discount_password" class="form-control" />
                                                    </div> 
                                                </div> 
                                            </div>

                                        </div>
                                    </div>

                                    <div class="modal-footer">
                                        <span id="pass_message"></span>
                                        <button type="button" class="btn btn-default waves-effect modal_close" data-dismiss="modal">Close</button>
                                        <button type="submit" class="btn btn-custom waves-effect waves-light cont">Continue</button>
                                    </div>
                                </div><!-- /.modal-content -->
                            </div><!-- /.modal-dialog -->
                        </div>
                    </form>
                </div>
                <!--invoice password end-->
                
                <!--Voucher Model-->
                <div id="voucherModal" class="modal fade in" tabindex="-1" role="dialog" aria-labelledby="voucherModal" aria-hidden="true" style="display: none;">
                    <div class="modal-dialog">
                        <div class="modal-content">
                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                                <h4 class="modal-title">Voucher Information</h4>
                            </div>
                            <div class="modal-body">
                                <div class="row">
                                    <div class="col-md-12">
                                        <input type="hidden" id="voucherType">
                                        <input type="hidden" id="voucherAmount">
                                        <input type="hidden" id="voucherRemainingAmount">
                                        <input type="hidden" id="voucherRemainingServices">
                                        <div class="" id="voucherHtml">
                                            
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="modal-footer" id="voucherModalFooter">
                                <button type="button" class="btn btn-default waves-effect" data-dismiss="modal">Close</button>
                                <button type="button" onclick="applyVoucher();" class="btn btn-custom waves-effect waves-light">Apply</button>
                            </div>
                        </div><!-- /.modal-content -->
                    </div><!-- /.modal-dialog -->
                </div>
                <!--End Voucher Model-->
                
                  <!--Add Product Modal-->
        <div id="product-modal" class="modal fade in" tabindex="-1" role="dialog" aria-labelledby="product-modal" aria-hidden="true" style="display: none;">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                        <h4 class="modal-title" id="custom-width-modalLabel">Product Update</h4>
                    </div>
                    <div class="modal-body">
                        <div class="row">
                            <div class="col-lg-6">
                                <div class="row">
                                    <div class="col-md-12">
                                        <div class="form-group">
                                            <label for="product1" class="control-label">Products</label>
                                            <select id="product1" name="product1" class="form-control" multiple></select>
                                            <span class="text-danger selectexist"></span>
                                        </div> 
                                    </div> 
                                </div>
                            </div>
                            <div class="col-lg-6">
                                <div class="row">
                                    <div class="col-md-12">
                                        <div class="form-group">
                                            <label for="product2" class="control-label">&nbsp;</label>
                                            <select id="product2" name="product2[]" class="form-control" multiple></select>
                                        </div> 
                                    </div> 
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <input type="hidden" name="vid" id="vid" />
                        <input type="hidden" name="visit_id_customer" id="visit_id_customer" value="<?php echo $this->input->post('visit-id'); ?>" />
                        <button type="button" class="btn btn-default waves-effect" data-dismiss="modal">Close</button>
                        <button onclick="product_update();" type="button" class="btn btn-custom waves-effect waves-light">Save</button>
                    </div>
                </div><!-- /.modal-content -->
            </div><!-- /.modal-dialog -->
        </div>
        <!--End Product Modal-->
        
        <!--Add Color Record Modal-->
        <div id="addlist" class="modal fade in" tabindex="-1" role="dialog" aria-labelledby="addlist" aria-hidden="true" style="display: none;">
            <div class="modal-dialog modal-lg" style="width: 80%;">
                <div class="modal-content">
                    <div class="modal-header">
<!--                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>-->
                        <h4 class="modal-title" id="custom-width-modalLabel">Add a Color Record</h4>
                    </div>
                    <div class="modal-body">
                        
                        <div class="row">
                            <div class="col-lg-6">
                                <div class="row">
                                    <div class="col-md-12">
                                        <div class="form-group">
                                            <label for="txttype" class="control-label">Color Type</label>
                                            <select id="txttype" name="txttype" class="form-control">
                                                <option value=""></option>
                                                <?php
                                                if (isset($color_type_list)) {
                                                    foreach ($color_type_list as $color_type) {
                                                        if ($color_type['status'] == "Yes") {
                                                            ?>
                                                            <option value="<?php echo $color_type['id']; ?>"><?php echo $color_type['type']; ?></option>
                                                        <?php }
                                                    }
                                                } ?>
                                            </select>
                                        </div> 
                                    </div> 
                                </div>

                                <div class="row">
                                    <div class="col-md-12">
                                        <div class="form-group">
                                            <label for="txtdate" class="control-label">Date</label>
                                            <input type="text" class="form-control" placeholder="Date" id="txtdate" name="txtdate">
                                        </div> 
                                    </div> 
                                </div>
                                
                                <div class="row">
                                    <div class="col-md-12">
                                        <div class="form-group">
                                            <label for="txttime" class="control-label">Duration (in minutes)</label>
                                            <input type="text" class="form-control numeric" placeholder="Time" id="txttime" name="txttime">
                                        </div> 
                                    </div> 
                                </div>
                            </div>
                            <div class="col-lg-6">
                                <div class="row">
                                    <div class="col-md-12">
                                        <div class="form-group">
                                            <label for="txtcharge" class="control-label">Charge</label>
                                            <input type="text" class="form-control numeric" placeholder="Charge" id="txtcharge" name="txtcharge">
                                        </div> 
                                    </div> 
                                </div>

                                <div class="row">
                                    <div class="col-md-12">
                                        <div class="form-group">
                                            <label for="txttypenumber" class="control-label">Color</label>
                                            <input class="form-control" type="text" name="txttypenumber" id="txttypenumber" />
                                        </div> 
                                    </div> 
                                </div>
                                
                                <div class="row">
                                    <div class="col-md-12">
                                        <div class="form-group">
                                            <label for="txtw_content" class="control-label">Water Content</label>
                                            <select class="form-control" name="txtw_content" id="txtw_content">
                                                <?php foreach ($WaterContent as $content){ ?>
                                                    <option value="<?php echo $content['content']; ?>"><?php echo $content['content']; ?></option>
                                                    <?php } ?>
                                            </select>
                                        </div> 
                                    </div> 
                                </div>
                            </div>
                        </div>
                      <!--Base Color Roots -->
                        <div class="row">                            
                            <div class="col-lg-12">
                                <label for="textdetails" class="control-label">Base Color & Roots:</label>
                                <ul id="rootsul" style="line-height: 32px;  list-style-type: none;">
                                    <li>
                                        
                                        <input style="display:inline;"  type="checkbox" class="checkbox checkbox-circle checkbox-info" name="rootscheckbox"> 
                                        
                                        Roots were 
                                        <select name="workdone" style="display: inline; width:100px; border:none;  ">
                                            <option value=""></option>
                                            <option value="glossed">glossed</option>
                                            <option value="colored">colored</option>
                                        </select> 
                                        with 
                                        <select name="colortype" style="display: inline; width:80px; border:none;  ">
                                            <option value=""></option>
                                                <?php
                                                if (isset($color_type_list)) {
                                                    foreach ($color_type_list as $color_type) {
                                                        if ($color_type['status'] == "Yes") {
                                                            ?>
                                                            <option value="<?php  echo $color_type['type']; ?>"><?php echo $color_type['type']; ?></option>
                                                        <?php }
                                                    }
                                                } ?>  
                                        </select>
                                        <select name="colornumber" style="display: inline; width:50px; border:none;  ">
                                            <option value=""></option>
                                            <?php foreach($color_numbers as $cn){?>
                                                <option value="<?php echo $cn['number'];?>"><?php echo $cn['number'];?></option>
                                            <?php } ?>   
                                        </select>         
                                        for 
                                        <select name="time" style="display: inline; width:50px; border:none;  ">
                                            <option value=""></option>
                                            <option value="1">1</option>
                                            <option value="2">2</option>
                                            <option value="3">3</option>
                                            <option value="4">4</option>
                                            <option value="5">5</option>
                                            <option value="6">6</option>
                                            <option value="7">7</option>
                                            <option value="8">8</option>
                                            <option value="9">9</option>
                                            <option value="10">10</option>
                                            <option value="15">15</option>
                                            <option value="20">20</option>
                                            <option value="25">25</option>
                                            <option value="30">30</option>
                                            <option value="35">35</option>
                                            <option value="40">40</option>
                                        </select>                 
                                        mins.
                                    </li>
                                    <li>
                                        <input type="checkbox" class="checkbox-circle" name="rootscheckbox"> Roots were 
                                        <select name="workdone" style="display: inline; width:100px; border:none;  ">
                                            <option value=""></option>
                                            <option value="glossed">glossed</option>
                                            <option value="colored">colored</option>
                                        </select>  
                                        with 
                                        <select name="colortype" style="display: inline; width:80px; border:none;  ">
                                            <option value=""></option>
                                                <?php
                                                if (isset($color_type_list)) {
                                                    foreach ($color_type_list as $color_type) {
                                                        if ($color_type['status'] == "Yes") {
                                                            ?>
                                                            <option value="<?php  echo $color_type['type']; ?>"><?php echo $color_type['type']; ?></option>
                                                        <?php }
                                                    }
                                                } ?>  
                                        </select>
                                        <select name="colornumber" style="display: inline; width:50px; border:none;  ">
                                            <option value=""></option>
                                            <?php foreach($color_numbers as $cn){?>
                                                <option value="<?php echo $cn['number'];?>"><?php echo $cn['number'];?></option>
                                            <?php } ?>   
                                        </select>  
                                        for 
                                        <select name="time" style="display: inline; width:50px; border:none;  ">
                                            <option value=""></option>
                                            <option value="1">1</option>
                                            <option value="2">2</option>
                                            <option value="3">3</option>
                                            <option value="4">4</option>
                                            <option value="5">5</option>
                                            <option value="6">6</option>
                                            <option value="7">7</option>
                                            <option value="8">8</option>
                                            <option value="9">9</option>
                                            <option value="10">10</option>
                                            <option value="15">15</option>
                                            <option value="20">20</option>
                                            <option value="25">25</option>
                                            <option value="30">30</option>
                                            <option value="35">35</option>
                                            <option value="40">40</option>
                                        </select> 
                                        mins and the length were glossed with 
                                        <select name="colortype1" style="display: inline; width:80px; border:none;  ">
                                            <option value=""></option>
                                                <?php
                                                if (isset($color_type_list)) {
                                                    foreach ($color_type_list as $color_type) {
                                                        if ($color_type['status'] == "Yes") {
                                                            ?>
                                                            <option value="<?php  echo $color_type['type']; ?>"><?php echo $color_type['type']; ?></option>
                                                        <?php }
                                                    }
                                                } ?>  
                                        </select>
                                        <select name="colornumber1" style="display: inline; width:50px; border:none;  ">
                                            <option value=""></option>
                                            <?php foreach($color_numbers as $cn){?>
                                                <option value="<?php echo $cn['number'];?>"><?php echo $cn['number'];?></option>
                                            <?php } ?>   
                                        </select>  
                                        for  
                                        <select name="time1" style="display: inline; width:50px; border:none;  ">
                                            <option value=""></option>
                                            <option value="1">1</option>
                                            <option value="2">2</option>
                                            <option value="3">3</option>
                                            <option value="4">4</option>
                                            <option value="5">5</option>
                                            <option value="6">6</option>
                                            <option value="7">7</option>
                                            <option value="8">8</option>
                                            <option value="9">9</option>
                                            <option value="10">10</option>
                                            <option value="15">15</option>
                                            <option value="20">20</option>
                                            <option value="25">25</option>
                                            <option value="30">30</option>
                                            <option value="35">35</option>
                                            <option value="40">40</option>
                                        </select>
                                        mins.
                                    </li>
                                    <li><input type="checkbox" class="checkbox-circle" name="rootscheckbox"> Fullhead was 
                                        <select name="workdone" style="display: inline; width:100px; border:none;  ">
                                            <option value=""></option>
                                            <option value="glossed">glossed</option>
                                            <option value="colored">colored</option>
                                        </select>   
                                        with 
                                        <select name="colortype" style="display: inline; width:80px; border:none;  ">
                                            <option value=""></option>
                                                <?php
                                                if (isset($color_type_list)) {
                                                    foreach ($color_type_list as $color_type) {
                                                        if ($color_type['status'] == "Yes") {
                                                            ?>
                                                            <option value="<?php  echo $color_type['type']; ?>"><?php echo $color_type['type']; ?></option>
                                                        <?php }
                                                    }
                                                } ?>  
                                        </select>
                                        <select name="colornumber" style="display: inline; width:50px; border:none;  ">
                                            <option value=""></option>
                                        <?php foreach($color_numbers as $cn){?>
                                            <option value="<?php echo $cn['number'];?>"><?php echo $cn['number'];?></option>
                                        <?php } ?>   
                                        </select>  
                                        for 
                                        <select name="time" style="display: inline; width:50px; border:none;  ">
                                            <option value=""></option>
                                            <option value="1">1</option>
                                            <option value="2">2</option>
                                            <option value="3">3</option>
                                            <option value="4">4</option>
                                            <option value="5">5</option>
                                            <option value="6">6</option>
                                            <option value="7">7</option>
                                            <option value="8">8</option>
                                            <option value="9">9</option>
                                            <option value="10">10</option>
                                            <option value="15">15</option>
                                            <option value="20">20</option>
                                            <option value="25">25</option>
                                            <option value="30">30</option>
                                            <option value="35">35</option>
                                            <option value="40">40</option>
                                        </select> 
                                        mins in the roots and 
                                        <select name="time1" style="display: inline; width:50px; border:none;  ">
                                            <option value=""></option>
                                            <option value="1">1</option>
                                            <option value="2">2</option>
                                            <option value="3">3</option>
                                            <option value="4">4</option>
                                            <option value="5">5</option>
                                            <option value="6">6</option>
                                            <option value="7">7</option>
                                            <option value="8">8</option>
                                            <option value="9">9</option>
                                            <option value="10">10</option>
                                            <option value="15">15</option>
                                            <option value="20">20</option>
                                            <option value="25">25</option>
                                            <option value="30">30</option>
                                            <option value="35">35</option>
                                            <option value="40">40</option>
                                        </select> 
                                        mins through the length.                                        
                                    </li>
                                    <li>
                                        <input type="checkbox" class="checkbox-circle" name="rootscheckbox"> Braids were  
                                        <select name="workdone" style="display: inline; width:100px; border:none;  ">
                                            <option value=""></option>
                                            <option value="glossed">glossed</option>
                                            <option value="colored">colored</option>
                                        </select>    
                                        with 
                                        <select name="colortype" style="display: inline; width:80px; border:none;  ">
                                            <option value=""></option>
                                                <?php
                                                if (isset($color_type_list)) {
                                                    foreach ($color_type_list as $color_type) {
                                                        if ($color_type['status'] == "Yes") {
                                                            ?>
                                                            <option value="<?php  echo $color_type['type']; ?>"><?php echo $color_type['type']; ?></option>
                                                        <?php }
                                                    }
                                                } ?>  
                                        </select>
                                        <select name="colornumber" style="display: inline; width:50px; border:none;  ">
                                            <option value=""></option>
                                        <?php foreach($color_numbers as $cn){?>
                                            <option value="<?php echo $cn['number'];?>"><?php echo $cn['number'];?></option>
                                        <?php } ?>   
                                        </select>  
                                        for
                                        <select name="time" style="display: inline; width:50px; border:none;  ">
                                            <option value=""></option>
                                            <option value="1">1</option>
                                            <option value="2">2</option>
                                            <option value="3">3</option>
                                            <option value="4">4</option>
                                            <option value="5">5</option>
                                            <option value="6">6</option>
                                            <option value="7">7</option>
                                            <option value="8">8</option>
                                            <option value="9">9</option>
                                            <option value="10">10</option>
                                            <option value="15">15</option>
                                            <option value="20">20</option>
                                            <option value="25">25</option>
                                            <option value="30">30</option>
                                            <option value="35">35</option>
                                            <option value="40">40</option>
                                        </select> 
                                        mins.
                                    </li>
                                </ul>
                            </div>
                            
                        </div>
                        
                      <!-- HighLights -->
                      <div class="row">                            
                            <div class="col-lg-12">
                                <label for="textdetails" class="control-label">Lights:</label>
                                <ul id="lightsul" style="line-height: 32px;  list-style-type: none;">
                                    <li>
                                        
                                        <input style="display:inline;"  type="checkbox" class="checkbox checkbox-circle checkbox-info" name="lightscheckbox"> 
                                        
                                        Lights were Pre-lightened with 
                                         <select name="colornumber" style="display: inline; width:50px; border:none;  ">
                                            <option value="10">10</option>
                                            <option value="20">20</option>
                                            <option value="30">30</option>
                                            <option value="40">40</option>
                                        </select>         
                                        vol.
                                    </li>
                                    <li><input type="checkbox" class="checkbox-circle" name="lightscheckbox"> 
                                        Lights were Toned with
                                        <select name="colornumber" style="display: inline; width:50px; border:none;  ">
                                            <option value=""></option>
                                            <?php foreach($color_numbers as $cn){?>
                                                <option value="<?php echo $cn['number'];?>"><?php echo $cn['number'];?></option>
                                            <?php } ?>   
                                        </select>  
                                        for 
                                        <select name="time" style="display: inline; width:50px; border:none;  ">
                                            <option value=""></option>
                                            <option value="1">1</option>
                                            <option value="2">2</option>
                                            <option value="3">3</option>
                                            <option value="4">4</option>
                                            <option value="5">5</option>
                                            <option value="6">6</option>
                                            <option value="7">7</option>
                                            <option value="8">8</option>
                                            <option value="9">9</option>
                                            <option value="10">10</option>
                                            <option value="15">15</option>
                                            <option value="20">20</option>
                                            <option value="25">25</option>
                                            <option value="30">30</option>
                                            <option value="35">35</option>
                                            <option value="40">40</option>
                                        </select> 
                                        mins throughout.
                                    </li>
                                    <li><input type="checkbox" class="checkbox-circle" name="lightscheckbox"> 
                                        Lights were Toned with
                                        <select name="colornumber" style="display: inline; width:50px; border:none;  ">
                                            <option value=""></option>
                                            <?php foreach($color_numbers as $cn){?>
                                                <option value="<?php echo $cn['number'];?>"><?php echo $cn['number'];?></option>
                                            <?php } ?>   
                                        </select>  
                                        in the roots and 
                                        <select name="colornumber1" style="display: inline; width:50px; border:none;  ">
                                            <option value=""></option>
                                            <?php foreach($color_numbers as $cn){?>
                                                <option value="<?php echo $cn['number'];?>"><?php echo $cn['number'];?></option>
                                            <?php } ?>   
                                        </select>  
                                        through the length for
                                        <select name="time" style="display: inline; width:50px; border:none;  ">
                                            <option value=""></option>
                                            <option value="1">1</option>
                                            <option value="2">2</option>
                                            <option value="3">3</option>
                                            <option value="4">4</option>
                                            <option value="5">5</option>
                                            <option value="6">6</option>
                                            <option value="7">7</option>
                                            <option value="8">8</option>
                                            <option value="9">9</option>
                                            <option value="10">10</option>
                                            <option value="15">15</option>
                                            <option value="20">20</option>
                                            <option value="25">25</option>
                                            <option value="30">30</option>
                                            <option value="35">35</option>
                                            <option value="40">40</option>
                                        </select> 
                                        mins.
                                    </li>
                                    <li>
                                        <input type="checkbox" class="checkbox-circle" name="lightscheckbox"> 
                                        Smart Bond
                                    </li>
                                    <li>
                                        <input type="checkbox" class="checkbox-circle" name="lightscheckbox"> 
                                        Color Correction
                                    </li>
                                    <li>
                                        <input type="checkbox" class="checkbox-circle" name="lightscheckbox"> 
                                        Double Application
                                    </li>
                                    <li>
                                        <input type="checkbox" class="checkbox-circle" name="lightscheckbox"> 
                                        Open Foils
                                    </li>
                                </ul>
                            </div>
                            
                        </div>
                        
                        
                        <div class="row">
                            <div class="col-md-12">
                                <div class="form-group">
                                    <label for="txtcolorremarks" class="control-label">Remarks</label>
                                    <textarea id="txtcolorremarks" class="form-control"  style="height:100px;"></textarea>
                                </div> 
                            </div> 
                        </div>
                        <div class="row">
                            <div class="col-md-12">
                                <div class="form-group">
                                    <label for="txtrecommendation" class="control-label">Recommendation</label>
                                    <textarea id="txtrecommendation" name="txtrecommendation" class="form-control"></textarea>
                                </div> 
                            </div> 
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default waves-effect" data-dismiss="modal">Close</button>
                        <button onclick="$('#btncolor').hide(); updateHairColorHistory();" class="btn btn-custom waves-effect waves-light">Save</button>
                    </div>
                </div><!-- /.modal-content -->
            </div><!-- /.modal-dialog -->
        </div>
        <!--End Color Record Modal-->

        <!--Add Facial Modal-->
        <div id="addfacial" class="modal fade in" tabindex="-1" role="dialog" aria-labelledby="addfacial" aria-hidden="true" style="display: none;">
            <div class="modal-dialog">
                <div class="modal-content">
                    
                        <div class="modal-header">
                            <!--<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>-->
                            <h4 class="modal-title" id="custom-width-modalLabel">Add a Facial Record</h4>
                        </div>
                        <div class="modal-body">
                            <div class="row">
                                <div class="col-lg-6">
                                    <div class="row">
                                        <div class="col-md-12">
                                            <div class="form-group">
                                                <label for="txtdate" class="control-label">Date</label>
                                                <input type="text" readonly="readonly" class="form-control" value="<?php echo date('Y-m-d'); ?>" placeholder="Date" name="txtfacialdate" id="txtfacialdate">
                                            </div> 
                                        </div> 
                                    </div>
                                    <div class="row">
                                        <div class="col-md-12">
                                            <div class="form-group">
                                                <label for="txtexfoliant" class="control-label">Exfoliant</label>
                                                <input type="text" class="form-control" placeholder="Exfoliant" id="txtfacialexfoliant" name="txtfacialexfoliant">
                                            </div> 
                                        </div> 
                                    </div>
                                    
                                    <div class="row">
                                        <div class="col-md-12">
                                            <div class="form-group">
                                                <label for="txtcleanser" class="control-label">Cleanser</label>
                                                <input type="text" class="form-control" placeholder="Cleanser" id="txtfacialcleanser" name="txtfacialcleanser">
                                            </div> 
                                        </div> 
                                    </div>
                                </div>
                                <div class="col-lg-6">
                                    <div class="row">
                                        <div class="col-md-12">
                                            <div class="form-group">
                                                <label for="txtcharge" class="control-label">Charge</label>
                                                <input type="text" class="form-control numeric" placeholder="Charge" id="txtfacialcharge" name="txtfacialcharge">
                                            </div> 
                                        </div> 
                                    </div>
                                    <div class="row">
                                        <div class="col-md-12">
                                            <div class="form-group">
                                                <label for="txttime" class="control-label">Duration (minutes)</label>
                                                <input type="text" class="form-control numeric" placeholder="Time" id="txtfacialtime" name="txtfacialtime">
                                            </div> 
                                        </div> 
                                    </div>
                                    
                                    <div class="row">
                                        <div class="col-md-12">
                                            <div class="form-group">
                                                <label for="txtmask" class="control-label">Mask</label>
                                                <input type="text" class="form-control" placeholder="Mask" id="txtfacialmask" name="txtfacialmask">
                                            </div> 
                                        </div> 
                                    </div>
                                    
                                    <div class="row">
                                        <div class="col-md-12">
                                            <div class="form-group">
                                                <label for="txtfacial" class="control-label">Facial name</label>
                                                <input type="text" class="form-control" placeholder="Flash" id="txtfacial" name="txtfacial">
                                            </div> 
                                        </div> 
                                    </div>
                                </div>
                            </div>
                            
                            <div class="row">
                                <div class="col-md-12">
                                    <div class="form-group">
                                        <label for="txtfacialremarks" class="control-label">Remarks</label>
                                        <textarea id="txtfacialremarks" name="txtfacialremarks" class="form-control"></textarea>
                                    </div> 
                                </div> 
                            </div>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default waves-effect" data-dismiss="modal">Close</button>
                            <button type="button" onclick="$('#btnfacial').hide(); updateFacialRecord();" class="btn btn-custom waves-effect waves-light">Save</button>
                        </div>
                   
                </div><!-- /.modal-content -->
            </div><!-- /.modal-dialog -->
        </div>
        <!--End Facial Modal-->
        <!--Add Add eyelash Modal-->
        <div id="addeyelashrecord" class="modal fade in" tabindex="-1" role="dialog" aria-labelledby="addeyelashrecord" aria-hidden="true" style="display: none;">
            <div class="modal-dialog">
                <div class="modal-content">
                    <form id="addlistForm" action="<?php echo base_url("eyelashes_controller/add_eyelashes"); ?>" method="POST">
                        <div class="modal-header">
                            <!--<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>-->
                            <h4 class="modal-title" id="custom-width-modalLabel">Add a Eyelashes Record</h4>
                        </div>
                        <div class="modal-body">
                            <div class="row">
                                <div class="col-lg-6">
                                    <div class="row">
                                        <div class="col-md-12">
                                            <div class="form-group">
                                                <label for="txttypeoflashes" class="control-label">Type of Lashes</label>
                                                <select name="txttypeoflashes" id="txttypeoflashes" class="form-control">
                                                    <option value=""></option>
                                                    <?php foreach($eyelashtypes as $eyelashtype){?>
                                                        <option value="<?php echo $eyelashtype['eyelash_type']; ?>"><?php echo $eyelashtype['eyelash_type']; ?></option>
                                                    <?php } ?>
                                                </select>
                                            </div> 
                                        </div> 
                                    </div>

                                    <div class="row">
                                        <div class="col-md-12">
                                            <div class="form-group">
                                                <label for="txteyelashthickness" class="control-label">Thickness</label>
                                                <select name="txteyelashthickness" id="txteyelashthickness" class="form-control">
                                                    <option value=""></option>
                                                    <option value="0.02">0.02</option>
                                                    <option value="0.03">0.03</option>
                                                    <option value="0.04">0.04</option>
                                                    <option value="0.05">0.05</option>
                                                    <option value="0.07">0.07</option>
                                                    <option value="0.10">0.10</option>
                                                    <option value="0.15">0.15</option>
                                                    <option value="0.20">0.20</option>
                                                    <option value="0.25">0.25</option>
                                                </select>
                                            </div> 
                                        </div> 
                                    </div>

                                    <div class="row">
                                        <div class="col-md-12">
                                            <div class="form-group">
                                                <label for="txteyelashdate" class="control-label">Date</label>
                                                <input type="text" class="form-control" placeholder="Date" value="<?php echo date('Y-m-d'); ?>" readonly="readonly" id="txteyelashdate" name="txteyelashdate">
                                            </div> 
                                        </div> 
                                    </div>
                                    
                                    <div class="row">
                                        <div class="col-md-12">
                                            <div class="form-group">
                                                <label for="txteyelashdate" class="control-label">Price</label>
                                                <input type="text" class="form-control" placeholder="Price" value=""  id="txteyelashprice" name="txteyelashprice">
                                            </div> 
                                        </div> 
                                    </div>

                                </div>
                                <div class="col-lg-6">
                                    <div class="row">
                                        <div class="col-md-12">
                                            <div class="form-group">
                                                <label for="txteyelashlength" class="control-label">Length</label>
                                                <!--<input name="txteyelashlength" required id="txteyelashlength" class="form-control multinumeric" />-->
                                                <select name="txteyelashlength" id="txteyelashlength" multiple="multiple" class="form-control">
                                                    <option value="7">7</option>
                                                    <option value="8">8</option>
                                                    <option value="9">9</option>
                                                    <option value="10">10</option>
                                                    <option value="11">11</option>
                                                    <option value="12">12</option>
                                                    <option value="13">13</option>
                                                    <option value="14">14</option>
                                                    <option value="15">15</option>
                                                </select>
                                            </div> 
                                        </div> 
                                    </div>

                                    <div class="row">
                                        <div class="col-md-12">
                                            <div class="form-group">
                                                <label for="txteyelashcurl"  class="control-label">Curl</label>
                                                <select name="txteyelashcurl" required id="txteyelashcurl" class="form-control">
                                                    <option value=""></option>
                                                    <option value="C" selected="selected">C</option>
                                                    <option value="J">J</option>
                                                    <option value="B">B</option>
                                                    <option value="D">D</option>
                                                </select>
                                            </div> 
                                        </div> 
                                    </div>

                                    <div class="row">
                                        <div class="col-md-12">
                                            <div class="form-group">
                                                <div class="row"></div>
                                                <div class="row">&nbsp;</div>
                                                <label class="radio-inline">
                                                    <input type="radio" checked="checked" value="Full set" name="txt_full_set_refill" id="txt_full_set_refill1"> Full set
                                                </label>
                                                <label class="radio-inline">
                                                    <input type="radio" value="Refill" name="txt_full_set_refill" id="txt_full_set_refill2"> Refill
                                                </label>
                                                <label class="radio-inline">
                                                    <input type="radio" value="Removal" name="txt_full_set_refill" id="txt_full_set_refill3"> Removal
                                                </label>
                                                <label class="radio-inline">
                                                    <input type="radio" value="Fix" name="txt_full_set_refill" id="txt_full_set_refill4"> Fix
                                                </label>
                                            </div> 
                                        </div> 
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-md-12">
                                    <div class="form-group">
                                        <label for="txteyelashremarks" class="control-label">Remarks</label>
                                        <textarea id="txteyelashremarks" name="txteyelashremarks" class="form-control"></textarea>
                                    </div> 
                                </div> 
                            </div>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default waves-effect" data-dismiss="modal">Close</button>
                            <button type="button" onclick="$('#btneyelash').hide(); addeyelashrecord();" class="btn btn-custom waves-effect waves-light">Save</button>
                        </div>
                    </form>
                </div><!-- /.modal-content -->
            </div><!-- /.modal-dialog -->
        </div>
        <!--End EyeLash Modal-->
                <input type="hidden" name="uid" id="uid" />
                <input type="hidden" name="uname" id="uname" />
                <input type="hidden" name="uusername" id="uusername" />
                <input type="hidden" name="uemail" id="uemail" />
                <input type="hidden" name="ddiscount_remarks" id="ddiscount_remarks" value="<?php if($services[0]['loyalty_service']=='Y'){echo "Loyalty Points Used to Avail Free Service";} else {echo "";} ?>" />

<?php include 'js_functions/service_invoice_js.php'; ?>                
<script>
    var enabtax=false;
    
    $(document).ready(function(){
        
        $(".service_products").select2({width: 'resolve'});
        
        
        $("#rootsul select").change( function(){
            $(this).parent().children("input[name='rootscheckbox']").prop('checked','checked');
        });
        $("#lightsul select").change( function(){
            $(this).parent().children("input[name='lightscheckbox']").prop('checked','checked');
        });
        
        $("#txteyelashlength").select2();
        
        
        <?php if($business[0]['tax_optional'] === 'No'){ ?>
            enabletaxes('yes');
        <?php } ?>
        
        <?php if($color_record === TRUE &&  $business[0]['force_extra_record']=='Y'){ foreach($services as $service){ ?>
            <?php if(stripos($service['service_type'],'Color') > -1){ ?>
                $('#addlist').modal({
                    
                    keyboard:true,
                    show:true
                });
                $("#btncolor").show();
            <?php } ?>
        <?php } } ?>
            
            
        <?php if($facial_record === TRUE &&  $business[0]['force_extra_record']=='Y'){ foreach($services as $service){ ?>
            <?php if(stripos($service['service_type'], "facial") > -1 || stripos($service['service_category'], "facial") > -1 || stripos($service['service_name'], "facial") > -1 ){ ?>
                $("#txtfacial").val('<?php echo $service['service_name'];?>');
                $("#txtfacialcharge").val('<?php echo $service['service_rate'];?>');
                $("#txtfacialtime").val('<?php echo $service['service_duration'];?>');
                
                $('#addfacial').modal({
                   
                    keyboard:true,
                    show:true
                });
                $("#btnfacial").show();
            <?php } ?>
        <?php } } ?>    
            
        <?php if($eyelashes_record === TRUE &&  $business[0]['force_extra_record']=='Y'){ foreach($services as $service){ ?>
            <?php if(stripos($service['service_type'], "eyelahes") > -1 || stripos($service['service_category'], "eyelashes") > -1 || stripos($service['service_name'], "eyelashes") > -1 ){ ?>
                
                $("#txteyelashprice").val('<?php echo $service['service_rate'];?>');
                
                $('#addeyelashrecord').modal({
                   
                    keyboard:true,
                    show:true
                });
                $("#btneyelash").show();
            <?php } ?>
        <?php } } ?>        
        
         $("#txtdate").datepicker({
            default: today,
            autoclose: true,
            todayHighlight: true,
            format: 'yyyy-mm-dd'
        }).datepicker('setDate', new Date());
   
        $("#txtcustomer").select2();
        $('#txtcustomer').select2('data', {id: $('#customerid').val(), text: $('#customername').val()});
        
        //Two Select box for services insert moving....
        $('#product1').on('change', function() {
            var val1 = $("#product1 option:selected").val();
            var txt1 = $("#product1 option:selected").text();


            $('#product2 option').each(function() {
                if($(this).attr('value') == val1){
                    alert("already exist!");die;
                }
            });

            $('#product2').append('<option selected value="'+val1+'">'+txt1+'</opiton>');

        });

        $('#product2').on('click', function() {
            $("#product2 option:selected").remove();
            $('#product2').find('option').prop('selected',true);
        });
        //end two select box..
               
        $(".numeric").keypress(function (e) {
            //if the letter is not digit then display error and don't type anything
            if (e.which != 13 && e.which != 8 && e.which != 0  && e.which != 46 && (e.which < 48 || e.which > 57)) {
               return false;
           }
        });
        $(".multinumeric").keypress(function (e) {
            //if the letter is not digit then display error and don't type anything
            if (e.which != 13 && e.which != 8 && e.which != 0  && e.which != 46 && e.which != 44 && (e.which < 48 || e.which > 57)) {
               return false;
           }
        });
        
        
        updatetotal();
        
        toastr.options = {
                    "closeButton": true,
                    "debug": true,
                    "newestOnTop": true,
                    "progressBar": true,
                    "positionClass": "toast-bottom-center",
                    "preventDuplicates": true,
                    "onclick": null,
                    "showDuration": "300",
                    "hideDuration": "1000",
                    "timeOut": "5000",
                    "extendedTimeOut": "1000",
                    "showEasing": "swing",
                    "hideEasing": "linear",
                    "showMethod": "fadeIn",
                    "hideMethod": "fadeOut"
                }
            $(".discount_by_service").on('click',function() {                
                if($(this).attr("readonly") && $("#btnloyalty").hasClass('btn-success')){
                    if($("#discount_pw").val()=="Y"){
                        $("#invoicepass").modal("show");
                    } else {
                        if($("#btnloyalty").hasClass('btn-success')){
                            $("#txtdiscount").attr("readonly",false);
                            $("#txtdiscountperc").attr("readonly",false);
                        }
                        $(".discount_by_service").attr("readonly",false);
                        $(".perc_discount_service").attr("readonly",false);
                    }
                }
            });
            
            $(".perc_discount_service").on('click',function() {                
                if($(this).attr("readonly") && $("#btnloyalty").hasClass('btn-success')){
                    if($("#discount_pw").val()=="Y"){
                        $("#invoicepass").modal("show");
                    } else {
                        if($("#btnloyalty").hasClass('btn-success')){
                            $("#txtdiscount").attr("readonly",false);
                            $("#txtdiscountperc").attr("readonly",false);
                        }
                        $(".discount_by_service").attr("readonly",false);
                        $(".perc_discount_service").attr("readonly",false);
                    }
                }
            });
                
            $("#txtdiscountperc").on('click',function() {                
                if($(this).attr("readonly") && $("#btnloyalty").hasClass('btn-success')){
                    if($("#discount_pw").val()=="Y"){
                        $("#invoicepass").modal("show");
                    } else {
                        if($("#btnloyalty").hasClass('btn-success')){
                            $("#txtdiscount").attr("readonly",false);
                            $("#txtdiscountperc").attr("readonly",false);
                        }
                        $(".discount_by_service").attr("readonly",false);
                        $(".perc_discount_service").attr("readonly",false);
                    }
                }
            });
            
            $("#txtdiscount").on('click',function() {
                if($(this).attr("readonly") && $("#btnloyalty").hasClass('btn-success')){
                    if($("#discount_pw").val()=="Y"){
                        $("#invoicepass").modal("show");
                    } else {
                        if($("#btnloyalty").hasClass('btn-success')){
                            $("#txtdiscount").attr("readonly",false);
                            $("#txtdiscountperc").attr("readonly",false);
                        }
                        $(".discount_by_service").attr("readonly",false);
                        $(".perc_discount_service").attr("readonly",false);
                    }
                }
            });
            
            $("#txtdiscountperc").dblclick(function() {
                if($("#btnloyalty").hasClass('btn-success')){
                    if($("#discount_pw").val()=="Y"){
                        $("#invoicepass").modal("show");
                    } else {
                        if($("#btnloyalty").hasClass('btn-success')){
                            $("#txtdiscount").attr("readonly",false);
                            $("#txtdiscountperc").attr("readonly",false);
                        }
                        $(".discount_by_service").attr("readonly",false);
                        $(".perc_discount_service").attr("readonly",false);
                    }
                }
            });
            
            $("#txtdiscount").dblclick(function() {
                if($("#btnloyalty").hasClass('btn-success')){
                    if($("#discount_pw").val()=="Y"){
                        $("#invoicepass").modal("show");
                    } else {
                        if($("#btnloyalty").hasClass('btn-success')){
                            $("#txtdiscount").attr("readonly",false);
                            $("#txtdiscountperc").attr("readonly",false);
                        }
                        $(".discount_by_service").attr("readonly",false);
                        $(".perc_discount_service").attr("readonly",false);
                    }
                }
            });
            
                    
        $('#discountForm').on('submit', function(e) {
            
        e.preventDefault();
        
            $.ajax({
            url: $(this).attr('action') || window.location.pathname,
            type: "POST",
            data: $(this).serialize(),
            dataType: "json",
            cache: false,
            //async: true,
            success: function(data) {
                if (data !== "error"){
                    //console.log(data);
                    
                    $("#uid").val(data['id']);
                    $("#uname").val(data['name']);
                    $("#uusername").val(data['username']);
                    $("#uemail").val(data['email']);
                    $("#ddiscount_remarks").val($("#discount_remarks").val());
                    
                    $("#discount_username").val('');
                    $("#discount_password").val('');
                    $("#discount_remarks").val('');
                    if($("#btnloyalty").hasClass('btn-success')){
                        $("#txtdiscount").attr("readonly",false);
                        $("#txtdiscountperc").attr("readonly",false);
                    }
                    $(".discount_by_service").attr("readonly",false);
                    $(".perc_discount_service").attr("readonly",false);
                    
                    $("#invoicepass").modal("hide");
                } else{
                    //$("#pass_message").text('Please provide valid username/password!');
                    //$("#pass_message").fadeOut(1000);
                }
            },
            error: function(jXHR, textStatus, errorThrown) {
            //alert(errorThrown);
            $("#pass_message").text('Invalid username/password!');
            $("#pass_message").fadeIn(3000);
            $("#pass_message").fadeOut(3000);
            }
            });
        });
 

        $("#txtdiscount").change(function(){
            //if($('#txtothercharges').val()===""){
                $('#txtothercharges').val(0);
            //}
            var subtotalextra = parseFloat($('#txtsubtotal').val())+parseFloat($('#txtothercharges').val());
            var parcentage = (parseFloat($(this).val()) / subtotalextra) * 100;
            $('#txtdiscountperc').val(Math.round(parcentage*100)/100);
            //$("#paid").val($("#grandtotal").val());
            $("#balanceamount").val(parseFloat($("#grandtotal").val()) - parseFloat($("#paid").val()));
            updatetotal();
            
        });
        
        $('#txtcc_charge').change(function(){
            updatetotal();
        });
        $("#cc_charge").change(function(){
            updatetotal();
        })
        
        $('#txtdate').datepicker({
            autoclose: true,
            todayHighlight: true,
            format: 'yyyy-mm-dd'
        });
        
        $('#keepadv').click(function(){
            
            if(parseInt($("#returnamount").val()) <= 0){
                $(this).prop('checked',false)
            }
        });
        
    });   
    
    

    async function updatetotal(mixedcash=false){
        //console.log(mixedcash);
        
        $('#btnsubmit').addClass('disabled');
        $('#btnsubmit').html('<i class="fa fa-spin fa-spinner"></i> Please wait');
        
        if($('#txtdiscount').val()===""){$('#txtdiscount').val('0');}
        if($('#txtothercharges').val()===""){$('#txtothercharges').val('0');}
       
        //var grosstotal=(parseFloat($("#txtsubtotal").val()) +  parseFloat($("#txtothercharges").val()) + parseFloat($("#txtcctip").val()) - parseFloat($("#txtdiscount").val()));
        var grosstotal=(parseFloat($("#txtsubtotal").val()) +  parseFloat($("#txtothercharges").val()) - parseFloat($("#txtdiscount").val()));
        var taxabletotal=(parseFloat($("#txtsubtotal").val()) +  parseFloat($("#txtothercharges").val())) - parseFloat($("#txtdiscount").val());
        var orggrosstotal = parseFloat($("#txt_org_subtotal").val()) +  parseFloat($("#txtothercharges").val()); //was txt_org_subtotal
        
        grosstotal = Math.round(grosstotal*100)/100;
        taxabletotal= Math.round(taxabletotal*100)/100;
        orggrosstotal=Math.round(orggrosstotal*100)/100;
        
        $("#txtgross").val(grosstotal);
        
        var nettax= 0;
        if(enabtax===true){
            var taxarray = [];
            $( ".tax" ).each(function(index) {
                $(this).val('0');
                var thistax=0;
                if($(this).attr("mode")=="all" || $(this).attr("mode").toUpperCase()==$("#mode").html().toUpperCase()){
                  <?php if(isset($business[0]['tax_mode'])){if($business[0]['tax_mode'] == 'before'){?>
                      thistax=orggrosstotal*parseFloat($("#taxperc"+index).val())/100;
                  <?php } else{?>
                      thistax=taxabletotal*parseFloat($("#taxperc"+index).val())/100;
                  <?php }?>
                  <?php } else {?>
                      thistax=orggrosstotal*parseFloat($("#taxperc"+index).val())/100;
                  <?php }?>    

                  $(this).val(Math.round(thistax*100)/100);
                  taxarray.push($(this).val());
                }

                if(thistax <= 0){ $(this).parent("p").hide(); }else{ $(this).parent("p").show(); }
            });
            for(x=0; x<taxarray.length;x++){
                nettax=nettax + parseFloat(taxarray[x]);
            }
            
        }
        
//        if ($("#divcccharge").is(':visible') &&  parseFloat($("#cc_charge").val()) > 0) {
//            
//            $("#txtcc_charge").val("0");
//            //console.log('grandtotal : '+ parseFloat($("#grandtotal").val()) + " cc_charge : " + $("#cc_charge").val());
//            var totaltax=0;
//            $('.tax').each(function(index){
//                totaltax += parseFloat($(this).val());
//            });
//            var tempgrosstotal = parseFloat($("#txtgross").val()) + totaltax;
//            var ccc = (tempgrosstotal * parseFloat($("#cc_charge").val())) / 100;
//            $("#txtcc_charge").val(Math.round(ccc*100)/100);
//
//        }        
        if ($("#input_payment_mode").val()=='Card' && $("#divcccharge").is(':visible') &&  parseFloat($("#cc_charge").val()) > 0) {           
            updatecccharge();
        } else if($("#input_payment_mode").val()=='Mixed'){
            updatepayingcard(mixedcash);           
        }
        
        var totalpayable=grosstotal + nettax + parseFloat($("#txtcc_charge").val())+ parseFloat($("#txtcctip").val());
        $("#txttotalpayable").val(Math.round(totalpayable*100)/100);
        
        var unroundedgrandtotal = (grosstotal + nettax + parseFloat($("#txtcc_charge").val())+ parseFloat($("#txtcctip").val())) - (parseFloat($("#txtadvance").val()));
        var grandtotal = Math.round(unroundedgrandtotal);
        var roundadjustment = grandtotal - unroundedgrandtotal;
        
        $("#txtroundadj").val(Math.round(roundadjustment*100)/100); 
        
        if(grandtotal>=0){
            $("#grandtotal").val(grandtotal);
        }else{
            $("#grandtotal").val('0');
        }
        
        if($("#paid").val() === "0" || $("#paid").val() === ""){
            $("#balanceamount").val(Math.round((grosstotal + nettax)*100)/100);
            $("#paid").val(0);
        } else {
            $("#balanceamount").val(Math.round((grosstotal - parseFloat($("#paid").val()))*100)/100);
        }
        
        if(parseInt($('#paid').val()) > (parseInt(grandtotal)+  parseInt($("#txtcc_charge").val()))){
            $('#returnamount').val(Math.round((parseFloat($('#paid').val()) - grandtotal)*100)/100);
            $("#balanceamount").val(0);
        } else{
            $("#returnamount").val(0);
            $('#balanceamount').val(Math.round((parseFloat(grandtotal) - parseFloat($('#paid').val()))*100)/100);
            //console.log('less');
        }
        
       
        $('#btnsubmit').html('Submit');        
        $('#btnsubmit').removeClass('disabled');
    }
    
    function createinvoice(){
        //console.log('checking other var');
        //updatetotal();
        
        if($("#btncolor").is(':visible')){
            opencolor();
            return false; 
        } else if($("#btneyelash").is(':visible')){
            openeyelash();
            return false;
        } else if($("#btnfacial").is(':visible')){
            openfacial();
            return false;
        }
        
        
        if($("#mode").html() == 'Voucher'){
            
        }
        
        if ($('#grandtotal').val() == ""){
            swal({
                title: 'Please Wait . . .',
                text: "Calculating Amounts!",
                type: 'info',
                showCancelButton: false,
                confirmButtonColor: '#ff5b5b !important',
                confirmButtonText: 'Ok'
            });
            return false;
        }
        
        if (parseInt($('#grandtotal').val()) <= 0 && parseInt($('#paid').val())-parseInt($('#txtadvance').val()) > 0){
            swal({
                title: 'Please Wait . . .',
                text: "Grand Total cannot be less then Paid Amount!",
                type: 'info',
                showCancelButton: false,
                confirmButtonColor: '#ff5b5b !important',
                confirmButtonText: 'Ok'
            });
            return false;
        }
        
        if ((parseInt($('#paid').val()) + parseInt($('#txtadvance').val())) - parseInt($('#returnamount').val()) < 0){
            swal({
                title: 'Please Wait . . .',
                text: "Paid minus return amount cannot be less then zero!",
                type: 'info',
                showCancelButton: false,
                confirmButtonColor: '#ff5b5b !important',
                confirmButtonText: 'Ok'
            });
            return false;
        }
        
        if($('#customerid').val() <= 1 && parseInt($('#paid').val()) < parseInt($('#grandtotal').val())){
            swal({
                title: 'Walk In Customer',
                text: "No Balances Allowed!",
                type: 'error',
                showCancelButton: false,
                confirmButtonColor: '#ff5b5b !important',
                confirmButtonText: 'Ok'
            });
            return false;
        }
        
        
        if($('#paid').val() === ''){
            swal({
                title: 'Paid amount is not found',
                text: "Please check you entry!",
                type: 'error',
                showCancelButton: false,
                confirmButtonColor: '#ff5b5b !important',
                confirmButtonText: 'Ok'
            });
            return false;
        }
        
        
        var totalservicediscount=0;
        $('input[name=discount_by_service]').each(function(x) {
            var discount = $(this).val() === "" ? 0 : $(this).val();
            totalservicediscount=totalservicediscount+discount;
        });
        
        if($("#discount_pw").val()==='Y' && $("#passwordverified").val()==='No' && $("#txtloyalty").html()!='Loyalty' && $("#invoice_discount_type option:selected").val() == '' && (parseInt($("#txtdiscount").val())>0 || totalservicediscount>0 )){
            checkdiscountpw();
           
        }else{
        <?php if(null !== $this->session->userdata('allow_balance')){ ?>    
            
            <?php if($this->session->userdata('allow_balance')=='No'){ ?>    
                <?php if($this->session->userdata('role')!="Admin" && $this->session->userdata['role']!='Super User'){?>
                    if(parseInt($('#paid').val()) < parseInt($('#grandtotal').val())){

                    swal('Blocked','Balance Option is blocked by the Admin.','info');
                    return false;
                }
                <?php } ?>
            <?php } ?>
        <?php } ?>        
            if(parseInt($('#paid').val()) === 0 && parseInt($('#grandtotal').val()) > 0){

                swal({
                    title: '0 Paid Now?',
                    text: "Total Amount will be Balanced!",
                    type: 'warning',
                    showCancelButton: true,
                    confirmButtonColor: '#ff5b5b !important',
                    cancelButtonColor: '#d33',
                    cancelButtonText: 'No',
                    confirmButtonText: 'Yes'
                }, function(e) {
                    if(e===false){
                        return false;
                    } else if (e===true){
                       create_new_invoice();
                      //console.log('create');
                    }
                });
            } else if (parseInt($('#paid').val()) >= 0){
               create_new_invoice();   
               //console.log('create');
            }
        }
    }
    
    function checkdiscountpw(){
        $("#passwordverified").val('No');
        
        var totalservicediscount=0;
         $("select[name=discount_type]").each(function(x) {
            var temp = "discount_by_service";
            var row = x + 1;
            var elemname = temp + $(this).attr("service_id") + "_"+row;
            //console.log(elemname);
            
            if($(this).attr("perc")!=0){                
                var discount = $(elemname).val() === "" ? 0 : $(elemname).val();
                totalservicediscount=totalservicediscount+discount;
            }            
         });        
        
        
//        
//        $('input[name=discount_by_service]').each(function(x) {
//            var discount = $(this).val() === "" ? 0 : $(this).val();
//            totalservicediscount=totalservicediscount+discount;            
//        });
        
        if($("#discount_pw").val()==='Y' && (parseInt($("#txtdiscount").val())>0 || totalservicediscount>0)){
                swal({
                    title: "Password",
                    text: "Please Enter The Discount Password",
                    type: "input",
                    showCancelButton: true,
                    confirmButtonColor: '#ff5b5b !important',
                    cancelButtonColor: '#d33',
                    cancelButtonText: 'Cancel',
                    confirmButtonText: 'Submit'
                }, function (inputValue) {
                    if (inputValue === false ){ return false;}
                    if (inputValue === "") {
                        swal.showInputError("You need to write something!");
                        return false;
                    }
                    
                    var myinput='';
                    $.ajax({
                        url:'invoice_controller/checkdiscountpw',
                        data:{'mypassword': inputValue},
                        dataType:"text",
                        method:"POST",
                        async:false,
                        success:function(mymd5password){
                            myinput = mymd5password;
                        }
                    });
                    swal.close();
                    $("#discountpw_list > option").each(function(index, value){
                        //console.log('input ' + myinput+' option '+$(this).val())
                        if(myinput===$(this).val()){
                            $("#passwordverified").val('Yes');
                            swal('Verified','Click Invoice Button Again.','success');
                        }
                    });                    
                }); 
            
        } else {
            create_new_invoice();
        }
    }
    
    function create_new_invoice(){
            
        var totalServices = $('input[name=discount_by_service]').length;

        var service_membership = [];
        $('input[name=service_membership]').each(function(x) {
            var membership = $(this).val() === "" ? 0 : $(this).val();
            service_membership.push(parseFloat(membership));
        });

        var service_discount = []; 
        $('input[name=discount_by_service]').each(function(x) {
            var discount = $(this).val() === "" ? 0 : $(this).val();
            service_discount.push(parseFloat(discount));
            
        });
        
        var service_addition = [];
        $('input[name=addition_by_service]').each(function(x) {
            var addition = $(this).val() === "" ? 0 : $(this).val();
            service_addition.push(parseFloat(addition));
            
        });
        
        
        var discount_type = [];
        $('select[name=discount_type]').each(function(x) {
            discount_type.push($(this).val());
        });

        var discounted_price = [];
        $('input[name=orignal_service_rate]').each(function(x) {
            discounted_price.push((parseFloat($(this).val()) + parseFloat(service_addition[x])) - parseFloat(service_discount[x]));
            //console.log(discounted_price[x]);
        });
        
        var service_ids=[];
        $('input[name=service_ids]').each(function(x) {
            service_ids.push($(this).val());
        });
        
        
        var visit_service_ids=[];
        $('input[name=visit_service_ids]').each(function(x) {
            visit_service_ids.push($(this).val());
        });
        
        var visit_staff_ids=[];
        $('input[name=visit_service_ids]').each(function(x) {
            visit_staff_ids.push($(this).val());
        });
        
        
        var service_flag=[];
        $('input[name=service_flag]').each(function(x) {
            service_flag.push($(this).val());
        });
        
        var requested=[];
        $('input[name=requested]').each(function(x) {
            if($(this).is(":checked")){
                requested.push("Yes");
            } else {
                requested.push("No");
            }
        });

       
        var service_products=[];
        $('select[name=service_products]').each(function(x) {            
            service_products.push($(this).val());
            
        });


        var taxtotal=0;
        var instrument_number="";

        if($("#mode").html()==="Card"){
            if($("#ccno").val()===""){ toastr.warning('Enter Card Number!', 'Instrument number is mandatory'); return false;}else{instrument_number=$("#ccno").val();}
        } else if($("#mode").html()==="Check" || $("#mode").html()==="Loyalty" || $("#mode").html()==="Online"){ 
            if($("#checkno").val()===""){ toastr.warning('Enter Instrument Number!', 'Instrument number is mandatory'); return false;}else{instrument_number=$("#checkno").val();}
        } else if($("#mode").html()==="Voucher"){
            if($("#voucherno").val()==="" || $("#voucherno").val()==="0"){
                toastr.warning('Enter Voucher Number!', 'Voucher number is mandatory'); return false;
            } else{
                instrument_number='C'+$("#voucherno").val();
            }
        } else {
            instrument_number="";
        }


        if(enabtax===true){
            var taxarray = [];
            $( ".tax" ).each(function(index) {
                var taxname="#txttaxname"+index;
                taxarray.push({taxname: $(taxname).html(), tax: $(this).val()});
                taxtotal = taxtotal + parseFloat($(this).val());
                
            });
        }
       
        $('#btnsubmit').addClass('disabled');
        $('#btnsubmit').html('<i class="fa fa-spin fa-spinner"></i> Please wait');
        
        $.ajax({
            type: 'POST',
            url: 'invoice_controller/updateinvoice',
            asyn: false,
            data: {
                visitid: $("#visitid").val(),
                serviceids: service_ids,
                visitserviceids: visit_service_ids,
                service_flag: service_flag,
                invoicenumber:$("#invoicenumber").html(),
                invoicedate:$("#invoice_date").html(),
                customerid:$("#customerid").val(),
                customercell:$("#customercell").val(),
                
                org_subtotal:$("#txt_org_subtotal").val(),
                subtotal:$("#txtsubtotal").val(),
                discount:$("#txtdiscount").val(),
                discount_perc:$('#txtdiscountperc').val(),
                invoice_discount_type:$('#invoice_discount_type option:selected').val(),
                
                loyaltyenabled:$("#loyaltyenabled").val(),
                sloyaltyenabled:$("#sloyaltyenabled").val(),
                rloyaltyenabled:$("#rloyaltyenabled").val(),
                loyaltyused: $("#txtloyalty").html()=='Loyalty' ? $("#txtdiscount").val() : 0,
                loyaltyrate:$("#loyaltyrate").val(),
                loyaltyvalue:$("#loyaltyvalue").val(),
                grosstotal:$("#txtgross").val(),
                                
                paid:  parseFloat($('#paid').val()) > 0 ?  parseFloat($('#paid').val()) - parseFloat($('#returnamount').val()) : 0,
                //paid:  parseInt($('#paid').val()),
                cashpaid: parseFloat($("#cashpaid").val()),
                cardpaid: parseFloat($("#cardpaid").val()),
                grandtotal:$("#grandtotal").val(),
                roundedadjustment:$("#txtroundadj").val(),
                totalpayable:$("#txttotalpayable").val(),
                taxes:taxarray,
                taxtotal:taxtotal,
                mode: $("#input_payment_mode").val(),
                instrument_number: instrument_number,
                balance: $('#balanceamount').val(),
                
                uid: $('#uid').val(),
                uname: $('#uname').val(),
                uusername: $('#uusername').val(),
                uemail: $('#uemail').val(),
                
                discount_remarks: $("#ddiscount_remarks").val(),
                returnamount: $('#returnamount').val(),
                service_membership: service_membership,
                service_discount: service_discount,
                discount_type: discount_type,
                discounted_price: discounted_price,
                
                service_addition: service_addition,
                service_products: service_products,
                
                advance_amount:$('#txtadvance').val(),                
                other_charges: $('#txtothercharges').val(),
                customer_advance: $("#keepadv").prop('checked'),
                retained_used: $("#retainedused").val(),
                retained_amount_used: $("#retainedamountused").val(),
                remaining_retained: $("#remainingretained").val(),
                cctip: $("#txtcctip").val(),
                loyalty_sms: '<?php echo $business[0]['loyalty_sms'];?>',
                cc_charge: $("#txtcc_charge").val(),
                requested: requested,
                remarks: $("#txtremarks").val(),
                coupon: $("#txtcoupon").val(),
                invoice_extra: $("#visit_extra").val()
            },
            success: function(data) {
                console.log(data);
                var result = data.split("|");
                if (result[0] === "success") {
                    $("#txtinvoiceid").val(result[1]);
                    
                    if($("#mode").html() === "Voucher"){
                        if($("#voucherno").val() !== ""){
                            updateVoucher();
                        }
                    }
                    toastr.success('New Invoice Added!', 'Print the invoice');

                    //if receipts enabled
                    <?php if(isset($business[0]['receipts_installed'])){ if($business[0]['receipts_installed']=='Yes') { ?>
                        // console.log(result[2]);
                        // url = "https://wa.me/+92" + result[3] + "?text=" + "%22View%20your%20invoice%20here%22%20"+result[2];
                        
                        // window.open(url, 'wacall');

                    <?php }} ?>
                    
                    //testing
                    
                    var a = updateimsfiscal(result[1]); //check if imsfiscal pra is enabled
                    //var a = false;
                    if(a==false){       
                        //Now check if srb_fiscal is enabled

                        var b = checksrbfiscal(result[1]);
                        if(b==false){
                           window.location.href = '<?php echo base_url(); ?>existinginvoice/' + result[1];
                        }
                    }
                } else {
                    swal({
                        title: "Error",
                        text: result[1],
                        type: "error",
                        confirmButtonText: 'OK!'
                    });
                }

            }
        });

        $("#txtdiscount").attr("readonly",true);
        $("#txtdiscountperc").attr("readonly",true);
        $(".discount_by_service").attr("readonly",true);
        $(".perc_discount_service").attr("readonly",true);
        
    }
    
    function service_row_sum(){
        var theTotal = 0;
        $("table td:nth-child(11) .combat").each(function () {
            var val = $(this).text();//.replace(" ", "").replace(",-", "");
            theTotal += parseFloat(val);
        });

        $('#txtsubtotal').val(Math.round(theTotal*100)/100);
    }

    function original_row_sum(){
        
        var theTotal = 0; var additionalTotal = 0;
        
        $("table td:nth-child(12) input[name=orignal_service_rate]").each(function () {
            //console.log($(this).val());
            var val = $(this).val();//.replace(" ", "").replace(",-", "");
            theTotal += parseFloat(val);
        });
        $("table td:nth-child(10) .addition_by_service").each(function () {
            //console.log($(this).val());
            var val = $(this).val();//.replace(" ", "").replace(",-", "");
            additionalTotal += parseFloat(val);
        });
        
        $('#txt_org_subtotal').val(Math.round((theTotal + additionalTotal)*100)/100);
    }

    function sendsms(){
        $.ajax({
           type: 'POST',
           url: "<?php echo base_url() . 'sms_controller/send_sms'; ?>",
           data:{message: $('#msg').val(), phone:$('#phone').val()},
           dataType: "xml",
           cache: false,
           //async: true,
           success: function(data) {
               alert(data);
           }
       });
   }

    function perc_discount_service(discount, idservices) {
        console.log(idservices);
        
        //todo    
        //if(discount==0){return false;}
        var orignal_unitcost = parseFloat($('#orignal_service_rate' + idservices).val());
        var additional_cost = parseFloat($('#addition_by_service' + idservices).val());
        //orignal_unitcost = orignal_unitcost + additional_cost;
        console.log(additional_cost);
        if(additional_cost > 0){
            var temp = '#unitcost' + idservices + ' .combat';
            $(temp).html(orignal_unitcost.toFixed(2));
            orignal_unitcost = orignal_unitcost + additional_cost;
            original_row_sum();
        }
        
        
        if (discount === "") {
            $('#unitcost' + idservices).text(orignal_unitcost.toFixed(2));
            var temp = '#discount_by_service' + idservices;
            $(temp).val('');
            service_row_sum();
        } else {
            discount = (parseFloat(discount) * orignal_unitcost) / 100;
            discount = discount.toFixed(2);
            var temp = '#discount_by_service' + idservices;
            $(temp).val(Math.round(discount*100)/100);
        }


        discount_by_service(parseFloat(discount), idservices);

    }
    function discount_by_service(discount, idservices) {
        
        
        if($('#addition_by_service'+ idservices).val()==''){
            $('#addition_by_service'+ idservices).val('0');
        }
        var orignal_unitcost = parseFloat($('#orignal_service_rate' + idservices).val());
        
        var additional_cost = parseFloat($('#addition_by_service' + idservices).val());
        if(additional_cost >= 0){
            var temp = '#unitcost' + idservices + ' .combat';
            $(temp).html(orignal_unitcost.toFixed(2));
            orignal_unitcost = orignal_unitcost + additional_cost;
            original_row_sum();
        }
        
        // console.log(discount);
        // console.log(orignal_unitcost);
        if (discount === "") {
            $('#unitcost' + idservices).text(orignal_unitcost.toFixed(2));
            service_row_sum();
            var temp = '#perc_discount_service' + idservices;
            $(temp).val('');
        } else {
            discount = parseFloat(discount);
            var discount_rate = orignal_unitcost - discount;
            $('#unitcost' + idservices).text(discount_rate.toFixed(2));
            service_row_sum();
            if(discount>0){
                var perc_discount = (100 * discount) / orignal_unitcost;
            }else{ var perc_discount=0; }    
            perc_discount = perc_discount.toFixed(2);
            var temp = '#perc_discount_service' + idservices;
            $(temp).val(Math.round(perc_discount*100)/100);

        }
        //calcdiscount_perc();
        updatetotal();
//        var x = '#discount_type_' + idservices;
//        $(x).val('Normal');
    }
    
    function applycoupondiscount(){
        
        var couponnumber = $("#txtcoupon").val();
        
         $.ajax({
           type: 'POST',
           url: "<?php echo base_url() . 'coupon_controller/verify'; ?>",
           data:{coupon: couponnumber},
           dataType: "json",
           cache: false,
           //async: true,
           success: function(data) {
             
                var coupon = data.coupondetails;
                var services = data.couponservices;
                // console.log(coupon);
                if(coupon!==null){
                    
                
                    if(coupon['coupon_type']=='service'){
                        $("#txtdiscountperc").val(0);
                        $("#txtdiscountperc").change();
                        
                        for(a=0; a<services.length; a++){
                            $('input[name=perc_discount_service]').each(function(y) {
                                if($(this).attr('service_id')==services[a]){
                                    console.log('fount');
                                    servicefound=true;
                                    $(this).val(coupon['discount_perc']);
                                    $(this).blur();
                                    $(this).attr('readonly','readonly');
                                    $('#txtcoupon').attr('readonly','readonly');
                                    var row = y+1;
                                    perc_discount_service(coupon['discount_perc'], services[a]+'_'+row);
                                }
                            });

                            $('select[name=discount_type]').each(function(y) {
                                if($(this).attr('service_id')==services[a]){
                                    var o = new Option(coupon['coupon_number'], coupon['coupon_number']);
                                    $(this).append(o);
                                    $("option:contains("+ coupon['coupon_number'] +")", this).attr('selected', 'selected');
                                    $(this).attr('readonly','readonly');
                                    $('#txtcoupon').attr('readonly','readonly');
                                }
                            }); 
                            
                        }
                       
                    } else {
                        $("#txtdiscountperc").val(coupon['discount_perc']);
                        $("#txtdiscountperc").change();
                        
                        var o = new Option(coupon['coupon_number'], coupon['coupon_number']);
                        $("#invoice_discount_type").append(o);
                        $("option:contains("+ coupon['coupon_number'] +")", '#invoice_discount_type').attr('selected', 'selected');
                        
                        $('#txtdiscountperc').attr('readonly','readonly');
                        $('#txtdiscount').attr('readonly','readonly');
                        $("#invoice_discount_type").attr('readonly','readonly');
                        $('#txtcoupon').attr('readonly','readonly');
                    }
                    
                } else {
                    swal({
                        title: "Coupon Not Found",
                        text: "This coupon is Expired or is not valid",
                        type: "info",
                        confirmButtonText: 'OK!'
                    });
                }
               
           }
       });
     
    }
    
    
    function addremark(){
        
        var newhtml = "<li onclick='$(this).remove();'>"+$("#txtwork option:selected").val()+ " were " +  $("#txtfor").val() + " with " + $("#txtremarktype option:selected").text() + " " + $("#txtremarktypenumber").val() + " for " + $("#txtremarktime").val() + " min " + $("#txtlength option:selected").text() + "</li>";
                
        $("#colorremarkslist").append( newhtml);
        
    }
   
   function opencolor(){
       $('#addlist').modal({
                    backgroun:'static',
                    keyboard:true,
                    show:true
                });
    }
   
   
   function openeyelash(){
       $('#addeyelashrecord').modal({
                    backgroun:'static',
                    keyboard:true,
                    show:true
                });
    }
    
    
   function openfacial(){
       $('#addfacial').modal({
                    backgroun:'static',
                    keyboard:false,
                    show:true
                });
    }
    
    function rootsoptionchecked(){
        $x=1;
        var rootoptions=[];
        $('#rootsul li').each(function() {
            if($x==1){
                var checked = $(this).find("input[name='rootscheckbox']").prop('checked');
                
                var var1 = $(this).find("select[name='workdone'] option:selected").val();
                var var2 = $(this).find("select[name='colortype'] option:selected").val();
                var var3 = $(this).find("select[name='colornumber'] option:selected").val();
                var var4 = $(this).find("select[name='time'] option:selected").val();
                if(checked==true){
                    var result = 'Roots were '+var1+' with '+var2+' '+ var3 + ' for '+var4+' mins.';
                    rootoptions.push(result);
                }
                
            }
            
            if($x==2){
                var checked = $(this).find("input[name='rootscheckbox']").prop('checked');
                var var1 = $(this).find("select[name='workdone'] option:selected").val();
                var var2 = $(this).find("select[name='colortype'] option:selected").val();
                var var3 = $(this).find("select[name='colornumber'] option:selected").val();
                var var4 = $(this).find("select[name='time'] option:selected").val();
                var var5 = $(this).find("select[name='colortype1'] option:selected").val();
                var var6 = $(this).find("select[name='colornumber1'] option:selected").val();
                var var7 = $(this).find("select[name='time1'] option:selected").val();
                
                if(checked==true){
                    var result = 'Roots were '+var1+' with '+var2+' '+var3+' for '+var4+' mins and the Length were glossed with '+var5+' '+var6 +' for '+ var7 + ' mins.';
                    rootoptions.push(result);
                }
                
            }
            
            if($x==3){
                var checked = $(this).find("input[name='rootscheckbox']").prop('checked');
                var var1 = $(this).find("select[name='workdone'] option:selected").val();
                var var2 = $(this).find("select[name='colortype'] option:selected").val();
                var var3 = $(this).find("select[name='colornumber'] option:selected").val();
                var var4 = $(this).find("select[name='time'] option:selected").val();
                var var5 = $(this).find("select[name='time1'] option:selected").val();                
                
                if(checked==true){
                    var result = 'Fullhead was '+var1+' with '+var2+' ' +var3 +' for '+var4+' mins in the roots and '+var5+' min through the length';
                    rootoptions.push(result);
                }
                
            }
            
            if($x==4){
                var checked = $(this).find("input[name='rootscheckbox']").prop('checked');
                var var1 = $(this).find("select[name='workdone'] option:selected").val();
                var var2 = $(this).find("select[name='colortype'] option:selected").val();
                var var3 = $(this).find("select[name='colornumber'] option:selected").val();
                var var4 = $(this).find("select[name='time'] option:selected").val();
                
                if(checked==true){
                    var result = 'Braids were '+var1+' '+var2+' with '+var3+' for '+var4+' mins.';
                    rootoptions.push(result);
                }
                
            }
            
            $x++; 
        });
        return rootoptions;
    }
    
    function lightsoptionchecked(){
        $x=1;
        var lightsoptions=[];
        $('#lightsul li').each(function() {
            if($x==1){
                var checked = $(this).find("input[name='lightscheckbox']").prop('checked');
                var var1 = $(this).find("select[name='colornumber'] option:selected").val();                
                if(checked==true){
                    var result = 'Lights were Pre-lightened with '+var1+' vol.';
                    lightsoptions.push(result);
                }
                
            }
            
            if($x==2){
                var checked = $(this).find("input[name='lightscheckbox']").prop('checked');
                
                var var1 = $(this).find("select[name='colornumber'] option:selected").val();
                var var2 = $(this).find("select[name='time'] option:selected").val();
                
                if(checked==true){
                    var result = 'Lights were Toned with '+var1+' for '+var2+' mins throughtout.';
                    lightsoptions.push(result);
                }
                
            }
            
            if($x==3){
                var checked = $(this).find("input[name='lightscheckbox']").prop('checked');
                
                var var1 = $(this).find("select[name='colornumber'] option:selected").val();
                var var2 = $(this).find("select[name='colornumber1'] option:selected").val();
                var var3 = $(this).find("select[name='time'] option:selected").val();
                if(checked==true){
                    var result = 'Lights were Toned with '+var1+' in the roots and '+var2+' through the length for '+var3+' mins.';
                    lightsoptions.push(result);
                }
                
            }
            
            if($x==4){
                var checked = $(this).find("input[name='lightscheckbox']").prop('checked');
                               
                if(checked==true){
                    var result = 'Smart Bond';
                    lightsoptions.push(result);
                }
                
            }
            if($x==5){
                var checked = $(this).find("input[name='lightscheckbox']").prop('checked');
                               
                if(checked==true){
                    var result = 'Color Correction';
                    lightsoptions.push(result);
                }
                
            }
            if($x==6){
                var checked = $(this).find("input[name='lightscheckbox']").prop('checked');
                               
                if(checked==true){
                    var result = 'Double Application';
                    lightsoptions.push(result);
                }
                
            }
            if($x==7){
                var checked = $(this).find("input[name='lightscheckbox']").prop('checked');
                               
                if(checked==true){
                    var result = 'Open Foils';
                    lightsoptions.push(result);
                }
                
            }
            
            $x++; 
        });
        return lightsoptions;
    }
    
    
    
    
    function updateimsfiscal(invoiceid){
        var check = "";
        check = '<?php if(isset($business[0]['imsfiscal'])){ if($business[0]['imsfiscal']=='Yes'){ echo "true";}}?>';
        console.log("pra" + check);
        if(check==="true"){
            $.ajax({
                type: 'POST',
                url: '<?php echo base_url();?>getimsjson',
                data: {csrf_test_name: '', invoiceid:invoiceid, invoicetype:1},
                asyn: false,
                success: function(data) {
                    //console.log(data);
                    data = $.parseJSON(data);
                    var mJson = data.mJson;
                    var imsdetails = data.imsdetails;
                    
                    runimsfiscalupdate(mJson, invoiceid, imsdetails);
                }
            });
        } else {
            return false;
        }
               
    }
    
    function runimsfiscalupdate(data, invoiceid, imsdetails){     
        var url = imsdetails.ims_url;
        var token = imsdetails.ims_token;
        var local = imsdetails.ims_local;
        var username = 'skedwise';
        var password = 'rest1234';
        
        var mData  = $.parseJSON(data);
       
         $.ajax({
            type: 'POST',
            //url: 'http://localhost:8524/api/IMSFiscal/GetInvoiceNumberByModel',
            url: url,
            contentType: "application/json",
            asyn: false,
            beforeSend: function (xhr) {
                xhr.setRequestHeader ("Authorization", "Bearer " + token);
            },            
            //data: {myJSON: data, url: url, token: token},
            data: data,
            success: function(response) {
                console.log(response);
               //response= $.parseJSON(response);
               
               toastr.success(response.Response, 'Fiscal');
                //update the log tables
                updateimslog(data, response.InvoiceNumber, invoiceid);
                
            }
        });
    }
    
    function updateimslog(data, invoicenumber, invoiceid){
        console.log(data, invoicenumber, invoiceid);
     
        $.ajax({
            type: 'POST',
            url: 'imsfiscal_controller/imsfiscal_update_log',
            data: {data, invoicenumber: invoicenumber, invoiceid: invoiceid},
            asyn: false,
            success: function(response) {                
                toastr.success(response, 'FISCAL Log'); 
                
                window.location.href = '<?php echo base_url(); ?>existinginvoice/' + invoiceid;
            }
        });        
    }

   



    function runimsfiscalupdate(data, invoiceid, imsdetails){
      
                
     var url = imsdetails.ims_url;
     var token = imsdetails.ims_token;
     var local = imsdetails.ims_local;
     var username = 'skedwise';
     var password = 'rest1234';
     
     var mData  = $.parseJSON(data);
    
      $.ajax({
         type: 'POST',
         //url: 'http://localhost:8524/api/IMSFiscal/GetInvoiceNumberByModel',
         url: url,
         contentType: "application/json",
         asyn: false,
         beforeSend: function (xhr) {
             xhr.setRequestHeader ("Authorization", "Bearer " + token);
         },            
         //data: {myJSON: data, url: url, token: token},
         data: data,
         success: function(response) {
            console.log(response);
            //resp = $.parseJSON(response);
            
            toastr.success(response, 'Fiscal');
             //update the log tables
             updateimslog(data, response.InvoiceNumber, invoiceid);
             
         }
     });
 }



 function checksrbfiscal(invoiceid){
        var check = "";
        check = '<?php if(isset($business[0]['srb_fiscal_service'])){ if($business[0]['srb_fiscal_service']=='Yes'){ echo "true";}}?>';
        console.log('srb' + check);
        if(check==="true"){
            $.ajax({
                type: 'POST',
                url: '<?php echo base_url();?>imsfiscal_controller/getsrbjson',
                data: {csrf_test_name: '', invoiceid:invoiceid, invoicetype:1},
                asyn: false,
                success: function(data) {
                    //console.log(data);
                    data = $.parseJSON(data);
                    var mJson = data.mJson;
                    var imsdetails = data.imsdetails;
                    
                    console.log(mJson);
                    runsrbfiscalupdate(mJson, invoiceid, imsdetails);
                }
            });
        } else {
            return false;
        }               
    }

    function runsrbfiscalupdate(data, invoiceid, imsdetails){
        var url = imsdetails.ims_url;
        var pos_user = imsdetails.pos_user;
        var pos_pass = imsdetails.pos_pass;
                
       // var mData  = $.parseJSON(data);
       
         $.ajax({
            type: 'POST',        
            url: url,
            contentType: "application/json",
            asyn: false,
            // beforeSend: function (xhr) {
            //     xhr.setRequestHeader ("Authorization", "Bearer " + token);
            // },            
            //data: {myJSON: data, url: url, token: token},
            data: data,
            success: function(response) {
                console.log(response);
               //var resp = $.parseJSON(response);
               
               toastr.success(response.msg, 'Fiscal');
                //update the log tables
                updatesrblog(data, response.srbInvoceId, invoiceid);
                
            }
        });
    }

    function updatesrblog(data, invoicenumber, invoiceid){
        console.log(data, invoicenumber, invoiceid);
     
        $.ajax({
            type: 'POST',
            url: 'imsfiscal_controller/srbfiscal_update_log',
            data: {data, invoicenumber: invoicenumber, invoiceid: invoiceid},
            asyn: false,
            success: function(response) {                
                toastr.success(response, 'FISCAL Log'); 
                
                window.location.href = '<?php echo base_url(); ?>existinginvoice/' + invoiceid;
            }
        });


    }

    
    function removeservice(vsid, vsname){
        
            //var vsname = $(this).attr('visit_service_name');
            swal({
                title: 'Remove Serivce',
                text: "Are you sure you want to remove (" + vsname + ")?",
                type: 'warning',
                showCancelButton: true,
                confirmButtonColor: '#ff5b5b !important',
                cancelButtonColor: '#d33',
                cancelButtonText: 'No',
                confirmButtonText: 'Yes'
            }, function() {
                $.ajax({
                    //url: 'Scheduler_controller/cancelVisitService',
                    url: "<?php echo base_url() . 'Scheduler_controller/cancelVisitService'; ?>",
                    //data: 'visit_service_id=' +vsid,
                    data: {
                        visit_service_id: vsid
                    },
                    type: 'POST',
                    success: function(response) {
                        if (response === "success") {
                            
                            toastr.success('Service removed!', 'Done!');
                            location.reload();
                            // $('#calendar').fullCalendar('refetchEvents');
                        } else if (response === "one_service") {
                           // cancelVisit();
                            swal({
                                title: "please use 'CANCLE VISIT' option",
                                text: "This is the only service in the visit.",
                                type: "error",
                                confirmButtonText: 'OK!'
                            });
                        }
                    }
                });
            });
    }


    function calculate_discount(id_business_services, x, service_rate){
        console.log('discount_reason changed');
        var additional_elem = "#addition_by_service"+id_business_services+"_"+x;
        var this_elem = "#discount_by_service"+id_business_services+"_"+x;

        $(additional_elem).val('0'); 
        
        
        if(this.value > service_rate || this.value==''){
            $(this_elem).val('0');
        }
        
        discount_by_service($(this_elem).val(), id_business_services+"_"+x); 

    }



    <?php if(defined('RECEIPTS_INSTALLED')){
        if(RECEIPTS_INSTALLED == true){ ?> 

            function getreceiptjson(invoiceid, flag){
                console.log('getreceiptjson:')
                var url = '<?php echo base_url();?>ReceiptsAPI/receiptsjson_retail';
                if(flag=='service'){ url = '<?php echo base_url();?>ReceiptsAPI/receiptsjson_service';}

                $.ajax({
                    type: 'POST',
                    url: url,
                    data: {invoiceid:invoiceid},            
                    asyn: false,
                    success: function(data) {
                        console.log(data);
                    // data = $.parseJSON(data);
                        // var mJson = data.mJson;
                        sendreceiptdata(invoiceid, data);
                    }
                });
            }

            function sendreceiptdata(invoiceid, data, token){
                var url = 'https://receipt.mexyon.com/insert-receipt';  
                var mData  = $.parseJSON(data);

                //var token = "bWV4eW9ucmVjZWlwdEBnbWFpbC5jb206YWRtaW4xMjM="; //mexyon
                var token = "cGVuZ3JlY2VpcHRAZ21haWwuY29tOnBlbmcxMjM="; //pengs

                $.ajax({
                    url: "https://receipt.mexyon.com/insert-receipt",
                    method: "POST",
                    data: data,
                    type: "json",
                    async: false,
                    contentType: "application/json",
                    beforeSend: function (xhr) {
                        xhr.setRequestHeader ("Authorization", "Basic " + token);                
                    },         
                    success: function(response) {               
                    console.log(response.message);
                    var r=response.message;
                    var code = response.receipt_code;
                    var url = response.receipt_url;                
                        
                        if(r  === 'Data inserted successfully'){
                            console.log('receitpapi success ' + url);
                            updateslipcode(url, code, invoiceid);
                            //window.open(url);
                        } else {
                            console.log('receitpapi fail: ' + response);
                        }                
                    },
                    error: function(err){
                        console.log(err);
                    }
                });

            }

            function updateslipcode(url, code, invoiceid){

                $.ajax({
                    type: 'POST',
                    url: '<?php echo base_url();?>invoice_controller/updateslipcode',
                    data: {
                        invoiceid : invoiceid,
                        receipt_code : code,
                        receipt_url : url
                    },
                    async: false,
                    success: function(data) {
                        var result = data.split("|");
                        if (result[0] === "success") {
                            swal("Success", "Rceipt Code updated", "success");
                            
                        } else {
                            swal("Error", "Receipt Code not sent", "error");
                        }
                    } 
                });

            }
        <?php }
    } ?>


    
</script>
