From e0dee02855bdb6b625ffd97c3c76b456782dfa34 Mon Sep 17 00:00:00 2001
From: Laurent Destailleur <eldy@users.sourceforge.net>
Date: Tue, 4 Sep 2007 17:53:11 +0000
Subject: [PATCH] New: Debut date fin adhesion sur adhesion.

---
 htdocs/adherents/adherent.class.php     | 15 +++++++++---
 htdocs/adherents/card_subscriptions.php | 16 +++++++++++--
 htdocs/adherents/cotisation.class.php   |  2 ++
 htdocs/adherents/fiche_subscription.php | 31 ++++++++++++++++++++-----
 mysql/migration/2.1.0-2.2.0.sql         |  3 +++
 mysql/tables/llx_cotisation.sql         |  1 +
 6 files changed, 57 insertions(+), 11 deletions(-)

diff --git a/htdocs/adherents/adherent.class.php b/htdocs/adherents/adherent.class.php
index 1ba8dbfd639..f21090d4a8e 100644
--- a/htdocs/adherents/adherent.class.php
+++ b/htdocs/adherents/adherent.class.php
@@ -1739,16 +1739,25 @@ class Adherent
 	 *    	\brief      Renvoie nom clicable (avec eventuellement le picto)
 	 *		\param		withpicto		0=Pas de picto, 1=Inclut le picto dans le lien, 2=Picto seul
 	 *		\param		maxlen			Longueur max libelle
+	 *		\param		option			Page lien
 	 *		\return		string			Chaine avec URL
 	 */
