diff --git a/htdocs/compta/paiement.php b/htdocs/compta/paiement.php index 022028257f2..e38af4c4dee 100644 --- a/htdocs/compta/paiement.php +++ b/htdocs/compta/paiement.php @@ -158,7 +158,7 @@ if ($_POST['action'] == 'confirm_paiement' && $_POST['confirm'] == 'yes') if (! $error) { $paiement_id = $paiement->create($user); - if (! $paiement_id > 0) + if ($paiement_id < 0) { $errmsg=$paiement->error; $error++; @@ -168,7 +168,7 @@ if ($_POST['action'] == 'confirm_paiement' && $_POST['confirm'] == 'yes') if (! $error) { $result=$paiement->addPaymentToBank($user,'payment','(CustomerInvoicePayment)',$_POST['accountid'],$_POST['chqemetteur'],$_POST['chqbank']); - if (! $result > 0) + if ($result < 0) { $errmsg=$paiement->error; $error++; diff --git a/htdocs/compta/paiement/class/paiement.class.php b/htdocs/compta/paiement/class/paiement.class.php index b05008c2648..3d080e1f7a6 100644 --- a/htdocs/compta/paiement/class/paiement.class.php +++ b/htdocs/compta/paiement/class/paiement.class.php @@ -32,7 +32,12 @@ */ class Paiement { - var $id; + var $db; + var $error; + var $element='payment'; + var $table_element='paiement'; + + var $id; var $ref; var $facid; var $datepaye; @@ -49,8 +54,6 @@ class Paiement // fk_paiement dans llx_paiement est l'id du type de paiement (7 pour CHQ, ...) // fk_paiement dans llx_paiement_facture est le rowid du paiement - var $db; - /** * \brief Constructeur de la classe @@ -352,47 +355,53 @@ class Paiement } // Add link 'payment', 'payment_supplier' in bank_url between payment and bank transaction - $url=''; - if ($mode == 'payment') $url=DOL_URL_ROOT.'/compta/paiement/fiche.php?id='; - if ($mode == 'payment_supplier') $url=DOL_URL_ROOT.'/fourn/paiement/fiche.php?id='; - if ($url) + if ( ! $error) { - $result=$acc->add_url_line($bank_line_id, $this->id, $url, '(paiement)', $mode); - if ($result <= 0) + $url=''; + if ($mode == 'payment') $url=DOL_URL_ROOT.'/compta/paiement/fiche.php?id='; + if ($mode == 'payment_supplier') $url=DOL_URL_ROOT.'/fourn/paiement/fiche.php?id='; + if ($url) { - $error++; - dol_print_error($this->db); + $result=$acc->add_url_line($bank_line_id, $this->id, $url, '(paiement)', $mode); + if ($result <= 0) + { + $error++; + dol_print_error($this->db); + } } } // Add link 'company' in bank_url between invoice and bank transaction (for each invoice concerned by payment) - $linkaddedforthirdparty=array(); - foreach ($this->amounts as $key => $value) + if (! $error) { - if ($mode == 'payment') + $linkaddedforthirdparty=array(); + foreach ($this->amounts as $key => $value) { - $fac = new Facture($this->db); - $fac->fetch($key); - $fac->fetch_thirdparty(); // This should be always same third party but we loop in case of. - if (! in_array($fac->client->id,$linkaddedforthirdparty)) // Not yet done for this thirdparty + if ($mode == 'payment') { - $result=$acc->add_url_line($bank_line_id, $fac->client->id, - DOL_URL_ROOT.'/compta/fiche.php?socid=', $fac->client->nom, 'company'); - if ($result <= 0) dol_print_error($this->db); - $linkaddedforthirdparty[$fac->client->id]=$fac->client->id; // Mark as done for this thirdparty + $fac = new Facture($this->db); + $fac->fetch($key); + $fac->fetch_thirdparty(); // This should be always same third party but we loop in case of. + if (! in_array($fac->client->id,$linkaddedforthirdparty)) // Not yet done for this thirdparty + { + $result=$acc->add_url_line($bank_line_id, $fac->client->id, + DOL_URL_ROOT.'/compta/fiche.php?socid=', $fac->client->nom, 'company'); + if ($result <= 0) dol_print_error($this->db); + $linkaddedforthirdparty[$fac->client->id]=$fac->client->id; // Mark as done for this thirdparty + } } - } - if ($mode == 'payment_supplier') - { - $fac = new FactureFournisseur($this->db); - $fac->fetch($key); - $fac->fetch_fournisseur(); // This should be always same third party but we loop in case of. - if (! in_array($fac->client->id,$linkaddedforthirdparty)) // Not yet done for this thirdparty + if ($mode == 'payment_supplier') { - $result=$acc->add_url_line($bank_line_id, $fac->fournisseur->id, - DOL_URL_ROOT.'/fourn/fiche.php?socid=', $fac->fournisseur->nom, 'company'); - if ($result <= 0) dol_print_error($this->db); - $linkaddedforthirdparty[$fac->fournisseur->id]=$fac->fournisseur->id; // Mark as done for this thirdparty + $fac = new FactureFournisseur($this->db); + $fac->fetch($key); + $fac->fetch_fournisseur(); // This should be always same third party but we loop in case of. + if (! in_array($fac->client->id,$linkaddedforthirdparty)) // Not yet done for this thirdparty + { + $result=$acc->add_url_line($bank_line_id, $fac->fournisseur->id, + DOL_URL_ROOT.'/fourn/fiche.php?socid=', $fac->fournisseur->nom, 'company'); + if ($result <= 0) dol_print_error($this->db); + $linkaddedforthirdparty[$fac->fournisseur->id]=$fac->fournisseur->id; // Mark as done for this thirdparty + } } } } @@ -416,12 +425,12 @@ class Paiement /** - * \brief Mise a jour du lien entre le paiement et la ligne generee dans llx_bank - * \param id_bank Id compte bancaire + * Mise a jour du lien entre le paiement et la ligne generee dans llx_bank + * @param id_bank Id compte bancaire */ function update_fk_bank($id_bank) { - $sql = 'UPDATE llx_paiement set fk_bank = '.$id_bank; + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' set fk_bank = '.$id_bank; $sql.= ' WHERE rowid = '.$this->id; dol_syslog(get_class($this).'::update_fk_bank sql='.$sql); @@ -432,18 +441,19 @@ class Paiement } else { - dol_print_error($this->db); - return 0; + $this->error=$this->db->lasterror(); + dol_syslog(get_class($this).'::update_fk_bank '.$this->error); + return -1; } } /** - * \brief Valide le paiement - * \return int <0 si ko, >0 si ok + * Validate payment + * @return int <0 if KO, >0 if OK */ function valide() { - $sql = 'UPDATE '.MAIN_DB_PREFIX.'paiement SET statut = 1 WHERE rowid = '.$this->id; + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' SET statut = 1 WHERE rowid = '.$this->id; dol_syslog(get_class($this).'::valide sql='.$sql); $result = $this->db->query($sql); @@ -453,7 +463,8 @@ class Paiement } else { - dol_syslog(get_class($this).'::valide Error -1'); + $this->error=$this->db->lasterror(); + dol_syslog(get_class($this).'::valide '.$this->error); return -1; } } diff --git a/htdocs/fourn/class/paiementfourn.class.php b/htdocs/fourn/class/paiementfourn.class.php index b6e82ed4a8f..a4f2dd76916 100644 --- a/htdocs/fourn/class/paiementfourn.class.php +++ b/htdocs/fourn/class/paiementfourn.class.php @@ -26,17 +26,21 @@ \remarks Cette classe est presque identique a paiement.class.php \version $Id$ */ - require_once(DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'); +require_once(DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php'); /** \class PaiementFourn \brief Classe permettant la gestion des paiements des factures fournisseurs */ - -class PaiementFourn +class PaiementFourn extends Paiement { - var $id; + var $db; + var $error; + var $element='payment_supplier'; + var $table_element='paiementfourn'; + + var $id; var $ref; var $facid; var $datepaye; @@ -54,8 +58,6 @@ class PaiementFourn // fk_paiement dans llx_paiement est l'id du type de paiement (7 pour CHQ, ...) // fk_paiement dans llx_paiement_facture est le rowid du paiement - var $db; - /** * \brief Constructeur de la classe * \param DB handler acces base de donnees @@ -294,48 +296,6 @@ class PaiementFourn } } - /** - * \brief Mise a jour du lien entre le paiement et la ligne generee dans llx_bank - * \param id_bank Id compte bancaire - */ - function update_fk_bank($id_bank) - { - $sql = 'UPDATE '.MAIN_DB_PREFIX.'paiementfourn set fk_bank = '.$id_bank; - $sql.= ' WHERE rowid = '.$this->id; - $result = $this->db->query($sql); - if ($result) - { - return 1; - } - else - { - dol_print_error($this->db); - return 0; - } - } - - /** - * \brief Valide le paiement - * \return int <0 si ko, >0 si ok - */ - function valide() - { - $sql = 'UPDATE '.MAIN_DB_PREFIX.'paiementfourn SET statut = 1 WHERE rowid = '.$this->id; - - dol_syslog("PaiementFourn::valide sql=".$sql); - $result = $this->db->query($sql); - if ($result) - { - return 0; - } - else - { - $this->error='Paiement::Valide Error -1 '.$this->db->error(); - dol_syslog('PaiementFourn::valide error '.$this->error, LOG_ERR); - return -1; - } - } - /* * \brief Information sur l'objet * \param id id du paiement dont il faut afficher les infos diff --git a/htdocs/fourn/facture/paiement.php b/htdocs/fourn/facture/paiement.php index 95355101001..7cdb22af9b7 100644 --- a/htdocs/fourn/facture/paiement.php +++ b/htdocs/fourn/facture/paiement.php @@ -136,7 +136,7 @@ if ($action == 'add_paiement') if (! $error) { $result=$paiement->addPaymentToBank($user,'payment_supplier','(SupplierInvoicePayment)',$_POST['accountid'],'',''); - if (! $result > 0) + if ($result < 0) { $errmsg='