2004-10-20 23:06:45 +02:00
|
|
|
|
<?php
|
2002-06-19 00:01:03 +02:00
|
|
|
|
/* Copyright (C) 2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
2004-05-05 00:02:27 +02:00
|
|
|
|
* Copyright (C) 2004 Laurent Destailleur <eldy@users.sourceforge.net>
|
2004-06-08 17:09:49 +02:00
|
|
|
|
*
|
2002-06-19 00:01:03 +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$
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2004-11-30 21:54:51 +01:00
|
|
|
|
/**
|
|
|
|
|
|
\file htdocs/chargesociales.class.php
|
|
|
|
|
|
\ingroup facture
|
|
|
|
|
|
\brief Fichier de la classe des charges sociales
|
|
|
|
|
|
\version $Revision$
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** \class PaiementCharge
|
|
|
|
|
|
\brief Classe permettant la gestion des paiements des charges
|
|
|
|
|
|
*/
|
2004-06-08 17:09:49 +02:00
|
|
|
|
class PaiementCharge {
|
|
|
|
|
|
var $db;
|
|
|
|
|
|
|
|
|
|
|
|
var $id;
|
|
|
|
|
|
var $chid;
|
|
|
|
|
|
var $paiementtype;
|
|
|
|
|
|
var $datepaye;
|
|
|
|
|
|
var $amounts;
|
|
|
|
|
|
var $num_paiement;
|
|
|
|
|
|
var $note;
|
|
|
|
|
|
|
2004-08-07 20:51:54 +02:00
|
|
|
|
function PaiementCharge($DB) {
|
2004-06-08 17:09:49 +02:00
|
|
|
|
$this->db = $DB;
|
|
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-08-07 20:51:54 +02:00
|
|
|
|
function create($user) {
|
2004-06-08 17:09:49 +02:00
|
|
|
|
$sql_err = 0;
|
|
|
|
|
|
/*
|
|
|
|
|
|
* Insertion dans la base
|
|
|
|
|
|
*/
|
|
|
|
|
|
if ($this->db->begin())
|
|
|
|
|
|
{
|
|
|
|
|
|
$total = 0;
|
|
|
|
|
|
foreach ($this->amounts as $key => $value)
|
|
|
|
|
|
{
|
|
|
|
|
|
$facid = $key;
|
|
|
|
|
|
$value = trim($value);
|
|
|
|
|
|
$amount = round(ereg_replace(",",".",$value), 2);
|
|
|
|
|
|
|
|
|
|
|
|
if (is_numeric($amount))
|
|
|
|
|
|
{
|
|
|
|
|
|
$total += $amount;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2004-11-30 21:54:51 +01:00
|
|
|
|
$total = round(ereg_replace(",",".",$total), 2);
|
2004-06-08 17:09:49 +02:00
|
|
|
|
if ($total > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX."paiementcharge (fk_charge, datec, datep, amount, fk_typepaiement, num_paiement, note, fk_user_creat)";
|
2004-11-30 21:54:51 +01:00
|
|
|
|
$sql .= " VALUES ($this->chid, now(), $this->datepaye, '$total', $this->paiementtype, '$this->num_paiement', '$this->note', $user->id)";
|
2004-06-08 17:09:49 +02:00
|
|
|
|
|
|
|
|
|
|
if ( $this->db->query($sql) )
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
$this->id = $this->db->last_insert_id();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
$sql_err++;
|
|
|
|
|
|
print "Error: $sql : ".$this->db->error();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ( $total > 0 && $sql_err == 0 )
|
|
|
|
|
|
{
|
|
|
|
|
|
$this->db->commit();
|
|
|
|
|
|
return $this->id;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
$this->db->rollback();
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* Mise a jour du lien entre le paiement de charge et la ligne dans llx_bank g<EFBFBD>n<EFBFBD>r<EFBFBD>e
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
2004-08-07 20:51:54 +02:00
|
|
|
|
function update_fk_bank($id_bank) {
|
2004-06-08 17:09:49 +02:00
|
|
|
|
$sql = "UPDATE llx_paiementcharge set fk_bank = ".$id_bank." where rowid = ".$this->id;
|
|
|
|
|
|
$result = $this->db->query($sql);
|
|
|
|
|
|
if ($result)
|
|
|
|
|
|
{
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
print $this->db->error() ."<br>".$sql;
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-11-30 21:54:51 +01:00
|
|
|
|
|
|
|
|
|
|
/** \class ChargeSociales
|
|
|
|
|
|
\brief Classe permettant la gestion des paiements des charges
|
|
|
|
|
|
La tva collect<EFBFBD>e n'est calcul<EFBFBD>e que sur les factures pay<EFBFBD>es.
|
2004-06-08 17:09:49 +02:00
|
|
|
|
*/
|
2002-06-19 00:01:03 +02:00
|
|
|
|
class ChargeSociales {
|
2004-06-08 17:09:49 +02:00
|
|
|
|
var $db;
|
2002-06-19 00:01:03 +02:00
|
|
|
|
|
2004-06-08 17:09:49 +02:00
|
|
|
|
var $id;
|
|
|
|
|
|
var $date_ech;
|
|
|
|
|
|
var $date_pai;
|
|
|
|
|
|
var $lib;
|
|
|
|
|
|
var $type;
|
|
|
|
|
|
var $type_libelle;
|
|
|
|
|
|
var $amount;
|
|
|
|
|
|
var $paye;
|
|
|
|
|
|
var $periode;
|
|
|
|
|
|
|
2004-08-07 20:51:54 +02:00
|
|
|
|
function ChargeSociales($DB) {
|
2004-06-08 17:09:49 +02:00
|
|
|
|
$this->db = $DB;
|
|
|
|
|
|
|
|
|
|
|
|
return 1;
|
2004-05-05 00:02:27 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2004-06-08 17:09:49 +02:00
|
|
|
|
/*
|
|
|
|
|
|
* Retrouve et charge une charge sociale
|
|
|
|
|
|
* Retour: 1 si trouve, 0 sinon
|
|
|
|
|
|
*/
|
2004-08-07 20:51:54 +02:00
|
|
|
|
function fetch($id) {
|
2004-06-08 17:09:49 +02:00
|
|
|
|
$sql = "SELECT cs.rowid,".$this->db->pdate("cs.date_ech")." as date_ech,".$this->db->pdate("cs.date_pai")." as date_pai";
|
2004-06-11 15:39:09 +02:00
|
|
|
|
$sql .=", cs.libelle as lib, cs.fk_type, cs.amount, cs.paye, ".$this->db->pdate("cs.periode")." as periode, c.libelle";
|
2004-06-08 17:09:49 +02:00
|
|
|
|
$sql .= " FROM ".MAIN_DB_PREFIX."chargesociales as cs, ".MAIN_DB_PREFIX."c_chargesociales as c";
|
|
|
|
|
|
$sql .= " WHERE cs.fk_type = c.id";
|
|
|
|
|
|
$sql .=" AND cs.rowid = ".$id;
|
|
|
|
|
|
|
|
|
|
|
|
if ($this->db->query($sql))
|
|
|
|
|
|
{
|
|
|
|
|
|
if ($this->db->num_rows())
|
|
|
|
|
|
{
|
2004-10-23 23:02:56 +02:00
|
|
|
|
$obj = $this->db->fetch_object();
|
2002-06-19 00:01:03 +02:00
|
|
|
|
|
2004-06-08 17:09:49 +02:00
|
|
|
|
$this->id = $obj->rowid;
|
|
|
|
|
|
$this->date_ech = $obj->date_ech;
|
|
|
|
|
|
$this->date_pai = $obj->date_pai;
|
|
|
|
|
|
$this->lib = $obj->lib;
|
|
|
|
|
|
$this->type = $obj->fk_type;
|
|
|
|
|
|
$this->type_libelle = $obj->libelle;
|
|
|
|
|
|
$this->amount = $obj->amount;
|
|
|
|
|
|
$this->paye = $obj->paye;
|
|
|
|
|
|
$this->periode = $obj->periode;
|
2002-06-19 00:01:03 +02:00
|
|
|
|
|
2004-06-08 17:09:49 +02:00
|
|
|
|
return 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
$this->db->free();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
print $this->db->error();
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
2002-06-19 00:01:03 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2004-08-07 20:51:54 +02:00
|
|
|
|
function solde($year = 0) {
|
2002-06-19 00:01:03 +02:00
|
|
|
|
|
2004-06-08 17:09:49 +02:00
|
|
|
|
$sql = "SELECT sum(f.amount) as amount";
|
|
|
|
|
|
$sql .= " FROM ".MAIN_DB_PREFIX."chargesociales as f WHERE paye = 0";
|
2002-06-19 00:01:03 +02:00
|
|
|
|
|
2004-06-08 17:09:49 +02:00
|
|
|
|
if ($year) {
|
|
|
|
|
|
$sql .= " AND f.datev >= '$y-01-01' AND f.datev <= '$y-12-31' ";
|
|
|
|
|
|
}
|
2002-06-19 00:01:03 +02:00
|
|
|
|
|
2004-06-08 17:09:49 +02:00
|
|
|
|
$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();
|
2004-06-08 17:09:49 +02:00
|
|
|
|
return $obj->amount;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$this->db->free();
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
print $this->db->error();
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Tag la charge comme pay<EFBFBD>e compl<EFBFBD>tement
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
2004-08-07 20:51:54 +02:00
|
|
|
|
function set_payed($rowid)
|
2004-06-08 17:09:49 +02:00
|
|
|
|
{
|
|
|
|
|
|
$sql = "UPDATE ".MAIN_DB_PREFIX."chargesociales set paye=1 WHERE rowid = $rowid ;";
|
|
|
|
|
|
$return = $this->db->query( $sql);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Renvoi le staut sous forme de libell<EFBFBD> d'une charge
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
2004-08-07 20:51:54 +02:00
|
|
|
|
function getLibStatut() {
|
2004-06-08 17:09:49 +02:00
|
|
|
|
if ($this->paye == 0) { return "Non Pay<61>"; }
|
|
|
|
|
|
else { return "Pay<EFBFBD>"; }
|
|
|
|
|
|
}
|
2002-06-19 00:01:03 +02:00
|
|
|
|
}
|
|
|
|
|
|
/*
|
2004-06-08 17:09:49 +02:00
|
|
|
|
* $Id$
|
|
|
|
|
|
* $Source$
|
|
|
|
|
|
*/
|
2002-06-19 00:01:03 +02:00
|
|
|
|
?>
|