// Spec candidate public Spec SpecCandidate(OperationRawSG raw) { // Init Spec _spec = DefaultSpec; // Détermination du spec conversion candidate bool decision = raw.SpecRapproCandidates.Count > 0 && raw.TypeMoyenPaiement != "CHEQUE" && raw.TypeMoyenPaiement != "REMISE CHEQUE" ; var _retenues = raw.SpecRapproCandidates .Where(s => s.Value.CandidatureRetenue == true) ; if (decision && _retenues.Count() > 0) { // Spec avec le plus grand nombre de rappro var countMax = _retenues .Max(g => g.Value.Count); // Choix de la première spec si plusieurs _spec = _retenues .Where(g => g.Value.Count == countMax) .First().Value; } // Retour return _spec; }
// MatchBudget public virtual Boolean Match(Operation ope, OperationRawSG raw) { if (raw.HasCompteInCompteAutorises(ope.CompteB)) { return true; } return false; }
// _Match: retourne l'indice de confiance public bool Match(Operation operation, OperationRawSG raw, SeuilRappro seuil) { // Type de raw var type = raw.TypeMoyenPaiement; // Choix de la machine budget en fonction du seuil.budgetAutorise if (seuil.BudgetAutorise == false) { BudgetMachine = new BudgetMatchingMachine(); } else { BudgetMachine = new BudgetNonAlloueMatchingMachine(); } //BudgetMachine.fabriqueSpec = fab; // Variation sur type de raw switch (type) { // VIREMENT case "COTISATION": case "FRAIS": case "TELEREGLT": case "TIP": case "ECHEANCE": case "PRELEVEMENT EUROPEEN": case "PRELEVEMENT": case "VIREMENT PAYE": case "VIREMENT RECU": if (MatchVirement(operation, raw, seuil)) { return true; } break; // CHEQUE case "REMISE CHEQUE": case "CHEQUE": if (MatchCheque(operation, raw, seuil)) { return true; } break; // RETRAIT case "RETRAIT": if (MatchRetrait(operation, raw, seuil)) { return true; } break; // CARTE case "CARTE": if (MatchCarte(operation, raw, seuil)) { return true; } break; default: break; } // Par défaut return false; }
// Private private int CalculerIndiceConfiance(OperationRawSG raw) { // Init indice int indice = 0; // Specs candidates retenues var specs = raw.SpecRapproCandidates.Where(s => s.Value.CandidatureRetenue == true); int nb = specs.Count(); indice = 100; if (nb == 0) { indice = 0; } if (nb == 1) { var spec = specs.First().Value; if (fabriqueSpec.SpecIsDefault(spec) || raw.TypeMoyenPaiement == "CHEQUE" || raw.TypeMoyenPaiement == "REMISE CHEQUE") { indice = 1; } } if (nb > 1) { // Calcul de la sommes des opés sur spec cadidates retenues int nbOpes = 0; foreach (var _spec in specs) { nbOpes += _spec.Value.Count; } var _nbOpesSpecsCandidate = raw.SpecConversionCandidate.Count; if (nbOpes != 0) { indice = System.Convert.ToInt32((_nbOpesSpecsCandidate * 100.00) / nbOpes); } else { indice = System.Convert.ToInt32(100 / nb); } } // Retour return indice; }
// Fabriquer et rapprocher public RapproRaw Produire(Operation ope, OperationRawSG raw, int indice, string _origine) { // Rappro RapproRaw rappro = this.FabriquerRappro(ope, raw, indice, _origine); // Rappro Raw raw.Rapprocher(); raw.Pointer(); // Rappro opé ope.Rapprocher(raw); ope.Pointer(); // Retour return rappro; }
// Fabrique rappro private RapproRaw FabriquerRappro(Operation ope, OperationRawSG raw, int indice, string _origine) { // Nouveau rappro var rappro = new RapproRaw(); rappro.DateRapprochement = DateTime.Now; rappro.GroupeId = groupeId; rappro.Operation = ope; rappro.RawSG = raw; rappro.IndiceConfiance = indice; rappro.Origine = _origine; string _commentaire = ""; switch (_origine) { case "CONVERSION ECHEANCE from RAW": _commentaire = "Rappro créé le " + ope.DateSaisie.ToShortDateString() + " par " + ope.AuteurSaisie + " à partir de la conversion d'une échéance identifiée avec la raw." ; break; case "RAPPRO with OPERATION FRONTLOADED": _commentaire = "Rappro créé le " + ope.DateSaisie.ToShortDateString() + " par " + ope.AuteurSaisie + " à partir d'une opération déjà présente dans le système au moment du rapprochement." ; break; case "CONVERSION RAW": _commentaire = "Rappro créé le " + ope.DateSaisie.ToShortDateString() + " par " + ope.AuteurSaisie + " à partir de la conversion d'une raw en opération." ; break; default: _commentaire = "Rappro créé le " + ope.DateSaisie.ToShortDateString() + " par " + ope.AuteurSaisie; break; } rappro.Commentaire = _commentaire; // Retour return rappro; }
// Match public bool Match(EcheanceContrat _echeance, OperationRawSG raw) { var _dateEch = _echeance.DateEcheance; var _rawDate = raw.DateOperation; var _ecartConfianceDate = _echeance.CalculerEcartConfianceDate(); // Test si écart confiance == 0 _ échéance unique dans contrat DateTime inf; DateTime sup; if (_ecartConfianceDate == 0) { inf = _echeance.Contrat.DateDebut; sup = _echeance.Contrat.DateFin; } else { inf = _dateEch.AddDays(-_ecartConfianceDate); sup = _dateEch.AddDays(_ecartConfianceDate); } bool matchDate = _rawDate >= inf && _rawDate <= sup; // Match montant bool matchMontant = false; var _echanceMontant = _echeance.Montant; if (_echanceMontant != 0) { var _rawMontant = -raw.Montant; var diff = _rawMontant - _echanceMontant; var div = diff / _echanceMontant; matchMontant = Math.Abs(div) < 0.25M; } if (matchDate && matchMontant) { return true; } return false; }
public RapproRaw ProduireFromConversionRaw(Operation ope, OperationRawSG raw, int indice, bool _pointee) { // Validation de la proposition d'opération if (ope.IsValid()) { // Mise à jour des soldes dans le contexte ope.Valider(); } ope.Etat = EtatOperationEnum.RAPPROCHEE; ope.Pointee = _pointee; // Rapprpochement raw raw.Etat = EtatOperationRaw.RAPPROCHEE; raw.Pointer(); // Création rappro string _origine = "CONVERSION RAW"; RapproRaw rappro = this.FabriquerRappro(ope, raw, indice, _origine); // Retour return rappro; }
// MatchDate private Boolean MatchDate(Operation ope, OperationRawSG raw, SeuilRappro seuil) { if ( ope.DateOperation.AddDays(seuil.DeltaDays) >= raw.DateOperation && raw.DateOperation >= ope.DateOperation.AddDays(-seuil.DeltaDays) ) { return true; } return false; }
//Spec candidates public Dictionary<string, Spec> SpecCandidates(IEnumerable<RapproRaw> rappros, OperationRawSG raw) { // Filtre des rappros sur la clé Tiers/Ref/Carte var _rappros = rappros .Where(r => r.RawSG.Tiers == raw.Tiers) ; if (raw.TypeMoyenPaiement == "VIREMENT PAYE") { _rappros = _rappros.ToList(); } else { _rappros = _rappros .Where(r => r.RawSG.Ref == raw.Ref) .Where(r => r.RawSG.Carte == raw.Carte) .ToList(); } var _rapproGroupes = _rappros .GroupBy(r => new { r.Operation.CompteB , r.Operation.MoyenPaiementCompteA , r.Operation.MoyenPaiementCompteB , r.Operation.Signe } ) .Select(group => new { Key = group.Key, Count = group.Count(), GroupeRappros = group.Where(r => r.RawSG.Tiers == raw.Tiers) }) ; var _specRapproCandidates = _rapproGroupes .ToDictionary(g => raw.TypeMoyenPaiement + "-" + raw.Carte + "-" + g.Key.Signe + "-" + g.Key.CompteB.Id + "-" + g.Key.MoyenPaiementCompteA.Id + "-" + g.Key.MoyenPaiementCompteB.Id + "-" + g.Key.CompteB.Libelle + "(" + g.Count + ")" , g => new Spec(g.GroupeRappros, g.Key.CompteB , g.Key.MoyenPaiementCompteA , g.Key.MoyenPaiementCompteB , g.Key.Signe )) ; //var _specRapproCandidatesInIntervalleConfiance = new Dictionary<string, Spec>(); foreach (var _spec in _specRapproCandidates) { if (_spec.Value.IsInIntervalleConfiance(raw)) { _spec.Value.CandidatureRetenue = true; } } // Retour return _specRapproCandidates; }
private bool MatchRetrait(Operation operation, OperationRawSG raw, SeuilRappro seuil) { return operation.MoyenPaiementCompteA.Type == EnumTypeMoyenPaiement.CARTE && operation.TypeOperation.Libelle == "MiseEnCaisse" && BudgetMachine.Match(operation, raw) && MatchDate(operation, raw, seuil) && MatchMontant(operation, raw, seuil); }
public bool IsInIntervalleConfiance(OperationRawSG raw) { var result = false; var test = -raw.Montant <= this.Ope_IntervalleConfiance.ElementAt(1) && -raw.Montant >= this.Ope_IntervalleConfiance.ElementAt(0); if (test) { result = true; } return result; }
// Egalité de deux raws public Boolean Equals(OperationRawSG other) { if (CompteId != other.CompteId) { return false; } if (Valorisee != other.Valorisee) { return false; } if (Libelle != other.Libelle) { return false; } if (Montant != other.Montant) { return false; } if (Currency != other.Currency) { return false; } if (Detail != other.Detail) { return false; } return true; }
// Match fonction des types de transaction private bool MatchVirement(Operation operation, OperationRawSG raw, SeuilRappro seuil) { return operation.MoyenPaiementCompteA.Type == EnumTypeMoyenPaiement.VIREMENT && operation.TypeOperation.Libelle == "TransactionCompte" && BudgetMachine.Match(operation, raw) && MatchDate(operation, raw, seuil) && MatchMontant(operation, raw, seuil); }
// MatchBudgetNonAlloue public override Boolean Match(Operation ope, OperationRawSG raw) { return true; }
// MatchMontant private Boolean MatchMontant(Operation ope, OperationRawSG raw, SeuilRappro seuil) { if (raw.Montant == 0) { return false; } decimal ecart = Math.Abs(ope.Montant - (-raw.Montant)); decimal ecartRelatif = ecart / Math.Abs(raw.Montant); decimal diff = Math.Abs(ecartRelatif - (seuil.DeltaMontant / 100.00M)); if (seuil.DeltaMontant == 3.00M) { if (ope.Montant == 15.58M) { //var stopIt = "say hello"; } } if (ecartRelatif <= seuil.DeltaMontant / 100.00M) //if (diff <= 0.01M) { return true; } return false; }
private void Enrichir(OperationRawSG raw) { // Types IEnumerable<TypeOperation> types = uow.TypeOperation.GetAll().ToList(); // Init liste comtpe raw.SpecRapproCandidates = new Dictionary<string, Spec>(); raw.TypeOperation = types.ElementAt(0); // string[] pattern = new string[] { "MOTIF:", "REF:", "POUR:", "ID:" }; char[] x = new char[1]; x[0] = ' '; var type = System.String.Empty; var words = raw.Detail.Split(x); // Pour les tiers char[] y = new char[1]; y[0] = ':'; #region CARTE if (words.Count() > 2 && words.ElementAt(0) == "CARTE" && words.ElementAt(2) != "RETRAIT") // CARTE X4978 23/09 - CARTE X4978 23/09 AUTOROUTE DU SUD { try { // Date opération var dateSansYear = words.ElementAt(2); var dateAvecYear = dateSansYear + '/' + DateTime.Now.Year.ToString(); DateTime date = System.Convert.ToDateTime(dateAvecYear); raw.DateOperation = date; } catch (Exception) { raw.DateOperation = raw.Valorisee; } // Type raw.TypeMoyenPaiement = "CARTE"; // Carte raw.Carte = words.ElementAt(1); // Decripyion string toRemove = words.ElementAt(0) + ' ' + words.ElementAt(1) + ' ' + words.ElementAt(2); raw.Description = raw.Detail.Substring(toRemove.Count() + 1); // Tiers raw.Tiers = raw.Description; }; if (words.Count() > 2 && words.ElementAt(0) == "CARTE" && words.ElementAt(2) == "RETRAIT") // CARTE X6909 RETRAI - CARTE X6909 RETRAIT DAB 27/12 10H59 SUPER U CASTELNAU LE 18702A02 { // Date opération try { var dateSansYear = words.ElementAt(4); var dateAvecYear = dateSansYear + '/' + DateTime.Now.Year.ToString(); DateTime date = System.Convert.ToDateTime(dateAvecYear); raw.DateOperation = date; } catch (Exception) { raw.DateOperation = raw.Valorisee; } // Type raw.TypeMoyenPaiement = "RETRAIT"; raw.TypeOperation = types.ElementAt(1); // Carte raw.Carte = words.ElementAt(1); // Decripyion string toRemove = words.ElementAt(0) + ' ' + words.ElementAt(1) + ' ' + words.ElementAt(2); raw.Description = raw.Detail.Substring(toRemove.Count() + 1); }; #endregion #region VIR if (words.Count() > 1 && words.ElementAt(0) + ' ' + words.ElementAt(1) == "VIR RECU") // VIR RECU 121327208 - VIR RECU 1213272086453 DE: COUPLE LEOTARD MICHEL MOTIF: Cadeau emily montre { // Date opération raw.DateOperation = raw.Valorisee; // Type raw.TypeMoyenPaiement = "VIREMENT RECU"; // Decripyion string toRemove = words.ElementAt(0) + ' ' + words.ElementAt(1) + ' ' + words.ElementAt(2) + ' ' + words.ElementAt(3); raw.Description = raw.Detail.Substring(toRemove.Count() + 1); // Tiers var substrings = raw.Description.Split(pattern, StringSplitOptions.None); raw.Tiers = substrings.ElementAt(0); raw.Motif = substrings.ElementAt(1); }; if (words.Count() > 2 && words.ElementAt(0) + ' ' + words.ElementAt(1) + ' ' + words.ElementAt(2) == "000001 VIR PERM") // 000001 VIR PERM - 000001 VIR PERM POUR: EMILY LEOTARD REF: 1000065671056 MOTIF: VIREMENT CAV 0339300050227495 { // Date opération raw.DateOperation = raw.Valorisee; // Type raw.TypeMoyenPaiement = "VIREMENT PAYE"; // Decripyion string toRemove = words.ElementAt(0) + ' ' + words.ElementAt(1) + ' ' + words.ElementAt(2) + ' ' + words.ElementAt(3); raw.Description = raw.Detail.Substring(toRemove.Count() + 1); // Tiers var substrings = raw.Description.Split(pattern, StringSplitOptions.None); raw.Tiers = substrings.ElementAt(0); raw.Ref = substrings.ElementAt(1); raw.Motif = substrings.ElementAt(2); }; if (words.Count() > 2 && words.ElementAt(0) + ' ' + words.ElementAt(1) + ' ' + words.ElementAt(2) == "000001 VIR EUROPEEN") // 000001 VIR EUROPEE - 000001 VIR EUROPEEN EMIS LOGITEL POUR: Michel Leotard 16 12 SG 01430 CPT 00052423218 REF: 1213349070899 { // Date opération raw.DateOperation = raw.Valorisee; // Type raw.TypeMoyenPaiement = "VIREMENT PAYE"; // Decripyion string toRemove = words.ElementAt(0) + ' ' + words.ElementAt(1) + ' ' + words.ElementAt(2) + ' ' + words.ElementAt(3) + ' ' + words.ElementAt(4) + ' ' + words.ElementAt(5) ; raw.Description = raw.Detail.Substring(toRemove.Count() + 1); // Tiers var substrings = raw.Description.Split(pattern, StringSplitOptions.None); var _tiersPlus = substrings.ElementAt(0); var spliPattern = new string[] { " " }; var wordsTiers = _tiersPlus.Split(spliPattern, StringSplitOptions.RemoveEmptyEntries); var nb = wordsTiers.Count() - 1; if (nb > 6) { string _remove = wordsTiers.ElementAt(nb) + ' ' + wordsTiers.ElementAt(nb - 1) + ' ' + wordsTiers.ElementAt(nb - 2) + ' ' + wordsTiers.ElementAt(nb - 3) + ' ' + wordsTiers.ElementAt(nb - 4) + ' ' + wordsTiers.ElementAt(nb - 5) ; raw.Tiers = _tiersPlus.Substring(0, _tiersPlus.Count() - 1 - _remove.Count() - 1); } else { raw.Tiers = substrings.ElementAt(0); } raw.Ref = substrings.ElementAt(1); }; #endregion #region CHEQUE if (words.Count() > 1 && words.ElementAt(0) == "CHEQUE") // CHEQUE 812 - CHEQUE 812 { // Date opération raw.DateOperation = raw.Valorisee; // Type raw.TypeMoyenPaiement = "CHEQUE"; // Numéro chèque raw.NumeroCheque = words.ElementAt(1); // Decripyion raw.Description = raw.Detail; }; if (words.Count() > 1 && words.ElementAt(0) + ' ' + words.ElementAt(1) == "REMISE CHEQUE") // REMISE CHEQUE - REMISE CHEQUE 0000045 273 DE 1 CHQ 01529 0000045 { // Date opération raw.DateOperation = raw.Valorisee; // Type raw.TypeMoyenPaiement = "REMISE CHEQUE"; // Decripyion raw.Description = raw.Detail; }; #endregion #region PRELEVEMENT if (words.Count() > 1 && (words.ElementAt(0) == "PRELEVEMENT") && (words.ElementAt(0) + ' ' + words.ElementAt(1) != "PRELEVEMENT EUROPEEN")) // PRELEVEMENT 107510 - PRELEVEMENT 1075105078 GDF SUEZ 5104172320480004093*99363 { // Date opération raw.DateOperation = raw.Valorisee; // Type raw.TypeMoyenPaiement = "PRELEVEMENT"; // Decripyion string toRemove = words.ElementAt(0) + ' ' + words.ElementAt(1); raw.Description = raw.Detail.Substring(toRemove.Count() + 1); }; if (words.Count() > 1 && words.ElementAt(0) + ' ' + words.ElementAt(1) == "PRELEVEMENT EUROPEEN") // PRELEVEMENT EUROPE - PRELEVEMENT EUROPEEN 5304618158 DE: URSSAF DE LA LOIRE-CNCESU ID: FR55ZZZ143065 MOTIF: PRELEVEMENT CNCESU MR ET MME LEOTAR { // Date opération raw.DateOperation = raw.Valorisee; // Type raw.TypeMoyenPaiement = "PRELEVEMENT EUROPEEN"; // Decripyion string toRemove = words.ElementAt(0) + ' ' + words.ElementAt(1) + ' ' + words.ElementAt(2) + ' ' + words.ElementAt(3); raw.Description = raw.Detail.Substring(toRemove.Count() + 1); // Tiers var substrings = raw.Description.Split(pattern, StringSplitOptions.None); raw.Tiers = substrings.ElementAt(0); raw.Ref = substrings.ElementAt(1); raw.Motif = substrings.ElementAt(2); }; #endregion #region ECHEANCE if (words.Count() > 0 && words.ElementAt(0) == "ECHEANCE") // PRELEVEMENT 107510 - PRELEVEMENT 1075105078 GDF SUEZ 5104172320480004093*99363 { // Date opération raw.DateOperation = raw.Valorisee; // Type raw.TypeMoyenPaiement = "ECHEANCE"; // Decripyion string toRemove = words.ElementAt(0) + ' ' + words.ElementAt(1); raw.Description = raw.Detail.Substring(toRemove.Count() + 1); }; #endregion #region TIP if (words.Count() > 0 && words.ElementAt(0) == "TIP") // TIP 726023 - TIP 7260239701 VEOLIA SUD 5P1ER8 200651200011630213380000 07632201120 0000 520763 { // Date opération raw.DateOperation = raw.Valorisee; // Type raw.TypeMoyenPaiement = "TIP"; // Decripyion string toRemove = words.ElementAt(0) + ' ' + words.ElementAt(1); raw.Description = raw.Detail.Substring(toRemove.Count() + 1); }; #endregion #region TELEREGLT if (words.Count() > 0 && words.ElementAt(0) == "TELEREGLT") // TELEREGLT 256169 - TELEREGLT 2561691432 REGLEMENT IMPOT IR 600035090661TLR1334032442620 P1839765015473 { // Date opération raw.DateOperation = raw.Valorisee; // Type raw.TypeMoyenPaiement = "TELEREGLT"; // Decripyion string toRemove = words.ElementAt(0) + ' ' + words.ElementAt(1) + ' ' + words.ElementAt(2); raw.Description = raw.Detail.Substring(toRemove.Count() + 1); }; #endregion #region FRAIS if (words.Count() > 0 && words.ElementAt(0) == "FRAIS") // FRAIS PAIEMENT HOR - FRAIS PAIEMENT HORS ZONE EURO 113,62 EUR A 2,70 % 1 PAIEMENT A 1,00 EUR NT // FRAIS RETRAIT HORS - FRAIS RETRAIT HORS ZONE EURO 1 RETRAIT A 3,00 EUR NT 232,83 EUR A 2,70 % // FRAIS RET EUR DAB - FRAIS RET EUR DAB UE HORS SG PRESTA 0000000000000006184177 5 RETRAITS EN 11/2013 FORFAIT MENS. 3/3 GRATUITS { // Date opération raw.DateOperation = raw.Valorisee; // Type raw.TypeMoyenPaiement = "FRAIS"; // Decripyion string toRemove = words.ElementAt(0); raw.Description = raw.Detail.Substring(toRemove.Count() + 1); }; #endregion #region COTISATION if (words.Count() > 0 && words.ElementAt(0) == "COTISATION") // COTISATION ANNUELL - COTISATION ANNUELLE CARTE Visa X3973 { // Date opération raw.DateOperation = raw.Valorisee; // Type raw.TypeMoyenPaiement = "COTISATION"; // Decripyion raw.Description = raw.Detail; }; #endregion // Compte boursorama - non traité pour le moment if (raw.Compte.GroupeId == 409) { raw.DateOperation = raw.Valorisee; raw.Description = raw.Libelle; } }