diff --git a/htdocs/adherents/adherent.class.php b/htdocs/adherents/adherent.class.php index f21090d4a8e..c47c007f211 100644 --- a/htdocs/adherents/adherent.class.php +++ b/htdocs/adherents/adherent.class.php @@ -941,9 +941,10 @@ class Adherent \param num_chq Numero cheque (si Id compte bancaire fourni) \param emetteur_nom Nom emetteur chèque \param emetteur_banque Nom banque emetteur chèque + \param datesubend Date fin adhesion \return int rowid de l'entrée ajoutée, <0 si erreur */ - function cotisation($date, $montant, $accountid=0, $operation='', $label='', $num_chq='', $emetteur_nom='', $emetteur_banque='') + function cotisation($date, $montant, $accountid=0, $operation='', $label='', $num_chq='', $emetteur_nom='', $emetteur_banque='', $datesubend=0) { global $conf,$langs,$user; @@ -956,6 +957,7 @@ class Adherent $cotisation=new Cotisation($this->db); $cotisation->fk_adherent=$this->id; $cotisation->dateh=$date; + $cotisation->datef=$datesubend; $cotisation->amount=$montant; $cotisation->note=$label; @@ -963,10 +965,17 @@ class Adherent if ($rowid > 0) { - // datefin = date + 1 an - 1 jour - $datefin = dolibarr_time_plus_duree($date,1,'y'); - $datefin = dolibarr_time_plus_duree($datefin,-1,'d'); - + if ($datesubend) + { + $datefin=$datesubend; + } + else + { + // If no end date, end date = date + 1 year - 1 day + $datefin = dolibarr_time_plus_duree($date,1,'y'); + $datefin = dolibarr_time_plus_duree($datefin,-1,'d'); + } + $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET datefin = ".$this->db->idate($datefin); $sql.= " WHERE rowid =". $this->id; diff --git a/htdocs/adherents/card_subscriptions.php b/htdocs/adherents/card_subscriptions.php index d57bbdb3c67..be9430becd7 100644 --- a/htdocs/adherents/card_subscriptions.php +++ b/htdocs/adherents/card_subscriptions.php @@ -50,6 +50,9 @@ $adho = new AdherentOptions($db); $adht = new AdherentType($db); $errmsg=''; +$defaultdelay=1; +$defaultdelayunit='y'; + $action=isset($_GET["action"])?$_GET["action"]:$_POST["action"]; $rowid=isset($_GET["rowid"])?$_GET["rowid"]:$_POST["rowid"]; $typeid=isset($_GET["typeid"])?$_GET["typeid"]:$_POST["typeid"]; @@ -71,12 +74,15 @@ if ($user->rights->adherent->cotisation->creer && $_POST["action"] == 'cotisatio $adht->fetch($adh->typeid); - $reday=$_POST["reday"]; - $remonth=$_POST["remonth"]; - $reyear=$_POST["reyear"]; + $datecotisation=0; + $datesubend=0; if ($_POST["reyear"] && $_POST["remonth"] && $_POST["reday"]) { - $datecotisation=dolibarr_mktime(12, 0, 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]); + $datecotisation=dolibarr_mktime(0, 0, 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]); + } + if ($_POST["endyear"] && $_POST["endmonth"] && $_POST["endday"]) + { + $datesubend=dolibarr_mktime(0, 0, 0, $_POST["endmonth"], $_POST["endday"], $_POST["endyear"]); } $cotisation=$_POST["cotisation"]; @@ -92,7 +98,11 @@ if ($user->rights->adherent->cotisation->creer && $_POST["action"] == 'cotisatio $errmsg=$langs->trans("BadDateFormat"); $action='addsubscription'; } - + if (! $datesubend) + { + $datesubend=dolibarr_time_plus_duree(dolibarr_time_plus_duree($datecotisation,$defaultdelay,$defaultdelayunit),-1,'d'); + } + if ($adht->cotisation) // Type adherent soumis a cotisation { if (! is_numeric($_POST["cotisation"])) @@ -124,7 +134,7 @@ if ($user->rights->adherent->cotisation->creer && $_POST["action"] == 'cotisatio { $db->begin(); - $crowid=$adh->cotisation($datecotisation, $cotisation, $accountid, $operation, $label, $num_chq, $emetteur_nom, $emetteur_banque); + $crowid=$adh->cotisation($datecotisation, $cotisation, $accountid, $operation, $label, $num_chq, $emetteur_nom, $emetteur_banque, $datesubend); if ($crowid > 0) { @@ -160,13 +170,8 @@ if ($user->rights->adherent->cotisation->creer && $_POST["action"] == 'cotisatio /* ************************************************************************** */ llxHeader(); -$html = new Form($db); -if ($errmsg) -{ - print '