浏览代码

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

Jacque 7 年之前
父节点
当前提交
4ef72d3489

+ 163 - 170
app/assets/javascripts/config.js

@@ -422,185 +422,178 @@ var TableWithCheckbox = function () {
 
 
 var tableWithCheckboxAjax = function () {
-		//var arrayForRows = [];
-		var initTableCheckboxAjax = function (tableClass, columns, order, extraParams, arrayForRows) {
-				var table = $(tableClass);
-
-				/* Table tools samples: https://www.datatables.net/release-datatables/extras/TableTools/ */
-				 $.fn.dataTableExt.oStdClasses.sFilterInput = "form-control input-xlarge input-inline";
-				/* Set tabletools buttons and button container */
-
-
-				var oTable = table.dataTable({
-					    "processing": true,
-					    "serverSide": true,
-						"ajax": {
-						    "url": $(tableClass).data('source'),
-						    "data": function ( d ) {
-						    	d.busqueda = $(tableClass).closest('.dataTables_wrapper').find('input[type="search"]').val();
-						        // son los parametros custom de cada tabla, se envia el obj.
-								for(var param in extraParams){
-							 		d[param] = extraParams[param];
-								}
-					    	}
-					    },
-					    "drawCallback": function( settings ) {
-					        arrayForRows.length = 0;
-					    },
-					    'columns': columns,
-			          	'columnDefs': [{
-				            'targets': 0,
-				            'searchable':false,
-				            'orderable':false,
-				            'className': 'dt-body-center',
-			             	'render': function (data, type, full, meta) {
-			                 	return '<input type="checkbox" name="id[]">';
-			             	}
-			          	}],
-						"language": {
-								"aria": {
-										"sortAscending": ": activate to sort column ascending",
-										"sortDescending": ": activate to sort column descending"
-								},
-								"sProcessing": "Cargando...",
-								"emptyTable": "No hay informacion en la tabla",
-								"info": "Mostrando del _START_ al _END_ de _TOTAL_ registros",
-								"infoEmpty": "No se encontraron coincidencias",
-								"infoFiltered": "(filtrado un total de _MAX_ registros)",
-								"lengthMenu": "Mostrar _MENU_ registros",
-								"search": "Buscar:",
-								"zeroRecords": "No se encontraron coincidencias",
-								"paginate": {
-		                            "sPrevious": "Ant",
-		                            "sNext": "Sig"
-		                        }
-						},
-						'order': [order, 'asc'],
-					      "rowCallback": function(row, data, dataIndex){
-					         // Get row ID
-					         var rowId = data[0];
-
-					         // If row ID is in the list of selected row IDs
-					         if($.inArray(rowId, arrayForRows) !== -1){
-					            $(row).find('input[type="checkbox"]').prop('checked', true);
-					            $(row).addClass('selected');
-					         }
-					      },
-						"lengthMenu": [
-								[20, 50, 75, 100,	-1],
-								[20, 50, 75, 100,	"Todos"] // change per page values here
-						],
-						// set the initial value
-						"pageLength": 20,
-						"dom": "<'row'<'col-md-6 col-sm-12'l><'col-md-6 col-sm-12'f>r><'table-scrollable't><'row'<'col-md-5 col-sm-12'i><'col-md-7 col-sm-12'p>>" // horizobtal scrollable datatable
-
-				});
-
-				var tableWrapper = $('.tableadvanced_wrapper'); // datatable creates the table wrapper by adding with id {your_table_jd}_wrapper
-
-				tableWrapper.find('.dataTables_length select').select2(); // initialize select2 dropdown
-
-
-				var table = $(tableClass).DataTable();
-					// Handle click on checkbox
-				   $(tableClass + ' tbody').on('click', 'input[type="checkbox"]', function(e){
-				      var $row = $(this).closest('tr');
-
-				      // Get row data
-				      var data = table.row($row).data();
-
-				      // Get row ID
-				      // var rowId = data[0];
-				      var rowId = $row.attr('id').substring($row.attr('id').indexOf('_') + 1, $row.attr('id').length);
-				      // Determine whether row ID is in the list of selected row IDs
-				      var index = $.inArray(rowId, arrayForRows);
-
-				      // If checkbox is checked and row ID is not in list of selected row IDs
-				      if(this.checked && index === -1){
-				         arrayForRows.push(rowId);
-
-				      // Otherwise, if checkbox is not checked and row ID is in list of selected row IDs
-				      } else if (!this.checked && index !== -1){
-				         arrayForRows.splice(index, 1);
-				      }
-
-				      if(this.checked){
-				         $row.addClass('selected');
-				        //$row.css('background-color', '#34495E');
-				      } else {
-				        //$row.css('background-color', '#F9F9F9');
-				        $row.removeClass('selected');
-				      }
+	//var arrayForRows = [];
+	var initTableCheckboxAjax = function (tableClass, columns, order, extraParams, arrayForRows) {
+		var table = $(tableClass);
+
+		/* Table tools samples: https://www.datatables.net/release-datatables/extras/TableTools/ */
+		$.fn.dataTableExt.oStdClasses.sFilterInput = "form-control input-xlarge input-inline";
+		/* Set tabletools buttons and button container */
+		var oTable = table.dataTable({
+	    "processing": true,
+	    "serverSide": true,
+			"ajax": {
+		    "url": $(tableClass).data('source'),
+		    "data": function ( d ) {
+		    	d.busqueda = $(tableClass).closest('.dataTables_wrapper').find('input[type="search"]').val();
+		    	d.pointsale = $('#pointsale').val();
+	        // son los parametros custom de cada tabla, se envia el obj.
+					for(var param in extraParams){
+				 		d[param] = extraParams[param];
+					}
+	    	}
+	    },
+	    "drawCallback": function( settings ) {
+        arrayForRows.length = 0;
+	    },
+	    'columns': columns,
+    	'columnDefs': [{
+        'targets': 0,
+        'searchable':false,
+        'orderable':false,
+        'className': 'dt-body-center',
+       	'render': function (data, type, full, meta) {
+           	return '<input type="checkbox" name="id[]">';
+       	}
+    	}],
+			"language": {
+				"aria": {
+					"sortAscending": ": activate to sort column ascending",
+					"sortDescending": ": activate to sort column descending"
+				},
+				"sProcessing": "Cargando...",
+				"emptyTable": "No hay informacion en la tabla",
+				"info": "Mostrando del _START_ al _END_ de _TOTAL_ registros",
+				"infoEmpty": "No se encontraron coincidencias",
+				"infoFiltered": "(filtrado un total de _MAX_ registros)",
+				"lengthMenu": "Mostrar _MENU_ registros",
+				"search": "Buscar:",
+				"zeroRecords": "No se encontraron coincidencias",
+				"paginate": {
+          "sPrevious": "Ant",
+          "sNext": "Sig"
+        }
+			},
+			'order': [order, 'asc'],
+      "rowCallback": function(row, data, dataIndex) {
+        // Get row ID
+        var rowId = data[0];
+         // If row ID is in the list of selected row IDs
+          if($.inArray(rowId, arrayForRows) !== -1){
+            $(row).find('input[type="checkbox"]').prop('checked', true);
+            $(row).addClass('selected');
+          }
+	      },
+				"lengthMenu": [
+					[20, 50, 75, 100,	-1],
+					[20, 50, 75, 100,	"Todos"] // change per page values here
+				],
+				// set the initial value
+				"pageLength": 20,
+				"dom": "<'row'<'col-md-6 col-sm-12'l><'col-md-6 col-sm-12'f>r><'table-scrollable't><'row'<'col-md-5 col-sm-12'i><'col-md-7 col-sm-12'p>>" // horizobtal scrollable datatable
+		});
 
-				      // Update state of "Select all" control
-				      updateDataTableSelectAllCtrl(table);
+		var tableWrapper = $('.tableadvanced_wrapper'); // datatable creates the table wrapper by adding with id {your_table_jd}_wrapper
+		tableWrapper.find('.dataTables_length select').select2(); // initialize select2 dropdown
+
+		var table = $(tableClass).DataTable();
+		// Handle click on checkbox
+	  $(tableClass + ' tbody').on('click', 'input[type="checkbox"]', function(e){
+      var $row = $(this).closest('tr');
+
+      // Get row data
+      var data = table.row($row).data();
+
+      // Get row ID
+      // var rowId = data[0];
+      var rowId = $row.attr('id').substring($row.attr('id').indexOf('_') + 1, $row.attr('id').length);
+      // Determine whether row ID is in the list of selected row IDs
+      var index = $.inArray(rowId, arrayForRows);
+
+      // If checkbox is checked and row ID is not in list of selected row IDs
+      if(this.checked && index === -1) {
+        arrayForRows.push(rowId);
+      	// Otherwise, if checkbox is not checked and row ID is in list of selected row IDs
+      } else if (!this.checked && index !== -1) {
+        arrayForRows.splice(index, 1);
+      }
 
-				      // Prevent click event from propagating to parent
-				      e.stopPropagation();
-				   });
+      if(this.checked){
+        $row.addClass('selected');
+        //$row.css('background-color', '#34495E');
+      } else {
+        //$row.css('background-color', '#F9F9F9');
+        $row.removeClass('selected');
+      }
 
-				   // Handle click on table cells with checkboxes
-				   $(tableClass).on('click', 'tbody td, thead th:first-child', function(e){
-				      $(this).parent().find('input[type="checkbox"]').trigger('click');
-				   });
+      // Update state of "Select all" control
+      updateDataTableSelectAllCtrl(table);
 
-				   // Handle click on "Select all" control
-				   $('thead input[name="select_all"]', table.table().container()).on('click', function(e){
-				      if(this.checked){
-				         $(tableClass + ' tbody input[type="checkbox"]:not(:checked)').trigger('click');
-				      } else {
-				         $(tableClass + ' tbody input[type="checkbox"]:checked').trigger('click');
-				      }
+      // Prevent click event from propagating to parent
+      e.stopPropagation();
+	  });
 
-				      // Prevent click event from propagating to parent
-				      e.stopPropagation();
-				   });
+	  // Handle click on table cells with checkboxes
+	  $(tableClass).on('click', 'tbody td, thead th:first-child', function(e){
+	    $(this).parent().find('input[type="checkbox"]').trigger('click');
+	  });
 
-				   // Handle table draw event
-				   table.on('draw', function(){
-				      // Update state of "Select all" control
-				      updateDataTableSelectAllCtrl(table);
-				   });
+	  // Handle click on "Select all" control
+	  $('thead input[name="select_all"]', table.table().container()).on('click', function(e){
+	    if(this.checked){
+        $(tableClass + ' tbody input[type="checkbox"]:not(:checked)').trigger('click');
+      } else {
+        $(tableClass + ' tbody input[type="checkbox"]:checked').trigger('click');
+      }
 
-				   function updateDataTableSelectAllCtrl(table){
-					   var $table             = table.table().node();
-					   var $chkbox_all        = $('tbody input[type="checkbox"]', $table);
-					   var $chkbox_checked    = $('tbody input[type="checkbox"]:checked', $table);
-					   var chkbox_select_all  = $('thead input[name="select_all"]', $table).get(0);
-
-					   // If none of the checkboxes are checked
-					   if($chkbox_checked.length === 0){
-					      chkbox_select_all.checked = false;
-					      if('indeterminate' in chkbox_select_all){
-					         chkbox_select_all.indeterminate = false;
-					      }
-
-					   // If all of the checkboxes are checked
-					   } else if ($chkbox_checked.length === $chkbox_all.length){
-					      chkbox_select_all.checked = true;
-					      if('indeterminate' in chkbox_select_all){
-					         chkbox_select_all.indeterminate = false;
-					      }
-
-					   // If some of the checkboxes are checked
-					   } else {
-					      chkbox_select_all.checked = true;
-					      if('indeterminate' in chkbox_select_all){
-					         chkbox_select_all.indeterminate = true;
-					      }
-					   }
-					}
+      // Prevent click event from propagating to parent
+      e.stopPropagation();
+	  });
+
+	  // Handle table draw event
+	  table.on('draw', function(){
+      // Update state of "Select all" control
+      updateDataTableSelectAllCtrl(table);
+	  });
+
+		function updateDataTableSelectAllCtrl(table){
+		  var $table = table.table().node();
+		  var $chkbox_all = $('tbody input[type="checkbox"]', $table);
+		  var $chkbox_checked = $('tbody input[type="checkbox"]:checked', $table);
+		  var chkbox_select_all = $('thead input[name="select_all"]', $table).get(0);
+
+		  // If none of the checkboxes are checked
+		  if($chkbox_checked.length === 0){
+	      chkbox_select_all.checked = false;
+	      if('indeterminate' in chkbox_select_all){
+	        chkbox_select_all.indeterminate = false;
+	      }
+
+		  	// If all of the checkboxes are checked
+		  } else if ($chkbox_checked.length === $chkbox_all.length){
+	      chkbox_select_all.checked = true;
+	      if('indeterminate' in chkbox_select_all){
+	        chkbox_select_all.indeterminate = false;
+	      }
+
+		  	// If some of the checkboxes are checked
+		  } else {
+	      chkbox_select_all.checked = true;
+	      if('indeterminate' in chkbox_select_all){
+	        chkbox_select_all.indeterminate = true;
+	      }
+		  }
 		}
-		return {
-				//main function to initiate the module
-				init: function (tableClass, columns, order, data, arrayForRows) {
-					if (!$().dataTable) {
-							return;
-					}
-					initTableCheckboxAjax(tableClass, columns, order, data, arrayForRows);
-
+	}
+	return {
+			//main function to initiate the module
+			init: function (tableClass, columns, order, data, arrayForRows) {
+				if (!$().dataTable) {
+					return;
 				}
-		};
+				initTableCheckboxAjax(tableClass, columns, order, data, arrayForRows);
+			}
+	};
 }();
 
 

+ 18 - 2
app/controllers/available_products_controller.rb

@@ -6,7 +6,15 @@ class AvailableProductsController < ApplicationController
     @showcolumns = "minMax"
     # se utiliza para mandarle al datatable el numero de columnas y en que orden se deben de acomodar
     @column_definition = [{ "data": "0" }, { "data": "1" }, { "data": "2" }, { "data": "3" }, { "data": "4" }, { "data": "5" }, { "data": "6" }, { "data": "7" }].to_json
-    @location_id = current_user.pointsale_id.present? ? current_user.pointsale_id : current_user.warehouse_id
+    @location_id =
+      if current_user.usertype == "G"
+        current_user.pointsale_id
+      elsif current_user.usertype == "S"
+        current_user.warehouse_id
+      else
+        @pointsales = Pointsale.activos
+        @pointsales.first.id
+      end
     respond_to do |format|
       format.html
       format.json { render json: StocksDatatable.new(view_context, current_user, @showcolumns) }
@@ -15,7 +23,15 @@ class AvailableProductsController < ApplicationController
 
   def initial_stock
     @showcolumns = "initial"
-    @location_id = current_user.pointsale_id.present? ? current_user.pointsale_id : current_user.warehouse_id
+    @location_id =
+      if current_user.usertype == "G"
+        current_user.pointsale_id
+      elsif current_user.usertype == "S"
+        current_user.warehouse_id
+      else
+        @pointsales = Pointsale.activos
+        @pointsales.first.id
+      end
     # se utiliza para mandarle al datatable el numero de columnas y en que orden se deben de acomodar
     @column_definition = [{ "data": "0" }, { "data": "1" }, { "data": "2" }, { "data": "3" }, { "data": "4" }, { "data": "5" }, { "data": "6" }].to_json
 

+ 1 - 6
app/controllers/pointsales_controller.rb

@@ -153,12 +153,7 @@ class PointsalesController < ApplicationController
     respond_to do |format|
       @products = JSON.parse params[:products]
       @products.each do |product|
-        available = AvailableProduct.new
-        available.product_id = product['id']
-        available.pointsale_id = params[:pointsale_id]
-        available.stock_min = 0
-        available.stock_max = 0
-        available.stock = product['stock']
+        available = AvailableProduct.new(product_id: product['id'], pointsale_id: params[:pointsale_id], stock_min: 0, stock_max: 0, stock: product['stock'], price_sale: product['price'].to_f > 0 ? product['price'].to_f : Product.find(product['id']).price_sale)
         available.save
       end
       format.json { head :ok }

+ 4 - 1
app/controllers/users_controller.rb

@@ -21,7 +21,9 @@ class UsersController < ApplicationController
     set_usertypes
   end
 
-  def edit; end
+  def edit
+    set_usertypes
+  end
 
   def update
     respond_to do |format|
@@ -32,6 +34,7 @@ class UsersController < ApplicationController
         format.html { redirect_to users_path, success: message }
         format.json { render :show, status: :ok, location: @user }
       else
+        set_usertypes
         format.html { render :edit }
         format.json { render json: @user.errors, status: :unprocessable_entity }
       end

+ 2 - 1
app/datatables/available_products_datatable.rb

@@ -9,7 +9,7 @@ class AvailableProductsDatatable
   def as_json(*)
     {
       sEcho: params[:sEcho].to_i,
-      iTotalRecords: @pointsale.products.activos_children.size,
+      iTotalRecords: params[:table] == 'in_pointsale' ? @pointsale.products.activos_children.size : products.total_entries,
       iTotalDisplayRecords: products.total_entries,
       aaData: data
     }
@@ -82,6 +82,7 @@ class AvailableProductsDatatable
         products = products.where('attributes_json ilike :attribute', attribute: "%#{attribute}%")
       end
     end
+
     products
   end
 

+ 22 - 35
app/datatables/stocks_datatable.rb

@@ -1,8 +1,5 @@
 class StocksDatatable
-
-  delegate :params, :image_tag,
-    :available_products_path, :products_initial_stock_path,
-    to: :@view
+  delegate :params, :image_tag, :available_products_path, :products_initial_stock_path, to: :@view
 
   def initialize(view, user, showcolumns)
     @view = view
@@ -10,13 +7,13 @@ class StocksDatatable
     @showcolumns = showcolumns
   end
 
-  def as_json(options = {})
-
-    if @current_user.usertype == 'S'
-      total = WarehouseStock.activos.where(:warehouse_id => @current_user.pointsale_id)
-    else
-      total = AvailableProduct.activos.where(:pointsale_id => @current_user.warehouse_id)
-    end
+  def as_json(_options = {})
+    total =
+      if @current_user.usertype == 'S'
+        WarehouseStock.activos.where(warehouse_id: @current_user.warehouse_id)
+      else
+        AvailableProduct.activos.where(pointsale_id: @current_user.pointsale_id.present? ? @current_user.pointsale_id : params[:pointsale])
+      end
 
     {
       sEcho: params[:sEcho].to_i,
@@ -26,53 +23,44 @@ class StocksDatatable
     }
   end
 
-private
+  private
 
   def data
-    stock.map do | available |
-      if available.product.img_product?
-        img = available.product.img_product.url(:small)
-      else
-        img = "/images/small/missing.png"
-      end
+    stock.map do |available|
+      img = available.product.img_product? ? available.product.img_product.url(:small) : "/images/small/missing.png"
       category = available.product.categories[0]
       {
         'DT_RowId' => "availableProduct_#{available.id}",
         '0' => '<input class="form-control checkboxes" type="checkbox"/>',
         '1' => (image_tag img),
         '2' => available.product.sku,
-        '3' => "#{available.product.name + '<br>' + available.product.display_attributes}",
-        '4' => (category.parent_id == 0 ? category.category : category.parent.category),
+        '3' => available.product.name + '<br>' + available.product.display_attributes,
+        '4' => (category.parent_id.zero? ? category.category : category.parent.category),
         '5' => (category.parent_id != 0 ? category.category : ' '),
         '6' => (@showcolumns == "minMax" ? available.stock_min : available.stock),
         '7' => (@showcolumns == "minMax" ? available.stock_max : nil)
-      }.compact.reject { |k, v| v.nil? }
+      }.compact.reject { |_k, v| v.nil? }
     end
   end
 
-
   def stock
     @stock ||= fetch_stock
   end
 
   def fetch_stock
-    if @current_user.usertype == 'S'
-      stock = WarehouseStock.activos.includes(:product, :categories).where(:warehouse_id => @current_user.warehouse_id).order('products.name')
-    else
-      stock = AvailableProduct.activos.includes(:product, :categories).where(:pointsale_id => @current_user.pointsale_id).order('products.name')
-    end
-
+    stock =
+      if @current_user.usertype == 'S'
+        WarehouseStock.activos.includes(:product, :categories).where(warehouse_id: @current_user.warehouse_id).order('products.name')
+      else
+        AvailableProduct.activos.includes(:product, :categories).where(pointsale_id: @current_user.pointsale_id.present? ? @current_user.pointsale_id : params[:pointsale]).order('products.name')
+      end
     stock = stock.page(page).per_page(per_page)
-
-    unless params[:busqueda].blank?
-      stock = stock.where("products.sku ilike :search or products.name ilike :search", search: "%#{params[:busqueda]}%").order('products.name')
-    end
-
+    stock = stock.where("products.sku ilike :search or products.name ilike :search", search: "%#{params[:busqueda]}%").order('products.name') unless params[:busqueda].blank?
     stock
   end
 
   def page
-    params[:start].to_i/per_page + 1
+    params[:start].to_i / per_page + 1
   end
 
   def per_page
@@ -87,5 +75,4 @@ private
   def sort_direction
     params[:sSortDir_0] == "desc" ? "desc" : "asc"
   end
-
 end

+ 5 - 5
app/models/product.rb

@@ -383,14 +383,14 @@ class Product < ActiveRecord::Base
       end_period = Date.current.end_of_month
     end
 
-    if user.usertype == 'A'
+    if user.usertype == "A" || user.usertype == "SS"
       quantities_top_products = SalesDetail.activos.joins(:sale, :product).where("sales.date_sale between ? and ?", beg_period, end_period).group('products.name').order('sum_quantity desc').limit(10).sum(:quantity)
       total_top_products = SalesDetail.activos.joins(:sale).where('sales.date_sale between ? and ?', beg_period, end_period).order('sum_quantity desc').limit(10).sum(:quantity)
       total_sold = SalesDetail.activos.joins(:sale).where('sales.date_sale between ? and ?', beg_period, end_period).sum(:quantity)
     elsif user.usertype == 'G'
-      quantities_top_products = user.pointsale.sales_details.joins(:sale, :product).where("sales.status != 1 and sales.date_sale between ? and ?", beg_period, end_period).group('products.name').order('sum_quantity desc').limit(10).sum(:quantity)
-      total_top_products = user.pointsale.sales_details.joins(:sale).where('sales.status != 1 and sales.date_sale between ? and ?', beg_period, end_period).order('sum_quantity desc').limit(10).sum(:quantity)
-      total_sold = user.pointsale.sales_details.joins(:sale).where('sales.status != 1 and sales.date_sale between ? and ?', beg_period, end_period).sum(:quantity)
+      quantities_top_products = user.pointsale.sales_details.joins(:sale, :product).where("sales.status != ? and sales.date_sale between ? and ?", 1, beg_period, end_period).group('products.name').order('sum_quantity desc').limit(10).sum(:quantity)
+      total_top_products = user.pointsale.sales_details.joins(:sale).where('sales.status != ? and sales.date_sale between ? and ?', 1, beg_period, end_period).order('sum_quantity desc').limit(10).sum(:quantity)
+      total_sold = user.pointsale.sales_details.joins(:sale).where('sales.status != ? and sales.date_sale between ? and ?', 1, beg_period, end_period).sum(:quantity)
     end
 
     others = total_sold - total_top_products
@@ -401,7 +401,7 @@ class Product < ActiveRecord::Base
   end
 
   def get_available_children(just_pointsales)
-    children = Product.where("parent_id = ? and status != 0 ", id).pluck(:id)
+    children = Product.vigentes.where("parent_id = ?", id).pluck(:id)
     if just_pointsales
       AvailableProduct.where("product_id IN (?)", children).joins(:pointsale).select(:pointsale_id, :name).distinct(:pointsale_id)
     else

+ 49 - 52
app/views/available_products/_form.html.erb

@@ -1,62 +1,62 @@
-<%= form_for(AvailableProduct.new, :html => {:class=>"form-horizontal", :id=> "available_products_form"}) do |f| %>
-  <div class="portlet-body form">
-    <div id="error_explanation"></div>
-
-      <table class="table table-striped table-bordered table-hover stock-table" id="pointsale_stock" data-source="<%= @showcolumns == 'initial' ?  products_initial_stock_path(@location_id, :format => 'json') : products_stock_path(@location_id, :format => 'json') %>">
-        <thead>
-          <tr>
-            <th class="text-center"><input name="select_all" value="1" id="select-all" type="checkbox" /></th>
-            <th>Imagen</th>
-            <th>SKU</th>
-            <th>Producto</th>
-            <th>Línea</th>
-            <th>Sublínea</th>
-            <% case @showcolumns
-              when "initial" %>
-                <th>Stock inicial</th>
-            <% when "minMax" %>
-                <th>Stock mínimo</th>
-                <th>Stock máximo</th>
-            <% end %>
-          </tr>
-        </thead>
-        <tbody>
-        </tbody>
-      </table>
-    </div>
+<div class="portlet-body form">
+  <div id="error_explanation"></div>
+    <table class="table table-striped table-bordered table-hover stock-table" id="pointsale_stock" data-source="<%= @showcolumns == 'initial' ?  products_initial_stock_path(@location_id, format: 'json') : products_stock_path(@location_id, format: 'json') %>">
+      <thead>
+        <tr>
+          <th class="text-center"><input name="select_all" value="1" id="select-all" type="checkbox" /></th>
+          <th>Imagen</th>
+          <th>SKU</th>
+          <th>Producto</th>
+          <th>Línea</th>
+          <th>Sublínea</th>
+          <% if @showcolumns == "initial" %>
+            <th>Stock inicial</th>
+          <% elsif @showcolumns == "minMax" %>
+            <th>Stock mínimo</th>
+            <th>Stock máximo</th>
+          <% end %>
+        </tr>
+      </thead>
+      <tbody>
+      </tbody>
+    </table>
   </div>
-<% end %>
+</div>
 
 <script type="text/javascript">
   var rows_selected = [];
   var tableClass = '.stock-table';
   var columns = "<%= @column_definition %>";
-  var tableColumns = JSON.parse(columns.replace(/&quot;/g,'"'));
+  var tableColumns = JSON.parse(columns.replace(/&quot;/g, '"'));
   var order = 3;
   var extraData = {};
 
+  $('#pointsale').on('change', function(e) {
+    $('#pointsale_stock').DataTable().draw();
+  });
+
   tableWithCheckboxAjax.init(tableClass, tableColumns, order, extraData, rows_selected);
 
-// $(document).on("page:change", function() {
-//   App.init();
-// });
+  // $(document).on("page:change", function() {
+  //   App.init();
+  // });
 
-toastr.options = {
-  "closeButton": false,
-  "debug": false,
-  "positionClass": "toast-bottom-right",
-  "onclick": null,
-  "showDuration": "1000",
-  "hideDuration": "1000",
-  "timeOut": "5000",
-  "extendedTimeOut": "1000",
-  "showEasing": "swing",
-  "hideEasing": "linear",
-  "showMethod": "fadeIn",
-  "hideMethod": "fadeOut"
-}
+  toastr.options = {
+    "closeButton": false,
+    "debug": false,
+    "positionClass": "toast-bottom-right",
+    "onclick": null,
+    "showDuration": "1000",
+    "hideDuration": "1000",
+    "timeOut": "5000",
+    "extendedTimeOut": "1000",
+    "showEasing": "swing",
+    "hideEasing": "linear",
+    "showMethod": "fadeIn",
+    "hideMethod": "fadeOut"
+  }
 
-function updateStock() {
+  function updateStock() {
   var min = parseInt($('#min_stock_general').val());
   var max = parseInt($('#max_stock_general').val());
   // checar por campos vacios
@@ -100,9 +100,9 @@ function updateStock() {
         });
     }
   }
-}
+  }
 
