diff --git a/htdocs/expensereport/card.php b/htdocs/expensereport/card.php index 54bdc279098..8e382fb4285 100644 --- a/htdocs/expensereport/card.php +++ b/htdocs/expensereport/card.php @@ -827,6 +827,18 @@ if ($action == "confirm_brouillonner" && GETPOST('confirm')=="yes" && $id > 0 && } } +if ($action == 'set_paid') +{ + if ($object->set_paid($id) >= 0) + { + header("Location: ".$_SERVER['PHP_SELF']."?id=".$id); + exit; + } + else { + setEventMessage($object->error, 'errors'); + } +} + if ($action == "addline") { $error = 0; @@ -1988,7 +2000,11 @@ if ($action != 'create' && $action != 'edit') { print '
' . $langs->trans('DoPayment') . '
'; } - print 'id.'">'.$langs->trans('TO_PAID').''; + + if ($object->statut == 1 && round($remaintopay) == 0 && $object->paid == 0 && $user->rights->don->creer) + { + print '
'.$langs->trans("ClassifyPaid")."
"; + } // Cancel if ($user->id == $object->fk_user_author || $user->id == $object->fk_user_valid) diff --git a/htdocs/expensereport/class/expensereport.class.php b/htdocs/expensereport/class/expensereport.class.php index 7dede6d11a9..168b4580a62 100644 --- a/htdocs/expensereport/class/expensereport.class.php +++ b/htdocs/expensereport/class/expensereport.class.php @@ -372,6 +372,36 @@ class ExpenseReport extends CommonObject } } + /** + * Classify the expense report as paid + * + * @param int $id id of expense report + * @param int $modepayment mode of payment + * @return int <0 if KO, >0 if OK + */ + function set_paid($id) + { + $sql = "UPDATE ".MAIN_DB_PREFIX."expensereport SET fk_statut = 6"; + $sql.= " WHERE rowid = $id AND fk_statut = 5"; + + $resql=$this->db->query($sql); + if ($resql) + { + if ($this->db->affected_rows($resql)) + { + return 1; + } + else + { + return 0; + } + } + else + { + dol_print_error($this->db); + return -1; + } + } /** * Returns the label status