src/org/openbravo/erpCommon/ad_reports/ReportProductMovement_data.xsql
changeset 15925 3d5a75391c27
parent 13007 bc639e86fe20
child 16207 705c297b4a4e
--- a/src/org/openbravo/erpCommon/ad_reports/ReportProductMovement_data.xsql	Wed Mar 21 16:07:10 2012 +0100
+++ b/src/org/openbravo/erpCommon/ad_reports/ReportProductMovement_data.xsql	Wed Mar 21 17:34:15 2012 +0100
@@ -38,7 +38,7 @@
       AD_MESSAGE_GET2(M_INOUT.ISSOTRX,?) AS OUT,
       (SUM(M_TRANSACTION.MOVEMENTQTY)||' '||C_UOM.NAME) AS MOVEMENTQTY, M_INOUT.ISSOTRX AS ISSOTRX, M_INOUT.M_INOUT_ID,
       M_INOUT.DOCUMENTNO AS DOCUMENTNO, '' AS M_MOVEMENTLINE_ID, '' AS MOVEMENT, '' AS MOVEMENT_DESCRIPTION,
-      '' AS M_INVENTORY_ID, '' AS M_MOVEMENT_ID, '' AS M_PRODUCTIONPLAN_ID, '' AS PRODUCTION_PLAN
+      '' AS M_INVENTORY_ID, '' AS M_MOVEMENT_ID, '' AS M_PRODUCTIONPLAN_ID, '' AS PRODUCTION_PLAN, '' AS M_INTERNAL_CONSUMPTION_ID
       FROM M_PRODUCT left join C_BPARTNER on M_PRODUCT.C_BPARTNER_ID = C_BPARTNER.C_BPARTNER_ID
                      right join M_TRANSACTION on M_TRANSACTION.M_PRODUCT_ID = M_PRODUCT.M_PRODUCT_ID
                      left join M_ATTRIBUTESETINSTANCE ON M_ATTRIBUTESETINSTANCE.M_ATTRIBUTESETINSTANCE_ID=M_TRANSACTION.M_ATTRIBUTESETINSTANCE_ID,
@@ -164,6 +164,38 @@
     <Parameter name="cBpartner" optional="true" after="AND 1=1"><![CDATA[ AND C_BPARTNER.C_BPARTNER_ID = ?]]></Parameter>
     <Parameter name="mProductId" optional="true" after="AND 1=1"><![CDATA[ AND M_PRODUCT.M_PRODUCT_ID = ?]]></Parameter>
   </SqlMethod>
+  
+  <SqlMethod name="selectInternalConsumption" type="preparedStatement" return="multiple">
+    <SqlMethodComment></SqlMethodComment>
+    <Sql>
+    <![CDATA[
+      SELECT M_PRODUCT.VALUE, M_PRODUCT.NAME, M_LOCATOR.X AS X_ORIGIN, M_LOCATOR.Y AS Y_ORIGIN, M_LOCATOR.Z AS Z_ORIGIN, C_BPARTNER.NAME AS PARTNERNAME, 
+      (SUM(M_TRANSACTION.MOVEMENTQTY)||' '||C_UOM.NAME) AS MOVEMENTQTY, M_TRANSACTION.MOVEMENTDATE, 'No' AS OUT,
+      M_INTERNAL_CONSUMPTION.M_INTERNAL_CONSUMPTION_ID, M_INTERNAL_CONSUMPTION.NAME AS MOVEMENT, M_INTERNAL_CONSUMPTION.NAME AS MOVEMENT_DESCRIPTION
+      FROM M_PRODUCT left join C_BPARTNER on M_PRODUCT.C_BPARTNER_ID = C_BPARTNER.C_BPARTNER_ID
+                     right join M_TRANSACTION on M_TRANSACTION.M_PRODUCT_ID = M_PRODUCT.M_PRODUCT_ID,
+          M_LOCATOR,  C_UOM, M_INTERNAL_CONSUMPTIONLINE, M_INTERNAL_CONSUMPTION
+      WHERE  M_TRANSACTION.M_LOCATOR_ID = M_LOCATOR.M_LOCATOR_ID
+      AND M_TRANSACTION.C_UOM_ID = C_UOM.C_UOM_ID
+      AND M_TRANSACTION.M_INTERNAL_CONSUMPTIONLINE_ID = M_INTERNAL_CONSUMPTIONLINE.M_INTERNAL_CONSUMPTIONLINE_ID
+      AND M_INTERNAL_CONSUMPTIONLINE.M_INTERNAL_CONSUMPTION_ID = M_INTERNAL_CONSUMPTION.M_INTERNAL_CONSUMPTION_ID
+      AND M_TRANSACTION.M_INTERNAL_CONSUMPTIONLINE_ID IS NOT NULL
+      AND M_TRANSACTION.AD_CLIENT_ID IN ('1')
+      AND M_TRANSACTION.AD_ORG_ID IN ('1')
+      AND 1=1
+      GROUP BY M_PRODUCT.VALUE, M_PRODUCT.NAME, M_LOCATOR.X, M_LOCATOR.Y, M_LOCATOR.Z, C_BPARTNER.NAME, C_UOM.NAME, 
+      M_TRANSACTION.MOVEMENTDATE, M_INTERNAL_CONSUMPTION.M_INTERNAL_CONSUMPTION_ID, M_INTERNAL_CONSUMPTION.NAME, M_INTERNAL_CONSUMPTION.DESCRIPTION
+      HAVING SUM(M_TRANSACTION.MOVEMENTQTY) <> 0
+      ORDER BY C_BPARTNER.NAME, M_TRANSACTION.MOVEMENTDATE DESC
+     ]]></Sql>
+    <Field name="rownum" value="count"/>
+    <Parameter name="adUserClient" type="replace" optional="true" after="AND M_TRANSACTION.AD_CLIENT_ID IN (" text="'1'"/>
+    <Parameter name="adOrgClient" type="replace" optional="true" after="AND M_TRANSACTION.AD_ORG_ID IN (" text="'1'"/>
+    <Parameter name="parDateFrom" optional="true" after="AND 1=1"><![CDATA[ AND M_TRANSACTION.MOVEMENTDATE >= to_date(?)]]></Parameter>
+    <Parameter name="parDateTo" optional="true" after="AND 1=1"><![CDATA[ AND M_TRANSACTION.MOVEMENTDATE < to_date(?)]]></Parameter>
+    <Parameter name="cBpartner" optional="true" after="AND 1=1"><![CDATA[ AND C_BPARTNER.C_BPARTNER_ID = ?]]></Parameter>
+    <Parameter name="mProductId" optional="true" after="AND 1=1"><![CDATA[ AND M_PRODUCT.M_PRODUCT_ID = ?]]></Parameter>
+  </SqlMethod>
 
   <SqlMethod name="selectBpartner" type="preparedStatement" return="String" default="">
     <SqlMethodComment></SqlMethodComment>