Fixes Issue 22751. Revert changes made when fixing Issue 19043
authorDavid Miguelez <david.miguelez@openbravo.com>
Wed, 09 Jan 2013 12:41:13 +0100
changeset 19206 0ce3b01ec4eb
parent 19205 84cc08e9ad90
child 19207 98f5002398d1
Fixes Issue 22751. Revert changes made when fixing Issue 19043
src-db/database/model/functions/M_INOUT_POST.xml
src-db/database/model/triggers/M_INOUTLINE_TRG.xml
src/org/openbravo/erpCommon/ad_actionButton/CreateFrom.java
src/org/openbravo/erpCommon/ad_actionButton/CreateFrom_Invoice_data.xsql
src/org/openbravo/erpCommon/ad_actionButton/CreateFrom_ShipmentPO.html
src/org/openbravo/erpCommon/ad_actionButton/CreateFrom_Shipment_data.xsql
src/org/openbravo/erpCommon/ad_forms/MaterialReceiptPending_data.xsql
--- a/src-db/database/model/functions/M_INOUT_POST.xml	Wed Jan 09 12:22:32 2013 +0100
+++ b/src-db/database/model/functions/M_INOUT_POST.xml	Wed Jan 09 12:41:13 2013 +0100
@@ -524,19 +524,13 @@
                   AND sl.M_Product_ID=ol.M_Product_ID  --    AND   sl.M_AttributeSetInstance_ID=ol.M_AttributeSetInstance_ID
                   AND sl.M_InOut_ID=Cur_InOut.M_InOut_ID
                 )
-              LOOP
-                
-                SELECT count(*) INTO v_count
-                FROM M_MATCHPO
-                WHERE C_ORDERLINE_ID = Cur_SLines.C_OrderLine_ID
-                      AND M_INOUTLINE_ID = Cur_SLines.M_InOutLine_ID;            
+              LOOP          
 
                 v_Qty:=Cur_SLines.MovementQty;
                 --IF (ABS(Cur_SLines.MovementQty) > ABS(Cur_SLines.QtyOrdered)) THEN
                 -- v_Qty := Cur_SLines.QtyOrdered;
                 --END IF;
 
-                IF (v_count = 0) THEN
                   Ad_Sequence_Next('M_MatchPO', Cur_SLines.AD_Org_ID, v_MatchPO_ID) ;
                   -- The min qty. Modified by Ismael Ciordia
                   v_ResultStr:='InsertMatchPO ' || v_MatchPO_ID;
@@ -556,18 +550,7 @@
                       v_Qty, 'N', 'Y', 'N'
                     )
                   ;
-                ELSE
-                  SELECT max(M_MATCHPO_ID)
-                  INTO v_MatchPO_ID
-                  FROM M_MATCHPO
-                  WHERE C_ORDERLINE_ID = Cur_SLines.C_OrderLine_ID
-                        AND M_INOUTLINE_ID = Cur_SLines.M_InOutLine_ID;
                   
-                  v_ResultStr:='UpdateMatchPO ' || v_MatchPO_ID;
-                  UPDATE M_MATCHPO
-                  SET DateTrx = now(), Qty =v_Qty, Processing = 'N', Processed = 'Y', Posted='N'
-                  WHERE M_MATCHPO_ID = v_MatchPO_ID;
-                END IF;
               END LOOP;
               v_ResultStr:='MatchInv';
               FOR Cur_ILines IN
--- a/src-db/database/model/triggers/M_INOUTLINE_TRG.xml	Wed Jan 09 12:22:32 2013 +0100
+++ b/src-db/database/model/triggers/M_INOUTLINE_TRG.xml	Wed Jan 09 12:41:13 2013 +0100
@@ -14,7 +14,6 @@
   v_qtyold   NUMBER;
   v_qtyorderold  NUMBER;
   v_MatchInvCount  NUMBER;
-  v_MatchPoCount NUMBER;
   v_STOCKED   NUMBER;
   v_UOM_ID    varchar2(32);
   v_AttrSetValueType M_Product.AttrSetValueType%TYPE;
@@ -35,7 +34,7 @@
  * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
  * created by ComPiere are Copyright (C) ComPiere, Inc.;   All Rights Reserved.
  * Contributor(s): Openbravo SLU
- * Contributions are Copyright (C) 2001-2010 Openbravo S.L.U.
+ * Contributions are Copyright (C) 2001-2013 Openbravo S.L.U.
  ******************************************************************************/
      
 BEGIN
@@ -133,18 +132,6 @@
          AND M_INOUTLINE_ID = :NEW.M_INOUTLINE_ID;
      END IF;
 
-     SELECT COUNT(*) INTO v_MatchPoCount
-     FROM M_MatchPo MO
-     WHERE MO.Qty = :OLD.MovementQty
-     AND MO.M_InOutLine_ID = :NEW.M_InOutLine_ID;
-
-     IF (:OLD.MovementQty <> :NEW.MovementQty AND v_MatchPoCount = 1) THEN
-      UPDATE M_MatchPo
-      SET Qty = :NEW.MovementQty
-      WHERE Qty = :OLD.MovementQty
-      AND M_InOutLine_ID = :NEW.M_InOutLine_ID;
-     END IF;
-
  END IF;
 
 
--- a/src/org/openbravo/erpCommon/ad_actionButton/CreateFrom.java	Wed Jan 09 12:22:32 2013 +0100
+++ b/src/org/openbravo/erpCommon/ad_actionButton/CreateFrom.java	Wed Jan 09 12:41:13 2013 +0100
@@ -487,7 +487,7 @@
           if (isSOTrx.equals("Y"))
             data = CreateFromInvoiceData.selectFromPOSOTrx(this, vars.getLanguage(),
                 Utility.getContext(this, vars, "#User_Client", strWindowId),
-                Utility.getContext(this, vars, "#User_Org", strWindowId), strPO, strKey);
+                Utility.getContext(this, vars, "#User_Org", strWindowId), strPO);
           else
             data = CreateFromInvoiceData.selectFromPO(this, vars.getLanguage(), strKey,
                 Utility.getContext(this, vars, "#User_Client", strWindowId),
@@ -496,7 +496,7 @@
           if (isSOTrx.equals("Y"))
             data = CreateFromInvoiceData.selectFromPOTrlSOTrx(this, vars.getLanguage(),
                 Utility.getContext(this, vars, "#User_Client", strWindowId),
-                Utility.getContext(this, vars, "#User_Org", strWindowId), strPO, strKey);
+                Utility.getContext(this, vars, "#User_Org", strWindowId), strPO);
           else
             data = CreateFromInvoiceData.selectFromPOTrl(this, vars.getLanguage(), strKey,
                 Utility.getContext(this, vars, "#User_Client", strWindowId),
@@ -508,23 +508,23 @@
             data = CreateFromInvoiceData.selectFromShipmentSOTrx(this, vars.getLanguage(),
                 Utility.getContext(this, vars, "#User_Client", strWindowId),
                 Utility.getContext(this, vars, "#User_Org", strWindowId), strShipment,
-                strIsTaxIncluded, strKey);
+                strIsTaxIncluded);
           else
             data = CreateFromInvoiceData.selectFromShipment(this, vars.getLanguage(),
                 Utility.getContext(this, vars, "#User_Client", strWindowId),
                 Utility.getContext(this, vars, "#User_Org", strWindowId), strShipment,
-                strIsTaxIncluded, strKey);
+                strIsTaxIncluded);
         } else {
           if (isSOTrx.equals("Y"))
             data = CreateFromInvoiceData.selectFromShipmentTrlSOTrx(this, vars.getLanguage(),
                 Utility.getContext(this, vars, "#User_Client", strWindowId),
                 Utility.getContext(this, vars, "#User_Org", strWindowId), strShipment,
-                strIsTaxIncluded, strKey);
+                strIsTaxIncluded);
           else
             data = CreateFromInvoiceData.selectFromShipmentTrl(this, vars.getLanguage(),
                 Utility.getContext(this, vars, "#User_Client", strWindowId),
                 Utility.getContext(this, vars, "#User_Org", strWindowId), strShipment,
-                strIsTaxIncluded, strKey);
+                strIsTaxIncluded);
         }
       }
     }
