From 8046bc7745cf255a4112e0d4963402765f978869 Mon Sep 17 00:00:00 2001 From: Nweni Date: Thu, 29 Jun 2017 18:59:17 +0630 Subject: [PATCH 1/7] shift --- .../origami/cash_ins_controller.rb | 3 ++ .../origami/cash_outs_controller.rb | 3 ++ app/controllers/origami/shifts_controller.rb | 5 +- app/models/payment_journal.rb | 21 ++++++++ app/models/sale.rb | 36 +++++++++++-- app/models/sale_payment.rb | 22 ++++---- app/models/shift_sale.rb | 11 ++-- app/views/origami/shifts/new.html.erb | 33 ++++++++++++ app/views/origami/shifts/show.html.erb | 54 ++----------------- 9 files changed, 119 insertions(+), 69 deletions(-) diff --git a/app/controllers/origami/cash_ins_controller.rb b/app/controllers/origami/cash_ins_controller.rb index dd78bc1b..085f68b8 100644 --- a/app/controllers/origami/cash_ins_controller.rb +++ b/app/controllers/origami/cash_ins_controller.rb @@ -11,5 +11,8 @@ class Origami::CashInsController < BaseOrigamiController payment_method_reference = params[:payment_method_reference] p_jour = PaymentJournal.new p_jour.cash_in(reference, remark, amount, payment_method, payment_method_reference, current_user.id) + shift = ShiftSale.current_open_shift(current_user.id) + shift.cash_in = shift.cash_in + amount.to_i + shift.save end end diff --git a/app/controllers/origami/cash_outs_controller.rb b/app/controllers/origami/cash_outs_controller.rb index ac079a39..95ab97a2 100644 --- a/app/controllers/origami/cash_outs_controller.rb +++ b/app/controllers/origami/cash_outs_controller.rb @@ -9,5 +9,8 @@ class Origami::CashOutsController < BaseOrigamiController amount = params[:amount] p_jour = PaymentJournal.new p_jour.cash_out(reference, remark, amount, current_user.id) + shift = ShiftSale.current_open_shift(current_user.id) + shift.cash_out = shift.cash_out + amount.to_i + shift.save end end diff --git a/app/controllers/origami/shifts_controller.rb b/app/controllers/origami/shifts_controller.rb index 1a7a5289..cd607b42 100644 --- a/app/controllers/origami/shifts_controller.rb +++ b/app/controllers/origami/shifts_controller.rb @@ -18,9 +18,12 @@ class Origami::ShiftsController < BaseOrigamiController end def update_shift - @shift = ShiftSale.current_open_shift(current_user.id) + closing_balance = params[:closing_balance] + shift_id = params[:shift_id] + @shift = ShiftSale.find_by_id(shift_id) if @shift @shift.shift_closed_at = DateTime.now.utc + @shift.closing_balance = closing_balance.to_f @shift.save end end diff --git a/app/models/payment_journal.rb b/app/models/payment_journal.rb index 6105a574..0f0c3ce5 100644 --- a/app/models/payment_journal.rb +++ b/app/models/payment_journal.rb @@ -19,4 +19,25 @@ class PaymentJournal < ApplicationRecord self.created_by = current_user self.save end + + # def self.today_cash_in(current_user) + # credit = 0.0 + # today_date = DateTime.now.strftime("%Y-%m-%d") + # pj_credit = PaymentJournal.where("TO_CHAR(created_at, 'YYYY-MM-DD')=? and created_by=?",today_date, current_user) + # pj_credit.each do |obj| + # credit += obj.credit_amount + # end + # return credit + # end + # + # def self.today_cash_out(current_user) + # debit = 0.0 + # today_date = DateTime.now.strftime("%Y-%m-%d") + # pj_debit = PaymentJournal.where("TO_CHAR(created_at, 'YYYY-MM-DD')=? and created_by=?",today_date, current_user) + # pj_debit.each do |obj| + # debit += obj.debit_amount + # end + # return debit + # end + end diff --git a/app/models/sale.rb b/app/models/sale.rb index bf3bc216..12a88048 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -25,7 +25,7 @@ class Sale < ApplicationRecord SALE_STATUS_OUTSTANDING = "outstanding" SALE_STATUS_COMPLETED = "completed" - def generate_invoice_from_booking(booking_id, requested_by, cashier) + def generate_invoice_from_booking(booking_id, requested_by, cashier) booking = Booking.find(booking_id) status = false Rails.logger.debug "Booking -> " + booking.id.to_s @@ -66,7 +66,7 @@ class Sale < ApplicationRecord #Default Tax - Values self.tax_type = "exclusive" - # set cashier + # set cashier if cashier != nil self.cashier_id = cashier[0].id self.cashier_name = cashier[0].name @@ -270,8 +270,6 @@ class Sale < ApplicationRecord end - private - def product_get_unit_price(item_code) menu_item_hash =MenuItem.search_by_item_code(item_code) if (menu_instance_code) @@ -409,6 +407,36 @@ def self.get_by_range_by_saleitems(from,to,status,report_type) end + def get_cash_amount + cash = 0.0 + self.sale_payments.each do |pay| + if pay.payment_method == 'cash' + cash = pay.payment_amount + end + end + return cash + end + + def get_credit_amount + credit = 0.0 + self.sale_payments.each do |pay| + if pay.payment_method == 'creditnote' + credit = pay.payment_amount + end + end + return credit + end + + def get_other_amount + other = 0.0 + self.sale_payments.each do |pay| + if pay.payment_method != 'cash' && pay.payment_method != 'creditnote' + other += pay.payment_amount + end + end + return other + end + private def generate_custom_id diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 7a835618..feafd017 100644 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -131,7 +131,6 @@ class SalePayment < ApplicationRecord self.payment_status = "paid" payment_method = self.save! sale_update_payment_status(self.received_amount) - return payment_status end @@ -146,7 +145,6 @@ class SalePayment < ApplicationRecord payment_method = self.save! sale_update_payment_status(self.received_amount) - return payment_status end @@ -161,7 +159,6 @@ class SalePayment < ApplicationRecord payment_method = self.save! sale_update_payment_status(self.received_amount) - return payment_status end @@ -175,7 +172,6 @@ class SalePayment < ApplicationRecord self.outstanding_amount = self.sale.grand_total- self.received_amount self.payment_status = "paid" payment_method = self.save! - sale_update_payment_status(self.received_amount) return payment_status @@ -192,7 +188,6 @@ class SalePayment < ApplicationRecord self.outstanding_amount = self.sale.grand_total- self.received_amount self.payment_status = "paid" payment_method = self.save! - sale_update_payment_status(self.received_amount) return payment_status @@ -220,7 +215,6 @@ class SalePayment < ApplicationRecord else sale_update_payment_status(0) end - return payment_status end @@ -249,16 +243,20 @@ class SalePayment < ApplicationRecord self.sale.save! table_update_status(sObj) rebat(sObj) - shift = ShiftSale.current_open_shift(self.sale.cashier_id) - puts shift - if !shift.nil? - puts ">>>> shift >>>>>>" - shift.update(self.sale) + if paid_amount != "0.0" + update_shift end end end + def update_shift + shift = ShiftSale.current_open_shift(self.sale.cashier_id) + if !shift.nil? + shift.update(self.sale) + end + end + def table_update_status(sale_obj) status = true booking = Booking.find_by_sale_id(sale_obj.id) @@ -321,6 +319,8 @@ class SalePayment < ApplicationRecord end end + + private def generate_custom_id self.sale_payment_id = SeedGenerator.generate_id(self.class.name, "SPI") diff --git a/app/models/shift_sale.rb b/app/models/shift_sale.rb index ee6885ae..420a700f 100644 --- a/app/models/shift_sale.rb +++ b/app/models/shift_sale.rb @@ -37,14 +37,17 @@ class ShiftSale < ApplicationRecord def update(sale) saleobj = Sale.find_by_sale_id(sale) - self.total_revenue = self.total_revenue + saleobj.total_amount + cash = saleobj.get_cash_amount + credit = saleobj.get_credit_amount + other_sales = saleobj.get_other_amount + self.total_revenue = self.total_revenue.to_f + saleobj.total_amount.to_f self.total_discounts = self.total_discounts + saleobj.total_discount self.total_taxes = self.total_taxes + saleobj.total_tax self.grand_total = self.grand_total + saleobj.grand_total + self.cash_sales = self.cash_sales.to_f + cash.to_f + self.credit_sales = self.credit_sales.to_i + credit.to_f + self.other_sales = self.other_sales.to_i + other_sales.to_f # self.nett_sales = - # self.cash_sales = - # self.credit_sales = - # self.other_sales = # self.commercial_taxes = self.save diff --git a/app/views/origami/shifts/new.html.erb b/app/views/origami/shifts/new.html.erb index 16c2aa10..1569eaea 100644 --- a/app/views/origami/shifts/new.html.erb +++ b/app/views/origami/shifts/new.html.erb @@ -21,7 +21,40 @@ +
+
+
+
+
1
+
2
+
3
+
+
+
4
+
5
+
6
+
+
+
7
+
8
+
9
+
+
+
0
+
.
+
00
+
+
+
Del
+
Clr
+
Ent
+
+
+ +
+
+ diff --git a/config/routes.rb b/config/routes.rb index dd38914d..10ee5a05 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -93,6 +93,11 @@ Rails.application.routes.draw do # post '/:booking_id' => 'home#item_show' + # Other Charges + get "/:sale_id/other_charges" => "other_charges#index" + post "/:sale_id/other_charges" => "other_charges#create" + + # Discount get "/:id/discount" => "discounts#index" post "/:id/discount" => "discounts#create" get "/:id/remove_all_discount" => "discounts#remove_all_discount" From 2713fae6b5e9181253b9f0925896f08a151e968a Mon Sep 17 00:00:00 2001 From: Nweni Date: Fri, 30 Jun 2017 13:44:29 +0630 Subject: [PATCH 7/7] Update --- app/controllers/origami/shifts_controller.rb | 3 +- app/views/origami/shifts/new.html.erb | 4 +++ db/migrate/20170403160742_create_sales.rb | 2 +- lib/tasks/menu_import.rake | 29 +++++++++++--------- 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/app/controllers/origami/shifts_controller.rb b/app/controllers/origami/shifts_controller.rb index 8649a0db..3329aa0b 100644 --- a/app/controllers/origami/shifts_controller.rb +++ b/app/controllers/origami/shifts_controller.rb @@ -10,6 +10,7 @@ class Origami::ShiftsController < BaseOrigamiController def new @float = Lookup.where('lookup_type=?','float_value') + @terminal = CashierTerminal.all end def create @@ -29,7 +30,7 @@ class Origami::ShiftsController < BaseOrigamiController end end - + def edit end end diff --git a/app/views/origami/shifts/new.html.erb b/app/views/origami/shifts/new.html.erb index 1569eaea..2903a8ae 100644 --- a/app/views/origami/shifts/new.html.erb +++ b/app/views/origami/shifts/new.html.erb @@ -1,5 +1,9 @@

