Example #1
0
 /**
  * Constructor
  * @param fm a FileMaker to provide a stream for every new document
  * @param tag the tag on with to create a new document and close it
  * @param opentag the tag on which to open the document ( {@link Document#open()}
  * @param pagesize the pagesize for the documents
  *
  */
 public AutoDocPipeline(IFileMaker fm, String tag, String opentag, Rectangle pagesize) : base(null)
 {
     this.fm       = fm;
     this.tag      = tag;
     this.opentag  = opentag;
     this.pagesize = pagesize;
 }
Example #2
0
 public ExportClientHistoryCommandHandler(
     IHistoryClient historyClient,
     IFileMaker fileMaker,
     IFileUploader fileUploader,
     IFileMapper fileMapper,
     IExpiryWatcher expiryWatcher,
     TimeSpan ttl)
 {
     _historyClient = historyClient;
     _fileMaker     = fileMaker;
     _fileUploader  = fileUploader;
     _fileMapper    = fileMapper;
     _expiryWatcher = expiryWatcher;
     _ttl           = ttl;
 }
        public CallPrintProcessing(
            ILogService log,
            ITime time,
            IDbFactory dbFactory,
            IEmailService emailService,
            CompanyDTO company,
            string outputDirectory,
            string templateDirectory,
            string reserveDirectory)
        {
            _log           = log;
            _time          = time;
            _company       = company;
            _emailService  = emailService;
            _pdfMaker      = new PdfMakerByIText(_log);
            _dbFactory     = dbFactory;
            _weightService = new WeightService();

            _outputDirectory   = outputDirectory;
            _templateDirectory = templateDirectory;
            _reserveDirectory  = reserveDirectory;
        }
Example #4
0
        public LabelBatchService(IDbFactory dbFactory,
                                 ISystemActionService actionService,
                                 ILogService log,
                                 ITime time,
                                 IWeightService weightService,
                                 IServiceFactory serviceFactory,
                                 IEmailService emailService,
                                 IBatchManager batchManager,
                                 IFileMaker pdfMaker,
                                 IAddressService addressService,
                                 IOrderHistoryService orderHistoryService,
                                 string defaultCustomType,
                                 string labelDirectory,
                                 string reserveDirectory,
                                 string templateDirectory,
                                 Config config,
                                 bool isSampleMode)
        {
            _dbFactory           = dbFactory;
            _actionService       = actionService;
            _log                 = log;
            _time                = time;
            _weightService       = weightService;
            _serviceFactory      = serviceFactory;
            _emailService        = emailService;
            _batchManager        = batchManager;
            _pdfMaker            = pdfMaker;
            _addressService      = addressService;
            _orderHistoryService = orderHistoryService;

            _defaultCustomType = defaultCustomType;
            _labelDirectory    = labelDirectory;
            _reserveDirectory  = reserveDirectory;
            _templateDirectory = templateDirectory;
            _config            = config;
            _isSampleMode      = isSampleMode;
        }
Example #5
0
 /**
  * Constructor
  * @param fm a FileMaker to provide a stream for every new document
  * @param tag the tag on with to create a new document and close it
  * @param opentag the tag on which to open the document ( {@link Document#open()}
  * @param pagesize the pagesize for the documents
  *
  */
 public AutoDocPipeline(IFileMaker fm, String tag, String opentag, Rectangle pagesize)
     : base(null)
 {
     this.fm = fm;
     this.tag = tag;
     this.opentag = opentag;
     this.pagesize = pagesize;
 }
