diff --git a/htdocs/admin/facture.php b/htdocs/admin/facture.php index e993d2c276c..d03dbc1f568 100644 --- a/htdocs/admin/facture.php +++ b/htdocs/admin/facture.php @@ -280,6 +280,24 @@ if ($action == 'set_FAC_AUTO_FILLJS') } } +if ($action == 'set_INVOICE_CREDIT_NOTE_STANDALONE') +{ + $freetext = GETPOST('INVOICE_CREDIT_NOTE_STANDALONE'); // No alpha here, we want exact string + + $res = dolibarr_set_const($db, "INVOICE_CREDIT_NOTE_STANDALONE",$freetext,'chaine',0,'',$conf->entity); + + if (! $res > 0) $error++; + + if (! $error) + { + setEventMessage($langs->trans("SetupSaved")); + } + else + { + setEventMessage($langs->trans("Error"),'errors'); + } +} + /* * View @@ -750,6 +768,34 @@ print '\n"; print ''; +// Add js auto fill amount on paiement form +$var=! $var; +print '
'; + +// Allow to create credit note not related to an invoice +$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 a5f7f1e004d..37812dbf413 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -706,7 +706,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 ++; setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CorrectInvoice")), 'errors'); @@ -739,7 +740,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); @@ -2878,7 +2879,7 @@ else if ($id > 0 || ! empty($ref)) $facreplaced->fetch($object->fk_facture_source); print ' (' . $langs->transnoentities("ReplaceInvoice", $facreplaced->getNomUrl(1)) . ')'; } - if ($object->type == Facture::TYPE_CREDIT_NOTE) { + if ($object->type == Facture::TYPE_CREDIT_NOTE && !empty($object->fk_facture_source)) { $facusing = new Facture($db); $facusing->fetch($object->fk_facture_source); print ' (' . $langs->transnoentities("CorrectInvoice", $facusing->getNomUrl(1)) . ')'; diff --git a/htdocs/core/modules/facture/doc/pdf_crabe.modules.php b/htdocs/core/modules/facture/doc/pdf_crabe.modules.php index aa9fbf65ed2..74d73d5d497 100644 --- a/htdocs/core/modules/facture/doc/pdf_crabe.modules.php +++ b/htdocs/core/modules/facture/doc/pdf_crabe.modules.php @@ -1500,7 +1500,7 @@ class pdf_crabe extends ModelePDFFactures $pdf->SetTextColor(0,0,60); $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ReplacementInvoice").' : '.$outputlangs->convToOutputCharset($objectreplaced->ref), '', 'R'); } - if ($object->type == 2) + if ($object->type == 2 && !empty($object->fk_facture_source)) { $objectreplaced=new Facture($this->db); $objectreplaced->fetch($object->fk_facture_source); diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index 3bf2d5a14b5..bf1010f767b 100755 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -1165,6 +1165,7 @@ CreditNotePDFModules=Credit note document models CreditNote=Credit note CreditNotes=Credit notes ForceInvoiceDate=Force invoice date to validation date +AllowCreditNoteWithoutRelatedInvoice=Allow to create credit note without a related invoice DisableRepeatable=Disable repeatable invoices SuggestedPaymentModesIfNotDefinedInInvoice=Suggested payments mode on invoice by default if not defined for invoice EnableEditDeleteValidInvoice=Enable the possibility to edit/delete valid invoice with no payment