dolibarr/htdocs/compta/payment_sc/card.php

267 lines
7.7 KiB
PHP
Raw Normal View History

<?php
2022-06-14 09:14:00 +02:00
/* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2014 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
* Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2022 Alexandre Spangaro <aspangaro@open-dsi.fr>
*
* 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
2019-09-23 21:55:30 +02:00
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/compta/payment_sc/card.php
2020-11-03 14:52:04 +01:00
* \ingroup tax
* \brief Tab with payment of a social contribution
* \remarks File similar to fourn/paiement/card.php
*/
require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/paymentsocialcontribution.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php';
2022-08-29 11:25:44 +02:00
if (isModEnabled('banque')) {
2021-02-23 21:09:01 +01:00
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
}
2018-05-27 09:27:09 +02:00
// Load translation files required by the page
$langs->loadLangs(array('bills', 'banks', 'companies'));
// Security check
$id = GETPOST("id", 'int');
$action = GETPOST('action', 'aZ09');
2020-11-03 14:52:04 +01:00
$confirm = GETPOST('confirm', 'aZ09');
2021-02-23 21:09:01 +01:00
if ($user->socid) {
$socid = $user->socid;
}
// TODO ajouter regle pour restreindre acces paiement
//$result = restrictedArea($user, 'facture', $id,'');
2017-10-07 21:13:54 +02:00
$object = new PaymentSocialContribution($db);
2021-02-23 21:09:01 +01:00
if ($id > 0) {
$result = $object->fetch($id);
2021-02-23 21:09:01 +01:00
if (!$result) {
dol_print_error($db, 'Failed to get payment id '.$id);
}
2014-03-26 15:41:09 +01:00
}
/*
* Actions
*/
// Delete payment
2021-02-23 21:09:01 +01:00
if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->tax->charges->supprimer) {
$db->begin();
2017-10-07 21:13:54 +02:00
$result = $object->delete($user);
2021-02-23 21:09:01 +01:00
if ($result > 0) {
$db->commit();
2020-11-03 14:52:04 +01:00
header("Location: ".DOL_URL_ROOT."/compta/sociales/payments.php");
exit;
2020-05-21 15:05:19 +02:00
} else {
2017-10-07 21:13:54 +02:00
setEventMessages($object->error, $object->errors, 'errors');
$db->rollback();
}
}
/*
* View
*/
llxHeader();
$socialcontrib = new ChargeSociales($db);
$form = new Form($db);
$h = 0;
2016-12-18 13:27:14 +01:00
$head[$h][0] = DOL_URL_ROOT.'/compta/payment_sc/card.php?id='.$id;
2020-05-17 13:34:16 +02:00
$head[$h][1] = $langs->trans("PaymentSocialContribution");
$hselected = $h;
$h++;
2016-12-18 13:27:14 +01:00
/*$head[$h][0] = DOL_URL_ROOT.'/compta/payment_sc/info.php?id='.$id;
$head[$h][1] = $langs->trans("Info");
$h++;
*/
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head($head, $hselected, $langs->trans("PaymentSocialContribution"), -1, 'payment');
/*
2015-11-15 07:47:35 +01:00
* Deletion confirmation of payment
*/
2021-02-23 21:09:01 +01:00
if ($action == 'delete') {
print $form->formconfirm('card.php?id='.$object->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete', '', 0, 2);
}
$linkback = '<a href="'.DOL_URL_ROOT.'/compta/sociales/payments.php">'.$langs->trans("BackToList").'</a>';
2017-10-07 21:13:54 +02:00
dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'id', '');
print '<div class="fichecenter">';
print '<div class="underbanner clearboth"></div>';
2019-11-05 21:24:41 +01:00
print '<table class="border centpercent">';
// Ref
2017-10-07 21:13:54 +02:00
/*print '<tr><td class="titlefield">'.$langs->trans('Ref').'</td>';
2010-02-10 18:07:25 +01:00
print '<td colspan="3">';
2017-10-07 21:13:54 +02:00
print $form->showrefnav($object,'id','',1,'rowid','id');
print '</td></tr>';*/
// Date
print '<tr><td>'.$langs->trans('Date').'</td><td colspan="3">'.dol_print_date($object->datep, 'day').'</td></tr>';
// Mode
2017-10-07 21:13:54 +02:00
print '<tr><td>'.$langs->trans('Mode').'</td><td colspan="3">'.$langs->trans("PaymentType".$object->type_code).'</td></tr>';
// Numero
print '<tr><td>'.$langs->trans('Numero').'</td><td colspan="3">'.$object->num_payment.'</td></tr>';
// Amount
2022-06-14 09:14:00 +02:00
print '<tr><td>'.$langs->trans('Amount').'</td><td colspan="3">'.price($object->amount, 0, $langs, 1, -1, -1, $conf->currency).'</td></tr>';
// Note
2017-10-07 21:13:54 +02:00
print '<tr><td>'.$langs->trans('Note').'</td><td colspan="3">'.nl2br($object->note).'</td></tr>';
// Bank account
2022-08-29 11:25:44 +02:00
if (isModEnabled('banque')) {
2021-02-23 21:09:01 +01:00
if ($object->bank_account) {
$bankline = new AccountLine($db);
$bankline->fetch($object->bank_line);
print '<tr>';
print '<td>'.$langs->trans('BankTransactionLine').'</td>';
print '<td colspan="3">';
print $bankline->getNomUrl(1, 0, 'showall');
print '</td>';
print '</tr>';
}
}
print '</table>';
2017-10-07 21:13:54 +02:00
print '</div>';
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end();
2017-10-07 21:13:54 +02:00
/*
2021-02-03 19:36:02 +01:00
* List of social contributions paid
*/
$disable_delete = 0;
2019-11-02 12:59:38 +01:00
$sql = 'SELECT f.rowid as scid, f.libelle as label, f.paye, f.amount as sc_amount, pf.amount, pc.libelle as sc_type';
$sql .= ' FROM '.MAIN_DB_PREFIX.'paiementcharge as pf,'.MAIN_DB_PREFIX.'chargesociales as f, '.MAIN_DB_PREFIX.'c_chargesociales as pc';
$sql .= ' WHERE pf.fk_charge = f.rowid AND f.fk_type = pc.id';
$sql .= ' AND f.entity = '.$conf->entity;
2021-08-27 23:36:06 +02:00
$sql .= ' AND pf.rowid = '.((int) $object->id);
2010-02-14 14:27:24 +01:00
dol_syslog("compta/payment_sc/card.php", LOG_DEBUG);
$resql = $db->query($sql);
2021-02-23 21:09:01 +01:00
if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
$total = 0;
2019-11-05 21:24:41 +01:00
print '<br><table class="noborder centpercent">';
print '<tr class="liste_titre">';
print '<td>'.$langs->trans('SocialContribution').'</td>';
print '<td>'.$langs->trans('Type').'</td>';
print '<td>'.$langs->trans('Label').'</td>';
2019-02-10 15:59:19 +01:00
print '<td class="right">'.$langs->trans('ExpectedToPay').'</td>';
2019-12-12 10:31:08 +01:00
print '<td class="center">'.$langs->trans('Status').'</td>';
2019-02-10 15:59:19 +01:00
print '<td class="right">'.$langs->trans('PayedByThisPayment').'</td>';
print "</tr>\n";
2021-02-23 21:09:01 +01:00
if ($num > 0) {
while ($i < $num) {
$objp = $db->fetch_object($resql);
2010-09-12 13:49:02 +02:00
print '<tr class="oddeven">';
2010-09-12 13:49:02 +02:00
// Ref
print '<td>';
2010-09-12 13:49:02 +02:00
$socialcontrib->fetch($objp->scid);
print $socialcontrib->getNomUrl(1);
print "</td>\n";
2010-09-12 13:49:02 +02:00
// Type
print '<td>';
print $socialcontrib->type_label;
/*print $socialcontrib->type;*/
print "</td>\n";
2010-09-12 13:49:02 +02:00
// Label
2019-11-02 12:59:38 +01:00
print '<td>'.$objp->label.'</td>';
2010-02-10 18:07:25 +01:00
// Expected to pay
2021-03-29 13:00:17 +02:00
print '<td class="right"><span class="amount">'.price($objp->sc_amount).'</span></td>';
2010-02-10 18:07:25 +01:00
// Status
2019-12-12 10:31:08 +01:00
print '<td class="center">'.$socialcontrib->getLibStatut(4, $objp->amount).'</td>';
2021-02-03 19:36:02 +01:00
// Amount paid
2021-03-29 13:00:17 +02:00
print '<td class="right"><span class="amount">'.price($objp->amount).'</span></td>';
print "</tr>\n";
2021-02-23 21:09:01 +01:00
if ($objp->paye == 1) { // If at least one invoice is paid, disable delete
$disable_delete = 1;
}
$total = $total + $objp->amount;
$i++;
}
}
2017-10-07 21:13:54 +02:00
print "</table>\n";
$db->free($resql);
2020-05-21 15:05:19 +02:00
} else {
dol_print_error($db);
}
/*
* Actions Buttons
*/
print '<div class="tabsAction">';
/*
2012-09-15 10:01:35 +02:00
if (! empty($conf->global->BILL_ADD_PAYMENT_VALIDATION))
{
if ($user->socid == 0 && $object->statut == 0 && $_GET['action'] == '')
{
if ($user->rights->facture->paiement)
{
2021-03-30 03:55:17 +02:00
print '<a class="butAction" href="card.php?id='.GETPOST('id', 'int').'&amp;facid='.$objp->facid.'&amp;action=valide">'.$langs->trans('Valid').'</a>';
}
}
}
*/
2021-02-23 21:09:01 +01:00
if ($action == '') {
if ($user->rights->tax->charges->supprimer) {
if (!$disable_delete) {
print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.GETPOST('id', 'int').'&action=delete&token='.newToken().'">'.$langs->trans('Delete').'</a>';
2020-05-21 15:05:19 +02:00
} else {
2018-11-13 21:40:17 +01:00
print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("CantRemovePaymentWithOneInvoicePaid")).'">'.$langs->trans('Delete').'</a>';
}
}
}
print '</div>';
2018-08-08 12:29:36 +02:00
// End of page
llxFooter();
2014-03-26 15:41:09 +01:00
$db->close();