浏览代码

Utility report

Jacqueline Maldonado 7 年之前
父节点
当前提交
d68400b1bc

+ 30 - 0
app/controllers/reports_controller.rb

@@ -2,6 +2,7 @@ class ReportsController < ApplicationController
   ##--- Breadcrum_rails
   add_breadcrumb "Reporte de mínimos y máximos", :min_max_path, only: :min_max
   add_breadcrumb "Reporte de compras y egresos por mes", :purchases_per_month_path, only: :purchases_per_month
+  add_breadcrumb "Reporte de utilidades", :utilities_report_path, only: :utilities_report
 
   def min_max
     @pointsales = Pointsale.activos
@@ -52,4 +53,33 @@ class ReportsController < ApplicationController
       end
     end
   end
+
+  def utilities_report
+    if params[:start_date].present? && params[:end_date].present?
+      @start_date = DateTime.parse(params[:start_date]).in_time_zone(Time.zone).beginning_of_day + 1.days
+      @end_date = DateTime.parse(params[:end_date]).in_time_zone(Time.zone).end_of_day + 1.days
+      @sales =
+        if params[:pointsale].blank?
+          Sale.joins(:products, products: :categories).where.not(status: 1).where(created_at: @start_date..@end_date).order("id DESC")
+        else
+          Pointsale.find(params[:pointsale]).sales.joins(:products, products: :categories).where.not(status: 1).where(created_at: @start_date..@end_date).order("id DESC")
+        end
+      categories = Category.find(params[:subcategory].present? ? params[:subcategory] : params[:category]) if params[:category].present?
+      @sales = @sales.where(categories: { id: [categories.id, categories.children.ids].flatten }) if categories.present?
+      @total_prods = 0
+      @total_utility = 0
+      @sales.each do |sale|
+        @total_prods += sale.sales_details.sum(:quantity)
+        cost = 0
+        sale.sales_details.each do |detail|
+          cost += (detail.product.price_base * detail.quantity)
+        end
+        utility = sale.total - cost
+        @total_utility += utility
+      end
+      respond_to do |format|
+        format.js
+      end
+    end
+  end
 end

+ 8 - 0
app/helpers/sales_helper.rb

@@ -22,4 +22,12 @@ module SalesHelper
       content_tag(:span, "PAGO PENDIENTE", class: "label label-default")
     end
   end
+
+  def sale_utility(details)
+    total = 0
+    details.each do |detail|
+      total += (detail.product.price_base * detail.quantity)
+    end
+    total
+  end
 end

+ 25 - 0
app/views/reports/_report_utilities.html.erb

@@ -0,0 +1,25 @@
+<tr class="<%= sale.cancelled? ? 'danger' : '' %>">
+  <td><%= l(sale.date_sale, :format => '%d/%m/%Y') %></td>
+  <td><%= sale.sale_code %> </td>
+  <td><%= @pointsale.present? ? @pointsale.name : sale.get_pointsale.name %> </td>
+  <td><%= sale.sales_details.sum(:quantity).to_i %> </td>
+  <td>
+    <% if sale.saletype == "credit" && sale.credit_note.blank? %>
+    Crédito
+    <% elsif sale.saletype == "credit" && sale.credit_note.present? %>
+    Crédito/vale
+    <% elsif sale.saletype == "cash" %>
+    Contado
+    <% elsif sale.saletype == "reserved" %>
+    Apartado
+    <% end %>
+  </td>
+  <td><%= sale_status(sale) %></td>
+  <td><%= number_to_currency(sale.amount, precision: 2) %></td>
+  <td><%= number_to_currency(sale.tax, precision: 2) %></td>
+  <td><%= number_to_currency(sale.discount, precision: 2) %></td>
+  <td><%= number_to_currency(sale.total, precision: 2) %></td>
+  <% cost = sale_utility(sale.sales_details) %>
+  <td><%= number_to_currency(cost, precision: 2) %></td>
+  <td><%= number_to_currency(sale.total - cost, precision: 2) %></td>
+</tr>

+ 208 - 0
app/views/reports/utilities_report.html.erb

