src/org/openbravo/erpCommon/ad_actionButton/CreateFrom_Bank_data.xsql
author Asier Lostalé <asier.lostale@openbravo.com>
Mon, 05 May 2008 06:59:24 +0000
changeset 799 fef2c5e2feb7
parent 423 ecf368072c48
child 939 bb675e064cce
permissions -rw-r--r--
Merged cleanup branch (r3931) with trunk
<?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="CreateFromBankData" package="org.openbravo.erpCommon.ad_actionButton">
  <SqlMethod name="select" type="preparedStatement" return="multiple">
    <SqlMethodComment></SqlMethodComment>
    <Sql>
      <![CDATA[
        SELECT p.DatePlanned, p.C_DEBT_Payment_ID, 
        (CASE Ad_Column_Identifier(to_char('C_Debt_Payment'), to_char(p.C_DEBT_Payment_ID), to_char(?)) WHEN '**' THEN to_char(p.description) ELSE to_char(Ad_Column_Identifier(to_char('C_Debt_Payment'), to_char(p.C_DEBT_Payment_ID), to_char(?))) END) AS DEBT_PAYMENT, 
        p.C_Currency_ID,c.ISO_Code AS CURRENCY, p.Amount - p.WriteOffAmt AS AMOUNT, p.Amount - p.WriteOffAmt AS AMOUNT2,
        C_Currency_Convert(p.Amount,p.C_Currency_ID,ba.C_Currency_ID,to_date(?),to_char(null),p.AD_Client_ID,p.AD_Org_ID) AS CONVERTED, 
        Ad_Column_Identifier(to_char('C_BankAccount'), to_char(ba.C_BankAccount_ID), to_char(?)) AS BANK, o.Name AS Org,
        Ad_Column_Identifier(to_char('C_Invoice'), to_char(p.C_INVOICE_ID), to_char(?)) AS INVOICE
        FROM C_DEBT_Payment_v p left join C_BankAccount ba on p.C_BankAccount_ID = ba.C_BankAccount_ID
                                left join C_Bank bk        on ba.C_Bank_ID = bk.C_Bank_ID
                                left join C_BPARTNER b     on p.C_BPARTNER_ID = b.C_BPARTNER_ID
                                left join AD_REF_LIST_V l  on p.PAYMENTRULE = l.VALUE
                                                           and l.AD_LANGUAGE  = ? 
                                                           AND l.AD_REFERENCE_ID = 195, 
         C_Currency c,  AD_Org o 
        where p.C_Currency_ID=c.C_Currency_ID 
        AND p.IsActive = 'Y' 
        AND p.AD_Org_ID = o.AD_Org_ID 
        AND p.AD_CLIENT_ID IN ('1') 
        AND p.AD_ORG_ID IN ('1') 
        AND C_DEBT_PAYMENT_STATUS(p.C_Settlement_Cancel_ID, p.Cancel_Processed, p.Generate_Processed, 
        p.IsPaid, p.IsValid, p.C_CashLine_ID, p.C_BankStatementLine_ID) IN ('P', 'A') 
        AND NOT EXISTS (SELECT * FROM C_BankStatementLine l WHERE p.C_DEBT_Payment_ID=l.C_DEBT_PAYMENT_ID) 
        ORDER BY p.DATEPLANNED DESC
      ]]>
    </Sql>
    <Parameter name="adLanguage"/>
    <Parameter name="adLanguage"/>
    <Parameter name="statementdate"/>
    <Parameter name="adLanguage"/>
    <Parameter name="adLanguage"/>
    <Parameter name="userClient" optional="true" type="replace" after="AND p.AD_CLIENT_ID IN (" text="'1'"/>
    <Parameter name="userOrg" optional="true" type="replace" after="AND p.AD_ORG_ID IN (" text="'1'"/>
    <Parameter name="adLanguage"/>
    <Parameter name="cBPartnerId" optional="true" after="AND NOT EXISTS (SELECT * FROM C_BankStatementLine l WHERE p.C_DEBT_Payment_ID=l.C_DEBT_PAYMENT_ID)" text=" AND p.C_BPARTNER_ID = TO_NUMBER(?) "/>
    <Parameter name="paymentrule" optional="true" after="AND NOT EXISTS (SELECT * FROM C_BankStatementLine l WHERE p.C_DEBT_Payment_ID=l.C_DEBT_PAYMENT_ID)" text=" AND p.PAYMENTRULE = ? "/>
    <Parameter name="planneddateFrom" optional="true" after="AND NOT EXISTS (SELECT * FROM C_BankStatementLine l WHERE p.C_DEBT_Payment_ID=l.C_DEBT_PAYMENT_ID)"><![CDATA[ AND p.DATEPLANNED >= TO_DATE(?) ]]></Parameter>
    <Parameter name="planneddateTo" optional="true" after="AND NOT EXISTS (SELECT * FROM C_BankStatementLine l WHERE p.C_DEBT_Payment_ID=l.C_DEBT_PAYMENT_ID)"><![CDATA[ AND p.DATEPLANNED <= TO_DATE(?) ]]></Parameter>
    <Parameter name="amountFrom" optional="true" after="AND NOT EXISTS (SELECT * FROM C_BankStatementLine l WHERE p.C_DEBT_Payment_ID=l.C_DEBT_PAYMENT_ID)"><![CDATA[ AND p.AMOUNT >= ? ]]></Parameter>
    <Parameter name="amountTo" optional="true" after="AND NOT EXISTS (SELECT * FROM C_BankStatementLine l WHERE p.C_DEBT_Payment_ID=l.C_DEBT_PAYMENT_ID)"><![CDATA[ AND p.AMOUNT <= ? ]]></Parameter>
    <Parameter name="isreceipt" optional="true" after="AND NOT EXISTS (SELECT * FROM C_BankStatementLine l WHERE p.C_DEBT_Payment_ID=l.C_DEBT_PAYMENT_ID)" text=" AND p.ISRECEIPT = ? "/>
    <Parameter name="cBankaccountId" optional="true" after="AND NOT EXISTS (SELECT * FROM C_BankStatementLine l WHERE p.C_DEBT_Payment_ID=l.C_DEBT_PAYMENT_ID)" text=" AND p.C_BankAccount_ID = TO_NUMBER(?) "/>
    <Parameter name="adOrgId" optional="true" after="AND NOT EXISTS (SELECT * FROM C_BankStatementLine l WHERE p.C_DEBT_Payment_ID=l.C_DEBT_PAYMENT_ID)" text=" AND p.AD_ORG_ID = TO_NUMBER(?) "/>
    <Parameter name="ischarge" optional="true" after="AND NOT EXISTS (SELECT * FROM C_BankStatementLine l WHERE p.C_DEBT_Payment_ID=l.C_DEBT_PAYMENT_ID)" text=" AND p.ISPAID = ? "/>
    <Parameter name="invoice" optional="true" after="AND NOT EXISTS (SELECT * FROM C_BankStatementLine l WHERE p.C_DEBT_Payment_ID=l.C_DEBT_PAYMENT_ID)" text=" AND EXISTS (SELECT 1 FROM C_INVOICE WHERE p.C_INVOICE_ID = C_INVOICE.C_INVOICE_ID AND DOCUMENTNO LIKE TO_CHAR(?))"/>
  </SqlMethod>

  <SqlMethod name="NotIsReconcilied" type="preparedStatement" connection="true" return="boolean">
    <SqlMethodComment></SqlMethodComment>
    <Sql>
      <![CDATA[
        SELECT COUNT(*) 
        FROM C_DEBT_Payment_v p 
        WHERE p.C_Debt_Payment_ID = TO_NUMBER(?) 
        AND C_DEBT_PAYMENT_STATUS(p.C_Settlement_Cancel_ID, p.Cancel_Processed, p.Generate_Processed, 
        p.IsPaid, p.IsValid, p.C_CashLine_ID, p.C_BankStatementLine_ID) IN ('P', 'A') 
        AND NOT EXISTS (SELECT * FROM C_BankStatementLine l WHERE p.C_DEBT_Payment_ID=l.C_DEBT_PAYMENT_ID)
      ]]>
    </Sql>
    <Parameter name="cDebtPaymentId"/>
  </SqlMethod>
  <SqlMethod name="bpartner" type="preparedStatement" return="String" default="">
    <SqlMethodComment></SqlMethodComment>
    <Sql>
      SELECT NAME FROM C_BPARTNER WHERE C_BPARTNER_ID = TO_NUMBER(?)
    </Sql>
    <Parameter name="cBpartnerId"/>
  </SqlMethod>
  <SqlMethod name="insert" connection="true" type="preparedStatement" return="rowCount">
    <SqlMethodComment></SqlMethodComment>
    <Sql>
      <![CDATA[
        INSERT INTO C_BankStatementLine 
            (C_BankStatementLine_ID, AD_Client_ID,AD_Org_ID,
            IsActive,Created,CreatedBy,
            Updated,UpdatedBy, C_BankStatement_ID,
            DateAcct,ValutaDate,
            C_Debt_Payment_ID, Description, 
            TrxAmt,
            ChargeAmt, 
            C_Currency_ID,
            StmtAmt) 
        SELECT TO_NUMBER(?),TO_NUMBER(?),p.AD_ORG_ID, 
               'Y', now(), TO_NUMBER(?), 
               now(), TO_NUMBER(?), TO_NUMBER(?), 
               TO_DATE(?), TO_DATE(?), (SELECT (COALESCE(Max(Line),0))+10 FROM C_BankStatementLine WHERE C_BankStatement_ID = TO_NUMBER(?)), 'N', 
               p.C_Debt_Payment_ID, Description, 
               C_Currency_Convert(p.Amount,p.C_Currency_ID, (SELECT A.C_CURRENCY_ID
                                                              FROM C_BANKSTATEMENT S, C_BANKACCOUNT A 
                                                              WHERE S.C_BANKACCOUNT_ID = A.C_BANKACCOUNT_ID 
                                                              AND S.C_BankStatement_ID = TO_NUMBER(?)),TO_DATE(?),null,p.AD_Client_ID,p.AD_Org_ID),
               TO_NUMBER(?),
               (SELECT A.C_CURRENCY_ID
                  FROM C_BANKSTATEMENT S, C_BANKACCOUNT A 
                  WHERE S.C_BANKACCOUNT_ID = A.C_BANKACCOUNT_ID 
                  AND S.C_BankStatement_ID = TO_NUMBER(?)), 
               C_Currency_Convert(p.Amount,p.C_Currency_ID, (SELECT A.C_CURRENCY_ID
                                                                              FROM C_BANKSTATEMENT S, C_BANKACCOUNT A 
                                                                              WHERE S.C_BANKACCOUNT_ID = A.C_BANKACCOUNT_ID 
                                                                              AND S.C_BankStatement_ID = TO_NUMBER(?)),TO_DATE(?),null,p.AD_Client_ID,p.AD_Org_ID)- TO_NUMBER(?)
        FROM C_Debt_Payment_v p 
        WHERE p.C_Debt_Payment_ID = TO_NUMBER(?)
      ]]>
    </Sql>
    <Parameter name="cBankstatementlineId"/>
    <Parameter name="adClientId"/>
    <Parameter name="adUserId"/>
    <Parameter name="adUserId"/>
    <Parameter name="cBankstatementId"/>
    <Parameter name="statementdate"/>
    <Parameter name="statementdate"/>
    <Parameter name="cBankstatementId"/>

    <Parameter name="cBankstatementId"/>
    <Parameter name="statementdate"/>

    <Parameter name="cChargeAmt"/>
    

    <Parameter name="cBankstatementId"/>

    
    <Parameter name="cBankstatementId"/>
    <Parameter name="statementdate"/>
    <Parameter name="cChargeAmt"/>

    <Parameter name="cPaymentId"/>
  </SqlMethod>
  </SqlClass>