168 lines
4.9 KiB
JavaScript
168 lines
4.9 KiB
JavaScript
$(function(){
|
|
$("tbody #inp-produto_id").select2({
|
|
minimumInputLength: 2,
|
|
language: "pt-BR",
|
|
placeholder: "Digite para buscar o produto",
|
|
width: "100%",
|
|
ajax: {
|
|
cache: true,
|
|
url: path_url + "api/produtos",
|
|
dataType: "json",
|
|
data: function (params) {
|
|
let empresa_id = $('#empresa_id').val()
|
|
|
|
console.clear();
|
|
|
|
var query = {
|
|
pesquisa: params.term,
|
|
empresa_id: empresa_id,
|
|
};
|
|
return query;
|
|
},
|
|
processResults: function (response) {
|
|
var results = [];
|
|
|
|
$.each(response, function (i, v) {
|
|
var o = {};
|
|
o.id = v.id;
|
|
if(v.codigo_variacao){
|
|
o.codigo_variacao = v.codigo_variacao
|
|
}
|
|
|
|
o.text = v.nome;
|
|
o.text += ' | R$ ' + convertFloatToMoeda(v.valor_unitario);
|
|
|
|
if(v.codigo_barras){
|
|
o.text += ' [' + v.codigo_barras + ']';
|
|
}
|
|
o.value = v.id;
|
|
results.push(o);
|
|
});
|
|
return {
|
|
results: results,
|
|
};
|
|
},
|
|
},
|
|
});
|
|
})
|
|
|
|
$('.btn-add-tr-prod').on("click", function () {
|
|
console.clear()
|
|
var $table = $(this)
|
|
.closest(".row")
|
|
.prev()
|
|
.find(".table-dynamic");
|
|
|
|
var hasEmpty = false;
|
|
|
|
$table.find("input, select").each(function () {
|
|
if (($(this).val() == "" || $(this).val() == null) && $(this).attr("type") != "hidden" && $(this).attr("type") != "file" && !$(this).hasClass("ignore")) {
|
|
hasEmpty = true;
|
|
}
|
|
});
|
|
|
|
|
|
if (hasEmpty) {
|
|
swal(
|
|
"Atenção",
|
|
"Preencha todos os campos antes de adicionar novos.",
|
|
"warning"
|
|
);
|
|
return;
|
|
}
|
|
|
|
// $table.find("select.select2").select2("destroy");
|
|
var $tr = $table.find(".dynamic-form").first();
|
|
$tr.find("select.select2").select2("destroy");
|
|
var $clone = $tr.clone();
|
|
$clone.show();
|
|
|
|
$clone.find("input,select").val("");
|
|
$clone.find("span").html("");
|
|
|
|
$table.append($clone);
|
|
setTimeout(function () {
|
|
$("tbody select.select2").select2({
|
|
language: "pt-BR",
|
|
width: "100%",
|
|
theme: "bootstrap4"
|
|
});
|
|
|
|
$("tbody #inp-produto_id").select2({
|
|
minimumInputLength: 2,
|
|
language: "pt-BR",
|
|
placeholder: "Digite para buscar o produto",
|
|
width: "100%",
|
|
ajax: {
|
|
cache: true,
|
|
url: path_url + "api/produtos",
|
|
dataType: "json",
|
|
data: function (params) {
|
|
let empresa_id = $('#empresa_id').val()
|
|
console.clear();
|
|
var query = {
|
|
pesquisa: params.term,
|
|
empresa_id: empresa_id
|
|
};
|
|
return query;
|
|
},
|
|
processResults: function (response) {
|
|
var results = [];
|
|
|
|
$.each(response, function (i, v) {
|
|
var o = {};
|
|
o.id = v.id;
|
|
if(v.codigo_variacao){
|
|
o.codigo_variacao = v.codigo_variacao
|
|
}
|
|
|
|
o.text = v.nome;
|
|
o.text += ' | R$ ' + convertFloatToMoeda(v.valor_unitario);
|
|
|
|
if(v.codigo_barras){
|
|
o.text += ' [' + v.codigo_barras + ']';
|
|
}
|
|
o.value = v.id;
|
|
results.push(o);
|
|
});
|
|
return {
|
|
results: results,
|
|
};
|
|
},
|
|
},
|
|
});
|
|
}, 100);
|
|
|
|
})
|
|
|
|
$(document).delegate(".btn-remove-tr", "click", function (e) {
|
|
e.preventDefault();
|
|
swal({
|
|
title: "Você esta certo?",
|
|
text: "Deseja remover esse item mesmo?",
|
|
icon: "warning",
|
|
buttons: true
|
|
}).then(willDelete => {
|
|
if (willDelete) {
|
|
var trLength = $(this)
|
|
.closest("tr")
|
|
.closest("tbody")
|
|
.find("tr")
|
|
.not(".dynamic-form-document").length;
|
|
if (!trLength || trLength > 1) {
|
|
$(this)
|
|
.closest("tr")
|
|
.remove();
|
|
calcTotal()
|
|
calTotalNfe()
|
|
limpaFatura()
|
|
} else {
|
|
swal(
|
|
"Atenção",
|
|
"Você deve ter ao menos um item na lista",
|
|
"warning"
|
|
);
|
|
}
|
|
}
|
|
});
|
|
}); |