From ffaf748ac8450bdbe74d95760b47ac3fc2b57441 Mon Sep 17 00:00:00 2001 From: Romain Neil Date: Mon, 1 May 2023 19:45:33 +0200 Subject: [PATCH 1/6] feat(api/documents): upload contract --- htdocs/api/class/api_documents.class.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/htdocs/api/class/api_documents.class.php b/htdocs/api/class/api_documents.class.php index d7fd1ea7118..01677456cb3 100644 --- a/htdocs/api/class/api_documents.class.php +++ b/htdocs/api/class/api_documents.class.php @@ -672,6 +672,10 @@ class Documents extends DolibarrApi require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; $object = new Contact($this->db); $fetchbyid = true; + } elseif ($modulepart == 'contrat' || $modulepart == 'contract') { + $modulepart = 'contrat'; + require_once DOL_DOCUMENT_ROOT . '/contrat/class/contrat.class.php'; + $object = new Contrat($this->db); } else { // TODO Implement additional moduleparts throw new RestException(500, 'Modulepart '.$modulepart.' not implemented yet.'); From 458fb18b5d905246a2834cb95f0e1c2ef69f9e5c Mon Sep 17 00:00:00 2001 From: Romain Neil Date: Mon, 1 May 2023 20:10:48 +0200 Subject: [PATCH 2/6] feat(api/documents): list contract --- htdocs/api/class/api_documents.class.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/htdocs/api/class/api_documents.class.php b/htdocs/api/class/api_documents.class.php index 01677456cb3..042b48707fb 100644 --- a/htdocs/api/class/api_documents.class.php +++ b/htdocs/api/class/api_documents.class.php @@ -502,6 +502,17 @@ class Documents extends DolibarrApi // $upload_dir = $conf->ecm->dir_output; // $type = 'all'; // $recursive = 0; + } elseif($modulepart == 'contrat' || $modulepart == 'contract') { + $modulepart = 'contrat'; + require_once DOL_DOCUMENT_ROOT . '/contrat/class/contrat.class.php'; + + $object = new Contrat($this->db); + $result = $object->fetch($id, $ref); + if (!$result) { + throw new RestException(404, 'Contract not found'); + } + + $upload_dir = $conf->contrat->dir_output . "/" . get_exdir(0, 0, 0, 1, $object, 'contract'); } else { throw new RestException(500, 'Modulepart '.$modulepart.' not implemented yet.'); } From 1f8671ed84afb2121e2d595311fed3b85057f02d Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Mon, 1 May 2023 18:11:31 +0000 Subject: [PATCH 3/6] Fixing style errors. --- htdocs/api/class/api_documents.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/api/class/api_documents.class.php b/htdocs/api/class/api_documents.class.php index 042b48707fb..1ee47667b46 100644 --- a/htdocs/api/class/api_documents.class.php +++ b/htdocs/api/class/api_documents.class.php @@ -502,7 +502,7 @@ class Documents extends DolibarrApi // $upload_dir = $conf->ecm->dir_output; // $type = 'all'; // $recursive = 0; - } elseif($modulepart == 'contrat' || $modulepart == 'contract') { + } elseif ($modulepart == 'contrat' || $modulepart == 'contract') { $modulepart = 'contrat'; require_once DOL_DOCUMENT_ROOT . '/contrat/class/contrat.class.php'; From a4fd13e3e46ebed071312333a41a73a81fff7d3f Mon Sep 17 00:00:00 2001 From: Romain Neil Date: Mon, 1 May 2023 22:11:27 +0200 Subject: [PATCH 4/6] feat(api/documents): build contract --- htdocs/api/class/api_documents.class.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/htdocs/api/class/api_documents.class.php b/htdocs/api/class/api_documents.class.php index 1ee47667b46..fbfde850935 100644 --- a/htdocs/api/class/api_documents.class.php +++ b/htdocs/api/class/api_documents.class.php @@ -221,6 +221,22 @@ class Documents extends DolibarrApi if ($result <= 0) { throw new RestException(500, 'Error generating document'); } + } elseif ($modulepart == 'contrat' || $modulepart == 'contract') { + require_once DOL_DOCUMENT_ROOT . '/contrat/class/contrat.class.php'; + + $this->contract = new Contrat($this->db); + $result = $this->contract->fetch(0, preg_replace('/\.[^\.]+$/', '', basename($original_file))); + + if (!$result) { + throw new RestException(404, 'Contract not found'); + } + + $templateused = $doctemplate ? $doctemplate : $this->contract->model_pdf; + $result = $this->contract->generateDocument($templateused, $outputlangs, $hidedetails, $hidedesc, $hideref); + + if ($result <= 0) { + throw new RestException(500, 'Error generating document missing doctemplate parameter'); + } } else { throw new RestException(403, 'Generation not available for this modulepart'); } From 1487c233f0c4a741d04556b0addc33f3a7d6aa21 Mon Sep 17 00:00:00 2001 From: rneil Date: Tue, 2 May 2023 00:56:10 +0200 Subject: [PATCH 5/6] add missing copyright --- htdocs/api/class/api_documents.class.php | 1 + 1 file changed, 1 insertion(+) diff --git a/htdocs/api/class/api_documents.class.php b/htdocs/api/class/api_documents.class.php index fbfde850935..02955c21c77 100644 --- a/htdocs/api/class/api_documents.class.php +++ b/htdocs/api/class/api_documents.class.php @@ -2,6 +2,7 @@ /* Copyright (C) 2016 Xebax Christy * Copyright (C) 2016 Laurent Destailleur * Copyright (C) 2016 Jean-François Ferry + * COpyright (C) 2023 Romain Neil * * 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 2c13d26b69c376704553ad1bc86f22a8fd8cb659 Mon Sep 17 00:00:00 2001 From: Romain Neil Date: Tue, 2 May 2023 00:59:51 +0200 Subject: [PATCH 6/6] Update api_documents.class.php typo fix --- htdocs/api/class/api_documents.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/api/class/api_documents.class.php b/htdocs/api/class/api_documents.class.php index 02955c21c77..1bab0c282e6 100644 --- a/htdocs/api/class/api_documents.class.php +++ b/htdocs/api/class/api_documents.class.php @@ -2,7 +2,7 @@ /* Copyright (C) 2016 Xebax Christy * Copyright (C) 2016 Laurent Destailleur * Copyright (C) 2016 Jean-François Ferry - * COpyright (C) 2023 Romain Neil + * Copyright (C) 2023 Romain Neil * * 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