public void SearchBalance(Model.Sage.F_COMPTET F_COMPTET, uint PsCustomer, DateTime DebutExo, DateTime FinExo)
        {
            try
            {
                Model.Prestashop.PsAECBalanceAccountingRepository PsAECBalanceAccountingRepository = new Model.Prestashop.PsAECBalanceAccountingRepository();
                PsAECBalanceAccountingRepository.Delete(PsAECBalanceAccountingRepository.ListCustomer(PsCustomer));

                Model.Sage.F_ECRITURECRepository F_ECRITURECRepository = new Model.Sage.F_ECRITURECRepository();
                List <Model.Sage.F_ECRITUREC>    ListF_ECRITUREC       = F_ECRITURECRepository.ListTiers(F_COMPTET.CT_Num, DebutExo, FinExo);

                List <Model.Prestashop.PsAEcBalanceAccounting> temp = new List <Model.Prestashop.PsAEcBalanceAccounting>();
                foreach (Model.Sage.F_ECRITUREC F_ECRITUREC in ListF_ECRITUREC)
                {
                    temp.Add(new Model.Prestashop.PsAEcBalanceAccounting()
                    {
                        IDCustomer    = PsCustomer,
                        DateAdd       = F_ECRITUREC.EC_Date.Value,
                        DateTerm      = F_ECRITUREC.EC_Echeance.Value,
                        CreditAmount  = (F_ECRITUREC.EC_Sens == (short)ABSTRACTION_SAGE.F_ECRITUREC.Obj._Enum_EC_Sens.Credit && F_ECRITUREC.EC_Montant.HasValue) ? F_ECRITUREC.EC_Montant.Value : 0,
                        DebitAmount   = (F_ECRITUREC.EC_Sens == (short)ABSTRACTION_SAGE.F_ECRITUREC.Obj._Enum_EC_Sens.Debit && F_ECRITUREC.EC_Montant.HasValue) ? F_ECRITUREC.EC_Montant.Value : 0,
                        Description   = F_ECRITUREC.EC_Intitule,
                        InvoiceNumber = F_ECRITUREC.EC_RefPiece,
                        Lettering     = (F_ECRITUREC.EC_Lettre == (short)ABSTRACTION_SAGE.F_ECRITUREC.Obj._Enum_Boolean.Oui) ? F_ECRITUREC.EC_Lettrage : string.Empty,
                    });
                }
                PsAECBalanceAccountingRepository.Add(temp);
            }
            catch (Exception ex)
            {
                logs.Add("BA30- Erreur lecture écritures comptables" + ex.ToString());
            }
        }
 public void Exec(Int32 F_COMPTETSend)
 {
     try
     {
         Model.Local.SupplierRepository SupplierRepository = new Model.Local.SupplierRepository();
         if (SupplierRepository.ExistSag_Id(F_COMPTETSend) == false)
         {
             Model.Sage.F_COMPTETRepository F_COMPTETRepository = new Model.Sage.F_COMPTETRepository();
             Model.Sage.F_COMPTET           F_COMPTET           = F_COMPTETRepository.Read(F_COMPTETSend);
             Model.Local.Supplier           Supplier            = new Model.Local.Supplier()
             {
                 Sup_Active          = true,
                 Sup_Description     = F_COMPTET.CT_Intitule,
                 Sup_MetaDescription = F_COMPTET.CT_Intitule,
                 Sup_MetaKeyword     = F_COMPTET.CT_Intitule,
                 Sup_Name            = F_COMPTET.CT_Intitule,
                 Sup_MetaTitle       = F_COMPTET.CT_Intitule,
                 Sup_Date            = DateTime.Now,
                 Sup_Sync            = true,
                 Sag_Id = F_COMPTET.cbMarq
             };
             SupplierRepository.Add(Supplier);
         }
     }
     catch (Exception ex)
     {
         Core.Error.SendMailError(ex.ToString());
     }
 }
