From 743b978c446e524ec29ee2d87b1d8a40b5d11bbf Mon Sep 17 00:00:00 2001 From: Nweni Date: Sun, 4 Jun 2017 15:52:29 +0630 Subject: [PATCH 001/128] update --- app/views/settings/menu_item_instances/_form.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/settings/menu_item_instances/_form.html.erb b/app/views/settings/menu_item_instances/_form.html.erb index c0170245..7d326c95 100644 --- a/app/views/settings/menu_item_instances/_form.html.erb +++ b/app/views/settings/menu_item_instances/_form.html.erb @@ -1,5 +1,5 @@ -<%= simple_form_for([:settings,:menu_item, @settings_menu_item_instance]) do |f| %> +<%= simple_form_for([:settings,@item, @settings_menu_item_instances]) do |f| %> <%= f.error_notification %> From e6cef8ef937ab82830ad8283b75e83b0083b95ac Mon Sep 17 00:00:00 2001 From: Phyo Date: Sun, 18 Jun 2017 11:57:14 +0630 Subject: [PATCH 002/128] Redeem amount not cut bug Fix --- app/models/sale_payment.rb | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 731fa321..465a8e5b 100644 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -187,17 +187,17 @@ class SalePayment < ApplicationRecord payment_status = false #Next time - validate if the vochure number is valid - within - self.payment_method = "paypar" - self.payment_amount = self.received_amount - self.payment_reference = self.voucher_no - self.outstanding_amount = self.sale.grand_total.to_f - self.received_amount.to_f - self.payment_status = "pending" - payment_method = self.save! customer_data = Customer.find_by_customer_id(self.sale.customer_id) membership_setting = MembershipSetting.find_by_membership_type("paypar_url") membership_data = SalePayment.redeem(membership_setting.gateway_url,membership_setting.auth_token,customer_data.membership_id,self.received_amount,self.sale.sale_id) if membership_data["status"]==true + self.payment_method = "paypar" + self.payment_amount = self.received_amount + self.payment_reference = self.voucher_no + self.outstanding_amount = self.sale.grand_total.to_f - self.received_amount.to_f + self.payment_status = "pending" + payment_method = self.save! SalePayment.where(:sale_payment_id => self.sale_payment_id).update_all(:payment_status => 'paid') sale_update_payment_status(self.received_amount.to_f) @@ -251,7 +251,12 @@ class SalePayment < ApplicationRecord payparcost = payparcost + pp.payment_amount end end - total_amount = food_prices - payparcost + overall_dis = SaleItem.get_overall_discount(sObj.id) + total_amount = food_prices - payparcost + overall_dis + puts "total_amount" + puts food_prices + puts payparcost + puts total_amount if total_amount > 0 receipt_no = sObj.receipt_no membership = MembershipSetting.find_by_membership_type("paypar_url") @@ -266,7 +271,7 @@ class SalePayment < ApplicationRecord 'Content-Type' => 'application/json', 'Accept' => 'application/json' }) - + puts "haha" puts response.to_json end end From 3a1fba2c6f2f1a3fb96e5e130c5513b3aec622c0 Mon Sep 17 00:00:00 2001 From: Phyo Date: Sun, 18 Jun 2017 13:18:23 +0630 Subject: [PATCH 003/128] Other Payments Bug fix --- app/views/origami/jcb/index.html.erb | 8 +++++++- app/views/origami/master/index.html.erb | 8 +++++++- app/views/origami/mpu/index.html.erb | 8 +++++++- app/views/origami/visa/index.html.erb | 8 +++++++- 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/app/views/origami/jcb/index.html.erb b/app/views/origami/jcb/index.html.erb index 6d08b25a..9c239931 100644 --- a/app/views/origami/jcb/index.html.erb +++ b/app/views/origami/jcb/index.html.erb @@ -96,6 +96,12 @@ \ No newline at end of file diff --git a/app/views/reports/daily_sale/index.html.erb b/app/views/reports/daily_sale/index.html.erb new file mode 100644 index 00000000..4aa0c841 --- /dev/null +++ b/app/views/reports/daily_sale/index.html.erb @@ -0,0 +1,190 @@ + + +
+ <%= render :partial=>'shift_sale_report_filter', + :locals=>{ :period_type => true, :shift_name => false, :report_path =>reports_daily_sale_index_path} %> +
+
+ +
+
+ +
+
+ +
+
+
+ + + <% if params[:from]%> + + + + <% end %> + + + + + + + + + + + + + + + + + + + <% unless @sale_data.empty? %> + + + <% void = 0 %> + <% mpu = 0 %> + <% master = 0 %> + <% visa = 0 %> + <% jcb = 0 %> + <% paypar = 0 %> + <% cash = 0 %> + <% credit = 0 %> + <% foc = 0 %> + <% discount = 0 %> + <% total = 0 %> + <% grand_total = 0 %> + <% count = 1 %> <% rounding_adj = 0 %> + <% @sale_data.each do |sale| %> + <% void += sale[:void_amount] %> + <% mpu += sale[:mpu_amount] %> + <% master += sale[:master_amount] %> + <% visa += sale[:visa_amount] %> + <% jcb += sale[:jcb_amount] %> + <% paypar += sale[:paypar_amount] %> + <% cash += sale[:cash_amount] %> + <% credit += sale[:credit_amount] %> + <% foc += sale[:foc_amount] %> + <% discount += sale[:total_discount] %> + <% total += sale[:grand_total].to_f + sale[:rounding_adj].to_f %> + <% grand_total += sale[:grand_total].to_f %> + <% rounding_adj += sale[:rounding_adj].to_f %> + + + + + + + + + + + + + + + + + + <% count = count + 1 %> + <% end %> + + + + + + + + + + + + + + + + + + <% total_tax = 0 %> + <% unless @tax.empty? %> + <% @tax.each do |tax| %> + <% total_tax += tax.tax_amount.to_f %> + + + + + + + <% end %> + <% net = total - total_tax %> + + + + + + <% end %> + + <% end %> +
Sale (<%= params[:from] rescue '-' %> - <%= params[:to] rescue '-'%>)
Sr.noDateDaily Void AmountDaily mpu SalesDaily master SalesDaily visa SalesDaily jcb SalesDaily paypar SalesDaily Cash SalesDaily Credit SalesDaily FOC Sales(Daily Discount)Grand Total +
Rounding Adj.
Rounding Adj.Grand Total
<%= count %><%= sale[:sale_date].strftime("#{sale[:sale_date].day.ordinalize} %b") rescue '-' %><%= number_with_delimiter(sprintf("%.2f",sale[:void_amount]), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",sale[:mpu_amount]), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",sale[:master_amount]), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",sale[:visa_amount]), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",sale[:jcb_amount]), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",sale[:paypar_amount]), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",sale[:cash_amount]), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",sale[:credit_amount]), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",sale[:foc_amount]), :delimiter => ',') rescue '-'%>(<%= number_with_delimiter(sprintf("%.2f",sale[:total_discount]), :delimiter => ',') rescue '-'%>)<%= number_with_delimiter(sprintf("%.2f",sale[:grand_total].to_f + sale[:rounding_adj].to_f ), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",sale[:rounding_adj].to_f), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",sale[:grand_total]), :delimiter => ',') rescue '-'%>
Total<%= number_with_delimiter(sprintf("%.2f",mpu_amount), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",master_amount), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",visa_amount), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",jcb_amount), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",paypar_amount), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",cash), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",credit), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",foc), :delimiter => ',') rescue '-'%>(<%= number_with_delimiter(sprintf("%.2f",discount), :delimiter => ',') rescue '-'%>)<%= number_with_delimiter(sprintf("%.2f",total), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",rounding_adj), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",grand_total), :delimiter => ',') rescue '-'%>
<%= tax.tax_name rescue '-'%><%= number_with_delimiter(sprintf("%.2f",tax.tax_amount), :delimiter => ',') rescue '-'%> 
Net Amount<%= number_with_delimiter(sprintf("%.2f",net), :delimiter => ',') rescue '-'%> 
+
+
+
+ + + \ No newline at end of file diff --git a/app/views/reports/daily_sale/index.xls.erb b/app/views/reports/daily_sale/index.xls.erb new file mode 100644 index 00000000..dfcc18d4 --- /dev/null +++ b/app/views/reports/daily_sale/index.xls.erb @@ -0,0 +1,116 @@ +
+
+ + + <% if params[:from]%> + + + + <% end %> + + + + + + + + + + + + + + + + + + + <% unless @sale_data.empty? %> + + + <% void = 0 %> + <% mpu = 0 %> + <% master = 0 %> + <% visa = 0 %> + <% jcb = 0 %> + <% paypar = 0 %> + <% cash = 0 %> + <% credit = 0 %> + <% foc = 0 %> + <% discount = 0 %> + <% total = 0 %> + <% grand_total = 0 %> + <% count = 1 %> <% rounding_adj = 0 %> + <% @sale_data.each do |sale| %> + <% void += sale[:void_amount] %> + <% mpu += sale[:mpu_amount] %> + <% master += sale[:master_amount] %> + <% visa += sale[:visa_amount] %> + <% jcb += sale[:jcb_amount] %> + <% paypar += sale[:paypar_amount] %> + <% cash += sale[:cash_amount] %> + <% credit += sale[:credit_amount] %> + <% foc += sale[:foc_amount] %> + <% discount += sale[:total_discount] %> + <% total += sale[:grand_total].to_f + sale[:rounding_adj].to_f %> + <% grand_total += sale[:grand_total].to_f %> + <% rounding_adj += sale[:rounding_adj].to_f %> + + + + + + + + + + + + + + + + + + <% count = count + 1 %> + <% end %> + + + + + + + + + + + + + + + + + + <% total_tax = 0 %> + <% unless @tax.empty? %> + <% @tax.each do |tax| %> + <% total_tax += tax.tax_amount.to_f %> + + + + + + + <% end %> + <% net = total - total_tax %> + + + + + + <% end %> + + <% end %> +
Sale (<%= params[:from] rescue '-' %> - <%= params[:to] rescue '-'%>)
Sr.noDateDaily Void AmountDaily mpu SalesDaily master SalesDaily visa SalesDaily jcb SalesDaily paypar SalesDaily Cash SalesDaily Credit SalesDaily FOC Sales(Daily Discount)Grand Total +
Rounding Adj.
Rounding Adj.Grand Total
<%= count %><%= sale[:sale_date].strftime("#{sale[:sale_date].day.ordinalize} %b") rescue '-' %><%= number_with_delimiter(sprintf("%.2f",sale[:void_amount]), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",sale[:mpu_amount]), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",sale[:master_amount]), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",sale[:visa_amount]), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",sale[:jcb_amount]), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",sale[:paypar_amount]), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",sale[:cash_amount]), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",sale[:credit_amount]), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",sale[:foc_amount]), :delimiter => ',') rescue '-'%>(<%= number_with_delimiter(sprintf("%.2f",sale[:total_discount]), :delimiter => ',') rescue '-'%>)<%= number_with_delimiter(sprintf("%.2f",sale[:grand_total].to_f + sale[:rounding_adj].to_f ), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",sale[:rounding_adj].to_f), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",sale[:grand_total]), :delimiter => ',') rescue '-'%>
Total<%= number_with_delimiter(sprintf("%.2f",mpu_amount), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",master_amount), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",visa_amount), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",jcb_amount), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",paypar_amount), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",cash), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",credit), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",foc), :delimiter => ',') rescue '-'%>(<%= number_with_delimiter(sprintf("%.2f",discount), :delimiter => ',') rescue '-'%>)<%= number_with_delimiter(sprintf("%.2f",total), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",rounding_adj), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",grand_total), :delimiter => ',') rescue '-'%>
<%= tax.tax_name rescue '-'%><%= number_with_delimiter(sprintf("%.2f",tax.tax_amount), :delimiter => ',') rescue '-'%> 
Net Amount<%= number_with_delimiter(sprintf("%.2f",net), :delimiter => ',') rescue '-'%> 
+
+
\ No newline at end of file diff --git a/app/views/reports/daily_sale_report.html.erb b/app/views/reports/daily_sale_report.html.erb index e69de29b..786951f5 100644 --- a/app/views/reports/daily_sale_report.html.erb +++ b/app/views/reports/daily_sale_report.html.erb @@ -0,0 +1,20 @@ + + +
+ <%= render :partial=>'shift_sale_report_filter', + :locals=>{ :period_type => true, :shift_name => false, :report_path =>reports_receipt_no_index_path} %> +
+
+ +
+
+ +
+
diff --git a/config/routes.rb b/config/routes.rb index b5f944b5..22a042bd 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -210,6 +210,7 @@ Rails.application.routes.draw do #--------- Reports Controller Sections ------------# namespace :reports do resources :receipt_no, :only => [:index, :show] + resources :daily_sale, :only => [:index, :show] # resources :sales, :only => [:index, :show] # resources :orders, :only => [:index, :show] # resources :customers, :only => [:index, :show] From b65d127fd0463c266cca2dc01852104229f3eb59 Mon Sep 17 00:00:00 2001 From: Yan Date: Sun, 18 Jun 2017 20:07:28 +0630 Subject: [PATCH 006/128] bill print format and tax fix --- app/assets/javascripts/origami.js | 39 ++++++++++++++------------- app/models/order.rb | 4 +-- app/models/sale.rb | 12 ++++++--- app/pdf/receipt_bill_pdf.rb | 37 ++++++++++++++----------- app/views/origami/home/index.html.erb | 6 ++--- 5 files changed, 56 insertions(+), 42 deletions(-) diff --git a/app/assets/javascripts/origami.js b/app/assets/javascripts/origami.js index 78a21c3b..d4071432 100644 --- a/app/assets/javascripts/origami.js +++ b/app/assets/javascripts/origami.js @@ -55,7 +55,7 @@ $(document).ready(function(){ var cashier=""; var receipt_date=""; - var sub_total=0; + var sub_total=0.0; var discount_amount=0; var tax_amount=0; var grand_total_amount=0; @@ -69,11 +69,11 @@ $(document).ready(function(){ type: "POST", url: "/origami/" + unique_id, data: { 'booking_id' : unique_id }, - success:function(result){ + success:function(result){ for (i = 0; i < result.length; i++) { var data = JSON.stringify(result[i]); var parse_data = JSON.parse(data); - var show_date = ""; + var show_date = ""; // Receipt Header receipt_no = result[i].receipt_no; @@ -81,36 +81,37 @@ $(document).ready(function(){ if(result[i].receipt_date != null){ receipt_date = new Date(result[i].receipt_date); show_date = receipt_date.getDate() + "-" + receipt_date.getMonth() + "-" + receipt_date.getFullYear() + ' ' + receipt_date.getHours()+ ':' + receipt_date.getMinutes() - } - - $("#receipt_no").text(receipt_no); - $("#cashier").text(cashier == null ? "" : cashier); - $("#receipt_date").text(show_date); - + } //Receipt Charges - sub_total += (parse_data.qty*parse_data.price); + sub_total += parseFloat(parse_data.price); discount_amount = parse_data.discount_amount == null? '0.0' : parse_data.discount_amount; tax_amount = parse_data.tax_amount; - grand_total_amount = parse_data.grand_total_amount; - - $("#order-sub-total").text(sub_total); - // $("#order-food").text(''); - // $("#order-beverage").text(''); - $("#order-discount").text(discount_amount); - $("#order-Tax").text(tax_amount); - $("#order-grand-total").text(grand_total_amount); + grand_total_amount = parse_data.grand_total_amount; // Ordered Items var order_items_rows = "" + "" + parse_data.item_name + "" + "" + parse_data.qty + "" + - "" + parse_data.qty*parse_data.price + "" + + "" + parse_data.price + "" + ""; $("#order-items-table").children("tbody").append(order_items_rows); } + + // Cashier Info + $("#receipt_no").text(receipt_no); + $("#cashier").text(cashier == null ? "" : cashier); + $("#receipt_date").text(show_date); + + // Payment Info + $("#order-sub-total").text(sub_total); + // $("#order-food").text(''); + // $("#order-beverage").text(''); + $("#order-discount").text(discount_amount); + $("#order-Tax").text(tax_amount); + $("#order-grand-total").text(grand_total_amount); } }); // End AJAX Call diff --git a/app/models/order.rb b/app/models/order.rb index 14fd8cda..a4328d76 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -231,7 +231,7 @@ class Order < ApplicationRecord .joins("left join orders on orders.order_id = booking_orders.order_id") .joins("left join sales on sales.sale_id = bookings.sale_id") .where("(orders.status = 'new' or orders.status = 'billed') and (dining_facilities.type=? and dining_facilities.is_active=?)",DiningFacility::TABLE_TYPE,true) - .group("bookings.booking_id,sales.receipt_no,orders.status,sales.sale_id,dining_facilities.name,orders.status,orders.order_id") + .group("bookings.booking_id") # For PG # booking_orders.order_id IS NOT NULL and dining_facilities.type=? and dining_facilities.is_active=?",DiningFacility::TABLE_TYPE,true # sales.receipt_no,orders.status,sales.sale_id,dining_facilities.name,orders.status,orders.order_id @@ -262,7 +262,7 @@ class Order < ApplicationRecord .joins("left join orders on orders.order_id = booking_orders.order_id") .joins("left join sales on sales.sale_id = bookings.sale_id") .where("(orders.status = 'new' or orders.status = 'billed') and (dining_facilities.type=? and dining_facilities.is_active=?)",DiningFacility::ROOM_TYPE,true) - .group("bookings.booking_id,sales.receipt_no,orders.status,sales.sale_id,dining_facilities.name,orders.customer_id,orders.order_id") + .group("bookings.booking_id") # For PG # booking_orders.order_id IS NOT NULL and dining_facilities.type=? and dining_facilities.is_active=?",DiningFacility::ROOM_TYPE,true # sales.receipt_no,orders.status,sales.sale_id,dining_facilities.name,orders.customer_id,orders.order_id diff --git a/app/models/sale.rb b/app/models/sale.rb index 3714c21e..ccd2a96a 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -23,8 +23,7 @@ class Sale < ApplicationRecord if (booking) Rails.logger.debug "Booking -> Booking Order Count -> " + booking.booking_orders.count.to_s #get all order attached to this booking and combine into 1 invoice - - puts booking.booking_orders.length + booking.booking_orders.each do |order| if booking.sale_id status, sale_id = generate_invoice_from_order(order.order_id, nil, booking, requested_by) @@ -90,6 +89,8 @@ class Sale < ApplicationRecord order.save booking.sale_id = self.id + booking.checkout_at = Time.now.utc + booking.checkout_by = requested_by.name booking.save return true, self.id @@ -190,9 +191,14 @@ class Sale < ApplicationRecord # Tax Calculate def apply_tax(total_taxable) + #if tax is not apply create new record + # self.sale_taxes.each do |existing_tax| + # #delete existing and create new + # existing_tax.delete + # end #if tax is not apply create new record - self.sale_taxes.each do |existing_tax| + SaleTax.where("sale_id='#{self.sale_id}'").find_each do |existing_tax| #delete existing and create new existing_tax.delete end diff --git a/app/pdf/receipt_bill_pdf.rb b/app/pdf/receipt_bill_pdf.rb index 6cacc391..c1ba4936 100644 --- a/app/pdf/receipt_bill_pdf.rb +++ b/app/pdf/receipt_bill_pdf.rb @@ -4,9 +4,9 @@ class ReceiptBillPdf < Prawn::Document self.page_width = 210 self.page_height = 2500 self.margin = 5 - self.price_width = 35 + self.price_width = 40 self.qty_width = 20 - self.total_width = 35 + self.total_width = 40 self.item_width = self.page_width - ((self.price_width + self.qty_width + self.total_width)) self.item_height = 15 self.item_description_width = (self.page_width-20) / 2 @@ -53,29 +53,36 @@ class ReceiptBillPdf < Prawn::Document # move_down 2 y_position = cursor bounding_box([0,y_position], :width =>self.label_width, :height => self.item_height) do - text "Receipt No:", :size => self.item_font_size,:align => :left + text "Receipt No: #{sale_data.receipt_no}", :size => self.item_font_size,:align => :left end - - bounding_box([self.label_width, y_position], :width =>self.item_width) do - text "#{sale_data.receipt_no}" , :size => self.item_font_size, :align => :left + bounding_box([self.label_width,y_position], :width => self.label_width, :height => self.item_height) do + text "#{ sale_data.bookings[0].dining_facility.name }" , :size => self.item_font_size,:align => :right end move_down 5 y_position = cursor - bounding_box([0,y_position], :width =>self.label_width, :height => self.item_height) do - text "Customer:", :size => self.item_font_size,:align => :left + bounding_box([0, y_position], :width =>self.item_width) do + text "Waiter: #{sale_data.requested_by}" , :size => self.item_font_size, :align => :left end - bounding_box([self.label_width,y_position], :width =>self.item_width) do - text "#{customer_name}" , :size => self.item_font_size,:align => :left + move_down 5 + + y_position = cursor + bounding_box([0,y_position], :width =>self.item_width, :height => self.item_height) do + text "Cashier: #{sale_data.cashier_name}", :size => self.item_font_size,:align => :left end move_down 5 + # bounding_box([self.label_width,y_position], :width =>self.item_width) do + # text "#{customer_name}" , :size => self.item_font_size,:align => :left + # end + # move_down 5 + y_position = cursor bounding_box([0,y_position], :width =>self.label_width, :height => self.item_height) do - text "Date:", :size => self.item_font_size,:align => :left + text "Time In: #{ sale_data.bookings[0].checkin_at.strftime('%I:%M %p') }", :size => self.item_font_size,:align => :left end - bounding_box([self.label_width,y_position], :width => self.item_width) do - text "#{sale_data.receipt_date.strftime('%Y-%m-%d %I:%M %p')}" , :size => self.item_font_size,:align => :left + bounding_box([self.label_width,y_position], :width => self.label_width, :height => self.item_height) do + text "Time Out: #{ sale_data.bookings[0].checkout_at.strftime('%I:%M %p') }" , :size => self.item_font_size,:align => :right end move_down 5 @@ -118,7 +125,7 @@ class ReceiptBillPdf < Prawn::Document y_position = cursor pad_top(15) { - text_box "#{product_name}", :at =>[0,y_position], :width => self.item_width, :height =>self.item_height, :overflow => :shrink_to_fix, :size => self.item_font_size, :overflow => :shrink_to_fix + text_box "#{product_name}", :at =>[0,y_position], :width => self.item_width, :height =>self.item_height, :size => self.item_font_size, :overflow => :shrink_to_fix text_box "#{price}", :at =>[self.item_width,y_position], :width => self.price_width, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix text_box "#{qty}", :at =>[item_name_width,y_position], :width => self.qty_width, :height =>self.item_height, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix text_box "#{total_price}", :at =>[(item_name_width),y_position], :width =>self.total_width+5, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix @@ -163,7 +170,7 @@ class ReceiptBillPdf < Prawn::Document text "( " +"#{sale_data.total_discount}" +" )" , :size => self.item_font_size,:align => :right end - if sale_data.sale_taxes.length > 1 + if sale_data.sale_taxes.length > 0 sale_data.sale_taxes.each do |st| move_down 5 y_position = cursor diff --git a/app/views/origami/home/index.html.erb b/app/views/origami/home/index.html.erb index ff83dad4..ce2b3a94 100644 --- a/app/views/origami/home/index.html.erb +++ b/app/views/origami/home/index.html.erb @@ -306,12 +306,12 @@ sub_total = 0 if @selected_item_type == "Sale" @selected_item.sale_items.each do |sale_item| - sub_total += (sale_item.qty*sale_item.unit_price) + sub_total = sub_total + sale_item.price %> <%= sale_item.product_name %> <%= sale_item.qty %> - <%= sale_item.qty*sale_item.price %> + <%= sale_item.price %> <% end @@ -322,7 +322,7 @@ # For Order Items if @selected_item_type == "Order" @selected_item.order_items.each do |order_item| - sub_total += (order_item.qty*order_item.unit_price) + sub_total = sub_total + (order_item.qty*order_item.price) %> <%= order_item.item_name %> From faa6beb2436dae9a0b0c190298a54fd41d91bbb0 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Sun, 18 Jun 2017 20:23:39 +0630 Subject: [PATCH 007/128] update sale report --- .../_shift_sale_report_filter.html.erb | 62 ------------------- 1 file changed, 62 deletions(-) diff --git a/app/views/reports/daily_sale/_shift_sale_report_filter.html.erb b/app/views/reports/daily_sale/_shift_sale_report_filter.html.erb index 815cf24c..04e548da 100644 --- a/app/views/reports/daily_sale/_shift_sale_report_filter.html.erb +++ b/app/views/reports/daily_sale/_shift_sale_report_filter.html.erb @@ -145,68 +145,6 @@ $(function(){ // window.location = url; }); - var item = $('#item').val(); - var payment_type = $('#payment_type'); - - if(item == 'order'){ - $('#cashier').hide(); - $('#waiter').show(); - if(payment_type){ - $('#payment_type').hide(); - } - } - else if(item == 'sale'){ - $('#waiter').hide(); - $('#cashier').show(); - } - else{ - $('#waiter').hide(); - $('#cashier').show(); - $("#item").val('sale'); - } }); -//Reset the form to pervious values -$("#branch").val(<%=params[:branch]%>); -$("#waiter").val("<%=params[:waiter]%>"); -$("#cashier").val(<%=params[:cashier]%>); -$("#product").val(<%=params[:product]%>); -$("#singer").val(<%=params[:singer]%>); -$("#item").val('<%=params[:item]%>'); -$("#guest_role").val('<%=params[:guest_role]%>'); - - -$("#from").val("<%=params[:from]%>"); -$("#to").val("<%=params[:to]%>"); -$("#sel_period").val(<%=params[:period]%>); -$("#sel_sale_type").val(<%=params[:sale_type]%>); - -<% if params[:period_type] == 1 || params[:period_type] == "1" %> - $("#rd_period_type_1").attr("checked","checked"); -<% else %> - $("#rd_period_type_0").attr("checked","checked"); -<% end %> -$(".btn-group button").removeClass("active"); -<% report_type = params[:report_type].blank? ? "0" : params[:report_type] %> -$("#btn_report_type_<%= report_type %>").addClass("active"); - -$('#item').change(function(){ - var item = $('#item').val(); - var payment_type = $('#payment_type'); - - if(item == 'sale'){ - $('#waiter').hide(); - $('#cashier').show(); - if(payment_type){ - $('#payment_type').show(); - } - } - else{ - $('#cashier').hide(); - $('#waiter').show(); - if(payment_type){ - $('#payment_type').hide(); - } - } -}); \ No newline at end of file From 675d83c80fff58933c8d42c3c2d542cd1fb689e5 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Mon, 19 Jun 2017 11:54:34 +0630 Subject: [PATCH 008/128] sale item report and rebate balance --- app/assets/javascripts/application.js | 7 + app/assets/javascripts/origami.js | 2 +- app/controllers/crm/customers_controller.rb | 10 +- .../reports/daily_sale_controller.rb | 12 -- .../reports/sale_item_controller.rb | 14 ++ app/models/sale.rb | 42 ++++++ app/pdf/receipt_bill_pdf.rb | 47 +++--- app/views/origami/home/index.html.erb | 2 +- .../_shift_sale_report_filter.html.erb | 1 + app/views/reports/daily_sale/index.html.erb | 20 +-- app/views/reports/daily_sale/index.xls.erb | 20 +-- app/views/reports/daily_sale_report.html.erb | 20 --- .../_shift_sale_report_filter.html.erb | 73 ++------- app/views/reports/sale_item/index.html.erb | 141 ++++++++++++++++++ app/views/reports/sale_item/index.xls.erb | 116 ++++++++++++++ config/routes.rb | 1 + 16 files changed, 391 insertions(+), 137 deletions(-) create mode 100644 app/controllers/reports/sale_item_controller.rb delete mode 100644 app/views/reports/daily_sale_report.html.erb rename app/views/reports/{ => sale_item}/_shift_sale_report_filter.html.erb (77%) create mode 100644 app/views/reports/sale_item/index.html.erb create mode 100644 app/views/reports/sale_item/index.xls.erb diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 202d4387..8604d3c8 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -25,6 +25,13 @@ $(document).on("focus", "[data-behaviour~='datepicker']", function(e){ $('.dropdown-toggle').dropdown(); }); +function export_to(path) +{ + var form_params = $("#frm_report").serialize(); + alert(form_params); + window.location = path+"?"+ form_params; +} + /* * ToDo Move to here from pages * diff --git a/app/assets/javascripts/origami.js b/app/assets/javascripts/origami.js index 78a21c3b..88bd919d 100644 --- a/app/assets/javascripts/origami.js +++ b/app/assets/javascripts/origami.js @@ -49,7 +49,7 @@ $(document).ready(function(){ control_button(order_status); var customer_id=$(this).find(".customer-id").text(); - show_customer_details(customer_id); + //show_customer_details(customer_id); $("#re-print").val(unique_id); diff --git a/app/controllers/crm/customers_controller.rb b/app/controllers/crm/customers_controller.rb index 290f6ca1..d83d434f 100644 --- a/app/controllers/crm/customers_controller.rb +++ b/app/controllers/crm/customers_controller.rb @@ -95,6 +95,7 @@ class Crm::CustomersController < BaseCrmController auth_token = memberaction.auth_token.to_s url = membership.gateway_url.to_s + memberaction.gateway_url.to_s + begin response = HTTParty.post(url, :body => { name: name,phone: phone,email: email, dob: dob, member_group_id: member_group_id,merchant_uid:merchant_uid,auth_token:auth_token}.to_json, @@ -103,6 +104,9 @@ class Crm::CustomersController < BaseCrmController 'Accept' => 'application/json' } ) + rescue Net::OpenTimeout + response = { status: false } + end if response["status"] == true @@ -159,7 +163,7 @@ end merchant_uid = memberaction.merchant_account_id.to_s auth_token = memberaction.auth_token.to_s url = membership.gateway_url.to_s + memberaction.gateway_url.to_s - + begin response = HTTParty.post(url, :body => { name: name,phone: phone,email: email, dob: dob, id: id,member_group_id:member_group_id,merchant_uid:merchant_uid,auth_token:auth_token}.to_json, @@ -168,7 +172,9 @@ end 'Accept' => 'application/json' } ) - + rescue Net::OpenTimeout + response = { status: false } + end format.html { redirect_to crm_customers_path, notice: 'Customer was successfully updated.' } format.json { render :show, status: :ok, location: @crm_customer } diff --git a/app/controllers/reports/daily_sale_controller.rb b/app/controllers/reports/daily_sale_controller.rb index 86e60702..34a3b5e2 100644 --- a/app/controllers/reports/daily_sale_controller.rb +++ b/app/controllers/reports/daily_sale_controller.rb @@ -5,19 +5,7 @@ class Reports::DailySaleController < BaseReportController @sale_data = Sale.daily_sales_list(from,to) @tax = SaleTax.get_tax(from,to) end - - # @locations = Location.all - # branch,from, to, report_type = get_date_range_from_params - - # @location = Location.find_by_id(current_location) - # @sale_data = Sale.daily_sales_report(current_location,from,to) - # @tax = SaleT.get_tax(current_location,from,to) - - # if @sale_data.blank? && @tax.blank? && request.post? - # flash.now[:notice] = "No data available for selected filters" - # end - def show end diff --git a/app/controllers/reports/sale_item_controller.rb b/app/controllers/reports/sale_item_controller.rb new file mode 100644 index 00000000..40aea618 --- /dev/null +++ b/app/controllers/reports/sale_item_controller.rb @@ -0,0 +1,14 @@ +class Reports::SaleItemController < BaseReportController + + def index + + from, to, report_type = get_date_range_from_params + + @sale_data = Sale.get_by_range_by_saleitems(from,to,Sale::SALE_STATUS_COMPLETED,report_type) + end + + def show + + end + +end \ No newline at end of file diff --git a/app/models/sale.rb b/app/models/sale.rb index 999577d7..5e0691f4 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -16,6 +16,14 @@ class Sale < ApplicationRecord scope :open_invoices, -> { where("sale_status = 'new' and receipt_date BETWEEN '#{DateTime.now.utc.end_of_day}' AND '#{DateTime.now.utc.beginning_of_day}'") } + REPORT_TYPE = { + "daily" => 0, + "monthly" => 1, + "yearly" => 2 + } + + SALE_STATUS_COMPLETED = "completed" + def generate_invoice_from_booking(booking_id, requested_by) booking = Booking.find(booking_id) status = false @@ -328,6 +336,40 @@ class Sale < ApplicationRecord return daily_total end +def self.get_by_range_by_saleitems(from,to,status,report_type) + + query = Sale.select(" + mi.item_code as code,(SUM(i.qty) * i.unit_price) as grand_total, + SUM(i.qty) as total_item," + + " i.unit_price as unit_price, + mi.name as product_name, + mc.name as menu_category_name, + mc.id as menu_category_id ") + .group('mi.id') + .order("mi.menu_category_id") + + query = query.joins("JOIN sale_items i ON i.sale_id = sales.sale_id + JOIN menu_items mi ON i.product_code = mi.item_code" + + " JOIN menu_categories mc ON mc.id = mi.menu_category_id + JOIN employees ea ON ea.id = sales.cashier_id") + + + query = query.where("receipt_date between ? and ? and sale_status=?",from,to,status) + + + + case report_type.to_i + when REPORT_TYPE["daily"] + return query + when REPORT_TYPE["monthly"] + + return query.group("MONTH(date)") + when REPORT_TYPE["yearly"] + return query.group("YEAR(date)") + end + +end + private def generate_custom_id diff --git a/app/pdf/receipt_bill_pdf.rb b/app/pdf/receipt_bill_pdf.rb index 6cacc391..dfecfdf0 100644 --- a/app/pdf/receipt_bill_pdf.rb +++ b/app/pdf/receipt_bill_pdf.rb @@ -33,7 +33,7 @@ class ReceiptBillPdf < Prawn::Document all_total(sale_data) if member_info != nil - member_info(member_info) + member_info(member_info,customer_name) end footer end @@ -61,14 +61,14 @@ class ReceiptBillPdf < Prawn::Document end move_down 5 - y_position = cursor - bounding_box([0,y_position], :width =>self.label_width, :height => self.item_height) do - text "Customer:", :size => self.item_font_size,:align => :left - end - bounding_box([self.label_width,y_position], :width =>self.item_width) do - text "#{customer_name}" , :size => self.item_font_size,:align => :left - end - move_down 5 + # y_position = cursor + # bounding_box([0,y_position], :width =>self.label_width, :height => self.item_height) do + # text "Customer:", :size => self.item_font_size,:align => :left + # end + # bounding_box([self.label_width,y_position], :width =>self.item_width) do + # text "#{customer_name}" , :size => self.item_font_size,:align => :left + # end + # move_down 5 y_position = cursor bounding_box([0,y_position], :width =>self.label_width, :height => self.item_height) do @@ -203,19 +203,32 @@ class ReceiptBillPdf < Prawn::Document end # show member information - def member_info(member_info) + def member_info(member_info,customer_name) move_down 7 + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do + text "Customer", :size => self.item_font_size,:align => :left + end + bounding_box([self.item_description_width,y_position], :width =>self.label_width) do + text "#{ customer_name }" , :size => self.item_font_size,:align => :right + end + move_down 5 + if member_info["status"] == true member_info["data"].each do |res| - move_down 5 - y_position = cursor - bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do - text "#{ res["accountable_type"] }", :size => self.item_font_size,:align => :left - end - bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "#{ res["balance"] }" , :size => self.item_font_size,:align => :right + if res["accountable_type"]== "RebateAccount" + + move_down 5 + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do + text "Rebate Balance", :size => self.item_font_size,:align => :left + end + bounding_box([self.item_description_width,y_position], :width =>self.label_width) do + text "#{ res["balance"] }" , :size => self.item_font_size,:align => :right + end + end end diff --git a/app/views/origami/home/index.html.erb b/app/views/origami/home/index.html.erb index ff83dad4..6b7b0c20 100644 --- a/app/views/origami/home/index.html.erb +++ b/app/views/origami/home/index.html.erb @@ -364,7 +364,7 @@ <%=@selected_item.grand_total rescue 0%> --> - + diff --git a/app/views/reports/daily_sale/_shift_sale_report_filter.html.erb b/app/views/reports/daily_sale/_shift_sale_report_filter.html.erb index 04e548da..3a5d788c 100644 --- a/app/views/reports/daily_sale/_shift_sale_report_filter.html.erb +++ b/app/views/reports/daily_sale/_shift_sale_report_filter.html.erb @@ -147,4 +147,5 @@ $(function(){ }); + \ No newline at end of file diff --git a/app/views/reports/daily_sale/index.html.erb b/app/views/reports/daily_sale/index.html.erb index 4aa0c841..a2403045 100644 --- a/app/views/reports/daily_sale/index.html.erb +++ b/app/views/reports/daily_sale/index.html.erb @@ -32,16 +32,16 @@ Sr.no Date - Daily Void Amount - Daily mpu Sales - Daily master Sales - Daily visa Sales - Daily jcb Sales - Daily paypar Sales - Daily Cash Sales - Daily Credit Sales - Daily FOC Sales - (Daily Discount) + Void Amount + Mpu Sales + Master Sales + Visa Sales + Jcb Sales + Paypar Sales + Cash Sales + Credit Sales + FOC Sales + (Discount) Grand Total +
Rounding Adj. Rounding Adj. Grand Total diff --git a/app/views/reports/daily_sale/index.xls.erb b/app/views/reports/daily_sale/index.xls.erb index dfcc18d4..67e76e3c 100644 --- a/app/views/reports/daily_sale/index.xls.erb +++ b/app/views/reports/daily_sale/index.xls.erb @@ -10,16 +10,16 @@ Sr.no Date - Daily Void Amount - Daily mpu Sales - Daily master Sales - Daily visa Sales - Daily jcb Sales - Daily paypar Sales - Daily Cash Sales - Daily Credit Sales - Daily FOC Sales - (Daily Discount) + Void Amount + Mpu Sales + Master Sales + Visa Sales + Jcb Sales + Paypar Sales + Cash Sales + Credit Sales + FOC Sales + (Discount) Grand Total +
Rounding Adj. Rounding Adj. Grand Total diff --git a/app/views/reports/daily_sale_report.html.erb b/app/views/reports/daily_sale_report.html.erb deleted file mode 100644 index 786951f5..00000000 --- a/app/views/reports/daily_sale_report.html.erb +++ /dev/null @@ -1,20 +0,0 @@ - - -
- <%= render :partial=>'shift_sale_report_filter', - :locals=>{ :period_type => true, :shift_name => false, :report_path =>reports_receipt_no_index_path} %> -
-
- -
-
- -
-
diff --git a/app/views/reports/_shift_sale_report_filter.html.erb b/app/views/reports/sale_item/_shift_sale_report_filter.html.erb similarity index 77% rename from app/views/reports/_shift_sale_report_filter.html.erb rename to app/views/reports/sale_item/_shift_sale_report_filter.html.erb index 1b4082f5..7f95b6b9 100644 --- a/app/views/reports/_shift_sale_report_filter.html.erb +++ b/app/views/reports/sale_item/_shift_sale_report_filter.html.erb @@ -18,7 +18,8 @@ -
+ +
@@ -143,69 +144,13 @@ $(function(){ $('#frm_report').submit(); // window.location = url; }); + + function export_to(path) +{ + var form_params = $("#frm_report").serialize(); + window.location = path+"?"+ form_params; +} - var item = $('#item').val(); - var payment_type = $('#payment_type'); - - if(item == 'order'){ - $('#cashier').hide(); - $('#waiter').show(); - if(payment_type){ - $('#payment_type').hide(); - } - } - else if(item == 'sale'){ - $('#waiter').hide(); - $('#cashier').show(); - } - else{ - $('#waiter').hide(); - $('#cashier').show(); - $("#item").val('sale'); - } }); -//Reset the form to pervious values -$("#branch").val(<%=params[:branch]%>); -$("#waiter").val("<%=params[:waiter]%>"); -$("#cashier").val(<%=params[:cashier]%>); -$("#product").val(<%=params[:product]%>); -$("#singer").val(<%=params[:singer]%>); -$("#item").val('<%=params[:item]%>'); -$("#guest_role").val('<%=params[:guest_role]%>'); - - -$("#from").val("<%=params[:from]%>"); -$("#to").val("<%=params[:to]%>"); -$("#sel_period").val(<%=params[:period]%>); -$("#sel_sale_type").val(<%=params[:sale_type]%>); - -<% if params[:period_type] == 1 || params[:period_type] == "1" %> - $("#rd_period_type_1").attr("checked","checked"); -<% else %> - $("#rd_period_type_0").attr("checked","checked"); -<% end %> -$(".btn-group button").removeClass("active"); -<% report_type = params[:report_type].blank? ? "0" : params[:report_type] %> -$("#btn_report_type_<%= report_type %>").addClass("active"); - -$('#item').change(function(){ - var item = $('#item').val(); - var payment_type = $('#payment_type'); - - if(item == 'sale'){ - $('#waiter').hide(); - $('#cashier').show(); - if(payment_type){ - $('#payment_type').show(); - } - } - else{ - $('#cashier').hide(); - $('#waiter').show(); - if(payment_type){ - $('#payment_type').hide(); - } - } -}); \ No newline at end of file diff --git a/app/views/reports/sale_item/index.html.erb b/app/views/reports/sale_item/index.html.erb new file mode 100644 index 00000000..cce5a210 --- /dev/null +++ b/app/views/reports/sale_item/index.html.erb @@ -0,0 +1,141 @@ + + +
+ <%= render :partial=>'shift_sale_report_filter', + :locals=>{ :period_type => true, :shift_name => false, :report_path =>reports_sale_item_index_path} %> +
+
+ +
+
+ +
+
+ +
+
+
+ + + + + + + + + + + + + + + + + + +
Date
Menu CategoryCodeProductTotal ItemUnit PriceRevenue
+
+
+
+ + \ No newline at end of file diff --git a/app/views/reports/sale_item/index.xls.erb b/app/views/reports/sale_item/index.xls.erb new file mode 100644 index 00000000..dfcc18d4 --- /dev/null +++ b/app/views/reports/sale_item/index.xls.erb @@ -0,0 +1,116 @@ +
+
+ + + <% if params[:from]%> + + + + <% end %> + + + + + + + + + + + + + + + + + + + <% unless @sale_data.empty? %> + + + <% void = 0 %> + <% mpu = 0 %> + <% master = 0 %> + <% visa = 0 %> + <% jcb = 0 %> + <% paypar = 0 %> + <% cash = 0 %> + <% credit = 0 %> + <% foc = 0 %> + <% discount = 0 %> + <% total = 0 %> + <% grand_total = 0 %> + <% count = 1 %> <% rounding_adj = 0 %> + <% @sale_data.each do |sale| %> + <% void += sale[:void_amount] %> + <% mpu += sale[:mpu_amount] %> + <% master += sale[:master_amount] %> + <% visa += sale[:visa_amount] %> + <% jcb += sale[:jcb_amount] %> + <% paypar += sale[:paypar_amount] %> + <% cash += sale[:cash_amount] %> + <% credit += sale[:credit_amount] %> + <% foc += sale[:foc_amount] %> + <% discount += sale[:total_discount] %> + <% total += sale[:grand_total].to_f + sale[:rounding_adj].to_f %> + <% grand_total += sale[:grand_total].to_f %> + <% rounding_adj += sale[:rounding_adj].to_f %> + + + + + + + + + + + + + + + + + + <% count = count + 1 %> + <% end %> + + + + + + + + + + + + + + + + + + <% total_tax = 0 %> + <% unless @tax.empty? %> + <% @tax.each do |tax| %> + <% total_tax += tax.tax_amount.to_f %> + + + + + + + <% end %> + <% net = total - total_tax %> + + + + + + <% end %> + + <% end %> +
Sale (<%= params[:from] rescue '-' %> - <%= params[:to] rescue '-'%>)
Sr.noDateDaily Void AmountDaily mpu SalesDaily master SalesDaily visa SalesDaily jcb SalesDaily paypar SalesDaily Cash SalesDaily Credit SalesDaily FOC Sales(Daily Discount)Grand Total +
Rounding Adj.
Rounding Adj.Grand Total
<%= count %><%= sale[:sale_date].strftime("#{sale[:sale_date].day.ordinalize} %b") rescue '-' %><%= number_with_delimiter(sprintf("%.2f",sale[:void_amount]), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",sale[:mpu_amount]), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",sale[:master_amount]), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",sale[:visa_amount]), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",sale[:jcb_amount]), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",sale[:paypar_amount]), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",sale[:cash_amount]), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",sale[:credit_amount]), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",sale[:foc_amount]), :delimiter => ',') rescue '-'%>(<%= number_with_delimiter(sprintf("%.2f",sale[:total_discount]), :delimiter => ',') rescue '-'%>)<%= number_with_delimiter(sprintf("%.2f",sale[:grand_total].to_f + sale[:rounding_adj].to_f ), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",sale[:rounding_adj].to_f), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",sale[:grand_total]), :delimiter => ',') rescue '-'%>
Total<%= number_with_delimiter(sprintf("%.2f",mpu_amount), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",master_amount), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",visa_amount), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",jcb_amount), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",paypar_amount), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",cash), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",credit), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",foc), :delimiter => ',') rescue '-'%>(<%= number_with_delimiter(sprintf("%.2f",discount), :delimiter => ',') rescue '-'%>)<%= number_with_delimiter(sprintf("%.2f",total), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",rounding_adj), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",grand_total), :delimiter => ',') rescue '-'%>
<%= tax.tax_name rescue '-'%><%= number_with_delimiter(sprintf("%.2f",tax.tax_amount), :delimiter => ',') rescue '-'%> 
Net Amount<%= number_with_delimiter(sprintf("%.2f",net), :delimiter => ',') rescue '-'%> 
+
+
\ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 6253a95f..7bb463ee 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -212,6 +212,7 @@ Rails.application.routes.draw do namespace :reports do resources :receipt_no, :only => [:index, :show] resources :daily_sale, :only => [:index, :show] + resources :sale_item, :only => [:index, :show] # resources :sales, :only => [:index, :show] # resources :orders, :only => [:index, :show] # resources :customers, :only => [:index, :show] From dd3c429301389f684d9413e46e0ee7092a198683 Mon Sep 17 00:00:00 2001 From: Yan Date: Mon, 19 Jun 2017 11:56:26 +0630 Subject: [PATCH 009/128] control paypar url and oqs fix --- app/models/order_queue_station.rb | 4 ++- app/models/sale_payment.rb | 50 +++++++++++++++++-------------- 2 files changed, 31 insertions(+), 23 deletions(-) diff --git a/app/models/order_queue_station.rb b/app/models/order_queue_station.rb index 0350049c..2df76af8 100644 --- a/app/models/order_queue_station.rb +++ b/app/models/order_queue_station.rb @@ -29,7 +29,9 @@ class OrderQueueStation < ApplicationRecord if oqs.id == oqpbz.order_queue_station_id #Same Order_items can appear in two location. AssignedOrderItem.assigned_order_item(order, order_item.item_code, oqs) - end + else + AssignedOrderItem.assigned_order_item(order, order_item.item_code, oqs) + end end end end diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 3b67648c..856cd054 100644 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -66,19 +66,20 @@ class SalePayment < ApplicationRecord end - def self.get_paypar_account(url,token,membership_id,campaign_type_id,merchant_uid,auth_token) - begin - response = HTTParty.get(url, - :body => { app_token: token,membership_id:membership_id,campaign_type_id:campaign_type_id,merchant_uid:merchant_uid,auth_token:auth_token}.to_json, - :headers => { - 'Content-Type' => 'application/json', - 'Accept' => 'application/json' - }, :timeout => 10 - ) - rescue Net::OpenTimeout - response = { status: false } - end - return response; + def self.get_paypar_account(url,token,membership_id,campaign_type_id,merchant_uid,auth_token) + # Control for Paypar Cloud + begin + response = HTTParty.get(url, + :body => { app_token: token,membership_id:membership_id,campaign_type_id:campaign_type_id,merchant_uid:merchant_uid,auth_token:auth_token}.to_json, + :headers => { + 'Content-Type' => 'application/json', + 'Accept' => 'application/json' + }, :timeout => 10 + ) + rescue Net::OpenTimeout + response = { status: false } + end + return response; end def self.redeem(paypar_url,token,membership_id,received_amount,sale_id) @@ -90,13 +91,19 @@ class SalePayment < ApplicationRecord campaign_type_id = membership_actions_data.additional_parameter["campaign_type_id"] sale_data = Sale.find_by_sale_id(sale_id) if sale_data - response = HTTParty.post(url, - :body => { generic_customer_id:membership_id,redeem_amount:received_amount,receipt_no:sale_data.receipt_no,campaign_type_id:campaign_type_id,account_no:"",merchant_uid:merchant_uid,auth_token:auth_token}.to_json, - :headers => { - 'Content-Type' => 'application/json', - 'Accept' => 'application/json' - } - ) + # Control for Paypar Cloud + begin + response = HTTParty.post(url, + :body => { generic_customer_id:membership_id,redeem_amount:received_amount,receipt_no:sale_data.receipt_no,campaign_type_id:campaign_type_id,account_no:"",merchant_uid:merchant_uid,auth_token:auth_token}.to_json, + :headers => { + 'Content-Type' => 'application/json', + 'Accept' => 'application/json' + }, + :timeout => 10 + ) + rescue Net::OpenTimeout + response = false + end else response = false; end @@ -122,7 +129,6 @@ class SalePayment < ApplicationRecord end def creditnote_payment(customer_id) - payment_status = false self.payment_method = "creditnote" @@ -190,7 +196,6 @@ 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) membership_setting = MembershipSetting.find_by_membership_type("paypar_url") membership_data = SalePayment.redeem(membership_setting.gateway_url,membership_setting.auth_token,customer_data.membership_id,self.received_amount,self.sale.sale_id) @@ -269,6 +274,7 @@ class SalePayment < ApplicationRecord auth_token = memberaction.auth_token.to_s url = membership.gateway_url.to_s + memberaction.gateway_url.to_s + # Control for Paypar Cloud begin response = HTTParty.post(url, :body => { generic_customer_id:generic_customer_id ,merchant_uid:merchant_uid,total_amount: total_amount,campaign_type_id: campaign_type_id, receipt_no: receipt_no,auth_token:auth_token}.to_json, From b826b479cdd05aea3493f56005dac2398d77d212 Mon Sep 17 00:00:00 2001 From: Yan Date: Mon, 19 Jun 2017 12:07:43 +0630 Subject: [PATCH 010/128] update for oqs print --- app/models/printer/order_queue_printer.rb | 16 ++++++++-------- app/pdf/order_item_pdf.rb | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/models/printer/order_queue_printer.rb b/app/models/printer/order_queue_printer.rb index dae1ad53..f0b3d576 100644 --- a/app/models/printer/order_queue_printer.rb +++ b/app/models/printer/order_queue_printer.rb @@ -6,12 +6,12 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker #Print order_item= print_query('order_item', item_code) #OrderItem.find_by_item_code(item_code) pdf = OrderItemPdf.new(order_item[0]) - pdf.render_file "tmp/receipt.pdf" + pdf.render_file "tmp/order_item.pdf" if oqs.print_copy - self.print("tmp/receipt.pdf", oqs.printer_name) - self.print("tmp/receipt.pdf", oqs.printer_name) + self.print("tmp/order_item.pdf", oqs.printer_name) + self.print("tmp/order_item.pdf", oqs.printer_name) else - self.print("tmp/receipt.pdf", oqs.printer_name) + self.print("tmp/order_item.pdf", oqs.printer_name) end end @@ -24,12 +24,12 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker if oqs.cut_per_item order.each do|odi| pdf = OrderItemPdf.new(odi) - pdf.render_file "tmp/receipt.pdf" + pdf.render_file "tmp/order_item.pdf" if oqs.print_copy - self.print("tmp/receipt.pdf", oqs.printer_name) - self.print("tmp/receipt.pdf", oqs.printer_name) + self.print("tmp/order_item.pdf", oqs.printer_name) + self.print("tmp/order_item.pdf", oqs.printer_name) else - self.print("tmp/receipt.pdf", oqs.printer_name) + self.print("tmp/order_item.pdf", oqs.printer_name) end end # For Print Order Summary diff --git a/app/pdf/order_item_pdf.rb b/app/pdf/order_item_pdf.rb index 96008dfd..dd223e49 100644 --- a/app/pdf/order_item_pdf.rb +++ b/app/pdf/order_item_pdf.rb @@ -71,7 +71,7 @@ class OrderItemPdf < Prawn::Document add_order_items(order_item) dash(1, :space => 1, :phase => 1) - stroke_horizontal_line 0, self.page_width + stroke_horizontal_line 0, (self.page_width - self.margin) move_down 5 end From 33128d26a21e7c82ade0aa72a06dcb4b6f595fd0 Mon Sep 17 00:00:00 2001 From: Phyo Date: Mon, 19 Jun 2017 12:17:08 +0630 Subject: [PATCH 011/128] add Back Button in Redeem --- app/views/origami/redeem_payments/index.html.erb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/views/origami/redeem_payments/index.html.erb b/app/views/origami/redeem_payments/index.html.erb index 0991e562..3d7607c4 100644 --- a/app/views/origami/redeem_payments/index.html.erb +++ b/app/views/origami/redeem_payments/index.html.erb @@ -41,7 +41,7 @@

