<?php session_start();
include ('../inc/dbcon.php');
include ('../inc/functions.php');
if(isset($_SESSION["axeslogin"]) && $_SESSION["axeslogin"] == true){
$_SESSION['cuPages']='sel_sinvcteate.php';   
$cuPage='sel_poscreate.php';    
$aid=$_SESSION['uid'];
$brid=$_SESSION['abrid'];    
}else{
header('Location:../index.php');
exit;    
}
$mhead='sales';
$menuh='Sales';
$phead='poscreate';
$page='POS';
$dtnow = date("Y-m-d h:i:s", time());
?>
<?php
include('../layout/head.php');
?>

<section class="content-header" >
<h1><?php echo $page;?><?php if(isset($exdata)){echo '<span style="color:Blue;"> ( Invoice No: '.$exdata.' )</span>';}?></h1>
<ol class="breadcrumb">
<li><a href="home.php" ><i class="fa fa-dashboard"></i><?php if($mhead!='home'){if(get_fild_data('tbl_setting','1','sval')==0){echo 'Dashboard';}else{echo 'ড্যাশবোর্ড';}}else{if(get_fild_data('tbl_setting','1','sval')==0){echo 'Home';}else{echo 'বাড়ী';}}?></a></li>
<?php if($mhead!='home'){?>    
<li><a href="<?php echo $_SESSION['cuPages'];?>"><?php echo $menuh;?></a></li>
<li class=""><a href="#" ><?php echo $page;?></a></li>
<?php } ?>
</ol>
</section>
<!-- Main content -->
<section class="content" >
<div class="addsersales">   
<div class="parent" style="height: 308px;">
    <div class="left leftopen" id="left">
        <div  style="width: calc(100% - 25px);">    
            <div class="box box-solid" id="pdpanel" style="display: block;">
                <div class="box-body">
                    <div class="col-md-12">
                        <div class="row">
                            <div class="col-md-12">   
                                <div class="form-group">  
                                    <div class="input-group">
                                        <span class="input-group-addon"><span class="fa fa-search"></span></span>
                                        <input type="text" class="form-control" name="search" id="search" placeholder="e.g. Product Code or Name" autocomplete="off">    
                                    </div>
                                </div>   
                            </div>   
                        </div>
                        <div class="row">
                            <div class="product-panel style-2" id="purchaseitem">

                            </div>
                        </div>
                        <div class="row">
                            <br>   
                            <div class="col-md-4">
                                <div class="form-group">
                                <label>Ref</label>
                                <input type="text" maxlength="25" class="form-control" name="ref" id="ref" placeholder="e.g. #ORD8976453" autocomplete="off">    
                                </div>
                                <div class="form-group">
                                <label>Sales Person</label>    
                                <select class="form-control select2" name="selp" id="selp">
                                <option value="">-Select-</option>    
                                <?php
                                $sql="SELECT id,name FROM tbl_employe ORDER BY name ASC";    
                                $querys=mysqli_query($con,$sql)or die(mysqli_error($con));
                                while ($rows=mysqli_fetch_array($querys)){
                                ?>
                                <option value="<?php echo $rows['id'];?>"><?php echo $rows['name'];?></option>
                                <?php } ?>
                                </select>    
                                </div>    
                            </div>
                            <div class="col-md-8">    
                                <div class="form-group">    
                                <label>Note</label>
                                <textarea class="form-control" name="note" id="note" maxlength="150" rows="5" placeholder="Invoice Note"></textarea>    
                                </div>    
                            </div>    
                            </div>
                    </div>    
                </div>
            </div>
            <div class="slide"><div class="vertical-text text-center">PRODUCT PANEL<span class="arrow vertical-text "></span></div></div>
        </div>
    </div>
    <div class="right rightopen" id="right">
        <div class="box box-solid">
            <div class="box-body">
                <div class="col-md-12">
                    <div class="row">
                        <div class="col-md-9">
                            <div class="form-group">
                                <div class="input-group">
                                    <span class="input-group-addon"><span class="fa fa-user-o"></span></span>
                                    <span class="input-group-addon"><a data-toggle="collapse" data-target="#walkcus" class="accordion-toggle" id="walkin" style="cursor: pointer;">Walk-In</a></span>   
                                    <input type="text" class="form-control" id="cusname" value="" placeholder="Type Customer Code, Name Or Mobile No..." autocomplete="off" />
                                    <span class="input-group-addon"><a id="addcus" style="cursor: pointer;"><span class="fa fa-plus"></span></a></span>    
                                </div>
                                <input type="hidden" name="cusid" id="cusid" class="form-control" value="" readOnly />    
                            </div>    
                        </div>
                        <div class="col-md-3"><span style="font-size: 18px;color: red;font-weight: bold;">Bal.: </span><span style="font-size: 18px;color: blue;font-weight: bold;" id="cusbal">0.00</span></div>    
                    </div>
                    <div class="row">   
                        <div class="accordian-body collapse" id="walkcus">
                            <div class="col-md-6">    
                                <div class="form-group">
                                    <div class="input-group">
                                        <span class="input-group-addon"><span class="fa fa-id-card-o"></span></span>    
                                        <input type="text" id="walkname" name="walkname"  maxlength="35" class="form-control" value="Walk-In Customer" placeholder="Customer Name" autocomplete="off">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label>Select District</label>
                                    <select class="form-control select2" name="wdid" id="wdid" onchange="getAllSubwgroup(this.value)">
                                        <option value="">-Select-</option>
                                        <?php									
                                        $querys=mysqli_query($con,"SELECT * FROM tbl_district ORDER BY name ASC")or die(mysqli_error($con));
                                        while ($rows=mysqli_fetch_array($querys)){
                                        ?>
                                        <option value="<?php echo $rows['id'];?>"><?php echo $rows['name'];?></option>
                                        <?php } ?>
                                    </select>    
                                </div>
                                <div class="form-group">
                                    <label>Email</label>
                                    <input type="text" name="wemail" maxlength="50" value="" id="wemail" class="form-control" placeholder="e.g. info@axesgl.com"/>   
                                </div>    

                            </div>
                            <div class="col-md-6">     
                                <div class="form-group">
                                    <div class="input-group">
                                        <span class="input-group-addon"><span class="fa fa-mobile"></span></span>    
                                        <input type="text" id="walkmobile" name="walkmobile" maxlength="18" class="form-control" value="" placeholder="e.g. 016167xx7x" autocomplete="off">
                                    </div>
                                </div>
                                <input type="hidden" name="addsales" readonly />
                                <div class="form-group">
                                    <label>Select Zone</label>
                                    <select class="form-control select2" name="wzid" id="wzid">
                                        <option value="">-Select-</option>    
                                    </select>     
                                </div>
                                <div class="form-group">
                                    <label>Address</label>
                                    <input type="text" name="wadd" maxlength="250" value="" id="wadd" class="form-control" placeholder="e.g. B-323, Khilgaon"/>   
                                </div>    
                            </div>    
                        </div>    
                    </div>     
                    <div class="row">
                        <div class="col-md-8">
                            <div class="form-group">  
                                <div class="input-group">
                                    <span class="input-group-addon"><span class="fa fa-search"></span></span>
                                    <input type="text" class="form-control" id="pcode" placeholder="e.g. Product Code or Name" autocomplete="off">   <span class="input-group-addon"><a id="addpro" style="cursor: pointer;"><span class="fa fa-plus"></span></a></span>  
                                </div>
                            </div>       
                        </div>
                        <div class="col-md-4">
                            <div class="form-group">  
                                <div class="input-group">
                                    <span class="input-group-addon"><span class="fa fa-barcode"></span></span>
                                    <input type="text" class="form-control" id="bcode" placeholder="e.g. Barcode" autocomplete="off">   
                                </div>
                            </div>
                        </div>       
                    </div>
                    
                    <div class="row">
                    <div class="cart cart-sm">     
                        <table class="table table-bordered table-striped" style="margin-bottom: 0;">
                            <thead>
                                <th width="30px">SN</th>
                                <th width="214px">Item</th>
                                <th width="72px">Qty</th>
                                <th width="72px">Price</th>
                                <th width="35px">ASL</th>    
                                <th width="77px">SubTotal</th>
                                <th width="25px"><a class="empty" style="cursor: pointer;"><i class="fa fa-trash"></i></a></th>    
                            </thead>
                        </table>
                        <div class="cart-msg style-3 item" style="padding:0px;"> 
                           <div class="invhold scrol-y" id="invhold" style="height: 400px;">     
                            <table class="table table-bordered table-striped" style="margin-bottom: 0;">    
                                <tbody id="itemdata">

                                </tbody>    
                            </table>
                           </div>
                        </div>
                        <table class="table table-bordered table-striped" style="margin-bottom: 0;">
                            <tfoot id="itemfoot">

                            </tfoot>
                        </table>    
                    </div>    
                </div>
                    
                    <!-- <div class="row" id="serialpro">
                        
                        
                    </div>     -->
                
                    <div class="row" id="extra">
                    
                    </div>  
                    <input type="hidden" maxlength="35" class="form-control" name="chbid" id="chbid" value="" >
                    <input type="hidden" maxlength="35" class="form-control" name="caid" id="caid" value="">
                    <input type="hidden" maxlength="35" class="form-control" name="mobid" id="mobid" value="">
                    <input type="hidden" maxlength="20" class="form-control" name="chkno" id="chkno" value="" >
                    <input type="hidden" class="form-control" name="baid" id="baid" value="" >
                    <input type="hidden" class="form-control" name="chkdt" id="chkdt" value="" >
                    <input type="hidden" maxlength="35" class="form-control" name="caname" id="caname" value="" >
                    <input type="hidden" maxlength="20" class="form-control" name="trxid" id="trxid" value="">
                    <input type="hidden" name="pname" id="pname" maxlength="35" class="form-control" >
                    <input type="hidden" name="dipname" id="dipname" maxlength="35" class="form-control" >
                    <input type="hidden" name="paddress" id="paddress" maxlength="35" class="form-control" >
                    <input type="hidden" name="otclient" id="otclient" maxlength="35" class="form-control" >
                    <input type="hidden" name="otmobile" id="otmobile" maxlength="35" class="form-control" >
                </div> 
                
            </div>
        </div>
    </div>
