"
@@ -237,10 +238,10 @@ $(function() {
//instances = $(this).data('instance');
item_sets = $(this).data('item-sets');
instances = $(this).data('instances');
- // item_sets = $(data).attr('data-item-sets');
+ item_options = $(this).data('options');
for(var field in item_sets) {
-
+
$('.set_order').attr('data-min-qty',item_sets[field]["min_selectable_qty"]);
value = item_sets[field]["instances"];
@@ -283,10 +284,20 @@ $(function() {
});
}
+ for(var j in item_options) {
+ value = item_options[j]["values"];
+ type = item_options[j]["type"];
+ row = "
";
+ });
+ $(".options-list").append(row);
+ }
$('.set-item').attr('data-code',instances[0]['code']);
$('.set-item').attr('data-name',instances[0]['name']);
$('.set-item').attr('data-price',instances[0]['price']);
- $('.set-item').attr('data-options','[]');
+ $('.set-item').attr('data-options','');
$('.set-item').attr('data-parent',true);
$('#set_change_qty').val(1);
@@ -341,6 +352,7 @@ $(function() {
sub_total = $('#set_total_price').text();
name = $(this).data('name');
price = $(this).data('price');
+ options = $(this).attr('data-options','');
// qty = $('#set_change_qty').val();
qty = document.getElementById("set_count").value;
total = qty*price;
@@ -369,52 +381,48 @@ $(function() {
item = get_set_item(items);
customer_display_view(item,"set_add");
-
+ var option = ''
attribute_arr = []
- option_arr = []
var rowCount = $('.summary-items tbody tr').length+1;
- option_arr = []
code = $('.set-item').attr('data-code');
name = $('.set-item').attr('data-name');
price = $('.set-item').attr('data-price');
- option = $('.set-item').attr('data-options');
+ option = ($('.set-item').attr('data-options') === 'undefined') ? '' :$('.set-item').attr('data-options');
parent = $('.set-item').attr('data-parent');
total = qty * price ;
- option_arr.push(option);
row ="
';
$(".summary-items tbody").append(row);
-
var rowCount = $('.summary-items tbody tr').length+1;
+ var set_option = ''
$(items).each(function(i){
code = $(items[i]).attr('data-code');
name = $(items[i]).attr('data-name');
price = $(items[i]).attr('data-price');
- option = $(items[i]).attr('data-options');
+ set_option = ($(items[i]).attr('data-options') === 'undefined') ? ' ' :$(items[i]).attr('data-options');
+
sub_item = $(items[i]).attr('data-sub-item');
- option = $(items[i]).attr('data-options');
total = qty * price ;
- option_arr.push(option);
row ="
"
+ +set_option+"' data-row ='"+rowCount+ "' data-sub-item ='"+sub_item+ "'>"
+''+rowCount+' '
- +'' + item_name+ ' ' + name +' '
+ +'' + item_name+ ' ' + name +' ' + set_option +' '
+'' + qty + ' '
+''
+ parseFloat(total).toFixed(2)
@@ -626,8 +634,6 @@ $(function() {
if(group == "set_menu"){
- code = $(this).data('code');
- value = $(this).data('value');
instance = $(".selected-instance");
$(instance).each(function(i){
@@ -638,6 +644,12 @@ $(function() {
}
});
}
+
+ if(group == "set_menu_default"){
+ option_arr = get_selected_attributes('selected-option');
+ $('.set-item').attr('data-options',JSON.stringify(option_arr));
+ $('.set_default_option').text(option_arr);
+ }
}); //End selecct attribute buttom
@@ -650,7 +662,6 @@ $(function() {
attribute_arr = get_selected_attributes('selected-attribute');
option_arr = get_selected_attributes('selected-option');
-
if (item_row.length>0) {
var instances = jQuery.parseJSON(item_row.attr('data-instances'));
@@ -689,9 +700,9 @@ $(function() {
$('.add_to_order').attr('data-attributes',JSON.stringify(attribute_arr));
$('.add_to_order').attr('data-options',JSON.stringify(option_arr));
var item_data = $(this);
- item = get_item(item_data);
+ item = get_item(item_data,"add_to_order");
customer_display_view(item,"add");
- show_item_detail(item_data);
+ show_item_detail(item_data,"add_to_order");
calculate_sub_total();
}); //End add order Click
@@ -699,13 +710,13 @@ $(function() {
// click plus icon for add
$(document).on('click', '.add_icon', function(event){
var item_data = $(this);
- item = get_item(item_data);
+ item = get_item(item_data,"add_icon");
customer_display_view(item,"add");
- show_item_detail(item_data);
+ show_item_detail(item_data,"add_icon");
calculate_sub_total();
}); //End Add Icon Click
- function show_item_detail(data){
+ function show_item_detail(data,click_type){
qty = parseInt(data.attr('data-qty'));
append = 0;
@@ -717,23 +728,24 @@ $(function() {
}else{
instance = "("+data.attr('data-instance')+")";
}
-
- d_option = data.attr('data-options');
- if (d_option){
- option_name = "-"+data.attr('data-options');
+ d_option = data.attr('data-opt');
+ if (click_type != "add_icon"){
+ option_name = "-"+data.attr('data-options');
+ data_option = data.attr('data-options') ;
}else{
- option_name = '';
+ option_name = ' ';
+ data_option = '[]';
}
+
var rowCount = $('.summary-items tbody tr').length+1;
var item_row = $('.summary-items tbody tr');
$(item_row).each(function(i){
item_code = $(item_row[i]).attr('data-code');
instance_code = $(item_row[i]).attr('data-instance-code');
- r_option = $(item_row[i]).attr('data-options');
-
- if (item_code == data.attr('data-item-code') && instance_code == data.attr('data-instance-code')&&r_option==d_option) {
+ r_option = $(item_row[i]).attr('data-opt');
+ if (item_code == data.attr('data-item-code') && instance_code == data.attr('data-instance-code')&&r_option == d_option) {
if (qty > 1) {
qty = parseInt($(item_row[i]).children('#item_qty').text()) + qty;
}else{
@@ -757,9 +769,10 @@ $(function() {
+instance+ "' data-code='"+data.attr('data-item-code')+"' data-instance-code='"
+data.attr('data-instance-code')+"' data-attributes='"
+data.attr('data-attributes')+"' data-options ='"
+ +data_option+"' data-opt ='"
+data.attr('data-options')+"' data-row ='"+rowCount+ "'>"
+' '+rowCount+' '
- +'' + data.attr('data-name')+ ' ' + instance +' ' + option_name +' '
+ +'' + data.attr('data-name')+ ' ' + instance +''+option_name+' '
+'' + qty + ' '
+''
+ parseFloat(price).toFixed(2)
@@ -776,17 +789,17 @@ $(function() {
e.preventDefault();
$("#oqs_loading_wrapper").show();
- type = window.location.href.indexOf("quick_service");
- if (type != -1) {
+ quick_service = window.location.href.indexOf("quick_service");
+ if (quick_service != -1) {
type = 'quick_service'
- var table_type = $('#table_type').text();
+ var table_type = $('#table_type').text();
var table_id = $('#table_id').val();
var customer_id = $('#customer_id').val();
var booking_id = $('#booking_id').text();
var ajax_url = 'addorders/create';
}else{
type = 'cashier'
- var table_type = $('#table_type').text();
+ var table_type = $('#table_type').text();
var table_id = $('#table_id').text();
var customer_id = $('#customer_id').text();
var booking_id = $('#booking_id').text();
@@ -813,17 +826,17 @@ $(function() {
data: params,
dataType: "json",
success:function(result){
- customer_display_view(null,"reload");
if (type == "quick_service") {
- window.location.href = "/origami/quick_service"
+ window.location.href = "/origami/quick_service"
}else{
if(table_type == "Table"){
- window.location.href = "/origami/table/" + table_id
+ window.location.href = "/origami/table/" + table_id
}
else {
- window.location.href = "/origami/room/" + table_id
+ window.location.href = "/origami/room/" + table_id
}
}
+ customer_display_view(null,"reload");
}
});
// }else{
@@ -878,13 +891,24 @@ $(function() {
dataType: "json",
success:function(result){
if (result.status) {
+
if (result.data == null){
- window.location.href = '/origami/quick_service/pending_order/' + $('#sale_id').text();
+ swal({
+ title: "Please Open Shift !",
+ text: result.status,
+ type: "warning",
+ confirmButtonColor: "#DD6B55",
+ confirmButtonText: "Ok",
+ closeOnConfirm: false
+ }, function () {
+ window.location.href = '/origami/quick_service/pending_order/' + $('#sale_id').text();
+ });
+
}else{
window.location.href = "/origami/sale/"+result.data["sale_id"]+"/"+type+"/payment"
}
}
- }
+ }
});
});
@@ -1156,7 +1180,7 @@ $(function() {
for(var i in data) {
- row = '' ;
$(sub_category).append(row);
@@ -1169,7 +1193,7 @@ $(function() {
}
/* Get Item rows */
- function get_item(data){
+ function get_item(data,click_type){
var sale_items = [];
var sale_item = {};
@@ -1180,6 +1204,8 @@ $(function() {
sale_item.instance_code = data.attr('data-instance-code')
sale_item.attributes = data.attr('data-attributes')
sale_item.options = data.attr('data-options')
+ sale_item.opt = data.attr('data-opt')
+ sale_item.click_type = click_type
sale_item.instance = data.attr('data-instance')
sale_items.push(sale_item);
diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js
index 76341958..e486c152 100755
--- a/app/assets/javascripts/application.js
+++ b/app/assets/javascripts/application.js
@@ -104,6 +104,86 @@ $(document).ready(function() {
}
});
+ $("#shop_logo").fileinput({
+ previewFileType: "image",
+ allowedFileExtensions: ["jpg", "gif", "png"],
+ browseClass: "btn btn-success",
+ browseLabel: "Pick Image",
+ browseIcon: " ",
+ removeClass: "btn btn-danger",
+ removeLabel: "Delete",
+ removeIcon: " ",
+ showUpload: false,
+ // uploadClass: "btn btn-info",
+ // uploadLabel: "Upload",
+ // uploadIcon: " ",
+ previewTemplates: {
+ image: '\n' +
+ '
\n' +
+ '
\n',
+ }
+ });
+
+ $("#commissioner_image_path").fileinput({
+ previewFileType: "image",
+ allowedFileExtensions: ["jpg", "gif", "png"],
+ browseClass: "btn btn-success",
+ browseLabel: "Pick Image",
+ browseIcon: " ",
+ removeClass: "btn btn-danger",
+ removeLabel: "Delete",
+ removeIcon: " ",
+ showUpload: false,
+ // uploadClass: "btn btn-info",
+ // uploadLabel: "Upload",
+ // uploadIcon: " ",
+ previewTemplates: {
+ image: '\n' +
+ '
\n' +
+ '
\n',
+ }
+ });
+
+ $("#employee_image_path").fileinput({
+ previewFileType: "image",
+ allowedFileExtensions: ["jpg", "gif", "png"],
+ browseClass: "btn btn-success",
+ browseLabel: "Pick Image",
+ browseIcon: " ",
+ removeClass: "btn btn-danger",
+ removeLabel: "Delete",
+ removeIcon: " ",
+ showUpload: false,
+ // uploadClass: "btn btn-info",
+ // uploadLabel: "Upload",
+ // uploadIcon: " ",
+ previewTemplates: {
+ image: '\n' +
+ '
\n' +
+ '
\n',
+ }
+ });
+
+ $("#shop_image").fileinput({
+ previewFileType: "image",
+ allowedFileExtensions: ["jpg", "gif", "png"],
+ browseClass: "btn btn-success",
+ browseLabel: "Pick Image",
+ browseIcon: " ",
+ removeClass: "btn btn-danger",
+ removeLabel: "Delete",
+ removeIcon: " ",
+ showUpload: false,
+ // uploadClass: "btn btn-info",
+ // uploadLabel: "Upload",
+ // uploadIcon: " ",
+ previewTemplates: {
+ image: '\n' +
+ '
\n' +
+ '
\n',
+ }
+ });
+
// first input focus for all form
$('form:first *input[data-behaviour!=datepicker]:input[type!=hidden]:first').focus();
diff --git a/app/assets/javascripts/channels/second_display_view.js b/app/assets/javascripts/channels/second_display_view.js
index 00d4904c..1a1cba86 100644
--- a/app/assets/javascripts/channels/second_display_view.js
+++ b/app/assets/javascripts/channels/second_display_view.js
@@ -10,10 +10,12 @@ App.checkin = App.cable.subscriptions.create('SecondDisplayViewChannel', {
var tax = data.tax_profiles;
var status= data.status
if (status == "reload") {
- window.location.reload();
+ jQuery('#s_reload').click();
}
- $('#second_display_slider').addClass("hidden")
- $('#second_display_items').removeClass("hidden")
+ $('#second_display_slider').addClass("hidden")
+ $('#second_display_items').removeClass("hidden")
+
+
// append items
if (status == "add") {
for(var i in items) {
@@ -28,11 +30,20 @@ App.checkin = App.cable.subscriptions.create('SecondDisplayViewChannel', {
instance = "("+items[i].instance+")";
}
- d_option = items[i].options;
- if (d_option){
- option_name = "-"+items[i].options;
+ // d_option = items[i].options;
+ // if (d_option){
+ // option_name = "-"+items[i].options;
+ // }else{
+ // option_name = '';
+ // }
+
+ d_option = items[i].opt;
+ if (items[i].click_type != "add_icon"){
+ option_name = "-"+items[i].options;
+ data_option = items[i].options ;
}else{
- option_name = '';
+ option_name = ' ';
+ data_option = '[]';
}
var rowCount = $('.second_display_items tbody tr').length+1;
@@ -66,7 +77,8 @@ App.checkin = App.cable.subscriptions.create('SecondDisplayViewChannel', {
+instance+ "' data-code='"+items[i].item_code+"' data-instance-code='"
+items[i].instance_code+"' data-attributes='"
+items[i].attributes+"' data-options ='"
- +items[i].options+"' data-row ='"+rowCount+ "'>"
+ +data_option+"' data-opt ='"
+ +items[i].options+"' data-row ='"+rowCount+ "'>"
+' '+rowCount+' '
+'' + items[i].name+ ' ' + instance + ' ' + option_name +' '
+'' + qty + ' '
@@ -84,8 +96,6 @@ App.checkin = App.cable.subscriptions.create('SecondDisplayViewChannel', {
var attribute_arr = [];
var rowCount = $('.second_display_items tbody tr').length+1;
for(var i in items) {
-
-
code = items[i].code;
item_code = items[i].item_code;
name = items[i].name;
diff --git a/app/assets/javascripts/custom.js b/app/assets/javascripts/custom.js
index a2011022..778de553 100644
--- a/app/assets/javascripts/custom.js
+++ b/app/assets/javascripts/custom.js
@@ -9,7 +9,8 @@ $(document).ready(function() {
color: 'rgba(0,0,0,0.5)',
alwaysVisible: false,
borderRadius: '0',
- railBorderRadius: '0'
+ railBorderRadius: '0',
+ touchScrollStep : 25
});
$('#order-detail-slimscroll').slimScroll({
@@ -18,7 +19,18 @@ $(document).ready(function() {
color: 'rgba(0,0,0,0.5)',
alwaysVisible: false,
borderRadius: '0',
- railBorderRadius: '0'
+ railBorderRadius: '0',
+ touchScrollStep : 25
+ });
+
+ $('#menu-slimscroll').slimScroll({
+ height: height-$('#menu-slimscroll').attr('data-height'),
+ size: '5px',
+ color: 'rgba(0,0,0,0.5)',
+ alwaysVisible: false,
+ borderRadius: '0',
+ railBorderRadius: '0',
+ touchScrollStep : 25
});
// $('.delete').click(function(){
diff --git a/app/assets/javascripts/origami.js b/app/assets/javascripts/origami.js
index 842b236b..f2219711 100755
--- a/app/assets/javascripts/origami.js
+++ b/app/assets/javascripts/origami.js
@@ -9,12 +9,37 @@
//= require bootstrap-notify/bootstrap-notify.js
//= require node-waves/waves.js
//= require sweetalert/sweetalert.min.js
+//= require fileinput.min
//= require cable
//= require turbolinks
//= require BSBMaterial/turbolink_admin.js
//= require BSBMaterial/demo.js
//= require custom.js
+
+$(document).on('turbolinks:load', function() {
+
+ $("#customer_image_path").fileinput({
+ previewFileType: "image",
+ allowedFileExtensions: ["jpg", "gif", "png"],
+ browseClass: "btn btn-success",
+ browseLabel: "Pick Image",
+ browseIcon: " ",
+ removeClass: "btn btn-danger",
+ removeLabel: "Delete",
+ removeIcon: " ",
+ showUpload: false,
+ // uploadClass: "btn btn-info",
+ // uploadLabel: "Upload",
+ // uploadIcon: " ",
+ previewTemplates: {
+ image: '\n' +
+ '
\n' +
+ '
\n',
+ }
+ });
+});
+
$(document).on('turbolinks:load', function() {
$('.datetimepicker').bootstrapMaterialDatePicker({
format: 'DD-MM-YYYY - HH:mm',
@@ -224,7 +249,7 @@ function setCommPorts(comPortLists) {
closeOnCancel: false,
allowOutsideClick: false
}, function () {
- window.location.href = '/origami/sale/'+ sale_id + "/payment/others_payment";
+ window.location.href = '/origami/sale/'+ sale_id +"/"+cashier_type+"/payment/others_payment";
});
}
}
@@ -298,7 +323,7 @@ function resCBPay(resMsg,card_sale_trans_id,cmd_type,payment_type,bnk_bill_amoun
if(jobj.STATUS == "Approved"){
$.ajax({type: "POST",
url: "/origami/payment/"+payment_type,
- data: "amount="+ bnk_bill_amount + "&sale_id="+ sale_id,
+ data: "amount="+ bnk_bill_amount + "&sale_id="+ sale_id + "&ref_no=" + jobj.REFNUM,
success:function(result){
if(result){
swal({
@@ -317,6 +342,8 @@ function resCBPay(resMsg,card_sale_trans_id,cmd_type,payment_type,bnk_bill_amoun
}else{
if(payment_type!="master"){
payment_type = payment_type.toUpperCase();
+ }else{
+ payment_type = "Master";
}
swal({
title: 'Oops',
diff --git a/app/assets/stylesheets/CRM.scss b/app/assets/stylesheets/CRM.scss
index 8b652eac..5bfab409 100755
--- a/app/assets/stylesheets/CRM.scss
+++ b/app/assets/stylesheets/CRM.scss
@@ -13,6 +13,7 @@
@import "BSBMaterial/style";
@import "BSBMaterial/themes/all-themes";
@import "reset";
+@import "fileinput.min";
.sx-margin-0 {
margin: 0 !important;
diff --git a/app/assets/stylesheets/login.scss b/app/assets/stylesheets/login.scss
index 030b0fe1..b5f29da6 100755
--- a/app/assets/stylesheets/login.scss
+++ b/app/assets/stylesheets/login.scss
@@ -8,6 +8,11 @@
background-color: #2790a5;
}
+.active_tab{
+ border-style: solid;
+ border-color: #2790a5;
+}
+
.login-page {
margin: 0% auto;
background-color: #2790a5;
@@ -75,3 +80,13 @@
background-color: #fff;
border-top: none;
}
+
+.p-card{
+ margin: 20px 0;
+ text-align: center;
+}
+
+.p-name{
+ padding-bottom: 20px;
+ font-size: 14px;
+}
diff --git a/app/assets/stylesheets/origami.scss b/app/assets/stylesheets/origami.scss
index 623a4618..f882e526 100755
--- a/app/assets/stylesheets/origami.scss
+++ b/app/assets/stylesheets/origami.scss
@@ -198,6 +198,18 @@ select.form-control {
background-color: blue !important;
}
+.selected-payment {
+ color: #fff !important;
+ background-color: blue !important;
+}
+.payment_btn {
+ white-space: normal !important;
+ margin-bottom: 15px;
+ margin-right: 15px;
+ color:#fff !important;
+ # background-color: green !important;
+}
+
/* Reciept Style */
#order-charges-table td {
border-top: none !important;
@@ -314,7 +326,7 @@ tr.discount-item-row:hover {
position: relative;
left: 42%;
top: 30%;
- background-color: #d9534f;
+ background-color: #32ad1a;
color: #fff;
text-align: center;
width: 200px;
@@ -396,3 +408,27 @@ i.logout_icon{
color: #fff !important;
background-color: #5DADE2 !important;
}
+
+/* Start Is Member Modal */
+#is_memberModal .modal-body {
+ height: 260px !important;
+}
+
+#is_memberModal .btn {
+ width: 80%;
+}
+/* End Is Member Modal */
+
+/* Start iframe */
+iframe {
+ border: none;
+ overflow: hidden !important;
+ width: 400px;
+ height: 550px;
+}
+
+#pdfModal .btn {
+ width: 150%;
+ height: 100%;
+}
+/* End iframe */
\ No newline at end of file
diff --git a/app/controllers/api/orders_controller.rb b/app/controllers/api/orders_controller.rb
index 2e9602c8..383a6606 100755
--- a/app/controllers/api/orders_controller.rb
+++ b/app/controllers/api/orders_controller.rb
@@ -67,7 +67,8 @@ class Api::OrdersController < Api::ApiController
end
}
#end extra time
-
+ puts params[:order_items]
+ puts "ORDER ITEMS"
# begin
@order = Order.new
@order.source = params[:order_source]
@@ -171,9 +172,9 @@ class Api::OrdersController < Api::ApiController
# Update customer info, Guest Info
# Input Params
# order_id , order_items {[item_code, item_instance_code , qty, option, variants]}
- def update
+ # def update
- end
+ # end
def order_params
params.permits(:order_source, :booking_id,:order_type,
@@ -198,4 +199,59 @@ class Api::OrdersController < Api::ApiController
end
return status
end
+
+ def update
+ Rails.logger.debug "Booking ID - " + params[:booking_id].to_s
+ if checkin_checkout_time(params[:booking_id])
+ Rails.logger.debug "Order Item ID - " + params[:order_item_id].to_s
+
+ order_items_id = params[:order_item_id]
+ qty_weight = params[:quantity].to_f
+ remarks = params[:remark]
+
+ order_item = OrderItem.find(order_items_id)
+ before_updated_qty = order_item.qty
+
+ order_item.item_order_by = current_login_employee.name
+ order_item.qty = qty_weight
+ order_item.remark = remarks
+ order_item.save
+
+ if ENV["SERVER_MODE"] != "cloud" #no print in cloud server
+ # print
+ assigned_item = AssignedOrderItem.find_by_instance_code(order_item.item_instance_code)
+ # order queue stations
+ oqs = assigned_item.order_queue_station
+
+ order_slim_pdf = Lookup.collection_of("print_settings") #print_settings with name:OrderSlimPdf
+
+ unique_code="OrderItemPdf"
+ if !order_slim_pdf.empty?
+ order_slim_pdf.each do |order_item_slim|
+ if order_item_slim[0] == 'OrderSlimPdf'
+ if order_item_slim[1] == '1'
+ unique_code="OrderItemSlimPdf"
+ else
+ unique_code="OrderItemPdf"
+ end
+ elsif order_item_slim[0] == 'OrderSetPdf'
+ if order_item_slim[1] == '1'
+ unique_code="OrderSetItemPdf"
+ else
+ unique_code="OrderItemPdf"
+ end
+ end
+ end
+ end
+
+ print_settings=PrintSetting.find_by_unique_code(unique_code)
+ order_queue_printer= Printer::OrderQueuePrinter.new(print_settings)
+ order_queue_printer.print_order_item(print_settings, oqs, order_item.order_id, order_items_id, print_status=" (Cancelled)", before_updated_qty )
+ end
+
+ return return_json_status_with_code(200, "updated successfully!")
+ else
+ return return_json_status_with_code(406, "Checkout time is over!")
+ end
+ end
end
diff --git a/app/controllers/api/payments_controller.rb b/app/controllers/api/payments_controller.rb
index 39219c6b..459589ed 100755
--- a/app/controllers/api/payments_controller.rb
+++ b/app/controllers/api/payments_controller.rb
@@ -84,6 +84,17 @@ class Api::PaymentsController < ActionController::API
sale_payment.payment_reference = params[:payment_reference]
#TODO: implement paypar implementation
@status, @invoice = sale_payment.process_payment(sale_payment, current_login_employee.name)
+ when "JunctionPay"
+ sale_payment.payment_method = "JunctionPay"
+ sale_payment.received_amount = params[:amount]
+ sale_payment.customer_id = params[:customer_id]
+ sale_payment.payment_reference = params[:vochure_no]
+ @status, @invoice = sale_payment.process_payment(sale_payment, current_login_employee.name)
+ when "alipay"
+ sale_payment.payment_method = "alipay"
+ sale_payment.received_amount = params[:amount]
+ sale_payment.payment_reference = params[:payment_reference]
+ @status, @invoice = sale_payment.process_payment(sale_payment, current_login_employee.name)
end
end
end
diff --git a/app/controllers/base_controller.rb b/app/controllers/base_controller.rb
index 1bf5b4d4..aad5c676 100755
--- a/app/controllers/base_controller.rb
+++ b/app/controllers/base_controller.rb
@@ -1,5 +1,12 @@
class BaseController < ActionController::Base
layout "installation"
protect_from_forgery with: :exception
+
+ helper_method :shop_detail
+
+ #Shop Name in Navbor
+ def shop_detail
+ @shop = Shop.first
+ end
end
diff --git a/app/controllers/base_crm_controller.rb b/app/controllers/base_crm_controller.rb
index d7c008f6..65350605 100755
--- a/app/controllers/base_crm_controller.rb
+++ b/app/controllers/base_crm_controller.rb
@@ -2,11 +2,36 @@ class BaseCrmController < ActionController::Base
include LoginVerification
layout "CRM"
+ before_action :check_user
+
#before_action :check_installation
protect_from_forgery with: :exception
+ helper_method :shop_detail
+
rescue_from CanCan::AccessDenied do |exception|
flash[:warning] = exception.message
redirect_to root_path
end
+
+ #change locallization
+ def set_locale
+ I18n.locale = params[:locale] || I18n.default_locale
+ end
+
+ # RESTful url for localize
+ def default_url_options
+ { locale: I18n.locale }
+ end
+
+ def check_user
+ if current_user.nil?
+ redirect_to root_path
+ end
+ end
+
+ #Shop Name in Navbor
+ def shop_detail
+ @shop = Shop.first
+ end
end
diff --git a/app/controllers/base_inventory_controller.rb b/app/controllers/base_inventory_controller.rb
index fc9c0c47..ebbd32e3 100755
--- a/app/controllers/base_inventory_controller.rb
+++ b/app/controllers/base_inventory_controller.rb
@@ -2,11 +2,26 @@ class BaseInventoryController < ActionController::Base
include LoginVerification
layout "inventory"
+ before_action :check_user
+
#before_action :check_installation
protect_from_forgery with: :exception
+ helper_method :shop_detail
+
rescue_from CanCan::AccessDenied do |exception|
flash[:warning] = exception.message
redirect_to root_path
end
+
+ def check_user
+ if current_user.nil?
+ redirect_to root_path
+ end
+ end
+
+ #Shop Name in Navbor
+ def shop_detail
+ @shop = Shop.first
+ end
end
diff --git a/app/controllers/base_oqs_controller.rb b/app/controllers/base_oqs_controller.rb
index 19b01ea3..2b621cf1 100755
--- a/app/controllers/base_oqs_controller.rb
+++ b/app/controllers/base_oqs_controller.rb
@@ -2,11 +2,36 @@ class BaseOqsController < ActionController::Base
include LoginVerification
layout "OQS"
+ before_action :check_user
+
#before_action :check_installation
protect_from_forgery with: :exception
+
+ helper_method :shop_detail
rescue_from CanCan::AccessDenied do |exception|
flash[:warning] = exception.message
redirect_to root_path
end
+
+ #change locallization
+ def set_locale
+ I18n.locale = params[:locale] || I18n.default_locale
+ end
+
+ # RESTful url for localize
+ def default_url_options
+ { locale: I18n.locale }
+ end
+
+ def check_user
+ if current_user.nil?
+ redirect_to root_path
+ end
+ end
+
+ #Shop Name in Navbor
+ def shop_detail
+ @shop = Shop.first
+ end
end
diff --git a/app/controllers/base_origami_controller.rb b/app/controllers/base_origami_controller.rb
index 4b20f9e5..e14a6959 100755
--- a/app/controllers/base_origami_controller.rb
+++ b/app/controllers/base_origami_controller.rb
@@ -2,19 +2,22 @@ class BaseOrigamiController < ActionController::Base
include LoginVerification
layout "origami"
- # before_action :checkin_process
+ before_action :check_user
#before_action :check_installation
protect_from_forgery with: :exception
+ helper_method :shop_detail
rescue_from CanCan::AccessDenied do |exception|
flash[:warning] = exception.message
# redirect_to origami_root_path
redirect_to origami_dashboard_path
end
- def current_user
- @current_user ||= Employee.find_by_token_session(session[:session_token]) if session[:session_token]
+ def check_user
+ if current_user.nil?
+ redirect_to root_path
+ end
end
# def checkin_process
@@ -25,4 +28,10 @@ class BaseOrigamiController < ActionController::Base
def get_cashier
@cashier = Employee.where("role = 'cashier' AND token_session <> ''")
end
+
+ #Shop Name in Navbor
+ def shop_detail
+ @shop = Shop.first
+ end
+
end
diff --git a/app/controllers/base_report_controller.rb b/app/controllers/base_report_controller.rb
index 7689ed54..51c250f8 100755
--- a/app/controllers/base_report_controller.rb
+++ b/app/controllers/base_report_controller.rb
@@ -2,10 +2,14 @@ class BaseReportController < ActionController::Base
include LoginVerification
layout "application"
+ before_action :check_user
+
#before_action :check_installation
protect_from_forgery with: :exception
- rescue_from CanCan::AccessDenied do |exception|
+ helper_method :shop_detail
+
+ rescue_from CanCan::AccessDenied do |exception|
flash[:warning] = exception.message
redirect_to root_path
end
@@ -80,4 +84,15 @@ class BaseReportController < ActionController::Base
return from, to
end
+
+ def check_user
+ if current_user.nil?
+ redirect_to root_path
+ end
+ end
+
+ #Shop Name in Navbor
+ def shop_detail
+ @shop = Shop.first
+ end
end
diff --git a/app/controllers/base_waiter_controller.rb b/app/controllers/base_waiter_controller.rb
index ca4622db..94d1cd45 100755
--- a/app/controllers/base_waiter_controller.rb
+++ b/app/controllers/base_waiter_controller.rb
@@ -2,6 +2,21 @@ class BaseWaiterController < ActionController::Base
include LoginVerification
layout "waiter"
+ before_action :check_user
+
#before_action :check_installation
protect_from_forgery with: :exception
+
+ helper_method :shop_detail
+
+ def check_user
+ if current_user.nil?
+ redirect_to root_path
+ end
+ end
+
+ #Shop Name in Navbor
+ def shop_detail
+ @shop = Shop.first
+ end
end
diff --git a/app/controllers/concerns/login_verification.rb b/app/controllers/concerns/login_verification.rb
index bb9df067..14b1e2e1 100755
--- a/app/controllers/concerns/login_verification.rb
+++ b/app/controllers/concerns/login_verification.rb
@@ -33,10 +33,10 @@ module LoginVerification
protected
# Authenticate the user with token based authentication
def authenticate
- authenticate_session_token || render_unauthorized
+ authenticate_session_token || render_unauthorized
end
- def authenticate_session_token
+ def authenticate_session_token
token = session[:session_token]
if (token)
#@current_user = User.find_by(api_key: token)
@@ -50,7 +50,7 @@ module LoginVerification
end
end
- def render_unauthorized()
+ def render_unauthorized
redirect_to root_path
end
diff --git a/app/controllers/crm/bookings_controller.rb b/app/controllers/crm/bookings_controller.rb
index 30a9eb92..7e6c3c83 100755
--- a/app/controllers/crm/bookings_controller.rb
+++ b/app/controllers/crm/bookings_controller.rb
@@ -15,9 +15,4 @@ class Crm::BookingsController < BaseCrmController
end
end
- #Shop Name in Navbor
- helper_method :shop_detail
- def shop_detail
- @shop = Shop.first
- end
end
diff --git a/app/controllers/crm/customers_controller.rb b/app/controllers/crm/customers_controller.rb
index 83a437a2..3082687b 100755
--- a/app/controllers/crm/customers_controller.rb
+++ b/app/controllers/crm/customers_controller.rb
@@ -143,7 +143,7 @@ class Crm::CustomersController < BaseCrmController
:body => member_params,
:headers => {
'Content-Type' => 'application/json',
- 'Accept' => 'application/json; version=2'
+ 'Accept' => 'application/json; version=3'
},
:timeout => 10
)
@@ -269,7 +269,7 @@ end
:body => member_params,
:headers => {
'Content-Type' => 'application/json',
- 'Accept' => 'application/json; version=2'
+ 'Accept' => 'application/json; version=3'
},
:timeout => 10
)
@@ -328,7 +328,7 @@ end
:body => member_params,
:headers => {
'Content-Type' => 'application/json',
- 'Accept' => 'application/json; version=2'
+ 'Accept' => 'application/json; version=3'
},
:timeout => 10
)
@@ -396,12 +396,7 @@ end
def customer_params
params.require(:customer).permit(:id, :name, :company, :contact_no, :email,
- :date_of_birth,:salutation,:gender,:nrc_no,:address,:card_no, :paypar_account_no, :customer_type)
+ :date_of_birth,:salutation,:gender,:nrc_no,:address,:card_no, :paypar_account_no, :customer_type, :image_path)
end
-
- #Shop Name in Navbor
- helper_method :shop_detail
- def shop_detail
- @shop = Shop.first
- end
+
end
diff --git a/app/controllers/crm/dining_queues_controller.rb b/app/controllers/crm/dining_queues_controller.rb
index 4b1eddcc..e52abeea 100755
--- a/app/controllers/crm/dining_queues_controller.rb
+++ b/app/controllers/crm/dining_queues_controller.rb
@@ -142,10 +142,5 @@ class Crm::DiningQueuesController < BaseCrmController
def dining_queue_params
params.require(:dining_queue).permit(:customer_id, :name, :contact_no, :queue_no,:status,:seater,:remark)
end
-
- #Shop Name in Navbor
- helper_method :shop_detail
- def shop_detail
- @shop = Shop.first
- end
+
end
diff --git a/app/controllers/crm/home_controller.rb b/app/controllers/crm/home_controller.rb
index b5acf59a..398fc96a 100755
--- a/app/controllers/crm/home_controller.rb
+++ b/app/controllers/crm/home_controller.rb
@@ -56,10 +56,5 @@ class Crm::HomeController < BaseCrmController
# end
# end
- #Shop Name in Navbor
- helper_method :shop_detail
- def shop_detail
- @shop = Shop.first
- end
end
diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb
index 3ebafa99..d2b0ad36 100755
--- a/app/controllers/home_controller.rb
+++ b/app/controllers/home_controller.rb
@@ -1,6 +1,21 @@
class HomeController < ApplicationController
# layout "application", except: [:index, :show]
- # skip_before_action only: [:index, :show, :create, :update, :destroy]
+ # skip_before_action :authenticate, only: [:index, :show, :create, :update, :destroy]
+
+ before_action :check_user, only: :dashboard
+
+ helper_method :shop_detail
+
+ # Special check for only dashboard
+ def check_user
+ if current_user.nil?
+ redirect_to root_path
+ end
+ end
+
+ def current_user
+ @current_user ||= Employee.find_by_token_session(session[:session_token]) if session[:session_token]
+ end
def index
# @employees = Employee.all_emp_except_waiter.order("name asc")
@@ -65,63 +80,78 @@ class HomeController < ApplicationController
end
def dashboard
- @from, @to = get_date_range_from_params
+ @from, @to, @from_time, @to_time = get_date_range_from_params
@shop = Shop.first
today = DateTime.now.strftime('%Y-%m-%d')
- @orders = Sale::where("payment_status='new' and sale_status='bill' and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'").count()
- @sales = Sale::where("payment_status='paid' and sale_status='completed' and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'").count()
-
- @top_products = Sale.top_products(today,@from,@to).sum('i.qty')
- @bottom_products = Sale.bottom_products(today,@from,@to).sum('i.qty')
- @hourly_sales = Sale.hourly_sales(today,@from,@to).sum(:grand_total)
+ if !@from.nil? && !@to.nil?
+ if !@from_time.nil? && @to_time.nil?
+ @orders = Sale::where("payment_status='new' and sale_status='bill' and DATE_FORMAT(receipt_date,'%Y-%m-%d') between '#{@from}' and '#{@to}' and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%H:%m') between '#{@from_time}' and '#{@to_time}'").count()
+ else
+ @orders = Sale::where("payment_status='new' and sale_status='bill' and DATE_FORMAT(receipt_date,'%Y-%m-%d') between '#{@from}' and '#{@to}'").count()
+ end
+ else
+ @orders = Sale::where("payment_status='new' and sale_status='bill' and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'").count()
+ end
+ if !@from.nil? && !@to.nil?
+ if !@from_time.nil? && @to_time.nil?
+ @sales = Sale::where("payment_status='paid' and sale_status='completed' and DATE_FORMAT(receipt_date,'%Y-%m-%d') between '#{@from}' and '#{@to}' and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%H:%m') between '#{@from_time}' and '#{@to_time}'").count()
+ else
+ @sales = Sale::where("payment_status='paid' and sale_status='completed' and DATE_FORMAT(receipt_date,'%Y-%m-%d') between '#{@from}' and '#{@to}'").count()
+ end
+ else
+ @sales = Sale::where("payment_status='paid' and sale_status='completed' and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'").count()
+ end
+ @top_products = Sale.top_products(today,current_user,@from,@to,@from_time,@to_time).sum('i.qty')
+ @bottom_products = Sale.bottom_products(today,current_user,@from,@to,@from_time,@to_time).sum('i.qty')
+ @hourly_sales = Sale.hourly_sales(today,current_user,@from,@to,@from_time,@to_time).sum(:grand_total)
# .group_by_hour(:created_at, :time_zone => 'Asia/Rangoon',format: '%I:%p')
# .sum(:grand_total)
- @employee_sales = Sale.employee_sales(today,@from,@to)
+ @employee_sales = Sale.employee_sales(today,current_user,@from,@to,@from_time,@to_time)
.sum('(CASE WHEN sp.payment_method="cash" THEN (sp.payment_amount - sales.amount_changed) ELSE sp.payment_amount END)')
- @inventories = StockJournal.inventory_balances(today,@from,@to).sum(:balance)
+ @inventories = StockJournal.inventory_balances(today,@from,@to,@from_time,@to_time).sum(:balance)
- @total_sale = Sale.total_sale(today,current_user,@from,@to)
- @total_count = Sale.total_count(today,current_user,@from,@to)
- @total_card = Sale.total_card_sale(today,current_user,@from,@to)
- @total_credit = Sale.credit_payment(today,current_user,@from,@to)
+ @total_sale = Sale.total_sale(today,current_user,@from,@to,@from_time,@to_time)
+ @total_count = Sale.total_count(today,current_user,@from,@to,@from_time,@to_time)
+ @total_card = Sale.total_card_sale(today,current_user,@from,@to,@from_time,@to_time)
+ @total_credit = Sale.credit_payment(today,current_user,@from,@to,@from_time,@to_time)
@sale_data = Array.new
- @total_payment_methods = Sale.total_payment_methods(today,current_user,@from,@to)
+ @total_payment_methods = Sale.total_payment_methods(today,current_user,@from,@to,@from_time,@to_time)
if !@total_payment_methods.nil?
@total_payment_methods.each do |payment|
- if payment.payment_method == "mpu" || payment.payment_method == "visa" || payment.payment_method == "master" || payment.payment_method == "jcb"
- pay = Sale.payment_sale('card', today, current_user,@from,@to)
+ if payment.payment_method == "mpu" || payment.payment_method == "visa" || payment.payment_method == "master" || payment.payment_method == "jcb" || payment.payment_method == "unionpay"
+ pay = Sale.payment_sale('card', today, current_user,@from,@to,@from_time,@to_time)
@sale_data.push({'card' => pay.payment_amount})
else
- pay = Sale.payment_sale(payment.payment_method, today, current_user,@from,@to)
+ pay = Sale.payment_sale(payment.payment_method, today, current_user,@from,@to,@from_time,@to_time)
@sale_data.push({payment.payment_method => pay.payment_amount})
end
end
end
- @summ_sale = Sale.summary_sale_receipt(today,current_user,@from,@to)
- @total_customer = Sale.total_customer(today,current_user,@from,@to)
- @total_dinein = Sale.total_dinein(today,current_user,@from,@to)
- @total_takeaway = Sale.total_takeaway(today,current_user,@from,@to)
- @total_other_customer = Sale.total_other_customer(today,current_user,@from,@to)
- @total_membership = Sale.total_membership(today,current_user,@from,@to)
+ @summ_sale = Sale.summary_sale_receipt(today,current_user,@from,@to,@from_time,@to_time)
+ @total_customer = Sale.total_customer(today,current_user,@from,@to,@from_time,@to_time)
+ @total_dinein = Sale.total_dinein(today,current_user,@from,@to,@from_time,@to_time)
+ @total_takeaway = Sale.total_takeaway(today,current_user,@from,@to,@from_time,@to_time)
+ @total_other_customer = Sale.total_other_customer(today,current_user,@from,@to,@from_time,@to_time)
+ @total_membership = Sale.total_membership(today,current_user,@from,@to,@from_time,@to_time)
- @total_order = Sale.total_order(today,current_user,@from,@to)
- @total_accounts = Sale.total_account(today,current_user,@from,@to)
+ @total_order = Sale.total_order(today,current_user,@from,@to,@from_time,@to_time)
+ @total_accounts = Sale.total_account(today,current_user,@from,@to,@from_time,@to_time)
@account_data = Array.new
if !@total_accounts.nil?
@total_accounts.each do |account|
- acc = Sale.account_data(account.account_id, today,current_user,@from,@to)
+ acc = Sale.account_data(account.account_id, today,current_user,@from,@to,@from_time,@to_time)
if !acc.nil?
@account_data.push({account.title => acc.cnt_acc, account.title + '_amount' => acc.total_acc})
end
end
end
- @top_items = Sale.top_items(today,current_user,@from,@to)
- @total_foc_items = Sale.total_foc_items(today,current_user,@from,@to)
+ @top_items = Sale.top_items(today,current_user,@from,@to,@from_time,@to_time)
+ @total_foc_items = Sale.total_foc_items(today,current_user,@from,@to,@from_time,@to_time)
# get printer info
@print_settings = PrintSetting.get_precision_delimiter()
@@ -135,12 +165,6 @@ class HomeController < ApplicationController
render :json => {:status=> "Success", :url => root_path }.to_json
end
- #Shop Name in Navbor
- helper_method :shop_detail
- def shop_detail
- @shop = Shop.first
- end
-
private
# Never trust parameters from the scary internet, only allow the white list through.
@@ -181,17 +205,27 @@ class HomeController < ApplicationController
def get_date_range_from_params
from = params[:from]
- to = params[:to]
+ to = params[:to]
+ from_time = params[:from_time]
+ to_time = params[:to_time]
if from.present? && to.present?
- f_date = DateTime.parse(from)
- t_date = DateTime.parse(to)
- f_time = Time.mktime(f_date.year,f_date.month,f_date.day,f_date.hour,f_date.min,f_date.sec)
- t_time = Time.mktime(t_date.year,t_date.month,t_date.day,t_date.hour,t_date.min,t_date.sec)
- from = f_time.beginning_of_day.utc.getlocal
- to = t_time.end_of_day.utc.getlocal
+ # f_date = DateTime.parse(from)
+ # t_date = DateTime.parse(to)
+ # f_time = Time.mktime(f_date.year,f_date.month,f_date.day,f_date.hour,f_date.min,f_date.sec)
+ # t_time = Time.mktime(t_date.year,t_date.month,t_date.day,t_date.hour,t_date.min,t_date.sec)
+ # from = f_time.beginning_of_day.utc.getlocal
+ # to = t_time.end_of_day.utc.getlocal
+
+ from = DateTime.parse(from).utc.getlocal.strftime('%Y-%m-%d')
+ to = DateTime.parse(to).utc.getlocal.strftime('%Y-%m-%d')
end
- return from, to
+ return from, to, from_time, to_time
+ end
+
+ #Shop Name in Navbor
+ def shop_detail
+ @shop = Shop.first
end
end
diff --git a/app/controllers/install_controller.rb b/app/controllers/install_controller.rb
index 1ff003db..ccc1bf3e 100755
--- a/app/controllers/install_controller.rb
+++ b/app/controllers/install_controller.rb
@@ -3,6 +3,8 @@ class InstallController < BaseController
skip_before_action :verify_authenticity_token
# before_action :check_license
+ helper_method :shop_detail
+
def index
end
@@ -75,4 +77,9 @@ class InstallController < BaseController
# return nil
# end
# end
+
+ #Shop Name in Navbor
+ def shop_detail
+ @shop = Shop.first
+ end
end
diff --git a/app/controllers/oqs/backhome_controller.rb b/app/controllers/oqs/backhome_controller.rb
index 990fa459..4ac5f0a2 100755
--- a/app/controllers/oqs/backhome_controller.rb
+++ b/app/controllers/oqs/backhome_controller.rb
@@ -30,12 +30,6 @@ class Oqs::HomeController < BaseOqsController
@queue_stations_items
end
- #Shop Name in Navbor
- helper_method :shop_detail
- def shop_detail
- @shop = Shop.first
- end
-
# Get Order items
def get_order_items
items = []
@@ -129,9 +123,4 @@ class Oqs::HomeController < BaseOqsController
# completed_order = AssignedOrderItem.group(:order_id).where('delivery_status=true');
end
- #Shop Name in Navbor
- helper_method :shop_detail
- def shop_detail
- @shop = Shop.first
- end
end
diff --git a/app/controllers/oqs/edit_controller.rb b/app/controllers/oqs/edit_controller.rb
old mode 100755
new mode 100644
index ea2e6662..ccef4e4a
--- a/app/controllers/oqs/edit_controller.rb
+++ b/app/controllers/oqs/edit_controller.rb
@@ -3,9 +3,15 @@ class Oqs::EditController < BaseOqsController
assigned_item_id = params[:id]
@link_type = params[:type]
@dining_type = nil
+ @booking = nil
if params[:type] == 'oqs'
assigned_item = AssignedOrderItem.find(assigned_item_id)
@order_item = OrderItem.where("order_id='#{ assigned_item.order_id }' AND item_instance_code='#{ assigned_item.instance_code }'")
+ elsif params[:type] == "pending"
+ assigned_item = OrderItem.find(assigned_item_id)
+ @booking = Booking.joins(" JOIN booking_orders as bko on bko.booking_id = bookings.booking_id")
+ .where("bko.order_id = '#{assigned_item.order_id}'").first()
+ @order_item = OrderItem.where("order_id='#{ assigned_item.order_id }' AND item_instance_code='#{ assigned_item.item_instance_code }'")
else
assigned_item = OrderItem.find(assigned_item_id)
dining = DiningFacility.find_by_id(params[:type])
diff --git a/app/controllers/oqs/home_controller.rb b/app/controllers/oqs/home_controller.rb
index 95c4d833..19d4c17f 100755
--- a/app/controllers/oqs/home_controller.rb
+++ b/app/controllers/oqs/home_controller.rb
@@ -244,10 +244,4 @@ class Oqs::HomeController < BaseOqsController
.group("order_queue_stations.id")
end
- #Shop Name in Navbor
- helper_method :shop_detail
- def shop_detail
- @shop = Shop.first
- end
-
end
diff --git a/app/controllers/oqs/print_controller.rb b/app/controllers/oqs/print_controller.rb
index 5f973c7a..baa4af40 100755
--- a/app/controllers/oqs/print_controller.rb
+++ b/app/controllers/oqs/print_controller.rb
@@ -102,9 +102,4 @@ class Oqs::PrintController < ApplicationController
end
end
- #Shop Name in Navbor
- helper_method :shop_detail
- def shop_detail
- @shop = Shop.first
- end
end
\ No newline at end of file
diff --git a/app/controllers/origami/addorders_controller.rb b/app/controllers/origami/addorders_controller.rb
index 35f672ef..0e905724 100755
--- a/app/controllers/origami/addorders_controller.rb
+++ b/app/controllers/origami/addorders_controller.rb
@@ -1,6 +1,6 @@
class Origami::AddordersController < BaseOrigamiController
# before_action :set_dining, only: [:detail]
-
+
def index
@tables = Table.all.active.order('zone_id asc').group("zone_id")
@rooms = Room.all.active.order('zone_id asc').group("zone_id")
@@ -94,20 +94,20 @@ class Origami::AddordersController < BaseOrigamiController
extra_time = Time.at(time)
end
end
- if i["parent_order_item_id"]
- items = {"order_item_id": i["order_item_id"],"item_instance_code": i["item_instance_code"],"quantity": i["quantity"],"parent_order_item_id": i["parent_order_item_id"],"options": i["options"]}
+ if i["parent_order_item_id"];
+ items = {"order_item_id": i["order_item_id"],"item_instance_code": i["item_instance_code"],"quantity": i["quantity"],"parent_order_item_id": i["parent_order_item_id"],"options": JSON.parse(i["options"])}
else
- items = {"order_item_id": i["order_item_id"],"item_instance_code": i["item_instance_code"],"quantity": i["quantity"],"options": i["options"]}
+ items = {"order_item_id": i["order_item_id"],"item_instance_code": i["item_instance_code"],"quantity": i["quantity"],"options": JSON.parse(i["options"])}
end
items_arr.push(items)
}
# begin
- if params[:order_source] == "quick_service"
- customer_id = "CUS-000000000002" # for no customer id from mobile
- else
+ # if params[:order_source] == "quick_service"
+ # customer_id = "CUS-000000000002" # for no customer id from mobile
+ # else
customer_id = params[:customer_id] == ""? "CUS-000000000001" : params[:customer_id] # for no customer id from mobile
- end
+ # end
@order = Order.new
@order.source = params[:order_source]
@order.order_type = params[:order_type]
@@ -226,9 +226,4 @@ class Origami::AddordersController < BaseOrigamiController
# @dining = DiningFacility.find(params[:id])
# end
- #Shop Name in Navbor
- helper_method :shop_detail
- def shop_detail
- @shop = Shop.first
- end
end
diff --git a/app/controllers/origami/alipay_controller.rb b/app/controllers/origami/alipay_controller.rb
new file mode 100644
index 00000000..3f449856
--- /dev/null
+++ b/app/controllers/origami/alipay_controller.rb
@@ -0,0 +1,77 @@
+class Origami::AlipayController < BaseOrigamiController
+ def index
+ @sale_id = params[:sale_id]
+ @cashier_type = params[:type]
+ # limit alipay_amount
+ sale_data = Sale.find_by_sale_id(@sale_id)
+ total = 0
+ @alipaycount = 0
+ @shop = Shop::ShopDetail
+ @rounding_adj = 0
+ @can_alipay = 0
+ @member_discount = 0
+ @sub_total = 0
+ @membership_id = nil
+ @receipt_no = nil
+ if !sale_data.nil?
+ total = sale_data.grand_total
+
+ others = 0
+
+ if @shop.is_rounding_adj
+ new_total = Sale.get_rounding_adjustment(sale_data.grand_total)
+ else
+ new_total = sale_data.grand_total
+ end
+ @rounding_adj = new_total-sale_data.grand_total
+
+ sale_data.sale_payments.each do |sale_payment|
+ if sale_payment.payment_method == "alipay"
+ @alipaycount = @alipaycount + sale_payment.payment_amount
+ else
+ others = others + sale_payment.payment_amount
+ end
+ end
+ @can_alipay = total - @alipaycount - others
+
+ @member_discount = MembershipSetting.find_by_discount(1)
+ @sub_total = sale_data.total_amount
+ @membership_id = sale_data.customer.membership_id
+ #for bank integration
+ @receipt_no = sale_data.receipt_no
+ end
+
+ bank_integration = Lookup.collection_of('bank_integration')
+ @bank_integration = 0
+ if !bank_integration[0].nil?
+ @bank_integration = bank_integration[0][1]
+ end
+ end
+
+ def create
+ cash = params[:amount]
+ sale_id = params[:sale_id]
+ ref_no = params[:ref_no]
+ if(Sale.exists?(sale_id))
+ saleObj = Sale.find(sale_id)
+ shop_details = Shop::ShopDetail
+
+ # rounding adjustment
+ # if shop_details.is_rounding_adj
+ # new_total = Sale.get_rounding_adjustment(saleObj.grand_total)
+ # rounding_adj = new_total-saleObj.grand_total
+ # saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:rounding_adj)
+ # end
+
+ # saleObj = Sale.find(sale_id)
+ sale_payment = SalePayment.new
+ @status, @sale = sale_payment.process_payment(saleObj, @user, cash, "alipay",ref_no)
+ end
+ end
+
+ #Shop Name in Navbor
+ helper_method :shop_detail
+ def shop_detail
+ @shop = Shop.first
+ end
+end
diff --git a/app/controllers/origami/bank_integration_controller.rb b/app/controllers/origami/bank_integration_controller.rb
index 6dde10da..cb735873 100644
--- a/app/controllers/origami/bank_integration_controller.rb
+++ b/app/controllers/origami/bank_integration_controller.rb
@@ -96,9 +96,4 @@ class Origami::BankIntegrationController < ApplicationController #BaseOrigamiCon
render json: response
end
- #Shop Name in Navbor
- helper_method :shop_detail
- def shop_detail
- @shop = Shop.first
- end
end
diff --git a/app/controllers/origami/card_payments_controller.rb b/app/controllers/origami/card_payments_controller.rb
index cd08c16a..e0c56971 100755
--- a/app/controllers/origami/card_payments_controller.rb
+++ b/app/controllers/origami/card_payments_controller.rb
@@ -24,9 +24,4 @@ class Origami::CardPaymentsController < BaseOrigamiController
def create
end
- #Shop Name in Navbor
- helper_method :shop_detail
- def shop_detail
- @shop = Shop.first
- end
end
diff --git a/app/controllers/origami/cash_ins_controller.rb b/app/controllers/origami/cash_ins_controller.rb
index 4d7c2b64..441cd94e 100755
--- a/app/controllers/origami/cash_ins_controller.rb
+++ b/app/controllers/origami/cash_ins_controller.rb
@@ -14,10 +14,5 @@ class Origami::CashInsController < BaseOrigamiController
shift.cash_in = shift.cash_in + amount.to_i
shift.save
end
-
- #Shop Name in Navbor
- helper_method :shop_detail
- def shop_detail
- @shop = Shop.first
- end
+
end
diff --git a/app/controllers/origami/cash_mgmt_controller.rb b/app/controllers/origami/cash_mgmt_controller.rb
index 1f48370e..916f5d8b 100755
--- a/app/controllers/origami/cash_mgmt_controller.rb
+++ b/app/controllers/origami/cash_mgmt_controller.rb
@@ -8,9 +8,4 @@ class Origami::CashMgmtController < ApplicationController
def create
end
- #Shop Name in Navbor
- helper_method :shop_detail
- def shop_detail
- @shop = Shop.first
- end
end
diff --git a/app/controllers/origami/cash_outs_controller.rb b/app/controllers/origami/cash_outs_controller.rb
index cc22516c..8c81b5cb 100755
--- a/app/controllers/origami/cash_outs_controller.rb
+++ b/app/controllers/origami/cash_outs_controller.rb
@@ -13,9 +13,4 @@ class Origami::CashOutsController < BaseOrigamiController
shift.save
end
- #Shop Name in Navbor
- helper_method :shop_detail
- def shop_detail
- @shop = Shop.first
- end
end
diff --git a/app/controllers/origami/check_in_process_controller.rb b/app/controllers/origami/check_in_process_controller.rb
index 48d55c9a..ad3efee0 100644
--- a/app/controllers/origami/check_in_process_controller.rb
+++ b/app/controllers/origami/check_in_process_controller.rb
@@ -36,9 +36,4 @@ class Origami::CheckInProcessController < BaseOrigamiController
end
end
- #Shop Name in Navbor
- helper_method :shop_detail
- def shop_detail
- @shop = Shop.first
- end
end
diff --git a/app/controllers/origami/credit_payments_controller.rb b/app/controllers/origami/credit_payments_controller.rb
index 4fd9ba71..d70ef870 100755
--- a/app/controllers/origami/credit_payments_controller.rb
+++ b/app/controllers/origami/credit_payments_controller.rb
@@ -47,10 +47,4 @@ class Origami::CreditPaymentsController < BaseOrigamiController
end
end
- #Shop Name in Navbor
- helper_method :shop_detail
- def shop_detail
- @shop = Shop.first
- end
-
end
diff --git a/app/controllers/origami/customers_controller.rb b/app/controllers/origami/customers_controller.rb
index 25dc9748..c3a3d3b9 100755
--- a/app/controllers/origami/customers_controller.rb
+++ b/app/controllers/origami/customers_controller.rb
@@ -98,10 +98,10 @@ class Origami::CustomersController < BaseOrigamiController
def update_sale_by_customer
- id = params[:sale_id][0,3]
- customer_id = params[:customer_id]
- customer = Customer.find(customer_id)
-
+ id = params[:sale_id][0,3]
+ customer_id = params[:customer_id]
+ customer = Customer.find(customer_id)
+ order_source = params[:type]
# Check and find with card no
# if(!customer_id.include? "CUS")
# customer = Customer.find_by_paypar_account_no(customer_id)
@@ -135,16 +135,11 @@ class Origami::CustomersController < BaseOrigamiController
if status == true
render json: JSON.generate({:status => true})
if(id == "SAL")
- sale.compute_by_sale_items(sale.sale_id, sale.sale_items, sale.total_discount)
+ sale.compute_by_sale_items(sale.sale_id, sale.sale_items, sale.total_discount, nil, order_source)
end
else
render json: JSON.generate({:status => false, :error_message => "Record not found"})
end
end
-
- #Shop Name in Navbor
- helper_method :shop_detail
- def shop_detail
- @shop = Shop.first
- end
+
end
diff --git a/app/controllers/origami/dashboard_controller.rb b/app/controllers/origami/dashboard_controller.rb
index a3d08132..f888ac57 100644
--- a/app/controllers/origami/dashboard_controller.rb
+++ b/app/controllers/origami/dashboard_controller.rb
@@ -58,8 +58,4 @@ class Origami::DashboardController < BaseOrigamiController
@current_user = current_user
end
- helper_method :shop_detail
- def shop_detail
- @shop = Shop.first
- end
end
diff --git a/app/controllers/origami/discounts_controller.rb b/app/controllers/origami/discounts_controller.rb
index 24b2c83f..6add4a12 100755
--- a/app/controllers/origami/discounts_controller.rb
+++ b/app/controllers/origami/discounts_controller.rb
@@ -20,10 +20,12 @@ class Origami::DiscountsController < BaseOrigamiController
#discount page show from origami index with selected order
def create
+ order_source = params[:cashier_type]
sale_id = params[:sale_id]
discount_items = JSON.parse(params[:discount_items])
overall_discount = params[:overall_discount]
sub_total = params[:sub_total]
+
if Sale.exists?(sale_id)
sale = Sale.find(sale_id)
@@ -82,7 +84,7 @@ class Origami::DiscountsController < BaseOrigamiController
sale_audit = SaleAudit.record_audit_discount(sale.sale_id,sale.cashier_id, action_by,remark,"OVERALLDISCOUNT" )
end
- sale.compute_by_sale_items(sale_id, sale.sale_items, overall_discount.to_f)
+ sale.compute_by_sale_items(sale_id, sale.sale_items, overall_discount.to_f, nil,order_source)
if !table.nil?
result = {:status=> "Success", :table_id => table_id, :table_type => table.type }
else
@@ -102,6 +104,7 @@ class Origami::DiscountsController < BaseOrigamiController
# Remove selected discount Items
def remove_discount_items
+ order_source = params[:cashier_type]
sale_id = params[:sale_id]
discount_items = JSON.parse(params[:discount_items])
if Sale.exists?(sale_id)
@@ -136,7 +139,7 @@ class Origami::DiscountsController < BaseOrigamiController
# sale.grand_total = (sale.total_amount - sale.total_discount) + sale.total_tax;
# sale.save
# Re-calc All Amount in Sale
- sale.compute_by_sale_items(sale_id, sale.sale_items, sale.total_discount)
+ sale.compute_by_sale_items(sale_id, sale.sale_items, sale.total_discount, nil, order_source)
if table.nil?
result = {:status=> "Success"}
else
@@ -158,6 +161,7 @@ class Origami::DiscountsController < BaseOrigamiController
# Remove all discount Items
def remove_all_discount
sale_id = params[:id]
+ order_source = params[:type]
if Sale.exists?(sale_id)
sale = Sale.find(sale_id)
@@ -197,7 +201,7 @@ class Origami::DiscountsController < BaseOrigamiController
sale_audit = SaleAudit.record_audit_discount(sale.sale_id,sale.cashier_id, action_by,remark,"REMOVEALLDISCOUNT" )
# Re-calc All Amount in Sale
- sale.compute_by_sale_items(sale_id, sale.sale_items, 0)
+ sale.compute_by_sale_items(sale_id, sale.sale_items, 0, nil, order_source)
if table.nil?
result = {:status=> "Success"}
else
@@ -218,7 +222,7 @@ class Origami::DiscountsController < BaseOrigamiController
# Member Discount
def member_discount
-
+ order_source = params[:cashier_type]
sale_id = params[:sale_id]
is_card = params[:is_card]
sub_total = params[:sub_total]
@@ -273,7 +277,7 @@ class Origami::DiscountsController < BaseOrigamiController
auth_token:auth_token}.to_json,
:headers => {
'Content-Type' => 'application/json',
- 'Accept' => 'application/json; version=2'
+ 'Accept' => 'application/json; version=3'
}, :timeout => 10)
rescue HTTParty::Error
response = {"status": false, "message": "Can't open membership server " }
@@ -297,7 +301,7 @@ class Origami::DiscountsController < BaseOrigamiController
if response["discount_bonus_earned"]
discount_amount = discount_amount + response["discount_bonus_earned"]
end
- sale.compute_by_sale_items(sale_id, sale.sale_items, discount_amount, 'member_discount')
+ sale.compute_by_sale_items(sale_id, sale.sale_items, discount_amount, 'member_discount', order_source)
result = {:status=> "Success",:title=>"Member Discount", :table_id => table_id,:table_type => table_type }
elsif response["status"] == "500"
result = {:status=> response["error"],:title=>"Alert", :table_id => table_id,:table_type => table_type }
@@ -355,9 +359,5 @@ class Origami::DiscountsController < BaseOrigamiController
# redirect_to origami_path(sale_id)
# end
- #Shop Name in Navbor
- helper_method :shop_detail
- def shop_detail
- @shop = Shop.first
- end
+
end
diff --git a/app/controllers/origami/home_controller.rb b/app/controllers/origami/home_controller.rb
index c89b83eb..759cb1b6 100755
--- a/app/controllers/origami/home_controller.rb
+++ b/app/controllers/origami/home_controller.rb
@@ -74,16 +74,6 @@ class Origami::HomeController < BaseOrigamiController
@date = order.created_at
@booking= booking
order.order_items.each do |item|
- if !item.set_menu_items.nil?
- instance_item_sets = JSON.parse(item.set_menu_items)
- arr_instance_item_sets = Array.new
- instance_item_sets.each do |instance_item|
- item_instance_name = MenuItemInstance.find_by_item_instance_code(instance_item["item_instance_code"]).item_instance_name
- arr_instance_item_sets.push(item_instance_name)
- item.price = item.price.to_f + instance_item["price"].to_f
- end
- item.set_menu_items = arr_instance_item_sets
- end
@order_items.push(item)
# assigned_order_items = AssignedOrderItem.find_by_item_code_and_instance_code_and_order_id(item.item_code,item.item_instance_code,item.order_id)
# if !assigned_order_items.nil?
@@ -105,7 +95,7 @@ class Origami::HomeController < BaseOrigamiController
@status_order = 'order'
else
sale = Sale.find(booking.sale_id)
- if sale.sale_status != "completed" && sale.sale_status != 'void'
+ if sale.sale_status != "completed" && sale.sale_status != 'void' && sale.sale_status != 'spoile' && sale.sale_status != 'waste'
@sale_array.push(sale)
if @status_order == 'order'
@status_order = 'sale'
@@ -136,12 +126,6 @@ class Origami::HomeController < BaseOrigamiController
end
end
- #Shop Name in Navbor
- helper_method :shop_detail
- def shop_detail
- @shop = Shop.first
- end
-
private
def set_dining
diff --git a/app/controllers/origami/home_controller_bk.rb b/app/controllers/origami/home_controller_bk.rb
index 3e414665..4839f15c 100755
--- a/app/controllers/origami/home_controller_bk.rb
+++ b/app/controllers/origami/home_controller_bk.rb
@@ -81,9 +81,4 @@ class Origami::HomeController < ApplicationController
end
end
- #Shop Name in Navbor
- helper_method :shop_detail
- def shop_detail
- @shop = Shop.first
- end
end
diff --git a/app/controllers/origami/in_duties_controller.rb b/app/controllers/origami/in_duties_controller.rb
index 945f3bd9..9846516e 100755
--- a/app/controllers/origami/in_duties_controller.rb
+++ b/app/controllers/origami/in_duties_controller.rb
@@ -169,9 +169,4 @@ class Origami::InDutiesController < BaseOrigamiController
params.require(:in_duty).permit(:id, :dinning_id, :commissioner_ids, :in_time, :out_time)
end
- #Shop Name in Navbor
- helper_method :shop_detail
- def shop_detail
- @shop = Shop.first
- end
end
diff --git a/app/controllers/origami/jcb_controller.rb b/app/controllers/origami/jcb_controller.rb
old mode 100755
new mode 100644
index 0604535e..315af34a
--- a/app/controllers/origami/jcb_controller.rb
+++ b/app/controllers/origami/jcb_controller.rb
@@ -5,32 +5,43 @@ class Origami::JcbController < BaseOrigamiController
@cashier_type = params[:type]
# limit jcb_amount
sale_data = Sale.find_by_sale_id(@sale_id)
- total = sale_data.grand_total
+ total = 0
@jcbcount = 0
- others = 0
+ @shop = Shop::ShopDetail
+ @rounding_adj = 0
+ @can_jcb = 0
+ @member_discount= 0
+ @sub_total = 0
+ @membership_id = nil
+ @receipt_no = nil
+ if !sale_data.nil?
+ total = sale_data.grand_total
+
+ others = 0
+
+ if @shop.is_rounding_adj
+ new_total = Sale.get_rounding_adjustment(sale_data.grand_total)
+ else
+ new_total = sale_data.grand_total
+ end
+ @rounding_adj = new_total-sale_data.grand_total
+
+ sale_data.sale_payments.each do |sale_payment|
+ if sale_payment.payment_method == "jcb"
+ @jcbcount = @jcbcount + sale_payment.payment_amount
+ else
+ others = others + sale_payment.payment_amount
+ end
+ end
+ @can_jcb = total - @jcbcount - others
- @shop = Shop::ShopDetail
- if @shop.is_rounding_adj
- new_total = Sale.get_rounding_adjustment(sale_data.grand_total)
- else
- new_total = sale_data.grand_total
+ @member_discount = MembershipSetting.find_by_discount(1)
+ @sub_total = sale_data.total_amount
+ @membership_id = sale_data.customer.membership_id
+ #for bank integration
+ @receipt_no = sale_data.receipt_no
end
- @rounding_adj = new_total-sale_data.grand_total
-
- sale_data.sale_payments.each do |sale_payment|
- if sale_payment.payment_method == "jcb"
- @jcbcount = @jcbcount + sale_payment.payment_amount
- else
- others = others + sale_payment.payment_amount
- end
- end
- @can_jcb = total - @jcbcount - others
- @member_discount = MembershipSetting.find_by_discount(1)
- @sub_total = sale_data.total_amount
- @membership_id = sale_data.customer.membership_id
- #for bank integration
- @receipt_no = sale_data.receipt_no
bank_integration = Lookup.collection_of('bank_integration')
@bank_integration = 0
if !bank_integration[0].nil?
@@ -41,6 +52,7 @@ class Origami::JcbController < BaseOrigamiController
def create
cash = params[:amount]
sale_id = params[:sale_id]
+ ref_no = params[:ref_no]
if(Sale.exists?(sale_id))
saleObj = Sale.find(sale_id)
shop_details = Shop::ShopDetail
@@ -54,7 +66,7 @@ class Origami::JcbController < BaseOrigamiController
# saleObj = Sale.find(sale_id)
sale_payment = SalePayment.new
- @status, @sale = sale_payment.process_payment(saleObj, @user, cash, "jcb")
+ @status, @sale = sale_payment.process_payment(saleObj, @user, cash, "jcb",ref_no)
end
end
diff --git a/app/controllers/origami/junction_pay_controller.rb b/app/controllers/origami/junction_pay_controller.rb
new file mode 100644
index 00000000..1c52a271
--- /dev/null
+++ b/app/controllers/origami/junction_pay_controller.rb
@@ -0,0 +1,70 @@
+class Origami::JunctionPayController < BaseOrigamiController
+
+ def index
+ @sale_id = params[:sale_id]
+ @cashier_type = params[:type]
+ # limit jcb_amount
+ sale_data = Sale.find_by_sale_id(@sale_id)
+ total = sale_data.grand_total
+ @junction_pay_count = 0
+ others = 0
+ @cashier_id = current_user.emp_id
+
+ @payment_method_setting_nav = PaymentMethodSetting.all
+ @shop = Shop::ShopDetail
+ if @shop.is_rounding_adj
+ new_total = Sale.get_rounding_adjustment(sale_data.grand_total)
+ else
+ new_total = sale_data.grand_total
+ end
+ @rounding_adj = new_total-sale_data.grand_total
+
+ sale_data.sale_payments.each do |sale_payment|
+ if sale_payment.payment_method == "JunctionPay"
+ @junction_pay_count = @junction_pay_count + sale_payment.payment_amount
+ else
+ others = others + sale_payment.payment_amount
+ end
+ end
+ @can_junction_pay = total - @junction_pay_count - others
+
+ @member_discount = MembershipSetting.find_by_discount(1)
+ @sub_total = sale_data.total_amount
+ @membership_id = sale_data.customer.membership_id
+ #for bank integration
+ @receipt_no = sale_data.receipt_no
+ end
+
+ def create
+ gift_amount = params[:gift_amount]
+ voucher_amount = params[:voucher_amount]
+ voucher_no = params[:voucher_no]
+ sale_id = params[:sale_id]
+
+ # Gift card or Voucher classified and add for payment_reference
+ remarks = ''
+ cash = (gift_amount.to_f + voucher_amount.to_f)
+ if gift_amount.to_f > 0
+ remarks = "Junciton Gift Card Payment. RefNo-" + voucher_no
+ else
+ remarks = "Junciton Voucher Payment. RefNo-" + voucher_no
+ end
+
+ if(Sale.exists?(sale_id))
+ saleObj = Sale.find(sale_id)
+ shop_details = Shop::ShopDetail
+
+ # rounding adjustment
+ # if shop_details.is_rounding_adj
+ # new_total = Sale.get_rounding_adjustment(saleObj.grand_total)
+ # rounding_adj = new_total-saleObj.grand_total
+ # saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:rounding_adj)
+ # end
+
+ # saleObj = Sale.find(sale_id)
+ sale_payment = SalePayment.new
+ @status, @sale = sale_payment.process_payment(saleObj, @user, cash, "JunctionPay", remarks)
+ end
+ end
+
+end
diff --git a/app/controllers/origami/master_controller.rb b/app/controllers/origami/master_controller.rb
old mode 100755
new mode 100644
index 25bebf55..dc3a83d9
--- a/app/controllers/origami/master_controller.rb
+++ b/app/controllers/origami/master_controller.rb
@@ -5,31 +5,41 @@ class Origami::MasterController < BaseOrigamiController
@cashier_type = params[:type]
# limit master_amount
sale_data = Sale.find_by_sale_id(@sale_id)
- total = sale_data.grand_total
+ total = 0
@mastercount = 0
- others = 0
-
- @shop = Shop::ShopDetail
- if @shop.is_rounding_adj
- new_total = Sale.get_rounding_adjustment(sale_data.grand_total)
- else
- new_total = sale_data.grand_total
- end
- @rounding_adj = new_total-sale_data.grand_total
+ @shop = Shop::ShopDetail
+ @rounding_adj = 0
+ @can_master = 0
+ @member_discount = 0
+ @sub_total = 0
+ @membership_id = nil
+ @receipt_no = nil
+ if !sale_data.nil?
+ total = sale_data.grand_total
+
+ others = 0
+
+ if @shop.is_rounding_adj
+ new_total = Sale.get_rounding_adjustment(sale_data.grand_total)
+ else
+ new_total = sale_data.grand_total
+ end
+ @rounding_adj = new_total-sale_data.grand_total
- sale_data.sale_payments.each do |sale_payment|
- if sale_payment.payment_method == "master"
- @mastercount = @mastercount + sale_payment.payment_amount
- else
- others = others + sale_payment.payment_amount
- end
+ sale_data.sale_payments.each do |sale_payment|
+ if sale_payment.payment_method == "master"
+ @mastercount = @mastercount + sale_payment.payment_amount
+ else
+ others = others + sale_payment.payment_amount
+ end
+ end
+ @can_master = total - @mastercount - others
+ @member_discount = MembershipSetting.find_by_discount(1)
+ @sub_total = sale_data.total_amount
+ @membership_id = sale_data.customer.membership_id
+ #for bank integration
+ @receipt_no = sale_data.receipt_no
end
- @can_master = total - @mastercount - others
- @member_discount = MembershipSetting.find_by_discount(1)
- @sub_total = sale_data.total_amount
- @membership_id = sale_data.customer.membership_id
- #for bank integration
- @receipt_no = sale_data.receipt_no
bank_integration = Lookup.collection_of('bank_integration')
@bank_integration = 0
if !bank_integration[0].nil?
@@ -40,6 +50,7 @@ class Origami::MasterController < BaseOrigamiController
def create
cash = params[:amount]
sale_id = params[:sale_id]
+ ref_no = params[:ref_no]
if(Sale.exists?(sale_id))
saleObj = Sale.find(sale_id)
shop_details = Shop::ShopDetail
@@ -53,7 +64,7 @@ class Origami::MasterController < BaseOrigamiController
# saleObj = Sale.find(sale_id)
sale_payment = SalePayment.new
- @status, @sale = sale_payment.process_payment(saleObj, @user, cash, "master")
+ @status, @sale = sale_payment.process_payment(saleObj, @user, cash, "master",ref_no)
end
end
diff --git a/app/controllers/origami/moveroom_controller.rb b/app/controllers/origami/moveroom_controller.rb
index 5b53f68c..316ab894 100755
--- a/app/controllers/origami/moveroom_controller.rb
+++ b/app/controllers/origami/moveroom_controller.rb
@@ -35,11 +35,5 @@ class Origami::MoveroomController < BaseOrigamiController
end
end
end
-
- #Shop Name in Navbor
- helper_method :shop_detail
- def shop_detail
- @shop = Shop.first
- end
end
diff --git a/app/controllers/origami/movetable_controller.rb b/app/controllers/origami/movetable_controller.rb
index 8da417ac..dfdfcabf 100755
--- a/app/controllers/origami/movetable_controller.rb
+++ b/app/controllers/origami/movetable_controller.rb
@@ -70,10 +70,5 @@ class Origami::MovetableController < BaseOrigamiController
@get_type = Booking.update_dining_facility(booking_array,change_to,change_from)
end
-
- #Shop Name in Navbor
- helper_method :shop_detail
- def shop_detail
- @shop = Shop.first
- end
+
end
diff --git a/app/controllers/origami/mpu_controller.rb b/app/controllers/origami/mpu_controller.rb
old mode 100755
new mode 100644
index ce0dccce..7d3ded34
--- a/app/controllers/origami/mpu_controller.rb
+++ b/app/controllers/origami/mpu_controller.rb
@@ -4,32 +4,43 @@ class Origami::MpuController < BaseOrigamiController
@cashier_type = params[:type]
# limit mpu_amount
sale_data = Sale.find_by_sale_id(@sale_id)
- total = sale_data.grand_total
+ total = 0
@mpucount = 0
- others = 0
-
@shop = Shop::ShopDetail
- if @shop.is_rounding_adj
- new_total = Sale.get_rounding_adjustment(sale_data.grand_total)
- else
- new_total = sale_data.grand_total
- end
- @rounding_adj = new_total-sale_data.grand_total
-
- sale_data.sale_payments.each do |sale_payment|
- if sale_payment.payment_method == "mpu"
- @mpucount = @mpucount + sale_payment.payment_amount
- else
- others = others + sale_payment.payment_amount
- end
- end
- @can_mpu = total - @mpucount - others
+ @rounding_adj = 0
+ @can_mpu = 0
+ @member_discount = 0
+ @sub_total = 0
+ @membership_id = nil
+ @receipt_no = nil
+ if !sale_data.nil?
+ total = sale_data.grand_total
+
+ others = 0
+
+ if @shop.is_rounding_adj
+ new_total = Sale.get_rounding_adjustment(sale_data.grand_total)
+ else
+ new_total = sale_data.grand_total
+ end
+ @rounding_adj = new_total-sale_data.grand_total
+
+ sale_data.sale_payments.each do |sale_payment|
+ if sale_payment.payment_method == "mpu"
+ @mpucount = @mpucount + sale_payment.payment_amount
+ else
+ others = others + sale_payment.payment_amount
+ end
+ end
+ @can_mpu = total - @mpucount - others
+
+ @member_discount = MembershipSetting.find_by_discount(1)
+ @sub_total = sale_data.total_amount
+ @membership_id = sale_data.customer.membership_id
+ #for bank integration
+ @receipt_no = sale_data.receipt_no
+ end
- @member_discount = MembershipSetting.find_by_discount(1)
- @sub_total = sale_data.total_amount
- @membership_id = sale_data.customer.membership_id
- #for bank integration
- @receipt_no = sale_data.receipt_no
bank_integration = Lookup.collection_of('bank_integration')
@bank_integration = 0
if !bank_integration[0].nil?
@@ -40,6 +51,7 @@ class Origami::MpuController < BaseOrigamiController
def create
cash = params[:amount]
sale_id = params[:sale_id]
+ ref_no = params[:ref_no]
if(Sale.exists?(sale_id))
saleObj = Sale.find(sale_id)
shop_details = Shop::ShopDetail
@@ -53,7 +65,7 @@ class Origami::MpuController < BaseOrigamiController
# saleObj = Sale.find(sale_id)
sale_payment = SalePayment.new
- @status, @sale = sale_payment.process_payment(saleObj, @user, cash, "mpu")
+ @status, @sale = sale_payment.process_payment(saleObj, @user, cash, "alipay",ref_no)
end
end
diff --git a/app/controllers/origami/orders_controller.rb b/app/controllers/origami/orders_controller.rb
index 13f5b684..3181d470 100755
--- a/app/controllers/origami/orders_controller.rb
+++ b/app/controllers/origami/orders_controller.rb
@@ -80,10 +80,5 @@ class Origami::OrdersController < BaseOrigamiController
end
end
end
-
- #Shop Name in Navbor
- helper_method :shop_detail
- def shop_detail
- @shop = Shop.first
- end
+
end
diff --git a/app/controllers/origami/other_charges_controller.rb b/app/controllers/origami/other_charges_controller.rb
index 93afc99a..def94a1f 100755
--- a/app/controllers/origami/other_charges_controller.rb
+++ b/app/controllers/origami/other_charges_controller.rb
@@ -19,6 +19,7 @@ class Origami::OtherChargesController < BaseOrigamiController
sale_id = params[:sale_id]
other_charges_items = JSON.parse(params[:other_charges_items])
sub_total = params[:sub_total]
+ cashier_type = params[:cashier_type]
if Sale.exists?(sale_id)
sale = Sale.find(sale_id)
@@ -68,7 +69,7 @@ class Origami::OtherChargesController < BaseOrigamiController
end
# Re-calc All Amount in Sale
- sale.compute_by_sale_items(sale_id, sale.sale_items, sale.total_discount)
+ sale.compute_by_sale_items(sale_id, sale.sale_items, sale.total_discount, nil, cashier_type)
end
if !table.nil?
dining = {:table_id => table_id, :table_type => table.type }
@@ -76,10 +77,5 @@ class Origami::OtherChargesController < BaseOrigamiController
end
end
-
- #Shop Name in Navbor
- helper_method :shop_detail
- def shop_detail
- @shop = Shop.first
- end
+
end
\ No newline at end of file
diff --git a/app/controllers/origami/others_payments_controller.rb b/app/controllers/origami/others_payments_controller.rb
index ab755ea1..e4a39662 100755
--- a/app/controllers/origami/others_payments_controller.rb
+++ b/app/controllers/origami/others_payments_controller.rb
@@ -37,9 +37,4 @@ class Origami::OthersPaymentsController < BaseOrigamiController
def create
end
- #Shop Name in Navbor
- helper_method :shop_detail
- def shop_detail
- @shop = Shop.first
- end
end
diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb
index 78fee237..66d62df6 100755
--- a/app/controllers/origami/payments_controller.rb
+++ b/app/controllers/origami/payments_controller.rb
@@ -27,7 +27,7 @@ class Origami::PaymentsController < BaseOrigamiController
cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id)
end
- if ENV["SERVER_MODE"] != "cloud" #no print in cloud server
+ # if ENV["SERVER_MODE"] != "cloud" #no print in cloud server
receipt_bill_a5_pdf = Lookup.collection_of("print_settings") #print_settings with name:ReceiptBillA5Pdf
# Print for First Bill to Customer
unique_code = "ReceiptBillPdf"
@@ -63,9 +63,9 @@ class Origami::PaymentsController < BaseOrigamiController
# get member information
rebate = MembershipSetting.find_by_rebate(1)
if customer.membership_id != nil && rebate
- member_info = Customer.get_member_account(customer)
- current_balance = SaleAudit.paymal_search(sale_id)
- # current_balance = 0
+ # member_info = Customer.get_member_account(customer)
+ # current_balance = SaleAudit.paymal_search(sale_id)
+ current_balance = 0
end
# get printer info
print_settings=PrintSetting.find_by_unique_code(unique_code)
@@ -79,8 +79,17 @@ class Origami::PaymentsController < BaseOrigamiController
printer = Printer::ReceiptPrinter.new(print_settings)
- printer.print_receipt_bill(print_settings,cashier_terminal,sale_items,sale_data,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info, shop_details, "Frt",current_balance,nil)
- end
+ filename, receipt_no, cashier_printer = printer.print_receipt_bill(print_settings,cashier_terminal,sale_items,sale_data,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info, shop_details, "Frt",current_balance,nil)
+
+ result = {
+ :filepath => filename,
+ :printer_model => print_settings.brand_name,
+ :printer_url => print_settings.api_settings
+ }
+
+ # Mobile Print
+ render :json => result.to_json
+ # end
end
def create
@@ -104,7 +113,7 @@ class Origami::PaymentsController < BaseOrigamiController
end
end
#end rounding adjustment
-
+
sale_payment = SalePayment.new
sale_payment.process_payment(saleObj, current_user.name, cash, "cash")
@@ -129,7 +138,7 @@ class Origami::PaymentsController < BaseOrigamiController
end
# For Print
- if ENV["SERVER_MODE"] != "cloud" #no print in cloud server
+ # if ENV["SERVER_MODE"] != "cloud" #no print in cloud server
receipt_bill_a5_pdf = Lookup.collection_of("print_settings") #print_settings with name:ReceiptBillA5Pdf
unique_code = "ReceiptBillPdf"
if !receipt_bill_a5_pdf.empty?
@@ -156,6 +165,23 @@ class Origami::PaymentsController < BaseOrigamiController
current_balance = SaleAudit.paymal_search(sale_id)
end
+ #orders print out
+ if params[:type] == "quick_service"
+ booking = Booking.find_by_sale_id(sale_id)
+ if booking.dining_facility_id.to_i>0
+ table_id = booking.dining_facility_id
+ else
+ table_id = 0
+ end
+
+ booking.booking_orders.each do |order|
+ # Order.pay_process_order_queue(order.order_id, table_id)
+ oqs = OrderQueueStation.new
+ oqs.pay_process_order_queue(order.order_id, table_id)
+ end
+
+ end
+
#for card sale data
card_data = Array.new
card_sale_trans_ref_no = Sale.getCardSaleTrans(sale_id)
@@ -180,19 +206,7 @@ class Origami::PaymentsController < BaseOrigamiController
render json: JSON.generate({:status => saleObj.rebate_status, :message => "Can't Rebate coz of Sever Error ", :filename => filename, :receipt_no => sale_receipt_no, :printer_name => printer_name})
- if params[:type] == "quick_service"
- booking = Booking.find_by_sale_id(sale_id)
- if booking.dining_facility_id.to_i>0
- table_id = booking.dining_facility_id
- else
- table_id = 0
- end
-
- booking.booking_orders.each do |order|
- Order.pay_process_order_queue(order.order_id,table_id)
- end
- end
- end
+ #end
end
end
@@ -210,16 +224,20 @@ class Origami::PaymentsController < BaseOrigamiController
@jcbcount= 0.0
@mastercount = 0.0
@unionpaycount = 0.0
+ @alipaycount = 0.0
+ @junctionpaycount = 0.0
@credit = 0.0
@paymalcount = 0.0
@sale_data = Sale.find_by_sale_id(sale_id)
- @balance = 0.00
+ @balance = 0
@accountable_type = ''
@table_no = ''
@dining = ''
@shop = Shop::ShopDetail #show shop info
+ @customer_lists = Customer.where("customer_id = 'CUS-000000000001' or customer_id = 'CUS-000000000002'")
+
saleObj = Sale.find(sale_id)
#total customer with individual total amount
@@ -269,10 +287,11 @@ class Origami::PaymentsController < BaseOrigamiController
#get customer amount
@customer = Customer.find(@sale_data.customer_id)
- accounts = @customer.tax_profiles
+ # accounts = @customer.tax_profiles
+ accounts = TaxProfile.where("group_type = ?",@cashier_type).order("order_by ASC")
@account_arr =[]
accounts.each do |acc|
- account = TaxProfile.find(acc)
+ account = TaxProfile.find(acc.id)
@account_arr.push(account)
end
@@ -283,7 +302,7 @@ class Origami::PaymentsController < BaseOrigamiController
if response["status"]==true
response["account_data"].each do |res|
if res["accountable_type"] == "RebateAccount" || res["accountable_type"] == "RebatebonusAccount"
- @balance += res["balance"]
+ @balance = @balance.to_f + res["balance"].to_f
# @accountable_type = res["accountable_type"]
@accountable_type = "Rebate Balance"
end
@@ -323,10 +342,14 @@ class Origami::PaymentsController < BaseOrigamiController
@mastercount += spay.payment_amount
elsif spay.payment_method == "unionpay"
@unionpaycount += spay.payment_amount
+ elsif spay.payment_method == "JunctionPay"
+ @junctionpaycount += spay.payment_amount
elsif spay.payment_method == "creditnote"
@credit += spay.payment_amount
elsif spay.payment_method == "paymal"
@paymalcount += spay.payment_amount
+ elsif spay.payment_method == "alipay"
+ @alipaycount += spay.payment_amount
end
end
end
@@ -402,19 +425,19 @@ class Origami::PaymentsController < BaseOrigamiController
member_info = nil
rebate_amount = nil
current_balance = nil
+ order_source = params[:type]
if(Sale.exists?(sale_id))
saleObj = Sale.find(sale_id)
if saleObj.discount_type == "member_discount"
saleObj.update_attributes(rounding_adjustment: 0)
- saleObj.compute_by_sale_items(sale_id, saleObj.sale_items,0)
+ saleObj.compute_by_sale_items(sale_id, saleObj.sale_items,0,order_source)
end
saleObj.update_attributes(rounding_adjustment: 0)
sale_payment = SalePayment.new
sale_payment.process_payment(saleObj, current_user.name, cash, "foc" ,remark)
-
# For Cashier by Zone
bookings = Booking.where("sale_id='#{sale_id}'")
# if bookings.count > 1
@@ -436,7 +459,7 @@ class Origami::PaymentsController < BaseOrigamiController
# Re-call Sale Data
saleObj = Sale.find(sale_id)
- if ENV["SERVER_MODE"] != "cloud" #no print in cloud server
+ # if ENV["SERVER_MODE"] != "cloud" #no print in cloud server
unique_code = "ReceiptBillPdf"
customer= Customer.find(saleObj.customer_id)
@@ -450,7 +473,17 @@ class Origami::PaymentsController < BaseOrigamiController
discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(saleObj.sale_items)
printer = Printer::ReceiptPrinter.new(print_settings)
- printer.print_receipt_bill(print_settings,cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details, "FOC",nil,nil)
+
+ filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings,cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details, "FOC",nil,nil)
+ result = {
+ :status => true,
+ :filepath => filename,
+ :printer_model => print_settings.brand_name,
+ :printer_url => print_settings.api_settings
+ }
+
+ # Mobile Print
+ render :json => result.to_json
if params[:type] == "quick_service"
booking = Booking.find_by_sale_id(sale_id)
@@ -464,7 +497,7 @@ class Origami::PaymentsController < BaseOrigamiController
Order.pay_process_order_queue(order.order_id,table_id)
end
end
- end
+ # end
end
end
@@ -510,12 +543,15 @@ class Origami::PaymentsController < BaseOrigamiController
printer = Printer::ReceiptPrinter.new(print_settings)
printer.print_receipt_pdf(filename,receipt_no,print_settings.print_copies,printer_name)
- render :json => {status: true}
- end
+ result = {
+ :status => true,
+ :filepath => filename,
+ :printer_model => print_settings.brand_name,
+ :printer_url => print_settings.api_settings
+ }
- #Shop Name in Navbor
- helper_method :shop_detail
- def shop_detail
- @shop = Shop.first
- end
+ # Mobile Print
+ render :json => result.to_json
+ # render :json => {status: true}
+ end
end
\ No newline at end of file
diff --git a/app/controllers/origami/paypar_payments_controller.rb b/app/controllers/origami/paypar_payments_controller.rb
index 04a52f0f..faaeca8e 100755
--- a/app/controllers/origami/paypar_payments_controller.rb
+++ b/app/controllers/origami/paypar_payments_controller.rb
@@ -29,9 +29,4 @@ class Origami::PayparPaymentsController < BaseOrigamiController
end
- #Shop Name in Navbor
- helper_method :shop_detail
- def shop_detail
- @shop = Shop.first
- end
end
diff --git a/app/controllers/origami/pending_order_controller.rb b/app/controllers/origami/pending_order_controller.rb
index d738a0a5..9a413316 100644
--- a/app/controllers/origami/pending_order_controller.rb
+++ b/app/controllers/origami/pending_order_controller.rb
@@ -41,9 +41,4 @@ class Origami::PendingOrderController < BaseOrigamiController
end
end
-
- helper_method :shop_detail
- def shop_detail
- @shop = Shop.first
- end
end
diff --git a/app/controllers/origami/product_commissions_controller.rb b/app/controllers/origami/product_commissions_controller.rb
index 2ab9a618..2f209a7a 100755
--- a/app/controllers/origami/product_commissions_controller.rb
+++ b/app/controllers/origami/product_commissions_controller.rb
@@ -137,9 +137,4 @@ class Origami::ProductCommissionsController < BaseOrigamiController
params.fetch(:product_commission, {})
end
- #Shop Name in Navbor
- helper_method :shop_detail
- def shop_detail
- @shop = Shop.first
- end
end
diff --git a/app/controllers/origami/quick_service_controller.rb b/app/controllers/origami/quick_service_controller.rb
index 44dcfcb8..8abcfcc8 100644
--- a/app/controllers/origami/quick_service_controller.rb
+++ b/app/controllers/origami/quick_service_controller.rb
@@ -1,6 +1,12 @@
class Origami::QuickServiceController < ApplicationController
# before_action :set_dining, only: [:detail]
-
+ before_action :check_user
+ def check_user
+ if current_user.nil?
+ redirect_to root_path
+ end
+ end
+
def index
today = DateTime.now
day = Date.today.wday
@@ -211,6 +217,11 @@ class Origami::QuickServiceController < ApplicationController
end
end
+ def check_user
+ if current_user.nil?
+ redirect_to root_path
+ end
+ end
# this can always true
def check_order_with_booking(booking)
if booking.sale.sale_status == "completed" || booking.sale.sale_status == "new"
diff --git a/app/controllers/origami/redeem_payments_controller.rb b/app/controllers/origami/redeem_payments_controller.rb
index 76517e8a..bcb8f9ae 100755
--- a/app/controllers/origami/redeem_payments_controller.rb
+++ b/app/controllers/origami/redeem_payments_controller.rb
@@ -6,6 +6,7 @@ class Origami::RedeemPaymentsController < BaseOrigamiController
@membership_rebate_balance=0
sale_data = Sale.find_by_sale_id(@sale_id)
+ @payment_method_setting_nav = PaymentMethodSetting.all
@shop = Shop::ShopDetail
# if @shop.is_rounding_adj
# new_total = Sale.get_rounding_adjustment(sale_data.grand_total)
@@ -68,10 +69,5 @@ class Origami::RedeemPaymentsController < BaseOrigamiController
end
@out = false, 0
end
-
- #Shop Name in Navbor
- helper_method :shop_detail
- def shop_detail
- @shop = Shop.first
- end
+
end
diff --git a/app/controllers/origami/request_bills_controller.rb b/app/controllers/origami/request_bills_controller.rb
index 409177fe..e2553a83 100755
--- a/app/controllers/origami/request_bills_controller.rb
+++ b/app/controllers/origami/request_bills_controller.rb
@@ -1,5 +1,11 @@
class Origami::RequestBillsController < ApplicationController
-
+ before_action :check_user
+
+ def check_user
+ if current_user.nil?
+ redirect_to root_path
+ end
+ end
# Print Request Bill and add to sale tables
def print
@sale = Sale.new
@@ -8,14 +14,12 @@ class Origami::RequestBillsController < ApplicationController
if !ShiftSale.current_shift.nil?
order_id = params[:id] # order_id
bk_order = BookingOrder.find_by_order_id(order_id)
- puts params[:id]
- puts bk_order
- puts bk_order.booking_id
+ order = Order.find(order_id)
check_booking = Booking.find_by_booking_id(bk_order.booking_id)
if check_booking.sale_id.nil?
# Create Sale if it doesn't exist
- @status, @sale_id = @sale.generate_invoice_from_booking(check_booking.id,current_login_employee, current_user)
+ @status, @sale_id = @sale.generate_invoice_from_booking(check_booking.id,current_login_employee, current_user, order.source)
@sale_data = Sale.find_by_sale_id(@sale_id)
@sale_items = SaleItem.where("sale_id=?",@sale_id)
else
@@ -29,6 +33,10 @@ class Origami::RequestBillsController < ApplicationController
# Promotion Activation
Promotion.promo_activate(@sale)
+ if order.source == "quick_service"
+ result = {:status=> @status, :data => @sale.sale_id }
+ render :json => result.to_json
+ end
else
@status = false
@error_message = "No Current Open Shift for This Employee"
@@ -56,10 +64,5 @@ class Origami::RequestBillsController < ApplicationController
# printer.print_receipt_bill(print_settings,@sale_items,@sale_data,customer.name, item_price_by_accounts,member_info,shop_details)
end
-
- #Shop Name in Navbor
- helper_method :shop_detail
- def shop_detail
- @shop = Shop.first
- end
+
end
diff --git a/app/controllers/origami/room_invoices_controller.rb b/app/controllers/origami/room_invoices_controller.rb
index 9c3b16a6..8d805771 100755
--- a/app/controllers/origami/room_invoices_controller.rb
+++ b/app/controllers/origami/room_invoices_controller.rb
@@ -37,9 +37,4 @@ class Origami::RoomInvoicesController < BaseOrigamiController
@customer = @sale.customer
end
- #Shop Name in Navbor
- helper_method :shop_detail
- def shop_detail
- @shop = Shop.first
- end
end
diff --git a/app/controllers/origami/rooms_controller.rb b/app/controllers/origami/rooms_controller.rb
index 6117d01d..5c0cd454 100755
--- a/app/controllers/origami/rooms_controller.rb
+++ b/app/controllers/origami/rooms_controller.rb
@@ -68,16 +68,6 @@ class Origami::RoomsController < BaseOrigamiController
@date = order.created_at
@booking = booking
order.order_items.each do |item|
- if !item.set_menu_items.nil?
- instance_item_sets = JSON.parse(item.set_menu_items)
- arr_instance_item_sets = Array.new
- instance_item_sets.each do |instance_item|
- item_instance_name = MenuItemInstance.find_by_item_instance_code(instance_item["item_instance_code"]).item_instance_name
- arr_instance_item_sets.push(item_instance_name)
- item.price = item.price.to_f + instance_item["price"].to_f
- end
- item.set_menu_items = arr_instance_item_sets
- end
@order_items.push(item)
# assigned_order_items = AssignedOrderItem.find_by_item_code_and_instance_code_and_order_id(item.item_code,item.item_instance_code,item.order_id)
# if !assigned_order_items.nil?
@@ -89,8 +79,7 @@ class Origami::RoomsController < BaseOrigamiController
@status_order = 'order'
else
sale = Sale.find(booking.sale_id)
- if sale.sale_status != "completed" && sale.sale_status != 'void'
- puts "enter"
+ if sale.sale_status != "completed" && sale.sale_status != 'void' && sale.sale_status != 'spoile' && sale.sale_status != 'waste'
@sale_array.push(sale)
if @status_order == 'order'
@status_order = 'sale'
@@ -136,9 +125,4 @@ class Origami::RoomsController < BaseOrigamiController
end
end
- #Shop Name in Navbor
- helper_method :shop_detail
- def shop_detail
- @shop = Shop.first
- end
end
diff --git a/app/controllers/origami/sale_edit_controller.rb b/app/controllers/origami/sale_edit_controller.rb
index 44ec6442..1743f881 100755
--- a/app/controllers/origami/sale_edit_controller.rb
+++ b/app/controllers/origami/sale_edit_controller.rb
@@ -76,11 +76,14 @@ class Origami::SaleEditController < BaseOrigamiController
# re-calc tax
saleObj = Sale.find(saleitemObj.sale_id)
+ order_id = SaleOrder.find_by_sale_id(saleitemObj.sale_id).order_id
+ order = Order.find(order_id)
+
action_by = current_user.id
remark = "FOC Sale Item ID #{saleitemObj.sale_item_id} | Receipt No #{saleObj.receipt_no} | Item Name ->#{saleitemObj.product_name}-Product Code ->#{saleitemObj.product_code}-Instance Code ->#{saleitemObj.item_instance_code}Receipt No #{saleObj.receipt_no}"
sale_audit = SaleAudit.record_audit_for_edit(saleitemObj.sale_id,saleObj.cashier_id, action_by,remark,"SALEITEMFOC" )
- saleObj.compute_by_sale_items(saleObj.sale_id, saleObj.sale_items, saleObj.total_discount)
+ saleObj.compute_by_sale_items(saleObj.sale_id, saleObj.sale_items, saleObj.total_discount,order.source)
ProductCommission.create_product_commission(@newsaleitem, saleitemObj)
end
@@ -141,7 +144,7 @@ class Origami::SaleEditController < BaseOrigamiController
end
end
- saleObj.compute_by_sale_items(saleObj.sale_id, saleObj.sale_items, saleObj.total_discount)
+ saleObj.compute_by_sale_items(saleObj.sale_id, saleObj.sale_items, saleObj.total_discount,order.source)
ProductCommission.edit_product_commission(saleitemObj)
end
@@ -162,17 +165,21 @@ class Origami::SaleEditController < BaseOrigamiController
# re-calc tax
saleObj = Sale.find(saleitemObj.sale_id)
+ order_id = SaleOrder.find_by_sale_id(saleitemObj.sale_id).order_id
+ order = Order.find(order_id)
+
action_by = current_user.id
remark = "Cancle Void Sale Item ID #{saleitemObj.sale_item_id} | Item Name ->#{saleitemObj.product_name}-Product Code ->#{saleitemObj.product_code}-Instance Code ->#{saleitemObj.item_instance_code}|Receipt No #{saleObj.receipt_no}"
sale_audit = SaleAudit.record_audit_for_edit(saleitemObj.sale_id,saleObj.cashier_id, action_by,remark,"ITEMCANCELVOID" )
- saleObj.compute_by_sale_items(saleObj.sale_id, saleObj.sale_items, saleObj.total_discount)
+ saleObj.compute_by_sale_items(saleObj.sale_id, saleObj.sale_items, saleObj.total_discount, order.source)
ProductCommission.remove_product_commission(saleitemObj)
end
# remove all void items
def cancel_all_void
sale_id = params[:sale_id]
+ order_source = params[:type]
saleObj = Sale.find(sale_id)
saleObj.sale_items.each do |item|
if item.qty.to_i < 0
@@ -185,21 +192,17 @@ class Origami::SaleEditController < BaseOrigamiController
end
# re-calc tax
- saleObj.compute_by_sale_items(saleObj.sale_id, saleObj.sale_items, saleObj.total_discount)
+ saleObj.compute_by_sale_items(saleObj.sale_id, saleObj.sale_items, saleObj.total_discount,order_source)
end
def apply_void
sale_id = params[:sale_id]
+ order_source = params[:type]
saleObj = Sale.find(sale_id)
- saleObj.compute_without_void
+ saleObj.compute_without_void(order_source)
saleObj.sale_items.each do |item|
ProductCommission.remove_product_commission(item)
end
end
-
- #Shop Name in Navbor
- helper_method :shop_detail
- def shop_detail
- @shop = Shop.first
- end
+
end
diff --git a/app/controllers/origami/sales_controller.rb b/app/controllers/origami/sales_controller.rb
index 513bdb2c..eee75e37 100755
--- a/app/controllers/origami/sales_controller.rb
+++ b/app/controllers/origami/sales_controller.rb
@@ -56,9 +56,4 @@ class Origami::SalesController < BaseOrigamiController
end
end
- #Shop Name in Navbor
- helper_method :shop_detail
- def shop_detail
- @shop = Shop.first
- end
end
diff --git a/app/controllers/origami/shifts_controller.rb b/app/controllers/origami/shifts_controller.rb
index 29a6e76a..acce6c65 100755
--- a/app/controllers/origami/shifts_controller.rb
+++ b/app/controllers/origami/shifts_controller.rb
@@ -3,6 +3,7 @@ class Origami::ShiftsController < BaseOrigamiController
end
def show
+ @cashier_type = params[:type]
@shift = ShiftSale.current_open_shift(current_user.id)
#for bank integration
bank_integration = Lookup.collection_of('bank_integration')
@@ -125,9 +126,4 @@ class Origami::ShiftsController < BaseOrigamiController
end
- #Shop Name in Navbor
- helper_method :shop_detail
- def shop_detail
- @shop = Shop.first
- end
end
diff --git a/app/controllers/origami/split_bill_controller.rb b/app/controllers/origami/split_bill_controller.rb
old mode 100644
new mode 100755
index 9f8afd0d..e18828fc
--- a/app/controllers/origami/split_bill_controller.rb
+++ b/app/controllers/origami/split_bill_controller.rb
@@ -3,6 +3,7 @@ class Origami::SplitBillController < BaseOrigamiController
def index
dining_id = params[:dining_id]
+ @cashier_type = params[:type]
@table = DiningFacility.find(dining_id)
@booking = @table.get_booking
@orders = Array.new
@@ -76,7 +77,12 @@ class Origami::SplitBillController < BaseOrigamiController
end
def create
+ cashier_type = params[:cashier_type]
order_ids = params[:order_ids]
+ arr_order_ids = nil
+ if !params[:arr_order_ids].nil?
+ arr_order_ids = JSON.parse(params[:arr_order_ids])
+ end
orders = nil
if !params[:orders].empty?
orders = JSON.parse(params[:orders])
@@ -107,7 +113,7 @@ class Origami::SplitBillController < BaseOrigamiController
if booking
if booking.sale_id.nil?
sale = Sale.new
- status, sale_id = sale.generate_invoice_from_booking(params[:booking_id], current_user, current_user)
+ status, sale_id = sale.generate_invoice_from_booking(params[:booking_id], current_user, current_user, cashier_type)
sale_data = Sale.find_by_sale_id(sale_id)
else
status = true
@@ -136,14 +142,15 @@ class Origami::SplitBillController < BaseOrigamiController
order_id_count = 0
order_id = nil
- order_items.each do |order_item|
- order_item_count = 0
- order = Order.find(order_item["order_id"])
- if order.order_items.count == 1
- order_id = order.id
- order_id_count += 1
- else
- order_item_count += 1
+ arr_order_ids.each do |order|
+ order.each do |odr|
+ data = Order.find(odr[0])
+ if data.order_items.count == odr[1]
+ order_id = odr[0]
+ order_id_count += 1
+ else
+ order_item_count += 1
+ end
end
end
@@ -158,10 +165,12 @@ class Origami::SplitBillController < BaseOrigamiController
puts "order_id_count > 1"
updated_order_id = Array.new
- order_ids.each do |odr_id|
- odr = Order.find(odr_id)
- if odr.order_items.count > 1
- updated_order_id.push(odr_id)
+ arr_order_ids.each do |order|
+ order.each do |odr|
+ data = Order.find(odr[0])
+ if data.order_items.count != odr[1]
+ updated_order_id.push(odr[0])
+ end
end
end
@@ -226,7 +235,7 @@ class Origami::SplitBillController < BaseOrigamiController
puts "order_id_count < 1"
new_order_status = true
order_items.each do |order_item|
- orderItem = OrderItem.find_by_order_id(order_id)
+ orderItem = OrderItem.find(order_item["id"])
if !orderItem.nil?
if order_item["id"] == orderItem.order_items_id
if orderItem.qty.to_f != order_item['qty'].to_f
@@ -266,12 +275,32 @@ class Origami::SplitBillController < BaseOrigamiController
end
end
else
- # puts order_ids
- if order_ids.count == 1 && order_id_count == 0 && order_item_count == 1
- BookingOrder.find_by_order_id(order_ids[0]).delete
- BookingOrder.create({:booking_id => booking.booking_id, :order_id => order_ids[0]})
- order_items.each do |order_item|
- update_order_item(order_ids[0], order_item)
+ if order_ids.count == 1 && order_item_count == 1
+ if order_id_count == 0
+ customer = Customer.find(params[:customer_id])
+ order_type = "dine_in"
+ if !customer.nil?
+ if customer.customer_type == "Takeaway"
+ order_type = "takeaway"
+ elsif customer.customer_type == "Delivery"
+ order_type = "delivery"
+ end
+ end
+
+ # begin
+ order = create_order(params,order_type,order_items.count,current_user)
+
+ BookingOrder.create({:booking_id => booking.booking_id, :order_id => order.order_id})
+
+ order_items.each do |order_item|
+ update_order_item(order.order_id, order_item)
+ end
+ else
+ BookingOrder.find_by_order_id(order_ids[0]).delete
+ BookingOrder.create({:booking_id => booking.booking_id, :order_id => order_ids[0]})
+ order_items.each do |order_item|
+ update_order_item(order_ids[0], order_item)
+ end
end
else
customer = Customer.find(params[:customer_id])
@@ -297,7 +326,7 @@ class Origami::SplitBillController < BaseOrigamiController
end
sale = Sale.new
- status, sale_id = sale.generate_invoice_from_booking(booking.booking_id, current_user, current_user)
+ status, sale_id = sale.generate_invoice_from_booking(booking.booking_id, current_user, current_user, cashier_type)
end
Promotion.promo_activate(sale)
diff --git a/app/controllers/origami/surveys_controller.rb b/app/controllers/origami/surveys_controller.rb
index 47b7e8fd..654f8a1a 100644
--- a/app/controllers/origami/surveys_controller.rb
+++ b/app/controllers/origami/surveys_controller.rb
@@ -90,10 +90,5 @@ class Origami::SurveysController < BaseOrigamiController
def survey_params
params.require(:survey).permit(:child, :adult,:male,:female,:local,:foreigner, :dining_name,:receipt_no,:shift_id,:created_by,:total_customer,:total_amount,:survey_id)
end
-
- #Shop Name in Navbor
- helper_method :shop_detail
- def shop_detail
- @shop = Shop.first
- end
+
end
diff --git a/app/controllers/origami/table_invoices_controller.rb b/app/controllers/origami/table_invoices_controller.rb
index 9aff7202..5cd22054 100755
--- a/app/controllers/origami/table_invoices_controller.rb
+++ b/app/controllers/origami/table_invoices_controller.rb
@@ -31,6 +31,8 @@ class Origami::TableInvoicesController < BaseOrigamiController
def show
@table = DiningFacility.find(params[:table_id])
+ @membership = MembershipSetting::MembershipSetting
+ @payment_methods = PaymentMethodSetting.all
shop = Shop::ShopDetail
@sale_array = Array.new
@table.bookings.each do |booking|
@@ -70,9 +72,4 @@ class Origami::TableInvoicesController < BaseOrigamiController
@print_settings = PrintSetting.get_precision_delimiter()
end
- #Shop Name in Navbor
- helper_method :shop_detail
- def shop_detail
- @shop = Shop.first
- end
end
diff --git a/app/controllers/origami/unionpay_controller.rb b/app/controllers/origami/unionpay_controller.rb
index 89adfd3e..ec941a20 100644
--- a/app/controllers/origami/unionpay_controller.rb
+++ b/app/controllers/origami/unionpay_controller.rb
@@ -4,31 +4,40 @@ class Origami::UnionpayController < BaseOrigamiController
@cashier_type = params[:type]
# limit unionpay_amount
sale_data = Sale.find_by_sale_id(@sale_id)
- total = sale_data.grand_total
+ total = 0
@unionpaycount = 0
- others = 0
-
@shop = Shop::ShopDetail
- if @shop.is_rounding_adj
- new_total = Sale.get_rounding_adjustment(sale_data.grand_total)
- else
- new_total = sale_data.grand_total
+ @rounding_adj = 0
+ @can_unionpay = 0
+ @member_discount = 0
+ @sub_total = 0
+ @membership_id = nil
+ @receipt_no = nil
+ if !sale_data.nil?
+ total = sale_data.grand_total
+ others = 0
+
+ if @shop.is_rounding_adj
+ new_total = Sale.get_rounding_adjustment(sale_data.grand_total)
+ else
+ new_total = sale_data.grand_total
+ end
+ @rounding_adj = new_total-sale_data.grand_total
+
+ sale_data.sale_payments.each do |sale_payment|
+ if sale_payment.payment_method == "unionpay"
+ @unionpaycount = @unionpaycount + sale_payment.payment_amount
+ else
+ others = others + sale_payment.payment_amount
+ end
+ end
+ @can_unionpay = total - @unionpaycount - others
+ @member_discount = MembershipSetting.find_by_discount(1)
+ @sub_total = sale_data.total_amount
+ @membership_id = sale_data.customer.membership_id
+ #for bank integration
+ @receipt_no = sale_data.receipt_no
end
- @rounding_adj = new_total-sale_data.grand_total
-
- sale_data.sale_payments.each do |sale_payment|
- if sale_payment.payment_method == "unionpay"
- @unionpaycount = @unionpaycount + sale_payment.payment_amount
- else
- others = others + sale_payment.payment_amount
- end
- end
- @can_unionpay = total - @unionpaycount - others
- @member_discount = MembershipSetting.find_by_discount(1)
- @sub_total = sale_data.total_amount
- @membership_id = sale_data.customer.membership_id
- #for bank integration
- @receipt_no = sale_data.receipt_no
bank_integration = Lookup.collection_of('bank_integration')
@bank_integration = 0
if !bank_integration[0].nil?
@@ -39,6 +48,7 @@ class Origami::UnionpayController < BaseOrigamiController
def create
cash = params[:amount]
sale_id = params[:sale_id]
+ ref_no = params[:ref_no]
if(Sale.exists?(sale_id))
saleObj = Sale.find(sale_id)
shop_details = Shop::ShopDetail
@@ -53,7 +63,7 @@ class Origami::UnionpayController < BaseOrigamiController
# saleObj = Sale.find(sale_id)
#end rounding adjustment
sale_payment = SalePayment.new
- @status, @sale = sale_payment.process_payment(saleObj, @user, cash, "unionpay")
+ @status, @sale = sale_payment.process_payment(saleObj, @user, cash, "unionpay",ref_no)
end
end
diff --git a/app/controllers/origami/visa_controller.rb b/app/controllers/origami/visa_controller.rb
old mode 100755
new mode 100644
index 5404789c..8cc2bbe3
--- a/app/controllers/origami/visa_controller.rb
+++ b/app/controllers/origami/visa_controller.rb
@@ -4,31 +4,40 @@ class Origami::VisaController < BaseOrigamiController
@cashier_type = params[:type]
# limit visa_amount
sale_data = Sale.find_by_sale_id(@sale_id)
- total = sale_data.grand_total
+ total = 0
@visacount = 0
- others = 0
-
@shop = Shop::ShopDetail
- if @shop.is_rounding_adj
- new_total = Sale.get_rounding_adjustment(sale_data.grand_total)
- else
- new_total = sale_data.grand_total
+ @rounding_adj = 0
+ @can_visa = 0
+ @member_discount = 0
+ @sub_total = 0
+ @membership_id = nil
+ @receipt_no = nil
+ if !sale_data.nil?
+ total = sale_data.grand_total
+ others = 0
+
+ if @shop.is_rounding_adj
+ new_total = Sale.get_rounding_adjustment(sale_data.grand_total)
+ else
+ new_total = sale_data.grand_total
+ end
+ @rounding_adj = new_total-sale_data.grand_total
+
+ sale_data.sale_payments.each do |sale_payment|
+ if sale_payment.payment_method == "visa"
+ @visacount = @visacount + sale_payment.payment_amount
+ else
+ others = others + sale_payment.payment_amount
+ end
+ end
+ @can_visa = total - @visacount - others
+ @member_discount = MembershipSetting.find_by_discount(1)
+ @sub_total = sale_data.total_amount
+ @membership_id = sale_data.customer.membership_id
+ #for bank integration
+ @receipt_no = sale_data.receipt_no
end
- @rounding_adj = new_total-sale_data.grand_total
-
- sale_data.sale_payments.each do |sale_payment|
- if sale_payment.payment_method == "visa"
- @visacount = @visacount + sale_payment.payment_amount
- else
- others = others + sale_payment.payment_amount
- end
- end
- @can_visa = total - @visacount - others
- @member_discount = MembershipSetting.find_by_discount(1)
- @sub_total = sale_data.total_amount
- @membership_id = sale_data.customer.membership_id
- #for bank integration
- @receipt_no = sale_data.receipt_no
bank_integration = Lookup.collection_of('bank_integration')
@bank_integration = 0
if !bank_integration[0].nil?
@@ -39,6 +48,7 @@ class Origami::VisaController < BaseOrigamiController
def create
cash = params[:amount]
sale_id = params[:sale_id]
+ ref_no = params[:ref_no]
if(Sale.exists?(sale_id))
saleObj = Sale.find(sale_id)
shop_details = Shop::ShopDetail
@@ -53,7 +63,7 @@ class Origami::VisaController < BaseOrigamiController
# saleObj = Sale.find(sale_id)
#end rounding adjustment
sale_payment = SalePayment.new
- @status, @sale = sale_payment.process_payment(saleObj, @user, cash, "visa")
+ @status, @sale = sale_payment.process_payment(saleObj, @user, cash, "visa",ref_no)
end
end
diff --git a/app/controllers/origami/void_controller.rb b/app/controllers/origami/void_controller.rb
index 5bbc9ac3..83dce707 100755
--- a/app/controllers/origami/void_controller.rb
+++ b/app/controllers/origami/void_controller.rb
@@ -4,12 +4,13 @@ class Origami::VoidController < BaseOrigamiController
sale_id = params[:sale_id]
remark = params[:remark]
+ order_source = params[:type] #tax profile source
if Sale.exists?(sale_id)
sale = Sale.find_by_sale_id(sale_id)
if sale.discount_type == "member_discount"
sale.update_attributes(total_discount: 0)
- sale.compute_by_sale_items(sale_id, sale.sale_items,0)
+ sale.compute_by_sale_items(sale_id, sale.sale_items,0,order_source)
end
# update count for shift sale
@@ -47,7 +48,7 @@ class Origami::VoidController < BaseOrigamiController
table.bookings.each do |booking|
if booking.booking_status != 'moved'
if booking.sale_id
- if booking.sale.sale_status != 'completed' && booking.sale.sale_status != 'void'
+ if booking.sale.sale_status != 'completed' && booking.sale.sale_status != 'void' && booking.sale.sale_status != 'spoile' && booking.sale.sale_status != 'waste'
table_avaliable = false
table_count += 1
else
@@ -86,8 +87,6 @@ class Origami::VoidController < BaseOrigamiController
if bookings[0].dining_facility_id.to_i>0
table = DiningFacility.find(bookings[0].dining_facility_id)
end
-
-
end
if bookings[0].dining_facility_id.to_i > 0
@@ -99,7 +98,7 @@ class Origami::VoidController < BaseOrigamiController
end
- if ENV["SERVER_MODE"] != "cloud" #no print in cloud server
+ # if ENV["SERVER_MODE"] != "cloud" #no print in cloud server
unique_code = "ReceiptBillPdf"
customer= Customer.find(sale.customer_id)
@@ -119,9 +118,17 @@ class Origami::VoidController < BaseOrigamiController
item_price_by_accounts = SaleItem.calculate_price_by_accounts(sale.sale_items)
discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(sale.sale_items)
- printer = Printer::ReceiptPrinter.new(print_settings)
- printer.print_receipt_bill(print_settings,cashier_terminal,sale.sale_items,sale,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details, "VOID",current_balance,nil)
- end
+ printer = Printer::ReceiptPrinter.new(print_settings)
+ filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings,cashier_terminal,sale.sale_items,sale,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details, "VOID",current_balance,nil)
+ result = {
+ :filepath => filename,
+ :printer_model => print_settings.brand_name,
+ :printer_url => print_settings.api_settings
+ }
+
+ # Mobile Print
+ render :json => result.to_json
+ # end
#end print
@@ -134,10 +141,5 @@ class Origami::VoidController < BaseOrigamiController
end
end
end
-
- #Shop Name in Navbor
- helper_method :shop_detail
- def shop_detail
- @shop = Shop.first
- end
+
end
\ No newline at end of file
diff --git a/app/controllers/origami/voucher_controller.rb b/app/controllers/origami/voucher_controller.rb
index 750189df..25352597 100755
--- a/app/controllers/origami/voucher_controller.rb
+++ b/app/controllers/origami/voucher_controller.rb
@@ -54,7 +54,7 @@ class Origami::VoucherController < BaseOrigamiController
}.to_json,
:headers => {
'Content-Type' => 'application/json',
- 'Accept' => 'application/json; version=2'
+ 'Accept' => 'application/json; version=3'
}, :timeout => 10
)
rescue Net::OpenTimeout
@@ -78,9 +78,4 @@ class Origami::VoucherController < BaseOrigamiController
end
end
- #Shop Name in Navbor
- helper_method :shop_detail
- def shop_detail
- @shop = Shop.first
- end
end
diff --git a/app/controllers/origami/waste_spoile_controller.rb b/app/controllers/origami/waste_spoile_controller.rb
new file mode 100755
index 00000000..c94b33bb
--- /dev/null
+++ b/app/controllers/origami/waste_spoile_controller.rb
@@ -0,0 +1,128 @@
+class Origami::WasteSpoileController < BaseOrigamiController
+ def waste_and_spoilage
+
+ sale_id = params[:sale_id]
+ remark = params[:remark]
+ order_source = params[:type] #tax profile source
+ if Sale.exists?(sale_id)
+ sale = Sale.find_by_sale_id(sale_id)
+ SaleTax.where("sale_id='#{sale_id}'").find_each do |existing_tax|
+ existing_tax.delete
+ end
+ sale.update_attributes(total_discount: 0,total_tax: 0,grand_total: sale.total_amount,rounding_adjustment:0)
+ sale.payment_status = remark
+ sale.sale_status = remark
+ sale.save
+
+ # sale.compute_by_sale_items(sale_id, sale.sale_items,0,order_source)
+ # add to sale item with foc
+ # sale_items = SaleItem.where("sale_id='#{ sale_id }' and status is null")
+
+ sale.sale_items.each do|item|
+ # SaleItem.update_existing_item(item.qty, item, sale_id, remark, item.unit_price, item.price)
+ item.status = remark
+ item.remark = remark
+ item.save
+ end
+
+ if sale.bookings[0].dining_facility_id.to_i > 0
+ table_avaliable = true
+ table_count = 0
+ table = sale.bookings[0].dining_facility
+ table.bookings.each do |booking|
+ if booking.booking_status != 'moved'
+ if booking.sale_id
+ if booking.sale.sale_status != 'completed' && booking.sale.sale_status != 'void' && booking.sale.sale_status != 'spoile' && booking.sale.sale_status != 'waste'
+ table_avaliable = false
+ table_count += 1
+ else
+ table_avaliable = true
+ end
+ else
+ table_avaliable = false
+ table_count += 1
+ end
+ end
+ end
+ if table_avaliable && table_count == 0
+ table.status = 'available'
+ table.save
+ end
+ else
+ table = nil
+ end
+
+ # FOr Sale Audit
+ action_by = current_user.name
+ # remark = "Void Sale ID #{sale_id} | Receipt No #{sale.receipt_no} | Receipt No #{sale.receipt_no} | Table ->#{table.name}"
+ sale_audit = SaleAudit.record_audit_for_edit(sale_id,sale.cashier_id, action_by,remark,remark )
+
+ # For Print
+
+ member_info = nil
+ rebate_amount = nil
+ current_balance = nil
+
+ # For Cashier by Zone
+ bookings = Booking.where("sale_id='#{sale_id}'")
+ if bookings.count > 1
+ # for Multiple Booking
+ if bookings[0].dining_facility_id.to_i>0
+ table = DiningFacility.find(bookings[0].dining_facility_id)
+ end
+ end
+
+ if bookings[0].dining_facility_id.to_i > 0
+ cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id)
+ cashier_terminal = CashierTerminal.find(cashier_zone.cashier_terminal_id)
+ else
+ shift = ShiftSale.find(sale.shift_sale_id)
+ cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id)
+ end
+
+
+ # if ENV["SERVER_MODE"] != "cloud" #no print in cloud server
+ unique_code = "ReceiptBillPdf"
+ customer= Customer.find(sale.customer_id)
+
+ #shop detail
+ shop_details = Shop.find(1)
+ # get member information
+ rebate = MembershipSetting.find_by_rebate(1)
+ if customer.membership_id != nil && rebate
+ member_info = Customer.get_member_account(customer)
+ rebate_amount = Customer.get_membership_transactions(customer,sale.receipt_no)
+ current_balance = SaleAudit.paymal_search(sale_id)
+ end
+
+ # get printer info
+ print_settings=PrintSetting.find_by_unique_code(unique_code)
+ # Calculate Food and Beverage Total
+ item_price_by_accounts = SaleItem.calculate_price_by_accounts(sale.sale_items)
+ discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(sale.sale_items)
+
+ printer = Printer::ReceiptPrinter.new(print_settings)
+ filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings,cashier_terminal,sale.sale_items,sale,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details, remark,current_balance,nil)
+ result = {
+ :filepath => filename,
+ :printer_model => print_settings.brand_name,
+ :printer_url => print_settings.api_settings
+ }
+
+ # Mobile Print
+ render :json => result.to_json
+ # end
+
+ #end print
+
+ # update complete order items in oqs
+ SaleOrder.where("sale_id = '#{ sale_id }'").find_each do |sodr|
+ AssignedOrderItem.where("order_id = '#{ sodr.order_id }'").find_each do |aoi|
+ aoi.delivery_status = 1
+ aoi.save
+ end
+ end
+ end
+ end
+
+end
\ No newline at end of file
diff --git a/app/controllers/print_settings_controller.rb b/app/controllers/print_settings_controller.rb
index a72319b3..f12778af 100755
--- a/app/controllers/print_settings_controller.rb
+++ b/app/controllers/print_settings_controller.rb
@@ -2,6 +2,8 @@ class PrintSettingsController < ApplicationController
load_and_authorize_resource except: [:create]
before_action :set_print_setting, only: [:show, :edit, :update, :destroy]
+ helper_method :shop_detail
+
# GET /print_settings
# GET /print_settings.json
def index
@@ -62,6 +64,17 @@ class PrintSettingsController < ApplicationController
end
end
+ def get_printer_options
+ printer_name = params[:printer_name]
+ printer_options = Printer::PrinterWorker.printer_options(printer_name)
+ options = {
+ :url => printer_options['device-uri'],
+ :model => printer_options['printer-info'],
+ }
+
+ render :json => options.to_json
+ end
+
private
# Use callbacks to share common setup or constraints between actions.
def set_print_setting
@@ -70,6 +83,11 @@ class PrintSettingsController < ApplicationController
# Never trust parameters from the scary internet, only allow the white list through.
def print_setting_params
- params.require(:print_setting).permit(:name, :unique_code, :template, :printer_name, :font, :api_settings, :page_width, :page_height, :print_copies,:precision,:delimiter,:heading_space)
+ params.require(:print_setting).permit(:name, :unique_code, :template, :printer_name, :brand_name, :printer_type, :font, :api_settings, :page_width, :page_height, :print_copies,:precision,:delimiter,:heading_space)
end
+
+ #Shop Name in Navbor
+ def shop_detail
+ @shop = Shop.first
+ end
end
diff --git a/app/controllers/reports/bksaleitem_controller.rb b/app/controllers/reports/bksaleitem_controller.rb
index 118269bb..0f91681d 100755
--- a/app/controllers/reports/bksaleitem_controller.rb
+++ b/app/controllers/reports/bksaleitem_controller.rb
@@ -16,10 +16,4 @@ class Reports::SaleitemController < BaseReportController
end
- #Shop Name in Navbor
- helper_method :shop_detail
- def shop_detail
- @shop = Shop.first
- end
-
end
diff --git a/app/controllers/reports/commission_controller.rb b/app/controllers/reports/commission_controller.rb
index 9e13bd75..9a7f4ca1 100755
--- a/app/controllers/reports/commission_controller.rb
+++ b/app/controllers/reports/commission_controller.rb
@@ -49,11 +49,6 @@ class Reports::CommissionController < BaseReportController
format.json { render json: out }
end
end
-
- #Shop Name in Navbor
- helper_method :shop_detail
- def shop_detail
- @shop = Shop.first
- end
+
end
diff --git a/app/controllers/reports/credit_payment_controller.rb b/app/controllers/reports/credit_payment_controller.rb
index abf7a6af..f46b008f 100755
--- a/app/controllers/reports/credit_payment_controller.rb
+++ b/app/controllers/reports/credit_payment_controller.rb
@@ -60,9 +60,4 @@ authorize_resource :class => false
end
end
- #Shop Name in Navbor
- helper_method :shop_detail
- def shop_detail
- @shop = Shop.first
- end
end
\ No newline at end of file
diff --git a/app/controllers/reports/dailysale_controller.rb b/app/controllers/reports/dailysale_controller.rb
index d43355fa..4f6d8e68 100755
--- a/app/controllers/reports/dailysale_controller.rb
+++ b/app/controllers/reports/dailysale_controller.rb
@@ -19,10 +19,5 @@ class Reports::DailysaleController < BaseReportController
def show
end
-
- #Shop Name in Navbor
- helper_method :shop_detail
- def shop_detail
- @shop = Shop.first
- end
+
end
diff --git a/app/controllers/reports/payment_method_controller.rb b/app/controllers/reports/payment_method_controller.rb
index 0262594f..928f17d6 100644
--- a/app/controllers/reports/payment_method_controller.rb
+++ b/app/controllers/reports/payment_method_controller.rb
@@ -62,9 +62,4 @@ class Reports::PaymentMethodController < BaseReportController
end
end
- #Shop Name in Navbor
- helper_method :shop_detail
- def shop_detail
- @shop = Shop.first
- end
end
\ No newline at end of file
diff --git a/app/controllers/reports/product_sale_controller.rb b/app/controllers/reports/product_sale_controller.rb
index 38a77115..9791545e 100644
--- a/app/controllers/reports/product_sale_controller.rb
+++ b/app/controllers/reports/product_sale_controller.rb
@@ -18,4 +18,10 @@ class Reports::ProductSaleController < BaseReportController
format.xls
end
end
+
+ #Shop Name in Navbor
+ helper_method :shop_detail
+ def shop_detail
+ @shop = Shop.first
+ end
end
diff --git a/app/controllers/reports/receipt_no_controller.rb b/app/controllers/reports/receipt_no_controller.rb
index ead85d72..cff7887c 100755
--- a/app/controllers/reports/receipt_no_controller.rb
+++ b/app/controllers/reports/receipt_no_controller.rb
@@ -61,10 +61,5 @@ authorize_resource :class => false
format.json { render json: out }
end
end
-
- #Shop Name in Navbor
- helper_method :shop_detail
- def shop_detail
- @shop = Shop.first
- end
+
end
\ No newline at end of file
diff --git a/app/controllers/reports/saleitem_controller.rb b/app/controllers/reports/saleitem_controller.rb
index b9712722..24c812eb 100755
--- a/app/controllers/reports/saleitem_controller.rb
+++ b/app/controllers/reports/saleitem_controller.rb
@@ -15,7 +15,8 @@ class Reports::SaleitemController < BaseReportController
shift = ShiftSale.where('shift_started_at = ? and shift_closed_at = ? ',shift_sale.shift_started_at, shift_sale.shift_closed_at)
end
end
- @sale_data, @other_charges,@discount_data , @cash_data , @card_data , @credit_data , @foc_data , @grand_total , @change_amount = Sale.get_by_shift_items(shift_sale_range,shift, from, to, Sale::SALE_STATUS_COMPLETED)
+ @type = params[:sale_type]
+ @sale_data, @other_charges,@discount_data , @cash_data , @card_data , @credit_data , @foc_data , @grand_total , @change_amount = Sale.get_by_shift_items(shift_sale_range,shift, from, to, Sale::SALE_STATUS_COMPLETED,@type)
@sale_taxes = Sale.get_separate_tax(shift_sale_range,shift,from,to,nil)
@@ -76,10 +77,5 @@ class Reports::SaleitemController < BaseReportController
format.json { render json: out }
end
end
-
- #Shop Name in Navbor
- helper_method :shop_detail
- def shop_detail
- @shop = Shop.first
- end
+
end
diff --git a/app/controllers/reports/shiftsale_controller.rb b/app/controllers/reports/shiftsale_controller.rb
index cf722495..21ca498b 100755
--- a/app/controllers/reports/shiftsale_controller.rb
+++ b/app/controllers/reports/shiftsale_controller.rb
@@ -48,10 +48,5 @@ class Reports::ShiftsaleController < BaseReportController
end
end
- #Shop Name in Navbor
- helper_method :shop_detail
- def shop_detail
- @shop = Shop.first
- end
end
diff --git a/app/controllers/reports/stock_check_controller.rb b/app/controllers/reports/stock_check_controller.rb
index 7dee598e..c2f2cf0d 100755
--- a/app/controllers/reports/stock_check_controller.rb
+++ b/app/controllers/reports/stock_check_controller.rb
@@ -46,11 +46,6 @@ class Reports::StockCheckController < BaseReportController
format.json { render json: out }
end
end
-
- #Shop Name in Navbor
- helper_method :shop_detail
- def shop_detail
- @shop = Shop.first
- end
+
end
diff --git a/app/controllers/reports/void_sale_controller.rb b/app/controllers/reports/void_sale_controller.rb
index 50a7c57d..32926d63 100755
--- a/app/controllers/reports/void_sale_controller.rb
+++ b/app/controllers/reports/void_sale_controller.rb
@@ -59,9 +59,4 @@ authorize_resource :class => false
end
end
- #Shop Name in Navbor
- helper_method :shop_detail
- def shop_detail
- @shop = Shop.first
- end
end
\ No newline at end of file
diff --git a/app/controllers/reports/waste_and_spoilage_controller.rb b/app/controllers/reports/waste_and_spoilage_controller.rb
new file mode 100755
index 00000000..369c6860
--- /dev/null
+++ b/app/controllers/reports/waste_and_spoilage_controller.rb
@@ -0,0 +1,19 @@
+class Reports::WasteAndSpoilageController < BaseReportController
+authorize_resource :class => false
+ def index
+ from, to = get_date_range_from_params
+ @sale_type = params[:sale_type]
+ @sale_data = Sale.get_wastes_and_spoilages(from,to,@sale_type)
+ @from = from
+ @to = to
+ # get printer info
+ @print_settings = PrintSetting.get_precision_delimiter()
+
+ respond_to do |format|
+ format.html
+ format.xls
+ end
+ end
+
+
+end
\ No newline at end of file
diff --git a/app/controllers/settings/commissioners_controller.rb b/app/controllers/settings/commissioners_controller.rb
index 4f195f43..fb8c1993 100755
--- a/app/controllers/settings/commissioners_controller.rb
+++ b/app/controllers/settings/commissioners_controller.rb
@@ -1,6 +1,7 @@
class Settings::CommissionersController < ApplicationController
load_and_authorize_resource except: [:create]
before_action :set_commissioner, only: [:show, :edit, :update, :destroy]
+ before_action :check_user
# GET /commissioners
# GET /commissioners.json
@@ -82,7 +83,11 @@ class Settings::CommissionersController < ApplicationController
end
render json: @transactions
end
-
+ def check_user
+ if current_user.nil?
+ redirect_to root_path
+ end
+ end
private
# Use callbacks to share common setup or constraints between actions.
def set_commissioner
@@ -91,6 +96,6 @@ class Settings::CommissionersController < ApplicationController
# Never trust parameters from the scary internet, only allow the white list through.
def commissioner_params
- params.require(:commissioner).permit(:name, :emp_id, :created_by, :commission_id, :joined_date, :resigned_date, :is_active)
+ params.require(:commissioner).permit(:name, :emp_id, :created_by, :commission_id, :joined_date, :resigned_date, :is_active, :image_path)
end
end
diff --git a/app/controllers/settings/commissions_controller.rb b/app/controllers/settings/commissions_controller.rb
index 5a41de17..1ac6b2cc 100755
--- a/app/controllers/settings/commissions_controller.rb
+++ b/app/controllers/settings/commissions_controller.rb
@@ -1,6 +1,7 @@
class Settings::CommissionsController < ApplicationController
load_and_authorize_resource except: [:create]
before_action :set_commission, only: [:show, :edit, :update, :destroy]
+ before_action :check_user
# GET /commissions
# GET /commissions.json
@@ -68,6 +69,12 @@ class Settings::CommissionsController < ApplicationController
# end
end
+ def check_user
+ if current_user.nil?
+ redirect_to root_path
+ end
+ end
+
private
# Use callbacks to share common setup or constraints between actions.
def set_commission
diff --git a/app/controllers/settings/display_images_controller.rb b/app/controllers/settings/display_images_controller.rb
new file mode 100644
index 00000000..48406f48
--- /dev/null
+++ b/app/controllers/settings/display_images_controller.rb
@@ -0,0 +1,11 @@
+class Settings::DisplayImagesController < ApplicationController
+ def destroy
+ #byebug
+ @item_photo = DisplayImage.find(params[:shop_id])
+ item = @item_photo.id
+ @item_photo.destroy
+ respond_to do |format|
+ format.html {redirect_to settings_shops_url+'/1/edit', notice: 'Image was successfully destroyed.'}
+ end
+ end
+end
diff --git a/app/controllers/settings/employees_controller.rb b/app/controllers/settings/employees_controller.rb
index 2bc81c51..cefb7b9c 100755
--- a/app/controllers/settings/employees_controller.rb
+++ b/app/controllers/settings/employees_controller.rb
@@ -68,6 +68,6 @@ class Settings::EmployeesController < ApplicationController
# Never trust parameters from the scary internet, only allow the white list through.
def employee_params
- params.require(:employee).permit(:name, :role, :emp_id, :password)
+ params.require(:employee).permit(:name, :role, :emp_id, :password, :image_path)
end
end
diff --git a/app/controllers/settings/menus_controller.rb b/app/controllers/settings/menus_controller.rb
index 240343b1..b7e02fb5 100755
--- a/app/controllers/settings/menus_controller.rb
+++ b/app/controllers/settings/menus_controller.rb
@@ -6,6 +6,10 @@ class Settings::MenusController < ApplicationController
# GET /settings/menus.json
def index
@settings_menus = Menu.all.page(params[:page]).per(10)
+ respond_to do |format|
+ format.html
+ format.xlsx
+ end
end
# GET /settings/menus/1
@@ -67,6 +71,14 @@ class Settings::MenusController < ApplicationController
# end
end
+ def import
+ if params[:file]
+ Menu.import(params[:file])
+ redirect_to settings_menus_path, notice: "Menu was successfully Imported"
+ end
+
+ end
+
private
# Use callbacks to share common setup or constraints between actions.
def set_settings_menu
diff --git a/app/controllers/settings/order_queue_stations_controller.rb b/app/controllers/settings/order_queue_stations_controller.rb
index b6baf64d..adcbc507 100755
--- a/app/controllers/settings/order_queue_stations_controller.rb
+++ b/app/controllers/settings/order_queue_stations_controller.rb
@@ -1,6 +1,7 @@
class Settings::OrderQueueStationsController < ApplicationController
load_and_authorize_resource except: [:create]
before_action :set_settings_order_queue_station, only: [:show, :edit, :update, :destroy]
+ before_action :check_user
# GET /settings/order_queue_stations
# GET /settings/order_queue_stations.json
@@ -67,6 +68,12 @@ class Settings::OrderQueueStationsController < ApplicationController
# end
end
+ def check_user
+ if current_user.nil?
+ redirect_to root_path
+ end
+ end
+
private
# Use callbacks to share common setup or constraints between actions.
def set_settings_order_queue_station
diff --git a/app/controllers/settings/products_controller.rb b/app/controllers/settings/products_controller.rb
index c0be149e..66e8f162 100755
--- a/app/controllers/settings/products_controller.rb
+++ b/app/controllers/settings/products_controller.rb
@@ -1,6 +1,7 @@
class Settings::ProductsController < ApplicationController
load_and_authorize_resource except: [:create]
before_action :set_settings_product, only: [:show, :edit, :update, :destroy]
+ before_action :check_user
# GET /settings/products
# GET /settings/products.json
@@ -65,6 +66,12 @@ load_and_authorize_resource except: [:create]
# end
end
+ def check_user
+ if current_user.nil?
+ redirect_to root_path
+ end
+ end
+
private
# Use callbacks to share common setup or constraints between actions.
def set_settings_product
diff --git a/app/controllers/settings/promotion_products_controller.rb b/app/controllers/settings/promotion_products_controller.rb
index d297fb71..c66761d7 100755
--- a/app/controllers/settings/promotion_products_controller.rb
+++ b/app/controllers/settings/promotion_products_controller.rb
@@ -1,6 +1,7 @@
class Settings::PromotionProductsController < ApplicationController
before_action :set_promotion, only: [:show, :edit, :update, :destroy,:new]
before_action :set_promotion_product, only: [:show, :edit, :update, :destroy]
+ before_action :check_user
# GET /promotion_products
# GET /promotion_products.json
@@ -63,6 +64,12 @@ class Settings::PromotionProductsController < ApplicationController
# end
end
+ def check_user
+ if current_user.nil?
+ redirect_to root_path
+ end
+ end
+
private
# Use callbacks to share common setup or constraints between actions.
def set_promotion
diff --git a/app/controllers/settings/promotions_controller.rb b/app/controllers/settings/promotions_controller.rb
index ec00c5f6..7272ab0c 100755
--- a/app/controllers/settings/promotions_controller.rb
+++ b/app/controllers/settings/promotions_controller.rb
@@ -1,6 +1,7 @@
class Settings::PromotionsController < ApplicationController
load_and_authorize_resource except: [:create]
before_action :set_promotion, only: [:show, :edit, :update, :destroy]
+ before_action :check_user
# GET /promotions
# GET /promotions.json
@@ -119,6 +120,12 @@ class Settings::PromotionsController < ApplicationController
render json: res
end
+ def check_user
+ if current_user.nil?
+ redirect_to root_path
+ end
+ end
+
private
# Use callbacks to share common setup or constraints between actions.
def set_promotion
diff --git a/app/controllers/settings/shops_controller.rb b/app/controllers/settings/shops_controller.rb
index a48bcb9a..365be7e2 100644
--- a/app/controllers/settings/shops_controller.rb
+++ b/app/controllers/settings/shops_controller.rb
@@ -1,6 +1,6 @@
class Settings::ShopsController < ApplicationController
load_and_authorize_resource except: [:create]
- before_action :set_shop, only: [:show, :edit, :update]
+ before_action :set_shop, only: [:show, :edit, :update, :destroy]
# GET /settings/shops
# GET /settings/shops.json
@@ -11,11 +11,13 @@ class Settings::ShopsController < ApplicationController
# GET /settings/shops/1
# GET /settings/shops/1.json
def show
+ @display_images = @settings_shop.display_images.all
end
# GET /settings/shops/new
def new
@settings_shop = Shop.new
+ @display_image = @settings_shop.display_images.build
end
# GET /settings/shops/1/edit
@@ -28,6 +30,11 @@ class Settings::ShopsController < ApplicationController
@settings_shop = Shop.new(shop_params)
respond_to do |format|
if @settings_shop.save
+ if params[:display_images].present?
+ params[:display_images]['image'].each do |a|
+ @display_image = @settings_shop.display_images.create!(:shop_id => @shop.id, :image => a)
+ end
+ end
format.html { redirect_to settings_shops_url, notice: 'Shop was successfully created.' }
format.json { render :index, status: :created, location: @settings_shop }
else
@@ -42,6 +49,11 @@ class Settings::ShopsController < ApplicationController
def update
respond_to do |format|
if @settings_shop.update(shop_params)
+ if params[:display_images].present?
+ params[:display_images]['image'].each do |a|
+ @display_image = @settings_shop.display_images.create!(:shop_id => @shop.id, :image => a)
+ end
+ end
format.html { redirect_to settings_shops_url, notice: 'Shop was successfully updated.' }
format.json { render :index, status: :ok, location: @settings_shop }
else
@@ -71,6 +83,6 @@ class Settings::ShopsController < ApplicationController
# Never trust parameters from the scary internet, only allow the white list through.
def shop_params
- params.require(:shop).permit(:name,:address,:city,:township,:state,:country,:phone_no,:reservation_no,:license,:activated_at,:license_data,:base_currency,:cloud_token,:cloud_url,:owner_token,:id_prefix,:is_rounding_adj,:quick_sale_summary,:calc_tax_order,:show_account_info)
+ params.require(:shop).permit(:logo, :name,:address,:city,:township,:state,:country,:phone_no,:reservation_no,:license,:activated_at,:license_data,:base_currency,:cloud_token,:cloud_url,:owner_token,:id_prefix,:is_rounding_adj,:quick_sale_summary,:calc_tax_order,:show_account_info, display_images_attributes: [:id, :shop_id, :image])
end
end
diff --git a/app/controllers/settings/tax_profiles_controller.rb b/app/controllers/settings/tax_profiles_controller.rb
index 77414c57..75e4343e 100755
--- a/app/controllers/settings/tax_profiles_controller.rb
+++ b/app/controllers/settings/tax_profiles_controller.rb
@@ -6,6 +6,18 @@ class Settings::TaxProfilesController < ApplicationController
# GET /settings/tax_profiles.json
def index
@settings_tax_profiles = TaxProfile.all
+ tax_profiles = Lookup.collection_of("tax_profiles")
+ if !@settings_tax_profiles.nil?
+ @settings_tax_profiles.each_with_index do |setting_tax_profile, tax_index|
+ if !tax_profiles.nil?
+ tax_profiles.each do |group|
+ if setting_tax_profile.group_type == group[1]
+ @settings_tax_profiles[tax_index].group_type = group[0]
+ end
+ end
+ end
+ end
+ end
end
# GET /settings/tax_profiles/1
@@ -15,11 +27,19 @@ class Settings::TaxProfilesController < ApplicationController
# GET /settings/tax_profiles/new
def new
+ @name = nil
@settings_tax_profile = TaxProfile.new
+ @tax_profiles = TaxProfile.all
end
# GET /settings/tax_profiles/1/edit
def edit
+ @settings_tax_profile = TaxProfile.find(params[:id])
+ @name = nil
+ if !@settings_tax_profile.nil?
+ @name = @settings_tax_profile.name
+ end
+ @tax_profiles = TaxProfile.all
end
# POST /settings/tax_profiles
@@ -69,10 +89,20 @@ class Settings::TaxProfilesController < ApplicationController
# Use callbacks to share common setup or constraints between actions.
def set_settings_tax_profile
@settings_tax_profile = TaxProfile.find(params[:id])
+ tax_profiles = Lookup.collection_of("tax_profiles")
+ if !@settings_tax_profile.nil?
+ if !tax_profiles.nil?
+ tax_profiles.each do |group|
+ if @settings_tax_profile.group_type == group[1]
+ @settings_tax_profile.group_type = group[0]
+ end
+ end
+ end
+ end
end
# Never trust parameters from the scary internet, only allow the white list through.
def settings_tax_profile_params
- params.require(:tax_profile).permit(:name, :rate, :inclusive, :order_by, :created_by)
+ params.require(:tax_profile).permit(:name, :group_type, :rate, :inclusive, :order_by, :created_by)
end
end
diff --git a/app/controllers/sym_control_controller.rb b/app/controllers/sym_control_controller.rb
index 8ef6fd78..d2923bf2 100644
--- a/app/controllers/sym_control_controller.rb
+++ b/app/controllers/sym_control_controller.rb
@@ -2,6 +2,8 @@ class SymControlController < BaseController
skip_before_action :verify_authenticity_token
http_basic_authenticate_with name: "vip", password: "!abcABC01"
+ helper_method :shop_detail
+
def run
sym_path = File.expand_path("~/symmetric/")
check_sym_proc_str = `#{"sudo service SymmetricDS status"}`
@@ -43,4 +45,9 @@ class SymControlController < BaseController
end
end
+ #Shop Name in Navbor
+ def shop_detail
+ @shop = Shop.first
+ end
+
end
\ No newline at end of file
diff --git a/app/controllers/transactions/credit_notes_controller.rb b/app/controllers/transactions/credit_notes_controller.rb
index e35baa77..27f52f12 100755
--- a/app/controllers/transactions/credit_notes_controller.rb
+++ b/app/controllers/transactions/credit_notes_controller.rb
@@ -1,6 +1,7 @@
class Transactions::CreditNotesController < ApplicationController
before_action :set_transactions_sale, only: [:show, :edit, :update, :destroy]
+ before_action :check_user
# GET /transactions/sales
# GET /transactions/sales.json
@@ -25,12 +26,18 @@ class Transactions::CreditNotesController < ApplicationController
@credit_notes = 0
end
end
-puts "sssssssssssss"
-puts @credit_notes.to_json
+
respond_to do |format|
format.html # index.html.erb
format.json { render json: @credit_notes }
end
- end
- end
\ No newline at end of file
+ end
+
+ def check_user
+ if current_user.nil?
+ redirect_to root_path
+ end
+ end
+
+end
\ No newline at end of file
diff --git a/app/controllers/transactions/orders_controller.rb b/app/controllers/transactions/orders_controller.rb
index 17a117bb..c2132ff6 100755
--- a/app/controllers/transactions/orders_controller.rb
+++ b/app/controllers/transactions/orders_controller.rb
@@ -1,5 +1,7 @@
class Transactions::OrdersController < ApplicationController
load_and_authorize_resource except: [:create]
+ before_action :check_user
+
def index
filter = params[:filter]
@@ -21,11 +23,12 @@ class Transactions::OrdersController < ApplicationController
@receipt_no = filter
@from = from
@to = to
-
+
respond_to do |format|
- format.html # index.html.erb
- format.json { render json: @orders }
- end
+ format.html
+ format.json { render json: @orders }
+ # format.csv { send_data OrdersCsvExport.generate }
+ end
end
def show
@@ -38,4 +41,10 @@ class Transactions::OrdersController < ApplicationController
end
end
+ def check_user
+ if current_user.nil?
+ redirect_to root_path
+ end
+ end
+
end
diff --git a/app/controllers/transactions/sales_controller.rb b/app/controllers/transactions/sales_controller.rb
index fafc89f3..be370371 100755
--- a/app/controllers/transactions/sales_controller.rb
+++ b/app/controllers/transactions/sales_controller.rb
@@ -1,20 +1,30 @@
class Transactions::SalesController < ApplicationController
load_and_authorize_resource except: [:create]
before_action :set_transactions_sale, only: [:show, :edit, :update, :destroy]
+ before_action :check_user
# GET /transactions/sales
# GET /transactions/sales.json
def index
receipt_no = params[:receipt_no]
- from = params[:from]
- to = params[:to]
+ # from = params[:from]
+ # to = params[:to]
+ from, to = get_date_range_from_params
+ @shift = ''
+ if params[:shift_name].to_i != 0
+ @shift = ShiftSale.find(params[:shift_name])
+ end
if receipt_no.nil? && from.nil? && to.nil?
- @sales = Sale.where("NOT sale_status = 'void' " ).order("sale_id desc")
+ if @shift.blank?
+ @sales = Sale.where("NOT sale_status='new'").order("sale_id desc")
+ else
+ @sales = Sale.where("NOT sale_status='new' and shift_sale_id ='#{@shift.id}'").order("sale_id desc")
+ end
@sales = Kaminari.paginate_array(@sales).page(params[:page]).per(20)
else
- sale = Sale.search(receipt_no,from,to)
+ sale = Sale.search(receipt_no,from,to,@shift)
if sale.count > 0
@sales = sale
@sales = Kaminari.paginate_array(@sales).page(params[:page]).per(20)
@@ -25,6 +35,12 @@ class Transactions::SalesController < ApplicationController
@receipt_no = receipt_no
@from = from
@to = to
+
+ if @shift.present?
+ @shift_from = @shift.shift_started_at.nil? ? '-' : @shift.shift_started_at.utc.getlocal.strftime("%e %b %I:%M%p")
+ @shift_to = @shift.shift_closed_at.nil? ? '-' : @shift.shift_closed_at.utc.getlocal.strftime("%e %b %I:%M%p")
+ @shift_data = @shift
+ end
# if receipt_no.nil? && search_date.nil?
# @sales = Sale.where("NOT sale_status = 'void' " ).order("sale_id desc").limit(500)
@@ -45,6 +61,24 @@ class Transactions::SalesController < ApplicationController
# end
# end
+ @sale_audits = []
+ @sale_item_audits = []
+ if @sales != 0
+ @sales.each do |sale|
+ sale_audit = SaleAudit.where("(action = 'SALEPAYMENT' or action = 'SALEVOID') and sale_id = ? and remark IS NOT NULL",sale.sale_id)
+ if !sale_audit.nil?
+ sale_audit.each do |audit|
+ @sale_audits.push({sale.sale_id => audit.remark})
+ end
+ end
+
+ sale_item_audit = SaleAudit.where("(action LIKE '%ITEM%') and sale_id = ?",sale.sale_id)
+ if !sale_item_audit.nil? && sale_item_audit.count > 0
+ @sale_item_audits.push({sale.sale_id => sale_item_audit.count})
+ end
+ end
+ end
+
respond_to do |format|
format.html # index.html.erb
format.json { render json: @sales }
@@ -129,6 +163,80 @@ class Transactions::SalesController < ApplicationController
end
end
+ # date range
+ PERIOD = {
+ "today" => 0,
+ "yesterday" => 1,
+ "this_week" => 2,
+ "last_week" => 3,
+ "last_7" => 4,
+ "this_month" => 5,
+ "last_month" => 6,
+ "last_30" => 7,
+ "this_year" => 8,
+ "last_year" => 9
+ }
+
+ def get_date_range_from_params
+ period_type = params[:period_type]
+ period = params[:period]
+ from = params[:from]
+ to = params[:to]
+ day_ref = Time.now.utc.getlocal
+
+ if from.present? && to.present?
+ f_date = DateTime.parse(from)
+ t_date = DateTime.parse(to)
+ f_time = Time.mktime(f_date.year,f_date.month,f_date.day,f_date.hour,f_date.min,f_date.sec)
+ t_time = Time.mktime(t_date.year,t_date.month,t_date.day,t_date.hour,t_date.min,t_date.sec)
+ from = f_time.beginning_of_day.utc.getlocal
+ to = t_time.end_of_day.utc.getlocal
+ else
+ case period.to_i
+ when PERIOD["today"]
+ from = day_ref.beginning_of_day.utc
+ to = day_ref.end_of_day.utc
+
+ when PERIOD["yesterday"]
+ from = (day_ref - 1.day).beginning_of_day.utc
+ to = (day_ref - 1.day).end_of_day.utc
+
+ when PERIOD["this_week"]
+ from = Time.now.beginning_of_week.utc
+ to = Time.now.utc
+ when PERIOD["last_week"]
+ from = (day_ref - 7.day).beginning_of_week.utc
+ to = (day_ref - 7.day).end_of_week.utc
+ when PERIOD["last_7"]
+ from = (day_ref - 7.day).utc
+ to = Time.now.utc
+ when PERIOD["this_month"]
+ from = Time.now.beginning_of_month.utc
+ to = Time.now.utc
+ when PERIOD["last_month"]
+ from = (day_ref - 1.month).beginning_of_month.utc
+ to = (day_ref - 1.month).end_of_month.utc
+ when PERIOD["last_30"]
+ from = (day_ref - 30.day).utc
+ to = Time.now.utc
+ when PERIOD["this_year"]
+ from = Time.now.beginning_of_year.utc
+ to = Time.now.utc
+ when PERIOD["last_year"]
+ from = (day_ref - 1.year).beginning_of_year.utc
+ to = (day_ref - 1.year).end_of_year.utc
+ end
+ end
+
+ return from, to
+ end
+
+ def check_user
+ if current_user.nil?
+ redirect_to root_path
+ end
+ end
+
private
# Use callbacks to share common setup or constraints between actions.
def set_transactions_sale
diff --git a/app/controllers/transactions/shift_sales_controller.rb b/app/controllers/transactions/shift_sales_controller.rb
index ce226d30..f3a9fc05 100644
--- a/app/controllers/transactions/shift_sales_controller.rb
+++ b/app/controllers/transactions/shift_sales_controller.rb
@@ -1,6 +1,7 @@
class Transactions::ShiftSalesController < ApplicationController
load_and_authorize_resource except: [:create]
before_action :set_transactions_shift_sale, only: [:show, :edit, :update, :destroy]
+ before_action :check_user
def index
@@ -53,6 +54,12 @@ class Transactions::ShiftSalesController < ApplicationController
end
end
+ def check_user
+ if current_user.nil?
+ redirect_to root_path
+ end
+ end
+
private
# Use callbacks to share common setup or constraints between actions.
def set_transactions_shift_sale
diff --git a/app/controllers/transactions/surveys_controller.rb b/app/controllers/transactions/surveys_controller.rb
new file mode 100644
index 00000000..b6c48215
--- /dev/null
+++ b/app/controllers/transactions/surveys_controller.rb
@@ -0,0 +1,28 @@
+class Transactions::SurveysController < ApplicationController
+ def index
+ filter = params[:filter]
+ from = params[:from]
+ to = params[:to]
+
+ if filter.nil? && from.nil? && to.nil?
+ surveys = Survey.all
+ else
+ surveys = Survey.search(filter,from,to)
+ end
+
+ if !surveys.nil?
+ @surveys = Kaminari.paginate_array(surveys).page(params[:page]).per(20)
+ else
+ @surveys = []
+ end
+
+ @filter = filter
+ @from = from
+ @to = to
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.json { render json: @surveys }
+ end
+ end
+end
diff --git a/app/models/ability.rb b/app/models/ability.rb
index 95c6005f..b1930e1b 100755
--- a/app/models/ability.rb
+++ b/app/models/ability.rb
@@ -93,6 +93,11 @@ class Ability
can :index, :home
can :show, :home
+ #ability for split_bill
+ can :index, :split_bill
+ can :create, :split_bill
+ can :update_sale, :split_bill
+
elsif user.role == "cashier"
# can :overall_void, :void
@@ -100,7 +105,7 @@ class Ability
can :show, :home
can :read, Order
can :update, Order
- can :menage, Booking
+ can :manage, Booking
can :manage, OrderQueueStation
can :read, Sale
can :update, Sale
@@ -174,6 +179,11 @@ class Ability
can :remove_all_discount, :discount
can :member_discount, :discount
+ can :move_dining, :movetable
+ can :moving, :movetable
+
+ can :move_dining, :moveroom
+
can :manage, Customer
can :manage, DiningQueue
@@ -191,6 +201,11 @@ class Ability
can :index, :home
can :show, :home
+
+ #ability for split_bill
+ can :index, :split_bill
+ can :create, :split_bill
+ can :update_sale, :split_bill
elsif user.role == "waiter"
can :index, :home
can :show, :home
diff --git a/app/models/commissioner.rb b/app/models/commissioner.rb
index 2b262afc..68573460 100755
--- a/app/models/commissioner.rb
+++ b/app/models/commissioner.rb
@@ -7,4 +7,7 @@ class Commissioner < ApplicationRecord
# validations
validates_presence_of :name
+
+ # Commissioner Image Uploader
+ mount_uploader :image_path, CommissionerImageUploader
end
diff --git a/app/models/customer.rb b/app/models/customer.rb
index fcdd7f31..934d371f 100755
--- a/app/models/customer.rb
+++ b/app/models/customer.rb
@@ -2,6 +2,9 @@ class Customer < ApplicationRecord
#self.primary_key = :customer_id
+ # Customer Image Uploader
+ mount_uploader :image_path, CustomerImageUploader
+
before_create :generate_custom_id
has_many :orders
has_many :sales
@@ -31,7 +34,7 @@ class Customer < ApplicationRecord
}.to_json,
:headers => {
'Content-Type' => 'application/json',
- 'Accept' => 'application/json; version=2'
+ 'Accept' => 'application/json; version=3'
},
:timeout => 10)
rescue HTTParty::Error
@@ -68,7 +71,7 @@ class Customer < ApplicationRecord
}.to_json,
:headers => {
'Content-Type' => 'application/json',
- 'Accept' => 'application/json; version=2'
+ 'Accept' => 'application/json; version=3'
},
:timeout => 10
)
@@ -121,7 +124,7 @@ class Customer < ApplicationRecord
:body => member_params,
:headers => {
'Content-Type' => 'application/json',
- 'Accept' => 'application/json; version=2'
+ 'Accept' => 'application/json; version=3'
})
rescue Net::OpenTimeout
response = { status: false, message: "Server Time out" }
@@ -198,7 +201,7 @@ class Customer < ApplicationRecord
}.to_json,
:headers => {
'Content-Type' => 'application/json',
- 'Accept' => 'application/json; version=2'
+ 'Accept' => 'application/json; version=3'
}, :timeout => 10)
rescue Net::OpenTimeout
response = { "status": false , "message": "Connect To" }
@@ -274,7 +277,7 @@ class Customer < ApplicationRecord
}.to_json,
:headers => {
'Content-Type' => 'application/json',
- 'Accept' => 'application/json; version=2'
+ 'Accept' => 'application/json; version=3'
}, :timeout => 10)
rescue Net::OpenTimeout
response = { "status": false , "message": "Connect To" }
@@ -309,7 +312,7 @@ class Customer < ApplicationRecord
}.to_json,
:headers => {
'Content-Type' => 'application/json',
- 'Accept' => 'application/json; version=2'
+ 'Accept' => 'application/json; version=3'
},
:timeout => 10
)
diff --git a/app/models/display_image.rb b/app/models/display_image.rb
new file mode 100644
index 00000000..63405b26
--- /dev/null
+++ b/app/models/display_image.rb
@@ -0,0 +1,5 @@
+class DisplayImage < ApplicationRecord
+ mount_uploader :image, DisplayImageUploader
+ belongs_to :shop
+
+end
diff --git a/app/models/employee.rb b/app/models/employee.rb
index a12521cb..c1f985ea 100755
--- a/app/models/employee.rb
+++ b/app/models/employee.rb
@@ -8,6 +8,9 @@ class Employee < ApplicationRecord
validates :emp_id, uniqueness: true, numericality: true, length: {in: 1..4}, allow_blank: true
validates :password, numericality: true, length: {in: 3..9}, allow_blank: true
+ # Employee Image Uploader
+ mount_uploader :image_path, EmployeeImageUploader
+
def self.all_emp_except_waiter
Employee.where('role!=?','waiter')
end
diff --git a/app/models/inventory_definition.rb b/app/models/inventory_definition.rb
index 91823068..4634ff73 100755
--- a/app/models/inventory_definition.rb
+++ b/app/models/inventory_definition.rb
@@ -12,7 +12,7 @@ class InventoryDefinition < ApplicationRecord
end
def self.find_product_in_inventory(item)
- product = InventoryDefinition.find_by_item_code(item.product_code)
+ product = InventoryDefinition.find_by_item_code(item.item_instance_code)
if product.nil?
return false, nil
else
@@ -21,7 +21,7 @@ class InventoryDefinition < ApplicationRecord
end
def self.check_balance(item,inventory_definition) # item => saleItemOBj
- stock = StockJournal.where('item_code=?', item.product_code).order('created_at desc').take
+ stock = StockJournal.where('item_code=?', item.item_instance_code).order('created_at desc').take
unless stock.nil?
modify_balance(item, stock, inventory_definition)
else
diff --git a/app/models/license.rb b/app/models/license.rb
index 7d935185..ac82721c 100755
--- a/app/models/license.rb
+++ b/app/models/license.rb
@@ -1,7 +1,7 @@
class License
include HTTParty
- base_uri "connect.smartsales.dev/api"
+ base_uri "connect.smartsales.asia/api"
attr_accessor :name, :address_1, :address_2, :township, :city, :country, :email, :phone, :fax, :logo, :subdomain,
:plan_activation_date, :plan_next_renewal_date, :plan_max_products,:plan_max_customers, :plan_active_connections,
diff --git a/app/models/menu.rb b/app/models/menu.rb
index b96fe03a..9f4e6b14 100755
--- a/app/models/menu.rb
+++ b/app/models/menu.rb
@@ -1,4 +1,6 @@
class Menu < ApplicationRecord
+
+ require 'spreadsheet'
has_many :menu_categories, dependent: :destroy
validates_presence_of :name, :valid_days, :valid_time_from, :valid_time_to
@@ -31,4 +33,120 @@ class Menu < ApplicationRecord
menu.destroy
return false
end
-end
+
+ def self.to_csv
+ m_attributes = %w{name is_active valid_days valid_time_from valid_time_to created_by created_at updated_at}
+ CSV.generate(headers: true, row_sep: "\r\n") do |csv|
+ csv << m_attributes
+ menu = Menu.all
+ menu.each do |user|
+ csv << m_attributes.map{ |attr| user.send(attr)}
+ end
+ end
+ end
+
+ def self.import(file)
+
+ spreadsheet = open_spreadsheet(file)
+ sheet_count = spreadsheet.sheets.count-1
+ for i in 0..sheet_count do
+ header = spreadsheet.sheet(i).row(1)
+ sheet_name = spreadsheet.sheets[i]
+
+ (2..spreadsheet.sheet(i).last_row).each do |ii|
+ row = Hash[[header,spreadsheet.sheet(i).row(ii)].transpose]
+ if sheet_name == "Account"
+ # Account.create(id:row["id"], title: row["title"],account_type: row["account_type"],discount: row["discount"],point: row["point"],bonus: row["bonus"],rebate: row["rebate"])
+ account = Account.find_by_id(row["id"])
+ if account
+ Account.create(title: row["title"],account_type: row["account_type"],discount: row["discount"],point: row["point"],bonus: row["bonus"],rebate: row["rebate"])
+ else
+ Account.create(id:row["id"], title: row["title"],account_type: row["account_type"],discount: row["discount"],point: row["point"],bonus: row["bonus"],rebate: row["rebate"])
+ end
+ elsif sheet_name == "Item Set"
+ # ItemSet.create(id:row["id"], name: row[name], alt_name: row[alt_name], min_selectable_qty: row[min_selectable_qty], max_selectable_qty: row[max_selectable_qty])
+ item_set = ItemSet.find_by_id(row["id"])
+ if item_set
+ ItemSet.create( name: row[name], alt_name: row[alt_name], min_selectable_qty: row[min_selectable_qty], max_selectable_qty: row[max_selectable_qty])
+ else
+ ItemSet.create(id:row["id"], name: row[name], alt_name: row[alt_name], min_selectable_qty: row[min_selectable_qty], max_selectable_qty: row[max_selectable_qty])
+ end
+ elsif sheet_name == "Menu Item Options"
+ # MenuItemOption.create(id:row["id"], option_type: row["option_type"],name: row["name"],value: row["value"])
+ item_options = MenuItemOption.find_by_id(row["id"])
+ if item_options
+ MenuItemOption.create( option_type: row["option_type"],name: row["name"],value: row["value"])
+ else
+ MenuItemOption.create(id:row["id"], option_type: row["option_type"],name: row["name"],value: row["value"])
+ end
+ elsif sheet_name == "Menu Item Attributes"
+ # MenuItemAttribute.create(id:row["id"], attribute_type: row["attribute_type"],name: row["name"],value: row["value"])
+ item_attributes = MenuItemAttribute.find_by_id(row["id"])
+ if item_attributes
+ MenuItemAttribute.create( attribute_type: row["attribute_type"],name: row["name"],value: row["value"])
+ else
+ MenuItemAttribute.create(id:row["id"], attribute_type: row["attribute_type"],name: row["name"],value: row["value"])
+ end
+ elsif sheet_name == "Menu"
+ menu = Menu.find_by_id(row["id"])
+ if menu
+ Menu.create(name: row["name"], is_active: row["is_active"], valid_days: row["valid_days"],valid_time_from: row["valid_time_from"], valid_time_to: row["valid_time_to"], created_by: row["created_by"])
+ else
+ Menu.create(id:row["id"], name: row["name"], is_active: row["is_active"], valid_days: row["valid_days"],valid_time_from: row["valid_time_from"], valid_time_to: row["valid_time_to"], created_by: row["created_by"])
+ end
+ elsif sheet_name == "Menu Category"
+ # MenuCategory.create(id:row["id"], menu_id: row["menu_id"], code: row["code"], name: row["name"], alt_name: row["alt_name"], order_by: row["order_by"], created_by: row["created_by"], menu_category_id: row["menu_category_id"], is_available: row["is_available"])
+ menu_category = MenuCategory.find_by_id(row["id"])
+ if menu_category
+ MenuCategory.create(menu_id: row["menu_id"], code: row["code"], name: row["name"], alt_name: row["alt_name"], order_by: row["order_by"], created_by: row["created_by"], menu_category_id: row["menu_category_id"], is_available: row["is_available"])
+ else
+ MenuCategory.create(id:row["id"], menu_id: row["menu_id"], code: row["code"], name: row["name"], alt_name: row["alt_name"], order_by: row["order_by"], created_by: row["created_by"], menu_category_id: row["menu_category_id"], is_available: row["is_available"])
+ end
+ elsif sheet_name == "Menu Item"
+ # MenuItem.create(id:row["id"], item_code: row["item_code"], name: row["name"], alt_name: row["alt_name"], image_path: row["image_path"], description: row["description"], information: row["information"], unit: row["unit"], type: row["type"], menu_category_id: row["menu_category_id"], item_attributes: row["item_attributes"], item_options: row["item_options"], account_id: row["account_id"], min_qty: row["min_qty"], taxable: row["taxable"], is_sub_item: row["is_sub_item"], is_available: row["is_available"], created_by: row["created_by"])
+ menu_item = MenuItem.find_by_id(row["id"])
+ if menu_item
+ MenuItem.create(item_code: row["item_code"], name: row["name"], alt_name: row["alt_name"], image_path: row["image_path"], description: row["description"], information: row["information"], unit: row["unit"], type: row["type"], menu_category_id: row["menu_category_id"], item_attributes: JSON.parse(row["item_attributes"]), item_options: JSON.parse(row["item_options"]), account_id: row["account_id"], min_qty: row["min_qty"], taxable: row["taxable"], is_sub_item: row["is_sub_item"], is_available: row["is_available"], created_by: row["created_by"])
+ else
+ MenuItem.create(id:row["id"], item_code: row["item_code"], name: row["name"], alt_name: row["alt_name"], image_path: row["image_path"], description: row["description"], information: row["information"], unit: row["unit"], type: row["type"], menu_category_id: row["menu_category_id"], item_attributes: JSON.parse(row["item_attributes"]), item_options: JSON.parse(row["item_options"]), account_id: row["account_id"], min_qty: row["min_qty"], taxable: row["taxable"], is_sub_item: row["is_sub_item"], is_available: row["is_available"], created_by: row["created_by"])
+ end
+ elsif sheet_name == "Menu Item Instance"
+ # MenuItemInstance.create(id:row["id"], menu_item_id: row["menu_item_id"].to_i, item_instance_code: row["item_instance_code"], item_instance_name: row["item_instance_name"], item_attributes: row["item_attributes"], price: row["price"], is_on_promotion: row["is_on_promotion"], promotion_price: row["promotion_price"], is_available: row["is_available"], is_default: row["is_default"])
+ item_instance = MenuItemInstance.find_by_id(row["id"])
+ if item_instance
+ MenuItemInstance.create(menu_item_id: row["menu_item_id"].to_i, item_instance_code: row["item_instance_code"], item_instance_name: row["item_instance_name"], item_attributes: JSON.parse(row["item_attributes"]), price: row["price"], is_on_promotion: row["is_on_promotion"], promotion_price: row["promotion_price"], is_available: row["is_available"], is_default: row["is_default"])
+ else
+ MenuItemInstance.create(id:row["id"], menu_item_id: row["menu_item_id"].to_i, item_instance_code: row["item_instance_code"], item_instance_name: row["item_instance_name"], item_attributes: JSON.parse(row["item_attributes"]), price: row["price"], is_on_promotion: row["is_on_promotion"], promotion_price: row["promotion_price"], is_available: row["is_available"], is_default: row["is_default"])
+ end
+ elsif sheet_name == "Menu Instance Item Set"
+ # MenuInstanceItemSet.create(id:row["id"], item_set_id: row["item_set_id"], menu_item_instance_id: row["menu_item_instance_id"])
+ menu_instance_set = MenuInstanceItemSet.find_by_id(row["id"])
+ if menu_instance_set
+ MenuInstanceItemSet.create(item_set_id: row["item_set_id"], menu_item_instance_id: row["menu_item_instance_id"])
+ else
+ MenuInstanceItemSet.create(id:row["id"], item_set_id: row["item_set_id"], menu_item_instance_id: row["menu_item_instance_id"])
+ end
+ elsif sheet_name == "Menu Item Set"
+ # MenuItemSet.create(id:row["id"], item_set_id: row["item_set_id"], menu_item_id: row["menu_item_id"])
+ menu_item_set = MenuItemSet.find_by_id(row["id"])
+ if menu_item_set
+ MenuItemSet.create(item_set_id: row["item_set_id"], menu_item_id: row["menu_item_id"])
+ else
+ MenuItemSet.create(id:row["id"], item_set_id: row["item_set_id"], menu_item_id: row["menu_item_id"])
+ end
+ end
+ end
+ end
+
+ end
+
+ def self.open_spreadsheet(file)
+ case File.extname(file.original_filename)
+ when ".csv" then Roo::CSV.new(file.path,nil,:ignore)
+ when ".xls" then Roo::Excel.new(file.path,nil,:ignore)
+ when ".xlsx" then Roo::Excelx.new(file.path,nil,:ignore)
+ else raise "Unknown File type: #{original_filename}"
+ end
+ end
+
+end
\ No newline at end of file
diff --git a/app/models/menu_category.rb b/app/models/menu_category.rb
index acb06c4f..666f251a 100755
--- a/app/models/menu_category.rb
+++ b/app/models/menu_category.rb
@@ -1,7 +1,7 @@
class MenuCategory < ApplicationRecord
# before_create :generate_menu_category_code
- belongs_to :menu
+ belongs_to :menu
has_many :children, :class_name => "MenuCategory", foreign_key: "menu_category_id"
belongs_to :parent, :class_name => "MenuCategory", foreign_key: "menu_category_id", optional: true
has_many :menu_items
@@ -83,4 +83,19 @@ class MenuCategory < ApplicationRecord
# def generate_menu_category_code
# self.code = SeedGenerator.generate_code(self.class.name, "C")
# end
+
+ def self.to_csv
+
+ mc_attributes = %w{id menu_id code name alt_name order_by created_by menu_category_id is_available created_at updated_at}
+ CSV.generate(headers: true) do |csv|
+ csv << mc_attributes
+
+ csv << mc_attributes
+ MenuCategory.all.each do |user|
+ puts user
+ csv << mc_attributes.map{ |attr| user.send(attr)}
+ end
+ end
+
+ end
end
diff --git a/app/models/order.rb b/app/models/order.rb
index 3f8ce21a..fcc8b6c2 100755
--- a/app/models/order.rb
+++ b/app/models/order.rb
@@ -71,9 +71,9 @@ class Order < ApplicationRecord
BookingOrder.create({:booking_id => booking.booking_id, :order => self})
#Send order to queue one it done!
- if self.source != "quick_service"
+ # if self.source != "quick_service"
process_order_queue
- end
+ # end
#send order to broadcast job
send_order_broadcast(booking)
@@ -135,7 +135,7 @@ class Order < ApplicationRecord
#loop to add all items to order
ordered_list.each do |item|
-
+
menu_item = MenuItem.search_by_item_code(item[:item_instance_code])
# For Product while item code not in menu item
@@ -152,7 +152,7 @@ class Order < ApplicationRecord
item[:sub_items].each do |si|
# Retrive instance's Price
set_item = MenuItem.search_by_item_code(si[:item_instance_code])
- set_order_items.push({"item_instance_code"=>si[:item_instance_code], "quantity"=>si[:quantity], "price"=>set_item[:price]})
+ set_order_items.push({"item_instance_code"=>si[:item_instance_code], "item_instance_name"=>set_item[:name], "quantity"=>si[:quantity], "price"=>set_item[:price], "options"=>si[:options]})
end
end
set_order_items = set_order_items.to_json
@@ -290,14 +290,14 @@ class Order < ApplicationRecord
cup_status = `#{"sudo service cups status"}`
print_status = check_cup_status(cup_status)
sidekiq = Lookup.find_by_lookup_type("sidekiq")
-
+
if print_status
if !sidekiq.nil?
OrderQueueProcessorJob.perform_later(self.id, self.table_id)
else
if order
oqs = OrderQueueStation.new
- oqs.process_order(order, self.table_id)
+ oqs.process_order(order, self.table_id, self.source)
end
assign_order = AssignedOrderItem.assigned_order_item_by_job(self.id)
ActionCable.server.broadcast "order_queue_station_channel",order: assign_order
@@ -313,7 +313,7 @@ class Order < ApplicationRecord
else
if order
oqs = OrderQueueStation.new
- oqs.process_order(order, self.table_id)
+ oqs.process_order(order, self.table_id, self.source)
end
assign_order = AssignedOrderItem.assigned_order_item_by_job(self.id)
ActionCable.server.broadcast "order_queue_station_channel",order: assign_order
@@ -326,7 +326,7 @@ class Order < ApplicationRecord
else
if order
oqs = OrderQueueStation.new
- oqs.process_order(order, self.table_id)
+ oqs.process_order(order, self.table_id, self.source)
end
assign_order = AssignedOrderItem.assigned_order_item_by_job(self.id)
ActionCable.server.broadcast "order_queue_station_channel",order: assign_order
@@ -339,17 +339,17 @@ class Order < ApplicationRecord
#Process order items and send to order queue
def self.pay_process_order_queue(id,table_id)
sidekiq = Lookup.find_by_lookup_type("sidekiq")
- if !sidekiq.nil?
- OrderQueueProcessorJob.perform_later(id, table_id)
- else
- order = Order.find(id)
- if order
- oqs = OrderQueueStation.new
- oqs.process_order(order, table_id)
- end
- assign_order = AssignedOrderItem.assigned_order_item_by_job(id)
- ActionCable.server.broadcast "order_queue_station_channel",order: assign_order
- end
+ if !sidekiq.nil?
+ OrderQueueProcessorJob.perform_later(id, table_id)
+ else
+ order = Order.find(id)
+ if order
+ oqs = OrderQueueStation.new
+ oqs.process_order(order, table_id)
+ end
+ assign_order = AssignedOrderItem.assigned_order_item_by_job(id)
+ ActionCable.server.broadcast "order_queue_station_channel",order: assign_order
+ end
end
def check_cup_status(status)
diff --git a/app/models/order_item.rb b/app/models/order_item.rb
index 776bb94c..87d60e63 100755
--- a/app/models/order_item.rb
+++ b/app/models/order_item.rb
@@ -5,7 +5,8 @@ class OrderItem < ApplicationRecord
before_create :generate_custom_id
#Associations
- belongs_to :order, autosave: true
+ belongs_to :order, autosave: true
+ # belongs_to :order, counter_cache: true
#Validation
validates_presence_of :item_code, :item_name, :qty
diff --git a/app/models/order_queue_station.rb b/app/models/order_queue_station.rb
index af544ce5..889491ed 100755
--- a/app/models/order_queue_station.rb
+++ b/app/models/order_queue_station.rb
@@ -13,7 +13,7 @@ class OrderQueueStation < ApplicationRecord
# validations
validates_presence_of :station_name, :printer_name
- def process_order (order, table_id)
+ def process_order (order, table_id, order_source = nil)
oqs_stations = OrderQueueStation.active
@@ -55,7 +55,7 @@ class OrderQueueStation < ApplicationRecord
end
end
- if oqs.auto_print
+ if oqs.auto_print && order_source != "quick_service"
if oqs_order_items.length > 0
print_slip(oqs, order, oqs_order_items)
is_auto_printed = true
@@ -90,7 +90,81 @@ class OrderQueueStation < ApplicationRecord
end
end
- if oqs.auto_print
+ if oqs.auto_print && order_source != "quick_service"
+ if oqs_order_items.length > 0
+ print_slip(oqs, order, oqs_order_items)
+ is_auto_printed = true
+ end
+ end
+ end
+ end
+ end #end else
+ end
+
+ def pay_process_order_queue (order_id, table_id)
+
+ oqs_stations = OrderQueueStation.active
+
+ order = Order.find(order_id)
+ order_items = order.order_items
+
+ if table_id.to_i > 0
+ # get dining
+ dining = DiningFacility.find(table_id)
+ oqs_by_zones = OrderQueueProcessByZone.where("zone_id=#{dining.zone_id}")
+ booking = Booking.find_by_dining_facility_id(dining.id)
+
+ # ToDo per item per printer
+
+ oqs_by_zones.each do |oqpbz|
+ oqs = OrderQueueStation.find(oqpbz.order_queue_station_id)
+ is_auto_printed = false
+ oqs_order_items = []
+
+ if oqs.is_active
+ #Get List of items -
+ pq_items = JSON.parse(oqs.processing_items)
+ #Loop through the processing items
+ pq_items.each do |pq_item|
+ #Processing through the looping items
+ order_items.each do |order_item|
+ if (pq_item == order_item.item_code)
+ if (order_item.qty > 0)
+ oqs_order_items.push(order_item)
+ end
+ end
+ end
+ end
+
+ if oqs.auto_print
+ if oqs_order_items.length > 0
+ print_slip(oqs, order, oqs_order_items)
+ is_auto_printed = true
+ end
+ end
+ end
+ end
+ else
+ oqs_stations.each do |oqs|
+ is_auto_printed = false
+ oqs_order_items = []
+
+ if oqs.is_active
+ #Get List of items -
+ pq_items = JSON.parse(oqs.processing_items)
+ #Loop through the processing items
+ pq_items.each do |pq_item|
+ #Processing through the looping items
+ order_items.each do |order_item|
+ if (pq_item == order_item.item_code)
+ if (order_item.qty > 0)
+ oqs_order_items.push(order_item)
+ end
+ end
+ end
+ end
+
+ if oqs.auto_print
if oqs_order_items.length > 0
print_slip(oqs, order, oqs_order_items)
is_auto_printed = true
diff --git a/app/models/print_setting.rb b/app/models/print_setting.rb
index d28b852b..a3cfc597 100755
--- a/app/models/print_setting.rb
+++ b/app/models/print_setting.rb
@@ -1,6 +1,6 @@
class PrintSetting < ApplicationRecord
# validations
- validates_presence_of :name, :unique_code, :printer_name, :page_width, :page_height, :print_copies
+ validates_presence_of :name, :unique_code, :printer_name, :brand_name, :api_settings, :page_width, :page_height, :print_copies
def self.get_precision_delimiter
PrintSetting.find_by_unique_code("ReceiptBillPdf")
diff --git a/app/models/printer/printer_worker.rb b/app/models/printer/printer_worker.rb
index c0485187..2924853e 100755
--- a/app/models/printer/printer_worker.rb
+++ b/app/models/printer/printer_worker.rb
@@ -24,6 +24,11 @@ class Printer::PrinterWorker
end
end
+ # Options from printer name
+ def self.printer_options(printer_name)
+ Cups.options_for(printer_name)
+ end
+
def self.printers()
Cups.show_destinations
end
diff --git a/app/models/printer/receipt_printer.rb b/app/models/printer/receipt_printer.rb
index d544c908..a5482b31 100755
--- a/app/models/printer/receipt_printer.rb
+++ b/app/models/printer/receipt_printer.rb
@@ -176,7 +176,7 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker
def print_receipt_bill(printer_settings,cashier_terminal,sale_items,sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info = nil,rebate_amount=nil,shop_details, printed_status,balance,card_data)
#Use CUPS service
#Generate PDF
- #Print
+ #Print
pdf = ReceiptBillPdf.new(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details,printed_status,balance,card_data)
receipt_bill_a5_pdf = Lookup.collection_of("print_settings") #print_settings with name:ReceiptBillA5Pdf
if !receipt_bill_a5_pdf.empty?
@@ -202,14 +202,14 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker
begin
if count == 1
- filename = "/receipts/receipt_bill_#{sale_data.receipt_no}.pdf"
- pdf.render_file directory_name + "/receipt_bill_#{sale_data.receipt_no}.pdf"
+ filename = directory_name + "/receipt_bill_#{sale_data.receipt_no}.pdf"
+ pdf.render_file filename
if printed_status != 'Paid'
self.print(directory_name + "/receipt_bill_#{sale_data.receipt_no}.pdf", cashier_terminal.printer_name)
end
else
- filename = "/receipts/receipt_bill_#{sale_data.receipt_no}_#{count}.pdf"
- pdf.render_file directory_name + "/receipt_bill_#{sale_data.receipt_no}_#{count}.pdf"
+ filename = directory_name + "/receipt_bill_#{sale_data.receipt_no}_#{count}.pdf"
+ pdf.render_file filename
if printed_status != 'Paid'
self.print(directory_name + "/receipt_bill_#{sale_data.receipt_no}_#{count}.pdf", cashier_terminal.printer_name)
end
@@ -262,11 +262,11 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker
def print_receipt_pdf(filename,receipt_no,print_copies,printer_name)
count = print_copies.to_i
# if count == 0
- # self.print("public"+filename, printer_name)
+ # self.print(filename, printer_name)
# else
begin
if count == 1
- self.print("public"+filename, printer_name)
+ self.print(filename, printer_name)
else
filename = "public/receipts/receipt_bill_#{receipt_no}_#{count}.pdf"
self.print(filename, printer_name)
diff --git a/app/models/sale.rb b/app/models/sale.rb
index f0b5aeed..883fbad4 100755
--- a/app/models/sale.rb
+++ b/app/models/sale.rb
@@ -26,7 +26,7 @@ class Sale < ApplicationRecord
SALE_STATUS_OUTSTANDING = "outstanding"
SALE_STATUS_COMPLETED = "completed"
- def generate_invoice_from_booking(booking_id, requested_by, cashier)
+ def generate_invoice_from_booking(booking_id, requested_by, cashier, order_source = nil)
booking = Booking.find(booking_id)
status = false
Rails.logger.debug "Booking -> " + booking.id.to_s
@@ -36,9 +36,9 @@ class Sale < ApplicationRecord
booking.booking_orders.each do |order|
if booking.sale_id
- status, sale_id = generate_invoice_from_order(order.order_id, nil, booking, requested_by, cashier)
+ status, sale_id = generate_invoice_from_order(order.order_id, nil, booking, requested_by, cashier, order_source)
else
- status, sale_id = generate_invoice_from_order(order.order_id, booking.sale_id, booking, requested_by, cashier)
+ status, sale_id = generate_invoice_from_order(order.order_id, booking.sale_id, booking, requested_by, cashier, order_source)
end
booking.sale_id = sale_id
end
@@ -58,7 +58,7 @@ class Sale < ApplicationRecord
end
end
- def generate_invoice_from_order (order_id, sale_id, booking, requested_by, cashier = nil)
+ def generate_invoice_from_order (order_id, sale_id, booking, requested_by, cashier = nil, order_source = nil)
taxable = true
#if sale_id is exsit and validate
#add order to that invoice
@@ -128,7 +128,7 @@ class Sale < ApplicationRecord
self.save!
#compute sales summary
- compute
+ compute(order_source)
#Update the order items that is billed
order.update_items_status_to_billed(nil)
@@ -172,7 +172,7 @@ class Sale < ApplicationRecord
# Create Sale if it doesn't exist
# puts "current_login_employee"
# puts current_login_employee.name
- @status, @sale_id = @sale.generate_invoice_from_booking(check_booking.id,current_login_employee,current_user)
+ @status, @sale_id = @sale.generate_invoice_from_booking(check_booking.id,current_login_employee,current_user,order.source)
@sale_data = Sale.find_by_sale_id(@sale_id)
@sale_items = SaleItem.where("sale_id=?",@sale_id)
else
@@ -310,7 +310,7 @@ class Sale < ApplicationRecord
end
#compute - invoice total
- def compute
+ def compute(order_source = nil)
sales_items = self.sale_items
#Computation Fields
@@ -329,7 +329,7 @@ class Sale < ApplicationRecord
# total_taxable = total_taxable + (item.taxable_price * item.qty)
end
- apply_tax (total_taxable)
+ apply_tax(total_taxable, order_source)
self.total_amount = subtotal_price
self.total_discount = total_discount
@@ -342,8 +342,7 @@ class Sale < ApplicationRecord
end
#compute - invoice total
- def compute_by_sale_items(sale_id, sale_itemss, total_discount,discount_type=nil)
-
+ def compute_by_sale_items(sale_id, sale_itemss, total_discount,discount_type=nil,order_source=nil)
sale = Sale.find(sale_id)
sales_items = sale_itemss
@@ -362,7 +361,6 @@ class Sale < ApplicationRecord
end
end
- compute_tax(sale, total_taxable, total_discount)
sale.total_amount = subtotal_price
sale.total_discount = total_discount
sale.grand_total = (sale.total_amount - sale.total_discount) + sale.total_tax
@@ -371,12 +369,15 @@ class Sale < ApplicationRecord
end
#compute rounding adjustment
# adjust_rounding
- sale.save!
+ sale.rounding_adjustment = compute_adjust_rounding(sale.grand_total)
+ compute_tax(sale, total_taxable, total_discount, order_source)
+
+ sale.save!
end
# No Use too many wrong
- def compute_without_void
+ def compute_without_void(order_source = nil)
sales_items = self.sale_items
#Computation Fields
@@ -396,7 +397,7 @@ class Sale < ApplicationRecord
end
end
- apply_tax (total_taxable)
+ apply_tax(total_taxable, order_source)
self.total_amount = subtotal_price
self.total_discount = total_discount
self.grand_total = (self.total_amount - self.total_discount) + self.total_tax
@@ -407,7 +408,7 @@ class Sale < ApplicationRecord
end
# Tax Re-Calculte
- def compute_tax(sale, total_taxable, total_discount = 0)
+ def compute_tax(sale, total_taxable, total_discount = 0, order_source = nil)
shop = Shop.first();
#if tax is not apply create new record
@@ -423,8 +424,9 @@ class Sale < ApplicationRecord
# #Creat new tax records
if sale.payment_status != 'foc'
tax_profiles.each do |tax|
- customer.tax_profiles.each do |cus_tax|
- if cus_tax.to_i == tax.id
+ # customer.tax_profiles.each do |cus_tax|
+ # if cus_tax.to_i == tax.id
+ if tax.group_type.to_s == order_source.to_s
sale_tax = SaleTax.new(:sale => sale)
sale_tax.tax_name = tax.name
sale_tax.tax_rate = tax.rate
@@ -447,15 +449,17 @@ class Sale < ApplicationRecord
sale_tax.inclusive = tax.inclusive
sale_tax.save
- end
end
+ # end
+ # end
end
end
+
sale.total_tax = total_tax_amount
end
# Tax Calculate
- def apply_tax(total_taxable)
+ def apply_tax(total_taxable, order_source = nil)
shop = Shop.first();
#if tax is not apply create new record
@@ -469,11 +473,14 @@ class Sale < ApplicationRecord
tax_profiles = TaxProfile.all.order("order_by asc")
customer = Customer.find(self.customer_id)
-
+ if order_source.to_s == "emenu"
+ order_source = "cashier"
+ end
#Create new tax records
tax_profiles.each do |tax|
- customer.tax_profiles.each do |cus_tax|
- if cus_tax.to_i == tax.id
+ # customer.tax_profiles.each do |cus_tax|
+ # if cus_tax.to_i == tax.id
+ if tax.group_type.to_s == order_source.to_s
sale_tax = SaleTax.new(:sale => self)
sale_tax.tax_name = tax.name
sale_tax.tax_rate = tax.rate
@@ -497,8 +504,9 @@ class Sale < ApplicationRecord
sale_tax.inclusive = tax.inclusive
sale_tax.save
- end
end
+ # end
+ # end
end
self.total_tax = total_tax_amount
end
@@ -546,6 +554,26 @@ class Sale < ApplicationRecord
end
+ def compute_adjust_rounding(grand_total)
+ shop_details = Shop::ShopDetail
+ # rounding adjustment
+ if shop_details.is_rounding_adj
+ a = grand_total % 25 # Modulus
+ b = grand_total / 25 # Division
+ #not calculate rounding if modulus is 0 and division is even
+ #calculate rounding if modulus is zero or not zero and division are not even
+ if (a != 0.0 && b%2 != 0.0) || (a==0.0 && b%2 !=0)
+ new_total = Sale.get_rounding_adjustment(grand_total)
+ rounding_adjustment = new_total - grand_total
+ else
+ rounding_adjustment = 0.00
+ end
+ else
+ rounding_adjustment = 0.00
+ end
+ return rounding_adjustment
+ end
+
#Generate new Receipt No when it is not assigned
def generate_receipt_no
#shop_code and client_code
@@ -570,7 +598,7 @@ class Sale < ApplicationRecord
end
end
- def self.search(filter,from,to)
+ def self.search(filter,from,to,shift)
if filter.blank?
keyword = ''
else
@@ -578,10 +606,18 @@ class Sale < ApplicationRecord
end
if from.present? && to.present?
- sale = Sale.where("DATE_FORMAT(receipt_date,'%d-%m-%Y') >= ?" + " AND DATE_FORMAT(receipt_date,'%d-%m-%Y') <= ? and NOT sale_status = 'void' ", from,to)
- query = sale.where(keyword)
+ if shift.blank?
+ sale = Sale.where("DATE_FORMAT(receipt_date,'%Y-%m-%d') >= ?" + " AND DATE_FORMAT(receipt_date,'%Y-%m-%d') <= ? and NOT sale_status = 'new' ", from,to)
+ else
+ sale = Sale.where("DATE_FORMAT(receipt_date,'%Y-%m-%d') >= ?" + " AND DATE_FORMAT(receipt_date,'%Y-%m-%d') <= ? and NOT sale_status = 'new' and shift_sale_id = '#{shift.id}'", from,to)
+ end
+ query = sale.where(keyword)
else
+ if shift.blank?
where("receipt_no LIKE ? OR cashier_name LIKE ? OR sale_status ='#{filter}'","%#{filter}%","%#{filter}%")
+ else
+ where("receipt_no LIKE ? OR cashier_name LIKE ? OR sale_status ='#{filter}' and shift_sale_id = ?","%#{filter}%","%#{filter}%",shift.id)
+ end
end
end
@@ -770,12 +806,27 @@ def self.get_by_shift_sale(from,to,status)
return query = query.where("shift_sales.shift_started_at >= ?" + " AND shift_sales.shift_closed_at <= ?", from,to)
end
-def self.get_item_query()
- query = Sale.select("acc.title as account_name,mi.account_id, i.item_instance_code as item_code,i.account_id as account_id, " +
- "SUM(i.qty * i.unit_price) as grand_total,SUM(i.qty) as total_item,i.qty as qty," +
+def self.get_item_query(type)
+
+ if type == "revenue" || type.nil?
+ sale_type = "i.status IS NULL and i.qty >0 "
+ elsif type == "all"
+ sale_type = ""
+ elsif type == "discount"
+ sale_type = "i.status = 'Discount'"
+ elsif type == "foc"
+ sale_type = "i.status = 'foc' and i.qty > 0"
+ elsif type == "void"
+ sale_type = "i.status = 'void' and i.qty > 0"
+ elsif type == "other"
+ sale_type = "i.item_instance_code IS NULL"
+ end
+ query = Sale.select("acc.title as account_name,mi.account_id,
+ i.item_instance_code as item_code,i.account_id as account_id, " +
+ "SUM(i.qty * i.unit_price) as grand_total,
+ SUM(i.qty) as total_item,i.qty as qty," +
"i.status as status_type,"+
- " i.unit_price,i.price as price,i.product_name as product_name, mc.name as" +
- " menu_category_name,mc.id as menu_category_id ")
+ "i.unit_price,i.price as price,i.product_name as product_name,mc.name as " +"menu_category_name,mc.id as menu_category_id ")
query = query.joins("JOIN sale_items i ON i.sale_id = sales.sale_id" +
" JOIN menu_item_instances mii ON i.item_instance_code = mii.item_instance_code" +
@@ -784,7 +835,7 @@ def self.get_item_query()
" JOIN menu_categories mc ON mc.id = mi.menu_category_id ")
# "JOIN employee_accesses ea ON ea.`employee_id` = sales.cashier_id ")
query = query.joins(" JOIN accounts acc ON acc.id = mi.account_id")
- # query = query.where("i.item_instance_code IS NOT NULL")
+ query = query.where("#{sale_type}")
query = query.group("acc.title,mi.account_id,mi.menu_category_id,i.product_name,i.unit_price")
.order("acc.title desc, mi.account_id desc, mi.menu_category_id desc, i.unit_price asc")
end
@@ -799,10 +850,15 @@ def self.get_other_charges()
query = query.group("i.sale_item_id")
end
-def self.get_by_shift_items(shift_sale_range, shift, from, to, status)
+def self.get_by_shift_items(shift_sale_range, shift, from, to, status,type)
# date_type_selection = get_sql_function_for_report_type(report_type)
- query = self.get_item_query()
-
+ if type == "other"
+ other_charges = self.get_other_charges()
+ query = self.get_item_query(type)
+ else
+ query = self.get_item_query(type)
+ end
+
discount_query = 0
total_card_amount = 0
total_cash_amount = 0
@@ -884,9 +940,9 @@ def self.get_menu_item_query(order_by)
"(CASE WHEN si.qty IS NOT NULL THEN SUM(si.qty) ELSE 0 END) as total_item," +
"(CASE WHEN si.unit_price != mii.price THEN si.unit_price ELSE mii.price END) as unit_price," +
"(CASE WHEN si.qty IS NOT NULL THEN (SUM(si.qty) * si.unit_price) ELSE 0 END) as grand_total," +
- "mii.price as unit_price, (CASE WHEN si.product_name IS NOT NULL THEN si.product_name ELSE mii.item_instance_name END) as product_name,
+ "mii.price as unit_price, (CASE WHEN si.product_name IS NOT NULL THEN si.product_name ELSE CONCAT(menu_items.name,' - ',mii.item_instance_name) END) as product_name,
mc.name as" +
- " menu_category_name,mc.id as menu_category_id, si.remark as status_type,
+ " menu_category_name,mc.id as menu_category_id, si.status as status_type,
si.price as price ")
.joins(" LEFT JOIN menu_item_instances mii ON menu_items.id = mii.menu_item_id" +
" LEFT JOIN menu_categories mc ON mc.id = menu_items.menu_category_id" +
@@ -894,7 +950,7 @@ def self.get_menu_item_query(order_by)
" LEFT JOIN sale_items si ON si.item_instance_code = mii.item_instance_code" +
" LEFT JOIN sales s ON s.sale_id = si.sale_id")
.where("(CASE WHEN s.sale_status IS NOT NULL THEN s.sale_status='completed' ELSE 1 END)")
- .group("mc.id, (CASE WHEN si.product_name IS NOT NULL THEN si.product_name ELSE mii.item_instance_name END)")
+ .group("mc.id, (CASE WHEN si.product_name IS NOT NULL THEN si.product_name ELSE CONCAT(menu_items.name,' - ',mii.item_instance_name) END)")
.order("si.qty #{order_by}, menu_items.menu_category_id #{order_by}")
end
#product sale report query
@@ -1053,6 +1109,16 @@ def self.get_payment_method_by_shift(shift_sale_range,shift,from,to,payment_type
return all_total,sale_type
end
+def self.get_wastes_and_spoilages(from,to,status)
+ if status == "spoile"
+ type = "and sales.sale_status = 'spoile'"
+ else
+ type = "and sales.sale_status = 'waste'"
+ end
+ query = Sale.all.where("sales.receipt_date between ? and ? #{type}",from,to)
+ .group("sales.receipt_no")
+end
+
# def self.get_separate_tax(from,to,payment_method=nil)
# query = SaleTax.select("SUM(tax_payable_amount) AS st_amount,tax_name")
@@ -1106,88 +1172,319 @@ end
return tax
end
- def self.top_products(today,from,to)
+ def self.top_products(today,current_user,from,to,from_time,to_time)
if !from.nil? && !to.nil?
- query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," +
+ if current_user.nil?
+ query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," +
+ " i.price as unit_price,mi.name as product_name")
+ .joins("JOIN sale_items i ON i.sale_id = sales.sale_id JOIN menu_items mi ON i.product_code = mi.item_code")
+ if !from_time.nil? && !to_time.nil?
+ query = query.where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'"+
+ " and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%H:%M') between '#{from_time}' and '#{to_time}' and sale_status= 'completed'")
+ else
+ query = query.where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'"+
+ " and sale_status= 'completed'")
+ end
+ query = query.group('mi.name')
+ .order("SUM(i.qty) DESC").limit(20)
+ else
+ if current_user.role == 'administrator' || current_user.role == 'manager'
+ query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," +
" i.price as unit_price,mi.name as product_name")
.joins("JOIN sale_items i ON i.sale_id = sales.sale_id JOIN menu_items mi ON i.product_code = mi.item_code")
- .where("(i.qty > 0 and i.price > 0) and receipt_date between '#{from}' and '#{to}'"+
- "and sale_status= 'completed'")
- .group('mi.name')
- .order("SUM(i.qty) DESC").limit(20)
+ if !from_time.nil? && !to_time.nil?
+ query = query.where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'"+
+ " and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%H:%M') between '#{from_time}' and '#{to_time}' and sale_status= 'completed'")
+ else
+ query = query.where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'"+
+ " and sale_status= 'completed'")
+ end
+ query = query.group('mi.name')
+ .order("SUM(i.qty) DESC").limit(20)
+ else
+ shift = ShiftSale.current_open_shift(current_user.id)
+ if !shift.nil?
+ query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," +
+ " i.price as unit_price,mi.name as product_name")
+ .joins("JOIN sale_items i ON i.sale_id = sales.sale_id JOIN menu_items mi ON i.product_code = mi.item_code")
+ if !from_time.nil? && !to_time.nil?
+ query = query.where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'"+
+ " and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%H:%M') between '#{from_time}' and '#{to_time}' and sale_status= 'completed' and shift_sale_id='#{shift.id}'")
+ else
+ query = query.where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'"+
+ " and sale_status= 'completed' and shift_sale_id='#{shift.id}'")
+ end
+ query = query.group('mi.name')
+ .order("SUM(i.qty) DESC").limit(20)
+ end
+ end
+ end
else
- query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," +
+ if current_user.nil?
+ query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," +
" i.price as unit_price,mi.name as product_name")
.joins("JOIN sale_items i ON i.sale_id = sales.sale_id JOIN menu_items mi ON i.product_code = mi.item_code")
.where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'"+
- "and sale_status= 'completed'")
+ " and sale_status= 'completed'")
.group('mi.name')
.order("SUM(i.qty) DESC").limit(20)
+ else
+ if current_user.role == 'administrator' || current_user.role == 'manager'
+ query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," +
+ " i.price as unit_price,mi.name as product_name")
+ .joins("JOIN sale_items i ON i.sale_id = sales.sale_id JOIN menu_items mi ON i.product_code = mi.item_code")
+ .where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'"+
+ " and sale_status= 'completed'")
+ .group('mi.name')
+ .order("SUM(i.qty) DESC").limit(20)
+ else
+ shift = ShiftSale.current_open_shift(current_user.id)
+ if !shift.nil?
+ query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," +
+ " i.price as unit_price,mi.name as product_name")
+ .joins("JOIN sale_items i ON i.sale_id = sales.sale_id JOIN menu_items mi ON i.product_code = mi.item_code")
+ .where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'"+
+ " and sale_status= 'completed' and shift_sale_id='#{shift.id}'")
+ .group('mi.name')
+ .order("SUM(i.qty) DESC").limit(20)
+ end
+ end
+ end
end
end
- def self.bottom_products(today,from,to)
+ def self.bottom_products(today,current_user,from,to,from_time,to_time)
if !from.nil? && !to.nil?
- query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," +
- " i.price as unit_price,mi.name as product_name")
- .joins("JOIN sale_items i ON i.sale_id = sales.sale_id JOIN menu_items mi ON i.product_code = mi.item_code")
- .where("(i.qty > 0 and i.price > 0) and receipt_date between '#{from}' and '#{to}'"+
- "and sale_status= 'completed'")
- .group('mi.name')
+ if current_user.nil?
+ query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," +
+ " i.price as unit_price,mi.name as product_name")
+ .joins("JOIN sale_items i ON i.sale_id = sales.sale_id JOIN menu_items mi ON i.product_code = mi.item_code")
+ if !from_time.nil? && !to_time.nil?
+ query = query.where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'"+
+ " and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%H:%M') between '#{from_time}' and '#{to_time}' and sale_status= 'completed'")
+ else
+ query = query.where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'"+
+ " and sale_status= 'completed'")
+ end
+ query = query.group('mi.name')
.order("SUM(i.qty) ASC").limit(20)
+ else
+ if current_user.role == 'administrator' || current_user.role == 'manager'
+ query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," +
+ " i.price as unit_price,mi.name as product_name")
+ .joins("JOIN sale_items i ON i.sale_id = sales.sale_id JOIN menu_items mi ON i.product_code = mi.item_code")
+ if !from_time.nil? && !to_time.nil?
+ query = query.where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'"+
+ " and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%H:%M') between '#{from_time}' and '#{to_time}' and sale_status= 'completed'")
+ else
+ query = query.where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'"+
+ " and sale_status= 'completed'")
+ end
+ query = query.group('mi.name')
+ .order("SUM(i.qty) ASC").limit(20)
+ else
+ shift = ShiftSale.current_open_shift(current_user.id)
+ if !shift.nil?
+ query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," +
+ " i.price as unit_price,mi.name as product_name")
+ .joins("JOIN sale_items i ON i.sale_id = sales.sale_id JOIN menu_items mi ON i.product_code = mi.item_code")
+ if !from_time.nil? && !to_time.nil?
+ query = query.where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'"+
+ " and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%H:%M') between '#{from_time}' and '#{to_time}' and sale_status= 'completed' and shift_sale_id='#{shift.id}'")
+ else
+ query = query.where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30') between '#{from}' and '#{to}'"+
+ " and sale_status= 'completed' and shift_sale_id='#{shift.id}'")
+ end
+ query = query.group('mi.name')
+ .order("SUM(i.qty) ASC").limit(20)
+ end
+ end
+ end
else
- query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," +
+ if current_user.nil?
+ query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," +
" i.price as unit_price,mi.name as product_name")
.joins("JOIN sale_items i ON i.sale_id = sales.sale_id JOIN menu_items mi ON i.product_code = mi.item_code")
.where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'"+
"and sale_status= 'completed'")
.group('mi.name')
.order("SUM(i.qty) ASC").limit(20)
+ else
+ if current_user.role == 'administrator' || current_user.role == 'manager'
+ query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," +
+ " i.price as unit_price,mi.name as product_name")
+ .joins("JOIN sale_items i ON i.sale_id = sales.sale_id JOIN menu_items mi ON i.product_code = mi.item_code")
+ .where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'"+
+ "and sale_status= 'completed'")
+ .group('mi.name')
+ .order("SUM(i.qty) ASC").limit(20)
+ else
+ shift = ShiftSale.current_open_shift(current_user.id)
+ if !shift.nil?
+ query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," +
+ " i.price as unit_price,mi.name as product_name")
+ .joins("JOIN sale_items i ON i.sale_id = sales.sale_id JOIN menu_items mi ON i.product_code = mi.item_code")
+ .where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'"+
+ " and sale_status= 'completed' and shift_sale_id=#{shift.id}")
+ .group('mi.name')
+ .order("SUM(i.qty) ASC").limit(20)
+ end
+ end
+ end
end
end
- def self.hourly_sales(today,from,to)
+ def self.hourly_sales(today,current_user,from,to,from_time,to_time)
if !from.nil? && !to.nil?
- query= Sale.select("grand_total")
- .where('sale_status = "completed" and receipt_date between ? and ?',from,to)
- .group("date_format(CONVERT_TZ(receipt_date,'+00:00', 'SYSTEM'), '%I %p')")
- .order('receipt_date')
+ if current_user.nil?
+ query = Sale.select("grand_total")
+ if !from_time.nil? && !to_time.nil?
+ query = query.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ?',from,to,from_time,to_time)
+ else
+ query = query.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to)
+ end
+ query = query.group("date_format(CONVERT_TZ(receipt_date,'+00:00', 'SYSTEM'), '%I %p')")
+ .order('receipt_date')
+ else
+ if current_user.role == 'administrator' || current_user.role == 'manager'
+ query = Sale.select("grand_total")
+ if !from_time.nil? && !to_time.nil?
+ query = query.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ?',from,to,from_time,to_time)
+ else
+ query = query.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to)
+ end
+ query = query.group("date_format(CONVERT_TZ(receipt_date,'+00:00', 'SYSTEM'), '%I %p')")
+ .order('receipt_date')
+ else
+ shift = ShiftSale.current_open_shift(current_user.id)
+ if !shift.nil?
+ query = Sale.select("grand_total")
+ if !from_time.nil? && !to_time.nil?
+ query = query.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ? and shift_sale_id=?',from,to,from_time,to_time,shift.id)
+ else
+ query = query.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and shift_sale_id=?',from,to,shift.id)
+ end
+ query = query.group("date_format(CONVERT_TZ(receipt_date,'+00:00', 'SYSTEM'), '%I %p')")
+ .order('receipt_date')
+ end
+ end
+ end
else
- query= Sale.select("grand_total")
+ if current_user.nil?
+ query = Sale.select("grand_total")
.where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today)
.group("date_format(CONVERT_TZ(receipt_date,'+00:00', 'SYSTEM'), '%I %p')")
.order('receipt_date')
+ else
+ if current_user.role == 'administrator' || current_user.role == 'manager'
+ query = Sale.select("grand_total")
+ .where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today)
+ .group("date_format(CONVERT_TZ(receipt_date,'+00:00', 'SYSTEM'), '%I %p')")
+ .order('receipt_date')
+ else
+ shift = ShiftSale.current_open_shift(current_user.id)
+ if !shift.nil?
+ query = Sale.select("grand_total")
+ .where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ? and shift_sale_id=?',today,shift.id)
+ .group("date_format(CONVERT_TZ(receipt_date,'+00:00', 'SYSTEM'), '%I %p')")
+ .order('receipt_date')
+ end
+ end
+ end
end
end
- def self.employee_sales(today,from,to)
+ def self.employee_sales(today,current_user,from,to,from_time,to_time)
if !from.nil? && !to.nil?
- query = Sale.joins("JOIN employees as e on e.id=sales.cashier_id")
+ if current_user.nil?
+ query = Sale.joins("JOIN employees as e on e.id=sales.cashier_id")
+ .joins("JOIN sale_payments as sp on sp.sale_id=sales.sale_id")
+ if !from_time.nil? && !to_time.nil?
+ query = query.where("sales.payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%M') between '#{from_time}' and '#{to_time}'")
+ else
+ query = query.where("sales.payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'")
+ end
+ query = query.group("(CASE WHEN (sp.payment_method='mpu' or sp.payment_method='visa' or sp.payment_method='master' or sp.payment_method='jcb' or sp.payment_method='unionpay') THEN 'card' ELSE sp.payment_method END)","e.name")
+ .order("e.name")
+ else
+ if current_user.role == 'administrator' || current_user.role == 'manager'
+ query = Sale.joins("JOIN employees as e on e.id=sales.cashier_id")
.joins("JOIN sale_payments as sp on sp.sale_id=sales.sale_id")
- .where("sales.payment_status='paid' and sales.sale_status = 'completed' and sales.receipt_date between '#{from}' and '#{to}'")
- .group("(CASE WHEN (sp.payment_method='mpu' or sp.payment_method='visa' or sp.payment_method='master' or sp.payment_method='jcb' or sp.payment_method='unionpay') THEN 'card' ELSE sp.payment_method END)","e.name")
- .order("e.name")
+ if !from_time.nil? && !to_time.nil?
+ query = query.where("sales.payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%M') between '#{from_time}' and '#{to_time}'")
+ else
+ query = query.where("sales.payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'")
+ end
+ query = query.group("(CASE WHEN (sp.payment_method='mpu' or sp.payment_method='visa' or sp.payment_method='master' or sp.payment_method='jcb' or sp.payment_method='unionpay') THEN 'card' ELSE sp.payment_method END)","e.name")
+ .order("e.name")
+ else
+ shift = ShiftSale.current_open_shift(current_user.id)
+ if !shift.nil?
+ query = Sale.joins("JOIN employees as e on e.id=sales.cashier_id")
+ .joins("JOIN sale_payments as sp on sp.sale_id=sales.sale_id")
+ if !from_time.nil? && !to_time.nil?
+ query = query.where("sales.payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%M') between '#{from_time}' and '#{to_time}' and shift_sale_id='#{shift.id}'")
+ else
+ query = query.where("sales.payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}' and shift_sale_id='#{shift.id}'")
+ end
+ query = query.group("(CASE WHEN (sp.payment_method='mpu' or sp.payment_method='visa' or sp.payment_method='master' or sp.payment_method='jcb' or sp.payment_method='unionpay') THEN 'card' ELSE sp.payment_method END)","e.name")
+ .order("e.name")
+ end
+ end
+ end
else
- query = Sale.joins("JOIN employees as e on e.id=sales.cashier_id")
+ if current_user.nil?
+ query = Sale.joins("JOIN employees as e on e.id=sales.cashier_id")
.joins("JOIN sale_payments as sp on sp.sale_id=sales.sale_id")
.where("sales.payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = '#{today}'")
.group("(CASE WHEN (sp.payment_method='mpu' or sp.payment_method='visa' or sp.payment_method='master' or sp.payment_method='jcb' or sp.payment_method='unionpay') THEN 'card' ELSE sp.payment_method END)","e.name")
.order("e.name")
- end
- end
-
- def self.total_sale(today,current_user=nil,from=nil,to=nil)
- if !from.nil? && !to.nil?
- if current_user.nil?
- total = Sale.where('sale_status = "completed" and receipt_date between ? and ?',from,to).sum("grand_total")
else
if current_user.role == 'administrator' || current_user.role == 'manager'
- total = Sale.where('sale_status = "completed" and receipt_date between ? and ?',from,to).sum("grand_total")
+ query = Sale.joins("JOIN employees as e on e.id=sales.cashier_id")
+ .joins("JOIN sale_payments as sp on sp.sale_id=sales.sale_id")
+ .where("sales.payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = '#{today}'")
+ .group("(CASE WHEN (sp.payment_method='mpu' or sp.payment_method='visa' or sp.payment_method='master' or sp.payment_method='jcb' or sp.payment_method='unionpay') THEN 'card' ELSE sp.payment_method END)","e.name")
+ .order("e.name")
else
shift = ShiftSale.current_open_shift(current_user.id)
if !shift.nil?
- total = Sale.where('sale_status = "completed" and sales.receipt_date between ? and ? and shift_sale_id=?',from,to,shift.id)
+ query = Sale.joins("JOIN employees as e on e.id=sales.cashier_id")
+ .joins("JOIN sale_payments as sp on sp.sale_id=sales.sale_id")
+ .where("sales.payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = '#{today}' and shift_sale_id='#{shift.id}'")
+ .group("(CASE WHEN (sp.payment_method='mpu' or sp.payment_method='visa' or sp.payment_method='master' or sp.payment_method='jcb' or sp.payment_method='unionpay') THEN 'card' ELSE sp.payment_method END)","e.name")
+ .order("e.name")
+ end
+ end
+ end
+ end
+ end
+
+ def self.total_sale(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
+ if !from.nil? && !to.nil?
+ if current_user.nil?
+ if !from_time.nil? && !to_time.nil?
+ total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ?',from,to,from_time,to_time).sum("grand_total")
+ else
+ total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to).sum("grand_total")
+ end
+ else
+ if current_user.role == 'administrator' || current_user.role == 'manager'
+ if !from_time.nil? && !to_time.nil?
+ total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ?',from,to,from_time,to_time).sum("grand_total")
+ else
+ total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to).sum("grand_total")
+ end
+ else
+ shift = ShiftSale.current_open_shift(current_user.id)
+ if !shift.nil?
+ if !from_time.nil? && !to_time.nil?
+ total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ? and shift_sale_id=?',from,to,from_time,to_time,shift.id)
.sum("grand_total")
+ else
+ total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and shift_sale_id=?',from,to,shift.id)
+ .sum("grand_total")
+ end
end
end
end
@@ -1208,17 +1505,29 @@ end
end
end
- def self.total_count(today,current_user=nil,from=nil,to=nil)
+ def self.total_count(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
if !from.nil? && !to.nil?
if current_user.nil?
- total = Sale.where('sale_status = "completed" and receipt_date between ? and ?',from,to).count
+ if !from_time.nil? && !to_time.nil?
+ total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(receipt_date, "+00:00", "+06:30"),"%H:%M") between ? and ?',from,to,from_time,to_time).count
+ else
+ total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ?',from,to).count
+ end
else
if current_user.role == 'administrator' || current_user.role == 'manager'
- total = Sale.where('sale_status = "completed" and receipt_date between ? and ?',from,to).count
+ if !from_time.nil? && !to_time.nil?
+ total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(receipt_date, "+00:00", "+06:30"),"%H:%M") between ? and ?',from,to,from_time,to_time).count
+ else
+ total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ?',from,to).count
+ end
else
shift = ShiftSale.current_open_shift(current_user.id)
if !shift.nil?
- total = Sale.where('sale_status = "completed" and receipt_date between ? and ? and shift_sale_id = ?',from,to,shift.id).count
+ if !from_time.nil? && !to_time.nil?
+ total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(receipt_date, "+00:00", "+06:30"),"%H:%M") between ? and ? and shift_sale_id = ?',from,to,from_time,to_time,shift.id).count
+ else
+ total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and shift_sale_id = ?',from,to,shift.id).count
+ end
end
end
end
@@ -1238,23 +1547,41 @@ end
end
end
- def self.total_card_sale(today,current_user=nil,from=nil,to=nil)
+ def self.total_card_sale(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
if !from.nil? && !to.nil?
if current_user.nil?
- query = Sale.where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay")',from,to)
- .joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id")
- .sum("sp.payment_amount")
- else
- if current_user.role == 'administrator' || current_user.role == 'manager'
- query = Sale.where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay")',from,to)
+ if !from_time.nil? && !to_time.nil?
+ query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay")',from,to,from_time,to_time)
.joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id")
.sum("sp.payment_amount")
else
- shift = ShiftSale.current_open_shift(current_user.id)
- if !shift.nil?
- query = Sale.where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay") and shift_sale_id=?',from,to,shift.id)
+ query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay")',from,to)
.joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id")
.sum("sp.payment_amount")
+ end
+ else
+ if current_user.role == 'administrator' || current_user.role == 'manager'
+ if !from_time.nil? && !to_time.nil?
+ query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay")',from,to,from_time,to_time)
+ .joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id")
+ .sum("sp.payment_amount")
+ else
+ query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay")',from,to)
+ .joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id")
+ .sum("sp.payment_amount")
+ end
+ else
+ shift = ShiftSale.current_open_shift(current_user.id)
+ if !shift.nil?
+ if !from_time.nil? && !to_time.nil?
+ query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay") and shift_sale_id=?',from,to,from_time,to_time,shift.id)
+ .joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id")
+ .sum("sp.payment_amount")
+ else
+ query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay") and shift_sale_id=?',from,to,shift.id)
+ .joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id")
+ .sum("sp.payment_amount")
+ end
end
end
end
@@ -1280,23 +1607,41 @@ end
end
end
- def self.credit_payment(today,current_user=nil,from=nil,to=nil)
+ def self.credit_payment(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
if !from.nil? && !to.nil?
if current_user.nil?
- query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and s.receipt_date between ? and ?',from,to)
- .joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id")
- .sum("payment_amount")
- else
- if current_user.role == 'administrator' || current_user.role == 'manager'
- query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and s.receipt_date between ? and ?',from,to)
+ if !from_time.nil? && !to_time.nil?
+ query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ?',from,to,from_time,to_time)
.joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id")
.sum("payment_amount")
else
- shift = ShiftSale.current_open_shift(current_user.id)
- if !shift.nil?
- query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and s.receipt_date between ? and ? and s.shift_sale_id=?',from,to,shift.id)
+ query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to)
.joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id")
.sum("payment_amount")
+ end
+ else
+ if current_user.role == 'administrator' || current_user.role == 'manager'
+ if !from_time.nil? && !to_time.nil?
+ query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ?',from,to,from_time,to_time)
+ .joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id")
+ .sum("payment_amount")
+ else
+ query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to)
+ .joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id")
+ .sum("payment_amount")
+ end
+ else
+ shift = ShiftSale.current_open_shift(current_user.id)
+ if !shift.nil?
+ if !from_time.nil? && !to_time.nil?
+ query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ? and s.shift_sale_id=?',from,to,from_time,to_time,shift.id)
+ .joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id")
+ .sum("payment_amount")
+ else
+ query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and s.shift_sale_id=?',from,to,shift.id)
+ .joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id")
+ .sum("payment_amount")
+ end
end
end
end
@@ -1322,23 +1667,41 @@ end
end
end
- def self.summary_sale_receipt(today,current_user=nil,from=nil,to=nil)
+ def self.summary_sale_receipt(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
if !from.nil? && !to.nil?
if current_user.nil?
- query = Sale.select('count(sale_id) as total_receipt, (case when sum(total_amount) > 0 then sum(total_amount) else 0.0 end) as total_amount, (case when sum(grand_total) > 0 then sum(grand_total) else 0.0 end) as grand_total, (case when sum(total_discount) > 0 then sum(total_discount) else 0.0 end) as total_discount, (case when sum(total_tax) > 0 then sum(total_tax) else 0.0 end) as total_tax')
- .where('sale_status = "completed" and receipt_date between ? and ?',from,to)
+ if !from_time.nil? && !to_time.nil?
+ query = Sale.select('count(sale_id) as total_receipt, (case when sum(total_amount) > 0 then sum(total_amount) else 0.0 end) as total_amount, (case when sum(grand_total) > 0 then sum(grand_total) else 0.0 end) as grand_total, (case when sum(total_discount) > 0 then sum(total_discount) else 0.0 end) as total_discount, (case when sum(total_tax) > 0 then sum(total_tax) else 0.0 end) as total_tax')
+ .where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ?',from,to,from_time,to_time)
.first()
+ else
+ query = Sale.select('count(sale_id) as total_receipt, (case when sum(total_amount) > 0 then sum(total_amount) else 0.0 end) as total_amount, (case when sum(grand_total) > 0 then sum(grand_total) else 0.0 end) as grand_total, (case when sum(total_discount) > 0 then sum(total_discount) else 0.0 end) as total_discount, (case when sum(total_tax) > 0 then sum(total_tax) else 0.0 end) as total_tax')
+ .where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to)
+ .first()
+ end
else
if current_user.role == 'administrator' || current_user.role == 'manager'
- query = Sale.select('count(sale_id) as total_receipt, (case when sum(total_amount) > 0 then sum(total_amount) else 0.0 end) as total_amount, (case when sum(grand_total) > 0 then sum(grand_total) else 0.0 end) as grand_total, (case when sum(total_discount) > 0 then sum(total_discount) else 0.0 end) as total_discount, (case when sum(total_tax) > 0 then sum(total_tax) else 0.0 end) as total_tax')
- .where('sale_status = "completed" and receipt_date between ? and ?',from,to)
- .first()
+ if !from_time.nil? && !to_time.nil?
+ query = Sale.select('count(sale_id) as total_receipt, (case when sum(total_amount) > 0 then sum(total_amount) else 0.0 end) as total_amount, (case when sum(grand_total) > 0 then sum(grand_total) else 0.0 end) as grand_total, (case when sum(total_discount) > 0 then sum(total_discount) else 0.0 end) as total_discount, (case when sum(total_tax) > 0 then sum(total_tax) else 0.0 end) as total_tax')
+ .where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ?',from,to,from_time,to_time)
+ .first()
+ else
+ query = Sale.select('count(sale_id) as total_receipt, (case when sum(total_amount) > 0 then sum(total_amount) else 0.0 end) as total_amount, (case when sum(grand_total) > 0 then sum(grand_total) else 0.0 end) as grand_total, (case when sum(total_discount) > 0 then sum(total_discount) else 0.0 end) as total_discount, (case when sum(total_tax) > 0 then sum(total_tax) else 0.0 end) as total_tax')
+ .where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to)
+ .first()
+ end
else
shift = ShiftSale.current_open_shift(current_user.id)
if !shift.nil?
- query = Sale.select('count(sale_id) as total_receipt, (case when sum(total_amount) > 0 then sum(total_amount) else 0.0 end) as total_amount, (case when sum(grand_total) > 0 then sum(grand_total) else 0.0 end) as grand_total, (case when sum(total_discount) > 0 then sum(total_discount) else 0.0 end) as total_discount, (case when sum(total_tax) > 0 then sum(total_tax) else 0.0 end) as total_tax')
- .where('sale_status = "completed" and receipt_date between ? and ? and shift_sale_id=?',from,to,shift.id)
- .first()
+ if !from_time.nil? && !to_time.nil?
+ query = Sale.select('count(sale_id) as total_receipt, (case when sum(total_amount) > 0 then sum(total_amount) else 0.0 end) as total_amount, (case when sum(grand_total) > 0 then sum(grand_total) else 0.0 end) as grand_total, (case when sum(total_discount) > 0 then sum(total_discount) else 0.0 end) as total_discount, (case when sum(total_tax) > 0 then sum(total_tax) else 0.0 end) as total_tax')
+ .where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ? and shift_sale_id=?',from,to,from_time,to_time,shift.id)
+ .first()
+ else
+ query = Sale.select('count(sale_id) as total_receipt, (case when sum(total_amount) > 0 then sum(total_amount) else 0.0 end) as total_amount, (case when sum(grand_total) > 0 then sum(grand_total) else 0.0 end) as grand_total, (case when sum(total_discount) > 0 then sum(total_discount) else 0.0 end) as total_discount, (case when sum(total_tax) > 0 then sum(total_tax) else 0.0 end) as total_tax')
+ .where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and shift_sale_id=?',from,to,shift.id)
+ .first()
+ end
end
end
end
@@ -1364,23 +1727,41 @@ end
end
end
- def self.total_payment_methods(today,current_user=nil,from=nil,to=nil)
+ def self.total_payment_methods(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
if !from.nil? && !to.nil?
if current_user.nil?
- query = Sale.select("distinct sp.payment_method")
- .where('sales.sale_status = "completed" and sales.receipt_date between ? and ?',from,to)
+ if !from_time.nil? && !to_time.nil?
+ query = Sale.select("distinct sp.payment_method")
+ .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%H:%M") between ? and ?',from,to,from_time,to_time)
.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
+ else
+ query = Sale.select("distinct sp.payment_method")
+ .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ?',from,to)
+ .joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
+ end
else
if current_user.role == 'administrator' || current_user.role == 'manager'
- query = Sale.select("distinct sp.payment_method")
- .where('sales.sale_status = "completed" and sales.receipt_date between ? and ?',from,to)
+ if !from_time.nil? && !to_time.nil?
+ query = Sale.select("distinct sp.payment_method")
+ .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%H:%M") between ? and ?',from,to,from_time,to_time)
.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
+ else
+ query = Sale.select("distinct sp.payment_method")
+ .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ?',from,to)
+ .joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
+ end
else
shift = ShiftSale.current_open_shift(current_user.id)
if !shift.nil?
- query = Sale.select("distinct sp.payment_method")
- .where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and sales.shift_sale_id=?',from,to,shift.id)
- .joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
+ if !from_time.nil? && !to_time.nil?
+ query = Sale.select("distinct sp.payment_method")
+ .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%H:%M") between ? and ? and sales.shift_sale_id=?',from,to,from_time,to_time,shift.id)
+ .joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
+ else
+ query = Sale.select("distinct sp.payment_method")
+ .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and sales.shift_sale_id=?',from,to,shift.id)
+ .joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
+ end
end
end
end
@@ -1406,35 +1787,69 @@ end
end
end
- def self.payment_sale(payment_method, today, current_user=nil,from=nil,to=nil)
+ def self.payment_sale(payment_method, today, current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
+ time_query = ''
+ if !from_time.nil? && !to_time.nil?
+ time_query = " and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%H:%M') between '#{from_time}' and '#{to_time}'"
+ end
if !from.nil? && !to.nil?
if current_user.nil?
- query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
- if payment_method == 'card'
- query = query.where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay")',from,to)
- else
- query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and sales.receipt_date between ? and ?",from,to)
- end
- query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) - SUM(sales.amount_changed)) ELSE SUM(sp.payment_amount) END) as payment_amount").first()
- else
- if current_user.role == 'administrator' || current_user.role == 'manager'
+ if !from_time.nil? && !to_time.nil?
query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
if payment_method == 'card'
- query = query.where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay")',from,to)
+ query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%H:%M") between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay")',from,to,from_time,to_time)
else
- query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and sales.receipt_date between ? and ?",from,to)
+ query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between ? and ? and and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%H:%M') between ? and ?",from,to,from_time,to_time)
end
query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) - SUM(sales.amount_changed)) ELSE SUM(sp.payment_amount) END) as payment_amount").first()
else
- shift = ShiftSale.current_open_shift(current_user.id)
- if !shift.nil?
+ query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
+ if payment_method == 'card'
+ query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay")',from,to)
+ else
+ query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between ? and ?",from,to)
+ end
+ query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) - SUM(sales.amount_changed)) ELSE SUM(sp.payment_amount) END) as payment_amount").first()
+ end
+ else
+ if current_user.role == 'administrator' || current_user.role == 'manager'
+ if !from_time.nil? && !to_time.nil?
query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
if payment_method == 'card'
- query = query.where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay") and sales.shift_sale_id=?',from,to,shift.id)
+ query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%H:%M") between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay")',from,to,from_time,to_time)
else
- query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and sales.receipt_date between ? and ? and sales.shift_sale_id=?",from,to,shift.id)
+ query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%H:%M') between ? and ?",from,to,from_time,to_time)
end
query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) - SUM(sales.amount_changed)) ELSE SUM(sp.payment_amount) END) as payment_amount").first()
+ else
+ query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
+ if payment_method == 'card'
+ query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay")',from,to)
+ else
+ query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between ? and ?",from,to)
+ end
+ query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) - SUM(sales.amount_changed)) ELSE SUM(sp.payment_amount) END) as payment_amount").first()
+ end
+ else
+ shift = ShiftSale.current_open_shift(current_user.id)
+ if !shift.nil?
+ if !from_time.nil? && !to_time.nil?
+ query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
+ if payment_method == 'card'
+ query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%H:%M") between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay") and sales.shift_sale_id=?',from,to,from_time,to_time,shift.id)
+ else
+ query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%H:%M') between ? and ? and sales.shift_sale_id=?",from,to,from_time,to_time,shift.id)
+ end
+ query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) - SUM(sales.amount_changed)) ELSE SUM(sp.payment_amount) END) as payment_amount").first()
+ else
+ query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
+ if payment_method == 'card'
+ query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay") and sales.shift_sale_id=?',from,to,shift.id)
+ else
+ query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between ? and ? and sales.shift_sale_id=?",from,to,shift.id)
+ end
+ query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) - SUM(sales.amount_changed)) ELSE SUM(sp.payment_amount) END) as payment_amount").first()
+ end
end
end
end
@@ -1472,10 +1887,10 @@ end
end
end
- def self.total_customer(today,current_user=nil,from=nil,to=nil)
- dinein_cnt = self.total_dinein(today,current_user,from,to)
- takeaway_cnt = self.total_takeaway(today,current_user,from,to)
- membership_cnt = self.total_membership(today,current_user,from,to)
+ def self.total_customer(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
+ dinein_cnt = self.total_dinein(today,current_user,from,to,from_time,to_time)
+ takeaway_cnt = self.total_takeaway(today,current_user,from,to,from_time,to_time)
+ membership_cnt = self.total_membership(today,current_user,from,to,from_time,to_time)
total_cus = 0
if !dinein_cnt.nil? || !takeaway_cnt.nil? || !membership_cnt.nil?
@@ -1485,26 +1900,47 @@ end
return total_cus
end
- def self.total_dinein(today,current_user=nil,from=nil,to=nil)
+ def self.total_dinein(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
if !from.nil? && !to.nil?
if current_user.nil?
- query = Sale.select("count(sales.customer_id) as total_dinein_cus")
+ if !from_time.nil? && !to_time.nil?
+ query = Sale.select("count(sales.customer_id) as total_dinein_cus")
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
- .where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and c.customer_type = "Dinein" and c.membership_id is null',from,to)
+ .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ? and c.customer_type = "Dinein" and c.membership_id is null',from,to,from_time,to_time)
.first()
+ else
+ query = Sale.select("count(sales.customer_id) as total_dinein_cus")
+ .joins("JOIN customers as c ON c.customer_id = sales.customer_id")
+ .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and c.customer_type = "Dinein" and c.membership_id is null',from,to)
+ .first()
+ end
else
if current_user.role == 'administrator' || current_user.role == 'manager'
- query = Sale.select("count(sales.customer_id) as total_dinein_cus")
+ if !from_time.nil? && !to_time.nil?
+ query = Sale.select("count(sales.customer_id) as total_dinein_cus")
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
- .where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and c.customer_type = "Dinein" and c.membership_id is null',from,to)
+ .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ? and c.customer_type = "Dinein" and c.membership_id is null',from,to,from_time,to_time)
.first()
+ else
+ query = Sale.select("count(sales.customer_id) as total_dinein_cus")
+ .joins("JOIN customers as c ON c.customer_id = sales.customer_id")
+ .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and c.customer_type = "Dinein" and c.membership_id is null',from,to)
+ .first()
+ end
else
shift = ShiftSale.current_open_shift(current_user.id)
if !shift.nil?
- query = Sale.select("count(sales.customer_id) as total_dinein_cus")
+ if !from_time.nil? && !to_time.nil?
+ query = Sale.select("count(sales.customer_id) as total_dinein_cus")
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
- .where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and c.customer_type = "Dinein" and c.membership_id is null and sales.shift_sale_id=?',from,to,shift.id)
+ .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ? and c.customer_type = "Dinein" and c.membership_id is null and sales.shift_sale_id=?',from,to,from_time,to_time,shift.id)
.first()
+ else
+ query = Sale.select("count(sales.customer_id) as total_dinein_cus")
+ .joins("JOIN customers as c ON c.customer_id = sales.customer_id")
+ .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and c.customer_type = "Dinein" and c.membership_id is null and sales.shift_sale_id=?',from,to,shift.id)
+ .first()
+ end
end
end
end
@@ -1533,26 +1969,47 @@ end
end
end
- def self.total_takeaway(today,current_user=nil,from=nil,to=nil)
+ def self.total_takeaway(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
if !from.nil? && !to.nil?
if current_user.nil?
- query = Sale.select("count(sales.customer_id) as total_take_cus")
- .joins("JOIN customers as c ON c.customer_id = sales.customer_id")
- .where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and c.customer_type = "Takeaway" and c.membership_id is null',from,to)
- .first()
- else
- if current_user.role == 'administrator' || current_user.role == 'manager'
+ if !from_time.nil? && !to_time.nil?
query = Sale.select("count(sales.customer_id) as total_take_cus")
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
- .where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and c.customer_type = "Takeaway" and c.membership_id is null',from,to)
+ .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZsales.receipt_date,"%H:%M") between ? and ? and c.customer_type = "Takeaway" and c.membership_id is null',from,to,from_time,to_time)
.first()
+ else
+ query = Sale.select("count(sales.customer_id) as total_take_cus")
+ .joins("JOIN customers as c ON c.customer_id = sales.customer_id")
+ .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and c.customer_type = "Takeaway" and c.membership_id is null',from,to)
+ .first()
+ end
+ else
+ if current_user.role == 'administrator' || current_user.role == 'manager'
+ if !from_time.nil? && !to_time.nil?
+ query = Sale.select("count(sales.customer_id) as total_take_cus")
+ .joins("JOIN customers as c ON c.customer_id = sales.customer_id")
+ .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ? and c.customer_type = "Takeaway" and c.membership_id is null',from,to,from_time,to_time)
+ .first()
+ else
+ query = Sale.select("count(sales.customer_id) as total_take_cus")
+ .joins("JOIN customers as c ON c.customer_id = sales.customer_id")
+ .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and c.customer_type = "Takeaway" and c.membership_id is null',from,to)
+ .first()
+ end
else
shift = ShiftSale.current_open_shift(current_user.id)
if !shift.nil?
- query = Sale.select("count(sales.customer_id) as total_take_cus")
- .joins("JOIN customers as c ON c.customer_id = sales.customer_id")
- .where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and c.customer_type = "Takeaway" and c.membership_id is null and sales.shift_sale_id=?',from,to,shift.id)
- .first()
+ if !from_time.nil? && !to_time.nil?
+ query = Sale.select("count(sales.customer_id) as total_take_cus")
+ .joins("JOIN customers as c ON c.customer_id = sales.customer_id")
+ .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ? and c.customer_type = "Takeaway" and c.membership_id is null and sales.shift_sale_id=?',from,to,from_time,to_time,shift.id)
+ .first()
+ else
+ query = Sale.select("count(sales.customer_id) as total_take_cus")
+ .joins("JOIN customers as c ON c.customer_id = sales.customer_id")
+ .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and c.customer_type = "Takeaway" and c.membership_id is null and sales.shift_sale_id=?',from,to,shift.id)
+ .first()
+ end
end
end
end
@@ -1581,26 +2038,43 @@ end
end
end
- def self.total_membership(today,current_user=nil,from=nil,to=nil)
+ def self.total_membership(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
if !from.nil? && !to.nil?
if current_user.nil?
- query = Sale.select("count(distinct sales.customer_id) as total_memb_cus")
- .joins("JOIN customers as c ON c.customer_id = sales.customer_id")
- .where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and ((c.customer_type = "Dinein" and c.membership_id is not null) or (c.customer_type = "Takeaway" and c.membership_id is not null))',from,to)
- .first()
- else
- if current_user.role == 'administrator' || current_user.role == 'manager'
+ if !from_time.nil? && !to_time.nil?
query = Sale.select("count(distinct sales.customer_id) as total_memb_cus")
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
- .where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and ((c.customer_type = "Dinein" and c.membership_id is not null) or (c.customer_type = "Takeaway" and c.membership_id is not null))',from,to)
+ .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ? and ((c.customer_type = "Dinein" and c.membership_id is not null) or (c.customer_type = "Takeaway" and c.membership_id is not null))',from,to,from_time,to_time)
.first()
+ else
+ query = Sale.select("count(distinct sales.customer_id) as total_memb_cus")
+ .joins("JOIN customers as c ON c.customer_id = sales.customer_id")
+ .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and ((c.customer_type = "Dinein" and c.membership_id is not null) or (c.customer_type = "Takeaway" and c.membership_id is not null))',from,to)
+ .first()
+ end
+ else
+ if current_user.role == 'administrator' || current_user.role == 'manager'
+ if !from_time.nil? && !to_time.nil?
+ query = Sale.select("count(distinct sales.customer_id) as total_memb_cus")
+ .joins("JOIN customers as c ON c.customer_id = sales.customer_id")
+ .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ? and ((c.customer_type = "Dinein" and c.membership_id is not null) or (c.customer_type = "Takeaway" and c.membership_id is not null))',from,to,from_time,to_time)
+ .first()
+ else
+ query = Sale.select("count(distinct sales.customer_id) as total_memb_cus")
+ .joins("JOIN customers as c ON c.customer_id = sales.customer_id")
+ .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and ((c.customer_type = "Dinein" and c.membership_id is not null) or (c.customer_type = "Takeaway" and c.membership_id is not null))',from,to)
+ .first()
+ end
else
shift = ShiftSale.current_open_shift(current_user.id)
if !shift.nil?
query = Sale.select("count(distinct sales.customer_id) as total_memb_cus")
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
- .where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and ((c.customer_type = "Dinein" and c.membership_id is not null) or (c.customer_type = "Takeaway" and c.membership_id is not null)) and sales.shift_sale_id=?',from,to,shift.id)
- .first()
+ if !from_time.nil? && !to_time.nil?
+ query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ? and ((c.customer_type = "Dinein" and c.membership_id is not null) or (c.customer_type = "Takeaway" and c.membership_id is not null)) and sales.shift_sale_id=?',from,to,from_time,to_time,shift.id).first()
+ else
+ query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and ((c.customer_type = "Dinein" and c.membership_id is not null) or (c.customer_type = "Takeaway" and c.membership_id is not null)) and sales.shift_sale_id=?',from,to,shift.id).first()
+ end
end
end
end
@@ -1629,26 +2103,41 @@ end
end
end
- def self.total_other_customer(today,current_user=nil,from=nil,to=nil)
+ def self.total_other_customer(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
if !from.nil? && !to.nil?
if current_user.nil?
query = Sale.select("count(sales.customer_id) as total_cus")
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
- .where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and c.customer_type is null and c.membership_id is null',from,to)
- .first()
+ if !from_time.nil? && !to_time.nil?
+ query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ? and c.customer_type is null and c.membership_id is null',from,to,from_time,to_time)
+ .first()
+ else
+ query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and c.customer_type is null and c.membership_id is null',from,to)
+ .first()
+ end
else
if current_user.role == 'administrator' || current_user.role == 'manager'
query = Sale.select("count(sales.customer_id) as total_cus")
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
- .where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and c.customer_type is null and c.membership_id is null',from,to)
- .first()
+ if !from_time.nil? && !to_time.nil?
+ query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ? and c.customer_type is null and c.membership_id is null',from,to,from_time,to_time)
+ .first()
+ else
+ query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and c.customer_type is null and c.membership_id is null',from,to)
+ .first()
+ end
else
shift = ShiftSale.current_open_shift(current_user.id)
if !shift.nil?
query = Sale.select("count(sales.customer_id) as total_cus")
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
- .where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and c.customer_type is null and c.membership_id is null and sales.shift_sale_id=?',from,to,shift.id)
- .first()
+ if !from_time.nil? && !to_time.nil?
+ query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ? and c.customer_type is null and c.membership_id is null and sales.shift_sale_id=?',from,to,from_time,to_time,shift.id)
+ .first()
+ else
+ query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and c.customer_type is null and c.membership_id is null and sales.shift_sale_id=?',from,to,shift.id)
+ .first()
+ end
end
end
end
@@ -1677,29 +2166,44 @@ end
end
end
- def self.total_order(today,current_user=nil,from=nil,to=nil)
+ def self.total_order(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
if !from.nil? && !to.nil?
if current_user.nil?
query = Sale.select("count(distinct a.order_id) as total_order")
.joins("JOIN sale_orders as a ON a.sale_id = sales.sale_id")
.joins("JOIN orders as b ON b.order_id = a.order_id")
- .where('b.status = "billed" and sales.receipt_date between ? and ?',from,to)
- .first()
+ if !from_time.nil? && !to_time.nil?
+ query = query.where('b.status = "billed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ?',from,to,from_time,to_time)
+ .first()
+ else
+ query = query.where('b.status = "billed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to)
+ .first()
+ end
else
if current_user.role == 'administrator' || current_user.role == 'manager'
query = Sale.select("count(distinct a.order_id) as total_order")
.joins("JOIN sale_orders as a ON a.sale_id = sales.sale_id")
.joins("JOIN orders as b ON b.order_id = a.order_id")
- .where('b.status = "billed" and sales.receipt_date between ? and ?',from,to)
- .first()
+ if !from_time.nil? && !to_time.nil?
+ query = query.where('b.status = "billed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ?',from,to,from_time,to_time)
+ .first()
+ else
+ query = query.where('b.status = "billed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to)
+ .first()
+ end
else
shift = ShiftSale.current_open_shift(current_user.id)
if !shift.nil?
query = Sale.select("count(distinct a.order_id) as total_order")
.joins("JOIN sale_orders as a ON a.sale_id = sales.sale_id")
.joins("JOIN orders as b ON b.order_id = a.order_id")
- .where('b.status = "billed" and sales.receipt_date between ? and ? and sales.shift_sale_id=?',from,to,shift.id)
- .first()
+ if !from_time.nil? && !to_time.nil?
+ query = query.where('b.status = "billed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ? and sales.shift_sale_id=?',from,to,from_time,to_time,shift.id)
+ .first()
+ else
+ query = query.where('b.status = "billed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and sales.shift_sale_id=?',from,to,shift.id)
+ .first()
+ end
end
end
end
@@ -1731,26 +2235,38 @@ end
end
end
- def self.total_account(today,current_user=nil,from=nil,to=nil)
+ def self.total_account(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
if !from.nil? && !to.nil?
if current_user.nil?
query = Sale.select("distinct b.id as account_id, b.title as title")
.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
.joins("JOIN accounts as b ON b.id = a.account_id")
- .where('sales.sale_status = "completed" and sales.receipt_date between ? and ?',from,to)
+ if !from_time.nil? && !to_time.nil?
+ query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to,from_time,to_time)
+ else
+ query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to)
+ end
else
if current_user.role == 'administrator' || current_user.role == 'manager'
query = Sale.select("distinct b.id as account_id, b.title as title")
.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
.joins("JOIN accounts as b ON b.id = a.account_id")
- .where('sales.sale_status = "completed" and sales.receipt_date between ? and ?',from,to)
+ if !from_time.nil? && !to_time.nil?
+ query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ?',from,to,from_time,to_time)
+ else
+ query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to)
+ end
else
shift = ShiftSale.current_open_shift(current_user.id)
if !shift.nil?
query = Sale.select("distinct b.id as account_id, b.title as title")
.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
.joins("JOIN accounts as b ON b.id = a.account_id")
- .where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and sales.shift_sale_id=?',from,to,shift.id)
+ if !from_time.nil? && !to_time.nil?
+ query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ? and sales.shift_sale_id=?',from,to,from_time,to_time,shift.id)
+ else
+ query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and sales.shift_sale_id=?',from,to,shift.id)
+ end
end
end
end
@@ -1779,26 +2295,41 @@ end
end
end
- def self.account_data(account_id, today, current_user=nil,from=nil,to=nil)
+ def self.account_data(account_id, today, current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
if !from.nil? && !to.nil?
if current_user.nil?
query = Sale.select("count(*) as cnt_acc, SUM(a.price) as total_acc")
.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
- .where("sales.sale_status = 'completed' and a.account_id ='#{account_id}' and sales.receipt_date between ? and ?",from,to)
- .first()
+ if !from_time.nil? && !to_time.nil?
+ query = query.where("sales.sale_status = 'completed' and a.account_id ='#{account_id}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%M') between ? and ?",from,to,from_time,to_time)
+ .first()
+ else
+ query = query.where("sales.sale_status = 'completed' and a.account_id ='#{account_id}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ?",from,to)
+ .first()
+ end
else
if current_user.role == 'administrator' || current_user.role == 'manager'
query = Sale.select("count(*) as cnt_acc, SUM(a.price) as total_acc")
.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
- .where("sales.sale_status = 'completed' and a.account_id ='#{account_id}' and sales.receipt_date between ? and ?",from,to)
- .first()
+ if !from_time.nil? && !to_time.nil?
+ query = query.where("sales.sale_status = 'completed' and a.account_id ='#{account_id}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%M') between ? and ?",from,to,from_time,to_time)
+ .first()
+ else
+ query = query.where("sales.sale_status = 'completed' and a.account_id ='#{account_id}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ?",from,to)
+ .first()
+ end
else
shift = ShiftSale.current_open_shift(current_user.id)
if !shift.nil?
query = Sale.select("count(*) as cnt_acc, SUM(a.price) as total_acc")
.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
- .where("sales.sale_status = 'completed' and a.account_id ='#{account_id}' and sales.receipt_date between ? and ? and sales.shift_sale_id=?",from,to,shift.id)
- .first()
+ if !from_time.nil? && !to_time.nil?
+ query = query.where("sales.sale_status = 'completed' and a.account_id ='#{account_id}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%M') between ? and ? and sales.shift_sale_id=?",from,to,from_time,to_time,shift.id)
+ .first()
+ else
+ query = query.where("sales.sale_status = 'completed' and a.account_id ='#{account_id}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ? and sales.shift_sale_id=?",from,to,shift.id)
+ .first()
+ end
end
end
end
@@ -1827,32 +2358,44 @@ end
end
end
- def self.top_items(today,current_user=nil,from=nil,to=nil)
+ def self.top_items(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
if !from.nil? && !to.nil?
if current_user.nil?
query = Sale.select("a.product_name as item_name, SUM(a.price) as item_total_price")
.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
- .where("(a.qty > 0 and a.price > 0) and payment_status='paid' and sales.sale_status = 'completed' and sales.receipt_date between ? and ?",from,to)
- .group("a.product_code")
- .order("SUM(a.qty) DESC")
- .first()
+ if !from_time.nil? && !to_time.nil?
+ query = query.where("(a.qty > 0 and a.price > 0) and payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%M') between ? and ?",from,to,from_time,to_time)
+ else
+ query = query.where("(a.qty > 0 and a.price > 0) and payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ?",from,to)
+ end
+ query = query.group("a.product_code")
+ .order("SUM(a.qty) DESC")
+ .first()
else
if current_user.role == 'administrator' || current_user.role == 'manager'
query = Sale.select("a.product_name as item_name, SUM(a.price) as item_total_price")
.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
- .where("(a.qty > 0 and a.price > 0) and payment_status='paid' and sales.sale_status = 'completed' and sales.receipt_date between ? and ?",from,to)
- .group("a.product_code")
- .order("SUM(a.qty) DESC")
- .first()
+ if !from_time.nil? && !to_time.nil?
+ query = query.where("(a.qty > 0 and a.price > 0) and payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%M') between ? and ?",from,to,from_time,to_time)
+ else
+ query = query.where("(a.qty > 0 and a.price > 0) and payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ?",from,to)
+ end
+ query = query.group("a.product_code")
+ .order("SUM(a.qty) DESC")
+ .first()
else
shift = ShiftSale.current_open_shift(current_user.id)
if !shift.nil?
query = Sale.select("a.product_name as item_name, SUM(a.price) as item_total_price")
.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
- .where("(a.qty > 0 and a.price > 0) and payment_status='paid' and sales.sale_status = 'completed' and sales.receipt_date between ? and ? and sales.shift_sale_id=?",from,to,shift.id)
- .group("a.product_code")
- .order("SUM(a.qty) DESC")
- .first()
+ if !from_time.nil? && !to_time.nil?
+ query = query.where("(a.qty > 0 and a.price > 0) and payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%M') between ? and ? and sales.shift_sale_id=?",from,to,from_time,to_time,shift.id)
+ else
+ query = query.where("(a.qty > 0 and a.price > 0) and payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ? and sales.shift_sale_id=?",from,to,shift.id)
+ end
+ query = query.group("a.product_code")
+ .order("SUM(a.qty) DESC")
+ .first()
end
end
end
@@ -1887,23 +2430,38 @@ end
end
end
- def self.total_foc_items(today,current_user=nil,from=nil,to=nil)
+ def self.total_foc_items(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
if !from.nil? && !to.nil?
if current_user.nil?
query = Sale.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
- .where("sales.sale_status = 'completed' and a.remark='foc' and a.product_name not like '%FOC%' and sales.receipt_date between ? and ?",from,to)
- .sum("a.qty")
+ if !from_time.nil? && !to_time.nil?
+ query = query.where("sales.sale_status = 'completed' and a.remark='foc' and a.product_name not like '%FOC%' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%M') between ? and ?",from,to,from_time,to_time)
+ .sum("a.qty")
+ else
+ query = query.where("sales.sale_status = 'completed' and a.remark='foc' and a.product_name not like '%FOC%' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ?",from,to)
+ .sum("a.qty")
+ end
else
if current_user.role == 'administrator' || current_user.role == 'manager'
query = Sale.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
- .where("sales.sale_status = 'completed' and a.remark='foc' and a.product_name not like '%FOC%' and sales.receipt_date between ? and ?",from,to)
- .sum("a.qty")
+ if !from_time.nil? && !to_time.nil?
+ query = query.where("sales.sale_status = 'completed' and a.remark='foc' and a.product_name not like '%FOC%' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%M') between ? and ?",from,to,from_time,to_time)
+ .sum("a.qty")
+ else
+ query = query.where("sales.sale_status = 'completed' and a.remark='foc' and a.product_name not like '%FOC%' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ?",from,to)
+ .sum("a.qty")
+ end
else
shift = ShiftSale.current_open_shift(current_user.id)
if !shift.nil?
query = Sale.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
- .where("sales.sale_status = 'completed' and a.remark='foc' and a.product_name not like '%FOC%' and sales.receipt_date between ? and ? and sales.shift_sale_id=?",from,to,shift.id)
- .sum("a.qty")
+ if !from_time.nil? && !to_time.nil?
+ query = query.where("sales.sale_status = 'completed' and a.remark='foc' and a.product_name not like '%FOC%' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%M') between ? and ? and sales.shift_sale_id=?",from,to,from_time,to_time,shift.id)
+ .sum("a.qty")
+ else
+ query = query.where("sales.sale_status = 'completed' and a.remark='foc' and a.product_name not like '%FOC%' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ? and sales.shift_sale_id=?",from,to,shift.id)
+ .sum("a.qty")
+ end
end
end
end
@@ -1963,7 +2521,7 @@ end
end
# Re-compute for add
- saleobj.compute
+ saleobj.compute(order.source)
saleobj.save
order.save
booking.save
@@ -1993,7 +2551,7 @@ end
end
# Re-compute for add
- saleobj.compute
+ saleobj.compute(order.source)
saleobj.save
order.save
booking.save
diff --git a/app/models/sale_item.rb b/app/models/sale_item.rb
index 64e0ec73..fc32098f 100755
--- a/app/models/sale_item.rb
+++ b/app/models/sale_item.rb
@@ -38,7 +38,8 @@ class SaleItem < ApplicationRecord
sale_item.product_alt_name = item.product_alt_name
sale_item.account_id = item.account_id
sale_item.status = type
- if type == "foc" || type == "promotion" || type == "void"
+ sale_item.remark = type
+ if type == "foc" || type == "promotion" || type == "void" || type == "waste" || type == "spoile"
sale_item.qty = qty * (-1)
else
sale_item.qty = qty
diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb
index 280101ad..d4b549bb 100755
--- a/app/models/sale_payment.rb
+++ b/app/models/sale_payment.rb
@@ -11,6 +11,7 @@ class SalePayment < ApplicationRecord
def process_payment(invoice, action_by, cash_amount, payment_method,remark=nil)
self.sale = invoice
self.received_amount = cash_amount
+ self.payment_reference = remark
amount_due = invoice.grand_total
#get all payment for this invoices
@@ -48,8 +49,15 @@ class SalePayment < ApplicationRecord
payment_status = paypar_payment
when "foc"
payment_status = foc_payment
+<<<<<<< HEAD
when "paymal"
payment_status = paymal_payment
+=======
+ when "JunctionPay"
+ payment_status = junction_pay_payment
+ when "alipay"
+ payment_status = external_terminal_card_payment(:alipay)
+>>>>>>> 996392a041cb5f92a3b2985cbd0379210132d829
else
puts "it was something else"
end
@@ -87,7 +95,7 @@ class SalePayment < ApplicationRecord
}.to_json,
:headers => {
'Content-Type' => 'application/json',
- 'Accept' => 'application/json; version=2'
+ 'Accept' => 'application/json; version=3'
}, :timeout => 10
)
rescue Net::OpenTimeout
@@ -135,7 +143,7 @@ class SalePayment < ApplicationRecord
auth_token:auth_token}.to_json,
:headers => {
'Content-Type' => 'application/json',
- 'Accept' => 'application/json; version=2'
+ 'Accept' => 'application/json; version=3'
},
:timeout => 10
)
@@ -261,8 +269,7 @@ class SalePayment < ApplicationRecord
self.outstanding_amount = self.sale.grand_total.to_f - self.received_amount.to_f
self.payment_status = "paid"
payment_method = self.save!
- sale_update_payment_status(self.received_amount)
-
+ sale_update_payment_status(self.received_amount)
return payment_status
end
@@ -284,7 +291,7 @@ class SalePayment < ApplicationRecord
payment_status = false
self.payment_method = method
self.payment_amount = self.received_amount
- self.payment_reference = self.card_payment_reference
+ # self.payment_reference = self.card_payment_reference
self.outstanding_amount = self.sale.grand_total.to_f - self.received_amount.to_f
self.payment_status = "paid"
payment_method = self.save!
@@ -353,6 +360,7 @@ class SalePayment < ApplicationRecord
end
+<<<<<<< HEAD
def paymal_payment
payment_status = false
@@ -378,6 +386,20 @@ class SalePayment < ApplicationRecord
else
sale_update_payment_status(0)
end
+=======
+ def junction_pay_payment
+ payment_status = false
+
+ #Next time - validate if the vochure number is valid - within
+ self.payment_method = "JunctionPay"
+ self.payment_amount = self.received_amount
+ # self.payment_reference = self.payment_reference
+ self.outstanding_amount = self.sale.grand_total- self.received_amount
+ self.payment_status = "paid"
+ payment_method = self.save!
+ sale_update_payment_status(self.received_amount)
+
+>>>>>>> 996392a041cb5f92a3b2985cbd0379210132d829
return payment_status
end
@@ -391,6 +413,7 @@ class SalePayment < ApplicationRecord
sObj = Sale.find(self.sale_id)
is_credit = 0
is_foc = 0
+ method_status = false
sObj.sale_payments.each do |spay|
all_received_amount += spay.payment_amount.to_f
if spay.payment_method == "creditnote"
@@ -399,8 +422,12 @@ class SalePayment < ApplicationRecord
if spay.payment_method == "foc"
is_foc = 1
end
+ if spay.payment_method == "cash" || spay.payment_method == "foc" || spay.payment_method == "creditnote"
+ method_status = true
+ end
end
- if (self.sale.grand_total <= all_received_amount)
+
+ if (self.sale.grand_total <= all_received_amount) && method_status
if is_credit == 0
self.sale.payment_status = "paid"
else
@@ -440,11 +467,15 @@ class SalePayment < ApplicationRecord
end
self.sale.save!
- table_update_status(sObj)
if check_foc
+ table_update_status(sObj)
update_shift
elsif paid_amount.to_f > 0 #|| paid_amount != "0.0"
+ table_update_status(sObj)
+ update_shift
+ elsif method_status && paid_amount.to_f == 0
+ table_update_status(sObj)
update_shift
end
end
@@ -476,7 +507,7 @@ class SalePayment < ApplicationRecord
bookings.each do |tablebooking|
if tablebooking.booking_status != 'moved'
if tablebooking.sale_id
- if tablebooking.sale.sale_status != 'completed' && tablebooking.sale.sale_status != 'void'
+ if tablebooking.sale.sale_status != 'completed' && tablebooking.sale.sale_status != 'void' && tablebooking.sale.sale_status != 'spoile' && tablebooking.sale.sale_status != 'waste'
status = false
sale_count += 1
else
@@ -540,7 +571,7 @@ class SalePayment < ApplicationRecord
}.to_json,
:headers => {
'Content-Type' => 'application/json',
- 'Accept' => 'application/json; version=2'
+ 'Accept' => 'application/json; version=3'
}, :timeout => 10)
rescue Net::OpenTimeout
response = { "status": false , "message": " Connection timeout" }
@@ -585,7 +616,8 @@ class SalePayment < ApplicationRecord
end
rebate_arr.push(data)
end
-
+ Rails.logger.debug "Rebage Response"
+ Rails.logger.debug rebate_arr.to_json
total_amount = rebate_prices - payparcost - overall_dis
if credit == 1
@@ -616,7 +648,7 @@ class SalePayment < ApplicationRecord
}.to_json,
:headers => {
'Content-Type' => 'application/json',
- 'Accept' => 'application/json; version=2'
+ 'Accept' => 'application/json; version=3'
}, :timeout => 10)
rescue Net::OpenTimeout
response = { "status": false , "message": "Connect To" }
diff --git a/app/models/shop.rb b/app/models/shop.rb
index c722adc2..b0e84912 100755
--- a/app/models/shop.rb
+++ b/app/models/shop.rb
@@ -1,3 +1,9 @@
class Shop < ApplicationRecord
ShopDetail = Shop.find_by_id(1)
+
+ # Shop Image Uploader
+ mount_uploader :logo, ShopImageUploader
+
+ has_many :display_images
+ accepts_nested_attributes_for :display_images
end
diff --git a/app/models/stock_journal.rb b/app/models/stock_journal.rb
index c2a12f4a..fa4bd285 100755
--- a/app/models/stock_journal.rb
+++ b/app/models/stock_journal.rb
@@ -8,7 +8,7 @@ class StockJournal < ApplicationRecord
balance = calculate_balance(balance, item.qty)
journal = StockJournal.new
- journal.item_code = item.product_code
+ journal.item_code = item.item_instance_code
journal.inventory_definition_id = inventory_definition.id
journal.debit = item.qty
journal.balance = balance
@@ -36,12 +36,16 @@ class StockJournal < ApplicationRecord
journal.save
end
- def self.inventory_balances(today,from,to)
+ def self.inventory_balances(today,from,to,from_time,to_time)
if !from.nil? && !to.nil?
query = StockJournal.select("mii.item_instance_name as item_instance_name,balance")
.joins("join menu_item_instances mii on mii.item_instance_code=stock_journals.item_code")
- .where("stock_journals.created_at between '#{from}' and '#{to}'")
- .group("mii.item_instance_name")
+ if !from_time.nil? && !to_time.nil?
+ query = query.where("DATE_FORMAT(CONVERT_TZ(stock_journals.created_at,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'")
+ else
+ query = query.where("DATE_FORMAT(CONVERT_TZ(stock_journals.created_at,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}' and DATE_FORMAT(CONVERT_TZ(stock_journals.created_at,'+00:00','+06:30'),'%H:%M') between '#{from_time}' and '#{to_time}'")
+ end
+ query = query.group("mii.item_instance_name")
.order("mii.item_instance_name ASC")
else
query = StockJournal.select("mii.item_instance_name as item_instance_name,balance")
diff --git a/app/models/survey.rb b/app/models/survey.rb
index 27b6229e..840b4c1e 100644
--- a/app/models/survey.rb
+++ b/app/models/survey.rb
@@ -1,2 +1,17 @@
class Survey < ApplicationRecord
+
+ def self.search(filter,from,to)
+ if filter.blank?
+ keyword = ''
+ else
+ keyword = "dining_name LIKE ?","%#{filter}%"
+ end
+
+ if from.present? && to.present?
+ survey = Survey.where("DATE_FORMAT(created_at,'%d-%m-%Y') >= ?" + " AND DATE_FORMAT(created_at,'%d-%m-%Y') <= ?", from,to)
+ query = survey.where(keyword)
+ else
+ where("dining_name LIKE ?", "%#{filter}%")
+ end
+ end
end
diff --git a/app/models/tax_profile.rb b/app/models/tax_profile.rb
index e478ecd5..a9e56fac 100755
--- a/app/models/tax_profile.rb
+++ b/app/models/tax_profile.rb
@@ -1,5 +1,5 @@
class TaxProfile < ApplicationRecord
default_scope { order('order_by asc') }
# validations
- validates_presence_of :name, :rate
+ validates_presence_of :name, :rate, :group_type
end
diff --git a/app/pdf/order_item_pdf.rb b/app/pdf/order_item_pdf.rb
index 379e919c..58682d8a 100755
--- a/app/pdf/order_item_pdf.rb
+++ b/app/pdf/order_item_pdf.rb
@@ -37,7 +37,7 @@ class OrderItemPdf < Prawn::Document
# font "public/fonts/Zawgyi-One.ttf"
# font "public/fonts/padauk.ttf"
#font "public/fonts/Chinese.ttf"
- if order_item.dining.to_i > 0
+ if !order_item.dining.nil?
text "#{ order_item.type + '-' + order_item.dining + print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20
else
text "#{ print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20
@@ -110,7 +110,7 @@ class OrderItemPdf < Prawn::Document
end
if alt_name
- if !(order_item.alt_name).empty?
+ if order_item.alt_name
move_down 4
font("public/fonts/NotoSansCJKtc-Regular.ttf") do
text "(#{order_item.alt_name})", :size => self.item_font_size,:align => :left, :inline_format => true
diff --git a/app/pdf/order_item_slim_pdf.rb b/app/pdf/order_item_slim_pdf.rb
old mode 100644
new mode 100755
index 09cce4d1..05add2c9
--- a/app/pdf/order_item_slim_pdf.rb
+++ b/app/pdf/order_item_slim_pdf.rb
@@ -37,7 +37,7 @@ class OrderItemSlimPdf < Prawn::Document
# font "public/fonts/Zawgyi-One.ttf"
# font "public/fonts/padauk.ttf"
#font "public/fonts/Chinese.ttf"
- if order_item_slim.dining.to_i > 0
+ if !order_item_slim.dining.nil?
text "#{ order_item_slim.type + '-' + order_item_slim.dining + print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20
else
text "#{ print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20
@@ -110,7 +110,7 @@ class OrderItemSlimPdf < Prawn::Document
end
# if alt_name
- # if !(order_item_slim.alt_name).empty?
+ # if order_item_slim.alt_name
# move_down 1
# font("public/fonts/NotoSansCJKtc-Regular.ttf") do
# text "(#{order_item_slim.alt_name})", :size => self.item_font_size,:align => :left, :inline_format => true
diff --git a/app/pdf/order_set_item_pdf.rb b/app/pdf/order_set_item_pdf.rb
old mode 100644
new mode 100755
index 6aa6efc4..ce06081f
--- a/app/pdf/order_set_item_pdf.rb
+++ b/app/pdf/order_set_item_pdf.rb
@@ -37,7 +37,7 @@ class OrderSetItemPdf < Prawn::Document
# font "public/fonts/Zawgyi-One.ttf"
# font "public/fonts/padauk.ttf"
#font "public/fonts/Chinese.ttf"
- if order_set_item.dining.to_i > 0
+ if !order_set_item.dining.nil?
text "#{ order_set_item.type + '-' + order_set_item.dining + print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20
else
text "#{ print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20
@@ -109,7 +109,7 @@ class OrderSetItemPdf < Prawn::Document
end
if alt_name
- if !(order_set_item.alt_name).empty?
+ if order_set_item.alt_name
move_down 4
font("public/fonts/NotoSansCJKtc-Regular.ttf") do
text "(#{order_set_item.alt_name})", :size => self.item_font_size,:align => :left, :inline_format => true
diff --git a/app/pdf/order_summary_pdf.rb b/app/pdf/order_summary_pdf.rb
index 6c8dacac..17cf905c 100755
--- a/app/pdf/order_summary_pdf.rb
+++ b/app/pdf/order_summary_pdf.rb
@@ -36,7 +36,8 @@ class OrderSummaryPdf < Prawn::Document
# font "public/fonts/Zawgyi-One.ttf"
# font "public/fonts/padauk.ttf"
- if order[0].dining.to_i > 0
+
+ if !order[0].dining.nil?
text "#{ order[0].type + '-' + order[0].dining + print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20
else
text "#{ print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20
diff --git a/app/pdf/order_summary_set_pdf.rb b/app/pdf/order_summary_set_pdf.rb
old mode 100644
new mode 100755
index 8828ea43..14b2f796
--- a/app/pdf/order_summary_set_pdf.rb
+++ b/app/pdf/order_summary_set_pdf.rb
@@ -36,7 +36,7 @@ class OrderSummarySetPdf < Prawn::Document
# font "public/fonts/Zawgyi-One.ttf"
# font "public/fonts/padauk.ttf"
- if order[0].dining.to_i > 0
+ if !order[0].dining.nil?
text "#{ order[0].type + '-' + order[0].dining + print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20
else
text "#{ print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20
diff --git a/app/pdf/order_summary_slim_pdf.rb b/app/pdf/order_summary_slim_pdf.rb
old mode 100644
new mode 100755
index 73023278..c88061ea
--- a/app/pdf/order_summary_slim_pdf.rb
+++ b/app/pdf/order_summary_slim_pdf.rb
@@ -36,7 +36,7 @@ class OrderSummarySlimPdf < Prawn::Document
# font "public/fonts/Zawgyi-One.ttf"
# font "public/fonts/padauk.ttf"
- if order[0].dining.to_i > 0
+ if !order[0].dining.nil?
text "#{ order[0].type + '-' + order[0].dining + print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20
else
text "#{ print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20
diff --git a/app/pdf/receipt_bill_a5_pdf.rb b/app/pdf/receipt_bill_a5_pdf.rb
index 11ad8100..604d99dd 100644
--- a/app/pdf/receipt_bill_a5_pdf.rb
+++ b/app/pdf/receipt_bill_a5_pdf.rb
@@ -1,6 +1,7 @@
class ReceiptBillA5Pdf < Prawn::Document
include ActionView::Helpers::NumberHelper
- attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width, :description_width, :price_num_width
+
+ attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width, :description_width, :price_num_width, :line_move
def initialize(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info = nil,rebate_amount = nil,shop_details, printed_status,current_balance,card_data)
self.page_width = printer_settings.page_width
self.page_height = printer_settings.page_height
@@ -15,6 +16,7 @@ class ReceiptBillA5Pdf < Prawn::Document
self.description_width = 500
self.price_num_width = 100
+ self.line_move = 10
# @item_width = self.page_width.to_i / 2
# @qty_width = @item_width.to_i / 3
# @double = @qty_width * 1.3
@@ -91,27 +93,33 @@ class ReceiptBillA5Pdf < Prawn::Document
end
def header (shop_details)
- move_down 10
+ move_down line_move
text "#{shop_details.name}", :size => self.header_font_size,:align => :center
- move_down 10
+ move_down line_move
text "#{shop_details.address}", :size => self.item_font_size,:align => :center
# move_down self.item_height
- move_down 10
+ move_down line_move
text "#{shop_details.phone_no}", :size => self.item_font_size,:align => :center
- move_down 10
+ move_down line_move
stroke_horizontal_rule
end
def cashier_info(sale_data, customer_name)
- move_down 12
+ move_down line_move
# move_down 2
y_position = cursor
bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
text "Receipt No: #{sale_data.receipt_no}", :size => self.item_font_size,:align => :left
end
-
- move_down 10
+
+ if sale_data.bookings[0].dining_facility_id.to_i > 0
+ bounding_box([self.item_description_width, y_position], :width => self.item_description_width, :height => self.item_height) do
+ text "#{ sale_data.bookings[0].dining_facility.type } - #{ sale_data.bookings[0].dining_facility.name }" , :size => self.item_font_size,:align => :right
+ end
+ end
+
+ move_down line_move
y_position = cursor
if sale_data.bookings[0].dining_facility_id.to_i > 0
@@ -126,7 +134,7 @@ class ReceiptBillA5Pdf < Prawn::Document
bounding_box([self.item_description_width - 2,y_position], :width =>self.item_description_width, :height => self.item_height) do
text "C: #{sale_data.cashier_name}", :size => self.item_font_size,:align => :right
end
- move_down 10
+ move_down line_move
y_position = cursor
if sale_data.bookings[0].dining_facility_id.to_i > 0
@@ -145,7 +153,7 @@ class ReceiptBillA5Pdf < Prawn::Document
# :size => self.item_font_size,:align => :right
# end
- move_down 10
+ move_down line_move
stroke_horizontal_rule
end
@@ -162,9 +170,9 @@ class ReceiptBillA5Pdf < Prawn::Document
item_label_total_front_width = (self.item_width+self.price_width) + 5
item_label_total_end_width = self.total_width + 4
end
- move_down 10
+ move_down line_move
y_position = cursor
- move_down 10
+ move_down line_move
pad_top(15) {
# @item_width.to_i + @half_qty.to_i
text_box "Items", :at =>[0,y_position], :width => self.item_width, :height =>self.item_height, :size => self.item_font_size, :overflow => :shrink_to_fix
@@ -172,7 +180,7 @@ class ReceiptBillA5Pdf < Prawn::Document
text_box "Qty", :at =>[item_label_qty_front_width,y_position], :width => item_label_qty_end_width, :height =>self.item_height, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix
text_box "Total", :at =>[item_label_total_front_width,y_position], :width => item_label_total_end_width, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix
}
- move_down -5
+ move_down line_move
stroke_horizontal_rule
add_line_item_row(sale_items,precision,delimiter)
end
@@ -192,7 +200,7 @@ class ReceiptBillA5Pdf < Prawn::Document
item_total_end_width = self.total_width + 4
end
y_position = cursor
- move_down 10
+ move_down line_move
sub_total = 0.0
sale_items.each do |item|
# check for item not to show
@@ -223,25 +231,25 @@ class ReceiptBillA5Pdf < Prawn::Document
end
end
end
+ move_down line_move
}
- move_down 10
end
end
stroke_horizontal_rule
- move_down 10
+ move_down line_move
y_position = cursor
bounding_box([0,y_position], :width =>self.description_width, :height => self.item_height) do
text "Sub Total", :size => self.item_font_size,:align => :left
end
bounding_box([self.description_width,y_position], :width =>self.label_width) do
text "#{number_with_precision(sub_total, :precision => precision.to_i, :delimiter => delimiter)}" ,:delimiter => ',', :size => self.item_font_size,:align => :right
- end
- move_down 10
+ end
end
def all_total(sale_data,precision,delimiter)
+ move_down line_move
item_name_width = self.item_width
y_position = cursor
if sale_data.discount_type == 'member_discount'
@@ -259,7 +267,7 @@ class ReceiptBillA5Pdf < Prawn::Document
if sale_data.sale_taxes.length > 0
sale_data.sale_taxes.each do |st|
- move_down 10
+ move_down line_move
y_position = cursor
bounding_box([0,y_position], :width =>self.description_width, :height => self.item_height) do
@@ -284,7 +292,7 @@ class ReceiptBillA5Pdf < Prawn::Document
# end
if sale_data.rounding_adjustment != 0.0
- move_down 10
+ move_down line_move
y_position = cursor
bounding_box([0,y_position], :width =>self.description_width, :height => self.item_height) do
@@ -295,16 +303,16 @@ class ReceiptBillA5Pdf < Prawn::Document
end
end
- move_down 10
+ move_down line_move
y_position = cursor
- move_down 10
+ move_down line_move
bounding_box([0,y_position], :width =>self.description_width) do
text "Grand Total",:style => :bold, :size => self.header_font_size,:align => :left
end
bounding_box([self.description_width,y_position], :width =>self.label_width) do
text "#{number_with_precision(sale_data.grand_total, :precision => precision.to_i, :delimiter => delimiter)}" , :style => :bold, :size => self.header_font_size,:align => :right
end
- move_down 10
+ move_down line_move
sale_payment(sale_data,precision,delimiter)
@@ -312,7 +320,7 @@ class ReceiptBillA5Pdf < Prawn::Document
def sale_payment(sale_data,precision,delimiter)
stroke_horizontal_rule
- move_down 10
+ # move_down 10
sale_payments = SalePayment.select("SUM(sale_payments.payment_amount) as payment_amount,sale_payments.payment_method").where('sale_id = ?', sale_data.sale_id).group("payment_method")
sale_payments.each do |payment|
y_position = cursor
@@ -329,18 +337,18 @@ class ReceiptBillA5Pdf < Prawn::Document
bounding_box([self.description_width,y_position], :width =>self.label_width) do
text "#{number_with_precision(payment.payment_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right
end
- move_down 10
+ move_down line_move
end
if sale_data.amount_received > 0
y_position = cursor
- move_down 10
+ move_down line_move
bounding_box([0,y_position], :width =>self.description_width, :height => self.item_height) do
text "Change Amount", :size => self.item_font_size,:align => :left
end
bounding_box([self.description_width,y_position], :width =>self.label_width) do
text "#{number_with_precision(sale_data.amount_changed, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right
end
- move_down 10
+ #move_down line_move
end
end
@@ -367,7 +375,7 @@ class ReceiptBillA5Pdf < Prawn::Document
rebate_balance = rebate_balance + res["deposit"]
- move_down 10
+ move_down line_move
y_position = cursor
bounding_box([0,y_position], :width =>self.description_width, :height => self.item_height) do
text "Rebate Earn", :size => self.item_font_size,:align => :left
@@ -380,7 +388,7 @@ class ReceiptBillA5Pdf < Prawn::Document
# Total Rebate Amount if birthday
if res["receipt_no"]== sale_data.receipt_no && res["account_status"]== "RebatebonusAccount" && res["status"]== "Rebate"
rebate_balance = rebate_balance + res["deposit"]
- move_down 10
+ move_down line_move
y_position = cursor
bounding_box([0,y_position], :width =>self.description_width, :height => self.item_height) do
text "Rebate Earn Bonus", :size => self.item_font_size,:align => :left
@@ -392,7 +400,7 @@ class ReceiptBillA5Pdf < Prawn::Document
#end Total rebate if birthday
end
- move_down 10
+ move_down line_move
y_position = cursor
bounding_box([0,y_position], :width =>self.description_width, :height => self.item_height) do
text "Redeem Amount", :size => self.item_font_size,:align => :left
@@ -402,7 +410,7 @@ class ReceiptBillA5Pdf < Prawn::Document
end
if current_balance != nil
- move_down 10
+ move_down line_move
y_position = cursor
bounding_box([0,y_position], :width =>self.description_width, :height => self.item_height) do
text "Old Balance", :size => self.item_font_size,:align => :left
@@ -424,7 +432,7 @@ class ReceiptBillA5Pdf < Prawn::Document
end
end
- move_down 10
+ move_down line_move
y_position = cursor
bounding_box([0,y_position], :width =>self.description_width, :height => self.item_height) do
text "Total Balance", :size => self.item_font_size,:align => :left
@@ -437,21 +445,22 @@ class ReceiptBillA5Pdf < Prawn::Document
end
def customer(customer_name)
- move_down 10
+ move_down line_move
y_position = cursor
+ move_down line_move
bounding_box([0,y_position], :width =>self.description_width, :height => self.item_height) do
text "Customer Name", :size => self.item_font_size,:align => :left
end
bounding_box([self.description_width,y_position], :width =>self.label_width) do
text "#{ customer_name }" , :size => self.item_font_size,:align => :right
end
+ move_down line_move
end
def discount_account(discount_price_by_accounts,precision,delimiter)
- move_down 10
stroke_horizontal_rule
- move_down 10
+ move_down line_move
y_position = cursor
discount_price_by_accounts.each do |ipa|
y_position = cursor
@@ -461,13 +470,13 @@ class ReceiptBillA5Pdf < Prawn::Document
bounding_box([self.description_width,y_position], :width =>self.label_width) do
text "(" + "#{ number_with_precision(ipa[:price], :precision => precision.to_i, :delimiter => delimiter) }" + ")" , :size => self.item_font_size,:align => :right
end
+ move_down line_move
end
end
def items_account(item_price_by_accounts,precision,delimiter)
- move_down 10
stroke_horizontal_rule
- move_down 10
+ move_down line_move
y_position = cursor
item_price_by_accounts.each do |ipa|
y_position = cursor
@@ -477,15 +486,15 @@ class ReceiptBillA5Pdf < Prawn::Document
bounding_box([self.label_width,y_position], :width =>self.description_width) do
text "#{number_with_precision(ipa[:price], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right
end
+ move_down line_move
end
end
#individual payment per person
def individual_payment(sale_data, precision, delimiter)
- per_person = sale_data.grand_total.to_f / sale_data.equal_persons.to_i
- move_down 5
+ per_person = sale_data.grand_total.to_i / sale_data.equal_persons.to_i
stroke_horizontal_rule
- move_down 5
+ move_down line_move
y_position = cursor
bounding_box([0,y_position], :width =>self.label_width+50) do
text "Split Bill for #{sale_data.equal_persons} persons", :size => self.item_font_size+1,:align => :left
@@ -541,9 +550,9 @@ class ReceiptBillA5Pdf < Prawn::Document
end
def footer(printed_status)
- move_down 10
+ move_down line_move
stroke_horizontal_rule
- move_down 10
+ move_down line_move
y_position = cursor
bounding_box([0, y_position], :width =>self.item_description_width) do
@@ -553,15 +562,15 @@ class ReceiptBillA5Pdf < Prawn::Document
text "Thank You! See you Again", :left_margin => -5, :size => self.item_font_size,:align => :right
end
- move_down 10
+ move_down line_move
end
#start card sale trans data
def card_sale_data(card_data)
if card_data != nil && !card_data.empty?
- move_down 5
+ move_down line_move
stroke_horizontal_rule
- move_down 5
+ move_down line_move
y_position = cursor
card_data.each do |data|
diff --git a/app/pdf/receipt_bill_pdf.rb b/app/pdf/receipt_bill_pdf.rb
index c34ce3e4..c0299033 100755
--- a/app/pdf/receipt_bill_pdf.rb
+++ b/app/pdf/receipt_bill_pdf.rb
@@ -1,132 +1,134 @@
class ReceiptBillPdf < Prawn::Document
- include ActionView::Helpers::NumberHelper
- attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width, :description_width, :price_num_width
- def initialize(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info = nil,rebate_amount = nil,shop_details, printed_status,current_balance,card_data)
- self.page_width = printer_settings.page_width
- self.page_height = printer_settings.page_height
- self.margin = 0
- self.price_width = 60
- self.qty_width = 25
- self.total_width = 60
- self.item_width = self.page_width - ((self.qty_width + self.price_width + self.total_width))
- self.item_height = 15
- self.item_description_width = (self.page_width-5) / 2
- self.label_width = 100
+ include ActionView::Helpers::NumberHelper
- self.description_width = 150
- self.price_num_width = 50
- # @item_width = self.page_width.to_i / 2
- # @qty_width = @item_width.to_i / 3
- # @double = @qty_width * 1.3
- # @half_qty = @qty_width / 2
- #setting page margin and width
- super(:margin => [printer_settings.heading_space, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height])
+ attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width, :description_width, :price_num_width, :line_move
+
+ def initialize(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info = nil,rebate_amount = nil,shop_details, printed_status,current_balance,card_data)
+ self.page_width = printer_settings.page_width
+ self.page_height = printer_settings.page_height
+ self.margin = 0
+ self.price_width = 60
+ self.qty_width = 25
+ self.total_width = 60
+ self.item_width = self.page_width - ((self.qty_width + self.price_width + self.total_width))
+ self.item_height = 15
+ self.item_description_width = (self.page_width-5) / 2
+ self.label_width = 100
- #precision checked
- if printer_settings.precision.to_i > 2
- printer_settings.precision = 2
+ self.description_width = 150
+ self.price_num_width = 50
+ self.line_move = 2
+ # @item_width = self.page_width.to_i / 2
+ # @qty_width = @item_width.to_i / 3
+ # @double = @qty_width * 1.3
+ # @half_qty = @qty_width / 2
+ #setting page margin and width
+ super(:margin => [printer_settings.heading_space, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height])
+
+ #precision checked
+ if printer_settings.precision.to_i > 2
+ printer_settings.precision = 2
+ end
+
+ # db font setup
+ if printer_settings.font != ""
+ font_families.update("#{printer_settings.font}" => {
+ :normal => "public/fonts/#{printer_settings.font}.ttf",
+ :italic => "public/fonts/#{printer_settings.font}.ttf",
+ :bold => "public/fonts/#{printer_settings.font}.ttf",
+ :bold_italic => "public/fonts/#{printer_settings.font}.ttf"
+ })
+
+ font "#{printer_settings.font}"
+ fallback_fonts ["Courier", "Helvetica", "Times-Roman"]
+ end
+ # font "public/fonts/Zawgyi-One.ttf"
+ # font "public/fonts/padauk.ttf"
+ self.header_font_size = 10
+ self.item_font_size = 8
+
+ if printer_settings.delimiter
+ delimiter = ","
+ else
+ delimiter = ""
+ end
+
+ header(shop_details)
+
+ stroke_horizontal_rule
+
+ cashier_info(sale_data, customer_name)
+ line_items(sale_items,printer_settings.precision,delimiter)
+ all_total(sale_data,printer_settings.precision,delimiter)
+
+
+ if member_info != nil
+ member_info(member_info,customer_name,rebate_amount,sale_data,printer_settings.precision,delimiter,current_balance)
+ end
+
+ customer(customer_name)
+
+ #start card sale trans data
+ if card_data != nil
+ card_sale_data(card_data)
+ end
+ #end card sale trans data
+
+ if discount_price_by_accounts.length > 0 && shop_details.show_account_info
+ discount_account(discount_price_by_accounts,printer_settings.precision,delimiter)
+ end
+
+ if shop_details.show_account_info
+ items_account(item_price_by_accounts,printer_settings.precision,delimiter)
+ end
+
+ #start for individual payment
+ if !sale_data.equal_persons.nil?
+ individual_payment(sale_data, printer_settings.precision, delimiter)
+ end
+ #end for individual payment
+
+ sign(sale_data)
+
+ footer(printed_status)
end
- # db font setup
- if printer_settings.font != ""
- font_families.update("#{printer_settings.font}" => {
- :normal => "public/fonts/#{printer_settings.font}.ttf",
- :italic => "public/fonts/#{printer_settings.font}.ttf",
- :bold => "public/fonts/#{printer_settings.font}.ttf",
- :bold_italic => "public/fonts/#{printer_settings.font}.ttf"
- })
+ def header (shop_details)
+ text "#{shop_details.name}", :left_margin => -10, :size => self.header_font_size,:align => :center
+ move_down line_move
+ text "#{shop_details.address}", :size => self.item_font_size,:align => :center
+ # move_down self.item_height
+ move_down line_move
+ text "#{shop_details.phone_no}", :size => self.item_font_size,:align => :center
+ move_down line_move
- font "#{printer_settings.font}"
- fallback_fonts ["Courier", "Helvetica", "Times-Roman"]
- end
- # font "public/fonts/Zawgyi-One.ttf"
- # font "public/fonts/padauk.ttf"
- self.header_font_size = 10
- self.item_font_size = 8
-
- if printer_settings.delimiter
- delimiter = ","
- else
- delimiter = ""
+ stroke_horizontal_rule
end
- header(shop_details)
+ def cashier_info(sale_data, customer_name)
+ move_down line_move
- stroke_horizontal_rule
-
- cashier_info(sale_data, customer_name)
- line_items(sale_items,printer_settings.precision,delimiter)
- all_total(sale_data,printer_settings.precision,delimiter)
-
-
- if member_info != nil
- member_info(member_info,customer_name,rebate_amount,sale_data,printer_settings.precision,delimiter,current_balance)
- end
-
- customer(customer_name)
-
- #start card sale trans data
- if card_data != nil
- card_sale_data(card_data)
- end
- #end card sale trans data
-
- if discount_price_by_accounts.length > 0 && shop_details.show_account_info
- discount_account(discount_price_by_accounts,printer_settings.precision,delimiter)
- end
-
- if shop_details.show_account_info
- items_account(item_price_by_accounts,printer_settings.precision,delimiter)
- end
-
- #start for individual payment
- if !sale_data.equal_persons.nil?
- individual_payment(sale_data, printer_settings.precision, delimiter)
- end
- #end for individual payment
-
- sign(sale_data)
-
- footer(printed_status)
- end
-
- def header (shop_details)
- move_down 5
- text "#{shop_details.name}", :left_margin => -10, :size => self.header_font_size,:align => :center
- move_down 5
- text "#{shop_details.address}", :size => self.item_font_size,:align => :center
- # move_down self.item_height
- move_down 5
- text "#{shop_details.phone_no}", :size => self.item_font_size,:align => :center
- move_down 5
-
- stroke_horizontal_rule
- end
-
- def cashier_info(sale_data, customer_name)
- move_down 7
# move_down 2
y_position = cursor
bounding_box([0,y_position], :width =>self.description_width + self.price_num_width, :height => self.item_height) do
text "Receipt No: #{sale_data.receipt_no}", :size => self.item_font_size,:align => :left
end
- move_down 5
-
- y_position = cursor
if sale_data.bookings[0].dining_facility_id.to_i > 0
- bounding_box([0,y_position], :width => self.label_width, :height => self.item_height) do
- text "#{ sale_data.bookings[0].dining_facility.type } - #{ sale_data.bookings[0].dining_facility.name }" , :size => self.item_font_size,:align => :left
- end
+ bounding_box([self.description_width - 2,y_position], :width => self.price_num_width, :height => self.item_height) do
+ text "#{ sale_data.bookings[0].dining_facility.type } - #{ sale_data.bookings[0].dining_facility.name }" , :size => self.item_font_size,:align => :right
+ end
end
- bounding_box([self.label_width, y_position], :width =>self.label_width, :height => self.item_height) do
+ move_down line_move
+ y_position = cursor
+ bounding_box([0, y_position], :width =>self.label_width, :height => self.item_height) do
text "W: #{sale_data.requested_by}" , :size => self.item_font_size, :align => :left
end
bounding_box([self.label_width - 2,y_position], :width =>self.label_width, :height => self.item_height) do
text "C: #{sale_data.cashier_name}", :size => self.item_font_size,:align => :right
end
- move_down 5
+ move_down line_move
y_position = cursor
if sale_data.bookings[0].dining_facility_id.to_i > 0
@@ -134,21 +136,20 @@ class ReceiptBillPdf < Prawn::Document
else
time = sale_data.receipt_date.strftime('%d-%m-%Y %H:%M %p')
end
-
+
bounding_box([0,y_position], :width =>self.page_width - 10, :height => self.item_height) do
text "Date : #{ time }",:size => self.item_font_size,:align => :left
end
-
# bounding_box([self.item_description_width,y_position], :width =>self.label_width+5) do
# text "(#{ sale_data.bookings[0].checkin_at.utc.getlocal.strftime('%I:%M %p') }
# - #{ sale_data.bookings[0].checkin_at.utc.getlocal.strftime('%I:%M %p') })" ,
# :size => self.item_font_size,:align => :right
# end
- move_down 5
+ move_down line_move
stroke_horizontal_rule
- end
+ end
def line_items(sale_items,precision,delimiter)
if precision.to_i > 0
@@ -163,9 +164,9 @@ class ReceiptBillPdf < Prawn::Document
item_label_total_front_width = (self.item_width+self.price_width) + 5
item_label_total_end_width = self.total_width + 4
end
- move_down 5
+ move_down line_move
y_position = cursor
- move_down 5
+ move_down line_move
pad_top(15) {
# @item_width.to_i + @half_qty.to_i
text_box "Items", :at =>[0,y_position], :width => self.item_width, :height =>self.item_height, :size => self.item_font_size, :overflow => :shrink_to_fix
@@ -173,7 +174,7 @@ class ReceiptBillPdf < Prawn::Document
text_box "Qty", :at =>[item_label_qty_front_width,y_position], :width => item_label_qty_end_width, :height =>self.item_height, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix
text_box "Total", :at =>[item_label_total_front_width,y_position], :width => item_label_total_end_width, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix
}
- move_down -5
+ # move_down line_move
stroke_horizontal_rule
add_line_item_row(sale_items,precision,delimiter)
end
@@ -193,7 +194,7 @@ class ReceiptBillPdf < Prawn::Document
item_total_end_width = self.total_width + 4
end
y_position = cursor
- move_down 5
+ move_down line_move
sub_total = 0.0
sale_items.each do |item|
# check for item not to show
@@ -224,25 +225,26 @@ class ReceiptBillPdf < Prawn::Document
end
end
end
+ move_down line_move
}
- move_down 5
+
end
end
stroke_horizontal_rule
- move_down 5
+ move_down line_move
y_position = cursor
bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
text "Sub Total", :size => self.item_font_size,:align => :left
end
bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
text "#{number_with_precision(sub_total, :precision => precision.to_i, :delimiter => delimiter)}" ,:delimiter => ',', :size => self.item_font_size,:align => :right
- end
- move_down 5
+ end
end
def all_total(sale_data,precision,delimiter)
+ move_down line_move
item_name_width = self.item_width
y_position = cursor
if sale_data.discount_type == 'member_discount'
@@ -260,7 +262,7 @@ class ReceiptBillPdf < Prawn::Document
if sale_data.sale_taxes.length > 0
sale_data.sale_taxes.each do |st|
- move_down 5
+ move_down line_move
y_position = cursor
bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
@@ -285,7 +287,7 @@ class ReceiptBillPdf < Prawn::Document
# end
if sale_data.rounding_adjustment != 0.0
- move_down 5
+ move_down line_move
y_position = cursor
bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
@@ -296,24 +298,23 @@ class ReceiptBillPdf < Prawn::Document
end
end
- move_down 5
+ move_down line_move
y_position = cursor
- move_down 5
+ move_down line_move
bounding_box([0,y_position], :width =>self.item_description_width) do
text "Grand Total",:style => :bold, :size => self.header_font_size,:align => :left
end
bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
text "#{number_with_precision(sale_data.grand_total, :precision => precision.to_i, :delimiter => delimiter)}" , :style => :bold, :size => self.header_font_size,:align => :right
end
- move_down 5
+ move_down line_move
- sale_payment(sale_data,precision,delimiter)
-
+ sale_payment(sale_data,precision,delimiter)
end
def sale_payment(sale_data,precision,delimiter)
stroke_horizontal_rule
- move_down 5
+ #move_down line_move
sale_payments = SalePayment.select("SUM(sale_payments.payment_amount) as payment_amount,sale_payments.payment_method").where('sale_id = ?', sale_data.sale_id).group("payment_method")
sale_payments.each do |payment|
y_position = cursor
@@ -330,18 +331,18 @@ class ReceiptBillPdf < Prawn::Document
bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
text "#{number_with_precision(payment.payment_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right
end
- move_down 5
+ move_down line_move
end
if sale_data.amount_received > 0
y_position = cursor
- move_down 5
+ move_down line_move
bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
text "Change Amount", :size => self.item_font_size,:align => :left
end
bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
text "#{number_with_precision(sale_data.amount_changed, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right
end
- move_down 5
+ # move_down line_move
end
end
@@ -368,7 +369,7 @@ class ReceiptBillPdf < Prawn::Document
rebate_balance = rebate_balance + res["deposit"]
- move_down 5
+ move_down line_move
y_position = cursor
bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
text "Rebate Earn", :size => self.item_font_size,:align => :left
@@ -381,7 +382,7 @@ class ReceiptBillPdf < Prawn::Document
# Total Rebate Amount if birthday
if res["receipt_no"]== sale_data.receipt_no && res["account_status"]== "RebatebonusAccount" && res["status"]== "Rebate"
rebate_balance = rebate_balance + res["deposit"]
- move_down 5
+ move_down line_move
y_position = cursor
bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
text "Rebate Earn Bonus", :size => self.item_font_size,:align => :left
@@ -393,7 +394,7 @@ class ReceiptBillPdf < Prawn::Document
#end Total rebate if birthday
end
- move_down 5
+ move_down line_move
y_position = cursor
bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
text "Redeem Amount", :size => self.item_font_size,:align => :left
@@ -403,7 +404,7 @@ class ReceiptBillPdf < Prawn::Document
end
if current_balance != nil
- move_down 5
+ move_down line_move
y_position = cursor
bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
text "Old Balance", :size => self.item_font_size,:align => :left
@@ -425,7 +426,7 @@ class ReceiptBillPdf < Prawn::Document
end
end
- move_down 5
+ move_down line_move
y_position = cursor
bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
text "Total Balance", :size => self.item_font_size,:align => :left
@@ -438,21 +439,23 @@ class ReceiptBillPdf < Prawn::Document
end
def customer(customer_name)
- move_down 5
+ # move_down line_move
y_position = cursor
+ #move_down line_move
bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
text "Customer Name", :size => self.item_font_size,:align => :left
end
bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
text "#{ customer_name }" , :size => self.item_font_size,:align => :right
end
+ move_down line_move
end
def discount_account(discount_price_by_accounts,precision,delimiter)
- move_down 5
+
stroke_horizontal_rule
- move_down 5
+ move_down line_move
y_position = cursor
discount_price_by_accounts.each do |ipa|
y_position = cursor
@@ -462,13 +465,13 @@ class ReceiptBillPdf < Prawn::Document
bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
text "(" + "#{ number_with_precision(ipa[:price], :precision => precision.to_i, :delimiter => delimiter) }" + ")" , :size => self.item_font_size,:align => :right
end
+ move_down line_move
end
end
def items_account(item_price_by_accounts,precision,delimiter)
- move_down 5
stroke_horizontal_rule
- move_down 5
+ move_down line_move
y_position = cursor
item_price_by_accounts.each do |ipa|
y_position = cursor
@@ -477,16 +480,16 @@ class ReceiptBillPdf < Prawn::Document
end
bounding_box([self.label_width,y_position], :width =>self.item_description_width) do
text "#{number_with_precision(ipa[:price], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right
- end
+ end
+ move_down line_move
end
end
#individual payment per person
- def individual_payment(sale_data, precision, delimiter)
- per_person = sale_data.grand_total.to_f / sale_data.equal_persons.to_i
- move_down 5
+ def individual_payment(sale_data, survey, precision, delimiter)
+ per_person = sale_data.grand_total.to_f / survey.total_customer.to_i
stroke_horizontal_rule
- move_down 5
+ move_down line_move
y_position = cursor
bounding_box([0,y_position], :width =>self.label_width+50) do
text "Split Bill for #{sale_data.equal_persons} persons", :size => self.item_font_size+1,:align => :left
@@ -537,15 +540,15 @@ class ReceiptBillPdf < Prawn::Document
text "Acknowledged By" , :size => self.item_font_size,:align => :center
end
end
-
-
+
end
def footer(printed_status)
- move_down 5
+ move_down line_move
stroke_horizontal_rule
- move_down 5
+ move_down line_move
+ move_down line_move
y_position = cursor
bounding_box([0, y_position], :width =>self.label_width) do
text "#{printed_status}",:style => :bold, :size => header_font_size,:align => :left
@@ -554,15 +557,15 @@ class ReceiptBillPdf < Prawn::Document
text "Thank You! See you Again", :left_margin => -5, :size => self.item_font_size,:align => :left
end
- move_down 5
+ move_down line_move
end
#start card sale trans data
def card_sale_data(card_data)
if card_data != nil && !card_data.empty?
- move_down 5
+ move_down line_move
stroke_horizontal_rule
- move_down 5
+ move_down line_move
y_position = cursor
card_data.each do |data|
diff --git a/app/uploaders/commissioner_image_uploader.rb b/app/uploaders/commissioner_image_uploader.rb
new file mode 100644
index 00000000..639ce7d7
--- /dev/null
+++ b/app/uploaders/commissioner_image_uploader.rb
@@ -0,0 +1,59 @@
+class CommissionerImageUploader < CarrierWave::Uploader::Base
+
+ # Include RMagick or MiniMagick support:
+ # include CarrierWave::RMagick
+ include CarrierWave::MiniMagick
+
+ # Choose what kind of storage to use for this uploader:
+ storage :file
+ # storage :fog
+
+ def root
+ Rails.root.join 'public/'
+ end
+
+ # Override the directory where uploaded files will be stored.
+ # This is a sensible default for uploaders that are meant to be mounted:
+ def store_dir
+ "image/commissioner_images"
+ # "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
+ end
+
+ # def cache_dir
+ # '/tmp/images'
+ # end
+
+ # Provide a default URL as a default if there hasn't been a file uploaded:
+ # def default_url(*args)
+ # # For Rails 3.1+ asset pipeline compatibility:
+ # # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
+ #
+ # "/images/fallback/" + [version_name, "default.png"].compact.join('_')
+ # end
+
+ # Process files as they are uploaded:
+ # process scale: [200, 300]
+ process :resize_to_fit => [200, 150]
+ #
+ # def scale(width, height)
+ # # do something
+ # end
+
+ # Create different versions of your uploaded files:
+ # version :thumb do
+ # process resize_to_fit: [50, 50]
+ # end
+
+ # Add a white list of extensions which are allowed to be uploaded.
+ # For images you might use something like this:
+ def extension_whitelist
+ %w(jpg jpeg gif png)
+ end
+
+ # Override the filename of the uploaded files:
+ # Avoid using model.id or version_name here, see uploader/store.rb for details.
+ # def filename
+ # "something.jpg" if original_filename
+ # end
+
+end
\ No newline at end of file
diff --git a/app/uploaders/customer_image_uploader.rb b/app/uploaders/customer_image_uploader.rb
new file mode 100644
index 00000000..1de0f3ad
--- /dev/null
+++ b/app/uploaders/customer_image_uploader.rb
@@ -0,0 +1,59 @@
+class CustomerImageUploader < CarrierWave::Uploader::Base
+
+ # Include RMagick or MiniMagick support:
+ # include CarrierWave::RMagick
+ include CarrierWave::MiniMagick
+
+ # Choose what kind of storage to use for this uploader:
+ storage :file
+ # storage :fog
+
+ def root
+ Rails.root.join 'public/'
+ end
+
+ # Override the directory where uploaded files will be stored.
+ # This is a sensible default for uploaders that are meant to be mounted:
+ def store_dir
+ "image/customer_images"
+ # "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
+ end
+
+ # def cache_dir
+ # '/tmp/images'
+ # end
+
+ # Provide a default URL as a default if there hasn't been a file uploaded:
+ # def default_url(*args)
+ # # For Rails 3.1+ asset pipeline compatibility:
+ # # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
+ #
+ # "/images/fallback/" + [version_name, "default.png"].compact.join('_')
+ # end
+
+ # Process files as they are uploaded:
+ # process scale: [200, 300]
+ process :resize_to_fit => [200, 150]
+ #
+ # def scale(width, height)
+ # # do something
+ # end
+
+ # Create different versions of your uploaded files:
+ # version :thumb do
+ # process resize_to_fit: [50, 50]
+ # end
+
+ # Add a white list of extensions which are allowed to be uploaded.
+ # For images you might use something like this:
+ def extension_whitelist
+ %w(jpg jpeg gif png)
+ end
+
+ # Override the filename of the uploaded files:
+ # Avoid using model.id or version_name here, see uploader/store.rb for details.
+ # def filename
+ # "something.jpg" if original_filename
+ # end
+
+end
\ No newline at end of file
diff --git a/app/uploaders/display_image_uploader.rb b/app/uploaders/display_image_uploader.rb
new file mode 100644
index 00000000..33e28997
--- /dev/null
+++ b/app/uploaders/display_image_uploader.rb
@@ -0,0 +1,59 @@
+class DisplayImageUploader < CarrierWave::Uploader::Base
+
+ # Include RMagick or MiniMagick support:
+ # include CarrierWave::RMagick
+ include CarrierWave::MiniMagick
+
+ # Choose what kind of storage to use for this uploader:
+ storage :file
+ # storage :fog
+
+ # def root
+ # Rails.root.join 'public/'
+ # end
+
+ # Override the directory where uploaded files will be stored.
+ # This is a sensible default for uploaders that are meant to be mounted:
+ def store_dir
+ #"image/image"
+ "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
+ end
+
+ # def cache_dir
+ # '/tmp/images'
+ # end
+
+ # Provide a default URL as a default if there hasn't been a file uploaded:
+ # def default_url(*args)
+ # # For Rails 3.1+ asset pipeline compatibility:
+ # # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
+ #
+ # "/images/fallback/" + [version_name, "default.png"].compact.join('_')
+ # end
+
+ # Process files as they are uploaded:
+ # process scale: [200, 300]
+ process :resize_to_fit => [200, 150]
+ #
+ # def scale(width, height)
+ # # do something
+ # end
+
+ # Create different versions of your uploaded files:
+ # version :thumb do
+ # process resize_to_fit: [50, 50]
+ # end
+
+ # Add a white list of extensions which are allowed to be uploaded.
+ # For images you might use something like this:
+ def extension_whitelist
+ %w(jpg jpeg gif png)
+ end
+
+ # Override the filename of the uploaded files:
+ # Avoid using model.id or version_name here, see uploader/store.rb for details.
+ # def filename
+ # "something.jpg" if original_filename
+ # end
+
+end
\ No newline at end of file
diff --git a/app/uploaders/employee_image_uploader.rb b/app/uploaders/employee_image_uploader.rb
new file mode 100644
index 00000000..fd64db42
--- /dev/null
+++ b/app/uploaders/employee_image_uploader.rb
@@ -0,0 +1,59 @@
+class EmployeeImageUploader < CarrierWave::Uploader::Base
+
+ # Include RMagick or MiniMagick support:
+ # include CarrierWave::RMagick
+ include CarrierWave::MiniMagick
+
+ # Choose what kind of storage to use for this uploader:
+ storage :file
+ # storage :fog
+
+ def root
+ Rails.root.join 'public/'
+ end
+
+ # Override the directory where uploaded files will be stored.
+ # This is a sensible default for uploaders that are meant to be mounted:
+ def store_dir
+ "image/employee_images"
+ # "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
+ end
+
+ # def cache_dir
+ # '/tmp/images'
+ # end
+
+ # Provide a default URL as a default if there hasn't been a file uploaded:
+ # def default_url(*args)
+ # # For Rails 3.1+ asset pipeline compatibility:
+ # # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
+ #
+ # "/images/fallback/" + [version_name, "default.png"].compact.join('_')
+ # end
+
+ # Process files as they are uploaded:
+ # process scale: [200, 300]
+ process :resize_to_fit => [200, 150]
+ #
+ # def scale(width, height)
+ # # do something
+ # end
+
+ # Create different versions of your uploaded files:
+ # version :thumb do
+ # process resize_to_fit: [50, 50]
+ # end
+
+ # Add a white list of extensions which are allowed to be uploaded.
+ # For images you might use something like this:
+ def extension_whitelist
+ %w(jpg jpeg gif png)
+ end
+
+ # Override the filename of the uploaded files:
+ # Avoid using model.id or version_name here, see uploader/store.rb for details.
+ # def filename
+ # "something.jpg" if original_filename
+ # end
+
+end
\ No newline at end of file
diff --git a/app/uploaders/shop_image_uploader.rb b/app/uploaders/shop_image_uploader.rb
new file mode 100644
index 00000000..63a01c21
--- /dev/null
+++ b/app/uploaders/shop_image_uploader.rb
@@ -0,0 +1,59 @@
+class ShopImageUploader < CarrierWave::Uploader::Base
+
+ # Include RMagick or MiniMagick support:
+ # include CarrierWave::RMagick
+ include CarrierWave::MiniMagick
+
+ # Choose what kind of storage to use for this uploader:
+ storage :file
+ # storage :fog
+
+ def root
+ Rails.root.join 'public/'
+ end
+
+ # Override the directory where uploaded files will be stored.
+ # This is a sensible default for uploaders that are meant to be mounted:
+ def store_dir
+ "image/shop_images"
+ # "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
+ end
+
+ # def cache_dir
+ # '/tmp/images'
+ # end
+
+ # Provide a default URL as a default if there hasn't been a file uploaded:
+ # def default_url(*args)
+ # # For Rails 3.1+ asset pipeline compatibility:
+ # # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
+ #
+ # "/images/fallback/" + [version_name, "default.png"].compact.join('_')
+ # end
+
+ # Process files as they are uploaded:
+ # process scale: [200, 300]
+ process :resize_to_fit => [200, 150]
+ #
+ # def scale(width, height)
+ # # do something
+ # end
+
+ # Create different versions of your uploaded files:
+ # version :thumb do
+ # process resize_to_fit: [50, 50]
+ # end
+
+ # Add a white list of extensions which are allowed to be uploaded.
+ # For images you might use something like this:
+ def extension_whitelist
+ %w(jpg jpeg gif png)
+ end
+
+ # Override the filename of the uploaded files:
+ # Avoid using model.id or version_name here, see uploader/store.rb for details.
+ # def filename
+ # "something.jpg" if original_filename
+ # end
+
+end
\ No newline at end of file
diff --git a/app/views/api/orders/view_orders.json.jbuilder b/app/views/api/orders/view_orders.json.jbuilder
index ae3fea84..dd72a3a3 100755
--- a/app/views/api/orders/view_orders.json.jbuilder
+++ b/app/views/api/orders/view_orders.json.jbuilder
@@ -46,9 +46,12 @@ if (@booking)
child_spent += (item.price * item.qty)
end
# End YGN BBQ
+ json.order_items_id item.order_items_id
+ json.order_id item.order_id
json.item_code item.item_code
json.item_instance_code item.item_instance_code
json.item_name item.item_name
+ json.set_menu_items item.set_menu_items
json.price item.price
json.qty item.qty
json.options item.options
diff --git a/app/views/crm/customers/_new_form.html.erb b/app/views/crm/customers/_new_form.html.erb
index 2359ad57..5dcb86b0 100755
--- a/app/views/crm/customers/_new_form.html.erb
+++ b/app/views/crm/customers/_new_form.html.erb
@@ -90,6 +90,21 @@
<%= t("views.right_panel.detail.date_of_birth") %>
<%= f.text_field :date_of_birth, :value=>"01-01-1990",:class=>"datepicker form-control col-md-12"%>
+
+
\ No newline at end of file
diff --git a/app/views/home/dashboard.html.erb b/app/views/home/dashboard.html.erb
index 3dd73a3d..865202b0 100755
--- a/app/views/home/dashboard.html.erb
+++ b/app/views/home/dashboard.html.erb
@@ -68,16 +68,48 @@