You can rebate upto <%= @food_prices %>

-->
-
+
@@ -84,9 +84,15 @@
Pay
+
+ +
+
+ +
From 2dbbb17634beec5ff77f5e155440199a260971af Mon Sep 17 00:00:00 2001 From: Phyo Date: Mon, 19 Jun 2017 12:21:54 +0630 Subject: [PATCH 012/128] Add extra fields to accounts --- .../settings/accounts_controller.rb | 2 +- app/views/layouts/_header.html.erb | 2 ++ app/views/settings/accounts/_form.html.erb | 7 +++++-- app/views/settings/accounts/index.html.erb | 19 ++++++++++++++----- app/views/settings/accounts/show.html.erb | 12 ++++++++++-- db/migrate/20170331024747_create_accounts.rb | 4 ++++ 6 files changed, 36 insertions(+), 10 deletions(-) diff --git a/app/controllers/settings/accounts_controller.rb b/app/controllers/settings/accounts_controller.rb index 74f27c84..90e6a304 100644 --- a/app/controllers/settings/accounts_controller.rb +++ b/app/controllers/settings/accounts_controller.rb @@ -68,6 +68,6 @@ class Settings::AccountsController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def account_params - params.require(:account).permit(:title, :account_type) + params.require(:account).permit(:title, :account_type,:discount,:point,:bonus,:rebate) end end diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb index a385806c..c729f255 100644 --- a/app/views/layouts/_header.html.erb +++ b/app/views/layouts/_header.html.erb @@ -23,6 +23,8 @@
  • <%= link_to "Payment Method", settings_payment_method_settings_path, :tabindex =>"-1" %>
  • <%= link_to "Tax Profile", settings_tax_profiles_path, :tabindex =>"-1" %>
  • <%= link_to "Print Setting", print_settings_path, :tabindex =>"-1" %>
  • +
    +
  • <%= link_to "Accounts", settings_accounts_path, :tabindex =>"-1" %>
  • diff --git a/app/views/settings/accounts/_form.html.erb b/app/views/settings/accounts/_form.html.erb index 4231ad32..b2101a43 100644 --- a/app/views/settings/accounts/_form.html.erb +++ b/app/views/settings/accounts/_form.html.erb @@ -4,11 +4,14 @@
    <%= f.input :title %> <%= f.input :account_type, :collection => Lookup.collection_of("account_type") %> + <%= f.input :discount %> + <%= f.input :point %> + <%= f.input :bonus %> + <%= f.input :rebate %>
    <%= f.button :submit %>
    - -<% end %> +<% end %> diff --git a/app/views/settings/accounts/index.html.erb b/app/views/settings/accounts/index.html.erb index d8469a69..23cfb7eb 100644 --- a/app/views/settings/accounts/index.html.erb +++ b/app/views/settings/accounts/index.html.erb @@ -14,9 +14,14 @@ - - - + + + + + + + + @@ -25,10 +30,14 @@ + + + + <% end %> diff --git a/app/views/settings/accounts/show.html.erb b/app/views/settings/accounts/show.html.erb index 6ec1c80a..284bb602 100644 --- a/app/views/settings/accounts/show.html.erb +++ b/app/views/settings/accounts/show.html.erb @@ -17,6 +17,10 @@ + + + + @@ -25,10 +29,14 @@ - + + + + +
    TitleAccount TypeActionTitleAccount TypeCan get DiscountCan get PointsCan get BonusCan rebateAction
    <%= account.title %> <%= account.account_type %><%= account.discount %><%= account.point %><%= account.bonus %><%= account.rebate %> - <%= link_to 'Edit', edit_settings_account_path(account) %> | + <%= link_to 'Edit', edit_settings_account_path(account) %> | <%= link_to 'Destroy', settings_account_path(account), method: :delete, data: { confirm: 'Are you sure?' } %> - +
    Title Account typeCan get DiscountCan get PointsCan get BonusCan rebate Action
    <%= @settings_account.title %> <%= @settings_account.account_type %><%= @settings_account.discount %><%= @settings_account.point %><%= @settings_account.bonus %><%= @settings_account.rebate %><%= link_to 'Edit', edit_settings_account_path(@settings_account, @settings_account) %>
    - \ No newline at end of file + diff --git a/db/migrate/20170331024747_create_accounts.rb b/db/migrate/20170331024747_create_accounts.rb index 5816aace..4c4a7b74 100644 --- a/db/migrate/20170331024747_create_accounts.rb +++ b/db/migrate/20170331024747_create_accounts.rb @@ -3,6 +3,10 @@ class CreateAccounts < ActiveRecord::Migration[5.1] create_table :accounts do |t| t.string :title t.string :account_type + t.boolean :discount, :null => false, :default => false + t.boolean :point, :null => false, :default => false + t.boolean :bonus, :null => false, :default => false + t.boolean :rebate, :null => false, :default => false t.timestamps end From fcd159086818c784e0cf4aeea27f962fb5b5fce4 Mon Sep 17 00:00:00 2001 From: Nweni Date: Mon, 19 Jun 2017 15:51:04 +0630 Subject: [PATCH 013/128] change query --- app/assets/stylesheets/origami.scss | 4 ++++ app/models/order.rb | 4 ++-- app/views/origami/payments/show.html.erb | 7 ++++--- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app/assets/stylesheets/origami.scss b/app/assets/stylesheets/origami.scss index 71a9915e..c96237fa 100644 --- a/app/assets/stylesheets/origami.scss +++ b/app/assets/stylesheets/origami.scss @@ -95,6 +95,10 @@ background-color:#7a62d3; } +.orange{ + background-color:#FF7F50; +} + .red { background-color:#ff0000; } diff --git a/app/models/order.rb b/app/models/order.rb index f3ae798c..9c65304b 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -231,7 +231,7 @@ class Order < ApplicationRecord .joins("left join orders on orders.order_id = booking_orders.order_id") .joins("left join sales on sales.sale_id = bookings.sale_id") .where("(orders.status = 'new' or orders.status = 'billed') and (dining_facilities.type=? and dining_facilities.is_active=?)",DiningFacility::TABLE_TYPE,true) - .group("bookings.booking_id") + .group("bookings.booking_id,sales.receipt_no,orders.status,sales.sale_id,dining_facilities.name,orders.status,orders.order_id") # For PG # booking_orders.order_id IS NOT NULL and dining_facilities.type=? and dining_facilities.is_active=?",DiningFacility::TABLE_TYPE,true # sales.receipt_no,orders.status,sales.sale_id,dining_facilities.name,orders.status,orders.order_id @@ -262,7 +262,7 @@ class Order < ApplicationRecord .joins("left join orders on orders.order_id = booking_orders.order_id") .joins("left join sales on sales.sale_id = bookings.sale_id") .where("(orders.status = 'new' or orders.status = 'billed') and (dining_facilities.type=? and dining_facilities.is_active=?)",DiningFacility::ROOM_TYPE,true) - .group("bookings.booking_id") + .group("bookings.booking_id,sales.receipt_no,orders.status,sales.sale_id,dining_facilities.name,orders.customer_id,orders.order_id") # For PG # booking_orders.order_id IS NOT NULL and dining_facilities.type=? and dining_facilities.is_active=?",DiningFacility::ROOM_TYPE,true # sales.receipt_no,orders.status,sales.sale_id,dining_facilities.name,orders.customer_id,orders.order_id diff --git a/app/views/origami/payments/show.html.erb b/app/views/origami/payments/show.html.erb index 995e13e9..91d5b6b2 100644 --- a/app/views/origami/payments/show.html.erb +++ b/app/views/origami/payments/show.html.erb @@ -235,9 +235,10 @@
    - - - + + + +
    From d8930cb2b5c7812595fb03fd0564984b2f6846b4 Mon Sep 17 00:00:00 2001 From: Yan Date: Mon, 19 Jun 2017 15:55:21 +0630 Subject: [PATCH 014/128] still --- app/models/order_queue_station.rb | 38 +++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/app/models/order_queue_station.rb b/app/models/order_queue_station.rb index 2df76af8..f086e3cd 100644 --- a/app/models/order_queue_station.rb +++ b/app/models/order_queue_station.rb @@ -31,24 +31,52 @@ class OrderQueueStation < ApplicationRecord AssignedOrderItem.assigned_order_item(order, order_item.item_code, oqs) else AssignedOrderItem.assigned_order_item(order, order_item.item_code, oqs) - end + end + puts oqs.station_name + puts oqs.auto_print + puts oqs.cut_per_item + puts oqs.print_copy + if oqs.auto_print + print_slip(oqs, order, order_items) + end end end end end #Print OQS where printing is require - end private #Print order_items in 1 slip - def print_slip + def print_slip(oqs, order, items) + unique_code="OrderSummaryPdf" + + # print when complete click + print_settings=PrintSetting.find_by_unique_code(unique_code) + order_queue_printer= Printer::OrderQueuePrinter.new(print_settings) + order_queue_printer.print_order_summary(oqs,order.order_id) + # update print status for completed same order items + items.each do |ai| + ai.print_status=true + ai.save + end end - #Print order_items in 1 slip per item - def print_slip_item + #Print order_item in 1 slip per item + def print_slip_item(oqs, item) + unique_code="OrderItemPdf" + # print when complete click + print_settings=PrintSetting.find_by_unique_code(unique_code) + order_queue_printer= Printer::OrderQueuePrinter.new(print_settings) + order_queue_printer.print_order_item(oqs,item.order_id, item.item_code ) + + # update print status for completed same order items + item.each do |ai| + ai.print_status=true + ai.save + end end end From 35fc649df34757ce15d8436b465bf056aa1dde16 Mon Sep 17 00:00:00 2001 From: Nweni Date: Mon, 19 Jun 2017 15:56:45 +0630 Subject: [PATCH 015/128] pg order --- app/models/order.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/order.rb b/app/models/order.rb index 14fd8cda..96382c07 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -246,7 +246,7 @@ class Order < ApplicationRecord .joins("left join orders on orders.order_id = booking_orders.order_id") .joins("left join sales on sales.sale_id = bookings.sale_id") .where("sales.sale_status='completed'") - .group("sales.sale_id") + .group("sales.sale_id,bookings.booking_id,sales.receipt_no,orders.status,sales.sale_id,dining_facilities.name,orders.status,orders.order_id") # For PG #bookings.booking_id,sales.receipt_no,orders.status,sales.sale_id,dining_facilities.name,orders.status,orders.order_id end From d78327f90678f0967564a0905af98d4eebd290c5 Mon Sep 17 00:00:00 2001 From: Phyo Date: Mon, 19 Jun 2017 16:22:39 +0630 Subject: [PATCH 016/128] Membership Setting UI --- .../membership_actions/_form.html.erb | 1 - .../membership_actions/index.html.erb | 80 ++++++++++--------- 2 files changed, 43 insertions(+), 38 deletions(-) diff --git a/app/views/settings/membership_actions/_form.html.erb b/app/views/settings/membership_actions/_form.html.erb index 3084d4ac..ac3e07b0 100644 --- a/app/views/settings/membership_actions/_form.html.erb +++ b/app/views/settings/membership_actions/_form.html.erb @@ -9,7 +9,6 @@ <%= f.input :auth_token %> <%= f.input :merchant_account_id %> <%= f.input :created_by %> - <%= f.input :additional_parameter %>
    diff --git a/app/views/settings/membership_actions/index.html.erb b/app/views/settings/membership_actions/index.html.erb index 635fd34c..4a348ed3 100644 --- a/app/views/settings/membership_actions/index.html.erb +++ b/app/views/settings/membership_actions/index.html.erb @@ -1,41 +1,47 @@ -

    <%= notice %>

    -

    Settings Membership Actions

    - - - - - - - - - - - - - - - - - - <% @settings_membership_actions.each do |settings_membership_action| %> - - - - - - - - - - - - - - <% end %> - -
    Membership typeIs activeGateway communication typeGateway urlAuth tokenMerchant accountCreated byAdditional parameter
    <%= settings_membership_action.membership_type %><%= settings_membership_action.is_active %><%= settings_membership_action.gateway_communication_type %><%= settings_membership_action.gateway_url %><%= settings_membership_action.auth_token %><%= settings_membership_action.merchant_account_id %><%= settings_membership_action.created_by %><%= settings_membership_action.additional_parameter %><%= link_to 'Show', settings_membership_action_path(settings_membership_action) %><%= link_to 'Edit', edit_settings_membership_action_path(settings_membership_action) %><%= link_to 'Destroy', settings_membership_action_path(settings_membership_action), method: :delete, data: { confirm: 'Are you sure?' } %>
    +
    +
    + + + + + + + + + + + + + + -<%= link_to 'New Settings Membership Action', new_settings_membership_action_path %> + + <% @settings_membership_actions.each do |settings_membership_action| %> + + + + + + + + + + + + + + <% end %> + +
    Membership typeIs activeGateway communication typeGateway urlAuth tokenMerchant accountCreated byAdditional parameter
    <%= settings_membership_action.membership_type %><%= settings_membership_action.is_active %><%= settings_membership_action.gateway_communication_type %><%= settings_membership_action.gateway_url %><%= settings_membership_action.auth_token %><%= settings_membership_action.merchant_account_id %><%= settings_membership_action.created_by %><%= settings_membership_action.additional_parameter %><%= link_to 'Show', settings_membership_action_path(settings_membership_action) %><%= link_to 'Edit', edit_settings_membership_action_path(settings_membership_action) %><%= link_to 'Destroy', settings_membership_action_path(settings_membership_action), method: :delete, data: { confirm: 'Are you sure?' } %>
    +
    From c02e305c309ea309fad25f1faf2ee0283b37e9d0 Mon Sep 17 00:00:00 2001 From: Phyo Date: Mon, 19 Jun 2017 16:24:44 +0630 Subject: [PATCH 017/128] Zone Created_at Bug Fix --- app/controllers/settings/rooms_controller.rb | 10 ++++++---- app/controllers/settings/tables_controller.rb | 9 +++++---- app/controllers/settings/zones_controller.rb | 5 ++++- app/views/settings/rooms/_form.html.erb | 1 - app/views/settings/tables/_form.html.erb | 1 - app/views/settings/zones/_form.html.erb | 2 +- 6 files changed, 16 insertions(+), 12 deletions(-) diff --git a/app/controllers/settings/rooms_controller.rb b/app/controllers/settings/rooms_controller.rb index 69e3ec22..2d5b01e1 100644 --- a/app/controllers/settings/rooms_controller.rb +++ b/app/controllers/settings/rooms_controller.rb @@ -1,6 +1,6 @@ class Settings::RoomsController < ApplicationController before_action :set_settings_room, only: [:show, :edit, :update, :destroy] - before_action :set_settings_zone, only: [:index, :show, :edit, :new, :update,:create] + before_action :set_settings_zone, only: [:index, :show, :edit, :new, :update,:create,:destroy] # GET /settings/rooms # GET /settings/rooms.json def index @@ -28,9 +28,10 @@ class Settings::RoomsController < ApplicationController @settings_room = Room.new(settings_room_params) @settings_room.type = DiningFacility::ROOM_TYPE @settings_room.zone_id = params[:zone_id] + @settings_room.created_by = current_login_employee.name respond_to do |format| if @settings_room.save - format.html { redirect_to settings_zone_rooms_path, notice: 'Room was successfully created.' } + format.html { redirect_to settings_zone_path(@zone), notice: 'Room was successfully created.' } format.json { render :show, status: :created, location: @settings_room } else puts "abc" @@ -43,9 +44,10 @@ class Settings::RoomsController < ApplicationController # PATCH/PUT /settings/rooms/1 # PATCH/PUT /settings/rooms/1.json def update + @settings_room.created_by = current_login_employee.name respond_to do |format| if @settings_room.update(settings_room_params) - format.html { redirect_to settings_zone_rooms_path, notice: 'Room was successfully updated.' } + format.html { redirect_to settings_zone_path(@zone), notice: 'Room was successfully updated.' } format.json { render :show, status: :ok, location: @settings_room } else format.html { render :edit } @@ -59,7 +61,7 @@ class Settings::RoomsController < ApplicationController def destroy @settings_room.destroy respond_to do |format| - format.html { redirect_to settings_zones_path, notice: 'Room was successfully destroyed.' } + format.html { redirect_to settings_zone_path(@zone), notice: 'Room was successfully destroyed.' } format.json { head :no_content } end end diff --git a/app/controllers/settings/tables_controller.rb b/app/controllers/settings/tables_controller.rb index 124a0d94..7c293455 100644 --- a/app/controllers/settings/tables_controller.rb +++ b/app/controllers/settings/tables_controller.rb @@ -28,12 +28,12 @@ class Settings::TablesController < ApplicationController @settings_table = Table.new(settings_table_params) @settings_table.type = DiningFacility::TABLE_TYPE @settings_table.zone_id = params[:zone_id] + @settings_table.created_by = current_login_employee.name respond_to do |format| if @settings_table.save - format.html { redirect_to settings_zone_tables_path, notice: 'Table was successfully created.' } + format.html { redirect_to settings_zone_path(@zone), notice: 'Table was successfully created.' } format.json { render :show, status: :created, location: @settings_table } else - puts "abc" format.html { render :new } format.json { render json: @settings_table.errors, status: :unprocessable_entity } end @@ -43,9 +43,10 @@ class Settings::TablesController < ApplicationController # PATCH/PUT /settings/tables/1 # PATCH/PUT /settings/tables/1.json def update + @settings_table.created_by = current_login_employee.name respond_to do |format| if @settings_table.update(settings_table_params) - format.html { redirect_to settings_zone_tables_path, notice: 'Table was successfully updated.' } + format.html { redirect_to settings_zone_path(@zone), notice: 'Table was successfully updated.' } format.json { render :show, status: :ok, location: @settings_table } else format.html { render :edit } @@ -59,7 +60,7 @@ class Settings::TablesController < ApplicationController def destroy @settings_table.destroy respond_to do |format| - format.html { redirect_to settings_zones_path, notice: 'Table was successfully destroyed.' } + format.html { redirect_to settings_zone_path(@zone), notice: 'Table was successfully destroyed.' } format.json { head :no_content } end end diff --git a/app/controllers/settings/zones_controller.rb b/app/controllers/settings/zones_controller.rb index 5752b5e3..08a6f189 100644 --- a/app/controllers/settings/zones_controller.rb +++ b/app/controllers/settings/zones_controller.rb @@ -27,7 +27,7 @@ class Settings::ZonesController < ApplicationController # POST /settings/zones.json def create @settings_zone = Zone.new(settings_zone_params) - + @settings_zone.created_by = current_login_employee.name respond_to do |format| if @settings_zone.save format.html { redirect_to settings_zone_path(@settings_zone), notice: 'Zone was successfully created.' } @@ -43,6 +43,7 @@ class Settings::ZonesController < ApplicationController # PATCH/PUT /settings/zones/1.json def update respond_to do |format| + @settings_zone.created_by = current_login_employee.name if @settings_zone.update(settings_zone_params) format.html { redirect_to settings_zone_path(@settings_zone), notice: 'Zone was successfully updated.' } format.json { render :show, status: :ok, location: @settings_zone } @@ -56,6 +57,8 @@ class Settings::ZonesController < ApplicationController # DELETE /settings/zones/1 # DELETE /settings/zones/1.json def destroy + @settings_zone.rooms.destroy + @settings_zone.tables.destroy @settings_zone.destroy respond_to do |format| format.html { redirect_to settings_zones_path, notice: 'Zone was successfully destroyed.' } diff --git a/app/views/settings/rooms/_form.html.erb b/app/views/settings/rooms/_form.html.erb index c164ab67..25af618c 100644 --- a/app/views/settings/rooms/_form.html.erb +++ b/app/views/settings/rooms/_form.html.erb @@ -7,7 +7,6 @@ <%= f.input :seater %> <%= f.input :order_by %> <%= f.input :is_active %> - <%= f.input :created_by, :collection => Employee.collection %>
    diff --git a/app/views/settings/tables/_form.html.erb b/app/views/settings/tables/_form.html.erb index a411175c..169e1601 100644 --- a/app/views/settings/tables/_form.html.erb +++ b/app/views/settings/tables/_form.html.erb @@ -7,7 +7,6 @@ <%= f.input :seater %> <%= f.input :order_by %> <%= f.input :is_active %> - <%= f.input :created_by, :collection => Employee.collection %>
    diff --git a/app/views/settings/zones/_form.html.erb b/app/views/settings/zones/_form.html.erb index a7740211..351f2c94 100644 --- a/app/views/settings/zones/_form.html.erb +++ b/app/views/settings/zones/_form.html.erb @@ -4,7 +4,7 @@
    <%= f.input :name %> <%= f.input :is_active %> - <%= f.input :created_by, :collection => Employee.collection %> +
    From 9089eab19617643954de06fc38151adfacc4cc95 Mon Sep 17 00:00:00 2001 From: Yan Date: Mon, 19 Jun 2017 17:36:39 +0630 Subject: [PATCH 018/128] temp remove options in oqs --- app/controllers/oqs/home_controller.rb | 4 +-- app/models/order_queue_station.rb | 32 ++++++++++------------- app/models/printer/order_queue_printer.rb | 17 ++++++++---- app/pdf/order_summary_pdf.rb | 5 ++-- app/views/oqs/home/index.html.erb | 10 +++++-- 5 files changed, 39 insertions(+), 29 deletions(-) diff --git a/app/controllers/oqs/home_controller.rb b/app/controllers/oqs/home_controller.rb index 58aac67c..14d79857 100644 --- a/app/controllers/oqs/home_controller.rb +++ b/app/controllers/oqs/home_controller.rb @@ -2,9 +2,9 @@ class Oqs::HomeController < BaseOqsController def index queue_stations=OrderQueueStation.all - @queue_items_details = queue_items_query(0) + @queue_items_details = queue_items_query(false) - @queue_completed_item = queue_items_query(1) + @queue_completed_item = queue_items_query(true) @queue_stations_items=Array.new diff --git a/app/models/order_queue_station.rb b/app/models/order_queue_station.rb index f086e3cd..a5267442 100644 --- a/app/models/order_queue_station.rb +++ b/app/models/order_queue_station.rb @@ -16,6 +16,7 @@ class OrderQueueStation < ApplicationRecord oqpbz = OrderQueueProcessByZone.find_by_zone_id(dining.zone_id) order_items = order.order_items + #Assign OQS id to order Items oqs_stations.each do |oqs| #Get List of items - @@ -26,16 +27,13 @@ class OrderQueueStation < ApplicationRecord #Processing through the looping items order_items.each do |order_item| if (pq_item == order_item.item_code) - if oqs.id == oqpbz.order_queue_station_id - #Same Order_items can appear in two location. + # if oqs.id == oqpbz.order_queue_station_id + # #Same Order_items can appear in two location. + # AssignedOrderItem.assigned_order_item(order, order_item.item_code, oqs) + # else AssignedOrderItem.assigned_order_item(order, order_item.item_code, oqs) - else - AssignedOrderItem.assigned_order_item(order, order_item.item_code, oqs) - end - puts oqs.station_name - puts oqs.auto_print - puts oqs.cut_per_item - puts oqs.print_copy + # end + if oqs.auto_print print_slip(oqs, order, order_items) end @@ -43,29 +41,27 @@ class OrderQueueStation < ApplicationRecord end end end - - #Print OQS where printing is require end private #Print order_items in 1 slip - def print_slip(oqs, order, items) + def print_slip(oqs, order, order_items) unique_code="OrderSummaryPdf" - # print when complete click print_settings=PrintSetting.find_by_unique_code(unique_code) order_queue_printer= Printer::OrderQueuePrinter.new(print_settings) order_queue_printer.print_order_summary(oqs,order.order_id) - # update print status for completed same order items - items.each do |ai| + AssignedOrderItem.where("order_id = '#{ order.order_id }'").find_each do |ai| + # update print status for order items ai.print_status=true ai.save - end + end + end #Print order_item in 1 slip per item - def print_slip_item(oqs, item) + def print_slip_item(oqs, assigned_order_item) unique_code="OrderItemPdf" # print when complete click @@ -74,7 +70,7 @@ class OrderQueueStation < ApplicationRecord order_queue_printer.print_order_item(oqs,item.order_id, item.item_code ) # update print status for completed same order items - item.each do |ai| + assigned_order_item.each do |ai| ai.print_status=true ai.save end diff --git a/app/models/printer/order_queue_printer.rb b/app/models/printer/order_queue_printer.rb index f0b3d576..52fc3244 100644 --- a/app/models/printer/order_queue_printer.rb +++ b/app/models/printer/order_queue_printer.rb @@ -23,13 +23,15 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker # For Print Per Item if oqs.cut_per_item order.each do|odi| + filename = "tmp/order_item_#{odi.item_name}" + ".pdf" pdf = OrderItemPdf.new(odi) - pdf.render_file "tmp/order_item.pdf" + # pdf.render_file "tmp/order_item.pdf" + pdf.render_file filename if oqs.print_copy - self.print("tmp/order_item.pdf", oqs.printer_name) - self.print("tmp/order_item.pdf", oqs.printer_name) + self.print(filename, oqs.printer_name) + self.print(filename.gsub(".","-copy."), oqs.printer_name) else - self.print("tmp/order_item.pdf", oqs.printer_name) + self.print(filename, oqs.printer_name) end end # For Print Order Summary @@ -37,7 +39,12 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker filename = "tmp/order_summary_#{order_id}" + ".pdf" pdf = OrderSummaryPdf.new(order) pdf.render_file filename - self.print(filename, oqs.printer_name) + if oqs.print_copy + self.print(filename, oqs.printer_name) + self.print(filename.gsub(".","-copy."), oqs.printer_name) + else + self.print(filename, oqs.printer_name) + end end end diff --git a/app/pdf/order_summary_pdf.rb b/app/pdf/order_summary_pdf.rb index 47c1f6a5..22f27497 100644 --- a/app/pdf/order_summary_pdf.rb +++ b/app/pdf/order_summary_pdf.rb @@ -77,6 +77,7 @@ class OrderSummaryPdf < Prawn::Document move_down 5 order_item.each do|odi| + y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do text "#{odi.item_name}", :size => self.item_font_size,:align => :left end @@ -84,9 +85,9 @@ class OrderSummaryPdf < Prawn::Document bounding_box([self.item_width,y_position], :width => self.qty_width, :height => self.item_height) do text "#{odi.qty}", :size => self.item_font_size,:align => :left end - end - move_down 5 + move_down 5 + end end end diff --git a/app/views/oqs/home/index.html.erb b/app/views/oqs/home/index.html.erb index 18e72880..084ae8cf 100644 --- a/app/views/oqs/home/index.html.erb +++ b/app/views/oqs/home/index.html.erb @@ -49,7 +49,10 @@ <%= qid.qty %> ] -

    Medium, Fries, Salad

    +

    Order at @@ -97,7 +100,10 @@ <%= qid.qty %> ] -

    Medium, Fries, Salad

    +

    Order at From 90be2b8d63ab578e870760bec0e888dbd0695625 Mon Sep 17 00:00:00 2001 From: Phyo Date: Mon, 19 Jun 2017 18:54:19 +0630 Subject: [PATCH 019/128] OQS edit bug fix --- app/assets/javascripts/settings/processing_items.js | 2 +- app/controllers/settings/order_queue_stations_controller.rb | 2 +- app/views/settings/order_queue_stations/_form.html.erb | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/settings/processing_items.js b/app/assets/javascripts/settings/processing_items.js index 445b46d5..60c53ba4 100644 --- a/app/assets/javascripts/settings/processing_items.js +++ b/app/assets/javascripts/settings/processing_items.js @@ -40,7 +40,7 @@ $(document).on('turbolinks:load', function() { items.push($(value).attr("data-id")); }); - $("#order_queue_station_processing_items").val(items); + $("#order_queue_station_processing_items").val(JSON.stringify(items)); //$(this).submit(); }) }) diff --git a/app/controllers/settings/order_queue_stations_controller.rb b/app/controllers/settings/order_queue_stations_controller.rb index b63e1ca8..bc7766a7 100644 --- a/app/controllers/settings/order_queue_stations_controller.rb +++ b/app/controllers/settings/order_queue_stations_controller.rb @@ -41,7 +41,7 @@ class Settings::OrderQueueStationsController < ApplicationController # PATCH/PUT /settings/order_queue_stations/1 # PATCH/PUT /settings/order_queue_stations/1.json def update - params[:order_queue_station][:processing_items] = params[:order_queue_station][:processing_items].split(/,/).inspect + # params[:order_queue_station][:processing_items] = params[:order_queue_station][:processing_items].split(/,/).inspect respond_to do |format| if @settings_order_queue_station.update(settings_order_queue_station_params) format.html { redirect_to settings_order_queue_station_path(@settings_order_queue_station), notice: 'Order queue station was successfully updated.' } diff --git a/app/views/settings/order_queue_stations/_form.html.erb b/app/views/settings/order_queue_stations/_form.html.erb index 7a2cba43..67b34798 100644 --- a/app/views/settings/order_queue_stations/_form.html.erb +++ b/app/views/settings/order_queue_stations/_form.html.erb @@ -13,6 +13,7 @@ div.form-inputs span{ <%= f.input :printer_name %> <%= f.input :font_size %> <%= f.input :print_copy %> + <%= f.hidden_field :processing_items %> <%= f.label "Select Zones", :class => 'control-label' %> <%= f.collection_check_boxes :zone_ids , Zone.all, :id, :name , :class => 'ta'%> <%= f.input :cut_per_item %> From c95b0130dc9e94a8e8ac416b0fc58d8717474ede Mon Sep 17 00:00:00 2001 From: Yan Date: Mon, 19 Jun 2017 18:56:36 +0630 Subject: [PATCH 020/128] edit migrate oqs --- db/migrate/20170403151731_create_order_queue_stations.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/migrate/20170403151731_create_order_queue_stations.rb b/db/migrate/20170403151731_create_order_queue_stations.rb index 6c327b8e..801cdef0 100644 --- a/db/migrate/20170403151731_create_order_queue_stations.rb +++ b/db/migrate/20170403151731_create_order_queue_stations.rb @@ -3,7 +3,7 @@ class CreateOrderQueueStations < ActiveRecord::Migration[5.1] create_table :order_queue_stations do |t| t.string :station_name, :null => false t.boolean :is_active, :null => false, :default => false - t.json :processing_items + t.json :processing_items, :default => "[]" t.boolean :print_copy, :null => false, :default => false t.string :printer_name t.integer :font_size, :null => false, :default => 10 From a71ee3657ab5a1af8f4bffa33dc0f60466341da6 Mon Sep 17 00:00:00 2001 From: Nweni Date: Tue, 20 Jun 2017 07:36:38 +0630 Subject: [PATCH 021/128] origami changes --- app/assets/javascripts/origami.js | 345 +------------ app/assets/javascripts/origami_bk.js | 352 +++++++++++++ app/assets/stylesheets/origami.scss | 7 + app/controllers/oqs/home_controller.rb | 28 +- app/controllers/origami/home_controller.rb | 100 +--- app/controllers/origami/home_controller_bk.rb | 84 ++++ app/models/booking.rb | 2 + app/models/dining_facility.rb | 11 +- app/models/order.rb | 4 +- app/models/room.rb | 1 + app/models/table.rb | 2 +- app/models/table_booking.rb | 2 +- app/views/layouts/origami.html.erb | 4 +- app/views/origami/home/index.html.erb | 464 ++++-------------- app/views/origami/home/index_bk.html.erb | 388 +++++++++++++++ app/views/origami/home/show.html.erb | 217 ++++++++ config/initializers/assets.rb | 2 +- config/routes.rb | 3 +- 18 files changed, 1199 insertions(+), 817 deletions(-) create mode 100644 app/assets/javascripts/origami_bk.js create mode 100644 app/controllers/origami/home_controller_bk.rb create mode 100644 app/views/origami/home/index_bk.html.erb create mode 100644 app/views/origami/home/show.html.erb diff --git a/app/assets/javascripts/origami.js b/app/assets/javascripts/origami.js index d4071432..47a4dace 100644 --- a/app/assets/javascripts/origami.js +++ b/app/assets/javascripts/origami.js @@ -1,15 +1,3 @@ -// This is a manifest file that'll be compiled into application.js, which will include all the files -// listed below. -// -// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, -// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path. -// -// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the -// compiled file. JavaScript code in this file should be added after the last require_* statement. -// -// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details -// about supported directives. -// //= require jquery //= require tether //= require bootstrap @@ -20,333 +8,8 @@ //= require bootstrap-datepicker $(document).ready(function(){ - // auto refresh every 60 seconds - // setTimeout(function(){ - // window.location.reload(1); - // }, 60000); - - // For selected order return - var order_status = ""; - order_status = $(".selected-item").children().find(".orders-order-status").text().substr(0,6).trim(); - - // Enable/Disable Button - control_button(order_status); - - $(".orders").on('click', function(){ - $("#order-sub-total").text(''); - // $("#order-food").text(''); - // $("#order-beverage").text(''); - $("#order-discount").text(''); - $("#order-Tax").text(''); - $("#order-grand-total").text(''); - - var zone_name=$(this).find(".orders-table").text(); - var receipt_no=$(this).find(".orders-receipt-no").text(); - var unique_id = $(this).find(".orders-id").text(); - var order_status=$(this).find(".orders-order-status").text().trim(); - - // Enable/Disable Button - control_button(order_status); - - var customer_id=$(this).find(".customer-id").text(); - show_customer_details(customer_id); - - $("#re-print").val(unique_id); - - var cashier=""; - var receipt_date=""; - var sub_total=0.0; - var discount_amount=0; - var tax_amount=0; - var grand_total_amount=0; - - $("#order-title").text("ORDER DETAILS - " + zone_name); - // clear order items - $("#order-items-table").children("tbody").empty(); - - // AJAX call for order - $.ajax({ - type: "POST", - url: "/origami/" + unique_id, - data: { 'booking_id' : unique_id }, - success:function(result){ - for (i = 0; i < result.length; i++) { - var data = JSON.stringify(result[i]); - var parse_data = JSON.parse(data); - var show_date = ""; - - // Receipt Header - receipt_no = result[i].receipt_no; - cashier = result[i].cashier_name; - if(result[i].receipt_date != null){ - receipt_date = new Date(result[i].receipt_date); - show_date = receipt_date.getDate() + "-" + receipt_date.getMonth() + "-" + receipt_date.getFullYear() + ' ' + receipt_date.getHours()+ ':' + receipt_date.getMinutes() - } - - //Receipt Charges - sub_total += parseFloat(parse_data.price); - - discount_amount = parse_data.discount_amount == null? '0.0' : parse_data.discount_amount; - tax_amount = parse_data.tax_amount; - grand_total_amount = parse_data.grand_total_amount; - - // Ordered Items - var order_items_rows = "" + - "" + parse_data.item_name + "" + - "" + parse_data.qty + "" + - "" + parse_data.price + "" + - ""; - - $("#order-items-table").children("tbody").append(order_items_rows); - } - - // Cashier Info - $("#receipt_no").text(receipt_no); - $("#cashier").text(cashier == null ? "" : cashier); - $("#receipt_date").text(show_date); - - // Payment Info - $("#order-sub-total").text(sub_total); - // $("#order-food").text(''); - // $("#order-beverage").text(''); - $("#order-discount").text(discount_amount); - $("#order-Tax").text(tax_amount); - $("#order-grand-total").text(grand_total_amount); - } - }); - // End AJAX Call - - $('.orders').removeClass('selected-item'); - $(this).addClass('selected-item'); - }); - - // Bill Request - $('#request_bills').click(function() { - var order_id=$(".selected-item").find(".orders-id").text().substr(0,16); - if(order_id!=""){ - window.location.href = '/origami/' + order_id + '/request_bills' - } - else { - alert("Please select an order!"); - } - return false; - }); - - // Discount for Payment - $('#discount').click(function() { - var order_id=$(".selected-item").find(".orders-id").text().substr(0,16); - - if(order_id!=""){ - window.location.href = '/origami/' + order_id + '/discount' - } - else { - alert("Please select an order!"); - } - - return false; - }); - - // Pay Discount for Payment - $("#pay-discount").on('click', function(e){ - e.preventDefault(); - var sale_id = $('#sale-id').text(); - var sale_item_id = $('.selected-item').attr('id').substr(0,16); - var sub_total = $('#order-sub-total').text(); - var grand_total = $('#order-grand-total').text(); - var discount_type = $('#discount-type').val(); - var discount_value = $('#discount-amount').val(); - var discount_amount = discount_value; - var ajax_url = "/origami/" + sale_id + "/discount"; - - if(sale_item_id != null){ - ajax_url = "/origami/" + sale_item_id + "/discount"; - sub_total = $("#"+sale_item_id).children().find("#item-total-price").text(); - } - - // For Percentage Discount - if(discount_type == 1){ - discount_amount=(sub_total*discount_value)/100; - } - - var params = {'sale_id': sale_id, 'sale_item_id': sale_item_id, 'grand_total' : grand_total, 'discount_type':discount_type, 'discount_value':discount_value, 'discount_amount':discount_amount}; - $.ajax({ - type: "POST", - url: ajax_url, - data: params, - success:function(result){ } - }); - }); - - - // Payment for Bill - $('#pay-bill').click(function() { - var sale_id=$(".selected-item").find(".orders-id").text().substr(0,16); - if(sale_id!=""){ - window.location.href = '/origami/sale/'+ sale_id + "/payment" - } - else { - alert("Please select an order!"); - } - - return false; - }); - - $('#customer').click(function() { - var sale = $(".selected-item").find(".orders-id").text().substr(0,16); - if (sale.substring(0, 3)=="SAL") { - var sale_id = sale - }else{ - var sale_id = $(".selected-item").find(".order-cid").text(); - } - window.location.href = '/origami/'+ sale_id + "/customers" - - return false; - }); - - $('#re-print').click(function() { - var sale_id = $(".selected-item").find(".orders-id").text().substr(0,16); - - window.location.href = '/origami/'+ sale_id + "/reprint" - - return false; - }); - - function show_customer_details(customer_id){ - - if(window.location.pathname.substring(0, 12) == "/origami/SAL"){ - var url = customer_id+"/get_customer/" - }else{ - var url = "origami/"+customer_id+"/get_customer/" - } - - $('.customer_detail').removeClass('hide'); - - //Start Ajax - $.ajax({ - type: "GET", - url: url, - data: {}, - dataType: "json", - success: function(data) { - $("#customer_name").text(data["customer"].name); - if (data["response_data"]["data"].length) { - $.each(data["response_data"]["data"], function (i) { - if(data["response_data"]["data"][i]["accountable_type"] == "RebateAccount"){ - var balance = data["response_data"]["data"][i]["balance"]; - if (data["response_data"]["status"]==true) { - $('.rebate_amount').removeClass('hide'); - row = - '' + data["response_data"]["data"][i]["accountable_type"] +'' - +'' + balance + ''; - - $(".rebate_amount").html(row); - } - - } - }); - }else{ - $('.rebate_amount').addClass('hide'); - } - } - }); - //End Ajax - } - - /* For Receipt - Calculate discount or tax */ - $('.cashier_number').on('click', function(event){ - if(event.handled !== true) { - var original_value=0; - original_value = $('#discount-amount').val(); - - var input_type = $(this).attr("data-type"); - - switch (input_type) { - case 'num': - var input_value = $(this).attr("data-value"); - if (original_value == "0.0"){ - $('#discount-amount').val(input_value); - update_balance(); - } - else{ - $('#discount-amount').val(original_value + '' + input_value); - update_balance(); - } - break; - - case 'add': - var input_value = $(this).attr("data-value"); - amount = parseInt(input_value); - $('#discount-amount').val(amount); - $('#discount-type').val(1); - update_balance(); - break; - - case 'del' : - var discount_text=$('#discount-amount').val(); - $('#discount-amount').val(discount_text.substr(0,discount_text.length-1)); - update_balance(); - break; - - case 'clr': - $('#discount-amount').val("0.0"); - update_balance(); - break; - } - - event.handled = true; - } else { - return false; - } - }); - - $('.discount-item-row').on('click',function(){ - $('.discount-item-row').removeClass('selected-item'); - $(this).addClass('selected-item'); - }); - + $(".orders").on('click', function(){ + var dining_id = $(this).attr("data-id"); + window.location.href = '/origami/' + dining_id; + }) }); - -/* Button Control by Status */ -function control_button(order_status){ - if(order_status=="billed"){ - $("#customer").prop('disabled', false); - $("#request_bills").prop('disabled', true); - $("#discount").prop('disabled', false); - $("#pay-bill").prop('disabled', false); - $("#re-print").prop('disabled', true); - } - else if(order_status=="new") { - $("#customer").prop('disabled', false); - $("#request_bills").prop('disabled', false); - $("#discount").prop('disabled', true); - $("#pay-bill").prop('disabled', true); - $("#re-print").prop('disabled', true); - }else if(order_status=="completed"){ - $("#re-print").prop('disabled', false); - } - else { - $("#customer").prop('disabled', true); - $("#request_bills").prop('disabled', true); - $("#discount").prop('disabled', true); - $("#pay-bill").prop('disabled', true); - $("#re-print").prop('disabled', true); - } - -} - -/* For Receipt - Update Balance */ -function update_balance(){ - var discount_type = $('#discount-type').val(); - var discount_amount = $('#discount-amount').val(); - var sub_total = $('#order-sub-total').text(); - var tax = $('#order-Tax').text(); - - // For Percentage Discount - if(discount_type == 1){ - discount_amount=(sub_total*discount_amount)/100; - } - - var total = (parseFloat(sub_total) + parseFloat(tax)) - discount_amount; - $('#order-discount').text(discount_amount); - $('#order-grand-total').text(total); -} diff --git a/app/assets/javascripts/origami_bk.js b/app/assets/javascripts/origami_bk.js new file mode 100644 index 00000000..d4071432 --- /dev/null +++ b/app/assets/javascripts/origami_bk.js @@ -0,0 +1,352 @@ +// This is a manifest file that'll be compiled into application.js, which will include all the files +// listed below. +// +// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, +// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path. +// +// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the +// compiled file. JavaScript code in this file should be added after the last require_* statement. +// +// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details +// about supported directives. +// +//= require jquery +//= require tether +//= require bootstrap +//= require jquery_ujs +//= require turbolinks +//= require cable +//= require jquery-ui +//= require bootstrap-datepicker + +$(document).ready(function(){ + // auto refresh every 60 seconds + // setTimeout(function(){ + // window.location.reload(1); + // }, 60000); + + // For selected order return + var order_status = ""; + order_status = $(".selected-item").children().find(".orders-order-status").text().substr(0,6).trim(); + + // Enable/Disable Button + control_button(order_status); + + $(".orders").on('click', function(){ + $("#order-sub-total").text(''); + // $("#order-food").text(''); + // $("#order-beverage").text(''); + $("#order-discount").text(''); + $("#order-Tax").text(''); + $("#order-grand-total").text(''); + + var zone_name=$(this).find(".orders-table").text(); + var receipt_no=$(this).find(".orders-receipt-no").text(); + var unique_id = $(this).find(".orders-id").text(); + var order_status=$(this).find(".orders-order-status").text().trim(); + + // Enable/Disable Button + control_button(order_status); + + var customer_id=$(this).find(".customer-id").text(); + show_customer_details(customer_id); + + $("#re-print").val(unique_id); + + var cashier=""; + var receipt_date=""; + var sub_total=0.0; + var discount_amount=0; + var tax_amount=0; + var grand_total_amount=0; + + $("#order-title").text("ORDER DETAILS - " + zone_name); + // clear order items + $("#order-items-table").children("tbody").empty(); + + // AJAX call for order + $.ajax({ + type: "POST", + url: "/origami/" + unique_id, + data: { 'booking_id' : unique_id }, + success:function(result){ + for (i = 0; i < result.length; i++) { + var data = JSON.stringify(result[i]); + var parse_data = JSON.parse(data); + var show_date = ""; + + // Receipt Header + receipt_no = result[i].receipt_no; + cashier = result[i].cashier_name; + if(result[i].receipt_date != null){ + receipt_date = new Date(result[i].receipt_date); + show_date = receipt_date.getDate() + "-" + receipt_date.getMonth() + "-" + receipt_date.getFullYear() + ' ' + receipt_date.getHours()+ ':' + receipt_date.getMinutes() + } + + //Receipt Charges + sub_total += parseFloat(parse_data.price); + + discount_amount = parse_data.discount_amount == null? '0.0' : parse_data.discount_amount; + tax_amount = parse_data.tax_amount; + grand_total_amount = parse_data.grand_total_amount; + + // Ordered Items + var order_items_rows = "" + + "" + parse_data.item_name + "" + + "" + parse_data.qty + "" + + "" + parse_data.price + "" + + ""; + + $("#order-items-table").children("tbody").append(order_items_rows); + } + + // Cashier Info + $("#receipt_no").text(receipt_no); + $("#cashier").text(cashier == null ? "" : cashier); + $("#receipt_date").text(show_date); + + // Payment Info + $("#order-sub-total").text(sub_total); + // $("#order-food").text(''); + // $("#order-beverage").text(''); + $("#order-discount").text(discount_amount); + $("#order-Tax").text(tax_amount); + $("#order-grand-total").text(grand_total_amount); + } + }); + // End AJAX Call + + $('.orders').removeClass('selected-item'); + $(this).addClass('selected-item'); + }); + + // Bill Request + $('#request_bills').click(function() { + var order_id=$(".selected-item").find(".orders-id").text().substr(0,16); + if(order_id!=""){ + window.location.href = '/origami/' + order_id + '/request_bills' + } + else { + alert("Please select an order!"); + } + return false; + }); + + // Discount for Payment + $('#discount').click(function() { + var order_id=$(".selected-item").find(".orders-id").text().substr(0,16); + + if(order_id!=""){ + window.location.href = '/origami/' + order_id + '/discount' + } + else { + alert("Please select an order!"); + } + + return false; + }); + + // Pay Discount for Payment + $("#pay-discount").on('click', function(e){ + e.preventDefault(); + var sale_id = $('#sale-id').text(); + var sale_item_id = $('.selected-item').attr('id').substr(0,16); + var sub_total = $('#order-sub-total').text(); + var grand_total = $('#order-grand-total').text(); + var discount_type = $('#discount-type').val(); + var discount_value = $('#discount-amount').val(); + var discount_amount = discount_value; + var ajax_url = "/origami/" + sale_id + "/discount"; + + if(sale_item_id != null){ + ajax_url = "/origami/" + sale_item_id + "/discount"; + sub_total = $("#"+sale_item_id).children().find("#item-total-price").text(); + } + + // For Percentage Discount + if(discount_type == 1){ + discount_amount=(sub_total*discount_value)/100; + } + + var params = {'sale_id': sale_id, 'sale_item_id': sale_item_id, 'grand_total' : grand_total, 'discount_type':discount_type, 'discount_value':discount_value, 'discount_amount':discount_amount}; + $.ajax({ + type: "POST", + url: ajax_url, + data: params, + success:function(result){ } + }); + }); + + + // Payment for Bill + $('#pay-bill').click(function() { + var sale_id=$(".selected-item").find(".orders-id").text().substr(0,16); + if(sale_id!=""){ + window.location.href = '/origami/sale/'+ sale_id + "/payment" + } + else { + alert("Please select an order!"); + } + + return false; + }); + + $('#customer').click(function() { + var sale = $(".selected-item").find(".orders-id").text().substr(0,16); + if (sale.substring(0, 3)=="SAL") { + var sale_id = sale + }else{ + var sale_id = $(".selected-item").find(".order-cid").text(); + } + window.location.href = '/origami/'+ sale_id + "/customers" + + return false; + }); + + $('#re-print').click(function() { + var sale_id = $(".selected-item").find(".orders-id").text().substr(0,16); + + window.location.href = '/origami/'+ sale_id + "/reprint" + + return false; + }); + + function show_customer_details(customer_id){ + + if(window.location.pathname.substring(0, 12) == "/origami/SAL"){ + var url = customer_id+"/get_customer/" + }else{ + var url = "origami/"+customer_id+"/get_customer/" + } + + $('.customer_detail').removeClass('hide'); + + //Start Ajax + $.ajax({ + type: "GET", + url: url, + data: {}, + dataType: "json", + success: function(data) { + $("#customer_name").text(data["customer"].name); + if (data["response_data"]["data"].length) { + $.each(data["response_data"]["data"], function (i) { + if(data["response_data"]["data"][i]["accountable_type"] == "RebateAccount"){ + var balance = data["response_data"]["data"][i]["balance"]; + if (data["response_data"]["status"]==true) { + $('.rebate_amount').removeClass('hide'); + row = + '' + data["response_data"]["data"][i]["accountable_type"] +'' + +'' + balance + ''; + + $(".rebate_amount").html(row); + } + + } + }); + }else{ + $('.rebate_amount').addClass('hide'); + } + } + }); + //End Ajax + } + + /* For Receipt - Calculate discount or tax */ + $('.cashier_number').on('click', function(event){ + if(event.handled !== true) { + var original_value=0; + original_value = $('#discount-amount').val(); + + var input_type = $(this).attr("data-type"); + + switch (input_type) { + case 'num': + var input_value = $(this).attr("data-value"); + if (original_value == "0.0"){ + $('#discount-amount').val(input_value); + update_balance(); + } + else{ + $('#discount-amount').val(original_value + '' + input_value); + update_balance(); + } + break; + + case 'add': + var input_value = $(this).attr("data-value"); + amount = parseInt(input_value); + $('#discount-amount').val(amount); + $('#discount-type').val(1); + update_balance(); + break; + + case 'del' : + var discount_text=$('#discount-amount').val(); + $('#discount-amount').val(discount_text.substr(0,discount_text.length-1)); + update_balance(); + break; + + case 'clr': + $('#discount-amount').val("0.0"); + update_balance(); + break; + } + + event.handled = true; + } else { + return false; + } + }); + + $('.discount-item-row').on('click',function(){ + $('.discount-item-row').removeClass('selected-item'); + $(this).addClass('selected-item'); + }); + +}); + +/* Button Control by Status */ +function control_button(order_status){ + if(order_status=="billed"){ + $("#customer").prop('disabled', false); + $("#request_bills").prop('disabled', true); + $("#discount").prop('disabled', false); + $("#pay-bill").prop('disabled', false); + $("#re-print").prop('disabled', true); + } + else if(order_status=="new") { + $("#customer").prop('disabled', false); + $("#request_bills").prop('disabled', false); + $("#discount").prop('disabled', true); + $("#pay-bill").prop('disabled', true); + $("#re-print").prop('disabled', true); + }else if(order_status=="completed"){ + $("#re-print").prop('disabled', false); + } + else { + $("#customer").prop('disabled', true); + $("#request_bills").prop('disabled', true); + $("#discount").prop('disabled', true); + $("#pay-bill").prop('disabled', true); + $("#re-print").prop('disabled', true); + } + +} + +/* For Receipt - Update Balance */ +function update_balance(){ + var discount_type = $('#discount-type').val(); + var discount_amount = $('#discount-amount').val(); + var sub_total = $('#order-sub-total').text(); + var tax = $('#order-Tax').text(); + + // For Percentage Discount + if(discount_type == 1){ + discount_amount=(sub_total*discount_amount)/100; + } + + var total = (parseFloat(sub_total) + parseFloat(tax)) - discount_amount; + $('#order-discount').text(discount_amount); + $('#order-grand-total').text(total); +} diff --git a/app/assets/stylesheets/origami.scss b/app/assets/stylesheets/origami.scss index 71a9915e..f4ef30ac 100644 --- a/app/assets/stylesheets/origami.scss +++ b/app/assets/stylesheets/origami.scss @@ -89,6 +89,13 @@ text-align: right; } +.display-none{ + display: none; +} + +.text-white{ + color: #fff; +} /* Colors */ .purple { diff --git a/app/controllers/oqs/home_controller.rb b/app/controllers/oqs/home_controller.rb index 58aac67c..b4d564f2 100644 --- a/app/controllers/oqs/home_controller.rb +++ b/app/controllers/oqs/home_controller.rb @@ -2,9 +2,9 @@ class Oqs::HomeController < BaseOqsController def index queue_stations=OrderQueueStation.all - @queue_items_details = queue_items_query(0) + @queue_items_details = queue_items_query(false) - @queue_completed_item = queue_items_query(1) + @queue_completed_item = queue_items_query(true) @queue_stations_items=Array.new @@ -30,14 +30,14 @@ class Oqs::HomeController < BaseOqsController dining = DiningFacility.find_by_name(table_name); # oqpz = OrderQueueProcessByZone.find_by_zone_id(dining.zone_id) # if status == "" - # AssignedOrderItem.where("order_queue_station_id=#{ oqpz.order_queue_station_id } AND delivery_status=0").find_each do |aoi| - # oi = OrderItem.find_by_item_code(aoi.item_code) - # items.push(oi) + # AssignedOrderItem.where("order_queue_station_id=#{ oqpz.order_queue_station_id } AND delivery_status=0").find_each do |aoi| + # oi = OrderItem.find_by_item_code(aoi.item_code) + # items.push(oi) # end # else - # AssignedOrderItem.where("order_queue_station_id=#{ oqpz.order_queue_station_id } AND delivery_status=1").find_each do |aoi| - # oi = OrderItem.find_by_item_code(aoi.item_code) - # items.push(oi) + # AssignedOrderItem.where("order_queue_station_id=#{ oqpz.order_queue_station_id } AND delivery_status=1").find_each do |aoi| + # oi = OrderItem.find_by_item_code(aoi.item_code) + # items.push(oi) # end # end @@ -49,7 +49,7 @@ class Oqs::HomeController < BaseOqsController end end - # booking_id = dining.get_new_booking + # booking_id = dining.get_new_booking # BookingOrder.where("booking_id='#{ booking_id }'").find_each do |bo| # order=Order.find(bo.order_id); # order.order_items.each do |oi| @@ -81,6 +81,8 @@ class Oqs::HomeController < BaseOqsController # Query for OQS with status def queue_items_query(status) + puts status + puts "put what is status" # AssignedOrderItem.select("assigned_order_items.assigned_order_item_id, oqs.station_name, oqs.is_active, df.name as zone, odt.item_code, odt.item_name, odt.price, odt.qty, odt.item_order_by, cus.name as customer_name, odt.created_at") # .joins(" left join order_queue_process_by_zones as oqpz ON oqpz.order_queue_station_id = assigned_order_items.order_queue_station_id # left join dining_facilities as df on df.zone_id = oqpz.zone_id @@ -88,9 +90,9 @@ class Oqs::HomeController < BaseOqsController # left join orders as od ON od.order_id = assigned_order_items.order_id # left join order_items as odt ON odt.item_code = assigned_order_items.item_code # left join customers as cus ON cus.customer_id = od.customer_id") - # .where("assigned_order_items.delivery_status = #{status}") + # .where("assigned_order_items.delivery_status = #{status}") # .group("assigned_order_items.assigned_order_item_id") - # .order("odt.item_name DESC") + # .order("odt.item_name DESC") AssignedOrderItem.select("assigned_order_items.assigned_order_item_id, oqs.station_name, oqs.is_active, df.name as zone, odt.item_code, odt.item_name, odt.price, odt.qty, odt.item_order_by, cus.name as customer_name, odt.created_at") .joins(" left join order_queue_stations as oqs on oqs.id = assigned_order_items.order_queue_station_id left join orders as od ON od.order_id = assigned_order_items.order_id @@ -99,7 +101,7 @@ class Oqs::HomeController < BaseOqsController left join booking_orders as bo on bo.order_id = assigned_order_items.order_id left join bookings as bk on bk.booking_id = bo.booking_id left join dining_facilities as df on df.id = bk.dining_facility_id") - .where("assigned_order_items.delivery_status = #{status}") - .group("assigned_order_items.assigned_order_item_id") + .where("assigned_order_items.delivery_status = #{status}") + .group("assigned_order_items.assigned_order_item_id,oqs.station_name,oqs.is_active,df.name,odt.item_code,odt.item_name,odt.price, odt.qty, odt.item_order_by,cus.name,odt.created_at") end end diff --git a/app/controllers/origami/home_controller.rb b/app/controllers/origami/home_controller.rb index 1aca9b2d..455cda09 100644 --- a/app/controllers/origami/home_controller.rb +++ b/app/controllers/origami/home_controller.rb @@ -1,84 +1,32 @@ class Origami::HomeController < BaseOrigamiController + before_action :set_dining, only: [:show] + def index - if params[:booking_id] != nil - type=params[:booking_id].split('-')[0]; - # Sale - if type == "SAL" - @selected_item = Sale.find(params[:booking_id]) - @selected_item_type="Sale" - # Booking - else - @selected_item = Order.find(params[:booking_id]) - @selected_item_type="Order" - end - end - - @completed_orders = Order.get_completed_order() - @booking_orders = Order.get_booking_order_table() - @booking_rooms = Order.get_booking_order_rooms() - @orders = Order.get_orders() + @tables = Table.all.active.order('status desc') + @rooms = Room.all.active.order('status desc') end - def item_show - selection(params[:booking_id],1) - end - - def selection(selected_id, is_ajax) - str = [] - type=selected_id.split('-')[0]; - # Sale - if type == "SAL" - @order_details = SaleItem.get_order_items_details(params[:booking_id]) - @order_details.each do |ord_detail| - str.push(ord_detail) - end - # Booking - else - @order_details = OrderItem.get_order_items_details(params[:booking_id]) - @order_details.each do |ord_detail| - str.push(ord_detail) - end - end - - if is_ajax == 1 - render :json => str.to_json - else - str - end - end - - def update_sale_by_customer - - id = params[:sale_id][0,3] - if(id == "SAL") - sale = Sale.find(params[:sale_id]) - else - sale = Order.find(params[:sale_id]) - end - - status = sale.update_attributes(customer_id: params[:customer_id]) - - if status == true - render json: JSON.generate({:status => true}) - else - render json: JSON.generate({:status => false, :error_message => "Record not found"}) - - end - end - - def get_customer - - @customer = Customer.find(params[:customer_id]) - - response = Customer.get_member_account(@customer) - - respond_to do |format| - format.js do - render :json => { - :response_data => response.as_json, - :customer => @customer} - end + def show + @tables = Table.all.active.order('status desc') + @rooms = Room.all.active.order('status desc') + @dining.bookings.each do |booking| + if booking.sale_id.nil? + booking_orders = booking.booking_orders + booking_orders.each do |booking_order| + @order = booking_order.order + end + @status = 'order' + else + @status = 'sale' + @obj = Sale.find(booking.sale_id) end + end end +private + +def set_dining + @dining = DiningFacility.find(params[:dining_id]) +end + end diff --git a/app/controllers/origami/home_controller_bk.rb b/app/controllers/origami/home_controller_bk.rb new file mode 100644 index 00000000..1aca9b2d --- /dev/null +++ b/app/controllers/origami/home_controller_bk.rb @@ -0,0 +1,84 @@ +class Origami::HomeController < BaseOrigamiController + def index + if params[:booking_id] != nil + type=params[:booking_id].split('-')[0]; + # Sale + if type == "SAL" + @selected_item = Sale.find(params[:booking_id]) + @selected_item_type="Sale" + # Booking + else + @selected_item = Order.find(params[:booking_id]) + @selected_item_type="Order" + end + end + + @completed_orders = Order.get_completed_order() + @booking_orders = Order.get_booking_order_table() + @booking_rooms = Order.get_booking_order_rooms() + @orders = Order.get_orders() + end + + def item_show + selection(params[:booking_id],1) + end + + def selection(selected_id, is_ajax) + str = [] + type=selected_id.split('-')[0]; + # Sale + if type == "SAL" + @order_details = SaleItem.get_order_items_details(params[:booking_id]) + @order_details.each do |ord_detail| + str.push(ord_detail) + end + # Booking + else + @order_details = OrderItem.get_order_items_details(params[:booking_id]) + @order_details.each do |ord_detail| + str.push(ord_detail) + end + end + + if is_ajax == 1 + render :json => str.to_json + else + str + end + end + + def update_sale_by_customer + + id = params[:sale_id][0,3] + if(id == "SAL") + sale = Sale.find(params[:sale_id]) + else + sale = Order.find(params[:sale_id]) + end + + status = sale.update_attributes(customer_id: params[:customer_id]) + + if status == true + render json: JSON.generate({:status => true}) + else + render json: JSON.generate({:status => false, :error_message => "Record not found"}) + + end + end + + def get_customer + + @customer = Customer.find(params[:customer_id]) + + response = Customer.get_member_account(@customer) + + respond_to do |format| + format.js do + render :json => { + :response_data => response.as_json, + :customer => @customer} + end + end + end + +end diff --git a/app/models/booking.rb b/app/models/booking.rb index 01cf0f46..0738df40 100644 --- a/app/models/booking.rb +++ b/app/models/booking.rb @@ -1,5 +1,7 @@ class Booking < ApplicationRecord + + self.primary_key = "booking_id" #primary key - need to be unique diff --git a/app/models/dining_facility.rb b/app/models/dining_facility.rb index 6f898989..588a7bcd 100644 --- a/app/models/dining_facility.rb +++ b/app/models/dining_facility.rb @@ -1,6 +1,7 @@ class DiningFacility < ApplicationRecord belongs_to :zone - + has_many :bookings + TABLE_TYPE = "Table" ROOM_TYPE = "Room" @@ -9,8 +10,8 @@ class DiningFacility < ApplicationRecord scope :active, -> {where(is_active: true)} def get_current_booking - puts "enter booking" - booking = Booking.where("dining_facility_id = #{self.id} and booking_status ='assign' and checkin_at between '#{DateTime.now.utc - 5.hours}' and '#{DateTime.now.utc}' and checkout_at is null").limit(1) + puts "enter booking" + booking = Booking.where("dining_facility_id = #{self.id} and booking_status ='assign' and checkin_at between '#{DateTime.now.utc - 5.hours}' and '#{DateTime.now.utc}' and checkout_at is null").limit(1) if booking.count > 0 then return booking[0].booking_id @@ -21,10 +22,10 @@ class DiningFacility < ApplicationRecord def get_new_booking # query for new - # if status + # if status # to ask when req bill booking_status? booking = Booking.where("dining_facility_id = #{self.id} and booking_status ='assign' and sale_id is null and checkout_at is null").limit(1) - # else + # else # booking = Booking.where("dining_facility_id = #{self.id} and booking_status ='assign' and sale_id not null").limit(1) # end diff --git a/app/models/order.rb b/app/models/order.rb index 2ea76a98..96382c07 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -231,7 +231,7 @@ class Order < ApplicationRecord .joins("left join orders on orders.order_id = booking_orders.order_id") .joins("left join sales on sales.sale_id = bookings.sale_id") .where("(orders.status = 'new' or orders.status = 'billed') and (dining_facilities.type=? and dining_facilities.is_active=?)",DiningFacility::TABLE_TYPE,true) - .group("bookings.booking_id") + .group("bookings.booking_id,sales.receipt_no,orders.status,sales.sale_id,dining_facilities.name,orders.status,orders.order_id") # For PG # booking_orders.order_id IS NOT NULL and dining_facilities.type=? and dining_facilities.is_active=?",DiningFacility::TABLE_TYPE,true # sales.receipt_no,orders.status,sales.sale_id,dining_facilities.name,orders.status,orders.order_id @@ -262,7 +262,7 @@ class Order < ApplicationRecord .joins("left join orders on orders.order_id = booking_orders.order_id") .joins("left join sales on sales.sale_id = bookings.sale_id") .where("(orders.status = 'new' or orders.status = 'billed') and (dining_facilities.type=? and dining_facilities.is_active=?)",DiningFacility::ROOM_TYPE,true) - .group("bookings.booking_id") + .group("bookings.booking_id,sales.receipt_no,orders.status,sales.sale_id,dining_facilities.name,orders.customer_id,orders.order_id") # For PG # booking_orders.order_id IS NOT NULL and dining_facilities.type=? and dining_facilities.is_active=?",DiningFacility::ROOM_TYPE,true # sales.receipt_no,orders.status,sales.sale_id,dining_facilities.name,orders.customer_id,orders.order_id diff --git a/app/models/room.rb b/app/models/room.rb index d99708a3..263120fd 100644 --- a/app/models/room.rb +++ b/app/models/room.rb @@ -1,3 +1,4 @@ class Room < DiningFacility + # has_many :bookings, :foreign_key => 'dining_facility_id' end diff --git a/app/models/table.rb b/app/models/table.rb index 31614e12..4012a40c 100644 --- a/app/models/table.rb +++ b/app/models/table.rb @@ -1,4 +1,4 @@ class Table < DiningFacility has_many :dining_ins - + # has_many :bookings, :foreign_key => 'dining_facility_id' end diff --git a/app/models/table_booking.rb b/app/models/table_booking.rb index 4b76f158..53fde486 100644 --- a/app/models/table_booking.rb +++ b/app/models/table_booking.rb @@ -1,3 +1,3 @@ class TableBooking < Booking - + belongs_to :sale end diff --git a/app/views/layouts/origami.html.erb b/app/views/layouts/origami.html.erb index 179d9ae1..ea2c0ce4 100644 --- a/app/views/layouts/origami.html.erb +++ b/app/views/layouts/origami.html.erb @@ -10,7 +10,7 @@ <%= csrf_meta_tags %> <%= stylesheet_link_tag 'origami', media: 'all', 'data-turbolinks-track': 'reload' %> - <%= javascript_include_tag 'origami', 'data-turbolinks-track': 'reload' %> + <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> @@ -23,7 +23,7 @@ <%=message%>

    <% end %> - + <% end %> <%= yield %> diff --git a/app/views/origami/home/index.html.erb b/app/views/origami/home/index.html.erb index ce2b3a94..4b85d839 100644 --- a/app/views/origami/home/index.html.erb +++ b/app/views/origami/home/index.html.erb @@ -1,388 +1,104 @@ -
    - -
    +
    + +
    - - - + + + -
    - -
    -
    - <% - @completed_orders.each do |cpo| - # ToDo no need check new - # Assigned Id for new Order? Sale? - unique_id = "" - customer_id = "" +
    + +
    +
    - # For CSS- Class for Order? Sale? - # sale_status="" - # if cpo.order_status == 'new' - # unique_id=cpo.booking_id +
    +
    - # customer_id=cpo.order_customer_id - # # check selected item and assign - # if @selected_item_type == "Sale" - # if cpo.order_id == @selected_item.order_id - # sale_status = sale_status + " selected-item" - # end - # end - # else - unique_id=cpo.sale_id - customer_id=cpo.sale_customer_id - sale_status="paid" - # check selected item and assign - if @selected_item != nil - if unique_id == @selected_item.sale_id - sale_status = sale_status + " selected-item" - end - end - # end - %> -
    -
    - - - -

    <%= cpo.table_name %>

    -

    - Receipt No : - - <%= cpo.receipt_no %> - -

    -

    - Order Status : - <%= cpo.sale_status %> - -

    -
    -
    - <% - end - %> -
    -
    +
    +
    - -
    -
    - <% - @booking_orders.each do |bko| - # No Show completed - if bko.sale_status == 'completed' - next - end +
    +
    - # Assigned Id for new Order? Sale? - unique_id="" - customer_id="" - # For CSS- Class for Order? Sale? - sale_status="" - if bko.order_status == 'new' - unique_id=bko.booking_id - customer_id=bko.order_customer_id - # check selected item and assign - # if @selected_item != nil - # if bko.order_id == @selected_item.order_id - # sale_status = sale_status + " selected-item" - # end - # end - else - unique_id=bko.sale_id - customer_id=bko.sale_customer_id - sale_status="sold" - # check selected item and assign - if @selected_item != nil - if unique_id == @selected_item.sale_id - sale_status = sale_status + " selected-item" - end - end - end - %> -
    -
    - - - -

    <%= bko.table_name %>

    -

    - Receipt No : - - <%= bko.receipt_no %> - -

    -

    - Order Status : - <%= bko.order_status %> - -

    -
    -
    - <% - end - %> -
    -
    + +
    +
    + <% @tables.each do |table| %> + <% if table.status == 'occupied' %> +
    +
    + <%= table.name %> +
    +
    + <% else %> +
    +
    + <%= table.name %> +
    +
    + <% end %> + <% end %> +
    +
    - -
    -
    - <% - @booking_rooms.each do |rmo| - # No Show completed - if rmo.sale_status == 'completed' - next - end + +
    +
    + <% @rooms.each do |room| %> + <% if room.status == 'occupied' %> +
    +
    + <%= room.name %> +
    +
    + <% else %> +
    +
    + <%= room.name %> +
    +
    + <% end %> + <% end %> +
    +
    - # Assigned Id for new Order? Sale? - unique_id="" - customer_id="" - # For CSS- Class for Order? Sale? - sale_status="" + +
    +
    - if rmo.order_status == 'new' - unique_id=rmo.booking_id - customer_id=rmo.order_customer_id - # check selected item and assign - # if @selected_item != nil - # if rmo.order_id == @selected_item.order_id - # sale_status = sale_status + " selected-item" - # end - # end - else - unique_id=rmo.sale_id - customer_id=rmo.sale_customer_id - sale_status="sold" - # check selected item and assign - if @selected_item != nil - if unique_id == @selected_item.sale_id - sale_status = sale_status + " selected-item" - end - end - end - %> -
    -
    - - - -

    <%= rmo.room_name %>

    -

    - Receipt No : - - <%= rmo.receipt_no %> - -

    -

    - Order Status : - <%= rmo.order_status %> - -

    -
    -
    - <% - end - %> -
    -
    +
    +
    - -
    -
    - <% - @orders.each do |odr| - # No Show completed - if odr.sale_status == 'completed' - next - end - # Assigned Id for new Order? Sale? - unique_id="" - customer_id="" - # For CSS- Class for Order? Sale? - sale_status="" +
    +
    - if odr.order_status == 'new' - unique_id=odr.booking_id - customer_id = odr.order_customer_id - # if @selected_item != nil - # if odr.order_id == @selected_item.order_id - # sale_status = sale_status + " selected-item" - # end - # end - else - unique_id=odr.sale_id - customer_id = odr.sale_customer_id - sale_status="sold" - # check selected item and assign - if @selected_item != nil - if unique_id == @selected_item.sale_id - sale_status = sale_status + " selected-item" - end - end - end - %> -
    -
    - - - -

    <%= odr.table_name %>

    - Receipt No : - - <%= odr.receipt_no %> - -

    -

    - Order Status : - <%= odr.order_status %> - -

    -
    -
    - <% - end - %> -
    +
    -
    -
    - -
    - - - -
    -
    -
    -
    ORDER DETAILS -
    -
    -
    -
    -
    -

    Receipt No: <%=@selected_item.receipt_no rescue ' '%>

    - -
    -
    -

    Date: <%=@selected_item.receipt_date.strftime("%d/%m/%Y - %I:%M %p") rescue '-'%>

    -
    -
    -
    -
    -

    Customer :

    - -
    - -
    -
    - - - - - - - - <% - # For Sale Items - sub_total = 0 - if @selected_item_type == "Sale" - @selected_item.sale_items.each do |sale_item| - sub_total = sub_total + sale_item.price - %> - - - - - - <% - end - end - %> - - <% - # For Order Items - if @selected_item_type == "Order" - @selected_item.order_items.each do |order_item| - sub_total = sub_total + (order_item.qty*order_item.price) - %> - - - - - - <% - end - end - %> - -
    ItemsQTY - Price -
    <%= sale_item.product_name %><%= sale_item.qty %><%= sale_item.price %>
    <%= order_item.item_name %><%= order_item.qty %><%= order_item.qty*order_item.price %>
    -
    - -
    -
    +
    - - -
    - - - - - - - - - - - -
    -
    + +
    +
    + + diff --git a/app/views/origami/home/index_bk.html.erb b/app/views/origami/home/index_bk.html.erb new file mode 100644 index 00000000..ce2b3a94 --- /dev/null +++ b/app/views/origami/home/index_bk.html.erb @@ -0,0 +1,388 @@ +
    + +
    + + + + + +
    + +
    +
    + <% + @completed_orders.each do |cpo| + # ToDo no need check new + # Assigned Id for new Order? Sale? + unique_id = "" + customer_id = "" + + # For CSS- Class for Order? Sale? + # sale_status="" + # if cpo.order_status == 'new' + # unique_id=cpo.booking_id + + # customer_id=cpo.order_customer_id + # # check selected item and assign + # if @selected_item_type == "Sale" + # if cpo.order_id == @selected_item.order_id + # sale_status = sale_status + " selected-item" + # end + # end + # else + unique_id=cpo.sale_id + customer_id=cpo.sale_customer_id + sale_status="paid" + # check selected item and assign + if @selected_item != nil + if unique_id == @selected_item.sale_id + sale_status = sale_status + " selected-item" + end + end + # end + %> +
    +
    + + + + +

    <%= cpo.table_name %>

    +

    + Receipt No : + + <%= cpo.receipt_no %> + +

    +

    + Order Status : + <%= cpo.sale_status %> + +

    +
    +
    + <% + end + %> +
    +
    + + +
    +
    + <% + @booking_orders.each do |bko| + # No Show completed + if bko.sale_status == 'completed' + next + end + + # Assigned Id for new Order? Sale? + unique_id="" + customer_id="" + # For CSS- Class for Order? Sale? + sale_status="" + if bko.order_status == 'new' + unique_id=bko.booking_id + customer_id=bko.order_customer_id + # check selected item and assign + # if @selected_item != nil + # if bko.order_id == @selected_item.order_id + # sale_status = sale_status + " selected-item" + # end + # end + else + unique_id=bko.sale_id + customer_id=bko.sale_customer_id + sale_status="sold" + # check selected item and assign + if @selected_item != nil + if unique_id == @selected_item.sale_id + sale_status = sale_status + " selected-item" + end + end + end + %> +
    +
    + + + +

    <%= bko.table_name %>

    +

    + Receipt No : + + <%= bko.receipt_no %> + +

    +

    + Order Status : + <%= bko.order_status %> + +

    +
    +
    + <% + end + %> +
    +
    + + +
    +
    + <% + @booking_rooms.each do |rmo| + # No Show completed + if rmo.sale_status == 'completed' + next + end + + # Assigned Id for new Order? Sale? + unique_id="" + customer_id="" + # For CSS- Class for Order? Sale? + sale_status="" + + if rmo.order_status == 'new' + unique_id=rmo.booking_id + customer_id=rmo.order_customer_id + # check selected item and assign + # if @selected_item != nil + # if rmo.order_id == @selected_item.order_id + # sale_status = sale_status + " selected-item" + # end + # end + else + unique_id=rmo.sale_id + customer_id=rmo.sale_customer_id + sale_status="sold" + # check selected item and assign + if @selected_item != nil + if unique_id == @selected_item.sale_id + sale_status = sale_status + " selected-item" + end + end + end + %> +
    +
    + + + +

    <%= rmo.room_name %>

    +

    + Receipt No : + + <%= rmo.receipt_no %> + +

    +

    + Order Status : + <%= rmo.order_status %> + +

    +
    +
    + <% + end + %> +
    +
    + + +
    +
    + <% + @orders.each do |odr| + # No Show completed + if odr.sale_status == 'completed' + next + end + # Assigned Id for new Order? Sale? + unique_id="" + customer_id="" + # For CSS- Class for Order? Sale? + sale_status="" + + if odr.order_status == 'new' + unique_id=odr.booking_id + customer_id = odr.order_customer_id + # if @selected_item != nil + # if odr.order_id == @selected_item.order_id + # sale_status = sale_status + " selected-item" + # end + # end + else + unique_id=odr.sale_id + customer_id = odr.sale_customer_id + sale_status="sold" + # check selected item and assign + if @selected_item != nil + if unique_id == @selected_item.sale_id + sale_status = sale_status + " selected-item" + end + end + end + %> +
    +
    + + + +

    <%= odr.table_name %>

    + Receipt No : + + <%= odr.receipt_no %> + +

    +

    + Order Status : + <%= odr.order_status %> + +

    +
    +
    + <% + end + %> +
    + +
    +
    + +
    + + + +
    +
    +
    +
    ORDER DETAILS -
    +
    +
    +
    +
    +

    Receipt No: <%=@selected_item.receipt_no rescue ' '%>

    + +
    +
    +

    Date: <%=@selected_item.receipt_date.strftime("%d/%m/%Y - %I:%M %p") rescue '-'%>

    +
    +
    +
    +
    +

    Customer :

    + +
    + +
    +
    + + + + + + + + <% + # For Sale Items + sub_total = 0 + if @selected_item_type == "Sale" + @selected_item.sale_items.each do |sale_item| + sub_total = sub_total + sale_item.price + %> + + + + + + <% + end + end + %> + + <% + # For Order Items + if @selected_item_type == "Order" + @selected_item.order_items.each do |order_item| + sub_total = sub_total + (order_item.qty*order_item.price) + %> + + + + + + <% + end + end + %> + +
    ItemsQTY + Price +
    <%= sale_item.product_name %><%= sale_item.qty %><%= sale_item.price %>
    <%= order_item.item_name %><%= order_item.qty %><%= order_item.qty*order_item.price %>
    +
    + +
    +
    +
    + + +
    + + + + + + + + + + + +
    +
    diff --git a/app/views/origami/home/show.html.erb b/app/views/origami/home/show.html.erb new file mode 100644 index 00000000..32b3a85c --- /dev/null +++ b/app/views/origami/home/show.html.erb @@ -0,0 +1,217 @@ +
    + +
    + + + + + +
    + +
    +
    + +
    +
    + + +
    +
    +
    +
    + + +
    +
    + <% @tables.each do |table| %> + <% if table.status == 'occupied' %> +
    +
    + <%= table.name %> +
    +
    + <% else %> +
    +
    + <%= table.name %> +
    +
    + <% end %> + <% end %> +
    +
    + + +
    +
    + <% @rooms.each do |room| %> + <% if room.status == 'occupied' %> +
    +
    + <%= room.name %> +
    +
    + <% else %> +
    +
    + <%= room.name %> +
    +
    + <% end %> + <% end %> +
    +
    + + +
    +
    + +
    +
    + +
    +
    +
    + +
    +
    + +
    + + + +
    +
    +
    +
    ORDER DETAILS
    +
    +
    +
    +
    +

    Receipt No: + <% if @status == 'sale' %> + <%= @obj.receipt_no rescue '' %> + <% end %> +

    +
    +
    +

    Date: <%= @obj.created_at.utc.strftime("%d/%m/%Y - %I:%M %p") rescue '-'%>

    +
    +
    +
    +
    +

    Customer :

    +
    + +
    +
    + + + + + + + + <% + # For Sale Items + sub_total = 0 + if @status == "sale" + @obj.sale_items.each do |sale_item| + sub_total = sub_total + sale_item.price + %> + <% unless sale_item.price <= 0 %> + + + + + + <% + end + end + end + %> + + <% + # For Order Items + if @status == "order" + sub_total = 0 + @order.order_items.each do |order_item| + sub_total = sub_total + (order_item.qty*order_item.price) + %> + + + + + + <% + end + end + %> + +
    ItemsQTY + Price +
    <%= sale_item.product_name %><%= sale_item.qty %><%= sale_item.price %>
    <%= order_item.item_name %><%= order_item.qty %><%= order_item.qty*order_item.price %>
    +
    + +
    +
    +
    + + +
    + + + + + + + + + + + +
    +
    + diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index 9952a7bc..3a596cee 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -12,7 +12,7 @@ Rails.application.config.assets.version = '1.0' # --- Waiter/ Cashier - Orgiami ---- Rails.application.config.assets.precompile += %w( origami.css ) -Rails.application.config.assets.precompile += %w( origami.js ) +# Rails.application.config.assets.precompile += %w( origami.js ) # -- Order Queue Station ----- Rails.application.config.assets.precompile += %w( OQS.css ) Rails.application.config.assets.precompile += %w( OQS.js ) diff --git a/config/routes.rb b/config/routes.rb index 6253a95f..0df21efd 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -72,7 +72,8 @@ Rails.application.routes.draw do #--------- Cashier ------------# namespace :origami do root "home#index" - get "/:booking_id" => "home#index" do #origami/:booking_id will show + get "/:dining_id" => "home#show" do #origami/:booking_id will show + # resources :discounts, only: [:index,:new, :create ] #add discount type resources :customers #add customer type end From bdb42daad796a751fb677c284cefb4f35043aa4f Mon Sep 17 00:00:00 2001 From: Nweni Date: Tue, 20 Jun 2017 07:42:05 +0630 Subject: [PATCH 022/128] dining facility model --- app/models/booking.rb | 2 -- app/models/dining_facility.rb | 3 +-- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/app/models/booking.rb b/app/models/booking.rb index 0738df40..01cf0f46 100644 --- a/app/models/booking.rb +++ b/app/models/booking.rb @@ -1,7 +1,5 @@ class Booking < ApplicationRecord - - self.primary_key = "booking_id" #primary key - need to be unique diff --git a/app/models/dining_facility.rb b/app/models/dining_facility.rb index 588a7bcd..65c337e4 100644 --- a/app/models/dining_facility.rb +++ b/app/models/dining_facility.rb @@ -1,7 +1,6 @@ class DiningFacility < ApplicationRecord belongs_to :zone - has_many :bookings - + TABLE_TYPE = "Table" ROOM_TYPE = "Room" From 80362f87feddabb1a2d844daf475303460967676 Mon Sep 17 00:00:00 2001 From: Phyo Date: Tue, 20 Jun 2017 13:22:27 +0630 Subject: [PATCH 023/128] Rebate Option --- .../origami/redeem_payments_controller.rb | 11 ++-- app/models/sale_item.rb | 55 ++++++++++--------- app/models/sale_payment.rb | 14 ++--- .../origami/redeem_payments/index.html.erb | 6 +- 4 files changed, 44 insertions(+), 42 deletions(-) diff --git a/app/controllers/origami/redeem_payments_controller.rb b/app/controllers/origami/redeem_payments_controller.rb index 99601449..792cb7a4 100644 --- a/app/controllers/origami/redeem_payments_controller.rb +++ b/app/controllers/origami/redeem_payments_controller.rb @@ -6,7 +6,8 @@ class Origami::RedeemPaymentsController < BaseOrigamiController sale_data = Sale.find_by_sale_id(@sale_id) # limit redeem_amount - food_prices, beverage_prices = SaleItem.calculate_food_beverage(sale_data.sale_items) + rebate_prices = SaleItem.calculate_food_beverage(sale_data.sale_items) + nonrebate_prices = sale_data.total_amount - rebate_prices @payparcount = 0 others = 0 sale_data.sale_payments.each do |sale_payment| @@ -16,11 +17,11 @@ class Origami::RedeemPaymentsController < BaseOrigamiController others = others + sale_payment.payment_amount end end - is_bervage_exceed = others - (beverage_prices + sale_data.total_tax) - if is_bervage_exceed < 0 - @food_prices = food_prices - @payparcount + non_rebate_exceed = others - (nonrebate_prices + sale_data.total_tax) + if non_rebate_exceed < 0 + @redeem_prices = rebate_prices - @payparcount else - @food_prices = food_prices - @payparcount -is_bervage_exceed + @redeem_prices = rebate_prices - @payparcount -non_rebate_exceed end if sale_data diff --git a/app/models/sale_item.rb b/app/models/sale_item.rb index a999b6a8..bec8b5c5 100644 --- a/app/models/sale_item.rb +++ b/app/models/sale_item.rb @@ -32,48 +32,49 @@ class SaleItem < ApplicationRecord # Calculate food total and beverage total def self.calculate_food_beverage(sale_items) - food_prices=0 - beverage_prices=0 - sale_items.each do |si| - food_price, beverage_price = self.get_price(si.sale_item_id) - - food_prices = food_prices + food_price - beverage_prices = beverage_prices + beverage_price + rebateacc = Account.where("rebate=?",true) + puts "Account that can rebate" + rebateacc.each do |i| + puts i.title end - puts food_prices - puts beverage_prices - return food_prices, beverage_prices + prices=0 + sale_items.each do |si| + price = self.get_price(si.sale_item_id,rebateacc) + + prices = prices + price + end + return prices end # get food price or beverage price for item - def self.get_price(sale_item_id) - food_price=0 - beverage_price=0 + def self.get_price(sale_item_id,rebateacc) + price=0 item=SaleItem.select("sale_items.price , menu_items.account_id") .joins("left join menu_items on menu_items.item_code = sale_items.product_code") .where("sale_items.sale_item_id=?", sale_item_id.to_s) - if item[0].account_id == 1 - food_price = item[0].price - else - beverage_price = item[0].price - end - return food_price, beverage_price - end - - def self.get_overall_discount(sale_id) - price = 0.0 - item=SaleItem.where("product_code=?", sale_id) - - item.each do|i| - price += i.price + rebateacc.each do |i| + if item[0].account_id == i.id + price = item[0].price + end end return price end + # def self.get_overall_discount(sale_id) + # price = 0.0 + # item=SaleItem.where("product_code=?", sale_id) + # + # item.each do|i| + # price += i.price + # end + # + # return price + # end + private def generate_custom_id self.sale_item_id = SeedGenerator.generate_id(self.class.name, "SLI") diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 715c7479..4ca22423 100644 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -241,7 +241,9 @@ class SalePayment < ApplicationRecord end def rebat(sObj) - food_prices, beverage_prices = SaleItem.calculate_food_beverage(sObj.sale_items) + rebate_prices = SaleItem.calculate_food_beverage(sObj.sale_items) + puts "rebate_prices" + puts rebate_prices generic_customer_id = sObj.customer.membership_id if generic_customer_id != nil || generic_customer_id != "" || generic_customer_id != 0 paypar = sObj.sale_payments @@ -251,12 +253,10 @@ class SalePayment < ApplicationRecord payparcost = payparcost + pp.payment_amount end end - overall_dis = SaleItem.get_overall_discount(sObj.id) - total_amount = food_prices - payparcost + overall_dis - puts "total_amount" - puts food_prices - puts payparcost - puts total_amount + # overall_dis = SaleItem.get_overall_discount(sObj.id) + overall_dis = sObj.total_discount + + total_amount = rebate_prices - payparcost + overall_dis if total_amount > 0 receipt_no = sObj.receipt_no membership = MembershipSetting.find_by_membership_type("paypar_url") diff --git a/app/views/origami/redeem_payments/index.html.erb b/app/views/origami/redeem_payments/index.html.erb index e1363d8b..83b24213 100644 --- a/app/views/origami/redeem_payments/index.html.erb +++ b/app/views/origami/redeem_payments/index.html.erb @@ -6,7 +6,7 @@
    - +

    @@ -38,7 +38,7 @@ +

    You can rebate upto <%= @redeem_prices %>

    -->
    @@ -151,7 +151,7 @@ $("#redeem").click(function(){ }else if(valid_amount< redeem_amount){ alert(" Insufficient Amount!") }else{ - if(redeem_amount <= "<%= @food_prices %>"){ + if(redeem_amount <= "<%= @redeem_prices %>"){ $.ajax({ type: "POST", url: "<%=origami_payment_paypar_path%>", From e43818fdf5101667fc01f593e11dd2c482ec533a Mon Sep 17 00:00:00 2001 From: Yan Date: Tue, 20 Jun 2017 13:33:41 +0630 Subject: [PATCH 024/128] oqs updated --- app/assets/javascripts/OQS.js | 4 ++- app/controllers/oqs/print_controller.rb | 11 +++++-- app/models/order_queue_station.rb | 3 ++ app/models/printer/order_queue_printer.rb | 22 +++++++------- app/pdf/order_item_pdf.rb | 18 ++++++------ app/pdf/order_summary_pdf.rb | 29 +++++++++++-------- ...70403151731_create_order_queue_stations.rb | 2 +- 7 files changed, 53 insertions(+), 36 deletions(-) diff --git a/app/assets/javascripts/OQS.js b/app/assets/javascripts/OQS.js index e7b85110..87121ea3 100644 --- a/app/assets/javascripts/OQS.js +++ b/app/assets/javascripts/OQS.js @@ -122,11 +122,13 @@ $(document).ready(function(){ // Print Order Summary $('#print_order_summary').on('click',function(){ + var table_name=$('.selected-item').children().children().children('.order-zone').text().trim(); var assigned_item_id=$('.selected-item').children('.card-block').children('.assigned-order-item').text(); - var params = { 'id':assigned_item_id }; + var params = { 'table_name':table_name }; $.ajax({ type: 'GET', url: '/oqs/print/print_order_summary/'+assigned_item_id, + data: params, success: function(data){ } }); }); diff --git a/app/controllers/oqs/print_controller.rb b/app/controllers/oqs/print_controller.rb index 9fc2a2d7..dbbc8351 100644 --- a/app/controllers/oqs/print_controller.rb +++ b/app/controllers/oqs/print_controller.rb @@ -8,11 +8,12 @@ class Oqs::PrintController < ApplicationController # order queue stations oqs = assigned_item.order_queue_station + print_status = assigned_item.print_status == true ? " (Re-Print)" : "" # print when complete click print_settings=PrintSetting.find_by_unique_code(unique_code) order_queue_printer= Printer::OrderQueuePrinter.new(print_settings) - order_queue_printer.print_order_item(oqs,assigned_item.order_id, assigned_item.item_code ) + order_queue_printer.print_order_item(oqs, assigned_item.order_id, assigned_item.item_code, print_status ) # update print status for completed same order items assigned_items.each do |ai| @@ -25,16 +26,22 @@ class Oqs::PrintController < ApplicationController def print_order_summary unique_code="OrderSummaryPdf" assigned_item_id=params[:id] + table_name=params[:table_name] assigned_item=AssignedOrderItem.find(assigned_item_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 + print_status = assigned_item.print_status == true ? " (Re-Print)" : "" + + # get dining + dining = DiningFacility.find_by_name(table_name); + booking = Booking.find_by_dining_facility_id(dining.id) # print when complete click print_settings=PrintSetting.find_by_unique_code(unique_code) order_queue_printer= Printer::OrderQueuePrinter.new(print_settings) - order_queue_printer.print_order_summary(oqs,assigned_item.order_id) + order_queue_printer.print_order_summary(oqs, booking, print_status) # update print status for completed same order items assigned_items.each do |ai| diff --git a/app/models/order_queue_station.rb b/app/models/order_queue_station.rb index a5267442..2f0b40aa 100644 --- a/app/models/order_queue_station.rb +++ b/app/models/order_queue_station.rb @@ -31,6 +31,9 @@ class OrderQueueStation < ApplicationRecord # #Same Order_items can appear in two location. # AssignedOrderItem.assigned_order_item(order, order_item.item_code, oqs) # else + puts pq_item + puts order_item.item_code + puts oqs.station_name AssignedOrderItem.assigned_order_item(order, order_item.item_code, oqs) # end diff --git a/app/models/printer/order_queue_printer.rb b/app/models/printer/order_queue_printer.rb index 52fc3244..ab6794b2 100644 --- a/app/models/printer/order_queue_printer.rb +++ b/app/models/printer/order_queue_printer.rb @@ -1,11 +1,11 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker - def print_order_item(oqs,order_id, item_code) + def print_order_item(oqs,order_id, item_code, print_status) #Use CUPS service #Generate PDF #Print - order_item= print_query('order_item', item_code) #OrderItem.find_by_item_code(item_code) - pdf = OrderItemPdf.new(order_item[0]) + order_item = print_query('order_item', item_code) #OrderItem.find_by_item_code(item_code) + pdf = OrderItemPdf.new(order_item[0], print_status) pdf.render_file "tmp/order_item.pdf" if oqs.print_copy self.print("tmp/order_item.pdf", oqs.printer_name) @@ -15,16 +15,16 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker end end - def print_order_summary(oqs,order_id) + def print_order_summary(oqs,booking, print_status) #Use CUPS service #Generate PDF #Print - order=print_query('order_summary',order_id) + order=print_query('order_summary',booking.booking_id) # For Print Per Item if oqs.cut_per_item order.each do|odi| filename = "tmp/order_item_#{odi.item_name}" + ".pdf" - pdf = OrderItemPdf.new(odi) + pdf = OrderItemPdf.new(odi, print_status) # pdf.render_file "tmp/order_item.pdf" pdf.render_file filename if oqs.print_copy @@ -36,8 +36,8 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker end # For Print Order Summary else - filename = "tmp/order_summary_#{order_id}" + ".pdf" - pdf = OrderSummaryPdf.new(order) + filename = "tmp/order_summary_#{booking.booking_id}" + ".pdf" + pdf = OrderSummaryPdf.new(order, print_status) pdf.render_file filename if oqs.print_copy self.print(filename, oqs.printer_name) @@ -59,15 +59,15 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker left join customers as cus ON cus.customer_id = orders.customer_id") .where("order_items.item_code='" + code + "'") .group("order_items.item_code") - else + else OrderItem.select("order_items.item_code, order_items.item_name, order_items.qty, order_items.price, order_items.item_order_by as order_by, order_items.created_at as order_at, cus.name as customer, df.name as dining") .joins("left join orders ON orders.order_id = order_items.order_id left join booking_orders AS bo ON bo.order_id=order_items.order_id left join bookings AS b ON b.booking_id = bo.booking_id left join dining_facilities AS df ON df.id = b.dining_facility_id left join customers as cus ON cus.customer_id = orders.customer_id") - .where("orders.order_id='" + code + "'") - .group("order_items.item_code") + .where("b.booking_id='" + code + "'") + # .group("order_items.item_code") end end diff --git a/app/pdf/order_item_pdf.rb b/app/pdf/order_item_pdf.rb index dd223e49..e5c5395f 100644 --- a/app/pdf/order_item_pdf.rb +++ b/app/pdf/order_item_pdf.rb @@ -1,16 +1,16 @@ class OrderItemPdf < Prawn::Document attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width - def initialize(order_item) - self.page_width = 254 - self.page_height = 1450 - self.margin = 10 + def initialize(order_item, print_status) + self.page_width = 210 + self.page_height = 2500 + self.margin = 5 self.price_width = 40 # No Need for item - self.qty_width = 34 + self.qty_width = 30 self.total_width = 40 # No Need for item - self.item_width = self.page_width - (self.qty_width + (self.margin*4)) + self.item_width = self.page_width - self.qty_width self.item_height = 15 self.item_description_width = self.page_width - (self.price_width + self.qty_width + self.total_width) - self.label_width=80 + self.label_width=100 super(:margin => [self.margin, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height]) # super(:margin => [10, 5, 30, 5], :page_size => [200,400]) @@ -19,9 +19,9 @@ class OrderItemPdf < Prawn::Document # font "public/fonts/Zawgyi-One.ttf" # font "public/fonts/padauk.ttf" self.header_font_size = 14 - self.item_font_size = 12 + self.item_font_size = 12 - text "#{order_item.dining}", :size => self.header_font_size,:align => :center, :left_margin => -20 + text "#{ order_item.dining+print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 stroke_horizontal_rule move_down 5 diff --git a/app/pdf/order_summary_pdf.rb b/app/pdf/order_summary_pdf.rb index 22f27497..a1459512 100644 --- a/app/pdf/order_summary_pdf.rb +++ b/app/pdf/order_summary_pdf.rb @@ -1,13 +1,13 @@ class OrderSummaryPdf < Prawn::Document attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width - def initialize(order) - self.page_width = 254 - self.page_height = 1450 - self.margin = 10 + def initialize(order, print_status) + self.page_width = 210 + self.page_height = 2500 + self.margin = 5 self.price_width = 40 # No Need for item - self.qty_width = 34 + self.qty_width = 30 self.total_width = 40 # No Need for item - self.item_width = self.page_width - (self.qty_width + (self.margin*4)) + self.item_width = self.page_width - (self.qty_width - self.margin) self.item_height = 15 self.item_description_width = self.page_width - (self.price_width + self.qty_width + self.total_width) self.label_width=100 @@ -20,7 +20,7 @@ class OrderSummaryPdf < Prawn::Document self.header_font_size = 12 self.item_font_size = 10 - text "#{order[0].dining}", :size => self.header_font_size,:align => :center, :left_margin => -20 + text "#{ order[0].dining + print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 stroke_horizontal_rule move_down 5 @@ -59,7 +59,7 @@ class OrderSummaryPdf < Prawn::Document text "Item", :size => self.item_font_size,:align => :left end - bounding_box([self.item_width,y_position], :width => self.qty_width, :height => self.item_height) do + bounding_box([self.item_width-2,y_position], :width => self.qty_width, :height => self.item_height) do text "Qty", :size => self.item_font_size,:align => :left end @@ -78,12 +78,17 @@ class OrderSummaryPdf < Prawn::Document order_item.each do|odi| y_position = cursor - bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "#{odi.item_name}", :size => self.item_font_size,:align => :left + + # pad_top(15) { + # text_box "#{odi.item_name}", :at =>[0,y_position], :width => self.item_width, :height =>self.item_height, :size => self.item_font_size, :overflow => :shrink_to_fix + # text_box "#{odi.qty}", :at =>[self.item_width,y_position], :width => self.qty_width, :height =>self.item_height, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix + # } + bounding_box([0,y_position], :width => self.item_width) do + text "#{odi.item_name}", :size => self.item_font_size,:align => :left, :height => self.item_height end - bounding_box([self.item_width,y_position], :width => self.qty_width, :height => self.item_height) do - text "#{odi.qty}", :size => self.item_font_size,:align => :left + bounding_box([self.item_width,y_position], :width => self.qty_width) do + text "#{odi.qty}", :size => self.item_font_size,:align => :left, :height => self.item_height end move_down 5 diff --git a/db/migrate/20170403151731_create_order_queue_stations.rb b/db/migrate/20170403151731_create_order_queue_stations.rb index 801cdef0..6c327b8e 100644 --- a/db/migrate/20170403151731_create_order_queue_stations.rb +++ b/db/migrate/20170403151731_create_order_queue_stations.rb @@ -3,7 +3,7 @@ class CreateOrderQueueStations < ActiveRecord::Migration[5.1] create_table :order_queue_stations do |t| t.string :station_name, :null => false t.boolean :is_active, :null => false, :default => false - t.json :processing_items, :default => "[]" + t.json :processing_items t.boolean :print_copy, :null => false, :default => false t.string :printer_name t.integer :font_size, :null => false, :default => 10 From 6528845d827a4f8fdf8ddc7fce185c4ccc1656c3 Mon Sep 17 00:00:00 2001 From: Yan Date: Tue, 20 Jun 2017 15:58:50 +0630 Subject: [PATCH 025/128] oqs updated --- app/controllers/oqs/print_controller.rb | 8 ++- app/models/order_queue_station.rb | 13 ++-- app/models/printer/order_queue_printer.rb | 85 +++++++++++++++++++---- 3 files changed, 83 insertions(+), 23 deletions(-) diff --git a/app/controllers/oqs/print_controller.rb b/app/controllers/oqs/print_controller.rb index dbbc8351..ff2cf98d 100644 --- a/app/controllers/oqs/print_controller.rb +++ b/app/controllers/oqs/print_controller.rb @@ -8,6 +8,8 @@ class Oqs::PrintController < ApplicationController # order queue stations oqs = assigned_item.order_queue_station + + # Check Printed print_status = assigned_item.print_status == true ? " (Re-Print)" : "" # print when complete click @@ -22,7 +24,7 @@ class Oqs::PrintController < ApplicationController end end - # Print Order Details + # Print Order Details with booking id def print_order_summary unique_code="OrderSummaryPdf" assigned_item_id=params[:id] @@ -32,6 +34,8 @@ class Oqs::PrintController < ApplicationController # order queue stations oqs = assigned_item.order_queue_station + + # Check Printed print_status = assigned_item.print_status == true ? " (Re-Print)" : "" # get dining @@ -41,7 +45,7 @@ class Oqs::PrintController < ApplicationController # print when complete click print_settings=PrintSetting.find_by_unique_code(unique_code) order_queue_printer= Printer::OrderQueuePrinter.new(print_settings) - order_queue_printer.print_order_summary(oqs, booking, print_status) + order_queue_printer.print_booking_summary(oqs, booking.booking_id, print_status) # update print status for completed same order items assigned_items.each do |ai| diff --git a/app/models/order_queue_station.rb b/app/models/order_queue_station.rb index 2f0b40aa..2e85ecde 100644 --- a/app/models/order_queue_station.rb +++ b/app/models/order_queue_station.rb @@ -16,6 +16,9 @@ class OrderQueueStation < ApplicationRecord oqpbz = OrderQueueProcessByZone.find_by_zone_id(dining.zone_id) order_items = order.order_items + + # get dining + booking = Booking.find_by_dining_facility_id(dining.id) #Assign OQS id to order Items oqs_stations.each do |oqs| @@ -31,9 +34,7 @@ class OrderQueueStation < ApplicationRecord # #Same Order_items can appear in two location. # AssignedOrderItem.assigned_order_item(order, order_item.item_code, oqs) # else - puts pq_item - puts order_item.item_code - puts oqs.station_name + AssignedOrderItem.assigned_order_item(order, order_item.item_code, oqs) # end @@ -49,11 +50,11 @@ class OrderQueueStation < ApplicationRecord private #Print order_items in 1 slip def print_slip(oqs, order, order_items) - unique_code="OrderSummaryPdf" + unique_code="OrderSummaryPdf" print_settings=PrintSetting.find_by_unique_code(unique_code) order_queue_printer= Printer::OrderQueuePrinter.new(print_settings) - order_queue_printer.print_order_summary(oqs,order.order_id) + order_queue_printer.print_order_summary(oqs,order.order_id, print_status="") AssignedOrderItem.where("order_id = '#{ order.order_id }'").find_each do |ai| # update print status for order items @@ -70,7 +71,7 @@ class OrderQueueStation < ApplicationRecord # print when complete click print_settings=PrintSetting.find_by_unique_code(unique_code) order_queue_printer= Printer::OrderQueuePrinter.new(print_settings) - order_queue_printer.print_order_item(oqs,item.order_id, item.item_code ) + order_queue_printer.print_order_item(oqs,item.order_id, item.item_code, print_status="" ) # update print status for completed same order items assigned_order_item.each do |ai| diff --git a/app/models/printer/order_queue_printer.rb b/app/models/printer/order_queue_printer.rb index ab6794b2..63666a68 100644 --- a/app/models/printer/order_queue_printer.rb +++ b/app/models/printer/order_queue_printer.rb @@ -4,22 +4,29 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker #Use CUPS service #Generate PDF #Print - order_item = print_query('order_item', item_code) #OrderItem.find_by_item_code(item_code) + order_item = print_query('order_item', item_code) #OrderItem.find_by_item_code(item_code) + + filename = "tmp/order_item_#{order_item[0].item_name}" + ".pdf" pdf = OrderItemPdf.new(order_item[0], print_status) - pdf.render_file "tmp/order_item.pdf" + pdf.render_file filename + if oqs.print_copy - self.print("tmp/order_item.pdf", oqs.printer_name) - self.print("tmp/order_item.pdf", oqs.printer_name) + self.print(filename, oqs.printer_name) + + #For print copy + pdf.render_file filename.gsub(".","-copy.") + self.print(filename.gsub(".","-copy."), oqs.printer_name) else - self.print("tmp/order_item.pdf", oqs.printer_name) + self.print(filename, oqs.printer_name) end end - def print_order_summary(oqs,booking, print_status) + # Query for per order + def print_order_summary(oqs, order_id, print_status) #Use CUPS service #Generate PDF - #Print - order=print_query('order_summary',booking.booking_id) + #Print + order=print_query('order_summary', order_id) # For Print Per Item if oqs.cut_per_item order.each do|odi| @@ -36,11 +43,51 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker end # For Print Order Summary else - filename = "tmp/order_summary_#{booking.booking_id}" + ".pdf" + filename = "tmp/order_summary_#{ order_id }" + ".pdf" pdf = OrderSummaryPdf.new(order, print_status) pdf.render_file filename if oqs.print_copy self.print(filename, oqs.printer_name) + + #For print copy + pdf.render_file filename.gsub(".","-copy.") + self.print(filename.gsub(".","-copy."), oqs.printer_name) + else + self.print(filename, oqs.printer_name) + end + end + end + + # Print for orders in booking + def print_booking_summary(oqs, booking_id, print_status) + order=print_query('booking_summary', booking_id) + # For Print Per Item + if oqs.cut_per_item + order.each do|odi| + filename = "tmp/order_item_#{odi.item_name}" + ".pdf" + pdf = OrderItemPdf.new(odi, print_status) + pdf.render_file filename + + if oqs.print_copy + self.print(filename, oqs.printer_name) + + #For print copy + pdf.render_file filename.gsub(".","-copy.") + self.print(filename.gsub(".","-copy."), oqs.printer_name) + else + self.print(filename, oqs.printer_name) + end + end + # For Print Order Summary + else + filename = "tmp/booking_summary_#{ booking_id }" + ".pdf" + pdf = OrderSummaryPdf.new(order, print_status) + pdf.render_file filename + if oqs.print_copy + self.print(filename, oqs.printer_name) + + #For print copy + pdf.render_file filename.gsub(".","-copy.") self.print(filename.gsub(".","-copy."), oqs.printer_name) else self.print(filename, oqs.printer_name) @@ -49,25 +96,33 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker end # Query for OQS with status - def print_query(type, code) - if type == 'order_item' + def print_query(type, id) + if type == "order_item" OrderItem.select("order_items.item_code, order_items.item_name, order_items.qty, order_items.price, order_items.item_order_by as order_by, order_items.created_at as order_at, cus.name as customer, df.name as dining") .joins("left join orders ON orders.order_id = order_items.order_id left join booking_orders AS bo ON bo.order_id=order_items.order_id left join bookings AS b ON b.booking_id = bo.booking_id left join dining_facilities AS df ON df.id = b.dining_facility_id left join customers as cus ON cus.customer_id = orders.customer_id") - .where("order_items.item_code='" + code + "'") + .where("order_items.item_code = '#{ id }'") .group("order_items.item_code") - else + elsif type == "order_summary" OrderItem.select("order_items.item_code, order_items.item_name, order_items.qty, order_items.price, order_items.item_order_by as order_by, order_items.created_at as order_at, cus.name as customer, df.name as dining") .joins("left join orders ON orders.order_id = order_items.order_id left join booking_orders AS bo ON bo.order_id=order_items.order_id left join bookings AS b ON b.booking_id = bo.booking_id left join dining_facilities AS df ON df.id = b.dining_facility_id left join customers as cus ON cus.customer_id = orders.customer_id") - .where("b.booking_id='" + code + "'") - # .group("order_items.item_code") + .where("orders.order_id = '#{ id }'") + else + # order summary for booking + OrderItem.select("order_items.item_code, order_items.item_name, order_items.qty, order_items.price, order_items.item_order_by as order_by, order_items.created_at as order_at, cus.name as customer, df.name as dining") + .joins("left join orders ON orders.order_id = order_items.order_id + left join booking_orders AS bo ON bo.order_id=order_items.order_id + left join bookings AS b ON b.booking_id = bo.booking_id + left join dining_facilities AS df ON df.id = b.dining_facility_id + left join customers as cus ON cus.customer_id = orders.customer_id") + .where("b.booking_id = '#{ id }'") end end From 33cb8b64a32d25c093bf89cb44d545999adaf26f Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Tue, 20 Jun 2017 17:57:50 +0630 Subject: [PATCH 026/128] finished customer form and update --- app/assets/stylesheets/CRM.scss | 3 + app/controllers/crm/customers_controller.rb | 33 +++--- .../origami/payments_controller.rb | 5 +- app/models/customer.rb | 42 ++----- app/models/sale_payment.rb | 4 +- app/views/api/customers/index.json.jbuilder | 4 +- app/views/api/customers/show.json.jbuilder | 4 +- app/views/crm/customers/index.html.erb | 107 +++++++++++++++--- app/views/crm/customers/show.json.jbuilder | 5 +- app/views/origami/customers/index.html.erb | 93 +++++++++++++-- app/views/reports/receipt_no/index.html.erb | 9 +- app/views/transactions/sales/show.html.erb | 2 +- ....rb => 20170620091919_create_customers.rb} | 8 +- 13 files changed, 235 insertions(+), 84 deletions(-) rename db/migrate/{20170403135121_create_customers.rb => 20170620091919_create_customers.rb} (73%) diff --git a/app/assets/stylesheets/CRM.scss b/app/assets/stylesheets/CRM.scss index 8ddc1605..e2b88eaa 100644 --- a/app/assets/stylesheets/CRM.scss +++ b/app/assets/stylesheets/CRM.scss @@ -23,3 +23,6 @@ .assign .text-muted{ color: #fff !important; } +.required abbr{ + color: red !important; +} \ No newline at end of file diff --git a/app/controllers/crm/customers_controller.rb b/app/controllers/crm/customers_controller.rb index d83d434f..0adefbf4 100644 --- a/app/controllers/crm/customers_controller.rb +++ b/app/controllers/crm/customers_controller.rb @@ -7,23 +7,19 @@ class Crm::CustomersController < BaseCrmController filter = params[:filter] if filter.nil? - @crm_customers = Customer.order("customer_id").page(params[:page]) - #@products = Product.order("name").page(params[:page]).per(5) + @crm_customers = Customer.all else @crm_customers = Customer.search(filter) end #@crm_customers = Customer.all - @crm_customers = Kaminari.paginate_array(@crm_customers).page(params[:page]).per(50) + @crm_customers = Kaminari.paginate_array(@crm_customers).page(params[:page]).per(50) @crm_customer = Customer.new + @count_customer = Customer.count_customer # if flash["errors"] # @crm_customer.valid? # end - # @membership = Customer.get_member_group - # if @membership["status"] == true - # @member_group = @membership["data"] - # end respond_to do |format| format.html # index.html.erb format.json { render json: @crm_customers } @@ -50,14 +46,14 @@ class Crm::CustomersController < BaseCrmController end #get customer amount - @customer = Customer.find(params[:id]) - response = Customer.get_member_account(@customer) + # @customer = Customer.find(params[:id]) + # response = Customer.get_member_account(@customer) - if(response["status"] == true) - @membership = response["data"] - else + # if(response["status"] == true) + # @membership = response["data"] + # else @membership = 0 - end + # end #end customer amount @@ -87,6 +83,8 @@ class Crm::CustomersController < BaseCrmController phone = customer_params[:contact_no] email = customer_params[:email] dob = customer_params[:date_of_birth] + address = customer_params[:address] + nrc = customer_params[:nrc_no] member_group_id = params[:member_group_id] membership = MembershipSetting.find_by_membership_type("paypar_url") @@ -97,7 +95,7 @@ class Crm::CustomersController < BaseCrmController begin response = HTTParty.post(url, :body => { name: name,phone: phone,email: email, - dob: dob, + dob: dob,address: address,nrc:nrc, member_group_id: member_group_id,merchant_uid:merchant_uid,auth_token:auth_token}.to_json, :headers => { 'Content-Type' => 'application/json', @@ -155,6 +153,8 @@ end phone = customer_params[:contact_no] email = customer_params[:email] dob = customer_params[:date_of_birth] + address = customer_params[:address] + nrc = customer_params[:nrc_no] id = @crm_customer.membership_id member_group_id = params[:member_group_id] @@ -165,7 +165,7 @@ end url = membership.gateway_url.to_s + memberaction.gateway_url.to_s begin response = HTTParty.post(url, :body => { name: name,phone: phone,email: email, - dob: dob, + dob: dob,address: address,nrc:nrc, id: id,member_group_id:member_group_id,merchant_uid:merchant_uid,auth_token:auth_token}.to_json, :headers => { 'Content-Type' => 'application/json', @@ -207,6 +207,7 @@ end # Never trust parameters from the scary internet, only allow the white list through. def customer_params - params.require(:customer).permit(:name, :company, :contact_no, :email, :date_of_birth) + params.require(:customer).permit(:name, :company, :contact_no, :email, + :date_of_birth,:salution,:gender,:nrc_no,:address,:card_no) end end diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index e8ce6a96..6a6f4ca6 100644 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -10,10 +10,9 @@ class Origami::PaymentsController < BaseOrigamiController if(Sale.exists?(sale_id)) saleObj = Sale.find(sale_id) sale_payment = SalePayment.new - rebate_amount = sale_payment.process_payment(saleObj, @user, cash, "cash") + sale_payment.process_payment(saleObj, @user, cash, "cash") - puts "resssssssssssssssssss" - puts rebate_amount.to_json + rebate_amount = nil unique_code = "ReceiptBillPdf" customer= Customer.find(saleObj.customer_id) diff --git a/app/models/customer.rb b/app/models/customer.rb index de9846f2..0924d232 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -45,43 +45,19 @@ class Customer < ApplicationRecord end end -# require "net/http" -# def self.url_exist?(url_string) -# url = URI.parse(url_string) - - -# req = Net::HTTP.new(url.host, url.port) -# puts "hhhhhhhhhhhh" -# puts req.to_json -# req.use_ssl = (url.scheme == 'https') -# puts "aaaaaaaaaaaa" -# puts req.use_ssl? -# path = url.path if url.path.present? -# puts "bbbbbbbbbbbbb" -# puts path -# res = req.request_head(path || '/') -# puts "cccccccccccccc" -# puts res.to_json -# puts "ddddddddd" -# puts res.kind_of?(Net::HTTPRedirection) -# if res.kind_of?(Net::HTTPRedirection) -# url_exist?(res['location']) # Go after any redirect and make sure you can access the redirected URL -# else -# ! %W(4 5).include?(res.code[0]) # Not from 4xx or 5xx families -# end -# rescue Errno::ENOENT -# false #false if can't find the server -# end - - - # def self.search(search) - # where("name LIKE ? OR contact_no LIKE ?", "%#{search}%", "%#{search}%",) - # end - def lastest_invoices sales.where(:customer_id => self.id).order("created_at desc").limit(5) end + def self.count_customer + all = self.all.count+1 + count = all-2 + + end + + WALKIN = "CUS-000000000001" + TAKEAWAY = "CUS-000000000002" + private def generate_custom_id self.customer_id = SeedGenerator.generate_id(self.class.name, "CUS") diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 92bebd59..c31ed341 100644 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -54,10 +54,8 @@ class SalePayment < ApplicationRecord #record an payment in sale-audit remark = "Payment #{payment_method}- for Invoice #{invoice.receipt_no} Due [#{amount_due}]| pay amount -> #{cash_amount} | Payment Status ->#{payment_status}" sale_audit = SaleAudit.record_payment(invoice.id, remark, action_by) - sObj = Sale.find(self.sale_id) - response = rebat(sObj) - return true, response + return true, self.save else #record an payment in sale-audit remark = "No outstanding Amount - Grand Total [#{invoice.grand_total}] | Due [#{amount_due}] | Paid [#{invoice.amount_received}]" diff --git a/app/views/api/customers/index.json.jbuilder b/app/views/api/customers/index.json.jbuilder index 900e6c6b..2c3c07a7 100644 --- a/app/views/api/customers/index.json.jbuilder +++ b/app/views/api/customers/index.json.jbuilder @@ -1 +1,3 @@ -json.array! @customers, :id, :name, :company, :contact_no, :email, :membership_id, :membership_type +json.array! @customers, :id, :name, :company, :contact_no,:salution, + :gender,:nrc_no,:address,:card_no, :membership_type, + :membership_id, :created_at diff --git a/app/views/api/customers/show.json.jbuilder b/app/views/api/customers/show.json.jbuilder index 79397308..db56961b 100644 --- a/app/views/api/customers/show.json.jbuilder +++ b/app/views/api/customers/show.json.jbuilder @@ -1,4 +1,6 @@ -json.extract! @customer, :id, :name, :company, :contact_no, :membership_type, :membership_id, :created_at +json.extract! @customer, :id, :name, :company, :contact_no,:salution, + :gender,:nrc_no,:address,:card_no, :membership_type, + :membership_id, :created_at json.invoices do json.array! @customer.lastest_invoices ,:id, :receipt_no, :receipt_date, :sale_status, :payment_status end diff --git a/app/views/crm/customers/index.html.erb b/app/views/crm/customers/index.html.erb index f97de091..532857f9 100644 --- a/app/views/crm/customers/index.html.erb +++ b/app/views/crm/customers/index.html.erb @@ -34,6 +34,7 @@ Select + Sr.no Name Company Contact no @@ -43,11 +44,13 @@ <% if @crm_customers.count > 0 %> + <% @i = 0 %> <% @crm_customers.each do |crm_customer| %> <% if crm_customer.customer_id != "CUS-000000000001" && crm_customer.customer_id != "CUS-000000000002" %> + <%= @i += 1 %> <%= crm_customer.name %> <%= crm_customer.company rescue '-' %> <%= crm_customer.contact_no %> @@ -75,32 +78,89 @@ <%= f.hidden_field :id, :class => "form-control col-md-6 " %> + +
    +
    + + + + +
    "> - <%= f.input :name, :class => "form-control col-md-6 name" %> + <%= f.input :name, :class => "form-control col-md-6 name", :required => true %> + <% flash.each do |name, msg| %> - <%= msg['name'] %> + <% str="[\"#{msg['name']}\"]" + str.gsub!('["', '') + str.gsub!('"]', '') %> + <%= str %> <% end -%> -
    +
    - <%= f.input :company, :class => "form-control col-md-6 company" %> +
    + + +
    + +
    + <%= f.input :nrc_no, :class => "form-control nrc_no" %> +
    + +
    + <%= f.input :company, :class => "form-control col-md-6 company",:required => true%> + + <% flash.each do |name, msg| %> + <% str="[\"#{msg['company']}\"]" + str.gsub!('["', '') + str.gsub!('"]', '') %> + <%= str %> + <% end -%>
    "> - <%= f.input :contact_no, :class => "form-control col-md-6 contact_no" %> + <%= f.input :contact_no, :class => "form-control col-md-6 contact_no" ,:required => true%> + <% flash.each do |name, msg| %> - <%= msg['contact_no'] %> + <% str="[\"#{msg['contact_no']}\"]" + str.gsub!('["', '') + str.gsub!('"]', '') %> + <%= str %> <% end -%>
    "> - <%= f.input :email, :class => "form-control col-md-6 email" %> + <%= f.input :email, :class => "form-control col-md-6 email" ,:required => true%> <% flash.each do |name, msg| %> - <%= msg['email'] %> + <% str="[\"#{msg['contact_no']}\"]" + str.gsub!('["', '') + str.gsub!('"]', '') %> + <%= str %> <% end -%>
    +
    + <%= f.input :address, :class => "form-control col-md-6 address" %> +
    + +
    + + +
    +
    <%= f.text_field :date_of_birth,:value=>"01-01-1990",:class=>"form-control datepicker"%> @@ -137,12 +197,12 @@ - - - - diff --git a/app/views/origami/home/index.html.erb b/app/views/origami/home/index.html.erb index 4b85d839..e1e530e8 100644 --- a/app/views/origami/home/index.html.erb +++ b/app/views/origami/home/index.html.erb @@ -1,6 +1,6 @@
    -
    +