src-util/modulescript/src/org/openbravo/modulescript/UpdatePersistOrgInfo_data.xsql
author Víctor Martínez Romanos <victor.martinez@openbravo.com>
Fri, 27 Apr 2018 10:55:13 +0200
changeset 33894 faca925fb578
parent 33887 793f3d0ba3f5
permissions -rw-r--r--
Related to issue 33650: code review improvements
Properly format modulescript
Removed info message in module script
Increased limits
Ensure we don't work with * org and any organization where the persist org is already available
<?xml version="1.0" encoding="UTF-8" ?>
<!--
 *************************************************************************
 * 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) 2018 Openbravo SLU
 * All Rights Reserved.
 * Contributor(s):  ______________________________________.
 ************************************************************************
-->
<SqlClass name="UpdatePersistOrgInfoData" package="org.openbravo.modulescript">
   <SqlClassComment></SqlClassComment>
   <SqlMethod name="select" type="preparedStatement" return="multiple">
    <SqlMethodComment></SqlMethodComment>
    <Sql><![CDATA[
      SELECT 1 as dummy, '' as AD_Org_ID, '' as C_CALENDAR_ID FROM DUAL
      ]]>
    </Sql>
   </SqlMethod>
  <SqlMethod name="selectOrgs" type="preparedStatement" return="multiple">
    <SqlMethodComment></SqlMethodComment>
    <Sql><![CDATA[
        SELECT AD_Org_ID
        FROM AD_Org
        WHERE IsReady = 'Y'
        AND AD_Org_ID <> '0'
        AND AD_PeriodControlAllowed_Org_ID IS NULL
        AND AD_CalendarOwner_Org_ID IS NULL 
        AND AD_InheritedCalendar_ID IS NULL 
        AND AD_LegalEntity_Org_ID IS NULL
        AND AD_BusinessUnit_Org_ID IS NULL
    ]]></Sql>
    <Field name="dummy" value="void"/>
  </SqlMethod>
  <SqlMethod name="updatePersistOrgInfo" type="preparedStatement" return="rowcount">
    <SqlMethodComment></SqlMethodComment>
    <Sql><![CDATA[
        UPDATE AD_Org
        SET AD_PeriodControlAllowed_Org_ID = ?,
            AD_CalendarOwner_Org_ID = ?,
            AD_InheritedCalendar_ID = ?,
            AD_LegalEntity_Org_ID = ?,
            AD_BusinessUnit_Org_ID = ?
        WHERE AD_Org_ID = ?
    ]]></Sql>
    <Parameter name="periodControlAllowedOrg"/>
    <Parameter name="calendarOwnerOrg"/>
    <Parameter name="inheritedCalendarOrg"/>
    <Parameter name="legalEntityOrg"/>
    <Parameter name="businessUnitOrg"/>
    <Parameter name="orgId"/>
  </SqlMethod>
  <SqlMethod name="getPeriodControlAllowedOrg" type="preparedStatement" return="String">
    <SqlMethodComment></SqlMethodComment>
    <Sql><![CDATA[
        SELECT ad_org_getperiodcontrolallowtn(?) AS AD_Org_ID
        FROM DUAL
    ]]></Sql>
    <Parameter name="orgId"/>
  </SqlMethod>
  <SqlMethod name="getCalendarOwnerOrg" type="preparedStatement" return="String">
    <SqlMethodComment></SqlMethodComment>
    <Sql><![CDATA[
        SELECT ad_org_getcalendarownertn(?) AS AD_Org_ID
        FROM DUAL
    ]]></Sql>
    <Parameter name="orgId"/>
  </SqlMethod>
  <SqlMethod name="getCalendar" type="preparedStatement" return="String">
    <SqlMethodComment></SqlMethodComment>
    <Sql><![CDATA[
        SELECT C_CALENDAR_ID
        FROM AD_ORG
        WHERE AD_ORG_ID = ?
    ]]></Sql>
    <Parameter name="orgId"/>
  </SqlMethod>
  <SqlMethod name="getLegalEntityBusinessUnitOrg" type="preparedStatement" return="String">
    <SqlMethodComment></SqlMethodComment>
    <Sql><![CDATA[
        SELECT ad_get_org_le_bu_treenode(?, ?) AS AD_Org_ID
        FROM DUAL
    ]]></Sql>
    <Parameter name="orgId"/>
    <Parameter name="orgType"/>
  </SqlMethod>
  <SqlMethod name="isPersistOrgInfoUpdated" type="preparedStatement" return="boolean">
    <SqlMethodComment></SqlMethodComment>
    <Sql>
      <![CDATA[
        SELECT count(*) as exist
        FROM DUAL
        WHERE EXISTS (SELECT 1 FROM ad_preference
                      WHERE attribute = 'PersistOrgInfoUpdated')
      ]]>
    </Sql>
  </SqlMethod>
  <SqlMethod name="createPreferencePersistOrgInfoUpdated" type="preparedStatement" return="rowcount">
    <SqlMethodComment></SqlMethodComment>
    <Sql>
      <![CDATA[
        INSERT INTO ad_preference (
          ad_preference_id, ad_client_id, ad_org_id, isactive,
          createdby, created, updatedby, updated,
          attribute, value
        ) VALUES (
          get_uuid(), '0', '0', 'Y',
          '0', NOW(), '0', NOW(),
          'PersistOrgInfoUpdated', 'Y'
        )
      ]]>
    </Sql>
  </SqlMethod>
 </SqlClass>