diff --git a/app/controllers/api/bill_controller.rb b/app/controllers/api/bill_controller.rb index 4fdd0c35..9671ba47 100644 --- a/app/controllers/api/bill_controller.rb +++ b/app/controllers/api/bill_controller.rb @@ -38,7 +38,7 @@ class Api::BillController < Api::ApiController item_price_by_accounts = SaleItem.calculate_price_by_accounts(@sale_items) printer = Printer::ReceiptPrinter.new(print_settings) - printer.print_receipt_bill(print_settings,@sale_items,@sale_data,customer.name, item_price_by_accounts) + # printer.print_receipt_bill(print_settings,@sale_items,@sale_data,customer.name, item_price_by_accounts) end diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 0700ce0b..3136417f 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -80,7 +80,7 @@ class HomeController < ApplicationController redirect_to dashboard_path elsif employee.role == "cashier" #check if cashier has existing open cashier - shift = ShiftSale.current_open_shift(employee) + shift = ShiftSale.current_open_shift(employee.id) if !shift.nil? redirect_to origami_root_path else diff --git a/app/controllers/origami/cash_ins_controller.rb b/app/controllers/origami/cash_ins_controller.rb new file mode 100644 index 00000000..dd78bc1b --- /dev/null +++ b/app/controllers/origami/cash_ins_controller.rb @@ -0,0 +1,15 @@ +class Origami::CashInsController < BaseOrigamiController + + def new + end + + def create + reference = params[:reference] + remark = params[:remark] + amount = params[:amount] + payment_method = params[:payment_method] + 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) + end +end diff --git a/app/controllers/origami/cash_outs_controller.rb b/app/controllers/origami/cash_outs_controller.rb new file mode 100644 index 00000000..ac079a39 --- /dev/null +++ b/app/controllers/origami/cash_outs_controller.rb @@ -0,0 +1,13 @@ +class Origami::CashOutsController < BaseOrigamiController + + def new + end + + def create + reference = params[:reference] + remark = params[:remark] + amount = params[:amount] + p_jour = PaymentJournal.new + p_jour.cash_out(reference, remark, amount, current_user.id) + end +end diff --git a/app/controllers/origami/home_controller.rb b/app/controllers/origami/home_controller.rb index 1b0aa491..32f4ab12 100644 --- a/app/controllers/origami/home_controller.rb +++ b/app/controllers/origami/home_controller.rb @@ -6,6 +6,7 @@ class Origami::HomeController < BaseOrigamiController @rooms = Room.all.active.order('status desc') @complete = Sale.all @orders = Order.all.order('date desc') + # @shift = ShiftSale.current_open_shift(current_user.id) end # origami table detail diff --git a/app/controllers/origami/request_bills_controller.rb b/app/controllers/origami/request_bills_controller.rb index 314835a2..a04936fc 100644 --- a/app/controllers/origami/request_bills_controller.rb +++ b/app/controllers/origami/request_bills_controller.rb @@ -38,7 +38,7 @@ class Origami::RequestBillsController < BaseOrigamiController printer = Printer::ReceiptPrinter.new(print_settings) - printer.print_receipt_bill(print_settings,@sale_items,@sale_data,customer.name, item_price_by_accounts,member_info,shop_details) + # printer.print_receipt_bill(print_settings,@sale_items,@sale_data,customer.name, item_price_by_accounts,member_info,shop_details) # redirect_to origami_path(@sale_data.sale_id) end diff --git a/app/controllers/origami/shifts_controller.rb b/app/controllers/origami/shifts_controller.rb index b20c4d7b..1a7a5289 100644 --- a/app/controllers/origami/shifts_controller.rb +++ b/app/controllers/origami/shifts_controller.rb @@ -4,10 +4,11 @@ class Origami::ShiftsController < BaseOrigamiController end def show + @shift = ShiftSale.current_open_shift(current_user.id) end def new - @float = Lookup.where('lookup_type=?','float') + @float = Lookup.where('lookup_type=?','float_value') end def create @@ -16,6 +17,14 @@ class Origami::ShiftsController < BaseOrigamiController @shift.create(opening_balance,current_user) end + def update_shift + @shift = ShiftSale.current_open_shift(current_user.id) + if @shift + @shift.shift_closed_at = DateTime.now.utc + @shift.save + end + end + def edit end end diff --git a/app/models/employee.rb b/app/models/employee.rb index 1816c2e3..2d70768d 100644 --- a/app/models/employee.rb +++ b/app/models/employee.rb @@ -1,6 +1,7 @@ class Employee < ApplicationRecord has_secure_password + has_many :shit_sales validates_presence_of :name, :role validates_presence_of :password, :on => [:create] validates :emp_id, uniqueness: true, numericality: true, length: {in: 1..4}, allow_blank: true diff --git a/app/models/payment_journal.rb b/app/models/payment_journal.rb index 237f9cd4..6105a574 100644 --- a/app/models/payment_journal.rb +++ b/app/models/payment_journal.rb @@ -1,2 +1,22 @@ class PaymentJournal < ApplicationRecord + + def cash_in(reference, remark, amount, payment_method, payment_method_reference, current_user) + self.payment_references = reference + self.remark = remark + self.credit_amount = amount + self.payment_method = payment_method + self.payment_status = 'paid' + self.payment_method_references = payment_method_reference + self.created_by = current_user + self.save + end + + def cash_out(payment_reference, remark, amount, current_user) + self.payment_references = payment_reference + self.remark = remark + self.debit_amount = amount + self.payment_status = 'paid' + self.created_by = current_user + self.save + end end diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 7f39aa18..7a835618 100644 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -247,12 +247,14 @@ class SalePayment < ApplicationRecord end self.sale.sale_status = "completed" self.sale.save! - shift = ShiftSale.current_open_shift(self.sale.cashier_id) - if shift - shift.update(self.sale) - end 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) + end end end diff --git a/app/models/shift_sale.rb b/app/models/shift_sale.rb index ea7f1132..c8bdf7a7 100644 --- a/app/models/shift_sale.rb +++ b/app/models/shift_sale.rb @@ -14,13 +14,14 @@ class ShiftSale < ApplicationRecord belongs_to :cashier_terminal - belongs_to :employee + belongs_to :employee, :foreign_key => 'employee_id' def self.current_open_shift(current_user) #if current_user #find open shift where is open today and is not closed and login by current cashier today_date = DateTime.now.strftime("%Y-%m-%d") - shift = ShiftSale.where("TO_CHAR(shift_started_at, 'YYYY-MM-DD')=? and shift_started_at is not null and shift_closed_at is null and employee_id = #{current_user.id}",today_date).take + puts today_date + shift = ShiftSale.where("TO_CHAR(shift_started_at, 'YYYY-MM-DD')=? and shift_started_at is not null and shift_closed_at is null and employee_id = #{current_user}",today_date).take return shift #end @@ -35,6 +36,7 @@ class ShiftSale < ApplicationRecord end def update(sale) + puts ">>>>>> shift sale update" saleobj = Sale.find(sale) self.total_revenue = self.total_revenue + saleobj.total_amount self.total_discounts = self.total_discounts + saleobj.total_discount diff --git a/app/views/origami/cash_ins/new.html.erb b/app/views/origami/cash_ins/new.html.erb new file mode 100644 index 00000000..1c513895 --- /dev/null +++ b/app/views/origami/cash_ins/new.html.erb @@ -0,0 +1,79 @@ + +
| Payment Reference + | ++ |
| Remark + | ++ |
| Payment Method + | ++ + + + + | +
| Payment Reference + | ++ |
| Remark + | ++ |
| Amount + | ++ |
Find me in app/views/origami/shifts/edit.html.erb
+Find me in app/views/origami/shifts/show.html.erb
+ +| Shift Started At | +<%= @shift.shift_started_at.utc.getlocal.strftime("%d/%m/%Y - %I:%M %p") rescue '-' %> | +
| Cashier Name | +<%= @shift.employee.name rescue ''%> | +
| Opening Balance | +<%= @shift.opening_balance rescue ''%> | +
| Total Revenue | +<%= @shift.total_revenue rescue ''%> | +
| Total Discount | +<%= @shift.total_discounts rescue ''%> | +
| Total Tax | +<%= @shift.total_taxes rescue ''%> | +
| Grand Total | +<%= @shift.grand_total rescue ''%> | +
| Nett Sale | +<%= @shift.nett_sales rescue ''%> | +
| Cash Sale | +<%= @shift.cash_sales rescue ''%> | +
| Credit Sale | +<%= @shift.credit_sales rescue ''%> | +
| Other Sale | +<%= @shift.other_sales rescue ''%> | +
| Commercial Tax | +<%= @shift.commercial_taxes rescue ''%> | +
| Cash In | +<%= @shift.cash_in rescue ''%> | +
| Cash Out | +<%= @shift.cash_out rescue ''%> | +