From b1aebcda1d236750d3457e37b8676fc2add96f0b Mon Sep 17 00:00:00 2001 From: www-data Date: Tue, 11 Jan 2022 16:10:40 +0100 Subject: [PATCH] Almost Finished supplier ui using mvc model. Data check needs to be completed --- app/compta/controlers/supplier.php | 42 ++++++++++- app/compta/models/supplier.php | 114 ++++++++++++++++++++++++++++- app/compta/pages.php | 30 ++++++++ app/compta/services.php | 2 + app/compta/views/supplier_bill.php | 38 +++++----- app/compta/views/supplier_pay.php | 70 +++++++----------- app/config/syndic.php | 4 +- app/xsl | 2 +- css | 2 +- 9 files changed, 230 insertions(+), 74 deletions(-) diff --git a/app/compta/controlers/supplier.php b/app/compta/controlers/supplier.php index 4d8d681..c986129 100644 --- a/app/compta/controlers/supplier.php +++ b/app/compta/controlers/supplier.php @@ -17,6 +17,10 @@ require_once(controler::$basedir."/../../phplib/iface.ActionResult.php"); require_once(controler::$basedir."/../../phplib/class.ActionResults.php"); require_once(controler::$modeldir."/supplier.php"); +/** + * + * + */ class Supplier extends controler { @@ -39,11 +43,12 @@ class Supplier extends controler $page = new \compta\views\supplier\Index($this->_model); return $page; } + /** * Get the details of the supplier account. * @param string $_accout_id the supplier account */ - public function account($_account_id) + public function account($_account_id) : \IActionResult { require_once(controler::$viewdir."/supplier_account.php"); $this->_model->getDetails($_account_id); @@ -51,7 +56,7 @@ class Supplier extends controler return $page; } - public function details($_supplier_id) + public function details($_supplier_id) : \IActionResult { require_once(controler::$viewdir."/supplier_details.php"); $this->_model->getDetails($_id); @@ -59,15 +64,16 @@ class Supplier extends controler return $page; } - public function pay($_id) + public function pay($_id) : \IActionResult { require_once(controler::$viewdir."/supplier_pay.php"); $this->_model->getDetails($_id); + $this->_model->getAccount($_id); $page = new \compta\views\supplier\Pay($this->_model); return $page; } - public function bill($_id) + public function bill($_id) : \IActionResult { require_once(controler::$viewdir."/supplier_bill.php"); $this->_model->getDetails($_id); @@ -75,6 +81,34 @@ class Supplier extends controler $page = new \compta\views\supplier\Bill($this->_model); return $page; } + + public function billPost() : \IActionResult + { + $model = $this->_model; + require_once(controler::$viewdir."/supplier_bill.php"); + $model->getDetails($model->_id); + $model->getAccount($model->_id); + if ( $model->validePost()) + { + $model->newBill(); + return $this->account($model->_id); + } else + return new \compta\views\supplier\Bill($model); + } + + public function payPost() : \IActionResult + { + $model = $this->_model; + require_once(controler::$viewdir."/supplier_pay.php"); + $model->getDetails($model->_id); + $model->getAccount($model->_id); + if ( $model->validePost()) + { + $model->payBill(); + return $this->account($model->_id); + } else + return new \compta\views\supplier\Pay($this->_model); + } } ?> diff --git a/app/compta/models/supplier.php b/app/compta/models/supplier.php index 88221d2..0924206 100644 --- a/app/compta/models/supplier.php +++ b/app/compta/models/supplier.php @@ -8,6 +8,8 @@ require_once(dirname(__FILE__)."/../api_pcmn.php"); require_once(dirname(__FILE__)."/../api_syndic.php"); require_once(dirname(__FILE__)."/../api_retrieve.php"); +require_once(dirname(__FILE__)."/../../../phplib/class.validator.php"); + /** * @brief Data model for a transaction. */ @@ -20,13 +22,40 @@ class Model implements \JsonSerializable public $_solde = 0.0; public $_id = -1; // current entry. -1 no entry selected public $_account = Array(); + + /* Bill parameters */ + private $bValide = false; // is Bill from post valide + private $billPostParams = Array("suppl_amount","suppl_date","suppl_voucher_date","suppl_voucher_ref" + ,"suppl_desc","suppl_charge_key","suppl_charge"); + private $billPostCheck = Array("num_float","str_date","str_date","str","str","",""); + public $suppl_desc = ""; + public $suppl_charge = ""; + public $suppl_amount = 0.0; + public $suppl_date = ""; + public $suppl_voucher_date = ""; + public $suppl_voucher_ref = ""; + public $suppl_charge_key = 1; + + /* Pay paramater all the same except suppl_charge become suppl_banque*/ + public $suppl_banque = ""; + /** * Constructor */ function __construct($_sess,$_auth) { - $this->_session = $_sess; - $this->_auth_cfg = $_auth; + $this->_session = $_sess; + $this->_auth_cfg = $_auth; + $this->suppl_date = date("Y-m-d"); + if (\AEB::$REQUEST['btFFRecord'] != null) + { + $this->getBillPost(); + } else if (\AEB::$REQUEST['btFPRecord'] != null) + { + $this->billPostParams[6] = "suppl_banque"; + // Ok handler pay bill + $this->getBillPost(); + } } private function getSession() @@ -34,6 +63,41 @@ class Model implements \JsonSerializable return $this->_session; } + /** + * Retrieve values from billPost request + */ + private function getBillPost() + { + $count = 0; + $valid = true; + $v = new \Validator(); + $this->_id = \AEB::$REQUEST['suppl_id']; + foreach ( $this->billPostParams as $param) + { + $pv = \AEB::$REQUEST[$param]; + try { + $ck = $this->billPostCheck[$count++]; + if ($ck != "") + { + $v->{$ck}($pv,"Not valid ".$param); + } + $this->{$param} = $pv; + } catch (Throwable $rte) + { + $valid = false; + } catch (\Exception $e) + { + $valid = false; + } + } + $this->bValide = $valid; + } + + public function validePost() + { + return $this->bValide; + } + public function getDetails($_id) { $_cfg = $this->_auth_cfg; @@ -78,13 +142,13 @@ class Model implements \JsonSerializable /** * Adapter method */ - public function getChargeAccounts() + public function getListAccounts($c = "6") { $_cfg = $this->_auth_cfg; $pcmn = new \Pcmn( $this->getSession() , $_cfg , $this->getSession()->getDb()); - return $pcmn->getAccountList("6"); + return $pcmn->getAccountList($c); } @@ -100,6 +164,48 @@ class Model implements \JsonSerializable return $pcmn->getKeysCharge(); } + + /** + * + */ + public function newBill() + { + $transi = Array( 'act_trans_date' => $this->suppl_date + , 'voucher_date' => $this->suppl_voucher_date + , 'voucher_ref' => $this->suppl_voucher_ref + , 'acc_supplier' => $this->_id + , 'acc_charge' => $this->suppl_charge + , 'amount' => $this->suppl_amount + , 'trans_label' => $this->suppl_desc + , 'key_charge' => $this->suppl_charge_key + ); + $_cfg = $this->_auth_cfg; + $pcmn = new \Booking( $this->getSession() + , $_cfg + , $this->getSession()->getDb()); + return $pcmn->newBill($transi,""); + } + + /** + * + */ + public function payBill() + { + $transi = Array( 'act_trans_date' => $this->suppl_date + , 'voucher_date' => $this->suppl_voucher_date + , 'voucher_ref' => $this->suppl_voucher_ref + , 'acc_supplier' => $this->_id + , 'acc_banque' => $this->suppl_banque + , 'amount' => $this->suppl_amount + , 'trans_label' => $this->suppl_desc + ); + $_cfg = $this->_auth_cfg; + $pcmn = new \Booking( $this->getSession() + , $_cfg + , $this->getSession()->getDb()); + return $pcmn->payBill($transi,""); + } + /** * Required by JsonSerializable */ diff --git a/app/compta/pages.php b/app/compta/pages.php index 292d471..a4206e2 100644 --- a/app/compta/pages.php +++ b/app/compta/pages.php @@ -67,7 +67,37 @@ class PageCompta extends AppPage { $xpath = new DOMXPath($xml); return $xpath->query("//*[@id='$id']")->item(0); } + /** + * + */ + protected function getElementsAspfor($xml) + { + $xpath = new DOMXPath($xml); + return $xpath->query("//*[@asp-for]"); + } + protected function updateAspfor($xml,$model) + { + foreach($this->getElementsAspfor($xml) as $key => $value) + { + if ($value->nodeName == "ComboBox") + { + $afor_value = $model->{$value->getAttribute("asp-for")}; + // Get and find right selection set selected + foreach($value->childNodes as $child) + { + if ( ($child->nodeType == XML_ELEMENT_NODE) && + ($child->nodeName == "Entry") + &&($child->getAttribute("value") == $afor_value) ) + { + error_log("Found Entry ".$afor_value."\n"); + $child->setAttribute("selected","1"); + } + } + } else + $value->setAttribute("value",$model->{$value->getAttribute("asp-for")}); + } + } /** * */ diff --git a/app/compta/services.php b/app/compta/services.php index 59e126a..b3cd3ad 100644 --- a/app/compta/services.php +++ b/app/compta/services.php @@ -56,6 +56,8 @@ $r->get('/supplier/details/?:id',"supplier#details")->setRoot($ctrl_dir); $r->get('/supplier/account/?:id',"supplier#account")->setRoot($ctrl_dir); $r->get('/supplier/bill/?:id',"supplier#bill")->setRoot($ctrl_dir); $r->get('/supplier/pay/?:id',"supplier#pay")->setRoot($ctrl_dir); +$r->post('/supplier/billPost',"supplier#billPost")->setRoot($ctrl_dir); +$r->post('/supplier/payPost',"supplier#payPost")->setRoot($ctrl_dir); /* exercice */ $r->get('/exercice',"exercice#index")->setRoot($ctrl_dir); diff --git a/app/compta/views/supplier_bill.php b/app/compta/views/supplier_bill.php index 48db472..8797921 100644 --- a/app/compta/views/supplier_bill.php +++ b/app/compta/views/supplier_bill.php @@ -31,28 +31,30 @@ const SupplierBill =<< Nouvelle Facture +
-
- +
+ -
- +
+ -
- -
- - +
+ +
+ +
- - - - - + --> + + + +
+
+ @@ -112,7 +114,9 @@ _EOF; ,$this->_model->_id); $nel = $xml->createDocumentFragment(); $nel->appendXML($frag); - $f->appendChild($nel); + $f->appendChild($nel); + // Update asp for fields + $this->updateAspfor($xml,$this->_model); } /** @@ -148,7 +152,7 @@ _EOF; _EOF; $frag = ""; $count = 0; - $lst = $this->_model->getChargeAccounts(); + $lst = $this->_model->getListAccounts("6"); foreach( $lst as $row) { $frag.=sprintf($template diff --git a/app/compta/views/supplier_pay.php b/app/compta/views/supplier_pay.php index 17fb5c7..71dd0e3 100644 --- a/app/compta/views/supplier_pay.php +++ b/app/compta/views/supplier_pay.php @@ -29,31 +29,31 @@ const SupplierPay =<<