diff --git a/htdocs/adherents/class/adherent.class.php b/htdocs/adherents/class/adherent.class.php index c87c1d90b0d..8e5cdbe8067 100644 --- a/htdocs/adherents/class/adherent.class.php +++ b/htdocs/adherents/class/adherent.class.php @@ -1749,7 +1749,7 @@ class Adherent extends CommonObject if (!$error) { // Set invoice as paid - $invoice->set_paid($user); + $invoice->setPaid($user); } } diff --git a/htdocs/cashdesk/validation_verif.php b/htdocs/cashdesk/validation_verif.php index 1df6f805ff6..da320c7d855 100644 --- a/htdocs/cashdesk/validation_verif.php +++ b/htdocs/cashdesk/validation_verif.php @@ -319,7 +319,7 @@ switch ($action) && $obj_facturation->getSetPaymentMode() != 'DIFF') { // We set status to paid - $result = $invoice->set_paid($user); + $result = $invoice->setPaid($user); //print 'set paid';exit; } } diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index f689e7c3a4c..da75d86de7c 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -1630,7 +1630,7 @@ class Propal extends CommonObject $sql .= " fk_input_reason=".(isset($this->demand_reason_id) ? $this->demand_reason_id : "null").","; $sql .= " note_private=".(isset($this->note_private) ? "'".$this->db->escape($this->note_private)."'" : "null").","; $sql .= " note_public=".(isset($this->note_public) ? "'".$this->db->escape($this->note_public)."'" : "null").","; - $sql .= " model_pdf=".(isset($this->modelpdf) ? "'".$this->db->escape($this->modelpdf)."'" : "null").","; + $sql .= " model_pdf=".(isset($this->model_pdf) ? "'".$this->db->escape($this->model_pdf)."'" : "null").","; $sql .= " import_key=".(isset($this->import_key) ? "'".$this->db->escape($this->import_key)."'" : "null").""; $sql .= " WHERE rowid=".$this->id; diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php index c87083895c7..f6b3a1b3fa4 100644 --- a/htdocs/commande/card.php +++ b/htdocs/commande/card.php @@ -501,7 +501,7 @@ if (empty($reshook)) setEventMessages($object->error, $object->errors, 'errors'); } } elseif ($action == 'setremise' && $usercancreate) { - $result = $object->set_remise($user, GETPOST('remise')); + $result = $object->setDiscount($user, GETPOST('remise')); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); @@ -607,7 +607,7 @@ if (empty($reshook)) setEventMessages($object->error, $object->errors, 'errors'); } } elseif ($action == 'setremisepercent' && $usercancreate) { - $result = $object->set_remise($user, price2num(GETPOST('remise_percent'), 2)); + $result = $object->setDiscount($user, price2num(GETPOST('remise_percent'), 2)); } elseif ($action == 'setremiseabsolue' && $usercancreate) { $result = $object->set_remise_absolue($user, price2num(GETPOST('remise_absolue'), 'MU')); } elseif ($action == 'addline' && GETPOST('submitforalllines', 'alpha') && GETPOST('vatforalllines', 'alpha')) { diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 3d359ca6563..4f8e4ab6643 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -2359,6 +2359,8 @@ class Commande extends CommonOrder /** * Applique une remise relative * + * @deprecated + * @see setDiscount() * @param User $user User qui positionne la remise * @param float $remise Discount (percent) * @param int $notrigger 1=Does not execute triggers, 0= execute triggers @@ -2367,6 +2369,20 @@ class Commande extends CommonOrder public function set_remise($user, $remise, $notrigger = 0) { // phpcs:enable + dol_syslog(get_class($this)."::set_remise is deprecated, use setDiscount instead", LOG_NOTICE); + return $this->setDiscount($user, $remise, $notrigger); + } + + /** + * Applique une remise relative + * + * @param User $user User qui positionne la remise + * @param float $remise Discount (percent) + * @param int $notrigger 1=Does not execute triggers, 0= execute triggers + * @return int <0 if KO, >0 if OK + */ + public function setDiscount($user, $remise, $notrigger = 0) + { $remise = trim($remise) ?trim($remise) : 0; if ($user->rights->commande->creer) @@ -3271,7 +3287,7 @@ class Commande extends CommonOrder $sql .= " fk_input_reason=".($this->demand_reason_id > 0 ? $this->demand_reason_id : "null").","; $sql .= " note_private=".(isset($this->note_private) ? "'".$this->db->escape($this->note_private)."'" : "null").","; $sql .= " note_public=".(isset($this->note_public) ? "'".$this->db->escape($this->note_public)."'" : "null").","; - $sql .= " model_pdf=".(isset($this->modelpdf) ? "'".$this->db->escape($this->modelpdf)."'" : "null").","; + $sql .= " model_pdf=".(isset($this->model_pdf) ? "'".$this->db->escape($this->model_pdf)."'" : "null").","; $sql .= " import_key=".(isset($this->import_key) ? "'".$this->db->escape($this->import_key)."'" : "null").""; $sql .= " WHERE rowid=".$this->id; @@ -3921,7 +3937,7 @@ class Commande extends CommonOrder if (!empty($this->model_pdf)) { $modele = $this->model_pdf; - } elseif (!empty($this->modelpdf)) { // dperecated + } elseif (!empty($this->modelpdf)) { // deprecated $modele = $this->modelpdf; } elseif (!empty($conf->global->COMMANDE_ADDON_PDF)) { $modele = $conf->global->COMMANDE_ADDON_PDF; diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index e0e89b7b978..cdb729991da 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -14,7 +14,7 @@ * Copyright (C) 2013 Cédric Salvador * Copyright (C) 2014-2019 Ferran Marcet * Copyright (C) 2015-2016 Marcos García - * Copyright (C) 2018-2019 Frédéric France + * Copyright (C) 2018-2021 Frédéric France * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -193,7 +193,7 @@ if (empty($reshook)) $result = $object->fetch($id); if ($object->statut == Facture::STATUS_CLOSED || ($object->statut == Facture::STATUS_ABANDONED && ($object->close_code != 'replaced' || $object->getIdReplacingInvoice() == 0)) || ($object->statut == Facture::STATUS_VALIDATED && $object->paye == 1)) { // ($object->statut == 1 && $object->paye == 1) should not happened but can be found when data are corrupted - $result = $object->set_unpaid($user); + $result = $object->setUnpaid($user); if ($result > 0) { header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$id); exit(); @@ -483,7 +483,7 @@ if (empty($reshook)) $result = $object->setBankAccount(GETPOST('fk_account', 'int')); } elseif ($action == 'setremisepercent' && $usercancreate) { $object->fetch($id); - $result = $object->set_remise($user, price2num(GETPOST('remise_percent'), 2)); + $result = $object->setDiscount($user, price2num(GETPOST('remise_percent'), 2)); } elseif ($action == "setabsolutediscount" && $usercancreate) { // POST[remise_id] or POST[remise_id_for_payment] @@ -747,7 +747,7 @@ if (empty($reshook)) elseif ($action == 'confirm_paid' && $confirm == 'yes' && $usercanissuepayment) { $object->fetch($id); - $result = $object->set_paid($user); + $result = $object->setPaid($user); if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); } // Classif "paid partialy" elseif ($action == 'confirm_paid_partially' && $confirm == 'yes' && $usercanissuepayment) @@ -756,7 +756,7 @@ if (empty($reshook)) $close_code = GETPOST("close_code", 'restricthtml'); $close_note = GETPOST("close_note", 'restricthtml'); if ($close_code) { - $result = $object->set_paid($user, $close_code, $close_note); + $result = $object->setPaid($user, $close_code, $close_note); if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); } else { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Reason")), null, 'errors'); @@ -767,7 +767,7 @@ if (empty($reshook)) $close_code = GETPOST("close_code", 'restricthtml'); $close_note = GETPOST("close_note", 'restricthtml'); if ($close_code) { - $result = $object->set_canceled($user, $close_code, $close_note); + $result = $object->setCanceled($user, $close_code, $close_note); if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); } else { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Reason")), null, 'errors'); @@ -921,7 +921,7 @@ if (empty($reshook)) { if ($object->type != Facture::TYPE_DEPOSIT) { // Classe facture - $result = $object->set_paid($user); + $result = $object->setPaid($user); if ($result >= 0) { $db->commit(); diff --git a/htdocs/compta/facture/class/api_invoices.class.php b/htdocs/compta/facture/class/api_invoices.class.php index 316f43bc011..444fca3155a 100644 --- a/htdocs/compta/facture/class/api_invoices.class.php +++ b/htdocs/compta/facture/class/api_invoices.class.php @@ -910,7 +910,7 @@ class Invoices extends DolibarrApi throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } - $result = $this->invoice->set_paid(DolibarrApiAccess::$user, $close_code, $close_note); + $result = $this->invoice->setPaid(DolibarrApiAccess::$user, $close_code, $close_note); if ($result == 0) { throw new RestException(304, 'Error nothing done. May be object is already validated'); } @@ -960,7 +960,7 @@ class Invoices extends DolibarrApi throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } - $result = $this->invoice->set_unpaid(DolibarrApiAccess::$user); + $result = $this->invoice->setUnpaid(DolibarrApiAccess::$user); if ($result == 0) { throw new RestException(304, 'Nothing done'); } @@ -1167,7 +1167,7 @@ class Invoices extends DolibarrApi { if ($this->invoice->type != Facture::TYPE_DEPOSIT) { // Classe facture - $result = $this->invoice->set_paid(DolibarrApiAccess::$user); + $result = $this->invoice->setPaid(DolibarrApiAccess::$user); if ($result >= 0) { $this->db->commit(); diff --git a/htdocs/compta/facture/class/facture-rec.class.php b/htdocs/compta/facture/class/facture-rec.class.php index 1a50fadcc9c..13a58a3e075 100644 --- a/htdocs/compta/facture/class/facture-rec.class.php +++ b/htdocs/compta/facture/class/facture-rec.class.php @@ -280,7 +280,7 @@ class FactureRec extends CommonInvoice $sql .= ", ".(!empty($facsrc->remise) ? $this->remise : '0'); $sql .= ", ".(!empty($this->note_private) ? ("'".$this->db->escape($this->note_private)."'") : "NULL"); $sql .= ", ".(!empty($this->note_public) ? ("'".$this->db->escape($this->note_public)."'") : "NULL"); - $sql .= ", ".(!empty($this->modelpdf) ? ("'".$this->db->escape($this->modelpdf)."'") : "NULL"); + $sql .= ", ".(!empty($this->model_pdf) ? ("'".$this->db->escape($this->model_pdf)."'") : "NULL"); $sql .= ", '".$this->db->escape($user->id)."'"; $sql .= ", ".(!empty($facsrc->fk_project) ? "'".$this->db->escape($facsrc->fk_project)."'" : "null"); $sql .= ", ".(!empty($facsrc->fk_account) ? "'".$this->db->escape($facsrc->fk_account)."'" : "null"); @@ -347,7 +347,7 @@ class FactureRec extends CommonInvoice { // Extrafields if (method_exists($facsrc->lines[$i], 'fetch_optionals')) { - $facsrc->lines[$i]->fetch_optionals($facsrc->lines[$i]->rowid); + $facsrc->lines[$i]->fetch_optionals($facsrc->lines[$i]->id); $objectline->array_options = $facsrc->lines[$i]->array_options; } @@ -562,7 +562,7 @@ class FactureRec extends CommonInvoice $this->note_private = $obj->note_private; $this->note_public = $obj->note_public; $this->user_author = $obj->fk_user_author; - $this->modelpdf = $obj->model_pdf; // deprecatd + $this->modelpdf = $obj->model_pdf; // deprecated $this->model_pdf = $obj->model_pdf; $this->rang = $obj->rang; $this->special_code = $obj->special_code; @@ -1280,9 +1280,8 @@ class FactureRec extends CommonInvoice { // We refresh the object in order to have all necessary data (like date_lim_reglement) $facture->fetch($facture->id); - $result = $facture->generateDocument($facturerec->modelpdf, $langs); - if ($result <= 0) - { + $result = $facture->generateDocument($facturerec->model_pdf, $langs); + if ($result <= 0) { $this->errors = $facture->errors; $this->error = $facture->error; $error++; @@ -1873,7 +1872,7 @@ class FactureRec extends CommonInvoice dol_syslog(get_class($this)."::setModelPdf", LOG_DEBUG); if ($this->db->query($sql)) { - $this->modelpdf = $model; + $this->model_pdf = $model; return 1; } else { dol_print_error($this->db); diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 26c40c2c45e..5dbf97db2d0 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -498,7 +498,7 @@ class Facture extends CommonInvoice $this->fk_project = GETPOST('projectid', 'int') > 0 ? ((int) GETPOST('projectid', 'int')) : $_facrec->fk_project; $this->note_public = GETPOST('note_public', 'none') ? GETPOST('note_public', 'restricthtml') : $_facrec->note_public; $this->note_private = GETPOST('note_private', 'none') ? GETPOST('note_private', 'restricthtml') : $_facrec->note_private; - $this->modelpdf = GETPOST('model', 'alpha') ? GETPOST('model', 'alpha') : $_facrec->modelpdf; + $this->model_pdf = GETPOST('model', 'alpha') ? GETPOST('model', 'alpha') : $_facrec->model_pdf; $this->cond_reglement_id = GETPOST('cond_reglement_id', 'int') > 0 ? ((int) GETPOST('cond_reglement_id', 'int')) : $_facrec->cond_reglement_id; $this->mode_reglement_id = GETPOST('mode_reglement_id', 'int') > 0 ? ((int) GETPOST('mode_reglement_id', 'int')) : $_facrec->mode_reglement_id; $this->fk_account = GETPOST('fk_account') > 0 ? ((int) GETPOST('fk_account')) : $_facrec->fk_account; @@ -1062,8 +1062,8 @@ class Facture extends CommonInvoice $facture->note_public = $this->note_public; $facture->note_private = $this->note_private; $facture->ref_client = $this->ref_client; - $facture->modelpdf = $this->modelpdf; // deprecated - $facture->model_pdf = $this->modelpdf; + $facture->modelpdf = $this->model_pdf; // deprecated + $facture->model_pdf = $this->model_pdf; $facture->fk_project = $this->fk_project; $facture->cond_reglement_id = $this->cond_reglement_id; $facture->mode_reglement_id = $this->mode_reglement_id; @@ -2293,6 +2293,8 @@ class Facture extends CommonInvoice * Tag the invoice as paid completely (if close_code is filled) => this->fk_statut=2, this->paye=1 * or partialy (if close_code filled) + appel trigger BILL_PAYED => this->fk_statut=2, this->paye stay 0 * + * @deprecated + * @see setPaid() * @param User $user Object user that modify * @param string $close_code Code renseigne si on classe a payee completement alors que paiement incomplet (cas escompte par exemple) * @param string $close_note Commentaire renseigne si on classe a payee alors que paiement incomplet (cas escompte par exemple) @@ -2301,6 +2303,21 @@ class Facture extends CommonInvoice public function set_paid($user, $close_code = '', $close_note = '') { // phpcs:enable + dol_syslog(get_class($this)."::set_paid is deprecated, use setPaid instead", LOG_NOTICE); + return $this->setPaid($user, $close_code, $close_note); + } + + /** + * Tag the invoice as paid completely (if close_code is filled) => this->fk_statut=2, this->paye=1 + * or partialy (if close_code filled) + appel trigger BILL_PAYED => this->fk_statut=2, this->paye stay 0 + * + * @param User $user Object user that modify + * @param string $close_code Code renseigne si on classe a payee completement alors que paiement incomplet (cas escompte par exemple) + * @param string $close_note Commentaire renseigne si on classe a payee alors que paiement incomplet (cas escompte par exemple) + * @return int <0 if KO, >0 if OK + */ + public function setPaid($user, $close_code = '', $close_note = '') + { $error = 0; if ($this->paye != 1) @@ -2352,12 +2369,28 @@ class Facture extends CommonInvoice * Fonction utilisee quand un paiement prelevement est refuse, * ou quand une facture annulee et reouverte. * + * @deprecated + * @see setUnpaid() * @param User $user Object user that change status * @return int <0 if KO, >0 if OK */ public function set_unpaid($user) { // phpcs:enable + dol_syslog(get_class($this)."::set_unpaid is deprecated, use setUnpaid instead", LOG_NOTICE); + return $this->setUnpaid($user); + } + + /** + * Tag la facture comme non payee completement + appel trigger BILL_UNPAYED + * Fonction utilisee quand un paiement prelevement est refuse, + * ou quand une facture annulee et reouverte. + * + * @param User $user Object user that change status + * @return int <0 if KO, >0 if OK + */ + public function setUnpaid($user) + { $error = 0; $this->db->begin(); @@ -2399,6 +2432,8 @@ class Facture extends CommonInvoice * Warning, if option to decrease stock on invoice was set, this function does not change stock (it might be a cancel because * of no payment even if merchandises were sent). * + * @deprecated + * @see setCanceled() * @param User $user Object user making change * @param string $close_code Code of closing invoice (CLOSECODE_REPLACED, CLOSECODE_...) * @param string $close_note Comment @@ -2407,8 +2442,23 @@ class Facture extends CommonInvoice public function set_canceled($user, $close_code = '', $close_note = '') { // phpcs:enable + dol_syslog(get_class($this)."::set_canceled is deprecated, use setCanceled instead", LOG_NOTICE); + return $this->setCanceled($user, $close_code, $close_note); + } - dol_syslog(get_class($this)."::set_canceled rowid=".$this->id, LOG_DEBUG); + /** + * Tag invoice as canceled, with no payment on it (example for replacement invoice or payment never received) + call trigger BILL_CANCEL + * Warning, if option to decrease stock on invoice was set, this function does not change stock (it might be a cancel because + * of no payment even if merchandises were sent). + * + * @param User $user Object user making change + * @param string $close_code Code of closing invoice (CLOSECODE_REPLACED, CLOSECODE_...) + * @param string $close_note Comment + * @return int <0 if KO, >0 if OK + */ + public function setCanceled($user, $close_code = '', $close_note = '') + { + dol_syslog(get_class($this)."::setCanceled rowid=".$this->id, LOG_DEBUG); $this->db->begin(); @@ -2542,7 +2592,7 @@ class Facture extends CommonInvoice return -12; } - $result = $facreplaced->set_canceled($user, self::CLOSECODE_REPLACED, ''); + $result = $facreplaced->setCanceled($user, self::CLOSECODE_REPLACED, ''); if ($result < 0) { $this->error = $facreplaced->error; @@ -3370,8 +3420,8 @@ class Facture extends CommonInvoice } $this->line->id = $rowid; - $this->line->rowid = $rowid; - $this->line->label = $label; + $this->line->rowid = $rowid; + $this->line->label = $label; $this->line->desc = $desc; $this->line->ref_ext = $ref_ext; $this->line->qty = ($this->type == self::TYPE_CREDIT_NOTE ?abs($qty) : $qty); // For credit note, quantity is always positive and unit price negative @@ -3567,6 +3617,8 @@ class Facture extends CommonInvoice /** * Set percent discount * + * @deprecated + * @see setDiscount() * @param User $user User that set discount * @param double $remise Discount * @param int $notrigger 1=Does not execute triggers, 0= execute triggers @@ -3575,6 +3627,20 @@ class Facture extends CommonInvoice public function set_remise($user, $remise, $notrigger = 0) { // phpcs:enable + dol_syslog(get_class($this)."::set_remise is deprecated, use setDiscount instead", LOG_NOTICE); + return $this->setDiscount($user, $remise, $notrigger); + } + + /** + * Set percent discount + * + * @param User $user User that set discount + * @param double $remise Discount + * @param int $notrigger 1=Does not execute triggers, 0= execute triggers + * @return int <0 if ko, >0 if ok + */ + public function setDiscount($user, $remise, $notrigger = 0) + { // Clean parameters if (empty($remise)) $remise = 0; @@ -3732,7 +3798,7 @@ class Facture extends CommonInvoice } if (!empty($addon)) { - dol_syslog("Call getNextNumRef with ".$addonConstName." = ".$conf->global->FACTURE_ADDON.", thirdparty=".$soc->nom.", type=".$soc->typent_code, LOG_DEBUG); + dol_syslog("Call getNextNumRef with ".$addonConstName." = ".$conf->global->FACTURE_ADDON.", thirdparty=".$soc->name.", type=".$soc->typent_code, LOG_DEBUG); $mybool = false; diff --git a/htdocs/compta/paiement/card.php b/htdocs/compta/paiement/card.php index 374ab19e358..b7f8d3c9a3d 100644 --- a/htdocs/compta/paiement/card.php +++ b/htdocs/compta/paiement/card.php @@ -119,7 +119,7 @@ if ($action == 'confirm_validate' && $confirm == 'yes' && $user->rights->facture $outputlangs->setDefaultLang($_REQUEST['lang_id']); } if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { - $fac->generateDocument($fac->modelpdf, $outputlangs); + $fac->generateDocument($fac->model_pdf, $outputlangs); } } diff --git a/htdocs/compta/paiement/cheque/class/remisecheque.class.php b/htdocs/compta/paiement/cheque/class/remisecheque.class.php index 4e22d8f141a..9c685bcce1d 100644 --- a/htdocs/compta/paiement/cheque/class/remisecheque.class.php +++ b/htdocs/compta/paiement/cheque/class/remisecheque.class.php @@ -788,7 +788,7 @@ class RemiseCheque extends CommonObject { $invoice = new Facture($this->db); $invoice->fetch($obj->fk_facture); - $invoice->set_unpaid($user); + $invoice->setUnpaid($user); $rejectedPayment->amounts[$obj->fk_facture] = price2num($obj->amount) * -1; } diff --git a/htdocs/compta/paiement/class/paiement.class.php b/htdocs/compta/paiement/class/paiement.class.php index fcc27276628..fc37c3f309c 100644 --- a/htdocs/compta/paiement/class/paiement.class.php +++ b/htdocs/compta/paiement/class/paiement.class.php @@ -398,7 +398,7 @@ class Paiement extends CommonObject // Set invoice to paid if (!$error) { - $result = $invoice->set_paid($user, '', ''); + $result = $invoice->setPaid($user, '', ''); if ($result < 0) { $this->error = $invoice->error; @@ -425,7 +425,7 @@ class Paiement extends CommonObject $outputlangs->setDefaultLang($newlang); } $ret = $invoice->fetch($facid); // Reload to get new records - $result = $invoice->generateDocument($invoice->modelpdf, $outputlangs); + $result = $invoice->generateDocument($invoice->model_pdf, $outputlangs); if ($result < 0) { setEventMessages($invoice->error, $invoice->errors, 'errors'); $error++; diff --git a/htdocs/compta/paiement_vat.php b/htdocs/compta/paiement_vat.php index 7db2aa674af..5e073f69c53 100644 --- a/htdocs/compta/paiement_vat.php +++ b/htdocs/compta/paiement_vat.php @@ -1,6 +1,6 @@ - * Copyright (C) 2016-2018 Frédéric France + * Copyright (C) 2016-2021 Frédéric France * Copyright (C) 2021 Gauthier VERDOL * * This program is free software; you can redistribute it and/or modify @@ -111,11 +111,10 @@ if ($action == 'add_payment' || ($action == 'confirm_paiement' && $confirm == 'y $paiement->amounts = $amounts; // Tableau de montant $paiement->paiementtype = GETPOST("paiementtype", 'alphanohtml'); $paiement->num_payment = GETPOST("num_payment", 'alphanohtml'); - $paiement->note = GETPOST("note", 'restricthtml'); - $paiement->note_private = GETPOST("note", 'restricthtml'); + $paiement->note = (string) GETPOST("note", 'restricthtml'); + $paiement->note_private = (string) GETPOST("note", 'restricthtml'); - if (!$error) - { + if (!$error) { $paymentid = $paiement->create($user, (GETPOST('closepaidvat') == 'on' ? 1 : 0)); if ($paymentid < 0) { @@ -193,7 +192,7 @@ if ($action == 'create') print ''; print ''; - dol_fiche_head('', ''); + print dol_get_fiche_head('', ''); print ''; @@ -208,8 +207,7 @@ if ($action == 'create') $sql .= " FROM ".MAIN_DB_PREFIX."payment_vat as p"; $sql .= " WHERE p.fk_tva = ".$chid; $resql = $db->query($sql); - if ($resql) - { + if ($resql) { $obj = $db->fetch_object($resql); $sumpaid = $obj->total; $db->free(); @@ -248,7 +246,7 @@ if ($action == 'create') print '
'; - dol_fiche_end(); + print dol_get_fiche_end(); /* * Autres charges impayees @@ -314,8 +312,7 @@ if ($action == 'create') $totalrecu += $objp->am; $i++; } - if ($i > 1) - { + if ($i > 1) { // Print total print ''; print ''.$langs->trans("Total").':'; diff --git a/htdocs/compta/payment_vat/card.php b/htdocs/compta/payment_vat/card.php index 1b085dfe040..dee616eb2ef 100644 --- a/htdocs/compta/payment_vat/card.php +++ b/htdocs/compta/payment_vat/card.php @@ -138,13 +138,12 @@ $h++; */ -dol_fiche_head($head, $hselected, $langs->trans("VATPayment"), -1, 'payment'); +print dol_get_fiche_head($head, $hselected, $langs->trans("VATPayment"), -1, 'payment'); /* * Deletion confirmation of payment */ -if ($action == 'delete') -{ +if ($action == 'delete') { print $form->formconfirm('card.php?id='.$object->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete', '', 0, 2); } @@ -213,7 +212,7 @@ print ''; print ''; -dol_fiche_end(); +print dol_get_fiche_end(); /* diff --git a/htdocs/compta/prelevement/class/bonprelevement.class.php b/htdocs/compta/prelevement/class/bonprelevement.class.php index 961ebe96a7a..22737fcfbfe 100644 --- a/htdocs/compta/prelevement/class/bonprelevement.class.php +++ b/htdocs/compta/prelevement/class/bonprelevement.class.php @@ -375,7 +375,7 @@ class BonPrelevement extends CommonObject dol_syslog(get_class($this)."::set_credite set_paid fac ".$facs[$i]); $fac = new Facture($this->db); $fac->fetch($facs[$i]); - $result = $fac->set_paid($user); + $result = $fac->setPaid($user); } } @@ -482,7 +482,7 @@ class BonPrelevement extends CommonObject // @TODO Move this after creation of payment if (price2num($alreadypayed + $facs[$i][1], 'MT') == $fac->total_ttc) { - $result = $fac->set_paid($user); + $result = $fac->setPaid($user); if ($result < 0) { $this->error = $fac->error; $this->errors = $fac->errors; diff --git a/htdocs/compta/prelevement/class/rejetprelevement.class.php b/htdocs/compta/prelevement/class/rejetprelevement.class.php index 8b7d21d221f..28a3b1e4efa 100644 --- a/htdocs/compta/prelevement/class/rejetprelevement.class.php +++ b/htdocs/compta/prelevement/class/rejetprelevement.class.php @@ -184,7 +184,7 @@ class RejetPrelevement //Tag invoice as unpaid dol_syslog("RejetPrelevement::Create set_unpaid fac ".$fac->ref); - $fac->set_unpaid($user); + $fac->setUnpaid($user); //TODO: Must be managed by notifications module // Send email to sender of the standing order request diff --git a/htdocs/compta/sociales/card.php b/htdocs/compta/sociales/card.php index cfe938ce974..07f3424ba60 100644 --- a/htdocs/compta/sociales/card.php +++ b/htdocs/compta/sociales/card.php @@ -74,14 +74,14 @@ $object = new ChargeSociales($db); if ($action == 'confirm_paid' && $user->rights->tax->charges->creer && $confirm == 'yes') { $object->fetch($id); - $result = $object->set_paid($user); + $result = $object->setPaid($user); } if ($action == 'reopen' && $user->rights->tax->charges->creer) { $result = $object->fetch($id); if ($object->paye) { - $result = $object->set_unpaid($user); + $result = $object->setUnpaid($user); if ($result > 0) { header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id); diff --git a/htdocs/compta/sociales/class/chargesociales.class.php b/htdocs/compta/sociales/class/chargesociales.class.php index 57c169d6180..ec4e945f922 100644 --- a/htdocs/compta/sociales/class/chargesociales.class.php +++ b/htdocs/compta/sociales/class/chargesociales.class.php @@ -432,12 +432,26 @@ class ChargeSociales extends CommonObject /** * Tag social contribution as paid completely * - * @param User $user Object user making change - * @return int <0 if KO, >0 if OK + * @deprecated + * @see setPaid() + * @param User $user Object user making change + * @return int <0 if KO, >0 if OK */ public function set_paid($user) { // phpcs:enable + dol_syslog(get_class($this)."::set_paid is deprecated, use setPaid instead", LOG_NOTICE); + return $this->setPaid($user); + } + + /** + * Tag social contribution as paid completely + * + * @param User $user Object user making change + * @return int <0 if KO, >0 if OK + */ + public function setPaid($user) + { $sql = "UPDATE ".MAIN_DB_PREFIX."chargesociales SET"; $sql .= " paye = 1"; $sql .= " WHERE rowid = ".$this->id; @@ -450,12 +464,26 @@ class ChargeSociales extends CommonObject /** * Remove tag paid on social contribution * - * @param User $user Object user making change - * @return int <0 if KO, >0 if OK + * @deprecated + * @see setUnpaid() + * @param User $user Object user making change + * @return int <0 if KO, >0 if OK */ public function set_unpaid($user) { // phpcs:enable + dol_syslog(get_class($this)."::set_unpaid is deprecated, use setUnpaid instead", LOG_NOTICE); + return $this->setUnpaid($user); + } + + /** + * Remove tag paid on social contribution + * + * @param User $user Object user making change + * @return int <0 if KO, >0 if OK + */ + public function setUnpaid($user) + { $sql = "UPDATE ".MAIN_DB_PREFIX."chargesociales SET"; $sql .= " paye = 0"; $sql .= " WHERE rowid = ".$this->id; diff --git a/htdocs/compta/sociales/class/paymentsocialcontribution.class.php b/htdocs/compta/sociales/class/paymentsocialcontribution.class.php index e821bae2dd9..9258ff63fc3 100644 --- a/htdocs/compta/sociales/class/paymentsocialcontribution.class.php +++ b/htdocs/compta/sociales/class/paymentsocialcontribution.class.php @@ -197,7 +197,7 @@ class PaymentSocialContribution extends CommonObject $remaintopay = price2num($contrib->amount - $paiement - $creditnotes - $deposits, 'MT'); if ($remaintopay == 0) { - $result = $contrib->set_paid($user); + $result = $contrib->setPaid($user); } else dol_syslog("Remain to pay for conrib ".$contribid." not null. We do nothing."); } } diff --git a/htdocs/compta/tva/card.php b/htdocs/compta/tva/card.php index 37ef7d689ab..a961d4f1994 100644 --- a/htdocs/compta/tva/card.php +++ b/htdocs/compta/tva/card.php @@ -111,14 +111,14 @@ if ($action == 'setbankaccount' && $user->rights->tax->charges->creer) { if ($action == 'confirm_paid' && $user->rights->tax->charges->creer && $confirm == 'yes') { $object->fetch($id); - $result = $object->set_paid($user); + $result = $object->setPaid($user); } if ($action == 'reopen' && $user->rights->tax->charges->creer) { $result = $object->fetch($id); if ($object->paye) { - $result = $object->set_unpaid($user); + $result = $object->setUnpaid($user); if ($result > 0) { header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id); diff --git a/htdocs/compta/tva/class/paymentvat.class.php b/htdocs/compta/tva/class/paymentvat.class.php index 35178dbc0ee..13369e596bc 100644 --- a/htdocs/compta/tva/class/paymentvat.class.php +++ b/htdocs/compta/tva/class/paymentvat.class.php @@ -194,7 +194,7 @@ class PaymentVAT extends CommonObject $remaintopay = price2num($contrib->amount - $paiement - $creditnotes - $deposits, 'MT'); if ($remaintopay == 0) { - $result = $contrib->set_paid($user); + $result = $contrib->setPaid($user); } else dol_syslog("Remain to pay for conrib ".$contribid." not null. We do nothing."); } @@ -480,7 +480,7 @@ class PaymentVAT extends CommonObject { $this->id = 0; - $this->fk_tva = ''; + $this->fk_tva = 0; $this->datec = ''; $this->tms = ''; $this->datep = ''; @@ -489,9 +489,9 @@ class PaymentVAT extends CommonObject $this->num_payment = ''; $this->note_private = ''; $this->note_public = ''; - $this->fk_bank = ''; - $this->fk_user_creat = ''; - $this->fk_user_modif = ''; + $this->fk_bank = 0; + $this->fk_user_creat = 0; + $this->fk_user_modif = 0; } diff --git a/htdocs/compta/tva/class/tva.class.php b/htdocs/compta/tva/class/tva.class.php index 8a817e6575f..a39a00d8b01 100644 --- a/htdocs/compta/tva/class/tva.class.php +++ b/htdocs/compta/tva/class/tva.class.php @@ -246,14 +246,14 @@ class Tva extends CommonObject * @param User $user Object user making change * @return int <0 if KO, >0 if OK */ - public function set_paid($user) + public function setPaid($user) { // phpcs:enable $sql = "UPDATE ".MAIN_DB_PREFIX."tva SET"; $sql .= " paye = 1"; $sql .= " WHERE rowid = ".$this->id; - $return = $this->db->query($sql); - if ($return) return 1; + $resql = $this->db->query($sql); + if ($resql) return 1; else return -1; } @@ -263,14 +263,14 @@ class Tva extends CommonObject * @param User $user Object user making change * @return int <0 if KO, >0 if OK */ - public function set_unpaid($user) + public function setUnpaid($user) { // phpcs:enable $sql = "UPDATE ".MAIN_DB_PREFIX."tva SET"; $sql .= " paye = 0"; $sql .= " WHERE rowid = ".$this->id; - $return = $this->db->query($sql); - if ($return) return 1; + $resql = $this->db->query($sql); + if ($resql) return 1; else return -1; } diff --git a/htdocs/core/actions_massactions.inc.php b/htdocs/core/actions_massactions.inc.php index 403c8c52a42..95c5037c5fb 100644 --- a/htdocs/core/actions_massactions.inc.php +++ b/htdocs/core/actions_massactions.inc.php @@ -304,7 +304,7 @@ if (!$error && $massaction == 'confirm_presend') if ($_POST['addmaindocfile']) { // TODO Use future field $objectobj->fullpathdoc to know where is stored default file - // TODO If not defined, use $objectobj->modelpdf (or defaut invoice config) to know what is template to use to regenerate doc. + // TODO If not defined, use $objectobj->model_pdf (or defaut invoice config) to know what is template to use to regenerate doc. $filename = dol_sanitizeFileName($objectobj->ref).'.pdf'; $subdir = ''; // TODO Set subdir to be compatible with multi levels dir trees @@ -1281,7 +1281,7 @@ if (!$error && $massaction == 'generate_doc' && $permissiontoread) if (empty($hideref)) $hideref = 0; if (empty($moreparams)) $moreparams = null; - $result = $objecttmp->generateDocument($objecttmp->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams); + $result = $objecttmp->generateDocument($objecttmp->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams); if ($result <= 0) { diff --git a/htdocs/core/class/commondocgenerator.class.php b/htdocs/core/class/commondocgenerator.class.php index 03a5154f23f..2340657ef4e 100644 --- a/htdocs/core/class/commondocgenerator.class.php +++ b/htdocs/core/class/commondocgenerator.class.php @@ -55,6 +55,11 @@ abstract class CommonDocGenerator */ public $extrafieldsCache; + /** + * @var int If set to 1, save the fullname of generated file with path as the main doc when generating a doc with this template. + */ + public $update_main_doc_field; + /** * Constructor * diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 50c60dc16eb..4ada3c368d0 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -355,6 +355,13 @@ abstract class CommonObject */ public $model_pdf; + /** + * @var string + * @deprecated + * @see model_pdf + */ + public $modelpdf; + /** * @var string * Contains relative path of last generated main file diff --git a/htdocs/core/class/html.formcompany.class.php b/htdocs/core/class/html.formcompany.class.php index b3e383ea762..93b8f5391e7 100644 --- a/htdocs/core/class/html.formcompany.class.php +++ b/htdocs/core/class/html.formcompany.class.php @@ -757,30 +757,36 @@ class FormCompany extends Form * @param string $sortorder Sort criteria ('position', 'code', ...) * @param int $showempty 1=Add en empty line * @param string $morecss Add more css to select component + * @param int $output 0=return HTML, 1= direct print * @return void */ - public function selectTypeContact($object, $selected, $htmlname = 'type', $source = 'internal', $sortorder = 'position', $showempty = 0, $morecss = '') + public function selectTypeContact($object, $selected, $htmlname = 'type', $source = 'internal', $sortorder = 'position', $showempty = 0, $morecss = '', $output = 1) { global $user, $langs; - + $out = ''; if (is_object($object) && method_exists($object, 'liste_type_contact')) { $lesTypes = $object->liste_type_contact($source, $sortorder, 0, 1); - print ''; + if ($showempty) $out .= ''; foreach ($lesTypes as $key=>$value) { - print ''; + $out .= '