Skip to content

Commit

Permalink
NEW: supplier credit notes: handle Excess Paid + translation
Browse files Browse the repository at this point in the history
  • Loading branch information
ATM-Marc committed Feb 19, 2018
1 parent 924a9c3 commit f5ad93b
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 35 deletions.
29 changes: 15 additions & 14 deletions htdocs/comm/remx.php
Expand Up @@ -276,12 +276,12 @@
dol_print_error($db);
}

print '<tr><td class="titlefield">'.$langs->trans("CustomerAbsoluteDiscountAllUsers").'</td>'; // TODO adapt text
print '<tr><td class="titlefield">'.$langs->trans("CustomerAbsoluteDiscountAllUsers").'</td>';
print '<td>'.$remise_all.'&nbsp;'.$langs->trans("Currency".$conf->currency).' '.$langs->trans("HT").'</td></tr>';

if (! empty($user->fk_soc)) // No need to show this for external users
{
print '<tr><td>'.$langs->trans("CustomerAbsoluteDiscountMy").'</td>'; // TODO adapt text
print '<tr><td>'.$langs->trans("CustomerAbsoluteDiscountMy").'</td>';
print '<td>'.$remise_user.'&nbsp;'.$langs->trans("Currency".$conf->currency).' '.$langs->trans("HT").'</td></tr>';
}

Expand All @@ -307,12 +307,12 @@
dol_print_error($db);
}

print '<tr><td class="titlefield">'.$langs->trans("CustomerAbsoluteDiscountAllUsers").'</td>'; // TODO adapt text
print '<tr><td class="titlefield">'.$langs->trans("SupplierAbsoluteDiscountAllUsers").'</td>';
print '<td>'.$remise_all.'&nbsp;'.$langs->trans("Currency".$conf->currency).' '.$langs->trans("HT").'</td></tr>';