@@ -560,20 +560,20 @@
         xmlDocument.setData("reportShipmentReciept", "liststructure", CreateFromInvoiceData
             .selectFromShipmentSOTrxCombo(this, vars.getLanguage(),
                 Utility.getContext(this, vars, "#User_Client", strWindowId), narturalOrgTreeList,
-                strBPartner, strIsTaxIncluded, strKey));
+                strBPartner, strIsTaxIncluded));
         xmlDocument.setData("reportPurchaseOrder", "liststructure", CreateFromInvoiceData
             .selectFromPOSOTrxCombo(this, vars.getLanguage(),
                 Utility.getContext(this, vars, "#User_Client", strWindowId), narturalOrgTreeList,
-                strBPartner, strIsTaxIncluded, strKey));
+                strBPartner, strIsTaxIncluded));
       } else {
         xmlDocument.setData("reportShipmentReciept", "liststructure", CreateFromInvoiceData
             .selectFromShipmentCombo(this, vars.getLanguage(),
                 Utility.getContext(this, vars, "#User_Client", strWindowId), narturalOrgTreeList,
-                strBPartner, strIsTaxIncluded, strKey));
+                strBPartner, strIsTaxIncluded));
         xmlDocument.setData("reportPurchaseOrder", "liststructure", CreateFromInvoiceData
             .selectFromPOCombo(this, vars.getLanguage(),
                 Utility.getContext(this, vars, "#User_Client", strWindowId), narturalOrgTreeList,
-                strBPartner, strIsTaxIncluded, strKey));
+                strBPartner, strIsTaxIncluded));
       }
     }
     {
@@ -637,21 +637,21 @@
           if (isSOTrx.equals("Y")) {
             data = CreateFromShipmentData.selectFromPOSOTrx(this, vars.getLanguage(),
                 Utility.getContext(this, vars, "#User_Client", strWindowId),
-                Utility.getContext(this, vars, "#User_Org", strWindowId), strPO, strKey);
+                Utility.getContext(this, vars, "#User_Org", strWindowId), strPO);
           } else {
             data = CreateFromShipmentData.selectFromPO(this, vars.getLanguage(),
                 Utility.getContext(this, vars, "#User_Client", strWindowId),
-                Utility.getContext(this, vars, "#User_Org", strWindowId), strPO, strKey);
+                Utility.getContext(this, vars, "#User_Org", strWindowId), strPO);
           }
         } else {
           if (isSOTrx.equals("Y"))
             data = CreateFromShipmentData.selectFromPOTrlSOTrx(this, vars.getLanguage(),
                 Utility.getContext(this, vars, "#User_Client", strWindowId),
-                Utility.getContext(this, vars, "#User_Org", strWindowId), strPO, strKey);
+                Utility.getContext(this, vars, "#User_Org", strWindowId), strPO);
           else
             data = CreateFromShipmentData.selectFromPOTrl(this, vars.getLanguage(),
                 Utility.getContext(this, vars, "#User_Client", strWindowId),
-                Utility.getContext(this, vars, "#User_Org", strWindowId), strPO, strKey);
+                Utility.getContext(this, vars, "#User_Org", strWindowId), strPO);
         }
       } else {
         if (vars.getLanguage().equals("en_US")) {
@@ -711,7 +711,7 @@
         xmlDocument.setData("reportPurchaseOrder", "liststructure", CreateFromShipmentData
             .selectFromPOSOTrxCombo(this, vars.getLanguage(),
                 Utility.getContext(this, vars, "#User_Client", strWindowId), narturalOrgTreeList,
-                strBPartner, strKey));
+                strBPartner));
       } else {
         xmlDocument.setData("reportInvoice", "liststructure", CreateFromShipmentData
             .selectFromInvoiceCombo(this, vars.getLanguage(),
@@ -720,7 +720,7 @@
         xmlDocument.setData("reportPurchaseOrder", "liststructure", CreateFromShipmentData
             .selectFromPOCombo(this, vars.getLanguage(),
                 Utility.getContext(this, vars, "#User_Client", strWindowId), narturalOrgTreeList,
-                strBPartner, strKey));
+                strBPartner));
       }
     }
 
