src-db/database/model/functions/C_DEBT_PAYMENT_CHANGE.xml
author Juan Pablo Aroztegi <juanpablo.aroztegi@openbravo.com>
Wed, 03 Sep 2008 17:55:37 +0000
changeset 1605 8a0fe0193bef
parent 923 ba61ef9e3c19
child 2586 683779f1e610
permissions -rw-r--r--
Merge r2.5x intro trunk
<?xml version="1.0"?>
  <database name="FUNCTION C_DEBT_PAYMENT_CHANGE">
    <function name="C_DEBT_PAYMENT_CHANGE" type="NULL">
      <parameter name="p_pinstance_id" type="VARCHAR" mode="in">
        <default/>
      </parameter>
      <body><![CDATA[/*************************************************************************
* 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):  ______________________________________.
************************************************************************/
  --  Logistice
  v_ResultStr VARCHAR2(2000):='';
  v_Message VARCHAR2(2000):='';
  v_Result NUMBER:=1; -- 0=failure
  v_Record_ID VARCHAR2(32) ;
  v_AD_User_ID VARCHAR2(32) ;
  --  Parameter
  TYPE RECORD IS REF CURSOR;
    Cur_Parameter RECORD;
    --  Parameter Variables
    v_Aux NUMBER;
    v_GetOutSettlement CHAR(1):='N';
    v_IsPaid CHAR(1) ;
    v_WriteOffAmt NUMBER;
    FINISH_PROCESS BOOLEAN:=false;
  BEGIN
    --  Update AD_PInstance
    DBMS_OUTPUT.PUT_LINE('Updating PInstance - Processing ' || p_PInstance_ID) ;
    v_ResultStr:='PInstanceNotFound';
    AD_UPDATE_PINSTANCE(p_PInstance_ID, NULL, 'Y', NULL, NULL) ;
  BEGIN --BODY
    --  Get Parameters
    v_ResultStr:='ReadingParameters';
    FOR Cur_Parameter IN
      (SELECT i.Record_ID,
        p.ParameterName,
        p.P_String,
        p.P_Number,
        p.P_Date,
        i.AD_USER_ID
      FROM AD_PInstance i
      LEFT JOIN AD_PInstance_Para p
        ON i.AD_PInstance_ID=p.AD_PInstance_ID
      WHERE i.AD_PInstance_ID=p_PInstance_ID
      ORDER BY p.SeqNo
      )
    LOOP
      v_Record_ID:=Cur_Parameter.Record_ID;
      v_AD_User_ID:=Cur_Parameter.AD_User_ID;
      IF(Cur_Parameter.ParameterName='GetOutSettlement') THEN
        v_GetOutSettlement:=Cur_Parameter.P_String;
        DBMS_OUTPUT.PUT_LINE('  GetOutSettlement=' || v_GetOutSettlement) ;
      ELSIF(Cur_Parameter.ParameterName='CheckIsPaid') THEN
        v_IsPaid:=Cur_Parameter.P_String;
        DBMS_OUTPUT.PUT_LINE('  IsPaid=' || v_IsPaid) ;
      ELSIF(Cur_Parameter.ParameterName='NewWriteOffAmt') THEN
        v_WriteOffAmt:=Cur_Parameter.P_Number;
        DBMS_OUTPUT.PUT_LINE('  WriteOffAmt=' || v_WriteOffAmt) ;
      ELSE
        DBMS_OUTPUT.PUT_LINE('*** Unknown Parameter=' || Cur_Parameter.ParameterName) ;
      END IF;
    END LOOP; --  Get Parameter
    DBMS_OUTPUT.PUT_LINE('  Record_ID=' || v_Record_ID) ;
    /*
    *  Checking Restrictions
    */
    v_ResultStr:='CheckingRestrictions';
    SELECT COUNT(*)
    INTO v_Aux
    FROM C_Debt_Payment p
    WHERE p.C_Debt_Payment_ID=v_Record_ID
      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('I', 'P') ;
    IF v_Aux=0 THEN
      RAISE_APPLICATION_ERROR(-20000, '@DebtPaymentNotPending@');
    END IF;
    IF(NOT FINISH_PROCESS) THEN
      IF(v_GetOutSettlement='Y') THEN
        UPDATE C_DEBT_PAYMENT
          SET UPDATED=now(),
          UPDATEDBY=v_AD_User_ID,
          ISPAID='N',
          C_SETTLEMENT_CANCEL_ID=NULL,
          WRITEOFFAMT=0
        WHERE C_Debt_Payment_ID=v_Record_ID;
      ELSE
        UPDATE C_DEBT_PAYMENT
          SET UPDATED=now(),
          UPDATEDBY=v_AD_User_ID,
          -- ISPAID=v_IsPaid,
          WRITEOFFAMT=v_WriteOffAmt
        WHERE C_Debt_Payment_ID=v_Record_ID;
      END IF;
    END IF; --FINISH_PROCESS
    --<<FINISH_PROCESS>>
    --  Update AD_PInstance
    DBMS_OUTPUT.PUT_LINE('Updating PInstance - Finished ' || v_Message) ;
    AD_UPDATE_PINSTANCE(p_PInstance_ID, NULL, 'N', v_Result, v_Message) ;
    RETURN;
  END; --BODY
EXCEPTION
WHEN OTHERS THEN
  v_ResultStr:= '@ERROR=' || SQLERRM;
  DBMS_OUTPUT.PUT_LINE(v_ResultStr) ;
  ROLLBACK;
  AD_UPDATE_PINSTANCE(p_PInstance_ID, NULL, 'N', 0, v_ResultStr) ;
  RETURN;
END C_DEBT_PAYMENT_CHANGE
]]></body>
    </function>
  </database>