</div>
</div>
    
<div class="rotate btn-cat-con">
<button type="button" id="open-brands" class="btn btn-info open-brands" tabindex="-1">Brands</button>
<button type="button" id="open-subcategory" class="btn btn-warning open-subcategory" tabindex="-1">Sub Categories</button>
<button type="button" id="open-category" class="btn btn-primary open-category" tabindex="-1">Categories</button>
</div>
    
<div id="brands-slider">
<div class="row">
<div class="col-md-2"></div>
<div class="col-md-8">
<div class="form-group">
<div class="input-group">
<span class="input-group-addon"><span class="fa fa-search"></span></span>    
<input type="text" class="form-control form-control-lg" id="searchbrands" placeholder="Search by Name" autocomplete="off">
</div>
</div>
</div>    
</div>
<div class="col-md-2"></div>
<div id="brands-list" class="ps-container style-2">
<button id="brand_0" type="button" value="0" class="btn-prni brand" tabindex="-1"><img src="../img/product/no_image.png" class="img-rounded img-thumbnail"><span>ALL Brands</span></button>
<?php
$sql="SELECT tbl_brstock.brnid AS id,tbl_brand.name FROM tbl_brstock  LEFT JOIN tbl_brand ON tbl_brand.id=tbl_brstock.brnid WHERE tbl_brstock.brnid IS NOT NULL GROUP BY tbl_brstock.brnid ORDER BY tbl_brand.name ASC";	
$query=mysqli_query($con,$sql)or die(mysqli_error($con));
while ($rowc=mysqli_fetch_array($query)){
$id=$rowc['id'];
?>
<button id="brand_<?php echo $rowc['id']?>" type="button" value="<?php echo $rowc['id']?>" class="btn-prni brand" tabindex="-1"><img src="../img/product/<?php if(empty($rowc['image']) || $rowc['image']==''){echo 'no_image.png';}else{echo $rowc['image'];}?>" class="img-rounded img-thumbnail"><span class="bname"><?php echo $rowc['name']?></span></button>    
<?php } ?>
<div class="ps-scrollbar-x-rail" style="width: 0px; display: none; left: 0px; bottom: 3px;"><div class="ps-scrollbar-x" style="left: 0px; width: 0px;"></div></div><div class="ps-scrollbar-y-rail" style="top: 0px; height: 0px; display: none; right: 3px;"><div class="ps-scrollbar-y" style="top: 0px; height: 0px;"></div></div>
</div>
</div>

<div id="category-slider">
<div class="row">
<div class="col-md-2"></div>
<div class="col-md-8">
<div class="form-group">
<div class="input-group">
<span class="input-group-addon"><span class="fa fa-search"></span></span>     
<input type="text" class="form-control form-control-lg" id="searchcategory" placeholder="Search by Name" autocomplete="off">
</div>
</div>
</div>   
<div class="col-md-2"></div>
</div>
<div id="category-list" class="ps-container style-2">
<button id="category_0" type="button" value="0" class="btn-prni category" tabindex="-1"><img src="../img/product/<?php if(empty($rowc['image']) || $rowc['image']==''){echo 'no_image.png';}else{echo $rowc['image'];}?>" class="img-rounded img-thumbnail"><span>All Categories</span></button>
<?php
$sql="SELECT tbl_brstock.catid AS id,tbl_category.name FROM tbl_brstock  LEFT JOIN tbl_category ON tbl_category.id=tbl_brstock.catid WHERE tbl_brstock.catid IS NOT NULL GROUP BY tbl_brstock.catid ORDER BY tbl_category.name ASC";	

$query=mysqli_query($con,$sql)or die(mysqli_error($con));
while ($rowc=mysqli_fetch_array($query)){
$id=$rowc['id'];
?>
<button id="category_<?php echo $rowc['id']?>" type="button" value="<?php echo $rowc['id']?>" class="btn-prni category" tabindex="-1"><img src="../img/product/<?php if(empty($rowc['image']) || $rowc['image']==''){echo 'no_image.png';}else{echo $rowc['image'];}?>" class="img-rounded img-thumbnail"><span class="cname"><?php echo $rowc['name']?></span></button>    
<?php } ?>
<div class="ps-scrollbar-x-rail" style="width: 0px; display: none; left: 0px; bottom: 3px;"><div class="ps-scrollbar-x" style="left: 0px; width: 0px;"></div></div><div class="ps-scrollbar-y-rail" style="top: 0px; height: 0px; display: none; right: 3px;"><div class="ps-scrollbar-y" style="top: 0px; height: 0px;"></div></div>
</div>
</div>

<div id="subcategory-slider">
<div class="row">
<div class="col-md-2"></div>
<div class="col-md-8">
<div class="form-group">
<div class="input-group">
<span class="input-group-addon"><span class="fa fa-search"></span></span>     
<input type="text" class="form-control form-control-lg" id="searchsubcategory" placeholder="Search by Name" autocomplete="off">
</div>
</div>   
</div>
<div class="col-md-2"></div>
</div>
<div id="subcategory" class="ps-container style-2">
    
</div>
</div>

<!-- Same Barcode Mutiproduct -->
<div id="saleBarcode" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="global-modal-title">Fill the product's options</h4>
</div>
<div class="modal-body color-black" id="posProductOptions">
<div class="form-group"> <label class="control-label">Purchase Batch</label>
<div id="multipro">

</div>
</div>
<input type="hidden" name="emn" id="emn" value="" readonly />
<button type="button" id="cart_product" class="form-control btn-primary"><span class="hidden-xs hidden-sm hidden-md">Add to Cart</span> <i class="icon-cart-add2"></i></button>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-info" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<!--end same barcode-->    
    
