浏览代码

added add all kontrahenci to group

Piotr Labudda 7 年之前
父节点
当前提交
0442a8b58e
共有 2 个文件被更改,包括 180 次插入35 次删除
  1. 70 2
      tools/Bocian.php
  2. 110 33
      tools/Bocian.php.view.js

+ 70 - 2
tools/Bocian.php

@@ -797,11 +797,21 @@ public function showPowiazaniaEnergaRumKontrahenciPowiazania($items) {
 	}
 	public function addKontrahenciToGroupAjax($args) {
 		$idGroup = V::get('idGroup', '', $args);
+		$type = V::get('type', 'ids', $args);
 		$kontrahenciIds = V::get('kontrahenciIds', '', $args);
+		$filter = V::get('filter', '', $args);
 
 		// validate
 		if (!$idGroup) throw new Exception("Nie wybrano grupa");
-		if (!$kontrahenciIds || count($kontrahenciIds) == 0 ) throw new Exception("Proszę wybrać kontrahentów");
+		switch ($type) {
+			case 'ids': {
+				if (!$kontrahenciIds || count($kontrahenciIds) == 0) throw new Exception("Proszę wybrać kontrahentów");
+			} break;
+			case 'filter': {
+				if (!isset($args['filter'])) throw new Exception("Proszę wybrać kontrahentów");
+			} break;
+			default: throw new Exception("Missing type");
+		}
 
 		$group = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_KONTRAHENCI_group/BI_audit_ENERGA_KONTRAHENCI_group')->buildQuery([
 			'cols' => [ // TODO:? propertyName = []
@@ -814,6 +824,63 @@ public function showPowiazaniaEnergaRumKontrahenciPowiazania($items) {
 		if (!$group) throw new Exception("Grupa nie istnieje");
 		if (User::getID() != $group['ID_USER']) throw new Exception("Brak uprawnień do grupy");
 
+		if ('filter' === $type) {
+			$args__idGroup = V::get('filterIdGroup', 0, $args['filter'], 'int'); // dla filtrów "Wysokiego ryzyka" - przekazywany ID rekodu
+			if ($args__idGroup < 0) $args__idGroup = 0;
+			$search = V::get('search', '', $args['filter']);
+			$searchParams = [];
+			if (!empty($search)) {
+				$ogcSearch = "*{$search}*"; // wildCard="*" -> mysql '%'
+				$searchParams['ogc:Filter'] = '
+					<ogc:Filter>
+				    <ogc:Or>
+				      <ogc:PropertyIsLike wildCard="" singleChar="%23" escapeChar="!">
+				        <ogc:PropertyName>NIP</ogc:PropertyName>
+				        <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
+				      </ogc:PropertyIsLike>
+				      <ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">
+				        <ogc:PropertyName>Nazwa_grupy_kapitalowej</ogc:PropertyName>
+								<ogc:Literal>' . $ogcSearch . '</ogc:Literal>
+				      </ogc:PropertyIsLike>
+				      <ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">
+				        <ogc:PropertyName>Pelna_nazwa_kontrahenta</ogc:PropertyName>
+								<ogc:Literal>' . $ogcSearch . '</ogc:Literal>
+				      </ogc:PropertyIsLike>
+				    </ogc:Or>
+				  </ogc:Filter>
+				';
+			}
+
+			$backRefFilter = [];
+			if ($args__idGroup > 0) {
+				$backRefFilter['__backRef'] = [
+					'namespace' => 'default_db/BI_audit_ENERGA_KONTRAHENCI_group/BI_audit_ENERGA_KONTRAHENCI_group',
+					'primaryKey' => $args__idGroup,
+					'fieldName' => 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI:BI_audit_ENERGA_RUM_KONTRAHENCI',
+				];
+			}
+
+			$filtersParams = [];
+			$fieldFilterKeys = array_filter(array_keys($args['filter']), function ($key) {
+				return ('f_' === substr($key, 0, 2));
+			});
+			foreach ($fieldFilterKeys as $key) {
+				$filtersParams[ $key ] = '%' . $args['filter'][ $key ] . '%';
+			}
+
+			$acl = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_RUM_KONTRAHENCI');
+			$query = $acl->buildQuery(array_merge([
+				'cols' => ['ID'],
+			], $searchParams, $filtersParams, $backRefFilter, [
+				'limit' => 0
+			]));
+			$items = $query->getItems();
+
+			$kontrahenciIds = array_map(function ($row) {
+				return $row['ID'];
+			}, $items);
+		}
+
 		// $refGrupyToPracownicy = ACL::getRefTable('obiekt główny', 'nazwa pola - powiązane rekordy');
 		$refGrupyToKontrahenci = ACL::getRefTable('default_db/BI_audit_ENERGA_KONTRAHENCI_group/BI_audit_ENERGA_KONTRAHENCI_group',
 			'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI:BI_audit_ENERGA_RUM_KONTRAHENCI');
@@ -1358,7 +1425,8 @@ public function showPowiazaniaEnergaRumKontrahenciPowiazania($items) {
 					<li><a  title="IMPORT KONTRAHENCI" onClick="showViewUploadFile(event, \'Import kontrahentów\', \'kontrahenci\', \'no\', \''.$csvExampleKontrahenci.'\' )" class="btn btn-info">IMPORT KONTRAHENCI</a></li>
 					<!--<li><a href="#" title="DODAJ KONTRAHENCI" class="btn btn-info">+ DODAJ KONTRAHENCI</a></li>-->'; //todo: dodać obsługe doddawania kontrahentow
 
-					$buttonMoveToGroup = '<a title="DODAJ DO GRUPY" onClick="addKontrahenciToGroup(event)" class="btn btn-info">DODAJ DO GRUPY</a>';
+					$buttonMoveToGroup = '<a title="DODAJ WYBRANE DO GRUPY" onClick="addKontrahenciToGroup(event)" class="btn btn-info">DODAJ WYBRANE DO GRUPY</a>';
+					$buttonMoveToGroup .= '<a title="DODAJ WSZYSTKIE DO GRUPY" onClick="addKontrahenciAllToGroup(event)" class="btn btn-info" style="margin-left:12px">DODAJ WSZYSTKIE DO GRUPY</a>';
 
 					$showButtonNextStep = '<button type="button" class="btn btn-primary" onClick="generateBiAuditRaport(event)" id="button-generate-reaport">SZUKAJ POWIĄZAŃ</button>';
 

+ 110 - 33
tools/Bocian.php.view.js

@@ -316,11 +316,10 @@ function addPracownikToGroup(event) {
 	event.preventDefault();
 
 	var pracownicyIdsArray = getItemLocalStorage('Bocian.biAuditForm.pracownicyIds');
-	console.log(pracownicyIdsArray);
-	if (pracownicyIdsArray === null) {
-		showTextListIdPracownikow = 'ID pracowników: nie wybrano';
+	if (pracownicyIdsArray === null || !pracownicyIdsArray || !pracownicyIdsArray.length) {
+		showTextListIdPracownikow = 'nie wybrano pracowników';
 	} else {
-		showTextListIdPracownikow = 'ID pracowników: ' + pracownicyIdsArray;
+		showTextListIdPracownikow = '' + pracownicyIdsArray.length + ' pracowników';
 	}
 
 	var arrayGroupOptions = [];
@@ -396,13 +395,7 @@ function addPracownikToGroup(event) {
 function addPracownikAllToGroup(event) {
 	event.preventDefault();
 
-	var pracownicyIdsArray = getItemLocalStorage('Bocian.biAuditForm.pracownicyIds');
-	console.log(pracownicyIdsArray);
-	if (pracownicyIdsArray === null) {
-		showTextListIdPracownikow = 'ID pracowników: nie wybrano';
-	} else {
-		showTextListIdPracownikow = 'ID pracowników: ' + pracownicyIdsArray;
-	}
+	var showTextListIdPracownikow = 'wszystkich pracowników pasujących do kryteriów wyszukiwania';
 
 	var arrayGroupOptions = [];
 	var listGroupStorage = getItemLocalStorage('Bocian.biAuditForm.pracownicy.groups');
@@ -424,11 +417,6 @@ function addPracownikAllToGroup(event) {
 	  showLoaderOnConfirm: true,
 	  preConfirm: function (idGroup) {
 	    return new Promise(function (resolve, reject) {
-				// if ( !pracownicyIdsArray || pracownicyIdsArray === null || pracownicyIdsArray === 'undefined' ) {
-				// 		reject('Wybierz pracowników');
-				// } else if ( pracownicyIdsArray.length === 0 ) {
-				// 	reject('Wybierz pracowników');
-				// }
 				if (!idGroup) {
 					reject('Proszę wybrać nazwę grupy');
 					return;
@@ -500,22 +488,20 @@ function addKontrahenciToGroup(event) {
 	event.preventDefault();
 
 	var kontrahenciIdsArray = getItemLocalStorage('Bocian.biAuditForm.kontrahenciIds');
-
-	if (kontrahenciIdsArray === null) {
-		showTextListIdKontrahentow = 'ID kontrahentów: nie wybrano';
+	if (kontrahenciIdsArray === null || !kontrahenciIdsArray || !kontrahenciIdsArray.length) {
+		showTextListIdKontrahentow = 'nie wybrano kontrahentów';
 	} else {
-		showTextListIdKontrahentow = 'ID kontrahentów: ' + kontrahenciIdsArray;
+		showTextListIdKontrahentow = '' + kontrahenciIdsArray.length + ' kontrahentów';
 	}
 
-
-		var arrayGroupOptions = [];
-		var listGroupStorage = getItemLocalStorage('Bocian.biAuditForm.kontrahenci.groups');
-	  // utworzenie tablicy Optionsów grupy
-		listGroupStorage.map(function(item) {
-			if (item.ID !== undefined) {
-		   	arrayGroupOptions[item.ID] = item.NAZWA;
-			}
-		});
+	var arrayGroupOptions = [];
+	var listGroupStorage = getItemLocalStorage('Bocian.biAuditForm.kontrahenci.groups');
+  // utworzenie tablicy Optionsów grupy
+	listGroupStorage.map(function(item) {
+		if (item.ID !== undefined) {
+	   	arrayGroupOptions[item.ID] = item.NAZWA;
+		}
+	});
 
 	swal({
 	  title: 'Dodaj do grupy',
@@ -529,11 +515,13 @@ function addKontrahenciToGroup(event) {
 	  preConfirm: function (idGroup) {
 	    return new Promise(function (resolve, reject) {
 
-				if (!idGroup) reject('Proszę wybrać nazwę grupy');
-				if ( !kontrahenciIdsArray || kontrahenciIdsArray === null || kontrahenciIdsArray === 'undefined' ) {
-						reject('Wybierz kontrahentów');
-				} else if ( kontrahenciIdsArray.length === 0 ) {
+				if (!idGroup) {
+					reject('Proszę wybrać nazwę grupy');
+					return;
+				}
+				if (!kontrahenciIdsArray || !kontrahenciIdsArray.length) {
 					reject('Wybierz kontrahentów');
+					return;
 				}
 
 				window.fetch(URL_ADD_KONTRAHENCI_TO_GROUP, {
@@ -575,6 +563,94 @@ function addKontrahenciToGroup(event) {
 		//TODO: PIOTRKU CZY TU POWINIENEM COŚ JESZCZE OBSŁUŻYĆ
 	});
 }
+function addKontrahenciAllToGroup(event) {
+	event.preventDefault();
+
+	var kontrahenciIdsArray = getItemLocalStorage('Bocian.biAuditForm.kontrahenciIds');
+
+	var showTextListIdKontrahentow = 'wszystkich kontrahentów pasujących do kryteriów wyszukiwania';
+
+	var arrayGroupOptions = [];
+	var listGroupStorage = getItemLocalStorage('Bocian.biAuditForm.kontrahenci.groups');
+  // utworzenie tablicy Optionsów grupy
+	listGroupStorage.map(function(item) {
+		if (item.ID !== undefined) {
+			arrayGroupOptions[item.ID] = item.NAZWA;
+		}
+	});
+
+	swal({
+	  title: 'Dodaj do grupy',
+		input: 'select',
+		text: showTextListIdKontrahentow,
+	  inputOptions: arrayGroupOptions,
+	  inputPlaceholder: 'Wybierz grupę',
+	  showCancelButton: true,
+	  confirmButtonText: 'Zapisz',
+	  showLoaderOnConfirm: true,
+	  preConfirm: function (idGroup) {
+	    return new Promise(function (resolve, reject) {
+				if (!idGroup) {
+					reject('Proszę wybrać nazwę grupy');
+					return;
+				}
+
+				var filterFields = {}
+				var frm = document.getElementById('filtersFieldRemoveBtn-KONTRAHENCI').form
+				var fieldNameList = FIELD_LIST_KONTRAHENCI
+				fieldNameList.filter(function (fieldName) {
+					if (!frm[fieldName]) console.log('Err missing field: "'+fieldName+'"')
+					return (frm[fieldName]) ? true : false
+				}).map(function (fieldName) {
+					return [ fieldName, frm[fieldName].value ]
+				}).filter(function (filter) {
+					return ( filter[1].length > 0 )
+				}).map(function (filter) {
+					filterFields[ filter[0] ] = filter[1]
+				})
+				var filterIdGroup = getItemLocalStorage('Bocian.biAuditForm.kontrahenci.filterIdGroup');
+				if (filterIdGroup) filterFields[ 'filterIdGroup' ] = filterIdGroup
+
+				window.fetch(URL_ADD_KONTRAHENCI_TO_GROUP, {
+					method: 'POST',
+					header: {
+						'contentType': 'applications/json'
+					},
+					credentials: 'same-origin',
+					body: JSON.stringify({
+						'idGroup': idGroup,
+						'type': 'filter',
+						'filter': filterFields,
+					})
+				})
+				.then(function(response) {
+					return response.text();
+				})
+				.then(function(responseText) {
+
+					try {
+						return JSON.parse(responseText);
+					} catch (e) {
+						throw responseText;
+					}
+				})
+				.then(function(result) {
+
+					if (result.type == 'success') {
+						p5UI__notifyAjaxCallback(result);
+						resolve(result.msg);
+					} else {
+						reject(result.msg);
+					}
+				})
+				.catch(function(error) {
+					console.log('request failed', error)
+				});
+	    })
+	  },
+	  allowOutsideClick: false
+	});
+}
 
 
 function createGroupKontrahenci(event) {
@@ -1920,6 +1996,7 @@ global.removeItemArrayInArray = removeItemArrayInArray;
 global.addPracownikToGroup = addPracownikToGroup;
 global.addPracownikAllToGroup = addPracownikAllToGroup;
 global.addKontrahenciToGroup = addKontrahenciToGroup;
+global.addKontrahenciAllToGroup = addKontrahenciAllToGroup;
 
 global.showViewUploadFile = showViewUploadFile;
 global.parseCsvFile = parseCsvFile;