From c589f11758779cd6f3ce54829d5f510840179a0c Mon Sep 17 00:00:00 2001 From: Nweni Date: Sat, 1 Jul 2017 09:46:14 +0630 Subject: [PATCH] shift sale --- app/controllers/origami/shifts_controller.rb | 6 +++--- app/models/sale.rb | 11 ++++++----- app/models/sale_payment.rb | 4 +++- app/models/shift_sale.rb | 4 ++-- app/views/origami/shifts/new.html.erb | 19 ++++++++++++++----- db/migrate/20170403160742_create_sales.rb | 2 +- 6 files changed, 29 insertions(+), 17 deletions(-) diff --git a/app/controllers/origami/shifts_controller.rb b/app/controllers/origami/shifts_controller.rb index 3329aa0b..35af84b6 100644 --- a/app/controllers/origami/shifts_controller.rb +++ b/app/controllers/origami/shifts_controller.rb @@ -4,7 +4,6 @@ class Origami::ShiftsController < BaseOrigamiController end def show - puts current_user.id @shift = ShiftSale.current_open_shift(current_user.id) end @@ -15,8 +14,9 @@ class Origami::ShiftsController < BaseOrigamiController def create opening_balance = params[:opening_balance] + cashier_terminal = params[:cashier_terminal] @shift = ShiftSale.new - @shift.create(opening_balance,current_user) + @shift.create(opening_balance,cashier_terminal, current_user) end def update_shift @@ -30,7 +30,7 @@ class Origami::ShiftsController < BaseOrigamiController end end - def edit end + end diff --git a/app/models/sale.rb b/app/models/sale.rb index 693f6874..1df94034 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -345,8 +345,8 @@ class Sale < ApplicationRecord else ## up to 100 value = 100 - get_last_no.to_f - num += value - puts 'up to 100' + num += value + puts 'up to 100' end end end @@ -479,11 +479,12 @@ end def get_commerical_tax tax = 0.0 - self.sale_taxes.each do |tax| - if tax.tax_name == "Commerical Tax" - tax += tax.tax_payable_amount + self.sale_taxes.each do |taxobj| + if taxobj.tax_name == "Commerical Tax" + tax += taxobj.tax_payable_amount end end + return tax end diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index c78b6cd8..741abfc2 100644 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -266,6 +266,8 @@ class SalePayment < ApplicationRecord shift = ShiftSale.current_open_shift(self.sale.cashier_id) if !shift.nil? shift.update(self.sale) + self.sale.shift_sale_id = shift.id + self.sale.save end end @@ -324,7 +326,7 @@ class SalePayment < ApplicationRecord }, :timeout => 10) rescue Net::OpenTimeout response = { status: false } - + rescue OpenURI::HTTPError response = { status: false} diff --git a/app/models/shift_sale.rb b/app/models/shift_sale.rb index a897de2b..ae4c93a8 100644 --- a/app/models/shift_sale.rb +++ b/app/models/shift_sale.rb @@ -27,8 +27,8 @@ class ShiftSale < ApplicationRecord #end end - def create(opening_balance,current_user) - self.cashier_terminal_id = CashierTerminal.first.id + def create(opening_balance,cashier_terminal, current_user) + self.cashier_terminal_id = cashier_terminal self.shift_started_at = DateTime.now self.employee_id = current_user.id self.opening_balance = opening_balance diff --git a/app/views/origami/shifts/new.html.erb b/app/views/origami/shifts/new.html.erb index 2903a8ae..f5f032bc 100644 --- a/app/views/origami/shifts/new.html.erb +++ b/app/views/origami/shifts/new.html.erb @@ -1,12 +1,19 @@

Open Cashier


-
-
-
-
+
+ + + + <% @float.each do |float| %> @@ -69,10 +76,12 @@ $(document).on('focusout', '.float-value', function(event){ }) $('#open_cashier').on('click',function(){ + var cashier_terminal = $('#cashier_terminal').val(); + alert(cashier_terminal) var amount = $('#total').text(); $.ajax({type: "POST", url: "<%= origami_shifts_path %>", - data: "opening_balance=" + amount, + data: "opening_balance=" + amount + "&cashier_terminal="+ cashier_terminal, success:function(result){ if(result){ window.location.href = '/origami'; diff --git a/db/migrate/20170403160742_create_sales.rb b/db/migrate/20170403160742_create_sales.rb index ae806472..9deeb9b8 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.integer :shift_sale_id t.timestamps end end
Cashier Terminal + +
<%= float.name %>