From 54526230aa8f2cec287380e1fdee779f7be7a6bb Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Thu, 22 Jun 2017 10:25:40 +0630 Subject: [PATCH 01/12] update customerbind in origami --- .../origami/customers_controller.rb | 19 +++++++++++++++++++ config/routes.rb | 2 +- db/seeds.rb | 4 ++-- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/app/controllers/origami/customers_controller.rb b/app/controllers/origami/customers_controller.rb index 601055e5..878571f1 100644 --- a/app/controllers/origami/customers_controller.rb +++ b/app/controllers/origami/customers_controller.rb @@ -39,5 +39,24 @@ class Origami::CustomersController < BaseOrigamiController 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 + end diff --git a/config/routes.rb b/config/routes.rb index 7ec8b9e5..3b647fa9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -112,7 +112,7 @@ Rails.application.routes.draw do #resources :customers get '/:sale_id/customers', to: "customers#add_customer" get '/:customer_id/get_customer' => 'home#get_customer' - post '/:sale_id/update_sale' , to: "home#update_sale_by_customer"#update customer id in sale table + post '/:sale_id/update_sale' , to: "customers#update_sale_by_customer"#update customer id in sale table end #--------- Waiter/Ordering Station ------------# diff --git a/db/seeds.rb b/db/seeds.rb index a646bdad..0e88e336 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -83,8 +83,8 @@ void_reason = Lookup.create([{lookup_type:'void_reason', name: 'Approve By Manag {lookup_type:'void_reason', name: 'Waiter Mistake', value: 'Waiter Mistake'}]) #WALK CUSTOMER - Default CUSTOMER (take key 1) -customer = Customer.create({name:"WALK-IN", email: "cus1@customer.com", contact_no:"000000000"}) -customer2 = Customer.create({name:"TAKEAWAY", email: "cus2@customer.com", contact_no:"111111111"}) +customer = Customer.create({name:"WALK-IN", email: "cus1@customer.com", contact_no:"000000000",card_no:"000"}) +customer2 = Customer.create({name:"TAKEAWAY", email: "cus2@customer.com", contact_no:"111111111",card_no:"000"}) #Default ZOne # zone = Zone.create({id:1, name: "Normal Zone", is_active:true, created_by: "SYSTEM DEFAULT"}) From 187caa5253c63b5a2f02e6a422eee111d46a58df Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Thu, 22 Jun 2017 11:58:16 +0630 Subject: [PATCH 02/12] update customre --- app/assets/stylesheets/origami.scss | 6 ++++++ app/controllers/origami/customers_controller.rb | 13 +++++++++---- app/models/customer.rb | 2 +- app/views/origami/customers/index.html.erb | 2 +- app/views/origami/home/show.html.erb | 2 +- ...ers.rb => 20170622050926_create_customers.rb} | 16 +++++++--------- db/seeds.rb | 2 +- 7 files changed, 26 insertions(+), 17 deletions(-) rename db/migrate/{20170621085729_create_customers.rb => 20170622050926_create_customers.rb} (81%) diff --git a/app/assets/stylesheets/origami.scss b/app/assets/stylesheets/origami.scss index 6b350bf1..30e3781d 100644 --- a/app/assets/stylesheets/origami.scss +++ b/app/assets/stylesheets/origami.scss @@ -179,3 +179,9 @@ select.form-control { tr.discount-item-row:hover { background-color: #e3e3e3 !important; } + +/* Jquery Confirm */ + +.jconfirm-box-container{ + margin-left:-40px !important +} \ No newline at end of file diff --git a/app/controllers/origami/customers_controller.rb b/app/controllers/origami/customers_controller.rb index 878571f1..373dc2f5 100644 --- a/app/controllers/origami/customers_controller.rb +++ b/app/controllers/origami/customers_controller.rb @@ -44,17 +44,22 @@ class Origami::CustomersController < BaseOrigamiController id = params[:sale_id][0,3] if(id == "SAL") sale = Sale.find(params[:sale_id]) + status = sale.update_attributes(customer_id: params[:customer_id]) else - sale = Order.find(params[:sale_id]) - end + @booking = BookingOrder.find_by_order_id(params[:sale_id]) + @orders = BookingOrder.where("booking_id = ? ", @booking.booking_id) - status = sale.update_attributes(customer_id: params[:customer_id]) + @orders.each do |bo| + order = Order.find(bo.order_id) + status = order.update_attributes(customer_id: params[:customer_id]) + end + + end if status == true render json: JSON.generate({:status => true}) else render json: JSON.generate({:status => false, :error_message => "Record not found"}) - end end diff --git a/app/models/customer.rb b/app/models/customer.rb index 4e25c9bc..5debec38 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -6,7 +6,7 @@ class Customer < ApplicationRecord has_many :orders has_many :sales - validates_presence_of :name, :contact_no, :email,:company,:card_no + validates_presence_of :name, :contact_no, :email,:card_no validates :contact_no, uniqueness: true validates :email, uniqueness: true validates :card_no, uniqueness: true diff --git a/app/views/origami/customers/index.html.erb b/app/views/origami/customers/index.html.erb index 3b192319..5539b42b 100644 --- a/app/views/origami/customers/index.html.erb +++ b/app/views/origami/customers/index.html.erb @@ -246,7 +246,7 @@ $('#update_customer').removeAttr('disabled').val(''); $('#update_customer').attr('value', 'Update'); - $('#submit_customer').attr('disabled','disabled'); + // $('#submit_customer').attr('disabled','disabled'); $("#new_customer").attr('class', 'simple_form edit_customer'); var id = "edit_customer_"+$('#customer_id').val(); diff --git a/app/views/origami/home/show.html.erb b/app/views/origami/home/show.html.erb index 22e35765..2719a758 100644 --- a/app/views/origami/home/show.html.erb +++ b/app/views/origami/home/show.html.erb @@ -298,7 +298,7 @@ $(document).ready(function(){ // bind customer to order or sale $("#customer").on('click', function(){ var sale = $('#sale_id').val(); - if (sale!="") { + if (sale) { var sale_id = sale }else{ var sale_id = $('#save_order_id').attr('data-order'); diff --git a/db/migrate/20170621085729_create_customers.rb b/db/migrate/20170622050926_create_customers.rb similarity index 81% rename from db/migrate/20170621085729_create_customers.rb rename to db/migrate/20170622050926_create_customers.rb index 57553010..07ec136f 100644 --- a/db/migrate/20170621085729_create_customers.rb +++ b/db/migrate/20170622050926_create_customers.rb @@ -1,22 +1,20 @@ class CreateCustomers < ActiveRecord::Migration[5.1] def change - create_table :customers, :id => false do |t| + create_table :customers, :id => false do |t| t.string :customer_id, :limit => 16, :primary_key => true #custom foreign_key to prevent conflict during sync t.string :name, :null => false t.string :company - t.string :contact_no, :unique => true t.string :email - t.date :date_of_birth - t.string :membership_id - t.string :membership_type - t.string :membership_authentication_code - t.string :salution + t.string :contact_no, :unique => true + t.date :date_of_birth + t.string :salutation t.string :gender t.string :nrc_no t.string :address t.string :card_no, :unique => true - - t.timestamps + t.string :membership_id + t.string :membership_type + t.string :membership_authentication_code end end end diff --git a/db/seeds.rb b/db/seeds.rb index 0e88e336..21268860 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -84,7 +84,7 @@ void_reason = Lookup.create([{lookup_type:'void_reason', name: 'Approve By Manag #WALK CUSTOMER - Default CUSTOMER (take key 1) customer = Customer.create({name:"WALK-IN", email: "cus1@customer.com", contact_no:"000000000",card_no:"000"}) -customer2 = Customer.create({name:"TAKEAWAY", email: "cus2@customer.com", contact_no:"111111111",card_no:"000"}) +customer2 = Customer.create({name:"TAKEAWAY", email: "cus2@customer.com", contact_no:"111111111",card_no:"111"}) #Default ZOne # zone = Zone.create({id:1, name: "Normal Zone", is_active:true, created_by: "SYSTEM DEFAULT"}) From f8cab803f84c0a3f1fead6b1ae7aa6e4e76dac59 Mon Sep 17 00:00:00 2001 From: Phyo Date: Thu, 22 Jun 2017 13:31:54 +0630 Subject: [PATCH 03/12] Redeem amount bug fic --- .../origami/redeem_payments_controller.rb | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/app/controllers/origami/redeem_payments_controller.rb b/app/controllers/origami/redeem_payments_controller.rb index 792cb7a4..802ba51b 100644 --- a/app/controllers/origami/redeem_payments_controller.rb +++ b/app/controllers/origami/redeem_payments_controller.rb @@ -6,8 +6,24 @@ class Origami::RedeemPaymentsController < BaseOrigamiController sale_data = Sale.find_by_sale_id(@sale_id) # limit redeem_amount - rebate_prices = SaleItem.calculate_food_beverage(sale_data.sale_items) - nonrebate_prices = sale_data.total_amount - rebate_prices + # 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| + # if sale_payment.payment_method == "paypar" + # @payparcount = @payparcount + sale_payment.payment_amount + # else + # others = others + sale_payment.payment_amount + # end + # end + # non_rebate_exceed = others - (nonrebate_prices + sale_data.total_tax) + # if non_rebate_exceed < 0 + # @redeem_prices = rebate_prices - @payparcount + # else + # @redeem_prices = rebate_prices - @payparcount -non_rebate_exceed + # end + @payparcount = 0 others = 0 sale_data.sale_payments.each do |sale_payment| @@ -17,12 +33,8 @@ class Origami::RedeemPaymentsController < BaseOrigamiController others = others + sale_payment.payment_amount end end - non_rebate_exceed = others - (nonrebate_prices + sale_data.total_tax) - if non_rebate_exceed < 0 - @redeem_prices = rebate_prices - @payparcount - else - @redeem_prices = rebate_prices - @payparcount -non_rebate_exceed - end + @redeem_prices = sale_data.grand_total - @payparcount -others + if sale_data if sale_data.customer_id From 3d838bc989b662793a817c02a99b645f77186e67 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Thu, 22 Jun 2017 13:35:20 +0630 Subject: [PATCH 04/12] update report and customer --- app/controllers/crm/customers_controller.rb | 4 +- .../reports/daily_sale_controller.rb | 4 + .../reports/receipt_no_controller.rb | 4 + .../reports/sale_item_controller.rb | 5 + app/views/api/customers/index.json.jbuilder | 2 +- app/views/api/customers/show.json.jbuilder | 2 +- .../crm/customers/_crm_customer.json.jbuilder | 2 +- app/views/crm/customers/index.html.erb | 8 +- app/views/crm/customers/show.json.jbuilder | 3 +- app/views/origami/customers/index.html.erb | 8 +- app/views/reports/sale_item/index.xls.erb | 246 ++++++++++-------- config/initializers/mime_types.rb | 1 + 12 files changed, 161 insertions(+), 128 deletions(-) diff --git a/app/controllers/crm/customers_controller.rb b/app/controllers/crm/customers_controller.rb index 646f6475..ce585686 100644 --- a/app/controllers/crm/customers_controller.rb +++ b/app/controllers/crm/customers_controller.rb @@ -46,7 +46,7 @@ class Crm::CustomersController < BaseCrmController end #get customer amount - @customer = Customer.find(params[:id]) + @customer = Customer.find(params[:id]) @response = Customer.get_membership_transactions(@customer) #end customer amount @@ -201,6 +201,6 @@ end def customer_params params.require(:customer).permit(:name, :company, :contact_no, :email, - :date_of_birth,:salution,:gender,:nrc_no,:address,:card_no) + :date_of_birth,:salutation,:gender,:nrc_no,:address,:card_no) end end diff --git a/app/controllers/reports/daily_sale_controller.rb b/app/controllers/reports/daily_sale_controller.rb index 6e1eb85a..ba453f55 100644 --- a/app/controllers/reports/daily_sale_controller.rb +++ b/app/controllers/reports/daily_sale_controller.rb @@ -4,6 +4,10 @@ class Reports::DailySaleController < BaseReportController from, to ,report_type = get_date_range_from_params @sale_data = Sale.daily_sales_list(from,to) @tax = SaleTax.get_tax(from,to) + respond_to do |format| + format.html + format.xls + end end def show diff --git a/app/controllers/reports/receipt_no_controller.rb b/app/controllers/reports/receipt_no_controller.rb index 86c8d981..d85c7d57 100644 --- a/app/controllers/reports/receipt_no_controller.rb +++ b/app/controllers/reports/receipt_no_controller.rb @@ -8,6 +8,10 @@ class Reports::ReceiptNoController < BaseReportController puts to @sale_data = Sale.get_receipt_no_list(from,to) @sale_data = Kaminari.paginate_array(@sale_data).page(params[:page]).per(50) + respond_to do |format| + format.html + format.xls + end end def show diff --git a/app/controllers/reports/sale_item_controller.rb b/app/controllers/reports/sale_item_controller.rb index 1da31aff..eb7d3b86 100644 --- a/app/controllers/reports/sale_item_controller.rb +++ b/app/controllers/reports/sale_item_controller.rb @@ -5,6 +5,11 @@ class Reports::SaleItemController < BaseReportController 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) + + respond_to do |format| + format.html + format.xls + end end def show diff --git a/app/views/api/customers/index.json.jbuilder b/app/views/api/customers/index.json.jbuilder index 2c3c07a7..0d1d37e7 100644 --- a/app/views/api/customers/index.json.jbuilder +++ b/app/views/api/customers/index.json.jbuilder @@ -1,3 +1,3 @@ -json.array! @customers, :id, :name, :company, :contact_no,:salution, +json.array! @customers, :id, :name, :company, :contact_no,:salutation, :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 db56961b..acf54ac1 100644 --- a/app/views/api/customers/show.json.jbuilder +++ b/app/views/api/customers/show.json.jbuilder @@ -1,4 +1,4 @@ -json.extract! @customer, :id, :name, :company, :contact_no,:salution, +json.extract! @customer, :id, :name, :company, :contact_no,:salutation, :gender,:nrc_no,:address,:card_no, :membership_type, :membership_id, :created_at json.invoices do diff --git a/app/views/crm/customers/_crm_customer.json.jbuilder b/app/views/crm/customers/_crm_customer.json.jbuilder index c80c1716..1b1b237e 100644 --- a/app/views/crm/customers/_crm_customer.json.jbuilder +++ b/app/views/crm/customers/_crm_customer.json.jbuilder @@ -1,2 +1,2 @@ -json.extract! crm_customer, :id, :name, :company, :contact_no, :email, :date_of_birth, :membership_id, :membership_type, :membership_authentication_code, :created_at, :updated_at +json.extract! crm_customer, :id, :name, :company, :contact_no, :email, :date_of_birth, :membership_id, :membership_type, :membership_authentication_code, :created_at, :updated_at,:salutation, :gender,:nrc_no,:address,:card_no json.url crm_customer_url(crm_customer, format: :json) diff --git a/app/views/crm/customers/index.html.erb b/app/views/crm/customers/index.html.erb index e7b47460..3678008e 100644 --- a/app/views/crm/customers/index.html.erb +++ b/app/views/crm/customers/index.html.erb @@ -120,7 +120,7 @@ $(document).on('click',".customer_tr",function(){ $('#customer_company').val(data.company); $('#customer_contact_no').val(data.contact_no); $('#customer_email').val(data.email); - $('#customer_salution').val(data.salution); + $('#customer_salutation').val(data.salutation); $('#customer_nrc_no').val(data.nrc_no); $('#customer_card_no').val(data.card_no); $('#customer_address').val(data.address); @@ -133,11 +133,11 @@ $(document).on('click',".customer_tr",function(){ $('.female').prop( "checked", true ) } - if(data.salution == 'Mr') { + if(data.salutation == 'Mr') { $('.mr').prop( "checked", true ) - }else if(data.salution == 'Miss') { + }else if(data.salutation == 'Miss') { $('.miss').prop( "checked", true ) - }else if(data.salution == 'Mrs'){ + }else if(data.salutation == 'Mrs'){ $('.mrs').prop( "checked", true ) }else{ $('.mdm').prop( "checked", true ) diff --git a/app/views/crm/customers/show.json.jbuilder b/app/views/crm/customers/show.json.jbuilder index d41edb5d..86901801 100644 --- a/app/views/crm/customers/show.json.jbuilder +++ b/app/views/crm/customers/show.json.jbuilder @@ -1,5 +1,4 @@ json.extract! @crm_customer, :id, :name, :company, :contact_no, :email, :date_of_birth, :membership_id, :membership_type, :membership_authentication_code, - :created_at, :updated_at, - :salution, :gender,:nrc_no,:address,:card_no + :salutation, :gender,:nrc_no,:address,:card_no json.url crm_customer_url(@crm_customer, format: :json) diff --git a/app/views/origami/customers/index.html.erb b/app/views/origami/customers/index.html.erb index 5539b42b..8a811073 100644 --- a/app/views/origami/customers/index.html.erb +++ b/app/views/origami/customers/index.html.erb @@ -225,7 +225,7 @@ $('.select > option[value="'+data.membership_id+'"]').attr('selected','selected'); $('.membership_authentication_code').val(data.membership_authentication_code); - $('#customer_salution').val(data.salution); + $('#customer_salutation').val(data.salutation); $('#customer_nrc_no').val(data.nrc_no); if (data.gender == 'Male') { @@ -234,11 +234,11 @@ $('.female').prop( "checked", true ) } - if (data.salution == 'Mr') { + if (data.salutation == 'Mr') { $('.mr').prop( "checked", true ) - } else if(data.salution == 'Miss') { + } else if(data.salutation == 'Miss') { $('.miss').prop( "checked", true ) - }else if(data.salution == 'Mrs'){ + }else if(data.salutation == 'Mrs'){ $('.mrs').prop( "checked", true ) }else{ $('.mdm').prop( "checked", true ) diff --git a/app/views/reports/sale_item/index.xls.erb b/app/views/reports/sale_item/index.xls.erb index dfcc18d4..2807ec3f 100644 --- a/app/views/reports/sale_item/index.xls.erb +++ b/app/views/reports/sale_item/index.xls.erb @@ -1,116 +1,136 @@ -
-
- - - <% 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 %> + + + + + + + +
+<% unless @sale_data.blank? %> -
- - - - - - - - - - - - - - +
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 '-'%>
+ - <% total_tax = 0 %> - <% unless @tax.empty? %> - <% @tax.each do |tax| %> - <% total_tax += tax.tax_amount.to_f %> - - - - - - - <% end %> - <% net = total - total_tax %> - - - - - - <% end %> - + <% if !params[:from].blank?%> + + + + <% end %> + <% if @shift_from %> + + <% if @shift_data.employee %> + <% cashier_name = !@shift_data.nil? ? @shift_data.employee.name : '-' %> + <% end %> + + + <% end %> + + + + + + + + + + + + + <% acc_arr = Array.new %> + <% cate_arr = Array.new %> + + <% sub_total = 0.0 %> + <% count = 0%> + <% total_price = 0.0 %> + <% cate_count = 0 %> + <% acc_count = 0%> + <% grand_total = 0%> + <% total_discount = 0.0 %> + + <% @sale_data.order("total_item desc").each do |sale| %> + + <% if !acc_arr.include?(sale.account_id) %> + + + + + + + <% acc_arr.push(sale.account_id) %> + + <% end %> + + + <% if !cate_arr.include?(sale.menu_category_id) %> + + <% cate_arr.push(sale.menu_category_id) %> + <% else %> + <% end %> -
<%= tax.tax_name rescue '-'%><%= number_with_delimiter(sprintf("%.2f",tax.tax_amount), :delimiter => ',') rescue '-'%> 
Net Amount<%= number_with_delimiter(sprintf("%.2f",net), :delimiter => ',') rescue '-'%> 
From Date : <%= params[:from] %> , To Date : <%= params[:to] %>
Shift Name = <%= @shift_from %> - <%= @shift_to %> ( <%= cashier_name %> )
 Menu CategoryCodeProductTotal ItemUnit PriceRevenue