@@ -782,22 +782,22 @@
         // CreateFrom
         if (isSOTrx.equals("Y")) {
           strArray = Utility.arrayEntradaSimple("arrDatos", new CreateFromShipmentData[0]);
-          strArray2 = Utility.arrayEntradaSimple("arrDatos2", CreateFromShipmentData
-              .selectFromPOSOTrxCombo(this, vars.getLanguage(),
+          strArray2 = Utility.arrayEntradaSimple(
+              "arrDatos2",
+              CreateFromShipmentData.selectFromPOSOTrxCombo(this, vars.getLanguage(),
                   Utility.getContext(this, vars, "#User_Client", strWindowId),
-                  Utility.getContext(this, vars, "#AccessibleOrgTree", strWindowId), strBPartner,
-                  null));
+                  Utility.getContext(this, vars, "#AccessibleOrgTree", strWindowId), strBPartner));
         } else {
           strArray = Utility.arrayEntradaSimple(
               "arrDatos",
               CreateFromShipmentData.selectFromInvoiceCombo(this, vars.getLanguage(),
                   Utility.getContext(this, vars, "#User_Client", strWindowId),
                   Utility.getContext(this, vars, "#AccessibleOrgTree", strWindowId), strBPartner));
-          strArray2 = Utility.arrayEntradaSimple("arrDatos2", CreateFromShipmentData
-              .selectFromPOCombo(this, vars.getLanguage(),
+          strArray2 = Utility.arrayEntradaSimple(
+              "arrDatos2",
+              CreateFromShipmentData.selectFromPOCombo(this, vars.getLanguage(),
                   Utility.getContext(this, vars, "#User_Client", strWindowId),
-                  Utility.getContext(this, vars, "#AccessibleOrgTree", strWindowId), strBPartner,
-                  null));
+                  Utility.getContext(this, vars, "#AccessibleOrgTree", strWindowId), strBPartner));
         }
       } else { // Loading the Combos in the Invoice's CreateFrom
         Invoice invoice = OBDal.getInstance().get(Invoice.class, strKey);
@@ -808,23 +808,23 @@
               .selectFromShipmentSOTrxCombo(this, vars.getLanguage(),
                   Utility.getContext(this, vars, "#User_Client", strWindowId),
                   Utility.getContext(this, vars, "#AccessibleOrgTree", strWindowId), strBPartner,
-                  strIsTaxIncluded, strKey));
+                  strIsTaxIncluded));
           strArray2 = Utility.arrayEntradaSimple("arrDatos2", CreateFromInvoiceData
               .selectFromPOSOTrxCombo(this, vars.getLanguage(),
                   Utility.getContext(this, vars, "#User_Client", strWindowId),
                   Utility.getContext(this, vars, "#AccessibleOrgTree", strWindowId), strBPartner,
-                  strIsTaxIncluded, strKey));
+                  strIsTaxIncluded));
         } else {
           strArray = Utility.arrayEntradaSimple("arrDatos", CreateFromInvoiceData
               .selectFromShipmentCombo(this, vars.getLanguage(),
                   Utility.getContext(this, vars, "#User_Client", strWindowId),
                   Utility.getContext(this, vars, "#AccessibleOrgTree", strWindowId), strBPartner,
-                  strIsTaxIncluded, strKey));
+                  strIsTaxIncluded));
           strArray2 = Utility.arrayEntradaSimple("arrDatos2", CreateFromInvoiceData
               .selectFromPOCombo(this, vars.getLanguage(),
                   Utility.getContext(this, vars, "#User_Client", strWindowId),
                   Utility.getContext(this, vars, "#AccessibleOrgTree", strWindowId), strBPartner,
-                  strIsTaxIncluded, strKey));
+                  strIsTaxIncluded));
         }
       }
     }
@@ -1717,7 +1717,7 @@
               strLineId = data[i].cOrderlineId;
             }
 
-            final String strMovementqty = vars.getRequiredStringParameter("inpmovementqty"
+            final String strMovementqty = vars.getRequiredNumericParameter("inpmovementqty"
                 + strLineId);
             String strQuantityorder = "";
             String strProductUomId = "";
@@ -1861,14 +1861,13 @@
                   if (strInOutLineId.isEmpty())
                     CreateFromShipmentData.updateInvoice(conn, this, strSequence,
                         data[i].cInvoicelineId);
-                  CreateFromShipmentData.insertMatchInv(conn, this, vars.getUser(),
-                      data[i].cInvoicelineId, strSequence, data[i].cInvoiceId);
-                } else {
+                  else {
+                    CreateFromShipmentData.insertMatchInv(conn, this, vars.getUser(),
+                        data[i].cInvoicelineId, strSequence, data[i].cInvoiceId);
+                  }
+                } else
                   CreateFromShipmentData.updateInvoiceOrder(conn, this, strSequence,
                       data[i].cOrderlineId);
-                  CreateFromShipmentData.insertMatchPO(conn, this, vars.getUser(),
-                      data[i].cOrderlineId, strSequence, strPO);
-                }
               } catch (final ServletException ex) {
                 myMessage = Utility.translateError(this, vars, vars.getLanguage(), ex.getMessage());
                 releaseRollbackConnection(conn);
--- a/src/org/openbravo/erpCommon/ad_actionButton/CreateFrom_Invoice_data.xsql	Wed Jan 09 12:22:32 2013 +0100
+++ b/src/org/openbravo/erpCommon/ad_actionButton/CreateFrom_Invoice_data.xsql	Wed Jan 09 12:41:13 2013 +0100
@@ -12,7 +12,7 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2001-2012 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2013 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  Cheli Pineda__________________________.
  ************************************************************************
@@ -57,8 +57,7 @@
                                                  AND m.C_InvoiceLine_ID IS NOT NULL
                        WHERE CO.C_ORDERLINE_ID = l.c_orderline_id AND CI.C_INVOICE_ID=? 
                        GROUP BY CI.C_orderline_id , CO.QtyORDERED
-                       HAVING (SUM(COALESCE(CI.QtyINVOICED, 0))-(COALESCE(CO.QtyORDERED,0)-SUM(COALESCE(m.Qty,0)))) >= 0 )
-                       AND (NOT EXISTS (SELECT 1 FROM C_InvoiceLine WHERE C_Invoice_ID = ? AND C_OrderLine_ID = l.C_OrderLine_Id))   
+                       HAVING (SUM(COALESCE(CI.QtyINVOICED, 0))-(COALESCE(CO.QtyORDERED,0)-SUM(COALESCE(m.Qty,0)))) >= 0 )   
         GROUP BY o.C_ORDER_ID, o.DocumentNo, o.DateOrdered, o.GrandTotal, l.QtyOrdered,l.C_UOM_ID,
         uom.UOMSymbol,l.M_Product_ID,p.NAME,l.Line,l.C_OrderLine_ID, l.ad_org_id, l.taxbaseamt,l.CancelPriceAD,
         COALESCE(l.A_Asset_ID, o.A_Asset_ID), COALESCE(l.C_Project_ID, o.C_Project_ID), COALESCE(l.C_Costcenter_ID, o.C_Costcenter_ID),
@@ -75,7 +74,6 @@
     <Parameter name="adOrgClient" type="replace" optional="true" after="o.AD_Org_ID IN (" text="'1'"/>
     <Parameter name="poId"/>
     <Parameter name="piId"/>
-    <Parameter name="piId"/>
   </SqlMethod>
   <SqlMethod name="selectFromPOCombo" type="preparedStatement" return="multiple">
     <SqlMethodComment></SqlMethodComment>
@@ -93,7 +91,6 @@
                      FROM C_ORDERLINE l left join M_MATCHPO m on  l.C_OrderLine_ID=m.C_OrderLine_ID
                                                               and m.C_InvoiceLine_ID IS NOT NULL  
                     WHERE l.C_ORDER_ID = o.C_ORDER_ID  
-                    AND (NOT EXISTS (SELECT 1 FROM C_InvoiceLine WHERE C_Invoice_ID = ? AND C_OrderLine_Id = l.C_OrderLine_Id))
                     GROUP BY l.QtyOrdered,l.C_OrderLine_ID 
                     HAVING (l.QtyOrdered-SUM(COALESCE(m.Qty,0))) <> 0)
         ORDER BY NAME
@@ -104,7 +101,6 @@
     <Parameter name="adOrgClient" type="replace" optional="true" after="o.AD_Org_ID IN (" text="'1'"/>
     <Parameter name="cBpartnerId"/>
     <Parameter name="isTaxIncluded"/>
-    <Parameter name="cInvoiceId"/>
   </SqlMethod>
   <SqlMethod name="selectFromPOSOTrx" type="preparedStatement" return="multiple">
     <SqlMethodComment></SqlMethodComment>
