From c53276f21cd93f03e16512df7385db865488bb47 Mon Sep 17 00:00:00 2001 From: San Wai Lwin Date: Mon, 2 Apr 2018 18:09:36 +0630 Subject: [PATCH 01/18] Add survey's fieldset --- app/views/origami/surveys/_form.html.erb | 157 +++++++++++++------- app/views/settings/employees/index.html.erb | 32 ++-- config/initializers/action_controller.rb | 2 +- 3 files changed, 126 insertions(+), 65 deletions(-) diff --git a/app/views/origami/surveys/_form.html.erb b/app/views/origami/surveys/_form.html.erb index 68c3f59b..1322f677 100755 --- a/app/views/origami/surveys/_form.html.erb +++ b/app/views/origami/surveys/_form.html.erb @@ -6,73 +6,120 @@ <%= f.error_notification %>
<% if !@survey_data.nil? %> - <%= f.input :child, input_html: { value: @survey_data.child, class: 'col-md-10' }%> - <%= f.input :adult, input_html: { value: @survey_data.adult, class: 'col-md-10' }%> - <%= f.input :male , input_html: { value: @survey_data.male, class: 'col-md-10' }%> - <%= f.input :female , input_html: { value: @survey_data.female, class: 'col-md-10' }%> - <%= f.input :total_customer, input_html: { value: @survey_data.total_customer, class: 'col-md-10'} %> - <%= f.input :local , input_html: { value: @survey_data.local, class: 'col-md-10' }%> -
-
+
- - - + <%= f.input :child, input_html: { value: @survey_data.child, class: 'col-md-10' }%>
-
+
- - + <%= f.input :adult, input_html: { value: @survey_data.adult, class: 'col-md-10' }%>
-
-
- -
-
+
+
+
+
+ <%= f.input :male , input_html: { value: @survey_data.male, class: 'col-md-10' }%> +
+
+
+
+ <%= f.input :female , input_html: { value: @survey_data.female, class: 'col-md-10' }%> +
+
+
+ <%= f.input :total_customer, input_html: { value: @survey_data.total_customer, class: 'col-md-11'} %> + <%= f.input :local , input_html: { value: @survey_data.local, class: 'col-md-11' }%> +
+ Foreigner +
+
+
+ + + +
+
+
+
+ + +
+
+
+
+ +
+
+ +
<% else %> - <%= f.input :child , input_html: { class: 'col-md-10' }%> - <%= f.input :adult , input_html: { class: 'col-md-10' }%> - <%= f.input :male , input_html: { class: 'col-md-10' }%> - <%= f.input :female , input_html: { class: 'col-md-10' }%> - <%= f.input :total_customer, input_html: { class: 'col-md-10'} %> - <%= f.input :local , input_html: { class: 'col-md-10' }%> -
-
+
- - - + <%= f.input :child , input_html: { class: 'col-md-10' }%>
-
+
- - + <%= f.input :adult , input_html: { class: 'col-md-10' }%>
-
-
- -
-
- <% end %> - +
+
+
+ <%= f.input :male , input_html: { class: 'col-md-10' }%> +
+
+
+
+ <%= f.input :female , input_html: { class: 'col-md-10' }%> +
+
+
+ <%= f.input :total_customer, input_html: { class: 'col-md-11'} %> + <%= f.input :local , input_html: { class: 'col-md-11' }%> -
+
+ Foreigner +
+
+
+ + + +
+
+
+
+ + +
+
+
+
+ +
+
+ +
+ <% end %> + <%if !@dining_facility.nil? %> @@ -95,8 +142,8 @@ <%= f.input :created_by, :as => :hidden, :input_html => { :value => current_login_employee.name } %> <%= f.input :receipt_no, :as => :hidden, :input_html => { :value => @receipt_no} %> <%= f.input :total_amount, :as => :hidden, :input_html => { :value => @grand_total } %> -
-
+
+
<%= f.submit "Submit",:class => 'btn btn-primary btn-lg waves-effect' %>
<% end %> @@ -202,7 +249,7 @@ var cashier_type = "<%= @cashier_type %>"; $('#newTemplate').removeClass('hidden'); var text_box = '
' - +'
' + +'
' +'
' +' ' +'
' +'
' - +'
' + +'
' +'
' +'' +'
' diff --git a/app/views/settings/employees/index.html.erb b/app/views/settings/employees/index.html.erb index 7aeee2ec..f47cc8e5 100755 --- a/app/views/settings/employees/index.html.erb +++ b/app/views/settings/employees/index.html.erb @@ -27,15 +27,29 @@ <% @employees.each do |employee| %> - - <%= link_to employee.name,settings_employee_path(employee) %> - <%= employee.role %> - <%= employee.created_at.utc.getlocal.strftime("%Y-%m-%d/%I:%M %p") %> - <%= employee.updated_at.utc.getlocal.strftime("%Y-%m-%d/%I:%M %p") %> - - <%= link_to t("views.btn.edit"), edit_settings_employee_path(employee),:class => 'btn btn-info btn-sm waves-effect' %> - - + <% if current_login_employee.role == "administrator" %> + + <%= link_to employee.name,settings_employee_path(employee) %> + <%= employee.role %> + <%= employee.created_at.utc.getlocal.strftime("%Y-%m-%d/%I:%M %p") %> + <%= employee.updated_at.utc.getlocal.strftime("%Y-%m-%d/%I:%M %p") %> + + <%= link_to t("views.btn.edit"), edit_settings_employee_path(employee),:class => 'btn btn-info btn-sm waves-effect' %> + + + <% else %> + <% if employee.role != "administrator" %> + + <%= link_to employee.name,settings_employee_path(employee) %> + <%= employee.role %> + <%= employee.created_at.utc.getlocal.strftime("%Y-%m-%d/%I:%M %p") %> + <%= employee.updated_at.utc.getlocal.strftime("%Y-%m-%d/%I:%M %p") %> + + <%= link_to t("views.btn.edit"), edit_settings_employee_path(employee),:class => 'btn btn-info btn-sm waves-effect' %> + + + <% end %> + <% end %> <% end %> diff --git a/config/initializers/action_controller.rb b/config/initializers/action_controller.rb index dcfcfed5..b063f28e 100644 --- a/config/initializers/action_controller.rb +++ b/config/initializers/action_controller.rb @@ -12,7 +12,7 @@ class ActionController::Base ActiveRecord::Base.establish_connection(website_connection(@license)) # authenticate_session_token # logger.info "Connecting to - " + @license.subdomain + " - "+ @license.dbhost + "@" + @license.dbschema - else + else8 # reconnect_default_db logger.info 'License is nil' # redirect_to root_url(:host => request.domain) + "store_error" From 650eb53f5109a7a2bc5e4542fb37c8bb2ff328ec Mon Sep 17 00:00:00 2001 From: San Wai Lwin Date: Mon, 2 Apr 2018 18:10:47 +0630 Subject: [PATCH 02/18] Pull from master --- Main Menu.xlsx | Bin 0 -> 3997 bytes app/assets/javascripts/addorder.js | 17 +- app/assets/javascripts/custom.js | 6 +- app/controllers/oqs/edit_controller.rb | 50 ++-- app/controllers/oqs/print_controller.rb | 2 +- .../origami/payments_controller.rb | 10 +- app/controllers/settings/menus_controller.rb | 109 ++++++++- app/models/menu.rb | 217 +++++++++++------- app/models/menu_category.rb | 2 +- app/models/menu_item.rb | 48 ++-- app/models/sale.rb | 4 +- app/models/sale_payment.rb | 6 +- app/views/layouts/_header.html.erb | 4 +- app/views/origami/home/show.html.erb | 2 +- app/views/origami/rooms/show.html.erb | 2 +- app/views/settings/menus/export.html.erb | 0 app/views/settings/menus/index.html.erb | 27 ++- config/routes.rb | 6 +- lib/tasks/clear_data.rake | 2 +- 19 files changed, 351 insertions(+), 163 deletions(-) create mode 100644 Main Menu.xlsx create mode 100644 app/views/settings/menus/export.html.erb diff --git a/Main Menu.xlsx b/Main Menu.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..94c703382ba6733020ef9e02db8febb2b38c130b GIT binary patch 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<>c2%GaD225ieg`e3jh$JBH#_-a)EWHCCPydH+cE$*>Ux zx;kLBWw3P-Y~~gqFm$@WULn<@ABuPOFuqee9m266|BS=hFbw}4Wgr^EeWGbcZ7ca z2G*3a%jvTSJ{etsiu`mfU#ufh-UsBkO2?Sh&vsy_9Glsi5<6(|?J;D$xOX=^W>{mC zKH6!H3i+VTJ=NrFo((@Z6;URV4~g*rNvu8DNZSb2z^31Gg@xm2Q-W_}Lu~nJcOZ3z zO*4h#4`cYbii)J=*1!UVbpq&yj=o*2K8_KGKb^-^uo^d`arYs50e241iGqr_ULRHr zpxF+ln?n?jAnlPUk2AONKb|Exp}q1u5#MRn<*dxaxlA{Yll89ZkxZ2%c$F^7+eDYT zn%pT+wN>db#ujbiwm zupP=~-_bZ3bF|#?DP>kQF?x~<4n*@rARKwjq2|+j{eyfirqu5q!3D6#hZ-$ae4vs( zP;FYH_cMVnlS2H4!#9`%{0DP|Zf|BE*icLj*$2~=@GhkLFHQ&!FJII(0?*qj0o7pN zkhy#EZ>xem+dZ8qn3`g~Yg7Iey30yL}-gb|M%-w`Y<@t0Y?Dz3%p9}KkJ$Zz>w zo=XZ94~ftKfK}8YMak3B*+SjT*~Oj9!r9I0N}`T&eW+tfB75>ocG=&&;mMPVcqrN? z9urfr#5Z;uxc(>NsXW|3wZ#wgiS=o9HnE@K<{|~0Lcxb$*2zYqGcl^UW5ygKXSa;% zB@u-rFx;j2uT=P)3VS_*d1B-rWWq_m3G2jI?tjTle)dS zg)zI=y3h1@8zN(4#b}*-;c7$yMwiCMgYG3;Q(RUlg_+<#WZ_&0CYn!Z!ToH>jLl_J zxO-ka#Q1PWZGWxr(BOytgBoH(d>5xqJp-F zS|q;)&&!b+2r!@(RKI;`SdzAJ&bu>J-vWSC92II`QMbhZibyYHu< zl6&@v=Xa- zYY}TA#)4FhK)FEL1z%>I-y@2AtNW9poqxU*#6MJZ<3%CPXFFl(%iiZ+dEJR+tO|k# zf%9-y?%6)pNCgs~-SsaoPEeDlJ}y@7Mpt}G-n3kay~`_u;ULPq zmH;O!j|MM#I7{?-1y`ij<(nan4TQTQt8`Lc_UOj5lZ)mdSfj4T;B9OL+u*Xvv>{zI zV@$_qniWIa24|nN`#O&)(eU+;bSnhbPT4UEZ>P!7GI+zs=!H_=tHeZTY+C{s%>?`? z9-I=0C)L@MuPkEP*VWePzFHHjH|LdeNa#_l?_!@Vy>*LNFyPn?xS=9Bn|DvTP_bl3#g+Ik75%E87`1_`8sB_K5w~j~{FJ@` zz7x!R#2pC~m9U-R*SFB|{IGu-5);YBf_Qsz@evu2JC*hX%quim%*L$%3|GL$rrT}! z$_HsUZg=}(DGqm2*);9-u`B*+*1qg9fUhwX&EB)d+uOFuu>L|dLTKQ)qA&w;5I3JU z+#Lw^1}!}=6HO!2XpY1g6i+G^?v!2Nno3Qc=W{YHoNimUku5j!JDQlY?`DCPbMf@k zZeXn9on-wWl!NP1Z%AKAS9|3(-Gvg*{Vt^ydrD zzfX`>v@#JoJqhMXM({so?b1Sdu#%CW)@bZMCed9_Lzugk`ZSUfb;`yL6dSxXmvk$` zMwuklJy%GpCS2ymmoRU?bE-y&6A)EYQYQ6NOYI&-b#tm$iY6-gun&ES-v*|Bwnz5) zw(IrseVD_d3=MqZetJXt77ToH&rq`0LiJ#j|KanswFX{b$_(IqvA-1w6*%JTDBG8>m=7nSi+|H=z1gR=y1X-uIU3(b% zAvOf7dG^@Lb461$Q z^Qk~k4^J{ND%;}q8zZdzy3Y5aXaS$o(3B1eai0~kuCkzgFyZ-51P2=JazX?Zoy;x; zlIJP3o)!vPmcv#aTAT^UQ54c4T+GI{BPh?`fAS_~sS$ZyqOoyXtWwFrqrSj*e{5Rb zgSa4;2A(5<+|RP>^3-Fa$7iqo`h!qPI*Z~1a%W~|kqa@_m>SmO|Ce1Jh_B|$b9FOg%dJ+s_MH5ezO zG4tjFwW_phf1%XR*RQNhj(r71=%w;cESqTt*{L>E@WV$Lw4Y|PIP#@+xrQuHow2Vg zA*k0Tspa|V;O_xp;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 literal 0 HcmV?d00001 diff --git a/app/assets/javascripts/addorder.js b/app/assets/javascripts/addorder.js index 47c6cd4f..31209c99 100755 --- a/app/assets/javascripts/addorder.js +++ b/app/assets/javascripts/addorder.js @@ -381,16 +381,18 @@ $(function() { item = get_set_item(items); customer_display_view(item,"set_add"); - var option = '' + var option = [] attribute_arr = [] var rowCount = $('.summary-items tbody tr').length+1; code = $('.set-item').attr('data-code'); name = $('.set-item').attr('data-name'); price = $('.set-item').attr('data-price'); - option = ($('.set-item').attr('data-options') === 'undefined') ? '' :$('.set-item').attr('data-options'); + option_name = ($('.set-item').attr('data-options') === 'undefined') ? '' :$('.set-item').attr('data-options'); + option = ($('.set-item').attr('data-options') === '') ? '[]' :$('.set-item').attr('data-options'); parent = $('.set-item').attr('data-parent'); total = qty * price ; + row ="" +''+rowCount+'' - +'' + item_name+ ' ' + name +' ' + option +'' + +'' + item_name+ ' ' + name +' ' + option_name +'' +'' + qty + '' +'' + parseFloat(total).toFixed(2) @@ -406,15 +408,16 @@ $(function() { +''; $(".summary-items tbody").append(row); var rowCount = $('.summary-items tbody tr').length+1; - var set_option = '' + var set_option = [] $(items).each(function(i){ code = $(items[i]).attr('data-code'); name = $(items[i]).attr('data-name'); price = $(items[i]).attr('data-price'); - set_option = ($(items[i]).attr('data-options') === 'undefined') ? ' ' :$(items[i]).attr('data-options'); - + set_option_name = ($(items[i]).attr('data-options') === 'undefined') ? ' ' :$(items[i]).attr('data-options'); + set_option= ($(items[i]).attr('data-options') === '') ? '[]' :$(items[i]).attr('data-options'); sub_item = $(items[i]).attr('data-sub-item'); total = qty * price ; + row ="" +''+rowCount+'' - +'' + item_name+ ' ' + name +' ' + set_option +'' + +'' + item_name+ ' ' + name +' ' + set_option_name +'' +'' + qty + '' +'' + parseFloat(total).toFixed(2) diff --git a/app/assets/javascripts/custom.js b/app/assets/javascripts/custom.js index 778de553..c6e6a47b 100644 --- a/app/assets/javascripts/custom.js +++ b/app/assets/javascripts/custom.js @@ -10,7 +10,7 @@ $(document).ready(function() { alwaysVisible: false, borderRadius: '0', railBorderRadius: '0', - touchScrollStep : 25 + touchScrollStep : 50 }); $('#order-detail-slimscroll').slimScroll({ @@ -20,7 +20,7 @@ $(document).ready(function() { alwaysVisible: false, borderRadius: '0', railBorderRadius: '0', - touchScrollStep : 25 + touchScrollStep : 50 }); $('#menu-slimscroll').slimScroll({ @@ -30,7 +30,7 @@ $(document).ready(function() { alwaysVisible: false, borderRadius: '0', railBorderRadius: '0', - touchScrollStep : 25 + touchScrollStep : 50 }); // $('.delete').click(function(){ diff --git a/app/controllers/oqs/edit_controller.rb b/app/controllers/oqs/edit_controller.rb index ccef4e4a..049bbda6 100644 --- a/app/controllers/oqs/edit_controller.rb +++ b/app/controllers/oqs/edit_controller.rb @@ -36,33 +36,39 @@ class Oqs::EditController < BaseOqsController if ENV["SERVER_MODE"] != "cloud" #no print in cloud server # print assigned_item = AssignedOrderItem.find_by_instance_code(order_item.item_instance_code) - # order queue stations - oqs = assigned_item.order_queue_station - - order_slim_pdf = Lookup.collection_of("print_settings") #print_settings with name:OrderSlimPdf + assigned_items = AssignedOrderItem.where("item_code='" + assigned_item.item_code + "' AND " + "order_id='" + assigned_item.order_id + "'") - unique_code="OrderItemPdf" - if !order_slim_pdf.empty? - order_slim_pdf.each do |order_item_slim| - if order_item_slim[0] == 'OrderSlimPdf' - if order_item_slim[1] == '1' - unique_code="OrderItemSlimPdf" - else - unique_code="OrderItemPdf" - end - elsif order_item_slim[0] == 'OrderSetPdf' - if order_item_slim[1] == '1' - unique_code="OrderSetItemPdf" - else - unique_code="OrderItemPdf" + if !assigned_items.nil? + assigned_items.each do |assign_item| + # order queue stations + oqs = assign_item.order_queue_station + + order_slim_pdf = Lookup.collection_of("print_settings") #print_settings with name:OrderSlimPdf + + unique_code="OrderItemPdf" + if !order_slim_pdf.empty? + order_slim_pdf.each do |order_item_slim| + if order_item_slim[0] == 'OrderSlimPdf' + if order_item_slim[1] == '1' + unique_code="OrderItemSlimPdf" + else + unique_code="OrderItemPdf" + end + elsif order_item_slim[0] == 'OrderSetPdf' + if order_item_slim[1] == '1' + unique_code="OrderSetItemPdf" + else + unique_code="OrderItemPdf" + end + end end end + + print_settings=PrintSetting.find_by_unique_code(unique_code) + order_queue_printer= Printer::OrderQueuePrinter.new(print_settings) + order_queue_printer.print_order_item(print_settings, oqs, order_item.order_id, order_items_id, print_status=" (Cancelled)", before_updated_qty ) end end - - print_settings=PrintSetting.find_by_unique_code(unique_code) - order_queue_printer= Printer::OrderQueuePrinter.new(print_settings) - order_queue_printer.print_order_item(print_settings, oqs, order_item.order_id, order_items_id, print_status=" (Cancelled)", before_updated_qty ) end end diff --git a/app/controllers/oqs/print_controller.rb b/app/controllers/oqs/print_controller.rb index baa4af40..930d3d5c 100755 --- a/app/controllers/oqs/print_controller.rb +++ b/app/controllers/oqs/print_controller.rb @@ -26,7 +26,7 @@ class Oqs::PrintController < ApplicationController assigned_item_id = params[:id] options = params[:options] assigned_item = AssignedOrderItem.find(assigned_item_id) - assigned_items = AssignedOrderItem.where("item_code='" + assigned_item.item_code + "' AND " + "order_id='" + assigned_item.order_id + "'"); + assigned_items = AssignedOrderItem.where("item_code='" + assigned_item.item_code + "' AND " + "order_id='" + assigned_item.order_id + "'") # order queue stations oqs = assigned_item.order_queue_station diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index da5f216b..943fc3e9 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -431,13 +431,17 @@ class Origami::PaymentsController < BaseOrigamiController if(Sale.exists?(sale_id)) saleObj = Sale.find(sale_id) + #calculate cash acmount + cash = saleObj.total_amount + if saleObj.discount_type == "member_discount" - saleObj.update_attributes(rounding_adjustment: 0) + saleObj.update_attributes(grand_total: 0, rounding_adjustment: 0, amount_received: 0, amount_changed: 0) saleObj.compute_by_sale_items(sale_id, saleObj.sale_items,0,order_source) end - saleObj.update_attributes(rounding_adjustment: 0) - + saleObj.update_attributes(grand_total: 0, rounding_adjustment: 0, amount_received: 0, amount_changed: 0) + puts "FOC" + puts saleObj.to_json sale_payment = SalePayment.new sale_payment.process_payment(saleObj, current_user.name, cash, "foc" ,remark) # For Cashier by Zone diff --git a/app/controllers/settings/menus_controller.rb b/app/controllers/settings/menus_controller.rb index b7e02fb5..c7de4df8 100755 --- a/app/controllers/settings/menus_controller.rb +++ b/app/controllers/settings/menus_controller.rb @@ -62,7 +62,8 @@ class Settings::MenusController < ApplicationController def destroy # @settings_menu.destroy abc = Menu.destroyMenu(@settings_menu) - @settings_menu_item_set.destroy + + # @settings_menu_item_set.destroy flash[:notice] = 'Menu was successfully destroyed.' render :json => {:status=> "Success", :url => settings_menus_path }.to_json # respond_to do |format| @@ -71,12 +72,110 @@ class Settings::MenusController < ApplicationController # end end + def export + @settings_menus = Menu.all.page(params[:page]).per(10) + menu = Menu.find(params[:id]) + + p = Axlsx::Package.new + wb = p.workbook + wb.styles do |s| + time_format = wb.styles.add_style :format_code => 'hh:mm:ss' + title = s.add_style :fg_color => "004586", + :b => true, + :sz => 12 + wrap_text = s.add_style :sz => 11, + :alignment => { :horizontal => :left,:vertical => :center , + :wrap_text => true} + header_text = s.add_style :fg_color=> "090909", + :b => true, + :sz => 12, + :border => { :style => :thin, :color => "00" }, + :alignment => { :horizontal => :left, + :vertical => :center , + :header_text => true} + + # Menu Sheet + wb.add_worksheet(name: menu.name) do |sheet| + sheet.add_row ["Name",menu.name], :style=>title + sheet.add_row + + sheet.add_row ["Category Code", "Category Name", "Item Code", "Item Name", "Item AltName", "Taxable", "Instance Code", "Instance Name", "Price"], :style=>header_text + menu.menu_categories.each do |mc| + mc.menu_items.each do |mi| + mi.menu_item_instances.each do |mii| + sheet.add_row [ mc.code, mc.name, mi.item_code, mi.name, mi.alt_name, mi.taxable, mii.item_instance_code, mii.item_instance_name, mii.price], :style=>wrap_text + end + end + end + + + # # Category + # menu.menu_categories.each do |mc| + # sheet.add_row ["Category"], :style=>wrap_text + # sheet.add_row %w(id menu_id code name alt_name order_by created_by menu_category_id is_available), :style=>header_text + # sheet.add_row [mc.id, mc.menu_id, mc.code, mc.name, mc.alt_name, mc.order_by, mc.created_by, mc.menu_category_id, mc.is_available], :style=>wrap_text + # sheet.add_row + + # # Menu Item + # mc.menu_items.each do |mi| + # sheet.add_row ["Menu Item"], :style=>wrap_text + # sheet.add_row %w(id item_code name alt_name image_path description information unit type menu_category_id item_attributes item_options account_id min_qty taxable is_sub_item is_available created_by), :style=>header_text + # sheet.add_row [mi.id,mi.item_code, mi.name, mi.alt_name, mi.image_path, mi.description, mi.information, mi.unit, mi.type, mi.menu_category_id, mi.item_attributes, mi.item_options, mi.account_id, mi.min_qty, mi.taxable, mi.is_sub_item, mi.is_available, mi.created_by], :style=>wrap_text + # sheet.add_row + + # # Menu Item Instance + # sheet.add_row ["Menu Item Instance"], :style=>wrap_text + # sheet.add_row %w(id menu_item_id item_instance_code item_instance_name item_attributes price is_on_promotion promotion_price is_available is_default), :style=>header_text + # mi.menu_item_instances.each do |mii| + # sheet.add_row [mii.id, mii.menu_item_id, mii.item_instance_code, mii.item_instance_name, mii.item_attributes, mii.price, mii.is_on_promotion, mii.promotion_price, mii.is_available, mii.is_default], :style=>wrap_text + # end + # sheet.add_row + # end + # end + end + + # # Account + # wb.add_worksheet(name: "Account") do |sheet| + # sheet.add_row %w(id title account_type discount point bonus rebate), :style=>header_text + # Account.all.each do |acc| + # sheet.add_row [acc.id, acc.title,acc.account_type,acc.discount,acc.point,acc.bonus,acc.rebate], :style=>wrap_text + # end + # end + + # # Item set + # wb.add_worksheet(name: "Item Set") do |sheet| + # sheet.add_row %w(id name alt_name min_selectable_qty max_selectable_qty), :style=>header_text + # ItemSet.all.each do |set| + # sheet.add_row [set.id,set.name, set.alt_name, set.min_selectable_qty, set.max_selectable_qty], :style=>wrap_text + # end + # end + + # # Item Options + # wb.add_worksheet(name: "Menu Item Options") do |sheet| + # sheet.add_row %w(id option_type name value), :style=>header_text + # MenuItemOption.all.each do |option| + # sheet.add_row [option.id, option.option_type, option.name, option.value], :style=>wrap_text + # end + # end + + # # Item Attributes + # wb.add_worksheet(name: "Menu Item Attributes") do |sheet| + # sheet.add_row %w(id attribute_type name value), :style=>header_text + # MenuItemAttribute.all.each do |attr| + # sheet.add_row [attr.id, attr.attribute_type,attr.name,attr.value], :style=>wrap_text + # end + # end + end + + p.serialize("tmp/menus/" + menu.name + ".xlsx") + render :json => {status: true} + end + def import if params[:file] - Menu.import(params[:file]) - redirect_to settings_menus_path, notice: "Menu was successfully Imported" - end - + status = Menu.import(params[:file], current_user.name) + redirect_to settings_menus_path, notice: status + end end private diff --git a/app/models/menu.rb b/app/models/menu.rb index 9f4e6b14..d81079bd 100755 --- a/app/models/menu.rb +++ b/app/models/menu.rb @@ -45,99 +45,142 @@ class Menu < ApplicationRecord end end - def self.import(file) - + def self.import(file, created_by) + status = "" spreadsheet = open_spreadsheet(file) - sheet_count = spreadsheet.sheets.count-1 - for i in 0..sheet_count do - header = spreadsheet.sheet(i).row(1) - sheet_name = spreadsheet.sheets[i] + if spreadsheet.sheets.count > 1 + sheet_count = spreadsheet.sheets.count-1 + for i in 0..sheet_count do + header = spreadsheet.sheet(i).row(1) + sheet_name = spreadsheet.sheets[i] - (2..spreadsheet.sheet(i).last_row).each do |ii| - row = Hash[[header,spreadsheet.sheet(i).row(ii)].transpose] - if sheet_name == "Account" - # Account.create(id:row["id"], title: row["title"],account_type: row["account_type"],discount: row["discount"],point: row["point"],bonus: row["bonus"],rebate: row["rebate"]) - account = Account.find_by_id(row["id"]) - if account - Account.create(title: row["title"],account_type: row["account_type"],discount: row["discount"],point: row["point"],bonus: row["bonus"],rebate: row["rebate"]) - else - Account.create(id:row["id"], title: row["title"],account_type: row["account_type"],discount: row["discount"],point: row["point"],bonus: row["bonus"],rebate: row["rebate"]) - end - elsif sheet_name == "Item Set" - # ItemSet.create(id:row["id"], name: row[name], alt_name: row[alt_name], min_selectable_qty: row[min_selectable_qty], max_selectable_qty: row[max_selectable_qty]) - item_set = ItemSet.find_by_id(row["id"]) - if item_set - ItemSet.create( name: row[name], alt_name: row[alt_name], min_selectable_qty: row[min_selectable_qty], max_selectable_qty: row[max_selectable_qty]) - else - ItemSet.create(id:row["id"], name: row[name], alt_name: row[alt_name], min_selectable_qty: row[min_selectable_qty], max_selectable_qty: row[max_selectable_qty]) - end - elsif sheet_name == "Menu Item Options" - # MenuItemOption.create(id:row["id"], option_type: row["option_type"],name: row["name"],value: row["value"]) - item_options = MenuItemOption.find_by_id(row["id"]) - if item_options - MenuItemOption.create( option_type: row["option_type"],name: row["name"],value: row["value"]) - else - MenuItemOption.create(id:row["id"], option_type: row["option_type"],name: row["name"],value: row["value"]) - end - elsif sheet_name == "Menu Item Attributes" - # MenuItemAttribute.create(id:row["id"], attribute_type: row["attribute_type"],name: row["name"],value: row["value"]) - item_attributes = MenuItemAttribute.find_by_id(row["id"]) - if item_attributes - MenuItemAttribute.create( attribute_type: row["attribute_type"],name: row["name"],value: row["value"]) - else - MenuItemAttribute.create(id:row["id"], attribute_type: row["attribute_type"],name: row["name"],value: row["value"]) - end - elsif sheet_name == "Menu" - menu = Menu.find_by_id(row["id"]) - if menu - Menu.create(name: row["name"], is_active: row["is_active"], valid_days: row["valid_days"],valid_time_from: row["valid_time_from"], valid_time_to: row["valid_time_to"], created_by: row["created_by"]) - else - Menu.create(id:row["id"], name: row["name"], is_active: row["is_active"], valid_days: row["valid_days"],valid_time_from: row["valid_time_from"], valid_time_to: row["valid_time_to"], created_by: row["created_by"]) - end - elsif sheet_name == "Menu Category" - # MenuCategory.create(id:row["id"], menu_id: row["menu_id"], code: row["code"], name: row["name"], alt_name: row["alt_name"], order_by: row["order_by"], created_by: row["created_by"], menu_category_id: row["menu_category_id"], is_available: row["is_available"]) - menu_category = MenuCategory.find_by_id(row["id"]) - if menu_category - MenuCategory.create(menu_id: row["menu_id"], code: row["code"], name: row["name"], alt_name: row["alt_name"], order_by: row["order_by"], created_by: row["created_by"], menu_category_id: row["menu_category_id"], is_available: row["is_available"]) - else - MenuCategory.create(id:row["id"], menu_id: row["menu_id"], code: row["code"], name: row["name"], alt_name: row["alt_name"], order_by: row["order_by"], created_by: row["created_by"], menu_category_id: row["menu_category_id"], is_available: row["is_available"]) - end - elsif sheet_name == "Menu Item" - # MenuItem.create(id:row["id"], item_code: row["item_code"], name: row["name"], alt_name: row["alt_name"], image_path: row["image_path"], description: row["description"], information: row["information"], unit: row["unit"], type: row["type"], menu_category_id: row["menu_category_id"], item_attributes: row["item_attributes"], item_options: row["item_options"], account_id: row["account_id"], min_qty: row["min_qty"], taxable: row["taxable"], is_sub_item: row["is_sub_item"], is_available: row["is_available"], created_by: row["created_by"]) - menu_item = MenuItem.find_by_id(row["id"]) - if menu_item - MenuItem.create(item_code: row["item_code"], name: row["name"], alt_name: row["alt_name"], image_path: row["image_path"], description: row["description"], information: row["information"], unit: row["unit"], type: row["type"], menu_category_id: row["menu_category_id"], item_attributes: JSON.parse(row["item_attributes"]), item_options: JSON.parse(row["item_options"]), account_id: row["account_id"], min_qty: row["min_qty"], taxable: row["taxable"], is_sub_item: row["is_sub_item"], is_available: row["is_available"], created_by: row["created_by"]) - else - MenuItem.create(id:row["id"], item_code: row["item_code"], name: row["name"], alt_name: row["alt_name"], image_path: row["image_path"], description: row["description"], information: row["information"], unit: row["unit"], type: row["type"], menu_category_id: row["menu_category_id"], item_attributes: JSON.parse(row["item_attributes"]), item_options: JSON.parse(row["item_options"]), account_id: row["account_id"], min_qty: row["min_qty"], taxable: row["taxable"], is_sub_item: row["is_sub_item"], is_available: row["is_available"], created_by: row["created_by"]) - end - elsif sheet_name == "Menu Item Instance" - # MenuItemInstance.create(id:row["id"], menu_item_id: row["menu_item_id"].to_i, item_instance_code: row["item_instance_code"], item_instance_name: row["item_instance_name"], item_attributes: row["item_attributes"], price: row["price"], is_on_promotion: row["is_on_promotion"], promotion_price: row["promotion_price"], is_available: row["is_available"], is_default: row["is_default"]) - item_instance = MenuItemInstance.find_by_id(row["id"]) - if item_instance - MenuItemInstance.create(menu_item_id: row["menu_item_id"].to_i, item_instance_code: row["item_instance_code"], item_instance_name: row["item_instance_name"], item_attributes: JSON.parse(row["item_attributes"]), price: row["price"], is_on_promotion: row["is_on_promotion"], promotion_price: row["promotion_price"], is_available: row["is_available"], is_default: row["is_default"]) - else - MenuItemInstance.create(id:row["id"], menu_item_id: row["menu_item_id"].to_i, item_instance_code: row["item_instance_code"], item_instance_name: row["item_instance_name"], item_attributes: JSON.parse(row["item_attributes"]), price: row["price"], is_on_promotion: row["is_on_promotion"], promotion_price: row["promotion_price"], is_available: row["is_available"], is_default: row["is_default"]) - end - elsif sheet_name == "Menu Instance Item Set" - # MenuInstanceItemSet.create(id:row["id"], item_set_id: row["item_set_id"], menu_item_instance_id: row["menu_item_instance_id"]) - menu_instance_set = MenuInstanceItemSet.find_by_id(row["id"]) - if menu_instance_set - MenuInstanceItemSet.create(item_set_id: row["item_set_id"], menu_item_instance_id: row["menu_item_instance_id"]) - else - MenuInstanceItemSet.create(id:row["id"], item_set_id: row["item_set_id"], menu_item_instance_id: row["menu_item_instance_id"]) - end - elsif sheet_name == "Menu Item Set" - # MenuItemSet.create(id:row["id"], item_set_id: row["item_set_id"], menu_item_id: row["menu_item_id"]) - menu_item_set = MenuItemSet.find_by_id(row["id"]) - if menu_item_set - MenuItemSet.create(item_set_id: row["item_set_id"], menu_item_id: row["menu_item_id"]) - else - MenuItemSet.create(id:row["id"], item_set_id: row["item_set_id"], menu_item_id: row["menu_item_id"]) + (2..spreadsheet.sheet(i).last_row).each do |ii| + row = Hash[[header,spreadsheet.sheet(i).row(ii)].transpose] + if sheet_name == "Account" + # Account.create(id:row["id"], title: row["title"],account_type: row["account_type"],discount: row["discount"],point: row["point"],bonus: row["bonus"],rebate: row["rebate"]) + account = Account.find_by_id(row["id"]) + if account + Account.create(title: row["title"],account_type: row["account_type"],discount: row["discount"],point: row["point"],bonus: row["bonus"],rebate: row["rebate"]) + else + Account.create(id:row["id"], title: row["title"],account_type: row["account_type"],discount: row["discount"],point: row["point"],bonus: row["bonus"],rebate: row["rebate"]) + end + elsif sheet_name == "Item Set" + # ItemSet.create(id:row["id"], name: row[name], alt_name: row[alt_name], min_selectable_qty: row[min_selectable_qty], max_selectable_qty: row[max_selectable_qty]) + item_set = ItemSet.find_by_id(row["id"]) + if item_set + ItemSet.create( name: row["name"], alt_name: row["alt_name"], min_selectable_qty: row["min_selectable_qty"], max_selectable_qty: row["max_selectable_qty"]) + else + ItemSet.create(id:row["id"], name: row["name"], alt_name: row["alt_name"], min_selectable_qty: row["min_selectable_qty"], max_selectable_qty: row["max_selectable_qty"]) + end + elsif sheet_name == "Menu Item Options" + # MenuItemOption.create(id:row["id"], option_type: row["option_type"],name: row["name"],value: row["value"]) + item_options = MenuItemOption.find_by_id(row["id"]) + if item_options + MenuItemOption.create( option_type: row["option_type"],name: row["name"],value: row["value"]) + else + MenuItemOption.create(id:row["id"], option_type: row["option_type"],name: row["name"],value: row["value"]) + end + elsif sheet_name == "Menu Item Attributes" + # MenuItemAttribute.create(id:row["id"], attribute_type: row["attribute_type"],name: row["name"],value: row["value"]) + item_attributes = MenuItemAttribute.find_by_id(row["id"]) + if item_attributes + MenuItemAttribute.create( attribute_type: row["attribute_type"],name: row["name"],value: row["value"]) + else + MenuItemAttribute.create(id:row["id"], attribute_type: row["attribute_type"],name: row["name"],value: row["value"]) + end + elsif sheet_name == "Menu" + menu = Menu.find_by_id(row["id"]) + if menu + Menu.create(name: row["name"], is_active: row["is_active"], valid_days: row["valid_days"],valid_time_from: row["valid_time_from"], valid_time_to: row["valid_time_to"], created_by: row["created_by"]) + else + Menu.create(id:row["id"], name: row["name"], is_active: row["is_active"], valid_days: row["valid_days"],valid_time_from: row["valid_time_from"], valid_time_to: row["valid_time_to"], created_by: row["created_by"]) + end + elsif sheet_name == "Menu Category" + # MenuCategory.create(id:row["id"], menu_id: row["menu_id"], code: row["code"], name: row["name"], alt_name: row["alt_name"], order_by: row["order_by"], created_by: row["created_by"], menu_category_id: row["menu_category_id"], is_available: row["is_available"]) + menu_category = MenuCategory.find_by_id(row["id"]) + if menu_category + MenuCategory.create(menu_id: row["menu_id"], code: row["code"], name: row["name"], alt_name: row["alt_name"], order_by: row["order_by"], created_by: row["created_by"], menu_category_id: row["menu_category_id"], is_available: row["is_available"]) + else + MenuCategory.create(id:row["id"], menu_id: row["menu_id"], code: row["code"], name: row["name"], alt_name: row["alt_name"], order_by: row["order_by"], created_by: row["created_by"], menu_category_id: row["menu_category_id"], is_available: row["is_available"]) + end + elsif sheet_name == "Menu Item" + # MenuItem.create(id:row["id"], item_code: row["item_code"], name: row["name"], alt_name: row["alt_name"], image_path: row["image_path"], description: row["description"], information: row["information"], unit: row["unit"], type: row["type"], menu_category_id: row["menu_category_id"], item_attributes: row["item_attributes"], item_options: row["item_options"], account_id: row["account_id"], min_qty: row["min_qty"], taxable: row["taxable"], is_sub_item: row["is_sub_item"], is_available: row["is_available"], created_by: row["created_by"]) + menu_item = MenuItem.find_by_id(row["id"]) + if menu_item + MenuItem.create(item_code: row["item_code"], name: row["name"], alt_name: row["alt_name"], image_path: row["image_path"], description: row["description"], information: row["information"], unit: row["unit"], type: row["type"], menu_category_id: row["menu_category_id"], item_attributes: JSON.parse(row["item_attributes"]), item_options: JSON.parse(row["item_options"]), account_id: row["account_id"], min_qty: row["min_qty"], taxable: row["taxable"], is_sub_item: row["is_sub_item"], is_available: row["is_available"], created_by: row["created_by"]) + else + MenuItem.create(id:row["id"], item_code: row["item_code"], name: row["name"], alt_name: row["alt_name"], image_path: row["image_path"], description: row["description"], information: row["information"], unit: row["unit"], type: row["type"], menu_category_id: row["menu_category_id"], item_attributes: JSON.parse(row["item_attributes"]), item_options: JSON.parse(row["item_options"]), account_id: row["account_id"], min_qty: row["min_qty"], taxable: row["taxable"], is_sub_item: row["is_sub_item"], is_available: row["is_available"], created_by: row["created_by"]) + end + elsif sheet_name == "Menu Item Instance" + # MenuItemInstance.create(id:row["id"], menu_item_id: row["menu_item_id"].to_i, item_instance_code: row["item_instance_code"], item_instance_name: row["item_instance_name"], item_attributes: row["item_attributes"], price: row["price"], is_on_promotion: row["is_on_promotion"], promotion_price: row["promotion_price"], is_available: row["is_available"], is_default: row["is_default"]) + item_instance = MenuItemInstance.find_by_id(row["id"]) + if item_instance + MenuItemInstance.create(menu_item_id: row["menu_item_id"].to_i, item_instance_code: row["item_instance_code"], item_instance_name: row["item_instance_name"], item_attributes: JSON.parse(row["item_attributes"]), price: row["price"], is_on_promotion: row["is_on_promotion"], promotion_price: row["promotion_price"], is_available: row["is_available"], is_default: row["is_default"]) + else + MenuItemInstance.create(id:row["id"], menu_item_id: row["menu_item_id"].to_i, item_instance_code: row["item_instance_code"], item_instance_name: row["item_instance_name"], item_attributes: JSON.parse(row["item_attributes"]), price: row["price"], is_on_promotion: row["is_on_promotion"], promotion_price: row["promotion_price"], is_available: row["is_available"], is_default: row["is_default"]) + end + elsif sheet_name == "Menu Instance Item Set" + # MenuInstanceItemSet.create(id:row["id"], item_set_id: row["item_set_id"], menu_item_instance_id: row["menu_item_instance_id"]) + menu_instance_set = MenuInstanceItemSet.find_by_id(row["id"]) + if menu_instance_set + MenuInstanceItemSet.create(item_set_id: row["item_set_id"], menu_item_instance_id: row["menu_item_instance_id"]) + else + MenuInstanceItemSet.create(id:row["id"], item_set_id: row["item_set_id"], menu_item_instance_id: row["menu_item_instance_id"]) + end + elsif sheet_name == "Menu Item Set" + # MenuItemSet.create(id:row["id"], item_set_id: row["item_set_id"], menu_item_id: row["menu_item_id"]) + menu_item_set = MenuItemSet.find_by_id(row["id"]) + if menu_item_set + MenuItemSet.create(item_set_id: row["item_set_id"], menu_item_id: row["menu_item_id"]) + else + MenuItemSet.create(id:row["id"], item_set_id: row["item_set_id"], menu_item_id: row["menu_item_id"]) + end end end end + else + # Menu by Menu Import + accs = Account.all + account_id = 1 + if accs.length > 0 + account_id = accs[0].id + else + status = "No Account Created." + end + + sheet = spreadsheet.sheet(0) + menu = sheet.row(1)[1] + imported_menu = Menu.create({name: menu, is_active: true, valid_days: "1,2,3,4,5,6,7",valid_time_from: "00:00:00", valid_time_to: "23:59:59", created_by: created_by}) + + (4..sheet.last_row).each do |ii| + row = Hash[[sheet.row(3),sheet.row(ii)].transpose] + menu_cat = MenuCategory.find_by_code(row["Category Code"]) + if !menu_cat + menu_cat = MenuCategory.create({menu_id: imported_menu.id, code: row["Category Code"], name: row["Category Name"], alt_name: '', order_by: (ii - 3), created_by: created_by, menu_category_id: nil, is_available: 1}) + # else + # status = status + "Category Code already exists." + end + + menu_itm = MenuItem.find_by_item_code(row["Item Code"]) + if !menu_itm + menu_itm = MenuItem.create(item_code: row["Item Code"], name: row["Item Name"], 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) + # else + # status = status + "Item Code already exists for " + row["Item Name"] + "." + end + + menu_inst = MenuItemInstance.find_by_item_instance_code(row["Instance Code"]) + if !menu_inst + imported_instance = MenuItemInstance.create(menu_item_id: menu_itm.id, item_instance_code: row["Instance Code"], item_instance_name: row["Instance Name"], item_attributes: "[]", price: row["Price"], is_on_promotion: false, promotion_price: 0, is_available: true, is_default: false) + # else + # status = status + "Instance Code already exists for " + row["Instance Name"] + "." + end + end end - + # if status == '' + status="Menu Imported!" + # end + + return status end def self.open_spreadsheet(file) diff --git a/app/models/menu_category.rb b/app/models/menu_category.rb index 666f251a..7fb23647 100755 --- a/app/models/menu_category.rb +++ b/app/models/menu_category.rb @@ -33,7 +33,7 @@ class MenuCategory < ApplicationRecord abc = MenuItem.deleteRecursive(item) end menu_category.destroy - return false + return true end end diff --git a/app/models/menu_item.rb b/app/models/menu_item.rb index 836e0caf..03e90011 100755 --- a/app/models/menu_item.rb +++ b/app/models/menu_item.rb @@ -55,27 +55,35 @@ class MenuItem < ApplicationRecord def self.deleteRecursive(menu_item) # find the sub menu item of current item - sub_menu_items = MenuItem.where("id=?",menu_item.id) - if sub_menu_items.length != 0 - sub_menu_items.each do |subitem| - # if deleteRecursive(subitem) - # end - end - # find the instances of current menu item - instances = MenuItemInstance.where("menu_item_id=?",menu_item.id) - instances.each do |instance| - instance.destroy - end - menu_item.destroy - return true - else - instances = MenuItemInstance.where("menu_item_id=?",menu_item.id) - instances.each do |instance| - instance.destroy - end - menu_item.destroy - return false + # sub_menu_items = MenuItem.where("id=?",menu_item.id) + # if sub_menu_items.length != 0 + # # sub_menu_items.each do |subitem| + # # # if deleteRecursive(subitem) + # # # end + # # end + # # find the instances of current menu item + # instances = MenuItemInstance.where("menu_item_id=?",menu_item.id) + # instances.each do |instance| + # instance.menu_instance_item_sets.destroy_all + # end + # menu_item.menu_item_sets.destroy_all + # return true + # else + # instances = MenuItemInstance.where("menu_item_id=?",menu_item.id) + # instances.each do |instance| + # instance.menu_instance_item_sets.destroy_all + # end + # menu_item.menu_item_sets.destroy_all + # return true + # end + instances = MenuItemInstance.where("menu_item_id=?",menu_item.id) + instances.each do |instance| + instance.menu_instance_item_sets.destroy_all + instance.destroy end + menu_item.menu_item_sets.destroy_all + menu_item.destroy + return true end # private diff --git a/app/models/sale.rb b/app/models/sale.rb index 883fbad4..49c27448 100755 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -361,6 +361,8 @@ class Sale < ApplicationRecord end end + compute_tax(sale, total_taxable, total_discount, order_source) + sale.total_amount = subtotal_price sale.total_discount = total_discount sale.grand_total = (sale.total_amount - sale.total_discount) + sale.total_tax @@ -371,8 +373,6 @@ class Sale < ApplicationRecord # adjust_rounding sale.rounding_adjustment = compute_adjust_rounding(sale.grand_total) - compute_tax(sale, total_taxable, total_discount, order_source) - sale.save! end diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index e43414b8..4621adba 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -263,10 +263,12 @@ class SalePayment < ApplicationRecord self.payment_method = "foc" self.payment_amount = self.received_amount - self.outstanding_amount = self.sale.grand_total.to_f - self.received_amount.to_f + # self.outstanding_amount = self.sale.grand_total.to_f - self.received_amount.to_f + self.outstanding_amount = 0.00 self.payment_status = "paid" payment_method = self.save! - sale_update_payment_status(self.received_amount) + # sale_update_payment_status(self.received_amount) + sale_update_payment_status(0) return payment_status end diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb index e42f33ec..d6a2d2f1 100755 --- a/app/views/layouts/_header.html.erb +++ b/app/views/layouts/_header.html.erb @@ -100,8 +100,8 @@ $.ajax({ type: method, url: url , - success: function(data) { - location.href = data.url; + success: function(data) { + location.href = data.url; } }); } else { diff --git a/app/views/origami/home/show.html.erb b/app/views/origami/home/show.html.erb index ec935f04..f28e291f 100755 --- a/app/views/origami/home/show.html.erb +++ b/app/views/origami/home/show.html.erb @@ -300,7 +300,7 @@ <% end %> <% end %> - <% if !order_item.set_menu_items.nil? + <% if !order_item.set_menu_items.nil? && order_item.set_menu_items != '[]' JSON.parse(order_item.set_menu_items).each do |item_instance| %>
<%= item_instance["item_instance_name"] %> diff --git a/app/views/origami/rooms/show.html.erb b/app/views/origami/rooms/show.html.erb index 43c4d5e7..565abcf7 100755 --- a/app/views/origami/rooms/show.html.erb +++ b/app/views/origami/rooms/show.html.erb @@ -370,7 +370,7 @@ <% end %> <% end %> - <% if !order_item.set_menu_items.nil? + <% if !order_item.set_menu_items.nil? && order_item.set_menu_items != '[]' JSON.parse(order_item.set_menu_items).each do |item_instance| %>
<%= item_instance["item_instance_name"] %> diff --git a/app/views/settings/menus/export.html.erb b/app/views/settings/menus/export.html.erb new file mode 100644 index 00000000..e69de29b diff --git a/app/views/settings/menus/index.html.erb b/app/views/settings/menus/index.html.erb index 5fafa5db..42eca334 100755 --- a/app/views/settings/menus/index.html.erb +++ b/app/views/settings/menus/index.html.erb @@ -62,9 +62,12 @@ <%= link_to t("views.btn.edit"), edit_settings_menu_path(settings_menu),:class => 'btn btn-info btn-sm waves-effect' %> - - - <% end %> + + backup + + + + <% end %>
@@ -101,3 +104,21 @@
+ + diff --git a/config/routes.rb b/config/routes.rb index 0c0f47a9..94db2ebd 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -310,8 +310,10 @@ scope "(:locale)", locale: /en|mm/ do collection do post :import end - resources :menu_categories, only: [:new, :create, :edit, :delete] - end + resources :menu_categories, only: [:new, :create, :edit, :delete] + end + + get '/menus/:id/export' => 'menus#export' resources :item_sets diff --git a/lib/tasks/clear_data.rake b/lib/tasks/clear_data.rake index 9d476d67..247992be 100755 --- a/lib/tasks/clear_data.rake +++ b/lib/tasks/clear_data.rake @@ -17,7 +17,7 @@ namespace :clear do Survey.delete_all DiningFacility.update_all(status:'available') CashierTerminal.update_all(is_currently_login: 0) - SeedGenerator.where("id > 1").update(:current => 0, :next => 1) + SeedGenerator.where("id > 1").update(:current => 0, :next => 0) puts "Clear Data Done." end From 2cb6427aa1b78d1015dff4f7b7f38468323d6b5c Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Tue, 3 Apr 2018 10:54:06 +0630 Subject: [PATCH 03/18] update license check --- app/models/license.rb | 33 +++++++++++++++++---------------- config/license.yml | 15 +++++++++++++++ 2 files changed, 32 insertions(+), 16 deletions(-) create mode 100644 config/license.yml diff --git a/app/models/license.rb b/app/models/license.rb index ac82721c..132585d8 100755 --- a/app/models/license.rb +++ b/app/models/license.rb @@ -134,21 +134,23 @@ class License def verify_license api_token = read_license_no_decrypt("api_token") @params = { query: {lookup_type: "application", api_token: api_token} } - response = self.class.get("/verify", @params) - - rescue SocketError => e - Rails.logger.debug "In Socket errror" - return true - rescue => e - @varified = response.parsed_response - Rails.logger.debug "License Remote Response - " + response.parsed_response.to_s - if (@varified["status"]) - if (!check_expired(@varified["renewable_date"])) - return true - end - else - delete_license_file - end + + begin + response = self.class.get("/verify", @params) + @varified = response.parsed_response + Rails.logger.debug "License Remote Response - " + response.parsed_response.to_s + if (@varified["status"]) + + if (!check_expired(@varified["renewable_date"])) + return true + end + else + delete_license_file + end + rescue SocketError => e + Rails.logger.debug "In SocketError No Internet connection ! " + return true + end return false end @@ -164,7 +166,6 @@ class License def check_expired(renewal_date_str) expired_date_str = read_license("renewable_date") renewal_date = DateTime.parse(renewal_date_str) - if(renewal_date_str != expired_date_str) update_license("renewable_date", renewal_date_str) end diff --git a/config/license.yml b/config/license.yml new file mode 100644 index 00000000..9f4d1542 --- /dev/null +++ b/config/license.yml @@ -0,0 +1,15 @@ +iv_key: rwOZKWcQho6fE4V+A2zFuQ== +shop_name: AMZ_Test +email: aungmyo.zaw@code2lab.com +telephone: +fax: +address: +dbhost: dNzh66R80remB694OEds96OpuyZ4wmHeHFdQh0KwjYFvTInK6+pCN/y6HdbyIlqqjcBHkqPjkjzw45PznLn7hA== +dbschema: 4vooJDxgWdFv/8V7Qx8tzR/8B8T2c5U4XvYcF+2KOoA= +dbusername: Xc8ELRsW7N/f8KsVikMBlg== +dbpassword: HMg+TbLxmfYrDFI4IIAd4g== +api_token: bisryXiEnbTJlZwghAnIByQpiRUMouu +app_token: LycQXJYBZGeCygjIEKdlBXnjIGMiMzgmt +plan_sku: 84hdnSCgkfhvItY7uB/pPQ== +renewable_date: 8E6Ecz8QXAMSlKZnIzn0pQ== +plan_name: 4cMIO0n/JzGFPIccXM6u5A== From b0d7c3b1b8ece45d63386e8b21ec44e522f906b5 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Tue, 3 Apr 2018 15:01:54 +0630 Subject: [PATCH 04/18] update sale item report --- app/controllers/reports/saleitem_controller.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/controllers/reports/saleitem_controller.rb b/app/controllers/reports/saleitem_controller.rb index 24c812eb..e2823d93 100755 --- a/app/controllers/reports/saleitem_controller.rb +++ b/app/controllers/reports/saleitem_controller.rb @@ -3,10 +3,14 @@ class Reports::SaleitemController < BaseReportController def index from, to = get_date_range_from_params - shift_sale_range = Sale.get_by_shift_sale(from,to,Sale::SALE_STATUS_COMPLETED) + + shift_sale_range = '' shift = '' if params[:shift_name].to_i != 0 + + shift_sale_range = Sale.get_by_shift_sale(from,to,Sale::SALE_STATUS_COMPLETED) + shift_sale = ShiftSale.find(params[:shift_name]) if to.blank? shift = ShiftSale.where('shift_started_at = ? and shift_closed_at is NULL ',shift_sale.shift_started_at) @@ -14,6 +18,7 @@ class Reports::SaleitemController < BaseReportController shift = ShiftSale.where('shift_started_at = ? and shift_closed_at = ? ',shift_sale.shift_started_at, shift_sale.shift_closed_at) end + end @type = params[:sale_type] @sale_data, @other_charges,@discount_data , @cash_data , @card_data , @credit_data , @foc_data , @grand_total , @change_amount = Sale.get_by_shift_items(shift_sale_range,shift, from, to, Sale::SALE_STATUS_COMPLETED,@type) From 8e07cd5f4e655c52b70d82d340378c340ea28068 Mon Sep 17 00:00:00 2001 From: phyusin Date: Tue, 3 Apr 2018 18:06:18 +0630 Subject: [PATCH 05/18] check FOC payment issue --- app/controllers/origami/payments_controller.rb | 10 +++++++--- app/models/sale.rb | 4 ++-- app/models/sale_payment.rb | 6 ++++-- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index da5f216b..943fc3e9 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -431,13 +431,17 @@ class Origami::PaymentsController < BaseOrigamiController if(Sale.exists?(sale_id)) saleObj = Sale.find(sale_id) + #calculate cash acmount + cash = saleObj.total_amount + if saleObj.discount_type == "member_discount" - saleObj.update_attributes(rounding_adjustment: 0) + saleObj.update_attributes(grand_total: 0, rounding_adjustment: 0, amount_received: 0, amount_changed: 0) saleObj.compute_by_sale_items(sale_id, saleObj.sale_items,0,order_source) end - saleObj.update_attributes(rounding_adjustment: 0) - + saleObj.update_attributes(grand_total: 0, rounding_adjustment: 0, amount_received: 0, amount_changed: 0) + puts "FOC" + puts saleObj.to_json sale_payment = SalePayment.new sale_payment.process_payment(saleObj, current_user.name, cash, "foc" ,remark) # For Cashier by Zone diff --git a/app/models/sale.rb b/app/models/sale.rb index 883fbad4..49c27448 100755 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -361,6 +361,8 @@ class Sale < ApplicationRecord end end + compute_tax(sale, total_taxable, total_discount, order_source) + sale.total_amount = subtotal_price sale.total_discount = total_discount sale.grand_total = (sale.total_amount - sale.total_discount) + sale.total_tax @@ -371,8 +373,6 @@ class Sale < ApplicationRecord # adjust_rounding sale.rounding_adjustment = compute_adjust_rounding(sale.grand_total) - compute_tax(sale, total_taxable, total_discount, order_source) - sale.save! end diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index e43414b8..4621adba 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -263,10 +263,12 @@ class SalePayment < ApplicationRecord self.payment_method = "foc" self.payment_amount = self.received_amount - self.outstanding_amount = self.sale.grand_total.to_f - self.received_amount.to_f + # self.outstanding_amount = self.sale.grand_total.to_f - self.received_amount.to_f + self.outstanding_amount = 0.00 self.payment_status = "paid" payment_method = self.save! - sale_update_payment_status(self.received_amount) + # sale_update_payment_status(self.received_amount) + sale_update_payment_status(0) return payment_status end From 17562f6fcf6a75ef9f9c4e11c5cd19d7c872795d Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Wed, 4 Apr 2018 09:43:02 +0630 Subject: [PATCH 06/18] update license and login dashboard --- app/models/license.rb | 12 +++++++++++- app/views/layouts/login_dashboard.html.erb | 4 ++-- config/initializers/action_controller.rb | 10 +++++----- config/secrets.yml | 2 +- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/app/models/license.rb b/app/models/license.rb index 132585d8..ed8e3eb8 100755 --- a/app/models/license.rb +++ b/app/models/license.rb @@ -140,20 +140,30 @@ class License @varified = response.parsed_response Rails.logger.debug "License Remote Response - " + response.parsed_response.to_s if (@varified["status"]) - if (!check_expired(@varified["renewable_date"])) return true end else delete_license_file end + rescue SocketError => e Rails.logger.debug "In SocketError No Internet connection ! " return true + rescue HTTParty::Error + Rails.logger.debug "Server Error HTTParty" + return true + rescue Net::OpenTimeout + Rails.logger.debug "connection Timeout" + return true + rescue OpenURI::HTTPError + Rails.logger.debug "Can't connect server" + return true end return false end + # Check Expired before 30 days def check_expiring(renewal_date_str) if !renewal_date_str.empty? diff --git a/app/views/layouts/login_dashboard.html.erb b/app/views/layouts/login_dashboard.html.erb index f2f6f958..04fe8ded 100755 --- a/app/views/layouts/login_dashboard.html.erb +++ b/app/views/layouts/login_dashboard.html.erb @@ -11,8 +11,8 @@ - - + <%= stylesheet_link_tag 'login', media: 'all', 'data-turbolinks-track': 'reload' %> diff --git a/config/initializers/action_controller.rb b/config/initializers/action_controller.rb index 02e35bb8..8f310dab 100644 --- a/config/initializers/action_controller.rb +++ b/config/initializers/action_controller.rb @@ -20,11 +20,11 @@ class ActionController::Base end else # check for license file - # if check_license - # current_license(ENV["SX_PROVISION_URL"]) - # else - # redirect_to activate_path - # end + if check_license + current_license(ENV["SX_PROVISION_URL"]) + else + redirect_to activate_path + end end end diff --git a/config/secrets.yml b/config/secrets.yml index 076b6691..0282c5fc 100755 --- a/config/secrets.yml +++ b/config/secrets.yml @@ -12,7 +12,7 @@ development: secret_key_base: b61d85f8ed2a1a9e0eeece3443b3e8f838d002cc1d9f32115d8e93db920e2957adfedc57501d44741211538f3108b742cdeada87d5bfae796c53da1f90a3cd61 - sx_provision_url: connect.smartsales.dev/api #connect.smartsales.dev/api #connect.smartsales.asia/api #provision.zsai.ws/api + sx_provision_url: connect.smartsales.asia/api #connect.smartsales.dev/api #connect.smartsales.asia/api #provision.zsai.ws/api server_mode: application cipher_type: AES-256-CBC sx_key: Wh@t1$C2L From 907fd671c8054b7c28d7a4b859914224355f219a Mon Sep 17 00:00:00 2001 From: phyusin Date: Wed, 4 Apr 2018 11:55:45 +0630 Subject: [PATCH 07/18] check foreigner lists --- app/views/origami/surveys/_form.html.erb | 128 +++++++++++++++++- app/views/transactions/surveys/index.html.erb | 9 +- 2 files changed, 128 insertions(+), 9 deletions(-) diff --git a/app/views/origami/surveys/_form.html.erb b/app/views/origami/surveys/_form.html.erb index 1322f677..967a5837 100755 --- a/app/views/origami/surveys/_form.html.erb +++ b/app/views/origami/surveys/_form.html.erb @@ -32,17 +32,19 @@
<%= f.input :total_customer, input_html: { value: @survey_data.total_customer, class: 'col-md-11'} %> <%= f.input :local , input_html: { value: @survey_data.local, class: 'col-md-11' }%> -
- Foreigner -
+ + +
+ +
- + <% Lookup.where("lookup_type = ?", "country" ).each do |ct| %> + <%end %>
@@ -243,7 +245,11 @@ \ No newline at end of file diff --git a/app/views/transactions/surveys/index.html.erb b/app/views/transactions/surveys/index.html.erb index 66defdc0..7e750faa 100644 --- a/app/views/transactions/surveys/index.html.erb +++ b/app/views/transactions/surveys/index.html.erb @@ -56,6 +56,7 @@ <% total_female = 0 %> <% total_local = 0 %> <% total_customer = 0 %> + <% total_foreigner = 0 %> <% if !@surveys.nil? %> <% @surveys.each do |survey| %> <% total_child = total_child.to_i + survey.child.to_i %> @@ -80,8 +81,11 @@ <% foreigner_lists = foreign.split(",") %> <% if !foreigner_lists.empty? %> <% foreigner_lists.each do |fgn| %> + <% unless fgn.match(/[^[:digit:]]+/) + total_foreigner = total_foreigner.to_i + fgn.to_i + end %> <% if !fgn.scan(/\D/).empty? %> - <%= fgn %> :<% end %> <%= fgn.to_i unless fgn.match(/[^[:digit:]]+/) %>
+ <%= fgn %> :<% end %> <%= fgn.to_i unless fgn.match(/[^[:digit:]]+/) %>
<% end %> <% end %> <% end %> @@ -97,7 +101,8 @@ <%= total_male %> <%= total_female %> <%= total_customer %> - <%= total_local %> + <%= total_local %> + <%= total_foreigner %> From 9bf4047548d782fd6236587296412069bc2e4121 Mon Sep 17 00:00:00 2001 From: San Wai Lwin Date: Wed, 4 Apr 2018 10:33:31 +0630 Subject: [PATCH 08/18] Add MoveTablePdf with multiple printer --- .../origami/movetable_controller.rb | 39 +++++++++++-------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/app/controllers/origami/movetable_controller.rb b/app/controllers/origami/movetable_controller.rb index 09d9669e..20aaf0c5 100755 --- a/app/controllers/origami/movetable_controller.rb +++ b/app/controllers/origami/movetable_controller.rb @@ -56,19 +56,19 @@ class Origami::MovetableController < BaseOrigamiController end end - def moving - change_to = params[:change_to] #new - change_from = params[:change_from] #original - bookings = Booking.where('dining_facility_id=?',change_from) + def moving + change_to = params[:change_to] #new + change_from = params[:change_from] #original + bookings = Booking.where('dining_facility_id=?',change_from) - booking_array = Array.new - bookings.each do | booking | - if booking.sale_id.nil? && booking.booking_status != 'moved' - booking_array.push(booking) - end - end + booking_array = Array.new + bookings.each do | booking | + if booking.sale_id.nil? && booking.booking_status != 'moved' + booking_array.push(booking) + end + end - @get_type = Booking.update_dining_facility(booking_array,change_to,change_from) + @get_type = Booking.update_dining_facility(booking_array,change_to,change_from) # get printer info @from = (DiningFacility.find(change_from)).name @@ -78,9 +78,16 @@ class Origami::MovetableController < BaseOrigamiController @date = DateTime.now @shop = Shop::ShopDetail unique_code = "MoveTablePdf" - print_settings = PrintSetting.find_by_unique_code(unique_code) - printer = Printer::ReceiptPrinter.new(print_settings) - printer.print_move_table(print_settings,@to,@from ,@shop,@date,@type,@moved_by) - end - + pdf_no = PrintSetting.where(:unique_code => unique_code).count + #print_settings = PrintSetting.find_by_unique_code(unique_code) + printer_array = [] + printer_array = PrintSetting.where(:unique_code => unique_code) + for i in 0..pdf_no + if i != pdf_no + print_settings = printer_array[i] + printer = Printer::ReceiptPrinter.new(print_settings) + printer.print_move_table(print_settings,@to,@from ,@shop,@date,@type,@moved_by) + end + end + end end From 8c9b0f756d86b6588a8b269090f520cd13d6ac9c Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Wed, 4 Apr 2018 14:09:35 +0630 Subject: [PATCH 09/18] update sale item report --- .../reports/saleitem_controller.rb | 21 +++++++++++-------- app/models/sale.rb | 9 ++++++++ app/views/reports/saleitem/index.html.erb | 3 ++- config/routes.rb | 3 ++- 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/app/controllers/reports/saleitem_controller.rb b/app/controllers/reports/saleitem_controller.rb index e2823d93..92604b04 100755 --- a/app/controllers/reports/saleitem_controller.rb +++ b/app/controllers/reports/saleitem_controller.rb @@ -9,17 +9,20 @@ class Reports::SaleitemController < BaseReportController shift = '' if params[:shift_name].to_i != 0 - shift_sale_range = Sale.get_by_shift_sale(from,to,Sale::SALE_STATUS_COMPLETED) + shift_sale_range = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED) shift_sale = ShiftSale.find(params[:shift_name]) - if to.blank? + if to.blank? shift = ShiftSale.where('shift_started_at = ? and shift_closed_at is NULL ',shift_sale.shift_started_at) else - - shift = ShiftSale.where('shift_started_at = ? and shift_closed_at = ? ',shift_sale.shift_started_at, shift_sale.shift_closed_at) + if shift_sale.shift_closed_at.blank? + shift = ShiftSale.where('shift_started_at = ? and shift_closed_at is NULL',shift_sale.shift_started_at) + else + shift = ShiftSale.where('shift_started_at = ? and shift_closed_at = ? ',shift_sale.shift_started_at, shift_sale.shift_closed_at) + end end - end + @type = params[:sale_type] @sale_data, @other_charges,@discount_data , @cash_data , @card_data , @credit_data , @foc_data , @grand_total , @change_amount = Sale.get_by_shift_items(shift_sale_range,shift, from, to, Sale::SALE_STATUS_COMPLETED,@type) @@ -59,8 +62,8 @@ class Reports::SaleitemController < BaseReportController def show from, to, report_type = get_date_range_from_params - - @sale_data = Sale.get_by_shift_sale(from,to,Sale::SALE_STATUS_COMPLETED) +puts "aaaaaaaaaaaaaaaaaaaaaaaaaa" + @sale_data = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED) date_arr = Array.new @sale_data.each do |sale| @@ -73,8 +76,8 @@ class Reports::SaleitemController < BaseReportController date_arr.push(str) end - @totalByAccount = Hash.new {|hash, key| hash[key] = 0} - @sale_data.each {|acc| @totalByAccount[acc.account_id] += acc.grand_total} + # @totalByAccount = Hash.new {|hash, key| hash[key] = 0} + # @sale_data.each {|acc| @totalByAccount[acc.account_id] += acc.grand_total} out = {:status => 'ok', :message => date_arr} diff --git a/app/models/sale.rb b/app/models/sale.rb index e25589dc..9306b0eb 100755 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -806,6 +806,15 @@ def self.get_by_shift_sale(from,to,status) return query = query.where("shift_sales.shift_started_at >= ?" + " AND shift_sales.shift_closed_at <= ?", from,to) end +def self.get_by_shift_sale_by_item(from,to,status) + query = ShiftSale.select("shift_sales.id ,shift_started_at AS opening_date, + shift_closed_at As closing_date," + + " grand_total AS grand_total, cash_sales AS cash," + + "total_taxes AS total_tax,total_discounts As total_discount") + .order("shift_sales.id DESC") + return query = query.where("shift_sales.shift_started_at >= ?" , from) +end + def self.get_item_query(type) if type == "revenue" || type.nil? diff --git a/app/views/reports/saleitem/index.html.erb b/app/views/reports/saleitem/index.html.erb index a972443f..a3937ec2 100644 --- a/app/views/reports/saleitem/index.html.erb +++ b/app/views/reports/saleitem/index.html.erb @@ -325,7 +325,8 @@ var str = ''; var param_shift = '<%= params[:shift_name]%>'; - url = '<%= reports_get_shift_by_date_path %>'; + url = '<%= reports_get_shift_by_sale_item_path %>'; + console.log(url) $.get(url, {period :period, period_type :period_type, from :from, to :to, report_type :shift_item} , function(data){ console.log(data) diff --git a/config/routes.rb b/config/routes.rb index 4448b75f..5f0d21ba 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -407,8 +407,9 @@ scope "(:locale)", locale: /en|mm/ do resources :stock_check, :only => [:index, :show] resources :payment_method resources :product_sale, :only => [:index, :show] - + get "saleitem/get_shift_by_date", to: "saleitem#show", as: "get_shift_by_sale_item" get "receipt_no/get_shift_by_date", to: "receipt_no#get_shift_by_date", as: "get_shift_by_date" + end # ----------- Inventory --------------------------- From 2e81de1ea7551035678f2525853429bc5505c40b Mon Sep 17 00:00:00 2001 From: phyusin Date: Wed, 4 Apr 2018 16:37:10 +0630 Subject: [PATCH 10/18] bill channel for request bill and creditnote payment duoble amt --- app/controllers/origami/request_bills_controller.rb | 4 +++- app/models/sale_payment.rb | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/controllers/origami/request_bills_controller.rb b/app/controllers/origami/request_bills_controller.rb index e2553a83..cdd1f442 100755 --- a/app/controllers/origami/request_bills_controller.rb +++ b/app/controllers/origami/request_bills_controller.rb @@ -16,7 +16,7 @@ class Origami::RequestBillsController < ApplicationController bk_order = BookingOrder.find_by_order_id(order_id) order = Order.find(order_id) check_booking = Booking.find_by_booking_id(bk_order.booking_id) - + table = DiningFacility.find(check_booking.dining_facility_id) if check_booking.sale_id.nil? # Create Sale if it doesn't exist @status, @sale_id = @sale.generate_invoice_from_booking(check_booking.id,current_login_employee, current_user, order.source) @@ -33,6 +33,8 @@ class Origami::RequestBillsController < ApplicationController # Promotion Activation Promotion.promo_activate(@sale) + #bill channel + ActionCable.server.broadcast "bill_channel",table: table if order.source == "quick_service" result = {:status=> @status, :data => @sale.sale_id } render :json => result.to_json diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 4621adba..5cd7ea40 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -472,7 +472,7 @@ class SalePayment < ApplicationRecord elsif paid_amount.to_f > 0 #|| paid_amount != "0.0" table_update_status(sObj) update_shift - elsif method_status && paid_amount.to_f == 0 + elsif method_status && paid_amount.to_f == 0 && is_credit == 0 table_update_status(sObj) update_shift end From 03e8ba99a62ad894fde3535cf1aa5d7dc21a3f0d Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Wed, 4 Apr 2018 17:20:49 +0630 Subject: [PATCH 11/18] update add --- app/assets/javascripts/custom.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/app/assets/javascripts/custom.js b/app/assets/javascripts/custom.js index c6e6a47b..043fbb03 100644 --- a/app/assets/javascripts/custom.js +++ b/app/assets/javascripts/custom.js @@ -32,6 +32,26 @@ $(document).ready(function() { railBorderRadius: '0', touchScrollStep : 50 }); + + $('#modal-slimscroll').slimScroll({ + height: height-$('#modal-slimscroll').attr('data-height'), + size: '5px', + color: 'rgba(0,0,0,0.5)', + alwaysVisible: false, + borderRadius: '0', + railBorderRadius: '0', + touchScrollStep : 45 + }); + + $('#modal-set-slimscroll').slimScroll({ + height: height-$('#modal-slimscroll').attr('data-height'), + size: '5px', + color: 'rgba(0,0,0,0.5)', + alwaysVisible: false, + borderRadius: '0', + railBorderRadius: '0', + touchScrollStep : 45 + }); // $('.delete').click(function(){ // var method = $(this).attr('data-method'); From 9136e9de07278f0a8d0315aec5556990adf6a812 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Wed, 4 Apr 2018 17:51:51 +0630 Subject: [PATCH 12/18] update addorder set multiple --- app/assets/javascripts/addorder.js | 92 +++++++++++++++------ app/views/origami/addorders/detail.html.erb | 8 +- 2 files changed, 76 insertions(+), 24 deletions(-) diff --git a/app/assets/javascripts/addorder.js b/app/assets/javascripts/addorder.js index 31209c99..a8de44b1 100755 --- a/app/assets/javascripts/addorder.js +++ b/app/assets/javascripts/addorder.js @@ -315,6 +315,7 @@ $(function() { $(".options-list").empty(); rowCount = $('.selected-instance'); + setCount = $('.selected-set'); item_options = $(this).data('option'); min_qty = $(this).data('min-qty'); @@ -335,19 +336,19 @@ $(function() { $(".options-list").append(row); } } - if($(this).hasClass('selected-instance') == true){ - sub_total = $('#set_total_price').text(); - name = $(this).data('name'); - price = $(this).data('price'); - // qty = $('#set_change_qty').val(); - qty = document.getElementById("set_count").value; - total = qty*price; - var total_price = +sub_total - +total; - $(this).removeClass('selected-instance'); - $(".options-list").empty(); - $(this).removeAttr('data-options'); - $('#instance_option').text('') - }else { + // if($(this).hasClass('selected-instance') == true){ + // sub_total = $('#set_total_price').text(); + // name = $(this).data('name'); + // price = $(this).data('price'); + // // qty = $('#set_change_qty').val(); + // qty = document.getElementById("set_count").value; + // total = qty*price; + // var total_price = +sub_total - +total; + // $(this).removeClass('selected-instance'); + // $(".options-list").empty(); + // $(this).removeAttr('data-options'); + // $('#instance_option').text('') + // }else { if (rowCount.length+1 <= max_qty) { sub_total = $('#set_total_price').text(); name = $(this).data('name'); @@ -358,12 +359,55 @@ $(function() { total = qty*price; var total_price = +sub_total + +total; $(this).addClass('selected-instance'); + + set = "
" + + +'
' + +' ' + +''+$(this).data('name')+'' + +'
' + +'
' + + +' ' + +'
' + // +'' + +'
' + $(".selected-set-list").append(set); + }else{ + swal("Alert !", 'Maximum Qty is ' + max_qty + " items", "warning"); } - } + // } $('#set_unit_price').text(price); $('#set_total_price').text(total_price); }); //End selecct attribute buttom + + // click add order + $(document).on('click', '#remove_set', function(event){ + code = $(this).parent().parent('.selected-set').attr('data-code'); + instance = $(".selected-instance"); + console.log(code) + $(instance).each(function(i){ + if ($(instance[i]).attr('data-code')==code){ + console.log($(instance[i])) + $(instance[i]).removeClass("selected-instance") + } + }); + $(this).parent().parent('.selected-set').remove(); + }); // click add order $(document).on('click', '.set_order', function(event){ @@ -637,15 +681,17 @@ $(function() { if(group == "set_menu"){ - - instance = $(".selected-instance"); - $(instance).each(function(i){ - if ($(instance[i]).attr('data-code')==code){ - option_arr = get_selected_attributes('selected-option'); - $(instance[i]).attr('data-options',JSON.stringify(option_arr)); - $(instance[i]).children().children('#instance_option').text(option_arr); - } - }); + option_arr = get_selected_attributes('selected-option'); + $(".selected-set:last").attr('data-options',JSON.stringify(option_arr)); + $(".selected-set:last").children().children('#instance_option').text(option_arr); + // instance = $(".selected-instance"); + // $(instance).each(function(i){ + // if ($(instance[i]).attr('data-code')==code){ + // option_arr = get_selected_attributes('selected-option'); + // $(instance[i]).attr('data-options',JSON.stringify(option_arr)); + // $(instance[i]).children().children('#instance_option').text(option_arr); + // } + // }); } if(group == "set_menu_default"){ diff --git a/app/views/origami/addorders/detail.html.erb b/app/views/origami/addorders/detail.html.erb index 607f4c0e..93569170 100755 --- a/app/views/origami/addorders/detail.html.erb +++ b/app/views/origami/addorders/detail.html.erb @@ -405,9 +405,15 @@

