bill print format and tax fix

This commit is contained in:
Yan
2017-06-18 20:07:28 +06:30
parent 5906dde741
commit b65d127fd0
5 changed files with 56 additions and 42 deletions

View File

@@ -55,7 +55,7 @@ $(document).ready(function(){
var cashier=""; var cashier="";
var receipt_date=""; var receipt_date="";
var sub_total=0; var sub_total=0.0;
var discount_amount=0; var discount_amount=0;
var tax_amount=0; var tax_amount=0;
var grand_total_amount=0; var grand_total_amount=0;
@@ -69,11 +69,11 @@ $(document).ready(function(){
type: "POST", type: "POST",
url: "/origami/" + unique_id, url: "/origami/" + unique_id,
data: { 'booking_id' : unique_id }, data: { 'booking_id' : unique_id },
success:function(result){ success:function(result){
for (i = 0; i < result.length; i++) { for (i = 0; i < result.length; i++) {
var data = JSON.stringify(result[i]); var data = JSON.stringify(result[i]);
var parse_data = JSON.parse(data); var parse_data = JSON.parse(data);
var show_date = ""; var show_date = "";
// Receipt Header // Receipt Header
receipt_no = result[i].receipt_no; receipt_no = result[i].receipt_no;
@@ -81,36 +81,37 @@ $(document).ready(function(){
if(result[i].receipt_date != null){ if(result[i].receipt_date != null){
receipt_date = new Date(result[i].receipt_date); receipt_date = new Date(result[i].receipt_date);
show_date = receipt_date.getDate() + "-" + receipt_date.getMonth() + "-" + receipt_date.getFullYear() + ' ' + receipt_date.getHours()+ ':' + receipt_date.getMinutes() show_date = receipt_date.getDate() + "-" + receipt_date.getMonth() + "-" + receipt_date.getFullYear() + ' ' + receipt_date.getHours()+ ':' + receipt_date.getMinutes()
} }
$("#receipt_no").text(receipt_no);
$("#cashier").text(cashier == null ? "" : cashier);
$("#receipt_date").text(show_date);
//Receipt Charges //Receipt Charges
sub_total += (parse_data.qty*parse_data.price); sub_total += parseFloat(parse_data.price);
discount_amount = parse_data.discount_amount == null? '0.0' : parse_data.discount_amount; discount_amount = parse_data.discount_amount == null? '0.0' : parse_data.discount_amount;
tax_amount = parse_data.tax_amount; tax_amount = parse_data.tax_amount;
grand_total_amount = parse_data.grand_total_amount; grand_total_amount = parse_data.grand_total_amount;
$("#order-sub-total").text(sub_total);
// $("#order-food").text('');
// $("#order-beverage").text('');
$("#order-discount").text(discount_amount);
$("#order-Tax").text(tax_amount);
$("#order-grand-total").text(grand_total_amount);
// Ordered Items // Ordered Items
var order_items_rows = "<tr>" + var order_items_rows = "<tr>" +
"<td class='item-name'>" + parse_data.item_name + "</td>" + "<td class='item-name'>" + parse_data.item_name + "</td>" +
"<td class='item-attr'>" + parse_data.qty + "</td>" + "<td class='item-attr'>" + parse_data.qty + "</td>" +
"<td class='item-attr'>" + parse_data.qty*parse_data.price + "</td>" + "<td class='item-attr'>" + parse_data.price + "</td>" +
"</tr>"; "</tr>";
$("#order-items-table").children("tbody").append(order_items_rows); $("#order-items-table").children("tbody").append(order_items_rows);
} }
// Cashier Info
$("#receipt_no").text(receipt_no);
$("#cashier").text(cashier == null ? "" : cashier);
$("#receipt_date").text(show_date);
// Payment Info
$("#order-sub-total").text(sub_total);
// $("#order-food").text('');
// $("#order-beverage").text('');
$("#order-discount").text(discount_amount);
$("#order-Tax").text(tax_amount);
$("#order-grand-total").text(grand_total_amount);
} }
}); });
// End AJAX Call // End AJAX Call

View File

@@ -231,7 +231,7 @@ class Order < ApplicationRecord
.joins("left join orders on orders.order_id = booking_orders.order_id") .joins("left join orders on orders.order_id = booking_orders.order_id")
.joins("left join sales on sales.sale_id = bookings.sale_id") .joins("left join sales on sales.sale_id = bookings.sale_id")
.where("(orders.status = 'new' or orders.status = 'billed') and (dining_facilities.type=? and dining_facilities.is_active=?)",DiningFacility::TABLE_TYPE,true) .where("(orders.status = 'new' or orders.status = 'billed') and (dining_facilities.type=? and dining_facilities.is_active=?)",DiningFacility::TABLE_TYPE,true)
.group("bookings.booking_id,sales.receipt_no,orders.status,sales.sale_id,dining_facilities.name,orders.status,orders.order_id") .group("bookings.booking_id")
# For PG # For PG
# booking_orders.order_id IS NOT NULL and dining_facilities.type=? and dining_facilities.is_active=?",DiningFacility::TABLE_TYPE,true # booking_orders.order_id IS NOT NULL and dining_facilities.type=? and dining_facilities.is_active=?",DiningFacility::TABLE_TYPE,true
# sales.receipt_no,orders.status,sales.sale_id,dining_facilities.name,orders.status,orders.order_id # sales.receipt_no,orders.status,sales.sale_id,dining_facilities.name,orders.status,orders.order_id
@@ -262,7 +262,7 @@ class Order < ApplicationRecord
.joins("left join orders on orders.order_id = booking_orders.order_id") .joins("left join orders on orders.order_id = booking_orders.order_id")
.joins("left join sales on sales.sale_id = bookings.sale_id") .joins("left join sales on sales.sale_id = bookings.sale_id")
.where("(orders.status = 'new' or orders.status = 'billed') and (dining_facilities.type=? and dining_facilities.is_active=?)",DiningFacility::ROOM_TYPE,true) .where("(orders.status = 'new' or orders.status = 'billed') and (dining_facilities.type=? and dining_facilities.is_active=?)",DiningFacility::ROOM_TYPE,true)
.group("bookings.booking_id,sales.receipt_no,orders.status,sales.sale_id,dining_facilities.name,orders.customer_id,orders.order_id") .group("bookings.booking_id")
# For PG # For PG
# booking_orders.order_id IS NOT NULL and dining_facilities.type=? and dining_facilities.is_active=?",DiningFacility::ROOM_TYPE,true # booking_orders.order_id IS NOT NULL and dining_facilities.type=? and dining_facilities.is_active=?",DiningFacility::ROOM_TYPE,true
# sales.receipt_no,orders.status,sales.sale_id,dining_facilities.name,orders.customer_id,orders.order_id # sales.receipt_no,orders.status,sales.sale_id,dining_facilities.name,orders.customer_id,orders.order_id

View File

@@ -23,8 +23,7 @@ class Sale < ApplicationRecord
if (booking) if (booking)
Rails.logger.debug "Booking -> Booking Order Count -> " + booking.booking_orders.count.to_s Rails.logger.debug "Booking -> Booking Order Count -> " + booking.booking_orders.count.to_s
#get all order attached to this booking and combine into 1 invoice #get all order attached to this booking and combine into 1 invoice
puts booking.booking_orders.length
booking.booking_orders.each do |order| booking.booking_orders.each do |order|
if booking.sale_id if booking.sale_id
status, sale_id = generate_invoice_from_order(order.order_id, nil, booking, requested_by) status, sale_id = generate_invoice_from_order(order.order_id, nil, booking, requested_by)
@@ -90,6 +89,8 @@ class Sale < ApplicationRecord
order.save order.save
booking.sale_id = self.id booking.sale_id = self.id
booking.checkout_at = Time.now.utc
booking.checkout_by = requested_by.name
booking.save booking.save
return true, self.id return true, self.id
@@ -190,9 +191,14 @@ class Sale < ApplicationRecord
# Tax Calculate # Tax Calculate
def apply_tax(total_taxable) def apply_tax(total_taxable)
#if tax is not apply create new record
# self.sale_taxes.each do |existing_tax|
# #delete existing and create new
# existing_tax.delete
# end
#if tax is not apply create new record #if tax is not apply create new record
self.sale_taxes.each do |existing_tax| SaleTax.where("sale_id='#{self.sale_id}'").find_each do |existing_tax|
#delete existing and create new #delete existing and create new
existing_tax.delete existing_tax.delete
end end

View File

@@ -4,9 +4,9 @@ class ReceiptBillPdf < Prawn::Document
self.page_width = 210 self.page_width = 210
self.page_height = 2500 self.page_height = 2500
self.margin = 5 self.margin = 5
self.price_width = 35 self.price_width = 40
self.qty_width = 20 self.qty_width = 20
self.total_width = 35 self.total_width = 40
self.item_width = self.page_width - ((self.price_width + self.qty_width + self.total_width)) self.item_width = self.page_width - ((self.price_width + self.qty_width + self.total_width))
self.item_height = 15 self.item_height = 15
self.item_description_width = (self.page_width-20) / 2 self.item_description_width = (self.page_width-20) / 2
@@ -53,29 +53,36 @@ class ReceiptBillPdf < Prawn::Document
# move_down 2 # move_down 2
y_position = cursor y_position = cursor
bounding_box([0,y_position], :width =>self.label_width, :height => self.item_height) do bounding_box([0,y_position], :width =>self.label_width, :height => self.item_height) do
text "Receipt No:", :size => self.item_font_size,:align => :left text "Receipt No: #{sale_data.receipt_no}", :size => self.item_font_size,:align => :left
end end
bounding_box([self.label_width,y_position], :width => self.label_width, :height => self.item_height) do
bounding_box([self.label_width, y_position], :width =>self.item_width) do text "#{ sale_data.bookings[0].dining_facility.name }" , :size => self.item_font_size,:align => :right
text "#{sale_data.receipt_no}" , :size => self.item_font_size, :align => :left
end end
move_down 5 move_down 5
y_position = cursor y_position = cursor
bounding_box([0,y_position], :width =>self.label_width, :height => self.item_height) do bounding_box([0, y_position], :width =>self.item_width) do
text "Customer:", :size => self.item_font_size,:align => :left text "Waiter: #{sale_data.requested_by}" , :size => self.item_font_size, :align => :left
end end
bounding_box([self.label_width,y_position], :width =>self.item_width) do move_down 5
text "#{customer_name}" , :size => self.item_font_size,:align => :left
y_position = cursor
bounding_box([0,y_position], :width =>self.item_width, :height => self.item_height) do
text "Cashier: #{sale_data.cashier_name}", :size => self.item_font_size,:align => :left
end end
move_down 5 move_down 5
# bounding_box([self.label_width,y_position], :width =>self.item_width) do
# text "#{customer_name}" , :size => self.item_font_size,:align => :left
# end
# move_down 5
y_position = cursor y_position = cursor
bounding_box([0,y_position], :width =>self.label_width, :height => self.item_height) do bounding_box([0,y_position], :width =>self.label_width, :height => self.item_height) do
text "Date:", :size => self.item_font_size,:align => :left text "Time In: #{ sale_data.bookings[0].checkin_at.strftime('%I:%M %p') }", :size => self.item_font_size,:align => :left
end end
bounding_box([self.label_width,y_position], :width => self.item_width) do bounding_box([self.label_width,y_position], :width => self.label_width, :height => self.item_height) do
text "#{sale_data.receipt_date.strftime('%Y-%m-%d %I:%M %p')}" , :size => self.item_font_size,:align => :left text "Time Out: #{ sale_data.bookings[0].checkout_at.strftime('%I:%M %p') }" , :size => self.item_font_size,:align => :right
end end
move_down 5 move_down 5
@@ -118,7 +125,7 @@ class ReceiptBillPdf < Prawn::Document
y_position = cursor y_position = cursor
pad_top(15) { pad_top(15) {
text_box "#{product_name}", :at =>[0,y_position], :width => self.item_width, :height =>self.item_height, :overflow => :shrink_to_fix, :size => self.item_font_size, :overflow => :shrink_to_fix 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 "#{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 "#{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 "#{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),y_position], :width =>self.total_width+5, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix text_box "#{total_price}", :at =>[(item_name_width),y_position], :width =>self.total_width+5, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix
@@ -163,7 +170,7 @@ class ReceiptBillPdf < Prawn::Document
text "( " +"#{sale_data.total_discount}" +" )" , :size => self.item_font_size,:align => :right text "( " +"#{sale_data.total_discount}" +" )" , :size => self.item_font_size,:align => :right
end end
if sale_data.sale_taxes.length > 1 if sale_data.sale_taxes.length > 0
sale_data.sale_taxes.each do |st| sale_data.sale_taxes.each do |st|
move_down 5 move_down 5
y_position = cursor y_position = cursor

View File

@@ -306,12 +306,12 @@
sub_total = 0 sub_total = 0
if @selected_item_type == "Sale" if @selected_item_type == "Sale"
@selected_item.sale_items.each do |sale_item| @selected_item.sale_items.each do |sale_item|
sub_total += (sale_item.qty*sale_item.unit_price) sub_total = sub_total + sale_item.price
%> %>
<tr> <tr>
<td class='item-name'><%= sale_item.product_name %></td> <td class='item-name'><%= sale_item.product_name %></td>
<td class='item-attr'><%= sale_item.qty %></td> <td class='item-attr'><%= sale_item.qty %></td>
<td class='item-attr'><%= sale_item.qty*sale_item.price %></td> <td class='item-attr'><%= sale_item.price %></td>
</tr> </tr>
<% <%
end end
@@ -322,7 +322,7 @@
# For Order Items # For Order Items
if @selected_item_type == "Order" if @selected_item_type == "Order"
@selected_item.order_items.each do |order_item| @selected_item.order_items.each do |order_item|
sub_total += (order_item.qty*order_item.unit_price) sub_total = sub_total + (order_item.qty*order_item.price)
%> %>
<tr> <tr>
<td class='item-name'><%= order_item.item_name %></td> <td class='item-name'><%= order_item.item_name %></td>