@@ -0,0 +1,208 @@
+<!-- BEGIN CONTAINER -->
+<div class="page-container">
+  <!-- BEGIN CONTENT -->
+  <div class="page-content-wrapper">
+    <!-- BEGIN CONTENT BODY -->
+    <!-- BEGIN PAGE HEAD-->
+    <div class="page-head">
+      <div class="container-fluid">
+        <!-- BEGIN PAGE TITLE -->
+        <div class="page-title">
+          <h1>Reporte de utilidades por periodo </h1>
+        </div>
+        <!-- END PAGE TITLE -->
+      </div>
+    </div>
+    <!-- END PAGE HEAD-->
+    <!-- BEGIN PAGE CONTENT BODY -->
+    <div class="page-content">
+      <div class="container-fluid">
+        <!-- BEGIN PAGE BREADCRUMBS -->
+        <ul class="page-breadcrumb breadcrumb">
+          <%= render_breadcrumbs :tag => :li, :separator => ' <i class="fa fa-circle"></i> ' %>
+        </ul>
+        <!-- END PAGE BREADCRUMBS -->
+        <div class="search-page search-content-3">
+          <div class="row">
+            <div class="col-md-12">
+              <%= form_tag(utilities_report_path, method: :get, remote: true) do |f| %>
+                <div class="search-filter bordered">
+                <!-- <h4 class=" uppercase form-section"> Búsqueda de producto </h4> <hr> -->
+                  <div class="form-group">
+                    <div class="row">
+                      <div class="col-md-3 col-sm-4">
+                        <div class="search-label uppercase">Punto de venta</div>
+                        <div class="col-md-12">
+                          <%= select_tag "pointsale", options_from_collection_for_select(Pointsale.vigentes, :id, :name), include_blank: "Todos", class: "form-control  input-medium" %>
+                        </div>
+                      </div>
+                      <div class="col-md-3 col-sm-4">
+                        <div class="search-label uppercase"> Del </div>
+                        <div class="col-md-6">
+                          <div class="input-group input-medium date date-picker" data-date-format="dd/mm/yyyy">
+                            <%= text_field_tag "start_date", l(Date.today.beginning_of_month, format: '%d/%m/%Y'), class: "form-control" %>
+                            <span class="input-group-addon">
+                              <span class="glyphicon glyphicon-calendar"></span>
+                            </span>
+                          </div>
+                        </div>
+                      </div>
+                      <div class="col-md-3 col-sm-4">
+                        <div class="search-label uppercase"> Al </div>
+                        <div class="col-md-6">
+                          <div class="input-group input-medium date date-picker" data-date-format="dd/mm/yyyy">
+                            <%= text_field_tag "end_date", l(Date.today.end_of_month, format: '%d/%m/%Y'), class: "form-control" %>
+                            <span class="input-group-addon">
+                              <span class="glyphicon glyphicon-calendar"></span>
+                            </span>
+                          </div>
+                        </div>
+                      </div>
+                    </div>
+                  </div>
+                  <div class="form-group">
+                    <div class="row">
+                      <div class="col-md-3 col-sm-4">
+                        <!-- categoria -->
+                        <div class="search-label uppercase">Línea</div>
+                        <div class="col-md-12">
+                          <div class="select2-bootstrap-prepend">
+                            <%= select_tag "category", options_from_collection_for_select(Category.activos_padre, :id, :category), include_blank: "Todas",  class: "form-control select2-allow-clear-todas", onchange: 'getSubCategories($(this).val());'%>
+                          </div>
+                        </div>
+                      </div>
+                      <div class="col-md-3 col-sm-4">
+                        <!-- sub- categoria -->
+                        <div class="search-label uppercase">Sublínea</div>
+                        <div class="col-md-12">
+                          <div class="select2-bootstrap-prepend">
+                            <%= collection_select("", :subcategory, ({}), :id, :category, options = { include_blank: "Todas" }, html_options = { class: 'form-control select2-allow-clear-todas input-medium' }) %>
+                          </div>
+                        </div>
+                      </div>
+                      <div class="col-md-3 col-sm-4" style="margin-top: 20px">
+                        <%= submit_tag 'Filtrar', { class: "btn green bold btn-block", style: 'margin:0px' } %>
+                      </div>
+                    </div>
+                  </div>
+                </div>
+              <% end %>
+            </div>
+          </div>
+        </div>
+        <!-- BEGIN PAGE CONTENT INNER -->
+        <div class="page-content-inner">
+          <div class="portlet light">
+            <div class="portlet-title">
+              <div class="caption">
+                <span class="caption-subject font-blue-dark bold uppercase">Ventas e ingresos</span>
+              </div>
+            </div>
+            <div class="portlet-body form" id="sales_content">
+              <div class="product_track_search">
+                <div class="row">
+                  <div class="col-md-12">
+                    <div class="note note-success hidden" id="note_info">
+                      <h4 class="block">Detalle de utilidades del periodo: <strong><span id="start_date_display"></span></strong> al <strong><span id="end_date_display"></span></strong></h4>
+                    </div>
+                    <div class="col-xs-offset-1 col-xs-5">
+                      <div class="text-center well" id="container_total_prods" style="margin-bottom: 0px">
+                        <div class="font-grey-mint font-sm">NÚMERO DE VENTAS</div>
+                        <div class="uppercase font-hg font-blue-sharp" id="sales_quantity">0</div>
+                      </div>
+                    </div>
+                    <div class="col-xs-offset-1 col-xs-5">
+                      <div class="text-center well" id="container_total_prods" style="margin-bottom: 0px">
+                        <div class="font-grey-mint font-sm">PRODUCTOS VENDIDOS</div>
+                        <div class="uppercase font-hg font-blue-sharp" id="prods_total">0</div>
+                      </div>
+                    </div>
+                  </div>
+                </div>
+                <div class="row" style="margin-top: 20px">
+                  <div class="col-md-12">
+                    <div class="col-xs-offset-1 col-xs-5">
+                      <div class="text-center well" id="container_total_prods" style="margin-bottom: 0px">
+                        <div class="font-grey-mint font-sm">TOTAL UTILIDAD</div>
+                        <div class="uppercase font-hg font-green" id="total_utility">0</div>
+                      </div>
+                    </div>
+                  </div>
+                </div>
+
+                <br>
+                <div class="row">
+                  <div class="col-md-12">
+                    <h4 class="form-section">Desglose de ventas</h4>
+                    <table class="table table-striped table-bordered table-hover tableadvanced" id="utility_report_table">
+                      <thead>
+                        <tr>
+                          <th>Fecha</th>
+                          <th>Folio</th>
+                          <th>Punto<br>de<br>venta</th>
+                          <th>Productos</th>
+                          <th>Tipo</th>
+                          <th>Status</th>
+                          <th>Subtotal</th>
+                          <th>IVA</th>
+                          <th>Descto.</th>
+                          <th>Total</th>
+                          <th>Costo<br>total</th>
+                          <th>Utilidad</th>
+                        </tr>
+                      </thead>
+                      <tbody>
+                      </tbody>
+                    </table>
+                  </div>
+                </div>
+              </div>
+            </div>
+          </div>
+        </div>
+        <!-- END PAGE CONTENT INNER -->
+      </div>
+    </div>
+    <!-- END PAGE CONTENT BODY -->
+    <!-- END CONTENT BODY -->
+  </div>
+  <!-- END CONTENT -->
+</div>
+<script>
+  function getSubCategories(value) {
+    $('#_subcategory').html('');
+    $('#_subcategory').select2("destroy").select2({
+      placeholder: 'Seleccione',
+      "language": {
+        "noResults": function(){
+          return "No se encontraron coincidencias";
+        }
+      }
+    });
+    $('#_subcategory').select2('val', null);
+    if(value) {
+      $.ajax({
+        type: "get",
+        url: '/getcategories/' + value,
+        dataType: 'json',
+        success: function(data) {
+          if(data.length > 0) {
+            $('#_subcategory').append('<option></option>')
+            for(i in data) {
+              $('#_subcategory').append("<option value='" + data[i].id + "'>" + data[i].category + "</option>")
+            }
+            $('#_subcategory').select2({
+              allowClear: true,
+              placeholder: 'Todas',
+              "language": {
+                "noResults": function(){
+                  return "No se encontraron coincidencias";
+                }
+              }
+            });
+          }
+        }
+      });
+    }
+  }
+</script>

