public async Task <IActionResult> Put([FromRoute] int id, [FromBody] UnitReceiptNoteViewModel vm)
        {
            identityService.Token    = Request.Headers["Authorization"].First().Replace("Bearer ", "");
            identityService.Username = User.Claims.Single(p => p.Type.Equals("username")).Value;

            UnitReceiptNote m = _mapper.Map <UnitReceiptNote>(vm);

            IValidateService validateService = (IValidateService)_serviceProvider.GetService(typeof(IValidateService));

            try
            {
                validateService.Validate(vm);

                int result = await _facade.Update(id, m, identityService.Username);

                return(NoContent());
            }
            catch (ServiceValidationExeption e)
            {
                Dictionary <string, object> Result =
                    new ResultFormatter(ApiVersion, General.BAD_REQUEST_STATUS_CODE, General.BAD_REQUEST_MESSAGE)
                    .Fail(e);
                return(BadRequest(Result));
            }
            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 async Task Should_Error_Update_Invalid_Data()
        {
            UnitReceiptNote model = await DataUtil.GetTestData("dev2");

            var responseGetById = await this.Client.GetAsync($"{URI}/{model.Id}");

            var json = responseGetById.Content.ReadAsStringAsync().Result;

            Dictionary <string, object> result = JsonConvert.DeserializeObject <Dictionary <string, object> >(json.ToString());

            Assert.True(result.ContainsKey("apiVersion"));
            Assert.True(result.ContainsKey("message"));
            Assert.True(result.ContainsKey("data"));
            Assert.True(result["data"].GetType().Name.Equals("JObject"));

            UnitReceiptNoteViewModel viewModel = JsonConvert.DeserializeObject <UnitReceiptNoteViewModel>(result.GetValueOrDefault("data").ToString());

            viewModel.date     = DateTimeOffset.MinValue;
            viewModel.supplier = null;
            viewModel.unit     = null;
            viewModel.items    = new List <UnitReceiptNoteItemViewModel> {
            };

            var response = await this.Client.PutAsync($"{URI}/{model.Id}", new StringContent(JsonConvert.SerializeObject(viewModel).ToString(), Encoding.UTF8, MediaType));

            Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
        }
Exemple #3
0
        public IActionResult GetPDF(int id)
        {
            try
            {
                var indexAcceptPdf = Request.Headers["Accept"].ToList().IndexOf("application/pdf");
                identityService.Username = User.Claims.Single(p => p.Type.Equals("username")).Value;
                UnitPaymentCorrectionNote model = _facade.ReadById(id);

                UnitPaymentCorrectionNoteViewModel viewModel = _mapper.Map <UnitPaymentCorrectionNoteViewModel>(model);

                if (indexAcceptPdf < 0)
                {
                    return(Ok(new
                    {
                        apiVersion = ApiVersion,
                        statusCode = General.OK_STATUS_CODE,
                        message = General.OK_MESSAGE,
                        data = viewModel,
                    }));
                }
                else
                {
                    int clientTimeZoneOffset               = int.Parse(Request.Headers["x-timezone-offset"].First());
                    UnitPaymentOrder          spbModel     = _spbFacade.ReadById((int)model.UPOId);
                    UnitPaymentOrderViewModel viewModelSpb = _mapper.Map <UnitPaymentOrderViewModel>(spbModel);
                    var supplier         = _facade.GetSupplier(model.SupplierId);
                    var supplier_address = "";
                    if (supplier != null)
                    {
                        supplier_address = supplier.address;
                    }

                    var temp_date = new DateTimeOffset();
                    foreach (var item in viewModel.items)
                    {
                        Lib.Models.UnitReceiptNoteModel.UnitReceiptNote urnModel = _facade.ReadByURNNo(item.uRNNo);
                        UnitReceiptNoteViewModel viewModelUrn = _mapper.Map <UnitReceiptNoteViewModel>(urnModel);
                        if (viewModelUrn != null && temp_date < viewModelUrn.date)
                        {
                            temp_date = viewModelUrn.date;
                        }
                    }
                    UnitPaymentQuantityCorrectionNotePDFTemplate PdfTemplate = new UnitPaymentQuantityCorrectionNotePDFTemplate();
                    MemoryStream stream = PdfTemplate.GeneratePdfTemplate(viewModel, viewModelSpb, temp_date, supplier_address, identityService.Username, clientTimeZoneOffset);

                    return(new FileStreamResult(stream, "application/pdf")
                    {
                        FileDownloadName = $"{model.UPCNo}.pdf"
                    });
                }
            }
            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 async Task Should_Success_Create_Data()
        {
            UnitReceiptNoteViewModel viewModel = await DataUtil.GetNewDataViewModel("dev2");

            HttpContent httpContent = new StringContent(JsonConvert.SerializeObject(viewModel).ToString(), Encoding.UTF8, MediaType);

            httpContent.Headers.Add("x-timezone-offset", "0");
            var response = await this.Client.PostAsync(URI, httpContent);

            Assert.Equal(HttpStatusCode.Created, response.StatusCode);
        }
        public async Task Should_Error_Create_Invalid_Data_Item()
        {
            UnitReceiptNoteViewModel viewModel = await DataUtil.GetNewDataViewModel("dev2");

            foreach (UnitReceiptNoteItemViewModel item in viewModel.items)
            {
                item.product           = null;
                item.deliveredQuantity = 0;
            }
            var response = await this.Client.PostAsync(URI, new StringContent(JsonConvert.SerializeObject(viewModel).ToString(), Encoding.UTF8, MediaType));

            Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
        }
        public async Task Should_Error_Create_Invalid_Date_Data()
        {
            DeliveryOrder ModelDO = await DataUtilDO.GetTestData("dev2");

            //var response1 = await this.Client.PostAsync(URI, new StringContent(JsonConvert.SerializeObject(viewModelDO).ToString(), Encoding.UTF8, MediaType));

            UnitReceiptNoteViewModel viewModel = await DataUtil.GetNewDataViewModel("dev2");

            viewModel.doId = ModelDO.Id.ToString();
            viewModel.date = ModelDO.DODate.AddDays(-90);
            var response = await this.Client.PostAsync(URI, new StringContent(JsonConvert.SerializeObject(viewModel).ToString(), Encoding.UTF8, MediaType));

            Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
        }
        public async Task Should_Error_Create_Invalid_Data()
        {
            UnitReceiptNoteViewModel viewModel = await DataUtil.GetNewDataViewModel("dev2");

            viewModel.date      = DateTimeOffset.MinValue;
            viewModel.unit      = null;
            viewModel.items     = new List <UnitReceiptNoteItemViewModel> {
            };
            viewModel.isStorage = true;
            viewModel.storage   = null;
            var response = await this.Client.PostAsync(URI, new StringContent(JsonConvert.SerializeObject(viewModel).ToString(), Encoding.UTF8, MediaType));

            Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
        }
        public async Task <IActionResult> Post([FromBody] UnitReceiptNoteViewModel vm)
        {
            identityService.Token    = Request.Headers["Authorization"].First().Replace("Bearer ", "");
            identityService.Username = User.Claims.Single(p => p.Type.Equals("username")).Value;
            if (vm.supplier != null)
            {
                if (vm.no == "" || vm.no == null)
                {
                    if (vm.supplier.import == true)
                    {
                        vm.no = "BPI";
                    }
                    else
                    {
                        vm.no = "BPL";
                    }
                }
            }

            UnitReceiptNote m = _mapper.Map <UnitReceiptNote>(vm);

            IValidateService validateService = (IValidateService)_serviceProvider.GetService(typeof(IValidateService));

            try
            {
                validateService.Validate(vm);

                int result = await _facade.Create(m, identityService.Username);

                Dictionary <string, object> Result =
                    new ResultFormatter(ApiVersion, General.CREATED_STATUS_CODE, General.OK_MESSAGE)
                    .Ok();
                return(Created(String.Concat(Request.Path, "/", 0), Result));
            }
            catch (ServiceValidationExeption e)
            {
                Dictionary <string, object> Result =
                    new ResultFormatter(ApiVersion, General.BAD_REQUEST_STATUS_CODE, General.BAD_REQUEST_MESSAGE)
                    .Fail(e);
                return(BadRequest(Result));
            }
            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 static UnitReceiptNoteViewModel GetUnitReceiptNote(HttpClientTestService client)
        {
            var response = client.GetAsync($"{APIEndpoint.Purchasing}/unit-receipt-notes-basic?page=1&size=1").Result;

            response.EnsureSuccessStatusCode();

            var data = response.Content.ReadAsStringAsync();
            Dictionary <string, object> result = JsonConvert.DeserializeObject <Dictionary <string, object> >(data.Result.ToString());

            List <UnitReceiptNoteViewModel> list = JsonConvert.DeserializeObject <List <UnitReceiptNoteViewModel> >(result["data"].ToString());
            //List<UnitReceiptNoteViewModel.Item> item =
            UnitReceiptNoteViewModel UnitReceiptNote = list.First();

            return(UnitReceiptNote);
        }
        public void should_succes_instantiate()
        {
            //Act
            UnitReceiptNoteViewModel viewModel = new UnitReceiptNoteViewModel()
            {
                no       = "no",
                _id      = "1",
                unit     = new UnitViewModel(),
                items    = new List <UnitReceiptNoteViewModel.Item>(),
                supplier = new SupplierViewModel()
            };

            //Assert
            Assert.Equal("no", viewModel.no);
            Assert.NotNull(viewModel.unit);
            Assert.NotNull(viewModel.items);
            Assert.NotNull(viewModel.supplier);
            Assert.Equal("1", viewModel._id);
        }
        public IActionResult Get(int id)
        {
            try
            {
                var indexAcceptPdf = Request.Headers["Accept"].ToList().IndexOf("application/pdf");

                UnitReceiptNote          model     = _facade.ReadById(id);
                UnitReceiptNoteViewModel viewModel = _mapper.Map <UnitReceiptNoteViewModel>(model);
                if (viewModel == null)
                {
                    throw new Exception("Invalid Id");
                }
                if (indexAcceptPdf < 0)
                {
                    return(Ok(new
                    {
                        apiVersion = ApiVersion,
                        statusCode = General.OK_STATUS_CODE,
                        message = General.OK_MESSAGE,
                        data = viewModel,
                    }));
                }
                else
                {
                    UnitReceiptNotePDFTemplate PdfTemplate = new UnitReceiptNotePDFTemplate();
                    MemoryStream stream = PdfTemplate.GeneratePdfTemplate(viewModel);

                    return(new FileStreamResult(stream, "application/pdf")
                    {
                        FileDownloadName = $"{viewModel.no}.pdf"
                    });
                }
            }
            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));
            }
        }
