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
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.openmrs.module.billing.api.model.Bill;
import org.openmrs.module.billing.api.model.BillExemption;
import org.openmrs.module.billing.api.model.BillLineItem;
import org.openmrs.module.billing.api.model.BillLineItemStatus;
import org.openmrs.module.billing.api.model.BillStatus;
import org.openmrs.module.billing.api.model.BillableService;
import org.openmrs.module.billing.api.model.BillableServiceStatus;
Expand Down Expand Up @@ -85,7 +86,8 @@ public void afterReturning(Object returnValue, Method method, Object[] args, Obj
if (!stockItems.isEmpty()) {
// check from the list for all exemptions
boolean isExempted = checkIfOrderIsExempted(workflowService, order, ExemptionType.COMMODITY);
BillStatus lineItemStatus = isExempted ? BillStatus.EXEMPTED : BillStatus.PENDING;
BillLineItemStatus lineItemStatus = isExempted ? BillLineItemStatus.EXEMPTED
: BillLineItemStatus.PENDING;
addBillItemToBill(order, patient, cashierUUID, stockItems.get(0), null, (int) drugQuantity,
order.getDateActivated(), lineItemStatus);
}
Expand All @@ -99,7 +101,8 @@ public void afterReturning(Object returnValue, Method method, Object[] args, Obj
List<BillableService> searchResult = service.getBillableServices(searchTemplate, null);
if (!searchResult.isEmpty()) {
boolean isExempted = checkIfOrderIsExempted(workflowService, order, ExemptionType.SERVICE);
BillStatus lineItemStatus = isExempted ? BillStatus.EXEMPTED : BillStatus.PENDING;
BillLineItemStatus lineItemStatus = isExempted ? BillLineItemStatus.EXEMPTED
: BillLineItemStatus.PENDING;
addBillItemToBill(order, patient, cashierUUID, null, searchResult.get(0), 1,
order.getDateActivated(), lineItemStatus);
}
Expand Down Expand Up @@ -168,7 +171,7 @@ private Map<String, Object> buildVariablesMap(Order order, ProgramWorkflowServic
* @param cashierUUID
*/
public void addBillItemToBill(Order order, Patient patient, String cashierUUID, StockItem stockitem,
BillableService service, Integer quantity, Date orderDate, BillStatus lineItemStatus) {
BillableService service, Integer quantity, Date orderDate, BillLineItemStatus lineItemStatus) {
try {
// Search for a bill
Bill activeBill = new Bill();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.openmrs.module.billing.api.ItemPriceService;
import org.openmrs.module.billing.api.model.Bill;
import org.openmrs.module.billing.api.model.BillLineItem;
import org.openmrs.module.billing.api.model.BillLineItemStatus;
import org.openmrs.module.billing.api.model.BillStatus;
import org.openmrs.module.billing.api.model.BillableService;
import org.openmrs.module.billing.api.model.BillableServiceStatus;
Expand Down Expand Up @@ -141,7 +142,7 @@ public void addBillItemToBill(Order order, Patient patient, String cashierUUID,
billLineItem.setPrice(new BigDecimal("0.0"));
}
billLineItem.setQuantity(quantity);
billLineItem.setPaymentStatus(BillStatus.PENDING);
billLineItem.setPaymentStatus(BillLineItemStatus.PENDING);
billLineItem.setLineItemOrder(0);

// Bill
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public void synchronizeBillStatus() {
if (this.lineItems != null) {
for (BillLineItem lineItem : this.lineItems) {
if (lineItem != null && !lineItem.getVoided()) {
lineItem.setPaymentStatus(BillStatus.PAID);
lineItem.setPaymentStatus(BillLineItemStatus.PAID);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ public class BillLineItem extends BaseChangeableOpenmrsData {

private Integer lineItemOrder;

private BillStatus paymentStatus; // this should only be set to either
// pending or paid
private BillLineItemStatus paymentStatus;

private Order order;

Expand Down Expand Up @@ -133,11 +132,11 @@ public void setLineItemOrder(Integer lineItemOrder) {
this.lineItemOrder = lineItemOrder;
}

public BillStatus getPaymentStatus() {
public BillLineItemStatus getPaymentStatus() {
return paymentStatus;
}

public void setPaymentStatus(BillStatus paymentStatus) {
public void setPaymentStatus(BillLineItemStatus paymentStatus) {
this.paymentStatus = paymentStatus;
}

Expand Down
Comment thread
EDSONZ-WASSWA marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* The contents of this file are subject to the OpenMRS Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://license.openmrs.org
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* Copyright (C) OpenMRS, LLC. All Rights Reserved.
*/


package org.openmrs.module.billing.api.model;

Comment thread
EDSONZ-WASSWA marked this conversation as resolved.
/**
* The allowable statuses that a {@link BillLineItem} can have.
*/
public enum BillLineItemStatus {

PENDING(),
PAID(),
CANCELLED(),
ADJUSTED(),
EXEMPTED();
}
2 changes: 1 addition & 1 deletion api/src/main/resources/Bill.hbm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
<property name="lineItemOrder" type="int" column="line_item_order"/>
<property name="paymentStatus" column="payment_status" not-null="true">
<type name="org.hibernate.type.EnumType">
<param name="enumClass">org.openmrs.module.billing.api.model.BillStatus</param>
<param name="enumClass">org.openmrs.module.billing.api.model.BillLineItemStatus</param>
Comment thread
NethmiRodrigo marked this conversation as resolved.
<param name="type">12</param>
</type>
</property>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public void synchronizeBillStatus_shouldUpdateStatusToPaidWhenFullyPaid() {
bill.synchronizeBillStatus();

assertEquals(BillStatus.PAID, bill.getStatus());
assertEquals(BillStatus.PAID, lineItem.getPaymentStatus());
assertEquals(BillLineItemStatus.PAID, lineItem.getPaymentStatus());
}

@Test
Expand Down Expand Up @@ -177,7 +177,7 @@ public void synchronizeBillStatus_shouldUpdateStatusToPaidAfterVoidingLineItems(
bill.synchronizeBillStatus();
assertEquals(BillStatus.PAID, bill.getStatus());
// Only non-voided line items should be set to PAID
assertEquals(BillStatus.PAID, lineItem1.getPaymentStatus());
assertEquals(BillLineItemStatus.PAID, lineItem1.getPaymentStatus());
}

@Test
Expand Down Expand Up @@ -212,8 +212,8 @@ public void synchronizeBillStatus_shouldUpdateAllNonVoidedLineItemsToPaidWhenBil
bill.synchronizeBillStatus();

assertEquals(BillStatus.PAID, bill.getStatus());
assertEquals(BillStatus.PAID, lineItem1.getPaymentStatus());
assertEquals(BillStatus.PAID, lineItem2.getPaymentStatus());
assertEquals(BillLineItemStatus.PAID, lineItem1.getPaymentStatus());
assertEquals(BillLineItemStatus.PAID, lineItem2.getPaymentStatus());
// Voided line items should not be updated
assertNull(voidedLineItem.getPaymentStatus());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.openmrs.module.billing.api.base.PagingInfo;
import org.openmrs.module.billing.api.model.Bill;
import org.openmrs.module.billing.api.model.BillLineItem;
import org.openmrs.module.billing.api.model.BillLineItemStatus;
import org.openmrs.module.billing.api.model.BillStatus;
import org.openmrs.module.billing.api.model.Payment;
import org.openmrs.module.billing.api.model.PaymentMode;
Expand Down Expand Up @@ -148,7 +149,7 @@ public void saveBill_shouldCreateNewBillWithNewItem() {
StockItem stockItem = existingItem.getItem();

BillLineItem lineItem = newBill.addLineItem(stockItem, BigDecimal.valueOf(150), "New price", 2);
lineItem.setPaymentStatus(BillStatus.PENDING);
lineItem.setPaymentStatus(BillLineItemStatus.PENDING);
lineItem.setUuid(UUID.randomUUID().toString());

Bill savedBill = billService.saveBill(newBill);
Expand Down Expand Up @@ -227,7 +228,7 @@ public void saveBill_shouldAllowAddingLineItemsToPendingBill() {
BillLineItem newLineItem = new BillLineItem();
newLineItem.setPrice(BigDecimal.valueOf(25.50));
newLineItem.setQuantity(2);
newLineItem.setPaymentStatus(BillStatus.PENDING);
newLineItem.setPaymentStatus(BillLineItemStatus.PENDING);
newLineItem.setLineItemOrder(pendingBill.getLineItems().size());
pendingBill.addLineItem(newLineItem);

Expand All @@ -251,7 +252,7 @@ public void saveBill_shouldThrowExceptionWhenAddingLineItemsToPaidBill() {
BillLineItem newLineItem = new BillLineItem();
newLineItem.setPrice(BigDecimal.valueOf(25.50));
newLineItem.setQuantity(2);
newLineItem.setPaymentStatus(BillStatus.PENDING);
newLineItem.setPaymentStatus(BillLineItemStatus.PENDING);
paidBill.addLineItem(newLineItem);

// Should throw exception when saving (BillValidator catches line item
Expand Down Expand Up @@ -500,7 +501,7 @@ public void saveBill_shouldGenerateReceiptNumberWhenNotProvided() {
Bill templateBill = billService.getBill(0);
BillLineItem existingItem = templateBill.getLineItems().get(0);
BillLineItem lineItem = newBill.addLineItem(existingItem.getItem(), BigDecimal.valueOf(100), "Test price", 1);
lineItem.setPaymentStatus(BillStatus.PENDING);
lineItem.setPaymentStatus(BillLineItemStatus.PENDING);
lineItem.setUuid(UUID.randomUUID().toString());

Bill savedBill = billService.saveBill(newBill);
Expand Down
15 changes: 15 additions & 0 deletions omod/src/main/resources/liquibase.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1095,6 +1095,21 @@
baseTableName="bill_exemption_rule" baseColumnNames="voided_by"
referencedTableName="users" referencedColumnNames="user_id"/>
</changeSet>
<changeSet id="openmrs.billing-004-20260320-migrate-line-item-payment-status" author="Edson Wasswa">
<preConditions onFail="MARK_RAN">
<sqlCheck expectedResult="1">
SELECT CASE WHEN EXISTS (
SELECT 1 FROM cashier_bill_line_item WHERE payment_status = 'POSTED'
) THEN 1 ELSE 0 END
</sqlCheck>
</preConditions>
<sql>
UPDATE cashier_bill_line_item
SET payment_status = 'PENDING'
WHERE payment_status = 'POSTED'
</sql>
</changeSet>
</databaseChangeLog>

<changeSet id="openmrs.billing-004-20260320-add-provider-id-to-bill-payment" author="Nethmi Rodrigo">
<comment>Add cashier (provider) for each payment to track which cashier processed the payment</comment>
Comment on lines 1114 to 1115

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be inside the tags.

Expand Down
Loading