public void ReportInfosSynchro(Model.Local.Customer_Progress datas, Core.Temp._action_information_synchro action, string comment = null) { Context.Post(state => { switch (action) { case PRESTACONNECT.Core.Temp._action_information_synchro.debut: this.list_progress.Add(new Model.Local.Customer_Progress(datas)); break; case PRESTACONNECT.Core.Temp._action_information_synchro.fin: this.list_progress.Remove(list_progress.FirstOrDefault(p => p.CT_Num == datas.CT_Num)); break; case PRESTACONNECT.Core.Temp._action_information_synchro.refresh: this.list_progress.FirstOrDefault(p => p.CT_Num == datas.CT_Num).Comment = (comment != null) ? comment : datas.Comment; break; default: break; } listBoxProgress.ItemsSource = list_progress; }, null); }
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(); }