if (! empty($user->fk_soc)) // No need to show this for external users
{
print '<tr><td>'.$langs->trans("CustomerAbsoluteDiscountMy").'</td>'; // TODO adapt text
print '<tr><td>'.$langs->trans("SupplierAbsoluteDiscountMy").'</td>';
print '<td>'.$remise_user.'&nbsp;'.$langs->trans("Currency".$conf->currency).' '.$langs->trans("HT").'</td></tr>';
}
}
Expand All @@ -330,9 +330,10 @@
print '<div class="underbanner clearboth"></div>';
print '<table class="border" width="100%">';
if($conf->global->MAIN_FEATURES_LEVEL > 0) {
print '<tr><td>'.$langs->trans('DiscountType').'</td>';
print '<td><input type="radio" name="discount_type" id="discount_type_0" selected value="0"/> <label for="discount_type_0">'.$langs->trans('Customer').'</label>';
print ' <input type="radio" name="discount_type" id="discount_type_1" selected value="1"/> <label for="discount_type_1">'.$langs->trans('Supplier').'</label></td></tr>';
print '<tr><td>'.$langs->trans('DiscountType').'</td>';
print '<td><input type="radio" name="discount_type" id="discount_type_0" selected value="0"/> <label for="discount_type_0">'.$langs->trans('Customer').'</label>';
print ' <input type="radio" name="discount_type" id="discount_type_1" selected value="1"/> <label for="discount_type_1">'.$langs->trans('Supplier').'</label>';
print '</td></tr>';
}
print '<tr><td class="titlefield fieldrequired">'.$langs->trans("AmountHT").'</td>';
print '<td><input type="text" size="5" name="amount_ht" value="'.price2num(GETPOST("amount_ht")).'">';
Expand Down Expand Up @@ -401,7 +402,7 @@
if ($resql)
{
if($conf->global->MAIN_FEATURES_LEVEL > 0) {
print load_fiche_titre($langs->trans("CustomerDiscounts"), '', ''); // TODO translate
print load_fiche_titre($langs->trans("CustomerDiscounts"), '', '');
}
print '<table width="100%" class="noborder">';
print '<tr class="liste_titre">';
Expand Down Expand Up @@ -536,7 +537,7 @@
$resql=$db->query($sql);
if ($resql)
{
print load_fiche_titre($langs->trans("SupplierDiscounts"), '', ''); // TODO translate
print load_fiche_titre($langs->trans("SupplierDiscounts"), '', '');
print '<table width="100%" class="noborder">';
print '<tr class="liste_titre">';
print '<td class="widthdate">'.$langs->trans("Date").'</td>'; // Need 120+ for format with AM/PM
Expand Down Expand Up @@ -585,7 +586,7 @@
$facturefournstatic->id=$obj->fk_invoice_supplier_source;
$facturefournstatic->ref=$obj->ref;
$facturefournstatic->type=$obj->type;
print preg_replace('/\(EXCESS PAID\)/',$langs->trans("ExcessPaid"),$obj->description).' '.$facturefournstatic->getNomURl(1); // TODO translate ExcessPaid
print preg_replace('/\(EXCESS PAID\)/',$langs->trans("ExcessPaid"),$obj->description).' '.$facturefournstatic->getNomURl(1);
print '</td>';
}
else
Expand Down Expand Up @@ -705,7 +706,7 @@
if ($resql2)
{
if($conf->global->MAIN_FEATURES_LEVEL > 0) {
print load_fiche_titre($langs->trans("CustomerDiscounts"), '', ''); // TODO translate
print load_fiche_titre($langs->trans("CustomerDiscounts"), '', '');
}
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
Expand Down Expand Up @@ -855,7 +856,7 @@
if ($resql) $resql2=$db->query($sql2);
if ($resql2)
{
print load_fiche_titre($langs->trans("SupplierDiscounts"), '', ''); // TODO translate
print load_fiche_titre($langs->trans("SupplierDiscounts"), '', '');
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
print '<td class="widthdate">'.$langs->trans("Date").'</td>'; // Need 120+ for format with AM/PM
Expand Down Expand Up @@ -934,12 +935,12 @@
print $obj->description;
print '</td>';
}
print '<td align="left" class="nowrap"><a href="'.DOL_URL_ROOT.'/compta/facture/card.php?facid='.$obj->rowid.'">'.img_object($langs->trans("ShowBill"),'bill').' '.$obj->facnumber.'</a></td>'; // TODO adapt to supplier invoice of use getNomUrl
print '<td align="left" class="nowrap"><a href="'.DOL_URL_ROOT.'/fourn/facture/card.php?facid='.$obj->rowid.'">'.img_object($langs->trans("ShowBill"),'bill').' '.$obj->facnumber.'</a></td>';
print '<td align="right">'.price($obj->amount_ht).'</td>';
print '<td align="right">'.price2num($obj->tva_tx,'MU').'%</td>';
print '<td align="right">'.price($obj->amount_ttc).'</td>';
print '<td align="center">';
print '<a href="'.DOL_URL_ROOT.'/user/card.php?id='.$obj->user_id.'">'.img_object($langs->trans("ShowUser"),'user').' '.$obj->login.'</a>'; // TODO getNomUrl ?
print '<a href="'.DOL_URL_ROOT.'/user/card.php?id='.$obj->user_id.'">'.img_object($langs->trans("ShowUser"),'user').' '.$obj->login.'</a>';
print '</td>';
print '<td>&nbsp;</td>';
print '</tr>';
Expand Down
8 changes: 7 additions & 1 deletion htdocs/core/class/commonobject.class.php
Expand Up @@ -3963,7 +3963,13 @@ function printOriginLine($line, $var, $restrictlist='')
$discount=new DiscountAbsolute($this->db);
$discount->fetch($line->fk_remise_except);
$this->tpl['description'] = $langs->transnoentities("DiscountFromExcessReceived",$discount->getNomUrl(0));
} // TODO handle (EXCESS PAID)
}
elseif ($line->desc == '(EXCESS PAID)')
{
$discount=new DiscountAbsolute($this->db);
$discount->fetch($line->fk_remise_except);
$this->tpl['description'] = $langs->transnoentities("DiscountFromExcessPaid",$discount->getNomUrl(0));
}
else
{
$this->tpl['description'] = dol_trunc($line->desc,60);
Expand Down
6 changes: 4 additions & 2 deletions htdocs/core/class/discount.class.php
Expand Up @@ -46,6 +46,7 @@ class DiscountAbsolute
public $fk_facture; // Id invoice when a discount line is used into an invoice (for credit note)
public $fk_facture_source; // Id facture avoir a l'origine de la remise
public $ref_facture_source; // Ref facture avoir a l'origine de la remise
public $ref_invoive_supplier_source;

/**
* Constructor
Expand Down Expand Up @@ -568,10 +569,11 @@ function getNomUrl($withpicto,$option='invoice')
$result='';

if ($option == 'invoice') {
$facid=! empty($this->discount_type)?$this->fk_invoice_supplier_source:$this->fk_facture_source;
$label=$langs->trans("ShowDiscount").': '.$this->ref_facture_source;
$link = '<a href="'.DOL_URL_ROOT.'/compta/facture/card.php?facid='.$this->fk_facture_source.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
$link = '<a href="'.DOL_URL_ROOT.'/compta/facture/card.php?facid='.$facid.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
$linkend='</a>';
$ref=$this->ref_facture_source;
$ref=! empty($this->discount_type)?$this->ref_invoice_supplier_source:$this->ref_facture_source;
$picto='bill';
}
if ($option == 'discount') {
Expand Down
2 changes: 1 addition & 1 deletion htdocs/core/class/html.form.class.php
Expand Up @@ -1236,7 +1236,7 @@ function select_remises($selected, $htmlname, $filter, $socid, $maxvalue=0)
if (preg_match('/\(CREDIT_NOTE\)/', $desc)) $desc=preg_replace('/\(CREDIT_NOTE\)/', $langs->trans("CreditNote"), $desc);
if (preg_match('/\(DEPOSIT\)/', $desc)) $desc=preg_replace('/\(DEPOSIT\)/', $langs->trans("Deposit"), $desc);
if (preg_match('/\(EXCESS RECEIVED\)/', $desc)) $desc=preg_replace('/\(EXCESS RECEIVED\)/', $langs->trans("ExcessReceived"), $desc);
// TODO handle (EXCESS PAID)
if (preg_match('/\(EXCESS PAID\)/', $desc)) $desc=preg_replace('/\(EXCESS PAID\)/', $langs->trans("ExcessPaid"), $desc);

$selectstring='';
if ($selected > 0 && $selected == $obj->rowid) $selectstring=' selected';
Expand Down
12 changes: 10 additions & 2 deletions htdocs/core/lib/doc.lib.php
Expand Up @@ -73,13 +73,15 @@ function doc_getlinedesc($line,$outputlangs,$hideref=0,$hidedesc=0,$issupplierli
{
$discount=new DiscountAbsolute($db);
$discount->fetch($line->fk_remise_except);
$libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromCreditNote",$discount->ref_facture_source);
$sourceref=!empty($discount_type)?$discount->ref_invoive_supplier_source:$discount->ref_facture_source;
$libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromCreditNote",$sourceref);
}
elseif ($desc == '(DEPOSIT)' && $line->fk_remise_except)
{
$discount=new DiscountAbsolute($db);
$discount->fetch($line->fk_remise_except);
$libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromDeposit",$discount->ref_facture_source);
$sourceref=!empty($discount_type)?$discount->ref_invoive_supplier_source:$discount->ref_facture_source;
// Add date of deposit
if (! empty($conf->global->INVOICE_ADD_DEPOSIT_DATE)) $libelleproduitservice.=' ('.dol_print_date($discount->datec,'day','',$outputlangs).')';
}
Expand All @@ -88,7 +90,13 @@ function doc_getlinedesc($line,$outputlangs,$hideref=0,$hidedesc=0,$issupplierli
$discount=new DiscountAbsolute($db);
$discount->fetch($line->fk_remise_except);
$libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromExcessReceived",$discount->ref_facture_source);
} // TODO handle (EXCESS PAID)
}
elseif ($desc == '(EXCESS PAID)' && $line->fk_remise_except)
{
$discount=new DiscountAbsolute($db);
$discount->fetch($line->fk_remise_except);
$libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromExcessPaid",$discount->ref_invoice_supplier_source);
}
else
{
if ($idprod)
Expand Down
14 changes: 11 additions & 3 deletions htdocs/core/lib/pdf.lib.php
Expand Up @@ -1236,13 +1236,15 @@ function pdf_getlinedesc($object,$i,$outputlangs,$hideref=0,$hidedesc=0,$issuppl
{
$discount=new DiscountAbsolute($db);
$discount->fetch($object->lines[$i]->fk_remise_except);
$libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromCreditNote",$discount->ref_facture_source);
$sourceref=!empty($discount->discount_type)?$discount->ref_invoive_supplier_source:$discount->ref_facture_source;
$libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromCreditNote",$sourceref);
}
elseif ($desc == '(DEPOSIT)' && $object->lines[$i]->fk_remise_except)
{
$discount=new DiscountAbsolute($db);
$discount->fetch($object->lines[$i]->fk_remise_except);
$libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromDeposit",$discount->ref_facture_source);
$sourceref=!empty($discount->discount_type)?$discount->ref_invoive_supplier_source:$discount->ref_facture_source;
$libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromDeposit",$sourceref);
// Add date of deposit
if (! empty($conf->global->INVOICE_ADD_DEPOSIT_DATE)) echo ' ('.dol_print_date($discount->datec,'day','',$outputlangs).')';
}
Expand All @@ -1251,7 +1253,13 @@ function pdf_getlinedesc($object,$i,$outputlangs,$hideref=0,$hidedesc=0,$issuppl
$discount=new DiscountAbsolute($db);
$discount->fetch($object->lines[$i]->fk_remise_except);
$libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromExcessReceived",$discount->ref_facture_source);
} // TODO handle (EXCESS PAID)
}
elseif ($desc == '(EXCESS PAID)' && $object->lines[$i]->fk_remise_except)
{
$discount=new DiscountAbsolute($db);
$discount->fetch($object->lines[$i]->fk_remise_except);
$libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromExcessPaid",$discount->ref_invoice_supplier_source);
}
else
{
if ($idprod)
Expand Down
11 changes: 9 additions & 2 deletions htdocs/core/tpl/objectline_view.tpl.php
Expand Up @@ -72,7 +72,8 @@
$txt='';
print img_object($langs->trans("ShowReduc"),'reduc').' ';
if ($line->description == '(DEPOSIT)') $txt=$langs->trans("Deposit");
elseif ($line->description == '(EXCESS RECEIVED)') $txt=$langs->trans("ExcessReceived"); // TODO handle (EXCESS PAID)
elseif ($line->description == '(EXCESS RECEIVED)') $txt=$langs->trans("ExcessReceived");
elseif ($line->description == '(EXCESS PAID)') $txt=$langs->trans("ExcessPaid");
//else $txt=$langs->trans("Discount");
print $txt;
?>
Expand Down Expand Up @@ -100,7 +101,13 @@
$discount=new DiscountAbsolute($this->db);
$discount->fetch($line->fk_remise_except);
echo ($txt?' - ':'').$langs->transnoentities("DiscountFromExcessReceived",$discount->getNomUrl(0));
} // TODO handle (EXCESS PAID)
}
elseif ($line->description == '(EXCESS PAID)' && $objp->fk_remise_except > 0)
{
$discount=new DiscountAbsolute($this->db);
$discount->fetch($line->fk_remise_except);
echo ($txt?' - ':'').$langs->transnoentities("DiscountFromExcessPaid",$discount->getNomUrl(0));
}
else
{
echo ($txt?' - ':'').dol_htmlentitiesbr($line->description);
Expand Down
2 changes: 2 additions & 0 deletions htdocs/fourn/class/fournisseur.facture.class.php
Expand Up @@ -1049,6 +1049,8 @@ public function delete(User $user, $notrigger=0)
}
}

// TODO Delete related discounts

if (! $error)
{
// Delete linked object
Expand Down
10 changes: 5 additions & 5 deletions htdocs/fourn/facture/card.php
Expand Up @@ -2167,10 +2167,10 @@

// Confirmation de la conversion de l'avoir en reduc
if ($action == 'converttoreduc') {
if($object->type == FactureFournisseur::TYPE_STANDARD) $type_fac = 'ExcessReceived'; // TODO translation trop-perçu => trop-payé
if($object->type == FactureFournisseur::TYPE_STANDARD) $type_fac = 'ExcessPaid';
elseif($object->type == FactureFournisseur::TYPE_CREDIT_NOTE) $type_fac = 'CreditNote';
elseif($object->type == FactureFournisseur::TYPE_DEPOSIT) $type_fac = 'Deposit';
$text = $langs->trans('ConfirmConvertToReduc', strtolower($langs->transnoentities($type_fac))); // TODO translation client => fournisseur
$text = $langs->trans('ConfirmConvertToReducSupplier', strtolower($langs->transnoentities($type_fac)));
$formconfirm = $form->formconfirm($_SERVER['PHP_SELF'] . '?facid=' . $object->id, $langs->trans('ConvertToReduc'), $text, 'confirm_converttoreduc', '', "yes", 2);
}

Expand Down Expand Up @@ -2872,7 +2872,7 @@
print ' :</td>';
print '<td align="right">' . price($obj->amount_ttc) . '</td>';
print '<td align="right">';
print '<a href="' . $_SERVER["PHP_SELF"] . '?facid=' . $object->id . '&action=unlinkdiscount&discountid=' . $obj->rowid . '">' . img_delete() . '</a>'; // TODO unlinkdiscount
print '<a href="' . $_SERVER["PHP_SELF"] . '?facid=' . $object->id . '&action=unlinkdiscount&discountid=' . $obj->rowid . '">' . img_delete() . '</a>';
print '</td></tr>';
$i ++;
if ($invoice->type == FactureFournisseur::TYPE_CREDIT_NOTE)
Expand Down Expand Up @@ -2929,7 +2929,7 @@
if ($resteapayeraffiche >= 0)
print $langs->trans('RemainderToPay');
else
print $langs->trans('ExcessReceived');
print $langs->trans('ExcessPaid');
print ' :</td>';
print '<td align="right" class="'.($resteapayeraffiche?'amountremaintopay':$cssforamountpaymentcomplete).'">' . price($resteapayeraffiche) . '</td>';
print '<td class="nowrap">&nbsp;</td></tr>';
Expand Down Expand Up @@ -3113,7 +3113,7 @@
// For standard invoice with excess paid
if ($object->type == FactureFournisseur::TYPE_STANDARD && empty($object->paye) && ($object->total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits) < 0 && $user->rights->fournisseur->facture->creer && empty($discount->id))
{
print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?facid='.$object->id.'&amp;action=converttoreduc">'.$langs->trans('ConvertExcessReceivedToReduc').'</a></div>'; // TODO translation : trop-perçu => trop payé
print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?facid='.$object->id.'&amp;action=converttoreduc">'.$langs->trans('ConvertExcessPaidToReduc').'</a></div>';
}
// For credit note
if ($object->type == FactureFournisseur::TYPE_CREDIT_NOTE && $object->statut == 1 && $object->paye == 0 && $user->rights->fournisseur->facture->creer && $object->getSommePaiement() == 0) {
Expand Down
9 changes: 8 additions & 1 deletion htdocs/langs/en_US/bills.lang
Expand Up @@ -67,6 +67,7 @@ PaidBack=Paid back
DeletePayment=Delete payment
ConfirmDeletePayment=Are you sure you want to delete this payment?
ConfirmConvertToReduc=Do you want to convert this %s into an absolute discount ?<br>The amount will so be saved among all discounts and could be used as a discount for a current or a future invoice for this customer.
ConfirmConvertToReducSupplier=Do you want to convert this %s into an absolute discount ?<br>The amount will so be saved among all discounts and could be used as a discount for a current or a future invoice for this supplier.
SupplierPayments=Suppliers payments
ReceivedPayments=Received payments
ReceivedCustomersPayments=Payments received from customers
Expand All @@ -91,7 +92,7 @@ PaymentAmount=Payment amount
ValidatePayment=Validate payment
PaymentHigherThanReminderToPay=Payment higher than reminder to pay
HelpPaymentHigherThanReminderToPay=Attention, the payment amount of one or more bills is higher than the rest to pay. <br> Edit your entry, otherwise confirm and think about creating a credit note of the excess received for each overpaid invoices.
HelpPaymentHigherThanReminderToPaySupplier=Attention, the payment amount of one or more bills is higher than the rest to pay. <br> Edit your entry, otherwise confirm.
HelpPaymentHigherThanReminderToPaySupplier=Attention, the payment amount of one or more bills is higher than the rest to pay. <br> Edit your entry, otherwise confirm and think about creating a credit note of the excess paid for each overpaid invoice.
ClassifyPaid=Classify 'Paid'
ClassifyPaidPartially=Classify 'Paid partially'
ClassifyCanceled=Classify 'Abandoned'
Expand All @@ -110,6 +111,7 @@ DoPayment=Enter payment
DoPaymentBack=Enter refund
ConvertToReduc=Convert into future discount
ConvertExcessReceivedToReduc=Convert excess received into future discount
ConvertExcessPaidToReduc=Convert excess paid into future discount
EnterPaymentReceivedFromCustomer=Enter payment received from customer
EnterPaymentDueToCustomer=Make payment due to customer
DisabledBecauseRemainderToPayIsZero=Disabled because remaining unpaid is zero
Expand Down Expand Up @@ -220,6 +222,7 @@ RemainderToPayBack=Remaining amount to refund
Rest=Pending
AmountExpected=Amount claimed
ExcessReceived=Excess received
ExcessPaid=Excess paid
EscompteOffered=Discount offered (payment before term)
EscompteOfferedShort=Discount
SendBillRef=Submission of invoice %s
Expand Down Expand Up @@ -284,15 +287,19 @@ Deposits=Down payments
DiscountFromCreditNote=Discount from credit note %s
DiscountFromDeposit=Down payments from invoice %s
DiscountFromExcessReceived=Payments from excess received of invoice %s
DiscountFromExcessPaid=Payments from excess paid of invoice %s
AbsoluteDiscountUse=This kind of credit can be used on invoice before its validation
CreditNoteDepositUse=Invoice must be validated to use this kind of credits
NewGlobalDiscount=New absolute discount
NewRelativeDiscount=New relative discount
DiscountType=Discount type
NoteReason=Note/Reason
ReasonDiscount=Reason
DiscountOfferedBy=Granted by
DiscountStillRemaining=Discounts available
DiscountAlreadyCounted=Discounts already consumed
CustomerDiscounts=Customer discounts
SupplierDiscounts=Supplier discounts
BillAddress=Bill address
HelpEscompte=This discount is a discount granted to customer because its payment was made before term.
HelpAbandonBadCustomer=This amount has been abandoned (customer said to be a bad customer) and is considered as an exceptional loose.
Expand Down

0 comments on commit f5ad93b

Please sign in to comment.