Finish Carelli_DocInterni_ControlloRigheOnSave

This commit is contained in:
2023-11-03 17:16:17 +01:00
5 changed files with 222 additions and 158 deletions

View File

@@ -291,6 +291,7 @@ class Rest {
$ret["http_code"] = $httpCode;
$ret["body"] = $result->raw_body;
$Ret->set_number($httpCode);
if ($httpCode == 200) {
$rawResponse = $result->raw_body;
if (!is_null($this->privateKey)) {
@@ -346,6 +347,10 @@ class Rest {
if ($retData[0]["esito"] == 1) {
$Ret->set_data($retData);
} else {
if ($retData) {
$Ret->set_data($retData);
}
if (isset($retData[0]["errorMessage"])) {
$Ret->set_error($retData[0]["errorMessage"]);
} else {
@@ -361,19 +366,15 @@ class Rest {
}
}
}
} else if ($httpCode == 400) {
$errorLog = "400";
$Ret->set_errorCode(ErrorHandler::EMSHTTP400, $this->service);
} else if ($httpCode == 550) {
$errorLog = "550";
$Ret->set_errorCode(ErrorHandler::EMSHTTP550, $this->service);
} else if ($httpCode == 551) {
$errorLog = "551";
$Ret->set_errorCode(ErrorHandler::EMSHTTP551, $this->service);
} else {
$errorLog = $httpCode;
$Ret->set_errorCode(ErrorHandler::EMSHTTP, $httpCode, $rawHeaders, $this->service);

View File

@@ -104,47 +104,51 @@ class DocInterni {
public static function gen_doc($data) {
$datiDoc = $data["dati_doc"];
$keyCollo = $data["key_collo"];
$Ret = new Ret();
$ret = new Ret();
if ($keyCollo["cod_dtip_provv"] === "TRAPV" && !self::getPermettiTrapv($datiDoc["mbox_cod_anag"])) {
$Ret->set_error("Destinatario documento non idoneo alla creazione di un documento di trasferimento tra P.V.!");
return $Ret;
}
$Ret = self::validateDocAndForn($datiDoc, $keyCollo);
if (!$Ret->is_OK()) {
return $Ret;
$ret->set_error("Destinatario documento non idoneo alla creazione di un documento di trasferimento tra P.V.!");
return $ret;
}
$Body = new EntityItem;
$ret = self::validateDocAndForn($datiDoc, $keyCollo);
if (!$ret->is_OK()) {
return $ret;
}
$body = new EntityItem;
if (array_key_exists("note_doc", $datiDoc)) {
$Body->set("noteDoc", $datiDoc["note_doc"]);
$body->set("noteDoc", $datiDoc["note_doc"]);
} else {
$Body->set("codAnag", $datiDoc["mbox_cod_anag"])
$body->set("codAnag", $datiDoc["mbox_cod_anag"])
->set("codVdes", $datiDoc["mbox_cod_vdes"]);
}
if (isset($datiDoc["mbox_data_doc"])) {
$Body->set("dataDoc", strftime(Format::strftimeDMY, $datiDoc["mbox_data_doc"]))
$body->set("dataDoc", strftime(Format::strftimeDMY, $datiDoc["mbox_data_doc"]))
->set("numDoc", $datiDoc["mbox_num_doc"]);
}
$Body->set("tipoLista", $keyCollo["gestione_doc"]);
$body->set("tipoLista", $keyCollo["gestione_doc"]);
$Collo = new EntityItem;
$Collo->set("gestione", $keyCollo["gestione"])
$collo = new EntityItem;
$collo->set("gestione", $keyCollo["gestione"])
->set("dataCollo", strftime(Format::strftimeDMY, $keyCollo["data_collo"]) . " 00:00:00")
->set("serCollo", $keyCollo["ser_collo"])
->set("numCollo", $keyCollo["num_collo"]);
$Body->set("colli")->append($Collo);
$body->set("colli")->append($collo);
$IMSApi = new IMSApi;
$Ret = $IMSApi->post("saveDocFromPickingPvm")->body($Body)->send();
if ($Ret->is_OK()) {
$retData = $Ret->get_data();
$data = $retData[0];
$ret = $IMSApi->post("saveDocFromPickingPvm")->body($body)->send();
$retData = $ret->get_data();
$data = $retData[0];
if ($ret->is_OK()) {
$entityList = array_key_exists("entityList", $data) ? $data["entityList"] : $data["dto"];
$entity = reset($entityList);
if (array_key_exists("codDtip", $entity)) {
$docKey = array(
"cod_dtip" => $entity["codDtip"],
@@ -155,17 +159,23 @@ class DocInterni {
);
$reportName = self::getReportName();
if (!is_null($reportName)) {
$Ret = self::save_dtbDocPdf($docKey);
$ret = self::save_dtbDocPdf($docKey);
}
if ($Ret->is_OK()) {
$Ret->set_string(B64JSON_stringify($docKey));
if ($ret->is_OK()) {
$ret->set_string(B64JSON_stringify($docKey));
}
}
} else if (array_get($data, "errorMessage")) {
$ret->set_data($data);
} else {
$dto = $data["dto"];
$ret->set_data($dto);
}
return $Ret;
return $ret;
}
private static function save_dtbDocPdf($docKey) {
@@ -289,8 +299,6 @@ class DocInterni {
$Ret = new Ret;
$fornKey = array_key_exists("mbox_cod_anag", $datiDoc) ? ($datiDoc["mbox_cod_anag"] . ($datiDoc["mbox_cod_vdes"] ? "-" . $datiDoc["mbox_cod_vdes"] : "")) : null;
if (self::allowNote($keyCollo)) {
$Ret = self::get_cnfSenzaPartita($keyCollo);
if ($Ret->is_OK()) {
@@ -300,20 +308,6 @@ class DocInterni {
}
}
}
if ($fornSetup != null && array_key_exists($fornKey, $fornSetup) && array_key_exists($keyCollo["cod_dtip_provv"], $fornSetup[$fornKey])) {
switch ($fornSetup[$fornKey][$keyCollo["cod_dtip_provv"]]) {
case "check-partitaMag":
$Ret = self::get_cnfSenzaPartita($keyCollo);
if ($Ret->is_OK()) {
$batchless = $Ret->get_data();
if (!empty($batchless)) {
$Ret->set_error("Assegnare la data di scadenza sugli articoli che prevedono tracciabilità e riprovare.");
}
}
break;
}
}
if ($docSetup != null && array_key_exists($keyCollo["cod_dtip_provv"], $docSetup) &&
!in_array(

View File

@@ -1,8 +1,12 @@
<?
$Ret = DocInterni::getCollo($data["key"]);
if ($Ret->is_OK()) {
$collo = $Ret->get_data();
<?php
$key = $data["key"];
$righeErrate = array_get($key, "righeErrate");
$ret = DocInterni::getCollo($key);
if ($ret->is_OK()) {
$collo = $ret->get_data();
ob_start();
if (!is_null($collo["rag_soc"])) {
?>
<div class="row">
@@ -18,37 +22,71 @@ if ($Ret->is_OK()) {
</span>
</div>
</div>
<?
<?php
}
$is_lottoVisible = DocInterni::is_lottoVisible();
$is_lottoEditable = DocInterni::is_lottoEditable();
$allowNote = DocInterni::allowNote($collo);
$minDataSCad = $allowNote ? \Utility\Date::fromNow(0) : \Utility\Date::fromNow(-15);
?>
<div class="max-height-400px">
<table class="table table-striped table-hover table-condensed mt-20">
<thead>
<tr>
<?php if ($righeErrate) { ?>
<th></th>
<?php } ?>
<th>Cod. Articolo</th>
<th>Descrizione</th><?
if ($is_lottoVisible || $is_lottoEditable) {
?>
<th>Descrizione</th>
<?php if ($is_lottoVisible || $is_lottoEditable) { ?>
<th>Lotto</th>
<th style="width: 120px;">Scadenza</th><?
} ?>
<th style="width: 120px;">Scadenza</th>
<?php } ?>
<th>Quantit&agrave;</th>
</tr>
</thead>
<tbody><?
foreach ($collo["rows"] as $riga) {
?>
<tbody>
<?php foreach ($collo["rows"] as $riga) { ?>
<tr data-riga="<?= $riga["riga"] ?>" data-cod_mart="<?= $riga["cod_mart"] ?>">
<?php
$result = $righeErrate ? array_values(array_filter($righeErrate, function ($x) use ($riga) {
return $x["codMart"] === $riga["cod_mart"];
})) : null;
if ($righeErrate) {
?>
<td class="text-center" style="color: red">
<?php
if ($result) {
$result = $result[0];
$title = "";
if (array_get($result, "nonAcquistato")) {
$title = "Articolo non acquistato dal fornitore";
} else if (array_get($result, "qtaMaggiore")) {
$title = "Quantità resa maggiore di quella acquistata";
if (array_get($result, "qtaAcq")) {
$title .= " (" . $result["qtaAcq"] . ")";
}
} else if (array_get($result, "scadenzaNulla")) {
$title = "Assegnare la data di scadenza sugli articoli che prevedono tracciabilità e riprovare";
}
?>
<div data-toggle="tooltip" data-placement="top" title="<?= $title ?>">
<i class="fa fa-fw fa-exclamation-triangle" style="font-size: 20px"></i>
</div>
<?php } ?>
</td>
<?php } ?>
<td class="text-center"><?= $riga["cod_mart"] ?></td>
<td><?
if (is_null($riga["cod_mart"])) {
?>
<td>
<?php if (is_null($riga["cod_mart"])) { ?>
<input type="text" class="descrizione form-control input-xs"
value="<?= htmlentities($riga["descrizione"]) ?>"/><?
value="<?= htmlentities($riga["descrizione"]) ?>"/>
<?php
} else {
echo htmlentities($riga["descrizione"]);
if ($allowNote) {
@@ -56,51 +94,52 @@ if ($Ret->is_OK()) {
<br>
<input type="text" required class="note form-control input-xs"
value="<?= htmlentities($riga["note"]) ?>"/>
<?
<?php
}
} ?>
</td><?
if ($is_lottoVisible) {
}
?>
<td><?
if ($is_lottoEditable && ($riga["flag_tracciabilita"] == "S" || $allowNote)) {
?>
<input class="partita_mag form-control input-sm" value="<?= $riga["partita_mag"] ?>"/><?
</td>
<?php if ($is_lottoVisible) { ?>
<td>
<?php if ($is_lottoEditable && ($riga["flag_tracciabilita"] == "S" || $allowNote)) { ?>
<input class="partita_mag form-control input-sm"
value="<?= $riga["partita_mag"] ?>"/>
<?php
} else {
echo $riga["partita_mag"];
} ?>
</td>
<td><?
if ($is_lottoEditable && ($riga["flag_tracciabilita"] == "S" || $allowNote)) {
}
?>
<input class="data_scad form-control input-sm"
min="<?= $minDataSCad->format(Format::strtotimeDMY) ?>"
value="<?= Utility\Date::format($riga["data_scad"], Format::strftimeDMY) ?>"
readonly /><?
} else {
echo $riga["data_scad"] ? Utility\Date::format($riga["data_scad"], Format::strftimeDMY) : "";
} ?>
</td><?
} ?>
</td>
<td>
<?php if ($is_lottoEditable && ($riga["flag_tracciabilita"] == "S" || $allowNote)) { ?>
<input class="data_scad form-control input-sm"
min="<?= $minDataSCad->format(Format::strtotimeDMY) ?>"
value="<?= Utility\Date::format($riga["data_scad"], Format::strftimeDMY) ?>"
readonly/>
<?php
} else {
echo $riga["data_scad"] ? Utility\Date::format($riga["data_scad"], Format::strftimeDMY) : "";
}
?>
</td>
<?php } ?>
<td style="width: 120px;">
<div class="input-group input-group-xs">
<div class="input-group input-group-sm">
<input type="number" class="qta_col form-control text-monospace no-spin-buttons" step="any"
value="<?= $riga["qta_col"] ?>"/>
<span class="input-group-addon text-monospace" style="width: 30px;">
<?= is_null($riga["cod_mart"]) ? "ND" : $riga["unt_mis"] ?>
</span>
</span>
</div>
</td>
</tr>
<? } ?>
<?php } ?>
</tbody>
</table>
</div>
<?
<?php
$html = Utility\Str::remove_multiple_spaces(@ob_get_clean());
$Ret->set_string($html);
$ret->set_string($html);
}
$Ret->display();
$ret->display();

View File

@@ -3,12 +3,14 @@ $(function () {
e.stopPropagation();
const $tr = $(this).closest("tr[data-keycollo]");
const keyCollo = $tr.getDataAttr("keycollo");
const righeErrate = $tr.getAttr("data-righeErrate");
const keyCollo = $tr.getAttr("data-keycollo");
const key = {
dataCollo: keyCollo.data_collo,
gestione: keyCollo.gestione,
serCollo: keyCollo.ser_collo,
numCollo: keyCollo.num_collo
numCollo: keyCollo.num_collo,
righeErrate: righeErrate
};
const title = "Collo n. " + key.numCollo + " del " + key.dataCollo.unixtime_format("DD/MM/YYYY");
@@ -19,69 +21,79 @@ $(function () {
.waitModal()
.onSuccess(function (ret) {
const modalBox = new ModalBox();
modalBox.btOK({
text: "Salva", style: "primary", size: {sm: 12},
onClick: function (e, $bt, $div) {
const rows = [];
let error = false;
$div.find("table > tbody > tr").each(function () {
const $tr = $(this);
if ($tr.find(".note").length > 0 && (_.isEmpty($tr.find(".note").val()))) {
const toast = new Toast();
toast.danger("inserisci tutte le note per poter continuare!");
error = true;
return false;
}
const codMart = $tr.getDataAttr("cod_mart");
const row = {
riga: $tr.getDataAttr("riga"),
qtaCol: $tr.find(".qta_col").getValue(),
codMart: codMart,
note: is_null(codMart) ? $tr.find(".descrizione").getValue() : $tr.find(".note").val()
};
if ($tr.find("input.partita_mag").exists()) {
row.partitaMag = $tr.find("input.partita_mag").val();
}
modalBox
.btOK({
text: "Salva", style: "primary", size: {sm: 12},
onClick: function (e, $bt, $div) {
const rows = [];
let error = false;
if ($tr.find("input.data_scad").exists()) {
let datascad = $tr.find("input.data_scad").val();
if (!_.isNil(datascad)) {
let formattedDate = moment(datascad, "DD/MM/YYYY");
if (formattedDate.isValid()) {
row.dataScad = formattedDate.format("YYYY/MM/DD");
} else {
row.dataScad = datascad;
}
} else {
row.dataScad = $tr.find("input.data_scad").val();
$div.find("table > tbody > tr").each(function () {
const $tr = $(this);
if ($tr.find(".note").length > 0 && (_.isEmpty($tr.find(".note").val()))) {
const toast = new Toast();
toast.danger("inserisci tutte le note per poter continuare!");
error = true;
return false;
}
}
rows.push(row);
});
const codMart = $tr.getAttr("data-cod_mart");
const row = {
riga: $tr.getAttr("data-riga"),
qtaCol: $tr.find(".qta_col").getValue(),
codMart: codMart,
note: is_null(codMart) ? $tr.find(".descrizione").getValue() : $tr.find(".note").val()
};
if (!error) {
const ajax = new Ajax();
ajax.post("updateCollo")
.data({key: key, rows: rows})
.noticeAsModal()
.waitModal()
.onSuccess({
toast: {message: "Il collo è stato aggiornato"},
callback: function (ret) {
$tr.find(".tot_colli").text(ret.returnData.tot_colli.toFixed(0));
$tr.find(".tot_peso").text(ret.returnData.tot_peso.toFixed(2));
modalBox.close();
if ($tr.find("input.partita_mag").exists()) {
row.partitaMag = $tr.find("input.partita_mag").val();
}
if ($tr.find("input.data_scad").exists()) {
let datascad = $tr.find("input.data_scad").val();
if (!_.isNil(datascad)) {
let formattedDate = moment(datascad, "DD/MM/YYYY");
if (formattedDate.isValid()) {
row.dataScad = formattedDate.format("YYYY/MM/DD");
} else {
row.dataScad = datascad;
}
} else {
row.dataScad = $tr.find("input.data_scad").val();
}
})
.execute();
}
rows.push(row);
});
if (!error) {
const ajax = new Ajax();
ajax.post("updateCollo")
.data({key: key, rows: rows})
.noticeAsModal()
.waitModal()
.onSuccess({
toast: {message: "Il collo è stato aggiornato"},
callback: function (ret) {
$tr.find(".tot_colli").text(ret.returnData.tot_colli.toFixed(0));
$tr.find(".tot_peso").text(ret.returnData.tot_peso.toFixed(2));
modalBox.close();
}
})
.execute();
}
}
}
})
})
.onBeforeShow(function ($div) {
const $datascad = $div.find("input.data_scad");
$datascad.datepicker({dateFormat: "dd/mm/yy", minDate: $datascad.attr("min")});
$("[data-toggle='tooltip']").tooltip({
container: "#" + modalBox.getId()
});
})
.lg().primary(ret.returnString, title);
})
@@ -91,8 +103,8 @@ $(function () {
$(".bt_save").on("click", function () {
const $td = $(this).closest("td");
const $tr = $td.closest("tr[data-keycollo]");
const keyCollo = $tr.getDataAttr("keycollo");
const datiCollo = $tr.getDataAttr("daticollo");
const keyCollo = $tr.getAttr("data-keycollo");
const datiCollo = $tr.getAttr("data-daticollo");
const gestioneDoc = keyCollo.gestione_doc;
const gestioneTipoDoc = keyCollo.gestione_tipo_doc;
@@ -192,18 +204,34 @@ $(function () {
ajax.post("gen_doc")
.data({dati_doc: formData, key_collo: keyCollo})
.waitModal()
.noticeAsModal()
.onSuccess(function (ret) {
modalBoxForm.close();
if (ret.returnString) {
_APP.location.href("doc_interni.php?viewdoc=&focus=" + ret.returnString);
} else {
var toast = new Toast();
const toast = new Toast();
toast.success("Collo salvato con successo");
_APP.location.reload("Ricarico i dati...");
}
}).execute();
})
.onError(function (ret) {
const retData = ret.returnData;
if (retData?.errorMessage) {
const modal = new ModalBox()
modal.danger(ret.errorText);
} else {
modalBoxForm.close();
const $editBtn = $tr.find(".bt_edit");
$tr.attr("data-righeErrate", _ojbc.B64JSON_stringify(retData));
$editBtn.trigger("click");
}
})
.execute();
}
}
})

View File

@@ -1103,15 +1103,17 @@ const _impostazioni = {
$btnGroup.append(btShowDescription);
// language=HTML
const btEditProp = `
<button class="btn btn-default btEditProp" type="button"
title="Modifica proprietà">
<i class="fas fa-pencil fa-fw text-info"></i>
</button>
`;
if (_USER.is_amministratoreSistema()) {
// language=HTML
const btEditProp = `
<button class="btn btn-default btEditProp" type="button"
title="Modifica proprietà">
<i class="fas fa-pencil fa-fw text-info"></i>
</button>
`;
$btnGroup.append(btEditProp);
$btnGroup.append(btEditProp);
}
if (gestSetup.flag_setup_depo === "S") {
// language=HTML