Merge pull request #9016 from yolocodefrench/develop
ajout de la gestion des comptes bancaires des tiers via l'api
This commit is contained in:
commit
1ff8788ff7
@ -80,6 +80,16 @@ if ($action == "set")
|
||||
$res = dolibarr_set_const($db, "PRELEVEMENT_USER", GETPOST("PRELEVEMENT_USER"),'chaine',0,'',$conf->entity);
|
||||
if (! $res > 0) $error++;
|
||||
}
|
||||
if (GETPOST("PRELEVEMENT_END_TO_END") || GETPOST("PRELEVEMENT_END_TO_END")=="")
|
||||
{
|
||||
$res = dolibarr_set_const($db, "END_TO_END", GETPOST("PRELEVEMENT_END_TO_END"),'chaine',0,'',$conf->entity);
|
||||
if (! $res > 0) $error++;
|
||||
}
|
||||
if (GETPOST("PRELEVEMENT_USTRD") || GETPOST("PRELEVEMENT_USTRD")=="")
|
||||
{
|
||||
$res = dolibarr_set_const($db, "USTRD", GETPOST("PRELEVEMENT_USTRD"),'chaine',0,'',$conf->entity);
|
||||
if (! $res > 0) $error++;
|
||||
}
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
@ -221,6 +231,18 @@ print $form->select_dolusers($conf->global->PRELEVEMENT_USER, 'PRELEVEMENT_USER'
|
||||
print '</td>';
|
||||
print '</tr>';
|
||||
|
||||
//EntToEnd
|
||||
print '<tr class="pair"><td class="fieldrequired">'.$langs->trans("END_TO_END").'</td>';
|
||||
print '<td align="left">';
|
||||
print '<input type="text" name="PRELEVEMENT_END_TO_END" value="'.$conf->global->END_TO_END.'" size="15" ></td>';
|
||||
print '</td></tr>';
|
||||
|
||||
//USTRD
|
||||
print '<tr class="pair"><td class="fieldrequired">'.$langs->trans("USTRD").'</td>';
|
||||
print '<td align="left">';
|
||||
print '<input type="text" name="PRELEVEMENT_USTRD" value="'.$conf->global->USTRD.'" size="15" ></td>';
|
||||
print '</td></tr>';
|
||||
|
||||
print '</table>';
|
||||
print '<br>';
|
||||
|
||||
|
||||
@ -1575,7 +1575,8 @@ class BonPrelevement extends CommonObject
|
||||
$XML_DEBITOR ='';
|
||||
$XML_DEBITOR .=' <DrctDbtTxInf>'.$CrLf;
|
||||
$XML_DEBITOR .=' <PmtId>'.$CrLf;
|
||||
$XML_DEBITOR .=' <EndToEndId>'.('AS-'.dol_trunc($row_facnumber,20).'-'.$Rowing).'</EndToEndId>'.$CrLf; // ISO20022 states that EndToEndId has a MaxLength of 35 characters
|
||||
// $XML_DEBITOR .=' <EndToEndId>'.('AS-'.dol_trunc($row_facnumber,20).'-'.$Rowing).'</EndToEndId>'.$CrLf; // ISO20022 states that EndToEndId has a MaxLength of 35 characters
|
||||
$XML_DEBITOR .=' <EndToEndId>'.(($conf->global->END_TO_END != "" ) ? $conf->global->END_TO_END : ('AS-'.dol_trunc($row_facnumber,20)).'-'.$Rowing).'</EndToEndId>'.$CrLf; // ISO20022 states that EndToEndId has a MaxLength of 35 characters
|
||||
$XML_DEBITOR .=' </PmtId>'.$CrLf;
|
||||
$XML_DEBITOR .=' <InstdAmt Ccy="EUR">'.round($row_somme, 2).'</InstdAmt>'.$CrLf;
|
||||
$XML_DEBITOR .=' <DrctDbtTx>'.$CrLf;
|
||||
@ -1607,7 +1608,8 @@ class BonPrelevement extends CommonObject
|
||||
$XML_DEBITOR .=' </DbtrAcct>'.$CrLf;
|
||||
$XML_DEBITOR .=' <RmtInf>'.$CrLf;
|
||||
// $XML_DEBITOR .=' <Ustrd>'.($row_facnumber.'/'.$Rowing.'/'.$Rum).'</Ustrd>'.$CrLf;
|
||||
$XML_DEBITOR .=' <Ustrd>'.dol_trunc($row_facnumber, 135).'</Ustrd>'.$CrLf; // 140 max
|
||||
// $XML_DEBITOR .=' <Ustrd>'.dol_trunc($row_facnumber, 135).'</Ustrd>'.$CrLf; // 140 max
|
||||
$XML_DEBITOR .=' <Ustrd>'.(($conf->global->USTRD != "" ) ? $conf->global->USTRD : dol_trunc($row_facnumber, 135) ).'</Ustrd>'.$CrLf; // 140 max
|
||||
$XML_DEBITOR .=' </RmtInf>'.$CrLf;
|
||||
$XML_DEBITOR .=' </DrctDbtTxInf>'.$CrLf;
|
||||
return $XML_DEBITOR;
|
||||
|
||||
@ -997,6 +997,179 @@ class Thirdparties extends DolibarrApi
|
||||
|
||||
return $result;
|
||||
}
|
||||
/**
|
||||
* Get CompanyBankAccount objects for thirdparty
|
||||
*
|
||||
* @param int $socid Thirdparty id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function getCompanyBankAccount($socid){
|
||||
|
||||
global $db, $conf;
|
||||
|
||||
if(! DolibarrApiAccess::$user->rights->facture->lire) {
|
||||
throw new RestException(401);
|
||||
}
|
||||
if(empty($socid)) {
|
||||
throw new RestException(400, 'Thirdparty ID is mandatory');
|
||||
}
|
||||
|
||||
if( ! DolibarrApi::_checkAccessToResource('societe',$socid)) {
|
||||
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
|
||||
}
|
||||
|
||||
/**
|
||||
* We select all the records that match the socid
|
||||
*/
|
||||
|
||||
$sql = "SELECT rowid, fk_soc, bank, number, code_banque, code_guichet, cle_rib, bic, iban_prefix as iban, domiciliation, proprio,";
|
||||
$sql.= " owner_address, default_rib, label, datec, tms as datem, rum, frstrecur";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."societe_rib";
|
||||
if ($socid) $sql.= " WHERE fk_soc = ".$socid." ";
|
||||
|
||||
|
||||
$result = $db->query($sql);
|
||||
|
||||
if($result->num_rows == 0 ){
|
||||
throw new RestException(404, 'Account not found');
|
||||
}
|
||||
|
||||
$i=0;
|
||||
|
||||
$accounts =[];
|
||||
|
||||
if ($result)
|
||||
{
|
||||
$num = $db->num_rows($result);
|
||||
while ($i < $num)
|
||||
{
|
||||
$obj = $db->fetch_object($result);
|
||||
$account = new CompanyBankAccount($db);
|
||||
if($account->fetch($obj->rowid)) {
|
||||
$accounts[] = $account;
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
else{
|
||||
throw new RestException(404, 'Account not found');
|
||||
}
|
||||
|
||||
|
||||
$fields = ['socid', 'default_rib', 'frstrecur', '1000110000001', 'datec', 'datem', 'label', 'bank', 'bic', 'iban', 'id'];
|
||||
|
||||
$returnAccounts = [];
|
||||
|
||||
foreach($accounts as $account){
|
||||
$object= [];
|
||||
foreach($account as $key => $value)
|
||||
if(in_array($key, $fields)){
|
||||
$object[$key] = $value;
|
||||
|
||||
}
|
||||
$returnAccounts[] = $object;
|
||||
}
|
||||
|
||||
return $returnAccounts;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create CompanyBankAccount object for thirdparty
|
||||
* @param int $socid thirdparty id
|
||||
* @param array $request_data Request datas
|
||||
*
|
||||
* @return object ID of thirdparty
|
||||
*
|
||||
* @url POST {socid}/CompanyBankAccount
|
||||
*/
|
||||
function createCompanyBankAccount($socid, $request_data = null)
|
||||
{
|
||||
if(! DolibarrApiAccess::$user->rights->societe->creer) {
|
||||
throw new RestException(401);
|
||||
}
|
||||
|
||||
$account = new CompanyBankAccount($this->db);
|
||||
|
||||
$account->socid = $socid;
|
||||
|
||||
foreach($request_data as $field => $value) {
|
||||
$account->$field = $value;
|
||||
}
|
||||
|
||||
if ($account->create(DolibarrApiAccess::$user) < 0)
|
||||
throw new RestException(500, 'Error creating Company Bank account');
|
||||
|
||||
|
||||
if ($account->update(DolibarrApiAccess::$user) < 0)
|
||||
throw new RestException(500, 'Error updating values');
|
||||
|
||||
return $account;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update CompanyBankAccount object for thirdparty
|
||||
*
|
||||
* @param int $socid Thirdparty id
|
||||
* @param int $id CompanyBankAccount's id
|
||||
* @param array $request_data Request datas
|
||||
*
|
||||
* @return object ID of thirdparty
|
||||
*
|
||||
* @url PUT {socid}/CompanyBankAccount/{id}
|
||||
*/
|
||||
function updateCompanyBankAccount($socid, $id, $request_data = null)
|
||||
{
|
||||
if(! DolibarrApiAccess::$user->rights->societe->creer) {
|
||||
throw new RestException(401);
|
||||
}
|
||||
|
||||
$account = new CompanyBankAccount($this->db);
|
||||
|
||||
$account->fetchFromApi($id, $socid);
|
||||
|
||||
|
||||
|
||||
if($account->socid != $socid){
|
||||
throw new RestException(401);
|
||||
}
|
||||
|
||||
|
||||
foreach($request_data as $field => $value) {
|
||||
$account->$field = $value;
|
||||
}
|
||||
|
||||
if ($account->update(DolibarrApiAccess::$user) < 0)
|
||||
throw new RestException(500, 'Error updating values');
|
||||
|
||||
return $account;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id CompanyBankAccount's id
|
||||
* @param int $socid Thirdparty id
|
||||
*
|
||||
* @return int -1 if error 1 if correct deletion
|
||||
*
|
||||
* @url DELETE {socid}/CompanyBankAccount/{id}
|
||||
*/
|
||||
function deleteCompanyBankAccount($id, $socid){
|
||||
|
||||
if(! DolibarrApiAccess::$user->rights->societe->creer) {
|
||||
throw new RestException(401);
|
||||
}
|
||||
|
||||
$account = new CompanyBankAccount($this->db);
|
||||
|
||||
$account->fetch($id);
|
||||
|
||||
if(!$account->socid == $socid)
|
||||
throw new RestException(401);
|
||||
|
||||
return $account->delete(DolibarrApiAccess::$user);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@ -250,6 +250,63 @@ class CompanyBankAccount extends Account
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load record from database for the API
|
||||
*
|
||||
* @param int $id Id of record
|
||||
* @param int $socid Id of company. If this is filled, function will return the first default RIB of company
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*/
|
||||
function fetchFromApi($id, $socid=0)
|
||||
{
|
||||
if (empty($id) && empty($socid)) return -1;
|
||||
|
||||
$sql = "SELECT rowid, fk_soc, bank, number, code_banque, code_guichet, cle_rib, bic, iban_prefix as iban, domiciliation, proprio,";
|
||||
$sql.= " owner_address, default_rib, label, datec, tms as datem, rum, frstrecur";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."societe_rib";
|
||||
if ($id) $sql.= " WHERE rowid = ".$id;
|
||||
if ($socid) $sql.= " AND fk_soc = ".$socid;
|
||||
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
if ($this->db->num_rows($resql))
|
||||
{
|
||||
$obj = $this->db->fetch_object($resql);
|
||||
|
||||
$this->ref = $obj->fk_soc.'-'.$obj->label; // Generate an artificial ref
|
||||
|
||||
$this->id = $obj->rowid;
|
||||
$this->type = $obj->type;
|
||||
$this->socid = $obj->fk_soc;
|
||||
$this->bank = $obj->bank;
|
||||
$this->code_banque = $obj->code_banque;
|
||||
$this->code_guichet = $obj->code_guichet;
|
||||
$this->number = $obj->number;
|
||||
$this->cle_rib = $obj->cle_rib;
|
||||
$this->bic = $obj->bic;
|
||||
$this->iban = $obj->iban;
|
||||
$this->domiciliation = $obj->domiciliation;
|
||||
$this->proprio = $obj->proprio;
|
||||
$this->owner_address = $obj->owner_address;
|
||||
$this->label = $obj->label;
|
||||
$this->default_rib = $obj->default_rib;
|
||||
$this->datec = $this->db->jdate($obj->datec);
|
||||
$this->datem = $this->db->jdate($obj->datem);
|
||||
$this->rum = $obj->rum;
|
||||
$this->frstrecur = $obj->frstrecur;
|
||||
}
|
||||
$this->db->free($resql);
|
||||
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
dol_print_error($this->db);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a rib from database
|
||||
*
|
||||
|
||||
Loading…
Reference in New Issue
Block a user