<?php include('../layout/quick.php');?>    
</section>
<!-- /.main content -->
<?php include('../layout/rside.php'); ?>
<?php include('../layout/checkout.php'); ?>
<div id="invdata" style="display: none;"></div>     
</div>
<?php if(get_fild_data('tbl_setting','8','sval')==0){?>
<?php require_once('axe_chat.php');?>
<?php } ?>
<?php require_once('axe_glsearch.php');?>
<?php include('../layout/rfree.php'); ?> 

<?php include('../layout/page_default.php'); ?>
</div>
<!-- ./wrapper -->
<script src="../js/jquery.min.js"></script>
<script src="../js/bootstrap.min.js"></script>
<script src="../js/jquery-ui.min.js"></script>
<script src="../js/bootstrap-datepicker.js?V=1.0"></script>
<script src="../plugins/checkedit/ckeditor.js"></script>
<script src="../js/bootbox.min.js"></script>
<script src="../plugins/piker/spectrum.js"></script>
<script src="../plugins/datatable/jquery.dataTables.js"></script>
<script src="../plugins/datatable/dataTables.bootstrap.js"></script>
<script src="../plugins/treetable/js/jquery.treetable.js"></script>
<script src="../plugins/select/select2.js"></script>
<script src="../js/axes.js?V=1.0"></script>
<script src="../js/common.js?V=1.0"></script>
<script src="../js/jquery.PrintArea.js"></script>
<script src="../js/axes-scanner.js"></script>
<script src="../js/parsley.js"></script>
<script src="../plugins/notify/notify.js"></script>
<script src="../plugins/list/list.min.js"></script>
<script src="../plugins/list/list.pagination.min.js"></script>
<script src="../plugins/toastr/toastr.min.js"></script>
<script src="../plugins/tinymce/js/tinymce/tinymce.min.js"></script>
<script src="../plugins/livevalidation/live_validation.js"></script>

<?php if(get_fild_data('tbl_setting','8','sval')==0){?>
<script type="text/javascript">
var siteurl = '';
var chatmod = '<?php if(isset($_SESSION['chatmod'])){echo $_SESSION['chatmod'];}else{echo 'off';} ?>';
var chat;
var chatlist;    
var session_uname = '<?php echo $_SESSION['uid']; ?>';
var session_img = '<?php echo $_SESSION['uimage']; ?>';
</script>
<!-- Media Uploader -->
<script type="text/javascript" src="../chat/smiley/js/emojione.min.js"></script>
<script type="text/javascript" src="../chat/smiley/smiley.js"></script>
<script type="text/javascript" src="../chat/chatjs/lightbox.js"></script>
<script type="text/javascript" src="../chat/chatjs/chat.js"></script>
<script type="text/javascript" src="../chat/chatjs/custom.js"></script>
<script type="text/javascript" src="../chat/uploader/plupload.full.min.js"></script>
<script type="text/javascript" src="../chat/uploader/jquery.ui.plupload/jquery.ui.plupload.js"></script>
<?php } ?> 
<script type="text/javascript">
var AXES_PAGE_TITLE = document.title;
$(document).ready(function () {

$('body').on("click", ".notifi_delete", function () {
delete_notification(this, 1);
});
$('body').on("click", ".notifi_clear_all", function () {
delete_notification(this, 2);
});

$('body').on("click", ".notifications-menu .dropdown-menu", function (e) {
e.stopPropagation();
});
$('.notifications-menu').on('show.bs.dropdown', function () {
$(this).find('.dropdown-menu').first().stop(true, true).slideDown();
});
$('.notifications-menu').on('hide.bs.dropdown', function () {
$(this).find('.dropdown-menu').first().stop(true, true).slideUp();
});

$('body').on("click", ".delete_confirm", function () {
var msg = $(this).data("msg");
var url = $(this).prop('href');

confirmbox(msg, url);
return false;
});
$('body').on("click", ".popup", function () {
popup(this);
return false;
});

$("#modal-default").on("hidden.bs.modal", function () {
var callback = $('#callback').val();
if (callback)
excecute_callback(callback);
$('#callback').val('');
});

check_window_is_child();
        
toggle_sidebar_menu();
    
document.getElementById('modal_default_iframe').onload = function () {
$('.holds-the-iframe .modal-body').addClass('hideBg');
};

$("#txtMenuEval").keypress(function(e) {
if(e.which == 13) {
var result = eval($('#txtMenuEval').val());
result = parseFloat(result);
$('#txtMenuEvalResult').val( result.toFixed(2) );
// $('#txtEvalResult').text().toFixed(2);

}
});

$("#txtMenuEval").focus(function () {
$(this).select();
});    
    
});
    
setTimeout(function() {
$('#mymsg').fadeOut('fast');
$.ajax({
url: 'msg.php',
type: 'post',
data: {shows:1},
//dataType: 'json',
success:function(data) {
}
});    
}, 3000); // <-- time in milliseconds


function toggle_sidebar_menu_call(){
    
}
    
function check_window_is_child() {
if (window.self !== window.top) {
//$('.main-header,.main-sidebar,.main-footer').hide();
//$('.content-wrapper, .main-footer').css({'margin-left': '0'});
//$('.skin-purple .wrapper, .skin-purple .main-sidebar, .skin-purple .left-side').css({'background-color': '#ecf0f5'});
} else {
           
}   
} 

$(document).bind("keyup keydown", function(e) {
if (e.ctrlKey && e.keyCode == 80) {
var isPrint = document.getElementsByClassName('printableArea');
if (typeof(isPrint) != 'undefined' && isPrint != null){    
var mode = 'iframe'; //popup
var close = mode == "popup";
var options = {
mode: mode,
popClose: close
};    
$("div.printableArea").printArea(options);          
return false;
}else{
return false;    
}
}    
});    
    
function popup(obj) {
$('.holds-the-iframe .modal-body').removeClass('hideBg');
var modal_title = $(obj).data('title');
$('#modal-default .modal-title').text(modal_title);
$('#modal-default .modal-body iframe').prop('src', '');
$('#modal-default .modal-body iframe').contents().find("body").html("");
var urllink = $(obj).prop('href');
$('#modal_default_iframe').hide();
$('#modal-default .modal-body iframe').prop('src', urllink);
var callback = $(obj).data("callback");
$('#callback').val(callback);
$("#modal-default").modal();
setTimeout(function () {
$('#modal_default_iframe').show();

}, 1500);
return false;
}
    
function popup_open(data) {
$('.holds-the-iframe .modal-body').removeClass('hideBg');
$('#modal-default .modal-body iframe').prop('src', '');
$('#modal-default .modal-body iframe').contents().find("body").html("");
$('#modal_default_iframe').hide();

$('#modal-default .modal-body iframe').prop('src', data['src']);
$('#modal-default .modal-title').text(data['title']);
$('#callback').val(data['callback']);
$("#modal-default").modal();
setTimeout(function () {
$('#modal_default_iframe').show();

}, 1500);

}

function toaster(msg) {
$('.modal-msg .modal-body').html(msg);
$('.modal-msg').modal({backdrop: 'static', keyboard: false});
}
   
function toaster2(msg, url) {
$('.modal-msg .modal-msg-url').text('');
if (url)
$('.modal-msg .modal-msg-url').text(url);
$('.modal-msg .modal-body').html(msg);
$('.modal-msg').modal({backdrop: 'static', keyboard: false});
}
    
function close_toaster() {
try {
var modal_msg_url = $('.modal-msg .modal-msg-url').text();

$('.modal-msg').modal('hide');
if (modal_msg_url && modal_msg_url != '' && modal_msg_url != null) {
window.location.href = modal_msg_url;
}
} catch (exception) {
alert(exception);
}

}
    
function confirmbox(msg, url, obj) {
if (obj) {
url = $('.modal-confirm #urlpath').val();
if (url && url != 'undefined') {
window.location = url;
}
} else {

$('.modal-confirm .modal-body p').text(msg);
$('.modal-confirm #urlpath').val(url);
$('.modal-confirm').modal({backdrop: 'static', keyboard: false});
}
}
    
