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 '