You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ha...@apache.org on 2011/08/30 06:11:16 UTC

svn commit: r1163083 - in /ofbiz/trunk/applications: accounting/config/ accounting/script/org/ofbiz/accounting/invoice/ accounting/servicedef/ accounting/src/org/ofbiz/accounting/invoice/ order/entitydef/ order/servicedef/ order/src/org/ofbiz/order/ord...

Author: hansbak
Date: Tue Aug 30 04:11:16 2011
New Revision: 1163083

URL: http://svn.apache.org/viewvc?rev=1163083&view=rev
Log:
added a new accounting configuration option to generate invoice per order or per shipment. can be overridden at the order level

Modified:
    ofbiz/trunk/applications/accounting/config/AccountingConfig.properties
    ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/invoice/InvoiceServices.xml
    ofbiz/trunk/applications/accounting/servicedef/services_invoice.xml
    ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceServices.java
    ofbiz/trunk/applications/order/entitydef/entitymodel.xml
    ofbiz/trunk/applications/order/servicedef/secas.xml
    ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java
    ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/controller.xml
    ofbiz/trunk/applications/order/webapp/ordermgr/order/orderinfo.ftl

Modified: ofbiz/trunk/applications/accounting/config/AccountingConfig.properties
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/config/AccountingConfig.properties?rev=1163083&r1=1163082&r2=1163083&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/config/AccountingConfig.properties (original)
+++ ofbiz/trunk/applications/accounting/config/AccountingConfig.properties Tue Aug 30 04:11:16 2011
@@ -37,3 +37,5 @@ accounting.payment.application.autocreat
 # create a 'not-paid' payment record if the purchase order is approved
 accounting.payment.purchaseorder.autocreate=Y
 
+# create invoice per shipment = Y Invoice per order = N
+create.invoice.per.shipment=Y

Modified: ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/invoice/InvoiceServices.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/invoice/InvoiceServices.xml?rev=1163083&r1=1163082&r2=1163083&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/invoice/InvoiceServices.xml (original)
+++ ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/invoice/InvoiceServices.xml Tue Aug 30 04:11:16 2011
@@ -883,4 +883,46 @@ under the License.
             </else>
         </if>
     </simple-method>
+
+    <simple-method method-name="createInvoiceFromOrder" short-description="Create an invoice from existing order when invoicePerShipment is N">
+        <entity-one value-field="orderHeader" entity-name="OrderHeader">
+            <field-map field-name="orderId" from-field="parameters.orderId"/>
+        </entity-one>
+        <set field="invoicePerShipment" from-field="orderHeader.invoicePerShipment"/>
+        <if-empty field="invoicePerShipment">
+            <property-to-field resource="AccountingConfig" property="create.invoice.per.shipment" field="invoicePerShipment"/>
+        </if-empty>
+        <if-compare operator="equals" value="N" field="invoicePerShipment">
+            <entity-and list="orderItemBilling" entity-name="OrderItemBilling">
+                <field-map field-name="orderId" from-field="parameters.orderId"/>
+            </entity-and>
+            <if-empty field="orderItemBilling">
+                <set field="createInvoiceContext.orderId" from-field="parameters.orderId"/>
+                <call-service service-name="createInvoiceForOrderAllItems" in-map-name="createInvoiceContext">
+                    <result-to-field result-name="invoiceId" field="invoiceId"/>
+                </call-service>
+            <else>
+                <entity-and list="orderItems" entity-name="OrderItem">
+                    <field-map field-name="orderId" from-field="parameters.orderId"/>
+                    <order-by field-name="orderItemSeqId"/>
+                </entity-and>
+                <iterate entry="orderItem" list="orderItems">
+                    <entity-and list="checkOrderItem" entity-name="OrderItemBilling">
+                        <field-map field-name="orderId" from-field="parameters.orderId"/>
+                        <field-map field-name="orderItemSeqId" from-field="orderItem.orderItemSeqId"/>
+                    </entity-and>
+                    <if-empty field="checkOrderItem">
+                        <field-to-list list="billItems" field="orderItem"/>
+                    </if-empty>
+                    <set field="createInvoiceContext.orderId" from-field="parameters.orderId"/>
+                    <set field="createInvoiceContext.billItems" from-field="billItems"/>
+                </iterate>
+                <call-service service-name="createInvoiceForOrder" in-map-name="createInvoiceContext">
+                    <result-to-field result-name="invoiceId" field="invoiceId"/>
+                </call-service>
+            </else>
+            </if-empty>
+            <field-to-result field="invoiceId" result-name="invoiceId"/>
+        </if-compare>
+    </simple-method>
 </simple-methods>

