From acca5b5a1d47a0cd86ce056ac1998b16bb16dcc9 Mon Sep 17 00:00:00 2001 From: Nweni Date: Sun, 2 Jul 2017 11:22:49 +0630 Subject: [PATCH] Update --- app/controllers/api/bill_controller.rb | 33 +++++++++++--------- app/controllers/origami/shifts_controller.rb | 2 ++ app/models/shift_sale.rb | 8 ++++- app/views/origami/home/show.html.erb | 12 +++---- app/views/origami/payments/show.html.erb | 2 ++ 5 files changed, 35 insertions(+), 22 deletions(-) diff --git a/app/controllers/api/bill_controller.rb b/app/controllers/api/bill_controller.rb index cb3b9cc2..bcd9d62b 100644 --- a/app/controllers/api/bill_controller.rb +++ b/app/controllers/api/bill_controller.rb @@ -5,26 +5,29 @@ class Api::BillController < Api::ApiController def create @status = false @error_message = "Order ID or Booking ID is require to request for a bill." - + if ShiftSale.current_shift #create Bill by Booking ID - if (params[:booking_id]) - booking = Booking.find(params[:booking_id]) + if (params[:booking_id]) + booking = Booking.find(params[:booking_id]) - if booking - if booking.sale_id.nil? - @sale = Sale.new - @status, @sale_id = @sale.generate_invoice_from_booking(params[:booking_id], current_login_employee, get_cashier) - else - @status = true - @sale_id = booking.sale_id + if booking + if booking.sale_id.nil? + @sale = Sale.new + @status, @sale_id = @sale.generate_invoice_from_booking(params[:booking_id], current_login_employee, get_cashier) + else + @status = true + @sale_id = booking.sale_id + end end - end - elsif (params[:order_id]) - @sale = Sale.new - @status, @sale_id = @sale.generate_invoice_from_order(params[:order_id], current_login_employee, get_cashier) + elsif (params[:order_id]) + @sale = Sale.new + @status, @sale_id = @sale.generate_invoice_from_order(params[:order_id], current_login_employee, get_cashier) + end + else + @status = false + @error_message = "No Current Open Shift" end - # Not Use for these printed bill cannot give customer # @sale_data = Sale.find_by_sale_id(@sale_id) # @sale_items = SaleItem.where("sale_id=?",@sale_id) diff --git a/app/controllers/origami/shifts_controller.rb b/app/controllers/origami/shifts_controller.rb index 07d10cf7..e527da46 100644 --- a/app/controllers/origami/shifts_controller.rb +++ b/app/controllers/origami/shifts_controller.rb @@ -4,6 +4,8 @@ class Origami::ShiftsController < BaseOrigamiController end def show + puts ">>>>>" + puts current_user.id @shift = ShiftSale.current_open_shift(current_user.id) end diff --git a/app/models/shift_sale.rb b/app/models/shift_sale.rb index acf3149c..b9c5aa28 100644 --- a/app/models/shift_sale.rb +++ b/app/models/shift_sale.rb @@ -16,11 +16,17 @@ class ShiftSale < ApplicationRecord belongs_to :cashier_terminal belongs_to :employee, :foreign_key => 'employee_id' + def self.current_shift + today_date = DateTime.now.strftime("%Y-%m-%d") + shift = ShiftSale.where("DATE(shift_started_at)=? and shift_started_at is not null and shift_closed_at is null",today_date).take + return shift + end + 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("DATE(shift_started_at)= #{ today_date } and shift_started_at is not null and shift_closed_at is null and employee_id = #{current_user}").take + shift = ShiftSale.where("DATE(shift_started_at)=? and shift_started_at is not null and shift_closed_at is null and employee_id = #{current_user}",today_date).take return shift #end end diff --git a/app/views/origami/home/show.html.erb b/app/views/origami/home/show.html.erb index 0d3de391..baad1a0a 100644 --- a/app/views/origami/home/show.html.erb +++ b/app/views/origami/home/show.html.erb @@ -163,18 +163,18 @@ <% - count = 0 sub_total = 0 if @status_sale == "sale" @sale_array[0].sale_items.each do |sale_item| - count += 1 - sub_total = sub_total + sale_item.price + + sub_total = sub_total + sale_item.price %> <% # Can't check for discount unless sale_item.price == 0 + count += 1 %> <%= count %> @@ -439,7 +439,7 @@ $("#first_bill").on('click', function(){ $.ajax({ type: "GET", url: ajax_url, - success:function(result){ + success:function(result){ location.reload(); } }); @@ -452,11 +452,11 @@ $('#pay').on('click',function() { $.ajax({ type: "POST", url: '/origami/sale/'+ sale_id + "/rounding_adj", - success:function(result){ + success:function(result){ window.location.href = '/origami/sale/'+ sale_id + "/payment"; } }); - + }); // Bill Request diff --git a/app/views/origami/payments/show.html.erb b/app/views/origami/payments/show.html.erb index 292ae5e1..86738c22 100644 --- a/app/views/origami/payments/show.html.erb +++ b/app/views/origami/payments/show.html.erb @@ -334,6 +334,7 @@ $( document ).ready(function() { }); $('#pay').click(function() { + $('#pay').text("Processing, Please wait!") if($('#balance').text() > 0){ alert(" Insufficient Amount!") }else{ @@ -351,6 +352,7 @@ $( document ).ready(function() { if($('#balance').text() < 0){ alert("Changed amount " + $('#balance').text() * (-1) ) }else{ + $('#pay').text("Pay") alert("Thank you") }