+ 15 - 0
app/views/reports/utilities_report.js.erb

@@ -0,0 +1,15 @@
+var utility_table = $('#utility_report_table').DataTable();
+$('#utility_report_table').dataTable().fnClearTable();
+
+<% @sales.each_with_index do |sale, key| %>
+  var row = $('<%= j render partial: "report_utilities", locals: { sale: sale } %>');
+  utility_table.row.add(row).draw();
+<% end %>
+
+$('#start_date_display').html("<%= l @start_date.to_date, format: :long %>");
+$('#end_date_display').html("<%= l @end_date.to_date, format: :long %>");
+$('#note_info').removeClass('hidden');
+
+$('#prods_total').html('<%= @total_prods.to_i %>');
+$('#sales_quantity').html('<%= @sales.count %>');
+$('#total_utility').html(accounting.formatMoney('<%= @total_utility %>'));

+ 14 - 12
config/navigation.rb

@@ -47,8 +47,8 @@ SimpleNavigation::Configuration.run do |navigation|
         sub_nav.dom_attributes = { class: 'dropdown-menu pull-left' }
         sub_nav.item :list_customers, 'Lista de clientes', customers_path
         sub_nav.item :divider_after_list_customers, '#', divider: true
-        sub_nav.item :debtor_customers, 'Clientes deudores', debtors_path if (can? :debtors, Customer)
-        sub_nav.item :special_prices, 'Descuentos especiales por cliente', new_special_price_path if (can? :create, SpecialPrice)
+        sub_nav.item :debtor_customers, 'Clientes deudores', debtors_path if can? :debtors, Customer
+        sub_nav.item :special_prices, 'Descuentos especiales por cliente', new_special_price_path if can? :create, SpecialPrice
       end
     end
     # productos
