Hi Vikas,

I agree completely with you that in the case of the purchase order only,
the second commit is not required and is a duplication of the code you
were referring to.

The second commit however twas meant to be more general, We often use
the payment and invoice without the order and would like at least that
the application is created automatically of the amounts that match what
happens in most cases. Therefore also the seca for payment received.

Regards,
Hans

On Fri, 2010-05-14 at 23:25 +0530, Vikas Mayur wrote:
> Hi Hans,
> 
> Let me elaborate a little more if that wasn't helpful.
> 
> I see two commits in succession from you related to purchase orders.
> 
> 1. Create Payment when a purchase order is approved.
> 
> 2. Apply payment when an invoice is approved or payment is sent/ 
> received. (though only payment sent is applicable in case of purchase  
> invoice so the eca on payment received is not required)
> 
> I know both process are configurable at this stage but still I would  
> like to understand the objective of this commit.
> 
> My understanding is that once you receive the shipment, it will create  
> the invoice through service createInvoiceFromShipment which
> 
> will eventually call createInvoiceForOrder.
> 
> In my last reply I posted the specific code snippet which apply the  
> payments to the invoice in a better way then it is done here.
> 
> If you are following the same way to generate the purchase invoice  
> then I think the code in this commit is redundant because the payment  
> application
> 
> is already handle in the service createInvoiceForOrder and the payment  
> will be already applied to the invoice in process status and changing  
> the status
> 
> of the invoice or payment later on will not have any effect.
> 
> Moreover I agree with Scott because this implementation takes a  
> guessing path to determine the invoice to be used for payment  
> application.
> 
> Looking forward to see your reply!
> 
> Regards
> Vikas
> 
> 
> 
> On May 13, 2010, at 11:38 PM, Vikas Mayur wrote:
> 
> > Hi Hans,
> >
> > Isn't the following code at line 732 in  
> > InvoiceServices.createInvoiceForOrder is doing the same thing?
> >
> > [snip]
> >
> >            // check for previous order payments
> >            List<GenericValue> orderPaymentPrefs =  
> > delegator.findByAnd("OrderPaymentPreference",  
> > UtilMisc.toMap("orderId", orderId));
> >            List<GenericValue> currentPayments =  
> > FastList.newInstance();
> >            for (GenericValue paymentPref : orderPaymentPrefs) {
> >                List<GenericValue> payments =  
> > paymentPref.getRelated("Payment");
> >                currentPayments.addAll(payments);
> >            }
> >            // apply these payments to the invoice if they have any  
> > remaining amount to apply
> >            for (GenericValue payment : currentPayments) {
> >                BigDecimal notApplied =  
> > PaymentWorker.getPaymentNotApplied(payment);
> >                if (notApplied.signum() > 0) {
> >                    Map<String, Object> appl = FastMap.newInstance();
> >                    appl.put("paymentId", payment.get("paymentId"));
> >                    appl.put("invoiceId", invoiceId);
> >                    appl.put("billingAccountId", billingAccountId);
> >                    appl.put("amountApplied", notApplied);
> >                    appl.put("userLogin", userLogin);
> >                    Map<String, Object> createPayApplResult =  
> > dispatcher.runSync("createPaymentApplication", appl);
> >                    if (ServiceUtil.isError(createPayApplResult)) {
> >                        return  
> > ServiceUtil 
> > .returnError 
> > (UtilProperties 
> > .getMessage 
> > (resource,"AccountingErrorCreatingInvoiceFromOrder",locale), null,  
> > null, createPayApplResult);
> >                    }
> >                }
> >
> > Regards
> > Vikas
> >
> > On May 12, 2010, at 2:50 PM, hans...@apache.org wrote:
> >
> >> Author: hansbak
> >> Date: Wed May 12 09:20:44 2010
> >> New Revision: 943417
> >>
> >> URL: http://svn.apache.org/viewvc?rev=943417&view=rev
> >> Log:
> >> if an invoice is approved or a payment is set to sent or received  
> >> this service will try to find a matching payment/invoice and when  
> >> found create the payment application
> >>
> >> Modified:
> >>   ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/ 
> >> payment/PaymentServices.xml
> >>   ofbiz/trunk/applications/accounting/servicedef/secas_invoice.xml
> >>   ofbiz/trunk/applications/accounting/servicedef/secas_payment.xml
> >>   ofbiz/trunk/applications/accounting/servicedef/services_payment.xml
> >>
> >> Modified: ofbiz/trunk/applications/accounting/script/org/ofbiz/ 
> >> accounting/payment/PaymentServices.xml
> >> URL: 
> >> http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/payment/PaymentServices.xml?rev=943417&r1=943416&r2=943417&view=diff
> >> = 
> >> = 
> >> = 
> >> = 
> >> = 
> >> = 
> >> = 
> >> = 
> >> = 
> >> =====================================================================
> >> --- ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/ 
> >> payment/PaymentServices.xml (original)
> >> +++ ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/ 
> >> payment/PaymentServices.xml Wed May 12 09:20:44 2010
> >> @@ -814,4 +814,79 @@ under the License.
> >>        <call-service service-name="updatePayment" in-map- 
> >> name="updatePayment"/>
> >>        <field-to-result field="parameters.paymentId" result- 
> >> name="paymentId"/>
> >>    </simple-method>
> >> -</simple-methods>
> >> \ No newline at end of file
> >> +
> >> +    <simple-method method-name="createMatchingPaymentApplication"  
> >> short-description="Create a payment application if either the  
> >> invoice of payment could be found">
> >> +        <if-not-empty field="parameters.invoiceId">
> >> +            <entity-one value-field="invoice" entity- 
> >> name="Invoice"/>
> >> +            <if-not-empty field="invoice">
> >> +                <call-class-method method-name="getInvoiceTotal"  
> >> class-name="org.ofbiz.accounting.invoice.InvoiceWorker" ret- 
> >> field="invoiceTotal">
> >> +                    <field field="invoice" type="GenericValue"/>
> >> +                </call-class-method>
> >> +                <entity-condition list="payments" entity- 
> >> name="Payment">
> >> +                    <condition-list combine="and">
> >> +                        <condition-expr field-name="statusId"  
> >> value="PMNT_CONFIRMED" operator="not-equals"/>
> >> +                        <condition-expr field-name="partyIdFrom"  
> >> from-field="invoice.partyId" operator="equals"/>
> >> +                        <condition-expr field-name="partyIdTo"  
> >> from-field="invoice.partyIdFrom" operator="equals"/>
> >> +                        <condition-expr field-name="amount" from- 
> >> field="invoiceTotal" operator="equals"/>
> >> +                    </condition-list>
> >> +                    <order-by field-name="effectiveDate"/>
> >> +                </entity-condition>
> >> +                <if-not-empty field="payments">
> >> +                    <!-- check if already applied -->
> >> +                    <entity-and list="paymentAppls" entity- 
> >> name="PaymentApplication">
> >> +                        <field-map field-name="paymentId" from- 
> >> field="payments[0].paymentId"/>
> >> +                    </entity-and>
> >> +                    <if-empty field="paymentAppls">
> >> +                        <set field="createAppl.paymentId" from- 
> >> field="payments[0].paymentId"/>
> >> +                        <set field="createAppl.invoiceId" from- 
> >> field="parameters.invoiceId"/>
> >> +                        <set field="createAppl.amountApplied" from- 
> >> field="invoiceTotal"/>
> >> +                    </if-empty>
> >> +                </if-not-empty>
> >> +            </if-not-empty>
> >> +        </if-not-empty>
> >> +
> >> +        <if-not-empty field="parameters.paymentId">
> >> +            <entity-one value-field="payment" entity- 
> >> name="Payment"/>
> >> +            <if-not-empty field="payment">
> >> +                <entity-condition list="invoices" entity- 
> >> name="Invoice">
> >> +                    <condition-list combine="and">
> >> +                        <condition-expr field-name="statusId"  
> >> value="INVOICE_READY" operator="not-equals"/>
> >> +                        <condition-expr field-name="statusId"  
> >> value="INVOICE_PAID" operator="not-equals"/>
> >> +                        <condition-expr field-name="statusId"  
> >> value="INVOICE_CANCELLED" operator="not-equals"/>
> >> +                        <condition-expr field-name="statusId"  
> >> value="INVOICE_WRITEOFF" operator="not-equals"/>
> >> +                        <condition-expr field-name="partyIdFrom"  
> >> from-field="payment.partyIdTo"/>
> >> +                        <condition-expr field-name="partyId" from- 
> >> field="payment.partyIdFrom"/>
> >> +                    </condition-list>
> >> +                    <order-by field-name="invoiceDate"/>
> >> +                </entity-condition>
> >> +                <iterate entry="invoice" list="invoices">
> >> +                    <call-class-method method- 
> >> name="getInvoiceTotal" class- 
> >> name="org.ofbiz.accounting.invoice.InvoiceWorker" ret- 
> >> field="invoiceTotal">
> >> +                        <field field="invoice" type="GenericValue"/>
> >> +                    </call-class-method>
> >> +                    <if-compare-field operator="equals"  
> >> field="invoiceTotal" to-field="payment.amount">
> >> +                        <set field="invoiceId" from- 
> >> field="invoice.invoiceId"/>
> >> +                    </if-compare-field>
> >> +                </iterate>
> >> +                <if-not-empty field="invoiceId">
> >> +                    <entity-and list="paymentAppls" entity- 
> >> name="PaymentApplication">
> >> +                        <field-map field-name="invoiceId" from- 
> >> field="invoiceId"/>
> >> +                    </entity-and>
> >> +                    <if-empty field="paymentAppls">
> >> +                        <set field="createAppl.paymentId" from- 
> >> field="parameters.paymentId"/>
> >> +                        <set field="createAppl.invoiceId" from- 
> >> field="invoiceId"/>
> >> +                        <set field="createAppl.amountApplied" from- 
> >> field="payment.amount"/>
> >> +                    </if-empty>
> >> +                </if-not-empty>
> >> +            </if-not-empty>
> >> +        </if-not-empty>
> >> +
> >> +
> >> +        <if-not-empty field="createAppl.paymentId">
> >> +            <if-not-empty field="createAppl.invoiceId">
> >> +                <call-service service- 
> >> name="createPaymentApplication" in-map-name="createAppl"/>
> >> +                <set field="successMessage" value="also  
> >> application created"/>
> >> +            </if-not-empty>
> >> +        </if-not-empty>
> >> +    </simple-method>
> >> +
> >> +</simple-methods>
> >>
> >> Modified: ofbiz/trunk/applications/accounting/servicedef/ 
> >> secas_invoice.xml
> >> URL: 
> >> http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/servicedef/secas_invoice.xml?rev=943417&r1=943416&r2=943417&view=diff
> >> = 
> >> = 
> >> = 
> >> = 
> >> = 
> >> = 
> >> = 
> >> = 
> >> = 
> >> =====================================================================
> >> --- ofbiz/trunk/applications/accounting/servicedef/ 
> >> secas_invoice.xml (original)
> >> +++ ofbiz/trunk/applications/accounting/servicedef/ 
> >> secas_invoice.xml Wed May 12 09:20:44 2010
> >> @@ -31,4 +31,11 @@ under the License.
> >>        <condition field-name="invoiceTypeId" operator="equals"  
> >> value="COMMISSION_INVOICE"/>
> >>        <action service="removeInvoiceItemAssocOnCancelInvoice"  
> >> mode="sync"/>
> >>    </eca>
> >> +
> >> +    <eca service="setInvoiceStatus" event="commit">
> >> +        <condition operator="equals" field-name="statusId"  
> >> value="INVOICE_APPROVED"/>
> >> +        <condition operator="not-equals" field-name="oldStatusId"  
> >> value="INVOICE_APPROVED"/>
> >> +        <action service="createMatchingPaymentApplication"  
> >> mode="sync"/>
> >> +    </eca>
> >> +
> >> </service-eca>
> >>
> >> Modified: ofbiz/trunk/applications/accounting/servicedef/ 
> >> secas_payment.xml
> >> URL: 
> >> http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/servicedef/secas_payment.xml?rev=943417&r1=943416&r2=943417&view=diff
> >> = 
> >> = 
> >> = 
> >> = 
> >> = 
> >> = 
> >> = 
> >> = 
> >> = 
> >> =====================================================================
> >> --- ofbiz/trunk/applications/accounting/servicedef/ 
> >> secas_payment.xml (original)
> >> +++ ofbiz/trunk/applications/accounting/servicedef/ 
> >> secas_payment.xml Wed May 12 09:20:44 2010
> >> @@ -67,4 +67,17 @@ under the License.
> >>         <condition field-name="statusId" operator="equals"  
> >> value="FINACT_TRNS_CANCELED"/>
> >>         <action service="setFinAccountTransStatus" mode="sync"/>
> >>     </eca>
> >> +
> >> +    <eca service="setPaymentStatus" event="commit">
> >> +        <condition operator="equals" field-name="statusId"  
> >> value="PMNT_RECEIVED"/>
> >> +        <condition operator="not-equals" field-name="oldStatusId"  
> >> value="PMNT_RECEIVED"/>
> >> +        <action service="createMatchingPaymentApplication"  
> >> mode="sync"/>
> >> +    </eca>
> >> +
> >> +    <eca service="setPaymentStatus" event="commit">
> >> +        <condition operator="equals" field-name="statusId"  
> >> value="PMNT_SENT"/>
> >> +        <condition operator="not-equals" field-name="oldStatusId"  
> >> value="PMNT_SENT"/>
> >> +        <action service="createMatchingPaymentApplication"  
> >> mode="sync"/>
> >> +    </eca>
> >> +
> >> </service-eca>
> >>
> >> Modified: ofbiz/trunk/applications/accounting/servicedef/ 
> >> services_payment.xml
> >> URL: 
> >> http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/servicedef/services_payment.xml?rev=943417&r1=943416&r2=943417&view=diff
> >> = 
> >> = 
> >> = 
> >> = 
> >> = 
> >> = 
> >> = 
> >> = 
> >> = 
> >> =====================================================================
> >> --- ofbiz/trunk/applications/accounting/servicedef/ 
> >> services_payment.xml (original)
> >> +++ ofbiz/trunk/applications/accounting/servicedef/ 
> >> services_payment.xml Wed May 12 09:20:44 2010
> >> @@ -240,4 +240,11 @@ under the License.
> >>        <attribute name="orderId" type="String" mode="IN"  
> >> optional="false"/>
> >>        <attribute name="paymentId" type="String" mode="OUT"  
> >> optional="false"/>
> >>    </service>
> >> +
> >> +    <service name="createMatchingPaymentApplication" engine="simple"
> >> +        location="component://accounting/script/org/ofbiz/ 
> >> accounting/payment/PaymentServices.xml"  
> >> invoke="createMatchingPaymentApplication" auth="true">
> >> +        <description>Create a payment application if either the  
> >> invoice of payment could be found</description>
> >> +        <attribute name="paymentId" type="String" mode="IN"  
> >> optional="true"/>
> >> +        <attribute name="invoiceId" type="String" mode="IN"  
> >> optional="true"/>
> >> +    </service>
> >> </services>
> >>
> >>
> >
> 

-- 
Ofbiz on twitter: http://twitter.com/apache_ofbiz
Myself on twitter: http://twitter.com/hansbak
Antwebsystems.com: Quality services for competitive rates.

Reply via email to