Example #6
0
        public CallResult <string> Closeout(IUnitOfWork db,
                                            IShipmentApi shipmentApi,
                                            IFileMaker pdfMaker,
                                            string outputDirectory,
                                            bool isSample,
                                            long?by)
        {
            _log.Info("Begin Closeout");
            var toCloseoutShippings = db.OrderShippingInfos.GetAllAsDto()
                                      .Where(sh => sh.ShipmentProviderType == (int)ShipmentProviderType.DhlECom &&
                                             !sh.ScanFormId.HasValue &&
                                             !sh.CancelLabelRequested &&
                                             !sh.LabelCanceled &&
                                             !String.IsNullOrEmpty(sh.StampsTxId))
                                      .ToList();

            var toCloseoutMails = db.MailLabelInfos.GetAllAsDto()
                                  .Where(m => m.ShipmentProviderType == (int)ShipmentProviderType.DhlECom &&
                                         !m.ScanFormId.HasValue &&
                                         !m.CancelLabelRequested &&
                                         !m.LabelCanceled &&
                                         !String.IsNullOrEmpty(m.StampsTxId))
                                  .ToList();

            //var shippingWithEmptyPackageIds = toCloseoutShippings.Where(sh => String.IsNullOrEmpty(sh.StampsTxId)).ToList();
            //if (shippingWithEmptyPackageIds.Any())
            //    return CallResult<string>.Fail("The following orders have has empty Package Id: "
            //        + String.Join(", ", shippingWithEmptyPackageIds.Select(sh => sh.OrderAmazonId).ToList()), null);

            //var mailingWithEmptyPackageIds = toCloseoutMails.Where(sh => String.IsNullOrEmpty(sh.StampsTxId)).ToList();
            //if (mailingWithEmptyPackageIds.Any())
            //    return CallResult<string>.Fail("The following orders have has empty Package Id: "
            //        + String.Join(", ", mailingWithEmptyPackageIds.Select(sh => sh.OrderAmazonId).ToList()), null);


            var closeoutIds = toCloseoutShippings.Select(sh => sh.StampsTxId).ToList();

            closeoutIds.AddRange(toCloseoutMails.Select(m => m.StampsTxId).ToList());

            _log.Info("Request closeout for Ids: " + String.Join(", ", closeoutIds));

            CallResult <IList <ScanFormInfo> > result = null;

            if (isSample)
            {
                result = CallResult <IList <ScanFormInfo> > .Success(new List <ScanFormInfo>()
                {
                    new ScanFormInfo()
                    {
                        ScanFormId   = "Test1",
                        ScanFormPath = "~/Closeouts/closeout_1_7027750.pdf"
                    }
                });
            }
            else
            {
                result = shipmentApi.GetScanForm(closeoutIds, null, DateTime.UtcNow);
            }
            _log.Info("Result: " + result.IsSuccess);

            if (result.IsSuccess)
            {
                var forms = result.Data;

                long?lastFormId = null;
                foreach (var form in forms)
                {
                    var dbForm = new ScanForm()
                    {
                        FormId     = form.ScanFormId,
                        FileName   = form.ScanFormPath,
                        CreateDate = _time.GetAppNowTime(),
                        CreatedBy  = by,
                    };
                    db.ScanForms.Add(dbForm);
                    db.Commit();
                    lastFormId = dbForm.Id;
                }

                var pdfFileName = pdfMaker.CreateFileWithLabels(new List <PrintLabelInfo>(),
                                                                forms.Select(s => outputDirectory + s.ScanFormPath.Trim(new[] { '~' })).ToList(),
                                                                null,
                                                                outputDirectory);

                var printPack = new LabelPrintPack()
                {
                    FileName   = pdfFileName,
                    CreateDate = _time.GetAppNowTime(),
                };
                db.LabelPrintPacks.Add(printPack);
                db.Commit();

                _log.Info("Begin update shipments");
                var fromDate          = _time.GetAppNowTime().AddDays(-30);
                var shipmentsToUpdate = db.OrderShippingInfos.GetAll().Where(sh => sh.CreateDate > fromDate &&
                                                                             closeoutIds.Contains(sh.StampsTxId))
                                        .ToList();
                var mailingsToUpdate = db.MailLabelInfos.GetAll().Where(sh => sh.CreateDate > fromDate &&
                                                                        closeoutIds.Contains(sh.StampsTxId))
                                       .ToList();

                foreach (var shipment in shipmentsToUpdate)
                {
                    shipment.ScanFormId = lastFormId;
                }
                db.Commit();
                foreach (var mailing in mailingsToUpdate)
                {
                    mailing.ScanFormId = lastFormId;
                }
                db.Commit();
                _log.Info("End update shipments");

                var url = Models.UrlHelper.GetPrintLabelPathById(printPack.Id);

                return(CallResult <string> .Success(url));
            }
            else
            {
                return(CallResult <string> .Fail(result.Message, null));
            }
        }
