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(); }
public SynchronisationPaiement() { this.InitializeComponent(); this.LabelInformation.Content = "Recherche des paiements à copier ..."; this.worker.WorkerReportsProgress = true; this.worker.DoWork += delegate(object s, DoWorkEventArgs args) { if (Core.Global.GetConfig().SyncReglementActif) { this.worker.ReportProgress(-42); Connexion = Core.Global.GetODBC(); if (Connexion != null) { Model.Prestashop.PsOrdersRepository PsOrdersRepository = new Model.Prestashop.PsOrdersRepository(); Model.Prestashop.PsOrderPaymentRepository PsOrderPaymentRepository = new Model.Prestashop.PsOrderPaymentRepository(); Model.Local.OrderRepository OrderRepository = new Model.Local.OrderRepository(); Model.Local.OrderPaymentRepository OrderPaymentRepository = new Model.Local.OrderPaymentRepository(); Model.Sage.F_DOCENTETERepository F_DOCENTETERepository = new Model.Sage.F_DOCENTETERepository(); List <Model.Prestashop.order_payment> list_order = PsOrdersRepository.ListIDPayment(Core.Global.CurrentShop.IDShop); foreach (Model.Prestashop.order_payment order in list_order) { try { // comparaison nombre de paiements PrestaShop avec ceux déjà transférés if (OrderRepository.ExistPrestashop((int)order.id_order) && F_DOCENTETERepository.ExistWeb(order.id_order.ToString()) && PsOrderPaymentRepository.CountOrderReference(order.reference) > OrderPaymentRepository.CountOrder((int)order.id_order)) // pour ne pas prendre en compte les articles non suivi en stock { // récupération du dernier document Sage Model.Sage.F_DOCENTETE F_DOCENTETE = F_DOCENTETERepository.ListWeb(order.id_order.ToString()).FirstOrDefault(); ABSTRACTION_SAGE.F_DOCENTETE.Obj ObjF_DOCENTETE = new ABSTRACTION_SAGE.F_DOCENTETE.Obj() { DO_Domaine = (ABSTRACTION_SAGE.F_DOCENTETE.Obj._Enum_DO_Domaine)F_DOCENTETE.DO_Domaine, DO_Type = (ABSTRACTION_SAGE.F_DOCENTETE.Obj._Enum_DO_Type)F_DOCENTETE.DO_Type, DO_Piece = F_DOCENTETE.DO_Piece }; ObjF_DOCENTETE.ReadDO_Domaine_DO_Type_DO_Piece(Connexion, false); if (ObjF_DOCENTETE != null) { Model.Prestashop.PsOrders PsOrders = PsOrdersRepository.ReadOrder((int)order.id_order); Core.Sync.SynchronisationCommande form = new Core.Sync.SynchronisationCommande(); bool exist_payment; form.ExecReglement(PsOrders, Connexion, ObjF_DOCENTETE, out exist_payment); } } } catch (Exception ex) { Core.Error.SendMailError("[SYNCHRONISATION REGLEMENTS]" + ex.ToString()); } lock (this) { this.CurrentCount += 1; } this.worker.ReportProgress((this.CurrentCount * 100 / list_order.Count)); } } } }; this.worker.ProgressChanged += delegate(object s, ProgressChangedEventArgs args) { if (args.ProgressPercentage >= 0) { this.ProgressBar.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(); }