diff --git a/app/assets/javascripts/CRM.js b/app/assets/javascripts/CRM.js index ff41cfdd..4b5baba8 100644 --- a/app/assets/javascripts/CRM.js +++ b/app/assets/javascripts/CRM.js @@ -18,3 +18,5 @@ //= require cable //= require jquery-ui //= require bootstrap-datepicker +//= require bootstrap/modal + diff --git a/app/assets/javascripts/OQS.js b/app/assets/javascripts/OQS.js index e3f42da8..3c532846 100644 --- a/app/assets/javascripts/OQS.js +++ b/app/assets/javascripts/OQS.js @@ -18,46 +18,71 @@ //= require cable $(document).ready(function(){ + // auto refresh every 10 seconds // setTimeout(function(){ // window.location.reload(1); // }, 10000); $('.queue_station').on('click',function(){ - var orderZone=$(this).children().children().children('.order-zone').text(); - var orderItem=$(this).children().children().children('.order-item').text(); - var orderQty=$(this).children().children().children('.order-qty').text(); - var orderBy=$(this).children().children().children().children('.order-by').text(); - var orderAt=$(this).children().children().children().children('.order-at').text(); - var orderCustomer=$(this).children().children('.order-customer').text(); + var orderZone=$(this).children().children().children('.order-zone').text().trim(); + // var orderItem=$(this).children().children().children('.order-item').text(); + //var assigned_item_id = $(this).children().find(".assigned-order-item").text(); + var orderQty = $(this).children().children().children('.order-qty').text(); + var orderBy = $(this).children().children().children().children('.order-by').text(); + var orderAt = $(this).children().children().children().children('.order-at').text(); + var orderCustomer = $(this).children().children('.order-customer').text(); + var order_status = $(this).children().children('.order-status').text(); $('#order-title').text("ORDER DETAILS - " + orderZone); $('#order-by').text(orderBy); $('#order-at').text(orderAt); $('#order-customer').text(orderCustomer); $('#order-from').text(orderZone); + // clear order items + $("#oqs-order-details-table").children("tbody").empty(); - $('#order-items').text(orderItem); - $('#order-qty').text(orderQty); + // Call get_order_items() for Order Items by dining + $.ajax({ + type: 'GET', + url: '/oqs/' + orderZone, + data: { 'status' : order_status }, + success: function(res){ + for (i = 0; i < res.length; i++) { + var data = JSON.stringify(res[i]); + var parse_data = JSON.parse(data); + + var order_item_row = "" + + "" + parse_data.item_name + "" + + "" + parse_data.qty + "" + + ""; + $("#oqs-order-details-table").children("tbody").append(order_item_row); + } + } + }) + + // $('#order-items').text(orderItem); + // $('#order-qty').text(orderQty); $('.queue_station').removeClass('selected-item'); $(this).addClass('selected-item'); }); // complete for queue item - $('.order-complete').on('click',function(e){ + $('.order-complete').on('click',function(e){ //e.preventDefault(); - var _self = $(this); // To know in ajax return - var assigned_item_id=$(this).attr('id').substr(15); + var _self = $(this); // To know in ajax return + var assigned_item_id=$(this).attr('id').substr(15); var params = { 'id':assigned_item_id }; - + + // Call update_delivery_status() for changed delivery and move to delivery $.ajax({ type: 'POST', url: '/oqs/update_delivery', data: params, dataType: 'json', - success: function(data){ - for (i = 0; i < data.length; i++) { + success: function(data){ + for (i = 0; i < data.length; i++) { var queue_station = $('#assigned_queue_' + data[i]).parent().parent(".queue_station"); var station = queue_station.parent().parent().attr('id'); @@ -66,7 +91,7 @@ $(document).ready(function(){ // Remove a queue card from current station queue_station.children('.card-footer').remove(); - + // Add removed queue card from station to completed $("#completed").children('.card-columns').append(queue_station); @@ -74,33 +99,37 @@ $(document).ready(function(){ var station_count=parseInt($("#"+station+"_count").text()) - 1; $("#"+station+"_count").text(station_count); } - - // update queue item count in completed station + + // update queue item count in completed station $("#completed_count").text(parseInt($("#completed_count").text()) + data.length); alert("updated!"); // Page reload location.reload(); } - }); + }); }); + // Print Order Item $('#print_order_item').on('click',function(){ - var assigned_item_id=$('.selected-item').children('.card-block').children('.assigned-order-item').text(); + var assigned_item_id=$('.selected-item').children('.card-block').children('.assigned-order-item').text(); var params = { 'id':assigned_item_id }; $.ajax({ type: 'GET', - url: '/oqs/print/print/'+assigned_item_id, + url: '/oqs/print/print/'+assigned_item_id, success: function(data){ } }); }); + // Print Order Summary $('#print_order_summary').on('click',function(){ - var assigned_item_id=$('.selected-item').children('.card-block').children('.assigned-order-item').text(); - var params = { 'id':assigned_item_id }; + var table_name=$('.selected-item').children().children().children('.order-zone').text().trim(); + var assigned_item_id=$('.selected-item').children('.card-block').children('.assigned-order-item').text(); + var params = { 'table_name':table_name }; $.ajax({ type: 'GET', - url: '/oqs/print/print_order_summary/'+assigned_item_id, + url: '/oqs/print/print_order_summary/'+assigned_item_id, + data: params, success: function(data){ } }); }); diff --git a/app/assets/javascripts/origami.js b/app/assets/javascripts/origami.js index 6149a2bc..d4071432 100644 --- a/app/assets/javascripts/origami.js +++ b/app/assets/javascripts/origami.js @@ -55,7 +55,7 @@ $(document).ready(function(){ var cashier=""; var receipt_date=""; - var sub_total=0; + var sub_total=0.0; var discount_amount=0; var tax_amount=0; var grand_total_amount=0; @@ -69,11 +69,11 @@ $(document).ready(function(){ type: "POST", url: "/origami/" + unique_id, data: { 'booking_id' : unique_id }, - success:function(result){ + success:function(result){ for (i = 0; i < result.length; i++) { var data = JSON.stringify(result[i]); var parse_data = JSON.parse(data); - var show_date = ""; + var show_date = ""; // Receipt Header receipt_no = result[i].receipt_no; @@ -81,36 +81,37 @@ $(document).ready(function(){ if(result[i].receipt_date != null){ receipt_date = new Date(result[i].receipt_date); show_date = receipt_date.getDate() + "-" + receipt_date.getMonth() + "-" + receipt_date.getFullYear() + ' ' + receipt_date.getHours()+ ':' + receipt_date.getMinutes() - } - - $("#receipt_no").text(receipt_no); - $("#cashier").text(cashier == null ? "" : cashier); - $("#receipt_date").text(show_date); - + } //Receipt Charges - sub_total += (parse_data.qty*parse_data.price); + sub_total += parseFloat(parse_data.price); discount_amount = parse_data.discount_amount == null? '0.0' : parse_data.discount_amount; tax_amount = parse_data.tax_amount; - grand_total_amount = parse_data.grand_total_amount; - - $("#order-sub-total").text(sub_total); - // $("#order-food").text(''); - // $("#order-beverage").text(''); - $("#order-discount").text(discount_amount); - $("#order-Tax").text(tax_amount); - $("#order-grand-total").text(grand_total_amount); + grand_total_amount = parse_data.grand_total_amount; // Ordered Items var order_items_rows = "" + "" + parse_data.item_name + "" + "" + parse_data.qty + "" + - "" + parse_data.qty*parse_data.price + "" + + "" + parse_data.price + "" + ""; $("#order-items-table").children("tbody").append(order_items_rows); } + + // Cashier Info + $("#receipt_no").text(receipt_no); + $("#cashier").text(cashier == null ? "" : cashier); + $("#receipt_date").text(show_date); + + // Payment Info + $("#order-sub-total").text(sub_total); + // $("#order-food").text(''); + // $("#order-beverage").text(''); + $("#order-discount").text(discount_amount); + $("#order-Tax").text(tax_amount); + $("#order-grand-total").text(grand_total_amount); } }); // End AJAX Call @@ -121,7 +122,7 @@ $(document).ready(function(){ // Bill Request $('#request_bills').click(function() { - var order_id=$(".selected-item").find(".orders-id").text(); + var order_id=$(".selected-item").find(".orders-id").text().substr(0,16); if(order_id!=""){ window.location.href = '/origami/' + order_id + '/request_bills' } @@ -133,7 +134,8 @@ $(document).ready(function(){ // Discount for Payment $('#discount').click(function() { - var order_id=$(".selected-item").find(".orders-id").text(); + var order_id=$(".selected-item").find(".orders-id").text().substr(0,16); + if(order_id!=""){ window.location.href = '/origami/' + order_id + '/discount' } @@ -148,7 +150,7 @@ $(document).ready(function(){ $("#pay-discount").on('click', function(e){ e.preventDefault(); var sale_id = $('#sale-id').text(); - var sale_item_id = $('.selected-item').attr('id'); + var sale_item_id = $('.selected-item').attr('id').substr(0,16); var sub_total = $('#order-sub-total').text(); var grand_total = $('#order-grand-total').text(); var discount_type = $('#discount-type').val(); @@ -178,7 +180,7 @@ $(document).ready(function(){ // Payment for Bill $('#pay-bill').click(function() { - var sale_id=$(".selected-item").find(".orders-id").text(); + var sale_id=$(".selected-item").find(".orders-id").text().substr(0,16); if(sale_id!=""){ window.location.href = '/origami/sale/'+ sale_id + "/payment" } @@ -190,7 +192,7 @@ $(document).ready(function(){ }); $('#customer').click(function() { - var sale = $(".selected-item").find(".orders-id").text(); + var sale = $(".selected-item").find(".orders-id").text().substr(0,16); if (sale.substring(0, 3)=="SAL") { var sale_id = sale }else{ @@ -202,7 +204,7 @@ $(document).ready(function(){ }); $('#re-print').click(function() { - var sale_id = $(".selected-item").find(".orders-id").text(); + var sale_id = $(".selected-item").find(".orders-id").text().substr(0,16); window.location.href = '/origami/'+ sale_id + "/reprint" diff --git a/app/assets/javascripts/settings/processing_items.js b/app/assets/javascripts/settings/processing_items.js index 445b46d5..60c53ba4 100644 --- a/app/assets/javascripts/settings/processing_items.js +++ b/app/assets/javascripts/settings/processing_items.js @@ -40,7 +40,7 @@ $(document).on('turbolinks:load', function() { items.push($(value).attr("data-id")); }); - $("#order_queue_station_processing_items").val(items); + $("#order_queue_station_processing_items").val(JSON.stringify(items)); //$(this).submit(); }) }) diff --git a/app/assets/stylesheets/CRM.scss b/app/assets/stylesheets/CRM.scss index a88efe96..8ddc1605 100644 --- a/app/assets/stylesheets/CRM.scss +++ b/app/assets/stylesheets/CRM.scss @@ -3,6 +3,7 @@ @import "theme"; @import "jquery-ui"; @import "bootstrap-datepicker3"; +@import "bootstrap/modal"; /* Show it is fixed to the top */ // body { @@ -10,4 +11,15 @@ // padding-top: 4.5rem; // } +.selected-item { + color: #fff !important; + background-color: #ccc !important; +} +.assign { + color: #fff !important; + background-color: red; +} +.assign .text-muted{ + color: #fff !important; +} diff --git a/app/controllers/api/bill_controller.rb b/app/controllers/api/bill_controller.rb index 94b785f5..cd2f8b47 100644 --- a/app/controllers/api/bill_controller.rb +++ b/app/controllers/api/bill_controller.rb @@ -15,14 +15,29 @@ class Api::BillController < Api::ApiController @status, @sale_id = @sale.generate_invoice_from_booking(params[:booking_id], current_login_employee) else @status = true + @sale_id = booking.sale_id end end elsif (params[:order_id]) @sale = Sale.new @status, @sale_id = @sale.generate_invoice_from_order(params[:order_id], current_login_employee) - end + @sale_data = Sale.find_by_sale_id(@sale_id) + @sale_items = SaleItem.where("sale_id=?",@sale_id) + + unique_code = "ReceiptBillPdf" + customer= Customer.where('customer_id=' + @sale_data.customer_id) + + # get printer info + print_settings=PrintSetting.find_by_unique_code(unique_code) + + # Calculate Food and Beverage Total + + food_total, beverage_total = SaleItem.calculate_food_beverage(@sale_items) + + printer = Printer::ReceiptPrinter.new(print_settings) + printer.print_receipt_bill(print_settings,@sale_items,@sale_data,customer.name, food_total, beverage_total) end diff --git a/app/controllers/base_report_controller.rb b/app/controllers/base_report_controller.rb index c1ae1a01..0ea51cf5 100644 --- a/app/controllers/base_report_controller.rb +++ b/app/controllers/base_report_controller.rb @@ -23,55 +23,117 @@ class BaseReportController < ActionController::Base period = params[:period] from = params[:from] to = params[:to] - day_ref = Time.now - if period_type.to_i == 1 - if params[:from] && params[:to] - if params[:from] != "" && params[:to] !="" - from = DateTime.strptime(params[:from], "%m/%d/%Y") - to = DateTime.strptime(params[:to], "%m/%d/%Y") - else + day_ref = Time.now.utc.getlocal + + if params[:report_type] == "daily_sale" + + if from != "" && to != "" + + f_date = DateTime.parse(params[:from]) + t_date = DateTime.parse(params[:to]) + f_time = Time.mktime(f_date.year,f_date.month,f_date.day,f_date.hour,f_date.min,f_date.sec) + t_time = Time.mktime(t_date.year,t_date.month,t_date.day,t_date.hour,t_date.min,t_date.sec) + from = f_time.beginning_of_day.utc.getlocal + to = t_time.end_of_day.utc.getlocal + + else + + case period.to_i + when PERIOD["today"] + from = day_ref.beginning_of_day.utc to = day_ref.end_of_day.utc - end - end - else - case period.to_i - when PERIOD["today"] - from = day_ref.beginning_of_day.utc - to = day_ref.end_of_day.utc + when PERIOD["yesterday"] + from = (day_ref - 1.day).beginning_of_day.utc + to = (day_ref - 1.day).end_of_day.utc - when PERIOD["yesterday"] - from = (day_ref - 1.day).beginning_of_day.utc - to = (day_ref - 1.day).end_of_day.utc + when PERIOD["this_week"] + from = Time.now.beginning_of_week.utc + to = Time.now.utc + when PERIOD["last_week"] + from = (day_ref - 7.day).beginning_of_week.utc + to = (day_ref - 7.day).end_of_week.utc + when PERIOD["last_7"] + from = (day_ref - 7.day).utc + to = Time.now.utc + when PERIOD["this_month"] + from = Time.now.beginning_of_month.utc + to = Time.now.utc + when PERIOD["last_month"] + from = (day_ref - 1.month).beginning_of_month.utc + to = (day_ref - 1.month).end_of_month.utc + when PERIOD["last_30"] + from = (day_ref - 30.day).utc + to = Time.now.utc + when PERIOD["this_year"] + from = Time.now.beginning_of_year.utc + to = Time.now.utc + when PERIOD["last_year"] + from = (day_ref - 1.year).beginning_of_year.utc + to = (day_ref - 1.year).end_of_year.utc + end + end + else # end daily sale report + if period_type.to_i == 1 + + if params[:from] && params[:to] - when PERIOD["this_week"] - from = Time.now.beginning_of_week.utc - to = Time.now.utc - when PERIOD["last_week"] - from = (day_ref - 7.day).beginning_of_week.utc - to = (day_ref - 7.day).end_of_week.utc - when PERIOD["last_7"] - from = (day_ref - 7.day).utc - to = Time.now.utc - when PERIOD["this_month"] - from = Time.now.beginning_of_month.utc - to = Time.now.utc - when PERIOD["last_month"] - from = (day_ref - 1.month).beginning_of_month.utc - to = (day_ref - 1.month).end_of_month.utc - when PERIOD["last_30"] - from = (day_ref - 30.day).utc - to = Time.now.utc - when PERIOD["this_year"] - from = Time.now.beginning_of_year.utc - to = Time.now.utc - when PERIOD["last_year"] - from = (day_ref - 1.year).beginning_of_year.utc - to = (day_ref - 1.year).end_of_year.utc - end + if params[:from] != "" && params[:to] !="" + + f_date = DateTime.parse(params[:from]) + t_date = DateTime.parse(params[:to]) + f_time = Time.mktime(f_date.year,f_date.month,f_date.day,f_date.hour,f_date.min,f_date.sec) + t_time = Time.mktime(t_date.year,t_date.month,t_date.day,t_date.hour,t_date.min,t_date.sec) + from = f_time.beginning_of_day.utc.getlocal + to = t_time.end_of_day.utc.getlocal + else + from = day_ref.beginning_of_day.utc + to = day_ref.end_of_day.utc + end + end + else + case period.to_i + when PERIOD["today"] + + from = day_ref.beginning_of_day.utc + to = day_ref.end_of_day.utc + + when PERIOD["yesterday"] + from = (day_ref - 1.day).beginning_of_day.utc + to = (day_ref - 1.day).end_of_day.utc + + when PERIOD["this_week"] + from = Time.now.beginning_of_week.utc + to = Time.now.utc + when PERIOD["last_week"] + from = (day_ref - 7.day).beginning_of_week.utc + to = (day_ref - 7.day).end_of_week.utc + when PERIOD["last_7"] + from = (day_ref - 7.day).utc + to = Time.now.utc + when PERIOD["this_month"] + from = Time.now.beginning_of_month.utc + to = Time.now.utc + when PERIOD["last_month"] + from = (day_ref - 1.month).beginning_of_month.utc + to = (day_ref - 1.month).end_of_month.utc + when PERIOD["last_30"] + from = (day_ref - 30.day).utc + to = Time.now.utc + when PERIOD["this_year"] + from = Time.now.beginning_of_year.utc + to = Time.now.utc + when PERIOD["last_year"] + from = (day_ref - 1.year).beginning_of_year.utc + to = (day_ref - 1.year).end_of_year.utc + end + end end + return from, to + + end end diff --git a/app/controllers/crm/customers_controller.rb b/app/controllers/crm/customers_controller.rb index 4cacae00..290f6ca1 100644 --- a/app/controllers/crm/customers_controller.rb +++ b/app/controllers/crm/customers_controller.rb @@ -117,7 +117,7 @@ class Crm::CustomersController < BaseCrmController # format.json { render :index, status: :created, location: @crm_customers } else - @crm_customers.destroy + # @crm_customers.destroy if params[:sale_id] format.html { redirect_to '/origami/'+params[:sale_id]+'/customers'} else diff --git a/app/controllers/crm/dining_queues_controller.rb b/app/controllers/crm/dining_queues_controller.rb index 41655d98..251b0781 100644 --- a/app/controllers/crm/dining_queues_controller.rb +++ b/app/controllers/crm/dining_queues_controller.rb @@ -4,7 +4,8 @@ class Crm::DiningQueuesController < BaseCrmController # GET /crm/dining_queues # GET /crm/dining_queues.json def index - @dining_queues = DiningQueue.all + today = DateTime.now.strftime('%Y-%m-%d') + @dining_queues = DiningQueue.where("DATE_FORMAT(created_at,'%Y-%m-%d') = ? ", today).order("queue_no asc") end # GET /crm/dining_queues/1 @@ -38,7 +39,7 @@ class Crm::DiningQueuesController < BaseCrmController printer = Printer::ReceiptPrinter.new(print_settings) printer.print_queue_no(print_settings,@dining_queue) - format.html { redirect_to crm_dining_queues_path, notice: 'Dining queue was successfully created.' } + format.html { redirect_to crm_dining_queues_path, notice: 'Queue was successfully created.' } format.json { render :show, status: :created, location: @dining_queue } else format.html { render :new } @@ -52,7 +53,7 @@ class Crm::DiningQueuesController < BaseCrmController def update respond_to do |format| if @dining_queue.update(dining_queue_params) - format.html { redirect_to crm_dining_queues_path, notice: 'Dining queue was successfully updated.' } + format.html { redirect_to crm_dining_queues_path, notice: 'Queue was successfully updated.' } format.json { render :show, status: :ok, location: @dining_queue } else format.html { render :edit } @@ -71,6 +72,27 @@ class Crm::DiningQueuesController < BaseCrmController end end + def assign + @queue = DiningQueue.find(params[:id]) + @tables = DiningFacility.where("status = 'available' ") + respond_to do |format| + format.html # index.html.erb + end + end + + def assign_table + queue = DiningQueue.find(params[:id]) + table_id = params[:table_id] + + queue.update_attributes(dining_facility_id: table_id,status:"Assign") + DiningFacility.find(table_id).update_attributes(status: "occupied") + respond_to do |format| + format.html { redirect_to crm_dining_queues_path, notice: 'Table was successfully assigned.' } + format.json { head :no_content } + end + end + + private # Use callbacks to share common setup or constraints between actions. def set_dining_queue @@ -79,6 +101,6 @@ class Crm::DiningQueuesController < BaseCrmController # Never trust parameters from the scary internet, only allow the white list through. def dining_queue_params - params.require(:dining_queue).permit(:name, :contact_no, :queue_no) + params.require(:dining_queue).permit(:name, :contact_no, :queue_no,:status) end end diff --git a/app/controllers/oqs/home_controller.rb b/app/controllers/oqs/home_controller.rb index 7af42166..14d79857 100644 --- a/app/controllers/oqs/home_controller.rb +++ b/app/controllers/oqs/home_controller.rb @@ -1,27 +1,65 @@ class Oqs::HomeController < BaseOqsController def index queue_stations=OrderQueueStation.all - - @queue_items_details = queue_items_query(0) - @queue_completed_item = queue_items_query(1) - + @queue_items_details = queue_items_query(false) + + @queue_completed_item = queue_items_query(true) + @queue_stations_items=Array.new # Calculate Count for each station tab - queue_stations.each do |que| + queue_stations.each do |que| i=0 - @queue_items_details.each do |qid| - if qid.station_name == que.station_name - i=i+1 - end - end - @queue_stations_items.push({:station_name => que.station_name, :is_active => que.is_active ,:item_count => i }) + @queue_items_details.each do |qid| + if qid.station_name == que.station_name + i=i+1 + end + end + @queue_stations_items.push({:station_name => que.station_name, :is_active => que.is_active ,:item_count => i }) end @queue_stations_items end + # Get Order items + def get_order_items + items = [] + table_name = params[:table_id] + status = params[:status] + dining = DiningFacility.find_by_name(table_name); + # oqpz = OrderQueueProcessByZone.find_by_zone_id(dining.zone_id) + # if status == "" + # AssignedOrderItem.where("order_queue_station_id=#{ oqpz.order_queue_station_id } AND delivery_status=0").find_each do |aoi| + # oi = OrderItem.find_by_item_code(aoi.item_code) + # items.push(oi) + # end + # else + # AssignedOrderItem.where("order_queue_station_id=#{ oqpz.order_queue_station_id } AND delivery_status=1").find_each do |aoi| + # oi = OrderItem.find_by_item_code(aoi.item_code) + # items.push(oi) + # end + # end + + booking = Booking.find_by_dining_facility_id(dining.id) + BookingOrder.where("booking_id='#{ booking.booking_id }'").find_each do |bo| + order=Order.find(bo.order_id) + order.order_items.each do |oi| + items.push(oi) + end + end + + # booking_id = dining.get_new_booking + # BookingOrder.where("booking_id='#{ booking_id }'").find_each do |bo| + # order=Order.find(bo.order_id); + # order.order_items.each do |oi| + # items.push(oi) + # end + # end + + render :json => items.to_json + end + def show end @@ -35,24 +73,33 @@ class Oqs::HomeController < BaseOqsController # update delivery status for completed same order items assigned_items.each do |ai| ai.delivery_status=true - ai.save + ai.save removed_item.push(ai.assigned_order_item_id) - end - render :json => removed_item.to_json + end + render :json => removed_item.to_json end # Query for OQS with status def queue_items_query(status) + # AssignedOrderItem.select("assigned_order_items.assigned_order_item_id, oqs.station_name, oqs.is_active, df.name as zone, odt.item_code, odt.item_name, odt.price, odt.qty, odt.item_order_by, cus.name as customer_name, odt.created_at") + # .joins(" left join order_queue_process_by_zones as oqpz ON oqpz.order_queue_station_id = assigned_order_items.order_queue_station_id + # left join dining_facilities as df on df.zone_id = oqpz.zone_id + # left join order_queue_stations as oqs ON oqs.id = assigned_order_items.order_queue_station_id + # left join orders as od ON od.order_id = assigned_order_items.order_id + # left join order_items as odt ON odt.item_code = assigned_order_items.item_code + # left join customers as cus ON cus.customer_id = od.customer_id") + # .where("assigned_order_items.delivery_status = #{status}") + # .group("assigned_order_items.assigned_order_item_id") + # .order("odt.item_name DESC") AssignedOrderItem.select("assigned_order_items.assigned_order_item_id, oqs.station_name, oqs.is_active, df.name as zone, odt.item_code, odt.item_name, odt.price, odt.qty, odt.item_order_by, cus.name as customer_name, odt.created_at") - .joins(" left join order_queue_process_by_zones as oqpz ON oqpz.order_queue_station_id = assigned_order_items.order_queue_station_id - left join dining_facilities as df on df.zone_id = oqpz.zone_id - left join order_queue_stations as oqs ON oqs.id = assigned_order_items.order_queue_station_id + .joins(" left join order_queue_stations as oqs on oqs.id = assigned_order_items.order_queue_station_id left join orders as od ON od.order_id = assigned_order_items.order_id left join order_items as odt ON odt.item_code = assigned_order_items.item_code - left join customers as cus ON cus.customer_id = od.customer_id") + left join customers as cus ON cus.customer_id = od.customer_id + left join booking_orders as bo on bo.order_id = assigned_order_items.order_id + left join bookings as bk on bk.booking_id = bo.booking_id + left join dining_facilities as df on df.id = bk.dining_facility_id") .where("assigned_order_items.delivery_status = #{status}") .group("assigned_order_items.assigned_order_item_id") - .order("odt.item_name DESC") end end - diff --git a/app/controllers/oqs/print_controller.rb b/app/controllers/oqs/print_controller.rb index 9fc2a2d7..ff2cf98d 100644 --- a/app/controllers/oqs/print_controller.rb +++ b/app/controllers/oqs/print_controller.rb @@ -9,10 +9,13 @@ class Oqs::PrintController < ApplicationController # order queue stations oqs = assigned_item.order_queue_station + # Check Printed + print_status = assigned_item.print_status == true ? " (Re-Print)" : "" + # print when complete click print_settings=PrintSetting.find_by_unique_code(unique_code) order_queue_printer= Printer::OrderQueuePrinter.new(print_settings) - order_queue_printer.print_order_item(oqs,assigned_item.order_id, assigned_item.item_code ) + order_queue_printer.print_order_item(oqs, assigned_item.order_id, assigned_item.item_code, print_status ) # update print status for completed same order items assigned_items.each do |ai| @@ -21,20 +24,28 @@ class Oqs::PrintController < ApplicationController end end - # Print Order Details + # Print Order Details with booking id def print_order_summary unique_code="OrderSummaryPdf" assigned_item_id=params[:id] + table_name=params[:table_name] assigned_item=AssignedOrderItem.find(assigned_item_id) assigned_items=AssignedOrderItem.where("item_code='" + assigned_item.item_code + "' AND " + "order_id='" + assigned_item.order_id + "'"); # order queue stations oqs = assigned_item.order_queue_station + + # Check Printed + print_status = assigned_item.print_status == true ? " (Re-Print)" : "" + + # get dining + dining = DiningFacility.find_by_name(table_name); + booking = Booking.find_by_dining_facility_id(dining.id) # print when complete click print_settings=PrintSetting.find_by_unique_code(unique_code) order_queue_printer= Printer::OrderQueuePrinter.new(print_settings) - order_queue_printer.print_order_summary(oqs,assigned_item.order_id) + order_queue_printer.print_booking_summary(oqs, booking.booking_id, print_status) # update print status for completed same order items assigned_items.each do |ai| diff --git a/app/controllers/origami/home_controller.rb b/app/controllers/origami/home_controller.rb index dbde3293..1aca9b2d 100644 --- a/app/controllers/origami/home_controller.rb +++ b/app/controllers/origami/home_controller.rb @@ -1,8 +1,8 @@ class Origami::HomeController < BaseOrigamiController def index if params[:booking_id] != nil - type=params[:booking_id].split('-')[0]; - # Sale + type=params[:booking_id].split('-')[0]; + # Sale if type == "SAL" @selected_item = Sale.find(params[:booking_id]) @selected_item_type="Sale" @@ -10,23 +10,23 @@ class Origami::HomeController < BaseOrigamiController else @selected_item = Order.find(params[:booking_id]) @selected_item_type="Order" - end - end + end + end @completed_orders = Order.get_completed_order() @booking_orders = Order.get_booking_order_table() - @booking_rooms = Order.get_booking_order_rooms() + @booking_rooms = Order.get_booking_order_rooms() @orders = Order.get_orders() - end + end def item_show selection(params[:booking_id],1) - end + end def selection(selected_id, is_ajax) str = [] - type=selected_id.split('-')[0]; - # Sale + type=selected_id.split('-')[0]; + # Sale if type == "SAL" @order_details = SaleItem.get_order_items_details(params[:booking_id]) @order_details.each do |ord_detail| @@ -39,6 +39,7 @@ class Origami::HomeController < BaseOrigamiController str.push(ord_detail) end end + if is_ajax == 1 render :json => str.to_json else @@ -54,21 +55,21 @@ class Origami::HomeController < BaseOrigamiController else sale = Order.find(params[:sale_id]) end - + status = sale.update_attributes(customer_id: params[:customer_id]) - + if status == true render json: JSON.generate({:status => true}) else render json: JSON.generate({:status => false, :error_message => "Record not found"}) - end + end end def get_customer @customer = Customer.find(params[:customer_id]) - + response = Customer.get_member_account(@customer) respond_to do |format| diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index ca497b81..44de8eb2 100644 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -12,7 +12,7 @@ class Origami::PaymentsController < BaseOrigamiController sale_payment = SalePayment.new sale_payment.process_payment(saleObj, @user, cash, "cash") - unique_code = "ReceiptBillPdf" + unique_code = "ReceiptBillPdf" customer= Customer.find(saleObj.customer_id) # get member information @@ -20,11 +20,10 @@ class Origami::PaymentsController < BaseOrigamiController # get printer info print_settings=PrintSetting.find_by_unique_code(unique_code) - # Calculate Food and Beverage Total food_total, beverage_total = SaleItem.calculate_food_beverage(saleObj.sale_items) - printer = Printer::ReceiptPrinter.new(print_settings) + printer = Printer::ReceiptPrinter.new(print_settings) printer.print_receipt_bill(print_settings,saleObj.sale_items,saleObj,customer.name, food_total, beverage_total, member_info) end end @@ -41,14 +40,14 @@ class Origami::PaymentsController < BaseOrigamiController @sale_data = Sale.find_by_sale_id(sale_id) #get customer amount - @customer = Customer.find(@sale_data.customer_id) + @customer = Customer.find(@sale_data.customer_id) # get member information response = Customer.get_member_account(@customer) @balance = 0.00 @accountable_type = '' - if response["data"]==true + if response["status"]==true response["data"].each do |res| if res["accountable_type"] == "RebateAccount" @balance = res["balance"] @@ -84,19 +83,19 @@ class Origami::PaymentsController < BaseOrigamiController saleObj = Sale.find(sale_id) - unique_code = "ReceiptBillPdf" + unique_code = "ReceiptBillPdf" customer= Customer.find(saleObj.customer_id) # get member information member_info = Customer.get_member_account(customer) - + # get printer info print_settings=PrintSetting.find_by_unique_code(unique_code) # Calculate Food and Beverage Total food_total, beverage_total = SaleItem.calculate_food_beverage(saleObj.sale_items) - printer = Printer::ReceiptPrinter.new(print_settings) + printer = Printer::ReceiptPrinter.new(print_settings) printer.print_receipt_bill(print_settings,saleObj.sale_items,saleObj,customer.name, food_total, beverage_total, member_info) end diff --git a/app/controllers/origami/redeem_payments_controller.rb b/app/controllers/origami/redeem_payments_controller.rb index 99601449..792cb7a4 100644 --- a/app/controllers/origami/redeem_payments_controller.rb +++ b/app/controllers/origami/redeem_payments_controller.rb @@ -6,7 +6,8 @@ class Origami::RedeemPaymentsController < BaseOrigamiController sale_data = Sale.find_by_sale_id(@sale_id) # limit redeem_amount - food_prices, beverage_prices = SaleItem.calculate_food_beverage(sale_data.sale_items) + rebate_prices = SaleItem.calculate_food_beverage(sale_data.sale_items) + nonrebate_prices = sale_data.total_amount - rebate_prices @payparcount = 0 others = 0 sale_data.sale_payments.each do |sale_payment| @@ -16,11 +17,11 @@ class Origami::RedeemPaymentsController < BaseOrigamiController others = others + sale_payment.payment_amount end end - is_bervage_exceed = others - (beverage_prices + sale_data.total_tax) - if is_bervage_exceed < 0 - @food_prices = food_prices - @payparcount + non_rebate_exceed = others - (nonrebate_prices + sale_data.total_tax) + if non_rebate_exceed < 0 + @redeem_prices = rebate_prices - @payparcount else - @food_prices = food_prices - @payparcount -is_bervage_exceed + @redeem_prices = rebate_prices - @payparcount -non_rebate_exceed end if sale_data diff --git a/app/controllers/reports/daily_sale_controller.rb b/app/controllers/reports/daily_sale_controller.rb index b487c269..86e60702 100644 --- a/app/controllers/reports/daily_sale_controller.rb +++ b/app/controllers/reports/daily_sale_controller.rb @@ -1,9 +1,25 @@ class Reports::DailySaleController < BaseReportController def index - from, to = get_date_range_from_params - @sale_data = Sale.get_receipt_no_list(from,to) - @sale_data = Kaminari.paginate_array(@sale_data).page(params[:page]).per(50) + from, to = get_date_range_from_params + @sale_data = Sale.daily_sales_list(from,to) + @tax = SaleTax.get_tax(from,to) + end + + # @locations = Location.all + + # branch,from, to, report_type = get_date_range_from_params + + # @location = Location.find_by_id(current_location) + # @sale_data = Sale.daily_sales_report(current_location,from,to) + # @tax = SaleT.get_tax(current_location,from,to) + + # if @sale_data.blank? && @tax.blank? && request.post? + # flash.now[:notice] = "No data available for selected filters" + # end + + def show + end end \ No newline at end of file diff --git a/app/controllers/settings/accounts_controller.rb b/app/controllers/settings/accounts_controller.rb index 74f27c84..90e6a304 100644 --- a/app/controllers/settings/accounts_controller.rb +++ b/app/controllers/settings/accounts_controller.rb @@ -68,6 +68,6 @@ class Settings::AccountsController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def account_params - params.require(:account).permit(:title, :account_type) + params.require(:account).permit(:title, :account_type,:discount,:point,:bonus,:rebate) end end diff --git a/app/controllers/settings/order_queue_stations_controller.rb b/app/controllers/settings/order_queue_stations_controller.rb index 408519d2..bc7766a7 100644 --- a/app/controllers/settings/order_queue_stations_controller.rb +++ b/app/controllers/settings/order_queue_stations_controller.rb @@ -41,7 +41,7 @@ class Settings::OrderQueueStationsController < ApplicationController # PATCH/PUT /settings/order_queue_stations/1 # PATCH/PUT /settings/order_queue_stations/1.json def update - params[:order_queue_station][:processing_items] = params[:order_queue_station][:processing_items].split(/,/).inspect + # params[:order_queue_station][:processing_items] = params[:order_queue_station][:processing_items].split(/,/).inspect respond_to do |format| if @settings_order_queue_station.update(settings_order_queue_station_params) format.html { redirect_to settings_order_queue_station_path(@settings_order_queue_station), notice: 'Order queue station was successfully updated.' } @@ -71,6 +71,11 @@ class Settings::OrderQueueStationsController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def settings_order_queue_station_params +# <<<<<<< HEAD params.require(:order_queue_station).permit(:station_name, :is_active, :auto_print, :processing_items, :print_copy, :printer_name, :font_size, :cut_per_item, :use_alternate_name, :created_by) +# ======= +# Don't Know { zone_ids: [] } +# params.require(:order_queue_station).permit(:station_name, :is_active, :processing_items, :print_copy, :printer_name, :font_size, :cut_per_item, :use_alternate_name, :created_by,{ zone_ids: [] }) +# >>>>>>> b093a993ba002c92659bbb34338c55c031c11d87 end end diff --git a/app/controllers/settings/rooms_controller.rb b/app/controllers/settings/rooms_controller.rb new file mode 100644 index 00000000..2d5b01e1 --- /dev/null +++ b/app/controllers/settings/rooms_controller.rb @@ -0,0 +1,83 @@ +class Settings::RoomsController < ApplicationController + before_action :set_settings_room, only: [:show, :edit, :update, :destroy] + before_action :set_settings_zone, only: [:index, :show, :edit, :new, :update,:create,:destroy] + # GET /settings/rooms + # GET /settings/rooms.json + def index + @settings_rooms = @zone.rooms + end + + # GET /settings/rooms/1 + # GET /settings/rooms/1.json + def show + @room = Room.find(params[:id]) + end + + # GET /settings/rooms/new + def new + @settings_room = Room.new + end + + # GET /settings/rooms/1/edit + def edit + end + + # POST /settings/rooms + # POST /settings/rooms.json + def create + @settings_room = Room.new(settings_room_params) + @settings_room.type = DiningFacility::ROOM_TYPE + @settings_room.zone_id = params[:zone_id] + @settings_room.created_by = current_login_employee.name + respond_to do |format| + if @settings_room.save + format.html { redirect_to settings_zone_path(@zone), notice: 'Room was successfully created.' } + format.json { render :show, status: :created, location: @settings_room } + else + puts "abc" + format.html { render :new } + format.json { render json: @settings_room.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /settings/rooms/1 + # PATCH/PUT /settings/rooms/1.json + def update + @settings_room.created_by = current_login_employee.name + respond_to do |format| + if @settings_room.update(settings_room_params) + format.html { redirect_to settings_zone_path(@zone), notice: 'Room was successfully updated.' } + format.json { render :show, status: :ok, location: @settings_room } + else + format.html { render :edit } + format.json { render json: @settings_room.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /settings/rooms/1 + # DELETE /settings/rooms/1.json + def destroy + @settings_room.destroy + respond_to do |format| + format.html { redirect_to settings_zone_path(@zone), notice: 'Room was successfully destroyed.' } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_settings_room + @settings_room = Room.find(params[:id]) + end + + def set_settings_zone + @zone = Zone.find(params[:zone_id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def settings_room_params + params.require(:room).permit(:name, :status, :seater, :order_by,:is_active ,:id, :zone_id, :created_by) + end +end diff --git a/app/controllers/settings/tables_controller.rb b/app/controllers/settings/tables_controller.rb new file mode 100644 index 00000000..7c293455 --- /dev/null +++ b/app/controllers/settings/tables_controller.rb @@ -0,0 +1,82 @@ +class Settings::TablesController < ApplicationController + before_action :set_settings_table, only: [:show, :edit, :update, :destroy] + before_action :set_settings_zone, only: [:index, :show, :edit, :new, :update,:create] + # GET /settings/tables + # GET /settings/tables.json + def index + @settings_tables = @zone.tables + end + + # GET /settings/tables/1 + # GET /settings/tables/1.json + def show + @table = Table.find(params[:id]) + end + + # GET /settings/tables/new + def new + @settings_table = Table.new + end + + # GET /settings/tables/1/edit + def edit + end + + # POST /settings/tables + # POST /settings/tables.json + def create + @settings_table = Table.new(settings_table_params) + @settings_table.type = DiningFacility::TABLE_TYPE + @settings_table.zone_id = params[:zone_id] + @settings_table.created_by = current_login_employee.name + respond_to do |format| + if @settings_table.save + format.html { redirect_to settings_zone_path(@zone), notice: 'Table was successfully created.' } + format.json { render :show, status: :created, location: @settings_table } + else + format.html { render :new } + format.json { render json: @settings_table.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /settings/tables/1 + # PATCH/PUT /settings/tables/1.json + def update + @settings_table.created_by = current_login_employee.name + respond_to do |format| + if @settings_table.update(settings_table_params) + format.html { redirect_to settings_zone_path(@zone), notice: 'Table was successfully updated.' } + format.json { render :show, status: :ok, location: @settings_table } + else + format.html { render :edit } + format.json { render json: @settings_table.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /settings/tables/1 + # DELETE /settings/tables/1.json + def destroy + @settings_table.destroy + respond_to do |format| + format.html { redirect_to settings_zone_path(@zone), notice: 'Table was successfully destroyed.' } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_settings_table + @settings_table = Table.find(params[:id]) + end + + def set_settings_zone + @zone = Zone.find(params[:zone_id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def settings_table_params + params.require(:table).permit(:name, :status, :seater, :order_by,:is_active ,:id, :zone_id, :created_by) + end +end diff --git a/app/controllers/settings/zones_controller.rb b/app/controllers/settings/zones_controller.rb index 779c03fe..08a6f189 100644 --- a/app/controllers/settings/zones_controller.rb +++ b/app/controllers/settings/zones_controller.rb @@ -10,6 +10,8 @@ class Settings::ZonesController < ApplicationController # GET /settings/zones/1 # GET /settings/zones/1.json def show + @settings_tables = @settings_zone.tables + @settings_rooms = @settings_zone.rooms end # GET /settings/zones/new @@ -25,10 +27,10 @@ class Settings::ZonesController < ApplicationController # POST /settings/zones.json def create @settings_zone = Zone.new(settings_zone_params) - + @settings_zone.created_by = current_login_employee.name respond_to do |format| if @settings_zone.save - format.html { redirect_to @settings_zone, notice: 'Zone was successfully created.' } + format.html { redirect_to settings_zone_path(@settings_zone), notice: 'Zone was successfully created.' } format.json { render :show, status: :created, location: @settings_zone } else format.html { render :new } @@ -41,8 +43,9 @@ class Settings::ZonesController < ApplicationController # PATCH/PUT /settings/zones/1.json def update respond_to do |format| + @settings_zone.created_by = current_login_employee.name if @settings_zone.update(settings_zone_params) - format.html { redirect_to @settings_zone, notice: 'Zone was successfully updated.' } + format.html { redirect_to settings_zone_path(@settings_zone), notice: 'Zone was successfully updated.' } format.json { render :show, status: :ok, location: @settings_zone } else format.html { render :edit } @@ -54,9 +57,11 @@ class Settings::ZonesController < ApplicationController # DELETE /settings/zones/1 # DELETE /settings/zones/1.json def destroy + @settings_zone.rooms.destroy + @settings_zone.tables.destroy @settings_zone.destroy respond_to do |format| - format.html { redirect_to settings_zones_url, notice: 'Zone was successfully destroyed.' } + format.html { redirect_to settings_zones_path, notice: 'Zone was successfully destroyed.' } format.json { head :no_content } end end @@ -69,6 +74,6 @@ class Settings::ZonesController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def settings_zone_params - params.require(:settings_zone).permit(:name, :is_active, :created_by) + params.require(:zone).permit(:name, :is_active, :created_by) end end diff --git a/app/models/customer.rb b/app/models/customer.rb index 0cbf8d58..de9846f2 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -9,28 +9,8 @@ class Customer < ApplicationRecord validates_presence_of :name, :contact_no, :email validates :contact_no, uniqueness: true validates :email, uniqueness: true - - paginates_per 50 - # def self.get_member_group - - # membership = MembershipSetting.find_by_membership_type("paypar_url") - # memberaction = MembershipAction.find_by_membership_type("get_all_member_group") - # app_token = membership.auth_token.to_s - - # url = membership.gateway_url.to_s + memberaction.gateway_url.to_s - # response = HTTParty.get(url, - # :body => { app_token: app_token}.to_json, - # :headers => { - # 'Content-Type' => 'application/json', - # 'Accept' => 'application/json' - # } - # ) - # puts response.body, response.code, response.message, response.headers.inspect - - # return response; - - # end + paginates_per 50 def self.get_member_account(customer) membership = MembershipSetting.find_by_membership_type("paypar_url") @@ -38,13 +18,19 @@ class Customer < ApplicationRecord merchant_uid = memberaction.merchant_account_id.to_s auth_token = memberaction.auth_token.to_s url = membership.gateway_url.to_s + memberaction.gateway_url.to_s +# urltest =self.url_exist?(url) + begin response = HTTParty.get(url, :body => { membership_id: customer.membership_id,merchant_uid:merchant_uid,auth_token:auth_token}.to_json, :headers => { 'Content-Type' => 'application/json', 'Accept' => 'application/json' - } + }, + :timeout => 10 ) + rescue Net::OpenTimeout + response = { status: false } + end return response; @@ -59,6 +45,35 @@ class Customer < ApplicationRecord end end +# require "net/http" +# def self.url_exist?(url_string) +# url = URI.parse(url_string) + + +# req = Net::HTTP.new(url.host, url.port) +# puts "hhhhhhhhhhhh" +# puts req.to_json +# req.use_ssl = (url.scheme == 'https') +# puts "aaaaaaaaaaaa" +# puts req.use_ssl? +# path = url.path if url.path.present? +# puts "bbbbbbbbbbbbb" +# puts path +# res = req.request_head(path || '/') +# puts "cccccccccccccc" +# puts res.to_json +# puts "ddddddddd" +# puts res.kind_of?(Net::HTTPRedirection) +# if res.kind_of?(Net::HTTPRedirection) +# url_exist?(res['location']) # Go after any redirect and make sure you can access the redirected URL +# else +# ! %W(4 5).include?(res.code[0]) # Not from 4xx or 5xx families +# end +# rescue Errno::ENOENT +# false #false if can't find the server +# end + + # def self.search(search) # where("name LIKE ? OR contact_no LIKE ?", "%#{search}%", "%#{search}%",) # end diff --git a/app/models/dining_facility.rb b/app/models/dining_facility.rb index a3f8948f..6f898989 100644 --- a/app/models/dining_facility.rb +++ b/app/models/dining_facility.rb @@ -9,8 +9,24 @@ class DiningFacility < ApplicationRecord scope :active, -> {where(is_active: true)} def get_current_booking - puts "enter 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) + puts "enter 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) + + if booking.count > 0 then + return booking[0].booking_id + else + return nil + end + end + + def get_new_booking + # query for new + # if status + # to ask when req bill booking_status? + booking = Booking.where("dining_facility_id = #{self.id} and booking_status ='assign' and sale_id is null and checkout_at is null").limit(1) + # else + # booking = Booking.where("dining_facility_id = #{self.id} and booking_status ='assign' and sale_id not null").limit(1) + # end if booking.count > 0 then return booking[0].booking_id diff --git a/app/models/dining_queue.rb b/app/models/dining_queue.rb index 09f8b6b5..d710d67f 100644 --- a/app/models/dining_queue.rb +++ b/app/models/dining_queue.rb @@ -1,7 +1,9 @@ class DiningQueue < ApplicationRecord - + belongs_to :dining_facility, :optional => true def self.generate_queue_no - queue_no = DiningQueue.all.count + 1 + today = DateTime.now.strftime('%Y-%m-%d') + dining_queues = DiningQueue.where("DATE_FORMAT(created_at,'%Y-%m-%d') = ? ", today).order("queue_no desc") + queue_no = dining_queues.count + 1 return queue_no end -end +end \ No newline at end of file diff --git a/app/models/employee.rb b/app/models/employee.rb index 1f3cace0..98b8380b 100644 --- a/app/models/employee.rb +++ b/app/models/employee.rb @@ -6,6 +6,9 @@ class Employee < ApplicationRecord validates :emp_id, uniqueness: true, numericality: true, length: {in: 1..4}, allow_blank: true validates :password, numericality: true, length: {in: 3..9}, allow_blank: true + def self.collection + Employee.select("id, name").map { |e| [e.name, e.id] } + end def self.login(emp_id, password) user = Employee.find_by_emp_id(emp_id) diff --git a/app/models/order.rb b/app/models/order.rb index 2ea76a98..a4328d76 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -246,7 +246,7 @@ class Order < ApplicationRecord .joins("left join orders on orders.order_id = booking_orders.order_id") .joins("left join sales on sales.sale_id = bookings.sale_id") .where("sales.sale_status='completed'") - .group("sales.sale_id,bookings.booking_id,sales.receipt_no,orders.status,sales.sale_id,dining_facilities.name,orders.status,orders.order_id") + .group("sales.sale_id") # For PG #bookings.booking_id,sales.receipt_no,orders.status,sales.sale_id,dining_facilities.name,orders.status,orders.order_id end diff --git a/app/models/order_queue_station.rb b/app/models/order_queue_station.rb index d6e21c64..2e85ecde 100644 --- a/app/models/order_queue_station.rb +++ b/app/models/order_queue_station.rb @@ -5,6 +5,8 @@ class OrderQueueStation < ApplicationRecord has_many :assigned_order_items has_many :order_items + has_many :order_queue_process_by_zones + has_many :zones, through: :order_queue_process_by_zones scope :active, -> {where(is_active: true)} @@ -14,37 +16,67 @@ class OrderQueueStation < ApplicationRecord oqpbz = OrderQueueProcessByZone.find_by_zone_id(dining.zone_id) order_items = order.order_items + + # get dining + booking = Booking.find_by_dining_facility_id(dining.id) + #Assign OQS id to order Items oqs_stations.each do |oqs| #Get List of items - pq_items = JSON.parse(oqs.processing_items) - - if oqs.id == oqpbz.order_queue_station_id + #Loop through the processing items - pq_items.each do |pq_item| - #Processing through the looping items - order_items.each do |order_item| - if (pq_item == order_item.item_code) - #Same Order_items can appear in two location. - AssignedOrderItem.assigned_order_item(order, order_item.item_code, oqs) + pq_items.each do |pq_item| + #Processing through the looping items + order_items.each do |order_item| + if (pq_item == order_item.item_code) + # if oqs.id == oqpbz.order_queue_station_id + # #Same Order_items can appear in two location. + # AssignedOrderItem.assigned_order_item(order, order_item.item_code, oqs) + # else + + AssignedOrderItem.assigned_order_item(order, order_item.item_code, oqs) + # end + + if oqs.auto_print + print_slip(oqs, order, order_items) end end end - end + end end - - #Print OQS where printing is require - end private #Print order_items in 1 slip - def print_slip + def print_slip(oqs, order, order_items) + unique_code="OrderSummaryPdf" + + print_settings=PrintSetting.find_by_unique_code(unique_code) + order_queue_printer= Printer::OrderQueuePrinter.new(print_settings) + order_queue_printer.print_order_summary(oqs,order.order_id, print_status="") + AssignedOrderItem.where("order_id = '#{ order.order_id }'").find_each do |ai| + # update print status for order items + ai.print_status=true + ai.save + end + end - #Print order_items in 1 slip per item - def print_slip_item + #Print order_item in 1 slip per item + def print_slip_item(oqs, assigned_order_item) + unique_code="OrderItemPdf" + # print when complete click + print_settings=PrintSetting.find_by_unique_code(unique_code) + order_queue_printer= Printer::OrderQueuePrinter.new(print_settings) + order_queue_printer.print_order_item(oqs,item.order_id, item.item_code, print_status="" ) + + # update print status for completed same order items + assigned_order_item.each do |ai| + ai.print_status=true + ai.save + end end end diff --git a/app/models/printer/order_queue_printer.rb b/app/models/printer/order_queue_printer.rb index dae1ad53..63666a68 100644 --- a/app/models/printer/order_queue_printer.rb +++ b/app/models/printer/order_queue_printer.rb @@ -1,66 +1,128 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker - def print_order_item(oqs,order_id, item_code) + def print_order_item(oqs,order_id, item_code, print_status) #Use CUPS service #Generate PDF #Print - order_item= print_query('order_item', item_code) #OrderItem.find_by_item_code(item_code) - pdf = OrderItemPdf.new(order_item[0]) - pdf.render_file "tmp/receipt.pdf" + order_item = print_query('order_item', item_code) #OrderItem.find_by_item_code(item_code) + + filename = "tmp/order_item_#{order_item[0].item_name}" + ".pdf" + pdf = OrderItemPdf.new(order_item[0], print_status) + pdf.render_file filename + if oqs.print_copy - self.print("tmp/receipt.pdf", oqs.printer_name) - self.print("tmp/receipt.pdf", oqs.printer_name) + self.print(filename, oqs.printer_name) + + #For print copy + pdf.render_file filename.gsub(".","-copy.") + self.print(filename.gsub(".","-copy."), oqs.printer_name) else - self.print("tmp/receipt.pdf", oqs.printer_name) + self.print(filename, oqs.printer_name) end end - def print_order_summary(oqs,order_id) + # Query for per order + def print_order_summary(oqs, order_id, print_status) #Use CUPS service #Generate PDF - #Print - order=print_query('order_summary',order_id) + #Print + order=print_query('order_summary', order_id) # For Print Per Item if oqs.cut_per_item order.each do|odi| - pdf = OrderItemPdf.new(odi) - pdf.render_file "tmp/receipt.pdf" + filename = "tmp/order_item_#{odi.item_name}" + ".pdf" + pdf = OrderItemPdf.new(odi, print_status) + # pdf.render_file "tmp/order_item.pdf" + pdf.render_file filename if oqs.print_copy - self.print("tmp/receipt.pdf", oqs.printer_name) - self.print("tmp/receipt.pdf", oqs.printer_name) + self.print(filename, oqs.printer_name) + self.print(filename.gsub(".","-copy."), oqs.printer_name) else - self.print("tmp/receipt.pdf", oqs.printer_name) + self.print(filename, oqs.printer_name) end end # For Print Order Summary else - filename = "tmp/order_summary_#{order_id}" + ".pdf" - pdf = OrderSummaryPdf.new(order) + filename = "tmp/order_summary_#{ order_id }" + ".pdf" + pdf = OrderSummaryPdf.new(order, print_status) pdf.render_file filename - self.print(filename, oqs.printer_name) + if oqs.print_copy + self.print(filename, oqs.printer_name) + + #For print copy + pdf.render_file filename.gsub(".","-copy.") + self.print(filename.gsub(".","-copy."), oqs.printer_name) + else + self.print(filename, oqs.printer_name) + end + end + end + + # Print for orders in booking + def print_booking_summary(oqs, booking_id, print_status) + order=print_query('booking_summary', booking_id) + # For Print Per Item + if oqs.cut_per_item + order.each do|odi| + filename = "tmp/order_item_#{odi.item_name}" + ".pdf" + pdf = OrderItemPdf.new(odi, print_status) + pdf.render_file filename + + if oqs.print_copy + self.print(filename, oqs.printer_name) + + #For print copy + pdf.render_file filename.gsub(".","-copy.") + self.print(filename.gsub(".","-copy."), oqs.printer_name) + else + self.print(filename, oqs.printer_name) + end + end + # For Print Order Summary + else + filename = "tmp/booking_summary_#{ booking_id }" + ".pdf" + pdf = OrderSummaryPdf.new(order, print_status) + pdf.render_file filename + if oqs.print_copy + self.print(filename, oqs.printer_name) + + #For print copy + pdf.render_file filename.gsub(".","-copy.") + self.print(filename.gsub(".","-copy."), oqs.printer_name) + else + self.print(filename, oqs.printer_name) + end end end # Query for OQS with status - def print_query(type, code) - if type == 'order_item' + def print_query(type, id) + if type == "order_item" OrderItem.select("order_items.item_code, order_items.item_name, order_items.qty, order_items.price, order_items.item_order_by as order_by, order_items.created_at as order_at, cus.name as customer, df.name as dining") .joins("left join orders ON orders.order_id = order_items.order_id left join booking_orders AS bo ON bo.order_id=order_items.order_id left join bookings AS b ON b.booking_id = bo.booking_id left join dining_facilities AS df ON df.id = b.dining_facility_id left join customers as cus ON cus.customer_id = orders.customer_id") - .where("order_items.item_code='" + code + "'") + .where("order_items.item_code = '#{ id }'") .group("order_items.item_code") - else + elsif type == "order_summary" OrderItem.select("order_items.item_code, order_items.item_name, order_items.qty, order_items.price, order_items.item_order_by as order_by, order_items.created_at as order_at, cus.name as customer, df.name as dining") .joins("left join orders ON orders.order_id = order_items.order_id left join booking_orders AS bo ON bo.order_id=order_items.order_id left join bookings AS b ON b.booking_id = bo.booking_id left join dining_facilities AS df ON df.id = b.dining_facility_id left join customers as cus ON cus.customer_id = orders.customer_id") - .where("orders.order_id='" + code + "'") - .group("order_items.item_code") + .where("orders.order_id = '#{ id }'") + else + # order summary for booking + OrderItem.select("order_items.item_code, order_items.item_name, order_items.qty, order_items.price, order_items.item_order_by as order_by, order_items.created_at as order_at, cus.name as customer, df.name as dining") + .joins("left join orders ON orders.order_id = order_items.order_id + left join booking_orders AS bo ON bo.order_id=order_items.order_id + left join bookings AS b ON b.booking_id = bo.booking_id + left join dining_facilities AS df ON df.id = b.dining_facility_id + left join customers as cus ON cus.customer_id = orders.customer_id") + .where("b.booking_id = '#{ id }'") end end diff --git a/app/models/printer/receipt_printer.rb b/app/models/printer/receipt_printer.rb index 92468b0e..bfef5588 100644 --- a/app/models/printer/receipt_printer.rb +++ b/app/models/printer/receipt_printer.rb @@ -52,7 +52,7 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker self.print(filename) end - + def print_receipt_payment_by_foc(sale_id) #Use CUPS service #Generate PDF @@ -70,6 +70,7 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker #Generate PDF #Print pdf = ReceiptBillPdf.new(printer_settings, sale_items, sale_data, customer_name, food_total, beverage_total, member_info) + pdf.render_file "tmp/receipt_bill.pdf" self.print("tmp/receipt_bill.pdf") end diff --git a/app/models/sale.rb b/app/models/sale.rb index 9683c2b2..2ffb53ef 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -23,6 +23,7 @@ class Sale < ApplicationRecord if (booking) Rails.logger.debug "Booking -> Booking Order Count -> " + booking.booking_orders.count.to_s #get all order attached to this booking and combine into 1 invoice + booking.booking_orders.each do |order| if booking.sale_id status, sale_id = generate_invoice_from_order(order.order_id, nil, booking, requested_by) @@ -88,6 +89,8 @@ class Sale < ApplicationRecord order.save booking.sale_id = self.id + booking.checkout_at = Time.now.utc + booking.checkout_by = requested_by.name booking.save return true, self.id @@ -188,9 +191,14 @@ class Sale < ApplicationRecord # Tax Calculate def apply_tax(total_taxable) + #if tax is not apply create new record + # self.sale_taxes.each do |existing_tax| + # #delete existing and create new + # existing_tax.delete + # end #if tax is not apply create new record - self.sale_taxes.each do |existing_tax| + SaleTax.where("sale_id='#{self.sale_id}'").find_each do |existing_tax| #delete existing and create new existing_tax.delete end @@ -199,7 +207,7 @@ class Sale < ApplicationRecord #tax_profile - list by order_by tax_profiles = TaxProfile.all.order("order_by asc") - #Creat new tax records + # #Creat new tax records tax_profiles.each do |tax| sale_tax = SaleTax.new(:sale => self) sale_tax.tax_name = tax.name @@ -273,6 +281,59 @@ class Sale < ApplicationRecord end end + def self.daily_sales_list(from,to) + payments_total = Sale.select("CAST((CONVERT_TZ(sales.receipt_date,'+00:00','+06:30')) AS DATE) as sale_date, + SUM(case when (sale_payments.payment_method='mpu') then sale_payments.payment_amount else 0 end) as mpu_amount, + SUM(case when (sale_payments.payment_method='master') then sale_payments.payment_amount else 0 end) as master_amount, + SUM(case when (sale_payments.payment_method='visa') then sale_payments.payment_amount else 0 end) as visa_amount, + SUM(case when (sale_payments.payment_method='jcb') then sale_payments.payment_amount else 0 end) as jcb_amount, + SUM(case when (sale_payments.payment_method='paypar') then sale_payments.payment_amount else 0 end) as paypar_amount, + SUM(case when (sale_payments.payment_method='cash') then sale_payments.payment_amount else 0 end) as cash_amount, + SUM(case when (sale_payments.payment_method='credit') then sale_payments.payment_amount else 0 end) as credit_amount, + SUM(case when (sale_payments.payment_method='foc') then sale_payments.payment_amount else 0 end) as foc_amount") + .joins("join (select * from sale_payments group by sale_payments.sale_id, sale_payments.payment_method) sale_payments on sale_payments.sale_id = sales.sale_id") + .where("sale_status = ? AND sales.receipt_date between ? and ? AND total_amount != 0", 'completed', from, to) + .group("DATE_FORMAT((CONVERT_TZ(sales.receipt_date,'+00:00','+06:30')),'%Y-%m-%d')") + + daily_total = Array.new + + payments_total.each do |pay| + sale_date = pay.sale_date + diff_time = payments_total.first.sale_date.beginning_of_day.utc - from + diff = diff_time % 86400 + from_date = sale_date.beginning_of_day.utc - diff + to_date = sale_date.end_of_day.utc - diff + + total_sale = Sale.select("IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0) as grand_total, + IFNULL(SUM(case when (sale_status='completed') then total_discount else 0 end),0) as total_discount, + IFNULL(SUM(case when (sale_status='void') then grand_total else 0 end),0) as void_amount, + IFNULL(SUM(case when (sale_status='completed') then rounding_adjustment else 0 end),0) as rounding_adj") + .where("(sale_status = ? OR sale_status = ?) AND receipt_date between ? and ? AND total_amount != 0", 'completed', 'void', from_date, to_date) + + total_sale.each do |sale| + grand_total = sale.grand_total + total_discount = sale.total_discount + void_amount = sale.void_amount + total = {:sale_date => pay.sale_date, + :mpu_amount => pay.mpu_amount, + :master_amount => pay.master_amount, + :visa_amount => pay.visa_amount, + :jcb_amount => pay.jcb_amount, + :paypar_amount => pay.paypar_amount, + :cash_amount => pay.cash_amount, + :credit_amount => pay.credit_amount, + :foc_amount => pay.foc_amount, + :total_discount => total_discount, + :grand_total => grand_total, + :void_amount => void_amount, + :rounding_adj => sale.rounding_adj} + daily_total.push(total) + end + + end + return daily_total + end + private def generate_custom_id diff --git a/app/models/sale_item.rb b/app/models/sale_item.rb index ef852bbd..bec8b5c5 100644 --- a/app/models/sale_item.rb +++ b/app/models/sale_item.rb @@ -30,35 +30,51 @@ class SaleItem < ApplicationRecord # end end + # Calculate food total and beverage total def self.calculate_food_beverage(sale_items) - food_prices=0 - beverage_prices=0 - sale_items.each do |si| - food_price, beverage_price = self.get_price(si.sale_item_id) - - food_prices = food_prices + food_price - beverage_prices = beverage_prices + beverage_price + rebateacc = Account.where("rebate=?",true) + puts "Account that can rebate" + rebateacc.each do |i| + puts i.title end - return food_prices, beverage_prices + prices=0 + sale_items.each do |si| + price = self.get_price(si.sale_item_id,rebateacc) + + prices = prices + price + end + return prices end - def self.get_price(sale_item_id) - food_price=0 - beverage_price=0 + # get food price or beverage price for item + def self.get_price(sale_item_id,rebateacc) + price=0 item=SaleItem.select("sale_items.price , menu_items.account_id") .joins("left join menu_items on menu_items.item_code = sale_items.product_code") .where("sale_items.sale_item_id=?", sale_item_id.to_s) - if item[0].account_id == 1 - food_price = item[0].price - else - beverage_price = item[0].price + + rebateacc.each do |i| + if item[0].account_id == i.id + price = item[0].price + end end - return food_price, beverage_price + return price end + # def self.get_overall_discount(sale_id) + # price = 0.0 + # item=SaleItem.where("product_code=?", sale_id) + # + # item.each do|i| + # price += i.price + # end + # + # return price + # end + private def generate_custom_id self.sale_item_id = SeedGenerator.generate_id(self.class.name, "SLI") diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 731fa321..b872e3b0 100644 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -66,16 +66,20 @@ class SalePayment < ApplicationRecord end - def self.get_paypar_account(url,token,membership_id,campaign_type_id,merchant_uid,auth_token) + def self.get_paypar_account(url,token,membership_id,campaign_type_id,merchant_uid,auth_token) + # Control for Paypar Cloud + begin response = HTTParty.get(url, - :body => { app_token: token,membership_id:membership_id,campaign_type_id:campaign_type_id,merchant_uid:merchant_uid,auth_token:auth_token}.to_json, - :headers => { - 'Content-Type' => 'application/json', - 'Accept' => 'application/json' - } - ) - return response; - + :body => { app_token: token,membership_id:membership_id,campaign_type_id:campaign_type_id,merchant_uid:merchant_uid,auth_token:auth_token}.to_json, + :headers => { + 'Content-Type' => 'application/json', + 'Accept' => 'application/json' + }, :timeout => 10 + ) + rescue Net::OpenTimeout + response = { status: false } + end + return response; end def self.redeem(paypar_url,token,membership_id,received_amount,sale_id) @@ -87,13 +91,19 @@ class SalePayment < ApplicationRecord campaign_type_id = membership_actions_data.additional_parameter["campaign_type_id"] sale_data = Sale.find_by_sale_id(sale_id) if sale_data - response = HTTParty.post(url, - :body => { generic_customer_id:membership_id,redeem_amount:received_amount,receipt_no:sale_data.receipt_no,campaign_type_id:campaign_type_id,account_no:"",merchant_uid:merchant_uid,auth_token:auth_token}.to_json, - :headers => { - 'Content-Type' => 'application/json', - 'Accept' => 'application/json' - } - ) + # Control for Paypar Cloud + begin + response = HTTParty.post(url, + :body => { generic_customer_id:membership_id,redeem_amount:received_amount,receipt_no:sale_data.receipt_no,campaign_type_id:campaign_type_id,account_no:"",merchant_uid:merchant_uid,auth_token:auth_token}.to_json, + :headers => { + 'Content-Type' => 'application/json', + 'Accept' => 'application/json' + }, + :timeout => 10 + ) + rescue Net::OpenTimeout + response = false + end else response = false; end @@ -119,7 +129,6 @@ class SalePayment < ApplicationRecord end def creditnote_payment(customer_id) - payment_status = false self.payment_method = "creditnote" @@ -187,17 +196,16 @@ class SalePayment < ApplicationRecord payment_status = false #Next time - validate if the vochure number is valid - within - self.payment_method = "paypar" - self.payment_amount = self.received_amount - self.payment_reference = self.voucher_no - self.outstanding_amount = self.sale.grand_total.to_f - self.received_amount.to_f - self.payment_status = "pending" - payment_method = self.save! - customer_data = Customer.find_by_customer_id(self.sale.customer_id) membership_setting = MembershipSetting.find_by_membership_type("paypar_url") membership_data = SalePayment.redeem(membership_setting.gateway_url,membership_setting.auth_token,customer_data.membership_id,self.received_amount,self.sale.sale_id) if membership_data["status"]==true + self.payment_method = "paypar" + self.payment_amount = self.received_amount + self.payment_reference = self.voucher_no + self.outstanding_amount = self.sale.grand_total.to_f - self.received_amount.to_f + self.payment_status = "pending" + payment_method = self.save! SalePayment.where(:sale_payment_id => self.sale_payment_id).update_all(:payment_status => 'paid') sale_update_payment_status(self.received_amount.to_f) @@ -241,7 +249,9 @@ class SalePayment < ApplicationRecord end def rebat(sObj) - food_prices, beverage_prices = SaleItem.calculate_food_beverage(sObj.sale_items) + rebate_prices = SaleItem.calculate_food_beverage(sObj.sale_items) + puts "rebate_prices" + puts rebate_prices generic_customer_id = sObj.customer.membership_id if generic_customer_id != nil || generic_customer_id != "" || generic_customer_id != 0 paypar = sObj.sale_payments @@ -251,7 +261,10 @@ class SalePayment < ApplicationRecord payparcost = payparcost + pp.payment_amount end end - total_amount = food_prices - payparcost + # overall_dis = SaleItem.get_overall_discount(sObj.id) + overall_dis = sObj.total_discount + + total_amount = rebate_prices - payparcost + overall_dis if total_amount > 0 receipt_no = sObj.receipt_no membership = MembershipSetting.find_by_membership_type("paypar_url") @@ -260,14 +273,20 @@ class SalePayment < ApplicationRecord campaign_type_id = memberaction.additional_parameter["campaign_type_id"] auth_token = memberaction.auth_token.to_s url = membership.gateway_url.to_s + memberaction.gateway_url.to_s - response = HTTParty.post(url, :body => { generic_customer_id:generic_customer_id ,merchant_uid:merchant_uid,total_amount: total_amount,campaign_type_id: campaign_type_id, + + # Control for Paypar Cloud + begin + response = HTTParty.post(url, :body => { generic_customer_id:generic_customer_id ,merchant_uid:merchant_uid,total_amount: total_amount,campaign_type_id: campaign_type_id, receipt_no: receipt_no,auth_token:auth_token}.to_json, :headers => { 'Content-Type' => 'application/json', 'Accept' => 'application/json' - }) + }, :timeout => 10) + rescue Net::OpenTimeout + response = { status: false } + end - puts response.to_json + # puts response.to_json end end end diff --git a/app/models/sale_tax.rb b/app/models/sale_tax.rb index 79de9134..7a42905a 100644 --- a/app/models/sale_tax.rb +++ b/app/models/sale_tax.rb @@ -5,6 +5,10 @@ class SaleTax < ApplicationRecord before_create :generate_custom_id belongs_to :sale + def self.get_tax(from,to) + query = SaleTax.select("sale_taxes.tax_name,SUM(sale_taxes.tax_payable_amount) as tax_amount").joins("join sales on sales.sale_id = sale_taxes.sale_id").where("sale_status = ? AND sales.receipt_date between ? and ? AND total_amount != 0", 'completed', from, to).group("sale_taxes.tax_name") + end + private def generate_custom_id self.sale_tax_id = SeedGenerator.generate_id(self.class.name, "STI") diff --git a/app/models/zone.rb b/app/models/zone.rb index e5ad15c7..164b80f4 100644 --- a/app/models/zone.rb +++ b/app/models/zone.rb @@ -2,7 +2,12 @@ class Zone < ApplicationRecord # model association has_many :tables, dependent: :destroy has_many :rooms, dependent: :destroy + has_many :order_queue_stations # validations validates_presence_of :name, :created_by + + def self.collection + Zone.select("id, name").map { |e| [e.name, e.id] } + end end diff --git a/app/pdf/order_item_pdf.rb b/app/pdf/order_item_pdf.rb index 96008dfd..e5c5395f 100644 --- a/app/pdf/order_item_pdf.rb +++ b/app/pdf/order_item_pdf.rb @@ -1,16 +1,16 @@ class OrderItemPdf < Prawn::Document attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width - def initialize(order_item) - self.page_width = 254 - self.page_height = 1450 - self.margin = 10 + def initialize(order_item, print_status) + self.page_width = 210 + self.page_height = 2500 + self.margin = 5 self.price_width = 40 # No Need for item - self.qty_width = 34 + self.qty_width = 30 self.total_width = 40 # No Need for item - self.item_width = self.page_width - (self.qty_width + (self.margin*4)) + self.item_width = self.page_width - self.qty_width self.item_height = 15 self.item_description_width = self.page_width - (self.price_width + self.qty_width + self.total_width) - self.label_width=80 + self.label_width=100 super(:margin => [self.margin, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height]) # super(:margin => [10, 5, 30, 5], :page_size => [200,400]) @@ -19,9 +19,9 @@ class OrderItemPdf < Prawn::Document # font "public/fonts/Zawgyi-One.ttf" # font "public/fonts/padauk.ttf" self.header_font_size = 14 - self.item_font_size = 12 + self.item_font_size = 12 - text "#{order_item.dining}", :size => self.header_font_size,:align => :center, :left_margin => -20 + text "#{ order_item.dining+print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 stroke_horizontal_rule move_down 5 @@ -71,7 +71,7 @@ class OrderItemPdf < Prawn::Document add_order_items(order_item) dash(1, :space => 1, :phase => 1) - stroke_horizontal_line 0, self.page_width + stroke_horizontal_line 0, (self.page_width - self.margin) move_down 5 end diff --git a/app/pdf/order_summary_pdf.rb b/app/pdf/order_summary_pdf.rb index 47c1f6a5..a1459512 100644 --- a/app/pdf/order_summary_pdf.rb +++ b/app/pdf/order_summary_pdf.rb @@ -1,13 +1,13 @@ class OrderSummaryPdf < Prawn::Document attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width - def initialize(order) - self.page_width = 254 - self.page_height = 1450 - self.margin = 10 + def initialize(order, print_status) + self.page_width = 210 + self.page_height = 2500 + self.margin = 5 self.price_width = 40 # No Need for item - self.qty_width = 34 + self.qty_width = 30 self.total_width = 40 # No Need for item - self.item_width = self.page_width - (self.qty_width + (self.margin*4)) + self.item_width = self.page_width - (self.qty_width - self.margin) self.item_height = 15 self.item_description_width = self.page_width - (self.price_width + self.qty_width + self.total_width) self.label_width=100 @@ -20,7 +20,7 @@ class OrderSummaryPdf < Prawn::Document self.header_font_size = 12 self.item_font_size = 10 - text "#{order[0].dining}", :size => self.header_font_size,:align => :center, :left_margin => -20 + text "#{ order[0].dining + print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 stroke_horizontal_rule move_down 5 @@ -59,7 +59,7 @@ class OrderSummaryPdf < Prawn::Document text "Item", :size => self.item_font_size,:align => :left end - bounding_box([self.item_width,y_position], :width => self.qty_width, :height => self.item_height) do + bounding_box([self.item_width-2,y_position], :width => self.qty_width, :height => self.item_height) do text "Qty", :size => self.item_font_size,:align => :left end @@ -77,16 +77,22 @@ class OrderSummaryPdf < Prawn::Document move_down 5 order_item.each do|odi| - bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "#{odi.item_name}", :size => self.item_font_size,:align => :left + y_position = cursor + + # pad_top(15) { + # text_box "#{odi.item_name}", :at =>[0,y_position], :width => self.item_width, :height =>self.item_height, :size => self.item_font_size, :overflow => :shrink_to_fix + # text_box "#{odi.qty}", :at =>[self.item_width,y_position], :width => self.qty_width, :height =>self.item_height, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix + # } + bounding_box([0,y_position], :width => self.item_width) do + text "#{odi.item_name}", :size => self.item_font_size,:align => :left, :height => self.item_height end - bounding_box([self.item_width,y_position], :width => self.qty_width, :height => self.item_height) do - text "#{odi.qty}", :size => self.item_font_size,:align => :left + bounding_box([self.item_width,y_position], :width => self.qty_width) do + text "#{odi.qty}", :size => self.item_font_size,:align => :left, :height => self.item_height end - end - move_down 5 + move_down 5 + end end end diff --git a/app/pdf/receipt_bill_pdf.rb b/app/pdf/receipt_bill_pdf.rb index 524ee7e5..c1ba4936 100644 --- a/app/pdf/receipt_bill_pdf.rb +++ b/app/pdf/receipt_bill_pdf.rb @@ -4,14 +4,13 @@ class ReceiptBillPdf < Prawn::Document self.page_width = 210 self.page_height = 2500 self.margin = 5 - self.price_width = 35 + self.price_width = 40 self.qty_width = 20 - self.total_width = 35 + self.total_width = 40 self.item_width = self.page_width - ((self.price_width + self.qty_width + self.total_width)) self.item_height = 15 self.item_description_width = (self.page_width-20) / 2 self.label_width = 100 - # @item_width = self.page_width.to_i / 2 # @qty_width = @item_width.to_i / 3 # @double = @qty_width * 1.3 @@ -36,7 +35,6 @@ class ReceiptBillPdf < Prawn::Document if member_info != nil member_info(member_info) end - footer end @@ -55,29 +53,36 @@ class ReceiptBillPdf < Prawn::Document # move_down 2 y_position = cursor bounding_box([0,y_position], :width =>self.label_width, :height => self.item_height) do - text "Receipt No:", :size => self.item_font_size,:align => :left + text "Receipt No: #{sale_data.receipt_no}", :size => self.item_font_size,:align => :left end - - bounding_box([self.label_width, y_position], :width =>self.item_width) do - text "#{sale_data.receipt_no}" , :size => self.item_font_size, :align => :left + bounding_box([self.label_width,y_position], :width => self.label_width, :height => self.item_height) do + text "#{ sale_data.bookings[0].dining_facility.name }" , :size => self.item_font_size,:align => :right end move_down 5 y_position = cursor - bounding_box([0,y_position], :width =>self.label_width, :height => self.item_height) do - text "Customer:", :size => self.item_font_size,:align => :left + bounding_box([0, y_position], :width =>self.item_width) do + text "Waiter: #{sale_data.requested_by}" , :size => self.item_font_size, :align => :left end - bounding_box([self.label_width,y_position], :width =>self.item_width) do - text "#{customer_name}" , :size => self.item_font_size,:align => :left + move_down 5 + + y_position = cursor + bounding_box([0,y_position], :width =>self.item_width, :height => self.item_height) do + text "Cashier: #{sale_data.cashier_name}", :size => self.item_font_size,:align => :left end move_down 5 + # bounding_box([self.label_width,y_position], :width =>self.item_width) do + # text "#{customer_name}" , :size => self.item_font_size,:align => :left + # end + # move_down 5 + y_position = cursor bounding_box([0,y_position], :width =>self.label_width, :height => self.item_height) do - text "Date:", :size => self.item_font_size,:align => :left + text "Time In: #{ sale_data.bookings[0].checkin_at.strftime('%I:%M %p') }", :size => self.item_font_size,:align => :left end - bounding_box([self.label_width,y_position], :width => self.item_width) do - text "#{sale_data.receipt_date.strftime('%Y-%m-%d %I:%M %p')}" , :size => self.item_font_size,:align => :left + bounding_box([self.label_width,y_position], :width => self.label_width, :height => self.item_height) do + text "Time Out: #{ sale_data.bookings[0].checkout_at.strftime('%I:%M %p') }" , :size => self.item_font_size,:align => :right end move_down 5 @@ -120,10 +125,10 @@ class ReceiptBillPdf < Prawn::Document y_position = cursor pad_top(15) { - text_box "#{product_name}", :at =>[0,y_position], :width => self.item_width, :height =>self.item_height, :overflow => :shrink_to_fix, :size => self.item_font_size, :overflow => :shrink_to_fix - text_box "#{price.to_i}", :at =>[self.item_width,y_position], :width => self.price_width, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix - text_box "#{qty.to_i}", :at =>[item_name_width,y_position], :width => self.qty_width, :height =>self.item_height, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix - text_box "#{total_price.to_i}", :at =>[(item_name_width),y_position], :width =>self.total_width+5, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix + text_box "#{product_name}", :at =>[0,y_position], :width => self.item_width, :height =>self.item_height, :size => self.item_font_size, :overflow => :shrink_to_fix + text_box "#{price}", :at =>[self.item_width,y_position], :width => self.price_width, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix + text_box "#{qty}", :at =>[item_name_width,y_position], :width => self.qty_width, :height =>self.item_height, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix + text_box "#{total_price}", :at =>[(item_name_width),y_position], :width =>self.total_width+5, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix } move_down 3 end @@ -165,7 +170,7 @@ class ReceiptBillPdf < Prawn::Document text "( " +"#{sale_data.total_discount}" +" )" , :size => self.item_font_size,:align => :right end - if sale_data.sale_taxes.length > 1 + if sale_data.sale_taxes.length > 0 sale_data.sale_taxes.each do |st| move_down 5 y_position = cursor @@ -174,7 +179,7 @@ class ReceiptBillPdf < Prawn::Document text "#{ st.tax_name }", :size => self.item_font_size,:align => :left end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "( " +"#{ st.tax_payable_amount }" +" )" , :size => self.item_font_size,:align => :right + text "#{ st.tax_payable_amount }" , :size => self.item_font_size,:align => :right end end else @@ -206,10 +211,10 @@ class ReceiptBillPdf < Prawn::Document # show member information def member_info(member_info) - + move_down 7 - if member_info["status"] == true - member_info["data"].each do |res| + if member_info["status"] == true + member_info["data"].each do |res| move_down 5 y_position = cursor @@ -219,9 +224,9 @@ class ReceiptBillPdf < Prawn::Document bounding_box([self.item_description_width,y_position], :width =>self.label_width) do text "#{ res["balance"] }" , :size => self.item_font_size,:align => :right end - - end - end + + end + end end def footer diff --git a/app/views/crm/dining_queues/_form.html.erb b/app/views/crm/dining_queues/_form.html.erb index 7f02ac15..320bac40 100644 --- a/app/views/crm/dining_queues/_form.html.erb +++ b/app/views/crm/dining_queues/_form.html.erb @@ -10,7 +10,7 @@
- <%= f.button :submit %> + <%= f.button :submit,"Create Queue" %>
<% end %> diff --git a/app/views/crm/dining_queues/assign.html.erb b/app/views/crm/dining_queues/assign.html.erb new file mode 100644 index 00000000..5de532cc --- /dev/null +++ b/app/views/crm/dining_queues/assign.html.erb @@ -0,0 +1,44 @@ + +
+
+ +
+
+
+ +
+ <%= form_tag crm_assign_table_path, :method => :post do %> + +
+ + + +
+
+ +
+ + + +
+ +
+
+
+ +
+ <% end %> +
+
+ diff --git a/app/views/crm/dining_queues/index.html.erb b/app/views/crm/dining_queues/index.html.erb index e7834b98..7050885d 100644 --- a/app/views/crm/dining_queues/index.html.erb +++ b/app/views/crm/dining_queues/index.html.erb @@ -1,38 +1,69 @@ - - -
-
- - - - - - - - - +
+
+ +
+ <% @i = 0 %> . + <% @dining_queues.each do |queue| %> +
+
" style="border:1px solid #ccc;margin-bottom: 10px "> +
+ + +

