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 63 64 65 66 67
| #Region "Check minimal"
Private Sub YieldMinErrors(ByVal listSaisieObj As IEnumerable(Of SaisieMasse.SaisieObj), ByVal collaborators As List(Of CollaboratorLight))
Dim listErrorMin = listSaisieObj.Where(Function(p) p.Valeur < p.Min And p.Valeur >= 0 And String.IsNullOrEmpty(p.Codeassoc))
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 New StringBuilder()
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.Append(String.Concat("<dd>", common.VbSysMethodes.GetNomComplet(collaborator.IdentifiantSI), "</dd>"))
End If
End If
Next
If Not String.IsNullOrEmpty(collaboratorsInError.ToString()) 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
' on doit exclure les enregistrements à remplacer, c'est à dire ceux des agences selectionnées puis faire un total PAR semaine.
Dim minimalTotal As Decimal = Decimal.MaxValue
Dim records = (From rec In currantGoals Where rec("IDENTIFIANTSI") = coll.IdentifiantSI And rec("CODEOBJECTIF") = goalId Select rec).ToList()
If (records.Count > 0) Then
records = Me.FilterRecordsByServices(records, coll)
If (records.Count > 0) Then
Dim periods = (From p In records Select p("ANNEE") * 100 + p("SEMAINE")).Distinct().ToList()
For Each period In periods
Dim total As Decimal = Me.GetTotalFromRecordsByPeriod(records, period)
minimalTotal = If(total < minimalTotal, total, minimalTotal)
Next
End If
End If
Return If(minimalTotal = Decimal.MaxValue, 0, minimalTotal)
End Function
#End Region
Private Function FilterRecordsByServices(ByRef records As List(Of DataRow), ByVal coll As CollaboratorLight) As List(Of DataRow)
For Each agency In coll.AgenciesCode
Dim soc = coll.CodeSociety
Dim ag = agency
records.RemoveAll(Function(row) row("codesociete") = soc And row("codeservice") = ag)
Next
Return records
End Function
Private Function GetTotalFromRecordsByPeriod(ByVal records As IEnumerable(Of DataRow), ByVal period As Integer) As Decimal
Dim total As Decimal = 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
Return total
End Function |
Partager