Open Cashier


+
+
+
+
diff --git a/db/migrate/20170403160742_create_sales.rb b/db/migrate/20170403160742_create_sales.rb index a3018bbd..ae806472 100644 --- a/db/migrate/20170403160742_create_sales.rb +++ b/db/migrate/20170403160742_create_sales.rb @@ -20,7 +20,7 @@ class CreateSales < ActiveRecord::Migration[5.1] t.decimal :rounding_adjustment, :precision => 10, :scale => 2, :null => false, :default => 0.00 t.decimal :amount_received, :precision => 10, :scale => 2, :null => false, :default => 0.00 t.decimal :amount_changed, :precision => 10, :scale => 2, :null => false, :default => 0.00 - + t.integer :shift_sale_id, :null => false t.timestamps end end diff --git a/lib/tasks/menu_import.rake b/lib/tasks/menu_import.rake index 1979d364..47b84ef5 100644 --- a/lib/tasks/menu_import.rake +++ b/lib/tasks/menu_import.rake @@ -60,8 +60,8 @@ menu_category2 = MenuCategory.create({menu: menu, code:"C002", name: "Specialty menu_category3 = MenuCategory.create({menu: menu, code:"C003", name: "Beef & Mutton", alt_name: "Beef_and_mutton", order_by: 3,created_by: "SYSTEM DEFAULT"}) # Australia Angus Boneless Short Rib menu_category1_menu_item6 = SimpleMenuItem.create({item_code:"01007", name: "Australia Angus Boneless Short Rib", alt_name: "Twin Pot",menu_category: menu_category3 , min_selectable_item: 1, max_selectable_item:1, account: food }) - menu_item0_instance = MenuItemInstance.create([{item_instance_name:"Half Potion",item_instance_code:"II0142", menu_item: menu_category1_menu_item5, price:12500.00, is_on_promotion:false}]) - menu_item0_instance = MenuItemInstance.create([{item_instance_name:"Full Potion",item_instance_code:"II0141", menu_item: menu_category1_menu_item5, price:25000.00, is_on_promotion:false}]) + menu_item0_instance = MenuItemInstance.create([{item_instance_name:"Half Potion",item_instance_code:"II0142", menu_item: menu_category1_menu_item6, price:12500.00, is_on_promotion:false}]) + menu_item0_instance = MenuItemInstance.create([{item_instance_name:"Full Potion",item_instance_code:"II0141", menu_item: menu_category1_menu_item6, price:25000.00, is_on_promotion:false}]) # Spain Beef menu_category1_menu_item7 = SimpleMenuItem.create({item_code:"01008", name: "Spain Beef", alt_name: "Twin Pot",menu_category: menu_category3 , min_selectable_item: 1, max_selectable_item:1, account: food }) menu_item0_instance = MenuItemInstance.create([{item_instance_name:"Half Potion",item_instance_code:"II0152", menu_item: menu_category1_menu_item7, price:8000.00, is_on_promotion:false}]) @@ -83,10 +83,13 @@ menu_category3 = MenuCategory.create({menu: menu, code:"C003", name: "Beef & Mut menu_item0_instance = MenuItemInstance.create([{item_instance_name:"Half Potion",item_instance_code:"II0192", menu_item: menu_category1_menu_item11, price:7000.00, is_on_promotion:false}]) menu_item0_instance = MenuItemInstance.create([{item_instance_name:"Full Potion",item_instance_code:"II0191", menu_item: menu_category1_menu_item11, price:14000.00, is_on_promotion:false}]) # Sliced Lamb - menu_category1_menu_item11 = SimpleMenuItem.create({item_code:"01012", name: "Sliced Lamb", alt_name: "Twin Pot",menu_category: menu_category3 , min_selectable_item: 1, max_selectable_item:1, account: food }) - menu_item0_instance = MenuItemInstance.create([{item_instance_name:"Half Potion",item_instance_code:"II0202", menu_item: menu_category1_menu_item11, price:7000.00, is_on_promotion:false}]) - menu_item0_instance = MenuItemInstance.create([{item_instance_name:"Full Potion",item_instance_code:"II0201", menu_item: menu_category1_menu_item11, price:14000.00, is_on_promotion:false}]) - + menu_category1_menu_item12 = SimpleMenuItem.create({item_code:"01013", name: "Sliced Lamb", alt_name: "Twin Pot",menu_category: menu_category3 , min_selectable_item: 1, max_selectable_item:1, account: food }) + menu_item0_instance = MenuItemInstance.create([{item_instance_name:"Half Potion",item_instance_code:"II0202", menu_item: menu_category1_menu_item12, price:7000.00, is_on_promotion:false}]) + menu_item0_instance = MenuItemInstance.create([{item_instance_name:"Full Potion",item_instance_code:"II0201", menu_item: menu_category1_menu_item12, price:14000.00, is_on_promotion:false}]) + # Sliced Beef ( Think ) + menu_category1_menu_item13 = SimpleMenuItem.create({item_code:"01014", name: "Sliced Beef ( Think )", alt_name: "Twin Pot",menu_category: menu_category3 , min_selectable_item: 1, max_selectable_item:1, account: food }) + menu_item0_instance = MenuItemInstance.create([{item_instance_name:"Half Potion",item_instance_code:"II1432", menu_item: menu_category1_menu_item13, price:7000.00, is_on_promotion:false}]) + menu_item0_instance = MenuItemInstance.create([{item_instance_name:"Full Potion",item_instance_code:"II1431", menu_item: menu_category1_menu_item13, price:14000.00, is_on_promotion:false}]) # Pork menu_category4 = MenuCategory.create({menu: menu, code:"C004", name: "Pork", alt_name: "Pork", order_by: 4,created_by: "SYSTEM DEFAULT"}) # Sliced Tenderloin Pork @@ -282,7 +285,7 @@ menu_category8 = MenuCategory.create({menu: menu, code:"C008", name: "Seafood", menu_category1_menu_item61 = SimpleMenuItem.create({item_code:"01062", name: "Live Lobster", alt_name: "Twin Pot",menu_category: menu_category7 , min_selectable_item: 1, max_selectable_item:1, account: food }) menu_item0_instance = MenuItemInstance.create([{item_instance_name:"",item_instance_code:"II0681", menu_item: menu_category1_menu_item61, price:10.00, is_on_promotion:false}]) # Live Mantis - menu_category1_menu_item62 = SimpleMenuItem.create({item_code:"01063", name: "Live Mantis", alt_name: "Twin Pot",menu_category: menu_category7 , min_selectable_item: 1, max_selectable_item:1, account: food }) + menu_category1_menu_item62 = SimpleMenuItem.create({item_code:"01063", name: "Live Mantis Prawn", alt_name: "Twin Pot",menu_category: menu_category7 , min_selectable_item: 1, max_selectable_item:1, account: food }) menu_item0_instance = MenuItemInstance.create([{item_instance_name:" ",item_instance_code:"II0691", menu_item: menu_category1_menu_item62, price:10.00, is_on_promotion:false}]) # Dumpling menu_category9 = MenuCategory.create({menu: menu, code:"C009", name: "Dumpling", alt_name: "Chicken", order_by: 9, created_by: "SYSTEM DEFAULT"}) @@ -567,20 +570,20 @@ menu_category19 = MenuCategory.create({menu: menu, code:"C0018", name: "Beer", a menu_item0_instance = MenuItemInstance.create([{item_instance_name:"Can",item_instance_code:"II1392", menu_item: menu_category1_menu_item132, price:1500.00, is_on_promotion:false}]) menu_item0_instance = MenuItemInstance.create([{item_instance_name:"Bottle",item_instance_code:"II1391", menu_item: menu_category1_menu_item132, price:3000.00, is_on_promotion:false}]) # # Tiger Beer -# menu_category1_menu_item133 = SimpleMenuItem.create({item_code:"01134", name: "Tiger Beer ", alt_name: "Twin Pot",menu_category: menu_category19 , min_selectable_item: 1, max_selectable_item:1, account: beverage }) -# menu_item0_instance = MenuItemInstance.create([{item_instance_name:"Can",item_instance_code:"II1402", menu_item: menu_category1_menu_item133, price:1500.00, is_on_promotion:false}]) -# menu_item0_instance = MenuItemInstance.create([{item_instance_name:"Bottle",item_instance_code:"II1401", menu_item: menu_category1_menu_item133, price:3000.00, is_on_promotion:false}]) + menu_category1_menu_item133 = SimpleMenuItem.create({item_code:"01134", name: "Tiger Beer ", alt_name: "Twin Pot",menu_category: menu_category19 , min_selectable_item: 1, max_selectable_item:1, account: beverage }) + menu_item0_instance = MenuItemInstance.create([{item_instance_name:"Can",item_instance_code:"II1442", menu_item: menu_category1_menu_item133, price:1500.00, is_on_promotion:false}]) + menu_item0_instance = MenuItemInstance.create([{item_instance_name:"Bottle",item_instance_code:"II1441", menu_item: menu_category1_menu_item133, price:3000.00, is_on_promotion:false}]) # Heineken Beer menu_category1_menu_item134 = SimpleMenuItem.create({item_code:"01135", name: "Heineken Beer", alt_name: "Twin Pot",menu_category: menu_category19 , min_selectable_item: 1, max_selectable_item:1, account: beverage }) menu_item0_instance = MenuItemInstance.create([{item_instance_name:"Can",item_instance_code:"II1402", menu_item: menu_category1_menu_item134, price:1800.00, is_on_promotion:false}]) menu_item0_instance = MenuItemInstance.create([{item_instance_name:"Bottle",item_instance_code:"II1401", menu_item: menu_category1_menu_item134, price:3600.00, is_on_promotion:false}]) # Tsing Tao Beer menu_category1_menu_item135 = SimpleMenuItem.create({item_code:"01136", name: "Tsing Tao Beer", alt_name: "Twin Pot",menu_category: menu_category19 , min_selectable_item: 1, max_selectable_item:1, account: beverage }) - menu_item0_instance = MenuItemInstance.create([{item_instance_name:"",item_instance_code:"II141", menu_item: menu_category1_menu_item135, price:2800.00, is_on_promotion:false}]) + menu_item0_instance = MenuItemInstance.create([{item_instance_name:"",item_instance_code:"II1411", menu_item: menu_category1_menu_item135, price:2800.00, is_on_promotion:false}]) # ABC Stout menu_category1_menu_item136 = SimpleMenuItem.create({item_code:"01137", name: "ABC Stout ", alt_name: "Twin Pot",menu_category: menu_category19 , min_selectable_item: 1, max_selectable_item:1, account: beverage }) - menu_item0_instance = MenuItemInstance.create([{item_instance_name:"Can",item_instance_code:"II1432", menu_item: menu_category1_menu_item136, price:2000.00, is_on_promotion:false}]) - menu_item0_instance = MenuItemInstance.create([{item_instance_name:"Bottle",item_instance_code:"II1431", menu_item: menu_category1_menu_item136, price:4000.00, is_on_promotion:false}]) + menu_item0_instance = MenuItemInstance.create([{item_instance_name:"Can",item_instance_code:"II1422", menu_item: menu_category1_menu_item136, price:2000.00, is_on_promotion:false}]) + menu_item0_instance = MenuItemInstance.create([{item_instance_name:"Bottle",item_instance_code:"II1421", menu_item: menu_category1_menu_item136, price:4000.00, is_on_promotion:false}]) # Signature Hot Tea" menu_category20 = MenuCategory.create({menu: menu, code:"C0019", name: "Signature Hot Tea", alt_name: "Chicken", order_by: 19, created_by: "SYSTEM DEFAULT"}) puts "Beauty in the pot's menu setup"