fixed conflictsale item order order item

This commit is contained in:
Aung Myo
2017-06-04 16:51:38 +06:30
61 changed files with 455 additions and 137 deletions

View File

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

View File

@@ -1,8 +1,14 @@
class Booking < ApplicationRecord
before_create :generate_custom_id
#primary key - need to be unique
belongs_to :dining_facility, :optional => true
belongs_to :sale, :optional => true
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

View File

@@ -1,4 +1,6 @@
class BookingOrder < ApplicationRecord
#primary key - need to be unique
belongs_to :booking
belongs_to :order
end

View File

@@ -1,4 +1,11 @@
class CashierLoginLog < ApplicationRecord
before_create :generate_custom_id
belongs_to :cashier_station
belongs_to :employee
private
def generate_custom_id
self.cashier_login_log_id = SeedGenerator.generate_id(self.class.name, "CLO")
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
before_create :generate_custom_id
has_many :orders
has_many :sales
@@ -8,4 +9,9 @@ class Customer < ApplicationRecord
def lastest_invoices
sales.where(:customer_id => self.id).order("created_at desc").limit(5)
end
private
def generate_custom_id
self.customer_id = SeedGenerator.generate_id(self.class.name, "CUS")
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

@@ -5,10 +5,13 @@ class MenuItem < ApplicationRecord
belongs_to :parent, :class_name => "MenuItem", foreign_key: "menu_item_id", :optional => true
has_many :children, :class_name => "MenuItem", foreign_key: "menu_item_id"
validates_presence_of :item_code, :type, :min_qty, :taxable, :min_selectable_item, :max_selectable_item
validates_presence_of :item_code, :name, :type, :min_qty, :taxable, :min_selectable_item, :max_selectable_item
default_scope { order('item_code asc') }
scope :simple_menu_item, -> { where(type: 'SimpleMenuItem') }
scope :set_menu_item, -> { where(type: 'SetMenuItem') }
def self.collection
MenuItem.select("id, name").map { |e| [e.name, e.id] }
end

View File

@@ -1,4 +1,6 @@
class MenuItemAttribute < ApplicationRecord
validates_presence_of :attribute_type, :name, :value
def self.collection
MenuItemAttribute.select("id, name").map { |e| [e.name, e.id] }
end
end

View File

@@ -1,4 +1,6 @@
class Order < ApplicationRecord
#primary key - need to be unique
before_create :generate_custom_id
before_create :set_order_date
belongs_to :customer
@@ -16,7 +18,7 @@ class Order < ApplicationRecord
# option_values : [],
# sub_order_items : [],
# }
def generate
booking = nil
@@ -180,14 +182,6 @@ class Order < ApplicationRecord
return new_items_list
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
def update_products_and_quantity_count
@@ -235,6 +229,18 @@ class Order < ApplicationRecord
.joins("left join sales on sales.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.id")
#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_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
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::ROOM_TYPE,"dine_in",true)
.group("orders.id,order_items.id,dining_facilities.name")
end
#Origami: Cashier : to view orders
def self.get_orders
@@ -244,9 +250,11 @@ class Order < ApplicationRecord
.joins("left join booking_orders on booking_orders.order_id = orders.id
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
left join sale_orders on sale_orders.order_id = orders.id
left join sales on sales.id = sale_orders.sale_id")
.where("dining_facilities.is_active=? and orders.date between ? and ?",true,from,to)
.group("orders.id")
@@ -259,4 +267,14 @@ class Order < ApplicationRecord
# .where("booking_orders.order_id IS NOT NULL and dining_facilities.is_active=? and orders.date between ? and ?",true,from,to)
# .group("orders.id")
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

View File

@@ -1,4 +1,7 @@
class OrderItem < ApplicationRecord
#primary key - need to be unique
before_create :generate_custom_id
#Associations
belongs_to :order, autosave: true
@@ -34,6 +37,7 @@ class OrderItem < ApplicationRecord
end
#Origami : Cashier : to show order items details
def self.get_order_items_details(booking_id)
booking_orders = BookingOrder.where("booking_id=?",booking_id)
if booking_orders
@@ -46,5 +50,10 @@ class OrderItem < ApplicationRecord
else
return false
end
private
def generate_custom_id
self.order_item_id = SeedGenerator.generate_id(self.class.name, "ODI")
end
end

View File

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

View File

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

View File

@@ -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)
@@ -48,4 +50,9 @@ class SaleAudit < ApplicationRecord
sale_audit.remark = remark
sale_audit.save!
end
private
def generate_custom_id
self.sale_audit_id = SeedGenerator.generate_id(self.class.name, "SAI")
end
end

View File

@@ -1,10 +1,14 @@
class SaleItem < ApplicationRecord
#primary key - need to be unique generated for multiple shops
before_create :generate_custom_id
belongs_to :sale
#compute items - discount, tax, price_change
def compute_item
end
def self.get_order_items_details(sale_id)
sale_orders = SaleOrder.where("sale_id=?",sale_id)
if sale_orders
@@ -17,5 +21,10 @@ class SaleItem < ApplicationRecord
else
return false
end
private
def generate_custom_id
self.sale_item_id = SeedGenerator.generate_id(self.class.name, "SLI")
end
end

View File

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

View File

@@ -1,4 +1,7 @@
class SalePayment < ApplicationRecord
#primary key - need to be unique generated for multiple shops
before_create :generate_custom_id
belongs_to :sale
:attr_accessor :received_amount, :card_payment_reference, :voucher_no, :giftcard_no, :customer_id, :external_payment_status
@@ -154,4 +157,8 @@ class SalePayment < ApplicationRecord
end
private
def generate_custom_id
self.sale_payment_id = SeedGenerator.generate_id(self.class.name, "SPI")
end
end

View File

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

View File

@@ -1,4 +1,24 @@
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
padding_len = 16 - prefix.len
return prefix +"-"+ seed.current.to_s.to_s.rjust((16-prefix.length)+1,'0')
end
def self.new_receipt_no
seed = SeedGenerator.find_by_model("sale")
new_receipt_no = 0

2
app/models/shop.rb Normal file
View File

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

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