From 1383f8e6aa4eee2a27b8964726c9e63589890942 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 8 Feb 2010 16:33:11 +0000 Subject: [PATCH] New: Add missing page to see social contribution payment --- htdocs/chargesociales.class.php | 338 +++++++++++++++++++++++++-- htdocs/compta/paiement_charge.php | 2 +- htdocs/compta/payment_sc/fiche.php | 312 +++++++++++++++++++++++++ htdocs/compta/payment_sc/pre.inc.php | 50 ++++ htdocs/compta/sociales/charges.php | 11 +- 5 files changed, 693 insertions(+), 20 deletions(-) create mode 100644 htdocs/compta/payment_sc/fiche.php create mode 100644 htdocs/compta/payment_sc/pre.inc.php diff --git a/htdocs/chargesociales.class.php b/htdocs/chargesociales.class.php index b3a7b795639..58d139aac37 100644 --- a/htdocs/chargesociales.class.php +++ b/htdocs/chargesociales.class.php @@ -344,23 +344,36 @@ class ChargeSociales extends CommonObject /** \class PaiementCharge - \brief Classe permettant la gestion des paiements des charges -*/ + * \brief Classe permettant la gestion des paiements des charges + */ class PaiementCharge { - var $db; + var $db; //!< To store db handler + var $error; //!< To return error code (or message) + var $errors=array(); //!< To return several error codes (or messages) + //var $element='paiementcharge'; //!< Id that identify managed objects + //var $table_element='paiementcharge'; //!< Name of table without prefix where object is stored var $id; - var $chid; - var $paiementtype; - var $datepaye; - var $amounts; - var $num_paiement; - var $note; + var $fk_charge; + var $datec=''; + var $tms=''; + var $datep=''; + var $amount; + var $fk_typepaiement; + var $num_paiement; + var $note; + var $fk_bank; + var $fk_user_creat; + var $fk_user_modif; - function PaiementCharge($DB) - { + /** + * \brief Constructor + * \param DB Database handler + */ + function Paiementcharge($DB) + { $this->db = $DB; return 1; } @@ -372,8 +385,8 @@ class PaiementCharge */ function create($user) { - global $conf; - $error = 0; + global $conf, $langs; + $error=0; // Validation parametres if (! $this->datepaye) @@ -382,7 +395,18 @@ class PaiementCharge return -1; } - $this->db->begin(); + + // Clean parameters + if (isset($this->fk_charge)) $this->fk_charge=trim($this->fk_charge); + if (isset($this->amount)) $this->amount=trim($this->amount); + if (isset($this->fk_typepaiement)) $this->fk_typepaiement=trim($this->fk_typepaiement); + if (isset($this->num_paiement)) $this->num_paiement=trim($this->num_paiement); + if (isset($this->note)) $this->note=trim($this->note); + if (isset($this->fk_bank)) $this->fk_bank=trim($this->fk_bank); + if (isset($this->fk_user_creat)) $this->fk_user_creat=trim($this->fk_user_creat); + if (isset($this->fk_user_modif)) $this->fk_user_modif=trim($this->fk_user_modif); + + $this->db->begin(); $total=0; foreach ($this->amounts as $key => $value) @@ -430,6 +454,292 @@ class PaiementCharge } /** + * \brief Load object in memory from database + * \param id id object + * \return int <0 if KO, >0 if OK + */ + function fetch($id) + { + global $langs; + $sql = "SELECT"; + $sql.= " t.rowid,"; + + $sql.= " t.fk_charge,"; + $sql.= " t.datec,"; + $sql.= " t.tms,"; + $sql.= " t.datep,"; + $sql.= " t.amount,"; + $sql.= " t.fk_typepaiement,"; + $sql.= " t.num_paiement,"; + $sql.= " t.note,"; + $sql.= " t.fk_bank,"; + $sql.= " t.fk_user_creat,"; + $sql.= " t.fk_user_modif,"; + + $sql.= " pt.code as type_code, pt.libelle as type_libelle"; + + $sql.= " FROM ".MAIN_DB_PREFIX."paiementcharge as t, ".MAIN_DB_PREFIX."c_paiement as pt"; + $sql.= " WHERE t.rowid = ".$id." AND t.fk_typepaiement = pt.id"; + + dol_syslog(get_class($this)."::fetch sql=".$sql, LOG_DEBUG); + $resql=$this->db->query($sql); + if ($resql) + { + if ($this->db->num_rows($resql)) + { + $obj = $this->db->fetch_object($resql); + + $this->id = $obj->rowid; + + $this->fk_charge = $obj->fk_charge; + $this->datec = $this->db->jdate($obj->datec); + $this->tms = $this->db->jdate($obj->tms); + $this->datep = $this->db->jdate($obj->datep); + $this->amount = $obj->amount; + $this->fk_typepaiement = $obj->fk_typepaiement; + $this->num_paiement = $obj->num_paiement; + $this->note = $obj->note; + $this->fk_bank = $obj->fk_bank; + $this->fk_user_creat = $obj->fk_user_creat; + $this->fk_user_modif = $obj->fk_user_modif; + + $this->type_code = $obj->type_code; + $this->type_libelle = $obj->type_libelle; + } + $this->db->free($resql); + + return 1; + } + else + { + $this->error="Error ".$this->db->lasterror(); + dol_syslog(get_class($this)."::fetch ".$this->error, LOG_ERR); + return -1; + } + } + + + /** + * \brief Update database + * \param user User that modify + * \param notrigger 0=launch triggers after, 1=disable triggers + * \return int <0 if KO, >0 if OK + */ + function update($user=0, $notrigger=0) + { + global $conf, $langs; + $error=0; + + // Clean parameters + + if (isset($this->fk_charge)) $this->fk_charge=trim($this->fk_charge); + if (isset($this->amount)) $this->amount=trim($this->amount); + if (isset($this->fk_typepaiement)) $this->fk_typepaiement=trim($this->fk_typepaiement); + if (isset($this->num_paiement)) $this->num_paiement=trim($this->num_paiement); + if (isset($this->note)) $this->note=trim($this->note); + if (isset($this->fk_bank)) $this->fk_bank=trim($this->fk_bank); + if (isset($this->fk_user_creat)) $this->fk_user_creat=trim($this->fk_user_creat); + if (isset($this->fk_user_modif)) $this->fk_user_modif=trim($this->fk_user_modif); + + + + // Check parameters + // Put here code to add control on parameters values + + // Update request + $sql = "UPDATE ".MAIN_DB_PREFIX."paiementcharge SET"; + + $sql.= " fk_charge=".(isset($this->fk_charge)?$this->fk_charge:"null").","; + $sql.= " datec=".(strlen($this->datec)!=0 ? "'".$this->db->idate($this->datec)."'" : 'null').","; + $sql.= " tms=".(strlen($this->tms)!=0 ? "'".$this->db->idate($this->tms)."'" : 'null').","; + $sql.= " datep=".(strlen($this->datep)!=0 ? "'".$this->db->idate($this->datep)."'" : 'null').","; + $sql.= " amount=".(isset($this->amount)?$this->amount:"null").","; + $sql.= " fk_typepaiement=".(isset($this->fk_typepaiement)?$this->fk_typepaiement:"null").","; + $sql.= " num_paiement=".(isset($this->num_paiement)?"'".addslashes($this->num_paiement)."'":"null").","; + $sql.= " note=".(isset($this->note)?"'".addslashes($this->note)."'":"null").","; + $sql.= " fk_bank=".(isset($this->fk_bank)?$this->fk_bank:"null").","; + $sql.= " fk_user_creat=".(isset($this->fk_user_creat)?$this->fk_user_creat:"null").","; + $sql.= " fk_user_modif=".(isset($this->fk_user_modif)?$this->fk_user_modif:"null").""; + + + $sql.= " WHERE rowid=".$this->id; + + $this->db->begin(); + + dol_syslog(get_class($this)."::update sql=".$sql, LOG_DEBUG); + $resql = $this->db->query($sql); + if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } + + if (! $error) + { + if (! $notrigger) + { + // Uncomment this and change MYOBJECT to your own tag if you + // want this action call a trigger. + + //// Call triggers + //include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php"); + //$interface=new Interfaces($this->db); + //$result=$interface->run_triggers('MYOBJECT_MODIFY',$this,$user,$langs,$conf); + //if ($result < 0) { $error++; $this->errors=$interface->errors; } + //// End call triggers + } + } + + // Commit or rollback + if ($error) + { + foreach($this->errors as $errmsg) + { + dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; + } + else + { + $this->db->commit(); + return 1; + } + } + + + /** + * \brief Delete object in database + * \param user User that delete + * \param notrigger 0=launch triggers after, 1=disable triggers + * \return int <0 if KO, >0 if OK + */ + function delete($user, $notrigger=0) + { + global $conf, $langs; + $error=0; + + $sql = "DELETE FROM ".MAIN_DB_PREFIX."paiementcharge"; + $sql.= " WHERE rowid=".$this->id; + + $this->db->begin(); + + dol_syslog(get_class($this)."::delete sql=".$sql); + $resql = $this->db->query($sql); + if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } + + if (! $error) + { + if (! $notrigger) + { + // Uncomment this and change MYOBJECT to your own tag if you + // want this action call a trigger. + + //// Call triggers + //include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php"); + //$interface=new Interfaces($this->db); + //$result=$interface->run_triggers('MYOBJECT_DELETE',$this,$user,$langs,$conf); + //if ($result < 0) { $error++; $this->errors=$interface->errors; } + //// End call triggers + } + } + + // Commit or rollback + if ($error) + { + foreach($this->errors as $errmsg) + { + dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; + } + else + { + $this->db->commit(); + return 1; + } + } + + + + /** + * \brief Load an object from its id and create a new one in database + * \param fromid Id of object to clone + * \return int New id of clone + */ + function createFromClone($fromid) + { + global $user,$langs; + + $error=0; + + $object=new Paiementcharge($this->db); + + $this->db->begin(); + + // Load source object + $object->fetch($fromid); + $object->id=0; + $object->statut=0; + + // Clear fields + // ... + + // Create clone + $result=$object->create($user); + + // Other options + if ($result < 0) + { + $this->error=$object->error; + $error++; + } + + if (! $error) + { + + + + } + + // End + if (! $error) + { + $this->db->commit(); + return $object->id; + } + else + { + $this->db->rollback(); + return -1; + } + } + + + /** + * \brief Initialise object with example values + * \remarks id must be 0 if object instance is a specimen. + */ + function initAsSpecimen() + { + $this->id=0; + + $this->fk_charge=''; + $this->datec=''; + $this->tms=''; + $this->datep=''; + $this->amount=''; + $this->fk_typepaiement=''; + $this->num_paiement=''; + $this->note=''; + $this->fk_bank=''; + $this->fk_user_creat=''; + $this->fk_user_modif=''; + + + } + + + /** * \brief Mise a jour du lien entre le paiement de charge et la ligne dans llx_bank generee * \param id_bank Id de la banque * \return int >0 si OK, <=0 si KO diff --git a/htdocs/compta/paiement_charge.php b/htdocs/compta/paiement_charge.php index 64ffd5e2a55..5b5d29f1d6b 100755 --- a/htdocs/compta/paiement_charge.php +++ b/htdocs/compta/paiement_charge.php @@ -24,7 +24,7 @@ */ include_once("./pre.inc.php"); -include_once("../chargesociales.class.php"); +include_once(DOL_DOCUMENT_ROOT."/chargesociales.class.php"); include_once(DOL_DOCUMENT_ROOT."/compta/bank/account.class.php"); $langs->load("bills"); diff --git a/htdocs/compta/payment_sc/fiche.php b/htdocs/compta/payment_sc/fiche.php new file mode 100644 index 00000000000..0df2e42338e --- /dev/null +++ b/htdocs/compta/payment_sc/fiche.php @@ -0,0 +1,312 @@ + + * Copyright (C) 2004-2010 Laurent Destailleur + * Copyright (C) 2005 Marc Barilley / Ocebo + * Copyright (C) 2005-2009 Regis Houssin + * + * 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. + */ + +/** + * \file htdocs/compta/payment_sc/fiche.php + * \ingroup facture + * \brief Onglet payment of a social contribution + * \remarks Fichier presque identique a fournisseur/paiement/fiche.php + * \version $Id$ + */ + +require('./pre.inc.php'); +require_once(DOL_DOCUMENT_ROOT.'/paiement.class.php'); +include_once(DOL_DOCUMENT_ROOT."/chargesociales.class.php"); +require_once(DOL_DOCUMENT_ROOT.'/facture.class.php'); +require_once(DOL_DOCUMENT_ROOT."/includes/modules/facture/modules_facture.php"); +if ($conf->banque->enabled) require_once(DOL_DOCUMENT_ROOT.'/compta/bank/account.class.php'); + +$langs->load('bills'); +$langs->load('banks'); +$langs->load('companies'); + +// Security check +$id=isset($_GET["id"])?$_GET["id"]:$_POST["id"]; +$action=isset($_GET["action"])?$_GET["action"]:$_POST["action"]; +if ($user->societe_id) $socid=$user->societe_id; +// TODO ajouter regle pour restreindre acces paiement +//$result = restrictedArea($user, 'facture', $id,''); + +$mesg=''; + + +/* + * Actions + */ + +if ($_REQUEST['action'] == 'confirm_delete' && $_REQUEST['confirm'] == 'yes' && $user->rights->facture->paiement) +{ + $db->begin(); + + $paiement = new Paiement($db); + $paiement->fetch($_GET['id']); + $result = $paiement->delete(); + if ($result > 0) + { + $db->commit(); + Header("Location: liste.php"); + exit; + } + else + { + $mesg='
'.$paiement->error.'
'; + $db->rollback(); + } +} + +if ($_REQUEST['action'] == 'confirm_valide' && $_REQUEST['confirm'] == 'yes' && $user->rights->facture->paiement) +{ + $db->begin(); + + $paiement = new Paiement($db); + $paiement->id = $_GET['id']; + if ($paiement->valide() > 0) + { + $db->commit(); + + // \TODO Boucler sur les facture liees a ce paiement et regenerer le pdf + $factures=array(); + foreach($factures as $id) + { + $fac = new Facture($db); + $fac->fetch($id); + + $outputlangs = $langs; + if (! empty($_REQUEST['lang_id'])) + { + $outputlangs = new Translate("",$conf); + $outputlangs->setDefaultLang($_REQUEST['lang_id']); + } + facture_pdf_create($db, $fac->id, '', $fac->modelpdf, $outputlangs); + } + + Header('Location: fiche.php?id='.$paiement->id); + exit; + } + else + { + $mesg='
'.$paiement->error.'
'; + $db->rollback(); + } +} + + +/* + * View + */ + +llxHeader(); + +$paiement = new PaiementCharge($db); +$result=$paiement->fetch($_GET['id']); +if ($result <= 0) +{ + dol_print_error($db,'Payment '.$_GET['id'].' not found in database'); + exit; +} + +$html = new Form($db); + +$h=0; + +$head[$h][0] = DOL_URL_ROOT.'/compta/payment_sc/fiche.php?id='.$_GET["id"]; +$head[$h][1] = $langs->trans("Card"); +$hselected = $h; +$h++; + +/*$head[$h][0] = DOL_URL_ROOT.'/compta/payment_sc/info.php?id='.$_GET["id"]; +$head[$h][1] = $langs->trans("Info"); +$h++; +*/ + + +dol_fiche_head($head, $hselected, $langs->trans("PaymentSocialContribution"), 0, 'payment'); + +/* + * Confirmation de la suppression du paiement + */ +if ($_GET['action'] == 'delete') +{ + $ret=$html->form_confirm('fiche.php?id='.$paiement->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete','',0,2); + if ($ret == 'html') print '
'; +} + +/* + * Confirmation de la validation du paiement + */ +if ($_GET['action'] == 'valide') +{ + $facid = $_GET['facid']; + $ret=$html->form_confirm('fiche.php?id='.$paiement->id.'&facid='.$facid, $langs->trans("ValidatePayment"), $langs->trans("ConfirmValidatePayment"), 'confirm_valide','',0,2); + if ($ret == 'html') print '
'; +} + + +if ($mesg) print $mesg.'
'; + + +print ''; + +// Ref +print ''; + +// Date +print ''; + +// Mode +print ''; + +// Numero +print ''; + +// Montant +print ''; + + +// Note +print ''; + +// Bank account +if ($conf->banque->enabled) +{ + if ($paiement->bank_account) + { + $bankline=new AccountLine($db); + $bankline->fetch($paiement->bank_line); + + print ''; + print ''; + print ''; + print ''; + } +} + +print '
'.$langs->trans('Ref').''.$paiement->id.'
'.$langs->trans('Date').''.dol_print_date($paiement->datep,'day').'
'.$langs->trans('Mode').''.$langs->trans("PaymentType".$paiement->type_code).'
'.$langs->trans('Numero').''.$paiement->num_paiement.'
'.$langs->trans('Amount').''.price($paiement->amount).' '.$langs->trans('Currency'.$conf->monnaie).'
'.$langs->trans('Note').''.nl2br($paiement->note).'
'.$langs->trans('BankTransactionLine').''; + print $bankline->getNomUrl(1,0,'showall'); + print '
'; + + +/* + * List of invoices + */ + +$disable_delete = 0; +$sql = 'SELECT f.rowid as scid, f.libelle, f.paye, pf.amount, pc.libelle as sc_type'; +$sql.= ' FROM '.MAIN_DB_PREFIX.'paiementcharge as pf,'.MAIN_DB_PREFIX.'chargesociales as f, '.MAIN_DB_PREFIX.'c_chargesociales as pc'; +$sql.= ' WHERE pf.fk_charge = f.rowid AND pf.fk_typepaiement = pc.id'; +$sql.= ' AND f.entity = '.$conf->entity; +$sql.= ' AND pf.rowid = '.$paiement->id; +$resql=$db->query($sql); +if ($resql) +{ + $num = $db->num_rows($resql); + + $i = 0; + $total = 0; + print '
'; + print ''; + print ''; + print ''; + print ''; + print ''; + print "\n"; + + if ($num > 0) + { + $var=True; + + $socialcontribstatic=new ChargeSociales($db); + + while ($i < $num) + { + $objp = $db->fetch_object($resql); + $var=!$var; + print ''; + print '\n"; + print ''; + print ''; + print ''; + print "\n"; + if ($objp->paye == 1) // If at least one invoice is paid, disable delete + { + $disable_delete = 1; + } + $total = $total + $objp->amount; + $i++; + } + } + $var=!$var; + + print "
'.$langs->trans('SocialContribution').''.$langs->trans('Label').''.$langs->trans('Status').''.$langs->trans('AmountTTC').'
'; + $socialcontribstatic->id=$objp->scid; + $socialcontribstatic->ref=$objp->scid; + $socialcontribstatic->lib=$objp->sc_type; + print $socialcontribstatic->getNomUrl(1); + print "'.$objp->libelle.''.$socialcontribstatic->LibStatut($objp->fk_statut,2).''.price($objp->amount).'
\n"; + $db->free($resql); +} +else +{ + dol_print_error($db); +} + +print ''; + + +/* + * Boutons Actions + */ +/* +print '
'; + +if ($conf->global->BILL_ADD_PAYMENT_VALIDATION) +{ + if ($user->societe_id == 0 && $paiement->statut == 0 && $_GET['action'] == '') + { + if ($user->rights->facture->paiement) + { + print ''.$langs->trans('Valid').''; + } + } +} + +if ($user->societe_id == 0 && $_GET['action'] == '') +{ + if ($user->rights->facture->paiement) + { + if (! $disable_delete) + { + print ''.$langs->trans('Delete').''; + } + else + { + print ''.$langs->trans('Delete').''; + } + } +} + +print '
'; +*/ + +$db->close(); + +llxFooter('$Date$ - $Revision$'); +?> diff --git a/htdocs/compta/payment_sc/pre.inc.php b/htdocs/compta/payment_sc/pre.inc.php new file mode 100644 index 00000000000..f623b981737 --- /dev/null +++ b/htdocs/compta/payment_sc/pre.inc.php @@ -0,0 +1,50 @@ + + * Copyright (C) 2005 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. + */ + +/** + * \file htdocs/compta/paiement/pre.inc.php + * \ingroup compta + * \brief Fichier gestionnaire du menu compta paiement + * \version $Id$ + */ + +require("../../main.inc.php"); + +$langs->load("bills"); +$langs->load("compta"); +$langs->load("propal"); + +function llxHeader($head = '', $title='', $help_url='') +{ + global $user, $conf, $langs; + $langs->load("compta"); + $langs->load("propal"); + + top_menu($head, $title, $target); + + $menu = new Menu(); + + $menu->add("index.php",$langs->trans("Contributions")); + + $menu->add_submenu(DOL_URL_ROOT."/compta/sociales/index.php",$langs->trans("SocialContributions")); + + left_menu($menu->liste); +} + +?> diff --git a/htdocs/compta/sociales/charges.php b/htdocs/compta/sociales/charges.php index 27a883276bb..932985f6696 100644 --- a/htdocs/compta/sociales/charges.php +++ b/htdocs/compta/sociales/charges.php @@ -327,8 +327,8 @@ if ($chid > 0) /* * Paiements */ - $sql = "SELECT ".$db->pdate("datep")." as dp, p.amount,"; - $sql.= "c.libelle as paiement_type, p.num_paiement, p.rowid"; + $sql = "SELECT p.rowid, p.num_paiement, datep as dp, p.amount,"; + $sql.= "c.libelle as paiement_type"; $sql.= " FROM ".MAIN_DB_PREFIX."paiementcharge as p"; $sql.= ", ".MAIN_DB_PREFIX."c_paiement as c "; $sql.= ", ".MAIN_DB_PREFIX."chargesociales as s"; @@ -338,6 +338,7 @@ if ($chid > 0) $sql.= " AND p.fk_typepaiement = c.id"; $sql.= " ORDER BY dp DESC"; + //print $sql; $resql = $db->query($sql); if ($resql) { @@ -354,9 +355,9 @@ if ($chid > 0) $objp = $db->fetch_object($resql); $var=!$var; print ""; - print img_object($langs->trans("Payment"),"payment").' '; - print dol_print_date($objp->dp)."\n"; - print "$objp->paiement_type $objp->num_paiement\n"; + print ''.img_object($langs->trans("Payment"),"payment").' '; + print dol_print_date($db->jdate($objp->dp))."\n"; + print "".$objp->paiement_type.' '.$objp->num_paiement."\n"; print ''.price($objp->amount)." ".$langs->trans("Currency".$conf->monnaie)."\n"; print ""; $totalpaye += $objp->amount;