I have written a code which is working fine but I'am using too many If and else-if conditions. Is there a way to minimise it? Based on the integer values shippingStatus
, invoiceStatus
and paymentStatus
values should change.
int qtyOrdered = dynamic integer values;
int qtyShipped = dynamic integer value;
int qtyReturned = dynamic integer values;
int qtyInvoiced = dynamic integer values;
ShiStatus shippingStatus;
InvStatus invoiceStatus;
PayStatus paymentStatus;
if (qtyOrdered == qtyShipped && qtyShipped >= qtyReturned) {
shippingStatus = ShiStatus.FULLY_SHIPPED;
} else if (qtyOrdered > qtyShipped && qtyShipped > qtyReturned) {
shippingStatus = ShiStatus.PARTIALLY_SHIPPED;
} else if (qtyOrdered > qtyShipped && qtyShipped == qtyReturned) {
shippingStatus = ShiStatus.NOT_SHIPPED;
} else {
shippingStatus = salesOrder.getShippingStatus();
}
if (qtyOrdered == qtyInvoiced && qtyInvoiced > qtyReturned) {
invoiceStatus = ShiStatus.FULLY_INVOICED;
} else if (qtyOrdered == qtyInvoiced && qtyInvoiced == qtyReturned) {
invoiceStatus = InvStatus .NOT_APPLICABLE;
} else if (qtyOrdered > qtyInvoiced && qtyShipped > qtyReturned) {
invoiceStatus = InvStatus .PARTIALLY_INVOICED;
} else if (qtyOrdered > qtyInvoiced && qtyShipped == qtyReturned) {
invoiceStatus = ShiStatus.NOT_INVOICED;
} else {
invoiceStatus = salesOrder.getInvoiceStatus();
}
if (MathUtils.isFirstLessThanSecond(totalAmountAfterEvent, salesOrder.getAmountPaid())) {
paymentStatus = PayStatus .FULLY_PAID;
} else if (MathUtils.areEqual(totalAmountAfterEvent, BigDecimal.ZERO)) {
paymentStatus = PayStatus .NOT_APPLICABLE;
} else if (MathUtils.isFirstLessThanSecond(salesOrder.getAmountPaid(), totalAmountAfterEvent) && (MathUtils.isFirstLessThanSecond(salesOrder.getAmountPaid(), totalAmountAfterEvent))) {
paymentStatus = PayStatus .PARTIALLY_PAID;
} else if (MathUtils.isFirstLessThanSecond(salesOrder.getAmountPaid(), totalAmountAfterEvent) && (MathUtils.isFirstLessThanSecond(totalAmountAfterEvent, salesOrder.getAmountPaid()) || (MathUtils.areEqual(totalAmountAfterEvent, salesOrder.getAmountPaid())))) {
paymentStatus = PayStatus .PARTIALLY_PAID;
} else {
paymentStatus = salesOrder.getPaymentStatus();
}
Aucun commentaire:
Enregistrer un commentaire