From 3cbeca26e72b63c959827ccc9186d263be74da77 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 3 Mar 2016 13:16:46 +0100 Subject: [PATCH] NEW When creating a template invoice from a draft invoice, if there is link to contract on draft invoice, link is kept on template invoice. --- .../facture/class/facture-rec.class.php | 20 ++++++++--- htdocs/compta/facture/fiche-rec.php | 35 +++++++++++++++++-- htdocs/langs/en_US/bills.lang | 1 - 3 files changed, 48 insertions(+), 8 deletions(-) diff --git a/htdocs/compta/facture/class/facture-rec.class.php b/htdocs/compta/facture/class/facture-rec.class.php index 14ec77600c7..ac2345e250a 100644 --- a/htdocs/compta/facture/class/facture-rec.class.php +++ b/htdocs/compta/facture/class/facture-rec.class.php @@ -163,9 +163,7 @@ class FactureRec extends Facture { $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."facture_rec"); - /* - * Lines - */ + // Add lines $num=count($facsrc->lines); for ($i = 0; $i < $num; $i++) { @@ -192,6 +190,20 @@ class FactureRec extends Facture $error++; } } + + // Add object linked + if (! $error && $this->id && is_array($this->linked_objects) && ! empty($this->linked_objects)) + { + foreach($this->linked_objects as $origin => $origin_id) + { + $ret = $this->add_object_linked($origin, $origin_id); + if (! $ret) + { + $this->error=$this->db->lasterror(); + $error++; + } + } + } if ($error) { @@ -205,7 +217,7 @@ class FactureRec extends Facture } else { - $this->error=$this->db->error().' sql='.$sql; + $this->error=$this->db->lasterror(); $this->db->rollback(); return -2; } diff --git a/htdocs/compta/facture/fiche-rec.php b/htdocs/compta/facture/fiche-rec.php index 76f796f78b6..4e753433419 100644 --- a/htdocs/compta/facture/fiche-rec.php +++ b/htdocs/compta/facture/fiche-rec.php @@ -121,12 +121,31 @@ if ($action == 'add') $date_next_execution = dol_mktime($rehour, $remin, 0, $remonth, $reday, $reyear); $object->date_when = $date_next_execution; + + // Get first contract linked to invoice used to generate template + if (GETPOST('facid','int') > 0) + { + $srcObject = new Facture($db); + $srcObject->fetch(GETPOST('facid','int')); + + $srcObject->fetchObjectLinked(); + + if (! empty($srcObject->linkedObjectsIds['contrat'])) + { + $contractidid = reset($srcObject->linkedObjectsIds['contrat']); + } + + $object->origin = 'contrat'; + $object->origin_id = $contractidid; + $object->linked_objects[$object->origin] = $object->origin_id; + } if ($object->create($user, $id) > 0) { $id = $object->id; - header("Location: " . $_SERVER['PHP_SELF'] . '?facid=' . $id); - exit; + + header("Location: " . $_SERVER['PHP_SELF'] . '?facid=' . $id); + exit; } else { @@ -932,6 +951,16 @@ else print ''; + + + print '
'; + print ''; // ancre + + // Linked object block + $somethingshown = $form->showLinkedObjectBlock($object); + + print '
'; + } else { @@ -970,7 +999,7 @@ else print ''; print ''; - print_barre_liste($langs->trans("RepeatableInvoices"),$page,$_SERVER['PHP_SELF'],$param,$sortfield,$sortorder,'',$num,$nbtotalofrecord,'title_accountancy.png',0,'','',$limit); + print_barre_liste($langs->trans("RepeatableInvoices"),$page,$_SERVER['PHP_SELF'],$param,$sortfield,$sortorder,'',$num,$nbtotalofrecord,'title_accountancy.png',0,'','',$limit); print $langs->trans("ToCreateAPredefinedInvoice").'

'; diff --git a/htdocs/langs/en_US/bills.lang b/htdocs/langs/en_US/bills.lang index ec04f9e2596..d757137fb7b 100644 --- a/htdocs/langs/en_US/bills.lang +++ b/htdocs/langs/en_US/bills.lang @@ -319,7 +319,6 @@ toolTipFrequency=Examples:
Set 7 / day: give a new invoice every 7 d NextDateToExecution=Date for next invoice generation DateLastGeneration=Date of last generation MaxPeriodNumber=Max nb of invoice generation -RestPeriodNumber=Rest period number NbOfGenerationDone=Nb of invoice generation already done InvoiceAutoValidate=Automatically validate invoice GeneratedFromRecurringInvoice=Generated from template recurring invoice %s