@@ -124,11 +120,6 @@
         AND ic.AD_Org_ID IN ('1') 
         AND l.M_Product_ID=p.M_Product_ID 
         AND ic.C_Order_ID = ? 
-        AND NOT EXISTS (SELECT 1
-                  FROM C_ORDERLINE CO LEFT JOIN C_INVOICELINE CI ON CI.C_ORDERLINE_ID = CO.C_ORDERLINE_ID
-                     left join M_MATCHPO m on  CO.C_OrderLine_ID=m.C_OrderLine_ID
-                     AND m.C_InvoiceLine_ID IS NOT NULL
-                     WHERE CO.C_ORDERLINE_ID = l.c_orderline_id AND CI.C_INVOICE_ID = ?)
         GROUP BY o.C_ORDER_ID, o.DocumentNo, o.DateOrdered, o.GrandTotal, l.QtyOrdered,
         l.C_UOM_ID,uom.UOMSymbol,l.M_Product_ID,p.NAME,l.Line,l.C_OrderLine_ID, l.QTYINVOICED, l.ad_org_id, l.taxbaseamt,
         COALESCE(l.A_Asset_ID, o.A_Asset_ID), COALESCE(l.C_Project_ID, o.C_Project_ID), COALESCE(l.C_Costcenter_ID, o.C_Costcenter_ID),
@@ -142,7 +133,6 @@
     <Parameter name="adUserClient" type="replace" optional="true" after="ic.AD_Client_ID IN (" text="'1'"/>
     <Parameter name="adOrgClient" type="replace" optional="true" after="ic.AD_Org_ID IN (" text="'1'"/>
     <Parameter name="poId"/>
-    <Parameter name="cInvoiceId"/>
   </SqlMethod>
   <SqlMethod name="selectFromPOSOTrxCombo" type="preparedStatement" return="multiple">
     <SqlMethodComment></SqlMethodComment>
@@ -156,11 +146,6 @@
         AND ic.AD_Org_ID IN ('1') 
         AND ic.C_BPartner_ID = ?
         AND pl.istaxincluded = ? 
-        AND EXISTS (SELECT 1
-                    FROM C_ORDERLINE l left join M_MATCHPO m on  l.C_OrderLine_ID=m.C_OrderLine_ID
-                    and m.C_InvoiceLine_ID IS NOT NULL
-                    WHERE l.C_ORDER_ID = o.C_ORDER_ID
-                    AND (NOT EXISTS (SELECT 1 FROM C_InvoiceLine WHERE C_Invoice_ID = ? AND C_OrderLine_Id = l.C_OrderLine_Id)))
         AND o.C_Order_Id = ic.C_Order_Id
         AND ((ic.term = 'D' AND ic.qtydelivered <>0) OR (ic.term = 'I' AND exists (SELECT 1 FROM C_ORDERLINE ol WHERE ol.C_ORDER_ID = o.C_ORDER_ID group by ol.c_orderline_id having SUM(ol.QTYORDERED)-SUM(ol.QTYINVOICED)<>0)) OR (ic.term <> 'N' AND (ic.term IN ('O','S') AND (ic.qtyordered = ic.qtydelivered) )) )
         GROUP BY o.C_ORDER_ID, o.DocumentNo, o.DateOrdered, o.GrandTotal 
@@ -172,7 +157,6 @@
     <Parameter name="adOrgClient" type="replace" optional="true" after="ic.AD_Org_ID IN (" text="'1'"/>
     <Parameter name="cBpartnerId"/>
     <Parameter name="isTaxIncluded"/>
-    <Parameter name="cInvoiceId"/>
   </SqlMethod>
   <SqlMethod name="selectFromPOTrl" type="preparedStatement" return="multiple">
     <SqlMethodComment></SqlMethodComment>
@@ -207,7 +191,6 @@
                        WHERE CO.C_ORDERLINE_ID = l.c_orderline_id AND CI.C_INVOICE_ID=? 
                        GROUP BY CI.C_orderline_id , CO.QtyORDERED
                        HAVING (SUM(COALESCE(CI.QtyINVOICED, 0))-(COALESCE(CO.QtyORDERED,0)-SUM(COALESCE(m.Qty,0)))) >= 0 )  
-                       AND (NOT EXISTS (SELECT 1 FROM C_InvoiceLine WHERE C_Invoice_ID = ? AND C_OrderLine_Id = l.C_OrderLine_Id))
         GROUP BY o.C_ORDER_ID, o.DocumentNo, o.DateOrdered, o.GrandTotal, l.QtyOrdered,l.C_UOM_ID,
         uom.UOMSymbol, uomt.UOMSYMBOL,l.M_Product_ID,p.NAME,l.Line,l.C_OrderLine_ID,
         l.taxbaseamt, COALESCE(l.A_Asset_ID, o.A_Asset_ID), COALESCE(l.C_Project_ID, o.C_Project_ID), COALESCE(l.C_Costcenter_ID, o.C_Costcenter_ID),
@@ -225,7 +208,6 @@
     <Parameter name="adOrgClient" type="replace" optional="true" after="o.AD_Org_ID IN (" text="'1'"/>
     <Parameter name="poId"/>
     <Parameter name="piId"/>
-    <Parameter name="piId"/>
   </SqlMethod>
   <SqlMethod name="selectFromPOTrlSOTrx" type="preparedStatement" return="multiple">
     <SqlMethodComment></SqlMethodComment>
@@ -246,11 +228,6 @@
         AND ic.AD_Org_ID IN ('1') 
         AND l.M_Product_ID=p.M_Product_ID
         AND ic.C_Order_ID = ? 
-        AND NOT EXISTS (SELECT 1
-                        FROM C_ORDERLINE CO LEFT JOIN C_INVOICELINE CI ON CI.C_ORDERLINE_ID = CO.C_ORDERLINE_ID
-                        left join M_MATCHPO m on  CO.C_OrderLine_ID=m.C_OrderLine_ID
-                        AND m.C_InvoiceLine_ID IS NOT NULL
-                        WHERE CO.C_ORDERLINE_ID = l.c_orderline_id AND CI.C_INVOICE_ID = ?)
         GROUP BY o.C_ORDER_ID, o.DocumentNo, o.DateOrdered, o.GrandTotal, l.QtyOrdered,
         l.C_UOM_ID,uom.UOMSymbol, uomt.UOMSymbol,l.M_Product_ID,p.NAME,l.Line,l.C_OrderLine_ID, l.QTYINVOICED,
         l.taxbaseamt, COALESCE(l.A_Asset_ID, o.A_Asset_ID), COALESCE(l.C_Project_ID, o.C_Project_ID), COALESCE(l.C_Costcenter_ID, o.C_Costcenter_ID),
@@ -265,7 +242,6 @@
     <Parameter name="adOrgClient" type="replace" optional="true" after="ic.AD_Org_ID IN (" text="'1'"/>
     <Parameter name="adLanguage"/>
     <Parameter name="poId"/>
-    <Parameter name="cInvoiceId"/>
   </SqlMethod>
   
   <SqlMethod name="selectFromPOUpdate" type="preparedStatement" connection="true" return="multiple">
