pulled master at 4

This commit is contained in:
Yan
2017-06-04 18:29:58 +06:30
71 changed files with 590 additions and 161 deletions

View File

@@ -2,6 +2,6 @@ class Account < ApplicationRecord
validates_presence_of :title, :account_type
has_many :menu_items
# belongs_to :lookup , :class_name => "Lookup" ,:foreign_key => :tax_type
# belongs_to :lookup , :class_name => "Lookup"
end

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,14 +18,14 @@ class Order < ApplicationRecord
# option_values : [],
# sub_order_items : [],
# }
def generate
booking = nil
if self.new_booking
booking = Booking.create({:dining_facility_id => self.table_id,:type => "TableBooking",
:checkin_at => Time.now.utc, :checkin_by => self.employee_name,
:booking_status => "new" })
:booking_status => "assign" })
else
if (self.booking_id.to_i > 0 )
booking = Booking.find(self.booking_id)
@@ -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
@@ -221,7 +215,9 @@ 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
#Origami: Cashier : to view order type Room
def self.get_order_rooms
@@ -232,7 +228,7 @@ 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::ROOM_TYPE,"dine_in",true)
.group("orders.id")
.group("orders.id,order_items.id,dining_facilities.name")
end
#Origami: Cashier : to view orders
def self.get_orders
@@ -244,7 +240,18 @@ 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
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
@@ -37,6 +40,12 @@ class OrderItem < ApplicationRecord
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")
.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

View File

@@ -63,4 +63,13 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker
self.print(filename)
end
#Bill Receipt Print
def print_receipt_bill(printer_settings,sale_items,sale)
#Use CUPS service
#Generate PDF
#Print
pdf = ReceiptBillPdf.new(printer_settings,sale_items,sale)
pdf.render_file "tmp/receipt_bill_#{sale.id}.pdf"
self.print("tmp/receipt_bill_#{sale.id}.pdf")
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
@@ -240,4 +242,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,7 +1,15 @@
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
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