diff --git a/htdocs/compta/paiement_charge.php b/htdocs/compta/paiement_charge.php new file mode 100755 index 00000000000..4fa167adbbf --- /dev/null +++ b/htdocs/compta/paiement_charge.php @@ -0,0 +1,346 @@ + + * + * 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$ + * + */ +include_once("./pre.inc.php"); +include_once("../chargesociales.class.php"); +include_once(DOL_DOCUMENT_ROOT."/compta/bank/account.class.php"); +/* + * + */ + +$chid=isset($_GET["id"])?$_GET["id"]:$_POST["id"]; + + +if ($_POST["action"] == 'add_paiement') +{ + if ($_POST["paiementtype"] > 0) + { + + $datepaye = $db->idate(mktime(12, 0 , 0, + $_POST["remonth"], + $_POST["reday"], + $_POST["reyear"])); + + $paiement_id = 0; + $amounts = array(); + foreach ($_POST as $key => $value) + { + if (substr($key,0,7) == 'amount_') + { + $other_chid = substr($key,7); + + $amounts[$other_chid] = $_POST[$key]; + } + } + + // TODO Mettre toute la chaine dans une même transaction + + // Creation de la ligne paiement + $paiement = new PaiementCharge($db); + $paiement->chid = $chid; + $paiement->datepaye = $datepaye; + $paiement->amounts = $amounts; // Tableau de montant + $paiement->paiementtype = $_POST["paiementtype"]; + $paiement->num_paiement = $_POST["num_paiement"]; + $paiement->note = $_POST["note"]; + $paiement_id = $paiement->create($user); + + if ($paiement_id > 0) + { + // On determine le montant total du paiement + $total=0; + foreach ($paiement->amounts as $key => $value) + { + $chid = $key; + $value = trim($value); + $amount = round(ereg_replace(",",".",$value), 2); + if (is_numeric($amount)) + { + $total += $amount; + } + } + + // Insertion dans llx_bank + $label = "Règlement charge"; + $acc = new Account($db, $_POST["accountid"]); + $bank_line_id = $acc->addline($paiement->datepaye, $paiement->paiementtype, $label, $total, $paiement->num_paiement, '', $user); + + // Mise a jour fk_bank dans llx_paiementcharge. On connait ainsi le paiement qui a généré l'écriture bancaire + if ($bank_line_id) { + $paiement->update_fk_bank($bank_line_id); + } + + // Mise a jour liens (pour chaque charge concernée par le paiement) + //foreach ($paiement->amounts as $key => $value) + //{ + // $chid = $key; + // $fac = new Facture($db); + // $fac->fetch($chid); + // $fac->fetch_client(); + // $acc->add_url_line($bank_line_id, $paiement_id, DOL_URL_ROOT.'/compta/paiement/fiche.php?id=', "(paiement)"); + // $acc->add_url_line($bank_line_id, $fac->client->id, DOL_URL_ROOT.'/compta/fiche.php?socid=', $fac->client->nom); + //} + + $loc = DOL_URL_ROOT.'/compta/sociales/charges.php?id='.$chid; + Header("Location: $loc"); + } + else + { + // Il y a eu erreur + $fiche_erreur_message = "Echec de la création du paiement: ".$db->error(); + } + } + else + { + $fiche_erreur_message = "Vous devez sélectionner un mode de paiement"; + } +} + +/* + * Sécurité accés client + */ +if ($user->societe_id > 0) +{ + $action = ''; + $socidp = $user->societe_id; +} + +/* + * Affichage + */ + +llxHeader(); + +if ($fiche_erreur_message) +{ + print "
$fiche_erreur_message

"; +} + + +/* + * Formulaire de creation d'un paiement de charge + */ +if ($_GET["action"] == 'create') +{ + + $charge = new ChargeSociales($db); + $charge->fetch($chid); + + $total = $charge->amount; + + print_titre("Emettre un paiement d'une charge"); + print "
\n"; + + print "
\n"; + print "id\">"; + print ''; + print ''; + + print ""; + + print ''; + print "\n"; + print "\n"; + print "\n"; + print "\n"; + + print ""; + + $sql = "SELECT sum(p.amount) FROM ".MAIN_DB_PREFIX."paiementcharge as p WHERE p.fk_charge = $chid;"; + $result = $db->query($sql); + if ($result) { + $sumpayed = $db->result(0,0); + $db->free(); + } + print ''; + + print ""; + + print ""; + + print ""; + print ""; + + print "\n"; + + print ''; + + print "\n"; + + print "\n"; + + print "\n"; +// print "\n"; + + /* + * Autres charges impayées + */ +// $sql = "SELECT f.rowid as facid,f.facnumber,f.total_ttc,".$db->pdate("f.datef")." as df"; +// $sql .= ", sum(pf.amount) as am"; +// $sql .= " FROM ".MAIN_DB_PREFIX."facture as f"; +// $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON pf.fk_facture = f.rowid"; +// $sql .= " WHERE f.fk_soc = ".$facture->socidp; +// $sql .= " AND f.paye = 0"; +// $sql .= " AND f.fk_statut = 1"; // Statut=0 => non validée, Statut=2 => annulée +// $sql .= " GROUP BY f.facnumber"; +// +// if ($db->query($sql)) +// { +// $num = $db->num_rows(); +// +// if ($num > 0) +// { + $i = 0; + print '\n"; +// } +// $db->free(); +// } +// else +// { +// print $sql ."
".$db->error(); +// } + /* + * + */ + + print ''; + print "
Charge
Numéro :'; + print ''.$chid.'
Type charge :$charge->type_libelle
Période :$charge->periode
Libellé :$charge->lib
Date échéance :".dolibarr_print_date($charge->date_ech)."
Montant TTC:".price($charge->amount)." euros
Déjà payé TTC'.price($sumpayed).' euros
Paiement
Date :"; + print_date_select(); + print "Commentaires
Type du paiement :"; + print "
Numéro :
Numéro du chèque / virement
Compte à créditer :"; + print "
Reste à payer :".price($total - $sumpayed)." euros TTC
Montant :
'; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print "\n"; + + $var=True; + $total=0; + $totalrecu=0; + + while ($i < $num) + { + //$objp = $db->fetch_object($i); + $objp = $charge; + + $var=!$var; + + print ""; + + print '\n"; + + if ($objp->date_ech > 0 ) + { + print "\n"; + } + else + { + print "\n"; + } + + print '"; + + print '"; + + print '"; + + print '"; + + print "\n"; + $total+=$objp->total; + $total_ttc+=$objp->total_ttc; + $totalrecu+=$objp->am; + $i++; + } + if ($i > 1) + { + // Print total + print ""; + print ''; + print ""; + print ""; + print ""; + print ''; + print "\n"; + } + print "
ChargeDate échéanceMontant TTCDéjà payé TTCReste à payer TTCMontant
' . $objp->id; + print "".dolibarr_print_date($objp->date_ech)."!!!'.price($objp->amount)."'.price($sumpayed)."'.price($objp->amount-$sumpayed)."'; + if ($sumpayed < $objp->amount) + { + $namef = "amount_".$objp->id; + print ''; + } + else + { + print '-'; + } + print "
Total :".price($total_ttc)."".price($totalrecu)."".price($total_ttc - $totalrecu)." 
"; + print "
\n"; +// } +} + + +$db->close(); + +llxFooter("Dernière modification $Date$ révision $Revision$"); +?> diff --git a/mysql/migration/1.1.0-1.2.0-RC1.sql b/mysql/migration/1.1.0-1.2.0-RC1.sql index 6c8518ffd38..0b53459acb2 100644 --- a/mysql/migration/1.1.0-1.2.0-RC1.sql +++ b/mysql/migration/1.1.0-1.2.0-RC1.sql @@ -162,6 +162,24 @@ insert into llx_c_forme_juridique (code, libelle) values (99,'Autre personne mor update llx_paiement set author = null where author = ''; +create table llx_paiementcharge +( + rowid integer AUTO_INCREMENT PRIMARY KEY, + fk_charge integer, + datec datetime, + tms timestamp, + datep datetime, + amount real default 0, + fk_typepaiement integer NOT NULL, + num_paiement varchar(50), + note text, + fk_bank integer NOT NULL, + fk_user_creat integer, + fk_user_modif integer + +)type=innodb; + + update llx_const set visible=0 where name like 'ADHERENT%'; drop table llx_c_pays; diff --git a/mysql/tables/llx_paiementcharge.sql b/mysql/tables/llx_paiementcharge.sql new file mode 100755 index 00000000000..2a856ce8f71 --- /dev/null +++ b/mysql/tables/llx_paiementcharge.sql @@ -0,0 +1,37 @@ +-- =================================================================== +-- 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 +-- (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$ +-- =================================================================== + +create table llx_paiementcharge +( + rowid integer AUTO_INCREMENT PRIMARY KEY, + fk_charge integer, + datec datetime, -- date de creation + tms timestamp, + datep datetime, -- payment date + amount real default 0, + fk_typepaiement integer NOT NULL, + num_paiement varchar(50), + note text, + fk_bank integer NOT NULL, + fk_user_creat integer, -- utilisateur qui a créé l'info + fk_user_modif integer -- utilisateur qui a modifié l'info + +)type=innodb;