fix discount and receipt bill

This commit is contained in:
Yan
2017-07-21 18:15:10 +06:30
parent 2e8c866761
commit b8fc67745d
3 changed files with 55 additions and 49 deletions

View File

@@ -97,13 +97,14 @@ class Origami::DiscountsController < BaseOrigamiController
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
table_type = DiningFacility.find(table_id).type
discount_items = []
#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
sale.sale_items.each do |si|
if si.remark == "Discount" && si.price < 0
sale.total_amount = (sale.total_amount + si.price.abs)
discount_items.push(si)
end
end
@@ -111,6 +112,9 @@ class Origami::DiscountsController < BaseOrigamiController
# sale.grand_total = (sale.total_amount - sale.total_discount) + sale.total_tax;
# sale.save
#destroy in sale.sale_items
sale.sale_items.destroy(discount_items)
# Re-calc All Amount in Sale
sale.compute_by_sale_items(sale_id, sale.sale_items, 0)
result = {:status=> "Success", :table_id => table_id, :table_type => table_type }
@@ -139,7 +143,6 @@ class Origami::DiscountsController < BaseOrigamiController
arr.push(str)
end
end
end
generic_customer_id = sale.customer.membership_id

View File

@@ -1,6 +1,6 @@
class ReceiptBillPdf < Prawn::Document
include ActionView::Helpers::NumberHelper
attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width
attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width, :description_width, :price_num_width
def initialize(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info = nil,rebate_amount = nil,shop_details, printed_status)
self.page_width = 210
self.page_height = 7000
@@ -12,6 +12,9 @@ class ReceiptBillPdf < Prawn::Document
self.item_height = 15
self.item_description_width = (self.page_width-20) / 2
self.label_width = 100
self.description_width = 150
self.price_num_width = 50
# @item_width = self.page_width.to_i / 2
# @qty_width = @item_width.to_i / 3
# @double = @qty_width * 1.3
@@ -73,10 +76,10 @@ class ReceiptBillPdf < Prawn::Document
move_down 7
# move_down 2
y_position = cursor
bounding_box([0,y_position], :width =>self.label_width, :height => self.item_height) do
bounding_box([0,y_position], :width =>self.description_width, :height => self.item_height) do
text "Receipt No: #{sale_data.receipt_no}", :size => self.item_font_size,:align => :left
end
bounding_box([self.label_width,y_position], :width => self.label_width, :height => self.item_height) do
bounding_box([self.description_width,y_position], :width => self.price_num_width, :height => self.item_height) do
text "#{ sale_data.bookings[0].dining_facility.type } - #{ sale_data.bookings[0].dining_facility.name }" , :size => self.item_font_size,:align => :right
end
move_down 5
@@ -140,7 +143,7 @@ class ReceiptBillPdf < Prawn::Document
y_position = cursor
pad_top(15) {
text_box "#{product_name}", :at =>[0,y_position], :width => self.item_width, :size => self.item_font_size, :overflow => :shrink_to_fix
text_box "#{product_name}", :at =>[0,y_position], :width => self.item_width, :size => self.item_font_size , :overflow => :expand
text_box "#{number_with_precision(price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[self.item_width,y_position], :width => self.price_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix
text_box "#{number_with_precision(qty, :precision => precision.to_i)}", :at =>[item_name_width,y_position], :width => self.qty_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix
text_box "#{number_with_precision(total_price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[(item_name_width+4),y_position], :width =>self.total_width+3, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix