NEW Support tag {ccc} on payment ref

This commit is contained in:
Laurent Destailleur 2019-02-03 20:36:20 +01:00
parent afd53a99c2
commit 4b77b3ff23
4 changed files with 31 additions and 22 deletions

View File

@ -43,9 +43,9 @@ $action = GETPOST('action','alpha');
$confirm = GETPOST('confirm'); $confirm = GETPOST('confirm');
$facid = GETPOST('facid','int'); $facid = GETPOST('facid','int');
$socname = GETPOST('socname'); $accountid = GETPOST('accountid','int');
$accountid = GETPOST('accountid'); $paymentnum = GETPOST('num_paiement','alpha');
$paymentnum = GETPOST('num_paiement'); $socid=GETPOST('socid','int');
$sortfield = GETPOST('sortfield','alpha'); $sortfield = GETPOST('sortfield','alpha');
$sortorder = GETPOST('sortorder','alpha'); $sortorder = GETPOST('sortorder','alpha');
@ -59,7 +59,6 @@ $multicurrency_amounts=array();
$multicurrency_amountsresttopay=array(); $multicurrency_amountsresttopay=array();
// Security check // Security check
$socid=0;
if ($user->societe_id > 0) if ($user->societe_id > 0)
{ {
$socid = $user->societe_id; $socid = $user->societe_id;
@ -219,6 +218,9 @@ if (empty($reshook))
$db->begin(); $db->begin();
$thirdparty = new Societe($db);
if ($socid > 0) $thirdparty->fetch($socid);
// Clean parameters amount if payment is for a credit note // Clean parameters amount if payment is for a credit note
if (GETPOST('type') == Facture::TYPE_CREDIT_NOTE) if (GETPOST('type') == Facture::TYPE_CREDIT_NOTE)
{ {
@ -238,7 +240,7 @@ if (empty($reshook))
if (! empty($conf->banque->enabled)) if (! empty($conf->banque->enabled))
{ {
// Si module bank actif, un compte est obligatoire lors de la saisie d'un paiement // Si module bank actif, un compte est obligatoire lors de la saisie d'un paiement
if (GETPOST('accountid') <= 0) if (GETPOST('accountid','int') <= 0)
{ {
setEventMessages($langs->trans('ErrorFieldRequired',$langs->transnoentities('AccountToCredit')), null, 'errors'); setEventMessages($langs->trans('ErrorFieldRequired',$langs->transnoentities('AccountToCredit')), null, 'errors');
$error++; $error++;
@ -256,7 +258,7 @@ if (empty($reshook))
if (! $error) if (! $error)
{ {
$paiement_id = $paiement->create($user, (GETPOST('closepaidinvoices')=='on'?1:0)); // This include closing invoices and regenerating documents $paiement_id = $paiement->create($user, (GETPOST('closepaidinvoices')=='on'?1:0), $thirdparty); // This include closing invoices and regenerating documents
if ($paiement_id < 0) if ($paiement_id < 0)
{ {
setEventMessages($paiement->error, $paiement->errors, 'errors'); setEventMessages($paiement->error, $paiement->errors, 'errors');
@ -280,7 +282,7 @@ if (empty($reshook))
{ {
$db->commit(); $db->commit();
// If payment dispatching on more than one invoice, we keep on summary page, otherwise jump on invoice card // If payment dispatching on more than one invoice, we stay on summary page, otherwise jump on invoice card
$invoiceid=0; $invoiceid=0;
foreach ($paiement->amounts as $key => $amount) foreach ($paiement->amounts as $key => $amount)
{ {

View File

@ -216,15 +216,16 @@ class Paiement extends CommonObject
} }
/** /**
* Create payment of invoices into database. * Create payment of invoices into database.
* Use this->amounts to have list of invoices for the payment. * Use this->amounts to have list of invoices for the payment.
* For payment of a customer invoice, amounts are positive, for payment of credit note, amounts are negative * For payment of a customer invoice, amounts are positive, for payment of credit note, amounts are negative
* *
* @param User $user Object user * @param User $user Object user
* @param int $closepaidinvoices 1=Also close payed invoices to paid, 0=Do nothing more * @param int $closepaidinvoices 1=Also close payed invoices to paid, 0=Do nothing more
* @return int id of created payment, < 0 if error * @param Societe $thirdparty Thirdparty
* @return int id of created payment, < 0 if error
*/ */
function create($user, $closepaidinvoices = 0) function create($user, $closepaidinvoices = 0, $thirdparty = null)
{ {
global $conf, $langs; global $conf, $langs;
@ -274,7 +275,7 @@ class Paiement extends CommonObject
$this->db->begin(); $this->db->begin();
$this->ref = $this->getNextNumRef(''); $this->ref = $this->getNextNumRef(is_object($thirdparty)?$thirdparty:'');
if ($way == 'dolibarr') if ($way == 'dolibarr')
{ {
@ -424,6 +425,7 @@ class Paiement extends CommonObject
// Regenerate documents of invoices // Regenerate documents of invoices
if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
{ {
$newlang='';
$outputlangs = $langs; $outputlangs = $langs;
if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $invoice->thirdparty->default_lang; if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $invoice->thirdparty->default_lang;
if (! empty($newlang)) { if (! empty($newlang)) {

View File

@ -141,11 +141,12 @@ class PaiementFourn extends Paiement
/** /**
* Create payment in database * Create payment in database
* *
* @param User $user Object of creating user * @param User $user Object of creating user
* @param int $closepaidinvoices 1=Also close payed invoices to paid, 0=Do nothing more * @param int $closepaidinvoices 1=Also close payed invoices to paid, 0=Do nothing more
* @param Societe $thirdparty Thirdparty
* @return int id of created payment, < 0 if error * @return int id of created payment, < 0 if error
*/ */
function create($user, $closepaidinvoices = 0) function create($user, $closepaidinvoices = 0, $thirdparty = null)
{ {
global $langs,$conf; global $langs,$conf;
@ -186,7 +187,7 @@ class PaiementFourn extends Paiement
if ($totalamount <> 0) // On accepte les montants negatifs if ($totalamount <> 0) // On accepte les montants negatifs
{ {
$ref = $this->getNextNumRef(''); $ref = $this->getNextNumRef(is_object($thirdparty)?$thirdparty:'');
$now=dol_now(); $now=dol_now();
if ($way == 'dolibarr') if ($way == 'dolibarr')
@ -245,7 +246,8 @@ class PaiementFourn extends Paiement
// Regenerate documents of invoices // Regenerate documents of invoices
if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
{ {
$outputlangs = $langs; $newlang='';
$outputlangs = $langs;
if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $invoice->thirdparty->default_lang; if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $invoice->thirdparty->default_lang;
if (! empty($newlang)) { if (! empty($newlang)) {
$outputlangs = new Translate("", $conf); $outputlangs = new Translate("", $conf);

View File

@ -253,6 +253,9 @@ if (empty($reshook))
{ {
$db->begin(); $db->begin();
$thirdparty = new Societe($db);
if ($socid > 0) $thirdparty->fetch($socid);
// Creation de la ligne paiement // Creation de la ligne paiement
$paiement = new PaiementFourn($db); $paiement = new PaiementFourn($db);
$paiement->datepaye = $datepaye; $paiement->datepaye = $datepaye;
@ -263,7 +266,7 @@ if (empty($reshook))
$paiement->note = $_POST['comment']; $paiement->note = $_POST['comment'];
if (! $error) if (! $error)
{ {
$paiement_id = $paiement->create($user,(GETPOST('closepaidinvoices')=='on'?1:0)); $paiement_id = $paiement->create($user, (GETPOST('closepaidinvoices')=='on'?1:0), $thirdparty);
if ($paiement_id < 0) if ($paiement_id < 0)
{ {
setEventMessages($paiement->error, $paiement->errors, 'errors'); setEventMessages($paiement->error, $paiement->errors, 'errors');
@ -285,7 +288,7 @@ if (empty($reshook))
{ {
$db->commit(); $db->commit();
// If payment dispatching on more than one invoice, we keep on summary page, otherwise go on invoice card // If payment dispatching on more than one invoice, we stay on summary page, otherwise go on invoice card
$invoiceid=0; $invoiceid=0;
foreach ($paiement->amounts as $key => $amount) foreach ($paiement->amounts as $key => $amount)
{ {