src-db/database/model/functions/C_TAXPAYMENT_POST.xml
author Juan Pablo Aroztegi <juanpablo.aroztegi@openbravo.com>
Wed, 03 Sep 2008 17:55:37 +0000
changeset 1605 8a0fe0193bef
parent 1349 ffd9daaff911
child 1628 3bc8670b937f
permissions -rw-r--r--
Merge r2.5x intro trunk
juanpablo@728
     1
<?xml version="1.0"?>
juanpablo@728
     2
  <database name="FUNCTION C_TAXPAYMENT_POST">
juanpablo@728
     3
    <function name="C_TAXPAYMENT_POST" type="NULL">
juanpablo@1605
     4
      <parameter name="p_pinstance_id" type="VARCHAR" mode="in">
antonio@735
     5
        <default/>
antonio@735
     6
      </parameter>
carlos@730
     7
      <body><![CDATA[/*************************************************************************
carlos@730
     8
* The contents of this file are subject to the Openbravo  Public  License
carlos@730
     9
* Version  1.0  (the  "License"),  being   the  Mozilla   Public  License
carlos@730
    10
* Version 1.1  with a permitted attribution clause; you may not  use this
carlos@730
    11
* file except in compliance with the License. You  may  obtain  a copy of
carlos@730
    12
* the License at http://www.openbravo.com/legal/license.html
carlos@730
    13
* Software distributed under the License  is  distributed  on  an "AS IS"
carlos@730
    14
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
carlos@730
    15
* License for the specific  language  governing  rights  and  limitations
carlos@730
    16
* under the License.
carlos@730
    17
* The Original Code is Openbravo ERP.
carlos@730
    18
* The Initial Developer of the Original Code is Openbravo SL
carlos@730
    19
* All portions are Copyright (C) 2001-2008 Openbravo SL
carlos@730
    20
* All Rights Reserved.
carlos@730
    21
* Contributor(s):  ______________________________________.
carlos@730
    22
************************************************************************/
carlos@730
    23
v_resultstr VARCHAR2(2000) := '';
eduardo@723
    24
v_message VARCHAR2(200) := '';
juanpablo@1605
    25
v_record_ID VARCHAR2(32);
antonio@735
    26
v_result NUMBER:= 1;
eduardo@723
    27
-- Success
eduardo@723
    28
v_total NUMBER;
juanpablo@1605
    29
v_c_settlement_cancel_ID VARCHAR2(32);
eduardo@723
    30
-- Parameter
antonio@735
    31
TYPE record IS REF CURSOR;
eduardo@723
    32
cur_parameter record;
eduardo@723
    33
cur_registertype record;
eduardo@723
    34
cur_line record;
eduardo@723
    35
-- Record Info
juanpablo@1605
    36
v_client_ID VARCHAR2(32);
juanpablo@1605
    37
v_org_ID VARCHAR2(32);
eduardo@723
    38
v_updatedby c_taxpayment.updatedby%TYPE;
eduardo@723
    39
v_createdby c_taxpayment.createdby%TYPE;
eduardo@723
    40
v_processed c_taxpayment.processed%TYPE;
eduardo@723
    41
antonio@735
    42
v_taxtotalamt NUMBER;
antonio@735
    43
v_prevvatcredit NUMBER;
antonio@735
    44
v_paymentamt NUMBER;
antonio@735
    45
v_paymentcreditamt NUMBER;
antonio@735
    46
v_paymentdebitamt NUMBER;
eduardo@723
    47
v_isreceipt VARCHAR2(1);
eduardo@723
    48
v_ispayment VARCHAR2(1);
eduardo@1349
    49
v_posted VARCHAR2(1);
eduardo@723
    50
antonio@735
    51
v_taxamtfromreglines NUMBER;
eduardo@723
    52
antonio@735
    53
v_taxregistertotal NUMBER;
eduardo@723
    54
eduardo@723
    55
v_date DATE;
juanpablo@1605
    56
v_settlementid varchar2(32);
juanpablo@1605
    57
v_settlementdoctype_ID VARCHAR2(32);
eduardo@723
    58
v_sdocumentno NUMBER;
juanpablo@1605
    59
v_debtpaymentid varchar2(32);
juanpablo@1605
    60
v_debtpaymentbalancingid varchar2(32);
eduardo@723
    61
v_paymentrule VARCHAR2(30);
juanpablo@1605
    62
v_bpartner_ID VARCHAR2(32);
eduardo@723
    63
eduardo@723
    64
juanpablo@1605
    65
v_gl_journalbatchid varchar2(32);
antonio@735
    66
v_gljbdocumentno NUMBER;
juanpablo@1605
    67
v_gl_journaldoctype_ID VARCHAR2(32);
juanpablo@1605
    68
v_gl_journalid varchar2(32);
antonio@735
    69
v_gljdocumentno NUMBER;
juanpablo@1605
    70
v_gl_journallineid varchar2(32);
antonio@735
    71
v_line NUMBER;
juanpablo@1605
    72
v_validcombination_ID VARCHAR2(32);
eduardo@723
    73
antonio@735
    74
v_glitem_acct NUMBER;
juanpablo@1605
    75
v_glitem_ID VARCHAR2(32);
eduardo@723
    76
antonio@735
    77
v_debit NUMBER;
antonio@735
    78
v_credit NUMBER;
antonio@735
    79
 v_totaldebit NUMBER;
antonio@735
    80
v_totalcredit NUMBER;
eduardo@723
    81
eduardo@723
    82
juanpablo@1605
    83
v_acctschema_ID VARCHAR2(32);
juanpablo@1605
    84
v_currency_ID VARCHAR2(32);
antonio@737
    85
v_currencyratetype VARCHAR2(30);
juanpablo@1605
    86
v_gl_category_ID VARCHAR2(32);
juanpablo@1605
    87
v_period_ID VARCHAR2(32);
eduardo@723
    88
antonio@737
    89
v_name NVARCHAR2(255);
eduardo@1349
    90
v_TRTcountY  NUMBER;
eduardo@1349
    91
v_TRTcountN  NUMBER;
juanpablo@1605
    92
v_DBA_ErrorLog_ID VARCHAR2(32);
eduardo@723
    93
eduardo@723
    94
eduardo@723
    95
eduardo@723
    96
eduardo@723
    97
eduardo@723
    98
BEGIN
eduardo@723
    99
  --  Update AD_PInstance
eduardo@723
   100
    DBMS_OUTPUT.PUT_LINE('Updating PInstance - Processing ' || p_pinstance_id);
eduardo@723
   101
    v_resultstr := 'PInstanceNotFound';
antonio@735
   102
    AD_UPDATE_PINSTANCE(p_pinstance_id,   NULL,   'Y',   NULL,   NULL);
eduardo@723
   103
    -- Get Parameters
eduardo@723
   104
    v_resultstr := 'ReadingParameters';
eduardo@723
   105
    FOR cur_parameter IN
eduardo@723
   106
      (SELECT i.record_id,
eduardo@723
   107
         i.ad_user_id,
eduardo@723
   108
         p.parametername,
eduardo@723
   109
         p.p_string,
eduardo@723
   110
         p.p_number,
eduardo@723
   111
         p.p_date
eduardo@723
   112
       FROM ad_pinstance i LEFT JOIN ad_pinstance_para p ON i.ad_pinstance_id = p.ad_pinstance_id
eduardo@723
   113
       WHERE i.ad_pinstance_id = p_pinstance_id
eduardo@723
   114
       ORDER BY p.seqno)
eduardo@723
   115
    LOOP
eduardo@723
   116
      v_record_id := cur_parameter.record_id;
eduardo@723
   117
    END LOOP;
eduardo@723
   118
eduardo@723
   119
    -- Get Parameter
eduardo@723
   120
    DBMS_OUTPUT.PUT_LINE('  v_Record_ID=' || v_record_id);
antonio@737
   121
eduardo@723
   122
    BEGIN
eduardo@723
   123
      -- BODY
antonio@737
   124
antonio@737
   125
      select dateto, ad_client_id, ad_org_id, createdby, updatedby, generatepayment, c_acctschema_id, c_currency_id, name, C_BPARTNER_ID, processed
antonio@737
   126
        into v_date, v_client_id, v_org_id, v_createdby, v_updatedby, v_ispayment, v_acctschema_id, v_currency_id, v_name, v_bpartner_id, v_processed
eduardo@723
   127
        from c_taxpayment
eduardo@723
   128
        where c_taxpayment_id=v_record_id;
antonio@737
   129
eduardo@1349
   130
      select max(gl_category_id)
antonio@737
   131
      into v_gl_category_id
antonio@737
   132
      from gl_category where name='Standard';
antonio@737
   133
antonio@737
   134
        v_paymentrule := 'T';
eduardo@723
   135
        v_currencyratetype := 'S';
antonio@737
   136
eduardo@723
   137
      select c_period_id into v_period_id from c_period
eduardo@723
   138
      where enddate = (select max(enddate) from c_period where enddate <=v_date);
antonio@737
   139
eduardo@723
   140
     --start processing
antonio@737
   141
eduardo@723
   142
     update c_taxpayment
eduardo@723
   143
     set processing='Y' where c_taxpayment_id=v_record_id;
antonio@737
   144
eduardo@723
   145
     --unprocess
eduardo@723
   146
     if v_processed='Y' then
eduardo@723
   147
      begin
antonio@737
   148
eduardo@723
   149
      select tp.gl_journal_id ,  gljb.gl_journalbatch_id, tp.c_settlement_id
eduardo@723
   150
      into v_gl_journalid, v_gl_journalbatchid, v_settlementid
eduardo@723
   151
      from c_taxpayment tp
eduardo@723
   152
      inner join gl_journal glj on tp.gl_journal_id=glj.gl_journal_id
eduardo@723
   153
      inner join gl_journalbatch gljb on gljb.gl_journalbatch_id=glj.gl_journal_id
eduardo@723
   154
      where tp.C_TAXPAYMENT_ID = v_record_id;
antonio@737
   155
eduardo@723
   156
      update gl_journal set docaction='RE' where gl_journal_id=v_gl_journalid;
eduardo@1349
   157
      select posted into v_posted from gl_journal where gl_journal_id=v_gl_journalid;
eduardo@1349
   158
      if v_posted = 'Y' then
eduardo@1349
   159
       RAISE_APPLICATION_ERROR(-20000, '@GLJournalDocumentPosted@') ;
eduardo@1349
   160
       end if;
eduardo@723
   161
      GL_JOURNAL_POST(null, v_gl_journalid);
eduardo@723
   162
        update c_taxpayment set gl_journal_id=null where c_taxpayment.C_TAXPAYMENT_ID = v_record_id;
eduardo@723
   163
        delete from gl_journalline where gl_journal_id=v_gl_journalid;
eduardo@723
   164
        delete from gl_journal where gl_journal_id=v_gl_journalid;
eduardo@723
   165
        delete from gl_journalbatch where gl_journalbatch_id=v_gl_journalbatchid;
antonio@737
   166
eduardo@723
   167
      if v_ispayment = 'Y' then
eduardo@723
   168
        C_SETTLEMENT_POST(null, v_settlementid);
eduardo@723
   169
        update c_taxpayment set c_settlement_id=null where c_taxpayment.C_TAXPAYMENT_ID = v_record_id;
antonio@737
   170
        delete from c_debt_payment_balancing where c_debt_payment_id in
eduardo@723
   171
        (select c_debt_payment_id from c_debt_payment where c_settlement_generate_id = v_settlementid);
eduardo@723
   172
        delete from c_debt_payment where c_settlement_generate_id = v_settlementid;
eduardo@723
   173
        delete from c_settlement where c_settlement_id=v_settlementid;
eduardo@723
   174
        end if;
eduardo@723
   175
      end;
eduardo@723
   176
       update c_taxpayment set processed='N' where c_taxpayment.C_TAXPAYMENT_ID = v_record_id;
eduardo@723
   177
      end if;
antonio@737
   178
antonio@737
   179
eduardo@723
   180
   if v_processed='N' then
eduardo@723
   181
   begin
antonio@737
   182
      --gl journal
antonio@735
   183
        ad_sequence_next('GL_JournalBatch', v_record_id, v_gl_journalbatchid);
antonio@735
   184
        ad_sequence_doc('DocumentNo_GL_JournalBatch', v_client_id, 'Y', v_gljbdocumentno);
antonio@737
   185
antonio@737
   186
        insert
eduardo@723
   187
        into gl_journalbatch (gl_journalbatch_id,   ad_client_id,   ad_org_id,   isactive,   created,   createdby,   updated,   updatedby,   documentno, description, postingtype,   datedoc,   dateacct, c_period_id, c_currency_id)
antonio@737
   188
        values (v_gl_journalbatchid, v_client_id, v_org_id,'Y', now(), v_createdby, now(), v_updatedby, v_gljbdocumentno, v_name, 'A', v_date, v_date, v_period_id, v_currency_id);
antonio@737
   189
eduardo@723
   190
        v_gl_journaldoctype_id := ad_get_doctype(v_client_id,   v_org_id,   to_char('GLJ'));
antonio@735
   191
        ad_sequence_next('GL_Journal', v_record_id, v_gl_journalid);
antonio@735
   192
        ad_sequence_doctype(v_gl_journaldoctype_id, v_record_id, 'Y', v_gljdocumentno);
antonio@737
   193
antonio@737
   194
        insert
eduardo@723
   195
        into gl_journal (gl_journal_id,   ad_client_id,   ad_org_id,   isactive,   created,   createdby,   updated,   updatedby, c_acctschema_id, c_doctype_id, documentno, docstatus, docaction, isapproved,description, postingtype, gl_category_id,   datedoc,   dateacct, c_period_id, c_currency_id, currencyratetype, gl_journalbatch_id)
antonio@737
   196
        values (v_gl_journalid, v_client_id, v_org_id,'Y', now(), v_createdby, now(), v_updatedby, v_acctschema_id, v_gl_journaldoctype_id, v_gljdocumentno, 'DR', 'CO', 'Y', v_name, 'A', v_gl_category_id, v_date, v_date, v_period_id, v_currency_id, v_currencyratetype, v_gl_journalbatchid);
antonio@737
   197
eduardo@723
   198
      v_line:=0;
antonio@737
   199
      v_totaldebit:=0;
eduardo@723
   200
      v_totalcredit:=0;
antonio@737
   201
eduardo@723
   202
      for cur_line in
antonio@737
   203
      (select
eduardo@723
   204
      ttl.c_tax_id,
eduardo@723
   205
      tt.issotrx,
eduardo@723
   206
      case when tt.issotrx='Y' then max(ta.t_due_acct) else max(ta.t_credit_acct) end as acct_id
eduardo@723
   207
      from c_taxregister_type_lines ttl
eduardo@723
   208
      inner join c_taxregister_type tt on ttl.c_taxregister_type_id=tt.c_taxregister_type_id
eduardo@723
   209
      inner join c_tax_acct ta on ta.c_tax_id=ttl.c_tax_id
eduardo@723
   210
      where tt.isactive='Y' and ttl.isactive='Y' and ta.isactive='Y'
eduardo@723
   211
      group by ttl.c_tax_id, tt.issotrx )
antonio@737
   212
eduardo@723
   213
      loop --move the sum over
antonio@737
   214
antonio@737
   215
      select sum(trl.taxamt)
eduardo@723
   216
      into v_taxamtfromreglines
eduardo@723
   217
      from c_taxregisterline trl
eduardo@723
   218
      inner join c_taxregister tr on tr.c_taxregister_id=trl.c_taxregister_id
eduardo@723
   219
      inner join c_taxregister_type trt on trt.c_taxregister_type_id=tr.c_taxregister_type_id
eduardo@723
   220
      where trl.c_tax_id=cur_line.c_tax_id
eduardo@723
   221
      and trt.issotrx=cur_line.issotrx
eduardo@723
   222
      and tr.c_taxpayment_id=v_record_id;
antonio@737
   223
antonio@735
   224
      ad_sequence_next('GL_JournalLine', v_record_id, v_gl_journallineid);
antonio@737
   225
antonio@737
   226
eduardo@723
   227
      if v_taxamtfromreglines is null then
eduardo@723
   228
      v_taxamtfromreglines := 0;
eduardo@723
   229
      end if;
antonio@737
   230
eduardo@723
   231
      if cur_line.issotrx='N'  then
eduardo@723
   232
      v_credit := v_taxamtfromreglines;
eduardo@723
   233
      v_debit := 0;
eduardo@723
   234
      else
eduardo@723
   235
      v_credit := 0;
eduardo@723
   236
      v_debit := v_taxamtfromreglines;
eduardo@723
   237
      end if;
antonio@737
   238
eduardo@723
   239
      if v_taxamtfromreglines <> 0 then
eduardo@723
   240
      begin
eduardo@723
   241
      v_line := v_line + 10;
antonio@737
   242
      insert
eduardo@723
   243
      into gl_journalline(gl_journalline_id,   ad_client_id,   ad_org_id,   isactive,   created,   createdby,   updated,   updatedby, gl_journal_id, line, c_currency_id, currencyratetype, dateacct, c_validcombination_id, AMTSOURCEDR, AMTSOURCECR, AMTACCTDR, AMTACCTCR)
eduardo@723
   244
      values
antonio@737
   245
      (v_gl_journallineid, v_client_id, v_org_id,'Y', now(), v_createdby, now(), v_updatedby, v_gl_journalid, v_line, v_currency_id, v_currencyratetype, v_date, cur_line.acct_id, v_debit, v_credit, v_debit, v_credit);
eduardo@723
   246
      end;
eduardo@723
   247
      end if;
antonio@737
   248
eduardo@723
   249
      v_totaldebit := v_totaldebit+v_credit;
eduardo@723
   250
      v_totalcredit := v_totalcredit+v_debit;
antonio@737
   251
eduardo@723
   252
      end loop;
eduardo@1349
   253
      
eduardo@1349
   254
      select count(*) 
eduardo@1349
   255
      into v_TRTcountY
eduardo@1349
   256
      from c_taxregister_type tt where tt.issotrx='Y';
eduardo@1349
   257
      
eduardo@1349
   258
      select count(*) 
eduardo@1349
   259
      into v_TRTcountN
eduardo@1349
   260
      from c_taxregister_type tt where tt.issotrx='N';
eduardo@1349
   261
      
eduardo@1349
   262
      if v_TRTcountY=0 or v_TRTcountN=0 then
eduardo@1349
   263
      RAISE_APPLICATION_ERROR(-20100, '@TwoRegisterTypesNeeded@');
eduardo@1349
   264
      end if;
eduardo@1349
   265
      
eduardo@723
   266
      select case when tt.issotrx='Y' then max(glitem_debit_acct) else max(glitem_credit_acct) end, max(tt.c_glitem_id)
eduardo@723
   267
      into v_glitem_acct, v_glitem_id
eduardo@723
   268
      from c_taxregister_type tt
eduardo@723
   269
      inner join c_glitem_acct gia on gia.c_glitem_id=tt.c_glitem_id
eduardo@723
   270
      where tt.isactive='Y' and gia.isactive='Y' and tt.issotrx= case when v_totalcredit - v_totaldebit > 0 then 'N' else 'Y' end
eduardo@723
   271
      group by tt.issotrx;
antonio@737
   272
antonio@737
   273
      if v_totalcredit - v_totaldebit > 0
eduardo@723
   274
      then
eduardo@723
   275
       v_totalcredit := v_totalcredit - v_totaldebit;
eduardo@723
   276
       v_totaldebit := 0;
eduardo@723
   277
       else
eduardo@723
   278
       v_totaldebit := v_totaldebit - v_totalcredit;
eduardo@723
   279
        v_totalcredit := 0;
eduardo@723
   280
        end if;
antonio@737
   281
eduardo@723
   282
      v_line := v_line + 10;
antonio@735
   283
      ad_sequence_next('GL_JournalLine', v_record_id, v_gl_journallineid);
antonio@737
   284
     insert
eduardo@723
   285
     into gl_journalline(gl_journalline_id,   ad_client_id,   ad_org_id,   isactive,   created,   createdby,   updated,   updatedby, gl_journal_id,    line, c_currency_id, currencyratetype, dateacct, c_validcombination_id, AMTSOURCEDR, AMTSOURCECR, AMTACCTDR, AMTACCTCR)
eduardo@723
   286
                 values (v_gl_journallineid,   v_client_id,      v_org_id,        'Y',     now(), v_createdby,   now(), v_updatedby, v_gl_journalid, v_line, v_currency_id, v_currencyratetype, v_date, v_glitem_acct, v_totaldebit, v_totalcredit, v_totaldebit, v_totalcredit);
antonio@737
   287
eduardo@723
   288
    GL_JOURNAL_POST(null, v_gl_journalid);
antonio@737
   289
antonio@737
   290
      UPDATE c_taxpayment
eduardo@723
   291
        SET gl_journal_id = v_gl_journalid
eduardo@723
   292
        where c_taxpayment.C_TAXPAYMENT_ID = v_record_id;
antonio@737
   293
eduardo@723
   294
      --settlement
antonio@737
   295
antonio@737
   296
eduardo@723
   297
      if v_ispayment='Y' then
antonio@737
   298
eduardo@723
   299
        v_settlementdoctype_id := ad_get_doctype(v_client_id,   v_org_id,   to_char('STM'));
antonio@735
   300
        ad_sequence_next('C_Settlement', v_record_id, v_settlementid);
antonio@735
   301
        ad_sequence_doctype(v_settlementdoctype_id, v_record_id, 'Y', v_sdocumentno);
eduardo@723
   302
eduardo@723
   303
        IF(v_sdocumentno IS NULL) THEN --to do send by mail
antonio@735
   304
        ad_sequence_doc('DocumentNo_C_Settlement', v_client_id, 'Y', v_sdocumentno);
eduardo@723
   305
        END IF;
antonio@737
   306
eduardo@723
   307
        INSERT
eduardo@723
   308
                INTO c_settlement(c_settlement_id,   ad_client_id,   ad_org_id,   isactive,   created,   createdby,   updated,   updatedby,   documentno,   datetrx,   dateacct,   settlementtype,   c_doctype_id,   processing,   processed,   posted,   createfrom,   isgenerated, c_currency_id)
eduardo@723
   309
                SELECT v_settlementid,
eduardo@723
   310
                  ad_client_id,
eduardo@723
   311
                  ad_org_id,
eduardo@723
   312
                  'Y',
eduardo@723
   313
                  now(),
eduardo@723
   314
                  createdby,
eduardo@723
   315
                  now(),
eduardo@723
   316
                  updatedby,
eduardo@723
   317
                  v_sdocumentno,
eduardo@723
   318
                  v_date,
eduardo@723
   319
                  TRUNC(now()),
eduardo@723
   320
                  'I',
eduardo@723
   321
                  v_settlementdoctype_id,
eduardo@723
   322
                  'N',
eduardo@723
   323
                  'N',
eduardo@723
   324
                  'N',
eduardo@723
   325
                  'N',
antonio@737
   326
                  'N',
eduardo@723
   327
                  v_currency_id
eduardo@723
   328
                FROM c_taxpayment
eduardo@723
   329
               WHERE c_taxpayment_id = v_record_id;
antonio@737
   330
antonio@737
   331
antonio@737
   332
antonio@737
   333
        select sum(case when  c_taxregister.C_TAXREGISTER_TYPE_ID in
eduardo@723
   334
        (select C_TAXREGISTER_TYPE_ID from c_taxregister_type where c_taxregister_type.ISSOTRX='Y')
eduardo@723
   335
        then taxtotalamt
eduardo@723
   336
        else -taxtotalamt end ),
antonio@737
   337
        sum(case when  c_taxregister.C_TAXREGISTER_TYPE_ID in
eduardo@723
   338
        (select C_TAXREGISTER_TYPE_ID from c_taxregister_type where c_taxregister_type.ISSOTRX='Y')
eduardo@723
   339
        then -lastregaccumamt
eduardo@723
   340
        else lastregaccumamt end )
eduardo@723
   341
        into v_taxtotalamt, v_prevvatcredit
eduardo@723
   342
        from c_taxregister where c_taxregister.C_TAXPAYMENT_ID=v_record_id;
antonio@737
   343
eduardo@723
   344
        if v_prevvatcredit < 0 then v_prevvatcredit := 0;
eduardo@723
   345
        end if;
eduardo@723
   346
        v_paymentamt := v_taxtotalamt - v_prevvatcredit;
antonio@737
   347
antonio@737
   348
antonio@737
   349
      if v_paymentamt <=0
antonio@737
   350
      then
eduardo@723
   351
      begin
eduardo@723
   352
      v_isreceipt:='Y';
eduardo@723
   353
      v_paymentamt:=(-1)*v_paymentamt;
eduardo@723
   354
      v_paymentcreditamt  := v_paymentamt;
eduardo@723
   355
      v_paymentdebitamt := 0;
eduardo@723
   356
      end;
antonio@737
   357
      else
eduardo@723
   358
      begin
antonio@737
   359
      v_isreceipt:='N';
eduardo@723
   360
      v_paymentcreditamt  := 0;
eduardo@723
   361
      v_paymentdebitamt := v_paymentamt;
eduardo@723
   362
      end;
eduardo@723
   363
      end if;
antonio@737
   364
antonio@737
   365
antonio@735
   366
        ad_sequence_next('C_Debt_Payment', v_record_id, v_debtpaymentid);
antonio@737
   367
eduardo@723
   368
        INSERT
eduardo@723
   369
         INTO c_debt_payment(c_debt_payment_id,   ad_client_id,   ad_org_id,   isactive,   created,   createdby,   updated,   updatedby,   isreceipt,   c_settlement_cancel_id,   c_settlement_generate_id,   description,   c_invoice_id,   c_bpartner_id,   c_currency_id,   c_cashline_id,   c_bankaccount_id,   c_cashbook_id,   paymentrule,   ispaid,   amount,   writeoffamt,   dateplanned,   ismanual,   isvalid,   c_bankstatementline_id,   changesettlementcancel,   cancel_processed,   generate_processed,   c_project_id,   status,   status_initial)
eduardo@723
   370
          VALUES(v_debtpaymentid,   v_client_id,   v_org_id,   'Y',   now(),   v_createdby,   now(),   v_updatedby,   v_isreceipt,   NULL,   v_settlementid, v_name,   NULL,   v_bpartner_id,   v_currency_id,   NULL,   NULL,   NULL,   v_paymentrule,   'N',  v_paymentamt ,   0,   v_date,   'Y',   'Y',   NULL,   'N',   'N',   'Y',   null,   'DE',   'DE');
antonio@737
   371
antonio@737
   372
antonio@735
   373
      ad_sequence_next('C_Debt_Payment_Balancing', v_record_id, v_debtpaymentbalancingid);
antonio@737
   374
eduardo@723
   375
       insert
eduardo@723
   376
       into c_debt_payment_balancing(c_debt_payment_balancing_id,   ad_client_id,   ad_org_id,   isactive,   created,   createdby,   updated,   updatedby, c_debt_payment_id, AMOUNTDEBIT, AMOUNTCREDIT, C_GLITEM_ID)
eduardo@723
   377
      values(v_debtpaymentbalancingid,   v_client_id,   v_org_id,   'Y',   now(),   v_createdby,   now(),   v_updatedby, v_debtpaymentid, v_paymentdebitamt, v_paymentcreditamt, v_glitem_id);
eduardo@723
   378
antonio@737
   379
antonio@737
   380
antonio@737
   381
eduardo@723
   382
       C_SETTLEMENT_POST(null, v_settlementid);
antonio@737
   383
antonio@737
   384
       UPDATE c_taxpayment
antonio@737
   385
        SET c_settlement_id = v_settlementid
eduardo@723
   386
        where c_taxpayment.C_TAXPAYMENT_ID = v_record_id;
antonio@737
   387
antonio@737
   388
antonio@737
   389
antonio@737
   390
      end if;
antonio@737
   391
antonio@737
   392
         UPDATE c_taxpayment
antonio@737
   393
        SET processed = 'Y'
antonio@737
   394
        where c_taxpayment.C_TAXPAYMENT_ID = v_record_id;
eduardo@723
   395
     END;
antonio@737
   396
antonio@737
   397
 end if;
antonio@737
   398
eduardo@723
   399
 -- stop processing
eduardo@723
   400
  update c_taxpayment
eduardo@723
   401
     set processing='N' where c_taxpayment_id=v_record_id;
antonio@737
   402
eduardo@723
   403
 end;
eduardo@723
   404
     IF(p_pinstance_id IS NOT NULL) THEN
eduardo@723
   405
    --  Update AD_PInstance
eduardo@723
   406
    DBMS_OUTPUT.PUT_LINE('Updating PInstance - Finished');
antonio@735
   407
    AD_UPDATE_PINSTANCE(p_pinstance_id,   v_updatedby,   'N',   v_result,   v_message);
eduardo@723
   408
    ELSE
eduardo@723
   409
    DBMS_OUTPUT.PUT_LINE('--<<C_TaxPayment_Post finished>> ' || v_message);
eduardo@723
   410
    END IF;
antonio@737
   411
eduardo@1349
   412
    EXCEPTION
eduardo@1349
   413
WHEN OTHERS THEN
eduardo@1349
   414
  v_ResultStr:= '@ERROR=' || SQLERRM;
eduardo@1349
   415
  DBMS_OUTPUT.PUT_LINE(v_ResultStr) ;
eduardo@1349
   416
  IF(p_PInstance_ID IS NOT NULL) THEN
eduardo@1349
   417
    ROLLBACK;
eduardo@1349
   418
    AD_UPDATE_PINSTANCE(p_PInstance_ID, NULL, 'N', 0, v_ResultStr) ;
eduardo@1349
   419
  ELSE
eduardo@1349
   420
    ROLLBACK;
eduardo@1349
   421
    RAISE;
eduardo@1349
   422
  END IF;
eduardo@1349
   423
  RETURN;
eduardo@723
   424
END C_TAXPAYMENT_POST
juanpablo@728
   425
]]></body>
juanpablo@728
   426
    </function>
juanpablo@728
   427
  </database>