var myFunction = function () {
window.focus();
};

function toggle_sidebar_menu(key)
{
if (key == 1) {
$('.sidebar-mini').addClass('sidebar-collapse');
} else {
$('.sidebar-mini').removeClass('sidebar-collapse');
}
}
    
function CheckEmailVal(email, check_val) {
try {
var result = true;
if (email) {
email = email.split(",");
for (var i = 0; i < email.length; i++) {
var expr = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,8}|[0-9]{1,3})(\]?)$/;
result = expr.test(email[i]);
}

} else if (check_val > 0 && !email) {
var result = false;
}
return result;
} catch (exception) {
return false;
}

}


function excecute_callback(callback) {
switch (callback) {
case 'refresh_dashboard':
refresh_dashboard();
break;
default:
break;
}
}
    
function isNumberKey(evt){
var charCode = (evt.which) ? evt.which : evt.keyCode
if (charCode != 46 && charCode > 31 && (charCode < 48 || charCode > 57))
return false;
return true;
}
    
$('.datetimepicker').datepicker({format: "yyyy-mm-dd", autoclose: true, clearBtn: true, orientation: 'auto bottom'});    
/* Select2 Init*/
$(".select2").select2();

<?php 
$parray = array('porcreate','pinvcreate','precreate','sescreate','sinvcreate','srecreate','bratra','whotra'); 
if(strlen(array_search($phead,$parray))<1){
?>    
//Barcode
var bscode='';    
$(document).scannerDetection({
timeBeforeScanTest: 200, 
//startChar: [120],
endChar: [13],
avgTimeByChar: 30,
onComplete: function(barcode,event){ 
bscode = barcode;   
$.ajax({
url: 'axe_globalview.php',
method: "POST",
data:{sbcode: bscode},
success: function(data){
var foundSomething = false;
for(var i=0; i<data.length; ++i) {
if(data[i] !== null) foundSomething = true;
break;
}    
if(foundSomething){
$('#datacon').html(data);   
$('.right-side-free').toggle('slide', { direction: 'right' }, 300);
}
}
});    
},
onKeyDetect: function(event){
if(event.keyCode === 13 || event.keyCode === 17 || event.keyCode === 74 ){
if (event.target.tagName == "INPUT" || event.target.tagName == "TEXTAREA") {
if(bscode.length>1){
event.preventDefault();    
}    
}else{
event.preventDefault();    
}  
}
}
});   
<?php } ?>

$(document).on('keydown', '#glsearch', function() {
$('#glsearch' ).autocomplete({
source: function( request, response ) {
$.ajax({
url: 'axe_cart.php',
type: 'post',
dataType: 'json',
data: {
search: request.term,glsearch:1
},
success: function(data) {
response(data);
}
});
},
select: function (event, ui) {
var te='';
$(this).val(te); // display the selected text
var glval = ui.item.value; // selected id to input

$.ajax({
url: 'axe_globalview.php',
method: "POST",
data:{sbcode: glval},
success: function(data){
var foundSomething = false;
for(var i=0; i<data.length; ++i) {
if(data[i] !== null) foundSomething = true;
break;
}    
if(foundSomething){
$('#datacon').html(data);   
$('.right-side-free').toggle('slide', { direction: 'right' }, 300);
}
}
});
return false;
}
});    
});   

$(document).on('click', '#glbox', function() {
if($('.glslide').hasClass('glslide-open')){
$('.glslide').removeClass('glslide-open');
$('#prodetails').html('');    
}else{
$('.glslide').addClass('glslide-open');     
}        
}); 
    
<?php if(get_fild_data('tbl_setting','8','sval')==0){?>

$(document).on('click', '#kchat', function() {
if($('.kchatslide').hasClass('kchatslide-open')){
$('.kchatslide').removeClass('kchatslide-open');    
}else{
$('.kchatslide').addClass('kchatslide-open');     
}        
});
    
$(document).on('change', '#chaton', function () {
var chkid = 0;	
$('#chaton').not(this).prop('checked', false);
if ($('#chaton').is(":checked")){
chkid = 1;
}else{
chkid = 0;	
}

$.ajax({
url: 'axe_chatcart.php',
method: "POST",
data: {
check: chkid
},
dataType: 'json',    
success: function(data) {
chatmod=data.status;
if(chatmod==='on'){
chatclientlist();    
startChatSession();   
}else{
for (i=0;i<chatBoxes.length;i++) {
chatboxtitle = chatBoxes[i];
closeChatBox(chatboxtitle);    
}
clearTimeout(chatlist);
$('#chat_list').html('');    
clearTimeout(chat);
}    
}
});
});
<?php } ?>    

$(document).on('click', '#glprosearch', function () {
var gdata = $('#gltextsearch').val();
if(gdata == '') return;
    
$.ajax({
url: 'axe_cart.php',
method: "POST",
data: {
proserarch:1, serdata: gdata
},   
success: function(data) {
$('#prodetails').html(data);    
}
});
    
}); 
    
