diff --git a/htdocs/admin/facture.php b/htdocs/admin/facture.php
index dee1789d6ec..46ca2b9fd87 100644
--- a/htdocs/admin/facture.php
+++ b/htdocs/admin/facture.php
@@ -750,6 +750,20 @@ print '\n";
print '';
+// Add js auto fill amount on paiement form
+$var=! $var;
+print '
';
+
$var=! $var;
print '';
-// Add js auto fill amount on paiement form
-$var=! $var;
-print '';
-
print '';
diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php
index de90cc068ea..29788e14408 100644
--- a/htdocs/compta/facture.php
+++ b/htdocs/compta/facture.php
@@ -713,7 +713,8 @@ if (empty($reshook))
// Credit note invoice
if ($_POST['type'] == Facture::TYPE_CREDIT_NOTE)
{
- if (! ($_POST['fac_avoir'] > 0))
+ $sourceinvoice = GETPOST('fac_avoir');
+ if (! ($sourceinvoice > 0) && empty($conf->global->INVOICE_CREDIT_NOTE_STANDALONE))
{
$error ++;
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CorrectInvoice")), null, 'errors');
@@ -746,7 +747,7 @@ if (empty($reshook))
$object->location_incoterms = GETPOST('location_incoterms', 'alpha');
// Proprietes particulieres a facture avoir
- $object->fk_facture_source = $_POST['fac_avoir'];
+ $object->fk_facture_source = $sourceinvoice > 0 ? $sourceinvoice : '';
$object->type = Facture::TYPE_CREDIT_NOTE;
$id = $object->create($user);
@@ -2033,7 +2034,7 @@ if ($action == 'create')
$newinvoice_static->paye = $valarray ['paye'];
$optionsav .= '