From 70ec80a1d55c688d709e036edf6ddfc088f4f502 Mon Sep 17 00:00:00 2001 From: San Wai Lwin Date: Wed, 18 Apr 2018 16:57:02 +0630 Subject: [PATCH 01/27] Manager level can not edit Administrator's password and id --- app/views/origami/payments/show.html.erb | 22 +++++++++++---------- app/views/settings/employees/_form.html.erb | 6 +++++- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/app/views/origami/payments/show.html.erb b/app/views/origami/payments/show.html.erb index 00852f95..2cf6fea5 100755 --- a/app/views/origami/payments/show.html.erb +++ b/app/views/origami/payments/show.html.erb @@ -435,16 +435,18 @@ diff --git a/app/views/settings/employees/_form.html.erb b/app/views/settings/employees/_form.html.erb index 0b973416..ad50e9b8 100755 --- a/app/views/settings/employees/_form.html.erb +++ b/app/views/settings/employees/_form.html.erb @@ -7,7 +7,11 @@
<%= f.input :name %> - <%= f.input :role, :collection => Lookup.collection_of("employee_roles"),:class=>'form-group' %> + <% if current_user.role == "administrator" %> + <%= f.input :role, :collection => Lookup.collection_of("employee_roles"),:class=>'form-group' %> + <% else %> + <%= f.input :role, :collection => Lookup.collection_of("employee_roles").select{|r| r[1] != "administrator"},:class=>'form-group' %> + <% end %> <%= f.input :emp_id, :label => "Employee Numberic ID (*Unique)" %> <%= f.input :password %> From e468bc65afea17786aba8b42368744c56ccac912 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Thu, 19 Apr 2018 10:32:59 +0630 Subject: [PATCH 02/27] update shift_sale migration file and secret yml --- config/secrets.yml | 2 +- db/migrate/20170626191519_create_shift_sales.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/config/secrets.yml b/config/secrets.yml index 6e8b73d4..b0d7c5c8 100755 --- a/config/secrets.yml +++ b/config/secrets.yml @@ -24,7 +24,7 @@ test: # instead read values from the environment. production: secret_key_base: c4bc81065013f9a3506d385bcbd49586c42e586488144b0de90c7da36867de9fa880f46b5c4f86f0ce9b7c783bb5a73bdb0e5605a47716567294390e726d3e22 - sx_provision_url: connect.smartsales.asia/api #192.168.1.147:3002/api + sx_provision_url: https://connect.pos-myanmar.com/api #192.168.1.147:3002/api server_mode: application cipher_type: AES-256-CBC sx_key: Wh@t1$C2L diff --git a/db/migrate/20170626191519_create_shift_sales.rb b/db/migrate/20170626191519_create_shift_sales.rb index f18a2c1c..bd19a8cf 100755 --- a/db/migrate/20170626191519_create_shift_sales.rb +++ b/db/migrate/20170626191519_create_shift_sales.rb @@ -21,7 +21,7 @@ class CreateShiftSales < ActiveRecord::Migration[5.1] t.integer :dining_count, :default => 0 t.integer :takeaway_count, :default => 0 t.integer :member_count, :default => 0 - t.decimal :total_rounding,, :precision => 10, :scale => 2, :null => false, :default => 0.00 + t.decimal :total_rounding, :precision => 10, :scale => 2, :null => false, :default => 0.00 t.integer :total_receipt, :default => 0 t.decimal :total_void, :default => 0 t.timestamps From 0241d209acea7691c31309bfdd9755095d25b0f5 Mon Sep 17 00:00:00 2001 From: San Wai Lwin Date: Thu, 19 Apr 2018 10:49:25 +0630 Subject: [PATCH 03/27] Pull from master --- Gemfile | 1 + Gemfile.lock | 6 + Main Menu.xlsx | Bin 3997 -> 0 bytes app/assets/javascripts/order_reservation.js | 238 +++++++++++------- app/controllers/api/api_controller.rb | 2 +- .../concerns/token_verification.rb | 4 +- .../origami/customers_controller.rb | 2 + app/controllers/origami/dinga_controller.rb | 25 +- .../origami/order_reservation_controller.rb | 30 ++- app/controllers/origami/paymal_controller.rb | 4 +- app/controllers/settings/menus_controller.rb | 5 +- app/models/customer.rb | 5 + app/models/menu.rb | 2 +- app/models/order_reservation.rb | 232 ++++++++++++++--- app/models/sale_payment.rb | 49 +++- app/views/origami/dinga/index.html.erb | 24 +- .../origami/order_reservation/index.html.erb | 43 ++-- app/views/origami/paymal/index.html.erb | 21 +- app/views/origami/payments/show.html.erb | 26 +- app/views/settings/menus/index.html.erb | 3 +- config/locales/en.yml | 4 + config/locales/mm.yml | 4 + config/routes.rb | 4 +- config/secrets.yml | 2 +- config/shops.json | 11 +- .../20170626191519_create_shift_sales.rb | 2 +- public/menus/Main Menu.xlsx | Bin 0 -> 4375 bytes public/menus/Shwe Myittar.xlsx | Bin 0 -> 3942 bytes 28 files changed, 529 insertions(+), 220 deletions(-) delete mode 100644 Main Menu.xlsx create mode 100644 public/menus/Main Menu.xlsx create mode 100644 public/menus/Shwe Myittar.xlsx diff --git a/Gemfile b/Gemfile index 41682d12..6005cae2 100644 --- a/Gemfile +++ b/Gemfile @@ -52,6 +52,7 @@ gem 'rubyzip', '= 1.0.0' gem 'axlsx', '= 2.0.1' gem 'axlsx_rails' gem 'roo' +gem 'pdfjs_viewer-rails' #Reporting gem #gem 'compendium' #gem "cancan" diff --git a/Gemfile.lock b/Gemfile.lock index eee001d1..b7f4b2ca 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -125,6 +125,7 @@ GEM thor (>= 0.14, < 2.0) jquery-ui-rails (6.0.1) railties (>= 3.2.16) + json (2.1.0) kaminari (1.0.1) activesupport (>= 4.1.0) kaminari-actionview (= 1.0.1) @@ -168,6 +169,10 @@ GEM nokogiri (1.8.1) mini_portile2 (~> 2.3.0) pdf-core (0.7.0) + pdfjs_viewer-rails (0.2.0) + json (> 1.8.4) + rails (> 4.2.0) + sass-rails (~> 5.0) pg (0.21.0) prawn (2.2.2) pdf-core (~> 0.7.0) @@ -333,6 +338,7 @@ DEPENDENCIES momentjs-rails mysql2 (>= 0.3.18, < 0.5) nested_form + pdfjs_viewer-rails pg prawn prawn-table diff --git a/Main Menu.xlsx b/Main Menu.xlsx deleted file mode 100644 index 94c703382ba6733020ef9e02db8febb2b38c130b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3997 zcmaJ^2Q*yk79K|LEeSHXN|5Lb(WBQWA$sp^^wEP5JxB^dUUi=G{_lxazUCQlJmA-+d*9V=oix=# z`;LXw*;%Lq4WA1O0^M93hFd-gemH68x6@mn5eUK)W$(@$g5MALa8<;ar{!&+C zd!K@)PE#(4PVW2qEzdi<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p;ilgVh>>zo(j>po=%X5Ej~<7&2c-=W1;qQu4;UJwCJE?O!6_jA z6vMHdG&^3Zv1LLmF0?Y=x132cHoj#nIv#aVIAsh1(h=lFGw(QeWVhe&8O=x`K`*h|UMqDOxYYt4O5E;gNk9C-)gNIUSRBbg(e44rs%cx+3ghVgZ$fL8u- zJ7QMXu&38Lf!D>+FevZHbNiG1fQ43}ViTo(V4E*1t6YAIk zP+1m`6Lj_T%OG_Vcyr>o`ur~-I%@lE{@Z z(M|Ntj^r8*$NYc&$xS;q>-@EyXsrKQ^=}%uS=6o#%wzxQ$gd^tCirG~xCW2n{2ToL tip5QXH*@#3!En?_iTa&a-u!LwI+Lp_W1`3c0Jx}26*YbeUCo|=e*#e9v@ZYv diff --git a/app/assets/javascripts/order_reservation.js b/app/assets/javascripts/order_reservation.js index 49ef043e..fdea26b8 100644 --- a/app/assets/javascripts/order_reservation.js +++ b/app/assets/javascripts/order_reservation.js @@ -2,37 +2,56 @@ $(function() { $(".nav-item").on("click", function(){ - type = $(this).attr("data-type"); - if (type == "pending") { - $('#accepted').text("Accepted"); - $('#accepted').attr("data-value","accepted"); - }else if(type == "processing"){ - $('#accepted').text("SEND TO KITCHEN"); - $('#accepted').attr("data-value","processed"); - }else if(type == "delivery"){ - $('#accepted').text("READY TO DELIVERY"); - $('#accepted').attr("data-value","delivery"); - }else if(type == "completed"){ - $('#accepted').text("PICK-UP"); - $('#accepted').attr("data-value","completed"); - } - console.log(type) + type = $(this).attr("data-type"); + refreshDetailData(); + if (type == "pending") { + $(".first-1").click(); + $('#accepted').text("Accepted"); + $('#accepted').attr("data-value","accepted"); + }else if(type == "processing"){ + $(".second-1").click(); + $('#accepted').text("SEND TO KITCHEN"); + $('#accepted').attr("data-value","processed"); + }else if(type == "delivery"){ + $(".third-1").click(); + $('#accepted').text("READY TO DELIVERY"); + $('#accepted').attr("data-value","delivery"); + }else if(type == "completed"){ + $(".fourth-1").click(); + $('#accepted').text("PICK-UP"); + $('#accepted').attr("data-value","completed"); + } + // console.log(type); }); jQuery(function(){ - jQuery('.first-1').click(); - }); - - $(".custom-tr").on("click", function(){ - $(".custom-tr").removeClass("tr-active"); - $(this).addClass("tr-active"); - var order_id = $(this).attr("data-id"); - var url = "order_reservation/get_order/"+order_id; - show_order_detail(url); + jQuery('.first-1').click(); }); - //show order list - function show_order_detail(url){ + $(".custom-tr").on("click", function(){ + $(".custom-tr").removeClass("tr-active"); + $(this).addClass("tr-active"); + var order_id = $(this).attr("data-id"); + var sr_no = $(this).attr("data-sr-no"); + var url = "order_reservation/get_order/"+order_id; + show_order_detail(url,sr_no); + }); + + function refreshDetailData(){ + $("#sr_number").text(""); + $("#delivery_info").text(""); + $("#contact_info").text(""); + $('.summary-items').html(""); + $('#sub_total').text("0.00"); + $('#delivery_fee').text("0.00"); + $('#total_charges').text("0.00"); + $('#total_tax').text("0.00"); + $('#grand_total').text("0.00"); + } + + //show order list + function show_order_detail(url,sr_no){ + $('.summary-items').html(""); //Start Ajax $.ajax({ type: "GET", @@ -40,96 +59,131 @@ $(function() { data: {}, dataType: "json", success: function(data) { - var delivery = data["delivery"] - var items = data["order_items"] + // console.log(data); + var delivery = data["delivery"]; + var items = data["order_items"]; - var item_list = $('.summary-items'); + var item_list = $('.summary-items'); item_list.empty(); - for(var i in items) { - var total = items[i].qty*items[i].unit_price; - row = '' - +''+items[i].item_name - +'
'+items[i].qty+ ' X'+items[i].unit_price+'' - +'' - +''+ total +'' - +''; - $('.summary-items').append(row); + if(items!=undefined && items!=""){ + if(items.length > 0){ + for(var i in items) { + var item_price = 0; + if(items[i].price > 0){ + item_price = items[i].price; + }else{ + item_price = items[i].unit_price; + } + var total = items[i].qty * item_price; + row = '' + +''+items[i].item_name + +'
'+items[i].qty+ ' X'+items[i].unit_price+'' + +'' + +''+ total +'' + +''; + $('.summary-items').append(row); + } + + $('#sub_total').text(data.total_amount); + $('#delivery_fee').text(delivery.delivery_fee); + $('#total_charges').text(0); + $('#total_tax').text(data.total_tax); + $('#grand_total').text(data.grand_total); + + var address = delivery.address +', ' +delivery.township+", (" +delivery.direction_address+")" + $('#customer_name').text(data.customer_name); + $('#phone').text(data.phone); + $('#address').text(address); + $('#delivery_to').text(delivery.provider); + + $('#ref_no').text(data.transaction_ref); + $('#callback_url').text(data.callback_url); + $('#order_id').text(data.order_reservation_id); + + if(delivery.provider == "direct_delivery"){ + $("#delivery_info").text("(DELIVERY)"); + }else if(delivery.provider == "self_pick_up"){ + $("#delivery_info").text("(PICK-UP)"); + } + + if(data.order_remark!=null && data.order_remark!=""){ + $("#order_remark").text(data.order_remark); + }else if(data.reservation_remark!=null && data.reservation_remark!=""){ + $("#order_remark").text(data.reservation_remark); + } + $("#sr_number").text("No."+sr_no); + $("#contact_info").text(); + } } - - $('#sub_total').text(data.total_amount); - $('#delivery_fee').text(delivery.delivery_fee); - $('#total_charges').text(0); - $('#total_tax').text(data.total_tax); - $('#grand_total').text(data.grand_total); - - var address = delivery.address +', ' +delivery.township+", (" +delivery.direction_address+")" - $('#customer_name').text(data.customer_name); - $('#phone').text(data.phone); - $('#address').text(address); - $('#delivery_to').text(delivery.provider); - - $('#ref_no').text(data.transaction_ref); - $('#callback_url').text(data.callback_url); - $('#order_id').text(data.order_reservation_id); } }); //end Ajax } $("#accepted").on("click", function(){ - var status = $(this).attr("data-value"); + var status = $(this).attr("data-value"); var order_id = $('#order_id').text(); - var url = 'order_reservation/update'; + var ref_no = $('#ref_no').text(); var callback = $('#callback_url').text(); - $.ajax({ - type: "POST", - url: url, - data: {'order_id': order_id, 'status': status}, - dataType: "json", - success: function(data) { - console.log(data) - if (data.status) { - // callback_url(callback,data.message) - swal("Information","Order has been +'data.status'+","success"); - window.location.href = '/origami/order_reservation'; - } - } - }); + callback_url(callback,ref_no,order_id,status); }); $("#cancel").on("click", function(){ - var status = $(this).attr("data-value"); + var status = $(this).attr("data-value"); var order_id = $('#order_id').text(); - var url = 'order_reservation/update'; var callback = $('#callback_url').text(); - $.ajax({ - type: "POST", - url: url, - data: {'order_id': order_id, 'status': status}, - dataType: "json", - success: function(data) { - console.log(data) - if (data.status) { - console.log(data) - // callback_url(callback,data.message) - swal("Information","Order has been +'data.status'+","warning"); - window.location.href = '/origami/order_reservation'; - } - } - }); + var ref_no = $('#ref_no').text(); + callback_url(callback,ref_no,order_id,status); }); - function callback_url(url,message){ + function callback_url(callback,ref_no,order_id,status){ + var url = 'order_reservation/update'; + var post_url = "order_reservation/send_status"; $.ajax({ type: "POST", - url: url, - data: {}, + url: post_url, + data: {url: callback, ref_no: ref_no, status: status}, dataType: "json", success: function(data) { - + if(data.status){ + $.ajax({ + type: "POST", + url: url, + data: {'order_id': order_id, 'status': status}, + dataType: "json", + success: function(data) { + console.log(data); + if (data.status) { + swal({ + title: 'Information', + text: "Order has been "+data.message, + type: 'success', + html: true, + closeOnConfirm: false, + closeOnCancel: false, + allowOutsideClick: false + }, function () { + window.location.href = '/origami/order_reservation'; + }); + } + } + }); + }else{ + swal({ + title: 'Oops', + text: data.message, + type: 'error', + html: true, + closeOnConfirm: false, + closeOnCancel: false, + allowOutsideClick: false + }, function () { + window.location.href = '/origami/order_reservation'; + }); + } } }); } +}); -}); \ No newline at end of file diff --git a/app/controllers/api/api_controller.rb b/app/controllers/api/api_controller.rb index 973fc159..2340abd4 100755 --- a/app/controllers/api/api_controller.rb +++ b/app/controllers/api/api_controller.rb @@ -1,7 +1,7 @@ class Api::ApiController < ActionController::API include TokenVerification - before_action :lookup_domain + # before_action :lookup_domain helper_method :current_token, :current_login_employee, :get_cashier private diff --git a/app/controllers/concerns/token_verification.rb b/app/controllers/concerns/token_verification.rb index 2c17e258..f8602ded 100755 --- a/app/controllers/concerns/token_verification.rb +++ b/app/controllers/concerns/token_verification.rb @@ -13,12 +13,12 @@ module TokenVerification authenticate_token || render_unauthorized end - def authenticate_token + def authenticate_token authenticate_with_http_token do |token, options| # Rails.logger.debug "token - " + token.to_s if(options.length !=0 && options["from"] == "DOEMAL") if(ENV["SERVER_MODE"] === "cloud") - from = request.subdomain.downcase + "." + request.domain.downcase + from = "local" #request.subdomain.downcase + "." + request.domain.downcase aes = MyAesCrypt.new return aes.checkKeyForAuth(from, token) end diff --git a/app/controllers/origami/customers_controller.rb b/app/controllers/origami/customers_controller.rb index fefb973e..537703a1 100755 --- a/app/controllers/origami/customers_controller.rb +++ b/app/controllers/origami/customers_controller.rb @@ -169,6 +169,8 @@ class Origami::CustomersController < BaseOrigamiController sale_audit = SaleAudit.record_audit_for_edit(sale.sale_id,sale.cashier_id, action_by,remark,"PAYBYACCOUNT" ) end @out = membership_data + + render json: JSON.generate({:status => membership_data["status"], :message => membership_data["message"]}) end end end diff --git a/app/controllers/origami/dinga_controller.rb b/app/controllers/origami/dinga_controller.rb index 448b39dd..586403f9 100644 --- a/app/controllers/origami/dinga_controller.rb +++ b/app/controllers/origami/dinga_controller.rb @@ -4,32 +4,32 @@ class Origami::DingaController < BaseOrigamiController payment_method = params[:payment_method] @cashier_type = params[:type] @membership_rebate_balance=0 - sale_data = Sale.find_by_sale_id(@sale_id) - @receipt_no = sale_data.receipt_no + @sale_data = Sale.find_by_sale_id(@sale_id) + @receipt_no = @sale_data.receipt_no @shop = Shop.first # if @shop.is_rounding_adj - # new_total = Sale.get_rounding_adjustment(sale_data.grand_total) + # new_total = Sale.get_rounding_adjustment(@sale_data.grand_total) # else - # new_total = sale_data.grand_total + # new_total = @sale_data.grand_total # end - # @rounding_adj = new_total-sale_data.grand_total - @rounding_adj = sale_data.rounding_adjustment + # @rounding_adj = new_total-@sale_data.grand_total + @rounding_adj = @sale_data.rounding_adjustment @payparcount = 0 others = 0 - sale_data.sale_payments.each do |sale_payment| + @sale_data.sale_payments.each do |sale_payment| if sale_payment.payment_method == "dinga" @payparcount = @payparcount + sale_payment.payment_amount else others = others + sale_payment.payment_amount end end - @payment_prices = sale_data.grand_total - @payparcount -others + @payment_prices = @sale_data.grand_total - @payparcount -others - if sale_data - if sale_data.customer_id - customer_data= Customer.find_by_customer_id(sale_data.customer_id) + if @sale_data + if @sale_data.customer_id + customer_data= Customer.find_by_customer_id(@sale_data.customer_id) if customer_data @membership_id = customer_data.membership_id if !@membership_id.nil? @@ -73,6 +73,7 @@ def create cash = params[:payment_amount] sale_id = params[:sale_id] transaction_ref = params[:transaction_ref] + account_no = params[:account_no] if(Sale.exists?(sale_id)) saleObj = Sale.find(sale_id) shop_details = Shop.first @@ -85,7 +86,7 @@ def create # saleObj = Sale.find(sale_id) sale_payment = SalePayment.new - status, @sale = sale_payment.process_payment(saleObj, @user, cash, "dinga",transaction_ref) + status, @sale = sale_payment.process_payment(saleObj, @user, cash, "dinga",account_no) if status == true @out = true, "Success!" else diff --git a/app/controllers/origami/order_reservation_controller.rb b/app/controllers/origami/order_reservation_controller.rb index a90e755b..562eaaed 100644 --- a/app/controllers/origami/order_reservation_controller.rb +++ b/app/controllers/origami/order_reservation_controller.rb @@ -7,22 +7,29 @@ class Origami::OrderReservationController < BaseOrigamiController def update @id = params[:order_id] @status = params[:status] - @order = OrderReservation.find(@id) + @order_reservation = OrderReservation.find(@id) status = true if status if @status == "processed" - OrderReservation.create_doemal_order(@order) - else + result = OrderReservation.create_doemal_order(@order_reservation,current_user) + elsif @status == "delivery" + OrderReservation.update_order_reservation(@id, nil, "ready_to_delivery") + response = OrderReservation.send_status_to_ordering(@order_reservation.callback_url,@order_reservation.transaction_ref,"ready_to_delivery") + result = {:status=> true, :message => "ready for delivery" } + elsif @status == "completed" + result = OrderReservation.update_doemal_payment(@order_reservation,current_user) + else if @status == "cancel" - result = {:status=> true, :message => "cancelled" } + OrderReservation.update_order_reservation(@id, nil, "cancelled") + result = {:status=> true, :message => "rejected" } else + OrderReservation.update_order_reservation(@id, nil, "accepted") result = {:status=> true, :message => "accepted" } end - render :json => result.to_json end - + render :json => result.to_json else result = {:status=> false, :message => "Order not accepted !" } render :json => result.to_json @@ -36,5 +43,16 @@ class Origami::OrderReservationController < BaseOrigamiController end end + def send_status + if params[:status] == "cancel" + status = "rejected" + else + status = params[:status] + end + + response = OrderReservation.send_status_to_ordering(params[:url],params[:ref_no],status) + + render :json => response + end end diff --git a/app/controllers/origami/paymal_controller.rb b/app/controllers/origami/paymal_controller.rb index 65af0c3b..1321cf87 100644 --- a/app/controllers/origami/paymal_controller.rb +++ b/app/controllers/origami/paymal_controller.rb @@ -73,6 +73,8 @@ def create cash = params[:payment_amount] sale_id = params[:sale_id] transaction_ref = params[:transaction_ref] + account_no = params[:account_no] + puts params.to_json if(Sale.exists?(sale_id)) saleObj = Sale.find(sale_id) shop_details = Shop.first @@ -86,7 +88,7 @@ def create # saleObj = Sale.find(sale_id) sale_payment = SalePayment.new - status, @sale = sale_payment.process_payment(saleObj, @user, cash, "paymal",transaction_ref) + status, @sale = sale_payment.process_payment(saleObj, @user, cash, "paymal",account_no) if status == true @out = true, "Success!" else diff --git a/app/controllers/settings/menus_controller.rb b/app/controllers/settings/menus_controller.rb index 0264084c..bc92a959 100755 --- a/app/controllers/settings/menus_controller.rb +++ b/app/controllers/settings/menus_controller.rb @@ -167,8 +167,9 @@ class Settings::MenusController < ApplicationController # end end - p.serialize("tmp/menus/" + menu.name + ".xlsx") - render :json => {status: true} + file_path = "public/menus/" + menu.name + ".xlsx" + p.serialize(file_path) + render :json => { status: true, path: file_path } end def import diff --git a/app/models/customer.rb b/app/models/customer.rb index 3eb51a24..c380f24b 100755 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -354,6 +354,11 @@ class Customer < ApplicationRecord #new customer for doemal def self.addCustomer(params) + if params[:gender] == "female" + gender = "Female" + else + gender = "Male" + end customer = Customer.new customer.name = params[:name] customer.email = params[:email] diff --git a/app/models/menu.rb b/app/models/menu.rb index 8bf616c9..28b23c76 100755 --- a/app/models/menu.rb +++ b/app/models/menu.rb @@ -160,7 +160,7 @@ class Menu < ApplicationRecord account = Account.create({title: row["Account"], account_type: "0"}) end - menu_itm = MenuItem.create(item_code: row["Item Code"], name: row["Item Name"], account_id: account.id, alt_name: row["Item AltName"], image_path: "", description: '', information: '', unit: '', type: "SimpleMenuItem", menu_category_id: menu_cat.id, item_attributes: "[]", item_options: "[]", account_id: account_id, is_sub_item: 0, is_available: 1, created_by: created_by) + menu_itm = MenuItem.create(item_code: row["Item Code"], name: row["Item Name"], account_id: account.id, alt_name: row["Item AltName"], image_path: "", description: '', information: '', unit: '', type: "SimpleMenuItem", menu_category_id: menu_cat.id, item_attributes: "[]", item_options: "[]", is_sub_item: 0, is_available: 1, created_by: created_by) # else # status = status + "Item Code already exists for " + row["Item Name"] + "." end diff --git a/app/models/order_reservation.rb b/app/models/order_reservation.rb index e23f852e..2fa99cf4 100644 --- a/app/models/order_reservation.rb +++ b/app/models/order_reservation.rb @@ -7,13 +7,18 @@ class OrderReservation < ApplicationRecord has_many :order_reservation_items belongs_to :delivery + SEND_TO_KITCHEN = "send_to_kitchen" + READY_TO_DELIVERY = "ready_to_deliver" + DELIVERED = "delivered" + COMPLETED = "completed" + def self.addOrderReservationInfo(params) check_order_reservation = OrderReservation.where("transaction_ref = ?",params[:reference]) if check_order_reservation.empty? order_reservation = OrderReservation.new order_reservation.order_reservation_type = params[:order_type] order_reservation.customer_id = params[:cus_info] - order_reservation.requested_time = Time.parse(params[:requested_time]).utc.strftime("%Y-%m-%d %H:%M:%S") + order_reservation.requested_time = DateTime.parse(params[:requested_time]).utc.strftime("%Y-%m-%d %H:%M:%S") order_reservation.callback_url = params[:callback_url] order_reservation.transaction_ref = params[:reference] if params[:order_info] @@ -48,53 +53,204 @@ class OrderReservation < ApplicationRecord end end - def self.create_doemal_order(order) - - is_extra_time = false - extra_time = '' + def self.create_doemal_order(order,current_user) + is_extra_time = false + extra_time = '' - items_arr = [] - count = 1 - order.order_reservation_items.each { |i| - i.item_instance_code = i.item_instance_code.downcase.to_s - - items = {"order_item_id": count,"item_instance_code": i.item_instance_code,"quantity": i.qty,"options": []} - count += 1 - items_arr.push(items) - } + items_arr = [] + count = 1 + order.order_reservation_items.each { |i| + i.item_instance_code = i.item_instance_code.downcase.to_s + items = {"order_item_id": count,"item_instance_code": i.item_instance_code,"quantity": i.qty,"options": []} + count += 1 + items_arr.push(items) + } - puts items_arr.to_json - puts "sssssssssssssssssssssss" - customer_id = order.customer_id + puts items_arr.to_json + puts "sssssssssssssssssssssss" + customer_id = order.customer_id - @order = Order.new - @order.source = "doemal_order" - @order.order_type = "delivery" - @order.customer_id = customer_id - @order.items = items_arr - @order.guest = '' - @order.table_id = nil # this is dining facilities's id - @order.new_booking = true - @order.waiters = current_login_employee.name - @order.employee_name = current_login_employee.name + @order = Order.new + @order.source = "doemal_order" + @order.order_type = "delivery" + @order.customer_id = customer_id + @order.items = items_arr + @order.guest = '' + @order.table_id = nil # this is dining facilities's id + @order.new_booking = true + @order.waiters = current_user.name + @order.employee_name = current_user.name - @order.is_extra_time = is_extra_time - @order.extra_time = extra_time + @order.is_extra_time = is_extra_time + @order.extra_time = extra_time - @status, @booking = @order.generate + @status, @booking = @order.generate - # Order.send_customer_view(@booking) - - + # Order.send_customer_view(@booking) if @status && @booking - @status, @sale = Sale.request_bill(@order,current_user,current_login_employee) - # for second display + @status, @sale = Sale.request_bill(@order,current_user,current_user) - result = {:status=> @status, :data => @sale } - render :json => result.to_json + #order status send to doemal + callback_response = send_status_to_ordering(order.callback_url,order.transaction_ref,SEND_TO_KITCHEN) + #order reservation status updated + update_order_reservation(order.id, @sale.sale_id, SEND_TO_KITCHEN) + + result = {:status=> @status, :data => @sale, :message => "created" } + return result end - + end + + def self.update_doemal_payment(order,current_user) + if(Sale.exists?(order.sale_id)) + saleObj = Sale.find(order.sale_id) + shop_details = Shop.first + # rounding adjustment + if shop_details.is_rounding_adj + 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) + end + end + #end rounding adjustment + + sale_payment = SalePayment.new + sale_payment.process_payment(saleObj, current_user.name, saleObj.grand_total, "cash") + + #order status send to doemal + callback_response = send_status_to_ordering(order.callback_url,order.transaction_ref,DELIVERED) + #order reservation status updated + update_order_reservation(order.id, saleObj.sale_id, DELIVERED) + + result = {:status=> true, :message => DELIVERED } + return result + # rebate_amount = nil + + # For Cashier by Zone + # bookings = Booking.where("sale_id='#{sale_id}'") + + # if bookings[0].dining_facility_id.to_i > 0 + # table = DiningFacility.find(bookings[0].dining_facility_id) + # cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id) + # cashier_terminal = CashierTerminal.find(cashier_zone.cashier_terminal_id) + # else + # shift = ShiftSale.find(saleObj.shift_sale_id) + # cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id) + # end + + # For Print + # if ENV["SERVER_MODE"] != "cloud" #no print in cloud server + # receipt_bill_a5_pdf = Lookup.collection_of("print_settings") #print_settings with name:ReceiptBillA5Pdf + # unique_code = "ReceiptBillPdf" + # if !receipt_bill_a5_pdf.empty? + # receipt_bill_a5_pdf.each do |receipt_bilA5| + # if receipt_bilA5[0] == 'ReceiptBillA5Pdf' + # if receipt_bilA5[1] == '1' + # unique_code = "ReceiptBillA5Pdf" + # else + # unique_code = "ReceiptBillPdf" + # end + # end + # end + # end + + # customer= Customer.find(saleObj.customer_id) + + # get member information + # rebate = MembershipSetting.find_by_rebate(1) + # credit_data = SalePayment.find_by_sale_id_and_payment_method(sale_id,'creditnote') + + # if customer.membership_id != nil && rebate && credit_data.nil? + # member_info = Customer.get_member_account(customer) + # if member_info["status"] == true + # rebate_amount = Customer.get_membership_transactions(customer,saleObj.receipt_no) + # current_balance = SaleAudit.paymal_search(sale_id) + # end + # end + + #orders print out + # if params[:type] == "quick_service" + # booking = Booking.find_by_sale_id(sale_id) + # if booking.dining_facility_id.to_i>0 + # table_id = booking.dining_facility_id + # else + # table_id = 0 + # end + + # booking.booking_orders.each do |order| + # # Order.pay_process_order_queue(order.order_id, table_id) + # oqs = OrderQueueStation.new + # oqs.pay_process_order_queue(order.order_id, table_id) + # end + + # end + + #for card sale data + # card_data = Array.new + # card_sale_trans_ref_no = Sale.getCardSaleTrans(sale_id) + # if !card_sale_trans_ref_no.nil? + # card_sale_trans_ref_no.each do |cash_sale_trans| + # card_res_date = cash_sale_trans.res_date.strftime("%Y-%m-%d").to_s + # card_res_time = cash_sale_trans.res_time.strftime("%H:%M").to_s + # card_no = cash_sale_trans.pan.last(4) + # card_no = card_no.rjust(19,"**** **** **** ") + # card_data.push({'res_date' => card_res_date, 'res_time' => card_res_time, 'batch_no' => cash_sale_trans.batch_no, 'trace' => cash_sale_trans.trace, 'pan' => card_no, 'app' => cash_sale_trans.app, 'tid' => cash_sale_trans.terminal_id, 'app_code' => cash_sale_trans.app_code, 'ref_no' => cash_sale_trans.ref_no, 'mid' => cash_sale_trans.merchant_id}) + # end + # end + + # get printer info + # print_settings=PrintSetting.find_by_unique_code(unique_code) + # Calculate Food and Beverage Total + # item_price_by_accounts = SaleItem.calculate_price_by_accounts(saleObj.sale_items) + # discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(saleObj.sale_items) + + # printer = Printer::ReceiptPrinter.new(print_settings) + # filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings,cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details, "Paid",current_balance,card_data) + + # render json: JSON.generate({:status => saleObj.rebate_status, :message => "Can't Rebate coz of Sever Error ", :filename => filename, :receipt_no => sale_receipt_no, :printer_name => printer_name}) + + #end + end + end + + def self.send_status_to_ordering(url,ref_no,status) + base_url = "http://192.168.1.186:3002" + post_url = base_url + url + + begin + response = HTTParty.post(post_url, + :body => { id: ref_no, status: status}.to_json, + :headers => { + 'Authorization' => 'Token token=3T-tnlYtFJ-5Z1vY6XQqxQ', + 'Content-Type' => 'application/json', + 'Accept' => 'application/json; version=3' + }, :timeout => 10 + ) + rescue Net::OpenTimeout + response = { status: false } + + rescue OpenURI::HTTPError + response = { status: false} + rescue SocketError + response = { status: false} + end + Rails.logger.debug "Get Doemal Status " + Rails.logger.debug response.to_json + return response + end + + def self.update_order_reservation(id, sale_id, status) + order_reservation = OrderReservation.find(id) + if sale_id.present? + order_reservation.sale_id = sale_id + end + order_reservation.status = status + order_reservation.save end private diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 201a1b57..29d755d7 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -197,13 +197,14 @@ class SalePayment < ApplicationRecord def self.create_payment(paypar_url,token,membership_id,received_amount,sale_id) membership_actions_data = MembershipAction.find_by_membership_type("create_payment"); - + sale_data = Sale.find_by_sale_id(sale_id) + customer_data = Customer.find_by_customer_id(sale_data.customer_id) if !membership_actions_data.nil? url = paypar_url.to_s + membership_actions_data.gateway_url.to_s merchant_uid = membership_actions_data.merchant_account_id auth_token = membership_actions_data.auth_token - sale_data = Sale.find_by_sale_id(sale_id) + if sale_data others = 0 @@ -211,14 +212,27 @@ class SalePayment < ApplicationRecord others = others + sale_payment.payment_amount end payment_prices = sale_data.grand_total - others - # Control for Paypar Cloud - begin - response = HTTParty.post(url, - :body => { membership_id:membership_id, + + if membership_id.to_i <= 0 + membership_id = customer_data.membership_id + params = { membership_id:membership_id, amount:received_amount, receipt_no:sale_data.receipt_no, merchant_uid:merchant_uid, - auth_token:auth_token}.to_json, + auth_token:auth_token}.to_json + else + params = { account_no:membership_id, + amount:received_amount, + receipt_no:sale_data.receipt_no, + merchant_uid:merchant_uid, + auth_token:auth_token}.to_json + end + + + # Control for Paypar Cloud + begin + response = HTTParty.post(url, + :body => params, :headers => { 'Content-Type' => 'application/json', 'Accept' => 'application/json; version=3' @@ -242,7 +256,7 @@ class SalePayment < ApplicationRecord response =false; end - Rails.logger.debug "Payment response" + Rails.logger.debug "Create Payment response" Rails.logger.debug response.to_json return response; @@ -390,9 +404,13 @@ class SalePayment < ApplicationRecord payment_status = false #Next time - validate if the vochure number is valid - within - customer_data = Customer.find_by_customer_id(self.sale.customer_id) + # customer_data = Customer.find_by_customer_id(self.sale.customer_id) + account_no = self.payment_reference + # if account_no.to_i <= 0 + # account_no = customer_data.membership_id + # end membership_setting = MembershipSetting.find_by_membership_type("paypar_url") - membership_data = SalePayment.create_payment(membership_setting.gateway_url,membership_setting.auth_token,customer_data.membership_id,self.received_amount,self.sale.sale_id) + membership_data = SalePayment.create_payment(membership_setting.gateway_url,membership_setting.auth_token,account_no,self.received_amount,self.sale.sale_id) #record an payment in sale-audit remark = "#{membership_data} PayMal Payment- for Customer #{self.sale.customer_id} Sale Id [#{self.sale.sale_id}]| pay amount -> #{self.received_amount} " @@ -433,9 +451,16 @@ class SalePayment < ApplicationRecord payment_status = false #Next time - validate if the vochure number is valid - within - customer_data = Customer.find_by_customer_id(self.sale.customer_id) + + # customer_data = Customer.find_by_customer_id(self.sale.customer_id) + + account_no = self.payment_reference + # if account_no == 0 + # account_no = customer_data.customer_id + # end + membership_setting = MembershipSetting.find_by_membership_type("paypar_url") - membership_data = SalePayment.create_payment(membership_setting.gateway_url,membership_setting.auth_token,customer_data.membership_id,self.received_amount,self.sale.sale_id) + membership_data = SalePayment.create_payment(membership_setting.gateway_url,membership_setting.auth_token,account_no,self.received_amount,self.sale.sale_id) #record an payment in sale-audit remark = "#{membership_data} Dinga Payment- for Customer #{self.sale.customer_id} Sale Id [#{self.sale.sale_id}]| pay amount -> #{self.received_amount} " diff --git a/app/views/origami/dinga/index.html.erb b/app/views/origami/dinga/index.html.erb index 6a4fc12b..1a7bd798 100644 --- a/app/views/origami/dinga/index.html.erb +++ b/app/views/origami/dinga/index.html.erb @@ -46,6 +46,8 @@
+ + -
+
@@ -214,6 +214,9 @@ 0.00 + + +
-

-

-

-

+ + + +