fix: gestion des montants avec espace et virgule lors de l'emission d'un paiement
fix: suppression de l'criture bancaire lors de la suppression d'un paiement
This commit is contained in:
parent
af75a55959
commit
ec4818c133
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
/* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2004-2005 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
/* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2004-2005 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
|
||||
*
|
||||
* 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
|
||||
@ -27,173 +28,162 @@
|
||||
\version $Revision$
|
||||
*/
|
||||
|
||||
include_once("./pre.inc.php");
|
||||
require_once(DOL_DOCUMENT_ROOT."/paiement.class.php");
|
||||
include_once(DOL_DOCUMENT_ROOT."/facture.class.php");
|
||||
include_once(DOL_DOCUMENT_ROOT."/compta/bank/account.class.php");
|
||||
include_once('./pre.inc.php');
|
||||
require_once(DOL_DOCUMENT_ROOT.'/paiement.class.php');
|
||||
include_once(DOL_DOCUMENT_ROOT.'/facture.class.php');
|
||||
include_once(DOL_DOCUMENT_ROOT.'/compta/bank/account.class.php');
|
||||
|
||||
$langs->load("bills");
|
||||
$langs->load("banks");
|
||||
$langs->load('bills');
|
||||
$langs->load('banks');
|
||||
|
||||
$facid=isset($_GET["facid"])?$_GET["facid"]:$_POST["facid"];
|
||||
$socname=isset($_GET["socname"])?$_GET["socname"]:$_POST["socname"];
|
||||
$facid=isset($_GET['facid'])?$_GET['facid']:$_POST['facid'];
|
||||
$socname=isset($_GET['socname'])?$_GET['socname']:$_POST['socname'];
|
||||
|
||||
$sortfield = isset($_GET["sortfield"])?$_GET["sortfield"]:$_POST["sortfield"];
|
||||
$sortorder = isset($_GET["sortorder"])?$_GET["sortorder"]:$_POST["sortorder"];
|
||||
$page=isset($_GET["page"])?$_GET["page"]:$_POST["page"];
|
||||
$sortfield = isset($_GET['sortfield'])?$_GET['sortfield']:$_POST['sortfield'];
|
||||
$sortorder = isset($_GET['sortorder'])?$_GET['sortorder']:$_POST['sortorder'];
|
||||
$page=isset($_GET['page'])?$_GET['page']:$_POST['page'];
|
||||
|
||||
|
||||
/*
|
||||
* Actions
|
||||
*/
|
||||
if ($_POST["action"] == 'add_paiement')
|
||||
if ($_POST['action'] == 'add_paiement')
|
||||
{
|
||||
$error = 0;
|
||||
$error = 0;
|
||||
|
||||
$datepaye = $db->idate(mktime(12, 0 , 0,
|
||||
$_POST["remonth"],
|
||||
$_POST["reday"],
|
||||
$_POST["reyear"]));
|
||||
$paiement_id = 0;
|
||||
$total = 0;
|
||||
// Génère tableau des montants amounts
|
||||
$amounts = array();
|
||||
foreach ($_POST as $key => $value)
|
||||
{
|
||||
if (substr($key,0,7) == 'amount_')
|
||||
{
|
||||
$other_facid = substr($key,7);
|
||||
$datepaye = $db->idate(mktime(12, 0 , 0,
|
||||
$_POST['remonth'],
|
||||
$_POST['reday'],
|
||||
$_POST['reyear']));
|
||||
$paiement_id = 0;
|
||||
$total = 0;
|
||||
// Génère tableau des montants amounts
|
||||
$amounts = array();
|
||||
foreach ($_POST as $key => $value)
|
||||
{
|
||||
if (substr($key,0,7) == 'amount_')
|
||||
{
|
||||
$other_facid = substr($key,7);
|
||||
$amounts[$other_facid] = $_POST[$key];
|
||||
$total = $total + $amounts[$other_facid];
|
||||
}
|
||||
}
|
||||
|
||||
$amounts[$other_facid] = $_POST[$key];
|
||||
$total = $total + $amounts[$other_facid];
|
||||
}
|
||||
}
|
||||
// Effectue les vérifications des parametres
|
||||
if ($_POST['paiementid'] <= 0)
|
||||
{
|
||||
$fiche_erreur_message = '<div class="error">'.$langs->trans('ErrorFieldRequired',$langs->trans('PaymentMode')).'</div>';
|
||||
$error++;
|
||||
}
|
||||
|
||||
// Effectue les vérifications des parametres
|
||||
if ($_POST["paiementid"] <= 0)
|
||||
{
|
||||
$fiche_erreur_message = '<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->trans("PaymentMode")).'</div>';
|
||||
$error++;
|
||||
}
|
||||
if ($conf->banque->enabled)
|
||||
{
|
||||
// Si module bank actif, un compte est obligatoire lors de la saisie
|
||||
// d'un paiement
|
||||
if (! $_POST['accountid'])
|
||||
{
|
||||
$fiche_erreur_message = '<div class="error">'.$langs->trans('ErrorFieldRequired',$langs->trans('AccountToCredit')).'</div>';
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
|
||||
if ($conf->banque->enabled)
|
||||
{
|
||||
// Si module bank actif, un compte est obligatoire lors de la saisie
|
||||
// d'un paiement
|
||||
if (! $_POST["accountid"])
|
||||
{
|
||||
$fiche_erreur_message = '<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->trans("AccountToCredit")).'</div>';
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
if ($total <= 0)
|
||||
{
|
||||
$fiche_erreur_message = '<div class="error">'.$langs->trans('ErrorFieldRequired',$langs->trans('Amount')).'</div>';
|
||||
$error++;
|
||||
}
|
||||
|
||||
if ($total <= 0)
|
||||
{
|
||||
$fiche_erreur_message = '<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->trans("Amount")).'</div>';
|
||||
$error++;
|
||||
}
|
||||
if (! $error)
|
||||
{
|
||||
$db->begin();
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
$db->begin();
|
||||
// Creation de la ligne paiement
|
||||
$paiement = new Paiement($db);
|
||||
$paiement->datepaye = $datepaye;
|
||||
$paiement->amounts = $amounts; // Tableau de montant
|
||||
$paiement->paiementid = $_POST['paiementid'];
|
||||
$paiement->num_paiement = $_POST['num_paiement'];
|
||||
$paiement->note = $_POST['comment'];
|
||||
|
||||
// Creation de la ligne paiement
|
||||
$paiement = new Paiement($db);
|
||||
$paiement->datepaye = $datepaye;
|
||||
$paiement->amounts = $amounts; // Tableau de montant
|
||||
$paiement->paiementid = $_POST["paiementid"];
|
||||
$paiement->num_paiement = $_POST["num_paiement"];
|
||||
$paiement->note = $_POST["comment"];
|
||||
$paiement_id = $paiement->create($user);
|
||||
|
||||
$paiement_id = $paiement->create($user);
|
||||
if ($paiement_id > 0)
|
||||
{
|
||||
// On determine le montant total du paiement
|
||||
$total=0;
|
||||
foreach ($paiement->amounts as $value)
|
||||
{
|
||||
$total += $value;
|
||||
}
|
||||
|
||||
if ($paiement_id > 0)
|
||||
{
|
||||
// On determine le montant total du paiement
|
||||
$total=0;
|
||||
foreach ($paiement->amounts as $key => $value)
|
||||
{
|
||||
$facid = $key;
|
||||
$value = trim($value);
|
||||
$amount = round(ereg_replace(",",".",$value), 2);
|
||||
if (is_numeric($amount))
|
||||
{
|
||||
$total += $amount;
|
||||
}
|
||||
}
|
||||
if ($conf->banque->enabled)
|
||||
{
|
||||
// Insertion dans llx_bank
|
||||
$label = 'Règlement facture';
|
||||
$acc = new Account($db, $_POST['accountid']);
|
||||
//paiementid contient "CHQ ou VIR par exemple"
|
||||
$bank_line_id = $acc->addline($paiement->datepaye,
|
||||
$paiement->paiementid,
|
||||
$label,
|
||||
$total,
|
||||
$paiement->num_paiement,
|
||||
'',
|
||||
$user);
|
||||
|
||||
if ($conf->banque->enabled)
|
||||
{
|
||||
// Insertion dans llx_bank
|
||||
$label = "Règlement facture";
|
||||
$acc = new Account($db, $_POST["accountid"]);
|
||||
//paiementid contient "CHQ ou VIR par exemple"
|
||||
$bank_line_id = $acc->addline($paiement->datepaye,
|
||||
$paiement->paiementid,
|
||||
$label,
|
||||
$total,
|
||||
$paiement->num_paiement,
|
||||
'',
|
||||
$user);
|
||||
// Mise a jour fk_bank dans llx_paiement.
|
||||
// On connait ainsi le paiement qui a généré l'écriture bancaire
|
||||
if ($bank_line_id > 0)
|
||||
{
|
||||
$paiement->update_fk_bank($bank_line_id);
|
||||
// Mise a jour liens (pour chaque facture concernées par le paiement)
|
||||
foreach ($paiement->amounts as $key => $value)
|
||||
{
|
||||
$facid = $key;
|
||||
$fac = new Facture($db);
|
||||
$fac->fetch($facid);
|
||||
$fac->fetch_client();
|
||||
$acc->add_url_line($bank_line_id,
|
||||
$paiement_id,
|
||||
DOL_URL_ROOT.'/compta/paiement/fiche.php?id=',
|
||||
'(paiement)',
|
||||
'payment');
|
||||
$acc->add_url_line($bank_line_id,
|
||||
$fac->client->id,
|
||||
DOL_URL_ROOT.'/compta/fiche.php?socid=',
|
||||
$fac->client->nom,
|
||||
'company');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$paiement->error;
|
||||
$error++;
|
||||
}
|
||||
|
||||
// Mise a jour fk_bank dans llx_paiement.
|
||||
// On connait ainsi le paiement qui a généré l'écriture bancaire
|
||||
if ($bank_line_id > 0)
|
||||
{
|
||||
$paiement->update_fk_bank($bank_line_id);
|
||||
|
||||
// Mise a jour liens (pour chaque facture concernées par le paiement)
|
||||
foreach ($paiement->amounts as $key => $value)
|
||||
{
|
||||
$facid = $key;
|
||||
$fac = new Facture($db);
|
||||
$fac->fetch($facid);
|
||||
$fac->fetch_client();
|
||||
$acc->add_url_line($bank_line_id,
|
||||
$paiement_id,
|
||||
DOL_URL_ROOT.'/compta/paiement/fiche.php?id=',
|
||||
"(paiement)",
|
||||
'payment');
|
||||
$acc->add_url_line($bank_line_id,
|
||||
$fac->client->id,
|
||||
DOL_URL_ROOT.'/compta/fiche.php?socid=',
|
||||
$fac->client->nom,
|
||||
'company');
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$paiement->error;
|
||||
$error++;
|
||||
}
|
||||
|
||||
|
||||
if ($error == 0)
|
||||
{
|
||||
$loc = DOL_URL_ROOT.'/compta/paiement/fiche.php?id='.$paiement_id;
|
||||
$db->commit();
|
||||
Header("Location: $loc");
|
||||
}
|
||||
else
|
||||
{
|
||||
$db->rollback();
|
||||
}
|
||||
}
|
||||
if ($error == 0)
|
||||
{
|
||||
$loc = DOL_URL_ROOT.'/compta/paiement/fiche.php?id='.$paiement_id;
|
||||
$db->commit();
|
||||
Header('Location: '.$loc);
|
||||
}
|
||||
else
|
||||
{
|
||||
$db->rollback();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Sécurité accés client
|
||||
if ($user->societe_id > 0)
|
||||
if ($user->societe_id > 0)
|
||||
{
|
||||
$action = '';
|
||||
$socidp = $user->societe_id;
|
||||
$action = '';
|
||||
$socidp = $user->societe_id;
|
||||
}
|
||||
|
||||
|
||||
@ -207,229 +197,225 @@ $html=new Form($db);
|
||||
|
||||
if ($fiche_erreur_message)
|
||||
{
|
||||
print '<tr><td colspan="3" align="center">'.$fiche_erreur_message.'</td></tr>';
|
||||
print '<tr><td colspan="3" align="center">'.$fiche_erreur_message.'</td></tr>';
|
||||
}
|
||||
|
||||
if ($_GET["action"] == 'create' || $_POST["action"] == 'add_paiement')
|
||||
if ($_GET['action'] == 'create' || $_POST['action'] == 'add_paiement')
|
||||
{
|
||||
$facture = new Facture($db);
|
||||
$facture->fetch($facid);
|
||||
$facture = new Facture($db);
|
||||
$facture->fetch($facid);
|
||||
|
||||
$sql = "SELECT s.nom,s.idp, f.amount, f.total_ttc as total, f.facnumber";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture as f WHERE f.fk_soc = s.idp";
|
||||
$sql .= " AND f.rowid = $facid";
|
||||
$sql = 'SELECT s.nom,s.idp, f.amount, f.total_ttc as total, f.facnumber';
|
||||
$sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s, '.MAIN_DB_PREFIX.'facture as f WHERE f.fk_soc = s.idp';
|
||||
$sql .= ' AND f.rowid = '.$facid;
|
||||
$resql = $db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$num = $db->num_rows($resql);
|
||||
if ($num)
|
||||
{
|
||||
$obj = $db->fetch_object($resql);
|
||||
|
||||
$resql = $db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$num = $db->num_rows($resql);
|
||||
if ($num)
|
||||
{
|
||||
$obj = $db->fetch_object($resql);
|
||||
$total = $obj->total;
|
||||
|
||||
$total = $obj->total;
|
||||
print_titre($langs->trans('DoPayment'));
|
||||
|
||||
print_titre($langs->trans("DoPayment"));
|
||||
print '<form action="paiement.php" method="post">';
|
||||
print '<input type="hidden" name="action" value="add_paiement">';
|
||||
print '<input type="hidden" name="facid" value="'.$facid.'">';
|
||||
print '<input type="hidden" name="facnumber" value="'.$obj->facnumber.'">';
|
||||
print '<input type="hidden" name="socid" value="'.$obj->idp.'">';
|
||||
print '<input type="hidden" name="societe" value="'.$obj->nom.'">';
|
||||
|
||||
print '<form action="paiement.php" method="post">';
|
||||
print '<input type="hidden" name="action" value="add_paiement">';
|
||||
print "<input type=\"hidden\" name=\"facid\" value=\"$facid\">";
|
||||
print "<input type=\"hidden\" name=\"facnumber\" value=\"$obj->facnumber\">";
|
||||
print "<input type=\"hidden\" name=\"socid\" value=\"$obj->idp\">";
|
||||
print "<input type=\"hidden\" name=\"societe\" value=\"$obj->nom\">";
|
||||
print '<table class="border" width="100%">';
|
||||
|
||||
print '<table class="border" width="100%">';
|
||||
print '<tr><td>'.$langs->trans('Company').'</td><td colspan="2">'.$obj->nom."</td></tr>\n";
|
||||
|
||||
print "<tr><td>".$langs->trans("Company")."</td><td colspan=\"2\">$obj->nom</td></tr>\n";
|
||||
print '<tr><td>'.$langs->trans('Date').'</td><td>';
|
||||
if (!empty($_POST['remonth']) && !empty($_POST['reday']) && !empty($_POST['reyear']))
|
||||
$sel_date=mktime(12, 0 , 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']);
|
||||
else
|
||||
$sel_date='';
|
||||
$html->select_date($sel_date);
|
||||
print '</td>';
|
||||
print '<td>'.$langs->trans('Comments').'</td></tr>';
|
||||
|
||||
print "<tr><td>".$langs->trans("Date")."</td><td>";
|
||||
$html->select_date();
|
||||
print '</td>';
|
||||
print '<td>'.$langs->trans("Comments").'</td></tr>';
|
||||
print '<tr><td>'.$langs->trans('PaymentMode').'</td><td>';
|
||||
$html->select_types_paiements(empty($_POST['paiementid'])?'':$_POST['paiementid'],'paiementid');
|
||||
print "</td>\n";
|
||||
|
||||
print '<tr><td>'.$langs->trans("PaymentMode").'</td><td>';
|
||||
$html->select_types_paiements('','paiementid');
|
||||
print "</td>\n";
|
||||
print '<td rowspan="3" valign="top">';
|
||||
print '<textarea name="comment" wrap="soft" cols="40" rows="4">'.(empty($_POST['comment'])?'':$_POST['comment']).'</textarea></td></tr>';
|
||||
|
||||
print '<td rowspan="3" valign="top">';
|
||||
print '<textarea name="comment" wrap="soft" cols="40" rows="4"></textarea></td></tr>';
|
||||
print '<tr><td>'.$langs->trans('Numero').'</td><td><input name="num_paiement" type="text" value="'.(empty($_POST['num_paiement'])?'':$_POST['num_paiement']).'"><br><em>Numéro du chèque / virement</em></td></tr>';
|
||||
|
||||
print "<tr><td>".$langs->trans("Numero")."</td><td><input name=\"num_paiement\" type=\"text\"><br><em>Numéro du chèque / virement</em></td></tr>\n";
|
||||
if ($conf->banque->enabled)
|
||||
{
|
||||
print '<tr><td>'.$langs->trans('AccountToCredit').'</td><td>';
|
||||
$html->select_comptes(empty($_POST['accountid'])?'':$_POST['accountid'],'accountid',0,'',1);
|
||||
print "</td></tr>\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
print '<tr><td colspan="2"> </td></tr>';
|
||||
}
|
||||
|
||||
/*
|
||||
* Autres factures impayées
|
||||
*/
|
||||
$sql = 'SELECT f.rowid as facid,f.facnumber,f.total_ttc,'.$db->pdate('f.datef').' as df';
|
||||
$sql .= ', sum(pf.amount) as am';
|
||||
$sql .= ' FROM '.MAIN_DB_PREFIX.'facture as f';
|
||||
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiement_facture as pf ON pf.fk_facture = f.rowid';
|
||||
$sql .= ' WHERE f.fk_soc = '.$facture->socidp;
|
||||
$sql .= ' AND f.paye = 0';
|
||||
$sql .= ' AND f.fk_statut = 1'; // Statut=0 => non validée, Statut=2 => annulée
|
||||
$sql .= ' GROUP BY f.facnumber';
|
||||
$resql = $db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$num = $db->num_rows($resql);
|
||||
if ($num > 0)
|
||||
{
|
||||
$i = 0;
|
||||
print '<tr><td colspan="3">';
|
||||
print '<table class="noborder" width="100%">';
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td>'.$langs->trans('Bill').'</td><td align="center">'.$langs->trans('Date').'</td>';
|
||||
print '<td align="right">'.$langs->trans('AmountTTC').'</td>';
|
||||
print '<td align="right">'.$langs->trans('Received').'</td>';
|
||||
print '<td align="right">'.$langs->trans('RemainderToPay').'</td>';
|
||||
print '<td align="center">'.$langs->trans('Amount').'</td>';
|
||||
print "</tr>\n";
|
||||
|
||||
if ($conf->banque->enabled)
|
||||
{
|
||||
print "<tr><td>".$langs->trans("AccountToCredit")."</td><td>";
|
||||
$html->select_comptes('','accountid',0,'',1);
|
||||
print "</td></tr>\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
print '<tr><td colspan="2"> </td></tr>';
|
||||
}
|
||||
$var=True;
|
||||
$total=0;
|
||||
$totalrecu=0;
|
||||
|
||||
/*
|
||||
* Autres factures impayées
|
||||
*/
|
||||
$sql = "SELECT f.rowid as facid,f.facnumber,f.total_ttc,".$db->pdate("f.datef")." as df";
|
||||
$sql .= ", sum(pf.amount) as am";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON pf.fk_facture = f.rowid";
|
||||
$sql .= " WHERE f.fk_soc = ".$facture->socidp;
|
||||
$sql .= " AND f.paye = 0";
|
||||
$sql .= " AND f.fk_statut = 1"; // Statut=0 => non validée, Statut=2 => annulée
|
||||
$sql .= " GROUP BY f.facnumber";
|
||||
while ($i < $num)
|
||||
{
|
||||
$objp = $db->fetch_object($resql);
|
||||
$var=!$var;
|
||||
|
||||
$resql = $db->query($sql);
|
||||
print '<tr '.$bc[$var].'>';
|
||||
|
||||
if ($resql)
|
||||
{
|
||||
$num = $db->num_rows($resql);
|
||||
print '<td><a href="facture.php?facid='.$objp->facid.'">'.img_object($langs->trans('ShowBill'),'bill').' '.$objp->facnumber;
|
||||
print "</a></td>\n";
|
||||
|
||||
if ($num > 0)
|
||||
{
|
||||
$i = 0;
|
||||
print '<tr><td colspan="3">';
|
||||
print '<table class="noborder" width="100%">';
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td>'.$langs->trans("Bill").'</td><td align="center">'.$langs->trans("Date").'</td>';
|
||||
print '<td align="right">'.$langs->trans("AmountTTC").'</td>';
|
||||
print '<td align="right">'.$langs->trans("Received").'</td>';
|
||||
print '<td align="right">'.$langs->trans("RemainderToPay").'</td>';
|
||||
print '<td align="center">'.$langs->trans("Amount").'</td>';
|
||||
print "</tr>\n";
|
||||
if ($objp->df > 0 )
|
||||
{
|
||||
print '<td align="center">';
|
||||
print dolibarr_print_date($objp->df)."</td>\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
print '<td align="center"><b>!!!</b></td>';
|
||||
}
|
||||
|
||||
$var=True;
|
||||
$total=0;
|
||||
$totalrecu=0;
|
||||
print '<td align="right">'.price($objp->total_ttc).'</td>';
|
||||
print '<td align="right">'.price($objp->am).'</td>';
|
||||
print '<td align="right">'.price($objp->total_ttc - $objp->am).'</td>';
|
||||
|
||||
while ($i < $num)
|
||||
{
|
||||
$objp = $db->fetch_object($resql);
|
||||
$var=!$var;
|
||||
print '<td align="center">';
|
||||
$namef = 'amount_'.$objp->facid;
|
||||
print '<input type="text" size="8" name="'.$namef.'">';
|
||||
print "</td></tr>\n";
|
||||
|
||||
print "<tr $bc[$var]>";
|
||||
$total+=$objp->total;
|
||||
$total_ttc+=$objp->total_ttc;
|
||||
$totalrecu+=$objp->am;
|
||||
$i++;
|
||||
}
|
||||
if ($i > 1)
|
||||
{
|
||||
// Print total
|
||||
print '<tr class="liste_total">';
|
||||
print '<td colspan="2" align="left">'.$langs->trans('TotalTTC').':</td>';
|
||||
print '<td align="right"><b>'.price($total_ttc).'</b></td>';
|
||||
print '<td align="right"><b>'.price($totalrecu).'</b></td>';
|
||||
print '<td align="right"><b>'.price($total_ttc - $totalrecu).'</b></td>';
|
||||
print '<td align="center"> </td>';
|
||||
print "</tr>\n";
|
||||
}
|
||||
print "</table></td></tr>\n";
|
||||
}
|
||||
$db->free($resql);
|
||||
}
|
||||
else
|
||||
{
|
||||
dolibarr_print_error($db);
|
||||
}
|
||||
|
||||
print '<td><a href="facture.php?facid='.$objp->facid.'">'.img_object($langs->trans("ShowBill"),"bill").' '.$objp->facnumber;
|
||||
print "</a></td>\n";
|
||||
|
||||
if ($objp->df > 0 )
|
||||
{
|
||||
print "<td align=\"center\">";
|
||||
print strftime("%d %b %Y",$objp->df)."</td>\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
print "<td align=\"center\"><b>!!!</b></td>\n";
|
||||
}
|
||||
|
||||
print '<td align="right">'.price($objp->total_ttc)."</td>";
|
||||
print '<td align="right">'.price($objp->am)."</td>";
|
||||
print '<td align="right">'.price($objp->total_ttc - $objp->am)."</td>";
|
||||
|
||||
print '<td align="center">';
|
||||
|
||||
$namef = "amount_".$objp->facid;
|
||||
print '<input type="text" size="8" name="'.$namef.'">';
|
||||
|
||||
print "</td></tr>\n";
|
||||
$total+=$objp->total;
|
||||
$total_ttc+=$objp->total_ttc;
|
||||
$totalrecu+=$objp->am;
|
||||
$i++;
|
||||
}
|
||||
if ($i > 1)
|
||||
{
|
||||
// Print total
|
||||
print '<tr class="liste_total">';
|
||||
print '<td colspan="2" align="left">'.$langs->trans("TotalTTC").':</td>';
|
||||
print "<td align=\"right\"><b>".price($total_ttc)."</b></td>";
|
||||
print "<td align=\"right\"><b>".price($totalrecu)."</b></td>";
|
||||
print "<td align=\"right\"><b>".price($total_ttc - $totalrecu)."</b></td>";
|
||||
print '<td align="center"> </td>';
|
||||
print "</tr>\n";
|
||||
}
|
||||
print "</table></td></tr>\n";
|
||||
}
|
||||
$db->free($resql);
|
||||
}
|
||||
else
|
||||
{
|
||||
dolibarr_print_error($db);
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
print '<tr><td colspan="3" align="center"><input type="submit" class="button" value="'.$langs->trans("Save").'"></td></tr>';
|
||||
print "</table>";
|
||||
print "</form>\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
*
|
||||
*/
|
||||
print '<tr><td colspan="3" align="center"><input type="submit" class="button" value="'.$langs->trans('Save').'"></td></tr>';
|
||||
print '</table>';
|
||||
print "</form>\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Affichage de la liste des paiement
|
||||
*/
|
||||
if (! $_GET["action"] && ! $_POST["action"])
|
||||
if (! $_GET['action'] && ! $_POST['action'])
|
||||
{
|
||||
|
||||
if ($page == -1) $page = 0 ;
|
||||
$limit = $conf->liste_limit;
|
||||
$offset = $limit * $page ;
|
||||
|
||||
if (! $sortorder) $sortorder="DESC";
|
||||
if (! $sortfield) $sortfield="p.datep";
|
||||
|
||||
$sql = "SELECT ".$db->pdate("p.datep")." as dp, p.amount, f.amount as fa_amount, f.facnumber";
|
||||
$sql .=", f.rowid as facid, c.libelle as paiement_type, p.num_paiement";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."paiement as p, ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."c_paiement as c";
|
||||
$sql .= " WHERE p.fk_facture = f.rowid AND p.fk_paiement = c.id";
|
||||
|
||||
if ($socidp)
|
||||
{
|
||||
$sql .= " AND f.fk_soc = $socidp";
|
||||
}
|
||||
|
||||
$sql .= " ORDER BY $sortfield $sortorder";
|
||||
$sql .= $db->plimit( $limit +1 ,$offset);
|
||||
$resql = $db->query($sql);
|
||||
|
||||
if ($resql)
|
||||
{
|
||||
$num = $db->num_rows($resql);
|
||||
$i = 0;
|
||||
$var=True;
|
||||
|
||||
print_barre_liste($langs->trans("Payments"), $page, "paiement.php","",$sortfield,$sortorder,'',$num);
|
||||
if ($page == -1) $page = 0 ;
|
||||
$limit = $conf->liste_limit;
|
||||
$offset = $limit * $page ;
|
||||
|
||||
print '<table class="noborder" width="100%">';
|
||||
print '<tr class="liste_titre">';
|
||||
print_liste_field_titre($langs->trans("Bill"),"paiement.php","facnumber","","","",$sortfield);
|
||||
print_liste_field_titre($langs->trans("Date"),"paiement.php","dp","","","",$sortfield);
|
||||
print_liste_field_titre($langs->trans("Type"),"paiement.php","libelle","","","",$sortfield);
|
||||
print_liste_field_titre($langs->trans("Amount"),"paiement.php","fa_amount","","",'align="right"',$sortfield);
|
||||
print "<td> </td>";
|
||||
print "</tr>\n";
|
||||
|
||||
while ($i < min($num,$limit))
|
||||
if (! $sortorder) $sortorder='DESC';
|
||||
if (! $sortfield) $sortfield='p.datep';
|
||||
|
||||
$sql = 'SELECT '.$db->pdate('p.datep').' as dp, p.amount, f.amount as fa_amount, f.facnumber';
|
||||
$sql .=', f.rowid as facid, c.libelle as paiement_type, p.num_paiement';
|
||||
$sql .= ' FROM '.MAIN_DB_PREFIX.'paiement as p, '.MAIN_DB_PREFIX.'facture as f, '.MAIN_DB_PREFIX.'c_paiement as c';
|
||||
$sql .= ' WHERE p.fk_facture = f.rowid AND p.fk_paiement = c.id';
|
||||
|
||||
if ($socidp)
|
||||
{
|
||||
$objp = $db->fetch_object($resql);
|
||||
$var=!$var;
|
||||
print "<tr $bc[$var]>";
|
||||
print "<td><a href=\"facture.php?facid=$objp->facid\">$objp->facnumber</a></td>\n";
|
||||
print "<td>".strftime("%d %B %Y",$objp->dp)."</td>\n";
|
||||
print "<td>$objp->paiement_type $objp->num_paiement</td>\n";
|
||||
print '<td align="right">'.price($objp->amount).'</td><td> </td>';
|
||||
print "</tr>";
|
||||
$i++;
|
||||
$sql .= ' AND f.fk_soc = '.$socidp;
|
||||
}
|
||||
|
||||
$sql .= ' ORDER BY '.$sortfield.' '.$sortorder;
|
||||
$sql .= $db->plimit( $limit +1 ,$offset);
|
||||
$resql = $db->query($sql);
|
||||
|
||||
if ($resql)
|
||||
{
|
||||
$num = $db->num_rows($resql);
|
||||
$i = 0;
|
||||
$var=True;
|
||||
|
||||
print_barre_liste($langs->trans('Payments'), $page, 'paiement.php','',$sortfield,$sortorder,'',$num);
|
||||
print '<table class="noborder" width="100%">';
|
||||
print '<tr class="liste_titre">';
|
||||
print_liste_field_titre($langs->trans('Bill'),'paiement.php','facnumber','','','',$sortfield);
|
||||
print_liste_field_titre($langs->trans('Date'),'paiement.php','dp','','','',$sortfield);
|
||||
print_liste_field_titre($langs->trans('Type'),'paiement.php','libelle','','','',$sortfield);
|
||||
print_liste_field_titre($langs->trans('Amount'),'paiement.php','fa_amount','','','align="right"',$sortfield);
|
||||
print '<td> </td>';
|
||||
print "</tr>\n";
|
||||
|
||||
while ($i < min($num,$limit))
|
||||
{
|
||||
$objp = $db->fetch_object($resql);
|
||||
$var=!$var;
|
||||
print '<tr '.$bc[$var].'>';
|
||||
print '<td><a href="facture.php?facid='.$objp->facid.'">'.$objp->facnumber."</a></td>\n";
|
||||
print '<td>'.dolibarr_print_date($objp->dp)."</td>\n";
|
||||
print '<td>'.$objp->paiement_type.' '.$objp->num_paiement."</td>\n";
|
||||
print '<td align="right">'.price($objp->amount).'</td><td> </td>';
|
||||
print '</tr>';
|
||||
$i++;
|
||||
}
|
||||
print '</table>';
|
||||
}
|
||||
print "</table>";
|
||||
}
|
||||
}
|
||||
|
||||
$db->close();
|
||||
|
||||
llxFooter("<em>Dernière modification $Date$ révision $Revision$</em>");
|
||||
llxFooter('<em>Dernière modification $Date$ révision $Revision$</em>');
|
||||
?>
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
/* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2004-2005 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
|
||||
*
|
||||
* 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
|
||||
@ -27,36 +28,54 @@
|
||||
\version $Revision$
|
||||
*/
|
||||
|
||||
require("./pre.inc.php");
|
||||
require_once(DOL_DOCUMENT_ROOT."/paiement.class.php");
|
||||
require_once(DOL_DOCUMENT_ROOT."/facture.class.php");
|
||||
require('./pre.inc.php');
|
||||
require_once(DOL_DOCUMENT_ROOT.'/paiement.class.php');
|
||||
require_once(DOL_DOCUMENT_ROOT.'/facture.class.php');
|
||||
|
||||
$user->getrights('facture');
|
||||
|
||||
$langs->load("bills");
|
||||
$langs->load("banks");
|
||||
$langs->load("companies");
|
||||
$langs->load('bills');
|
||||
$langs->load('banks');
|
||||
$langs->load('companies');
|
||||
|
||||
|
||||
|
||||
if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == 'yes' && $user->rights->facture->creer)
|
||||
if ($_POST['action'] == 'confirm_delete' && $_POST['confirm'] == 'yes' && $user->rights->facture->creer)
|
||||
{
|
||||
$paiement = new Paiement($db);
|
||||
$paiement->id = $_GET["id"];
|
||||
if ( $paiement->delete() )
|
||||
{
|
||||
Header("Location: liste.php");
|
||||
}
|
||||
$paiement = new Paiement($db);
|
||||
$paiement->fetch($_GET['id']);
|
||||
$bank_line_id = $paiement->bank_line;
|
||||
$deleted = $paiement->delete();
|
||||
if ($deleted)
|
||||
{
|
||||
// Supprimer l'écriture bancaire
|
||||
if (!empty($bank_line_id))
|
||||
{
|
||||
$acc = new Account($db);
|
||||
$acc->deleteline($bank_line_id);
|
||||
Header('Location: liste.php');
|
||||
}
|
||||
else
|
||||
{
|
||||
print 'bank_line_id='.$bank_line_id;
|
||||
exit;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print 'deleted='.$deleted;
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
if ($_POST["action"] == 'confirm_valide' && $_POST["confirm"] == 'yes' && $user->rights->facture->creer)
|
||||
if ($_POST['action'] == 'confirm_valide' && $_POST['confirm'] == 'yes' && $user->rights->facture->creer)
|
||||
{
|
||||
$paiement = new Paiement($db);
|
||||
$paiement->id = $_GET["id"];
|
||||
if ( $paiement->valide() == 0 )
|
||||
{
|
||||
Header("Location: fiche.php?id=".$paiement->id);
|
||||
}
|
||||
$paiement = new Paiement($db);
|
||||
$paiement->id = $_GET['id'];
|
||||
if ( $paiement->valide() == 0 )
|
||||
{
|
||||
Header('Location: fiche.php?id='.$paiement->id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -69,8 +88,8 @@ llxHeader();
|
||||
|
||||
|
||||
print '<div class="tabs">';
|
||||
print '<a href="fiche.php?id='.$_GET["id"].'" id="active" class="tab">'.$langs->trans("Payment").'</a>';
|
||||
print '<a class="tab" href="info.php?id='.$_GET["id"].'">'.$langs->trans("Info").'</a>';
|
||||
print '<a href="fiche.php?id='.$_GET['id'].'" id="active" class="tab">'.$langs->trans('Payment').'</a>';
|
||||
print '<a class="tab" href="info.php?id='.$_GET['id'].'">'.$langs->trans('Info').'</a>';
|
||||
print '</div>';
|
||||
|
||||
print '<div class="tabBar">';
|
||||
@ -81,43 +100,47 @@ print '<div class="tabBar">';
|
||||
*/
|
||||
|
||||
$paiement = new Paiement($db);
|
||||
$paiement->fetch($_GET["id"]);
|
||||
$paiement->fetch($_GET['id']);
|
||||
$html = new Form($db);
|
||||
|
||||
/*
|
||||
* Confirmation de la suppression du paiement
|
||||
*/
|
||||
if ($_GET["action"] == 'delete')
|
||||
if ($_GET['action'] == 'delete')
|
||||
{
|
||||
$html->form_confirm("fiche.php?id=$paiement->id","Supprimer le paiement","Etes-vous sûr de vouloir supprimer ce paiement ?","confirm_delete");
|
||||
print '<br>';
|
||||
$html->form_confirm('fiche.php?id='.$paiement->id, 'Supprimer le paiement', 'Etes-vous sûr de vouloir supprimer ce paiement ?', 'confirm_delete');
|
||||
print '<br>';
|
||||
}
|
||||
|
||||
/*
|
||||
* Confirmation de la validation du paiement
|
||||
*/
|
||||
if ($_GET["action"] == 'valide')
|
||||
if ($_GET['action'] == 'valide')
|
||||
{
|
||||
$html->form_confirm("fiche.php?id=$paiement->id","Valider le paiement","Etes-vous sûr de vouloir valider ce paiment, auncune modification n'est possible une fois le paiement validé ?","confirm_valide");
|
||||
print '<br>';
|
||||
$html->form_confirm('fiche.php?id='.$paiement->id, 'Valider le paiement', 'Etes-vous sûr de vouloir valider ce paiment, auncune modification n\'est possible une fois le paiement validé ?', 'confirm_valide');
|
||||
print '<br>';
|
||||
}
|
||||
|
||||
print '<table class="border" width="100%">';
|
||||
|
||||
print '<tr><td valign="top" width="140">'.$langs->trans("Ref").'</td><td>'.$paiement->id.'</td></tr>';
|
||||
if ($paiement->bank_account) {
|
||||
// Si compte renseigné, on affiche libelle
|
||||
print '<tr><td valign="top" width="140">';
|
||||
$bank=new Account($db);
|
||||
$bank->fetch($paiement->bank_account);
|
||||
print $langs->trans("BankAccount").'</td><td><a href="'.DOL_URL_ROOT.'/compta/bank/account.php?account='.$bank->id.'">'.$bank->label.'</a></td></tr>';
|
||||
print '<tr><td valign="top" width="140">'.$langs->trans('Ref').'</td><td>'.$paiement->id.'</td></tr>';
|
||||
if ($paiement->bank_account)
|
||||
{
|
||||
// Si compte renseigné, on affiche libelle
|
||||
print '<tr><td valign="top" width="140">';
|
||||
$bank=new Account($db);
|
||||
$bank->fetch($paiement->bank_account);
|
||||
print $langs->trans('BankAccount').'</td><td><a href="'.DOL_URL_ROOT.'/compta/bank/account.php?account='.$bank->id.'">'.$bank->label.'</a></td></tr>';
|
||||
}
|
||||
print '<tr><td valign="top" width="140">'.$langs->trans("Date").'</td><td>'.dolibarr_print_date($paiement->date).'</td></tr>';
|
||||
print '<tr><td valign="top">'.$langs->trans("Type").'</td><td>'.$paiement->type_libelle.'</td></tr>';
|
||||
if ($paiement->numero) { print '<tr><td valign="top">'.$langs->trans("Numero").'</td><td>'.$paiement->numero.'</td></tr>'; }
|
||||
print '<tr><td valign="top">'.$langs->trans("Amount").'</td><td>'.$paiement->montant." ".$langs->trans("Currency".$conf->monnaie).'</td></tr>';
|
||||
print '<tr><td valign="top">'.$langs->trans("Note").'</td><td>'.nl2br($paiement->note).'</td></tr>';
|
||||
print "</table>";
|
||||
print '<tr><td valign="top" width="140">'.$langs->trans('Date').'</td><td>'.dolibarr_print_date($paiement->date).'</td></tr>';
|
||||
print '<tr><td valign="top">'.$langs->trans('Type').'</td><td>'.$paiement->type_libelle.'</td></tr>';
|
||||
if ($paiement->numero)
|
||||
{
|
||||
print '<tr><td valign="top">'.$langs->trans('Numero').'</td><td>'.$paiement->numero.'</td></tr>';
|
||||
}
|
||||
print '<tr><td valign="top">'.$langs->trans('Amount').'</td><td>'.price($paiement->montant).' '.$langs->trans('Currency'.$conf->monnaie).'</td></tr>';
|
||||
print '<tr><td valign="top">'.$langs->trans('Note').'</td><td>'.nl2br($paiement->note).'</td></tr>';
|
||||
print '</table>';
|
||||
|
||||
|
||||
/*
|
||||
@ -125,59 +148,59 @@ print "</table>";
|
||||
*
|
||||
*/
|
||||
$allow_delete = 1 ;
|
||||
$sql = "SELECT f.facnumber, f.total_ttc, pf.amount, f.rowid as facid, f.paye, f.fk_statut, s.nom, s.idp";
|
||||
$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 AND f.fk_soc = s.idp";
|
||||
$sql .= " AND pf.fk_paiement = ".$paiement->id;
|
||||
$sql = 'SELECT f.facnumber, f.total_ttc, pf.amount, f.rowid as facid, f.paye, f.fk_statut, s.nom, s.idp';
|
||||
$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 AND f.fk_soc = s.idp';
|
||||
$sql .= ' AND pf.fk_paiement = '.$paiement->id;
|
||||
|
||||
if ($db->query($sql))
|
||||
{
|
||||
$num = $db->num_rows();
|
||||
$num = $db->num_rows();
|
||||
|
||||
$i = 0;
|
||||
$total = 0;
|
||||
print '<br><table class="noborder" width="100%">';
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td>'.$langs->trans("Bill").'</td><td>'.$langs->trans("Company").'</td>';
|
||||
print '<td align="right">'.$langs->trans("AmountTTC").'</td><td align="center">'.$langs->trans("Status").'</td>';
|
||||
print "</tr>\n";
|
||||
$i = 0;
|
||||
$total = 0;
|
||||
print '<br><table class="noborder" width="100%">';
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td>'.$langs->trans('Bill').'</td><td>'.$langs->trans('Company').'</td>';
|
||||
print '<td align="right">'.$langs->trans('AmountTTC').'</td><td align="center">'.$langs->trans('Status').'</td>';
|
||||
print "</tr>\n";
|
||||
|
||||
if ($num > 0)
|
||||
{
|
||||
$var=True;
|
||||
|
||||
while ($i < $num)
|
||||
if ($num > 0)
|
||||
{
|
||||
$objp = $db->fetch_object();
|
||||
$var=!$var;
|
||||
|
||||
print "<tr $bc[$var]>";
|
||||
print '<td><a href="'.DOL_URL_ROOT.'/compta/facture.php?facid='.$objp->facid.'">'.img_object($langs->trans("ShowBill"),"bill").' ';
|
||||
print $objp->facnumber;
|
||||
print "</a></td>\n";
|
||||
print '<td><a href="'.DOL_URL_ROOT.'/compta/fiche.php?socid='.$objp->idp.'">'.img_object($langs->trans("ShowCompany"),"company").' '.$objp->nom.'</a></td>';
|
||||
print '<td align="right">'.price($objp->amount).'</td>';
|
||||
$fac=new Facture($db);
|
||||
print '<td align="center">'.$fac->LibStatut($objp->paye,$objp->fk_statut).'</td>';
|
||||
print "</tr>\n";
|
||||
if ($objp->paye == 1)
|
||||
{
|
||||
$allow_delete = 0;
|
||||
}
|
||||
$total = $total + $objp->amount;
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
$var=!$var;
|
||||
$var=True;
|
||||
|
||||
while ($i < $num)
|
||||
{
|
||||
$objp = $db->fetch_object();
|
||||
$var=!$var;
|
||||
print '<tr '.$bc[$var].'>';
|
||||
print '<td><a href="'.DOL_URL_ROOT.'/compta/facture.php?facid='.$objp->facid.'">'.img_object($langs->trans('ShowBill'),'bill').' ';
|
||||
print $objp->facnumber;
|
||||
print "</a></td>\n";
|
||||
print '<td><a href="'.DOL_URL_ROOT.'/compta/fiche.php?socid='.$objp->idp.'">'.img_object($langs->trans('ShowCompany'),'company').' '.$objp->nom.'</a></td>';
|
||||
print '<td align="right">'.price($objp->amount).'</td>';
|
||||
$fac=new Facture($db);
|
||||
print '<td align="center">'.$fac->LibStatut($objp->paye,$objp->fk_statut).'</td>';
|
||||
print "</tr>\n";
|
||||
if ($objp->paye == 1)
|
||||
{
|
||||
$allow_delete = 0;
|
||||
}
|
||||
$total = $total + $objp->amount;
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
$var=!$var;
|
||||
|
||||
print "</table>\n";
|
||||
$db->free();
|
||||
print "</table>\n";
|
||||
$db->free();
|
||||
}
|
||||
else {
|
||||
dolibarr_print_error($db);
|
||||
else
|
||||
{
|
||||
dolibarr_print_error($db);
|
||||
}
|
||||
|
||||
print "</div>";
|
||||
print '</div>';
|
||||
|
||||
|
||||
/*
|
||||
@ -186,17 +209,17 @@ print "</div>";
|
||||
|
||||
print '<div class="tabsAction">';
|
||||
|
||||
if ($user->societe_id == 0 && $paiement->statut == 0 && $_GET["action"] == '')
|
||||
if ($user->societe_id == 0 && $paiement->statut == 0 && $_GET['action'] == '')
|
||||
{
|
||||
print '<a class="tabAction" href="fiche.php?id='.$_GET["id"].'&action=valide">'.$langs->trans("Valid").'</a>';
|
||||
print '<a class="tabAction" href="fiche.php?id='.$_GET['id'].'&action=valide">'.$langs->trans('Valid').'</a>';
|
||||
}
|
||||
|
||||
if ($user->societe_id == 0 && $allow_delete && $paiement->statut == 0 && $_GET["action"] == '')
|
||||
if ($user->societe_id == 0 && $allow_delete && $paiement->statut == 0 && $_GET['action'] == '')
|
||||
{
|
||||
print '<a class="butDelete" href="fiche.php?id='.$_GET["id"].'&action=delete">'.$langs->trans("Delete").'</a>';
|
||||
print '<a class="butDelete" href="fiche.php?id='.$_GET['id'].'&action=delete">'.$langs->trans('Delete').'</a>';
|
||||
|
||||
}
|
||||
print "</div>";
|
||||
print '</div>';
|
||||
|
||||
$db->close();
|
||||
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
/* Copyright (C) 2002-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2004-2005 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
/* Copyright (C) 2002-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2004-2005 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
|
||||
*
|
||||
* 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
|
||||
@ -33,162 +34,154 @@
|
||||
\brief Classe permettant la gestion des paiements des factures clients
|
||||
*/
|
||||
|
||||
class Paiement
|
||||
class Paiement
|
||||
{
|
||||
var $id;
|
||||
var $db;
|
||||
var $facid;
|
||||
var $datepaye;
|
||||
var $amount;
|
||||
var $author;
|
||||
var $paiementid; // Type de paiement. Stocké dans fk_paiement
|
||||
// de llx_paiement qui est lié aux types de
|
||||
//paiement de llx_c_paiement
|
||||
var $num_paiement; // Numéro du CHQ, VIR, etc...
|
||||
var $bank_account; // Id compte bancaire du paiement
|
||||
var $note;
|
||||
// fk_paiement dans llx_paiement est l'id du type de paiement (7 pour CHQ, ...)
|
||||
// fk_paiement dans llx_paiement_facture est le rowid du paiement
|
||||
var $id;
|
||||
var $db;
|
||||
var $facid;
|
||||
var $datepaye;
|
||||
var $amount;
|
||||
var $author;
|
||||
var $paiementid; // Type de paiement. Stocké dans fk_paiement
|
||||
// de llx_paiement qui est lié aux types de
|
||||
//paiement de llx_c_paiement
|
||||
var $num_paiement; // Numéro du CHQ, VIR, etc...
|
||||
var $bank_account; // Id compte bancaire du paiement
|
||||
var $bank_line; // Id de la ligne d'écriture bancaire
|
||||
var $note;
|
||||
// fk_paiement dans llx_paiement est l'id du type de paiement (7 pour CHQ, ...)
|
||||
// fk_paiement dans llx_paiement_facture est le rowid du paiement
|
||||
|
||||
|
||||
/**
|
||||
* \brief Constructeur de la classe
|
||||
* \param DB handler accès base de données
|
||||
* \param soc_idp id societe ("" par defaut)
|
||||
* \param soc_idp id societe ('' par defaut)
|
||||
*/
|
||||
|
||||
function Paiement($DB, $soc_idp="")
|
||||
{
|
||||
$this->db = $DB ;
|
||||
}
|
||||
|
||||
function Paiement($DB, $soc_idp='')
|
||||
{
|
||||
$this->db = $DB ;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Récupère l'objet paiement
|
||||
* \param id id du paiement a récupérer
|
||||
*/
|
||||
|
||||
function fetch($id)
|
||||
{
|
||||
$sql = "SELECT p.rowid,".$this->db->pdate("p.datep")." as dp, p.amount, p.statut";
|
||||
$sql .=", c.libelle as paiement_type";
|
||||
$sql .= ", p.num_paiement, p.note, b.fk_account";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."paiement as p, ".MAIN_DB_PREFIX."c_paiement as c ";
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON p.fk_bank = b.rowid ";
|
||||
$sql .= " WHERE p.fk_paiement = c.id";
|
||||
$sql .= " AND p.rowid = ".$id;
|
||||
|
||||
if ($this->db->query($sql))
|
||||
function fetch($id)
|
||||
{
|
||||
if ($this->db->num_rows())
|
||||
{
|
||||
$obj = $this->db->fetch_object();
|
||||
$sql = 'SELECT p.rowid,'.$this->db->pdate('p.datep').' as dp, p.amount, p.statut, p.fk_bank';
|
||||
$sql .=', c.libelle as paiement_type';
|
||||
$sql .= ', p.num_paiement, p.note, b.fk_account';
|
||||
$sql .= ' FROM '.MAIN_DB_PREFIX.'paiement as p, '.MAIN_DB_PREFIX.'c_paiement as c ';
|
||||
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid ';
|
||||
$sql .= ' WHERE p.fk_paiement = c.id';
|
||||
$sql .= ' AND p.rowid = '.$id;
|
||||
|
||||
$this->id = $obj->rowid;
|
||||
$this->date = $obj->dp;
|
||||
$this->numero = $obj->num_paiement;
|
||||
$this->bank_account = $obj->fk_account;
|
||||
|
||||
$this->montant = $obj->amount;
|
||||
$this->note = $obj->note;
|
||||
$this->type_libelle = $obj->paiement_type;
|
||||
$this->statut = $obj->statut;
|
||||
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
$this->db->free();
|
||||
if ($this->db->query($sql))
|
||||
{
|
||||
if ($this->db->num_rows())
|
||||
{
|
||||
$obj = $this->db->fetch_object();
|
||||
$this->id = $obj->rowid;
|
||||
$this->date = $obj->dp;
|
||||
$this->numero = $obj->num_paiement;
|
||||
$this->bank_account = $obj->fk_account;
|
||||
$this->bank_line = $obj->fk_bank;
|
||||
$this->montant = $obj->amount;
|
||||
$this->note = $obj->note;
|
||||
$this->type_libelle = $obj->paiement_type;
|
||||
$this->statut = $obj->statut;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
$this->db->free();
|
||||
}
|
||||
else
|
||||
{
|
||||
dolibarr_print_error($this->db);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dolibarr_print_error($this->db);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Création du paiement en base
|
||||
* \param user object utilisateur qui crée
|
||||
* \return int id du paiement crée, < 0 si erreur
|
||||
*/
|
||||
|
||||
function create($user)
|
||||
{
|
||||
$total = 0;
|
||||
$sql_err = 0;
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
foreach ($this->amounts as $key => $value)
|
||||
{
|
||||
$facid = $key;
|
||||
$value = trim($value);
|
||||
$amount = ereg_replace(",",".",round($value, 2));
|
||||
|
||||
if (is_numeric($amount))
|
||||
{
|
||||
$total += $amount;
|
||||
}
|
||||
}
|
||||
|
||||
$total = ereg_replace(",",".",$total);
|
||||
|
||||
if ($total <> 0) /* On accepte les montants négatifs pour les rejets de prélèvement */
|
||||
{
|
||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."paiement (datec, datep, amount, fk_paiement, num_paiement, note, fk_user_creat)";
|
||||
$sql .= " VALUES (now(), $this->datepaye, '$total', $this->paiementid, '$this->num_paiement', '$this->note', $user->id)";
|
||||
|
||||
if ( $this->db->query($sql) )
|
||||
{
|
||||
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."paiement");
|
||||
|
||||
foreach ($this->amounts as $key => $value)
|
||||
{
|
||||
$facid = $key;
|
||||
$value = trim($value);
|
||||
$amount = ereg_replace(",",".",round($value, 2));
|
||||
|
||||
if (is_numeric($amount) && $amount <> 0)
|
||||
{
|
||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."paiement_facture (fk_facture, fk_paiement, amount)";
|
||||
$sql .= " VALUES ('".$facid."','". $this->id."','". $amount."')";
|
||||
|
||||
if (! $this->db->query($sql) )
|
||||
{
|
||||
dolibarr_syslog("Paiement::Create Erreur INSERT dans paiement_facture ".$facid);
|
||||
$sql_err++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dolibarr_syslog("Paiement::Create Montant non numérique");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
dolibarr_syslog("Paiement::Create Erreur INSERT dans paiement");
|
||||
$sql_err++;
|
||||
}
|
||||
}
|
||||
|
||||
if ( $total <> 0 && $sql_err == 0 ) // On accepte les montants négatifs
|
||||
{
|
||||
$this->db->commit();
|
||||
dolibarr_syslog("Paiement::Create Ok Total = $total");
|
||||
return $this->id;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->rollback();
|
||||
dolibarr_syslog("Paiement::Create Erreur");
|
||||
return -1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function create($user)
|
||||
{
|
||||
$sql_err = 0;
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
$total = 0.0;
|
||||
foreach ($this->amounts as $key => $value)
|
||||
{
|
||||
$val = $value;
|
||||
$val = str_replace(' ','',$val);
|
||||
$val = str_replace(',','.',$val);
|
||||
$val = round($val, 2);
|
||||
$val = str_replace(',','.',$val);
|
||||
if (is_numeric($val))
|
||||
{
|
||||
$total += $val;
|
||||
}
|
||||
$this->amounts[$key] = $val;
|
||||
}
|
||||
$total = str_replace(',','.',$total);
|
||||
if ($total <> 0) /* On accepte les montants négatifs pour les rejets de prélèvement */
|
||||
{
|
||||
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'paiement (datec, datep, amount, fk_paiement, num_paiement, note, fk_user_creat)';
|
||||
$sql .= ' VALUES (now(), '.$this->datepaye.', \''.$total.'\', '.$this->paiementid.', \''.$this->num_paiement.'\', \''.$this->note.'\', '.$user->id.')';
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'paiement');
|
||||
foreach ($this->amounts as $key => $amount)
|
||||
{
|
||||
$facid = $key;
|
||||
if (is_numeric($amount) && $amount <> 0)
|
||||
{
|
||||
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'paiement_facture (fk_facture, fk_paiement, amount)';
|
||||
$sql .= ' VALUES ('.$facid.','. $this->id.',\''.$amount.'\')';
|
||||
if (! $this->db->query($sql) )
|
||||
{
|
||||
dolibarr_syslog('Paiement::Create Erreur INSERT dans paiement_facture '.$facid);
|
||||
$sql_err++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dolibarr_syslog('Paiement::Create Montant non numérique');
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dolibarr_syslog('Paiement::Create Erreur INSERT dans paiement');
|
||||
$sql_err++;
|
||||
}
|
||||
}
|
||||
|
||||
if ( $total <> 0 && $sql_err == 0 ) // On accepte les montants négatifs
|
||||
{
|
||||
$this->db->commit();
|
||||
dolibarr_syslog('Paiement::Create Ok Total = '.$total);
|
||||
return $this->id;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->rollback();
|
||||
dolibarr_syslog('Paiement::Create Erreur');
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Affiche la liste des modes de paiement possible
|
||||
@ -196,134 +189,128 @@ class Paiement
|
||||
* \param filtre filtre sur un sens de paiement particulier, norme ISO (CRDT=Mode propre à un crédit, DBIT=mode propre à un débit)
|
||||
* \param id ???
|
||||
*/
|
||||
function select($name, $filtre='', $id='')
|
||||
{
|
||||
$form = new Form($this->db);
|
||||
function select($name, $filtre='', $id='')
|
||||
{
|
||||
$form = new Form($this->db);
|
||||
|
||||
if ($filtre == 'CRDT')
|
||||
{
|
||||
$sql = "SELECT id, libelle FROM ".MAIN_DB_PREFIX."c_paiement WHERE active=1 AND type IN (0,2) ORDER BY libelle";
|
||||
}
|
||||
elseif ($filtre == 'DBIT')
|
||||
{
|
||||
$sql = "SELECT id, libelle FROM ".MAIN_DB_PREFIX."c_paiement WHERE active=1 AND type IN (1,2) ORDER BY libelle";
|
||||
}
|
||||
else
|
||||
{
|
||||
$sql = "SELECT id, libelle FROM ".MAIN_DB_PREFIX."c_paiement WHERE active=1 ORDER BY libelle";
|
||||
}
|
||||
$form->select($name, $sql, $id);
|
||||
}
|
||||
if ($filtre == 'CRDT')
|
||||
{
|
||||
$sql = 'SELECT id, libelle FROM '.MAIN_DB_PREFIX.'c_paiement WHERE active=1 AND type IN (0,2) ORDER BY libelle';
|
||||
}
|
||||
elseif ($filtre == 'DBIT')
|
||||
{
|
||||
$sql = 'SELECT id, libelle FROM '.MAIN_DB_PREFIX.'c_paiement WHERE active=1 AND type IN (1,2) ORDER BY libelle';
|
||||
}
|
||||
else
|
||||
{
|
||||
$sql = 'SELECT id, libelle FROM '.MAIN_DB_PREFIX.'c_paiement WHERE active=1 ORDER BY libelle';
|
||||
}
|
||||
$form->select($name, $sql, $id);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
function delete()
|
||||
{
|
||||
$sql = "DELETE FROM llx_paiement_facture WHERE fk_paiement = ".$this->id;
|
||||
|
||||
$result = $this->db->query($sql);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."paiement WHERE rowid = ".$this->id;
|
||||
|
||||
$result = $this->db->query($sql);
|
||||
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
dolibarr_print_error($this->db);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function delete()
|
||||
{
|
||||
$this->db->begin();
|
||||
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'paiement_facture WHERE fk_paiement = '.$this->id;
|
||||
$result = $this->db->query($sql);
|
||||
if ($result)
|
||||
{
|
||||
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'paiement WHERE rowid = '.$this->id;
|
||||
$result = $this->db->query($sql);
|
||||
$this->db->commit();
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
dolibarr_print_error($this->db);
|
||||
$this->db->rollback();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Mise a jour du lien entre le paiement et la ligne générée dans llx_bank
|
||||
*
|
||||
*/
|
||||
|
||||
function update_fk_bank($id_bank)
|
||||
{
|
||||
$sql = "UPDATE llx_paiement set fk_bank = ".$id_bank." where rowid = ".$this->id;
|
||||
$result = $this->db->query($sql);
|
||||
if ($result)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
dolibarr_print_error($this->db);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
function update_fk_bank($id_bank)
|
||||
{
|
||||
$sql = 'UPDATE llx_paiement set fk_bank = '.$id_bank.' where rowid = '.$this->id;
|
||||
$result = $this->db->query($sql);
|
||||
if ($result)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
dolibarr_print_error($this->db);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Valide le paiement
|
||||
*/
|
||||
function valide()
|
||||
{
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."paiement SET statut = 1 WHERE rowid = ".$this->id;
|
||||
$result = $this->db->query($sql);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
dolibarr_syslog("Paiement::Valide Error -1");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
function valide()
|
||||
{
|
||||
$sql = 'UPDATE '.MAIN_DB_PREFIX.'paiement SET statut = 1 WHERE rowid = '.$this->id;
|
||||
$result = $this->db->query($sql);
|
||||
if ($result)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
dolibarr_syslog('Paiement::Valide Error -1');
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* \brief Information sur l'objet
|
||||
* \param id id du paiement dont il faut afficher les infos
|
||||
*/
|
||||
|
||||
function info($id)
|
||||
{
|
||||
$sql = "SELECT c.rowid, ".$this->db->pdate("datec")." as datec, fk_user_creat, fk_user_modif";
|
||||
$sql .= ", ".$this->db->pdate("tms")." as tms";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."paiement as c";
|
||||
$sql .= " WHERE c.rowid = $id";
|
||||
|
||||
if ($this->db->query($sql))
|
||||
|
||||
function info($id)
|
||||
{
|
||||
if ($this->db->num_rows())
|
||||
{
|
||||
$obj = $this->db->fetch_object();
|
||||
|
||||
$this->id = $obj->idp;
|
||||
|
||||
if ($obj->fk_user_creat) {
|
||||
$cuser = new User($this->db, $obj->fk_user_creat);
|
||||
$cuser->fetch();
|
||||
$this->user_creation = $cuser;
|
||||
}
|
||||
|
||||
if ($obj->fk_user_modif) {
|
||||
$muser = new User($this->db, $obj->fk_user_modif);
|
||||
$muser->fetch();
|
||||
$this->user_modification = $muser;
|
||||
}
|
||||
|
||||
$this->date_creation = $obj->datec;
|
||||
$this->date_modification = $obj->tms;
|
||||
|
||||
}
|
||||
$this->db->free();
|
||||
$sql = 'SELECT c.rowid, '.$this->db->pdate('datec').' as datec, fk_user_creat, fk_user_modif';
|
||||
$sql .= ', '.$this->db->pdate('tms').' as tms';
|
||||
$sql .= ' FROM '.MAIN_DB_PREFIX.'paiement as c';
|
||||
$sql .= ' WHERE c.rowid = '.$id;
|
||||
|
||||
if ($this->db->query($sql))
|
||||
{
|
||||
if ($this->db->num_rows())
|
||||
{
|
||||
$obj = $this->db->fetch_object();
|
||||
$this->id = $obj->idp;
|
||||
if ($obj->fk_user_creat)
|
||||
{
|
||||
$cuser = new User($this->db, $obj->fk_user_creat);
|
||||
$cuser->fetch();
|
||||
$this->user_creation = $cuser;
|
||||
}
|
||||
if ($obj->fk_user_modif)
|
||||
{
|
||||
$muser = new User($this->db, $obj->fk_user_modif);
|
||||
$muser->fetch();
|
||||
$this->user_modification = $muser;
|
||||
}
|
||||
$this->date_creation = $obj->datec;
|
||||
$this->date_modification = $obj->tms;
|
||||
}
|
||||
$this->db->free();
|
||||
}
|
||||
else
|
||||
{
|
||||
dolibarr_print_error($this->db);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dolibarr_print_error($this->db);
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user