-	function getNomUrl($withpicto=0,$maxlen=0)
+	function getNomUrl($withpicto=0,$maxlen=0,$option='card')
 	{
 		global $langs;
 		
 		$result='';
 
-		$lien = '<a href="'.DOL_URL_ROOT.'/adherents/fiche.php?rowid='.$this->id.'">';
-		$lienfin='</a>';
+		if ($option == 'card')
+		{
+			$lien = '<a href="'.DOL_URL_ROOT.'/adherents/fiche.php?rowid='.$this->id.'">';
+			$lienfin='</a>';
+		}
+		if ($option == 'subscription')
+		{
+			$lien = '<a href="'.DOL_URL_ROOT.'/adherents/card_subscriptions.php?rowid='.$this->id.'">';
+			$lienfin='</a>';
+		}
 		
 		$picto='user';
 		$label=$langs->trans("ShowMember");
diff --git a/htdocs/adherents/card_subscriptions.php b/htdocs/adherents/card_subscriptions.php
index 5fd8a37f6e9..d57bbdb3c67 100644
--- a/htdocs/adherents/card_subscriptions.php
+++ b/htdocs/adherents/card_subscriptions.php
@@ -362,15 +362,27 @@ if ($action == 'addsubscription' && $user->rights->adherent->cotisation->creer)
 
 	print '<tr><td colspan="2"><b>'.$langs->trans("NewCotisation").'</b></td></tr>';
 
+	$today=mktime();
+	$defaultdelay=1;
+	$defaultdelayunit='y';
+
+	// Date start subscription
 	print '<tr><td>'.$langs->trans("DateSubscription").'</td><td>';
 	if ($adh->datefin > 0)
 	{
-		$html->select_date(dolibarr_time_plus_duree($adh->datefin,1,'d'),'','','','',"cotisation");
+		$datefrom=dolibarr_time_plus_duree($adh->datefin,1,'d');
 	}
 	else
 	{
-		$html->select_date('','','','','',"cotisation");
+		$datefrom=mktime();
 	}
+	$html->select_date($datefrom,'','','','',"cotisation");
+	print "</td></tr>";
+
+	// Date end subscription
+	print '<tr><td>'.$langs->trans("DateEndSubscription").'</td><td>';
+	$dateto=dolibarr_time_plus_duree(dolibarr_time_plus_duree($datefrom,$defaultdelay,$defaultdelayunit),-1,'d');
+	$html->select_date($dateto,'end','','','',"cotisation");
 	print "</td></tr>";
 
 	if ($adht->cotisation)
diff --git a/htdocs/adherents/cotisation.class.php b/htdocs/adherents/cotisation.class.php
index 2966ec13b7b..41324f41885 100644
--- a/htdocs/adherents/cotisation.class.php
+++ b/htdocs/adherents/cotisation.class.php
@@ -93,6 +93,7 @@ class Cotisation
         $sql ="SELECT rowid, fk_adherent, ".$this->db->pdate("datec")." as datec,";
 		$sql.=" tms,";
 		$sql.=" ".$this->db->pdate("dateadh")." as dateadh,";
+		$sql.=" ".$this->db->pdate("datef")." as datef,";
 		$sql.=" cotisation, note, fk_bank";
 		$sql.=" FROM ".MAIN_DB_PREFIX."cotisation";
 		$sql.="	WHERE rowid=".$rowid;
@@ -112,6 +113,7 @@ class Cotisation
 				$this->datec          = $obj->datec;
 				$this->datem          = $obj->tms;
 				$this->dateh          = $obj->dateadh;
+				$this->datef          = $obj->datef;
 				$this->amount         = $obj->cotisation;
 				$this->note           = $obj->note;
 				$this->fk_bank        = $obj->fk_bank;
diff --git a/htdocs/adherents/fiche_subscription.php b/htdocs/adherents/fiche_subscription.php
index 19e663692de..edce2ed3233 100644
--- a/htdocs/adherents/fiche_subscription.php
+++ b/htdocs/adherents/fiche_subscription.php
@@ -194,12 +194,18 @@ if ($user->rights->adherent->cotisation->creer && $action == 'edit')
     // Ref
     print '<tr><td width="20%">'.$langs->trans("Ref").'</td><td class="valeur" colspan="2">'.$subscription->ref.'&nbsp;</td></tr>';
 	
-    // Date
-    print '<tr><td>'.$langs->trans("Date").'</td><td class="valeur" colspan="2">';
+    // Date start subscription
+    print '<tr><td>'.$langs->trans("DateSubscription").'</td><td class="valeur" colspan="2">';
 	$htmls->select_date($subscription->dateh,'datesub',1,1,0,'update',1);
 	print '</td>';
     print '</tr>';
 
+    // Date end subscription
+    print '<tr><td>'.$langs->trans("DateEndSubscription").'</td><td class="valeur" colspan="2">';
+	$htmls->select_date($subscription->datef,'datesubend',0,0,0,'update',1);
+	print '</td>';
+    print '</tr>';
+
     // Amount
     print '<tr><td>'.$langs->trans("Amount").'</td><td class="valeur" colspan="2">';
 	print '<input type="text" class="flat" size="10" name="amount" value="'.price($subscription->amount).'"></td></tr>';
@@ -226,8 +232,9 @@ if ($rowid && $action != 'edit')
 	/*                                                                            */
 	/* ************************************************************************** */
 
-    $subscription->fetch($rowid);
-
+    $result=$subscription->fetch($rowid);
+	$result=$adh->fetch($subscription->fk_adherent);
+	
     $html = new Form($db);
 
 	/*
@@ -272,8 +279,20 @@ if ($rowid && $action != 'edit')
 	if ($previous_id || $next_id) print '</td><td class="nobordernopadding" align="center" width="20">'.$previous_id.'</td><td class="nobordernopadding" align="center" width="20">'.$next_id.'</td></tr></table>';
 	print '</td></tr>';
 
-    // Date
-    print '<tr><td>'.$langs->trans("Date").'</td><td class="valeur">'.dolibarr_print_date($subscription->dateh,'dayhour').'</td>';
+    // Member
+	$adh->ref=$adh->fullname;
+    print '<tr>';
+	print '<td>'.$langs->trans("Member").'</td><td class="valeur">'.$adh->getNomUrl(1,0,'subscription').'</td>';
+    print '</tr>';
+
+    // Date subscription
+    print '<tr>';
+	print '<td>'.$langs->trans("DateSubscription").'</td><td class="valeur">'.dolibarr_print_date($subscription->dateh,'dayhour').'</td>';
+    print '</tr>';
+
+    // Date end subscription
+    print '<tr>';
+	print '<td>'.$langs->trans("DateEndSubscription").'</td><td class="valeur">'.dolibarr_print_date($subscription->datef,'day').'</td>';
     print '</tr>';
 
     // Amount
diff --git a/mysql/migration/2.1.0-2.2.0.sql b/mysql/migration/2.1.0-2.2.0.sql
index 90b5bbe6e4c..0556e99dc53 100644
--- a/mysql/migration/2.1.0-2.2.0.sql
+++ b/mysql/migration/2.1.0-2.2.0.sql
@@ -31,7 +31,10 @@ alter table llx_paiement drop column author;
 
 update llx_actioncomm set fk_action = 9 where fk_action = 10;
 
+ALTER TABLE llx_cotisation ADD COLUMN datef date after dateadh;
+ALTER TABLE llx_cotisation modify datef date;
 ALTER TABLE llx_cotisation ADD UNIQUE INDEX uk_cotisation (fk_adherent,dateadh);
+update llx_cotisation set datef = ADDDATE(ADDDATE(dateadh, INTERVAL 1 YEAR),INTERVAL -1 DAY);
 
 update llx_const set name='MAIN_ENABLE_DEVELOPMENT' where name='MAIN_SHOW_DEVELOPMENT_MODULES';
 delete from llx_const where name='MAIN_SHOW_DEVELOPMENT_MODULES';
diff --git a/mysql/tables/llx_cotisation.sql b/mysql/tables/llx_cotisation.sql
index 06983d356ff..a1ca0a22ffd 100644
--- a/mysql/tables/llx_cotisation.sql
+++ b/mysql/tables/llx_cotisation.sql
@@ -26,6 +26,7 @@ create table llx_cotisation
   datec           datetime,
   fk_adherent     integer,
   dateadh         datetime,
+  datef           date,
   cotisation      real,
   fk_bank         int(11) DEFAULT NULL,
   note            text
-- 
GitLab