4 * Copyright © 2003-2024 The Galette Team
6 * This file is part of Galette (https://galette.eu).
8 * Galette is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
13 * Galette is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with Galette. If not, see <http://www.gnu.org/licenses/>.
27 use Galette\Core\Login
;
28 use Galette\Entity\Adherent
;
29 use Galette\Entity\ScheduledPayment
;
30 use Galette\Filters\ScheduledPaymentsList
;
31 use Galette\Repository\PaymentTypes
;
32 use Galette\Repository\ScheduledPayments
;
35 * Contributions CSV exports
37 * @author Johan Cwiklinski <johan@x-tnd.be>
40 class ScheduledPaymentsCsv
extends CsvOut
42 private string $filename;
50 * @param Db $zdb Db instance
51 * @param Login $login Login instance
53 public function __construct(Db
$zdb, Login
$login)
55 $this->filename
= 'filtered_shceduledpaymentslist.csv';
56 $this->path
= self
::DEFAULT_DIRECTORY
. $this->filename
;
58 $this->login
= $login;
59 parent
::__construct();
65 * @param ScheduledPaymentsList $filters Current filters
69 public function exportScheduledPayments(ScheduledPaymentsList
$filters)
71 $scheduled = new ScheduledPayment($this->zdb
);
72 $fields = $scheduled->getFields();
75 foreach ($fields as $k => $f) {
80 $scheduleds = new ScheduledPayments($this->zdb
, $this->login
, $filters);
81 $scheduled_list = $scheduleds->getArrayList($filters->selected
);
82 $ptypes = PaymentTypes
::getAll(false);
84 foreach ($scheduled_list as &$scheduled) {
85 /** @var ArrayObject<string, int|string> $scheduled */
86 if (isset($scheduled->id_paymenttype
)) {
87 //add textual payment type
88 $scheduled->id_paymenttype
= $ptypes[$scheduled->id_paymenttype
];
92 if (isset($scheduled->date
)) {
94 $scheduled->date
!= ''
95 && $scheduled->date
!= '1901-01-01'
97 $date = new DateTime($scheduled->date
);
98 $scheduled->date
= $date->format(__("Y-m-d"));
100 $scheduled->date
= '';
104 if (isset($scheduled->scheduled_date
)) {
106 $scheduled->scheduled_date
!= ''
107 && $scheduled->scheduled_date
!= '1901-01-01'
109 $date = new DateTime($scheduled->scheduled_date
);
110 $scheduled->scheduled_date
= $date->format(__("Y-m-d"));
112 $scheduled->scheduled_date
= '';
117 if (isset($scheduled->{Adherent
::PK
})) {
118 $scheduled->{Adherent
::PK
} = Adherent
::getSName($this->zdb
, $scheduled->{Adherent
::PK
});
122 $fp = fopen($this->path
, 'w');
126 self
::DEFAULT_SEPARATOR
,
136 * Get file path on disk
140 public function getPath()
150 public function getFileName()
152 return $this->filename
;