|
@@ -5,7 +5,7 @@ Lib::loadClass('UI');
|
|
|
Lib::loadClass('Response');
|
|
|
Lib::loadClass('Request');
|
|
|
|
|
|
-// index.php?_route=UrlAction_BiAuditRaport - uruchamia defaultAction
|
|
|
+// index.php?_route=UrlAction_Bocian - uruchamia defaultAction
|
|
|
class RouteTool_Bocian extends RouteToolBase {
|
|
|
|
|
|
public static $helpEmailTo = 'biuro@bialnet.com.pl'; // email na który zostanie wysłane zapytanie z formularza POMOCY
|
|
@@ -1795,9 +1795,121 @@ public function showPowiazaniaEnergaRumKontrahenciPowiazania($items) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ function fetchProgressAjaxAction() {
|
|
|
+ Response::sendTryCatchJson(array($this, 'fetchProgressAjax'), $args = 'JSON_FROM_REQUEST_BODY');
|
|
|
+ }
|
|
|
+ function fetchProgressAjax($args) {
|
|
|
+ $DBG_FAKE_ANIM = false;
|
|
|
+ if (empty($args['ids'])) return [ 'msg' => "empty ids", 'type' => "success" ];
|
|
|
+ $ids = $args['ids'];
|
|
|
+
|
|
|
+ // private static function getDirectory($table, $id) {
|
|
|
+ $firstId = reset($ids);
|
|
|
+ {
|
|
|
+ Lib::loadClass('FoldersConfig');
|
|
|
+ $folderConf = FoldersConfig::getAll('BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_COLUMN');
|
|
|
+ if (!isset($folderConf['mount_point'])) throw new HttpException("Błąd danych konfiguracyjnych<br>\n{$errMsg}", 404);
|
|
|
+ $rootPath = $folderConf['mount_point'];
|
|
|
+ }
|
|
|
|
|
|
+ $statuses = array_map(function ($id) {
|
|
|
+ return DB::getPDO()->fetchValue(" select FILE_STATUS from BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA where ID = :id ", [ ':id' => $id ]);
|
|
|
+ }, $ids);
|
|
|
+ $statusesInfo = array_map(function ($id) {
|
|
|
+ return DB::getPDO()->fetchValue(" select FILE_STATUS_info from BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA where ID = :id ", [ ':id' => $id ]);
|
|
|
+ }, $ids);
|
|
|
+ $progress = array_map(function ($id, $idx) use ($rootPath, $statuses, $DBG_FAKE_ANIM) {
|
|
|
+ DBG::log("Loop id({$id}) is-eq-82(".(82 == $id).") is-eq-'82'(".("82"==$id).")");
|
|
|
+ DBG::log("Loop id({$id}) is-eq-80(".(80 == $id).") is-eq-'80'(".("80"==$id).")");
|
|
|
+ $status = $statuses[$idx];
|
|
|
+ if ($DBG_FAKE_ANIM && 82 == $id) $status = 'IN_PROGRESS'; // TODO: DBG
|
|
|
+ if ($DBG_FAKE_ANIM && 80 == $id) $status = 'IN_PROGRESS'; // TODO: DBG
|
|
|
+ if ($DBG_FAKE_ANIM && 77 == $id) $status = 'IN_PROGRESS'; // TODO: DBG
|
|
|
+ DBG::log("Loop id({$id}) status({$status})...");
|
|
|
+
|
|
|
+ if ('GENERATED' === $status) return 1;
|
|
|
+ if ('IN_PROGRESS' !== $status) return 0;
|
|
|
+
|
|
|
+ if (!file_exists("{$rootPath}/.tasks/generatePowiazania-{$id}.progress")) return 0;
|
|
|
+ DBG::log("Loop id({$id}) status({$status}) progress file exists");
|
|
|
+ try {
|
|
|
+ $cnt = file_get_contents("{$rootPath}/.tasks/generatePowiazania-{$id}.progress");
|
|
|
+ $json = @json_decode($cnt, $assoc = true);
|
|
|
+ if (null === $json && 0 !== json_last_error()) {
|
|
|
+ throw new Exception("Parse json error for restrictions: " . json_last_error());
|
|
|
+ }
|
|
|
+ // $json['summary']['step']: 'initialize', 'relations', 'reports'
|
|
|
+ // $json['summary']['step'] = 'initialize' - recache - skip
|
|
|
+ // $json['summary']['step'] = 'relations' - szuka powiązań (@see AVG(details.progress / summary.count))
|
|
|
+ // $json['summary']['step'] = 'reports' - generuje pliki (@see summary.created)
|
|
|
+ if ($DBG_FAKE_ANIM && 82 == $id) { // TODO: DBG
|
|
|
+ $json = [
|
|
|
+ 'summary' => [
|
|
|
+ 'count' => 4,
|
|
|
+ 'step' => 'relations',
|
|
|
+ ],
|
|
|
+ 'details' => [
|
|
|
+ '9' => [ 'progress' => 1, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
|
|
|
+ '19' => [ 'progress' => 1, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
|
|
|
+ '22' => [ 'progress' => 0, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
|
|
|
+ '25' => [ 'progress' => 0, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
|
|
|
+ ] ];
|
|
|
+ }
|
|
|
+ if ($DBG_FAKE_ANIM && 80 == $id) { // TODO: DBG
|
|
|
+ $json = [
|
|
|
+ 'summary' => [
|
|
|
+ 'count' => 4,
|
|
|
+ 'created' => 2,
|
|
|
+ 'step' => 'reports',
|
|
|
+ ],
|
|
|
+ 'details' => [
|
|
|
+ '9' => [ 'progress' => 1, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
|
|
|
+ '19' => [ 'progress' => 1, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
|
|
|
+ '22' => [ 'progress' => 1, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
|
|
|
+ '25' => [ 'progress' => 1, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
|
|
|
+ ] ];
|
|
|
+ }
|
|
|
+ if ($DBG_FAKE_ANIM && 77 == $id) { // TODO: DBG
|
|
|
+ $json = [
|
|
|
+ 'summary' => [
|
|
|
+ 'count' => 4,
|
|
|
+ 'created' => 2,
|
|
|
+ 'step' => 'relations',
|
|
|
+ ],
|
|
|
+ 'details' => [
|
|
|
+ '9' => [ 'progress' => 1, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
|
|
|
+ '19' => [ 'progress' => 1, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
|
|
|
+ '22' => [ 'progress' => 0.25, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
|
|
|
+ '25' => [ 'progress' => 0, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
|
|
|
+ ] ];
|
|
|
+ }
|
|
|
+ DBG::log($json, 'array', "Loop id({$id}) status({$status}) progress json");
|
|
|
+
|
|
|
+ if (empty($json['summary'])) return 0;
|
|
|
+ if (empty($json['summary']['count'])) return 0;
|
|
|
+ if (empty($json['summary']['step'])) return 0;
|
|
|
+ if (empty($json['details'])) return 0;
|
|
|
+ if ('relations' === $json['summary']['step']
|
|
|
+ || 'reports' === $json['summary']['step']
|
|
|
+ ) {
|
|
|
+ $listDetailsProgress = array_map(function ($detail) {
|
|
|
+ return floatval($detail['progress']);
|
|
|
+ }, $json['details']);
|
|
|
+ return (array_sum($listDetailsProgress) + V::get('created', 0, $json['summary'], 'int')) / ($json['summary']['count'] * 2);
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
-
|
|
|
+ return 0;
|
|
|
+ } catch (Exception $e) {
|
|
|
+ DBG::log($e);
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ }, $ids, array_keys($ids));
|
|
|
+ return [ 'msg' => "DBG ids set", 'type' => "success", 'body' => [
|
|
|
+ 'ids' => $ids,
|
|
|
+ 'progress' => $progress,
|
|
|
+ 'statuses' => $statuses,
|
|
|
+ 'statusesInfo' => $statusesInfo,
|
|
|
+ ] ];
|
|
|
+ }
|
|
|
|
|
|
}
|