dolibarr/htdocs/paiement.class.php

135 lines
3.2 KiB
PHP
Raw Normal View History

2002-12-19 15:41:37 +01:00
<?PHP
/* Copyright (C) 2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
2004-01-28 01:25:15 +01:00
* Copyright (C) 2004 Laurent Destailleur <eldy@users.sourceforge.net>
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.
*
* $Id$
* $Source$
*
*/
class Paiement
{
var $id;
var $db;
var $facid;
var $datepaye;
var $amount;
var $author;
var $paiementid; // numero du paiement dans le cas ou une facture paye +ieur fois
var $num_paiement;
var $note;
/*
*
*
*
*/
Function Paiement($DB, $soc_idp="")
{
$this->db = $DB ;
}
/*
*
*
*
*/
Function create()
{
/*
* Insertion dans la base
*/
2003-09-19 17:01:39 +02:00
$this->amount = ereg_replace(",",".",$this->amount);
$sql = "INSERT INTO ".MAIN_DB_PREFIX."paiement (fk_facture, datec, datep, amount, author, fk_paiement, num_paiement, note)";
2002-12-19 15:41:37 +01:00
$sql .= " VALUES ($this->facid, now(), $this->datepaye,$this->amount,'$this->author', $this->paiementid, '$this->num_paiement', '$this->note')";
$result = $this->db->query($sql);
if ($result)
{
2003-10-21 18:26:50 +02:00
$this->id = $this->db->last_insert_id();
return $this->id;
2002-12-19 15:41:37 +01:00
}
else
{
print $this->db->error() ."<br>".$sql;
2002-12-19 15:41:37 +01:00
}
}
/*
*
*
*
*/
2002-12-19 19:55:38 +01:00
Function select($name, $filtre='', $id='')
2002-12-19 15:41:37 +01:00
{
$form = new Form($this->db);
2002-12-19 19:55:38 +01:00
if ($filtre == 'cr<63>dit')
{
2004-01-30 10:58:56 +01:00
$sql = "SELECT id, libelle FROM ".MAIN_DB_PREFIX."c_paiement WHERE type IN (0,2) ORDER BY libelle";
2002-12-19 19:55:38 +01:00
}
elseif ($filtre == 'd<>bit')
{
2004-01-30 10:58:56 +01:00
$sql = "SELECT id, libelle FROM ".MAIN_DB_PREFIX."c_paiement WHERE type IN (1,2) ORDER BY libelle";
2002-12-19 19:55:38 +01:00
}
else
{
2004-01-30 10:58:56 +01:00
$sql = "SELECT id, libelle FROM ".MAIN_DB_PREFIX."c_paiement ORDER BY libelle";
2002-12-19 19:55:38 +01:00
}
$form->select($name, $sql, $id);
2002-12-19 15:41:37 +01:00
}
2002-12-27 22:48:51 +01:00
/*
*
*
*
*/
2003-07-08 22:52:55 +02:00
Function delete()
{
$sql = "SELECT ".MAIN_DB_PREFIX."paiement.rowid FROM ".MAIN_DB_PREFIX."facture, ".MAIN_DB_PREFIX."paiement WHERE ".MAIN_DB_PREFIX."paiement.rowid = ".$this->id;
$sql .= " AND ".MAIN_DB_PREFIX."paiement.fk_facture = ".MAIN_DB_PREFIX."facture.rowid AND ".MAIN_DB_PREFIX."facture.paye = 0";
2003-07-08 22:52:55 +02:00
$result = $this->db->query($sql);
if ($result)
{
if ($this->db->num_rows() == 1)
{
$sql = "DELETE FROM ".MAIN_DB_PREFIX."paiement WHERE ".MAIN_DB_PREFIX."paiement.rowid = ".$this->id;
2002-12-27 22:48:51 +01:00
2003-07-08 22:52:55 +02:00
$result = $this->db->query($sql);
if ($result)
{
return 1;
}
else
{
print $this->db->error() ."<br>".$sql;
return 0;
}
}
}
else
{
print $this->db->error() ."<br>".$sql;
return 0;
}
}
2002-12-19 15:41:37 +01:00
}
?>