-function initialStock() {
+  function initialStock() {
   var initialStock = parseInt($('#initial_stock_input').val());
   if (initialStock || initialStock == 0) {
     if(rows_selected.length > 0) {
@@ -136,8 +136,5 @@ function initialStock() {
   } else {
     toastr["error"]("Error, NO puede quedar vacio el campo de stock inicial");
   }
-}
+  }
 </script>
-
-
-

+ 83 - 89
app/views/available_products/index.html.erb

@@ -1,100 +1,94 @@
-    <!-- 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>Productos disponibles</h1>
+<!-- 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>Productos disponibles</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">
+        <li>
+          <a href="/">Inicio</a>
+          <i class="fa fa-circle"></i>
+        </li>
+        <li>
+          <span> </span>
+        </li>
+      </ul>
+        <!-- END PAGE BREADCRUMBS -->
+        <!-- BEGIN PAGE CONTENT INNER -->
+      <div class="page-content-inner">
+        <div id="notice">
+          <% if success %>
+            <div class="alert alert-success">
+              <p><%= success %></p>
             </div>
-            <!-- END PAGE TITLE -->
-          </div>
+          <% elsif warning %>
+            <div class="alert alert-warning">
+              <p><%= warning %></p>
+            </div>
+          <% end %>
         </div>
-        <!-- END PAGE HEAD-->
-        <!-- BEGIN PAGE CONTENT BODY -->
-        <div class="page-content">
-          <div class="container-fluid">
-            <!-- BEGIN PAGE BREADCRUMBS -->
-            <ul class="page-breadcrumb breadcrumb">
-            <li>
-              <a href="/">Inicio</a>
-              <i class="fa fa-circle"></i>
-            </li>
-            <li>
-              <span> </span>
-            </li>
-          </ul> 
-            <!-- END PAGE BREADCRUMBS -->
-            <!-- BEGIN PAGE CONTENT INNER -->
-            <div class="page-content-inner">
-              <div id="notice">
-                <% if success %> 
-                <div class="alert alert-success">
-                  <p><%= success %></p>
-                </div>
-                <% elsif warning %>
-                <div class="alert alert-warning">
-                  <p><%= warning %></p>
+        <div class="row">
+          <%= form_for(@pointsale, html: { class: "form-horizontal" }) do |f| %>
+            <div class="col-md-6">
+              <div class="portlet light ">
+                <div class="portlet-title">
+                  <div class="caption">
+                    <i class="fa fa-list "></i>
+                    <span class="caption-subject bold uppercase">Productos disponibles</span>
+                  </div>
+                  <div class="actions">
+                  </div>
                 </div>
-                <% end %>
-              </div>
-              <div class="row">
-                <%= form_for(@pointsale, :html => {:class=>"form-horizontal"}) do |f| %>
-                <div class="col-md-6">
-                  <div class="portlet light ">
-                    <div class="portlet-title">
-                      <div class="caption">
-                        <i class="fa fa-list "></i>
-                        <span class="caption-subject bold uppercase">Productos disponibles</span>
-                      </div>
-                      <div class="actions">
-                        
-                      </div>
-                    </div>
-                    <div class="portlet-body">
-                      <div class="note note-info">
-                          <h4 class="block">Lista de productos disponibles</h4>
-                          <p> En esta lista se muestran todos los productos disponibles para su venta en forma general, dentro de la cuenta de administración. </p>
-                      </div>
-                      <table class="table table-striped table-bordered table-hover tablechecks">
-                        <thead>
-                          <tr>
-                            <th> <input type="checkbox" class="group-checkable" data-set=".tablechecks .checkboxes" /> </th>
-                            <th>SKU</th>
-                            <th>Producto</th>
-                            <th>Categorias</th>
-                            
-                          </tr>
-                        </thead>
-                        <tbody>
-                          <% @products.each do |product| %>
-                            <tr>  
-                              <td> <input type="checkbox" class="checkboxes" value="1" /> </td>
-                              <td><%= product.sku %></td>
-                              <td><%= product.name %> | <%= product.display_attributes %> </td>
-                              <td><%= product.categories.map { |cat| cat.category }.join(", ")  %></td>
-                              
-                            </tr>
-                          <% end %>
-                        </tbody>
-                      </table>
-                    </div>
+                <div class="portlet-body">
+                  <div class="note note-info">
+                    <h4 class="block">Lista de productos disponibles</h4>
+                    <p> En esta lista se muestran todos los productos disponibles para su venta en forma general, dentro de la cuenta de administración. </p>
                   </div>
+                  <table class="table table-striped table-bordered table-hover tablechecks">
+                    <thead>
+                      <tr>
+                        <th> <input type="checkbox" class="group-checkable" data-set=".tablechecks .checkboxes" /> </th>
+                        <th>SKU</th>
+                        <th>Producto</th>
+                        <th>Categorias</th>
+                      </tr>
+                    </thead>
+                    <tbody>
+                      <% @products.each do |product| %>
+                        <tr>
+                          <td> <input type="checkbox" class="checkboxes" value="1" /> </td>
+                          <td><%= product.sku %></td>
+                          <td><%= product.name %> | <%= product.display_attributes %> </td>
+                          <td><%= product.categories.map { |cat| cat.category }.join(", ") %></td>
+                        </tr>
+                      <% end %>
+                    </tbody>
+                  </table>
                 </div>
-                <% end %>
               </div>
             </div>
-            <!-- END PAGE CONTENT INNER -->
+            <% end %>
           </div>
         </div>
-        <!-- END PAGE CONTENT BODY -->
-        <!-- END CONTENT BODY -->
+        <!-- END PAGE CONTENT INNER -->
       </div>
-      <!-- END CONTENT -->
     </div>
-    <!-- END CONTAINER -->
-
-
+    <!-- END PAGE CONTENT BODY -->
+    <!-- END CONTENT BODY -->
+  </div>
+  <!-- END CONTENT -->
+</div>

+ 23 - 20
app/views/available_products/initial_stock.html.erb

@@ -17,36 +17,42 @@
     <!-- BEGIN PAGE CONTENT BODY -->
     <div class="page-content">
       <div class="container-fluid">
-        <%= link_to  root_path, {:class=>"btn blue-hoki pull-right margin-bottom-10"} do %>  <i class="fa fa-angle-left "></i> Regresar
-        <% end %>
         <!-- END PAGE BREADCRUMBS -->
+        <ul class="page-breadcrumb breadcrumb">
+          <%= render_breadcrumbs :tag => :li, :separator => ' <i class="fa fa-circle"></i> ' %>
+        </ul>
         <!-- BEGIN PAGE CONTENT INNER -->
         <div class="page-content-inner">
           <div id="notice"><%= notice %></div>
           <div class="row">
             <div class="col-md-12">
-              <div class="portlet light">  
+              <div class="portlet light">
                 <div class="portlet-body form">
-                  <div id="error_explanation"></div> 
-
+                  <div id="error_explanation"></div>
                   <!-- lista de productos -->
                   <h4 class="form-section"> Lista de productos</h4>
                   <div class="portlet-body">
-                    <div class="row"> 
+                    <div class="row">
+                      <% unless current_user.usertype == "G" %>
+                        <%= label_tag :pointsale, "Puntos de venta", class: "control-label col-md-1 col-sm-2" %>
+                        <div class="col-md-3 col-sm-4">
+                          <%= select_tag "pointsale", options_from_collection_for_select(@pointsales, :id, :name), class: "form-control input-medium" %>
+                        </div>
+                      <% end %>
                       <!-- stock minimo para los seleccionados -->
-                        <div class="col-md-8">
-                          <div class="form-group">
-                            <label class="col-md-1"> Stock inicial </label>          
-                            <div class="col-md-2">
-                              <input class="form-control" type="number" min="0" id="initial_stock_input">
-                            </div>
-                            <div class="col-md-2">
-                              <button type="button" class="btn btn-success" onclick="initialStock()"><i class="fa fa-save"></i>&nbsp&nbspGuardar cambios</button>                 
-                            </div>
-                          </div> 
+                      <div class="col-md-6 col-sm-6">
+                        <div class="form-group">
+                          <label class="col-md-3 col-sm-3"> Stock inicial </label>
+                          <div class="col-md-2 col-sm-3">
+                            <input class="form-control input-xsmall" type="number" min="0" id="initial_stock_input">
+                          </div>
+                          <div class="col-md-4 col-sm-5">
+                            <button type="button" class="btn btn-success" onclick="initialStock()"><i class="fa fa-save"></i>&nbsp&nbspGuardar cambios</button>
+                          </div>
                         </div>
+                      </div>
                     </div>
-                    <h4 class="form-section" style="margin-top: 5px; margin-bottom: 20px"></h4>   
+                    <h4 class="form-section" style="margin-top: 5px; margin-bottom: 20px"></h4>
                   </div>
                 </div>
                 <%= render 'form' %>
@@ -62,6 +68,3 @@
   </div>
   <!-- END CONTENT -->
 </div>
-<!-- END CONTAINER -->
-
-

+ 27 - 30
app/views/available_products/stock.html.erb

@@ -17,12 +17,10 @@
     <!-- BEGIN PAGE CONTENT BODY -->
     <div class="page-content">
       <div class="container-fluid">
-        <%= link_to  root_path, {:class=>"btn blue-hoki pull-right margin-bottom-10"} do %>  <i class="fa fa-angle-left "></i> Regresar
-        <% end %>
         <!-- BEGIN PAGE BREADCRUMBS -->
         <ul class="page-breadcrumb breadcrumb">
           <%= render_breadcrumbs :tag => :li, :separator => ' <i class="fa fa-circle"></i> ' %>
-      </ul>
+        </ul>
         <!-- END PAGE BREADCRUMBS -->
         <!-- BEGIN PAGE CONTENT INNER -->
         <div class="page-content-inner">
@@ -31,32 +29,34 @@
             <div class="col-md-12">
               <div class="portlet light">
                 <div class="portlet-body form">
-                    <div id="error_explanation"></div>
-
-                    <!-- lista de productos -->
-                    <h4 class="form-section"> Lista de productos</h4>
-                    <div class="portlet-body">
-
-                      <div class="row">
-                        <!-- stock minimo para los seleccionados -->
-                          <div class="col-md-offset-1 col-md-8">
-                            <div class="form-group">
-                              <label class="col-md-1"> Stock Mínimo </label>
-                              <div class="col-md-2">
-                                <input class="form-control" type="number" min="0" id="min_stock_general">
-                              </div>
-                              <label class="col-md-1"> Stock Máximo </label>
-                              <div class="col-md-2">
-                                <input class="form-control" type="number" min="0" id="max_stock_general">
-                              </div>
-                              <div class="col-md-2">
-                                <button type="button" class="btn btn-success" onclick="updateStock()"><i class="fa fa-save"></i>&nbsp&nbspGuardar cambios</button>
-                              </div>
-                            </div>
-                          </div>
+                  <div id="error_explanation"></div>
+                  <!-- lista de productos -->
+                  <h4 class="form-section"> Lista de productos</h4>
+                  <div class="portlet-body">
+                    <div class="row">
+                      <% unless current_user.usertype == "G" %>
+                        <%= label_tag :pointsale, "Puntos de venta", class: "control-label col-md-1 col-sm-2" %>
+                        <div class="col-md-3 col-sm-4">
+                          <%= select_tag "pointsale", options_from_collection_for_select(@pointsales, :id, :name), class: "form-control input-medium" %>
+                        </div>
+                      <% end %>
+                      <!-- stock minimo para los seleccionados -->
+                      <div class="col-md-8">
+                        <label class="col-md-1 col-sm-1"> Stock Mínimo </label>
+                        <div class="col-md-2 col-sm-2">
+                          <input class="form-control" type="number" min="0" id="min_stock_general">
+                        </div>
+                        <label class="col-md-1 col-sm-1"> Stock Máximo </label>
+                        <div class="col-md-2 col-sm-2">
+                          <input class="form-control" type="number" min="0" id="max_stock_general">
+                        </div>
+                        <div class="col-md-2 col-sm-3">
+                          <button type="button" class="btn btn-success" onclick="updateStock()"><i class="fa fa-save"></i>&nbsp&nbspGuardar cambios</button>
+                        </div>
                       </div>
-                      <h4 class="form-section" style="margin-top: 5px; margin-bottom: 20px"></h4>
                     </div>
+                    <h4 class="form-section" style="margin-top: 5px; margin-bottom: 20px"></h4>
+                  </div>
                 </div>
                 <%= render 'form' %>
               </div>
@@ -71,6 +71,3 @@
   </div>
   <!-- END CONTENT -->
 </div>
-<!-- END CONTAINER -->
-
-

+ 88 - 166
app/views/layouts/application.html.erb

@@ -1,183 +1,105 @@
 <!DOCTYPE html>
 <html>
-<head>
-	<title> <%= APP_ABR %> </title>
+	<head>
+		<title> <%= APP_ABR %> </title>
+
+		<% if user_signed_in? %>
+			<!-- BEGIN THEME LAYOUT STYLES -->
+			<%= stylesheet_link_tag  "application", "global/custom.css", "global/layout.css", "global/search.css", media: "all" %>
+			<!-- END THEME LAYOUT STYLES -->
+		<% else %>
+			<!-- BEGIN PAGE GLOBAL STYLES -->
+			<%= stylesheet_link_tag  "application", "global/login-5.css" %>
+			<!-- END PAGE GLOBAL STYLES -->
+		<% end %>
+		<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
+		<%= csrf_meta_tags %>
+	</head>
 
 	<% if user_signed_in? %>
-	<!-- BEGIN THEME LAYOUT STYLES -->
-	<%= stylesheet_link_tag  "application", "global/custom.css", "global/layout.css", "global/search.css", media: "all" %>
-	<!-- END THEME LAYOUT STYLES -->
-	<% else %>
-	<!-- BEGIN PAGE GLOBAL STYLES -->
-	<%= stylesheet_link_tag  "application", "global/login-5.css"  %>
-	<!-- END PAGE GLOBAL STYLES -->
-	<% end %>
-	
-	<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
-	
-	<%= csrf_meta_tags %>
-</head>
+		<!-- <body class="page-container-bg-solid page-header-menu-fixed"> -->
+		<body class="page-container-bg-solid page-boxed">
+			<% unless flash.empty? %>
+	  		<script type="text/javascript">
+      		<% flash.each do |f| %>
+	      		<% type = f[0].to_s.gsub('alert', 'error').gsub('notice', 'info') %>
+	     			toastr['<%= type %>']('<%= f[1] %>');
+      		<% end %>
+	  		</script>
+	 		<% end %>
 
-<% if user_signed_in? %>
-<!-- <body class="page-container-bg-solid page-header-menu-fixed"> -->
-	<body class="page-container-bg-solid page-boxed">
-	 <% unless flash.empty? %>
-	  <script type="text/javascript">
-	      <% flash.each do |f| %>
-	      <% type = f[0].to_s.gsub('alert', 'error').gsub('notice', 'info') %>
-	     	 toastr['<%= type %>']('<%= f[1] %>');
-	      <% end %>
-	  </script>
-	 <% end %>
-	 
-	<!-- BEGIN HEADER -->
-	<div class="page-header">
-		<!-- BEGIN HEADER TOP -->
-		<div class="page-header-top">
-			<div class="container-fluid">
-				<!-- BEGIN LOGO -->
-				<div class="page-logo">
-					<%= link_to root_path do %>
-					  <%= image_tag "logos/logo-default.png", {:class=>"logo-default"} %>
-					<% end %>	
-				</div>
-				<!-- END LOGO -->
-				<!-- BEGIN TOP NAVIGATION MENU -->
-				<a href="javascript:;" class="menu-toggler"></a>
-				<div class="top-menu">
-					<ul class="nav navbar-nav pull-right">
-						<!-- BEGIN NOTIFICATION DROPDOWN -->
-<!-- 						<li class="dropdown dropdown-extended dropdown-notification dropdown-dark" id="header_notification_bar">
-							<a href="javascript:;" class="dropdown-toggle" data-toggle="dropdown" data-hover="dropdown" data-close-others="true">
-								<i class="fa fa-bell-o"></i>
-								<span class="badge badge-default">7</span>
-							</a>
-							<ul class="dropdown-menu">
-								<li class="external">
-									<h3>Tienes
-										<strong>2 mensaje(s)</strong> pendientes </h3>
-									<a href="#">ver todos</a>
-								</li>
-								<li>
-									<ul class="dropdown-menu-list scroller" style="height: 250px;" data-handle-color="#637283">
+			<!-- BEGIN HEADER -->
+			<div class="page-header">
+				<!-- BEGIN HEADER TOP -->
+				<div class="page-header-top">
+					<div class="container-fluid">
+						<!-- BEGIN LOGO -->
+						<div class="page-logo">
+							<%= link_to root_path do %>
+							  <%= image_tag "logos/logo-default.png", { class: "logo-default" } %>
+							<% end %>
+						</div>
+						<!-- END LOGO -->
+						<!-- BEGIN TOP NAVIGATION MENU -->
+						<label style="margin-top: 25px;font-size: 14px;"> Módulo - <%= usertype(current_user) %><br><small><%= current_user.pointsale_id.present? ? "Punto de venta - #{current_user.pointsale.name}" : "" %></small></label>
+						<a href="javascript:;" class="menu-toggler"></a>
+						<div class="top-menu">
+							<ul class="nav navbar-nav pull-right">
+								<!-- BEGIN USER LOGIN DROPDOWN -->
+								<li class="dropdown dropdown-user dropdown-dark">
+									<a href="javascript:;" class="dropdown-toggle" data-toggle="dropdown" data-hover="dropdown" data-close-others="true">
+										<!--<img alt="" class="img-circle" src="../assets/layouts/layout3/img/avatar9.jpg"> -->
+										<%= image_tag "avatar.png", { class: "img-circle" } %>
+										<span class="username username-hide-mobile"> <%= current_user.full_name %> </span>
+									</a>
+									<ul class="dropdown-menu dropdown-menu-default">
 										<li>
-											<a href="javascript:;">
-												<span class="time">justo ahora</span>
-												<span class="details">
-													<span class="label label-sm label-icon label-success">
-													<i class="fa fa-plus"></i>
-													</span> Nuevo producto registrado. 
-												</span>
-											</a>
+											<%= link_to pwdchange_path do %> <i class="fa fa-lock"></i> Cambiar contraseña
+											<% end %>
 										</li>
 										<li>
-											<a href="javascript:;">
-												<span class="time">10 mins</span>
-												<span class="details">
-													<span class="label label-sm label-icon label-warning"> <i class="fa fa-bell-o"></i>
-													</span> Cambios en punto de venta. </span>
-											</a>
+											<%= link_to destroy_user_session_path, method: :delete do %> <i class="fa fa-key"></i> Cerrar sesión
+											<% end %>
 										</li>
 									</ul>
 								</li>
 							</ul>
-						</li> -->
-						<!-- END NOTIFICATION DROPDOWN -->
-
-<!-- 						<li class="droddown dropdown-separator">
-							<span class="separator"></span>
-						</li> -->
-						
-						<!-- BEGIN USER LOGIN DROPDOWN -->
-						<li class="dropdown dropdown-user dropdown-dark">
-							<a href="javascript:;" class="dropdown-toggle" data-toggle="dropdown" data-hover="dropdown" data-close-others="true">
-								<!--<img alt="" class="img-circle" src="../assets/layouts/layout3/img/avatar9.jpg"> -->
-								<%= image_tag "avatar.png", {:class=>"img-circle"} %>
-								<span class="username username-hide-mobile"> <%= current_user.full_name %> </span>
-							</a>
-							<ul class="dropdown-menu dropdown-menu-default">
-								<!-- <li>
-									<a href="page_user_profile_1.html">
-										<i class="icon-user"></i> My Profile </a>
-								</li>
-								<li>
-									<a href="app_calendar.html">
-										<i class="icon-calendar"></i> My Calendar </a>
-								</li>
-								<li>
-									<a href="app_inbox.html">
-										<i class="icon-envelope-open"></i> My Inbox
-										<span class="badge badge-danger"> 3 </span>
-									</a>
-								</li>
-								<li>
-									<a href="app_todo_2.html">
-										<i class="icon-rocket"></i> My Tasks
-										<span class="badge badge-success"> 7 </span>
-									</a>
-								</li>
-								<li class="divider"> </li> -->
-								<li>
-									<%= link_to  pwdchange_path   do %> <i class="fa fa-lock"></i> Cambiar contraseña
-									<% end %>
-								</li>
-								<li>
-									<%= link_to  destroy_user_session_path, :method => :delete  do %> <i class="fa fa-key"></i> Cerrar sesión
-									<% end %>
-								</li>
-								<!-- <li>
-									<a href="page_user_lock_1.html">
-										<i class="icon-lock"></i> Lock Screen </a>
-								</li>
-								<li>
-									<a href="page_user_login_1.html">
-										<i class="icon-key"></i> Log Out </a>
-								</li> -->
-							</ul>
-						</li>
-						<!-- END USER LOGIN DROPDOWN -->
-						
-					</ul>
+						</div>
+					</div>
 				</div>
-				<!-- END TOP NAVIGATION MENU -->
-			</div>
-		</div>
-		<!-- END HEADER TOP -->
-		<!-- BEGIN HEADER MENU -->
-		<div class="page-header-menu">
-			<div class="container-fluid">
-				<!-- BEGIN MEGA MENU -->
-				<!-- DOC: Apply "hor-menu-light" class after the "hor-menu" class below to have a horizontal menu with white background -->
-				<!-- DOC: Remove data-hover="dropdown" and data-close-others="true" attributes below to disable the dropdown opening on mouse hover -->
-				<div class="hor-menu  ">
-					<%= render_navigation( expand_all: true, renderer: :bootstrap3 ) %>
-				</div> 
-				<!-- END MEGA MENU -->
+				<div class="page-header-menu">
+					<div class="container-fluid">
+						<!-- BEGIN MEGA MENU -->
+						<!-- DOC: Apply "hor-menu-light" class after the "hor-menu" class below to have a horizontal menu with white background -->
+						<!-- DOC: Remove data-hover="dropdown" and data-close-others="true" attributes below to disable the dropdown opening on mouse hover -->
+						<div class="hor-menu">
+							<%= render_navigation( expand_all: true, renderer: :bootstrap3 ) %>
+						</div>
+						<!-- END MEGA MENU -->
+					</div>
+				</div>
+				<!-- END HEADER MENU -->
 			</div>
-		</div>
-		<!-- END HEADER MENU -->
-	</div>
-	<!-- END HEADER -->
+			<!-- END HEADER -->
 
-	<%= yield %>
-	<%= render 'layouts/dialog' %>
-	<div id="modal-holder"></div>
-	<!-- BEGIN FOOTER -->
-	
-	<!-- BEGIN INNER FOOTER -->
-	<div class="page-footer">
-		<div class="container-fluid"> <%= APP_CREDITS %> 
-			<!-- <a href="http://themeforest.net/item/metronic-responsive-admin-dashboard-template/4021469?ref=keenthemes" title="Purchase Metronic just for 27$ and get lifetime updates for free" target="_blank">Purchase Metronic!</a> -->
-		</div>
-	</div>
-	<div class="scroll-to-top">
-		<i class="fa fa-arrow-up"></i>
-	</div>
-	<!-- END INNER FOOTER -->
-	<!-- END FOOTER -->
-<% else %>
-	<%= yield %>
-<% end %>
+			<%= yield %>
+			<%= render 'layouts/dialog' %>
+			<div id="modal-holder"></div>
+			<!-- BEGIN FOOTER -->
 
-</body>
+			<!-- BEGIN INNER FOOTER -->
+			<div class="page-footer">
+				<div class="container-fluid"> <%= APP_CREDITS %>
+					<!-- <a href="http://themeforest.net/item/metronic-responsive-admin-dashboard-template/4021469?ref=keenthemes" title="Purchase Metronic just for 27$ and get lifetime updates for free" target="_blank">Purchase Metronic!</a> -->
+				</div>
+			</div>
+			<div class="scroll-to-top">
+				<i class="fa fa-arrow-up"></i>
+			</div>
+			<!-- END INNER FOOTER -->
+			<!-- END FOOTER -->
+		<% else %>
+			<%= yield %>
+		<% end %>
+		</body>
 </html>

+ 36 - 26
app/views/pointsales/_assign_products.html.erb

@@ -6,12 +6,13 @@
 				<tr>
 					<th> Producto </th>
 					<th> Stock inicial </th>
+					<th> Precio de venta </th>
 				</tr>
 			</thead>
 			<tbody>
 				<% @products.each do |product| %>
 					<tr id="product_<%= product.id %>">
-						<td> 
+						<td>
 							<strong><%= product.name %></strong> <br>
 							SKU: <%= product.sku %> <br>
 							<% if product.display_attributes.present? %>
@@ -19,8 +20,14 @@
 							<% end %>
 							<%= product.description if product.description.present? %>
 						</td>
-						<td> 
-    						<input type="number" min="0" class="form-control" value="0" pattern="^[0-9]*[1-9][0-9]*$" title="Stock con el que se agregará el producto al punto de venta">
+						<td>
+  						<input type="number" min="0" class="form-control" id="stock_<%= product.id %>" value="0" pattern="^[0-9]*[1-9][0-9]*$" title="Stock con el que se agregará el producto al punto de venta">
+						</td>
+						<td>
+							<div class="input-group">
+                <span class="input-group-addon"> $ </span>
+                <%= number_field_tag "price_sale", product.price_sale, class: 'form-control input-small', id: "price_" + product.id.to_s, min: 0.01 %>
+              </div>
 						</td>
 					</tr>
 				<% end %>
@@ -30,16 +37,20 @@
 	<div class="form-actions">
 		<div class="row">
 			<div class="col-md-9">
-  				<button type="button" title="Asignar los productos seleccionados al punto de venta" 		class="btn blue" onclick="assignOrDeleteProducts($(this))"> 
-  					<i class="fa fa-long-arrow-right"></i> Asignar productos
+				<button type="button" title="Asignar los productos seleccionados al punto de venta"	class="btn blue" onclick="assignOrDeleteProducts($(this))">
+					<i class="fa fa-long-arrow-right"></i> Asignar productos
 				</button>
 				<button class="btn default" onclick="closeModal()">Cancelar</button>
 			</div>
 		</div>
-	</div>	
+	</div>
 </div>
 
 <script>
+	$(document).ready(function(){
+    App.init();
+  });
+
 	function closeModal() {
 		$('#dialog').modal('toggle');
 	}
@@ -49,26 +60,25 @@
 		var products = [];
 		$('#table_assign_or_delete tbody tr').each(function(row) {
 			var idText = $(this).attr('id');
-    		var product_id = idText.substring(idText.lastIndexOf('_') + 1, idText.length);
-    		var obj = { id: product_id, stock: $(this).find('input').val() };			
-	      	products.push(obj);  
-	    });	
-
-	    $.ajax({
-	      type: "POST",
-	      url: "/pointsales/"+ <%= @pointsale.id %> + "/assign_products_to_pointsale",
-	      dataType: "json",
-	      data: {
-	      	products: JSON.stringify(products) 
-	      },
-	      success: function(xhr, status, error) {
-	      	button.attr('disabled', false);
-	      	toastr["success"]("Productos asignados correctamente.");
-	      	$('#dialog').modal('toggle');
-	      	$(class_1).DataTable().draw(); 
-	      	$(class_2).DataTable().draw();
+  		var product_id = idText.substring(idText.lastIndexOf('_') + 1, idText.length);
+  		var obj = { id: product_id, stock: $("#stock_" + product_id).val(), price: $("#price_" + product_id).val() };
+    	products.push(obj);
+    });
 
-	      }
-	    });	 
+    $.ajax({
+      type: "POST",
+      url: "/pointsales/"+ <%= @pointsale.id %> + "/assign_products_to_pointsale",
+      dataType: "json",
+      data: {
+      	products: JSON.stringify(products)
+      },
+      success: function(xhr, status, error) {
+      	button.attr('disabled', false);
+      	toastr["success"]("Productos asignados correctamente.");
+      	$('#dialog').modal('toggle');
+      	$(class_1).DataTable().draw();
+      	$(class_2).DataTable().draw();
+      }
+    });
 	}
 </script>

