Fix outing invoice ligne progress
This commit is contained in:
parent
b37a2f17bf
commit
689b3e3b64
@ -2168,12 +2168,12 @@ if (empty($reshook))
|
|||||||
$object->fetch($id,'', '','', TRUE);
|
$object->fetch($id,'', '','', TRUE);
|
||||||
|
|
||||||
if ($object->statut == Facture::STATUS_VALIDATED
|
if ($object->statut == Facture::STATUS_VALIDATED
|
||||||
|
&& $object->type == Facture::TYPE_SITUATION
|
||||||
&& $user->rights->facture->creer
|
&& $user->rights->facture->creer
|
||||||
&& !$objectidnext
|
&& !$objectidnext
|
||||||
&& $object->is_last_in_cycle()
|
&& $object->is_last_in_cycle()
|
||||||
&& ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->facture->creer))
|
&& ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->facture->creer))
|
||||||
|| (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->facture->invoice_advance->unvalidate)))
|
|| (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->facture->invoice_advance->unvalidate)))
|
||||||
//&& ($object->total_ttc - $totalcreditnotes) == 0
|
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
$outingError = 0;
|
$outingError = 0;
|
||||||
@ -2212,11 +2212,52 @@ if (empty($reshook))
|
|||||||
$sql.= ' , situation_counter='.$object->situation_counter;
|
$sql.= ' , situation_counter='.$object->situation_counter;
|
||||||
$sql.= ' WHERE rowid IN ('.implode(',',$linkedCreditNotesList).')';
|
$sql.= ' WHERE rowid IN ('.implode(',',$linkedCreditNotesList).')';
|
||||||
|
|
||||||
// TODO : change each progression persent on each lines
|
|
||||||
|
|
||||||
$resql=$db->query($sql);
|
$resql=$db->query($sql);
|
||||||
if (!$resql) $errors++;
|
if (!$resql) $errors++;
|
||||||
|
|
||||||
|
// Change each progression persent on each lines
|
||||||
|
foreach($object->lines as $line)
|
||||||
|
{
|
||||||
|
|
||||||
|
// no traitement for special product
|
||||||
|
if ($line->product_type == 9 ) continue;
|
||||||
|
|
||||||
|
|
||||||
|
if(!empty($object->tab_previous_situation_invoice))
|
||||||
|
{
|
||||||
|
// search the last invoice in cycle
|
||||||
|
$lineIndex = count($object->tab_previous_situation_invoice) - 1;
|
||||||
|
$searchPreviousInvoice = true;
|
||||||
|
while( $searchPreviousInvoice )
|
||||||
|
{
|
||||||
|
if($object->tab_previous_situation_invoice[$lineIndex]->type == Facture::TYPE_SITUATION || $lineIndex < 1)
|
||||||
|
{
|
||||||
|
$searchPreviousInvoice=false; // find, exit;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$lineIndex--; // go to previous invoice in cycle
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$maxPrevSituationPercent = 0;
|
||||||
|
foreach($object->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine)
|
||||||
|
{
|
||||||
|
if($prevLine->id == $line->fk_prev_id)
|
||||||
|
{
|
||||||
|
$maxPrevSituationPercent = max($maxPrevSituationPercent,$prevLine->situation_percent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$line->situation_percent = $line->situation_percent - $maxPrevSituationPercent;
|
||||||
|
|
||||||
|
if($line->update()<0) $errors++;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$errors)
|
if (!$errors)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user