Esempio n. 1
0
 private void ExecLocalToDistant(Model.Local.Article Article, Model.Local.ArticleRepository ArticleRepository, Model.Prestashop.PsProduct Product, Model.Prestashop.PsProductRepository ProductRepository)
 {
     try
     {
         Model.Sage.F_ARTICLERepository F_ARTICLERepository = new Model.Sage.F_ARTICLERepository();
         if (F_ARTICLERepository.ExistArticle(Article.Sag_Id))
         {
             Model.Sage.F_ARTICLE F_ARTICLE = F_ARTICLERepository.ReadArticle(Article.Sag_Id);
             Model.Prestashop.PsPackRepository PsPackRepository = new Model.Prestashop.PsPackRepository();
             List <Model.Prestashop.PsPack>    ListPsPack       = PsPackRepository.ListProductPack(Product.IDProduct);
             foreach (Model.Prestashop.PsPack PsPack in ListPsPack)
             {
                 PsPackRepository.Delete(PsPack);
             }
             #region Pack/nomenclature
             if (Article.Art_Pack == true)
             {
                 Model.Sage.F_NOMENCLATRepository F_NOMENCLATRepository = new Model.Sage.F_NOMENCLATRepository();
                 List <Model.Sage.F_NOMENCLAT>    ListF_NOMENCLAT       = F_NOMENCLATRepository.ListRef(F_ARTICLE.AR_Ref);
                 Model.Sage.F_ARTICLE             F_ARTICLENOMENCLAT;
                 Model.Local.Article     ArticleNomenclat;
                 Model.Prestashop.PsPack PsPackAdd;
                 foreach (Model.Sage.F_NOMENCLAT F_NOMENCLAT in ListF_NOMENCLAT)
                 {
                     if (F_ARTICLERepository.ExistReference(F_NOMENCLAT.NO_RefDet))
                     {
                         F_ARTICLENOMENCLAT = F_ARTICLERepository.ReadReference(F_NOMENCLAT.NO_RefDet);
                         if (ArticleRepository.ExistSag_Id(F_ARTICLENOMENCLAT.cbMarq) &&
                             F_ARTICLENOMENCLAT.AR_SuiviStock != (short)ABSTRACTION_SAGE.F_ARTICLE.Obj._Enum_AR_SuiviStock.Aucun)
                         // pour ne pas prendre en compte les articles non suivi en stock
                         {
                             ArticleNomenclat = ArticleRepository.ReadSag_Id(F_ARTICLENOMENCLAT.cbMarq);
                             if (ArticleNomenclat.Pre_Id != null && ArticleNomenclat.Pre_Id.Value != 0)
                             {
                                 if (ProductRepository.ExistId((UInt32)ArticleNomenclat.Pre_Id.Value))
                                 {
                                     PsPackAdd = new Model.Prestashop.PsPack()
                                     {
                                         IDProductPack = Product.IDProduct,
                                         IDProductItem = (UInt32)ArticleNomenclat.Pre_Id.Value,
                                         Quantity      = (UInt32)F_NOMENCLAT.NO_Qte.Value
                                     };
                                     PsPackRepository.Add(PsPackAdd);
                                 }
                             }
                         }
                     }
                 }
             }
             #endregion
         }
     }
     catch (Exception ex)
     {
         Core.Error.SendMailError(ex.ToString());
     }
 }
        public void Exec(Int32 ArticleSend)
        {
            try
            {
                Model.Local.ArticleRepository ArticleRepository = new Model.Local.ArticleRepository();
                Model.Local.Article           Article           = ArticleRepository.ReadArticle(ArticleSend);

                Model.Sage.F_ARTICLERepository F_ARTICLERepository = new Model.Sage.F_ARTICLERepository();
                Model.Sage.F_ARTICLE           F_ARTICLE           = new Model.Sage.F_ARTICLE();
                F_ARTICLE = F_ARTICLERepository.ReadArticle(Article.Sag_Id);

                Core.ImportSage.ImportArticle ImportArticle = new ImportSage.ImportArticle();
                ImportArticle.ImportCatalogueInfoLibre(F_ARTICLE, Article);

                //Model.Local.CatalogRepository CatalogRepository = new Model.Local.CatalogRepository();

                //Model.Local.InformationLibreArticleRepository InformationLibreArticleRepository = new Model.Local.InformationLibreArticleRepository();
                //Model.Local.InformationLibreArticle InformationLibreArticleCatalogueParent = new Model.Local.InformationLibreArticle();

                //Model.Local.Catalog Parent;

                //foreach (Model.Local.InformationLibreArticle InformationLibreArticle in InformationLibreArticleRepository.List())
                //{
                //    CatalogRepository = new Model.Local.CatalogRepository();

                //    if (InformationLibreArticle.Inf_Catalogue == 2)
                //    {
                //        if (CatalogRepository.ExistParent(InformationLibreArticle.Inf_Parent, InformationLibreArticle.Inf_Catalogue))
                //        {
                //            CreateCatalogueInfoLibre(InformationLibreArticle, F_ARTICLE, Article, InformationLibreArticle.Inf_Catalogue + 1, CatalogRepository.ReadParent(InformationLibreArticle.Inf_Parent, InformationLibreArticle.Inf_Catalogue).Cat_Id);
                //        }
                //    }
                //    else
                //    {
                //        if (InformationLibreArticleRepository.ExistInfoLibreLevel(InformationLibreArticle.Inf_Parent, 2))
                //        {
                //            InformationLibreArticleCatalogueParent = InformationLibreArticleRepository.ReadInfoLibre(InformationLibreArticle.Inf_Parent, (int)InformationLibreArticle.Inf_Catalogue - 1);
                //            if (CatalogRepository.ExistName(F_ARTICLERepository.ReadArticleInformationLibreText(InformationLibreArticleCatalogueParent.Sag_InfoLibreArticle, F_ARTICLE.AR_Ref)))
                //            {
                //                Parent = CatalogRepository.ReadParent(F_ARTICLERepository.ReadArticleInformationLibreText(InformationLibreArticleCatalogueParent.Sag_InfoLibreArticle, F_ARTICLE.AR_Ref), 2);

                //                if (Parent != null)
                //                {
                //                    CreateCatalogueInfoLibre(InformationLibreArticle, F_ARTICLE, Article, 3, Parent.Cat_Id);
                //                }
                //            }
                //        }
                //    }
                //}
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError(ex.ToString());
            }
        }
