public IActionResult GetXls(string no, string unit, string category, DateTime?dateFrom, DateTime?dateTo)
        {
            try
            {
                byte[] xlsInBytes;

                var xls = importPurchasingBookReportFacade.GenerateExcel(no, unit, category, dateFrom, dateTo);

                string filename = "Laporan Buku Pembelian Impor";

                if (dateFrom != null)
                {
                    filename += " " + ((DateTime)dateFrom).ToString("dd-MM-yyyy");
                }

                if (dateTo != null)
                {
                    filename += "_" + ((DateTime)dateTo).ToString("dd-MM-yyyy");
                }
                filename += ".xlsx";

                xlsInBytes = xls.ToArray();
                var file = File(xlsInBytes, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", filename);
                return(file);
            }
            catch (Exception e)
            {
                Dictionary <string, object> Result =
                    new ResultFormatter(ApiVersion, General.INTERNAL_ERROR_STATUS_CODE, e.Message)
                    .Fail();
                return(StatusCode(General.INTERNAL_ERROR_STATUS_CODE, Result));
            }
        }
        public void Should_Success_Get_Report_Data_Excel_Null_Parameter()
        {
            var dbContext = _dbContext(GetCurrentMethod());
            UnitReceiptNoteFacade facade = new UnitReceiptNoteFacade(_ServiceProvider.Object, dbContext);
            var dataUtil = _dataUtil(facade, dbContext).GetTestData(USERNAME);
            //UnitReceiptNote urn = await _dataUtil.GetTestData2("unit-test");
            var DateFrom = DateTime.Now;

            DateFrom = DateFrom.Date;
            var DateTo = DateTime.Now;

            DateTo = DateTo.Date;
            ImportPurchasingBookReportFacade iprFacade = new ImportPurchasingBookReportFacade(_ServiceProvider.Object, dbContext);
            //var Response = facade.GetReport(null, null, null, DateFrom, DateTo);
            var Response = iprFacade.GenerateExcel(null, null, null, DateFrom, DateTo);

            Assert.IsType(typeof(System.IO.MemoryStream), Response);
        }
예제 #3
0
        public async Task Should_Success_GenerateExcel_Data_Empty()
        {
            var dbContext       = _dbContext(GetCurrentMethod());
            var serviceProvider = _getServiceProvider(GetCurrentMethod()).Object;

            var unitPaymentOrderFacade = new UnitPaymentOrderFacade(serviceProvider, dbContext);
            var dataUtil = await _dataUtil(unitPaymentOrderFacade, dbContext, GetCurrentMethod()).GetTestImportData();

            var urnId = dataUtil.Items.FirstOrDefault().URNId;
            var urn   = dbContext.UnitReceiptNotes.FirstOrDefault(f => f.Id.Equals(urnId));
            var prId  = urn.Items.FirstOrDefault(f => f.URNId.Equals(urn.Id)).PRId;
            var pr    = dbContext.PurchaseRequests.FirstOrDefault(f => f.Id.Equals(prId));

            var facade = new ImportPurchasingBookReportFacade(serviceProvider, dbContext);

            var result = await facade.GenerateExcel(urn.URNNo, 0, 0, DateTime.Now.AddDays(-7), DateTime.Now.AddDays(7), 0);

            Assert.NotNull(result);
        }