]> git.agnieray.net Git - galette.git/commitdiff
Reload fee dates after member or type change; fixes #1115
authorJohan Cwiklinski <johan@x-tnd.be>
Mon, 27 Nov 2017 05:26:44 +0000 (06:26 +0100)
committerJohan Cwiklinski <johan@x-tnd.be>
Mon, 27 Nov 2017 05:26:44 +0000 (06:26 +0100)
Add a button when javascript is disabled aswell

galette/includes/dependencies.php
galette/includes/routes/ajax.routes.php
galette/includes/routes/contributions.routes.php
galette/templates/default/ajouter_contribution.tpl

index db83fbbb8104bf24a9a9f3746d8af0c9087bb45b..804091a6b4ee5c1a82434ef250cd4576f48800f7 100644 (file)
@@ -281,6 +281,7 @@ $container['acls'] = function ($c) {
         'transaction'       => 'staff',
         'doEditTransaction' => 'staff',
         'contribution'      => 'staff',
+        'contributionDates' => 'staff',
         'attendance_sheet_details'  => 'groupmanager',
         'attendance_sheet'  => 'groupmanager',
         'entitleds'         => 'staff',
index da68a8d00813cdd042d1454b2cd64a96b1c53f6b..cd27e1c6df1da66c0bce9dc7a7104c157a8e328b 100644 (file)
@@ -36,6 +36,8 @@
  */
 
 use Galette\Entity\Adherent;
+use Galette\Entity\Contribution;
+use Galette\Entity\ContributionsTypes;
 
 $app->group(__('/ajax', 'routes'), function () use ($authenticate) {
     $this->get(
@@ -234,4 +236,30 @@ $app->group(__('/ajax', 'routes'), function () use ($authenticate) {
             return $response->withJson(['message' => _T('Thank you for registering!')]);
         }
     )->setName('setRegistered')->add($authenticate);
+
+    $this->post(
+        __('/contribution', 'routes') . __('/dates', 'routes'),
+        function ($request, $response) {
+            $post = $request->getParsedBody();
+
+            // contribution types
+            $ct = new ContributionsTypes($this->zdb);
+            $contributions_types = $ct->getList(true);
+
+            $contrib = new Contribution(
+                $this->zdb,
+                $this->login,
+                [
+                    'type'  => __(array_keys($contributions_types)[$post['fee_id']], 'routes'),
+                    'adh'   => (int)$post['member_id']
+                ]
+            );
+            $contribution['duree_mois_cotis'] = $this->preferences->pref_membership_ext;
+
+            return $response->withJson([
+                'date_debut_cotis'  => $contrib->begin_date,
+                'date_fin_cotis'    => $contrib->end_date
+            ]);
+        }
+    )->setName('contributionDates')->add($authenticate);
 });
index 32f8131206f509e4d79b6a8b47c6908c843cd395..9ec651ddda16624712de3fa6b0932a6b921cdc68 100644 (file)
@@ -312,6 +312,13 @@ $app->get(
                         ));
                 }
             } else {
+                $id_type_cotis = 0;
+                if (isset($get[ContributionsTypes::PK])
+                    && $get[ContributionsTypes::PK]
+                    && $action === __('add', 'routes')
+                ) {
+                    $id_type_cotis = $get[ContributionsTypes::PK];
+                }
                 $cparams = ['type' => __(array_keys($contributions_types)[0], 'routes')];
 
                 //member id
@@ -333,6 +340,10 @@ $app->get(
                     (count($cparams) > 0 ? $cparams : null)
                 );
 
+                if (isset($get['montant_cotis']) && $get['montant_cotis'] > 0 && $action === __('add', 'routes')) {
+                    $contrib->amount = $get['montant_cotis'];
+                }
+
                 if ($contrib->isTransactionPart()) {
                     $id_adh = $contrib->member;
 
@@ -448,6 +459,17 @@ $app->post(
         __('add', 'routes') . '|' . __('edit', 'routes') .'}[/{id:\d+}]',
     function ($request, $response, $args) {
         $post = $request->getParsedBody();
+
+        if (isset($post['btnreload'])) {
+            $reditect_url = $this->router->pathFor('contribution', $args);
+            $reditect_url .= '?' . Adherent::PK . '=' . $post[Adherent::PK] . '&' .
+                ContributionsTypes::PK . '=' . $post[ContributionsTypes::PK] . '&' .
+                'montant_cotis=' . $post['montant_cotis'];
+            return $response
+                ->withStatus(301)
+                ->withHeader('Location', $reditect_url);
+        }
+
         $error_detected = [];
         $warning_detected = [];
         $reditect_url = null;
index 186a68863aa55ae44dd411fd9c4f9856faa26c6a..05bb7ebd2a2ed87cbf803e9e0da4e7a11d9fdbf9 100644 (file)
                         {html_options options=$type_cotis_options selected=$selectedid}
                     </select>
                 </p>
+    {if $type eq {_T string="fee" domain="routes"}}
+                <noscript>
+                    <div class="button-container" id="reloadcont">
+                        <input type="submit" id="btnreload" name="btnreload" value="{_T string="Reload"}" title="{_T string="Reload date informations according to selected member and contribution type"}"/>
+                    </div>
+                </noscript>
+    {/if}
             </fieldset>
 
             <fieldset class="cssform">
         </form>
     <script type="text/javascript">
         $(function(){
-            $.datepicker.setDefaults($.datepicker.regional['{$galette_lang}']);
-            $('#date_debut_cotis, #date_fin_cotis, #date_enreg').datepicker({
-                changeMonth: true,
-                changeYear: true,
-                showOn: 'button',
-                buttonImage: '{base_url}/{$template_subdir}images/calendar.png',
-                buttonImageOnly: true,
-                buttonText: '{_T string="Select a date" escape="js"}'
-            });
         });
     </script>
 {else} {* No members *}
     </div>
 {/if}
 {/block}
+
+{block name="javascripts"}
+<script type="text/javascript">
+    $(function() {
+        $.datepicker.setDefaults($.datepicker.regional['{$galette_lang}']);
+        $('#date_debut_cotis, #date_fin_cotis, #date_enreg').datepicker({
+            changeMonth: true,
+            changeYear: true,
+            showOn: 'button',
+            buttonImage: '{base_url}/{$template_subdir}images/calendar.png',
+            buttonImageOnly: true,
+            buttonText: '{_T string="Select a date" escape="js"}'
+        });
+
+    {if $type eq {_T string="fee" domain="routes"} and !$contribution->id}
+        $('#id_adh, #id_type_cotis').on('change', function() {
+            var _this = $(this);
+            var _member = $('#id_adh').val();
+            var _fee    = $('#id_type_cotis').val();
+
+            $.ajax({
+                type: 'POST',
+                dataType: 'json',
+                url : '{path_for name="contributionDates"}',
+                data: {
+                    member_id: _member,
+                    fee_id: _fee
+                },
+                {include file="js_loader.tpl"},
+                success: function(res){
+                    $('#date_debut_cotis').val(res.date_debut_cotis);
+                    $('#date_fin_cotis').val(res.date_fin_cotis);
+                },
+                error: function() {
+                    alert("{_T string="An error occured retrieving dates :(" escape="js"}");
+                }
+            });
+
+        });
+    {/if}
+    });
+</script>
+{/block}