dolibarr 19.0.3
payment.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2015 Alexandre Spangaro <aspangaro@open-dsi.fr>
3 * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
25// Load Dolibarr environment
26require '../../main.inc.php';
27require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php';
28require_once DOL_DOCUMENT_ROOT.'/don/class/paymentdonation.class.php';
29require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
30
31$langs->load("bills");
32
33$chid = GETPOST("rowid", 'int');
34$action = GETPOST('action', 'aZ09');
35$amounts = array();
36$cancel = GETPOST('cancel');
37
38// Security check
39$socid = 0;
40if ($user->socid > 0) {
41 $socid = $user->socid;
42}
43
44$object = new Don($db);
45
46
47/*
48 * Actions
49 */
50
51if ($action == 'add_payment') {
52 $error = 0;
53
54 if ($cancel) {
55 $loc = DOL_URL_ROOT.'/don/card.php?rowid='.$chid;
56 header("Location: ".$loc);
57 exit;
58 }
59
60 $datepaid = dol_mktime(12, 0, 0, GETPOST("remonth"), GETPOST("reday"), GETPOST("reyear"));
61
62 if (!(GETPOST("paymenttype") > 0)) {
63 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("PaymentMode")), null, 'errors');
64 $error++;
65 }
66 if ($datepaid == '') {
67 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Date")), null, 'errors');
68 $error++;
69 }
70 if (isModEnabled("banque") && !(GETPOST("accountid", 'int') > 0)) {
71 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("AccountToCredit")), null, 'errors');
72 $error++;
73 }
74
75 if (!$error) {
76 $paymentid = 0;
77
78 // Read possible payments
79 foreach ($_POST as $key => $value) {
80 if (substr($key, 0, 7) == 'amount_') {
81 $other_chid = substr($key, 7);
82 $amounts[$other_chid] = price2num(GETPOST($key));
83 }
84 }
85
86 if (count($amounts) <= 0) {
87 $error++;
88 $errmsg = 'ErrorNoPaymentDefined';
89 setEventMessages($errmsg, null, 'errors');
90 }
91
92 if (!$error) {
93 $db->begin();
94
95 // Create a line of payments
96 $payment = new PaymentDonation($db);
97 $payment->chid = $chid;
98 $payment->datep = $datepaid;
99 $payment->amounts = $amounts; // Tableau de montant
100 $payment->paymenttype = GETPOST("paymenttype", 'int');
101 $payment->num_payment = GETPOST("num_payment", 'alphanohtml');
102 $payment->note_public = GETPOST("note_public", 'restricthtml');
103
104 if (!$error) {
105 $paymentid = $payment->create($user);
106 if ($paymentid < 0) {
107 $errmsg = $payment->error;
108 setEventMessages($errmsg, null, 'errors');
109 $error++;
110 }
111 }
112
113 if (!$error) {
114 $result = $payment->addPaymentToBank($user, 'payment_donation', '(DonationPayment)', GETPOST('accountid', 'int'), '', '');
115 if (!($result > 0)) {
116 $errmsg = $payment->error;
117 setEventMessages($errmsg, null, 'errors');
118 $error++;
119 }
120 }
121
122 if (!$error) {
123 $db->commit();
124 $loc = DOL_URL_ROOT.'/don/card.php?rowid='.$chid;
125 header('Location: '.$loc);
126 exit;
127 } else {
128 $db->rollback();
129 }
130 }
131 }
132
133 $action = 'create';
134}
135
136
137/*
138 * View
139 */
140
141$form = new Form($db);
142
143llxHeader();
144
145
146$sql = "SELECT sum(p.amount) as total";
147$sql .= " FROM ".MAIN_DB_PREFIX."payment_donation as p";
148$sql .= " WHERE p.fk_donation = ".((int) $chid);
149$resql = $db->query($sql);
150if ($resql) {
151 $obj = $db->fetch_object($resql);
152 $sumpaid = $obj->total;
153 $db->free($resql);
154}
155
156
157// Form to create donation payment
158if ($action == 'create') {
159 $object->fetch($chid);
160
161 $total = $object->amount;
162
163 print load_fiche_titre($langs->trans("DoPayment"));
164
165 if (!empty($conf->use_javascript_ajax)) {
166 print "\n".'<script type="text/javascript">';
167 //Add js for AutoFill
168 print ' $(document).ready(function () {';
169 print ' $(".AutoFillAmout").on(\'click touchstart\', function(){
170 $("input[name="+$(this).data(\'rowname\')+"]").val($(this).data("value")).trigger("change");
171 });';
172 print ' });'."\n";
173
174 print ' </script>'."\n";
175 }
176
177 print '<form name="add_payment" action="'.$_SERVER['PHP_SELF'].'" method="post">';
178 print '<input type="hidden" name="token" value="'.newToken().'">';
179 print '<input type="hidden" name="rowid" value="'.$chid.'">';
180 print '<input type="hidden" name="chid" value="'.$chid.'">';
181 print '<input type="hidden" name="action" value="add_payment">';
182
183 print dol_get_fiche_head();
184
185 print '<table class="border centpercent tableforfieldcreate">';
186
187 print '<tr><td class="fieldrequired">'.$langs->trans("Date").'</td><td colspan="2">';
188 $datepaid = dol_mktime(12, 0, 0, GETPOST("remonth"), GETPOST("reday"), GETPOST("reyear"));
189 $datepayment = !getDolGlobalString('MAIN_AUTOFILL_DATE') ? (GETPOST("remonth") ? $datepaid : -1) : 0;
190 print $form->selectDate($datepayment, '', 0, 0, 0, "add_payment", 1, 1, 0, '', '', $object->date, '', 1, $langs->trans("DonationDate"));
191 print "</td>";
192 print '</tr>';
193
194 print '<tr><td class="fieldrequired">'.$langs->trans("PaymentMode").'</td><td colspan="2">';
195 $form->select_types_paiements(GETPOSTISSET("paymenttype") ? GETPOST("paymenttype") : $object->fk_typepayment, "paymenttype");
196 print "</td>\n";
197 print '</tr>';
198
199 print '<tr>';
200 print '<td class="fieldrequired">'.$langs->trans('AccountToCredit').'</td>';
201 print '<td colspan="2">';
202 $form->select_comptes(GETPOSTISSET("accountid") ? GETPOST("accountid") : "0", "accountid", 0, '', 2); // Show open bank account list
203 print '</td></tr>';
204
205 // Number
206 print '<tr><td>'.$langs->trans('Numero');
207 print ' <em>('.$langs->trans("ChequeOrTransferNumber").')</em>';
208 print '</td>';
209 print '<td colspan="2"><input name="num_payment" type="text" value="'.GETPOST('num_payment').'"></td></tr>'."\n";
210
211 print '<tr>';
212 print '<td class="tdtop">'.$langs->trans("Comments").'</td>';
213 print '<td class="tdtop" colspan="2"><textarea name="note_public" wrap="soft" cols="60" rows="'.ROWS_3.'"></textarea></td>';
214 print '</tr>';
215
216 print '</table>';
217
218 print dol_get_fiche_end();
219
220 /*
221 * List of payments on donation
222 */
223
224 $num = 1;
225 $i = 0;
226
227 print '<table class="noborder centpercent">';
228 print '<tr class="liste_titre">';
229 print '<td>'.$langs->trans("Donation").'</td>';
230 print '<td class="right">'.$langs->trans("Amount").'</td>';
231 print '<td class="right">'.$langs->trans("AlreadyPaid").'</td>';
232 print '<td class="right">'.$langs->trans("RemainderToPay").'</td>';
233 print '<td class="center">'.$langs->trans("Amount").'</td>';
234 print "</tr>\n";
235
236 $total = 0;
237 $totalrecu = 0;
238
239 while ($i < $num) {
240 $objp = $object;
241
242 print '<tr class="oddeven">';
243
244 print '<td>'.$object->getNomUrl(1)."</td>";
245
246 print '<td class="right">'.price($objp->amount)."</td>";
247
248 print '<td class="right">'.price($sumpaid)."</td>";
249
250 print '<td class="right">'.price($objp->amount - $sumpaid)."</td>";
251
252 print '<td class="center">';
253 if ($sumpaid < $objp->amount) {
254 $namef = "amount_".$objp->id;
255 if (!empty($conf->use_javascript_ajax)) {
256 print img_picto("Auto fill", 'rightarrow', "class='AutoFillAmout' data-rowname='".$namef."' data-value='".price($objp->amount - $sumpaid)."'");
257 }
258 print '<input type="text" size="8" name="'.$namef.'">';
259 } else {
260 print '-';
261 }
262 print "</td>";
263
264 print "</tr>\n";
265 /*$total+=$objp->total;
266 $total_ttc+=$objp->total_ttc;
267 $totalrecu+=$objp->am;*/ //Useless code ?
268 $i++;
269 }
270 /*if ($i > 1)
271 {
272 // Print total
273 print '<tr class="oddeven">';
274 print '<td colspan="2" class="left">'.$langs->trans("Total").':</td>';
275 print "<td class=\"right\"><b>".price($total_ttc)."</b></td>";
276 print "<td class=\"right\"><b>".price($totalrecu)."</b></td>";
277 print "<td class=\"right\"><b>".price($total_ttc - $totalrecu)."</b></td>";
278 print '<td class="center">&nbsp;</td>';
279 print "</tr>\n";
280 }*/ //Useless code ?
281
282 print "</table>";
283
284 print $form->buttonsSaveCancel();
285
286 print "</form>\n";
287}
288
289llxFooter();
290$db->close();
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:55
llxFooter()
Empty footer.
Definition wrapper.php:69
Class to manage donations.
Definition don.class.php:40
Class to manage generation of HTML components Only common components must be here.
Class to manage payments of donations.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.