$(document).on('click', '#closefree', function() {    
$('#datacon').html('');
if($('.right-side-free').is(':visible')) {
$('.right-side-free').toggle('slide', { direction: 'right' }, 300);
}    
});    
</script>
<?php if(isset($print)){ ?>
<script type="text/javascript">

$("#print").click(function() {    
var mode = 'iframe'; //popup
var close = mode == "popup";
var options = {
mode: mode,
popClose: close
};
$("div.printableArea").printArea(options);
});
    
function pagelist(){    
var perPage = 10;

new List("test-list", {
valueNames: ["pino","name"],
page: perPage,
plugins: [

ListPagination({
paginationClass: "pagination-layout",
left: 2,
right: 2
})
]
}).on("updated", function(list) {
var isFirst = list.i == 1;
var isLast = list.i > list.matchingItems.length - list.page;

// make the Prev and Nex buttons disabled on first and last pages accordingly
$(".pagination-prev.disabled, .pagination-next.disabled").removeClass(
"disabled"
);
if (isFirst) {
$(".pagination-prev").addClass("disabled");
}
if (isLast) {
$(".pagination-next").addClass("disabled");
}

// hide pagination if there one or less pages to show
if (list.matchingItems.length <= perPage) {
$(".pagination-wrap").hide();
} else {
$(".pagination-wrap").show();
}
});
}
    
$(".pagination-next").click(function(e) {
$(".pagination-layout .active")
.next()
.trigger("click");
e.preventDefault();    
});
    
$(".pagination-prev").click(function(e) {
$(".pagination-layout .active")
.prev()
.trigger("click");
e.preventDefault();    
});    
    
$("#print").click(function() {    
var mode = 'iframe'; //popup
var close = mode == "popup";
var options = {
mode: mode,
popClose: close
};
$("div.printableArea").printArea(options);
});    
        
function setPrinterConfig(){
resolution = $('#resolution').val()!=undefined?$('#resolution').val():"A4";
rotate = $('#rotate').val()!=undefined?$('#rotate').val():"portrait";

$('.page').removeClass('A2 A4 A5 Letter Legal');
$('.page').addClass(resolution);
$('.page').removeClass('portrait landscape');
$('.page').addClass(rotate);

w = "21cm"; h = "29.7cm";
if( resolution == "A4" ){
w = "21cm"; h = "29.7cm";     
}else if( resolution == "A5" ){
w = "14.8cm"; h = "21cm";
}else if( resolution == "Letter" ){
w = "21.6cm"; h = "27.9cm";
}else if( resolution == "Legal" ){
w = "21.6cm"; h = "35.6cm";
}
if( rotate == "landscape" ){
$('#pageInit').html("@page{size: "+h+" "+w+"}");
}else{
$('#pageInit').html("@page{size: "+w+" "+h+"}");
}
scaleTemplate();
};

function getPageHeight(){
resolution = $('#resolution').val()!=undefined?$('#resolution').val():"A4";
rotate = $('#rotate').val()!=undefined?$('#rotate').val():"portrait";

w = 21; h = 29.7;
if( resolution == "A4" ){
w = 21; h = 29.7;      
}else if( resolution == "A5" ){
w = 14.8; h = 21;
}else if( resolution == "Letter" ){
w = 21.6; h = 27.9;
}else if( resolution == "Legal" ){
w = 21.6; h = 35.6;
}
if( rotate == "landscape" ){
return w;
}else{
return h;
}
};

function getPageWidth(){
resolution = $('#resolution').val()!=undefined?$('#resolution').val():"A4";
rotate = $('#rotate').val()!=undefined?$('#rotate').val():"portrait";

w = 21; h = 29.7;
if( resolution == "A4" ){
w = 21; h = 29.7;      
}else if( resolution == "A5" ){
w = 14.8; h = 21;
}else if( resolution == "Letter" ){
w = 21.6; h = 27.9;
}else if( resolution == "Legal" ){
w = 21.6; h = 35.6;
}
if( rotate == "landscape" ){
return h;
}else{
return w;
}
};

function scaleTemplate(){
$.each($('[id=wrap_invoice]'), function(i, wrap_invoice){
var scale = 1;
if( $(wrap_invoice).parent().is(".wrapper") ){
$(wrap_invoice).unwrap();
}
var parent = $(wrap_invoice).parent();
var padding = $(parent).outerWidth()-$(parent).width();
var outer_height = $(parent).height();
var inner_height = $(wrap_invoice).outerHeight();
var outer_width = $(parent).width();
var inner_width = $(wrap_invoice).outerWidth();
if( outer_width < inner_width ){
if( padding == 0 ){
scale = parseFloat(outer_width/(inner_width+20));
padding = 20;
}else{
scale = parseFloat(outer_width/inner_width);
padding = 0;
}
var x = padding/2;
var origin = x.toFixed(2)+"px 0px 0px";
$(wrap_invoice).css({'-webkit-transform': 'scale('+(scale.toFixed(2))+')', '-webkit-transform-origin': origin});
var wrapper = $("<div class='wrapper'></div>");
$(wrapper).css({'width': inner_width*scale, 'height': inner_height*scale, "overflow": "hidden"});
$(wrap_invoice).wrap(wrapper);
}else{
$(wrap_invoice).css({'-webkit-transform': '', '-webkit-transform-origin': ""});
}
});
};

document.table_border = false;
document.table_strip = false;
document.table_border = true;
document.table_strip = true;

$(document).ready(function(){
$('#wrap_invoice table').removeClass();
$('#wrap_invoice table').addClass('table_invoice table_invoice-condensed');

$('#wrap_invoice table').addClass('table_invoice-bordered');
  
$('#wrap_invoice table').addClass('table_invoice-striped');
  
  

setPrinterConfig();
$('body').on('keyup', function(ev){
if( ev.keyCode == 27 ){
$('#close_page').click();
}
});

$('#close_page').click(function(){
window.close();
window.parent.window.close();
return false;
});
window.onresize = function() {
scaleTemplate();
}
scaleTemplate();
});
    
setTimeout(function() {
$(window).trigger("resize");
}, 100);
    
function sethead(){
var maxh = 0;
var ahe = $("#adheight").height();
var ihe = $("#inheight").height();

if(ahe>ihe){
maxh=ahe;   
}else{
maxh=ihe;    
}
if(maxh>ahe){
 $("#adheight").height(maxh);    
}else if(maxh>ihe){
 $("#inheight").height(maxh);        
}    
};
sethead();    
</script>
<?php } ?>


<!-- page script -->
<script type="text/javascript">
$(document).on('click', '.slide', function () {    
if ($("#left").hasClass("leftopen")) {
$("#pdpanel").fadeOut(700, function() {
$("#pdpanel").css("display", "none");
});    
$("#left").removeClass("leftopen");
$("#right").removeClass("rightopen");
$("#left").addClass("leftclose");
$("#right").addClass("rightexpand");
$(".arrow").addClass("active");
panel_status(0);    
}else{
$("#left").removeClass("leftclose");
$("#right").removeClass("rightexpand");    
$("#left").addClass("leftopen");
$("#right").addClass("rightopen");
$("#pdpanel").fadeIn(700, function() {
$("#pdpanel").css("display", "block");
});
$(".arrow").removeClass("active");
panel_status(1);    
}
ReadItem();    
});    

function panel_status(sval){
$.ajax({
url: "arc_cart.php",
method: "POST",
data:{ 
purpan:1, skey:'PURPAN', sval:sval
},
success: function(data){

}
});    
}    
    
$(function(){
var divHeight = $(".parent").height();    
$('.parent').css({ height: $(window).innerHeight()-150 });
$('.product-panel').css({ height: $('.parent').innerHeight()-118 });    
$(window).resize(function(){
$('.parent').css({ height: $(window).innerHeight()-150 });
$('.product-panel').css({ height: $('.parent').innerHeight()-118 });    
});
});       
    
ReadItem();
    
function ReadItem() {
$.ajax({
url: "sel_item.php",
method: "POST",
success: function(data) {
$('#purchaseitem').html(data);
}
})
}

ReadData();
function ReadData(){
$.ajax({
url: "sel_posview.php",
method: "POST",
data:{ 
body:1
},
success: function(data){
$('#itemdata').html(data);
}
})

$.ajax({
url: "sel_posview.php",
method: "POST",
data:{ 
foot:1
},
success: function(data){
$('#itemfoot').html(data);
}
})
ReadButon();    
ReadIMEI();    
};    

function ReadFoot(){
$.ajax({
url: "sel_posview.php",
method: "POST",
data:{ 
foot:1
},
success: function(data){
$('#itemfoot').html(data);
}
})	
}    

function ReadButon(){
$.ajax({
url: "sel_posview.php",
method: "POST",
data:{ 
buton:1
},
success: function(data){
$('#extra').html(data);
}
})	
}     
    
function ReadIMEI() {
$.ajax({
url: "sel_serialview.php",
method: "POST",
success: function(data) {
$('#serialpro').html(data);
}
})
}    

$(document).on('keyup', '#search', function () {    
var search = $("#search").on('input',function(){
var matcher = new RegExp($(this).val(), 'i');

$('.selitem').show().not(function(){
return matcher.test($(this).find('.name, .sku').text())
}).hide();
}); 
});
    
$(document).on('click', '.alphabets a', function () {
si=$(this).data('id');
var matcher = new RegExp(si, 'i');

$('.selitem').show().not(function(){
return matcher.test($(this).find('.indexg').text())
}).hide();   
});

$(document).on('keyup', '#searchcategory', function () {
var search = $("#searchcategory").on('input',function(){
var matcher = new RegExp($(this).val(), 'i');

$('.category').show().not(function(){
return matcher.test($(this).find('.cname').text())
}).hide();
})
});

$(document).on('keyup', '#searchsubcategory', function () {
var search = $("#searchsubcategory").on('input',function(){
var matcher = new RegExp($(this).val(), 'i');

$('.subcat').show().not(function(){
return matcher.test($(this).find('.sname').text())
}).hide();
})
});

$(document).on('keyup', '#searchbrands', function () {
var search = $("#searchbrands").on('input',function(){
var matcher = new RegExp($(this).val(), 'i');

$('.brand').show().not(function(){
return matcher.test($(this).find('.bname').text())
}).hide();
})
});

$(".open-brands").click(function () {
$('#brands-slider').toggle('slide', { direction: 'right' }, 700);
});
$(".open-category").click(function () {
$('#category-slider').toggle('slide', { direction: 'right' }, 700);
});
$(".open-subcategory").click(function () {
$('#subcategory-slider').toggle('slide', { direction: 'right' }, 700);
});
    
