2
0
forked from Wavyzz/dolibarr

NEW Can set to paid automaically social or fiscal contributions after a

payment was recorded.
This commit is contained in:
Laurent Destailleur
2016-08-22 14:31:15 +02:00
parent 03c30c487c
commit e22e243bc5
6 changed files with 57 additions and 19 deletions

View File

@@ -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 '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'; print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
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>';

View File

@@ -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';
/** /**
@@ -65,9 +66,10 @@ class PaymentSocialContribution extends CommonObject
* 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
* @param int $closepaidcontrib 1=Also close payed contributions to paid, 0=Do nothing more
* @return int <0 if KO, id of payment if OK * @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,6 +77,8 @@ class PaymentSocialContribution extends CommonObject
$now=dol_now(); $now=dol_now();
dol_syslog(get_class($this)."::create", LOG_DEBUG);
// Validate parametres // Validate parametres
if (! $this->datepaye) if (! $this->datepaye)
{ {
@@ -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
{ {

View File

@@ -857,9 +857,11 @@ 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
* @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 * @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;

View File

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

View File

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