diff --git a/htdocs/compta/bank/class/account.class.php b/htdocs/compta/bank/class/account.class.php
index 682c5d4808d..549ff685c8d 100644
--- a/htdocs/compta/bank/class/account.class.php
+++ b/htdocs/compta/bank/class/account.class.php
@@ -140,7 +140,8 @@ class Account extends CommonObject
}
else
{
- $this->error=$this->db->error();
+ $this->error=$this->db->lasterror();
+ dol_syslog("Account:add_url_line ".$this->error, LOG_ERR);
return -1;
}
}
@@ -186,7 +187,7 @@ class Account extends CommonObject
/**
* \brief Ajoute une entree dans la table ".MAIN_DB_PREFIX."bank
* \param $date Date operation
- * \param $oper 1,2,3,4... or TYP,VIR,PRE,LIQ,VAD,CB,CHQ...
+ * \param $oper 1,2,3,4... (deprecated) or TYP,VIR,PRE,LIQ,VAD,CB,CHQ...
* \param $label Descripton
* \param $amount Montant
* \param $num_chq Numero cheque ou virement
@@ -201,29 +202,21 @@ class Account extends CommonObject
// Clean parameters
$emetteur=trim($emetteur);
$banque=trim($banque);
- switch ($oper)
+ if (is_numeric($oper)) // Clean oper to have a code instead of a rowid
{
- case 1:
- $oper = 'TIP';
- break;
- case 2:
- $oper = 'VIR';
- break;
- case 3:
- $oper = 'PRE';
- break;
- case 4:
- $oper = 'LIQ';
- break;
- case 5:
- $oper = 'VAD';
- break;
- case 6:
- $oper = 'CB';
- break;
- case 7:
- $oper = 'CHQ';
- break;
+ $sql ="SELECT code FROM ".MAIN_DB_PREFIX."c_paiement";
+ $sql.=" WHERE id=".$oper;
+ $resql=$this->db->query($sql);
+ if ($resql)
+ {
+ $obj=$this->db->fetch_object($resql);
+ $oper=$obj->code;
+ }
+ else
+ {
+ dol_print_error($this->db,'Failed to get payment type code');
+ return -1;
+ }
}
// Check parameters
diff --git a/htdocs/compta/paiement.php b/htdocs/compta/paiement.php
index fef83324fa6..2b64fd5f92f 100644
--- a/htdocs/compta/paiement.php
+++ b/htdocs/compta/paiement.php
@@ -94,7 +94,7 @@ if ($_POST['action'] == 'add_paiement' || ($_POST['action'] == 'confirm_paiement
// d'un paiement
if (! $_POST['accountid'])
{
- $fiche_erreur_message = '
'.$langs->trans('ErrorFieldRequired',$langs->transnoentities('AccountToCredit')).'
';
+ $fiche_erreur_message = ''.$langs->trans('ErrorFieldRequired',$langs->transnoentities('AccountToCredit')).'
';
$error++;
}
}
@@ -153,7 +153,7 @@ if ($_POST['action'] == 'confirm_paiement' && $_POST['confirm'] == 'yes')
{
if ($conf->banque->enabled)
{
- // Insertion dans llx_bank
+ // Insert payment into llx_bank
$label = "(CustomerInvoicePayment)";
$acc = new Account($db, $_POST['accountid']);
@@ -162,7 +162,7 @@ if ($_POST['action'] == 'confirm_paiement' && $_POST['confirm'] == 'yes')
$label,
$totalpaiement,
$paiement->num_paiement,
- '',
+ '',
$user,
$_POST['chqemetteur'],
$_POST['chqbank']);
@@ -171,24 +171,30 @@ if ($_POST['action'] == 'confirm_paiement' && $_POST['confirm'] == 'yes')
// On connait ainsi le paiement qui a genere l'ecriture bancaire
if ($bank_line_id > 0)
{
- $paiement->update_fk_bank($bank_line_id);
- // Mise a jour liens (pour chaque facture concernees par le paiement)
- foreach ($paiement->amounts as $key => $value)
- {
- $facid = $key;
+ $result=$paiement->update_fk_bank($bank_line_id);
+ if ($result <= 0) dol_print_error($db);
+ // Add link in bank_url between payment and bank transaction
+ $result=$acc->add_url_line($bank_line_id,
+ $paiement_id,
+ DOL_URL_ROOT.'/compta/paiement/fiche.php?id=',
+ '(paiement)',
+ 'payment');
+ // Add link in bank_url between invoice and bank transaction (for each invoice concerned by payment)
+ $linkaddedforthirdparty=array();
+ foreach ($paiement->amounts as $key => $value)
+ {
$fac = new Facture($db);
- $fac->fetch($facid);
+ $fac->fetch($key);
$fac->fetch_thirdparty();
- $acc->add_url_line($bank_line_id,
- $paiement_id,
- DOL_URL_ROOT.'/compta/paiement/fiche.php?id=',
- '(paiement)',
- 'payment');
- $acc->add_url_line($bank_line_id,
- $fac->client->id,
- DOL_URL_ROOT.'/compta/fiche.php?socid=',
- $fac->client->nom,
- 'company');
+ 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');
+ $linkaddedforthirdparty[$fac->client->id]=$fac->client->id; // Mark as done for this thirdparty
+ }
}
}
else
@@ -464,9 +470,9 @@ if ($_GET['action'] == 'create' || $_POST['action'] == 'confirm_paiement' || $_P
// Bouton Enregistrer
if ($_POST["action"] != 'add_paiement')
{
-// print '| ';
+ // print ' |
';
print ' ';
-// print ' |
';
+ // print '';
}
diff --git a/htdocs/compta/paiement/class/paiement.class.php b/htdocs/compta/paiement/class/paiement.class.php
index 23104ebbdb0..907bdd21fa5 100644
--- a/htdocs/compta/paiement/class/paiement.class.php
+++ b/htdocs/compta/paiement/class/paiement.class.php
@@ -162,18 +162,18 @@ class Paiement
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'paiement_facture (fk_facture, fk_paiement, amount)';
$sql .= ' VALUES ('.$facid.', '. $this->id.', \''.$amount.'\')';
- dol_syslog("Paiement::Create insert paiement_facture sql=".$sql);
+ dol_syslog("Paiement::Create Amount line '.$key.' insert paiement_facture sql=".$sql);
$resql=$this->db->query($sql);
if (! $resql)
{
- $this->error=$this->db->error();
+ $this->error=$this->db->lasterror();
dol_syslog('Paiement::Create insert paiement_facture error='.$this->error, LOG_ERR);
$error++;
}
}
else
{
- dol_syslog('Paiement::Create Montant non numerique');
+ dol_syslog('Paiement::Create Amount line '.$key.' not a number. We discard it.');
}
}
diff --git a/htdocs/compta/paiement/fiche.php b/htdocs/compta/paiement/fiche.php
index 720e0e2a344..fc5847c1fff 100644
--- a/htdocs/compta/paiement/fiche.php
+++ b/htdocs/compta/paiement/fiche.php
@@ -81,7 +81,7 @@ if ($_REQUEST['action'] == 'confirm_valide' && $_REQUEST['confirm'] == 'yes' &&
{
$db->commit();
- // \TODO Boucler sur les facture liees a ce paiement et regenerer le pdf
+ // Loop on each invoice linked to this payment to rebuild PDF
$factures=array();
foreach($factures as $id)
{
@@ -169,8 +169,9 @@ print '| '.$langs->trans('Ref').' | | '.$langs->trans('Date').' | '.dol_print_date($paiement->date,'day').' |
';
-// Mode
-print '| '.$langs->trans('Mode').' | '.$langs->trans("PaymentType".$paiement->type_code).' |
';
+// Payment type (VIR, LIQ, ...)
+$labeltype=$langs->trans("PaymentType".$paiement->type_code)!=("PaymentType".$paiement->type_code)?$langs->trans("PaymentType".$paiement->type_code):$paiement->type_libelle;
+print '| '.$langs->trans('Mode').' | '.$labeltype.' |
';
// Numero
//if ($paiement->montant)
@@ -178,7 +179,7 @@ print '| '.$langs->trans('Mode').' | '.$lan
print ' |
| '.$langs->trans('Numero').' | '.$paiement->numero.' |
';
//}
-// Montant
+// Amount
print '| '.$langs->trans('Amount').' | '.price($paiement->montant).' '.$langs->trans('Currency'.$conf->monnaie).' |
';