diff --git a/app/assets/javascripts/OQS.js b/app/assets/javascripts/OQS.js index 7df365ec..2cddf699 100644 --- a/app/assets/javascripts/OQS.js +++ b/app/assets/javascripts/OQS.js @@ -40,31 +40,36 @@ $(document).ready(function(){ // complete for queue item $('.order-complete').on('click',function(){ - var _self= $(this); + var _self = $(this); // To know in ajax return var assigned_item_id=$(this).attr('id').substr(15); var params = { 'id':assigned_item_id }; - var station=$(this).parent().parent(".queue_station").parent().parent().attr('id'); $.ajax({ type: 'POST', url: '/oqs/update_delivery', data: params, dataType: 'json', - success: function(data){ - var queue_station=_self.parent().parent(".queue_station"); + 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'); - // Remove a queue card from current station - queue_station.remove(); + // Remove a queue card from current station + queue_station.remove(); - // 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); + // 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); - // update queue item count in station - $("#"+station+"_count").text(parseInt($("#"+station+"_count").text())-1); - $("#completed_count").text(parseInt($("#completed_count").text())+1); + // update queue item count in each station + var station_count=parseInt($("#"+station+"_count").text()) - 1; + $("#"+station+"_count").text(station_count); + } + + // update queue item count in completed station + $("#completed_count").text(parseInt($("#completed_count").text()) + data.length); alert("updated!"); } diff --git a/app/assets/javascripts/origami.js b/app/assets/javascripts/origami.js index 61bff6e9..14d0bf6c 100644 --- a/app/assets/javascripts/origami.js +++ b/app/assets/javascripts/origami.js @@ -17,10 +17,13 @@ //= require cable $(document).ready(function(){ + // Enable/Disable Button + control_button("disabled"); + $(".orders").on('click', function(){ $("#order-sub-total").text(''); - $("#order-food").text(''); - $("#order-beverage").text(''); + // $("#order-food").text(''); + // $("#order-beverage").text(''); $("#order-discount").text(''); $("#order-Tax").text(''); $("#order-grand-total").text(''); @@ -53,10 +56,10 @@ $(document).ready(function(){ // AJAX call for order $.ajax({ - type: "GET", - url: "origami/" + unique_id, - data: { 'id' : unique_id }, - success:function(result){ + type: "POST", + url: "/origami/" + unique_id, + data: { 'booking_id' : unique_id }, + success:function(result){ for (i = 0; i < result.length; i++) { var data = JSON.stringify(result[i]); var parse_data = JSON.parse(data); @@ -67,7 +70,7 @@ $(document).ready(function(){ receipt_date = result[i].receipt_date; $("#receipt_no").text(receipt_no); - $("#cashier").text(cashier==null?"":cashier); + $("#cashier").text(cashier == null ? "" : cashier); $("#receipt_date").text(receipt_date); @@ -79,8 +82,8 @@ $(document).ready(function(){ grand_total_amount = parse_data.grand_total_amount; $("#order-sub-total").text(sub_total); - $("#order-food").text(''); - $("#order-beverage").text(''); + // $("#order-food").text(''); + // $("#order-beverage").text(''); $("#order-discount").text(discount_amount); $("#order-Tax").text(tax_amount); $("#order-grand-total").text(grand_total_amount); @@ -106,7 +109,7 @@ $(document).ready(function(){ $('#request_bills').click(function() { var order_id=$(".selected-item").find(".orders-id").text(); if(order_id!=""){ - window.location.href = '/origami/request_bills/'+ order_id + window.location.href = '/origami/' + order_id + '/request_bills' } else { alert("Please select an order!"); @@ -118,7 +121,7 @@ $(document).ready(function(){ $('#discount').click(function() { var order_id=$(".selected-item").find(".orders-id").text(); if(order_id!=""){ - window.location.href = '/origami/discount/'+ order_id + window.location.href = '/origami/' + order_id + '/discount' } else { alert("Please select an order!"); @@ -130,21 +133,27 @@ $(document).ready(function(){ // Pay Discount for Payment $("#pay-discount").on('click', function(){ var sale_id = $('#sale-id').text(); + var sale_item_id = $('.selected-item').attr('id'); var sub_total = $('#order-sub-total').text(); var grand_total = $('#order-grand-total').text(); var discount_type = $('#discount-type').val(); var discount_value = $('#discount-amount').val(); var discount_amount = discount_value; + if(sale_item_id == null){ + alert('Please select item row to discount!'); + return; + } + // For Percentage Discount if(discount_type == 1){ discount_amount=(sub_total*discount_value)/100; } - var params = {'sale_id': sale_id, 'grand_total' : grand_total, 'discount_type':discount_type, 'discount_value':discount_value, 'discount_amount':discount_amount}; + var params = {'sale_id': sale_id, 'sale_item_id': sale_item_id, 'grand_total' : grand_total, 'discount_type':discount_type, 'discount_value':discount_value, 'discount_amount':discount_amount}; $.ajax({ type: "POST", - url: "/origami/discount", + url: "/origami/" + sale_item_id + "/discount", data: params, success:function(result){ } }); @@ -192,8 +201,9 @@ $(document).ready(function(){ case 'add': var input_value = $(this).attr("data-value"); - amount = parseInt(input_value) + parseInt(original_value); + amount = parseInt(input_value); $('#discount-amount').val(amount); + $('#discount-type').val(1); update_balance(); break; @@ -215,6 +225,11 @@ $(document).ready(function(){ } }); + $('.discount-item-row').on('click',function(){ + $('.discount-item-row').removeClass('selected-item'); + $(this).addClass('selected-item'); + }); + }); /* Button Control by Status */ @@ -222,12 +237,17 @@ function control_button(order_status){ if(order_status=="billed"){ $("#request_bills").prop('disabled', true); $("#discount").prop('disabled', false); - $("#pay").prop('disabled', false); + $("#pay-bill").prop('disabled', false); } else if(order_status=="new") { $("#request_bills").prop('disabled', false); $("#discount").prop('disabled', true); - $("#pay").prop('disabled', true); + $("#pay-bill").prop('disabled', true); + } + else { + $("#request_bills").prop('disabled', true); + $("#discount").prop('disabled', true); + $("#pay-bill").prop('disabled', true); } } diff --git a/app/assets/stylesheets/origami.scss b/app/assets/stylesheets/origami.scss index 0be16266..51f0c16a 100644 --- a/app/assets/stylesheets/origami.scss +++ b/app/assets/stylesheets/origami.scss @@ -8,9 +8,13 @@ // padding-top: 4.5rem; // } +.orders-table { + cursor: pointer; +} + .cashier_number{ - height:76px; - line-height:80px; + height:60px; + line-height:60px; text-align:center; background:#54A5AF; float:left; @@ -25,15 +29,20 @@ } .long{ - width:100% + width:100%; } .sold { background-color: red; } +.paid { + background-color: green; +} + .selected-item { - background-color: blue; + color: #fff !important; + background-color: blue !important; } /* Reciept Style */ @@ -76,3 +85,17 @@ select.form-control { height: inherit !important; } + +.form-horizontal .form-group { + margin-right: 0px !important; +} + +/* Discount */ + +.discount-item-row { + cursor: pointer; +} + +tr.discount-item-row:hover { + background-color: #e3e3e3 !important; +} \ No newline at end of file diff --git a/app/controllers/oqs/home_controller.rb b/app/controllers/oqs/home_controller.rb index 2b676f21..7af42166 100644 --- a/app/controllers/oqs/home_controller.rb +++ b/app/controllers/oqs/home_controller.rb @@ -27,10 +27,18 @@ class Oqs::HomeController < BaseOqsController # update delivery status when complete click def update_delivery_status + removed_item = [] assigned_item_id = params[:id] assigned_item=AssignedOrderItem.find(assigned_item_id) - assigned_item.delivery_status=true - assigned_item.save + assigned_items=AssignedOrderItem.where("item_code='" + assigned_item.item_code + "' AND " + "order_id='" + assigned_item.order_id + "'"); + + # update delivery status for completed same order items + assigned_items.each do |ai| + ai.delivery_status=true + ai.save + removed_item.push(ai.assigned_order_item_id) + end + render :json => removed_item.to_json end # Query for OQS with status diff --git a/app/controllers/oqs/print_controller.rb b/app/controllers/oqs/print_controller.rb index 8a12e439..1731f69c 100644 --- a/app/controllers/oqs/print_controller.rb +++ b/app/controllers/oqs/print_controller.rb @@ -1,31 +1,39 @@ class Oqs::PrintController < ApplicationController + # Print Order Item def print unique_code="OrderItemPdf" assigned_item_id=params[:id] - assigned_order_item=AssignedOrderItem.select("order_id, item_code").where("assigned_order_item_id='" + assigned_item_id + "'") + assigned_item=AssignedOrderItem.find(assigned_item_id) + assigned_items=AssignedOrderItem.where("item_code='" + assigned_item.item_code + "' AND " + "order_id='" + assigned_item.order_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_item(print_settings,assigned_order_item[0].order_id, assigned_order_item[0].item_code ) - - # update print status when complete click - assigned_item=AssignedOrderItem.find(assigned_item_id) - assigned_item.print_status=true - assigned_item.save + order_queue_printer.print_order_item(print_settings,assigned_item.order_id, assigned_item.item_code ) + + # update print status for completed same order items + assigned_items.each do |ai| + ai.print_status=true + ai.save + end end + # Print Order Details def print_order_summary unique_code="OrderSummaryPdf" assigned_item_id=params[:id] - assigned_order_item=AssignedOrderItem.select("order_id").where('assigned_order_item_id='+assigned_item_id) + assigned_item=AssignedOrderItem.find(assigned_item_id) + assigned_items=AssignedOrderItem.where("item_code='" + assigned_item.item_code + "' AND " + "order_id='" + assigned_item.order_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(print_settings,assigned_order_item[0].order_id) + order_queue_printer.print_order_summary(print_settings,assigned_item.order_id) - # update print status when complete click - assigned_item=AssignedOrderItem.find(assigned_item_id) - assigned_item.print_status=true - assigned_item.save + # update print status for completed same order items + assigned_items.each do |ai| + ai.print_status=true + ai.save + end end end diff --git a/app/controllers/origami/discounts_controller.rb b/app/controllers/origami/discounts_controller.rb index daf68918..e80ca348 100644 --- a/app/controllers/origami/discounts_controller.rb +++ b/app/controllers/origami/discounts_controller.rb @@ -2,7 +2,7 @@ class Origami::DiscountsController < BaseOrigamiController #discount page show from origami index with selected order def index - sale_id = params[:id] + sale_id = params[:id] if Sale.exists?(sale_id) @sale_data = Sale.find(sale_id) end @@ -11,30 +11,32 @@ class Origami::DiscountsController < BaseOrigamiController #discount for selected order def create sale_id = params[:sale_id] + sale_item_id = params[:sale_item_id] discount_type = params[:discount_type] - discount_value = params[:discount_value] - discount_amount = params[:discount_amount] - grand_total = params[:grand_total] + discount_value = params[:discount_value] + discount_amount = params[:discount_amount] + grand_total = params[:grand_total] - if discount_type == 0 - remark="Discount " + discount_amount + " as net" - else - remark="Discount " + discount_amount + " as percentage" - end + if discount_type == 0 + remark="Discount " + discount_amount + " as net" + else + remark="Discount " + discount_amount + " as percentage" + end - #update discount for sale - sale = Sale.find(sale_id) - sale.total_discount = discount_amount - sale.grand_total = grand_total - sale.save + #update discount for sale + sale = Sale.find(sale_id) + sale.total_discount = sale.total_discount + discount_amount.to_f + sale.grand_total = grand_total + sale.save #save sale item for discount + origin_sale_item = SaleItem.find(sale_item_id) sale_item = SaleItem.new #pull sale_item.sale_id = sale_id - sale_item.product_code = 0 - sale_item.product_name = "Discount" + sale_item.product_code = origin_sale_item.product_code + sale_item.product_name = origin_sale_item.product_name + " Discount" sale_item.remark = remark sale_item.qty = 1 @@ -45,7 +47,7 @@ class Origami::DiscountsController < BaseOrigamiController sale_item.price = sale_item.qty * sale_item.unit_price sale_item.save - redirect_to origami_root_path + redirect_to origami_path(sale_id) end end diff --git a/app/controllers/origami/home_controller.rb b/app/controllers/origami/home_controller.rb index 9733e488..83c6bd81 100644 --- a/app/controllers/origami/home_controller.rb +++ b/app/controllers/origami/home_controller.rb @@ -1,28 +1,48 @@ class Origami::HomeController < BaseOrigamiController def index + if params[:booking_id] != nil + type=params[:booking_id].split('-')[0]; + # Sale + if type == "SAL" + @selected_item = Sale.find(params[:booking_id]) + @selected_item_type="Sale" + # Booking + else + @selected_item = Order.find(params[:booking_id]) + @selected_item_type="Order" + end + end + + @completed_orders = Order.get_completed_order() @booking_orders = Order.get_booking_order_table() @booking_rooms = Order.get_booking_order_rooms() @orders = Order.get_orders() - end + end - def show - str = [] - type=params[:id].split('-')[0]; + def item_show + selection(params[:booking_id],1) + end + def selection(selected_id, is_ajax) + str = [] + type=selected_id.split('-')[0]; # Sale if type == "SAL" - @order_details = SaleItem.get_order_items_details(params[:id]) + @order_details = SaleItem.get_order_items_details(params[:booking_id]) @order_details.each do |ord_detail| str.push(ord_detail) end - render :json => str.to_json # Booking else - @order_details = OrderItem.get_order_items_details(params[:id]) + @order_details = OrderItem.get_order_items_details(params[:booking_id]) @order_details.each do |ord_detail| str.push(ord_detail) - end - render :json => str.to_json + end end + if is_ajax == 1 + render :json => str.to_json + else + str + end end end diff --git a/app/controllers/origami/request_bills_controller.rb b/app/controllers/origami/request_bills_controller.rb index d1aa9e61..4e884aaf 100644 --- a/app/controllers/origami/request_bills_controller.rb +++ b/app/controllers/origami/request_bills_controller.rb @@ -14,17 +14,23 @@ class Origami::RequestBillsController < BaseOrigamiController @sale_items = SaleItem.where("sale_id=?",@sale_id) else @sale_data = Sale.find_by_sale_id(check_booking.sale_id) - @sale_items = SaleItem.where("sale_id=?",@sale_id) + @sale_items = SaleItem.where("sale_id=?",@sale_data.sale_id) end unique_code = "ReceiptBillPdf" - customer_name = Customer.select("name").where('customer_id=' + @sale_data.customer_id) + customer= Customer.where('customer_id=' + @sale_data.customer_id) print_settings=PrintSetting.find_by_unique_code(unique_code) + # find order id by sale id + sale_order = SaleOrder.find_by_sale_id(@sale_data.sale_id) + + # 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) - redirect_to origami_root_path + printer.print_receipt_bill(print_settings,@sale_items,@sale_data,customer.name, food_total, beverage_total) + redirect_to origami_path(sale_order.sale_id) end end diff --git a/app/models/order.rb b/app/models/order.rb index 4817c3ce..f882e0a0 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -221,7 +221,7 @@ class Order < ApplicationRecord end #Origami: Cashier : to view booking order Table - def self.get_booking_order_table + def self.get_selected_order(id) booking_orders = Booking.select("sales.receipt_no,orders.status as order_status, bookings.booking_id,sales.sale_id as sale_id,dining_facilities.name as table_name") .joins("left join booking_orders on booking_orders.booking_id = bookings.booking_id") @@ -231,6 +231,32 @@ class Order < ApplicationRecord .where("booking_orders.order_id IS NOT NULL and dining_facilities.type=? and dining_facilities.is_active=?",DiningFacility::TABLE_TYPE,true) .group("bookings.booking_id,sales.receipt_no,orders.status,sales.sale_id,dining_facilities.name,orders.status") + end + + #Origami: Cashier : to view booking order Table + def self.get_completed_order + completed_orders = Booking.select("sales.receipt_no,orders.status as order_status, + bookings.booking_id,sales.sale_id as sale_id,dining_facilities.name as table_name") + .joins("left join booking_orders on booking_orders.booking_id = bookings.booking_id") + .joins("left join dining_facilities on dining_facilities.id = bookings.dining_facility_id") + .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='complete'") + .group("bookings.booking_id,sales.receipt_no,orders.status,sales.sale_id,dining_facilities.name,orders.status") + + end + + #Origami: Cashier : to view booking order Table + def self.get_booking_order_table + booking_orders = Booking.select("sales.receipt_no,orders.status as order_status, + bookings.booking_id,sales.sale_id as sale_id,dining_facilities.name as table_name") + .joins("left join booking_orders on booking_orders.booking_id = bookings.booking_id") + .joins("left join dining_facilities on dining_facilities.id = bookings.dining_facility_id") + .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<>'complete' and booking_orders.order_id IS NOT NULL and dining_facilities.type=? and dining_facilities.is_active=?",DiningFacility::TABLE_TYPE,true) + .group("bookings.booking_id,sales.receipt_no,orders.status,sales.sale_id,dining_facilities.name,orders.status") + end #Origami: Cashier : to view order type Room @@ -242,7 +268,7 @@ class Order < ApplicationRecord .joins("left join orders on orders.order_id = booking_orders.order_id") .joins("left join sale_orders on sale_orders.order_id = orders.order_id") .joins("left join sales on sales.sale_id = sale_orders.sale_id") - .where("booking_orders.order_id IS NOT NULL and dining_facilities.type=? and dining_facilities.is_active=?",DiningFacility::ROOM_TYPE,true) + .where("sales.sale_status<>'complete' and booking_orders.order_id IS NOT NULL and dining_facilities.type=? and dining_facilities.is_active=?",DiningFacility::ROOM_TYPE,true) .group("bookings.booking_id,sales.receipt_no,orders.status,sales.sale_id,dining_facilities.name") end @@ -271,7 +297,7 @@ class Order < ApplicationRecord left join order_items on order_items.order_id = orders.order_id left join sale_orders on sale_orders.order_id = orders.order_id left join sales on sales.sale_id = sale_orders.sale_id") - .where("dining_facilities.is_active=? and orders.date between ? and ?",true,from,to) + .where("sales.sale_status<>'complete' and dining_facilities.is_active=? and orders.date between ? and ?",true,from,to) .group("orders.order_id,order_items.order_items_id,dining_facilities.name,sales.receipt_no,bookings.booking_id,sales.sale_id") end diff --git a/app/models/printer/order_queue_printer.rb b/app/models/printer/order_queue_printer.rb index 5a0eaf25..9c928593 100644 --- a/app/models/printer/order_queue_printer.rb +++ b/app/models/printer/order_queue_printer.rb @@ -40,7 +40,7 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker 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.to_s + "'") + .where("orders.order_id='" + code + "'") .group("order_items.item_code") end diff --git a/app/models/printer/receipt_printer.rb b/app/models/printer/receipt_printer.rb index d203568f..a8a27db3 100644 --- a/app/models/printer/receipt_printer.rb +++ b/app/models/printer/receipt_printer.rb @@ -63,12 +63,13 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker self.print(filename) end -#Bill Receipt Print - def print_receipt_bill(printer_settings,sale_items,sale_data, customer_name) + + #Bill Receipt Print + def print_receipt_bill(printer_settings,sale_items,sale_data, customer_name, food_total, beverage_total) #Use CUPS service #Generate PDF #Print - pdf = ReceiptBillPdf.new(printer_settings, sale_items, sale_data, customer_name) + pdf = ReceiptBillPdf.new(printer_settings, sale_items, sale_data, customer_name, food_total, beverage_total) pdf.render_file "tmp/receipt_bill.pdf" self.print("tmp/receipt_bill.pdf") end diff --git a/app/models/sale_item.rb b/app/models/sale_item.rb index 5d87ff13..f727d184 100644 --- a/app/models/sale_item.rb +++ b/app/models/sale_item.rb @@ -29,6 +29,32 @@ class SaleItem < ApplicationRecord # return false # end end + + def self.calculate_food_beverage(sale_items) + food_prices=0 + beverage_prices=0 + + sale_items.each do |si| + food_price = get_food_price(si.sale_item_id) + beverage_price = get_beverage_price(si.sale_item_id) + + food_prices += food_price + beverage_prices += beverage_price + end + return food_prices, beverage_prices + end + + def get_food_price(sale_item_id) + food_price=SaleItem.select("sale_items.price") + .joins("left join menu_items on menu_items.item_code = sale_items.product_code") + .where("sale_items.sale_item_id=? and menu_items.account_id=0", sale_item_id) + end + + def get_beverage_price(sale_item_id) + beverage_price=SaleItem.select("sale_items.price") + .joins("left join menu_items on menu_items.item_code = sale_items.product_code") + .where("sale_items.sale_item_id=? and menu_items.account_id=1", sale_item_id) + end private def generate_custom_id diff --git a/app/pdf/order_item_pdf.rb b/app/pdf/order_item_pdf.rb index 3044c578..f322de64 100644 --- a/app/pdf/order_item_pdf.rb +++ b/app/pdf/order_item_pdf.rb @@ -1,29 +1,46 @@ class OrderItemPdf < Prawn::Document - + attr_accessor :receipt_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:item_description_width def initialize(order_item, print_settings) - super(:margin => [10, 5, 30, 5], :page_size => [200,400]) + self.page_width = 300 + self.page_height = 400 + self.margin = 10 + self.price_width = 50 + self.qty_width = 50 + self.item_width = self.page_width - (self.price_width + self.qty_width) + self.item_height = 15 + self.item_description_width = self.page_width - (self.price_width + self.qty_width) + self.receipt_width=130 + + 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]) # font "public/fonts/#{font_name}".to_s + ".ttf".to_s # font "public/fonts/Zawgyi-One.ttf" - # font "public/fonts/padauk.ttf" - font_size 9 - text "#{order_item.dining}", :size => 15 + # font "public/fonts/padauk.ttf" + self.header_font_size = 12 + self.item_font_size = 10 + + text "#{order_item.dining}", :size => self.header_font_size,:align => :center stroke_horizontal_rule move_down 5 #order_info - order_info(order_item.order_by,order_item.order_at, order_item.customer) + order_info(order_item.order_by,order_item.order_at) # order items order_items(order_item) end # Write Order Information to PDF - def order_info(order_by, order_at, customer) + def order_info(order_by, order_at) y_position = cursor - bounding_box([0,y_position], :width => 200, :height => 15) do - text "OrderBy:#{order_by} Customer:#{customer} Date:#{order_at.strftime("%Y-%m-%d")}", :size => 7,:align => :left + bounding_box([0,y_position], :width => self.item_width - 50, :height => self.item_height) do + text "OrderBy:#{order_by} ", :size => self.item_font_size,:align => :left + end + + bounding_box([self.item_width - 50,y_position], :width => self.item_width + 50, :height => self.item_height) do + text "Date:#{order_at.strftime("%Y-%m-%d %I:%M %p")}", :size => self.item_font_size,:align => :left end stroke_horizontal_rule @@ -35,12 +52,12 @@ class OrderItemPdf < Prawn::Document def order_items(order_item) y_position = cursor - bounding_box([0,y_position], :width => 180, :height => 15) do - text "Item", :size => 7,:align => :left + bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do + text "Item", :size => self.item_font_size,:align => :left end - bounding_box([160,y_position], :width => 20, :height => 15) do - text "Qty", :size => 7,:align => :right + bounding_box([self.item_width,y_position], :width => self.qty_width, :height => self.item_height) do + text "Qty", :size => self.item_font_size,:align => :right end stroke_horizontal_rule @@ -56,12 +73,12 @@ class OrderItemPdf < Prawn::Document move_down 5 - bounding_box([0,y_position], :width => 180, :height => 20) do - text "#{order_item.item_name}", :size => 7,:align => :left + bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do + text "#{order_item.item_name}", :size => self.item_font_size,:align => :left end - bounding_box([160,y_position], :width => 20, :height => 20) do - text "#{order_item.qty}", :size => 7,:align => :right + bounding_box([self.item_width,y_position], :width => self.qty_width, :height => self.item_height) do + text "#{order_item.qty}", :size => self.item_font_size,:align => :right end move_down 5 diff --git a/app/pdf/order_summary_pdf.rb b/app/pdf/order_summary_pdf.rb index 8a7a1ad9..63d75a78 100644 --- a/app/pdf/order_summary_pdf.rb +++ b/app/pdf/order_summary_pdf.rb @@ -1,19 +1,30 @@ class OrderSummaryPdf < Prawn::Document - + attr_accessor :receipt_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:item_description_width def initialize(order, print_settings) - super(:margin => [10, 5, 30, 5], :page_size => [200,400]) + self.page_width = 300 + self.page_height = 400 + self.margin = 10 + self.price_width = 60 + self.qty_width = 60 + self.item_width = self.page_width - (self.price_width + self.qty_width) + self.item_height = 15 + self.item_description_width = self.page_width - (self.price_width + self.qty_width) + self.receipt_width=130 + + super(:margin => [self.margin, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height]) # font "public/fonts/#{font_name}".to_s + ".ttf".to_s # font "public/fonts/Zawgyi-One.ttf" # font "public/fonts/padauk.ttf" + self.header_font_size = 12 + self.item_font_size = 10 - font_size 9 - text "#{order[0].dining}", :size => 15 + text "#{order[0].dining}", :size => self.header_font_size,:align => :center stroke_horizontal_rule move_down 5 #order_info - order_info(order[0].order_by,order[0].order_at, order[0].customer) + order_info(order[0].order_by,order[0].order_at) # order items order_items(order) @@ -21,11 +32,15 @@ class OrderSummaryPdf < Prawn::Document end # Write Order Information to PDF - def order_info(order_by, order_at, customer) + def order_info(order_by, order_at) y_position = cursor - bounding_box([0,y_position], :width => 200, :height => 15) do - text "OrderBy:#{order_by} Customer:#{customer} Date:#{order_at.strftime("%Y-%m-%d")}", :size => 7,:align => :left + bounding_box([0,y_position], :width => self.item_width - 20, :height => self.item_height) do + text "OrderBy:#{order_by} ", :size => self.item_font_size,:align => :left + end + + bounding_box([self.item_width - 20,y_position], :width => self.item_width + 20, :height => self.item_height) do + text "Date:#{order_at.strftime("%Y-%m-%d %I:%M %p")}", :size => self.item_font_size,:align => :left end stroke_horizontal_rule @@ -37,12 +52,12 @@ class OrderSummaryPdf < Prawn::Document def order_items(order_item) y_position = cursor - bounding_box([0,y_position], :width => 180, :height => 15) do - text "Item", :size => 7,:align => :left + bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do + text "Item", :size => self.item_font_size,:align => :left end - bounding_box([160,y_position], :width => 20, :height => 15) do - text "Qty", :size => 7,:align => :right + bounding_box([self.item_width,y_position], :width => self.qty_width, :height => self.item_height) do + text "Qty", :size => self.item_font_size,:align => :right end stroke_horizontal_rule @@ -59,13 +74,13 @@ class OrderSummaryPdf < Prawn::Document move_down 5 order_item.each do|odi| - bounding_box([0,y_position], :width => 180, :height => 20) do - text "#{odi.item_name}", :size => 7,:align => :left - end + 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 + end - bounding_box([160,y_position], :width => 20, :height => 20) do - text "#{odi.qty}", :size => 7,:align => :right - 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 => :right + end end move_down 5 diff --git a/app/pdf/receipt_bill_pdf.rb b/app/pdf/receipt_bill_pdf.rb index 5853b946..f91aebe1 100644 --- a/app/pdf/receipt_bill_pdf.rb +++ b/app/pdf/receipt_bill_pdf.rb @@ -1,30 +1,36 @@ class ReceiptBillPdf < Prawn::Document - attr_accessor :receipt_width,:price_column_width,:p_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_column_width,:item_description_width - def initialize(printer_settings, sale_items, sale_data, customer_name) - self.p_width = 200 + attr_accessor :receipt_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(printer_settings, sale_items, sale_data, customer_name, food_total, beverage_total) + self.page_width = 300 self.page_height = 1450 self.margin = 10 - # self.price_width = self.p_width / 2 - self.price_width=80 - self.item_width = self.p_width - self.price_width - self.item_height = self.item_height - self.qty_column_width = self.p_width / 2 - self.item_description_width=self.p_width - self.price_width - self.receipt_width=130 + self.price_width = 50 + self.qty_width = 30 + self.total_width = 50 + 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 - (self.price_width + self.qty_width + self.total_width) + self.receipt_width=100 - @item_width = self.p_width.to_i / 2 - @qty_width = @item_width.to_i / 3 - @double = @qty_width * 1.3 - @half_qty = @qty_width / 2 + # @item_width = self.page_width.to_i / 2 + # @qty_width = @item_width.to_i / 3 + # @double = @qty_width * 1.3 + # @half_qty = @qty_width / 2 #setting page margin and width - super(:margin => [self.margin, self.margin, self.margin, self.margin], :page_size => [self.p_width, self.page_height]) - self.header_font_size = 10 - self.item_font_size = 9 + super(:margin => [self.margin, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height]) + + # font "public/fonts/#{font_name}".to_s + ".ttf".to_s + # font "public/fonts/Zawgyi-One.ttf" + # font "public/fonts/padauk.ttf" + self.header_font_size = 12 + self.item_font_size = 10 header( printer_settings.printer_name, printer_settings.name) - stroke_horizontal_rule + + stroke_horizontal_rule + cashier_info(sale_data, customer_name) - line_items(sale_items) + line_items(sale_items, food_total, beverage_total) all_total(sale_data) @@ -38,71 +44,66 @@ class ReceiptBillPdf < Prawn::Document move_down 5 stroke_horizontal_rule - end def cashier_info(sale_data, customer_name) - move_down 5 - move_down 2 + move_down 7 + # move_down 2 y_position = cursor - bounding_box([0,y_position], :width =>self.price_width, :height => self.item_height) do + bounding_box([0,y_position], :width =>self.receipt_width, :height => self.item_height) do text "Receipt No:", :size => self.item_font_size,:align => :left end - bounding_box([self.price_width, y_position], :width =>self.receipt_width) do - text "#{sale_data.receipt_no}" , :size => self.item_font_size, :align => :left + bounding_box([self.receipt_width, y_position], :width =>self.receipt_width) do + text "#{sale_data.receipt_no}" , :size => self.item_font_size, :align => :left end move_down 5 y_position = cursor - bounding_box([0,y_position], :width =>self.price_width, :height => self.item_height) do + bounding_box([0,y_position], :width =>self.receipt_width, :height => self.item_height) do text "Customer:", :size => self.item_font_size,:align => :left end - bounding_box([self.price_width,y_position], :width =>self.price_width) do + bounding_box([self.receipt_width,y_position], :width =>self.receipt_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.price_width, :height => self.item_height) do + bounding_box([0,y_position], :width =>self.receipt_width, :height => self.item_height) do text "Date:", :size => self.item_font_size,:align => :left end - bounding_box([self.price_width,y_position], :width =>self.price_width) do + bounding_box([self.receipt_width,y_position], :width =>self.receipt_width) do text "#{sale_data.receipt_date.strftime('%Y %m %d %h:%m')}" , :size => self.item_font_size,:align => :left end # stroke_horizontal_rule move_down 5 end - def line_items(sale_items) + def line_items(sale_items, food_total, beverage_total) y_position = cursor - qty_column_width = self.p_width * 0.2 - item_description_width = self.p_width * 0.5 - price_column_width = self.p_width * 0.3 - - stroke_horizontal_rule move_down 5 - y_position = cursor + pad_top(15) { # @item_width.to_i + @half_qty.to_i - text_box "Items", :at =>[0,y_position], :width => @item_width.to_i - @half_qty.to_i , :height =>15, :overflow => :shrink_to_fix, :size => self.item_font_size - text_box "Price", :at =>[@item_width.to_i - @half_qty.to_i,y_position], :width => @qty_width, :height =>15, :overflow => :shrink_to_fix, :size => self.item_font_size, :align => :right - text_box "Qty", :at =>[@item_width.to_i-@qty_width,y_position], :width => @half_qty, :height =>15, :overflow => :shrink_to_fix, :size => self.item_font_size, :align => :right - text_box "Total", :at =>[@item_width.to_i + @half_qty.to_i,y_position], :width => @double, :height =>15, :overflow => :shrink_to_fix, :size => self.item_font_size, :align => :right + text_box "Items", :at =>[0,y_position], :width => self.item_width - 20, :height =>self.item_height, :size => self.item_font_size + text_box "Price", :at =>[self.item_width-20,y_position], :width => self.price_width, :height =>self.item_height, :size => self.item_font_size, :align => :right + text_box "Qty", :at =>[self.item_width+self.price_width,y_position], :width => self.qty_width, :height =>self.item_height, :size => self.item_font_size, :align => :right + text_box "Total", :at =>[self.item_width+self.price_width+self.qty_width,y_position], :width => self.total_width, :height =>self.item_height, :size => self.item_font_size, :align => :right } move_down 5 stroke_horizontal_rule - add_line_item_row(sale_items) + add_line_item_row(sale_items, food_total, beverage_total) end - def add_line_item_row(sale_items) + def add_line_item_row(sale_items, food_total, beverage_total) + item_name_width = self.item_width-20 y_position = cursor move_down 5 sub_total = 0.0 @@ -119,53 +120,67 @@ class ReceiptBillPdf < Prawn::Document pad_top(15) { # @item_width.to_i + @half_qty.to_i - text_box "#{product_name}", :at =>[0,y_position], :width => @item_width.to_i - @half_qty.to_i , :height =>15, :overflow => :shrink_to_fix, :size => self.item_font_size - text_box "#{price}", :at =>[@item_width.to_i - @half_qty.to_i,y_position], :width => @qty_width, :height =>15, :overflow => :shrink_to_fix, :size => self.item_font_size, :align => :right - text_box "#{qty.to_i}", :at =>[@item_width.to_i-@qty_width,y_position], :width => @half_qty, :height =>15, :overflow => :shrink_to_fix, :size => self.item_font_size, :align => :right - text_box "#{total_price}", :at =>[@item_width.to_i + @half_qty.to_i,y_position], :width => @double, :height =>15, :overflow => :shrink_to_fix, :size => self.item_font_size, :align => :right + text_box "#{product_name}", :at =>[0,y_position], :width => item_name_width, :height =>self.item_height, :overflow => :shrink_to_fix, :size => self.item_font_size + text_box "#{price}", :at =>[item_name_width,y_position], :width => self.price_width, :height =>self.item_height, :size => self.item_font_size, :align => :right + text_box "#{qty.to_i}", :at =>[item_name_width+self.price_width,y_position], :width => self.qty_width, :height =>self.item_height, :size => self.item_font_size, :align => :right + text_box "#{total_price}", :at =>[item_name_width+self.price_width+self.qty_width,y_position], :width =>self.total_width, :height =>self.item_height, :size => self.item_font_size, :align => :right } move_down 3 end + stroke_horizontal_rule + move_down 5 y_position = cursor - bounding_box([0,y_position], :width =>self.price_width, :height => self.item_height) do + bounding_box([0,y_position], :width =>(item_name_width+self.price_width+self.qty_width), :height => self.item_height) do text "Sub Total", :size => self.item_font_size,:align => :left end - bounding_box([self.price_width,y_position], :width =>self.price_width) do + bounding_box([(item_name_width+self.price_width+self.qty_width),y_position], :width =>self.total_width) do text "#{sub_total}" , :size => self.item_font_size,:align => :right end + + # Food and Beverage + food_beverage_total = food_total.to_s + '/' + beverage_total.to_s + move_down 5 + y_position = cursor + bounding_box([0,y_position], :width =>(item_name_width+self.price_width+self.qty_width), :height => self.item_height) do + text "Food/Beverage Total", :size => self.item_font_size,:align => :left + end + bounding_box([(item_name_width+self.price_width+self.qty_width),y_position], :width =>self.total_width) do + text "#{ food_beverage_total }" , :size => self.item_font_size,:align => :right + end end def all_total(sale_data) + item_name_width = self.item_width-20 move_down 5 - y_position =cursor + y_position = cursor - bounding_box([0,y_position], :width =>self.price_width, :height => self.item_height) do + bounding_box([0,y_position], :width =>(item_name_width+self.price_width+self.qty_width), :height => self.item_height) do text "Discount", :size => self.item_font_size,:align => :left end - bounding_box([self.price_width,y_position], :width =>self.price_width) do + bounding_box([(item_name_width+self.price_width+self.qty_width),y_position], :width =>self.total_width) do text "( " +"#{sale_data.total_discount}" +" )" , :size => self.item_font_size,:align => :right end move_down 5 - y_position =cursor + y_position = cursor - bounding_box([0,y_position], :width =>self.price_width, :height => self.item_height) do + bounding_box([0,y_position], :width =>(item_name_width+self.price_width+self.qty_width), :height => self.item_height) do text "Total Tax", :size => self.item_font_size,:align => :left end - bounding_box([self.price_width,y_position], :width =>self.price_width) do + bounding_box([(item_name_width+self.price_width+self.qty_width),y_position], :width =>self.total_width) do text "( " +"#{sale_data.total_tax}" +" )" , :size => self.item_font_size,:align => :right end move_down 5 y_position = cursor move_down 5 - bounding_box([0,y_position], :width =>self.price_width, :height => self.item_height) do + bounding_box([0,y_position], :width =>(item_name_width+self.price_width+self.qty_width), :height => self.item_height) do text "Grand Total", :size => self.item_font_size,:align => :left end - bounding_box([self.price_width,y_position], :width =>self.price_width) do + bounding_box([(item_name_width+self.price_width+self.qty_width),y_position], :width =>self.total_width) do text "#{sale_data.grand_total}" , :size => self.item_font_size,:align => :right end move_down 5 diff --git a/app/views/origami/discounts/index.html.erb b/app/views/origami/discounts/index.html.erb index e95bdcc3..65b376d8 100644 --- a/app/views/origami/discounts/index.html.erb +++ b/app/views/origami/discounts/index.html.erb @@ -4,22 +4,22 @@
<%=@sale_data.sale_id %>
+<%=@sale_data.sale_id %>
Receipt No: <%=@sale_data.receipt_no rescue ' '%>
-Cashier: <%=@sale_data.cashier_name rescue ' '%>
+Date: <%=@sale_data.receipt_date.strftime("%d/%m/%Y - %I:%M %p") rescue '-'%>
| Items | @@ -31,7 +31,7 @@ <% sub_total = 0 %> <% @sale_data.sale_items.each do |sale_item| %> <% sub_total += sale_item.qty*sale_item.unit_price%> -||
|---|---|---|
| <%=sale_item.product_name%>@<%=sale_item.unit_price%> | @@ -52,23 +52,23 @@Sub Total: | <%=sub_total%> |
| Discount: | (<%=@sale_data.total_discount rescue 0%>) | |
| Tax: | <%=@sale_data.total_tax rescue 0%> | |
| Grand Total: | <%=@sale_data.grand_total rescue 0%> | |
| <%= sale_item.product_name %> | +<%= sale_item.qty %> | +<%= sale_item.qty*sale_item.price %> | +
| <%= order_item.item_name %> | +<%= order_item.qty %> | +<%= order_item.qty*order_item.price %> | +
| Sub Total: | -+ | <%=sub_total%> |
| Discount: | -+ | (<%=@selected_item.total_discount rescue 0%>) |
| Tax: | -+ | <%=@selected_item.total_tax rescue 0%> |
| Grand Total: | -+ | <%=@selected_item.grand_total rescue 0%> |