* Copyright (C) 2019 Frédéric France * * 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 . */ /** * \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("banque")) { 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') ? GETPOST('rowid', 'int') : GETPOST('id', 'int'); $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->rights->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 */ llxHeader(); $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 '
'; print '
'; print ''; // Date print ''; // Mode print ''; // Number print ''; // Amount print ''; // Note public print ''; // Bank account if (isModEnabled("banque")) { if ($object->bank_account) { $bankline = new AccountLine($db); $bankline->fetch($object->bank_line); print ''; print ''; print ''; print ''; } } print '
'.$langs->trans('Date').''.dol_print_date($object->datep, 'day').'
'.$langs->trans('Mode').''.$langs->trans("PaymentType".$object->type_code).'
'.$langs->trans('Numero').''.$object->num_payment.'
'.$langs->trans('Amount').''.price($object->amount, 0, $outputlangs, 1, -1, -1, $conf->currency).'
'.$langs->trans('Note').''.nl2br($object->note_public).'
'.$langs->trans('BankTransactionLine').''; print $bankline->getNomUrl(1, 0, 'showall'); print '
'; /* * 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 '
'; print ''; print ''; print ''; print ''; print ''; print "\n"; if ($num > 0) { while ($i < $num) { $objp = $db->fetch_object($resql); print ''; // Ref print '\n"; // Expected to pay print ''; // Status print ''; // Amount paid print ''; print "\n"; if ($objp->paid == 1) { // If at least one invoice is paid, disable delete $disable_delete = 1; } $total = $total + $objp->amount; $i++; } } print "
'.$langs->trans('Donation').''.$langs->trans('ExpectedToPay').''.$langs->trans('Status').''.$langs->trans('PayedByThisPayment').'
'; $don->fetch($objp->did); print $don->getNomUrl(1); print "'.price($objp->d_amount).''.$don->getLibStatut(4).''.price($objp->amount).'
\n"; $db->free($resql); } else { dol_print_error($db); } print '
'; print dol_get_fiche_end(); /* * Actions buttons */ print '
'; if (empty($action)) { if ($user->rights->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'), 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), '', 1); } } } print '
'; llxFooter(); $db->close();