forked from Wavyzz/dolibarr
NEW Can set to paid automaically social or fiscal contributions after a
payment was recorded.
This commit is contained in:
@@ -1738,7 +1738,7 @@ class Facture extends CommonInvoice
|
|||||||
* @param string $close_note Commentaire renseigne si on classe a payee alors que paiement incomplet (cas escompte par exemple)
|
* @param string $close_note Commentaire renseigne si on classe a payee alors que paiement incomplet (cas escompte par exemple)
|
||||||
* @return int <0 if KO, >0 if OK
|
* @return int <0 if KO, >0 if OK
|
||||||
*/
|
*/
|
||||||
function set_paid($user,$close_code='',$close_note='')
|
function set_paid($user, $close_code='', $close_note='')
|
||||||
{
|
{
|
||||||
$error=0;
|
$error=0;
|
||||||
|
|
||||||
|
|||||||
@@ -29,8 +29,8 @@ require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
|
|||||||
|
|
||||||
$langs->load("bills");
|
$langs->load("bills");
|
||||||
|
|
||||||
$chid=GETPOST("id");
|
$chid=GETPOST("id", 'int');
|
||||||
$action=GETPOST('action');
|
$action=GETPOST('action', 'alpha');
|
||||||
$amounts = array();
|
$amounts = array();
|
||||||
|
|
||||||
// Security check
|
// Security check
|
||||||
@@ -45,7 +45,7 @@ if ($user->societe_id > 0)
|
|||||||
* Actions
|
* Actions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ($action == 'add_payment')
|
if ($action == 'add_payment' || ($action == 'confirm_paiement' && $confirm=='yes'))
|
||||||
{
|
{
|
||||||
$error=0;
|
$error=0;
|
||||||
|
|
||||||
@@ -109,7 +109,7 @@ if ($action == 'add_payment')
|
|||||||
|
|
||||||
if (! $error)
|
if (! $error)
|
||||||
{
|
{
|
||||||
$paymentid = $paiement->create($user);
|
$paymentid = $paiement->create($user, (GETPOST('closepaidcontrib')=='on'?1:0));
|
||||||
if ($paymentid < 0)
|
if ($paymentid < 0)
|
||||||
{
|
{
|
||||||
$errmsg=$paiement->error;
|
$errmsg=$paiement->error;
|
||||||
@@ -155,7 +155,7 @@ $form=new Form($db);
|
|||||||
|
|
||||||
|
|
||||||
// Formulaire de creation d'un paiement de charge
|
// Formulaire de creation d'un paiement de charge
|
||||||
if ($_GET["action"] == 'create')
|
if ($action == 'create')
|
||||||
{
|
{
|
||||||
|
|
||||||
$charge = new ChargeSociales($db);
|
$charge = new ChargeSociales($db);
|
||||||
@@ -317,8 +317,9 @@ if ($_GET["action"] == 'create')
|
|||||||
|
|
||||||
print "</table>";
|
print "</table>";
|
||||||
|
|
||||||
print '<br><div class="center">';
|
// Bouton Save payment
|
||||||
print '<input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">';
|
print '<br><div class="center"><input type="checkbox" checked name="closepaidcontrib"> '.$langs->trans("ClosePaidContributionsAutomatically");
|
||||||
|
print '<br><input type="submit" class="button" name="save" value="'.$langs->trans('ToMakePayment').'">';
|
||||||
print ' ';
|
print ' ';
|
||||||
print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
|
print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
|
||||||
print '</div>';
|
print '</div>';
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
|
require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
|
||||||
|
require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -64,10 +65,11 @@ class PaymentSocialContribution extends CommonObject
|
|||||||
* Create payment of social contribution into database.
|
* Create payment of social contribution into database.
|
||||||
* Use this->amounts to have list of lines for the payment
|
* Use this->amounts to have list of lines for the payment
|
||||||
*
|
*
|
||||||
* @param User $user User making payment
|
* @param User $user User making payment
|
||||||
* @return int <0 if KO, id of payment if OK
|
* @param int $closepaidcontrib 1=Also close payed contributions to paid, 0=Do nothing more
|
||||||
|
* @return int <0 if KO, id of payment if OK
|
||||||
*/
|
*/
|
||||||
function create($user)
|
function create($user, $closepaidcontrib=0)
|
||||||
{
|
{
|
||||||
global $conf, $langs;
|
global $conf, $langs;
|
||||||
|
|
||||||
@@ -75,7 +77,9 @@ class PaymentSocialContribution extends CommonObject
|
|||||||
|
|
||||||
$now=dol_now();
|
$now=dol_now();
|
||||||
|
|
||||||
// Validate parametres
|
dol_syslog(get_class($this)."::create", LOG_DEBUG);
|
||||||
|
|
||||||
|
// Validate parametres
|
||||||
if (! $this->datepaye)
|
if (! $this->datepaye)
|
||||||
{
|
{
|
||||||
$this->error='ErrorBadValueForParameterCreatePaymentSocialContrib';
|
$this->error='ErrorBadValueForParameterCreatePaymentSocialContrib';
|
||||||
@@ -117,11 +121,40 @@ class PaymentSocialContribution extends CommonObject
|
|||||||
$sql.= " ".$this->paiementtype.", '".$this->db->escape($this->num_paiement)."', '".$this->db->escape($this->note)."', ".$user->id.",";
|
$sql.= " ".$this->paiementtype.", '".$this->db->escape($this->num_paiement)."', '".$this->db->escape($this->note)."', ".$user->id.",";
|
||||||
$sql.= " 0)";
|
$sql.= " 0)";
|
||||||
|
|
||||||
dol_syslog(get_class($this)."::create", LOG_DEBUG);
|
|
||||||
$resql=$this->db->query($sql);
|
$resql=$this->db->query($sql);
|
||||||
if ($resql)
|
if ($resql)
|
||||||
{
|
{
|
||||||
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."paiementcharge");
|
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."paiementcharge");
|
||||||
|
|
||||||
|
// Insere tableau des montants / factures
|
||||||
|
foreach ($this->amounts as $key => $amount)
|
||||||
|
{
|
||||||
|
$contribid = $key;
|
||||||
|
if (is_numeric($amount) && $amount <> 0)
|
||||||
|
{
|
||||||
|
$amount = price2num($amount);
|
||||||
|
|
||||||
|
// If we want to closed payed invoices
|
||||||
|
if ($closepaidcontrib)
|
||||||
|
{
|
||||||
|
|
||||||
|
$contrib=new ChargeSociales($this->db);
|
||||||
|
$contrib->fetch($contribid);
|
||||||
|
$paiement = $contrib->getSommePaiement();
|
||||||
|
//$creditnotes=$contrib->getSumCreditNotesUsed();
|
||||||
|
$creditnotes=0;
|
||||||
|
//$deposits=$contrib->getSumDepositsUsed();
|
||||||
|
$deposits=0;
|
||||||
|
$alreadypayed=price2num($paiement + $creditnotes + $deposits,'MT');
|
||||||
|
$remaintopay=price2num($contrib->amount - $paiement - $creditnotes - $deposits,'MT');
|
||||||
|
if ($remaintopay == 0)
|
||||||
|
{
|
||||||
|
$result=$contrib->set_paid($user, '', '');
|
||||||
|
}
|
||||||
|
else dol_syslog("Remain to pay for conrib ".$contribid." not null. We do nothing.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -856,10 +856,12 @@ class FactureFournisseur extends CommonInvoice
|
|||||||
/**
|
/**
|
||||||
* Tag invoice as a payed invoice
|
* Tag invoice as a payed invoice
|
||||||
*
|
*
|
||||||
* @param User $user Object user
|
* @param User $user Object user
|
||||||
* @return int <0 si ko, >0 si ok
|
* @param string $close_code Code renseigne si on classe a payee completement alors que paiement incomplet. Not implementd yet.
|
||||||
|
* @param string $close_note Commentaire renseigne si on classe a payee alors que paiement incomplet. Not implementd yet.
|
||||||
|
* @return int <0 si ko, >0 si ok
|
||||||
*/
|
*/
|
||||||
function set_paid($user)
|
function set_paid($user, $close_code='', $close_note='')
|
||||||
{
|
{
|
||||||
global $conf,$langs;
|
global $conf,$langs;
|
||||||
$error=0;
|
$error=0;
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ class PaiementFourn extends Paiement
|
|||||||
* @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
|
* @return int id of created payment, < 0 if error
|
||||||
*/
|
*/
|
||||||
function create($user,$closepaidinvoices=0)
|
function create($user, $closepaidinvoices=0)
|
||||||
{
|
{
|
||||||
global $langs,$conf;
|
global $langs,$conf;
|
||||||
|
|
||||||
@@ -141,6 +141,8 @@ class PaiementFourn extends Paiement
|
|||||||
$totalamount = 0;
|
$totalamount = 0;
|
||||||
$totalamount_converted = 0;
|
$totalamount_converted = 0;
|
||||||
|
|
||||||
|
dol_syslog(get_class($this)."::create", LOG_DEBUG);
|
||||||
|
|
||||||
if ($way == 'dolibarr')
|
if ($way == 'dolibarr')
|
||||||
{
|
{
|
||||||
$amounts = &$this->amounts;
|
$amounts = &$this->amounts;
|
||||||
@@ -188,7 +190,6 @@ class PaiementFourn extends Paiement
|
|||||||
$sql.= " VALUES ('".$this->db->escape($ref)."', ".$conf->entity.", '".$this->db->idate($now)."',";
|
$sql.= " VALUES ('".$this->db->escape($ref)."', ".$conf->entity.", '".$this->db->idate($now)."',";
|
||||||
$sql.= " '".$this->db->idate($this->datepaye)."', '".$total."', '".$mtotal."', ".$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);
|
$resql = $this->db->query($sql);
|
||||||
if ($resql)
|
if ($resql)
|
||||||
{
|
{
|
||||||
@@ -220,7 +221,7 @@ class PaiementFourn extends Paiement
|
|||||||
$remaintopay=price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits,'MT');
|
$remaintopay=price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits,'MT');
|
||||||
if ($remaintopay == 0)
|
if ($remaintopay == 0)
|
||||||
{
|
{
|
||||||
$result=$invoice->set_paid($user,'','');
|
$result=$invoice->set_paid($user, '', '');
|
||||||
}
|
}
|
||||||
else dol_syslog("Remain to pay for invoice ".$facid." not null. We do nothing.");
|
else dol_syslog("Remain to pay for invoice ".$facid." not null. We do nothing.");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -429,6 +429,7 @@ CantRemoveConciliatedPayment=Can't remove conciliated payment
|
|||||||
PayedByThisPayment=Paid by this payment
|
PayedByThisPayment=Paid by this payment
|
||||||
ClosePaidInvoicesAutomatically=Classify "Paid" all standard, situation or replacement invoices entirely paid.
|
ClosePaidInvoicesAutomatically=Classify "Paid" all standard, situation or replacement invoices entirely paid.
|
||||||
ClosePaidCreditNotesAutomatically=Classify "Paid" all credit notes entirely paid back.
|
ClosePaidCreditNotesAutomatically=Classify "Paid" all credit notes entirely paid back.
|
||||||
|
ClosePaidContributionsAutomatically=Classify "Paid" all social or fiscal contributions entirely paid.
|
||||||
AllCompletelyPayedInvoiceWillBeClosed=All invoice with no remain to pay will be automatically closed to status "Paid".
|
AllCompletelyPayedInvoiceWillBeClosed=All invoice with no remain to pay will be automatically closed to status "Paid".
|
||||||
ToMakePayment=Pay
|
ToMakePayment=Pay
|
||||||
ToMakePaymentBack=Pay back
|
ToMakePaymentBack=Pay back
|
||||||
|
|||||||
Reference in New Issue
Block a user