27require
'../../main.inc.php';
28require_once DOL_DOCUMENT_ROOT.
'/don/class/don.class.php';
29require_once DOL_DOCUMENT_ROOT.
'/don/class/paymentdonation.class.php';
30require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
35$action =
GETPOST(
'action',
'aZ09');
41if ($user->socid > 0) {
42 $socid = $user->socid;
47$permissiontoread = $user->hasRight(
'don',
'lire');
48$permissiontoadd = $user->hasRight(
'don',
'creer');
49$permissiontodelete = $user->hasRight(
'don',
'supprimer');
56if ($action ==
'add_payment' && $permissiontoadd) {
60 $loc = DOL_URL_ROOT.
'/don/card.php?rowid='.$chid;
61 header(
"Location: ".$loc);
67 if (!(
GETPOST(
"paymenttype") > 0)) {
68 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"PaymentMode")),
null,
'errors');
71 if ($datepaid ==
'') {
72 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Date")),
null,
'errors');
75 if (isModEnabled(
"bank") && !(
GETPOSTINT(
"accountid") > 0)) {
76 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"AccountToCredit")),
null,
'errors');
84 foreach ($_POST as $key => $value) {
85 if (substr($key, 0, 7) ==
'amount_') {
86 $other_chid = substr($key, 7);
91 if (count($amounts) <= 0) {
93 $errmsg =
'ErrorNoPaymentDefined';
102 $payment->chid = $chid;
103 $payment->datep = $datepaid;
104 $payment->amounts = $amounts;
105 $payment->paymenttype =
GETPOSTINT(
"paymenttype");
106 $payment->num_payment =
GETPOST(
"num_payment",
'alphanohtml');
107 $payment->note_public =
GETPOST(
"note_public",
'restricthtml');
110 $paymentid = $payment->create($user);
111 if ($paymentid < 0) {
112 $errmsg = $payment->error;
119 $result = $payment->addPaymentToBank($user,
'payment_donation',
'(DonationPayment)',
GETPOSTINT(
'accountid'),
'',
'');
120 if (!($result > 0)) {
121 $errmsg = $payment->error;
129 $loc = DOL_URL_ROOT.
'/don/card.php?rowid='.$chid;
130 header(
'Location: '.$loc);
146$form =
new Form($db);
147$title = $langs->trans(
"Payment");
148llxHeader(
'', $title,
'',
'', 0, 0,
'',
'',
'',
'mod-donation page-payment');
151$sql =
"SELECT sum(p.amount) as total";
152$sql .=
" FROM ".MAIN_DB_PREFIX.
"payment_donation as p";
153$sql .=
" WHERE p.fk_donation = ".((int) $chid);
154$resql = $db->query($sql);
156 $obj = $db->fetch_object($resql);
157 $sumpaid = $obj->total;
163if ($action ==
'create') {
170 if (!empty($conf->use_javascript_ajax)) {
171 print
"\n".
'<script type="text/javascript">';
173 print
' $(document).ready(function () {';
174 print
' $(".AutoFillAmount").on(\'click touchstart\', function(){
175 $("input[name="+$(this).data(\'rowname\')+"]").val($(this).data("value")).trigger("change");
179 print
' </script>'.
"\n";
182 print
'<form name="add_payment" action="'.$_SERVER[
'PHP_SELF'].
'" method="post">';
183 print
'<input type="hidden" name="token" value="'.newToken().
'">';
184 print
'<input type="hidden" name="rowid" value="'.$chid.
'">';
185 print
'<input type="hidden" name="chid" value="'.$chid.
'">';
186 print
'<input type="hidden" name="action" value="add_payment">';
190 print
'<table class="border centpercent tableforfieldcreate">';
192 print
'<tr><td class="fieldrequired">'.$langs->trans(
"Date").
'</td><td colspan="2">';
195 print $form->selectDate($datepayment,
'', 0, 0, 0,
"add_payment", 1, 1, 0,
'',
'',
$object->date,
'', 1, $langs->trans(
"DonationDate"));
199 print
'<tr><td class="fieldrequired">'.$langs->trans(
"PaymentMode").
'</td><td colspan="2">';
200 $form->select_types_paiements(GETPOSTISSET(
"paymenttype") ?
GETPOST(
"paymenttype") :
$object->fk_typepayment,
"paymenttype");
205 print
'<td class="fieldrequired">'.$langs->trans(
'AccountToCredit').
'</td>';
206 print
'<td colspan="2">';
207 $form->select_comptes(GETPOSTISSET(
"accountid") ?
GETPOST(
"accountid") :
"0",
"accountid", 0,
'', 2);
211 print
'<tr><td>'.$langs->trans(
'Numero');
212 print
' <em>('.$langs->trans(
"ChequeOrTransferNumber").
')</em>';
214 print
'<td colspan="2"><input name="num_payment" type="text" value="'.GETPOST(
'num_payment').
'"></td></tr>'.
"\n";
217 print
'<td class="tdtop">'.$langs->trans(
"Comments").
'</td>';
218 print
'<td class="tdtop" colspan="2"><textarea name="note_public" wrap="soft" cols="60" rows="'.ROWS_3.
'"></textarea></td>';
232 print
'<table class="noborder centpercent">';
233 print
'<tr class="liste_titre">';
234 print
'<td>'.$langs->trans(
"Donation").
'</td>';
235 print
'<td class="right">'.$langs->trans(
"Amount").
'</td>';
236 print
'<td class="right">'.$langs->trans(
"AlreadyPaid").
'</td>';
237 print
'<td class="right">'.$langs->trans(
"RemainderToPay").
'</td>';
238 print
'<td class="center">'.$langs->trans(
"Amount").
'</td>';
247 print
'<tr class="oddeven">';
249 print
'<td>'.$object->getNomUrl(1).
"</td>";
251 print
'<td class="right">'.price($objp->amount).
"</td>";
253 print
'<td class="right">'.price($sumpaid).
"</td>";
255 print
'<td class="right">'.price($objp->amount - $sumpaid).
"</td>";
257 print
'<td class="center">';
258 if ($sumpaid < $objp->amount) {
259 $namef =
"amount_".$objp->id;
260 if (!empty($conf->use_javascript_ajax)) {
261 print
img_picto(
"Auto fill",
'rightarrow',
"class='AutoFillAmount' data-rowname='".$namef.
"' data-value='".
price($objp->amount - $sumpaid).
"'");
263 print
'<input type="text" size="8" name="'.$namef.
'">';
289 print $form->buttonsSaveCancel();
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Class to manage donations.
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 information (by default a local PHP server timestamp) Rep...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.