コード例 #1
0
        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();
        }
コード例 #2
0
        private void LoadOrdersAndCustomers()
        {
            PRESTACONNECT.Commande.ReadCommandePrestashop(DataGridCommande, 20);

            Core.Temp.ListLocalCustomer  = new Model.Local.CustomerRepository().List();
            Core.Temp.ListF_COMPTET_BtoB = new Model.Sage.F_COMPTETRepository().ListBtoB((short)ABSTRACTION_SAGE.F_COMPTET.Obj._Enum_CT_Type.Client);

            Model.Prestashop.PsCustomerRepository PsCustomerRepository = new Model.Prestashop.PsCustomerRepository();
            this.DataGridClient.ItemsSource = (Core.Global.GetConfig().ConfigClientFiltreCommande)
                ? PsCustomerRepository.ListTopActiveOrderByDateAdd(20, 1, Core.Global.CurrentShop.IDShop)
                : PsCustomerRepository.ListTopActiveOrderByDateAddWithOrder(20, 1, Global.CurrentShop.IDShop);
        }
        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();
        }
コード例 #4
0
        public void Exec(int DocumentSend)
        {
            this.Semaphore.WaitOne();

            try
            {
                Model.Sage.F_DOCENTETERepository F_DOCENTETERepository = new Model.Sage.F_DOCENTETERepository();
                Model.Sage.F_DOCENTETE           F_DOCENTETE           = F_DOCENTETERepository.Read(DocumentSend);

                Model.Local.OrderRepository OrderRepository = new Model.Local.OrderRepository();
                int PreID;
                // Contrôle de la provenance Web de la commande via une synchro Prestaconnect
                if (int.TryParse(F_DOCENTETE.DO_NoWeb, out PreID) &&
                    OrderRepository.ExistPrestashop(PreID))
                {
                    Model.Prestashop.PsOrdersRepository PsOrdersRepository = new Model.Prestashop.PsOrdersRepository();
                    if (PsOrdersRepository.ExistOrder(PreID))
                    {
                        Model.Prestashop.PsCartPreOrderRepository PsCartPreOrderRepository = new Model.Prestashop.PsCartPreOrderRepository();
                        if (!PsCartPreOrderRepository.ExistOrder(PreID))
                        {
                            Model.Prestashop.PsOrders PsOrder = PsOrdersRepository.ReadOrder(PreID);

                            Model.Prestashop.PsCustomerRepository PsCustomerRepository = new Model.Prestashop.PsCustomerRepository();
                            if (PsCustomerRepository.ExistCustomer(PsOrder.IDCustomer))
                            {
                                // récupération montant total des lignes
                                decimal?total_document = new Model.Sage.F_DOCLIGNERepository().MontantDomaineTypePieceValorise(F_DOCENTETE.DO_Domaine.Value, F_DOCENTETE.DO_Type.Value, F_DOCENTETE.DO_Piece);
                                // ajout frais de port pied de document
                                decimal total_port = 0;
                                if (F_DOCENTETE.DO_ValFrais != null)
                                {
                                    if (F_DOCENTETE.DO_TypeLigneFrais == (short)ABSTRACTION_SAGE.F_DOCENTETE.Obj._Enum_DO_TypeLigne.TTC)
                                    {
                                        total_port = (decimal)F_DOCENTETE.DO_ValFrais;
                                    }
                                    else
                                    {
                                        total_port = (decimal)F_DOCENTETE.DO_ValFrais * (1 + (F_DOCENTETE.DO_Taxe1.Value / 100));
                                    }
                                }
                                // calcul des acomptes et règlements
                                decimal?total_reglements = new Model.Sage.F_DOCREGLRepository().MontantDomaineTypePiece(F_DOCENTETE.DO_Domaine.Value, F_DOCENTETE.DO_Type.Value, F_DOCENTETE.DO_Piece);
                                if (total_document != null && total_reglements != null)
                                {
                                    decimal solde = (decimal)((total_document + total_port) - total_reglements);
                                    if (solde > 0)
                                    {
                                        #region création nouveau panier
                                        Model.Prestashop.PsCartRepository PsCartRepository = new Model.Prestashop.PsCartRepository();
                                        Model.Prestashop.PsCart           PsCart           = new Model.Prestashop.PsCart()
                                        {
                                            DateAdd           = DateTime.Now,
                                            DateUpd           = DateTime.Now,
                                            DeliveryOption    = string.Empty,
                                            Gift              = 0,
                                            GiftMessage       = string.Empty,
                                            IDAddressDelivery = PsOrder.IDAddressDelivery,
                                            IDAddressInvoice  = PsOrder.IDAddressInvoice,
                                            IDCarrier         = 0,
                                            IDCurrency        = PsOrder.IDCurrency,
                                            IDCustomer        = PsOrder.IDCustomer,
                                            IDGuest           = 0,
                                            IDLang            = PsOrder.IDLang,
                                            IDShop            = PsOrder.IDShop,
                                            IDShopGroup       = PsOrder.IDShopGroup,
                                            Recyclable        = PsOrder.Recyclable,
                                            SecureKey         = PsOrder.SecureKey,
                                        };
                                        PsCartRepository.Add(PsCart);
                                        #endregion

                                        #region attribution du solde en tant que prix spécifique pour le produit
                                        Model.Prestashop.PsSpecificPriceRepository PsSpecificPriceRepository = new Model.Prestashop.PsSpecificPriceRepository();
                                        Model.Prestashop.PsSpecificPrice           PsSpecificPrice           = new Model.Prestashop.PsSpecificPrice()
                                        {
                                            IDProduct     = (uint)Core.Global.GetConfig().ModulePreorderPrestashopProduct,
                                            FromQuantity  = 1,
                                            IDCart        = PsCart.IDCart,
                                            IDCustomer    = PsCart.IDCustomer,
                                            Price         = solde,
                                            ReductionType = Model.Prestashop.PsSpecificPrice._ReductionType_Amount,
                                            From          = new DateTime(),
                                            To            = new DateTime(),
                                        };
                                        PsSpecificPriceRepository.Add(PsSpecificPrice);
                                        PsSpecificPriceRepository.SaveReductionTypeFromDateToDate(PsSpecificPrice);
                                        #endregion

                                        #region attribution de l'article au panier
                                        Model.Prestashop.PsCartProductRepository PsCartProductRepository = new Model.Prestashop.PsCartProductRepository();
                                        Model.Prestashop.PsCartProduct           PsCartProduct           = new Model.Prestashop.PsCartProduct()
                                        {
                                            DateAdd            = DateTime.Now,
                                            IDAddressDelivery  = PsCart.IDAddressDelivery,
                                            IDCart             = PsCart.IDCart,
                                            IDProduct          = (uint)Core.Global.GetConfig().ModulePreorderPrestashopProduct,
                                            IDProductAttribute = 0,
                                            IDShop             = PsCart.IDShop,
                                            Quantity           = 1,
                                        };
                                        PsCartProductRepository.Add(PsCartProduct);
                                        #endregion

                                        #region ajout de l'identification du panier en tant que solde de précommande
                                        Model.Prestashop.PsCartPreOrder PsCartPreorder = new Model.Prestashop.PsCartPreOrder()
                                        {
                                            IDCart     = PsCart.IDCart,
                                            IDPreOrder = PsOrder.IDOrder,
                                        };
                                        PsCartPreOrderRepository.Add(PsCartPreorder);
                                        #endregion

                                        // génération URL directe panier
                                        PsOrder.Cart_URL = Core.Global.URL_Prestashop + "/commande?step=1&recover_cart=" + PsCart.IDCart
                                                           + "&token_cart=" + Core.RandomString.HashMD5(Core.Global.GetConfig().TransfertPrestashopCookieKey + "recover_cart_" + PsCart.IDCart.ToString());

                                        Core.Sync.SynchronisationCommande.SendMail(33, PsOrder);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError(ex.ToString());
            }

            lock (this)
            {
                this.CurrentCount += 1;
            }
            this.ReportProgress(this.CurrentCount * 100 / this.ListCount);
            this.Semaphore.Release();
        }
コード例 #5
0
        public SynchronisationClient()
        {
            this.InitializeComponent();
            this.worker.WorkerReportsProgress = true;
            this.LabelInformation.Content     = "Recherche des clients à créer ...";

            this.worker.DoWork += delegate(object s, DoWorkEventArgs args)
            {
                if (Core.Global.GetConfig().ConfigBToC)
                {
                    Model.Prestashop.PsCustomerRepository PsCustomerRepository = new Model.Prestashop.PsCustomerRepository();
                    List <Model.Prestashop.idcustomer>    ListCustomer         = (Core.Global.GetConfig().ConfigClientFiltreCommande)
                        ? PsCustomerRepository.ListIDActive(1, Core.Global.CurrentShop.IDShop)
                        : PsCustomerRepository.ListIDActiveWithOrder(1, Core.Global.CurrentShop.IDShop);

                    // <JG> ajout filtre clients déjà mappés
                    List <Model.Local.Customer> listLocal = new Model.Local.CustomerRepository().List();
                    ListCustomer = ListCustomer.Where(c => listLocal.Count(l => l.Pre_Id == c.id_customer) == 0).ToList();
                    this.worker.ReportProgress(0);

                    if (ListCustomer.Count > 0)
                    {
                        this.worker.ReportProgress(-42);
                        Connexion = Core.Global.GetODBC();

                        foreach (Model.Prestashop.idcustomer Customer in ListCustomer)
                        {
                            if (Connexion != null)
                            {
                                Core.Sync.SynchronisationClient SynchronisationClient = new Core.Sync.SynchronisationClient();
                                SynchronisationClient.Exec(Connexion, Customer.id_customer);
                            }
                            lock (this)
                            {
                                this.CurrentCount += 1;
                            }
                            this.worker.ReportProgress((this.CurrentCount * 100 / ListCustomer.Count));
                        }
                    }
                }
            };

            this.worker.ProgressChanged += delegate(object s, ProgressChangedEventArgs args)
            {
                if (args.ProgressPercentage >= 0)
                {
                    this.ProgressBarClient.Value  = args.ProgressPercentage;
                    this.LabelInformation.Content = "Informations : " + args.ProgressPercentage + " %";
                }
                else if (args.ProgressPercentage == -42)
                {
                    this.LabelInformation.Content = "Ouverture connexion ODBC Sage...";
                }
            };

            this.worker.RunWorkerCompleted += delegate(object s, RunWorkerCompletedEventArgs args)
            {
                if (Connexion != null)
                {
                    Connexion.Close_Connexion();
                }
                this.Close();
            };

            // Insérez le code requis pour la création d’objet sous ce point.
            this.worker.RunWorkerAsync();
        }
コード例 #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();
        }
コード例 #7
0
        private void ButtonSync_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                PRESTACONNECT.Loading Loading = new PRESTACONNECT.Loading();
                Loading.Show();


                DateTime?filtre = null, old_config = Core.Global.GetConfig().ConfigCommandeFiltreDate;
                if (DataContext.SyncDay)
                {
                    filtre = DateTime.Now.Date;
                }
                else if (DataContext.SyncWeek)
                {
                    filtre = DateTime.Now.Date.AddDays(-7);
                }
                else if (DataContext.SyncMonth)
                {
                    filtre = DateTime.Now.Date.AddMonths(-1);
                }

                if (filtre != null)
                {
                    Core.Global.GetConfig().UpdateConfigCommandeFiltreDate(filtre, true);
                }


                if (Core.Global.GetConfig().ConfigBToC)
                {
                    PRESTACONNECT.SynchronisationClient SynchronisationClient = new SynchronisationClient();
                    SynchronisationClient.ShowDialog();
                }

                PRESTACONNECT.SynchronisationLivraison SynchronisationLivraison = new SynchronisationLivraison();
                SynchronisationLivraison.ShowDialog();


                if (filtre != null)
                {
                    Core.Global.GetConfig().UpdateConfigCommandeFiltreDate(old_config, true);
                }

                Loading.Close();

                if (this.TabItemClientBToC.IsEnabled)
                {
                    Core.Temp.ListLocalCustomer  = new Model.Local.CustomerRepository().List();
                    Core.Temp.ListF_COMPTET_BtoB = new Model.Sage.F_COMPTETRepository().ListBtoB((short)ABSTRACTION_SAGE.F_COMPTET.Obj._Enum_CT_Type.Client);

                    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);
                }
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError(ex.ToString());
            }
        }
コード例 #8
0
        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();
        }
コード例 #9
0
        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();
        }
コード例 #10
0
        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();
        }