payment api
This commit is contained in:
2
Gemfile
2
Gemfile
@@ -5,7 +5,7 @@ git_source(:github) do |repo_name|
|
|||||||
"https://github.com/#{repo_name}.git"
|
"https://github.com/#{repo_name}.git"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#gem 'sqlite3' -
|
||||||
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
|
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
|
||||||
gem 'rails', '~> 5.0.2'
|
gem 'rails', '~> 5.0.2'
|
||||||
# Use mysql as the database for Active Record
|
# Use mysql as the database for Active Record
|
||||||
|
|||||||
19
app/controllers/api/discounts_controller.rb
Normal file
19
app/controllers/api/discounts_controller.rb
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
class Api::DiscountsController < ActionController::API
|
||||||
|
def create
|
||||||
|
@invoice = Sale.find(params[:invoice_id])
|
||||||
|
end
|
||||||
|
|
||||||
|
#Update sale item - Price | Qty |
|
||||||
|
def update
|
||||||
|
end
|
||||||
|
|
||||||
|
#destroy - Remove items form invoice
|
||||||
|
def destroy
|
||||||
|
@sale.remove_item(params[:sale_item_id])
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def set_invoice_params
|
||||||
|
@sale = Sale.find(params[:invoice_id])
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -1,33 +1,38 @@
|
|||||||
class Api::CustomersController < ActionController::API
|
class Api::InvoicesController < ActionController::API
|
||||||
before :authenticate_token
|
before :authenticate_token
|
||||||
|
before :set_sale_params, only:[:show, :update, :destroy]
|
||||||
|
|
||||||
|
#List open invoices for today.
|
||||||
|
def index
|
||||||
|
@sales = Sale.open_invoices
|
||||||
|
end
|
||||||
#Description
|
#Description
|
||||||
# This API show current order details
|
# This API show current sale details
|
||||||
# Input Params - order_id
|
# Input Params - ID
|
||||||
def show
|
def show
|
||||||
order = Order.find(params[:order_id])
|
@sale = Sale.find(params[:id])
|
||||||
order.order_items
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Description
|
#Creat Sales based on Items -
|
||||||
# This API allow new invoice creation
|
|
||||||
# Input Params
|
|
||||||
# order_id
|
|
||||||
# Output Params
|
|
||||||
# Status [Success | Error | System Error] , order_id, error_message (*)
|
|
||||||
def create
|
def create
|
||||||
#
|
#
|
||||||
|
end
|
||||||
|
|
||||||
|
#UPDATE SALES
|
||||||
|
def update
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def by_booking
|
#VOID Sale
|
||||||
end
|
def destroy
|
||||||
|
#Reason | #Approval
|
||||||
def by_order
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def process_items
|
def set_sale_params
|
||||||
|
@sale = Sale.find(params[:id])
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
19
app/controllers/api/memberships_controller.rb
Normal file
19
app/controllers/api/memberships_controller.rb
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
class Api::MembershipsController < ActionController::API
|
||||||
|
before :authenticate_token
|
||||||
|
|
||||||
|
|
||||||
|
#Add Membership to invoice
|
||||||
|
def create
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private
|
||||||
|
def set_sale_params
|
||||||
|
|
||||||
|
end
|
||||||
|
def process_items
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
@@ -31,7 +31,7 @@ class Api::OrdersController < ActionController::API
|
|||||||
@order.guest = params[:guest_info]
|
@order.guest = params[:guest_info]
|
||||||
@order.table_id = params[:table_id]
|
@order.table_id = params[:table_id]
|
||||||
@order.new_booking = true
|
@order.new_booking = true
|
||||||
@order.employee_name = "Test User"
|
@order.employee_name = current_login_employee.name
|
||||||
|
|
||||||
|
|
||||||
#Create Table Booking or Room Booking
|
#Create Table Booking or Room Booking
|
||||||
|
|||||||
@@ -8,11 +8,82 @@ class Api::PaymentsController < ActionController::API
|
|||||||
# Status - [True/False] | Invoice | error_message (* when status false)
|
# Status - [True/False] | Invoice | error_message (* when status false)
|
||||||
def create
|
def create
|
||||||
@invoice = Sale.find(params[:invoice_id])
|
@invoice = Sale.find(params[:invoice_id])
|
||||||
|
|
||||||
|
if (@invoice)
|
||||||
|
handle_payment(@invoice)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Update of payment status from the external party
|
# Update of payment status from the external party
|
||||||
# Invoice No | Payment ID | External params [] (* third party references and status)
|
# Invoice No | Payment ID | External params [] (* third party references and status)
|
||||||
#
|
#
|
||||||
def update
|
def update
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def handle_payment(sale_payment)
|
||||||
|
|
||||||
|
payment_method = params[:payment_method]
|
||||||
|
sale_payment = SalePayment.new
|
||||||
|
|
||||||
|
#:received_amount, :card_payment_reference, :vochure_no, :giftcard_no,
|
||||||
|
#:customer_id, :external_payment_status
|
||||||
|
switch (payment_method)
|
||||||
|
case "cash"
|
||||||
|
sale_payment.payment_method = "cash"
|
||||||
|
sale_payment.received_amount = params[:amount]
|
||||||
|
@status, @invoice = sale_payment.process_payment(sale_payment, current_login_employee.name)
|
||||||
|
case "creditnote"
|
||||||
|
sale_payment.payment_method = "creditnote"
|
||||||
|
sale_payment.received_amount = params[:amount]
|
||||||
|
sale_payment.customer_id = params[:customer_id]
|
||||||
|
|
||||||
|
@status, @invoice = sale_payment.process_payment(sale_payment, current_login_employee.name)
|
||||||
|
case "visa"
|
||||||
|
sale_payment.payment_method = "visa"
|
||||||
|
sale_payment.received_amount = params[:amount]
|
||||||
|
sale_payment.payment_reference = params[:payment_reference]
|
||||||
|
|
||||||
|
@status, @invoice = sale_payment.process_payment(sale_payment, current_login_employee.name)
|
||||||
|
case "master"
|
||||||
|
sale_payment.payment_method = "master"
|
||||||
|
sale_payment.received_amount = params[:amount]
|
||||||
|
sale_payment.payment_reference = params[:payment_reference]
|
||||||
|
@status, @invoice = sale_payment.process_payment(sale_payment, current_login_employee.name)
|
||||||
|
case "jcb"
|
||||||
|
sale_payment.payment_method = "jcb"
|
||||||
|
sale_payment.received_amount = params[:amount]
|
||||||
|
sale_payment.payment_reference = params[:payment_reference]
|
||||||
|
@status, @invoice = sale_payment.process_payment(sale_payment, current_login_employee.name)
|
||||||
|
case "mpu"
|
||||||
|
sale_payment.payment_method = "mpu"
|
||||||
|
sale_payment.received_amount = params[:amount]
|
||||||
|
sale_payment.payment_reference = params[:payment_reference]
|
||||||
|
@status, @invoice = sale_payment.process_payment(sale_payment, current_login_employee.name)
|
||||||
|
case "unionpay"
|
||||||
|
sale_payment.payment_method = "unionpay"
|
||||||
|
sale_payment.received_amount = params[:amount]
|
||||||
|
sale_payment.payment_reference = params[:payment_reference]
|
||||||
|
@status, @invoice = sale_payment.process_payment(sale_payment, current_login_employee.name)
|
||||||
|
case "vochure"
|
||||||
|
sale_payment.payment_method = "vochure"
|
||||||
|
sale_payment.received_amount = params[:amount]
|
||||||
|
sale_payment.customer_id = params[:customer_id]
|
||||||
|
sale_payment.payment_reference = params[:vochure_no]
|
||||||
|
@status, @invoice = sale_payment.process_payment(sale_payment, current_login_employee.name)
|
||||||
|
case "giftcard"
|
||||||
|
sale_payment.payment_method = "giftcard"
|
||||||
|
sale_payment.received_amount = params[:amount]
|
||||||
|
sale_payment.customer_id = params[:customer_id]
|
||||||
|
sale_payment.payment_reference = params[:giftcard_no]
|
||||||
|
@status, @invoice = sale_payment.process_payment(sale_payment, current_login_employee.name)
|
||||||
|
case "paypar"
|
||||||
|
sale_payment.payment_method = "paypar"
|
||||||
|
sale_payment.received_amount = params[:amount]
|
||||||
|
sale_payment.payment_reference = params[:payment_reference]
|
||||||
|
#TODO: implement paypar implementation
|
||||||
|
@status, @invoice = sale_payment.process_payment(sale_payment, current_login_employee.name)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
21
app/controllers/api/sale_items_controller.rb
Normal file
21
app/controllers/api/sale_items_controller.rb
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
class Api::SaleItemsController < ActionController::API
|
||||||
|
|
||||||
|
|
||||||
|
def create
|
||||||
|
@invoice = Sale.find(params[:invoice_id])
|
||||||
|
end
|
||||||
|
|
||||||
|
#Update sale item - Price | Qty |
|
||||||
|
def update
|
||||||
|
end
|
||||||
|
|
||||||
|
#destroy - Remove items form invoice
|
||||||
|
def destroy
|
||||||
|
@sale.remove_item(params[:sale_item_id])
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def set_invoice_params
|
||||||
|
@sale = Sale.find(params[:invoice_id])
|
||||||
|
end
|
||||||
|
end
|
||||||
74
app/controllers/settings/menus_controller.rb
Normal file
74
app/controllers/settings/menus_controller.rb
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
class Settings::MenusController < ApplicationController
|
||||||
|
before_action :set_settings_menu, only: [:show, :edit, :update, :destroy]
|
||||||
|
|
||||||
|
# GET /settings/menus
|
||||||
|
# GET /settings/menus.json
|
||||||
|
def index
|
||||||
|
@settings_menus = Settings::Menu.all
|
||||||
|
end
|
||||||
|
|
||||||
|
# GET /settings/menus/1
|
||||||
|
# GET /settings/menus/1.json
|
||||||
|
def show
|
||||||
|
end
|
||||||
|
|
||||||
|
# GET /settings/menus/new
|
||||||
|
def new
|
||||||
|
@settings_menu = Settings::Menu.new
|
||||||
|
end
|
||||||
|
|
||||||
|
# GET /settings/menus/1/edit
|
||||||
|
def edit
|
||||||
|
end
|
||||||
|
|
||||||
|
# POST /settings/menus
|
||||||
|
# POST /settings/menus.json
|
||||||
|
def create
|
||||||
|
@settings_menu = Settings::Menu.new(settings_menu_params)
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
if @settings_menu.save
|
||||||
|
format.html { redirect_to @settings_menu, notice: 'Menu was successfully created.' }
|
||||||
|
format.json { render :show, status: :created, location: @settings_menu }
|
||||||
|
else
|
||||||
|
format.html { render :new }
|
||||||
|
format.json { render json: @settings_menu.errors, status: :unprocessable_entity }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# PATCH/PUT /settings/menus/1
|
||||||
|
# PATCH/PUT /settings/menus/1.json
|
||||||
|
def update
|
||||||
|
respond_to do |format|
|
||||||
|
if @settings_menu.update(settings_menu_params)
|
||||||
|
format.html { redirect_to @settings_menu, notice: 'Menu was successfully updated.' }
|
||||||
|
format.json { render :show, status: :ok, location: @settings_menu }
|
||||||
|
else
|
||||||
|
format.html { render :edit }
|
||||||
|
format.json { render json: @settings_menu.errors, status: :unprocessable_entity }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# DELETE /settings/menus/1
|
||||||
|
# DELETE /settings/menus/1.json
|
||||||
|
def destroy
|
||||||
|
@settings_menu.destroy
|
||||||
|
respond_to do |format|
|
||||||
|
format.html { redirect_to settings_menus_url, notice: 'Menu was successfully destroyed.' }
|
||||||
|
format.json { head :no_content }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
# Use callbacks to share common setup or constraints between actions.
|
||||||
|
def set_settings_menu
|
||||||
|
@settings_menu = Settings::Menu.find(params[:id])
|
||||||
|
end
|
||||||
|
|
||||||
|
# Never trust parameters from the scary internet, only allow the white list through.
|
||||||
|
def settings_menu_params
|
||||||
|
params.fetch(:settings_menu, {})
|
||||||
|
end
|
||||||
|
end
|
||||||
2
app/helpers/settings/menus_helper.rb
Normal file
2
app/helpers/settings/menus_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
module Settings::MenusHelper
|
||||||
|
end
|
||||||
@@ -9,6 +9,8 @@ class Sale < ApplicationRecord
|
|||||||
has_many :sale_payments
|
has_many :sale_payments
|
||||||
has_many :sale_orders
|
has_many :sale_orders
|
||||||
|
|
||||||
|
scope :open_invoices, -> { where("sale_status = 'new' and receipt_date BETWEEN '#{DateTime.now.utc.end_of_day}' AND '#{DateTime.now.utc.beginning_of_day}'") }
|
||||||
|
|
||||||
def generate_invoice_from_booking(booking_id, requested_by)
|
def generate_invoice_from_booking(booking_id, requested_by)
|
||||||
booking = Booking.find(booking_id)
|
booking = Booking.find(booking_id)
|
||||||
status = false
|
status = false
|
||||||
@@ -48,6 +50,7 @@ class Sale < ApplicationRecord
|
|||||||
|
|
||||||
self.requested_by = requested_by
|
self.requested_by = requested_by
|
||||||
self.requested_at = DateTime.now.utc
|
self.requested_at = DateTime.now.utc
|
||||||
|
self.customer_id = order.customer_id
|
||||||
|
|
||||||
order = Order.find(order_no)
|
order = Order.find(order_no)
|
||||||
Rails.logger.debug "Order -> #{order.id} | order_status -> #{order.status}"
|
Rails.logger.debug "Order -> #{order.id} | order_status -> #{order.status}"
|
||||||
@@ -134,10 +137,6 @@ class Sale < ApplicationRecord
|
|||||||
#save action to sale_audit
|
#save action to sale_audit
|
||||||
end
|
end
|
||||||
|
|
||||||
def accept_payment (payment_method, amount, payment_ref, payment_external_result)
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
def void_sales (void_by, reason, approval_code, request_by)
|
def void_sales (void_by, reason, approval_code, request_by)
|
||||||
#save sale_audit
|
#save sale_audit
|
||||||
self.sale_status = "void"
|
self.sale_status = "void"
|
||||||
@@ -161,7 +160,9 @@ class Sale < ApplicationRecord
|
|||||||
apply_tax (total_taxable)
|
apply_tax (total_taxable)
|
||||||
self.total_amount = subtotal_price
|
self.total_amount = subtotal_price
|
||||||
self.total_discount = total_discount
|
self.total_discount = total_discount
|
||||||
|
self.grand_total = (self.total_amount - self.total_discount) + self.total_tax
|
||||||
|
#compute rounding adjustment
|
||||||
|
adjust_rounding
|
||||||
|
|
||||||
self.save!
|
self.save!
|
||||||
|
|
||||||
@@ -218,11 +219,16 @@ class Sale < ApplicationRecord
|
|||||||
#puts Time.now.format(":short")
|
#puts Time.now.format(":short")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def adjust_rounding
|
||||||
|
self.grand_total
|
||||||
|
self.rounding_adjustment = 0.00
|
||||||
|
end
|
||||||
|
|
||||||
#Generate new Receipt No when it is not assigned
|
#Generate new Receipt No when it is not assigned
|
||||||
def generate_receipt_no
|
def generate_receipt_no
|
||||||
#Date-Shift-
|
#Date-Shift-
|
||||||
if self.receipt_no.nil?
|
if self.receipt_no.nil?
|
||||||
prefix = DateTime.now()
|
prefix = DateTime.now().utc
|
||||||
#self.receipt_no = prefix.to_s + "/" + self.shit_id.to_s + "/" + SeedGenerator.new_receipt_no().to_s
|
#self.receipt_no = prefix.to_s + "/" + self.shit_id.to_s + "/" + SeedGenerator.new_receipt_no().to_s
|
||||||
self.receipt_no = prefix.strftime("%Y%m%d") + "/" + SeedGenerator.new_receipt_no().to_s
|
self.receipt_no = prefix.strftime("%Y%m%d") + "/" + SeedGenerator.new_receipt_no().to_s
|
||||||
|
|
||||||
|
|||||||
@@ -38,4 +38,14 @@ class SaleAudit < ApplicationRecord
|
|||||||
sale_audit.remark = reason
|
sale_audit.remark = reason
|
||||||
sale_audit.save!
|
sale_audit.save!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def record_payment(sale_id, remark, action_by)
|
||||||
|
sale_audit = SaleAudit.new()
|
||||||
|
sale_audit.sale_id = sale_id
|
||||||
|
sale_audit.action = "SALEPAYMENT"
|
||||||
|
sale_audit.action_at = DateTime.now.utc
|
||||||
|
sale_audit.action_by = action_by
|
||||||
|
sale_audit.remark = remark
|
||||||
|
sale_audit.save!
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,3 +1,157 @@
|
|||||||
class SalePayment < ApplicationRecord
|
class SalePayment < ApplicationRecord
|
||||||
belongs_to :sale
|
belongs_to :sale
|
||||||
|
|
||||||
|
:attr_accessor :received_amount, :card_payment_reference, :vochure_no, :giftcard_no, :customer_id, :external_payment_status
|
||||||
|
|
||||||
|
def process_payment(invoice, action_by)
|
||||||
|
self.sale = invoice
|
||||||
|
|
||||||
|
amount_due = invoice.grand_total
|
||||||
|
#get all payment for this invoices
|
||||||
|
invoice.sale_payments.each do |payment|
|
||||||
|
if (payment.payment_status == "paid" )
|
||||||
|
amount_due = amount_due - payment.payment_amount
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if (amount_due > 0)
|
||||||
|
payment_status = false
|
||||||
|
#route to payment type
|
||||||
|
switch (payment_method)
|
||||||
|
case "cash"
|
||||||
|
payment_status = cash_payment
|
||||||
|
case "creditnote"
|
||||||
|
payment_status = creditnote_payment
|
||||||
|
case "visa"
|
||||||
|
payment_status = external_terminal_card_payment(:visa)
|
||||||
|
case "master"
|
||||||
|
payment_status = external_terminal_card_payment(:master)
|
||||||
|
case "jcb"
|
||||||
|
payment_status = external_terminal_card_payment(:jcb)
|
||||||
|
case "mpu"
|
||||||
|
payment_status = external_terminal_card_payment(:mpu)
|
||||||
|
case "unionpay"
|
||||||
|
payment_status = external_terminal_card_payment(:unionpay)
|
||||||
|
case "vochure"
|
||||||
|
payment_status = vochure_payment
|
||||||
|
case "giftcard"
|
||||||
|
payment_status = giftcard_payment
|
||||||
|
case "paypar"
|
||||||
|
#TODO: implement paypar implementation
|
||||||
|
payment_status = paypar_payment
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#record an payment in sale-audit
|
||||||
|
remark = "Payment #{payment_method}- for Invoice #{invoice.receipt_no} Due [#{amount_due}]| pay amount -> #{amount} | Payment Status ->#{payment_status}"
|
||||||
|
sale_audit = SaleAudit.record_payment(invoice.id, remark, action_by)
|
||||||
|
|
||||||
|
return true, self.sale
|
||||||
|
else
|
||||||
|
#record an payment in sale-audit
|
||||||
|
remark = "No outstanding Amount - Grand Total [#{invoice.grand_total}] | Due [#{amount_due}] | Paid [#{invoice.amount_received}]"
|
||||||
|
sale_audit = SaleAudit.record_payment(invoice.id, remark,action_by)
|
||||||
|
|
||||||
|
return false, "No outstanding Amount"
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def cash_payment
|
||||||
|
payment_status = false
|
||||||
|
|
||||||
|
self.payment_method = "cash"
|
||||||
|
self.payment_amount = self.received_amount
|
||||||
|
self.outstanding_amount = self.sale.grand_total - received_amount
|
||||||
|
self.payment_status = "paid"
|
||||||
|
payment_method = self.save!
|
||||||
|
|
||||||
|
sale_update_payment_status(self.received_amount)
|
||||||
|
|
||||||
|
return payment_status
|
||||||
|
end
|
||||||
|
|
||||||
|
def creditnote_payment(self.customer_id)
|
||||||
|
payment_status = false
|
||||||
|
|
||||||
|
self.payment_method = "creditnote"
|
||||||
|
self.payment_amount = self.received_amount
|
||||||
|
self.customer_id = self.customer_id
|
||||||
|
self.outstanding_amount = 0 - self.received_amount
|
||||||
|
self.payment_status = "outstanding"
|
||||||
|
payment_method = self.save!
|
||||||
|
|
||||||
|
sale_update_payment_status(self.received_amount)
|
||||||
|
|
||||||
|
return payment_status
|
||||||
|
end
|
||||||
|
|
||||||
|
def external_terminal_card_payment(method)
|
||||||
|
payment_status = false
|
||||||
|
|
||||||
|
self.payment_method = method
|
||||||
|
self.payment_amount = self.received_amount
|
||||||
|
self.payment_reference = self.card_payment_reference
|
||||||
|
self.outstanding_amount = self.sale.grand_total- self.received_amount
|
||||||
|
self.payment_status = "paid"
|
||||||
|
payment_method = self.save!
|
||||||
|
|
||||||
|
sale_update_payment_status(self.received_amount)
|
||||||
|
|
||||||
|
return payment_status
|
||||||
|
end
|
||||||
|
|
||||||
|
def vochure_payment
|
||||||
|
payment_status = false
|
||||||
|
|
||||||
|
#Next time - validate if the vochure number is valid - within
|
||||||
|
self.payment_method = "vochure"
|
||||||
|
self.payment_amount = self.received_amount
|
||||||
|
self.payment_reference = self.vochure_no
|
||||||
|
self.outstanding_amount = self.sale.grand_total- self.received_amount
|
||||||
|
self.payment_status = "paid"
|
||||||
|
payment_method = self.save!
|
||||||
|
|
||||||
|
sale_update_payment_status(self.received_amount)
|
||||||
|
|
||||||
|
return payment_status
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def giftcard_payment
|
||||||
|
payment_status = false
|
||||||
|
|
||||||
|
#Next time - validate if the vochure number is valid - within
|
||||||
|
self.payment_method = "giftcard"
|
||||||
|
self.payment_amount = self.received_amount
|
||||||
|
self.payment_reference = self.giftcard_no
|
||||||
|
self.outstanding_amount = self.sale.grand_total- self.received_amount
|
||||||
|
self.payment_status = "paid"
|
||||||
|
payment_method = self.save!
|
||||||
|
|
||||||
|
sale_update_payment_status(self.received_amount)
|
||||||
|
|
||||||
|
return payment_status
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def paypar_payment
|
||||||
|
##TODO - Integration with Paypar (SmartPay)
|
||||||
|
end
|
||||||
|
|
||||||
|
def sale_update_payment_status(paid_amount)
|
||||||
|
|
||||||
|
#update amount_outstanding
|
||||||
|
self.sale.amount_received = self.sale.amount_received + paid_amount
|
||||||
|
self.sale.amount_changed = amount - self.sale.amount_received
|
||||||
|
if (self.sale.grand_total <= self.sale.amount_received && self.sale.amount_changed > 0)
|
||||||
|
self.sale.payment_status = "paid"
|
||||||
|
self.sale.sale_status = "completed"
|
||||||
|
self.sale.save!
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
10
app/views/settings/menus/_form.html.erb
Normal file
10
app/views/settings/menus/_form.html.erb
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<%= simple_form_for(@settings_menu) do |f| %>
|
||||||
|
<%= f.error_notification %>
|
||||||
|
|
||||||
|
<div class="form-inputs">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-actions">
|
||||||
|
<%= f.button :submit %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
2
app/views/settings/menus/_settings_menu.json.jbuilder
Normal file
2
app/views/settings/menus/_settings_menu.json.jbuilder
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
json.extract! settings_menu, :id, :created_at, :updated_at
|
||||||
|
json.url settings_menu_url(settings_menu, format: :json)
|
||||||
6
app/views/settings/menus/edit.html.erb
Normal file
6
app/views/settings/menus/edit.html.erb
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<h1>Editing Settings Menu</h1>
|
||||||
|
|
||||||
|
<%= render 'form', settings_menu: @settings_menu %>
|
||||||
|
|
||||||
|
<%= link_to 'Show', @settings_menu %> |
|
||||||
|
<%= link_to 'Back', settings_menus_path %>
|
||||||
25
app/views/settings/menus/index.html.erb
Normal file
25
app/views/settings/menus/index.html.erb
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
<p id="notice"><%= notice %></p>
|
||||||
|
|
||||||
|
<h1>Settings Menus</h1>
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th colspan="3"></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
|
||||||
|
<tbody>
|
||||||
|
<% @settings_menus.each do |settings_menu| %>
|
||||||
|
<tr>
|
||||||
|
<td><%= link_to 'Show', settings_menu %></td>
|
||||||
|
<td><%= link_to 'Edit', edit_settings_menu_path(settings_menu) %></td>
|
||||||
|
<td><%= link_to 'Destroy', settings_menu, method: :delete, data: { confirm: 'Are you sure?' } %></td>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<br>
|
||||||
|
|
||||||
|
<%= link_to 'New Settings Menu', new_settings_menu_path %>
|
||||||
1
app/views/settings/menus/index.json.jbuilder
Normal file
1
app/views/settings/menus/index.json.jbuilder
Normal file
@@ -0,0 +1 @@
|
|||||||
|
json.array! @settings_menus, partial: 'settings_menus/settings_menu', as: :settings_menu
|
||||||
5
app/views/settings/menus/new.html.erb
Normal file
5
app/views/settings/menus/new.html.erb
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<h1>New Settings Menu</h1>
|
||||||
|
|
||||||
|
<%= render 'form', settings_menu: @settings_menu %>
|
||||||
|
|
||||||
|
<%= link_to 'Back', settings_menus_path %>
|
||||||
4
app/views/settings/menus/show.html.erb
Normal file
4
app/views/settings/menus/show.html.erb
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
<p id="notice"><%= notice %></p>
|
||||||
|
|
||||||
|
<%= link_to 'Edit', edit_settings_menu_path(@settings_menu) %> |
|
||||||
|
<%= link_to 'Back', settings_menus_path %>
|
||||||
1
app/views/settings/menus/show.json.jbuilder
Normal file
1
app/views/settings/menus/show.json.jbuilder
Normal file
@@ -0,0 +1 @@
|
|||||||
|
json.partial! "settings_menus/settings_menu", settings_menu: @settings_menu
|
||||||
@@ -27,10 +27,10 @@ Rails.application.routes.draw do
|
|||||||
resources :menu_item_attributes, only: [:index]
|
resources :menu_item_attributes, only: [:index]
|
||||||
resources :menu_item_options, only: [:index]
|
resources :menu_item_options, only: [:index]
|
||||||
resources :menu_sold_out, only: [:index]
|
resources :menu_sold_out, only: [:index]
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
#User request move table or bills
|
#User request move table or bills
|
||||||
post "bill/:booking_id" => "bill#create"
|
post "bill" => "bill#create"
|
||||||
post "move" => "move#create"
|
post "move" => "move#create"
|
||||||
|
|
||||||
#Order Controller
|
#Order Controller
|
||||||
@@ -40,10 +40,17 @@ Rails.application.routes.draw do
|
|||||||
#Current active bookings
|
#Current active bookings
|
||||||
resources :bookings, only: [:index, :create, :update]
|
resources :bookings, only: [:index, :create, :update]
|
||||||
resources :customers, only: [:index, :show, :create, :update]
|
resources :customers, only: [:index, :show, :create, :update]
|
||||||
#Generating Invoice and making payments
|
|
||||||
resources :invoices, only: [:create, :show, :update ] do
|
#Generating Invoice and making payments - output render @sale
|
||||||
resources :payments, only: [:create, :update]
|
resources :invoices, only: [:index, :show, :create, :update, :destroy ] do
|
||||||
|
resources :sale_items, only:[:create, :update, :destroy]
|
||||||
|
resources :discounts, only: [:create, :update, :destroy]
|
||||||
|
resources :memberships, only:[:create]
|
||||||
|
post "payment/:payment_method" => "payment#create"
|
||||||
|
put "payment/:id" => "payment#update"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
#--------- Cashier ------------#
|
#--------- Cashier ------------#
|
||||||
|
|||||||
@@ -21,7 +21,8 @@ payment_methods = Lookup.create([{lookup_type:'payment_methods', name: 'Cash', v
|
|||||||
|
|
||||||
payment_status = Lookup.create([{lookup_type:'payment_status', name: 'New', value: 'new'},
|
payment_status = Lookup.create([{lookup_type:'payment_status', name: 'New', value: 'new'},
|
||||||
{lookup_type:'payment_status', name: 'paid', value: 'paid'},
|
{lookup_type:'payment_status', name: 'paid', value: 'paid'},
|
||||||
{lookup_type:'payment_status', name: 'Fail', value: 'fail'}])
|
{lookup_type:'payment_status', name: 'Fail', value: 'fail'},
|
||||||
|
{lookup_type:'payment_status', name: 'Outstanding', value: 'outstanding'}])
|
||||||
|
|
||||||
sales_status = Lookup.create([{lookup_type:'sales_status', name: 'New', value: 'new'},
|
sales_status = Lookup.create([{lookup_type:'sales_status', name: 'New', value: 'new'},
|
||||||
{lookup_type:'sales_status', name: 'Void', value: 'void'},
|
{lookup_type:'sales_status', name: 'Void', value: 'void'},
|
||||||
|
|||||||
159
spec/controllers/settings/menus_controller_spec.rb
Normal file
159
spec/controllers/settings/menus_controller_spec.rb
Normal file
@@ -0,0 +1,159 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
# This spec was generated by rspec-rails when you ran the scaffold generator.
|
||||||
|
# It demonstrates how one might use RSpec to specify the controller code that
|
||||||
|
# was generated by Rails when you ran the scaffold generator.
|
||||||
|
#
|
||||||
|
# It assumes that the implementation code is generated by the rails scaffold
|
||||||
|
# generator. If you are using any extension libraries to generate different
|
||||||
|
# controller code, this generated spec may or may not pass.
|
||||||
|
#
|
||||||
|
# It only uses APIs available in rails and/or rspec-rails. There are a number
|
||||||
|
# of tools you can use to make these specs even more expressive, but we're
|
||||||
|
# sticking to rails and rspec-rails APIs to keep things simple and stable.
|
||||||
|
#
|
||||||
|
# Compared to earlier versions of this generator, there is very limited use of
|
||||||
|
# stubs and message expectations in this spec. Stubs are only used when there
|
||||||
|
# is no simpler way to get a handle on the object needed for the example.
|
||||||
|
# Message expectations are only used when there is no simpler way to specify
|
||||||
|
# that an instance is receiving a specific message.
|
||||||
|
|
||||||
|
RSpec.describe Settings::MenusController, type: :controller do
|
||||||
|
|
||||||
|
# This should return the minimal set of attributes required to create a valid
|
||||||
|
# Settings::Menu. As you add validations to Settings::Menu, be sure to
|
||||||
|
# adjust the attributes here as well.
|
||||||
|
let(:valid_attributes) {
|
||||||
|
skip("Add a hash of attributes valid for your model")
|
||||||
|
}
|
||||||
|
|
||||||
|
let(:invalid_attributes) {
|
||||||
|
skip("Add a hash of attributes invalid for your model")
|
||||||
|
}
|
||||||
|
|
||||||
|
# This should return the minimal set of values that should be in the session
|
||||||
|
# in order to pass any filters (e.g. authentication) defined in
|
||||||
|
# Settings::MenusController. Be sure to keep this updated too.
|
||||||
|
let(:valid_session) { {} }
|
||||||
|
|
||||||
|
describe "GET #index" do
|
||||||
|
it "assigns all settings_menus as @settings_menus" do
|
||||||
|
menu = Settings::Menu.create! valid_attributes
|
||||||
|
get :index, params: {}, session: valid_session
|
||||||
|
expect(assigns(:settings_menus)).to eq([menu])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "GET #show" do
|
||||||
|
it "assigns the requested settings_menu as @settings_menu" do
|
||||||
|
menu = Settings::Menu.create! valid_attributes
|
||||||
|
get :show, params: {id: menu.to_param}, session: valid_session
|
||||||
|
expect(assigns(:settings_menu)).to eq(menu)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "GET #new" do
|
||||||
|
it "assigns a new settings_menu as @settings_menu" do
|
||||||
|
get :new, params: {}, session: valid_session
|
||||||
|
expect(assigns(:settings_menu)).to be_a_new(Settings::Menu)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "GET #edit" do
|
||||||
|
it "assigns the requested settings_menu as @settings_menu" do
|
||||||
|
menu = Settings::Menu.create! valid_attributes
|
||||||
|
get :edit, params: {id: menu.to_param}, session: valid_session
|
||||||
|
expect(assigns(:settings_menu)).to eq(menu)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "POST #create" do
|
||||||
|
context "with valid params" do
|
||||||
|
it "creates a new Settings::Menu" do
|
||||||
|
expect {
|
||||||
|
post :create, params: {settings_menu: valid_attributes}, session: valid_session
|
||||||
|
}.to change(Settings::Menu, :count).by(1)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "assigns a newly created settings_menu as @settings_menu" do
|
||||||
|
post :create, params: {settings_menu: valid_attributes}, session: valid_session
|
||||||
|
expect(assigns(:settings_menu)).to be_a(Settings::Menu)
|
||||||
|
expect(assigns(:settings_menu)).to be_persisted
|
||||||
|
end
|
||||||
|
|
||||||
|
it "redirects to the created settings_menu" do
|
||||||
|
post :create, params: {settings_menu: valid_attributes}, session: valid_session
|
||||||
|
expect(response).to redirect_to(Settings::Menu.last)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with invalid params" do
|
||||||
|
it "assigns a newly created but unsaved settings_menu as @settings_menu" do
|
||||||
|
post :create, params: {settings_menu: invalid_attributes}, session: valid_session
|
||||||
|
expect(assigns(:settings_menu)).to be_a_new(Settings::Menu)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "re-renders the 'new' template" do
|
||||||
|
post :create, params: {settings_menu: invalid_attributes}, session: valid_session
|
||||||
|
expect(response).to render_template("new")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "PUT #update" do
|
||||||
|
context "with valid params" do
|
||||||
|
let(:new_attributes) {
|
||||||
|
skip("Add a hash of attributes valid for your model")
|
||||||
|
}
|
||||||
|
|
||||||
|
it "updates the requested settings_menu" do
|
||||||
|
menu = Settings::Menu.create! valid_attributes
|
||||||
|
put :update, params: {id: menu.to_param, settings_menu: new_attributes}, session: valid_session
|
||||||
|
menu.reload
|
||||||
|
skip("Add assertions for updated state")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "assigns the requested settings_menu as @settings_menu" do
|
||||||
|
menu = Settings::Menu.create! valid_attributes
|
||||||
|
put :update, params: {id: menu.to_param, settings_menu: valid_attributes}, session: valid_session
|
||||||
|
expect(assigns(:settings_menu)).to eq(menu)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "redirects to the settings_menu" do
|
||||||
|
menu = Settings::Menu.create! valid_attributes
|
||||||
|
put :update, params: {id: menu.to_param, settings_menu: valid_attributes}, session: valid_session
|
||||||
|
expect(response).to redirect_to(menu)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with invalid params" do
|
||||||
|
it "assigns the settings_menu as @settings_menu" do
|
||||||
|
menu = Settings::Menu.create! valid_attributes
|
||||||
|
put :update, params: {id: menu.to_param, settings_menu: invalid_attributes}, session: valid_session
|
||||||
|
expect(assigns(:settings_menu)).to eq(menu)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "re-renders the 'edit' template" do
|
||||||
|
menu = Settings::Menu.create! valid_attributes
|
||||||
|
put :update, params: {id: menu.to_param, settings_menu: invalid_attributes}, session: valid_session
|
||||||
|
expect(response).to render_template("edit")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "DELETE #destroy" do
|
||||||
|
it "destroys the requested settings_menu" do
|
||||||
|
menu = Settings::Menu.create! valid_attributes
|
||||||
|
expect {
|
||||||
|
delete :destroy, params: {id: menu.to_param}, session: valid_session
|
||||||
|
}.to change(Settings::Menu, :count).by(-1)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "redirects to the settings_menus list" do
|
||||||
|
menu = Settings::Menu.create! valid_attributes
|
||||||
|
delete :destroy, params: {id: menu.to_param}, session: valid_session
|
||||||
|
expect(response).to redirect_to(settings_menus_url)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
15
spec/helpers/settings/menus_helper_spec.rb
Normal file
15
spec/helpers/settings/menus_helper_spec.rb
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
# Specs in this file have access to a helper object that includes
|
||||||
|
# the Settings::MenusHelper. For example:
|
||||||
|
#
|
||||||
|
# describe Settings::MenusHelper do
|
||||||
|
# describe "string concat" do
|
||||||
|
# it "concats two strings with spaces" do
|
||||||
|
# expect(helper.concat_strings("this","that")).to eq("this that")
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
RSpec.describe Settings::MenusHelper, type: :helper do
|
||||||
|
pending "add some examples to (or delete) #{__FILE__}"
|
||||||
|
end
|
||||||
10
spec/requests/settings/settings_menus_spec.rb
Normal file
10
spec/requests/settings/settings_menus_spec.rb
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe "Settings::Menus", type: :request do
|
||||||
|
describe "GET /settings_menus" do
|
||||||
|
it "works! (now write some real specs)" do
|
||||||
|
get settings_menus_path
|
||||||
|
expect(response).to have_http_status(200)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
39
spec/routing/settings/menus_routing_spec.rb
Normal file
39
spec/routing/settings/menus_routing_spec.rb
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
require "rails_helper"
|
||||||
|
|
||||||
|
RSpec.describe Settings::MenusController, type: :routing do
|
||||||
|
describe "routing" do
|
||||||
|
|
||||||
|
it "routes to #index" do
|
||||||
|
expect(:get => "/settings/menus").to route_to("settings/menus#index")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "routes to #new" do
|
||||||
|
expect(:get => "/settings/menus/new").to route_to("settings/menus#new")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "routes to #show" do
|
||||||
|
expect(:get => "/settings/menus/1").to route_to("settings/menus#show", :id => "1")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "routes to #edit" do
|
||||||
|
expect(:get => "/settings/menus/1/edit").to route_to("settings/menus#edit", :id => "1")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "routes to #create" do
|
||||||
|
expect(:post => "/settings/menus").to route_to("settings/menus#create")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "routes to #update via PUT" do
|
||||||
|
expect(:put => "/settings/menus/1").to route_to("settings/menus#update", :id => "1")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "routes to #update via PATCH" do
|
||||||
|
expect(:patch => "/settings/menus/1").to route_to("settings/menus#update", :id => "1")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "routes to #destroy" do
|
||||||
|
expect(:delete => "/settings/menus/1").to route_to("settings/menus#destroy", :id => "1")
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
14
spec/views/settings/menus/edit.html.erb_spec.rb
Normal file
14
spec/views/settings/menus/edit.html.erb_spec.rb
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe "settings/menus/edit", type: :view do
|
||||||
|
before(:each) do
|
||||||
|
@settings_menu = assign(:settings_menu, Settings::Menu.create!())
|
||||||
|
end
|
||||||
|
|
||||||
|
it "renders the edit settings_menu form" do
|
||||||
|
render
|
||||||
|
|
||||||
|
assert_select "form[action=?][method=?]", settings_menu_path(@settings_menu), "post" do
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
14
spec/views/settings/menus/index.html.erb_spec.rb
Normal file
14
spec/views/settings/menus/index.html.erb_spec.rb
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe "settings/menus/index", type: :view do
|
||||||
|
before(:each) do
|
||||||
|
assign(:settings_menus, [
|
||||||
|
Settings::Menu.create!(),
|
||||||
|
Settings::Menu.create!()
|
||||||
|
])
|
||||||
|
end
|
||||||
|
|
||||||
|
it "renders a list of settings/menus" do
|
||||||
|
render
|
||||||
|
end
|
||||||
|
end
|
||||||
14
spec/views/settings/menus/new.html.erb_spec.rb
Normal file
14
spec/views/settings/menus/new.html.erb_spec.rb
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe "settings/menus/new", type: :view do
|
||||||
|
before(:each) do
|
||||||
|
assign(:settings_menu, Settings::Menu.new())
|
||||||
|
end
|
||||||
|
|
||||||
|
it "renders new settings_menu form" do
|
||||||
|
render
|
||||||
|
|
||||||
|
assert_select "form[action=?][method=?]", settings_menus_path, "post" do
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
11
spec/views/settings/menus/show.html.erb_spec.rb
Normal file
11
spec/views/settings/menus/show.html.erb_spec.rb
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe "settings/menus/show", type: :view do
|
||||||
|
before(:each) do
|
||||||
|
@settings_menu = assign(:settings_menu, Settings::Menu.create!())
|
||||||
|
end
|
||||||
|
|
||||||
|
it "renders attributes in <p>" do
|
||||||
|
render
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user