diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 25d032982a9..b3d365650b5 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -486,14 +486,21 @@ else if ($action == 'confirm_canceled' && $confirm == 'yes') { // Convertir en reduc else if ($action == 'confirm_converttoreduc' && $confirm == 'yes' && $user->rights->facture->creer) { - $db->begin(); - $object->fetch($id); $object->fetch_thirdparty(); $object->fetch_lines(); - if (empty($object->paye)) // protection against multiple submit + // Check if there is already a discount (protection to avoid duplicate creation when resubmit post) + $discountcheck=new DiscountAbsolute($db); + $result=$discountcheck->fetch(0,$object->id); + + $canconvert=0; + if ($object->type == Facture::TYPE_DEPOSIT && $object->paye == 1 && empty($discountcheck->id)) $canconvert=1; // we can convert deposit into discount if deposit is payed completely and not already converted (see real condition into condition used to show button converttoreduc) + if ($object->type == Facture::TYPE_CREDIT_NOTE && $object->paye == 0 && empty($discountcheck->id)) $canconvert=1; // we can convert credit note into discount if credit note is not payed back and not already converted and amount of payment is 0 (see real condition into condition used to show button converttoreduc) + if ($canconvert) { + $db->begin(); + // Boucle sur chaque taux de tva $i = 0; foreach ($object->lines as $line) { @@ -1745,9 +1752,10 @@ if ($action == 'update_extras') { $action = 'edit_extras'; } + /* * View -*/ + */ $form = new Form($db); $formother = new FormOther($db); @@ -1941,10 +1949,12 @@ if ($action == 'create') $options .= ''; } - $facids = $facturestatic->list_qualified_avoir_invoices($soc->id); - if ($facids < 0) { - dol_print_error($db, $facturestatic); - exit(); + // Show link for credit note + $facids=$facturestatic->list_qualified_avoir_invoices($soc->id); + if ($facids < 0) + { + dol_print_error($db,$facturestatic); + exit; } $optionsav = ""; $newinvoice_static = new Facture($db); @@ -3277,10 +3287,11 @@ if ($action == 'create') } // Reopen a standard paid invoice - if (($object->type == Facture::TYPE_STANDARD || $object->type == Facture::TYPE_REPLACEMENT) && ($object->statut == Facture::TYPE_CREDIT_NOTE || $object->statut == Facture::TYPE_DEPOSIT) && $user->rights->facture->creer) // A paid - // invoice - // (partially or - // completely) + if ((($object->type == Facture::TYPE_STANDARD || $object->type == Facture::TYPE_REPLACEMENT) + || ($object->type == Facture::TYPE_CREDIT_NOTE && empty($discount->id)) + || ($object->type == Facture::TYPE_DEPOSIT && empty($discount->id))) + && ($object->statut == 2 || $object->statut == 3) + && $user->rights->facture->creer) // A paid invoice (partially or completely) { if (! $objectidnext && $object->close_code != 'replaced') // Not replaced by another invoice { @@ -3339,30 +3350,47 @@ if ($action == 'create') // Reverse back money or convert to reduction if ($object->type == Facture::TYPE_CREDIT_NOTE || $object->type == Facture::TYPE_DEPOSIT) { // For credit note only - if ($object->type == Facture::TYPE_CREDIT_NOTE && $object->statut == 1 && $object->paye == 0 && $user->rights->facture->paiement) { - print '
' . $langs->trans('DoPaymentBack') . '
'; + if ($object->type == Facture::TYPE_CREDIT_NOTE && $object->statut == 1 && $object->paye == 0 && $user->rights->facture->paiement) + { + if ($resteapayer == 0) + { + print '
'.$langs->trans('DoPaymentBack').'
'; + } + else + { + print '
'.$langs->trans('DoPaymentBack').'
'; + } } + // For credit note if ($object->type == Facture::TYPE_CREDIT_NOTE && $object->statut == 1 && $object->paye == 0 && $user->rights->facture->creer && $object->getSommePaiement() == 0) { print '
' . $langs->trans('ConvertToReduc') . '
'; } // For deposit invoice - if ($object->type == Facture::TYPE_DEPOSIT && $object->statut == 2 && $resteapayer == 0 && $user->rights->facture->creer && empty($discount->id)) { - print '
' . $langs->trans('ConvertToReduc') . '
'; + if ($object->type == Facture::TYPE_DEPOSIT && $object->paye == 1 && $resteapayer == 0 && $user->rights->facture->creer && empty($discount->id)) + { + print '
'.$langs->trans('ConvertToReduc').'
'; } } - // Classify paid (if not deposit and not credit note. Such invoice are "converted") - if ($object->statut == 1 && $object->paye == 0 && $user->rights->facture->paiement && (($object->type != Facture::TYPE_CREDIT_NOTE && $object->type != Facture::TYPE_DEPOSIT && $resteapayer <= 0) || ($object->type == Facture::TYPE_CREDIT_NOTE && $resteapayer >= 0))) { - print '
' . $langs->trans('ClassifyPaid') . '
'; + // Classify paid + if ($object->statut == 1 && $object->paye == 0 && $user->rights->facture->paiement && (($object->type != Facture::TYPE_CREDIT_NOTE && $object->type != Facture::TYPE_DEPOSIT && $resteapayer <= 0) || ($object->type == Facture::TYPE_CREDIT_NOTE && $resteapayer >= 0)) + || ($object->type == Facture::TYPE_DEPOSIT && $object->paye == 0 && $resteapayer == 0 && $user->rights->facture->paiement && empty($discount->id)) + ) + { + print '
'.$langs->trans('ClassifyPaid').'
'; } // Classify 'closed not completely paid' (possible si validee et pas encore classee payee) - if ($object->statut == 1 && $object->paye == 0 && $resteapayer > 0 && $user->rights->facture->paiement) { - if ($totalpaye > 0 || $totalcreditnotes > 0) { + if ($object->statut == 1 && $object->paye == 0 && $resteapayer > 0 && $user->rights->facture->paiement) + { + if ($totalpaye > 0 || $totalcreditnotes > 0) + { // If one payment or one credit note was linked to this invoice print '
' . $langs->trans('ClassifyPaidPartially') . '
'; - } else { + } + else + { if ($objectidnext) { print '
' . $langs->trans('ClassifyCanceled') . '
'; } else { @@ -3372,19 +3400,23 @@ if ($action == 'create') } // Clone - if (($object->type == Facture::TYPE_STANDARD || $object->type == Facture::TYPE_DEPOSIT || $object->type == Facture::TYPE_PROFORMA) && $user->rights->facture->creer) { + if (($object->type == Facture::TYPE_STANDARD || $object->type == Facture::TYPE_DEPOSIT || $object->type == Facture::TYPE_PROFORMA) && $user->rights->facture->creer) + { print '
' . $langs->trans("ToClone") . '
'; } // Clone as predefined - if (($object->type == Facture::TYPE_STANDARD || $object->type == Facture::TYPE_DEPOSIT || $object->type == Facture::TYPE_PROFORMA) && $object->statut == 0 && $user->rights->facture->creer) { - if (! $objectidnext) { + if (($object->type == Facture::TYPE_STANDARD || $object->type == Facture::TYPE_DEPOSIT || $object->type == Facture::TYPE_PROFORMA) && $object->statut == 0 && $user->rights->facture->creer) + { + if (! $objectidnext) + { print '
' . $langs->trans("ChangeIntoRepeatableInvoice") . '
'; } } // Delete - if ($user->rights->facture->supprimer) { + if ($user->rights->facture->supprimer) + { if (! $object->is_erasable()) { print '
' . $langs->trans('Delete') . '
'; } else if ($objectidnext) { @@ -3403,7 +3435,8 @@ if ($action == 'create') } print '
'; - if ($action != 'prerelance' && $action != 'presend') { + if ($action != 'prerelance' && $action != 'presend') + { print '
'; print ''; // ancre