New: Fin gestion date fin adhesion sur adhesion.

This commit is contained in:
Laurent Destailleur 2007-09-05 07:43:43 +00:00
parent 1c1e272f58
commit 178a64e8e9
3 changed files with 74 additions and 27 deletions

View File

@ -941,9 +941,10 @@ class Adherent
\param num_chq Numero cheque (si Id compte bancaire fourni) \param num_chq Numero cheque (si Id compte bancaire fourni)
\param emetteur_nom Nom emetteur chèque \param emetteur_nom Nom emetteur chèque
\param emetteur_banque Nom banque 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 \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; global $conf,$langs,$user;
@ -956,6 +957,7 @@ class Adherent
$cotisation=new Cotisation($this->db); $cotisation=new Cotisation($this->db);
$cotisation->fk_adherent=$this->id; $cotisation->fk_adherent=$this->id;
$cotisation->dateh=$date; $cotisation->dateh=$date;
$cotisation->datef=$datesubend;
$cotisation->amount=$montant; $cotisation->amount=$montant;
$cotisation->note=$label; $cotisation->note=$label;
@ -963,9 +965,16 @@ class Adherent
if ($rowid > 0) if ($rowid > 0)
{ {
// datefin = date + 1 an - 1 jour 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($date,1,'y');
$datefin = dolibarr_time_plus_duree($datefin,-1,'d'); $datefin = dolibarr_time_plus_duree($datefin,-1,'d');
}
$sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET datefin = ".$this->db->idate($datefin); $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET datefin = ".$this->db->idate($datefin);
$sql.= " WHERE rowid =". $this->id; $sql.= " WHERE rowid =". $this->id;

View File

@ -50,6 +50,9 @@ $adho = new AdherentOptions($db);
$adht = new AdherentType($db); $adht = new AdherentType($db);
$errmsg=''; $errmsg='';
$defaultdelay=1;
$defaultdelayunit='y';
$action=isset($_GET["action"])?$_GET["action"]:$_POST["action"]; $action=isset($_GET["action"])?$_GET["action"]:$_POST["action"];
$rowid=isset($_GET["rowid"])?$_GET["rowid"]:$_POST["rowid"]; $rowid=isset($_GET["rowid"])?$_GET["rowid"]:$_POST["rowid"];
$typeid=isset($_GET["typeid"])?$_GET["typeid"]:$_POST["typeid"]; $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); $adht->fetch($adh->typeid);
$reday=$_POST["reday"]; $datecotisation=0;
$remonth=$_POST["remonth"]; $datesubend=0;
$reyear=$_POST["reyear"];
if ($_POST["reyear"] && $_POST["remonth"] && $_POST["reday"]) 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"]; $cotisation=$_POST["cotisation"];
@ -92,6 +98,10 @@ if ($user->rights->adherent->cotisation->creer && $_POST["action"] == 'cotisatio
$errmsg=$langs->trans("BadDateFormat"); $errmsg=$langs->trans("BadDateFormat");
$action='addsubscription'; $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 ($adht->cotisation) // Type adherent soumis a cotisation
{ {
@ -124,7 +134,7 @@ if ($user->rights->adherent->cotisation->creer && $_POST["action"] == 'cotisatio
{ {
$db->begin(); $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) if ($crowid > 0)
{ {
@ -160,13 +170,8 @@ if ($user->rights->adherent->cotisation->creer && $_POST["action"] == 'cotisatio
/* ************************************************************************** */ /* ************************************************************************** */
llxHeader(); llxHeader();
$html = new Form($db);
if ($errmsg) $html = new Form($db);
{
print '<div class="error">'.$errmsg.'</div>';
print "\n";
}
$adh->id = $rowid; $adh->id = $rowid;
$result=$adh->fetch($rowid); $result=$adh->fetch($rowid);
@ -218,6 +223,13 @@ print '</form>';
print "</div>\n"; print "</div>\n";
if ($errmsg)
{
print '<div class="error">'.$errmsg.'</div>';
print "\n";
}
/* /*
* Barre d'actions * Barre d'actions
* *
@ -363,11 +375,17 @@ if ($action == 'addsubscription' && $user->rights->adherent->cotisation->creer)
print '<tr><td colspan="2"><b>'.$langs->trans("NewCotisation").'</b></td></tr>'; print '<tr><td colspan="2"><b>'.$langs->trans("NewCotisation").'</b></td></tr>';
$today=mktime(); $today=mktime();
$defaultdelay=1; $datefrom=0;
$defaultdelayunit='y'; $dateto=0;
// Date start subscription // Date start subscription
print '<tr><td>'.$langs->trans("DateSubscription").'</td><td>'; print '<tr><td>'.$langs->trans("DateSubscription").'</td><td>';
if ($_POST["reday"])
{
$datefrom=dolibarr_mktime(0,0,0,$_POST["remonth"],$_POST["reday"],$_POST["reyear"]);
}
if (! $datefrom)
{
if ($adh->datefin > 0) if ($adh->datefin > 0)
{ {
$datefrom=dolibarr_time_plus_duree($adh->datefin,1,'d'); $datefrom=dolibarr_time_plus_duree($adh->datefin,1,'d');
@ -376,12 +394,21 @@ if ($action == 'addsubscription' && $user->rights->adherent->cotisation->creer)
{ {
$datefrom=mktime(); $datefrom=mktime();
} }
}
$html->select_date($datefrom,'','','','',"cotisation"); $html->select_date($datefrom,'','','','',"cotisation");
print "</td></tr>"; print "</td></tr>";
// Date end subscription // 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 '<tr><td>'.$langs->trans("DateEndSubscription").'</td><td>'; 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"); $html->select_date($dateto,'end','','','',"cotisation");
print "</td></tr>"; print "</td></tr>";

View File

@ -41,7 +41,8 @@ class Cotisation
var $datec; var $datec;
var $datem; var $datem;
var $dateh; var $dateh; // Subscription start date
var $datef; // Subscription end date
var $fk_adherent; var $fk_adherent;
var $amount; var $amount;
var $note; var $note;
@ -65,8 +66,18 @@ class Cotisation
*/ */
function create($userid) function create($userid)
{ {
$sql = "INSERT INTO ".MAIN_DB_PREFIX."cotisation (fk_adherent, datec, dateadh, cotisation, note)"; // Check parameters
$sql .= " VALUES (".$this->fk_adherent.", now(), ".$this->db->idate($this->dateh).", ".$this->amount.",'".$this->note."')"; 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); dolibarr_syslog("Cotisation::create sql=".$sql);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);