Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
8.6.0-SNAPSHOT (WIP)
==================
* [OLMIS-8176](https://openlmis.atlassian.net/browse/OLMIS-8176): Added a Pack Size column to the requisition printed report.

8.5.1 / 2026-06-09
==================
Expand Down
17 changes: 12 additions & 5 deletions src/main/java/org/openlmis/requisition/utils/ReportUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,18 @@
import java.util.Map;
import java.util.ResourceBundle;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import net.sf.jasperreports.engine.JRBand;
import net.sf.jasperreports.engine.design.JRDesignTextField;
import org.openlmis.requisition.domain.RequisitionTemplateColumn;
import org.openlmis.requisition.domain.requisition.RequisitionStatus;
import org.springframework.context.i18n.LocaleContextHolder;

public final class ReportUtils {
private static final String FULL_PRODUCT_NAME_COLUMN = "orderable.fullProductName";
// key of the static Pack size column in requisitionLines.jrxml (not a template column)
private static final String PACK_SIZE_COLUMN = "packSize";

private ReportUtils() {
throw new UnsupportedOperationException();
}
Expand Down Expand Up @@ -94,6 +99,8 @@ public static Map<String, RequisitionTemplateColumn> getSortedTemplateColumnsFor
public static void customizeBandWithTemplateFields(
JRBand band, Map<String, RequisitionTemplateColumn> columns, int width, int margin) {
List<String> foundTemplateKeys = columns.keySet().stream()
.flatMap(key -> FULL_PRODUCT_NAME_COLUMN.equals(key)
? Stream.of(key, PACK_SIZE_COLUMN) : Stream.of(key))
.filter(key -> band.getElementByKey(key) != null)
.collect(Collectors.toList());
List<JRDesignTextField> foundColumns = band.getChildren().stream()
Expand All @@ -118,16 +125,16 @@ public static void customizeBandWithTemplateFields(

private static double getWidthMultipier(int width, int margin, List<String> foundTemplateKeys,
List<JRDesignTextField> foundColumns) {
int toFill = 0;
int keptTotal = 0;
for (JRDesignTextField field : foundColumns) {
if (!foundTemplateKeys.contains(field.getKey())) {
toFill += field.getWidth();
if (foundTemplateKeys.contains(field.getKey())) {
keptTotal += field.getWidth();
}
}

if (toFill != 0) {
if (keptTotal != 0) {
int lineWidth = width - 2 * margin;
return (double)lineWidth / (lineWidth - toFill);
return (double) lineWidth / keptTotal;
}
return 1;
}
Expand Down
26 changes: 26 additions & 0 deletions src/main/resources/jasperTemplates/requisitionLines.jrxml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,19 @@
</textElement>
<textFieldExpression><![CDATA[$P{template}.viewColumns().get("orderable.fullProductName").getLabel()]]></textFieldExpression>
</textField>
<textField>
<reportElement key="packSize" mode="Opaque" x="100" y="0" width="34" height="35" backcolor="#CCCCCC" uuid="b3b11473-3619-446a-8526-d0a285a82b4b"/>
<box padding="2">
<topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textElement>
<font size="6"/>
</textElement>
<textFieldExpression><![CDATA["Pack Size"]]></textFieldExpression>
</textField>
<textField>
<reportElement key="orderable.productCode" mode="Opaque" x="9" y="0" width="31" height="35" backcolor="#CCCCCC" uuid="aa050bad-b263-43fa-8d5e-9c9b506f2260">
<property name="com.jaspersoft.studio.unit.y" value="px"/>
Expand Down Expand Up @@ -663,6 +676,19 @@
</textElement>
<textFieldExpression><![CDATA[$P{template}.viewColumns().get("orderable.fullProductName").getIsDisplayed() ? $F{orderable}.getFullProductName() : null]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="true">
<reportElement key="packSize" x="100" y="0" width="34" height="25" uuid="29e9d253-e341-4e03-b54b-ce9eecb6a861"/>
<box padding="2">
<topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textElement>
<font size="6"/>
</textElement>
<textFieldExpression><![CDATA[$F{orderable}.getNetContent()]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="true">
<reportElement key="orderable.productCode" x="9" y="0" width="31" height="25" uuid="364650f2-c5ab-49b6-b74a-89aa733eeda5">
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
Expand Down
26 changes: 26 additions & 0 deletions src/test/java/org/openlmis/requisition/utils/ReportUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,32 @@ public void shouldSetProperFieldsWidthWhenAllFieldsInRequisitionTemplate() {
assertEquals(FIELD_THREE_WIDTH, fieldThree.getWidth(), DELTA);
}

@Test
public void shouldKeepPackSizeColumnAfterProductNameWhenNotInTemplate() {
// given
JRBand jrBand = mock(JRBand.class);
JRDesignTextField productName = getField("orderable.fullProductName", FIELD_ONE_WIDTH);
JRDesignTextField packSize = getField("packSize", FIELD_THREE_WIDTH);

LinkedList<JRChild> children = new LinkedList<>(Arrays.asList(productName, packSize));
when(jrBand.getChildren()).thenReturn(children);
when(jrBand.getElementByKey("orderable.fullProductName")).thenReturn(productName);
when(jrBand.getElementByKey("packSize")).thenReturn(packSize);

Map<String, RequisitionTemplateColumn> columns = new LinkedHashMap<>();
RequisitionTemplateColumn productNameColumn = mock(RequisitionTemplateColumn.class);
stubDisplay(productNameColumn, 1);
columns.put("orderable.fullProductName", productNameColumn);

// when
ReportUtils.customizeBandWithTemplateFields(jrBand, columns, WIDTH, MARGIN);

// then
assertTrue(children.contains(packSize));
assertEquals(MARGIN, productName.getX());
assertEquals(productName.getX() + productName.getWidth(), packSize.getX());
}

private void stubDisplay(RequisitionTemplateColumn column, int displayOrder) {
when(column.getDisplayOrder()).thenReturn(displayOrder);
when(column.getIsDisplayed()).thenReturn(true);
Expand Down
Loading