sales and orders methods updates
This commit is contained in:
@@ -1,8 +1,18 @@
|
|||||||
class Api::PaymentsController < ActionController::API
|
class Api::PaymentsController < ActionController::API
|
||||||
|
|
||||||
|
|
||||||
#Show customer by ID
|
#Payment by Invoice ID
|
||||||
|
# Payment Method - [Cash | CreditNote | VISA | MASTER | etc..]
|
||||||
|
# Invoice No | Amount
|
||||||
|
# Output
|
||||||
|
# Status - [True/False] | Invoice | error_message (* when status false)
|
||||||
def create
|
def create
|
||||||
@customer = Customer.find_by(params[:id])
|
@invoice = Sale.find(params[:invoice_id])
|
||||||
|
end
|
||||||
|
|
||||||
|
# Update of payment status from the external party
|
||||||
|
# Invoice No | Payment ID | External params [] (* third party references and status)
|
||||||
|
#
|
||||||
|
def update
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -30,13 +30,11 @@ class Order < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
booking.save!
|
booking.save!
|
||||||
|
|
||||||
self.default_values
|
self.default_values
|
||||||
|
|
||||||
if self.save!
|
if self.save!
|
||||||
|
|
||||||
self.adding_line_items
|
self.adding_line_items
|
||||||
|
|
||||||
#Add Order Table and Room relation afrer order creation
|
#Add Order Table and Room relation afrer order creation
|
||||||
if booking.type = "TableBooking"
|
if booking.type = "TableBooking"
|
||||||
#add to table_booking_order
|
#add to table_booking_order
|
||||||
@@ -60,7 +58,7 @@ class Order < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def adding_line_items
|
def adding_line_items
|
||||||
|
|
||||||
if self.items
|
if self.items
|
||||||
#loop to add all items to order
|
#loop to add all items to order
|
||||||
self.items.each do |item|
|
self.items.each do |item|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ class OrderItem < ApplicationRecord
|
|||||||
oitem.set_order_items = item["sub_order_items"]
|
oitem.set_order_items = item["sub_order_items"]
|
||||||
oitem.item_order_by = item_order_by
|
oitem.item_order_by = item_order_by
|
||||||
end
|
end
|
||||||
logger.info orderitem.to_yml
|
logger.debug orderitem.to_yml
|
||||||
orderitem.save!
|
orderitem.save!
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,93 @@
|
|||||||
class Sale < ApplicationRecord
|
class Sale < ApplicationRecord
|
||||||
|
before_create :generate_receipt_no
|
||||||
belongs_to :cashier
|
belongs_to :cashier
|
||||||
belongs_to :customer
|
belongs_to :customer
|
||||||
|
has_many :sale_items
|
||||||
|
has_many :sale_discounts
|
||||||
|
has_many :sale_taxes
|
||||||
|
has_many :sale_payments
|
||||||
|
has_many :sale_orders
|
||||||
|
|
||||||
|
def generate_invoice_from_order (order_no)
|
||||||
|
end
|
||||||
|
|
||||||
|
def generate_invoice_by_items (items)
|
||||||
|
end
|
||||||
|
|
||||||
|
def add_item (item)
|
||||||
|
#save sale_audit
|
||||||
|
end
|
||||||
|
|
||||||
|
def remove_item (item)
|
||||||
|
#save sale_audit
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def apply_discount_item (promotion_id, item)
|
||||||
|
end
|
||||||
|
|
||||||
|
def apply_discount (discount_type, discount_code)
|
||||||
|
#save action to sale_audit
|
||||||
|
end
|
||||||
|
|
||||||
|
def accept_payment (payment_method, amount, payment_ref, payment_external_result)
|
||||||
|
end
|
||||||
|
|
||||||
|
def void_sales (void_by, reason, approval_code)
|
||||||
|
#save sale_audit
|
||||||
|
end
|
||||||
|
|
||||||
|
#compute - invoice total
|
||||||
|
def compute
|
||||||
|
sales_items = self.sale_items
|
||||||
|
|
||||||
|
#Computation Fields
|
||||||
|
total_items_price = 0
|
||||||
|
total_discounts = 0
|
||||||
|
total_taxable = 0
|
||||||
|
rounding_adjustment = 0
|
||||||
|
|
||||||
|
sales_items.each do |item|
|
||||||
|
#compute each item and added to total
|
||||||
|
end
|
||||||
|
|
||||||
|
apply_tax
|
||||||
|
end
|
||||||
|
|
||||||
|
def apply_tax
|
||||||
|
#if tax is not apply create new record
|
||||||
|
self.sale_taxes.each |existing_tax|
|
||||||
|
#delete existing and create new
|
||||||
|
existing_tax.delete
|
||||||
|
end
|
||||||
|
|
||||||
|
#tax_profile - list by order_by
|
||||||
|
tax_profiles = TaxProfile.all.order("order_by asc")
|
||||||
|
|
||||||
|
|
||||||
|
#Creat new tax records
|
||||||
|
tax_profiles.each do |tax|
|
||||||
|
sale_tax = SaleTax.new(:sale => self)
|
||||||
|
sale_tax.tax_name = tax.name
|
||||||
|
sale_tax.tax_rate = tax.rate
|
||||||
|
#include or execulive
|
||||||
|
sale_tax.tax_payable_amount = self.total_amount * tax.rate
|
||||||
|
sale_tax.inclusive = tax.inclusive
|
||||||
|
sale_tax.save
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
private
|
||||||
|
#Generate new Receipt No when it is not assigned
|
||||||
|
def generate_receipt_no
|
||||||
|
#Date-Shift-
|
||||||
|
if !self.receipt_no.nil?
|
||||||
|
prefix = Date.now()
|
||||||
|
self.receipt_no = prefix.to_s + "/" + self.shit_id.to_s + "/" + SeedGenerator.new_receipt_no().to_s
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
class SaleItem < ApplicationRecord
|
class SaleItem < ApplicationRecord
|
||||||
belongs_to :sale
|
belongs_to :sale
|
||||||
|
|
||||||
|
#compute items - discount, tax, price_change
|
||||||
|
def compute_item
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
20
app/models/seed_generator.rb
Normal file
20
app/models/seed_generator.rb
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
class SeedGenerator < ApplicationRecord
|
||||||
|
def self.new_receipt_no
|
||||||
|
seed = SeedGenerator.find_by_model("sale")
|
||||||
|
new_receipt_no = 0
|
||||||
|
if (seed.nil?)
|
||||||
|
seed = SeedGenerator.new()
|
||||||
|
seed.model = "sale"
|
||||||
|
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 seed.current
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -31,15 +31,17 @@ Rails.application.routes.draw do
|
|||||||
resources :orders, only: [:create, :show, :update]
|
resources :orders, only: [:create, :show, :update]
|
||||||
#Current active bookings
|
#Current active bookings
|
||||||
resources :bookings, only: [:index, :create, :update]
|
resources :bookings, only: [:index, :create, :update]
|
||||||
resources :customers, only: [:index, :show, :create]
|
resources :customers, only: [:index, :show, :create, :update]
|
||||||
#Generating Invoice and making payments
|
#Generating Invoice and making payments
|
||||||
resources :invoices, only: [:create, :show, :update :show ] do
|
resources :invoices, only: [:create, :show, :update ] do
|
||||||
resources :payments, only: [:create]
|
resources :payments, only: [:create, :update]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#--------- Cashier ------------#
|
#--------- Cashier ------------#
|
||||||
namespace :cashier do
|
namespace :cashier do
|
||||||
|
|
||||||
|
#bookings
|
||||||
#orders
|
#orders
|
||||||
#invoices
|
#invoices
|
||||||
#payment
|
#payment
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ class CreateCustomers < ActiveRecord::Migration[5.0]
|
|||||||
t.string :company
|
t.string :company
|
||||||
t.string :contact_no
|
t.string :contact_no
|
||||||
t.string :email
|
t.string :email
|
||||||
|
t.date :date_of_birth
|
||||||
t.string :membership_id
|
t.string :membership_id
|
||||||
t.string :membership_type
|
t.string :membership_type
|
||||||
t.string :membership_authentication_code
|
t.string :membership_authentication_code
|
||||||
|
|||||||
12
db/migrate/20170408105938_create_seed_generators.rb
Normal file
12
db/migrate/20170408105938_create_seed_generators.rb
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
class CreateSeedGenerators < ActiveRecord::Migration[5.0]
|
||||||
|
def change
|
||||||
|
create_table :seed_generators do |t|
|
||||||
|
t.string :model, :null => false, :default => "sale"
|
||||||
|
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
|
||||||
|
end
|
||||||
5
spec/models/seed_generator_spec.rb
Normal file
5
spec/models/seed_generator_spec.rb
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe SeedGenerator, type: :model do
|
||||||
|
pending "add some examples to (or delete) #{__FILE__}"
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user