|
@@ -8,98 +8,67 @@ class Schema_DefaultDb_zaliczka_ZaliczkaStorageAcl extends Core_AclSimpleSchemaB
|
|
|
public $_simpleSchema = [
|
|
public $_simpleSchema = [
|
|
|
'root' => [
|
|
'root' => [
|
|
|
'@namespace' => 'default_db/ZALICZKA/Zaliczka',// Api_WfsNs::getBaseWfsUri() . '/default_db/Zaliczka'
|
|
'@namespace' => 'default_db/ZALICZKA/Zaliczka',// Api_WfsNs::getBaseWfsUri() . '/default_db/Zaliczka'
|
|
|
- 'id' => 'xsd:integer',
|
|
|
|
|
|
|
+ '@primaryKey' => 'id',
|
|
|
|
|
+ 'id' => [ '@type' => 'xsd:integer', '@alias' => 'ID' ],
|
|
|
'created' => [ '@type' => 'xsd:date', '@alias' => 'A_RECORD_CREATE_DATE' ],
|
|
'created' => [ '@type' => 'xsd:date', '@alias' => 'A_RECORD_CREATE_DATE' ],
|
|
|
'worker' => [ '@ref' => 'default_objects/AccessOwner' ],// 'alias_ref:default_objects:AccessOwner'
|
|
'worker' => [ '@ref' => 'default_objects/AccessOwner' ],// 'alias_ref:default_objects:AccessOwner'
|
|
|
- // 'worker' => [ '@ref' => 'Worker' ],
|
|
|
|
|
- 'kwota' => [ '@type' => 'xsd:decimal', '@totalDigits' => 16, '@fractionDigits' => 2 ],
|
|
|
|
|
- 'nierozliczona_kwota' => [ '@type' => 'xsd:decimal', '@totalDigits' => 16, '@fractionDigits' => 2 ],
|
|
|
|
|
|
|
+ 'kwota' => [ '@type' => 'xsd:decimal', '@totalDigits' => 16, '@fractionDigits' => 2, '@alias' => 'KWOTA' ],
|
|
|
|
|
+ 'nierozliczona_kwota' => [ '@type' => 'xsd:decimal', '@totalDigits' => 16, '@fractionDigits' => 2, '@alias' => 'NIEROZLICZONA_KWOTA' ],
|
|
|
'pozycja' => [ '@ref' => 'default_db/ZALICZKA_POZYCJA/ZaliczkaPozycja', '@maxOccurs' => 'unbounded' ]
|
|
'pozycja' => [ '@ref' => 'default_db/ZALICZKA_POZYCJA/ZaliczkaPozycja', '@maxOccurs' => 'unbounded' ]
|
|
|
],
|
|
],
|
|
|
- // 'ZaliczkaPozycja' => [
|
|
|
|
|
- // '@namespace' => 'default_db/ZALICZKA_POZYCJA/ZaliczkaPozycja',// Api_WfsNs::getBaseWfsUri() . '/default_db/Zaliczka'
|
|
|
|
|
- // 'id' => 'xsd:integer',
|
|
|
|
|
- // 'kwota' => [ '@type' => 'xsd:decimal', '@totalDigits' => 16, '@fractionDigits' => 2 ],
|
|
|
|
|
- // 'korespondencja' => [ '@ref' => 'Korespondencja' ],
|
|
|
|
|
- // 'projekt' => [ '@ref' => 'Projekt' ]
|
|
|
|
|
- // ],
|
|
|
|
|
- 'Korespondencja' => [
|
|
|
|
|
- '@namespace' => 'default_db/IN7_DZIENNIK_KORESP',
|
|
|
|
|
- 'id' => [ '@type' => 'xsd:integer', '@alias' => 'ID' ],
|
|
|
|
|
- 'title' => [ '@type' => 'xsd:string', '@alias' => 'K_ZAWARTOS' ],
|
|
|
|
|
- 'kategoriaKosztu' => [ '@type' => 'xsd:string', '@alias' => 'KATEGORIA_KOSZTU' ]
|
|
|
|
|
- ],
|
|
|
|
|
- 'Projekt' => [
|
|
|
|
|
- '@namespace' => 'default_db/IN7_MK_BAZA_DYSTRYBUCJI',
|
|
|
|
|
- 'id' => [ '@type' => 'xsd:integer', '@alias' => 'ID' ],
|
|
|
|
|
- 'nrBudowy' => [ '@type' => 'xsd:string', '@alias' => 'M_DIST_DEALNUM' ],// TODO: ? M_DIST_DESC (szerszy opis)
|
|
|
|
|
- ],
|
|
|
|
|
- // 'worker' => [
|
|
|
|
|
- // '@namespace' => 'default_objects/AccessOwner',
|
|
|
|
|
- // 'login' => 'xsd:string',
|
|
|
|
|
- // 'name' => 'xsd:string'
|
|
|
|
|
- // ]
|
|
|
|
|
];
|
|
];
|
|
|
- // [
|
|
|
|
|
- // '@typeName' => 'default_db__x3A__ZALICZKA:Zaliczka',
|
|
|
|
|
- // '@baseTypeName' => 'default_db:ZALICZKA',
|
|
|
|
|
- // '@namespace' => 'default_db/ZALICZKA/Zaliczka',// Api_WfsNs::getBaseWfsUri() . '/default_db/Zaliczka'
|
|
|
|
|
- // 'id' => 'xsd:integer',
|
|
|
|
|
- // 'created' => 'xsd:date',
|
|
|
|
|
- // 'worker' => [
|
|
|
|
|
- // '@namespace' => 'default_objects/AccessOwner',// alias_ref:default_objects:AccessOwner
|
|
|
|
|
- // ],
|
|
|
|
|
- // 'kwota' => 'xsd:decimal',
|
|
|
|
|
- // 'pozycja' => [
|
|
|
|
|
- // '@namespace' => 'default_db/ZALICZKA_POZYCJA/ZaliczkaPozycja',// alias_ref:default_db__x3A__ZALICZKA_POZYCJA:ZaliczkaPozycja
|
|
|
|
|
- // '@maxOccurs' => 'unbounded',
|
|
|
|
|
- // // 'id' => 'xsd:integer',
|
|
|
|
|
- // // 'kwota' => 'xsd:decimal',
|
|
|
|
|
- // // 'korespondencja' => [// 'ref:korespondencja'
|
|
|
|
|
- // // '@namespace' => 'default_db/IN7_DZIENNIK_KORESP',
|
|
|
|
|
- // // 'id' => 'xsd:integer',
|
|
|
|
|
- // // 'title' => 'xsd:string',
|
|
|
|
|
- // // 'kategoriaKosztu' => 'xsd:string'
|
|
|
|
|
- // // ],
|
|
|
|
|
- // // 'projekt' => [// 'ref:projekt'
|
|
|
|
|
- // // '@namespace' => 'default_db/IN7_MK_BAZA_DYSTRYBUCJI',
|
|
|
|
|
- // // 'id' => 'xsd:integer',
|
|
|
|
|
- // // 'nrBudowy' => 'xsd:string'
|
|
|
|
|
- // // ]
|
|
|
|
|
- // ]
|
|
|
|
|
- // ];
|
|
|
|
|
|
|
|
|
|
public function getTotal($params = array()) {
|
|
public function getTotal($params = array()) {
|
|
|
- return 10;
|
|
|
|
|
|
|
+ if (!isset($params['#refFrom'])) {
|
|
|
|
|
+ throw new Exception("Missing param #refFrom/primaryKey (id user)");
|
|
|
|
|
+ }
|
|
|
|
|
+ $idUser = V::get('primaryKey', 0, $params['#refFrom'], 'int');
|
|
|
|
|
+ return DB::getPDO()->fetchValue("
|
|
|
|
|
+ select count(*) as cnt
|
|
|
|
|
+ from ZALICZKA z
|
|
|
|
|
+ join ADMIN_USERS u on(z.L_APPOITMENT_USER = u.ADM_ACCOUNT and u.ID = {$idUser})
|
|
|
|
|
+ ");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function getItems($params = array()) {
|
|
public function getItems($params = array()) {
|
|
|
- return [
|
|
|
|
|
- [ 'id'=>1, 'created' => date("Y-m-d") ],
|
|
|
|
|
- [ 'id'=>2, 'created' => date("Y-m-d") ],
|
|
|
|
|
- ];
|
|
|
|
|
|
|
+ // '#refFrom' => [
|
|
|
|
|
+ // 'namespace' => 'default_db__x3A__ADMIN_USERS/Worker',
|
|
|
|
|
+ // 'primaryKey' => $idUser
|
|
|
|
|
+ // ]
|
|
|
|
|
+ if (!isset($params['#refFrom'])) {
|
|
|
|
|
+ throw new Exception("Missing param #refFrom/primaryKey (id user)");
|
|
|
|
|
+ }
|
|
|
|
|
+ $idUser = V::get('primaryKey', 0, $params['#refFrom'], 'int');
|
|
|
|
|
+ return DB::getPDO()->fetchAll("
|
|
|
|
|
+ select z.*
|
|
|
|
|
+ from ZALICZKA z
|
|
|
|
|
+ join ADMIN_USERS u on(z.L_APPOITMENT_USER = u.ADM_ACCOUNT and u.ID = {$idUser})
|
|
|
|
|
+ order by z.ID DESC
|
|
|
|
|
+ ");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function addItem($itemTodo) {
|
|
public function addItem($itemTodo) {
|
|
|
// TODO: btn "Dodaj Zaliczkę" $acl->addItem($item); // @require only 'worker' => [ 'id', 'login', 'name' ]
|
|
// TODO: btn "Dodaj Zaliczkę" $acl->addItem($item); // @require only 'worker' => [ 'id', 'login', 'name' ]
|
|
|
- DBG::nicePrint($itemTodo, '$itemTodo');// TODO: DBG
|
|
|
|
|
|
|
+ $DBG = V::get('DBG', '', $_GET);
|
|
|
|
|
+ if($DBG){DBG::nicePrint($itemTodo, '$itemTodo');}
|
|
|
|
|
|
|
|
if (!is_array($itemTodo) || empty($itemTodo['worker'])) throw new Exception("Missing worker");
|
|
if (!is_array($itemTodo) || empty($itemTodo['worker'])) throw new Exception("Missing worker");
|
|
|
if (empty($itemTodo['worker']['id'])) throw new Exception("Missing worker id");
|
|
if (empty($itemTodo['worker']['id'])) throw new Exception("Missing worker id");
|
|
|
$idUser = intval($itemTodo['worker']['id']);
|
|
$idUser = intval($itemTodo['worker']['id']);
|
|
|
if ($idUser <= 0) throw new Exception("Wrong worker id");
|
|
if ($idUser <= 0) throw new Exception("Wrong worker id");
|
|
|
|
|
|
|
|
|
|
+ // TODO: use default_objects/AccessOwner -> getItem($idUser)
|
|
|
$userLogin = DB::getPDO()->fetchValue("
|
|
$userLogin = DB::getPDO()->fetchValue("
|
|
|
select u.ADM_ACCOUNT
|
|
select u.ADM_ACCOUNT
|
|
|
from `ADMIN_USERS` u
|
|
from `ADMIN_USERS` u
|
|
|
where u.ID = {$idUser}
|
|
where u.ID = {$idUser}
|
|
|
");
|
|
");
|
|
|
if (empty($userLogin)) throw new Exception("User not exists ID={$idUser}");
|
|
if (empty($userLogin)) throw new Exception("User not exists ID={$idUser}");
|
|
|
- DBG::nicePrint($userLogin, '$userLogin');// TODO: DBG
|
|
|
|
|
|
|
+ if($DBG){DBG::nicePrint($userLogin, '$userLogin');}
|
|
|
|
|
|
|
|
$idTransaction = Core_AclHelper::startTransaction('ZALICZKA', $idUser, $userLogin);
|
|
$idTransaction = Core_AclHelper::startTransaction('ZALICZKA', $idUser, $userLogin);
|
|
|
|
|
|
|
|
- $zaliczkaRefWorker = Core_AclHelper::getRefTable('Zaliczka', 'worker');// `Zaliczka__#REF__worker`
|
|
|
|
|
|
|
+ $zaliczkaRefWorker = ACL::getRefTable('default_db/ZALICZKA/Zaliczka', 'worker');
|
|
|
$idActiveZaliczka = DB::getPDO()->fetchValue("
|
|
$idActiveZaliczka = DB::getPDO()->fetchValue("
|
|
|
select MAX(t.ID)
|
|
select MAX(t.ID)
|
|
|
from `ZALICZKA` t
|
|
from `ZALICZKA` t
|
|
@@ -109,8 +78,7 @@ class Schema_DefaultDb_zaliczka_ZaliczkaStorageAcl extends Core_AclSimpleSchemaB
|
|
|
where r.ID = {$idUser}
|
|
where r.ID = {$idUser}
|
|
|
and t.A_STATUS in('WAITING', 'NORMAL') -- TODO cache use #INSTANCE table
|
|
and t.A_STATUS in('WAITING', 'NORMAL') -- TODO cache use #INSTANCE table
|
|
|
");
|
|
");
|
|
|
- $zaliczkaRefWorker = Core_AclHelper::getRefTable('Zaliczka', 'worker');// `Zaliczka__#REF__worker`
|
|
|
|
|
- DBG::nicePrint("
|
|
|
|
|
|
|
+ if($DBG){DBG::nicePrint("
|
|
|
select MAX(t.ID)
|
|
select MAX(t.ID)
|
|
|
from `ZALICZKA` t
|
|
from `ZALICZKA` t
|
|
|
-- join `ADMIN_USERS` u on(t.L_APPOITMENT_USER = u.ADM_ACCOUNT)
|
|
-- join `ADMIN_USERS` u on(t.L_APPOITMENT_USER = u.ADM_ACCOUNT)
|
|
@@ -118,12 +86,12 @@ class Schema_DefaultDb_zaliczka_ZaliczkaStorageAcl extends Core_AclSimpleSchemaB
|
|
|
left join `ADMIN_USERS` r on(r.ID = ref.REMOTE_PRIMARY_KEY)
|
|
left join `ADMIN_USERS` r on(r.ID = ref.REMOTE_PRIMARY_KEY)
|
|
|
where r.ID = {$idUser}
|
|
where r.ID = {$idUser}
|
|
|
and t.A_STATUS in('WAITING', 'NORMAL') -- TODO cache use #INSTANCE table
|
|
and t.A_STATUS in('WAITING', 'NORMAL') -- TODO cache use #INSTANCE table
|
|
|
- ", 'sql');// TODO: DBG
|
|
|
|
|
- DBG::nicePrint($idActiveZaliczka, '$idActiveZaliczka');// TODO: DBG
|
|
|
|
|
|
|
+ ", 'sql');}
|
|
|
|
|
+ if($DBG){DBG::nicePrint($idActiveZaliczka, '$idActiveZaliczka');}
|
|
|
|
|
|
|
|
$userSaldo = 0;
|
|
$userSaldo = 0;
|
|
|
if ($idActiveZaliczka > 0) {
|
|
if ($idActiveZaliczka > 0) {
|
|
|
- $zaliczkaRefPozycja = Core_AclHelper::getRefTable('Zaliczka', 'pozycja');// `Zaliczka__#REF__pozycja`
|
|
|
|
|
|
|
+ $zaliczkaRefPozycja = ACL::getRefTable('default_db/ZALICZKA/Zaliczka', 'pozycja');
|
|
|
$userSaldo = DB::getPDO()->fetchValue("
|
|
$userSaldo = DB::getPDO()->fetchValue("
|
|
|
select t.KWOTA + t.NIEROZLICZONA_KWOTA - sum(r.KWOTA)
|
|
select t.KWOTA + t.NIEROZLICZONA_KWOTA - sum(r.KWOTA)
|
|
|
from `ZALICZKA` t
|
|
from `ZALICZKA` t
|
|
@@ -131,7 +99,7 @@ class Schema_DefaultDb_zaliczka_ZaliczkaStorageAcl extends Core_AclSimpleSchemaB
|
|
|
left join `ZALICZKA_POZYCJA` r on(r.ID = ref.REMOTE_PRIMARY_KEY)
|
|
left join `ZALICZKA_POZYCJA` r on(r.ID = ref.REMOTE_PRIMARY_KEY)
|
|
|
where t.ID = {$idActiveZaliczka}
|
|
where t.ID = {$idActiveZaliczka}
|
|
|
");
|
|
");
|
|
|
- DBG::nicePrint($userSaldo, '$userSaldo');// TODO: DBG
|
|
|
|
|
|
|
+ if($DBG){DBG::nicePrint($userSaldo, '$userSaldo');}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
$usrLogin = User::getLogin();
|
|
$usrLogin = User::getLogin();
|
|
@@ -143,9 +111,9 @@ class Schema_DefaultDb_zaliczka_ZaliczkaStorageAcl extends Core_AclSimpleSchemaB
|
|
|
from ADMIN_USERS u
|
|
from ADMIN_USERS u
|
|
|
where u.ID = {$idUser}
|
|
where u.ID = {$idUser}
|
|
|
");
|
|
");
|
|
|
- DBG::nicePrint($execRet, '$execRet');// TODO: DBG
|
|
|
|
|
|
|
+ if($DBG){DBG::nicePrint($execRet, '$execRet');}
|
|
|
$id = DB::getPDO()->lastInsertId();
|
|
$id = DB::getPDO()->lastInsertId();
|
|
|
- DBG::nicePrint($id, '$id');// TODO: DBG
|
|
|
|
|
|
|
+ if($DBG){DBG::nicePrint($id, '$id');}
|
|
|
if (!$id) throw new Exception("Wystąpiły błędy podczas dodawania Zaliczki do bazy danych");
|
|
if (!$id) throw new Exception("Wystąpiły błędy podczas dodawania Zaliczki do bazy danych");
|
|
|
|
|
|
|
|
DB::getPDO()->exec("
|
|
DB::getPDO()->exec("
|
|
@@ -160,7 +128,7 @@ class Schema_DefaultDb_zaliczka_ZaliczkaStorageAcl extends Core_AclSimpleSchemaB
|
|
|
where z.ID != {$id}
|
|
where z.ID != {$id}
|
|
|
and z.L_APPOITMENT_USER = '{$userLogin}'
|
|
and z.L_APPOITMENT_USER = '{$userLogin}'
|
|
|
") as $instance) {
|
|
") as $instance) {
|
|
|
- DBG::nicePrint($instance, '$instance');// TODO: DBG
|
|
|
|
|
|
|
+ if($DBG){DBG::nicePrint($instance, '$instance');}
|
|
|
|
|
|
|
|
// FIX Instance name
|
|
// FIX Instance name
|
|
|
foreach (DB::getPDO()->fetchAll("
|
|
foreach (DB::getPDO()->fetchAll("
|
|
@@ -172,7 +140,7 @@ class Schema_DefaultDb_zaliczka_ZaliczkaStorageAcl extends Core_AclSimpleSchemaB
|
|
|
where z.ID != {$id}
|
|
where z.ID != {$id}
|
|
|
and z.L_APPOITMENT_USER = '{$userLogin}'
|
|
and z.L_APPOITMENT_USER = '{$userLogin}'
|
|
|
") as $instance) {
|
|
") as $instance) {
|
|
|
- DBG::nicePrint($instance, '$instance');// TODO: DBG
|
|
|
|
|
|
|
+ if($DBG){DBG::nicePrint($instance, '$instance');}
|
|
|
if (!$instance['has_instance']) {
|
|
if (!$instance['has_instance']) {
|
|
|
DB::getPDO()->exec("
|
|
DB::getPDO()->exec("
|
|
|
insert into `ZALICZKA__#INSTANCE_HIST` (PRIMARY_KEY, INSTANCE_NAME)
|
|
insert into `ZALICZKA__#INSTANCE_HIST` (PRIMARY_KEY, INSTANCE_NAME)
|
|
@@ -216,27 +184,17 @@ class Schema_DefaultDb_zaliczka_ZaliczkaStorageAcl extends Core_AclSimpleSchemaB
|
|
|
return $id;
|
|
return $id;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public function getItem($primaryKey) {
|
|
|
|
|
|
|
+ public function getItem($primaryKey, $params = []) {
|
|
|
$zaliczkaRaw = DB::getPDO()->fetchAll("
|
|
$zaliczkaRaw = DB::getPDO()->fetchAll("
|
|
|
select t.*
|
|
select t.*
|
|
|
from `ZALICZKA` t
|
|
from `ZALICZKA` t
|
|
|
where t.ID = {$primaryKey}
|
|
where t.ID = {$primaryKey}
|
|
|
");
|
|
");
|
|
|
$zaliczkaRaw = (!empty($zaliczkaRaw)) ? reset($zaliczkaRaw) : null;
|
|
$zaliczkaRaw = (!empty($zaliczkaRaw)) ? reset($zaliczkaRaw) : null;
|
|
|
- DBG::nicePrint($zaliczkaRaw, '$zaliczkaRaw');
|
|
|
|
|
|
|
+ // DBG::nicePrint($zaliczkaRaw, '$zaliczkaRaw');
|
|
|
if (!$zaliczkaRaw) return null;
|
|
if (!$zaliczkaRaw) return null;
|
|
|
-
|
|
|
|
|
- foreach ($this->_simpleSchema['root'] as $fieldName => $field) {
|
|
|
|
|
- if ('@' == substr($fieldName, 0, 1)) continue;
|
|
|
|
|
- DBG::nicePrint($field, '$field['.$fieldName.']');
|
|
|
|
|
- if (!empty($field['@type'])) {
|
|
|
|
|
- UI::alert('warning', "TODO: field({$fieldName}) type({$field['@type']})");
|
|
|
|
|
- } else if (!empty($field['@ref'])) {
|
|
|
|
|
- UI::alert('warning', "TODO: field({$fieldName}) get ref table -> fetch value/s -> fetch HIST");
|
|
|
|
|
- } else {
|
|
|
|
|
- throw new Exception("Schema error for field '{$fieldName}'");
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ $filterCols = $this->getParamCols($params);
|
|
|
|
|
+ return $this->buildFromSqlRow($zaliczkaRaw, $params);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function reinstall() {
|
|
public function reinstall() {
|
|
@@ -308,10 +266,10 @@ class Schema_DefaultDb_zaliczka_ZaliczkaStorageAcl extends Core_AclSimpleSchemaB
|
|
|
) ENGINE=MyISAM DEFAULT CHARSET=latin2;
|
|
) ENGINE=MyISAM DEFAULT CHARSET=latin2;
|
|
|
");
|
|
");
|
|
|
|
|
|
|
|
- Core_AclHelper::getRefTable('Zaliczka', 'worker');// `ZaliczkaPozycja__#REF__worker`
|
|
|
|
|
- Core_AclHelper::getRefTable('Zaliczka', 'pozycja');// `Zaliczka__#REF__pozycja`
|
|
|
|
|
- Core_AclHelper::getRefTable('ZaliczkaPozycja', 'korespondencja');// `ZaliczkaPozycja__#REF__Kkorespondencja`
|
|
|
|
|
- Core_AclHelper::getRefTable('ZaliczkaPozycja', 'projekt');// `ZaliczkaPozycja__#REF__projekt`
|
|
|
|
|
|
|
+ ACL::getRefTable('default_db/ZALICZKA/Zaliczka', 'worker');
|
|
|
|
|
+ ACL::getRefTable('default_db/ZALICZKA/Zaliczka', 'pozycja');
|
|
|
|
|
+ ACL::getRefTable('default_db/ZALICZKA_POZYCJA/ZaliczkaPozycja', 'projekt');
|
|
|
|
|
+ ACL::getRefTable('default_db/ZALICZKA_POZYCJA/ZaliczkaPozycja', 'korespondencja');
|
|
|
|
|
|
|
|
Core_AclHelper::getInstanceTable('ZALICZKA');// `ZALICZKA__#INSTANCE`
|
|
Core_AclHelper::getInstanceTable('ZALICZKA');// `ZALICZKA__#INSTANCE`
|
|
|
// TODO: ZaliczkaOczekujaca A_STATUS = WAITING -- dodane przez pracownika
|
|
// TODO: ZaliczkaOczekujaca A_STATUS = WAITING -- dodane przez pracownika
|