@@ -374,7 +350,6 @@
         AND l.M_Product_ID=p.M_Product_ID 
         AND l.M_InOut_ID=? 
         AND (l.c_orderline_id is null OR pl.istaxincluded = ?)
-        AND (NOT EXISTS (SELECT 1 FROM C_InvoiceLine WHERE C_Invoice_ID = ? AND M_InOutLine_Id = l.M_InOutLine_Id))
         GROUP BY s.M_InOut_ID, s.DocumentNo, s.MovementDate, l.MovementQty,l.C_UOM_ID,uom.UOMSymbol,
         l.M_Product_ID,ma.serno,p.NAME, l.M_InOutLine_ID,l.Line,l.C_OrderLine_ID,
         COALESCE(l.A_Asset_ID, s.A_Asset_ID), COALESCE(l.C_Project_ID, s.C_Project_ID), COALESCE(l.C_Costcenter_ID, s.C_Costcenter_ID),
@@ -390,7 +365,6 @@
     <Parameter name="adOrgClient" type="replace" optional="true" after="s.AD_Org_ID IN (" text="'1'"/>
     <Parameter name="mInoutId"/>
     <Parameter name="isTaxIncluded"/>
-    <Parameter name="cInvoiceId"/>
   </SqlMethod>
   <SqlMethod name="selectFromShipmentCombo" type="preparedStatement" return="multiple">
     <SqlMethodComment></SqlMethodComment>
@@ -412,7 +386,6 @@
                            left join m_pricelist pl on pl.m_pricelist_id = o.m_pricelist_id
                       WHERE l.M_INOUT_ID = s.M_INOUT_ID 
                         AND (l.c_orderline_id is null OR pl.istaxincluded = ?)
-                        AND (NOT EXISTS (SELECT 1 FROM C_InvoiceLine WHERE C_Invoice_ID = ? AND M_InOutLine_Id = l.M_InOutLine_Id))
                       GROUP BY l.MovementQty, l.M_InOutLine_ID 
                       HAVING  (l.MovementQty-SUM(COALESCE(mi.Qty,0))) <> 0)
         ORDER BY NAME
@@ -424,7 +397,6 @@
     <Parameter name="adOrgClient" type="replace" optional="true" after="s.AD_Org_ID IN (" text="'1'"/>
     <Parameter name="cBpartnerId"/>
     <Parameter name="isTaxIncluded"/>
-    <Parameter name="cInvoiceId"/>
   </SqlMethod>
   <SqlMethod name="selectFromShipmentSOTrx" type="preparedStatement" return="multiple">
     <SqlMethodComment></SqlMethodComment>
@@ -453,7 +425,6 @@
         AND l.isinvoiced = 'N' 
         AND l.M_InOut_ID=?
         AND (l.c_orderline_id is null OR pl.istaxincluded = ?)
-        AND (NOT EXISTS (SELECT 1 FROM C_InvoiceLine WHERE C_Invoice_ID = ? AND M_InOutLine_Id = l.M_InOutLine_Id))
         GROUP BY s.M_InOut_ID, s.DocumentNo, s.MovementDate, l.MovementQty,l.C_UOM_ID,uom.UOMSymbol,
         l.M_Product_ID,p.NAME, ma.serno, l.M_InOutLine_ID,l.Line,l.C_OrderLine_ID,
         COALESCE(l.A_Asset_ID, s.A_Asset_ID), COALESCE(l.C_Project_ID, s.C_Project_ID), COALESCE(l.C_Costcenter_ID, s.C_Costcenter_ID),
@@ -468,7 +439,6 @@
     <Parameter name="adOrgClient" type="replace" optional="true" after="s.AD_Org_ID IN (" text="'1'"/>
     <Parameter name="mInoutId"/>
     <Parameter name="isTaxIncluded"/>
-    <Parameter name="cInvoiceId"/>
   </SqlMethod>  
   <SqlMethod name="selectFromShipmentSOTrxCombo" type="preparedStatement" return="multiple">
     <SqlMethodComment></SqlMethodComment>
@@ -489,7 +459,6 @@
                     WHERE l.M_INOUT_ID = s.M_INOUT_ID
                     AND (l.c_orderline_id is null OR pl.istaxincluded = ?)
                     AND l.isinvoiced = 'N'
-                    AND (NOT EXISTS (SELECT 1 FROM C_InvoiceLine WHERE C_Invoice_ID = ? AND M_InOutLine_Id = l.M_InOutLine_Id)))
         AND NOT EXISTS (SELECT 1 FROM C_INVOICE_CANDIDATE_V ic, C_ORDER o 
         WHERE o.C_ORDER_ID = s.C_ORDER_ID
         AND o.C_ORDER_ID = ic.C_ORDER_ID
@@ -508,7 +477,6 @@
     <Parameter name="adOrgClient" type="replace" optional="true" after="s.AD_Org_ID IN (" text="'1'"/>
     <Parameter name="cBpartnerId"/>
     <Parameter name="isTaxIncluded"/>
-     <Parameter name="cInvoiceId"/>
   </SqlMethod>
   <SqlMethod name="selectFromShipmentTrl" type="preparedStatement" return="multiple">
     <SqlMethodComment></SqlMethodComment>
@@ -539,7 +507,6 @@
         AND l.M_Product_ID=p.M_Product_ID 
         AND l.M_InOut_ID=? 
         AND (l.c_orderline_id is null OR pl.istaxincluded = ?)
-        AND (NOT EXISTS (SELECT 1 FROM C_InvoiceLine WHERE C_Invoice_ID = ? AND M_InOutLine_Id = l.M_InOutLine_Id))
         GROUP BY s.M_InOut_ID, s.DocumentNo, s.MovementDate, l.MovementQty,l.C_UOM_ID,uom.UOMSymbol, uomt.UOMSymbol,
         l.M_Product_ID,p.NAME, ma.serno, l.M_InOutLine_ID,l.Line,l.C_OrderLine_ID,
         COALESCE(l.A_Asset_ID, s.A_Asset_ID), COALESCE(l.C_Project_ID, s.C_Project_ID), COALESCE(l.C_Costcenter_ID, s.C_Costcenter_ID),
@@ -556,7 +523,6 @@
     <Parameter name="adOrgClient" type="replace" optional="true" after="s.AD_Org_ID IN (" text="'1'"/>
     <Parameter name="mInoutId"/>
     <Parameter name="isTaxIncluded"/>
-    <Parameter name="cInvoiceId"/>
   </SqlMethod>  
   <SqlMethod name="selectFromShipmentTrlSOTrx" type="preparedStatement" return="multiple">
     <SqlMethodComment></SqlMethodComment>
@@ -587,7 +553,6 @@
         AND l.isinvoiced = 'N' 
         AND l.M_InOut_ID=? 
         AND (l.c_orderline_id is null OR pl.istaxincluded = ?)
-        AND (NOT EXISTS (SELECT 1 FROM C_InvoiceLine WHERE C_Invoice_ID = ? AND M_InOutLine_Id = l.M_InOutLine_Id))
         GROUP BY s.M_InOut_ID, s.DocumentNo, s.MovementDate, l.MovementQty,l.C_UOM_ID,uom.UOMSymbol, uomt.UOMSymbol,
         l.M_Product_ID,p.NAME,ma.serno, l.M_InOutLine_ID,l.Line,l.C_OrderLine_ID,
         COALESCE(l.A_Asset_ID, s.A_Asset_ID), COALESCE(l.C_Project_ID, s.C_Project_ID), COALESCE(l.C_Costcenter_ID, s.C_Costcenter_ID),
@@ -603,7 +568,6 @@
     <Parameter name="adOrgClient" type="replace" optional="true" after="s.AD_Org_ID IN (" text="'1'"/>
     <Parameter name="mInoutId"/>
     <Parameter name="isTaxIncluded"/>
-    <Parameter name="cInvoiceId"/>
   </SqlMethod>
   <SqlMethod name="selectFromShipmentUpdate" type="preparedStatement" connection="true" return="multiple">
     <SqlMethodComment></SqlMethodComment>
--- a/src/org/openbravo/erpCommon/ad_actionButton/CreateFrom_ShipmentPO.html	Wed Jan 09 12:22:32 2013 +0100
+++ b/src/org/openbravo/erpCommon/ad_actionButton/CreateFrom_ShipmentPO.html	Wed Jan 09 12:41:13 2013 +0100
@@ -11,7 +11,7 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2001-2012 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2013 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -141,7 +141,9 @@
 
     function checkActual(obj) {
       selectedCheck = selectedRow.id.toString().replace('funcEvenOddRow', 'CheckNum');
-      document.getElementById(selectedCheck).checked = !document.getElementById(selectedCheck).checked;
+      if (document.getElementById(selectedCheck)){
+        document.getElementById(selectedCheck).checked = !document.getElementById(selectedCheck).checked;
+      }
     }
 
     function HoverCell(cell) {
@@ -172,7 +174,7 @@
             }
           }
           i = i + 1;     
