public void Sync(Model.Local.Customer Customer)
        {
            this.Semaphore.WaitOne();

            try
            {
                #region Module CustomerInfo
                if (Core.Global.ExistCustomerInfoModule())
                {
                    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) && PsCustomerRepository.ExistCustomer((uint)Customer.Pre_Id))
                    {
                        Model.Sage.F_COMPTET        F_COMPTET   = F_COMPTETRepository.Read(Customer.Sag_Id);
                        Model.Prestashop.PsCustomer PsCustomer  = PsCustomerRepository.ReadCustomer((uint)Customer.Pre_Id);
                        Core.Module.CustomerInfo    gestioninfo = new Core.Module.CustomerInfo();
                        gestioninfo.Exec(F_COMPTET, PsCustomer);
                    }
                }
                #endregion
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError(ex.ToString());
            }
            lock (this)
            {
                this.CurrentCount += 1;
            }
            this.ReportProgress(this.CurrentCount * 100 / this.ListCount);
            this.Semaphore.Release();
        }
Ejemplo n.º 2
0
        public void Sync(Model.Local.Customer Customer)
        {
            this.Semaphore.WaitOne();

            try
            {
                Model.Sage.F_COMPTETRepository F_COMPTETRepository = new Model.Sage.F_COMPTETRepository();

                if (F_COMPTETRepository.ExistId(Customer.Sag_Id))
                {
                    Model.Sage.F_COMPTET F_COMPTET = new Model.Sage.F_COMPTET();
                    Model.Prestashop.PsAECCustomerPayementRepository PsAECPayementRepository = new Model.Prestashop.PsAECCustomerPayementRepository();
                    Model.Prestashop.PsAEcCustomerPayement           PsAEcPayement           = new Model.Prestashop.PsAEcCustomerPayement();
                    F_COMPTET = F_COMPTETRepository.Read(Customer.Sag_Id);
                    List <Model.Sage.F_REGLEMENTT> ListF_REGLEMENTT = new Model.Sage.F_REGLEMENTTRepository().ListCLient(F_COMPTET.CT_Num);

                    // <JG> 05/03/2015 ajout suppression de prestashop ni modèle n'existe plus dans Sage
                    IQueryable <Model.Prestashop.PsAEcCustomerPayement> ListCustomerPayement = PsAECPayementRepository.ListCustomer((uint)Customer.Pre_Id);

                    foreach (Model.Prestashop.PsAEcCustomerPayement PsAEcCustomerPayement in ListCustomerPayement)
                    {
                        if (ListF_REGLEMENTT.Count(rg => rg.cbMarq == (int)PsAEcCustomerPayement.IDSage) == 0)
                        {
                            PsAECPayementRepository.Delete(PsAEcCustomerPayement);
                        }
                    }

                    foreach (Model.Sage.F_REGLEMENTT F_REGLEMENTT in ListF_REGLEMENTT)
                    {
                        PsAEcPayement           = new Model.Prestashop.PsAEcCustomerPayement();
                        PsAECPayementRepository = new Model.Prestashop.PsAECCustomerPayementRepository();

                        if (PsAECPayementRepository.ExistCustomerPayement((uint)Customer.Pre_Id, (uint)F_REGLEMENTT.cbMarq))
                        {
                            PsAEcPayement          = PsAECPayementRepository.ReadCustomerPayement((uint)Customer.Pre_Id, (uint)F_REGLEMENTT.cbMarq);
                            PsAEcPayement.Payement = ReadPayement(F_REGLEMENTT.cbMarq);
                            PsAECPayementRepository.Save();
                        }
                        else
                        {
                            PsAEcPayement.IDCustomer = (uint)Customer.Pre_Id;
                            PsAEcPayement.IDSage     = (uint)F_REGLEMENTT.cbMarq;
                            PsAEcPayement.Payement   = ReadPayement(F_REGLEMENTT.cbMarq);
                            PsAECPayementRepository.Add(PsAEcPayement);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError(ex.ToString());
            }
            lock (this)
            {
                this.CurrentCount += 1;
            }
            this.ReportProgress(this.CurrentCount * 100 / this.ListCount);
            this.Semaphore.Release();
        }
        public void Sync(Model.Local.Customer Customer)
        {
            this.Semaphore.WaitOne();

            try
            {
                Model.Sage.F_COMPTETRepository F_COMPTETRepository = new Model.Sage.F_COMPTETRepository();
                if (F_COMPTETRepository.ExistId(Customer.Sag_Id))
                {
                    Model.Sage.F_COMPTET F_COMPTET = new Model.Sage.F_COMPTET();

                    F_COMPTET = F_COMPTETRepository.Read(Customer.Sag_Id);
                    if (F_COMPTET.F_COLLABORATEUR != null && F_COMPTET.F_COLLABORATEUR.CO_No.HasValue)
                    {
                        Model.Prestashop.PsAECRepresentativeRepository PsAECRepresentativeRepository = new Model.Prestashop.PsAECRepresentativeRepository();
                        if (PsAECRepresentativeRepository.ExistSage((uint)F_COMPTET.F_COLLABORATEUR.CO_No))
                        {
                            Model.Prestashop.PsAEcRepresentative PsAECRepresentative = PsAECRepresentativeRepository.ReadSage((uint)F_COMPTET.F_COLLABORATEUR.CO_No);

                            Model.Prestashop.PsAECRepresentativeCustomerRepository PsAECRepresentativeCustomerRepository = new Model.Prestashop.PsAECRepresentativeCustomerRepository();
                            Model.Prestashop.PsAEcRepresentativeCustomer           PsAEcRepresentativeCustomer           = new Model.Prestashop.PsAEcRepresentativeCustomer();

                            if (PsAECRepresentativeCustomerRepository.Exist((uint)Customer.Pre_Id))
                            {
                                PsAEcRepresentativeCustomer = PsAECRepresentativeCustomerRepository.Read((uint)Customer.Pre_Id);
                                PsAEcRepresentativeCustomer.IDRepresentative = PsAECRepresentative.IDRepresentative;
                                PsAECRepresentativeCustomerRepository.Save();
                            }
                            else
                            {
                                PsAEcRepresentativeCustomer                  = new Model.Prestashop.PsAEcRepresentativeCustomer();
                                PsAEcRepresentativeCustomer.IDCustomer       = (uint)Customer.Pre_Id;
                                PsAEcRepresentativeCustomer.IDRepresentative = PsAECRepresentative.IDRepresentative;
                                PsAECRepresentativeCustomerRepository.Add(PsAEcRepresentativeCustomer);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError(ex.ToString());
            }
            lock (this)
            {
                this.CurrentCount += 1;
            }
            this.ReportProgress(this.CurrentCount * 100 / this.ListCount);
            this.Semaphore.Release();
        }
Ejemplo n.º 4
0
        public void Sync(Model.Local.Customer Customer)
        {
            this.Semaphore.WaitOne();

            try
            {
                Model.Sage.F_COMPTETRepository F_COMPTETRepository = new Model.Sage.F_COMPTETRepository();
                if (F_COMPTETRepository.ExistId(Customer.Sag_Id))
                {
                    Model.Sage.F_COMPTET F_COMPTET = new Model.Sage.F_COMPTET();

                    F_COMPTET = F_COMPTETRepository.Read(Customer.Sag_Id);
                    if (F_COMPTET.F_COLLABORATEUR != null)
                    {
                        Model.Prestashop.PsAECCustomerCollaborateurRepository PsAECCollaborateurRepository = new Model.Prestashop.PsAECCustomerCollaborateurRepository();
                        Model.Prestashop.PsAEcCustomerCollaborateur           PsAEcCollaborateur           = new Model.Prestashop.PsAEcCustomerCollaborateur();

                        if (PsAECCollaborateurRepository.ExistCollaborateur((uint)Customer.Pre_Id))
                        {
                            PsAEcCollaborateur = PsAECCollaborateurRepository.ReadCollaborateur((uint)Customer.Pre_Id);
                            PsAEcCollaborateur.NomCollaborateur       = F_COMPTET.F_COLLABORATEUR.CO_Nom;
                            PsAEcCollaborateur.PrenomCollaborateur    = F_COMPTET.F_COLLABORATEUR.CO_Prenom;
                            PsAEcCollaborateur.TelephoneCollaborateur = F_COMPTET.F_COLLABORATEUR.CO_Telephone;
                            PsAECCollaborateurRepository.Save();
                        }
                        else
                        {
                            PsAEcCollaborateur                        = new Model.Prestashop.PsAEcCustomerCollaborateur();
                            PsAEcCollaborateur.IDCustomer             = (uint)Customer.Pre_Id;
                            PsAEcCollaborateur.NomCollaborateur       = F_COMPTET.F_COLLABORATEUR.CO_Nom;
                            PsAEcCollaborateur.PrenomCollaborateur    = F_COMPTET.F_COLLABORATEUR.CO_Prenom;
                            PsAEcCollaborateur.TelephoneCollaborateur = F_COMPTET.F_COLLABORATEUR.CO_Telephone;
                            PsAECCollaborateurRepository.Add(PsAEcCollaborateur);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError(ex.ToString());
            }
            lock (this)
            {
                this.CurrentCount += 1;
            }
            this.ReportProgress(this.CurrentCount * 100 / this.ListCount);
            this.Semaphore.Release();
        }
        public void Sync(Model.Local.Customer Customer)
        {
            this.Semaphore.WaitOne();

            try
            {
                Model.Prestashop.PsCustomerRepository PsCustomerRepository = new Model.Prestashop.PsCustomerRepository();
                Model.Sage.F_COMPTETRepository        F_COMPTETRepository  = new Model.Sage.F_COMPTETRepository();

                if (F_COMPTETRepository.ExistId(Customer.Sag_Id) &&
                    PsCustomerRepository.ExistCustomer((uint)Customer.Pre_Id))
                {
                    Model.Sage.F_COMPTET        F_COMPTET  = F_COMPTETRepository.Read(Customer.Sag_Id);
                    Model.Prestashop.PsCustomer PsCustomer = PsCustomerRepository.ReadCustomer((uint)Customer.Pre_Id);

                    Model.Local.Employee_CollaborateurRepository           Employee_CollaborateurRepository      = new Model.Local.Employee_CollaborateurRepository();
                    Model.Prestashop.PsEmployeeRepository                  PsEmployeeRepository                  = new Model.Prestashop.PsEmployeeRepository();
                    Model.Prestashop.PsPortfolioCustomerEmployeeRepository PsPortfolioCustomerEmployeeRepository = new Model.Prestashop.PsPortfolioCustomerEmployeeRepository();

                    if (F_COMPTET.CO_No == null)
                    {
                        lock (this.logs)
                            logs.Add("SP30- Le client [ " + F_COMPTET.NumIntitule + " ] ne possède pas de collaborateur dans Sage !");
                    }
                    else if (!Employee_CollaborateurRepository.ExistCollaborateur((int)F_COMPTET.CO_No))
                    {
                        lock (this.logs)
                            logs.Add("SP40- Aucun compte employé PrestaShop affecté au collaborateur du client [ " + F_COMPTET.NumIntitule + " ]");

                        if (PsPortfolioCustomerEmployeeRepository.ExistCustomer(PsCustomer.IDCustomer))
                        {
                            List <Model.Prestashop.PsPortfolioCustomerEmployee> ListPsPortfolioCustomerEmployee = PsPortfolioCustomerEmployeeRepository.ListCustomer(PsCustomer.IDCustomer);
                            foreach (Model.Prestashop.PsPortfolioCustomerEmployee PsPortfolioCustomerEmployee in ListPsPortfolioCustomerEmployee)
                            {
                                if (PsPortfolioCustomerEmployee.IDEmployee != null)
                                {
                                    string name = (PsEmployeeRepository.Exist(PsPortfolioCustomerEmployee.IDEmployee.Value))
                                        ? PsEmployeeRepository.Read(PsPortfolioCustomerEmployee.IDEmployee.Value).EmployeeName
                                        : string.Empty;

                                    PsPortfolioCustomerEmployeeRepository.Delete(PsPortfolioCustomerEmployee);
                                    lock (this.logs)
                                        logs.Add("SP12- Détachement du compte employé [" + (!string.IsNullOrWhiteSpace(name) ? name : PsPortfolioCustomerEmployee.IDEmployee.Value.ToString()) + "] pour le client Sage [ " + F_COMPTET.NumIntitule + " ] / PrestaShop ID : " + PsCustomer.IDCustomer);
                                }
                            }
                        }
                    }
                    else
                    {
                        uint IdEmployee = (uint)Employee_CollaborateurRepository.ReadCollaborateur((int)F_COMPTET.CO_No).IdEmployee;

                        List <Model.Prestashop.PsPortfolioCustomerEmployee> ListPsPortfolioCustomerEmployee = PsPortfolioCustomerEmployeeRepository.ListCustomer(PsCustomer.IDCustomer);
                        if (ListPsPortfolioCustomerEmployee.Count(pce => pce.IDEmployee != IdEmployee) > 0)
                        {
                            foreach (Model.Prestashop.PsPortfolioCustomerEmployee PsPortfolioCustomerEmployee in ListPsPortfolioCustomerEmployee.Where(pce => pce.IDEmployee != IdEmployee))
                            {
                                if (PsPortfolioCustomerEmployee.IDEmployee != null)
                                {
                                    string name = (PsEmployeeRepository.Exist(PsPortfolioCustomerEmployee.IDEmployee.Value))
                                        ? PsEmployeeRepository.Read(PsPortfolioCustomerEmployee.IDEmployee.Value).EmployeeName
                                        : string.Empty;

                                    PsPortfolioCustomerEmployeeRepository.Delete(PsPortfolioCustomerEmployee);
                                    lock (this.logs)
                                        logs.Add("SP11- Détachement du compte employé [" + (!string.IsNullOrWhiteSpace(name) ? name : PsPortfolioCustomerEmployee.IDEmployee.Value.ToString()) + "] pour le client Sage [ " + F_COMPTET.NumIntitule + " ] / PrestaShop ID : " + PsCustomer.IDCustomer);
                                }
                            }
                        }
                        if (IdEmployee == 0)
                        {
                            lock (this.logs)
                                logs.Add("SP50- Aucun compte employé PrestaShop affecté au collaborateur du client [ " + F_COMPTET.NumIntitule + " ]");
                        }
                        else if (PsPortfolioCustomerEmployeeRepository.Exist(PsCustomer.IDCustomer, IdEmployee) == false)
                        {
                            if (PsEmployeeRepository.Exist(IdEmployee))
                            {
                                PsPortfolioCustomerEmployeeRepository.Add(new Model.Prestashop.PsPortfolioCustomerEmployee()
                                {
                                    IDCustomer = PsCustomer.IDCustomer,
                                    IDEmployee = IdEmployee,
                                });
                                string name = (PsEmployeeRepository.Exist(IdEmployee))
                                        ? PsEmployeeRepository.Read(IdEmployee).EmployeeName
                                        : string.Empty;

                                lock (this.logs)
                                    logs.Add("SP10- Rattachement au compte employé [" + (!string.IsNullOrWhiteSpace(name) ? name : IdEmployee.ToString()) + "] pour le client Sage [ " + F_COMPTET.NumIntitule + " ] / PrestaShop ID : " + PsCustomer.IDCustomer);
                            }
                            else
                            {
                                lock (this.logs)
                                    logs.Add("SP60- Le compte employé affecté au collaborateur du client [ " + F_COMPTET.NumIntitule + " ] est invalide");
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                lock (this.logs)
                    logs.Add("SC20- Erreur affecation client/employé : " + ex.ToString());
                Core.Error.SendMailError("[SP20] " + ex.ToString());
            }
            lock (this)
            {
                this.CurrentCount += 1;
            }
            this.ReportProgress(this.CurrentCount * 100 / this.ListCount);
            this.Semaphore.Release();
        }
Ejemplo n.º 6
0
        private void LoadComponent()
        {
            // <JG> 26/12/2012
            this.CbGroupeClient.ItemsSource = new Model.Local.GroupRepository().ListGroupesLies();

            this.ButtonOustanding.IsEnabled = Core.Global.GetConfig().ModuleAECCustomerOutstandingActif;

            if (Core.Global.GetConfig().ConfigBToB)
            {
                this.TabItemClientBToB.IsEnabled  = true;
                this.TabItemClientBToC.IsEnabled  = false;
                this.TabItemClientBToB.IsSelected = true;

                this.GroupBoxSageCustomer.Header = (Core.Global.GetConfig().ConfigClientMultiMappageBtoB) ? "Client(s) Sage" : "Client(s) Sage non mappé(s)";

                this.LoadBTOBCustomer();
            }
            else if (Core.Global.GetConfig().ConfigBToC)
            {
                this.TabItemClientBToC.IsEnabled  = true;
                this.TabItemClientBToB.IsEnabled  = false;
                this.TabItemClientBToC.IsSelected = true;

                Model.Prestashop.PsCustomerRepository PsCustomerRepository = new Model.Prestashop.PsCustomerRepository();

                this.DataGridClient.ItemsSource = (Core.Global.GetConfig().ConfigClientFiltreCommande)
                            ? PsCustomerRepository.ListTopActiveOrderByDateAdd(60, 1, Core.Global.CurrentShop.IDShop)
                            : PsCustomerRepository.ListTopActiveOrderByDateAddWithOrder(60, 1, Core.Global.CurrentShop.IDShop);
                this.TabItemClientBToB.IsEnabled = false;

                #region centralisation clients
                Model.Local.Config Config = new Model.Local.Config();

                Model.Local.ConfigRepository ConfigRepository = new Model.Local.ConfigRepository();
                if (ConfigRepository.ExistName(Core.Global.ConfigClientTypeLien) &&
                    ConfigRepository.ReadName(Core.Global.ConfigClientTypeLien).Con_Value == Core.Global.ConfigClientTypeLienEnum.CompteCentralisateur.ToString())
                {
                    if (ConfigRepository.ExistName(Core.Global.ConfigClientCompteCentralisateur))
                    {
                        Config = ConfigRepository.ReadName(Core.Global.ConfigClientCompteCentralisateur);
                        if (Core.Global.IsInteger(Config.Con_Value))
                        {
                            Int32 cbMarqCentralisateur = Int32.Parse(Config.Con_Value);
                            Model.Sage.F_COMPTETRepository F_COMPTETRepositoryCentralisateur = new Model.Sage.F_COMPTETRepository();
                            Model.Sage.F_COMPTET           F_COMPTETCentralisateur;
                            if (F_COMPTETRepositoryCentralisateur.ExistId(cbMarqCentralisateur))
                            {
                                F_COMPTETCentralisateur = F_COMPTETRepositoryCentralisateur.Read(cbMarqCentralisateur);

                                this.LabelClientCentralisateur.Content = "Commandes et adresses des clients Prestashop centralisées vers le compte Sage " + F_COMPTETCentralisateur.CT_Num + " " + F_COMPTETCentralisateur.CT_Intitule;
                            }
                        }
                    }
                }
                #endregion
            }
            else
            {
                this.BtTransfert.IsEnabled = false;
            }

            LoadModules();
        }
        public void Exec(Model.Local.Customer CustomerSend)
        {
            this.Semaphore.WaitOne();

            int  invoice_count_transfert = 0;
            bool send_mail_notif         = false;

            Model.Prestashop.PsOrders MailDatas = new Model.Prestashop.PsOrders();
            try
            {
                Model.Prestashop.PsCustomerRepository PsCustomerRepository = new Model.Prestashop.PsCustomerRepository();
                uint IDCustomer = (uint)CustomerSend.Pre_Id;
                if (PsCustomerRepository.ExistCustomer(IDCustomer))
                {
                    MailDatas.IDCustomer = IDCustomer;

                    Model.Sage.F_COMPTETRepository F_COMPTETRepository = new Model.Sage.F_COMPTETRepository();
                    Model.Sage.F_COMPTET           F_COMPTET           = F_COMPTETRepository.Read(CustomerSend.Sag_Id);
                    if (F_COMPTET != null)
                    {
                        // <JG> 03/08/2017 gestion rafraichissement progression
                        Model.Local.Customer_Progress datas_progress = new Model.Local.Customer_Progress()
                        {
                            CT_Num      = F_COMPTET.CT_Num,
                            CT_Intitule = F_COMPTET.CT_Intitule,
                            Comment     = string.Empty,
                        };
                        ReportInfosSynchro(datas_progress, Core.Temp._action_information_synchro.debut);

                        Model.Sage.F_DOCENTETERepository F_DOCENTETERepository = new Model.Sage.F_DOCENTETERepository();

                        // <JG> 22/01/2016
                        send_mail_notif = (!string.IsNullOrWhiteSpace(Core.Global.GetConfig().ModuleAECInvoiceHistoryInfoLibreClientSendMail) &&
                                           F_COMPTETRepository.ExistArticleInformationLibreText(Core.Global.GetConfig().ModuleAECInvoiceHistoryInfoLibreClientSendMail, F_COMPTET.CT_Num) &&
                                           F_COMPTETRepository.ReadArticleInformationLibreText(Core.Global.GetConfig().ModuleAECInvoiceHistoryInfoLibreClientSendMail, F_COMPTET.CT_Num) == Core.Global.GetConfig().ModuleAECInvoiceHistoryInfoLibreClientSendMailValue);

                        Model.Prestashop.PsAECInvoiceHistoryRepository PsAECInvoiceHistoryRepository = new Model.Prestashop.PsAECInvoiceHistoryRepository();

                        // <JG> 04/03/2015 ajout gestion envoi des bons de commandes Sage dans PrestaShop
                        string order_path = System.IO.Path.Combine(Core.Global.GetConfig().Folders.RootReport, "AEC_Order.rpt");
                        if (System.IO.File.Exists(order_path))
                        {
                            uint TypeDocOrder = (uint)ABSTRACTION_SAGE.F_DOCENTETE.Obj._Enum_DO_Type.Bon_Commande_Vente;
                            datas_progress.Comment = GetComment(TypeDocOrder);
                            ReportInfosSynchro(datas_progress, Core.Temp._action_information_synchro.refresh);
                            ClearData(PsAECInvoiceHistoryRepository, IDCustomer, TypeDocOrder);

                            if (!_ClearMode)
                            {
                                datas_progress.Comment = GetComment(TypeDocOrder);
                                ReportInfosSynchro(datas_progress, Core.Temp._action_information_synchro.refresh);

                                List <Model.Sage.Piece> ListBC = F_DOCENTETERepository.ListPieceTiers(F_COMPTET.CT_Num, ABSTRACTION_SAGE.F_DOCENTETE.Obj._Enum_DO_Domaine.Vente, ABSTRACTION_SAGE.F_DOCENTETE.Obj._Enum_DO_Type.Bon_Commande_Vente, this._PeriodeDebut, this._PeriodeFin);
                                foreach (Model.Sage.Piece Piece in ListBC)
                                {
                                    TransfertPiece(order_path, PsAECInvoiceHistoryRepository, Piece, IDCustomer, TypeDocOrder, F_COMPTET.CT_Num);
                                    datas_progress.Comment = Piece.DO_Piece + " " + ListBC.IndexOf(Piece) + "/" + ListBC.Count;
                                    ReportInfosSynchro(datas_progress, Core.Temp._action_information_synchro.refresh);
                                }
                            }
                        }

                        string invoice_path = System.IO.Path.Combine(Core.Global.GetConfig().Folders.RootReport, "AEC_Invoice.rpt");
                        if (System.IO.File.Exists(invoice_path))
                        {
                            uint TypeDocInvoice = (uint)ABSTRACTION_SAGE.F_DOCENTETE.Obj._Enum_DO_Type.Facture_Comptabilisee_Vente;
                            if (!_ClearMode)
                            {
                                datas_progress.Comment = GetComment(TypeDocInvoice);
                                ReportInfosSynchro(datas_progress, Core.Temp._action_information_synchro.refresh);

                                List <Model.Sage.Piece> ListFacturesCompta = F_DOCENTETERepository.ListPieceTiers(F_COMPTET.CT_Num, ABSTRACTION_SAGE.F_DOCENTETE.Obj._Enum_DO_Domaine.Vente, ABSTRACTION_SAGE.F_DOCENTETE.Obj._Enum_DO_Type.Facture_Comptabilisee_Vente, this._PeriodeDebut, this._PeriodeFin);

                                List <Model.Prestashop.PsAEcInvoiceHistory_Light> ListTransfert = PsAECInvoiceHistoryRepository.ListLight(IDCustomer, TypeDocInvoice);
                                ListFacturesCompta = ListFacturesCompta.Where(d => ListTransfert.Count(i => i.invoice_number == d.DO_Piece) == 0).ToList();

                                foreach (Model.Sage.Piece Piece in ListFacturesCompta)
                                {
                                    if (TransfertPiece(invoice_path, PsAECInvoiceHistoryRepository, Piece, IDCustomer, TypeDocInvoice, F_COMPTET.CT_Num))
                                    {
                                        invoice_count_transfert++;

                                        if (string.IsNullOrEmpty(MailDatas.Mail_Invoice_numbers))
                                        {
                                            MailDatas.Mail_Invoice_numbers = Piece.DO_Piece;
                                        }
                                        else
                                        {
                                            MailDatas.Mail_Invoice_numbers += ", " + Piece.DO_Piece;
                                        }
                                    }
                                    datas_progress.Comment = Piece.DO_Piece + " " + ListFacturesCompta.IndexOf(Piece) + "/" + ListFacturesCompta.Count;
                                    ReportInfosSynchro(datas_progress, Core.Temp._action_information_synchro.refresh);
                                }
                            }
                            else
                            {
                                datas_progress.Comment = GetComment(TypeDocInvoice);
                                ReportInfosSynchro(datas_progress, Core.Temp._action_information_synchro.refresh);

                                ClearData(PsAECInvoiceHistoryRepository, IDCustomer, TypeDocInvoice);
                            }
                        }
                        ReportInfosSynchro(datas_progress, Core.Temp._action_information_synchro.fin);
                    }
                }
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError(ex.ToString());
            }

            // <JG> 22/01/2016 ajout mail notification
            try
            {
                if (send_mail_notif && invoice_count_transfert > 0)
                {
                    Core.Sync.SynchronisationCommande.SendMail(40, MailDatas);
                }
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError(ex.ToString());
            }

            lock (this)
            {
                this.CurrentCount += 1;
            }
            this.ReportProgress(this.CurrentCount * 100 / this.ListCount);
            this.Semaphore.Release();
        }
        public void Sync(Model.Local.Customer Customer)
        {
            this.Semaphore.WaitOne();

            try
            {
                Model.Prestashop.PsCustomerRepository      PsCustomerRepository      = new Model.Prestashop.PsCustomerRepository();
                Model.Prestashop.PsCustomerGroupRepository PsCustomerGroupRepository = new Model.Prestashop.PsCustomerGroupRepository();
                Model.Sage.F_COMPTETRepository             F_COMPTETRepository       = new Model.Sage.F_COMPTETRepository();

                if (F_COMPTETRepository.ExistId(Customer.Sag_Id) &&
                    PsCustomerRepository.ExistCustomer((uint)Customer.Pre_Id))
                {
                    Model.Sage.F_COMPTET        F_COMPTET  = F_COMPTETRepository.Read(Customer.Sag_Id);
                    Model.Prestashop.PsCustomer PsCustomer = PsCustomerRepository.ReadCustomer((uint)Customer.Pre_Id);

                    Model.Local.GroupRepository GroupRepository = new Model.Local.GroupRepository();

                    if (GroupRepository.CatTarifSageMonoGroupe((int)F_COMPTET.N_CatTarif))
                    {
                        uint IdPsGroup = (uint)GroupRepository.SearchIdGroupCatTarifSage((int)F_COMPTET.N_CatTarif);
                        if (IdPsGroup != PsCustomer.IDDefaultGroup)
                        {
                            uint old_group = PsCustomer.IDDefaultGroup;
                            PsCustomer.IDDefaultGroup = IdPsGroup;
                            PsCustomerRepository.Save();
                            lock (this.logs)
                                logs.Add("SG10- Modification du groupe pour le client [ " + PsCustomer.IDCustomer + " - " + PsCustomer.LastName + " " + PsCustomer.FirstName + " ]");

                            if (PsCustomerGroupRepository.Exist(PsCustomer.IDCustomer, IdPsGroup) == false)
                            {
                                PsCustomerGroupRepository.Add(new Model.Prestashop.PsCustomerGroup()
                                {
                                    IDCustomer = PsCustomer.IDCustomer,
                                    IDGroup    = IdPsGroup,
                                });
                            }

                            // détachement ancien groupe
                            if (PsCustomerGroupRepository.Exist(PsCustomer.IDCustomer, old_group))
                            {
                                PsCustomerGroupRepository.Delete(PsCustomer.IDCustomer, old_group);
                            }
                        }
                    }
                    //else if (GroupRepository.ExistCatTarif((int)F_COMPTET.N_CatTarif) == false)
                    //{
                    //    PsCustomer.Active = 0;
                    //    PsCustomerRepository.Save();
                    //    logs.Add("SG10- La catégorie tarifaire n'a pas de lien avec un groupe. Désactivation du compte client [ " + PsCustomer.IDCustomer + " - " + PsCustomer.LastName + " " + PsCustomer.FirstName + " ]");
                    //}
                }
            }
            catch (Exception ex)
            {
                lock (this.logs)
                    logs.Add("SG20- Erreur synchronisation groupe/catégorie tarifaire : " + ex.ToString());
                Core.Error.SendMailError("[SG20] " + ex.ToString());
            }
            lock (this)
            {
                this.CurrentCount += 1;
            }
            this.ReportProgress(this.CurrentCount * 100 / this.ListCount);
            this.Semaphore.Release();
        }
        public void Sync(Model.Local.Customer Customer)
        {
            this.Semaphore.WaitOne();

            try
            {
                Model.Prestashop.PsCustomerRepository      PsCustomerRepository      = new Model.Prestashop.PsCustomerRepository();
                Model.Prestashop.PsCustomerGroupRepository PsCustomerGroupRepository = new Model.Prestashop.PsCustomerGroupRepository();
                Model.Sage.F_COMPTETRepository             F_COMPTETRepository       = new Model.Sage.F_COMPTETRepository();
                Model.Prestashop.PsGroupLangRepository     PsGroupLangRepository     = new Model.Prestashop.PsGroupLangRepository();
                Model.Prestashop.PsGroupRepository         PsGroupRepository         = new Model.Prestashop.PsGroupRepository();

                if (F_COMPTETRepository.ExistId(Customer.Sag_Id) &&
                    PsCustomerRepository.ExistCustomer((uint)Customer.Pre_Id))
                {
                    Model.Sage.F_COMPTET        F_COMPTET  = F_COMPTETRepository.Read(Customer.Sag_Id);
                    Model.Prestashop.PsCustomer PsCustomer = PsCustomerRepository.ReadCustomer((uint)Customer.Pre_Id);

                    Model.Local.Group_CRisqueRepository Group_CRisqueRepository = new Model.Local.Group_CRisqueRepository();

                    if (F_COMPTET.N_Risque == null)
                    {
                        lock (this.logs)
                            logs.Add("SC30- Le client [ " + F_COMPTET.NumIntitule + " ] ne possède pas de code risque dans Sage !");
                    }
                    else if (!Group_CRisqueRepository.ExistCRisque((int)F_COMPTET.N_Risque))
                    {
                        lock (this.logs)
                            logs.Add("SC40- Aucun groupe affecté au code risque du client [ " + F_COMPTET.NumIntitule + " ]");
                    }
                    else
                    {
                        Model.Local.Group_CRisque Group_CRisque = Group_CRisqueRepository.ReadCRisque((int)F_COMPTET.N_Risque);

                        if (F_COMPTET.CT_ControlEnc != null &&
                            F_COMPTET.CT_ControlEnc == (short)ABSTRACTION_SAGE.F_COMPTET.Obj._Enum_CT_ControlEnc.Compte_Bloque &&
                            Group_CRisque.Grp_LockCondition)
                        {
                            // si compte bloqué dans Sage et indication à PrestaConnect de détacher le client
                            uint IdPsGroup = (uint)Group_CRisque.Grp_Pre_Id;
                            if (PsCustomerGroupRepository.Exist(PsCustomer.IDCustomer, IdPsGroup))
                            {
                                PsCustomerGroupRepository.Delete(PsCustomer.IDCustomer, IdPsGroup);
                                string name = PsGroupLangRepository.Read(Core.Global.Lang, IdPsGroup).Name;
                                lock (this.logs)
                                    logs.Add("SC11- Détachement du groupe [" + (!string.IsNullOrWhiteSpace(name) ? name : IdPsGroup.ToString()) + "] pour le client Sage [ " + F_COMPTET.NumIntitule + " ] / PrestaShop ID : " + PsCustomer.IDCustomer);
                            }

                            uint IdDefaultGroup = (uint)Group_CRisque.Grp_PreId_Default;
                            if (PsGroupRepository.ExistGroup((int)IdDefaultGroup) &&
                                PsCustomerGroupRepository.Exist(PsCustomer.IDCustomer, IdDefaultGroup) == false)
                            {
                                PsCustomerGroupRepository.Add(new Model.Prestashop.PsCustomerGroup()
                                {
                                    IDCustomer = PsCustomer.IDCustomer,
                                    IDGroup    = IdDefaultGroup,
                                });
                                string name = PsGroupLangRepository.Read(Core.Global.Lang, IdDefaultGroup).Name;
                                lock (this.logs)
                                    logs.Add("SC12- Rattachement au groupe par défaut [" + (!string.IsNullOrWhiteSpace(name) ? name : IdDefaultGroup.ToString()) + "] pour le client Sage [ " + F_COMPTET.NumIntitule + " ] / PrestaShop ID : " + PsCustomer.IDCustomer);
                            }

                            // si groupe du code risque défini par défaut sur le client - rattachement au groupe défaut du code risque
                            if (IdPsGroup == PsCustomer.IDDefaultGroup)
                            {
                                PsCustomer.IDDefaultGroup = IdDefaultGroup;
                                PsCustomerRepository.Save();
                            }
                        }
                        else
                        {
                            uint IdPsGroup = (uint)Group_CRisque.Grp_Pre_Id;
                            if (PsCustomerGroupRepository.Exist(PsCustomer.IDCustomer, IdPsGroup) == false)
                            {
                                if (PsGroupRepository.ExistGroup((int)IdPsGroup))
                                {
                                    //uint old_group = PsCustomer.IDDefaultGroup;
                                    //PsCustomer.IDDefaultGroup = IdPsGroup;
                                    //PsCustomerRepository.Save();

                                    if (PsCustomerGroupRepository.Exist(PsCustomer.IDCustomer, IdPsGroup) == false)
                                    {
                                        PsCustomerGroupRepository.Add(new Model.Prestashop.PsCustomerGroup()
                                        {
                                            IDCustomer = PsCustomer.IDCustomer,
                                            IDGroup    = IdPsGroup,
                                        });
                                        string name = PsGroupLangRepository.Read(Core.Global.Lang, IdPsGroup).Name;
                                        lock (this.logs)
                                            logs.Add("SC10- Rattachement au groupe [" + (!string.IsNullOrWhiteSpace(name) ? name : IdPsGroup.ToString()) + "] pour le client Sage [ " + F_COMPTET.NumIntitule + " ] / PrestaShop ID : " + PsCustomer.IDCustomer);
                                    }

                                    // détachement ancien groupe
                                    //if (PsCustomerGroupRepository.Exist(PsCustomer.IDCustomer, old_group))
                                    //    PsCustomerGroupRepository.Delete(PsCustomer.IDCustomer, old_group);
                                }
                                else
                                {
                                    lock (this.logs)
                                        logs.Add("SC50- Le groupe affecté au code risque du client [ " + F_COMPTET.NumIntitule + " ] est invalide");
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                lock (this.logs)
                    logs.Add("SC20- Erreur synchronisation groupe/code risque : " + ex.ToString());
                Core.Error.SendMailError("[SC20] " + ex.ToString());
            }
            lock (this)
            {
                this.CurrentCount += 1;
            }
            this.ReportProgress(this.CurrentCount * 100 / this.ListCount);
            this.Semaphore.Release();
        }