From 03feae5b0f772cca25e6945e1524d9048547e384 Mon Sep 17 00:00:00 2001 From: Yan Date: Thu, 15 Jun 2017 17:57:58 +0630 Subject: [PATCH] fix get_order_items_details method in order_item and add taxes in receipt --- app/assets/javascripts/origami.js | 3 +- .../origami/discounts_controller.rb | 4 ++- app/models/order_item.rb | 32 +++++++++++------- app/models/sale.rb | 1 + app/pdf/receipt_bill_pdf.rb | 30 ++++++++++++---- dump.rdb | Bin 18306 -> 18288 bytes 6 files changed, 48 insertions(+), 22 deletions(-) diff --git a/app/assets/javascripts/origami.js b/app/assets/javascripts/origami.js index 87b74809..b1dc732d 100644 --- a/app/assets/javascripts/origami.js +++ b/app/assets/javascripts/origami.js @@ -157,10 +157,11 @@ $(document).ready(function(){ if(sale_item_id != null){ ajax_url = "/origami/" + sale_item_id + "/discount"; + sub_total = $("#"+sale_item_id).children().find("#item-total-price").text(); } // For Percentage Discount - if(discount_type == 1){ + if(discount_type == 1){ discount_amount=(sub_total*discount_value)/100; } diff --git a/app/controllers/origami/discounts_controller.rb b/app/controllers/origami/discounts_controller.rb index fb981a80..f5f7db9e 100644 --- a/app/controllers/origami/discounts_controller.rb +++ b/app/controllers/origami/discounts_controller.rb @@ -16,6 +16,7 @@ class Origami::DiscountsController < BaseOrigamiController discount_value = params[:discount_value] discount_amount = params[:discount_amount] grand_total = params[:grand_total] + product_name = "Overall Discount" if discount_type == 0 remark="Discount " + discount_amount + " as net" @@ -32,13 +33,14 @@ class Origami::DiscountsController < BaseOrigamiController #save sale item for discount if sale_item_id != nil origin_sale_item = SaleItem.find(sale_item_id) + product_name = origin_sale_item.product_name + "-Disocunt" end sale_item = SaleItem.new #pull sale_item.sale_id = sale_id sale_item.product_code = origin_sale_item != nil ? origin_sale_item.product_code : sale_id - sale_item.product_name = "Overall Discount" + sale_item.product_name = product_name sale_item.remark = remark sale_item.qty = 1 diff --git a/app/models/order_item.rb b/app/models/order_item.rb index a85d1113..564aa939 100644 --- a/app/models/order_item.rb +++ b/app/models/order_item.rb @@ -35,23 +35,29 @@ class OrderItem < ApplicationRecord #logger.debug orderitem.to_yml orderitem.save! - - end - #Origami : Cashier : to show order items details + #Origami : Cashier : to show order items details def self.get_order_items_details(booking_id) - booking_orders = BookingOrder.where("booking_id=?",booking_id) - if booking_orders - booking_orders.each do |book_order| - order_details = OrderItem.select("order_items.item_name,order_items.qty,order_items.price,(order_items.qty*order_items.price) as total_price") + # booking_orders = BookingOrder.where("booking_id=?",booking.booking_id) + # if booking_orders + # booking_orders.each do |book_order| + # order_details = OrderItem.select("order_items.item_name,order_items.qty,order_items.price,(order_items.qty*order_items.price) as total_price") + # .joins("left join orders on orders.order_id = order_items.order_id") + # .where("order_items.order_id=?",book_order.order) + # return order_details + # end + # else + # return false + # end + + order_details = OrderItem.select("order_items.item_name,order_items.qty,order_items.price,(order_items.qty*order_items.price) as total_price") .joins("left join orders on orders.order_id = order_items.order_id") - .where("order_items.order_id=?",book_order.order) - return order_details - end - else - return false - end + .joins("left join booking_orders on booking_orders.order_id = order_items.order_id") + .joins("left join bookings on bookings.booking_id = booking_orders.booking_id") + .where("bookings.booking_id=?",booking_id) + + return order_details end private diff --git a/app/models/sale.rb b/app/models/sale.rb index dee4c2f7..9683c2b2 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -186,6 +186,7 @@ class Sale < ApplicationRecord end + # Tax Calculate def apply_tax(total_taxable) #if tax is not apply create new record diff --git a/app/pdf/receipt_bill_pdf.rb b/app/pdf/receipt_bill_pdf.rb index 71562277..9d5742d6 100644 --- a/app/pdf/receipt_bill_pdf.rb +++ b/app/pdf/receipt_bill_pdf.rb @@ -165,16 +165,32 @@ class ReceiptBillPdf < Prawn::Document text "( " +"#{sale_data.total_discount}" +" )" , :size => self.item_font_size,:align => :right end - move_down 5 - y_position = cursor + if sale_data.sale_taxes.length > 1 + sale_data.sale_taxes.each do |st| + move_down 5 + y_position = cursor + + bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do + 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 + end + end + else - bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do - text "Total Tax", :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_tax}" +" )" , :size => self.item_font_size,:align => :right end + # move_down 5 + # y_position = cursor + + # bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do + # text "Total Tax", :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_tax}" +" )" , :size => self.item_font_size,:align => :right + # end + move_down 5 y_position = cursor move_down 5 diff --git a/dump.rdb b/dump.rdb index c3cd28258559f24367e082ffa37d6e43dc715137..859ccbd44566f00e49a2d0a844ce85ffed07e276 100644 GIT binary patch delta 914 zcmbu7OH30%9L9H8S{m@tLbL{=EEg(4)}5W1on4`%Ee7I2qQr}dmR4G{2`xfP^nxkE z!FW*X9Jok;XuSGZG;%9cLmEvqXyPMLn|Q&*M0_N^5_MWAc=tM){J-z}ec#!OVEF>L zq--mV`40cI4aLKurf4`i|NTdm@LTxh0IapcndM-(%)(b)u4=!p+Q3xD&mP? zVoz@{(iaZRIoTqJfhFcGsRlR9BPAa#po+0Y2m36&%^iQCxC z7H9KV`l?8DVt7Ua%cb2t{X;QNMu17X5XphvIbp_15yF}}TnVv338EC~vccap1)A>i zcNX!Dub^X2RQg5pvvbKJzVIC@C||cf+OMiqH)N<16+t9P<%5I$gWb_^JRUsm8Qa*_ zKhzhBxe`)uBo>l_TA6ezk~kr``n|(-3UIk|wrA<~x#-CIlCE%%gxK^JC%v2lw@ZnJ zF`O1acaOBo^K`1=t&Du&ij7jcm=@MGl2X^;Q{T1rh9F zNylDxud15ebvhaY_g4|5XRJsi9Qf)@4N-nG|HM&byw80>o^_06(ZYcOWs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