fixed conflict

This commit is contained in:
Nweni
2017-06-29 13:39:37 +06:30
21 changed files with 550 additions and 140 deletions

View File

@@ -1,6 +1,6 @@
class Api::ApiController < ActionController::API
include TokenVerification
helper_method :current_token, :current_login_employee
helper_method :current_token, :current_login_employee, :get_cashier
private
@@ -13,6 +13,11 @@ class Api::ApiController < ActionController::API
end
end
# Get current Cashier
def get_cashier
@cashier = Employee.where("role = 'cashier' AND token_session <> ''")
end
def current_login_employee
@employee = Employee.find_by_token_session(current_token)
end

View File

@@ -13,7 +13,7 @@ class Api::BillController < Api::ApiController
if booking
if booking.sale_id.nil?
@sale = Sale.new
@status, @sale_id = @sale.generate_invoice_from_booking(params[:booking_id], current_login_employee)
@status, @sale_id = @sale.generate_invoice_from_booking(params[:booking_id], current_login_employee, get_cashier)
else
@status = true
@sale_id = booking.sale_id
@@ -22,23 +22,31 @@ class Api::BillController < Api::ApiController
elsif (params[:order_id])
@sale = Sale.new
@status, @sale_id = @sale.generate_invoice_from_order(params[:order_id], current_login_employee)
@status, @sale_id = @sale.generate_invoice_from_order(params[:order_id], current_login_employee, get_cashier)
end
@sale_data = Sale.find_by_sale_id(@sale_id)
@sale_items = SaleItem.where("sale_id=?",@sale_id)
# Not Use for these printed bill cannot give customer
# @sale_data = Sale.find_by_sale_id(@sale_id)
# @sale_items = SaleItem.where("sale_id=?",@sale_id)
unique_code = "ReceiptBillPdf"
customer= Customer.find(@sale_data.customer_id)
# unique_code = "ReceiptBillPdf"
# #shop detail
# shop_details = Shop.find(1)
# get printer info
print_settings=PrintSetting.find_by_unique_code(unique_code)
# customer= Customer.find(@sale_data.customer_id)
# # get member information
# member_info = Customer.get_member_account(customer)
# Calculate Price by accounts
item_price_by_accounts = SaleItem.calculate_price_by_accounts(@sale_items)
# # get printer info
# print_settings=PrintSetting.find_by_unique_code(unique_code)
# # Calculate Price by accounts
# item_price_by_accounts = SaleItem.calculate_price_by_accounts(@sale_items)
# printer = Printer::ReceiptPrinter.new(print_settings)
# printer.print_receipt_bill(print_settings,@sale_items,@sale_data,customer.name, item_price_by_accounts, member_info, shop_details)
printer = Printer::ReceiptPrinter.new(print_settings)
# printer.print_receipt_bill(print_settings,@sale_items,@sale_data,customer.name, item_price_by_accounts)
end

View File

@@ -67,32 +67,58 @@ class Api::OrdersController < Api::ApiController
if booking
if booking.dining_facility_id.to_i == params[:table_id].to_i && booking.booking_status != 'moved'
if !booking.sale_id.nil?
check_order_with_booking(booking)
sale_status = check_order_with_booking(booking)
puts "WWwwWWWWWWww"
puts sale_status
if sale_status
return false , @message = "bill requested"
end
else
@order.new_booking = false
@order.booking_id = params[:booking_id]
end
else
check_order_with_table(params[:table_id])
sale_status = check_order_with_table(params[:table_id])
puts "OOOOOOOOO"
puts sale_status
if sale_status
return false , @message = "bill requested"
end
end
end #booking exists
else
check_order_with_table(params[:table_id])
end
sale_status = check_order_with_table(params[:table_id])
puts "MMMMMMMM"
puts sale_status
if sale_status
return false , @message = "bill requested"
end
end
@status, @booking = @order.generate
end
# render json for http status code 202
def return_json_status_with_code(code, msg, booking_id)
render status: code, json: {
message: msg,
booking_id: booking_id
}.to_json
end
def check_order_with_table(table_id)
table = DiningFacility.find(table_id)
if table
booking = table.get_current_booking
puts booking
if booking
if booking.sale.sale_status == "completed" || booking.sale.sale_status == "billed"
@order.new_booking = true
return true
else
@order.new_booking = false
@order.booking_id = booking.booking_id
return false
end
end
end
@@ -101,9 +127,11 @@ class Api::OrdersController < Api::ApiController
def check_order_with_booking(booking)
if booking.sale.sale_status == "completed" || booking.sale.sale_status == "billed"
@order.new_booking = true
return true
else
@order.new_booking = false
@order.booking_id = params[:booking_id]
return false
end
end
# Description