-          if(parseInt(currentValue) > parseInt(defaultValue)) {
+          if(formattedNumberOp(currentValue, '>', defaultValue)) {
             invalid = true;
             showJSMessage('InvalidMovementQty');
             break;
--- a/src/org/openbravo/erpCommon/ad_actionButton/CreateFrom_Shipment_data.xsql	Wed Jan 09 12:22:32 2013 +0100
+++ b/src/org/openbravo/erpCommon/ad_actionButton/CreateFrom_Shipment_data.xsql	Wed Jan 09 12:41:13 2013 +0100
@@ -12,7 +12,7 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2001-2012 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2013 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -56,8 +56,6 @@
         AND l.C_UOM_ID=uom.C_UOM_ID
         AND l.M_Product_ID=p.M_Product_ID
         AND l.C_Order_ID = ? 
-        AND (NOT EXISTS (SELECT 1 FROM M_InOutLine WHERE M_InOut_ID = ? AND C_OrderLine_Id = l.C_OrderLine_Id)
-        OR l.QtyOrdered <> (SELECT SUM(MovementQty) FROM M_InOutLine WHERE C_OrderLine_ID = l.C_OrderLine_ID AND M_InOut_ID = ?))
         GROUP BY o.C_ORDER_ID, o.DocumentNo, o.DateOrdered, o.GrandTotal, l.QtyOrdered,l.qtydelivered, 
         l.C_UOM_ID,uom.UOMSymbol,l.M_Product_ID,p.NAME,l.Line,l.C_OrderLine_ID, l.ad_org_id, l.DESCRIPTION, l.QUANTITYORDER, 
         l.M_PRODUCT_UOM_ID, l.M_ATTRIBUTESETINSTANCE_ID, coalesce(l.a_asset_id,o.a_asset_id), coalesce(l.c_project_id,o.c_project_id), coalesce(l.c_costcenter_id, o.c_costcenter_id),
@@ -72,8 +70,6 @@
     <Parameter name="adUserClient" type="replace" optional="true" after="o.AD_Client_ID IN (" text="'1'"/>
     <Parameter name="adOrgClient" type="replace" optional="true" after="o.AD_Org_ID IN (" text="'1'"/>
     <Parameter name="poId"/>
-    <Parameter name="mInOutId"/>
-    <Parameter name="mInOutId"/>
   </SqlMethod>
   <SqlMethod name="selectFromPOCombo" type="preparedStatement" return="multiple">
     <SqlMethodComment></SqlMethodComment>
@@ -90,8 +86,6 @@
                       FROM C_ORDERLINE l left join M_MATCHPO m on l.C_OrderLine_ID=m.C_OrderLine_ID
                                                               and  m.M_InOutLine_ID IS NOT NULL
                      WHERE l.C_ORDER_ID = o.C_ORDER_ID 
-                      AND (NOT EXISTS (SELECT 1 FROM M_InOutLine WHERE M_InOut_ID = ? AND C_OrderLine_Id=l.C_OrderLine_Id)
-                      OR l.QtyOrdered <> (SELECT SUM(MovementQty) FROM M_InOutLine WHERE C_OrderLine_ID = l.C_OrderLine_ID AND M_InOut_ID = ?))
                       GROUP BY l.C_OrderLine_ID, l.QtyOrdered 
                       HAVING (l.QtyOrdered-SUM(COALESCE(m.Qty,0))) <> 0)
         ORDER BY NAME
@@ -102,8 +96,6 @@
     <Parameter name="adUserClient" type="replace" optional="true" after="o.AD_Client_ID IN (" text="'1'"/>
     <Parameter name="adOrgClient" type="replace" optional="true" after="o.AD_Org_ID IN (" text="'1'"/>
     <Parameter name="cBpartnerId"/>
-    <Parameter name="mInOutId"/>
-    <Parameter name="mInOutId"/>
   </SqlMethod>
   <SqlMethod name="selectFromPOSOTrx" type="preparedStatement" return="multiple">
     <SqlMethodComment></SqlMethodComment>
@@ -126,7 +118,6 @@
         AND l.M_Product_ID=p.M_Product_ID 
         AND ic.C_Order_ID = ?
         AND l.QtyOrdered <> COALESCE(l.qtydelivered,0)
-        AND NOT EXISTS (SELECT 1 FROM M_InOutLine WHERE M_InOut_ID = ? AND C_OrderLine_Id = l.C_OrderLine_Id)
         GROUP BY o.C_ORDER_ID, o.DocumentNo, o.DateOrdered, o.GrandTotal, l.QtyOrdered,l.qtydelivered, 
         l.C_UOM_ID,uom.UOMSymbol,l.M_Product_ID,p.NAME,l.Line,l.C_OrderLine_ID, l.ad_org_id, l.DESCRIPTION,
        	coalesce(l.a_asset_id,o.a_asset_id) , coalesce( l.c_project_id,o.c_project_id),coalesce(l.c_costcenter_id,o.c_costcenter_id), 
@@ -140,7 +131,6 @@
     <Parameter name="adUserClient" type="replace" optional="true" after="ic.AD_Client_ID IN (" text="'1'"/>
     <Parameter name="adOrgClient" type="replace" optional="true" after="ic.AD_Org_ID IN (" text="'1'"/>
     <Parameter name="poId"/>
-    <Parameter name="mInOutId"/>
   </SqlMethod>
   <SqlMethod name="selectFromPOSOTrxCombo" type="preparedStatement" return="multiple">
     <SqlMethodComment></SqlMethodComment>
@@ -152,11 +142,6 @@
         AND ic.AD_Client_ID IN ('1') 
         AND ic.AD_Org_ID IN ('1') 
         AND ic.C_BPartner_ID = ? 
-        AND EXISTS (SELECT 1
-                      FROM C_ORDERLINE l left join M_MATCHPO m on l.C_OrderLine_ID=m.C_OrderLine_ID
-                                                              and  m.M_InOutLine_ID IS NOT NULL
-                     WHERE l.C_ORDER_ID = o.C_ORDER_ID
-                     AND NOT EXISTS (SELECT 1 FROM M_InOutLine WHERE M_InOut_ID = ? AND C_OrderLine_Id = l.C_OrderLine_Id))
         GROUP BY o.C_ORDER_ID, o.DocumentNo, o.DateOrdered, o.GrandTotal 
         ORDER BY NAME
       ]]>
