Ver Fonte

added btn "dodaj do analizy wg raportu"

Piotr Labudda há 8 anos atrás
pai
commit
5d99d3d971
2 ficheiros alterados com 293 adições e 14 exclusões
  1. 98 7
      tools/Bocian.php
  2. 195 7
      tools/Bocian.php.view.js

+ 98 - 7
tools/Bocian.php

@@ -157,9 +157,12 @@ public static $helpEmailTo = 'biuro@bialnet.com.pl'; // todo:email na który zos
 			'URL_FETCH_TEST_KRS' => $this->getLink('fetchTestKrsAjax'),
 			'URL_FETCH_TEST_CEIDG' => $this->getLink('fetchTestCeidgAjax'),
 			'URL_FETCH_PRACOWNICY' => $this->getLink('fetchPracownicyAjax'),
-			'URL_FETCH_PRACOWNICY_IDS_AJAX' => $this->getLink('fetchPracownicyIdsAjax'),
 			'URL_FETCH_KONTRAHENCI' => $this->getLink('fetchKontrahenciAjax'),
+			'URL_FETCH_PRACOWNICY_IDS_AJAX' => $this->getLink('fetchPracownicyIdsAjax'),
 			'URL_FETCH_KONTRAHENCI_IDS_AJAX' => $this->getLink('fetchKontrahenciIdsAjax'),
+			'URL_FETCH_LAST_REPORTS_AJAX' => $this->getLink('fetchLastReportsAjax'),
+			'URL_FETCH_PRACOWNICY_IDS_BY_REPORT_AJAX' => $this->getLink('fetchPracownicyIdsByReportAjax'),
+			'URL_FETCH_KONTRAHENCI_IDS_BY_REPORT_AJAX' => $this->getLink('fetchKontrahenciIdsByReportAjax'),
 			'URL_CREATE_PRACOWNICY_GROUP' => $this->getLink('createPracownicyGroupAjax'),
 			'URL_CREATE_KONTRAHENCI_GROUP' => $this->getLink('createKontrahenciGroupAjax'),
 			'URL_ADD_PRACOWNICY_TO_GROUP' => $this->getLink('addPracownicyToGroupAjax'),
@@ -1327,6 +1330,79 @@ public function showPowiazaniaEnergaRumKontrahenciPowiazania($items) {
 		];
 	}
 
