[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 279
  • Last Modified:

The following works ,but it seems clumsy

HI

I finally have the logic worked out on this damn thing.

Here is what works I am sure it can be sweetened up

What do you think

Regards

James


Sub Approved
      
      Dim ws As New NotesUIWorkspace
      Dim session As New NotesSession
      Dim db As NotesDatabase
      Dim doc As NotesDocument, note As notesdocument
      Dim view As NotesView
      Set note = ws.CurrentDocument.Document
      Set db = session.CurrentDatabase
      Set view = db.GetView( "AvailHol")
      If view Is Nothing Then
            Msgbox "Cannot find view"
            Exit Sub
      End If
      If note.HasItem("RequesterName") Then
            Set doc = view.GetDocumentByKey(note.RequesterName(0)) ' KEY Value passed to view
      End If
      
      If Not doc Is Nothing Then
            
            If note.type(0) = "Vac" And  Month(note.StartDate(0)) >6 Then
                  tmpNewDaysTotal = note.NewDaysTotal(0)    
                  tmpAllowanceAH_1 = tmpNewDaysTotal + doc.AllowanceAH_1(0)
                  tmpAllowanceAH_2 = doc.allowanceAH_2(0) - tmpNewDaysTotal
                  doc.AllowanceAH_1 = tmpAllowanceAH_1
                  doc.AllowanceAH_2 = tmpAllowanceAH_2
                  doc.totalAH_1 = doc.CarriedOverAH_1(0) + doc.AllowanceAH_1(0)
                  doc.totalAH_2 = doc.CarriedOverAH_2(0) + doc.AllowanceAH_2(0)
                  Goto SaveIt
                  
            Else
                  If Month(note.StartDate(0)) < 6 And note.type(0) = "Vac" Then
                        If note.newdaystotal(0)  =< doc.CarriedOverAH_2(0) Then
    REM If doc.CarriedOverAH(0)>= 1 And doc.CarriedOverAH(0) <= 5 Then
                              doc.CarriedOverAH_1 = doc.CarriedOverAH_1(0) + note.NewDaysTotal(0)
                              doc.CarriedOverAH_2 = doc.CarriedOverAH(0) - note.NewDaysTotal(0)
                              doc.totalAH_1 = doc.CarriedOverAH_1(0) + doc.AllowanceAH_1(0)
                              doc.totalAH_2 = doc.CarriedOverAH_2(0) + doc.AllowanceAH_2(0)
                              Goto SaveIt
                              
                        Else
                              If (doc.CarriedOverAh_2(0) <> 0)  And (note.newdaystotal(0)  > doc.CarriedOverAH_2(0)) Then
                                    tmpCarriedOverAH_2 = doc.CarriedOverAH_2(0)
                                    tmpNewDay = note.newdaystotal(0) - tmpCarriedOverAH_2
                                    tmpAllowanceAH_2 = doc.AllowanceAH_2(0) - tmpNewDay
                                    tmpAllowanceAH_1 = doc.AllowanceAH_1(0) + tmpNewDay
                                    doc.CarriedOverAH_1 = doc.CarriedOverAH_1(0) + tmpCarriedOverAH_2
                                    doc.CarriedOverAH_2 = 0
                                    doc.AllowanceAH_1 = tmpAllowanceAH_1
                                    doc.AllowanceAH_2 = tmpAllowanceAH_2
                                    doc.totalAH_1 = doc.CarriedOverAH_1(0) + doc.AllowanceAH_1(0)
                                    doc.totalAH_2 = doc.CarriedOverAH_2(0) + doc.AllowanceAH_2(0)
                                    
                              Else
                                    If doc.CarriedOverAH_2(0) = 0 Then
                                          tmpNewDaysTotal = note.NewDaysTotal(0)    
                                          tmpAllowanceAH_1 = tmpNewDaysTotal + doc.AllowanceAH_1(0)
                                          tmpAllowanceAH_2 = doc.allowanceAH_2(0) - tmpNewDaysTotal
                                          doc.AllowanceAH_1 = tmpAllowanceAH_1
                                          doc.AllowanceAH_2 = tmpAllowanceAH_2
                                          doc.totalAH_1 = doc.CarriedOverAH_1(0) + doc.AllowanceAH_1(0)
                                          doc.totalAH_2 = doc.CarriedOverAH_2(0) + doc.AllowanceAH_2(0)
                                          Goto SaveIt
                                    End If
                              End If
                        End If
                  End If
            End If
            
            If note.type(0) = "Per" Then
                  tmpPersonalDaysAH_2 =doc.PersonalDaysAH_2(0) - note.NewDaysTotal(0)
                  tmpPersonalDaysAH_1 = note.NewDaysTotal(0)
                  doc.PersonalDaysAH_2 = tmpPersonalDaysAH_2
                  doc.PersonalDaysAH_1 = tmpPersonalDaysAH_1
                  Goto SaveIt
            End If
            
            If note.type(0) = "WFH" Then
            End If
            
SaveIT:
            doc.ComputeWithForm True, False  
            doc.save True, False
      Else
            Msgbox "No leave document found for this employee"
      End If
End Sub

0
adspmo
Asked:
adspmo
  • 3
  • 2
2 Solutions
 
HemanthaKumarCommented:
There is nothing here to sweeten it as you are doing some calc...But anyway if you want to sweeten it up then add some remarks on top of each if condition that why you are doing that check and

~Hemanth
0
 
HemanthaKumarCommented:
Also in this if condition

 If note.HasItem("RequesterName") Then
          Set doc = view.GetDocumentByKey(note.RequesterName(0)) ' KEY Value passed to view
 End If

You don't accomodate the failure condition like this

 If note.HasItem("RequesterName") Then
          Set doc = view.GetDocumentByKey(note.RequesterName(0)) ' KEY Value passed to view
 ELse
          Msgbox "Required field RequesterName missing"
          Exit sub
 End If
0
 
qwaleteeCommented:
Well, as I'ev said before, more descriptive names than note and doc... those woudl be fine if there was only one of them.
You could take each block in teh IF and make it a subroutine, so that it is more readable and the logic flows easily, e.g.,


if note.type(0) = "vac" and month(note,startdate(00) >= 6 Then
  assignDaysInoringCarryOver
Else
....

Sub assignDaysIgnoringCarryOver
               tmpNewDaysTotal = note.NewDaysTotal(0)    
               tmpAllowanceAH_1 = tmpNewDaysTotal + doc.AllowanceAH_1(0)
               tmpAllowanceAH_2 = doc.allowanceAH_2(0) - tmpNewDaysTotal
               doc.AllowanceAH_1 = tmpAllowanceAH_1
               doc.AllowanceAH_2 = tmpAllowanceAH_2
               doc.totalAH_1 = doc.CarriedOverAH_1(0) + doc.AllowanceAH_1(0)
               doc.totalAH_2 = doc.CarriedOverAH_2(0) + doc.AllowanceAH_2(0)
End Sub
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
adspmoAuthor Commented:
I was thinking about subroutines or would it functions as from what I understand functions return a value.WOuld thta value be singular or could it be multiple.


Thanks for the other ideas

James
0
 
HemanthaKumarCommented:
Yes, functions return values and  mostly replace all repetitive tasks. But in your case each condition lead to a different set of calculations. If you were using same kind of calculations all over the place then you can write a function and call it accordingly.
0
 
qwaleteeCommented:
HemanthaKumar,
> If you were using same kind of calculations all over the place then you can write a function
I soetimes write subs or fnctions even if they get called once, if it helps make the code readabke.  That's what I was suggesting here.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now