@@ -166,7 +151,6 @@
     <Parameter name="adUserClient" type="replace" optional="true" after="ic.AD_Client_ID IN (" text="'1'"/>
     <Parameter name="adOrgClient" type="replace" optional="true" after="ic.AD_Org_ID IN (" text="'1'"/>
     <Parameter name="cBpartnerId"/>
-    <Parameter name="mInOutId"/>
   </SqlMethod>
   <SqlMethod name="selectFromPOTrl" type="preparedStatement" return="multiple">
     <SqlMethodComment></SqlMethodComment>
@@ -199,8 +183,6 @@
         AND l.C_UOM_ID=uom.C_UOM_ID 
         AND l.M_Product_ID=p.M_Product_ID
         AND l.C_Order_ID = ? 
-        AND (NOT EXISTS (SELECT 1 FROM M_InOutLine WHERE M_InOut_ID = ? AND C_OrderLine_Id = l.C_OrderLine_Id)
-        OR l.QtyOrdered <> (SELECT SUM(MovementQty) FROM M_InOutLine WHERE C_OrderLine_ID = l.C_OrderLine_ID AND M_InOut_ID = ?))
         GROUP BY o.C_ORDER_ID, o.DocumentNo, o.DateOrdered, o.GrandTotal, l.QtyOrdered,l.qtydelivered, 
         l.C_UOM_ID,uom.UOMSymbol, uomt.UOMSymbol,l.M_Product_ID,p.NAME,l.Line,l.C_OrderLine_ID, l.DESCRIPTION, l.QUANTITYORDER, l.M_PRODUCT_UOM_ID, l.M_ATTRIBUTESETINSTANCE_ID
         HAVING (l.QtyOrdered-SUM(COALESCE(m.Qty,0))) <> 0
@@ -214,8 +196,6 @@
     <Parameter name="adUserClient" type="replace" optional="true" after="o.AD_Client_ID IN (" text="'1'"/>
     <Parameter name="adOrgClient" type="replace" optional="true" after="o.AD_Org_ID IN (" text="'1'"/>
     <Parameter name="poId"/>
-    <Parameter name="mInOutId"/>
-    <Parameter name="mInOutId"/>
   </SqlMethod>
   <SqlMethod name="selectFromPOTrlSOTrx" type="preparedStatement" return="multiple">
     <SqlMethodComment></SqlMethodComment>
@@ -235,8 +215,6 @@
         AND l.M_Product_ID=p.M_Product_ID 
         AND ic.C_Order_ID = ?
         AND l.QtyOrdered <> COALESCE(l.qtydelivered,0)
-        AND (NOT EXISTS (SELECT 1 FROM M_InOutLine WHERE M_InOut_ID = ? AND C_OrderLine_Id = l.C_OrderLine_Id)
-        OR l.QtyOrdered <> (SELECT SUM(MovementQty) FROM M_InOutLine WHERE C_OrderLine_ID = l.C_OrderLine_ID AND M_InOut_ID = ?))
         GROUP BY o.C_ORDER_ID, o.DocumentNo, o.DateOrdered, o.GrandTotal, l.QtyOrdered,l.qtydelivered, 
         l.C_UOM_ID,uom.UOMSymbol,uomt.UOMSymbol,l.M_Product_ID,p.NAME,l.Line,l.C_OrderLine_ID, l.DESCRIPTION
         ORDER BY NAME, l.Line
@@ -249,8 +227,6 @@
     <Parameter name="adUserClient" type="replace" optional="true" after="ic.AD_Client_ID IN (" text="'1'"/>
     <Parameter name="adOrgClient" type="replace" optional="true" after="ic.AD_Org_ID IN (" text="'1'"/>
     <Parameter name="poId"/>
-    <Parameter name="mInOutId"/>
-    <Parameter name="mInOutId"/>
   </SqlMethod>
   <SqlMethod name="selectFromPOUpdate" type="preparedStatement" connection="true" return="multiple">
     <SqlMethodComment></SqlMethodComment>
@@ -345,8 +321,6 @@
         AND l.C_UOM_ID=uom.C_UOM_ID 
         AND l.M_Product_ID=p.M_Product_ID 
         AND l.C_Invoice_ID = ? 
-        AND (l.M_INOUTLINE_ID IS NULL
-        OR l.QtyInvoiced <> (SELECT SUM(MovementQty) FROM M_InOutLine WHERE M_InOutLine_ID = l.M_InOutLine_ID))
         GROUP BY i.C_Invoice_ID, i.DocumentNo, DateInvoiced, GrandTotal, l.QtyInvoiced, 
         l.C_UOM_ID,uom.UOMSymbol,l.M_Product_ID,p.NAME, l.C_InvoiceLine_ID,l.Line,l.C_OrderLine_ID, l.DESCRIPTION,l.QUANTITYORDER,
         l.M_PRODUCT_UOM_ID,l.M_ATTRIBUTESETINSTANCE_ID,  coalesce(l.a_asset_id,i.a_asset_id), coalesce(l.c_project_id,i.c_project_id), 
@@ -383,7 +357,6 @@
         AND l.C_UOM_ID=uom.C_UOM_ID 
         AND l.M_Product_ID=p.M_Product_ID 
         AND l.C_Invoice_ID = ?
-        AND l.M_InOutLine_ID IS NULL
         GROUP BY i.C_Invoice_ID, i.DocumentNo, DateInvoiced, GrandTotal, l.QtyInvoiced, 
         l.C_UOM_ID,uom.UOMSymbol,l.M_Product_ID,p.NAME, l.C_InvoiceLine_ID,l.Line,l.C_OrderLine_ID, l.DESCRIPTION,
         coalesce(l.a_asset_id,i.a_asset_id), coalesce(l.c_project_id,i.c_project_id),coalesce(l.c_costcenter_id,i.c_costcenter_id), 
