From: www-data Date: Tue, 30 May 2023 14:39:31 +0000 (+0200) Subject: Started Transaction MVC. Detail of transaction X-Git-Url: https://git.ebersold.fr/?a=commitdiff_plain;h=976703706d7f493fdba09d17a655768f6e1a3c88;p=www%2Fsyndic.git Started Transaction MVC. Detail of transaction --- diff --git a/app/compta/api_retrieve.php b/app/compta/api_retrieve.php index b9cad96..7cd524d 100644 --- a/app/compta/api_retrieve.php +++ b/app/compta/api_retrieve.php @@ -74,6 +74,8 @@ _EOF; debit_credit enum ('d','c'), description VARCHAR(255), voucher_ref VARCHAR(255) + @return Array( transaction : Array(transId,voucher_ref,voucher_date,act_transdate,trans_label) + entries : Array(tras_ent_id,entry_date,acc_id,acc_name_,debit_credit,amount,te_type) */ function getTransaction($id) { $period = $this->getCurrentExercice(); @@ -84,7 +86,7 @@ SELECT trans_id,voucher_ref,voucher_date,act_trans_date,trans_label _EOF; $transaction = $this->doQueryI($q); $q =<<<_EOF -SELECT trans_entry_id,entry_date,te.acc_id,acc.acc_name,debit_credit,amount +SELECT trans_entry_id,entry_date,te.acc_id,acc.acc_name,debit_credit,amount,te.entry_type FROM TransactionEntry AS te JOIN Account AS acc ON acc.acc_id = te.acc_id WHERE trans_id ='{$id};' @@ -235,12 +237,15 @@ EOF; /** * * @param array $opt Option array like limit, offset + * + * @return Array( entries : Array(Date,Ref,Designation,Debit,Credit,TransId) , solde : Array()) + * */ function getEntriesByAccount($period,$acc,$opt) { $q = 'call detail_compte_sans_solde("'.$period.'",'.$acc.');'; $res = $this->doQueryI($q); if ($res['total_matches'] == 0) { - return array('entries'=> array(array(0,0,0,0,0)),'solde' =>array(0,0,0)); + return array('entries'=> array(array(0,0,0,0,0,0)),'solde' =>array(0,0,0)); } // return $res['records']; $q = 'CALL solde_compte("'.$period.'","'.$acc.'");'; diff --git a/app/compta/controlers/transaction.php b/app/compta/controlers/transaction.php index 689e8c8..eb39a65 100644 --- a/app/compta/controlers/transaction.php +++ b/app/compta/controlers/transaction.php @@ -3,37 +3,61 @@ namespace compta\controlers; require_once(dirname(__FILE__)."/../controler_base.php"); +require_once(controler::$basedir."/../../phplib/iface.ActionResult.php"); +require_once(controler::$basedir."/../../phplib/class.ActionResults.php"); +require_once(controler::$basedir."/session.php"); +require_once(controler::$basedir."/models/transaction.php"); + + /** * @brief Transaction controler. * I'm missing the Transaction Model */ class Transaction { + private $_model = null; + private $_session = null; + private $_auth_cfg = null; + /** + * Constructor + */ + public function __construct() + { + GLOBAL $conf; + $conf_auth = $conf['auth']['mysql']; + $this->_session = new \SessionCompta($conf_auth,$conf_auth['req_file']); + $this->_auth_cfg = $conf['auth']['mysql']; + $this->_model = new \compta\models\transaction\Model($this->_session,$this->_auth_cfg); + } /** * method post add transaction. * The post method is actually a json encoded request. * I might need to review * */ - public add() + public function add() { } - public remove() + public function remove() { } - public detail() + public function detail($_id) : \IActionResult { + require_once(controler::$basedir."/views/transaction_detail.php"); + $this->_model->get($_id); + $page = new \compta\views\transaction\Detail($this->_model); + return $page; } - public summary() + public function summary() { } - public update() + public function update() { } } diff --git a/app/compta/models/transaction.php b/app/compta/models/transaction.php index 34cfcec..3a8bbbb 100644 --- a/app/compta/models/transaction.php +++ b/app/compta/models/transaction.php @@ -1,6 +1,11 @@ _session = $_sess; + $this->_auth_cfg = $_auth; } + private function getSession() + { + return $this->_session; + } + /** + * Get Transaction data from Database + */ + public function get($_id) + { + $_cfg = $this->_auth_cfg; + $pcmn = new \Retrieve( $this->getSession() + , $_cfg + , $this->getSession()->getDb()); + $r = $pcmn->getTransaction( $_id); // Get Transaction + $this->_id = $_id; + $this->_mouvements = $r['entries']; + $this->_summary = $r['transaction']; + } /** * Required by JsonSerializable */ diff --git a/app/compta/services.php b/app/compta/services.php index 4bc243a..4c45db3 100644 --- a/app/compta/services.php +++ b/app/compta/services.php @@ -102,7 +102,7 @@ $r->get('/jrnx/detailMonth/?:id',"jrnx#detailMonth")->setRoot($ctrl_dir); $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',"transaction#detail")->setRoot($ctrl_dir); +$r->get('/transaction/detail/?:id',"transaction#detail")->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/account_detail.php b/app/compta/views/account_detail.php index e56945d..752d260 100644 --- a/app/compta/views/account_detail.php +++ b/app/compta/views/account_detail.php @@ -126,8 +126,10 @@ _EOF; private function fillTable() { $template=<<<_EOF -%s%s -%s + +%s +%s +%s %s %s _EOF; @@ -139,7 +141,7 @@ _EOF; $debit = sprintf("%.2f",$row[3]); $credit = sprintf("%.2f",$row[4]); $frag.=sprintf($template - ,++$count % 2?"odd":"even" ,$row[0],$row[1] ,$row[2] + ,++$count % 2?"odd":"even" ,$row[0],$row[5] ,$row[1],$row[2] ,$row[3] == 0.0 ? "" : $debit ,$row[2] > $row[3] ? "red" : "black" ,$row[4] == 0.0? "" : $credit); diff --git a/app/compta/views/transaction_detail.php b/app/compta/views/transaction_detail.php new file mode 100644 index 0000000..7bbddb1 --- /dev/null +++ b/app/compta/views/transaction_detail.php @@ -0,0 +1,165 @@ + + + + + +Gestion comptable + + + + + + + + + +
+ +
+
+XML; +/** + * @brief Update GUI with the list of + * documents available. All decomptes + */ +class Detail extends \PageCompta + implements \IActionResult +{ + function __construct($model) + { + $this->_model = $model; + parent::__construct(XmlAccount,true); + } + + public function render() + { + $this->show(); + } + + /** + * @brief insert a script in the page to update menu link + * + */ + private function script() + { + $s=<<<_EOF + +_EOF; + echo $s; + } + + /** + * @brief allow sub classes to modify xml file + */ + protected function _updateXML(&$xml) + { + $sum = $this->_model->_summary; + $fields= Array('title','date','voucher_ref','voucher_date'); + $values= Array($sum[4],$sum[3],$sum[1],$sum[2]); + $tbody = $xml->getElementsByTagName('tbody'); + $f = $tbody->item(0); + $nel = $xml->createDocumentFragment(); + /* Fill Table with entries */ + $nel->appendXML($this->fillTable()); + $f->appendChild($nel); + /* Update title from xml template */ + foreach (array_keys($fields) as $key) + { + $title = $this->getElementById($xml,$fields[$key]); + $el = $xml->createTextNode(" ".$values[$key]); + $title->appendChild($el); + } + // Update return link + $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); + } + + /** + * @brief Fill bilan table + */ + private function fillTable() + { + $template=<<<_EOF + +%s +%s +%s +%s +%s +_EOF; + $frag = ""; + $count = 0; + $lst = $this->_model->_mouvements; + foreach( $lst as $row) + { + $debit = $row[4] == 'd'?sprintf("%.2f",$row[5]):0.0; + $credit = $row[4] == 'c'?sprintf("%.2f",$row[5]):0.0; + $frag.=sprintf($template + , ++$count % 2?"odd":"even" ,$row[1] + , $row[2] ,$row[3],$row[6] + , $debit == 0.0 ? "" : $debit + , $debit > $credit ? "red" : "black" + , $credit == 0.0? "" : $credit); + } + return $frag; + } + +} + +?>