diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 202d4387..8604d3c8 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -25,6 +25,13 @@ $(document).on("focus", "[data-behaviour~='datepicker']", function(e){ $('.dropdown-toggle').dropdown(); }); +function export_to(path) +{ + var form_params = $("#frm_report").serialize(); + alert(form_params); + window.location = path+"?"+ form_params; +} + /* * ToDo Move to here from pages * diff --git a/app/assets/javascripts/origami.js b/app/assets/javascripts/origami.js index 78a21c3b..88bd919d 100644 --- a/app/assets/javascripts/origami.js +++ b/app/assets/javascripts/origami.js @@ -49,7 +49,7 @@ $(document).ready(function(){ control_button(order_status); var customer_id=$(this).find(".customer-id").text(); - show_customer_details(customer_id); + //show_customer_details(customer_id); $("#re-print").val(unique_id); diff --git a/app/controllers/crm/customers_controller.rb b/app/controllers/crm/customers_controller.rb index 290f6ca1..d83d434f 100644 --- a/app/controllers/crm/customers_controller.rb +++ b/app/controllers/crm/customers_controller.rb @@ -95,6 +95,7 @@ class Crm::CustomersController < BaseCrmController auth_token = memberaction.auth_token.to_s url = membership.gateway_url.to_s + memberaction.gateway_url.to_s + begin response = HTTParty.post(url, :body => { name: name,phone: phone,email: email, dob: dob, member_group_id: member_group_id,merchant_uid:merchant_uid,auth_token:auth_token}.to_json, @@ -103,6 +104,9 @@ class Crm::CustomersController < BaseCrmController 'Accept' => 'application/json' } ) + rescue Net::OpenTimeout + response = { status: false } + end if response["status"] == true @@ -159,7 +163,7 @@ end merchant_uid = memberaction.merchant_account_id.to_s auth_token = memberaction.auth_token.to_s url = membership.gateway_url.to_s + memberaction.gateway_url.to_s - + begin response = HTTParty.post(url, :body => { name: name,phone: phone,email: email, dob: dob, id: id,member_group_id:member_group_id,merchant_uid:merchant_uid,auth_token:auth_token}.to_json, @@ -168,7 +172,9 @@ end 'Accept' => 'application/json' } ) - + rescue Net::OpenTimeout + response = { status: false } + end format.html { redirect_to crm_customers_path, notice: 'Customer was successfully updated.' } format.json { render :show, status: :ok, location: @crm_customer } diff --git a/app/controllers/reports/daily_sale_controller.rb b/app/controllers/reports/daily_sale_controller.rb index 86e60702..34a3b5e2 100644 --- a/app/controllers/reports/daily_sale_controller.rb +++ b/app/controllers/reports/daily_sale_controller.rb @@ -5,19 +5,7 @@ class Reports::DailySaleController < BaseReportController @sale_data = Sale.daily_sales_list(from,to) @tax = SaleTax.get_tax(from,to) end - - # @locations = Location.all - # branch,from, to, report_type = get_date_range_from_params - - # @location = Location.find_by_id(current_location) - # @sale_data = Sale.daily_sales_report(current_location,from,to) - # @tax = SaleT.get_tax(current_location,from,to) - - # if @sale_data.blank? && @tax.blank? && request.post? - # flash.now[:notice] = "No data available for selected filters" - # end - def show end diff --git a/app/controllers/reports/sale_item_controller.rb b/app/controllers/reports/sale_item_controller.rb new file mode 100644 index 00000000..40aea618 --- /dev/null +++ b/app/controllers/reports/sale_item_controller.rb @@ -0,0 +1,14 @@ +class Reports::SaleItemController < BaseReportController + + def index + + from, to, report_type = get_date_range_from_params + + @sale_data = Sale.get_by_range_by_saleitems(from,to,Sale::SALE_STATUS_COMPLETED,report_type) + end + + def show + + end + +end \ No newline at end of file diff --git a/app/models/sale.rb b/app/models/sale.rb index 999577d7..5e0691f4 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -16,6 +16,14 @@ class Sale < ApplicationRecord scope :open_invoices, -> { where("sale_status = 'new' and receipt_date BETWEEN '#{DateTime.now.utc.end_of_day}' AND '#{DateTime.now.utc.beginning_of_day}'") } + REPORT_TYPE = { + "daily" => 0, + "monthly" => 1, + "yearly" => 2 + } + + SALE_STATUS_COMPLETED = "completed" + def generate_invoice_from_booking(booking_id, requested_by) booking = Booking.find(booking_id) status = false @@ -328,6 +336,40 @@ class Sale < ApplicationRecord return daily_total end +def self.get_by_range_by_saleitems(from,to,status,report_type) + + query = Sale.select(" + mi.item_code as code,(SUM(i.qty) * i.unit_price) as grand_total, + SUM(i.qty) as total_item," + + " i.unit_price as unit_price, + mi.name as product_name, + mc.name as menu_category_name, + mc.id as menu_category_id ") + .group('mi.id') + .order("mi.menu_category_id") + + query = query.joins("JOIN sale_items i ON i.sale_id = sales.sale_id + JOIN menu_items mi ON i.product_code = mi.item_code" + + " JOIN menu_categories mc ON mc.id = mi.menu_category_id + JOIN employees ea ON ea.id = sales.cashier_id") + + + query = query.where("receipt_date between ? and ? and sale_status=?",from,to,status) + + + + case report_type.to_i + when REPORT_TYPE["daily"] + return query + when REPORT_TYPE["monthly"] + + return query.group("MONTH(date)") + when REPORT_TYPE["yearly"] + return query.group("YEAR(date)") + end + +end + private def generate_custom_id diff --git a/app/pdf/receipt_bill_pdf.rb b/app/pdf/receipt_bill_pdf.rb index 6cacc391..dfecfdf0 100644 --- a/app/pdf/receipt_bill_pdf.rb +++ b/app/pdf/receipt_bill_pdf.rb @@ -33,7 +33,7 @@ class ReceiptBillPdf < Prawn::Document all_total(sale_data) if member_info != nil - member_info(member_info) + member_info(member_info,customer_name) end footer end @@ -61,14 +61,14 @@ class ReceiptBillPdf < Prawn::Document end move_down 5 - y_position = cursor - bounding_box([0,y_position], :width =>self.label_width, :height => self.item_height) do - text "Customer:", :size => self.item_font_size,:align => :left - end - 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 + # bounding_box([0,y_position], :width =>self.label_width, :height => self.item_height) do + # text "Customer:", :size => self.item_font_size,:align => :left + # end + # 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 bounding_box([0,y_position], :width =>self.label_width, :height => self.item_height) do @@ -203,19 +203,32 @@ class ReceiptBillPdf < Prawn::Document end # show member information - def member_info(member_info) + def member_info(member_info,customer_name) move_down 7 + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do + text "Customer", :size => self.item_font_size,:align => :left + end + bounding_box([self.item_description_width,y_position], :width =>self.label_width) do + text "#{ customer_name }" , :size => self.item_font_size,:align => :right + end + move_down 5 + if member_info["status"] == true member_info["data"].each do |res| - move_down 5 - y_position = cursor - bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do - text "#{ res["accountable_type"] }", :size => self.item_font_size,:align => :left - end - bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "#{ res["balance"] }" , :size => self.item_font_size,:align => :right + if res["accountable_type"]== "RebateAccount" + + move_down 5 + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do + text "Rebate Balance", :size => self.item_font_size,:align => :left + end + bounding_box([self.item_description_width,y_position], :width =>self.label_width) do + text "#{ res["balance"] }" , :size => self.item_font_size,:align => :right + end + end end diff --git a/app/views/origami/home/index.html.erb b/app/views/origami/home/index.html.erb index ff83dad4..6b7b0c20 100644 --- a/app/views/origami/home/index.html.erb +++ b/app/views/origami/home/index.html.erb @@ -364,7 +364,7 @@ <%=@selected_item.grand_total rescue 0%> --> - + diff --git a/app/views/reports/daily_sale/_shift_sale_report_filter.html.erb b/app/views/reports/daily_sale/_shift_sale_report_filter.html.erb index 04e548da..3a5d788c 100644 --- a/app/views/reports/daily_sale/_shift_sale_report_filter.html.erb +++ b/app/views/reports/daily_sale/_shift_sale_report_filter.html.erb @@ -147,4 +147,5 @@ $(function(){ }); + \ No newline at end of file diff --git a/app/views/reports/daily_sale/index.html.erb b/app/views/reports/daily_sale/index.html.erb index 4aa0c841..a2403045 100644 --- a/app/views/reports/daily_sale/index.html.erb +++ b/app/views/reports/daily_sale/index.html.erb @@ -32,16 +32,16 @@ Sr.no Date - Daily Void Amount - Daily mpu Sales - Daily master Sales - Daily visa Sales - Daily jcb Sales - Daily paypar Sales - Daily Cash Sales - Daily Credit Sales - Daily FOC Sales - (Daily Discount) + Void Amount + Mpu Sales + Master Sales + Visa Sales + Jcb Sales + Paypar Sales + Cash Sales + Credit Sales + FOC Sales + (Discount) Grand Total +
Rounding Adj. Rounding Adj. Grand Total diff --git a/app/views/reports/daily_sale/index.xls.erb b/app/views/reports/daily_sale/index.xls.erb index dfcc18d4..67e76e3c 100644 --- a/app/views/reports/daily_sale/index.xls.erb +++ b/app/views/reports/daily_sale/index.xls.erb @@ -10,16 +10,16 @@ Sr.no Date - Daily Void Amount - Daily mpu Sales - Daily master Sales - Daily visa Sales - Daily jcb Sales - Daily paypar Sales - Daily Cash Sales - Daily Credit Sales - Daily FOC Sales - (Daily Discount) + Void Amount + Mpu Sales + Master Sales + Visa Sales + Jcb Sales + Paypar Sales + Cash Sales + Credit Sales + FOC Sales + (Discount) Grand Total +
Rounding Adj. Rounding Adj. Grand Total diff --git a/app/views/reports/daily_sale_report.html.erb b/app/views/reports/daily_sale_report.html.erb deleted file mode 100644 index 786951f5..00000000 --- a/app/views/reports/daily_sale_report.html.erb +++ /dev/null @@ -1,20 +0,0 @@ - - -
- <%= render :partial=>'shift_sale_report_filter', - :locals=>{ :period_type => true, :shift_name => false, :report_path =>reports_receipt_no_index_path} %> -
-
- -
-
- -
-
diff --git a/app/views/reports/_shift_sale_report_filter.html.erb b/app/views/reports/sale_item/_shift_sale_report_filter.html.erb similarity index 77% rename from app/views/reports/_shift_sale_report_filter.html.erb rename to app/views/reports/sale_item/_shift_sale_report_filter.html.erb index 1b4082f5..7f95b6b9 100644 --- a/app/views/reports/_shift_sale_report_filter.html.erb +++ b/app/views/reports/sale_item/_shift_sale_report_filter.html.erb @@ -18,7 +18,8 @@ -
+ +
@@ -143,69 +144,13 @@ $(function(){ $('#frm_report').submit(); // window.location = url; }); + + function export_to(path) +{ + var form_params = $("#frm_report").serialize(); + window.location = path+"?"+ form_params; +} - var item = $('#item').val(); - var payment_type = $('#payment_type'); - - if(item == 'order'){ - $('#cashier').hide(); - $('#waiter').show(); - if(payment_type){ - $('#payment_type').hide(); - } - } - else if(item == 'sale'){ - $('#waiter').hide(); - $('#cashier').show(); - } - else{ - $('#waiter').hide(); - $('#cashier').show(); - $("#item").val('sale'); - } }); -//Reset the form to pervious values -$("#branch").val(<%=params[:branch]%>); -$("#waiter").val("<%=params[:waiter]%>"); -$("#cashier").val(<%=params[:cashier]%>); -$("#product").val(<%=params[:product]%>); -$("#singer").val(<%=params[:singer]%>); -$("#item").val('<%=params[:item]%>'); -$("#guest_role").val('<%=params[:guest_role]%>'); - - -$("#from").val("<%=params[:from]%>"); -$("#to").val("<%=params[:to]%>"); -$("#sel_period").val(<%=params[:period]%>); -$("#sel_sale_type").val(<%=params[:sale_type]%>); - -<% if params[:period_type] == 1 || params[:period_type] == "1" %> - $("#rd_period_type_1").attr("checked","checked"); -<% else %> - $("#rd_period_type_0").attr("checked","checked"); -<% end %> -$(".btn-group button").removeClass("active"); -<% report_type = params[:report_type].blank? ? "0" : params[:report_type] %> -$("#btn_report_type_<%= report_type %>").addClass("active"); - -$('#item').change(function(){ - var item = $('#item').val(); - var payment_type = $('#payment_type'); - - if(item == 'sale'){ - $('#waiter').hide(); - $('#cashier').show(); - if(payment_type){ - $('#payment_type').show(); - } - } - else{ - $('#cashier').hide(); - $('#waiter').show(); - if(payment_type){ - $('#payment_type').hide(); - } - } -}); \ No newline at end of file diff --git a/app/views/reports/sale_item/index.html.erb b/app/views/reports/sale_item/index.html.erb new file mode 100644 index 00000000..cce5a210 --- /dev/null +++ b/app/views/reports/sale_item/index.html.erb @@ -0,0 +1,141 @@ + + +
+ <%= render :partial=>'shift_sale_report_filter', + :locals=>{ :period_type => true, :shift_name => false, :report_path =>reports_sale_item_index_path} %> +
+
+ +
+
+ +
+
+ +
+
+
+ + + + + + + + + + + + + + + + + + +
Date
Menu CategoryCodeProductTotal ItemUnit PriceRevenue
+
+
+
+ + \ No newline at end of file diff --git a/app/views/reports/sale_item/index.xls.erb b/app/views/reports/sale_item/index.xls.erb new file mode 100644 index 00000000..dfcc18d4 --- /dev/null +++ b/app/views/reports/sale_item/index.xls.erb @@ -0,0 +1,116 @@ +
+
+ + + <% if params[:from]%> + + + + <% end %> + + + + + + + + + + + + + + + + + + + <% unless @sale_data.empty? %> + + + <% void = 0 %> + <% mpu = 0 %> + <% master = 0 %> + <% visa = 0 %> + <% jcb = 0 %> + <% paypar = 0 %> + <% cash = 0 %> + <% credit = 0 %> + <% foc = 0 %> + <% discount = 0 %> + <% total = 0 %> + <% grand_total = 0 %> + <% count = 1 %> <% rounding_adj = 0 %> + <% @sale_data.each do |sale| %> + <% void += sale[:void_amount] %> + <% mpu += sale[:mpu_amount] %> + <% master += sale[:master_amount] %> + <% visa += sale[:visa_amount] %> + <% jcb += sale[:jcb_amount] %> + <% paypar += sale[:paypar_amount] %> + <% cash += sale[:cash_amount] %> + <% credit += sale[:credit_amount] %> + <% foc += sale[:foc_amount] %> + <% discount += sale[:total_discount] %> + <% total += sale[:grand_total].to_f + sale[:rounding_adj].to_f %> + <% grand_total += sale[:grand_total].to_f %> + <% rounding_adj += sale[:rounding_adj].to_f %> + + + + + + + + + + + + + + + + + + <% count = count + 1 %> + <% end %> + + + + + + + + + + + + + + + + + + <% total_tax = 0 %> + <% unless @tax.empty? %> + <% @tax.each do |tax| %> + <% total_tax += tax.tax_amount.to_f %> + + + + + + + <% end %> + <% net = total - total_tax %> + + + + + + <% end %> + + <% end %> +
Sale (<%= params[:from] rescue '-' %> - <%= params[:to] rescue '-'%>)
Sr.noDateDaily Void AmountDaily mpu SalesDaily master SalesDaily visa SalesDaily jcb SalesDaily paypar SalesDaily Cash SalesDaily Credit SalesDaily FOC Sales(Daily Discount)Grand Total +
Rounding Adj.
Rounding Adj.Grand Total
<%= count %><%= sale[:sale_date].strftime("#{sale[:sale_date].day.ordinalize} %b") rescue '-' %><%= number_with_delimiter(sprintf("%.2f",sale[:void_amount]), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",sale[:mpu_amount]), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",sale[:master_amount]), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",sale[:visa_amount]), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",sale[:jcb_amount]), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",sale[:paypar_amount]), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",sale[:cash_amount]), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",sale[:credit_amount]), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",sale[:foc_amount]), :delimiter => ',') rescue '-'%>(<%= number_with_delimiter(sprintf("%.2f",sale[:total_discount]), :delimiter => ',') rescue '-'%>)<%= number_with_delimiter(sprintf("%.2f",sale[:grand_total].to_f + sale[:rounding_adj].to_f ), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",sale[:rounding_adj].to_f), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",sale[:grand_total]), :delimiter => ',') rescue '-'%>
Total<%= number_with_delimiter(sprintf("%.2f",mpu_amount), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",master_amount), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",visa_amount), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",jcb_amount), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",paypar_amount), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",cash), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",credit), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",foc), :delimiter => ',') rescue '-'%>(<%= number_with_delimiter(sprintf("%.2f",discount), :delimiter => ',') rescue '-'%>)<%= number_with_delimiter(sprintf("%.2f",total), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",rounding_adj), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",grand_total), :delimiter => ',') rescue '-'%>
<%= tax.tax_name rescue '-'%><%= number_with_delimiter(sprintf("%.2f",tax.tax_amount), :delimiter => ',') rescue '-'%> 
Net Amount<%= number_with_delimiter(sprintf("%.2f",net), :delimiter => ',') rescue '-'%> 
+
+
\ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 6253a95f..7bb463ee 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -212,6 +212,7 @@ Rails.application.routes.draw do namespace :reports do resources :receipt_no, :only => [:index, :show] resources :daily_sale, :only => [:index, :show] + resources :sale_item, :only => [:index, :show] # resources :sales, :only => [:index, :show] # resources :orders, :only => [:index, :show] # resources :customers, :only => [:index, :show]