diff --git a/Gemfile.lock b/Gemfile.lock index e2c1dd73..badb3aa4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,6 +1,6 @@ GIT remote: git://github.com/amatsuda/kaminari.git - revision: c3c853a944cd2bff072ae05e48c563b2c9a29597 + revision: bc52ae73d41386d344b5d1b18e689e5a988f1a03 branch: master specs: kaminari (1.0.1) @@ -92,7 +92,7 @@ GEM railties (>= 3.2, < 5.2) globalid (0.4.0) activesupport (>= 4.2.0) - i18n (0.8.1) + i18n (0.8.4) jbuilder (2.6.4) activesupport (>= 3.0.0) multi_json (>= 1.2) @@ -124,7 +124,7 @@ GEM ttfunk (~> 1.5) prawn-table (0.2.2) prawn (>= 1.3.0, < 3.0.0) - puma (3.8.2) + puma (3.9.1) rack (2.0.3) rack-cors (0.4.1) rack-protection (2.0.0) diff --git a/app/controllers/crm/customers_controller.rb b/app/controllers/crm/customers_controller.rb index 4e97faec..d173888e 100644 --- a/app/controllers/crm/customers_controller.rb +++ b/app/controllers/crm/customers_controller.rb @@ -4,7 +4,7 @@ class Crm::CustomersController < ApplicationController # GET /crm/customers # GET /crm/customers.json def index - @crm_customers = Crm::Customer.all + @crm_customers = Customer.all end # GET /crm/customers/1 @@ -14,7 +14,7 @@ class Crm::CustomersController < ApplicationController # GET /crm/customers/new def new - @crm_customer = Crm::Customer.new + @crm_customer = Customer.new end # GET /crm/customers/1/edit @@ -24,7 +24,7 @@ class Crm::CustomersController < ApplicationController # POST /crm/customers # POST /crm/customers.json def create - @crm_customer = Crm::Customer.new(crm_customer_params) + @crm_customer = Customer.new(crm_customer_params) respond_to do |format| if @crm_customer.save @@ -64,7 +64,7 @@ class Crm::CustomersController < ApplicationController private # Use callbacks to share common setup or constraints between actions. def set_crm_customer - @crm_customer = Crm::Customer.find(params[:id]) + @crm_customer = Customer.find(params[:id]) end # Never trust parameters from the scary internet, only allow the white list through. diff --git a/app/controllers/origami/home_controller.rb b/app/controllers/origami/home_controller.rb index be5045d9..480e9204 100644 --- a/app/controllers/origami/home_controller.rb +++ b/app/controllers/origami/home_controller.rb @@ -1,16 +1,26 @@ class Origami::HomeController < BaseOrigamiController def index - @order_table = Order.get_order_table() - @order_rooms = Order.get_order_rooms() + @booking_orders = Order.get_booking_order_table() + @booking_rooms = Order.get_booking_order_rooms() @orders = Order.get_orders() end - + def show str = [] - @order_details = OrderItem.get_order_items_details(params[:order_id]) - @order_details.each do |ord_detail| - str.push(ord_detail) - end - render :json => str.to_json + + + if !params[:sale_id].nil? + @order_details = SaleItem.get_order_items_details(params[:sale_id]) + @order_details.each do |ord_detail| + str.push(ord_detail) + end + render :json => str.to_json + else + @order_details = OrderItem.get_order_items_details(params[:order_id]) + @order_details.each do |ord_detail| + str.push(ord_detail) + end + render :json => str.to_json + end end end diff --git a/app/controllers/origami/request_bills_controller.rb b/app/controllers/origami/request_bills_controller.rb index 40fc27f1..3fd7ffea 100644 --- a/app/controllers/origami/request_bills_controller.rb +++ b/app/controllers/origami/request_bills_controller.rb @@ -3,15 +3,18 @@ class Origami::RequestBillsController < BaseOrigamiController def create @sale = Sale.new - check_order = Order.find_by_id(params[:id]) - if check_order - @order_details = OrderItem.get_order_items_details(check_order.id) - @order_details = OrderItem.get_order_items_details(check_order.id) - @status, @sale_id = @sale.generate_invoice_from_order(check_order.id, nil,current_login_employee.name) - @sale_data = Sale.find_by_id(@sale_id) - @sale_items = SaleItem.where("sale_id=?",@sale_id) - end + booking_id = params[:id] + check_booking = Booking.find_by_booking_id(booking_id) + if check_booking.sale_id.nil? + #check if it doesn't exist + @status = @sale.generate_invoice_from_booking(check_booking.id,current_login_employee.name) + @sale_data = Sale.find_by_sale_id(check_booking.sale_id) + @sale_items = SaleItem.where("sale_id=?",check_booking.sale_id) + else + @sale_data = Sale.find_by_sale_id(check_booking.sale_id) + @sale_items = SaleItem.where("sale_id=?",check_booking.sale_id) + end unique_code="ReceiptBillPdf" @@ -19,7 +22,7 @@ class Origami::RequestBillsController < BaseOrigamiController printer = Printer::ReceiptPrinter.new(print_settings) - printer.print_receipt_bill(print_settings,@sale_items,@sale) + printer.print_receipt_bill(print_settings,@sale_items,@sale,@sale_data) end @@ -30,4 +33,5 @@ class Origami::RequestBillsController < BaseOrigamiController @sale_data = Sale.find_by_id(sale_id) end end + end diff --git a/app/controllers/settings/menu_categories_controller.rb b/app/controllers/settings/menu_categories_controller.rb index d7f373aa..c2a521ae 100644 --- a/app/controllers/settings/menu_categories_controller.rb +++ b/app/controllers/settings/menu_categories_controller.rb @@ -63,7 +63,14 @@ class Settings::MenuCategoriesController < ApplicationController # DELETE /settings/menu_categories/1 # DELETE /settings/menu_categories/1.json def destroy + # instances = MenuItemInstance.where("menu_item_id=?",@settings_menu_item.id) + # instances.each do |instance| + # instance.destroy + # end + # @settings_menu_item.destroy + # @settings_menu_category.destroy + abc = MenuCategory.destroyCategory(@settings_menu_category) respond_to do |format| format.html { redirect_to settings_menu_categories_path, notice: 'Menu category was successfully destroyed.' } format.json { head :no_content } diff --git a/app/controllers/settings/menu_item_instances_controller.rb b/app/controllers/settings/menu_item_instances_controller.rb index f9c20a2d..2b1fcecf 100644 --- a/app/controllers/settings/menu_item_instances_controller.rb +++ b/app/controllers/settings/menu_item_instances_controller.rb @@ -11,18 +11,21 @@ class Settings::MenuItemInstancesController < ApplicationController # GET /settings/menu_item_instances/1 # GET /settings/menu_item_instances/1.json def show - @category = MenuCategory.find(@item.menu_category_id) + id = MenuItemInstance.findParentCategory(@item) + @category = MenuCategory.find(id) end # GET /settings/menu_item_instances/new def new - @category = MenuCategory.find(@item.menu_category_id) + id = MenuItemInstance.findParentCategory(@item) + @category = MenuCategory.find(id) @settings_menu_item_instances = MenuItemInstance.new end # GET /settings/menu_item_instances/1/edit def edit - @category = MenuCategory.find(@item.menu_category_id) + id = MenuItemInstance.findParentCategory(@item) + @category = MenuCategory.find(id) end # POST /settings/menu_item_instances @@ -30,6 +33,7 @@ class Settings::MenuItemInstancesController < ApplicationController def create @settings_menu_item_instances = MenuItemInstance.new(settings_menu_item_instance_params) + #check if the menu item type is simple or not( not only the diff of status .. here is different routes) if params[:simple_menu_item_id] @settings_menu_item_instances.menu_item_id = params[:simple_menu_item_id] catID = MenuItem.find(params[:simple_menu_item_id]) @@ -38,7 +42,8 @@ class Settings::MenuItemInstancesController < ApplicationController catID = MenuItem.find(params[:set_menu_item_id]) end - category = MenuCategory.find(catID.menu_category_id) + id = MenuItemInstance.findParentCategory(catID) + category = MenuCategory.find(id) respond_to do |format| if @settings_menu_item_instances.save @settings_menu_item_instances.item_attributes = params[:menu_item_instance][:item_attributes].reject(&:blank?) @@ -55,14 +60,15 @@ class Settings::MenuItemInstancesController < ApplicationController # PATCH/PUT /settings/menu_item_instances/1 # PATCH/PUT /settings/menu_item_instances/1.json def update - puts "params[:menu_item_instance][:item_attributes]" - puts params[:menu_item_instance][:item_attributes] + #check if the menu item type is simple or not( not only the diff of status .. here is different routes) if params[:simple_menu_item_id] catID = MenuItem.find(params[:simple_menu_item_id]) else catID = MenuItem.find(params[:set_menu_item_id]) end - category = MenuCategory.find(catID.menu_category_id) + + id = MenuItemInstance.findParentCategory(catID) + category = MenuCategory.find(id) respond_to do |format| if @settings_menu_item_instances.update(settings_menu_item_instance_params) @@ -86,7 +92,13 @@ class Settings::MenuItemInstancesController < ApplicationController else catID = MenuItem.find(params[:set_menu_item_id]) end - category = MenuCategory.find(catID.menu_category_id) + # check if the menu item is sub of another menu item + if catID.menu_category_id + category = MenuCategory.find(catID.menu_category_id) + else + item = MenuItem.find(catID.menu_item_id) + category = MenuCategory.find(item.menu_category_id) + end respond_to do |format| format.html { redirect_to settings_menu_category_simple_menu_item_path(category,catID), notice: 'Menu item instance was successfully destroyed.' } format.json { head :no_content } diff --git a/app/controllers/settings/menus_controller.rb b/app/controllers/settings/menus_controller.rb index e0ecde30..fa6ac158 100644 --- a/app/controllers/settings/menus_controller.rb +++ b/app/controllers/settings/menus_controller.rb @@ -55,7 +55,8 @@ class Settings::MenusController < ApplicationController # DELETE /settings/menus/1 # DELETE /settings/menus/1.json def destroy - @settings_menu.destroy + # @settings_menu.destroy + abc = Menu.destroyMenu(@settings_menu) respond_to do |format| format.html { redirect_to settings_menus_path, notice: 'Menu was successfully destroyed.' } format.json { head :no_content } diff --git a/app/controllers/settings/set_menu_items_controller.rb b/app/controllers/settings/set_menu_items_controller.rb index f6771548..1c3e2247 100644 --- a/app/controllers/settings/set_menu_items_controller.rb +++ b/app/controllers/settings/set_menu_items_controller.rb @@ -62,7 +62,7 @@ class Settings::SetMenuItemsController < ApplicationController # DELETE /settings/menu_items/1 # DELETE /settings/menu_items/1.json def destroy - # @settings_menu_item.destroy + abc = MenuItem.deleteRecursive(@settings_menu_item) respond_to do |format| format.html { redirect_to settings_menu_category_set_menu_items_path, notice: 'Menu item was successfully destroyed.' } format.json { head :no_content } diff --git a/app/controllers/settings/simple_menu_items_controller.rb b/app/controllers/settings/simple_menu_items_controller.rb index e0d45fcb..b02310dc 100644 --- a/app/controllers/settings/simple_menu_items_controller.rb +++ b/app/controllers/settings/simple_menu_items_controller.rb @@ -59,7 +59,7 @@ class Settings::SimpleMenuItemsController < ApplicationController # DELETE /settings/menu_items/1 # DELETE /settings/menu_items/1.json def destroy - # @settings_menu_item.destroy + abc = MenuItem.deleteRecursive(@settings_menu_item) respond_to do |format| format.html { redirect_to settings_menu_category_simple_menu_items_path, notice: 'Menu item was successfully destroyed.' } format.json { head :no_content } diff --git a/app/jobs/order_queue_processor_job.rb b/app/jobs/order_queue_processor_job.rb index e92faa36..10081ad5 100644 --- a/app/jobs/order_queue_processor_job.rb +++ b/app/jobs/order_queue_processor_job.rb @@ -1,5 +1,5 @@ class OrderQueueProcessorJob < ApplicationJob - queue_as :default + queue_as :oqs def perform(order_id) # Do something later diff --git a/app/models/customer.rb b/app/models/customer.rb index 86a638c7..4bdc290a 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -1,6 +1,6 @@ class Customer < ApplicationRecord self.primary_key = "customer_id" - + before_create :generate_custom_id has_many :orders has_many :sales diff --git a/app/models/menu.rb b/app/models/menu.rb index 0c956a1e..05adfac4 100644 --- a/app/models/menu.rb +++ b/app/models/menu.rb @@ -22,4 +22,13 @@ class Menu < ApplicationRecord return current_menu end + + def self.destroyMenu(menu) + cats = MenuCategory.where("menu_id=?",menu.id) + cats.each do |cat| + abc = MenuCategory.destroyCategory(cat) + end + menu.destroy + return false + end end diff --git a/app/models/menu_category.rb b/app/models/menu_category.rb index 474990f2..e660b4b5 100644 --- a/app/models/menu_category.rb +++ b/app/models/menu_category.rb @@ -8,5 +8,29 @@ class MenuCategory < ApplicationRecord default_scope { order('order_by asc') } + def self.destroyCategory(menu_category) + # find the sub menu item of current item + sub_menu_cat = MenuCategory.where("menu_category_id=?",menu_category.id) + if sub_menu_cat.length != 0 + sub_menu_cat.each do |sub| + if destroyCategory(sub) + end + end + # find the items of current menu item + items = MenuItem.where("menu_category_id=?",menu_category.id) + items.each do |item| + abc = MenuItem.deleteRecursive(item) + end + menu_category.destroy + return true + else + items = MenuItem.where("menu_category_id=?",menu_category.id) + items.each do |item| + abc = MenuItem.deleteRecursive(item) + end + menu_category.destroy + return false + end + end end diff --git a/app/models/menu_item.rb b/app/models/menu_item.rb index 7d69ca3e..9c5a75ac 100644 --- a/app/models/menu_item.rb +++ b/app/models/menu_item.rb @@ -1,5 +1,6 @@ class MenuItem < ApplicationRecord - # belongs_to :account + + #belongs_to :account belongs_to :menu_category, :optional => true has_many :menu_item_instances belongs_to :parent, :class_name => "MenuItem", foreign_key: "menu_item_id", :optional => true @@ -38,4 +39,31 @@ class MenuItem < ApplicationRecord return nil end + + def self.deleteRecursive(menu_item) + + # find the sub menu item of current item + sub_menu_items = MenuItem.where("menu_item_id=?",menu_item.id) + if sub_menu_items.length != 0 + sub_menu_items.each do |subitem| + if deleteRecursive(subitem) + end + end + # find the instances of current menu item + instances = MenuItemInstance.where("menu_item_id=?",menu_item.id) + instances.each do |instance| + instance.destroy + end + menu_item.destroy + return true + else + instances = MenuItemInstance.where("menu_item_id=?",menu_item.id) + instances.each do |instance| + instance.destroy + end + menu_item.destroy + return false + end + + end end diff --git a/app/models/menu_item_instance.rb b/app/models/menu_item_instance.rb index e7f7775e..09225a23 100644 --- a/app/models/menu_item_instance.rb +++ b/app/models/menu_item_instance.rb @@ -1,4 +1,12 @@ class MenuItemInstance < ApplicationRecord belongs_to :menu_item + def self.findParentCategory(item) + if item.menu_category_id + return item.menu_category_id + else + parentitem = MenuItem.find(item.menu_item_id) + findParentCategory(parentitem) + end + end end diff --git a/app/models/order.rb b/app/models/order.rb index 60eca518..3fabf91b 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -192,7 +192,7 @@ class Order < ApplicationRecord # Count number of different items self.item_count = self.order_items.item_count self.quantity_count = quantity_count - # Counter number of quantity + # Counter number of quantityf end #Process order items and send to order queue @@ -209,6 +209,7 @@ class Order < ApplicationRecord end #Origami: Cashier : to view order type Table + def self.get_order_table order_table = Order.select("orders.id as order_id,sum(order_items.qty*order_items.price) as total_price, order_items.id as order_items_id,dining_facilities.name as table_name") @@ -221,33 +222,61 @@ class Order < ApplicationRecord .group("orders.id, order_items.id,dining_facilities.name") + 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 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::TABLE_TYPE,true) + .group("bookings.booking_id") + + end + #Origami: Cashier : to view order type Room + def self.get_booking_order_rooms + booking_rooms = Booking.select("sales.receipt_no,orders.status as order_status,bookings.booking_id,sales.sale_id as sale_id,dining_facilities.name as room_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 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) + .group("bookings.booking_id") end #Origami: Cashier : to view order type Room def self.get_order_rooms - order_rooms = Order.select("orders.id as order_id,sum(order_items.qty*order_items.price) as total_price, + order_rooms = Order.select("orders.order_id as order_id,sum(order_items.qty*order_items.price) as total_price, order_items.id as order_items_id,dining_facilities.name as room_name") - .joins("left join booking_orders on booking_orders.order_id = orders.id - left join bookings on bookings.id = booking_orders.id + .joins("left join booking_orders on booking_orders.order_id = orders.order_id + left join bookings on bookings.booking_id = booking_orders.order_id left join dining_facilities on dining_facilities.id = bookings.dining_facility_id - left join order_items on order_items.order_id = orders.id") + left join order_items on order_items.order_id = orders.order_id") .where("dining_facilities.type=? and orders.order_type=? and dining_facilities.is_active=?",DiningFacility::ROOM_TYPE,"dine_in",true) - .group("orders.id,order_items.id,dining_facilities.name") + .group("orders.order_id,order_items.id,dining_facilities.name") + end #Origami: Cashier : to view orders def self.get_orders from = Time.now.beginning_of_day.utc to = Time.now.end_of_day.utc - orders = Order.select("orders.id as order_id,sum(order_items.qty*order_items.price) as total_price, - order_items.id as order_items_id,dining_facilities.name as table_or_room_name") - .joins("left join booking_orders on booking_orders.order_id = orders.id - left join bookings on bookings.id = booking_orders.id + orders = Order.select("orders.order_id as order_id,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.order_id = orders.order_id + left join bookings on bookings.booking_id = booking_orders.order_id left join dining_facilities on dining_facilities.id = bookings.dining_facility_id - left join order_items on order_items.order_id = orders.id") + + 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) + .group("orders.id,order_items.id,dining_facilities.name") + end + private def generate_custom_id self.order_id = SeedGenerator.generate_id(self.class.name, "ODR") diff --git a/app/models/order_item.rb b/app/models/order_item.rb index 0e258ac4..a85d1113 100644 --- a/app/models/order_item.rb +++ b/app/models/order_item.rb @@ -39,11 +39,19 @@ class OrderItem < ApplicationRecord end #Origami : Cashier : to show order items details - def self.get_order_items_details(order_id) - order_details = OrderItem.select("order_items.item_name,order_items.qty,order_items.price,(order_items.qty*order_items.price) as total_price") - .joins("left join orders on orders.id = order_items.order_id") - .where("order_items.order_id=?",order_id) - + + def self.get_order_items_details(booking_id) + booking_orders = BookingOrder.where("booking_id=?",booking_id) + if booking_orders + booking_orders.each do |book_order| + order_details = OrderItem.select("order_items.item_name,order_items.qty,order_items.price,(order_items.qty*order_items.price) as total_price") + .joins("left join orders on orders.order_id = order_items.order_id") + .where("order_items.order_id=?",book_order.order) + return order_details + end + else + return false + end end private diff --git a/app/models/printer/receipt_printer.rb b/app/models/printer/receipt_printer.rb index d25dc8c3..86d43190 100644 --- a/app/models/printer/receipt_printer.rb +++ b/app/models/printer/receipt_printer.rb @@ -64,12 +64,12 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker self.print(filename) end #Bill Receipt Print - def print_receipt_bill(printer_settings,sale_items,sale) + def print_receipt_bill(printer_settings,sale_items,sale,sale_data) #Use CUPS service #Generate PDF #Print - pdf = ReceiptBillPdf.new(printer_settings,sale_items,sale) - pdf.render_file "tmp/receipt_bill_#{sale.id}.pdf" - self.print("tmp/receipt_bill_#{sale.id}.pdf") + pdf = ReceiptBillPdf.new(printer_settings,sale_items,sale,sale_data) + pdf.render_file "tmp/receipt_bill.pdf" + self.print("tmp/receipt_bill.pdf") end end diff --git a/app/models/sale.rb b/app/models/sale.rb index 880f0c54..d9725e4b 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -25,9 +25,9 @@ class Sale < ApplicationRecord #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, requested_by) + status, sale_id = generate_invoice_from_order(order.order_id, nil, booking, requested_by) else - status, sale_id = generate_invoice_from_order(order.order_id, booking.sale_id, requested_by) + status, sale_id = generate_invoice_from_order(order.order_id, booking.sale_id, booking, requested_by) end booking.sale_id = sale_id end @@ -37,7 +37,7 @@ class Sale < ApplicationRecord end end - def generate_invoice_from_order (order_id, sale_id, requested_by) + def generate_invoice_from_order (order_id, sale_id, booking, requested_by) taxable = true #if sale_id is exsit and validate #add order to that invoice @@ -68,8 +68,8 @@ class Sale < ApplicationRecord add_item(item) end - link_order_sale(order.id) - + link_order_sale(order.id) + end @@ -79,6 +79,11 @@ class Sale < ApplicationRecord #Update the order items that is billed order.update_items_status_to_billed(nil) + order.status = "billed" + order.save + + booking.sale_id = self.id + booking.save return true, self.id end diff --git a/app/models/sale_item.rb b/app/models/sale_item.rb index e202a53c..52ab480b 100644 --- a/app/models/sale_item.rb +++ b/app/models/sale_item.rb @@ -10,8 +10,24 @@ class SaleItem < ApplicationRecord def compute_item end + + def self.get_order_items_details(sale_id) + sale_orders = SaleOrder.where("sale_id=?",sale_id) + if sale_orders + sale_orders.each do |sale_order| + order_details = SaleItem.select("sales.total_discount as discount_amount,DATE_FORMAT(sales.receipt_date,'%Y-%m-%d %h:%m') as receipt_date,sales.cashier_name,sales.receipt_no,sale_items.product_name as item_name,sale_items.qty,sale_items.price,sale_items.unit_price as total_price") + .joins("left join sales on sales.id = sale_items.sale_id") + .where("sale_items.sale_id=?",sale_order.sale_id) + return order_details + end + else + return false + end + end + private def generate_custom_id self.sale_item_id = SeedGenerator.generate_id(self.class.name, "SLI") + end end diff --git a/app/models/seed_generator.rb b/app/models/seed_generator.rb index d55af84d..5e7864b6 100644 --- a/app/models/seed_generator.rb +++ b/app/models/seed_generator.rb @@ -14,9 +14,11 @@ class SeedGenerator < ApplicationRecord seed.current = current_no seed.save end + padding_len = 15 - prefix.length return prefix +"-"+ seed.current.to_s.to_s.rjust((14-prefix.length)+1,'0') + end def self.new_receipt_no diff --git a/app/pdf/receipt_bill_pdf.rb b/app/pdf/receipt_bill_pdf.rb index e9ad042c..ffce7da2 100644 --- a/app/pdf/receipt_bill_pdf.rb +++ b/app/pdf/receipt_bill_pdf.rb @@ -1,11 +1,11 @@ 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) + def initialize(printer_settings, sale_items,sale, sale_data) self.p_width = 200 self.page_height = 1450 self.margin = 10 # self.price_width = self.p_width / 2 - self.price_width=90 + 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 @@ -14,7 +14,7 @@ class ReceiptBillPdf < Prawn::Document @item_width = self.p_width.to_i / 2 @qty_width = @item_width.to_i / 3 - @double = @qty_width * 2 + @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]) @@ -23,8 +23,9 @@ class ReceiptBillPdf < Prawn::Document header( printer_settings.printer_name, printer_settings.name) stroke_horizontal_rule - cashier_info(sale.receipt_no,sale.customer.name, sale.receipt_date) + cashier_info(sale.receipt_no,sale.customer, sale.receipt_date) line_items(sale_items) + all_total(sale_data) end @@ -89,7 +90,6 @@ class ReceiptBillPdf < Prawn::Document 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 "Discount", :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 "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 } @@ -98,13 +98,80 @@ class ReceiptBillPdf < Prawn::Document stroke_horizontal_rule add_line_item_row(sale_items) - stroke_horizontal_rule + end def add_line_item_row(sale_items) - y_position = cursor - move_down 5 + y_position = cursor + move_down 5 + sub_total = 0.0 + sale_items.each do |item| + + sub_total += item.qty*item.unit_price + qty = item.qty + total_price = item.qty*item.unit_price + price = item.unit_price + product_name = item.product_name + + + y_position = cursor + + 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 + + } + 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 + text "Sub Total", :size => self.item_font_size,:align => :left + end + bounding_box([self.price_width,y_position], :width =>self.price_width) do + text "#{sub_total}" , :size => self.item_font_size,:align => :right + end + end + + def all_total(sale_data) + + move_down 5 + y_position =cursor + + bounding_box([0,y_position], :width =>self.price_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 + text "( " +"#{sale_data.total_discount}" +" )" , :size => self.item_font_size,:align => :right + end + + move_down 5 + y_position =cursor + + bounding_box([0,y_position], :width =>self.price_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 + 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 + text "Grand Total", :size => self.item_font_size,:align => :left + end + bounding_box([self.price_width,y_position], :width =>self.price_width) do + text "#{sale_data.grand_total}" , :size => self.item_font_size,:align => :right + end + move_down 5 + # stroke_horizontal_rule + end end diff --git a/app/views/api/bookings/show.json.jbuilder b/app/views/api/bookings/show.json.jbuilder index c4edb79f..cbd1575a 100644 --- a/app/views/api/bookings/show.json.jbuilder +++ b/app/views/api/bookings/show.json.jbuilder @@ -1,5 +1,5 @@ if (@booking) - json.id @booking.id + json.id @booking.booking_id json.status @booking.booking_status json.checkin_at @booking.checkin_at json.checkin_by @booking.checkin_by @@ -12,7 +12,8 @@ if (@booking) end @total_amount = 0.00 @total_tax = 0.00 - + + @booking_orders = BookingOrder.where("booking_id = #{@booking.booking_id}").all; if @booking.booking_orders order_items = [] @booking.booking_orders.each do |bo| diff --git a/app/views/crm/customers/_form.html.erb b/app/views/crm/customers/_form.html.erb index c5adac88..7c37a2fe 100644 --- a/app/views/crm/customers/_form.html.erb +++ b/app/views/crm/customers/_form.html.erb @@ -1,4 +1,5 @@ -<%= simple_form_for(@crm_customer) do |f| %> + +<%= simple_form_for([:crm,@crm_customer]) do |f| %> <%= f.error_notification %>
<%=order_table.total_price%>
-<%=order_room.total_price%>
-<%=order.total_price%>
-