-
+ +
From 866746db70cfdf086a38b84512650bb7a660f51e Mon Sep 17 00:00:00 2001 From: Jueli Moon Aung Date: Thu, 5 Apr 2018 07:01:40 +0000 Subject: [PATCH 13/18] license.rb edited by Julian (Enabled Rest API for SymmetricDS) --- app/models/license.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/models/license.rb b/app/models/license.rb index ed8e3eb8..13931376 100755 --- a/app/models/license.rb +++ b/app/models/license.rb @@ -356,7 +356,8 @@ class License 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.write("initial.load.use.extract.job.enabled=true\n") + f.write("rest.api.enable=true\n") f.close # read from license file @@ -379,7 +380,8 @@ class License 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("job.pull.period.time.ms=10000\n") + f.write("rest.api.enable=true\n") # f.write("initial.load.create.first=true\n") # f.write("initial.load.use.extract.job.enabled=true\n") f.close From 1fd6414886152a2eb27a5d6ef017562837eb547e Mon Sep 17 00:00:00 2001 From: phyusin Date: Thu, 5 Apr 2018 15:06:55 +0630 Subject: [PATCH 14/18] add api for survey --- app/controllers/api/survey_controller.rb | 47 ++++++++++++++++++++++++ config/routes.rb | 2 + 2 files changed, 49 insertions(+) create mode 100644 app/controllers/api/survey_controller.rb diff --git a/app/controllers/api/survey_controller.rb b/app/controllers/api/survey_controller.rb new file mode 100644 index 00000000..879c9ea7 --- /dev/null +++ b/app/controllers/api/survey_controller.rb @@ -0,0 +1,47 @@ +class Api::SurveyController < Api::ApiController + skip_before_action :authenticate + + def index + dining_facility = DiningFacility.find(params[:id]) + survey_data = Survey.find_by_dining_name(dining_facility.name) + countries = Lookup.collection_of("country") + if !countries.nil? || !survey_data.nil? + render :json => { :status => true, :data => { :countries => countries, :survey_data => survey_data} } + else + render :json => { :status => true, :error_message => "There is no data" } + end + end + + def create + dining_facility = DiningFacility.find(params[:id]) + cashier_zone = CashierTerminalByZone.find_by_zone_id(dining_facility.zone_id) + shift_by_terminal = ShiftSale.find_by_cashier_terminal_id_and_shift_closed_at(cashier_zone.cashier_terminal_id,nil) + + if params[:survey_id] + survey = Survey.find(params[:survey_id]) + else + survey = Survey.new + end + survey.dining_name = dining_facility.name + survey.shift_id = shift_by_terminal.id + survey.child = params[:child] + survey.adult = params[:adult] + survey.male = params[:male] + survey.female = params[:female] + survey.local = params[:local] + survey.created_by = current_login_employee.name + survey.total_customer = params[:total_customer] + survey.total_amount = params[:total_amount] + survey.foreigner = params[:foreigner].to_json + survey.save! + + render :json => { :status => true } + end + + # private + # def survey_params + # params.require(:survey).permit(:child, :adult,:male,:female,:local,:foreigner, + # :dining_name,:created_by,:total_customer,:total_amount) + # end + +end \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 94db2ebd..ace0f946 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -78,6 +78,8 @@ scope "(:locale)", locale: /en|mm/ do post "check_in" => "check_in_process#check_in_process" post "request_time" => "check_in_process#request_time" post "call_waiter" => "call_waiters#index" + get "survey/:id" => "survey#index" + post "survey/:id" => "survey#create" end From 7c15dac2aaacb02c3555b8694fbac189300e170c Mon Sep 17 00:00:00 2001 From: phyusin Date: Thu, 5 Apr 2018 17:30:44 +0630 Subject: [PATCH 15/18] webview --- app/assets/javascripts/origami.js | 12 +++++++++ app/controllers/api/survey_controller.rb | 2 +- app/controllers/base_origami_controller.rb | 29 ++++++++++++++++++++++ app/controllers/origami/home_controller.rb | 7 ++++++ app/views/origami/dashboard/index.html.erb | 2 +- app/views/origami/home/index.html.erb | 3 +++ config/locales/en.yml | 2 +- config/locales/mm.yml | 2 +- 8 files changed, 55 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/origami.js b/app/assets/javascripts/origami.js index 573f7c9e..7e91163f 100755 --- a/app/assets/javascripts/origami.js +++ b/app/assets/javascripts/origami.js @@ -387,3 +387,15 @@ function resCBPay(resMsg,card_sale_trans_id,cmd_type,payment_type,bnk_bill_amoun function setHeaderBreadCrumb(params){ $("#others_payment").html(params); } + +//show hide nav bar for webview +function showHideNavbar(webview,page){ + // if(webview){ + $("nav.navbar").hide(); + // if(page=="index"){ + // $(".btn-lists").hide(); + // } + // }else{ + // $("nav.navbar").show(); + // } +} diff --git a/app/controllers/api/survey_controller.rb b/app/controllers/api/survey_controller.rb index 879c9ea7..23f9c699 100644 --- a/app/controllers/api/survey_controller.rb +++ b/app/controllers/api/survey_controller.rb @@ -1,5 +1,5 @@ class Api::SurveyController < Api::ApiController - skip_before_action :authenticate + # before_action :authenticate def index dining_facility = DiningFacility.find(params[:id]) diff --git a/app/controllers/base_origami_controller.rb b/app/controllers/base_origami_controller.rb index e14a6959..45b9434d 100755 --- a/app/controllers/base_origami_controller.rb +++ b/app/controllers/base_origami_controller.rb @@ -33,5 +33,34 @@ class BaseOrigamiController < ActionController::Base def shop_detail @shop = Shop.first end + + #check webview + def check_mobile + status = false + if request.user_agent =~ /android|blackberry|iphone|ipad|ipod|iemobile|mobile|webos/i + status = true + end + return status + end + # protected + # # Authenticate the user with token based authentication + # def authenticate + # authenticate_token || render_unauthorized + # end + + # def authenticate_token + # authenticate_with_http_token do |token, options| + # Rails.logger.debug "token - " + token.to_s + # @user = Employee.authenticate_by_token(token) + # if @user + # return true + # end + # end + # end + + # def render_unauthorized(realm = "Application") + # request.headers["WWW-Authenticate"] = %(Token realm="#{realm.gsub(/"/, "")}") + # render json: 'Bad credentials', status: :unauthorized + # end end diff --git a/app/controllers/origami/home_controller.rb b/app/controllers/origami/home_controller.rb index 759cb1b6..2d19c9c5 100755 --- a/app/controllers/origami/home_controller.rb +++ b/app/controllers/origami/home_controller.rb @@ -3,6 +3,13 @@ class Origami::HomeController < BaseOrigamiController before_action :set_dining, only: [:show] def index + @webview = false + if check_mobile + puts "request data" + @webview = true + end + puts @webview == false + @tables = Table.all.active.order('status desc') @rooms = Room.all.active.order('status desc') @complete = Sale.where("DATE_FORMAT(created_at,'%Y-%m-%d') = ? and sale_status != 'new'",DateTime.now.strftime('%Y-%m-%d')) diff --git a/app/views/origami/dashboard/index.html.erb b/app/views/origami/dashboard/index.html.erb index c50b92f9..2d7657f5 100644 --- a/app/views/origami/dashboard/index.html.erb +++ b/app/views/origami/dashboard/index.html.erb @@ -31,7 +31,7 @@
arrow_forward
-
<%= t :dine_in_order %>
+
<%= t :dine_in_cashier %>
diff --git a/app/views/origami/home/index.html.erb b/app/views/origami/home/index.html.erb index aa000aab..5c0a51cd 100755 --- a/app/views/origami/home/index.html.erb +++ b/app/views/origami/home/index.html.erb @@ -139,6 +139,9 @@ \ No newline at end of file diff --git a/app/views/origami/customers/index.html.erb b/app/views/origami/customers/index.html.erb index 181319b9..59badabe 100755 --- a/app/views/origami/customers/index.html.erb +++ b/app/views/origami/customers/index.html.erb @@ -274,6 +274,9 @@ var cashier_type = "<%= @cashier_type %>"; var page = "<%= @page %>"; $(function() { + /* check webview loaded*/ + var webview = <%= @webview %>; + showHideNavbar(webview); /*$('.datepicker').datepicker({ setDate: '12-12-1999', format : 'dd-mm-yyyy', diff --git a/app/views/origami/discounts/index.html.erb b/app/views/origami/discounts/index.html.erb index fc05b630..59341bcb 100755 --- a/app/views/origami/discounts/index.html.erb +++ b/app/views/origami/discounts/index.html.erb @@ -257,6 +257,9 @@ var cashier_type = "<%= @cashier_type %>"; $(document).ready(function(){ setHeaderBreadCrumb(_DISCOUNTS_); + /* check webview loaded*/ + var webview = <%= @webview %>; + showHideNavbar(webview); $('#back').on('click',function(){ var id = $("#table_id").text(); diff --git a/app/views/origami/home/index.html.erb b/app/views/origami/home/index.html.erb index 5c0a51cd..38f0cc79 100755 --- a/app/views/origami/home/index.html.erb +++ b/app/views/origami/home/index.html.erb @@ -1,7 +1,7 @@
-
+
-
+