$(document).on('click', function(e){
if (!$(e.target).is(".open-brands, .cat-child") && !$(e.target).parents("#brands-slider").length && $('#brands-slider').is(':visible')) {
$('#brands-slider').toggle('slide', { direction: 'right' }, 700);
}
if (!$(e.target).is(".open-category, .cat-child") && !$(e.target).parents("#category-slider").length && $('#category-slider').is(':visible')) {
$('#category-slider').toggle('slide', { direction: 'right' }, 700);
}
if (!$(e.target).is(".open-subcategory, .cat-child") && !$(e.target).parents("#subcategory-slider").length && $('#subcategory-slider').is(':visible')) {
$('#subcategory-slider').toggle('slide', { direction: 'right' }, 700);
}
if (!$(e.target).is(".right-side-add, .side-cont") && !$(e.target).parents(".right-side-add").length && $('.right-side-add').hasClass('open-right-add')) {
if($('.right-side-add').is(':visible')) { $('.right-side-add').toggle('slide', { direction: 'right' }, 300); }
$('#addsitem').html('');
}    
});

$(document).on('click', '.category', function () {
id_arr = $(this).attr('id');
id = id_arr.split("_");
var ids = id[1];
$.ajax({
url: 'sel_item.php',
method: "POST",
data:{ 
catid: ids
},
success: function(data){
$('#purchaseitem').html(data);
}
});
    
$.ajax({
url: 'sel_subcat.php',
method: "POST",
data:{ 
catid: ids
},
success: function(data){
$('#subcategory').html(data);
}
});    
});
    
$(document).on('click', '.subcat', function () {
sid_arr = $(this).attr('id');
sid = sid_arr.split("_");    
var scid = sid[1];
$.ajax({
url: 'sel_item.php',
method: "POST",
data:{ 
subcatid: scid
},
success: function(data){
$('#purchaseitem').html(data);
}
});    
});
    
$(document).on('click', '.brand', function () {
sid_arr = $(this).attr('id');
sid = sid_arr.split("_");    
var brid = sid[1];
$.ajax({
url: 'sel_item.php',
method: "POST",
data:{ 
brandid: brid
},
success: function(data){
$('#purchaseitem').html(data);
}
});    
});
    
$(document).on('click', '#icon', function() {
if(!$("#icon").hasClass('cart-icon-rotate')){
$("#icon").addClass('cart-icon-rotate');
$(".cart tr.dshow").toggle();
}else{
$("#icon").removeClass('cart-icon-rotate');	
$(".cart tr.dshow").hide();
}	
});

$(document).on('click', '.selitem', function () {    
var id = $(this).attr('id');
pid_arr = $(this).attr('id');
unid = pid_arr.split("_");    
var unqid = unid[1];    
$.ajax({
url: 'sel_poscart.php',
method: "POST",
data:{ 
additem: unqid
},
success: function(data){
ReadData();
}
});    
});

$(document).on('keydown', '#pcode', function () {
$('#pcode' ).autocomplete({
source: function( request, response ) {
$.ajax({
url: 'sel_poscart.php',
type: 'post',
dataType: 'json',
data: {
search: request.term,itmsear:1
},
success: function(data) {
response(data);
}
});
},
select: function (event, ui) {
var te='';
$(this).val(te); // display the selected text
var unqid = ui.item.value; // selected id to input

$.ajax({
url: 'sel_poscart.php',
type: 'post',
data: {additem:unqid},
success:function(response){
ReadData();
}
});
return false;
}
});        
});    

$(document).on('keydown', '#bcode', function() {    
$('#bcode' ).autocomplete({
source: function( request, response ) {
$.ajax({
url: 'sel_poscart.php',
type: 'post',
dataType: 'json',
data: {
search: request.term,tyserial:1
},
success: function(data) {
response(data);
}
});
},
select: function (event, ui) {
var te='';
$(this).val(te); // display the selected text
var unqid = ui.item.value; // selected id to input
var serial = ui.item.label;    
$.ajax({
url: 'sel_poscart.php',
type: 'post',
data: {addslitem:unqid, serial:serial},
success:function(response){
ReadData();
}
});

return false;
}
});
});    
    
$(document).on('click', '.remove', function () {
var id = $(this).attr('id');
$.ajax({
url: 'sel_poscart.php',
method: "POST",
data:{ 
remove: id
},
success: function(data){
ReadData();
}
});    
});

//barcode 
var bscode='';   
$(document).scannerDetection({
timeBeforeScanTest: 200,
//startChar: [120],
endChar: [13],
avgTimeByChar: 30,
onComplete: function(barcode,event){
bscode='';    
bscode = barcode; 
$('#bcode').val(bscode);
$.ajax({
url: 'sel_poscart.php',
method: "POST",
data:{ 
scanbarcode: bscode , qty: 1
},
dataType: 'json',    
success: function(data){
if(data.status==='fail'){
toastr.error(data.message);
}else if(data.status==='exits'){
toastr.info(data.message);
ReadData();    
}else if(data.status==='invno'){    
viewinvoice(data.invoice);
}else if(data.status==='success'){     
ReadData();
toastr.success(data.message);
}else if(data.status==='multi'){
$('#multipro').html(data.html);
$('#saleBarcode').modal('show');    
}
}
});      
},
onKeyDetect: function(event){
if(event.keyCode === 13 || event.keyCode === 17 || event.keyCode === 74 ){
if (event.target.tagName == "INPUT" || event.target.tagName == "TEXTAREA") {
if(bscode.length>1){
event.preventDefault();    
}    
}else{
event.preventDefault();    
}    
} 
}   
});    

function myFunctions(prorbuton) {
document.getElementById("emn").value = prorbuton;
}    

$(document).on('click', '#cart_product', function () {
var enm = $('#emn').val();   
$.ajax({
url: 'sel_poscart.php',
method: "POST",
data:{ 
additem: enm
},
success: function(data){
$('#saleBarcode').modal('hide');
ReadData();
}
});    
});    
    
function viewinvoice(invno){
$.ajax({
url: 'axe_globalview.php',
method: "POST",
data:{sbcode: invno},
success: function(data){
var foundSomething = false;
for(var i=0; i<data.length; ++i) {
if(data[i] !== null) foundSomething = true;
break;
}    
if(foundSomething){
$('#datacon').html(data);   
$('.right-side-free').toggle('slide', { direction: 'right' }, 300);
}
}
});    
}    
    
$(document).on('blur', '.quantity', function() {
id_arr = $(this).attr('id');
id = id_arr.split("_");
var ids = id[1];
var qty = parseFloat($('#qty_'+id[1]).val());
$.ajax({
url: 'sel_poscart.php',
method: "POST",
data:{ 
upqty: ids, qty: qty
},
dataType: 'json',
success: function(data){
$('#qty_'+id[1]).val(data[0]);
$('#price_'+id[1]).val(data[1]);    
$('#stotal_'+id[1]).html(data[2]);
$('#pnote_'+id[1]).val(data[3]);    
$('#disp_'+id[1]).val(data[4]);
$('#disf_'+id[1]).val(data[5]);
$('#disamo_'+id[1]).html(data[6]);        
ReadFoot();
ReadIMEI();    
}
});     
});

$(document).on('blur', '.price', function() {
id_arr = $(this).attr('id');
id = id_arr.split("_");
var ids = id[1];
var amo = parseFloat($('#price_'+id[1]).val());
$.ajax({
url: 'sel_poscart.php',
method: "POST",
data:{ 
upprice: ids, amo: amo
},
dataType: 'json',
success: function(data){
$('#qty_'+id[1]).val(data[0]);
$('#price_'+id[1]).val(data[1]);    
$('#stotal_'+id[1]).html(data[2]);
$('#pnote_'+id[1]).val(data[3]);    
$('#disp_'+id[1]).val(data[4]);
$('#disf_'+id[1]).val(data[5]);
$('#disamo_'+id[1]).html(data[6]); 
ReadFoot();
}
});     
});

