merge with crm

This commit is contained in:
Yan
2017-06-29 13:40:30 +06:30
54 changed files with 294 additions and 1058 deletions

View File

@@ -1,6 +1,6 @@
class OrderItemPdf < Prawn::Document
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
def initialize(order_item, print_status, options)
def initialize(print_settings,order_item, print_status, options, alt_name)
self.page_width = 210
self.page_height = 1450
self.margin = 5
@@ -12,12 +12,13 @@ class OrderItemPdf < Prawn::Document
self.item_description_width = self.page_width - (self.price_width + self.qty_width + self.total_width)
self.label_width=100
super(:margin => [self.margin, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height])
super(:margin => [print_settings.heading_space, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height])
# super(:margin => [10, 5, 30, 5], :page_size => [200,400])
# font "public/fonts/#{font_name}".to_s + ".ttf".to_s
# font "public/fonts/Zawgyi-One.ttf"
# font "public/fonts/padauk.ttf"
# font "public/fonts/#{font_name}".to_s + ".ttf".to_s
# font "public/fonts/Zawgyi-One.ttf"
# font "public/fonts/padauk.ttf"
#font "public/fonts/Chinese.ttf"
self.header_font_size = 12
self.item_font_size = 10
@@ -29,7 +30,7 @@ class OrderItemPdf < Prawn::Document
order_info(order_item.order_id, order_item.order_by,order_item.order_at)
# order items
order_items(order_item, options)
order_items(order_item, options, alt_name)
end
# Write Order Information to PDF
@@ -57,11 +58,11 @@ class OrderItemPdf < Prawn::Document
end
# Write Order items to PDF
def order_items(order_item, options)
def order_items(order_item, options, alt_name)
y_position = cursor
#Add Order Item
add_order_items(order_item, options)
add_order_items(order_item, options, alt_name)
dash(1, :space => 1, :phase => 1)
stroke_horizontal_line 0, (self.page_width - self.margin)
@@ -69,19 +70,31 @@ class OrderItemPdf < Prawn::Document
end
# Add order items under order info
def add_order_items(order_item, options)
def add_order_items(order_item, options, alt_name)
y_position = cursor
move_down 5
bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do
bounding_box([0,y_position], :width => self.item_width) do
text "#{order_item.item_name}", :size => self.item_font_size,:align => :left
end
bounding_box([self.item_width,y_position], :width => self.qty_width, :height => self.item_height) do
bounding_box([self.item_width,y_position], :width => self.qty_width) do
text "[#{order_item.qty.to_i}]", :size => self.item_font_size,:align => :left
end
bounding_box([0,y_position], :width => self.item_width) do
text "#{order_item.item_name}", :size => self.item_font_size,:align => :left
end
if alt_name
move_down 4
font("public/fonts/Chinese.ttf") do
text "(#{order_item.alt_name})", :size => self.item_font_size,:align => :left, :inline_format => true
end
end
move_down 5
# add option

View File

@@ -1,6 +1,6 @@
class OrderSummaryPdf < Prawn::Document
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
def initialize(order, print_status, order_items = nil)
def initialize(print_settings,order, print_status, order_items = nil,alt_name)
self.page_width = 210
self.page_height = 1450
self.margin = 5
@@ -12,11 +12,11 @@ class OrderSummaryPdf < Prawn::Document
self.item_description_width = self.page_width - (self.price_width + self.qty_width + self.total_width)
self.label_width=100
super(:margin => [self.margin, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height])
super(:margin => [print_settings.heading_space, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height])
# font "public/fonts/#{font_name}".to_s + ".ttf".to_s
# font "public/fonts/Zawgyi-One.ttf"
# font "public/fonts/padauk.ttf"
font "public/fonts/padauk.ttf"
self.header_font_size = 12
self.item_font_size = 10
@@ -29,9 +29,9 @@ class OrderSummaryPdf < Prawn::Document
# order items
if order_items == nil
order_items(order)
order_items(order, alt_name)
else
order_items(order_items)
order_items(order_items, alt_name)
end
end
@@ -60,7 +60,7 @@ class OrderSummaryPdf < Prawn::Document
end
# Write Order items to PDF
def order_items(order_item)
def order_items(order_item, alt_name)
y_position = cursor
bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do
@@ -75,12 +75,12 @@ class OrderSummaryPdf < Prawn::Document
move_down 5
#Add Order Item
add_order_items(order_item)
add_order_items(order_item, alt_name)
end
# Add order items under order info
def add_order_items(order_item)
def add_order_items(order_item, alt_name)
y_position = cursor
move_down 5
@@ -92,12 +92,26 @@ class OrderSummaryPdf < Prawn::Document
bounding_box([0,y_position], :width => self.item_width) do
text "#{odi.item_name}", :size => self.item_font_size,:align => :left
end
bounding_box([self.item_width,y_position], :width => self.qty_width) do
text "#{odi.qty}", :size => self.item_font_size,:align => :left
end
bounding_box([0,y_position], :width => self.item_width) do
text "#{odi.item_name}", :size => self.item_font_size,:align => :left
end
if alt_name
move_down 4
font("public/fonts/Chinese.ttf") do
text "(#{odi.alt_name})", :size => self.item_font_size,:align => :left, :inline_format => true
end
end
move_down 5
# add option

