Fix: Use good payment type

This commit is contained in:
Laurent Destailleur 2010-08-14 01:42:59 +00:00
parent 0bf8bce765
commit 5be0cb859e
4 changed files with 52 additions and 52 deletions

View File

@ -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

View File

@ -94,7 +94,7 @@ if ($_POST['action'] == 'add_paiement' || ($_POST['action'] == 'confirm_paiement
// d'un paiement
if (! $_POST['accountid'])
{
$fiche_erreur_message = '<div class="error">'.$langs->trans('ErrorFieldRequired',$langs->transnoentities('AccountToCredit')).'</div>';
$fiche_erreur_message = '<div class="error">'.$langs->trans('ErrorFieldRequired',$langs->transnoentities('AccountToCredit')).'</div>';
$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 '<tr><td colspan="3" align="center">';
// print '<tr><td colspan="3" align="center">';
print '<br><center><input type="submit" class="button" value="'.$langs->trans('Save').'"></center>';
// print '</td></tr>';
// print '</td></tr>';
}

View File

@ -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.');
}
}

View File

@ -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 '<tr><td valign="top" width="140">'.$langs->trans('Ref').'</td><td colspan
// Date
print '<tr><td valign="top" width="120">'.$langs->trans('Date').'</td><td colspan="3">'.dol_print_date($paiement->date,'day').'</td></tr>';
// Mode
print '<tr><td valign="top">'.$langs->trans('Mode').'</td><td colspan="3">'.$langs->trans("PaymentType".$paiement->type_code).'</td></tr>';
// 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 '<tr><td valign="top">'.$langs->trans('Mode').'</td><td colspan="3">'.$labeltype.'</td></tr>';
// Numero
//if ($paiement->montant)
@ -178,7 +179,7 @@ print '<tr><td valign="top">'.$langs->trans('Mode').'</td><td colspan="3">'.$lan
print '<tr><td valign="top">'.$langs->trans('Numero').'</td><td colspan="3">'.$paiement->numero.'</td></tr>';
//}
// Montant
// Amount
print '<tr><td valign="top">'.$langs->trans('Amount').'</td><td colspan="3">'.price($paiement->montant).'&nbsp;'.$langs->trans('Currency'.$conf->monnaie).'</td></tr>';