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

+ 17 - 1
SE/se-lib/Schema/DefaultDb/zaliczka/ZaliczkaStorageAcl.php

@@ -204,6 +204,22 @@ class Schema_DefaultDb_zaliczka_ZaliczkaStorageAcl extends Core_AclSimpleSchemaB
     DBG::log(['msg' => '$oldItem', $oldItem]);
 
     // pozycja
+    $pozAcl = ACL::getAclByNamespace('default_db/ZALICZKA_POZYCJA/ZaliczkaPozycja');
+    if (empty($oldItem['pozycja'])) {
+      DBG::log("empty \$oldItem['pozycja']");
+      if (!empty($itemPatch['pozycja'])) {
+        foreach ($itemPatch['pozycja'] as $pozTodo) {
+          if ($pozTodo['id'] !== -1) throw new Exception("BUG ZaliczkaPozycja id not equal -1");
+          unset($pozTodo['id']);
+          $pkPoz = $pozAcl->addItem($pozTodo);
+          DBG::log(['msg'=> '$pkPoz', $pkPoz]);
+          $this->insertRef('pozycja', $pk, $pkPoz);
+        }
+      }
+    } else {
+      DBG::log("not empty \$oldItem['pozycja'] " . ((!empty($itemPatch['pozycja'])) ? "not empty" : "empty") . " patch pozycja");
+
+    }
 
     // korespondencja
     if (empty($oldItem['korespondencja'])) {
@@ -214,7 +230,7 @@ class Schema_DefaultDb_zaliczka_ZaliczkaStorageAcl extends Core_AclSimpleSchemaB
         $this->insertRef('korespondencja', $pk, $pkKoresp);
       }
     } else {
-      DBG::log("!empty \$oldItem['korespondencja'] " . ((!empty($itemPatch['korespondencja'])) ? "not empty" : "empty") . " patch koresp");
+      DBG::log("not 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");
 

+ 53 - 0
SE/se-lib/Schema/DefaultDb/zaliczka_pozycja/ZaliczkaPozycjaStorageAcl.php

@@ -36,4 +36,57 @@ class Schema_DefaultDb_zaliczka_pozycja_ZaliczkaPozycjaStorageAcl extends Core_A
     // ]
   ];
 
+  public function addItem($itemTodo) {
+    DBG::log(['msg'=> 'addItem', $itemTodo]);
+    $sqlItem = array();
+    if (!empty($itemTodo['nr_faktury'])) {
+      $sqlItem[ $this->getSqlFieldName('nr_faktury') ] = $itemTodo['nr_faktury'];
+    }
+    if (!empty($itemTodo['kwota'])) {
+      $kwota = V::get('kwota', 0, $itemTodo, 'price');
+      if ($kwota > 0) $sqlItem[ $this->getSqlFieldName('kwota') ] = $kwota;
+    }
+    if (!empty($itemTodo['vat'])) {
+      $vat = (int)$itemTodo['vat'];
+      if ($vat > 0) $sqlItem[ $this->getSqlFieldName('vat') ] = $vat;
+    }
+    if (!empty($itemTodo['kategoria_kosztu'])) {
+      $sqlItem[ $this->getSqlFieldName('kategoria_kosztu') ] = $itemTodo['kategoria_kosztu'];
+    }
+
+    $sqlItem[ $this->getSqlFieldName('kwota_netto') ] = ($kwota > 0 && $vat > 0)
+      ? $kwota / (1 + $vat / 100)
+      : 0;
+
+    if (empty($sqlItem)) throw new Exception("Empty record");
+    return DB::getPDO()->insert($this->getRootTableName(), $sqlItem);
+  }
+
+  public function getItems($params = array()) {
+    DBG::log(['msg'=> 'getItems', $params]);
+    // $idUser = V::get('primaryKey', 0, $params['#refFrom'], 'int');
+    $sqlWhereAnd = array();
+    if (empty($params)) {
+    } else if (!empty($params['@primaryKey'])) {// [@primaryKey] => Array ([0] => 59599)
+      if (is_array($params['@primaryKey'])) {
+        $sqlWhereAnd[] = "z.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);
+    //   $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 DB::getPDO()->fetchAll("
+      select z.*
+      from ZALICZKA_POZYCJA z
+      where {$sqlWhere}
+      order by z.ID ASC
+    ");
+  }
+
 }