View File

@@ -1,4 +1,5 @@
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
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)
self.page_width = 210
@@ -16,7 +17,7 @@ class ReceiptBillPdf < Prawn::Document
# @double = @qty_width * 1.3
# @half_qty = @qty_width / 2
#setting page margin and width
super(:margin => [self.margin, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height])
super(:margin => [printer_settings.heading_space, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height])
# font "public/fonts/#{font_name}".to_s + ".ttf".to_s
# font "public/fonts/Zawgyi-One.ttf"
@@ -24,26 +25,33 @@ class ReceiptBillPdf < Prawn::Document
self.header_font_size = 10
self.item_font_size = 8
if printer_settings.delimiter
delimiter = ","
else
delimiter = ""
end
header( shop_details)
stroke_horizontal_rule
cashier_info(sale_data, customer_name)
line_items(sale_items)
all_total(sale_data)
line_items(sale_items,printer_settings.precision,delimiter)
all_total(sale_data,printer_settings.precision,delimiter)
if member_info != nil
member_info(member_info,customer_name,rebate_amount,sale_data)
member_info(member_info,customer_name,rebate_amount,sale_data,printer_settings.precision,delimiter)
end
customer(customer_name)
if discount_price_by_accounts.length > 0
discount_account(discount_price_by_accounts)
discount_account(discount_price_by_accounts,printer_settings.precision,delimiter)
end
items_account(item_price_by_accounts)
items_account(item_price_by_accounts,printer_settings.precision,delimiter)
footer
end
@@ -87,7 +95,7 @@ class ReceiptBillPdf < Prawn::Document
y_position = cursor
bounding_box([0,y_position], :width =>self.page_width - 10, :height => self.item_height) do
text "Receipt Date : #{ sale_data.receipt_date.strftime('%d-%m-%Y') } ( #{ sale_data.bookings[0].checkin_at.utc.getlocal.strftime('%I:%M %p') } - #{ sale_data.bookings[0].checkin_at.utc.getlocal.strftime('%I:%M %p') } )",:size => self.item_font_size,:align => :left
text "Receipt Date : #{ sale_data.receipt_date.strftime('%d-%m-%Y') } ( #{ sale_data.bookings[0].checkin_at.utc.getlocal.strftime('%I:%M %p') } - #{ sale_data.bookings[0].checkout_at.utc.getlocal.strftime('%I:%M %p') } )",:size => self.item_font_size,:align => :left
end
@@ -101,7 +109,7 @@ class ReceiptBillPdf < Prawn::Document
stroke_horizontal_rule
end
def line_items(sale_items)
def line_items(sale_items,precision,delimiter)
move_down 5
y_position = cursor
move_down 5
@@ -114,10 +122,10 @@ class ReceiptBillPdf < Prawn::Document
}
move_down -5
stroke_horizontal_rule
add_line_item_row(sale_items)
add_line_item_row(sale_items,precision,delimiter)
end
def add_line_item_row(sale_items)
def add_line_item_row(sale_items,precision,delimiter)
item_name_width = (self.item_width+self.price_width)
y_position = cursor
move_down 5
@@ -136,9 +144,9 @@ class ReceiptBillPdf < Prawn::Document
pad_top(15) {
text_box "#{product_name}", :at =>[0,y_position], :width => self.item_width, :height =>self.item_height, :size => self.item_font_size, :overflow => :shrink_to_fix
text_box "#{price}", :at =>[self.item_width,y_position], :width => self.price_width, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix
text_box "#{number_with_precision(price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[self.item_width,y_position], :width => self.price_width, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix
text_box "#{qty}", :at =>[item_name_width,y_position], :width => self.qty_width, :height =>self.item_height, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix
text_box "#{total_price}", :at =>[(item_name_width+4),y_position], :width =>self.total_width+3, :height =>self.item_height, :size => self.item_font_size, :align => :right, :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, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix
}
move_down 1
end
@@ -152,12 +160,12 @@ class ReceiptBillPdf < Prawn::Document
text "Sub Total", :size => self.item_font_size,:align => :left
end
bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
text "#{ sub_total }" , :size => self.item_font_size,:align => :right
end
text "#{number_with_precision(sub_total, :precision => precision.to_i, :delimiter => delimiter)}" ,:delimiter => ',', :size => self.item_font_size,:align => :right
end
move_down 5
end
def all_total(sale_data)
def all_total(sale_data,precision,delimiter)
item_name_width = self.item_width
y_position = cursor
@@ -165,7 +173,7 @@ class ReceiptBillPdf < Prawn::Document
text "Overall Discount", :size => self.item_font_size,:align => :left
end
bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
text "( " +"#{sale_data.total_discount}" +" )" , :size => self.item_font_size,:align => :right
text "( #{number_with_precision(sale_data.total_discount, :precision => precision.to_i, :delimiter => delimiter)} )" , :size => self.item_font_size,:align => :right
end
if sale_data.sale_taxes.length > 0
@@ -177,7 +185,7 @@ class ReceiptBillPdf < Prawn::Document
text "#{ st.tax_name }", :size => self.item_font_size,:align => :left
end
bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
text "#{ st.tax_payable_amount }" , :size => self.item_font_size,:align => :right
text "#{number_with_precision(st.tax_payable_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right
end
end
else
@@ -198,18 +206,18 @@ class ReceiptBillPdf < Prawn::Document
y_position = cursor
move_down 5
bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
text "Grand Total", :size => self.header_font_size,:align => :left
text "Grand Total",:style => :bold, :size => self.header_font_size,:align => :left
end
bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
text "#{sale_data.grand_total}" , :size => self.header_font_size,:align => :right
text "#{number_with_precision(sale_data.grand_total, :precision => precision.to_i, :delimiter => delimiter)}" , :style => :bold, :size => self.header_font_size,:align => :right
end
move_down 5
sale_payment(sale_data)
sale_payment(sale_data,precision,delimiter)
end
def sale_payment(sale_data)
def sale_payment(sale_data,precision,delimiter)
stroke_horizontal_rule
move_down 5
@@ -220,7 +228,7 @@ class ReceiptBillPdf < Prawn::Document
text "#{payment.payment_method.capitalize} Payment", :size => self.item_font_size,:align => :left
end
bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
text "#{ payment.payment_amount }" , :size => self.item_font_size,:align => :right
text "#{number_with_precision(payment.payment_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right
end
move_down 5
end
@@ -231,7 +239,7 @@ class ReceiptBillPdf < Prawn::Document
text "Change Amount", :size => self.item_font_size,:align => :left
end
bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
text "#{sale_data.amount_changed}" , :size => self.item_font_size,:align => :right
text "#{number_with_precision(sale_data.amount_changed, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right
end
move_down 5
end
@@ -239,7 +247,7 @@ class ReceiptBillPdf < Prawn::Document
end
# show member information
def member_info(member_info,customer_name,rebate_amount,sale_data)
def member_info(member_info,customer_name,rebate_amount,sale_data,precision,delimiter)
if rebate_amount != nil
@@ -255,7 +263,7 @@ class ReceiptBillPdf < Prawn::Document
text "Current Rebate Amount", :size => self.item_font_size,:align => :left
end
bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
text "#{ res["rebate"] }" , :size => self.item_font_size,:align => :right
text "#{number_with_precision(res["rebate"], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right
end
end
if res["receipt_no"]== sale_data.receipt_no && res["status"]== "Redeem"
@@ -266,15 +274,15 @@ class ReceiptBillPdf < Prawn::Document
text "Current Redeem Amount", :size => self.item_font_size,:align => :left
end
bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
text "(#{ res["redeem"] })" , :size => self.item_font_size,:align => :right
text "#{number_with_precision(res["redeem"], :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right
end
end
end
end
end
if member_info["status"] == true
balance = 0.0
if member_info["status"] == true && member_info["data"].present?
balance = 0
member_info["data"].each do |res|
if res["accountable_type"] == "RebateAccount" || res["accountable_type"] == "RebatebonusAccount"
@@ -289,7 +297,7 @@ class ReceiptBillPdf < Prawn::Document
text "Current Balance", :size => self.item_font_size,:align => :left
end
bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
text "#{ balance }" , :size => self.item_font_size,:align => :right
text "#{number_with_precision(balance, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right
end
end
@@ -305,8 +313,7 @@ class ReceiptBillPdf < Prawn::Document
text "#{ customer_name }" , :size => self.item_font_size,:align => :right
end
end
def discount_account(discount_price_by_accounts)
def discount_account(discount_price_by_accounts,precision,delimiter)
move_down 5
stroke_horizontal_rule
move_down 5
@@ -317,12 +324,12 @@ class ReceiptBillPdf < Prawn::Document
text "#{ 'Total ' + ipa[:name] + ' Discounts' }", :size => self.item_font_size,:align => :left
end
bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
text "(" + "#{ ipa[:price] }" + ")" , :size => self.item_font_size,:align => :right
text "(" + "#{ number_with_precision(ipa[:price], :precision => precision.to_i, :delimiter => delimiter) }" + ")" , :size => self.item_font_size,:align => :right
end
end
end
def items_account(item_price_by_accounts)
def items_account(item_price_by_accounts,precision,delimiter)
move_down 5
stroke_horizontal_rule
move_down 5
@@ -333,7 +340,7 @@ class ReceiptBillPdf < Prawn::Document
text "#{ ipa[:name] }", :size => self.item_font_size,:align => :left
end
bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
text "#{ ipa[:price] }" , :size => self.item_font_size,:align => :right
text "#{number_with_precision(ipa[:price], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right
end
end
end