|
|
@@ -110,40 +110,37 @@
|
|
|
) %>
|
|
|
</div>
|
|
|
</div>
|
|
|
-
|
|
|
+ <%
|
|
|
+ @category = nil
|
|
|
+ @subcategory = nil
|
|
|
+ @prompt = 'Seleccione'
|
|
|
+ @disabled = true
|
|
|
+ if @product.category.present? && @product.category.parent_id == 0
|
|
|
+ @category = @product.category
|
|
|
+ @disabled = false
|
|
|
+ elsif @product.category.present? && @product.category.parent_id != 0
|
|
|
+ @category = Category.find(@product.category.parent_id)
|
|
|
+ @subcategory = @product.category
|
|
|
+ @disabled = false
|
|
|
+ end
|
|
|
+ %>
|
|
|
<div class="form-group">
|
|
|
- <%
|
|
|
- @category = nil
|
|
|
- @subcategory = nil;
|
|
|
- @prompt = 'Seleccione'
|
|
|
- @disabled = true
|
|
|
- if @product.categories[0].present? && @product.categories[0].parent_id == 0
|
|
|
- @category = @product.categories[0]
|
|
|
- @prompt = ''
|
|
|
- elsif @product.categories[0].present?
|
|
|
- @category = Category.find(@product.categories[0].parent_id)
|
|
|
- @subcategory = @product.categories[0]
|
|
|
- @disabled = false
|
|
|
- end
|
|
|
- %>
|
|
|
- <%= label_tag :categorias, "Líneas de producto", {:class=>"col-md-3 control-label"} do %>Líneas de producto
|
|
|
- <span class="required">*</span>
|
|
|
+ <%= f.label :category_id, "Líneas de producto", { class: "col-md-3 control-label" } do %>Líneas de producto
|
|
|
+ <span class="required">*</span>
|
|
|
<% end %>
|
|
|
<div class="col-md-4">
|
|
|
- <%= select_tag 'categorias',
|
|
|
- options_from_collection_for_select(Category.activos_padre, 'id', 'category',
|
|
|
- :selected => (@category.id unless @category.nil?)),
|
|
|
- {:include_blank => "Seleccione", :class => 'form-control'} %>
|
|
|
+ <%= f.collection_select(:category_id, Category.activos_padre, :id, :category, options = { include_blank: "Seleccione", selected: (@category.present? ? @category.id : @prompt ) }, class: "form-control select2", onchange: "getSubCategories($(this).val())") %>
|
|
|
</div>
|
|
|
</div>
|
|
|
<div class="form-group">
|
|
|
- <%= f.label :category_ids, "Sublinea del producto", {:class=>"col-md-3 control-label"} %>
|
|
|
+ <%= f.label :sub_category_id, "Sublíneas de producto", { class: "col-md-3 control-label" } do %>Sublínea de producto
|
|
|
+ <span class="required">*</span>
|
|
|
+ <% end %>
|
|
|
<div class="col-md-4">
|
|
|
- <%= f.collection_select(:category_ids, @category.nil? ? {} : Category.where(:parent_id => @category.id), :id, :category , options ={:include_blank => @prompt, :selected => (@subcategory.id unless @subcategory.nil?) }, :class => "form-control", :disabled => @disabled) %>
|
|
|
- <%= f.hidden_field :category_ids, {:id => 'subcategory_hidden'}%>
|
|
|
+ <%= collection_select("", :sub_category_id, (@category.present? ? Category.activos.where(parent_id: @category.id) : {}), :id, :category, options = { prompt: "Seleccione", selected: (@subcategory.id if @subcategory.present?) }, html_options = { class: 'form-control select2 select2-allow-clear-todas' }) %>
|
|
|
+ <%= hidden_field_tag :subcategory_hidden, (@subcategory.id if @subcategory.present?) %>
|
|
|
</div>
|
|
|
</div>
|
|
|
-
|
|
|
<div class="form-group">
|
|
|
<%= f.label :include_purchase_tax, "¿Incluir IVA en compra?", {:class=>"col-md-3 control-label"} do %> ¿Incluir IVA en compra?
|
|
|
<span class="required">*</span>
|
|
|
@@ -165,7 +162,7 @@
|
|
|
|
|
|
|
|
|
<div class="form-group">
|
|
|
- <%= f.label :include_sale_tax, "¿Incluir IVA en venta?", {:class=>"col-md-3 control-label"} do %> ¿Incluir IVA en compra?
|
|
|
+ <%= f.label :include_sale_tax, "¿Incluir IVA en venta?", {:class=>"col-md-3 control-label"} do %> ¿Incluir IVA en venta?
|
|
|
<span class="required">*</span>
|
|
|
<% end %>
|
|
|
<div class="col-md-9">
|
|
|
@@ -366,7 +363,6 @@
|
|
|
$('#product_style_list').on('change', function(event) { getVariants(); });
|
|
|
|
|
|
function presentaciones(){
|
|
|
- console.log($('#product_presentation').is(':checked'));
|
|
|
if ($('#product_presentation').is(':checked')){
|
|
|
$('.presentaciones').removeClass('hidden');
|
|
|
}
|
|
|
@@ -416,7 +412,34 @@
|
|
|
}
|
|
|
});
|
|
|
|
|
|
- $('#product_category_ids').on('change', function() {
|
|
|
+ function getSubCategories(value) {
|
|
|
+ $('#_sub_category_id').html('');
|
|
|
+ $('#_sub_category_id').select2("destroy").select2({ placeholder: 'Seleccione'});
|
|
|
+ $('#_sub_category_id').select2('val', null);
|
|
|
+ if($('#product_category_id').val()) {
|
|
|
+ $.ajax({
|
|
|
+ type: "get",
|
|
|
+ url: '/getcategories/' + value,
|
|
|
+ dataType: 'json',
|
|
|
+ success: function(data) {
|
|
|
+ if(data.length > 0) {
|
|
|
+ $('#_sub_category_id').append('<option></option>')
|
|
|
+ for(i in data) {
|
|
|
+ $('#_sub_category_id').append("<option value='" + data[i].id + "'>" + data[i].category + "</option>")
|
|
|
+ }
|
|
|
+ $('#_sub_category_id').select2({ placeholder: 'Seleccione'});
|
|
|
+ $('#_sub_category_id').attr('disabled', false);
|
|
|
+ } else {
|
|
|
+ $('#_sub_category_id').attr('disabled', true);
|
|
|
+ $('#subcategory_hidden').val($('#product_category_id').val());
|
|
|
+ }
|
|
|
+ fillSKU();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $('#_sub_category_id').on('change', function() {
|
|
|
$('#subcategory_hidden').val($(this).val());
|
|
|
fillSKU();
|
|
|
});
|
|
|
@@ -441,39 +464,33 @@
|
|
|
|
|
|
|
|
|
function getProductId() {
|
|
|
- $('#categorias').attr('disabled', true);
|
|
|
+ $('#product_category_id').attr('disabled', true);
|
|
|
+ var category_id = $('#_sub_category_id').val() ? $('#_sub_category_id').val() : $('#product_category_id').val();
|
|
|
$.ajax({
|
|
|
type: "get",
|
|
|
url: '/get_max_product_id',
|
|
|
dataType: 'json',
|
|
|
+ data: {
|
|
|
+ category_id: category_id
|
|
|
+ },
|
|
|
success: function(data) {
|
|
|
- $('#categorias').attr('disabled', false);
|
|
|
+ $('#product_category_id').attr('disabled', false);
|
|
|
var sku = $('#product_sku').val();
|
|
|
- if(sku.length && !$('#idproduct').val()) {
|
|
|
- $('#product_sku').val(sku + "-" + data);
|
|
|
- } else {
|
|
|
- $('#product_sku').val(sku + "-" + $('#idproduct').val());
|
|
|
- }
|
|
|
- },
|
|
|
+ $('#product_sku').val(sku + "-" + data);
|
|
|
+ }
|
|
|
});
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
function fillSKU() {
|
|
|
- var sku = $('#product_sku').val();
|
|
|
- if(sku.length <= 3) {
|
|
|
- $('#product_sku').val($('#categorias option:selected').text().substring(0,3).toUpperCase());
|
|
|
- getProductId();
|
|
|
- }
|
|
|
-
|
|
|
- sku = $('#product_sku').val();
|
|
|
- if(sku.length >= 3 && $('#product_category_ids').val() != "0") {
|
|
|
- var subcategory = $('#product_category_ids option:selected').text();
|
|
|
- if(subcategory){
|
|
|
- $('#product_sku').val(sku.substring(0,3) + '-' + subcategory.replace(regex, '')
|
|
|
- .substring(0,3).toUpperCase());
|
|
|
- getProductId();
|
|
|
+ var category = $('#product_category_id option:selected').text().substring(0,3).toUpperCase();
|
|
|
+ $('#product_sku').val(category);
|
|
|
+ if($('#_sub_category_id').val()) {
|
|
|
+ var subcategory = $('#_sub_category_id option:selected').text();
|
|
|
+ if(subcategory) {
|
|
|
+ $('#product_sku').val(category + '-' + subcategory.replace(regex, '').substring(0,3).toUpperCase());
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
+ getProductId();
|
|
|
}
|
|
|
|
|
|
function validateBarcode(barcode) {
|