<%= @i += 1 %> . Queue No

+

<%= queue.queue_no %>

+

+ Name : <%= queue.name %>
+ Contact : <%= queue.contact_no %> +
+ Status : <%= queue.status rescue '-' %> +

+
+
+ +
+ <% end %> +
+ + +
+
+ + +
-
- <% @dining_queues.each do |dining_queue| %> - - - - - - - <% end %> - -
NameContact NoQueue NoAction
<%= dining_queue.name %><%= dining_queue.contact_no %><%= dining_queue.queue_no %> - <%= link_to 'Edit', edit_crm_dining_queue_path(dining_queue) %> | <%= link_to 'Destroy', crm_dining_queue_path(dining_queue), method: :delete, data: { confirm: 'Are you sure?' } %>
+ + \ No newline at end of file diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb index 58ecd9b5..40ddae1f 100644 --- a/app/views/layouts/_header.html.erb +++ b/app/views/layouts/_header.html.erb @@ -14,6 +14,7 @@
  • <%= link_to "Menu Item Options",settings_menu_item_options_path, :tabindex =>"-1" %>

  • <%= link_to "Order Queue Stations",settings_order_queue_stations_path, :tabindex =>"-1" %>
  • +
  • <%= link_to "Zones", settings_zones_path, :tabindex =>"-1" %>

  • <%= link_to "Cashier Terminals ", settings_cashier_terminals_path, :tabindex =>"-1" %>
  • <%= link_to "Employees", settings_employees_path, :tabindex =>"-1" %>
  • @@ -22,6 +23,8 @@
  • <%= link_to "Payment Method", settings_payment_method_settings_path, :tabindex =>"-1" %>
  • <%= link_to "Tax Profile", settings_tax_profiles_path, :tabindex =>"-1" %>
  • <%= link_to "Print Setting", print_settings_path, :tabindex =>"-1" %>
  • +
    +
  • <%= link_to "Accounts", settings_accounts_path, :tabindex =>"-1" %>
  • @@ -35,7 +38,7 @@