Skip to content

Commit

Permalink
period of cover is the next consumer's date when the on hand is 0
Browse files Browse the repository at this point in the history
  • Loading branch information
hichamlahlou committed Jan 23, 2025
1 parent 26c078b commit 4d050c9
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions src/model/flowplan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -586,18 +586,29 @@ Duration FlowPlan::getPeriodOfCover() const {

// Case 2: Regular case
left_for_consumption = getOnhand();
auto fpiter2 = getBuffer()->getFlowPlans().begin(this);
++fpiter2;
while (fpiter2 != getBuffer()->getFlowPlans().end()) {
// On hand is 0, we return the next replenishment
if (getOnhand() == 0 && fpiter2->getQuantity() > 0.0)
return fpiter2->getDate() - getDate();
if (fpiter2->getQuantity() < 0.0) {
left_for_consumption += fpiter2->getQuantity();
if (left_for_consumption < ROUNDING_ERROR)
return fpiter2->getDate() - getDate();
if (left_for_consumption > 0) {
auto fpiter2 = getBuffer()->getFlowPlans().begin(this);
++fpiter2;
while (fpiter2 != getBuffer()->getFlowPlans().end()) {
if (fpiter2->getQuantity() < 0.0) {
left_for_consumption += fpiter2->getQuantity();
if (left_for_consumption < ROUNDING_ERROR)
return fpiter2->getDate() - getDate();
}
++fpiter2;
}
} else {
// Case 3:
// On hand is 0 so we display the next consumer's date
auto fpiter2 = getBuffer()->getFlowPlans().begin(this);
++fpiter2;
while (fpiter2 != getBuffer()->getFlowPlans().end()) {
if (fpiter2->getQuantity() < 0.0) {
return max(0L, fpiter2->getDate() - getDate() -
fpiter2->getOperationPlan()->getDelay());
}
++fpiter2;
}
}

return Duration(999L * 86400L);
Expand Down

0 comments on commit 4d050c9

Please sign in to comment.