From 869c574107fddb3f2a123de8d470613772936d7d Mon Sep 17 00:00:00 2001 From: Yan Date: Sun, 4 Jun 2017 11:34:59 +0630 Subject: [PATCH 1/7] comment pg in gem --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index ac3052b5..3d079c20 100644 --- a/Gemfile +++ b/Gemfile @@ -12,7 +12,7 @@ gem 'rails', '~> 5.1.0' gem 'mysql2', '>= 0.3.18', '< 0.5' #Use PosgreSQL -gem 'pg' +# gem 'pg' # redis server for cable # gem 'redis', '~> 3.0' From 8d4086d5e95fcfc9df7f61f9a69d97368ce57d57 Mon Sep 17 00:00:00 2001 From: Yan Date: Sun, 4 Jun 2017 18:25:09 +0630 Subject: [PATCH 2/7] oqs printing --- app/assets/javascripts/OQS.js | 10 ++++ app/controllers/oqs/print_controller.rb | 15 ++++++ app/models/printer/order_queue_printer.rb | 16 +++--- app/pdf/order_item_pdf.rb | 50 +++++++++++++++++-- app/pdf/order_summary_pdf.rb | 61 ++++++++++++++++++++++- app/views/oqs/home/index.html.erb | 2 +- config/routes.rb | 2 + 7 files changed, 141 insertions(+), 15 deletions(-) diff --git a/app/assets/javascripts/OQS.js b/app/assets/javascripts/OQS.js index 80a09b47..7df365ec 100644 --- a/app/assets/javascripts/OQS.js +++ b/app/assets/javascripts/OQS.js @@ -80,4 +80,14 @@ $(document).ready(function(){ success: function(data){ } }); }); + + $('#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 }; + $.ajax({ + type: 'GET', + url: '/oqs/print/print_order_summary/'+assigned_item_id, + success: function(data){ } + }); + }); }); diff --git a/app/controllers/oqs/print_controller.rb b/app/controllers/oqs/print_controller.rb index 368a513d..e0b729c3 100644 --- a/app/controllers/oqs/print_controller.rb +++ b/app/controllers/oqs/print_controller.rb @@ -13,4 +13,19 @@ class Oqs::PrintController < ApplicationController assigned_item.print_status=true assigned_item.save end + + def print_order_summary + unique_code="OrderSummaryPdf" + assigned_item_id=params[:id] + assigned_order_item=AssignedOrderItem.select("order_id").where('id='+assigned_item_id) + + 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) + + # update print status when complete click + assigned_item=AssignedOrderItem.find(assigned_item_id) + assigned_item.print_status=true + assigned_item.save + end end diff --git a/app/models/printer/order_queue_printer.rb b/app/models/printer/order_queue_printer.rb index 6a8a4b78..2440f176 100644 --- a/app/models/printer/order_queue_printer.rb +++ b/app/models/printer/order_queue_printer.rb @@ -10,12 +10,12 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker self.print("tmp/receipt.pdf") end - def print_order_summary(printer_settings,booking_id) + def print_order_summary(printer_settings,order_id) #Use CUPS service #Generate PDF #Print - order=print_query('booking',booking_id) - filename = "tmp/order_summary_#{booking_id}" + ".pdf" + order=print_query('order_summary',order_id) + filename = "tmp/order_summary_#{order_id}" + ".pdf" pdf = OrderSummaryPdf.new(order,printer_settings) pdf.render_file filename @@ -25,7 +25,7 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker # Query for OQS with status def print_query(type, code) if type == 'order_item' - OrderItem.select("order_items.item_code, order_items.item_name,order_items.item_order_by as order_by, order_items.created_at as order_at, cus.name as customer, df.name as dining") + 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.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.id = bo.booking_id @@ -34,12 +34,14 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker .where("order_items.item_code=" + code) .group("order_items.item_code") else - OrderItem.select("order_items.item_code, order_items.item_name, df.name as dining") + 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.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.id = bo.booking_id - left join dining_facilities AS df ON df.id = b.dining_facility_id") - .where("booking.id=" + code) + left join dining_facilities AS df ON df.id = b.dining_facility_id + left join customers as cus ON cus.id = orders.customer_id") + .where("orders.id=" + code.to_s) + .group("order_items.item_code") end end diff --git a/app/pdf/order_item_pdf.rb b/app/pdf/order_item_pdf.rb index 356327b4..3044c578 100644 --- a/app/pdf/order_item_pdf.rb +++ b/app/pdf/order_item_pdf.rb @@ -11,21 +11,61 @@ class OrderItemPdf < Prawn::Document stroke_horizontal_rule move_down 5 - cashier_info(order_item.order_by,order_item.order_at, order_item.customer) + #order_info + order_info(order_item.order_by,order_item.order_at, order_item.customer) + # order items + order_items(order_item) end - def cashier_info(order_by, order_at, customer) - move_down 5 + # Write Order Information to PDF + def order_info(order_by, order_at, customer) y_position = cursor - bounding_box([0,y_position], :width =>200, :height => 20) do - text "OrderBy:#{order_by} Customer:#{customer} Date:#{order_at.strftime("%Y %m %d")}", :size => 7,:align => :left + 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 end stroke_horizontal_rule + move_down 20 + end + + # Write Order items to PDF + def order_items(order_item) + y_position = cursor + + bounding_box([0,y_position], :width => 180, :height => 15) do + text "Item", :size => 7,:align => :left + end + + bounding_box([160,y_position], :width => 20, :height => 15) do + text "Qty", :size => 7,:align => :right + end + + stroke_horizontal_rule move_down 5 + + #Add Order Item + add_order_items(order_item) + end + + # Add order items under order info + def add_order_items(order_item) + y_position = cursor + + move_down 5 + + bounding_box([0,y_position], :width => 180, :height => 20) do + text "#{order_item.item_name}", :size => 7,:align => :left + end + + bounding_box([160,y_position], :width => 20, :height => 20) do + text "#{order_item.qty}", :size => 7,:align => :right + end + + move_down 5 + end end diff --git a/app/pdf/order_summary_pdf.rb b/app/pdf/order_summary_pdf.rb index 8b79b40e..8a7a1ad9 100644 --- a/app/pdf/order_summary_pdf.rb +++ b/app/pdf/order_summary_pdf.rb @@ -7,11 +7,68 @@ class OrderSummaryPdf < Prawn::Document # font "public/fonts/Zawgyi-One.ttf" # font "public/fonts/padauk.ttf" - font_size 9 - text "#{"table_name"}", :size => 15 + text "#{order[0].dining}", :size => 15 stroke_horizontal_rule move_down 5 + #order_info + order_info(order[0].order_by,order[0].order_at, order[0].customer) + + # order items + order_items(order) + + end + + # Write Order Information to PDF + def order_info(order_by, order_at, customer) + 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 + end + + stroke_horizontal_rule + + move_down 20 + end + + # Write Order items to PDF + def order_items(order_item) + y_position = cursor + + bounding_box([0,y_position], :width => 180, :height => 15) do + text "Item", :size => 7,:align => :left + end + + bounding_box([160,y_position], :width => 20, :height => 15) do + text "Qty", :size => 7,:align => :right + end + + stroke_horizontal_rule + move_down 5 + + #Add Order Item + add_order_items(order_item) + end + + # Add order items under order info + def add_order_items(order_item) + y_position = cursor + + 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([160,y_position], :width => 20, :height => 20) do + text "#{odi.qty}", :size => 7,:align => :right + end + end + + move_down 5 + end end diff --git a/app/views/oqs/home/index.html.erb b/app/views/oqs/home/index.html.erb index 982264ab..88c606da 100644 --- a/app/views/oqs/home/index.html.erb +++ b/app/views/oqs/home/index.html.erb @@ -193,7 +193,7 @@
+
diff --git a/config/routes.rb b/config/routes.rb index caa5cc2f..81c27917 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -99,7 +99,9 @@ Rails.application.routes.draw do post 'update_delivery', to: "home#update_delivery_status" + # Pass assigned_order_item_id get 'print/print/:id', to: "print#print" + get 'print/print_order_summary/:id', to: "print#print_order_summary" #dashboard # end From 42ba2d9ae4a850a1ff5f0b94d6955459260c1877 Mon Sep 17 00:00:00 2001 From: PhyoTheingi Date: Mon, 5 Jun 2017 10:00:32 +0630 Subject: [PATCH 3/7] comment the conflict in creating menu item instances with account and item attribute validate --- app/controllers/settings/menu_item_instances_controller.rb | 2 +- app/models/menu_item.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/settings/menu_item_instances_controller.rb b/app/controllers/settings/menu_item_instances_controller.rb index 6bd00638..f9c20a2d 100644 --- a/app/controllers/settings/menu_item_instances_controller.rb +++ b/app/controllers/settings/menu_item_instances_controller.rb @@ -41,7 +41,7 @@ class Settings::MenuItemInstancesController < ApplicationController category = MenuCategory.find(catID.menu_category_id) respond_to do |format| if @settings_menu_item_instances.save - @settings_menu_item_instances.item_attributes = params[:menu_item_instance][:item_attributes] + @settings_menu_item_instances.item_attributes = params[:menu_item_instance][:item_attributes].reject(&:blank?) @settings_menu_item_instances.save format.html { redirect_to settings_menu_category_simple_menu_item_path(category,catID), notice: 'Menu item instance was successfully created.' } format.json { render :show, status: :created, location: @settings_menu_item_instances } diff --git a/app/models/menu_item.rb b/app/models/menu_item.rb index 2a4e86be..7d69ca3e 100644 --- a/app/models/menu_item.rb +++ b/app/models/menu_item.rb @@ -1,5 +1,5 @@ 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 From c4e6f917f4c301f948547089cde6711a212da4a2 Mon Sep 17 00:00:00 2001 From: Yan Date: Mon, 5 Jun 2017 10:22:12 +0630 Subject: [PATCH 4/7] modified in order model --- app/models/order.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/models/order.rb b/app/models/order.rb index 9133e907..ecdfd51a 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -215,7 +215,6 @@ class Order < ApplicationRecord left join dining_facilities on dining_facilities.id = bookings.dining_facility_id left join order_items on order_items.order_id = orders.id") .where("dining_facilities.type=? and orders.order_type=? and dining_facilities.is_active=?",DiningFacility::TABLE_TYPE,"dine_in",true) - .group("orders.id") end @@ -240,7 +239,6 @@ class Order < ApplicationRecord left join bookings on bookings.id = booking_orders.id left join dining_facilities on dining_facilities.id = bookings.dining_facility_id left join order_items on order_items.order_id = orders.id") - .where("dining_facilities.is_active=? and orders.date between ? and ?",true,from,to) .group("orders.id") end From 1dbe133b79667cdbdafdae42bb74e98f0bd640ae Mon Sep 17 00:00:00 2001 From: Yan Date: Mon, 5 Jun 2017 13:28:40 +0630 Subject: [PATCH 5/7] update for db changed --- app/controllers/oqs/home_controller.rb | 10 +++++----- app/controllers/oqs/print_controller.rb | 4 ++-- app/models/printer/order_queue_printer.rb | 18 +++++++++--------- app/models/seed_generator.rb | 2 +- app/views/oqs/home/index.html.erb | 6 +++--- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/app/controllers/oqs/home_controller.rb b/app/controllers/oqs/home_controller.rb index 1292a5e6..49c496a8 100644 --- a/app/controllers/oqs/home_controller.rb +++ b/app/controllers/oqs/home_controller.rb @@ -35,15 +35,15 @@ class Oqs::HomeController < BaseOqsController # Query for OQS with status def queue_items_query(status) - AssignedOrderItem.select("assigned_order_items.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") + 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("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.id = assigned_order_items.order_id + left join order_queue_stations as oqs ON oqs.order_queue_stations_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.id = od.customer_id") + left join customers as cus ON cus.customer_id = od.customer_id") .where("assigned_order_items.delivery_status = #{status}") - .group("assigned_order_items.id") + .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 e0b729c3..1b48fae6 100644 --- a/app/controllers/oqs/print_controller.rb +++ b/app/controllers/oqs/print_controller.rb @@ -2,7 +2,7 @@ class Oqs::PrintController < ApplicationController def print unique_code="OrderItemPdf" assigned_item_id=params[:id] - assigned_order_item=AssignedOrderItem.select("order_id, item_code").where('id='+assigned_item_id) + assigned_order_item=AssignedOrderItem.select("order_id, item_code").where('assigned_order_item_id='+assigned_item_id) print_settings=PrintSetting.find_by_unique_code(unique_code) order_queue_printer= Printer::OrderQueuePrinter.new(print_settings) @@ -17,7 +17,7 @@ class Oqs::PrintController < ApplicationController def print_order_summary unique_code="OrderSummaryPdf" assigned_item_id=params[:id] - assigned_order_item=AssignedOrderItem.select("order_id").where('id='+assigned_item_id) + assigned_order_item=AssignedOrderItem.select("order_id").where('assigned_order_item_id='+assigned_item_id) print_settings=PrintSetting.find_by_unique_code(unique_code) order_queue_printer= Printer::OrderQueuePrinter.new(print_settings) diff --git a/app/models/printer/order_queue_printer.rb b/app/models/printer/order_queue_printer.rb index 2440f176..3428bb98 100644 --- a/app/models/printer/order_queue_printer.rb +++ b/app/models/printer/order_queue_printer.rb @@ -26,21 +26,21 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker def print_query(type, code) 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.id = order_items.order_id + .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.id = bo.booking_id - left join dining_facilities AS df ON df.id = b.dining_facility_id - left join customers as cus ON cus.id = orders.customer_id") + left join bookings AS b ON b.booking_id = bo.booking_id + left join dining_facilities AS df ON df.dining_facility_id = b.dining_facility_id + left join customers as cus ON cus.customer_id = orders.customer_id") .where("order_items.item_code=" + code) .group("order_items.item_code") else 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.id = order_items.order_id + .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.id = bo.booking_id - left join dining_facilities AS df ON df.id = b.dining_facility_id - left join customers as cus ON cus.id = orders.customer_id") - .where("orders.id=" + code.to_s) + left join bookings AS b ON b.booking_id = bo.booking_id + left join dining_facilities AS df ON df.dining_facility_id = b.dining_facility_id + left join customers as cus ON cus.customer_id = orders.customer_id") + .where("orders.order_id=" + code.to_s) .group("order_items.item_code") end diff --git a/app/models/seed_generator.rb b/app/models/seed_generator.rb index 02a9fb64..ff025b6f 100644 --- a/app/models/seed_generator.rb +++ b/app/models/seed_generator.rb @@ -14,7 +14,7 @@ class SeedGenerator < ApplicationRecord seed.current = current_no seed.save end - padding_len = 16 - prefix.len + padding_len = 16 - prefix.length return prefix +"-"+ seed.current.to_s.to_s.rjust((16-prefix.length)+1,'0') end diff --git a/app/views/oqs/home/index.html.erb b/app/views/oqs/home/index.html.erb index 88c606da..47d80f38 100644 --- a/app/views/oqs/home/index.html.erb +++ b/app/views/oqs/home/index.html.erb @@ -61,7 +61,7 @@

