From d3a63420340700504138f598eaad482aea7cc881 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 2 Feb 2018 10:33:41 +0100 Subject: [PATCH 1/2] Fix regeneration of PDF after creation of payment. --- htdocs/compta/paiement.php | 2 +- .../compta/paiement/class/paiement.class.php | 42 +++++++++---------- htdocs/core/lib/files.lib.php | 10 ++++- htdocs/fourn/class/paiementfourn.class.php | 26 ++++++++++-- 4 files changed, 53 insertions(+), 27 deletions(-) diff --git a/htdocs/compta/paiement.php b/htdocs/compta/paiement.php index f2e1352cdbb..11751fe258b 100644 --- a/htdocs/compta/paiement.php +++ b/htdocs/compta/paiement.php @@ -257,7 +257,7 @@ if (empty($reshook)) if (! $error) { - $paiement_id = $paiement->create($user, (GETPOST('closepaidinvoices')=='on'?1:0)); // This include closing invoices + $paiement_id = $paiement->create($user, (GETPOST('closepaidinvoices')=='on'?1:0)); // This include closing invoices and regenerating documents if ($paiement_id < 0) { setEventMessages($paiement->error, $paiement->errors, 'errors'); diff --git a/htdocs/compta/paiement/class/paiement.class.php b/htdocs/compta/paiement/class/paiement.class.php index bbdc6f94dfb..00ae831dc3a 100644 --- a/htdocs/compta/paiement/class/paiement.class.php +++ b/htdocs/compta/paiement/class/paiement.class.php @@ -141,7 +141,7 @@ class Paiement extends CommonObject /** * Create payment of invoices into database. * Use this->amounts to have list of invoices for the payment. - * For payment of a customer invoice, amounts are postive, for payment of credit note, amounts are negative + * For payment of a customer invoice, amounts are positive, for payment of credit note, amounts are negative * * @param User $user Object user * @param int $closepaidinvoices 1=Also close payed invoices to paid, 0=Do nothing more @@ -233,11 +233,12 @@ class Paiement extends CommonObject $resql=$this->db->query($sql); if ($resql) { + $invoice=new Facture($this->db); + $invoice->fetch($facid); + // If we want to closed payed invoices if ($closepaidinvoices) { - $invoice=new Facture($this->db); - $invoice->fetch($facid); $paiement = $invoice->getSommePaiement(); $creditnotes=$invoice->getSumCreditNotesUsed(); $deposits=$invoice->getSumDepositsUsed(); @@ -338,26 +339,25 @@ class Paiement extends CommonObject $error++; } } - } - - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) - { - $outputlangs = $langs; - if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $invoice->thirdparty->default_lang; - if (! empty($newlang)) { - $outputlangs = new Translate("", $conf); - $outputlangs->setDefaultLang($newlang); - } - $ret = $invoice->fetch($id); // Reload to get new records - - $result = $invoice->generateDocument($invoice->modelpdf, $outputlangs); - if ($result < 0) { - setEventMessages($invoice->error, $invoice->errors, 'errors'); - $error++; - } - } } + + // Regenerate documents of invoices + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) + { + $outputlangs = $langs; + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $invoice->thirdparty->default_lang; + if (! empty($newlang)) { + $outputlangs = new Translate("", $conf); + $outputlangs->setDefaultLang($newlang); + } + $ret = $invoice->fetch($facid); // Reload to get new records + $result = $invoice->generateDocument($invoice->modelpdf, $outputlangs); + if ($result < 0) { + setEventMessages($invoice->error, $invoice->errors, 'errors'); + $error++; + } + } } else { diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index 042d1318f77..206d1bb8099 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -1706,7 +1706,15 @@ function dol_convert_file($fileinput, $ext='png', $fileoutput='') if (empty($fileoutput)) $fileoutput=$fileinput.".".$ext; $count = $image->getNumberImages(); - $ret = $image->writeImages($fileoutput, true); + + if (! dol_is_file($fileoutput) || is_writeable($fileoutput)) + { + $ret = $image->writeImages($fileoutput, true); + } + else + { + dol_syslog("Warning: Failed to write cache preview file '.$fileoutput.'. Check permission on file/dir", LOG_ERR); + } if ($ret) return $count; else return -3; } diff --git a/htdocs/fourn/class/paiementfourn.class.php b/htdocs/fourn/class/paiementfourn.class.php index 6d402598284..fc917e112f7 100644 --- a/htdocs/fourn/class/paiementfourn.class.php +++ b/htdocs/fourn/class/paiementfourn.class.php @@ -210,11 +210,12 @@ class PaiementFourn extends Paiement $resql=$this->db->query($sql); if ($resql) { + $invoice=new FactureFournisseur($this->db); + $invoice->fetch($facid); + // If we want to closed payed invoices if ($closepaidinvoices) { - $invoice=new FactureFournisseur($this->db); - $invoice->fetch($facid); $paiement = $invoice->getSommePaiement(); //$creditnotes=$invoice->getSumCreditNotesUsed(); $creditnotes=0; @@ -228,17 +229,34 @@ class PaiementFourn extends Paiement } else dol_syslog("Remain to pay for invoice ".$facid." not null. We do nothing."); } + + // Regenerate documents of invoices + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) + { + $outputlangs = $langs; + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $invoice->thirdparty->default_lang; + if (! empty($newlang)) { + $outputlangs = new Translate("", $conf); + $outputlangs->setDefaultLang($newlang); + } + $ret = $invoice->fetch($facid); // Reload to get new records + $result = $invoice->generateDocument($invoice->modelpdf, $outputlangs); + if ($result < 0) { + setEventMessages($invoice->error, $invoice->errors, 'errors'); + $error++; + } + } } else { - dol_syslog('Paiement::Create Erreur INSERT dans paiement_facture '.$facid); + $this->error=$this->db->lasterror(); $error++; } } else { - dol_syslog('PaiementFourn::Create Montant non numerique',LOG_ERR); + dol_syslog(get_class($this).'::Create Amount line '.$key.' not a number. We discard it.'); } } From 4ea4419cd66e820dfcdbfc75fe63d7ef32c7caaa Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 2 Feb 2018 10:39:50 +0100 Subject: [PATCH 2/2] Update changelog --- ChangeLog | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ChangeLog b/ChangeLog index be3e87bfa6c..2cf9f178a16 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,8 @@ English Dolibarr ChangeLog ***** ChangeLog for 7.0.0 compared to 6.0.5 ***** For users: +NEW: When payment is registered, PDF of invoices are also regenerated so payments + appears with no need to click on regenerate. NEW: #5711 Add shipment line deleting and editing for draft shipments. NEW: Accept substitution key __[ABC]__ replaced with value of const ABC NEW: Accountancy Add variant on sell account for intracommunity sales & export sales