diff --git a/app/assets/javascripts/addorder.js b/app/assets/javascripts/addorder.js index 2804583a..34c93405 100755 --- a/app/assets/javascripts/addorder.js +++ b/app/assets/javascripts/addorder.js @@ -339,13 +339,14 @@ $(function(){ $(".sx_item_set_detailModal").css({ 'display': "none" }); }else{ $(".sx_item_set_detailModal").css({ 'display': "block" }); - $.alert({ - title: 'Alert!', - content: 'Please Select Minimum ' + min_qty + " items", - type: 'red', - typeAnimated: true, - btnClass: 'btn-danger', - }); + swal("Alert !", 'Please Select Minimum ' + min_qty + " items", "warning"); + // $.alert({ + // title: 'Alert!', + // content: 'Please Select Minimum ' + min_qty + " items", + // type: 'red', + // typeAnimated: true, + // btnClass: 'btn-danger', + // }); } }); //End add order Click @@ -420,7 +421,7 @@ $(function(){ for(var field in attributes) { value = attributes[field]["values"]; type = attributes[field]["type"] - row = "

"+attributes[field]["type"]+"

"; + row = "
"+attributes[field]["type"]+"
"; $(value).each(function(i){ disabled = "" @@ -794,11 +795,10 @@ $(function(){ // Get Selected Class function change_qty_plus_minus(id,plus,minus) { - var count = 1; + var count = parseInt($('#'+id).val()) var countEl = document.getElementById(id); $('#'+plus).on("click", function(){ - count++; countEl.value = count; @@ -852,6 +852,37 @@ $(function(){ } }) } + + + $('.keypress_qty').keyup(function(e){ + + id = $(this).attr('id'); + value = $(this).val(); + + if (id=="count") { + price = $("#unit_price").text(); + $("#total_price").text(value*price); + }else{ + var item_row = $('.selected-instance'); + price = $("#set_unit_price").text(); + set_total_price = $("#set_total_price").text(); + $("#set_count").val(value); + if (item_row.length > 1) { + total = 0 ; + $(item_row).each(function(i){ + total += value * $(item_row[i]).attr('data-price'); + total_price = total; + }); + }else{ + total_price = value*price; + } + $("#set_total_price").text(total_price); + } + }); + + /* $("input").keypress(function(){ + $("span").text(i += 1); +});*/ // $("#set_change_qty").change(function(){ // qty = $(this).val(); // price = $("#set_total_price").text(); diff --git a/app/assets/javascripts/custom.js b/app/assets/javascripts/custom.js index 2460031d..f33f6d11 100644 --- a/app/assets/javascripts/custom.js +++ b/app/assets/javascripts/custom.js @@ -2,8 +2,6 @@ $(document).ready(function() { $('body').bootstrapMaterialDesign(); var height = ($(window).height() - ($('.legal').outerHeight() + $('.user-info').outerHeight() + $('.navbar').innerHeight())); -console.log(height); -console.log($('#order-detail-slimscroll').attr('data-height')) $('#custom-slimscroll').slimScroll({ height: height, diff --git a/app/assets/stylesheets/CRM.scss b/app/assets/stylesheets/CRM.scss index 50529aea..18bdca31 100755 --- a/app/assets/stylesheets/CRM.scss +++ b/app/assets/stylesheets/CRM.scss @@ -87,3 +87,29 @@ } +.cashier_number{ + width: 33%; + height:58px; + line-height:58px; + text-align:center; + background:#54A5AF; + // float:left; + // margin:2px; + font-size:20px; + color:white; + // cursor:pointer; +} + +.red { + background-color:#F44336; +} + +.green{ + background-color: #009900; +} +.left{ + margin-left:1px; +} +.bottom{ + margin-bottom:1px; +} diff --git a/app/assets/stylesheets/addorder.scss b/app/assets/stylesheets/addorder.scss index b14895df..970532f7 100755 --- a/app/assets/stylesheets/addorder.scss +++ b/app/assets/stylesheets/addorder.scss @@ -152,6 +152,10 @@ section.content{ } -#count { +#count ,#set_count{ text-align: center; +} + +.add_icon{ + cursor: pointer; } \ No newline at end of file diff --git a/app/assets/stylesheets/origami.scss b/app/assets/stylesheets/origami.scss index 8b269d92..9f7de6dd 100755 --- a/app/assets/stylesheets/origami.scss +++ b/app/assets/stylesheets/origami.scss @@ -139,6 +139,13 @@ select.form-control { background-color:#795548; } +.others-color{ + background-color:#E1BEE7; + height: 30px !important; + line-height: 30px !important; +} + + .cashier_number:hover{ background:#A9F5F2; } diff --git a/app/controllers/api/check_in_process_controller.rb b/app/controllers/api/check_in_process_controller.rb new file mode 100644 index 00000000..0baa258a --- /dev/null +++ b/app/controllers/api/check_in_process_controller.rb @@ -0,0 +1,78 @@ +class Api::CheckInProcessController < Api::ApiController + + def check_in_process + if params[:dining_id] + dining_facility = DiningFacility.find(params[:dining_id]) + if dining_facility.status == "available" + dining_charge = DiningCharge.select('charge_type','charge_block') + .where('dining_facility_id = ?',params[:dining_id]) + .first() + + checkout_at = Time.now.utc + + if !dining_charge.nil? + hr = (dining_charge.charge_block.utc.strftime("%H").to_i).to_int + min = (dining_charge.charge_block.utc.strftime("%M").to_i).to_int + # if dining_charge.charge_type == 'hr' + checkout_at = checkout_at + hr.hour + min.minutes + # else + + # end + end + + dining_facility.status = "occupied" + dining_facility.save! + + if dining_facility.type == "Table" + type = "TableBooking" + else + type = "RoomBooking" + end + + booking = Booking.create({:dining_facility_id => params[:dining_id],:type => type, + :checkin_at => Time.now.utc,:checkout_at =>checkout_at, :booking_status => "assign" }) + booking.save! + + render :json => { :status => true, :checkout_at => booking.checkout_at.utc.strftime("%Y-%m-%d %H:%M") } + else + error_message = "#{dining_facility.type} is not available!" + render :json => { :status => false, :error_message => error_message } + end + else + error_message = "dining_id is required!" + render :json => { :status => false, :error_message => error_message } + end + end + + def request_time + if !params[:booking_id].nil? && !params[:time].nil? + time = Time.parse(params[:time]) + booking = Booking.find(params[:booking_id]) + + checkout_at = booking.checkout_at.utc + + hr = (time.strftime("%H").to_i).to_int + min = (time.strftime("%M").to_i).to_int + checkout_at = checkout_at + hr.hour + min.minutes + + booking.checkout_at = checkout_at + booking.save! + + render :json => { :status => true, :checkout_at => booking.checkout_at.utc.strftime("%Y-%m-%d %H:%M") } + elsif !params[:booking_id].nil? && params[:time].nil? + error_message = "time is required!" + render :json => { :status => false, :error_message => error_message } + elsif params[:booking_id].nil? && !params[:time].nil? + error_message = "booking_id is required!" + render :json => { :status => false, :error_message => error_message } + else + error_message = "booking_id and time are required!" + render :json => { :status => false, :error_message => error_message } + end + end + + private + def check_in_process_params + params.permit(:dining_id,:booking_id,:time) + end +end diff --git a/app/controllers/crm/customers_controller.rb b/app/controllers/crm/customers_controller.rb index d8ee10fb..2a277144 100755 --- a/app/controllers/crm/customers_controller.rb +++ b/app/controllers/crm/customers_controller.rb @@ -33,7 +33,7 @@ class Crm::CustomersController < BaseCrmController end end end - @crm_customers = Kaminari.paginate_array(@crm_customers).page(params[:page]).per(50) + @crm_customers = Kaminari.paginate_array(@crm_customers).page(params[:page]).per(15) @crm_customer = Customer.new @count_customer = Customer.count_customer @@ -70,7 +70,7 @@ class Crm::CustomersController < BaseCrmController #get customer amount @customer = Customer.find(params[:id]) @response = Customer.get_membership_transactions(@customer) - + puts @response.to_json # @response = "" #end customer amount diff --git a/app/controllers/crm/dining_queues_controller.rb b/app/controllers/crm/dining_queues_controller.rb index a48e03a7..480ad08e 100755 --- a/app/controllers/crm/dining_queues_controller.rb +++ b/app/controllers/crm/dining_queues_controller.rb @@ -7,6 +7,7 @@ class Crm::DiningQueuesController < BaseCrmController def index today = DateTime.now.strftime('%Y-%m-%d') @dining_queues = DiningQueue.where("DATE_FORMAT(created_at,'%Y-%m-%d') = ? and status is NULL ", today).order("queue_no asc") + @complete_queue = DiningQueue.where("DATE_FORMAT(created_at,'%Y-%m-%d') = ? and status = 'Assign' ", today).order("queue_no asc") end # GET /crm/dining_queues/1 diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 8cfdfd22..bc621bd7 100755 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -68,24 +68,49 @@ class HomeController < ApplicationController @sales = Sale::where("payment_status='paid' and sale_status='completed' and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'").count() @top_products = Sale.top_products(today).sum('i.qty') + @bottom_products = Sale.bottom_products(today).sum('i.qty') @hourly_sales = Sale.hourly_sales(today).sum(:grand_total) # .group_by_hour(:created_at, :time_zone => 'Asia/Rangoon',format: '%I:%p') # .sum(:grand_total) @employee_sales = Sale.employee_sales(today).sum(:grand_total) @inventories = StockJournal.inventory_balances(today).sum(:balance) - #@employee_sales = Hash.new - #employee_sales.each do |key, value| - # if(@employee_sales.has_key? key[1]) - # @employee_sales[key[1]].push({key[0] => value}) - # else - # @employee_sales[key[1]] = [key[0] => value] - # end - #end @total_sale = Sale.total_sale(today) @total_count = Sale.total_count(today) @total_card = Sale.total_card_sale(today) - @total_credit = Sale.credit_payment(today) + @total_credit = Sale.credit_payment(today) + + @sale_data = Array.new + @total_payment_methods = Sale.total_payment_methods(today) + @total_payment_methods.each do |payment| + if payment.payment_method == "mpu" || payment.payment_method == "visa" || payment.payment_method == "master" || payment.payment_method == "jcb" + pay = Sale.payment_sale('card', today) + @sale_data.push({'card' => pay}) + else + pay = Sale.payment_sale(payment.payment_method, today) + @sale_data.push({payment.payment_method => pay}) + end + end + @summ_sale = Sale.summary_sale_receipt(today) + p @summ_sale + @total_customer = Sale.total_customer(today) + @total_dinein = Sale.total_dinein(today) + @total_takeaway = Sale.total_takeaway(today) + @total_other_customer = Sale.total_other_customer(today) + @total_membership = Sale.total_membership(today) + + @total_order = Sale.total_order(today) + @total_accounts = Sale.total_account(today) + @account_data = Array.new + @total_accounts.each do |account| + acc = Sale.account_data(account.account_id, today) + if !acc.nil? + @account_data.push({account.title => acc.cnt_acc, account.title + '_amount' => acc.total_acc}) + end + end + + @top_items = Sale.top_items(today) + @total_foc_items = Sale.total_foc_items(today) end def destroy diff --git a/app/controllers/origami/check_in_process_controller.rb b/app/controllers/origami/check_in_process_controller.rb new file mode 100644 index 00000000..8e9a1f38 --- /dev/null +++ b/app/controllers/origami/check_in_process_controller.rb @@ -0,0 +1,38 @@ +class Origami::CheckInProcessController < BaseOrigamiController + + def check_in_process + dining_charge = DiningCharge.select('charge_type','charge_block') + .where('dining_facility_id = ?',params[:dining_id]) + .first() + + checkout_at = Time.now.utc + + if !dining_charge.nil? + hr = (dining_charge.charge_block.utc.strftime("%H").to_i).to_int + min = (dining_charge.charge_block.utc.strftime("%M").to_i).to_int + # if dining_charge.charge_type == 'hr' + checkout_at = checkout_at + hr.hour + min.minutes + # else + + # end + end + @dining_facility = DiningFacility.find(params[:dining_id]) + @dining_facility.status = "occupied" + @dining_facility.save! + + if @dining_facility.type == "Table" + type = "TableBooking" + else + type = "RoomBooking" + end + + @booking = Booking.create({:dining_facility_id => params[:dining_id],:type => type, + :checkin_at => Time.now.utc,:checkout_at =>checkout_at, :booking_status => "assign" }) + @booking.save! + + respond = {:status => 'ok'} + respond_to do |format| + format.json { render json: respond } + end + end +end diff --git a/app/controllers/origami/discounts_controller.rb b/app/controllers/origami/discounts_controller.rb index 82e878bd..c1319bfe 100755 --- a/app/controllers/origami/discounts_controller.rb +++ b/app/controllers/origami/discounts_controller.rb @@ -215,7 +215,7 @@ class Origami::DiscountsController < BaseOrigamiController else response = {"status": false, "message": "You have no selected discount item" } end - puts "discount" + puts "discountttttttttttt" puts response.to_json # Re-calc All Amount in Sale if response["status"] == true diff --git a/app/controllers/origami/home_controller.rb b/app/controllers/origami/home_controller.rb index febf7e45..8e5b33c2 100755 --- a/app/controllers/origami/home_controller.rb +++ b/app/controllers/origami/home_controller.rb @@ -7,7 +7,7 @@ class Origami::HomeController < BaseOrigamiController @complete = Sale.where("DATE_FORMAT(created_at,'%Y-%m-%d') = ? and sale_status != 'new'",DateTime.now.strftime('%Y-%m-%d')) @orders = Order.all.order('date desc') @shop = Shop.find_by_id(1) - + # @shift = ShiftSale.current_open_shift(current_user.id) end @@ -23,10 +23,12 @@ class Origami::HomeController < BaseOrigamiController @sale_array = Array.new @dining.bookings.active.each do |booking| - if booking.sale_id.nil? && booking.booking_status != 'moved' - - @order_items = Array.new - booking.booking_orders.each do |booking_order| + if booking.sale_id.nil? && booking.booking_status != 'moved' + @order_items = Array.new + if booking.booking_orders.empty? + @booking = booking + else + booking.booking_orders.each do |booking_order| order = Order.find(booking_order.order_id) if (order.status == "new") @obj_order = order @@ -43,29 +45,30 @@ class Origami::HomeController < BaseOrigamiController @account_arr.push(account) end end - end - @status_order = 'order' - else - sale = Sale.find(booking.sale_id) - if sale.sale_status != "completed" && sale.sale_status != 'void' - - @sale_array.push(sale) - if @status_order == 'order' - @status_order = 'sale' - end - @booking= booking - @date = sale.created_at - @status_sale = 'sale' - @obj_sale = sale - @customer = sale.customer - accounts = @customer.tax_profiles - @account_arr =[] - accounts.each do |acc| - account = TaxProfile.find(acc) - @account_arr.push(account) - end - end + end end + @status_order = 'order' + else + sale = Sale.find(booking.sale_id) + if sale.sale_status != "completed" && sale.sale_status != 'void' + + @sale_array.push(sale) + if @status_order == 'order' + @status_order = 'sale' + end + @booking= booking + @date = sale.created_at + @status_sale = 'sale' + @obj_sale = sale + @customer = sale.customer + accounts = @customer.tax_profiles + @account_arr =[] + accounts.each do |acc| + account = TaxProfile.find(acc) + @account_arr.push(account) + end + end + end end end diff --git a/app/controllers/origami/request_bills_controller.rb b/app/controllers/origami/request_bills_controller.rb index d83e600d..e0f1d06c 100755 --- a/app/controllers/origami/request_bills_controller.rb +++ b/app/controllers/origami/request_bills_controller.rb @@ -9,6 +9,7 @@ class Origami::RequestBillsController < ApplicationController order_id = params[:id] # order_id bk_order = BookingOrder.find_by_order_id(order_id) check_booking = Booking.find_by_booking_id(bk_order.booking_id) + if check_booking.sale_id.nil? # Create Sale if it doesn't exist # puts "current_login_employee" diff --git a/app/controllers/transactions/bookings_controller.rb b/app/controllers/transactions/bookings_controller.rb index b826cd52..66418caa 100644 --- a/app/controllers/transactions/bookings_controller.rb +++ b/app/controllers/transactions/bookings_controller.rb @@ -10,12 +10,12 @@ class Transactions::BookingsController < ApplicationController if filter.nil? && from.nil? && to.nil? @bookings = Booking.all.order("sale_id desc") - @bookings = Kaminari.paginate_array(@bookings).page(params[:page]).per(2) + @bookings = Kaminari.paginate_array(@bookings).page(params[:page]).per(20) else - sale = Sale.search(filter,from,to) - if sale.count > 0 - @bookings = sale - @bookings = Kaminari.paginate_array(@bookings).page(params[:page]).per(2) + booking = Booking.search(filter,from,to) + if booking.count > 0 + @bookings = booking + @bookings = Kaminari.paginate_array(@bookings).page(params[:page]).per(20) else @bookings = 0 end diff --git a/app/controllers/transactions/shift_sales_controller.rb b/app/controllers/transactions/shift_sales_controller.rb new file mode 100644 index 00000000..1f765d21 --- /dev/null +++ b/app/controllers/transactions/shift_sales_controller.rb @@ -0,0 +1,61 @@ +class Transactions::ShiftSalesController < ApplicationController + load_and_authorize_resource except: [:create] + before_action :set_transactions_shift_sale, only: [:show, :edit, :update, :destroy] + + def index + + filter = params[:filter] + from = params[:from] + to = params[:to] + + if filter.nil? && from.nil? && to.nil? + @shift_sales = ShiftSale.all.order("id desc") + @shift_sales = Kaminari.paginate_array(@shift_sales).page(params[:page]).per(20) + else + shift_sale = ShiftSale.search(filter,from,to) + if shift_sale.count > 0 + @shift_sales = shift_sale + @shift_sales = Kaminari.paginate_array(@shift_sales).page(params[:page]).per(20) + else + @shift_sales = 0 + end + end + + respond_to do |format| + format.html # index.html.erb + format.json { render json: @shift_sales } + end + + end + + # GET /transactions/shift_sales/1 + # GET /transactions/shift_sales/1.json + def show + + @shift = ShiftSale.find(params[:id]) + + #get tax + shift_obj = ShiftSale.where('id =?',@shift.id) + @sale_taxes = Sale.get_separate_tax(shift_obj,from=nil,to=nil,type='') + #other payment details for mpu or visa like card + @other_payment = ShiftSale.get_by_shift_other_payment(@shift) + + # Calculate price_by_accounts + @total_amount_by_account = ShiftSale.calculate_total_price_by_accounts(@shift,'amount') + @total_discount_by_account = ShiftSale.calculate_total_price_by_accounts(@shift,'discount') + @total_member_discount = ShiftSale.get_total_member_discount(@shift) + + + + respond_to do |format| + format.html # show.html.erb + format.json { render json: @shift } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_transactions_shift_sale + @transactions_shift_sale = ShiftSale.find(params[:id]) + end +end diff --git a/app/models/booking.rb b/app/models/booking.rb index b65063a4..826d585d 100755 --- a/app/models/booking.rb +++ b/app/models/booking.rb @@ -45,14 +45,14 @@ class Booking < ApplicationRecord if filter.blank? keyword = '' else - keyword = "booking_id LIKE ? OR cashier_name LIKE ? OR sale_status ='#{filter}'","%#{filter}%","%#{filter}%" + keyword = "booking_id LIKE ? OR checkin_by LIKE ? OR booking_status LIKE? OR checkout_by LIKE? OR sale_id ='#{filter}'","%#{filter}%","%#{filter}%","%#{filter}%","%#{filter}%" end if from.present? && to.present? - sale = Sale.where("DATE_FORMAT(receipt_date,'%d-%m-%Y') >= ?" + " AND DATE_FORMAT(receipt_date,'%d-%m-%Y') <= ? and NOT sale_status = 'void' ", from,to) - query = sale.where(keyword) + booking = Booking.where("DATE_FORMAT(created_at,'%d-%m-%Y') >= ?" + " AND DATE_FORMAT(created_at,'%d-%m-%Y') <= ? and NOT booking_status = 'void' ", from,to) + query = booking.where(keyword) else - where("receipt_no LIKE ? OR cashier_name LIKE ? OR sale_status ='#{filter}'","%#{filter}%","%#{filter}%",) + where("booking_id LIKE ? OR checkin_by LIKE ? OR booking_status LIKE? OR checkout_by LIKE? OR sale_id ='#{filter}'","%#{filter}%","%#{filter}%","%#{filter}%","%#{filter}%") end end diff --git a/app/models/dining_facility.rb b/app/models/dining_facility.rb index 24a3e47b..1130003e 100755 --- a/app/models/dining_facility.rb +++ b/app/models/dining_facility.rb @@ -32,7 +32,7 @@ class DiningFacility < ApplicationRecord end def get_current_booking - booking = Booking.where("dining_facility_id = #{self.id} and booking_status ='assign' and checkin_at between '#{DateTime.now.utc - 5.hours}' and '#{DateTime.now.utc}' and checkout_at is null").limit(1) + booking = Booking.where("dining_facility_id = #{self.id} and booking_status ='assign' and checkin_at between '#{DateTime.now.utc - 5.hours}' and '#{DateTime.now.utc}' and checkout_by is null").limit(1) #and checkout_at is null if booking.count > 0 then return booking[0] else @@ -65,4 +65,32 @@ class DiningFacility < ApplicationRecord return nil end end + + def get_current_checkout_booking + booking = Booking.where("dining_facility_id = #{self.id} and booking_status ='assign' and sale_id is null and checkout_at is not null and checkout_by is null").limit(1) + if booking.count > 0 then + return booking[0] + else + return nil + end + end + + def get_checkout_booking + booking = self.get_current_checkout_booking + if booking + now = Time.now.utc + hr = (now.strftime("%H").to_i).to_int + min = (now.strftime("%M").to_i).to_int + + checkout_at = booking.checkout_at.utc + + checkout_at = checkout_at - hr.hour + checkout_at = checkout_at - min.minutes + checkout_at = checkout_at.utc.strftime("%M").to_i + + if checkout_at <= 15 + return booking + end + end + end end diff --git a/app/models/sale.rb b/app/models/sale.rb index 87e2d6d5..7e68e771 100755 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -907,7 +907,17 @@ end .where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'"+ "and payment_status='paid' and sale_status= 'completed'") .group('mi.name') - .order("SUM(i.qty) DESC").limit(5) + .order("SUM(i.qty) DESC").limit(10) + end + + def self.bottom_products(today) + query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," + + " i.price as unit_price,mi.name as product_name") + .joins("JOIN sale_items i ON i.sale_id = sales.sale_id JOIN menu_items mi ON i.product_code = mi.item_code") + .where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'"+ + "and payment_status='paid' and sale_status= 'completed'") + .group('mi.name') + .order("SUM(i.qty) ASC").limit(10) end def self.hourly_sales(today) @@ -941,9 +951,9 @@ end # .joins("join sale_payments on sale_id = sales.sale_id") # .group("sales.sale_id") - query = SalePayment.where('s.sale_status = "completed" and payment_method = "mpu" or payment_method = "visa" or payment_method = "master" or payment_method = "jcb" and DATE_FORMAT(s.receipt_date,"%Y-%m-%d") = ?',today) - .joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id") - .sum("payment_amount") + query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb"',today) + .joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id") + .sum("sp.payment_amount") end @@ -953,6 +963,99 @@ end .sum("payment_amount") end + def self.summary_sale_receipt(today) + query = Sale.select('count(sale_id) as total_receipt, (case when sum(total_amount) > 0 then sum(total_amount) else 0.0 end) as total_amount, (case when sum(grand_total) > 0 then sum(grand_total) else 0.0 end) as grand_total, (case when sum(total_discount) > 0 then sum(total_discount) else 0.0 end) as total_discount, (case when sum(total_tax) > 0 then sum(total_tax) else 0.0 end) as total_tax') + .where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today) + .first() + end + + def self.total_payment_methods(today) + query = Sale.select("sp.payment_method") + .where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ?',today) + .joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") + end + + def self.payment_sale(payment_method, today) + query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") + if payment_method == 'card' + query = query.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb"',today) + else + query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today) + end + query.sum("sp.payment_amount") + end + + def self.total_customer(today) + query = Sale.select("count(distinct sales.customer_id) as total_cus") + .where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ?',today) + .first() + end + + def self.total_dinein(today) + query = Sale.select("count(distinct sales.customer_id) as total_dinein_cus") + .joins("JOIN customers as c ON c.customer_id = sales.customer_id") + .where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and c.customer_type = "Dinein" and c.membership_id is null',today) + .first() + end + + def self.total_takeaway(today) + query = Sale.select("count(distinct sales.customer_id) as total_take_cus") + .joins("JOIN customers as c ON c.customer_id = sales.customer_id") + .where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and c.customer_type = "Takeaway" and c.membership_id is null',today) + .first() + end + + def self.total_membership(today) + query = Sale.select("count(distinct sales.customer_id) as total_memb_cus") + .joins("JOIN customers as c ON c.customer_id = sales.customer_id") + .where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and c.customer_type = "Takeaway" and c.membership_id is not null',today) + .first() + end + + def self.total_other_customer(today) + query = Sale.select("count(distinct sales.customer_id) as total_cus") + .joins("JOIN customers as c ON c.customer_id = sales.customer_id") + .where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and c.customer_type is null and c.membership_id is null',today) + .first() + end + + def self.total_order(today) + query = Sale.select("count(distinct a.order_id) as total_order") + .joins("JOIN sale_orders as a ON a.sale_id = sales.sale_id") + .joins("JOIN orders as b ON b.order_id = a.order_id") + .where('b.status = "billed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ?',today) + .first() + end + + def self.total_account(today) + query = Sale.select("distinct b.id as account_id, b.title as title") + .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") + .joins("JOIN accounts as b ON b.id = a.account_id") + .where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ?',today) + end + + def self.account_data(account_id, today) + query = Sale.select("count(*) as cnt_acc, SUM(a.price) as total_acc") + .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") + .where("sales.sale_status = 'completed' and a.account_id ='#{account_id}' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today) + .first() + end + + def self.top_items(today) + query = Sale.select("a.product_name as item_name, SUM(a.price) as item_total_price") + .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") + .where("sales.sale_status = 'completed' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today) + .group("a.product_code") + .order("SUM(a.price) DESC") + .first() + end + + def self.total_foc_items(today) + query = Sale.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") + .where("sales.sale_status = 'completed' and a.remark='foc' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today) + .count() + end + private def generate_custom_id diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index b4b29303..e712ed9d 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -264,8 +264,6 @@ class SalePayment < ApplicationRecord end def sale_update_payment_status(paid_amount) - puts paid_amount - puts "parid Masssssssssssssssssssssssssssssssssssssssss" #update amount_outstanding self.sale.amount_received = self.sale.amount_received.to_f + paid_amount.to_f self.sale.save! @@ -316,8 +314,6 @@ class SalePayment < ApplicationRecord self.sale.rebate_status = nil end end - puts "rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr" - puts response.to_json end self.sale.save! @@ -375,7 +371,8 @@ class SalePayment < ApplicationRecord paypar.each do |pp| if pp.payment_method == "paypar" payparcost = payparcost + pp.payment_amount - elsif pp.payment_method == "creditnote" + end + if pp.payment_method == "creditnote" credit = 1 end end @@ -410,7 +407,9 @@ class SalePayment < ApplicationRecord rescue SocketError response = { "status": false, "message": "Can't connect server"} end - + puts response.to_json + puts payparcost + puts overall_dis redeem_amount = payparcost + overall_dis total_percentage = 0 @@ -431,15 +430,19 @@ class SalePayment < ApplicationRecord data = {:type => a[:type], :amount => a[:amount]} type_arr.each do |si| if si[:type] == a[:type] - amount = (redeem_amount / total_percentage)*si[:percentage] - actual = a[:amount] - amount - data[:amount] = actual + if credit == 1 + data[:amount] = 0 + else + amount = (redeem_amount / total_percentage)*si[:percentage] + actual = a[:amount] - amount + data[:amount] = actual + end + end - end rebate_arr.push(data) end - + total_amount = rebate_prices - payparcost - overall_dis if credit == 1 @@ -485,6 +488,7 @@ class SalePayment < ApplicationRecord response = { "status": "no_member", "message": "Not membership"} end + end diff --git a/app/models/shift_sale.rb b/app/models/shift_sale.rb index e9a6dd44..7546daa5 100755 --- a/app/models/shift_sale.rb +++ b/app/models/shift_sale.rb @@ -135,4 +135,20 @@ class ShiftSale < ApplicationRecord end + def self.search(filter,from,to) + if filter.blank? + keyword = '' + else + keyword = "booking_id LIKE ? OR checkin_by LIKE ? OR booking_status LIKE? OR checkout_by LIKE? OR sale_id ='#{filter}'","%#{filter}%","%#{filter}%","%#{filter}%","%#{filter}%" + end + + if from.present? && to.present? + booking = ShiftSale.where("DATE_FORMAT(created_at,'%d-%m-%Y') >= ?" + " AND DATE_FORMAT(created_at,'%d-%m-%Y') <= ? and NOT booking_status = 'void' ", from,to) + query = booking.where(keyword) + else + where("booking_id LIKE ? OR checkin_by LIKE ? OR booking_status LIKE? OR checkout_by LIKE? OR sale_id ='#{filter}'","%#{filter}%","%#{filter}%","%#{filter}%","%#{filter}%") + end + + end + end diff --git a/app/views/crm/customers/_new_form.html.erb b/app/views/crm/customers/_new_form.html.erb index 300603a3..992512f2 100755 --- a/app/views/crm/customers/_new_form.html.erb +++ b/app/views/crm/customers/_new_form.html.erb @@ -22,7 +22,7 @@ str="[\"#{msg['name']}\"]" str.gsub!('["', '') str.gsub!('"]', '') %> - <%= str %> + <%= str %> <% end -%> @@ -45,7 +45,7 @@ <% str="[\"#{msg['company']}\"]" str.gsub!('["', '') str.gsub!('"]', '') %> - <%= str %> + <%= str %> <% end -%>
"> @@ -55,7 +55,7 @@ <% str="[\"#{msg['contact_no']}\"]" str.gsub!('["', '') str.gsub!('"]', '') %> - <%= str %> + <%= str %> <% end %>
@@ -66,7 +66,7 @@ <% str="[\"#{msg['email']}\"]" str.gsub!('["', '') str.gsub!('"]', '') %> - <%= str %> + <%= str %> <% end %> @@ -107,7 +107,7 @@ <% str="[\"#{msg['card_no']}\"]" str.gsub!('["', '') str.gsub!('"]', '') %> - <%= str %> + <%= str %> <% end %> diff --git a/app/views/crm/customers/show.html.erb b/app/views/crm/customers/show.html.erb index 640e8ef6..6027eec6 100755 --- a/app/views/crm/customers/show.html.erb +++ b/app/views/crm/customers/show.html.erb @@ -36,6 +36,7 @@ + <%= @customer.card_no rescue '-'%> @@ -43,9 +44,9 @@ <%= @customer.company rescue '-' %> <%= @customer.contact_no %> <%= @customer.email %> - <%= @customer.nrc_no %> - <%= @customer.address%> - <%= @customer.date_of_birth %> + <%= @customer.nrc_no rescue '-' %> + <%= @customer.address rescue '-'%> + <%= @customer.date_of_birth rescue '-'%> <% if @customer.membership_type.to_f > 0%> <%lookup= Lookup.find_by_value(@customer.membership_type) %> <%= lookup.name %> @@ -80,7 +81,7 @@ <%= transaction["date"]%> - <%= transaction["rebate"] %> + <%= transaction["deposit"] %> <%= transaction["account_status"] %> <%= transaction["status"] %> @@ -104,7 +105,6 @@ <%= t("views.right_panel.detail.order_id") %> <%= t("views.right_panel.detail.type") %> - <%= t("views.right_panel.detail.type") %> <%= t("views.right_panel.detail.order_status") %> <%= t("views.right_panel.detail.order_date") %> <%= t("views.right_panel.detail.items_count") %> @@ -114,10 +114,10 @@ <% @orders.each do |order| %> - <%= order.order_id %> + <%= link_to order.order_id, transactions_order_path(order) %> <%= order.order_type %> <%= order.status %> - <%= order.date.strftime("%d-%m-%Y") %> + <%= order.date.strftime("%d-%m-%Y %I:%m %p") %> <%= order.item_count %> <% end %> @@ -146,13 +146,13 @@ <% @sales.each do |sale| %> - <%= sale.sale_id %> + <%= link_to sale.sale_id, transactions_sale_path(sale) %> <%= sale.receipt_no %> <%= sale.grand_total rescue '-' %> <%= sale.total_tax %> <%= sale.cashier_name rescue '-' %> <%= sale.sale_status %> - <%= sale.receipt_date.strftime("%d-%m-%Y") %> + <%= sale.receipt_date.strftime("%d-%m-%Y %I:%m %p") %> <% end %> diff --git a/app/views/crm/dining_queues/_form.html.erb b/app/views/crm/dining_queues/_form.html.erb index 2fb01b44..f20b2a57 100755 --- a/app/views/crm/dining_queues/_form.html.erb +++ b/app/views/crm/dining_queues/_form.html.erb @@ -1,27 +1,83 @@
-
+
<%= simple_form_for([:crm,@dining_queue]) do |f| %> <%= f.error_notification %> -
+
<%= f.input :queue_no , :class => "dining",:id => "dining", :readonly => true%> <%= f.input :name %> <%= f.input :contact_no %> <%= f.input :seater %> <%= f.input :remark %> - -

- <%= f.button :submit,"Create Queue" ,:class=>"btn btn-primary bg-blue btn-lg waves-effect"%> + <%= f.submit t('views.btn.submit'),:class => 'btn btn-primary btn-lg waves-effect' %>
-
+ <% end %>
-
+
+
+
+
+
+
+
+
1
+
2
+
3
+
+
+
+ +
+
+
+
4
+
5
+
6
+
+
+
+ +
+
+
+
7
+
8
+
9
+
+
+
+ +
+
+
+
0
+
.
+
00
+
+
+
+ +
+
+
+
+
DEL
+
CLR
+
+
+
+
+
+
+
+ +
view_headline <%= t("views.right_panel.header.page_detail") %>
@@ -50,9 +106,55 @@ diff --git a/app/views/crm/dining_queues/index.html.erb b/app/views/crm/dining_queues/index.html.erb index a02cc36d..fab41cdc 100755 --- a/app/views/crm/dining_queues/index.html.erb +++ b/app/views/crm/dining_queues/index.html.erb @@ -11,42 +11,79 @@
-
+
-
- - -
-
-
- - <% @dining_queues.each do |queue| %> - <% if queue.status == "Assign" - @bg_color = "assign" - elsif queue.status == "Cancel" - @bg_color = "cancel" - else - @bg_color = "normal" - end - %> -
-
- - - Queue No : <%= queue.queue_no %> - Seater : <%= queue.seater %>
- Name : <%= queue.name %>
- Contact No : <%= queue.contact_no %> - Remark : <%= queue.remark %> -
-
- - <% end %> -
-
+
+
+
+ <% if @dining_queues.count > 0 %> +
+ + <% @dining_queues.each do |queue| %> + <% if queue.status == "Assign" + @bg_color = "assign" + elsif queue.status == "Cancel" + @bg_color = "cancel" + else + @bg_color = "normal" + end + %> +
+
+ + + Queue No : <%= queue.queue_no %> + Seater : <%= queue.seater %>
+ Name : <%= queue.name %>
+ Contact No : <%= queue.contact_no %>
+ Remark : <%= queue.remark %> +
+
+ <% end %> +
-
+ <% else %> +

There is no queue Now !

+ <% end %> +
+
+
+
+
+
+
+
view_headline QUEUE DETAILs
+

+ 1) Latest Queue No - <%= @complete_queue.last.queue_no%>
+ 2) Next Queue No - <% @next = @complete_queue.last.queue_no.to_i + 1%> + <%= @next%>
+ 3) Today Completed Queue - <%= @complete_queue.count %>
+ +