Exemple #12
0
        public override FpRegradingResultDocs GetNewData()
        {
            UnitReceiptNoteViewModel unit = UnitReceiptNoteDataUtil.GetUnitReceiptNote(client);
            //ProductViewModel product = ProductDataUtil.GetProduct(client);
            MachineViewModel machine = MachineDataUtil.GetMachine(client);
            //SupplierViewModel supplier = SupplierDataUtil.GetSupplier(client);

            FpRegradingResultDocs TestData = new FpRegradingResultDocs
            {
                Date    = DateTimeOffset.UtcNow,
                NoBon   = unit.no,
                NoBonId = unit._id,

                MachineId   = machine._id,
                MachineCode = machine.code,
                MachineName = machine.name,

                ProductId   = unit.items[0].product._id,
                ProductCode = unit.items[0].product.code,
                ProductName = unit.items[0].product.name,

                SupplierId    = unit.supplier._id,
                SupplierCode  = unit.supplier.code,
                SupplierName  = unit.supplier.name,
                Operator      = "operator test",
                Shift         = "shift 1 test",
                TotalLength   = 100,
                OriginalGrade = "test grade",
                Remark        = "test remark",
                UnitName      = "PRINTING",

                Details = new List <FpRegradingResultDocsDetails> {
                    fpRegradingResultDetailsDataUtil.GetNewData()
                }
            };

            return(TestData);
        }
        public MemoryStream GeneratePdfTemplate(UnitReceiptNoteViewModel viewModel)
        {
            Font header_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 12);
            Font normal_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8);
            Font bold_font   = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8);

            Document     document = new Document(PageSize.A6.Rotate(), 15, 15, 15, 15);
            MemoryStream stream   = new MemoryStream();
            PdfWriter    writer   = PdfWriter.GetInstance(document, stream);

            document.Open();

            #region Header

            string    titleString = "BON PENERIMAAN BARANG";
            Paragraph title       = new Paragraph(titleString, bold_font)
            {
                Alignment = Element.ALIGN_CENTER
            };
            document.Add(title);

            string    companyNameString = "PT. MULTIYASA ABADI SENTOSA";
            Paragraph companyName       = new Paragraph(companyNameString, header_font)
            {
                Alignment = Element.ALIGN_LEFT
            };
            document.Add(companyName);

            PdfPTable tableHeader = new PdfPTable(2);
            tableHeader.SetWidths(new float[] { 4f, 4f });
            PdfPCell cellHeaderContentLeft = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT
            };
            PdfPCell cellHeaderContentRight = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT
            };

            cellHeaderContentLeft.Phrase = new Phrase("BANARAN, GROGOL, SUKOHARJO", bold_font);
            tableHeader.AddCell(cellHeaderContentLeft);

            //cellHeaderContentRight.Phrase = new Phrase("FM-PB-00-06-010/R1", bold_font);
            //tableHeader.AddCell(cellHeaderContentRight);

            PdfPCell cellHeader = new PdfPCell(tableHeader);
            tableHeader.ExtendLastRow = false;
            tableHeader.SpacingAfter  = 10f;
            document.Add(tableHeader);

            LineSeparator lineSeparator = new LineSeparator(1f, 100f, BaseColor.Black, Element.ALIGN_CENTER, 1);
            document.Add(lineSeparator);


            #endregion

            #region Identity


            PdfPTable tableIdentity = new PdfPTable(4);
            tableIdentity.SetWidths(new float[] { 3f, 7f, 2f, 5f });
            PdfPCell cellIdentityContentLeft = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT
            };

            cellIdentityContentLeft.Phrase = new Phrase("Tanggal", normal_font);
            tableIdentity.AddCell(cellIdentityContentLeft);
            cellIdentityContentLeft.Phrase = new Phrase(": " + viewModel.date.ToString("dd/MM/yyyy", new CultureInfo("id-ID")), normal_font);
            tableIdentity.AddCell(cellIdentityContentLeft);
            cellIdentityContentLeft.Phrase = new Phrase("Bagian", normal_font);
            tableIdentity.AddCell(cellIdentityContentLeft);
            cellIdentityContentLeft.Phrase = new Phrase(": " + viewModel.unit.name, normal_font);
            tableIdentity.AddCell(cellIdentityContentLeft);
            cellIdentityContentLeft.Phrase = new Phrase("Diterima dari", normal_font);
            tableIdentity.AddCell(cellIdentityContentLeft);
            cellIdentityContentLeft.Phrase = new Phrase(": " + viewModel.supplier.name, normal_font);
            tableIdentity.AddCell(cellIdentityContentLeft);
            cellIdentityContentLeft.Phrase = new Phrase("No.", normal_font);
            tableIdentity.AddCell(cellIdentityContentLeft);
            cellIdentityContentLeft.Phrase = new Phrase(": " + viewModel.no, normal_font);
            tableIdentity.AddCell(cellIdentityContentLeft);

            PdfPCell cellIdentity = new PdfPCell(tableIdentity);
            tableIdentity.ExtendLastRow = false;
            tableIdentity.SpacingAfter  = 10f;
            tableIdentity.SpacingBefore = 10f;
            document.Add(tableIdentity);

            #endregion

            #region TableContent

            PdfPCell cellCenter = new PdfPCell()
            {
                Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 5
            };
            PdfPCell cellRight = new PdfPCell()
            {
                Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 5
            };
            PdfPCell cellLeft = new PdfPCell()
            {
                Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 5
            };

            PdfPTable tableContent = new PdfPTable(5);
            tableContent.SetWidths(new float[] { 1.5f, 9f, 2.5f, 2.5f, 5f });

            cellCenter.Phrase = new Phrase("No", bold_font);
            tableContent.AddCell(cellCenter);
            cellCenter.Phrase = new Phrase("Nama Barang", bold_font);
            tableContent.AddCell(cellCenter);
            cellCenter.Phrase = new Phrase("Jumlah", bold_font);
            tableContent.AddCell(cellCenter);
            cellCenter.Phrase = new Phrase("Satuan", bold_font);
            tableContent.AddCell(cellCenter);
            cellCenter.Phrase = new Phrase("Keterangan", bold_font);
            tableContent.AddCell(cellCenter);

            //for (int a = 0; a < 20; a++) // coba kalau banyak baris ^_^
            for (int indexItem = 0; indexItem < viewModel.items.Count; indexItem++)
            {
                UnitReceiptNoteItemViewModel item = viewModel.items[indexItem];

                cellCenter.Phrase = new Phrase((indexItem + 1).ToString(), normal_font);
                tableContent.AddCell(cellCenter);

                cellLeft.Phrase = new Phrase($"{item.product.code} - {item.product.name}", normal_font);
                tableContent.AddCell(cellLeft);
                //cellCenter.Phrase = new Phrase(string.Format("{0:n2}", item.deliveredQuantity), normal_font);
                cellCenter.Phrase = new Phrase($"{item.deliveredQuantity}", normal_font);
                tableContent.AddCell(cellCenter);

                cellLeft.Phrase = new Phrase(item.product.uom.unit, normal_font);
                tableContent.AddCell(cellLeft);

                cellCenter.Phrase = new Phrase(item.prNo + "\n" + item.productRemark, normal_font);
                tableContent.AddCell(cellCenter);
            }


            PdfPCell cellContent = new PdfPCell(tableContent);
            tableContent.ExtendLastRow = false;
            tableContent.SpacingAfter  = 10f;
            document.Add(tableContent);

            #endregion


            Paragraph date = new Paragraph($"Sukoharjo, {viewModel.date.ToString("dd MMMM yyyy", new CultureInfo("id-ID"))}", normal_font)
            {
                Alignment = Element.ALIGN_RIGHT
            };
            document.Add(date);

            #region TableSignature

            PdfPTable tableSignature = new PdfPTable(2);

            PdfPCell cellSignatureContent = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_CENTER
            };
            cellSignatureContent.Phrase = new Phrase("Mengetahui\n\n\n\n\n(  _____________________  )", bold_font);
            tableSignature.AddCell(cellSignatureContent);
            cellSignatureContent.Phrase = new Phrase("Yang Menerima\n\n\n\n\n(  _____________________  )", bold_font);
            tableSignature.AddCell(cellSignatureContent);


            PdfPCell cellSignature = new PdfPCell(tableSignature); // dont remove
            tableSignature.ExtendLastRow = false;
            tableSignature.SpacingBefore = 10f;
            document.Add(tableSignature);

            #endregion

            document.Close();
            byte[] byteInfo = stream.ToArray();
            stream.Write(byteInfo, 0, byteInfo.Length);
            stream.Position = 0;

            return(stream);
        }