Bladeren bron

added select all by filter

Piotr Labudda 7 jaren geleden
bovenliggende
commit
133400662b
2 gewijzigde bestanden met toevoegingen van 216 en 9 verwijderingen
  1. 118 8
      tools/Bocian.php
  2. 98 1
      tools/Bocian.php.view.js

+ 118 - 8
tools/Bocian.php

@@ -24,7 +24,9 @@ class RouteTool_Bocian extends RouteToolBase {
 			'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_KONTRAHENCI_IDS_AJAX' => $this->getLink('fetchKontrahenciIdsAjax'),
 			'URL_CREATE_PRACOWNICY_GROUP' => $this->getLink('createPracownicyGroupAjax'),
 			'URL_CREATE_KONTRAHENCIS_GROUP' => $this->getLink('createKontrahenciGroupAjax'),
 			'URL_ADD_PRACOWNICY_TO_GROUP' => $this->getLink('addPracownicyToGroupAjax'),
@@ -453,6 +455,61 @@ public function showPowiazaniaEnergaRumKontrahenciPowiazania($items) {
 		];
 	}
 
+	public function fetchKontrahenciIdsAjaxAction() {
+		Response::sendTryCatchJson(array($this, 'fetchKontrahenciIdsAjax'), $args = 'JSON_FROM_REQUEST_BODY');
+	}
+	public function fetchKontrahenciIdsAjax($args) {
+		$idGroup = V::get('filter_idGroup', 0, $args, 'int');
+		if ($idGroup < 0) $idGroup = 0;
+		$backRefFilter = [];
+		if ($idGroup > 0) {
+			$backRefFilter['__backRef'] = [
+				'namespace' => 'default_db/BI_audit_ENERGA_KONTRAHENCI_group/BI_audit_ENERGA_KONTRAHENCI_group',
+				'primaryKey' => $idGroup,
+				'fieldName' => 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI:BI_audit_ENERGA_RUM_KONTRAHENCI',
+			];
+		}
+
+		$searchParams = []; // TODO: ???
+
+		$filtersParams = [];
+		$fieldFilterKeys = array_filter(array_keys($args), function ($key) {
+			return ('f_' === substr($key, 0, 2));
+		});
+		foreach ($fieldFilterKeys as $key) {
+			$filtersParams[ $key ] = $args[ $key ];
+		}
+
+		$acl = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_RUM_KONTRAHENCI');
+		$query = $acl->buildQuery(array_merge([
+			'cols' => [
+				'ID',
+			],
+			//'f_ID' => $id,
+			'limit' => 0,
+			// 'limitstart' => $limitstart, // offset
+			// 'order_by' => 'ID', // sortowanie po kolumnie
+			// 'order_dir' => 'DESC', // kierunek sortowania
+			// 'f_nip' = "=12345", // szukamy dokładnie tej wartości - mysql: where nip = "12345"
+			// 'f_nip' = "12345", // szukamy dokładnie tej wartości - mysql: where nip like "%12345%"
+			// 'f_nip' = "12345%", // szukamy dokładnie tej wartości - mysql: where nip like "12345%"
+			// 'f_ID' = "=12345", // szukamy dokładnie tej wartości - mysql: where ID = "12345"
+		], $searchParams, $filtersParams, $backRefFilter));
+		// $total = $query->getTotal();
+		$items = $query->getItems();
+
+		return [
+			'type' => 'success',
+			'msg' => 'kontrahenci ids',
+			'body' => [
+				'ids' => array_map( V::makePick('ID'), $items ),
+			],
+			'__args' => $args,
+			'__args_$idGroup' => $idGroup,
+			'__args_$filtersParams' => $filtersParams,
+			'__args_$backRefFilter' => $backRefFilter,
+		];
+	}
 	/**
 	 * KONTRAHENCI
 	 */