<%= sale.account_name %> Total Price By <%= sale.account_name %> + <% @totalByAccount.each do |account, total| %> + <% if sale.account_id == account %> + <%= total %> + <% end %> + <% end %> +
 <%= sale.menu_category_name %> 
-
-
\ No newline at end of file + <%= sale.code rescue '-' %> + <% if @item_table == 'sale' %> + <% if sale.item_remark == 'FOC' %> + <%= '[PROMO] '.to_s + sale.product_name.to_s rescue '-' %> + <% elsif sale.item_remark == 'FOC ITEM' %> + <%= '[DIS:QTY] '.to_s + sale.product_name.to_s rescue '-' %> + <% elsif sale.item_remark == 'DISCOUNT' %> + <%= '[DIS:TP] '.to_s + sale.product_name.to_s rescue '-' %> + <% else %> + <%= sale.product_name.to_s rescue '-' %> + <% end %> + <% if sale.item_remark == 'DISCOUNT' %> + - + - + <%= sale.total_price.abs rescue '-' %> + <% total_price += sale.total_price %> + <% else %> + <%= sale.total_item.abs rescue '-' %> + <%= sale.unit_price rescue '-' %> + <%= sale.grand_total.abs rescue '-' %> + <% end %> + <% else %> + <%= sale.product_name.to_s rescue '-' %> + <%= sale.total_item.abs rescue '-' %> + <%= sale.unit_price rescue '-' %> + <%= sale.grand_total.abs rescue '-' %> + <% end %> + + + + <% @menu_cate_count.each do |key,value| %> + <% if sale.menu_category_id == key %> + <% count = count + 1 %> + <% sub_total += sale.grand_total %> + <% if count == value %> + +   + Sub Total + <%= sub_total + total_price %> + + <% sub_total = 0.0%> + <% total_discount = total_discount + total_price %> + <% total_price = 0.0%> + <% count = 0%> + <% end %> + <% end %> + <% end %> + + <% grand_total += sale.grand_total%> + <% end %> + +   + Grand Total + <%= grand_total + total_discount %> + + + +<% end %> + + + \ No newline at end of file diff --git a/config/initializers/mime_types.rb b/config/initializers/mime_types.rb index dc189968..3859c754 100644 --- a/config/initializers/mime_types.rb +++ b/config/initializers/mime_types.rb @@ -2,3 +2,4 @@ # Add new mime types for use in respond_to blocks: # Mime::Type.register "text/richtext", :rtf +Mime::Type.register 'application/vnd.ms-excel', :xls From 0ea2b778d18314646fc4a3ba0b208cc7709a1e4c Mon Sep 17 00:00:00 2001 From: Nweni Date: Thu, 22 Jun 2017 14:26:23 +0630 Subject: [PATCH 05/12] multiple sale and order --- app/controllers/api/orders_controller.rb | 83 ++++++++----------- app/controllers/origami/home_controller.rb | 10 +-- app/controllers/origami/orders_controller.rb | 2 +- app/controllers/origami/rooms_controller.rb | 2 +- app/controllers/origami/sales_controller.rb | 36 +++++++- app/models/booking.rb | 1 + app/models/dining_facility.rb | 11 +++ app/models/sale_payment.rb | 2 + app/views/origami/home/show.html.erb | 41 ++++++--- .../origami/movetable/move_dining.html.erb | 2 +- app/views/origami/payments/show.html.erb | 14 +++- .../add_to_existing_invoice.json.jbuilder | 1 + config/routes.rb | 1 + 13 files changed, 134 insertions(+), 72 deletions(-) create mode 100644 app/views/origami/sales/add_to_existing_invoice.json.jbuilder diff --git a/app/controllers/api/orders_controller.rb b/app/controllers/api/orders_controller.rb index b42de7c5..1eba8c56 100644 --- a/app/controllers/api/orders_controller.rb +++ b/app/controllers/api/orders_controller.rb @@ -22,27 +22,19 @@ class Api::OrdersController < Api::ApiController if booking if booking.dining_facility_id.to_i == table_id.to_i - @booking = booking + if booking.booking_status == 'assign' + if booking.sale_id.nil? + @booking = booking + end + end else table = DiningFacility.find(table_id) - booking = table.get_current_booking - if booking - if booking.dining_facility_id.to_i == table_id.to_i - @booking = booking - end - end + @booking = table.get_booking end end else - puts "only table" table = DiningFacility.find(table_id) - booking = table.get_current_booking - puts booking - if booking - if booking.dining_facility_id.to_i == table_id.to_i - @booking = booking - end - end + @booking = table.get_booking end end @@ -73,54 +65,47 @@ class Api::OrdersController < Api::ApiController # check booking id is already completed. booking = Booking.find(params[:booking_id]) if booking - if booking.dining_facility_id.to_i == params[:table_id].to_i + if booking.dining_facility_id.to_i == params[:table_id].to_i && booking.booking_status != 'moved' if !booking.sale_id.nil? - if booking.sale.sale_status == "completed" || booking.sale.sale_status == "billed" - @order.new_booking = true - else - @order.new_booking = false - @order.booking_id = params[:booking_id] - end + check_order_with_booking(booking) else @order.new_booking = false @order.booking_id = params[:booking_id] - puts "booking sale is null" end else - # booking.table id not equal current table - table = DiningFacility.find(params[:table_id]) - if table - booking = table.get_current_booking - if booking - if booking.sale.sale_status == "completed" || booking.sale.sale_status == "billed" - @order.new_booking = true - else - @order.new_booking = false - @order.booking_id = booking.booking_id - end - end - end + check_order_with_table(params[:table_id]) end end #booking exists else - #no booking id - table = DiningFacility.find(params[:table_id]) - if table - booking = table.get_current_booking - if booking - if booking.sale.sale_status == "completed" || booking.sale.sale_status == "billed" - @order.new_booking = true - else - @order.new_booking = false - @order.booking_id = booking.booking_id - end - end + check_order_with_table(params[:table_id]) end - end @status, @booking = @order.generate end + def check_order_with_table(table_id) + table = DiningFacility.find(table_id) + if table + booking = table.get_current_booking + if booking + if booking.sale.sale_status == "completed" || booking.sale.sale_status == "billed" + @order.new_booking = true + else + @order.new_booking = false + @order.booking_id = booking.booking_id + end + end + end + end + + def check_order_with_booking(booking) + if booking.sale.sale_status == "completed" || booking.sale.sale_status == "billed" + @order.new_booking = true + else + @order.new_booking = false + @order.booking_id = params[:booking_id] + end + end # Description # This API - allow order to add new items to existing orders, does not allow you to remove confirm items # Update customer info, Guest Info diff --git a/app/controllers/origami/home_controller.rb b/app/controllers/origami/home_controller.rb index 4c35a918..a8560eee 100644 --- a/app/controllers/origami/home_controller.rb +++ b/app/controllers/origami/home_controller.rb @@ -4,7 +4,7 @@ class Origami::HomeController < BaseOrigamiController def index @tables = Table.all.active.order('status desc') @rooms = Room.all.active.order('status desc') - @complete = Sale.complete_sale + @complete = Sale.all @orders = Order.all.order('date desc') end @@ -12,13 +12,13 @@ class Origami::HomeController < BaseOrigamiController def show @tables = Table.all.active.order('status desc') @rooms = Room.all.active.order('status desc') - @complete = Sale.complete_sale + @complete = Sale.all @orders = Order.all.order('date desc') @status_order = "" @status_sale = "" @sale_array = Array.new - @dining.bookings.each do |booking| - if booking.sale_id.nil? + @dining.bookings.active.each do |booking| + if booking.sale_id.nil? && booking.booking_status != 'moved' @order_items = Array.new booking.booking_orders.each do |booking_order| @@ -42,7 +42,7 @@ class Origami::HomeController < BaseOrigamiController @obj_sale = sale end end - end + end end private diff --git a/app/controllers/origami/orders_controller.rb b/app/controllers/origami/orders_controller.rb index e5eb2808..cc5fac3f 100644 --- a/app/controllers/origami/orders_controller.rb +++ b/app/controllers/origami/orders_controller.rb @@ -3,7 +3,7 @@ class Origami::OrdersController < BaseOrigamiController def show @tables = Table.all.active.order('status desc') @rooms = Room.all.active.order('status desc') - @complete = Sale.complete_sale + @complete = Sale.all @orders = Order.all.order('status desc') @order = Order.find(params[:order_id]) sale_order = SaleOrder.find_by_order_id(@order.order_id) diff --git a/app/controllers/origami/rooms_controller.rb b/app/controllers/origami/rooms_controller.rb index 56030d4f..1ac7f41a 100644 --- a/app/controllers/origami/rooms_controller.rb +++ b/app/controllers/origami/rooms_controller.rb @@ -3,7 +3,7 @@ class Origami::RoomsController < BaseOrigamiController def show @tables = Table.all.active.order('status desc') @rooms = Room.all.active.order('status desc') - @complete = Sale.complete_sale + @complete = Sale.all @orders = Order.all.order('date desc') @room = DiningFacility.find(params[:room_id]) @room.bookings.each do |booking| diff --git a/app/controllers/origami/sales_controller.rb b/app/controllers/origami/sales_controller.rb index b5200114..e272c1ee 100644 --- a/app/controllers/origami/sales_controller.rb +++ b/app/controllers/origami/sales_controller.rb @@ -3,8 +3,42 @@ class Origami::SalesController < BaseOrigamiController def show @tables = Table.all.active.order('status desc') @rooms = Room.all.active.order('status desc') - @complete = Sale.complete_sale + @complete = Sale.all @orders = Order.all.order('date desc') @sale = Sale.find(params[:sale_id]) end + + def add_to_existing_invoice + dining = params[:dining_id] + sale_id = params[:sale_id] + table = DiningFacility.find(dining) + table.bookings.each do |booking| + if booking.sale_id.nil? + booking.booking_orders.each do |booking_order| + booking.booking_status = 'moved' + order = Order.find(booking_order.order_id) + order.status = 'billed' + order.order_items.each do |item| + item.order_item_status = 'billed' + end + # create sale item + saleobj = Sale.find(sale_id) + order.order_items.each do |orer_item| + saleobj.add_item (orer_item) + end + saleobj.save + order.save + booking.save + end + existing_booking = Booking.find_by_sale_id(sale_id) + booking_order = BookingOrder.where('booking_id=?',booking) + booking_order.each do |bo| + bo.booking_id = existing_booking.booking_id + bo.save + end + end + end + end + + end diff --git a/app/models/booking.rb b/app/models/booking.rb index 79fbad4a..b7c6667a 100644 --- a/app/models/booking.rb +++ b/app/models/booking.rb @@ -9,6 +9,7 @@ class Booking < ApplicationRecord belongs_to :sale, :optional => true has_many :booking_orders has_many :orders, :through => :booking_orders + scope :active, -> {where("booking_status != 'moved'")} def self.update_dining_facility(booking_arr, newd, old) booking_arr.each do |booking| diff --git a/app/models/dining_facility.rb b/app/models/dining_facility.rb index abf39d7a..0e10307b 100644 --- a/app/models/dining_facility.rb +++ b/app/models/dining_facility.rb @@ -18,6 +18,17 @@ class DiningFacility < ApplicationRecord self.save end + def get_booking + booking = self.get_current_booking + if booking + if booking.dining_facility_id.to_i == self.id + if booking.booking_status == 'assign' + return booking + end + end + end + end + def get_current_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) diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index e827113c..4974c856 100644 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -244,9 +244,11 @@ class SalePayment < ApplicationRecord table = DiningFacility.find(booking.dining_facility_id) bookings = table.bookings bookings.each do |tablebooking| + if tablebooking.booking_status != 'moved' if tablebooking.sale.sale_status != 'completed' status = false end + end end if status table.status = "available" diff --git a/app/views/origami/home/show.html.erb b/app/views/origami/home/show.html.erb index b6398686..8ff59b45 100644 --- a/app/views/origami/home/show.html.erb +++ b/app/views/origami/home/show.html.erb @@ -137,7 +137,6 @@ count = 0 sub_total = 0 if @status_sale == "sale" - puts @sale_array[0] @sale_array[0].sale_items.each do |sale_item| count += 1 sub_total = sub_total + sale_item.price @@ -159,8 +158,6 @@ unless @order_items.nil? count = 0 @order_items.each do |order_item | - puts @order_items.size - puts "view" count += 1 sub_total = sub_total + order_item.price @@ -212,10 +209,13 @@ Pending New Order <% + count = 0 @order_items.each do |order_item | + count += 1 %> + @@ -225,14 +225,15 @@ end %>
<%= count %> <%= order_item.item_name %> <%= order_item.qty %> <%= order_item.qty*order_item.price %>
- + <% - else + end @sale_array.each do |sale| if @sale_array.size > 1 unless sale.receipt_no == @sale_array[0].receipt_no %> - Pending New Invoice +

