custom primary key for transaction

This commit is contained in:
Min Zeya Phyo
2017-06-04 16:27:14 +06:30
parent 394d2ed938
commit 4fc511d531
19 changed files with 88 additions and 55 deletions

View File

@@ -1,4 +1,6 @@
class AssignedOrderItem < ApplicationRecord class AssignedOrderItem < ApplicationRecord
before_create :generate_custom_id
belongs_to :order belongs_to :order
belongs_to :order_queue_station belongs_to :order_queue_station
@@ -11,4 +13,9 @@ class AssignedOrderItem < ApplicationRecord
assigned_order_item.delivery_status = false assigned_order_item.delivery_status = false
assigned_order_item.save assigned_order_item.save
end end
private
def generate_custom_id
self.assigned_order_item_id = SeedGenerator.generate_id(self.class.name, "AOI")
end
end end

View File

@@ -1,9 +1,14 @@
class Booking < ApplicationRecord class Booking < ApplicationRecord
before_create :generate_custom_id
#primary key - need to be unique #primary key - need to be unique
belongs_to :dining_facility, :optional => true belongs_to :dining_facility, :optional => true
belongs_to :sale, :optional => true belongs_to :sale, :optional => true
has_many :booking_orders has_many :booking_orders
has_many :orders, :through => :booking_orders
private
def generate_custom_id
self.booking_id = SeedGenerator.generate_id(self.class.name, "BKI")
end
end end

View File

@@ -1,4 +1,11 @@
class CashierLoginLog < ApplicationRecord class CashierLoginLog < ApplicationRecord
before_create :generate_custom_id
belongs_to :cashier_station belongs_to :cashier_station
belongs_to :employee belongs_to :employee
private
def generate_custom_id
self.cashier_login_log_id = SeedGenerator.generate_id(self.class.name, "CLO")
end
end end

View File

@@ -1,5 +0,0 @@
module Crm
def self.table_name_prefix
'crm_'
end
end

View File

@@ -1,4 +1,5 @@
class Customer < ApplicationRecord class Customer < ApplicationRecord
before_create :generate_custom_id
has_many :orders has_many :orders
has_many :sales has_many :sales
@@ -8,4 +9,9 @@ class Customer < ApplicationRecord
def lastest_invoices def lastest_invoices
sales.where(:customer_id => self.id).order("created_at desc").limit(5) sales.where(:customer_id => self.id).order("created_at desc").limit(5)
end end
private
def generate_custom_id
self.customer_id = SeedGenerator.generate_id(self.class.name, "CUS")
end
end end

View File

@@ -1,16 +0,0 @@
class LoginForm
include ActiveModel::Model
include ActiveModel::Validations
attr_accessor :emp_id, :password
validates_presence_of :emp_id, :password
def persisted?
false
end
def initialize(attributes={})
super
end
end

View File

@@ -1,6 +1,6 @@
class Order < ApplicationRecord class Order < ApplicationRecord
#primary key - need to be unique #primary key - need to be unique
before_create :generate_custom_id
before_create :set_order_date before_create :set_order_date
belongs_to :customer belongs_to :customer
@@ -18,7 +18,7 @@ class Order < ApplicationRecord
# option_values : [], # option_values : [],
# sub_order_items : [], # sub_order_items : [],
# } # }
def generate def generate
booking = nil booking = nil
@@ -182,14 +182,6 @@ class Order < ApplicationRecord
return new_items_list return new_items_list
end end
private
def validate_api_inputs
end
def set_order_date
self.date = Time.now.utc
end
#Update Items Count and Quantity changes whenever there is changes #Update Items Count and Quantity changes whenever there is changes
def update_products_and_quantity_count def update_products_and_quantity_count
@@ -249,4 +241,14 @@ class Order < ApplicationRecord
.where("dining_facilities.is_active=? and orders.date between ? and ?",true,from,to) .where("dining_facilities.is_active=? and orders.date between ? and ?",true,from,to)
.group("orders.id") .group("orders.id")
end end
private
def generate_custom_id
self.order_id = SeedGenerator.generate_id(self.class.name, "ODR")
end
def set_order_date
self.date = Time.now.utc
end
end end

View File

