zoukankan      html  css  js  c++  java
  • 存储过程数据insert into select





      1 create or replace procedure PRO_K3_CZZH (org_name      in varchar2, --财政专户名称
      2                                          opertype      in varchar2, --操作类型 0:正常对碰的直接支付 1:正常对碰的授权支付 2:全额退款的直接支付 4:部分退款的直接支付 3:全额退款的授权支付 5:部分退款的授权支付
      3                                          fdate         in varchar2, --日期
      4                                          i_pk_id       in varchar2, --主键id
      5                                          i_databasename    in varchar2, --数据库名
      6                                          i_fgroup      in varchar2, -- 字号, 记
      7                                          i_fpreparer   in number, -- 制单人,id
      8                                          i_fattachment in number, -- 附件数
      9                                          o_ret out number
     10                                          ) is
     11   v_total        number(16, 2);
     12   v_fserialnum_1 number(16, 2); -- 流水号
     13   v_fserialnum_2 number(16, 2); -- 流水号
     14   v_fserialnum_3 number(16, 2); -- 流水号
     15   v_fserialnum_4 number(16, 2); -- 流水号
     16   v_fserialnum_5 number(16, 2); -- 流水号  
     17   v_max_index    number;
     18   v_count number;
     19   v_orign_type number;
     20   v_count_gkfszh number;
     21 
     22 begin
     23   o_ret := 0;
     24   select nextid('GK_ZWVCH_SEQ') into v_fserialnum_1 from dual;
     25   select nextid('GK_ZWVCH_SEQ') into v_fserialnum_2 from dual;
     26   select nextid('GK_ZWVCH_SEQ') into v_fserialnum_3 from dual;
     27   select nextid('GK_ZWVCH_SEQ') into v_fserialnum_4 from dual;
     28   select nextid('GK_ZWVCH_SEQ') into v_fserialnum_5 from dual;
     29 
     30   select count(1) into v_count from  GK_ZWVCH_IDS a where a.pk_id  = i_pk_id;
     31 
     32   if v_count = 0 then
     33   return ;
     34   end if;
     35   /* 操作类型 0:正常对碰的直接支付
     36              1:正常对碰的授权支付
     37              2:全额退款的直接支付
     38              4:部分退款的直接支付
     39              3:全额退款的授权支付
     40              5:部分退款的授权支付
     41              6:正常对碰的一般支付
     42              7:全额退款的一般支付
     43   */
     44    if opertype='0' or opertype='1'  or opertype='6'   then
     45       v_orign_type:=1 ;
     46    elsif   opertype='2' or  opertype='3' or  opertype='4' or   opertype='5' or   opertype='7'  then
     47       v_orign_type:=3;
     48    end if;
     49 
     50   --先判断入参是否有值,如果没有值 整个存储过程返回空值
     51 if org_name is not null and opertype is not null and fdate is not null  and i_pk_id is not null then
     52 
     53 
     54   /* 操作类型 0:正常对碰的直接支付
     55              1:正常对碰的授权支付
     56              2:全额退款的直接支付
     57              4:部分退款的直接支付
     58              3:全额退款的授权支付
     59              5:部分退款的授权支付
     60              6:正常对碰的一般支付
     61              7:全额退款的一般支付
     62  */
     63 --================================================================================================================
     64 --==========                                             代管资金户                                        ========
     65 --================================================================================================================      
     66       if org_name='代管资金户' then
     67 
     68          --插入主表
     69         insert into gk_zwvch
     70           (fserialnum,
     71            FPERIOD,
     72            fgroup,
     73            fdate,
     74            fnum,
     75            fpreparer,
     76            fattachment,
     77            fmodule,
     78            jz_database,
     79            org_type,
     80            jz_fserialnum,
     81            orign_type,
     82            make_date)
     83           select v_fserialnum_1,
     84                  substr(fdate, 6, 2),
     85                  i_fgroup,
     86                  to_date(fdate, 'yyyy-MM-dd'),
     87                  0,
     88                  i_fpreparer,
     89                  i_fattachment,
     90                  3,
     91                  i_databasename,
     92                  '1', --资金来源类型
     93                  0,
     94                  v_orign_type,
     95                  sysdate
     96 
     97             from dual;
     98 
     99          if opertype='0' or opertype='1'  or opertype='6'     then
    100           /*    正常对碰的直接支付 授权支付
    101 
    102                 借:2017.001[项目]应付代管资金.代管资金
    103                 贷:1004.001.01其他财政存款.信社存款.农商行活期
    104 
    105            --代管资金户的项目代码有些特殊。是按照项目名称中的关键字来进行区分转化其项目编码的。
    106           */
    107            ---借方数据插入     
    108             insert into gk_zwentry(fserialnum,fentryid,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,budgetid)
    109                select   fserialnum,ROWNUM,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname, budgetid from (
    110                select fserialnum,ROWNUM,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,
    111                         budgetno || ',' || year1 || ',' || budget_type || ',' || voucher_type || ',' || SRC_ID  budgetid
    112                from (
    113                    SELECT Z.SRC_ID,Z.voucher_type,z.budget_type,z.budgetno,substr(to_char(sysdate,'yyyy-MM-dd'),0,4) year1,  v_fserialnum_1  fserialnum ,
    114                 '2017001' facctid,
    115                 '1' fclsid ,
    116                 z.purpose fexp,z.zf_item_amt fdebit,0 fcredit,'1' fbanksettel ,z.prjno ftransid,'RMB' fcyid,z.unitno fobjid,z.zf_itemno zf_itemno,z.zf_itemname zf_itemname
    117                  FROM (
    118                           SELECT Z.voucher_type,
    119                                  (select  bx.prj_name from bs_xmk bx where bx.prj_code=z.prjno) purpose,
    120                                  z.amt  zf_item_amt,
    121                                  (select (case when instr(bx.prj_name,'环保' )>0 then '16'
    122                                                when instr(bx.prj_name,'电力' )>0 then '17'
    123                                                when instr(bx.prj_name,'地下' )>0 then '18'
    124                                                when instr(bx.prj_name,'百村' )>0 then '19'
    125                                                when instr(bx.prj_name,'特色古村' )>0 then '20'
    126                                                when instr(bx.prj_name,'利息收入' )>0 then '21'
    127                                                when instr(bx.prj_name,'五好' )>0 then '22'
    128                                                when instr(bx.prj_name,'扶持' )>0 then '23' else '12'     end ) prjno from bs_xmk bx where bx.prj_code=z.prjno)  prjno,
    129                                  z.unitno,
    130                                  Z.SRC_ID,
    131                                  Z.budget_type,
    132                                  Z.budgetno,
    133                                  '' zf_itemno,
    134                                  '' zf_itemname,
    135                                  (select bz.org_type  from bs_zjly bz where bz.fundno=z.src_id ) ORG_TYPE
    136                                 -- z.AFFIRM_DATE
    137                             FROM  gk_zfpz  Z
    138                            WHERE Z.id IN
    139                                  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    140                        ) Z
    141                       order by z.budgetno
    142                 )
    143               )
    144               ;
    145             ---贷方:
    146 
    147               select sum(a.fdebit) into v_total from gk_zwentry a where a.fserialnum = v_fserialnum_1 ;
    148               select max(a.fentryid) + 1 into v_max_index from gk_zwentry a where a.fserialnum = v_fserialnum_1;
    149               insert into gk_zwentry
    150                 (fserialnum,
    151                  fentryid,
    152                  facctid,
    153                  fclsid,
    154                  fexp,
    155                  fdebit,
    156                  fcredit,
    157                  fbanksettel,
    158                  ftransid,
    159                  fcyid,
    160                  fobjid,
    161                  zf_itemno,
    162                  zf_itemname,BUDGETID)
    163                 SELECT v_fserialnum_1,
    164                        v_max_index,
    165                        '100400101',
    166                        '0',
    167                        '',
    168                        0,
    169                        v_total,
    170                        '1',
    171                        '000',
    172                        'RMB',
    173                        '*',
    174                        '',
    175                        '','100400101,' || substr(fdate,0,4) || ',*,*,*'
    176                   from dual;
    177 
    178               insert into gk_zwvch_refer(FSERIALNUM, orign_type,orign_id,voucher_type,origin_teable,fmodule)
    179                select v_fserialnum_1 ,
    180                    '1' ORIGN_TYPE,
    181                   z.id ORIGN_ID,
    182                   z.voucher_type VOUCHER_TYPE,
    183                   'GK_ZFPZ' ORIGIN_TEABLE,
    184                   '3' FMODULE
    185              from gk_zfpz z
    186              WHERE Z.id IN (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id);
    187 
    188 
    189          elsif   opertype='2' or  opertype='3'  then
    190            /*  全额退款的 直接支付 授权支付
    191 
    192                 借:1004.001.01其他财政存款.信社存款.农商行活期
    193                 贷:2017.001[项目]应付代管资金.代管资金
    194 
    195            --代管资金户的项目代码有些特殊。是按照项目名称中的关键字来进行区分转化其项目编码的。
    196           */
    197            ---贷方数据插入     
    198             insert into gk_zwentry(fserialnum,fentryid,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,budgetid)
    199                select   fserialnum,ROWNUM+1,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname, budgetid from (
    200                select fserialnum,ROWNUM+1,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,
    201                         budgetno || ',' || year1 || ',' || budget_type || ',' || voucher_type || ',' || SRC_ID  budgetid
    202                from (
    203                    SELECT Z.SRC_ID,Z.voucher_type,z.budget_type,z.budgetno,substr(to_char(sysdate,'yyyy-MM-dd'),0,4) year1,  v_fserialnum_1  fserialnum ,
    204                 '2017001' facctid,  '1' fclsid ,
    205                 z.purpose fexp,0 fdebit, z.zf_item_amt fcredit,'1' fbanksettel ,z.prjno ftransid,'RMB' fcyid,z.unitno fobjid,z.zf_itemno zf_itemno,z.zf_itemname zf_itemname
    206                  FROM (
    207                           SELECT  Z.voucher_type,
    208                                  (select  bx.prj_name from bs_xmk bx where bx.prj_code=z.prjno) purpose,
    209                                  z.amt  zf_item_amt,
    210                                  (select (case when instr(bx.prj_name,'环保' )>0 then '16'
    211                                                when instr(bx.prj_name,'电力' )>0 then '17'
    212                                                when instr(bx.prj_name,'地下' )>0 then '18'
    213                                                when instr(bx.prj_name,'百村' )>0 then '19'
    214                                                when instr(bx.prj_name,'特色古村' )>0 then '20'
    215                                                when instr(bx.prj_name,'利息收入' )>0 then '21'
    216                                                when instr(bx.prj_name,'五好' )>0 then '22'
    217                                                when instr(bx.prj_name,'扶持' )>0 then '23' else '12'     end ) prjno from bs_xmk bx where bx.prj_code=z.prjno)  prjno,
    218                                  z.unitno,
    219                                  Z.SRC_ID,
    220                                  Z.budget_type,
    221                                  Z.budgetno,
    222                                  '' zf_itemno,
    223                                  '' zf_itemname,
    224                                  (select bz.org_type  from bs_zjly bz where bz.fundno=z.src_id ) ORG_TYPE
    225                                 -- z.AFFIRM_DATE
    226                             FROM  gk_zfpz  Z
    227                            WHERE Z.id IN
    228                                  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    229                        ) Z
    230                       order by z.budgetno
    231                 )
    232               )
    233               ;
    234             ---借方:
    235 
    236               select sum(a.fcredit) into v_total from gk_zwentry a where a.fserialnum = v_fserialnum_1 ;
    237 
    238               insert into gk_zwentry
    239                 (fserialnum,
    240                  fentryid,
    241                  facctid,
    242                  fclsid,
    243                  fexp,
    244                  fdebit,
    245                  fcredit,
    246                  fbanksettel,
    247                  ftransid,
    248                  fcyid,
    249                  fobjid,
    250                  zf_itemno,
    251                  zf_itemname,BUDGETID)
    252                 SELECT v_fserialnum_1,
    253                        '1',
    254                        '100400101',
    255                        '0',
    256                        '',
    257                        v_total,
    258                         0,
    259                        '1',
    260                        '000',
    261                        'RMB',
    262                        '*',
    263                        '',
    264                        '','100400101,' || substr(fdate,0,4) || ',*,*,*'
    265                   from dual;
    266 
    267               insert into gk_zwvch_refer(FSERIALNUM, orign_type,orign_id,voucher_type,origin_teable,fmodule)
    268                select v_fserialnum_1 ,
    269                    '3' ORIGN_TYPE,
    270                   z.id ORIGN_ID,
    271                   z.voucher_type VOUCHER_TYPE,
    272                   'GK_ZFPZ' ORIGIN_TEABLE,
    273                   '3' FMODULE
    274              from gk_zfpz z
    275              WHERE Z.id IN (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id);
    276 
    277          elsif   opertype='4' or   opertype='5' then
    278             /* 部分退款的直接支付  授权支付
    279 
    280                 借:1004.001.01其他财政存款.信社存款.农商行活期
    281                 贷:2017.001[项目]应付代管资金.代管资金
    282 
    283            --代管资金户的项目代码有些特殊。是按照项目名称中的关键字来进行区分转化其项目编码的。
    284           */
    285            ---贷方数据插入     
    286             insert into gk_zwentry(fserialnum,fentryid,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,budgetid)
    287                select   fserialnum,ROWNUM+1,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname, budgetid from (
    288                select fserialnum,ROWNUM+1,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,
    289                         budgetno || ',' || year1 || ',' || budget_type || ',' || voucher_type || ',' || SRC_ID  budgetid
    290                from (
    291                    SELECT Z.SRC_ID,Z.voucher_type,z.budget_type,z.budgetno,substr(to_char(sysdate,'yyyy-MM-dd'),0,4) year1,  v_fserialnum_1  fserialnum ,
    292                 '2017001' facctid,  '1' fclsid ,
    293                 z.purpose fexp,0 fdebit,z.zf_item_amt fcredit,'1' fbanksettel ,z.prjno ftransid,'RMB' fcyid,z.unitno fobjid,z.zf_itemno zf_itemno,z.zf_itemname zf_itemname
    294                  FROM (
    295                        SELECT   Z.voucher_type,
    296                                  (select  bx.prj_name from bs_xmk bx where bx.prj_code=z.prjno) purpose,
    297                                  z.amt  zf_item_amt,
    298                                   (select (case when instr(bx.prj_name,'环保' )>0 then '16'
    299                                                when instr(bx.prj_name,'电力' )>0 then '17'
    300                                                when instr(bx.prj_name,'地下' )>0 then '18'
    301                                                when instr(bx.prj_name,'百村' )>0 then '19'
    302                                                when instr(bx.prj_name,'特色古村' )>0 then '20'
    303                                                when instr(bx.prj_name,'利息收入' )>0 then '21'
    304                                                when instr(bx.prj_name,'五好' )>0 then '22'
    305                                                when instr(bx.prj_name,'扶持' )>0 then '23' else '12'     end ) prjno from bs_xmk bx where bx.prj_code=z.prjno) prjno,
    306                                  z.unitno,
    307                                  Z.SRC_ID,
    308                                  Z.budget_type,
    309                                  Z.budgetno,
    310                                  '' zf_itemno,
    311                                  '' zf_itemname,
    312                                  (select bz.org_type  from bs_zjly bz where bz.fundno=z.src_id ) ORG_TYPE
    313 
    314                             FROM  gk_part_refundment  Z
    315                            WHERE Z.id IN
    316                                  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    317                        ) Z
    318                       order by z.budgetno
    319                 )
    320               )
    321               ;
    322             ---借方:
    323 
    324               select sum(a.fcredit) into v_total from gk_zwentry a where a.fserialnum = v_fserialnum_1 ;
    325 
    326               insert into gk_zwentry
    327                 (fserialnum,
    328                  fentryid,
    329                  facctid,
    330                  fclsid,
    331                  fexp,
    332                  fdebit,
    333                  fcredit,
    334                  fbanksettel,
    335                  ftransid,
    336                  fcyid,
    337                  fobjid,
    338                  zf_itemno,
    339                  zf_itemname,BUDGETID)
    340                 SELECT v_fserialnum_1,
    341                        '1',
    342                        '100400101',
    343                        '0',
    344                        '',
    345                        v_total,
    346                        0,
    347                        '1',
    348                        '000',
    349                        'RMB',
    350                        '*',
    351                        '',
    352                        '','100400101,' || substr(fdate,0,4) || ',*,*,*'
    353                   from dual;
    354              ---部分退款
    355               insert into gk_zwvch_refer(FSERIALNUM, orign_type,orign_id,voucher_type,origin_teable,fmodule)
    356                select v_fserialnum_1 ,
    357                    '3' ORIGN_TYPE,
    358                   z.id ORIGN_ID,
    359                   z.voucher_type VOUCHER_TYPE,
    360                   'GK_PART_REFUNDMENT' ORIGIN_TEABLE,
    361                   '3' FMODULE
    362              from gk_part_refundment z
    363              WHERE Z.id IN (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id);
    364 
    365          elsif   opertype='7'    then
    366              /* 一般支付 退款
    367 
    368                 借:1004.001.01其他财政存款.信社存款.农商行活期
    369                 贷:2017.001[项目]应付代管资金.代管资金
    370 
    371                --代管资金户的项目代码有些特殊。是按照项目名称中的关键字来进行区分转化其项目编码的。
    372            */
    373            ---贷方数据插入     
    374             insert into gk_zwentry(fserialnum,fentryid,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,budgetid)
    375                select   fserialnum,ROWNUM+1,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname, budgetid from (
    376                select fserialnum,ROWNUM+1,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,
    377                         budgetno || ',' || year1 || ',' || budget_type || ',' || voucher_type || ',' || SRC_ID  budgetid
    378                from (
    379                    SELECT Z.SRC_ID,Z.voucher_type,z.budget_type,z.budgetno,substr(to_char(sysdate,'yyyy-MM-dd'),0,4) year1,  v_fserialnum_1  fserialnum ,
    380                 '2017001' facctid,  '1' fclsid ,
    381                 z.purpose fexp,0 fdebit,z.zf_item_amt fcredit,'1' fbanksettel ,z.prjno ftransid,'RMB' fcyid,z.unitno fobjid,z.zf_itemno zf_itemno,z.zf_itemname zf_itemname
    382                  FROM (
    383                        SELECT   Z.voucher_type,
    384                                  (select  bx.prj_name from bs_xmk bx where bx.prj_code=z.prjno) purpose,
    385                                  z.amt  zf_item_amt,
    386                                   (select (case when instr(bx.prj_name,'环保' )>0 then '16'
    387                                                when instr(bx.prj_name,'电力' )>0 then '17'
    388                                                when instr(bx.prj_name,'地下' )>0 then '18'
    389                                                when instr(bx.prj_name,'百村' )>0 then '19'
    390                                                when instr(bx.prj_name,'特色古村' )>0 then '20'
    391                                                when instr(bx.prj_name,'利息收入' )>0 then '21'
    392                                                when instr(bx.prj_name,'五好' )>0 then '22'
    393                                                when instr(bx.prj_name,'扶持' )>0 then '23' else '12'     end ) prjno from bs_xmk bx where bx.prj_code=z.prjno) prjno,
    394                                  z.unitno,
    395                                  Z.SRC_ID,
    396                                  Z.budget_type,
    397                                  Z.budgetno,
    398                                  '' zf_itemno,
    399                                  '' zf_itemname,
    400                                  (select bz.org_type  from bs_zjly bz where bz.fundno=z.src_id ) ORG_TYPE
    401 
    402                             FROM   (  select crbd.id  as id ,  '3' voucher_type , crb.reason as refundment_memo ,   crbd.pay_amt as amt , crbd.prjno as prjno  ,crb.unitno ,crb.src_id as SRC_ID ,crbd.budget_type ,crbd.budgetno  from  common_req_back crb,common_req_back_detail crbd where crb.id=crbd.common_req_back_id)  Z
    403                            WHERE Z.id IN
    404                                  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    405                        ) Z
    406                       order by z.budgetno
    407                 )
    408               )
    409               ;
    410             ---借方:
    411 
    412               select sum(a.fcredit) into v_total from gk_zwentry a where a.fserialnum = v_fserialnum_1 ;
    413 
    414               insert into gk_zwentry
    415                 (fserialnum,
    416                  fentryid,
    417                  facctid,
    418                  fclsid,
    419                  fexp,
    420                  fdebit,
    421                  fcredit,
    422                  fbanksettel,
    423                  ftransid,
    424                  fcyid,
    425                  fobjid,
    426                  zf_itemno,
    427                  zf_itemname,BUDGETID)
    428                 SELECT v_fserialnum_1,
    429                        '1',
    430                        '100400101',
    431                        '0',
    432                        '',
    433                        v_total,
    434                        0,
    435                        '1',
    436                        '000',
    437                        'RMB',
    438                        '*',
    439                        '',
    440                        '','100400101,' || substr(fdate,0,4) || ',*,*,*'
    441                   from dual;
    442              ---部分退款
    443               insert into gk_zwvch_refer(FSERIALNUM, orign_type,orign_id,voucher_type,origin_teable,fmodule)
    444                select v_fserialnum_1 ,
    445                    '3' ORIGN_TYPE,
    446                   z.id ORIGN_ID,
    447                   z.voucher_type VOUCHER_TYPE,
    448                   'common_req_back_detail' ORIGIN_TEABLE,
    449                   '3' FMODULE
    450              from  (  select crbd.id  as id ,  '3' voucher_type , crb.reason as refundment_memo ,   crbd.pay_amt as amt , crbd.prjno as prjno  ,crb.unitno ,crb.src_id as SRC_ID ,crbd.budget_type ,crbd.budgetno  from  common_req_back crb,common_req_back_detail crbd where crb.id=crbd.common_req_back_id)  z
    451              WHERE Z.id IN (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id);
    452          end if;
    453 --================================================================================================================
    454 --==========                                             非税收入专户                                      ========
    455 --================================================================================================================        
    456       elsif org_name='非税收入专户'  then
    457          if opertype='0' or opertype='1'or opertype='6' then
    458 
    459            /*    正常对碰的直接支付 授权支付  一般支付
    460                  ---资金来源为非税收入
    461                  借:5005财政专户管理资金支出 [功能分类科目编码  预算单位编码 ]
    462                  贷:1004.001/002其他财政存款.农行/农商行
    463                       根据第八点的付款帐号来进行区分:农行、 农商
    464 
    465                 会计科目编码组成:5005+功能分类科目编码
    466           */
    467           select count(1) into v_count_gkfszh  from gk_zfpz  Z   WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)   and z.src_id='013' ; /*非税收入专户*/
    468             if    v_count_gkfszh >0 then
    469                    --插入主表
    470                   insert into gk_zwvch
    471                     (fserialnum,
    472                      FPERIOD,
    473                      fgroup,
    474                      fdate,
    475                      fnum,
    476                      fpreparer,
    477                      fattachment,
    478                      fmodule,
    479                      jz_database,
    480                      org_type,
    481                      jz_fserialnum,
    482                      orign_type,
    483                      make_date)
    484                     select v_fserialnum_1,
    485                            substr(fdate, 6, 2),
    486                            i_fgroup,
    487                            to_date(fdate, 'yyyy-MM-dd'),
    488                            0,
    489                            i_fpreparer,
    490                            v_count_gkfszh,
    491                            3,
    492                            i_databasename,
    493                            '1', --资金来源类型
    494                            0,
    495                            v_orign_type,
    496                            sysdate
    497 
    498                       from dual;
    499 
    500 
    501                  ---借方数据插入     
    502                   insert into gk_zwentry(fserialnum,fentryid,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,budgetid)
    503                      select   fserialnum,ROWNUM,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname, budgetid from (
    504                      select fserialnum,ROWNUM,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,
    505                               budgetno || ',' ||substr(fdate,0,4)|| ',' || budget_type || ',' || voucher_type || ',' || SRC_ID  budgetid
    506                      from (
    507                          SELECT Z.SRC_ID,Z.voucher_type,z.budget_type,z.budgetno,substr(to_char(sysdate,'yyyy-MM-dd'),0,4) year1,  v_fserialnum_1  fserialnum ,
    508                       '5005'||budgetno  facctid,
    509                       '1' fclsid ,
    510                       z.purpose fexp,z.zf_item_amt fdebit,0 fcredit,'1' fbanksettel ,z.prjno ftransid,'RMB' fcyid,z.unitno fobjid,z.zf_itemno zf_itemno,z.zf_itemname zf_itemname
    511                        FROM (
    512                                 SELECT Z.voucher_type,
    513                                        '拨清算资金 ' purpose,
    514                                        z.amt  zf_item_amt,
    515                                        z.prjno  prjno,
    516                                        z.unitno,
    517                                        Z.SRC_ID,
    518                                        Z.budget_type,
    519                                        Z.budgetno,
    520                                        '' zf_itemno,
    521                                        '' zf_itemname,
    522                                        (select bz.org_type  from bs_zjly bz where bz.fundno=z.src_id ) ORG_TYPE
    523                                       -- z.AFFIRM_DATE
    524                                   FROM  gk_zfpz  Z
    525                                  WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    526                                      and z.src_id='013' /*非税收入专户*/
    527                              ) Z
    528                             order by z.budgetno
    529                       )
    530                     )
    531                     ;
    532                   ---贷方:
    533 
    534                     select sum(a.fdebit) into v_total from gk_zwentry a where a.fserialnum = v_fserialnum_1 ;
    535                     select max(a.fentryid) + 1 into v_max_index from gk_zwentry a where a.fserialnum = v_fserialnum_1;
    536                     insert into gk_zwentry
    537                       (fserialnum,
    538                        fentryid,
    539                        facctid,
    540                        fclsid,
    541                        fexp,
    542                        fdebit,
    543                        fcredit,
    544                        fbanksettel,
    545                        ftransid,
    546                        fcyid,
    547                        fobjid,
    548                        zf_itemno,
    549                        zf_itemname,BUDGETID)
    550                       SELECT v_fserialnum_1,
    551                              v_max_index,
    552                              (select (case when instr(bz.yswqs_fk_bank, '农村商业') > 0 then  '1004001'
    553                                         when instr(bz.yswqs_fk_bank, '农业') > 0 then      '1004002'
    554                                         when instr(bz.yswqs_fk_bank, '建设') > 0 then       '1004003'
    555                                         else           '1004001'       end) asfacctid
    556                                from bs_zjly bz  where bz.fundno = '013') ,
    557                              '0',
    558                              '拨清算资金',
    559                              0,
    560                              v_total,
    561                              '1',
    562                              '000',
    563                              'RMB',
    564                              '*',
    565                              '',
    566                              '',(select (case when instr(bz.yswqs_fk_bank, '农村商业') > 0 then  '1004001'
    567                                           when instr(bz.yswqs_fk_bank, '农业') > 0 then      '1004002'
    568                                           when instr(bz.yswqs_fk_bank, '建设') > 0 then       '1004003'
    569                                           else           '1004001'       end) asfacctid
    570                                  from bs_zjly bz  where bz.fundno = '113')||',' ||substr(fdate,0,4)|| ',*,*,*'
    571                         from dual;
    572 
    573                     insert into gk_zwvch_refer(FSERIALNUM, orign_type,orign_id,voucher_type,origin_teable,fmodule)
    574                      select v_fserialnum_1 ,
    575                          '1' ORIGN_TYPE,
    576                         z.id ORIGN_ID,
    577                         z.voucher_type VOUCHER_TYPE,
    578                         'GK_ZFPZ' ORIGIN_TEABLE,
    579                         '3' FMODULE
    580                    from gk_zfpz z
    581                    WHERE Z.id IN (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id);
    582              end if;
    583 
    584 
    585 
    586             /*    正常对碰的直接支付 授权支付  一般支付
    587                  注:当资金来源为非税收入(上年结转)时
    588                  借:2011[单位] 应付国库集中支付(根据预算单位编码填列)
    589                  贷:1004.001/002/004 其他财政存款.农行/农商行/建行
    590                           根据第八点的付款帐号来进行区分:农行、 农商、  建行
    591 
    592                 会计科目编码组成:5005+功能分类科目编码
    593            */
    594 
    595            select count(1) into v_count_gkfszh  from gk_zfpz  Z  WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)   and z.src_id='113' ; /*非税收入专户(上年结转)*/
    596            if    v_count_gkfszh >0 then
    597                  ---插入主表
    598                    insert into gk_zwvch
    599                       (fserialnum,
    600                        FPERIOD,
    601                        fgroup,
    602                        fdate,
    603                        fnum,
    604                        fpreparer,
    605                        fattachment,
    606                        fmodule,
    607                        jz_database,
    608                        org_type,
    609                        jz_fserialnum,
    610                        orign_type,
    611                        make_date)
    612                       select v_fserialnum_2,
    613                              substr(fdate, 6, 2),
    614                              i_fgroup,
    615                              to_date(fdate, 'yyyy-MM-dd'),
    616                              0,
    617                              i_fpreparer,
    618                              v_count_gkfszh,
    619                              3,
    620                              i_databasename,
    621                              '1', --资金来源类型
    622                              0,
    623                              v_orign_type,
    624                              sysdate
    625 
    626                         from dual;
    627                     ---借方数据插入     
    628                     insert into gk_zwentry(fserialnum,fentryid,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,budgetid)
    629                        select   fserialnum,ROWNUM,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname, budgetid from (
    630                        select fserialnum,ROWNUM,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,
    631                                 budgetno || ',' || year1 || ',' || budget_type || ',' || voucher_type || ',' || SRC_ID  budgetid
    632                        from (
    633                            SELECT Z.SRC_ID,Z.voucher_type,z.budget_type,z.budgetno,substr(to_char(sysdate,'yyyy-MM-dd'),0,4) year1,  v_fserialnum_2  fserialnum ,
    634                         '2011'||budgetno  facctid,
    635                         '1' fclsid ,
    636                         z.purpose fexp,z.zf_item_amt fdebit,0 fcredit,'1' fbanksettel ,z.prjno ftransid,'RMB' fcyid,z.unitno fobjid,z.zf_itemno zf_itemno,z.zf_itemname zf_itemname
    637                          FROM (
    638                                   SELECT Z.voucher_type,
    639                                          '拨清算资金 ' purpose,
    640                                          z.amt  zf_item_amt,
    641                                          z.prjno  prjno,
    642                                          z.unitno,
    643                                          Z.SRC_ID,
    644                                          Z.budget_type,
    645                                          Z.budgetno,
    646                                          '' zf_itemno,
    647                                          '' zf_itemname,
    648                                          (select bz.org_type  from bs_zjly bz where bz.fundno=z.src_id ) ORG_TYPE
    649                                         -- z.AFFIRM_DATE
    650                                     FROM  gk_zfpz  Z
    651                                    WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    652                                        and z.src_id='113' /*非税收入专户*/
    653                                ) Z
    654                               order by z.budgetno
    655                         )
    656                       )
    657                       ;
    658                     ---贷方:
    659 
    660                       select sum(a.fdebit) into v_total from gk_zwentry a where a.fserialnum = v_fserialnum_2 ;
    661                       select max(a.fentryid) + 1 into v_max_index from gk_zwentry a where a.fserialnum = v_fserialnum_2;
    662                       insert into gk_zwentry
    663                         (fserialnum,
    664                          fentryid,
    665                          facctid,
    666                          fclsid,
    667                          fexp,
    668                          fdebit,
    669                          fcredit,
    670                          fbanksettel,
    671                          ftransid,
    672                          fcyid,
    673                          fobjid,
    674                          zf_itemno,
    675                          zf_itemname,BUDGETID)
    676                         SELECT v_fserialnum_2,
    677                                v_max_index,
    678                                (select (case when instr(bz.yswqs_fk_bank, '农村商业') > 0 then  '1004001'
    679                                           when instr(bz.yswqs_fk_bank, '农业') > 0 then      '1004002'
    680                                           when instr(bz.yswqs_fk_bank, '建设') > 0 then       '1004003'
    681                                           else           '1004001'       end) asfacctid
    682                                  from bs_zjly bz  where bz.fundno = '113') ,
    683                                '0',
    684                                '拨清算资金',
    685                                 0,
    686                                 v_total,
    687                                '1',
    688                                '000',
    689                                'RMB',
    690                                '*',
    691                                '',
    692                                '',(select (case when instr(bz.yswqs_fk_bank, '农村商业') > 0 then  '1004001'
    693                                           when instr(bz.yswqs_fk_bank, '农业') > 0 then      '1004002'
    694                                           when instr(bz.yswqs_fk_bank, '建设') > 0 then       '1004003'
    695                                           else           '1004001'       end) asfacctid
    696                                  from bs_zjly bz  where bz.fundno = '113')||',' || substr(fdate,0,4) || ',*,*,*'
    697                           from dual;
    698 
    699                       insert into gk_zwvch_refer(FSERIALNUM, orign_type,orign_id,voucher_type,origin_teable,fmodule)
    700                        select v_fserialnum_2 ,
    701                            '1' ORIGN_TYPE,
    702                           z.id ORIGN_ID,
    703                           z.voucher_type VOUCHER_TYPE,
    704                           'GK_ZFPZ' ORIGIN_TEABLE,
    705                           '3' FMODULE
    706                      from gk_zfpz z
    707                      WHERE Z.id IN (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id);
    708             end if;
    709 
    710 
    711 
    712 
    713          elsif   opertype='2' or  opertype='3'  then
    714 
    715          /*    财政专户名称为:全额退款的直接支付 授权支付
    716                  ---资金来源为非税收入
    717                  借:1004.001/002其他财政存款.农行/农商行
    718                  贷:5005财政专户管理资金支出 [功能分类科目编码  预算单位编码 ]
    719                       根据第八点的付款帐号来进行区分:农行、 农商
    720 
    721                 会计科目编码组成:5005+功能分类科目编码
    722           */
    723           select count(1) into v_count_gkfszh  from gk_zfpz  Z   WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)   and z.src_id='013' ; /*非税收入专户*/
    724             if    v_count_gkfszh >0 then
    725                    --插入主表
    726                   insert into gk_zwvch
    727                     (fserialnum,
    728                      FPERIOD,
    729                      fgroup,
    730                      fdate,
    731                      fnum,
    732                      fpreparer,
    733                      fattachment,
    734                      fmodule,
    735                      jz_database,
    736                      org_type,
    737                      jz_fserialnum,
    738                      orign_type,
    739                      make_date)
    740                     select v_fserialnum_1,
    741                            substr(fdate, 6, 2),
    742                            i_fgroup,
    743                            to_date(fdate, 'yyyy-MM-dd'),
    744                            0,
    745                            i_fpreparer,
    746                            v_count_gkfszh,
    747                            3,
    748                            i_databasename,
    749                            '1', --资金来源类型
    750                            0,
    751                            v_orign_type,
    752                            sysdate
    753 
    754                       from dual;
    755 
    756 
    757                  ---贷方数据插入     
    758                   insert into gk_zwentry(fserialnum,fentryid,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,budgetid)
    759                      select   fserialnum,ROWNUM+1,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname, budgetid from (
    760                      select fserialnum,ROWNUM+1,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,
    761                               budgetno || ',' ||substr(fdate,0,4)|| ',' || budget_type || ',' || voucher_type || ',' || SRC_ID  budgetid
    762                      from (
    763                          SELECT Z.SRC_ID,Z.voucher_type,z.budget_type,z.budgetno,substr(to_char(sysdate,'yyyy-MM-dd'),0,4) year1,  v_fserialnum_1  fserialnum ,
    764                       '5005'||budgetno  facctid,
    765                       '1' fclsid ,
    766                       z.purpose fexp,0 fdebit,z.zf_item_amt fcredit,'1' fbanksettel ,z.prjno ftransid,'RMB' fcyid,z.unitno fobjid,z.zf_itemno zf_itemno,z.zf_itemname zf_itemname
    767                        FROM (
    768                                 SELECT Z.voucher_type,
    769                                        '拨清算资金 ' purpose,
    770                                        z.amt  zf_item_amt,
    771                                        z.prjno  prjno,
    772                                        z.unitno,
    773                                        Z.SRC_ID,
    774                                        Z.budget_type,
    775                                        Z.budgetno,
    776                                        '' zf_itemno,
    777                                        '' zf_itemname,
    778                                        (select bz.org_type  from bs_zjly bz where bz.fundno=z.src_id ) ORG_TYPE
    779                                       -- z.AFFIRM_DATE
    780                                   FROM  gk_zfpz  Z
    781                                  WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    782                                      and z.src_id='013' /*非税收入专户*/
    783                              ) Z
    784                             order by z.budgetno
    785                       )
    786                     )
    787                     ;
    788                   ---借方:
    789 
    790                     select sum(a.fcredit) into v_total from gk_zwentry a where a.fserialnum = v_fserialnum_1 ;
    791 
    792                     insert into gk_zwentry
    793                       (fserialnum,
    794                        fentryid,
    795                        facctid,
    796                        fclsid,
    797                        fexp,
    798                        fdebit,
    799                        fcredit,
    800                        fbanksettel,
    801                        ftransid,
    802                        fcyid,
    803                        fobjid,
    804                        zf_itemno,
    805                        zf_itemname,BUDGETID)
    806                       SELECT v_fserialnum_1,
    807                              '1',
    808                              (select (case when instr(bz.yswqs_fk_bank, '农村商业') > 0 then  '1004001'
    809                                         when instr(bz.yswqs_fk_bank, '农业') > 0 then      '1004002'
    810                                         when instr(bz.yswqs_fk_bank, '建设') > 0 then       '1004003'
    811                                         else           '1004001'       end) asfacctid
    812                                from bs_zjly bz  where bz.fundno = '013') ,
    813                              '0',
    814                              '拨清算资金',
    815                               v_total,
    816                              0,
    817                              '1',
    818                              '000',
    819                              'RMB',
    820                              '*',
    821                              '',
    822                              '',(select (case when instr(bz.yswqs_fk_bank, '农村商业') > 0 then  '1004001'
    823                                           when instr(bz.yswqs_fk_bank, '农业') > 0 then      '1004002'
    824                                           when instr(bz.yswqs_fk_bank, '建设') > 0 then       '1004003'
    825                                           else           '1004001'       end) asfacctid
    826                                  from bs_zjly bz  where bz.fundno = '113')||',' ||substr(fdate,0,4)|| ',*,*,*'
    827                         from dual;
    828 
    829                     insert into gk_zwvch_refer(FSERIALNUM, orign_type,orign_id,voucher_type,origin_teable,fmodule)
    830                      select v_fserialnum_1 ,
    831                          '3' ORIGN_TYPE,
    832                         z.id ORIGN_ID,
    833                         z.voucher_type VOUCHER_TYPE,
    834                         'GK_ZFPZ' ORIGIN_TEABLE,
    835                         '3' FMODULE
    836                    from gk_zfpz z
    837                    WHERE Z.id IN (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id )  and z.src_id='013' ;
    838              end if;
    839 
    840 
    841 
    842             /*    正常对碰的直接支付 授权支付  一般支付
    843                  注:当资金来源为非税收入(上年结转)时
    844                  借: 1004.001/002/004 其他财政存款.农行/农商行/建行
    845                  贷: 2011[单位] 应付国库集中支付(根据预算单位编码填列
    846                           根据第八点的付款帐号来进行区分:农行、 农商、  建行
    847 
    848                 会计科目编码组成:5005+功能分类科目编码
    849            */
    850 
    851            select count(1) into v_count_gkfszh  from gk_zfpz  Z  WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)   and z.src_id='113' ; /*非税收入专户(上年结转)*/
    852            if    v_count_gkfszh >0 then
    853                  ---插入主表
    854                    insert into gk_zwvch
    855                       (fserialnum,
    856                        FPERIOD,
    857                        fgroup,
    858                        fdate,
    859                        fnum,
    860                        fpreparer,
    861                        fattachment,
    862                        fmodule,
    863                        jz_database,
    864                        org_type,
    865                        jz_fserialnum,
    866                        orign_type,
    867                        make_date)
    868                       select v_fserialnum_2,
    869                              substr(fdate, 6, 2),
    870                              i_fgroup,
    871                              to_date(fdate, 'yyyy-MM-dd'),
    872                              0,
    873                              i_fpreparer,
    874                              v_count_gkfszh,
    875                              3,
    876                              i_databasename,
    877                              '1', --资金来源类型
    878                              0,
    879                              v_orign_type,
    880                              sysdate
    881 
    882                         from dual;
    883                     ---贷方数据插入     
    884                     insert into gk_zwentry(fserialnum,fentryid,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,budgetid)
    885                        select   fserialnum,ROWNUM+1,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname, budgetid from (
    886                        select fserialnum,ROWNUM+1,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,
    887                                 budgetno || ',' || year1 || ',' || budget_type || ',' || voucher_type || ',' || SRC_ID  budgetid
    888                        from (
    889                            SELECT Z.SRC_ID,Z.voucher_type,z.budget_type,z.budgetno,substr(to_char(sysdate,'yyyy-MM-dd'),0,4) year1,  v_fserialnum_2  fserialnum ,
    890                         '2011'||budgetno  facctid,
    891                         '1' fclsid ,
    892                         z.purpose fexp,0 fdebit, z.zf_item_amt  fcredit,'1' fbanksettel ,z.prjno ftransid,'RMB' fcyid,z.unitno fobjid,z.zf_itemno zf_itemno,z.zf_itemname zf_itemname
    893                          FROM (
    894                                   SELECT Z.voucher_type,
    895                                          '拨清算资金 ' purpose,
    896                                          z.amt  zf_item_amt,
    897                                          z.prjno  prjno,
    898                                          z.unitno,
    899                                          Z.SRC_ID,
    900                                          Z.budget_type,
    901                                          Z.budgetno,
    902                                          '' zf_itemno,
    903                                          '' zf_itemname,
    904                                          (select bz.org_type  from bs_zjly bz where bz.fundno=z.src_id ) ORG_TYPE
    905                                         -- z.AFFIRM_DATE
    906                                     FROM  gk_zfpz  Z
    907                                    WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    908                                        and z.src_id='113' /*非税收入专户*/
    909                                ) Z
    910                               order by z.budgetno
    911                         )
    912                       )
    913                       ;
    914                     ---借方:
    915 
    916                       select sum(a.fcredit) into v_total from gk_zwentry a where a.fserialnum = v_fserialnum_2 ;
    917 
    918                       insert into gk_zwentry
    919                         (fserialnum,
    920                          fentryid,
    921                          facctid,
    922                          fclsid,
    923                          fexp,
    924                          fdebit,
    925                          fcredit,
    926                          fbanksettel,
    927                          ftransid,
    928                          fcyid,
    929                          fobjid,
    930                          zf_itemno,
    931                          zf_itemname,BUDGETID)
    932                         SELECT v_fserialnum_2,
    933                                '1',
    934                                (select (case when instr(bz.yswqs_fk_bank, '农村商业') > 0 then  '1004001'
    935                                           when instr(bz.yswqs_fk_bank, '农业') > 0 then      '1004002'
    936                                           when instr(bz.yswqs_fk_bank, '建设') > 0 then       '1004003'
    937                                           else           '1004001'       end) asfacctid
    938                                  from bs_zjly bz  where bz.fundno = '113') ,
    939                                '0',
    940                                '拨清算资金',
    941                                 v_total,
    942                                0,
    943 
    944                                '1',
    945                                '000',
    946                                'RMB',
    947                                '*',
    948                                '',
    949                                '',(select (case when instr(bz.yswqs_fk_bank, '农村商业') > 0 then  '1004001'
    950                                           when instr(bz.yswqs_fk_bank, '农业') > 0 then      '1004002'
    951                                           when instr(bz.yswqs_fk_bank, '建设') > 0 then       '1004003'
    952                                           else           '1004001'       end) asfacctid
    953                                  from bs_zjly bz  where bz.fundno = '113')||',' || substr(fdate,0,4) || ',*,*,*'
    954                           from dual;
    955 
    956                       insert into gk_zwvch_refer(FSERIALNUM, orign_type,orign_id,voucher_type,origin_teable,fmodule)
    957                        select v_fserialnum_2 ,
    958                            '3' ORIGN_TYPE,
    959                           z.id ORIGN_ID,
    960                           z.voucher_type VOUCHER_TYPE,
    961                           'GK_ZFPZ' ORIGIN_TEABLE,
    962                           '3' FMODULE
    963                      from gk_zfpz z
    964                      WHERE Z.id IN (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    965                        and z.src_id='113' /*非税收入专户*/ ;
    966             end if;
    967 
    968 
    969 
    970          elsif   opertype='4' or  opertype='5'  then
    971 
    972             /*    财政专户名称为:部分退款的直接支付 授权支付
    973                  ---资金来源为非税收入
    974                  借:1004.001/002其他财政存款.农行/农商行
    975                  贷:5005财政专户管理资金支出 [功能分类科目编码  预算单位编码 ]
    976                       根据第八点的付款帐号来进行区分:农行、 农商
    977 
    978                 会计科目编码组成:5005+功能分类科目编码
    979           */
    980           select count(1) into v_count_gkfszh  from gk_part_refundment  Z   WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)   and z.src_id='013' ; /*非税收入专户*/
    981             if    v_count_gkfszh >0 then
    982                    --插入主表
    983                   insert into gk_zwvch
    984                     (fserialnum,
    985                      FPERIOD,
    986                      fgroup,
    987                      fdate,
    988                      fnum,
    989                      fpreparer,
    990                      fattachment,
    991                      fmodule,
    992                      jz_database,
    993                      org_type,
    994                      jz_fserialnum,
    995                      orign_type,
    996                      make_date)
    997                     select v_fserialnum_1,
    998                            substr(fdate, 6, 2),
    999                            i_fgroup,
    1000                            to_date(fdate, 'yyyy-MM-dd'),
    1001                            0,
    1002                            i_fpreparer,
    1003                            v_count_gkfszh,
    1004                            3,
    1005                            i_databasename,
    1006                            '1', --资金来源类型
    1007                            0,
    1008                            v_orign_type,
    1009                            sysdate
    1010 
    1011                       from dual;
    1012 
    1013 
    1014                  ---贷方数据插入     
    1015                   insert into gk_zwentry(fserialnum,fentryid,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,budgetid)
    1016                      select   fserialnum,ROWNUM+1,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname, budgetid from (
    1017                      select fserialnum,ROWNUM+1,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,
    1018                               budgetno || ',' ||substr(fdate,0,4)|| ',' || budget_type || ',' || voucher_type || ',' || SRC_ID  budgetid
    1019                      from (
    1020                          SELECT Z.SRC_ID,Z.voucher_type,z.budget_type,z.budgetno,substr(to_char(sysdate,'yyyy-MM-dd'),0,4) year1,  v_fserialnum_1  fserialnum ,
    1021                       '5005'||budgetno  facctid,
    1022                       '1' fclsid ,
    1023                       z.purpose fexp,0 fdebit,z.zf_item_amt fcredit,'1' fbanksettel ,z.prjno ftransid,'RMB' fcyid,z.unitno fobjid,z.zf_itemno zf_itemno,z.zf_itemname zf_itemname
    1024                        FROM (
    1025                                 SELECT Z.voucher_type,
    1026                                        '拨清算资金 ' purpose,
    1027                                        z.amt  zf_item_amt,
    1028                                        z.prjno  prjno,
    1029                                        z.unitno,
    1030                                        Z.SRC_ID,
    1031                                        Z.budget_type,
    1032                                        Z.budgetno,
    1033                                        '' zf_itemno,
    1034                                        '' zf_itemname,
    1035                                        (select bz.org_type  from bs_zjly bz where bz.fundno=z.src_id ) ORG_TYPE
    1036                                       -- z.AFFIRM_DATE
    1037                                   FROM  gk_part_refundment  Z
    1038                                  WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    1039                                      and z.src_id='013' /*非税收入专户*/
    1040                              ) Z
    1041                             order by z.budgetno
    1042                       )
    1043                     )
    1044                     ;
    1045                   ---借方:
    1046 
    1047                     select sum(a.fcredit) into v_total from gk_zwentry a where a.fserialnum = v_fserialnum_1 ;
    1048 
    1049                     insert into gk_zwentry
    1050                       (fserialnum,
    1051                        fentryid,
    1052                        facctid,
    1053                        fclsid,
    1054                        fexp,
    1055                        fdebit,
    1056                        fcredit,
    1057                        fbanksettel,
    1058                        ftransid,
    1059                        fcyid,
    1060                        fobjid,
    1061                        zf_itemno,
    1062                        zf_itemname,BUDGETID)
    1063                       SELECT v_fserialnum_1,
    1064                              '1',
    1065                              (select (case when instr(bz.yswqs_fk_bank, '农村商业') > 0 then  '1004001'
    1066                                         when instr(bz.yswqs_fk_bank, '农业') > 0 then      '1004002'
    1067                                         when instr(bz.yswqs_fk_bank, '建设') > 0 then       '1004003'
    1068                                         else           '1004001'       end) asfacctid
    1069                                from bs_zjly bz  where bz.fundno = '013') ,
    1070                              '0',
    1071                              '拨清算资金',
    1072                               v_total,
    1073                              0,
    1074                              '1',
    1075                              '000',
    1076                              'RMB',
    1077                              '*',
    1078                              '',
    1079                              '',(select (case when instr(bz.yswqs_fk_bank, '农村商业') > 0 then  '1004001'
    1080                                           when instr(bz.yswqs_fk_bank, '农业') > 0 then      '1004002'
    1081                                           when instr(bz.yswqs_fk_bank, '建设') > 0 then       '1004003'
    1082                                           else           '1004001'       end) asfacctid
    1083                                  from bs_zjly bz  where bz.fundno = '113')||',' ||substr(fdate,0,4)|| ',*,*,*'
    1084                         from dual;
    1085 
    1086                     insert into gk_zwvch_refer(FSERIALNUM, orign_type,orign_id,voucher_type,origin_teable,fmodule)
    1087                      select v_fserialnum_1 ,
    1088                          '3' ORIGN_TYPE,
    1089                         z.id ORIGN_ID,
    1090                         z.voucher_type VOUCHER_TYPE,
    1091                         'GK_PART_REFUNDMENT' ORIGIN_TEABLE,
    1092                         '3' FMODULE
    1093                    from gk_part_refundment z
    1094                    WHERE Z.id IN (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id )  and z.src_id='013' ;
    1095              end if;
    1096 
    1097 
    1098 
    1099             /*    部分退款的直接支付 授权支付
    1100                  注:当资金来源为非税收入(上年结转)时
    1101                  借: 1004.001/002/004 其他财政存款.农行/农商行/建行
    1102                  贷: 2011[单位] 应付国库集中支付(根据预算单位编码填列
    1103                           根据第八点的付款帐号来进行区分:农行、 农商、  建行
    1104 
    1105                 会计科目编码组成:5005+功能分类科目编码
    1106            */
    1107 
    1108            select count(1) into v_count_gkfszh  from gk_part_refundment  Z  WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)   and z.src_id='113' ; /*非税收入专户(上年结转)*/
    1109            if    v_count_gkfszh >0 then
    1110                  ---插入主表
    1111                    insert into gk_zwvch
    1112                       (fserialnum,
    1113                        FPERIOD,
    1114                        fgroup,
    1115                        fdate,
    1116                        fnum,
    1117                        fpreparer,
    1118                        fattachment,
    1119                        fmodule,
    1120                        jz_database,
    1121                        org_type,
    1122                        jz_fserialnum,
    1123                        orign_type,
    1124                        make_date)
    1125                       select v_fserialnum_2,
    1126                              substr(fdate, 6, 2),
    1127                              i_fgroup,
    1128                              to_date(fdate, 'yyyy-MM-dd'),
    1129                              0,
    1130                              i_fpreparer,
    1131                              v_count_gkfszh,
    1132                              3,
    1133                              i_databasename,
    1134                              '1', --资金来源类型
    1135                              0,
    1136                              v_orign_type,
    1137                              sysdate
    1138 
    1139                         from dual;
    1140                     ---贷方数据插入     
    1141                     insert into gk_zwentry(fserialnum,fentryid,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,budgetid)
    1142                        select   fserialnum,ROWNUM+1,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname, budgetid from (
    1143                        select fserialnum,ROWNUM+1,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,
    1144                                 budgetno || ',' || year1 || ',' || budget_type || ',' || voucher_type || ',' || SRC_ID  budgetid
    1145                        from (
    1146                            SELECT Z.SRC_ID,Z.voucher_type,z.budget_type,z.budgetno,substr(to_char(sysdate,'yyyy-MM-dd'),0,4) year1,  v_fserialnum_2  fserialnum ,
    1147                         '2011'||budgetno  facctid,
    1148                         '1' fclsid ,
    1149                         z.purpose fexp,0 fdebit, z.zf_item_amt  fcredit,'1' fbanksettel ,z.prjno ftransid,'RMB' fcyid,z.unitno fobjid,z.zf_itemno zf_itemno,z.zf_itemname zf_itemname
    1150                          FROM (
    1151                                   SELECT Z.voucher_type,
    1152                                          '拨清算资金 ' purpose,
    1153                                          z.amt  zf_item_amt,
    1154                                          z.prjno  prjno,
    1155                                          z.unitno,
    1156                                          Z.SRC_ID,
    1157                                          Z.budget_type,
    1158                                          Z.budgetno,
    1159                                          '' zf_itemno,
    1160                                          '' zf_itemname,
    1161                                          (select bz.org_type  from bs_zjly bz where bz.fundno=z.src_id ) ORG_TYPE
    1162                                         -- z.AFFIRM_DATE
    1163                                     FROM  gk_part_refundment  Z
    1164                                    WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    1165                                        and z.src_id='113' /*非税收入专户*/
    1166                                ) Z
    1167                               order by z.budgetno
    1168                         )
    1169                       )
    1170                       ;
    1171                     ---借方:
    1172 
    1173                       select sum(a.fcredit) into v_total from gk_zwentry a where a.fserialnum = v_fserialnum_2 ;
    1174 
    1175                       insert into gk_zwentry
    1176                         (fserialnum,
    1177                          fentryid,
    1178                          facctid,
    1179                          fclsid,
    1180                          fexp,
    1181                          fdebit,
    1182                          fcredit,
    1183                          fbanksettel,
    1184                          ftransid,
    1185                          fcyid,
    1186                          fobjid,
    1187                          zf_itemno,
    1188                          zf_itemname,BUDGETID)
    1189                         SELECT v_fserialnum_2,
    1190                                '1',
    1191                                (select (case when instr(bz.yswqs_fk_bank, '农村商业') > 0 then  '1004001'
    1192                                           when instr(bz.yswqs_fk_bank, '农业') > 0 then      '1004002'
    1193                                           when instr(bz.yswqs_fk_bank, '建设') > 0 then       '1004003'
    1194                                           else           '1004001'       end) asfacctid
    1195                                  from bs_zjly bz  where bz.fundno = '113') ,
    1196                                '0',
    1197                                '拨清算资金',
    1198                                 v_total,
    1199                                0,
    1200 
    1201                                '1',
    1202                                '000',
    1203                                'RMB',
    1204                                '*',
    1205                                '',
    1206                                '',(select (case when instr(bz.yswqs_fk_bank, '农村商业') > 0 then  '1004001'
    1207                                           when instr(bz.yswqs_fk_bank, '农业') > 0 then      '1004002'
    1208                                           when instr(bz.yswqs_fk_bank, '建设') > 0 then       '1004003'
    1209                                           else           '1004001'       end) asfacctid
    1210                                  from bs_zjly bz  where bz.fundno = '113')||',' || substr(fdate,0,4) || ',*,*,*'
    1211                           from dual;
    1212 
    1213                       insert into gk_zwvch_refer(FSERIALNUM, orign_type,orign_id,voucher_type,origin_teable,fmodule)
    1214                        select v_fserialnum_2 ,
    1215                            '3' ORIGN_TYPE,
    1216                           z.id ORIGN_ID,
    1217                           z.voucher_type VOUCHER_TYPE,
    1218                           'GK_PART_REFUNDMENT' ORIGIN_TEABLE,
    1219                           '3' FMODULE
    1220                      from gk_part_refundment z
    1221                      WHERE Z.id IN (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    1222                        and z.src_id='113' /*非税收入专户*/ ;
    1223             end if;
    1224 
    1225 
    1226 
    1227 
    1228 
    1229 
    1230 
    1231 
    1232           elsif   opertype='7'    then
    1233               /*    财政专户名称为:部分退款的一般支付
    1234                  ---资金来源为非税收入
    1235                  借:1004.001/002其他财政存款.农行/农商行
    1236                  贷:5005财政专户管理资金支出 [功能分类科目编码  预算单位编码 ]
    1237                       根据第八点的付款帐号来进行区分:农行、 农商
    1238 
    1239                 会计科目编码组成:5005+功能分类科目编码
    1240           */
    1241           select count(1) into v_count_gkfszh  from (  select crbd.id  as id ,  '3' voucher_type , crb.reason as refundment_memo ,   crbd.pay_amt as amt , crbd.prjno as prjno  ,crb.unitno ,crb.src_id as SRC_ID ,crbd.budget_type ,crbd.budgetno  from  common_req_back crb,common_req_back_detail crbd where crb.id=crbd.common_req_back_id)  Z   WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)   and z.src_id='013' ; /*非税收入专户*/
    1242             if    v_count_gkfszh >0 then
    1243                    --插入主表
    1244                   insert into gk_zwvch
    1245                     (fserialnum,
    1246                      FPERIOD,
    1247                      fgroup,
    1248                      fdate,
    1249                      fnum,
    1250                      fpreparer,
    1251                      fattachment,
    1252                      fmodule,
    1253                      jz_database,
    1254                      org_type,
    1255                      jz_fserialnum,
    1256                      orign_type,
    1257                      make_date)
    1258                     select v_fserialnum_1,
    1259                            substr(fdate, 6, 2),
    1260                            i_fgroup,
    1261                            to_date(fdate, 'yyyy-MM-dd'),
    1262                            0,
    1263                            i_fpreparer,
    1264                            v_count_gkfszh,
    1265                            3,
    1266                            i_databasename,
    1267                            '1', --资金来源类型
    1268                            0,
    1269                            v_orign_type,
    1270                            sysdate
    1271 
    1272                       from dual;
    1273 
    1274 
    1275                  ---贷方数据插入     
    1276                   insert into gk_zwentry(fserialnum,fentryid,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,budgetid)
    1277                      select   fserialnum,ROWNUM+1,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname, budgetid from (
    1278                      select fserialnum,ROWNUM+1,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,
    1279                               budgetno || ',' ||substr(fdate,0,4)|| ',' || budget_type || ',' || voucher_type || ',' || SRC_ID  budgetid
    1280                      from (
    1281                          SELECT Z.SRC_ID,Z.voucher_type,z.budget_type,z.budgetno,substr(to_char(sysdate,'yyyy-MM-dd'),0,4) year1,  v_fserialnum_1  fserialnum ,
    1282                       '5005'||budgetno  facctid,
    1283                       '1' fclsid ,
    1284                       z.purpose fexp,0 fdebit,z.zf_item_amt fcredit,'1' fbanksettel ,z.prjno ftransid,'RMB' fcyid,z.unitno fobjid,z.zf_itemno zf_itemno,z.zf_itemname zf_itemname
    1285                        FROM (
    1286                                 SELECT Z.voucher_type,
    1287                                        '拨清算资金 ' purpose,
    1288                                        z.amt  zf_item_amt,
    1289                                        z.prjno  prjno,
    1290                                        z.unitno,
    1291                                        Z.SRC_ID,
    1292                                        Z.budget_type,
    1293                                        Z.budgetno,
    1294                                        '' zf_itemno,
    1295                                        '' zf_itemname,
    1296                                        (select bz.org_type  from bs_zjly bz where bz.fundno=z.src_id ) ORG_TYPE
    1297                                       -- z.AFFIRM_DATE
    1298                                   FROM  (  select crbd.id  as id ,  '3' voucher_type , crb.reason as refundment_memo ,   crbd.pay_amt as amt , crbd.prjno as prjno  ,crb.unitno ,crb.src_id as SRC_ID ,crbd.budget_type ,crbd.budgetno  from  common_req_back crb,common_req_back_detail crbd where crb.id=crbd.common_req_back_id)  Z
    1299                                  WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    1300                                      and z.src_id='013' /*非税收入专户*/
    1301                              ) Z
    1302                             order by z.budgetno
    1303                       )
    1304                     )
    1305                     ;
    1306                   ---借方:
    1307 
    1308                     select sum(a.fcredit) into v_total from gk_zwentry a where a.fserialnum = v_fserialnum_1 ;
    1309 
    1310                     insert into gk_zwentry
    1311                       (fserialnum,
    1312                        fentryid,
    1313                        facctid,
    1314                        fclsid,
    1315                        fexp,
    1316                        fdebit,
    1317                        fcredit,
    1318                        fbanksettel,
    1319                        ftransid,
    1320                        fcyid,
    1321                        fobjid,
    1322                        zf_itemno,
    1323                        zf_itemname,BUDGETID)
    1324                       SELECT v_fserialnum_1,
    1325                              '1',
    1326                              (select (case when instr(bz.yswqs_fk_bank, '农村商业') > 0 then  '1004001'
    1327                                         when instr(bz.yswqs_fk_bank, '农业') > 0 then      '1004002'
    1328                                         when instr(bz.yswqs_fk_bank, '建设') > 0 then       '1004003'
    1329                                         else           '1004001'       end) asfacctid
    1330                                from bs_zjly bz  where bz.fundno = '013') ,
    1331                              '0',
    1332                              '拨清算资金',
    1333                               v_total,
    1334                              0,
    1335                              '1',
    1336                              '000',
    1337                              'RMB',
    1338                              '*',
    1339                              '',
    1340                              '',(select (case when instr(bz.yswqs_fk_bank, '农村商业') > 0 then  '1004001'
    1341                                           when instr(bz.yswqs_fk_bank, '农业') > 0 then      '1004002'
    1342                                           when instr(bz.yswqs_fk_bank, '建设') > 0 then       '1004003'
    1343                                           else           '1004001'       end) asfacctid
    1344                                  from bs_zjly bz  where bz.fundno = '113')||',' ||substr(fdate,0,4)|| ',*,*,*'
    1345                         from dual;
    1346 
    1347                     insert into gk_zwvch_refer(FSERIALNUM, orign_type,orign_id,voucher_type,origin_teable,fmodule)
    1348                      select v_fserialnum_1 ,
    1349                          '3' ORIGN_TYPE,
    1350                         z.id ORIGN_ID,
    1351                         z.voucher_type VOUCHER_TYPE,
    1352                         'common_req_back_detail' ORIGIN_TEABLE,
    1353                         '3' FMODULE
    1354                    from (  select crbd.id  as id ,  '3' voucher_type , crb.reason as refundment_memo ,   crbd.pay_amt as amt , crbd.prjno as prjno  ,crb.unitno ,crb.src_id as SRC_ID ,crbd.budget_type ,crbd.budgetno  from  common_req_back crb,common_req_back_detail crbd where crb.id=crbd.common_req_back_id) z
    1355                    WHERE Z.id IN (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id )  and z.src_id='013' ;
    1356              end if;
    1357 
    1358 
    1359 
    1360             /*    部分退款的 一般支付
    1361                  注:当资金来源为非税收入(上年结转)时
    1362                  借: 1004.001/002/004 其他财政存款.农行/农商行/建行
    1363                  贷: 2011[单位] 应付国库集中支付(根据预算单位编码填列
    1364                           根据第八点的付款帐号来进行区分:农行、 农商、  建行
    1365 
    1366                 会计科目编码组成:5005+功能分类科目编码
    1367            */
    1368 
    1369            select count(1) into v_count_gkfszh  from (  select crbd.id  as id ,  '3' voucher_type , crb.reason as refundment_memo ,   crbd.pay_amt as amt , crbd.prjno as prjno  ,crb.unitno ,crb.src_id as SRC_ID ,crbd.budget_type ,crbd.budgetno  from  common_req_back crb,common_req_back_detail crbd where crb.id=crbd.common_req_back_id)  Z  WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)   and z.src_id='113' ; /*非税收入专户(上年结转)*/
    1370            if    v_count_gkfszh >0 then
    1371                  ---插入主表
    1372                    insert into gk_zwvch
    1373                       (fserialnum,
    1374                        FPERIOD,
    1375                        fgroup,
    1376                        fdate,
    1377                        fnum,
    1378                        fpreparer,
    1379                        fattachment,
    1380                        fmodule,
    1381                        jz_database,
    1382                        org_type,
    1383                        jz_fserialnum,
    1384                        orign_type,
    1385                        make_date)
    1386                       select v_fserialnum_2,
    1387                              substr(fdate, 6, 2),
    1388                              i_fgroup,
    1389                              to_date(fdate, 'yyyy-MM-dd'),
    1390                              0,
    1391                              i_fpreparer,
    1392                              v_count_gkfszh,
    1393                              3,
    1394                              i_databasename,
    1395                              '1', --资金来源类型
    1396                              0,
    1397                              v_orign_type,
    1398                              sysdate
    1399 
    1400                         from dual;
    1401                     ---贷方数据插入     
    1402                     insert into gk_zwentry(fserialnum,fentryid,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,budgetid)
    1403                        select   fserialnum,ROWNUM+1,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname, budgetid from (
    1404                        select fserialnum,ROWNUM+1,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,
    1405                                 budgetno || ',' || year1 || ',' || budget_type || ',' || voucher_type || ',' || SRC_ID  budgetid
    1406                        from (
    1407                            SELECT Z.SRC_ID,Z.voucher_type,z.budget_type,z.budgetno,substr(to_char(sysdate,'yyyy-MM-dd'),0,4) year1,  v_fserialnum_2  fserialnum ,
    1408                         '2011'||budgetno  facctid,
    1409                         '1' fclsid ,
    1410                         z.purpose fexp,0 fdebit, z.zf_item_amt  fcredit,'1' fbanksettel ,z.prjno ftransid,'RMB' fcyid,z.unitno fobjid,z.zf_itemno zf_itemno,z.zf_itemname zf_itemname
    1411                          FROM (
    1412                                   SELECT Z.voucher_type,
    1413                                          '拨清算资金 ' purpose,
    1414                                          z.amt  zf_item_amt,
    1415                                          z.prjno  prjno,
    1416                                          z.unitno,
    1417                                          Z.SRC_ID,
    1418                                          Z.budget_type,
    1419                                          Z.budgetno,
    1420                                          '' zf_itemno,
    1421                                          '' zf_itemname,
    1422                                          (select bz.org_type  from bs_zjly bz where bz.fundno=z.src_id ) ORG_TYPE
    1423                                         -- z.AFFIRM_DATE
    1424                                     FROM  (  select crbd.id  as id ,  '3' voucher_type , crb.reason as refundment_memo ,   crbd.pay_amt as amt , crbd.prjno as prjno  ,crb.unitno ,crb.src_id as SRC_ID ,crbd.budget_type ,crbd.budgetno  from  common_req_back crb,common_req_back_detail crbd where crb.id=crbd.common_req_back_id)  Z
    1425                                    WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    1426                                        and z.src_id='113' /*非税收入专户*/
    1427                                ) Z
    1428                               order by z.budgetno
    1429                         )
    1430                       )
    1431                       ;
    1432                     ---借方:
    1433 
    1434                       select sum(a.fcredit) into v_total from gk_zwentry a where a.fserialnum = v_fserialnum_2 ;
    1435 
    1436                       insert into gk_zwentry
    1437                         (fserialnum,
    1438                          fentryid,
    1439                          facctid,
    1440                          fclsid,
    1441                          fexp,
    1442                          fdebit,
    1443                          fcredit,
    1444                          fbanksettel,
    1445                          ftransid,
    1446                          fcyid,
    1447                          fobjid,
    1448                          zf_itemno,
    1449                          zf_itemname,BUDGETID)
    1450                         SELECT v_fserialnum_2,
    1451                                '1',
    1452                                (select (case when instr(bz.yswqs_fk_bank, '农村商业') > 0 then  '1004001'
    1453                                           when instr(bz.yswqs_fk_bank, '农业') > 0 then      '1004002'
    1454                                           when instr(bz.yswqs_fk_bank, '建设') > 0 then       '1004003'
    1455                                           else           '1004001'       end) as facctid
    1456                                  from bs_zjly bz  where bz.fundno = '113') ,
    1457                                '0',
    1458                                '拨清算资金',
    1459                                 v_total,
    1460                                0,
    1461 
    1462                                '1',
    1463                                '000',
    1464                                'RMB',
    1465                                '*',
    1466                                '',
    1467                                '',(select (case when instr(bz.yswqs_fk_bank, '农村商业') > 0 then  '1004001'
    1468                                           when instr(bz.yswqs_fk_bank, '农业') > 0 then      '1004002'
    1469                                           when instr(bz.yswqs_fk_bank, '建设') > 0 then       '1004003'
    1470                                           else           '1004001'       end) as facctid
    1471                                  from bs_zjly bz  where bz.fundno = '113')||',' || substr(fdate,0,4) || ',*,*,*'
    1472                           from dual;
    1473 
    1474                       insert into gk_zwvch_refer(FSERIALNUM, orign_type,orign_id,voucher_type,origin_teable,fmodule)
    1475                        select v_fserialnum_2 ,
    1476                            '3' ORIGN_TYPE,
    1477                           z.id ORIGN_ID,
    1478                           z.voucher_type VOUCHER_TYPE,
    1479                           'common_req_back_detail' ORIGIN_TEABLE,
    1480                           '3' FMODULE
    1481                      from  (  select crbd.id  as id ,  '3' voucher_type , crb.reason as refundment_memo ,   crbd.pay_amt as amt , crbd.prjno as prjno  ,crb.unitno ,crb.src_id as SRC_ID ,crbd.budget_type ,crbd.budgetno  from  common_req_back crb,common_req_back_detail crbd where crb.id=crbd.common_req_back_id) z
    1482                      WHERE Z.id IN (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    1483                        and z.src_id='113' /*非税收入专户*/ ;
    1484             end if;
    1485 
    1486 
    1487 
    1488 
    1489          end if;
    1490 --================================================================================================================
    1491 --==========                                机关事业单位养老保险专户                                        ========
    1492 --================================================================================================================  
    1493       elsif org_name='机关事业单位养老保险专户'  then
    1494           if opertype='0' or opertype='1' or opertype='6'  then
    1495 
    1496           /*
    1497               借:5005.209.11.01[预算单位]财政专户管理资金支出.社会保险基金支出.机关事业单位基本养老保险基金支出.基本养老支出
    1498               贷:1003.001.01财政专户存款.农商行.活期
    1499 
    1500               会计科目编码组成:5005+功能分类科目编码
    1501 
    1502           */
    1503 
    1504                insert into gk_zwvch
    1505                     (fserialnum,
    1506                      FPERIOD,
    1507                      fgroup,
    1508                      fdate,
    1509                      fnum,
    1510                      fpreparer,
    1511                      fattachment,
    1512                      fmodule,
    1513                      jz_database,
    1514                      org_type,
    1515                      jz_fserialnum,
    1516                      orign_type,
    1517                      make_date)
    1518                     select v_fserialnum_1,
    1519                            substr(fdate, 6, 2),
    1520                            i_fgroup,
    1521                            to_date(fdate, 'yyyy-MM-dd'),
    1522                            0,
    1523                            i_fpreparer,
    1524                            i_fattachment,
    1525                            3,
    1526                            i_databasename,
    1527                            '1', --资金来源类型
    1528                            0,
    1529                            v_orign_type,
    1530                            sysdate
    1531 
    1532                       from dual;
    1533 
    1534 
    1535                  ---借方数据插入     
    1536                   insert into gk_zwentry(fserialnum,fentryid,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,budgetid)
    1537                      select   fserialnum,ROWNUM,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname, budgetid from (
    1538                      select fserialnum,ROWNUM,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,
    1539                               budgetno || ',' ||substr(fdate,0,4)|| ',' || budget_type || ',' || voucher_type || ',' || SRC_ID  budgetid
    1540                      from (
    1541                          SELECT Z.SRC_ID,Z.voucher_type,z.budget_type,z.budgetno,substr(to_char(sysdate,'yyyy-MM-dd'),0,4) year1,  v_fserialnum_1  fserialnum ,
    1542                       '50052091101' facctid,
    1543                       '1' fclsid ,
    1544                       z.purpose fexp,z.zf_item_amt fdebit,0 fcredit,'1' fbanksettel ,z.prjno ftransid,'RMB' fcyid,z.unitno fobjid,z.zf_itemno zf_itemno,z.zf_itemname zf_itemname
    1545                        FROM (
    1546                                 SELECT Z.voucher_type,
    1547                                        '拨清算资金' purpose,
    1548                                        z.amt  zf_item_amt,
    1549                                        z.prjno  prjno,
    1550                                        z.unitno,
    1551                                        Z.SRC_ID,
    1552                                        Z.budget_type,
    1553                                        Z.budgetno,
    1554                                        '' zf_itemno,
    1555                                        '' zf_itemname,
    1556                                        (select bz.org_type  from bs_zjly bz where bz.fundno=z.src_id ) ORG_TYPE
    1557                                       -- z.AFFIRM_DATE
    1558                                   FROM  gk_zfpz  Z
    1559                                  WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    1560                              ) Z
    1561                             order by z.budgetno
    1562                       )
    1563                     )
    1564                     ;
    1565                   ---贷方:
    1566 
    1567                     select sum(a.fdebit) into v_total from gk_zwentry a where a.fserialnum = v_fserialnum_1 ;
    1568                     select max(a.fentryid) + 1 into v_max_index from gk_zwentry a where a.fserialnum = v_fserialnum_1;
    1569                     insert into gk_zwentry
    1570                       (fserialnum,
    1571                        fentryid,
    1572                        facctid,
    1573                        fclsid,
    1574                        fexp,
    1575                        fdebit,
    1576                        fcredit,
    1577                        fbanksettel,
    1578                        ftransid,
    1579                        fcyid,
    1580                        fobjid,
    1581                        zf_itemno,
    1582                        zf_itemname,BUDGETID)
    1583                       SELECT v_fserialnum_1,
    1584                              v_max_index,
    1585                              '100300101' as facctid ,
    1586                              '0',
    1587                             '拨清算资金',
    1588                              0,
    1589                              v_total,
    1590                              '1',
    1591                              '000',
    1592                              'RMB',
    1593                              '*',
    1594                              '',
    1595                              '','100300101'||',' ||substr(fdate,0,4)|| ',*,*,*'
    1596                         from dual;
    1597 
    1598                     insert into gk_zwvch_refer(FSERIALNUM, orign_type,orign_id,voucher_type,origin_teable,fmodule)
    1599                      select v_fserialnum_1 ,
    1600                          '1' ORIGN_TYPE,
    1601                         z.id ORIGN_ID,
    1602                         z.voucher_type VOUCHER_TYPE,
    1603                         'GK_ZFPZ' ORIGIN_TEABLE,
    1604                         '3' FMODULE
    1605                    from gk_zfpz z
    1606                    WHERE Z.id IN (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)   ;
    1607 
    1608 
    1609 
    1610 
    1611 
    1612 
    1613          elsif   opertype='2' or  opertype='3' then
    1614 
    1615            /*
    1616               (2)收退回清算资金
    1617               借:?? 1003.001.01财政专户存款.农商行.活期
    1618               贷:5005.209.11.01[预算单位]财政专户管理资金支出.社会保险基金支出.机关事业单位基本养老保险基金支出.基本养老支出
    1619 
    1620 
    1621               会计科目编码组成:5005+功能分类科目编码
    1622 
    1623            */
    1624            insert into gk_zwvch
    1625                     (fserialnum,
    1626                      FPERIOD,
    1627                      fgroup,
    1628                      fdate,
    1629                      fnum,
    1630                      fpreparer,
    1631                      fattachment,
    1632                      fmodule,
    1633                      jz_database,
    1634                      org_type,
    1635                      jz_fserialnum,
    1636                      orign_type,
    1637                      make_date)
    1638                     select v_fserialnum_1,
    1639                            substr(fdate, 6, 2),
    1640                            i_fgroup,
    1641                            to_date(fdate, 'yyyy-MM-dd'),
    1642                            0,
    1643                            i_fpreparer,
    1644                            i_fattachment,
    1645                            3,
    1646                            i_databasename,
    1647                            '1', --资金来源类型
    1648                            0,
    1649                            v_orign_type,
    1650                            sysdate
    1651 
    1652                       from dual;
    1653 
    1654 
    1655                  ---借方数据插入     
    1656                   insert into gk_zwentry(fserialnum,fentryid,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,budgetid)
    1657                      select   fserialnum,ROWNUM+1,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname, budgetid from (
    1658                      select fserialnum,ROWNUM+1,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,
    1659                               budgetno || ',' ||substr(fdate,0,4)|| ',' || budget_type || ',' || voucher_type || ',' || SRC_ID  budgetid
    1660                      from (
    1661                          SELECT Z.SRC_ID,Z.voucher_type,z.budget_type,z.budgetno,substr(to_char(sysdate,'yyyy-MM-dd'),0,4) year1,  v_fserialnum_1  fserialnum ,
    1662                       '50052091101' facctid,
    1663                       '1' fclsid ,
    1664                       z.purpose fexp,0 fdebit,z.zf_item_amt fcredit,'1' fbanksettel ,z.prjno ftransid,'RMB' fcyid,z.unitno fobjid,z.zf_itemno zf_itemno,z.zf_itemname zf_itemname
    1665                        FROM (
    1666                                 SELECT Z.voucher_type,
    1667                                         '拨清算资金' purpose,
    1668                                        z.amt  zf_item_amt,
    1669                                        z.prjno  prjno,
    1670                                        z.unitno,
    1671                                        Z.SRC_ID,
    1672                                        Z.budget_type,
    1673                                        Z.budgetno,
    1674                                        '' zf_itemno,
    1675                                        '' zf_itemname,
    1676                                        (select bz.org_type  from bs_zjly bz where bz.fundno=z.src_id ) ORG_TYPE
    1677                                       -- z.AFFIRM_DATE
    1678                                   FROM  gk_zfpz  Z
    1679                                  WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    1680                              ) Z
    1681                             order by z.budgetno
    1682                       )
    1683                     )
    1684                     ;
    1685                   ---借方:
    1686 
    1687                     select sum(a.fcredit) into v_total from gk_zwentry a where a.fserialnum = v_fserialnum_1 ;
    1688                     insert into gk_zwentry
    1689                       (fserialnum,
    1690                        fentryid,
    1691                        facctid,
    1692                        fclsid,
    1693                        fexp,
    1694                        fdebit,
    1695                        fcredit,
    1696                        fbanksettel,
    1697                        ftransid,
    1698                        fcyid,
    1699                        fobjid,
    1700                        zf_itemno,
    1701                        zf_itemname,BUDGETID)
    1702                       SELECT v_fserialnum_1,
    1703                              1,
    1704                              '100300101' as facctid ,
    1705                              '0',
    1706                              '拨清算资金',
    1707                              v_total,
    1708                              0,
    1709 
    1710                              '1',
    1711                              '000',
    1712                              'RMB',
    1713                              '*',
    1714                              '',
    1715                              '','100300101'||',' ||substr(fdate,0,4)|| ',*,*,*'
    1716                         from dual;
    1717 
    1718                     insert into gk_zwvch_refer(FSERIALNUM, orign_type,orign_id,voucher_type,origin_teable,fmodule)
    1719                      select v_fserialnum_1 ,
    1720                          '1' ORIGN_TYPE,
    1721                         z.id ORIGN_ID,
    1722                         z.voucher_type VOUCHER_TYPE,
    1723                         'GK_ZFPZ' ORIGIN_TEABLE,
    1724                         '3' FMODULE
    1725                    from gk_zfpz z
    1726                    WHERE Z.id IN (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)   ;
    1727 
    1728 
    1729 
    1730 
    1731 
    1732          elsif   opertype='4' or  opertype='5' then
    1733 
    1734 
    1735            /*
    1736               收退回清算资金
    1737               借:?? 1003.001.01财政专户存款.农商行.活期
    1738               贷:5005.209.11.01[预算单位]财政专户管理资金支出.社会保险基金支出.机关事业单位基本养老保险基金支出.基本养老支出
    1739 
    1740 
    1741               会计科目编码组成:5005+功能分类科目编码
    1742 
    1743            */
    1744             insert into gk_zwvch
    1745                     (fserialnum,
    1746                      FPERIOD,
    1747                      fgroup,
    1748                      fdate,
    1749                      fnum,
    1750                      fpreparer,
    1751                      fattachment,
    1752                      fmodule,
    1753                      jz_database,
    1754                      org_type,
    1755                      jz_fserialnum,
    1756                      orign_type,
    1757                      make_date)
    1758                     select v_fserialnum_1,
    1759                            substr(fdate, 6, 2),
    1760                            i_fgroup,
    1761                            to_date(fdate, 'yyyy-MM-dd'),
    1762                            0,
    1763                            i_fpreparer,
    1764                            i_fattachment,
    1765                            3,
    1766                            i_databasename,
    1767                            '1', --资金来源类型
    1768                            0,
    1769                            v_orign_type,
    1770                            sysdate
    1771 
    1772                       from dual;
    1773 
    1774 
    1775 
    1776                  ---借方数据插入     
    1777                   insert into gk_zwentry(fserialnum,fentryid,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,budgetid)
    1778                      select   fserialnum,ROWNUM+1,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname, budgetid from (
    1779                      select fserialnum,ROWNUM+1,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,
    1780                               budgetno || ',' ||substr(fdate,0,4)|| ',' || budget_type || ',' || voucher_type || ',' || SRC_ID  budgetid
    1781                      from (
    1782                          SELECT Z.SRC_ID,Z.voucher_type,z.budget_type,z.budgetno,substr(to_char(sysdate,'yyyy-MM-dd'),0,4) year1,  v_fserialnum_1  fserialnum ,
    1783                       '50052091101' facctid,
    1784                       '1' fclsid ,
    1785                       z.purpose fexp,0 fdebit,z.zf_item_amt fcredit,'1' fbanksettel ,z.prjno ftransid,'RMB' fcyid,z.unitno fobjid,z.zf_itemno zf_itemno,z.zf_itemname zf_itemname
    1786                        FROM (
    1787                                 SELECT Z.voucher_type,
    1788                                         '拨清算资金' purpose,
    1789                                        z.amt  zf_item_amt,
    1790                                        z.prjno  prjno,
    1791                                        z.unitno,
    1792                                        Z.SRC_ID,
    1793                                        Z.budget_type,
    1794                                        Z.budgetno,
    1795                                        '' zf_itemno,
    1796                                        '' zf_itemname,
    1797                                        (select bz.org_type  from bs_zjly bz where bz.fundno=z.src_id ) ORG_TYPE
    1798                                       -- z.AFFIRM_DATE
    1799                                   FROM  GK_PART_REFUNDMENT  Z
    1800                                  WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    1801                              ) Z
    1802                             order by z.budgetno
    1803                       )
    1804                     )
    1805                     ;
    1806 
    1807                   ---借方:
    1808 
    1809                     select sum(a.fcredit) into v_total from gk_zwentry a where a.fserialnum = v_fserialnum_1 ;
    1810                     insert into gk_zwentry
    1811                       (fserialnum,
    1812                        fentryid,
    1813                        facctid,
    1814                        fclsid,
    1815                        fexp,
    1816                        fdebit,
    1817                        fcredit,
    1818                        fbanksettel,
    1819                        ftransid,
    1820                        fcyid,
    1821                        fobjid,
    1822                        zf_itemno,
    1823                        zf_itemname,BUDGETID)
    1824                       SELECT v_fserialnum_1,
    1825                              1,
    1826                              '100300101' as facctid ,
    1827                              '0',
    1828                              '拨清算资金',
    1829                              v_total,
    1830                              0,
    1831 
    1832                              '1',
    1833                              '000',
    1834                              'RMB',
    1835                              '*',
    1836                              '',
    1837                              '','100300101'||',' ||substr(fdate,0,4)|| ',*,*,*'
    1838                         from dual;
    1839 
    1840 
    1841                     insert into gk_zwvch_refer(FSERIALNUM, orign_type,orign_id,voucher_type,origin_teable,fmodule)
    1842                      select v_fserialnum_1 ,
    1843                          '1' ORIGN_TYPE,
    1844                         z.id ORIGN_ID,
    1845                         z.voucher_type VOUCHER_TYPE,
    1846                         'GK_PART_REFUNDMENT' ORIGIN_TEABLE,
    1847                         '3' FMODULE
    1848                    from GK_PART_REFUNDMENT z
    1849                    WHERE Z.id IN (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)   ;
    1850 
    1851 
    1852 
    1853          elsif   opertype='7' then
    1854 
    1855            /*
    1856               收退回清算资金
    1857               借:?? 1003.001.01财政专户存款.农商行.活期
    1858               贷:5005.209.11.01[预算单位]财政专户管理资金支出.社会保险基金支出.机关事业单位基本养老保险基金支出.基本养老支出
    1859 
    1860 
    1861               会计科目编码组成:5005+功能分类科目编码
    1862 
    1863            */
    1864           insert into gk_zwvch
    1865                     (fserialnum,
    1866                      FPERIOD,
    1867                      fgroup,
    1868                      fdate,
    1869                      fnum,
    1870                      fpreparer,
    1871                      fattachment,
    1872                      fmodule,
    1873                      jz_database,
    1874                      org_type,
    1875                      jz_fserialnum,
    1876                      orign_type,
    1877                      make_date)
    1878                     select v_fserialnum_1,
    1879                            substr(fdate, 6, 2),
    1880                            i_fgroup,
    1881                            to_date(fdate, 'yyyy-MM-dd'),
    1882                            0,
    1883                            i_fpreparer,
    1884                            i_fattachment,
    1885                            3,
    1886                            i_databasename,
    1887                            '1', --资金来源类型
    1888                            0,
    1889                            v_orign_type,
    1890                            sysdate
    1891 
    1892                       from dual;
    1893 
    1894 
    1895 
    1896                  ---借方数据插入     
    1897                   insert into gk_zwentry(fserialnum,fentryid,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,budgetid)
    1898                      select   fserialnum,ROWNUM+1,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname, budgetid from (
    1899                      select fserialnum,ROWNUM+1,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,
    1900                               budgetno || ',' ||substr(fdate,0,4)|| ',' || budget_type || ',' || voucher_type || ',' || SRC_ID  budgetid
    1901                      from (
    1902                          SELECT Z.SRC_ID,Z.voucher_type,z.budget_type,z.budgetno,substr(to_char(sysdate,'yyyy-MM-dd'),0,4) year1,  v_fserialnum_1  fserialnum ,
    1903                       '50052091101' facctid,
    1904                       '1' fclsid ,
    1905                       z.purpose fexp,0 fdebit,z.zf_item_amt fcredit,'1' fbanksettel ,z.prjno ftransid,'RMB' fcyid,z.unitno fobjid,z.zf_itemno zf_itemno,z.zf_itemname zf_itemname
    1906                        FROM (
    1907                                 SELECT Z.voucher_type,
    1908                                         '拨清算资金' purpose,
    1909                                        z.amt  zf_item_amt,
    1910                                        z.prjno  prjno,
    1911                                        z.unitno,
    1912                                        Z.SRC_ID,
    1913                                        Z.budget_type,
    1914                                        Z.budgetno,
    1915                                        '' zf_itemno,
    1916                                        '' zf_itemname,
    1917                                        (select bz.org_type  from bs_zjly bz where bz.fundno=z.src_id ) ORG_TYPE
    1918                                       -- z.AFFIRM_DATE
    1919                                   FROM   (  select crbd.id  as id ,  '3' voucher_type , crb.reason as refundment_memo ,   crbd.pay_amt as amt , crbd.prjno as prjno  ,crb.unitno ,crb.src_id as SRC_ID ,crbd.budget_type ,crbd.budgetno  from  common_req_back crb,common_req_back_detail crbd where crb.id=crbd.common_req_back_id)   Z
    1920                                  WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    1921                              ) Z
    1922                             order by z.budgetno
    1923                       )
    1924                     )
    1925                     ;
    1926 
    1927                   ---借方:
    1928 
    1929                     select sum(a.fcredit) into v_total from gk_zwentry a where a.fserialnum = v_fserialnum_1 ;
    1930                     insert into gk_zwentry
    1931                       (fserialnum,
    1932                        fentryid,
    1933                        facctid,
    1934                        fclsid,
    1935                        fexp,
    1936                        fdebit,
    1937                        fcredit,
    1938                        fbanksettel,
    1939                        ftransid,
    1940                        fcyid,
    1941                        fobjid,
    1942                        zf_itemno,
    1943                        zf_itemname,BUDGETID)
    1944                       SELECT v_fserialnum_1,
    1945                              1,
    1946                              '100300101' as facctid ,
    1947                              '0',
    1948                              '拨清算资金',
    1949                              v_total,
    1950                              0,
    1951 
    1952                              '1',
    1953                              '000',
    1954                              'RMB',
    1955                              '*',
    1956                              '',
    1957                              '','100300101'||',' ||substr(fdate,0,4)|| ',*,*,*'
    1958                         from dual;
    1959 
    1960 
    1961                     insert into gk_zwvch_refer(FSERIALNUM, orign_type,orign_id,voucher_type,origin_teable,fmodule)
    1962                      select v_fserialnum_1 ,
    1963                          '1' ORIGN_TYPE,
    1964                         z.id ORIGN_ID,
    1965                         z.voucher_type VOUCHER_TYPE,
    1966                         'common_req_back_detail' ORIGIN_TEABLE,
    1967                         '3' FMODULE
    1968                    from  (  select crbd.id  as id ,  '3' voucher_type , crb.reason as refundment_memo ,   crbd.pay_amt as amt , crbd.prjno as prjno  ,crb.unitno ,crb.src_id as SRC_ID ,crbd.budget_type ,crbd.budgetno  from  common_req_back crb,common_req_back_detail crbd where crb.id=crbd.common_req_back_id)  z
    1969                    WHERE Z.id IN (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)   ;
    1970 
    1971 
    1972          end if;
    1973 
    1974 
    1975 --================================================================================================================
    1976 --==========                                全征地农民养老保险专户                                          ========
    1977 --================================================================================================================  
    1978       elsif org_name='全征地农民养老保险专户'  then
    1979          if opertype='0' or opertype='1' or opertype='6'  then
    1980           /*
    1981               支出
    1982               借:5005.208.99.01[预算单位]财政专户管理资金支出.社会保障与就业.其他社会保障与就业支出.其他社会保障与就业支出
    1983               贷:1003.001.01财政专户存款.农商行.活期
    1984 
    1985           */
    1986              insert into gk_zwvch
    1987                     (fserialnum,
    1988                      FPERIOD,
    1989                      fgroup,
    1990                      fdate,
    1991                      fnum,
    1992                      fpreparer,
    1993                      fattachment,
    1994                      fmodule,
    1995                      jz_database,
    1996                      org_type,
    1997                      jz_fserialnum,
    1998                      orign_type,
    1999                      make_date)
    2000                     select v_fserialnum_1,
    2001                            substr(fdate, 6, 2),
    2002                            i_fgroup,
    2003                            to_date(fdate, 'yyyy-MM-dd'),
    2004                            0,
    2005                            i_fpreparer,
    2006                            i_fattachment,
    2007                            3,
    2008                            i_databasename,
    2009                            '1', --资金来源类型
    2010                            0,
    2011                            v_orign_type,
    2012                            sysdate
    2013 
    2014                       from dual;
    2015 
    2016 
    2017                  ---借方数据插入     
    2018                   insert into gk_zwentry(fserialnum,fentryid,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,budgetid)
    2019                      select   fserialnum,ROWNUM,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname, budgetid from (
    2020                      select fserialnum,ROWNUM,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,
    2021                               budgetno || ',' ||substr(fdate,0,4)|| ',' || budget_type || ',' || voucher_type || ',' || SRC_ID  budgetid
    2022                      from (
    2023                          SELECT Z.SRC_ID,Z.voucher_type,z.budget_type,z.budgetno,substr(to_char(sysdate,'yyyy-MM-dd'),0,4) year1,  v_fserialnum_1  fserialnum ,
    2024                       '50052089901' facctid,
    2025                       '1' fclsid ,
    2026                       z.purpose fexp,z.zf_item_amt fdebit,0 fcredit,'1' fbanksettel ,z.prjno ftransid,'RMB' fcyid,z.unitno fobjid,z.zf_itemno zf_itemno,z.zf_itemname zf_itemname
    2027                        FROM (
    2028                                 SELECT Z.voucher_type,
    2029                                        '拨清算资金' purpose,
    2030                                        z.amt  zf_item_amt,
    2031                                        z.prjno  prjno,
    2032                                        z.unitno,
    2033                                        Z.SRC_ID,
    2034                                        Z.budget_type,
    2035                                        Z.budgetno,
    2036                                        '' zf_itemno,
    2037                                        '' zf_itemname,
    2038                                        (select bz.org_type  from bs_zjly bz where bz.fundno=z.src_id ) ORG_TYPE
    2039                                       -- z.AFFIRM_DATE
    2040                                   FROM  gk_zfpz  Z
    2041                                  WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    2042                              ) Z
    2043                             order by z.budgetno
    2044                       )
    2045                     )
    2046                     ;
    2047                   ---贷方:
    2048 
    2049                     select sum(a.fdebit) into v_total from gk_zwentry a where a.fserialnum = v_fserialnum_1 ;
    2050                     select max(a.fentryid) + 1 into v_max_index from gk_zwentry a where a.fserialnum = v_fserialnum_1;
    2051                     insert into gk_zwentry
    2052                       (fserialnum,
    2053                        fentryid,
    2054                        facctid,
    2055                        fclsid,
    2056                        fexp,
    2057                        fdebit,
    2058                        fcredit,
    2059                        fbanksettel,
    2060                        ftransid,
    2061                        fcyid,
    2062                        fobjid,
    2063                        zf_itemno,
    2064                        zf_itemname,BUDGETID)
    2065                       SELECT v_fserialnum_1,
    2066                              v_max_index,
    2067                              '100300101' as facctid ,
    2068                              '0',
    2069                             '拨清算资金',
    2070                              0,
    2071                              v_total,
    2072                              '1',
    2073                              '000',
    2074                              'RMB',
    2075                              '*',
    2076                              '',
    2077                              '','100300101'||',' ||substr(fdate,0,4)|| ',*,*,*'
    2078                         from dual;
    2079 
    2080                     insert into gk_zwvch_refer(FSERIALNUM, orign_type,orign_id,voucher_type,origin_teable,fmodule)
    2081                      select v_fserialnum_1 ,
    2082                          '1' ORIGN_TYPE,
    2083                         z.id ORIGN_ID,
    2084                         z.voucher_type VOUCHER_TYPE,
    2085                         'GK_ZFPZ' ORIGIN_TEABLE,
    2086                         '3' FMODULE
    2087                    from gk_zfpz z
    2088                    WHERE Z.id IN (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)   ;
    2089 
    2090 
    2091 
    2092          elsif   opertype='2' or  opertype='3' then
    2093 
    2094            /*
    2095                退款
    2096               借: 1003.001.01财政专户存款.农商行.活期
    2097               贷:5005.208.99.01[预算单位]财政专户管理资金支出.社会保障与就业.其他社会保障与就业支出.其他社会保障与就业支出
    2098 
    2099           */
    2100            insert into gk_zwvch
    2101                     (fserialnum,
    2102                      FPERIOD,
    2103                      fgroup,
    2104                      fdate,
    2105                      fnum,
    2106                      fpreparer,
    2107                      fattachment,
    2108                      fmodule,
    2109                      jz_database,
    2110                      org_type,
    2111                      jz_fserialnum,
    2112                      orign_type,
    2113                      make_date)
    2114                     select v_fserialnum_1,
    2115                            substr(fdate, 6, 2),
    2116                            i_fgroup,
    2117                            to_date(fdate, 'yyyy-MM-dd'),
    2118                            0,
    2119                            i_fpreparer,
    2120                            i_fattachment,
    2121                            3,
    2122                            i_databasename,
    2123                            '1', --资金来源类型
    2124                            0,
    2125                            v_orign_type,
    2126                            sysdate
    2127 
    2128                       from dual;
    2129 
    2130 
    2131                  ---借方数据插入     
    2132                   insert into gk_zwentry(fserialnum,fentryid,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,budgetid)
    2133                      select   fserialnum,ROWNUM+1,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname, budgetid from (
    2134                      select fserialnum,ROWNUM+1,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,
    2135                               budgetno || ',' ||substr(fdate,0,4)|| ',' || budget_type || ',' || voucher_type || ',' || SRC_ID  budgetid
    2136                      from (
    2137                          SELECT Z.SRC_ID,Z.voucher_type,z.budget_type,z.budgetno,substr(to_char(sysdate,'yyyy-MM-dd'),0,4) year1,  v_fserialnum_1  fserialnum ,
    2138                       '50052089901' facctid,
    2139                       '1' fclsid ,
    2140                       z.purpose fexp,0 fdebit,z.zf_item_amt fcredit,'1' fbanksettel ,z.prjno ftransid,'RMB' fcyid,z.unitno fobjid,z.zf_itemno zf_itemno,z.zf_itemname zf_itemname
    2141                        FROM (
    2142                                 SELECT Z.voucher_type,
    2143                                         '拨清算资金' purpose,
    2144                                        z.amt  zf_item_amt,
    2145                                        z.prjno  prjno,
    2146                                        z.unitno,
    2147                                        Z.SRC_ID,
    2148                                        Z.budget_type,
    2149                                        Z.budgetno,
    2150                                        '' zf_itemno,
    2151                                        '' zf_itemname,
    2152                                        (select bz.org_type  from bs_zjly bz where bz.fundno=z.src_id ) ORG_TYPE
    2153                                       -- z.AFFIRM_DATE
    2154                                   FROM  gk_zfpz  Z
    2155                                  WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    2156                              ) Z
    2157                             order by z.budgetno
    2158                       )
    2159                     )
    2160                     ;
    2161                   ---借方:
    2162 
    2163                     select sum(a.fcredit) into v_total from gk_zwentry a where a.fserialnum = v_fserialnum_1 ;
    2164                     insert into gk_zwentry
    2165                       (fserialnum,
    2166                        fentryid,
    2167                        facctid,
    2168                        fclsid,
    2169                        fexp,
    2170                        fdebit,
    2171                        fcredit,
    2172                        fbanksettel,
    2173                        ftransid,
    2174                        fcyid,
    2175                        fobjid,
    2176                        zf_itemno,
    2177                        zf_itemname,BUDGETID)
    2178                       SELECT v_fserialnum_1,
    2179                              1,
    2180                              '100300101' as facctid ,
    2181                              '0',
    2182                              '拨清算资金',
    2183                              v_total,
    2184                              0,
    2185 
    2186                              '1',
    2187                              '000',
    2188                              'RMB',
    2189                              '*',
    2190                              '',
    2191                              '','100300101'||',' ||substr(fdate,0,4)|| ',*,*,*'
    2192                         from dual;
    2193 
    2194                     insert into gk_zwvch_refer(FSERIALNUM, orign_type,orign_id,voucher_type,origin_teable,fmodule)
    2195                      select v_fserialnum_1 ,
    2196                          '1' ORIGN_TYPE,
    2197                         z.id ORIGN_ID,
    2198                         z.voucher_type VOUCHER_TYPE,
    2199                         'GK_ZFPZ' ORIGIN_TEABLE,
    2200                         '3' FMODULE
    2201                    from gk_zfpz z
    2202                    WHERE Z.id IN (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)   ;
    2203 
    2204 
    2205 
    2206 
    2207 
    2208          elsif   opertype='4' or  opertype='5' then
    2209            /*
    2210                退款
    2211               借: 1003.001.01财政专户存款.农商行.活期
    2212               贷:5005.208.99.01[预算单位]财政专户管理资金支出.社会保障与就业.其他社会保障与就业支出.其他社会保障与就业支出
    2213 
    2214           */
    2215            insert into gk_zwvch
    2216                     (fserialnum,
    2217                      FPERIOD,
    2218                      fgroup,
    2219                      fdate,
    2220                      fnum,
    2221                      fpreparer,
    2222                      fattachment,
    2223                      fmodule,
    2224                      jz_database,
    2225                      org_type,
    2226                      jz_fserialnum,
    2227                      orign_type,
    2228                      make_date)
    2229                     select v_fserialnum_1,
    2230                            substr(fdate, 6, 2),
    2231                            i_fgroup,
    2232                            to_date(fdate, 'yyyy-MM-dd'),
    2233                            0,
    2234                            i_fpreparer,
    2235                            i_fattachment,
    2236                            3,
    2237                            i_databasename,
    2238                            '1', --资金来源类型
    2239                            0,
    2240                            v_orign_type,
    2241                            sysdate
    2242 
    2243                       from dual;
    2244 
    2245 
    2246                  ---借方数据插入     
    2247                   insert into gk_zwentry(fserialnum,fentryid,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,budgetid)
    2248                      select   fserialnum,ROWNUM+1,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname, budgetid from (
    2249                      select fserialnum,ROWNUM+1,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,
    2250                               budgetno || ',' ||substr(fdate,0,4)|| ',' || budget_type || ',' || voucher_type || ',' || SRC_ID  budgetid
    2251                      from (
    2252                          SELECT Z.SRC_ID,Z.voucher_type,z.budget_type,z.budgetno,substr(to_char(sysdate,'yyyy-MM-dd'),0,4) year1,  v_fserialnum_1  fserialnum ,
    2253                       '50052089901' facctid,
    2254                       '1' fclsid ,
    2255                       z.purpose fexp,0 fdebit,z.zf_item_amt fcredit,'1' fbanksettel ,z.prjno ftransid,'RMB' fcyid,z.unitno fobjid,z.zf_itemno zf_itemno,z.zf_itemname zf_itemname
    2256                        FROM (
    2257                                 SELECT Z.voucher_type,
    2258                                         '拨清算资金' purpose,
    2259                                        z.amt  zf_item_amt,
    2260                                        z.prjno  prjno,
    2261                                        z.unitno,
    2262                                        Z.SRC_ID,
    2263                                        Z.budget_type,
    2264                                        Z.budgetno,
    2265                                        '' zf_itemno,
    2266                                        '' zf_itemname,
    2267                                        (select bz.org_type  from bs_zjly bz where bz.fundno=z.src_id ) ORG_TYPE
    2268                                       -- z.AFFIRM_DATE
    2269                                   FROM  GK_PART_REFUNDMENT  Z
    2270                                  WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    2271                              ) Z
    2272                             order by z.budgetno
    2273                       )
    2274                     )
    2275                     ;
    2276                   ---借方:
    2277 
    2278                     select sum(a.fcredit) into v_total from gk_zwentry a where a.fserialnum = v_fserialnum_1 ;
    2279                     insert into gk_zwentry
    2280                       (fserialnum,
    2281                        fentryid,
    2282                        facctid,
    2283                        fclsid,
    2284                        fexp,
    2285                        fdebit,
    2286                        fcredit,
    2287                        fbanksettel,
    2288                        ftransid,
    2289                        fcyid,
    2290                        fobjid,
    2291                        zf_itemno,
    2292                        zf_itemname,BUDGETID)
    2293                       SELECT v_fserialnum_1,
    2294                              1,
    2295                              '100300101' as facctid ,
    2296                              '0',
    2297                              '拨清算资金',
    2298                              v_total,
    2299                              0,
    2300 
    2301                              '1',
    2302                              '000',
    2303                              'RMB',
    2304                              '*',
    2305                              '',
    2306                              '','100300101'||',' ||substr(fdate,0,4)|| ',*,*,*'
    2307                         from dual;
    2308 
    2309                     insert into gk_zwvch_refer(FSERIALNUM, orign_type,orign_id,voucher_type,origin_teable,fmodule)
    2310                      select v_fserialnum_1 ,
    2311                          '1' ORIGN_TYPE,
    2312                         z.id ORIGN_ID,
    2313                         z.voucher_type VOUCHER_TYPE,
    2314                         'GK_PART_REFUNDMENT' ORIGIN_TEABLE,
    2315                         '3' FMODULE
    2316                    from GK_PART_REFUNDMENT z
    2317                    WHERE Z.id IN (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)   ;
    2318 
    2319 
    2320 
    2321          elsif   opertype='7' then
    2322             /*
    2323                退款
    2324               借: 1003.001.01财政专户存款.农商行.活期
    2325               贷:5005.208.99.01[预算单位]财政专户管理资金支出.社会保障与就业.其他社会保障与就业支出.其他社会保障与就业支出
    2326 
    2327           */
    2328            insert into gk_zwvch
    2329                     (fserialnum,
    2330                      FPERIOD,
    2331                      fgroup,
    2332                      fdate,
    2333                      fnum,
    2334                      fpreparer,
    2335                      fattachment,
    2336                      fmodule,
    2337                      jz_database,
    2338                      org_type,
    2339                      jz_fserialnum,
    2340                      orign_type,
    2341                      make_date)
    2342                     select v_fserialnum_1,
    2343                            substr(fdate, 6, 2),
    2344                            i_fgroup,
    2345                            to_date(fdate, 'yyyy-MM-dd'),
    2346                            0,
    2347                            i_fpreparer,
    2348                            i_fattachment,
    2349                            3,
    2350                            i_databasename,
    2351                            '1', --资金来源类型
    2352                            0,
    2353                            v_orign_type,
    2354                            sysdate
    2355 
    2356                       from dual;
    2357 
    2358 
    2359                  ---借方数据插入     
    2360                   insert into gk_zwentry(fserialnum,fentryid,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,budgetid)
    2361                      select   fserialnum,ROWNUM+1,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname, budgetid from (
    2362                      select fserialnum,ROWNUM+1,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,
    2363                               budgetno || ',' ||substr(fdate,0,4)|| ',' || budget_type || ',' || voucher_type || ',' || SRC_ID  budgetid
    2364                      from (
    2365                          SELECT Z.SRC_ID,Z.voucher_type,z.budget_type,z.budgetno,substr(to_char(sysdate,'yyyy-MM-dd'),0,4) year1,  v_fserialnum_1  fserialnum ,
    2366                       '50052089901' facctid,
    2367                       '1' fclsid ,
    2368                       z.purpose fexp,0 fdebit,z.zf_item_amt fcredit,'1' fbanksettel ,z.prjno ftransid,'RMB' fcyid,z.unitno fobjid,z.zf_itemno zf_itemno,z.zf_itemname zf_itemname
    2369                        FROM (
    2370                                 SELECT Z.voucher_type,
    2371                                         '拨清算资金' purpose,
    2372                                        z.amt  zf_item_amt,
    2373                                        z.prjno  prjno,
    2374                                        z.unitno,
    2375                                        Z.SRC_ID,
    2376                                        Z.budget_type,
    2377                                        Z.budgetno,
    2378                                        '' zf_itemno,
    2379                                        '' zf_itemname,
    2380                                        (select bz.org_type  from bs_zjly bz where bz.fundno=z.src_id ) ORG_TYPE
    2381                                       -- z.AFFIRM_DATE
    2382                                   FROM   (  select crbd.id  as id ,  '3' voucher_type , crb.reason as refundment_memo ,   crbd.pay_amt as amt , crbd.prjno as prjno  ,crb.unitno ,crb.src_id as SRC_ID ,crbd.budget_type ,crbd.budgetno  from  common_req_back crb,common_req_back_detail crbd where crb.id=crbd.common_req_back_id)   Z
    2383                                  WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    2384                              ) Z
    2385                             order by z.budgetno
    2386                       )
    2387                     )
    2388                     ;
    2389                   ---借方:
    2390 
    2391                     select sum(a.fcredit) into v_total from gk_zwentry a where a.fserialnum = v_fserialnum_1 ;
    2392                     insert into gk_zwentry
    2393                       (fserialnum,
    2394                        fentryid,
    2395                        facctid,
    2396                        fclsid,
    2397                        fexp,
    2398                        fdebit,
    2399                        fcredit,
    2400                        fbanksettel,
    2401                        ftransid,
    2402                        fcyid,
    2403                        fobjid,
    2404                        zf_itemno,
    2405                        zf_itemname,BUDGETID)
    2406                       SELECT v_fserialnum_1,
    2407                              1,
    2408                              '100300101' as facctid ,
    2409                              '0',
    2410                              '拨清算资金',
    2411                              v_total,
    2412                              0,
    2413 
    2414                              '1',
    2415                              '000',
    2416                              'RMB',
    2417                              '*',
    2418                              '',
    2419                              '','100300101'||',' ||substr(fdate,0,4)|| ',*,*,*'
    2420                         from dual;
    2421 
    2422                     insert into gk_zwvch_refer(FSERIALNUM, orign_type,orign_id,voucher_type,origin_teable,fmodule)
    2423                      select v_fserialnum_1 ,
    2424                          '1' ORIGN_TYPE,
    2425                         z.id ORIGN_ID,
    2426                         z.voucher_type VOUCHER_TYPE,
    2427                         'common_req_back_detail' ORIGIN_TEABLE,
    2428                         '3' FMODULE
    2429                    from  (  select crbd.id  as id ,  '3' voucher_type , crb.reason as refundment_memo ,   crbd.pay_amt as amt , crbd.prjno as prjno  ,crb.unitno ,crb.src_id as SRC_ID ,crbd.budget_type ,crbd.budgetno  from  common_req_back crb,common_req_back_detail crbd where crb.id=crbd.common_req_back_id)  z
    2430                    WHERE Z.id IN (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)   ;
    2431 
    2432 
    2433 
    2434          end if;
    2435 
    2436 
    2437 
    2438 --================================================================================================================
    2439 --==========                                社会保障基金财政专户(工伤)                                      ========
    2440 --================================================================================================================  
    2441       elsif org_name='社会保障基金财政专户(工伤)'  then
    2442          if opertype='0' or  opertype='1' or   opertype='6'  then
    2443             /*
    2444                (1)工伤 :上划社保资金(人行)
    2445                   借:2001.001暂收款.工伤/失业/医疗统筹资金
    2446                   贷:1003.003财政专户存款.人民银行
    2447 
    2448                   人行社保专户	190606000004273090	中国人民银行顺德支行
    2449 
    2450              */
    2451             select count(1) into v_count_gkfszh  from gk_zfpz  Z   WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)   and z.src_id  in ('00S','007')    and z.purpose like '%工伤%' and z.fk_account in ('190606000004273090' ); /*社会保障基金财政专户(工伤)*/
    2452             if    v_count_gkfszh >0 then
    2453                    --插入主表
    2454                   insert into gk_zwvch
    2455                     (fserialnum,
    2456                      FPERIOD,
    2457                      fgroup,
    2458                      fdate,
    2459                      fnum,
    2460                      fpreparer,
    2461                      fattachment,
    2462                      fmodule,
    2463                      jz_database,
    2464                      org_type,
    2465                      jz_fserialnum,
    2466                      orign_type,
    2467                      make_date)
    2468                     select v_fserialnum_1,
    2469                            substr(fdate, 6, 2),
    2470                            i_fgroup,
    2471                            to_date(fdate, 'yyyy-MM-dd'),
    2472                            0,
    2473                            i_fpreparer,
    2474                            v_count_gkfszh,
    2475                            3,
    2476                            i_databasename,
    2477                            '1', --资金来源类型
    2478                            0,
    2479                            v_orign_type,
    2480                            sysdate
    2481 
    2482                       from dual;
    2483 
    2484 
    2485                  ---借方数据插入     
    2486                   insert into gk_zwentry(fserialnum,fentryid,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,budgetid)
    2487                      select   fserialnum,ROWNUM,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname, budgetid from (
    2488                      select fserialnum,ROWNUM,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,
    2489                               budgetno || ',' ||substr(fdate,0,4)|| ',' || budget_type || ',' || voucher_type || ',' || SRC_ID  budgetid
    2490                      from (
    2491                          SELECT Z.SRC_ID,Z.voucher_type,z.budget_type,z.budgetno,substr(to_char(sysdate,'yyyy-MM-dd'),0,4) year1,  v_fserialnum_1  fserialnum ,
    2492                       '2001001' facctid,
    2493                       '1' fclsid ,
    2494                       z.purpose fexp,z.zf_item_amt fdebit,0 fcredit,'1' fbanksettel ,z.prjno ftransid,'RMB' fcyid,z.unitno fobjid,z.zf_itemno zf_itemno,z.zf_itemname zf_itemname
    2495                        FROM (
    2496                                 SELECT Z.voucher_type,
    2497                                         z.purpose purpose,
    2498                                        z.amt  zf_item_amt,
    2499                                        z.prjno  prjno,
    2500                                        z.unitno,
    2501                                        Z.SRC_ID,
    2502                                        Z.budget_type,
    2503                                        Z.budgetno,
    2504                                        '' zf_itemno,
    2505                                        '' zf_itemname,
    2506                                        (select bz.org_type  from bs_zjly bz where bz.fundno=z.src_id ) ORG_TYPE
    2507                                       -- z.AFFIRM_DATE
    2508                                   FROM  gk_zfpz  Z
    2509                                  WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    2510                                     and z.src_id  in ('00S','007')    and z.purpose like '%工伤%' and z.fk_account in ('190606000004273090' )
    2511                              ) Z
    2512                             order by z.budgetno
    2513                       )
    2514                     )
    2515                     ;
    2516                   ---贷方:
    2517 
    2518                     select sum(a.fdebit) into v_total from gk_zwentry a where a.fserialnum = v_fserialnum_1 ;
    2519                     select max(a.fentryid) + 1 into v_max_index from gk_zwentry a where a.fserialnum = v_fserialnum_1;
    2520                     insert into gk_zwentry
    2521                       (fserialnum,
    2522                        fentryid,
    2523                        facctid,
    2524                        fclsid,
    2525                        fexp,
    2526                        fdebit,
    2527                        fcredit,
    2528                        fbanksettel,
    2529                        ftransid,
    2530                        fcyid,
    2531                        fobjid,
    2532                        zf_itemno,
    2533                        zf_itemname,BUDGETID)
    2534                       SELECT v_fserialnum_1,
    2535                              v_max_index,
    2536                              '1003003' as facctid ,
    2537                              '0',
    2538                              '',
    2539                              0,
    2540                              v_total,
    2541                              '1',
    2542                              '000',
    2543                              'RMB',
    2544                              '*',
    2545                              '',
    2546                              '','1003003'||',' ||substr(fdate,0,4)|| ',*,*,*'
    2547                         from dual;
    2548 
    2549                     insert into gk_zwvch_refer(FSERIALNUM, orign_type,orign_id,voucher_type,origin_teable,fmodule)
    2550                      select v_fserialnum_1 ,
    2551                          '1' ORIGN_TYPE,
    2552                         z.id ORIGN_ID,
    2553                         z.voucher_type VOUCHER_TYPE,
    2554                         'GK_ZFPZ' ORIGIN_TEABLE,
    2555                         '3' FMODULE
    2556                    from gk_zfpz z
    2557                    WHERE Z.id IN (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)   and z.src_id  in ('00S','007')    and z.purpose like '%工伤%' and z.fk_account in ('190606000004273090' );
    2558              end if;
    2559 
    2560 
    2561 
    2562 
    2563 
    2564 
    2565              /*
    2566                (2)工伤 :上划社保资金(农行)
    2567                 借:2001.001暂收款.工伤/失业/医疗统筹资金
    2568                 贷:1003.002财政专户存款.工伤/失业/医疗市级统筹专户
    2569                 社会保障基金专户(市级统筹工伤)	465001040021376-0000000006	中国农业银行股份有限公司顺德清晖支行
    2570              */
    2571             select count(1) into v_count_gkfszh  from gk_zfpz  Z   WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)   and z.src_id  in ('00S','007')    and z.purpose like '%工伤%' and z.fk_account='44465001040021376-0000000006'; /*社会保障基金财政专户(工伤)*/
    2572             if    v_count_gkfszh >0 then
    2573                    --插入主表
    2574                   insert into gk_zwvch
    2575                     (fserialnum,
    2576                      FPERIOD,
    2577                      fgroup,
    2578                      fdate,
    2579                      fnum,
    2580                      fpreparer,
    2581                      fattachment,
    2582                      fmodule,
    2583                      jz_database,
    2584                      org_type,
    2585                      jz_fserialnum,
    2586                      orign_type,
    2587                      make_date)
    2588                     select v_fserialnum_2,
    2589                            substr(fdate, 6, 2),
    2590                            i_fgroup,
    2591                            to_date(fdate, 'yyyy-MM-dd'),
    2592                            0,
    2593                            i_fpreparer,
    2594                            v_count_gkfszh,
    2595                            3,
    2596                            i_databasename,
    2597                            '1', --资金来源类型
    2598                            0,
    2599                            v_orign_type,
    2600                            sysdate
    2601 
    2602                       from dual;
    2603 
    2604 
    2605                  ---借方数据插入     
    2606                   insert into gk_zwentry(fserialnum,fentryid,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,budgetid)
    2607                      select   fserialnum,ROWNUM,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname, budgetid from (
    2608                      select fserialnum,ROWNUM,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,
    2609                               budgetno || ',' ||substr(fdate,0,4)|| ',' || budget_type || ',' || voucher_type || ',' || SRC_ID  budgetid
    2610                      from (
    2611                          SELECT Z.SRC_ID,Z.voucher_type,z.budget_type,z.budgetno,substr(to_char(sysdate,'yyyy-MM-dd'),0,4) year1,  v_fserialnum_2  fserialnum ,
    2612                       '2001001' facctid,
    2613                       '1' fclsid ,
    2614                       z.purpose fexp,z.zf_item_amt fdebit,0 fcredit,'1' fbanksettel ,z.prjno ftransid,'RMB' fcyid,z.unitno fobjid,z.zf_itemno zf_itemno,z.zf_itemname zf_itemname
    2615                        FROM (
    2616                                 SELECT Z.voucher_type,
    2617                                         z.purpose purpose,
    2618                                        z.amt  zf_item_amt,
    2619                                        z.prjno  prjno,
    2620                                        z.unitno,
    2621                                        Z.SRC_ID,
    2622                                        Z.budget_type,
    2623                                        Z.budgetno,
    2624                                        '' zf_itemno,
    2625                                        '' zf_itemname,
    2626                                        (select bz.org_type  from bs_zjly bz where bz.fundno=z.src_id ) ORG_TYPE
    2627                                       -- z.AFFIRM_DATE
    2628                                   FROM  gk_zfpz  Z
    2629                                  WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    2630                                   and z.src_id  in ('00S','007')    and z.purpose like '%工伤%' and z.fk_account='44465001040021376-0000000006'
    2631                              ) Z
    2632                             order by z.budgetno
    2633                       )
    2634                     )
    2635                     ;
    2636                   ---贷方:
    2637 
    2638                     select sum(a.fdebit) into v_total from gk_zwentry a where a.fserialnum = v_fserialnum_2 ;
    2639                     select max(a.fentryid) + 1 into v_max_index from gk_zwentry a where a.fserialnum = v_fserialnum_2;
    2640                     insert into gk_zwentry
    2641                       (fserialnum,
    2642                        fentryid,
    2643                        facctid,
    2644                        fclsid,
    2645                        fexp,
    2646                        fdebit,
    2647                        fcredit,
    2648                        fbanksettel,
    2649                        ftransid,
    2650                        fcyid,
    2651                        fobjid,
    2652                        zf_itemno,
    2653                        zf_itemname,BUDGETID)
    2654                       SELECT v_fserialnum_2,
    2655                              v_max_index,
    2656                              '1003002' as facctid ,
    2657                              '0',
    2658                              '',
    2659                              0,
    2660                              v_total,
    2661                              '1',
    2662                              '000',
    2663                              'RMB',
    2664                              '*',
    2665                              '',
    2666                              '','1003002'||',' ||substr(fdate,0,4)|| ',*,*,*'
    2667                         from dual;
    2668 
    2669                     insert into gk_zwvch_refer(FSERIALNUM, orign_type,orign_id,voucher_type,origin_teable,fmodule)
    2670                      select v_fserialnum_2 ,
    2671                          '1' ORIGN_TYPE,
    2672                         z.id ORIGN_ID,
    2673                         z.voucher_type VOUCHER_TYPE,
    2674                         'GK_ZFPZ' ORIGIN_TEABLE,
    2675                         '3' FMODULE
    2676                    from gk_zfpz z
    2677                    WHERE Z.id IN (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)  and z.src_id  in ('00S','007')    and z.purpose like '%工伤%' and z.fk_account='44465001040021376-0000000006' ;
    2678              end if;
    2679 
    2680          end if;
    2681 
    2682 
    2683 
    2684 --================================================================================================================
    2685 --==========                                社会保障基金财政专户(其它)                                      ========
    2686 --================================================================================================================  
    2687       elsif org_name='社会保障基金财政专户(其它)'  then
    2688          if  opertype='0' or  opertype='1' or   opertype='6' then
    2689           /*
    2690            -- 正常对碰的 直接支付  授权支付  一般支付
    2691            借:5005财政专户管理资金支出[功能分类科目编码 预算单位编码]
    2692            贷:1004.005.01其他财政存款.残疾人事业专项资金.农行活期(需与功能分类科目相对应)
    2693            取功能分类科目名称中的关键字:  残疾           (全部以农行活期结尾)
    2694 
    2695            会计科目编码组成:5005+功能分类科目编码
    2696 
    2697           */
    2698 
    2699            select count(1) into v_count_gkfszh  from gk_zfpz  Z   WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    2700             and z.budgetno in (select distinct bg.func_bdgid from bs_gnflyskm bg where bg.func_bdgname like '%残疾%');
    2701             if    v_count_gkfszh >0 then
    2702                    --插入主表
    2703                   insert into gk_zwvch
    2704                     (fserialnum,
    2705                      FPERIOD,
    2706                      fgroup,
    2707                      fdate,
    2708                      fnum,
    2709                      fpreparer,
    2710                      fattachment,
    2711                      fmodule,
    2712                      jz_database,
    2713                      org_type,
    2714                      jz_fserialnum,
    2715                      orign_type,
    2716                      make_date)
    2717                     select v_fserialnum_1,
    2718                            substr(fdate, 6, 2),
    2719                            i_fgroup,
    2720                            to_date(fdate, 'yyyy-MM-dd'),
    2721                            0,
    2722                            i_fpreparer,
    2723                            v_count_gkfszh,
    2724                            3,
    2725                            i_databasename,
    2726                            '1', --资金来源类型
    2727                            0,
    2728                            v_orign_type,
    2729                            sysdate
    2730 
    2731                       from dual;
    2732 
    2733 
    2734                  ---借方数据插入     
    2735                   insert into gk_zwentry(fserialnum,fentryid,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,budgetid)
    2736                      select   fserialnum,ROWNUM,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname, budgetid from (
    2737                      select fserialnum,ROWNUM,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,
    2738                               budgetno || ',' ||substr(fdate,0,4)|| ',' || budget_type || ',' || voucher_type || ',' || SRC_ID  budgetid
    2739                      from (
    2740                          SELECT Z.SRC_ID,Z.voucher_type,z.budget_type,z.budgetno,substr(to_char(sysdate,'yyyy-MM-dd'),0,4) year1,  v_fserialnum_1  fserialnum ,
    2741                       '5005'||budgetno  facctid,
    2742                       '1' fclsid ,
    2743                       z.purpose fexp,z.zf_item_amt fdebit,0 fcredit,'1' fbanksettel ,z.prjno ftransid,'RMB' fcyid,z.unitno fobjid,z.zf_itemno zf_itemno,z.zf_itemname zf_itemname
    2744                        FROM (
    2745                                 SELECT Z.voucher_type,
    2746                                         z.purpose purpose,
    2747                                        z.amt  zf_item_amt,
    2748                                        z.prjno  prjno,
    2749                                        z.unitno,
    2750                                        Z.SRC_ID,
    2751                                        Z.budget_type,
    2752                                        Z.budgetno,
    2753                                        '' zf_itemno,
    2754                                        '' zf_itemname,
    2755                                        (select bz.org_type  from bs_zjly bz where bz.fundno=z.src_id ) ORG_TYPE
    2756                                       -- z.AFFIRM_DATE
    2757                                   FROM  gk_zfpz  Z
    2758                                  WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    2759                                  and z.budgetno in (select distinct bg.func_bdgid from bs_gnflyskm bg where bg.func_bdgname like '%残疾%')
    2760                              ) Z
    2761                             order by z.budgetno
    2762                       )
    2763                     )
    2764                     ;
    2765                   ---贷方:
    2766 
    2767                     select sum(a.fdebit) into v_total from gk_zwentry a where a.fserialnum = v_fserialnum_1 ;
    2768                     select max(a.fentryid) + 1 into v_max_index from gk_zwentry a where a.fserialnum = v_fserialnum_1;
    2769                     insert into gk_zwentry
    2770                       (fserialnum,
    2771                        fentryid,
    2772                        facctid,
    2773                        fclsid,
    2774                        fexp,
    2775                        fdebit,
    2776                        fcredit,
    2777                        fbanksettel,
    2778                        ftransid,
    2779                        fcyid,
    2780                        fobjid,
    2781                        zf_itemno,
    2782                        zf_itemname,BUDGETID)
    2783                       SELECT v_fserialnum_1,
    2784                              v_max_index,
    2785                              '100400501' as facctid ,
    2786                              '0',
    2787                              '',
    2788                              0,
    2789                              v_total,
    2790                              '1',
    2791                              '000',
    2792                              'RMB',
    2793                              '*',
    2794                              '',
    2795                              '','100400501'||',' ||substr(fdate,0,4)|| ',*,*,*'
    2796                         from dual;
    2797 
    2798                     insert into gk_zwvch_refer(FSERIALNUM, orign_type,orign_id,voucher_type,origin_teable,fmodule)
    2799                      select v_fserialnum_1 ,
    2800                          '1' ORIGN_TYPE,
    2801                         z.id ORIGN_ID,
    2802                         z.voucher_type VOUCHER_TYPE,
    2803                         'GK_ZFPZ' ORIGIN_TEABLE,
    2804                         '3' FMODULE
    2805                    from gk_zfpz z
    2806                    WHERE Z.id IN (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)  and z.budgetno in (select distinct bg.func_bdgid from bs_gnflyskm bg where bg.func_bdgname like '%残疾%') ;
    2807              end if;
    2808 
    2809          /*
    2810            -- 正常对碰的 直接支付  授权支付  一般支付
    2811            借:5005财政专户管理资金支出[功能分类科目编码 预算单位编码]
    2812            贷:1004.004.01其他财政存款.医疗救助资金.农行活期(需与功能分类科目相对应)
    2813            取功能分类科目名称中的关键字: 医疗
    2814 
    2815            会计科目编码组成:5005+功能分类科目编码
    2816 
    2817           */
    2818           select count(1) into v_count_gkfszh  from gk_zfpz  Z   WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    2819             and z.budgetno in (select distinct bg.func_bdgid from bs_gnflyskm bg where bg.func_bdgname like '%医疗%' and bg.func_bdgname not  like '%药品%')  ;
    2820             if    v_count_gkfszh >0 then
    2821                    --插入主表
    2822                   insert into gk_zwvch
    2823                     (fserialnum,
    2824                      FPERIOD,
    2825                      fgroup,
    2826                      fdate,
    2827                      fnum,
    2828                      fpreparer,
    2829                      fattachment,
    2830                      fmodule,
    2831                      jz_database,
    2832                      org_type,
    2833                      jz_fserialnum,
    2834                      orign_type,
    2835                      make_date)
    2836                     select v_fserialnum_2,
    2837                            substr(fdate, 6, 2),
    2838                            i_fgroup,
    2839                            to_date(fdate, 'yyyy-MM-dd'),
    2840                            0,
    2841                            i_fpreparer,
    2842                            v_count_gkfszh,
    2843                            3,
    2844                            i_databasename,
    2845                            '1', --资金来源类型
    2846                            0,
    2847                            v_orign_type,
    2848                            sysdate
    2849 
    2850                       from dual;
    2851 
    2852 
    2853                  ---借方数据插入     
    2854                   insert into gk_zwentry(fserialnum,fentryid,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,budgetid)
    2855                      select   fserialnum,ROWNUM,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname, budgetid from (
    2856                      select fserialnum,ROWNUM,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,
    2857                               budgetno || ',' ||substr(fdate,0,4)|| ',' || budget_type || ',' || voucher_type || ',' || SRC_ID  budgetid
    2858                      from (
    2859                          SELECT Z.SRC_ID,Z.voucher_type,z.budget_type,z.budgetno,substr(to_char(sysdate,'yyyy-MM-dd'),0,4) year1,  v_fserialnum_2  fserialnum ,
    2860                       '5005'||budgetno  facctid,
    2861                       '1' fclsid ,
    2862                       z.purpose fexp,z.zf_item_amt fdebit,0 fcredit,'1' fbanksettel ,z.prjno ftransid,'RMB' fcyid,z.unitno fobjid,z.zf_itemno zf_itemno,z.zf_itemname zf_itemname
    2863                        FROM (
    2864                                 SELECT Z.voucher_type,
    2865                                         z.purpose purpose,
    2866                                        z.amt  zf_item_amt,
    2867                                        z.prjno  prjno,
    2868                                        z.unitno,
    2869                                        Z.SRC_ID,
    2870                                        Z.budget_type,
    2871                                        Z.budgetno,
    2872                                        '' zf_itemno,
    2873                                        '' zf_itemname,
    2874                                        (select bz.org_type  from bs_zjly bz where bz.fundno=z.src_id ) ORG_TYPE
    2875                                       -- z.AFFIRM_DATE
    2876                                   FROM  gk_zfpz  Z
    2877                                  WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    2878                                   and z.budgetno in (select distinct bg.func_bdgid from bs_gnflyskm bg where bg.func_bdgname like '%医疗%' and bg.func_bdgname not  like '%药品%')
    2879                              ) Z
    2880                             order by z.budgetno
    2881                       )
    2882                     )
    2883                     ;
    2884                   ---贷方:
    2885 
    2886                     select sum(a.fdebit) into v_total from gk_zwentry a where a.fserialnum = v_fserialnum_2 ;
    2887                     select max(a.fentryid) + 1 into v_max_index from gk_zwentry a where a.fserialnum = v_fserialnum_2;
    2888                     insert into gk_zwentry
    2889                       (fserialnum,
    2890                        fentryid,
    2891                        facctid,
    2892                        fclsid,
    2893                        fexp,
    2894                        fdebit,
    2895                        fcredit,
    2896                        fbanksettel,
    2897                        ftransid,
    2898                        fcyid,
    2899                        fobjid,
    2900                        zf_itemno,
    2901                        zf_itemname,BUDGETID)
    2902                       SELECT v_fserialnum_2,
    2903                              v_max_index,
    2904                              '100400401' as facctid ,
    2905                              '0',
    2906                              '',
    2907                              0,
    2908                              v_total,
    2909                              '1',
    2910                              '000',
    2911                              'RMB',
    2912                              '*',
    2913                              '',
    2914                              '','100400401'||',' ||substr(fdate,0,4)|| ',*,*,*'
    2915                         from dual;
    2916 
    2917                     insert into gk_zwvch_refer(FSERIALNUM, orign_type,orign_id,voucher_type,origin_teable,fmodule)
    2918                      select v_fserialnum_2 ,
    2919                          '1' ORIGN_TYPE,
    2920                         z.id ORIGN_ID,
    2921                         z.voucher_type VOUCHER_TYPE,
    2922                         'GK_ZFPZ' ORIGIN_TEABLE,
    2923                         '3' FMODULE
    2924                    from gk_zfpz z
    2925                    WHERE Z.id IN (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id) and z.budgetno in (select distinct bg.func_bdgid from bs_gnflyskm bg where bg.func_bdgname like '%医疗%' and bg.func_bdgname not  like '%药品%' )  ;
    2926              end if;
    2927 
    2928          /*
    2929            -- 正常对碰的 直接支付  授权支付  一般支付
    2930            借:5005财政专户管理资金支出[功能分类科目编码 预算单位编码]
    2931            贷:1004.003.01其他财政存款.灵活就业资金.农行活期(需与功能分类科目相对应)
    2932            取功能分类科目名称中的关键字:就业
    2933 
    2934            会计科目编码组成:5005+功能分类科目编码
    2935 
    2936           */
    2937            select count(1) into v_count_gkfszh  from gk_zfpz  Z   WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    2938             and z.budgetno in (select distinct bg.func_bdgid from bs_gnflyskm bg where bg.func_bdgname like '%就业%')  ;
    2939             if    v_count_gkfszh >0 then
    2940                    --插入主表
    2941                   insert into gk_zwvch
    2942                     (fserialnum,
    2943                      FPERIOD,
    2944                      fgroup,
    2945                      fdate,
    2946                      fnum,
    2947                      fpreparer,
    2948                      fattachment,
    2949                      fmodule,
    2950                      jz_database,
    2951                      org_type,
    2952                      jz_fserialnum,
    2953                      orign_type,
    2954                      make_date)
    2955                     select v_fserialnum_3,
    2956                            substr(fdate, 6, 2),
    2957                            i_fgroup,
    2958                            to_date(fdate, 'yyyy-MM-dd'),
    2959                            0,
    2960                            i_fpreparer,
    2961                            v_count_gkfszh,
    2962                            3,
    2963                            i_databasename,
    2964                            '1', --资金来源类型
    2965                            0,
    2966                            v_orign_type,
    2967                            sysdate
    2968 
    2969                       from dual;
    2970 
    2971 
    2972                  ---借方数据插入     
    2973                   insert into gk_zwentry(fserialnum,fentryid,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,budgetid)
    2974                      select   fserialnum,ROWNUM,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname, budgetid from (
    2975                      select fserialnum,ROWNUM,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,
    2976                               budgetno || ',' ||substr(fdate,0,4)|| ',' || budget_type || ',' || voucher_type || ',' || SRC_ID  budgetid
    2977                      from (
    2978                          SELECT Z.SRC_ID,Z.voucher_type,z.budget_type,z.budgetno,substr(to_char(sysdate,'yyyy-MM-dd'),0,4) year1,  v_fserialnum_3  fserialnum ,
    2979                       '5005'||budgetno  facctid,
    2980                       '1' fclsid ,
    2981                       z.purpose fexp,z.zf_item_amt fdebit,0 fcredit,'1' fbanksettel ,z.prjno ftransid,'RMB' fcyid,z.unitno fobjid,z.zf_itemno zf_itemno,z.zf_itemname zf_itemname
    2982                        FROM (
    2983                                 SELECT Z.voucher_type,
    2984                                         z.purpose purpose,
    2985                                        z.amt  zf_item_amt,
    2986                                        z.prjno  prjno,
    2987                                        z.unitno,
    2988                                        Z.SRC_ID,
    2989                                        Z.budget_type,
    2990                                        Z.budgetno,
    2991                                        '' zf_itemno,
    2992                                        '' zf_itemname,
    2993                                        (select bz.org_type  from bs_zjly bz where bz.fundno=z.src_id ) ORG_TYPE
    2994                                       -- z.AFFIRM_DATE
    2995                                   FROM  gk_zfpz  Z
    2996                                  WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    2997                                   and z.budgetno in (select distinct bg.func_bdgid from bs_gnflyskm bg where bg.func_bdgname like '%就业%')
    2998                              ) Z
    2999                             order by z.budgetno
    3000                       )
    3001                     )
    3002                     ;
    3003                   ---贷方:
    3004 
    3005                     select sum(a.fdebit) into v_total from gk_zwentry a where a.fserialnum = v_fserialnum_3 ;
    3006                     select max(a.fentryid) + 1 into v_max_index from gk_zwentry a where a.fserialnum = v_fserialnum_3;
    3007                     insert into gk_zwentry
    3008                       (fserialnum,
    3009                        fentryid,
    3010                        facctid,
    3011                        fclsid,
    3012                        fexp,
    3013                        fdebit,
    3014                        fcredit,
    3015                        fbanksettel,
    3016                        ftransid,
    3017                        fcyid,
    3018                        fobjid,
    3019                        zf_itemno,
    3020                        zf_itemname,BUDGETID)
    3021                       SELECT v_fserialnum_3,
    3022                              v_max_index,
    3023                              '100400301' as facctid ,
    3024                              '0',
    3025                              '',
    3026                              0,
    3027                              v_total,
    3028                              '1',
    3029                              '000',
    3030                              'RMB',
    3031                              '*',
    3032                              '',
    3033                              '','100400301'||',' ||substr(fdate,0,4)|| ',*,*,*'
    3034                         from dual;
    3035 
    3036                     insert into gk_zwvch_refer(FSERIALNUM, orign_type,orign_id,voucher_type,origin_teable,fmodule)
    3037                      select v_fserialnum_3 ,
    3038                          '1' ORIGN_TYPE,
    3039                         z.id ORIGN_ID,
    3040                         z.voucher_type VOUCHER_TYPE,
    3041                         'GK_ZFPZ' ORIGIN_TEABLE,
    3042                         '3' FMODULE
    3043                    from gk_zfpz z
    3044                    WHERE Z.id IN (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id) and z.budgetno in (select distinct bg.func_bdgid from bs_gnflyskm bg where bg.func_bdgname like '%就业%')  ;
    3045              end if;
    3046 
    3047 
    3048 
    3049 
    3050 
    3051          /*
    3052            -- 正常对碰的 直接支付  授权支付  一般支付
    3053            借:5005财政专户管理资金支出[功能分类科目编码 预算单位编码]
    3054            贷:1004.002.01其他财政存款.其他社会保险基金.农行活期(需与功能分类科目相对应)
    3055            取功能分类科目名称中的关键字:社保保险
    3056 
    3057            会计科目编码组成:5005+功能分类科目编码
    3058 
    3059           */
    3060            select count(1) into v_count_gkfszh  from gk_zfpz  Z   WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    3061             and z.budgetno in (select distinct bg.func_bdgid from bs_gnflyskm bg where bg.func_bdgname like '%保险%')  ;
    3062             if    v_count_gkfszh >0 then
    3063                    --插入主表
    3064                   insert into gk_zwvch
    3065                     (fserialnum,
    3066                      FPERIOD,
    3067                      fgroup,
    3068                      fdate,
    3069                      fnum,
    3070                      fpreparer,
    3071                      fattachment,
    3072                      fmodule,
    3073                      jz_database,
    3074                      org_type,
    3075                      jz_fserialnum,
    3076                      orign_type,
    3077                      make_date)
    3078                     select v_fserialnum_4,
    3079                            substr(fdate, 6, 2),
    3080                            i_fgroup,
    3081                            to_date(fdate, 'yyyy-MM-dd'),
    3082                            0,
    3083                            i_fpreparer,
    3084                            v_count_gkfszh,
    3085                            3,
    3086                            i_databasename,
    3087                            '1', --资金来源类型
    3088                            0,
    3089                            v_orign_type,
    3090                            sysdate
    3091 
    3092                       from dual;
    3093 
    3094 
    3095                  ---借方数据插入     
    3096                   insert into gk_zwentry(fserialnum,fentryid,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,budgetid)
    3097                      select   fserialnum,ROWNUM,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname, budgetid from (
    3098                      select fserialnum,ROWNUM,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,
    3099                               budgetno || ',' ||substr(fdate,0,4)|| ',' || budget_type || ',' || voucher_type || ',' || SRC_ID  budgetid
    3100                      from (
    3101                          SELECT Z.SRC_ID,Z.voucher_type,z.budget_type,z.budgetno,substr(to_char(sysdate,'yyyy-MM-dd'),0,4) year1,  v_fserialnum_4  fserialnum ,
    3102                       '5005'||budgetno  facctid,
    3103                       '1' fclsid ,
    3104                       z.purpose fexp,z.zf_item_amt fdebit,0 fcredit,'1' fbanksettel ,z.prjno ftransid,'RMB' fcyid,z.unitno fobjid,z.zf_itemno zf_itemno,z.zf_itemname zf_itemname
    3105                        FROM (
    3106                                 SELECT Z.voucher_type,
    3107                                         z.purpose purpose,
    3108                                        z.amt  zf_item_amt,
    3109                                        z.prjno  prjno,
    3110                                        z.unitno,
    3111                                        Z.SRC_ID,
    3112                                        Z.budget_type,
    3113                                        Z.budgetno,
    3114                                        '' zf_itemno,
    3115                                        '' zf_itemname,
    3116                                        (select bz.org_type  from bs_zjly bz where bz.fundno=z.src_id ) ORG_TYPE
    3117                                       -- z.AFFIRM_DATE
    3118                                   FROM  gk_zfpz  Z
    3119                                  WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    3120                                   and z.budgetno in (select distinct bg.func_bdgid from bs_gnflyskm bg where bg.func_bdgname like '%保险%')
    3121                              ) Z
    3122                             order by z.budgetno
    3123                       )
    3124                     )
    3125                     ;
    3126                   ---贷方:
    3127 
    3128                     select sum(a.fdebit) into v_total from gk_zwentry a where a.fserialnum = v_fserialnum_4 ;
    3129                     select max(a.fentryid) + 1 into v_max_index from gk_zwentry a where a.fserialnum = v_fserialnum_4;
    3130                     insert into gk_zwentry
    3131                       (fserialnum,
    3132                        fentryid,
    3133                        facctid,
    3134                        fclsid,
    3135                        fexp,
    3136                        fdebit,
    3137                        fcredit,
    3138                        fbanksettel,
    3139                        ftransid,
    3140                        fcyid,
    3141                        fobjid,
    3142                        zf_itemno,
    3143                        zf_itemname,BUDGETID)
    3144                       SELECT v_fserialnum_4,
    3145                              v_max_index,
    3146                              '100400201' as facctid ,
    3147                              '0',
    3148                              '',
    3149                              0,
    3150                              v_total,
    3151                              '1',
    3152                              '000',
    3153                              'RMB',
    3154                              '*',
    3155                              '',
    3156                              '','100400201'||',' ||substr(fdate,0,4)|| ',*,*,*'
    3157                         from dual;
    3158 
    3159                     insert into gk_zwvch_refer(FSERIALNUM, orign_type,orign_id,voucher_type,origin_teable,fmodule)
    3160                      select v_fserialnum_4 ,
    3161                          '1' ORIGN_TYPE,
    3162                         z.id ORIGN_ID,
    3163                         z.voucher_type VOUCHER_TYPE,
    3164                         'GK_ZFPZ' ORIGIN_TEABLE,
    3165                         '3' FMODULE
    3166                    from gk_zfpz z
    3167                    WHERE Z.id IN (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id) and z.budgetno in (select distinct bg.func_bdgid from bs_gnflyskm bg where bg.func_bdgname like '%保险%')  ;
    3168              end if;
    3169 
    3170 
    3171 
    3172 
    3173 
    3174 
    3175          /*
    3176            -- 正常对碰的 直接支付  授权支付  一般支付
    3177            借:5005财政专户管理资金支出[功能分类科目编码 预算单位编码]
    3178            贷:1004.001.01其他财政存款.医院药品收支结余.农行活期(需与功能分类科目相对应)
    3179            取功能分类科目名称中的关键字: 药品
    3180 
    3181            会计科目编码组成:5005+功能分类科目编码
    3182 
    3183           */
    3184            select count(1) into v_count_gkfszh  from gk_zfpz  Z   WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    3185             and z.budgetno in (select distinct bg.func_bdgid from bs_gnflyskm bg where bg.func_bdgname like '%药品%')  ;
    3186             if    v_count_gkfszh >0 then
    3187                    --插入主表
    3188                   insert into gk_zwvch
    3189                     (fserialnum,
    3190                      FPERIOD,
    3191                      fgroup,
    3192                      fdate,
    3193                      fnum,
    3194                      fpreparer,
    3195                      fattachment,
    3196                      fmodule,
    3197                      jz_database,
    3198                      org_type,
    3199                      jz_fserialnum,
    3200                      orign_type,
    3201                      make_date)
    3202                     select v_fserialnum_5,
    3203                            substr(fdate, 6, 2),
    3204                            i_fgroup,
    3205                            to_date(fdate, 'yyyy-MM-dd'),
    3206                            0,
    3207                            i_fpreparer,
    3208                            v_count_gkfszh,
    3209                            3,
    3210                            i_databasename,
    3211                            '1', --资金来源类型
    3212                            0,
    3213                            v_orign_type,
    3214                            sysdate
    3215 
    3216                       from dual;
    3217 
    3218 
    3219                  ---借方数据插入     
    3220                   insert into gk_zwentry(fserialnum,fentryid,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,budgetid)
    3221                      select   fserialnum,ROWNUM,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname, budgetid from (
    3222                      select fserialnum,ROWNUM,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,
    3223                               budgetno || ',' ||substr(fdate,0,4)|| ',' || budget_type || ',' || voucher_type || ',' || SRC_ID  budgetid
    3224                      from (
    3225                          SELECT Z.SRC_ID,Z.voucher_type,z.budget_type,z.budgetno,substr(to_char(sysdate,'yyyy-MM-dd'),0,4) year1,  v_fserialnum_5  fserialnum ,
    3226                       '5005'||budgetno  facctid,
    3227                       '1' fclsid ,
    3228                       z.purpose fexp,z.zf_item_amt fdebit,0 fcredit,'1' fbanksettel ,z.prjno ftransid,'RMB' fcyid,z.unitno fobjid,z.zf_itemno zf_itemno,z.zf_itemname zf_itemname
    3229                        FROM (
    3230                                 SELECT Z.voucher_type,
    3231                                         z.purpose purpose,
    3232                                        z.amt  zf_item_amt,
    3233                                        z.prjno  prjno,
    3234                                        z.unitno,
    3235                                        Z.SRC_ID,
    3236                                        Z.budget_type,
    3237                                        Z.budgetno,
    3238                                        '' zf_itemno,
    3239                                        '' zf_itemname,
    3240                                        (select bz.org_type  from bs_zjly bz where bz.fundno=z.src_id ) ORG_TYPE
    3241                                       -- z.AFFIRM_DATE
    3242                                   FROM  gk_zfpz  Z
    3243                                  WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    3244                                   and z.budgetno in (select distinct bg.func_bdgid from bs_gnflyskm bg where bg.func_bdgname like '%药品%')
    3245                              ) Z
    3246                             order by z.budgetno
    3247                       )
    3248                     )
    3249                     ;
    3250                   ---贷方:
    3251 
    3252                     select sum(a.fdebit) into v_total from gk_zwentry a where a.fserialnum = v_fserialnum_5 ;
    3253                     select max(a.fentryid) + 1 into v_max_index from gk_zwentry a where a.fserialnum = v_fserialnum_5;
    3254                     insert into gk_zwentry
    3255                       (fserialnum,
    3256                        fentryid,
    3257                        facctid,
    3258                        fclsid,
    3259                        fexp,
    3260                        fdebit,
    3261                        fcredit,
    3262                        fbanksettel,
    3263                        ftransid,
    3264                        fcyid,
    3265                        fobjid,
    3266                        zf_itemno,
    3267                        zf_itemname,BUDGETID)
    3268                       SELECT v_fserialnum_5,
    3269                              v_max_index,
    3270                              '100400101' as facctid ,
    3271                              '0',
    3272                              '',
    3273                              0,
    3274                              v_total,
    3275                              '1',
    3276                              '000',
    3277                              'RMB',
    3278                              '*',
    3279                              '',
    3280                              '','100400101'||',' ||substr(fdate,0,4)|| ',*,*,*'
    3281                         from dual;
    3282 
    3283                     insert into gk_zwvch_refer(FSERIALNUM, orign_type,orign_id,voucher_type,origin_teable,fmodule)
    3284                      select v_fserialnum_5 ,
    3285                          '1' ORIGN_TYPE,
    3286                         z.id ORIGN_ID,
    3287                         z.voucher_type VOUCHER_TYPE,
    3288                         'GK_ZFPZ' ORIGIN_TEABLE,
    3289                         '3' FMODULE
    3290                    from gk_zfpz z
    3291                    WHERE Z.id IN (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id) and z.budgetno in (select distinct bg.func_bdgid from bs_gnflyskm bg where bg.func_bdgname like '%药品%')  ;
    3292              end if;
    3293 
    3294 
    3295          elsif   opertype='2' or  opertype='3' then
    3296           /*
    3297            --  全额退款的 直接支付  授权支付
    3298 
    3299            借: 1004.005.01其他财政存款.残疾人事业专项资金.农行活期(需与功能分类科目相对应)
    3300            贷: 5005财政专户管理资金支出[功能分类科目编码 预算单位编码]
    3301 
    3302             取功能分类科目名称中的关键字:  残疾           (全部以农行活期结尾)
    3303            会计科目编码组成:5005+功能分类科目编码
    3304 
    3305           */
    3306           select count(1) into v_count_gkfszh  from gk_zfpz  Z   WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    3307             and z.budgetno in (select distinct bg.func_bdgid from bs_gnflyskm bg where bg.func_bdgname like '%残疾%');
    3308             if    v_count_gkfszh >0 then
    3309                    --插入主表
    3310                   insert into gk_zwvch
    3311                     (fserialnum,
    3312                      FPERIOD,
    3313                      fgroup,
    3314                      fdate,
    3315                      fnum,
    3316                      fpreparer,
    3317                      fattachment,
    3318                      fmodule,
    3319                      jz_database,
    3320                      org_type,
    3321                      jz_fserialnum,
    3322                      orign_type,
    3323                      make_date)
    3324                     select v_fserialnum_1,
    3325                            substr(fdate, 6, 2),
    3326                            i_fgroup,
    3327                            to_date(fdate, 'yyyy-MM-dd'),
    3328                            0,
    3329                            i_fpreparer,
    3330                            v_count_gkfszh,
    3331                            3,
    3332                            i_databasename,
    3333                            '1', --资金来源类型
    3334                            0,
    3335                            v_orign_type,
    3336                            sysdate
    3337 
    3338                       from dual;
    3339 
    3340 
    3341                  ---贷方数据插入     
    3342                   insert into gk_zwentry(fserialnum,fentryid,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,budgetid)
    3343                      select   fserialnum,ROWNUM+1,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname, budgetid from (
    3344                      select fserialnum,ROWNUM+1,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,
    3345                               budgetno || ',' ||substr(fdate,0,4)|| ',' || budget_type || ',' || voucher_type || ',' || SRC_ID  budgetid
    3346                      from (
    3347                          SELECT Z.SRC_ID,Z.voucher_type,z.budget_type,z.budgetno,substr(to_char(sysdate,'yyyy-MM-dd'),0,4) year1,  v_fserialnum_1  fserialnum ,
    3348                       '5005'||budgetno  facctid,
    3349                       '1' fclsid ,
    3350                       z.purpose fexp, 0 fdebit,z.zf_item_amt fcredit,'1' fbanksettel ,z.prjno ftransid,'RMB' fcyid,z.unitno fobjid,z.zf_itemno zf_itemno,z.zf_itemname zf_itemname
    3351                        FROM (
    3352                                 SELECT Z.voucher_type,
    3353                                         z.purpose purpose,
    3354                                        z.amt  zf_item_amt,
    3355                                        z.prjno  prjno,
    3356                                        z.unitno,
    3357                                        Z.SRC_ID,
    3358                                        Z.budget_type,
    3359                                        Z.budgetno,
    3360                                        '' zf_itemno,
    3361                                        '' zf_itemname,
    3362                                        (select bz.org_type  from bs_zjly bz where bz.fundno=z.src_id ) ORG_TYPE
    3363                                       -- z.AFFIRM_DATE
    3364                                   FROM  gk_zfpz  Z
    3365                                  WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    3366                                  and z.budgetno in (select distinct bg.func_bdgid from bs_gnflyskm bg where bg.func_bdgname like '%残疾%')
    3367                              ) Z
    3368                             order by z.budgetno
    3369                       )
    3370                     )
    3371                     ;
    3372                   ---借方:
    3373 
    3374                     select sum(a.fcredit) into v_total from gk_zwentry a where a.fserialnum = v_fserialnum_1 ;
    3375 
    3376                     insert into gk_zwentry
    3377                       (fserialnum,
    3378                        fentryid,
    3379                        facctid,
    3380                        fclsid,
    3381                        fexp,
    3382                        fdebit,
    3383                        fcredit,
    3384                        fbanksettel,
    3385                        ftransid,
    3386                        fcyid,
    3387                        fobjid,
    3388                        zf_itemno,
    3389                        zf_itemname,BUDGETID)
    3390                       SELECT v_fserialnum_1,
    3391                              1,
    3392                              '100400501' as facctid ,
    3393                              '0',
    3394                              '',
    3395                              v_total,
    3396                              0,
    3397                              '1',
    3398                              '000',
    3399                              'RMB',
    3400                              '*',
    3401                              '',
    3402                              '','100400501'||',' ||substr(fdate,0,4)|| ',*,*,*'
    3403                         from dual;
    3404 
    3405                     insert into gk_zwvch_refer(FSERIALNUM, orign_type,orign_id,voucher_type,origin_teable,fmodule)
    3406                      select v_fserialnum_1 ,
    3407                          '3' ORIGN_TYPE,
    3408                         z.id ORIGN_ID,
    3409                         z.voucher_type VOUCHER_TYPE,
    3410                         'GK_ZFPZ' ORIGIN_TEABLE,
    3411                         '3' FMODULE
    3412                    from gk_zfpz z
    3413                    WHERE Z.id IN (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)  and z.budgetno in (select distinct bg.func_bdgid from bs_gnflyskm bg where bg.func_bdgname like '%残疾%') ;
    3414              end if;
    3415 
    3416 
    3417          /*
    3418            --  全额退款的 直接支付  授权支付
    3419            借: 1004.004.01其他财政存款.医疗救助资金.农行活期(需与功能分类科目相对应)
    3420            贷: 5005财政专户管理资金支出[功能分类科目编码 预算单位编码]
    3421 
    3422 
    3423            取功能分类科目名称中的关键字: 医疗
    3424            会计科目编码组成:5005+功能分类科目编码
    3425 
    3426           */
    3427           select count(1) into v_count_gkfszh  from gk_zfpz  Z   WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    3428             and z.budgetno in (select distinct bg.func_bdgid from bs_gnflyskm bg where bg.func_bdgname like '%医疗%' and bg.func_bdgname not  like '%药品%')  ;
    3429             if    v_count_gkfszh >0 then
    3430                    --插入主表
    3431                   insert into gk_zwvch
    3432                     (fserialnum,
    3433                      FPERIOD,
    3434                      fgroup,
    3435                      fdate,
    3436                      fnum,
    3437                      fpreparer,
    3438                      fattachment,
    3439                      fmodule,
    3440                      jz_database,
    3441                      org_type,
    3442                      jz_fserialnum,
    3443                      orign_type,
    3444                      make_date)
    3445                     select v_fserialnum_2,
    3446                            substr(fdate, 6, 2),
    3447                            i_fgroup,
    3448                            to_date(fdate, 'yyyy-MM-dd'),
    3449                            0,
    3450                            i_fpreparer,
    3451                            v_count_gkfszh,
    3452                            3,
    3453                            i_databasename,
    3454                            '1', --资金来源类型
    3455                            0,
    3456                            v_orign_type,
    3457                            sysdate
    3458 
    3459                       from dual;
    3460 
    3461 
    3462                  ---贷方数据插入     
    3463                   insert into gk_zwentry(fserialnum,fentryid,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,budgetid)
    3464                      select   fserialnum,ROWNUM+1,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname, budgetid from (
    3465                      select fserialnum,ROWNUM+1,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,
    3466                               budgetno || ',' ||substr(fdate,0,4)|| ',' || budget_type || ',' || voucher_type || ',' || SRC_ID  budgetid
    3467                      from (
    3468                          SELECT Z.SRC_ID,Z.voucher_type,z.budget_type,z.budgetno,substr(to_char(sysdate,'yyyy-MM-dd'),0,4) year1,  v_fserialnum_2  fserialnum ,
    3469                       '5005'||budgetno  facctid,
    3470                       '1' fclsid ,
    3471                       z.purpose fexp,0 fdebit,  z.zf_item_amt fcredit,'1' fbanksettel ,z.prjno ftransid,'RMB' fcyid,z.unitno fobjid,z.zf_itemno zf_itemno,z.zf_itemname zf_itemname
    3472                        FROM (
    3473                                 SELECT Z.voucher_type,
    3474                                         z.purpose purpose,
    3475                                        z.amt  zf_item_amt,
    3476                                        z.prjno  prjno,
    3477                                        z.unitno,
    3478                                        Z.SRC_ID,
    3479                                        Z.budget_type,
    3480                                        Z.budgetno,
    3481                                        '' zf_itemno,
    3482                                        '' zf_itemname,
    3483                                        (select bz.org_type  from bs_zjly bz where bz.fundno=z.src_id ) ORG_TYPE
    3484                                       -- z.AFFIRM_DATE
    3485                                   FROM  gk_zfpz  Z
    3486                                  WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    3487                                   and z.budgetno in (select distinct bg.func_bdgid from bs_gnflyskm bg where bg.func_bdgname like '%医疗%' and bg.func_bdgname not  like '%药品%')
    3488                              ) Z
    3489                             order by z.budgetno
    3490                       )
    3491                     )
    3492                     ;
    3493                   ---借方:
    3494 
    3495                     select sum(a.fcredit) into v_total from gk_zwentry a where a.fserialnum = v_fserialnum_2 ;
    3496                     insert into gk_zwentry
    3497                       (fserialnum,
    3498                        fentryid,
    3499                        facctid,
    3500                        fclsid,
    3501                        fexp,
    3502                        fdebit,
    3503                        fcredit,
    3504                        fbanksettel,
    3505                        ftransid,
    3506                        fcyid,
    3507                        fobjid,
    3508                        zf_itemno,
    3509                        zf_itemname,BUDGETID)
    3510                       SELECT v_fserialnum_2,
    3511                              1,
    3512                              '100400401' as facctid ,
    3513                              '0',
    3514                              '',
    3515                              v_total,
    3516                              0,
    3517                              '1',
    3518                              '000',
    3519                              'RMB',
    3520                              '*',
    3521                              '',
    3522                              '','100400401'||',' ||substr(fdate,0,4)|| ',*,*,*'
    3523                         from dual;
    3524 
    3525                     insert into gk_zwvch_refer(FSERIALNUM, orign_type,orign_id,voucher_type,origin_teable,fmodule)
    3526                      select v_fserialnum_2 ,
    3527                          '3' ORIGN_TYPE,
    3528                         z.id ORIGN_ID,
    3529                         z.voucher_type VOUCHER_TYPE,
    3530                         'GK_ZFPZ' ORIGIN_TEABLE,
    3531                         '3' FMODULE
    3532                    from gk_zfpz z
    3533                    WHERE Z.id IN (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id) and z.budgetno in (select distinct bg.func_bdgid from bs_gnflyskm bg where bg.func_bdgname like '%医疗%' and bg.func_bdgname not  like '%药品%' )  ;
    3534              end if;
    3535 
    3536 
    3537 
    3538 
    3539 
    3540          /*
    3541            --  全额退款的 直接支付  授权支付
    3542            借:1004.003.01其他财政存款.灵活就业资金.农行活期(需与功能分类科目相对应)
    3543            贷:5005财政专户管理资金支出[功能分类科目编码 预算单位编码]
    3544            取功能分类科目名称中的关键字:就业
    3545 
    3546            会计科目编码组成:5005+功能分类科目编码
    3547 
    3548           */
    3549            select count(1) into v_count_gkfszh  from gk_zfpz  Z   WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    3550             and z.budgetno in (select distinct bg.func_bdgid from bs_gnflyskm bg where bg.func_bdgname like '%就业%')  ;
    3551             if    v_count_gkfszh >0 then
    3552                    --插入主表
    3553                   insert into gk_zwvch
    3554                     (fserialnum,
    3555                      FPERIOD,
    3556                      fgroup,
    3557                      fdate,
    3558                      fnum,
    3559                      fpreparer,
    3560                      fattachment,
    3561                      fmodule,
    3562                      jz_database,
    3563                      org_type,
    3564                      jz_fserialnum,
    3565                      orign_type,
    3566                      make_date)
    3567                     select v_fserialnum_3,
    3568                            substr(fdate, 6, 2),
    3569                            i_fgroup,
    3570                            to_date(fdate, 'yyyy-MM-dd'),
    3571                            0,
    3572                            i_fpreparer,
    3573                            v_count_gkfszh,
    3574                            3,
    3575                            i_databasename,
    3576                            '1', --资金来源类型
    3577                            0,
    3578                            v_orign_type,
    3579                            sysdate
    3580 
    3581                       from dual;
    3582 
    3583 
    3584                  ---贷方数据插入     
    3585                   insert into gk_zwentry(fserialnum,fentryid,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,budgetid)
    3586                      select   fserialnum,ROWNUM+1,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname, budgetid from (
    3587                      select fserialnum,ROWNUM+1,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,
    3588                               budgetno || ',' ||substr(fdate,0,4)|| ',' || budget_type || ',' || voucher_type || ',' || SRC_ID  budgetid
    3589                      from (
    3590                          SELECT Z.SRC_ID,Z.voucher_type,z.budget_type,z.budgetno,substr(to_char(sysdate,'yyyy-MM-dd'),0,4) year1,  v_fserialnum_3  fserialnum ,
    3591                       '5005'||budgetno  facctid,
    3592                       '1' fclsid ,
    3593                       z.purpose fexp,0 fdebit, z.zf_item_amt fcredit,'1' fbanksettel ,z.prjno ftransid,'RMB' fcyid,z.unitno fobjid,z.zf_itemno zf_itemno,z.zf_itemname zf_itemname
    3594                        FROM (
    3595                                 SELECT Z.voucher_type,
    3596                                         z.purpose purpose,
    3597                                        z.amt  zf_item_amt,
    3598                                        z.prjno  prjno,
    3599                                        z.unitno,
    3600                                        Z.SRC_ID,
    3601                                        Z.budget_type,
    3602                                        Z.budgetno,
    3603                                        '' zf_itemno,
    3604                                        '' zf_itemname,
    3605                                        (select bz.org_type  from bs_zjly bz where bz.fundno=z.src_id ) ORG_TYPE
    3606                                       -- z.AFFIRM_DATE
    3607                                   FROM  gk_zfpz  Z
    3608                                  WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    3609                                   and z.budgetno in (select distinct bg.func_bdgid from bs_gnflyskm bg where bg.func_bdgname like '%就业%')
    3610                              ) Z
    3611                             order by z.budgetno
    3612                       )
    3613                     )
    3614                     ;
    3615                   ---借方:
    3616 
    3617                     select sum(a.fcredit) into v_total from gk_zwentry a where a.fserialnum = v_fserialnum_3 ;
    3618                     insert into gk_zwentry
    3619                       (fserialnum,
    3620                        fentryid,
    3621                        facctid,
    3622                        fclsid,
    3623                        fexp,
    3624                        fdebit,
    3625                        fcredit,
    3626                        fbanksettel,
    3627                        ftransid,
    3628                        fcyid,
    3629                        fobjid,
    3630                        zf_itemno,
    3631                        zf_itemname,BUDGETID)
    3632                       SELECT v_fserialnum_3,
    3633                              1,
    3634                              '100400301' as facctid ,
    3635                              '0',
    3636                              '',
    3637                              v_total,
    3638                              0,
    3639                              '1',
    3640                              '000',
    3641                              'RMB',
    3642                              '*',
    3643                              '',
    3644                              '','100400301'||',' ||substr(fdate,0,4)|| ',*,*,*'
    3645                         from dual;
    3646 
    3647                     insert into gk_zwvch_refer(FSERIALNUM, orign_type,orign_id,voucher_type,origin_teable,fmodule)
    3648                      select v_fserialnum_3 ,
    3649                          '3' ORIGN_TYPE,
    3650                         z.id ORIGN_ID,
    3651                         z.voucher_type VOUCHER_TYPE,
    3652                         'GK_ZFPZ' ORIGIN_TEABLE,
    3653                         '3' FMODULE
    3654                    from gk_zfpz z
    3655                    WHERE Z.id IN (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id) and z.budgetno in (select distinct bg.func_bdgid from bs_gnflyskm bg where bg.func_bdgname like '%就业%')  ;
    3656              end if;
    3657 
    3658 
    3659 
    3660 
    3661 
    3662 
    3663          /*
    3664            --  全额退款的 直接支付  授权支付
    3665            借:5005财政专户管理资金支出[功能分类科目编码 预算单位编码]
    3666            贷:1004.002.01其他财政存款.其他社会保险基金.农行活期(需与功能分类科目相对应)
    3667            取功能分类科目名称中的关键字:社保保险
    3668 
    3669            会计科目编码组成:5005+功能分类科目编码
    3670 
    3671           */
    3672            select count(1) into v_count_gkfszh  from gk_zfpz  Z   WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    3673             and z.budgetno in (select distinct bg.func_bdgid from bs_gnflyskm bg where bg.func_bdgname like '%保险%')  ;
    3674             if    v_count_gkfszh >0 then
    3675                    --插入主表
    3676                   insert into gk_zwvch
    3677                     (fserialnum,
    3678                      FPERIOD,
    3679                      fgroup,
    3680                      fdate,
    3681                      fnum,
    3682                      fpreparer,
    3683                      fattachment,
    3684                      fmodule,
    3685                      jz_database,
    3686                      org_type,
    3687                      jz_fserialnum,
    3688                      orign_type,
    3689                      make_date)
    3690                     select v_fserialnum_4,
    3691                            substr(fdate, 6, 2),
    3692                            i_fgroup,
    3693                            to_date(fdate, 'yyyy-MM-dd'),
    3694                            0,
    3695                            i_fpreparer,
    3696                            v_count_gkfszh,
    3697                            3,
    3698                            i_databasename,
    3699                            '1', --资金来源类型
    3700                            0,
    3701                            v_orign_type,
    3702                            sysdate
    3703 
    3704                       from dual;
    3705 
    3706 
    3707                  ---借方数据插入     
    3708                   insert into gk_zwentry(fserialnum,fentryid,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,budgetid)
    3709                      select   fserialnum,ROWNUM+1,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname, budgetid from (
    3710                      select fserialnum,ROWNUM+1,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,
    3711                               budgetno || ',' ||substr(fdate,0,4)|| ',' || budget_type || ',' || voucher_type || ',' || SRC_ID  budgetid
    3712                      from (
    3713                          SELECT Z.SRC_ID,Z.voucher_type,z.budget_type,z.budgetno,substr(to_char(sysdate,'yyyy-MM-dd'),0,4) year1,  v_fserialnum_4  fserialnum ,
    3714                       '5005'||budgetno  facctid,
    3715                       '1' fclsid ,
    3716                       z.purpose fexp,0 fdebit,z.zf_item_amt fcredit,'1' fbanksettel ,z.prjno ftransid,'RMB' fcyid,z.unitno fobjid,z.zf_itemno zf_itemno,z.zf_itemname zf_itemname
    3717                        FROM (
    3718                                 SELECT Z.voucher_type,
    3719                                         z.purpose purpose,
    3720                                        z.amt  zf_item_amt,
    3721                                        z.prjno  prjno,
    3722                                        z.unitno,
    3723                                        Z.SRC_ID,
    3724                                        Z.budget_type,
    3725                                        Z.budgetno,
    3726                                        '' zf_itemno,
    3727                                        '' zf_itemname,
    3728                                        (select bz.org_type  from bs_zjly bz where bz.fundno=z.src_id ) ORG_TYPE
    3729                                       -- z.AFFIRM_DATE
    3730                                   FROM  gk_zfpz  Z
    3731                                  WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    3732                                   and z.budgetno in (select distinct bg.func_bdgid from bs_gnflyskm bg where bg.func_bdgname like '%保险%')
    3733                              ) Z
    3734                             order by z.budgetno
    3735                       )
    3736                     )
    3737                     ;
    3738                   ---借方:
    3739 
    3740                     select sum(a.fcredit) into v_total from gk_zwentry a where a.fserialnum = v_fserialnum_4 ;
    3741 
    3742                     insert into gk_zwentry
    3743                       (fserialnum,
    3744                        fentryid,
    3745                        facctid,
    3746                        fclsid,
    3747                        fexp,
    3748                        fdebit,
    3749                        fcredit,
    3750                        fbanksettel,
    3751                        ftransid,
    3752                        fcyid,
    3753                        fobjid,
    3754                        zf_itemno,
    3755                        zf_itemname,BUDGETID)
    3756                       SELECT v_fserialnum_4,
    3757                              1,
    3758                              '100400201' as facctid ,
    3759                              '0',
    3760                              '',
    3761                               v_total,
    3762                              0,
    3763 
    3764                              '1',
    3765                              '000',
    3766                              'RMB',
    3767                              '*',
    3768                              '',
    3769                              '','100400201'||',' ||substr(fdate,0,4)|| ',*,*,*'
    3770                         from dual;
    3771 
    3772                     insert into gk_zwvch_refer(FSERIALNUM, orign_type,orign_id,voucher_type,origin_teable,fmodule)
    3773                      select v_fserialnum_4 ,
    3774                          '3' ORIGN_TYPE,
    3775                         z.id ORIGN_ID,
    3776                         z.voucher_type VOUCHER_TYPE,
    3777                         'GK_ZFPZ' ORIGIN_TEABLE,
    3778                         '3' FMODULE
    3779                    from gk_zfpz z
    3780                    WHERE Z.id IN (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id) and z.budgetno in (select distinct bg.func_bdgid from bs_gnflyskm bg where bg.func_bdgname like '%保险%')  ;
    3781              end if;
    3782 
    3783 
    3784 
    3785 
    3786          /*
    3787            --  全额退款的 直接支付  授权支付
    3788            借:1004.001.01其他财政存款.医院药品收支结余.农行活期(需与功能分类科目相对应)
    3789            贷:5005财政专户管理资金支出[功能分类科目编码 预算单位编码]
    3790            取功能分类科目名称中的关键字: 药品
    3791 
    3792            会计科目编码组成:5005+功能分类科目编码
    3793 
    3794           */
    3795 
    3796             select count(1) into v_count_gkfszh  from gk_zfpz  Z   WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    3797             and z.budgetno in (select distinct bg.func_bdgid from bs_gnflyskm bg where bg.func_bdgname like '%药品%')  ;
    3798             if    v_count_gkfszh >0 then
    3799                    --插入主表
    3800                   insert into gk_zwvch
    3801                     (fserialnum,
    3802                      FPERIOD,
    3803                      fgroup,
    3804                      fdate,
    3805                      fnum,
    3806                      fpreparer,
    3807                      fattachment,
    3808                      fmodule,
    3809                      jz_database,
    3810                      org_type,
    3811                      jz_fserialnum,
    3812                      orign_type,
    3813                      make_date)
    3814                     select v_fserialnum_5,
    3815                            substr(fdate, 6, 2),
    3816                            i_fgroup,
    3817                            to_date(fdate, 'yyyy-MM-dd'),
    3818                            0,
    3819                            i_fpreparer,
    3820                            v_count_gkfszh,
    3821                            3,
    3822                            i_databasename,
    3823                            '1', --资金来源类型
    3824                            0,
    3825                            v_orign_type,
    3826                            sysdate
    3827 
    3828                       from dual;
    3829 
    3830 
    3831                  ---贷方数据插入     
    3832                   insert into gk_zwentry(fserialnum,fentryid,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,budgetid)
    3833                      select   fserialnum,ROWNUM+1,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname, budgetid from (
    3834                      select fserialnum,ROWNUM+1,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,
    3835                               budgetno || ',' ||substr(fdate,0,4)|| ',' || budget_type || ',' || voucher_type || ',' || SRC_ID  budgetid
    3836                      from (
    3837                          SELECT Z.SRC_ID,Z.voucher_type,z.budget_type,z.budgetno,substr(to_char(sysdate,'yyyy-MM-dd'),0,4) year1,  v_fserialnum_5  fserialnum ,
    3838                       '5005'||budgetno  facctid,
    3839                       '1' fclsid ,
    3840                       z.purpose fexp,z.zf_item_amt fdebit,0 fcredit,'1' fbanksettel ,z.prjno ftransid,'RMB' fcyid,z.unitno fobjid,z.zf_itemno zf_itemno,z.zf_itemname zf_itemname
    3841                        FROM (
    3842                                 SELECT Z.voucher_type,
    3843                                         z.purpose purpose,
    3844                                        z.amt  zf_item_amt,
    3845                                        z.prjno  prjno,
    3846                                        z.unitno,
    3847                                        Z.SRC_ID,
    3848                                        Z.budget_type,
    3849                                        Z.budgetno,
    3850                                        '' zf_itemno,
    3851                                        '' zf_itemname,
    3852                                        (select bz.org_type  from bs_zjly bz where bz.fundno=z.src_id ) ORG_TYPE
    3853                                       -- z.AFFIRM_DATE
    3854                                   FROM  gk_zfpz  Z
    3855                                  WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    3856                                   and z.budgetno in (select distinct bg.func_bdgid from bs_gnflyskm bg where bg.func_bdgname like '%药品%')
    3857                              ) Z
    3858                             order by z.budgetno
    3859                       )
    3860                     )
    3861                     ;
    3862                   ---借方:
    3863 
    3864                     select sum(a.fcredit) into v_total from gk_zwentry a where a.fserialnum = v_fserialnum_5 ;
    3865                     insert into gk_zwentry
    3866                       (fserialnum,
    3867                        fentryid,
    3868                        facctid,
    3869                        fclsid,
    3870                        fexp,
    3871                        fdebit,
    3872                        fcredit,
    3873                        fbanksettel,
    3874                        ftransid,
    3875                        fcyid,
    3876                        fobjid,
    3877                        zf_itemno,
    3878                        zf_itemname,BUDGETID)
    3879                       SELECT v_fserialnum_5,
    3880                              v_max_index,
    3881                              '100400101' as facctid ,
    3882                              '0',
    3883                              '',
    3884                               v_total,
    3885                              0,
    3886 
    3887                              '1',
    3888                              '000',
    3889                              'RMB',
    3890                              '*',
    3891                              '',
    3892                              '','100400101'||',' ||substr(fdate,0,4)|| ',*,*,*'
    3893                         from dual;
    3894 
    3895                     insert into gk_zwvch_refer(FSERIALNUM, orign_type,orign_id,voucher_type,origin_teable,fmodule)
    3896                      select v_fserialnum_5 ,
    3897                          '3' ORIGN_TYPE,
    3898                         z.id ORIGN_ID,
    3899                         z.voucher_type VOUCHER_TYPE,
    3900                         'GK_ZFPZ' ORIGIN_TEABLE,
    3901                         '3' FMODULE
    3902                    from gk_zfpz z
    3903                    WHERE Z.id IN (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id) and z.budgetno in (select distinct bg.func_bdgid from bs_gnflyskm bg where bg.func_bdgname like '%药品%')  ;
    3904              end if;
    3905 
    3906 
    3907          elsif   opertype='4' or   opertype='5'  then
    3908 
    3909           /*
    3910            -- 部分退款的  直接支付  授权支付
    3911            借:1004.005.01其他财政存款.残疾人事业专项资金.农行活期(需与功能分类科目相对应)
    3912            贷:5005财政专户管理资金支出[功能分类科目编码 预算单位编码]
    3913            取功能分类科目名称中的关键字:  残疾           (全部以农行活期结尾)
    3914 
    3915            会计科目编码组成:5005+功能分类科目编码
    3916 
    3917           */
    3918          select count(1) into v_count_gkfszh  from gk_part_refundment  Z   WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    3919             and z.budgetno in (select distinct bg.func_bdgid from bs_gnflyskm bg where bg.func_bdgname like '%残疾%');
    3920             if    v_count_gkfszh >0 then
    3921                    --插入主表
    3922                   insert into gk_zwvch
    3923                     (fserialnum,
    3924                      FPERIOD,
    3925                      fgroup,
    3926                      fdate,
    3927                      fnum,
    3928                      fpreparer,
    3929                      fattachment,
    3930                      fmodule,
    3931                      jz_database,
    3932                      org_type,
    3933                      jz_fserialnum,
    3934                      orign_type,
    3935                      make_date)
    3936                     select v_fserialnum_1,
    3937                            substr(fdate, 6, 2),
    3938                            i_fgroup,
    3939                            to_date(fdate, 'yyyy-MM-dd'),
    3940                            0,
    3941                            i_fpreparer,
    3942                            v_count_gkfszh,
    3943                            3,
    3944                            i_databasename,
    3945                            '1', --资金来源类型
    3946                            0,
    3947                            v_orign_type,
    3948                            sysdate
    3949 
    3950                       from dual;
    3951 
    3952 
    3953                  ---贷方数据插入     
    3954                   insert into gk_zwentry(fserialnum,fentryid,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,budgetid)
    3955                      select   fserialnum,ROWNUM+1,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname, budgetid from (
    3956                      select fserialnum,ROWNUM+1,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,
    3957                               budgetno || ',' ||substr(fdate,0,4)|| ',' || budget_type || ',' || voucher_type || ',' || SRC_ID  budgetid
    3958                      from (
    3959                          SELECT Z.SRC_ID,Z.voucher_type,z.budget_type,z.budgetno,substr(to_char(sysdate,'yyyy-MM-dd'),0,4) year1,  v_fserialnum_1  fserialnum ,
    3960                       '5005'||budgetno  facctid,
    3961                       '1' fclsid ,
    3962                       z.purpose fexp, 0 fdebit,z.zf_item_amt fcredit,'1' fbanksettel ,z.prjno ftransid,'RMB' fcyid,z.unitno fobjid,z.zf_itemno zf_itemno,z.zf_itemname zf_itemname
    3963                        FROM (
    3964                                 SELECT Z.voucher_type,
    3965                                         z.remark purpose,
    3966                                        z.amt  zf_item_amt,
    3967                                        z.prjno  prjno,
    3968                                        z.unitno,
    3969                                        Z.SRC_ID,
    3970                                        Z.budget_type,
    3971                                        Z.budgetno,
    3972                                        '' zf_itemno,
    3973                                        '' zf_itemname,
    3974                                        (select bz.org_type  from bs_zjly bz where bz.fundno=z.src_id ) ORG_TYPE
    3975                                       -- z.AFFIRM_DATE
    3976                                   FROM  gk_part_refundment  Z
    3977                                  WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    3978                                  and z.budgetno in (select distinct bg.func_bdgid from bs_gnflyskm bg where bg.func_bdgname like '%残疾%')
    3979                              ) Z
    3980                             order by z.budgetno
    3981                       )
    3982                     )
    3983                     ;
    3984                   ---借方:
    3985 
    3986                     select sum(a.fcredit) into v_total from gk_zwentry a where a.fserialnum = v_fserialnum_1 ;
    3987 
    3988                     insert into gk_zwentry
    3989                       (fserialnum,
    3990                        fentryid,
    3991                        facctid,
    3992                        fclsid,
    3993                        fexp,
    3994                        fdebit,
    3995                        fcredit,
    3996                        fbanksettel,
    3997                        ftransid,
    3998                        fcyid,
    3999                        fobjid,
    4000                        zf_itemno,
    4001                        zf_itemname,BUDGETID)
    4002                       SELECT v_fserialnum_1,
    4003                              1,
    4004                              '100400501' as facctid ,
    4005                              '0',
    4006                              '',
    4007                              v_total,
    4008                              0,
    4009                              '1',
    4010                              '000',
    4011                              'RMB',
    4012                              '*',
    4013                              '',
    4014                              '','100400501'||',' ||substr(fdate,0,4)|| ',*,*,*'
    4015                         from dual;
    4016 
    4017                     insert into gk_zwvch_refer(FSERIALNUM, orign_type,orign_id,voucher_type,origin_teable,fmodule)
    4018                      select v_fserialnum_1 ,
    4019                          '3' ORIGN_TYPE,
    4020                         z.id ORIGN_ID,
    4021                         z.voucher_type VOUCHER_TYPE,
    4022                         'GK_PART_REFUNDMENT' ORIGIN_TEABLE,
    4023                         '3' FMODULE
    4024                    from gk_part_refundment z
    4025                    WHERE Z.id IN (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)  and z.budgetno in (select distinct bg.func_bdgid from bs_gnflyskm bg where bg.func_bdgname like '%残疾%') ;
    4026              end if;
    4027 
    4028 
    4029          /*
    4030           -- 部分退款的  直接支付  授权支付
    4031            借:1004.004.01其他财政存款.医疗救助资金.农行活期(需与功能分类科目相对应)
    4032            贷:5005财政专户管理资金支出[功能分类科目编码 预算单位编码]
    4033            取功能分类科目名称中的关键字: 医疗
    4034 
    4035            会计科目编码组成:5005+功能分类科目编码
    4036 
    4037           */
    4038            select count(1) into v_count_gkfszh  from gk_part_refundment  Z   WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    4039             and z.budgetno in (select distinct bg.func_bdgid from bs_gnflyskm bg where bg.func_bdgname like '%医疗%' and bg.func_bdgname not  like '%药品%')  ;
    4040             if    v_count_gkfszh >0 then
    4041                    --插入主表
    4042                   insert into gk_zwvch
    4043                     (fserialnum,
    4044                      FPERIOD,
    4045                      fgroup,
    4046                      fdate,
    4047                      fnum,
    4048                      fpreparer,
    4049                      fattachment,
    4050                      fmodule,
    4051                      jz_database,
    4052                      org_type,
    4053                      jz_fserialnum,
    4054                      orign_type,
    4055                      make_date)
    4056                     select v_fserialnum_2,
    4057                            substr(fdate, 6, 2),
    4058                            i_fgroup,
    4059                            to_date(fdate, 'yyyy-MM-dd'),
    4060                            0,
    4061                            i_fpreparer,
    4062                            v_count_gkfszh,
    4063                            3,
    4064                            i_databasename,
    4065                            '1', --资金来源类型
    4066                            0,
    4067                            v_orign_type,
    4068                            sysdate
    4069 
    4070                       from dual;
    4071 
    4072 
    4073                  ---贷方数据插入     
    4074                   insert into gk_zwentry(fserialnum,fentryid,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,budgetid)
    4075                      select   fserialnum,ROWNUM+1,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname, budgetid from (
    4076                      select fserialnum,ROWNUM+1,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,
    4077                               budgetno || ',' ||substr(fdate,0,4)|| ',' || budget_type || ',' || voucher_type || ',' || SRC_ID  budgetid
    4078                      from (
    4079                          SELECT Z.SRC_ID,Z.voucher_type,z.budget_type,z.budgetno,substr(to_char(sysdate,'yyyy-MM-dd'),0,4) year1,  v_fserialnum_2  fserialnum ,
    4080                       '5005'||budgetno  facctid,
    4081                       '1' fclsid ,
    4082                       z.purpose fexp,0 fdebit,  z.zf_item_amt fcredit,'1' fbanksettel ,z.prjno ftransid,'RMB' fcyid,z.unitno fobjid,z.zf_itemno zf_itemno,z.zf_itemname zf_itemname
    4083                        FROM (
    4084                                 SELECT Z.voucher_type,
    4085                                         z.remark purpose,
    4086                                        z.amt  zf_item_amt,
    4087                                        z.prjno  prjno,
    4088                                        z.unitno,
    4089                                        Z.SRC_ID,
    4090                                        Z.budget_type,
    4091                                        Z.budgetno,
    4092                                        '' zf_itemno,
    4093                                        '' zf_itemname,
    4094                                        (select bz.org_type  from bs_zjly bz where bz.fundno=z.src_id ) ORG_TYPE
    4095                                       -- z.AFFIRM_DATE
    4096                                   FROM  gk_part_refundment  Z
    4097                                  WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    4098                                   and z.budgetno in (select distinct bg.func_bdgid from bs_gnflyskm bg where bg.func_bdgname like '%医疗%' and bg.func_bdgname not  like '%药品%')
    4099                              ) Z
    4100                             order by z.budgetno
    4101                       )
    4102                     )
    4103                     ;
    4104                   ---借方:
    4105 
    4106                     select sum(a.fcredit) into v_total from gk_zwentry a where a.fserialnum = v_fserialnum_2 ;
    4107                     insert into gk_zwentry
    4108                       (fserialnum,
    4109                        fentryid,
    4110                        facctid,
    4111                        fclsid,
    4112                        fexp,
    4113                        fdebit,
    4114                        fcredit,
    4115                        fbanksettel,
    4116                        ftransid,
    4117                        fcyid,
    4118                        fobjid,
    4119                        zf_itemno,
    4120                        zf_itemname,BUDGETID)
    4121                       SELECT v_fserialnum_2,
    4122                              1,
    4123                              '100400401' as facctid ,
    4124                              '0',
    4125                              '',
    4126                              v_total,
    4127                              0,
    4128                              '1',
    4129                              '000',
    4130                              'RMB',
    4131                              '*',
    4132                              '',
    4133                              '','100400401'||',' ||substr(fdate,0,4)|| ',*,*,*'
    4134                         from dual;
    4135 
    4136                     insert into gk_zwvch_refer(FSERIALNUM, orign_type,orign_id,voucher_type,origin_teable,fmodule)
    4137                      select v_fserialnum_2 ,
    4138                          '3' ORIGN_TYPE,
    4139                         z.id ORIGN_ID,
    4140                         z.voucher_type VOUCHER_TYPE,
    4141                         'GK_PART_REFUNDMENT' ORIGIN_TEABLE,
    4142                         '3' FMODULE
    4143                    from gk_part_refundment z
    4144                    WHERE Z.id IN (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id) and z.budgetno in (select distinct bg.func_bdgid from bs_gnflyskm bg where bg.func_bdgname like '%医疗%' and bg.func_bdgname not  like '%药品%' )  ;
    4145              end if;
    4146 
    4147 
    4148 
    4149 
    4150          /*
    4151            -- 部分退款的  直接支付  授权支付
    4152            借:1004.003.01其他财政存款.灵活就业资金.农行活期(需与功能分类科目相对应)
    4153            贷:5005财政专户管理资金支出[功能分类科目编码 预算单位编码]
    4154            取功能分类科目名称中的关键字:就业
    4155 
    4156            会计科目编码组成:5005+功能分类科目编码
    4157 
    4158           */
    4159            select count(1) into v_count_gkfszh  from gk_part_refundment  Z   WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    4160             and z.budgetno in (select distinct bg.func_bdgid from bs_gnflyskm bg where bg.func_bdgname like '%就业%')  ;
    4161             if    v_count_gkfszh >0 then
    4162                    --插入主表
    4163                   insert into gk_zwvch
    4164                     (fserialnum,
    4165                      FPERIOD,
    4166                      fgroup,
    4167                      fdate,
    4168                      fnum,
    4169                      fpreparer,
    4170                      fattachment,
    4171                      fmodule,
    4172                      jz_database,
    4173                      org_type,
    4174                      jz_fserialnum,
    4175                      orign_type,
    4176                      make_date)
    4177                     select v_fserialnum_3,
    4178                            substr(fdate, 6, 2),
    4179                            i_fgroup,
    4180                            to_date(fdate, 'yyyy-MM-dd'),
    4181                            0,
    4182                            i_fpreparer,
    4183                            v_count_gkfszh,
    4184                            3,
    4185                            i_databasename,
    4186                            '1', --资金来源类型
    4187                            0,
    4188                            v_orign_type,
    4189                            sysdate
    4190 
    4191                       from dual;
    4192 
    4193 
    4194                  ---贷方数据插入     
    4195                   insert into gk_zwentry(fserialnum,fentryid,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,budgetid)
    4196                      select   fserialnum,ROWNUM+1,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname, budgetid from (
    4197                      select fserialnum,ROWNUM+1,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,
    4198                               budgetno || ',' ||substr(fdate,0,4)|| ',' || budget_type || ',' || voucher_type || ',' || SRC_ID  budgetid
    4199                      from (
    4200                          SELECT Z.SRC_ID,Z.voucher_type,z.budget_type,z.budgetno,substr(to_char(sysdate,'yyyy-MM-dd'),0,4) year1,  v_fserialnum_3  fserialnum ,
    4201                       '5005'||budgetno  facctid,
    4202                       '1' fclsid ,
    4203                       z.purpose fexp,0 fdebit, z.zf_item_amt fcredit,'1' fbanksettel ,z.prjno ftransid,'RMB' fcyid,z.unitno fobjid,z.zf_itemno zf_itemno,z.zf_itemname zf_itemname
    4204                        FROM (
    4205                                 SELECT Z.voucher_type,
    4206                                         z.remark purpose,
    4207                                        z.amt  zf_item_amt,
    4208                                        z.prjno  prjno,
    4209                                        z.unitno,
    4210                                        Z.SRC_ID,
    4211                                        Z.budget_type,
    4212                                        Z.budgetno,
    4213                                        '' zf_itemno,
    4214                                        '' zf_itemname,
    4215                                        (select bz.org_type  from bs_zjly bz where bz.fundno=z.src_id ) ORG_TYPE
    4216                                       -- z.AFFIRM_DATE
    4217                                   FROM  GK_PART_REFUNDMENT  Z
    4218                                  WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    4219                                   and z.budgetno in (select distinct bg.func_bdgid from bs_gnflyskm bg where bg.func_bdgname like '%就业%')
    4220                              ) Z
    4221                             order by z.budgetno
    4222                       )
    4223                     )
    4224                     ;
    4225                   ---借方:
    4226 
    4227                     select sum(a.fcredit) into v_total from gk_zwentry a where a.fserialnum = v_fserialnum_3 ;
    4228                     insert into gk_zwentry
    4229                       (fserialnum,
    4230                        fentryid,
    4231                        facctid,
    4232                        fclsid,
    4233                        fexp,
    4234                        fdebit,
    4235                        fcredit,
    4236                        fbanksettel,
    4237                        ftransid,
    4238                        fcyid,
    4239                        fobjid,
    4240                        zf_itemno,
    4241                        zf_itemname,BUDGETID)
    4242                       SELECT v_fserialnum_3,
    4243                              1,
    4244                              '100400301' as facctid ,
    4245                              '0',
    4246                              '',
    4247                              v_total,
    4248                              0,
    4249                              '1',
    4250                              '000',
    4251                              'RMB',
    4252                              '*',
    4253                              '',
    4254                              '','100400301'||',' ||substr(fdate,0,4)|| ',*,*,*'
    4255                         from dual;
    4256 
    4257                     insert into gk_zwvch_refer(FSERIALNUM, orign_type,orign_id,voucher_type,origin_teable,fmodule)
    4258                      select v_fserialnum_3 ,
    4259                          '3' ORIGN_TYPE,
    4260                         z.id ORIGN_ID,
    4261                         z.voucher_type VOUCHER_TYPE,
    4262                         'GK_PART_REFUNDMENT' ORIGIN_TEABLE,
    4263                         '3' FMODULE
    4264                    from GK_PART_REFUNDMENT z
    4265                    WHERE Z.id IN (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id) and z.budgetno in (select distinct bg.func_bdgid from bs_gnflyskm bg where bg.func_bdgname like '%就业%')  ;
    4266              end if;
    4267 
    4268 
    4269 
    4270 
    4271          /*
    4272           -- 部分退款的  直接支付  授权支付
    4273            借:1004.002.01其他财政存款.其他社会保险基金.农行活期(需与功能分类科目相对应)
    4274            贷:5005财政专户管理资金支出[功能分类科目编码 预算单位编码]
    4275            取功能分类科目名称中的关键字:社保保险
    4276 
    4277            会计科目编码组成:5005+功能分类科目编码
    4278 
    4279           */
    4280            select count(1) into v_count_gkfszh  from gk_part_refundment  Z   WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    4281             and z.budgetno in (select distinct bg.func_bdgid from bs_gnflyskm bg where bg.func_bdgname like '%保险%')  ;
    4282             if    v_count_gkfszh >0 then
    4283                    --插入主表
    4284                   insert into gk_zwvch
    4285                     (fserialnum,
    4286                      FPERIOD,
    4287                      fgroup,
    4288                      fdate,
    4289                      fnum,
    4290                      fpreparer,
    4291                      fattachment,
    4292                      fmodule,
    4293                      jz_database,
    4294                      org_type,
    4295                      jz_fserialnum,
    4296                      orign_type,
    4297                      make_date)
    4298                     select v_fserialnum_4,
    4299                            substr(fdate, 6, 2),
    4300                            i_fgroup,
    4301                            to_date(fdate, 'yyyy-MM-dd'),
    4302                            0,
    4303                            i_fpreparer,
    4304                            v_count_gkfszh,
    4305                            3,
    4306                            i_databasename,
    4307                            '1', --资金来源类型
    4308                            0,
    4309                            v_orign_type,
    4310                            sysdate
    4311 
    4312                       from dual;
    4313 
    4314 
    4315                  ---借方数据插入     
    4316                   insert into gk_zwentry(fserialnum,fentryid,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,budgetid)
    4317                      select   fserialnum,ROWNUM+1,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname, budgetid from (
    4318                      select fserialnum,ROWNUM+1,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,
    4319                               budgetno || ',' ||substr(fdate,0,4)|| ',' || budget_type || ',' || voucher_type || ',' || SRC_ID  budgetid
    4320                      from (
    4321                          SELECT Z.SRC_ID,Z.voucher_type,z.budget_type,z.budgetno,substr(to_char(sysdate,'yyyy-MM-dd'),0,4) year1,  v_fserialnum_4  fserialnum ,
    4322                       '5005'||budgetno  facctid,
    4323                       '1' fclsid ,
    4324                       z.purpose fexp,0 fdebit,z.zf_item_amt fcredit,'1' fbanksettel ,z.prjno ftransid,'RMB' fcyid,z.unitno fobjid,z.zf_itemno zf_itemno,z.zf_itemname zf_itemname
    4325                        FROM (
    4326                                 SELECT Z.voucher_type,
    4327                                         z.remark purpose,
    4328                                        z.amt  zf_item_amt,
    4329                                        z.prjno  prjno,
    4330                                        z.unitno,
    4331                                        Z.SRC_ID,
    4332                                        Z.budget_type,
    4333                                        Z.budgetno,
    4334                                        '' zf_itemno,
    4335                                        '' zf_itemname,
    4336                                        (select bz.org_type  from bs_zjly bz where bz.fundno=z.src_id ) ORG_TYPE
    4337                                       -- z.AFFIRM_DATE
    4338                                   FROM  GK_PART_REFUNDMENT  Z
    4339                                  WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    4340                                   and z.budgetno in (select distinct bg.func_bdgid from bs_gnflyskm bg where bg.func_bdgname like '%保险%')
    4341                              ) Z
    4342                             order by z.budgetno
    4343                       )
    4344                     )
    4345                     ;
    4346                   ---借方:
    4347 
    4348                     select sum(a.fcredit) into v_total from gk_zwentry a where a.fserialnum = v_fserialnum_4 ;
    4349 
    4350                     insert into gk_zwentry
    4351                       (fserialnum,
    4352                        fentryid,
    4353                        facctid,
    4354                        fclsid,
    4355                        fexp,
    4356                        fdebit,
    4357                        fcredit,
    4358                        fbanksettel,
    4359                        ftransid,
    4360                        fcyid,
    4361                        fobjid,
    4362                        zf_itemno,
    4363                        zf_itemname,BUDGETID)
    4364                       SELECT v_fserialnum_4,
    4365                              1,
    4366                              '100400201' as facctid ,
    4367                              '0',
    4368                              '',
    4369                               v_total,
    4370                              0,
    4371 
    4372                              '1',
    4373                              '000',
    4374                              'RMB',
    4375                              '*',
    4376                              '',
    4377                              '','100400201'||',' ||substr(fdate,0,4)|| ',*,*,*'
    4378                         from dual;
    4379 
    4380                     insert into gk_zwvch_refer(FSERIALNUM, orign_type,orign_id,voucher_type,origin_teable,fmodule)
    4381                      select v_fserialnum_4 ,
    4382                          '3' ORIGN_TYPE,
    4383                         z.id ORIGN_ID,
    4384                         z.voucher_type VOUCHER_TYPE,
    4385                         'GK_PART_REFUNDMENT' ORIGIN_TEABLE,
    4386                         '3' FMODULE
    4387                    from GK_PART_REFUNDMENT z
    4388                    WHERE Z.id IN (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id) and z.budgetno in (select distinct bg.func_bdgid from bs_gnflyskm bg where bg.func_bdgname like '%保险%')  ;
    4389              end if;
    4390 
    4391 
    4392 
    4393          /*
    4394            -- 部分退款的  直接支付  授权支付
    4395            借:1004.001.01其他财政存款.医院药品收支结余.农行活期(需与功能分类科目相对应)
    4396            贷:5005财政专户管理资金支出[功能分类科目编码 预算单位编码]
    4397            取功能分类科目名称中的关键字: 药品
    4398 
    4399            会计科目编码组成:5005+功能分类科目编码
    4400 
    4401           */
    4402             select count(1) into v_count_gkfszh  from gk_part_refundment  Z   WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    4403             and z.budgetno in (select distinct bg.func_bdgid from bs_gnflyskm bg where bg.func_bdgname like '%药品%')  ;
    4404             if    v_count_gkfszh >0 then
    4405                    --插入主表
    4406                   insert into gk_zwvch
    4407                     (fserialnum,
    4408                      FPERIOD,
    4409                      fgroup,
    4410                      fdate,
    4411                      fnum,
    4412                      fpreparer,
    4413                      fattachment,
    4414                      fmodule,
    4415                      jz_database,
    4416                      org_type,
    4417                      jz_fserialnum,
    4418                      orign_type,
    4419                      make_date)
    4420                     select v_fserialnum_5,
    4421                            substr(fdate, 6, 2),
    4422                            i_fgroup,
    4423                            to_date(fdate, 'yyyy-MM-dd'),
    4424                            0,
    4425                            i_fpreparer,
    4426                            v_count_gkfszh,
    4427                            3,
    4428                            i_databasename,
    4429                            '1', --资金来源类型
    4430                            0,
    4431                            v_orign_type,
    4432                            sysdate
    4433 
    4434                       from dual;
    4435 
    4436 
    4437                  ---贷方数据插入     
    4438                   insert into gk_zwentry(fserialnum,fentryid,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,budgetid)
    4439                      select   fserialnum,ROWNUM+1,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname, budgetid from (
    4440                      select fserialnum,ROWNUM+1,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,
    4441                               budgetno || ',' ||substr(fdate,0,4)|| ',' || budget_type || ',' || voucher_type || ',' || SRC_ID  budgetid
    4442                      from (
    4443                          SELECT Z.SRC_ID,Z.voucher_type,z.budget_type,z.budgetno,substr(to_char(sysdate,'yyyy-MM-dd'),0,4) year1,  v_fserialnum_5  fserialnum ,
    4444                       '5005'||budgetno  facctid,
    4445                       '1' fclsid ,
    4446                       z.purpose fexp,z.zf_item_amt fdebit,0 fcredit,'1' fbanksettel ,z.prjno ftransid,'RMB' fcyid,z.unitno fobjid,z.zf_itemno zf_itemno,z.zf_itemname zf_itemname
    4447                        FROM (
    4448                                 SELECT Z.voucher_type,
    4449                                         z.remark purpose,
    4450                                        z.amt  zf_item_amt,
    4451                                        z.prjno  prjno,
    4452                                        z.unitno,
    4453                                        Z.SRC_ID,
    4454                                        Z.budget_type,
    4455                                        Z.budgetno,
    4456                                        '' zf_itemno,
    4457                                        '' zf_itemname,
    4458                                        (select bz.org_type  from bs_zjly bz where bz.fundno=z.src_id ) ORG_TYPE
    4459                                       -- z.AFFIRM_DATE
    4460                                   FROM  GK_PART_REFUNDMENT  Z
    4461                                  WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    4462                                   and z.budgetno in (select distinct bg.func_bdgid from bs_gnflyskm bg where bg.func_bdgname like '%药品%')
    4463                              ) Z
    4464                             order by z.budgetno
    4465                       )
    4466                     )
    4467                     ;
    4468                   ---借方:
    4469 
    4470                     select sum(a.fcredit) into v_total from gk_zwentry a where a.fserialnum = v_fserialnum_5 ;
    4471                     insert into gk_zwentry
    4472                       (fserialnum,
    4473                        fentryid,
    4474                        facctid,
    4475                        fclsid,
    4476                        fexp,
    4477                        fdebit,
    4478                        fcredit,
    4479                        fbanksettel,
    4480                        ftransid,
    4481                        fcyid,
    4482                        fobjid,
    4483                        zf_itemno,
    4484                        zf_itemname,BUDGETID)
    4485                       SELECT v_fserialnum_5,
    4486                              v_max_index,
    4487                              '100400101' as facctid ,
    4488                              '0',
    4489                              '',
    4490                               v_total,
    4491                              0,
    4492 
    4493                              '1',
    4494                              '000',
    4495                              'RMB',
    4496                              '*',
    4497                              '',
    4498                              '','100400101'||',' ||substr(fdate,0,4)|| ',*,*,*'
    4499                         from dual;
    4500 
    4501                     insert into gk_zwvch_refer(FSERIALNUM, orign_type,orign_id,voucher_type,origin_teable,fmodule)
    4502                      select v_fserialnum_5 ,
    4503                          '3' ORIGN_TYPE,
    4504                         z.id ORIGN_ID,
    4505                         z.voucher_type VOUCHER_TYPE,
    4506                         'GK_PART_REFUNDMENT' ORIGIN_TEABLE,
    4507                         '3' FMODULE
    4508                    from GK_PART_REFUNDMENT z
    4509                    WHERE Z.id IN (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id) and z.budgetno in (select distinct bg.func_bdgid from bs_gnflyskm bg where bg.func_bdgname like '%药品%')  ;
    4510              end if;
    4511 
    4512 
    4513 
    4514          elsif   opertype='7' then
    4515 
    4516           /*
    4517            -- 退款的 一般支付
    4518            借:1004.005.01其他财政存款.残疾人事业专项资金.农行活期(需与功能分类科目相对应)
    4519            贷:5005财政专户管理资金支出[功能分类科目编码 预算单位编码]
    4520            取功能分类科目名称中的关键字:  残疾           (全部以农行活期结尾)
    4521 
    4522            会计科目编码组成:5005+功能分类科目编码
    4523 
    4524           */
    4525 
    4526           select count(1) into v_count_gkfszh  from  (  select crbd.id  as id ,  '3' voucher_type , crb.reason as refundment_memo ,   crbd.pay_amt as amt , crbd.prjno as prjno  ,crb.unitno ,crb.src_id as SRC_ID ,crbd.budget_type ,crbd.budgetno  from  common_req_back crb,common_req_back_detail crbd where crb.id=crbd.common_req_back_id)   Z   WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    4527             and z.budgetno in (select distinct bg.func_bdgid from bs_gnflyskm bg where bg.func_bdgname like '%残疾%');
    4528             if    v_count_gkfszh >0 then
    4529                    --插入主表
    4530                   insert into gk_zwvch
    4531                     (fserialnum,
    4532                      FPERIOD,
    4533                      fgroup,
    4534                      fdate,
    4535                      fnum,
    4536                      fpreparer,
    4537                      fattachment,
    4538                      fmodule,
    4539                      jz_database,
    4540                      org_type,
    4541                      jz_fserialnum,
    4542                      orign_type,
    4543                      make_date)
    4544                     select v_fserialnum_1,
    4545                            substr(fdate, 6, 2),
    4546                            i_fgroup,
    4547                            to_date(fdate, 'yyyy-MM-dd'),
    4548                            0,
    4549                            i_fpreparer,
    4550                            v_count_gkfszh,
    4551                            3,
    4552                            i_databasename,
    4553                            '1', --资金来源类型
    4554                            0,
    4555                            v_orign_type,
    4556                            sysdate
    4557 
    4558                       from dual;
    4559 
    4560 
    4561                  ---贷方数据插入     
    4562                   insert into gk_zwentry(fserialnum,fentryid,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,budgetid)
    4563                      select   fserialnum,ROWNUM+1,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname, budgetid from (
    4564                      select fserialnum,ROWNUM+1,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,
    4565                               budgetno || ',' ||substr(fdate,0,4)|| ',' || budget_type || ',' || voucher_type || ',' || SRC_ID  budgetid
    4566                      from (
    4567                          SELECT Z.SRC_ID,Z.voucher_type,z.budget_type,z.budgetno,substr(to_char(sysdate,'yyyy-MM-dd'),0,4) year1,  v_fserialnum_1  fserialnum ,
    4568                       '5005'||budgetno  facctid,
    4569                       '1' fclsid ,
    4570                       z.purpose fexp, 0 fdebit,z.zf_item_amt fcredit,'1' fbanksettel ,z.prjno ftransid,'RMB' fcyid,z.unitno fobjid,z.zf_itemno zf_itemno,z.zf_itemname zf_itemname
    4571                        FROM (
    4572                                 SELECT Z.voucher_type,
    4573                                         z.refundment_memo purpose,
    4574                                        z.amt  zf_item_amt,
    4575                                        z.prjno  prjno,
    4576                                        z.unitno,
    4577                                        Z.SRC_ID,
    4578                                        Z.budget_type,
    4579                                        Z.budgetno,
    4580                                        '' zf_itemno,
    4581                                        '' zf_itemname,
    4582                                        (select bz.org_type  from bs_zjly bz where bz.fundno=z.src_id ) ORG_TYPE
    4583                                       -- z.AFFIRM_DATE
    4584                                   FROM   (  select crbd.id  as id ,  '3' voucher_type , crb.reason as refundment_memo ,   crbd.pay_amt as amt , crbd.prjno as prjno  ,crb.unitno ,crb.src_id as SRC_ID ,crbd.budget_type ,crbd.budgetno  from  common_req_back crb,common_req_back_detail crbd where crb.id=crbd.common_req_back_id)    Z
    4585                                  WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    4586                                  and z.budgetno in (select distinct bg.func_bdgid from bs_gnflyskm bg where bg.func_bdgname like '%残疾%')
    4587                              ) Z
    4588                             order by z.budgetno
    4589                       )
    4590                     )
    4591                     ;
    4592                   ---借方:
    4593 
    4594                     select sum(a.fcredit) into v_total from gk_zwentry a where a.fserialnum = v_fserialnum_1 ;
    4595 
    4596                     insert into gk_zwentry
    4597                       (fserialnum,
    4598                        fentryid,
    4599                        facctid,
    4600                        fclsid,
    4601                        fexp,
    4602                        fdebit,
    4603                        fcredit,
    4604                        fbanksettel,
    4605                        ftransid,
    4606                        fcyid,
    4607                        fobjid,
    4608                        zf_itemno,
    4609                        zf_itemname,BUDGETID)
    4610                       SELECT v_fserialnum_1,
    4611                              1,
    4612                              '100400501' as facctid ,
    4613                              '0',
    4614                              '',
    4615                              v_total,
    4616                              0,
    4617                              '1',
    4618                              '000',
    4619                              'RMB',
    4620                              '*',
    4621                              '',
    4622                              '','100400501'||',' ||substr(fdate,0,4)|| ',*,*,*'
    4623                         from dual;
    4624 
    4625                     insert into gk_zwvch_refer(FSERIALNUM, orign_type,orign_id,voucher_type,origin_teable,fmodule)
    4626                      select v_fserialnum_1 ,
    4627                          '3' ORIGN_TYPE,
    4628                         z.id ORIGN_ID,
    4629                         z.voucher_type VOUCHER_TYPE,
    4630                         'common_req_back_detail' ORIGIN_TEABLE,
    4631                         '3' FMODULE
    4632                    from (  select crbd.id  as id ,  '3' voucher_type , crb.reason as refundment_memo ,   crbd.pay_amt as amt , crbd.prjno as prjno  ,crb.unitno ,crb.src_id as SRC_ID ,crbd.budget_type ,crbd.budgetno  from  common_req_back crb,common_req_back_detail crbd where crb.id=crbd.common_req_back_id)  z
    4633                    WHERE Z.id IN (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)  and z.budgetno in (select distinct bg.func_bdgid from bs_gnflyskm bg where bg.func_bdgname like '%残疾%') ;
    4634              end if;
    4635 
    4636 
    4637          /*
    4638           -- 退款的 一般支付
    4639            借:1004.004.01其他财政存款.医疗救助资金.农行活期(需与功能分类科目相对应)
    4640            贷:5005财政专户管理资金支出[功能分类科目编码 预算单位编码]
    4641            取功能分类科目名称中的关键字: 医疗
    4642 
    4643            会计科目编码组成:5005+功能分类科目编码
    4644 
    4645           */
    4646          select count(1) into v_count_gkfszh  from gk_zfpz  Z   WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    4647             and z.budgetno in (select distinct bg.func_bdgid from bs_gnflyskm bg where bg.func_bdgname like '%医疗%' and bg.func_bdgname not  like '%药品%')  ;
    4648             if    v_count_gkfszh >0 then
    4649                    --插入主表
    4650                   insert into gk_zwvch
    4651                     (fserialnum,
    4652                      FPERIOD,
    4653                      fgroup,
    4654                      fdate,
    4655                      fnum,
    4656                      fpreparer,
    4657                      fattachment,
    4658                      fmodule,
    4659                      jz_database,
    4660                      org_type,
    4661                      jz_fserialnum,
    4662                      orign_type,
    4663                      make_date)
    4664                     select v_fserialnum_2,
    4665                            substr(fdate, 6, 2),
    4666                            i_fgroup,
    4667                            to_date(fdate, 'yyyy-MM-dd'),
    4668                            0,
    4669                            i_fpreparer,
    4670                            v_count_gkfszh,
    4671                            3,
    4672                            i_databasename,
    4673                            '1', --资金来源类型
    4674                            0,
    4675                            v_orign_type,
    4676                            sysdate
    4677 
    4678                       from dual;
    4679 
    4680 
    4681                  ---贷方数据插入     
    4682                   insert into gk_zwentry(fserialnum,fentryid,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,budgetid)
    4683                      select   fserialnum,ROWNUM+1,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname, budgetid from (
    4684                      select fserialnum,ROWNUM+1,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,
    4685                               budgetno || ',' ||substr(fdate,0,4)|| ',' || budget_type || ',' || voucher_type || ',' || SRC_ID  budgetid
    4686                      from (
    4687                          SELECT Z.SRC_ID,Z.voucher_type,z.budget_type,z.budgetno,substr(to_char(sysdate,'yyyy-MM-dd'),0,4) year1,  v_fserialnum_2  fserialnum ,
    4688                       '5005'||budgetno  facctid,
    4689                       '1' fclsid ,
    4690                       z.purpose fexp,0 fdebit,  z.zf_item_amt fcredit,'1' fbanksettel ,z.prjno ftransid,'RMB' fcyid,z.unitno fobjid,z.zf_itemno zf_itemno,z.zf_itemname zf_itemname
    4691                        FROM (
    4692                                 SELECT Z.voucher_type,
    4693                                         z.refundment_memo purpose,
    4694                                        z.amt  zf_item_amt,
    4695                                        z.prjno  prjno,
    4696                                        z.unitno,
    4697                                        Z.SRC_ID,
    4698                                        Z.budget_type,
    4699                                        Z.budgetno,
    4700                                        '' zf_itemno,
    4701                                        '' zf_itemname,
    4702                                        (select bz.org_type  from bs_zjly bz where bz.fundno=z.src_id ) ORG_TYPE
    4703                                       -- z.AFFIRM_DATE
    4704                                   FROM  (  select crbd.id  as id ,  '3' voucher_type , crb.reason as refundment_memo ,   crbd.pay_amt as amt , crbd.prjno as prjno  ,crb.unitno ,crb.src_id as SRC_ID ,crbd.budget_type ,crbd.budgetno  from  common_req_back crb,common_req_back_detail crbd where crb.id=crbd.common_req_back_id)   Z
    4705                                  WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    4706                                   and z.budgetno in (select distinct bg.func_bdgid from bs_gnflyskm bg where bg.func_bdgname like '%医疗%' and bg.func_bdgname not  like '%药品%')
    4707                              ) Z
    4708                             order by z.budgetno
    4709                       )
    4710                     )
    4711                     ;
    4712                   ---借方:
    4713 
    4714                     select sum(a.fcredit) into v_total from gk_zwentry a where a.fserialnum = v_fserialnum_2 ;
    4715                     insert into gk_zwentry
    4716                       (fserialnum,
    4717                        fentryid,
    4718                        facctid,
    4719                        fclsid,
    4720                        fexp,
    4721                        fdebit,
    4722                        fcredit,
    4723                        fbanksettel,
    4724                        ftransid,
    4725                        fcyid,
    4726                        fobjid,
    4727                        zf_itemno,
    4728                        zf_itemname,BUDGETID)
    4729                       SELECT v_fserialnum_2,
    4730                              1,
    4731                              '100400401' as facctid ,
    4732                              '0',
    4733                              '',
    4734                              v_total,
    4735                              0,
    4736                              '1',
    4737                              '000',
    4738                              'RMB',
    4739                              '*',
    4740                              '',
    4741                              '','100400401'||',' ||substr(fdate,0,4)|| ',*,*,*'
    4742                         from dual;
    4743 
    4744                     insert into gk_zwvch_refer(FSERIALNUM, orign_type,orign_id,voucher_type,origin_teable,fmodule)
    4745                      select v_fserialnum_2 ,
    4746                          '3' ORIGN_TYPE,
    4747                         z.id ORIGN_ID,
    4748                         z.voucher_type VOUCHER_TYPE,
    4749                         'common_req_back_detail' ORIGIN_TEABLE,
    4750                         '3' FMODULE
    4751                    from  (  select crbd.id  as id ,  '3' voucher_type , crb.reason as refundment_memo ,   crbd.pay_amt as amt , crbd.prjno as prjno  ,crb.unitno ,crb.src_id as SRC_ID ,crbd.budget_type ,crbd.budgetno  from  common_req_back crb,common_req_back_detail crbd where crb.id=crbd.common_req_back_id)  z
    4752                    WHERE Z.id IN (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id) and z.budgetno in (select distinct bg.func_bdgid from bs_gnflyskm bg where bg.func_bdgname like '%医疗%' and bg.func_bdgname not  like '%药品%' )  ;
    4753              end if;
    4754 
    4755 
    4756 
    4757          /*
    4758            -- 退款的 一般支付
    4759            借:1004.003.01其他财政存款.灵活就业资金.农行活期(需与功能分类科目相对应)
    4760            贷:5005财政专户管理资金支出[功能分类科目编码 预算单位编码]
    4761            取功能分类科目名称中的关键字:就业
    4762 
    4763            会计科目编码组成:5005+功能分类科目编码
    4764 
    4765           */
    4766            select count(1) into v_count_gkfszh  from gk_zfpz  Z   WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    4767             and z.budgetno in (select distinct bg.func_bdgid from bs_gnflyskm bg where bg.func_bdgname like '%就业%')  ;
    4768             if    v_count_gkfszh >0 then
    4769                    --插入主表
    4770                   insert into gk_zwvch
    4771                     (fserialnum,
    4772                      FPERIOD,
    4773                      fgroup,
    4774                      fdate,
    4775                      fnum,
    4776                      fpreparer,
    4777                      fattachment,
    4778                      fmodule,
    4779                      jz_database,
    4780                      org_type,
    4781                      jz_fserialnum,
    4782                      orign_type,
    4783                      make_date)
    4784                     select v_fserialnum_3,
    4785                            substr(fdate, 6, 2),
    4786                            i_fgroup,
    4787                            to_date(fdate, 'yyyy-MM-dd'),
    4788                            0,
    4789                            i_fpreparer,
    4790                            v_count_gkfszh,
    4791                            3,
    4792                            i_databasename,
    4793                            '1', --资金来源类型
    4794                            0,
    4795                            v_orign_type,
    4796                            sysdate
    4797 
    4798                       from dual;
    4799 
    4800 
    4801                  ---贷方数据插入     
    4802                   insert into gk_zwentry(fserialnum,fentryid,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,budgetid)
    4803                      select   fserialnum,ROWNUM+1,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname, budgetid from (
    4804                      select fserialnum,ROWNUM+1,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,
    4805                               budgetno || ',' ||substr(fdate,0,4)|| ',' || budget_type || ',' || voucher_type || ',' || SRC_ID  budgetid
    4806                      from (
    4807                          SELECT Z.SRC_ID,Z.voucher_type,z.budget_type,z.budgetno,substr(to_char(sysdate,'yyyy-MM-dd'),0,4) year1,  v_fserialnum_3  fserialnum ,
    4808                       '5005'||budgetno  facctid,
    4809                       '1' fclsid ,
    4810                       z.purpose fexp,0 fdebit, z.zf_item_amt fcredit,'1' fbanksettel ,z.prjno ftransid,'RMB' fcyid,z.unitno fobjid,z.zf_itemno zf_itemno,z.zf_itemname zf_itemname
    4811                        FROM (
    4812                                 SELECT Z.voucher_type,
    4813                                         z.refundment_memo purpose,
    4814                                        z.amt  zf_item_amt,
    4815                                        z.prjno  prjno,
    4816                                        z.unitno,
    4817                                        Z.SRC_ID,
    4818                                        Z.budget_type,
    4819                                        Z.budgetno,
    4820                                        '' zf_itemno,
    4821                                        '' zf_itemname,
    4822                                        (select bz.org_type  from bs_zjly bz where bz.fundno=z.src_id ) ORG_TYPE
    4823                                       -- z.AFFIRM_DATE
    4824                                   FROM   (  select crbd.id  as id ,  '3' voucher_type , crb.reason as refundment_memo ,   crbd.pay_amt as amt , crbd.prjno as prjno  ,crb.unitno ,crb.src_id as SRC_ID ,crbd.budget_type ,crbd.budgetno  from  common_req_back crb,common_req_back_detail crbd where crb.id=crbd.common_req_back_id)   Z
    4825                                  WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    4826                                   and z.budgetno in (select distinct bg.func_bdgid from bs_gnflyskm bg where bg.func_bdgname like '%就业%')
    4827                              ) Z
    4828                             order by z.budgetno
    4829                       )
    4830                     )
    4831                     ;
    4832                   ---借方:
    4833 
    4834                     select sum(a.fcredit) into v_total from gk_zwentry a where a.fserialnum = v_fserialnum_3 ;
    4835                     insert into gk_zwentry
    4836                       (fserialnum,
    4837                        fentryid,
    4838                        facctid,
    4839                        fclsid,
    4840                        fexp,
    4841                        fdebit,
    4842                        fcredit,
    4843                        fbanksettel,
    4844                        ftransid,
    4845                        fcyid,
    4846                        fobjid,
    4847                        zf_itemno,
    4848                        zf_itemname,BUDGETID)
    4849                       SELECT v_fserialnum_3,
    4850                              1,
    4851                              '100400301' as facctid ,
    4852                              '0',
    4853                              '',
    4854                              v_total,
    4855                              0,
    4856                              '1',
    4857                              '000',
    4858                              'RMB',
    4859                              '*',
    4860                              '',
    4861                              '','100400301'||',' ||substr(fdate,0,4)|| ',*,*,*'
    4862                         from dual;
    4863 
    4864                     insert into gk_zwvch_refer(FSERIALNUM, orign_type,orign_id,voucher_type,origin_teable,fmodule)
    4865                      select v_fserialnum_3 ,
    4866                          '3' ORIGN_TYPE,
    4867                         z.id ORIGN_ID,
    4868                         z.voucher_type VOUCHER_TYPE,
    4869                         'common_req_back_detail' ORIGIN_TEABLE,
    4870                         '3' FMODULE
    4871                    from  (  select crbd.id  as id ,  '3' voucher_type , crb.reason as refundment_memo ,   crbd.pay_amt as amt , crbd.prjno as prjno  ,crb.unitno ,crb.src_id as SRC_ID ,crbd.budget_type ,crbd.budgetno  from  common_req_back crb,common_req_back_detail crbd where crb.id=crbd.common_req_back_id)   z
    4872                    WHERE Z.id IN (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id) and z.budgetno in (select distinct bg.func_bdgid from bs_gnflyskm bg where bg.func_bdgname like '%就业%')  ;
    4873              end if;
    4874 
    4875 
    4876 
    4877 
    4878          /*
    4879           -- 退款的 一般支付
    4880            借:1004.002.01其他财政存款.其他社会保险基金.农行活期(需与功能分类科目相对应)
    4881            贷:5005财政专户管理资金支出[功能分类科目编码 预算单位编码]
    4882            取功能分类科目名称中的关键字:社保保险
    4883 
    4884            会计科目编码组成:5005+功能分类科目编码
    4885 
    4886           */
    4887           select count(1) into v_count_gkfszh  from gk_zfpz  Z   WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    4888             and z.budgetno in (select distinct bg.func_bdgid from bs_gnflyskm bg where bg.func_bdgname like '%保险%')  ;
    4889             if    v_count_gkfszh >0 then
    4890                    --插入主表
    4891                   insert into gk_zwvch
    4892                     (fserialnum,
    4893                      FPERIOD,
    4894                      fgroup,
    4895                      fdate,
    4896                      fnum,
    4897                      fpreparer,
    4898                      fattachment,
    4899                      fmodule,
    4900                      jz_database,
    4901                      org_type,
    4902                      jz_fserialnum,
    4903                      orign_type,
    4904                      make_date)
    4905                     select v_fserialnum_4,
    4906                            substr(fdate, 6, 2),
    4907                            i_fgroup,
    4908                            to_date(fdate, 'yyyy-MM-dd'),
    4909                            0,
    4910                            i_fpreparer,
    4911                            v_count_gkfszh,
    4912                            3,
    4913                            i_databasename,
    4914                            '1', --资金来源类型
    4915                            0,
    4916                            v_orign_type,
    4917                            sysdate
    4918 
    4919                       from dual;
    4920 
    4921 
    4922                  ---借方数据插入     
    4923                   insert into gk_zwentry(fserialnum,fentryid,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,budgetid)
    4924                      select   fserialnum,ROWNUM+1,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname, budgetid from (
    4925                      select fserialnum,ROWNUM+1,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,
    4926                               budgetno || ',' ||substr(fdate,0,4)|| ',' || budget_type || ',' || voucher_type || ',' || SRC_ID  budgetid
    4927                      from (
    4928                          SELECT Z.SRC_ID,Z.voucher_type,z.budget_type,z.budgetno,substr(to_char(sysdate,'yyyy-MM-dd'),0,4) year1,  v_fserialnum_4  fserialnum ,
    4929                       '5005'||budgetno  facctid,
    4930                       '1' fclsid ,
    4931                       z.purpose fexp,0 fdebit,z.zf_item_amt fcredit,'1' fbanksettel ,z.prjno ftransid,'RMB' fcyid,z.unitno fobjid,z.zf_itemno zf_itemno,z.zf_itemname zf_itemname
    4932                        FROM (
    4933                                 SELECT Z.voucher_type,
    4934                                         z.refundment_memo purpose,
    4935                                        z.amt  zf_item_amt,
    4936                                        z.prjno  prjno,
    4937                                        z.unitno,
    4938                                        Z.SRC_ID,
    4939                                        Z.budget_type,
    4940                                        Z.budgetno,
    4941                                        '' zf_itemno,
    4942                                        '' zf_itemname,
    4943                                        (select bz.org_type  from bs_zjly bz where bz.fundno=z.src_id ) ORG_TYPE
    4944                                       -- z.AFFIRM_DATE
    4945                                   FROM   (  select crbd.id  as id ,  '3' voucher_type , crb.reason as refundment_memo ,   crbd.pay_amt as amt , crbd.prjno as prjno  ,crb.unitno ,crb.src_id as SRC_ID ,crbd.budget_type ,crbd.budgetno  from  common_req_back crb,common_req_back_detail crbd where crb.id=crbd.common_req_back_id)  Z
    4946                                  WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    4947                                   and z.budgetno in (select distinct bg.func_bdgid from bs_gnflyskm bg where bg.func_bdgname like '%保险%')
    4948                              ) Z
    4949                             order by z.budgetno
    4950                       )
    4951                     )
    4952                     ;
    4953                   ---借方:
    4954 
    4955                     select sum(a.fcredit) into v_total from gk_zwentry a where a.fserialnum = v_fserialnum_4 ;
    4956 
    4957                     insert into gk_zwentry
    4958                       (fserialnum,
    4959                        fentryid,
    4960                        facctid,
    4961                        fclsid,
    4962                        fexp,
    4963                        fdebit,
    4964                        fcredit,
    4965                        fbanksettel,
    4966                        ftransid,
    4967                        fcyid,
    4968                        fobjid,
    4969                        zf_itemno,
    4970                        zf_itemname,BUDGETID)
    4971                       SELECT v_fserialnum_4,
    4972                              1,
    4973                              '100400201' as facctid ,
    4974                              '0',
    4975                              '',
    4976                               v_total,
    4977                              0,
    4978 
    4979                              '1',
    4980                              '000',
    4981                              'RMB',
    4982                              '*',
    4983                              '',
    4984                              '','100400201'||',' ||substr(fdate,0,4)|| ',*,*,*'
    4985                         from dual;
    4986 
    4987                     insert into gk_zwvch_refer(FSERIALNUM, orign_type,orign_id,voucher_type,origin_teable,fmodule)
    4988                      select v_fserialnum_4 ,
    4989                          '3' ORIGN_TYPE,
    4990                         z.id ORIGN_ID,
    4991                         z.voucher_type VOUCHER_TYPE,
    4992                         'common_req_back_detail' ORIGIN_TEABLE,
    4993                         '3' FMODULE
    4994                    from  (  select crbd.id  as id ,  '3' voucher_type , crb.reason as refundment_memo ,   crbd.pay_amt as amt , crbd.prjno as prjno  ,crb.unitno ,crb.src_id as SRC_ID ,crbd.budget_type ,crbd.budgetno  from  common_req_back crb,common_req_back_detail crbd where crb.id=crbd.common_req_back_id) z
    4995                    WHERE Z.id IN (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id) and z.budgetno in (select distinct bg.func_bdgid from bs_gnflyskm bg where bg.func_bdgname like '%保险%')  ;
    4996              end if;
    4997 
    4998 
    4999 
    5000          /*
    5001           -- 退款的 一般支付
    5002            借:1004.001.01其他财政存款.医院药品收支结余.农行活期(需与功能分类科目相对应)
    5003            贷:5005财政专户管理资金支出[功能分类科目编码 预算单位编码]
    5004            取功能分类科目名称中的关键字: 药品
    5005 
    5006            会计科目编码组成:5005+功能分类科目编码
    5007 
    5008           */
    5009 
    5010            select count(1) into v_count_gkfszh  from gk_zfpz  Z   WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    5011             and z.budgetno in (select distinct bg.func_bdgid from bs_gnflyskm bg where bg.func_bdgname like '%药品%')  ;
    5012             if    v_count_gkfszh >0 then
    5013                    --插入主表
    5014                   insert into gk_zwvch
    5015                     (fserialnum,
    5016                      FPERIOD,
    5017                      fgroup,
    5018                      fdate,
    5019                      fnum,
    5020                      fpreparer,
    5021                      fattachment,
    5022                      fmodule,
    5023                      jz_database,
    5024                      org_type,
    5025                      jz_fserialnum,
    5026                      orign_type,
    5027                      make_date)
    5028                     select v_fserialnum_5,
    5029                            substr(fdate, 6, 2),
    5030                            i_fgroup,
    5031                            to_date(fdate, 'yyyy-MM-dd'),
    5032                            0,
    5033                            i_fpreparer,
    5034                            v_count_gkfszh,
    5035                            3,
    5036                            i_databasename,
    5037                            '1', --资金来源类型
    5038                            0,
    5039                            v_orign_type,
    5040                            sysdate
    5041 
    5042                       from dual;
    5043 
    5044 
    5045                  ---贷方数据插入     
    5046                   insert into gk_zwentry(fserialnum,fentryid,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,budgetid)
    5047                      select   fserialnum,ROWNUM+1,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname, budgetid from (
    5048                      select fserialnum,ROWNUM+1,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,
    5049                               budgetno || ',' ||substr(fdate,0,4)|| ',' || budget_type || ',' || voucher_type || ',' || SRC_ID  budgetid
    5050                      from (
    5051                          SELECT Z.SRC_ID,Z.voucher_type,z.budget_type,z.budgetno,substr(to_char(sysdate,'yyyy-MM-dd'),0,4) year1,  v_fserialnum_5  fserialnum ,
    5052                       '5005'||budgetno  facctid,
    5053                       '1' fclsid ,
    5054                       z.purpose fexp,z.zf_item_amt fdebit,0 fcredit,'1' fbanksettel ,z.prjno ftransid,'RMB' fcyid,z.unitno fobjid,z.zf_itemno zf_itemno,z.zf_itemname zf_itemname
    5055                        FROM (
    5056                                 SELECT Z.voucher_type,
    5057                                         z.refundment_memo purpose,
    5058                                        z.amt  zf_item_amt,
    5059                                        z.prjno  prjno,
    5060                                        z.unitno,
    5061                                        Z.SRC_ID,
    5062                                        Z.budget_type,
    5063                                        Z.budgetno,
    5064                                        '' zf_itemno,
    5065                                        '' zf_itemname,
    5066                                        (select bz.org_type  from bs_zjly bz where bz.fundno=z.src_id ) ORG_TYPE
    5067                                       -- z.AFFIRM_DATE
    5068                                   FROM   (  select crbd.id  as id ,  '3' voucher_type , crb.reason as refundment_memo ,   crbd.pay_amt as amt , crbd.prjno as prjno  ,crb.unitno ,crb.src_id as SRC_ID ,crbd.budget_type ,crbd.budgetno  from  common_req_back crb,common_req_back_detail crbd where crb.id=crbd.common_req_back_id)  Z
    5069                                  WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    5070                                   and z.budgetno in (select distinct bg.func_bdgid from bs_gnflyskm bg where bg.func_bdgname like '%药品%')
    5071                              ) Z
    5072                             order by z.budgetno
    5073                       )
    5074                     )
    5075                     ;
    5076                   ---借方:
    5077 
    5078                     select sum(a.fcredit) into v_total from gk_zwentry a where a.fserialnum = v_fserialnum_5 ;
    5079                     insert into gk_zwentry
    5080                       (fserialnum,
    5081                        fentryid,
    5082                        facctid,
    5083                        fclsid,
    5084                        fexp,
    5085                        fdebit,
    5086                        fcredit,
    5087                        fbanksettel,
    5088                        ftransid,
    5089                        fcyid,
    5090                        fobjid,
    5091                        zf_itemno,
    5092                        zf_itemname,BUDGETID)
    5093                       SELECT v_fserialnum_5,
    5094                              v_max_index,
    5095                              '100400101' as facctid ,
    5096                              '0',
    5097                              '',
    5098                               v_total,
    5099                              0,
    5100 
    5101                              '1',
    5102                              '000',
    5103                              'RMB',
    5104                              '*',
    5105                              '',
    5106                              '','100400101'||',' ||substr(fdate,0,4)|| ',*,*,*'
    5107                         from dual;
    5108 
    5109                     insert into gk_zwvch_refer(FSERIALNUM, orign_type,orign_id,voucher_type,origin_teable,fmodule)
    5110                      select v_fserialnum_5 ,
    5111                          '3' ORIGN_TYPE,
    5112                         z.id ORIGN_ID,
    5113                         z.voucher_type VOUCHER_TYPE,
    5114                         'common_req_back_detail' ORIGIN_TEABLE,
    5115                         '3' FMODULE
    5116                    from  (  select crbd.id  as id ,  '3' voucher_type , crb.reason as refundment_memo ,   crbd.pay_amt as amt , crbd.prjno as prjno  ,crb.unitno ,crb.src_id as SRC_ID ,crbd.budget_type ,crbd.budgetno  from  common_req_back crb,common_req_back_detail crbd where crb.id=crbd.common_req_back_id) z
    5117                    WHERE Z.id IN (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id) and z.budgetno in (select distinct bg.func_bdgid from bs_gnflyskm bg where bg.func_bdgname like '%药品%')  ;
    5118              end if;
    5119 
    5120 
    5121          end if;
    5122 
    5123 
    5124 --================================================================================================================
    5125 --==========                                社会保障基金财政专户(失业)                                      ========
    5126 --================================================================================================================  
    5127       elsif org_name='社会保障基金财政专户(失业)'  then
    5128          if opertype='0' or  opertype='1' or   opertype='6'  then
    5129             /*
    5130                (1)失业:上划社保资金(人行)
    5131                   借:2001.001暂收款.工伤/失业/医疗统筹资金
    5132                   贷:1003.003财政专户存款.人民银行
    5133 
    5134              */
    5135           select count(1) into v_count_gkfszh  from gk_zfpz  Z   WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)   and z.src_id  in ('00S','007')    and z.purpose like '%失业%' and z.fk_account='190606000004273090'; /*社会保障基金财政专户(失业)*/
    5136             if    v_count_gkfszh >0 then
    5137                    --插入主表
    5138                   insert into gk_zwvch
    5139                     (fserialnum,
    5140                      FPERIOD,
    5141                      fgroup,
    5142                      fdate,
    5143                      fnum,
    5144                      fpreparer,
    5145                      fattachment,
    5146                      fmodule,
    5147                      jz_database,
    5148                      org_type,
    5149                      jz_fserialnum,
    5150                      orign_type,
    5151                      make_date)
    5152                     select v_fserialnum_1,
    5153                            substr(fdate, 6, 2),
    5154                            i_fgroup,
    5155                            to_date(fdate, 'yyyy-MM-dd'),
    5156                            0,
    5157                            i_fpreparer,
    5158                            v_count_gkfszh,
    5159                            3,
    5160                            i_databasename,
    5161                            '1', --资金来源类型
    5162                            0,
    5163                            v_orign_type,
    5164                            sysdate
    5165 
    5166                       from dual;
    5167 
    5168 
    5169                  ---借方数据插入     
    5170                   insert into gk_zwentry(fserialnum,fentryid,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,budgetid)
    5171                      select   fserialnum,ROWNUM,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname, budgetid from (
    5172                      select fserialnum,ROWNUM,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,
    5173                               budgetno || ',' ||substr(fdate,0,4)|| ',' || budget_type || ',' || voucher_type || ',' || SRC_ID  budgetid
    5174                      from (
    5175                          SELECT Z.SRC_ID,Z.voucher_type,z.budget_type,z.budgetno,substr(to_char(sysdate,'yyyy-MM-dd'),0,4) year1,  v_fserialnum_1  fserialnum ,
    5176                       '2001001' facctid,
    5177                       '1' fclsid ,
    5178                       z.purpose fexp,z.zf_item_amt fdebit,0 fcredit,'1' fbanksettel ,z.prjno ftransid,'RMB' fcyid,z.unitno fobjid,z.zf_itemno zf_itemno,z.zf_itemname zf_itemname
    5179                        FROM (
    5180                                 SELECT Z.voucher_type,
    5181                                         z.purpose purpose,
    5182                                        z.amt  zf_item_amt,
    5183                                        z.prjno  prjno,
    5184                                        z.unitno,
    5185                                        Z.SRC_ID,
    5186                                        Z.budget_type,
    5187                                        Z.budgetno,
    5188                                        '' zf_itemno,
    5189                                        '' zf_itemname,
    5190                                        (select bz.org_type  from bs_zjly bz where bz.fundno=z.src_id ) ORG_TYPE
    5191                                       -- z.AFFIRM_DATE
    5192                                   FROM  gk_zfpz  Z
    5193                                  WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    5194                                    and z.src_id  in ('00S','007')    and z.purpose like '%失业%' and z.fk_account='190606000004273090'
    5195                              ) Z
    5196                             order by z.budgetno
    5197                       )
    5198                     )
    5199                     ;
    5200                   ---贷方:
    5201 
    5202                     select sum(a.fdebit) into v_total from gk_zwentry a where a.fserialnum = v_fserialnum_1 ;
    5203                     select max(a.fentryid) + 1 into v_max_index from gk_zwentry a where a.fserialnum = v_fserialnum_1;
    5204                     insert into gk_zwentry
    5205                       (fserialnum,
    5206                        fentryid,
    5207                        facctid,
    5208                        fclsid,
    5209                        fexp,
    5210                        fdebit,
    5211                        fcredit,
    5212                        fbanksettel,
    5213                        ftransid,
    5214                        fcyid,
    5215                        fobjid,
    5216                        zf_itemno,
    5217                        zf_itemname,BUDGETID)
    5218                       SELECT v_fserialnum_1,
    5219                              v_max_index,
    5220                              '1003003' as facctid ,
    5221                              '0',
    5222                              '',
    5223                              0,
    5224                              v_total,
    5225                              '1',
    5226                              '000',
    5227                              'RMB',
    5228                              '*',
    5229                              '',
    5230                              '','1003003'||',' ||substr(fdate,0,4)|| ',*,*,*'
    5231                         from dual;
    5232 
    5233                     insert into gk_zwvch_refer(FSERIALNUM, orign_type,orign_id,voucher_type,origin_teable,fmodule)
    5234                      select v_fserialnum_1 ,
    5235                          '1' ORIGN_TYPE,
    5236                         z.id ORIGN_ID,
    5237                         z.voucher_type VOUCHER_TYPE,
    5238                         'GK_ZFPZ' ORIGIN_TEABLE,
    5239                         '3' FMODULE
    5240                    from gk_zfpz z
    5241                    WHERE Z.id IN (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)   and z.src_id  in ('00S','007')    and z.purpose like '%失业%' and z.fk_account='190606000004273090' ;
    5242              end if;
    5243 
    5244 
    5245 
    5246 
    5247              /*
    5248                (2)失业:上划社保资金(农行)
    5249                 借:2001.001暂收款.工伤/失业/医疗统筹资金
    5250                 贷:1003.002财政专户存款.工伤/失业/医疗市级统筹专户
    5251              社会保障基金专户(市级统筹失业)	465001040021376-0000000007	中国农业银行股份有限公司顺德清晖支行
    5252              */
    5253             select count(1) into v_count_gkfszh  from gk_zfpz  Z   WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)   and z.src_id  in ('00S','007')    and z.purpose like '%失业%' and z.fk_account='44465001040021376-0000000007'; /*社会保障基金财政专户(失业)*/
    5254             if    v_count_gkfszh >0 then
    5255                    --插入主表
    5256                   insert into gk_zwvch
    5257                     (fserialnum,
    5258                      FPERIOD,
    5259                      fgroup,
    5260                      fdate,
    5261                      fnum,
    5262                      fpreparer,
    5263                      fattachment,
    5264                      fmodule,
    5265                      jz_database,
    5266                      org_type,
    5267                      jz_fserialnum,
    5268                      orign_type,
    5269                      make_date)
    5270                     select v_fserialnum_2,
    5271                            substr(fdate, 6, 2),
    5272                            i_fgroup,
    5273                            to_date(fdate, 'yyyy-MM-dd'),
    5274                            0,
    5275                            i_fpreparer,
    5276                            v_count_gkfszh,
    5277                            3,
    5278                            i_databasename,
    5279                            '1', --资金来源类型
    5280                            0,
    5281                            v_orign_type,
    5282                            sysdate
    5283 
    5284                       from dual;
    5285 
    5286 
    5287                  ---借方数据插入     
    5288                   insert into gk_zwentry(fserialnum,fentryid,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,budgetid)
    5289                      select   fserialnum,ROWNUM,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname, budgetid from (
    5290                      select fserialnum,ROWNUM,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,
    5291                               budgetno || ',' ||substr(fdate,0,4)|| ',' || budget_type || ',' || voucher_type || ',' || SRC_ID  budgetid
    5292                      from (
    5293                          SELECT Z.SRC_ID,Z.voucher_type,z.budget_type,z.budgetno,substr(to_char(sysdate,'yyyy-MM-dd'),0,4) year1,  v_fserialnum_2  fserialnum ,
    5294                       '2001001' facctid,
    5295                       '1' fclsid ,
    5296                       z.purpose fexp,z.zf_item_amt fdebit,0 fcredit,'1' fbanksettel ,z.prjno ftransid,'RMB' fcyid,z.unitno fobjid,z.zf_itemno zf_itemno,z.zf_itemname zf_itemname
    5297                        FROM (
    5298                                 SELECT Z.voucher_type,
    5299                                         z.purpose purpose,
    5300                                        z.amt  zf_item_amt,
    5301                                        z.prjno  prjno,
    5302                                        z.unitno,
    5303                                        Z.SRC_ID,
    5304                                        Z.budget_type,
    5305                                        Z.budgetno,
    5306                                        '' zf_itemno,
    5307                                        '' zf_itemname,
    5308                                        (select bz.org_type  from bs_zjly bz where bz.fundno=z.src_id ) ORG_TYPE
    5309                                       -- z.AFFIRM_DATE
    5310                                   FROM  gk_zfpz  Z
    5311                                  WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    5312                                     and z.src_id  in ('00S','007')    and z.purpose like '%失业%' and z.fk_account='44465001040021376-0000000007'
    5313                              ) Z
    5314                             order by z.budgetno
    5315                       )
    5316                     )
    5317                     ;
    5318                   ---贷方:
    5319 
    5320                     select sum(a.fdebit) into v_total from gk_zwentry a where a.fserialnum = v_fserialnum_2 ;
    5321                     select max(a.fentryid) + 1 into v_max_index from gk_zwentry a where a.fserialnum = v_fserialnum_2;
    5322                     insert into gk_zwentry
    5323                       (fserialnum,
    5324                        fentryid,
    5325                        facctid,
    5326                        fclsid,
    5327                        fexp,
    5328                        fdebit,
    5329                        fcredit,
    5330                        fbanksettel,
    5331                        ftransid,
    5332                        fcyid,
    5333                        fobjid,
    5334                        zf_itemno,
    5335                        zf_itemname,BUDGETID)
    5336                       SELECT v_fserialnum_2,
    5337                              v_max_index,
    5338                              '1003002' as facctid ,
    5339                              '0',
    5340                              '',
    5341                              0,
    5342                              v_total,
    5343                              '1',
    5344                              '000',
    5345                              'RMB',
    5346                              '*',
    5347                              '',
    5348                              '','1003002'||',' ||substr(fdate,0,4)|| ',*,*,*'
    5349                         from dual;
    5350 
    5351                     insert into gk_zwvch_refer(FSERIALNUM, orign_type,orign_id,voucher_type,origin_teable,fmodule)
    5352                      select v_fserialnum_2 ,
    5353                          '1' ORIGN_TYPE,
    5354                         z.id ORIGN_ID,
    5355                         z.voucher_type VOUCHER_TYPE,
    5356                         'GK_ZFPZ' ORIGIN_TEABLE,
    5357                         '3' FMODULE
    5358                    from gk_zfpz z
    5359                    WHERE Z.id IN (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)   and z.src_id  in ('00S','007')    and z.purpose like '%失业%' and z.fk_account='44465001040021376-0000000007' ;
    5360              end if;
    5361 
    5362 
    5363          end if;
    5364 
    5365 
    5366 
    5367 --================================================================================================================
    5368 --==========                                社会保障基金财政专户(养老)                                      ========
    5369 --================================================================================================================  
    5370       elsif org_name='社会保障基金财政专户(养老)'  then
    5371          if opertype='0' or  opertype='1' or   opertype='6' then
    5372            /*
    5373              (1)养老/生育:上划社保资金(人行)  一般支付支出
    5374                   借:2001.001暂收款.养老统筹资金
    5375                   贷:1003.002 财政专户存款.人民银行
    5376 
    5377                   gk_zfpz 表付款帐号为: 	人行社保专户	190606000004273090	中国人民银行顺德支行
    5378 
    5379            */
    5380 
    5381             select count(1) into v_count_gkfszh  from gk_zfpz  Z   WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)   and z.src_id  in ('00S','007')    and( z.purpose like '%养老%' and z.purpose not like '%利息%' ) and z.fk_account in ('190606000004273090' ); /*社会保障基金财政专户(养老)*/
    5382             if    v_count_gkfszh >0 then
    5383                    --插入主表
    5384                   insert into gk_zwvch
    5385                     (fserialnum,
    5386                      FPERIOD,
    5387                      fgroup,
    5388                      fdate,
    5389                      fnum,
    5390                      fpreparer,
    5391                      fattachment,
    5392                      fmodule,
    5393                      jz_database,
    5394                      org_type,
    5395                      jz_fserialnum,
    5396                      orign_type,
    5397                      make_date)
    5398                     select v_fserialnum_1,
    5399                            substr(fdate, 6, 2),
    5400                            i_fgroup,
    5401                            to_date(fdate, 'yyyy-MM-dd'),
    5402                            0,
    5403                            i_fpreparer,
    5404                            v_count_gkfszh,
    5405                            3,
    5406                            i_databasename,
    5407                            '1', --资金来源类型
    5408                            0,
    5409                            v_orign_type,
    5410                            sysdate
    5411 
    5412                       from dual;
    5413 
    5414 
    5415                  ---借方数据插入     
    5416                   insert into gk_zwentry(fserialnum,fentryid,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,budgetid)
    5417                      select   fserialnum,ROWNUM,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname, budgetid from (
    5418                      select fserialnum,ROWNUM,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,
    5419                               budgetno || ',' ||substr(fdate,0,4)|| ',' || budget_type || ',' || voucher_type || ',' || SRC_ID  budgetid
    5420                      from (
    5421                          SELECT Z.SRC_ID,Z.voucher_type,z.budget_type,z.budgetno,substr(to_char(sysdate,'yyyy-MM-dd'),0,4) year1,  v_fserialnum_1  fserialnum ,
    5422                       '2001001' facctid,
    5423                       '1' fclsid ,
    5424                       z.purpose fexp,z.zf_item_amt fdebit,0 fcredit,'1' fbanksettel ,z.prjno ftransid,'RMB' fcyid,z.unitno fobjid,z.zf_itemno zf_itemno,z.zf_itemname zf_itemname
    5425                        FROM (
    5426                                 SELECT Z.voucher_type,
    5427                                         z.purpose purpose,
    5428                                        z.amt  zf_item_amt,
    5429                                        z.prjno  prjno,
    5430                                        z.unitno,
    5431                                        Z.SRC_ID,
    5432                                        Z.budget_type,
    5433                                        Z.budgetno,
    5434                                        '' zf_itemno,
    5435                                        '' zf_itemname,
    5436                                        (select bz.org_type  from bs_zjly bz where bz.fundno=z.src_id ) ORG_TYPE
    5437                                       -- z.AFFIRM_DATE
    5438                                   FROM  gk_zfpz  Z
    5439                                  WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    5440                                       and z.src_id  in ('00S','007')
    5441                                       and( z.purpose like '%养老%' and z.purpose not like '%利息%' )
    5442                                       and z.fk_account in ('190606000004273090' )
    5443                              ) Z
    5444                             order by z.budgetno
    5445                       )
    5446                     )
    5447                     ;
    5448                   ---贷方:
    5449 
    5450                     select sum(a.fdebit) into v_total from gk_zwentry a where a.fserialnum = v_fserialnum_1 ;
    5451                     select max(a.fentryid) + 1 into v_max_index from gk_zwentry a where a.fserialnum = v_fserialnum_1;
    5452                     insert into gk_zwentry
    5453                       (fserialnum,
    5454                        fentryid,
    5455                        facctid,
    5456                        fclsid,
    5457                        fexp,
    5458                        fdebit,
    5459                        fcredit,
    5460                        fbanksettel,
    5461                        ftransid,
    5462                        fcyid,
    5463                        fobjid,
    5464                        zf_itemno,
    5465                        zf_itemname,BUDGETID)
    5466                       SELECT v_fserialnum_1,
    5467                              v_max_index,
    5468                              '1003002' as facctid ,
    5469                              '0',
    5470                              '',
    5471                              0,
    5472                              v_total,
    5473                              '1',
    5474                              '000',
    5475                              'RMB',
    5476                              '*',
    5477                              '',
    5478                              '','1003002'||',' ||substr(fdate,0,4)|| ',*,*,*'
    5479                         from dual;
    5480 
    5481                     insert into gk_zwvch_refer(FSERIALNUM, orign_type,orign_id,voucher_type,origin_teable,fmodule)
    5482                      select v_fserialnum_1 ,
    5483                          '1' ORIGN_TYPE,
    5484                         z.id ORIGN_ID,
    5485                         z.voucher_type VOUCHER_TYPE,
    5486                         'GK_ZFPZ' ORIGIN_TEABLE,
    5487                         '3' FMODULE
    5488                    from gk_zfpz z
    5489                    WHERE Z.id IN (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    5490                           and z.src_id  in ('00S','007')
    5491                           and( z.purpose like '%养老%' and z.purpose not like '%利息%' )
    5492                           and z.fk_account in ('190606000004273090' );
    5493              end if;
    5494 
    5495 
    5496 
    5497 
    5498 
    5499           /*
    5500              (2)养老/生育:上划社保资金(农行)   一般支付支出
    5501                   借:2001001暂收款.养老统筹资金
    5502                   贷:1003.001财政专户存款.养老市级统筹专户   44465001040021376-0000000005
    5503 
    5504                  gk_zfpz 表付款帐号为: 社会保障基金专户(市级统筹养老)	465001040021376-0000000005	中国农业银行股份有限公司顺德清晖支行
    5505            */
    5506 
    5507             select count(1) into v_count_gkfszh  from gk_zfpz  Z   WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)   and z.src_id  in ('00S','007')    and (z.purpose like '%养老%'    and z.purpose not like '%利息%') and z.fk_account='44465001040021376-0000000005'; /*社会保障基金财政专户(养老)*/
    5508             if    v_count_gkfszh >0 then
    5509                    --插入主表
    5510                   insert into gk_zwvch
    5511                     (fserialnum,
    5512                      FPERIOD,
    5513                      fgroup,
    5514                      fdate,
    5515                      fnum,
    5516                      fpreparer,
    5517                      fattachment,
    5518                      fmodule,
    5519                      jz_database,
    5520                      org_type,
    5521                      jz_fserialnum,
    5522                      orign_type,
    5523                      make_date)
    5524                     select v_fserialnum_2,
    5525                            substr(fdate, 6, 2),
    5526                            i_fgroup,
    5527                            to_date(fdate, 'yyyy-MM-dd'),
    5528                            0,
    5529                            i_fpreparer,
    5530                            v_count_gkfszh,
    5531                            3,
    5532                            i_databasename,
    5533                            '1', --资金来源类型
    5534                            0,
    5535                            v_orign_type,
    5536                            sysdate
    5537 
    5538                       from dual;
    5539 
    5540 
    5541                  ---借方数据插入     
    5542                   insert into gk_zwentry(fserialnum,fentryid,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,budgetid)
    5543                      select   fserialnum,ROWNUM,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname, budgetid from (
    5544                      select fserialnum,ROWNUM,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,
    5545                               budgetno || ',' ||substr(fdate,0,4)|| ',' || budget_type || ',' || voucher_type || ',' || SRC_ID  budgetid
    5546                      from (
    5547                          SELECT Z.SRC_ID,Z.voucher_type,z.budget_type,z.budgetno,substr(to_char(sysdate,'yyyy-MM-dd'),0,4) year1,  v_fserialnum_2  fserialnum ,
    5548                       '2001001' facctid,
    5549                       '1' fclsid ,
    5550                       z.purpose fexp,z.zf_item_amt fdebit,0 fcredit,'1' fbanksettel ,z.prjno ftransid,'RMB' fcyid,z.unitno fobjid,z.zf_itemno zf_itemno,z.zf_itemname zf_itemname
    5551                        FROM (
    5552                                 SELECT Z.voucher_type,
    5553                                         z.purpose purpose,
    5554                                        z.amt  zf_item_amt,
    5555                                        z.prjno  prjno,
    5556                                        z.unitno,
    5557                                        Z.SRC_ID,
    5558                                        Z.budget_type,
    5559                                        Z.budgetno,
    5560                                        '' zf_itemno,
    5561                                        '' zf_itemname,
    5562                                        (select bz.org_type  from bs_zjly bz where bz.fundno=z.src_id ) ORG_TYPE
    5563                                       -- z.AFFIRM_DATE
    5564                                   FROM  gk_zfpz  Z
    5565                                  WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    5566                                      and z.src_id  in ('00S','007')
    5567                                      and (z.purpose like '%养老%'    and z.purpose not like '%利息%')
    5568                                      and z.fk_account='44465001040021376-0000000005'
    5569                              ) Z
    5570                             order by z.budgetno
    5571                       )
    5572                     )
    5573                     ;
    5574                   ---贷方:
    5575 
    5576                     select sum(a.fdebit) into v_total from gk_zwentry a where a.fserialnum = v_fserialnum_2 ;
    5577                     select max(a.fentryid) + 1 into v_max_index from gk_zwentry a where a.fserialnum = v_fserialnum_2;
    5578                     insert into gk_zwentry
    5579                       (fserialnum,
    5580                        fentryid,
    5581                        facctid,
    5582                        fclsid,
    5583                        fexp,
    5584                        fdebit,
    5585                        fcredit,
    5586                        fbanksettel,
    5587                        ftransid,
    5588                        fcyid,
    5589                        fobjid,
    5590                        zf_itemno,
    5591                        zf_itemname,BUDGETID)
    5592                       SELECT v_fserialnum_2,
    5593                              v_max_index,
    5594                              '1003001' as facctid ,
    5595                              '0',
    5596                              '',
    5597                              0,
    5598                              v_total,
    5599                              '1',
    5600                              '000',
    5601                              'RMB',
    5602                              '*',
    5603                              '',
    5604                              '','1003001'||',' ||substr(fdate,0,4)|| ',*,*,*'
    5605                         from dual;
    5606 
    5607                     insert into gk_zwvch_refer(FSERIALNUM, orign_type,orign_id,voucher_type,origin_teable,fmodule)
    5608                      select v_fserialnum_2 ,
    5609                          '1' ORIGN_TYPE,
    5610                         z.id ORIGN_ID,
    5611                         z.voucher_type VOUCHER_TYPE,
    5612                         'GK_ZFPZ' ORIGIN_TEABLE,
    5613                         '3' FMODULE
    5614                    from gk_zfpz z
    5615                    WHERE Z.id IN (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    5616                          and z.src_id  in ('00S','007')
    5617                          and (z.purpose like '%养老%'    and z.purpose not like '%利息%')
    5618                          and z.fk_account='44465001040021376-0000000005' ;
    5619              end if;
    5620 
    5621 
    5622 
    5623 
    5624            /*
    5625              (3)上划利息收入(只针对养老户)   一般支付支出
    5626                   借:2001.001暂收款.养老统筹资金
    5627                   贷:1003.002财政专户存款.人民银行
    5628 
    5629                  gk_zfpz 表付款帐号为: 	人行社保专户	190606000004273090	中国人民银行顺德支行
    5630            */
    5631              select count(1) into v_count_gkfszh  from gk_zfpz  Z   WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)   and z.src_id  in ('00S','007')    and  z.purpose like '%利息%'  ; /*社会保障基金财政专户(养老)*/
    5632             if    v_count_gkfszh >0 then
    5633                    --插入主表
    5634                   insert into gk_zwvch
    5635                     (fserialnum,
    5636                      FPERIOD,
    5637                      fgroup,
    5638                      fdate,
    5639                      fnum,
    5640                      fpreparer,
    5641                      fattachment,
    5642                      fmodule,
    5643                      jz_database,
    5644                      org_type,
    5645                      jz_fserialnum,
    5646                      orign_type,
    5647                      make_date)
    5648                     select v_fserialnum_3,
    5649                            substr(fdate, 6, 2),
    5650                            i_fgroup,
    5651                            to_date(fdate, 'yyyy-MM-dd'),
    5652                            0,
    5653                            i_fpreparer,
    5654                            v_count_gkfszh,
    5655                            3,
    5656                            i_databasename,
    5657                            '1', --资金来源类型
    5658                            0,
    5659                            v_orign_type,
    5660                            sysdate
    5661 
    5662                       from dual;
    5663 
    5664 
    5665                  ---借方数据插入     
    5666                   insert into gk_zwentry(fserialnum,fentryid,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,budgetid)
    5667                      select   fserialnum,ROWNUM,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname, budgetid from (
    5668                      select fserialnum,ROWNUM,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,
    5669                               budgetno || ',' ||substr(fdate,0,4)|| ',' || budget_type || ',' || voucher_type || ',' || SRC_ID  budgetid
    5670                      from (
    5671                          SELECT Z.SRC_ID,Z.voucher_type,z.budget_type,z.budgetno,substr(to_char(sysdate,'yyyy-MM-dd'),0,4) year1,  v_fserialnum_3  fserialnum ,
    5672                       '2001001' facctid,
    5673                       '1' fclsid ,
    5674                       z.purpose fexp,z.zf_item_amt fdebit,0 fcredit,'1' fbanksettel ,z.prjno ftransid,'RMB' fcyid,z.unitno fobjid,z.zf_itemno zf_itemno,z.zf_itemname zf_itemname
    5675                        FROM (
    5676                                 SELECT Z.voucher_type,
    5677                                         z.purpose purpose,
    5678                                        z.amt  zf_item_amt,
    5679                                        z.prjno  prjno,
    5680                                        z.unitno,
    5681                                        Z.SRC_ID,
    5682                                        Z.budget_type,
    5683                                        Z.budgetno,
    5684                                        '' zf_itemno,
    5685                                        '' zf_itemname,
    5686                                        (select bz.org_type  from bs_zjly bz where bz.fundno=z.src_id ) ORG_TYPE
    5687                                       -- z.AFFIRM_DATE
    5688                                   FROM  gk_zfpz  Z
    5689                                  WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    5690                                       and z.src_id  in ('00S','007')
    5691                                       and  z.purpose like '%利息%'
    5692                              ) Z
    5693                             order by z.budgetno
    5694                       )
    5695                     )
    5696                     ;
    5697                   ---贷方:
    5698 
    5699                     select sum(a.fdebit) into v_total from gk_zwentry a where a.fserialnum = v_fserialnum_3 ;
    5700                     select max(a.fentryid) + 1 into v_max_index from gk_zwentry a where a.fserialnum = v_fserialnum_3;
    5701                     insert into gk_zwentry
    5702                       (fserialnum,
    5703                        fentryid,
    5704                        facctid,
    5705                        fclsid,
    5706                        fexp,
    5707                        fdebit,
    5708                        fcredit,
    5709                        fbanksettel,
    5710                        ftransid,
    5711                        fcyid,
    5712                        fobjid,
    5713                        zf_itemno,
    5714                        zf_itemname,BUDGETID)
    5715                       SELECT v_fserialnum_3,
    5716                              v_max_index,
    5717                              '1003002' as facctid ,
    5718                              '0',
    5719                              '',
    5720                              0,
    5721                              v_total,
    5722                              '1',
    5723                              '000',
    5724                              'RMB',
    5725                              '*',
    5726                              '',
    5727                              '','1003002'||',' ||substr(fdate,0,4)|| ',*,*,*'
    5728                         from dual;
    5729 
    5730                     insert into gk_zwvch_refer(FSERIALNUM, orign_type,orign_id,voucher_type,origin_teable,fmodule)
    5731                      select v_fserialnum_3 ,
    5732                          '1' ORIGN_TYPE,
    5733                         z.id ORIGN_ID,
    5734                         z.voucher_type VOUCHER_TYPE,
    5735                         'GK_ZFPZ' ORIGIN_TEABLE,
    5736                         '3' FMODULE
    5737                    from gk_zfpz z
    5738                    WHERE Z.id IN (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    5739                          and z.src_id  in ('00S','007')
    5740                          and  z.purpose like '%利息%';
    5741              end if;
    5742 
    5743          end if;
    5744 --================================================================================================================
    5745 --==========                                社会保障基金财政专户(生育)                                      ========
    5746 --================================================================================================================  
    5747       elsif org_name='社会保障基金财政专户(生育)'  then
    5748           if opertype='0' or  opertype='1' or   opertype='6' then
    5749            /*
    5750              (1)养老/生育:上划社保资金(人行)  一般支付支出
    5751                   借:2001.001暂收款.养老统筹资金
    5752                   贷:1003.002财政专户存款.人民银行
    5753 
    5754                 gk_zfpz 表付款帐号为: 	人行社保专户	190606000004273090	中国人民银行顺德支行
    5755            */
    5756             select count(1) into v_count_gkfszh  from gk_zfpz  Z   WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)   and z.src_id  in ('00S','007')    and z.purpose like '%生育%' and z.fk_account  in ('190606000004273090' ); /*社会保障基金财政专户(生育)*/
    5757             if    v_count_gkfszh >0 then
    5758                    --插入主表
    5759                   insert into gk_zwvch
    5760                     (fserialnum,
    5761                      FPERIOD,
    5762                      fgroup,
    5763                      fdate,
    5764                      fnum,
    5765                      fpreparer,
    5766                      fattachment,
    5767                      fmodule,
    5768                      jz_database,
    5769                      org_type,
    5770                      jz_fserialnum,
    5771                      orign_type,
    5772                      make_date)
    5773                     select v_fserialnum_1,
    5774                            substr(fdate, 6, 2),
    5775                            i_fgroup,
    5776                            to_date(fdate, 'yyyy-MM-dd'),
    5777                            0,
    5778                            i_fpreparer,
    5779                            v_count_gkfszh,
    5780                            3,
    5781                            i_databasename,
    5782                            '1', --资金来源类型
    5783                            0,
    5784                            v_orign_type,
    5785                            sysdate
    5786 
    5787                       from dual;
    5788 
    5789 
    5790                  ---借方数据插入     
    5791                   insert into gk_zwentry(fserialnum,fentryid,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,budgetid)
    5792                      select   fserialnum,ROWNUM,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname, budgetid from (
    5793                      select fserialnum,ROWNUM,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,
    5794                               budgetno || ',' ||substr(fdate,0,4)|| ',' || budget_type || ',' || voucher_type || ',' || SRC_ID  budgetid
    5795                      from (
    5796                          SELECT Z.SRC_ID,Z.voucher_type,z.budget_type,z.budgetno,substr(to_char(sysdate,'yyyy-MM-dd'),0,4) year1,  v_fserialnum_1  fserialnum ,
    5797                       '2001001' facctid,
    5798                       '1' fclsid ,
    5799                       z.purpose fexp,z.zf_item_amt fdebit,0 fcredit,'1' fbanksettel ,z.prjno ftransid,'RMB' fcyid,z.unitno fobjid,z.zf_itemno zf_itemno,z.zf_itemname zf_itemname
    5800                        FROM (
    5801                                 SELECT Z.voucher_type,
    5802                                         z.purpose purpose,
    5803                                        z.amt  zf_item_amt,
    5804                                        z.prjno  prjno,
    5805                                        z.unitno,
    5806                                        Z.SRC_ID,
    5807                                        Z.budget_type,
    5808                                        Z.budgetno,
    5809                                        '' zf_itemno,
    5810                                        '' zf_itemname,
    5811                                        (select bz.org_type  from bs_zjly bz where bz.fundno=z.src_id ) ORG_TYPE
    5812                                       -- z.AFFIRM_DATE
    5813                                   FROM  gk_zfpz  Z
    5814                                  WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    5815                                      and z.src_id  in ('00S','007')    and z.purpose like '%生育%' and z.fk_account  in ('190606000004273090' )
    5816                              ) Z
    5817                             order by z.budgetno
    5818                       )
    5819                     )
    5820                     ;
    5821                   ---贷方:
    5822 
    5823                     select sum(a.fdebit) into v_total from gk_zwentry a where a.fserialnum = v_fserialnum_1 ;
    5824                     select max(a.fentryid) + 1 into v_max_index from gk_zwentry a where a.fserialnum = v_fserialnum_1;
    5825                     insert into gk_zwentry
    5826                       (fserialnum,
    5827                        fentryid,
    5828                        facctid,
    5829                        fclsid,
    5830                        fexp,
    5831                        fdebit,
    5832                        fcredit,
    5833                        fbanksettel,
    5834                        ftransid,
    5835                        fcyid,
    5836                        fobjid,
    5837                        zf_itemno,
    5838                        zf_itemname,BUDGETID)
    5839                       SELECT v_fserialnum_1,
    5840                              v_max_index,
    5841                              '1003002' as facctid ,
    5842                              '0',
    5843                              '',
    5844                              0,
    5845                              v_total,
    5846                              '1',
    5847                              '000',
    5848                              'RMB',
    5849                              '*',
    5850                              '',
    5851                              '','1003002'||',' ||substr(fdate,0,4)|| ',*,*,*'
    5852                         from dual;
    5853 
    5854                     insert into gk_zwvch_refer(FSERIALNUM, orign_type,orign_id,voucher_type,origin_teable,fmodule)
    5855                      select v_fserialnum_1 ,
    5856                          '1' ORIGN_TYPE,
    5857                         z.id ORIGN_ID,
    5858                         z.voucher_type VOUCHER_TYPE,
    5859                         'GK_ZFPZ' ORIGIN_TEABLE,
    5860                         '3' FMODULE
    5861                    from gk_zfpz z
    5862                    WHERE Z.id IN (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)  and z.src_id  in ('00S','007')    and z.purpose like '%生育%' and z.fk_account  in ('190606000004273090' ) ;
    5863              end if;
    5864 
    5865 
    5866 
    5867 
    5868 
    5869 
    5870           /*
    5871              (2)养老/生育:上划社保资金(农行)   一般支付支出
    5872                   借:2001.001暂收款.养老统筹资金
    5873                   贷:1003.001财政专户存款.养老市级统筹专户
    5874                                                                    44465001040021376-0000000009
    5875               gk_zfpz 表付款帐号为: 	社会保障基金专户(市级统筹生育)	465001040021376-0000000009	中国农业银行股份有限公司顺德清晖支行
    5876 
    5877            */
    5878 
    5879            select count(1) into v_count_gkfszh  from gk_zfpz  Z   WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)   and z.src_id  in ('00S','007')    and z.purpose like '%生育%' and z.fk_account='44465001040021376-0000000009'; /*社会保障基金财政专户(生育)*/
    5880             if    v_count_gkfszh >0 then
    5881                    --插入主表
    5882                   insert into gk_zwvch
    5883                     (fserialnum,
    5884                      FPERIOD,
    5885                      fgroup,
    5886                      fdate,
    5887                      fnum,
    5888                      fpreparer,
    5889                      fattachment,
    5890                      fmodule,
    5891                      jz_database,
    5892                      org_type,
    5893                      jz_fserialnum,
    5894                      orign_type,
    5895                      make_date)
    5896                     select v_fserialnum_2,
    5897                            substr(fdate, 6, 2),
    5898                            i_fgroup,
    5899                            to_date(fdate, 'yyyy-MM-dd'),
    5900                            0,
    5901                            i_fpreparer,
    5902                            v_count_gkfszh,
    5903                            3,
    5904                            i_databasename,
    5905                            '1', --资金来源类型
    5906                            0,
    5907                            v_orign_type,
    5908                            sysdate
    5909 
    5910                       from dual;
    5911 
    5912 
    5913                  ---借方数据插入     
    5914                   insert into gk_zwentry(fserialnum,fentryid,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,budgetid)
    5915                      select   fserialnum,ROWNUM,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname, budgetid from (
    5916                      select fserialnum,ROWNUM,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,
    5917                               budgetno || ',' ||substr(fdate,0,4)|| ',' || budget_type || ',' || voucher_type || ',' || SRC_ID  budgetid
    5918                      from (
    5919                          SELECT Z.SRC_ID,Z.voucher_type,z.budget_type,z.budgetno,substr(to_char(sysdate,'yyyy-MM-dd'),0,4) year1,  v_fserialnum_2  fserialnum ,
    5920                       '2001001' facctid,
    5921                       '1' fclsid ,
    5922                       z.purpose fexp,z.zf_item_amt fdebit,0 fcredit,'1' fbanksettel ,z.prjno ftransid,'RMB' fcyid,z.unitno fobjid,z.zf_itemno zf_itemno,z.zf_itemname zf_itemname
    5923                        FROM (
    5924                                 SELECT Z.voucher_type,
    5925                                         z.purpose purpose,
    5926                                        z.amt  zf_item_amt,
    5927                                        z.prjno  prjno,
    5928                                        z.unitno,
    5929                                        Z.SRC_ID,
    5930                                        Z.budget_type,
    5931                                        Z.budgetno,
    5932                                        '' zf_itemno,
    5933                                        '' zf_itemname,
    5934                                        (select bz.org_type  from bs_zjly bz where bz.fundno=z.src_id ) ORG_TYPE
    5935                                       -- z.AFFIRM_DATE
    5936                                   FROM  gk_zfpz  Z
    5937                                  WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    5938                                    and z.src_id  in ('00S','007')    and z.purpose like '%生育%' and z.fk_account='44465001040021376-0000000009'
    5939                              ) Z
    5940                             order by z.budgetno
    5941                       )
    5942                     )
    5943                     ;
    5944                   ---贷方:
    5945 
    5946                     select sum(a.fdebit) into v_total from gk_zwentry a where a.fserialnum = v_fserialnum_2 ;
    5947                     select max(a.fentryid) + 1 into v_max_index from gk_zwentry a where a.fserialnum = v_fserialnum_2;
    5948                     insert into gk_zwentry
    5949                       (fserialnum,
    5950                        fentryid,
    5951                        facctid,
    5952                        fclsid,
    5953                        fexp,
    5954                        fdebit,
    5955                        fcredit,
    5956                        fbanksettel,
    5957                        ftransid,
    5958                        fcyid,
    5959                        fobjid,
    5960                        zf_itemno,
    5961                        zf_itemname,BUDGETID)
    5962                       SELECT v_fserialnum_2,
    5963                              v_max_index,
    5964                              '1003001' as facctid ,
    5965                              '0',
    5966                              '',
    5967                              0,
    5968                              v_total,
    5969                              '1',
    5970                              '000',
    5971                              'RMB',
    5972                              '*',
    5973                              '',
    5974                              '','1003001'||',' ||substr(fdate,0,4)|| ',*,*,*'
    5975                         from dual;
    5976 
    5977                     insert into gk_zwvch_refer(FSERIALNUM, orign_type,orign_id,voucher_type,origin_teable,fmodule)
    5978                      select v_fserialnum_2 ,
    5979                          '1' ORIGN_TYPE,
    5980                         z.id ORIGN_ID,
    5981                         z.voucher_type VOUCHER_TYPE,
    5982                         'GK_ZFPZ' ORIGIN_TEABLE,
    5983                         '3' FMODULE
    5984                    from gk_zfpz z
    5985                    WHERE Z.id IN (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)   and z.src_id  in ('00S','007')    and z.purpose like '%生育%' and z.fk_account='44465001040021376-0000000009' ;
    5986              end if;
    5987 
    5988          end if;
    5989 
    5990 
    5991 --================================================================================================================
    5992 --==========                                社会保障基金财政专户(医疗)                                      ========
    5993 --================================================================================================================  
    5994       elsif org_name='社会保障基金财政专户(医疗)'  then
    5995 
    5996          if opertype='0' or  opertype='1' or   opertype='6'  then
    5997             /*
    5998                (1) 医疗:上划社保资金(人行)
    5999                   借:2001.001暂收款.工伤/失业/医疗统筹资金
    6000                   贷:1003.003财政专户存款.人民银行
    6001 
    6002              */
    6003            select count(1) into v_count_gkfszh  from gk_zfpz  Z   WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)   and z.src_id  in ('00S','007')    and z.purpose like '%医疗%' and z.fk_account='190606000004273090'; /*社会保障基金财政专户(医疗)*/
    6004             if    v_count_gkfszh >0 then
    6005                    --插入主表
    6006                   insert into gk_zwvch
    6007                     (fserialnum,
    6008                      FPERIOD,
    6009                      fgroup,
    6010                      fdate,
    6011                      fnum,
    6012                      fpreparer,
    6013                      fattachment,
    6014                      fmodule,
    6015                      jz_database,
    6016                      org_type,
    6017                      jz_fserialnum,
    6018                      orign_type,
    6019                      make_date)
    6020                     select v_fserialnum_1,
    6021                            substr(fdate, 6, 2),
    6022                            i_fgroup,
    6023                            to_date(fdate, 'yyyy-MM-dd'),
    6024                            0,
    6025                            i_fpreparer,
    6026                            v_count_gkfszh,
    6027                            3,
    6028                            i_databasename,
    6029                            '1', --资金来源类型
    6030                            0,
    6031                            v_orign_type,
    6032                            sysdate
    6033 
    6034                       from dual;
    6035 
    6036 
    6037                  ---借方数据插入     
    6038                   insert into gk_zwentry(fserialnum,fentryid,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,budgetid)
    6039                      select   fserialnum,ROWNUM,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname, budgetid from (
    6040                      select fserialnum,ROWNUM,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,
    6041                               budgetno || ',' ||substr(fdate,0,4)|| ',' || budget_type || ',' || voucher_type || ',' || SRC_ID  budgetid
    6042                      from (
    6043                          SELECT Z.SRC_ID,Z.voucher_type,z.budget_type,z.budgetno,substr(to_char(sysdate,'yyyy-MM-dd'),0,4) year1,  v_fserialnum_1  fserialnum ,
    6044                       '2001001' facctid,
    6045                       '1' fclsid ,
    6046                       z.purpose fexp,z.zf_item_amt fdebit,0 fcredit,'1' fbanksettel ,z.prjno ftransid,'RMB' fcyid,z.unitno fobjid,z.zf_itemno zf_itemno,z.zf_itemname zf_itemname
    6047                        FROM (
    6048                                 SELECT Z.voucher_type,
    6049                                         z.purpose purpose,
    6050                                        z.amt  zf_item_amt,
    6051                                        z.prjno  prjno,
    6052                                        z.unitno,
    6053                                        Z.SRC_ID,
    6054                                        Z.budget_type,
    6055                                        Z.budgetno,
    6056                                        '' zf_itemno,
    6057                                        '' zf_itemname,
    6058                                        (select bz.org_type  from bs_zjly bz where bz.fundno=z.src_id ) ORG_TYPE
    6059                                       -- z.AFFIRM_DATE
    6060                                   FROM  gk_zfpz  Z
    6061                                  WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    6062                                     and z.src_id  in ('00S','007')    and z.purpose like '%医疗%' and z.fk_account='190606000004273090'
    6063                              ) Z
    6064                             order by z.budgetno
    6065                       )
    6066                     )
    6067                     ;
    6068                   ---贷方:
    6069 
    6070                     select sum(a.fdebit) into v_total from gk_zwentry a where a.fserialnum = v_fserialnum_1 ;
    6071                     select max(a.fentryid) + 1 into v_max_index from gk_zwentry a where a.fserialnum = v_fserialnum_1;
    6072                     insert into gk_zwentry
    6073                       (fserialnum,
    6074                        fentryid,
    6075                        facctid,
    6076                        fclsid,
    6077                        fexp,
    6078                        fdebit,
    6079                        fcredit,
    6080                        fbanksettel,
    6081                        ftransid,
    6082                        fcyid,
    6083                        fobjid,
    6084                        zf_itemno,
    6085                        zf_itemname,BUDGETID)
    6086                       SELECT v_fserialnum_1,
    6087                              v_max_index,
    6088                              '1003003' as facctid ,
    6089                              '0',
    6090                              '',
    6091                              0,
    6092                              v_total,
    6093                              '1',
    6094                              '000',
    6095                              'RMB',
    6096                              '*',
    6097                              '',
    6098                              '','1003003'||',' ||substr(fdate,0,4)|| ',*,*,*'
    6099                         from dual;
    6100 
    6101                     insert into gk_zwvch_refer(FSERIALNUM, orign_type,orign_id,voucher_type,origin_teable,fmodule)
    6102                      select v_fserialnum_1 ,
    6103                          '1' ORIGN_TYPE,
    6104                         z.id ORIGN_ID,
    6105                         z.voucher_type VOUCHER_TYPE,
    6106                         'GK_ZFPZ' ORIGIN_TEABLE,
    6107                         '3' FMODULE
    6108                    from gk_zfpz z
    6109                    WHERE Z.id IN (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)  and z.src_id  in ('00S','007')    and z.purpose like '%医疗%' and z.fk_account='190606000004273090' ;
    6110              end if;
    6111 
    6112 
    6113 
    6114 
    6115 
    6116              /*
    6117                (2)工伤/失业/医疗:上划社保资金(农行)
    6118                 借:2001.001暂收款.工伤/失业/医疗统筹资金
    6119                 贷:1003.002财政专户存款.工伤/失业/医疗市级统筹专户
    6120 
    6121                 社会保障基金专户(市级统筹医疗)	465001040021376-0000000008	中国农业银行股份有限公司顺德清晖支行
    6122 
    6123              */
    6124 
    6125             select count(1) into v_count_gkfszh  from gk_zfpz  Z   WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)   and z.src_id  in ('00S','007')    and z.purpose like '%医疗%' and z.fk_account='44465001040021376-0000000008'; /*社会保障基金财政专户(医疗)*/
    6126             if    v_count_gkfszh >0 then
    6127                    --插入主表
    6128                   insert into gk_zwvch
    6129                     (fserialnum,
    6130                      FPERIOD,
    6131                      fgroup,
    6132                      fdate,
    6133                      fnum,
    6134                      fpreparer,
    6135                      fattachment,
    6136                      fmodule,
    6137                      jz_database,
    6138                      org_type,
    6139                      jz_fserialnum,
    6140                      orign_type,
    6141                      make_date)
    6142                     select v_fserialnum_2,
    6143                            substr(fdate, 6, 2),
    6144                            i_fgroup,
    6145                            to_date(fdate, 'yyyy-MM-dd'),
    6146                            0,
    6147                            i_fpreparer,
    6148                            v_count_gkfszh,
    6149                            3,
    6150                            i_databasename,
    6151                            '1', --资金来源类型
    6152                            0,
    6153                            v_orign_type,
    6154                            sysdate
    6155 
    6156                       from dual;
    6157 
    6158 
    6159                  ---借方数据插入     
    6160                   insert into gk_zwentry(fserialnum,fentryid,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,budgetid)
    6161                      select   fserialnum,ROWNUM,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname, budgetid from (
    6162                      select fserialnum,ROWNUM,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,
    6163                               budgetno || ',' ||substr(fdate,0,4)|| ',' || budget_type || ',' || voucher_type || ',' || SRC_ID  budgetid
    6164                      from (
    6165                          SELECT Z.SRC_ID,Z.voucher_type,z.budget_type,z.budgetno,substr(to_char(sysdate,'yyyy-MM-dd'),0,4) year1,  v_fserialnum_2  fserialnum ,
    6166                       '2001001' facctid,
    6167                       '1' fclsid ,
    6168                       z.purpose fexp,z.zf_item_amt fdebit,0 fcredit,'1' fbanksettel ,z.prjno ftransid,'RMB' fcyid,z.unitno fobjid,z.zf_itemno zf_itemno,z.zf_itemname zf_itemname
    6169                        FROM (
    6170                                 SELECT Z.voucher_type,
    6171                                         z.purpose purpose,
    6172                                        z.amt  zf_item_amt,
    6173                                        z.prjno  prjno,
    6174                                        z.unitno,
    6175                                        Z.SRC_ID,
    6176                                        Z.budget_type,
    6177                                        Z.budgetno,
    6178                                        '' zf_itemno,
    6179                                        '' zf_itemname,
    6180                                        (select bz.org_type  from bs_zjly bz where bz.fundno=z.src_id ) ORG_TYPE
    6181                                       -- z.AFFIRM_DATE
    6182                                   FROM  gk_zfpz  Z
    6183                                  WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    6184                                   and z.src_id  in ('00S','007')    and z.purpose like '%医疗%' and z.fk_account='44465001040021376-0000000008'
    6185                              ) Z
    6186                             order by z.budgetno
    6187                       )
    6188                     )
    6189                     ;
    6190                   ---贷方:
    6191 
    6192                     select sum(a.fdebit) into v_total from gk_zwentry a where a.fserialnum = v_fserialnum_2 ;
    6193                     select max(a.fentryid) + 1 into v_max_index from gk_zwentry a where a.fserialnum = v_fserialnum_2;
    6194                     insert into gk_zwentry
    6195                       (fserialnum,
    6196                        fentryid,
    6197                        facctid,
    6198                        fclsid,
    6199                        fexp,
    6200                        fdebit,
    6201                        fcredit,
    6202                        fbanksettel,
    6203                        ftransid,
    6204                        fcyid,
    6205                        fobjid,
    6206                        zf_itemno,
    6207                        zf_itemname,BUDGETID)
    6208                       SELECT v_fserialnum_2,
    6209                              v_max_index,
    6210                              '1003002' as facctid ,
    6211                              '0',
    6212                              '',
    6213                              0,
    6214                              v_total,
    6215                              '1',
    6216                              '000',
    6217                              'RMB',
    6218                              '*',
    6219                              '',
    6220                              '','1003002'||',' ||substr(fdate,0,4)|| ',*,*,*'
    6221                         from dual;
    6222 
    6223                     insert into gk_zwvch_refer(FSERIALNUM, orign_type,orign_id,voucher_type,origin_teable,fmodule)
    6224                      select v_fserialnum_2 ,
    6225                          '1' ORIGN_TYPE,
    6226                         z.id ORIGN_ID,
    6227                         z.voucher_type VOUCHER_TYPE,
    6228                         'GK_ZFPZ' ORIGIN_TEABLE,
    6229                         '3' FMODULE
    6230                    from gk_zfpz z
    6231                    WHERE Z.id IN (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)  and z.src_id  in ('00S','007')    and z.purpose like '%医疗%' and z.fk_account='44465001040021376-0000000008'  ;
    6232              end if;
    6233 
    6234 
    6235 
    6236 
    6237 
    6238          end if;
    6239 
    6240 
    6241 --================================================================================================================
    6242 --==========                                新型农村社会养老保险资金专户                                    ========
    6243 --================================================================================================================  
    6244       elsif org_name='新型农村社会养老保险资金专户'  then
    6245          if opertype='0' or opertype='1'  or opertype='6'  then
    6246           /*
    6247                 拨清算资金  支出
    6248                 借:5005.208.99.01[预算单位]财政专户管理资金支出.社会保障与就业.其他社会保障与就业支出.其他社会保障与就业支出
    6249                 贷:1003.001.01财政专户存款.农商行.活期存款
    6250 
    6251                 会计科目编码组成:5005+功能分类科目编码
    6252 
    6253           */
    6254 
    6255             insert into gk_zwvch
    6256                     (fserialnum,
    6257                      FPERIOD,
    6258                      fgroup,
    6259                      fdate,
    6260                      fnum,
    6261                      fpreparer,
    6262                      fattachment,
    6263                      fmodule,
    6264                      jz_database,
    6265                      org_type,
    6266                      jz_fserialnum,
    6267                      orign_type,
    6268                      make_date)
    6269                     select v_fserialnum_1,
    6270                            substr(fdate, 6, 2),
    6271                            i_fgroup,
    6272                            to_date(fdate, 'yyyy-MM-dd'),
    6273                            0,
    6274                            i_fpreparer,
    6275                            i_fattachment,
    6276                            3,
    6277                            i_databasename,
    6278                            '1', --资金来源类型
    6279                            0,
    6280                            v_orign_type,
    6281                            sysdate
    6282 
    6283                       from dual;
    6284 
    6285 
    6286                  ---借方数据插入     
    6287                   insert into gk_zwentry(fserialnum,fentryid,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,budgetid)
    6288                      select   fserialnum,ROWNUM,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname, budgetid from (
    6289                      select fserialnum,ROWNUM,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,
    6290                               budgetno || ',' ||substr(fdate,0,4)|| ',' || budget_type || ',' || voucher_type || ',' || SRC_ID  budgetid
    6291                      from (
    6292                          SELECT Z.SRC_ID,Z.voucher_type,z.budget_type,z.budgetno,substr(to_char(sysdate,'yyyy-MM-dd'),0,4) year1,  v_fserialnum_1  fserialnum ,
    6293                       '50052089901' facctid,
    6294                       '1' fclsid ,
    6295                       z.purpose fexp,z.zf_item_amt fdebit,0 fcredit,'1' fbanksettel ,z.prjno ftransid,'RMB' fcyid,z.unitno fobjid,z.zf_itemno zf_itemno,z.zf_itemname zf_itemname
    6296                        FROM (
    6297                                 SELECT Z.voucher_type,
    6298                                        '拨清算资金' purpose,
    6299                                        z.amt  zf_item_amt,
    6300                                        z.prjno  prjno,
    6301                                        z.unitno,
    6302                                        Z.SRC_ID,
    6303                                        Z.budget_type,
    6304                                        Z.budgetno,
    6305                                        '' zf_itemno,
    6306                                        '' zf_itemname,
    6307                                        (select bz.org_type  from bs_zjly bz where bz.fundno=z.src_id ) ORG_TYPE
    6308                                       -- z.AFFIRM_DATE
    6309                                   FROM  gk_zfpz  Z
    6310                                  WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    6311                              ) Z
    6312                             order by z.budgetno
    6313                       )
    6314                     )
    6315                     ;
    6316                   ---贷方:
    6317 
    6318                     select sum(a.fdebit) into v_total from gk_zwentry a where a.fserialnum = v_fserialnum_1 ;
    6319                     select max(a.fentryid) + 1 into v_max_index from gk_zwentry a where a.fserialnum = v_fserialnum_1;
    6320                     insert into gk_zwentry
    6321                       (fserialnum,
    6322                        fentryid,
    6323                        facctid,
    6324                        fclsid,
    6325                        fexp,
    6326                        fdebit,
    6327                        fcredit,
    6328                        fbanksettel,
    6329                        ftransid,
    6330                        fcyid,
    6331                        fobjid,
    6332                        zf_itemno,
    6333                        zf_itemname,BUDGETID)
    6334                       SELECT v_fserialnum_1,
    6335                              v_max_index,
    6336                              '100300101' as facctid ,
    6337                              '0',
    6338                             '拨清算资金',
    6339                              0,
    6340                              v_total,
    6341                              '1',
    6342                              '000',
    6343                              'RMB',
    6344                              '*',
    6345                              '',
    6346                              '','100300101'||',' ||substr(fdate,0,4)|| ',*,*,*'
    6347                         from dual;
    6348 
    6349                     insert into gk_zwvch_refer(FSERIALNUM, orign_type,orign_id,voucher_type,origin_teable,fmodule)
    6350                      select v_fserialnum_1 ,
    6351                          '1' ORIGN_TYPE,
    6352                         z.id ORIGN_ID,
    6353                         z.voucher_type VOUCHER_TYPE,
    6354                         'GK_ZFPZ' ORIGIN_TEABLE,
    6355                         '3' FMODULE
    6356                    from gk_zfpz z
    6357                    WHERE Z.id IN (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)   ;
    6358 
    6359 
    6360          elsif   opertype='2' or  opertype='3' then
    6361           /*
    6362                 (2)收退回清算资金   退款
    6363                 借:1003.001.01财政专户存款.农商行.活期存款
    6364                 贷:5005.208.99.01[预算单位]财政专户管理资金支出.社会保障与就业.其他社会保障与就业支出.其他社会保障与就业支出
    6365 
    6366                 会计科目编码组成:5005+功能分类科目编码
    6367 
    6368           */
    6369            insert into gk_zwvch
    6370                     (fserialnum,
    6371                      FPERIOD,
    6372                      fgroup,
    6373                      fdate,
    6374                      fnum,
    6375                      fpreparer,
    6376                      fattachment,
    6377                      fmodule,
    6378                      jz_database,
    6379                      org_type,
    6380                      jz_fserialnum,
    6381                      orign_type,
    6382                      make_date)
    6383                     select v_fserialnum_1,
    6384                            substr(fdate, 6, 2),
    6385                            i_fgroup,
    6386                            to_date(fdate, 'yyyy-MM-dd'),
    6387                            0,
    6388                            i_fpreparer,
    6389                            i_fattachment,
    6390                            3,
    6391                            i_databasename,
    6392                            '1', --资金来源类型
    6393                            0,
    6394                            v_orign_type,
    6395                            sysdate
    6396 
    6397                       from dual;
    6398 
    6399 
    6400                  ---借方数据插入     
    6401                   insert into gk_zwentry(fserialnum,fentryid,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,budgetid)
    6402                      select   fserialnum,ROWNUM+1,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname, budgetid from (
    6403                      select fserialnum,ROWNUM+1,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,
    6404                               budgetno || ',' ||substr(fdate,0,4)|| ',' || budget_type || ',' || voucher_type || ',' || SRC_ID  budgetid
    6405                      from (
    6406                          SELECT Z.SRC_ID,Z.voucher_type,z.budget_type,z.budgetno,substr(to_char(sysdate,'yyyy-MM-dd'),0,4) year1,  v_fserialnum_1  fserialnum ,
    6407                       '50052089901' facctid,
    6408                       '1' fclsid ,
    6409                       z.purpose fexp,0 fdebit,z.zf_item_amt fcredit,'1' fbanksettel ,z.prjno ftransid,'RMB' fcyid,z.unitno fobjid,z.zf_itemno zf_itemno,z.zf_itemname zf_itemname
    6410                        FROM (
    6411                                 SELECT Z.voucher_type,
    6412                                         '拨清算资金' purpose,
    6413                                        z.amt  zf_item_amt,
    6414                                        z.prjno  prjno,
    6415                                        z.unitno,
    6416                                        Z.SRC_ID,
    6417                                        Z.budget_type,
    6418                                        Z.budgetno,
    6419                                        '' zf_itemno,
    6420                                        '' zf_itemname,
    6421                                        (select bz.org_type  from bs_zjly bz where bz.fundno=z.src_id ) ORG_TYPE
    6422                                       -- z.AFFIRM_DATE
    6423                                   FROM  gk_zfpz  Z
    6424                                  WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    6425                              ) Z
    6426                             order by z.budgetno
    6427                       )
    6428                     )
    6429                     ;
    6430                   ---借方:
    6431 
    6432                     select sum(a.fcredit) into v_total from gk_zwentry a where a.fserialnum = v_fserialnum_1 ;
    6433                     insert into gk_zwentry
    6434                       (fserialnum,
    6435                        fentryid,
    6436                        facctid,
    6437                        fclsid,
    6438                        fexp,
    6439                        fdebit,
    6440                        fcredit,
    6441                        fbanksettel,
    6442                        ftransid,
    6443                        fcyid,
    6444                        fobjid,
    6445                        zf_itemno,
    6446                        zf_itemname,BUDGETID)
    6447                       SELECT v_fserialnum_1,
    6448                              1,
    6449                              '100300101' as facctid ,
    6450                              '0',
    6451                              '拨清算资金',
    6452                              v_total,
    6453                              0,
    6454 
    6455                              '1',
    6456                              '000',
    6457                              'RMB',
    6458                              '*',
    6459                              '',
    6460                              '','100300101'||',' ||substr(fdate,0,4)|| ',*,*,*'
    6461                         from dual;
    6462 
    6463                     insert into gk_zwvch_refer(FSERIALNUM, orign_type,orign_id,voucher_type,origin_teable,fmodule)
    6464                      select v_fserialnum_1 ,
    6465                          '1' ORIGN_TYPE,
    6466                         z.id ORIGN_ID,
    6467                         z.voucher_type VOUCHER_TYPE,
    6468                         'GK_ZFPZ' ORIGIN_TEABLE,
    6469                         '3' FMODULE
    6470                    from gk_zfpz z
    6471                    WHERE Z.id IN (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)   ;
    6472 
    6473 
    6474 
    6475 
    6476 
    6477 
    6478          elsif   opertype='4' or  opertype='3' then
    6479           /*
    6480                 (2)收退回清算资金   退款
    6481                 借:1003.001.01财政专户存款.农商行.活期存款
    6482                 贷:5005.208.99.01[预算单位]财政专户管理资金支出.社会保障与就业.其他社会保障与就业支出.其他社会保障与就业支出
    6483 
    6484                 会计科目编码组成:5005+功能分类科目编码
    6485 
    6486           */
    6487   insert into gk_zwvch
    6488                     (fserialnum,
    6489                      FPERIOD,
    6490                      fgroup,
    6491                      fdate,
    6492                      fnum,
    6493                      fpreparer,
    6494                      fattachment,
    6495                      fmodule,
    6496                      jz_database,
    6497                      org_type,
    6498                      jz_fserialnum,
    6499                      orign_type,
    6500                      make_date)
    6501                     select v_fserialnum_1,
    6502                            substr(fdate, 6, 2),
    6503                            i_fgroup,
    6504                            to_date(fdate, 'yyyy-MM-dd'),
    6505                            0,
    6506                            i_fpreparer,
    6507                            i_fattachment,
    6508                            3,
    6509                            i_databasename,
    6510                            '1', --资金来源类型
    6511                            0,
    6512                            v_orign_type,
    6513                            sysdate
    6514 
    6515                       from dual;
    6516 
    6517 
    6518                  ---借方数据插入     
    6519                   insert into gk_zwentry(fserialnum,fentryid,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,budgetid)
    6520                      select   fserialnum,ROWNUM+1,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname, budgetid from (
    6521                      select fserialnum,ROWNUM+1,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,
    6522                               budgetno || ',' ||substr(fdate,0,4)|| ',' || budget_type || ',' || voucher_type || ',' || SRC_ID  budgetid
    6523                      from (
    6524                          SELECT Z.SRC_ID,Z.voucher_type,z.budget_type,z.budgetno,substr(to_char(sysdate,'yyyy-MM-dd'),0,4) year1,  v_fserialnum_1  fserialnum ,
    6525                       '50052089901' facctid,
    6526                       '1' fclsid ,
    6527                       z.purpose fexp,0 fdebit,z.zf_item_amt fcredit,'1' fbanksettel ,z.prjno ftransid,'RMB' fcyid,z.unitno fobjid,z.zf_itemno zf_itemno,z.zf_itemname zf_itemname
    6528                        FROM (
    6529                                 SELECT Z.voucher_type,
    6530                                         '拨清算资金' purpose,
    6531                                        z.amt  zf_item_amt,
    6532                                        z.prjno  prjno,
    6533                                        z.unitno,
    6534                                        Z.SRC_ID,
    6535                                        Z.budget_type,
    6536                                        Z.budgetno,
    6537                                        '' zf_itemno,
    6538                                        '' zf_itemname,
    6539                                        (select bz.org_type  from bs_zjly bz where bz.fundno=z.src_id ) ORG_TYPE
    6540                                       -- z.AFFIRM_DATE
    6541                                   FROM  GK_PART_REFUNDMENT  Z
    6542                                  WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    6543                              ) Z
    6544                             order by z.budgetno
    6545                       )
    6546                     )
    6547                     ;
    6548                   ---借方:
    6549 
    6550                     select sum(a.fcredit) into v_total from gk_zwentry a where a.fserialnum = v_fserialnum_1 ;
    6551                     insert into gk_zwentry
    6552                       (fserialnum,
    6553                        fentryid,
    6554                        facctid,
    6555                        fclsid,
    6556                        fexp,
    6557                        fdebit,
    6558                        fcredit,
    6559                        fbanksettel,
    6560                        ftransid,
    6561                        fcyid,
    6562                        fobjid,
    6563                        zf_itemno,
    6564                        zf_itemname,BUDGETID)
    6565                       SELECT v_fserialnum_1,
    6566                              1,
    6567                              '100300101' as facctid ,
    6568                              '0',
    6569                              '拨清算资金',
    6570                              v_total,
    6571                              0,
    6572 
    6573                              '1',
    6574                              '000',
    6575                              'RMB',
    6576                              '*',
    6577                              '',
    6578                              '','100300101'||',' ||substr(fdate,0,4)|| ',*,*,*'
    6579                         from dual;
    6580 
    6581                     insert into gk_zwvch_refer(FSERIALNUM, orign_type,orign_id,voucher_type,origin_teable,fmodule)
    6582                      select v_fserialnum_1 ,
    6583                          '1' ORIGN_TYPE,
    6584                         z.id ORIGN_ID,
    6585                         z.voucher_type VOUCHER_TYPE,
    6586                         'GK_PART_REFUNDMENT' ORIGIN_TEABLE,
    6587                         '3' FMODULE
    6588                    from GK_PART_REFUNDMENT z
    6589                    WHERE Z.id IN (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)   ;
    6590 
    6591 
    6592 
    6593 
    6594          elsif   opertype='7' then
    6595           /*
    6596                 (2)收退回清算资金   退款
    6597                 借:1003.001.01财政专户存款.农商行.活期存款
    6598                 贷:5005.208.99.01[预算单位]财政专户管理资金支出.社会保障与就业.其他社会保障与就业支出.其他社会保障与就业支出
    6599 
    6600                 会计科目编码组成:5005+功能分类科目编码
    6601 
    6602           */
    6603 
    6604            insert into gk_zwvch
    6605                     (fserialnum,
    6606                      FPERIOD,
    6607                      fgroup,
    6608                      fdate,
    6609                      fnum,
    6610                      fpreparer,
    6611                      fattachment,
    6612                      fmodule,
    6613                      jz_database,
    6614                      org_type,
    6615                      jz_fserialnum,
    6616                      orign_type,
    6617                      make_date)
    6618                     select v_fserialnum_1,
    6619                            substr(fdate, 6, 2),
    6620                            i_fgroup,
    6621                            to_date(fdate, 'yyyy-MM-dd'),
    6622                            0,
    6623                            i_fpreparer,
    6624                            i_fattachment,
    6625                            3,
    6626                            i_databasename,
    6627                            '1', --资金来源类型
    6628                            0,
    6629                            v_orign_type,
    6630                            sysdate
    6631 
    6632                       from dual;
    6633 
    6634 
    6635                  ---借方数据插入     
    6636                   insert into gk_zwentry(fserialnum,fentryid,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,budgetid)
    6637                      select   fserialnum,ROWNUM+1,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname, budgetid from (
    6638                      select fserialnum,ROWNUM+1,facctid,fclsid,fexp,fdebit,fcredit,fbanksettel,ftransid,fcyid,fobjid,zf_itemno,zf_itemname,
    6639                               budgetno || ',' ||substr(fdate,0,4)|| ',' || budget_type || ',' || voucher_type || ',' || SRC_ID  budgetid
    6640                      from (
    6641                          SELECT Z.SRC_ID,Z.voucher_type,z.budget_type,z.budgetno,substr(to_char(sysdate,'yyyy-MM-dd'),0,4) year1,  v_fserialnum_1  fserialnum ,
    6642                       '50052089901' facctid,
    6643                       '1' fclsid ,
    6644                       z.purpose fexp,0 fdebit,z.zf_item_amt fcredit,'1' fbanksettel ,z.prjno ftransid,'RMB' fcyid,z.unitno fobjid,z.zf_itemno zf_itemno,z.zf_itemname zf_itemname
    6645                        FROM (
    6646                                 SELECT Z.voucher_type,
    6647                                         '拨清算资金' purpose,
    6648                                        z.amt  zf_item_amt,
    6649                                        z.prjno  prjno,
    6650                                        z.unitno,
    6651                                        Z.SRC_ID,
    6652                                        Z.budget_type,
    6653                                        Z.budgetno,
    6654                                        '' zf_itemno,
    6655                                        '' zf_itemname,
    6656                                        (select bz.org_type  from bs_zjly bz where bz.fundno=z.src_id ) ORG_TYPE
    6657                                       -- z.AFFIRM_DATE
    6658                                   FROM   (  select crbd.id  as id ,  '3' voucher_type , crb.reason as refundment_memo ,   crbd.pay_amt as amt , crbd.prjno as prjno  ,crb.unitno ,crb.src_id as SRC_ID ,crbd.budget_type ,crbd.budgetno  from  common_req_back crb,common_req_back_detail crbd where crb.id=crbd.common_req_back_id)   Z
    6659                                  WHERE Z.id IN  (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)
    6660                              ) Z
    6661                             order by z.budgetno
    6662                       )
    6663                     )
    6664                     ;
    6665                   ---借方:
    6666 
    6667                     select sum(a.fcredit) into v_total from gk_zwentry a where a.fserialnum = v_fserialnum_1 ;
    6668                     insert into gk_zwentry
    6669                       (fserialnum,
    6670                        fentryid,
    6671                        facctid,
    6672                        fclsid,
    6673                        fexp,
    6674                        fdebit,
    6675                        fcredit,
    6676                        fbanksettel,
    6677                        ftransid,
    6678                        fcyid,
    6679                        fobjid,
    6680                        zf_itemno,
    6681                        zf_itemname,BUDGETID)
    6682                       SELECT v_fserialnum_1,
    6683                              1,
    6684                              '100300101' as facctid ,
    6685                              '0',
    6686                              '拨清算资金',
    6687                              v_total,
    6688                              0,
    6689 
    6690                              '1',
    6691                              '000',
    6692                              'RMB',
    6693                              '*',
    6694                              '',
    6695                              '','100300101'||',' ||substr(fdate,0,4)|| ',*,*,*'
    6696                         from dual;
    6697 
    6698                     insert into gk_zwvch_refer(FSERIALNUM, orign_type,orign_id,voucher_type,origin_teable,fmodule)
    6699                      select v_fserialnum_1 ,
    6700                          '1' ORIGN_TYPE,
    6701                         z.id ORIGN_ID,
    6702                         z.voucher_type VOUCHER_TYPE,
    6703                         'common_req_back_detail' ORIGIN_TEABLE,
    6704                         '3' FMODULE
    6705                    from  (  select crbd.id  as id ,  '3' voucher_type , crb.reason as refundment_memo ,   crbd.pay_amt as amt , crbd.prjno as prjno  ,crb.unitno ,crb.src_id as SRC_ID ,crbd.budget_type ,crbd.budgetno  from  common_req_back crb,common_req_back_detail crbd where crb.id=crbd.common_req_back_id)  z
    6706                    WHERE Z.id IN (select GK_ZFPZ_ID from GK_ZWVCH_IDS a where pk_id = i_pk_id)   ;
    6707 
    6708 
    6709 
    6710          end if;
    6711 
    6712       end if;
    6713 
    6714 end if;
    6715 
    6716 exception
    6717 when others then
    6718 o_ret := 1;
    6719 
    6720 END PRO_K3_CZZH;
  • 相关阅读:
    Qt/Qml 电子书阅读器
    Qt/Qml 翻页特效
    vue如何引入本地js(不被打包编译的js)文件
    CSS3解决移动端手指点击或滑动屏幕时出现的浅蓝色背景框
    vue移动端touch插件
    vue组件间通信六种方式(完整版)
    Vue 过渡实现轮播图
    vue中遇到的坑 --- 变化检测问题(数组相关)
    Vue判断设备是移动端还是pc端
    vue项目如何监听窗口变化,达到页面自适应?
  • 原文地址:https://www.cnblogs.com/ios9/p/9037106.html
Copyright © 2011-2022 走看看