diff --git a/htdocs/chargesociales.class.php b/htdocs/chargesociales.class.php index 78cf8686198..492b3923001 100644 --- a/htdocs/chargesociales.class.php +++ b/htdocs/chargesociales.class.php @@ -1,7 +1,7 @@ * Copyright (C) 2004 Laurent Destailleur - * + * * 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 @@ -20,102 +20,208 @@ * $Source$ */ -/* - * La tva collectée n'est calculée que sur les factures payées. - * - */ -class ChargeSociales { - var $id; - var $db; - var $date_ech; - var $date_pai; - var $lib; - var $type; - var $lib_typ; - var $amount; - var $paye; - var $periode; - - Function ChargeSociales($DB) - { - $this->db = $DB; +class PaiementCharge { + var $db; - return 1; - } + var $id; + var $chid; + var $paiementtype; + var $datepaye; + var $amounts; + var $num_paiement; + var $note; - /* - * + Function PaiementCharge($DB) { + $this->db = $DB; + + return 1; + } + + Function create($user) { + $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; + } + } + if ($total > 0) + { + $sql = "INSERT INTO ".MAIN_DB_PREFIX."paiementcharge (fk_charge, datec, datep, amount, fk_typepaiement, num_paiement, note, fk_user_creat)"; + $sql .= " VALUES ($this->chid, now(), $this->datepaye, $total, $this->paiementtype, '$this->num_paiement', '$this->note', $user->id)"; + + 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énérée + * + */ + Function update_fk_bank($id_bank) { + $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() ."
".$sql; + return 0; + } + } +} + +/* +* La tva collectée n'est calculée que sur les factures payées. +* +*/ +class ChargeSociales { + var $db; + + var $id; + var $date_ech; + var $date_pai; + var $lib; + var $type; + var $type_libelle; + var $amount; + var $paye; + var $periode; + + Function ChargeSociales($DB) { + $this->db = $DB; + + return 1; + } + + /* + * Retrouve et charge une charge sociale + * Retour: 1 si trouve, 0 sinon + */ + Function fetch($id) { + $sql = "SELECT cs.rowid,".$this->db->pdate("cs.date_ech")." as date_ech,".$this->db->pdate("cs.date_pai")." as date_pai"; + $sql .=", cs.libelle as lib, cs.fk_type, cs.amount, cs.paye, cs.periode, c.libelle"; + $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()) + { + $obj = $this->db->fetch_object(0); + + $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; + + return 1; + } + else + { + return 0; + } + $this->db->free(); + } + else + { + print $this->db->error(); + return 0; + } + } + + Function solde($year = 0) { + + $sql = "SELECT sum(f.amount) as amount"; + $sql .= " FROM ".MAIN_DB_PREFIX."chargesociales as f WHERE paye = 0"; + + if ($year) { + $sql .= " AND f.datev >= '$y-01-01' AND f.datev <= '$y-12-31' "; + } + + $result = $this->db->query($sql); + + if ($result) { + if ($this->db->num_rows()) { + $obj = $this->db->fetch_object(0); + return $obj->amount; + } else { + return 0; + } + + $this->db->free(); + + } else { + print $this->db->error(); + return -1; + } + } + + /** + * Tag la charge comme payée complètement * */ - Function fetch($id) + Function set_payed($rowid) { - $sql = "SELECT cs.rowid,".$this->db->pdate("cs.date_ech")." as date_ech,".$this->db->pdate("cs.date_pai")." as date_pai"; - $sql .=", cs.libelle as lib, cs.fk_type, cs.amount, cs.paye, cs.periode, c.libelle"; - $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()) - { - $obj = $this->db->fetch_object(0); - - $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; - - return 1; - } - else - { - return 0; - } - $this->db->free(); - } - else - { - print $this->db->error(); - return 0; - } + $sql = "UPDATE ".MAIN_DB_PREFIX."chargesociales set paye=1 WHERE rowid = $rowid ;"; + $return = $this->db->query( $sql); } - Function solde($year = 0) { - $sql = "SELECT sum(f.amount) as amount"; - $sql .= " FROM ".MAIN_DB_PREFIX."chargesociales as f WHERE paye = 0"; - - if ($year) { - $sql .= " AND f.datev >= '$y-01-01' AND f.datev <= '$y-12-31' "; + /** + * Renvoi le staut sous forme de libellé d'une charge + * + */ + Function getLibStatut() { + if ($this->paye == 0) { return "Non Payé"; } + else { return "Payé"; } } - - $result = $this->db->query($sql); - - if ($result) { - if ($this->db->num_rows()) { - $obj = $this->db->fetch_object(0); - return $obj->amount; - } else { - return 0; - } - - $this->db->free(); - - } else { - print $this->db->error(); - return -1; - } - } - } /* - * $Id$ - * $Source$ - */ +* $Id$ +* $Source$ +*/ ?> diff --git a/htdocs/compta/sociales/charges.php b/htdocs/compta/sociales/charges.php index d07c95002ef..6f68c1ea54a 100644 --- a/htdocs/compta/sociales/charges.php +++ b/htdocs/compta/sociales/charges.php @@ -21,14 +21,12 @@ */ require("./pre.inc.php"); -$user->getrights('facture'); $user->getrights('compta'); if (!$user->admin && !$user->rights->compta->charges) accessforbidden(); require("../../chargesociales.class.php"); -//require("../../paiement_charge.class.php"); require("../bank/account.class.php"); llxHeader(); @@ -36,6 +34,20 @@ llxHeader(); $chid=isset($_GET["id"])?$_GET["id"]:$_POST["id"]; + +/* *************************************************************************** */ +/* */ +/* Action Classer Payé */ +/* */ +/* *************************************************************************** */ +if ($_GET["action"] == 'payed') +{ + $cha = new ChargeSociales($db); + $result = $cha->set_payed($chid); +} + + + /* *************************************************************************** */ /* */ /* Mode fiche */ @@ -160,19 +172,19 @@ if ($chid > 0) print "
\n"; // Supprimer - if ($cha->paye == 0 && $user->rights->facture->supprimer) + if ($cha->paye == 0 && $totalpaye <=0 && $user->rights->compta->charges) { print "id&action=delete\">Supprimer"; } // Emettre paiement - if ($cha->paye == 0 && $user->rights->facture->paiement) + if ($cha->paye == 0 && round($resteapayer) > 0 && $user->rights->compta->charges) { print "id&action=create\">Emettre paiement"; } // Classer 'payé' - if ($cha->paye == 0 && $user->rights->facture->paiement) + if ($cha->paye == 0 && round($resteapayer) <=0 && $user->rights->compta->charges) { print "id&action=payed\">Classer 'Payée'"; } @@ -180,12 +192,6 @@ if ($chid > 0) print "
"; } - if ($_GET["action"] == 'payed') - { - print "Cette fonction n'a pas encore été implémentée"; - - } - } else {