From f004db9b193bb4868ea57b9b1b0e5b87fa1c5a1b Mon Sep 17 00:00:00 2001 From: Yan Date: Mon, 5 Jun 2017 15:06:34 +0630 Subject: [PATCH] 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