@@ -62,9 +62,9 @@ SimpleNavigation::Configuration.run do |navigation|
         sub_nav.item :list_categories, 'Lista de líneas de producto', categories_path
         sub_nav.item :divider_before_products, '#', divider: true
       end
-      sub_nav.item :list_products, 'Lista de productos', products_path if (can? :index, Product)
-      sub_nav.item :stock_by_pointsale, 'Existencias', stock_by_pointsale_path if (can? :read, AvailableProduct)
-      sub_nav.item :list_waste_of_products, 'Lista de mermas de productos', product_wastes_path if (can? :read, ProductWaste)
+      sub_nav.item :list_products, 'Lista de productos', products_path if can? :index, Product
+      sub_nav.item :stock_by_pointsale, 'Existencias', stock_by_pointsale_path if can? :read, AvailableProduct
+      sub_nav.item :list_waste_of_products, 'Lista de mermas de productos', product_wastes_path if can? :read, ProductWaste
       if can? :read, Purchase
         sub_nav.item :divider_before_purchases, '#', divider: true
         sub_nav.item :list_products, 'Lista de compras', purchases_path
@@ -73,7 +73,7 @@ SimpleNavigation::Configuration.run do |navigation|
         sub_nav.item :divider_before_purchases, '#', divider: true
         sub_nav.item :list_suppliers, 'Lista de proveedores', suppliers_path
       end
-      if (can? :product_track, Product)
+      if can? :product_track, Product
         sub_nav.item :divider_before_purchases, '#', divider: true
         sub_nav.item :product_track, 'Seguimiento de productos', product_track_path
       end
@@ -85,11 +85,11 @@ SimpleNavigation::Configuration.run do |navigation|
         sub_nav.item :list_pointsales, 'Lista de puntos de venta', pointsales_path
         sub_nav.item :divider_before_pointsales, '#', divider: true
       end
-      sub_nav.item :list_cash_registers, 'Lista de cajas', cash_registers_path if (can? :index, CashRegister)
-      sub_nav.item :list_cash_outs, 'Lista de cortes de caja', cash_outs_path if (can? :read, CashOut)
+      sub_nav.item :list_cash_registers, 'Lista de cajas', cash_registers_path if can? :index, CashRegister
+      sub_nav.item :list_cash_outs, 'Lista de cortes de caja', cash_outs_path if can? :read, CashOut
       sub_nav.item :divider_before_pointsales, '#', divider: true
-      sub_nav.item :list_promotions, 'Promociones', promotions_path if (can? :read, Promotion)
-      if (can? :read, Seller)
+      sub_nav.item :list_promotions, 'Promociones', promotions_path if can? :read, Promotion
+      if can? :read, Seller
         sub_nav.item :divider_before_sellers, '#', divider: true
         sub_nav.item :list_sellers, 'Lista de vendedores', sellers_path
       end
@@ -135,10 +135,12 @@ SimpleNavigation::Configuration.run do |navigation|
       primary.item :reports, { icon: "fa fa-bar-chart", text: "Reportes" }, '#', class: 'menu-dropdown classic-menu-dropdown' do |sub_nav|
         sub_nav.dom_attributes = { class: 'dropdown-menu pull-left' }
         sub_nav.item :sales_per_month, 'Ventas por mes', sales_per_month_report_path
-        sub_nav.item :divider_after_month_sales, '#', divider: true
+        sub_nav.item :divider_after_sales_report, '#', divider: true
+        sub_nav.item :purchases_per_month, 'Compras por mes', purchases_per_month_path
+        sub_nav.item :divider_after_purchases_report, '#', divider: true
         sub_nav.item :minmax_report, 'Mínimos y Máximos', min_max_path
         sub_nav.item :divider_after_minmax_report, '#', divider: true
-        sub_nav.item :purchases_per_month, 'Compras por mes', purchases_per_month_path
+        sub_nav.item :utilities_report, 'Utilidades', utilities_report_path
       end
     end
     # soporte

+ 1 - 0
config/routes.rb

@@ -253,6 +253,7 @@ Rails.application.routes.draw do
   ## reports
   get "min_max" => "reports#min_max"
   get 'purchases_per_month' => 'reports#purchases_per_month'
+  get 'utilities_report' => 'reports#utilities_report'
 
   ## soporte
   get "contact_support" => "supports#contact_support"