New: Add option to close invoice if paiement is complete.
This commit is contained in:
parent
d3422da09e
commit
66acd4ea8a
@ -174,6 +174,7 @@ class Paiement extends CommonObject
|
|||||||
$resql=$this->db->query($sql);
|
$resql=$this->db->query($sql);
|
||||||
if ($resql)
|
if ($resql)
|
||||||
{
|
{
|
||||||
|
// If we want to closed payed invoices
|
||||||
if ($closepaidinvoices)
|
if ($closepaidinvoices)
|
||||||
{
|
{
|
||||||
$invoice=new Facture($this->db);
|
$invoice=new Facture($this->db);
|
||||||
|
|||||||
@ -638,9 +638,9 @@ class FactureFournisseur extends Facture
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Tag la facture comme payee completement
|
* Tag invoice as a payed invoice
|
||||||
* \param user Objet utilisateur qui modifie l'etat
|
* @param user Object user
|
||||||
* \return int <0 si ko, >0 si ok
|
* @return int <0 si ko, >0 si ok
|
||||||
*/
|
*/
|
||||||
function set_paid($user)
|
function set_paid($user)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -116,11 +116,12 @@ class PaiementFourn extends Paiement
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Create payment in database
|
* Create payment in database
|
||||||
* \param user Object of creating user
|
* @param user Object of creating user
|
||||||
* \return int id of created payment, < 0 if error
|
* @param closepaidinvoices 1=Also close payed invoices to paid, 0=Do nothing more
|
||||||
|
* @return int id of created payment, < 0 if error
|
||||||
*/
|
*/
|
||||||
function create($user)
|
function create($user,$closepaidinvoices=0)
|
||||||
{
|
{
|
||||||
global $langs,$conf;
|
global $langs,$conf;
|
||||||
|
|
||||||
@ -162,11 +163,34 @@ class PaiementFourn extends Paiement
|
|||||||
$amount = price2num($amount);
|
$amount = price2num($amount);
|
||||||
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'paiementfourn_facturefourn (fk_facturefourn, fk_paiementfourn, amount)';
|
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'paiementfourn_facturefourn (fk_facturefourn, fk_paiementfourn, amount)';
|
||||||
$sql .= ' VALUES ('.$facid.','. $this->id.',\''.$amount.'\')';
|
$sql .= ' VALUES ('.$facid.','. $this->id.',\''.$amount.'\')';
|
||||||
if (! $this->db->query($sql) )
|
$resql=$this->db->query($sql);
|
||||||
|
if ($resql)
|
||||||
|
{
|
||||||
|
// If we want to closed payed invoices
|
||||||
|
if ($closepaidinvoices)
|
||||||
|
{
|
||||||
|
$invoice=new FactureFournisseur($this->db);
|
||||||
|
$invoice->fetch($facid);
|
||||||
|
$paiement = $invoice->getSommePaiement();
|
||||||
|
//$creditnotes=$invoice->getSumCreditNotesUsed();
|
||||||
|
$creditnotes=0;
|
||||||
|
//$deposits=$invoice->getSumDepositsUsed();
|
||||||
|
$deposits=0;
|
||||||
|
$alreadypayed=price2num($paiement + $creditnotes + $deposits,'MT');
|
||||||
|
$remaintopay=price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits,'MT');
|
||||||
|
if ($remaintopay == 0)
|
||||||
|
{
|
||||||
|
$result=$invoice->set_paid($user,'','');
|
||||||
|
}
|
||||||
|
else dol_syslog("Remain to pay for invoice ".$facid." not null. We do nothing.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
dol_syslog('Paiement::Create Erreur INSERT dans paiement_facture '.$facid);
|
dol_syslog('Paiement::Create Erreur INSERT dans paiement_facture '.$facid);
|
||||||
$error++;
|
$error++;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@ -128,11 +128,10 @@ if ($action == 'add_paiement')
|
|||||||
$paiement->paiementid = $_POST['paiementid'];
|
$paiement->paiementid = $_POST['paiementid'];
|
||||||
$paiement->num_paiement = $_POST['num_paiement'];
|
$paiement->num_paiement = $_POST['num_paiement'];
|
||||||
$paiement->note = $_POST['comment'];
|
$paiement->note = $_POST['comment'];
|
||||||
|
|
||||||
if (! $error)
|
if (! $error)
|
||||||
{
|
{
|
||||||
$paiement_id = $paiement->create($user);
|
$paiement_id = $paiement->create($user,(GETPOST('closepaidinvoices')=='on'?1:0));
|
||||||
if (! $paiement_id > 0)
|
if ($paiement_id < 0)
|
||||||
{
|
{
|
||||||
$errmsg='<div class="error">'.$paiement->error.'</div>';
|
$errmsg='<div class="error">'.$paiement->error.'</div>';
|
||||||
$error++;
|
$error++;
|
||||||
@ -326,12 +325,10 @@ if ($action == 'create' || $action == 'add_paiement')
|
|||||||
dol_print_error($db);
|
dol_print_error($db);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
// print '<tr><td colspan="3" align="center">';
|
||||||
*
|
print '<center><br><input type="checkbox" checked="checked" name="closepaidinvoices"> '.$langs->trans("ClosePaidInvoicesAutomatically");
|
||||||
*/
|
print '<br><input type="submit" class="button" value="'.$langs->trans('Save').'"></center>';
|
||||||
|
// print '</td></tr>';
|
||||||
print '<br>';
|
|
||||||
print '<center><input type="submit" class="button" value="'.$langs->trans('Save').'"></center>';
|
|
||||||
|
|
||||||
print '</form>';
|
print '</form>';
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user