/*
*********************************************************************
** Internal Script * Minimal QA Testing * Validate results with your
**    set of parameters !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
**********************************************************************
**  NAME:    JVREVERSAL.sql
**  PURPOSE: This will recreate fgbjvcd records from a document that 
**            has posted to the fgbtrnh tables.
**  jvreversal code from ActionLine modified by Deborah Colella   3/15/2000
**  This will recreate fgbjvcd records from a document that has posted to the
**  fgbtrnh tables.
**                                                                         
**  After running this sql, you will need to go into FGAJVCD and create the
**  header record for the new JV. When you go into the form, be sure to use
**  the new document code you identify below. Put in any amount for the
**  document total and then exit the form. Go back into FGAJVCD, call up your
**  new JV number again and do a next block. All the sequences will appear.  
**  To get the JV total, go to FGIJSUM and pull up the new JV. It will give  
**  you the total.                                                           
**                                                                           
**  NOTE: If your intention is to reverse the amounts of the original journal 
**  voucher, the fgbjvcd_dr_cr_ind must be changed.  This is done for you with
**  the decode statement on the debit credit indicator.  IF you do not want to
**  reverse the document, then remove the decode statement on the debit credit
**  indicator and just use the field.
** ----------------------------------------------------------------------
**     PARAMETERS
**     OUTPUTDOCUMENT: The document number to be used on the journal voucher
**     INPUTDOCUMENT:  The document number in fgbtrnh to create the new
**                     journal voucher from.
** ----------------------------------------------------------------------
**    TABLES USED
**      FGBTRNH,
**      FGBJVCD
** *************************************************************************
** AUDIT TRAIL: 
** Jim Beyer 06.Sep.2006
** Updated and reformatted code, added comments and verified V.7 data map.
** AUDIT TRAIL End
*/

INSERT INTO fimsmgr.fgbjvcd
     (fgbjvcd_doc_num, 
      fgbjvcd_submission_number, 
      fgbjvcd_seq_num, 
      fgbjvcd_activity_date, 
      fgbjvcd_user_id, 
      fgbjvcd_rucl_code, 
      fgbjvcd_trans_amt, 
      fgbjvcd_trans_desc, 
      fgbjvcd_dr_cr_ind, 
      fgbjvcd_fsyr_code, 
      fgbjvcd_acci_code, 
      fgbjvcd_coas_code, 
      fgbjvcd_fund_code, 
      fgbjvcd_orgn_code, 
      fgbjvcd_acct_code, 
      fgbjvcd_prog_code, 
      fgbjvcd_actv_code, 
      fgbjvcd_locn_code, 
      fgbjvcd_bank_code, 
      fgbjvcd_doc_ref_num, 
      fgbjvcd_vendor_pidm, 
      fgbjvcd_cmt_type, 
      fgbjvcd_cmt_pct, 
      fgbjvcd_dep_num, 
      fgbjvcd_encb_action_ind,
      fgbjvcd_prjd_code,
      fgbjvcd_dist_pct,
      fgbjvcd_posting_period,
      fgbjvcd_budget_period,
      fgbjvcd_accrual_ind,
      fgbjvcd_status_ind,
      fgbjvcd_abal_override,
      fgbjvcd_coas_code_pool,
      fgbjvcd_fund_code_pool)
    select '&OUTPUTDOCUMENT',
   fgbtrnh_submission_number,
   fgbtrnh_seq_num,
   fgbtrnh_activity_date,
   fgbtrnh_user_id,
   fgbtrnh_rucl_code,
   fgbtrnh_trans_amt,
   fgbtrnh_trans_desc,
   decode(fgbtrnh_dr_cr_ind,'D','C','C','D','+','-','-','+'),
   fgbtrnh_fsyr_code,
   fgbtrnh_acci_code,
   fgbtrnh_coas_code,
   fgbtrnh_fund_code,
   fgbtrnh_orgn_code,
   fgbtrnh_acct_code,
   fgbtrnh_prog_code,
   fgbtrnh_actv_code,
   fgbtrnh_locn_code,
   fgbtrnh_bank_code,
   fgbtrnh_doc_ref_num,
   fgbtrnh_vendor_pidm,
   fgbtrnh_cmt_type,
   fgbtrnh_cmt_pct,
   fgbtrnh_dep_num,
   fgbtrnh_encd_action_ind,
   fgbtrnh_prjd_code,
   fgbtrnh_dist_pct,
   fgbtrnh_posting_period,
   fgbtrnh_budget_period,
   fgbtrnh_accrual_ind,
   'P',
   fgbtrnh_abal_override,
   fgbtrnh_coas_code_pool,
   fgbtrnh_fund_code_pool
FROM fgbtrnh
WHERE fgbtrnh_doc_code = '&INPUTDOCUMENT'
AND FGBTRNH_COAS_CODE = 'R' 
/
