]> git.agnieray.net Git - galette.git/commitdiff
Fix next contribution start date overalpping by one year
authorJohan Cwiklinski <johan@x-tnd.be>
Sat, 30 Dec 2023 05:44:34 +0000 (06:44 +0100)
committerJohan Cwiklinski <johan@x-tnd.be>
Fri, 12 Jan 2024 15:03:32 +0000 (16:03 +0100)
fixes #1762

Add test on contribution next year begin date; from Galette, and from
previous version

galette/lib/Galette/Entity/Contribution.php
tests/Galette/Entity/tests/units/Contribution.php

index bf933ffb7a3d490f5c6e617f8b854ea6a7849e4a..f8cc8bd0db1e93ca8cf37ee7a0a2e1a896b65759 100644 (file)
@@ -603,10 +603,17 @@ class Contribution
             $results = $this->zdb->execute($select);
             if ($results->count() > 0) {
                 $result = $results->current();
-                $d = new \DateTime($result->date_debut_cotis);
+
+                $d_begin = new \DateTime($result->date_debut_cotis);
+                $d_end = new \DateTime($result->date_fin_cotis);
+
+                if ($d_begin->format('m-d') == $d_end->format('m-d') && $result->date_fin_cotis == $this->_begin_date) {
+                    //see https://bugs.galette.eu/issues/1762
+                    return true;
+                }
 
                 return _T("- Membership period overlaps period starting at ") .
-                    $d->format(__("Y-m-d"));
+                    $d_begin->format(__("Y-m-d"));
             }
             return true;
         } catch (Throwable $e) {
index 0e5a1a85c72681d2e08d0f84ca5602a94edb9469..ee63d59c94913962d20aa88d50f4f198599bb3a7 100644 (file)
@@ -739,4 +739,102 @@ class Contribution extends GaletteTestCase
         $this->login->logOut();
         $this->assertFalse($this->login->isLogged());
     }
+
+    /**
+     * Test next year contribution
+     *
+     * @return void
+     */
+    public function testNextYear()
+    {
+        $this->logSuperAdmin();
+        $this->getMemberOne();
+
+        //create contribution for member
+        $begin_date = new \DateTime(); // 2023-12-30
+        $ny_begin_date = clone $begin_date; // 2023-12-30
+        $end_date = clone $begin_date;
+        $begin_date->sub(new \DateInterval('P1Y')); // 2022-12-30
+        $end_date->sub(new \DateInterval('P1D')); // 2023-12-29
+
+        $data = [
+            'id_adh' => $this->adh->id,
+            'id_type_cotis' => 1, //contribution
+            'montant_cotis' => 100,
+            'type_paiement_cotis' => 3,
+            'info_cotis' => 'FAKER' . $this->seed,
+            'date_enreg' => $begin_date->format('Y-m-d'),
+            'date_debut_cotis' => $begin_date->format('Y-m-d'),
+            'duree_mois_cotis' => 12
+        ];
+        $this->createContrib($data);
+
+        $contrib = new \Galette\Entity\Contribution($this->zdb, $this->login, $this->contrib->id);
+        $this->assertSame(100.00, $contrib->amount);
+        $this->assertSame($end_date->format('Y-m-d'), $contrib->end_date);
+
+        $contrib = new \Galette\Entity\Contribution($this->zdb, $this->login, ['type' => 1, 'adh' => $this->adh->id]);
+        $this->assertSame($ny_begin_date->format('Y-m-d'), $contrib->begin_date);
+    }
+
+    /**
+     * Test next year contribution from a 0.9.x
+     *
+     * @return void
+     */
+    public function testNextYearFrom096()
+    {
+        $this->logSuperAdmin();
+        $this->getMemberOne();
+
+        //create contribution for member
+        $begin_date = new \DateTime(); // 2023-12-30
+        $ny_begin_date = clone $begin_date; // 2023-12-30
+        $end_date = clone $begin_date;
+        $due_date = clone $begin_date;
+
+        $begin_date->sub(new \DateInterval('P1Y')); // 2022-12-30
+
+        $contrib = new \Galette\Entity\Contribution($this->zdb, $this->login);
+        $insert = $this->zdb->insert(\Galette\Entity\Contribution::TABLE);
+        $insert->values(
+            [
+                'id_adh' => $this->adh->id,
+                'id_type_cotis' => 1, //contribution
+                'montant_cotis' => 100,
+                'type_paiement_cotis' => 3,
+                'info_cotis' => 'FAKER' . $this->seed,
+                'date_enreg' => $begin_date->format('Y-m-d'),
+                'date_debut_cotis' => $begin_date->format('Y-m-d'),
+                'date_fin_cotis' => $due_date->format('Y-m-d')
+            ]
+        );
+        $add = $this->zdb->execute($insert);
+        $this->assertSame(1, $add->count());
+        $contribution_id = (int)($add->getGeneratedValue() ?? $this->zdb->getLastGeneratedValue($contrib));
+
+        $update = $this->zdb->update(\Galette\Entity\Adherent::TABLE);
+        $update->set(
+            array('date_echeance' => $due_date->format('Y-m-d'))
+        )->where(
+            [\Galette\Entity\Adherent::PK => $this->adh->id]
+        );
+        $this->zdb->execute($update);
+
+        $contrib = new \Galette\Entity\Contribution($this->zdb, $this->login, $contribution_id);
+        $this->assertSame(100.00, $contrib->amount);
+        $this->assertSame($end_date->format('Y-m-d'), $contrib->end_date);
+
+        $contrib = new \Galette\Entity\Contribution($this->zdb, $this->login, ['type' => 1, 'adh' => $this->adh->id, 'payment_type' => 1]);
+        $this->assertSame($ny_begin_date->format('Y-m-d'), $contrib->begin_date);
+
+        $check = $contrib->check(['type_paiement_cotis' => 1, 'info_cotis' => 'FAKER' . $this->seed], [], []);
+        if (is_array($check)) {
+            var_dump($check);
+        }
+        $this->assertTrue($check);
+
+        $store = $contrib->store();
+        $this->assertTrue($store);
+    }
 }