Просмотр исходного кода

updated Zaliczka schema, search

Piotr Labudda 9 лет назад
Родитель
Сommit
311cfcea7e

+ 45 - 5
SE/se-lib/Core/AclSimpleSchemaBase.php

@@ -260,10 +260,10 @@ class Core_AclSimpleSchemaBase extends Core_AclBase {
   public function canWriteField($fieldName) { return false; }// TODO: perms from Procesy
   public function canWriteObjectField($fieldName, $record) { return false; }// TODO: perms from Procesy
 
-  public function getTotal($params = array()) { throw new Exception("Unimplemented - TODO: F." . __FUNCTION__); }// TODO: use ParseOgcQuery
-  public function getItem($primaryKey, $params = []) { throw new Exception("Unimplemented - TODO: F." . __FUNCTION__); }
-  public function getItems($params = array()) { throw new Exception("Unimplemented - TODO: F." . __FUNCTION__); }// TODO: use ParseOgcQuery
-  public function itemsFetchRefs(&$items) { throw new Exception("Unimplemented - TODO: F." . __FUNCTION__); }// TODO: , $fieldName = ''
+  public function getTotal($params = array()) { throw new Exception("Unimplemented - TODO: " . get_class($this) . "::" . __FUNCTION__); }// TODO: use ParseOgcQuery
+  public function getItem($primaryKey, $params = []) { throw new Exception("Unimplemented - TODO: " . get_class($this) . "::" . __FUNCTION__); }
+  public function getItems($params = array()) { throw new Exception("Unimplemented - TODO: " . get_class($this) . "::" . __FUNCTION__); }// TODO: use ParseOgcQuery
+  public function itemsFetchRefs(&$items) { throw new Exception("Unimplemented - TODO: " . get_class($this) . "::" . __FUNCTION__); }// TODO: , $fieldName = ''
   public function fetchItemFieldRefs($primaryKey, $fieldName) {
     $refTable = ACL::getRefTable($this->getNamespace(), $fieldName);
     $sqlPk = DB::getPDO()->quote($primaryKey, PDO::PARAM_STR);
@@ -282,7 +282,7 @@ class Core_AclSimpleSchemaBase extends Core_AclBase {
     );
   }
   public function addItem($itemTodo) { throw new Exception("Unimplemented - TODO: " . get_class($this) . "::" . __FUNCTION__); }
-  public function updateItem($itemPatch) { throw new Exception("Unimplemented - TODO: F." . __FUNCTION__); }
+  public function updateItem($itemPatch) { throw new Exception("Unimplemented - TODO: " . get_class($this) . "::" . __FUNCTION__); }
 
   public function getGeomFieldType($fieldName) { return null; }
   public function getPrimaryKeyField() { return $this->_primaryKey; }
@@ -468,4 +468,44 @@ class Core_AclSimpleSchemaBase extends Core_AclBase {
     return Core_AclHelper::getChildHistTable($this->getRootTableName(), $childName, $childSchema);
   }
 
+  public function getEnumValues($childName) {
+    $childSchema = $this->_simpleSchema['root'][$childName];
+    DBG::log([
+      'msg' => 'dbg acl',
+      'sql field name' => $this->getSqlFieldName($childName),
+      'xsdType' => $this->getXsdFieldType($childName),
+      'childSchema' => $childSchema,
+    ]);
+
+    if ('p5:enum' == $this->getXsdFieldType($childName)) {
+      if (!empty($this->_simpleSchema['root'][$childName]['@aliasFieldValues'])) {
+        $aliasConf = $this->_simpleSchema['root'][$childName]['@aliasFieldValues'];
+        $acl = Core_AclHelper::getAclByNamespace($aliasConf['namespace']);
+        $sqlFldName = DB::getPDO()->quote($acl->getSqlFieldName($aliasConf['childName']), PDO::PARAM_STR);
+        $sqlTblName = DB::getPDO()->quote($acl->getRootTableName(), PDO::PARAM_STR);
+        $sqlDbName = DB::getPDO()->quote(DB::getPDO()->getDatabaseName(), PDO::PARAM_STR);
+      } else {
+        $sqlFldName = DB::getPDO()->quote($this->getSqlFieldName($childName), PDO::PARAM_STR);
+        $sqlTblName = DB::getPDO()->quote($this->getRootTableName(), PDO::PARAM_STR);
+        $sqlDbName = DB::getPDO()->quote(DB::getPDO()->getDatabaseName(), PDO::PARAM_STR);
+      }
+      $optionsEnum = DB::getPDO()->fetchValue("
+        select COLUMN_TYPE
+        from information_schema.COLUMNS c
+        where c.COLUMN_NAME = {$sqlFldName}
+          and c.TABLE_SCHEMA = {$sqlDbName}
+          and c.TABLE_NAME = {$sqlTblName}
+      ");
+      if (!empty($optionsEnum)) {
+        $optionsEnum = substr($optionsEnum, strlen('enum'));
+        $optionsEnum = trim($optionsEnum, "()'");
+        DBG::log(['msg' => '$optionsEnum', '$optionsEnum' => $optionsEnum]);
+        return explode("','", $optionsEnum);
+      }
+      DBG::log(['msg' => 'Error empty options from enum field', '$optionsEnum' => $optionsEnum]);
+      return null;
+    }
+    return null;
+  }
+
 }

+ 23 - 18
SE/se-lib/Route/UrlAction/UserProNetMediaZaliczka.php

@@ -91,27 +91,32 @@ class Route_UrlAction_UserProNetMediaZaliczka extends RouteBase {// TODO: UrlAct
 		Response::sendTryCatchJson(array($this, 'fetchDataAjaxReponseCallback'), $args = 'JSON_FROM_REQUEST_BODY');// try to read json from request body
 	}
 	public function fetchDataAjaxReponseCallback($args) {
-		if (empty($args) || empty($args['schema']['@namespace']) || empty($args['schema']['@namespace'])) throw new HttpException("Error Parsing Request - missing @namespace", 400);
-		$nsUri = $args['schema']['@namespace'];
-		if ('default_db/IN7_DZIENNIK_KORESP/ZaliczkaKoresp' == $nsUri) {
-			return [
-				'options' => [
-					[ 'id' => "65432", 'title' => "testowa koresp 1", 'kategoriaKosztu' => "KOSZT1" ],
-					[ 'id' => "10008", 'title' => "testowa koresp 8", 'kategoriaKosztu' => "KOSZT8" ],
-					[ 'id' => "10009", 'title' => "testowa koresp 9", 'kategoriaKosztu' => "KOSZT9" ],
-				]
-			];
-		}
-		if ('default_db/IN7_MK_BAZA_DYSTRYBUCJI/ZaliczkaProjekt' == $nsUri) {
+		DBG::log(['msg' => 'args', 'args' => $args]);
+		if (empty($args)) throw new HttpException("Error Parsing Request - missing args", 400);
+		if (empty($args['schema']['@namespace']) && empty($args['objectNamespace'])) throw new HttpException("Error Parsing Request - missing @namespace", 400);
+		if (!empty($args['schema']['@namespace'])) {
+			if ('default_db/IN7_DZIENNIK_KORESP/ZaliczkaKoresp' == $args['schema']['@namespace']) {
+				return [
+					'type' => 'success',
+					'options' => array_values(Core_AclHelper::getAclByNamespace($args['schema']['@namespace'])->getItems([
+						'f_K_ZAWARTOS' => V::get('query', '', $args)
+					]))
+				];
+			} else {
+				return [ 'type' => "error", 'msg' => "Unsupported @namespace" ];
+			}
+		} else if (!empty($args['objectNamespace'])) {
+			// childName : "kategoria_kosztu"
+			// objectNamespace : "default_db/ZALICZKA_POZYCJA/ZaliczkaPozycja"
+			if (empty($args['childName'])) throw new Exception("Missing childName");
+
+			$acl = Core_AclHelper::getAclByNamespace($args['objectNamespace']);
 			return [
-				'options' => [
-					[ 'id' => 100, 'nrBudowy' => 'Budowa 100/2016' ],
-					[ 'id' => 101, 'nrBudowy' => 'Budowa 101/2016' ],
-					[ 'id' => 102, 'nrBudowy' => 'Budowa 102/2016' ],
-				]
+				'type' => 'success',
+				'options' => $acl->getEnumValues($args['childName'])
 			];
 		}
-		return null;// msg?
+		return [ 'type' => "error", 'msg' => "Unsupported @namespace or xsdType" ];
 	}
 
 	public function fetchDataBySchema($schema, $idUser, $primaryKey = null) {// if $primaryKey is null then search for last row

+ 45 - 21
SE/se-lib/Route/UrlAction/UserProNetMediaZaliczka.php.fetchData.js

@@ -1,21 +1,21 @@
 // @require var SYNC_URL
 
-function zaliczkaFetchData(query, fieldType, resultCallback) {
-  console.warn('TODO: zaliczkaFetchData(query, fieldType, resultCallback)  query('+query+') fieldType:', fieldType);
+function zaliczkaFetchData(query, args, resultCallback) {
+  console.warn('TODO: zaliczkaFetchData(query, objectNamespace, resultCallback)  query('+query+') args:', args);
 
-  // fieldType: Object {"@namespace": "default_db:IN7_DZIENNIK_KORESP", id: "xsd:integer", title: "xsd:string", kategoriaKosztu: "xsd:string"}
-  if ('object' !== typeof fieldType) {
-    console.log("BUG: Unsupported type '" + fieldType + "'");
+  // objectNamespace: Object {"@namespace": "default_db:IN7_DZIENNIK_KORESP", id: "xsd:integer", title: "xsd:string", kategoriaKosztu: "xsd:string"}
+  if ('object' !== typeof args) {
+    console.log("BUG: Unsupported type '" + args + "'");
     return;
   }
-  if (!fieldType['@namespace'] && !fieldType['xsdType']) {
+  if (!args['@namespace'] && !args['objectNamespace']) {
     // TODO: log error
-    console.error("BUG: Missing xmlns or xsdType on fieldType");
+    console.error("BUG: Missing namespace in args");
     return;
   }
 
-  if (fieldType['@namespace']) {
-    switch (fieldType['@namespace']) {
+  if (args['@namespace']) {
+    switch (args['@namespace']) {
       case 'default_db/IN7_MK_BAZA_DYSTRYBUCJI/ZaliczkaProjekt':
       case 'default_db/IN7_DZIENNIK_KORESP/ZaliczkaKoresp':
       {
@@ -23,7 +23,7 @@ function zaliczkaFetchData(query, fieldType, resultCallback) {
           .post(SYNC_URL)
           .type('json') // header ĺapplication/x-www-form-urlencoded' requires type('form');
           .send({
-            schema: fieldType,
+            schema: args,
             query: query
           })
           .set('Accept', 'application/json')
@@ -40,24 +40,48 @@ function zaliczkaFetchData(query, fieldType, resultCallback) {
 			}
       break;
       default: {
-        console.log("BUG: Unsupported type namespace '" + fieldType['@namespace'] + "'");
+        console.log("BUG: Unsupported type namespace '" + args['@namespace'] + "'");
       }
     }
     return;
   }
 
-  if (fieldType['xsdType']) {
-    switch (fieldType['xsdType']) {
-      case 'default_db__x3A__ZALICZKA_POZYCJA:kategoria_kosztuType': {
-        var options = [
-          'Koszt-1',
-          'Koszt-2',
-          'Koszt-3',
-        ]
-        resultCallback({options: options});
+  if ('default_db/ZALICZKA_POZYCJA/ZaliczkaPozycja' == args['objectNamespace']) {
+    switch (args['childName']) {
+      case 'kategoria_kosztu': {
+        fetch(SYNC_URL, {
+  			  method: 'POST',
+  				credentials: 'same-origin',// add cookies
+          headers: { 'Content-Type': 'application/json' },
+          body: JSON.stringify({
+            objectNamespace: args['objectNamespace'],
+            childName: args['childName'],
+            query: query
+          })
+  			}).then(function (response) {
+  				return response.json()
+  			}).then(function (data) {
+          if (!data) throw "Empty response";
+  				console.log('loadDataAjax:fetch: request finished data:', data);
+          if ('error' === data.type) {
+            p5UI__notifyAjaxCallback(data);
+    				console.log('loadDataAjax:fetch: ERR:', e);
+          } else if ('success' === data.type) {
+            resultCallback({options: data.options || []});
+          } else {
+            p5UI__notifyAjaxCallback(data);
+    				console.log('loadDataAjax:fetch: ERR:', e);
+          }
+  			}).catch(function (e) {
+          p5UI__notifyAjaxCallback({
+            type: 'error',
+            msg: "Request error " + e
+          });
+  				console.log('loadDataAjax:fetch: ERR:', e);
+  			});
       } break;
       default: {
-        console.warn("BUG: Unsupported xsdType '" + fieldType['xsdType'] + "'");
+        console.warn("BUG: Unsupported namespace '" + args['objectNamespace'] + "'");
       }
     }
     return;

+ 44 - 0
SE/se-lib/Schema/DefaultDb/in7_dziennik_koresp/ZaliczkaKorespStorageAcl.php

@@ -16,4 +16,48 @@ class Schema_DefaultDb_in7_dziennik_koresp_ZaliczkaKorespStorageAcl extends Core
     ],
   ];
 
+  public function getItems($params = array()) {
+    DBG::log($params);// f_K_ZAWARTOS' => 'kore'
+    $sqlWhere = "1=1";
+    if (empty($params) || empty($params['f_K_ZAWARTOS'])) {
+      DBG::log("TODO: return last created rows by user or another users");
+    } else {
+      DBG::log("TODO: return filter by K_ZAWARTOS like '%{$params['f_K_ZAWARTOS']}%' order by last created rows by user or another users");
+      $sqlWhere = " k.K_ZAWARTOS like " . DB::getPDO()->quote("%{$params['f_K_ZAWARTOS']}%", PDO::PARAM_STR);
+    }
+
+    return array_map(
+      function ($row) {
+        return [
+          'id' => $row['id'],
+          'title' => $row['title'],
+          'kategoriaKosztu' => $row['kategoriaKosztu'],
+          'projekt' => ($row['ID_PROJECT'] > 0)
+            ? DB::getPDO()->fetchFirst("
+              select p.ID as id
+                  , p.M_DIST_DEALNUM as nrBudowy
+              from IN7_MK_BAZA_DYSTRYBUCJI p
+              where p.ID = {$row['ID_PROJECT']}
+            ")
+            : null,
+        ];
+      },
+      DB::getPDO()->fetchAll("
+        select k.ID as id
+          , k.K_ZAWARTOS as title
+          , k.KATEGORIA_KOSZTU as kategoriaKosztu
+          , k.ID_PROJECT
+        from IN7_DZIENNIK_KORESP k
+        where {$sqlWhere}
+        order by ID desc
+        limit 30
+      ")
+    );
+    // return [
+    //   [ 'id' => "65432", 'title' => "testowa koresp 1", 'kategoriaKosztu' => "KOSZT1" ],
+    //   [ 'id' => "10008", 'title' => "testowa koresp 8", 'kategoriaKosztu' => "KOSZT8" ],
+    //   [ 'id' => "10009", 'title' => "testowa koresp 9", 'kategoriaKosztu' => "KOSZT9" ],
+    // ];
+  }
+
 }

+ 4 - 1
SE/se-lib/Schema/DefaultDb/zaliczka_pozycja/ZaliczkaPozycjaStorageAcl.php

@@ -14,7 +14,10 @@ class Schema_DefaultDb_zaliczka_pozycja_ZaliczkaPozycjaStorageAcl extends Core_A
       'kwota' => [ '@type' => 'xsd:decimal', '@totalDigits' => 16, '@fractionDigits' => 2 ],
       'vat' => [ '@type' => "xsd:integer", '@default' => 23 ],
       'kwota_netto' => [ '@type' => 'xsd:decimal', '@totalDigits' => 16, '@fractionDigits' => 2 ],
-      'kategoria_kosztu' => [ '@type' => 'default_db__x3A__ZALICZKA_POZYCJA:kategoria_kosztuType' ],// default_db__x3A__IN7_DZIENNIK_KORESP:kategoria_kosztuType
+      'kategoria_kosztu' => [ '@type' => 'p5:enum', '@aliasFieldValues' => [
+        'namespace' => 'default_db/IN7_DZIENNIK_KORESP',
+        'childName' => 'KATEGORIA_KOSZTU'
+      ] ],// default_db__x3A__ZALICZKA_POZYCJA:kategoria_kosztuType, default_db__x3A__IN7_DZIENNIK_KORESP:kategoria_kosztuType
       // 'korespondencja' => [ '@ref' => 'default_db/IN7_DZIENNIK_KORESP/ZaliczkaKoresp' ],
       // 'projekt' => [ '@ref' => 'default_db/IN7_MK_BAZA_DYSTRYBUCJI/ZaliczkaProjekt' ]
     ],

Разница между файлами не показана из-за своего большого размера
+ 0 - 0
SE/static/zaliczka/main.js


Некоторые файлы не были показаны из-за большого количества измененных файлов