@@ -1,5 +1,6 @@
class OrderItem < ApplicationRecord class OrderItem < ApplicationRecord
#primary key - need to be unique #primary key - need to be unique
before_create :generate_custom_id
#Associations #Associations
belongs_to :order, autosave: true belongs_to :order, autosave: true
@@ -39,6 +40,11 @@ class OrderItem < ApplicationRecord
def self.get_order_items_details(order_id) 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") 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") .joins("left join orders on orders.id = order_items.order_id")
.where("order_items.order_id=?",order_id) .where("order_items.order_id=?",order_id)
end
private
def generate_custom_id
self.order_item_id = SeedGenerator.generate_id(self.class.name, "ODI")
end end
end end

View File

@@ -1,3 +1,4 @@
class RoomBooking < Booking class RoomBooking < Booking
has_many :orders
end end

View File

@@ -1,6 +1,6 @@
#primary key - need to be unique generated for multiple shops
class Sale < ApplicationRecord class Sale < ApplicationRecord
#primary key - need to be unique generated for multiple shops
#before_create :generate_receipt_no #before_create :generate_receipt_no
belongs_to :cashier, :optional => true belongs_to :cashier, :optional => true
belongs_to :customer, :optional => true belongs_to :customer, :optional => true
@@ -242,4 +242,8 @@ class Sale < ApplicationRecord
end end
end end
private
def generate_custom_id
self.sale_id = SeedGenerator.generate_id(self.class.name, "SAL")
end
end end

View File

@@ -1,6 +1,6 @@
class SaleAudit < ApplicationRecord class SaleAudit < ApplicationRecord
#primary key - need to be unique generated for multiple shops #primary key - need to be unique generated for multiple shops
belongs_to :sale belongs_to :sale
def record_audit_void(sale_id, void_by, approved_by, reason) def record_audit_void(sale_id, void_by, approved_by, reason)
@@ -50,4 +50,9 @@ class SaleAudit < ApplicationRecord
sale_audit.remark = remark sale_audit.remark = remark
sale_audit.save! sale_audit.save!
end end
private
def generate_custom_id
self.sale_audit_id = SeedGenerator.generate_id(self.class.name, "SAI")
end
end end

View File

@@ -1,9 +1,15 @@
class SaleItem < ApplicationRecord class SaleItem < ApplicationRecord
#primary key - need to be unique generated for multiple shops #primary key - need to be unique generated for multiple shops
before_create :generate_custom_id
belongs_to :sale belongs_to :sale
#compute items - discount, tax, price_change #compute items - discount, tax, price_change
def compute_item def compute_item
end end
private
def generate_custom_id
self.sale_item_id = SeedGenerator.generate_id(self.class.name, "SLI")
end
end end

View File

@@ -1,6 +1,12 @@
class SaleOrder < ApplicationRecord class SaleOrder < ApplicationRecord
#primary key - need to be unique generated for multiple shops #primary key - need to be unique generated for multiple shops
before_create :generate_custom_id
belongs_to :sale belongs_to :sale
belongs_to :order belongs_to :order
private
def generate_custom_id
self.sale_order_id = SeedGenerator.generate_id(self.class.name, "SOI")
end
end end

View File

@@ -1,5 +1,6 @@
class SalePayment < ApplicationRecord class SalePayment < ApplicationRecord
#primary key - need to be unique generated for multiple shops #primary key - need to be unique generated for multiple shops
before_create :generate_custom_id
belongs_to :sale belongs_to :sale
@@ -156,4 +157,8 @@ class SalePayment < ApplicationRecord
end end
private
def generate_custom_id
self.sale_payment_id = SeedGenerator.generate_id(self.class.name, "SPI")
end
end end

View File

@@ -1,5 +1,10 @@
class SaleTax < ApplicationRecord class SaleTax < ApplicationRecord
#primary key - need to be unique generated for multiple shops #primary key - need to be unique generated for multiple shops
before_create :generate_custom_id
belongs_to :sale belongs_to :sale
private
def generate_custom_id
self.sale_tax_id = SeedGenerator.generate_id(self.class.name, "STI")
end
end end

View File

@@ -14,8 +14,9 @@ class SeedGenerator < ApplicationRecord
seed.current = current_no seed.current = current_no
seed.save seed.save
end end
padding_len = 16 - prefix.len
return prefix + "-" + seed.current.to_s return prefix +"-"+ seed.current.to_s.to_s.rjust((16-prefix.length)+1,'0')
end end
def self.new_receipt_no def self.new_receipt_no

View File

@@ -1,2 +0,0 @@
class Test < ApplicationRecord
end

View File

@@ -1,5 +0,0 @@
module Transactions
def self.table_name_prefix
'transactions_'
end
end

View File

@@ -1,5 +0,0 @@
require 'rails_helper'
RSpec.describe Test, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end