src/org/openbravo/erpCommon/ad_forms/RemittanceCancel_data.xsql
author Iván Perdomo <ivan.perdomo@openbravo.com>
Thu, 24 Apr 2008 17:12:02 +0000
changeset 770 8850d5956eba
parent 423 ecf368072c48
child 1601 2e879205773a
permissions -rw-r--r--
Bug fix [0000111]. Modified mapping name used on manual code.
<?xml version="1.0" encoding="UTF-8" ?>
<!--
 *************************************************************************
 * The contents of this file are subject to the Openbravo  Public  License
 * Version  1.0  (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 SL 
 * All portions are Copyright (C) 2001-2006 Openbravo SL 
 * All Rights Reserved. 
 * Contributor(s):  ______________________________________.
 ************************************************************************
-->





<SqlClass name="RemittanceCancelData" package="org.openbravo.erpCommon.ad_forms">
  <SqlClassComment>Clase MaterialReceiptPendingLinesData</SqlClassComment>
  <SqlMethod name="select" type="preparedStatement" return="multiple">
    <SqlMethodComment>Select for relation</SqlMethodComment>
    <Sql>
    <![CDATA[
        select rl.C_RemittanceLine_ID,
               dp.C_Debt_Payment_ID,ad_column_identifier('C_Debt_Payment',to_char(dp.C_Debt_Payment_ID),?) AS DPIdentifier,
               rl.C_Remittance_Id,  ad_column_identifier('C_Remittance',to_char(rl.C_Remittance_Id),?) AS RIdentifier,
               r.duedate, '' as line
          from c_debt_payment    dp,
               c_remittanceLine  rl,
               c_Remittance			 r
         where rl.c_debt_payment_id = dp.c_debt_payment_id
           and coalesce(rl.returned,'N') = 'N'
           and dp.C_SETTLEMENT_CANCEL_ID is null
           and r.processed = 'Y'
           and r.C_Remittance_ID    = rl.C_Remittance_ID
           AND r.AD_CLIENT_ID IN ('1') 
           AND r.AD_ORG_ID IN ('1') 
           AND 1=1 
           order by r.DOCUMENTNO, r.duedate
      ]]></Sql>
      <Field name="rownum" value="count"/>
      <Parameter name="adLanguage"/>
      <Parameter name="adLanguage"/>
      <Parameter name="userClient" optional="true" type="replace" after="AND r.AD_CLIENT_ID IN (" text="'1'"/>
      <Parameter name="userOrg" optional="true" type="replace" after="AND r.AD_ORG_ID IN (" text="'1'"/>
      <Parameter name="cRemittanceId" optional="true" after="AND 1=1 " text=" and r.C_Remittance_ID = TO_NUMBER(?) "/> 
      <Parameter name="from" optional="true" after="AND 1=1 "><![CDATA[ and r.duedate >= TO_DATE(?) ]]></Parameter>
      <Parameter name="to" optional="true" after="AND 1=1 "><![CDATA[ and r.duedate <= TO_DATE(?) ]]></Parameter>
  </SqlMethod>

 <SqlMethod name="set" type="constant" return="multiple">
  <SqlMethodComment>Create a registry</SqlMethodComment>
  <Sql></Sql> 
  </SqlMethod>

  <SqlMethod name="insertSettlement" connection="true" type="preparedStatement" return="rowCount">
    <SqlMethodComment>Principal select</SqlMethodComment>
    <Sql>
    <![CDATA[
        INSERT INTO C_SETTLEMENT (C_SETTLEMENT_ID, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED, CREATEDBY, UPDATED, UPDATEDBY,
           DOCUMENTNO, DATETRX, DATEACCT, SETTLEMENTTYPE, C_DOCTYPE_ID, C_Currency_ID,
           description,IsGenerated)
           values
           (?, ?, ?, 'Y', now(), ?, now(), ?, 
           '*RT*'||?,?, ?,'C', Ad_Get_DocType(?, ?, 'STT'),  (select c_currency_id
                                       from  c_remittanceLine rl,
                                             c_debt_payment   dp
                                      where c_RemittanceLine_ID = TO_NUMBER(?)
                                        and dp.c_debt_payment_id = rl.c_debt_payment_id),
           '*RT* Cancel','Y')
      ]]></Sql>
    <Parameter name="cSettlementID"/>
    <Parameter name="client"/>
    <Parameter name="org"/>
    <Parameter name="user"/>
    <Parameter name="user"/>
    <Parameter name="docNo"/>
    <Parameter name="dateacct"/>
    <Parameter name="dateacct"/>
    <Parameter name="client"/>
    <Parameter name="org"/>
    <Parameter name="rl"/> 
  </SqlMethod>


    <SqlMethod name="insertDPManagement" connection="true" type="preparedStatement" return="rowCount">
    <SqlMethodComment>Principal select</SqlMethodComment>
    <Sql>
    <![CDATA[
       insert into C_DP_Management
       (C_DP_MANAGEMENT_ID, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED, CREATEDBY, UPDATED, UPDATEDBY, 
       DOCUMENTNO, DATETRX, C_DOCTYPE_ID,  DATEACCT,C_Currency_ID)
     values
       (?, ?, ?, 'Y', now(), ?, now(), ?, 
        ?, ?, Ad_Get_DocType(?, ?, 'DPM'), ?, (select c_currency_id
                                 from  c_remittanceLine rl,
                                       c_debt_payment   dp
                                where c_RemittanceLine_ID = TO_NUMBER(?)
                                  and dp.c_debt_payment_id = rl.c_debt_payment_id))
      ]]></Sql>
    <Parameter name="CDPID"/>
    <Parameter name="client"/>
    <Parameter name="org"/>
    <Parameter name="user"/>
    <Parameter name="user"/>
    <Parameter name="docNo"/>
    <Parameter name="dateacct"/>
    <Parameter name="client"/>
    <Parameter name="org"/>
    <Parameter name="dateacct"/>
    <Parameter name="rl"/> 
  </SqlMethod>
    <SqlMethod name="selectOrg" type="preparedStatement" return="String">
    <SqlMethodComment></SqlMethodComment>
    <Sql>
    <![CDATA[
      SELECT C_REMITTANCE.AD_ORG_ID FROM C_REMITTANCE, C_REMITTANCELINE
      WHERE C_REMITTANCE.C_REMITTANCE_ID =  C_REMITTANCELINE.C_REMITTANCE_ID
      AND C_REMITTANCELINE_ID = TO_NUMBER(?)
      ]]></Sql>
    <Parameter name="line"/>
  </SqlMethod>
  <SqlMethod name="cancel" connection="true" type="preparedStatement" return="rowCount">
    <SqlMethodComment>Principal select</SqlMethodComment>
    <Sql>
    <![CDATA[
        update c_debt_payment
           set c_Settlement_Cancel_ID = TO_NUMBER(?)
        where c_debt_payment_id in (select c_debt_payment_cancelled
                                      from c_remittanceLine 
                                     where c_RemittanceLine_ID = TO_NUMBER(?)
                                     union
                                    select c_debt_payment_id
                                      from c_remittanceLine 
                                     where c_RemittanceLine_ID = TO_NUMBER(?))
      ]]></Sql>
    <Parameter name="cSettlementID"/>
    <Parameter name="cRemittanceLine"/>
    <Parameter name="cRemittanceLine"/>
  </SqlMethod>


  <SqlMethod name="returnDPOriginal" connection="true" type="preparedStatement" return="rowCount">
    <SqlMethodComment>Principal select</SqlMethodComment>
    <Sql>
    <![CDATA[
         insert into C_DP_ManagementLine
           (C_DP_MANAGEMENTLINE_ID, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED, CREATEDBY, UPDATED, UPDATEDBY, 
            C_DP_MANAGEMENT_ID, STATUS_FROM, STATUS_TO, C_DEBT_PAYMENT_ID, LINE)
         values
           (?,?, ?, 'Y', now(), ?, now(), ?, 
            ?, (select dp.status
                        from c_debt_payment dp,
                             c_remittanceLine rl
                       where c_RemittanceLine_ID = TO_NUMBER(?)
                         and dp.c_debt_payment_id = rl.c_debt_payment_id), 
                     (select STATUS_RETURNED
                        from c_remittanceLine rl,
                             c_remittance r,
                             c_remittance_type rt
                       where rl.c_remittance_id = r.c_remittance_id
                         and r.c_remittance_type_id  = rt.c_remittance_type_id
                         and rl.c_RemittanceLine_ID = TO_NUMBER(?)),
                     (select c_debt_payment_id
                        from c_remittanceLine rl
                       where c_RemittanceLine_ID = TO_NUMBER(?)), ?)
      ]]></Sql>
    <Parameter name="LID"/>
    <Parameter name="client"/>
    <Parameter name="org"/>
    <Parameter name="user"/>
    <Parameter name="user"/>
    <Parameter name="DPMId"/>
    <Parameter name="cRemittanceLine"/>
    <Parameter name="cRemittanceLine"/>
    <Parameter name="cRemittanceLine"/>
	<Parameter name="line"/>
  </SqlMethod>

    <SqlMethod name="returnDPGenerated" connection="true" type="preparedStatement" return="rowCount">
    <SqlMethodComment>Principal select</SqlMethodComment>
    <Sql>
    <![CDATA[
         insert into C_DP_ManagementLine
           (C_DP_MANAGEMENTLINE_ID, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED, CREATEDBY, UPDATED, UPDATEDBY, 
            C_DP_MANAGEMENT_ID, STATUS_FROM, STATUS_TO, C_DEBT_PAYMENT_ID, LINE)
         values
           (?,?, ?, 'Y', now(), ?, now(), ?, 
            ?, (select dp.status
                        from c_debt_payment dp,
                             c_remittanceLine rl
                       where c_RemittanceLine_ID = TO_NUMBER(?)
                         and dp.c_debt_payment_id = rl.C_DEBT_PAYMENT_CANCELLED), 
                     (select STATUS_RETURNED
                        from c_remittanceLine rl,
                             c_remittance r,
                             c_remittance_type rt
                       where rl.c_remittance_id = r.c_remittance_id
                         and r.c_remittance_type_id  = rt.c_remittance_type_id
                         and rl.c_RemittanceLine_ID = TO_NUMBER(?)),
                     (select C_DEBT_PAYMENT_CANCELLED
                        from c_remittanceLine rl
                       where c_RemittanceLine_ID = TO_NUMBER(?)), ?)
      ]]></Sql>
    <Parameter name="LID"/>
    <Parameter name="client"/>
    <Parameter name="org"/>
    <Parameter name="user"/>
    <Parameter name="user"/>
    <Parameter name="DPMId"/>
    <Parameter name="cRemittanceLine"/>
    <Parameter name="cRemittanceLine"/>
    <Parameter name="cRemittanceLine"/>
    <Parameter name="line"/>
  </SqlMethod>

  <SqlMethod name="selectLineNo" type="preparedStatement" return="rowCount">
    <Sql>
      <![CDATA[
          SELECT COALESCE(MAX(LINE),0) AS LINE
            FROM C_REMITTANCELINE 
           WHERE C_REMITTANCE_ID = TO_NUMBER(?)
        ]]>
    </Sql>
    <Parameter name="remittaceID"/>
   </SqlMethod>


  <SqlMethod name="setReturned" connection="true" type="preparedStatement" return="rowCount">
    <SqlMethodComment>Principal select</SqlMethodComment>
    <Sql>
    <![CDATA[
        update c_RemittanceLine
           set returned = 'Y'
         where c_RemittanceLine_ID = TO_NUMBER(?)
      ]]></Sql>
    <Parameter name="cRemittanceLineID"/>
  </SqlMethod>


  <SqlMethod name="process800140" connection="true" type="callableStatement" return="object" object="RemittanceCancelData">
      <SqlMethodComment>procedure C_DP_Management_Post</SqlMethodComment>
      <Sql><![CDATA[
        CALL C_DP_Management_Post(TO_NUMBER(?), NULL)
      ]]></Sql>
      <Parameter name="adPinstanceId"></Parameter>
   </SqlMethod>

   <SqlMethod name="process800025" connection="true" type="callableStatement" return="object" object="RemittanceCancelData">
      <SqlMethodComment>procedure C_Settlement_Post0</SqlMethodComment>
      <Sql><![CDATA[
        CALL C_Settlement_Post(NULL, TO_NUMBER(?))
      ]]></Sql>
      <Parameter name="cSettlementId"></Parameter>
   </SqlMethod>

    <SqlMethod name="getLineDPM" type="preparedStatement" return="String">
    <SqlMethodComment></SqlMethodComment>
    <Sql>
      <![CDATA[
	    SELECT COALESCE(MAX(LINE),0) AS LINE
		  FROM C_DP_ManagementLine
		 WHERE C_DP_MANAGEMENT_ID = TO_NUMBER(?)
      ]]>
    </Sql>
    <Parameter name="dpmId"/>
  </SqlMethod>

</SqlClass>