+ Pending Payment @@ -240,7 +241,6 @@
Receipt No - <%= sale.receipt_no %>
<% - end end end end @@ -258,17 +258,23 @@ <% if @dining.bookings.length >= 1 %> - + - <% if @status_order == 'order' %> + + <% if @status_order == 'order' && @status_sale != 'sale' %> + + <% else %> + + + <% end %> - + <% end %> @@ -319,4 +325,19 @@ $('#move').on('click',function(){ $('#back').on('click',function(){ window.location.href = '/origami/'; }) + +$('#add_invoice').on('click',function(){ + var dining_id = "<%= @dining.id %>" + var sale_id = "<%= @obj_sale.sale_id rescue "" %>" + var ajax_url = "/origami/sale/append_order"; + $.ajax({ + type: "POST", + url: ajax_url, + data: 'dining_id='+ dining_id + "&sale_id=" + sale_id, + success:function(result){ + alert("Invoice updated") + window.location.reload(); + } + }); +}) diff --git a/app/views/origami/movetable/move_dining.html.erb b/app/views/origami/movetable/move_dining.html.erb index 83419ca0..fd2e78cb 100644 --- a/app/views/origami/movetable/move_dining.html.erb +++ b/app/views/origami/movetable/move_dining.html.erb @@ -180,7 +180,7 @@ if @sale_array.size > 1 unless sale.receipt_no == @sale_array[0].receipt_no %> - Pending New Invoice + Pending Payment diff --git a/app/views/origami/payments/show.html.erb b/app/views/origami/payments/show.html.erb index fe36277b..923e3eef 100644 --- a/app/views/origami/payments/show.html.erb +++ b/app/views/origami/payments/show.html.erb @@ -24,7 +24,8 @@
Receipt No - <%= sale.receipt_no %>
- + + @@ -34,10 +35,16 @@
Items#Items QTY Price
- <% sub_total = 0 %> - <% @sale_data.sale_items.each do |sale_item| %> + <% sub_total = 0 + count = 0 + %> + <% @sale_data.sale_items.each do |sale_item| + count += 1 + %> + <% sub_total += sale_item.qty*sale_item.unit_price%> + @@ -236,7 +243,6 @@ - diff --git a/app/views/origami/sales/add_to_existing_invoice.json.jbuilder b/app/views/origami/sales/add_to_existing_invoice.json.jbuilder new file mode 100644 index 00000000..08bf292c --- /dev/null +++ b/app/views/origami/sales/add_to_existing_invoice.json.jbuilder @@ -0,0 +1 @@ +json.status true diff --git a/config/routes.rb b/config/routes.rb index dd5831ae..3da4e9a1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -80,6 +80,7 @@ Rails.application.routes.draw do get 'table/:dining_id/movetable' => "movetable#move_dining" get 'table/:dining_id/moveroom' => "moveroom#move_dining" get 'sale/:sale_id' => 'sales#show' + post 'sale/append_order' => 'sales#add_to_existing_invoice' get 'room/:room_id' => 'rooms#show' get 'order/:order_id' => "orders#show" From cd5fdaac6a716dcedb05a94f61faa9553b198df6 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Thu, 22 Jun 2017 15:28:40 +0630 Subject: [PATCH 06/12] update origami scss --- app/assets/stylesheets/origami.scss | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/assets/stylesheets/origami.scss b/app/assets/stylesheets/origami.scss index 30e3781d..2670dcc4 100644 --- a/app/assets/stylesheets/origami.scss +++ b/app/assets/stylesheets/origami.scss @@ -179,7 +179,9 @@ select.form-control { tr.discount-item-row:hover { background-color: #e3e3e3 !important; } - +.required abbr{ + color: red !important; +} /* Jquery Confirm */ .jconfirm-box-container{ From 4b9291110d63049e799852a7a648c3059efed1fc Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Thu, 22 Jun 2017 15:30:16 +0630 Subject: [PATCH 07/12] update origami customer --- app/views/origami/customers/index.html.erb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/views/origami/customers/index.html.erb b/app/views/origami/customers/index.html.erb index 8a811073..e862ea7f 100644 --- a/app/views/origami/customers/index.html.erb +++ b/app/views/origami/customers/index.html.erb @@ -75,7 +75,15 @@ <%= f.error_notification %> <%= f.hidden_field :id, :class => "form-control col-md-6 " %> - +
"> + <%= f.input :card_no, :class => "form-control col-md-6 card_no"%> + <% flash.each do |name, msg| %> + <% str="[\"#{msg['name']}\"]" + str.gsub!('["', '') + str.gsub!('"]', '') %> + <%= str %> + <% end -%> +

@@ -155,7 +155,7 @@ @order_items.each do |order_item | sub_total = sub_total + order_item.price - unless order_item.price <= 0 %> + unless order_item.price == 0 %> @@ -259,15 +259,65 @@ $(document).ready(function(){ var order_id = $(this).attr("data-id"); window.location.href = '/origami/order/' + order_id; }) + + // bind customer to order or sale + $("#customer").on('click', function(){ + var sale = $('#sale_id').val(); + if (sale) { + var sale_id = sale + }else{ + var sale_id = $('#save_order_id').attr('data-order'); + } + + window.location.href = '/origami/'+ sale_id + "/customers" + }); + + // Discount for Payment + $('#discount').click(function() { + var sale = $('#sale_id').val(); + if (sale!="") { + var sale_id = sale + }else{ + var sale_id = $('#save_order_id').attr('data-order'); + } + + if(sale_id!=""){ + window.location.href = '/origami/' + sale_id + '/discount' + } + else { + alert("Please select an table!"); + } + + return false; + }); }); + + $('#pay').on('click',function() { var sale_id = $('#sale_id').val(); window.location.href = '/origami/sale/'+ sale_id + "/payment"; }); + +// Bill Request +$('#request_bills').click(function() { + var order_id = $('#save_order_id').attr('data-order'); + var ajax_url = "/origami/" + order_id + "/request_bills"; + $.ajax({ + type: "POST", + url: ajax_url, + data: 'order_id='+ order_id, + success:function(result){ + + location.reload(); + } + }); +}); + $('#move').on('click',function(){ var dining_id = "<%= @room.id %>" window.location.href = '/origami/table/'+ dining_id + "/moveroom"; }) + $('#back').on('click',function(){ window.location.href = '/origami/'; }) From a90bbbebec6e96242dea7313cc49c411e1ea60b7 Mon Sep 17 00:00:00 2001 From: Yan Date: Thu, 22 Jun 2017 18:06:56 +0630 Subject: [PATCH 12/12] merge with origin master --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 227cfa72..22275707 100644 --- a/Gemfile +++ b/Gemfile @@ -12,7 +12,7 @@ gem 'rails', '~> 5.1.0' gem 'mysql2', '>= 0.3.18', '< 0.5' #Use PosgreSQL -gem 'pg' +# gem 'pg' # redis server for cable # gem 'redis', '~> 3.0'
<%= count %> <%=sale_item.product_name%>@<%=sale_item.unit_price%>
<%= sale_item.product_name %> <%= sale_item.qty %>
<%= order_item.item_name %> <%= order_item.qty %>