View File

@@ -29,7 +29,6 @@ class Origami::DiscountsController < BaseOrigamiController
if discount_items.length > 0
#save sale item for discount
discount_items.each do |di|
puts di
origin_sale_item = SaleItem.find(di["id"])
sale_item = SaleItem.new
@@ -53,6 +52,59 @@ class Origami::DiscountsController < BaseOrigamiController
render :json => dining.to_json
end
# Remove selected discount Items
def remove_discount_items
sale_id = params[:sale_id]
discount_items = JSON.parse(params[:discount_items])
if Sale.exists?(sale_id)
sale = Sale.find(sale_id)
table_id = sale.bookings[0].dining_facility_id
table_type = DiningFacility.find(table_id).type
if discount_items.length > 0
#destroy sale item for discount
discount_items.each do |di|
sale_item = SaleItem.find(di["id"])
sale.total_amount = (sale.total_amount + sale_item.price.abs)
sale_item.destroy
end
end
sale.grand_total = (sale.total_amount - sale.total_discount) + sale.total_tax;
sale.save
end
dining = {:table_id => table_id, :table_type => table_type }
render :json => dining.to_json
end
# Remove all discount Items
def remove_all_discount
sale_id = params[:id]
if Sale.exists?(sale_id)
sale = Sale.find(sale_id)
table_id = sale.bookings[0].dining_facility_id
table_type = DiningFacility.find(table_id).type
#destroy all discount sale item
sale.sale_items.each do |si|
if si.remark == "Discount" && si.price < 0
sale.total_amount = (sale.total_amount + si.price.abs)
si.destroy
end
end
sale.grand_total = (sale.total_amount - sale.total_discount) + sale.total_tax;
sale.save
end
dining = {:table_id => table_id, :table_type => table_type }
render :json => dining.to_json
end
#discount for selected order
# def create
# sale_id = params[:sale_id]

View File

@@ -4,6 +4,34 @@ class Origami::PaymentsController < BaseOrigamiController
def index
end
def first_bill
sale_id = params[:sale_id] # sale_id
sale_data = Sale.find_by_sale_id(sale_id)
sale_items = SaleItem.where("sale_id=?",sale_id)
# Print for First Bill to Customer
unique_code = "ReceiptBillPdf"
#shop detail
shop_details = Shop.find(1)
# customer= Customer.where('customer_id=' +.customer_id)
customer= Customer.find(sale_data.customer_id)
# get member information
member_info = Customer.get_member_account(customer)
# get printer info
print_settings=PrintSetting.find_by_unique_code(unique_code)
# find order id by sale id
# sale_order = SaleOrder.find_by_sale_id(@sale_data.sale_id)
# Calculate price_by_accounts
item_price_by_accounts = SaleItem.calculate_price_by_accounts(sale_items)
discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(sale_items)
printer = Printer::ReceiptPrinter.new(print_settings)
printer.print_receipt_bill(print_settings,sale_items,sale_data,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info, shop_details)
end
def create
cash = params[:cash]
sale_id = params[:sale_id]
@@ -26,9 +54,10 @@ class Origami::PaymentsController < BaseOrigamiController
print_settings=PrintSetting.find_by_unique_code(unique_code)
# Calculate Food and Beverage Total
item_price_by_accounts = SaleItem.calculate_price_by_accounts(saleObj.sale_items)
discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(saleObj.sale_items)
printer = Printer::ReceiptPrinter.new(print_settings)
printer.print_receipt_bill(print_settings,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, member_info,rebate_amount,shop_details)
printer.print_receipt_bill(print_settings,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details)
end
end
@@ -104,10 +133,9 @@ class Origami::PaymentsController < BaseOrigamiController
# Calculate price_by_accounts
item_price_by_accounts = SaleItem.calculate_price_by_accounts(saleObj.sale_items)
discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(saleObj.sale_items)
printer = Printer::ReceiptPrinter.new(print_settings)
printer.print_receipt_bill(print_settings,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, member_info,rebate_amount,shop_details)
printer.print_receipt_bill(print_settings,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details)
end
end

