2004-10-20 23:06:45 +02:00
|
|
|
|
<?php
|
2005-10-05 03:48:00 +02:00
|
|
|
|
/* Copyright (C) 2002-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
2006-04-08 14:52:30 +02:00
|
|
|
|
* Copyright (C) 2004-2006 Laurent Destailleur <eldy@users.sourceforge.net>
|
2005-10-05 03:48:00 +02:00
|
|
|
|
* Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
|
2002-12-19 15:41:37 +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 2 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, write to the Free Software
|
|
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2005-04-15 23:57:04 +02:00
|
|
|
|
/**
|
|
|
|
|
|
\file htdocs/paiement.class.php
|
2005-01-09 21:20:46 +01:00
|
|
|
|
\ingroup facture
|
|
|
|
|
|
\brief Fichier de la classe des paiement de factures clients
|
2006-04-08 14:52:30 +02:00
|
|
|
|
\remarks Cette classe est presque identique <EFBFBD> paiementfourn.class.php
|
2008-01-25 21:25:44 +01:00
|
|
|
|
\version $Id$
|
2004-09-14 22:53:49 +02:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-01-09 21:20:46 +01:00
|
|
|
|
/** \class Paiement
|
|
|
|
|
|
\brief Classe permettant la gestion des paiements des factures clients
|
2004-09-14 22:53:49 +02:00
|
|
|
|
*/
|
|
|
|
|
|
|
2005-10-05 03:48:00 +02:00
|
|
|
|
class Paiement
|
2002-12-19 15:41:37 +01:00
|
|
|
|
{
|
2005-10-05 03:48:00 +02:00
|
|
|
|
var $id;
|
2005-10-15 17:32:01 +02:00
|
|
|
|
var $ref;
|
2005-10-05 03:48:00 +02:00
|
|
|
|
var $facid;
|
|
|
|
|
|
var $datepaye;
|
|
|
|
|
|
var $amount;
|
2006-04-08 14:52:30 +02:00
|
|
|
|
var $total;
|
2005-10-05 03:48:00 +02:00
|
|
|
|
var $author;
|
|
|
|
|
|
var $paiementid; // Type de paiement. Stock<63> dans fk_paiement
|
|
|
|
|
|
// de llx_paiement qui est li<6C> aux types de
|
|
|
|
|
|
//paiement de llx_c_paiement
|
|
|
|
|
|
var $num_paiement; // Num<75>ro du CHQ, VIR, etc...
|
|
|
|
|
|
var $bank_account; // Id compte bancaire du paiement
|
|
|
|
|
|
var $bank_line; // Id de la ligne d'<27>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
|
2004-02-28 21:50:27 +01:00
|
|
|
|
|
2005-10-15 17:32:01 +02:00
|
|
|
|
var $db;
|
2004-09-14 22:53:49 +02:00
|
|
|
|
|
2005-10-05 03:48:00 +02:00
|
|
|
|
|
2006-04-08 14:52:30 +02:00
|
|
|
|
/**
|
|
|
|
|
|
* \brief Constructeur de la classe
|
|
|
|
|
|
* \param DB handler acc<EFBFBD>s base de donn<EFBFBD>es
|
|
|
|
|
|
*/
|
|
|
|
|
|
function Paiement($DB)
|
2005-10-05 03:48:00 +02:00
|
|
|
|
{
|
|
|
|
|
|
$this->db = $DB ;
|
|
|
|
|
|
}
|
2004-09-14 22:53:49 +02:00
|
|
|
|
|
2005-10-15 17:32:01 +02:00
|
|
|
|
/**
|
|
|
|
|
|
* \brief R<EFBFBD>cup<EFBFBD>re l'objet paiement
|
|
|
|
|
|
* \param id id du paiement a r<EFBFBD>cup<EFBFBD>rer
|
2007-05-24 00:38:46 +02:00
|
|
|
|
* \return int <0 si ko, 0 si non trouv<EFBFBD>, >0 si ok
|
2005-10-15 17:32:01 +02:00
|
|
|
|
*/
|
|
|
|
|
|
function fetch($id)
|
2004-02-09 15:41:41 +01:00
|
|
|
|
{
|
2005-10-05 03:48:00 +02:00
|
|
|
|
$sql = 'SELECT p.rowid,'.$this->db->pdate('p.datep').' as dp, p.amount, p.statut, p.fk_bank';
|
2006-11-10 01:28:39 +01:00
|
|
|
|
$sql.= ', c.code as type_code, c.libelle as type_libelle';
|
|
|
|
|
|
$sql.= ', p.num_paiement, p.note, b.fk_account';
|
|
|
|
|
|
$sql.= ' FROM '.MAIN_DB_PREFIX.'c_paiement as c, '.MAIN_DB_PREFIX.'paiement as p';
|
|
|
|
|
|
$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;
|
2004-02-09 15:41:41 +01:00
|
|
|
|
|
2009-02-20 23:53:15 +01:00
|
|
|
|
dol_syslog("Paiement::fetch sql=".$sql);
|
2007-05-05 16:18:12 +02:00
|
|
|
|
$result = $this->db->query($sql);
|
|
|
|
|
|
|
|
|
|
|
|
if ($result)
|
2005-10-05 03:48:00 +02:00
|
|
|
|
{
|
2007-05-05 16:18:12 +02:00
|
|
|
|
if ($this->db->num_rows($result))
|
2005-10-05 03:48:00 +02:00
|
|
|
|
{
|
2007-05-05 16:18:12 +02:00
|
|
|
|
$obj = $this->db->fetch_object($result);
|
2005-10-05 03:48:00 +02:00
|
|
|
|
$this->id = $obj->rowid;
|
2005-10-15 17:32:01 +02:00
|
|
|
|
$this->ref = $obj->rowid;
|
2005-10-05 03:48:00 +02:00
|
|
|
|
$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;
|
2006-11-10 01:28:39 +01:00
|
|
|
|
$this->type_libelle = $obj->type_libelle;
|
|
|
|
|
|
$this->type_code = $obj->type_code;
|
2005-10-05 03:48:00 +02:00
|
|
|
|
$this->statut = $obj->statut;
|
2007-05-24 00:38:46 +02:00
|
|
|
|
|
|
|
|
|
|
$this->db->free($result);
|
2005-10-05 03:48:00 +02:00
|
|
|
|
return 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2007-05-24 00:38:46 +02:00
|
|
|
|
$this->db->free($result);
|
|
|
|
|
|
return 0;
|
2005-10-05 03:48:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2009-02-20 23:53:15 +01:00
|
|
|
|
dol_print_error($this->db);
|
2005-10-15 17:32:01 +02:00
|
|
|
|
return -1;
|
2005-10-05 03:48:00 +02:00
|
|
|
|
}
|
2004-02-09 15:41:41 +01:00
|
|
|
|
}
|
2004-09-14 22:53:49 +02:00
|
|
|
|
|
2006-04-08 14:52:30 +02:00
|
|
|
|
/**
|
|
|
|
|
|
* \brief Cr<EFBFBD>ation du paiement en base
|
|
|
|
|
|
* \param user object utilisateur qui cr<EFBFBD>e
|
|
|
|
|
|
* \return int id du paiement cr<EFBFBD>e, < 0 si erreur
|
|
|
|
|
|
*/
|
2005-10-05 03:48:00 +02:00
|
|
|
|
function create($user)
|
|
|
|
|
|
{
|
2008-02-28 21:37:04 +01:00
|
|
|
|
global $langs,$conf;
|
|
|
|
|
|
|
2006-04-08 14:52:30 +02:00
|
|
|
|
$error = 0;
|
2005-10-05 03:48:00 +02:00
|
|
|
|
|
2006-04-08 14:52:30 +02:00
|
|
|
|
// Nettoyage parametres
|
|
|
|
|
|
$this->total = 0;
|
2005-10-05 03:48:00 +02:00
|
|
|
|
foreach ($this->amounts as $key => $value)
|
|
|
|
|
|
{
|
2006-04-11 15:37:54 +02:00
|
|
|
|
$value = price2num($value);
|
2006-04-08 14:52:30 +02:00
|
|
|
|
$val = round($value, 2);
|
2005-10-05 03:48:00 +02:00
|
|
|
|
$this->amounts[$key] = $val;
|
2006-04-08 14:52:30 +02:00
|
|
|
|
$this->total += $val;
|
2005-10-05 03:48:00 +02:00
|
|
|
|
}
|
2006-04-08 14:52:30 +02:00
|
|
|
|
$this->total = price2num($this->total);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->db->begin();
|
|
|
|
|
|
|
|
|
|
|
|
if ($this->total <> 0) // On accepte les montants n<>gatifs pour les rejets de pr<70>l<EFBFBD>vement
|
2005-10-05 03:48:00 +02:00
|
|
|
|
{
|
|
|
|
|
|
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'paiement (datec, datep, amount, fk_paiement, num_paiement, note, fk_user_creat)';
|
2008-08-27 20:53:27 +02:00
|
|
|
|
$sql.= ' VALUES ('.$this->db->idate(mktime()).', '.$this->db->idate($this->datepaye).', \''.$this->total.'\', '.$this->paiementid.', \''.$this->num_paiement.'\', \''.addslashes($this->note).'\', '.$user->id.')';
|
2005-10-05 03:48:00 +02:00
|
|
|
|
$resql = $this->db->query($sql);
|
2007-02-20 16:22:41 +01:00
|
|
|
|
|
2009-02-20 23:53:15 +01:00
|
|
|
|
dol_syslog("Paiement::Create insert paiement sql=".$sql);
|
2005-10-05 03:48:00 +02:00
|
|
|
|
if ($resql)
|
|
|
|
|
|
{
|
|
|
|
|
|
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'paiement');
|
2006-04-08 14:52:30 +02:00
|
|
|
|
|
2007-02-20 16:22:41 +01:00
|
|
|
|
// Insere liens montants / factures
|
2005-10-05 03:48:00 +02:00
|
|
|
|
foreach ($this->amounts as $key => $amount)
|
|
|
|
|
|
{
|
|
|
|
|
|
$facid = $key;
|
|
|
|
|
|
if (is_numeric($amount) && $amount <> 0)
|
|
|
|
|
|
{
|
2006-04-12 12:13:26 +02:00
|
|
|
|
$amount = price2num($amount);
|
2005-10-05 03:48:00 +02:00
|
|
|
|
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'paiement_facture (fk_facture, fk_paiement, amount)';
|
|
|
|
|
|
$sql .= ' VALUES ('.$facid.','. $this->id.',\''.$amount.'\')';
|
2007-02-20 16:22:41 +01:00
|
|
|
|
|
2009-02-20 23:53:15 +01:00
|
|
|
|
dol_syslog("Paiement::Create insert paiement_facture sql=".$sql);
|
2007-02-20 16:22:41 +01:00
|
|
|
|
$resql=$this->db->query($sql);
|
|
|
|
|
|
if (! $resql)
|
2005-10-05 03:48:00 +02:00
|
|
|
|
{
|
2008-01-25 21:25:44 +01:00
|
|
|
|
$this->error=$this->db->error();
|
2009-02-20 23:53:15 +01:00
|
|
|
|
dol_syslog('Paiement::Create insert paiement_facture error='.$this->error, LOG_ERR);
|
2006-04-08 14:52:30 +02:00
|
|
|
|
$error++;
|
2005-10-05 03:48:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2009-02-20 23:53:15 +01:00
|
|
|
|
dol_syslog('Paiement::Create Montant non num<75>rique');
|
2005-10-05 03:48:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2006-04-08 14:52:30 +02:00
|
|
|
|
|
|
|
|
|
|
if (! $error)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Appel des triggers
|
|
|
|
|
|
include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
|
|
|
|
|
|
$interface=new Interfaces($this->db);
|
2008-02-28 21:37:04 +01:00
|
|
|
|
$result=$interface->run_triggers('PAYMENT_CUSTOMER_CREATE',$this,$user,$langs,$conf);
|
2008-01-29 21:34:58 +01:00
|
|
|
|
if ($result < 0) { $error++; $this->errors=$interface->errors; }
|
2006-04-08 14:52:30 +02:00
|
|
|
|
// Fin appel triggers
|
|
|
|
|
|
}
|
2005-10-05 03:48:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2008-01-25 21:25:44 +01:00
|
|
|
|
$this->error=$this->db->error();
|
2009-02-20 23:53:15 +01:00
|
|
|
|
dol_syslog('Paiement::Create insert paiement error='.$this->error, LOG_ERR);
|
2006-04-08 14:52:30 +02:00
|
|
|
|
$error++;
|
2005-10-05 03:48:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2008-01-25 21:25:44 +01:00
|
|
|
|
if ($this->total <> 0 && ! $error) // On accepte les montants n<>gatifs
|
2005-10-05 03:48:00 +02:00
|
|
|
|
{
|
|
|
|
|
|
$this->db->commit();
|
|
|
|
|
|
return $this->id;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
$this->db->rollback();
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2004-09-14 22:53:49 +02:00
|
|
|
|
|
2002-12-19 15:41:37 +01:00
|
|
|
|
|
2005-10-15 20:28:21 +02:00
|
|
|
|
/**
|
|
|
|
|
|
* \brief Supprime un paiement ainsi que les lignes qu'il a g<EFBFBD>n<EFBFBD>r<EFBFBD> dans comptes
|
|
|
|
|
|
* Si le paiement porte sur un <EFBFBD>criture compte qui est rapproch<EFBFBD>e, on refuse
|
|
|
|
|
|
* Si le paiement porte sur au moins une facture <EFBFBD> "pay<EFBFBD>e", on refuse
|
|
|
|
|
|
* \return int <0 si ko, >0 si ok
|
|
|
|
|
|
*/
|
2005-10-05 03:48:00 +02:00
|
|
|
|
function delete()
|
|
|
|
|
|
{
|
2005-10-15 20:28:21 +02:00
|
|
|
|
$bank_line_id = $this->bank_line;
|
|
|
|
|
|
|
2005-10-05 03:48:00 +02:00
|
|
|
|
$this->db->begin();
|
2005-10-15 20:28:21 +02:00
|
|
|
|
|
2007-02-20 16:22:41 +01:00
|
|
|
|
// V<>rifier si paiement porte pas sur une facture class<73>e
|
2005-10-15 20:28:21 +02:00
|
|
|
|
// Si c'est le cas, on refuse la suppression
|
2007-02-20 16:22:41 +01:00
|
|
|
|
$billsarray=$this->getBillsArray('fk_statut > 1');
|
2005-10-15 20:28:21 +02:00
|
|
|
|
if (is_array($billsarray))
|
|
|
|
|
|
{
|
|
|
|
|
|
if (sizeof($billsarray))
|
|
|
|
|
|
{
|
2007-02-20 16:22:41 +01:00
|
|
|
|
$this->error="Impossible de supprimer un paiement portant sur au moins une facture ferm<72>e";
|
2005-10-15 20:28:21 +02:00
|
|
|
|
$this->db->rollback();
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
$this->db->rollback();
|
|
|
|
|
|
return -2;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// V<>rifier si paiement ne porte pas sur ecriture bancaire rapproch<63>e
|
|
|
|
|
|
// Si c'est le cas, on refuse le paiement
|
|
|
|
|
|
if ($bank_line_id)
|
|
|
|
|
|
{
|
|
|
|
|
|
$accline = new AccountLine($this->db,$bank_line_id);
|
|
|
|
|
|
$accline->fetch($bank_line_id);
|
|
|
|
|
|
if ($accline->rappro)
|
|
|
|
|
|
{
|
|
|
|
|
|
$this->error="Impossible de supprimer un paiement qui a g<>n<EFBFBD>r<EFBFBD> une <20>criture qui a <20>t<EFBFBD> rapproch<63>e";
|
|
|
|
|
|
$this->db->rollback();
|
|
|
|
|
|
return -3;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Efface la ligne de paiement (dans paiement_facture et paiement)
|
|
|
|
|
|
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'paiement_facture';
|
|
|
|
|
|
$sql.= ' WHERE fk_paiement = '.$this->id;
|
2005-10-05 03:48:00 +02:00
|
|
|
|
$result = $this->db->query($sql);
|
|
|
|
|
|
if ($result)
|
|
|
|
|
|
{
|
2005-10-15 20:28:21 +02:00
|
|
|
|
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'paiement';
|
|
|
|
|
|
$sql.= ' WHERE rowid = '.$this->id;
|
2005-10-05 03:48:00 +02:00
|
|
|
|
$result = $this->db->query($sql);
|
2005-10-15 20:28:21 +02:00
|
|
|
|
if (! $result)
|
|
|
|
|
|
{
|
|
|
|
|
|
$this->error=$this->db->error();
|
|
|
|
|
|
$this->db->rollback();
|
|
|
|
|
|
return -3;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Supprimer l'<27>criture bancaire si paiement li<6C> <20> <20>criture
|
|
|
|
|
|
if ($bank_line_id)
|
|
|
|
|
|
{
|
2007-06-01 22:32:35 +02:00
|
|
|
|
$accline = new AccountLine($this->db);
|
|
|
|
|
|
$accline->fetch($bank_line_id);
|
|
|
|
|
|
$result=$accline->delete();
|
2005-10-15 20:28:21 +02:00
|
|
|
|
if ($result < 0)
|
|
|
|
|
|
{
|
2007-06-01 22:32:35 +02:00
|
|
|
|
$this->error=$accline->error;
|
2005-10-15 20:28:21 +02:00
|
|
|
|
$this->db->rollback();
|
|
|
|
|
|
return -4;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$this->db->commit();
|
|
|
|
|
|
return 1;
|
2005-10-05 03:48:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2005-10-15 20:28:21 +02:00
|
|
|
|
$this->error=$this->db->error;
|
2005-10-05 03:48:00 +02:00
|
|
|
|
$this->db->rollback();
|
2005-10-15 20:28:21 +02:00
|
|
|
|
return -5;
|
2005-10-05 03:48:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2005-10-15 20:28:21 +02:00
|
|
|
|
/**
|
|
|
|
|
|
* \brief Mise a jour du lien entre le paiement et la ligne g<EFBFBD>n<EFBFBD>r<EFBFBD>e dans llx_bank
|
|
|
|
|
|
* \param id_bank Id compte bancaire
|
|
|
|
|
|
*/
|
2005-10-05 03:48:00 +02:00
|
|
|
|
function update_fk_bank($id_bank)
|
|
|
|
|
|
{
|
2005-10-15 20:28:21 +02:00
|
|
|
|
$sql = 'UPDATE llx_paiement set fk_bank = '.$id_bank;
|
|
|
|
|
|
$sql.= ' WHERE rowid = '.$this->id;
|
2005-10-05 03:48:00 +02:00
|
|
|
|
$result = $this->db->query($sql);
|
|
|
|
|
|
if ($result)
|
|
|
|
|
|
{
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2009-02-20 23:53:15 +01:00
|
|
|
|
dol_print_error($this->db);
|
2005-10-05 03:48:00 +02:00
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2004-05-02 15:40:27 +02:00
|
|
|
|
|
2005-10-15 20:28:21 +02:00
|
|
|
|
/**
|
|
|
|
|
|
* \brief Valide le paiement
|
|
|
|
|
|
* \return int <0 si ko, >0 si ok
|
|
|
|
|
|
*/
|
2005-10-05 03:48:00 +02:00
|
|
|
|
function valide()
|
|
|
|
|
|
{
|
|
|
|
|
|
$sql = 'UPDATE '.MAIN_DB_PREFIX.'paiement SET statut = 1 WHERE rowid = '.$this->id;
|
2007-05-16 01:08:23 +02:00
|
|
|
|
|
2009-02-20 23:53:15 +01:00
|
|
|
|
dol_syslog('Paiement::valide sql='.$sql);
|
2005-10-05 03:48:00 +02:00
|
|
|
|
$result = $this->db->query($sql);
|
|
|
|
|
|
if ($result)
|
|
|
|
|
|
{
|
2007-05-16 01:08:23 +02:00
|
|
|
|
return 1;
|
2005-10-05 03:48:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2009-02-20 23:53:15 +01:00
|
|
|
|
dol_syslog('Paiement::valide Error -1');
|
2005-10-05 03:48:00 +02:00
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2004-12-16 14:26:13 +01:00
|
|
|
|
|
2005-10-15 20:28:21 +02:00
|
|
|
|
/*
|
|
|
|
|
|
* \brief Information sur l'objet
|
|
|
|
|
|
* \param id id du paiement dont il faut afficher les infos
|
|
|
|
|
|
*/
|
|
|
|
|
|
function info($id)
|
2004-02-09 15:41:41 +01:00
|
|
|
|
{
|
2005-10-05 03:48:00 +02:00
|
|
|
|
$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;
|
|
|
|
|
|
|
2009-02-20 23:53:15 +01:00
|
|
|
|
dol_syslog('Paiement::info sql='.$sql);
|
2007-05-05 16:18:12 +02:00
|
|
|
|
$result = $this->db->query($sql);
|
|
|
|
|
|
|
|
|
|
|
|
if ($result)
|
2005-10-05 03:48:00 +02:00
|
|
|
|
{
|
2007-05-05 16:18:12 +02:00
|
|
|
|
if ($this->db->num_rows($result))
|
2005-10-05 03:48:00 +02:00
|
|
|
|
{
|
2007-05-05 16:18:12 +02:00
|
|
|
|
$obj = $this->db->fetch_object($result);
|
2007-06-12 00:51:47 +02:00
|
|
|
|
$this->id = $obj->rowid;
|
2005-10-05 03:48:00 +02:00
|
|
|
|
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;
|
|
|
|
|
|
}
|
2007-05-05 16:18:12 +02:00
|
|
|
|
$this->db->free($result);
|
2005-10-05 03:48:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2009-02-20 23:53:15 +01:00
|
|
|
|
dol_print_error($this->db);
|
2005-10-05 03:48:00 +02:00
|
|
|
|
}
|
2004-02-09 15:41:41 +01:00
|
|
|
|
}
|
2005-10-15 20:28:21 +02:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* \brief Retourne la liste des factures sur lesquels porte le paiement
|
|
|
|
|
|
* \param filter Critere de filtre
|
|
|
|
|
|
* \return array Tableau des id de factures
|
|
|
|
|
|
*/
|
|
|
|
|
|
function getBillsArray($filter='')
|
|
|
|
|
|
{
|
|
|
|
|
|
$sql = 'SELECT fk_facture';
|
|
|
|
|
|
$sql.= ' FROM '.MAIN_DB_PREFIX.'paiement_facture as pf, '.MAIN_DB_PREFIX.'facture as f';
|
|
|
|
|
|
$sql.= ' WHERE pf.fk_facture = f.rowid AND fk_paiement = '.$this->id;
|
|
|
|
|
|
if ($filter) $sql.= ' AND '.$filter;
|
|
|
|
|
|
$resql = $this->db->query($sql);
|
|
|
|
|
|
if ($resql)
|
|
|
|
|
|
{
|
|
|
|
|
|
$i=0;
|
|
|
|
|
|
$num=$this->db->num_rows($resql);
|
|
|
|
|
|
$billsarray=array();
|
|
|
|
|
|
|
|
|
|
|
|
while ($i < $num)
|
|
|
|
|
|
{
|
|
|
|
|
|
$obj = $this->db->fetch_object($resql);
|
|
|
|
|
|
$billsarray[$i]=$obj->fk_facture;
|
|
|
|
|
|
$i++;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return $billsarray;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
$this->error=$this->db->error();
|
2009-02-20 23:53:15 +01:00
|
|
|
|
dol_syslog('Paiement::getBillsArray Error '.$this->error.' - sql='.$sql);
|
2005-10-15 20:28:21 +02:00
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2007-01-05 21:30:34 +01:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* \brief Renvoie nom clicable (avec eventuellement le picto)
|
2008-02-18 07:16:05 +01:00
|
|
|
|
* \param withpicto 0=Pas de picto, 1=Inclut le picto dans le lien, 2=Picto seul
|
2007-01-05 21:30:34 +01:00
|
|
|
|
* \param option Sur quoi pointe le lien
|
|
|
|
|
|
* \return string Chaine avec URL
|
|
|
|
|
|
*/
|
|
|
|
|
|
function getNomUrl($withpicto=0,$option='')
|
|
|
|
|
|
{
|
2007-12-03 22:40:46 +01:00
|
|
|
|
global $langs;
|
2007-01-05 21:30:34 +01:00
|
|
|
|
|
|
|
|
|
|
$result='';
|
|
|
|
|
|
|
2008-11-16 23:26:47 +01:00
|
|
|
|
$lien = '<a href="'.DOL_URL_ROOT.'/compta/paiement/fiche.php?id='.$this->id.'">';
|
2007-01-05 21:30:34 +01:00
|
|
|
|
$lienfin='</a>';
|
|
|
|
|
|
|
2008-02-18 07:16:05 +01:00
|
|
|
|
if ($withpicto) $result.=($lien.img_object($langs->trans("ShowPayment"),'payment').$lienfin);
|
|
|
|
|
|
if ($withpicto && $withpicto != 2) $result.=' ';
|
2008-11-16 23:26:47 +01:00
|
|
|
|
if ($withpicto != 2) $result.=$lien.$this->ref.$lienfin;
|
2007-01-05 21:30:34 +01:00
|
|
|
|
return $result;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* \brief Retourne le libell<EFBFBD> du statut d'une facture (brouillon, valid<EFBFBD>e, abandonn<EFBFBD>e, pay<EFBFBD>e)
|
|
|
|
|
|
* \param mode 0=libell<EFBFBD> long, 1=libell<EFBFBD> court, 2=Picto + Libell<EFBFBD> court, 3=Picto, 4=Picto + Libell<EFBFBD> long, 5=Libell<EFBFBD> court + Picto
|
|
|
|
|
|
* \return string Libelle
|
|
|
|
|
|
*/
|
|
|
|
|
|
function getLibStatut($mode=0)
|
|
|
|
|
|
{
|
|
|
|
|
|
return $this->LibStatut($this->statut,$mode);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* \brief Renvoi le libell<EFBFBD> d'un statut donne
|
|
|
|
|
|
* \param status Statut
|
|
|
|
|
|
* \param mode 0=libell<EFBFBD> long, 1=libell<EFBFBD> court, 2=Picto + Libell<EFBFBD> court, 3=Picto, 4=Picto + Libell<EFBFBD> long, 5=Libell<EFBFBD> court + Picto
|
|
|
|
|
|
* \return string Libell<EFBFBD> du statut
|
|
|
|
|
|
*/
|
|
|
|
|
|
function LibStatut($status,$mode=0)
|
|
|
|
|
|
{
|
|
|
|
|
|
global $langs; // TODO Renvoyer le libell<6C> anglais et faire traduction a affichage
|
|
|
|
|
|
$langs->load('compta');
|
|
|
|
|
|
if ($mode == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
if ($status == 0) return $langs->trans('ToValidate');
|
|
|
|
|
|
if ($status == 1) return $langs->trans('Validated');
|
|
|
|
|
|
}
|
|
|
|
|
|
if ($mode == 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
if ($status == 0) return $langs->trans('ToValidate');
|
|
|
|
|
|
if ($status == 1) return $langs->trans('Validated');
|
|
|
|
|
|
}
|
|
|
|
|
|
if ($mode == 2)
|
|
|
|
|
|
{
|
|
|
|
|
|
if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1').' '.$langs->trans('ToValidate');
|
|
|
|
|
|
if ($status == 1) return img_picto($langs->trans('Validated'),'statut4').' '.$langs->trans('Validated');
|
|
|
|
|
|
}
|
|
|
|
|
|
if ($mode == 3)
|
|
|
|
|
|
{
|
|
|
|
|
|
if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1');
|
|
|
|
|
|
if ($status == 1) return img_picto($langs->trans('Validated'),'statut4');
|
|
|
|
|
|
}
|
|
|
|
|
|
if ($mode == 4)
|
|
|
|
|
|
{
|
|
|
|
|
|
if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1').' '.$langs->trans('ToValidate');
|
|
|
|
|
|
if ($status == 1) return img_picto($langs->trans('Validated'),'statut4').' '.$langs->trans('Validated');
|
|
|
|
|
|
}
|
|
|
|
|
|
if ($mode == 5)
|
|
|
|
|
|
{
|
|
|
|
|
|
if ($status == 0) return $langs->trans('ToValidate').' '.img_picto($langs->trans('ToValidate'),'statut1');
|
|
|
|
|
|
if ($status == 1) return $langs->trans('Validated').' '.img_picto($langs->trans('Validated'),'statut4');
|
|
|
|
|
|
}
|
|
|
|
|
|
return $langs->trans('Unknown');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2002-12-19 15:41:37 +01:00
|
|
|
|
}
|
|
|
|
|
|
?>
|