$(document).on('change', '.bscan', function () {
id_arr = $(this).attr('id');
id = id_arr.split("_");
var ids = id[1];
var chkid = 0;	
$('.bscan').not(this).prop('checked', false);
if ($('.bscan').is(":checked")){
chkid = 1;
}else{
chkid = 0;	
}

$.ajax({
url: 'sel_poscart.php',
method: "POST",
data: {
check: chkid, pid:ids
},
success: function(data) {

}
});

});    
    
$(document).on('blur', '.pnote', function() {
id_arr = $(this).attr('id');
id = id_arr.split("_");
var ids = id[1];
var ref = $('#pnote_'+id[1]).val();  
$.ajax({
url: 'sel_poscart.php',
method: "POST",
data:{ 
upnote: ids, note: ref
},
dataType: 'json',
success: function(data){
$('#qty_'+id[1]).val(data[0]);
$('#price_'+id[1]).val(data[1]);    
$('#stotal_'+id[1]).html(data[2]);
$('#pnote_'+id[1]).val(data[3]);    
$('#disp_'+id[1]).val(data[4]);
$('#disf_'+id[1]).val(data[5]);
$('#disamo_'+id[1]).html(data[6]); 
ReadFoot();
}
});     
});

$(document).on('blur', '.wday', function() {
id_arr = $(this).attr('id');
id = id_arr.split("_");
var ids = id[1];
var wdays = $('#wday_'+id[1]).val();  
$.ajax({
url: 'sel_poscart.php',
method: "POST",
data:{ 
upwday: ids, wdays: wdays
},
dataType: 'json',
success: function(data){
$('#qty_'+id[1]).val(data[0]);
$('#price_'+id[1]).val(data[1]);    
$('#stotal_'+id[1]).html(data[2]);
$('#pnote_'+id[1]).val(data[3]);    
$('#disp_'+id[1]).val(data[4]);
$('#disf_'+id[1]).val(data[5]);
$('#disamo_'+id[1]).html(data[6]); 
$('#wday_'+id[1]).html(data[7]); 
ReadFoot();
}
});     
});
    
$(document).on('blur', '.disp', function() {
id_arr = $(this).attr('id');
id = id_arr.split("_");
var ids = id[1];
var dic = parseFloat($('#disp_' + id[1]).val());
$.ajax({
url: 'sel_poscart.php',
method: "POST",
data: {
itemdisp: ids,
disp: dic
},
dataType: 'json',
success: function(data) {
$('#qty_'+id[1]).val(data[0]);
$('#price_'+id[1]).val(data[1]);    
$('#stotal_'+id[1]).html(data[2]);
$('#pnote_'+id[1]).val(data[3]);    
$('#disp_'+id[1]).val(data[4]);
$('#disf_'+id[1]).val(data[5]);
$('#disamo_'+id[1]).html(data[6]);
ReadFoot();
}
});
});
    
$(document).on('blur', '.disf', function() {
id_arr = $(this).attr('id');
id = id_arr.split("_");
var ids = id[1];
var dica = parseFloat($('#disf_' + id[1]).val());
$.ajax({
url: 'sel_poscart.php',
method: "POST",
data: {
itemdisf: ids,
disf: dica
},
dataType: 'json',
success: function(data) {
$('#qty_'+id[1]).val(data[0]);
$('#price_'+id[1]).val(data[1]);    
$('#stotal_'+id[1]).html(data[2]);
$('#pnote_'+id[1]).val(data[3]);    
$('#disp_'+id[1]).val(data[4]);
$('#disf_'+id[1]).val(data[5]);
$('#disamo_'+id[1]).html(data[6]);
ReadFoot();
}
});
});
    
function get_foot(){
$.ajax({
url: 'sel_poscart.php',
method: "POST",
data: {
foot: 1
},
dataType: 'json',
success: function(data) {	
$('#discount').val((Math.round(data[0] * 100) / 100).toFixed(2));
$('#disitems').html('<strong>'+(Math.round(data[1] * 100) / 100).toFixed(2)+'</strong>');
if(parseFloat((Math.round(data[2] * 100) / 100).toFixed(2))>0){
$('#totdisamo').html('<strong>'+(Math.round(data[2] * 100) / 100).toFixed(2)+'</strong>');
}
    
$('#vatp').val((Math.round(data[3] * 100) / 100).toFixed(2));
$('#vatamo').html('<strong>'+(Math.round(data[4] * 100) / 100).toFixed(2)+'</strong>');

$('#aitp').val((Math.round(data[5] * 100) / 100).toFixed(2));
$('#aitamo').html('<strong>'+(Math.round(data[6] * 100) / 100).toFixed(2)+'</strong>');
        
$('#otdname').html('<strong>'+data[7]+'</strong>');
$('#others').val((Math.round(data[8] * 100) / 100).toFixed(2));
$('#othersamo').html('<strong>'+(Math.round(data[8] * 100) / 100).toFixed(2)+'</strong>');
    
$('#otame').html(data[7]);

$('#freight').val((Math.round(data[9] * 100) / 100).toFixed(2));
$('#freightd').html('<strong>'+(Math.round(data[9] * 100) / 100).toFixed(2)+'</strong>');
$('#less').val((Math.round(data[10] * 100) / 100).toFixed(2));
$('#lessd').html('<strong>'+(Math.round(data[10] * 100) / 100).toFixed(2)+'</strong>');
$('#grtotal').html('<strong>'+(Math.round(data[11] * 100) / 100).toFixed(2)+'</strong>');
}
});	
}
    
$(document).on('blur', '#discount', function() {
var disp = parseFloat($('#discount').val());
$.ajax({
url: 'sel_poscart.php',
method: "POST",
data: {
seldis: disp
},
success: function(data) {
get_foot();
}
});
});
    
$(document).on('blur', '#vatp', function() {
var vatp = parseFloat($('#vatp').val());
$.ajax({
url: 'sel_poscart.php',
method: "POST",
data: {
selvat: vatp
},
success: function(data) {
get_foot();
}
});
});
    
$(document).on('blur', '#aitp', function() {
var aitp = parseFloat($('#aitp').val());
$.ajax({
url: 'sel_poscart.php',
method: "POST",
data: {
seltax: aitp
},
success: function(data) {
get_foot();
}
});
});
    
$(document).on('blur', '#others', function() {
var others = parseFloat($('#others').val());
$.ajax({
url: 'sel_poscart.php',
method: "POST",
data: {
others: others
},
success: function(data) {
get_foot();
}
});
});

$(document).on('blur', '#otname', function() {
var otname = $('#otname').val();
$.ajax({
url: 'sel_poscart.php',
method: "POST",
data: {
otname: otname
},
success: function(data) {
get_foot();
}
});
});
    
$(document).on('blur', '#freight', function() {
var frei = parseFloat($('#freight').val());
$.ajax({
url: 'sel_poscart.php',
method: "POST",
data: {
freight: frei
},
success: function(data) {
get_foot();
}
});
});				
				
$(document).on('blur', '#less', function() {
var less = parseFloat($('#less').val());
$.ajax({
url: 'sel_poscart.php',
method: "POST",
data: {
less: less
},
success: function(data) {
get_foot();
}
});
});
    
$(document).on('click', '.slremove', function () {
var id = $(this).attr('id');
$.ajax({
url: 'sel_poscart.php',
method: "POST",
data:{ 
removeitmsl: id
},
success: function(data){
ReadData();
}
});    
});
    
$(document).on('blur', '.imei', function() {
id_arr = $(this).attr('id');
id = id_arr.split("_");
var ids = id[1];
var imei = $('#imei_'+id[1]).val();
$.ajax({
url: 'sel_poscart.php',
method: "POST",
data:{ 
upimei: ids, imeidata: imei
},
dataType: 'json',
success: function(data){
$('#imei_'+id[1]).val(data[0]);
}
});     
});

