|
@@ -9,7 +9,7 @@ class Schema_DefaultDb_zaliczka_pozycja_ZaliczkaPozycjaStorageAcl extends Core_A
|
|
|
'root' => [
|
|
'root' => [
|
|
|
'@namespace' => 'default_db/ZALICZKA_POZYCJA/ZaliczkaPozycja',// Api_WfsNs::getBaseWfsUri() . '/default_db/Zaliczka'
|
|
'@namespace' => 'default_db/ZALICZKA_POZYCJA/ZaliczkaPozycja',// Api_WfsNs::getBaseWfsUri() . '/default_db/Zaliczka'
|
|
|
'@primaryKey' => 'id',
|
|
'@primaryKey' => 'id',
|
|
|
- 'id' => 'xsd:integer',
|
|
|
|
|
|
|
+ 'id' => [ '@type' => 'xsd:integer', '@alias' => 'ID' ],
|
|
|
'nr_faktury' => [ '@type' => "xsd:string" ],
|
|
'nr_faktury' => [ '@type' => "xsd:string" ],
|
|
|
'kwota' => [ '@type' => 'xsd:decimal', '@totalDigits' => 16, '@fractionDigits' => 2 ],
|
|
'kwota' => [ '@type' => 'xsd:decimal', '@totalDigits' => 16, '@fractionDigits' => 2 ],
|
|
|
'vat' => [ '@type' => "xsd:integer", '@default' => 23 ],
|
|
'vat' => [ '@type' => "xsd:integer", '@default' => 23 ],
|
|
@@ -62,6 +62,66 @@ class Schema_DefaultDb_zaliczka_pozycja_ZaliczkaPozycjaStorageAcl extends Core_A
|
|
|
return DB::getPDO()->insert($this->getRootTableName(), $sqlItem);
|
|
return DB::getPDO()->insert($this->getRootTableName(), $sqlItem);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public function updateItem($itemPatch) {
|
|
|
|
|
+ DBG::log(['msg'=> 'updateItem: $itemPatch', $itemPatch]);
|
|
|
|
|
+ // 'id' => '1',
|
|
|
|
|
+ // 'nr_faktury' => '100.',
|
|
|
|
|
+ // 'kwota' => '123.46',
|
|
|
|
|
+ // 'vat' => '23',
|
|
|
|
|
+ // 'kwota_netto' => '100.37',
|
|
|
|
|
+ // 'kategoria_kosztu' => 'BUDOWA: Wynagrodzenia osobowe + ZUS',
|
|
|
|
|
+ $pkField = $this->getPrimaryKeyField();
|
|
|
|
|
+ $pk = V::get($pkField, null, $itemPatch);
|
|
|
|
|
+ if (null === $pk) throw new Exception("BUG missing primary key field for {$this->_namespace}");
|
|
|
|
|
+ $oldItem = $this->getItem($pk);// TODO: only cols: ['id', 'nr_faktury', 'kwota', 'vat', 'kategoria_kosztu']
|
|
|
|
|
+ DBG::log(['msg'=> 'updateItem: $oldItem', $oldItem]);
|
|
|
|
|
+ if (!$oldItem) throw new Exception("BUG item '{$pk}' not found ({$this->_namespace})");
|
|
|
|
|
+ $sqlPatch = array();
|
|
|
|
|
+ if (array_key_exists('nr_faktury', $itemPatch) && $oldItem['nr_faktury'] != $itemPatch['nr_faktury']) {
|
|
|
|
|
+ $sqlPatch[ $this->getSqlFieldName('nr_faktury') ] = $itemPatch['nr_faktury'];
|
|
|
|
|
+ }
|
|
|
|
|
+ $nettoToUpdate = false;
|
|
|
|
|
+ $kwota = V::get('kwota', 0, $oldItem, 'price');
|
|
|
|
|
+ if (array_key_exists('kwota', $itemPatch) && $oldItem['kwota'] != $itemPatch['kwota']) {
|
|
|
|
|
+ $nettoToUpdate = true;
|
|
|
|
|
+ $kwota = V::get('kwota', 0, $itemPatch, 'price');
|
|
|
|
|
+ $sqlPatch[ $this->getSqlFieldName('kwota') ] = $kwota;
|
|
|
|
|
+ }
|
|
|
|
|
+ $vat = V::get('vat', 0, $oldItem, 'int');
|
|
|
|
|
+ if (array_key_exists('vat', $itemPatch) && $oldItem['vat'] != $itemPatch['vat']) {
|
|
|
|
|
+ $nettoToUpdate = true;
|
|
|
|
|
+ $vat = V::get('vat', 0, $itemPatch, 'int');
|
|
|
|
|
+ $sqlPatch[ $this->getSqlFieldName('vat') ] = $vat;
|
|
|
|
|
+ }
|
|
|
|
|
+ if ($nettoToUpdate) {
|
|
|
|
|
+ $sqlPatch[ $this->getSqlFieldName('kwota_netto') ] = ($kwota > 0 && $vat > 0)
|
|
|
|
|
+ ? $kwota / (1 + $vat / 100)
|
|
|
|
|
+ : 0;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (array_key_exists('kategoria_kosztu', $itemPatch) && $oldItem['kategoria_kosztu'] != $itemPatch['kategoria_kosztu']) {
|
|
|
|
|
+ $sqlPatch[ $this->getSqlFieldName('kategoria_kosztu') ] = $itemPatch['kategoria_kosztu'];
|
|
|
|
|
+ }
|
|
|
|
|
+ DBG::log(['msg'=> 'updateItem: $sqlPatch', $sqlPatch]);
|
|
|
|
|
+ if (empty($sqlPatch)) return 0;
|
|
|
|
|
+ return DB::getPDO()->update(
|
|
|
|
|
+ $this->getRootTableName(),
|
|
|
|
|
+ $this->getSqlPrimaryKeyField(),
|
|
|
|
|
+ $pk,
|
|
|
|
|
+ $sqlPatch
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function getItem($primaryKey, $params = []) {
|
|
|
|
|
+ $row = DB::getPDO()->fetchAll("
|
|
|
|
|
+ select t.*
|
|
|
|
|
+ from `ZALICZKA_POZYCJA` t
|
|
|
|
|
+ where t.ID = {$primaryKey}
|
|
|
|
|
+ ");
|
|
|
|
|
+ $row = (!empty($row)) ? reset($row) : null;
|
|
|
|
|
+ if (!$row) return null;
|
|
|
|
|
+ return $this->buildFromSqlRow($row, $params);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public function getItems($params = array()) {
|
|
public function getItems($params = array()) {
|
|
|
DBG::log(['msg'=> 'getItems', $params]);
|
|
DBG::log(['msg'=> 'getItems', $params]);
|
|
|
// $idUser = V::get('primaryKey', 0, $params['#refFrom'], 'int');
|
|
// $idUser = V::get('primaryKey', 0, $params['#refFrom'], 'int');
|
|
@@ -81,12 +141,17 @@ class Schema_DefaultDb_zaliczka_pozycja_ZaliczkaPozycjaStorageAcl extends Core_A
|
|
|
// ) ";
|
|
// ) ";
|
|
|
}
|
|
}
|
|
|
$sqlWhere = (!empty($sqlWhereAnd)) ? implode(" and ", $sqlWhereAnd) : "1=1";
|
|
$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
|
|
|
|
|
- ");
|
|
|
|
|
|
|
+ return array_map(
|
|
|
|
|
+ function ($row) use ($params) {
|
|
|
|
|
+ return $this->buildFromSqlRow($row, $params);
|
|
|
|
|
+ },
|
|
|
|
|
+ DB::getPDO()->fetchAll("
|
|
|
|
|
+ select z.*
|
|
|
|
|
+ from ZALICZKA_POZYCJA z
|
|
|
|
|
+ where {$sqlWhere}
|
|
|
|
|
+ order by z.ID ASC
|
|
|
|
|
+ ")
|
|
|
|
|
+ );
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|