From ebaf4ad418c8d09c572d4595cf5f7bf9dd6a247a Mon Sep 17 00:00:00 2001 From: San Wai Lwin Date: Thu, 5 Jul 2018 15:29:33 +0630 Subject: [PATCH 1/8] Add Account Filture --- app/assets/stylesheets/application.scss | 4 ++++ app/controllers/reports/saleitem_controller.rb | 6 ++++-- app/models/sale.rb | 17 ++++++++++++----- .../saleitem/_shift_sale_report_filter.html.erb | 16 ++++++++++++++-- 4 files changed, 34 insertions(+), 9 deletions(-) diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 15e8a986..639a763b 100755 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -103,4 +103,8 @@ i.logout_icon{ /* Second display image */ .second-display{ margin : 12px; +} + +.float_right{ + float : right; } \ No newline at end of file diff --git a/app/controllers/reports/saleitem_controller.rb b/app/controllers/reports/saleitem_controller.rb index c49ba894..aff7f3c2 100755 --- a/app/controllers/reports/saleitem_controller.rb +++ b/app/controllers/reports/saleitem_controller.rb @@ -1,7 +1,8 @@ class Reports::SaleitemController < BaseReportController authorize_resource :class => false def index - + + @account = Account.all from, to = get_date_range_from_params shift_sale_range = '' @@ -23,8 +24,9 @@ class Reports::SaleitemController < BaseReportController end end + account_type = params[:account_type] @type = params[:sale_type] - @sale_data, @other_charges,@product, @discount_data , @cash_data , @card_data , @credit_data , @foc_data , @grand_total , @change_amount = Sale.get_by_shift_items(shift_sale_range,shift, from, to, Sale::SALE_STATUS_COMPLETED,@type) + @sale_data, @other_charges,@product, @discount_data , @cash_data , @card_data , @credit_data , @foc_data , @grand_total , @change_amount = Sale.get_by_shift_items(shift_sale_range,shift, from, to, Sale::SALE_STATUS_COMPLETED,@type,account_type) @sale_taxes = Sale.get_separate_tax(shift_sale_range,shift,from,to,nil) diff --git a/app/models/sale.rb b/app/models/sale.rb index 33c7f1b6..262e487d 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -911,9 +911,14 @@ def self.get_other_charges() query = query.group("i.sale_item_id") end -def self.get_by_shift_items(shift_sale_range, shift, from, to, status,type) +def self.get_by_shift_items(shift_sale_range, shift, from, to, status,type,account_type) # date_type_selection = get_sql_function_for_report_type(report_type) - + if account_type.blank? + account_type = '' + else + account_type = " and acc.title = '#{account_type}'" + end + query = self.get_item_query(type) discount_query = 0 @@ -929,7 +934,7 @@ def self.get_by_shift_items(shift_sale_range, shift, from, to, status,type) product = self.get_product_sale() if shift.present? - query = query.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift.to_a) + query = query.where("sales.shift_sale_id IN (?) #{account_type} and sale_status='completed'",shift.to_a) if type.nil? || type == 'all' || type == "other" other_charges = other_charges.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift.to_a) end @@ -952,7 +957,7 @@ def self.get_by_shift_items(shift_sale_range, shift, from, to, status,type) ### => get all sales range in shift_sales elsif shift_sale_range.present? - query = query.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift_sale_range.to_a) + query = query.where("sales.shift_sale_id IN (?) #{account_type} and sale_status='completed'",shift_sale_range.to_a) if type.nil? || type == 'all' || type == "other" other_charges = other_charges.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift_sale_range.to_a) end @@ -975,11 +980,13 @@ def self.get_by_shift_items(shift_sale_range, shift, from, to, status,type) total_grand_total = total_cash_amount.to_f + total_card_amount.to_f + total_credit_amount.to_f else - query = query.where("sales.receipt_date between ? and ? and sale_status='completed'",from,to) + query = query.where("sales.receipt_date between ? and ? #{account_type} and sale_status='completed'",from,to) + if type.nil? || type == 'all' || type == "other" other_charges = other_charges.where("sales.receipt_date between ? and ? and sale_status='completed'",from,to) end product = product.where("sales.receipt_date between ? and ? and sale_status='completed'",from,to) + discount_query = Sale.where("sales.receipt_date between ? and ? and sale_status ='completed'", from,to).sum(:total_discount) change_amount = Sale.where("sales.receipt_date between ? and ? and sale_status ='completed'", from,to).sum(:amount_changed) sale_cash = Sale.select("SUM(case when (sale_payments.payment_method = 'mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' or sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay' or sale_payments.payment_method = 'giftvoucher') then (sale_payments.payment_amount) else 0 end) as card_amount, diff --git a/app/views/reports/saleitem/_shift_sale_report_filter.html.erb b/app/views/reports/saleitem/_shift_sale_report_filter.html.erb index d1a3ec5b..65df7aea 100755 --- a/app/views/reports/saleitem/_shift_sale_report_filter.html.erb +++ b/app/views/reports/saleitem/_shift_sale_report_filter.html.erb @@ -32,6 +32,16 @@ +
+ + + +
@@ -46,9 +56,9 @@
-
+

- +
<% end %> @@ -70,6 +80,8 @@ var item = $('#item').val(); var payment_type = $('#payment_type'); + $("#account_type").val("<%=params[:account_type]%>"); + if(item == 'order'){ $('#cashier').hide(); $('#waiter').show(); From e5eb9b90adaede61cdac29d7d0d42f7c19483704 Mon Sep 17 00:00:00 2001 From: San Wai Lwin Date: Thu, 5 Jul 2018 15:42:58 +0630 Subject: [PATCH 2/8] Pull from master --- app/controllers/home_controller.rb | 1 + app/controllers/origami/home_controller.rb | 4 +- .../origami/payments_controller.rb | 38 +++++++--------- app/controllers/origami/shifts_controller.rb | 15 ++++--- app/models/assigned_order_item.rb | 18 ++++---- app/models/order.rb | 18 ++++---- app/models/sale.rb | 14 +++--- app/models/sale_order.rb | 12 ++--- app/models/sale_payment.rb | 15 ++++--- app/pdf/receipt_bill_pdf.rb | 2 +- app/views/layouts/login_dashboard.html.erb | 45 +++---------------- 11 files changed, 78 insertions(+), 104 deletions(-) diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 09d6671e..4e0e89f3 100755 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -20,6 +20,7 @@ class HomeController < ApplicationController def index # @employees = Employee.all_emp_except_waiter.order("name asc") @employees = Employee.all.where("is_active = true").order("name asc") + @roles = Lookup.collection_of("employee_roles") @login_form = LoginForm.new() render "layouts/login_dashboard", layout: false end diff --git a/app/controllers/origami/home_controller.rb b/app/controllers/origami/home_controller.rb index 2d03d298..1cd6505d 100755 --- a/app/controllers/origami/home_controller.rb +++ b/app/controllers/origami/home_controller.rb @@ -8,7 +8,7 @@ class Origami::HomeController < BaseOrigamiController @rooms = Room.unscoped.all.active.order('status desc') @complete = Sale.where("DATE_FORMAT(created_at,'%Y-%m-%d') = ? and sale_status != 'new'",DateTime.now.strftime('%Y-%m-%d')) @orders = Order.includes("sale_orders").where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc') - @shop = Shop.first + @shop = shop_detail # @shift = ShiftSale.current_open_shift(current_user.id) end @@ -26,7 +26,7 @@ class Origami::HomeController < BaseOrigamiController @status_sale = "" @sale_array = Array.new - @shop = Shop.first + @shop = shop_detail @membership = MembershipSetting::MembershipSetting @payment_methods = PaymentMethodSetting.all @dining_booking = @dining.bookings.active.where("DATE_FORMAT(created_at,'%Y-%m-%d') = '#{DateTime.now.strftime('%Y-%m-%d')}' OR DATE_FORMAT(created_at,'%Y-%m-%d') = '#{Date.today.prev_day}' ") diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index 4bd7ff59..2ca8b45a 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -44,11 +44,11 @@ class Origami::PaymentsController < BaseOrigamiController end #shop detail - shop_details = Shop.first + ## shop_detail = Shop.first # customer= Customer.where('customer_id=' +.customer_id) customer = Customer.find(sale_data.customer_id) # rounding adjustment - if shop_details.is_rounding_adj + if shop_detail.is_rounding_adj a = sale_data.grand_total % 25 # Modulus b = sale_data.grand_total / 25 # Division #not calculate rounding if modulus is 0 and division is even @@ -79,7 +79,7 @@ class Origami::PaymentsController < BaseOrigamiController printer = Printer::ReceiptPrinter.new(print_settings) - filename, receipt_no, cashier_printer = printer.print_receipt_bill(print_settings,cashier_terminal,sale_items,sale_data,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info, shop_details, "Frt",current_balance,nil) + filename, receipt_no, cashier_printer = printer.print_receipt_bill(print_settings,cashier_terminal,sale_items,sale_data,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info, shop_detail, "Frt",current_balance,nil) result = { :filepath => filename, @@ -102,9 +102,9 @@ class Origami::PaymentsController < BaseOrigamiController if(Sale.exists?(sale_id)) saleObj = Sale.find(sale_id) sale_items = SaleItem.get_all_sale_items(sale_id) - shop_details = Shop.first + #shop_detail = Shop.first # rounding adjustment - if shop_details.is_rounding_adj + if shop_detail.is_rounding_adj a = saleObj.grand_total % 25 # Modulus b = saleObj.grand_total / 25 # Division #not calculate rounding if modulus is 0 and division is even @@ -123,16 +123,10 @@ class Origami::PaymentsController < BaseOrigamiController rebate_amount = nil # For Cashier by Zone - bookings = Booking.where("sale_id='#{sale_id}'") - # if bookings.count > 1 - # # for Multiple Booking - # table = DiningFacility.find(bookings[0].dining_facility_id) - # else - # table = DiningFacility.find(bookings[0].dining_facility_id) - # end - - if bookings[0].dining_facility_id.to_i > 0 - table = DiningFacility.find(bookings[0].dining_facility_id) + # bookings = Booking.where("sale_id='#{sale_id}'") + bookings = Booking.find_by_sale_id(sale_id) + if bookings.dining_facility_id.to_i > 0 + table = DiningFacility.find(bookings.dining_facility_id) cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id) cashier_terminal = CashierTerminal.find(cashier_zone.cashier_terminal_id) @@ -216,7 +210,7 @@ class Origami::PaymentsController < BaseOrigamiController discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(saleObj.sale_items) printer = Printer::ReceiptPrinter.new(print_settings) - filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings,cashier_terminal,sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details, "Paid",current_balance,card_data) + filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings,cashier_terminal,sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_detail, "Paid",current_balance,card_data) render json: JSON.generate({:status => saleObj.rebate_status, :message => "Can't Rebate coz of Sever Error ", :filename => filename, :receipt_no => sale_receipt_no, :printer_name => printer_name}) @@ -255,7 +249,7 @@ class Origami::PaymentsController < BaseOrigamiController if !@lookup_pdf.nil? @pdf_view = @lookup_pdf.value end - @shop = Shop.first #show shop info + @shop = shop_detail #show shop info @customer_lists = Customer.where("customer_id = 'CUS-000000000001' or customer_id = 'CUS-000000000002'") @@ -435,7 +429,7 @@ class Origami::PaymentsController < BaseOrigamiController customer= Customer.find(saleObj.customer_id) #shop detail - shop_details = Shop.first + #shop_detail = Shop.first # get member information rebate = MembershipSetting.find_by_rebate(1) if customer.membership_id != nil && rebate @@ -464,7 +458,7 @@ class Origami::PaymentsController < BaseOrigamiController discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(saleObj.sale_items) printer = Printer::ReceiptPrinter.new(print_settings) - filename, receipt_no, cashier_printer = printer.print_receipt_bill(print_settings,cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details, "Re-print",current_balance,card_data) + filename, receipt_no, cashier_printer = printer.print_receipt_bill(print_settings,cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_detail, "Re-print",current_balance,card_data) result = { :status => true, @@ -539,7 +533,7 @@ class Origami::PaymentsController < BaseOrigamiController customer= Customer.find(saleObj.customer_id) #shop detail - shop_details = Shop.first + #shop_detail = Shop.first # get printer info print_settings=PrintSetting.find_by_unique_code(unique_code) @@ -549,7 +543,7 @@ class Origami::PaymentsController < BaseOrigamiController printer = Printer::ReceiptPrinter.new(print_settings) - filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings,cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details, "FOC",nil,nil) + filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings,cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_detail, "FOC",nil,nil) result = { :status => true, :filepath => filename, @@ -579,7 +573,7 @@ class Origami::PaymentsController < BaseOrigamiController def rounding_adj saleObj = Sale.find(params[:sale_id]) - @shop = Shop.find_by_id(1) + @shop = shop_detail if @shop.is_rounding_adj a = saleObj.grand_total % 25 # Modulus diff --git a/app/controllers/origami/shifts_controller.rb b/app/controllers/origami/shifts_controller.rb index 3b2fe081..fd82d474 100755 --- a/app/controllers/origami/shifts_controller.rb +++ b/app/controllers/origami/shifts_controller.rb @@ -53,12 +53,15 @@ class Origami::ShiftsController < BaseOrigamiController cashier_terminal.save #add shift_sale_id to card_settle_trans - card_settle_trans = CardSettleTran.select('id').where(['shift_sale_id IS NULL and status IS NOT NULL']) + bank_integration = Lookup.find_by_lookup_type('bank_integration') + if !bank_integration.nil? + card_settle_trans = CardSettleTran.select('id').where(['shift_sale_id IS NULL and status IS NOT NULL']) - card_settle_trans.each do |data| - card_sett_trans = CardSettleTran.find(data.id) - card_sett_trans.shift_sale_id = @shift.id - card_sett_trans.save() + card_settle_trans.each do |data| + card_sett_trans = CardSettleTran.find(data.id) + card_sett_trans.shift_sale_id = @shift.id + card_sett_trans.save() + end end if ENV["SERVER_MODE"] != "cloud" #no print in cloud server @@ -77,7 +80,7 @@ class Origami::ShiftsController < BaseOrigamiController end end end - shop_details = Shop.find(1) + shop_details = shop_detail #get tax shift_obj = ShiftSale.where('id =?',@shift.id) @sale_taxes = Sale.get_separate_tax(shift_obj,from=nil,to=nil,type='') diff --git a/app/models/assigned_order_item.rb b/app/models/assigned_order_item.rb index ea1b9b39..d5acc98a 100755 --- a/app/models/assigned_order_item.rb +++ b/app/models/assigned_order_item.rb @@ -8,14 +8,16 @@ class AssignedOrderItem < ApplicationRecord belongs_to :order_queue_station def self.assigned_order_item (order, item_code, instance_code, order_queue_station ) - assigned_order_item = AssignedOrderItem.new() - assigned_order_item.order = order - assigned_order_item.item_code = item_code - assigned_order_item.instance_code = instance_code - assigned_order_item.order_queue_station = order_queue_station - assigned_order_item.print_status = false - assigned_order_item.delivery_status = false - assigned_order_item.save + AssignedOrderItem.transaction do + assigned_order_item = AssignedOrderItem.new() + assigned_order_item.order = order + assigned_order_item.item_code = item_code + assigned_order_item.instance_code = instance_code + assigned_order_item.order_queue_station = order_queue_station + assigned_order_item.print_status = false + assigned_order_item.delivery_status = false + assigned_order_item.save! + end end def self.assigned_order_item_by_job(order_id) diff --git a/app/models/order.rb b/app/models/order.rb index 01136578..af5887e6 100755 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -190,16 +190,18 @@ class Order < ApplicationRecord def update_items_status_to_billed(items) if (items.nil?) + OrderItem.where({ order_items_id: '#{self.order_items.pluck(:order_items_id)}'}).update_all(order_item_status: "billed") ##Update the order status to ensure that reflect the stage - self.order_items.each do |item| - item.order_item_status = "billed" - item.save - end + # self.order_items.each do |item| + # item.order_item_status = "billed" + # item.save + # end else - items.each do |item| - item.order_item_status = "billed" - item.save - end + OrderItem.where({ order_items_id: '#{items.pluck(:order_items_id)}'}).update_all(order_item_status: "billed") + # items.each do |item| + # item.order_item_status = "billed" + # item.save + # end end end diff --git a/app/models/sale.rb b/app/models/sale.rb index 262e487d..2f5035d6 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -412,13 +412,15 @@ class Sale < ApplicationRecord # Tax Re-Calculte def compute_tax(sale, total_taxable, total_discount = 0, order_source = nil, tax_type=nil) - shop = Shop.first(); + shop = Shop.first #if tax is not apply create new record - SaleTax.where("sale_id='#{sale.sale_id}'").find_each do |existing_tax| - #delete existing and create new - existing_tax.delete - end + # SaleTax.where("sale_id='#{sale.sale_id}'").find_each do |existing_tax| + # #delete existing and create new + # existing_tax.delete + # end + taxes = SaleTax.where("sale_id='#{sale.sale_id}'").pluck(:sale_tax_id) + SaleTax.where("sale_tax_id IN (?)", taxes).destroy_all total_tax_amount = 0 tax_incl_exec = "exclusive" @@ -495,7 +497,7 @@ class Sale < ApplicationRecord # Tax Calculate def apply_tax(total_taxable, order_source = nil) - shop = Shop.first(); + shop = Shop.first #if tax is not apply create new record SaleTax.where("sale_id='#{self.sale_id}'").find_each do |existing_tax| diff --git a/app/models/sale_order.rb b/app/models/sale_order.rb index 56a64353..773f2c06 100755 --- a/app/models/sale_order.rb +++ b/app/models/sale_order.rb @@ -7,11 +7,13 @@ class SaleOrder < ApplicationRecord belongs_to :sale belongs_to :order - def create_sale_order(sale, order) - sale_order = SaleOrder.new - sale_order.sale_id = sale - sale_order.order_id = order - sale_order.save! + def create_sale_order(sale, order) + SaleOrder.transaction do + sale_order = SaleOrder.new + sale_order.sale_id = sale + sale_order.order_id = order + sale_order.save! + end end private diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 782153f2..9b52c248 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -71,10 +71,12 @@ class SalePayment < ApplicationRecord # update complete order items in oqs booking = Booking.find_by_sale_id(sale_id) booking.booking_orders.each do |sodr| - AssignedOrderItem.where("order_id = '#{ sodr.order_id }'").find_each do |aoi| - aoi.delivery_status = 1 - aoi.save - end + assigned =AssignedOrderItem.where("order_id = '#{ sodr.order_id }'").pluck(:assigned_order_item_id) + AssignedOrderItem.where({ order_id: '#{assigned}'}).update_all(print_status: true) + # AssignedOrderItem.where("order_id = '#{ sodr.order_id }'").find_each do |aoi| + # aoi.delivery_status = 1 + # aoi.save + # end end return true, self.save,membership_data @@ -616,8 +618,9 @@ class SalePayment < ApplicationRecord end end if status && sale_count == 0 - table.status = "available" - table.save + table.update_attributes(status: "available") + # table.status = "available" + # table.save end # type = 'payment' diff --git a/app/pdf/receipt_bill_pdf.rb b/app/pdf/receipt_bill_pdf.rb index e9bf595c..9a1f92b1 100755 --- a/app/pdf/receipt_bill_pdf.rb +++ b/app/pdf/receipt_bill_pdf.rb @@ -199,9 +199,9 @@ class ReceiptBillPdf < Prawn::Document move_down line_move sub_total = 0.0 total_qty = 0.0 + show_price = Lookup.find_by_lookup_type("show_price") sale_items.each do |item| # check for item not to show - show_price = Lookup.find_by_lookup_type("show_price") if item.status != 'Discount' && item.qty > 0 if !show_price.nil? && show_price.value.to_i > 0 && item.price == 0 diff --git a/app/views/layouts/login_dashboard.html.erb b/app/views/layouts/login_dashboard.html.erb index 5db72f79..df2a35c2 100755 --- a/app/views/layouts/login_dashboard.html.erb +++ b/app/views/layouts/login_dashboard.html.erb @@ -112,49 +112,14 @@
From bfce0dc044d038aec15513f49e1db60a0168d26d Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Mon, 9 Jul 2018 17:27:51 +0630 Subject: [PATCH 3/8] added receipt no detail report --- .../reports/receipt_no_detail_controller.rb | 71 +++++ app/models/sale.rb | 31 ++ .../_shift_sale_report_filter.html.erb | 140 +++++++++ .../reports/receipt_no_detail/index.html.erb | 289 ++++++++++++++++++ .../reports/receipt_no_detail/index.xls.erb | 182 +++++++++++ config/routes.rb | 1 + 6 files changed, 714 insertions(+) create mode 100755 app/controllers/reports/receipt_no_detail_controller.rb create mode 100755 app/views/reports/receipt_no_detail/_shift_sale_report_filter.html.erb create mode 100755 app/views/reports/receipt_no_detail/index.html.erb create mode 100755 app/views/reports/receipt_no_detail/index.xls.erb diff --git a/app/controllers/reports/receipt_no_detail_controller.rb b/app/controllers/reports/receipt_no_detail_controller.rb new file mode 100755 index 00000000..d7b018d7 --- /dev/null +++ b/app/controllers/reports/receipt_no_detail_controller.rb @@ -0,0 +1,71 @@ +class Reports::ReceiptNoDetailController < BaseReportController +authorize_resource :class => false + def index + @payments = [["All Payment",''], ["Cash Payment","cash"], ["Credit Payment","creditnote"], ["FOC Payment","foc"]] + @payment_method = PaymentMethodSetting.all + from, to = get_date_range_from_params + + @shift_sale_range = '' + + @shift = '' + if params[:shift_name].to_i != 0 + + @shift_sale_range = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED) + + @shift_sale = ShiftSale.find(params[:shift_name]) + if to.blank? + @shift = ShiftSale.where('shift_started_at = ? and shift_closed_at is NULL ',@shift_sale.shift_started_at) + else + if @shift_sale.shift_closed_at.blank? + @shift = ShiftSale.where('shift_started_at = ? and shift_closed_at is NULL',@shift_sale.shift_started_at) + else + @shift = ShiftSale.where('shift_started_at = ? and shift_closed_at = ? ',@shift_sale.shift_started_at, @shift_sale.shift_closed_at) + end + end + end + + payment_type = params[:payment_type] + @sale_data = Sale.get_shift_sales_by_receipt_no_detail(@shift_sale_range,@shift,from,to,payment_type) + + @from = from + @to = to + # get printer info + @print_settings = PrintSetting.get_precision_delimiter() + if @shift.present? + @shift.each do |sh| + @shift_from = sh.shift_started_at.nil? ? '-' : sh.shift_started_at.utc.getlocal.strftime("%e %b %I:%M%p") + @shift_to = sh.shift_closed_at.nil? ? '-' : sh.shift_closed_at.utc.getlocal.strftime("%e %b %I:%M%p") + @shift_data = sh + end + end + + respond_to do |format| + format.html + format.xls + end + end + + def show + from, to = get_date_range_from_params + + @sale_data = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED) + + date_arr = Array.new + @sale_data.each do |sale| + local_opening_date = sale.opening_date.nil? ? '-' : sale.opening_date.utc.getlocal.strftime("%e %b %I:%M%p") + local_closing_date = sale.closing_date.nil? ? '-' : sale.closing_date.utc.getlocal.strftime("%e %b %I:%M%p") + opening_date = sale.opening_date.nil? ? '-' : sale.opening_date.utc + closing_date = sale.closing_date.nil? ? '-' : sale.closing_date.utc + shift_id = sale.id.nil? ? '-' : sale.id + str = {:shift_id => shift_id, :local_opening_date => local_opening_date, :local_closing_date => local_closing_date, :opening_date => opening_date, :closing_date => closing_date} + date_arr.push(str) + end + + out = {:status => 'ok', :message => date_arr} + + respond_to do |format| + format.json { render json: out } + end + end + +end \ No newline at end of file diff --git a/app/models/sale.rb b/app/models/sale.rb index 574d303c..b25ee229 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -1061,6 +1061,37 @@ def self.get_shift_sales_by_receipt_no(shift_sale_range,shift,from,to,payment_ty return query end +def self.get_shift_sales_by_receipt_no_detail(shift_sale_range,shift,from,to,payment_type) + ## => left join -> show all sales although no orders + if payment_type.blank? + payment_type = '' + else + payment_type = " and sale_payments.payment_method = '#{payment_type}'" + end + + query = Sale.select("sales.*,dining_facilities.name as table_name,dining_facilities.type as table_type") + if shift.present? + query = query.where("sales.shift_sale_id in (?) #{payment_type} and sale_status= 'completed' and sale_payments.payment_amount != 0", shift.to_a) + .joins("join sale_payments on sale_payments.sale_id = sales.sale_id") + .joins("join bookings on bookings.sale_id = sales.sale_id") + .joins("join dining_facilities on dining_facilities.id = bookings.dining_facility_id") + .group("sales.sale_id") + elsif shift_sale_range.present? + query = query.where("sale_status='completed' #{payment_type} and sale_payments.payment_amount != 0 and sales.shift_sale_id in (?)",shift_sale_range.to_a) + .joins("join sale_payments on sale_payments.sale_id = sales.sale_id") + .joins("join bookings on bookings.sale_id = sales.sale_id") + .joins("join dining_facilities on dining_facilities.id = bookings.dining_facility_id") + .group("sales.sale_id") + else + query = query.where("sale_status='completed' and sales.receipt_date between ? and ? #{payment_type} and sale_payments.payment_amount != 0",from,to) + .joins("join sale_payments on sale_payments.sale_id = sales.sale_id") + .joins("join bookings on bookings.sale_id = sales.sale_id") + .joins("join dining_facilities on dining_facilities.id = bookings.dining_facility_id") + .group("sales.sale_id") + end + return query +end + def self.get_by_shift_sale_credit_payment(shift_sale_range,shift,from,to) query = SalePayment.select("s.receipt_no, sale_payments.*,s.receipt_date as sale_date, s.cashier_name as cashier_name") diff --git a/app/views/reports/receipt_no_detail/_shift_sale_report_filter.html.erb b/app/views/reports/receipt_no_detail/_shift_sale_report_filter.html.erb new file mode 100755 index 00000000..1d7c2a94 --- /dev/null +++ b/app/views/reports/receipt_no_detail/_shift_sale_report_filter.html.erb @@ -0,0 +1,140 @@ +
+ <%= form_tag report_path, :method => :get, :id=>"frm_report", :class => "form" do %> + <% if period_type != false %> +
+
+ + +
+ <% if defined? payments %> + +
+ + + +
+ <% end %> +
+ + + +
+
+ + +
+
+ + +
+
+
+ +
+
+ <% end %> + + <% end %> +
+ + diff --git a/app/views/reports/receipt_no_detail/index.html.erb b/app/views/reports/receipt_no_detail/index.html.erb new file mode 100755 index 00000000..d2f7f11f --- /dev/null +++ b/app/views/reports/receipt_no_detail/index.html.erb @@ -0,0 +1,289 @@ +
+ +
+
+ <%= render :partial=>'shift_sale_report_filter', + :locals=>{ :period_type => true, :shift_name => true,:payments => true, :report_path =>reports_receipt_no_detail_index_path} %> +
+ + +
+
+ + + + + + <% if @shift_from %> + + <% if @shift_data.employee %> + <% cashier_name = !@shift_data.nil? ? @shift_data.employee.name : '-' %> + <% end %> + + + <% end %> + + + + + + + + + + + <% grand_total = 0 %> + <% @sale_data.each do |result| %> + <% grand_total = grand_total.to_f + result.grand_total.to_f%> + + + + + + + + + + + + + + + + + + <% result.sale_items.each do |item|%> + + + + + + + + <% end %> + + + + <%survey = Survey.find_by_receipt_no(result.receipt_no)%> + <% if !survey.nil?%> + + + + + + + + <% end %> + + <% if !result.total_amount.nil?%> + + + + + + + + <% end %> + + <% if result.total_discount.to_f > 0 %> + + + + + + + + <% end %> + + <% if !result.total_tax.nil? %> + + + + + + + + <% end %> + + <% if result.sale_payments.count > 0%> + <% result.sale_payments.each do |rec| %> + + + + + + + + + <% if !rec.payment_reference.nil? %> + + + + + + + + <% end %> + <% end %> + <% if result.amount_changed != 0 && !result.amount_changed.nil? %> + + + + + + + + <% end %> + <% if !result.customer_id.nil?%> + + + + + + + + <% end %> + <% end %> + + <% end %> + + + + + + + + + +
<%= t("views.right_panel.detail.from_date") %> : <%= @from.utc.getlocal.strftime("%Y-%b-%d") rescue '-' %> - <%= t("views.right_panel.detail.to_date") %> : <%= @to.utc.getlocal.strftime("%Y-%b-%d") rescue '-'%> +
<%= t("views.right_panel.detail.shift_name") %> = <%= @shift_from %> - <%= @shift_to %> ( <%= cashier_name %> )
<%= t("views.right_panel.detail.shift_name") %><%= t("views.right_panel.detail.table") %><%= t("views.right_panel.detail.receipt_no") %><%= t :cashier %> <%= t("views.right_panel.detail.name") %><%= t("views.right_panel.detail.revenue") %> 
<%= @shift_from %> - <%= @shift_to %><%= result.table_type %> - <%= result.table_name %><%= result.receipt_no rescue '-' %> <%= result.cashier_name rescue '-' %><%=result.grand_total%>
<%= t("views.right_panel.detail.product") %><%= t("views.right_panel.detail.qty") %><%= t("views.right_panel.detail.unit_price") %><%= t("views.right_panel.detail.total_price") %><%= t("views.right_panel.detail.created_at") %>
+ <% if item.price.to_i < 0.to_i %> + <% if item.qty.to_i < 0.to_i%> + [PROMO QTY]<%= item.product_name rescue '-' %> + <% else %> + [PROMO PRICE]<%= item.product_name rescue '-' %> + <% end %> + <% else %> + <%= item.product_name rescue '-' %> + <% end %> + <%= item.qty rescue '-' %><%= item.unit_price rescue '-' %><%= item.price rescue '-' %><%=l item.created_at.utc.getlocal, :format => :short rescue '-' %>
 
  No. of Guest<%= survey.total_customer rescue '-' %> 
  <%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.amount") %><%= result.total_amount %> 
  <%= t("views.right_panel.detail.total") %> + <%= t("views.right_panel.detail.discount") %> + <%= t("views.right_panel.detail.amount") %> - <%= result.total_discount %>  
  Tax Amount <%= result.total_tax %>  
  Payment <%= rec.payment_method.upcase %><%= rec.payment_amount %> ( <%= result.payment_status %> ) 
  Payment Ref.<%= rec.payment_reference %> 
  <%= t("views.right_panel.detail.change") %> <%= t("views.right_panel.detail.amount") %><%= result.amount_changed %> 
  Customer<%= result.customer.name.contact_first_name rescue '-'%> + (<%= result.customer.company rescue '-' %>) +  
   Total Nett - <%= grand_total %> 
+
+
+
+
+
+ \ No newline at end of file diff --git a/app/views/reports/receipt_no_detail/index.xls.erb b/app/views/reports/receipt_no_detail/index.xls.erb new file mode 100755 index 00000000..a4f5ed20 --- /dev/null +++ b/app/views/reports/receipt_no_detail/index.xls.erb @@ -0,0 +1,182 @@ + + + + + + + +
+
+
+
+
+ + + + + + <% if @shift_from %> + + <% if @shift_data.employee %> + <% cashier_name = !@shift_data.nil? ? @shift_data.employee.name : '-' %> + <% end %> + + + <% end %> + + + + + + + + + + + <% grand_total = 0 %> + <% @sale_data.each do |result| %> + <% grand_total = grand_total.to_f + result.grand_total.to_f%> + + + + + + + + + + + + + + + + + + <% result.sale_items.each do |item|%> + + + + + + + + <% end %> + + + + <%survey = Survey.find_by_receipt_no(result.receipt_no)%> + <% if !survey.nil?%> + + + + + + + + <% end %> + + <% if !result.total_amount.nil?%> + + + + + + + + <% end %> + + <% if result.total_discount.to_f > 0 %> + + + + + + + + <% end %> + + <% if !result.total_tax.nil? %> + + + + + + + + <% end %> + + <% if result.sale_payments.count > 0%> + <% result.sale_payments.each do |rec| %> + + + + + + + + + <% if !rec.payment_reference.nil? %> + + + + + + + + <% end %> + <% end %> + <% if result.amount_changed != 0 && !result.amount_changed.nil? %> + + + + + + + + <% end %> + <% if !result.customer_id.nil?%> + + + + + + + + <% end %> + <% end %> + + <% end %> + + + + + + + + + +
<%= t("views.right_panel.detail.from_date") %> : <%= @from.utc.getlocal.strftime("%Y-%b-%d") rescue '-' %> - <%= t("views.right_panel.detail.to_date") %> : <%= @to.utc.getlocal.strftime("%Y-%b-%d") rescue '-'%> +
<%= t("views.right_panel.detail.shift_name") %> = <%= @shift_from %> - <%= @shift_to %> ( <%= cashier_name %> )
<%= t("views.right_panel.detail.shift_name") %><%= t("views.right_panel.detail.table") %><%= t("views.right_panel.detail.receipt_no") %><%= t :cashier %> <%= t("views.right_panel.detail.name") %><%= t("views.right_panel.detail.revenue") %> 
<%= @shift_from %> - <%= @shift_to %><%= result.table_type %> - <%= result.table_name %><%= result.receipt_no rescue '-' %> <%= result.cashier_name rescue '-' %><%=result.grand_total%>
<%= t("views.right_panel.detail.product") %><%= t("views.right_panel.detail.qty") %><%= t("views.right_panel.detail.unit_price") %><%= t("views.right_panel.detail.total_price") %><%= t("views.right_panel.detail.created_at") %>
+ <% if item.price.to_i < 0.to_i %> + <% if item.qty.to_i < 0.to_i%> + [PROMO QTY]<%= item.product_name rescue '-' %> + <% else %> + [PROMO PRICE]<%= item.product_name rescue '-' %> + <% end %> + <% else %> + <%= item.product_name rescue '-' %> + <% end %> + <%= item.qty rescue '-' %><%= item.unit_price rescue '-' %><%= item.price rescue '-' %><%=l item.created_at.utc.getlocal, :format => :short rescue '-' %>
 
  No. of Guest<%= survey.total_customer rescue '-' %> 
  <%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.amount") %><%= result.total_amount %> 
  <%= t("views.right_panel.detail.total") %> + <%= t("views.right_panel.detail.discount") %> + <%= t("views.right_panel.detail.amount") %> - <%= result.total_discount %>  
  Tax Amount <%= result.total_tax %>  
  Payment <%= rec.payment_method.upcase %><%= rec.payment_amount %> ( <%= result.payment_status %> ) 
  Payment Ref.<%= rec.payment_reference %> 
  <%= t("views.right_panel.detail.change") %> <%= t("views.right_panel.detail.amount") %><%= result.amount_changed %> 
  Customer<%= result.customer.name.contact_first_name rescue '-'%> + (<%= result.customer.company rescue '-' %>) +  
   Total Nett - <%= grand_total %> 
+ +
+
+
+
+
+ + \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 1b7f3682..99c008ae 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -443,6 +443,7 @@ scope "(:locale)", locale: /en|mm/ do #--------- Reports Controller Sections ------------# namespace :reports do resources :receipt_no + resources :receipt_no_detail resources :dailysale, :only => [:index, :show] resources :saleitem, :only => [:index, :show] resources :shiftsale, :only => [:index, :show] From 82ede72f34e0472b6e966d3a8eaec01fd58c8aa2 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Tue, 10 Jul 2018 10:00:44 +0630 Subject: [PATCH 4/8] update sidebar --- app/views/layouts/_left_sidebar.html.erb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/views/layouts/_left_sidebar.html.erb b/app/views/layouts/_left_sidebar.html.erb index f83284ae..0d324b95 100644 --- a/app/views/layouts/_left_sidebar.html.erb +++ b/app/views/layouts/_left_sidebar.html.erb @@ -143,6 +143,9 @@
  • Receipt
  • +
  • + Receipt Detail +
  • Shift Sales
  • From 5c8fd3666d9d631a039fed212d55fa602031b539 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Tue, 10 Jul 2018 15:16:49 +0630 Subject: [PATCH 5/8] update other charge add to recipt bill and close pdf --- app/controllers/origami/payments_controller.rb | 8 ++++++-- app/controllers/origami/shifts_controller.rb | 2 +- app/models/print_setting.rb | 6 +++++- app/models/printer/cashier_station_printer.rb | 8 ++++---- app/models/printer/receipt_printer.rb | 8 ++++---- app/models/sale_item.rb | 13 +++++++++++++ app/pdf/close_cashier_pdf.rb | 14 +++++++++++--- app/pdf/receipt_bill_a5_pdf.rb | 16 +++++++++++++++- app/pdf/receipt_bill_pdf.rb | 16 +++++++++++++++- 9 files changed, 74 insertions(+), 17 deletions(-) diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index 2ca8b45a..e420be17 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -77,9 +77,11 @@ class Origami::PaymentsController < BaseOrigamiController item_price_by_accounts = SaleItem.calculate_price_by_accounts(sale_items) discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(sale_items) + other_amount = SaleItem.calculate_other_charges(sale_items) + printer = Printer::ReceiptPrinter.new(print_settings) - filename, receipt_no, cashier_printer = printer.print_receipt_bill(print_settings,cashier_terminal,sale_items,sale_data,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info, shop_detail, "Frt",current_balance,nil) + filename, receipt_no, cashier_printer = printer.print_receipt_bill(print_settings,cashier_terminal,sale_items,sale_data,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info, shop_detail, "Frt",current_balance,nil,other_amount) result = { :filepath => filename, @@ -209,8 +211,10 @@ class Origami::PaymentsController < BaseOrigamiController 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) + other_amount = SaleItem.calculate_other_charges(sale_items) + printer = Printer::ReceiptPrinter.new(print_settings) - filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings,cashier_terminal,sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_detail, "Paid",current_balance,card_data) + filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings,cashier_terminal,sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_detail, "Paid",current_balance,card_data,other_amount) render json: JSON.generate({:status => saleObj.rebate_status, :message => "Can't Rebate coz of Sever Error ", :filename => filename, :receipt_no => sale_receipt_no, :printer_name => printer_name}) diff --git a/app/controllers/origami/shifts_controller.rb b/app/controllers/origami/shifts_controller.rb index fd82d474..81d41565 100755 --- a/app/controllers/origami/shifts_controller.rb +++ b/app/controllers/origami/shifts_controller.rb @@ -101,7 +101,7 @@ class Origami::ShiftsController < BaseOrigamiController print_settings = PrintSetting.find_by_unique_code(unique_code) printer = Printer::CashierStationPrinter.new(print_settings) - printer.print_close_cashier(print_settings,cashier_terminal,@shift,shop_details,@sale_taxes,@other_payment,@total_amount_by_account,@total_discount_by_account,@total_member_discount,@total_dinein,@total_takeway,@total_other_charges,@total_waste,@total_spoile) + printer.print_close_cashier(print_settings,cashier_terminal,@shift,shop_details,@sale_taxes,@other_payment,@total_amount_by_account,@total_discount_by_account,@total_member_discount,@total_dinein,@total_takeway,@total_other_charges,@total_waste,@total_spoile ) end end Employee.logout(session[:session_token]) diff --git a/app/models/print_setting.rb b/app/models/print_setting.rb index 59c58001..c1a17c5a 100755 --- a/app/models/print_setting.rb +++ b/app/models/print_setting.rb @@ -3,7 +3,11 @@ class PrintSetting < ApplicationRecord validates_presence_of :name, :unique_code, :printer_name, :api_settings, :page_width, :page_height, :print_copies, :header_font_size, :item_font_size def self.get_precision_delimiter - PrintSetting.find_by_unique_code("CloseCashierPdf") + setting = PrintSetting.find_by_unique_code("CloseCashierPdf") + if setting.nil? + setting = PrintSetting.find_by_unique_code("CloseCashierCustomisePdf") + end + return setting end end diff --git a/app/models/printer/cashier_station_printer.rb b/app/models/printer/cashier_station_printer.rb index 73813d1a..f6473df4 100755 --- a/app/models/printer/cashier_station_printer.rb +++ b/app/models/printer/cashier_station_printer.rb @@ -37,7 +37,7 @@ class Printer::CashierStationPrinter < Printer::PrinterWorker # pdf.render_file filename # self.print(filename, cashier_terminal.printer_name) # end - + def print_close_cashier(printer_settings,cashier_terminal,shift_sale,shop_details,sale_taxes,other_payment,amount,discount,member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile) #Use CUPS service @@ -46,16 +46,16 @@ class Printer::CashierStationPrinter < Printer::PrinterWorker cashier = shift_sale.employee.name shift_name = shift_sale.shift_started_at.utc.getlocal.strftime("%d-%m-%Y %I:%M %p") + "_" + shift_sale.shift_closed_at.utc.getlocal.strftime("%d-%m-%Y %I:%M %p") filename = "tmp/close_cashier_#{cashier}_#{shift_name}.pdf" - pdf = CloseCashierPdf.new(printer_settings,shift_sale,shop_details,sale_taxes,other_payment,amount,discount,member_discount,total_waste,total_spoile) + pdf = CloseCashierPdf.new(printer_settings,shift_sale,shop_details,sale_taxes,other_payment,amount,discount,member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile) close_cashier_pdf = Lookup.collection_of("print_settings") #print_settings with name:CloseCashierPdf if !close_cashier_pdf.empty? close_cashier_pdf.each do |close_cashier| if close_cashier[0] == 'CloseCashierCustomisePdf' if close_cashier[1] == '1' - pdf = CloseCashierCustomisePdf.new(printer_settings,shift_sale,shop_details,sale_taxes,other_payment,amount,discount,member_discount,total_dinein,total_takeway,total_other_charges) + pdf = CloseCashierCustomisePdf.new(printer_settings,shift_sale,shop_details,sale_taxes,other_payment,amount,discount,member_discount,total_dinein,total_takeway,total_other_charges,@total_waste,@total_spoile) else - pdf = CloseCashierPdf.new(printer_settings,shift_sale,shop_details,sale_taxes,other_payment,amount,discount,member_discount,total_waste,total_spoile) + pdf = CloseCashierPdf.new(printer_settings,shift_sale,shop_details,sale_taxes,other_payment,amount,discount,member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile) end end end diff --git a/app/models/printer/receipt_printer.rb b/app/models/printer/receipt_printer.rb index 2c925384..f77fc96c 100755 --- a/app/models/printer/receipt_printer.rb +++ b/app/models/printer/receipt_printer.rb @@ -188,19 +188,19 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker end #Bill Receipt Print - def print_receipt_bill(printer_settings,cashier_terminal,sale_items,sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info = nil,rebate_amount=nil,shop_details, printed_status,balance,card_data) + def print_receipt_bill(printer_settings,cashier_terminal,sale_items,sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info = nil,rebate_amount=nil,shop_details, printed_status,balance,card_data,other_amount) #Use CUPS service #Generate PDF #Print - pdf = ReceiptBillPdf.new(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details,printed_status,balance,card_data) + pdf = ReceiptBillPdf.new(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details,printed_status,balance,card_data,other_amount) receipt_bill_a5_pdf = Lookup.collection_of("print_settings") #print_settings with name:ReceiptBillA5Pdf if !receipt_bill_a5_pdf.empty? receipt_bill_a5_pdf.each do |receipt_bilA5| if receipt_bilA5[0] == 'ReceiptBillA5Pdf' if receipt_bilA5[1] == '1' - pdf = ReceiptBillA5Pdf.new(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details,printed_status,balance,card_data) + pdf = ReceiptBillA5Pdf.new(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details,printed_status,balance,card_data,other_amount) else - pdf = ReceiptBillPdf.new(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details,printed_status,balance,card_data) + pdf = ReceiptBillPdf.new(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details,printed_status,balance,card_data,other_amount) end end end diff --git a/app/models/sale_item.rb b/app/models/sale_item.rb index 3d5a659c..62db6097 100755 --- a/app/models/sale_item.rb +++ b/app/models/sale_item.rb @@ -150,6 +150,19 @@ class SaleItem < ApplicationRecord return price,type end + # Get Prices for each accounts (eg: food, beverage) + def self.calculate_other_charges(sale_items) + total = 0 + # Check for actual sale items + sale_items.each do |si| + if si.product_code == "Other Charges" && si.item_instance_code == nil + total = total + si.price + end + end + + return total + end + # def self.get_overall_discount(sale_id) # price = 0.0 # item=SaleItem.where("product_code=?", sale_id) diff --git a/app/pdf/close_cashier_pdf.rb b/app/pdf/close_cashier_pdf.rb index 3888c549..461022c1 100755 --- a/app/pdf/close_cashier_pdf.rb +++ b/app/pdf/close_cashier_pdf.rb @@ -2,7 +2,7 @@ class CloseCashierPdf < 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,:text_width - def initialize(printer_settings, shift_sale,shop_details,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount,total_waste,total_spoile) + def initialize(printer_settings, shift_sale,shop_details,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile) self.page_width = printer_settings.page_width #PrintSetting.where("name = ?","Close Cashier").first.page_width self.page_height = printer_settings.page_height self.header_font_size = printer_settings.header_font_size.to_i @@ -54,7 +54,7 @@ class CloseCashierPdf < Prawn::Document stroke_horizontal_rule - shift_detail(shift_sale,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount,printer_settings.precision,delimiter,total_waste,total_spoile) + shift_detail(shift_sale,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount,printer_settings.precision,delimiter,total_waste,total_spoile,total_other_charges) end def header (shop_details) @@ -70,7 +70,7 @@ class CloseCashierPdf < Prawn::Document stroke_horizontal_rule end - def shift_detail(shift_sale,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount,precision,delimiter,total_waste,total_spoile) + def shift_detail(shift_sale,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount,precision,delimiter,total_waste,total_spoile,total_other_charges) move_down 7 y_position = cursor bounding_box([0,y_position], :width =>self.label_width, :height => self.item_height) do @@ -449,6 +449,14 @@ class CloseCashierPdf < Prawn::Document text "#{number_with_precision(amount.total_price, :precision => precision.to_i, :delimiter => delimiter)} ", :size => self.item_font_size, :align => :right end end + + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "Total Other Amount :", :size => self.item_font_size, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{total_other_charges}", :size => self.item_font_size, :align => :right + end #end total amount by Account y_position = cursor diff --git a/app/pdf/receipt_bill_a5_pdf.rb b/app/pdf/receipt_bill_a5_pdf.rb index 4f6969c5..f6555bcb 100644 --- a/app/pdf/receipt_bill_a5_pdf.rb +++ b/app/pdf/receipt_bill_a5_pdf.rb @@ -2,7 +2,7 @@ class ReceiptBillA5Pdf < 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, :description_width, :price_num_width, :line_move - 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,current_balance,card_data) + 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,current_balance,card_data,other_charges_amount) self.page_width = printer_settings.page_width self.page_height = printer_settings.page_height self.header_font_size = printer_settings.header_font_size.to_i @@ -79,6 +79,9 @@ class ReceiptBillA5Pdf < Prawn::Document if shop_details.show_account_info items_account(item_price_by_accounts,printer_settings.precision,delimiter) + if other_charges_amount + show_other_charges_amount(other_charges_amount,printer_settings.precision,delimiter) + end end #start for individual payment @@ -537,6 +540,17 @@ class ReceiptBillA5Pdf < Prawn::Document end end + def show_other_charges_amount(other_amount,precision,delimiter) + y_position = cursor + bounding_box([0,y_position], :width =>self.label_width) do + text "Other Charges", :size => self.item_font_size,:align => :left + end + bounding_box([self.label_width,y_position], :width =>self.item_description_width) do + text "#{number_with_precision(other_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + end + move_down line_move + end + #individual payment per person def individual_payment(sale_data, precision, delimiter) per_person = sale_data.grand_total.to_i / sale_data.equal_persons.to_i diff --git a/app/pdf/receipt_bill_pdf.rb b/app/pdf/receipt_bill_pdf.rb index 9a1f92b1..80a57c51 100755 --- a/app/pdf/receipt_bill_pdf.rb +++ b/app/pdf/receipt_bill_pdf.rb @@ -3,7 +3,7 @@ class ReceiptBillPdf < 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, :description_width, :price_num_width, :line_move - 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,current_balance,card_data) + 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,current_balance,card_data,other_charges_amount) self.page_width = printer_settings.page_width self.page_height = printer_settings.page_height self.header_font_size = printer_settings.header_font_size.to_i @@ -80,6 +80,9 @@ class ReceiptBillPdf < Prawn::Document if shop_details.show_account_info items_account(item_price_by_accounts,printer_settings.precision,delimiter) + if other_charges_amount + show_other_charges_amount(other_charges_amount,printer_settings.precision,delimiter) + end end #start for individual payment @@ -536,6 +539,17 @@ class ReceiptBillPdf < Prawn::Document end end + def show_other_charges_amount(other_amount,precision,delimiter) + y_position = cursor + bounding_box([0,y_position], :width =>self.label_width) do + text "Other Charges", :size => self.item_font_size,:align => :left + end + bounding_box([self.label_width,y_position], :width =>self.item_description_width) do + text "#{number_with_precision(other_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + end + move_down line_move + end + #individual payment per person def individual_payment(sale_data, survey, precision, delimiter) # per_person = sale_data.grand_total.to_f / survey.total_customer.to_i From 158760abdbc36b72f0df38a05ed7542c09053dfb Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Tue, 10 Jul 2018 16:05:37 +0630 Subject: [PATCH 6/8] update vodi and pay foc waste and spoil for other paymtnt amount in receipt pdf --- app/controllers/origami/payments_controller.rb | 9 ++++++--- app/controllers/origami/void_controller.rb | 4 ++-- app/controllers/origami/waste_spoile_controller.rb | 4 ++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index e420be17..cde70fa8 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -460,9 +460,10 @@ 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) - + other_amount = SaleItem.calculate_other_charges(sale_items) + printer = Printer::ReceiptPrinter.new(print_settings) - filename, receipt_no, cashier_printer = printer.print_receipt_bill(print_settings,cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_detail, "Re-print",current_balance,card_data) + filename, receipt_no, cashier_printer = printer.print_receipt_bill(print_settings,cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_detail, "Re-print",current_balance,card_data,other_amount) result = { :status => true, @@ -545,9 +546,11 @@ class Origami::PaymentsController < BaseOrigamiController 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) + other_amount = SaleItem.calculate_other_charges(sale_items) + printer = Printer::ReceiptPrinter.new(print_settings) - filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings,cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_detail, "FOC",nil,nil) + filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings,cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_detail, "FOC",nil,nil,other_amount) result = { :status => true, :filepath => filename, diff --git a/app/controllers/origami/void_controller.rb b/app/controllers/origami/void_controller.rb index 891cd398..21ac822b 100755 --- a/app/controllers/origami/void_controller.rb +++ b/app/controllers/origami/void_controller.rb @@ -124,9 +124,9 @@ class Origami::VoidController < BaseOrigamiController # Calculate Food and Beverage Total item_price_by_accounts = SaleItem.calculate_price_by_accounts(sale.sale_items) discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(sale.sale_items) - + other_amount = SaleItem.calculate_other_charges(sale_items) printer = Printer::ReceiptPrinter.new(print_settings) - filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings,cashier_terminal,sale.sale_items,sale,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details, "VOID",current_balance,nil) + filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings,cashier_terminal,sale.sale_items,sale,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details, "VOID",current_balance,nil,other_amount) result = { :filepath => filename, :printer_model => print_settings.brand_name, diff --git a/app/controllers/origami/waste_spoile_controller.rb b/app/controllers/origami/waste_spoile_controller.rb index d008a54d..7c005b87 100755 --- a/app/controllers/origami/waste_spoile_controller.rb +++ b/app/controllers/origami/waste_spoile_controller.rb @@ -105,9 +105,9 @@ class Origami::WasteSpoileController < BaseOrigamiController # Calculate Food and Beverage Total item_price_by_accounts = SaleItem.calculate_price_by_accounts(sale.sale_items) discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(sale.sale_items) - + other_amount = SaleItem.calculate_other_charges(sale_items) printer = Printer::ReceiptPrinter.new(print_settings) - filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings,cashier_terminal,sale.sale_items,sale,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details, remark,current_balance,nil) + filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings,cashier_terminal,sale.sale_items,sale,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details, remark,current_balance,nil,other_amount) result = { :filepath => filename, :printer_model => print_settings.brand_name, From 9924aaef8ac43da119c543a33ddb04674aba6d62 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Tue, 10 Jul 2018 16:10:04 +0630 Subject: [PATCH 7/8] update vodi and pay foc waste and spoil for other paymtnt amount in receipt pdf --- app/controllers/origami/payments_controller.rb | 2 +- app/controllers/origami/void_controller.rb | 2 +- app/controllers/origami/waste_spoile_controller.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index cde70fa8..822a601b 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -546,7 +546,7 @@ class Origami::PaymentsController < BaseOrigamiController 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) - other_amount = SaleItem.calculate_other_charges(sale_items) + other_amount = SaleItem.calculate_other_charges(saleObj.sale_items) printer = Printer::ReceiptPrinter.new(print_settings) diff --git a/app/controllers/origami/void_controller.rb b/app/controllers/origami/void_controller.rb index 21ac822b..76533730 100755 --- a/app/controllers/origami/void_controller.rb +++ b/app/controllers/origami/void_controller.rb @@ -124,7 +124,7 @@ class Origami::VoidController < BaseOrigamiController # Calculate Food and Beverage Total item_price_by_accounts = SaleItem.calculate_price_by_accounts(sale.sale_items) discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(sale.sale_items) - other_amount = SaleItem.calculate_other_charges(sale_items) + other_amount = SaleItem.calculate_other_charges(sale.sale_items) printer = Printer::ReceiptPrinter.new(print_settings) filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings,cashier_terminal,sale.sale_items,sale,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details, "VOID",current_balance,nil,other_amount) result = { diff --git a/app/controllers/origami/waste_spoile_controller.rb b/app/controllers/origami/waste_spoile_controller.rb index 7c005b87..e7ca1091 100755 --- a/app/controllers/origami/waste_spoile_controller.rb +++ b/app/controllers/origami/waste_spoile_controller.rb @@ -105,7 +105,7 @@ class Origami::WasteSpoileController < BaseOrigamiController # Calculate Food and Beverage Total item_price_by_accounts = SaleItem.calculate_price_by_accounts(sale.sale_items) discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(sale.sale_items) - other_amount = SaleItem.calculate_other_charges(sale_items) + other_amount = SaleItem.calculate_other_charges(sale.sale_items) printer = Printer::ReceiptPrinter.new(print_settings) filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings,cashier_terminal,sale.sale_items,sale,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details, remark,current_balance,nil,other_amount) result = { From 441f37ba8ac6bac1d254e3e4a8a7a24953dbd662 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Tue, 10 Jul 2018 16:13:09 +0630 Subject: [PATCH 8/8] update repriint --- app/controllers/origami/payments_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index 822a601b..7948941b 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -460,7 +460,7 @@ 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) - other_amount = SaleItem.calculate_other_charges(sale_items) + other_amount = SaleItem.calculate_other_charges(saleObj.sale_items) printer = Printer::ReceiptPrinter.new(print_settings) filename, receipt_no, cashier_printer = printer.print_receipt_bill(print_settings,cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_detail, "Re-print",current_balance,card_data,other_amount)