list <%= t("views.right_panel.header.button_lists") %>
+

+ 1) <%= t("views.right_panel.button.cancel") %> + <%= t("views.right_panel.button.queue") %> - + <%= t("views.right_panel.detail.cancel_btn_txt") %> + <%= t("views.right_panel.detail.queue_txt") %>
+ + 2) <%= t("views.btn.new") %> + <%= t("views.right_panel.button.queue") %> - + <%= t("views.right_panel.detail.create_btn_txt") %> + <%= t("views.right_panel.detail.queue_txt") %>
+ + 2) <%= t("views.btn.assign") %> + <%= t("views.right_panel.button.queue") %> - + <%= t("views.right_panel.detail.assign_txt") %> + <%= t("views.right_panel.detail.queue_txt") %>
+

+
list <%= t("views.right_panel.header.link_lists") %>
+

+ 1) <%= t("views.right_panel.button.home") %> - <%= t("views.right_panel.detail.home_txt") %>
+ 2) <%= t("views.right_panel.button.back") %> - <%= t("views.right_panel.detail.back_txt") %> <%= t("views.right_panel.detail.home_txt") %>
+

+
+
<%= link_to t("views.btn.new"),new_crm_dining_queue_path,:class => 'btn bg-green btn-block btn-lg btn-block', 'data-no-turbolink' => true %> @@ -112,3 +149,10 @@ function cancel_queue(id,url) { } + \ No newline at end of file diff --git a/app/views/home/dashboard.html.erb b/app/views/home/dashboard.html.erb index a48a440a..bf4321be 100755 --- a/app/views/home/dashboard.html.erb +++ b/app/views/home/dashboard.html.erb @@ -56,9 +56,9 @@ <% if current_user.role == 'administrator' || current_user.role == 'manager' %>
-
+
-
+