Esempio n. 3
0
        public SyncArticle(Model.Local.Article local, Model.Sage.F_ARTICLE sage)
        {
            Local = local;
            Sage  = sage;

            OnPropertyChanged("CanDelete");

            ListRedirectType = new ObservableCollection <RedirectType>();
            foreach (Core.Parametres.RedirectType valeur in Enum.GetValues(typeof(Core.Parametres.RedirectType)))
            {
                ListRedirectType.Add(new RedirectType(valeur));
            }
            if (!String.IsNullOrWhiteSpace(Local.Art_RedirectType) && Core.Global.IsInteger(Local.Art_RedirectType) && ListRedirectType.Count(r => r.Page == Local.Art_RedirectType) == 1)
            {
                SelectedRedirectType = ListRedirectType.First(r => r.Page == Local.Art_RedirectType);
            }
        }
        private void ExecLocalToDistant(Model.Local.Article Article, Model.Prestashop.PsProduct Product, Model.Prestashop.PsProductRepository ProductRepository)
        {
            try
            {
                if (Article.TypeArticle == Model.Local.Article.enum_TypeArticle.ArticleComposition)
                {
                    if (Core.UpdateVersion.License.Option2)
                    {
                        Product.Quantity = 0;
                        Product.Price    = 0;
                        SynchronisationArticle.WriteStockAvailableProduct(Product);
                        SynchronisationArticle.ExecCompositionArticle(Article, Product, ProductRepository);
                    }
                }
                else
                {
                    Model.Sage.F_ARTICLERepository F_ARTICLERepository = new Model.Sage.F_ARTICLERepository();
                    if (F_ARTICLERepository.ExistArticle(Article.Sag_Id))
                    {
                        Model.Sage.F_ARTICLE F_ARTICLE = F_ARTICLERepository.ReadArticle(Article.Sag_Id);

                        if ((F_ARTICLE.AR_Gamme1 != null && F_ARTICLE.AR_Gamme1 != 0) || (F_ARTICLE.AR_Condition != null && F_ARTICLE.AR_Condition != 0))
                        {
                            int CatComptaArticle      = Core.Global.GetConfig().ConfigArticleCatComptable;
                            Model.Sage.F_TAXE TaxeTVA = SynchronisationArticle.ReadTaxe(F_ARTICLE, Product, CatComptaArticle);
                            Model.Sage.F_TAXE TaxeEco = SynchronisationArticle.ReadEcoTaxe(F_ARTICLE, Product, TaxeTVA, CatComptaArticle);
                            SynchronisationArticle.ReadPrice(F_ARTICLE, Product, TaxeTVA);


                            // <JG> 19/02/2013 déplacement pour correction problème prix spécifiques lors de la création de l'article
                            SynchronisationArticle.ExecAttribute(Article, Product, ProductRepository, TaxeTVA);
                            SynchronisationArticle.ExecConditioning(Article, Product, ProductRepository, TaxeTVA);

                            //List<string> log;
                            //SynchronisationArticle.ExecSpecificPrice(F_ARTICLE, Product, Article.Art_Id, TaxeTVA, TaxeEco, out log);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError(ex.ToString());
            }
        }
Esempio n. 5
0
        public Boolean ImportValues(Model.Local.Article Article, string AR_Ref)
        {
            Boolean HasValue = false;

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

                #region Informations libre Article

                Model.Local.InformationLibreRepository InformationLibreRepository = new Model.Local.InformationLibreRepository();
                foreach (Model.Local.InformationLibre InformationLibre in InformationLibreRepository.ListSync())
                {
                    // <JG> 21/08/2017 ajout filtre info libre pour automates
                    if (Core.Temp.TaskImportStatInfoLibreFilter == null || Core.Temp.TaskImportStatInfoLibreFilter.Contains(Core.Global.EscapeArgumentSyntax(InformationLibre.Sag_InfoLibre)))
                    {
                        Model.Sage.cbSysLibreRepository.CB_Type TypeInfoLibre = new Model.Sage.cbSysLibreRepository().ReadTypeInformationLibre(InformationLibre.Sag_InfoLibre, Model.Sage.cbSysLibreRepository.CB_File.F_ARTICLE);

                        switch (TypeInfoLibre)
                        {
                        case Model.Sage.cbSysLibreRepository.CB_Type.SageText:
                        case Model.Sage.cbSysLibreRepository.CB_Type.SageTable:
                            #region text
                            if (F_ARTICLERepository.ExistArticleInformationLibreText(InformationLibre.Sag_InfoLibre, AR_Ref))
                            {
                                if (!string.IsNullOrWhiteSpace(Core.Global.SageValueReplacement(F_ARTICLERepository.ReadArticleInformationLibreText(InformationLibre.Sag_InfoLibre, AR_Ref))))
                                {
                                    Model.Local.CharacteristicRepository CharacteristicRepository = new Model.Local.CharacteristicRepository();
                                    Model.Local.Characteristic           ArticleCharacteristic;
                                    if (CharacteristicRepository.ExistFeatureArticle(InformationLibre.Cha_Id, Article.Art_Id))
                                    {
                                        ArticleCharacteristic = CharacteristicRepository.ReadFeatureArticle(InformationLibre.Cha_Id, Article.Art_Id);
                                        string temp_text = ArticleCharacteristic.Cha_Value;
                                        int?   temp_id   = ArticleCharacteristic.Pre_Id;
                                        ArticleCharacteristic.Cha_Value = Core.Global.SageValueReplacement(F_ARTICLERepository.ReadArticleInformationLibreText(InformationLibre.Sag_InfoLibre, AR_Ref));;
                                        switch (InformationLibre.Inf_Mode)
                                        {
                                        case (short)Core.Parametres.InformationLibreValeursMode.Predefinies:
                                            ArticleCharacteristic.Cha_Custom = false;
                                            ArticleCharacteristic.Pre_Id     = CreateFeatureValue(ArticleCharacteristic.Cha_Value, InformationLibre.Cha_Id);
                                            break;

                                        case (short)Core.Parametres.InformationLibreValeursMode.Personnalisees:
                                            ArticleCharacteristic.Cha_Custom = true;
                                            break;
                                        }
                                        CharacteristicRepository.Save();
                                        if (temp_text != ArticleCharacteristic.Cha_Value || temp_id != ArticleCharacteristic.Pre_Id)
                                        {
                                            HasValue = true;
                                        }
                                    }
                                    else
                                    {
                                        HasValue = true;
                                        ArticleCharacteristic = new Model.Local.Characteristic()
                                        {
                                            Art_Id        = Article.Art_Id,
                                            Cha_IdFeature = (int)InformationLibre.Cha_Id,
                                            Cha_Value     = Core.Global.SageValueReplacement(F_ARTICLERepository.ReadArticleInformationLibreText(InformationLibre.Sag_InfoLibre, AR_Ref)),
                                        };
                                        switch (InformationLibre.Inf_Mode)
                                        {
                                        case (short)Core.Parametres.InformationLibreValeursMode.Predefinies:
                                            ArticleCharacteristic.Cha_Custom = false;
                                            ArticleCharacteristic.Pre_Id     = CreateFeatureValue(ArticleCharacteristic.Cha_Value, InformationLibre.Cha_Id);
                                            break;

                                        case (short)Core.Parametres.InformationLibreValeursMode.Personnalisees:
                                            ArticleCharacteristic.Cha_Custom = true;
                                            break;
                                        }
                                        CharacteristicRepository.Add(ArticleCharacteristic);
                                    }
                                }
                                else if (Core.Global.GetConfig().ArticleSuppressionAutoCaracteristique)
                                {
                                    DeleteFeatureProduct(InformationLibre, Article);
                                }
                            }
                            #endregion
                            break;

                        case Model.Sage.cbSysLibreRepository.CB_Type.SageValeur:
                        case Model.Sage.cbSysLibreRepository.CB_Type.SageMontant:
                            #region decimal
                            if (F_ARTICLERepository.ExistArticleInformationLibreNumerique(InformationLibre.Sag_InfoLibre, AR_Ref))
                            {
                                if (F_ARTICLERepository.ReadArticleInformationLibreNumerique(InformationLibre.Sag_InfoLibre, AR_Ref) != null)
                                {
                                    Model.Local.CharacteristicRepository CharacteristicRepository = new Model.Local.CharacteristicRepository();
                                    Model.Local.Characteristic           ArticleCharacteristic;
                                    if (CharacteristicRepository.ExistFeatureArticle(InformationLibre.Cha_Id, Article.Art_Id))
                                    {
                                        ArticleCharacteristic = CharacteristicRepository.ReadFeatureArticle(InformationLibre.Cha_Id, Article.Art_Id);
                                        string temp_text = ArticleCharacteristic.Cha_Value;
                                        int?   temp_id   = ArticleCharacteristic.Pre_Id;
                                        ArticleCharacteristic.Cha_Value = F_ARTICLERepository.ReadArticleInformationLibreNumerique(InformationLibre.Sag_InfoLibre, AR_Ref).Value
                                                                          .ToString((TypeInfoLibre == Model.Sage.cbSysLibreRepository.CB_Type.SageMontant) ? "0.00####" : "0.######");
                                        switch (InformationLibre.Inf_Mode)
                                        {
                                        case (short)Core.Parametres.InformationLibreValeursMode.Predefinies:
                                            ArticleCharacteristic.Cha_Custom = false;
                                            ArticleCharacteristic.Pre_Id     = CreateFeatureValue(ArticleCharacteristic.Cha_Value, InformationLibre.Cha_Id);
                                            break;

                                        case (short)Core.Parametres.InformationLibreValeursMode.Personnalisees:
                                            ArticleCharacteristic.Cha_Custom = true;
                                            break;
                                        }
                                        CharacteristicRepository.Save();
                                        if (temp_text != ArticleCharacteristic.Cha_Value || temp_id != ArticleCharacteristic.Pre_Id)
                                        {
                                            HasValue = true;
                                        }
                                    }
                                    else
                                    {
                                        HasValue = true;
                                        ArticleCharacteristic = new Model.Local.Characteristic()
                                        {
                                            Art_Id        = Article.Art_Id,
                                            Cha_IdFeature = (int)InformationLibre.Cha_Id,
                                            Cha_Value     = F_ARTICLERepository.ReadArticleInformationLibreNumerique(InformationLibre.Sag_InfoLibre, AR_Ref).Value
                                                            .ToString((TypeInfoLibre == Model.Sage.cbSysLibreRepository.CB_Type.SageMontant) ? "0.00####" : "0.######"),
                                        };
                                        switch (InformationLibre.Inf_Mode)
                                        {
                                        case (short)Core.Parametres.InformationLibreValeursMode.Predefinies:
                                            ArticleCharacteristic.Cha_Custom = false;
                                            ArticleCharacteristic.Pre_Id     = CreateFeatureValue(ArticleCharacteristic.Cha_Value, InformationLibre.Cha_Id);
                                            break;

                                        case (short)Core.Parametres.InformationLibreValeursMode.Personnalisees:
                                            ArticleCharacteristic.Cha_Custom = true;
                                            break;
                                        }
                                        CharacteristicRepository.Add(ArticleCharacteristic);
                                    }
                                }
                                else if (Core.Global.GetConfig().ArticleSuppressionAutoCaracteristique)
                                {
                                    DeleteFeatureProduct(InformationLibre, Article);
                                }
                            }
                            #endregion
                            break;

                        case Model.Sage.cbSysLibreRepository.CB_Type.SageDate:
                        case Model.Sage.cbSysLibreRepository.CB_Type.SageSmallDate:
                            #region datetime
                            if (F_ARTICLERepository.ExistArticleInformationLibreDate(InformationLibre.Sag_InfoLibre, AR_Ref))
                            {
                                if (F_ARTICLERepository.ReadArticleInformationLibreDate(InformationLibre.Sag_InfoLibre, AR_Ref) != null)
                                {
                                    Model.Local.CharacteristicRepository CharacteristicRepository = new Model.Local.CharacteristicRepository();
                                    Model.Local.Characteristic           ArticleCharacteristic;
                                    if (CharacteristicRepository.ExistFeatureArticle(InformationLibre.Cha_Id, Article.Art_Id))
                                    {
                                        ArticleCharacteristic = CharacteristicRepository.ReadFeatureArticle(InformationLibre.Cha_Id, Article.Art_Id);
                                        string temp_text = ArticleCharacteristic.Cha_Value;
                                        int?   temp_id   = ArticleCharacteristic.Pre_Id;
                                        ArticleCharacteristic.Cha_Value = F_ARTICLERepository.ReadArticleInformationLibreDate(InformationLibre.Sag_InfoLibre, AR_Ref).ToString();
                                        switch (InformationLibre.Inf_Mode)
                                        {
                                        case (short)Core.Parametres.InformationLibreValeursMode.Predefinies:
                                            ArticleCharacteristic.Cha_Custom = false;
                                            ArticleCharacteristic.Pre_Id     = CreateFeatureValue(ArticleCharacteristic.Cha_Value, InformationLibre.Cha_Id);
                                            break;

                                        case (short)Core.Parametres.InformationLibreValeursMode.Personnalisees:
                                            ArticleCharacteristic.Cha_Custom = true;
                                            break;
                                        }
                                        CharacteristicRepository.Save();
                                        if (temp_text != ArticleCharacteristic.Cha_Value || temp_id != ArticleCharacteristic.Pre_Id)
                                        {
                                            HasValue = true;
                                        }
                                    }
                                    else
                                    {
                                        ArticleCharacteristic = new Model.Local.Characteristic()
                                        {
                                            Art_Id        = Article.Art_Id,
                                            Cha_IdFeature = (int)InformationLibre.Cha_Id,
                                            Cha_Value     = F_ARTICLERepository.ReadArticleInformationLibreDate(InformationLibre.Sag_InfoLibre, AR_Ref).ToString(),
                                        };
                                        switch (InformationLibre.Inf_Mode)
                                        {
                                        case (short)Core.Parametres.InformationLibreValeursMode.Predefinies:
                                            ArticleCharacteristic.Cha_Custom = false;
                                            ArticleCharacteristic.Pre_Id     = CreateFeatureValue(ArticleCharacteristic.Cha_Value, InformationLibre.Cha_Id);
                                            break;

                                        case (short)Core.Parametres.InformationLibreValeursMode.Personnalisees:
                                            ArticleCharacteristic.Cha_Custom = true;
                                            break;
                                        }
                                        CharacteristicRepository.Add(ArticleCharacteristic);
                                    }
                                }
                                else if (Core.Global.GetConfig().ArticleSuppressionAutoCaracteristique)
                                {
                                    DeleteFeatureProduct(InformationLibre, Article);
                                }
                            }
                            #endregion
                            break;

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

                #endregion

                // traitement uniquement si absence de filtre sur l'automate
                if (Core.Temp.TaskImportStatInfoLibreFilter == null)
                {
                    #region Statistiques Article

                    Model.Local.StatistiqueArticleRepository StatistiqueArticleRepository = new Model.Local.StatistiqueArticleRepository();
                    foreach (Model.Local.StatistiqueArticle StatistiqueArticle in StatistiqueArticleRepository.ListSync())
                    {
                        Model.Sage.P_INTSTATARTRepository P_INTSTATARTRepository = new Model.Sage.P_INTSTATARTRepository();
                        if (P_INTSTATARTRepository.ExistStatArt(StatistiqueArticle.Sag_StatArt))
                        {
                            Model.Sage.P_INTSTATART P_INTSTATART = P_INTSTATARTRepository.ReadStatArt(StatistiqueArticle.Sag_StatArt);
                            Model.Sage.F_ARTICLE    F_ARTICLE    = F_ARTICLERepository.ReadReference(AR_Ref);
                            String stat_value = null;
                            switch (P_INTSTATART.cbMarq)
                            {
                            case 1:
                                stat_value = F_ARTICLE.AR_Stat01;
                                break;

                            case 2:
                                stat_value = F_ARTICLE.AR_Stat02;
                                break;

                            case 3:
                                stat_value = F_ARTICLE.AR_Stat03;
                                break;

                            case 4:
                                stat_value = F_ARTICLE.AR_Stat04;
                                break;

                            case 5:
                                stat_value = F_ARTICLE.AR_Stat05;
                                break;
                            }
                            if (!String.IsNullOrWhiteSpace(stat_value))
                            {
                                Model.Local.CharacteristicRepository CharacteristicRepository = new Model.Local.CharacteristicRepository();
                                Model.Local.Characteristic           ArticleCharacteristic;
                                if (CharacteristicRepository.ExistFeatureArticle(StatistiqueArticle.Cha_Id, Article.Art_Id))
                                {
                                    ArticleCharacteristic = CharacteristicRepository.ReadFeatureArticle(StatistiqueArticle.Cha_Id, Article.Art_Id);
                                    string temp_text = ArticleCharacteristic.Cha_Value;
                                    int?   temp_id   = ArticleCharacteristic.Pre_Id;
                                    ArticleCharacteristic.Cha_Value = Core.Global.SageValueReplacement(stat_value);
                                    switch (StatistiqueArticle.Inf_Mode)
                                    {
                                    case (short)PRESTACONNECT.Core.Parametres.InformationLibreValeursMode.Predefinies:
                                        ArticleCharacteristic.Cha_Custom = false;
                                        ArticleCharacteristic.Pre_Id     = CreateFeatureValue(ArticleCharacteristic.Cha_Value, StatistiqueArticle.Cha_Id);
                                        break;

                                    case (short)PRESTACONNECT.Core.Parametres.InformationLibreValeursMode.Personnalisees:
                                        ArticleCharacteristic.Cha_Custom = true;
                                        break;
                                    }
                                    CharacteristicRepository.Save();
                                    if (temp_text != ArticleCharacteristic.Cha_Value || temp_id != ArticleCharacteristic.Pre_Id)
                                    {
                                        HasValue = true;
                                    }
                                }
                                else
                                {
                                    HasValue = true;
                                    ArticleCharacteristic = new Model.Local.Characteristic()
                                    {
                                        Art_Id        = Article.Art_Id,
                                        Cha_IdFeature = (int)StatistiqueArticle.Cha_Id,
                                        Cha_Value     = Core.Global.SageValueReplacement(stat_value),
                                    };
                                    switch (StatistiqueArticle.Inf_Mode)
                                    {
                                    case (short)PRESTACONNECT.Core.Parametres.InformationLibreValeursMode.Predefinies:
                                        ArticleCharacteristic.Cha_Custom = false;
                                        ArticleCharacteristic.Pre_Id     = CreateFeatureValue(ArticleCharacteristic.Cha_Value, StatistiqueArticle.Cha_Id);
                                        break;

                                    case (short)PRESTACONNECT.Core.Parametres.InformationLibreValeursMode.Personnalisees:
                                        ArticleCharacteristic.Cha_Custom = true;
                                        break;
                                    }
                                    CharacteristicRepository.Add(ArticleCharacteristic);
                                }
                            }
                        }
                    }

                    #endregion
                }

                #region Marque/Fabricant

                if (Core.Global.GetConfig().MarqueAutoStatistiqueActif&& Core.Temp.TaskImportStatInfoLibreFilter == null)
                {
                    Model.Sage.P_INTSTATARTRepository P_INTSTATARTRepository = new Model.Sage.P_INTSTATARTRepository();
                    if (P_INTSTATARTRepository.ExistStatArt(Core.Global.GetConfig().MarqueAutoStatistiqueName))
                    {
                        Model.Sage.P_INTSTATART P_INTSTATART = P_INTSTATARTRepository.ReadStatArt(Core.Global.GetConfig().MarqueAutoStatistiqueName);
                        Model.Sage.F_ARTICLE    F_ARTICLE    = F_ARTICLERepository.ReadReference(AR_Ref);
                        String stat_value = null;
                        switch (P_INTSTATART.cbMarq)
                        {
                        case 1:
                            stat_value = F_ARTICLE.AR_Stat01;
                            break;

                        case 2:
                            stat_value = F_ARTICLE.AR_Stat02;
                            break;

                        case 3:
                            stat_value = F_ARTICLE.AR_Stat03;
                            break;

                        case 4:
                            stat_value = F_ARTICLE.AR_Stat04;
                            break;

                        case 5:
                            stat_value = F_ARTICLE.AR_Stat05;
                            break;
                        }
                        if (!String.IsNullOrWhiteSpace(stat_value))
                        {
                            int temp_id = Article.Art_Manufacturer;
                            Article.Art_Manufacturer = CreateManufacturer(Core.Global.SageValueReplacement(stat_value));
                            if (temp_id != Article.Art_Manufacturer)
                            {
                                HasValue = true;
                            }
                        }
                    }
                }
                else if (Core.Global.GetConfig().MarqueAutoInfolibreActif)
                {
                    Model.Sage.cbSysLibreRepository.CB_Type TypeInfoLibre = new Model.Sage.cbSysLibreRepository().ReadTypeInformationLibre(Core.Global.GetConfig().MarqueAutoInfolibreName, Model.Sage.cbSysLibreRepository.CB_File.F_ARTICLE);

                    switch (TypeInfoLibre)
                    {
                    case PRESTACONNECT.Model.Sage.cbSysLibreRepository.CB_Type.SageText:
                    case PRESTACONNECT.Model.Sage.cbSysLibreRepository.CB_Type.SageTable:
                        #region text
                        if (F_ARTICLERepository.ExistArticleInformationLibreText(Core.Global.GetConfig().MarqueAutoInfolibreName, AR_Ref) &&
                            !string.IsNullOrWhiteSpace(Core.Global.SageValueReplacement(F_ARTICLERepository.ReadArticleInformationLibreText(Core.Global.GetConfig().MarqueAutoInfolibreName, AR_Ref))))
                        {
                            int temp_id = Article.Art_Manufacturer;
                            Article.Art_Manufacturer = CreateManufacturer(Core.Global.SageValueReplacement(F_ARTICLERepository.ReadArticleInformationLibreText(Core.Global.GetConfig().MarqueAutoInfolibreName, AR_Ref)));
                            if (temp_id != Article.Art_Manufacturer)
                            {
                                HasValue = true;
                            }
                        }
                        #endregion
                        break;

                    default:
                        break;
                    }
                }

                #endregion

                #region Fournisseur

                if (Core.Global.GetConfig().FournisseurAutoStatistiqueActif&& Core.Temp.TaskImportStatInfoLibreFilter == null)
                {
                    Model.Sage.P_INTSTATARTRepository P_INTSTATARTRepository = new Model.Sage.P_INTSTATARTRepository();
                    if (P_INTSTATARTRepository.ExistStatArt(Core.Global.GetConfig().FournisseurAutoStatistiqueName))
                    {
                        Model.Sage.P_INTSTATART P_INTSTATART = P_INTSTATARTRepository.ReadStatArt(Core.Global.GetConfig().FournisseurAutoStatistiqueName);
                        Model.Sage.F_ARTICLE    F_ARTICLE    = F_ARTICLERepository.ReadReference(AR_Ref);
                        String stat_value = null;
                        switch (P_INTSTATART.cbMarq)
                        {
                        case 1:
                            stat_value = F_ARTICLE.AR_Stat01;
                            break;

                        case 2:
                            stat_value = F_ARTICLE.AR_Stat02;
                            break;

                        case 3:
                            stat_value = F_ARTICLE.AR_Stat03;
                            break;

                        case 4:
                            stat_value = F_ARTICLE.AR_Stat04;
                            break;

                        case 5:
                            stat_value = F_ARTICLE.AR_Stat05;
                            break;
                        }
                        if (!String.IsNullOrWhiteSpace(stat_value))
                        {
                            int temp_id = Article.Art_Supplier;
                            Article.Art_Supplier = CreateSupplier(Core.Global.SageValueReplacement(stat_value));
                            if (temp_id != Article.Art_Supplier)
                            {
                                HasValue = true;
                            }
                        }
                    }
                }
                else if (Core.Global.GetConfig().FournisseurAutoInfolibreActif)
                {
                    Model.Sage.cbSysLibreRepository.CB_Type TypeInfoLibre = new Model.Sage.cbSysLibreRepository().ReadTypeInformationLibre(Core.Global.GetConfig().FournisseurAutoInfolibreName, Model.Sage.cbSysLibreRepository.CB_File.F_ARTICLE);

                    switch (TypeInfoLibre)
                    {
                    case PRESTACONNECT.Model.Sage.cbSysLibreRepository.CB_Type.SageText:
                    case PRESTACONNECT.Model.Sage.cbSysLibreRepository.CB_Type.SageTable:
                        #region text
                        if (F_ARTICLERepository.ExistArticleInformationLibreText(Core.Global.GetConfig().FournisseurAutoInfolibreName, AR_Ref) &&
                            !string.IsNullOrWhiteSpace(Core.Global.SageValueReplacement(F_ARTICLERepository.ReadArticleInformationLibreText(Core.Global.GetConfig().FournisseurAutoInfolibreName, AR_Ref))))
                        {
                            int temp_id = Article.Art_Supplier;
                            Article.Art_Supplier = CreateSupplier(Core.Global.SageValueReplacement(F_ARTICLERepository.ReadArticleInformationLibreText(Core.Global.GetConfig().FournisseurAutoInfolibreName, AR_Ref)));
                            if (temp_id != Article.Art_Supplier)
                            {
                                HasValue = true;
                            }
                        }
                        #endregion
                        break;

                    default:
                        break;
                    }
                }

                #endregion

                if (Core.Temp.TaskImportStatInfoLibreFilter == null)
                {
                    #region Information Sage

                    Model.Local.InformationArticleRepository InformationArticleRepository = new Model.Local.InformationArticleRepository();
                    foreach (Model.Local.InformationArticle InformationArticle in InformationArticleRepository.ListSync())
                    {
                        {
                            Model.Internal.SageInfoArticle SageInfoArticle = new Model.Internal.SageInfoArticle((Parametres.SageInfoArticle)InformationArticle.Sag_InfoArt);
                            Model.Sage.F_ARTICLE           F_ARTICLE       = F_ARTICLERepository.ReadReference(AR_Ref);
                            String stat_value = null;
                            switch (SageInfoArticle._SageInfoArticle)
                            {
                            case PRESTACONNECT.Core.Parametres.SageInfoArticle.Substitut:
                                stat_value = F_ARTICLE.AR_Substitut;
                                break;

                            case PRESTACONNECT.Core.Parametres.SageInfoArticle.FamilleCode:
                                stat_value = F_ARTICLE.FA_CodeFamille;
                                break;

                            case PRESTACONNECT.Core.Parametres.SageInfoArticle.FamilleIntitule:
                                if (F_ARTICLE.F_FAMILLE != null && !string.IsNullOrEmpty(F_ARTICLE.F_FAMILLE.FA_Intitule))
                                {
                                    stat_value = F_ARTICLE.F_FAMILLE.FA_Intitule;
                                }
                                break;

                            case PRESTACONNECT.Core.Parametres.SageInfoArticle.Garantie:
                                if (F_ARTICLE.AR_Garantie != null)
                                {
                                    stat_value = F_ARTICLE.AR_Garantie.Value.ToString();
                                }
                                break;

                            case PRESTACONNECT.Core.Parametres.SageInfoArticle.Pays:
                                stat_value = F_ARTICLE.AR_Pays;
                                break;

                            case PRESTACONNECT.Core.Parametres.SageInfoArticle.PoidsNet:
                                if (F_ARTICLE.AR_PoidsNet != null && F_ARTICLE.AR_PoidsNet != 0)
                                {
                                    stat_value = F_ARTICLE.AR_PoidsNet.ToString();
                                }
                                break;

                            case PRESTACONNECT.Core.Parametres.SageInfoArticle.PoidsBrut:
                                if (F_ARTICLE.AR_PoidsBrut != null && F_ARTICLE.AR_PoidsBrut != 0)
                                {
                                    stat_value = F_ARTICLE.AR_PoidsBrut.ToString();
                                }
                                break;
                            }
                            if (!String.IsNullOrWhiteSpace(stat_value))
                            {
                                Model.Local.CharacteristicRepository CharacteristicRepository = new Model.Local.CharacteristicRepository();
                                Model.Local.Characteristic           ArticleCharacteristic;
                                if (CharacteristicRepository.ExistFeatureArticle(InformationArticle.Cha_Id, Article.Art_Id))
                                {
                                    ArticleCharacteristic = CharacteristicRepository.ReadFeatureArticle(InformationArticle.Cha_Id, Article.Art_Id);
                                    string temp_text = ArticleCharacteristic.Cha_Value;
                                    int?   temp_id   = ArticleCharacteristic.Pre_Id;
                                    ArticleCharacteristic.Cha_Value = Core.Global.SageValueReplacement(stat_value);
                                    switch (InformationArticle.Inf_Mode)
                                    {
                                    case (short)PRESTACONNECT.Core.Parametres.InformationLibreValeursMode.Predefinies:
                                        ArticleCharacteristic.Cha_Custom = false;
                                        ArticleCharacteristic.Pre_Id     = CreateFeatureValue(ArticleCharacteristic.Cha_Value, InformationArticle.Cha_Id);
                                        break;

                                    case (short)PRESTACONNECT.Core.Parametres.InformationLibreValeursMode.Personnalisees:
                                        ArticleCharacteristic.Cha_Custom = true;
                                        break;
                                    }
                                    CharacteristicRepository.Save();
                                    if (temp_text != ArticleCharacteristic.Cha_Value || temp_id != ArticleCharacteristic.Pre_Id)
                                    {
                                        HasValue = true;
                                    }
                                }
                                else
                                {
                                    HasValue = true;
                                    ArticleCharacteristic = new Model.Local.Characteristic()
                                    {
                                        Art_Id        = Article.Art_Id,
                                        Cha_IdFeature = (int)InformationArticle.Cha_Id,
                                        Cha_Value     = Core.Global.SageValueReplacement(stat_value),
                                    };
                                    switch (InformationArticle.Inf_Mode)
                                    {
                                    case (short)PRESTACONNECT.Core.Parametres.InformationLibreValeursMode.Predefinies:
                                        ArticleCharacteristic.Cha_Custom = false;
                                        ArticleCharacteristic.Pre_Id     = CreateFeatureValue(ArticleCharacteristic.Cha_Value, InformationArticle.Cha_Id);
                                        break;

                                    case (short)PRESTACONNECT.Core.Parametres.InformationLibreValeursMode.Personnalisees:
                                        ArticleCharacteristic.Cha_Custom = true;
                                        break;
                                    }
                                    CharacteristicRepository.Add(ArticleCharacteristic);
                                }
                            }
                        }
                    }

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

            return(HasValue);
        }
Esempio n. 6
0
        private void ExecLocalToDistant(Model.Local.Article Article, Model.Prestashop.PsProduct Product, Model.Prestashop.PsProductRepository PsProductRepository,
                                        out List <string> log_chrono)
        {
            log_chrono = new List <string>();
            try
            {
                if (Article.TypeArticle == Model.Local.Article.enum_TypeArticle.ArticleComposition)
                {
                    if (Core.UpdateVersion.License.Option2)
                    {
                        Product.Price    = 0;
                        Product.Quantity = 0;
                        SynchronisationArticle.WriteStockAvailableProduct(Product);
                        ExecCompositionArticle(Article, Product);
                    }
                }
                else
                {
                    Model.Sage.F_ARTICLERepository F_ARTICLERepository = new Model.Sage.F_ARTICLERepository();
                    if (F_ARTICLERepository.ExistArticle(Article.Sag_Id))
                    {
                        Model.Sage.F_ARTICLE F_ARTICLE = F_ARTICLERepository.ReadArticle(Article.Sag_Id);
                        SynchronisationArticle.ReadQuantity(F_ARTICLE, Product);

                        #region Stock pack limité par composés
                        if (Article.Art_Pack == true || F_ARTICLE.AR_Nomencl == (short)ABSTRACTION_SAGE.F_ARTICLE.Obj._Enum_AR_Nomencl.Commerciale_Composant ||
                            F_ARTICLE.AR_Nomencl == (short)ABSTRACTION_SAGE.F_ARTICLE.Obj._Enum_AR_Nomencl.Commerciale_Compose)                                        // pour que les articles en nomenclature soient pris en compte
                        {
                            Model.Sage.F_NOMENCLATRepository F_NOMENCLATRepository = new Model.Sage.F_NOMENCLATRepository();
                            List <Model.Sage.F_NOMENCLAT>    ListF_NOMENCLAT       = F_NOMENCLATRepository.ListRef(F_ARTICLE.AR_Ref);
                            Model.Sage.F_ARTICLE             F_ARTICLENOMENCLAT;
                            Int32 QuantityPack = 0;
                            foreach (Model.Sage.F_NOMENCLAT F_NOMENCLAT in ListF_NOMENCLAT)
                            {
                                if (F_ARTICLERepository.ExistReference(F_NOMENCLAT.NO_RefDet))
                                {
                                    F_ARTICLENOMENCLAT = F_ARTICLERepository.ReadReference(F_NOMENCLAT.NO_RefDet);
                                    if (F_ARTICLENOMENCLAT.AR_SuiviStock != (short)ABSTRACTION_SAGE.F_ARTICLE.Obj._Enum_AR_SuiviStock.Aucun)                                                            // pour ne pas prendre en compte les articles non suivi en stock
                                    {
                                        Int32 CurrentQuantity = SynchronisationArticle.ReadQuantityPack(F_ARTICLENOMENCLAT, F_NOMENCLAT.NO_Qte.Value);
                                        if (Core.Global.GetConfig().ArticleStockNegatifZero&& CurrentQuantity < 0)
                                        {
                                            CurrentQuantity = 0;
                                        }
                                        if (CurrentQuantity < QuantityPack)
                                        {
                                            QuantityPack = CurrentQuantity;
                                        }
                                        else if (QuantityPack == 0)
                                        {
                                            QuantityPack = CurrentQuantity;
                                            // <AM> 14/08/2014 Si un des articles composant n'a pas de stock on sort de la fonction pour que l'article parent ai un stock à 0
                                            if (CurrentQuantity == 0)
                                            {
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                            Product.Quantity = QuantityPack;
                        }
                        #endregion

                        int CatComptaArticle      = Core.Global.GetConfig().ConfigArticleCatComptable;
                        Model.Sage.F_TAXE TaxeTVA = SynchronisationArticle.ReadTaxe(F_ARTICLE, Product, CatComptaArticle);
                        Model.Sage.F_TAXE TaxeEco = SynchronisationArticle.ReadEcoTaxe(F_ARTICLE, Product, TaxeTVA, CatComptaArticle);
                        // <JG> 03/06/2016
                        if (Article.Art_SyncPrice)
                        {
                            SynchronisationArticle.ReadPrice(F_ARTICLE, Product, TaxeTVA);
                        }

                        if (Core.Global.GetConfig().MajPoidsSynchroStock)
                        {
                            SynchronisationArticle.ReadWeight(F_ARTICLE, Product);
                        }

                        if (Core.Global.GetConfig().ArticleDateDispoInfoLibreActif)
                        {
                            SynchronisationArticle.ReadDateDispo(Product, F_ARTICLE);
                        }

                        PsProductRepository.Save();
                        PsProductRepository.WriteDate(Product.IDProduct);

                        // <JG> 05/11/2013 déplacement pour application taxes et pdt spécifiques sur nouvelles déclinaisons
                        this.ExecAttribute(Article, Product, TaxeTVA, PsProductRepository);
                        this.ExecConditioning(Article, Product, TaxeTVA, PsProductRepository);

                        // <JG> 03/06/2016
                        if (Article.Art_SyncPrice)
                        {
                            List <string> log;
                            SynchronisationArticle.ExecSpecificPrice(F_ARTICLE, Product, Article, null, TaxeTVA, TaxeEco, out log);
                            if (log != null && log.Count > 0)
                            {
                                log_chrono.AddRange(log);
                            }
                        }

                        // <JG> 17/12/2012
                        SynchronisationArticle.ExecShopProduct(Product);

                        SynchronisationArticle.WriteStockAvailableProduct(Product);
                    }
                }
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError(ex.ToString());
            }
        }
Esempio n. 7
0
        private void ExecCompositionArticle(Model.Local.Article Article, Model.Prestashop.PsProduct Product)
        {
            Model.Sage.F_ARTICLERepository           F_ARTICLERepository          = new Model.Sage.F_ARTICLERepository();
            Model.Local.CompositionArticleRepository CompositionArticleRepository = new Model.Local.CompositionArticleRepository();
            List <Model.Local.CompositionArticle>    ListCompositionArticle       = CompositionArticleRepository.ListArticle(Article.Art_Id);

            foreach (var item in ListCompositionArticle)
            {
                try
                {
                    Model.Sage.F_ARTICLE_Composition F_ARTICLE_Composition = F_ARTICLERepository.ReadComposition(item.ComArt_F_ARTICLE_SagId, item.ComArt_F_ARTENUMREF_SagId, item.ComArt_F_CONDITION_SagId);
                    if (F_ARTICLE_Composition != null)
                    {
                        Model.Sage.F_ARTICLE F_ARTICLE = F_ARTICLERepository.ReadArticle(item.ComArt_F_ARTICLE_SagId);
                        Model.Prestashop.PsProductAttributeRepository PsProductAttributeRepository  = new Model.Prestashop.PsProductAttributeRepository();
                        Model.Prestashop.PsProductAttribute           PsProductAttributeComposition = new Model.Prestashop.PsProductAttribute();
                        Boolean isProductAttribute = false;
                        if (item.Pre_Id != null && PsProductAttributeRepository.ExistProductAttribute((uint)item.Pre_Id))
                        {
                            PsProductAttributeComposition = PsProductAttributeRepository.ReadProductAttribute((uint)item.Pre_Id);
                            if (PsProductAttributeComposition != null)
                            {
                                isProductAttribute = true;
                            }
                        }

                        if (isProductAttribute == true)
                        {
                            int CatComptaArticle      = Core.Global.GetConfig().ConfigArticleCatComptable;
                            Model.Sage.F_TAXE TaxeTVA = SynchronisationArticle.ReadTaxe(F_ARTICLE, Product, CatComptaArticle);

                            Model.Prestashop.PsProduct temp_product = new Model.Prestashop.PsProduct();
                            temp_product.taxe_famillesage = Product.taxe_famillesage;

                            // temp_product sert pour conserver l'information "ecoraxeht_sage" pour la fonction SpecificPrice
                            Model.Sage.F_TAXE TaxeEco = SynchronisationArticle.ReadEcoTaxe(F_ARTICLE, temp_product, TaxeTVA, CatComptaArticle);
                            PsProductAttributeComposition.EcOtAx = temp_product.EcOtAx;

                            if (F_ARTICLE_Composition.F_CONDITION_SagId == null && F_ARTICLE_Composition.F_ARTENUMREF_SagId == null)
                            {
                                if (Core.Global.GetConfig().MajPoidsSynchroStock)
                                {
                                    SynchronisationArticle.ReadWeight(F_ARTICLE, PsProductAttributeComposition);
                                }

                                SynchronisationArticle.ReadQuantity(F_ARTICLE, PsProductAttributeComposition);

                                // <JG> 03/06/2016
                                if (Article.Art_SyncPrice)
                                {
                                    SynchronisationArticle.ReadPrice(F_ARTICLE, PsProductAttributeComposition, TaxeTVA);
                                }

                                //List<string> log;
                                //this.ExecSpecificPrice(F_ARTICLE, Product, Article.Art_Id, TaxeTVA, TaxeEco, out log);
                                //if (log != null && log.Count > 0)
                                //    log_chrono.AddRange(log);
                            }
                            else if (F_ARTICLE_Composition.F_ARTENUMREF_SagId != null)
                            {
                                Model.Prestashop.PsProduct temp_product_f_artenumref = new Model.Prestashop.PsProduct();
                                // lecture des valeurs pour F_ARTICLE
                                if (Core.Global.GetConfig().MajPoidsSynchroStock)
                                {
                                    SynchronisationArticle.ReadWeight(F_ARTICLE, temp_product_f_artenumref);
                                }

                                SynchronisationArticle.ReadQuantity(F_ARTICLE, temp_product_f_artenumref);

                                // <JG> 03/06/2016
                                if (Article.Art_SyncPrice)
                                {
                                    SynchronisationArticle.ReadPrice(F_ARTICLE, temp_product_f_artenumref, TaxeTVA);
                                }

                                // transformation en fonction de f_artenumref
                                if (Core.Global.GetConfig().MajPoidsSynchroStock)
                                {
                                    SynchronisationArticle.ReadWeightAttribute(temp_product_f_artenumref, PsProductAttributeComposition, F_ARTICLE, item.EnumereGamme1);
                                    PsProductAttributeComposition.Weight += temp_product_f_artenumref.Weight;
                                }
                                SynchronisationArticle.ReadQuantityAttribute(PsProductAttributeComposition, F_ARTICLE, item.EnumereGamme1, item.EnumereGamme2);
                                //SynchronisationArticle.ReadRefEANAttribute(PsProductAttributeComposition, F_ARTICLE, item.EnumereGamme1, item.EnumereGamme2);

                                // <JG> 03/06/2016
                                if (Article.Art_SyncPrice)
                                {
                                    SynchronisationArticle.ReadPriceAttribute(temp_product_f_artenumref, PsProductAttributeComposition, F_ARTICLE, item.EnumereGamme1, item.EnumereGamme2, TaxeTVA);
                                }
                                PsProductAttributeComposition.Price += temp_product_f_artenumref.Price;
                            }
                            else if (F_ARTICLE_Composition.F_CONDITION_SagId != null)
                            {
                                Model.Prestashop.PsProduct temp_product_f_condition = new Model.Prestashop.PsProduct();
                                // lecture des valeurs pour F_ARTICLE
                                if (Core.Global.GetConfig().MajPoidsSynchroStock)
                                {
                                    SynchronisationArticle.ReadWeight(F_ARTICLE, temp_product_f_condition);
                                }

                                SynchronisationArticle.ReadQuantity(F_ARTICLE, temp_product_f_condition);

                                // <JG> 03/06/2016
                                if (Article.Art_SyncPrice)
                                {
                                    SynchronisationArticle.ReadPrice(F_ARTICLE, temp_product_f_condition, TaxeTVA);
                                }

                                // transformation en fonction de F_CONDITION
                                if (Core.Global.GetConfig().MajPoidsSynchroStock)
                                {
                                    SynchronisationArticle.ReadWeightConditioning(temp_product_f_condition, PsProductAttributeComposition, item.EnumereF_CONDITION);
                                    PsProductAttributeComposition.Weight += temp_product_f_condition.Weight;
                                }
                                SynchronisationArticle.ReadQuantityConditioning(PsProductAttributeComposition, F_ARTICLE, item.EnumereF_CONDITION);

                                // <JG> 03/06/2016
                                if (Article.Art_SyncPrice)
                                {
                                    SynchronisationArticle.ReadPriceConditioning(temp_product_f_condition, PsProductAttributeComposition, F_ARTICLE, item.EnumereF_CONDITION, TaxeTVA);
                                }
                                PsProductAttributeComposition.Price += temp_product_f_condition.Price;
                            }

                            //PsProductAttributeComposition.DefaultOn = (item.ComArt_Default) ? (byte)1 : (byte)0;
                            PsProductAttributeRepository.Save();
                            SynchronisationArticle.ExecShopProductAttribute(PsProductAttributeComposition);

                            SynchronisationArticle.WriteStockAvailableComposition(Product, PsProductAttributeComposition);

                            // <JG> 03/06/2016
                            if (Article.Art_SyncPrice)
                            {
                                // prix spécifiques
                                temp_product.Price     = PsProductAttributeComposition.Price;
                                temp_product.IDProduct = Product.IDProduct;
                                List <string> log;
                                SynchronisationArticle.ExecSpecificPrice(F_ARTICLE, temp_product, Article, item, TaxeTVA, TaxeEco, out log);
                                if (log != null && log.Count > 0)
                                {
                                    SynchronisationArticle.log_chrono.AddRange(log);
                                }
                            }
                        }
                    }
                }
                catch (Exception ex) { Core.Error.SendMailError(ex.ToString()); }
            }
        }
Esempio n. 8
0
        private void ExecConditioning(Model.Local.Article Article, Model.Prestashop.PsProduct PsProduct, Model.Sage.F_TAXE TaxeTVA, Model.Prestashop.PsProductRepository PsProductRepository)
        {
            try
            {
                Model.Sage.F_ARTICLERepository F_ARTICLERepository = new Model.Sage.F_ARTICLERepository();
                if (F_ARTICLERepository.ExistArticle(Article.Sag_Id))
                {
                    Model.Sage.F_ARTICLE F_ARTICLE = F_ARTICLERepository.ReadArticle(Article.Sag_Id);

                    Model.Local.ConditioningGroupRepository     ConditioningGroupRepository = new Model.Local.ConditioningGroupRepository();
                    Model.Prestashop.PsAttributeGroupRepository PsAttributeGroupRepository  = new Model.Prestashop.PsAttributeGroupRepository();

                    Boolean isProductAttribute;

                    if (F_ARTICLE.AR_Condition != null && F_ARTICLE.AR_Condition != 0 &&
                        ConditioningGroupRepository.ExistSage((int)F_ARTICLE.AR_Condition) &&
                        PsAttributeGroupRepository.ExistAttributeGroup((uint)ConditioningGroupRepository.ReadSage((int)F_ARTICLE.AR_Condition).Pre_Id))
                    {
                        Model.Local.ConditioningArticleRepository ConditioningArticleRepository = new Model.Local.ConditioningArticleRepository();
                        List <Model.Local.ConditioningArticle>    ListConditioningArticle       = ConditioningArticleRepository.ListArticleSync(Article.Art_Id, true);

                        Model.Prestashop.PsProductAttributeRepository PsProductAttributeRepository = new Model.Prestashop.PsProductAttributeRepository();
                        Model.Prestashop.PsProductAttribute           PsProductAttribute;
                        int stockmaxunity = 0;
                        foreach (Model.Local.ConditioningArticle ConditioningArticle in ListConditioningArticle)
                        {
                            if (ConditioningArticle.EnumereF_CONDITION != null)
                            {
                                PsProductAttribute = new Model.Prestashop.PsProductAttribute();
                                isProductAttribute = false;
                                if (ConditioningArticle.Pre_Id != null && ConditioningArticle.Pre_Id != 0)
                                {
                                    if (PsProductAttributeRepository.ExistProductAttribute((UInt32)ConditioningArticle.Pre_Id))
                                    {
                                        PsProductAttribute = PsProductAttributeRepository.ReadProductAttribute((UInt32)ConditioningArticle.Pre_Id);
                                        isProductAttribute = true;
                                    }
                                }

                                if (Core.Global.GetConfig().MajPoidsSynchroStock)
                                {
                                    SynchronisationArticle.ReadWeightConditioning(PsProduct, PsProductAttribute, ConditioningArticle.EnumereF_CONDITION);
                                }

                                SynchronisationArticle.ReadQuantityConditioning(PsProductAttribute, F_ARTICLE, ConditioningArticle.EnumereF_CONDITION);

                                if (Core.Global.GetConfig().LimiteStockConditionnement&& PsProductAttribute.Quantity >= stockmaxunity)
                                {
                                    stockmaxunity      = PsProductAttribute.Quantity;
                                    PsProduct.Quantity = stockmaxunity;
                                    PsProductRepository.Save();
                                }

                                // <JG> 03/06/2016
                                if (Article.Art_SyncPrice)
                                {
                                    SynchronisationArticle.ReadPriceConditioning(PsProduct, PsProductAttribute, F_ARTICLE, ConditioningArticle.EnumereF_CONDITION, TaxeTVA);
                                }

                                //PsProductAttribute.DefaultOn = (ConditioningArticle.ConArt_Default) ? (byte)1 : (byte)0;
                                if (isProductAttribute == true)
                                {
                                    PsProductAttributeRepository.Save();
                                    SynchronisationArticle.ExecShopProductAttribute(PsProductAttribute);

                                    SynchronisationArticle.WriteStockAvailableProductAttribute(PsProduct, PsProductAttribute);
                                }
                            }
                        }
                        PsProductAttributeRepository.WriteDate(PsProduct.IDProduct);
                    }
                }
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError(ex.ToString());
            }
        }
Esempio n. 9
0
        private void ExecAttribute(Model.Local.Article Article, Model.Prestashop.PsProduct PsProduct, Model.Sage.F_TAXE TaxeTVA, Model.Prestashop.PsProductRepository PsProductRepository)
        {
            try
            {
                Model.Sage.F_ARTICLERepository F_ARTICLERepository = new Model.Sage.F_ARTICLERepository();
                if (F_ARTICLERepository.ExistArticle(Article.Sag_Id))
                {
                    Model.Sage.F_ARTICLE F_ARTICLE = F_ARTICLERepository.ReadArticle(Article.Sag_Id);

                    Model.Local.AttributeGroupRepository        AttributeGroupRepository   = new Model.Local.AttributeGroupRepository();
                    Model.Prestashop.PsAttributeGroupRepository PsAttributeGroupRepository = new Model.Prestashop.PsAttributeGroupRepository();

                    Boolean isProductAttribute;

                    if (F_ARTICLE.AR_Gamme1 != null && F_ARTICLE.AR_Gamme1 != 0 &&
                        AttributeGroupRepository.ExistSage((int)F_ARTICLE.AR_Gamme1) &&
                        PsAttributeGroupRepository.ExistAttributeGroup((uint)AttributeGroupRepository.ReadSage((int)F_ARTICLE.AR_Gamme1).Pre_Id) &&
                        ((F_ARTICLE.AR_Gamme2 == null || F_ARTICLE.AR_Gamme2 == 0) ||
                         (AttributeGroupRepository.ExistSage((int)F_ARTICLE.AR_Gamme2) &&
                          PsAttributeGroupRepository.ExistAttributeGroup((uint)AttributeGroupRepository.ReadSage((int)F_ARTICLE.AR_Gamme2).Pre_Id))))
                    {
                        Model.Local.AttributeArticleRepository AttributeArticleRepository = new Model.Local.AttributeArticleRepository();
                        List <Model.Local.AttributeArticle>    ListAttributeArticle       = AttributeArticleRepository.ListArticleSync(Article.Art_Id, true);

                        Model.Prestashop.PsProductAttributeRepository PsProductAttributeRepository = new Model.Prestashop.PsProductAttributeRepository();
                        Model.Prestashop.PsProductAttribute           PsProductAttribute;

                        int CumulStockGammes = 0;
                        foreach (Model.Local.AttributeArticle AttributeArticle in ListAttributeArticle)
                        {
                            if (AttributeArticle.EnumereF_ARTENUMREF != null)
                            {
                                PsProductAttribute = new Model.Prestashop.PsProductAttribute();
                                isProductAttribute = false;

                                if (AttributeArticle.Pre_Id != null && AttributeArticle.Pre_Id != 0)
                                {
                                    if (PsProductAttributeRepository.ExistProductAttribute((UInt32)AttributeArticle.Pre_Id))
                                    {
                                        PsProductAttribute = PsProductAttributeRepository.ReadProductAttribute((UInt32)AttributeArticle.Pre_Id);
                                        isProductAttribute = true;
                                    }
                                }

                                if (isProductAttribute == true)
                                {
                                    if (Core.Global.GetConfig().MajPoidsSynchroStock)
                                    {
                                        SynchronisationArticle.ReadWeightAttribute(PsProduct, PsProductAttribute, F_ARTICLE, AttributeArticle.EnumereGamme1);
                                    }

                                    SynchronisationArticle.ReadQuantityAttribute(PsProductAttribute, F_ARTICLE, AttributeArticle.EnumereGamme1, AttributeArticle.EnumereGamme2);
                                    CumulStockGammes += PsProductAttribute.Quantity;

                                    // <JG> 03/06/2016
                                    if (Article.Art_SyncPrice)
                                    {
                                        SynchronisationArticle.ReadPriceAttribute(PsProduct, PsProductAttribute, F_ARTICLE, AttributeArticle.EnumereGamme1, AttributeArticle.EnumereGamme2, TaxeTVA);
                                    }

                                    PsProductAttributeRepository.Save();
                                    SynchronisationArticle.ExecShopProductAttribute(PsProductAttribute);

                                    SynchronisationArticle.WriteStockAvailableProductAttribute(PsProduct, PsProductAttribute);
                                }
                            }
                        }
                        if (PsProduct.Quantity != CumulStockGammes)
                        {
                            PsProduct.Quantity = CumulStockGammes;
                            PsProductRepository.Save();
                        }
                        PsProductAttributeRepository.WriteDate(PsProduct.IDProduct);
                    }
                }
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError(ex.ToString());
            }
        }
Esempio n. 10
0
        private void ExecLocalToDistant(Model.Local.Article Article, Model.Prestashop.PsProduct Product, Model.Prestashop.PsProductRepository PsProductRepository)
        {
            try
            {
                if (Article.TypeArticle == Model.Local.Article.enum_TypeArticle.ArticleComposition)
                {
                    if (Core.UpdateVersion.License.Option2)
                    {
                        Product.Quantity = 0;
                        SynchronisationArticle.WriteStockAvailableProduct(Product);
                        ExecCompositionArticle(Article, Product);
                    }
                }
                else
                {
                    Model.Sage.F_ARTICLERepository F_ARTICLERepository = new Model.Sage.F_ARTICLERepository();
                    if (F_ARTICLERepository.ExistArticle(Article.Sag_Id))
                    {
                        Model.Sage.F_ARTICLE F_ARTICLE = F_ARTICLERepository.ReadArticle(Article.Sag_Id);
                        SynchronisationArticle.ReadQuantity(F_ARTICLE, Product);

                        #region Stock pack limité par composés
                        if (Article.Art_Pack == true || F_ARTICLE.AR_Nomencl == (short)ABSTRACTION_SAGE.F_ARTICLE.Obj._Enum_AR_Nomencl.Commerciale_Composant ||
                            F_ARTICLE.AR_Nomencl == (short)ABSTRACTION_SAGE.F_ARTICLE.Obj._Enum_AR_Nomencl.Commerciale_Compose)                                        // pour que les articles en nomenclature soient pris en compte
                        {
                            Model.Sage.F_NOMENCLATRepository F_NOMENCLATRepository = new Model.Sage.F_NOMENCLATRepository();
                            List <Model.Sage.F_NOMENCLAT>    ListF_NOMENCLAT       = F_NOMENCLATRepository.ListRef(F_ARTICLE.AR_Ref);
                            Model.Sage.F_ARTICLE             F_ARTICLENOMENCLAT;
                            Int32 QuantityPack = 0;
                            foreach (Model.Sage.F_NOMENCLAT F_NOMENCLAT in ListF_NOMENCLAT)
                            {
                                if (F_ARTICLERepository.ExistReference(F_NOMENCLAT.NO_RefDet))
                                {
                                    F_ARTICLENOMENCLAT = F_ARTICLERepository.ReadReference(F_NOMENCLAT.NO_RefDet);
                                    if (F_ARTICLENOMENCLAT.AR_SuiviStock != (short)ABSTRACTION_SAGE.F_ARTICLE.Obj._Enum_AR_SuiviStock.Aucun)                                            // pour ne pas prendre en compte les articles non suivi en stock
                                    {
                                        Int32 CurrentQuantity = SynchronisationArticle.ReadQuantityPack(F_ARTICLENOMENCLAT, F_NOMENCLAT.NO_Qte.Value);
                                        if (Core.Global.GetConfig().ArticleStockNegatifZero&& CurrentQuantity < 0)
                                        {
                                            CurrentQuantity = 0;
                                        }
                                        if (CurrentQuantity < QuantityPack)
                                        {
                                            QuantityPack = CurrentQuantity;
                                            // <AM> 14/08/2014 Si un des articles composant n'a pas de stock on sort de la fonction pour que l'article parent ai un stock à 0
                                            if (CurrentQuantity == 0)
                                            {
                                                break;
                                            }
                                        }
                                        else if (QuantityPack == 0)
                                        {
                                            QuantityPack = CurrentQuantity;
                                            // <AM> 14/08/2014 Si un des articles composant n'a pas de stock on sort de la fonction pour que l'article parent ai un stock à 0
                                            if (CurrentQuantity == 0)
                                            {
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                            Product.Quantity = QuantityPack;
                        }
                        #endregion

                        // <JG> 29/10/2012 ajout synchronisation des stocks seule
                        //SynchronisationArticle.ReadEcoTaxe(F_ARTICLE, Product);
                        //SynchronisationArticle.ReadPrice(F_ARTICLE, Product);

                        if (Core.Global.GetConfig().MajPoidsSynchroStock)
                        {
                            SynchronisationArticle.ReadWeight(F_ARTICLE, Product);
                        }

                        if (Core.Global.GetConfig().ArticleDateDispoInfoLibreActif)
                        {
                            SynchronisationArticle.ReadDateDispo(Product, F_ARTICLE);
                        }

                        PsProductRepository.Save();
                        PsProductRepository.WriteDate(Product.IDProduct);

                        this.ExecAttribute(Article, Product, PsProductRepository);
                        this.ExecConditioning(Article, Product, PsProductRepository);

                        //SynchronisationArticle.ExecSpecificPrice(F_ARTICLE, Product);

                        // <JG> 17/12/2012
                        SynchronisationArticle.ExecShopProduct(Product);

                        SynchronisationArticle.WriteStockAvailableProduct(Product);
                    }
                }
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError(ex.ToString());
            }
        }
Esempio n. 11
0
        public void Exec(Int32 ProductSend)
        {
            try
            {
                Model.Local.ArticleRepository ArticleRepository = new Model.Local.ArticleRepository();
                if (ArticleRepository.ExistPre_Id(ProductSend) == false)
                {
                    Model.Prestashop.PsProductLangRepository PsProductLangRepository = new Model.Prestashop.PsProductLangRepository();
                    if (PsProductLangRepository.ExistProductLang(ProductSend, Global.Lang, Global.CurrentShop.IDShop))
                    {
                        Model.Prestashop.PsProductRepository PsProductRepository = new Model.Prestashop.PsProductRepository();
                        Model.Prestashop.PsProduct           PsProduct           = PsProductRepository.ReadId(Convert.ToUInt32(ProductSend));
                        Model.Prestashop.PsProductLang       PsProductLang       = PsProductLangRepository.ReadProductLang(ProductSend, Global.Lang, Global.CurrentShop.IDShop);

                        Model.Sage.F_ARTICLERepository F_ARTICLERepository = new Model.Sage.F_ARTICLERepository();
                        string product_reference = PsProduct.Reference;
                        product_reference = product_reference.Replace(" ", "_");
                        if (F_ARTICLERepository.ExistReference(product_reference))
                        {
                            Model.Sage.F_ARTICLE F_ARTICLE = F_ARTICLERepository.ReadReference(product_reference);
                            Model.Local.Article  Article   = new Model.Local.Article()
                            {
                                Art_Name              = PsProductLang.Name,
                                Art_Description       = PsProductLang.Description,
                                Art_Description_Short = PsProductLang.DescriptionShort,
                                Art_LinkRewrite       = PsProductLang.LinkRewrite,
                                Art_MetaTitle         = PsProductLang.MetaTitle,
                                Art_MetaKeyword       = PsProductLang.MetaKeywords,
                                Art_MetaDescription   = PsProductLang.MetaDescription,
                                Art_Ref             = PsProduct.Reference,
                                Art_Ean13           = PsProduct.EAn13,
                                Art_Pack            = PsProduct.CacheIsPack == 1,
                                Art_Solde           = Convert.ToBoolean(PsProduct.OnSale),
                                Art_Active          = Convert.ToBoolean(PsProduct.Active),
                                Art_Sync            = true,
                                Art_SyncPrice       = true,
                                Art_Date            = (PsProduct.DateUpd != null && PsProduct.DateUpd > new DateTime(1753, 1, 2)) ? PsProduct.DateUpd : DateTime.Now.Date,
                                Sag_Id              = F_ARTICLE.cbMarq,
                                Pre_Id              = Convert.ToInt32(PsProduct.IDProduct),
                                Cat_Id              = this.ReadCatalog(PsProduct.IDCategoryDefault),
                                Art_RedirectType    = new Model.Internal.RedirectType(Core.Parametres.RedirectType.NoRedirect404).Page,
                                Art_RedirectProduct = 0,
                                Art_Manufacturer    = (PsProduct.IDManufacturer != null) ? (int)PsProduct.IDManufacturer : 0,
                                Art_Supplier        = (PsProduct.IDSupplier != null) ? (int)PsProduct.IDSupplier : 0,
                            };

                            if (Article.Cat_Id == 0)
                            {
                                foreach (Model.Prestashop.PsCategoryProduct PsCategoryProduct in new Model.Prestashop.PsCategoryProductRepository().ListProduct(PsProduct.IDProduct))
                                {
                                    Article.Cat_Id = this.ReadCatalog(PsCategoryProduct.IDCategory);
                                    if (Article.Cat_Id != 0)
                                    {
                                        break;
                                    }
                                }
                            }

                            if (PsProduct.CacheIsPack == 1)
                            {
                                Article.Art_Pack = true;
                            }
                            if (Article.Cat_Id != 0)
                            {
                                ArticleRepository.Add(Article);
                                RecoveryChildData(Article, PsProduct, ArticleRepository, false);
                            }
                        }
                    }
                }
                else
                {
                    Model.Local.Article Article = ArticleRepository.ReadPre_Id(ProductSend);
                    Model.Prestashop.PsProductRepository PsProductRepository = new Model.Prestashop.PsProductRepository();
                    Model.Prestashop.PsProduct           PsProduct           = PsProductRepository.ReadId(Convert.ToUInt32(ProductSend));
                    RecoveryChildData(Article, PsProduct, ArticleRepository, true);
                }
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError(ex.ToString());
            }
        }