Ver código fonte

fixed Zaliczka update koresp

Piotr Labudda 9 anos atrás
pai
commit
db62eec586

+ 6 - 0
SE/se-lib/Core/AclBase.php

@@ -691,6 +691,12 @@ class Core_AclBase {
   }
 
   public function cleanRefs($childName, $pk) {// TODO: $idTransaction
+    $refTable = ACL::getRefTable($this->getNamespace(), $childName);
+    DB::getPDO()->update($refTable, 'PRIMARY_KEY', $pk, [
+      'A_STATUS' => 'DELETED',
+    ]);
+
+    // TODO: REMOVE legacy code below:
     $refTable = Core_AclHelper::getRefTable($this->getName(), $childName);
     $sqlPk = DB::getPDO()->quote($pk, PDO::PARAM_STR);
     DB::getPDO()->exec("

+ 1 - 0
SE/se-lib/Route/UrlAction/UserProNetMediaZaliczka.php

@@ -79,6 +79,7 @@ class Route_UrlAction_UserProNetMediaZaliczka extends RouteBase {// TODO: UrlAct
 				'nierozliczona_kwota',
 				'pozycja',
 				'worker',
+				'korespondencja',
 			]
 		]);// $this->fetchDataBySchema($schema, $args['idUser']);
 		return [

+ 11 - 7
SE/se-lib/Schema/DefaultDb/in7_dziennik_koresp/ZaliczkaKorespStorageAcl.php

@@ -18,18 +18,22 @@ class Schema_DefaultDb_in7_dziennik_koresp_ZaliczkaKorespStorageAcl extends Core
 
   public function getItems($params = array()) {
     DBG::log($params);// f_title' => 'kore'
-    $sqlWhere = "1=1";
-    if (empty($params) || empty($params['f_title'])) {
-      DBG::log("return last created rows by user or another users");
-    } else {
+    $sqlWhereAnd = array();
+    if (empty($params)) {
+    } else if (!empty($params['@primaryKey'])) {// [@primaryKey] => Array ([0] => 59599)
+      if (is_array($params['@primaryKey'])) {
+        $sqlWhereAnd[] = "k.ID in(" . implode(", ", $params['@primaryKey']) . ")";
+      }
+    } else if (!empty($params['f_title'])) {
       DBG::log("return filter by K_ZAWARTOS, K_OD_KOGO like '%{$params['f_title']}%' order by last created rows by user or another users");
       $sqlParamTitle = DB::getPDO()->quote("%{$params['f_title']}%", PDO::PARAM_STR);
-      $sqlWhere = " (
+      $sqlWhereAnd[] = " (
         k.ID like {$sqlParamTitle}
         or k.K_ZAWARTOS like {$sqlParamTitle}
         or k.K_OD_KOGO like {$sqlParamTitle}
       ) ";
     }
+    $sqlWhere = (!empty($sqlWhereAnd)) ? implode(" and ", $sqlWhereAnd) : "1=1";
 
     return array_map(
       function ($row) {
@@ -38,12 +42,12 @@ class Schema_DefaultDb_in7_dziennik_koresp_ZaliczkaKorespStorageAcl extends Core
           'title' => $row['title'],
           'kategoriaKosztu' => $row['kategoriaKosztu'],
           'projekt' => ($row['ID_PROJECT'] > 0)
-            ? DB::getPDO()->fetchFirst("
+            ? array(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,
         ];
       },

+ 65 - 6
SE/se-lib/Schema/DefaultDb/zaliczka/ZaliczkaStorageAcl.php

@@ -186,6 +186,7 @@ class Schema_DefaultDb_zaliczka_ZaliczkaStorageAcl extends Core_AclSimpleSchemaB
   }
 
   public function updateItem($itemPatch) {
+    DBG::log(['msg' => '$itemPatch', $itemPatch]);
     $pkField = $this->getPrimaryKeyField();
     if (!array_key_exists($pkField, $itemPatch)) throw new Exception("Missing primary key");
     $pk = (int)$itemPatch[$pkField];
@@ -195,18 +196,76 @@ class Schema_DefaultDb_zaliczka_ZaliczkaStorageAcl extends Core_AclSimpleSchemaB
 				'id',
 				'kwota',
 				// 'nierozliczona_kwota',
+				'korespondencja',
 				'pozycja',
 				// 'worker',
 			]
 		]);
+    DBG::log(['msg' => '$oldItem', $oldItem]);
+
+    // pozycja
+
+    // korespondencja
+    if (empty($oldItem['korespondencja'])) {
+      DBG::log("empty \$oldItem['korespondencja']");
+      if (!empty($itemPatch['korespondencja'])) {
+        if (empty($itemPatch['korespondencja'][0]['id'])) throw new Exception("BUG: Missing Koresp id");
+        $pkKoresp = $itemPatch['korespondencja'][0]['id'];
+        $this->insertRef('korespondencja', $pk, $pkKoresp);
+      }
+    } else {
+      DBG::log("!empty \$oldItem['korespondencja'] " . ((!empty($itemPatch['korespondencja'])) ? "not empty" : "empty") . " patch koresp");
+      // if (id != id) => update : clearRefs, insertRef
+      if (empty($oldItem['korespondencja'][0]['id'])) throw new Exception("BUG: Missing Koresp id in current object");
+
+      if (!empty($itemPatch['korespondencja'])) {
+        if (empty($itemPatch['korespondencja'][0]['id'])) throw new Exception("BUG: Missing Koresp id");
+        $pkOldKoresp = $oldItem['korespondencja'][0]['id'];
+        $pkKoresp = $itemPatch['korespondencja'][0]['id'];
+        DBG::log("\$pkOldKoresp({$pkOldKoresp}), \$pkKoresp({$pkKoresp})");
+        if ($pkOldKoresp != $pkKoresp) {
+          $this->cleanRefs('korespondencja', $pk);
+          $this->insertRef('korespondencja', $pk, $pkKoresp);
+        }
+      } else {
+        DBG::log("cleanRefs \$pk({$pk})");
+        $this->cleanRefs('korespondencja', $pk);
+      }
+    }
+
+/* { "updates": {
+        "@instance": "ZaliczkaAktywna",
+        "id": "8",
+        "created": "2017-01-27 11:10:59",
+        "worker": [{ "id": "1", "login": "magdalena.cichosz", "name": "Magdalena Cichosz" }],
+        "kwota": "0.01",
+        "nierozliczona_kwota": "300.02",
+        "pozycja": [{
+            "id": -1,
+            "nr_faktury": "fv 2017/1/1",
+            "kwota": 100,
+            "vat": 23,
+            "kwota_netto": 0,
+            "kategoria_kosztu": "BUDOWA: Usługi obce"
+        }],
+        "korespondencja": {
+            "id": "6013",
+            "title": "faktura Vat (MULTI-TAB) [6013]",
+            "kategoriaKosztu": "do uzgodnienia",
+            "projekt": { "id": "64", "nrBudowy": "20/2016" }
+        }
+    }
+} */
+
     $patch = [];
-    $itemPatch['kwota'] = str_replace(',', '.', $itemPatch['kwota']);
-    if ($itemPatch['kwota'] != $oldItem['kwota']) $patch['kwota'] = $itemPatch['kwota'];
-    // TODO: doff $itemPatch['pozycja'] != $oldItem['pozycja']
+    // $itemPatch['kwota'] = str_replace(',', '.', $itemPatch['kwota']);
+    // if ($itemPatch['kwota'] != $oldItem['kwota']) $patch['kwota'] = $itemPatch['kwota'];
+
+    // TODO: diff $itemPatch['pozycja'] != $oldItem['pozycja']
     if (!empty($patch)) {
-      if (array_key_exists('kwota', $patch)) {
-        DB::getPDO()->update('ZALICZKA', 'ID', $pk, [ 'kwota' => $patch['kwota'] ]);
-      }
+      // if (array_key_exists('kwota', $patch)) {
+      //   DB::getPDO()->update('ZALICZKA', 'ID', $pk, [ 'kwota' => $patch['kwota'] ]);
+      // }
     }
   }
 

Diferenças do arquivo suprimidas por serem muito extensas
+ 0 - 0
SE/static/zaliczka/main.js


Alguns arquivos não foram mostrados porque muitos arquivos mudaram nesse diff