From: root Date: Thu, 3 Aug 2023 16:39:11 +0000 (+0200) Subject: Continued on MVC to edit transaction X-Git-Url: https://git.ebersold.fr/?a=commitdiff_plain;h=8410aa5d39e0e212deac1041cfaf84af75ef1547;p=www%2Fsyndic.git Continued on MVC to edit transaction --- diff --git a/app/compta/controlers/transaction.php b/app/compta/controlers/transaction.php index eb39a65..165ffb6 100644 --- a/app/compta/controlers/transaction.php +++ b/app/compta/controlers/transaction.php @@ -39,7 +39,7 @@ class Transaction { } - public function remove() + public function remove($_id) { } @@ -57,8 +57,12 @@ class Transaction { } - public function update() + public function update($_id) { + require_once(controler::$basedir."/views/transaction_update.php"); + $this->_model->get($_id); + $page = new \compta\views\transaction\Update($this->_model); + return $page; } } diff --git a/app/compta/models/transaction.php b/app/compta/models/transaction.php index 3a8bbbb..f85cad8 100644 --- a/app/compta/models/transaction.php +++ b/app/compta/models/transaction.php @@ -7,6 +7,85 @@ require_once(dirname(__FILE__)."/../api_booking.php"); require_once(dirname(__FILE__)."/../api_pcmn.php"); require_once(dirname(__FILE__)."/../api_retrieve.php"); +//SELECT trans_id,voucher_ref,voucher_date,act_trans_date,trans_label +class Transaction implements \JsonSerializable +{ + /* Order is important don't change */ + public $id = -1; + public $voucher_ref = -1; + public $voucher_date = "2022-01-01"; // Could be HA, AN, what ever + public $trans_date = ""; // Account name + public $trans_label = ""; // Debit or credit + + /** + * Build entry from SQL request Retrieve getTransaction + */ + public function __construct($c = null) + { + if ($c != null) + { + $i = 0; + foreach( get_object_vars($this) as $k => $v) + { $this->{$k} = $c[$i++]; } + } + } + /** + * Required by JsonSerializable + */ + public function jsonSerialize() + { + return [ + 'id' => $this->id + , 'voucher_date' => $this->voucher_date + , 'voucher_ref' => $this->voucher_ref + , 'trans_date' => $this->trans_date + , 'trans_label' => $this->trans_label + ]; + } +}; + + +class Entry implements \JsonSerializable +{ + // $arr = Array("id","acc_id","acc_name","entry_type","amount_debit","amount_credit"); + // trans_entry_id,entry_date,te.acc_id,acc.acc_name,debit_credit,amount,te.entry_type + /* Order is important don't change */ + public $id = -1; + public $entry_date = "2022-01-01"; // Could be HA, AN, what ever + public $acc_id = -1; + public $acc_name = ""; // Account name + public $dc = "d"; // Debit or credit + public $amount = 0.0; + public $entry_type = "BQ"; // Could be HA, AN, what ever + + /** + * Build entry from SQL request Retrieve getTransaction + */ + public function __construct($c = null) + { + if ($c != null) + { + $i = 0; + foreach( get_object_vars($this) as $k => $v) + { $this->{$k} = $c[$i++]; } + } + } + /** + * Required by JsonSerializable + */ + public function jsonSerialize() + { + return [ + 'id' => $this->id + , 'entry_date' => $this->entry_date + , 'entry_type' => $this->entry_type + , 'acc_id' => $this->acc_id + , 'amount' => $this->amount + , 'dc' => $this->dc + , 'acc_name' => $this->acc_name]; + } +}; + /** * @brief Data model for a transaction. */ @@ -17,6 +96,8 @@ class Model implements \JsonSerializable private $_entries; + public $_id; + public $_mouvements; /** * Constructor */ @@ -42,7 +123,16 @@ class Model implements \JsonSerializable $r = $pcmn->getTransaction( $_id); // Get Transaction $this->_id = $_id; $this->_mouvements = $r['entries']; - $this->_summary = $r['transaction']; + foreach($r['entries'] as $e) + { + $this->_entries[] = new Entry($e); + } + $this->_summary = new Transaction($r['transaction']); + } + + public function getEntries() + { + return $this->_entries; } /** * Required by JsonSerializable diff --git a/app/compta/pages.php b/app/compta/pages.php index 1644fe2..b4e8ea6 100644 --- a/app/compta/pages.php +++ b/app/compta/pages.php @@ -117,7 +117,7 @@ class PageCompta extends AppPage { } else { // Get attribute directly from object model - return $model->{$value->getAttribute("asp-for")}; + return $model->{$asp}; } } /** diff --git a/app/compta/services.php b/app/compta/services.php index 4c45db3..31978b5 100644 --- a/app/compta/services.php +++ b/app/compta/services.php @@ -103,6 +103,7 @@ $r->get('/transaction',"transaction#index")->setRoot($ctrl_dir); $r->get('/transaction/',"transaction#index")->setRoot($ctrl_dir); $r->get('/transaction/nouveau',"transaction#nouveau")->setRoot($ctrl_dir); $r->get('/transaction/detail/?:id',"transaction#detail")->setRoot($ctrl_dir); +$r->get('/transaction/remove/?:id',"transaction#remove")->setRoot($ctrl_dir); $r->get('/transaction/update/?:id',"transaction#update")->setRoot($ctrl_dir); $r->post('/transaction/updatePost',"transaction#updatePost")->setRoot($ctrl_dir); diff --git a/app/compta/views/transaction_detail.php b/app/compta/views/transaction_detail.php index 7bbddb1..9cdd649 100644 --- a/app/compta/views/transaction_detail.php +++ b/app/compta/views/transaction_detail.php @@ -46,6 +46,10 @@ const XmlAccount =<< + + +
@@ -104,9 +108,14 @@ _EOF; */ protected function _updateXML(&$xml) { - $sum = $this->_model->_summary; + $buttons=<<<_EOF + + + +_EOF; + $sum = $this->_model->_summary->jsonSerialize(); $fields= Array('title','date','voucher_ref','voucher_date'); - $values= Array($sum[4],$sum[3],$sum[1],$sum[2]); + $values= Array($sum['trans_label'],$sum['trans_date'],$sum['voucher_ref'],$sum['voucher_date']); $tbody = $xml->getElementsByTagName('tbody'); $f = $tbody->item(0); $nel = $xml->createDocumentFragment(); @@ -124,10 +133,11 @@ _EOF; $retour = $this->getElementById($xml,"btRetour"); $retour->removeAttribute('link'); $retour->setAttribute('link',"/app/compta/services.php/".\AEB::$REQUEST['b']); - // Ok Handle solde - //$solde = $this->getElementById($xml,"accSoldeCompte"); - //$el = $xml->createTextNode("compte ".$this->_model->_solde[2]); - //$solde->appendChild($el); + // Ok Handle buttons + $panelButtons= $this->getElementById($xml,"pButtons"); + $nel = $xml->createDocumentFragment(); + $nel->appendXML($buttons); + $panelButtons->appendChild($nel); } /** diff --git a/app/compta/views/transaction_update.php b/app/compta/views/transaction_update.php new file mode 100644 index 0000000..bd92184 --- /dev/null +++ b/app/compta/views/transaction_update.php @@ -0,0 +1,210 @@ + + + + + +Gestion comptable + + + + + + + + + +
+ +
+
+XML; + + +/** + * @brief Update GUI with the list of + * documents available. All decomptes + */ +class Update extends \PageCompta + implements \IActionResult +{ + private $_model; + + function __construct($model) + { + $this->_model = $model; + parent::__construct(xmlTransactionUpdate,true); + } + + public function render() + { + $this->show(); + } + + /** + * @brief insert a script in the page to update menu link + * + */ + private function script($loc = "/app/compta/services.php/") + { + $s=<<<_EOF + +_EOF; + echo $s; + } + /** + * @brief allow sub classes to modify xml file + */ + protected function _updateXML(&$xml) + { + // Update the title + $tbody = $xml->getElementsByTagName("tbody"); + $nel = $xml->createDocumentFragment(); + $nel->appendXML($this->fillEntries()); + $tbody->item(0)->appendChild($nel); + /* Update menu */ + $tbody = $xml->getElementsByTagName('menu'); + $f = $tbody->item(0); + $items =<<<_EOF + +_EOF; + $frag=sprintf($items + ,$this->_model->_id); + $nel = $xml->createDocumentFragment(); + $nel->appendXML($frag); + $f->appendChild($nel); + // Update asp for fields + $this->updateAspfor($xml,$this->_model); + } + + private function fillEntries() + { + $model = $this->_model; + $count = 0; + $frag = ""; + //trans_entry_id,entry_date,te.acc_id,acc.acc_name,debit_credit,amount,te.entry_type + $arr = Array("id","acc_id","acc_name","entry_type","amount_debit","amount_credit"); + $tplt =<<<_EOF + +_EOF; + $tplt_ro =<<<_EOF + +_EOF; + // Add some empty entries to fill the gap. + $entries = $model->getEntries(); + $ce = count($model->getEntries()); + if ($count < 8 ) + { + for ($i = 8 - $ce ; $i > 0 ; $i--) + { $entries[] = new \compta\models\transaction\Entry(); } + + } + foreach($entries as $e) + { + $i = 0; + $fe = ""; + foreach($arr as $f) + { + if ($f == "amount_debit" ) + { + if ($e->dc == 'd') + { + $fe.=sprintf($tplt,"text",$count,$f,$e->amount); + } else { + $fe.=sprintf($tplt,"text",$count,$f,"0.0"); + } + } else if ($f == "id") + { + $fe.=sprintf($tplt,"hidden",$count,$f,$e->{$f}); + } else if ($f == "amount_credit") + { + if ($e->dc == 'c') + { + $fe.=sprintf($tplt,"text",$count,$f,$e->amount); + } else { + $fe.=sprintf($tplt,"text",$count,$f,"0.0"); + } + } else if ($f == "acc_name") + { + $fe.=sprintf($tplt_ro,"text",$count,$f,$e->{$f}); + } else + $fe.=sprintf($tplt,"text",$count,$f,$e->{$f}); + } + $fe.=""; + $frag.=$fe; + $count++; + } + return $frag; + } +} + +?>