|
diff --git a/galette/lib/Galette/Controllers/Crud/ContributionsTypesController.php b/galette/lib/Galette/Controllers/Crud/ContributionsTypesController.php
|
|
index d02f0a31..f01e0b4f 100644
|
|
--- a/galette/lib/Galette/Controllers/Crud/ContributionsTypesController.php
|
|
+++ b/galette/lib/Galette/Controllers/Crud/ContributionsTypesController.php
|
|
@@ -197,7 +197,7 @@ class ContributionsTypesController extends CrudController
|
|
$ctype = new ContributionsTypes($this->zdb);
|
|
|
|
$label = trim($post['libelle_type_cotis']);
|
|
- $field = (bool)trim($post['cotis_extension'] ?? 0);
|
|
+ $field = (int)trim($post['cotis_extension'] ?? 0);
|
|
$amount = null;
|
|
if (isset($post['amount']) && $post['amount'] !== '') {
|
|
$amount = (float)$post['amount'];
|
|
diff --git a/galette/lib/Galette/Entity/Contribution.php b/galette/lib/Galette/Entity/Contribution.php
|
|
index 6de13eb4..b8dc5b7f 100644
|
|
--- a/galette/lib/Galette/Entity/Contribution.php
|
|
+++ b/galette/lib/Galette/Entity/Contribution.php
|
|
@@ -237,30 +237,39 @@ class Contribution
|
|
$begin_date = new \DateTime($this->_begin_date);
|
|
if ($preferences->pref_beg_membership != '') {
|
|
//case beginning of membership
|
|
- list($j, $m) = explode('/', $preferences->pref_beg_membership);
|
|
- $next_begin_date = new \DateTime($begin_date->format('Y') . '-' . $m . '-' . $j);
|
|
- while ($next_begin_date <= $begin_date) {
|
|
- $next_begin_date->add(new \DateInterval('P1Y'));
|
|
- }
|
|
+ if($this->_type->extension < 1){ // 0 = donate; -1= else duration (months)
|
|
|
|
- if ($preferences->pref_membership_offermonths > 0) {
|
|
- //count days until next membership begin date
|
|
- $diff1 = (int)$now->diff($next_begin_date)->format('%a');
|
|
+ list($j, $m) = explode('/', $preferences->pref_beg_membership);
|
|
+ $next_begin_date = new \DateTime($begin_date->format('Y') . '-' . $m . '-' . $j);
|
|
+ while ($next_begin_date <= $begin_date) {
|
|
+ $next_begin_date->add(new \DateInterval('P1Y'));
|
|
+ }
|
|
|
|
- //count days between next membership begin date and offered months
|
|
- $tdate = clone $next_begin_date;
|
|
- $tdate->sub(new \DateInterval('P' . $preferences->pref_membership_offermonths . 'M'));
|
|
- $diff2 = (int)$next_begin_date->diff($tdate)->format('%a');
|
|
+ if ($preferences->pref_membership_offermonths > 0) {
|
|
+ //count days until next membership begin date
|
|
+ $diff1 = (int)$now->diff($next_begin_date)->format('%a');
|
|
|
|
- //when number of days until next membership begin date is less than or equal to the offered months, it's free :)
|
|
- if ($diff1 <= $diff2) {
|
|
- $next_begin_date->add(new \DateInterval('P1Y'));
|
|
+ //count days between next membership begin date and offered months
|
|
+ $tdate = clone $next_begin_date;
|
|
+ $tdate->sub(new \DateInterval('P' . $preferences->pref_membership_offermonths . 'M'));
|
|
+ $diff2 = (int)$next_begin_date->diff($tdate)->format('%a');
|
|
+
|
|
+ //when number of days until next membership begin date is less than or equal to the offered months, it's free :)
|
|
+ if ($diff1 <= $diff2) {
|
|
+ $next_begin_date->add(new \DateInterval('P1Y'));
|
|
+ }
|
|
}
|
|
- }
|
|
|
|
- // Caution : the end_date to retrieve is the day before the next_begin_date.
|
|
- $end_date = clone $next_begin_date;
|
|
- $end_date->sub(new \DateInterval('P1D'));
|
|
+ // Caution : the end_date to retrieve is the day before the next_begin_date.
|
|
+ $end_date = clone $next_begin_date;
|
|
+ $end_date->sub(new \DateInterval('P1D'));
|
|
+ }
|
|
+ else
|
|
+ {
|
|
+ $dext = new \DateInterval('P' . $this->_type->extension . 'M');
|
|
+ $end_date = $begin_date->add($dext);
|
|
+ $end_date->sub(new \DateInterval('P1D')); //-1 day
|
|
+ }
|
|
$this->_end_date = $end_date->format('Y-m-d');
|
|
} elseif ($preferences->pref_membership_ext != '') {
|
|
//case membership extension
|
|
@@ -568,7 +577,7 @@ class Contribution
|
|
'c.' . ContributionsTypes::PK . '=ct.' . ContributionsTypes::PK,
|
|
array()
|
|
)->where([Adherent::PK => $this->_member])
|
|
- ->where(array('cotis_extension' => new Expression('true')))
|
|
+ ->where->notEqualTo('cotis_extension', 0)
|
|
->where->nest->nest
|
|
->greaterThanOrEqualTo('date_debut_cotis', $this->_begin_date)
|
|
->lessThanOrEqualTo('date_debut_cotis', $this->_end_date)
|
|
@@ -869,9 +878,8 @@ class Contribution
|
|
array()
|
|
)->where(
|
|
[Adherent::PK => $member_id]
|
|
- )->where(
|
|
- array('cotis_extension' => new Expression('true'))
|
|
- );
|
|
+ )
|
|
+ ->where->notEqualTo('cotis_extension', 0);
|
|
|
|
$results = $zdb->execute($select);
|
|
$result = $results->current();
|
|
@@ -1484,10 +1492,10 @@ class Contribution
|
|
//set type
|
|
$this->_type = new ContributionsTypes($this->zdb, $type);
|
|
//set is_cotis according to type
|
|
- if ($this->_type->extension == 1) {
|
|
- $this->_is_cotis = true;
|
|
- } else {
|
|
+ if ($this->_type->extension == 0) {
|
|
$this->_is_cotis = false;
|
|
+ } else {
|
|
+ $this->_is_cotis = true;
|
|
}
|
|
} else {
|
|
Analog::log(
|
|
diff --git a/galette/lib/Galette/Entity/ContributionsTypes.php b/galette/lib/Galette/Entity/ContributionsTypes.php
|
|
index a3d87207..3153468d 100644
|
|
--- a/galette/lib/Galette/Entity/ContributionsTypes.php
|
|
+++ b/galette/lib/Galette/Entity/ContributionsTypes.php
|
|
@@ -37,7 +37,7 @@ use Throwable;
|
|
* @property string $label
|
|
* @property string $libelle
|
|
* @property ?float $amount
|
|
- * @property boolean $extension
|
|
+ * @property int $extension
|
|
*/
|
|
|
|
class ContributionsTypes
|
|
@@ -53,7 +53,7 @@ class ContributionsTypes
|
|
private int $id;
|
|
private string $label;
|
|
private ?float $amount;
|
|
- private bool $is_extension = false;
|
|
+ private int $extension = -1;
|
|
|
|
public const ID_NOT_EXITS = -1;
|
|
|
|
@@ -136,7 +136,7 @@ class ContributionsTypes
|
|
$this->id = $r->{self::PK};
|
|
$this->label = $r->libelle_type_cotis;
|
|
$this->amount = $r->amount;
|
|
- $this->is_extension = (bool)$r->cotis_extension;
|
|
+ $this->extension = (int)$r->cotis_extension;
|
|
}
|
|
|
|
/**
|
|
@@ -234,9 +234,9 @@ class ContributionsTypes
|
|
$select->order(self::PK);
|
|
|
|
if ($extent === true) {
|
|
- $select->where(array('cotis_extension' => new Expression('true')));
|
|
+ $select->where->notEqualTo('cotis_extension', 0);
|
|
} elseif ($extent === false) {
|
|
- $select->where(array('cotis_extension' => new Expression('false')));
|
|
+ $select->where->equalTo('cotis_extension', 0);
|
|
}
|
|
|
|
$results = $this->zdb->execute($select);
|
|
@@ -383,11 +383,11 @@ class ContributionsTypes
|
|
*
|
|
* @param string $label The label
|
|
* @param ?float $amount The amount
|
|
- * @param boolean $extension Extends membership?
|
|
+ * @param int $extension Extends membership in months (or -1 by default)?
|
|
*
|
|
* @return bool|integer -2 : label already exists
|
|
*/
|
|
- public function add(string $label, ?float $amount, bool $extension): bool|int
|
|
+ public function add(string $label, ?float $amount, int $extension): bool|int
|
|
{
|
|
// Avoid duplicates.
|
|
$label = strip_tags($label);
|
|
@@ -406,7 +406,7 @@ class ContributionsTypes
|
|
$values = array(
|
|
'libelle_type_cotis' => $label,
|
|
'amount' => $amount ?? new Expression('NULL'),
|
|
- 'cotis_extension' => $extension ? true : ($this->zdb->isPostgres() ? 'false' : 0)
|
|
+ 'cotis_extension' => $extension //? true : ($this->zdb->isPostgres() ? 'false' : 0)
|
|
);
|
|
|
|
$insert = $this->zdb->insert(self::TABLE);
|
|
@@ -446,11 +446,11 @@ class ContributionsTypes
|
|
* @param integer $id Entry ID
|
|
* @param string $label The label
|
|
* @param ?float $amount The amount
|
|
- * @param boolean $extension Extends membership?
|
|
+ * @param int $extension Extends membership?
|
|
*
|
|
* @return self::ID_NOT_EXITS|boolean
|
|
*/
|
|
- public function update(int $id, string $label, ?float $amount, bool $extension): int|bool
|
|
+ public function update(int $id, string $label, ?float $amount, int $extension): int|bool
|
|
{
|
|
$label = strip_tags($label);
|
|
$ret = $this->get($id);
|
|
@@ -465,7 +465,7 @@ class ContributionsTypes
|
|
$values = array(
|
|
'libelle_type_cotis' => $label,
|
|
'amount' => $amount ?? new Expression('NULL'),
|
|
- 'cotis_extension' => $extension ? true : ($this->zdb->isPostgres() ? 'false' : 0)
|
|
+ 'cotis_extension' => $extension //? true : ($this->zdb->isPostgres() ? 'false' : 0)
|
|
);
|
|
|
|
$update = $this->zdb->update(self::TABLE);
|
|
@@ -584,7 +584,7 @@ class ContributionsTypes
|
|
public function __get(string $name)
|
|
{
|
|
$forbidden = array();
|
|
- $virtuals = array('extension', 'libelle');
|
|
+ $virtuals = array('extension', 'isextension', 'libelle');
|
|
if (
|
|
in_array($name, $virtuals)
|
|
|| !in_array($name, $forbidden)
|
|
@@ -593,7 +593,7 @@ class ContributionsTypes
|
|
switch ($name) {
|
|
case 'libelle':
|
|
return _T($this->label);
|
|
- case 'extension':
|
|
+ case 'isextension':
|
|
return $this->isExtension();
|
|
default:
|
|
return $this->$name;
|
|
diff --git a/galette/lib/Galette/Entity/Transaction.php b/galette/lib/Galette/Entity/Transaction.php
|
|
index 9e3bef9c..c43aa540 100644
|
|
--- a/galette/lib/Galette/Entity/Transaction.php
|
|
+++ b/galette/lib/Galette/Entity/Transaction.php
|
|
@@ -56,8 +56,8 @@ class Transaction
|
|
private string $_date;
|
|
private float $_amount;
|
|
private ?string $_description = null;
|
|
- private int $_member;
|
|
- private ?int $_payment_type;
|
|
+ private ?int $_member = null;
|
|
+ private ?int $_payment_type = null;
|
|
|
|
/**
|
|
* fields list and their translation
|
|
diff --git a/galette/templates/default/components/forms/input.html.twig b/galette/templates/default/components/forms/input.html.twig
|
|
index 01e139f2..386fed2b 100644
|
|
--- a/galette/templates/default/components/forms/input.html.twig
|
|
+++ b/galette/templates/default/components/forms/input.html.twig
|
|
@@ -30,6 +30,7 @@
|
|
<div class="ui toggle{% if checked is defined and checked == true %} checked{% endif %} right aligned checkbox">
|
|
{% else %}
|
|
{% block label %}
|
|
+ {% if label is defined %}
|
|
<label for="{{ id }}"{% if title is defined %} title="{{ title }}"{% endif %}{% if labelclass is defined %} class="{% if labelclass is defined %}{{ labelclass }}{% endif %}"{% endif %}>
|
|
{% if masschange ?? false %}
|
|
{# Add a checkbox for fields to change on mass edition #}
|
|
@@ -37,6 +38,7 @@
|
|
{% endif %}
|
|
{{ label }}
|
|
</label>
|
|
+ {% endif %}
|
|
{% endblock %}
|
|
{% endif %}
|
|
{% if type is defined and type == 'password' %}
|
|
diff --git a/galette/templates/default/pages/contribution_type_form.html.twig b/galette/templates/default/pages/contribution_type_form.html.twig
|
|
index 538cfacb..ea99bc8d 100644
|
|
--- a/galette/templates/default/pages/contribution_type_form.html.twig
|
|
+++ b/galette/templates/default/pages/contribution_type_form.html.twig
|
|
@@ -33,11 +33,17 @@
|
|
<label for="amount">{{ _T("Amount:") }}</label>
|
|
<input type="text" name="amount" id="amount" value="{{ entry.amount }}"/>
|
|
</div>
|
|
- <div class="ui toggle checkbox">
|
|
- <input type="checkbox" name="cotis_extension" id="cotis_extension" value="1"{% if entry.cotis_extension == 1 %} checked="checked"{% endif %} />
|
|
- <label for="cotis_extension">
|
|
- {{ _T("Extends membership?") }}
|
|
- </label>
|
|
+ <div class="field inline">
|
|
+ {% set cotisextensions = { (0) : _T("No"), (-1) : _T("By default"), (1) : '1 ' ~ _T("month")} %}
|
|
+ {% for m in 2..11 %} {% set cotisextensions = cotisextensions + { (m) : (m ~' ' ~ _T("months") ) } %} {% endfor %}
|
|
+ {% include "components/forms/select.html.twig" with {
|
|
+ id: 'cotis_extension',
|
|
+ value: entry.cotis_extension,
|
|
+ values: cotisextensions,
|
|
+ required: false,
|
|
+ label : _T("Extends membership?"),
|
|
+ tip: ''
|
|
+ } %}
|
|
</div>
|
|
</div>
|
|
|
|
diff --git a/galette/templates/default/pages/contributions_types_list.html.twig b/galette/templates/default/pages/contributions_types_list.html.twig
|
|
index 6d8bb096..4703b2e7 100644
|
|
--- a/galette/templates/default/pages/contributions_types_list.html.twig
|
|
+++ b/galette/templates/default/pages/contributions_types_list.html.twig
|
|
@@ -53,10 +53,15 @@
|
|
</div>
|
|
</td>
|
|
<td class="left" data-col-label="{{ _T("Extends membership?") }}">
|
|
- <select name="cotis_extension" class="ui dropdown">
|
|
- <option value="0" selected="selected">{{ _T("No") }}</option>
|
|
- <option value="1">{{ _T("Yes") }}</option>
|
|
- </select>
|
|
+ {% set cotisextensions = { (0) : _T("No"), (-1) : _T("By default"), (1) : '1 ' ~ _T("month")} %}
|
|
+ {% for m in 2..11 %} {% set cotisextensions = cotisextensions + { (m) : (m ~' ' ~ _T("months") ) } %} {% endfor %}
|
|
+ {% include "components/forms/select.html.twig" with {
|
|
+ id: 'cotis_extension',
|
|
+ value: 0,
|
|
+ values: cotisextensions,
|
|
+ required: false,
|
|
+ tip: ''
|
|
+ } %}
|
|
</td>
|
|
<td class="center actions_row">
|
|
<input type="hidden" name="new" value="1" />
|
|
@@ -85,10 +90,14 @@
|
|
{{ entry.amount }}
|
|
</td>
|
|
<td data-col-label="{{ _T("Extends membership?") }}">
|
|
- {% if entry.extra == 1 %}
|
|
- {{ _T("Yes") }}
|
|
- {% else %}
|
|
+ {% if entry.extra == -1 %}
|
|
+ {{ _T("By default") }}
|
|
+ {% elseif entry.extra == 0 %}
|
|
{{ _T("No") }}
|
|
+ {% elseif entry.extra == 1 %}
|
|
+ 1 {{ _T("month") }}
|
|
+ {% else %}
|
|
+ {{ entry.extra }} {{ _T("months") }}
|
|
{% endif %}
|
|
</td>
|
|
<td class="center actions_row">
|