|
@@ -29,7 +29,7 @@ class StockByPointsaleDatatable
|
|
|
(available.product.category.parent_id.zero? ? available.product.category.category : available.product.category.parent.category),
|
|
(available.product.category.parent_id.zero? ? available.product.category.category : available.product.category.parent.category),
|
|
|
(available.product.category.parent_id != 0 ? available.product.category.category : ' '),
|
|
(available.product.category.parent_id != 0 ? available.product.category.category : ' '),
|
|
|
available.stock.round,
|
|
available.stock.round,
|
|
|
- "<h3> $#{get_price_sale(available.product)} </h3>"
|
|
|
|
|
|
|
+ "<h3> #{get_price_sale(available.product)} </h3>"
|
|
|
].compact
|
|
].compact
|
|
|
else
|
|
else
|
|
|
arr = [
|
|
arr = [
|
|
@@ -88,13 +88,42 @@ class StockByPointsaleDatatable
|
|
|
stock = stock.page(page).per_page(per_page)
|
|
stock = stock.page(page).per_page(per_page)
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
- unless params[:busqueda].blank?
|
|
|
|
|
- stock = stock.where("products.sku ilike :search or products.name ilike :search", search: "%#{params[:busqueda]}%")
|
|
|
|
|
- end
|
|
|
|
|
|
|
+ search = params[:busqueda]
|
|
|
|
|
|
|
|
|
|
+ unless search.blank?
|
|
|
|
|
+ stock = stock.where(prepare_query_string(search))
|
|
|
|
|
+ end
|
|
|
stock
|
|
stock
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
|
|
+ def prepare_query_string(query)
|
|
|
|
|
+ product_query =
|
|
|
|
|
+ if query.include? ':' # search with attributes
|
|
|
|
|
+ query_array = query.split(':')
|
|
|
|
|
+ @product_name = query_array[0]
|
|
|
|
|
+ query_array.shift # delete the name of the product from the array to iterate the attributes
|
|
|
|
|
+ attrs_query_string = ''
|
|
|
|
|
+ query_array.each do |attribute|
|
|
|
|
|
+ next if attribute.nil?
|
|
|
|
|
+ attr_type =
|
|
|
|
|
+ case attribute[0]
|
|
|
|
|
+ when 'c'
|
|
|
|
|
+ 'colors'
|
|
|
|
|
+ when 't'
|
|
|
|
|
+ 'sizes'
|
|
|
|
|
+ when 'e'
|
|
|
|
|
+ 'styles'
|
|
|
|
|
+ end
|
|
|
|
|
+ attribute[0] = "" # delete the attribute type character
|
|
|
|
|
+ attrs_query_string.concat(" AND products.attributes_json::json->>'#{attr_type}' ilike '%#{attribute}%'")
|
|
|
|
|
+ end
|
|
|
|
|
+ "products.sku ilike '%#{@product_name}%' or products.name ilike '%#{@product_name}%' #{attrs_query_string}"
|
|
|
|
|
+ else
|
|
|
|
|
+ "products.sku ilike '%#{query}%' or products.name ilike '%#{query}%'"
|
|
|
|
|
+ end
|
|
|
|
|
+ product_query
|
|
|
|
|
+ end
|
|
|
|
|
+
|
|
|
def page
|
|
def page
|
|
|
params[:start].to_i / per_page + 1
|
|
params[:start].to_i / per_page + 1
|
|
|
end
|
|
end
|