@@ -551,6 +608,7 @@ public function showPowiazaniaEnergaRumKontrahenciPowiazania($items) {
 		$pagination['size'] = ceil($total/$limit); // pages size
 		$pagination['current'] = $page;
 		$pagination['limit'] = $limit;
+		if ($idGroup > 0) $pagination['filter_idGroup'] = $idGroup;
 
 		return [
 			'type' => 'success',
@@ -711,6 +769,61 @@ public function showPowiazaniaEnergaRumKontrahenciPowiazania($items) {
 	}
 
 
+	public function fetchPracownicyIdsAjaxAction() {
+		Response::sendTryCatchJson(array($this, 'fetchPracownicyIdsAjax'), $args = 'JSON_FROM_REQUEST_BODY');
+	}
+ 	public function fetchPracownicyIdsAjax($args) {
+		$idGroup = V::get('filter_idGroup', 0, $args, 'int');
+		if ($idGroup < 0) $idGroup = 0;
+		$backRefFilter = [];
+		if ($idGroup > 0) {
+			$backRefFilter['__backRef'] = [
+				'namespace' => 'default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group',
+				'primaryKey' => $idGroup,
+				'fieldName' => 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY',
+			];
+		}
+
+		$searchParams = []; // TODO: ???
+
+		$filtersParams = [];
+		$fieldFilterKeys = array_filter(array_keys($args), function ($key) {
+			return ('f_' === substr($key, 0, 2));
+		});
+		foreach ($fieldFilterKeys as $key) {
+			$filtersParams[ $key ] = $args[ $key ];
+		}
+
+		$acl = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY');
+		$query = $acl->buildQuery(array_merge([
+			'cols' => [
+				'ID',
+			],
+			//'f_ID' => $id,
+			'limit' => 0,
+			// 'limitstart' => $limitstart, // offset
+			// 'order_by' => 'ID', // sortowanie po kolumnie
+			// 'order_dir' => 'DESC', // kierunek sortowania
+			// 'f_nip' = "=12345", // szukamy dokładnie tej wartości - mysql: where nip = "12345"
+			// 'f_nip' = "12345", // szukamy dokładnie tej wartości - mysql: where nip like "%12345%"
+			// 'f_nip' = "12345%", // szukamy dokładnie tej wartości - mysql: where nip like "12345%"
+			// 'f_ID' = "=12345", // szukamy dokładnie tej wartości - mysql: where ID = "12345"
+		], $searchParams, $filtersParams, $backRefFilter));
+		// $total = $query->getTotal();
+		$items = $query->getItems();
+
+		return [
+			'type' => 'success',
+			'msg' => 'pracownicy ids',
+			'body' => [
+				'ids' => array_map( V::makePick('ID'), $items ),
+			],
+			'__args' => $args,
+			'__args_$idGroup' => $idGroup,
+			'__args_$filtersParams' => $filtersParams,
+			'__args_$backRefFilter' => $backRefFilter,
+		];
+	}
 	/*
 	 * PRACOWNICY
 	 */
@@ -719,7 +832,7 @@ public function showPowiazaniaEnergaRumKontrahenciPowiazania($items) {
 	}
 	public function fetchPracownicyAjax($args) {
 
-		$idGroup = V::get('filterIdGroup', 0, $_REQUEST, 'int'); // TODO: dla filtrów "Wysokiego ryzyka" - przekazywany ID rekodu
+		$idGroup = V::get('filterIdGroup', 0, $_REQUEST, 'int'); // dla filtrów "Wysokiego ryzyka" - przekazywany ID rekodu
 		if ($idGroup < 0) $idGroup = 0;
 
 		$limit = 20;
@@ -755,20 +868,15 @@ public function showPowiazaniaEnergaRumKontrahenciPowiazania($items) {
 		$backRefFilter = [];
 		if ($idGroup > 0) {
 			$backRefFilter['__backRef'] = [
-				'namespace' => 'default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group', // TODO: nowy rejetr na grupy / filty pracowników
+				'namespace' => 'default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group',
 				'primaryKey' => $idGroup,
 				'fieldName' => 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY',
 			];
-			// TODO: Storage dodać obiekt xsd default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group:
-			// - ID
-			// - ID_USER - id usera który stworzył grupę (tylko dla niego będzie widoczna)
-			// - NAZWA - nazwa grupy
-			// - 'default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY' minOccurs="0" maxOccurs="unbounded"
 		}
 
 		$acl = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY');
 		$query = $acl->buildQuery(array_merge([
-			'cols' => [ // TODO:? propertyName = []
+			'cols' => [
 				'ID',
 				'imiona',
 				'nazwisko',
@@ -801,6 +909,8 @@ public function showPowiazaniaEnergaRumKontrahenciPowiazania($items) {
 		$pagination['size'] = ceil($total/$limit); // pages size
 		$pagination['current'] = $page;
 		$pagination['limit'] = $limit;
+		// $idGroup = V::get('filterIdGroup', 0, $_REQUEST, 'int'); // TODO: dla filtrów "Wysokiego ryzyka" - przekazywany ID rekodu
+		if ($idGroup > 0) $pagination['filter_idGroup'] = $idGroup;
 
 		// { // tworzenie własnego zapytanie mysql
 		// 	$rootTableName = $acl->getRootTableName();

+ 98 - 1
tools/Bocian.php.view.js

@@ -759,7 +759,55 @@ 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 btnAddAll = $('<button class="btn btn-primary" style="padding:1px 5px; margin-left:12px">DODAJ WSZYSTKIE DO ANALIZY</button>')
+						btnAddAll.on('click', { pagination: data.body.pagination }, function (event) {
+							// event.data.pagination: { [ filter_idGroup: ... ] }
+							// fetch ids from request, set to LocatStorage, update selected on gui
+							var postData = {}
+							if ('filter_idGroup' in event.data.pagination && event.data.pagination['filter_idGroup']) postData['filter_idGroup'] = event.data.pagination['filter_idGroup']
+							Object.keys(event.data.pagination).filter(function (key) {
+								return ('f_' === key.substr(0, 2))
+							}).forEach(function (filterKey) {
+								var value = event.data.pagination[filterKey]
+								postData[filterKey] = value
+							})
+							var thisButton = $(this)
+							thisButton.attr('disabled', true)
+							thisButton.text( thisButton.text() + '...' )
+							p5UI__notifyAjaxCallback({ type: 'info', msg: "Pobieranie kontrahentów..." })
+							global.fetch(URL_FETCH_KONTRAHENCI_IDS_AJAX, {
+								credentials: 'same-origin',
+								method: 'POST',
+								headers: {
+									'Content-Type': 'application/json'
+								},
+								body: JSON.stringify(postData)
+							})
+							.then(function __parseJSON(response) {
+								return response.json()
+							})
+							.then(function (json) {
+								if ('success' === json.type && json.body && json.body.ids) {
+									updateListIdBiAuditReaport('KONTRAHENCI', json.body.ids.map(function (id) {
+										return parseInt(id)
+									}))
+									jQuery('#body-kontrahenci').find('input[name="kontrID[]"]').attr('checked', true)
+									thisButton.attr('disabled', false)
+									var txt = thisButton.text()
+									thisButton.text( '...' === txt.substr(-3) ? txt.substr(0, txt.length - 3) : txt )
+									p5UI__notifyAjaxCallback({ type: 'success', msg: "Dodano "+json.body.ids.length+" kontrahentów" })
+								}
+							})
+							.catch(function (e) {
+								p5UI__notifyAjaxCallback({ type: 'error', msg: '' + e })
+								thisButton.attr('disabled', false)
+								var txt = thisButton.text()
+								thisButton.text( '...' === txt.substr(-3) ? txt.substr(0, txt.length - 3) : txt )
+							})
+						})
+						$('#smad-filter-desc-kontrahenci').append(btnAddAll);
+					}
 				}
 
 				var groupSelectData = getNameGroupById(getItemLocalStorage('Bocian.biAuditForm.kontrahenci.groups'), filterIdGroup);
@@ -845,6 +893,55 @@ 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 btnAddAll = $('<button class="btn btn-primary" style="padding:1px 5px; margin-left:12px">DODAJ WSZYSTKIE DO ANALIZY</button>')
+							btnAddAll.on('click', { pagination: data.body.pagination }, function (event) {
+								// event.data.pagination: { [ filter_idGroup: ... ] }
+								// fetch ids from request, set to LocatStorage, redirect to '#KONTRAHENCI'
+								var postData = {}
+								if ('filter_idGroup' in event.data.pagination && event.data.pagination['filter_idGroup']) postData['filter_idGroup'] = event.data.pagination['filter_idGroup']
+								Object.keys(event.data.pagination).filter(function (key) {
+									return ('f_' === key.substr(0, 2))
+								}).forEach(function (filterKey) {
+									var value = event.data.pagination[filterKey]
+									postData[filterKey] = value
+								})
+								var thisButton = $(this)
+								thisButton.attr('disabled', true)
+								thisButton.text( thisButton.text() + '...' )
+								p5UI__notifyAjaxCallback({ type: 'info', msg: "Pobieranie pracowników..." })
+								global.fetch(URL_FETCH_PRACOWNICY_IDS_AJAX, {
+									credentials: 'same-origin',
+									method: 'POST',
+									headers: {
+										'Content-Type': 'application/json'
+									},
+									body: JSON.stringify(postData)
+								})
+								.then(function __parseJSON(response) {
+									return response.json()
+								})
+								.then(function (json) {
+									if ('success' === json.type && json.body && json.body.ids) {
+										updateListIdBiAuditReaport('PRACOWNICY', json.body.ids.map(function (id) {
+											return parseInt(id)
+										}))
+										thisButton.attr('disabled', false)
+										var txt = thisButton.text()
+										thisButton.text( '...' === txt.substr(-3) ? txt.substr(0, txt.length - 3) : txt )
+										p5UI__notifyAjaxCallback({ type: 'success', msg: "Dodano "+json.body.ids.length+" pracowników" })
+										window.location.hash = 'KONTRAHENCI'
+									}
+								})
+								.catch(function (e) {
+									p5UI__notifyAjaxCallback({ type: 'error', msg: '' + e })
+									thisButton.attr('disabled', false)
+									var txt = thisButton.text()
+									thisButton.text( '...' === txt.substr(-3) ? txt.substr(0, txt.length - 3) : txt )
+								})
+							})
+							$('#smad-filter-desc-pracownicy').append(btnAddAll);
+						}
 			}