DPR
effective width divide by zero fixed

effective width divide by zero fixed

Here is the analysis of the codebase, the recent changes in the branch, and the answers to your questions regarding the DivideByZeroException.


1. Analysis of the Fix in the Current Branch

Your teammate has already committed a fix (commit 9f95548) that guards against DivideByZeroException in all vulnerable endpoints in PrdnPlanController.cs.

Specifically, checks for firstLineInfo == null || firstLineInfo.EffectiveWidth == 0 were added to:

If the condition is met, the controller gracefully adds a model state error (e.g., “First issue details not found or issue width is 0. Cannot calculate receipt quantity.”) and avoids executing the division.


2. Answers to Your Questions

What is Effective Width?

EffectiveWidth represents the total actual width of the material being moved (issued or produced) in a given line item of a production plan:

  • For Issue Lines (Input raw material coil): It is the width (coil size) of that issued coil itself.
  • For Receipt/Scrap Lines (Output slit coils or scrap): It is the total width of the slits produced on that line, calculated as: $$\text{EffectiveWidth} = \text{CoilSize} \times \text{NoOfSlits}$$

Where exactly are we using it and what is its purpose?

  • Proportional Weight Allocation: It is used in PrdnPlanController.cs to automatically calculate receipt or scrap weights (Qty) based on the input coil weight. The formula used is: $$\text{qtyPerWidth} = \frac{\text{issueQtySum}}{\text{firstLineInfo.EffectiveWidth}}$$ $$\text{totalQty} = \text{totalWidth} \times \text{qtyPerWidth}$$
  • UI Display & Reports: It is stored in the database (PrdnPlan1.EffectiveWidth column) and shown in the UI (PrdnPlan1Index.razor) as “Size” and printed on Excel reports.
  • Width Balancing: It ensures that the sum of the widths of all slitted receipt lines and scrap matches the parent coil’s width.

Are we using it only for slitting plans or FG plans also?

  • Only for Slitting and Transfer plans.
  • It is not used for Finished Goods (FG) plans. Finished goods are standard shaped products where weight is calculated based on a fixed standard piece weight (i.e., stdweight * Qty1) rather than coil width proportions.
  • In the repository, PrdnPlan1Create (used for creating FG lines) explicitly comments out and excludes EffectiveWidth.

Is the fix ok or do we take the effective width as 1 when it goes as zero?

  • The committed validation fix is correct; defaulting to 1 should NOT be used.
  • Reason: If we fallback to 1 when EffectiveWidth is 0, it would cause massive, completely incorrect weight calculations. For example, if an issue coil weighs 10,000 kg and has a width of 0:
    • If we fallback to 1, qtyPerWidth = 10,000 / 1 = 10,000 kg/mm.
    • Creating a slit receipt with a total width of 500 mm would calculate the weight as $500 \times 10,000 = 5,000,000\text{ kg}$ (5,000 tons!).
  • The validation error correctly prevents database corruption and prompts the user to either define the issue line first or correct the master data width.