dolibarr  7.0.0-beta
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 $langs->load('bills');
32 $langs->load('banks');
33 $langs->load('companies');
34 
35 // Security check
36 $id=GETPOST('rowid')?GETPOST('rowid','int'):GETPOST('id','int');
37 $action=GETPOST('action','aZ09');
38 $confirm=GETPOST('confirm');
39 if ($user->societe_id) $socid=$user->societe_id;
40 // TODO Add rule to restrict access payment
41 //$result = restrictedArea($user, 'facture', $id,'');
42 
43 $object = new PaymentDonation($db);
44 if ($id > 0)
45 {
46  $result=$object->fetch($id);
47  if (! $result) dol_print_error($db,'Failed to get payment id '.$id);
48 }
49 
50 
51 /*
52  * Actions
53  */
54 
55 // Delete payment
56 if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->don->supprimer)
57 {
58  $db->begin();
59 
60  $result = $object->delete($user);
61  if ($result > 0)
62  {
63  $db->commit();
64  header("Location: ".DOL_URL_ROOT."/don/index.php");
65  exit;
66  }
67  else
68  {
69  setEventMessages($object->error, $object->errors, 'errors');
70  $db->rollback();
71  }
72 }
73 
74 // Create payment
75 if ($action == 'confirm_valide' && $confirm == 'yes' && $user->rights->don->creer)
76 {
77  $db->begin();
78 
79  $result=$object->valide();
80 
81  if ($result > 0)
82  {
83  $db->commit();
84 
85  $factures=array(); // TODO Get all id of invoices linked to this payment
86  foreach($factures as $id)
87  {
88  $fac = new Facture($db);
89  $fac->fetch($id);
90 
91  $outputlangs = $langs;
92  if (! empty($_REQUEST['lang_id']))
93  {
94  $outputlangs = new Translate("",$conf);
95  $outputlangs->setDefaultLang($_REQUEST['lang_id']);
96  }
97  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
98  $fac->generateDocument($fac->modelpdf, $outputlangs);
99  }
100  }
101 
102  header('Location: card.php?id='.$object->id);
103  exit;
104  }
105  else
106  {
107  setEventMessages($object->error, $object->errors, 'errors');
108  $db->rollback();
109  }
110 }
111 
112 
113 /*
114  * View
115  */
116 
117 llxHeader();
118 
119 $don = new Don($db);
120 $form = new Form($db);
121 
122 $h=0;
123 
124 $head[$h][0] = DOL_URL_ROOT.'/don/payment/card.php?id='.$id;
125 $head[$h][1] = $langs->trans("Card");
126 $hselected = $h;
127 $h++;
128 
129 dol_fiche_head($head, $hselected, $langs->trans("DonationPayment"), -1, 'payment');
130 
131 /*
132  * Confirm deleting of the payment
133  */
134 if ($action == 'delete')
135 {
136  print $form->formconfirm('card.php?id='.$object->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete','',0,2);
137 
138 }
139 
140 /*
141  * Confirm validation of the payment
142  */
143 if ($action == 'valide')
144 {
145  $facid = GETPOST('facid','int');
146  print $form->formconfirm('card.php?id='.$object->id.'&amp;facid='.$facid, $langs->trans("ValidatePayment"), $langs->trans("ConfirmValidatePayment"), 'confirm_valide','',0,2);
147 
148 }
149 
150 
151 dol_banner_tab($object,'id','',1,'rowid','id');
152 
153 print '<div class="fichecenter">';
154 print '<div class="underbanner clearboth"></div>';
155 
156 print '<table class="border" width="100%">';
157 
158 // Ref
159 /*print '<tr><td class=">'.$langs->trans('Ref').'</td>';
160 print '<td colspan="3">';
161 print $form->showrefnav($object,'id','',1,'rowid','id');
162 print '</td></tr>';
163 */
164 
165 // Date
166 print '<tr><td class="titlefield">'.$langs->trans('Date').'</td><td>'.dol_print_date($object->datep,'day').'</td></tr>';
167 
168 // Mode
169 print '<tr><td>'.$langs->trans('Mode').'</td><td>'.$langs->trans("PaymentType".$object->type_code).'</td></tr>';
170 
171 // Number
172 print '<tr><td>'.$langs->trans('Number').'</td><td>'.$object->num_payment.'</td></tr>';
173 
174 // Amount
175 print '<tr><td>'.$langs->trans('Amount').'</td><td>'.price($object->amount, 0, $outputlangs, 1, -1, -1, $conf->currency).'</td></tr>';
176 
177 // Note
178 print '<tr><td>'.$langs->trans('Note').'</td><td>'.nl2br($object->note).'</td></tr>';
179 
180 // Bank account
181 if (! empty($conf->banque->enabled))
182 {
183  if ($object->bank_account)
184  {
185  $bankline=new AccountLine($db);
186  $bankline->fetch($object->bank_line);
187 
188  print '<tr>';
189  print '<td>'.$langs->trans('BankTransactionLine').'</td>';
190  print '<td>';
191  print $bankline->getNomUrl(1,0,'showall');
192  print '</td>';
193  print '</tr>';
194  }
195 }
196 
197 print '</table>';
198 
199 
200 /*
201  * List of donations paid
202  */
203 
204 $disable_delete = 0;
205 $sql = 'SELECT d.rowid as did, d.paid, d.amount as d_amount, pd.amount';
206 $sql.= ' FROM '.MAIN_DB_PREFIX.'payment_donation as pd,'.MAIN_DB_PREFIX.'don as d';
207 $sql.= ' WHERE pd.fk_donation = d.rowid';
208 $sql.= ' AND d.entity = '.$conf->entity;
209 $sql.= ' AND pd.rowid = '.$id;
210 
211 dol_syslog("don/payment/card.php", LOG_DEBUG);
212 $resql=$db->query($sql);
213 if ($resql)
214 {
215  $num = $db->num_rows($resql);
216 
217  $i = 0;
218  $total = 0;
219  print '<br><table class="noborder" width="100%">';
220  print '<tr class="liste_titre">';
221  print '<td>'.$langs->trans('Donation').'</td>';
222  print '<td align="right">'.$langs->trans('ExpectedToPay').'</td>';
223  print '<td align="center">'.$langs->trans('Status').'</td>';
224  print '<td align="right">'.$langs->trans('PayedByThisPayment').'</td>';
225  print "</tr>\n";
226 
227  if ($num > 0)
228  {
229  $var=True;
230 
231  while ($i < $num)
232  {
233  $objp = $db->fetch_object($resql);
234 
235 
236  print '<tr class="oddeven">';
237  // Ref
238  print '<td>';
239  $don->fetch($objp->did);
240  print $don->getNomUrl(1);
241  print "</td>\n";
242  // Expected to pay
243  print '<td align="right">'.price($objp->d_amount).'</td>';
244  // Status
245  print '<td align="center">'.$don->getLibStatut(4,$objp->amount).'</td>';
246  // Amount payed
247  print '<td align="right">'.price($objp->amount).'</td>';
248  print "</tr>\n";
249  if ($objp->paid == 1) // If at least one invoice is paid, disable delete
250  {
251  $disable_delete = 1;
252  }
253  $total = $total + $objp->amount;
254  $i++;
255  }
256  }
257 
258 
259  print "</table>\n";
260  $db->free($resql);
261 }
262 else
263 {
264  dol_print_error($db);
265 }
266 
267 print '</div>';
268 
269 dol_fiche_end();
270 
271 
272 /*
273  * Actions buttons
274  */
275 print '<div class="tabsAction">';
276 
277 /*
278 if (! empty($conf->global->BILL_ADD_PAYMENT_VALIDATION))
279 {
280  if ($user->societe_id == 0 && $object->statut == 0 && $_GET['action'] == '')
281  {
282  if ($user->rights->facture->paiement)
283  {
284  print '<a class="butAction" href="card.php?id='.$_GET['id'].'&amp;facid='.$objp->facid.'&amp;action=valide">'.$langs->trans('Valid').'</a>';
285  }
286  }
287 }
288 */
289 
290 if ($_GET['action'] == '')
291 {
292  if ($user->rights->don->supprimer)
293  {
294  if (! $disable_delete)
295  {
296  print '<a class="butActionDelete" href="card.php?id='.$_GET['id'].'&amp;action=delete">'.$langs->trans('Delete').'</a>';
297  }
298  else
299  {
300  print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("CantRemovePaymentWithOneInvoicePaid")).'">'.$langs->trans('Delete').'</a>';
301  }
302  }
303 }
304 
305 print '</div>';
306 
307 
308 
309 llxFooter();
310 
311 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:58
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='')
Show tab header of a card.
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...
if(empty($reshook)) $form
View.
Definition: perms.php:103
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
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:46
Class to manage translations.
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).
print
Draft customers invoices.
Definition: index.php:91
Class to manage donations.
Definition: don.class.php:35
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:1013
Class to manage invoices.