diff --git a/app/forms/shop_form.rb b/app/forms/shop_form.rb new file mode 100644 index 00000000..19af84a5 --- /dev/null +++ b/app/forms/shop_form.rb @@ -0,0 +1,7 @@ +#Form object to use during the installation process - will handle creation of shop model into db after verification from the cloud +#provising service through license verification + +class ShopForm < ActiveModel + :attr_accessor :logo, :name, :address, :township, :city, :state, :country, :license, :base_currency, :password, :password_confirmation + +end diff --git a/app/models/booking.rb b/app/models/booking.rb index c6a6452e..c34ecf42 100644 --- a/app/models/booking.rb +++ b/app/models/booking.rb @@ -1,5 +1,6 @@ class Booking < ApplicationRecord - + #primary key - need to be unique + belongs_to :dining_facility, :optional => true belongs_to :sale, :optional => true has_many :booking_orders diff --git a/app/models/booking_order.rb b/app/models/booking_order.rb index c0883967..c9f748f0 100644 --- a/app/models/booking_order.rb +++ b/app/models/booking_order.rb @@ -1,4 +1,6 @@ class BookingOrder < ApplicationRecord + #primary key - need to be unique + belongs_to :booking belongs_to :order end diff --git a/app/models/order.rb b/app/models/order.rb index 4bbe4a28..cf65a047 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -1,4 +1,6 @@ class Order < ApplicationRecord + #primary key - need to be unique + before_create :set_order_date belongs_to :customer diff --git a/app/models/order_item.rb b/app/models/order_item.rb index f839ad99..6e06404c 100644 --- a/app/models/order_item.rb +++ b/app/models/order_item.rb @@ -1,4 +1,6 @@ class OrderItem < ApplicationRecord + #primary key - need to be unique + #Associations belongs_to :order, autosave: true diff --git a/app/models/sale.rb b/app/models/sale.rb index 37819c9b..744baafa 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -1,3 +1,5 @@ +#primary key - need to be unique generated for multiple shops + class Sale < ApplicationRecord #before_create :generate_receipt_no belongs_to :cashier, :optional => true diff --git a/app/models/sale_audit.rb b/app/models/sale_audit.rb index 15fee460..cce6982d 100644 --- a/app/models/sale_audit.rb +++ b/app/models/sale_audit.rb @@ -1,4 +1,6 @@ class SaleAudit < ApplicationRecord +#primary key - need to be unique generated for multiple shops + belongs_to :sale def record_audit_void(sale_id, void_by, approved_by, reason) diff --git a/app/models/sale_item.rb b/app/models/sale_item.rb index 82b20237..c92ed48f 100644 --- a/app/models/sale_item.rb +++ b/app/models/sale_item.rb @@ -1,4 +1,6 @@ class SaleItem < ApplicationRecord +#primary key - need to be unique generated for multiple shops + belongs_to :sale #compute items - discount, tax, price_change diff --git a/app/models/sale_order.rb b/app/models/sale_order.rb index 7a27f5a3..23fd39bd 100644 --- a/app/models/sale_order.rb +++ b/app/models/sale_order.rb @@ -1,4 +1,6 @@ class SaleOrder < ApplicationRecord +#primary key - need to be unique generated for multiple shops + belongs_to :sale belongs_to :order end diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 71793f4c..2f7b72ea 100644 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -1,4 +1,6 @@ class SalePayment < ApplicationRecord +#primary key - need to be unique generated for multiple shops + belongs_to :sale :attr_accessor :received_amount, :card_payment_reference, :voucher_no, :giftcard_no, :customer_id, :external_payment_status diff --git a/app/models/sale_tax.rb b/app/models/sale_tax.rb index cb3fae0b..6e0a2d47 100644 --- a/app/models/sale_tax.rb +++ b/app/models/sale_tax.rb @@ -1,3 +1,5 @@ class SaleTax < ApplicationRecord +#primary key - need to be unique generated for multiple shops + belongs_to :sale end diff --git a/app/models/seed_generator.rb b/app/models/seed_generator.rb index 573e0ff6..4351e74b 100644 --- a/app/models/seed_generator.rb +++ b/app/models/seed_generator.rb @@ -1,4 +1,23 @@ class SeedGenerator < ApplicationRecord + def self.generate_id(model, prefix) + seed = SeedGenerator.find_by_model(model) + new_receipt_no = 0 + if (seed.nil?) + seed = SeedGenerator.new() + seed.model = model + new_receipt_no = seed.next + seed.save + + else + current_no = seed.next + seed.next = seed.next + seed.increase_by + seed.current = current_no + seed.save + end + + return prefix + "-" + seed.current.to_s + end + def self.new_receipt_no seed = SeedGenerator.find_by_model("sale") new_receipt_no = 0 diff --git a/app/models/shop.rb b/app/models/shop.rb new file mode 100644 index 00000000..1cf1119c --- /dev/null +++ b/app/models/shop.rb @@ -0,0 +1,2 @@ +class Shop < ApplicationRecord +end diff --git a/db/migrate/20170403163734_create_sale_payments.rb b/db/migrate/20170403163734_create_sale_payments.rb index dd440036..3da5cb17 100644 --- a/db/migrate/20170403163734_create_sale_payments.rb +++ b/db/migrate/20170403163734_create_sale_payments.rb @@ -7,7 +7,7 @@ class CreateSalePayments < ActiveRecord::Migration[5.0] t.decimal :outstanding_amount, :precision => 10, :scale => 2, :null => false, :default => 0.00 t.string :payment_reference t.string :payment_status, :null => false, :default => "new" - + t.timestamps end end diff --git a/db/migrate/20170408105938_create_seed_generators.rb b/db/migrate/20170408105938_create_seed_generators.rb index 6ccf669f..eb58749a 100644 --- a/db/migrate/20170408105938_create_seed_generators.rb +++ b/db/migrate/20170408105938_create_seed_generators.rb @@ -5,7 +5,6 @@ class CreateSeedGenerators < ActiveRecord::Migration[5.0] t.integer :increase_by, :null => false, :default => 1 t.bigint :current, :null => false ,:default => 1 t.bigint :next, :null => false, :default => 2 - t.timestamps end end diff --git a/db/migrate/20170530072247_create_shops.rb b/db/migrate/20170530072247_create_shops.rb new file mode 100644 index 00000000..25de6c6a --- /dev/null +++ b/db/migrate/20170530072247_create_shops.rb @@ -0,0 +1,25 @@ +class CreateShops < ActiveRecord::Migration[5.1] + def change + create_table :shops do |t| + t.string :logo + t.string :name, :null => false + t.string :address, :null => false + t.string :township, :null => false + t.string :city, :null => false + t.string :state, :null => false + t.string :country, :null => false + t.string :phone_no, :null => false + t.string :reserviation_no, :null => false + t.string :license, :null => false + t.datetime :activated_at, :null => false + t.text :license_data, :null => false + t.string :base_currency, :null => false, :limit => 3 + t.string :cloud_url + t.string :cloud_token + t.string :owner_token + t.string :id_prefix, :null => false, :limit => 3 + + t.timestamps + end + end +end diff --git a/spec/models/shop_spec.rb b/spec/models/shop_spec.rb new file mode 100644 index 00000000..9fd43ff8 --- /dev/null +++ b/spec/models/shop_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Shop, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end