From 4266b97c29e0b4598487ca67a400253a23d6fd64 Mon Sep 17 00:00:00 2001 From: www-data Date: Sun, 9 Jan 2022 09:43:53 +0100 Subject: [PATCH] Started supplier mvc model --- app/compta/api_pcmn.php | 3 +- app/compta/controlers/owner.php | 62 ++++++++++++ app/compta/controlers/supplier.php | 36 ++++++- app/compta/models/owner.php | 41 ++++++++ app/compta/models/supplier.php | 69 +++++++++++++ app/compta/services.php | 8 ++ app/compta/views/owner_decomptes.php | 109 ++++++++++++++++++++ app/compta/views/supplier_index.php | 146 +++++++++++++++++++++++++++ 8 files changed, 471 insertions(+), 3 deletions(-) create mode 100644 app/compta/controlers/owner.php create mode 100644 app/compta/models/owner.php create mode 100644 app/compta/models/supplier.php create mode 100644 app/compta/views/owner_decomptes.php create mode 100644 app/compta/views/supplier_index.php diff --git a/app/compta/api_pcmn.php b/app/compta/api_pcmn.php index 158452a..b2950d9 100644 --- a/app/compta/api_pcmn.php +++ b/app/compta/api_pcmn.php @@ -181,12 +181,13 @@ __EOF; function getFournisseur($opt) { + $period = $this->getCurrentExercice(); $q1=<<<_EOF SELECT res.Compte,res.Description,res.Debit, res.Credit, res.Debit - res.Credit as Solde FROM (SELECT a.acc_id as Compte ,a.acc_name as Description , ROUND (SUM(CASE WHEN te.debit_credit = 'd' THEN te.amount ELSE 0.0 END),2) As Debit , ROUND(SUM(CASE WHEN te.debit_credit = 'c' THEN te.amount ELSE 0.0 END),2) As Credit - FROM Account as a JOIN Period as p on p.per_string = "2021" + FROM Account as a JOIN Period as p on p.per_string = "{$period}" LEFT JOIN Transactions as t on t.act_trans_date BETWEEN p.per_begin and p.per_end LEFT JOIN TransactionEntry as te ON te.trans_id = t.trans_id AND te.acc_id = a.acc_id WHERE a.acc_id like "401%" or a.acc_id like "460%" and te.entry_type != 'AN' diff --git a/app/compta/controlers/owner.php b/app/compta/controlers/owner.php new file mode 100644 index 0000000..e3bd348 --- /dev/null +++ b/app/compta/controlers/owner.php @@ -0,0 +1,62 @@ + + * @version 1.0 + * @package Compta + */ + +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::$modeldir."/owner.php"); + +/** + * + * + */ +class Owner extends controler +{ + + /** + * Constructor + */ + public function __construct() + { + parent::__construct(); + $this->_model = new \compta\models\owner\Model( + $this->getSession(),$this->getAuthConfig()); + } + /** + * Get the details of the supplier account. + * @param string $_accout_id the supplier account + */ + public function index() : \IActionResult + { + require_once(controler::$basedir."/views/owner_index.php"); + $page = new \compta\views\Owner\Index(); + return $page; + } + /** + * Get the details of the supplier account. + * @param string $_accout_id the supplier account + */ + public function decomptes() : \IActionResult + { + require_once(controler::$basedir."/views/owner_decomptes.php"); + $page = new \compta\views\Owner\Decomptes(); + return $page; + } +} + +?> diff --git a/app/compta/controlers/supplier.php b/app/compta/controlers/supplier.php index 9f79f83..73db5cf 100644 --- a/app/compta/controlers/supplier.php +++ b/app/compta/controlers/supplier.php @@ -13,8 +13,11 @@ 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::$modeldir."/supplier.php"); -class Supplier +class Supplier extends controler { /** @@ -22,6 +25,19 @@ class Supplier */ public function __construct() { + parent::__construct(); + $this->_model = new \compta\models\supplier\Model( + $this->getSession(),$this->getAuthConfig()); + } + + /** + * Get the details of the supplier account. + */ + public function index() : \IActionResult + { + require_once(controler::$viewdir."/supplier_index.php"); + $page = new \compta\views\supplier\Index($this->_model); + return $page; } /** * Get the details of the supplier account. @@ -29,18 +45,34 @@ class Supplier */ public function account($_account_id) { + require_once(controler::$viewdir."/supplier_accout.php"); + $this->_model->getDetails($_id); + $page = new \compta\views\supplier\Account($this->_model); + return $page; } - public function details() + public function details($_supplier_id) { + require_once(controler::$viewdir."/supplier_details.php"); + $this->_model->getDetails($_id); + $page = new \compta\views\supplier\Details($this->_model); + return $page; } public function pay() { + require_once(controler::$viewdir."/supplier_pay.php"); + $this->_model->getDetails($_id); + $page = new \compta\views\supplier\Pay($this->_model); + return $page; } public function bill() { + require_once(controler::$viewdir."/supplier_bill.php"); + $this->_model->getDetails($_id); + $page = new \compta\views\supplier\Bill($this->_model); + return $page; } } diff --git a/app/compta/models/owner.php b/app/compta/models/owner.php new file mode 100644 index 0000000..2480671 --- /dev/null +++ b/app/compta/models/owner.php @@ -0,0 +1,41 @@ +_session = $_sess; + $this->_auth_cfg = $_auth; + } + + private function getSession() + { + return $this->_session; + } + +} +?> diff --git a/app/compta/models/supplier.php b/app/compta/models/supplier.php new file mode 100644 index 0000000..6ff61a6 --- /dev/null +++ b/app/compta/models/supplier.php @@ -0,0 +1,69 @@ +_session = $_sess; + $this->_auth_cfg = $_auth; + } + + private function getSession() + { + return $this->_session; + } + public function getDetails($_id) + { + $_cfg = $this->_auth_cfg; + $pcmn = new \Retrieve( $this->getSession() + , $_cfg + , $this->getSession()->getDb()); + $r = $pcmn->getEntriesByAccount( + $this->getSession()->getCurrentExercice() + , $_id + , ""); // Get Banks accounts + $this->_id = $_id; + $this->_mouvements = $r['entries']; + $this->_solde = $r['solde']; + } + + public function getSuppliers() + { + $_cfg = $this->_auth_cfg; + $pcmn = new \Pcmn( $this->getSession() + , $_cfg + , $this->getSession()->getDb()); + return $pcmn->getFournisseur(""); + } + + /** + * Required by JsonSerializable + */ + public function jsonSerialize() + { + return [ + 'account' => $this->_summary + , 'entries' => $this->_mouvements]; + } + +} +?> diff --git a/app/compta/services.php b/app/compta/services.php index 1e33372..1fee6d3 100644 --- a/app/compta/services.php +++ b/app/compta/services.php @@ -50,6 +50,10 @@ $r->get('/chart/acount/?:id',"chart#account")->setRoot($ctrl_dir); $r->get('/account',"account#index")->setRoot($ctrl_dir); $r->get('/account/detail/?:id',"account#detail")->setRoot($ctrl_dir); +/* Supplier services*/ +$r->get('/supplier',"supplier#index")->setRoot($ctrl_dir); +$r->get('/supplier/detail/?:id',"supplier#detail")->setRoot($ctrl_dir); + /* exercice */ $r->get('/exercice',"exercice#index")->setRoot($ctrl_dir); $r->get('/exercice/',"exercice#index")->setRoot($ctrl_dir); @@ -110,6 +114,10 @@ $r->post('/budget/updatePost',"budget#updatePost")->setRoot($ctrl_dir); $r->get('/admin',"admin#index")->setRoot($ctrl_dir); $r->get('/admin/index',"admin#index")->setRoot($ctrl_dir); +/* Onwer services*/ +$r->get('/owner',"owner#index")->setRoot($ctrl_dir); +$r->get('/owner/decomptes',"owner#decomptes")->setRoot($ctrl_dir); + /** * Run router */ diff --git a/app/compta/views/owner_decomptes.php b/app/compta/views/owner_decomptes.php new file mode 100644 index 0000000..c923bcd --- /dev/null +++ b/app/compta/views/owner_decomptes.php @@ -0,0 +1,109 @@ + + + + + +Gestion comptable + + + + + + + + + + + + +

Chargement ...

+
+ + + +
+
+XML; + + +/** + * @brief Update GUI with the list of + * documents available. All decomptes + */ +class Decomptes extends \PageCompta + implements \IActionResult +{ + + function __construct() + { + global $xmlComptaDocuments; + parent::__construct($xmlComptaDocuments,true); + GLOBAL $conf; + $this->conf_auth = $conf['auth']['mysql']; + $this->_retrieve = new \Retrieve( $this->session + , $this->conf_auth + , $this->session->getDb()); + } + /** + * @implement IActionResult render method + */ + public function render() + { + $this->show(); + } + + private function decompte($period,$cpt) + { + $_scheme = $this->request->getScheme(); + $root = $_scheme."".$this->request->getServerHost()."/".$this->alias."/app/compta/reports/syndic_builder_decompte.php?period="; + echo '
  • Décompte de charge '.$period.'
  • '; + } + private function documents() + { + $_cfg = $this->_auth_cfg; + $ex = new \Exercice( $this->getSession() + , $_cfg + , $this->getSession()->getDb()); + $syndic = new \Syndic( $this->getSession() + , $_cfg + , $this->getSession()->getDb()); + $retrieve = $this->_retrieve; + $res = $retrieve->getSoldeCharge(); + $compte = $retrieve->getAccount($this->session->id()); + $acc = $syndic->getCoproprietaires(0); + $p = $ex->getClosed(false); + echo ""; + } + + /** + * @brief Display The articles in flex mode + * Also revise menu + */ + function main() { + echo '
    '; + echo "

    Vos décomptes de charges

    "; + $this->documents(); + echo '
    '; + } +} + + + +?> diff --git a/app/compta/views/supplier_index.php b/app/compta/views/supplier_index.php new file mode 100644 index 0000000..aa815c7 --- /dev/null +++ b/app/compta/views/supplier_index.php @@ -0,0 +1,146 @@ + + + + + +Gestion comptable + + + + + + + + + +
    + +
    +
    +XML; +/** + * @brief Update GUI with the list of + * documents available. All decomptes + */ +class Index extends \PageCompta + implements \IActionResult +{ + function __construct($model) + { + $this->_model = $model; + parent::__construct(SupplierIndex,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) + { + $c1 = ""; + $c2 = ""; + $lc1 = $this->getElementById($xml,"supplier-list-c1"); + $lc2 = $this->getElementById($xml,"supplier-list-c2"); + $frag1 = $xml->createDocumentFragment(); + $frag2 = $xml->createDocumentFragment(); + $this->fillTable($c1,$c2); + $frag1->appendXML($c1); + $frag2->appendXML($c2); + $lc1->appendChild($frag1); + $lc2->appendChild($frag2); + } + + /** + * @brief Fill bilan table + */ + private function fillTable(&$c1,&$c2) + { + $template=<<<_EOF + +

    +%s %s + +Solde %.2f + +

    +
    +
    +_EOF; + $frag = ""; + $count = 0; + $lst = $this->_model->getSuppliers(); + foreach( $lst as $row) + { + if (++$count % 2) + { + $c1.=sprintf($template + ,$row['acc_id'] ,$row['acc_id'] + ,$row['acc_desc'] + ,$row['solde']); + } else + { + $c2.=sprintf($template + ,$row['acc_id'] ,$row['acc_id'] + ,$row['acc_desc'] + ,$row['solde']); + } + } + return $frag; + } + +} + + +?> -- 2.30.2