Modified: ofbiz/trunk/applications/accounting/servicedef/services_invoice.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/servicedef/services_invoice.xml?rev=1163083&r1=1163082&r2=1163083&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/servicedef/services_invoice.xml (original)
+++ ofbiz/trunk/applications/accounting/servicedef/services_invoice.xml Tue Aug 30 04:11:16 2011
@@ -371,4 +371,11 @@ under the License.
         <attribute name="errorMessage" type="String" optional="true" mode="OUT"/>
     </service>
     
+    <service name="createInvoiceFromOrder" engine="simple"
+        location="component://accounting/script/org/ofbiz/accounting/invoice/InvoiceServices.xml" invoke="createInvoiceFromOrder">
+        <description>Create an invoice from existing order when invoicePerShipment is N</description>
+        <attribute name="orderId" type="String" mode="IN" optional="false"/>
+        <attribute name="invoiceId" type="String" mode="OUT" optional="true"/>
+    </service>
+    
 </services>

Modified: ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceServices.java?rev=1163083&r1=1163082&r2=1163083&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceServices.java (original)
+++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceServices.java Tue Aug 30 04:11:16 2011
@@ -1063,23 +1063,47 @@ public class InvoiceServices {
 
     public static Map<String, Object> createInvoicesFromShipment(DispatchContext dctx, Map<String, Object> context) {
         //Delegator delegator = dctx.getDelegator();
+        Delegator delegator = dctx.getDelegator();
         LocalDispatcher dispatcher = dctx.getDispatcher();
         String shipmentId = (String) context.get("shipmentId");
         Locale locale = (Locale) context.get("locale");
         List<String> invoicesCreated = FastList.newInstance();
+        Map<String, Object> response = ServiceUtil.returnSuccess();
+        List<GenericValue> orderShipments = FastList.newInstance();
+        String invoicePerShipment = null;
 
-        Map<String, Object> serviceContext = UtilMisc.toMap("shipmentIds", UtilMisc.toList(shipmentId), "eventDate", context.get("eventDate"), "userLogin", context.get("userLogin"));
         try {
-            Map<String, Object> result = dispatcher.runSync("createInvoicesFromShipments", serviceContext);
-            invoicesCreated = UtilGenerics.checkList(result.get("invoicesCreated"));
-        } catch (GenericServiceException e) {
-            Debug.logError(e, "Trouble calling createInvoicesFromShipment service; invoice not created for shipment [" + shipmentId + "]", module);
-            return ServiceUtil.returnError(UtilProperties.getMessage(resource,
-                    "AccountingTroubleCallingCreateInvoicesFromShipmentService",
-                    UtilMisc.toMap("shipmentId", shipmentId), locale));
+            orderShipments = delegator.findByAnd("OrderShipment", UtilMisc.toMap("shipmentId", shipmentId));
+        } catch (GenericEntityException e) {
+            return ServiceUtil.returnError(e.getMessage());
+        }
+
+        GenericValue orderShipment = EntityUtil.getFirst(orderShipments);
+        if (orderShipment != null) {
+            String orderId = orderShipment.getString("orderId");
+            try {
+                GenericValue orderHeader = delegator.findByPrimaryKey("OrderHeader", UtilMisc.toMap("orderId", orderId));
+                invoicePerShipment = orderHeader.getString("invoicePerShipment");
+            } catch (GenericEntityException e) {
+                return ServiceUtil.returnError(e.getMessage());
+            }
+        } else {
+            invoicePerShipment = UtilProperties.getPropertyValue("AccountingConfig","create.invoice.per.shipment");
+        }
+
+        if ("Y".equals(invoicePerShipment)) {
+            Map<String, Object> serviceContext = UtilMisc.toMap("shipmentIds", UtilMisc.toList(shipmentId), "eventDate", context.get("eventDate"), "userLogin", context.get("userLogin"));
+            try {
+                Map<String, Object> result = dispatcher.runSync("createInvoicesFromShipments", serviceContext);
+                invoicesCreated = UtilGenerics.checkList(result.get("invoicesCreated"));
+            } catch (GenericServiceException e) {
+                Debug.logError(e, "Trouble calling createInvoicesFromShipment service; invoice not created for shipment [" + shipmentId + "]", module);
+                return ServiceUtil.returnError(UtilProperties.getMessage(resource,
+                        "AccountingTroubleCallingCreateInvoicesFromShipmentService",
+                        UtilMisc.toMap("shipmentId", shipmentId), locale));
+            }
+            response.put("invoicesCreated", invoicesCreated);
         }
-        Map<String, Object> response = ServiceUtil.returnSuccess();
-        response.put("invoicesCreated", invoicesCreated);
         return response;
     }
 

Modified: ofbiz/trunk/applications/order/entitydef/entitymodel.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/entitydef/entitymodel.xml?rev=1163083&r1=1163082&r2=1163083&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/entitydef/entitymodel.xml (original)
+++ ofbiz/trunk/applications/order/entitydef/entitymodel.xml Tue Aug 30 04:11:16 2011
@@ -391,6 +391,7 @@ under the License.
       <field name="remainingSubTotal" type="currency-amount"></field>
       <field name="grandTotal" type="currency-amount"></field>
       <field name="isViewed" type="indicator"></field>
+      <field name="invoicePerShipment" type="indicator"></field>
       <prim-key field="orderId"/>
       <relation type="one" fk-name="ORDER_HDR_TYPE" rel-entity-name="OrderType">
         <key-map field-name="orderTypeId"/>

Modified: ofbiz/trunk/applications/order/servicedef/secas.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/servicedef/secas.xml?rev=1163083&r1=1163082&r2=1163083&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/servicedef/secas.xml (original)
+++ ofbiz/trunk/applications/order/servicedef/secas.xml Tue Aug 30 04:11:16 2011
@@ -90,6 +90,7 @@ under the License.
     <eca service="changeOrderStatus" event="global-commit" run-on-error="false">
         <condition field-name="statusId" operator="equals" value="ORDER_COMPLETED"/>
         <condition-field field-name="statusId" operator="not-equals" to-field-name="oldStatusId"/>
+        <action service="createInvoiceFromOrder" mode="sync"/>
         <action service="resetGrandTotal" mode="sync"/>
         <action service="sendOrderCompleteNotification" mode="async" persist="true"/>
     </eca>

Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java?rev=1163083&r1=1163082&r2=1163083&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java (original)
+++ ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java Tue Aug 30 04:11:16 2011
@@ -558,6 +558,11 @@ public class OrderServices {
             orderHeader.set("createdBy", userLogin.getString("userLoginId"));
         }
 
+        String invoicePerShipment = UtilProperties.getPropertyValue("AccountingConfig","create.invoice.per.shipment");
+        if (UtilValidate.isNotEmpty(invoicePerShipment)) {
+            orderHeader.set("invoicePerShipment", invoicePerShipment);
+        }
+
         // first try to create the OrderHeader; if this does not fail, continue.
         try {
             delegator.create(orderHeader);

Modified: ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/controller.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/controller.xml?rev=1163083&r1=1163082&r2=1163083&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/controller.xml (original)
+++ ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/controller.xml Tue Aug 30 04:11:16 2011
@@ -1763,6 +1763,13 @@ under the License.
         <response name="error" type="request" value="json"/>
     </request-map>
 
+    <request-map uri="setInvoicePerShipment">
+        <security https="true" auth="true"/>
+        <event type="service" invoke="updateOrderHeader"/>
+        <response name="success" type="view" value="orderview"/>
+        <response name="error" type="view" value="orderview"/>
+    </request-map>
+
     <request-map uri="addShippingAddress">
         <security https="true" auth="true"/>
         <event type="service" invoke="createUpdateShippingAddress"/>

Modified: ofbiz/trunk/applications/order/webapp/ordermgr/order/orderinfo.ftl
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/webapp/ordermgr/order/orderinfo.ftl?rev=1163083&r1=1163082&r2=1163083&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/webapp/ordermgr/order/orderinfo.ftl (original)
+++ ofbiz/trunk/applications/order/webapp/ordermgr/order/orderinfo.ftl Tue Aug 30 04:11:16 2011
@@ -252,8 +252,23 @@ under the License.
                     </form>
                   </td>
                 </tr>
-            <tr><td colspan="3"><hr /></td></tr>
             </#if>
+            <tr><td colspan="3"><hr /></td></tr>
+            <tr>
+              <td align="right" valign="top" width="15%" class="label">&nbsp;Invoice Per Shipment</td>
+              <td width="5%">&nbsp;</td>
+              <td valign="top" width="80%">
+                 <form name="setInvoicePerShipment" method="post" action="<@o...@ofbizUrl>">
+                 <input type = "hidden" name="orderId" value="${orderId}"/>
+                <select name="invoicePerShipment">
+                  <option value="Y" <#if (orderHeader.invoicePerShipment)?if_exists == "Y">selected="selected" </#if>>Y</option>
+                  <option value="N" <#if (orderHeader.invoicePerShipment)?if_exists == "N">selected="selected" </#if>>N</option>
+                </select>
+                <input type="submit" class="smallSubmit" value="${uiLabelMap.CommonUpdate}"/>
+                </form>
+              </td>
+            </tr>
+            <tr><td colspan="3"><hr /></td></tr>
             <#if orderHeader.isViewed?has_content && orderHeader.isViewed == "Y">
             <tr>
               <td class="label">${uiLabelMap.OrderViewed}</td>



Re: svn commit: r1163083 - in /ofbiz/trunk/applications: accounting/config/ accounting/script/org/ofbiz/accounting/invoice/ accounting/servicedef/ accounting/src/org/ofbiz/accounting/invoice/ order/entitydef/ order/servicedef/ order/src/org/ofbiz/order/ord...

Posted by "J. Eckard" <ec...@redrocketcorp.com>.
A bit late on this, but I think there is a problem with this change.

Any orders that were created before applying this change will have the OrderHeader field "invoicePerShipment" set to NULL, and will not generate any invoices when its shipments are packed or when it is completed after applying the change.

If Y should be the default value for invoicePerShipment, createInvoicesFromShipment needs to be updated.


On Aug 30, 2011, at 12:11 AM, hansbak@apache.org wrote:

> Author: hansbak
> Date: Tue Aug 30 04:11:16 2011
> New Revision: 1163083
> 
> URL: http://svn.apache.org/viewvc?rev=1163083&view=rev
> Log:
> added a new accounting configuration option to generate invoice per order or per shipment. can be overridden at the order level
> 
> Modified:
>    ofbiz/trunk/applications/accounting/config/AccountingConfig.properties
>    ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/invoice/InvoiceServices.xml
>    ofbiz/trunk/applications/accounting/servicedef/services_invoice.xml
>    ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceServices.java
>    ofbiz/trunk/applications/order/entitydef/entitymodel.xml
>    ofbiz/trunk/applications/order/servicedef/secas.xml
>    ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java
>    ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/controller.xml
>    ofbiz/trunk/applications/order/webapp/ordermgr/order/orderinfo.ftl
> 
> Modified: ofbiz/trunk/applications/accounting/config/AccountingConfig.properties
> URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/config/AccountingConfig.properties?rev=1163083&r1=1163082&r2=1163083&view=diff
> ==============================================================================
> --- ofbiz/trunk/applications/accounting/config/AccountingConfig.properties (original)
> +++ ofbiz/trunk/applications/accounting/config/AccountingConfig.properties Tue Aug 30 04:11:16 2011
> @@ -37,3 +37,5 @@ accounting.payment.application.autocreat
> # create a 'not-paid' payment record if the purchase order is approved
> accounting.payment.purchaseorder.autocreate=Y
> 
> +# create invoice per shipment = Y Invoice per order = N
> +create.invoice.per.shipment=Y
> 
> Modified: ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/invoice/InvoiceServices.xml
> URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/invoice/InvoiceServices.xml?rev=1163083&r1=1163082&r2=1163083&view=diff
> ==============================================================================
> --- ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/invoice/InvoiceServices.xml (original)
> +++ ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/invoice/InvoiceServices.xml Tue Aug 30 04:11:16 2011
> @@ -883,4 +883,46 @@ under the License.
>             </else>
>         </if>
>     </simple-method>
> +
> +    <simple-method method-name="createInvoiceFromOrder" short-description="Create an invoice from existing order when invoicePerShipment is N">
> +        <entity-one value-field="orderHeader" entity-name="OrderHeader">
> +            <field-map field-name="orderId" from-field="parameters.orderId"/>
> +        </entity-one>
> +        <set field="invoicePerShipment" from-field="orderHeader.invoicePerShipment"/>
> +        <if-empty field="invoicePerShipment">
> +            <property-to-field resource="AccountingConfig" property="create.invoice.per.shipment" field="invoicePerShipment"/>
> +        </if-empty>
> +        <if-compare operator="equals" value="N" field="invoicePerShipment">
> +            <entity-and list="orderItemBilling" entity-name="OrderItemBilling">
> +                <field-map field-name="orderId" from-field="parameters.orderId"/>
> +            </entity-and>
> +            <if-empty field="orderItemBilling">
> +                <set field="createInvoiceContext.orderId" from-field="parameters.orderId"/>
> +                <call-service service-name="createInvoiceForOrderAllItems" in-map-name="createInvoiceContext">
> +                    <result-to-field result-name="invoiceId" field="invoiceId"/>
> +                </call-service>
> +            <else>
> +                <entity-and list="orderItems" entity-name="OrderItem">
> +                    <field-map field-name="orderId" from-field="parameters.orderId"/>
> +                    <order-by field-name="orderItemSeqId"/>
> +                </entity-and>
> +                <iterate entry="orderItem" list="orderItems">
> +                    <entity-and list="checkOrderItem" entity-name="OrderItemBilling">
> +                        <field-map field-name="orderId" from-field="parameters.orderId"/>
> +                        <field-map field-name="orderItemSeqId" from-field="orderItem.orderItemSeqId"/>
> +                    </entity-and>
> +                    <if-empty field="checkOrderItem">
> +                        <field-to-list list="billItems" field="orderItem"/>
> +                    </if-empty>
> +                    <set field="createInvoiceContext.orderId" from-field="parameters.orderId"/>
> +                    <set field="createInvoiceContext.billItems" from-field="billItems"/>
> +                </iterate>
> +                <call-service service-name="createInvoiceForOrder" in-map-name="createInvoiceContext">
> +                    <result-to-field result-name="invoiceId" field="invoiceId"/>
> +                </call-service>
> +            </else>
> +            </if-empty>
> +            <field-to-result field="invoiceId" result-name="invoiceId"/>
> +        </if-compare>
> +    </simple-method>
> </simple-methods>
> 
> Modified: ofbiz/trunk/applications/accounting/servicedef/services_invoice.xml
> URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/servicedef/services_invoice.xml?rev=1163083&r1=1163082&r2=1163083&view=diff
> ==============================================================================
> --- ofbiz/trunk/applications/accounting/servicedef/services_invoice.xml (original)
> +++ ofbiz/trunk/applications/accounting/servicedef/services_invoice.xml Tue Aug 30 04:11:16 2011
> @@ -371,4 +371,11 @@ under the License.
>         <attribute name="errorMessage" type="String" optional="true" mode="OUT"/>
>     </service>
> 
> +    <service name="createInvoiceFromOrder" engine="simple"
> +        location="component://accounting/script/org/ofbiz/accounting/invoice/InvoiceServices.xml" invoke="createInvoiceFromOrder">
> +        <description>Create an invoice from existing order when invoicePerShipment is N</description>
> +        <attribute name="orderId" type="String" mode="IN" optional="false"/>
> +        <attribute name="invoiceId" type="String" mode="OUT" optional="true"/>
> +    </service>
> +    
> </services>
> 
> Modified: ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceServices.java
> URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceServices.java?rev=1163083&r1=1163082&r2=1163083&view=diff
> ==============================================================================
> --- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceServices.java (original)
> +++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceServices.java Tue Aug 30 04:11:16 2011
> @@ -1063,23 +1063,47 @@ public class InvoiceServices {
> 
>     public static Map<String, Object> createInvoicesFromShipment(DispatchContext dctx, Map<String, Object> context) {
>         //Delegator delegator = dctx.getDelegator();
> +        Delegator delegator = dctx.getDelegator();
>         LocalDispatcher dispatcher = dctx.getDispatcher();
>         String shipmentId = (String) context.get("shipmentId");
>         Locale locale = (Locale) context.get("locale");
>         List<String> invoicesCreated = FastList.newInstance();
> +        Map<String, Object> response = ServiceUtil.returnSuccess();
> +        List<GenericValue> orderShipments = FastList.newInstance();
> +        String invoicePerShipment = null;
> 
> -        Map<String, Object> serviceContext = UtilMisc.toMap("shipmentIds", UtilMisc.toList(shipmentId), "eventDate", context.get("eventDate"), "userLogin", context.get("userLogin"));
>         try {
> -            Map<String, Object> result = dispatcher.runSync("createInvoicesFromShipments", serviceContext);
> -            invoicesCreated = UtilGenerics.checkList(result.get("invoicesCreated"));
> -        } catch (GenericServiceException e) {
> -            Debug.logError(e, "Trouble calling createInvoicesFromShipment service; invoice not created for shipment [" + shipmentId + "]", module);
> -            return ServiceUtil.returnError(UtilProperties.getMessage(resource,
> -                    "AccountingTroubleCallingCreateInvoicesFromShipmentService",
> -                    UtilMisc.toMap("shipmentId", shipmentId), locale));
> +            orderShipments = delegator.findByAnd("OrderShipment", UtilMisc.toMap("shipmentId", shipmentId));
> +        } catch (GenericEntityException e) {
> +            return ServiceUtil.returnError(e.getMessage());
> +        }
> +
> +        GenericValue orderShipment = EntityUtil.getFirst(orderShipments);
> +        if (orderShipment != null) {
> +            String orderId = orderShipment.getString("orderId");
> +            try {
> +                GenericValue orderHeader = delegator.findByPrimaryKey("OrderHeader", UtilMisc.toMap("orderId", orderId));
> +                invoicePerShipment = orderHeader.getString("invoicePerShipment");
> +            } catch (GenericEntityException e) {
> +                return ServiceUtil.returnError(e.getMessage());
> +            }
> +        } else {
> +            invoicePerShipment = UtilProperties.getPropertyValue("AccountingConfig","create.invoice.per.shipment");
> +        }
> +
> +        if ("Y".equals(invoicePerShipment)) {
> +            Map<String, Object> serviceContext = UtilMisc.toMap("shipmentIds", UtilMisc.toList(shipmentId), "eventDate", context.get("eventDate"), "userLogin", context.get("userLogin"));
> +            try {
> +                Map<String, Object> result = dispatcher.runSync("createInvoicesFromShipments", serviceContext);
> +                invoicesCreated = UtilGenerics.checkList(result.get("invoicesCreated"));
> +            } catch (GenericServiceException e) {
> +                Debug.logError(e, "Trouble calling createInvoicesFromShipment service; invoice not created for shipment [" + shipmentId + "]", module);
> +                return ServiceUtil.returnError(UtilProperties.getMessage(resource,
> +                        "AccountingTroubleCallingCreateInvoicesFromShipmentService",
> +                        UtilMisc.toMap("shipmentId", shipmentId), locale));
> +            }
> +            response.put("invoicesCreated", invoicesCreated);
>         }
> -        Map<String, Object> response = ServiceUtil.returnSuccess();
> -        response.put("invoicesCreated", invoicesCreated);
>         return response;
>     }
> 
> 
> Modified: ofbiz/trunk/applications/order/entitydef/entitymodel.xml
> URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/entitydef/entitymodel.xml?rev=1163083&r1=1163082&r2=1163083&view=diff
> ==============================================================================
> --- ofbiz/trunk/applications/order/entitydef/entitymodel.xml (original)
> +++ ofbiz/trunk/applications/order/entitydef/entitymodel.xml Tue Aug 30 04:11:16 2011
> @@ -391,6 +391,7 @@ under the License.
>       <field name="remainingSubTotal" type="currency-amount"></field>
>       <field name="grandTotal" type="currency-amount"></field>
>       <field name="isViewed" type="indicator"></field>
> +      <field name="invoicePerShipment" type="indicator"></field>
>       <prim-key field="orderId"/>
>       <relation type="one" fk-name="ORDER_HDR_TYPE" rel-entity-name="OrderType">
>         <key-map field-name="orderTypeId"/>
> 
> Modified: ofbiz/trunk/applications/order/servicedef/secas.xml
> URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/servicedef/secas.xml?rev=1163083&r1=1163082&r2=1163083&view=diff
> ==============================================================================
> --- ofbiz/trunk/applications/order/servicedef/secas.xml (original)
> +++ ofbiz/trunk/applications/order/servicedef/secas.xml Tue Aug 30 04:11:16 2011
> @@ -90,6 +90,7 @@ under the License.
>     <eca service="changeOrderStatus" event="global-commit" run-on-error="false">
>         <condition field-name="statusId" operator="equals" value="ORDER_COMPLETED"/>
>         <condition-field field-name="statusId" operator="not-equals" to-field-name="oldStatusId"/>
> +        <action service="createInvoiceFromOrder" mode="sync"/>
>         <action service="resetGrandTotal" mode="sync"/>
>         <action service="sendOrderCompleteNotification" mode="async" persist="true"/>
>     </eca>
> 
> Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java
> URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java?rev=1163083&r1=1163082&r2=1163083&view=diff
> ==============================================================================
> --- ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java (original)
> +++ ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java Tue Aug 30 04:11:16 2011
> @@ -558,6 +558,11 @@ public class OrderServices {
>             orderHeader.set("createdBy", userLogin.getString("userLoginId"));
>         }
> 
> +        String invoicePerShipment = UtilProperties.getPropertyValue("AccountingConfig","create.invoice.per.shipment");
> +        if (UtilValidate.isNotEmpty(invoicePerShipment)) {
> +            orderHeader.set("invoicePerShipment", invoicePerShipment);
> +        }
> +
>         // first try to create the OrderHeader; if this does not fail, continue.
>         try {
>             delegator.create(orderHeader);
> 
> Modified: ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/controller.xml
> URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/controller.xml?rev=1163083&r1=1163082&r2=1163083&view=diff
> ==============================================================================
> --- ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/controller.xml (original)
> +++ ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/controller.xml Tue Aug 30 04:11:16 2011
> @@ -1763,6 +1763,13 @@ under the License.
>         <response name="error" type="request" value="json"/>
>     </request-map>
> 
> +    <request-map uri="setInvoicePerShipment">
> +        <security https="true" auth="true"/>
> +        <event type="service" invoke="updateOrderHeader"/>
> +        <response name="success" type="view" value="orderview"/>
> +        <response name="error" type="view" value="orderview"/>
> +    </request-map>
> +
>     <request-map uri="addShippingAddress">
>         <security https="true" auth="true"/>
>         <event type="service" invoke="createUpdateShippingAddress"/>
> 
> Modified: ofbiz/trunk/applications/order/webapp/ordermgr/order/orderinfo.ftl
> URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/webapp/ordermgr/order/orderinfo.ftl?rev=1163083&r1=1163082&r2=1163083&view=diff
> ==============================================================================
> --- ofbiz/trunk/applications/order/webapp/ordermgr/order/orderinfo.ftl (original)
> +++ ofbiz/trunk/applications/order/webapp/ordermgr/order/orderinfo.ftl Tue Aug 30 04:11:16 2011
> @@ -252,8 +252,23 @@ under the License.
>                     </form>
>                   </td>
>                 </tr>
> -            <tr><td colspan="3"><hr /></td></tr>
>             </#if>
> +            <tr><td colspan="3"><hr /></td></tr>
> +            <tr>
> +              <td align="right" valign="top" width="15%" class="label">&nbsp;Invoice Per Shipment</td>
> +              <td width="5%">&nbsp;</td>
> +              <td valign="top" width="80%">
> +                 <form name="setInvoicePerShipment" method="post" action="<@o...@ofbizUrl>">
> +                 <input type = "hidden" name="orderId" value="${orderId}"/>
> +                <select name="invoicePerShipment">
> +                  <option value="Y" <#if (orderHeader.invoicePerShipment)?if_exists == "Y">selected="selected" </#if>>Y</option>
> +                  <option value="N" <#if (orderHeader.invoicePerShipment)?if_exists == "N">selected="selected" </#if>>N</option>
> +                </select>
> +                <input type="submit" class="smallSubmit" value="${uiLabelMap.CommonUpdate}"/>
> +                </form>
> +              </td>
> +            </tr>
> +            <tr><td colspan="3"><hr /></td></tr>
>             <#if orderHeader.isViewed?has_content && orderHeader.isViewed == "Y">
>             <tr>
>               <td class="label">${uiLabelMap.OrderViewed}</td>
> 
>