+	function fetchLastReportsAjaxAction() { Response::sendTryCatchJson([ $this, 'fetchLastReportsAjax' ], $args = 'JSON_FROM_REQUEST_BODY'); }
+	function fetchLastReportsAjax() {
+		$refRaportToPracownicyConfig = ACL::getRefConfig(
+			$rootObjectNamespace = 'default_db/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA',
+			$fieldTypeName = 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY'
+		);
+		$refRaportToKontrahenciConfig = ACL::getRefConfig(
+			$rootObjectNamespace = 'default_db/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA',
+			$fieldTypeName = 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI:BI_audit_ENERGA_RUM_KONTRAHENCI'
+		);
+		$items = DB::getPDO()->fetchAll("
+			select r.ID as id
+				, r.L_APPOITMENT_INFO as adnotacje
+				, (select count(1) from `{$refRaportToPracownicyConfig->tableName}`  as prRef  where prRef.PRIMARY_KEY = r.ID  and prRef.A_STATUS not in ('DELETED')) as totalPracownicy
+				, (select count(1) from `{$refRaportToKontrahenciConfig->tableName}` as comRef where comRef.PRIMARY_KEY = r.ID and comRef.A_STATUS not in ('DELETED')) as totalKontrahenci
+			from `BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA` as r
+			order by r.ID DESC
+			limit 10
+		");
+		return [
+			'type' => 'success',
+			'msg' => 'ostatnie raporty',
+			'body' => [
+				'items' => $items,
+			],
+		];
+	}
+	function fetchPracownicyIdsByReportAjaxAction() { Response::sendTryCatchJson([ $this, 'fetchPracownicyIdsByReportAjax' ], $args = 'JSON_FROM_REQUEST_BODY'); }
+	function fetchPracownicyIdsByReportAjax($args) {
+		$id = V::get('id', 0, $args);
+		if ($id <= 0) throw new HttpException("Missing id", 400);
+		$refConf = ACL::getRefConfig(
+			$rootObjectNamespace = 'default_db/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA',
+			$fieldTypeName = 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY'
+		);
+		$items = DB::getPDO()->fetchAll("
+			select REMOTE_PRIMARY_KEY
+			from `{$refConf->tableName}`
+			where PRIMARY_KEY = :id
+				and A_STATUS not in ('DELETED')
+		", [ ':id' => $id ]);
+		return [
+			'type' => 'success',
+			'msg' => 'kontrahenci ids',
+			'body' => [
+				'ids' => array_map( V::makePick('REMOTE_PRIMARY_KEY'), $items ),
+			],
+		];
+	}
+	function fetchKontrahenciIdsByReportAjaxAction() { Response::sendTryCatchJson([ $this, 'fetchKontrahenciIdsByReportAjax' ], $args = 'JSON_FROM_REQUEST_BODY'); }
+	function fetchKontrahenciIdsByReportAjax($args) {
+		$id = V::get('id', 0, $args);
+		if ($id <= 0) throw new HttpException("Missing id", 400);
+		$refConf = ACL::getRefConfig(
+			$rootObjectNamespace = 'default_db/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA',
+			$fieldTypeName = 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI:BI_audit_ENERGA_RUM_KONTRAHENCI'
+		);
+		$items = DB::getPDO()->fetchAll("
+			select REMOTE_PRIMARY_KEY
+			from `{$refConf->tableName}`
+			where PRIMARY_KEY = :id
+				and A_STATUS not in ('DELETED')
+		", [ ':id' => $id ]);
+		return [
+			'type' => 'success',
+			'msg' => 'kontrahenci ids',
+			'body' => [
+				'ids' => array_map( V::makePick('REMOTE_PRIMARY_KEY'), $items ),
+			],
+		];
+	}
+
+
 	public function fetchKontrahenciIdsAjaxAction() {
 		Response::sendTryCatchJson(array($this, 'fetchKontrahenciIdsAjax'), $args = 'JSON_FROM_REQUEST_BODY');
 	}
@@ -2800,6 +2876,21 @@ public function showPowiazaniaEnergaRumKontrahenciPowiazania($items) {
 		$activeFormSteps = '';
 		$fieldLabels = [];
 		$currentDate = date("j.n.Y");
+
+		$btnGrafPowiazan = '';
+		switch ($type) {
+			case 'PRACOWNICY': $btnGrafPowiazan = '<button class="btn btn-primary smad-pracownicy-graph-button" onclick="graphShowHide(\'pracownicy\')" style="padding:1px 5px; margin-left:12px">GRAF POWIĄZAŃ</button>'; break;
+			case 'KONTRAHENCI': $btnGrafPowiazan = '<button class="btn btn-primary smad-kontrahenci-graph-button" onclick="graphShowHide(\'kontrahenci\')" style="padding:1px 5px; margin-left:12px">GRAF POWIĄZAŃ</button>'; break;
+		}
+
+		$formFilterHeadDesc = '';
+		switch ($type) {
+			case 'PRACOWNICY': $formFilterHeadDesc = 'Liczba pozycji na liście: <span id="smad-filter-desc-pracownicy">0</span>'; break;
+			case 'KONTRAHENCI': $formFilterHeadDesc = 'Liczba pozycji na liście: <span id="smad-filter-desc-kontrahenci">0</span>'; break;
+			case 'OPERACYJNA_BAZA_ZGLOSZEN': $formFilterHeadDesc = 'Liczba pozycji na liście: <span id="smad-filter-desc-kontrahenci">0</span>'; break;
+		}
+
+
 		switch($type) {
 				case 'KONTRAHENCI':
 
@@ -2822,7 +2913,6 @@ public function showPowiazaniaEnergaRumKontrahenciPowiazania($items) {
 					$formSmadSelectTarget = '<select class="form-control" id="smad-select-target-kontrahenci"><option value="y">tak</option><option value="n">nie</option></select>';
 
 					$formFilterHeadTitle = '<h2 class="title" id="smad-filter-head-title-kontrahenci">Wszyscy</h2>';
-					$formFilterHeadDesc = '<p>Liczba pozycji na liście: <span id="smad-filter-desc-kontrahenci">0</span></p>';
 					$countSelectedItem = '<div>Wybrano: <span id="count-selected-item-kontrahenci">0</span> <span><a title="wyczyść zapamietanych kontrahentów"  class="link-primary" onClick="clearListLocalStorageByType(\'kontrahenci\')"><small>(wyczyść)</small></a></span></div>';
 
 					$graphView = '<div class="smad-kontrahenci-graph-view" id="smad-kontrahenci-graph-view" style="display: none;"></div>';
@@ -2874,7 +2964,6 @@ public function showPowiazaniaEnergaRumKontrahenciPowiazania($items) {
 					$formSmadSelectTarget = '<select class="form-control" id="smad-select-target-kontrahenci"><option value="y">tak</option><option value="n">nie</option></select>';
 
 					$formFilterHeadTitle = '<h2 class="title" id="smad-filter-head-title-kontrahenci">Wszyscy</h2>';
-					$formFilterHeadDesc = '<p>Liczba pozycji na liście: <span id="smad-filter-desc-kontrahenci">0</span></p>';
 					$countSelectedItem = '<div>Wybrano: <span id="count-selected-item-kontrahenci">0</span> <span><a title="wyczyść zapamietanych kontrahentów"  class="link-primary" onClick="clearListLocalStorageByType(\'kontrahenci\')"><small>(wyczyść)</small></a></span></div>';
 
 					$graphView = '<div class="smad-kontrahenci-graph-view" style="display: none;"></div>';
@@ -2923,7 +3012,6 @@ public function showPowiazaniaEnergaRumKontrahenciPowiazania($items) {
 					$formSmadSelectTarget = '<select class="form-control" id="smad-select-target"><option value="y">tak</option><option value="n">nie</option></select>';
 
 					$formFilterHeadTitle = '<h2 class="title" id="smad-filter-head-title-pracownicy">Wszyscy</h2>';
-					$formFilterHeadDesc = '<p>Liczba pozycji na liście: <span id="smad-filter-desc-pracownicy">0</span></p>';
 					$countSelectedItem = '<div>Wybrano: <span id="count-selected-item-pracownicy">0</span> <span><a title="wyczyść zapamietanych pracowników" class="link-primary" onClick="clearListLocalStorageByType(\'pracownicy\')"><small>(wyczyść)</small></a></span></div>';
 
 					$graphView = '<div class="smad-pracownicy-graph-view" id="smad-pracownicy-graph-view" style="display: none;"></div>';
@@ -3049,18 +3137,18 @@ public function showPowiazaniaEnergaRumKontrahenciPowiazania($items) {
 			<div class="container-fluid">
 
 							<div class="padding-0 smad-employees-list-head">
-									<div class="col-md-6">
+									<div class="col-md-8">
 											<header>
 											'.$formFilterHeadTitle.'
 											</header>
 											<div class="desc">
-													'.$formFilterHeadDesc.'
+													<p style="text-align:left">'.$formFilterHeadDesc.'</p>
 											</div>
 											<div class="countSelectedItem">
 													'.$countSelectedItem.'
 											</div>
 									</div>
-									<div class="col-md-6">
+									<div class="col-md-4">
 											<div class="menu-items">
 													<div class="menu-item">
 															<ul class="padding-0">
@@ -3068,6 +3156,9 @@ public function showPowiazaniaEnergaRumKontrahenciPowiazania($items) {
 															</ul>
 													</div>
 											</div>
+											<div style="position:absolute; bottom:0; right:24px">
+												'.$btnGrafPowiazan.'
+											</div>
 									</div>
 							</div>
 			</div>

+ 195 - 7
tools/Bocian.php.view.js

@@ -1544,12 +1544,14 @@ function urlFetchKontrahenci(page) {
 					$('#paginationShowNextCount-KONTRAHENCI').text(paginationShowNextCount);
 					$('#smad-filter-desc-kontrahenci').text(data.body.pagination.total_items);
 					if (data.body.pagination.total_items > 0) {
-						var btnGraphView = $('<button class="btn btn-primary smad-kontrahenci-graph-button" onClick="graphShowHide(\'kontrahenci\')" style="padding:1px 5px; margin-left:12px">GRAF POWIĄZAŃ</button>')
-
-						var btnAddAll = $('<button class="btn btn-primary" style="padding:1px 5px; margin-left:12px">DODAJ WSZYSTKIE DO ANALIZY</button>')
+						var btnAddAll = $('<button class="btn btn-primary" style="padding:1px 5px; margin-left:12px">DODAJ WSZYSTKIE DO ANALIZY</button>');
 						btnAddAll.on('click', { type: 'kontrahenci', pagination: data.body.pagination }, addAllMatchesToReport);
+
+						var btnAddByReport = $('<button class="btn btn-primary" style="padding:1px 5px; margin-left:12px">DODAJ DO ANALIZY WG RAPORTU</button>');
+						btnAddByReport.on('click', { type: 'kontrahenci', pagination: data.body.pagination }, addToReportByPreviousReport);
+
 						$('#smad-filter-desc-kontrahenci').append(btnAddAll);
-						$('#smad-filter-desc-kontrahenci').append(btnGraphView);
+						$('#smad-filter-desc-kontrahenci').append(btnAddByReport);
 					}
 				}
 
@@ -1688,12 +1690,14 @@ function urlFetchPracownicy(page) {
 						$('#paginationShowNextCount-PRACOWNICY').text(paginationShowNextCount);
 						$('#smad-filter-desc-pracownicy').text(data.body.pagination.total_items);
 						if (data.body.pagination.total_items > 0) {
-							var btnGraphView = $('<button class="btn btn-primary smad-pracownicy-graph-button" onClick="graphShowHide(\'pracownicy\')" style="padding:1px 5px; margin-left:12px">GRAF POWIĄZAŃ</button>')
-
 							var btnAddAll = $('<button class="btn btn-primary" style="padding:1px 5px; margin-left:12px">DODAJ WSZYSTKIE DO ANALIZY</button>')
 							btnAddAll.on('click', { type: 'pracownicy', pagination: data.body.pagination }, addAllMatchesToReport);
+
+							var btnAddByReport = $('<button class="btn btn-primary" style="padding:1px 5px; margin-left:12px">DODAJ DO ANALIZY WG RAPORTU</button>');
+							btnAddByReport.on('click', { type: 'pracownicy', pagination: data.body.pagination }, addToReportByPreviousReport);
+
 							$('#smad-filter-desc-pracownicy').append(btnAddAll);
-							$('#smad-filter-desc-pracownicy').append(btnGraphView);
+							$('#smad-filter-desc-pracownicy').append(btnAddByReport);
 						}
 			}
 
@@ -2611,6 +2615,190 @@ function addAllMatchesToReport(event) {
 	}
 }
 
+function mock_error__fetchLastReports(id) {
+	return new Promise(function (resolve) {
+		throw "Wystąpił błąd, spróbuj ponownie później"
+	})
+}
+function mock__fetchLastReports(id) {
+	return new Promise(function (resolve) {
+		var fakeResponse = '{"type":"success","msg":"ostatnie raporty","body":{"items":[{"id":"103","adnotacje":"raport pani x","totalPracownicy":"1","totalKontrahenci":"2"},{"id":"102","adnotacje":"test","totalPracownicy":"1","totalKontrahenci":"1"},{"id":"101","adnotacje":"Zuranski test all 7","totalPracownicy":"1","totalKontrahenci":"9307"},{"id":"100","adnotacje":"kike all 4","totalPracownicy":"5","totalKontrahenci":"9305"},{"id":"99","adnotacje":"test pracownik z KRS bez celu 3","totalPracownicy":"1","totalKontrahenci":"9305"}]}}';
+		var json = JSON.parse(fakeResponse);
+		var items = json.body.items;
+		console.log('items', items)
+		setTimeout(function () {
+			console.log('resolve items', items)
+			resolve(items);
+		}, 500);
+	});
+}
+function fetchLastReports(id) {
+	return global.fetch(URL_FETCH_LAST_REPORTS_AJAX, {
+		credentials: 'same-origin',
+		method: 'POST',
+		headers: { 'Content-Type': 'application/json' },
+		body: JSON.stringify({ id: id })
+	})
+	.then(function __parseJSON(response) {
+		return response.json()
+	})
+	.then(function (json) {
+		if ('success' === json.type && json.body && json.body.items) {
+			if (!json.body.items.length) throw "Brak danych"
+			return json.body.items;
+		}
+		throw "Wystąpił błąd, spróbuj ponownie później.";
+	})
+}
+function fetchPracownicyIdsByReport(id) {
+	return global.fetch(URL_FETCH_PRACOWNICY_IDS_BY_REPORT_AJAX, {
+		credentials: 'same-origin',
+		method: 'POST',
+		headers: { 'Content-Type': 'application/json' },
+		body: JSON.stringify({ id: id })
+	})
+	.then(function __parseJSON(response) {
+		return response.json()
+	})
+	.then(function (json) {
+		if ('success' === json.type && json.body && json.body.ids) {
+			if (!json.body.ids.length) throw "Brak danych"
+			return json.body.ids;
+		}
+		throw "Wystąpił błąd, spróbuj ponownie później.";
+	})
+}
+function fetchKontrahenciIdsByReport(id) {
+	return global.fetch(URL_FETCH_KONTRAHENCI_IDS_BY_REPORT_AJAX, {
+		credentials: 'same-origin',
+		method: 'POST',
+		headers: { 'Content-Type': 'application/json' },
+		body: JSON.stringify({ id: id })
+	})
+	.then(function __parseJSON(response) {
+		return response.json()
+	})
+	.then(function (json) {
+		if ('success' === json.type && json.body && json.body.ids) {
+			if (!json.body.ids.length) throw "Brak danych"
+			return json.body.ids;
+		}
+		throw "Wystąpił błąd, spróbuj ponownie później.";
+	})
+}
+
+function addToReportByPreviousReport(event) {
+	var pageType = (event.data.type) ? event.data.type : '';
+	switch (pageType) {
+		case 'pracownicy': break; // OK
+		case 'kontrahenci': break; // OK
+		default: throw "Wrong type";
+	}
+
+	var thisButton = $(this)
+	thisButton.attr('disabled', true)
+	thisButton.text( thisButton.text() + '...' )
+	function this__enableButton() {
+		thisButton.attr('disabled', false)
+		var txt = thisButton.text()
+		thisButton.text( '...' === txt.substr(-3) ? txt.substr(0, txt.length - 3) : txt )
+	}
+
+	var lastReportOptions = new Promise(function (resolve) {
+		fetchLastReports() // TODO: TEST remote `mock__`
+		.then(function (items) {
+			var options = {};
+			items.forEach(function (item) {
+				var label = "Nr " + item.id + ": " + item.adnotacje + " ";
+				var total = 0;
+				switch (pageType) {
+					case 'pracownicy':  total = parseInt(item.totalPracownicy); break;
+					case 'kontrahenci': total = parseInt(item.totalKontrahenci); break;
+				}
+				label += ( total > 0 ? "(" + total + ")" : "brak");
+				options[item.id] = label;
+			});
+			resolve(options);
+		})
+		.catch(function (e) {
+			swal.showValidationError(''+e)
+			swal.hideLoading();
+			resolve();
+		})
+	});
+
+	swal({
+		title: "Dodaj " + ('pracownicy' === pageType ? "praconików" : "kontrahentów") + " do analizy",
+		showCancelButton: true,
+		cancelButtonText: "Anuluj",
+		showConfirmButton: true,
+		confirmButtonText: "Wybierz",
+		focusCancel: true,
+		width: 600,
+		input: 'select',
+		inputOptions: lastReportOptions,
+		inputClass: "form-control input-lg",
+		preConfirm: function (selected) {
+			var id = parseInt(selected);
+			swal.showLoading();
+			if ('pracownicy' === pageType) {
+				return new Promise(function (resolve) {
+					fetchPracownicyIdsByReport(id)
+					.then(function (ids) {
+						updateListIdBiAuditReaport('PRACOWNICY', ids.map(function (id) {
+							return parseInt(id)
+						}))
+						ids.forEach(function (id) {
+							jQuery('#body-pracownicy').find('input[name="prID[]"][value="'+id+'"]').each(function (idx, inputNode) {
+								inputNode.checked = true;
+							})
+						})
+						updateCountItemCheckedByType('pracownicy');
+						p5UI__notifyAjaxCallback({ type: 'success', msg: "Dodano "+ids.length+" pracowników" })
+						resolve();
+					})
+					.catch(function (e) {
+						swal.showValidationError(''+e)
+						swal.hideLoading();
+						resolve();
+					});
+				});
+			} else if ('kontrahenci' === pageType) {
+				return new Promise(function (resolve) {
+					fetchKontrahenciIdsByReport(id)
+					.then(function (ids) {
+						updateListIdBiAuditReaport('KONTRAHENCI', ids.map(function (id) {
+							return parseInt(id)
+						}))
+						ids.forEach(function (id) {
+							jQuery('#body-kontrahenci').find('input[name="kontrID[]"][value="'+id+'"]').each(function (idx, inputNode) {
+								inputNode.checked = true;
+							})
+						})
+						updateCountItemCheckedByType('kontrahenci');
+						p5UI__notifyAjaxCallback({ type: 'success', msg: "Dodano "+ids.length+" kontrahentów" })
+						resolve();
+					})
+					.catch(function (e) {
+						swal.showValidationError(''+e)
+						swal.hideLoading();
+						resolve();
+					});
+				});
+			} else return true;
+		},
+		// inputValidator: (value) => {
+		// 	return !value && 'Proszę wybrać raport'
+		// }
+		// html: '<p>Ostatnie raporty:</p>' + '<ul id="' + uniqHtmlId + '"></ul></p>',
+	}).then(function (selected) {
+		this__enableButton();
+	}).catch(function (e) {
+		this__enableButton();
+	})
+}
+
+
 $(document).ready(function(){
 	rootChangeForm();
 	updateTopCounters();