FIX credit note can be split
This commit is contained in:
parent
7ae6472e36
commit
6deba39c6a
@ -195,6 +195,29 @@ abstract class CommonInvoice extends CommonObject
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return amount (with tax) of all converted amount for this credit note
|
||||
*
|
||||
* @param int $multicurrency Return multicurrency_amount instead of amount
|
||||
* @return int <0 if KO, Sum of credit notes and deposits amount otherwise
|
||||
*/
|
||||
function getSumFromThisCreditNotesNotUsed($multicurrency=0)
|
||||
{
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
|
||||
|
||||
$discountstatic=new DiscountAbsolute($this->db);
|
||||
$result=$discountstatic->getSumFromThisCreditNotesNotUsed($this, $multicurrency);
|
||||
if ($result >= 0)
|
||||
{
|
||||
return $result;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$discountstatic->error;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Renvoie tableau des ids de facture avoir issus de la facture
|
||||
*
|
||||
|
||||
@ -568,6 +568,49 @@ class DiscountAbsolute
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Return amount (with tax) of all converted amount for this credit note
|
||||
*
|
||||
* @param CommonInvoice $invoice Object invoice
|
||||
* @param int $multicurrency Return multicurrency_amount instead of amount
|
||||
* @return int <0 if KO, Sum of credit notes and deposits amount otherwise
|
||||
*/
|
||||
function getSumFromThisCreditNotesNotUsed($invoice, $multicurrency=0)
|
||||
{
|
||||
dol_syslog(get_class($this)."::getSumCreditNotesUsed", LOG_DEBUG);
|
||||
|
||||
if ($invoice->element == 'facture' || $invoice->element == 'invoice')
|
||||
{
|
||||
$sql = 'SELECT sum(rc.amount_ttc) as amount, sum(rc.multicurrency_amount_ttc) as multicurrency_amount';
|
||||
$sql.= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc';
|
||||
$sql.= ' WHERE rc.fk_facture IS NULL AND rc.fk_facture_source = '.$invoice->id;
|
||||
}
|
||||
else if ($invoice->element == 'invoice_supplier')
|
||||
{
|
||||
$sql = 'SELECT sum(rc.amount_ttc) as amount, sum(rc.multicurrency_amount_ttc) as multicurrency_amount';
|
||||
$sql.= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc';
|
||||
$sql.= ' WHERE rc.fk_invoice_supplier IS NULL AND rc.fk_invoice_supplier_source = '.$invoice->id;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=get_class($this)."::getSumCreditNotesUsed was called with a bad object as a first parameter";
|
||||
dol_print_error($this->error);
|
||||
return -1;
|
||||
}
|
||||
|
||||
$resql=$this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$obj = $this->db->fetch_object($resql);
|
||||
if ($multicurrency) return $obj->multicurrency_amount;
|
||||
else return $obj->amount;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error = $this->db->lasterror();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return clickable ref of object (with picto or not)
|
||||
|
||||
@ -852,8 +852,11 @@ if ($resql)
|
||||
$remaintopay = $obj->total_ttc - $totalpay;
|
||||
|
||||
//If invoice has been converted and the conversion has been used, we dont have remain to pay on invoice
|
||||
if($facturestatic->type == FactureFournisseur::TYPE_CREDIT_NOTE && $facturestatic->statut == FactureFournisseur::STATUS_CLOSED) {
|
||||
if($facturestatic->isCreditNoteUsed())$remaintopay=0;
|
||||
if($facturestatic->type == FactureFournisseur::TYPE_CREDIT_NOTE) {
|
||||
|
||||
if($facturestatic->isCreditNoteUsed()){
|
||||
$remaintopay=-$facturestatic->getSumFromThisCreditNotesNotUsed();
|
||||
}
|
||||
}
|
||||
|
||||
print '<tr class="oddeven">';
|
||||
|
||||
@ -3778,11 +3778,11 @@ class Societe extends CommonObject
|
||||
|
||||
$outstandingOpened+=$obj->total_ttc - $paiement - $creditnotes - $deposits;
|
||||
}
|
||||
|
||||
//if credit note is converted but not used
|
||||
if($mode == 'supplier' && $obj->type == FactureFournisseur::TYPE_CREDIT_NOTE && $tmpobject->isCreditNoteUsed())$outstandingOpened-=$tmpobject->getSumFromThisCreditNotesNotUsed();
|
||||
|
||||
|
||||
if($mode == 'supplier' && $obj->type == FactureFournisseur::TYPE_CREDIT_NOTE && $obj->fk_statut == FactureFournisseur::STATUS_CLOSED && !$tmpobject->isCreditNoteUsed()) { //if credit note is converted but not used
|
||||
if(empty($paiement)) $paiement = $tmpobject->getSommePaiement();
|
||||
$outstandingOpened+=$obj->total_ttc-$paiement;
|
||||
}
|
||||
}
|
||||
return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax); // 'opened' is 'incl taxes'
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user