瀏覽代碼

added btn add all to group

Piotr Labudda 7 年之前
父節點
當前提交
caa685700a
共有 2 個文件被更改,包括 166 次插入2 次删除
  1. 66 2
      tools/Bocian.php
  2. 100 0
      tools/Bocian.php.view.js

+ 66 - 2
tools/Bocian.php

@@ -1110,11 +1110,21 @@ public function showPowiazaniaEnergaRumKontrahenciPowiazania($items) {
 	}
 	public function addPracownicyToGroupAjax($args) {
 		$idGroup = V::get('idGroup', '', $args);
+		$type = V::get('type', 'ids', $args);
 		$pracownicyIds = V::get('pracownicyIds', '', $args);
+		$filter = V::get('filter', '', $args);
 
 		// validate
 		if (!$idGroup) throw new Exception("Nie wybrano grupa");
-		if (!$pracownicyIds || count($pracownicyIds) == 0 ) throw new Exception("Proszę wybrać pracowników");
+		switch ($type) {
+			case 'ids': {
+				if (!$pracownicyIds || count($pracownicyIds) == 0) throw new Exception("Proszę wybrać pracowników");
+			} break;
+			case 'filter': {
+				if (!isset($args['filter'])) throw new Exception("Proszę wybrać pracowników");
+			} break;
+			default: throw new Exception("Missing type");
+		}
 
 		// TODO: SPRWADZENIE  CZY NIE DODANOU JUZ PRACOWNIKAS
 		// default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group
@@ -1131,6 +1141,59 @@ 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>nazwisko</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_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group',
+					'primaryKey' => $args__idGroup,
+					'fieldName' => 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY',
+				];
+			}
+
+			$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_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY');
+			$query = $acl->buildQuery(array_merge([
+				'cols' => array_merge(self::$FIELD_LIST_PRACOWNICY, [
+					'default_db__x3A__BI_audit_ENERGA_PRACOWNICY_adresy:BI_audit_ENERGA_PRACOWNICY_adresy/*'
+				]),
+			], $searchParams, $filtersParams, $backRefFilter));
+			$items = $query->getItems();
+
+			$pracownicyIds = array_map(function ($row) {
+				return $row['ID'];
+			}, $items);
+		}
+
 		// $refGrupyToPracownicy = ACL::getRefTable('obiekt główny', 'nazwa pola - powiązane rekordy');
 		$refGrupyToPracownicy = ACL::getRefTable('default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group',
 			'default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY');
@@ -1335,7 +1398,8 @@ public function showPowiazaniaEnergaRumKontrahenciPowiazania($items) {
 					<li><a  title="IMPORT PRACOWNIKÓW" onClick="showViewUploadFile(event, \'Import pracowników\', \'pracownicy\', \'yes\', \''.$csvExamplePracownicy.'\'  )" class="btn btn-info">IMPORT PRACOWNIKÓW</a></li>
 					<!--<li><a href="#" title="DODAJ PRACOWNIKÓW" class="btn btn-info" >+ DODAJ PRACOWNIKÓW</a></li>-->'; //todo: dodać obsługe doddawania pracownikow
 
-					$buttonMoveToGroup = '<a title="DODAJ DO GRUPY" onClick="addPracownikToGroup(event)" class="btn btn-info">DODAJ DO GRUPY</a>';
+					$buttonMoveToGroup = '<a title="DODAJ WYBRANE DO GRUPY" onClick="addPracownikToGroup(event)" class="btn btn-info">DODAJ WYBRANE DO GRUPY</a>';
+					$buttonMoveToGroup .= '<a title="DODAJ WSZYSTKIE DO GRUPY" onClick="addPracownikAllToGroup(event)" class="btn btn-info" style="margin-left:12px">DODAJ WSZYSTKIE DO GRUPY</a>';
 
 					$showButtonNextStep = '<a href="'.Request::getPathUri().'index.php?_route=UrlAction_Bocian#KONTRAHENCI"  title="DODAJ DO ANALIZY" class="btn btn-primary">DODAJ DO ANALIZY</a>';
 

+ 100 - 0
tools/Bocian.php.view.js

@@ -393,6 +393,105 @@ function addPracownikToGroup(event) {
 		//TODO: pIOTRKU CZY TU POWINIENEM COŚ JESZCZE OBSŁUŻYĆ
 	});
 }
+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 arrayGroupOptions = [];
+	var listGroupStorage = getItemLocalStorage('Bocian.biAuditForm.pracownicy.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: showTextListIdPracownikow,
+	  inputOptions: arrayGroupOptions,
+	  inputPlaceholder: 'Wybierz grupę',
+	  showCancelButton: true,
+	  confirmButtonText: 'Zapisz',
+	  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;
+				}
+
+				var filterFields = {}
+				var frm = document.getElementById('filtersFieldRemoveBtn-PRACOWNICY').form
+				var fieldNameList = FIELD_LIST_PRACOWNICY
+				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.pracownicy.filterIdGroup');
+				if (filterIdGroup) filterFields[ 'filterIdGroup' ] = filterIdGroup
+
+				window.fetch(URL_ADD_PRACOWNICY_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
+	}).then(function (groupPracownicyData) {
+		//TODO: pIOTRKU CZY TU POWINIENEM COŚ JESZCZE OBSŁUŻYĆ
+	});
+}
 
 /**
  * Popup z opcja przeniesienia kontrahentów do innej grupy
@@ -1819,6 +1918,7 @@ global.removeItemInArray = removeItemInArray;
 global.removeItemArrayInArray = removeItemArrayInArray;
 
 global.addPracownikToGroup = addPracownikToGroup;
+global.addPracownikAllToGroup = addPracownikAllToGroup;
 global.addKontrahenciToGroup = addKontrahenciToGroup;
 
 global.showViewUploadFile = showViewUploadFile;