From 3d838bc989b662793a817c02a99b645f77186e67 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Thu, 22 Jun 2017 13:35:20 +0630 Subject: [PATCH] update report and customer --- app/controllers/crm/customers_controller.rb | 4 +- .../reports/daily_sale_controller.rb | 4 + .../reports/receipt_no_controller.rb | 4 + .../reports/sale_item_controller.rb | 5 + app/views/api/customers/index.json.jbuilder | 2 +- app/views/api/customers/show.json.jbuilder | 2 +- .../crm/customers/_crm_customer.json.jbuilder | 2 +- app/views/crm/customers/index.html.erb | 8 +- app/views/crm/customers/show.json.jbuilder | 3 +- app/views/origami/customers/index.html.erb | 8 +- app/views/reports/sale_item/index.xls.erb | 246 ++++++++++-------- config/initializers/mime_types.rb | 1 + 12 files changed, 161 insertions(+), 128 deletions(-) diff --git a/app/controllers/crm/customers_controller.rb b/app/controllers/crm/customers_controller.rb index 646f6475..ce585686 100644 --- a/app/controllers/crm/customers_controller.rb +++ b/app/controllers/crm/customers_controller.rb @@ -46,7 +46,7 @@ class Crm::CustomersController < BaseCrmController end #get customer amount - @customer = Customer.find(params[:id]) + @customer = Customer.find(params[:id]) @response = Customer.get_membership_transactions(@customer) #end customer amount @@ -201,6 +201,6 @@ end def customer_params params.require(:customer).permit(:name, :company, :contact_no, :email, - :date_of_birth,:salution,:gender,:nrc_no,:address,:card_no) + :date_of_birth,:salutation,:gender,:nrc_no,:address,:card_no) end end diff --git a/app/controllers/reports/daily_sale_controller.rb b/app/controllers/reports/daily_sale_controller.rb index 6e1eb85a..ba453f55 100644 --- a/app/controllers/reports/daily_sale_controller.rb +++ b/app/controllers/reports/daily_sale_controller.rb @@ -4,6 +4,10 @@ class Reports::DailySaleController < BaseReportController from, to ,report_type = get_date_range_from_params @sale_data = Sale.daily_sales_list(from,to) @tax = SaleTax.get_tax(from,to) + respond_to do |format| + format.html + format.xls + end end def show diff --git a/app/controllers/reports/receipt_no_controller.rb b/app/controllers/reports/receipt_no_controller.rb index 86c8d981..d85c7d57 100644 --- a/app/controllers/reports/receipt_no_controller.rb +++ b/app/controllers/reports/receipt_no_controller.rb @@ -8,6 +8,10 @@ class Reports::ReceiptNoController < BaseReportController puts to @sale_data = Sale.get_receipt_no_list(from,to) @sale_data = Kaminari.paginate_array(@sale_data).page(params[:page]).per(50) + respond_to do |format| + format.html + format.xls + end end def show diff --git a/app/controllers/reports/sale_item_controller.rb b/app/controllers/reports/sale_item_controller.rb index 1da31aff..eb7d3b86 100644 --- a/app/controllers/reports/sale_item_controller.rb +++ b/app/controllers/reports/sale_item_controller.rb @@ -5,6 +5,11 @@ class Reports::SaleItemController < BaseReportController 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) + + respond_to do |format| + format.html + format.xls + end end def show diff --git a/app/views/api/customers/index.json.jbuilder b/app/views/api/customers/index.json.jbuilder index 2c3c07a7..0d1d37e7 100644 --- a/app/views/api/customers/index.json.jbuilder +++ b/app/views/api/customers/index.json.jbuilder @@ -1,3 +1,3 @@ -json.array! @customers, :id, :name, :company, :contact_no,:salution, +json.array! @customers, :id, :name, :company, :contact_no,:salutation, :gender,:nrc_no,:address,:card_no, :membership_type, :membership_id, :created_at diff --git a/app/views/api/customers/show.json.jbuilder b/app/views/api/customers/show.json.jbuilder index db56961b..acf54ac1 100644 --- a/app/views/api/customers/show.json.jbuilder +++ b/app/views/api/customers/show.json.jbuilder @@ -1,4 +1,4 @@ -json.extract! @customer, :id, :name, :company, :contact_no,:salution, +json.extract! @customer, :id, :name, :company, :contact_no,:salutation, :gender,:nrc_no,:address,:card_no, :membership_type, :membership_id, :created_at json.invoices do diff --git a/app/views/crm/customers/_crm_customer.json.jbuilder b/app/views/crm/customers/_crm_customer.json.jbuilder index c80c1716..1b1b237e 100644 --- a/app/views/crm/customers/_crm_customer.json.jbuilder +++ b/app/views/crm/customers/_crm_customer.json.jbuilder @@ -1,2 +1,2 @@ -json.extract! crm_customer, :id, :name, :company, :contact_no, :email, :date_of_birth, :membership_id, :membership_type, :membership_authentication_code, :created_at, :updated_at +json.extract! crm_customer, :id, :name, :company, :contact_no, :email, :date_of_birth, :membership_id, :membership_type, :membership_authentication_code, :created_at, :updated_at,:salutation, :gender,:nrc_no,:address,:card_no json.url crm_customer_url(crm_customer, format: :json) diff --git a/app/views/crm/customers/index.html.erb b/app/views/crm/customers/index.html.erb index e7b47460..3678008e 100644 --- a/app/views/crm/customers/index.html.erb +++ b/app/views/crm/customers/index.html.erb @@ -120,7 +120,7 @@ $(document).on('click',".customer_tr",function(){ $('#customer_company').val(data.company); $('#customer_contact_no').val(data.contact_no); $('#customer_email').val(data.email); - $('#customer_salution').val(data.salution); + $('#customer_salutation').val(data.salutation); $('#customer_nrc_no').val(data.nrc_no); $('#customer_card_no').val(data.card_no); $('#customer_address').val(data.address); @@ -133,11 +133,11 @@ $(document).on('click',".customer_tr",function(){ $('.female').prop( "checked", true ) } - if(data.salution == 'Mr') { + if(data.salutation == 'Mr') { $('.mr').prop( "checked", true ) - }else if(data.salution == 'Miss') { + }else if(data.salutation == 'Miss') { $('.miss').prop( "checked", true ) - }else if(data.salution == 'Mrs'){ + }else if(data.salutation == 'Mrs'){ $('.mrs').prop( "checked", true ) }else{ $('.mdm').prop( "checked", true ) diff --git a/app/views/crm/customers/show.json.jbuilder b/app/views/crm/customers/show.json.jbuilder index d41edb5d..86901801 100644 --- a/app/views/crm/customers/show.json.jbuilder +++ b/app/views/crm/customers/show.json.jbuilder @@ -1,5 +1,4 @@ json.extract! @crm_customer, :id, :name, :company, :contact_no, :email, :date_of_birth, :membership_id, :membership_type, :membership_authentication_code, - :created_at, :updated_at, - :salution, :gender,:nrc_no,:address,:card_no + :salutation, :gender,:nrc_no,:address,:card_no json.url crm_customer_url(@crm_customer, format: :json) diff --git a/app/views/origami/customers/index.html.erb b/app/views/origami/customers/index.html.erb index 5539b42b..8a811073 100644 --- a/app/views/origami/customers/index.html.erb +++ b/app/views/origami/customers/index.html.erb @@ -225,7 +225,7 @@ $('.select > option[value="'+data.membership_id+'"]').attr('selected','selected'); $('.membership_authentication_code').val(data.membership_authentication_code); - $('#customer_salution').val(data.salution); + $('#customer_salutation').val(data.salutation); $('#customer_nrc_no').val(data.nrc_no); if (data.gender == 'Male') { @@ -234,11 +234,11 @@ $('.female').prop( "checked", true ) } - if (data.salution == 'Mr') { + if (data.salutation == 'Mr') { $('.mr').prop( "checked", true ) - } else if(data.salution == 'Miss') { + } else if(data.salutation == 'Miss') { $('.miss').prop( "checked", true ) - }else if(data.salution == 'Mrs'){ + }else if(data.salutation == 'Mrs'){ $('.mrs').prop( "checked", true ) }else{ $('.mdm').prop( "checked", true ) diff --git a/app/views/reports/sale_item/index.xls.erb b/app/views/reports/sale_item/index.xls.erb index dfcc18d4..2807ec3f 100644 --- a/app/views/reports/sale_item/index.xls.erb +++ b/app/views/reports/sale_item/index.xls.erb @@ -1,116 +1,136 @@ -
-
- - - <% 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 %> + + + + + + + +
+<% unless @sale_data.blank? %> -
- - - - - - - - - - - - - - +
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 '-'%>
+ - <% total_tax = 0 %> - <% unless @tax.empty? %> - <% @tax.each do |tax| %> - <% total_tax += tax.tax_amount.to_f %> - - - - - - - <% end %> - <% net = total - total_tax %> - - - - - - <% end %> - + <% if !params[:from].blank?%> + + + + <% end %> + <% if @shift_from %> + + <% if @shift_data.employee %> + <% cashier_name = !@shift_data.nil? ? @shift_data.employee.name : '-' %> + <% end %> + + + <% end %> + + + + + + + + + + + + + <% acc_arr = Array.new %> + <% cate_arr = Array.new %> + + <% sub_total = 0.0 %> + <% count = 0%> + <% total_price = 0.0 %> + <% cate_count = 0 %> + <% acc_count = 0%> + <% grand_total = 0%> + <% total_discount = 0.0 %> + + <% @sale_data.order("total_item desc").each do |sale| %> + + <% if !acc_arr.include?(sale.account_id) %> + + + + + + + <% acc_arr.push(sale.account_id) %> + + <% end %> + + + <% if !cate_arr.include?(sale.menu_category_id) %> + + <% cate_arr.push(sale.menu_category_id) %> + <% else %> + <% end %> -
<%= tax.tax_name rescue '-'%><%= number_with_delimiter(sprintf("%.2f",tax.tax_amount), :delimiter => ',') rescue '-'%> 
Net Amount<%= number_with_delimiter(sprintf("%.2f",net), :delimiter => ',') rescue '-'%> 
From Date : <%= params[:from] %> , To Date : <%= params[:to] %>
Shift Name = <%= @shift_from %> - <%= @shift_to %> ( <%= cashier_name %> )
 Menu CategoryCodeProductTotal ItemUnit PriceRevenue
