require_once(controler::$basedir."/../../phplib/class.ActionResults.php");
require_once(controler::$modeldir."/supplier.php");
+/**
+ *
+ *
+ */
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);
return $page;
}
- public function details($_supplier_id)
+ public function details($_supplier_id) : \IActionResult
{
require_once(controler::$viewdir."/supplier_details.php");
$this->_model->getDetails($_id);
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);
$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);
+ }
}
?>
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.
*/
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()
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;
/**
* 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);
}
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
*/
$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")});
+ }
+ }
/**
*
*/
$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);
<group id="group">
<grouptitle>Nouvelle Facture</grouptitle>
<groupcontent>
+<form method="post" action="/app/compta/services.php/supplier/billPost">
<FieldSet labelWidth="95" style="border:none 0px;">
- <TextField width="253" id="suppl_desc" style=""><Label style="">Intitule</Label></TextField><br/>
- <ComboBox width="259" id="suppl_id" style="margin-right:10px;"><Label>Fournisseur</Label>
+ <TextField width="253" id="suppl_desc" asp-for="suppl_desc" style=""><Label style="">Intitule</Label></TextField><br/>
+ <ComboBox width="259" id="suppl_id" asp-for="_id" style="margin-right:15px;"><Label>Fournisseur</Label>
</ComboBox>
- <TextField width="190" id="suppl_date" style=""><Label style=""> Date Saisie</Label></TextField><br/>
- <ComboBox width="259" id="suppl_charge" style="margin-right:10px;"><Label>Charge</Label>
+ <TextField width="190" id="suppl_date" asp-for="suppl_date" style=""><Label style=""> Date Saisie</Label></TextField><br/>
+ <ComboBox width="259" id="suppl_charge" asp-for="suppl_charge" style="margin-right:15px;"><Label>Charge</Label>
</ComboBox>
- <TextField width="190" id="suppl_voucher_date" style=""><Label style=""> Date Facture</Label></TextField><br/>
- <TextField width="253" id="suppl_voucher_ref" style="margin-right:9px;"><Label style="">Référence</Label></TextField>
- <TextField width="190" id="suppl_amount" style=""><Label style=""> Montant</Label></TextField><br/>
- <TextField width="253" id="suppl_voucher_file" type="file" style="margin-right:10px;"><Label style="">Fichier</Label></TextField>
- <ComboBox width="199" id="suppl_charge_key" style=""><Label>Clé Charge</Label>
+ <TextField width="190" id="suppl_voucher_date" asp-for="suppl_voucher_date" style=""><Label style=""> Date Facture</Label></TextField><br/>
+ <TextField width="253" id="suppl_voucher_ref" asp-for="suppl_voucher_ref" style="margin-right:15px;"><Label style="">Référence</Label></TextField>
+ <TextField width="190" id="suppl_amount" asp-for="suppl_amount" style=""><Label style=""> Montant</Label></TextField><br/>
+ <TextField width="253" id="suppl_voucher_file" type="file" style="margin-right:15px;"><Label style="">Fichier</Label></TextField>
+ <ComboBox width="199" id="suppl_charge_key" asp-for="suppl_charge_key" style=""><Label>Clé Charge</Label>
</ComboBox>
</FieldSet>
<panel resp-width="98%" style="min-height:14px;">
<!--
- -->
- <button id='btFFRecord' href="#" style="float:left;">Enregistrer</button>
- <button id='btFFCancel' style="float:left;" href="#">Annuler</button>
- </panel>
-</groupcontent>
-</group>
+ -->
+ <button id='btFFRecord' type="submit" style="float:left;margin-right: 15px;">Enregistrer</button>
+ <button id='btFFCancel' href="#" style="float:left;">Annuler</button>
+ </panel>
+ </form>
+ </groupcontent>
+ </group>
</panel>
,$this->_model->_id);
$nel = $xml->createDocumentFragment();
$nel->appendXML($frag);
- $f->appendChild($nel);
+ $f->appendChild($nel);
+ // Update asp for fields
+ $this->updateAspfor($xml,$this->_model);
}
/**
_EOF;
$frag = "";
$count = 0;
- $lst = $this->_model->getChargeAccounts();
+ $lst = $this->_model->getListAccounts("6");
foreach( $lst as $row)
{
$frag.=sprintf($template
<panel id="pAccount" class="col-11 pg-account" style="min-height:150px;">
<h2 id="title" style="width:100%">Payer facture fournisseur</h2>
- <group id="group">
-<grouptitle>Payer Facture</grouptitle>
-<groupcontent>
+ <group id="group">
+ <grouptitle>Payer Facture</grouptitle>
+ <groupcontent>
+ <form method="post" action="/app/compta/services.php/supplier/payPost">
<FieldSet labelWidth="95" style="border:none 0px;">
- <TextField width="243" id="suppl_desc" style=""><Label style="">Intitule</Label></TextField><br/>
- <ComboBox width="220" id="suppl_id" style="margin-right:10px;"><Label>Fournisseur</Label>
- <Entry key="401001-" value="401001"></Entry>
- <Entry key="401002-BOLLORE" value="401002"></Entry>
- </ComboBox>
- <TextField width="75" id="suppl_date" style=""><Label style=""> Date Saisie</Label></TextField><br/>
- <ComboBox width="220" id="suppl_banque" style="margin-right:10px;"><Label>Banque</Label>
+ <TextField width="243" id="suppl_desc" asp-for="suppl_desc" style=""><Label style="">Intitule</Label></TextField><br/>
+ <ComboBox width="249" id="suppl_id" asp-for="_id" style="margin-right:15px;"><Label>Fournisseur</Label>
+ </ComboBox>
+ <TextField width="75" id="suppl_date" asp-for="suppl_date" style=""><Label style=""> Date Saisie</Label></TextField><br/>
+ <ComboBox width="249" id="suppl_banque" asp-for="suppl_banque" style="margin-right:15px;"><Label>Banque</Label>
<Entry key="512001-Banque postale" value="512001"></Entry>
- </ComboBox>
- <TextField width="75" id="suppl_voucher_date" style=""><Label style=""> Date Facture</Label></TextField><br/>
- <TextField width="220" id="suppl_voucher_ref" value="CHEQUE N°" style="margin-right:9px;"><Label style="">Reference</Label></TextField>
- <TextField width="73" id="suppl_amount" style=""><Label style=""> Montant</Label></TextField>
+ </ComboBox>
+ <TextField width="75" id="suppl_voucher_date" asp-for="suppl_voucher_date" style=""><Label style=""> Date Facture</Label></TextField><br/>
+ <TextField width="243" id="suppl_voucher_ref" asp-for="suppl_voucher_ref" value="CHEQUE N°" style="margin-right:15px;"><Label style="">Reference</Label></TextField>
+ <TextField width="73" id="suppl_amount" asp-for="suppl_amount" style=""><Label style=""> Montant</Label></TextField>
</FieldSet>
- <panel class="col-md-10 col-sm-12" style="min-height:14px;">
- <button id='btFPRecord' href="#" style="float:left;">Enregistrer</button>
- <button id='btFPCancel' style="float:left;" href="#">Annuler</button>
+ <panel class="col-md-10 col-sm-12" style="min-height:14px;">
+ <button id='btFPRecord' type="submit" style="float:left;margin-right: 15px;">Enregistrer</button>
+ <button id='btFPCancel' style="float:left;" href="">Annuler</button>
<!--
-->
- </panel>
-</groupcontent>
-</group>
+ </panel>
+ </form>
+ </groupcontent>
+ </group>
</panel>
// Ok Handle Charges
$solde = $this->getElementById($xml,"suppl_banque");
$nel = $xml->createDocumentFragment();
- $nel->appendXML($this->fillCharge());
+ $nel->appendXML($this->fillBanque());
$solde->appendChild($nel);
// Update supplier ID
$tbody = $this->getElementById($xml,"suppl_id");
$nel = $xml->createDocumentFragment();
$nel->appendXML($frag);
$f->appendChild($nel);
+ // Update asp for fields
+ $this->updateAspfor($xml,$this->_model);
}
/**
* @brief Fill key Charge
*/
- private function fillKeys()
+ private function fillBanque()
{
$template=<<<_EOF
_EOF;
$frag = "";
$count = 0;
- $lst = $this->_model->getKeysCharge();
- foreach( $lst as $row)
- {
- $frag.=sprintf($template
- ,$row[1]
- ,$row[2],$row[0]);
- }
- return $frag;
-
- }
-
- /**
- * @brief Fill key Charge
- */
- private function fillCharge()
- {
-
- $template=<<<_EOF
-<Entry key="%s - %s" value="%s"></Entry>
-_EOF;
- $frag = "";
- $count = 0;
- $lst = $this->_model->getChargeAccounts();
+ $lst = $this->_model->getListAccounts("5");
foreach( $lst as $row)
{
$frag.=sprintf($template
_('Copropriété') => '/'.$alias.$lang.'/app/compta/services.php/org',
_('Plan Comptable') => '/'.$alias.$lang.'/app/compta/services.php/chart',
_('Exercices') => '/'.$alias.$lang.'/app/compta/services.php/exercice',
- _('Fournisseurs') => '/'.$alias.$lang.'/app/compta/page_ledger_fournisseur.php',
+ _('Fournisseurs') => '/'.$alias.$lang.'/app/compta/services.php/supplier',
_('Copropriétaires') => '/'.$alias.$lang.'/app/compta/page_ledger_coproprietaire.php',
- _('Décompte Charge') => '/'.$alias.$lang.'/app/compta/page_ledger_mes_documents.php',
+ _('Décompte Charge') => '/'.$alias.$lang.'/app/compta/services.php/owner/decomptes',
_('Journaux') => '/'.$alias.$lang.'/app/compta/services.php/jrnx',
_('Bilan') => '/'.$alias.$lang.'/app/compta/services.php/bilan',
_('Budget') => '/'.$alias.$lang.'/app/compta/services.php/budget',
-Subproject commit 01e86fd0b4968b1e2cf37e183f77ff8a7a650837
+Subproject commit b1016666f5fd4264ce632b3e00126819a0f02084
-Subproject commit 540dc587e4ab3eafb341a0d7d3990bffb35b848e
+Subproject commit 83819fb21391da8cfbfeba2fe8d16f654f554ffd