diff --git a/htdocs/adherents/card_subscriptions.php b/htdocs/adherents/card_subscriptions.php index 29b6ef1f1f2..2e8822b75d2 100644 --- a/htdocs/adherents/card_subscriptions.php +++ b/htdocs/adherents/card_subscriptions.php @@ -338,7 +338,7 @@ if ($user->rights->adherent->cotisation->creer && $action == 'cotisation' && ! $ } // Create draft invoice - $invoice->type=0; + $invoice->type= Facture::TYPE_STANDARD; $invoice->cond_reglement_id=$customer->cond_reglement_id; if (empty($invoice->cond_reglement_id)) { diff --git a/htdocs/cashdesk/validation_verif.php b/htdocs/cashdesk/validation_verif.php index ffaa01b7a94..7cd29a54ec5 100644 --- a/htdocs/cashdesk/validation_verif.php +++ b/htdocs/cashdesk/validation_verif.php @@ -53,7 +53,7 @@ switch ($action) $invoice=new Facture($db); $invoice->date=dol_now(); - $invoice->type=0; + $invoice->type= Facture::TYPE_STANDARD; $num=$invoice->getNextNumRef($company); $obj_facturation->numInvoice($num); diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index d845a364c1d..32cebbe8284 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -211,7 +211,7 @@ else if ($action == 'valid' && $user->rights->facture->creer) { $object->fetch($id); // On verifie signe facture - if ($object->type == 2) { + if ($object->type == Facture::TYPE_CREDIT_NOTE) { // Si avoir, le signe doit etre negatif if ($object->total_ht >= 0) { $mesgs [] = '
' . $langs->trans("ErrorInvoiceAvoirMustBeNegative") . '
'; @@ -354,7 +354,7 @@ else if ($action == 'confirm_valid' && $confirm == 'yes' && $user->rights->factu } // Check for warehouse - if ($object->type != 3 && ! empty($conf->global->STOCK_CALCULATE_ON_BILL) && $qualified_for_stock_change) { + if ($object->type != Facture::TYPE_DEPOSIT && ! empty($conf->global->STOCK_CALCULATE_ON_BILL) && $qualified_for_stock_change) { if (! $idwarehouse || $idwarehouse == - 1) { $error ++; setEventMessage($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Warehouse")), 'errors'); @@ -401,7 +401,7 @@ else if ($action == 'confirm_modif' && ((empty($conf->global->MAIN_USE_ADVANCED_ } // Check parameters - if ($object->type != 3 && ! empty($conf->global->STOCK_CALCULATE_ON_BILL) && $qualified_for_stock_change) { + if ($object->type != Facture::TYPE_DEPOSIT && ! empty($conf->global->STOCK_CALCULATE_ON_BILL) && $qualified_for_stock_change) { if (! $idwarehouse || $idwarehouse == - 1) { $error ++; setEventMessage($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Warehouse")), 'errors'); @@ -504,9 +504,9 @@ else if ($action == 'confirm_converttoreduc' && $confirm == 'yes' && $user->righ // Insert one discount by VAT rate category $discount = new DiscountAbsolute($db); - if ($object->type == 2) + if ($object->type == Facture::TYPE_CREDIT_NOTE) $discount->description = '(CREDIT_NOTE)'; - elseif ($object->type == 3) + elseif ($object->type == Facture::TYPE_DEPOSIT) $discount->description = '(DEPOSIT)'; else { $this->error = "CantConvertToReducAnInvoiceOfThisType"; @@ -596,7 +596,7 @@ else if ($action == 'add' && $user->rights->facture->creer) { // Proprietes particulieres a facture de remplacement $object->fk_facture_source = $_POST ['fac_replacement']; - $object->type = 1; + $object->type = Facture::TYPE_REPLACEMENT; $id = $object->createFromCurrent($user); if ($id <= 0) @@ -639,7 +639,7 @@ else if ($action == 'add' && $user->rights->facture->creer) { // Proprietes particulieres a facture avoir $object->fk_facture_source = $_POST ['fac_avoir']; - $object->type = 2; + $object->type = Facture::TYPE_CREDIT_NOTE; $id = $object->create($user); @@ -1262,7 +1262,7 @@ elseif ($action == 'updateligne' && $user->rights->facture->creer && ! GETPOST(' $label = ((GETPOST('update_label') && GETPOST('product_label')) ? GETPOST('product_label') : ''); // Check price is not lower than minimum (check is done only for standard or replacement invoices) - if (($object->type == 0 || $object->type == 1) && $price_min && (price2num($pu_ht) * (1 - price2num(GETPOST('remise_percent')) / 100) < price2num($price_min))) { + if (($object->type == Facture::TYPE_STANDARD || $object->type == Facture::TYPE_REPLACEMENT) && $price_min && (price2num($pu_ht) * (1 - price2num(GETPOST('remise_percent')) / 100) < price2num($price_min))) { setEventMessage($langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, - 1, $conf->currency)), 'errors'); $error ++; } @@ -2282,11 +2282,11 @@ if ($action == 'create') { $qualified_for_stock_change = $object->hasProductsOrServices(1); } - if ($object->type != 3 && ! empty($conf->global->STOCK_CALCULATE_ON_BILL) && $qualified_for_stock_change && $object->statut >= 1) { + if ($object->type != Facture::TYPE_DEPOSIT && ! empty($conf->global->STOCK_CALCULATE_ON_BILL) && $qualified_for_stock_change && $object->statut >= 1) { $langs->load("stocks"); require_once DOL_DOCUMENT_ROOT . '/product/class/html.formproduct.class.php'; $formproduct = new FormProduct($db); - $label = $object->type == 2 ? $langs->trans("SelectWarehouseForStockDecrease") : $langs->trans("SelectWarehouseForStockIncrease"); + $label = $object->type == Facture::TYPE_CREDIT_NOTE ? $langs->trans("SelectWarehouseForStockDecrease") : $langs->trans("SelectWarehouseForStockIncrease"); $formquestion = array( // 'text' => $langs->trans("ConfirmClone"), // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => @@ -2332,7 +2332,7 @@ if ($action == 'create') { $qualified_for_stock_change = $object->hasProductsOrServices(1); } - if ($object->type != 3 && ! empty($conf->global->STOCK_CALCULATE_ON_BILL) && $qualified_for_stock_change) { + if ($object->type != Facture::TYPE_DEPOSIT && ! empty($conf->global->STOCK_CALCULATE_ON_BILL) && $qualified_for_stock_change) { $langs->load("stocks"); require_once DOL_DOCUMENT_ROOT . '/product/class/html.formproduct.class.php'; require_once DOL_DOCUMENT_ROOT . '/product/stock/class/entrepot.class.php'; @@ -2340,10 +2340,10 @@ if ($action == 'create') { $warehouse = new Entrepot($db); $warehouse_array = $warehouse->list_array(); if (count($warehouse_array) == 1) { - $label = $object->type == 2 ? $langs->trans("WarehouseForStockIncrease", current($warehouse_array)) : $langs->trans("WarehouseForStockDecrease", current($warehouse_array)); + $label = $object->type == Facture::TYPE_CREDIT_NOTE ? $langs->trans("WarehouseForStockIncrease", current($warehouse_array)) : $langs->trans("WarehouseForStockDecrease", current($warehouse_array)); $value = ''; } else { - $label = $object->type == 2 ? $langs->trans("SelectWarehouseForStockIncrease") : $langs->trans("SelectWarehouseForStockDecrease"); + $label = $object->type == Facture::TYPE_CREDIT_NOTE ? $langs->trans("SelectWarehouseForStockIncrease") : $langs->trans("SelectWarehouseForStockDecrease"); $value = $formproduct->selectWarehouses(GETPOST('idwarehouse'), 'idwarehouse', '', 1); } $formquestion = array( @@ -2354,11 +2354,11 @@ if ($action == 'create') { // => 1), array('type' => 'other','name' => 'idwarehouse','label' => $label,'value' => $value)); } - if ($object->type != 2 && $object->total_ttc < 0) // Can happen only if $conf->global->FACTURE_ENABLE_NEGATIVE is on + if ($object->type != Facture::TYPE_CREDIT_NOTE && $object->total_ttc < 0) // Can happen only if $conf->global->FACTURE_ENABLE_NEGATIVE is on { $text .= '
' . img_warning() . ' ' . $langs->trans("ErrorInvoiceOfThisTypeMustBePositive"); } - $formconfirm = $form->formconfirm($_SERVER ["PHP_SELF"] . '?facid=' . $object->id, $langs->trans('ValidateBill'), $text, 'confirm_valid', $formquestion, (($object->type != 2 && $object->total_ttc < 0) ? "no" : "yes"), ($conf->notification->enabled ? 0 : 2)); + $formconfirm = $form->formconfirm($_SERVER ["PHP_SELF"] . '?facid=' . $object->id, $langs->trans('ValidateBill'), $text, 'confirm_valid', $formquestion, (($object->type != Facture::TYPE_CREDIT_NOTE && $object->total_ttc < 0) ? "no" : "yes"), ($conf->notification->enabled ? 0 : 2)); } // Confirm back to draft status @@ -2372,7 +2372,7 @@ if ($action == 'create') { } else { $qualified_for_stock_change = $object->hasProductsOrServices(1); } - if ($object->type != 3 && ! empty($conf->global->STOCK_CALCULATE_ON_BILL) && $qualified_for_stock_change) { + if ($object->type != Facture::TYPE_DEPOSIT && ! empty($conf->global->STOCK_CALCULATE_ON_BILL) && $qualified_for_stock_change) { $langs->load("stocks"); require_once DOL_DOCUMENT_ROOT . '/product/class/html.formproduct.class.php'; require_once DOL_DOCUMENT_ROOT . '/product/stock/class/entrepot.class.php'; @@ -2380,10 +2380,10 @@ if ($action == 'create') { $warehouse = new Entrepot($db); $warehouse_array = $warehouse->list_array(); if (count($warehouse_array) == 1) { - $label = $object->type == 2 ? $langs->trans("WarehouseForStockDecrease", current($warehouse_array)) : $langs->trans("WarehouseForStockIncrease", current($warehouse_array)); + $label = $object->type == Facture::TYPE_CREDIT_NOTE ? $langs->trans("WarehouseForStockDecrease", current($warehouse_array)) : $langs->trans("WarehouseForStockIncrease", current($warehouse_array)); $value = ''; } else { - $label = $object->type == 2 ? $langs->trans("SelectWarehouseForStockDecrease") : $langs->trans("SelectWarehouseForStockIncrease"); + $label = $object->type == Facture::TYPE_CREDIT_NOTE ? $langs->trans("SelectWarehouseForStockDecrease") : $langs->trans("SelectWarehouseForStockIncrease"); $value = $formproduct->selectWarehouses(GETPOST('idwarehouse'), 'idwarehouse', '', 1); } $formquestion = array( @@ -2563,12 +2563,12 @@ if ($action == 'create') { // Type print '' . $langs->trans('Type') . ''; print $object->getLibType(); - if ($object->type == 1) { + if ($object->type == Facture::TYPE_REPLACEMENT) { $facreplaced = new Facture($db); $facreplaced->fetch($object->fk_facture_source); print ' (' . $langs->transnoentities("ReplaceInvoice", $facreplaced->getNomUrl(1)) . ')'; } - if ($object->type == 2) { + if ($object->type == Facture::TYPE_CREDIT_NOTE) { $facusing = new Facture($db); $facusing->fetch($object->fk_facture_source); print ' (' . $langs->transnoentities("CorrectInvoice", $facusing->getNomUrl(1)) . ')'; @@ -2611,12 +2611,12 @@ if ($action == 'create') { if ($absolute_discount > 0) { print '. '; - if ($object->statut > 0 || $object->type == 2 || $object->type == 3) { + if ($object->statut > 0 || $object->type == Facture::TYPE_CREDIT_NOTE || $object->type == Facture::TYPE_DEPOSIT) { if ($object->statut == 0) { print $langs->trans("CompanyHasAbsoluteDiscount", price($absolute_discount), $langs->transnoentities("Currency" . $conf->currency)); print '. '; } else { - if ($object->statut < 1 || $object->type == 2 || $object->type == 3) { + if ($object->statut < 1 || $object->type == Facture::TYPE_CREDIT_NOTE || $object->type == Facture::TYPE_DEPOSIT) { $text = $langs->trans("CompanyHasAbsoluteDiscount", price($absolute_discount), $langs->transnoentities("Currency" . $conf->currency)); print '
' . $text . '.
'; } else { @@ -2633,7 +2633,7 @@ if ($action == 'create') { } else { if ($absolute_creditnote > 0) // If not, link will be added later { - if ($object->statut == 0 && $object->type != 2 && $object->type != 3) + if ($object->statut == 0 && $object->type != TYPE_CREDIT_NOTE && $object->type != TYPE_DEPOSIT) print ' (' . $addabsolutediscount . ')
'; else print '. '; @@ -2642,8 +2642,8 @@ if ($action == 'create') { } if ($absolute_creditnote > 0) { // If validated, we show link "add credit note to payment" - if ($object->statut != 1 || $object->type == 2 || $object->type == 3) { - if ($object->statut == 0 && $object->type != 3) { + if ($object->statut != 1 || $object->type == Facture::TYPE_CREDIT_NOTE || $object->type == Facture::TYPE_DEPOSIT) { + if ($object->statut == 0 && $object->type != Facture::TYPE_DEPOSIT) { $text = $langs->trans("CompanyHasCreditNote", price($absolute_creditnote), $langs->transnoentities("Currency" . $conf->currency)); print $form->textwithpicto($text, $langs->trans("CreditNoteDepositUse")); } else { @@ -2669,7 +2669,7 @@ if ($action == 'create') { } if (! $absolute_discount && ! $absolute_creditnote) { print $langs->trans("CompanyHasNoAbsoluteDiscount"); - if ($object->statut == 0 && $object->type != 2 && $object->type != 3) + if ($object->statut == 0 && $object->type != Facture::TYPE_CREDIT_NOTE && $object->type != Facture::TYPE_DEPOSIT) print ' (' . $addabsolutediscount . ')
'; else print '. '; @@ -2688,12 +2688,12 @@ if ($action == 'create') { print ''; - if ($object->type != 2 && $action != 'editinvoicedate' && ! empty($object->brouillon) && $user->rights->facture->creer) + if ($object->type != Facture::TYPE_CREDIT_NOTE && $action != 'editinvoicedate' && ! empty($object->brouillon) && $user->rights->facture->creer) print ''; print '
'; print $langs->trans('Date'); print 'id . '">' . img_edit($langs->trans('SetDate'), 1) . '
'; print ''; - if ($object->type != 2) { + if ($object->type != Facture::TYPE_CREDIT_NOTE) { if ($action == 'editinvoicedate') { $form->form_date($_SERVER ['PHP_SELF'] . '?facid=' . $object->id, $object->date, 'invoicedate'); } else { @@ -2707,7 +2707,7 @@ if ($action == 'create') { // List of payments $sign = 1; - if ($object->type == 2) + if ($object->type == Facture::TYPE_CREDIT_NOTE) $sign = - 1; $nbrows = 8; @@ -2730,7 +2730,7 @@ if ($action == 'create') { // List of payments already done print ''; - print '' . ($object->type == 2 ? $langs->trans("PaymentsBack") : $langs->trans('Payments')) . ''; + print '' . ($object->type == Facture::TYPE_CREDIT_NOTE ? $langs->trans("PaymentsBack") : $langs->trans('Payments')) . ''; print '' . $langs->trans('Type') . ''; if (! empty($conf->banque->enabled)) print '' . $langs->trans('BankAccount') . ''; @@ -2790,10 +2790,10 @@ if ($action == 'create') { dol_print_error($db); } - if ($object->type != 2) { + if ($object->type != Facture::TYPE_CREDIT_NOTE) { // Total already paid print ''; - if ($object->type != 3) + if ($object->type != Facture::TYPE_DEPOSIT) print $langs->trans('AlreadyPaidNoCreditNotesNoDeposits'); else print $langs->trans('AlreadyPaid'); @@ -2817,9 +2817,9 @@ if ($action == 'create') { $obj = $db->fetch_object($resql); $invoice->fetch($obj->fk_facture_source); print ''; - if ($invoice->type == 2) + if ($invoice->type == Facture::TYPE_CREDIT_NOTE) print $langs->trans("CreditNote") . ' '; - if ($invoice->type == 3) + if ($invoice->type == Facture::TYPE_DEPOSIT) print $langs->trans("Deposit") . ' '; print $invoice->getNomUrl(0); print ' :'; @@ -2828,9 +2828,9 @@ if ($action == 'create') { print 'rowid . '">' . img_delete() . ''; print ''; $i ++; - if ($invoice->type == 2) + if ($invoice->type == Facture::TYPE_CREDIT_NOTE) $creditnoteamount += $obj->amount_ttc; - if ($invoice->type == 3) + if ($invoice->type == Facture::TYPE_DEPOSIT) $depositamount += $obj->amount_ttc; } } else { @@ -2922,11 +2922,11 @@ if ($action == 'create') { print ''; - if ($object->type != 2 && $action != 'editconditions' && ! empty($object->brouillon) && $user->rights->facture->creer) + if ($object->type != Facture::TYPE_CREDIT_NOTE && $action != 'editconditions' && ! empty($object->brouillon) && $user->rights->facture->creer) print ''; print '
'; print $langs->trans('PaymentConditionsShort'); print 'id . '">' . img_edit($langs->trans('SetConditions'), 1) . '
'; print ''; - if ($object->type != 2) { + if ($object->type != Facture::TYPE_CREDIT_NOTE) { if ($action == 'editconditions') { $form->form_conditions_reglement($_SERVER ['PHP_SELF'] . '?facid=' . $object->id, $object->cond_reglement_id, 'cond_reglement_id'); } else { @@ -2942,11 +2942,11 @@ if ($action == 'create') { print ''; - if ($object->type != 2 && $action != 'editpaymentterm' && ! empty($object->brouillon) && $user->rights->facture->creer) + if ($object->type != Facture::TYPE_CREDIT_NOTE && $action != 'editpaymentterm' && ! empty($object->brouillon) && $user->rights->facture->creer) print ''; print '
'; print $langs->trans('DateMaxPayment'); print 'id . '">' . img_edit($langs->trans('SetDate'), 1) . '
'; print ''; - if ($object->type != 2) { + if ($object->type != Facture::TYPE_CREDIT_NOTE) { if ($action == 'editpaymentterm') { $form->form_date($_SERVER ['PHP_SELF'] . '?facid=' . $object->id, $object->date_lim_reglement, 'paymentterm'); } else { @@ -3188,7 +3188,7 @@ if ($action == 'create') { } // Reopen a standard paid invoice - if (($object->type == 0 || $object->type == 1) && ($object->statut == 2 || $object->statut == 3) && $user->rights->facture->creer) // A paid + 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) @@ -3202,7 +3202,7 @@ if ($action == 'create') { } // Validate - if ($object->statut == 0 && count($object->lines) > 0 && ((($object->type == 0 || $object->type == 1 || $object->type == 3 || $object->type == 4) && (! empty($conf->global->FACTURE_ENABLE_NEGATIVE) || $object->total_ttc >= 0)) || ($object->type == 2 && $object->total_ttc <= 0))) { + if ($object->statut == 0 && count($object->lines) > 0 && ((($object->type == Facture::TYPE_STANDARD || $object->type == Facture::TYPE_REPLACEMENT || $object->type == Facture::TYPE_DEPOSIT || $object->type == Facture::TYPE_PROFORMA) && (! empty($conf->global->FACTURE_ENABLE_NEGATIVE) || $object->total_ttc >= 0)) || ($object->type == Facture::TYPE_CREDIT_NOTE && $object->total_ttc <= 0))) { if ($user->rights->facture->valider) { print '
' . $langs->trans('Validate') . '
'; } @@ -3235,7 +3235,7 @@ if ($action == 'create') { } // Create payment - if ($object->type != 2 && $object->statut == 1 && $object->paye == 0 && $user->rights->facture->paiement) { + if ($object->type != Facture::TYPE_CREDIT_NOTE && $object->statut == 1 && $object->paye == 0 && $user->rights->facture->paiement) { if ($objectidnext) { print '
' . $langs->trans('DoPayment') . '
'; } else { @@ -3248,23 +3248,23 @@ if ($action == 'create') { } // Reverse back money or convert to reduction - if ($object->type == 2 || $object->type == 3) { + if ($object->type == Facture::TYPE_CREDIT_NOTE || $object->type == Facture::TYPE_DEPOSIT) { // For credit note only - if ($object->type == 2 && $object->statut == 1 && $object->paye == 0 && $user->rights->facture->paiement) { + if ($object->type == Facture::TYPE_CREDIT_NOTE && $object->statut == 1 && $object->paye == 0 && $user->rights->facture->paiement) { print '
' . $langs->trans('DoPaymentBack') . '
'; } // For credit note - if ($object->type == 2 && $object->statut == 1 && $object->paye == 0 && $user->rights->facture->creer && $object->getSommePaiement() == 0) { + 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 == 3 && $object->statut == 1 && $resteapayer == 0 && $user->rights->facture->creer) { + if ($object->type == Facture::TYPE_DEPOSIT && $object->statut == 1 && $resteapayer == 0 && $user->rights->facture->creer) { 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 != 2 && $object->type != 3 && $resteapayer <= 0) || ($object->type == 2 && $resteapayer >= 0))) { + 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') . '
'; } @@ -3283,12 +3283,12 @@ if ($action == 'create') { } // Clone - if (($object->type == 0 || $object->type == 3 || $object->type == 4) && $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 == 0 || $object->type == 3 || $object->type == 4) && $object->statut == 0 && $user->rights->facture->creer) { + 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") . '
'; } diff --git a/htdocs/compta/facture/apercu.php b/htdocs/compta/facture/apercu.php index ab508e50035..36802709c0a 100644 --- a/htdocs/compta/facture/apercu.php +++ b/htdocs/compta/facture/apercu.php @@ -107,13 +107,13 @@ if ($id > 0 || ! empty($ref)) // Type print ''.$langs->trans('Type').''; print $object->getLibType(); - if ($object->type == 1) + if ($object->type == Facture::TYPE_REPLACEMENT) { $facreplaced=new Facture($db); $facreplaced->fetch($object->fk_facture_source); print ' ('.$langs->transnoentities("ReplaceInvoice",$facreplaced->getNomUrl(1)).')'; } - if ($object->type == 2) + if ($object->type == Facture::TYPE_CREDIT_NOTE) { $facusing=new Facture($db); $facusing->fetch($object->fk_facture_source); @@ -155,7 +155,7 @@ if ($id > 0 || ! empty($ref)) if ($absolute_discount > 0) { print '. '; - if ($object->statut > 0 || $object->type == 2 || $object->type == 3) + if ($object->statut > 0 || $object->type == Facture::TYPE_CREDIT_NOTE || $object->type == Facture::TYPE_DEPOSIT) { if ($object->statut == 0) { @@ -164,7 +164,7 @@ if ($id > 0 || ! empty($ref)) } else { - if ($object->statut < 1 || $object->type == 2 || $object->type == 3) + if ($object->statut < 1 || $object->type == Facture::TYPE_CREDIT_NOTE || $object->type == Facture::TYPE_DEPOSIT) { $text=$langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->transnoentities("Currency".$conf->currency)); print '
'.$text.'.
'; @@ -189,7 +189,7 @@ if ($id > 0 || ! empty($ref)) { if ($absolute_creditnote > 0) // If not linke will be added later { - if ($object->statut == 0 && $object->type != 2 && $object->type != 3) print ' - '.$addabsolutediscount.'
'; + if ($object->statut == 0 && $object->type != Facture::TYPE_CREDIT_NOTE && $object->type != Facture::TYPE_DEPOSIT) print ' - '.$addabsolutediscount.'
'; else print '.'; } else print '. '; @@ -197,9 +197,9 @@ if ($id > 0 || ! empty($ref)) if ($absolute_creditnote > 0) { // If validated, we show link "add credit note to payment" - if ($object->statut != 1 || $object->type == 2 || $object->type == 3) + if ($object->statut != 1 || $object->type == Facture::TYPE_CREDIT_NOTE || $object->type == Facture::TYPE_DEPOSIT) { - if ($object->statut == 0 && $object->type != 3) + if ($object->statut == 0 && $object->type != Facture::TYPE_DEPOSIT) { $text=$langs->trans("CompanyHasCreditNote",price($absolute_creditnote),$langs->transnoentities("Currency".$conf->currency)); print $form->textwithpicto($text,$langs->trans("CreditNoteDepositUse")); @@ -220,7 +220,7 @@ if ($id > 0 || ! empty($ref)) if (! $absolute_discount && ! $absolute_creditnote) { print $langs->trans("CompanyHasNoAbsoluteDiscount"); - if ($object->statut == 0 && $object->type != 2 && $object->type != 3) print ' - '.$addabsolutediscount.'
'; + if ($object->statut == 0 && $object->type != Facture::TYPE_CREDIT_NOTE && $object->type != Facture::TYPE_DEPOSIT) print ' - '.$addabsolutediscount.'
'; else print '. '; } /*if ($object->statut == 0 && $object->type != 2 && $object->type != 3) @@ -242,10 +242,10 @@ if ($id > 0 || ! empty($ref)) print ''; - if ($object->type != 2 && $action != 'editpaymentterm' && $object->brouillon && $user->rights->facture->creer) print ''; + if ($object->type != Facture::TYPE_CREDIT_NOTE && $action != 'editpaymentterm' && $object->brouillon && $user->rights->facture->creer) print ''; print '
'; print $langs->trans('DateMaxPayment'); print 'id.'">'.img_edit($langs->trans('SetDate'),1).'id.'">'.img_edit($langs->trans('SetDate'),1).'
'; print ''; - if ($object->type != 2) + if ($object->type != Facture::TYPE_CREDIT_NOTE) { if ($action == 'editpaymentterm') { diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index dc154b2a51f..ec86fbcbaec 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -68,7 +68,7 @@ class Facture extends CommonInvoice var $ref_ext; var $ref_int; //Check constants for types - var $type= self::TYPE_STANDARD; + var $type = self::TYPE_STANDARD; //var $amount; var $remise_absolue; diff --git a/htdocs/compta/facture/prelevement.php b/htdocs/compta/facture/prelevement.php index 48b08946469..740bd8ea11a 100644 --- a/htdocs/compta/facture/prelevement.php +++ b/htdocs/compta/facture/prelevement.php @@ -183,13 +183,13 @@ if ($object->id > 0) // Type print ''.$langs->trans('Type').''; print $object->getLibType(); - if ($object->type == 1) + if ($object->type == Facture::TYPE_REPLACEMENT) { $facreplaced=new Facture($db); $facreplaced->fetch($object->fk_facture_source); print ' ('.$langs->transnoentities("ReplaceInvoice",$facreplaced->getNomUrl(1)).')'; } - if ($object->type == 2) + if ($object->type == Facture::TYPE_CREDIT_NOTE) { $facusing=new Facture($db); $facusing->fetch($object->fk_facture_source); @@ -228,7 +228,7 @@ if ($object->id > 0) print '. '; if ($absolute_discount > 0) { - if ($object->statut > 0 || $object->type == 2 || $object->type == 3) + if ($object->statut > 0 || $object->type == Facture::TYPE_CREDIT_NOTE || $object->type == Facture::TYPE_DEPOSIT) { if ($object->statut == 0) { @@ -236,7 +236,7 @@ if ($object->id > 0) } else { - if ($object->statut < 1 || $object->type == 2 || $object->type == 3) + if ($object->statut < 1 || $object->type == Facture::TYPE_CREDIT_NOTE || $object->type == Facture::TYPE_DEPOSIT) { $text=$langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->transnoentities("Currency".$conf->currency)); print '
'.$text.'.
'; @@ -260,9 +260,9 @@ if ($object->id > 0) if ($absolute_creditnote > 0) { // If validated, we show link "add credit note to payment" - if ($object->statut != 1 || $object->type == 2 || $object->type == 3) + if ($object->statut != 1 || $object->type == Facture::TYPE_DEPOSIT || $object->type == Facture::TYPE_CREDIT_NOTE) { - if ($object->statut == 0 && $object->type != 3) + if ($object->statut == 0 && $object->type != Facture::TYPE_DEPOSIT) { $text=$langs->trans("CompanyHasCreditNote",price($absolute_creditnote),$langs->transnoentities("Currency".$conf->currency)); print $form->textwithpicto($text,$langs->trans("CreditNoteDepositUse")); @@ -285,11 +285,11 @@ if ($object->id > 0) print ''; - if ($object->type != 2 && $action != 'editinvoicedate' && ! empty($object->brouillon) && $user->rights->facture->creer) print ''; + if ($object->type != Facture::TYPE_CREDIT_NOTE && $action != 'editinvoicedate' && ! empty($object->brouillon) && $user->rights->facture->creer) print ''; print '
'; print $langs->trans('Date'); print 'id.'">'.img_edit($langs->trans('SetDate'),1).'id.'">'.img_edit($langs->trans('SetDate'),1).'
'; print ''; - if ($object->type != 2) + if ($object->type != Facture::TYPE_CREDIT_NOTE) { if ($action == 'editinvoicedate') { @@ -312,10 +312,10 @@ if ($object->id > 0) print ''; - if ($object->type != 2 && $action != 'editpaymentterm' && ! empty($object->brouillon) && $user->rights->facture->creer) print ''; + if ($object->type != Facture::TYPE_CREDIT_NOTE && $action != 'editpaymentterm' && ! empty($object->brouillon) && $user->rights->facture->creer) print ''; print '
'; print $langs->trans('DateMaxPayment'); print 'id.'">'.img_edit($langs->trans('SetDate'),1).'id.'">'.img_edit($langs->trans('SetDate'),1).'
'; print ''; - if ($object->type != 2) + if ($object->type != Facture::TYPE_CREDIT_NOTE) { if ($action == 'editpaymentterm') { @@ -338,10 +338,10 @@ if ($object->id > 0) print ''; - if ($object->type != 2 && $action != 'editconditions' && ! empty($object->brouillon) && $user->rights->facture->creer) print ''; + if ($object->type != Facture::TYPE_CREDIT_NOTE && $action != 'editconditions' && ! empty($object->brouillon) && $user->rights->facture->creer) print ''; print '
'; print $langs->trans('PaymentConditionsShort'); print 'id.'">'.img_edit($langs->trans('SetConditions'),1).'id.'">'.img_edit($langs->trans('SetConditions'),1).'
'; print ''; - if ($object->type != 2) + if ($object->type != Facture::TYPE_CREDIT_NOTE) { if ($action == 'editconditions') { diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php index 74949814577..b9bcaaa4a6c 100644 --- a/htdocs/fourn/class/fournisseur.facture.class.php +++ b/htdocs/fourn/class/fournisseur.facture.class.php @@ -46,8 +46,8 @@ class FactureFournisseur extends CommonInvoice var $product_ref; var $ref_supplier; var $socid; - //! 0=Standard invoice, 1=Replacement invoice, 2=Credit note invoice, 3=Deposit invoice, 4=Proforma invoice - var $type; + //Check constants for types + var $type = self::TYPE_STANDARD; //! 0=draft, //! 1=validated //! 2=classified paid partially (close_code='discount_vat','badcustomer') or completely (close_code=null), @@ -87,6 +87,30 @@ class FactureFournisseur extends CommonInvoice var $extraparams=array(); + /** + * Standard invoice + */ + const TYPE_STANDARD = 0; + + /** + * Replacement invoice + */ + const TYPE_REPLACEMENT = 1; + + /** + * Credit note invoice + */ + const TYPE_CREDIT_NOTE = 2; + + /** + * Deposit invoice + */ + const TYPE_DEPOSIT = 3; + + /** + * Proforma invoice + */ + const TYPE_PROFORMA = 4; /** * Constructor @@ -338,7 +362,7 @@ class FactureFournisseur extends CommonInvoice $this->ref_supplier = $obj->ref_supplier; $this->entity = $obj->entity; - $this->type = empty($obj->type)?0:$obj->type; + $this->type = empty($obj->type)? self::TYPE_STANDARD:$obj->type; $this->fk_soc = $obj->fk_soc; $this->datec = $this->db->jdate($obj->datec); $this->date = $this->db->jdate($obj->datef); diff --git a/htdocs/fourn/facture/document.php b/htdocs/fourn/facture/document.php index 6c47f66ec7d..9a228f28802 100644 --- a/htdocs/fourn/facture/document.php +++ b/htdocs/fourn/facture/document.php @@ -125,13 +125,13 @@ if ($object->id > 0) // Type print ''.$langs->trans('Type').''; print $object->getLibType(); - if ($object->type == 1) + if ($object->type == FactureFournisseur::TYPE_REPLACEMENT) { $facreplaced=new FactureFournisseur($db); $facreplaced->fetch($object->fk_facture_source); print ' ('.$langs->transnoentities("ReplaceInvoice",$facreplaced->getNomUrl(1)).')'; } - if ($object->type == 2) + if ($object->type == FactureFournisseur::TYPE_CREDIT_NOTE) { $facusing=new FactureFournisseur($db); $facusing->fetch($object->fk_facture_source); diff --git a/htdocs/fourn/facture/fiche.php b/htdocs/fourn/facture/fiche.php index 6d095e48b93..c6aab783018 100644 --- a/htdocs/fourn/facture/fiche.php +++ b/htdocs/fourn/facture/fiche.php @@ -1518,13 +1518,13 @@ else // Type print ''.$langs->trans('Type').''; print $object->getLibType(); - if ($object->type == 1) + if ($object->type == FactureFournisseur::TYPE_REPLACEMENT) { $facreplaced=new FactureFournisseur($db); $facreplaced->fetch($object->fk_facture_source); print ' ('.$langs->transnoentities("ReplaceInvoice",$facreplaced->getNomUrl(1)).')'; } - if ($object->type == 2) + if ($object->type == FactureFournisseur::TYPE_CREDIT_NOTE) { $facusing=new FactureFournisseur($db); $facusing->fetch($object->fk_facture_source); @@ -2166,7 +2166,7 @@ else } // Reopen a standard paid invoice - if (($object->type == 0 || $object->type == 1) && ($object->statut == 2 || $object->statut == 3)) // A paid invoice (partially or completely) + if (($object->type == FactureFournisseur::TYPE_STANDARD || $object->type == FactureFournisseur::TYPE_REPLACEMENT) && ($object->statut == 2 || $object->statut == 3)) // A paid invoice (partially or completely) { if (! $facidnext && $object->close_code != 'replaced') // Not replaced by another invoice { diff --git a/htdocs/fourn/facture/note.php b/htdocs/fourn/facture/note.php index e3963a5f738..12b754dea19 100644 --- a/htdocs/fourn/facture/note.php +++ b/htdocs/fourn/facture/note.php @@ -98,13 +98,13 @@ if ($object->id > 0) // Type print ''.$langs->trans('Type').''; print $object->getLibType(); - if ($object->type == 1) + if ($object->type == FactureFournisseur::TYPE_REPLACEMENT) { $facreplaced=new FactureFournisseur($db); $facreplaced->fetch($object->fk_facture_source); print ' ('.$langs->transnoentities("ReplaceInvoice",$facreplaced->getNomUrl(1)).')'; } - if ($object->type == 2) + if ($object->type == FactureFournisseur::TYPE_CREDIT_NOTE) { $facusing=new FactureFournisseur($db); $facusing->fetch($object->fk_facture_source);