public void AutoBuyAmazonNextDay()
        {
            var orderHistoryService = new OrderHistoryService(_log, _time, _dbFactory);
            var batchManager        = new BatchManager(_log, _time, orderHistoryService, _weightService);
            var actionService       = new SystemActionService(_log, _time);
            var serviceFactory      = new ServiceFactory();

            var labelBatchService = new LabelBatchService(_dbFactory,
                                                          actionService,
                                                          _log,
                                                          _time,
                                                          _weightService,
                                                          serviceFactory,
                                                          _emailService,
                                                          batchManager,
                                                          _pdfMaker,
                                                          AddressService.Default,
                                                          orderHistoryService,
                                                          AppSettings.DefaultCustomType,
                                                          AppSettings.LabelDirectory,
                                                          AppSettings.ReserveDirectory,
                                                          AppSettings.TemplateDirectory,
                                                          new LabelBatchService.Config(),
                                                          AppSettings.IsSampleLabels);

            var autoPurchaseService = new LabelAutoBuyService(_dbFactory,
                                                              _log,
                                                              _time,
                                                              batchManager,
                                                              labelBatchService,
                                                              actionService,
                                                              _emailService,
                                                              _weightService,
                                                              _company.Id);

            autoPurchaseService.PurchaseAmazonNextDay();
        }
Пример #2
0
        public void CheckOverdue(IUnitOfWork db,
                                 DateTime when,
                                 TimeSpan autoPrintTime)
        {
            var overdueOrdersInfoes = LabelAutoBuyService.GetOverdueOrderInfos(db, when);

            _log.Info("Overdue orders count=" + overdueOrdersInfoes.Count);
            _log.Info("Overdue orders: " + String.Join(", ", overdueOrdersInfoes.Select(o => o.OrderId).ToList()));

            if (overdueOrdersInfoes.Count > 5)
            {
                var message = String.Format("{0}: Total/In batches: {1}/{2} orders are not processed and will be overdue. Auto purchase at: {3}",
                                            PortalEnum.PA.ToString(),
                                            overdueOrdersInfoes.Count,
                                            overdueOrdersInfoes.Where(i => i.BatchId.HasValue).Count(),
                                            autoPrintTime.ToString("hh\\:mm"));

                _emailService.SendSmsEmail(message,
                                           _company.SellerAlertEmail);

                _emailService.SendSystemEmailToAdmin(message, message);
                _emailService.SendSystemEmail(message, message, "*****@*****.**", null, null);
            }
        }
        protected override void RunCallback()
        {
            CompanyDTO company   = null;
            var        dbFactory = new DbFactory();
            var        time      = new TimeService(dbFactory);
            var        log       = GetLogger();

            var now = time.GetAppNowTime();

            if (!time.IsBusinessDay(now))
            {
                return;
            }

            using (var db = dbFactory.GetRDb())
            {
                company = db.Companies.GetByIdWithSettingsAsDto(CompanyId);
            }
            var fromAddressList = new CompanyAddressService(company);

            var serviceFactory = new ServiceFactory();
            var pdfMaker       = new PdfMakerByIText(GetLogger());
            var actionService  = new SystemActionService(log, time);
            var addressService = new AddressService(null,
                                                    fromAddressList.GetReturnAddress(MarketIdentifier.Empty()),
                                                    fromAddressList.GetPickupAddress(MarketIdentifier.Empty()));
            var emailSmtpSettings = SettingsBuilder.GetSmtpSettingsFromCompany(company, AppSettings.IsDebug, AppSettings.IsSampleLabels);
            var emailService      = new EmailService(GetLogger(), emailSmtpSettings, addressService);

            var weightService = new WeightService();

            var orderHistoryService = new OrderHistoryService(log, time, dbFactory);
            var batchManager        = new BatchManager(log, time, orderHistoryService, weightService);
            var labelBatchService   = new LabelBatchService(dbFactory,
                                                            actionService,
                                                            log,
                                                            time,
                                                            weightService,
                                                            serviceFactory,
                                                            emailService,
                                                            batchManager,
                                                            pdfMaker,
                                                            AddressService.Default,
                                                            orderHistoryService,
                                                            AppSettings.DefaultCustomType,
                                                            AppSettings.LabelDirectory,
                                                            AppSettings.ReserveDirectory,
                                                            AppSettings.TemplateDirectory,
                                                            new LabelBatchService.Config()
            {
                PrintErrorsToEmails = new[] { company.SellerEmail, company.SellerWarehouseEmailAddress },
                PrintErrorsCCEmails = new[] { EmailHelper.RaananEmail, EmailHelper.SupportDgtexEmail },
            },
                                                            AppSettings.IsSampleLabels);

            var autoPurchaseService = new LabelAutoBuyService(dbFactory,
                                                              log,
                                                              time,
                                                              batchManager,
                                                              labelBatchService,
                                                              actionService,
                                                              emailService,
                                                              weightService,
                                                              company.Id);

            autoPurchaseService.PurchaseAmazonNextDay();
        }