|
|
@@ -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'] ]);
|
|
|
+ // }
|
|
|
}
|
|
|
}
|
|
|
|