Exemplo n.º 3
0
 public void Exec(Model.Sage.F_COMPTET F_COMPTET, Model.Prestashop.PsCustomer PsCustomer)
 {
     try
     {
         if (Core.Global.ExistCustomerInfoModule())
         {
             Model.Prestashop.PsCustomerInfoRepository PsCustomerInfoRepository = new Model.Prestashop.PsCustomerInfoRepository();
             if (PsCustomerInfoRepository.ExistCustomer(PsCustomer.IDCustomer))
             {
                 Model.Prestashop.PsCustomerInfo PsCustomerInfo = PsCustomerInfoRepository.ReadCustomer(PsCustomer.IDCustomer);
                 if (string.IsNullOrWhiteSpace(PsCustomerInfo.CustomerNumber))
                 {
                     PsCustomerInfo.CustomerNumber = F_COMPTET.CT_Num;
                     PsCustomerInfoRepository.Save();
                 }
             }
             else
             {
                 PsCustomerInfoRepository.Add(new Model.Prestashop.PsCustomerInfo()
                 {
                     IDCustomer      = PsCustomer.IDCustomer,
                     CustomerNumber  = F_COMPTET.CT_Num,
                     IDStoreCustomer = 0,
                 });
             }
         }
     }
     catch (Exception ex)
     {
         Core.Error.SendMailError(ex.ToString());
     }
 }
        public void Exec(Model.Local.Customer Customer, out List <String> log_out)
        {
            try
            {
                DateTime DebutExo = new DateTime(1900, 01, 01);
                DateTime FinExo   = new DateTime(1900, 01, 01);
                //if (Core.Global.GetConfig().ModuleAECCustomerOutstandingActif && Core.Global.ExistAECCustomerOutstandingModule())
                {
                    Model.Sage.F_COMPTETRepository        F_COMPTETRepository  = new Model.Sage.F_COMPTETRepository();
                    Model.Prestashop.PsCustomerRepository PsCustomerRepository = new Model.Prestashop.PsCustomerRepository();

                    if (!F_COMPTETRepository.ExistId(Customer.Sag_Id))
                    {
                        logs.Add("BA10- Client Sage introuvable à partir du l'identifiant " + Customer.Sag_Id.ToString() + " !");
                    }
                    else if (!PsCustomerRepository.ExistCustomer((uint)Customer.Pre_Id))
                    {
                        logs.Add("BA11- Client PrestaShop introuvable à partir de l'identifiant " + Customer.Pre_Id.ToString() + " !");
                    }
                    else
                    {
                        List <string> log = new List <string>();
                        if (current_exercice(out DebutExo, out FinExo))
                        {
                            Model.Sage.F_COMPTET F_COMPTET = F_COMPTETRepository.Read(Customer.Sag_Id);

                            SearchBalance(F_COMPTET, (uint)Customer.Pre_Id, DebutExo, FinExo);
                        }
                        if (log.Count > 0)
                        {
                            logs.AddRange(log);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError("BA01- Une erreur est survenue : " + ex.ToString());
            }
            finally
            {
                log_out = logs;
            }
        }
        public void LoadControleEncours(Model.Sage.F_COMPTET F_COMPTET, DateTime DebutExo, DateTime FinExo, out Decimal SoldeComptable, out Decimal Portefeuille)
        {
            Model.Sage.P_CRISQUE._Enum_R_Type EtatControle = Model.Sage.P_CRISQUE._Enum_R_Type.Livraison;

            Portefeuille   = 0;
            SoldeComptable = 0;

            if (F_COMPTET.CT_ControlEnc == null)
            {
                // pas d'action = livraison
            }
            else if (F_COMPTET.CT_ControlEnc == (short)ABSTRACTION_SAGE.F_COMPTET.Obj._Enum_CT_ControlEnc.Compte_Bloque)
            {
                EtatControle = Model.Sage.P_CRISQUE._Enum_R_Type.Blocage;
            }
            // si compte client en "controle automatique" ou "selon code risque"
            else
            {
                Model.Sage.P_CRISQUE           P_CRISQUE;
                Model.Sage.P_CRISQUERepository P_CRISQUERepository = new Model.Sage.P_CRISQUERepository();
                if (P_CRISQUERepository.ExistCRisque(F_COMPTET.N_Risque.Value))
                {
                    P_CRISQUE = P_CRISQUERepository.ReadCRisque(F_COMPTET.N_Risque.Value);

                    if (P_CRISQUE.R_Type != null)
                    {
                        EtatControle = (Model.Sage.P_CRISQUE._Enum_R_Type)P_CRISQUE.R_Type;
                    }
                }
            }

            // envoi des informations sur l'encours du client

            // récupération du montant d'encours
            Model.Sage.DP_ENCOURSTIERSRepository DP_ENCOURSTIERSRepository = new Model.Sage.DP_ENCOURSTIERSRepository();
            Model.Sage.DP_ENCOURSTIERS           DP_ENCOURSTIERS           = DP_ENCOURSTIERSRepository.ReadTiers2(F_COMPTET.CT_Num, DebutExo, FinExo);
            SoldeComptable = DP_ENCOURSTIERS.SoldeComptable;

            Decimal LimiteTiers = 0;

            if (F_COMPTET.CT_Encours != null)
            {
                LimiteTiers = (Decimal)F_COMPTET.CT_Encours;
            }

            //Decimal DepassementMax = 0;
            //Decimal DepassementMini = 0;
            //if(P_CRISQUE.R_Min != null)
            //{
            //    DepassementMini = (Decimal)P_CRISQUE.R_Min;
            //}
            //if(P_CRISQUE.R_Max != null)
            //{
            //    DepassementMax = (Decimal)P_CRISQUE.R_Max;
            //}

            // récupération du portefeuille selon le paramétrage de Sage
            Model.Sage.DP_PORTEFEUILLEVENTERepository DP_PORTEFEUILLEVENTRepository = new Model.Sage.DP_PORTEFEUILLEVENTERepository();
            Model.Sage.DP_PORTEFEUILLEVENTE           DP_PORTEFEUILLEVENTE          = DP_PORTEFEUILLEVENTRepository.ReadTiers2(F_COMPTET.CT_Num, ParametrePortefeuille);
            Portefeuille = DP_PORTEFEUILLEVENTE.MontantPortefeuille;

            //solde = SoldeComptable + Portefeuille;
            //NouvelEncours = SoldeComptable + MontantDocument;
            //Depassement = NouvelEncours - LimiteTiers;

            F_COMPTET.EtatControleEncours = EtatControle;
        }
        public void Exec(Model.Local.Customer Customer, out List <String> log_out)
        {
            //logs.Add("Client ps " + Customer.Pre_Id.ToString() + " / sage " + Customer.Sag_Id.ToString());
            try
            {
                //if (Core.Global.GetConfig().ModuleAECCustomerOutstandingActif && Core.Global.ExistAECCustomerOutstandingModule())
                {
                    //logs.Add("module encours actif");
                    Model.Sage.F_COMPTETRepository        F_COMPTETRepository  = new Model.Sage.F_COMPTETRepository();
                    Model.Prestashop.PsCustomerRepository PsCustomerRepository = new Model.Prestashop.PsCustomerRepository();

                    if (!F_COMPTETRepository.ExistId(Customer.Sag_Id))
                    {
                        logs.Add("BO10- Client Sage introuvable à partir du l'identifiant " + Customer.Sag_Id.ToString() + " !");
                    }
                    else if (!PsCustomerRepository.ExistCustomer((uint)Customer.Pre_Id))
                    {
                        logs.Add("BO11- Client PrestaShop introuvable à partir de l'identifiant " + Customer.Pre_Id.ToString() + " !");
                    }
                    else
                    {
                        //logs.Add("données client récupérées");
                        List <string> log = new List <string>();
                        try
                        {
                            DateTime DebutExo = new DateTime(1900, 01, 01);
                            DateTime FinExo   = new DateTime(1900, 01, 01);
                            if (current_exercice(out DebutExo, out FinExo))
                            {
                                //logs.Add("Exercice " + DebutExo.ToShortDateString() + " / " + FinExo.Date.ToShortDateString());
                                if (ParametrePortefeuille == Core.Parametres.P_BaseEncours.NonDefini)
                                {
                                    read_param_portefeuille();
                                }

                                //logs.Add("Paramètre portefeuille " + ParametrePortefeuille.ToString());

                                Model.Sage.F_COMPTET F_COMPTET = F_COMPTETRepository.Read(Customer.Sag_Id);

                                Decimal EncoursAutorise = (F_COMPTET.CT_Encours != null) ? F_COMPTET.CT_Encours.Value : 0;
                                Decimal SoldeComptable, Portefeuille;
                                LoadControleEncours(F_COMPTET, DebutExo, FinExo, out SoldeComptable, out Portefeuille);


                                //logs.Add("client : " + F_COMPTET.CT_Num
                                //+ " / type encours : " + F_COMPTET.EtatControleEncours.ToString()
                                //+ " / autorisé : " + EncoursAutorise
                                //+ " / solde comptable : " + SoldeComptable
                                //+ " / portefeuille : " + Portefeuille);


                                #region Saisie PrestaShop

                                Model.Prestashop.PsCustomer PsCustomer = PsCustomerRepository.ReadCustomer((uint)Customer.Pre_Id);
                                PsCustomer.OutstandingAllowAmount = EncoursAutorise;
                                PsCustomerRepository.Save();

                                Model.Prestashop.PsAECBalanceOutstandingRepository PsAECBalanceOutstandingRepository = new Model.Prestashop.PsAECBalanceOutstandingRepository();
                                Model.Prestashop.PsAEcBalanceOutstanding           encours_client;
                                if (PsAECBalanceOutstandingRepository.ExistCustomer(PsCustomer.IDCustomer))
                                {
                                    encours_client = PsAECBalanceOutstandingRepository.ReadCustomer(PsCustomer.IDCustomer);
                                    encours_client.SageOutstanding        = SoldeComptable;
                                    encours_client.SageWallet             = Portefeuille;
                                    encours_client.OutstandingAllowAmount = EncoursAutorise;

                                    switch (F_COMPTET.EtatControleEncours)
                                    {
                                    case PRESTACONNECT.Model.Sage.P_CRISQUE._Enum_R_Type.Livraison:
                                        encours_client.Oversee       = 0;
                                        encours_client.AccountLocked = 0;
                                        break;

                                    case PRESTACONNECT.Model.Sage.P_CRISQUE._Enum_R_Type.Surveillance:
                                        encours_client.Oversee       = 1;
                                        encours_client.AccountLocked = 0;
                                        break;

                                    case PRESTACONNECT.Model.Sage.P_CRISQUE._Enum_R_Type.Blocage:
                                        encours_client.Oversee       = 0;
                                        encours_client.AccountLocked = 1;
                                        break;
                                    }
                                    PsAECBalanceOutstandingRepository.Save();
                                }
                                else
                                {
                                    encours_client = new Model.Prestashop.PsAEcBalanceOutstanding()
                                    {
                                        IDCustomer             = PsCustomer.IDCustomer,
                                        SageOutstanding        = SoldeComptable,
                                        SageWallet             = Portefeuille,
                                        OutstandingAllowAmount = EncoursAutorise,
                                    };

                                    switch (F_COMPTET.EtatControleEncours)
                                    {
                                    case PRESTACONNECT.Model.Sage.P_CRISQUE._Enum_R_Type.Livraison:
                                        encours_client.Oversee       = 0;
                                        encours_client.AccountLocked = 0;
                                        break;

                                    case PRESTACONNECT.Model.Sage.P_CRISQUE._Enum_R_Type.Surveillance:
                                        encours_client.Oversee       = 1;
                                        encours_client.AccountLocked = 0;
                                        break;

                                    case PRESTACONNECT.Model.Sage.P_CRISQUE._Enum_R_Type.Blocage:
                                        encours_client.Oversee       = 0;
                                        encours_client.AccountLocked = 1;
                                        break;
                                    }
                                    PsAECBalanceOutstandingRepository.Add(encours_client);
                                }

                                #endregion
                            }
                        }
                        catch (Exception ex)
                        {
                            log.Add("BO02- Erreur calcul suivi comptable : " + ex.ToString());
                        }
                        if (log.Count > 0)
                        {
                            logs.AddRange(log);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError("BO01- Une erreur est survenue : " + ex.ToString());
            }
            finally
            {
                log_out = logs;
            }
        }
        private void ExecDistantToLocal(Model.Local.Customer Customer, Model.Prestashop.PsAddress PsAddress, ABSTRACTION_SAGE.ALTERNETIS.Connexion Connexion, Model.Local.AddressRepository AddressRepository)
        {
            try
            {
                Model.Local.ConfigRepository     ConfigRepository   = new Model.Local.ConfigRepository();
                Model.Local.Config               Config             = new Model.Local.Config();
                ABSTRACTION_SAGE.F_LIVRAISON.Obj F_LIVRAISON        = new ABSTRACTION_SAGE.F_LIVRAISON.Obj();
                Model.Sage.F_COMPTETRepository   F_COMPTERepository = new Model.Sage.F_COMPTETRepository();
                if (F_COMPTERepository.ExistId(Customer.Sag_Id))
                {
                    Model.Sage.F_COMPTET F_COMPTET = F_COMPTERepository.Read(Customer.Sag_Id);
                    F_LIVRAISON.CT_Num = F_COMPTET.CT_Num;

                    // <JG> 07/09/2012 Modification gestion adresse livraison
                    if (ConfigRepository.ExistName(Core.Global.ConfigClientIntituleAdresse) &&
                        ConfigRepository.ReadName(Core.Global.ConfigClientIntituleAdresse).Con_Value == Core.Global.ConfigClientIntituleAdresseEnum.NomPrenomPrestashop.ToString())
                    {
                        string temp = (Core.Global.GetConfig().ConfigClientSocieteIntituleActif&& !string.IsNullOrEmpty(PsAddress.Company))
                            ? PsAddress.Company
                            : PsAddress.LastName + " " + PsAddress.FirstName;

                        string CodePrestashop = PsAddress.IDAddress.ToString();
                        Int32  maxlenght      = 32 - CodePrestashop.Length;
                        if (temp.Length > maxlenght)
                        {
                            temp = temp.Substring(0, maxlenght);
                        }
                        temp += " [" + CodePrestashop + "]";
                        F_LIVRAISON.LI_Intitule = temp;
                    }
                    else
                    {
                        F_LIVRAISON.LI_Intitule = Core.Global.GetConfig().ConfigClientNumPrefixe + PsAddress.IDAddress.ToString();
                    }

                    #region Module SoColissimo
                    Model.Prestashop.order_address info_cart    = null;
                    Model.Prestashop.PsSoDelivery  PsSoDelivery = null;
                    if (Core.Global.ExistSoColissimoDeliveryModule() &&
                        Core.Global.GetConfig().ModuleSoColissimoDeliveryActive &&
                        Core.Global.GetConfig().ModuleSoColissimoReplaceAddressNameActive)
                    {
                        Model.Prestashop.PsOrdersRepository   PsOrdersRepository = new Model.Prestashop.PsOrdersRepository();
                        List <Model.Prestashop.order_address> ListAddress        = PsOrdersRepository.ListAddress(Core.Global.CurrentShop.IDShop, PsAddress.IDCustomer);
                        if (ListAddress != null)
                        {
                            info_cart = (from L in ListAddress where L.id_address_delivery == PsAddress.IDAddress orderby L.id_order descending select L).FirstOrDefault();
                            if (info_cart != null)
                            {
                                Model.Prestashop.PsSoDeliveryRepository PsSoDeliveryRepository = new Model.Prestashop.PsSoDeliveryRepository();
                                if (PsSoDeliveryRepository.ExistCart(info_cart.id_cart))
                                {
                                    PsSoDelivery = PsSoDeliveryRepository.ReadCart(info_cart.id_cart);
                                    string temp = (!string.IsNullOrWhiteSpace(PsSoDelivery.LiBelle))
                                        ? PsSoDelivery.LiBelle
                                        : PsSoDelivery.FirstName + " " + PsSoDelivery.LastName
                                                  + (!string.IsNullOrEmpty(PsSoDelivery.Company) ? " " + PsSoDelivery.Company : string.Empty);
                                    //: ((!string.IsNullOrEmpty(PsSoDelivery.Company))
                                    //    ? PsSoDelivery.Company
                                    //        + (!string.IsNullOrEmpty(PsSoDelivery.LastName) ? " " + PsSoDelivery.LastName : string.Empty)
                                    //        + (!string.IsNullOrEmpty(PsSoDelivery.FirstName) ? " " + PsSoDelivery.FirstName : string.Empty)
                                    //    : PsSoDelivery.LastName + " " + PsSoDelivery.FirstName);

                                    string CodePrestashop = PsAddress.IDAddress.ToString();
                                    Int32  maxlenght      = 32 - CodePrestashop.Length;
                                    if (temp.Length > maxlenght)
                                    {
                                        temp = temp.Substring(0, maxlenght);
                                    }
                                    temp += " [" + CodePrestashop + "]";
                                    F_LIVRAISON.LI_Intitule = temp;
                                }
                            }
                        }
                    }
                    #endregion

                    // conversion valeur prestashop
                    string intitule_iso = Core.Global.ConvertUnicodeToISO_8859_1(F_LIVRAISON.LI_Intitule);

                    // <JG> 31/05/2012 Correction adresse livraison existantes
                    Model.Sage.F_LIVRAISONRepository F_LIVRAISONRepository = new Model.Sage.F_LIVRAISONRepository();

                    if (!F_LIVRAISONRepository.ExistComptetIntitule(F_COMPTET.CT_Num, F_LIVRAISON.LI_Intitule) &&
                        !F_LIVRAISONRepository.ExistComptetIntitule(F_COMPTET.CT_Num, intitule_iso) &&
                        (bool)F_LIVRAISON.ExistCT_Num_LI_Intitule(Connexion) == false)
                    {
                        String Adresse2 = string.Empty;
                        if (PsAddress.Address1.Length > 35)
                        {
                            F_LIVRAISON.LI_Adresse = PsAddress.Address1.Substring(0, 35);
                            Adresse2 = PsAddress.Address1.Substring(35);
                        }
                        else
                        {
                            F_LIVRAISON.LI_Adresse = PsAddress.Address1;
                        }
                        if (!string.IsNullOrWhiteSpace(PsAddress.Address2))
                        {
                            Adresse2 += " " + PsAddress.Address2;
                        }

                        F_LIVRAISON.LI_Complement = (Adresse2.Length > 35) ? Adresse2.Substring(0, 35) : Adresse2;
                        F_LIVRAISON.LI_CodePostal = (PsAddress.PostCode.Length > 9) ? PsAddress.PostCode.Substring(0, 9) : PsAddress.PostCode;
                        F_LIVRAISON.LI_Ville      = (PsAddress.City.Length > 35) ? PsAddress.City.Substring(0, 35) : PsAddress.City;

                        Model.Prestashop.PsCountryRepository PsCountryRepository = new Model.Prestashop.PsCountryRepository();
                        if (PsCountryRepository.Exist(PsAddress.IDCountry))
                        {
                            Model.Prestashop.PsCountry  PsCountry        = new Model.Prestashop.PsCountryRepository().Read(PsAddress.IDCountry);
                            Model.Sage.F_PAYSRepository F_PAYSRepository = new Model.Sage.F_PAYSRepository();
                            if (F_PAYSRepository.ExistPaysIso2(PsCountry.IsoCode))
                            {
                                F_LIVRAISON.LI_Pays = new Model.Sage.F_PAYSRepository().ReadPaysIso2(PsCountry.IsoCode).PA_Intitule;
                            }
                            else
                            {
                                Model.Prestashop.PsCountryLangRepository PsCountryLangRepository = new Model.Prestashop.PsCountryLangRepository();
                                if (PsCountryLangRepository.ExistCountryLang(PsAddress.IDCountry, Core.Global.Lang))
                                {
                                    Model.Prestashop.PsCountryLang PsCountryLang = PsCountryLangRepository.ReadCountryLang(PsAddress.IDCountry, Core.Global.Lang);
                                    F_LIVRAISON.LI_Pays = (PsCountryLang.Name.Length > 35) ? PsCountryLang.Name.Substring(0, 35) : PsCountryLang.Name;
                                }
                            }
                        }

                        String Contact = (Core.Global.GetConfig().ConfigClientSocieteIntituleActif&& !string.IsNullOrEmpty(PsAddress.Company))
                            ? PsAddress.LastName + " " + PsAddress.FirstName
                            : (!string.IsNullOrEmpty(PsAddress.Company) ? PsAddress.Company : string.Empty);

                        // SI Module SoColissimo
                        //if (Core.Global.ExistSoColissimoDeliveryModule()
                        //    && Core.Global.GetConfig().ModuleSoColissimoDeliveryActive
                        //    && Core.Global.GetConfig().ModuleSoColissimoReplaceAddressNameActive
                        //    && info_cart != null && PsSoDelivery != null)
                        //{
                        //    Contact = (!string.IsNullOrWhiteSpace(PsSoDelivery.LiBelle))
                        //        ? PsSoDelivery.FirstName + " " + PsSoDelivery.LastName
                        //        : (!string.IsNullOrEmpty(PsSoDelivery.Company) ? PsSoDelivery.Company : string.Empty);
                        //}

                        F_LIVRAISON.LI_Contact = (Contact.Length > 35) ? Contact.Substring(0, 35) : Contact;

                        if (!string.IsNullOrWhiteSpace(PsAddress.Phone))
                        {
                            F_LIVRAISON.LI_Telephone = (PsAddress.Phone.Length > 21) ? PsAddress.Phone.Substring(0, 21) : PsAddress.Phone;
                            // <JG> 17/11/2014 correction si valeur nulle (tests AM)
                            if (!string.IsNullOrWhiteSpace(PsAddress.PhoneMobile))
                            {
                                F_LIVRAISON.LI_Telecopie = (PsAddress.PhoneMobile.Length > 21) ? PsAddress.PhoneMobile.Substring(0, 21) : PsAddress.PhoneMobile;
                            }
                        }
                        else if (!string.IsNullOrWhiteSpace(PsAddress.PhoneMobile))
                        {
                            if (Core.Global.GetConfig().ConfigClientAdresseTelephonePositionFixe)
                            {
                                F_LIVRAISON.LI_Telecopie = (PsAddress.PhoneMobile.Length > 21) ? PsAddress.PhoneMobile.Substring(0, 21) : PsAddress.PhoneMobile;
                            }
                            else
                            {
                                F_LIVRAISON.LI_Telephone = (PsAddress.PhoneMobile.Length > 21) ? PsAddress.PhoneMobile.Substring(0, 21) : PsAddress.PhoneMobile;
                            }
                        }

                        #region Module SoColissimo
                        if (Core.Global.ExistSoColissimoDeliveryModule() &&
                            Core.Global.GetConfig().ModuleSoColissimoDeliveryActive &&
                            Core.Global.GetConfig().ModuleSoColissimoReplacePhoneActive)
                        {
                            if (info_cart == null)
                            {
                                // si info_cart n'a pas déjà été identifié par rapport à l'option intitulé adresse
                                Model.Prestashop.PsOrdersRepository   PsOrdersRepository = new Model.Prestashop.PsOrdersRepository();
                                List <Model.Prestashop.order_address> ListAddress        = PsOrdersRepository.ListAddress(Core.Global.CurrentShop.IDShop, PsAddress.IDCustomer);
                                if (ListAddress != null)
                                {
                                    info_cart = (from L in ListAddress where L.id_address_delivery == PsAddress.IDAddress orderby L.id_order descending select L).FirstOrDefault();
                                }
                            }
                            if (info_cart != null && PsSoDelivery == null)
                            {
                                Model.Prestashop.PsSoDeliveryRepository PsSoDeliveryRepository = new Model.Prestashop.PsSoDeliveryRepository();
                                if (PsSoDeliveryRepository.ExistCart(info_cart.id_cart))
                                {
                                    PsSoDelivery = PsSoDeliveryRepository.ReadCart(info_cart.id_cart);
                                }
                            }
                            if (PsSoDelivery != null)
                            {
                                if (!string.IsNullOrWhiteSpace(PsSoDelivery.Telephone))
                                {
                                    F_LIVRAISON.LI_Telephone = (PsSoDelivery.Telephone.Length > 21) ? PsSoDelivery.Telephone.Substring(0, 21) : PsSoDelivery.Telephone;
                                }
                            }
                        }
                        #endregion

                        Model.Prestashop.PsCustomerRepository PsCustomerRepository = new Model.Prestashop.PsCustomerRepository();
                        if (PsCustomerRepository.ExistCustomer(PsAddress.IDCustomer))
                        {
                            string customer_mail = PsCustomerRepository.ReadCustomer(PsAddress.IDCustomer).Email;
                            F_LIVRAISON.LI_Email = (customer_mail.Length > 69) ? customer_mail.Substring(0, 69) : customer_mail;
                        }


                        Config = new Model.Local.Config();
                        if (ConfigRepository.ExistName(Core.Global.ConfigClientModeExpedition))
                        {
                            Config = ConfigRepository.ReadName(Core.Global.ConfigClientModeExpedition);
                            F_LIVRAISON.N_Expedition = Convert.ToInt32(Config.Con_Value);
                        }
                        Config = new Model.Local.Config();
                        if (ConfigRepository.ExistName(Core.Global.ConfigClientConditionLivraison))
                        {
                            Config = ConfigRepository.ReadName(Core.Global.ConfigClientConditionLivraison);
                            F_LIVRAISON.N_Condition = Convert.ToInt32(Config.Con_Value);
                        }

                        if (F_LIVRAISONRepository.ExistComptetPrincipal(F_COMPTET.CT_Num, 1))
                        {
                            F_LIVRAISON.LI_Principal = ABSTRACTION_SAGE.F_LIVRAISON.Obj._Enum_LI_Principal.Non_Principal;
                        }
                        else
                        {
                            F_LIVRAISON.LI_Principal = ABSTRACTION_SAGE.F_LIVRAISON.Obj._Enum_LI_Principal.Lieu_Principal;
                        }

                        // <JG> 03/06/2016 Ajout mise des infos en majuscule via option
                        if (Core.Global.GetConfig().ConfigClientInfosMajusculeActif)
                        {
                            F_LIVRAISON.LI_Intitule   = F_LIVRAISON.LI_Intitule.ToUpper();
                            F_LIVRAISON.LI_Adresse    = F_LIVRAISON.LI_Adresse.ToUpper();
                            F_LIVRAISON.LI_Complement = F_LIVRAISON.LI_Complement.ToUpper();
                            F_LIVRAISON.LI_CodePostal = F_LIVRAISON.LI_CodePostal.ToUpper();
                            F_LIVRAISON.LI_Ville      = F_LIVRAISON.LI_Ville.ToUpper();
                            F_LIVRAISON.LI_Pays       = F_LIVRAISON.LI_Pays.ToUpper();
                            F_LIVRAISON.LI_Contact    = F_LIVRAISON.LI_Contact.ToUpper();
                        }

                        // sinon absence de mode d'expédition par défaut ou  de conditions de livraison par défaut blocage de l'insertion sinon erreur ODBC
                        if (F_LIVRAISON.N_Expedition == 0 || F_LIVRAISON.N_Condition == 0)
                        {
                            Core.Log.WriteLog("[SYNCHRO_ADRESSE_23] Mode d'expédition par défaut et/ou Conditions de livraison par défaut non définies. Impossible d'ajouter l'adresse de livraison !", true);
                        }
                        // si paramètres obligatoires en création renseignés -> ajout de l'adresse
                        else
                        {
                            F_LIVRAISON.Add(Connexion);

                            // <JG> 17/02/2017 traitement déplacé dans la création de la fiche client
                            // obsolète en V8 puisque l'ODBC ajoute en auto l'adresse de livraison par défaut
                            //if (F_LIVRAISON.LI_Principal == ABSTRACTION_SAGE.F_LIVRAISON.Obj._Enum_LI_Principal.Lieu_Principal)
                            //{
                            //    ABSTRACTION_SAGE.F_COMPTET.Obj ObjF_COMPTET = new ABSTRACTION_SAGE.F_COMPTET.Obj();
                            //    ObjF_COMPTET.CT_Num = F_COMPTET.CT_Num;
                            //    ObjF_COMPTET.ReadCT_Num(Connexion, false);
                            //    ObjF_COMPTET.CT_Adresse = F_LIVRAISON.LI_Adresse;
                            //    ObjF_COMPTET.CT_Complement = F_LIVRAISON.LI_Complement;
                            //    ObjF_COMPTET.CT_CodePostal = F_LIVRAISON.LI_CodePostal;
                            //    ObjF_COMPTET.CT_Ville = F_LIVRAISON.LI_Ville;
                            //    ObjF_COMPTET.CT_Pays = F_LIVRAISON.LI_Pays;
                            //    ObjF_COMPTET.CT_Contact = F_LIVRAISON.LI_Contact;
                            //    ObjF_COMPTET.CT_Telephone = F_LIVRAISON.LI_Telephone;
                            //    ObjF_COMPTET.CT_Telecopie = F_LIVRAISON.LI_Telecopie;

                            //    string tva = !string.IsNullOrWhiteSpace(PsAddress.VatNumber) ? PsAddress.VatNumber : string.Empty;
                            //    if (tva.Length > 25)
                            //        tva = tva.Replace(" ", "");
                            //    ObjF_COMPTET.CT_Identifiant = (tva.Length > 25) ? tva.Substring(0, 25) : tva;

                            //    ObjF_COMPTET.Update(Connexion);
                            //}

                            if (Core.Global.GetConfig().ConfigClientNIFActif&& string.IsNullOrWhiteSpace(F_COMPTET.CT_Siret))
                            {
                                try
                                {
                                    string dni = !string.IsNullOrWhiteSpace(PsAddress.DNi) ? PsAddress.DNi.Replace(" ", "") : string.Empty;
                                    Connexion.Request = "UPDATE F_COMPTET SET CT_Siret='" + ((dni.Length > 15) ? dni.Substring(0, 15) : dni)
                                                        + "' WHERE CT_Num='" + F_COMPTET.CT_Num + "'";
                                    Connexion.Exec_Request();
                                }
                                catch (Exception ex)
                                {
                                    Core.Error.SendMailError("Erreur insertion numéro d'identification fiscale !<br/>" + ex.ToString());
                                }
                            }
                        }
                    }
                    if (!F_LIVRAISONRepository.ExistComptetIntitule(F_COMPTET.CT_Num, F_LIVRAISON.LI_Intitule) &&
                        F_LIVRAISON.LI_Intitule != intitule_iso &&
                        (bool)F_LIVRAISON.ExistCT_Num_LI_Intitule(Connexion) == true)
                    {
                        F_LIVRAISON.ReadCT_Num_LI_Intitule(Connexion);
                        F_LIVRAISON.LI_Intitule = intitule_iso;
                        F_LIVRAISON.Update(Connexion);
                    }

                    if (F_LIVRAISONRepository.ExistComptetIntitule(F_COMPTET.CT_Num, F_LIVRAISON.LI_Intitule))
                    {
                        Model.Sage.F_LIVRAISON F_LIVRAISONUpdate = F_LIVRAISONRepository.ReadComptetIntitule(F_COMPTET.CT_Num, F_LIVRAISON.LI_Intitule);
                        Model.Local.Address    Address           = new Model.Local.Address();
                        Address.Pre_Id = Convert.ToInt32(PsAddress.IDAddress);

                        // <JG> 08/11/2012 suppression de l'ancienne occurence si l'adresse a été supprimée de Sage
                        // =>> clé primaire sur les 2 ID, update impossible
                        if (AddressRepository.ExistPrestashop(Address.Pre_Id))
                        {
                            Address = AddressRepository.ReadPrestashop(Address.Pre_Id);
                            AddressRepository.Delete(Address);
                            Address        = new Model.Local.Address();
                            Address.Pre_Id = Convert.ToInt32(PsAddress.IDAddress);
                        }
                        Address.Sag_Id   = F_LIVRAISONUpdate.cbMarq;
                        Address.Add_Date = (PsAddress.DateUpd != null && PsAddress.DateUpd > new DateTime(1753, 1, 2)) ? PsAddress.DateUpd : DateTime.Now.Date;
                        AddressRepository.Add(Address);
                    }

                    Core.Temp.ListAddressOnCurrentSync.Add(PsAddress.IDAddress);
                }
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError(ex.ToString());
            }
        }
        // <JG> 08/11/2012 Correction mise-à-jour adresses de livraisons
        private void UpdateDistantToLocal(Model.Local.Customer Customer, Model.Prestashop.PsAddress PsAddress, ABSTRACTION_SAGE.ALTERNETIS.Connexion Connexion, Model.Local.Address Address)
        {
            try
            {
                Model.Sage.F_COMPTETRepository F_COMPTERepository = new Model.Sage.F_COMPTETRepository();
                if (F_COMPTERepository.ExistId(Customer.Sag_Id))
                {
                    ABSTRACTION_SAGE.F_LIVRAISON.Obj F_LIVRAISONUpdate = new ABSTRACTION_SAGE.F_LIVRAISON.Obj();
                    Model.Sage.F_COMPTET             F_COMPTET         = F_COMPTERepository.Read(Customer.Sag_Id);
                    F_LIVRAISONUpdate.CT_Num = F_COMPTET.CT_Num;

                    Model.Sage.F_LIVRAISONRepository F_LIVRAISONRepository = new Model.Sage.F_LIVRAISONRepository();
                    F_LIVRAISONUpdate.LI_No = (F_LIVRAISONRepository.ExistId(Address.Sag_Id) ? F_LIVRAISONRepository.ReadId(Address.Sag_Id).LI_No : 0);

                    if ((Boolean)F_LIVRAISONUpdate.ExistCT_Num_LI_No(Connexion))
                    {
                        F_LIVRAISONUpdate.ReadCT_Num_LI_No(Connexion, false);

                        // gestion de l'intitulé
                        Model.Local.ConfigRepository ConfigRepository = new Model.Local.ConfigRepository();
                        Model.Local.Config           Config           = new Model.Local.Config();

                        // <JG> 07/09/2012 Modification gestion adresse livraison
                        if (ConfigRepository.ExistName(Core.Global.ConfigClientIntituleAdresse) &&
                            ConfigRepository.ReadName(Core.Global.ConfigClientIntituleAdresse).Con_Value == Core.Global.ConfigClientIntituleAdresseEnum.NomPrenomPrestashop.ToString())
                        {
                            string temp = (Core.Global.GetConfig().ConfigClientSocieteIntituleActif&& !string.IsNullOrEmpty(PsAddress.Company))
                            ? PsAddress.Company
                            : PsAddress.LastName + " " + PsAddress.FirstName;

                            string CodePrestashop = PsAddress.IDAddress.ToString();
                            Int32  maxlenght      = 32 - CodePrestashop.Length;
                            if (temp.Length > maxlenght)
                            {
                                temp = temp.Substring(0, maxlenght);
                            }
                            temp += " [" + CodePrestashop + "]";
                            F_LIVRAISONUpdate.LI_Intitule = temp;
                        }
                        else
                        {
                            F_LIVRAISONUpdate.LI_Intitule = Core.Global.GetConfig().ConfigClientNumPrefixe + PsAddress.IDAddress.ToString();
                        }

                        String Adresse2 = string.Empty;
                        if (PsAddress.Address1.Length > 35)
                        {
                            F_LIVRAISONUpdate.LI_Adresse = PsAddress.Address1.Substring(0, 35);
                            Adresse2 = PsAddress.Address1.Substring(35);
                        }
                        else
                        {
                            F_LIVRAISONUpdate.LI_Adresse = PsAddress.Address1;
                        }
                        if (!string.IsNullOrWhiteSpace(PsAddress.Address2))
                        {
                            Adresse2 += PsAddress.Address2;
                        }

                        F_LIVRAISONUpdate.LI_Complement = (Adresse2.Length > 35) ? Adresse2.Substring(0, 35) : Adresse2;
                        F_LIVRAISONUpdate.LI_CodePostal = (PsAddress.PostCode.Length > 9) ? PsAddress.PostCode.Substring(0, 9) : PsAddress.PostCode;
                        F_LIVRAISONUpdate.LI_Ville      = (PsAddress.City.Length > 35) ? PsAddress.City.Substring(0, 35) : PsAddress.City;

                        Model.Prestashop.PsCountryLangRepository PsCountryLangRepository = new Model.Prestashop.PsCountryLangRepository();
                        if (PsCountryLangRepository.ExistCountryLang(PsAddress.IDCountry, Core.Global.Lang))
                        {
                            Model.Prestashop.PsCountryLang PsCountryLang = PsCountryLangRepository.ReadCountryLang(PsAddress.IDCountry, Core.Global.Lang);
                            F_LIVRAISONUpdate.LI_Pays = (PsCountryLang.Name.Length > 35) ? PsCountryLang.Name.Substring(0, 35) : PsCountryLang.Name;
                        }

                        String Contact = (Core.Global.GetConfig().ConfigClientSocieteIntituleActif&& !string.IsNullOrEmpty(PsAddress.Company))
                            ? PsAddress.LastName + " " + PsAddress.FirstName
                            : (!string.IsNullOrEmpty(PsAddress.Company) ? PsAddress.Company : string.Empty);
                        F_LIVRAISONUpdate.LI_Contact = (Contact.Length > 35) ? Contact.Substring(0, 35) : Contact;

                        if (!string.IsNullOrWhiteSpace(PsAddress.Phone))
                        {
                            F_LIVRAISONUpdate.LI_Telephone = (PsAddress.Phone.Length > 21) ? PsAddress.Phone.Substring(0, 21) : PsAddress.Phone;
                            // <JG> 17/11/2014 correction si valeur nulle (tests AM)
                            if (!string.IsNullOrWhiteSpace(PsAddress.PhoneMobile))
                            {
                                F_LIVRAISONUpdate.LI_Telecopie = (PsAddress.PhoneMobile.Length > 21) ? PsAddress.PhoneMobile.Substring(0, 21) : PsAddress.PhoneMobile;
                            }
                        }
                        else if (!string.IsNullOrWhiteSpace(PsAddress.PhoneMobile))
                        {
                            if (Core.Global.GetConfig().ConfigClientAdresseTelephonePositionFixe)
                            {
                                F_LIVRAISONUpdate.LI_Telecopie = (PsAddress.PhoneMobile.Length > 21) ? PsAddress.PhoneMobile.Substring(0, 21) : PsAddress.PhoneMobile;
                            }
                            else
                            {
                                F_LIVRAISONUpdate.LI_Telephone = (PsAddress.PhoneMobile.Length > 21) ? PsAddress.PhoneMobile.Substring(0, 21) : PsAddress.PhoneMobile;
                            }
                        }

                        Model.Prestashop.PsCustomerRepository PsCustomerRepository = new Model.Prestashop.PsCustomerRepository();
                        if (PsCustomerRepository.ExistCustomer(PsAddress.IDCustomer))
                        {
                            string customer_mail = PsCustomerRepository.ReadCustomer(PsAddress.IDCustomer).Email;
                            F_LIVRAISONUpdate.LI_Email = (customer_mail.Length > 69) ? customer_mail.Substring(0, 69) : customer_mail;
                        }

                        // <JG> 03/06/2016 Ajout mise des infos en majuscule via option
                        if (Core.Global.GetConfig().ConfigClientInfosMajusculeActif)
                        {
                            F_LIVRAISONUpdate.LI_Intitule   = F_LIVRAISONUpdate.LI_Intitule.ToUpper();
                            F_LIVRAISONUpdate.LI_Adresse    = F_LIVRAISONUpdate.LI_Adresse.ToUpper();
                            F_LIVRAISONUpdate.LI_Complement = F_LIVRAISONUpdate.LI_Complement.ToUpper();
                            F_LIVRAISONUpdate.LI_CodePostal = F_LIVRAISONUpdate.LI_CodePostal.ToUpper();
                            F_LIVRAISONUpdate.LI_Ville      = F_LIVRAISONUpdate.LI_Ville.ToUpper();
                            F_LIVRAISONUpdate.LI_Pays       = F_LIVRAISONUpdate.LI_Pays.ToUpper();
                            F_LIVRAISONUpdate.LI_Contact    = F_LIVRAISONUpdate.LI_Contact.ToUpper();
                        }

                        F_LIVRAISONUpdate.Update(Connexion);
                    }
                }

                Core.Temp.ListAddressOnCurrentSync.Add(PsAddress.IDAddress);
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError(ex.ToString());
            }
        }
        public void LoadControleEncours(Model.Sage.F_COMPTET F_COMPTET, out Decimal Encours)
        {
            Model.Sage.P_CRISQUE._Enum_R_Type EtatControle = Model.Sage.P_CRISQUE._Enum_R_Type.Livraison;
            Decimal Portefeuille   = 0,
                    SoldeComptable = 0;

            Encours = 0;

            if (F_COMPTET.CT_ControlEnc == null)
            {
                // pas d'action = livraison
            }
            else if (F_COMPTET.CT_ControlEnc == (short)ABSTRACTION_SAGE.F_COMPTET.Obj._Enum_CT_ControlEnc.Compte_Bloque)
            {
                EtatControle = Model.Sage.P_CRISQUE._Enum_R_Type.Blocage;
            }
            // si compte client en "controle automatique" ou "selon code risque" alors
            else
            {
                Model.Sage.P_CRISQUE           P_CRISQUE;
                Model.Sage.P_CRISQUERepository P_CRISQUERepository = new Model.Sage.P_CRISQUERepository();
                if (P_CRISQUERepository.ExistCRisque(F_COMPTET.N_Risque.Value))
                {
                    P_CRISQUE = P_CRISQUERepository.ReadCRisque(F_COMPTET.N_Risque.Value);

                    if (P_CRISQUE.R_Type != null)
                    {
                        switch (P_CRISQUE.R_Type)
                        {
                        case (short)Model.Sage.P_CRISQUE._Enum_R_Type.Livraison:
                            // aucun blocage
                            break;

                        case (short)Model.Sage.P_CRISQUE._Enum_R_Type.Surveillance:
                        case (short)Model.Sage.P_CRISQUE._Enum_R_Type.Blocage:

                            // récupération du montant d'encours
                            Model.Sage.DP_ENCOURSTIERSRepository DP_ENCOURSTIERSRepository = new Model.Sage.DP_ENCOURSTIERSRepository();
                            Model.Sage.DP_ENCOURSTIERS           DP_ENCOURSTIERS           = DP_ENCOURSTIERSRepository.ReadTiers(F_COMPTET.CT_Num, DebutExo, FinExo);
                            Decimal LimiteTiers = 0;
                            //Decimal DepassementMax = 0;
                            //Decimal DepassementMini = 0;
                            if (F_COMPTET.CT_Encours != null)
                            {
                                LimiteTiers = (Decimal)F_COMPTET.CT_Encours;
                            }
                            //if(P_CRISQUE.R_Min != null)
                            //{
                            //    DepassementMini = (Decimal)P_CRISQUE.R_Min;
                            //}
                            //if(P_CRISQUE.R_Max != null)
                            //{
                            //    DepassementMax = (Decimal)P_CRISQUE.R_Max;
                            //}
                            Model.Sage.DP_PORTEFEUILLEVENTERepository DP_PORTEFEUILLEVENTRepository = new Model.Sage.DP_PORTEFEUILLEVENTERepository();

                            Model.Sage.DP_PORTEFEUILLEVENTE DP_PORTEFEUILLEVENTE = DP_PORTEFEUILLEVENTRepository.ReadTiers(F_COMPTET.CT_Num, ParametrePortefeuille);
                            Portefeuille = DP_PORTEFEUILLEVENTE.MontantPortefeuille;

                            SoldeComptable = DP_ENCOURSTIERS.SoldeComptable;

                            Encours = SoldeComptable + Portefeuille;
                            //NouvelEncours = SoldeComptable + MontantDocument;
                            //Depassement = NouvelEncours - LimiteTiers;
                            if (Encours >= LimiteTiers)
                            {
                                if (P_CRISQUE.R_Type == (short)Model.Sage.P_CRISQUE._Enum_R_Type.Surveillance)
                                {
                                    EtatControle = Model.Sage.P_CRISQUE._Enum_R_Type.Surveillance;
                                }
                                else if (P_CRISQUE.R_Type == (short)Model.Sage.P_CRISQUE._Enum_R_Type.Blocage)
                                {
                                    EtatControle = Model.Sage.P_CRISQUE._Enum_R_Type.Blocage;
                                }
                            }
                            break;
                        }
                    }
                }
            }
            F_COMPTET.EtatControleEncours = EtatControle;
        }
        public void Exec(Model.Local.Customer Customer, out List <String> log_out)
        {
            logs = new List <string>();
            //logs.Add("Client ps " + Customer.Pre_Id.ToString() + " / sage " + Customer.Sag_Id.ToString());
            try
            {
                if (Core.Global.GetConfig().ModuleAECCustomerOutstandingActif&& Core.Global.ExistAECCustomerOutstandingModule())
                {
                    //logs.Add("module encours actif");
                    Model.Sage.F_COMPTETRepository        F_COMPTETRepository  = new Model.Sage.F_COMPTETRepository();
                    Model.Prestashop.PsCustomerRepository PsCustomerRepository = new Model.Prestashop.PsCustomerRepository();

                    if (!F_COMPTETRepository.ExistId(Customer.Sag_Id))
                    {
                        logs.Add("TEC10- Client Sage introuvable à partir du l'identifiant " + Customer.Sag_Id.ToString() + " !");
                    }
                    else if (!PsCustomerRepository.ExistCustomer((uint)Customer.Pre_Id))
                    {
                        logs.Add("TEC11- Client PrestaShop introuvable à partir de l'identifiant " + Customer.Pre_Id.ToString() + " !");
                    }
                    else
                    {
                        //logs.Add("données client récupérées");
                        List <string> log = new List <string>();
                        if (current_exercice(out DebutExo, out FinExo))
                        {
                            //logs.Add("Exercice " + DebutExo.ToShortDateString() + " / " + FinExo.Date.ToShortDateString());
                            if (ParametrePortefeuille == Core.Parametres.P_BaseEncours.NonDefini)
                            {
                                read_param_portefeuille();
                            }

                            //logs.Add("Paramètre portefeuille " + ParametrePortefeuille.ToString());

                            Model.Sage.F_COMPTET F_COMPTET = F_COMPTETRepository.Read(Customer.Sag_Id);

                            Decimal EncoursAutorise = 0;
                            Decimal EncoursUtilise;
                            LoadControleEncours(F_COMPTET, out EncoursUtilise);


                            //logs.Add("client : " + F_COMPTET.CT_Num
                            //+ " / type encours " + F_COMPTET.EtatControleEncours.ToString()
                            //+ " / autorisé " + EncoursAutorise
                            //+ " / utilisé " + EncoursUtilise);

                            switch (F_COMPTET.EtatControleEncours)
                            {
                            case PRESTACONNECT.Model.Sage.P_CRISQUE._Enum_R_Type.Livraison:
                                EncoursAutorise = (F_COMPTET.CT_Encours != null) ? F_COMPTET.CT_Encours.Value : 0;
                                break;

                            case PRESTACONNECT.Model.Sage.P_CRISQUE._Enum_R_Type.Surveillance:
                            case PRESTACONNECT.Model.Sage.P_CRISQUE._Enum_R_Type.Blocage:
                                if (F_COMPTET.CT_ControlEnc == (short)ABSTRACTION_SAGE.F_COMPTET.Obj._Enum_CT_ControlEnc.Compte_Bloque)
                                {
                                    EncoursAutorise = 0;
                                }
                                else
                                {
                                    EncoursAutorise = (F_COMPTET.CT_Encours != null) ? F_COMPTET.CT_Encours.Value : 0;
                                }
                                break;
                            }

                            #region Saisie PrestaShop

                            Model.Prestashop.PsCustomer PsCustomer = PsCustomerRepository.ReadCustomer((uint)Customer.Pre_Id);
                            PsCustomer.OutstandingAllowAmount = EncoursAutorise;
                            PsCustomerRepository.Save();

                            Model.Prestashop.PsAECCustomerOutstandingRepository PsAECCustomerOutstandingRepository = new Model.Prestashop.PsAECCustomerOutstandingRepository();
                            Model.Prestashop.PsAEcCustomerOutstanding           encours_client;
                            if (PsAECCustomerOutstandingRepository.ExistCustomer(PsCustomer.IDCustomer))
                            {
                                encours_client = PsAECCustomerOutstandingRepository.ReadCustomer(PsCustomer.IDCustomer);
                                encours_client.EncoursActuelSage = EncoursUtilise;
                                PsAECCustomerOutstandingRepository.Save();
                            }
                            else
                            {
                                PsAECCustomerOutstandingRepository.Add(new Model.Prestashop.PsAEcCustomerOutstanding()
                                {
                                    IDCustomer        = PsCustomer.IDCustomer,
                                    EncoursActuelSage = EncoursUtilise,
                                });
                                if (log != null && log.Count > 0)
                                {
                                    logs.AddRange(log);
                                }
                            }

                            #endregion
                        }
                        if (log.Count > 0)
                        {
                            logs.AddRange(log);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError("TEC01- Une erreur est survenue : " + ex.ToString());
            }
            finally
            {
                log_out = logs;
            }
        }
Exemplo n.º 11
0
        public void Exec(Int32 SageClientSend)
        {
            try
            {
                if (Core.Global.GetConfig().StatInfolibreClientActif)
                {
                    Model.Local.CustomerRepository CustomerRepository = new Model.Local.CustomerRepository();
                    if (CustomerRepository.ExistSage(SageClientSend))
                    {
                        Model.Local.Customer           Customer            = CustomerRepository.ReadSage(SageClientSend);
                        Model.Sage.F_COMPTETRepository F_COMPTETRepository = new Model.Sage.F_COMPTETRepository();
                        if (F_COMPTETRepository.ExistId(Customer.Sag_Id))
                        {
                            Model.Sage.F_COMPTET F_COMPTET = F_COMPTETRepository.Read(Customer.Sag_Id);

                            #region Informations libre client

                            Model.Local.InformationLibreClientRepository InformationLibreClientRepository = new Model.Local.InformationLibreClientRepository();
                            foreach (Model.Local.InformationLibreClient InformationLibreClient in InformationLibreClientRepository.ListSync())
                            {
                                Model.Sage.cbSysLibreRepository.CB_Type TypeInfoLibre = new Model.Sage.cbSysLibreRepository().ReadTypeInformationLibre(InformationLibreClient.Sag_InfoLibreClient, Model.Sage.cbSysLibreRepository.CB_File.F_COMPTET);
                                UInt32 IDCustomerFeatureValue = 0;
                                switch (TypeInfoLibre)
                                {
                                case PRESTACONNECT.Model.Sage.cbSysLibreRepository.CB_Type.SageText:
                                case PRESTACONNECT.Model.Sage.cbSysLibreRepository.CB_Type.SageTable:
                                    #region text
                                    if (F_COMPTETRepository.ExistArticleInformationLibreText(InformationLibreClient.Sag_InfoLibreClient, F_COMPTET.CT_Num) &&
                                        !string.IsNullOrWhiteSpace(Core.Global.SageValueReplacement(F_COMPTETRepository.ReadArticleInformationLibreText(InformationLibreClient.Sag_InfoLibreClient, F_COMPTET.CT_Num))))
                                    {
                                        IDCustomerFeatureValue = CreateCustomerFeatureValue(Core.Global.SageValueReplacement(F_COMPTETRepository.ReadArticleInformationLibreText(InformationLibreClient.Sag_InfoLibreClient, F_COMPTET.CT_Num)), (uint)InformationLibreClient.Cha_Id, InformationLibreClient.Inf_Mode);
                                    }
                                    AssociateCustomerFeatureValueWithCustomer((uint)InformationLibreClient.Cha_Id, (uint)Customer.Pre_Id, IDCustomerFeatureValue);
                                    #endregion
                                    break;

                                case PRESTACONNECT.Model.Sage.cbSysLibreRepository.CB_Type.SageValeur:
                                case PRESTACONNECT.Model.Sage.cbSysLibreRepository.CB_Type.SageMontant:
                                    #region decimal
                                    if (F_COMPTETRepository.ExistArticleInformationLibreNumerique(InformationLibreClient.Sag_InfoLibreClient, F_COMPTET.CT_Num) &&
                                        F_COMPTETRepository.ReadArticleInformationLibreNumerique(InformationLibreClient.Sag_InfoLibreClient, F_COMPTET.CT_Num) != null)
                                    {
                                        IDCustomerFeatureValue = CreateCustomerFeatureValue(Core.Global.SageValueReplacement(F_COMPTETRepository.ReadArticleInformationLibreNumerique(InformationLibreClient.Sag_InfoLibreClient, F_COMPTET.CT_Num).ToString()), (uint)InformationLibreClient.Cha_Id, InformationLibreClient.Inf_Mode);
                                    }
                                    AssociateCustomerFeatureValueWithCustomer((uint)InformationLibreClient.Cha_Id, (uint)Customer.Pre_Id, IDCustomerFeatureValue);
                                    #endregion
                                    break;

                                case PRESTACONNECT.Model.Sage.cbSysLibreRepository.CB_Type.SageDate:
                                case PRESTACONNECT.Model.Sage.cbSysLibreRepository.CB_Type.SageSmallDate:
                                    #region datetime
                                    if (F_COMPTETRepository.ExistArticleInformationLibreDate(InformationLibreClient.Sag_InfoLibreClient, F_COMPTET.CT_Num) &&
                                        F_COMPTETRepository.ReadArticleInformationLibreDate(InformationLibreClient.Sag_InfoLibreClient, F_COMPTET.CT_Num) != null)
                                    {
                                        IDCustomerFeatureValue = CreateCustomerFeatureValue(Core.Global.SageValueReplacement(F_COMPTETRepository.ReadArticleInformationLibreDate(InformationLibreClient.Sag_InfoLibreClient, F_COMPTET.CT_Num).ToString()), (uint)InformationLibreClient.Cha_Id, InformationLibreClient.Inf_Mode);
                                    }
                                    AssociateCustomerFeatureValueWithCustomer((uint)InformationLibreClient.Cha_Id, (uint)Customer.Pre_Id, IDCustomerFeatureValue);
                                    #endregion
                                    break;

                                case PRESTACONNECT.Model.Sage.cbSysLibreRepository.CB_Type.Deleted:
                                default:
                                    break;
                                }
                            }

                            #endregion

                            #region Statistiques client

                            Model.Local.StatistiqueClientRepository StatistiqueClientRepository = new Model.Local.StatistiqueClientRepository();
                            foreach (Model.Local.StatistiqueClient StatistiqueClient in StatistiqueClientRepository.ListSync())
                            {
                                Model.Sage.P_STATISTIQUERepository P_STATISTIQUERepository = new Model.Sage.P_STATISTIQUERepository();
                                if (P_STATISTIQUERepository.ExistStatClient(StatistiqueClient.Sag_StatClient))
                                {
                                    Model.Sage.P_STATISTIQUE P_STATISTIQUE = P_STATISTIQUERepository.ReadStatClient(StatistiqueClient.Sag_StatClient);
                                    String stat_value = null;
                                    switch (P_STATISTIQUE.cbMarq)
                                    {
                                    case 1:
                                        stat_value = F_COMPTET.CT_Statistique01;
                                        break;

                                    case 2:
                                        stat_value = F_COMPTET.CT_Statistique02;
                                        break;

                                    case 3:
                                        stat_value = F_COMPTET.CT_Statistique03;
                                        break;

                                    case 4:
                                        stat_value = F_COMPTET.CT_Statistique04;
                                        break;

                                    case 5:
                                        stat_value = F_COMPTET.CT_Statistique05;
                                        break;

                                    case 6:
                                        stat_value = F_COMPTET.CT_Statistique06;
                                        break;

                                    case 7:
                                        stat_value = F_COMPTET.CT_Statistique07;
                                        break;

                                    case 8:
                                        stat_value = F_COMPTET.CT_Statistique08;
                                        break;

                                    case 9:
                                        stat_value = F_COMPTET.CT_Statistique09;
                                        break;

                                    case 10:
                                        stat_value = F_COMPTET.CT_Statistique10;
                                        break;
                                    }
                                    UInt32 IDCustomerFeatureValue = 0;
                                    if (!String.IsNullOrWhiteSpace(stat_value))
                                    {
                                        IDCustomerFeatureValue = CreateCustomerFeatureValue(Core.Global.SageValueReplacement(stat_value), (uint)StatistiqueClient.Cha_Id, StatistiqueClient.Inf_Mode);
                                    }
                                    AssociateCustomerFeatureValueWithCustomer((uint)StatistiqueClient.Cha_Id, (uint)Customer.Pre_Id, IDCustomerFeatureValue);
                                }
                            }

                            #endregion
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError(ex.ToString());
            }
        }