api discount and change tax

This commit is contained in:
Thein Lin Kyaw
2023-10-17 16:52:12 +06:30
parent 81eb30c03a
commit 3441811bb0
27 changed files with 1225 additions and 1067 deletions

View File

@@ -1,5 +1,5 @@
class Api::BookingsController < Api::ApiController
skip_before_action :authenticate
# skip_before_action :authenticate
#Show customer by ID
def index
@bookings = Booking.all

View File

@@ -0,0 +1,16 @@
class Api::ChangeTaxController < Api::ApiController
def index
sale_id = params[:sale_id]
group_type = params[:group_type]
tax_type = params[:tax_type].present? ? params[:tax_type] : "no_tax"
sale = Sale.find(sale_id)
sale.compute_by_sale_items(sale.total_discount, nil, group_type, tax_type)
remark = "Change tax to #{tax_type} for Sale ID #{sale_id} By #{current_login_employee.name}"
SaleAudit.record_audit_change_tax(sale_id,remark,current_login_employee.name)
end
end

View File

@@ -23,9 +23,10 @@ class Api::CustomersController < Api::ApiController
def get_customer_by_account
account_no = params[:account_no]
group_type = params[:group_type] || 'food_court'
unless @customer = Customer.find_by(paypar_account_no: account_no)
response = Customer.search_paypar_account_no(account_no)
response = Customer.search_paypar_account_no(account_no)
if response["status"] == true
@customer = Customer.create({
name: response["customer_data"]["name"],
@@ -39,8 +40,10 @@ class Api::CustomersController < Api::ApiController
membership_id: response["customer_data"]["id"],
membership_type: response["customer_data"]["member_group_id"],
customer_type: "Dinein",
tax_profiles: ["1", "2"],
tax_profiles: TaxProfile.where(group_type: group_type).pluck(:id),
})
else
@message = response["message"]
end
end
end

View File

