Skip to content

Commit

Permalink
fix: Form Payment Allocation document type. (#953)
Browse files Browse the repository at this point in the history
  • Loading branch information
EdwinBetanc0urt authored Dec 20, 2024
1 parent 4ba6cdd commit 45e93a6
Show file tree
Hide file tree
Showing 3 changed files with 198 additions and 68 deletions.
Binary file modified resources/adempiere-grpc-server.pb
Binary file not shown.
146 changes: 121 additions & 25 deletions src/main/java/org/spin/grpc/service/form/PaymentAllocation.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.adempiere.core.domains.models.I_AD_Ref_List;
import org.adempiere.core.domains.models.I_C_Charge;
import org.adempiere.core.domains.models.I_C_Currency;
import org.adempiere.core.domains.models.I_C_DocType;
import org.adempiere.core.domains.models.I_C_Invoice;
import org.adempiere.core.domains.models.I_C_Payment;
import org.adempiere.core.domains.models.X_T_InvoiceGL;
Expand All @@ -41,6 +42,7 @@
import org.compiere.model.MBPartner;
import org.compiere.model.MCharge;
import org.compiere.model.MCurrency;
import org.compiere.model.MDocType;
import org.compiere.model.MLookupInfo;
import org.compiere.model.MOrg;
import org.compiere.model.MPayment;
Expand All @@ -58,6 +60,7 @@
import org.spin.backend.grpc.common.ListLookupItemsResponse;
import org.spin.backend.grpc.form.payment_allocation.Charge;
import org.spin.backend.grpc.form.payment_allocation.Currency;
import org.spin.backend.grpc.form.payment_allocation.DocumentType;
import org.spin.backend.grpc.form.payment_allocation.Invoice;
import org.spin.backend.grpc.form.payment_allocation.InvoiceSelection;
import org.spin.backend.grpc.form.payment_allocation.ListBusinessPartnersRequest;
Expand Down Expand Up @@ -216,14 +219,21 @@ public static Organization.Builder convertOrganization(MOrg organization) {
return builder;
}

builder.setId(organization.getAD_Org_ID())
builder.setId(
organization.getAD_Org_ID()
)
.setUuid(
StringManager.getValidString(
organization.getUUID()
)
)
.setValue(
ValueManager.validateNull(
StringManager.getValidString(
organization.getName()
)
)
.setName(
ValueManager.validateNull(
StringManager.getValidString(
organization.getName()
)
)
Expand Down Expand Up @@ -323,14 +333,21 @@ public static Currency.Builder convertCurrency(MCurrency currency) {
return builder;
}

builder.setId(currency.getC_Currency_ID())
builder.setId(
currency.getC_Currency_ID()
)
.setUuid(
StringManager.getValidString(
currency.getUUID()
)
)
.setIsoCode(
ValueManager.validateNull(
StringManager.getValidString(
currency.getISO_Code()
)
)
.setDescription(
ValueManager.validateNull(
StringManager.getValidString(
currency.getDescription()
)
)
Expand Down Expand Up @@ -429,24 +446,72 @@ public static TransactionType.Builder convertTransactionType(MRefList transactio
description = transactionType.get_Translation(I_AD_Ref_List.COLUMNNAME_Description);
}

builder.setId(transactionType.getAD_Ref_List_ID())
builder.setId(
transactionType.getAD_Ref_List_ID()
)
.setUuid(
StringManager.getValidString(
transactionType.getUUID()
)
)
.setValue(
ValueManager.validateNull(
StringManager.getValidString(
transactionType.getValue()
)
)
.setName(
ValueManager.validateNull(name)
StringManager.getValidString(name)
)
.setDescription(
ValueManager.validateNull(description)
StringManager.getValidString(description)
)
;

return builder;
}


public static DocumentType.Builder convertDocumentType(int documentTypeId) {
if (documentTypeId < 0) {
return DocumentType.newBuilder();
}
MDocType documentType = MDocType.get(Env.getCtx(), documentTypeId);
return convertDocumentType(documentType);
}
public static DocumentType.Builder convertDocumentType(MDocType documentType) {
DocumentType.Builder builder = DocumentType.newBuilder();
if (documentType == null || documentType.getC_DocType_ID() < 0) {
return builder;
}

builder.setId(
documentType.getC_DocType_ID()
)
.setUuid(
StringManager.getValidString(
documentType.getUUID()
)
)
.setName(
StringManager.getValidString(
documentType.get_Translation(I_C_DocType.COLUMNNAME_Name)
)
)
.setPrintName(
StringManager.getValidString(
documentType.get_Translation(I_C_DocType.COLUMNNAME_PrintName)
)
)
.setDescription(
StringManager.getValidString(
documentType.get_Translation(I_C_DocType.COLUMNNAME_Description)
)
)
;

return builder;
}


@Override
public void listPayments(ListPaymentsRequest request, StreamObserver<ListPaymentsResponse> responseObserver) {
Expand Down Expand Up @@ -482,6 +547,7 @@ private ListPaymentsResponse.Builder listPayments(ListPaymentsRequest request) {
* 5-ConvAmt, 6-ConvOpen, 7-Allocated
*/
StringBuffer sql = new StringBuffer("SELECT p.DateTrx, p.DocumentNo, p.C_Payment_ID," // 1..3
+ "p.UUID, p.C_DocTypeTarget_ID, "
+ "c.ISO_Code, p.PayAmt," // 4..5
+ "currencyConvert(p.PayAmt, p.C_Currency_ID, ?, ?, p.C_ConversionType_ID, p.AD_Client_ID, p.AD_Org_ID) AS ConvertedAmt,"// #1, #2
+ "currencyConvert(paymentAvailable(C_Payment_ID), p.C_Currency_ID, ?, ?, p.C_ConversionType_ID, p.AD_Client_ID, p.AD_Org_ID) AS AvailableAmt," // 7 #3, #4
Expand Down Expand Up @@ -537,6 +603,9 @@ private ListPaymentsResponse.Builder listPayments(ListPaymentsRequest request) {
while (rs.next()) {
recordCount++;

DocumentType.Builder documentTypeBuilder = convertDocumentType(
rs.getInt(I_C_Invoice.COLUMNNAME_C_DocTypeTarget_ID)
);
Organization.Builder organizationBuilder = convertOrganization(
rs.getInt(I_AD_Org.COLUMNNAME_AD_Org_ID)
);
Expand All @@ -555,19 +624,27 @@ private ListPaymentsResponse.Builder listPayments(ListPaymentsRequest request) {
int paymentId = rs.getInt(I_C_Payment.COLUMNNAME_C_Payment_ID);
Payment.Builder paymentBuilder = Payment.newBuilder()
.setId(paymentId)
.setTransactionDate(
ValueManager.getTimestampFromDate(
rs.getTimestamp(I_C_Payment.COLUMNNAME_DateTrx)
.setUuid(
StringManager.getValidString(
rs.getString(I_C_Payment.COLUMNNAME_UUID)
)
)
.setIsReceipt(isReceipt)
.setDocumentNo(
ValueManager.validateNull(
StringManager.getValidString(
rs.getString(I_C_Payment.COLUMNNAME_DocumentNo)
)
)
.setDocumentType(
documentTypeBuilder
)
.setTransactionDate(
ValueManager.getTimestampFromDate(
rs.getTimestamp(I_C_Payment.COLUMNNAME_DateTrx)
)
)
.setIsReceipt(isReceipt)
.setDescription(
ValueManager.validateNull(
StringManager.getValidString(
rs.getString(I_C_Payment.COLUMNNAME_Description)
)
)
Expand Down Expand Up @@ -648,6 +725,7 @@ private ListInvoicesResponse.Builder listInvoices(ListInvoicesRequest request) {
*/
StringBuffer sql = new StringBuffer(
"SELECT i.DateInvoiced, i.DocumentNo, i.Description, i.C_Invoice_ID, " // 1..3
+ "p.UUID, p.C_DocTypeTarget_ID, "
+ "c.ISO_Code, (i.GrandTotal * i.MultiplierAP) AS OriginalAmt, " // 4..5 Orig Currency
+ "currencyConvert(i.GrandTotal * i.MultiplierAP, i.C_Currency_ID, ?, ?, i.C_ConversionType_ID, i.AD_Client_ID, i.AD_Org_ID) AS ConvertedAmt, " // 6 #1 Converted, #2 Date
+ "(currencyConvert(invoiceOpen(C_Invoice_ID,C_InvoicePaySchedule_ID), i.C_Currency_ID, ?, ?, i.C_ConversionType_ID, i.AD_Client_ID, i.AD_Org_ID) * i.MultiplierAP) AS OpenAmt, " // 7 #3, #4 Converted Open
Expand Down Expand Up @@ -705,6 +783,9 @@ private ListInvoicesResponse.Builder listInvoices(ListInvoicesRequest request) {
while (rs.next()) {
recordCount++;

DocumentType.Builder targetDocumentTypeBuilder = convertDocumentType(
rs.getInt(I_C_Invoice.COLUMNNAME_C_DocTypeTarget_ID)
);
Organization.Builder organizationBuilder = convertOrganization(
rs.getInt(I_AD_Org.COLUMNNAME_AD_Org_ID)
);
Expand All @@ -723,19 +804,27 @@ private ListInvoicesResponse.Builder listInvoices(ListInvoicesRequest request) {
int invoiceId = rs.getInt(I_C_Invoice.COLUMNNAME_C_Invoice_ID);
Invoice.Builder invoiceBuilder = Invoice.newBuilder()
.setId(invoiceId)
.setDateInvoiced(
ValueManager.getTimestampFromDate(
rs.getTimestamp(I_C_Invoice.COLUMNNAME_DateInvoiced)
.setUuid(
StringManager.getValidString(
rs.getString(I_C_Invoice.COLUMNNAME_UUID)
)
)
.setIsSalesTransaction(isSalesTransaction)
.setDocumentNo(
ValueManager.validateNull(
StringManager.getValidString(
rs.getString(I_C_Invoice.COLUMNNAME_DocumentNo)
)
)
.setTargetDocumentType(
targetDocumentTypeBuilder
)
.setDateInvoiced(
ValueManager.getTimestampFromDate(
rs.getTimestamp(I_C_Invoice.COLUMNNAME_DateInvoiced)
)
)
.setIsSalesTransaction(isSalesTransaction)
.setDescription(
ValueManager.validateNull(
StringManager.getValidString(
rs.getString(I_C_Invoice.COLUMNNAME_Description)
)
)
Expand Down Expand Up @@ -832,14 +921,21 @@ public static Charge.Builder convertCharge(MCharge charge) {
return builder;
}

builder.setId(charge.getC_Charge_ID())
builder.setId(
charge.getC_Charge_ID()
)
.setUuid(
StringManager.getValidString(
charge.getUUID()
)
)
.setName(
ValueManager.validateNull(
StringManager.getValidString(
charge.getName()
)
)
.setDescription(
ValueManager.validateNull(
StringManager.getValidString(
charge.getDescription()
)
)
Expand Down
Loading

0 comments on commit 45e93a6

Please sign in to comment.