- + - + <% From b332d6a52508e76e1c9868fa2af00dc4e8708cdb Mon Sep 17 00:00:00 2001 From: Yan Date: Mon, 5 Jun 2017 13:37:07 +0630 Subject: [PATCH 6/7] postfix length 16 to 12 for limit 16 --- app/models/seed_generator.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/seed_generator.rb b/app/models/seed_generator.rb index ff025b6f..da1e6284 100644 --- a/app/models/seed_generator.rb +++ b/app/models/seed_generator.rb @@ -14,9 +14,9 @@ class SeedGenerator < ApplicationRecord seed.current = current_no seed.save end - padding_len = 16 - prefix.length + padding_len = 12 - prefix.length - return prefix +"-"+ seed.current.to_s.to_s.rjust((16-prefix.length)+1,'0') + return prefix +"-"+ seed.current.to_s.to_s.rjust((12-prefix.length)+1,'0') end def self.new_receipt_no From f004db9b193bb4868ea57b9b1b0e5b87fa1c5a1b Mon Sep 17 00:00:00 2001 From: Yan Date: Mon, 5 Jun 2017 15:06:34 +0630 Subject: [PATCH 7/7] updated migration code --- app/controllers/api/orders_controller.rb | 2 +- app/controllers/oqs/home_controller.rb | 2 +- app/models/order.rb | 2 +- app/models/order_item.rb | 2 +- app/models/seed_generator.rb | 4 ++-- db/migrate/20170403135121_create_customers.rb | 4 ++-- db/migrate/20170403135934_create_orders.rb | 4 ++-- db/migrate/20170403140820_create_order_items.rb | 4 ++-- db/migrate/20170403160742_create_sales.rb | 4 ++-- db/migrate/20170403161857_create_sale_items.rb | 4 ++-- db/migrate/20170403163219_create_sale_taxes.rb | 4 ++-- db/migrate/20170403163734_create_sale_payments.rb | 4 ++-- db/migrate/20170403174029_create_sale_orders.rb | 8 ++++---- db/migrate/20170403174111_create_sale_audits.rb | 4 ++-- db/migrate/20170404034234_create_bookings.rb | 4 ++-- db/migrate/20170414110918_create_booking_orders.rb | 10 +++++----- 16 files changed, 33 insertions(+), 33 deletions(-) diff --git a/app/controllers/api/orders_controller.rb b/app/controllers/api/orders_controller.rb index 443a754b..df9b1542 100644 --- a/app/controllers/api/orders_controller.rb +++ b/app/controllers/api/orders_controller.rb @@ -28,7 +28,7 @@ class Api::OrdersController < Api::ApiController @order = Order.new @order.source = params[:order_source] @order.order_type = params[:order_type] - @order.customer_id = params[:customer_id] + @order.customer_id = params[:customer_id] == ""? "CUS-000000000001" : params[:customer_id] # for no customer id from mobile @order.items = params[:order_items] @order.guest = params[:guest_info] @order.table_id = params[:table_id] diff --git a/app/controllers/oqs/home_controller.rb b/app/controllers/oqs/home_controller.rb index 49c496a8..0c680624 100644 --- a/app/controllers/oqs/home_controller.rb +++ b/app/controllers/oqs/home_controller.rb @@ -38,7 +38,7 @@ class Oqs::HomeController < BaseOqsController 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("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.order_queue_stations_id = assigned_order_items.order_queue_station_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") diff --git a/app/models/order.rb b/app/models/order.rb index ecdfd51a..3b54315c 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -40,7 +40,7 @@ class Order < ApplicationRecord self.adding_line_items #Add Order Table and Room relation afrer order creation - BookingOrder.create({:booking_id => booking.id, :order => self}) + BookingOrder.create({:booking_id => booking.booking_id, :order => self}) #Send order to queue one it done! process_order_queue diff --git a/app/models/order_item.rb b/app/models/order_item.rb index 1cd83dc1..92992f90 100644 --- a/app/models/order_item.rb +++ b/app/models/order_item.rb @@ -46,6 +46,6 @@ class OrderItem < ApplicationRecord private def generate_custom_id - self.order_item_id = SeedGenerator.generate_id(self.class.name, "ODI") + self.order_items_id = SeedGenerator.generate_id(self.class.name, "ODI") end end diff --git a/app/models/seed_generator.rb b/app/models/seed_generator.rb index da1e6284..d55af84d 100644 --- a/app/models/seed_generator.rb +++ b/app/models/seed_generator.rb @@ -14,9 +14,9 @@ class SeedGenerator < ApplicationRecord seed.current = current_no seed.save end - padding_len = 12 - prefix.length + padding_len = 15 - prefix.length - return prefix +"-"+ seed.current.to_s.to_s.rjust((12-prefix.length)+1,'0') + return prefix +"-"+ seed.current.to_s.to_s.rjust((14-prefix.length)+1,'0') end def self.new_receipt_no diff --git a/db/migrate/20170403135121_create_customers.rb b/db/migrate/20170403135121_create_customers.rb index 17c104cd..8094f035 100644 --- a/db/migrate/20170403135121_create_customers.rb +++ b/db/migrate/20170403135121_create_customers.rb @@ -1,7 +1,7 @@ class CreateCustomers < ActiveRecord::Migration[5.0] def change - create_table :customers, :id => false, :primary_key => :customer_id do |t| - t.string :customer_id, :limit => 16, :null => false, :index => true, :unique => true #custom foreign_key to prevent conflict during sync + create_table :customers, :id => false do |t| + t.string :customer_id, :limit => 16, :primary_key => true #custom foreign_key to prevent conflict during sync t.string :name, :null => false t.string :company t.string :contact_no diff --git a/db/migrate/20170403135934_create_orders.rb b/db/migrate/20170403135934_create_orders.rb index 7fe7eb12..a80e2760 100644 --- a/db/migrate/20170403135934_create_orders.rb +++ b/db/migrate/20170403135934_create_orders.rb @@ -1,7 +1,7 @@ class CreateOrders < ActiveRecord::Migration[5.0] def change - create_table :orders, :id => false, :primary_key => :order_id do |t| - t.string :order_id, :limit => 16, :null => false, :index => true, :unique => true #custom foreign_key to prevent conflict during sync + create_table :orders, :id => false do |t| + t.string :order_id, :limit => 16, :primary_key => true #custom foreign_key to prevent conflict during sync t.datetime :date, :null => false t.string :source, :null => false, :default => "emenu" t.string :order_type, :null => false, :default => "dine-in" diff --git a/db/migrate/20170403140820_create_order_items.rb b/db/migrate/20170403140820_create_order_items.rb index 45a0f8fa..32760907 100644 --- a/db/migrate/20170403140820_create_order_items.rb +++ b/db/migrate/20170403140820_create_order_items.rb @@ -1,7 +1,7 @@ class CreateOrderItems < ActiveRecord::Migration[5.0] def change - create_table :order_items, :id => false, :primary_key => :order_items_id do |t| - t.string :order_items_id, :limit => 16, :null => false, :index => true, :unique => true #custom primary key - to ensure consistence for cloud syncing + create_table :order_items, :id => false do |t| + t.string :order_items_id, :limit => 16, :primary_key => true #custom primary key - to ensure consistence for cloud syncing t.string :order_id, foreign_key: true, :null => false, :limit => 16 t.string :order_item_status, :null => false, :default => "new" t.string :item_order_by #person who order this diff --git a/db/migrate/20170403160742_create_sales.rb b/db/migrate/20170403160742_create_sales.rb index 8d653421..c2bb718a 100644 --- a/db/migrate/20170403160742_create_sales.rb +++ b/db/migrate/20170403160742_create_sales.rb @@ -1,7 +1,7 @@ class CreateSales < ActiveRecord::Migration[5.0] def change - create_table :sales, :id => false, :primary_key => :sale_id do |t| - t.string :sale_id, :limit => 16, :null => false, :index => true, :unique => true #custom primary key - to ensure consistence for cloud syncing + create_table :sales, :id => false do |t| + t.string :sale_id, :limit => 16, :primary_key => true #custom primary key - to ensure consistence for cloud syncing t.integer :cashier_id, :index => true t.string :cashier_name diff --git a/db/migrate/20170403161857_create_sale_items.rb b/db/migrate/20170403161857_create_sale_items.rb index 7f58c5bb..aaf1dac3 100644 --- a/db/migrate/20170403161857_create_sale_items.rb +++ b/db/migrate/20170403161857_create_sale_items.rb @@ -1,7 +1,7 @@ class CreateSaleItems < ActiveRecord::Migration[5.0] def change - create_table :sale_items, :id => false, :primary_key => :sale_item_id do |t| - t.string :sale_item_id, :limit => 16, :null => false, :index => true, :unique => true #custom primary key - to ensure consistence for cloud syncing + create_table :sale_items, :id => false do |t| + t.string :sale_item_id, :limit => 16, :primary_key => true#custom primary key - to ensure consistence for cloud syncing t.string :sale_id, foreign_key: true, :limit => 16 t.string :product_code, :null => false t.string :product_name, :null => false diff --git a/db/migrate/20170403163219_create_sale_taxes.rb b/db/migrate/20170403163219_create_sale_taxes.rb index d12ab367..3d28381a 100644 --- a/db/migrate/20170403163219_create_sale_taxes.rb +++ b/db/migrate/20170403163219_create_sale_taxes.rb @@ -1,7 +1,7 @@ class CreateSaleTaxes < ActiveRecord::Migration[5.0] def change - create_table :sale_taxes, :id => false, :primary_key => :sale_tax_id do |t| - t.string :sale_tax_id, :limit => 16, :null => false, :index => true, :unique => true #custom primary key - to ensure consistence for cloud syncing + create_table :sale_taxes, :id => false do |t| + t.string :sale_tax_id, :limit => 16, :primary_key => true #custom primary key - to ensure consistence for cloud syncing t.string :sale_id, foreign_key: true, :limit => 16 t.string :tax_name, :null => false diff --git a/db/migrate/20170403163734_create_sale_payments.rb b/db/migrate/20170403163734_create_sale_payments.rb index fc625e44..3badca93 100644 --- a/db/migrate/20170403163734_create_sale_payments.rb +++ b/db/migrate/20170403163734_create_sale_payments.rb @@ -1,7 +1,7 @@ class CreateSalePayments < ActiveRecord::Migration[5.0] def change - create_table :sale_payments, :id => false, :primary_key => :sale_payment_id do |t| - t.string :sale_payment_id, :limit => 16, :null => false, :index => true, :unique => true #custom primary key - to ensure consistence for cloud syncing + create_table :sale_payments, :id => false do |t| + t.string :sale_payment_id, :limit => 16, :primary_key => true #custom primary key - to ensure consistence for cloud syncing t.string :sale_id, foreign_key: true, :limit => 16 t.string :payment_method, :null => false, :default => "cash" diff --git a/db/migrate/20170403174029_create_sale_orders.rb b/db/migrate/20170403174029_create_sale_orders.rb index 420e4b13..3da13e60 100644 --- a/db/migrate/20170403174029_create_sale_orders.rb +++ b/db/migrate/20170403174029_create_sale_orders.rb @@ -1,10 +1,10 @@ class CreateSaleOrders < ActiveRecord::Migration[5.0] def change - create_table :sale_orders, :id => false, :primary_key => :sale_order_id do |t| - t.string :sale_order_id, :limit => 16, :null => false, :index => true, :unique => true #custom primary key - to ensure consistence for cloud syncing + create_table :sale_orders, :id => false do |t| + t.primary_key :sale_order_id #custom primary key - to ensure consistence for cloud syncing - t.string :sale, foreign_key: true,:limit => 16 - t.string :order, foreign_key: true, :limit => 16 + t.string :sale_id, foreign_key: true,:limit => 16 + t.string :order_id, foreign_key: true, :limit => 16 t.timestamps end diff --git a/db/migrate/20170403174111_create_sale_audits.rb b/db/migrate/20170403174111_create_sale_audits.rb index 38af14ab..ae6ba3f4 100644 --- a/db/migrate/20170403174111_create_sale_audits.rb +++ b/db/migrate/20170403174111_create_sale_audits.rb @@ -1,7 +1,7 @@ class CreateSaleAudits < ActiveRecord::Migration[5.0] def change - create_table :sale_audits, :id => false, :primary_key => :sale_audit_id do |t| - t.string :sale_audit_id, :limit => 16, :null => false, :index => true, :unique => true #custom primary key - to ensure consistence for cloud syncing + create_table :sale_audits, :id => false do |t| + t.string :sale_audit_id, :limit => 16, :primary_key => true #custom primary key - to ensure consistence for cloud syncing t.string :sale_id, foreign_key: true, :limit => 16 t.string :action, :null => false diff --git a/db/migrate/20170404034234_create_bookings.rb b/db/migrate/20170404034234_create_bookings.rb index a9e7c21f..f41e8fb4 100644 --- a/db/migrate/20170404034234_create_bookings.rb +++ b/db/migrate/20170404034234_create_bookings.rb @@ -1,7 +1,7 @@ class CreateBookings < ActiveRecord::Migration[5.0] def change - create_table :bookings, :id => false, :primary_key => :booking_id do |t| - t.string :booking_id, :limit => 16, :null => false, :index => true, :unique => true #custom primary key - to ensure consistence for cloud syncing + create_table :bookings, :id => false do |t| + t.string :booking_id, :limit => 16, :primary_key => true #custom primary key - to ensure consistence for cloud syncing t.references :dining_facility, foreign_key: true t.string :type, :null => false, :default => "Table" diff --git a/db/migrate/20170414110918_create_booking_orders.rb b/db/migrate/20170414110918_create_booking_orders.rb index 50277de9..e9bf7cc0 100644 --- a/db/migrate/20170414110918_create_booking_orders.rb +++ b/db/migrate/20170414110918_create_booking_orders.rb @@ -1,10 +1,10 @@ class CreateBookingOrders < ActiveRecord::Migration[5.0] def change - create_table :booking_orders, :id => false, :primary_key => :booking_order_id do |t| - t.string :booking_order_id, :limit => 16, :null => false, :index => true, :unique => true #custom primary key - to ensure consistence for cloud syncing - - t.string :booking, foreign_key: true, :limit => 16 - t.string :order, foreign_key: true, :limit => 16 + create_table :booking_orders, :id => false do |t| + #t.string :booking_order_id, :limit => 16, :null => false, :index => true, :unique => true #custom primary key - to ensure consistence for cloud syncing + t.primary_key :booking_order_id + t.string :booking_id, foreign_key: true, :limit => 16 + t.string :order_id, foreign_key: true, :limit => 16 t.timestamps end