New add supplier payment

This commit is contained in:
phf 2016-02-21 22:47:52 +01:00
parent ec0282a28e
commit fd4cda819c
6 changed files with 80 additions and 17 deletions

View File

@ -150,7 +150,7 @@ class Paiement extends CommonObject
global $conf, $langs;
$error = 0;
$way = $this->getWay();
$way = $this->getWay();
$now=dol_now();

View File

@ -27,6 +27,7 @@
*/
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
require_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php';
/**
* Class to manage payments for supplier invoices
@ -134,29 +135,58 @@ class PaiementFourn extends Paiement
global $langs,$conf;
$error = 0;
$way = $this->getWay();
// Clean parameters
$this->total = 0;
foreach ($this->amounts as $key => $value)
$totalamount = 0;
$totalamount_converted = 0;
if ($way == 'dolibarr')
{
$newvalue = price2num($value, 'MT');
$this->amounts[$key] = $newvalue;
$this->total += $newvalue;
$amounts = &$this->amounts;
$amounts_to_update = &$this->multicurrency_amounts;
}
$this->total = price2num($this->total);
else
{
$amounts = &$this->multicurrency_amounts;
$amounts_to_update = &$this->amounts;
}
foreach ($amounts as $key => $value)
{
$value_converted = Multicurrency::getAmountConversionFromInvoiceRate($key, $value, $way, 'facture_fourn');
$totalamount_converted += $value_converted;
$amounts_to_update[$key] = price2num($value_converted, 'MT');
$newvalue = price2num($value,'MT');
$amounts[$key] = $newvalue;
$totalamount += $newvalue;
}
$totalamount = price2num($totalamount);
$totalamount_converted = price2num($totalamount_converted);
$this->db->begin();
if ($this->total <> 0) // On accepte les montants negatifs
if ($totalamount <> 0) // On accepte les montants negatifs
{
$ref = $this->getNextNumRef('');
$now=dol_now();
if ($way == 'dolibarr')
{
$total = $totalamount;
$mtotal = $totalamount_converted; // Maybe use price2num with MT for the converted value
}
else
{
$total = $totalamount_converted; // Maybe use price2num with MT for the converted value
$mtotal = $totalamount;
}
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'paiementfourn (';
$sql.= 'ref, entity, datec, datep, amount, fk_paiement, num_paiement, note, fk_user_author, fk_bank)';
$sql.= 'ref, entity, datec, datep, amount, multicurrency_amount, fk_paiement, num_paiement, note, fk_user_author, fk_bank)';
$sql.= " VALUES ('".$this->db->escape($ref)."', ".$conf->entity.", '".$this->db->idate($now)."',";
$sql.= " '".$this->db->idate($this->datepaye)."', '".$this->total."', ".$this->paiementid.", '".$this->num_paiement."', '".$this->db->escape($this->note)."', ".$user->id.", 0)";
$sql.= " '".$this->db->idate($this->datepaye)."', '".$total."', '".$mtotal."', ".$this->paiementid.", '".$this->num_paiement."', '".$this->db->escape($this->note)."', ".$user->id.", 0)";
dol_syslog("PaiementFourn::create", LOG_DEBUG);
$resql = $this->db->query($sql);
@ -171,8 +201,8 @@ class PaiementFourn extends Paiement
if (is_numeric($amount) && $amount <> 0)
{
$amount = price2num($amount);
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'paiementfourn_facturefourn (fk_facturefourn, fk_paiementfourn, amount)';
$sql .= ' VALUES ('.$facid.','. $this->id.',\''.$amount.'\')';
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'paiementfourn_facturefourn (fk_facturefourn, fk_paiementfourn, amount, multicurrency_amount)';
$sql .= ' VALUES ('.$facid.','. $this->id.',\''.$amount.'\', \''.$this->multicurrency_amounts[$key].'\')';
$resql=$this->db->query($sql);
if ($resql)
{
@ -229,8 +259,11 @@ class PaiementFourn extends Paiement
$error++;
}
if ($this->total <> 0 && $error == 0) // On accepte les montants negatifs
if ($totalamount <> 0 && $error == 0) // On accepte les montants negatifs
{
$this->amount=$total;
$this->total=$total;
$this->multicurrency_amount=$mtotal;
$this->db->commit();
dol_syslog('PaiementFourn::Create Ok Total = '.$this->total);
return $this->id;
@ -625,4 +658,29 @@ class PaiementFourn extends Paiement
return "";
}
}
/**
* get the right way of payment
*
* @return string 'dolibarr' if standard comportment or paid in dolibarr currency, 'customer' if payment received from multicurrency inputs
*/
function getWay()
{
global $conf;
$way = 'dolibarr';
if (!empty($conf->multicurrency->enabled))
{
foreach ($this->multicurrency_amounts as $value)
{
if (!empty($value)) // one value found then payment is in invoice currency
{
$way = 'customer';
break;
}
}
}
return $way;
}
}

View File

@ -1269,14 +1269,15 @@ if ($action == 'create')
dol_htmloutput_events();
$currency_code = $conf->currency;
$societe='';
if (GETPOST('socid') > 0)
{
$societe=new Societe($db);
$societe->fetch(GETPOST('socid','int'));
if (!empty($conf->multicurrency->enabled) && !empty($societe->multicurrency_code)) $currency_code = $societe->multicurrency_code;
}
$currency_code = $conf->currency;
if (GETPOST('origin') && GETPOST('originid'))
{

View File

@ -497,7 +497,9 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
print '<tr class="liste_total">';
print '<td colspan="3" align="left">'.$langs->trans('TotalTTC').':</td>';
print '<td align="right"><b>'.price($total_ttc).'</b></td>';
if (!empty($conf->multicurrency->enabled)) print '<td>&nbsp;</td>';
print '<td align="right"><b>'.price($totalrecu).'</b></td>';
if (!empty($conf->multicurrency->enabled)) print '<td>&nbsp;</td>';
print '<td align="right"><b>'.price($total_ttc - $totalrecu).'</b></td>';
print '<td align="center">&nbsp;</td>';
print "</tr>\n";

View File

@ -262,6 +262,7 @@ ALTER TABLE llx_contratdet ADD COLUMN multicurrency_total_ttc double(24,8) DEFAU
ALTER TABLE llx_paiement ADD COLUMN multicurrency_amount double(24,8) DEFAULT 0;
ALTER TABLE llx_paiement_facture ADD COLUMN multicurrency_amount double(24,8) DEFAULT 0;
ALTER TABLE llx_paiementfourn ADD COLUMN multicurrency_amount double(24,8) DEFAULT 0;
ALTER TABLE llx_paiementfourn_facturefourn ADD COLUMN multicurrency_amount double(24,8) DEFAULT 0;
ALTER TABLE llx_societe_remise_except ADD COLUMN multicurrency_amount_ht double(24,8) NOT NULL;

View File

@ -26,6 +26,7 @@ create table llx_paiementfourn
datec datetime, -- date de creation de l'enregistrement
datep datetime, -- date de paiement
amount real DEFAULT 0, -- montant
multicurrency_amount double(24,8) DEFAULT 0, -- multicurrency amount
fk_user_author integer, -- auteur
fk_paiement integer NOT NULL, -- moyen de paiement
num_paiement varchar(50), -- numero de paiement (cheque)