diff --git a/public_html/gest-lib/produttivita_a_valore/classes/ProduttivitaAValore.class.php b/public_html/gest-lib/produttivita_a_valore/classes/ProduttivitaAValore.class.php index 704c45dbc..209268f4b 100644 --- a/public_html/gest-lib/produttivita_a_valore/classes/ProduttivitaAValore.class.php +++ b/public_html/gest-lib/produttivita_a_valore/classes/ProduttivitaAValore.class.php @@ -30,54 +30,62 @@ class ProduttivitaAValore { } public static function get_reparti($codMdep, $mondayDate) { - $Query = new Query(); - $Ret = $Query + $query = new Query(); + $ret = $query ->importSqlFile("getReparti") ->setVar("cod_mdep", $codMdep) ->setVar("username", User::get_current_username()) ->toRet()->execute(); - if ($Ret->is_OK()) { - $arr_repo = $Ret->get_data(); + + if ($ret->is_OK()) { + $arr_repo = $ret->get_data(); + foreach ($arr_repo as $i => $repo) { $codJfas = $repo["cod_jfas"]; $um = explode("/", $repo["um_prod"]); $repo["um"] = $um[0]; // QTA_PREV_UM - $Ret = self::get_qtaBdgPrev($codMdep, $codJfas, $mondayDate); - if ($Ret->is_OK()) { - $qtaBdgPrev = self::fill_dataWeekRow($Ret->get_data()); + $ret = self::get_qtaBdgPrev($codMdep, $codJfas, $mondayDate); + + if ($ret->is_OK()) { + $qtaBdgPrev = self::fill_dataWeekRow($ret->get_data()); } else { break; } + $repo["qtaBdgPrev"] = $qtaBdgPrev; // QTA_CONSUNTIVA_UM - $Ret = self::get_qtaVendCons($codMdep, $codJfas, $mondayDate); - if ($Ret->is_OK()) { - $repo["qtaVendCons"] = self::fill_dataWeekRow($Ret->get_data()); + $ret = self::get_qtaVendCons($codMdep, $codJfas, $mondayDate); + + if ($ret->is_OK()) { + $repo["qtaVendCons"] = self::fill_dataWeekRow($ret->get_data()); } else { break; } // PERC_SCOSTAMENTO - $Ret = self::get_formazione($codMdep, $codJfas, $mondayDate); - if ($Ret->is_OK()) { - $repo["oreFormazione"] = self::fill_dataWeekRow($Ret->get_data()); + $ret = self::get_formazione($codMdep, $codJfas, $mondayDate); + + if ($ret->is_OK()) { + $repo["oreFormazione"] = self::fill_dataWeekRow($ret->get_data()); } else { break; } - $Ret = self::get_prodStd($codMdep, $codJfas, $mondayDate); - if ($Ret->is_OK()) { - $repo["prodStd"] = self::fill_dataWeekRow($Ret->get_data()); + $ret = self::get_prodStd($codMdep, $codJfas, $mondayDate); + + if ($ret->is_OK()) { + $repo["prodStd"] = self::fill_dataWeekRow($ret->get_data()); } else { break; } - $Ret = self::get_qtaBdgAdeg($codMdep, $codJfas, $mondayDate); - if ($Ret->is_OK()) { - $qtaBdgAdeg = self::fill_dataWeekRow($Ret->get_data()); + $ret = self::get_qtaBdgAdeg($codMdep, $codJfas, $mondayDate); + + if ($ret->is_OK()) { + $qtaBdgAdeg = self::fill_dataWeekRow($ret->get_data()); } else { break; } @@ -97,29 +105,33 @@ class ProduttivitaAValore { $retData = array(); - if ($Ret->is_OK()) { - $Ret = self::get_oreMin($codMdep, $mondayDate); - if ($Ret->is_OK()) { - $retData["oreMin"] = self::fill_dataWeekRow($Ret->get_data()); + if ($ret->is_OK()) { + $ret = self::get_oreMin($codMdep, $mondayDate); + + if ($ret->is_OK()) { + $retData["oreMin"] = self::fill_dataWeekRow($ret->get_data()); } } - if ($Ret->is_OK()) { - $Ret = self::get_oreSvolto($codMdep, $mondayDate); - if ($Ret->is_OK()) { - $retData["oreSvolto"] = self::fill_dataWeekRow($Ret->get_data()); + if ($ret->is_OK()) { + $ret = self::get_oreSvolto($codMdep, $mondayDate); + + if ($ret->is_OK()) { + $retData["oreSvolto"] = self::fill_dataWeekRow($ret->get_data()); } } - if ($Ret->is_OK()) { - $Ret = self::get_oreInvestimento($codMdep, $mondayDate); - if ($Ret->is_OK()) { - $retData["oreInvestimento"] = self::fill_dataWeekRow($Ret->get_data()); + if ($ret->is_OK()) { + $ret = self::get_oreInvestimento($codMdep, $mondayDate); + + if ($ret->is_OK()) { + $retData["oreInvestimento"] = self::fill_dataWeekRow($ret->get_data()); } } - if ($Ret->is_OK()) { + if ($ret->is_OK()) { $retData["oreFormazioneNegozio"] = self::fill_dataWeekRow(); + foreach ($arr_repo as $repo) { foreach ($repo["oreFormazione"] as $dayId => $oreFormazioneDay) { $retData["oreFormazioneNegozio"][$dayId] += $oreFormazioneDay; @@ -127,6 +139,7 @@ class ProduttivitaAValore { } $retData["differenzaNettoCN"] = self::fill_dataWeekRow(); + foreach ($retData["differenzaNettoCN"] as $dayId => $differenzaNettoCNDay) { $oreSvoltoDay = $retData["oreSvolto"][$dayId]; $oreInvestimentoDay = $retData["oreInvestimento"][$dayId]; @@ -135,10 +148,13 @@ class ProduttivitaAValore { $retData["differenzaNettoCN"][$dayId] = $differenzaNettoCNDay; } } + $rapProdStdPv = array(); + foreach ($arr_repo as $repo) { for ($j = 1; $j <= 7; $j++) { $dayId = "d{$j}"; + if (array_key_exists($dayId, $rapProdStdPv) && is_numeric($rapProdStdPv[$dayId])) { $rapProdStdPv[$dayId] += $repo["rapProd"][$dayId]; } else { @@ -146,6 +162,7 @@ class ProduttivitaAValore { } } } + $retData["RapProdStdPv"] = $rapProdStdPv; foreach ($arr_repo as $i => $repo) { @@ -153,18 +170,20 @@ class ProduttivitaAValore { foreach ($arr_repo as $k => $item) { if ($item["cod_jfas"] === $repo["cod_jfas_view"]) { $arr_repo[$k]["child"][] = $repo; - } } + unset($arr_repo[$i]); } } - if ($Ret->is_OK()) { + + if ($ret->is_OK()) { $retData["repo"] = $arr_repo; - $Ret->set_data($retData); + $ret->set_data($retData); } } - return $Ret; + + return $ret; } public static function get_prodStd($codMdep, $codJfas, $mondayDate) { @@ -220,8 +239,8 @@ class ProduttivitaAValore { } public static function save($data) { - $Ret = new Ret; - $EntityList = new EntityList; + $ret = new Ret; + $entityList = new EntityList; $codMdep = User::get_current_userCodMdep(); $arr_dataBdg = array_values(from($data["values"])->distinct(function ($x) { @@ -238,10 +257,10 @@ class ProduttivitaAValore { })->select(function ($x) { return $x["cod_jfas"]; })->toArray()); - foreach ($arr_codJfas as $codJfas) { - $JtbBdgHr = new EntityItem("jtb_bdg_hr"); - $JtbBdgHr->insert_or_update() + foreach ($arr_codJfas as $codJfas) { + $jtbBdgHr = new EntityItem("jtb_bdg_hr"); + $jtbBdgHr->insert_or_update() ->set("codMdep", $codMdep) ->setDate("dataBdg", $dataBdg) ->set("codJfas", $codJfas); @@ -249,39 +268,36 @@ class ProduttivitaAValore { $arr_itemValues = array_values(from($data["values"])->where(function ($x) use ($dataBdg, $codJfas) { return $x["data_bdg"] == $dataBdg && $x["cod_jfas"] == $codJfas; })->toArray()); - foreach ($arr_itemValues as $resValue) { + foreach ($arr_itemValues as $resValue) { if ($resValue["row"] == "oreFormazione") { $activityTypeId = "FORMAZIONE"; - } else { - $Ret->set_error("Tipo dato '{$resValue["row"]}' non ammesso"); + $ret->set_error("Tipo dato '{$resValue["row"]}' non ammesso"); break; } - $JtbBdgHrDet = new EntityItem("jtb_bdg_hr_det"); - $JtbBdgHrDet->insert_or_update() + $jtbBdgHrDet = new EntityItem("jtb_bdg_hr_det"); + $jtbBdgHrDet->insert_or_update() ->set("activityTypeId", $activityTypeId) ->set("flagTipologia", "A") ->set("ore", $resValue["value"], 0); - $JtbBdgHr->set("jtbBdgHrDet")->append($JtbBdgHrDet); + $jtbBdgHr->set("jtbBdgHrDet")->append($jtbBdgHrDet); } - $EntityList->push($JtbBdgHr); + $entityList->push($jtbBdgHr); } } - //echo$EntityList;exit; - - if ($Ret->is_OK()) { - if ($EntityList->count() > 0) { - $Ret = $EntityList->profileDB(self::get_defaultProfileDb())->send(); + if ($ret->is_OK()) { + if ($entityList->count() > 0) { + $ret = $entityList->profileDB(self::get_defaultProfileDb())->send(); } else { - $Ret->set_error("Non è stato registrato alcun aggiornamento"); + $ret->set_error("Non è stato registrato alcun aggiornamento"); } } - return $Ret; + return $ret; } private static function get_defaultProfileDb() { diff --git a/public_html/gest-lib/produttivita_a_valore/include/ajax.php b/public_html/gest-lib/produttivita_a_valore/include/ajax.php index 967a56017..27ab1a53b 100644 --- a/public_html/gest-lib/produttivita_a_valore/include/ajax.php +++ b/public_html/gest-lib/produttivita_a_valore/include/ajax.php @@ -13,11 +13,9 @@ if (isset($_GET["load_weekPvTable"])) { $html = Utility\Str::remove_multiple_spaces(@ob_get_clean()); $Ret = new Ret;//sleep(30); $Ret->set_string($html)->display(); - -} else if (isset($_POST["update"])) { - $data = Utility::sanitizeB64JSON_parse($_POST["update"]); +} else if (isset($_POST["save"])) { + $data = Utility::sanitizeB64JSON_parse($_POST["save"]); ProduttivitaAValore::save($data)->display(); - } else if (Controller::is_ajaxRequest()) { $Ret = new Ret; $Ret->set_errorCode(ErrorHandler::UNEXPECTED_AJAX_METHOD)->display(); diff --git a/public_html/gest-lib/produttivita_a_valore/include/box-main.php b/public_html/gest-lib/produttivita_a_valore/include/box-main.php index 4174735ec..cd2fe430f 100644 --- a/public_html/gest-lib/produttivita_a_valore/include/box-main.php +++ b/public_html/gest-lib/produttivita_a_valore/include/box-main.php @@ -1,347 +1,364 @@ is_OK()) { - $prodData = $Ret->get_data(); +$ret = ProduttivitaAValore::get_reparti($codMdep, $mondayDate); + +if ($ret->is_OK()) { + $prodData = $ret->get_data(); ?> - - - $day) { - $time = ProduttivitaAValore::get_weekDate($i, $mondayDate); - ?> - - - - + + + + $day) { + $time = ProduttivitaAValore::get_weekDate($i, $mondayDate); + ?> + + + + + - - - - - - - + + + - - - - - - - + + + + + - - - - - - - + + - - - - - + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + ?> - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + - + + + + + + + + + + + + + + + + + + + + + + + - + - - + } + + $sumOreMin = $sumRow; + ?> + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
TOTALE
SETTIMANALE
 
TOTALE
SETTIMANALE
- Valore vendite a budget () - - + +
+ Valore vendite a budget ()
- Valore vendite consuntivo () - - + + + +
+ Valore vendite consuntivo () - -
- Differenza valore () - - + + + + +
- Standard produttivo () -
+ Differenza valore () + + +
+ Standard produttivo () +
+ Rapporto Consuntivo / Standard () +
- Rapporto Consuntivo / Standard () -
- - () -
- - () -
- Differenza () -
Standard produttivo ()
- Rapporto Consuntivo / Standard () -
Rapporto Consuntivo / Standard (generale) + + () +
+ + () +
+ Differenza + () +
+ Standard produttivo () +
+ Rapporto Consuntivo / Standard () +
+ Rapporto Consuntivo / Standard (generale) +
Ore formazione + " placeholder="0" + type="number" class="form-control no-spin-buttons text-monospace input-xs" min="0" + step="0.1" + value=""/> +
 
Ore formazione Minime - " - type="number" class="form-control no-spin-buttons text-monospace input-xs" min="0" step="0.1" - placeholder="0" - value=""/> -
 Svolto
Investimento
Formazione
 
Differenza netta 
Andamento settimanale consuntivo
Differenza netta - andamento settimanale
Minime
Svolto
Investimento
Formazione
 
Differenza netta 
Andamento settimanale consuntivo
Differenza netta - andamento settimanale
+ showErrorAlert(); + $ret->showErrorAlert(); } \ No newline at end of file diff --git a/public_html/gest-lib/produttivita_a_valore/include/main.php b/public_html/gest-lib/produttivita_a_valore/include/main.php index 92eb58a9a..cbaf08db2 100644 --- a/public_html/gest-lib/produttivita_a_valore/include/main.php +++ b/public_html/gest-lib/produttivita_a_valore/include/main.php @@ -1,8 +1,10 @@
is_OK()) { - $arr_pv = $Ret->get_data(); + $arr_pv = array(); + $ret = ProduttivitaAValore::get_pv(); + + if ($ret->is_OK()) { + $arr_pv = $ret->get_data(); } ?>
diff --git a/public_html/gest-lib/produttivita_a_valore/js/main.js b/public_html/gest-lib/produttivita_a_valore/js/main.js index a038808ab..380d78cda 100644 --- a/public_html/gest-lib/produttivita_a_valore/js/main.js +++ b/public_html/gest-lib/produttivita_a_valore/js/main.js @@ -1,5 +1,4 @@ $(function () { - $("#bt_save").on("click", function () { _produttivitaAValore.save(); }); @@ -7,14 +6,15 @@ $(function () { _produttivitaAValore.init(); }); -var _produttivitaAValore = { +const _produttivitaAValore = { module: null, _week: null, _year: null, _toastRefresh: null, init: function () { - var self = this; + const self = this; + self.module = new Module(); self.module.onLoad(function () { const $weekPicker = $("#weekPicker"); @@ -27,19 +27,20 @@ var _produttivitaAValore = { } }); $weekPicker.weekPicker("change"); - }).load(); + $("#cod_mdep").on("change", function () { $("#weekPicker").weekPicker("change"); }) }, init_tableEvents: function () { - var self = this; - var $btSave = $("#bt_save"); + const self = this; + const $btSave = $("#bt_save"); + const $boxMain = $("#box-main"); + $btSave.disabled(); - var $boxMain = $("#box-main"); $boxMain.find("input[data-row][data-data_bdg][data-cod_jfas]").on("keyup change", function () { $(this).attr("edited", ""); $btSave.enabled(); @@ -51,54 +52,68 @@ var _produttivitaAValore = { }, view_toastRefresh: function () { - var self = this; + const self = this; + if (is_null(self._toastRefresh)) { self._toastRefresh = new Toast(); self._toastRefresh.noAutoclose().bottomRight().closeButton().classes("small") /*.icon("exclamation-circle")*/.warning("Alcuni dati visualizzati potrebbero differire da quelli effettivi.
Salvare le modifiche attuali per aggiornarli."/*, "Aggiornamento necessario"*/); } + return self; }, refresh_rowSum: function ($tr) { - var sum = 0; + let sum = 0; + $tr.find("input[data-row][data-data_bdg][data-cod_jfas]").each(function () { sum += $(this).getNumericValue(); }); + $tr.find(".sumRow").text(number_format(sum, 2, ".", "'")); + return this; }, refresh_table: function () { - var self = this; - var $boxMain = $("#box-main"); - var data = {week: self._week, year: self._year, codMdep: self.get_codMdep()}; - var ajax = new Ajax(); + const self = this; + const $boxMain = $("#box-main"); + const data = {week: self._week, year: self._year, codMdep: self.get_codMdep()}; + const ajax = new Ajax(); + ajax.get("load_weekPvTable").data(data).$toDisable($("#content")).waitToast("Caricamento dati della settimana").noticeAsModal().execute(function (ret) { - if (ret.returnId == 1) { + if (ret.returnId === 1) { $boxMain.html(ret.returnString); self.init_tableEvents(); } }); + if (!is_null(self._toastRefresh)) { self._toastRefresh.close(); self._toastRefresh = null; } + return self; }, + get_codMdep: function () { const $codMdep = $("#cod_mdep"); + if ($codMdep.length > 0) { return $codMdep.val(); } + return null; }, save: function () { - var self = this; - var $boxMain = $("#box-main"); - var data = []; + const self = this; + const $boxMain = $("#box-main"); + const data = []; + $boxMain.find("input[data-row][data-data_bdg][data-cod_jfas][edited]").each(function () { - var $this = $(this); + const $this = $(this); + + console.log($this); data.push({ row: $this.getDataAttr("row"), data_bdg: $this.getIntDataAttr("data_bdg"), @@ -108,17 +123,21 @@ var _produttivitaAValore = { }); if (data.length > 0) { - var ajax = new Ajax(); - ajax.post("update").data({values: data}).waitModal("Aggiornamento dati").noticeAsModal().execute(function (ret) { - if (ret.returnId == 1) { - self.refresh_table(); - //$boxMain.find("input[data-row][data-data_bdg][data-cod_jfas]").removeAttr("edited"); - // $("#bt_save").disabled(); - } - }); + const ajax = new Ajax(); + ajax + .post("save") + .data({values: data}) + .waitModal("Aggiornamento dati") + .noticeAsModal() + .execute(function (ret) { + if (ret.returnId === 1) { + self.refresh_table(); + } + }); } else { - var toast = new Toast(); + const toast = new Toast(); + toast.warning("Nessun dato da salvare"); } }