Fixed issue 25308.Added c_get_product_taxcategory procedure.
authorGorka Ion Damián <gorkaion.damian@openbravo.com>
Wed, 11 Dec 2013 17:47:43 +0100
changeset 21629 f82bbc9db4cb
parent 21628 a3700b6722a3
child 21630 1bd8af6b5ac9
Fixed issue 25308.Added c_get_product_taxcategory procedure.
src-db/database/model/functions/C_GETTAX.xml
src-db/database/model/functions/C_GET_PRODUCT_TAXCATEGORY.xml
src-db/database/sourcedata/AD_REF_LIST.xml
--- a/src-db/database/model/functions/C_GETTAX.xml	Wed Dec 11 17:50:26 2013 +0100
+++ b/src-db/database/model/functions/C_GETTAX.xml	Wed Dec 11 17:47:43 2013 +0100
@@ -146,18 +146,6 @@
         END LOOP;
       END;
     ELSE
-      IF(p_glitem_id IS NULL) THEN
-        SELECT C_TaxCategory_ID
-        INTO v_TaxCategoryID
-        FROM M_Product
-        WHERE M_Product_ID = p_Product_ID;
-      ELSE
-        SELECT C_TaxCategory_ID
-        INTO v_TaxCategoryID
-        FROM C_GLITEM
-        WHERE C_GLITEM_ID = p_glitem_id;
-      END IF;
-      
       IF(p_Warehouse_ID IS NULL) THEN
         v_shipFrom := v_billFrom;
       ELSE
@@ -170,7 +158,7 @@
       INTO v_shipTo
       FROM C_BPartner_Location
       WHERE C_BPartner_Location_ID = p_shipBPartnerLoc_ID;
-      IF p_IsSOTrx = 'N' THEN
+      IF (p_IsSOTrx = 'N') THEN
         v_aux := v_billTo;
         v_billTo := v_billFrom;
         v_billFrom := v_aux;
@@ -178,6 +166,14 @@
         v_shipTo := v_shipFrom;
         v_shipFrom := v_aux;
       END IF;
+      IF(p_glitem_id IS NULL) THEN
+        v_taxcategoryid := C_GET_PRODUCT_TAXCATEGORY(p_product_id, p_org_id, p_shipDate, v_shipfrom, v_shipto);
+      ELSE
+        SELECT C_TaxCategory_ID
+        INTO v_TaxCategoryID
+        FROM C_GLITEM
+        WHERE C_GLITEM_ID = p_glitem_id;
+      END IF;
       DECLARE
         SEL1 RECORD;
         SEL2 RECORD;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-db/database/model/functions/C_GET_PRODUCT_TAXCATEGORY.xml	Wed Dec 11 17:47:43 2013 +0100
