Skip to content

Commit

Permalink
Fixed error with cash opening document type
Browse files Browse the repository at this point in the history
  • Loading branch information
yamelsenih committed Nov 17, 2021
1 parent 0e8e338 commit d2212cd
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 13 deletions.
8 changes: 7 additions & 1 deletion src/main/java/org/spin/base/util/ConvertUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,13 @@ public static Order.Builder convertOrder(MOrder order) {
MRefList reference = MRefList.get(Env.getCtx(), MOrder.DOCSTATUS_AD_REFERENCE_ID, order.getDocStatus(), null);
MPriceList priceList = MPriceList.get(Env.getCtx(), order.getM_PriceList_ID(), order.get_TrxName());
BigDecimal baseAmount = Arrays.asList(order.getLines()).stream().map(orderLine -> Optional.ofNullable(orderLine.getPriceList()).orElse(Env.ZERO)).reduce(BigDecimal.ZERO, BigDecimal::add);
Optional<BigDecimal> paidAmount = MPayment.getOfOrder(order).stream().map(payment -> getConvetedAmount(order, payment, payment.getPayAmt())).collect(Collectors.reducing(BigDecimal::add));
Optional<BigDecimal> paidAmount = MPayment.getOfOrder(order).stream().map(payment -> {
BigDecimal paymentAmount = payment.getPayAmt();
if(!payment.isReceipt()) {
paymentAmount = payment.getPayAmt().negate();
}
return getConvetedAmount(order, payment, paymentAmount);
}).collect(Collectors.reducing(BigDecimal::add));
BigDecimal grandTotal = order.getGrandTotal();
BigDecimal totalLines = order.getTotalLines();
BigDecimal paymentAmount = Env.ZERO;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4185,7 +4185,18 @@ private MPayment createPaymentFromOrder(MOrder salesOrder, CreatePaymentRequest
//
MPayment payment = new MPayment(Env.getCtx(), 0, transactionName);
payment.setC_BankAccount_ID(pointOfSalesDefinition.getC_BankAccount_ID());
payment.setC_DocType_ID(!request.getIsRefund());
// Get from POS
int documentTypeId;
if(!request.getIsRefund()) {
documentTypeId = pointOfSalesDefinition.get_ValueAsInt("POSCollectingDocumentType_ID");
} else {
documentTypeId = pointOfSalesDefinition.get_ValueAsInt("POSRefundDocumentType_ID");
}
if(documentTypeId > 0) {
payment.setC_DocType_ID(documentTypeId);
} else {
payment.setC_DocType_ID(!request.getIsRefund());
}
payment.setAD_Org_ID(salesOrder.getAD_Org_ID());
String value = DB.getDocumentNo(payment.getC_DocType_ID(), transactionName, false, payment);
payment.setDocumentNo(value);
Expand Down Expand Up @@ -4313,18 +4324,16 @@ private MPayment createPaymentFromCharge(int defaultChargeId, CreatePaymentReque
}
payment = new MPayment(Env.getCtx(), 0, transactionName);
payment.setC_BankAccount_ID(pointOfSalesDefinition.getC_BankAccount_ID());
int documentTypeId;
if(!request.getIsRefund()) {
if(cashAccount.get_ValueAsInt("DepositDocumentType_ID") > 0) {
payment.setC_DocType_ID(cashAccount.get_ValueAsInt("DepositDocumentType_ID"));
} else {
payment.setC_DocType_ID(true);
}
documentTypeId = pointOfSalesDefinition.get_ValueAsInt("POSOpeningDocumentType_ID");
} else {
if(cashAccount.get_ValueAsInt("WithdrawalDocumentType_ID") > 0) {
payment.setC_DocType_ID(cashAccount.get_ValueAsInt("WithdrawalDocumentType_ID"));
} else {
payment.setC_DocType_ID(false);
}
documentTypeId = pointOfSalesDefinition.get_ValueAsInt("POSWithdrawalDocumentType_ID");
}
if(documentTypeId > 0) {
payment.setC_DocType_ID(documentTypeId);
} else {
payment.setC_DocType_ID(!request.getIsRefund());
}
payment.setAD_Org_ID(pointOfSalesDefinition.getAD_Org_ID());
String value = DB.getDocumentNo(payment.getC_DocType_ID(), transactionName, false, payment);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2283,14 +2283,25 @@ private Stock.Builder getStockFromSku(GetStockRequest request) {
Optional<MStorage> maybeStorage = Arrays.asList(MStorage.getOfProduct(Env.getCtx(), product.getM_Product_ID(), null))
.stream()
.filter(storage -> storage.getQtyOnHand().signum() > 0)
.findFirst();
.reduce(StockSummary::add);
if(maybeStorage.isPresent()) {
builder = convertStock(maybeStorage.get());
}
//
return builder;
}

/**
* Summarize stock
*/
private static final class StockSummary {
public static MStorage add(MStorage previousValue, MStorage newValue) {
previousValue.setQtyOnHand(previousValue.getQtyOnHand().add(newValue.getQtyOnHand()));
previousValue.setQtyOnHand(previousValue.getQtyReserved().add(newValue.getQtyReserved()));
return previousValue;
}
}

/**
* List Products
* @param request
Expand Down

0 comments on commit d2212cd

Please sign in to comment.