dashboard<%= (t :top) + " " + (t :products) %>

@@ -67,6 +67,15 @@
+
+
+
+

dashboard<%= (t :bottom) + " " + (t :products) %>

+ + <%= pie_chart @bottom_products %> +
+
+
+ <% end %> + +
+
+
+
+
Customer
+ + <% if !@total_customer.nil? %> + + + + + <% end %> + <% if !@total_dinein.nil? %> + + + + + <% end %> + <% if !@total_takeaway.nil? %> + + + + + <% end %> + <% if !@total_other_customer.nil? %> + + + + + <% end %> + <% if !@total_membership.nil? %> + + + + + <% end %> +
Total Customer : <%= @total_customer.total_cus %>
Dine in : <%= @total_dinein.total_dinein_cus %>
Takeaway : <%= @total_takeaway.total_take_cus %>
Customer : <%= @total_other_customer.total_cus %>
Membership : <%= @total_membership.total_memb_cus %>
+
+
+
+
+ +
+
+
+
+
Order
+ + <% if !@total_order.nil? %> + + + + + <% end %> + + <% if !(@total_accounts.nil?) %> + <% @total_accounts.each do |account| %> + + + + + <% end %> + <% end %> + <% if !@top_items.nil? %> + + + + + <% end %> + <% if !@total_foc_items.nil? %> + + + + + <% end %> +
Total Order : <%= @total_order.total_order %>
<%= account.title %> (Account) : + <% @account_data.each do |data| %> + <% acc = account.title %> + <%= data[""+acc+""] %> <% if !data[''+acc+''].nil? %> ( <%= data[''+acc+'_amount'] %> ) <% end %> + <% end %> +
Top Item : <%= @top_items.item_name %> +
( <%= @top_items.item_total_price %> )
Total FOC Item : <%= @total_foc_items %>
+
+
+
+
+
<% end %>
\ No newline at end of file diff --git a/app/views/layouts/_left_sidebar.html.erb b/app/views/layouts/_left_sidebar.html.erb index 25b196af..1ec77487 100755 --- a/app/views/layouts/_left_sidebar.html.erb +++ b/app/views/layouts/_left_sidebar.html.erb @@ -77,12 +77,12 @@ <%= t :transactions %>
  • diff --git a/app/views/origami/addorders/detail.html.erb b/app/views/origami/addorders/detail.html.erb index 8fa1b640..095036fa 100755 --- a/app/views/origami/addorders/detail.html.erb +++ b/app/views/origami/addorders/detail.html.erb @@ -33,7 +33,7 @@
    - ORDER DETAILS | Table<%=@table.name%> + ORDER DETAILS | Table-<%=@table.name%> @@ -62,7 +62,7 @@ 0.00 - +
  • @@ -98,8 +98,16 @@
    @@ -110,7 +118,7 @@
    @@ -173,7 +193,7 @@ <% else %> -
    -
    + <% if table.get_checkout_booking.nil? %> +
    + <% else %> +
    + <% end %> +
    Zone <%= table.zone_id %>
    Table <%= table.name %> ( <%= table.seater %> Seat ) -
    -
    +
    +
    <% end %> <% else %>
    - <%= table.get_booking %> Zone <%= table.zone_id %>
    Table <%= table.name %> ( <%= table.seater %> Seat )
    diff --git a/app/views/origami/home/show.html.erb b/app/views/origami/home/show.html.erb index 6ac6bd42..ece1d39a 100755 --- a/app/views/origami/home/show.html.erb +++ b/app/views/origami/home/show.html.erb @@ -5,16 +5,16 @@ @@ -37,9 +37,8 @@
    - <% @tables.each do |table| %> + <% @tables.each do |table| %> <% if table.status == 'occupied' %> - <% if table.get_booking.nil? %>
    @@ -49,12 +48,16 @@
    <% else %> + <% if table.get_checkout_booking.nil? %>
    -
    - <%= table.name %> - new -
    + <% else %> +
    + <% end %> +
    + <%= table.name %> + new
    +
    <% end %> <% else %>
    @@ -119,7 +122,11 @@
    <% if @status_order == 'order' && @status_sale != 'sale' %> + <% if !@obj_order.nil? %>
    + <% else %> +
    + <% end %> ORDER DETAILS | Table <%= @dining.name rescue "" %> Checkin Time : <%= @booking.checkin_at.utc.getlocal.strftime("%I:%M %p") %>
    @@ -132,29 +139,38 @@
    -
    - Receipt No: - <% if @status_sale == 'sale' %> - <%= @sale_array[0].receipt_no rescue '' %> + <% if (!@sale_array.empty?) && (!@date.nil?) %> +
    + Receipt No: + <% if @status_sale == 'sale' %> + <%= @sale_array[0].receipt_no rescue '' %> - <% end %> - -
    -
    -
    - Date: <%= @date.utc.getlocal.strftime("%d/%m/%Y - %I:%M %p") rescue '-' %> -
    -
    + <% end %> +
    +
    +
    +
    + Date: <%= @date.utc.getlocal.strftime("%d/%m/%Y - %I:%M %p") rescue '-' %> +
    +
    + <% elsif !@date.nil? %> +
    + Date: <%= @date.utc.getlocal.strftime("%d/%m/%Y - %I:%M %p") rescue '-' %> +
    +
    + <% end %>
    - <% if @status_sale == 'sale' %> - - Customer : <%= @sale_array[0].customer.name rescue '' %> - <% else %> - - Customer : <%= @customer.name rescue "" %> - <% end %> + <% if !@sale_array.empty? %> + <% if @status_sale == 'sale' %> + + Customer : <%= @sale_array[0].customer.name rescue '' %> + <% else %> + + Customer : <%= @customer.name rescue "" %> + <% end %> + <% end %>
    @@ -328,10 +344,10 @@ - - + + <% if @dining.status != "available" %> <% if @status_order == 'order' %> @@ -360,6 +376,8 @@ + <% else %> + <% end %>
    @@ -628,7 +646,24 @@ }); $('#add_order').on('click', function () { - var dining_id = "<%= @dining.id %>" + var dining_id = "<%= @dining.id %>"; window.location.href = '/origami/addorders/' + dining_id; }); + + /* check in process */ + $('#check_in').on('click',function(){ + var dining_id = "<%= @dining.id %>"; + + $.ajax({ + type: 'POST', + data: {dining_id : dining_id}, + datatype: 'JSON', + url: '/origami/check_in', + success: function(data) { + if(data.status == 'ok'){ + window.location.reload(); + } + } + }); + }); diff --git a/app/views/origami/payments/show.html.erb b/app/views/origami/payments/show.html.erb index 846487be..a911acf4 100755 --- a/app/views/origami/payments/show.html.erb +++ b/app/views/origami/payments/show.html.erb @@ -148,7 +148,7 @@
    <% if @other != 0.0 %> -
    +
    MPU
    <%= @other %>
    @@ -162,7 +162,7 @@ <% end %> <% if @ppamount != 0.0 %> -
    +
    Redeem
    <%= @ppamount %>
    @@ -176,7 +176,7 @@ <% end %> <% if @visacount != 0.0 %> -
    +
    Visa
    <%= @visacount %>
    @@ -190,7 +190,7 @@ <% end %> <% if @jcbcount != 0.0 %> -
    +
    JCB
    <%= @jcbcount %>
    @@ -204,7 +204,7 @@ <% end %> <% if @mastercount != 0.0 %> -
    +
    Master
    <%= @mastercount %>
    diff --git a/app/views/origami/redeem_payments/index.html.erb b/app/views/origami/redeem_payments/index.html.erb index 50347dd1..23b6dc29 100755 --- a/app/views/origami/redeem_payments/index.html.erb +++ b/app/views/origami/redeem_payments/index.html.erb @@ -174,9 +174,10 @@ data: {redeem_amount:redeem_amount,membership_id:membership_id,sale_id:sale_id}, success: function(result){ if(result.status == true){ + console.log(result) swal({ title: "Information!", - text: result.status, + text: result.message, }, function () { window.location.href = '/origami/sale/'+ sale_id + "/payment" }); diff --git a/app/views/reports/saleitem/_shift_sale_report_filter.html.erb b/app/views/reports/saleitem/_shift_sale_report_filter.html.erb index b6dfe98f..c913b592 100755 --- a/app/views/reports/saleitem/_shift_sale_report_filter.html.erb +++ b/app/views/reports/saleitem/_shift_sale_report_filter.html.erb @@ -3,7 +3,7 @@ <% if period_type != false %>
    - +