1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| Partial Public Class CheckForm
Inherits IdentificationPage
Dim reponse As String = String.Empty
Dim currantGoals As DataTable = Nothing
Private Sub YieldMinErrors(ByVal listSaisieObj As List(Of SaisieObj), ByVal collaborators As List(Of CollaboratorLight))
'Le contrôle se fait en 3 étapes : sur la saisie, sur le nombre d'agences puis sur les données déjà enregistrées.
Dim listErrorMin = listSaisieObj.Where(Function(p) p.Valeur < p.Min And p.Valeur >= 0 And p.Codeassoc = String.Empty)
For Each goalInError In listErrorMin
'On a trouvé des objectifs saisis où la valeur ne correspond pas au minimum attendu donc on va contrôler que cette valeur est bonne en tenant compte du nombre d'agences de chaque collaborateur. Chaque collaborateur en erreur lèvera un dernier contrôle.
Dim collaboratorsInError As String = String.Empty
For Each collaborator In collaborators
Dim nbAgencies = If(collaborator.AgenciesCode Is Nothing, 0, collaborator.AgenciesCode.Count)
Dim difference = goalInError.Min - (goalInError.Valeur * nbAgencies)
If (difference > 0) Then
'On a des collaborateurs pour lesquels le nombre d'agences ne compense pas l'écart entre la valeur saisie et le minimum. On va devoir contrôler ce qui a déjà été saisi.
Dim total As Decimal = 0
total = GetMinTotalByCollaboratorAndGoal(collaborator, goalInError.Id.ToString())
If (difference - total > 0) Then
collaboratorsInError = String.Concat(collaboratorsInError, "<dd>", common.VbSysMethodes.GetNomComplet(collaborator.IdentifiantSI), "</dd>")
End If
End If
Next
If Not String.IsNullOrEmpty(collaboratorsInError) Then
Me.reponse = String.Concat(Me.reponse, String.Format("<p>L'objectif '{0}' doit être supérieur ou égal à {1} sur l'ensemble des agences pour :{2}</p>", goalInError.Libelle, goalInError.Min, collaboratorsInError))
End If
Next
End Sub
Private Function GetMinTotalByCollaboratorAndGoal(ByVal coll As CollaboratorLight, ByVal goalId As String) As Decimal
Dim records = (From rec In currantGoals Where rec("IDENTIFIANTSI") = coll.IdentifiantSI And rec("CODEOBJECTIF") = goalId Select rec).ToList()
Dim total As Decimal
Dim minimalTotal As Decimal = Decimal.MaxValue
' on doit exclure les enregistrements à remplacer, c'est à dire ceux des agences selectionnées puis faire un total PAR semaine.
If (records.Count > 0) Then
For Each agency In coll.AgenciesCode
Dim soc = coll.CodeSociety
Dim ag = agency
Dim rowsToExclude = records.Where(Function(row) row("codesociete") = soc And row("codeservice") = ag).ToList()
For Each row In rowsToExclude
records.Remove(row)
Next
Next
Dim periods = (From p In records Select p("ANNEE") * 100 + p("SEMAINE")).Distinct().ToList()
For Each period In periods
total = 0
Dim year As Integer = Decimal.Floor(period / 100)
Dim week As Integer = period - year * 100
Dim rows = (From r In records Where r("ANNEE") = year And r("SEMAINE") = week Select r).ToList()
For Each row In rows
total += row("VALEUR")
Next
minimalTotal = If(total < minimalTotal, total, minimalTotal)
Next
End If
Return If(minimalTotal = Decimal.MaxValue, 0, minimalTotal)
End Function |
Partager