From 51456741d97337329bde1f8fd0b8fa8861db1036 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 30 Jun 2021 12:43:44 +0200 Subject: [PATCH] FIX Can't edit replacement invoice FIX Status of invoice when making a replacement invoice --- htdocs/compta/facture/card.php | 6 ++--- htdocs/compta/facture/class/facture.class.php | 26 +++++++++++------- htdocs/core/tpl/objectline_edit.tpl.php | 27 ++++++++++++++----- 3 files changed, 39 insertions(+), 20 deletions(-) diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index 54994eaf187..b3a33b11d1b 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -3131,10 +3131,10 @@ if ($action == 'create') foreach ($facids as $facparam) { $options .= ''; } } diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 4ae9fe197fe..63a7b2f8e21 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -3927,8 +3927,8 @@ class Facture extends CommonInvoice * Invoices matching the following rules are returned: * (Status validated or abandonned for a reason 'other') + not payed + no payment at all + not already replaced * - * @param int $socid Id thirdparty - * @return array|int Array of invoices ('id'=>id, 'ref'=>ref, 'status'=>status, 'paymentornot'=>0/1) + * @param int $socid Id thirdparty + * @return array|int Array of invoices ('id'=>id, 'ref'=>ref, 'status'=>status, 'paymentornot'=>0/1) */ public function list_replacable_invoices($socid = 0) { @@ -3937,17 +3937,19 @@ class Facture extends CommonInvoice $return = array(); - $sql = "SELECT f.rowid as rowid, f.ref, f.fk_statut,"; + $sql = "SELECT f.rowid as rowid, f.ref, f.fk_statut as status, f.paye as paid,"; $sql .= " ff.rowid as rowidnext"; + //$sql .= ", SUM(pf.amount) as alreadypaid"; $sql .= " FROM ".MAIN_DB_PREFIX."facture as f"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON f.rowid = pf.fk_facture"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture as ff ON f.rowid = ff.fk_facture_source"; $sql .= " WHERE (f.fk_statut = ".self::STATUS_VALIDATED." OR (f.fk_statut = ".self::STATUS_ABANDONED." AND f.close_code = '".self::CLOSECODE_ABANDONED."'))"; $sql .= " AND f.entity IN (".getEntity('invoice').")"; - $sql .= " AND f.paye = 0"; // Pas classee payee completement - $sql .= " AND pf.fk_paiement IS NULL"; // Aucun paiement deja fait - $sql .= " AND ff.fk_statut IS NULL"; // Renvoi vrai si pas facture de remplacement - if ($socid > 0) $sql .= " AND f.fk_soc = ".$socid; + $sql .= " AND f.paye = 0"; // Not paid completely + $sql .= " AND pf.fk_paiement IS NULL"; // No payment already done + $sql .= " AND ff.fk_statut IS NULL"; // Return true if it is not a replacement invoice + if ($socid > 0) $sql .= " AND f.fk_soc = ".((int) $socid); + //$sql .= " GROUP BY f.rowid, f.ref, f.fk_statut, f.paye, ff.rowid"; $sql .= " ORDER BY f.ref"; dol_syslog(get_class($this)."::list_replacable_invoices", LOG_DEBUG); @@ -3956,9 +3958,13 @@ class Facture extends CommonInvoice { while ($obj = $this->db->fetch_object($resql)) { - $return[$obj->rowid] = array('id' => $obj->rowid, - 'ref' => $obj->ref, - 'status' => $obj->fk_statut); + $return[$obj->rowid] = array( + 'id' => $obj->rowid, + 'ref' => $obj->ref, + 'status' => $obj->status, + 'paid' => $obj->paid, + 'alreadypaid' => 0 + ); } //print_r($return); return $return; diff --git a/htdocs/core/tpl/objectline_edit.tpl.php b/htdocs/core/tpl/objectline_edit.tpl.php index bc6b87a3353..685cc78fe67 100644 --- a/htdocs/core/tpl/objectline_edit.tpl.php +++ b/htdocs/core/tpl/objectline_edit.tpl.php @@ -109,9 +109,16 @@ $coldisplay++; $reshook = $hookmanager->executeHooks('formEditProductOptions', $parameters, $this, $action); } + $situationinvoicelinewithparent = 0; + if ($line->fk_prev_id != null && in_array($object->element, array('facture', 'facturedet'))) { + if ($object->type == $object::TYPE_SITUATION) { // The constant TYPE_SITUATION exists only for object invoice + // Set constant to disallow editing during a situation cycle + $situationinvoicelinewithparent = 1; + } + } + // Do not allow editing during a situation cycle - if ($line->fk_prev_id == null) - { + if (!$situationinvoicelinewithparent) { // editor wysiwyg require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; $nbrows = ROWS_2; @@ -149,7 +156,7 @@ $coldisplay++; } $coldisplay++; - if ($line->fk_prev_id == null) { + if (!$situationinvoicelinewithparent) { print ''.$form->load_tva('tva_tx', $line->tva_tx.($line->vat_src_code ? (' ('.$line->vat_src_code.')') : ''), $seller, $buyer, 0, $line->info_bits, $line->product_type, false, 1).''; } else { print '%'; @@ -157,7 +164,9 @@ $coldisplay++; $coldisplay++; print 'fk_prev_id != null) print ' readonly'; + if ($situationinvoicelinewithparent) { + print ' readonly'; + } print '>'; if (!empty($conf->multicurrency->enabled) && $this->multicurrency_code != $conf->currency) { @@ -176,12 +185,14 @@ $coldisplay++; info_bits & 2) != 2) { - // I comment this because it shows info even when not required + // I comment warning of stock because it shows the info even when it should not. // for example always visible on invoice but must be visible only if stock module on and stock decrease option is on invoice validation and status is not validated // must also not be output for most entities (proposal, intervention, ...) //if($line->qty > $line->stock) print img_picto($langs->trans("StockTooLow"),"warning", 'style="vertical-align: bottom;"')." "; print 'fk_prev_id != null) print ' readonly'; + if ($situationinvoicelinewithparent) { // Do not allow editing during a situation cycle + print ' readonly'; + } print '>'; } else { ?>   @@ -202,7 +213,9 @@ $coldisplay++; info_bits & 2) != 2) { print 'fk_prev_id != null) print ' readonly'; + if ($situationinvoicelinewithparent) { + print ' readonly'; + } print '>%'; } else { ?>