diff --git a/app/controllers/origami/home_controller.rb b/app/controllers/origami/home_controller.rb index a8e2818c..759cb1b6 100755 --- a/app/controllers/origami/home_controller.rb +++ b/app/controllers/origami/home_controller.rb @@ -95,7 +95,7 @@ class Origami::HomeController < BaseOrigamiController @status_order = 'order' else sale = Sale.find(booking.sale_id) - if sale.sale_status != "completed" && sale.sale_status != 'void' + if sale.sale_status != "completed" && sale.sale_status != 'void' && sale.sale_status != 'spoile' && sale.sale_status != 'waste' @sale_array.push(sale) if @status_order == 'order' @status_order = 'sale' diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index 5397c7f0..16a79d33 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -113,8 +113,6 @@ class Origami::PaymentsController < BaseOrigamiController end end #end rounding adjustment - puts "sale" - puts saleObj.to_json sale_payment = SalePayment.new sale_payment.process_payment(saleObj, current_user.name, cash, "cash") diff --git a/app/controllers/origami/rooms_controller.rb b/app/controllers/origami/rooms_controller.rb index 11a7f93d..5c0cd454 100755 --- a/app/controllers/origami/rooms_controller.rb +++ b/app/controllers/origami/rooms_controller.rb @@ -79,8 +79,7 @@ class Origami::RoomsController < BaseOrigamiController @status_order = 'order' else sale = Sale.find(booking.sale_id) - if sale.sale_status != "completed" && sale.sale_status != 'void' - puts "enter" + if sale.sale_status != "completed" && sale.sale_status != 'void' && sale.sale_status != 'spoile' && sale.sale_status != 'waste' @sale_array.push(sale) if @status_order == 'order' @status_order = 'sale' diff --git a/app/controllers/origami/void_controller.rb b/app/controllers/origami/void_controller.rb index 74e495ca..83dce707 100755 --- a/app/controllers/origami/void_controller.rb +++ b/app/controllers/origami/void_controller.rb @@ -48,7 +48,7 @@ class Origami::VoidController < BaseOrigamiController table.bookings.each do |booking| if booking.booking_status != 'moved' if booking.sale_id - if booking.sale.sale_status != 'completed' && booking.sale.sale_status != 'void' + if booking.sale.sale_status != 'completed' && booking.sale.sale_status != 'void' && booking.sale.sale_status != 'spoile' && booking.sale.sale_status != 'waste' table_avaliable = false table_count += 1 else diff --git a/app/controllers/origami/waste_spoile_controller .rb b/app/controllers/origami/waste_spoile_controller.rb similarity index 83% rename from app/controllers/origami/waste_spoile_controller .rb rename to app/controllers/origami/waste_spoile_controller.rb index 72180786..c94b33bb 100755 --- a/app/controllers/origami/waste_spoile_controller .rb +++ b/app/controllers/origami/waste_spoile_controller.rb @@ -1,29 +1,28 @@ class Origami::WasteSpoileController < BaseOrigamiController - def index - - end - def waste_and_spoile + def waste_and_spoilage sale_id = params[:sale_id] remark = params[:remark] order_source = params[:type] #tax profile source if Sale.exists?(sale_id) sale = Sale.find_by_sale_id(sale_id) - - if sale.discount_type == "member_discount" - sale.update_attributes(total_discount: 0) - sale.compute_by_sale_items(sale_id, sale.sale_items,0,order_source) + SaleTax.where("sale_id='#{sale_id}'").find_each do |existing_tax| + existing_tax.delete end - + sale.update_attributes(total_discount: 0,total_tax: 0,grand_total: sale.total_amount,rounding_adjustment:0) sale.payment_status = remark sale.sale_status = remark sale.save + # sale.compute_by_sale_items(sale_id, sale.sale_items,0,order_source) # add to sale item with foc - sale_items = SaleItem.where("sale_id='#{ sale_id }' and status is null") + # sale_items = SaleItem.where("sale_id='#{ sale_id }' and status is null") - sale_items.each do|item| - SaleItem.update_existing_item(item.qty, item, sale_id, remark, item.unit_price, item.price) + sale.sale_items.each do|item| + # SaleItem.update_existing_item(item.qty, item, sale_id, remark, item.unit_price, item.price) + item.status = remark + item.remark = remark + item.save end if sale.bookings[0].dining_facility_id.to_i > 0 @@ -33,7 +32,7 @@ class Origami::WasteSpoileController < BaseOrigamiController table.bookings.each do |booking| if booking.booking_status != 'moved' if booking.sale_id - if booking.sale.sale_status != 'completed' && booking.sale.sale_status != 'void' + if booking.sale.sale_status != 'completed' && booking.sale.sale_status != 'void' && booking.sale.sale_status != 'spoile' && booking.sale.sale_status != 'waste' table_avaliable = false table_count += 1 else @@ -45,7 +44,6 @@ class Origami::WasteSpoileController < BaseOrigamiController end end end - if table_avaliable && table_count == 0 table.status = 'available' table.save @@ -104,7 +102,7 @@ class Origami::WasteSpoileController < BaseOrigamiController discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(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) + 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) result = { :filepath => filename, :printer_model => print_settings.brand_name, diff --git a/app/controllers/reports/waste_and_spoilage_controller.rb b/app/controllers/reports/waste_and_spoilage_controller.rb new file mode 100755 index 00000000..369c6860 --- /dev/null +++ b/app/controllers/reports/waste_and_spoilage_controller.rb @@ -0,0 +1,19 @@ +class Reports::WasteAndSpoilageController < BaseReportController +authorize_resource :class => false + def index + from, to = get_date_range_from_params + @sale_type = params[:sale_type] + @sale_data = Sale.get_wastes_and_spoilages(from,to,@sale_type) + @from = from + @to = to + # get printer info + @print_settings = PrintSetting.get_precision_delimiter() + + respond_to do |format| + format.html + format.xls + end + end + + +end \ No newline at end of file diff --git a/app/models/sale.rb b/app/models/sale.rb index 970896bf..e25589dc 100755 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -1109,6 +1109,16 @@ def self.get_payment_method_by_shift(shift_sale_range,shift,from,to,payment_type return all_total,sale_type end +def self.get_wastes_and_spoilages(from,to,status) + if status == "spoile" + type = "and sales.sale_status = 'spoile'" + else + type = "and sales.sale_status = 'waste'" + end + query = Sale.all.where("sales.receipt_date between ? and ? #{type}",from,to) + .group("sales.receipt_no") +end + # def self.get_separate_tax(from,to,payment_method=nil) # query = SaleTax.select("SUM(tax_payable_amount) AS st_amount,tax_name") diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 3ff4697e..5a0b22b2 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -418,7 +418,7 @@ class SalePayment < ApplicationRecord bookings.each do |tablebooking| if tablebooking.booking_status != 'moved' if tablebooking.sale_id - if tablebooking.sale.sale_status != 'completed' && tablebooking.sale.sale_status != 'void' + if tablebooking.sale.sale_status != 'completed' && tablebooking.sale.sale_status != 'void' && tablebooking.sale.sale_status != 'spoile' && tablebooking.sale.sale_status != 'waste' status = false sale_count += 1 else diff --git a/app/views/layouts/_left_sidebar.html.erb b/app/views/layouts/_left_sidebar.html.erb index 63067ec0..ea3a7b61 100644 --- a/app/views/layouts/_left_sidebar.html.erb +++ b/app/views/layouts/_left_sidebar.html.erb @@ -144,6 +144,9 @@
| + Receipt No :<%= sale.receipt_no %> + | ++ | Date : <%= sale.created_at.utc.getlocal.strftime("%e,%b %Y %I:%M %p") %> | +||
| Product | +Code | +Qty | +Price | +Total Price | +
| <%= item.product_name %> | +<%= item.product_code %> | +<%= item.qty %> | +<%= item.price %> | +<%= item.price %> | +
| Total Qty: | ++ <%= waste_and_spoil_item_count %> + | +Grand Total: | ++ + <%= sale.grand_total %> + + | +|
| <%= 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.receipt_no") %> | +<%= t :cashier %> <%= t("views.right_panel.detail.name") %> | +<%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.amount") %> | +<%= t("views.right_panel.detail.discount") %> <%= t("views.right_panel.detail.amount") %> | + <% @tax_profiles.each do |tax| %> +<%= tax.name %> | + <% end %> + +<%= t("views.right_panel.detail.grand_total") %> | +<%= t("views.right_panel.detail.rnd_adj_sh") %> | +<%= t("views.right_panel.detail.grand_total") %> + + <%= t("views.right_panel.detail.rnd_adj_sh") %> + |
+ |
| <%= result.receipt_no rescue '-' %> | +<%= result.cashier_name rescue '-' %> | +<%= result.total_amount rescue '-' %> | +<%= result.total_discount rescue '-' %> | + <%if result.customer.customer_type == "Takeaway"%> +0.0 | + <%end%> + <% result.sale_taxes.each do |tax| %> +<%= tax.tax_payable_amount rescue '-' %> | + <%end%> + +<%= result.grand_total %> | +<%= result.rounding_adjustment.to_f rescue '-' %> | +<%= result.grand_total_after_rounding() rescue '-'%> | +
| + | <%= total_sum rescue '-'%> | +<%= discount_amt rescue '-'%> | + <% @sale_taxes.each do |tax| %> +<%= tax.st_amount.round(2) %> | + <% end %> +<%= grand_total.to_f.round(2) rescue '-'%> | +<%= rounding_adj rescue '-'%> | +<%= grand_total.to_f.round + rounding_adj %> | +||
| + | <%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.amount") %> | +<%= t("views.right_panel.detail.discount") %> <%= t("views.right_panel.detail.amount") %> | + + <% @tax_profiles.each do |tax| %> +<%= tax.name %> | + <% end %> +<%= t("views.right_panel.detail.grand_total") %> | +<%= t("views.right_panel.detail.rnd_adj_sh") %> | +<%= t("views.right_panel.detail.grand_total") %> + + <%= t("views.right_panel.detail.rnd_adj_sh") %> + |
+ ||