Forráskód Böngészése

Merge branch 'chemi_branch' of SML/pos-boutique into master

Jose Miguel Ledon 6 éve
szülő
commit
e7526f035d

+ 11 - 8
app/controllers/available_products_controller.rb

@@ -133,16 +133,17 @@ class AvailableProductsController < ApplicationController
       location_id = params[:location][2, params[:location].length] unless location.blank?
 
       if (current_user.usertype == 'S' && location.blank?) || (!location.blank? && location.first == 'W')
-        stock = WarehouseStock.activos.(:warehouse, :categories).where(warehouse_id: (location_id.blank? ? current_user.warehouse_id : location_id)).where('stock > 0')
+        stock = WarehouseStock.activos.includes(:warehouse, :categories).where(warehouse_id: (location_id.blank? ? current_user.warehouse_id : location_id)).where('stock > 0')
       elsif (current_user.usertype != 'S' && location.blank?) || (!location.blank? && location.first == 'P')
-        stock = AvailableProduct.activos.(:pointsale, :categories).where(pointsale_id: (location_id.blank? ? current_user.pointsale_id : location_id)).where('stock > 0')
+        stock = AvailableProduct.activos.includes(:pointsale, :categories).where(pointsale_id: (location_id.blank? ? current_user.pointsale_id : location_id)).where('stock > 0')
       end
 
       if sub_category.present?
         stock = stock.joins(:categories).where('categories.id = ?', sub_category)
       elsif category.present?
-        subs_ids = Category.activos.where(parent_id: category).pluck(:id)
-        stock = stock.joins(:categories).where('categories.id IN (?)', subs_ids)
+        category = Category.find(category)
+        children = category.children
+        stock = stock.joins(:categories).where('categories.id IN (?)', children.present? ? children.pluck(:id) : category.id)
       end
 
       if size != 0
@@ -181,8 +182,9 @@ class AvailableProductsController < ApplicationController
     if sub_category.present?
       stock = stock.joins(:categories).where('categories.id = ?', sub_category)
     elsif category.present?
-      subs_ids = Category.activos.where(parent_id: category).pluck(:id)
-      stock = stock.joins(:categories).where('categories.id IN (?)', subs_ids)
+      category = Category.find(category)
+      children = category.children
+      stock = stock.joins(:categories).where('categories.id IN (?)', children.present? ? children.pluck(:id) : category.id)
     end
 
     total_prods = stock.sum(:stock)
@@ -204,8 +206,9 @@ class AvailableProductsController < ApplicationController
     if sub_category.present?
       stock = stock.joins(:categories).where('categories.id = ?', sub_category)
     elsif category.present?
-      subs_ids = Category.activos.where(parent_id: category).pluck(:id)
-      stock = stock.joins(:categories).where('categories.id IN (?)', subs_ids)
+      category = Category.find(category)
+      children = category.children
+      stock = stock.joins(:categories).where('categories.id IN (?)', children.present? ? children.pluck(:id) : category.id)
     end
 
     obj = Hash.new

+ 3 - 0
app/controllers/products_controller.rb

@@ -317,6 +317,9 @@ class ProductsController < ApplicationController
 
     file_name = "etiquetas_#{Time.now.to_i}"
     pdf = render_to_string pdf: file_name, template: "products/print_labels.pdf.erb", layout: 'labels.html.erb', locals: { objs: @products }, show_as_html: params.key?('debug'), page_width: '62mm', page_height: '300mm'
+    unless Dir.exist?(Rails.public_path.join("pdfs"))
+      Dir.mkdir(Rails.public_path.join("pdfs"))
+    end
     save_path = Rails.public_path.join("pdfs", "#{file_name}.pdf")
     File.open(save_path, 'wb') do |file|
       file << pdf

+ 3 - 2
app/datatables/stock_by_pointsale_datatable.rb

@@ -80,8 +80,9 @@ class StockByPointsaleDatatable
     if sub_category.present?
       stock = stock.joins(:categories).where('categories.id = ?', sub_category)
     elsif category.present?
-      subs_ids = Category.activos.where(parent_id: category).pluck(:id)
-      stock = stock.joins(:categories).where('categories.id IN (?)', subs_ids)
+      category = Category.find(category)
+      children = category.children
+      stock = stock.joins(:categories).where('categories.id IN (?)', children.present? ? children.pluck(:id) : category.id)
     end
 
     if params[:length].to_i != -1

+ 3 - 0
app/models/product.rb

@@ -500,6 +500,9 @@ class Product < ActiveRecord::Base
       barcode_generated = format('%07d', id)
       self.barcode = barcode_generated
       save_path = Rails.public_path.join('barcodes', "#{barcode_generated}.png")
+      unless Dir.exist?(Rails.public_path.join("barcodes"))
+        Dir.mkdir(Rails.public_path.join("barcodes"))
+      end
       File.open(save_path, 'wb') { |f| f.write Barby::Code39.new(barcode_generated).to_png(height: 50, margin: 5) }
     end
   end

+ 1 - 1
app/views/available_products/stock_by_pointsale.pdf.erb

@@ -3,7 +3,7 @@
 	<h4 style="margin-top:5px;margin-bottom:5px;">Fecha: <%= l(Time.now, :format => '%d/%m/%y %I:%M %p') %> </h4>
 
 	<% if category.present? %>
-		<h4 style="margin-top:5px;margin-bottom:5px;">Línea: <%= Category.find(category).category %> </h4>
+		<h4 style="margin-top:5px;margin-bottom:5px;">Línea: <%= category.category %> </h4>
 	<% end %>
 
 	<% if sub_category.present? %>