dolibarr  9.0.0
card.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2015 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
24 require '../../main.inc.php';
25 require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php';
26 require_once DOL_DOCUMENT_ROOT.'/don/class/paymentdonation.class.php';
27 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php';
29 if (! empty($conf->banque->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
30 
31 // Load translation files required by the page
32 $langs->loadLangs(array("bills","banks","companies"));
33 
34 // Security check
35 $id=GETPOST('rowid')?GETPOST('rowid','int'):GETPOST('id','int');
36 $action=GETPOST('action','aZ09');
37 $confirm=GETPOST('confirm');
38 if ($user->societe_id) $socid=$user->societe_id;
39 // TODO Add rule to restrict access payment
40 //$result = restrictedArea($user, 'facture', $id,'');
41 
42 $object = new PaymentDonation($db);
43 if ($id > 0)
44 {
45  $result=$object->fetch($id);
46  if (! $result) dol_print_error($db,'Failed to get payment id '.$id);
47 }
48 
49 
50 /*
51  * Actions
52  */
53 
54 // Delete payment
55 if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->don->supprimer)
56 {
57  $db->begin();
58 
59  $result = $object->delete($user);
60  if ($result > 0)
61  {
62  $db->commit();
63  header("Location: ".DOL_URL_ROOT."/don/index.php");
64  exit;
65  }
66  else
67  {
68  setEventMessages($object->error, $object->errors, 'errors');
69  $db->rollback();
70  }
71 }
72 
73 // Create payment
74 if ($action == 'confirm_valide' && $confirm == 'yes' && $user->rights->don->creer)
75 {
76  $db->begin();
77 
78  $result=$object->valide();
79 
80  if ($result > 0)
81  {
82  $db->commit();
83 
84  $factures=array(); // TODO Get all id of invoices linked to this payment
85  foreach($factures as $id)
86  {
87  $fac = new Facture($db);
88  $fac->fetch($id);
89 
90  $outputlangs = $langs;
91  if (! empty($_REQUEST['lang_id']))
92  {
93  $outputlangs = new Translate("",$conf);
94  $outputlangs->setDefaultLang($_REQUEST['lang_id']);
95  }
96  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
97  $fac->generateDocument($fac->modelpdf, $outputlangs);
98  }
99  }
100 
101  header('Location: card.php?id='.$object->id);
102  exit;
103  }
104  else
105  {
106  setEventMessages($object->error, $object->errors, 'errors');
107  $db->rollback();
108  }
109 }
110 
111 
112 /*
113  * View
114  */
115 
116 llxHeader();
117 
118 $don = new Don($db);
119 $form = new Form($db);
120 
121 $h=0;
122 
123 $head[$h][0] = DOL_URL_ROOT.'/don/payment/card.php?id='.$id;
124 $head[$h][1] = $langs->trans("Card");
125 $hselected = $h;
126 $h++;
127 
128 dol_fiche_head($head, $hselected, $langs->trans("DonationPayment"), -1, 'payment');
129 
130 /*
131  * Confirm deleting of the payment
132  */
133 if ($action == 'delete')
134 {
135  print $form->formconfirm('card.php?id='.$object->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete','',0,2);
136 }
137 
138 /*
139  * Confirm validation of the payment
140  */
141 if ($action == 'valide')
142 {
143  $facid = GETPOST('facid','int');
144  print $form->formconfirm('card.php?id='.$object->id.'&amp;facid='.$facid, $langs->trans("ValidatePayment"), $langs->trans("ConfirmValidatePayment"), 'confirm_valide','',0,2);
145 }
146 
147 
148 dol_banner_tab($object,'id','',1,'rowid','id');
149 
150 print '<div class="fichecenter">';
151 print '<div class="underbanner clearboth"></div>';
152 
153 print '<table class="border" width="100%">';
154 
155 // Ref
156 /*print '<tr><td class=">'.$langs->trans('Ref').'</td>';
157 print '<td colspan="3">';
158 print $form->showrefnav($object,'id','',1,'rowid','id');
159 print '</td></tr>';
160 */
161 
162 // Date
163 print '<tr><td class="titlefield">'.$langs->trans('Date').'</td><td>'.dol_print_date($object->datep,'day').'</td></tr>';
164 
165 // Mode
166 print '<tr><td>'.$langs->trans('Mode').'</td><td>'.$langs->trans("PaymentType".$object->type_code).'</td></tr>';
167 
168 // Number
169 print '<tr><td>'.$langs->trans('Number').'</td><td>'.$object->num_payment.'</td></tr>';
170 
171 // Amount
172 print '<tr><td>'.$langs->trans('Amount').'</td><td>'.price($object->amount, 0, $outputlangs, 1, -1, -1, $conf->currency).'</td></tr>';
173 
174 // Note
175 print '<tr><td>'.$langs->trans('Note').'</td><td>'.nl2br($object->note).'</td></tr>';
176 
177 // Bank account
178 if (! empty($conf->banque->enabled))
179 {
180  if ($object->bank_account)
181  {
182  $bankline=new AccountLine($db);
183  $bankline->fetch($object->bank_line);
184 
185  print '<tr>';
186  print '<td>'.$langs->trans('BankTransactionLine').'</td>';
187  print '<td>';
188  print $bankline->getNomUrl(1,0,'showall');
189  print '</td>';
190  print '</tr>';
191  }
192 }
193 
194 print '</table>';
195 
196 
197 /*
198  * List of donations paid
199  */
200 
201 $disable_delete = 0;
202 $sql = 'SELECT d.rowid as did, d.paid, d.amount as d_amount, pd.amount';
203 $sql.= ' FROM '.MAIN_DB_PREFIX.'payment_donation as pd,'.MAIN_DB_PREFIX.'don as d';
204 $sql.= ' WHERE pd.fk_donation = d.rowid';
205 $sql.= ' AND d.entity = '.$conf->entity;
206 $sql.= ' AND pd.rowid = '.$id;
207 
208 dol_syslog("don/payment/card.php", LOG_DEBUG);
209 $resql=$db->query($sql);
210 if ($resql)
211 {
212  $num = $db->num_rows($resql);
213 
214  $i = 0;
215  $total = 0;
216  print '<br><table class="noborder" width="100%">';
217  print '<tr class="liste_titre">';
218  print '<td>'.$langs->trans('Donation').'</td>';
219  print '<td align="right">'.$langs->trans('ExpectedToPay').'</td>';
220  print '<td align="center">'.$langs->trans('Status').'</td>';
221  print '<td align="right">'.$langs->trans('PayedByThisPayment').'</td>';
222  print "</tr>\n";
223 
224  if ($num > 0)
225  {
226  while ($i < $num)
227  {
228  $objp = $db->fetch_object($resql);
229 
230  print '<tr class="oddeven">';
231  // Ref
232  print '<td>';
233  $don->fetch($objp->did);
234  print $don->getNomUrl(1);
235  print "</td>\n";
236  // Expected to pay
237  print '<td align="right">'.price($objp->d_amount).'</td>';
238  // Status
239  print '<td align="center">'.$don->getLibStatut(4,$objp->amount).'</td>';
240  // Amount payed
241  print '<td align="right">'.price($objp->amount).'</td>';
242  print "</tr>\n";
243  if ($objp->paid == 1) // If at least one invoice is paid, disable delete
244  {
245  $disable_delete = 1;
246  }
247  $total = $total + $objp->amount;
248  $i++;
249  }
250  }
251 
252 
253  print "</table>\n";
254  $db->free($resql);
255 }
256 else
257 {
258  dol_print_error($db);
259 }
260 
261 print '</div>';
262 
263 dol_fiche_end();
264 
265 
266 /*
267  * Actions buttons
268  */
269 print '<div class="tabsAction">';
270 
271 /*
272 if (! empty($conf->global->BILL_ADD_PAYMENT_VALIDATION))
273 {
274  if ($user->societe_id == 0 && $object->statut == 0 && $_GET['action'] == '')
275  {
276  if ($user->rights->facture->paiement)
277  {
278  print '<a class="butAction" href="card.php?id='.$_GET['id'].'&amp;facid='.$objp->facid.'&amp;action=valide">'.$langs->trans('Valid').'</a>';
279  }
280  }
281 }
282 */
283 
284 if ($_GET['action'] == '')
285 {
286  if ($user->rights->don->supprimer)
287  {
288  if (! $disable_delete)
289  {
290  print '<a class="butActionDelete" href="card.php?id='.$_GET['id'].'&amp;action=delete">'.$langs->trans('Delete').'</a>';
291  }
292  else
293  {
294  print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("CantRemovePaymentWithOneInvoicePaid")).'">'.$langs->trans('Delete').'</a>';
295  }
296  }
297 }
298 
299 print '</div>';
300 
301 
302 
303 llxFooter();
304 
305 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:56
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) if(! empty($conf->don->enabled) && $user->rights->societe->lire) if(! empty($conf->tax->enabled) && $user->rights->tax->charges->lire) if(! empty($conf->facture->enabled) &&! empty($conf->commande->enabled) && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1053
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
Class to manage bank transaction lines.
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
Class to manage generation of HTML components Only common components must be here.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
dol_fiche_end($notab=0)
Show tab footer of a card.
llxHeader()
Empty header.
Definition: wrapper.php:44
Class to manage translations.
if($_POST["cancel"]==$langs->trans("Cancel") &&! $id) if($action=='add' && $_POST["cancel"]<> $langs->trans("Cancel")) if($action=='delete') if($id) $form
Actions.
Definition: card.php:153
Class to manage payments of donations.
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...
dol_print_date($time, $format='', $tzoutput='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Class to manage donations.
Definition: don.class.php:35
Class to manage invoices.
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='')
Show tab header of a card.