NEW On invoice, show also nb of credit notes notyet converted for

consumption
This commit is contained in:
ldestailleur 2025-08-15 18:43:58 +02:00
parent 4edb50855f
commit ee52d31f18
6 changed files with 67 additions and 10 deletions

View file

@ -4788,6 +4788,8 @@ if ($action == 'create') {
$absolute_discount = price2num($absolute_discount, 'MT');
$absolute_creditnote = price2num($absolute_creditnote, 'MT');
$nb_creditnote_notyetavailable = $soc->getOpenCreditNotesNotYetConvertedIntoDiscount(0);
$author = new User($db);
if ($object->user_creation_id) {
$author->fetch($object->user_creation_id);
@ -5245,7 +5247,7 @@ if ($action == 'create') {
print ' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities("CorrectInvoice", $facusing->getNomUrl(1, '', 32)).'</span>';
}
// Retrieve credit note ids
// Retrieve credit note ids (credit notes generated from this invoice)
$object->getListIdAvoirFromInvoice();
if (!empty($object->creditnote_ids)) {

View file

@ -453,7 +453,8 @@ abstract class CommonInvoice extends CommonObject
$sql = "SELECT rowid";
$sql .= " FROM ".$this->db->prefix().$this->table_element;
$sql .= " WHERE fk_facture_source = ".((int) $this->id);
$sql .= " AND type = 2";
$sql .= " AND type = ".self::TYPE_CREDIT_NOTE;
$resql = $this->db->query($sql);
if ($resql) {
$num = $this->db->num_rows($resql);

View file

@ -378,8 +378,6 @@ class DiscountAbsolute extends CommonObject
*/
public function delete($user)
{
global $conf, $langs;
// Check if we can remove the discount
if ($this->fk_facture_source) {
$sql = "SELECT COUNT(rowid) as nb";
@ -605,7 +603,7 @@ class DiscountAbsolute extends CommonObject
* Return amount (with tax) of discounts currently available for a company, user or other criteria
*
* @param ?Societe $company Object third party for filter
* @param ?User $user Filtre sur un user auteur des remises
* @param ?User $user Filtre on an author of the discount
* @param string $filter Filter other. Warning: Do not use a user input value here.
* @param int|float $maxvalue Filter on max value for discount
* @param int<0,1> $discount_type 0 => customer discount, 1 => supplier discount
@ -671,7 +669,6 @@ class DiscountAbsolute extends CommonObject
return -1;
}
/**
* Return amount (with tax) of all deposits invoices used by invoice as a payment.
* Should always be empty, except if option FACTURE_DEPOSITS_ARE_JUST_PAYMENTS or FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS is on (not recommended).

View file

@ -24,14 +24,22 @@
* $backtopage URL to come back to from discount modification pages
*/
/**
* @var Object $object
/**
* @var Conf $conf
* @var Form $form
* @var Object $object
* @var Translate $langs
* @var Societe $thirdparty
* @var float $absolute_discount Amount of fixed discounts available
* @var float $absolute_creditnote Amount of credit notes available
* @var string $backtopage
*
* @var float $absolute_discount Amount of fixed discounts available
* @var float $absolute_creditnote Amount of credit notes available
* @var int $nb_creditnote_notyetavailable Nb of cedit notes not yet available (not yet converted into discount)
* @var string $filterabsolutediscount
* @var string $filtercreditnote
* @var string $resteapayer
* @var int $cannotApplyDiscount
* @var int $discount_type
*/
print '<!-- BEGIN object_discounts.tpl.php -->'."\n";
@ -140,6 +148,12 @@ if ($absolute_creditnote > 0) {
}
}
if ($nb_creditnote_notyetavailable > 0) {
print '<!-- absolute_creditnote not yet converted -->';
$translationKey = 'SomeNotConvertedCreditNoteExists';
print '<br><span class="opacitymedium">'.$langs->trans($translationKey, $nb_creditnote_notyetavailable).'</span>';
}
if ($absolute_discount <= 0 && $absolute_creditnote <= 0) {
if ($conf->dol_optimize_smallscreen) {
$translationKey = 'AbsoluteDiscount';

View file

@ -329,3 +329,4 @@ RuleForLinesDates=Rule for lines dates
Prepaid=Prepaid
Postpaid=Postpaid
SetRuleForLinesDates=Set rule for lines dates
SomeNotConvertedCreditNoteExists=There is %s credit notes not yet converted for consumption

View file

@ -2810,6 +2810,48 @@ class Societe extends CommonObject
}
}
/**
* Return amount (with tax) of discounts currently available for a company, user or other criteria
*
* @param int<0,1> $discount_type 0 => customer discount, 1 => supplier discount
* @return int Return integer <0 if KO, nb otherwise
*/
public function getOpenCreditNotesNotYetConvertedIntoDiscount($discount_type = 0)
{
global $conf;
$sql = "SELECT COUNT(f.rowid) as nb, SUM(f.total_ttc) as amount, SUM(f.multicurrency_total_ttc) as multicurrency_amount";
if (!empty($discount_type)) {
$sql .= " FROM ".$this->db->prefix()."facture_fourn as f";
} else {
$sql .= " FROM ".$this->db->prefix()."facture as f";
}
$sql .= " WHERE f.entity = ".$conf->entity;
$sql .= " AND paye = 0 AND fk_statut = 1";
$sql .= " AND f.type = ".CommonInvoice::TYPE_CREDIT_NOTE;
$sql .= " AND NOT EXISTS (SELECT rowid FROM ".$this->db->prefix()."societe_remise_except as rc";
$sql .= " WHERE rc.discount_type = ".((int) $discount_type);
if (!empty($discount_type)) {
$sql .= " AND rc.fk_invoice_supplier = f.rowid";
} else {
$sql .= " AND rc.fk_facture = f.rowid";
}
$sql .= " AND rc.fk_soc = ".((int) $this->socid);
$sql .= ")";
$sql .= " AND f.fk_soc = ".((int) $this->socid);
$resql = $this->db->query($sql);
if ($resql) {
$obj = $this->db->fetch_object($resql);
return $obj->nb;
}
return -1;
}
/**
* Return array of sales representatives
*