<%= sale.account_name %> Total Price By <%= sale.account_name %> + <% @totalByAccount.each do |account, total| %> + <% if sale.account_id == account %> + <%= total %> + <% end %> + <% end %> +
 <%= sale.menu_category_name %> 
-
-
\ No newline at end of file + <%= sale.code rescue '-' %> + <% if @item_table == 'sale' %> + <% if sale.item_remark == 'FOC' %> + <%= '[PROMO] '.to_s + sale.product_name.to_s rescue '-' %> + <% elsif sale.item_remark == 'FOC ITEM' %> + <%= '[DIS:QTY] '.to_s + sale.product_name.to_s rescue '-' %> + <% elsif sale.item_remark == 'DISCOUNT' %> + <%= '[DIS:TP] '.to_s + sale.product_name.to_s rescue '-' %> + <% else %> + <%= sale.product_name.to_s rescue '-' %> + <% end %> + <% if sale.item_remark == 'DISCOUNT' %> + - + - + <%= sale.total_price.abs rescue '-' %> + <% total_price += sale.total_price %> + <% else %> + <%= sale.total_item.abs rescue '-' %> + <%= sale.unit_price rescue '-' %> + <%= sale.grand_total.abs rescue '-' %> + <% end %> + <% else %> + <%= sale.product_name.to_s rescue '-' %> + <%= sale.total_item.abs rescue '-' %> + <%= sale.unit_price rescue '-' %> + <%= sale.grand_total.abs rescue '-' %> + <% end %> + + + + <% @menu_cate_count.each do |key,value| %> + <% if sale.menu_category_id == key %> + <% count = count + 1 %> + <% sub_total += sale.grand_total %> + <% if count == value %> + +   + Sub Total + <%= sub_total + total_price %> + + <% sub_total = 0.0%> + <% total_discount = total_discount + total_price %> + <% total_price = 0.0%> + <% count = 0%> + <% end %> + <% end %> + <% end %> + + <% grand_total += sale.grand_total%> + <% end %> + +   + Grand Total + <%= grand_total + total_discount %> + + + +<% end %> + + + \ No newline at end of file diff --git a/config/initializers/mime_types.rb b/config/initializers/mime_types.rb index dc189968..3859c754 100644 --- a/config/initializers/mime_types.rb +++ b/config/initializers/mime_types.rb @@ -2,3 +2,4 @@ # Add new mime types for use in respond_to blocks: # Mime::Type.register "text/richtext", :rtf +Mime::Type.register 'application/vnd.ms-excel', :xls