NEW When down payment is entered, discount to reuse into final invoice
is automatically created. This save one click into invoice workflow.
This commit is contained in:
parent
a9eeb823bd
commit
7c2b3b8df0
@ -611,7 +611,9 @@ if (empty($reshook))
|
|||||||
{
|
{
|
||||||
$db->begin();
|
$db->begin();
|
||||||
|
|
||||||
// Boucle sur chaque taux de tva
|
$amount_ht = $amount_tva = $amount_ttc = array();
|
||||||
|
|
||||||
|
// Loop on each vat rate
|
||||||
$i = 0;
|
$i = 0;
|
||||||
foreach ($object->lines as $line)
|
foreach ($object->lines as $line)
|
||||||
{
|
{
|
||||||
@ -630,20 +632,19 @@ if (empty($reshook))
|
|||||||
$discount->description = '(CREDIT_NOTE)';
|
$discount->description = '(CREDIT_NOTE)';
|
||||||
elseif ($object->type == Facture::TYPE_DEPOSIT)
|
elseif ($object->type == Facture::TYPE_DEPOSIT)
|
||||||
$discount->description = '(DEPOSIT)';
|
$discount->description = '(DEPOSIT)';
|
||||||
elseif ($object->type == Facture::TYPE_STANDARD)
|
elseif ($object->type == Facture::TYPE_STANDARD || $object->type == Facture::TYPE_REPLACEMENT || $object->type == Facture::TYPE_SITUATION)
|
||||||
$discount->description = '(EXCESS RECEIVED)';
|
$discount->description = '(EXCESS RECEIVED)';
|
||||||
else {
|
else {
|
||||||
setEventMessages($langs->trans('CantConvertToReducAnInvoiceOfThisType'), null, 'errors');
|
setEventMessages($langs->trans('CantConvertToReducAnInvoiceOfThisType'), null, 'errors');
|
||||||
}
|
}
|
||||||
$discount->tva_tx = abs($object->total_ttc);
|
|
||||||
$discount->fk_soc = $object->socid;
|
$discount->fk_soc = $object->socid;
|
||||||
$discount->fk_facture_source = $object->id;
|
$discount->fk_facture_source = $object->id;
|
||||||
|
|
||||||
$error = 0;
|
$error = 0;
|
||||||
|
|
||||||
if ($object->type == Facture::TYPE_STANDARD) {
|
if ($object->type == Facture::TYPE_STANDARD || $object->type == Facture::TYPE_REPLACEMENT || $object->type == Facture::TYPE_SITUATION)
|
||||||
|
{
|
||||||
// If we're on a standard invoice, we have to get excess received to create it in TTC wuthout VAT
|
// If we're on a standard invoice, we have to get excess received to create a discount in TTC without VAT
|
||||||
|
|
||||||
$sql = 'SELECT SUM(pf.amount) as total_paiements
|
$sql = 'SELECT SUM(pf.amount) as total_paiements
|
||||||
FROM llx_c_paiement as c, llx_paiement_facture as pf, llx_paiement as p
|
FROM llx_c_paiement as c, llx_paiement_facture as pf, llx_paiement as p
|
||||||
@ -663,8 +664,9 @@ if (empty($reshook))
|
|||||||
$error++;
|
$error++;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
}
|
||||||
|
if ($object->type == Facture::TYPE_CREDIT_NOTE || $object->type == Facture::TYPE_DEPOSIT)
|
||||||
|
{
|
||||||
foreach ($amount_ht as $tva_tx => $xxx)
|
foreach ($amount_ht as $tva_tx => $xxx)
|
||||||
{
|
{
|
||||||
$discount->amount_ht = abs($amount_ht[$tva_tx]);
|
$discount->amount_ht = abs($amount_ht[$tva_tx]);
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
/* Copyright (C) 2001-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
/* Copyright (C) 2001-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||||
* Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
|
* Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||||
* Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
|
* Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
|
||||||
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
|
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
|
||||||
* Copyright (C) 2007 Franky Van Liedekerke <franky.van.liedekerke@telenet.be>
|
* Copyright (C) 2007 Franky Van Liedekerke <franky.van.liedekerke@telenet.be>
|
||||||
@ -221,7 +221,7 @@ if (empty($reshook))
|
|||||||
$db->begin();
|
$db->begin();
|
||||||
|
|
||||||
// Clean parameters amount if payment is for a credit note
|
// Clean parameters amount if payment is for a credit note
|
||||||
if (GETPOST('type') == 2)
|
if (GETPOST('type') == Facture::TYPE_CREDIT_NOTE)
|
||||||
{
|
{
|
||||||
foreach ($amounts as $key => $value) // How payment is dispatch
|
foreach ($amounts as $key => $value) // How payment is dispatch
|
||||||
{
|
{
|
||||||
@ -249,7 +249,7 @@ if (empty($reshook))
|
|||||||
// Creation of payment line
|
// Creation of payment line
|
||||||
$paiement = new Paiement($db);
|
$paiement = new Paiement($db);
|
||||||
$paiement->datepaye = $datepaye;
|
$paiement->datepaye = $datepaye;
|
||||||
$paiement->amounts = $amounts; // Array with all payments dispatching
|
$paiement->amounts = $amounts; // Array with all payments dispatching with invoice id
|
||||||
$paiement->multicurrency_amounts = $multicurrency_amounts; // Array with all payments dispatching
|
$paiement->multicurrency_amounts = $multicurrency_amounts; // Array with all payments dispatching
|
||||||
$paiement->paiementid = dol_getIdFromCode($db,GETPOST('paiementcode'),'c_paiement');
|
$paiement->paiementid = dol_getIdFromCode($db,GETPOST('paiementcode'),'c_paiement');
|
||||||
$paiement->num_paiement = GETPOST('num_paiement');
|
$paiement->num_paiement = GETPOST('num_paiement');
|
||||||
@ -257,7 +257,7 @@ if (empty($reshook))
|
|||||||
|
|
||||||
if (! $error)
|
if (! $error)
|
||||||
{
|
{
|
||||||
$paiement_id = $paiement->create($user, (GETPOST('closepaidinvoices')=='on'?1:0));
|
$paiement_id = $paiement->create($user, (GETPOST('closepaidinvoices')=='on'?1:0)); // This include closing invoices
|
||||||
if ($paiement_id < 0)
|
if ($paiement_id < 0)
|
||||||
{
|
{
|
||||||
setEventMessages($paiement->error, $paiement->errors, 'errors');
|
setEventMessages($paiement->error, $paiement->errors, 'errors');
|
||||||
@ -268,7 +268,7 @@ if (empty($reshook))
|
|||||||
if (! $error)
|
if (! $error)
|
||||||
{
|
{
|
||||||
$label='(CustomerInvoicePayment)';
|
$label='(CustomerInvoicePayment)';
|
||||||
if (GETPOST('type') == 2) $label='(CustomerInvoicePaymentBack)';
|
if (GETPOST('type') == Facture::TYPE_CREDIT_NOTE) $label='(CustomerInvoicePaymentBack)'; // Refund of a credit note
|
||||||
$result=$paiement->addPaymentToBank($user,'payment',$label,GETPOST('accountid'),GETPOST('chqemetteur'),GETPOST('chqbank'));
|
$result=$paiement->addPaymentToBank($user,'payment',$label,GETPOST('accountid'),GETPOST('chqemetteur'),GETPOST('chqbank'));
|
||||||
if ($result < 0)
|
if ($result < 0)
|
||||||
{
|
{
|
||||||
@ -281,7 +281,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 keep on summary page, otherwise jump on invoice card
|
||||||
$invoiceid=0;
|
$invoiceid=0;
|
||||||
foreach ($paiement->amounts as $key => $amount)
|
foreach ($paiement->amounts as $key => $amount)
|
||||||
{
|
{
|
||||||
@ -309,7 +309,7 @@ if (empty($reshook))
|
|||||||
* View
|
* View
|
||||||
*/
|
*/
|
||||||
|
|
||||||
llxHeader();
|
llxHeader('', $langs->trans("Payment"));
|
||||||
|
|
||||||
$form=new Form($db);
|
$form=new Form($db);
|
||||||
|
|
||||||
@ -324,8 +324,8 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
|
|||||||
$facture->fetch_thirdparty();
|
$facture->fetch_thirdparty();
|
||||||
|
|
||||||
$title='';
|
$title='';
|
||||||
if ($facture->type != 2) $title.=$langs->trans("EnterPaymentReceivedFromCustomer");
|
if ($facture->type != Facture::TYPE_CREDIT_NOTE) $title.=$langs->trans("EnterPaymentReceivedFromCustomer");
|
||||||
if ($facture->type == 2) $title.=$langs->trans("EnterPaymentDueToCustomer");
|
if ($facture->type == Facture::TYPE_CREDIT_NOTE) $title.=$langs->trans("EnterPaymentDueToCustomer");
|
||||||
print load_fiche_titre($title);
|
print load_fiche_titre($title);
|
||||||
|
|
||||||
// Initialize data for confirmation (this is used because data can be change during confirmation)
|
// Initialize data for confirmation (this is used because data can be change during confirmation)
|
||||||
@ -347,7 +347,7 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add realtime total information
|
// Add realtime total information
|
||||||
if ($conf->use_javascript_ajax)
|
if (! empty($conf->use_javascript_ajax))
|
||||||
{
|
{
|
||||||
print "\n".'<script type="text/javascript" language="javascript">';
|
print "\n".'<script type="text/javascript" language="javascript">';
|
||||||
print '$(document).ready(function () {
|
print '$(document).ready(function () {
|
||||||
@ -369,7 +369,7 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
|
|||||||
}
|
}
|
||||||
if ($(\'#fieldchqemetteur\').val() == \'\')
|
if ($(\'#fieldchqemetteur\').val() == \'\')
|
||||||
{
|
{
|
||||||
var emetteur = ('.$facture->type.' == 2) ? \''.dol_escape_js(dol_escape_htmltag($conf->global->MAIN_INFO_SOCIETE_NOM)).'\' : jQuery(\'#thirdpartylabel\').val();
|
var emetteur = ('.$facture->type.' == '.Facture::TYPE_CREDIT_NOTE.') ? \''.dol_escape_js(dol_escape_htmltag($conf->global->MAIN_INFO_SOCIETE_NOM)).'\' : jQuery(\'#thirdpartylabel\').val();
|
||||||
$(\'#fieldchqemetteur\').val(emetteur);
|
$(\'#fieldchqemetteur\').val(emetteur);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -437,14 +437,14 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
|
|||||||
';
|
';
|
||||||
|
|
||||||
print ' });'."\n";
|
print ' });'."\n";
|
||||||
if (!empty($conf->use_javascript_ajax)){
|
|
||||||
//Add js for AutoFill
|
//Add js for AutoFill
|
||||||
print ' $(document).ready(function () {';
|
print ' $(document).ready(function () {';
|
||||||
print ' $(".AutoFillAmout").on(\'click touchstart\', function(){
|
print ' $(".AutoFillAmout").on(\'click touchstart\', function(){
|
||||||
$("input[name="+$(this).data(\'rowname\')+"]").val($(this).data("value")).trigger("change");
|
$("input[name="+$(this).data(\'rowname\')+"]").val($(this).data("value")).trigger("change");
|
||||||
});';
|
});';
|
||||||
print ' });'."\n";
|
print ' });'."\n";
|
||||||
}
|
|
||||||
print ' </script>'."\n";
|
print ' </script>'."\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -255,7 +255,7 @@ class Paiement extends CommonObject
|
|||||||
{
|
{
|
||||||
if (! empty($conf->prelevement->enabled))
|
if (! empty($conf->prelevement->enabled))
|
||||||
{
|
{
|
||||||
// TODO Check if this payment has a withdraw request
|
// FIXME Check if this invoice has a withdraw request
|
||||||
// if not, $mustwait++; // This will disable automatic close on invoice to allow to process
|
// if not, $mustwait++; // This will disable automatic close on invoice to allow to process
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -275,11 +275,61 @@ class Paiement extends CommonObject
|
|||||||
else if ($mustwait) dol_syslog("There is ".$mustwait." differed payment to process, we do nothing more.");
|
else if ($mustwait) dol_syslog("There is ".$mustwait." differed payment to process, we do nothing more.");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$result=$invoice->set_paid($user,'','');
|
// If invoice is a down payment, we also convert down payment to discount
|
||||||
if ($result<0)
|
if ($invoice->type == Facture::TYPE_DEPOSIT)
|
||||||
{
|
{
|
||||||
$this->error=$invoice->error;
|
$amount_ht = $amount_tva = $amount_ttc = array();
|
||||||
$error++;
|
|
||||||
|
// Loop on each vat rate
|
||||||
|
$i = 0;
|
||||||
|
foreach ($invoice->lines as $line)
|
||||||
|
{
|
||||||
|
if ($line->total_ht!=0)
|
||||||
|
{ // no need to create discount if amount is null
|
||||||
|
$amount_ht[$line->tva_tx] += $line->total_ht;
|
||||||
|
$amount_tva[$line->tva_tx] += $line->total_tva;
|
||||||
|
$amount_ttc[$line->tva_tx] += $line->total_ttc;
|
||||||
|
$i ++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Insert one discount by VAT rate category
|
||||||
|
$discount = new DiscountAbsolute($this->db);
|
||||||
|
$discount->description = '(DEPOSIT)';
|
||||||
|
$discount->fk_soc = $invoice->socid;
|
||||||
|
$discount->fk_facture_source = $invoice->id;
|
||||||
|
|
||||||
|
foreach ($amount_ht as $tva_tx => $xxx)
|
||||||
|
{
|
||||||
|
$discount->amount_ht = abs($amount_ht[$tva_tx]);
|
||||||
|
$discount->amount_tva = abs($amount_tva[$tva_tx]);
|
||||||
|
$discount->amount_ttc = abs($amount_ttc[$tva_tx]);
|
||||||
|
$discount->tva_tx = abs($tva_tx);
|
||||||
|
|
||||||
|
$result = $discount->create($user);
|
||||||
|
if ($result < 0)
|
||||||
|
{
|
||||||
|
$error++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($error)
|
||||||
|
{
|
||||||
|
setEventMessages($discount->error, $discount->errors, 'errors');
|
||||||
|
$error++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set invoice to paid
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
|
$result=$invoice->set_paid($user,'','');
|
||||||
|
if ($result<0)
|
||||||
|
{
|
||||||
|
$this->error=$invoice->error;
|
||||||
|
$error++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -447,7 +447,7 @@ CantRemovePaymentWithOneInvoicePaid=Can't remove payment since there is at least
|
|||||||
ExpectedToPay=Expected payment
|
ExpectedToPay=Expected payment
|
||||||
CantRemoveConciliatedPayment=Can't remove conciliated payment
|
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, down payment 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.
|
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".
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user