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.
This commit is contained in:
parent
d842d05639
commit
3cbeca26e7
@ -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;
|
||||
}
|
||||
|
||||
@ -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 '</div>';
|
||||
|
||||
|
||||
|
||||
print '<div class="fichecenter"><div class="fichehalfleft">';
|
||||
print '<a name="builddoc"></a>'; // ancre
|
||||
|
||||
// Linked object block
|
||||
$somethingshown = $form->showLinkedObjectBlock($object);
|
||||
|
||||
print '</div></div>';
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -970,7 +999,7 @@ else
|
||||
print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
|
||||
print '<input type="hidden" name="viewstatut" value="'.$viewstatut.'">';
|
||||
|
||||
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").'<br><br>';
|
||||
|
||||
|
||||
@ -319,7 +319,6 @@ toolTipFrequency=Examples:<br /><b>Set 7 / day</b>: 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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user