@@ -413,8 +386,6 @@
         AND EXISTS (SELECT 1 
                      FROM C_INVOICELINE l left join M_MATCHINV mi on l.C_InvoiceLine_ID=mi.C_InvoiceLine_ID
                       WHERE l.C_INVOICE_ID = i.C_INVOICE_ID 
-                      AND (l.M_INOUTLINE_ID IS NULL
-                      OR l.QtyInvoiced <> (SELECT SUM(MovementQty) FROM M_InOutLine WHERE M_InOutLine_ID = l.M_InOutLine_ID))
                       GROUP BY l.QtyInvoiced, l.C_InvoiceLine_ID 
                       HAVING (l.QtyInvoiced-SUM(COALESCE(mi.Qty,0))) <> 0 ) 
         ORDER BY NAME
@@ -440,7 +411,6 @@
         AND EXISTS (SELECT 1                      
                 FROM C_INVOICELINE l LEFT JOIN M_INOUTLINE MI ON l.M_INOUTLINE_ID = MI.M_INOUTLINE_ID                        
                 WHERE l.C_INVOICE_ID = i.C_INVOICE_ID                
-                AND l.M_INOUTLINE_ID IS NULL
                 GROUP BY l.C_InvoiceLine_ID ,l.QtyInvoiced                
                 HAVING (l.QtyInvoiced-SUM(COALESCE(mi.MOVEMENTQTY,0))) <> 0 ) 
         ORDER BY NAME
@@ -484,8 +454,6 @@
         AND l.C_UOM_ID=uom.C_UOM_ID 
         AND l.M_Product_ID=p.M_Product_ID 
         AND l.C_Invoice_ID = ? 
-        AND (l.M_INOUTLINE_ID IS NULL
-        OR l.QtyInvoiced <> (SELECT SUM(MovementQty) FROM M_InOutLine WHERE M_InOutLine_ID = l.M_InOutLine_ID))
         GROUP BY i.C_Invoice_ID, i.DocumentNo, DateInvoiced, GrandTotal, l.QtyInvoiced, 
         l.C_UOM_ID,uom.UOMSymbol, uomt.UOMSymbol,l.M_Product_ID,p.NAME, l.C_InvoiceLine_ID,l.Line,l.C_OrderLine_ID, 
         l.DESCRIPTION, l.QUANTITYORDER, l.M_PRODUCT_UOM_ID,l.M_ATTRIBUTESETINSTANCE_ID
@@ -715,29 +683,6 @@
     <Parameter name="mInoutlineId"/>
     <Parameter name="cInvoiceId"/>
   </SqlMethod>
-  <SqlMethod name="insertMatchPO" type="preparedStatement" connection="true" return="rowCount">
-    <SqlMethodComment></SqlMethodComment>
-    <Sql>
-      INSERT INTO M_MATCHPO
-        (
-        M_MATCHPO_ID, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED, CREATEDBY,
-        UPDATED, UPDATEDBY, M_INOUTLINE_ID, C_ORDERLINE_ID, M_PRODUCT_ID,
-        DATETRX, QTY, PROCESSING, PROCESSED, POSTED
-        )
-      SELECT
-        GET_UUID(), iol.AD_CLIENT_ID, iol.AD_ORG_ID, 'Y', NOW(), ?,
-        NOW(), ?, iol.M_INOUTLINE_ID, ?, iol.M_PRODUCT_ID,
-        o.DATEACCT, iol.MOVEMENTQTY, 'N', 'Y', 'N'
-      FROM M_INOUTLINE iol, C_ORDER o
-      WHERE iol.M_INOUTLINE_ID=?
-        AND o.C_ORDER_ID=?
-    </Sql>
-    <Parameter name="adUserId"/>
-    <Parameter name="adUserId"/>
-    <Parameter name="cOrderLineId"/>
-    <Parameter name="mInoutlineId"/>
-    <Parameter name="cOrderId"/>
-  </SqlMethod>
   <SqlMethod name="selectInvoiceInOut" type="preparedStatement" connection="true" return="string">
     <SqlMethodComment></SqlMethodComment>
     <Sql>
--- a/src/org/openbravo/erpCommon/ad_forms/MaterialReceiptPending_data.xsql	Wed Jan 09 12:22:32 2013 +0100
+++ b/src/org/openbravo/erpCommon/ad_forms/MaterialReceiptPending_data.xsql	Wed Jan 09 12:41:13 2013 +0100
@@ -12,7 +12,7 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2001-2012 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2013 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -63,12 +63,10 @@
       SELECT C_ORDERLINE.C_ORDERLINE_ID AS ID, C_ORDER.C_ORDER_ID AS C_ORDER_ID, C_ORDER.DOCUMENTNO AS DOCUMENTNO, C_ORDER.DATEORDERED AS DATEORDERED, 
       C_BPARTNER.C_BPARTNER_ID AS C_BPARTNER_ID, C_BPARTNER.NAME AS PARTNER_NAME, 
       AD_COLUMN_IDENTIFIER(TO_CHAR('M_Product'), TO_CHAR(C_ORDERLINE.M_PRODUCT_ID), TO_CHAR(?)) AS PRODUCT_NAME, M_ATTRIBUTESETINSTANCE.DESCRIPTION AS DESCRIPTION, C_ORDERLINE.QTYORDERED AS TOTAL_QTY,
-      C_ORDERLINE.QTYORDERED-SUM((CASE WHEN (COALESCE(m_inout.docstatus, 'DR') = 'DR') THEN 0 ELSE (COALESCE(M_MATCHPO.QTY,0)) END)) AS QTYORDERED, '-1' AS ISACTIVE, C_ORDERLINE.LINE
+      C_ORDERLINE.QTYORDERED-SUM(COALESCE(M_MATCHPO.QTY,0)) AS QTYORDERED, '-1' AS ISACTIVE, C_ORDERLINE.LINE
       FROM C_ORDERLINE left join M_MATCHPO on C_ORDERLINE.C_ORDERLINE_ID = M_MATCHPO.C_ORDERLINE_ID
                                            and M_MATCHPO.M_INOUTLINE_ID IS NOT NULL
-                       left join M_ATTRIBUTESETINSTANCE on C_ORDERLINE.M_ATTRIBUTESETINSTANCE_ID = M_ATTRIBUTESETINSTANCE.M_ATTRIBUTESETINSTANCE_ID
-                       left join m_inoutline on m_inoutline.m_inoutline_id =M_MATCHPO.M_INOUTLINE_ID
-                       left join m_inout on m_inoutline.m_inout_id=m_inout.m_inout_id,
+                       left join M_ATTRIBUTESETINSTANCE on C_ORDERLINE.M_ATTRIBUTESETINSTANCE_ID = M_ATTRIBUTESETINSTANCE.M_ATTRIBUTESETINSTANCE_ID,
       C_ORDER,   C_BPARTNER, C_DOCTYPE
       WHERE C_ORDER.C_BPARTNER_ID = C_BPARTNER.C_BPARTNER_ID
       AND C_ORDER.C_ORDER_ID = C_ORDERLINE.C_ORDER_ID