$(document).on('keydown', '.imei', function() {
id_arr = $(this).attr('id');
id = id_arr.split("_");
var ids=id[1];
   
$('.imei' ).autocomplete({
source: function( request, response ) {
$.ajax({
url: 'sel_poscart.php',
type: 'post',
dataType: 'json',
data: {
search: request.term, audimei:ids
},
success: function(data) {
response(data);
}
});
},
select: function (event, ui) {
var pid = ui.item.value;    
var srl = ui.item.label; // selected id to input
$(this).val(srl);
    
$.ajax({
url: 'sel_poscart.php',
method: "POST",
data:{ 
upimei: ids, imeidata: srl
},
success: function(data){
//$('#imei_'+id[1]).val(data[0]);
}
});

return false;
}
});
});    
    
$(document).on('click', '#emptycart', function () {
var id = $(this).attr('id');    
$.ajax({
url: 'sel_poscart.php',
method: "POST",
data:{ 
clear: id
},
success: function(data){
ReadData();
}
});    
});
    
$(document).on('click', '#walkin', function() {	
$('#cusname').val('Walk-In Customer');
$('#cusid').val('CU_0');
$('#cusbal').html('0.00');	
});
    
$(document).on('keyup', '#cusname', function() { 
var bal = $(this).val();
if(bal.length<1){
$('#cusid').val('');
$('#cusbal').html('0.00');	
}
});
    
$(document).on('keydown', '#cusname', function() {    
$('#cusname' ).autocomplete({
source: function( request, response ) {
$.ajax({
url: 'sel_poscart.php',
type: 'post',
dataType: 'json',
data: {
search: request.term,getcus:1
},
success: function(data) {
response(data);
}
});
},
select: function (event, ui) {
$(this).val(ui.item.label);	
var cusid = ui.item.value; // selected id to input
$('#cusid').val(cusid);
$.ajax({
url: 'sel_poscart.php',
type: 'post',
data: {checkbal:cusid},
success:function(data){
$('#cusbal').html(data);
}
});

return false;
}
});
});

$(document).on('click', '#addcus', function() {
$('#addsitem').html('');    
$.ajax({
url: "sel_poscart.php",
method: "POST",
data:{addcus:1},
success: function(data){
$('#addsitem').html(data);
$('.right-side-add').toggle('slide', { direction: 'right' }, 300);     
}
})       
});
    
$(document).on('click', '#adcus', function() { 
var customer_data = $('.addcustomer input, .addcustomer select, .addcustomer textarea');
if(!chek_error()){
return;   
}
$.ajax({
url: "sel_poscart.php",
data: customer_data,
type: 'post',
dataType: 'json',    
beforeSend: function () {
chek_error();    
},    
success: function(data){
if(data.status === "success"){
$('#cusname').val(data.cudata);
$('#cusbal').val(data.cbal);
$('#cusid').val(data.cuid);    
if($('.right-side-add').is(':visible')) { $('.right-side-add').toggle('slide', { direction: 'right' }, 300); }
$('#addsitem').html('');    
}else{
$('#cusname').val('');
$('#cusbal').val('0.00');
$('#cusid').val('');    
toastr.error(data.message);    
}         
}
})    
});    
    
$(document).on('click', '#save_sales', function() {
var cusid = $('#cusid').val();     
toastr.options = {'positionClass': 'toast-top-center'};
    
$.ajax({
url: 'sel_poscart.php',
method: "POST",
data:{ 
seldata:1
},
dataType: 'json',
success: function(response) {
if(cusid.length < 1 || cusid == ''){
toastr.info('Please Select Customer!');
return;
}
    
var pri = response[0];
var sri = response[1];

if(pri>0){
toastr.warning('Missing price Information!!')	
return;
}    

if(sri>0){
toastr.warning('Missing Product Serial!!')	
return;
}    
    
selsave(); 
}
});          
});    

function selsave(){
var cusid = $('#cusid').val();
var wname = $('#walkname').val();
var wmobil = $('#walkmobile').val();
var wdid = $('#wdid').val();
var wzid = $('#wzid').val();
var wadd = $('#wadd').val();
var wemail = $('#wemail').val();    
    

$.ajax({
url: "sel_poscart.php",
method: "POST",
data:{checkview:1,cusid:cusid,wname:wname,wmobil:wmobil,wdid:wdid,wzid:wzid,wadd:wadd,wemail:wemail},
success: function(data){
$('#checkview').html('');
$('#checkview').html(data); 
}
})    
    
$.ajax({
url: "sel_poscart.php",
method: "POST",
data:{checkout:1,cusid:cusid},
success: function(data){
$('#invhold').html('');
$('#invhold').html(data);       
}
})
$('.right-side-checkout').addClass('open-right-checkout');    
}
    
$(document).on('click', '#closechk', function() {
$('.right-side-checkout').removeClass('open-right-checkout');
$('#addsitem').html('');    
});    
    
$(document).on('click', '#closepop', function() {    
if($('.right-side-add').is(':visible')) { $('.right-side-add').toggle('slide', { direction: 'right' }, 300); }
$('#addsitem').html('');    
});
    
$(document).on('click', '.saveseinv', function() {
var cusid = $('#cusid').val(); 
var due = parseFloat($('#dueamo').html());
var stype = $(this).attr('id');
var cash_data = $('.addsersales input, .addsersales select, .addsersales textarea');    
toastr.options = {'positionClass': 'toast-top-center'};    

$.ajax({
url: 'sel_poscart.php',
method: "POST",
data:{ 
seldata:1
},
dataType: 'json',
success: function(response) {
if(cusid.length < 1 || cusid == ''){
toastr.info('Please Select Customer!');
return;
}
    
var pri = response[0];

if(pri>0){
toastr.warning('Missing price Information!!')	
return;
}    

}
}); 

if(cusid<=0 && due > 0){
toastr.warning('Due Not Permitted for Walking Customer!');
return;
}

$.ajax({
url: "sel_poscart.php",
data: cash_data,
type: 'post',
dataType: 'json',    
success: function(data){
if(data.status === "success"){
$('.right-side-checkout').removeClass('open-right-checkout');
$('#addsitem').html('');
$('#cusname').val('');    
$("#cusid").val('');
$("#cusbal").html('0.00');
ReadItem();    
ReadData();    
toastr.success(data.message);
if(stype!='saveinv'){
print_inv(data.invid,stype);       
}    
}else{
toastr.error(data.message);    
}         
}
})    
    
});

function print_inv(id,key){
var mode = 'iframe'; //popup
var close = mode == "popup";
var options = {
mode: mode,
popClose: close
};    
$.ajax({
url: "sel_print.php",
data:{print:id,key:key}, 
type: 'post',    
success: function(data){
$("#invdata").html(data);    
$("div.printableArea").printArea(options);
$("#invdata").html('');    
}
})    
};
    
function getAllSubwgroup(id){
$.ajax({
url: 'axe_getsub.php',
type: 'post',
data: {zone : id},
success:function(data) {
$('#wzid').html(data);
}
});
};   

function cashcalculation(){
var pab = parseFloat($('#pabamo').html());
var cash = parseFloat($('#cash').val());
var adv = parseFloat($('#balance').val());
var adj = parseFloat($('#adjust').val());    
var paid=0; due=0; chang=0;
if(isNaN(cash)){
cash=0;    
}
if(isNaN(adj)){
adj=0;    
}
    
if((cash+adj)<=pab){
paid=cash;
due=(pab-(cash+adj));
chang=0;    
}else{
paid=pab;
due=0;
chang=((cash+adj)-pab);    
}
$('#paidamo').html(paid);
$('#dueamo').html(due);
$('#changamo').html(chang);   
}
    
$(document).on('keyup', '#cash', function() { 
cashcalculation();
});
    
$(document).on('keyup', '#adjust', function() {
var pab = parseFloat($('#pabamo').html());    
var adv = parseFloat($('#balance').val());
var adj = parseFloat($('#adjust').val());    
var maxad = 0;
if(pab<=adv){
maxad=pab;
}else{
maxad=adv;    
}
if(adj>maxad){
$('#adjust').val(maxad);    
}    
cashcalculation();
});
</script>    
<!-- /page script -->
</html>    