3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
6 * Contributions related routes
10 * Copyright © 2014-2016 The Galette Team
12 * This file is part of Galette (http://galette.tuxfamily.org).
14 * Galette is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation, either version 3 of the License, or
17 * (at your option) any later version.
19 * Galette is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with Galette. If not, see <http://www.gnu.org/licenses/>.
30 * @author Johan Cwiklinski <johan@x-tnd.be>
31 * @copyright 2014-2016 The Galette Team
32 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
34 * @link http://galette.tuxfamily.org
35 * @since 0.8.2dev 2014-11-27
38 use Galette\Entity\Contribution
;
39 use Galette\Repository\Contributions
;
40 use Galette\Entity\Transaction
;
41 use Galette\Repository\Transactions
;
42 use Galette\Repository\Members
;
43 use Galette\Entity\Adherent
;
44 use Galette\Entity\ContributionsTypes
;
45 use Galette\Core\GaletteMail
;
46 use Galette\Entity\Texts
;
47 use Galette\IO\PdfContribution
;
48 use Galette\Repository\PaymentTypes
;
51 '/{type:transactions|contributions}[/{option:page|order|member}/{value:\d+|all}]',
52 function ($request, $response, $args) {
55 ||
isset($request->getQueryParams()['ajax'])
56 && $request->getQueryParams()['ajax'] == 'true'
60 $get = $request->getQueryParams();
63 if (isset($args['option'])) {
64 $option = $args['option'];
67 if (isset($args['value'])) {
68 $value = $args['value'];
72 switch ($args['type']) {
74 $raw_type = 'transactions';
77 $raw_type = 'contributions';
81 $filter_name = 'filter_' . $raw_type;
83 if (isset($this->session
->$filter_name) && $ajax === false) {
84 $filters = $this->session
->$filter_name;
86 $filter_class = '\\Galette\\Filters\\' . ucwords($raw_type . 'List');
87 $filters = new $filter_class();
92 if (isset($get[Adherent
::PK
]) && $get[Adherent
::PK
] > 0) {
93 $id_adh = (int)$get[Adherent
::PK
];
94 $filters->filtre_cotis_adh
= $id_adh;
98 if (isset($request->getQueryParams()['max_amount'])) {
99 $filters->filtre_transactions
= true;
100 $filters->max_amount
= (int)$request->getQueryParams()['max_amount'];
102 $filters->filtre_transactions
= false;
103 $filters->max_amount
= null;
106 if ($option !== null) {
109 $filters->current_page
= (int)$value;
112 $filters->orderby
= $value;
115 if (($this->login
->isAdmin()
116 ||
$this->login
->isStaff())
118 if ($value == 'all') {
119 $filters->filtre_cotis_adh
= null;
121 $filters->filtre_cotis_adh
= $value;
128 if (!$this->login
->isAdmin() && !$this->login
->isStaff()) {
129 $filters->filtre_cotis_adh
= $this->login
->id
;
132 $class = '\\Galette\\Repository\\' . ucwords($raw_type);
133 $contrib = new $class($this->zdb
, $this->login
, $filters);
134 $contribs_list = $contrib->getList(true);
136 //store filters into session
137 if ($ajax === false) {
138 $this->session
->$filter_name = $filters;
141 //assign pagination variables to the template and add pagination links
142 $filters->setSmartyPagination($this->router
, $this->view
->getSmarty());
145 'page_title' => $raw_type === 'contributions' ?
146 _T("Contributions management") :
147 _T("Transactions management"),
148 'require_dialog' => true,
149 'require_calendar' => true,
150 'contribs' => $contrib,
151 'list' => $contribs_list,
152 'nb' => $contrib->getCount(),
153 'filters' => $filters,
154 'mode' => ($ajax === true ?
'ajax' : 'std')
157 if ($filters->filtre_cotis_adh
!= null) {
158 $member = new Adherent($this->zdb
);
159 $member->load($filters->filtre_cotis_adh
);
160 $tpl_vars['member'] = $member;
166 'gestion_' . $raw_type . '.tpl',
171 )->setName('contributions')->add($authenticate);
174 '/{type:contributions|transactions}/filter',
175 function ($request, $response, $args) {
177 switch ($args['type']) {
179 $raw_type = 'transactions';
181 case 'contributions':
182 $raw_type = 'contributions';
186 $type = 'filter_' . $raw_type;
187 $post = $request->getParsedBody();
188 $error_detected = [];
190 if ($this->session
->$type !== null) {
191 $filters = $this->session
->$type;
193 $filter_class = '\\Galette\\Filters\\' . ucwords($raw_type) . 'List';
194 $filters = new $filter_class();
197 if (isset($post['clear_filter'])) {
200 if (isset($post['max_amount'])) {
201 $filters->max_amount
= null;
204 if ((isset($post['nbshow']) && is_numeric($post['nbshow']))
206 $filters->show
= $post['nbshow'];
209 if (isset($post['end_date_filter']) ||
isset($post['start_date_filter'])) {
211 if (isset($post['start_date_filter'])) {
212 $field = _T("start date filter");
213 $filters->start_date_filter
= $post['start_date_filter'];
215 if (isset($post['end_date_filter'])) {
216 $field = _T("end date filter");
217 $filters->end_date_filter
= $post['end_date_filter'];
219 } catch (Exception
$e) {
220 $error_detected[] = $e->getMessage();
224 if (isset($post['payment_type_filter'])) {
225 $ptf = (int)$post['payment_type_filter'];
226 $ptypes = new PaymentTypes(
231 $ptlist = $ptypes->getList();
232 if (isset($ptlist[$ptf])) {
233 $filters->payment_type_filter
= $ptf;
234 } elseif ($ptf == -1) {
235 $filters->payment_type_filter
= null;
237 $error_detected[] = _T("- Unknown payment type!");
242 $this->session
->$type = $filters;
244 if (count($error_detected) > 0) {
246 foreach ($error_detected as $error) {
247 $this->flash
->addMessage(
256 ->withHeader('Location', $this->router
->pathFor('contributions', ['type' => $raw_type]));
260 )->add($authenticate);
263 '/contribution/{type:fee|donation}/{action:add|edit}[/{id:\d+}]',
264 function ($request, $response, $args) {
265 $action = $args['action'];
266 $get = $request->getQueryParams();
269 if (isset($args['id'])) {
270 $id_cotis = $args['id'];
273 if ($action === 'edit' && $id_cotis === null) {
274 throw new \
RuntimeException(
275 _T("Contribution ID cannot ben null calling edit route!")
277 } elseif ($action === 'add' && $id_cotis !== null) {
282 $this->router
->pathFor(
285 'type' => $args['type'],
292 // contribution types
293 $ct = new ContributionsTypes($this->zdb
);
294 $contributions_types = $ct->getList($args['type'] === 'fee');
296 if ($this->session
->contribution
!== null) {
297 $contrib = $this->session
->contribution
;
298 $this->session
->contribution
= null;
300 if ($args['action'] === 'edit') {
301 $contrib = new Contribution($this->zdb
, $this->login
, (int)$id_cotis);
302 $id_adh = $contrib->member
;
303 if ($contrib->id
== '') {
304 //not possible to load contribution, exit
305 $this->flash
->addMessage(
310 _T("Unable to load contribution #%id!")
315 ->withHeader('Location', $this->router
->pathFor(
317 ['type' => 'contributions']
322 if (isset($get[ContributionsTypes
::PK
])
323 && $get[ContributionsTypes
::PK
]
326 $id_type_cotis = $get[ContributionsTypes
::PK
];
328 $cparams = ['type' => array_keys($contributions_types)[0]];
332 if (isset($get[Adherent
::PK
]) && $get[Adherent
::PK
] > 0 && $action === 'add') {
333 $id_adh = (int)$get[Adherent
::PK
];
334 $cparams['adh'] = $id_adh;
339 if (isset($get[Transaction
::PK
]) && $get[Transaction
::PK
] > 0) {
340 $cparams['trans'] = $get[Transaction
::PK
];
343 $contrib = new Contribution(
346 (count($cparams) > 0 ?
$cparams : null)
349 if (isset($get['montant_cotis']) && $get['montant_cotis'] > 0 && $action === 'add') {
350 $contrib->amount
= $get['montant_cotis'];
353 if ($contrib->isTransactionPart()) {
354 $id_adh = $contrib->member
;
361 if (!is_int($contrib->id
)) {
362 // initialiser la structure contribution à vide (nouvelle contribution)
363 $contribution['duree_mois_cotis'] = $this->preferences
->pref_membership_ext
;
366 // template variable declaration
368 if ($args['type'] === 'fee') {
369 $title = _T("Membership fee");
371 $title = _T("Donation");
374 if ($contrib->id
!= '') {
375 $title .= ' (' . _T("modification") . ')';
377 $title .= ' (' . _T("creation") . ')';
382 'id_type_cotis' => 1,
385 'date_debut_cotis' => 1,
386 'date_fin_cotis' => $contrib->isCotis(),
387 'montant_cotis' => $contrib->isCotis() ?
1 : 0
391 'page_title' => $title,
392 'required' => $required,
393 'disabled' => $disabled,
394 'contribution' => $contrib,
395 'adh_selected' => $id_adh,
396 'require_calendar' => true,
397 'type' => $args['type']
400 // contribution types
401 $params['type_cotis_options'] = $contributions_types;
406 $required_fields = array(
411 $list_members = $m->getList(false, $required_fields, true);
413 if (count($list_members) > 0) {
414 foreach ($list_members as $member) {
416 $sname = mb_strtoupper($member->nom_adh
, 'UTF-8') .
417 ' ' . ucwords(mb_strtolower($member->prenom_adh
, 'UTF-8')) .
418 ' (' . $member->id_adh
. ')';
419 $members[$member->$pk] = $sname;
423 $params['members'] = [
424 'filters' => $m->getFilters(),
425 'count' => $m->getCount()
428 //check if current attached member is part of the list
430 && $contrib->member
> 0
431 && !isset($members[$contrib->member
])
433 $members[$contrib->member
] = Adherent
::getSName($this->zdb
, $contrib->member
, true);
436 if (count($members)) {
437 $params['members']['list'] = $members;
440 $ext_membership = '';
441 if (isset($contrib) && $contrib->isCotis() ||
!isset($contrib) && $args['type'] === 'fee') {
442 $ext_membership = $this->preferences
->pref_membership_ext
;
444 $params['pref_membership_ext'] = $ext_membership;
445 $params['autocomplete'] = true;
450 'ajouter_contribution.tpl',
455 )->setName('contribution')->add($authenticate);
458 '/contribution/{type:fee|donation}/{action:add|edit}[/{id:\d+}]',
459 function ($request, $response, $args) {
460 $post = $request->getParsedBody();
462 if (isset($post['btnreload'])) {
463 $redirect_url = $this->router
->pathFor('contribution', $args);
464 $redirect_url .= '?' . Adherent
::PK
. '=' . $post[Adherent
::PK
] . '&' .
465 ContributionsTypes
::PK
. '=' . $post[ContributionsTypes
::PK
] . '&' .
466 'montant_cotis=' . $post['montant_cotis'];
469 ->withHeader('Location', $redirect_url);
472 $error_detected = [];
473 $warning_detected = [];
474 $redirect_url = null;
476 $action = $args['action'];
478 if (isset($args['id'])) {
479 $id_cotis = $args['id'];
482 $id_adh = $post['id_adh'];
484 if ($action === 'edit' && $id_cotis === null) {
485 throw new \
RuntimeException(
486 _T("Contribution ID cannot ben null calling edit route!")
488 } elseif ($action === 'add' && $id_cotis !== null) {
489 throw new \
RuntimeException(
490 _T("Contribution ID must be null calling add route!")
494 if ($this->session
->contribution
!== null) {
495 $contrib = $this->session
->contribution
;
496 $this->session
->contribution
= null;
498 if ($id_cotis === null) {
499 $contrib = new Contribution($this->zdb
, $this->login
);
501 $contrib = new Contribution($this->zdb
, $this->login
, (int)$id_cotis);
505 // flagging required fields for first step only
507 'id_type_cotis' => 1,
510 'montant_cotis' => 1, //TODO: not always required, see #196
511 'date_debut_cotis' => 1,
512 'date_fin_cotis' => ($args['type'] === 'fee')
517 $valid = $contrib->check($post, $required, $disabled);
518 if ($valid !== true) {
519 $error_detected = array_merge($error_detected, $valid);
522 if (count($error_detected) == 0) {
523 //all goes well, we can proceed
525 if ($contrib->id
== '') {
529 if (count($error_detected) == 0) {
530 $store = $contrib->store();
531 if ($store === true) {
532 //contribution has been stored :)
534 //if an external script has been configured, we call it
535 if ($this->preferences
->pref_new_contrib_script
) {
536 $es = new Galette\IO\
ExternalScript($this->preferences
);
537 $res = $contrib->executePostScript($es);
540 //send admin a mail with all details
541 if ($this->preferences
->pref_mail_method
> GaletteMail
::METHOD_DISABLED
) {
542 $mail = new GaletteMail($this->preferences
);
544 _T("Post contribution script failed")
548 foreach ($this->preferences
->vpref_email_newadh
as $pref_email) {
549 $recipients[$pref_email] = $pref_email;
551 $mail->setRecipients($recipients);
553 $message = _T("The configured post contribution script has failed.");
554 $message .= "\n" . _T("You can find contribution information and script output below.");
558 $mail->setMessage($message);
559 $sent = $mail->send();
563 array('/%name/', '/%email/'),
564 array($adh->sname
, $adh->getEmail()),
565 _T("A problem happened while sending to admin post contribution notification for user %name (%email) contribution")
567 $this->history
->add($txt);
568 $error_detected[] = $txt;
569 //Mails are disabled... We log (not safe, but)...
571 'Post contribution script has failed. Here was the data: ' .
572 "\n" . print_r($res, true),
577 //Mails are disabled... We log (not safe, but)...
579 'Post contribution script has failed. Here was the data: ' .
580 "\n" . print_r($res, true),
588 //something went wrong :'(
589 $error_detected[] = _T("An error occurred while storing the contribution.");
594 if (count($error_detected) == 0) {
595 // Get member informations
596 $adh = new Adherent($this->zdb
);
597 $adh->load($contrib->member
);
599 if ($this->preferences
->pref_mail_method
> GaletteMail
::METHOD_DISABLED
) {
605 'name_adh' => custom_html_entity_decode($adh->sname
),
606 'firstname_adh' => custom_html_entity_decode($adh->surname
),
607 'lastname_adh' => custom_html_entity_decode($adh->name
),
608 'mail_adh' => custom_html_entity_decode($adh->getEmail()),
609 'login_adh' => custom_html_entity_decode($adh->login
),
610 'deadline' => custom_html_entity_decode($contrib->end_date
),
611 'contrib_info' => custom_html_entity_decode($contrib->info
),
612 'contrib_amount' => custom_html_entity_decode($contrib->amount
),
613 'contrib_type' => custom_html_entity_decode($contrib->type
->libelle
)
616 if ($new && isset($_POST['mail_confirm'])
617 && $_POST['mail_confirm'] == '1'
619 if (GaletteMail
::isValidEmail($adh->getEmail())) {
621 if (!$contrib->isCotis()) {
624 $mtxt = $texts->getTexts($text, $adh->language
);
626 $mail = new GaletteMail($this->preferences
);
627 $mail->setSubject($texts->getSubject());
628 $mail->setRecipients(
630 $adh->getEmail() => $adh->sname
634 $mail->setMessage($texts->getBody());
635 $sent = $mail->send();
640 array('/%name/', '/%email/'),
641 array($adh->sname
, $adh->getEmail()),
642 _T("Mail sent to user %name (%email)")
647 array('/%name/', '/%email/'),
648 array($adh->sname
, $adh->getEmail()),
649 _T("A problem happened while sending contribution receipt to user %name (%email)")
651 $this->history
->add($txt);
652 $error_detected[] = $txt;
656 array('/%name/', '/%email/'),
657 array($adh->sname
, $adh->getEmail()),
658 _T("Trying to send a mail to a member (%name) with an invalid address: %email")
660 $this->history
->add($txt);
661 $warning_detected[] = $txt;
665 // Sent email to admin if pref checked
666 if ($new && $this->preferences
->pref_bool_mailadh
) {
667 // Get email text in database
669 if (!$contrib->isCotis()) {
670 $text = 'newdonation';
672 $mtxt = $texts->getTexts($text, $this->preferences
->pref_lang
);
674 $mail = new GaletteMail($this->preferences
);
675 $mail->setSubject($texts->getSubject());
678 foreach ($this->preferences
->vpref_email_newadh
as $pref_email) {
679 $recipients[$pref_email] = $pref_email;
681 $mail->setRecipients($recipients);
683 $mail->setMessage($texts->getBody());
684 $sent = $mail->send();
689 array('/%name/', '/%email/'),
690 array($adh->sname
, $adh->getEmail()),
691 _T("Mail sent to admin for user %name (%email)")
696 array('/%name/', '/%email/'),
697 array($adh->sname
, $adh->getEmail()),
698 _T("A problem happened while sending to admin notification for user %name (%email) contribution")
700 $this->history
->add($txt);
701 $error_detected[] = $txt;
706 if (count($warning_detected) > 0) {
707 foreach ($warning_detected as $warning) {
708 $this->flash
->addMessage(
715 if (count($error_detected) == 0) {
716 if ($contrib->isTransactionPart() && $contrib->transaction
->getMissingAmount() > 0) {
717 $redirect_url = $this->router
->pathFor(
721 'type' => $post['contrib_type']
723 ) . '?' . Transaction
::PK
. '=' . $contrib->transaction
->id
.
724 '&' . Adherent
::PK
. '=' . $contrib->member
;
726 $redirect_url = $this->router
->pathFor(
729 'type' => 'contributions'
731 ) . '?' . Adherent
::PK
. '=' . $contrib->member
;
737 if (!isset($contribution['duree_mois_cotis'])
738 ||
$contribution['duree_mois_cotis'] == ''
740 // On error restore entered value or default to display the form again
741 if (isset($_POST['duree_mois_cotis'])
742 && $_POST['duree_mois_cotis'] != ''
744 $contribution['duree_mois_cotis'] = $_POST['duree_mois_cotis'];
746 $contribution['duree_mois_cotis'] = $this->preferences
->pref_membership_ext
;
750 if (count($error_detected) > 0) {
751 //something went wrong.
752 //store entity in session
753 $this->session
->contribution
= $contrib;
754 $redirect_url = $this->router
->pathFor('contribution', $args);
757 foreach ($error_detected as $error) {
758 $this->flash
->addMessage(
764 $this->session
->contribution
= null;
765 if ($redirect_url === null) {
766 $redirect_url = $this->router
->pathFor('contributions', ['type' => $args['type']]);
770 //redirect to calling action
773 ->withHeader('Location', $redirect_url);
775 )->setName('contribution')->add($authenticate);
778 '/transaction/{action:add|edit}[/{id:\d+}]',
779 function ($request, $response, $args) {
782 if ($this->session
->transaction
!== null) {
783 $trans = $this->session
->transaction
;
784 $this->session
->transaction
= null;
786 $trans = new Transaction($this->zdb
, $this->login
);
789 $action = $args['action'];
791 if (isset($args['id'])) {
792 $trans_id = $args['id'];
795 if ($action === 'edit' && $trans_id === null) {
796 throw new \
RuntimeException(
797 _T("Transaction ID cannot ben null calling edit route!")
799 } elseif ($action === 'add' && $trans_id !== null) {
802 ->withHeader('Location', $this->router
->pathFor('transaction', ['action' => 'add']));
805 $transaction['trans_id'] = $trans_id;
806 $transaction['trans_amount'] = get_numeric_form_value("trans_amount", '');
807 $transaction['trans_date'] = get_form_value("trans_date", '');
808 $transaction['trans_desc'] = get_form_value("trans_desc", '');
809 $transaction['id_adh'] = get_numeric_form_value("id_adh", '');
811 // flagging required fields
820 if ($action === 'edit') {
821 // initialize transactions structure with database values
822 $trans->load($trans_id);
823 if ($trans->id
== '') {
824 //not possible to load transaction, exit
825 throw new \
RuntimeException('Transaction does not exists!');
829 // template variable declaration
830 $title = _T("Transaction");
831 if ($action === 'edit') {
832 $title .= ' (' . _T("modification") . ')';
834 $title .= ' (' . _T("creation") . ')';
838 'page_title' => $title,
839 'required' => $required,
840 'data' => $transaction, //TODO: remove
841 'transaction' => $trans,
842 'require_calendar' => true,
843 'require_dialog' => true
846 if ($trans->id
!= '') {
847 $contribs = new Contributions($this->zdb
, $this->login
);
848 $params['contribs'] = $contribs->getListFromTransaction($trans->id
);
854 $required_fields = array(
859 $list_members = $m->getList(false, $required_fields, true);
861 if (count($list_members) > 0) {
862 foreach ($list_members as $member) {
864 $sname = mb_strtoupper($member->nom_adh
, 'UTF-8') .
865 ' ' . ucwords(mb_strtolower($member->prenom_adh
, 'UTF-8')) .
866 ' (' . $member->id_adh
. ')';
867 $members[$member->$pk] = $sname;
871 $params['members'] = [
872 'filters' => $m->getFilters(),
873 'count' => $m->getCount()
875 $params['autocomplete'] = true;
877 //check if current attached member is part of the list
878 if (isset($trans) && $trans->member
> 0) {
879 if (!isset($members[$trans->member
])) {
881 [$trans->member
=> Adherent
::getSName($this->zdb
, $trans->member
, true)] +
887 if (count($members)) {
888 $params['members']['list'] = $members;
894 'ajouter_transaction.tpl',
899 )->setName('transaction')->add($authenticate);
902 '/transaction/{id}/attach/{cid}',
903 function ($request, $response, $args) {
904 if (!Contribution
::setTransactionPart($this->zdb
, $args['id'], $args['cid'])) {
905 $this->flash
->addMessage(
907 _T("Unable to attach contribution to transaction")
910 $this->flash
->addMessage(
912 _T("Contribution has been successfully attached to current transaction")
918 ->withHeader('Location', $this->router
->pathFor(
920 ['action' => 'edit', 'id' => $args['id']]
923 )->setName('attach_contribution')->add($authenticate);
926 '/transaction/{id}/detach/{cid}',
927 function ($request, $response, $args) {
928 if (!Contribution
::unsetTransactionPart($this->zdb
, $this->login
, $args['id'], $args['cid'])) {
929 $this->flash
->addMessage(
931 _T("Unable to detach contribution from transaction")
934 $this->flash
->addMessage(
936 _T("Contribution has been successfully detached from current transaction")
942 ->withHeader('Location', $this->router
->pathFor(
944 ['action' => 'edit', 'id' => $args['id']]
947 )->setName('detach_contribution')->add($authenticate);
950 '/transaction/{action:add|edit}[/{id:\d+}]',
951 function ($request, $response, $args) {
952 $post = $request->getParsedBody();
953 $trans = new Transaction($this->zdb
, $this->login
);
955 $action = $args['action'];
957 if (isset($args['id'])) {
958 $trans_id = $args['id'];
961 if ($action === 'edit' && $trans_id === null) {
962 throw new \
RuntimeException(
963 _T("Transaction ID cannot ben null calling edit route!")
965 } elseif ($action === 'add' && $trans_id !== null) {
966 throw new \
RuntimeException(
967 _T("Transaction ID cannot ben set while adding!")
971 $transaction['trans_id'] = $trans_id;
972 $transaction['trans_amount'] = $post['trans_amount'];
973 $transaction['trans_date'] = $post['trans_date'];
974 $transaction['trans_desc'] = $post['trans_desc'];
975 $transaction['id_adh'] = $post['id_adh'];
977 // flagging required fields
986 if ($action === 'edit') {
987 // initialize transactions structure with database values
988 $trans->load($trans_id);
989 if ($trans->id
== '') {
990 //not possible to load transaction, exit
991 throw new \
RuntimeException('Transaction does not exists!');
995 $error_detected = [];
997 $valid = $trans->check($_POST, $required, $disabled);
998 if ($valid !== true) {
999 $error_detected = array_merge($error_detected, $valid);
1002 if (count($error_detected) == 0) {
1003 //all goes well, we can proceed
1005 if ($trans->id
== '') {
1009 $store = $trans->store($this->history
);
1010 if ($store === true) {
1011 //transaction has been stored :)
1013 $transaction['trans_id'] = $trans->id
;
1016 //something went wrong :'(
1017 $error_detected[] = _T("An error occurred while storing the transaction.");
1021 if (count($error_detected) == 0) {
1022 if ($trans->getMissingAmount() > 0) {
1025 'type' => $post['contrib_type']
1028 if (isset($trans->member
)) {
1029 $rparams['id_adh'] = $trans->member
;
1036 $this->router
->pathFor(
1039 ) . '?' . Transaction
::PK
. '=' . $trans->id
.
1040 '&' . Adherent
::PK
. '=' . $trans->member
1044 $this->flash
->addMessage(
1046 _T("Transaction has been successfully stored")
1049 //get back to transactions list
1054 $this->router
->pathFor('contributions', ['type' => 'transactions'])
1058 //something went wrong.
1059 //store entity in session
1060 $this->session
->transaction
= $trans;
1063 foreach ($error_detected as $error) {
1064 $this->flash
->addMessage(
1070 //redirect to calling action
1073 ->withHeader('Location', $this->router
->pathFor('transaction', $args));
1078 ->withHeader('Location', $this->router
->pathFor('contributions', ['type' => 'transactions']));
1080 )->setName('doEditTransaction')->add($authenticate);
1083 '/{type:contributions|transactions}/remove' .'/{id:\d+}',
1084 function ($request, $response, $args) {
1086 switch ($args['type']) {
1087 case 'transactions':
1088 $raw_type = 'transactions';
1090 case 'contributions':
1091 $raw_type = 'contributions';
1096 'id' => $args['id'],
1097 'redirect_uri' => $this->router
->pathFor('contributions', ['type' => $args['type']])
1101 $this->view
->render(
1103 'confirm_removal.tpl',
1105 'type' => ($raw_type === 'contributions') ?
_T('Contributions') : _T('Transactions'),
1106 'mode' => $request->isXhr() ?
'ajax' : '',
1107 'page_title' => sprintf(
1108 _T('Remove %1$s #%2$s'),
1109 ($raw_type === 'contributions') ?
_T('contribution') : _T('transaction'),
1112 'form_url' => $this->router
->pathFor(
1113 'doRemoveContribution',
1114 ['id' => $args['id'], 'type' => $args['type']]
1116 'cancel_uri' => $data['redirect_uri'],
1122 )->setName('removeContribution')->add($authenticate);
1125 '/{type:contributions|transactions}/batch/remove',
1126 function ($request, $response, $args) {
1127 $post = $request->getParsedBody();
1130 switch ($args['type']) {
1131 case 'transactions':
1132 $raw_type = 'transactions';
1134 case 'contributions':
1135 $raw_type = 'contributions';
1140 'id' => $post['contrib_sel'],
1141 'redirect_uri' => $this->router
->pathFor('contributions', ['type' => $args['type']])
1145 $this->view
->render(
1147 'confirm_removal.tpl',
1149 'type' => ($raw_type === 'contributions') ?
_T('Contributions') : _T('Transactions'),
1150 'mode' => $request->isXhr() ?
'ajax' : '',
1151 'page_title' => sprintf(
1153 ($raw_type === 'contributions') ?
_T('contributions') : _T('transactions')
1155 'message' => str_replace(
1158 ($raw_type === 'contributions' ?
1159 _T('You are about to remove %count contributions.') :
1160 _T('You are about to remove %count transactions.'))
1162 'form_url' => $this->router
->pathFor(
1163 'doRemoveContribution',
1164 ['type' => $args['type']]
1166 'cancel_uri' => $data['redirect_uri'],
1172 )->setName('removeContributions')->add($authenticate);
1175 '/{type:contributions|transactions}/remove[/{id}]',
1176 function ($request, $response, $args) {
1178 $post = $request->getParsedBody();
1179 $ajax = isset($post['ajax']) && $post['ajax'] === 'true';
1182 if (!is_array($post['id'])) {
1183 $ids = (array)$post['id'];
1189 switch ($args['type']) {
1190 case 'transactions':
1191 $raw_type = 'transactions';
1193 case 'contributions':
1194 $raw_type = 'contributions';
1198 $uri = isset($post['redirect_uri']) ?
1199 $post['redirect_uri'] :
1200 $this->router
->pathFor('slash');
1202 if (!isset($post['confirm'])) {
1203 $this->flash
->addMessage(
1205 _T("Removal has not been confirmed!")
1208 $class = '\\Galette\Repository\\' . ucwords($raw_type);
1209 $contribs = new $class($this->zdb
, $this->login
);
1210 $rm = $contribs->remove($ids, $this->history
);
1213 if ($raw_type === 'contributions') {
1214 $msg = _T("Contributions(s) has been removed!");
1216 $msg = _T("Transactions(s) has been removed!");
1218 $this->flash
->addMessage(
1225 if ($raw_type === 'contributions') {
1226 $msg = _T("An error occurred trying to remove contributions(s) :(");
1228 $msg = _T("An error occurred trying to remove transaction(s) :(");
1230 $this->flash
->addMessage(
1240 ->withHeader('Location', $uri);
1242 return $response->withJson(
1244 'success' => $success
1249 )->setName('doRemoveContribution')->add($authenticate);
1253 '/contribution/print/{id:\d+}',
1254 function ($request, $response, $args) {
1255 $contribution = new Contribution($this->zdb
, $this->login
, (int)$args['id']);
1256 $pdf = new PdfContribution($contribution, $this->zdb
, $this->preferences
);
1259 )->setName('printContribution')->add($authenticate);