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



##########
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:
       Hi Priya,
   
   Yes, If a variable is never used we can remove it safely.




----------------------------------------------------------------
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


Reply via email to