Example #7
0
        public CallResult <string> Closeout(IUnitOfWork db,
                                            IShipmentApi shipmentApi,
                                            IList <DropShipperApi> externalApis,
                                            IFileMaker pdfMaker,
                                            string outputDirectory,
                                            bool isSample,
                                            long?by)
        {
            _log.Info("Begin Closeout");
            var toCloseoutShippings = db.OrderShippingInfos.GetAllAsDto()
                                      .Where(sh => sh.ShipmentProviderType == (int)ShipmentProviderType.IBC &&
                                             !sh.ScanFormId.HasValue &&
                                             !sh.CancelLabelRequested &&
                                             !sh.LabelCanceled &&
                                             !String.IsNullOrEmpty(sh.StampsTxId))
                                      .ToList();

            var toCloseoutMails = db.MailLabelInfos.GetAllAsDto()
                                  .Where(m => m.ShipmentProviderType == (int)ShipmentProviderType.IBC &&
                                         !m.ScanFormId.HasValue &&
                                         !m.CancelLabelRequested &&
                                         !m.LabelCanceled &&
                                         !String.IsNullOrEmpty(m.StampsTxId))
                                  .ToList();

            var closeoutIds = toCloseoutShippings.Select(sh => sh.StampsTxId).ToList();

            closeoutIds.AddRange(toCloseoutMails.Select(m => m.StampsTxId).ToList());

            foreach (var extApi in externalApis)
            {
                var extInfo = extApi.GetIBCOrdersToClose();
                if (!extInfo.IsFail)
                {
                    var mbgCloseoutShippingIds = extInfo.Data.ToCloseoutIds;
                    _log.Info("External API " + extApi.Market + "-" + extApi.MarketplaceId + " closeout ids: " + String.Join(", ", mbgCloseoutShippingIds));
                    closeoutIds.AddRange(mbgCloseoutShippingIds);
                }
                else
                {
                    _log.Info("No communication with " + extApi.Market + "-" + extApi.MarketplaceId + ". Details: " + extInfo.Message);
                    //return CallResult<string>.Fail("No communication with " + extApi.Market + "-" + extApi.MarketplaceId + ". Details: " + extInfo.Message, null);
                }
            }

            _log.Info("Request closeout for Ids: " + String.Join(", ", closeoutIds));

            CallResult <IList <ScanFormInfo> > result = null;

            if (isSample)
            {
                result = CallResult <IList <ScanFormInfo> > .Success(new List <ScanFormInfo>()
                {
                    new ScanFormInfo()
                    {
                        ScanFormId   = "Test1",
                        ScanFormPath = "~/Closeouts/closeout_1_7027750.pdf"
                    }
                });
            }
            else
            {
                result = shipmentApi.GetScanForm(closeoutIds, null, DateTime.UtcNow);
            }
            _log.Info("Result: " + result.IsSuccess);

            if (result.IsSuccess)
            {
                var form = result.Data.FirstOrDefault();

                long?lastFormId = null;
                var  dbForm     = new ScanForm()
                {
                    FormId     = form.ScanFormId,
                    FileName   = form.ScanFormPath,
                    CreateDate = _time.GetAppNowTime(),
                    CreatedBy  = by,
                };
                db.ScanForms.Add(dbForm);
                db.Commit();
                lastFormId = dbForm.Id;

                _log.Info("Begin update shipments");
                var fromDate          = _time.GetAppNowTime().AddDays(-30);
                var shipmentsToUpdate = db.OrderShippingInfos.GetAll().Where(sh => sh.CreateDate > fromDate &&
                                                                             closeoutIds.Contains(sh.StampsTxId))
                                        .ToList();
                var mailingsToUpdate = db.MailLabelInfos.GetAll().Where(sh => sh.CreateDate > fromDate &&
                                                                        closeoutIds.Contains(sh.StampsTxId))
                                       .ToList();

                foreach (var shipment in shipmentsToUpdate)
                {
                    shipment.ScanFormId = lastFormId;
                }
                db.Commit();
                foreach (var mailing in mailingsToUpdate)
                {
                    mailing.ScanFormId = lastFormId;
                }
                db.Commit();
                _log.Info("End update shipments");

                _log.Info("Form: " + (form.CloseoutIds != null ? String.Join(",", form.CloseoutIds) : "null"));

                foreach (var extApi in externalApis)
                {
                    _log.Info("Begin update " + extApi.Market + "-" + extApi.MarketplaceId + " shipments");
                    var closeResult = extApi.CloseIBCOrders(form);
                    _log.Info("Close result: isSuccess: " + closeResult.IsSuccess + ", message: " + closeResult.Message);
                    _log.Info("End update shipments");
                }

                return(CallResult <string> .Success(""));
            }
            else
            {
                return(CallResult <string> .Fail(result.Message, null));
            }
        }