diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 001b9058b24e656484ae6664cb0e80b6d73cc70e..3bc60390d619a75793d543eb9aab377e7b7e3626 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -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) * @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; diff --git a/htdocs/compta/paiement_charge.php b/htdocs/compta/paiement_charge.php index c8e272cfd5aa8ddd1f5c9e155ecec56e2d66ebaf..3822f9f91f52a0f237f409c73d3cb9bc1c1f3c41 100644 --- a/htdocs/compta/paiement_charge.php +++ b/htdocs/compta/paiement_charge.php @@ -29,8 +29,8 @@ require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; $langs->load("bills"); -$chid=GETPOST("id"); -$action=GETPOST('action'); +$chid=GETPOST("id", 'int'); +$action=GETPOST('action', 'alpha'); $amounts = array(); // Security check @@ -45,7 +45,7 @@ if ($user->societe_id > 0) * Actions */ -if ($action == 'add_payment') +if ($action == 'add_payment' || ($action == 'confirm_paiement' && $confirm=='yes')) { $error=0; @@ -109,7 +109,7 @@ if ($action == 'add_payment') if (! $error) { - $paymentid = $paiement->create($user); + $paymentid = $paiement->create($user, (GETPOST('closepaidcontrib')=='on'?1:0)); if ($paymentid < 0) { $errmsg=$paiement->error; @@ -155,7 +155,7 @@ $form=new Form($db); // Formulaire de creation d'un paiement de charge -if ($_GET["action"] == 'create') +if ($action == 'create') { $charge = new ChargeSociales($db); @@ -317,8 +317,9 @@ if ($_GET["action"] == 'create') print "</table>"; - print '<br><div class="center">'; - print '<input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">'; + // Bouton Save payment + 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 '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">'; print '</div>'; diff --git a/htdocs/compta/sociales/class/paymentsocialcontribution.class.php b/htdocs/compta/sociales/class/paymentsocialcontribution.class.php index e3bf17b3418cbfc1531b328786226d6e00a61304..1d553831f99fb97520ca7e0f6c65423179eb0463 100644 --- a/htdocs/compta/sociales/class/paymentsocialcontribution.class.php +++ b/htdocs/compta/sociales/class/paymentsocialcontribution.class.php @@ -23,6 +23,7 @@ */ 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. * Use this->amounts to have list of lines for the payment * - * @param User $user User making payment - * @return int <0 if KO, id of payment if OK + * @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 */ - function create($user) + function create($user, $closepaidcontrib=0) { global $conf, $langs; @@ -75,7 +77,9 @@ class PaymentSocialContribution extends CommonObject $now=dol_now(); - // Validate parametres + dol_syslog(get_class($this)."::create", LOG_DEBUG); + + // Validate parametres if (! $this->datepaye) { $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.= " 0)"; - dol_syslog(get_class($this)."::create", LOG_DEBUG); $resql=$this->db->query($sql); if ($resql) { $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 { diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php index aab90ce4b498d463a3d1f6d4aeb6b4caeb7e4743..8a814c492d023209f2923eb4993df3f9fe743899 100644 --- a/htdocs/fourn/class/fournisseur.facture.class.php +++ b/htdocs/fourn/class/fournisseur.facture.class.php @@ -856,10 +856,12 @@ class FactureFournisseur extends CommonInvoice /** * Tag invoice as a payed invoice * - * @param User $user Object user - * @return int <0 si ko, >0 si ok + * @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 */ - function set_paid($user) + function set_paid($user, $close_code='', $close_note='') { global $conf,$langs; $error=0; diff --git a/htdocs/fourn/class/paiementfourn.class.php b/htdocs/fourn/class/paiementfourn.class.php index 78bdab0f6c5cf0db34a3ec3530c0990078dc3283..738c0eb716fe04fb63b12f468eb5a0fb7576cafa 100644 --- a/htdocs/fourn/class/paiementfourn.class.php +++ b/htdocs/fourn/class/paiementfourn.class.php @@ -130,7 +130,7 @@ class PaiementFourn extends Paiement * @param int $closepaidinvoices 1=Also close payed invoices to paid, 0=Do nothing more * @return int id of created payment, < 0 if error */ - function create($user,$closepaidinvoices=0) + function create($user, $closepaidinvoices=0) { global $langs,$conf; @@ -141,6 +141,8 @@ class PaiementFourn extends Paiement $totalamount = 0; $totalamount_converted = 0; + dol_syslog(get_class($this)."::create", LOG_DEBUG); + if ($way == 'dolibarr') { $amounts = &$this->amounts; @@ -188,7 +190,6 @@ class PaiementFourn extends Paiement $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)"; - dol_syslog("PaiementFourn::create", LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { @@ -220,7 +221,7 @@ class PaiementFourn extends Paiement $remaintopay=price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits,'MT'); 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."); } diff --git a/htdocs/langs/en_US/bills.lang b/htdocs/langs/en_US/bills.lang index f07b069e0310bc0cd14ef79176829b252a15c6ba..49402de185c4fe77788ad7d6d53d80af0189cbc0 100644 --- a/htdocs/langs/en_US/bills.lang +++ b/htdocs/langs/en_US/bills.lang @@ -429,6 +429,7 @@ CantRemoveConciliatedPayment=Can't remove conciliated payment PayedByThisPayment=Paid by this payment ClosePaidInvoicesAutomatically=Classify "Paid" all standard, situation or replacement invoices entirely paid. 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". ToMakePayment=Pay ToMakePaymentBack=Pay back