View File

@@ -10,9 +10,9 @@ class Origami::RequestBillsController < BaseOrigamiController
check_booking = Booking.find_by_booking_id(bk_order.booking_id)
if check_booking.sale_id.nil?
# Create Sale if it doesn't exist
puts "current_login_employee"
puts current_login_employee.name
@status, @sale_id = @sale.generate_invoice_from_booking(check_booking.id,current_login_employee)
# puts "current_login_employee"
# puts current_login_employee.name
@status, @sale_id = @sale.generate_invoice_from_booking(check_booking.id,current_login_employee, cashier = nil)
@sale_data = Sale.find_by_sale_id(@sale_id)
@sale_items = SaleItem.where("sale_id=?",@sale_id)
else
@@ -20,26 +20,26 @@ class Origami::RequestBillsController < BaseOrigamiController
@sale_items = SaleItem.where("sale_id=?",@sale_data.sale_id)
end
unique_code = "ReceiptBillPdf"
#shop detail
shop_details = Shop.find(1)
# customer= Customer.where('customer_id=' +.customer_id)
customer= Customer.find(@sale_data.customer_id)
# get member information
member_info = Customer.get_member_account(customer)
# get printer info
print_settings=PrintSetting.find_by_unique_code(unique_code)
# Not Use for these printed bill cannot give customer
# unique_code = "ReceiptBillPdf"
# #shop detail
# shop_details = Shop.find(1)
# # customer= Customer.where('customer_id=' +.customer_id)
# customer= Customer.find(@sale_data.customer_id)
# # get member information
# member_info = Customer.get_member_account(customer)
# # get printer info
# print_settings=PrintSetting.find_by_unique_code(unique_code)
# find order id by sale id
# sale_order = SaleOrder.find_by_sale_id(@sale_data.sale_id)
# # find order id by sale id
# # sale_order = SaleOrder.find_by_sale_id(@sale_data.sale_id)
# Calculate price_by_accounts
item_price_by_accounts = SaleItem.calculate_price_by_accounts(@sale_items)
# # Calculate price_by_accounts
# item_price_by_accounts = SaleItem.calculate_price_by_accounts(@sale_items)
# printer = Printer::ReceiptPrinter.new(print_settings)
printer = Printer::ReceiptPrinter.new(print_settings)
# printer.print_receipt_bill(print_settings,@sale_items,@sale_data,customer.name, item_price_by_accounts,member_info,shop_details)
# redirect_to origami_path(@sale_data.sale_id)
end
end

View File

@@ -18,6 +18,7 @@ class Origami::SaleEditController < BaseOrigamiController
@newsaleitem.save
@newsaleitem.qty = saleitemObj.qty * -1
@newsaleitem.price = saleitemObj.price * -1
@newsaleitem.is_taxable = 0
@newsaleitem.product_name = saleitemObj.product_name + " - void"
@newsaleitem.save
end