From f5f8a498bdb151cc5a338999d09049a49fbd150b Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 25 Jun 2007 00:02:37 +0000 Subject: [PATCH] Fix: Debuggage saisie charge sociale New: Possiblite modifier libelle charge sociale. --- htdocs/chargesociales.class.php | 74 ++++++-- htdocs/compta/bank/account.class.php | 22 +-- htdocs/compta/paiement_charge.php | 15 +- htdocs/compta/sociales/charges.php | 176 ++++++++++++++++-- htdocs/compta/sociales/index.php | 109 +---------- htdocs/compta/sociales/pre.inc.php | 5 +- .../menus/barre_left/eldy_backoffice.php | 3 +- htdocs/langs/en_US/compta.lang | 2 + htdocs/langs/en_US/main.lang | 1 + htdocs/langs/fr_FR/compta.lang | 2 + htdocs/langs/fr_FR/main.lang | 1 + 11 files changed, 256 insertions(+), 154 deletions(-) diff --git a/htdocs/chargesociales.class.php b/htdocs/chargesociales.class.php index 0cddc16798e..726d3631ed1 100644 --- a/htdocs/chargesociales.class.php +++ b/htdocs/chargesociales.class.php @@ -102,25 +102,42 @@ class ChargeSociales /** * \brief Crée une charge sociale * \param user Utilisateur qui crée - * \return int <0 si erreur, >0 si ok + * \return int <0 si KO, id charge créée si OK */ function create($user) { + // Nettoyage parametres + $newamount=price2num($this->amount,'MT'); + + // Validation parametres + if (! $newamount > 0) + { + $this->error="ErrorBadParameter"; + return -2; + } + + $this->db->begin(); + $sql = "INSERT INTO ".MAIN_DB_PREFIX."chargesociales (fk_type, libelle, date_ech, periode, amount)"; $sql.= " VALUES (".$this->type.",'".addslashes($this->lib)."',"; $sql.= "'".$this->date_ech."','".$this->periode."',"; - $sql.= "'".$this->amount."'"; - $sql.= ')'; + $sql.= " ".$newamount; + $sql.= ")"; dolibarr_syslog("ChargesSociales::create sql=".$sql); $resql=$this->db->query($sql); if ($resql) { - return 1; + $this->id=$this->db->last_insert_id(MAIN_DB_PREFIX."chargesociales"); + + //dolibarr_syslog("ChargesSociales::create this->id=".$this->id); + $this->db->commit(); + return $this->id; } else { $this->error=$this->db->error(); + $this->db->rollback(); return -1; } } @@ -148,6 +165,38 @@ class ChargeSociales } } + + /** + * \brief Met a jour une charge sociale + * \param user Utilisateur qui modifie + * \return int <0 si erreur, >0 si ok + */ + function update($user) + { + $this->db->begin(); + + $sql = "UPDATE ".MAIN_DB_PREFIX."chargesociales"; + $sql.= " SET libelle='".addslashes($this->lib)."',"; + $sql.= " date_ech='".$this->date_ech."',"; + $sql.= " periode='".$this->periode."'"; + $sql.= " WHERE rowid=".$this->id; + + dolibarr_syslog("ChargesSociales::update sql=".$sql); + $resql=$this->db->query($sql); + if ($resql) + { + $this->db->commit(); + return 1; + } + else + { + $this->error=$this->db->error(); + $this->db->rollback(); + return -1; + } + } + + function solde($year = 0) { $sql = "SELECT sum(f.amount) as amount"; @@ -293,26 +342,25 @@ class PaiementCharge */ function create($user) { + global $conf; + $error = 0; - $this->db->begin(); - $total = 0; + $total=0; foreach ($this->amounts as $key => $value) { $facid = $key; - $value = trim($value); - $amount = round(price2num($value), 2); // Un round est ok si nb avec '.' - if (is_numeric($amount)) $total += $amount; + $amount = price2num(trim($value), 'MT'); + $total += $amount; } - $total = price2num($total); 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)"; + $sql .= " VALUES ($this->chid, now(), ".$this->db->idate($this->datepaye).", ".price2num($total).", $this->paiementtype, '$this->num_paiement', '$this->note', $user->id)"; - dolibarr_syslog("PaiementCharges::create sql=".$sql); + dolibarr_syslog("PaiementCharge::create sql=".$sql); $resql=$this->db->query($sql); if ($resql) { @@ -342,7 +390,7 @@ class PaiementCharge /** * \brief Mise a jour du lien entre le paiement de charge et la ligne dans llx_bank générée * \param id_bank Id de la banque - * \return int 1 ou 0 + * \return int >0 si OK, <=0 si KO */ function update_fk_bank($id_bank) { diff --git a/htdocs/compta/bank/account.class.php b/htdocs/compta/bank/account.class.php index 1e562c8ca67..3f0470ebd9b 100644 --- a/htdocs/compta/bank/account.class.php +++ b/htdocs/compta/bank/account.class.php @@ -174,18 +174,6 @@ class Account // Nettoyage parametres $emetteur=trim($emetteur); $banque=trim($banque); - - dolibarr_syslog("Account::Addline: date=".$date.", oper=".$oper.", label=".$label.", amount=".$amount.", num_chq=".$num_chq.", categorie=".$categorie.", user=".$user->id); - - // Verififcation parametres - if (! $this->rowid) - { - $this->error="Account::addline this->rowid not defined"; - return -1; - } - - $this->db->begin(); - switch ($oper) { case 1: @@ -210,7 +198,16 @@ class Account $oper = 'CHQ'; break; } + + // Verification parametres + if (! $this->rowid) + { + $this->error="Account::addline this->rowid not defined"; + return -1; + } + $this->db->begin(); + $datev = $date; $sql = "INSERT INTO ".MAIN_DB_PREFIX."bank (datec, dateo, datev, label, amount, fk_user_author, num_chq, fk_account, fk_type,emetteur,banque)"; @@ -223,6 +220,7 @@ class Account $sql.= " ".($banque?"'".addslashes($banque)."'":"null"); $sql.= ")"; + dolibarr_syslog("Account::addline sql=".$sql); if ($this->db->query($sql)) { $rowid = $this->db->last_insert_id(MAIN_DB_PREFIX."bank"); diff --git a/htdocs/compta/paiement_charge.php b/htdocs/compta/paiement_charge.php index e740d1952e8..8ce20f560cc 100755 --- a/htdocs/compta/paiement_charge.php +++ b/htdocs/compta/paiement_charge.php @@ -56,11 +56,8 @@ if ($_POST["action"] == 'add_paiement') if ($_POST["paiementtype"] > 0) { - - $datepaye = $db->idate(dolibarr_mktime(12, 0 , 0, - $_POST["remonth"], - $_POST["reday"], - $_POST["reyear"])); + $datepaye = dolibarr_mktime(12, 0 , 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]); + //print "x".dolibarr_print_date($datepaye,'dayhour'); $paiement_id = 0; $amounts = array(); @@ -94,14 +91,13 @@ if ($_POST["action"] == 'add_paiement') { $chid = $key; $value = trim($value); - $amount = round(price2num($value), 2); // Un round est ok si nb avec '.' - if (is_numeric($amount)) $total += $amount; + $amount = price2num(trim($value), 'MT'); // Un round est ok si nb avec '.' + $total += $amount; } - $total = price2num($total); // Insertion dans llx_bank $langs->load("banks"); - $label = $langs->trans("SocialContributionPayment"); + $label = $langs->transnoentities("SocialContributionPayment"); $acc = new Account($db, $_POST["accountid"]); $bank_line_id = $acc->addline($paiement->datepaye, $paiement->paiementtype, $label, -abs($total), $paiement->num_paiement, '', $user); @@ -172,6 +168,7 @@ if ($_GET["action"] == 'create') print '
'; print "id\">"; print ''; + print ''; print ""; diff --git a/htdocs/compta/sociales/charges.php b/htdocs/compta/sociales/charges.php index 3ca8210ea75..74e3892c5d2 100644 --- a/htdocs/compta/sociales/charges.php +++ b/htdocs/compta/sociales/charges.php @@ -91,10 +91,155 @@ if ($_POST["action"] == 'confirm_delete') } } +/* + * Ajout d'une charge sociale + */ + +if ($_POST["action"] == 'add' && $user->rights->tax->charges->creer) +{ + if (! $_POST["date"]) + { + $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("DateDue")).'
'; + $_GET["action"] = 'create'; + } + elseif (! $_POST["period"]) + { + $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Period")).'
'; + $_GET["action"] = 'create'; + } + elseif (! $_POST["amount"]) + { + $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Amount")).'
'; + $_GET["action"] = 'create'; + } + else + { + $chargesociales=new ChargeSociales($db); + + $chargesociales->type=$_POST["type"]; + $chargesociales->lib=$_POST["label"]; + $chargesociales->date_ech=$_POST["date"]; + $chargesociales->periode=$_POST["period"]; + $chargesociales->amount=$_POST["amount"]; + + $chid=$chargesociales->create($user); + if ($chid > 0) + { + //$mesg='
'.$langs->trans("SocialContributionAdded").'
'; + } + else + { + $mesg='
'.$chargesociales->error.'
'; + } + } +} +if ($_GET["action"] == 'update' && ! $_POST["cancel"] && $user->rights->tax->charges->creer) +{ + if (! $_POST["date"]) + { + $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("DateDue")).'
'; + $_GET["action"] = 'edit'; + } + elseif (! $_POST["period"]) + { + $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Period")).'
'; + $_GET["action"] = 'edit'; + } + else + { + $chargesociales=new ChargeSociales($db); + $result=$chargesociales->fetch($_GET["id"]); + + $chargesociales->lib=$_POST["label"]; + $chargesociales->date_ech=$_POST["date"]; + $chargesociales->periode=$_POST["period"]; + + $result=$chargesociales->update($user); + if ($result > 0) + { + //$mesg='
'.$langs->trans("SocialContributionAdded").'
'; + } + else + { + $mesg='
'.$chargesociales->error.'
'; + } + } +} + llxHeader(); +/* + * Mode creation + * + */ +if ($_GET["action"] == 'create') +{ + print_fiche_titre($langs->trans("NewSocialContribution")); + print "
\n"; + + if ($mesg) print $mesg.'
'; + + $var=false; + + print ''; + print ''; + + print "
Charge
"; + print ""; + print ''; + print "\n"; + + print ''; + print ''; + print ''; + print ''; + + print ''; + + print ''; + + print ''; + + print ''; + print ''; + + print '
'; + print ' '; + print ''; + print $langs->trans("DateDue"); + print ''; + print $langs->trans("Period"); + print ''; + print $langs->trans("Type"); + print ''; + print $langs->trans("Label"); + print ''; + print $langs->trans("Amount"); + print ''; + print ' '; + print '
 
YYYYMMDD

YYYYMMDD
'; + print '
'; + + print '
'; +} + /* *************************************************************************** */ /* */ /* Mode fiche */ @@ -139,7 +284,7 @@ if ($chid > 0) print '
'; } - print "
id&action=update\" method=\"post\">"; + if ($_GET['action'] == 'edit') print "id&action=update\" method=\"post\">"; print ''; @@ -151,7 +296,7 @@ if ($chid > 0) print "'; print '"; } else { @@ -232,19 +377,28 @@ if ($chid > 0) print ''; print ''; + + if ($_GET['action'] == 'edit') + { + print ''; + } + print '
"; if ($cha->paye==0 && $_GET['action'] == 'edit') { - print "period)."\">"; + print "periode)."\">"; } else { @@ -219,10 +364,10 @@ if ($chid > 0) if ($cha->paye==0 && $_GET['action'] == 'edit') { print '
'.$langs->trans("Label").''; - print ''; + print ''; print '
'.$langs->trans("DateDue").""; - print "date_ech)."\">"; + print "date_ech)."\">"; print "
'.$langs->trans("AmountTTC").''.price($cha->amount).'
'.$langs->trans("Status").''.$cha->getLibStatut(4).'
'; + print ''; + print '   '; + print ''; + print '
'; - - print "
\n"; + if ($_GET['action'] == 'edit') print "\n"; print ''; - if (! $_GET["action"]) - { - /* - * Boutons actions - */ + /* + * Boutons actions + */ + if (! $_GET["action"] || $_GET["action"] == 'update') + { print "
\n"; // Editer diff --git a/htdocs/compta/sociales/index.php b/htdocs/compta/sociales/index.php index 3d12358c3d8..0bed02b8fa7 100644 --- a/htdocs/compta/sociales/index.php +++ b/htdocs/compta/sociales/index.php @@ -56,47 +56,6 @@ $filtre=$_GET["filtre"]; -/* - * Ajout d'une charge sociale - */ - -if ($_POST["action"] == 'add') -{ - if (! $_POST["date"]) - { - $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("DateDue")).'
'; - } - elseif (! $_POST["periode"]) - { - $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Period")).'
'; - } - elseif (! $_POST["amount"]) - { - $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Amount")).'
'; - } - else - { - $chargesociales=new ChargeSociales($db); - - $chargesociales->type=$_POST["type"]; - $chargesociales->lib=$_POST["libelle"]; - $chargesociales->date_ech=$_POST["date"]; - $chargesociales->period=$_POST["period"]; - $chargesociales->amount=$_POST["amount"]; - - $result=$chargesociales->create($user); - if ($result > 0) - { - $mesg='
'.$langs->trans("SocialContributionAdded").'
'; - } - else - { - $mesg='
'.$chargesociales->error.'
'; - } - } -} - - /* * Affichage liste et formulaire des charges. @@ -107,75 +66,13 @@ llxHeader(); print_fiche_titre($langs->trans("SocialContributions"),($year?"".img_previous()." ".$langs->trans("Year")." $year ".img_next()."":"")); print "
\n"; -if ($mesg) { - print "$mesg
"; +if ($mesg) +{ + print $mesg."
"; } print ""; -/* - * Forumalaire d'ajout d'une charge - * - */ -if ($user->rights->tax->charges->creer) { - $var=false; - - print ""; - print ''; - print "\n"; - - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - - print ''; - print ''; - print ''; - - print ''; - print ''; - - print ''; - - print ''; - -} - print ""; print_liste_field_titre($langs->trans("Ref"),"index.php","id","","","",$sortfield); print_liste_field_titre($langs->trans("DateDue"),"index.php","de","","","",$sortfield); diff --git a/htdocs/compta/sociales/pre.inc.php b/htdocs/compta/sociales/pre.inc.php index 6e94ce80a86..02e40f3057f 100644 --- a/htdocs/compta/sociales/pre.inc.php +++ b/htdocs/compta/sociales/pre.inc.php @@ -38,8 +38,9 @@ function llxHeader($head = "") $menu = new Menu(); - $menu->add("../charges/",$langs->trans("Contributions")); - $menu->add_submenu("index.php",$langs->trans("SocialContributions")); + $menu->add(DOL_URL_ROOT."/compta/charges/index.php",$langs->trans("Contributions")); + $menu->add_submenu(DOL_URL_ROOT."/compta/sociales/charges.php?action=create",$langs->trans("MenuNewSocialContribution")); + $menu->add_submenu(DOL_URL_ROOT."/compta/sociales/index.php",$langs->trans("List")); left_menu($menu->liste); } diff --git a/htdocs/includes/menus/barre_left/eldy_backoffice.php b/htdocs/includes/menus/barre_left/eldy_backoffice.php index eaa78947784..3fb1b1668d2 100644 --- a/htdocs/includes/menus/barre_left/eldy_backoffice.php +++ b/htdocs/includes/menus/barre_left/eldy_backoffice.php @@ -443,7 +443,8 @@ class MenuLeft { if ($conf->tax->enabled) { $newmenu->add(DOL_URL_ROOT."/compta/charges/index.php?leftmenu=charges&mainmenu=accountancy",$langs->trans("Charges"), 0, $user->rights->tax->charges->lire); - if ($leftmenu=="charges") $newmenu->add_submenu(DOL_URL_ROOT."/compta/sociales/index.php",$langs->trans("SocialContributions"), 1, $user->rights->tax->charges->lire); + if ($leftmenu=="charges") $newmenu->add_submenu(DOL_URL_ROOT."/compta/sociales/charges.php?action=create",$langs->trans("MenuNewSocialContribution"), 1, $user->rights->tax->charges->creer); + if ($leftmenu=="charges") $newmenu->add_submenu(DOL_URL_ROOT."/compta/sociales/index.php",$langs->trans("List"), 1, $user->rights->tax->charges->lire); } // Charges tva diff --git a/htdocs/langs/en_US/compta.lang b/htdocs/langs/en_US/compta.lang index 0e405bad38c..b26951e62cd 100644 --- a/htdocs/langs/en_US/compta.lang +++ b/htdocs/langs/en_US/compta.lang @@ -30,6 +30,8 @@ VATPayed=VAT payed VATCollected=VAT collected SocialContribution=Social contribution SocialContributions=Social contributions +MenuNewSocialContribution=New social contribution +NewSocialContribution=New social contribution ContributionsToPay=Contributions to pay AccountancyTreasuryArea=Accountancy/Treasury area AccountancySetup=Accountancy setup diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang index 8825f3b122a..d9bad2284f9 100644 --- a/htdocs/langs/en_US/main.lang +++ b/htdocs/langs/en_US/main.lang @@ -63,6 +63,7 @@ Home=Home Help=Help Always=Always Never=Never +Period=Period Activate=Activate Activated=Activated Closed=Closed diff --git a/htdocs/langs/fr_FR/compta.lang b/htdocs/langs/fr_FR/compta.lang index 20f0352a20d..a683ac09a33 100644 --- a/htdocs/langs/fr_FR/compta.lang +++ b/htdocs/langs/fr_FR/compta.lang @@ -30,6 +30,8 @@ VATPayed=TVA pay VATCollected=TVA récupérée SocialContribution=Charge sociale SocialContributions=Charges sociales +MenuNewSocialContribution=Nouvelle charge sociale +NewSocialContribution=Nouvelle charge sociale ContributionsToPay=Charges à payer AccountancyTreasuryArea=Espace Compta/Tréso AccountancySetup=Configuration compta diff --git a/htdocs/langs/fr_FR/main.lang b/htdocs/langs/fr_FR/main.lang index a2b8e1494a1..be7b02f5834 100644 --- a/htdocs/langs/fr_FR/main.lang +++ b/htdocs/langs/fr_FR/main.lang @@ -63,6 +63,7 @@ Home=Accueil Help=Aide Always=Toujours Never=Jamais +Period=Période Activate=Activer Activated=Activé Closed=Clôturé
'; - print ' '; - print ''; - print $langs->trans("DateDue"); - print ''; - print $langs->trans("Period"); - print ''; - print $langs->trans("Type"); - print ''; - print $langs->trans("Label"); - print ''; - print $langs->trans("Amount"); - print ''; - print ' '; - print '
 
YYYYMMDD

YYYYMMDD
'; - print '