From 178a64e8e93064ff26c44f54027724f5f022958b Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 5 Sep 2007 07:43:43 +0000 Subject: [PATCH] New: Fin gestion date fin adhesion sur adhesion. --- htdocs/adherents/adherent.class.php | 19 ++++++-- htdocs/adherents/card_subscriptions.php | 65 +++++++++++++++++-------- htdocs/adherents/cotisation.class.php | 17 +++++-- 3 files changed, 74 insertions(+), 27 deletions(-) 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 '
'.$errmsg.'
'; - print "\n"; -} +$html = new Form($db); $adh->id = $rowid; $result=$adh->fetch($rowid); @@ -218,6 +223,13 @@ print ''; print "\n"; +if ($errmsg) +{ + print '
'.$errmsg.'
'; + print "\n"; +} + + /* * Barre d'actions * @@ -363,25 +375,40 @@ if ($action == 'addsubscription' && $user->rights->adherent->cotisation->creer) print ''.$langs->trans("NewCotisation").''; $today=mktime(); - $defaultdelay=1; - $defaultdelayunit='y'; + $datefrom=0; + $dateto=0; // Date start subscription print ''.$langs->trans("DateSubscription").''; - if ($adh->datefin > 0) + if ($_POST["reday"]) { - $datefrom=dolibarr_time_plus_duree($adh->datefin,1,'d'); + $datefrom=dolibarr_mktime(0,0,0,$_POST["remonth"],$_POST["reday"],$_POST["reyear"]); } - else + if (! $datefrom) { - $datefrom=mktime(); + if ($adh->datefin > 0) + { + $datefrom=dolibarr_time_plus_duree($adh->datefin,1,'d'); + } + else + { + $datefrom=mktime(); + } } $html->select_date($datefrom,'','','','',"cotisation"); print ""; // Date end subscription + if ($_POST["endday"]) + { + $dateto=dolibarr_mktime(0,0,0,$_POST["endmonth"],$_POST["endday"],$_POST["endyear"]); + } + if (! $dateto) + { + //$dateto=dolibarr_time_plus_duree(dolibarr_time_plus_duree($datefrom,$defaultdelay,$defaultdelayunit),-1,'d'); + $dateto=-1; // By default, no date is suggested + } print ''.$langs->trans("DateEndSubscription").''; - $dateto=dolibarr_time_plus_duree(dolibarr_time_plus_duree($datefrom,$defaultdelay,$defaultdelayunit),-1,'d'); $html->select_date($dateto,'end','','','',"cotisation"); print ""; diff --git a/htdocs/adherents/cotisation.class.php b/htdocs/adherents/cotisation.class.php index 41324f41885..4e5a1245681 100644 --- a/htdocs/adherents/cotisation.class.php +++ b/htdocs/adherents/cotisation.class.php @@ -41,7 +41,8 @@ class Cotisation var $datec; var $datem; - var $dateh; + var $dateh; // Subscription start date + var $datef; // Subscription end date var $fk_adherent; var $amount; var $note; @@ -65,8 +66,18 @@ class Cotisation */ function create($userid) { - $sql = "INSERT INTO ".MAIN_DB_PREFIX."cotisation (fk_adherent, datec, dateadh, cotisation, note)"; - $sql .= " VALUES (".$this->fk_adherent.", now(), ".$this->db->idate($this->dateh).", ".$this->amount.",'".$this->note."')"; + // Check parameters + if ($this->datef <= $this->dateh) + { + $this->error="Error: Bad value for datef or dateh"; + return -1; + } + + $sql = "INSERT INTO ".MAIN_DB_PREFIX."cotisation (fk_adherent, datec, dateadh, datef, cotisation, note)"; + $sql.= " VALUES (".$this->fk_adherent.", now(),"; + $sql.= " ".$this->db->idate($this->dateh).","; + $sql.= " ".$this->db->idate($this->datef).","; + $sql.= " ".$this->amount.",'".$this->note."')"; dolibarr_syslog("Cotisation::create sql=".$sql); $resql = $this->db->query($sql);