add customer at first
This commit is contained in:
@@ -1187,79 +1187,18 @@ $(function() {
|
||||
|
||||
// Pay Discount for Payment
|
||||
$("#create_pay_order").on('click', function(e){
|
||||
$("#sxModal").show();
|
||||
$("#sxModal").attr('data-for', 'member');
|
||||
$(this).attr('disabled', 'disabled');
|
||||
e.preventDefault();
|
||||
type = $("#link_type").val();
|
||||
modify_order = window.location.href.indexOf("modify_order");
|
||||
$("#oqs_loading_wrapper").show();
|
||||
if (modify_order !=-1) {
|
||||
var ajax_url = '../../../'+type+'/update_modify_order';
|
||||
var table_type = $('#table_type').text();
|
||||
var table_id = $('#table_id').text();
|
||||
var customer_id = $('#customer_id').text();
|
||||
var booking_id = $('#booking_id').text();
|
||||
var sale_id = $('#sale_id').text();
|
||||
}else{
|
||||
var ajax_url = 'addorders/create';
|
||||
var table_type = $('#table_id').find("option:selected").data('type');
|
||||
var table_id = $('#table_id').val();
|
||||
var customer_id = $('#customer_id').val();
|
||||
var booking_id = $('#booking_id').text();
|
||||
var sale_id = ""
|
||||
}
|
||||
var order_items = JSON.stringify(get_order_item_rows());
|
||||
if (booking_id.length > 0) {
|
||||
getCardNo();
|
||||
});
|
||||
|
||||
var params = {'order_source': type, 'order_type': "dine_in",
|
||||
'customer_id': customer_id, 'guest_info': "",'booking_id':booking_id,
|
||||
'table_id': table_id,
|
||||
'order_items': order_items,'sale_id': sale_id,'create_type': "create_pay" };
|
||||
}else{
|
||||
var params = {'order_source': type, 'order_type': "dine_in",
|
||||
'customer_id': customer_id, 'guest_info': "",
|
||||
'table_id': table_id,
|
||||
'order_items': order_items,'sale_id': sale_id,'create_type': "create_pay" };
|
||||
$("#sxModal .btn_cancel").on('click',function(){
|
||||
if($("#order-items-table tr").length > 1){
|
||||
$( "#create_pay_order" ).prop( "disabled", false );
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: ajax_url,
|
||||
data: params,
|
||||
dataType: "json",
|
||||
success:function(result){
|
||||
if (result.status) {
|
||||
if (result.data == null){
|
||||
swal({
|
||||
title: "Please Open Shift !",
|
||||
text: result.status,
|
||||
type: "warning",
|
||||
confirmButtonColor: "#DD6B55",
|
||||
confirmButtonText: "Ok",
|
||||
closeOnConfirm: false
|
||||
}, function () {
|
||||
window.location.href = '/origami/'+type+'/pending_order/' + $('#sale_id').text();
|
||||
});
|
||||
|
||||
}else if(result.data == 'OK'){
|
||||
if (window.location.pathname.includes('foodcourt')) {
|
||||
order_id = $('#order_id').val()
|
||||
window.location.href = '/foodcourt/food_court/'+order_id+'/request_bill'
|
||||
}
|
||||
else {
|
||||
window.location.href = '/origami/'+type+'/pending_order/' + $('#sale_id').text();
|
||||
}
|
||||
}else{
|
||||
if(result.current_user_role == 'cashier'){
|
||||
window.location.href = "/foodcourt/sale/"+result.data["sale_id"]+"/"+type+"/payment";
|
||||
}
|
||||
else{
|
||||
module_name = window.location.pathname.includes('origami') ? 'origami' : 'foodcourt'
|
||||
window.location.href = "/"+module_name+"/sale/"+result.data["sale_id"]+"/"+type+"/payment";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
$("#sxModal").hide();
|
||||
});
|
||||
|
||||
//click item row for update qty
|
||||
@@ -1374,29 +1313,6 @@ $(function() {
|
||||
});
|
||||
}
|
||||
|
||||
/* Get Item rows */
|
||||
function get_order_item_rows(){
|
||||
var order_items = [];
|
||||
var item_row = $('.summary-items tbody tr');
|
||||
$(item_row).each(function(i){
|
||||
var order_item = {};
|
||||
|
||||
order_item.order_item_id = $(item_row[i]).attr('data-row');
|
||||
order_item.item_instance_code = $(item_row[i]).attr('data-instance-code');
|
||||
order_item.quantity = $(item_row[i]).children('#item_qty').text();
|
||||
//parent id
|
||||
if ($(item_row[i]).attr('data-parent')=="true") {
|
||||
parent_id = $(item_row[i]).attr('data-row');
|
||||
}
|
||||
if ($(item_row[i]).attr('data-sub-item')=="true") {
|
||||
order_item.parent_order_item_id = parent_id
|
||||
}
|
||||
//end parent id
|
||||
order_item.options = $(item_row[i]).attr('data-options');
|
||||
order_items.push(order_item);
|
||||
});
|
||||
return order_items;
|
||||
}
|
||||
// Get Selected Class
|
||||
function get_selected_attributes(selected_class) {
|
||||
var item_row = $('.'+selected_class);
|
||||
@@ -1969,3 +1885,26 @@ $(function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
/* Get Item rows */
|
||||
function get_order_item_rows(){
|
||||
var order_items = [];
|
||||
var item_row = $('.summary-items tbody tr');
|
||||
$(item_row).each(function(i){
|
||||
var order_item = {};
|
||||
|
||||
order_item.order_item_id = $(item_row[i]).attr('data-row');
|
||||
order_item.item_instance_code = $(item_row[i]).attr('data-instance-code');
|
||||
order_item.quantity = $(item_row[i]).children('#item_qty').text();
|
||||
//parent id
|
||||
if ($(item_row[i]).attr('data-parent')=="true") {
|
||||
parent_id = $(item_row[i]).attr('data-row');
|
||||
}
|
||||
if ($(item_row[i]).attr('data-sub-item')=="true") {
|
||||
order_item.parent_order_item_id = parent_id
|
||||
}
|
||||
//end parent id
|
||||
order_item.options = $(item_row[i]).attr('data-options');
|
||||
order_items.push(order_item);
|
||||
});
|
||||
return order_items;
|
||||
}
|
||||
|
||||
145
app/assets/javascripts/foodcourt/addorder.js
Normal file
145
app/assets/javascripts/foodcourt/addorder.js
Normal file
@@ -0,0 +1,145 @@
|
||||
function getCardNo(){
|
||||
if(typeof code2lab != 'undefined'){
|
||||
code2lab.readNFC();
|
||||
}
|
||||
}
|
||||
function setCardNo(cardNo){
|
||||
if(cardNo.length == 16){
|
||||
$("#paypar_account_no").val(cardNo);
|
||||
if ($("#sxModal").attr("data-for") == 'member') {
|
||||
member_card(cardNo)
|
||||
} else if ($("#sxModal").attr('data-for') == 'payment') {
|
||||
pay_with_card(cardNo);
|
||||
}
|
||||
$("#sxModal").hide();
|
||||
}
|
||||
}
|
||||
function member_card(cardNo) {
|
||||
var g_customer_id = '';
|
||||
var g_customer_name = '';
|
||||
var g_membership_id = '';
|
||||
var g_membership_type = '';
|
||||
var sale_id = 0 ;
|
||||
if(cardNo != 0){
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "/foodcourt/"+sale_id+"/get_customer" ,
|
||||
data: { filter : cardNo ,type :"card"},
|
||||
dataType: "json",
|
||||
success: function(data) {
|
||||
if (data[0].customer_id == false) {
|
||||
swal("Alert!", data[0].message, "error");
|
||||
}else{
|
||||
g_customer_id = data[0].customer_id;
|
||||
g_customer_name = data[0].name;
|
||||
g_membership_id = data[0].membership_id;
|
||||
g_membership_type = data[0].membership_type;
|
||||
type = $("#link_type").val();
|
||||
modify_order = window.location.href.indexOf("modify_order");
|
||||
if(!$('.btn').hasClass('req_bill') && !$('.btn').is('#pay')){
|
||||
var booking_id = $('#booking_id').text();
|
||||
if (modify_order !=-1) {
|
||||
var ajax_url = '../../../'+type+'/update_modify_order';
|
||||
var table_type = $('#table_type').text();
|
||||
var table_id = $('#table_id').text();
|
||||
var customer_id = $('#customer_id').text();
|
||||
var sale_id = $('#sale_id').text();
|
||||
}else{
|
||||
var ajax_url = 'addorders/create';
|
||||
var table_type = $('#table_id').find("option:selected").data('type');
|
||||
var table_id = $('#table_id').val();
|
||||
var customer_id = g_customer_id;
|
||||
var sale_id = ""
|
||||
}
|
||||
|
||||
var order_items = JSON.stringify(get_order_item_rows());
|
||||
|
||||
var params = {'order_source': type, 'order_type': "dine_in",
|
||||
'customer_id': customer_id, 'guest_info': "",
|
||||
'table_id': table_id,
|
||||
'order_items': order_items,'sale_id': sale_id,'create_type': "create_pay" };
|
||||
if (booking_id.length > 0) {
|
||||
params.booking_id = booking_id;
|
||||
}
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: ajax_url,
|
||||
data: params,
|
||||
dataType: "json",
|
||||
success:function(result){
|
||||
if (result.data == 'OK'){
|
||||
request_bill(g_membership_id, g_customer_id, g_customer_name);
|
||||
}else{
|
||||
if (result.data["sale_id"]){
|
||||
update_sale(g_membership_id, g_customer_id, g_customer_name,result.data["sale_id"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}else if($('.btn').is('#pay')){
|
||||
update_sale(g_membership_id, g_customer_id, g_customer_name,$('#sale_id').text());
|
||||
}
|
||||
else{
|
||||
request_bill(g_membership_id, g_customer_id, g_customer_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
function request_bill(membership_id,customer_id,customer_name){
|
||||
if (window.location.pathname.includes('foodcourt')) {
|
||||
order_id = $('#order_id').val() || $('#save_order_id').val()
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: "/foodcourt/food_court/"+order_id+"/request_bill" ,
|
||||
data: {},
|
||||
dataType: "json",
|
||||
success: function(data) {
|
||||
if(data.status == true)
|
||||
{
|
||||
update_sale(membership_id, customer_id, customer_name, data.sale_id);
|
||||
}else{
|
||||
swal("Alert!", "Error!", "error");
|
||||
location.reload();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
function update_sale(membership_id, customer_id, customer_name, sale_id) {
|
||||
var customer="";
|
||||
var cashier_type = 'food_court';
|
||||
if(customer_name != ""){
|
||||
customer = '(' + customer_name + ')';
|
||||
}
|
||||
|
||||
swal({
|
||||
title: "Confirmation !",
|
||||
text: 'Are You Sure to assign this customer' + customer + '!',
|
||||
showCancelButton: true,
|
||||
confirmButtonColor: "green",
|
||||
confirmButtonText: "Yes!",
|
||||
cancelButtonClass: 'btn btn-danger customer_assign_cancel',
|
||||
closeOnConfirm: false,
|
||||
}, function () {
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "/foodcourt/"+sale_id+"/"+cashier_type+"/customers/update_sale" ,
|
||||
data: {customer_id:customer_id,sale_id:sale_id},
|
||||
dataType: "json",
|
||||
success: function(data) {
|
||||
if(data.status == true)
|
||||
{
|
||||
//change customer detail
|
||||
$("#customer_name").html(customer_name);
|
||||
$("#membership_id").html(membership_id);
|
||||
window.location.href = '/foodcourt/sale/'+sale_id+'/'+cashier_type+'/payment/';
|
||||
}else{
|
||||
swal("Alert!", "Record not found!", "error");
|
||||
location.reload();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user