/
card.php
230 lines (182 loc) · 6.3 KB
/
card.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
<?php
/* Copyright (C) 2015 Alexandre Spangaro <aspangaro@open-dsi.fr>
* Copyright (C) 2019 Frédéric France <frederic.france@netlogic.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/don/payment/card.php
* \ingroup donations
* \brief Tab payment of a donation
*/
// Load Dolibarr environment
require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php';
require_once DOL_DOCUMENT_ROOT.'/don/class/paymentdonation.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php';
if (isModEnabled("bank")) {
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
}
// Load translation files required by the page
$langs->loadLangs(array("bills", "banks", "companies", "donations"));
// Security check
$id = GETPOST('rowid') ? GETPOSTINT('rowid') : GETPOSTINT('id');
$action = GETPOST('action', 'aZ09');
$confirm = GETPOST('confirm', 'alpha');
if ($user->socid) {
$socid = $user->socid;
}
// TODO Add rule to restrict access payment
//$result = restrictedArea($user, 'facture', $id,'');
$object = new PaymentDonation($db);
if ($id > 0) {
$result = $object->fetch($id);
if (!$result) {
dol_print_error($db, 'Failed to get payment id '.$id);
}
}
/*
* Actions
*/
// Delete payment
if ($action == 'confirm_delete' && $confirm == 'yes' && $user->hasRight('don', 'supprimer')) {
$db->begin();
$result = $object->delete($user);
if ($result > 0) {
$db->commit();
header("Location: ".DOL_URL_ROOT."/don/index.php");
exit;
} else {
setEventMessages($object->error, $object->errors, 'errors');
$db->rollback();
}
}
/*
* View
*/
$title = $langs->trans("Payment");
llxHeader('', $title, '', '', 0, 0, '', '', '', 'mod-donation page-payment_card');
$don = new Don($db);
$form = new Form($db);
$h = 0;
$head = array();
$head[$h][0] = DOL_URL_ROOT.'/don/payment/card.php?id='.$id;
$head[$h][1] = $langs->trans("DonationPayment");
$hselected = $h;
$h++;
print dol_get_fiche_head($head, $hselected, $langs->trans("DonationPayment"), -1, 'payment');
/*
* Confirm deleting of the payment
*/
if ($action == 'delete') {
print $form->formconfirm('card.php?id='.$object->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete', '', 0, 2);
}
dol_banner_tab($object, 'id', '', 1, 'rowid', 'id');
print '<div class="fichecenter">';
print '<div class="underbanner clearboth"></div>';
print '<table class="border centpercent">';
// Date
print '<tr><td class="titlefield">'.$langs->trans('Date').'</td><td>'.dol_print_date($object->datep, 'day').'</td></tr>';
// Mode
print '<tr><td>'.$langs->trans('Mode').'</td><td>'.$langs->trans("PaymentType".$object->type_code).'</td></tr>';
// Number
print '<tr><td>'.$langs->trans('Numero').'</td><td>'.dol_escape_htmltag($object->num_payment).'</td></tr>';
// Amount
print '<tr><td>'.$langs->trans('Amount').'</td><td>'.price($object->amount, 0, $outputlangs, 1, -1, -1, $conf->currency).'</td></tr>';
// Note public
print '<tr><td>'.$langs->trans('Note').'</td><td class="valeur sensiblehtmlcontent">'.dol_string_onlythesehtmltags(dol_htmlcleanlastbr($object->note_public)).'</td></tr>';
// Bank account
if (isModEnabled("bank")) {
if ($object->bank_account) {
$bankline = new AccountLine($db);
$bankline->fetch($object->bank_line);
print '<tr>';
print '<td>'.$langs->trans('BankTransactionLine').'</td>';
print '<td>';
print $bankline->getNomUrl(1, 0, 'showall');
print '</td>';
print '</tr>';
}
}
print '</table>';
/*
* List of donations paid
*/
$disable_delete = 0;
$sql = 'SELECT d.rowid as did, d.paid, d.amount as d_amount, pd.amount';
$sql .= ' FROM '.MAIN_DB_PREFIX.'payment_donation as pd,'.MAIN_DB_PREFIX.'don as d';
$sql .= ' WHERE pd.fk_donation = d.rowid';
$sql .= ' AND d.entity = '.$conf->entity;
$sql .= ' AND pd.rowid = '.((int) $id);
dol_syslog("don/payment/card.php", LOG_DEBUG);
$resql = $db->query($sql);
if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
$total = 0;
print '<br><table class="noborder centpercent">';
print '<tr class="liste_titre">';
print '<td>'.$langs->trans('Donation').'</td>';
print '<td class="right">'.$langs->trans('ExpectedToPay').'</td>';
print '<td class="center">'.$langs->trans('Status').'</td>';
print '<td class="right">'.$langs->trans('PayedByThisPayment').'</td>';
print "</tr>\n";
if ($num > 0) {
while ($i < $num) {
$objp = $db->fetch_object($resql);
print '<tr class="oddeven">';
// Ref
print '<td>';
$don->fetch($objp->did);
print $don->getNomUrl(1);
print "</td>\n";
// Expected to pay
print '<td class="right">'.price($objp->d_amount).'</td>';
// Status
print '<td class="center">'.$don->getLibStatut(4).'</td>';
// Amount paid
print '<td class="right">'.price($objp->amount).'</td>';
print "</tr>\n";
if ($objp->paid == 1) {
// If at least one invoice is paid, disable delete
$disable_delete = 1;
}
$total = $total + $objp->amount;
$i++;
}
}
print "</table>\n";
$db->free($resql);
} else {
dol_print_error($db);
}
print '</div>';
print dol_get_fiche_end();
/*
* Actions buttons
*/
print '<div class="tabsAction">';
if (empty($action)) {
if ($user->hasRight('don', 'supprimer')) {
if (!$disable_delete) {
print dolGetButtonAction($langs->trans('Delete'), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), '', 1);
} else {
print dolGetButtonAction($langs->trans("CantRemovePaymentWithOneInvoicePaid"), $langs->trans('Delete'), '', $_SERVER["PHP_SELF"].'?id='.$object->id.'#', '', 1, [ 'attr' => ['classOverride' => 'butActionRefused']]);
}
}
}
print '</div>';
llxFooter();
$db->close();