home *** CD-ROM | disk | FTP | other *** search
/ 203.33.198.31 / ftp-203.33.198.31.7z / 203.33.198.31 / psmaweb2120m0 < prev    next >
Encoding:
Text File  |  2009-04-22  |  13.8 KB  |  460 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    ttccom000
  11.     table   ttccom010
  12.     table   ttssma220
  13.     table    ttsgal052    |Service Package         
  14.     table    ttccom001    |Customers            
  15.     table    ttcgbb008    
  16.     table    ttsgal059    
  17.     long            ccon.cnt,seq1
  18.     domain    tssma.ccon    temp.ccon.f,temp.ccon.t    
  19.     long                return.val
  20.         string                gapi.error.code(151)
  21.     string                gapi.message.code(100),gapi.error.code1(150)
  22.     string                      test1(255)
  23.     string                test2(255)
  24.     string                 linetext1(255,1)
  25.     string                 linetext2(255,1)
  26.     string                line1(255),line2(255)
  27.     string                x.refa(6)
  28.     long                rett1,rett2
  29.     long                file.ptr1,file.ptr2,ret
  30.     domain        tccomp            i.comp
  31.     extern domain        tssma.ccon        x.i.ccon
  32.     domain    tccpay    i.cpay
  33.     domain        tssma.desc        x.i.desc
  34.     domain        tssma.sear        x.i.sear
  35.     domain        tcncmp            x.i.ncmp
  36.     domain        tcnama            x.i.tccom000.nama
  37.     domain        tccuno            x.i.cuno
  38.     domain        tssma.refa        x.i.refa
  39.     domain        tcccor            x.i.ccor
  40.     long                            x.i.ctst
  41.     string                          x.i.sdat(10)
  42.     string                          x.i.edat(10)
  43.     domain        tcamnt            x.i.spri
  44.     string                          x.i.cdat(10)
  45.     domain        tcamnt            x.i.pric
  46.     long                            x.i.citp
  47.     domain        tcccrs            x.i.ccrs
  48.     domain        tcccur            x.i.ccur
  49.     domain        tcclan            x.i.clan
  50.     domain        tssma.cpac        x.i.cpac fixed
  51.     domain        tccpay            x.i.cpay
  52.     domain        tccplt            x.i.cplt
  53.     domain        tssma.cpro        x.i.cpro
  54.     domain        tssma.ctpc        x.i.ctpc
  55.     domain        tccvat            x.i.cvat
  56.     extern     domain         tssma.ccon       x.i.ccon
  57.     extern     domain         tssma.ccon       new.ccon 
  58.     
  59.     domain         tssma.sdat       b.sdat
  60.     domain         tssma.edat       b.edat
  61.     domain         tssma.date       b.cdat
  62.     extern    domain        tssma.ccon            x.i.from.ccon
  63.     extern    domain        tssma.ccon            hold.from.ccon
  64.     extern    domain        tssma.ccon            x.i.to.ccon
  65.     extern    domain        tssma.ccon            hold.to.ccon
  66.     extern    domain        tssma.ccon            x.i.from.ccon
  67.     extern    domain        tssma.ccon            x.i.to.ccon
  68.     extern  domain    tcbool    flag.first.time
  69.     extern    String                temp.cont.date(6)
  70.     extern  String                start.year(4)
  71.     extern  String                end.year(4)
  72.     extern  String                start.month(2)
  73.     extern  String                end.month(2)
  74.     extern    String                start.date(10)
  75.     extern    String                end.date(10)
  76.     domain    tcbool    flg.stat
  77.     string     lUser(20),    mode(5)
  78.     long err1
  79.     string err2(50),err3(50),err(50)
  80.     #include "iccboiapifunc"
  81.      #include  <bic_text>
  82. function main()
  83. {
  84.     mode  = strip$(shiftl$(argv$(1)))
  85.     x.i.ccon=argv$(2)
  86.     x.i.desc=argv$(3)
  87.     x.i.sear=argv$(13)
  88.     x.i.cuno=argv$(8)
  89.     x.i.refa=argv$(16)
  90.     x.i.ccor=""
  91.     x.i.ctst=lval(argv$(6))
  92.     x.i.sdat=argv$(4)
  93.     x.i.edat=argv$(5)
  94.     x.i.pric=val(argv$(12))
  95.     x.i.citp=lval(argv$(11))
  96.     x.i.ccrs=""
  97.     x.i.ccur="INR"
  98.     x.i.clan="ENG"
  99.     x.i.cpac=argv$(10)
  100.     x.i.cpac = shiftr$(x.i.cpac)
  101.     x.i.cplt=argv$(17)
  102.     x.i.cpro=argv$(9)
  103.     x.i.ctpc=argv$(7)
  104.     x.i.cvat=""
  105.     test1=argv$(14)
  106.     test2=argv$(15)
  107.     seq1 = lval(argv$(82))
  108.     
  109.  
  110.     check.and.get.values.for.contract()                      
  111.                       
  112.     if isspace(gapi.error.code) then
  113.         string lflname_ctxt(100)
  114.         string lflname_itxt(100)
  115.         lflname_ctxt ="/tmp/tssma2120m_ctxt" & "." & x.i.ccon  
  116.         lflname_itxt ="/tmp/tssma2120m_itxt" & "." & x.i.ccon  
  117.         string command(50)    
  118.         command = "rm " & lflname_ctxt
  119.         shell(command,64)
  120.         command = "rm " & lflname_itxt
  121.         shell(command,64)
  122.         file.ptr1 = seq.open(lflname_ctxt,"w")
  123.         file.ptr2 = seq.open(lflname_itxt,"w")
  124.         seq.puts(test1,file.ptr1)
  125.         seq.puts(test2,file.ptr2)
  126.         seq.close(file.ptr1)
  127.         seq.close(file.ptr2)
  128.         db.retry.point()
  129.         select    tssma220.*
  130.         from    tssma220 for update
  131.         where    tssma220._index1 = {:x.i.ccon}
  132.         selectdo
  133.             if not isspace(test1) then
  134.                 ret = text.write("tssma220.ctxt","2","tssma220.ctxt","text","","","text","text",lflname_ctxt)
  135.             endif
  136.             if not isspace(test2) then
  137.                 ret = text.write("tssma220.itxt","2","tssma220.itxt","text","","","text","text",lflname_itxt)
  138.             endif
  139.             db.update(ttssma220,db.retry)
  140.             commit.transaction()
  141.         endselect
  142.         command = "rm " & lflname_ctxt
  143.         shell(command,64)
  144.         command = "rm " & lflname_itxt
  145.         shell(command,64)
  146.         get.fin.comp()        
  147.         String con.fin.mess(50)
  148.         con.fin.mess = str$(new.ccon)&" created for finance company "&str$(tcgbb008.fico)
  149.     endif
  150.     update.tsgal059()
  151. }
  152.  
  153.  
  154. function check.emp.code()                        |#EV GCC/4806
  155. {
  156.     extern    domain    tcemno    temp.refa
  157.     temp.refa = lval(strip$(shiftl$(x.i.refa)))
  158.     select    tccom001.*
  159.     from    tccom001
  160.     where    tccom001._index1 = {:temp.refa}
  161.     selectdo
  162.         end.date = convert.date.to.string(tccom001.edte)
  163.         start.date = convert.date.to.string(tccom001.sdte) 
  164.         String temp.start.date(6),temp.end.date(6)
  165.         temp.start.date = start.date(7;4)&start.date(4;2)
  166.         temp.end.date = end.date(7;4)&end.date(4;2)
  167.         if (temp.end.date >= temp.cont.date or tccom001.edte = 0) and temp.start.date <= temp.cont.date then
  168.             gapi.error.code = ""
  169.         else    
  170.             gapi.error.code = "Technician not employed in month of booking of contract"
  171.         endif    
  172.     selectempty
  173.         gapi.error.code = "Technician not found."
  174.     endselect
  175.     
  176. }    
  177.  
  178. function get.fin.comp()            
  179. {
  180.     long comp.log 
  181.     comp.log = get.compnr()
  182.     db.set.to.default(ttcgbb008)
  183.     select     tcgbb008.fico
  184.     from    tcgbb008
  185.     where    tcgbb008._index1 = {:comp.log, tcmlt.fin.ttyp.contr, :x.i.ctpc}
  186.     selectdo
  187.     endselect
  188. }    
  189.  
  190.  
  191. function check.and.get.values.for.contract()
  192. {
  193.     
  194.     string    curr.date(12),yy(2),mm(2)    
  195.     long    curr.dt    
  196.     long    sd,sm,sy
  197.     
  198.     err1 = 0 
  199.     err2 = ""
  200.     err3 = ""
  201.     sd = lval(x.i.sdat(7;2))    
  202.     sm = lval(x.i.sdat(5;2))
  203.     sy = lval(x.i.sdat(1;4))
  204.     flg.stat = FALSE        
  205.     ccon.cnt = 0
  206.     x.i.cuno = shiftr$(x.i.cuno)
  207.     db.set.to.default(ttccom010)
  208.     select    tccom010.cpay
  209.     from    tccom010
  210.     where    tccom010._index1 = {:x.i.cuno}
  211.     selectdo
  212.         i.cpay = tccom010.cpay
  213.     endselect
  214.     select    tssma220.ctst
  215.     from     tssma220
  216.     where    tssma220._index1={:x.i.ccon}
  217.     selectdo
  218.         if tssma220.ctst = ltoe(4) then
  219.             gapi.error.code = "This Contract is already Cancelled.So no changes can be done."
  220.         endif
  221.     endselect
  222.     
  223.     
  224.     if    mode = "1"    then
  225.         curr.dt = date.num()
  226.         curr.date = date.to.inputstr$(curr.dt,"%D002,3",8)
  227.         yy = curr.date(7;2)
  228.         mm = curr.date(3;2)
  229.         db.set.to.default(ttccom010)
  230.         select    tccom010.refa,tccom010.creg
  231.         from    tccom010
  232.         where    tccom010._index1 = {:x.i.cuno}
  233.         selectdo
  234.         endselect
  235.         
  236.         temp.ccon.f = tccom010.creg(2;2) & mm & yy & "0000" 
  237.         temp.ccon.t = tccom010.creg(2;2) & mm & yy & "9999" 
  238.         
  239.         select    count(tssma220.ccon):ccon.cnt
  240.         from    tssma220
  241.         where    tssma220._index3 inrange {:x.i.cuno,:temp.ccon.f}
  242.         and    {:x.i.cuno,:temp.ccon.t}
  243.         selectdo
  244.         endselect
  245.     endif
  246.     if strip$(shiftl$(tccom010.refa)) <> ""    then
  247.         if ccon.cnt => lval(tccom010.refa)    then
  248.             gapi.error.code = "Contract count for the customer is greater than no. of ctrcts for cust."
  249.         endif
  250.     endif        
  251.     if isspace(gapi.error.code) then            
  252.             
  253.         select    tsgal052.actv,tsgal052.idat
  254.         From    tsgal052
  255.         where    tsgal052._index1 = {:x.i.cpac}
  256.         selectdo
  257.             if tsgal052.actv = tcyesno.no then
  258.                 if (tsgal052.idat <> 0 and tsgal052.idat <= date.to.num(sy,sm,sd)) then
  259.                     if x.i.ctst = 4 then
  260.                         flg.stat = TRUE
  261.                     else
  262.                         gapi.error.code = "Service Package is Inactive"
  263.                     endif
  264.                 endif
  265.             endif        
  266.         selectempty
  267.             gapi.error.code = "Service Package Not Found"
  268.         endselect
  269.     endif    
  270.         
  271.         
  272.     if flg.stat = TRUE then
  273.      
  274.                 f2120mgal.put.Contract( x.i.ccon )
  275.                 err1=f2120mgal.find()
  276.                 if err1 then
  277.             f2120mgal.put.Contract_Status(ltoe(x.i.ctst))
  278.                         f2120mgal.update(1, err2)
  279.                         if isspace(err2) then
  280.                                 f2120mgal.save(err3)
  281.                               
  282.             endif
  283.                        
  284.         endif
  285.         f2120mgal.end()
  286.     else
  287.         if isspace(gapi.error.code) then    
  288.             insert.in.to.contract()
  289.         endif    
  290.     endif
  291.  
  292.     
  293. }
  294.  
  295. function insert.in.to.contract()
  296. {
  297.     String    create.date(10)
  298.     extern    domain    tcdate    temp.date
  299.     long    ed,em,ey
  300.     long    sd,sm,sy
  301.     
  302.     sd = lval(x.i.sdat(7;2))    
  303.     sm = lval(x.i.sdat(5;2))
  304.     sy = lval(x.i.sdat(1;4))
  305.     
  306.     ed = lval(x.i.edat(7;2))
  307.     em = lval(x.i.edat(5;2))
  308.     ey = lval(x.i.edat(1;4))    
  309.     
  310.  
  311.     
  312.     gapi.error.code="" 
  313.     if mode = "2" then                    
  314.         select    tssma220.edat,tssma220.sdat,tssma220.cpac
  315.         from    tssma220
  316.         where    tssma220._index1 = {:x.i.ccon}
  317.         selectdo
  318.             if (tssma220.sdat <> date.to.num(sy,sm,sd) or tssma220.edat <> date.to.num(ey,em,ed) or x.i.cpac <> tssma220.cpac )then
  319.                 select    tssma221.ccon,tssma221.invn
  320.                 from    tssma221
  321.                 where    tssma221._index1 = {:x.i.ccon}
  322.                 selectdo    
  323.                     if (tssma220.sdat <> date.to.num(sy,sm,sd) or tssma220.edat <> date.to.num(ey,em,ed)) then
  324.                         gapi.error.code = "The installments for this contract are already maintained.So the dates can not be changed."                                
  325.                     else
  326.                         if tssma221.invn <> 0 then
  327.                             gapi.error.code = "The invoices are generated for this contract.So the service package can not be changed."                                
  328.                         endif
  329.                     endif
  330.                 endselect
  331.             endif
  332.         endselect
  333.     endif 
  334.     if  isspace(gapi.error.code) then
  335.         f2120mgal.put.Contract( x.i.ccon ) 
  336.  
  337.         if mode <> "1" then
  338.             return.val = f2120mgal.find()
  339.         endif
  340.         if mode = "2" then                        
  341.                 temp.cont.date = "20"&x.i.ccon(5;2)&x.i.ccon(3;2)
  342.         endif    
  343.         if mode = "1" then
  344.             temp.date = date.num()
  345.             create.date = convert.date.to.string(temp.date)
  346.             temp.cont.date = create.date(7;4)&create.date(4;2)
  347.         endif                                
  348.         check.emp.code()    
  349.         if not isspace(gapi.error.code) then
  350.             
  351.             f2120mgal.end()
  352.         endif    
  353.         get.fin.comp()    
  354.         if mode <> "3" and isspace(gapi.error.code) then
  355.             f2120mgal.put.tssma220.desc(x.i.desc)
  356.             f2120mgal.put.Search_Argument(x.i.sear)
  357.             f2120mgal.put.tssma220.ncmp(tcgbb008.fico)    
  358.             f2120mgal.put.Customer(x.i.cuno)
  359.             f2120mgal.put.Technician_Code(x.i.refa)
  360.             f2120mgal.put.Postal_Address(x.i.ccor)
  361.             f2120mgal.put.Contract_Status(ltoe(x.i.ctst))
  362.             f2120mgal.put.Effective_Date(date.to.num(lval(x.i.sdat(1;4)),lval(x.i.sdat(5;2)),lval(x.i.sdat(7;2))))
  363.             f2120mgal.put.Expiry_Date(date.to.num(lval(x.i.edat(1;4)),lval(x.i.edat(5;2)),lval(x.i.edat(7;2))))
  364.             f2120mgal.put.Contract_Price(x.i.pric)
  365.             f2120mgal.put.Invoicing_Type(ltoe(x.i.citp))
  366.             f2120mgal.put.tssma220.ccrs(x.i.ccrs)                                                                
  367.             f2120mgal.put.tssma220.ccur(x.i.ccur)
  368.             f2120mgal.put.tssma220.clan(x.i.clan)
  369.             f2120mgal.put.tssma220.cpac(x.i.cpac)
  370.             f2120mgal.put.tssma220.cpay(i.cpay)
  371.             f2120mgal.put.Price_List(x.i.cplt)
  372.             f2120mgal.put.tssma220.cpro(x.i.cpro)
  373.             f2120mgal.put.tssma220.ctpc(x.i.ctpc)
  374.             f2120mgal.put.tssma220.cvat(x.i.cvat)
  375.             if mode = "1" then
  376.                 f2120mgal.insert(0,gapi.error.code)
  377.                 if not isspace(gapi.error.code) then
  378.                     gapi.message.code = f2120mgal.get.last.message.code()
  379.                     f2120mgal.end()
  380.                 endif
  381.                 f2120mgal.save(gapi.error.code1)
  382.                 new.ccon = ""
  383.                 tssma220.ncmp = 0
  384.                 new.ccon = f2120mgal.get.Contract()
  385.                 tssma220.ncmp = f2120mgal.get.tssma220.ncmp()
  386.             else
  387.                 f2120mgal.update(0,gapi.error.code)
  388.                 if not isspace(gapi.error.code) then
  389.                     gapi.message.code = f2120mgal.get.last.message.code()
  390.                     f2120mgal.end()
  391.                 endif
  392.                 f2120mgal.save(gapi.error.code1)
  393.             endif
  394.             if (not isspace(gapi.error.code) or not isspace(gapi.error.code1)) then
  395.                 gapi.message.code = f2120mgal.get.last.message.code()
  396.                 f2120mgal.end()
  397.             else
  398.                 if mode = "1" then
  399.                     f2120mgal.handle.sub.process("tssmal102s000","ADD")
  400.                     f2120mgal.Maintain_Extension_to_Service_Contract(err)
  401.                     if isspace(err) then
  402.                         fl102s000.put.Contract(x.i.ccon)
  403.                         fl102s000.insert(1,err)
  404.                         if isspace(err) then
  405.                             fl102s000.save(err)
  406.                             if not isspace(err) then
  407.                                 gapi.error.code = "Contract generated as " & x.i.ccon & "error in localization " & err
  408.                             else                                               
  409.                                 fl102s000.end()                                                      
  410.                             endif                                                                                                    
  411.                         else                                        
  412.                             gapi.error.code = "Contract generated as " & x.i.ccon & "error in localization " & err
  413.                     
  414.                         endif                                        
  415.                     else                                
  416.                         gapi.error.code = "Contract generated as " & x.i.ccon & "error in localization " & err
  417.                     endif 
  418.                     fl102s000.end()    
  419.                 endif
  420.                     
  421.             endif
  422.         endif    
  423.     endif    
  424.     
  425. }
  426.                                                              
  427. function update.tsgal059()
  428. {
  429.     
  430.     db.retry.point()
  431.     select    tsgal059.rlog,tsgal059.excp
  432.     from    tsgal059    for update
  433.     where    tsgal059._index1 = {:seq1}
  434. |     and     tsgal059._compnr = 779
  435.     selectdo
  436.         if (not isspace(gapi.error.code) or not isspace(gapi.error.code1)) then
  437.             
  438.             gapi.message.code = strip$(gapi.error.code)&" :"&strip$(gapi.error.code1)
  439.             
  440.             tsgal059.rlog = "N"
  441.         else
  442.             if mode = "1" then
  443.                 gapi.error.code = "Successful in maintaining contract:"&x.i.ccon
  444.             endif
  445.             if mode = "2" then
  446.                 gapi.error.code = "Successfully updated contract:"&x.i.ccon
  447.             endif
  448.             if mode = "3" then
  449.                 gapi.error.code = "Successfully deleted contract:"&x.i.ccon
  450.             endif
  451.             tsgal059.rlog = "Y"
  452.         endif
  453.         tsgal059.excp = gapi.error.code
  454.         db.update(ttsgal059,db.retry)
  455.         commit.transaction()
  456.     endselect    
  457. }
  458.                 
  459.  
  460.