diff --git a/app/controllers/origami/in_duties_controller.rb b/app/controllers/origami/in_duties_controller.rb
index 9846516e..7ac2d306 100755
--- a/app/controllers/origami/in_duties_controller.rb
+++ b/app/controllers/origami/in_duties_controller.rb
@@ -1,14 +1,12 @@
class Origami::InDutiesController < BaseOrigamiController
before_action :set_in_duty, only: %i[show edit update edit_in_duty update_for_in_duty destroy destroy_in_duty]
- # GET /in_duties
- # GET /in_duties.json
- def index
- @in_duties = InDuty.all
- end
-
+
def index_in_duty
- @duty_in = InDuty.where('dinning_id=?', params[:table_id])
- @table = DiningFacility.find(params[:table_id])
+ @sale_id = params[:sale_id]
+ booking = Booking.where("sale_id=?",@sale_id).first
+ @booking_id = booking.booking_id
+ @duty_in = InDuty.where('dinning_id=? and sale_id=?', booking.dining_facility_id, @sale_id)
+ @table = DiningFacility.find(booking.dining_facility_id)
@in_duty = InDuty.new
@duties_in = Kaminari.paginate_array(@duty_in).page(params[:page]).per(10)
end
@@ -31,11 +29,14 @@ class Origami::InDutiesController < BaseOrigamiController
def edit_in_duty
@in_duty = InDuty.find(params[:id])
- @table = DiningFacility.find(params[:table_id])
+ @sale_id = params[:sale_id]
+ booking = Booking.where("sale_id=?",@sale_id).first
+ @booking_id = booking.booking_id
+ @table = DiningFacility.find(booking.dining_facility_id)
@commissioner = @in_duty.commissioner
- # render json: {in_duty: @in_duty, commissioner: @commissioner}
- render partial: 'form'
+ render json: {in_duty: @in_duty, commissioner: @commissioner}
+ # render partial: 'form'
end
def assign_in_duty
@@ -45,20 +46,6 @@ class Origami::InDutiesController < BaseOrigamiController
# POST /in_duties
# POST /in_duties.json
- def create
- @in_duty = InDuty.new(in_duty_params)
-
- respond_to do |format|
- if @in_duty.save
- format.html { redirect_to origami_in_duties_path, notice: 'In duty was successfully created.' }
- format.json { render :show, status: :created, location: @in_duty }
- else
- format.html { render :new }
- format.json { render json: @in_duty.errors, status: :unprocessable_entity }
- end
- end
- end
-
def create_for_in_duty
# this one use for create and update
in_duty = in_duty_params
@@ -66,8 +53,8 @@ class Origami::InDutiesController < BaseOrigamiController
# in_time = in_time.change(offset: '+06:30')
# out_time = DateTime.new in_duty['out_time(1i)'].to_i, in_duty['out_time(2i)'].to_i, in_duty['out_time(3i)'].to_i, in_duty['out_time(4i)'].to_i, in_duty['out_time(5i)'].to_i
# out_time = out_time.change(offset: '+06:30')
- puts in_duty.to_json
- puts "sssssssssssssssssss"
+ # puts in_duty.to_json
+ # puts "sssssssssssssssssss"
@in_duty = InDuty.new
in_duty_id = in_duty[:id]
unless in_duty_id.empty?
@@ -75,6 +62,8 @@ class Origami::InDutiesController < BaseOrigamiController
end
@in_duty.dinning_id = in_duty_params[:dinning_id]
+ @in_duty.booking_id = in_duty_params[:booking_id]
+ @in_duty.sale_id = in_duty_params[:sale_id]
@in_duty.commissioner_ids = in_duty_params[:commissioner_ids]
@in_duty.in_time = in_duty['in_time']
@in_duty.out_time = in_duty['out_time']
@@ -97,38 +86,18 @@ class Origami::InDutiesController < BaseOrigamiController
# PATCH/PUT /in_duties/1
# PATCH/PUT /in_duties/1.json
- def update
- in_duty = in_duty_params
- in_time = DateTime.new in_duty['in_time(1i)'].to_i, in_duty['in_time(2i)'].to_i, in_duty['in_time(3i)'].to_i, in_duty['in_time(4i)'].to_i, in_duty['in_time(5i)'].to_i
- in_time = in_time.change(offset: '+06:30')
- out_time = DateTime.new in_duty['out_time(1i)'].to_i, in_duty['out_time(2i)'].to_i, in_duty['out_time(3i)'].to_i, in_duty['out_time(4i)'].to_i, in_duty['out_time(5i)'].to_i
- out_time = out_time.change(offset: '+06:30')
- @in_duty.commissioner_ids = in_duty_params[:commissioner_ids]
- @in_duty.in_time = in_time
- @in_duty.out_time = out_time
- respond_to do |format|
- if @in_duty.save
- format.html { redirect_to origami_index_in_duty_path(in_duty_params[:dinning_id]), notice: 'In duty was successfully updated.' }
- format.json { render :show, status: :ok, location: @in_duty }
- else
- format.html { render :edit }
- format.json { render json: @in_duty.errors, status: :unprocessable_entity }
- end
- end
- end
-
def update_for_in_duty
in_duty = in_duty_params
- in_time = DateTime.new in_duty['in_time(1i)'].to_i, in_duty['in_time(2i)'].to_i, in_duty['in_time(3i)'].to_i, in_duty['in_time(4i)'].to_i, in_duty['in_time(5i)'].to_i
- in_time = in_time.change(offset: '+06:30')
- out_time = DateTime.new in_duty['out_time(1i)'].to_i, in_duty['out_time(2i)'].to_i, in_duty['out_time(3i)'].to_i, in_duty['out_time(4i)'].to_i, in_duty['out_time(5i)'].to_i
- out_time = out_time.change(offset: '+06:30')
+ # in_time = DateTime.new in_duty['in_time(1i)'].to_i, in_duty['in_time(2i)'].to_i, in_duty['in_time(3i)'].to_i, in_duty['in_time(4i)'].to_i, in_duty['in_time(5i)'].to_i
+ # in_time = in_time.change(offset: '+06:30')
+ # out_time = DateTime.new in_duty['out_time(1i)'].to_i, in_duty['out_time(2i)'].to_i, in_duty['out_time(3i)'].to_i, in_duty['out_time(4i)'].to_i, in_duty['out_time(5i)'].to_i
+ # out_time = out_time.change(offset: '+06:30')
@in_duty.commissioner_ids = in_duty_params[:commissioner_ids]
- @in_duty.in_time = in_time
- @in_duty.out_time = out_time
+ @in_duty.in_time = in_duty_params[:in_time]
+ @in_duty.out_time = in_duty_params[:out_time]
respond_to do |format|
if @in_duty.save
- format.html { redirect_to origami_index_in_duty_path(in_duty_params[:dinning_id]), notice: 'In duty was successfully updated.' }
+ format.html { redirect_to origami_index_in_duty_path(in_duty_params[:sale_id]), notice: 'In duty was successfully updated.' }
format.json { render :show, status: :ok, location: @in_duty }
else
format.html { render :edit }
@@ -139,22 +108,15 @@ class Origami::InDutiesController < BaseOrigamiController
# DELETE /in_duties/1
# DELETE /in_duties/1.json
- def destroy
- @in_duty.destroy
- respond_to do |format|
- format.html { redirect_to origami_in_duties_path, notice: 'In duty was successfully removed.' }
- format.json { head :no_content }
- end
- end
-
def destroy_in_duty
@table_id = params[:table_id]
+ @sale_id = params[:sale_id]
+ booking = Booking.where("sale_id=?",@sale_id).first
+ @booking_id = booking.booking_id
@in_duty.destroy
- respond_to do |format|
- format.html { redirect_to origami_index_in_duty_path, notice: 'In duty was successfully removed.' }
- format.json { head :no_content }
- end
+ flash[:notice] = 'In duty was successfully destroyed.'
+ render :json => {:status=> "Success", :url => origami_index_in_duty_path }.to_json
end
private
@@ -166,7 +128,7 @@ class Origami::InDutiesController < BaseOrigamiController
# Never trust parameters from the scary internet, only allow the white list through.
def in_duty_params
- params.require(:in_duty).permit(:id, :dinning_id, :commissioner_ids, :in_time, :out_time)
+ params.require(:in_duty).permit(:id, :dinning_id, :booking_id, :sale_id, :commissioner_ids, :in_time, :out_time)
end
end
diff --git a/app/controllers/reports/induty_controller.rb b/app/controllers/reports/induty_controller.rb
new file mode 100644
index 00000000..f4bcc34f
--- /dev/null
+++ b/app/controllers/reports/induty_controller.rb
@@ -0,0 +1,66 @@
+class Reports::IndutyController < BaseReportController
+ authorize_resource :class => false
+ def index
+ @commissioners = Commissioner.all #.where("is_active='1'")
+
+ from, to = get_date_range_from_params
+
+ @shift_sale_range = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED)
+
+ @shift = ''
+ if params[:shift_name].to_i != 0
+ shift_sale = ShiftSale.find(params[:shift_name])
+ if to.blank?
+ @shift = ShiftSale.where('shift_started_at = ? and shift_closed_at is NULL ',shift_sale.shift_started_at)
+ else
+
+ @shift = ShiftSale.where('shift_started_at = ? and shift_closed_at = ? ',shift_sale.shift_started_at, shift_sale.shift_closed_at)
+ end
+ end
+
+ @commissioner = params[:commissioner]
+ @induty_data = InDuty.get_induty_by_shift(@shift_sale_range,@shift,from,to,@commissioner)
+
+ @from = from
+ @to = to
+ # get printer info
+ # @print_settings = PrintSetting.get_precision_delimiter()
+
+ if @shift.present?
+ @shift.each do |sh|
+ @shift_from = sh.shift_started_at.nil? ? '-' : sh.shift_started_at.utc.getlocal.strftime("%e %b %I:%M%p")
+ @shift_to = sh.shift_closed_at.nil? ? '-' : sh.shift_closed_at.utc.getlocal.strftime("%e %b %I:%M%p")
+ @shift_data = sh
+ end
+ end
+
+ respond_to do |format|
+ format.html
+ format.xls
+ end
+ end
+
+ def show
+ from, to = get_date_range_from_params
+
+ @induty_data = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED)
+ @commissioner = params[:commissioner]
+
+ date_arr = Array.new
+ @induty_data.each do |induty|
+ local_opening_date = induty.opening_date.nil? ? '-' : induty.opening_date.utc.getlocal.strftime("%e %b %I:%M%p")
+ local_closing_date = induty.closing_date.nil? ? '-' : induty.closing_date.utc.getlocal.strftime("%e %b %I:%M%p")
+ opening_date = induty.opening_date.nil? ? '-' : induty.opening_date.utc
+ closing_date = induty.closing_date.nil? ? '-' : induty.closing_date.utc
+ shift_id = induty.id.nil? ? '-' : induty.id
+ str = {:shift_id => shift_id, :local_opening_date => local_opening_date, :local_closing_date => local_closing_date, :opening_date => opening_date, :closing_date => closing_date}
+ date_arr.push(str)
+ end
+
+ out = {:status => 'ok', :message => date_arr}
+
+ respond_to do |format|
+ format.json { render json: out }
+ end
+ end
+end
diff --git a/app/models/in_duty.rb b/app/models/in_duty.rb
index 485787c7..9fbf67be 100755
--- a/app/models/in_duty.rb
+++ b/app/models/in_duty.rb
@@ -1,4 +1,34 @@
class InDuty < ApplicationRecord
belongs_to :dining_facility, foreign_key: 'dinning_id'
belongs_to :commissioner, foreign_key: 'commissioner_ids'
+
+ def self.get_induty_by_shift(shift_sale_range,shift,from,to,commissioner)
+ ## => left join -> show all sales although no orders
+ if commissioner.blank?
+ commissioner = ''
+ else
+ if commissioner.present?
+ commissioner = " and CAST(in_duties.commissioner_ids AS SIGNED INTEGER) = #{commissioner}"
+ end
+ end
+
+ query = InDuty.select("in_duties.*,sales.receipt_no, commissioners.name,dining_facilities.name as dining_name")
+ .joins(" LEFT JOIN commissioners on commissioners.id = CAST(in_duties.commissioner_ids AS SIGNED INTEGER)")
+ .joins(" LEFT JOIN dining_facilities on dining_facilities.id = in_duties.dinning_id")
+ .joins(" JOIN sales on sales.sale_id = in_duties.sale_id")
+ if shift.present?
+ query = query.where("sales.shift_sale_id in (?) #{commissioner} and sales.sale_status= 'completed' and sale_payments.payment_amount != 0", shift.to_a)
+ .joins("join sale_payments on sale_payments.sale_id = sales.sale_id")
+ .group("sales.sale_id, in_duties.commissioner_ids")
+ elsif shift_sale_range.present?
+ query = query.where("sales.sale_status='completed' #{commissioner} and sale_payments.payment_amount != 0 and sales.shift_sale_id in (?)",shift_sale_range.to_a)
+ .joins("join sale_payments on sale_payments.sale_id = sales.sale_id")
+ .group("sales.sale_id, in_duties.commissioner_ids")
+ else
+ query = query.where("sales.sale_status='completed' and sales.receipt_date between ? and ? #{commissioner} and sale_payments.payment_amount != 0",from,to)
+ .joins("join sale_payments on sale_payments.sale_id = sales.sale_id")
+ .group("sales.sale_id, in_duties.commissioner_ids")
+ end
+ return query
+ end
end
diff --git a/app/views/layouts/_left_sidebar.html.erb b/app/views/layouts/_left_sidebar.html.erb
index 4862acfe..f83284ae 100644
--- a/app/views/layouts/_left_sidebar.html.erb
+++ b/app/views/layouts/_left_sidebar.html.erb
@@ -161,6 +161,9 @@
Commission
+
+ Induty
+
Stock Check
diff --git a/app/views/origami/home/show.html.erb b/app/views/origami/home/show.html.erb
index 1552d872..58ba3838 100755
--- a/app/views/origami/home/show.html.erb
+++ b/app/views/origami/home/show.html.erb
@@ -991,8 +991,9 @@
});
$('#in_duties').on('click', function () {
- var dining_id = "<%= @dining.id %>"
- window.location.href = '/origami/assign_in_duty/'+ dining_id;
+ var dining_id = "<%= @dining.id %>";
+ var sale_id = "<%= @obj_sale.sale_id rescue "" %>";
+ window.location.href = '/origami/assign_in_duty/'+ sale_id;
});
$('#void').on('click', function () {
diff --git a/app/views/origami/in_duties/_form.html.erb b/app/views/origami/in_duties/_form.html.erb
index 07cee2cf..800e356a 100755
--- a/app/views/origami/in_duties/_form.html.erb
+++ b/app/views/origami/in_duties/_form.html.erb
@@ -5,6 +5,8 @@
<%= f.error_notification %>
<%= f.hidden_field :id, :class => "form-control col-md-6 " %>
+ <%= f.hidden_field :booking_id, :value => @booking_id %>
+ <%= f.hidden_field :sale_id, :value => @sale_id %>
<%= f.hidden_field :dinning_id, :value => @table.id, :class => "form-control col-md-4 " %>
@@ -21,9 +23,9 @@
date_range
<% if !@in_duty.in_time.nil?%>
-
+
<% else %>
-
+
<% end %>
@@ -34,19 +36,19 @@
date_range
<% if !@in_duty.out_time.nil?%>
-
+
<% else %>
-
+
<% end %>
-
+
<%= f.submit "Create In Duty", :class => 'btn bg-blue' %>
diff --git a/app/views/origami/in_duties/assign_in_duty.html.erb b/app/views/origami/in_duties/assign_in_duty.html.erb
index f24b16d9..8a4b24c8 100755
--- a/app/views/origami/in_duties/assign_in_duty.html.erb
+++ b/app/views/origami/in_duties/assign_in_duty.html.erb
@@ -53,11 +53,13 @@ $(function() {
var commissioner_ids = $('#in_duty_commissioner_ids').val();
var in_time = $('#in_duty_in_time').val();
var out_time = $('#in_duty_out_time').val();
- var dining_id = '<%= @table.id %>'
+ var dining_id = '<%= @table.id %>';
+ var sale_id = '<%= @sale_id %>';
+ var booking_id = '<%= @booking_id %>';
$.ajax({
type: "POST",
url: ajax_url,
- data: 'dining_id=' + dining_id + "&commissioner_ids=" + commissioner_ids +'&in_time=' + in_time + "&out_time=" + out_time,
+ data: 'dining_id=' + dining_id + "sale_id=" + sale_id + "booking_id=" + booking_id + "&commissioner_ids=" + commissioner_ids +'&in_time=' + in_time + "&out_time=" + out_time,
success: function (result) {
window.location.href = '/origami/assign_in_duty/'+ dining_id;
}
diff --git a/app/views/origami/in_duties/index_in_duty.html.erb b/app/views/origami/in_duties/index_in_duty.html.erb
index 72fcff96..16a8a03f 100755
--- a/app/views/origami/in_duties/index_in_duty.html.erb
+++ b/app/views/origami/in_duties/index_in_duty.html.erb
@@ -32,7 +32,7 @@
<%= in_duty.in_time.utc.getlocal.strftime("%Y-%m-%d/%I:%M %p") rescue '-' %> |
<%= in_duty.out_time.utc.getlocal.strftime("%Y-%m-%d/%I:%M %p") rescue '-' %> |
- |