Debug v19

This commit is contained in:
Laurent Destailleur 2023-10-05 16:32:38 +02:00
parent 553776a77a
commit a2b6532c5a
3 changed files with 11 additions and 8 deletions

View File

@ -243,7 +243,9 @@ if (empty($reshook)) {
$oldinvoice = new Facture($db);
$oldinvoice->fetch(GETPOST('facid', 'int'));
$result = $object->create($user, $oldinvoice->id);
$onlylines = GETPOST('toselect', 'array');
$result = $object->create($user, $oldinvoice->id, 0, $onlylines);
if ($result > 0) {
$result = $oldinvoice->delete($user, 1);
if ($result < 0) {

View File

@ -232,9 +232,10 @@ class FactureRec extends CommonInvoice
* @param User $user User object
* @param int $facid Id of source invoice
* @param int $notrigger No trigger
* @param array $onlylines Only the lines of the array
* @return int <0 if KO, id of invoice created if OK
*/
public function create($user, $facid, $notrigger = 0)
public function create($user, $facid, $notrigger = 0, $onlylines = array())
{
global $conf;
@ -336,12 +337,11 @@ class FactureRec extends CommonInvoice
$this->multicurrency_tx = $facsrc->multicurrency_tx;
// Add lines
$selectedLines = GETPOST('toselect', 'array');
$fk_parent_line = 0;
$num = count($facsrc->lines);
for ($i = 0; $i < $num; $i++) {
if (!in_array($facsrc->lines[$i]->id, $selectedLines)) {
if (!empty($onlylines) && !in_array($facsrc->lines[$i]->id, $onlylines)) {
continue; // Skip unselected lines
}

View File

@ -519,7 +519,7 @@ class Facture extends CommonInvoice
$nextdatewhen = null;
$previousdaynextdatewhen = null;
// Create invoice from a template recurring invoice
// Erase some properties of the invoice to create with the one of the recurring invoice
if ($this->fac_rec > 0) {
$this->fk_fac_rec_source = $this->fac_rec;
@ -796,7 +796,7 @@ class Facture extends CommonInvoice
if (!$error && empty($this->fac_rec) && count($this->lines) && is_object($this->lines[0])) { // If this->lines is array of InvoiceLines (preferred mode)
$fk_parent_line = 0;
dol_syslog("There is ".count($this->lines)." lines that are invoice lines objects");
dol_syslog("There is ".count($this->lines)." lines into ->lines that are InvoiceLines");
foreach ($this->lines as $i => $val) {
$newinvoiceline = $this->lines[$i];
@ -884,7 +884,7 @@ class Facture extends CommonInvoice
} elseif (!$error && empty($this->fac_rec)) { // If this->lines is an array of invoice line arrays
$fk_parent_line = 0;
dol_syslog("There is ".count($this->lines)." lines that are array lines");
dol_syslog("There is ".count($this->lines)." lines into ->lines as a simple array");
foreach ($this->lines as $i => $val) {
$line = $this->lines[$i];
@ -969,9 +969,10 @@ class Facture extends CommonInvoice
}
/*
* Insert lines of template invoices
* Insert lines coming from the template invoice
*/
if (!$error && $this->fac_rec > 0) {
dol_syslog("There is ".count($_facrec->lines)." lines from recurring invoice");
$fk_parent_line = 0;
foreach ($_facrec->lines as $i => $val) {