- Fix UserSettings nel datasource + ricezione su js [Ordini Acquisto] - Aggiunto un debounce alla pressione del tasto invio per mandare le mail
872 lines
36 KiB
JavaScript
872 lines
36 KiB
JavaScript
$(function () {
|
|
const module = new Module();
|
|
|
|
module.onLoad(function () {
|
|
$(".bt_viewOrd").on("click", function () {
|
|
const $tr = $(this).closest("tr[data-order_key]");
|
|
const key = $tr.getDataAttr("order_key");
|
|
|
|
_ordiniA.popup.open(key);
|
|
});
|
|
|
|
$(document).on("click", ".bt_pdfOrd", function (e) {
|
|
const $bt = $(this);
|
|
const $tr = $bt.closest("tr[data-order_key]");
|
|
const ajax = new Ajax();
|
|
|
|
ajax.get("getPdfOrdine")
|
|
.data({key: $tr.getDataAttr("order_key")})
|
|
.$toDisable($("#cod_alis"))
|
|
.$button($bt)
|
|
.noticeAsModal()
|
|
.onSuccess({downloadFile: true})
|
|
.execute();
|
|
|
|
e.preventDefault();
|
|
return false;
|
|
});
|
|
|
|
$(".bt_annulla").on("click", function () {
|
|
const $bt = $(this);
|
|
const $tr = $bt.closest("tr[data-order_key]");
|
|
const key = $tr.getDataAttr("order_key");
|
|
const ajax = new Ajax();
|
|
|
|
ajax.post("cancel")
|
|
.data({key: key})
|
|
.confirmModal({message: "Confermi l'annullamento dell'ordine n. " + key.num_ord + "?"})
|
|
.$button($bt)
|
|
.noticeAsModal()
|
|
.$toDisable($tr)
|
|
.onSuccess({
|
|
toast: {message: "L'ordine n. " + key.num_ord + " è stato annullato"},
|
|
callback: function () {
|
|
$tr.slideUp(500, function () {
|
|
$tr.remove();
|
|
location.reload();
|
|
});
|
|
}
|
|
})
|
|
.execute();
|
|
});
|
|
|
|
$(".emailbox > input[type='email']").on("enterKey", _.debounce(function () {
|
|
$(this).trigger("blur");
|
|
$(this).closest("td").find(".emailbox .emailok").trigger("click");
|
|
}, 500));
|
|
|
|
$(".bt_sendMail").on("click", function () {
|
|
const $btn = $(this);
|
|
const $tr = $btn.closest("tr[data-order_key]");
|
|
const key = $tr.getDataAttr("order_key");
|
|
const action = _.bind(activeEmailInput, this, $btn);
|
|
|
|
if (key.flagAccorpaOrdini && key.flagCountOrdiniNonEsportati) {
|
|
accorpaOrdini($(this), action);
|
|
} else {
|
|
action()
|
|
}
|
|
});
|
|
|
|
function activeEmailInput($btn) {
|
|
const $btnGroup = $btn.closest(".btn-group");
|
|
const $td = $btnGroup.closest("td");
|
|
const $emailbox = $td.find(".emailbox");
|
|
|
|
$btnGroup.hide();
|
|
$emailbox.fadeIn(300, function () {
|
|
const $email = $emailbox.find("input[type='email']");
|
|
|
|
if ($email.valueIsEmpty()) {
|
|
$email.focus();
|
|
}
|
|
});
|
|
}
|
|
|
|
$(".emailcancel").on("click", function () {
|
|
const $emailbox = $(this).closest(".emailbox");
|
|
const $td = $emailbox.closest("td");
|
|
|
|
$(".btn-group", $td).show();
|
|
$emailbox.hide();
|
|
});
|
|
|
|
$(".emailok").on("click", function () {
|
|
const $bt = $(this);
|
|
const $tr = $bt.closest("tr[data-order_key]");
|
|
const key = $tr.getDataAttr("order_key");
|
|
const eMail = $tr.find(".emailbox input[type='email']").getValue();
|
|
|
|
if (!is_null(eMail)) {
|
|
const ajax = new Ajax();
|
|
ajax.get("sendEmailOrdine")
|
|
.data({key: key, e_mail: eMail})
|
|
.noticeAsModal()
|
|
.$button($bt)
|
|
.$toDisable($tr)
|
|
.onSuccess({
|
|
toast: {message: "E-mail inviata al fornitore"},
|
|
callback: function () {
|
|
$tr.find(".dataExport_datePart").text(getToday("DD/MM/YY"));
|
|
$tr.find(".dataExport_timePart").text(getNow("HH:mm"));
|
|
$tr.find(".emailcancel").trigger("click");
|
|
}
|
|
})
|
|
.execute();
|
|
} else {
|
|
const toast = new Toast();
|
|
|
|
toast.warning("Indirizzo e-mail non specificato");
|
|
}
|
|
});
|
|
|
|
$(".bt_export").on("click", async function () {
|
|
const $btn = $(this);
|
|
const $tr = $btn.closest("tr[data-order_key]");
|
|
const key = $tr.getDataAttr("order_key");
|
|
const action = _.bind(esportaOrdine, this, $btn);
|
|
|
|
if (key.flagAccorpaOrdini && key.flagCountOrdiniNonEsportati) {
|
|
accorpaOrdini($btn, action);
|
|
} else {
|
|
action();
|
|
}
|
|
});
|
|
|
|
$(".bt_accorpa").on("click", function () {
|
|
const $btn = $(this);
|
|
|
|
accorpaOrdini($btn);
|
|
});
|
|
|
|
function esportaOrdine($btn) {
|
|
const $tr = $btn.closest("tr[data-order_key]");
|
|
const key = $tr.getDataAttr("order_key");
|
|
const $btAnnulla = $tr.find(".annulla");
|
|
|
|
const callback = function () {
|
|
const dataCons = $tr.getIntDataAttr("data_cons");
|
|
const flagTipoOrdine = $tr.getDataAttr("flag_tipo_ordine");
|
|
const numPrenotazione = $tr.getDataAttr("num_prenotazione");
|
|
const termCons = $tr.getDataAttr("term_cons");
|
|
|
|
let message = "Data consegna dell'ordine: <span style = 'color:#900;font-weight:bold'>" + dataCons.unixtime_format("DD/MM/YYYY") + "</span><br/>";
|
|
message += "<br/>Termini di consegna: <span style = 'color:#900;font-weight:bold'>" + blankIfNull(termCons) + "</span><br/>";
|
|
|
|
if (flagTipoOrdine === "O") {
|
|
message += "<br/>• Ordine: <span style = 'color:#900;font-weight:bold'>" + key.num_ord + "</span><br/>";
|
|
message += "<span style = 'color:#BBB'>• Prenotazione N°:</span><br/>";
|
|
} else {
|
|
message += "<br/><span style = 'color:#BBB'>• Ordine:</span><br/>";
|
|
message += "• Prenotazione N°: <span style = 'color:#900;font-weight:bold'>" + numPrenotazione + "</span><br/>";
|
|
}
|
|
|
|
message = message + "<br/>Vuoi esportare?";
|
|
|
|
const ajax = new Ajax();
|
|
ajax.post("export")
|
|
.data({key: key})
|
|
.confirmModal({message: message, title: "Verifica dati dell'ordine"})
|
|
.waitModal("Esportazione ordine")
|
|
.noticeAsModal()
|
|
.onSuccess(function () {
|
|
var modalBox = new ModalBox();
|
|
modalBox.message("L'ordine è stato esportato").primary().show().then(function () {
|
|
$tr.highlightRow(3000);
|
|
});
|
|
|
|
$tr.find(".dataExport_datePart").text(getToday("DD/MM/YY")).removeClass("dataExport_datePart");
|
|
$tr.find(".dataExport_timePart").text(getNow("HH:mm")).removeClass("dataExport_timePart");
|
|
|
|
$btn.disableAll();
|
|
$btAnnulla.disabled();
|
|
})
|
|
.execute();
|
|
};
|
|
|
|
const modalBox = new ModalBox();
|
|
const check_cartoni = $tr.getIntDataAttr("check_cartoni");
|
|
|
|
if (check_cartoni === -1) {
|
|
modalBox.warning("Quantità minima (" + $tr.attr("data-qta_chk_ct") + ") di cartoni ordinabili non rispettata (CT tot: " + $tr.attr("data-ct_effettivi") + ")");
|
|
} else if (check_cartoni === -2) {
|
|
modalBox.warning("Quantità massima (" + $tr.attr("data-qta_chk_ct") + ") di cartoni ordinabili non rispettata (CT tot: " + $tr.attr("data-ct_effettivi") + ")");
|
|
} else {
|
|
const ajax = new Ajax();
|
|
ajax.post("check_order")
|
|
.data({key: key})
|
|
.waitModal()
|
|
.noticeAsModal()
|
|
.onSuccess(function (ret) {
|
|
const checkValue = ret.returnData;
|
|
|
|
if (!_.isEmpty(checkValue.check_articoli)) {
|
|
var template = _.template(module.get_template("articoliFuoriGrigliaNotice"));
|
|
modalBox
|
|
.gridSize({xs: 6})
|
|
.content(template({products: checkValue.check_articoli}))
|
|
.title("Articoli fuori griglia")
|
|
.cancelOnly()
|
|
.backhash()
|
|
.danger()
|
|
.show();
|
|
} else if (checkValue.check_valoreMin.valoreMinimoSuperato === "0") {
|
|
modalBox
|
|
.title("Valore minimo non superato")
|
|
.content(
|
|
"Il valore minimo per l'esportazione dell'ordine non è stato raggiunto. <br>" +
|
|
`Valore minimo: <b class="text-danger">€ ${checkValue.check_valoreMin.valore_min_ord}</b>.<br>` +
|
|
`Valore ordinato: <b>€ ${checkValue.check_valoreMin.tot_merce}</b><br>` +
|
|
`Procedere ugualmente con l'esportazione?`
|
|
)
|
|
.yesNo(true, false)
|
|
.backhash()
|
|
.danger()
|
|
.show()
|
|
.then(function (ret) {
|
|
if (ret) {
|
|
callback();
|
|
}
|
|
});
|
|
} else if (checkValue.check_promo <= 0) {
|
|
modalBox.yesNo()
|
|
.content("Nell'ordine non sono presenti articoli in promozione. Vuoi continuare?")
|
|
.style("warning")
|
|
.show()
|
|
.then(function (ret) {
|
|
if (ret) {
|
|
callback();
|
|
}
|
|
});
|
|
} else {
|
|
callback();
|
|
}
|
|
})
|
|
.execute();
|
|
}
|
|
}
|
|
|
|
async function accorpaOrdini($btn, action) {
|
|
const $tr = $btn.closest("tr[data-order_key]");
|
|
const key = $tr.getDataAttr("order_key");
|
|
const ajax = new Ajax();
|
|
|
|
ajax.post("getOrdiniDaAccorpare")
|
|
.data({key: key})
|
|
.waitModal("Esportazione ordine")
|
|
.noticeAsModal()
|
|
.onSuccess(function (ret) {
|
|
const retData = ret?.returnData;
|
|
|
|
if (retData?.hasDuplicati) {
|
|
const modalBox = new ModalBox();
|
|
const template = _.template(module.get_template("ordiniDuplicati"));
|
|
|
|
modalBox
|
|
.title("Attenzione Ordini Duplicati");
|
|
|
|
if (action) {
|
|
modalBox
|
|
.yesNoCancel()
|
|
.btNo({
|
|
text: "Prosegui senza accorpare",
|
|
onClick: function (e, $btOk, $div) {
|
|
modalBox.close();
|
|
action();
|
|
}
|
|
})
|
|
} else {
|
|
modalBox.yesNo()
|
|
.btNo({
|
|
text: "Annulla",
|
|
});
|
|
}
|
|
|
|
modalBox.btYes({
|
|
text: "Accorpa selezionati",
|
|
onClick: function (e, $btOk, $div) {
|
|
const $table = $("#tableOrdiniDuplicati");
|
|
const $trUnchecked = $table.find("tr td input:not(:checked)").parents("tr");
|
|
const righe = retData.righe;
|
|
|
|
_.each($trUnchecked, function (tr) {
|
|
const numOrd = $(tr).find(".numOrd").text();
|
|
|
|
for (let i = 0; i < righe.length; i++) {
|
|
if (righe[i].num_ord == numOrd) {
|
|
righe.splice(i, 1);
|
|
break;
|
|
}
|
|
}
|
|
});
|
|
|
|
modalBox.close();
|
|
|
|
const data = {
|
|
"key": key,
|
|
"righe": righe,
|
|
}
|
|
|
|
getArticoliDaAccorpare(data);
|
|
}
|
|
})
|
|
.content(template({ordini: retData.righe, key: key}))
|
|
.style("warning")
|
|
.backdropStatic().backhash().xl().show();
|
|
} else {
|
|
const toast = new Toast();
|
|
toast.success("L'ordine n. " + key.num_ord + " è stato accorpato");
|
|
|
|
location.reload();
|
|
}
|
|
})
|
|
.execute();
|
|
}
|
|
|
|
function getArticoliDaAccorpare(data) {
|
|
const ajax = new Ajax();
|
|
const key = data.key;
|
|
|
|
ajax.post("getArticoliDaAccorpare")
|
|
.data(data)
|
|
.waitModal("Esportazione ordine")
|
|
.noticeAsModal()
|
|
.onSuccess(function (ret) {
|
|
const retData = ret?.returnData;
|
|
|
|
if (retData?.hasDuplicati) {
|
|
const modalBox = new ModalBox();
|
|
const template = _.template(module.get_template("articoliDuplicati"));
|
|
|
|
modalBox
|
|
.title("Attenzione Articoli Duplicati")
|
|
.okCancel()
|
|
.btCancel({size: {sm: 10}})
|
|
.btOK({
|
|
text: "Salva",
|
|
onClick: function (e, $btOk, $div) {
|
|
const $table = $("#tableArticoliDuplicati");
|
|
|
|
$table.find(".save:visible").trigger("click");
|
|
|
|
const trs = $table.find("tbody > tr");
|
|
|
|
_.each(trs, function (tr) {
|
|
const $tr = $(tr);
|
|
const codMart = $tr.find(".codMart").text();
|
|
const qtaOrd = $tr.find(".qtaOrd").text();
|
|
const righe = retData.righe;
|
|
const obj = righe.find(riga => riga.cod_mart === codMart && riga.id_riga_art === 1);
|
|
|
|
if (obj) {
|
|
obj.qta_ord = parseInt(qtaOrd);
|
|
}
|
|
});
|
|
|
|
const data = {
|
|
"key": key,
|
|
"righe": retData.righe,
|
|
}
|
|
|
|
ajax
|
|
.post("accorpaOrdini")
|
|
.waitModal()
|
|
.data(data)
|
|
.noticeAsToast()
|
|
.onSuccess(function (ret) {
|
|
const toast = new Toast();
|
|
toast.success("L'ordine n. " + key.num_ord + " è stato accorpato");
|
|
|
|
modalBox.close();
|
|
|
|
location.reload();
|
|
})
|
|
.execute();
|
|
}
|
|
})
|
|
.content(template({articoli: retData.righeDuplicate}))
|
|
.style("warning")
|
|
.backdropStatic().backhash().xl().okCancel().show();
|
|
} else {
|
|
const toast = new Toast();
|
|
toast.success("L'ordine n. " + key.num_ord + " è stato accorpato");
|
|
|
|
location.reload();
|
|
}
|
|
})
|
|
.execute();
|
|
}
|
|
|
|
$("#upload_ordine").on("click", function () {
|
|
$("input[name='file_orda']").trigger("click");
|
|
});
|
|
|
|
$("input[name='file_orda']").on("change", function () {
|
|
_ordiniA.uploadFile();
|
|
});
|
|
|
|
$("#btGetXmlGriglia").on("click", function () {
|
|
const $bt = $(this);
|
|
const codAlis = $("#cod_alis").getValue();
|
|
|
|
if (!is_null(codAlis)) {
|
|
const ajax = new Ajax();
|
|
ajax.get("get_xmlGriglia")
|
|
.data({cod_alis: codAlis})
|
|
.$button($bt)
|
|
.noticeAsModal()
|
|
.onSuccess({downloadString: "OR_4" + codAlis + ".xml"})
|
|
.execute();
|
|
}
|
|
});
|
|
|
|
$("#cod_alis").on("change", function () {
|
|
$("#btGetXmlGriglia").disabled(is_null($(this).getValue()));
|
|
});
|
|
_ordiniA.init(module);
|
|
}
|
|
).load();
|
|
});
|
|
|
|
const _ordiniA = {
|
|
module: null,
|
|
arr_listini: [],
|
|
|
|
init: function (module) {
|
|
const self = this;
|
|
const $table = $("table#list_ord");
|
|
|
|
clean_queryString();
|
|
self.module = module;
|
|
|
|
$("#btGetXmlGriglia").disabled();
|
|
$("#flt-fornitore").textTableFilter({$table: $table, children: [1]});
|
|
|
|
let availableDataOrdFlt = [];
|
|
$table.find("tbody > tr > td:nth-child(3)").each(function () {
|
|
availableDataOrdFlt.push($(this).text().trim().strtotime("DD/MM/YYYY"));
|
|
});
|
|
availableDataOrdFlt = _.uniq(availableDataOrdFlt);
|
|
|
|
let $fltDataOrd = $("#flt-dataOrd");
|
|
$fltDataOrd.datepicker({dateFormat: "dd/mm/yy"});
|
|
$fltDataOrd.setAvailableValuesDatepicker(availableDataOrdFlt);
|
|
$fltDataOrd.textTableFilter({$table: $table, children: [3]});
|
|
|
|
$("#bt_fltCancel").on("click", function () {
|
|
$("#flt-fornitore, #flt-dataOrd").val("").trigger("change");
|
|
});
|
|
|
|
const $codAlis = $("select#cod_alis");
|
|
self.arr_listini = self.module.get_dataSource("listini");
|
|
if (self.arr_listini.length > 0) {
|
|
$codAlis.html("<option value=''></option>");
|
|
for (var i = 0; i < self.arr_listini.length; i++) {
|
|
var listino = self.arr_listini[i];
|
|
$codAlis.append("<option value='" + listino.cod_alis + "'>" + listino.cod_alis + " - " + listino.descrizione + "</option>");
|
|
}
|
|
} else {
|
|
$codAlis.disabled();
|
|
}
|
|
|
|
$codAlis.selectpicker({size: 10, noneSelectedText: "Seleziona un listino", liveSearch: true});
|
|
},
|
|
|
|
popup: {
|
|
key: null,
|
|
modalBox: null,
|
|
|
|
open: function (key) {
|
|
const self = this;
|
|
const ajax = new Ajax();
|
|
|
|
ajax.get("popup-ordine")
|
|
.data({key: key})
|
|
.waitModal("Caricamento dati ordine")
|
|
.noticeAsModal()
|
|
.onSuccess(function (ret) {
|
|
const popupData = ret.returnData;
|
|
self.key = key;
|
|
self.modalBox = new ModalBox();
|
|
|
|
if (popupData.flagEditabile) {
|
|
self.modalBox
|
|
.onBeforeShow(function () {
|
|
self.init_events(popupData);
|
|
})
|
|
.okCancel()
|
|
.btCancel({size: {sm: 4, md: 4}})
|
|
.btOK({
|
|
style: "primary", text: "Aggiorna", size: {sm: 8, md: 8}, onClick: function () {
|
|
self.save();
|
|
}
|
|
});
|
|
} else {
|
|
self.modalBox.closeOnly();
|
|
}
|
|
|
|
self.modalBox.lg().primary(ret.returnString, "Ordine n. <b>" + key.num_ord + "</b> del <b>" + key.data_ord.unixtime_format("DD/MM/YYYY") + "</b>");
|
|
})
|
|
.execute();
|
|
},
|
|
|
|
save: function () {
|
|
const self = this;
|
|
const key = self.key;
|
|
const $div = self.modalBox.$div;
|
|
const $noteP = $div.find("[name='noteP']:checked");
|
|
const noteP = $noteP.exists() ? $noteP.getValue() : null;
|
|
const data = {
|
|
key: key,
|
|
term_cons: $div.find("[name='term_cons']").length ? $div.find("[name='term_cons']").getValue() : "",
|
|
note_popup: noteP,
|
|
num_prenotazione: $div.find("input[name='num_prenotazione']").length ? $div.find("input[name='num_prenotazione']").getValue() : "",
|
|
rows: []
|
|
};
|
|
|
|
$div.find("table > tbody > tr").each(function () {
|
|
const $tr = $(this);
|
|
const artData = $tr.getDataAttr("art_data");
|
|
|
|
data.rows.push({
|
|
cod_mart: artData.cod_mart,
|
|
cod_art_for: artData.cod_art_for,
|
|
riga_ord: artData.riga_ord,
|
|
qta_ord: $tr.find("input.qta_ord").getNumericValue(),
|
|
qta_ord2: $tr.find("input.qta_ord2").length ? $tr.find("input.qta_ord2").getNumericValue() : null,
|
|
qta_ord3: $tr.find("input.qta_ord3").length ? $tr.find("input.qta_ord3").getNumericValue() : null,
|
|
data_cons: $tr.find("input.data_cons").getTimestampValue()
|
|
});
|
|
});
|
|
|
|
const ajax = new Ajax();
|
|
ajax.post("update_ordine")
|
|
.data(data)
|
|
.waitModal("Aggiornamento dati ordine")
|
|
.noticeAsModal()
|
|
.onSuccess(function () {
|
|
self.modalBox.close();
|
|
_APP.location.reload("Ordine aggiornato");
|
|
})
|
|
.execute();
|
|
},
|
|
|
|
init_events: function (popupData) {
|
|
const self = this;
|
|
|
|
self.init_srcArt(popupData)
|
|
.init_radioNoteOP()
|
|
.init_dataCons();
|
|
|
|
self.modalBox.$div.find("table > tbody > tr").each(function () {
|
|
self.init_qtaRefresh($(this), popupData.tipoAzienda);
|
|
});
|
|
},
|
|
|
|
init_srcArt: function (popupData) {
|
|
const self = this;
|
|
const key = self.key;
|
|
const data = {listino: popupData.listino, gestione: key.gestione, data_validita: key.data_ord};
|
|
|
|
self.modalBox.$div.find("#src_art").bsautocomplete({
|
|
sourceAjaxAction: "src_art",
|
|
ajaxData: data,
|
|
item_labelKey: ["cod_mart"],
|
|
item_labelSubKey: ["descrizione"],
|
|
onSelect: function (e, retData, $this) {
|
|
self.append_nuovoArticolo(retData);
|
|
$this.val("").blur();
|
|
}
|
|
});
|
|
|
|
return self;
|
|
},
|
|
|
|
append_nuovoArticolo: function (articolo) {
|
|
const self = this;
|
|
const dataCons = self.get_suggestDataCons();
|
|
const artData = {
|
|
qta_cnf: articolo.qta_cnf,
|
|
cod_mart: articolo.cod_mart,
|
|
cod_art_for: articolo.cod_art_for,
|
|
riga_ord: 0
|
|
};
|
|
|
|
const $tr = $("<tr>", {
|
|
class: articolo.flag_assortimento === "N" ? "danger" : "",
|
|
"data-art_data": _ojbc.B64JSON_stringify(artData)
|
|
})
|
|
.append($("<td>", {class: "text-center", html: articolo.cod_mart}))
|
|
.append($("<td>", {class: "text-center", html: articolo.cod_art_for}))
|
|
.append($("<td>", {class: "small", html: articolo.descrizione}))
|
|
.append($("<td>", {
|
|
html: $("<div>", {
|
|
class: "input-group input-group-xs",
|
|
html: $("<input>", {
|
|
type: "text",
|
|
class: "data_cons form-control",
|
|
autocomplete: false,
|
|
value: dataCons.unixtime_format("DD/MM/YYYY"),
|
|
"data-prec_value": dataCons.unixtime_format("DD/MM/YYYY"),
|
|
readonly: true
|
|
})
|
|
}).append("<span class='input-group-addon dpicker'><i class='fa fa-calendar'></i></span>")
|
|
})).append($("<td>", {
|
|
html: $("<input>", {
|
|
type: "number",
|
|
class: "colli form-control input-xs no-spin-buttons",
|
|
autocomplete: false,
|
|
value: "",
|
|
lang: "en",
|
|
step: "any",
|
|
min: "0"
|
|
})
|
|
}))
|
|
.append($("<td>", {class: "text-center", html: articolo.unt_mis}))
|
|
.append($("<td>", {
|
|
html: $("<input>", {
|
|
type: "number",
|
|
class: "qta_ord form-control input-xs no-spin-buttons",
|
|
autocomplete: false,
|
|
value: "",
|
|
lang: "en",
|
|
step: "any",
|
|
min: "0"
|
|
})
|
|
}));
|
|
|
|
self.modalBox.$div.find("table").children("tbody").append($tr);
|
|
|
|
self.init_datePicker($tr.find("input.data_cons"))
|
|
.init_qtaRefresh($tr);
|
|
$tr.find("input.colli").focus();
|
|
|
|
return self;
|
|
},
|
|
|
|
get_suggestDataCons: function () { // RICERCA DI DATA CONS PIU COMUNE
|
|
const self = this;
|
|
const arr_dataCons = [];
|
|
|
|
self.modalBox.$div.find("table").children("tbody").find("input.data_cons").each(function () {
|
|
const dataCons = $(this).getTimestampValue();
|
|
|
|
if (!is_null(dataCons)) {
|
|
arr_dataCons.push(dataCons);
|
|
}
|
|
});
|
|
|
|
if (arr_dataCons.length > 0) {
|
|
const arr_groupCount = Enumerable.From(arr_dataCons)
|
|
.Select(function (dataCons) {
|
|
const c = Enumerable.From(arr_dataCons).Where(function (x) {
|
|
return x === dataCons;
|
|
}).Count();
|
|
|
|
return {data_cons: dataCons, c: c};
|
|
})
|
|
.Distinct(function (x) {
|
|
return x.data_cons;
|
|
})
|
|
.OrderByDescending(function (x) {
|
|
return x.c;
|
|
})
|
|
.ThenBy(function (x) {
|
|
return x.data_cons;
|
|
})
|
|
.ToArray();
|
|
|
|
return arr_groupCount[0].data_cons;
|
|
}
|
|
|
|
return getToday();
|
|
},
|
|
|
|
init_qtaRefresh: function ($tr, tipoAzienda) {
|
|
const self = this;
|
|
|
|
if (!tipoAzienda) {
|
|
const artData = $tr.getDataAttr("art_data");
|
|
const $colli = $tr.find("input.colli");
|
|
const $qtaOrd = $tr.find("input.qta_ord");
|
|
const qtaCnf = artData.qta_cnf;
|
|
|
|
$qtaOrd.on("change, keyup", function () {
|
|
const qtaOrd = $(this).getValue();
|
|
const colli = Math.ceil((qtaCnf == 0) ? qtaOrd : qtaOrd / qtaCnf);
|
|
|
|
$colli.val(colli);
|
|
});
|
|
|
|
$colli.on("change, keyup", function () {
|
|
const colli = $(this).getValue();
|
|
const qtaOrd = qtaCnf == 0 ? colli : colli * qtaCnf;
|
|
|
|
$qtaOrd.val(qtaOrd);
|
|
});
|
|
} else {
|
|
const $pezzi = $tr.find("input.qta_ord");
|
|
const $basi = $tr.find("input.qta_ord2");
|
|
const $carrelli = $tr.find("input.qta_ord3");
|
|
const pezziRc = parseFloat($pezzi.attr("data-rapconv"));
|
|
const basiRc = parseFloat($basi.attr("data-rapconv"));
|
|
const carrelliRc = parseFloat($carrelli.attr("data-rapconv"));
|
|
|
|
$pezzi.on("change, keyup", function () {
|
|
$basi.val(($(this).getNumericValue() * pezziRc / basiRc).toPrecision(5));
|
|
$carrelli.val(($(this).getNumericValue() * pezziRc / carrelliRc).toPrecision(5));
|
|
});
|
|
|
|
$basi.on("change, keyup", function () {
|
|
$pezzi.val(($(this).getNumericValue() * basiRc / pezziRc).round());
|
|
$carrelli.val(($(this).getNumericValue() * basiRc / carrelliRc).toPrecision(5));
|
|
});
|
|
|
|
$carrelli.on("change, keyup", function () {
|
|
$pezzi.val(($(this).getNumericValue() * carrelliRc / pezziRc).round());
|
|
$basi.val(($(this).getNumericValue() * carrelliRc / basiRc).toPrecision(5));
|
|
});
|
|
}
|
|
|
|
return self;
|
|
},
|
|
|
|
init_radioNoteOP: function () {
|
|
const self = this;
|
|
const $div = self.modalBox.$div;
|
|
const $radioO = $div.find(":radio[value='O']");
|
|
const $radioP = $div.find(":radio[value='R']");
|
|
const $numPrenotazione = $div.find("input[name='num_prenotazione']");
|
|
|
|
$radioO.on("click", function () {
|
|
$numPrenotazione.val("");
|
|
});
|
|
|
|
$radioP.on("click", function () {
|
|
$numPrenotazione.select();
|
|
});
|
|
|
|
$numPrenotazione.on("focus", function () {
|
|
$radioP.checked();
|
|
});
|
|
|
|
return self;
|
|
},
|
|
|
|
init_datePicker: function ($dataCons) {
|
|
const self = this;
|
|
|
|
$dataCons.datepicker({
|
|
dateFormat: "dd/mm/yy",
|
|
minDate: +1,
|
|
defaultDate: +2,
|
|
onSelect: function (dateText) {
|
|
const $this = $(this);
|
|
const precValue = $this.getDataAttr("prec_value");
|
|
let checkOtherSameValue = false;
|
|
|
|
$this.attr("data-prec_value", dateText);
|
|
|
|
$this.closest("tr").siblings("tr").each(function () {
|
|
var $input = $(this).find("input.data_cons");
|
|
if ($input.exists()) {
|
|
if ($input.val() === precValue) {
|
|
checkOtherSameValue = true;
|
|
}
|
|
}
|
|
});
|
|
|
|
if (checkOtherSameValue) {
|
|
const modalBox = new ModalBox();
|
|
|
|
modalBox.yesNo()
|
|
.content("Vuoi impostare la data <b>" + dateText + "</b> anche sulle righe con la stessa data consegna?")
|
|
.title("Aggiornamento data di consegna")
|
|
.show()
|
|
.then(function (ret) {
|
|
if (ret) {
|
|
$.each($dataCons, function () {
|
|
if ($(this).val() === precValue) {
|
|
$(this).val(dateText).attr("data-prec_value", dateText);
|
|
}
|
|
});
|
|
}
|
|
});
|
|
}
|
|
}
|
|
});
|
|
|
|
return self;
|
|
},
|
|
|
|
init_dataCons: function () {
|
|
const self = this;
|
|
|
|
return self.init_datePicker(self.modalBox.$div.find("input.data_cons"));
|
|
}
|
|
},
|
|
|
|
uploadFile: function (codAlis = null) {
|
|
const self = this;
|
|
const $file = $("input[name='file_orda']");
|
|
|
|
if (isNotEmpty($file.val()) && $file.checkType(".xml")) {
|
|
const $bt = $("#upload_ordine");
|
|
const requestListino = function () {
|
|
const arr_listini = self.arr_listini;
|
|
let html = "Indica il listino per l'ordine che si sta caricando<br/><br/>";
|
|
|
|
html += "<select id='cod_alis-p' class='form-control'><option value=''></option>";
|
|
|
|
for (let i = 0; i < arr_listini.length; i++) {
|
|
const item = arr_listini[i];
|
|
html += "<option value='" + item.cod_alis + "'>" + item.cod_alis + " - " + item.descrizione + "</option>";
|
|
}
|
|
|
|
html += "</select>";
|
|
|
|
const modalBoxPrompt = new ModalBox();
|
|
modalBoxPrompt.btOK({
|
|
style: "primary",
|
|
onClick: function () {
|
|
const codAlis = $("#cod_alis-p").getValue();
|
|
|
|
if (!is_null(codAlis)) {
|
|
modalBoxPrompt.close(true);
|
|
_ordiniA.uploadFile(codAlis);
|
|
} else {
|
|
const toast = new Toast();
|
|
toast.warning("Seleziona un listino");
|
|
}
|
|
}
|
|
}).onBeforeShow(function () {
|
|
$("#cod_alis-p").selectpicker({
|
|
liveSearch: true,
|
|
size: 10,
|
|
noneSelectedText: "",
|
|
dropupAuto: false
|
|
});
|
|
}).onShow(function () {
|
|
$("#cod_alis-p").focus();
|
|
}).sm().backdropStatic().okCancel().primary(html, "Importa ordine da file");
|
|
};
|
|
|
|
const ajax = new Ajax();
|
|
ajax.post("upload_ordine")
|
|
.data({cod_alis: codAlis})
|
|
.koAsModal()
|
|
.$button($bt)
|
|
.file($file)
|
|
.onSuccess(function (ret) {
|
|
const modalBox = new ModalBox();
|
|
modalBox.success().content("È stato creato l'ordine n. " + ret.returnNumber).show().then(function () {
|
|
_APP.location.href(_PHP_SELF + "?focus=" + ret.returnString);
|
|
});
|
|
})
|
|
.onWarning(function () {
|
|
requestListino();
|
|
})
|
|
.execute();
|
|
}
|
|
}
|
|
}; |