From fb5374149fc1bf226c38623f6604ab64bb088cc2 Mon Sep 17 00:00:00 2001 From: phyusin Date: Fri, 15 Dec 2017 09:56:36 +0630 Subject: [PATCH 01/84] change checkin booking color js --- .../javascripts/channels/check_in_booking.js | 10 ++++--- app/assets/javascripts/channels/checkin.js | 30 +++++++++---------- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/app/assets/javascripts/channels/check_in_booking.js b/app/assets/javascripts/channels/check_in_booking.js index 4f5300ee..18597f4d 100644 --- a/app/assets/javascripts/channels/check_in_booking.js +++ b/app/assets/javascripts/channels/check_in_booking.js @@ -5,10 +5,12 @@ App.checkin = App.cable.subscriptions.create('CheckInBookingChannel', { disconnected: function() {}, - received: function(data) { - $('.table_'+data.table.id).removeClass('green'); - $('.table_'+data.table.id).addClass('blue'); - $('.new_text_'+data.table.id).removeClass('hide') + received: function(data) { + if($('.table_'+data.table.id).hasClass('green')){ + $('.table_'+data.table.id).removeClass('green'); + $('.table_'+data.table.id).addClass('blue'); + } + $('.new_text_'+data.table.id).removeClass('hide'); } }); diff --git a/app/assets/javascripts/channels/checkin.js b/app/assets/javascripts/channels/checkin.js index d4a71d5e..03159170 100644 --- a/app/assets/javascripts/channels/checkin.js +++ b/app/assets/javascripts/channels/checkin.js @@ -6,21 +6,21 @@ App.order = App.cable.subscriptions.create('CheckinChannel', { disconnected: function() {}, received: function(data) { - $.each(data.table,function(key,value){ - if($('.table_'+value.table_id).hasClass('blue')){ - $('.table_'+value.table_id).removeClass('blue'); - $('.table_'+value.table_id).addClass('orange'); - } - else if($('.table_'+value.table_id).hasClass('red')){ - $('.table_'+value.table_id).removeClass('red'); - $('.table_'+value.table_id).addClass('orange'); - } - else { - $('.table_'+value.table_id).removeClass('green'); - $('.table_'+value.table_id).addClass('orange'); - } - $('.new_text_'+value.table_id).removeClass('hide'); - }); + $.each(data.table,function(key,value){ + if($('.table_'+value.table_id).hasClass('blue')){ + $('.table_'+value.table_id).removeClass('blue'); + $('.table_'+value.table_id).addClass('orange'); + } + else if($('.table_'+value.table_id).hasClass('red')){ + $('.table_'+value.table_id).removeClass('red'); + $('.table_'+value.table_id).addClass('orange'); + } + else { + $('.table_'+value.table_id).removeClass('green'); + $('.table_'+value.table_id).addClass('orange'); + } + $('.new_text_'+value.table_id).removeClass('hide'); + }); } }); From 20ae953af253a29a50fff55e1fdec7e852915d2b Mon Sep 17 00:00:00 2001 From: phyusin Date: Fri, 15 Dec 2017 11:50:05 +0630 Subject: [PATCH 02/84] cahnge foc process --- app/models/sale_payment.rb | 2 +- app/views/origami/payments/show.html.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 236606c6..56e18b25 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -187,7 +187,7 @@ class SalePayment < ApplicationRecord payment_status = false # add to sale item with foc - sale_items = SaleItem.where("sale_id='#{ self.sale.sale_id }'") + sale_items = SaleItem.where("sale_id='#{ self.sale.sale_id }' and remark is null") sale_items.each do|item| SaleItem.update_existing_item(item.qty, item, self.sale.sale_id, "foc", item.unit_price, item.price) diff --git a/app/views/origami/payments/show.html.erb b/app/views/origami/payments/show.html.erb index b2ffe0c3..286f86f3 100755 --- a/app/views/origami/payments/show.html.erb +++ b/app/views/origami/payments/show.html.erb @@ -497,7 +497,7 @@ //$( "#loading_wrapper" ).hide(); - if (cash > 0) { + if (cash >= 0) { swal({ title: "Information!", text: 'Thank You !', From 909bde979812435f590146ac482542d5ba7dbf61 Mon Sep 17 00:00:00 2001 From: phyusin Date: Fri, 15 Dec 2017 11:54:41 +0630 Subject: [PATCH 03/84] change top item --- app/models/sale.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/sale.rb b/app/models/sale.rb index 1598563f..29607c11 100755 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -1107,7 +1107,7 @@ end def self.top_items(today) 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("sales.sale_status = 'completed' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today) + .where("(a.qty > 0 and a.price > 0) and payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today) .group("a.product_code") .order("SUM(a.qty) DESC") .first() From c0170104c9c8773428c61eda4b95f8401782afa5 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Fri, 15 Dec 2017 13:57:54 +0630 Subject: [PATCH 04/84] update member discount for 5% --- README.md | 2 +- .../origami/discounts_controller.rb | 17 +++++++----- app/views/origami/jcb/index.html.erb | 26 +++++++++---------- app/views/origami/master/index.html.erb | 24 ++++++++--------- app/views/origami/mpu/index.html.erb | 24 ++++++++--------- app/views/origami/payments/show.html.erb | 15 +++++++---- app/views/origami/visa/index.html.erb | 24 ++++++++--------- 7 files changed, 70 insertions(+), 62 deletions(-) diff --git a/README.md b/README.md index ef68d0b7..5ff1aeda 100755 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ ruby 2.4.1p111 Campaign Id => {"campaign_type_id": 1} - +java -jar ~/Documents/Jade.jar http://192.168.1.88:3002 * ToDo list diff --git a/app/controllers/origami/discounts_controller.rb b/app/controllers/origami/discounts_controller.rb index f580a92f..1166a705 100755 --- a/app/controllers/origami/discounts_controller.rb +++ b/app/controllers/origami/discounts_controller.rb @@ -157,7 +157,11 @@ class Origami::DiscountsController < BaseOrigamiController is_card = params[:is_card] sub_total = params[:sub_total] sale = Sale.find(sale_id) - + if is_card == 'true' + is_card = true + else is_card.to_s == 'false' + is_card = false + end # Check for Card Payment is_card_payment = SalePayment.get_sale_payments_by_card(sale.sale_payments) @@ -178,9 +182,7 @@ class Origami::DiscountsController < BaseOrigamiController end end end - - generic_customer_id = sale.customer.membership_id - account_no = sale.customer.paypar_account_no + generic_customer_id = sale.customer.membership_id receipt_no = sale.receipt_no membership = MembershipSetting.find_by_membership_type("paypar_url") memberaction = MembershipAction.find_by_membership_type("member_discount") @@ -188,12 +190,13 @@ class Origami::DiscountsController < BaseOrigamiController campaign_type_id = memberaction.additional_parameter["campaign_type_id"] auth_token = memberaction.auth_token.to_s url = membership.gateway_url.to_s + memberaction.gateway_url.to_s + account_no = sale.customer.paypar_account_no rescue nil # Check for items for Paypar Cloud if acc_prices.length > 0 begin response = HTTParty.post(url, - :body => { account_no: nil, + :body => { account_no: account_no, generic_customer_id:generic_customer_id , campaign_type_id: campaign_type_id, receipt_no: receipt_no, @@ -220,8 +223,8 @@ class Origami::DiscountsController < BaseOrigamiController else response = {"status": false, "message": "You have no selected discount item" } end - puts "discountttttttttttt" - puts response.to_json + Rails.logger.debug "-------------- Member Discount Osaka ---------" + Rails.logger.debug response.to_json # Re-calc All Amount in Sale if response["status"] == true discount_amount = response["discount_earned"] diff --git a/app/views/origami/jcb/index.html.erb b/app/views/origami/jcb/index.html.erb index e33d4936..c7cc79f9 100755 --- a/app/views/origami/jcb/index.html.erb +++ b/app/views/origami/jcb/index.html.erb @@ -162,19 +162,19 @@ $('#jcb_pay').on('click',function(){ var sale_id = "<%= @sale_id %>"; if(parseFloat(amount) <= parseFloat($("#validamount").attr("value")) && amount > 0){ $(this).off("click"); - //start member discount 5% by pay card - var sub_total = $('#sub-total').text(); - var member_id = $('#membership_id').text(); - var member_discount = $('#member_discount').text(); - if (member_id && member_discount) { - $.ajax({ - type: "POST", - url: "/origami/" + sale_id + "/member_discount", - data: {'sale_id':sale_id, 'sub_total':sub_total,'is_card':true }, - // success:function(result){ - // } - }); - } + //start member discount 5% by pay card + // var sub_total = $('#sub-total').text(); + // var member_id = $('#membership_id').text(); + // var member_discount = $('#member_discount').text(); + // if (member_id && member_discount) { + // $.ajax({ + // type: "POST", + // url: "/origami/" + sale_id + "/member_discount", + // data: {'sale_id':sale_id, 'sub_total':sub_total,'is_card':true }, + // success:function(result){ + // } + // }); + // } //end member discount $.ajax({type: "POST", url: "<%= origami_payment_jcb_path %>", diff --git a/app/views/origami/master/index.html.erb b/app/views/origami/master/index.html.erb index 7dfac224..94a9e7c8 100755 --- a/app/views/origami/master/index.html.erb +++ b/app/views/origami/master/index.html.erb @@ -160,18 +160,18 @@ if(parseFloat(amount) <= parseFloat($("#validamount").attr("value")) && amount > 0){ $(this).off("click"); //start member discount 5% by pay card - var sub_total = $('#sub-total').text(); - var member_id = $('#membership_id').text(); - var member_discount = $('#member_discount').text(); - if (member_id && member_discount) { - $.ajax({ - type: "POST", - url: "/origami/" + sale_id + "/member_discount", - data: {'sale_id':sale_id, 'sub_total':sub_total,'is_card':true }, - // success:function(result){ - // } - }); - } + // var sub_total = $('#sub-total').text(); + // var member_id = $('#membership_id').text(); + // var member_discount = $('#member_discount').text(); + // if (member_id && member_discount) { + // $.ajax({ + // type: "POST", + // url: "/origami/" + sale_id + "/member_discount", + // data: {'sale_id':sale_id, 'sub_total':sub_total,'is_card':true }, + // // success:function(result){ + // // } + // }); + // } //end member discount $.ajax({type: "POST", url: "<%= origami_payment_master_path %>", diff --git a/app/views/origami/mpu/index.html.erb b/app/views/origami/mpu/index.html.erb index 85ebdc6c..722cd548 100755 --- a/app/views/origami/mpu/index.html.erb +++ b/app/views/origami/mpu/index.html.erb @@ -163,18 +163,18 @@ if(parseFloat(amount) <= parseFloat($("#validamount").attr("value")) && amount > 0){ $(this).off("click"); //start member discount 5% by pay card - var sub_total = $('#sub-total').text(); - var member_id = $('#membership_id').text(); - var member_discount = $('#member_discount').text(); - if (member_id && member_discount) { - $.ajax({ - type: "POST", - url: "/origami/" + sale_id + "/member_discount", - data: {'sale_id':sale_id, 'sub_total':sub_total,'is_card':true }, - // success:function(result){ - // } - }); - } + // var sub_total = $('#sub-total').text(); + // var member_id = $('#membership_id').text(); + // var member_discount = $('#member_discount').text(); + // if (member_id && member_discount) { + // $.ajax({ + // type: "POST", + // url: "/origami/" + sale_id + "/member_discount", + // data: {'sale_id':sale_id, 'sub_total':sub_total,'is_card':true }, + // success:function(result){ + // } + // }); + // } //end member discount //Mpu Payment $.ajax({type: "POST", diff --git a/app/views/origami/payments/show.html.erb b/app/views/origami/payments/show.html.erb index b2ffe0c3..e236928c 100755 --- a/app/views/origami/payments/show.html.erb +++ b/app/views/origami/payments/show.html.erb @@ -389,11 +389,11 @@ }else{ $(this).off("click"); var sale_id = $('#sale_id').text(); - var item_row = $('.is_card'); + // var item_row = $('.is_card'); - if (item_row.length < 1) { + // if (item_row.length < 1) { calculate_member_discount(sale_id); - } + // } // payment var cash = $('#cash').text(); @@ -517,15 +517,20 @@ var sub_total = $('#sub-total').text(); var member_id = $('#membership_id').text(); var member_discount = $('#member_discount').text(); + var item_row = $('.is_card'); if (member_id && member_discount) { + if (item_row.length < 1) { + is_card = false + }else{ + is_card = true + } $.ajax({ type: "POST", url: "/origami/" + sale_id + "/member_discount", - data: {'sale_id':sale_id, 'sub_total':sub_total,'is_card':false }, + data: {'sale_id':sale_id, 'sub_total':sub_total,'is_card':is_card }, async: false, success:function(result){ - } }); } diff --git a/app/views/origami/visa/index.html.erb b/app/views/origami/visa/index.html.erb index d239e231..cf0bd605 100755 --- a/app/views/origami/visa/index.html.erb +++ b/app/views/origami/visa/index.html.erb @@ -162,18 +162,18 @@ if(parseFloat(amount) <= parseFloat($("#validamount").attr("value")) && amount > 0){ $(this).off("click"); //start member discount 5% by pay card - var sub_total = $('#sub-total').text(); - var member_id = $('#membership_id').text(); - var member_discount = $('#member_discount').text(); - if (member_id && member_discount) { - $.ajax({ - type: "POST", - url: "/origami/" + sale_id + "/member_discount", - data: {'sale_id':sale_id, 'sub_total':sub_total,'is_card':true }, - // success:function(result){ - // } - }); - } + // var sub_total = $('#sub-total').text(); + // var member_id = $('#membership_id').text(); + // var member_discount = $('#member_discount').text(); + // if (member_id && member_discount) { + // $.ajax({ + // type: "POST", + // url: "/origami/" + sale_id + "/member_discount", + // data: {'sale_id':sale_id, 'sub_total':sub_total,'is_card':true }, + // success:function(result){ + // } + // }); + // } //end member discount $.ajax({type: "POST", url: "<%= origami_payment_visa_path %>", From 9a6c5fda130846033f20b0b03445078b82469a99 Mon Sep 17 00:00:00 2001 From: phyusin Date: Fri, 15 Dec 2017 15:15:29 +0630 Subject: [PATCH 05/84] change paid amount 0 --- app/models/sale_payment.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 56e18b25..06499c24 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -350,9 +350,9 @@ class SalePayment < ApplicationRecord self.sale.save! table_update_status(sObj) - if paid_amount != "0.0" + # if paid_amount != "0.0" update_shift - end + # end end end From 0ff76ca98ae859f5b4d9a0baebd3d85b14bce26a Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Fri, 15 Dec 2017 15:15:40 +0630 Subject: [PATCH 06/84] update osaka discoun 5% --- app/views/origami/customers/index.html.erb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/views/origami/customers/index.html.erb b/app/views/origami/customers/index.html.erb index e788a08f..03c73fea 100755 --- a/app/views/origami/customers/index.html.erb +++ b/app/views/origami/customers/index.html.erb @@ -32,7 +32,7 @@
- +
@@ -423,13 +423,13 @@ success: function(data) { if(data.status == true) { - var id = $("#table_id").val() - var type = $("#type").val() + var id = $("#table_id").val(); + var type = $("#type").val(); if (type=="Table") { window.location.href = '/origami/table/'+id }else{ - window.location.href = '/origami/room/'+id - } + window.location.href = '/origami/room/'+id + } }else{ swal("Alert!", "Record not found!", "error"); location.reload(); From 0c83a3a8cecc3f14a9258c5a6cf5101e6da23984 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Fri, 15 Dec 2017 16:26:35 +0630 Subject: [PATCH 07/84] update sale item for sub qty and person --- app/models/sale.rb | 2 +- app/views/reports/saleitem/index.html.erb | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/models/sale.rb b/app/models/sale.rb index 29607c11..b97c529e 100755 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -659,7 +659,7 @@ def self.get_item_query() # "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.group("i.product_name").order("mi.account_id asc","mi.menu_category_id asc") + query = query.group("i.product_name").order("mi.account_id desc") end def self.get_other_charges() diff --git a/app/views/reports/saleitem/index.html.erb b/app/views/reports/saleitem/index.html.erb index 7fa72521..97ba9c3f 100644 --- a/app/views/reports/saleitem/index.html.erb +++ b/app/views/reports/saleitem/index.html.erb @@ -49,6 +49,7 @@ <% acc_arr = Array.new %> <% cate_arr = Array.new %> + <% sub_qty = 0 %> <% sub_total = 0 %> <% other_sub_total = 0 %> <% count = 0 %> @@ -108,18 +109,23 @@ <%= sale.grand_total rescue '-' %> + <% @menu_cate_count.each do |key,value| %> <% if sale.menu_category_id == key %> <% count = count + 1 %> <% sub_total += sale.grand_total %> + <% sub_qty += sale.total_item %> <% if count == value %> -   +   + Total <%= sale.account_name %> Qty + <%= sub_qty %> <%= t("views.right_panel.detail.sub_total") %> <%= sub_total %> <% sub_total = 0.0%> + <% sub_qty = 0 %> <% count = 0%> <% end %> <% end %> @@ -127,7 +133,7 @@ <% end %> - + <% if @other_charges.present? %> Other Charges   @@ -157,7 +163,7 @@ <%= t("views.right_panel.detail.sub_total") %> <%= other_sub_total %> - + <%end%>   From 9f41be5c99e5ee5dca0de46f86fc08d1ba34c213 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Fri, 15 Dec 2017 17:55:02 +0630 Subject: [PATCH 08/84] upate call waiter print --- .../api/call_waiters_controller.rb | 8 +++ app/models/printer/receipt_printer.rb | 11 +++ app/pdf/call_waiter_pdf.rb | 71 +++++++++++++++++++ 3 files changed, 90 insertions(+) create mode 100644 app/pdf/call_waiter_pdf.rb diff --git a/app/controllers/api/call_waiters_controller.rb b/app/controllers/api/call_waiters_controller.rb index 2c45bbbe..4bd07570 100644 --- a/app/controllers/api/call_waiters_controller.rb +++ b/app/controllers/api/call_waiters_controller.rb @@ -6,6 +6,14 @@ class Api::CallWaitersController < ActionController::API @time = params[:time] @table = DiningFacility.find(@table_id) CallWaiterJob.perform_later(@table,@time) + + # get printer info + @shop = Shop::ShopDetail + unique_code = "CallWaiterPdf" + print_settings = PrintSetting.find_by_unique_code(unique_code) + printer = Printer::ReceiptPrinter.new(print_settings) + printer.print_call_waiter(print_settings,@table,@time,@shop) + end diff --git a/app/models/printer/receipt_printer.rb b/app/models/printer/receipt_printer.rb index 78aa204e..adcb187e 100755 --- a/app/models/printer/receipt_printer.rb +++ b/app/models/printer/receipt_printer.rb @@ -117,4 +117,15 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker pdf.render_file "tmp/print_crm_order.pdf" self.print("tmp/print_crm_order.pdf") end + + #Queue No Print + def print_call_waiter(printer_settings,table,time,shop_detail) + #Use CUPS service + #Generate PDF + #Print + pdf = CallWaiterPdf.new(printer_settings,table,time,shop_detail) + pdf.render_file "tmp/print_call_waiter.pdf" + self.print("tmp/print_call_waiter.pdf") + end + end diff --git a/app/pdf/call_waiter_pdf.rb b/app/pdf/call_waiter_pdf.rb new file mode 100644 index 00000000..a1ea756b --- /dev/null +++ b/app/pdf/call_waiter_pdf.rb @@ -0,0 +1,71 @@ +class CallWaiterPdf < Prawn::Document + 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 + def initialize(printer_settings, table,time,shop_detail) + self.page_width = printer_settings.page_width + self.page_height = printer_settings.page_height + self.margin = 5 + self.price_width = 35 + self.qty_width = 20 + self.total_width = 35 + self.item_width = self.page_width - ((self.price_width + self.qty_width + self.total_width)) + self.item_height = 15 + self.item_description_width = (self.page_width-20) / 2 + self.label_width = 100 + + super(:margin => [self.margin, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height]) + + # 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 + + self.header_font_size = 10 + self.item_font_size = 8 + + header( shop_detail.name, printer_settings.name) + + call_waiter(table) + stroke_horizontal_rule + + # date_info(queue) + + end + + def header (shop_name, name) + text "#{shop_name}", :left_margin => -10, :size => self.header_font_size,:align => :center + text "#{name}", :size => self.header_font_size,:align => :center + # move_down self.item_height + move_down 5 + stroke_horizontal_rule + move_down 5 + end + + def call_waiter (table) + move_down 3 + text "Table Name : #{table.name}",:align => :center + end + + # def date_info(queue) + # move_down 5 + + # y_position = cursor + # bounding_box([0,y_position], :width =>self.label_width, :height => self.item_height) do + # text "Date:", :size => self.item_font_size,:align => :left + # end + # bounding_box([self.label_width,y_position], :width => self.item_width) do + # text "#{queue.created_at.strftime('%Y-%m-%d %I:%M %p')}" , :size => self.item_font_size,:align => :left + # end + + # move_down 5 + + # end + +end From aec3b17127bbb88dae0f96b16a19fc181ea98fe0 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Fri, 15 Dec 2017 17:58:38 +0630 Subject: [PATCH 09/84] upate call waiter print --- app/controllers/api/call_waiters_controller.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/api/call_waiters_controller.rb b/app/controllers/api/call_waiters_controller.rb index 4bd07570..a778af12 100644 --- a/app/controllers/api/call_waiters_controller.rb +++ b/app/controllers/api/call_waiters_controller.rb @@ -8,11 +8,11 @@ class Api::CallWaitersController < ActionController::API CallWaiterJob.perform_later(@table,@time) # get printer info - @shop = Shop::ShopDetail - unique_code = "CallWaiterPdf" - print_settings = PrintSetting.find_by_unique_code(unique_code) - printer = Printer::ReceiptPrinter.new(print_settings) - printer.print_call_waiter(print_settings,@table,@time,@shop) + # @shop = Shop::ShopDetail + # unique_code = "CallWaiterPdf" + # print_settings = PrintSetting.find_by_unique_code(unique_code) + # printer = Printer::ReceiptPrinter.new(print_settings) + # printer.print_call_waiter(print_settings,@table,@time,@shop) end From 368405451f8d00005534e618374b82b67de29079 Mon Sep 17 00:00:00 2001 From: Yan Date: Tue, 19 Dec 2017 11:49:03 +0630 Subject: [PATCH 10/84] need to fix license --- app/controllers/application_controller.rb | 3 +- app/controllers/base_controller.rb | 1 + app/models/license.rb | 38 ++++++++++++++++++++--- config/license.yml | 7 ++--- config/secrets.yml | 2 +- 5 files changed, 40 insertions(+), 11 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index fcca34a7..93652e52 100755 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -44,9 +44,8 @@ class ApplicationController < ActionController::Base end end - def current_license(url) + def current_license(url) @license = License.new(url) - if (@license.detail_with_local_file() == true) puts "RUN SAY BYAR" else diff --git a/app/controllers/base_controller.rb b/app/controllers/base_controller.rb index 9f0914c4..1bf5b4d4 100755 --- a/app/controllers/base_controller.rb +++ b/app/controllers/base_controller.rb @@ -1,4 +1,5 @@ class BaseController < ActionController::Base layout "installation" protect_from_forgery with: :exception + end diff --git a/app/models/license.rb b/app/models/license.rb index 0f2fd0ed..f5d7597a 100755 --- a/app/models/license.rb +++ b/app/models/license.rb @@ -69,11 +69,32 @@ class License # For Local System def detail_with_local_file() - has_license = true # verify_license() + aes = MyAesCrypt.new + aes_key, aes_iv = aes.export_key(lookup) + renewal_date_str = read_license("renewable_date") - if has_license - puts "VERIFIED" + # ##Check from local redis - if available load local otherwise get from remote + # renewable_date = "renewable_date:#{renewal_date_str}" + + # ##Get redis connection from connection pool + # redis = Redis.new + # cache_renewable_date = redis.get(renewable_date) + # if cache_renewable_date.nil? + # redis = Redis.new + # redis.set(renewable_date, Marshal.dump(@license)) + # else + # get_renewable_date = Marshal.load(cache_renewable_date) + if check_expiring(renewal_date_str) + return true + else + has_license = verify_license() + + if has_license + puts "VERIFIED" + return true + end end + # end end # License Activation @@ -115,6 +136,12 @@ class License return false end + # Check Expired before 30 days + def check_expiring(renewal_date_str) + renewal_date = DateTime.parse(renewal_date_str) + renewal_date > Date.today.advance(:days => 30) + end + # Check License expired date from PROVISION SERVER def check_expired(renewal_date_str) renewal_date = DateTime.parse(renewal_date_str) @@ -136,7 +163,7 @@ class License if File.exist?("config/license.yml") File.open("config/license.yml").each do |line| if line.include? (key) - decrypted_line_array = line.split(": ") + decrypted_line_array = line.split(": ") decrypted_line = AESCrypt.decrypt_data(decode_str(decrypted_line_array[1]), decode_str(ENV['AES_KEY']), decode_str(ENV['AES_IV']), ENV['CIPHER_TYPE']) end end @@ -185,6 +212,9 @@ class License f.puts("dbpassword: #{response_data['dbpassword']}") f.puts("api_token: #{response_data['api_token']}") f.puts("app_token: #{response_data['app_token']}") + f.puts("plan_sku: #{response_data['plan_sku']}") + f.puts("renewable_date: #{response_data['renewable_date']}") + f.puts("plan_name: #{response_data['plan_name']}") end rescue IOError response = { "status": false, "message": "Activation is success but something is wrong. \n Please contact code2lab call center!"} diff --git a/config/license.yml b/config/license.yml index 4a5c6b90..b96a0256 100644 --- a/config/license.yml +++ b/config/license.yml @@ -10,7 +10,6 @@ dbusername: LapN+Geriht8yk866FxNiQ== dbpassword: QtboWZ4ATE05vvYw6J+Uqw== api_token: nGyMizHtoVEFYCjSVEFJuzkxuBJwSsH app_token: QUdPwSakcsnuVLdfkXgGHhPMiIOcSSfaVwQyA - -plan_sku: 001 -renewable_date: 2018-12-14 -plan_name: Community +plan_sku: 9+83FZetcbLZi6COG5PbSw== +renewable_date: shztSYIsNmM9nlHkR/4exQ== +plan_name: LapN+Geriht8yk866FxNiQ== diff --git a/config/secrets.yml b/config/secrets.yml index 23c287ba..af242402 100755 --- a/config/secrets.yml +++ b/config/secrets.yml @@ -13,7 +13,7 @@ development: secret_key_base: b61d85f8ed2a1a9e0eeece3443b3e8f838d002cc1d9f32115d8e93db920e2957adfedc57501d44741211538f3108b742cdeada87d5bfae796c53da1f90a3cd61 sx_provision_url: 192.168.1.147:3002/api #connect.smartsales.asia/api #provision.zsai.ws/api - server_mode: cloud + server_mode: application cipher_type: AES-256-CBC sx_key: Wh@t1$C2L aes_key: <%= ENV['AES_KEY'] %> From 4e616ed5eb51ad892d5497dfec72fe040ca57de5 Mon Sep 17 00:00:00 2001 From: Yan Date: Tue, 19 Dec 2017 14:18:41 +0630 Subject: [PATCH 11/84] need to fix license --- app/models/license.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/models/license.rb b/app/models/license.rb index f5d7597a..4ff507c1 100755 --- a/app/models/license.rb +++ b/app/models/license.rb @@ -69,8 +69,8 @@ class License # For Local System def detail_with_local_file() - aes = MyAesCrypt.new - aes_key, aes_iv = aes.export_key(lookup) + # aes = MyAesCrypt.new + # aes_key, aes_iv = aes.export_key(lookup) renewal_date_str = read_license("renewable_date") # ##Check from local redis - if available load local otherwise get from remote @@ -163,7 +163,8 @@ class License if File.exist?("config/license.yml") File.open("config/license.yml").each do |line| if line.include? (key) - decrypted_line_array = line.split(": ") + decrypted_line_array = line.split(": ") + byebug decrypted_line = AESCrypt.decrypt_data(decode_str(decrypted_line_array[1]), decode_str(ENV['AES_KEY']), decode_str(ENV['AES_IV']), ENV['CIPHER_TYPE']) end end From d7a3ba700400d12b626bf0741cfed1b247c416e3 Mon Sep 17 00:00:00 2001 From: phyusin Date: Tue, 19 Dec 2017 16:01:45 +0630 Subject: [PATCH 12/84] change alert to swal in origami/Add to Existing --- app/views/origami/home/show.html.erb | 14 +++++++++++--- app/views/origami/rooms/show.html.erb | 16 ++++++++++++---- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/app/views/origami/home/show.html.erb b/app/views/origami/home/show.html.erb index 2946791f..22d909b9 100755 --- a/app/views/origami/home/show.html.erb +++ b/app/views/origami/home/show.html.erb @@ -491,7 +491,7 @@ window.location.href = '/origami/' + sale_id + '/other_charges' } else { - alert("Please select an table!"); + swal ( "Oops" , "Please select an table!" , "warning" ); } return false; @@ -510,7 +510,7 @@ window.location.href = '/origami/' + sale_id + '/discount' } else { - alert("Please select an table!"); + swal ( "Oops" , "Please select an table!" , "warning" ); } return false; @@ -584,8 +584,16 @@ url: ajax_url, data: 'dining_id=' + dining_id + "&sale_id=" + sale_id, success: function (result) { - alert("Invoice updated") + swal({ + title: "Information!", + text: "Invoice updated", + html: true, + closeOnConfirm: false, + closeOnCancel: false, + allowOutsideClick: false + }, function () { window.location.reload(); + }); } }); }) diff --git a/app/views/origami/rooms/show.html.erb b/app/views/origami/rooms/show.html.erb index 600eaf73..759a171c 100755 --- a/app/views/origami/rooms/show.html.erb +++ b/app/views/origami/rooms/show.html.erb @@ -498,7 +498,7 @@ $(document).ready(function(){ window.location.href = '/origami/' + sale_id + '/discount' } else { - alert("Please select an table!"); + swal ( "Oops" , "Please select an table!" , "warning" ); } return false; @@ -517,7 +517,7 @@ $(document).ready(function(){ window.location.href = '/origami/' + sale_id + '/other_charges' } else { - alert("Please select an table!"); + swal ( "Oops" , "Please select an table!" , "warning" ); } return false; @@ -600,8 +600,16 @@ $('#add_invoice').on('click',function(){ url: ajax_url, data: 'dining_id='+ dining_id + "&sale_id=" + sale_id, success:function(result){ - alert("Invoice updated") - window.location.reload(); + swal({ + title: "Information!", + text: "Invoice updated", + html: true, + closeOnConfirm: false, + closeOnCancel: false, + allowOutsideClick: false + }, function () { + window.location.reload(); + }); } }); }); From bba3aa763195cdd0decca95ac27e3b987228394f Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Tue, 19 Dec 2017 16:27:00 +0630 Subject: [PATCH 13/84] update all report generate and excel --- app/pdf/order_item_pdf.rb | 6 +++--- app/pdf/receipt_bill_pdf.rb | 6 +++--- app/views/reports/credit_payment/index.html.erb | 5 ++++- app/views/reports/payment_method/index.html.erb | 5 ++++- app/views/reports/receipt_no/index.html.erb | 5 ++++- app/views/reports/saleitem/index.html.erb | 7 +++++-- app/views/reports/shiftsale/index.html.erb | 5 ++++- app/views/reports/void_sale/index.html.erb | 5 ++++- 8 files changed, 31 insertions(+), 13 deletions(-) diff --git a/app/pdf/order_item_pdf.rb b/app/pdf/order_item_pdf.rb index 4bc57878..e27fdaf5 100755 --- a/app/pdf/order_item_pdf.rb +++ b/app/pdf/order_item_pdf.rb @@ -40,7 +40,7 @@ class OrderItemPdf < Prawn::Document text "#{ order_item.type + '-' + order_item.dining + print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 stroke_horizontal_rule - move_down 5 + move_down 3 #order_info order_info(order_item.order_id, order_item.order_by,order_item.order_at) @@ -56,13 +56,13 @@ class OrderItemPdf < Prawn::Document text "OrderNo: #{order_no} ", :size => self.item_font_size,:align => :left end - move_down 5 + move_down 2 y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do text "OrderBy: #{order_by} ", :size => self.item_font_size,:align => :left end - move_down 5 + move_down 2 y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do text "Date: #{order_at.utc.getlocal.strftime("%Y-%m-%d %I:%M %p")}", :size => self.item_font_size,:align => :left diff --git a/app/pdf/receipt_bill_pdf.rb b/app/pdf/receipt_bill_pdf.rb index dfd67d89..ede3fb26 100755 --- a/app/pdf/receipt_bill_pdf.rb +++ b/app/pdf/receipt_bill_pdf.rb @@ -4,7 +4,7 @@ class ReceiptBillPdf < Prawn::Document 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) self.page_width = printer_settings.page_width self.page_height = printer_settings.page_height - self.margin = 5 + self.margin = 0 self.price_width = 40 self.qty_width = 20 self.total_width = 40 @@ -20,7 +20,7 @@ class ReceiptBillPdf < Prawn::Document # @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]) + super(:margin => [20, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height]) # db font setup if printer_settings.font != "" @@ -74,7 +74,7 @@ class ReceiptBillPdf < Prawn::Document end def header (shop_details) - move_down 7 + 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 diff --git a/app/views/reports/credit_payment/index.html.erb b/app/views/reports/credit_payment/index.html.erb index 9037f03b..7c520fe3 100755 --- a/app/views/reports/credit_payment/index.html.erb +++ b/app/views/reports/credit_payment/index.html.erb @@ -123,7 +123,10 @@ function show_shift_name(period,period_type,from,to,shift_item){ var shift = $('#shift_name'); - + if (from == '' && to == '') { + from = $("#from").val(); + to = $("#to").val(); + } shift.empty(); var str = ''; diff --git a/app/views/reports/payment_method/index.html.erb b/app/views/reports/payment_method/index.html.erb index 2407e50a..0c48fe22 100755 --- a/app/views/reports/payment_method/index.html.erb +++ b/app/views/reports/payment_method/index.html.erb @@ -189,7 +189,10 @@ var shift = $('#shift_name'); shift.empty(); - + if (from == '' && to == '') { + from = $("#from").val(); + to = $("#to").val(); + } var str = ''; var param_shift = ''; var param_shift = '<%= params[:shift_name] rescue '-'%>'; diff --git a/app/views/reports/receipt_no/index.html.erb b/app/views/reports/receipt_no/index.html.erb index 00622069..e82c3e3c 100755 --- a/app/views/reports/receipt_no/index.html.erb +++ b/app/views/reports/receipt_no/index.html.erb @@ -196,7 +196,10 @@ var str = ''; var param_shift = ''; var param_shift = '<%= params[:shift_name] rescue '-'%>'; - + if (from == '' && to == '') { + from = $("#from").val(); + to = $("#to").val(); + } url = '<%= reports_get_shift_by_date_path %>'; $.get(url, {period :period, period_type :period_type, from :from, to :to, report_type :shift_item} , function(data){ diff --git a/app/views/reports/saleitem/index.html.erb b/app/views/reports/saleitem/index.html.erb index 97ba9c3f..d0def563 100644 --- a/app/views/reports/saleitem/index.html.erb +++ b/app/views/reports/saleitem/index.html.erb @@ -297,12 +297,15 @@ function show_shift_name(period,period_type,from,to,shift_item){ var shift = $('#shift_name'); - + if (from == '' && to == '') { + from = $("#from").val(); + to = $("#to").val(); + } shift.empty(); var selected = ''; var str = ''; var param_shift = '<%= params[:shift_name]%>'; - + url = '<%= reports_get_shift_by_date_path %>'; $.get(url, {period :period, period_type :period_type, from :from, to :to, report_type :shift_item} , function(data){ console.log(data) diff --git a/app/views/reports/shiftsale/index.html.erb b/app/views/reports/shiftsale/index.html.erb index 2aeac1e5..8138007d 100755 --- a/app/views/reports/shiftsale/index.html.erb +++ b/app/views/reports/shiftsale/index.html.erb @@ -191,7 +191,10 @@ function show_shift_name(period,period_type,from,to,shift_item){ var shift = $('#shift_name'); - + if (from == '' && to == '') { + from = $("#from").val(); + to = $("#to").val(); + } shift.empty(); var str = ''; diff --git a/app/views/reports/void_sale/index.html.erb b/app/views/reports/void_sale/index.html.erb index 3bc48410..045df74d 100755 --- a/app/views/reports/void_sale/index.html.erb +++ b/app/views/reports/void_sale/index.html.erb @@ -144,7 +144,10 @@ function show_shift_name(period,period_type,from,to,shift_item){ var shift = $('#shift_name'); - + if (from == '' && to == '') { + from = $("#from").val(); + to = $("#to").val(); + } shift.empty(); var str = ''; From 3be8a56ac68678a8140d9980ea6949bb53b11769 Mon Sep 17 00:00:00 2001 From: Yan Date: Tue, 19 Dec 2017 16:54:11 +0630 Subject: [PATCH 14/84] need to fix license --- app/controllers/application_controller.rb | 8 ++-- app/models/license.rb | 58 +++++++++++++++++++---- 2 files changed, 55 insertions(+), 11 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 93652e52..d10fbbf5 100755 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -46,10 +46,12 @@ class ApplicationController < ActionController::Base def current_license(url) @license = License.new(url) - if (@license.detail_with_local_file() == true) - puts "RUN SAY BYAR" + if (@license.detail_with_local_file() == 0) + puts "Expired or No License!" + elsif (@license.detail_with_local_file() == 2) + puts "Expiring! pls, license extend..." else - return nil + puts "RUN SAY BYAR" end end diff --git a/app/models/license.rb b/app/models/license.rb index 4ff507c1..e9922084 100755 --- a/app/models/license.rb +++ b/app/models/license.rb @@ -69,8 +69,17 @@ class License # For Local System def detail_with_local_file() - # aes = MyAesCrypt.new - # aes_key, aes_iv = aes.export_key(lookup) + # flag = ENV["AES_KEY"] + # # Check Exists IV + # if flag == "<%= ENV['AES_IV'] %>" + # # Export for Key + # aes = MyAesCrypt.new + # aes_key, aes_iv = aes.export_key(lookup) + # else + # aes_key = ENV["AES_KEY"] + # aes_iv = ENV["AES_IV"] + # end + renewal_date_str = read_license("renewable_date") # ##Check from local redis - if available load local otherwise get from remote @@ -84,14 +93,17 @@ class License # redis.set(renewable_date, Marshal.dump(@license)) # else # get_renewable_date = Marshal.load(cache_renewable_date) - if check_expiring(renewal_date_str) - return true + if check_expiring(renewal_date_str) + # return for all ok + return 1 else has_license = verify_license() if has_license - puts "VERIFIED" - return true + # return for expiring + return 2 + else + return 0 end end # end @@ -144,7 +156,13 @@ class License # Check License expired date from PROVISION SERVER def check_expired(renewal_date_str) + expired_date_str = read_license("renewable_date") + expired_date = DateTime.parse(expired_date_str) renewal_date = DateTime.parse(renewal_date_str) + if(renewal_date != expired_date){ + update_license("renewable_date", renewal_date_str) + } + if (renewal_date < Date.today) return true else @@ -163,8 +181,7 @@ class License if File.exist?("config/license.yml") File.open("config/license.yml").each do |line| if line.include? (key) - decrypted_line_array = line.split(": ") - byebug + decrypted_line_array = line.split(": ") decrypted_line = AESCrypt.decrypt_data(decode_str(decrypted_line_array[1]), decode_str(ENV['AES_KEY']), decode_str(ENV['AES_IV']), ENV['CIPHER_TYPE']) end end @@ -186,7 +203,32 @@ class License return decrypted_line end + # Update license file for line + def update_license(content, new_content) + if !new_content.include? "==" + str = encode_str(new_content) + crypted_str = AESCrypt.encrypt_data(str, ENV['AES_KEY'], ENV['AES_IV'], ENV['CIPHER_TYPE']) + end + + content_str = read_license_no_decrypt(content) + if File.exist?("config/license.yml") + file_str = File.read("config/license.yml") + new_file_str = file_str.gsub(content, crypted_str) + + # To write changes to the file, use: + # File.open("config/license.yml", "w") {|file| file.puts new_file_str } + + # File.open("config/license.yml").each do |line| + # new_file_str = line.gsub(content, crypted_str) + # f.put + # end + end + end + private + def encode_str(str) + return Base64.encode64(str) + end def decode_str(str) return Base64.decode64(str) From fce3785912e1b9c83b5da2e98dc2543c88e7fd64 Mon Sep 17 00:00:00 2001 From: phyusin Date: Wed, 20 Dec 2017 15:57:37 +0630 Subject: [PATCH 15/84] add order item and order summary slim pdf --- app/assets/javascripts/OQS.js | 7 +- .../channels/order_queue_station.js | 4 +- app/models/printer/order_queue_printer.rb | 10 +- app/models/sale_payment.rb | 8 +- app/pdf/order_item_pdf.rb | 20 ++- app/pdf/order_item_slim_pdf.rb | 129 +++++++++++++++ app/pdf/order_summary_pdf.rb | 12 +- app/pdf/order_summary_slim_pdf.rb | 155 ++++++++++++++++++ app/views/oqs/home/index.html.erb | 4 +- config/routes.rb | 2 +- 10 files changed, 321 insertions(+), 30 deletions(-) create mode 100644 app/pdf/order_item_slim_pdf.rb create mode 100644 app/pdf/order_summary_slim_pdf.rb diff --git a/app/assets/javascripts/OQS.js b/app/assets/javascripts/OQS.js index 64e207ab..6068b53f 100755 --- a/app/assets/javascripts/OQS.js +++ b/app/assets/javascripts/OQS.js @@ -61,7 +61,7 @@ $(document).on('turbolinks:load', function() { if (data[field]["options"] == "[]" || data[field]["options"] == "") { var options = ""; }else{ - var options = data.options; + var options = data[field]["options"]; } var date = new Date(data[field]["created_at"]); @@ -80,7 +80,7 @@ $(document).on('turbolinks:load', function() { +' [x'+ data[field]["qty"] +'] ' +'

' - +'

'+ options +'

' + +'

'+ options +'

' +'' +'Order at - ' @@ -223,8 +223,9 @@ $(document).on('turbolinks:load', function() { var params = { 'options':options }; $.ajax({ - type: 'GET', + type: 'POST', url: '/oqs/print/print/'+assigned_item_id, + data: params, success: function(data){ } }); }); diff --git a/app/assets/javascripts/channels/order_queue_station.js b/app/assets/javascripts/channels/order_queue_station.js index a95a0eb6..d2b502d4 100755 --- a/app/assets/javascripts/channels/order_queue_station.js +++ b/app/assets/javascripts/channels/order_queue_station.js @@ -14,7 +14,7 @@ App.order_queue_station = App.cable.subscriptions.create('OrderQueueStationChann if (items[field]["options"] == "[]" || items[field]["options"] == "") { var options = ""; }else{ - var options = items.options; + var options = items[field]["options"]; } //for count test = document.getElementsByClassName("oqs_count"); @@ -49,7 +49,7 @@ App.order_queue_station = App.cable.subscriptions.create('OrderQueueStationChann +' [x'+ items[field]["qty"] +'] ' +'

' - +'

'+ options +'

' + +'

'+ options +'

' +'' +'Order at - ' diff --git a/app/models/printer/order_queue_printer.rb b/app/models/printer/order_queue_printer.rb index 495bf85a..499c718d 100755 --- a/app/models/printer/order_queue_printer.rb +++ b/app/models/printer/order_queue_printer.rb @@ -12,7 +12,7 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker order_item = print_query('order_item', order_item_id) #OrderItem.find_by_item_code(item_code) - filename = "tmp/order_item.pdf" + filename = "tmp/order_item_#{order_id}_#{order_item_id}" + ".pdf" # check for item not to show # if order_item[0].price != 0 @@ -47,7 +47,7 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker # For Print Per Item if oqs.cut_per_item order.each do|odi| - filename = "tmp/order_item.pdf" + filename = "tmp/order_item_#{order_id}" + ".pdf" # For Item Options options = odi.options == "[]"? "" : odi.options @@ -68,7 +68,7 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker end # For Print Order Summary else - filename = "tmp/order_summary.pdf" + filename = "tmp/order_summary_#{order_id}" + ".pdf" pdf = OrderSummaryPdf.new(print_settings,order, print_status, order_items, oqs.use_alternate_name) pdf.render_file filename if oqs.print_copy @@ -96,7 +96,7 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker # For Print Per Item if oqs.cut_per_item order.each do|odi| - filename = "tmp/order_item.pdf" + filename = "tmp/order_item_#{booking_id}" + ".pdf" # For Item Options options = odi.options == "[]"? "" : odi.options @@ -120,7 +120,7 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker end # For Print Order Summary else - filename = "tmp/booking_summary.pdf" + filename = "tmp/booking_summary_#{booking_id}" + ".pdf" pdf = OrderSummaryPdf.new(print_settings,order, print_status,oqs.use_alternate_name) pdf.render_file filename if oqs.print_copy diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 06499c24..c4b4cee4 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -198,7 +198,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,1) return payment_status end @@ -290,7 +290,7 @@ class SalePayment < ApplicationRecord end - def sale_update_payment_status(paid_amount) + def sale_update_payment_status(paid_amount,check_foc = 0) #update amount_outstanding self.sale.amount_received = self.sale.amount_received.to_f + paid_amount.to_f self.sale.save! @@ -350,9 +350,9 @@ class SalePayment < ApplicationRecord self.sale.save! table_update_status(sObj) - # if paid_amount != "0.0" + if paid_amount != "0.0" || check_foc > 0 update_shift - # end + end end end diff --git a/app/pdf/order_item_pdf.rb b/app/pdf/order_item_pdf.rb index 4bc57878..f0b0cecb 100755 --- a/app/pdf/order_item_pdf.rb +++ b/app/pdf/order_item_pdf.rb @@ -105,18 +105,22 @@ class OrderItemPdf < Prawn::Document end if 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 + if !(order_item.alt_name).empty? + 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 + end end end - move_down 5 + if !options.empty? + move_down 5 - # add option - y_position = cursor - bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "#{options}", :size => self.item_font_size,:align => :left + # add option + y_position = cursor + bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do + text "#{options}", :size => self.item_font_size,:align => :left + end end move_down 5 diff --git a/app/pdf/order_item_slim_pdf.rb b/app/pdf/order_item_slim_pdf.rb new file mode 100644 index 00000000..6887d201 --- /dev/null +++ b/app/pdf/order_item_slim_pdf.rb @@ -0,0 +1,129 @@ +class OrderItemSlimPdf < 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 + def initialize(print_settings,order_item_slim, print_status, options, alt_name) + self.page_width = print_settings.page_width + self.page_height = print_settings.page_height + self.margin = 0 + self.price_width = 40 # No Need for item + self.qty_width = 40 + self.total_width = 40 # No Need for item + self.item_width = self.page_width - (self.qty_width - self.margin) + self.item_height = 15 + self.item_description_width = self.page_width - (self.price_width + self.qty_width + self.total_width) + self.label_width=90 + + super(:margin => [print_settings.heading_space, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height]) + # super(:margin => [10, 5, 30, 5], :page_size => [200,400]) + + # db font setup + if print_settings.font != "" + font_families.update("#{print_settings.font}" => { + :normal => "public/fonts/#{print_settings.font}.ttf", + :italic => "public/fonts/#{print_settings.font}.ttf", + :bold => "public/fonts/#{print_settings.font}.ttf", + :bold_italic => "public/fonts/#{print_settings.font}.ttf" + }) + + font "#{print_settings.font}" + fallback_fonts ["Courier", "Helvetica", "Times-Roman"] + + self.header_font_size = 11 + self.item_font_size = 9 + else + self.header_font_size = 12 + self.item_font_size = 10 + end + # font "public/fonts/Zawgyi-One.ttf" + # font "public/fonts/padauk.ttf" + #font "public/fonts/Chinese.ttf" + + text "#{ order_item_slim.type + '-' + order_item_slim.dining + print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 + stroke_horizontal_rule + move_down 1 + + #order_info + order_info(order_item_slim.order_id, order_item_slim.order_by,order_item_slim.order_at) + + # order items slim + order_items_slim(order_item_slim, options, alt_name, print_settings.precision) + end + + # Write Order Information to PDF + def order_info(order_no, order_by, order_at) + y_position = cursor + bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do + text "OrderNo: #{order_no} ", :size => self.item_font_size,:align => :left + end + + move_down 1 + y_position = cursor + bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do + text "OrderBy: #{order_by} ", :size => self.item_font_size,:align => :left + end + + move_down 1 + y_position = cursor + bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do + text "Date: #{order_at.utc.getlocal.strftime("%Y-%m-%d %I:%M %p")}", :size => self.item_font_size,:align => :left + end + + stroke_horizontal_rule + + move_down 3 + end + + # Write Order items to PDF + def order_items_slim(order_item_slim, options, alt_name, precision) + y_position = cursor + + #Add Order Item + add_order_items_slim(order_item_slim, options, alt_name, precision) + + dash(1, :space => 1, :phase => 1) + stroke_horizontal_line 0, (self.page_width - self.margin) + move_down 1 + end + + # Add order items slim under order info + def add_order_items_slim(order_item_slim, options, alt_name, precision) + y_position = cursor + + move_down 1 + + bounding_box([0,y_position], :width => self.item_width) do + text "#{order_item_slim.item_name}", :size => self.item_font_size,:align => :left + end + + bounding_box([self.item_width,y_position], :width => self.qty_width) do + text "[#{number_with_precision(order_item_slim.qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left + end + + bounding_box([0,y_position], :width => self.item_width) do + text "#{order_item_slim.item_name}", :size => self.item_font_size,:align => :left + + end + + # if alt_name + # if !(order_item_slim.alt_name).empty? + # 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 + # end + # end + # end + + if !options.empty? + move_down 1 + + # add option + y_position = cursor + bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do + text "#{options}", :size => self.item_font_size,:align => :left + end + end + move_down 1 + + end + +end diff --git a/app/pdf/order_summary_pdf.rb b/app/pdf/order_summary_pdf.rb index ea0d4502..f48564a9 100755 --- a/app/pdf/order_summary_pdf.rb +++ b/app/pdf/order_summary_pdf.rb @@ -122,19 +122,21 @@ class OrderSummaryPdf < Prawn::Document end if alt_name - move_down 4 - font("public/fonts/NotoSansCJKtc-Regular.ttf") do - text "(#{odi.alt_name})", :size => self.item_font_size,:align => :left, :inline_format => true + if !(odi.alt_name).empty? + move_down 4 + font("public/fonts/NotoSansCJKtc-Regular.ttf") do + text "(#{odi.alt_name})", :size => self.item_font_size,:align => :left, :inline_format => true + end end end - move_down 5 - # add option options = odi.options == "[]"? "" : odi.options if options != "" + move_down 5 + y_position = cursor bounding_box([0,y_position], :width => self.item_width) do text "#{options}", :size => self.item_font_size,:align => :left diff --git a/app/pdf/order_summary_slim_pdf.rb b/app/pdf/order_summary_slim_pdf.rb new file mode 100644 index 00000000..87aba403 --- /dev/null +++ b/app/pdf/order_summary_slim_pdf.rb @@ -0,0 +1,155 @@ +class OrderSummarySlimPdf < 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 + def initialize(print_settings,order, print_status, order_items = nil,alt_name) + self.page_width = print_settings.page_width + self.page_height = print_settings.page_height + self.margin = 0 + self.price_width = 40 # No Need for item + self.qty_width = 40 + self.total_width = 40 # No Need for item + self.item_width = self.page_width - (self.qty_width - self.margin) + self.item_height = 15 + self.item_description_width = self.page_width - (self.price_width + self.qty_width + self.total_width) + self.label_width=90 + + super(:margin => [print_settings.heading_space, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height]) + + # db font setup + if print_settings.font != "" + font_families.update("#{print_settings.font}" => { + :normal => "public/fonts/#{print_settings.font}.ttf", + :italic => "public/fonts/#{print_settings.font}.ttf", + :bold => "public/fonts/#{print_settings.font}.ttf", + :bold_italic => "public/fonts/#{print_settings.font}.ttf" + }) + + font "#{print_settings.font}" + fallback_fonts ["Courier", "Helvetica", "Times-Roman"] + + self.header_font_size = 11 + self.item_font_size = 9 + else + self.header_font_size = 12 + self.item_font_size = 10 + end + + # font "public/fonts/Zawgyi-One.ttf" + # font "public/fonts/padauk.ttf" + + text "#{ order[0].type + '-' + order[0].dining + print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 + stroke_horizontal_rule + move_down 1 + + #order_info + order_info(order[0].order_id, order[0].order_by,order[0].order_at) + + # order items + if order_items == nil + order_items(order, alt_name, print_settings.precision) + else + order_items(order_items, alt_name, print_settings.precision) + end + end + + # Write Order Information to PDF + def order_info(order_no, order_by, order_at) + y_position = cursor + bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do + text "OrderNo: #{order_no} ", :size => self.item_font_size,:align => :left + end + + move_down 1 + y_position = cursor + bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do + text "OrderBy: #{order_by} ", :size => self.item_font_size,:align => :left + end + + move_down 1 + y_position = cursor + bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do + text "Date: #{order_at.utc.getlocal.strftime("%Y-%m-%d %I:%M %p")}", :size => self.item_font_size,:align => :left + end + + stroke_horizontal_rule + + move_down 1 + end + + # Write Order items to PDF + def order_items(order_item, alt_name, precision) + y_position = cursor + + bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do + text "Item", :size => self.item_font_size,:align => :left + end + + bounding_box([self.item_width,y_position], :width => self.qty_width, :height => self.item_height) do + text "Qty", :size => self.item_font_size,:align => :left + end + + stroke_horizontal_rule + move_down 1 + + #Add Order Item + add_order_items(order_item, alt_name, precision) + + end + + # Add order items under order info + def add_order_items(order_item, alt_name, precision) + y_position = cursor + + move_down 1 + + order_item.each do|odi| + # check for item not to show + # if odi.price != 0 + y_position = cursor + + bounding_box([0,y_position], :width => self.item_width) do + text "#{odi.item_name}", :size => self.item_font_size,:align => :left + + end + + bounding_box([self.item_width,y_position], :width => self.qty_width) do + text "#{number_with_precision(odi.qty, :precision => precision.to_i)}", :size => self.item_font_size,:align => :left + end + + bounding_box([0,y_position], :width => self.item_width) do + text "#{odi.item_name}", :size => self.item_font_size,:align => :left + + end + + if alt_name + if !(odi.alt_name).empty? + move_down 1 + font("public/fonts/NotoSansCJKtc-Regular.ttf") do + text "(#{odi.alt_name})", :size => self.item_font_size,:align => :left, :inline_format => true + end + end + end + + # add option + options = odi.options == "[]"? "" : odi.options + + if options != "" + move_down 1 + + y_position = cursor + bounding_box([0,y_position], :width => self.item_width) do + text "#{options}", :size => self.item_font_size,:align => :left + end + + move_down 1 + end + + move_down 1 + + dash(1, :space => 1, :phase => 1) + stroke_horizontal_line 0, (self.page_width - self.margin) + move_down 1 + # end + end + end +end diff --git a/app/views/oqs/home/index.html.erb b/app/views/oqs/home/index.html.erb index 7f7f2d24..f5868fa5 100755 --- a/app/views/oqs/home/index.html.erb +++ b/app/views/oqs/home/index.html.erb @@ -84,8 +84,8 @@ <%= qid.qty %> ]

- -

<%= qid.options == "[]"? "" : qid.options %>

+ +

<%= qid.options == "[]"? "" : qid.options %>

Order at - diff --git a/config/routes.rb b/config/routes.rb index 4c302b94..a0db7858 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -244,7 +244,7 @@ scope "(:locale)", locale: /en|mm/ do post "/:id", to: "edit#update" # Pass assigned_order_item_id - get 'print/print/:id', to: "print#print" + post 'print/print/:id', to: "print#print" get 'print/print_order_summary/:id', to: "print#print_order_summary" get "/get_items/:id" => "home#get_items_by_oqs", :as => "get_order_items_by_oqs" From 643cfaa1796e3d8cab13831e64ce5d59d60060ff Mon Sep 17 00:00:00 2001 From: phyusin Date: Wed, 20 Dec 2017 16:20:43 +0630 Subject: [PATCH 16/84] change sale payment for paid_amount=0 --- app/models/sale_payment.rb | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index c4b4cee4..14740851 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -179,7 +179,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,true) return payment_status end @@ -198,7 +198,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,1) + sale_update_payment_status(self.received_amount) return payment_status end @@ -290,7 +290,7 @@ class SalePayment < ApplicationRecord end - def sale_update_payment_status(paid_amount,check_foc = 0) + def sale_update_payment_status(paid_amount,check_foc = false) #update amount_outstanding self.sale.amount_received = self.sale.amount_received.to_f + paid_amount.to_f self.sale.save! @@ -350,7 +350,12 @@ class SalePayment < ApplicationRecord self.sale.save! table_update_status(sObj) - if paid_amount != "0.0" || check_foc > 0 + puts "check_foc" + puts check_foc + + if check_foc + update_shift + elsif paid_amount != "0.0" update_shift end end From 589492ee492d005f05c37ef62d622930ae01dac3 Mon Sep 17 00:00:00 2001 From: phyusin Date: Wed, 20 Dec 2017 16:21:44 +0630 Subject: [PATCH 17/84] remove puts in sale payment --- app/models/sale_payment.rb | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 14740851..5ab270b3 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -349,9 +349,6 @@ class SalePayment < ApplicationRecord self.sale.save! table_update_status(sObj) - - puts "check_foc" - puts check_foc if check_foc update_shift From 802b51eab45b31a7f743b95265dce1f9f093f81a Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Wed, 20 Dec 2017 17:11:27 +0630 Subject: [PATCH 18/84] update roundign adj and member discount in first bill --- app/controllers/origami/home_controller.rb | 4 + .../origami/payments_controller.rb | 43 +++++--- app/pdf/receipt_bill_pdf.rb | 2 +- app/views/origami/home/show.html.erb | 97 ++++++++++++++++--- app/views/origami/payments/show.html.erb | 8 +- 5 files changed, 122 insertions(+), 32 deletions(-) diff --git a/app/controllers/origami/home_controller.rb b/app/controllers/origami/home_controller.rb index 47ec2383..d3c1db70 100755 --- a/app/controllers/origami/home_controller.rb +++ b/app/controllers/origami/home_controller.rb @@ -22,6 +22,10 @@ class Origami::HomeController < BaseOrigamiController @status_sale = "" @sale_array = Array.new + @shop = Shop::ShopDetail + @membership = MembershipSetting.find_by_discount(1) + @payment_methods = PaymentMethodSetting.all + @dining.bookings.active.each do |booking| if booking.sale_id.nil? && booking.booking_status != 'moved' @order_items = Array.new diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index eecb8dcf..b01ff09a 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -26,7 +26,21 @@ class Origami::PaymentsController < BaseOrigamiController #shop detail shop_details = Shop::ShopDetail # customer= Customer.where('customer_id=' +.customer_id) - customer= Customer.find(sale_data.customer_id) + customer = Customer.find(sale_data.customer_id) + + # rounding adjustment + if shop_details.is_rounding_adj + a = sale_data.grand_total % 25 + b = sale_data.grand_total / 25 + + if (a != 0.0 && b%2 != 0.0) || (a==0.0 && b%2 !=0) + new_total = Sale.get_rounding_adjustment(sale_data.grand_total) + rounding_adj = new_total-sale_data.grand_total + sale_data.update_attributes(grand_total: new_total,old_grand_total: sale_data.grand_total,rounding_adjustment:rounding_adj) + end + end + #end rounding adjustment + # get member information rebate = MembershipSetting.find_by_rebate(1) if customer.membership_id != nil && rebate @@ -59,9 +73,13 @@ class Origami::PaymentsController < BaseOrigamiController # 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) + a = saleObj.grand_total % 25 + b = saleObj.grand_total / 25 + if (a != 0.0 && b%2 != 0.0) || (a==0.0 && b%2 !=0) + 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 end #end rounding adjustment @@ -278,14 +296,13 @@ class Origami::PaymentsController < BaseOrigamiController @shop = Shop.find_by_id(1) if @shop.is_rounding_adj - new_total = Sale.get_rounding_adjustment(saleObj.grand_total) - else - new_total = saleObj.grand_total + a = saleObj.grand_total % 25 + b = saleObj.grand_total / 25 + if (a != 0.0 && b%2 != 0.0) || (a==0.0 && b%2 !=0) + 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 end - - 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 -end +end \ No newline at end of file diff --git a/app/pdf/receipt_bill_pdf.rb b/app/pdf/receipt_bill_pdf.rb index ede3fb26..107e3163 100755 --- a/app/pdf/receipt_bill_pdf.rb +++ b/app/pdf/receipt_bill_pdf.rb @@ -20,7 +20,7 @@ class ReceiptBillPdf < Prawn::Document # @double = @qty_width * 1.3 # @half_qty = @qty_width / 2 #setting page margin and width - super(:margin => [20, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height]) + super(:margin => [printer_settings.heading_space, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height]) # db font setup if printer_settings.font != "" diff --git a/app/views/origami/home/show.html.erb b/app/views/origami/home/show.html.erb index 2946791f..5dd6034c 100755 --- a/app/views/origami/home/show.html.erb +++ b/app/views/origami/home/show.html.erb @@ -1,4 +1,7 @@
+
@@ -264,7 +267,7 @@ - + <% if @obj_sale != nil && @obj_sale.discount_type == 'member_discount' %> @@ -291,7 +294,8 @@ + <%= @obj_sale.rounding_adjustment + %> @@ -387,8 +391,12 @@ - - + + <%if @membership.discount && @obj_sale.customer.membership_id %> + + <%else%> + + <%end%> <% end %> @@ -398,6 +406,34 @@ <% else %> <% end %> + + + + @@ -516,20 +552,53 @@ return false; }); }); - // Print for first bill $("#first_bill").on('click', function () { var sale_id = $('#sale_id').val(); - var ajax_url = "/origami/sale/" + sale_id + "/first_bill"; - - $.ajax({ - type: "GET", - url: ajax_url, - success: function (result) { - location.reload(); - } - }); + var ajax_url = "/origami/sale/" + sale_id + "/first_bill"; + $.ajax({ + type: "GET", + url: ajax_url, + success: function (result) { + location.reload(); + } + }); }); + $(".choose_payment").on('click', function () { + $( "#loading_wrapper").show(); + + var sale_id = $('#sale_id').val(); + type = $('.payment_method').val(); + + calculate_member_discount(sale_id,type); + + var ajax_url = "/origami/sale/" + sale_id + "/first_bill"; + $.ajax({ + type: "GET", + url: ajax_url, + success: function (result) { + $( "#loading_wrapper" ).hide(); + location.reload(); + } + }); + }); + function calculate_member_discount(sale_id,type) { + var sub_total = $('#sub-total').text(); + if (type == "Cash") { + is_card = false + }else{ + is_card = true + } + $.ajax({ + type: "POST", + url: "/origami/" + sale_id + "/member_discount", + data: {'sale_id':sale_id, 'sub_total':sub_total,'is_card':is_card }, + async: false, + success:function(result){ + } + }); + + } // $('#pay').on('click', function () { // var sale_id = $('#sale_id').val(); diff --git a/app/views/origami/payments/show.html.erb b/app/views/origami/payments/show.html.erb index 7359397a..43eb3248 100755 --- a/app/views/origami/payments/show.html.erb +++ b/app/views/origami/payments/show.html.erb @@ -94,11 +94,11 @@ - + - + <%if @balance > 0%> @@ -124,7 +124,7 @@
- <%= @sale_data.grand_total + @rounding_adj rescue 0%> + <%= @sale_data.grand_total rescue 0%>
@@ -223,7 +223,7 @@
Balance
-
<%= @sale_data.grand_total+ @rounding_adj rescue 0 %>
+
<%= @sale_data.grand_total rescue 0 %>
From e0d97470cc0489a6ad85b3a307f6bfa6d9350654 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Thu, 21 Dec 2017 10:35:09 +0630 Subject: [PATCH 19/84] update membership discount firstbill --- app/controllers/origami/home_controller.rb | 3 +- .../origami/payments_controller.rb | 4 +- app/controllers/origami/rooms_controller.rb | 3 + app/models/membership_setting.rb | 1 + app/views/origami/rooms/show.html.erb | 75 ++++++++++++++++++- 5 files changed, 80 insertions(+), 6 deletions(-) diff --git a/app/controllers/origami/home_controller.rb b/app/controllers/origami/home_controller.rb index d3c1db70..50944b39 100755 --- a/app/controllers/origami/home_controller.rb +++ b/app/controllers/origami/home_controller.rb @@ -23,9 +23,8 @@ class Origami::HomeController < BaseOrigamiController @sale_array = Array.new @shop = Shop::ShopDetail - @membership = MembershipSetting.find_by_discount(1) + @membership = MembershipSetting::MembershipSetting @payment_methods = PaymentMethodSetting.all - @dining.bookings.active.each do |booking| if booking.sale_id.nil? && booking.booking_status != 'moved' @order_items = Array.new diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index b01ff09a..d307cc5d 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -296,8 +296,8 @@ class Origami::PaymentsController < BaseOrigamiController @shop = Shop.find_by_id(1) if @shop.is_rounding_adj - a = saleObj.grand_total % 25 - b = saleObj.grand_total / 25 + a = saleObj.grand_total % 25 # + b = saleObj.grand_total / 25 # if (a != 0.0 && b%2 != 0.0) || (a==0.0 && b%2 !=0) new_total = Sale.get_rounding_adjustment(saleObj.grand_total) rounding_adj = new_total-saleObj.grand_total diff --git a/app/controllers/origami/rooms_controller.rb b/app/controllers/origami/rooms_controller.rb index 6c0b98c8..4009666a 100755 --- a/app/controllers/origami/rooms_controller.rb +++ b/app/controllers/origami/rooms_controller.rb @@ -19,6 +19,9 @@ class Origami::RoomsController < BaseOrigamiController @status_sale = "" @sale_array = Array.new + @shop = Shop::ShopDetail + @membership = MembershipSetting::MembershipSetting + @payment_methods = PaymentMethodSetting.all @room.bookings.active.each do |booking| if booking.sale_id.nil? && booking.booking_status != 'moved' @order_items = Array.new diff --git a/app/models/membership_setting.rb b/app/models/membership_setting.rb index 89f9eb14..3b60c781 100755 --- a/app/models/membership_setting.rb +++ b/app/models/membership_setting.rb @@ -1,2 +1,3 @@ class MembershipSetting < ApplicationRecord + MembershipSetting = MembershipSetting.find_by_id(1) end diff --git a/app/views/origami/rooms/show.html.erb b/app/views/origami/rooms/show.html.erb index 759a171c..d4869a6a 100755 --- a/app/views/origami/rooms/show.html.erb +++ b/app/views/origami/rooms/show.html.erb @@ -1,4 +1,7 @@
+
@@ -260,7 +263,7 @@
Sub Total:<%= sub_total %><%= sub_total %>
Rounding Adj: - <%= @obj_sale.rounding_adjustment rescue 0 %>
Grand Total:
Rounding Adj:<%=@rounding_adj rescue 0%><%= @sale_data.rounding_adjustment rescue 0%>
Grand Total<%=@sale_data.grand_total+ @rounding_adj rescue 0%><%=@sale_data.grand_total rescue 0%>
- + <%if @obj_sale != nil && @obj_sale.discount_type == 'member_discount'%> @@ -369,10 +372,43 @@ - + <%if @membership.discount && @obj_sale.customer.membership_id %> + + <%else%> + + <%end%> <% end %> + + + + + @@ -538,6 +574,41 @@ $("#first_bill").on('click', function(){ }); }); +$(".choose_payment").on('click', function () { + $( "#loading_wrapper").show(); + var sale_id = $('#sale_id').val(); + type = $('.payment_method').val(); + + calculate_member_discount(sale_id,type); + + var ajax_url = "/origami/sale/" + sale_id + "/first_bill"; + $.ajax({ + type: "GET", + url: ajax_url, + success: function (result) { + $( "#loading_wrapper" ).hide(); + location.reload(); + } + }); +}); +function calculate_member_discount(sale_id,type) { + var sub_total = $('#sub-total').text(); + if (type == "Cash") { + is_card = false + }else{ + is_card = true +} +$.ajax({ + type: "POST", + url: "/origami/" + sale_id + "/member_discount", + data: {'sale_id':sale_id, 'sub_total':sub_total,'is_card':is_card }, + async: false, + success:function(result){ + } +}); + +} + $('#pay').on('click',function() { var sale_id = $('#sale_id').val(); var url = '/origami/sale/'+ sale_id + "/rounding_adj" ; From 90e7327bfe1ec0cc1bba083f4c637a356f389f40 Mon Sep 17 00:00:00 2001 From: phyusin Date: Thu, 21 Dec 2017 10:37:01 +0630 Subject: [PATCH 20/84] add global variable in origami js --- app/assets/javascripts/origami.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/assets/javascripts/origami.js b/app/assets/javascripts/origami.js index f23d13c6..802d676e 100755 --- a/app/assets/javascripts/origami.js +++ b/app/assets/javascripts/origami.js @@ -15,6 +15,8 @@ //= require BSBMaterial/demo.js //= require custom.js +var _FIRST_BILL_ = ""; + $(document).on('turbolinks:load', function() { $('.datetimepicker').bootstrapMaterialDatePicker({ format: 'DD-MM-YYYY - HH:mm', From 12f5e42d44418b0b4419bb05fef8ce76df8e17c3 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Thu, 21 Dec 2017 10:49:25 +0630 Subject: [PATCH 21/84] update comment for rounding adj --- app/controllers/origami/home_controller.rb | 1 + .../origami/payments_controller.rb | 21 ++++++++++++------- app/controllers/origami/rooms_controller.rb | 1 + 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/app/controllers/origami/home_controller.rb b/app/controllers/origami/home_controller.rb index 50944b39..fdf00b29 100755 --- a/app/controllers/origami/home_controller.rb +++ b/app/controllers/origami/home_controller.rb @@ -25,6 +25,7 @@ class Origami::HomeController < BaseOrigamiController @shop = Shop::ShopDetail @membership = MembershipSetting::MembershipSetting @payment_methods = PaymentMethodSetting.all + @dining.bookings.active.each do |booking| if booking.sale_id.nil? && booking.booking_status != 'moved' @order_items = Array.new diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index d307cc5d..2c0de0f7 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -30,9 +30,10 @@ class Origami::PaymentsController < BaseOrigamiController # rounding adjustment if shop_details.is_rounding_adj - a = sale_data.grand_total % 25 - b = sale_data.grand_total / 25 - + a = sale_data.grand_total % 25 # Modulus + b = sale_data.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(sale_data.grand_total) rounding_adj = new_total-sale_data.grand_total @@ -73,8 +74,10 @@ class Origami::PaymentsController < BaseOrigamiController # rounding adjustment if shop_details.is_rounding_adj - a = saleObj.grand_total % 25 - b = saleObj.grand_total / 25 + a = saleObj.grand_total % 25 # Modulus + b = saleObj.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(saleObj.grand_total) rounding_adj = new_total-saleObj.grand_total @@ -296,9 +299,11 @@ class Origami::PaymentsController < BaseOrigamiController @shop = Shop.find_by_id(1) if @shop.is_rounding_adj - a = saleObj.grand_total % 25 # - b = saleObj.grand_total / 25 # - if (a != 0.0 && b%2 != 0.0) || (a==0.0 && b%2 !=0) + a = saleObj.grand_total % 25 # Modulus + b = saleObj.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(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) diff --git a/app/controllers/origami/rooms_controller.rb b/app/controllers/origami/rooms_controller.rb index 4009666a..5e5b42cb 100755 --- a/app/controllers/origami/rooms_controller.rb +++ b/app/controllers/origami/rooms_controller.rb @@ -22,6 +22,7 @@ class Origami::RoomsController < BaseOrigamiController @shop = Shop::ShopDetail @membership = MembershipSetting::MembershipSetting @payment_methods = PaymentMethodSetting.all + @room.bookings.active.each do |booking| if booking.sale_id.nil? && booking.booking_status != 'moved' @order_items = Array.new From 11b8466e104780466ab65175e32c5f57d0a3d7b1 Mon Sep 17 00:00:00 2001 From: phyusin Date: Thu, 21 Dec 2017 15:11:11 +0630 Subject: [PATCH 22/84] check first bill or not --- app/assets/javascripts/origami.js | 41 ++++++++++++++++++++++-- app/views/origami/home/show.html.erb | 41 +++++++++++++++++------- app/views/origami/payments/show.html.erb | 6 ++++ app/views/origami/rooms/show.html.erb | 17 ++++++++++ 4 files changed, 91 insertions(+), 14 deletions(-) diff --git a/app/assets/javascripts/origami.js b/app/assets/javascripts/origami.js index 802d676e..c11df647 100755 --- a/app/assets/javascripts/origami.js +++ b/app/assets/javascripts/origami.js @@ -15,8 +15,6 @@ //= require BSBMaterial/demo.js //= require custom.js -var _FIRST_BILL_ = ""; - $(document).on('turbolinks:load', function() { $('.datetimepicker').bootstrapMaterialDatePicker({ format: 'DD-MM-YYYY - HH:mm', @@ -145,3 +143,42 @@ $(document).on('turbolinks:load', function() { return false; }); }); + +/* start check first bill or not funs: */ +function checkReceiptNoInFirstBillData(receipt_no) { + var status = false; + if((receipt_no!=undefined) && (receipt_no!="")){ + var arr_data = JSON.parse(localStorage.getItem("receipt_lists")); + if((arr_data!=undefined) && (arr_data!=null)){ + var json_data = arr_data.filter(function(e) { return e.receipt_no !== receipt_no }); + if((arr_data.length) > (json_data.length)){ + status = true; + } + } + } + + return status; +} + +function createReceiptNoInFirstBillData(receipt_no) { + var arr_data = []; + var json_data = []; + var receipt_lists = localStorage.getItem("receipt_lists"); + if((receipt_lists!=undefined) && (receipt_lists!=null) && (receipt_lists!="")){ + arr_data = JSON.parse(localStorage.getItem("receipt_lists")); + json_data = arr_data.filter(function(e) { return e.receipt_no == receipt_no }); + } + if(((arr_data.length == 0) && (json_data.length == 0)) || ((arr_data.length > 0) && (json_data.length == 0))){ + arr_data.push({receipt_no}); + localStorage.setItem("receipt_lists",JSON.stringify(arr_data)); + } +} + +function deleteReceiptNoInFirstBillData(receipt_no) { + var arr_data = JSON.parse(localStorage.getItem("receipt_lists")); + if((arr_data!=undefined) && (arr_data!=null)){ + var json_data = arr_data.filter(function(e) { return e.receipt_no !== receipt_no }); + localStorage.setItem("receipt_lists",JSON.stringify(json_data)); + } +} +/* end check first bill or not funs: */ \ No newline at end of file diff --git a/app/views/origami/home/show.html.erb b/app/views/origami/home/show.html.erb index b65deb7d..68c43ad8 100755 --- a/app/views/origami/home/show.html.erb +++ b/app/views/origami/home/show.html.erb @@ -156,8 +156,7 @@
  Receipt No: <% if @status_sale == 'sale' %> - <%= @sale_array[0].receipt_no rescue '' %> - + <%= @sale_array[0].receipt_no rescue '' %> <% end %>
@@ -439,6 +438,18 @@
From 3878f1644b108495eef0e32f5d958ec41706c09a Mon Sep 17 00:00:00 2001 From: phyusin Date: Thu, 21 Dec 2017 18:13:24 +0630 Subject: [PATCH 32/84] change UI for menu cats: --- app/views/settings/menu_categories/index.html.erb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/views/settings/menu_categories/index.html.erb b/app/views/settings/menu_categories/index.html.erb index 870c19bc..8d8c044c 100755 --- a/app/views/settings/menu_categories/index.html.erb +++ b/app/views/settings/menu_categories/index.html.erb @@ -30,7 +30,7 @@
- + @@ -43,7 +43,7 @@ - + @@ -51,8 +51,8 @@ <% end %>
Sub Total:<%= sub_total %><%= sub_total %>
<%= t("views.right_panel.detail.name") %> <%= t("views.right_panel.detail.alt_name") %> <%= t("views.right_panel.detail.is_available") %><%= t("views.right_panel.detail.order_by") %> <%= t("views.right_panel.detail.parent") %> <%= t("views.right_panel.detail.actions") %>
<%= link_to settings_menu_category.name, settings_menu_category_path(settings_menu_category) %> <%= settings_menu_category.alt_name rescue ''%> <%= settings_menu_category.is_available rescue false%><%= settings_menu_category.order_by rescue ''%> <%= settings_menu_category.parent.name rescue ''%> <%= link_to t("views.btn.edit"), edit_settings_menu_category_path(settings_menu_category),:class => 'btn btn-info btn-sm waves-effect' %>
+ <%= paginate @settings_menu_categories, param_name: :page, :outer_window => 3 %>
- <%= paginate @settings_menu_categories, param_name: :page, :outer_window => 3 %>
From a10a41f3ed002df67d0f5cba2a224a2fecf03df7 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Thu, 21 Dec 2017 19:16:53 +0630 Subject: [PATCH 33/84] update romm show page --- app/views/origami/rooms/show.html.erb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/views/origami/rooms/show.html.erb b/app/views/origami/rooms/show.html.erb index d4869a6a..41d7f612 100755 --- a/app/views/origami/rooms/show.html.erb +++ b/app/views/origami/rooms/show.html.erb @@ -186,7 +186,7 @@
<% if @status_sale == 'sale' %> - +   Customer : <%= @obj_sale.customer.name rescue '-' %> <%else%> @@ -361,7 +361,8 @@ - <% else %> + <% end %> + <% if @status_sale == 'sale' %> From 7d8fddbdeb793486b9bbc0db3ff6bb28ca0fc6ad Mon Sep 17 00:00:00 2001 From: phyusin Date: Fri, 22 Dec 2017 14:43:59 +0630 Subject: [PATCH 34/84] check order by and code for menu cats: --- app/pdf/receipt_bill_pdf.rb | 21 +++++++++++++------ .../api/restaurant/menu/_menu.json.jbuilder | 2 ++ app/views/print_settings/_form.html.erb | 8 +++++-- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/app/pdf/receipt_bill_pdf.rb b/app/pdf/receipt_bill_pdf.rb index 107e3163..14f05a00 100755 --- a/app/pdf/receipt_bill_pdf.rb +++ b/app/pdf/receipt_bill_pdf.rb @@ -5,12 +5,12 @@ class ReceiptBillPdf < Prawn::Document self.page_width = printer_settings.page_width self.page_height = printer_settings.page_height self.margin = 0 - self.price_width = 40 - self.qty_width = 20 - self.total_width = 40 + self.price_width = 50 + self.qty_width = 35 + self.total_width = 50 self.item_width = self.page_width - ((self.price_width + self.qty_width + self.total_width)) self.item_height = 15 - self.item_description_width = (self.page_width-20) / 2 + self.item_description_width = (self.page_width-5) / 2 self.label_width = 100 self.description_width = 150 @@ -22,6 +22,11 @@ class ReceiptBillPdf < Prawn::Document #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}" => { @@ -124,6 +129,8 @@ class ReceiptBillPdf < Prawn::Document end def line_items(sale_items,precision,delimiter) + item_label_total_front_width = (self.item_width+self.price_width) + 15 + item_label_total_end_width = self.total_width + 14 move_down 5 y_position = cursor move_down 5 @@ -132,7 +139,7 @@ class ReceiptBillPdf < Prawn::Document text_box "Items", :at =>[0,y_position], :width => self.item_width, :height =>self.item_height, :size => self.item_font_size, :overflow => :shrink_to_fix text_box "Price", :at =>[self.item_width,y_position], :width => self.price_width, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix text_box "Qty", :at =>[(self.item_width+self.price_width),y_position], :width => self.qty_width, :height =>self.item_height, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix - text_box "Total", :at =>[(self.item_width+self.price_width+4),y_position], :width => self.total_width+3, :height =>self.item_height, :size => self.item_font_size, :align => :right, :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 stroke_horizontal_rule @@ -141,6 +148,8 @@ class ReceiptBillPdf < Prawn::Document def add_line_item_row(sale_items,precision,delimiter) item_name_width = (self.item_width+self.price_width) + item_total_front_width = item_name_width + 15 + item_total_end_width = self.total_width + 14 y_position = cursor move_down 5 sub_total = 0.0 @@ -163,7 +172,7 @@ class ReceiptBillPdf < Prawn::Document # text_box "#{product_name}", :at =>[0,y_position], :width => self.item_width, :size => self.item_font_size text_box "#{number_with_precision(price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[self.item_width,y_position], :width => self.price_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix text_box "#{number_with_precision(qty, :precision => precision.to_i)}", :at =>[item_name_width,y_position], :width => self.qty_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix - text_box "#{number_with_precision(total_price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[(item_name_width+4),y_position], :width =>self.total_width+3, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix + text_box "#{number_with_precision(total_price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[item_total_front_width,y_position], :width =>item_total_end_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix } move_down 5 end diff --git a/app/views/api/restaurant/menu/_menu.json.jbuilder b/app/views/api/restaurant/menu/_menu.json.jbuilder index 9441daf9..cf046939 100755 --- a/app/views/api/restaurant/menu/_menu.json.jbuilder +++ b/app/views/api/restaurant/menu/_menu.json.jbuilder @@ -7,6 +7,8 @@ json.valid_time_to menu.valid_time_to.strftime("%H:%M") if (menu.menu_categories) json.categories menu.menu_categories do |category| json.id category.id + json.code category.code + json.order_by category.order_by json.name category.name json.alt_name category.alt_name json.parent_id category.menu_category_id diff --git a/app/views/print_settings/_form.html.erb b/app/views/print_settings/_form.html.erb index 51ee0eaa..201d1411 100755 --- a/app/views/print_settings/_form.html.erb +++ b/app/views/print_settings/_form.html.erb @@ -15,8 +15,8 @@ <%= f.input :api_settings %> <%= f.input :page_width %> <%= f.input :page_height %> - <%= f.input :print_copies, input_html: { min: '1', step: '1', :onkeypress => "return isNumberKey(event);", :onkeyup => "greaterThanOne(this.value);" } %> - <%= f.input :precision %> + <%= f.input :print_copies, input_html: { min: 1, step: '1', :onkeypress => "return isNumberKey(event);", :onkeyup => "greaterThanOne(this.value);" } %> + <%= f.input :precision, input_html: { min: 0, max: 2, :onkeypress => "return isNumberKey(event);", :onkeyup => "greaterThanThree(this.value);" } %> <%= f.input :delimiter %> <%= f.input :heading_space %>
@@ -73,4 +73,8 @@ function greaterThanOne(val){ if(parseInt(val)==0) $("#print_setting_print_copies").val(1); } + + function greaterThanThree(val){ + if(parseInt(val)>2) $("#print_setting_precision").val(2); + } \ No newline at end of file From dad83a1f83fc578c4d63c788088c47faceb39fbd Mon Sep 17 00:00:00 2001 From: phyusin Date: Fri, 22 Dec 2017 16:33:10 +0630 Subject: [PATCH 35/84] change receipt bill format --- app/pdf/receipt_bill_pdf.rb | 46 ++++++++++++++++++------- app/views/print_settings/_form.html.erb | 4 +-- 2 files changed, 35 insertions(+), 15 deletions(-) diff --git a/app/pdf/receipt_bill_pdf.rb b/app/pdf/receipt_bill_pdf.rb index 14f05a00..ae02b22d 100755 --- a/app/pdf/receipt_bill_pdf.rb +++ b/app/pdf/receipt_bill_pdf.rb @@ -5,10 +5,10 @@ class ReceiptBillPdf < Prawn::Document self.page_width = printer_settings.page_width self.page_height = printer_settings.page_height self.margin = 0 - self.price_width = 50 - self.qty_width = 35 - self.total_width = 50 - self.item_width = self.page_width - ((self.price_width + self.qty_width + self.total_width)) + 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 @@ -129,16 +129,26 @@ class ReceiptBillPdf < Prawn::Document end def line_items(sale_items,precision,delimiter) - item_label_total_front_width = (self.item_width+self.price_width) + 15 - item_label_total_end_width = self.total_width + 14 + if precision.to_i > 0 + item_label_qty_front_width = (self.item_width+self.price_width) + 5 + item_label_qty_end_width = self.qty_width + 4 + item_label_total_front_width = (self.item_width+self.price_width) + 10 + item_label_total_end_width = self.total_width + 9 + else + self.item_width = self.item_width.to_i + 8 + item_label_qty_front_width = (self.item_width+self.price_width) + 8 + item_label_qty_end_width = self.qty_width + 7 + 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 y_position = cursor move_down 5 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 - text_box "Price", :at =>[self.item_width,y_position], :width => self.price_width, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix - text_box "Qty", :at =>[(self.item_width+self.price_width),y_position], :width => self.qty_width, :height =>self.item_height, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix + text_box "Price", :at =>[(self.item_width),y_position], :width => self.price_width, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix + 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 @@ -147,9 +157,19 @@ class ReceiptBillPdf < Prawn::Document end def add_line_item_row(sale_items,precision,delimiter) - item_name_width = (self.item_width+self.price_width) - item_total_front_width = item_name_width + 15 - item_total_end_width = self.total_width + 14 + if precision.to_i > 0 + item_name_width = (self.item_width+self.price_width) + item_qty_front_width = (self.item_width+self.price_width) + 5 + item_qty_end_width = self.qty_width + 4 + item_total_front_width = item_name_width + 10 + item_total_end_width = self.total_width + 9 + else + item_name_width = (self.item_width+self.price_width) + item_qty_front_width = item_name_width + 8 + item_qty_end_width = self.qty_width + 7 + item_total_front_width = item_name_width + 5 + item_total_end_width = self.total_width + 4 + end y_position = cursor move_down 5 sub_total = 0.0 @@ -171,7 +191,7 @@ class ReceiptBillPdf < Prawn::Document end # text_box "#{product_name}", :at =>[0,y_position], :width => self.item_width, :size => self.item_font_size text_box "#{number_with_precision(price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[self.item_width,y_position], :width => self.price_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix - text_box "#{number_with_precision(qty, :precision => precision.to_i)}", :at =>[item_name_width,y_position], :width => self.qty_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix + text_box "#{number_with_precision(qty, :precision => precision.to_i)}", :at =>[item_qty_front_width,y_position], :width => item_qty_end_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix text_box "#{number_with_precision(total_price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[item_total_front_width,y_position], :width =>item_total_end_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix } move_down 5 @@ -478,7 +498,7 @@ class ReceiptBillPdf < Prawn::Document text "#{printed_status}",:style => :bold, :size => header_font_size,:align => :left end bounding_box([self.item_description_width,y_position], :width =>self.item_description_width, :height => self.item_height) do - text "Thank You! See you Again", :left_margin => -10, :size => self.item_font_size,:align => :left + text "Thank You! See you Again", :left_margin => -5, :size => self.item_font_size,:align => :left end move_down 5 diff --git a/app/views/print_settings/_form.html.erb b/app/views/print_settings/_form.html.erb index 201d1411..38e55330 100755 --- a/app/views/print_settings/_form.html.erb +++ b/app/views/print_settings/_form.html.erb @@ -16,7 +16,7 @@ <%= f.input :page_width %> <%= f.input :page_height %> <%= f.input :print_copies, input_html: { min: 1, step: '1', :onkeypress => "return isNumberKey(event);", :onkeyup => "greaterThanOne(this.value);" } %> - <%= f.input :precision, input_html: { min: 0, max: 2, :onkeypress => "return isNumberKey(event);", :onkeyup => "greaterThanThree(this.value);" } %> + <%= f.input :precision, input_html: { min: 0, max: 2, :onkeypress => "return isNumberKey(event);", :onkeyup => "greaterThanTwo(this.value);" } %> <%= f.input :delimiter %> <%= f.input :heading_space %>
@@ -74,7 +74,7 @@ if(parseInt(val)==0) $("#print_setting_print_copies").val(1); } - function greaterThanThree(val){ + function greaterThanTwo(val){ if(parseInt(val)>2) $("#print_setting_precision").val(2); } \ No newline at end of file From da4af7bfc504f98c664401555ce0abfafe87a721 Mon Sep 17 00:00:00 2001 From: Yan Date: Fri, 22 Dec 2017 16:33:12 +0630 Subject: [PATCH 36/84] license updated --- app/controllers/application_controller.rb | 16 +- app/controllers/install_controller.rb | 24 +- app/models/license.rb | 428 +++++++++--------- app/models/my_aes_crypt.rb | 3 +- .../api/restaurant/menu/_menu.json.jbuilder | 1 + config/license.yml | 30 +- config/routes.rb | 1 + config/secrets.yml | 7 +- 8 files changed, 250 insertions(+), 260 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index d10fbbf5..3f789fc4 100755 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -36,20 +36,23 @@ class ApplicationController < ActionController::Base # redirect_to root_url(:host => request.domain) + "store_error" render :json => [{ status: false, message: 'Invalid Access!'}] end - else + else # check for license file if check_license current_license(ENV["SX_PROVISION_URL"]) + else + redirect_to activate_path end end end def current_license(url) @license = License.new(url) - if (@license.detail_with_local_file() == 0) - puts "Expired or No License!" - elsif (@license.detail_with_local_file() == 2) - puts "Expiring! pls, license extend..." + flag = @license.detail_with_local_file() + if (flag == 0) + flash[:notice] = 'Expired or No License!' + elsif (flag == 2) + flash[:notice] = 'Expiring! Please, License extend...' else puts "RUN SAY BYAR" end @@ -108,9 +111,8 @@ class ApplicationController < ActionController::Base def check_license if License.check_license_file return true - else - redirect_to activate_path end + return false end end diff --git a/app/controllers/install_controller.rb b/app/controllers/install_controller.rb index a386416a..fac74926 100755 --- a/app/controllers/install_controller.rb +++ b/app/controllers/install_controller.rb @@ -1,6 +1,6 @@ class InstallController < BaseController skip_before_action :verify_authenticity_token - before_action :check_license + # before_action :check_license def index end @@ -17,20 +17,20 @@ class InstallController < BaseController db_schema = params[:db_schema] db_user = params[:db_user] db_password = params[:db_password] - phrase = license_key + phrase = license_key # Check Exists IV - if flag == "<%= ENV['AES_IV'] %>" - # Export for Key - aes = MyAesCrypt.new - aes_key, aes_iv = aes.export_key(phrase) - else - aes_key = ENV["AES_KEY"] - aes_iv = ENV["AES_IV"] - end + # if flag == "<%= ENV['AES_IV'] %>" + # # Export for Key + # aes = MyAesCrypt.new + # aes_key, aes_iv = aes.export_key(phrase) + # else + # aes_key = ENV["AES_KEY"] + # aes_iv = ENV["AES_IV"] + # end @license = License.new(ENV["SX_PROVISION_URL"]) - response = @license.license_activate(aes_key, aes_iv, license_key, db_host, db_schema, db_user, db_password) + response = @license.license_activate(restaurant, license_key, db_host, db_schema, db_user, db_password) if response[:status] redirect_to root_url, notice: response["message"] else @@ -38,7 +38,7 @@ class InstallController < BaseController end end - def check_license + def check_license if License.check_license_file redirect_to root_url end diff --git a/app/models/license.rb b/app/models/license.rb index e9922084..36ce9b29 100755 --- a/app/models/license.rb +++ b/app/models/license.rb @@ -68,31 +68,9 @@ class License end # For Local System - def detail_with_local_file() - # flag = ENV["AES_KEY"] - # # Check Exists IV - # if flag == "<%= ENV['AES_IV'] %>" - # # Export for Key - # aes = MyAesCrypt.new - # aes_key, aes_iv = aes.export_key(lookup) - # else - # aes_key = ENV["AES_KEY"] - # aes_iv = ENV["AES_IV"] - # end - + def detail_with_local_file() renewal_date_str = read_license("renewable_date") - - # ##Check from local redis - if available load local otherwise get from remote - # renewable_date = "renewable_date:#{renewal_date_str}" - - # ##Get redis connection from connection pool - # redis = Redis.new - # cache_renewable_date = redis.get(renewable_date) - # if cache_renewable_date.nil? - # redis = Redis.new - # redis.set(renewable_date, Marshal.dump(@license)) - # else - # get_renewable_date = Marshal.load(cache_renewable_date) + if check_expiring(renewal_date_str) # return for all ok return 1 @@ -110,13 +88,34 @@ class License end # License Activation - def license_activate (key, iv, license_key, db_host, db_schema, db_user, db_password) - @params = { query: { lookup_type: self.server_mode, iv_key: iv, license_key: license_key } } + def license_activate (shop, license_key, db_host, db_schema, db_user, db_password) + aes = MyAesCrypt.new + aes_key, aes_iv = aes.export_key(license_key) + + @params = { query: { lookup_type: self.server_mode, iv_key: aes_iv, license_key: license_key } } response = self.class.get("/activate", @params) @activate = response.parsed_response - Rails.logger.debug "License Remote Response - " + response.parsed_response.to_s if (@activate["status"]) + ##Check from local redis - if available load local otherwise get from remote + cache_key = "shop:#{@activate["shop_name"]}" + + cache_license = nil + + ##Get redis connection from connection pool + redis = Redis.new + cache_license = redis.get(cache_key) + + Rails.logger.info "Cache key - " + cache_key.to_s + + if cache_license.nil? + cache = {"shop" => @activate["shop_name"], "key" => aes_key, "iv" => @activate["iv_key"], "renewable_date" => @activate["renewable_date"] } + redis = Redis.new + redis.set(cache_key, Marshal.dump(cache)) + end + + Rails.logger.info "License - " + response.parsed_response.to_s + response = create_license_file(@activate) if(response[:status]) sym_path = "/home/yan/symmetric/" @@ -149,19 +148,21 @@ class License end # Check Expired before 30 days - def check_expiring(renewal_date_str) - renewal_date = DateTime.parse(renewal_date_str) - renewal_date > Date.today.advance(:days => 30) + def check_expiring(renewal_date_str) + if !renewal_date_str.empty? + renewal_date = DateTime.parse(renewal_date_str) + renewal_date > Date.today.advance(:days => 30) + end end # Check License expired date from PROVISION SERVER - def check_expired(renewal_date_str) + def check_expired(renewal_date_str) expired_date_str = read_license("renewable_date") - expired_date = DateTime.parse(expired_date_str) renewal_date = DateTime.parse(renewal_date_str) - if(renewal_date != expired_date){ + + if(renewal_date_str != expired_date_str) update_license("renewable_date", renewal_date_str) - } + end if (renewal_date < Date.today) return true @@ -176,16 +177,18 @@ class License end # read line by key for license file - def read_license(key) - decrypted_line = "" + def read_license(key_name) + decrypted_line = "" + key, iv = get_redis_key() + if File.exist?("config/license.yml") File.open("config/license.yml").each do |line| - if line.include? (key) - decrypted_line_array = line.split(": ") - decrypted_line = AESCrypt.decrypt_data(decode_str(decrypted_line_array[1]), decode_str(ENV['AES_KEY']), decode_str(ENV['AES_IV']), ENV['CIPHER_TYPE']) + if line.include? (key_name) + decrypted_line_array = line.split(": ") + decrypted_line = AESCrypt.decrypt_data(decode_str(decrypted_line_array[1]), decode_str(key), decode_str(iv), ENV['CIPHER_TYPE']) end end - end + end return decrypted_line end @@ -205,18 +208,19 @@ class License # Update license file for line def update_license(content, new_content) - if !new_content.include? "==" - str = encode_str(new_content) - crypted_str = AESCrypt.encrypt_data(str, ENV['AES_KEY'], ENV['AES_IV'], ENV['CIPHER_TYPE']) - end + key, iv = get_redis_key() + if !new_content.include? "==" + crypted_str = AESCrypt.encrypt_data(new_content, decode_str(key), decode_str(iv), ENV['CIPHER_TYPE']) + end + content_str = read_license_no_decrypt(content) if File.exist?("config/license.yml") file_str = File.read("config/license.yml") - new_file_str = file_str.gsub(content, crypted_str) + new_file_str = file_str.gsub(content_str, encode_str(crypted_str)) # To write changes to the file, use: - # File.open("config/license.yml", "w") {|file| file.puts new_file_str } + File.open("config/license.yml", "w") {|file| file.puts new_file_str } # File.open("config/license.yml").each do |line| # new_file_str = line.gsub(content, crypted_str) @@ -225,189 +229,187 @@ class License end end - private - def encode_str(str) - return Base64.encode64(str) + private + def get_redis_key + iv = "" + key = "" + shop = read_license_no_decrypt("shop_name") + ##Check from local redis - if available load local otherwise get from remote + cache_key = "shop:#{shop.chomp}" + + cache_shop = nil + + ##Get redis connection from connection pool + redis = Redis.new + cache_shop = redis.get(cache_key) + + if !cache_shop.nil? + @shop = Marshal.load(cache_shop) + key = @shop["key"] + iv = @shop["iv"] + end + return key, iv + end + + def encode_str(str) + return Base64.encode64(str) + end + + def decode_str(str) + return Base64.decode64(str) + end + + # License File Creation + def create_license_file(response_data) + if File.exist?("config/license.yml") + delete_license_file end - def decode_str(str) - return Base64.decode64(str) + begin + # Licese File Creation + File.open("config/license.yml", "w") do |f| + f.puts("iv_key: #{response_data['iv_key']}") + f.puts("shop_name: #{response_data['shop_name']}") + f.puts("email: #{response_data['email']}") + f.puts("telephone: #{response_data['telephone']}") + f.puts("fax: #{response_data['fax']}") + f.puts("address: #{response_data['address']}") + f.puts("dbhost: #{response_data['dbhost']}") + f.puts("dbschema: #{response_data['dbschema']}") + f.puts("dbusername: #{response_data['dbusername']}") + f.puts("dbpassword: #{response_data['dbpassword']}") + f.puts("api_token: #{response_data['api_token']}") + f.puts("app_token: #{response_data['app_token']}") + f.puts("plan_sku: #{response_data['plan_sku']}") + f.puts("renewable_date: #{response_data['renewable_date']}") + f.puts("plan_name: #{response_data['plan_name']}") + end + rescue IOError + response = { "status": false, "message": "Activation is success but something is wrong. \n Please contact code2lab call center!"} end + response = { "status": true, "message": "Success Activation. License also created."} + end - # License File Creation - def create_license_file(response_data) - if File.exist?("config/license.yml") - delete_license_file - end - + # Symmetric Configuration + def create_symmetric_config(sym_location, db_host, db_schema, db_user, db_password) + if File.directory? (sym_location) begin - # Licese File Creation - File.open("config/license.yml", "w") do |f| - f.puts("iv_key: #{response_data['iv_key']}") - f.puts("shop_name: #{response_data['shop_name']}") - f.puts("email: #{response_data['email']}") - f.puts("telephone: #{response_data['telephone']}") - f.puts("fax: #{response_data['fax']}") - f.puts("address: #{response_data['address']}") - f.puts("dbhost: #{response_data['dbhost']}") - f.puts("dbschema: #{response_data['dbschema']}") - f.puts("dbusername: #{response_data['dbusername']}") - f.puts("dbpassword: #{response_data['dbpassword']}") - f.puts("api_token: #{response_data['api_token']}") - f.puts("app_token: #{response_data['app_token']}") - f.puts("plan_sku: #{response_data['plan_sku']}") - f.puts("renewable_date: #{response_data['renewable_date']}") - f.puts("plan_name: #{response_data['plan_name']}") - end + # sx properties create + f = File.open(sym_location + "engines/sx.properties", "w") + f.write("engine.name=sx\n") + f.write("db.driver=com.mysql.jdbc.Driver\n") + f.write("db.url=jdbc:mysql://#{db_host}/#{db_schema}?tinyInt1isBit=false\n") + f.write("db.user=#{db_user}\n") + f.write("db.password=#{db_password}\n") + f.write("registration.url=\n") + f.write("sync.url=http://#{db_host}:31415/sync/sx\n") + f.write("group.id=sx\n") + f.write("external.id=000\n") + f.write("job.purge.period.time.ms=7200000\n") + f.write("job.routing.period.time.ms=5000\n") + f.write("job.push.period.time.ms=10000\n") + f.write("job.pull.period.time.ms=10000\n") + f.write("initial.load.create.first=true\n") + f.write("initial.load.use.extract.job.enabled=true\n") + f.close + + # read from license file + shop_name = read_license_no_decrypt("shop_name") + dbhost = read_license("dbhost") + dbschema = read_license("dbschema") + dbusername = read_license("dbusername") + dbpassword = read_license("dbpassword") + + # shop properties create + f = File.open(sym_location + "engines/#{shop_name}.properties", "w") + f.write("engine.name=#{shop_name}\n") + f.write("db.driver=com.mysql.jdbc.Driver\n") + f.write("db.url=jdbc:mysql://#{dbhost}/#{dbschema}?tinyInt1isBit=false\n") + f.write("db.user=#{dbusername}\n") + f.write("db.password=#{dbpassword}\n") + f.write("registration.url=http://#{db_host}:31415/sync/sx\n") + f.write("group.id=store\n") + f.write("external.id=001\n") + f.write("job.routing.period.time.ms=5000\n") + f.write("job.push.period.time.ms=10000\n") + f.write("job.pull.period.time.ms=10000\n") + # f.write("initial.load.create.first=true\n") + # f.write("initial.load.use.extract.job.enabled=true\n") + f.close rescue IOError response = { "status": false, "message": "Activation is success but something is wrong. \n Please contact code2lab call center!"} end response = { "status": true, "message": "Success Activation. License also created."} end + end - # Symmetric Configuration - def create_symmetric_config(sym_location, db_host, db_schema, db_user, db_password) - if File.directory? (sym_location) - begin - # sx properties create - f = File.open(sym_location + "engines/sx.properties", "w") - f.write("engine.name=sx\n") - f.write("db.driver=com.mysql.jdbc.Driver\n") - f.write("db.url=jdbc:mysql://#{db_host}/#{db_schema}?tinyInt1isBit=false\n") - f.write("db.user=#{db_user}\n") - f.write("db.password=#{db_password}\n") - f.write("registration.url=\n") - f.write("sync.url=http://#{db_host}:31415/sync/sx\n") - f.write("group.id=sx\n") - f.write("external.id=000\n") - f.write("job.purge.period.time.ms=7200000\n") - f.write("job.routing.period.time.ms=5000\n") - f.write("job.push.period.time.ms=10000\n") - f.write("job.pull.period.time.ms=10000\n") - f.write("initial.load.create.first=true\n") - f.write("initial.load.use.extract.job.enabled=true\n") - f.close + # Run Symmetric + def run_symmetric(sym_path) + # check_sym_proc_str = `#{sym_path + "bin/sym_service status"}` + # check_sym_proc_str = check_sym_proc_str.split("\n") + # sym_install_status = check_sym_proc_str[0].split(": ") + + check_sym_proc_str = `#{"service SymmetricDS status"}` - # read from license file - shop_name = read_license("shop_name") - dbhost = read_license("dbhost") - dbschema = read_license("dbschema") - dbusername = read_license("dbusername") - dbpassword = read_license("dbpassword") + # Check Sym Installed + # if sym_install_status[1] == "false" + # response = { "status": false, "message": "Activation is success but Symmetric service not Installed. \n Please contact code2lab call center!"} + # end - # shop properties create - f = File.open(sym_location + "engines/#{shop_name}.properties", "w") - f.write("engine.name=#{shop_name}\n") - f.write("db.driver=com.mysql.jdbc.Driver\n") - f.write("db.url=jdbc:mysql://#{dbhost}/#{dbschema}?tinyInt1isBit=false\n") - f.write("db.user=#{dbusername}\n") - f.write("db.password=#{dbpassword}\n") - f.write("registration.url=http://#{db_host}:31415/sync/sx\n") - f.write("group.id=store\n") - f.write("external.id=001\n") - f.write("job.routing.period.time.ms=5000\n") - f.write("job.push.period.time.ms=10000\n") - f.write("job.pull.period.time.ms=10000\n") - # f.write("initial.load.create.first=true\n") - # f.write("initial.load.use.extract.job.enabled=true\n") - f.close - rescue IOError - response = { "status": false, "message": "Activation is success but something is wrong. \n Please contact code2lab call center!"} - end - response = { "status": true, "message": "Success Activation. License also created."} - end - end - - # Run Symmetric - def run_symmetric(sym_path) - # check_sym_proc_str = `#{sym_path + "bin/sym_service status"}` - # check_sym_proc_str = check_sym_proc_str.split("\n") - # sym_install_status = check_sym_proc_str[0].split(": ") - - check_sym_proc_str = `#{"service SymmetricDS status"}` - - # Check Sym Installed - # if sym_install_status[1] == "false" - # response = { "status": false, "message": "Activation is success but Symmetric service not Installed. \n Please contact code2lab call center!"} - # end - - # Run Sym Service - sym_run_status = check_sym_running(check_sym_proc_str, sym_path) - if sym_run_status - # Create Sym Table - check_sym_table = system(sym_path + "bin/symadmin --engine sx create-sym-tables") - if check_sym_table - sym_sql = Rails.root + "db/sym_master.sql" - - if File.exist? (sym_sql) - # Import Sym Sql to db and start sym - run_sym_sql = system(sym_path + "bin/dbimport --engine sx " + sym_sql.to_s) - stop_sym = system("service SymmetricDS stop") - run_sym = system("service SymmetricDS start") - if run_sym - response = { "status": true, "message": "Activation is success and Configuration done..."} - end - else - response = { "status": false, "message": "Activation is success but Symmetric Sql not found. \n Please contact code2lab call center!"} + # Run Sym Service + sym_run_status = check_sym_running(check_sym_proc_str, sym_path) + if sym_run_status + # Create Sym Table + check_sym_table = system(sym_path + "bin/symadmin --engine sx create-sym-tables") + if check_sym_table + sym_sql = Rails.root + "db/sym_master.sql" + + if File.exist? (sym_sql) + # Import Sym Sql to db and start sym + run_sym_sql = system(sym_path + "bin/dbimport --engine sx " + sym_sql.to_s) + stop_sym = system("service SymmetricDS stop") + run_sym = system("service SymmetricDS start") + if run_sym + response = { "status": true, "message": "Activation is success and Configuration done..."} end + else + response = { "status": false, "message": "Activation is success but Symmetric Sql not found. \n Please contact code2lab call center!"} end - else - response = { "status": false, "message": "Activation is success but Symmetric not running. \n Please contact code2lab call center!"} end + else + response = { "status": false, "message": "Activation is success but Symmetric not running. \n Please contact code2lab call center!"} end + end - # Check Symmetric Running - def check_sym_running(status, sym_path) - # Run Sym Service - # if status.include? "Server is already running" - # return true - # elsif status.include? "false" - # sym_start_str = `#{sym_path + "bin/sym_service start"}` - # if sym_start_str.include? "Started" - # return true - # else - # check_sym_running(sym_start_status[0]) - # end - # else - # return true - # end + # Check Symmetric Running + def check_sym_running(status, sym_path) + # Run Sym Service + # if status.include? "Server is already running" + # return true + # elsif status.include? "false" + # sym_start_str = `#{sym_path + "bin/sym_service start"}` + # if sym_start_str.include? "Started" + # return true + # else + # check_sym_running(sym_start_status[0]) + # end + # else + # return true + # end - if status.include? "Active: active (running)" #"Server is already running" - return true - end - return false + if status.include? "Active: active (running)" || "Active: active (exited)" #"Server is already running" + return true end + return false + end - # Delete License File - def delete_license_file - File.delete("config/license.yml") if File.exist?("config/license.yml") - end + # Delete License File + def delete_license_file + File.delete("config/license.yml") if File.exist?("config/license.yml") + end # Assign db info for Cloud - def assign(aes_key, aes_iv) - # self.name = @license["name"] - # self.address_1 = @license["address_1"] - # self.address_2 = @license["address_2"] - # self.township = @license["township"] - # self.city = @license["city"] - # self.country = @license["country"] - # self.email = @license["email"] - # self.phone = @license["phone"] - # self.fax = @license["fax"] - # self.logo = @license["logo"] - # self.localhost_address = @license["localhost_address"] - # self.subdomain = @license["subdomain"] - # self.plan_activation_date = Date.parse(@license["plan_activation_date"]) - # self.plan_next_renewal_date = Date.parse(@license["plan_next_renewal_date"]) - - ## self.plan_activation_date = Date.strptime(@license["plan_activation_date"], "%Y-%m-%d") - ## self.plan_next_renewal_date = Date.strptime(@license["plan_next_renewal_date"], "%Y-%m-%d") - - # self.plan_max_products = @license["plan_max_products"].to_i - # self.plan_max_customers = @license["plan_max_customers"].to_i - # self.plan_active_connections = @license["plan_active_connections"].to_i - # salt = @license["secret_key"] - + def assign(aes_key, aes_iv) key = Base64.decode64(aes_key) iv = Base64.decode64(aes_iv) @@ -422,18 +424,6 @@ class License self.dbusername = AESCrypt.decrypt_data(dbusername, key, iv, ENV['CIPHER_TYPE']) self.dbpassword = AESCrypt.decrypt_data(dbpassword, key, iv, ENV['CIPHER_TYPE']) end - - # self.exchange_unqiue_id = @license["exchange_unqiue_id"] - - # self.localqueue_host= @license["localqueue_host"] - # self.localqueue_user= @license["localqueue_user"] - # self.localqueue_password= @license["localqueue_password"] - - # self.remotequeue_host = @license["remotequeue_host"] - # self.remotequeue_user = @license["remotequeue_user"] - # self.remotequeue_password = @license["remotequeue_password"] - - # self.api_token = @license["api_token"] - # self.app_token = @license["app_token"] + end end diff --git a/app/models/my_aes_crypt.rb b/app/models/my_aes_crypt.rb index 569a401d..680d0624 100644 --- a/app/models/my_aes_crypt.rb +++ b/app/models/my_aes_crypt.rb @@ -17,8 +17,7 @@ class MyAesCrypt passphrase = passphrase + ENV['SX_KEY'] passphrase = passphrase.gsub(".","_") digest = Digest::SHA256.new - key_digest = digest.update(passphrase) - # iv_digest = digest.update(iv_salt) + key_digest = digest.update(passphrase) key = key_digest.digest # iv = iv_digest.digest diff --git a/app/views/api/restaurant/menu/_menu.json.jbuilder b/app/views/api/restaurant/menu/_menu.json.jbuilder index 9441daf9..268a6391 100755 --- a/app/views/api/restaurant/menu/_menu.json.jbuilder +++ b/app/views/api/restaurant/menu/_menu.json.jbuilder @@ -9,6 +9,7 @@ if (menu.menu_categories) json.id category.id json.name category.name json.alt_name category.alt_name + json.order_by category.order_by json.parent_id category.menu_category_id json.is_available category.is_available diff --git a/config/license.yml b/config/license.yml index b96a0256..cc470a1d 100644 --- a/config/license.yml +++ b/config/license.yml @@ -1,15 +1,15 @@ -iv_key: A30HZdW+iDZA0vM5PAqwgg== -shop_name: 7DdPBxVo8m1xpa5T2kIcWQ== -email: yanaung.nyein@code2lab.com -telephone: 111111 -fax: 111111 -address: bitp -dbhost: 9+83FZetcbLZi6COG5PbSw== -dbschema: shztSYIsNmM9nlHkR/4exQ== -dbusername: LapN+Geriht8yk866FxNiQ== -dbpassword: QtboWZ4ATE05vvYw6J+Uqw== -api_token: nGyMizHtoVEFYCjSVEFJuzkxuBJwSsH -app_token: QUdPwSakcsnuVLdfkXgGHhPMiIOcSSfaVwQyA -plan_sku: 9+83FZetcbLZi6COG5PbSw== -renewable_date: shztSYIsNmM9nlHkR/4exQ== -plan_name: LapN+Geriht8yk866FxNiQ== +iv_key: TP8dIx4nBGzr+tYyKn5+Xw== +shop_name: Osaka +email: wathonaun9@gmail.com +telephone: 09979204288 +fax: 09979204288 +address: Yangon +dbhost: nk57NaR38B2eSYyron3Nbw== +dbschema: 3orxFaTi0uQhatBqZGiitQ== +dbusername: EtMle9Gr0/PE3NFHHfwo5A== +dbpassword: 86h61/O38GGo64nekz6oeA== +api_token: FVAGMnjVdaScfydXMbMvPPRWnkEwCSuxs +app_token: IoXPdqzbnQWbHsnxLAjMjimnjEJNySOeIo +plan_sku: PyQJ2sk5NZTudqQ2YIU16A== +renewable_date: d/Fk1deU/iPbZFDOdyKsjA== +plan_name: weWOqr1tZ61Av6YKth1lDw== diff --git a/config/routes.rb b/config/routes.rb index 4c302b94..a4bd24c6 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -12,6 +12,7 @@ scope "(:locale)", locale: /en|mm/ do #--------- SmartSales Activation ------------# get 'activate' => 'install#index' post 'activate' => 'install#activate' + get 'run_sym' => 'sym_control#run' #--------- Login/Authentication ------------# get 'auth/:emp_id' => 'home#show', as: :emp_login diff --git a/config/secrets.yml b/config/secrets.yml index af242402..37b1f0b0 100755 --- a/config/secrets.yml +++ b/config/secrets.yml @@ -12,12 +12,10 @@ development: secret_key_base: b61d85f8ed2a1a9e0eeece3443b3e8f838d002cc1d9f32115d8e93db920e2957adfedc57501d44741211538f3108b742cdeada87d5bfae796c53da1f90a3cd61 - sx_provision_url: 192.168.1.147:3002/api #connect.smartsales.asia/api #provision.zsai.ws/api + sx_provision_url: 192.168.1.49:3002/api #connect.smartsales.asia/api #provision.zsai.ws/api server_mode: application cipher_type: AES-256-CBC sx_key: Wh@t1$C2L - aes_key: <%= ENV['AES_KEY'] %> - aes_iv: <%= ENV['AES_IV'] %> test: secret_key_base: 5c92143fd4a844fdaf8b22aba0cda22ef1fc68f1b26dd3d40656866893718ae5e58625b4c3a5dc86b04c8be0a505ec0ebc0be3bf52249a3d1e0c1334ee591cf0 @@ -28,7 +26,6 @@ production: secret_key_base: c4bc81065013f9a3506d385bcbd49586c42e586488144b0de90c7da36867de9fa880f46b5c4f86f0ce9b7c783bb5a73bdb0e5605a47716567294390e726d3e22 sx_provision_url: provision.zsai.ws/api #192.168.1.94:3002 server_mode: cloud + cipher_type: AES-256-CBC sx_key: Wh@t1$C2L - aes_key: <%= ENV['AES_KEY'] %> - aes_iv: <%= ENV['AES_IV'] %> From 11d991240137bf66e4214c310e1f5275b38ea86a Mon Sep 17 00:00:00 2001 From: Yan Date: Fri, 22 Dec 2017 16:35:04 +0630 Subject: [PATCH 37/84] license updated --- app/controllers/sym_control_controller.rb | 35 +++++++++++++++++++++++ app/views/sym_control/run.html.erb | 1 + 2 files changed, 36 insertions(+) create mode 100644 app/controllers/sym_control_controller.rb create mode 100755 app/views/sym_control/run.html.erb diff --git a/app/controllers/sym_control_controller.rb b/app/controllers/sym_control_controller.rb new file mode 100644 index 00000000..816b8f2c --- /dev/null +++ b/app/controllers/sym_control_controller.rb @@ -0,0 +1,35 @@ +class SymControlController < BaseController + skip_before_action :verify_authenticity_token + + def run + sym_path = "/home/yan/symmetric/" + check_sym_proc_str = `#{"service SymmetricDS status"}` + # Check Sym Installed + # if sym_install_status[1] == "false" + # response = { "status": false, "message": "Activation is success but Symmetric service not Installed. \n Please contact code2lab call center!"} + # end + + if check_sym_proc_str.include? "Active: active (running)" || "Active: active (exited)" #"Server is already running" + # Create Sym Table + check_sym_table = system(sym_path + "bin/symadmin --engine sx create-sym-tables") + if check_sym_table + sym_sql = Rails.root + "db/sym_master.sql" + + if File.exist? (sym_sql) + # Import Sym Sql to db and start sym + run_sym_sql = system(sym_path + "bin/dbimport --engine sx " + sym_sql.to_s) + stop_sym = system("service SymmetricDS stop") + run_sym = system("service SymmetricDS start") + if run_sym + render :text => "

Success!

" + end + else + render :text => "

Sym Sql file not found!

" + end + end + else + render :text => "

Sym not running!

" + end + end + +end \ No newline at end of file diff --git a/app/views/sym_control/run.html.erb b/app/views/sym_control/run.html.erb new file mode 100755 index 00000000..8b137891 --- /dev/null +++ b/app/views/sym_control/run.html.erb @@ -0,0 +1 @@ + From 5bd1daa152f16afdaac9dd2a238714a7fa0bfaa1 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Fri, 22 Dec 2017 17:51:02 +0630 Subject: [PATCH 38/84] update payment and memberdiscoun --- app/assets/javascripts/origami.js | 27 +++- app/views/origami/home/show.html.erb | 2 +- app/views/origami/payments/show.html.erb | 151 ++++++++++++++--------- app/views/origami/rooms/show.html.erb | 3 +- 4 files changed, 114 insertions(+), 69 deletions(-) diff --git a/app/assets/javascripts/origami.js b/app/assets/javascripts/origami.js index e649f4b4..725e6353 100755 --- a/app/assets/javascripts/origami.js +++ b/app/assets/javascripts/origami.js @@ -145,30 +145,45 @@ $(document).on('turbolinks:load', function() { }); /* start check first bill or not funs: */ -function checkReceiptNoInFirstBillData(receipt_no) { +function checkReceiptNoInFirstBillData(receipt_no,payment=null) { + // localStorage.removeItem('receipt_lists'); var status = false; if((receipt_no!=undefined) && (receipt_no!="")){ if(localStorage.hasOwnProperty("receipt_lists")===true){ var arr_data = JSON.parse(localStorage.getItem("receipt_lists")); - var json_data = arr_data.filter(function(e) { return e.receipt_no !== receipt_no }); + console.log(arr_data) + if (payment) { + var json_data = arr_data.filter(function(e) { return e.receipt_no == receipt_no }); + }else{ + var json_data = arr_data.filter(function(e) { return e.receipt_no !== receipt_no }); + } + if((arr_data.length) > (json_data.length)){ status = true; } } } - - return status; + if (payment) { + return json_data[0]["payment"]; + }else{ + return status; + } } -function createReceiptNoInFirstBillData(receipt_no) { +function createReceiptNoInFirstBillData(receipt_no,payment=null) { var arr_data = []; var json_data = []; if(localStorage.hasOwnProperty("receipt_lists")===true){ arr_data = JSON.parse(localStorage.getItem("receipt_lists")); json_data = arr_data.filter(function(e) { return e.receipt_no == receipt_no }); + if (payment) { + jdata = arr_data.filter(function(e) { return e.receipt_no !== receipt_no }); + jdata.push({'receipt_no':receipt_no,'payment':payment}); + localStorage.setItem("receipt_lists",JSON.stringify(jdata)); + } } if(((arr_data.length == 0) && (json_data.length == 0)) || ((arr_data.length > 0) && (json_data.length == 0))){ - arr_data.push({'receipt_no':receipt_no}); + arr_data.push({'receipt_no':receipt_no,'payment':payment}); localStorage.setItem("receipt_lists",JSON.stringify(arr_data)); } } diff --git a/app/views/origami/home/show.html.erb b/app/views/origami/home/show.html.erb index 0fa545a3..5471b5e4 100755 --- a/app/views/origami/home/show.html.erb +++ b/app/views/origami/home/show.html.erb @@ -596,7 +596,7 @@ $( "#loading_wrapper" ).hide(); receipt_no = ($("#receipt_no").html()).trim(); if((receipt_no!=undefined) && (receipt_no!="")) - createReceiptNoInFirstBillData(receipt_no); + createReceiptNoInFirstBillData(receipt_no,type); location.reload(); } diff --git a/app/views/origami/payments/show.html.erb b/app/views/origami/payments/show.html.erb index 848a0b40..1cf61690 100755 --- a/app/views/origami/payments/show.html.erb +++ b/app/views/origami/payments/show.html.erb @@ -290,6 +290,21 @@