public void UploadAndDownloadFile([FromUri] int templateId, [FromUri] string lastBillingDate, [FromUri] string currentBillingDate)
        {
            var chargeMethodsList = _context.ChargeMethods
                                    .Include(x => x.ChargeTemplate)
                                    .Where(x => x.ChargeTemplate.Id == templateId)
                                    .OrderBy(x => x.From)
                                    .ToList();

            var fileGetter = new FilesGetter();
            var path       = fileGetter.GetAndSaveSingleFileFromHttpRequest(@"D:\TempFiles\");

            if (path == "")
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            var calculator = new InventoryFeeCalculator(path);

            calculator.RecalculateInventoryFeeInExcel(chargeMethodsList, chargeMethodsList.First().TimeUnit, lastBillingDate, currentBillingDate);

            //强行关闭Excel进程
            var killer = new ExcelKiller();

            killer.Dispose();

            //在静态变量中记录下载信息
            DownloadRecord.FileName = fileGetter.FileName;
            DownloadRecord.FilePath = path;
        }
        public IHttpActionResult GenerateNewStorageReport([FromUri] int templateId, [FromUri] string customerCode, [FromUri] DateTime lastBillingDate, [FromUri] DateTime currentBillingDate, [FromUri] float p1Discount, [FromUri] float p2Discount, [FromUri] bool isEstimatingCharge)
        {
            var closeDate = new DateTime(currentBillingDate.Year, currentBillingDate.Month, currentBillingDate.Day).AddDays(1);
            var startDate = new DateTime(lastBillingDate.Year, currentBillingDate.Month, currentBillingDate.Day);

            var warehouseLocationsInDb = _context2.WarehouseLocations.Select(x => x.WarehouseCode).ToArray();

            var customerId = _context2.UpperVendors.SingleOrDefault(x => x.CustomerCode == customerCode).Id;
            var generator  = new FBAExcelGenerator(@"D:\Template\StorageFee-Template.xlsx");
            var fullPath   = generator.GenerateStorageReport(customerId, lastBillingDate, closeDate, p1Discount, p2Discount, warehouseLocationsInDb, false);

            var chargeMethodsList = _context.ChargeMethods
                                    .Include(x => x.ChargeTemplate)
                                    .Where(x => x.ChargeTemplate.Id == templateId)
                                    .OrderBy(x => x.From)
                                    .ToList();

            var calculator = new InventoryFeeCalculator(fullPath);

            calculator.RecalculateInventoryFeeInExcel(chargeMethodsList, chargeMethodsList.First().TimeUnit, lastBillingDate.ToString("yyyy-MM-dd"), currentBillingDate.ToString("yyyy-MM-dd"));

            //强行关闭Excel进程
            var killer = new ExcelKiller();

            killer.Dispose();

            return(Ok(fullPath));
        }
        public IHttpActionResult GenerateNewStorageReportThroughPayload([FromBody] StorageChargePayload data)
        {
            var closeDate = new DateTime(data.CurrentBillingDate.Year, data.CurrentBillingDate.Month, data.CurrentBillingDate.Day).AddDays(1);
            var startDate = new DateTime(data.LastBillingDate.Year, data.CurrentBillingDate.Month, data.CurrentBillingDate.Day);

            var warehouseLocationsInDb = _context2.WarehouseLocations.Select(x => x.WarehouseCode).ToArray();
            var warehouseLocations     = data.WarehouseLocation.Length > 0 ? data.WarehouseLocation : warehouseLocationsInDb;

            var customerId = _context2.UpperVendors.SingleOrDefault(x => x.CustomerCode == data.CustomerCode).Id;
            var generator  = new FBAExcelGenerator(@"D:\Template\StorageFee-Template.xlsx");
            var fullPath   = generator.GenerateStorageReport(customerId, data.LastBillingDate, closeDate, data.P1Discount, data.P2Discount, warehouseLocations, data.IncludePrereleasedOrder);

            var chargeMethodsList = _context.ChargeMethods
                                    .Include(x => x.ChargeTemplate)
                                    .Where(x => x.ChargeTemplate.Id == data.TemplateId)
                                    .OrderBy(x => x.From)
                                    .ToList();

            var calculator = new InventoryFeeCalculator(fullPath);

            calculator.RecalculateInventoryFeeInExcel(chargeMethodsList, chargeMethodsList.First().TimeUnit, data.LastBillingDate.ToString("yyyy-MM-dd"), data.CurrentBillingDate.ToString("yyyy-MM-dd"));

            //强行关闭Excel进程
            var killer = new ExcelKiller();

            killer.Dispose();

            return(Ok(fullPath));
        }