@@ -0,0 +1,68 @@
+<?xml version="1.0"?>
+  <database name="FUNCTION C_GET_PRODUCT_TAXCATEGORY">
+    <function name="C_GET_PRODUCT_TAXCATEGORY" type="VARCHAR">
+      <parameter name="p_product_id" type="VARCHAR" mode="in">
+        <default/>
+      </parameter>
+      <parameter name="p_org_id" type="VARCHAR" mode="in">
+        <default/>
+      </parameter>
+      <parameter name="p_date" type="TIMESTAMP" mode="in">
+        <default/>
+      </parameter>
+      <parameter name="p_shipfrom" type="VARCHAR" mode="in">
+        <default/>
+      </parameter>
+      <parameter name="p_shipto" type="VARCHAR" mode="in">
+        <default/>
+      </parameter>
+      <body><![CDATA[/*************************************************************************
+* The contents of this file are subject to the Openbravo  Public  License
+* Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
+* Version 1.1  with a permitted attribution clause; you may not  use this
+* file except in compliance with the License. You  may  obtain  a copy of
+* the License at http://www.openbravo.com/legal/license.html
+* Software distributed under the License  is  distributed  on  an "AS IS"
+* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+* License for the specific  language  governing  rights  and  limitations
+* under the License.
+* The Original Code is Openbravo ERP.
+* The Initial Developer of the Original Code is Openbravo SLU
+* All portions are Copyright (C) 2013 Openbravo SLU
+* All Rights Reserved.
+* Contributor(s):  ______________________________________.
+************************************************************************/
+  v_count                   NUMBER;
+  v_dbprefix                VARCHAR2(7);
+  v_client_id               VARCHAR2(32);
+  v_prodtaxcategory_id      VARCHAR2(32);
+  v_taxcategory_id          VARCHAR2(32);
+  v_Sql VARCHAR2(2000);
+BEGIN
+  SELECT ad_client_id, c_taxcategory_id
+    INTO v_client_id, v_prodtaxcategory_id
+  FROM m_product
+  WHERE m_product_id = p_product_id;
+  SELECT count(1) INTO v_count
+  FROM ad_preference
+  WHERE property = 'GETPRODUCTTAXCATEGORY';
+    --AND ad_module_id <> '0';
+  IF (v_count > 0) THEN
+    v_dbprefix := AD_GET_PREFERENCE_VALUE('GETPRODUCTTAXCATEGORY', 'Y', v_client_id, p_org_id, NULL, NULL, NULL);
+  ELSIF (v_count = 0) THEN
+    RETURN v_prodtaxcategory_id;
+  END IF;
+  BEGIN
+    v_Sql := 'SELECT ' || v_dbprefix || '_get_product_taxcategory' || '(''' || coalesce(p_product_id, '') || ''', ''' || coalesce(p_org_id, '') || ''', ''' || coalesce(p_date, '') || ''', ''' || coalesce(p_shipfrom, '') || ''', ''' || coalesce(p_shipto, '') || ''') FROM DUAL';
+
+    EXECUTE IMMEDIATE v_Sql INTO v_taxcategory_id;
+  EXCEPTION WHEN OTHERS THEN
+    DBMS_OUTPUT.PUT_LINE(v_dbprefix || '_get_product_taxcategory function not implemented');
+    DBMS_OUTPUT.PUT_LINE('Error ' || SQLERRM);
+  END;
+  v_taxcategory_id := COALESCE(v_taxcategory_id, v_prodtaxcategory_id);
+
+  RETURN v_taxcategory_id;
+END C_GET_PRODUCT_TAXCATEGORY]]></body>
+    </function>
+  </database>
--- a/src-db/database/sourcedata/AD_REF_LIST.xml	Wed Dec 11 17:50:26 2013 +0100
+++ b/src-db/database/sourcedata/AD_REF_LIST.xml	Wed Dec 11 17:47:43 2013 +0100
@@ -10759,6 +10759,17 @@
 <!--A60D08A595E84734A6369720E2BFE84F-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
 <!--A60D08A595E84734A6369720E2BFE84F--></AD_REF_LIST>
 
+<!--A61B0423A65243D2AF148B4E268227C8--><AD_REF_LIST>
+<!--A61B0423A65243D2AF148B4E268227C8-->  <AD_REF_LIST_ID><![CDATA[A61B0423A65243D2AF148B4E268227C8]]></AD_REF_LIST_ID>
+<!--A61B0423A65243D2AF148B4E268227C8-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--A61B0423A65243D2AF148B4E268227C8-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--A61B0423A65243D2AF148B4E268227C8-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--A61B0423A65243D2AF148B4E268227C8-->  <VALUE><![CDATA[GETPRODUCTTAXCATEGORY]]></VALUE>
+<!--A61B0423A65243D2AF148B4E268227C8-->  <NAME><![CDATA[Get Product Tax Category impementation]]></NAME>
+<!--A61B0423A65243D2AF148B4E268227C8-->  <AD_REFERENCE_ID><![CDATA[A26BA480E2014707B47257024C3CBFF7]]></AD_REFERENCE_ID>
+<!--A61B0423A65243D2AF148B4E268227C8-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--A61B0423A65243D2AF148B4E268227C8--></AD_REF_LIST>
+
 <!--A68E543C89BE4174990D33DFBAD90E05--><AD_REF_LIST>
 <!--A68E543C89BE4174990D33DFBAD90E05-->  <AD_REF_LIST_ID><![CDATA[A68E543C89BE4174990D33DFBAD90E05]]></AD_REF_LIST_ID>
 <!--A68E543C89BE4174990D33DFBAD90E05-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>