dolibarr/htdocs/compta/paiement/card.php

456 lines
13 KiB
PHP
Raw Normal View History

<?php
/* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
2012-12-30 15:13:49 +01:00
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
2015-11-12 11:59:15 +01:00
* Copyright (C) 2013 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2015 Juanjo Menent <jmenent@2byte.es>
2004-01-31 18:29:54 +01:00
*
* 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
2004-01-31 18:29:54 +01:00
* (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
2011-08-03 02:45:22 +02:00
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2004-01-31 18:29:54 +01:00
*/
2004-09-14 22:46:09 +02:00
2005-04-15 23:49:23 +02:00
/**
* \file htdocs/compta/paiement/card.php
2009-07-15 21:53:31 +02:00
* \ingroup facture
* \brief Page of a customer payment
* \remarks Nearly same file than fournisseur/paiement/card.php
2009-07-15 21:53:31 +02:00
*/
2004-09-14 22:46:09 +02:00
require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
require_once DOL_DOCUMENT_ROOT .'/core/modules/facture/modules_facture.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
2012-09-15 10:01:35 +02:00
if (! empty($conf->banque->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
2004-01-31 18:29:54 +01:00
2018-05-27 09:27:09 +02:00
// Load translation files required by the page
2018-03-31 22:44:32 +02:00
$langs->loadLangs(array('bills','banks','companies'));
2004-09-14 22:46:09 +02:00
$id=GETPOST('id','int');
2017-04-07 14:18:04 +02:00
$ref=GETPOST('ref', 'alpha');
$action=GETPOST('action','alpha');
$confirm=GETPOST('confirm','alpha');
2017-12-03 11:59:16 +01:00
$backtopage=GETPOST('backtopage','alpha');
2017-04-07 14:18:04 +02:00
// Security check
if ($user->societe_id) $socid=$user->societe_id;
2010-01-15 00:21:22 +01:00
// TODO ajouter regle pour restreindre acces paiement
//$result = restrictedArea($user, 'facture', $id,'');
$object = new Paiement($db);
/*
* Actions
*/
2011-03-06 18:03:27 +01:00
if ($action == 'setnote' && $user->rights->facture->paiement)
{
$db->begin();
$object->fetch($id);
$result = $object->update_note(GETPOST('note','none'));
2011-03-06 18:03:27 +01:00
if ($result > 0)
{
$db->commit();
$action='';
}
else
{
2015-11-12 11:59:15 +01:00
setEventMessages($object->error, $object->errors, 'errors');
2011-03-06 18:03:27 +01:00
$db->rollback();
}
}
if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->facture->paiement)
2004-02-10 16:28:00 +01:00
{
$db->begin();
2009-03-02 19:17:19 +01:00
$object->fetch($id);
$result = $object->delete();
if ($result > 0)
{
$db->commit();
2017-12-03 11:59:16 +01:00
if ($backtopage)
{
header("Location: ".$backtopage);
exit;
}
else
{
header("Location: list.php");
exit;
}
}
else
{
$langs->load("errors");
2015-11-12 11:59:15 +01:00
setEventMessages($object->error, $object->errors, 'errors');
$db->rollback();
}
2004-02-10 16:28:00 +01:00
}
2004-12-16 14:26:13 +01:00
if ($action == 'confirm_valide' && $confirm == 'yes' && $user->rights->facture->paiement)
2004-12-16 14:26:13 +01:00
{
$db->begin();
$object->fetch($id);
if ($object->valide() > 0)
{
$db->commit();
2009-03-02 19:17:19 +01:00
2010-08-14 03:42:59 +02:00
// Loop on each invoice linked to this payment to rebuild PDF
$factures=array();
foreach($factures as $id)
{
$fac = new Facture($db);
$fac->fetch($id);
2008-10-29 00:36:36 +01:00
$outputlangs = $langs;
if (! empty($_REQUEST['lang_id']))
{
$outputlangs = new Translate("",$conf);
$outputlangs->setDefaultLang($_REQUEST['lang_id']);
}
if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
$fac->generateDocument($fac->modelpdf, $outputlangs);
}
}
2012-08-31 05:58:38 +02:00
header('Location: '.$_SERVER['PHP_SELF'].'?id='.$object->id);
exit;
}
else
{
$langs->load("errors");
2015-11-12 11:59:15 +01:00
setEventMessages($object->error, $object->errors, 'errors');
$db->rollback();
}
2004-12-16 14:26:13 +01:00
}
2012-06-14 22:47:45 +02:00
if ($action == 'setnum_paiement' && ! empty($_POST['num_paiement']))
{
$object->fetch($id);
$res = $object->update_num($_POST['num_paiement']);
if ($res === 0)
{
2015-11-12 11:59:15 +01:00
setEventMessages($langs->trans('PaymentNumberUpdateSucceeded'), null, 'mesgs');
}
else
{
2015-11-12 11:59:15 +01:00
setEventMessages($langs->trans('PaymentNumberUpdateFailed'), null, 'errors');
}
}
2012-06-14 22:47:45 +02:00
if ($action == 'setdatep' && ! empty($_POST['datepday']))
{
$object->fetch($id);
$datepaye = dol_mktime(12, 0, 0, $_POST['datepmonth'], $_POST['datepday'], $_POST['datepyear']);
$res = $object->update_date($datepaye);
if ($res === 0)
{
2015-11-12 11:59:15 +01:00
setEventMessages($langs->trans('PaymentDateUpdateSucceeded'), null, 'mesgs');
}
else
{
2015-11-12 11:59:15 +01:00
setEventMessages($langs->trans('PaymentDateUpdateFailed'), null, 'errors');
}
}
2004-01-31 18:29:54 +01:00
/*
2009-08-05 20:22:40 +02:00
* View
2004-01-31 18:29:54 +01:00
*/
2017-04-07 14:18:04 +02:00
llxHeader('', $langs->trans("Payment"));
2004-01-31 18:29:54 +01:00
$thirdpartystatic=new Societe($db);
2017-04-07 14:18:04 +02:00
$result=$object->fetch($id, $ref);
2007-05-24 00:39:14 +02:00
if ($result <= 0)
{
2011-03-06 18:03:27 +01:00
dol_print_error($db,'Payement '.$id.' not found in database');
2007-05-24 00:39:14 +02:00
exit;
}
2005-08-16 21:19:29 +02:00
$form = new Form($db);
2004-01-31 18:29:54 +01:00
$head = payment_prepare_head($object);
2005-08-16 21:19:29 +02:00
2017-04-07 14:18:04 +02:00
dol_fiche_head($head, 'payment', $langs->trans("PaymentCustomerInvoice"), -1, 'payment');
2004-02-10 16:28:00 +01:00
/*
2004-12-16 14:26:13 +01:00
* Confirmation de la suppression du paiement
2004-02-10 16:28:00 +01:00
*/
2011-03-06 18:03:27 +01:00
if ($action == 'delete')
2005-08-16 21:19:29 +02:00
{
print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete','',0,2);
2013-10-16 19:00:00 +02:00
2005-08-16 21:19:29 +02:00
}
2004-12-16 14:26:13 +01:00
2005-08-16 21:19:29 +02:00
/*
* Confirmation de la validation du paiement
*/
2011-03-06 18:03:27 +01:00
if ($action == 'valide')
2005-08-16 21:19:29 +02:00
{
2006-09-13 09:48:41 +02:00
$facid = $_GET['facid'];
print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;facid='.$facid, $langs->trans("ValidatePayment"), $langs->trans("ConfirmValidatePayment"), 'confirm_valide','',0,2);
2013-10-16 19:00:00 +02:00
2005-08-16 21:19:29 +02:00
}
2004-02-10 16:28:00 +01:00
2016-02-03 02:29:19 +01:00
$linkback = '<a href="' . DOL_URL_ROOT . '/compta/paiement/list.php">' . $langs->trans("BackToList") . '</a>';
2017-04-07 14:18:04 +02:00
dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', '');
2016-02-03 02:29:19 +01:00
2017-01-22 13:27:17 +01:00
2017-04-07 14:18:04 +02:00
print '<div class="fichecenter">';
print '<div class="underbanner clearboth"></div>';
print '<table class="border centpercent">'."\n";
// Date payment
2018-03-31 22:44:32 +02:00
print '<tr><td class="titlefield">'.$form->editfieldkey("Date",'datep',$object->date,$object,$user->rights->facture->paiement).'</td><td>';
print $form->editfieldval("Date",'datep',$object->date,$object,$user->rights->facture->paiement,'datepicker','',null,$langs->trans('PaymentDateUpdateSucceeded'));
print '</td></tr>';
2010-08-14 03:42:59 +02:00
// Payment type (VIR, LIQ, ...)
$labeltype=$langs->trans("PaymentType".$object->type_code)!=("PaymentType".$object->type_code)?$langs->trans("PaymentType".$object->type_code):$object->type_libelle;
2018-03-31 22:44:32 +02:00
print '<tr><td>'.$langs->trans('PaymentMode').'</td><td>'.$labeltype.'</td></tr>';
$disable_delete = 0;
// Bank account
if (! empty($conf->banque->enabled))
{
if ($object->fk_account > 0)
{
$bankline=new AccountLine($db);
$bankline->fetch($object->bank_line);
if ($bankline->rappro)
{
$disable_delete = 1;
$title_button = dol_escape_htmltag($langs->transnoentitiesnoconv("CantRemoveConciliatedPayment"));
}
print '<tr>';
print '<td>'.$langs->trans('BankAccount').'</td>';
print '<td>';
$accountstatic=new Account($db);
$accountstatic->fetch($bankline->fk_account);
print $accountstatic->getNomUrl(1);
print '</td>';
print '</tr>';
}
}
// Payment numero
2018-03-31 22:44:32 +02:00
/*
$titlefield=$langs->trans('Numero').' <em>('.$langs->trans("ChequeOrTransferNumber").')</em>';
print '<tr><td>'.$form->editfieldkey($titlefield,'num_paiement',$object->num_paiement,$object,$object->statut == 0 && $user->rights->fournisseur->facture->creer).'</td><td>';
print $form->editfieldval($titlefield,'num_paiement',$object->num_paiement,$object,$object->statut == 0 && $user->rights->fournisseur->facture->creer,'string','',null,$langs->trans('PaymentNumberUpdateSucceeded'));
print '</td></tr>';
2018-03-31 22:44:32 +02:00
// Check transmitter
$titlefield=$langs->trans('CheckTransmitter').' <em>('.$langs->trans("ChequeMaker").')</em>';
print '<tr><td>'.$form->editfieldkey($titlefield,'chqemetteur',$object->,$object,$object->statut == 0 && $user->rights->fournisseur->facture->creer).'</td><td>';
print $form->editfieldval($titlefield,'chqemetteur',$object->aaa,$object,$object->statut == 0 && $user->rights->fournisseur->facture->creer,'string','',null,$langs->trans('ChequeMakeUpdateSucceeded'));
print '</td></tr>';
2018-03-31 22:44:32 +02:00
// Bank name
$titlefield=$langs->trans('Bank').' <em>('.$langs->trans("ChequeBank").')</em>';
print '<tr><td>'.$form->editfieldkey($titlefield,'chqbank',$object->aaa,$object,$object->statut == 0 && $user->rights->fournisseur->facture->creer).'</td><td>';
print $form->editfieldval($titlefield,'chqbank',$object->aaa,$object,$object->statut == 0 && $user->rights->fournisseur->facture->creer,'string','',null,$langs->trans('ChequeBankUpdateSucceeded'));
2011-03-06 18:03:27 +01:00
print '</td></tr>';
2018-03-31 22:44:32 +02:00
*/
// Bank account
2012-09-15 10:01:35 +02:00
if (! empty($conf->banque->enabled))
{
2018-03-31 22:44:32 +02:00
if ($object->fk_account > 0)
{
2017-12-03 11:59:16 +01:00
if ($object->type_code == 'CHQ' && $bankline->fk_bordereau > 0)
{
dol_include_once('/compta/paiement/cheque/class/remisecheque.class.php');
$bordereau = new RemiseCheque($db);
$bordereau->fetch($bankline->fk_bordereau);
2013-10-16 19:00:00 +02:00
print '<tr>';
2018-03-31 22:44:32 +02:00
print '<td>'.$langs->trans('CheckReceipt').'</td>';
print '<td>';
2013-07-19 13:39:01 +02:00
print $bordereau->getNomUrl(1);
2018-03-31 22:44:32 +02:00
print '</td>';
print '</tr>';
}
2018-03-31 22:44:32 +02:00
}
print '<tr>';
print '<td>'.$langs->trans('BankTransactionLine').'</td>';
print '<td>';
print $bankline->getNomUrl(1,0,'showconciliated');
print '</td>';
print '</tr>';
}
2018-03-31 22:44:32 +02:00
// Comments
print '<tr><td class="tdtop">'.$form->editfieldkey("Comments",'note',$object->note,$object,$user->rights->facture->paiement).'</td><td>';
print $form->editfieldval("Note",'note',$object->note,$object,$user->rights->facture->paiement,'textarea:'.ROWS_3.':90%');
print '</td></tr>';
// Amount
print '<tr><td>'.$langs->trans('Amount').'</td><td>'.price($object->amount,'',$langs,0,-1,-1,$conf->currency).'</td></tr>';
print '</table>';
2004-01-31 18:29:54 +01:00
2017-04-07 14:18:04 +02:00
print '</div>';
2017-01-22 13:27:17 +01:00
dol_fiche_end();
2004-01-31 18:29:54 +01:00
2004-02-10 16:28:00 +01:00
/*
2010-01-15 00:21:22 +01:00
* List of invoices
2004-02-10 16:28:00 +01:00
*/
2010-01-15 00:21:22 +01:00
$sql = 'SELECT f.rowid as facid, f.facnumber, f.type, f.total_ttc, f.paye, f.fk_statut, pf.amount, s.nom as name, s.rowid as socid';
$sql.= ' FROM '.MAIN_DB_PREFIX.'paiement_facture as pf,'.MAIN_DB_PREFIX.'facture as f,'.MAIN_DB_PREFIX.'societe as s';
$sql.= ' WHERE pf.fk_facture = f.rowid';
$sql.= ' AND f.fk_soc = s.rowid';
2012-02-01 11:32:55 +01:00
$sql.= ' AND f.entity = '.$conf->entity;
$sql.= ' AND pf.fk_paiement = '.$object->id;
2009-03-02 19:17:19 +01:00
$resql=$db->query($sql);
if ($resql)
2004-02-10 16:28:00 +01:00
{
$num = $db->num_rows($resql);
2009-03-02 19:17:19 +01:00
$i = 0;
$total = 0;
2017-12-03 11:59:16 +01:00
2017-01-22 13:27:17 +01:00
$moreforfilter='';
2017-12-03 11:59:16 +01:00
2017-01-22 13:27:17 +01:00
print '<br>';
2017-12-03 11:59:16 +01:00
2017-01-22 13:27:17 +01:00
print '<div class="div-table-responsive">';
print '<table class="noborder" width="100%">';
2017-12-03 11:59:16 +01:00
print '<tr class="liste_titre">';
print '<td>'.$langs->trans('Bill').'</td>';
print '<td>'.$langs->trans('Company').'</td>';
2010-02-10 18:07:25 +01:00
print '<td align="right">'.$langs->trans('ExpectedToPay').'</td>';
print '<td align="right">'.$langs->trans('PayedByThisPayment').'</td>';
print '<td align="right">'.$langs->trans('RemainderToPay').'</td>';
print '<td align="right">'.$langs->trans('Status').'</td>';
print "</tr>\n";
2009-03-02 19:17:19 +01:00
if ($num > 0)
2004-02-10 16:28:00 +01:00
{
while ($i < $num)
{
$objp = $db->fetch_object($resql);
2017-12-03 11:59:16 +01:00
2018-03-07 18:32:25 +01:00
$thirdpartystatic->fetch($objp->socid);
$invoice=new Facture($db);
$invoice->fetch($objp->facid);
2010-02-10 18:07:25 +01:00
2018-03-07 18:32:25 +01:00
$paiement = $invoice->getSommePaiement();
$creditnotes=$invoice->getSumCreditNotesUsed();
$deposits=$invoice->getSumDepositsUsed();
$alreadypayed=price2num($paiement + $creditnotes + $deposits,'MT');
$remaintopay=price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits,'MT');
print '<tr class="oddeven">';
// Invoice
2009-03-02 19:17:19 +01:00
print '<td>';
print $invoice->getNomUrl(1);
2009-03-02 19:17:19 +01:00
print "</td>\n";
2010-02-10 18:07:25 +01:00
// Third party
print '<td>';
print $thirdpartystatic->getNomUrl(1);
print '</td>';
2010-02-10 18:07:25 +01:00
// Expected to pay
print '<td align="right">'.price($objp->total_ttc).'</td>';
// Amount payed
print '<td align="right">'.price($objp->amount).'</td>';
// Remain to pay
print '<td align="right">'.price($remaintopay).'</td>';
2010-02-10 18:07:25 +01:00
// Status
print '<td align="right">'.$invoice->getLibStatut(5, $alreadypayed).'</td>';
2010-02-10 18:07:25 +01:00
print "</tr>\n";
2010-01-15 00:21:22 +01:00
if ($objp->paye == 1) // If at least one invoice is paid, disable delete
{
2010-01-15 00:21:22 +01:00
$disable_delete = 1;
2016-01-09 10:37:53 +01:00
$title_button = dol_escape_htmltag($langs->transnoentitiesnoconv("CantRemovePaymentWithOneInvoicePaid"));
}
$total = $total + $objp->amount;
$i++;
2009-03-02 19:17:19 +01:00
}
}
2017-12-03 11:59:16 +01:00
print "</table>\n";
2017-01-22 13:27:17 +01:00
print '</div>';
2017-12-03 11:59:16 +01:00
2009-03-02 19:17:19 +01:00
$db->free($resql);
2004-02-10 16:28:00 +01:00
}
else
{
2009-03-02 19:17:19 +01:00
dol_print_error($db);
}
2004-02-10 16:28:00 +01:00
2004-02-10 16:28:00 +01:00
/*
* Boutons Actions
2004-02-10 16:28:00 +01:00
*/
2004-12-16 14:26:13 +01:00
print '<div class="tabsAction">';
2004-01-31 18:29:54 +01:00
2012-09-15 10:01:35 +02:00
if (! empty($conf->global->BILL_ADD_PAYMENT_VALIDATION))
2004-12-16 14:26:13 +01:00
{
if ($user->societe_id == 0 && $object->statut == 0 && $_GET['action'] == '')
{
if ($user->rights->facture->paiement)
{
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$id.'&amp;facid='.$objp->facid.'&amp;action=valide">'.$langs->trans('Valid').'</a>';
}
}
}
2010-01-15 00:21:22 +01:00
2011-03-06 18:03:27 +01:00
if ($user->societe_id == 0 && $action == '')
2004-12-16 14:26:13 +01:00
{
if ($user->rights->facture->paiement)
{
2010-01-15 00:21:22 +01:00
if (! $disable_delete)
{
print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?id='.$id.'&amp;action=delete">'.$langs->trans('Delete').'</a>';
2010-01-15 00:21:22 +01:00
}
else
{
2016-01-09 10:37:53 +01:00
print '<a class="butActionRefused" href="#" title="'.$title_button.'">'.$langs->trans('Delete').'</a>';
2010-01-15 00:21:22 +01:00
}
}
2004-12-16 14:26:13 +01:00
}
2009-03-02 19:17:19 +01:00
print '</div>';
llxFooter();
$db->close();