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();
_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};'
/**
*
* @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.'");';
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()
{
}
}
<?php
-namespace compta/model/transaction ;
+namespace compta\models\transaction ;
+
+require_once(dirname(__FILE__)."/../api_exercice.php");
+require_once(dirname(__FILE__)."/../api_booking.php");
+require_once(dirname(__FILE__)."/../api_pcmn.php");
+require_once(dirname(__FILE__)."/../api_retrieve.php");
/**
* @brief Data model for a transaction.
/**
* Constructor
*/
- function __construct()
+ function __construct($_sess,$_auth)
{
+ $this->_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
*/
$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);
private function fillTable()
{
$template=<<<_EOF
-<tr class="%s"><td>%s</td><td>%s</td>
-<td style="text-align:right">%s</td>
+<tr class="%s">
+<td style="text-align:left">%s</td>
+<td style="text-align:right"><link href="/app/compta/services.php/transaction/detail/%s">%s</link></td>
+<td>%s</td>
<td style="text-align:right">%s</td>
<td style="text-align:right;color:%s">%s</td></tr>
_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);
--- /dev/null
+<?php
+
+namespace compta\views\transaction;
+
+require_once(dirname(__FILE__)."/../pages.php");
+
+const XmlAccount =<<<XML
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<?xslt-param name='alias' value='/andre/'?>
+<?xml-stylesheet type="text/xsl" href="xsl/gui.xsl?alias='/andre/'"?>
+<gui langue='fr' style="padding: 0;">
+<liens/>
+<title langue='fr'>Gestion comptable</title>
+<content>
+ <script>
+ </script>
+ <script>
+ </script>
+
+<menu>
+ <item id="btRetour" link="/app/compta/services.php/" class="" title="Retour" />
+</menu>
+
+ <panel id="pAccount" class="col-12 pg-account" style="min-height:150px;">
+ <h2 id="title" style="width:100%">Transaction</h2>
+ <p id="date" style="width:100%" >Date de Saisie : </p>
+ <p id="voucher_date" style="width:100%">Date Facture : </p>
+ <p id="voucher_ref" style="width:100%" >Réference Facture: </p>
+ <table id="tAccount" autoScroll='true' height="200" style="margin:15px 30px 15px 0px; padding:15px 0px 0px 0px;" >
+ <caption>Détail Transaction</caption>
+ <thead resp-width="100%">
+ <tr>
+ <th resp-width="10%">Date</th>
+ <th resp-width="50%">Account</th>
+ <th resp-width="10%">Type</th>
+ <th resp-width="15%">Débit</th>
+ <th resp-width="15%">Crédit</th></tr>
+ </thead>
+ <tbody style="overflow:auto;">
+ </tbody>
+ <tfoot>
+ <tr><td id="accSoldeCompte" colspan="3">Solde:</td>
+ <td id="accSoldeDebit" style="text-align:right;" >0.0</td>
+ <td id="accSoldeCredit" style="text-align:right;" >0.0</td>
+ </tr>
+ </tfoot>
+ </table>
+ </panel>
+ <div class="clearfix"></div>
+ <!-- Script Section -->
+ </content>
+</gui>
+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
+<script>
+(function() {
+ var mh1a = $('mh1').firstChild;
+ mh1a.href = "page_ledger.php";
+})();
+(function() {
+ var h, a, f;
+ a = document.getElementsByTagName('link');
+ for (h = 0; h < a.length; h++) {
+ f = a[h];
+ if (f.rel.toLowerCase().match(/stylesheet/) && f.href) {
+ var g = f.href.replace(/(&|\?)rnd=\d+/, '');
+ f.href = g + (g.match(/\?/) ? '&' : '?');
+ f.href += 'rnd=' + (new Date().valueOf());
+ }
+ } // for
+})()
+
+</script>
+_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
+<tr class="%s">
+<td style="text-align:left">%s</td>
+<td style="text-align:right"><link href="/app/compta/services.php/transaction/detail/%s">%s</link></td>
+<td>%s</td>
+<td style="text-align:right">%s</td>
+<td style="text-align:right;color:%s">%s</td></tr>
+_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;
+ }
+
+}
+
+?>