+ 5 - 2
config/navigation.rb

@@ -117,6 +117,9 @@ SimpleNavigation::Configuration.run do |navigation|
         sub_nav.dom_attributes = { class: 'dropdown-menu pull-left' }
         sub_nav.item :pos_configs, 'Configurar parámetros generales', pos_configs_path
         sub_nav.item :divider_after_list_transfers, '#', divider: true
+        sub_nav.item :list_products_initial_stock, 'Stock inicial de productos', products_initial_stock_path
+        sub_nav.item :list_products_stock, 'Stock mínimo y máximo de productos', products_stock_path
+        sub_nav.item :divider_after_list_transfers, '#', divider: true
         sub_nav.item :list_users, 'Usuarios del sistema', users_path
       end
     end
@@ -192,8 +195,8 @@ SimpleNavigation::Configuration.run do |navigation|
       # configuracion
       primary.item :config, { icon: "fa fa-fw fa-cog", text: "Configuración" }, '#', class: 'menu-dropdown classic-menu-dropdown' do |sub_nav|
         sub_nav.dom_attributes = { class: 'dropdown-menu pull-left' }
-        sub_nav.item :list_products_initial_stock, 'Stock inicial de productos', products_initial_stock_path(current_user.pointsale_id)
-        sub_nav.item :list_products_stock, 'Stock mínimo y máximo de productos', products_stock_path(current_user.pointsale_id)
+        sub_nav.item :list_products_initial_stock, 'Stock inicial de productos', products_initial_stock_path(pointsale_id: current_user.pointsale_id)
+        sub_nav.item :list_products_stock, 'Stock mínimo y máximo de productos', products_stock_path(pointsale_id: current_user.pointsale_id)
         sub_nav.item :divider_after_list_transfers, '#', divider: true
         sub_nav.item :list_users, 'Usuarios del sistema', users_path
       end

+ 2 - 2
config/routes.rb

@@ -219,9 +219,9 @@ Rails.application.routes.draw do
 
   # rutas para el STOCK
   get 'stock_by_pointsale' => 'available_products#stock_by_pointsale', :as => 'stock_by_pointsale'
-  get 'products_stock/:pointsale_id' => 'available_products#stock', :as => 'products_stock'
+  get 'products_stock' => 'available_products#stock', :as => 'products_stock'
   put 'update_stock' => 'available_products#update_stock', defaults: { format: 'json' }
-  get 'products_initial_stock/:pointsale_id' => 'available_products#initial_stock', :as => 'products_initial_stock'
+  get 'products_initial_stock' => 'available_products#initial_stock', :as => 'products_initial_stock'
   get 'print_stock_by_pointsale' => 'available_products#print_stock', :as => 'print_stock_by_pointsale'
   put 'set_initial_stock' => 'available_products#set_initial_stock', defaults: { format: 'json' }
   get 'total_products_by_pointsale' => 'available_products#total_products_by_pointsale', :format => :json