[GitHub] [ofbiz-framework] priyasharma1 commented on a change in pull request #158: [Improved] Convert createPaymentApplication service from mini-lang to groovy DSL (OFBIZ-11481)

2020-07-16 Thread GitBox


priyasharma1 commented on a change in pull request #158:
URL: https://github.com/apache/ofbiz-framework/pull/158#discussion_r455750319



##
File path: applications/accounting/groovyScripts/payment/PaymentServices.groovy
##
@@ -134,3 +136,77 @@ def updatePaymentContent() {
 }
 }
 
+def createPaymentApplication() {
+// Create a Payment Application
+if (!parameters.invoiceId && !parameters.billingAccountId && 
!parameters.taxAuthGeoId && !parameters.toPaymentId) {
+return error(UtilProperties.getResourceBundleMap("AccountingUiLabels", 
locale)?.AccountingPaymentApplicationParameterMissing)
+}
+GenericValue paymentAppl = delegator.makeValue("PaymentApplication")
+paymentAppl.setNonPKFields(parameters)
+
+GenericValue payment = from("Payment").where("paymentId", 
parameters.paymentId).queryOne()
+if (!payment) {
+return error(UtilProperties.getResourceBundleMap("AccountingUiLabels", 
locale)?.AccountingPaymentApplicationParameterMissing)
+}
+
+BigDecimal notAppliedPayment = PaymentWorker.getPaymentNotApplied(payment)
+
+if (parameters.invoiceId) {
+// get the invoice and do some further validation against it
+GenericValue invoice = from("Invoice").where("invoiceId", 
parameters.invoiceId).queryOne()
+// check the currencies if they are compatible
+if (invoice.currencyUomId != payment.currencyUomId && 
invoice.currencyUomId != payment.actualCurrencyUomId) {
+return 
error(UtilProperties.getResourceBundleMap("AccountingUiLabels", 
locale)?.AccountingCurrenciesOfInvoiceAndPaymentNotCompatible)
+}
+if (invoice.currencyUomId != payment.currencyUomId && 
invoice.currencyUomId == payment.actualCurrencyUomId) {
+// if required get the payment amount in foreign currency (local 
we already have)
+Boolean actual = true
+notAppliedPayment = PaymentWorker.getPaymentNotApplied(payment, 
actual)
+}
+// get the amount that has not been applied yet for the invoice 
(outstanding amount)
+BigDecimal notAppliedInvoice = 
InvoiceWorker.getInvoiceNotApplied(invoice)
+if (notAppliedInvoice <= notAppliedPayment) {
+paymentAppl.amountApplied = notAppliedInvoice
+} else {
+paymentAppl.amountApplied = notAppliedPayment
+}
+
+if (invoice.billingAccountId) {
+paymentAppl.billingAccountId = invoice.billingAccountId
+}
+}
+
+if (parameters.toPaymentId) {
+// get the to payment and check the parent types are compatible
+GenericValue toPayment = from("Payment").where("paymentId", 
parameters.toPaymentId).queryOne()
+if (toPayment) {
+toPaymentType = from("PaymentType").where("paymentTypeId", 
toPayment.paymentTypeId).queryOne()

Review comment:
   Thanks, Pawan for the verification. I have removed both those lines.
   Though I have tested it please let me know if this causes any issue.





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [ofbiz-framework] priyasharma1 commented on a change in pull request #158: [Improved] Convert createPaymentApplication service from mini-lang to groovy DSL (OFBIZ-11481)

2020-07-14 Thread GitBox


priyasharma1 commented on a change in pull request #158:
URL: https://github.com/apache/ofbiz-framework/pull/158#discussion_r454121486



##
File path: applications/accounting/groovyScripts/payment/PaymentServices.groovy
##
@@ -134,3 +136,77 @@ def updatePaymentContent() {
 }
 }
 
+def createPaymentApplication() {
+// Create a Payment Application
+if (!parameters.invoiceId && !parameters.billingAccountId && 
!parameters.taxAuthGeoId && !parameters.toPaymentId) {
+return error(UtilProperties.getResourceBundleMap("AccountingUiLabels", 
locale)?.AccountingPaymentApplicationParameterMissing)
+}
+GenericValue paymentAppl = delegator.makeValue("PaymentApplication")
+paymentAppl.setNonPKFields(parameters)
+
+GenericValue payment = from("Payment").where("paymentId", 
parameters.paymentId).queryOne()
+if (!payment) {
+return error(UtilProperties.getResourceBundleMap("AccountingUiLabels", 
locale)?.AccountingPaymentApplicationParameterMissing)
+}
+
+BigDecimal notAppliedPayment = PaymentWorker.getPaymentNotApplied(payment)
+
+if (parameters.invoiceId) {
+// get the invoice and do some further validation against it
+GenericValue invoice = from("Invoice").where("invoiceId", 
parameters.invoiceId).queryOne()
+// check the currencies if they are compatible
+if (invoice.currencyUomId != payment.currencyUomId && 
invoice.currencyUomId != payment.actualCurrencyUomId) {
+return 
error(UtilProperties.getResourceBundleMap("AccountingUiLabels", 
locale)?.AccountingCurrenciesOfInvoiceAndPaymentNotCompatible)
+}
+if (invoice.currencyUomId != payment.currencyUomId && 
invoice.currencyUomId == payment.actualCurrencyUomId) {
+// if required get the payment amount in foreign currency (local 
we already have)
+Boolean actual = true
+notAppliedPayment = PaymentWorker.getPaymentNotApplied(payment, 
actual)
+}
+// get the amount that has not been applied yet for the invoice 
(outstanding amount)
+BigDecimal notAppliedInvoice = 
InvoiceWorker.getInvoiceNotApplied(invoice)
+if (notAppliedInvoice <= notAppliedPayment) {
+paymentAppl.amountApplied = notAppliedInvoice
+} else {
+paymentAppl.amountApplied = notAppliedPayment
+}
+
+if (invoice.billingAccountId) {
+paymentAppl.billingAccountId = invoice.billingAccountId
+}
+}
+
+if (parameters.toPaymentId) {
+// get the to payment and check the parent types are compatible
+GenericValue toPayment = from("Payment").where("paymentId", 
parameters.toPaymentId).queryOne()
+if (toPayment) {
+toPaymentType = from("PaymentType").where("paymentTypeId", 
toPayment.paymentTypeId).queryOne()

Review comment:
   Thanks, Deepak.
   As I was trying to make this improvement, I noticed that there two variables 
are never used i.e. paymentType and toPaymentType.
   Will it be fine to skip these two entity operations if they are not used?
   





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org