2004-10-20 23:15:17 +02:00
|
|
|
|
<?php
|
2003-07-23 16:16:45 +02:00
|
|
|
|
/* Copyright (C) 2002-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
2004-06-09 01:40:53 +02:00
|
|
|
|
* Copyright (C) 2004 Laurent Destailleur <eldy@users.sourceforge.net>
|
2002-06-18 20:21:12 +02: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$
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* La tva collect<EFBFBD>e n'est calcul<EFBFBD>e que sur les factures pay<EFBFBD>es.
|
|
|
|
|
|
*
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
2004-10-20 23:15:17 +02:00
|
|
|
|
|
2003-07-23 16:16:45 +02:00
|
|
|
|
class Tva
|
|
|
|
|
|
{
|
2002-06-18 20:21:12 +02:00
|
|
|
|
var $db;
|
|
|
|
|
|
var $note;
|
2002-06-20 21:25:15 +02:00
|
|
|
|
/*
|
|
|
|
|
|
* Initialistation automatique de la classe
|
|
|
|
|
|
*/
|
2004-08-07 20:51:54 +02:00
|
|
|
|
function Tva($DB)
|
2003-07-23 16:16:45 +02:00
|
|
|
|
{
|
|
|
|
|
|
$this->db = $DB;
|
2002-06-18 20:21:12 +02:00
|
|
|
|
|
2003-07-23 16:16:45 +02:00
|
|
|
|
return 1;
|
2002-06-18 20:21:12 +02:00
|
|
|
|
}
|
2004-10-20 23:15:17 +02:00
|
|
|
|
|
2002-06-20 21:25:15 +02:00
|
|
|
|
/*
|
2004-10-20 23:15:17 +02:00
|
|
|
|
* \brief Hum la fonction s'appelle 'Solde' elle doit a mon avis calcluer le solde de TVA, non ?
|
2002-06-20 21:25:15 +02:00
|
|
|
|
*
|
|
|
|
|
|
*/
|
2004-10-20 23:15:17 +02:00
|
|
|
|
|
2004-08-07 20:51:54 +02:00
|
|
|
|
function solde($year = 0)
|
2003-07-23 16:16:45 +02:00
|
|
|
|
{
|
2002-06-18 20:21:12 +02:00
|
|
|
|
|
2003-07-23 16:16:45 +02:00
|
|
|
|
$reglee = $this->tva_sum_reglee($year);
|
2002-06-26 02:03:47 +02:00
|
|
|
|
|
2003-07-23 16:16:45 +02:00
|
|
|
|
$payee = $this->tva_sum_payee($year);
|
|
|
|
|
|
$collectee = $this->tva_sum_collectee($year);
|
2002-06-18 20:21:12 +02:00
|
|
|
|
|
2003-07-23 16:16:45 +02:00
|
|
|
|
$solde = $reglee - ($collectee - $payee) ;
|
2002-06-18 20:21:12 +02:00
|
|
|
|
|
2003-07-23 16:16:45 +02:00
|
|
|
|
return $solde;
|
|
|
|
|
|
}
|
2004-10-20 23:15:17 +02:00
|
|
|
|
|
2002-06-18 20:21:12 +02:00
|
|
|
|
/*
|
2004-10-20 23:15:17 +02:00
|
|
|
|
* \brief Total de la TVA des factures emises par la societe.
|
2002-06-18 20:21:12 +02:00
|
|
|
|
*
|
|
|
|
|
|
*/
|
2004-10-20 23:15:17 +02:00
|
|
|
|
|
2004-08-07 20:51:54 +02:00
|
|
|
|
function tva_sum_collectee($year = 0)
|
2003-07-23 16:16:45 +02:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
$sql = "SELECT sum(f.tva) as amount";
|
2004-02-01 02:50:21 +01:00
|
|
|
|
$sql .= " FROM ".MAIN_DB_PREFIX."facture as f WHERE f.paye = 1";
|
2003-07-23 16:16:45 +02:00
|
|
|
|
|
|
|
|
|
|
if ($year)
|
|
|
|
|
|
{
|
|
|
|
|
|
$sql .= " AND f.datef >= '$year-01-01' AND f.datef <= '$year-12-31' ";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$result = $this->db->query($sql);
|
|
|
|
|
|
|
|
|
|
|
|
if ($result)
|
|
|
|
|
|
{
|
|
|
|
|
|
if ($this->db->num_rows())
|
|
|
|
|
|
{
|
2004-10-23 23:02:56 +02:00
|
|
|
|
$obj = $this->db->fetch_object($result);
|
2003-07-23 16:16:45 +02:00
|
|
|
|
return $obj->amount;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$this->db->free();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
print $this->db->error();
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
2002-06-18 20:21:12 +02:00
|
|
|
|
}
|
2004-10-20 23:15:17 +02:00
|
|
|
|
|
2002-06-18 20:21:12 +02:00
|
|
|
|
/*
|
2004-10-20 23:15:17 +02:00
|
|
|
|
* \brief Tva pay<EFBFBD>e
|
2002-06-26 02:03:47 +02:00
|
|
|
|
*
|
2002-06-18 20:21:12 +02:00
|
|
|
|
*/
|
2004-10-20 23:15:17 +02:00
|
|
|
|
|
2004-08-07 20:51:54 +02:00
|
|
|
|
function tva_sum_payee($year = 0)
|
2003-07-23 16:16:45 +02:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
$sql = "SELECT sum(f.amount) as amount";
|
2004-02-01 02:50:21 +01:00
|
|
|
|
$sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
|
2003-07-23 16:16:45 +02:00
|
|
|
|
|
|
|
|
|
|
if ($year)
|
|
|
|
|
|
{
|
|
|
|
|
|
$sql .= " WHERE f.datef >= '$year-01-01' AND f.datef <= '$year-12-31' ";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$result = $this->db->query($sql);
|
|
|
|
|
|
|
|
|
|
|
|
if ($result)
|
|
|
|
|
|
{
|
|
|
|
|
|
if ($this->db->num_rows())
|
|
|
|
|
|
{
|
2004-10-23 23:02:56 +02:00
|
|
|
|
$obj = $this->db->fetch_object($result);
|
2003-07-23 16:16:45 +02:00
|
|
|
|
return $obj->amount;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$this->db->free();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
print $this->db->error();
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
2002-06-26 02:03:47 +02:00
|
|
|
|
}
|
2004-10-20 23:15:17 +02:00
|
|
|
|
|
2002-06-26 02:03:47 +02:00
|
|
|
|
/*
|
|
|
|
|
|
* Tva r<EFBFBD>gl<EFBFBD>e
|
|
|
|
|
|
* Total de la TVA r<EFBFBD>glee aupres de qui de droit
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
2004-10-20 23:15:17 +02:00
|
|
|
|
|
2004-08-07 20:51:54 +02:00
|
|
|
|
function tva_sum_reglee($year = 0)
|
2003-07-23 16:16:45 +02:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
$sql = "SELECT sum(f.amount) as amount";
|
2004-02-01 02:50:21 +01:00
|
|
|
|
$sql .= " FROM ".MAIN_DB_PREFIX."tva as f";
|
2003-07-23 16:16:45 +02:00
|
|
|
|
|
|
|
|
|
|
if ($year)
|
|
|
|
|
|
{
|
|
|
|
|
|
$sql .= " WHERE f.datev >= '$year-01-01' AND f.datev <= '$year-12-31' ";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$result = $this->db->query($sql);
|
|
|
|
|
|
|
|
|
|
|
|
if ($result)
|
|
|
|
|
|
{
|
|
|
|
|
|
if ($this->db->num_rows())
|
|
|
|
|
|
{
|
2004-10-23 23:02:56 +02:00
|
|
|
|
$obj = $this->db->fetch_object($result);
|
2003-07-23 16:16:45 +02:00
|
|
|
|
return $obj->amount;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$this->db->free();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
print $this->db->error();
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
2002-06-18 20:21:12 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2003-07-23 16:16:45 +02:00
|
|
|
|
/*
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
2004-10-20 23:15:17 +02:00
|
|
|
|
|
2004-08-07 20:51:54 +02:00
|
|
|
|
function add_payement($datep, $datev, $amount)
|
2003-08-12 15:28:56 +02:00
|
|
|
|
{
|
2004-02-01 02:50:21 +01:00
|
|
|
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX."tva (datep, datev, amount) ";
|
2003-08-12 15:28:56 +02:00
|
|
|
|
$sql .= " VALUES ('".$this->db->idate($datep)."',";
|
|
|
|
|
|
$sql .= "'".$this->db->idate($datev)."'," . ereg_replace(",",".",$amount) .")";
|
|
|
|
|
|
|
|
|
|
|
|
$result = $this->db->query($sql);
|
2002-06-18 20:21:12 +02:00
|
|
|
|
|
2003-08-12 15:28:56 +02:00
|
|
|
|
if ($result)
|
|
|
|
|
|
{
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
print $this->db->error()."<br>".$sql;
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2002-06-18 20:21:12 +02:00
|
|
|
|
}
|
2002-06-20 21:25:15 +02:00
|
|
|
|
|
2002-06-18 20:21:12 +02:00
|
|
|
|
?>
|