Kaynağa Gözat

Added price sale column when assigning products to pointsale

Jacqueline Maldonado 7 yıl önce
ebeveyn
işleme
ff545c2d62

+ 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 }

+ 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
 

+ 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>