Bonjour à vous,
J’aimerais, depuis l’api, générer puis envoyer au client qui se sert de l’api un mandat sepa.
Le téléchargement et l’envoie du mandat sepa pour moi n’est pas un problème. Il me suffira de le transformer en base 64 et de l’envoyer dans un json.
Cependant, je souhaite générer le mandat sepa depuis l’api. je veux générer le même fichier que celui qui est généré à cette page societe/rib.php?socid={id}#builddoc.
Quelqu’un pourrait-il me venir en aide s’il vous plaît?
voici mon code.
PS: si le message n’est pas approprié pour le forum, merci de m’indiquer où je pourrais me renseigner d’avantage.
Merci d’avance pour vos réponses
<?php
/* Copyright (C) 2015 Jean-François Ferry <[email protected]>
* Copyright (C) 2018 CHENE Pierre
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
use Luracast\Restler\RestException;
require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php';
/**
* API class for apigenrib
*
* @smart-auto-routing false
* @access protected
* @class DolibarrApiAccess {@requires user,external}
*/
class ApiGenRibApi extends DolibarrApi
{
public function __construct()
{
global $db;
$this->db = $db;
}
/**
* Generate a sepamandate Document
*
* @param int $socid thirdparty id
*
* @return array Check success
*
* @url GET /generateMandat/{socid}
*/
public function generateMandat($socid){
$model = "sepamandate";
$object = new Societe($this->db);
$object->fetch($socid);
$action = 'builddoc';
$upload_dir = $conf->societe->multidir_output[$object->entity];
if(! DolibarrApiAccess::$user->rights->societe->creer)
throw new RestException(401);
// Reload to get all modified line records and be ready for hooks
$ret = $object->fetch($id);
$ret = $object->fetch_thirdparty();
$object->setDocModel($user, $model);
$object->fk_bank = $object->fk_account;
$outputlangs = $langs;
$newlang='';
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang=GETPOST('lang_id','aZ09');
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && isset($object->thirdparty->default_lang)) $newlang=$object->thirdparty->default_lang; // for proposal, order, invoice, ...
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && isset($object->default_lang)) $newlang=$object->default_lang; // for thirdparty
if (! empty($newlang))
{
$outputlangs = new Translate("",$conf);
$outputlangs->setDefaultLang($newlang);
}
// To be sure vars is defined
if (empty($hidedetails)) $hidedetails=0;
if (empty($hidedesc)) $hidedesc=0;
if (empty($hideref)) $hideref=0;
if (empty($moreparams)) $moreparams=null;
$sql = "SELECT rowid";
$sql.= " FROM ".MAIN_DB_PREFIX."societe_rib";
if ($socid) $sql.= " WHERE fk_soc = ".$socid." ";
$result = $this->db->query($sql);
if($result->num_rows == 0 ){
throw new RestException(404, 'Account not found');
}
$i=0;
$accounts =[];
if ($result)
{
$num = $this->db->num_rows($result);
while ($i < $num)
{
$obj = $this->db->fetch_object($result);
$account = new CompanyBankAccount($this->db);
if($account->fetchFromApi($obj->rowid)) {
$accounts[] = $account;
}
$i++;
}
}
else{
throw new RestException(404, 'Account not found');
}
$moreparams = array(
'use_companybankid'=>$accounts[0]->id,
'force_dir_output'=>$conf->societe->multidir_output[$object->entity].'/'.dol_sanitizeFileName($object->id)
);
$result= $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
return array("result" => $result);
if ($result <= 0)
{
throw new RestException(500);
}
else
{
return array("success" => true);
}
}
}