home *** CD-ROM | disk | FTP | other *** search
/ 203.33.198.31 / ftp-203.33.198.31.7z / 203.33.198.31 / psmaweb2121m0 < prev    next >
Encoding:
Text File  |  2009-04-22  |  11.4 KB  |  391 lines

  1. |******************************************************************************
  2. |* tssmaweb2120m  0  VRC B40C c4 gbc1
  3. |* Maintain contract
  4. |* kingsley
  5. |* 17-12-08 [10:56]
  6. |******************************************************************************
  7. |* Script Type: 0
  8. |******************************************************************************
  9.     table    ttssma221
  10.     table    ttssma916     
  11.     table    ttsgal059    
  12.     long            ccon.cnt,seq1
  13.     domain    tssma.ccon    temp.ccon.f,temp.ccon.t    
  14.     extern domain     tdstr3      ctcdf
  15.     long                return.val
  16.         string                gapi.error.code(151),gapi.error.code1(151),gapi.error.code2(151),gapi.error.code11(100)
  17.     string                gapi.message.code(30)
  18.     string                      test1(255)
  19.     string                test2(255)
  20.     string                 linetext1(255,1)
  21.     string                 linetext2(255,1)
  22.     string                line1(255),line2(255)
  23.     string                x.refa(6)
  24.     long                rett1,rett2
  25.     long                file.ptr1,file.ptr2,ret,instAmt
  26.     domain        tccomp            i.comp
  27.     extern domain        tssma.ccon        x.i.ccon
  28.     domain    tccpay    i.cpay
  29.     domain        tssma.desc        x.i.desc
  30.     domain        tcamnt               totInst 
  31.     domain        tcamnt            x.i.pric
  32.     extern domain        tssma.bkyr        x.i.bkyr,tmp.bkyr
  33.         extern domain        tssma.seqn        x.i.seqn,tmp.seqn
  34.         domain        tssma.cper        x.i.cper
  35.     domain        tssma.disc        x.i.disc
  36.     domain        tssma.disc        x.i.cppc
  37.     domain        tcamnt            x.i.cpam
  38.     domain        tssma.nprd        x.i.nprf
  39.     domain        tssma.prci        status
  40.     long                            x.i.slci
  41.     long                            x.i.prci
  42.     string                          x.i.prdt(10)
  43.     domain        tcinvn            x.i.invn
  44.     string                          x.i.invd(10)
  45.     domain        tcamnt            x.i.ldam
  46.     domain        tcamnt            x.i.nprc
  47.     extern     domain         tssma.ccon       x.i.ccon
  48.     extern     domain         tssma.ccon       new.ccon 
  49.     
  50.     domain         tssma.sdat       b.sdat
  51.     domain         tssma.edat       b.edat
  52.     domain         tssma.date       b.cdat
  53.     extern    domain        tssma.ccon            x.i.from.ccon
  54.     extern    domain        tssma.ccon            hold.from.ccon
  55.     extern    domain        tssma.ccon            x.i.to.ccon
  56.     extern    domain        tssma.ccon            hold.to.ccon
  57.     extern    domain        tssma.ccon            x.i.from.ccon
  58.     extern    domain        tssma.ccon            x.i.to.ccon
  59.     extern  domain    tcbool    flag.first.time
  60.     extern    String                temp.cont.date(6)
  61.     extern  String                start.year(4)
  62.     extern  String                end.year(4)
  63.     extern  String                start.month(2)
  64.     extern  String                end.month(2)
  65.     extern    String                start.date(10)
  66.     extern    String                end.date(10)
  67.     extern    String                spool.fileout(100)
  68.     extern    domain     tcdate            inv.date    
  69.     domain    tcbool    flg.stat
  70.     string     lUser(20),    mode(5)
  71.     long err1
  72.     string err2(50),err3(50),err(50),msg(100),ind(2)
  73.     
  74.     extern    long                 seq.id11,ret
  75.     extern    string                 file(150)
  76.         string                ddt1(10),ddt2(10)
  77.         String                 str(500)
  78.                     
  79.     
  80.     #include "iccboiapifunc"
  81.      #include  <bic_text>
  82.     #pragma used dll ottstpapihand
  83. function main()
  84. {
  85.     mode  = strip$(shiftl$(argv$(1)))
  86.     x.i.ccon=argv$(2)
  87.     x.i.desc=argv$(3)
  88.     x.i.seqn=lval(argv$(4))
  89.     x.i.bkyr=lval(argv$(5))
  90.     x.i.pric=val(argv$(6))
  91.     x.i.cper=lval(argv$(7))
  92.     test1=argv$(8)
  93.     x.i.slci=lval(argv$(9))
  94.     x.i.disc=val(argv$(10))
  95.     seq1 = lval(argv$(82))
  96.  
  97. |     check.tsgal059309()    
  98.     long indexval
  99.     indexval = string.scan(test1,"%s|%s",ctcdf,test2)                                                                                            
  100.     test1 = test2    
  101.     
  102.     generate.contract.installment()                      
  103.                           
  104.     string lflname_itxt(100)
  105.  
  106.     lflname_itxt ="/tmp/tssma2121m_itxt" & "." & x.i.ccon  
  107.     string command(50)
  108.     command = "rm " & lflname_itxt
  109.     shell(command,64)
  110.  
  111.  
  112.     file.ptr1 = seq.open(lflname_itxt,"w")
  113.     seq.puts(test1,file.ptr1)
  114.     seq.close(file.ptr1)
  115.  
  116.     db.retry.point()
  117.     select    tssma221.*
  118.     from    tssma221 for update
  119.     where    tssma221._index1 = {:x.i.ccon,:x.i.bkyr,:x.i.seqn}
  120.     selectdo
  121.     if not isspace(test1) then
  122.     ret = text.write("tssma221.itxt","2","tssma221.itxt","text","","","text","text",lflname_itxt)
  123.     endif
  124.         db.update(ttssma221,db.retry)
  125.         commit.transaction()
  126.     endselect
  127.     
  128.     command = "rm " & lflname_itxt
  129.     shell(command,64)
  130.     
  131.     
  132.     
  133. }
  134.  
  135.  
  136.     
  137. function update.tsgal059()
  138. {
  139.     
  140.     db.retry.point()
  141.     select    tsgal059.*
  142.     from    tsgal059    for update
  143.     where    tsgal059._index1 = {:seq1}
  144. |     and    tsgal059._compnr = 779
  145.     selectdo
  146.         tsgal059.rlog = ind
  147.         tsgal059.excp = gapi.error.code&gapi.error.code1
  148.         db.update(ttsgal059,db.retry)
  149.         commit.transaction()
  150.     endselect    
  151. }
  152.                 
  153. function generate.contract.installment()
  154. {
  155.     if mode = "1" and  x.i.pric < 0 then
  156.          f2120mgal.put.Contract( x.i.ccon ) 
  157.          return.val = f2120mgal.find()
  158.          f2120mgal.put.Invoicing_Type(ltoe(3))
  159.          f2120mgal.update(0,gapi.error.code11)
  160.          f2120mgal.save(gapi.error.code11)
  161.          f2120mgal.end()
  162.     endif     
  163.    f2121m000.put.Contract(x.i.ccon)
  164.    f2121m000.put.Year(x.i.bkyr)
  165.    f2121m000.set.view()                            
  166.    f2121m000.put.Sequence_Number(x.i.seqn)
  167.  
  168.  
  169.     if mode <> "1" then
  170.     return.val = f2121m000.find()
  171.     status = f2121m000.get.Processing_Status()
  172.     endif
  173.     if mode <> "3" then
  174.         f2121m000.put.Period(x.i.cper)
  175.         f2121m000.put.tssma221.desc(x.i.desc)
  176.         f2121m000.put.Installment_Amount(x.i.pric)
  177.          f2121m000.put.Discount(x.i.disc)
  178.     |     f2121m000.put.Perc._Forecast_Costs(x.i.cppc)
  179.     |     f2121m000.put.Amount_Forecast_Costs(x.i.cpam)
  180.     |     f2121m000.put.Number_of_Periods(x.i.nprf)
  181.         f2121m000.put.Advice_Status(ltoe(x.i.slci))
  182.                                             
  183.         if mode = "1" then
  184.             f2121m000.insert(1,gapi.error.code)
  185.         else
  186.             if status = tssma.prci.free then
  187.                 f2121m000.update(1,gapi.error.code)
  188.             else
  189.                 gapi.error.code = "Installment already Processed.Changing not allowed."
  190.             endif
  191.         endif
  192.         if not isspace(gapi.error.code) then
  193.             gapi.message.code = f2121m000.get.last.message.code()
  194.             f2121m000.end()
  195.             ind =  "N"
  196.              
  197.             update.tsgal059()
  198.         else     
  199.                 CalculateInstallment()
  200.                 instAmt = f2121m000.get.Contract_Price()
  201.             if mode = "1" then
  202.                 gapi.error.code = "Contract " & x.i.ccon & "Year " &str$(x.i.bkyr) & "Sequence " & str$(x.i.seqn)
  203.             endif
  204.             if totInst < instAmt then
  205.                 gapi.error.code = gapi.error.code & "Note! Installment Total ( " & STR$(totInst) & " ) Not Equal To Contract Price ( " & STR$(instAmt) & " )" 
  206.             endif
  207.             if totInst > instAmt then
  208.                 gapi.error.code = gapi.error.code & "Note! Installment Total ( " & STR$(totInst) & " ) Greater Than Contract Price ( " & STR$(instAmt) & " )" 
  209.             endif
  210.     
  211.             f2121m000.end()
  212. |             fl115sgal.put.Service_Contract(x.i.ccon)        
  213. |             fl115sgal.put.Year(x.i.bkyr)
  214. |             fl115sgal.put.Sequence(x.i.seqn)
  215. |             fl115sgal.put.Period(x.i.cper)    
  216. |             ctcdf ="036"    
  217. |             fl115sgal.put.Category_Code(ctcdf)    
  218. |             string err(200)
  219. |             fl115sgal.insert(1,err)
  220. |             if isspace(err) then
  221. |                 fl115sgal.save(err)
  222. |                 if not isspace(err) then
  223. |                     gapi.error.code1 = "Lines created localization error :" & err
  224. |                 else
  225. |                     fl115sgal.end()
  226. |                 endif
  227. |             else
  228. |                 gapi.error.code1 = "Lines created localization error :" & err
  229. |             endif
  230. |             if not isspace(err) then
  231. |                 gapi.message.code = fl115sgal.get.last.message.code()
  232. |                 fl115sgal.end()
  233. |             endif
  234.  
  235.             string err(200)
  236.             fl115sgal.put.Service_Contract(x.i.ccon)        
  237.             fl115sgal.put.Year(x.i.bkyr)
  238.             fl115sgal.put.Sequence(x.i.seqn)
  239.             
  240.             select    tssma916.* 
  241.             from     tssma916
  242.             where     tssma916._index1 = {:x.i.ccon,:x.i.bkyr,:x.i.seqn}
  243.             selectdo
  244.                 return.val = fl115sgal.find()    
  245.                 fl115sgal.put.Period(x.i.cper)    
  246.                 ctcdf ="036"    
  247.                 fl115sgal.put.Category_Code(ctcdf)    
  248.                 fl115sgal.put.base.dt(date.num() - 1)
  249.                 fl115sgal.update(1,err)
  250.             selectempty
  251.                 fl115sgal.put.Period(x.i.cper)    
  252.                 ctcdf ="036"    
  253.                 fl115sgal.put.Category_Code(ctcdf)    
  254.                 fl115sgal.insert(1,err)
  255.             endselect
  256.             if isspace(err) then
  257.                 fl115sgal.save(err)
  258.                 if not isspace(err) then
  259.                     gapi.error.code1 = "Lines created localization error :" & err
  260.                 else
  261.                     fl115sgal.end()
  262.                 endif
  263.             else
  264.                 gapi.error.code1 = "Lines created localization error :" & err
  265.             endif
  266.             if not isspace(err) then
  267.                 gapi.message.code = fl115sgal.get.last.message.code()
  268.                 fl115sgal.end()
  269.             endif    
  270.             
  271.             ind =  "Y"
  272.             update.tsgal059()
  273.             
  274.             if (x.i.pric < 0 )then
  275.                 if isspace(gapi.error.code1) then
  276.                     spool.fileout = "tssma2472m000."&strip$(shiftl$(tsgal059.wlog))
  277.                     file = "invoice_number"&str$(get.compnr())&strip$(shiftl$(tsgal059.wlog))&dte$()
  278.                     seq.id11 = seq.open(file,"w")                    
  279.                     
  280.                     gapi.error.code2 = ""
  281.                     inv.date = date.num()
  282. |                     spool.fileout = "tssma2472m000.system"
  283.                     f2472m000.put.Include_Printed_Invoices(ltoe(2))
  284.                     f2472m000.put.Invoice_Date(inv.date)
  285.                     f2472m000.put.Contract_from(x.i.ccon)
  286.                     f2472m000.put.Contract_to(x.i.ccon)
  287.                     f2472m000.put.Contract_Type_from("")
  288.                     f2472m000.put.Contract_Type_to("ZZZ")
  289.                     f2472m000.put.Customer_from("")
  290.                     f2472m000.put.Customer_to("ZZZZZZ")
  291.                     f2472m000.put.Finance_Company(0)
  292.                     f2472m000.put.ncmp.t(999)
  293.                     f2472m000.put.Final_Invoices(ltoe(1))
  294.                     f2472m000.put.Print_Invoice_Analysis(ltoe(2))
  295.                     f2472m000.put.Print_Installation_List(ltoe(2))
  296.                     stpapi.set.report("tssma2472m000","rtssma247201000","ASCIF",gapi.error.code2)
  297.                     stpapi.print.report("tssma2472m000",err)
  298.                     f2472m000.end()
  299.                     
  300.                     write.con.invoice()
  301.                     seq.close(seq.id11)
  302.                 endif
  303.             endif
  304.             
  305.             
  306.         endif
  307.     else
  308.         f2121m000.delete(0,gapi.error.code)
  309.         f2121m000.end()
  310.     endif
  311.  
  312.  
  313. }
  314.  
  315.  
  316. function write.con.invoice()
  317. {
  318.     
  319.     select    tssma221.ccon,tssma221.bkyr,tssma221.seqn,tssma221.invn,tssma221.invd,tssma221.ttyp,tssma221.prci,tssma221.prdt,tssma221.ldam,tssma221.nprc
  320.     from    tssma221
  321.     where    tssma221._index1 = {:x.i.ccon}
  322.     selectdo
  323.         if tssma221.invd <> 0 then
  324.             ddt1 = sprintf$("%D(%04Y%02m%02d)", tssma221.invd)
  325.         else
  326.             ddt1 = "00000000"    
  327.         endif
  328.         if tssma221.prdt <> 0 then
  329.             ddt2 = sprintf$("%D(%04Y%02m%02d)", tssma221.prdt)
  330.         else
  331.             ddt2 = "00000000"    
  332.         endif    
  333.         str = concat$("^",tssma221.ccon,tssma221.bkyr,tssma221.seqn,tssma221.invn,ddt1,tssma221.ttyp,tssma221.prci,ddt2,tssma221.ldam,tssma221.nprc)
  334.         seq.puts(str,seq.id11)
  335.     endselect    
  336. }
  337.  
  338.  function CalculateInstallment()
  339.  {
  340.     totInst = 0.0
  341.     select    SUM(tssma221.nprc):totInst,tssma221.ccon,tssma221.bkyr 
  342.     from    tssma221
  343.         where   tssma221._index1 = {:x.i.ccon, :x.i.bkyr}
  344.     group by tssma221.ccon,tssma221.bkyr
  345.     selectdo
  346.     endselect
  347.     
  348.  }
  349.  
  350. function Delete_Local_Data()            
  351. {
  352.     select    tssma916.*
  353.     from    tssma916 for update
  354.     where    tssma916._index1 = {:x.i.ccon, :x.i.bkyr,:x.i.seqn}
  355.     selectdo
  356.         db.delete(ttssma916,db.retry)
  357.         commit.transaction()
  358.     endselect
  359.  
  360. }                        
  361.        
  362. function check.tsgal059309()
  363. {
  364.     select    tsgal059.logn,tsgal059.sess,tsgal059.rlog,tsgal059.indi
  365.     from    tsgal059    
  366.     where    tsgal059._index5 = {:x.i.ccon,"tssma2120m000"}
  367.     selectdo
  368.         if (tsgal059.indi <> "Y") then
  369.             restore.tsgal059309()
  370.         else
  371.             if (tsgal059.rlog <> "Y") then 
  372.                 restore.tsgal059309()
  373.             endif    
  374.         endif    
  375.             
  376.     endselect    
  377. }
  378.                                                                             
  379. function restore.tsgal059309()
  380. {
  381.     db.retry.point()
  382.     select    tsgal059.*
  383.     from    tsgal059 for update
  384.     where    tsgal059._index1 = {:seq1}
  385.     selectdo
  386.         tsgal059.indi = "N"
  387.         db.update(ttsgal059,db.retry)
  388.         commit.transaction()
  389.     endselect
  390. }                                                                            
  391.