From 294f14ab63010b840ba3d5a219a9dcefdba45073 Mon Sep 17 00:00:00 2001 From: "STAGIAIRE-PC\\Pierre" Date: Thu, 19 Jul 2018 15:09:32 +0200 Subject: [PATCH 1/7] Generation of the mandate file from the api --- .../societe/class/api_thirdparties.class.php | 121 ++++++++++++++++++ 1 file changed, 121 insertions(+) diff --git a/htdocs/societe/class/api_thirdparties.class.php b/htdocs/societe/class/api_thirdparties.class.php index 3faf2f14994..1510c9c2b03 100644 --- a/htdocs/societe/class/api_thirdparties.class.php +++ b/htdocs/societe/class/api_thirdparties.class.php @@ -1170,6 +1170,127 @@ class Thirdparties extends DolibarrApi return $account->delete(DolibarrApiAccess::$user); } + /** + * Generate a sepamandate Document + * + * @param int $socid thirdparty id + * + * @return array Check success + * + * @url GET /generateMandat/{socid} + */ + public function generateMandat($socid){ + + $this->langs->load("database"); + $this->langs->load("main"); + $this->langs->load("dict"); + $this->langs->load("agenda"); + $this->langs->load("margins"); + $this->langs->load("resource"); + $this->langs->load("commercial"); + $this->langs->load("ecm"); + $this->langs->load("products"); + $this->langs->load("companies"); + $this->langs->load("banks"); + $this->langs->load("bills"); + $this->langs->load("withdrawals"); + + + $model = "sepamandate"; + + $this->company->fetch($socid); + + $action = 'builddoc'; + if(! DolibarrApiAccess::$user->rights->societe->creer) + throw new RestException(401); + + + // Reload to get all modified line records and be ready for hooks + + + $this->company->setDocModel($user, $model); + + $this->company->fk_bank = $this->company->fk_account; + + $outputlangs = $this->langs; + $newlang=''; + + + + if ($this->conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang=GETPOST('lang_id','aZ09'); + if ($this->conf->global->MAIN_MULTILANGS && empty($newlang) && isset($this->company->thirdparty->default_lang)) $newlang=$this->company->thirdparty->default_lang; // for proposal, order, invoice, ... + if ($this->conf->global->MAIN_MULTILANGS && empty($newlang) && isset($this->company->default_lang)) $newlang=$this->company->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'=>$this->conf->societe->multidir_output[$this->company->entity].'/'.dol_sanitizeFileName($this->company->id) + ); + + + + + $result = 0; + + + + + $result = $this->company->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams); + + if ($result > 0) + { + return array("success" => $result); + } + else + { + throw new RestException(500); + } + } + /** * Clean sensible object datas From d8b212897b5583d57ee9c268a57e15b1e7b24dbe Mon Sep 17 00:00:00 2001 From: "STAGIAIRE-PC\\Pierre" Date: Thu, 19 Jul 2018 15:13:55 +0200 Subject: [PATCH 2/7] ajout de credits --- htdocs/societe/class/api_thirdparties.class.php | 1 + 1 file changed, 1 insertion(+) diff --git a/htdocs/societe/class/api_thirdparties.class.php b/htdocs/societe/class/api_thirdparties.class.php index 1510c9c2b03..e2e6a497a41 100644 --- a/htdocs/societe/class/api_thirdparties.class.php +++ b/htdocs/societe/class/api_thirdparties.class.php @@ -1,5 +1,6 @@ + * Copyright (C) 2015 Pierre Chéné * * 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 From df6ad4426181a819d7c44dcfcf8b181eb6c70232 Mon Sep 17 00:00:00 2001 From: "STAGIAIRE-PC\\Pierre" Date: Thu, 19 Jul 2018 15:15:54 +0200 Subject: [PATCH 3/7] =?UTF-8?q?correction=20de=20l'ann=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/societe/class/api_thirdparties.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/societe/class/api_thirdparties.class.php b/htdocs/societe/class/api_thirdparties.class.php index e2e6a497a41..bacdd330041 100644 --- a/htdocs/societe/class/api_thirdparties.class.php +++ b/htdocs/societe/class/api_thirdparties.class.php @@ -1,6 +1,6 @@ - * Copyright (C) 2015 Pierre Chéné + * Copyright (C) 2018 Pierre Chéné * * 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 From ff8d31925b191e20d509e0eb07d2e227bba5bf67 Mon Sep 17 00:00:00 2001 From: "STAGIAIRE-PC\\Pierre" Date: Mon, 30 Jul 2018 09:37:41 +0200 Subject: [PATCH 4/7] ajout du parametre companyBankid --- htdocs/societe/class/api_thirdparties.class.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/htdocs/societe/class/api_thirdparties.class.php b/htdocs/societe/class/api_thirdparties.class.php index bacdd330041..6c5533a9ebf 100644 --- a/htdocs/societe/class/api_thirdparties.class.php +++ b/htdocs/societe/class/api_thirdparties.class.php @@ -1175,12 +1175,13 @@ class Thirdparties extends DolibarrApi * Generate a sepamandate Document * * @param int $socid thirdparty id + * @param int $id companybankid * * @return array Check success * * @url GET /generateMandat/{socid} */ - public function generateMandat($socid){ + public function generateMandat($socid, $id = null){ $this->langs->load("database"); $this->langs->load("main"); @@ -1237,6 +1238,7 @@ class Thirdparties extends DolibarrApi $sql = "SELECT rowid"; $sql.= " FROM ".MAIN_DB_PREFIX."societe_rib"; if ($socid) $sql.= " WHERE fk_soc = ".$socid." "; + if ($id) $sql.= " AND id = ".$id.""; $result = $this->db->query($sql); From 61995a3e02ce7da129d914c53ac0de03bb3c7718 Mon Sep 17 00:00:00 2001 From: "STAGIAIRE-PC\\Pierre" Date: Mon, 30 Jul 2018 17:34:43 +0200 Subject: [PATCH 5/7] Ajout d'une colonne indispensable dans la requete json --- htdocs/societe/class/api_thirdparties.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/societe/class/api_thirdparties.class.php b/htdocs/societe/class/api_thirdparties.class.php index 6c5533a9ebf..125d1faff18 100644 --- a/htdocs/societe/class/api_thirdparties.class.php +++ b/htdocs/societe/class/api_thirdparties.class.php @@ -1057,7 +1057,7 @@ class Thirdparties extends DolibarrApi } - $fields = ['socid', 'default_rib', 'frstrecur', '1000110000001', 'datec', 'datem', 'label', 'bank', 'bic', 'iban', 'id']; + $fields = ['socid', 'default_rib', 'frstrecur', '1000110000001', 'datec', 'datem', 'label', 'bank', 'bic', 'iban', 'id', 'rum']; $returnAccounts = []; From 019ba74225dc719ca63be29197c7e00a9180a6e8 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 19 Sep 2018 14:44:16 +0200 Subject: [PATCH 6/7] Update api_thirdparties.class.php --- .../societe/class/api_thirdparties.class.php | 36 +++++++------------ 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/htdocs/societe/class/api_thirdparties.class.php b/htdocs/societe/class/api_thirdparties.class.php index 58f4933fdea..bd83a10c7bb 100644 --- a/htdocs/societe/class/api_thirdparties.class.php +++ b/htdocs/societe/class/api_thirdparties.class.php @@ -1175,14 +1175,14 @@ class Thirdparties extends DolibarrApi /** * Generate a sepamandate Document * - * @param int $socid thirdparty id - * @param int $id companybankid + * @param int $id thirdparty id + * @param int $companybankid companybankid + * + * @return void * - * @return array Check success - * - * @url GET /generateMandat/{socid} + * @url GET {id}/generateMandat/{companybankid} */ - public function generateMandat($socid, $id = null){ + public function generateMandat($id, $companybankid = null){ $this->langs->load("database"); $this->langs->load("main"); @@ -1201,16 +1201,14 @@ class Thirdparties extends DolibarrApi $model = "sepamandate"; - $this->company->fetch($socid); + $this->company->fetch($id); $action = 'builddoc'; if(! DolibarrApiAccess::$user->rights->societe->creer) throw new RestException(401); - // Reload to get all modified line records and be ready for hooks - - + $this->company->setDocModel($user, $model); $this->company->fk_bank = $this->company->fk_account; @@ -1218,8 +1216,6 @@ class Thirdparties extends DolibarrApi $outputlangs = $this->langs; $newlang=''; - - if ($this->conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang=GETPOST('lang_id','aZ09'); if ($this->conf->global->MAIN_MULTILANGS && empty($newlang) && isset($this->company->thirdparty->default_lang)) $newlang=$this->company->thirdparty->default_lang; // for proposal, order, invoice, ... if ($this->conf->global->MAIN_MULTILANGS && empty($newlang) && isset($this->company->default_lang)) $newlang=$this->company->default_lang; // for thirdparty @@ -1238,10 +1234,9 @@ class Thirdparties extends DolibarrApi $sql = "SELECT rowid"; $sql.= " FROM ".MAIN_DB_PREFIX."societe_rib"; - if ($socid) $sql.= " WHERE fk_soc = ".$socid." "; - if ($id) $sql.= " AND id = ".$id.""; - - + if ($id) $sql.= " WHERE fk_soc = ".$id." "; + if ($companybankid) $sql.= " AND id = ".$companybankid.""; + $result = $this->db->query($sql); if($result->num_rows == 0 ){ @@ -1265,7 +1260,8 @@ class Thirdparties extends DolibarrApi $i++; } } - else{ + else + { throw new RestException(404, 'Account not found'); } @@ -1274,14 +1270,8 @@ class Thirdparties extends DolibarrApi 'use_companybankid'=>$accounts[0]->id, 'force_dir_output'=>$this->conf->societe->multidir_output[$this->company->entity].'/'.dol_sanitizeFileName($this->company->id) ); - - - $result = 0; - - - $result = $this->company->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams); From f240cd130d6b0511eb78f077065ba5256ea13099 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 19 Sep 2018 14:47:11 +0200 Subject: [PATCH 7/7] Update api_thirdparties.class.php --- htdocs/societe/class/api_thirdparties.class.php | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/htdocs/societe/class/api_thirdparties.class.php b/htdocs/societe/class/api_thirdparties.class.php index bd83a10c7bb..931cebc1150 100644 --- a/htdocs/societe/class/api_thirdparties.class.php +++ b/htdocs/societe/class/api_thirdparties.class.php @@ -1173,17 +1173,17 @@ class Thirdparties extends DolibarrApi } /** - * Generate a sepamandate Document + * Generate a Document from a bank account record (like SEPA mandate) * * @param int $id thirdparty id * @param int $companybankid companybankid - * + * @param string $model model of document to generate * @return void * - * @url GET {id}/generateMandat/{companybankid} + * @url GET {id}/generateBankAccountDocument/{companybankid}/{model} */ - public function generateMandat($id, $companybankid = null){ - + public function generateBankAccountDocument($id, $companybankid = null, $model = 'sepamandate') + { $this->langs->load("database"); $this->langs->load("main"); $this->langs->load("dict"); @@ -1198,9 +1198,6 @@ class Thirdparties extends DolibarrApi $this->langs->load("bills"); $this->langs->load("withdrawals"); - - $model = "sepamandate"; - $this->company->fetch($id); $action = 'builddoc';