@@ -1,19 +1,138 @@
class Api::DiscountsController < ActionController::API
def create
@invoice = Sale.find(params[:invoice_id])
class Api::DiscountsController < Api::ApiController
def create
sale_id = params[:sale_id]
sale_item_id = params[:sale_item_id]
discount = params[:discount].to_d
discount_type = params[:discount_type]
@sale = Sale.find(sale_id)
@booking = @sale.booking
dining_facility = @booking.dining_facility
action_by = current_login_employee.name
bill_discount = @sale.total_discount
if sale_item_id
sale_item = SaleItem.find(sale_item_id)
discount_item = sale_item.discount_item
if discount > 0
unless discount_item
discount_item = sale_item.build_discount_item
end
discount_item.discount = discount
if discount_type == 'nett'
discount_item.discount_type = 'nett'
discount_item.product_name = "#{sale_item.product_name} - discount"
unit_price = discount
elsif discount_type == 'percentage'
discount_item.discount_type = 'percentage'
discount_item.product_name = "#{sale_item.product_name} - discount(#{discount}%)"
unit_price = sale_item.unit_price * (discount / 100)
end
price = unit_price * sale_item.qty
discount_item.menu_category_code = sale_item.menu_category_code
discount_item.menu_category_name = sale_item.menu_category_name
discount_item.sale_id = sale_id
discount_item.product_code = sale_item != nil ? sale_item.product_code : sale_id
discount_item.item_instance_code = sale_item.item_instance_code
discount_item.product_alt_name = ""
discount_item.status = "Discount"
discount_item.qty = sale_item.qty
discount_item.unit_price = unit_price
discount_item.taxable_price = -price
discount_item.is_taxable = sale_item.is_taxable
discount_item.account_id = sale_item.account_id
discount_item.price = -price
discount_item.save
remark = "Discount Item Name ->#{discount_item.product_name}-Product Code ->#{discount_item.product_code} | Price [#{discount_item.price}] | Receipt No #{@sale.receipt_no} "
sale_audit = SaleAudit.record_audit_discount(discount_item.sale_id, @sale.cashier_name, action_by, remark, "ITEMDISCOUNT" )
else
discount_item.destroy
if dining_facility.nil?
remark = "Remove Item Discount Item Name ->#{discount_item.product_name}-Product Code ->#{discount_item.product_code} | Price [#{discount_item.price}] | Receipt No #{@sale.receipt_no} | Table- No Table "
else
remark = "Remove Item Discount Item Name ->#{discount_item.product_name}-Product Code ->#{discount_item.product_code} | Price [#{discount_item.price}] | Receipt No #{@sale.receipt_no} | Table- #{dining_facility.name} "
end
sale_audit = SaleAudit.record_audit_discount(@sale.sale_id, @sale.cashier_name, action_by, remark, "REMOVEITEMDISCOUNT" )
end
else
if discount > 0
if discount_type == 'nett'
bill_discount = discount
elsif discount_type == 'percentage'
bill_discount = @sale.total_amount * (discount / 100)
end
if dining_facility.nil?
remark = "Discount Overall Price [#{bill_discount}]| Receipt No #{@sale.receipt_no} | Table- no Table "
else
remark = "Discount Overall Price [#{bill_discount}]| Receipt No #{@sale.receipt_no} | Table- #{dining_facility.name} "
end
sale_audit = SaleAudit.record_audit_discount(@sale.sale_id, @sale.cashier_name, action_by, remark, "OVERALLDISCOUNT" )
else
if dining_facility.nil?
remark = "Remove Discount Sale Id [#{@sale.sale_id}]| Receipt No #{@sale.receipt_no} | Table- No Table"
else
remark = "Remove Discount Sale Id [#{@sale.sale_id}]| Receipt No #{@sale.receipt_no} | Table- #{dining_facility.name} "
end
sale_audit = SaleAudit.record_audit_discount(@sale.sale_id, @sale.cashier_name, action_by, remark, "REMOVEALLDISCOUNT" )
bill_discount = 0.0.to_d
end
end
@sale.compute_by_sale_items(bill_discount, nil, order_source)
end
#Update sale item - Price | Qty |
def update
end
#destroy - Remove items form invoice
def destroy
@sale.remove_item(params[:sale_item_id])
sale_id = params[:sale_id]
sale_item_id = params[:sale_item_id]
@sale = Sale.find(sale_id)
@booking = @sale.booking
dining_facility = @booking.dining_facility
action_by = current_login_employee.name
bill_discount = @sale.total_discount
if sale_item_id
sale_item = SaleItem.find(sale_item_id)
discount_item = sale_item.discount_item
discount_item.destroy
if dining_facility.nil?
remark = "Remove Item Discount Item Name ->#{discount_item.product_name}-Product Code ->#{discount_item.product_code} | Price [#{discount_item.price}] | Receipt No #{@sale.receipt_no} | Table- No Table "
else
remark = "Remove Item Discount Item Name ->#{discount_item.product_name}-Product Code ->#{discount_item.product_code} | Price [#{discount_item.price}] | Receipt No #{@sale.receipt_no} | Table- #{dining_facility.name} "
end
sale_audit = SaleAudit.record_audit_discount(@sale.sale_id, @sale.cashier_name, action_by, remark, "REMOVEITEMDISCOUNT" )
else
if dining_facility.nil?
remark = "Remove Discount Sale Id [#{@sale.sale_id}]| Receipt No #{@sale.receipt_no} | Table- No Table"
else
remark = "Remove Discount Sale Id [#{@sale.sale_id}]| Receipt No #{@sale.receipt_no} | Table- #{dining_facility.name} "
end
sale_audit = SaleAudit.record_audit_discount(@sale.sale_id, @sale.cashier_name, action_by, remark, "REMOVEALLDISCOUNT" )
bill_discount = 0.0.to_d
end
@sale.compute_by_sale_items(bill_discount, nil, order_source)
end
private
def set_invoice_params
@sale = Sale.find(params[:invoice_id])
def order_source
params[:order_source] || 'food_court'
end
end

View File

@@ -3,13 +3,13 @@ class Api::Foodcourt::BillsController < Api::ApiController
def create
Sale.transaction do
if shift = ShiftSale.current_open_shift(current_login_employee)
if booking = Booking.find(params[:booking_id])
if @booking = Booking.find(params[:booking_id])
cashier = Employee.find(shift.employee_id)
order = booking.orders.first
order = @booking.orders.first
if @sale_data = booking.sale
if @sale_data = @booking.sale
@status = true
elsif @sale_data = Sale.generate_invoice_from_booking(booking, current_login_employee, cashier, order.source, params[:current_checkin_induties_count])
elsif @sale_data = Sale.generate_invoice_from_booking(@booking, current_login_employee, cashier, order.source, params[:current_checkin_induties_count])
@status = true
else
@status = false