Merge pull request #9610 from atm-john/FIX_situation_credit_note
Fix situation credit note
This commit is contained in:
commit
ee8b5030a0
@ -953,6 +953,8 @@ if (empty($reshook))
|
||||
|
||||
if($facture_source->type == Facture::TYPE_SITUATION)
|
||||
{
|
||||
$source_fk_prev_id = $line->fk_prev_id; // temporary storing situation invoice fk_prev_id
|
||||
$line->fk_prev_id = $line->id; // Credit note line need to be linked to the situation invoice it is create from
|
||||
|
||||
if(!empty($facture_source->tab_previous_situation_invoice))
|
||||
{
|
||||
@ -976,7 +978,7 @@ if (empty($reshook))
|
||||
$maxPrevSituationPercent = 0;
|
||||
foreach($facture_source->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine)
|
||||
{
|
||||
if($prevLine->id == $line->fk_prev_id)
|
||||
if($prevLine->id == $source_fk_prev_id)
|
||||
{
|
||||
$maxPrevSituationPercent = max($maxPrevSituationPercent,$prevLine->situation_percent);
|
||||
|
||||
@ -1534,7 +1536,8 @@ if (empty($reshook))
|
||||
$line->origin = $object->origin;
|
||||
$line->origin_id = $line->id;
|
||||
$line->fetch_optionals($line->id);
|
||||
|
||||
$line->situation_percent = $line->get_prev_progress($object->id); // get good progress including credit note
|
||||
|
||||
// Si fk_remise_except defini on vérifie si la réduction à déjà été appliquée
|
||||
if ($line->fk_remise_except)
|
||||
{
|
||||
|
||||
@ -4828,9 +4828,10 @@ class FactureLigne extends CommonInvoiceLine
|
||||
* Warning: If invoice is a replacement invoice, this->fk_prev_id is id of the replaced line.
|
||||
*
|
||||
* @param int $invoiceid Invoice id
|
||||
* @param bool $include_credit_note Include credit note or not
|
||||
* @return int >= 0
|
||||
*/
|
||||
function get_prev_progress($invoiceid)
|
||||
function get_prev_progress($invoiceid, $include_credit_note=true)
|
||||
{
|
||||
if (is_null($this->fk_prev_id) || empty($this->fk_prev_id) || $this->fk_prev_id == "") {
|
||||
return 0;
|
||||
@ -4844,7 +4845,26 @@ class FactureLigne extends CommonInvoiceLine
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql && $resql->num_rows > 0) {
|
||||
$res = $this->db->fetch_array($resql);
|
||||
return floatval($res['situation_percent']);
|
||||
|
||||
$returnPercent = floatval($res['situation_percent']);
|
||||
|
||||
if($include_credit_note) {
|
||||
|
||||
$sql = 'SELECT fd.situation_percent FROM ' . MAIN_DB_PREFIX . 'facturedet fd';
|
||||
$sql.= ' JOIN ' . MAIN_DB_PREFIX . 'facture f ON (f.rowid = fd.fk_facture) ';
|
||||
$sql.= ' WHERE fd.fk_prev_id =' . $this->fk_prev_id;
|
||||
$sql.= ' AND f.situation_cycle_ref = '.$tmpinvoice->situation_cycle_ref; // Prevent cycle outed
|
||||
$sql.= ' AND f.type = '.Facture::TYPE_CREDIT_NOTE;
|
||||
|
||||
$res = $this->db->query($sql);
|
||||
if($res) {
|
||||
while($obj = $this->db->fetch_object($res)) {
|
||||
$returnPercent = $returnPercent + floatval($obj->situation_percent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $returnPercent;
|
||||
} else {
|
||||
$this->error = $this->db->error();
|
||||
dol_syslog(get_class($this) . "::select Error " . $this->error, LOG_ERR);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user