public IActionResult GetIncomePDF(int id)
        {
            try
            {
                identityService.Token = Request.Headers["Authorization"].FirstOrDefault().Replace("Bearer ", "");
                var indexAcceptPdf = Request.Headers["Accept"].ToList().IndexOf("application/pdf");

                GarmentInvoice          model     = facade.ReadById(id);
                GarmentInvoiceViewModel viewModel = mapper.Map <GarmentInvoiceViewModel>(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
                {
                    int clientTimeZoneOffset = int.Parse(Request.Headers["x-timezone-offset"].First());

                    /* tambahan */
                    /* get gsupplier */
                    string supplierUri = "master/garment-suppliers";
                    var    httpClient  = (IHttpClientService)serviceProvider.GetService(typeof(IHttpClientService));
                    var    response    = httpClient.GetAsync($"{Lib.Helpers.APIEndpoint.Core}{supplierUri}/{model.SupplierId}").Result.Content.ReadAsStringAsync();
                    Dictionary <string, object> result   = JsonConvert.DeserializeObject <Dictionary <string, object> >(response.Result);
                    SupplierViewModel           supplier = JsonConvert.DeserializeObject <SupplierViewModel>(result.GetValueOrDefault("data").ToString());
                    /* tambahan */

                    IncomeTaxPDFTemplate PdfTemplateLocal = new IncomeTaxPDFTemplate();
                    MemoryStream         stream           = PdfTemplateLocal.GeneratePdfTemplate(viewModel, supplier, clientTimeZoneOffset, DOfacade);

                    return(new FileStreamResult(stream, "application/pdf")
                    {
                        FileDownloadName = $"{viewModel.nph}.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));
            }
        }
Beispiel #2
0
        public IActionResult GetVatPDF(int id)
        {
            try
            {
                var indexAcceptPdf = Request.Headers["Accept"].ToList().IndexOf("application/pdf");

                GarmentInvoice          model     = facade.ReadById(id);
                GarmentInvoiceViewModel viewModel = mapper.Map <GarmentInvoiceViewModel>(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
                {
                    int clientTimeZoneOffset = int.Parse(Request.Headers["x-timezone-offset"].First());

                    VatPDFTemplate PdfTemplateLocal = new VatPDFTemplate();
                    MemoryStream   stream           = PdfTemplateLocal.GeneratePdfTemplate(viewModel, clientTimeZoneOffset, DOfacade);

                    return(new FileStreamResult(stream, "application/pdf")
                    {
                        FileDownloadName = $"{viewModel.npn}.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 <IActionResult> Post([FromBody] GarmentInvoiceViewModel ViewModel)
        {
            try
            {
                identityService.Username = User.Claims.Single(p => p.Type.Equals("username")).Value;
                identityService.Token    = Request.Headers["Authorization"].FirstOrDefault().Replace("Bearer ", "");

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

                validateService.Validate(ViewModel);

                var model = mapper.Map <GarmentInvoice>(ViewModel);

                await facade.Create(model, 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(StatusCode(General.BAD_REQUEST_STATUS_CODE, Result));
                //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));
            }
        }
Beispiel #4
0
        public MemoryStream GeneratePdfTemplate(GarmentInvoiceViewModel viewModel, int clientTimeZoneOffset, IGarmentDeliveryOrderFacade DOfacade)
        {
            Font header_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 18);
            Font normal_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 9);
            Font bold_font   = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8);
            //Font header_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8);

            Document document = new Document(PageSize.A4, 40, 40, 40, 40);

            document.AddHeader("Header", viewModel.nph);
            MemoryStream stream = new MemoryStream();
            PdfWriter    writer = PdfWriter.GetInstance(document, stream);

            writer.PageEvent = new PDFPages();
            document.Open();

            Chunk        chkHeader = new Chunk(" ");
            Phrase       pheader   = new Phrase(chkHeader);
            HeaderFooter header    = new HeaderFooter(pheader, false);

            header.Border    = Rectangle.NO_BORDER;
            header.Alignment = Element.ALIGN_RIGHT;
            document.Header  = header;


            #region Header

            PdfPTable tableHeader = new PdfPTable(1);
            tableHeader.SetWidths(new float[] { 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("PT AMBASSADOR GARMINDO" + "\n" + "Head Office : Kelurahan Banaran" + "\n" + "Kecamatan Grogol" + "\n" + "Sukoharjo 57193 - INDONESIA" + "\n" + "PO BOX 166 Solo 57100" + "\n" + "Telp. (0271) 714400, 7652913" + "\n" + "Fax. (0271) 735222, 740777", bold_font);
            tableHeader.AddCell(cellHeaderContentLeft);

            //string noPO = viewModel.Supplier.Import ? "FM-PB-00-06-009/R1" + "\n" + "PO: " + EPONo  : "PO: " + EPONo;


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

            string    titleString = "NOTA PAJAK PPH\n\n";
            Paragraph title       = new Paragraph(titleString, bold_font)
            {
                Alignment = Element.ALIGN_CENTER
            };
            document.Add(title);
            bold_font.SetStyle(Font.NORMAL);

            PdfPTable tableIncomeTax = new PdfPTable(1);
            tableIncomeTax.SetWidths(new float[] { 4.5f });
            PdfPCell cellTaxLeft = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT
            };
            cellTaxLeft.Phrase = new Phrase("No. Nota Pajak" + "    : " + viewModel.nph, normal_font);
            tableIncomeTax.AddCell(cellTaxLeft);
            cellTaxLeft.Phrase = new Phrase("Kode Supplier" + "      : " + viewModel.supplier.Code, normal_font);
            tableIncomeTax.AddCell(cellTaxLeft);
            cellTaxLeft.Phrase = new Phrase("Nama Supplier" + "     : " + viewModel.supplier.Name, normal_font);
            tableIncomeTax.AddCell(cellTaxLeft);

            PdfPCell cellSupplier = new PdfPCell(tableIncomeTax); // dont remove
            tableIncomeTax.ExtendLastRow = false;
            tableIncomeTax.SpacingAfter  = 10f;
            document.Add(tableIncomeTax);
            #endregion
            #region data
            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(6);
            tableContent.SetWidths(new float[] { 4.5f, 5f, 3.5f, 4f, 2.2f, 5f });
            cellCenter.Phrase = new Phrase("No Surat Jalan", bold_font);
            tableContent.AddCell(cellCenter);
            cellCenter.Phrase = new Phrase("Tanggal Surat Jalan", bold_font);
            tableContent.AddCell(cellCenter);
            cellCenter.Phrase = new Phrase("No Invoice", bold_font);
            tableContent.AddCell(cellCenter);
            cellCenter.Phrase = new Phrase("Nama Barang", bold_font);
            tableContent.AddCell(cellCenter);
            cellCenter.Phrase = new Phrase("Rate PPh", bold_font);
            tableContent.AddCell(cellCenter);
            cellCenter.Phrase = new Phrase("Sub Total PPh", bold_font);
            tableContent.AddCell(cellCenter);

            double total       = 0;
            double totalPPH    = 0;
            double totalPPHIDR = 0;
            foreach (GarmentInvoiceItemViewModel item in viewModel.items)
            {
                total += item.deliveryOrder.totalAmount;

                foreach (GarmentInvoiceDetailViewModel detail in item.details)
                {
                    cellLeft.Phrase = new Phrase(item.deliveryOrder.doNo, normal_font);
                    tableContent.AddCell(cellLeft);

                    string doDate = item.deliveryOrder.doDate.ToOffset(new TimeSpan(clientTimeZoneOffset, 0, 0)).ToString("dd MMMM yyyy", new CultureInfo("id-ID"));

                    cellLeft.Phrase = new Phrase(doDate, normal_font);
                    tableContent.AddCell(cellLeft);

                    cellLeft.Phrase = new Phrase(viewModel.invoiceNo, normal_font);
                    tableContent.AddCell(cellLeft);

                    cellLeft.Phrase = new Phrase(detail.product.Name, normal_font);
                    tableContent.AddCell(cellLeft);

                    cellRight.Phrase = new Phrase(viewModel.incomeTaxRate.ToString(), normal_font);
                    tableContent.AddCell(cellRight);

                    cellRight.Phrase = new Phrase(Math.Round(viewModel.incomeTaxRate * detail.pricePerDealUnit * detail.doQuantity / 100, 2).ToString("N2"), normal_font);
                    tableContent.AddCell(cellRight);
                    totalPPH += (viewModel.incomeTaxRate * detail.pricePerDealUnit * detail.doQuantity / 100);
                    var    garmentDeliveryOrder = DOfacade.ReadById((int)item.deliveryOrder.Id);
                    double rate = 1;
                    if (garmentDeliveryOrder != null)
                    {
                        rate = (double)garmentDeliveryOrder.DOCurrencyRate;
                    }
                    totalPPHIDR += ((viewModel.incomeTaxRate * detail.pricePerDealUnit * detail.doQuantity / 100) * rate);                   /**dikali rate DO*/
                }
            }
            cellRight.Phrase  = new Phrase("Total Pph", normal_font);
            cellRight.Colspan = 5;
            tableContent.AddCell(cellRight);
            cellRight.Phrase  = new Phrase(totalPPH.ToString("N2"), normal_font);
            cellRight.Colspan = 5;
            tableContent.AddCell(cellRight);
            cellRight.Phrase  = new Phrase("Total Pph IDR", normal_font);
            cellRight.Colspan = 5;
            tableContent.AddCell(cellRight);
            cellRight.Phrase  = new Phrase(totalPPHIDR.ToString("N2"), normal_font);
            cellRight.Colspan = 5;
            tableContent.AddCell(cellRight);

            PdfPCell cellContent = new PdfPCell(tableContent);             // dont remove
            tableContent.ExtendLastRow = false;
            tableContent.SpacingAfter  = 20f;
            document.Add(tableContent);
            #endregion
            #region TableSignature

            PdfPTable tableSignature = new PdfPTable(3);

            PdfPCell cellSignatureContent = new PdfPCell()
            {
                Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_CENTER
            };

            cellSignatureContent.Phrase = new Phrase("Administrasi\n\n\n\n\n\n\n(  " + "(Nama & Tanggal)" + "  )", bold_font);
            tableSignature.AddCell(cellSignatureContent);
            cellSignatureContent.Phrase = new Phrase("Staff Pembelian\n\n\n\n\n\n\n(  " + "(Nama & Tanggal)" + "  )", bold_font);
            tableSignature.AddCell(cellSignatureContent);
            cellSignatureContent.Phrase = new Phrase("Verifikasi\n\n\n\n\n\n\n(  " + "(Nama & Tanggal)" + "  )", bold_font);
            tableSignature.AddCell(cellSignatureContent);


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

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

            return(stream);
        }
        public IActionResult Get(int page = 1, int size = 25, string order = "{}", string keyword = null, string filter = "{}")
        {
            try
            {
                identityService.Username = User.Claims.Single(p => p.Type.Equals("username")).Value;

                var Data = facade.Read(page, size, order, keyword, filter);

                var viewModel = mapper.Map <List <GarmentInternNoteViewModel> >(Data.Item1);

                HashSet <long>        garmentInvoiceIds = new HashSet <long>(viewModel.SelectMany(vm => vm.items.Select(i => i.garmentInvoice.Id)));
                List <GarmentInvoice> garmentInvoices   = invoiceFacade.ReadForInternNote(garmentInvoiceIds.ToList());

                HashSet <long> deliveryOrderIds = new HashSet <long>(viewModel.SelectMany(vm => vm.items.SelectMany(i => i.details.Select(d => d.deliveryOrder.Id))));
                List <GarmentDeliveryOrder> garmentDeliveryOrders = deliveryOrderFacade.ReadForInternNote(deliveryOrderIds.ToList());

                foreach (var d in viewModel)
                {
                    foreach (var item in d.items)
                    {
                        GarmentInvoice garmentInvoice = garmentInvoices.SingleOrDefault(gi => gi.Id == item.garmentInvoice.Id);
                        if (garmentInvoice != null)
                        {
                            GarmentInvoiceViewModel invoiceViewModel = mapper.Map <GarmentInvoiceViewModel>(garmentInvoice);

                            item.garmentInvoice.items = invoiceViewModel.items;
                        }
                        foreach (var detail in item.details)
                        {
                            var deliveryOrder = garmentDeliveryOrders.SingleOrDefault(gdo => gdo.Id == detail.deliveryOrder.Id);
                            if (deliveryOrder != null)
                            {
                                var deliveryOrderViewModel = mapper.Map <GarmentDeliveryOrderViewModel>(deliveryOrder);
                                detail.deliveryOrder.items = deliveryOrderViewModel.items;
                            }
                        }
                    }
                }

                List <object> listData = new List <object>();
                listData.AddRange(
                    viewModel.AsQueryable().Select(s => new
                {
                    s.Id,
                    s.inNo,
                    s.inDate,
                    supplier = new { s.supplier.Name },
                    items    = s.items.Select(i => new {
                        //i.garmentInvoice,
                        garmentInvoice = new
                        {
                            i.garmentInvoice.invoiceNo,
                            items = i.garmentInvoice.items == null ? null : i.garmentInvoice.items.Select(gii => new
                            {
                                details = gii.details == null ? null : gii.details.Select(gid => new
                                {
                                    gid.dODetailId
                                })
                            })
                        },
                        details = i.details.Select(d => new
                        {
                            //d.deliveryOrder
                            deliveryOrder = new
                            {
                                items = d.deliveryOrder.items == null ? null : d.deliveryOrder.items.Select(doi => new
                                {
                                    fulfillments = doi.fulfillments == null ? null : doi.fulfillments.Select(dof => new
                                    {
                                        dof.Id,
                                        dof.receiptQuantity
                                    })
                                })
                            }
                        }).ToList(),
                    }).ToList(),
                    s.CreatedBy,
                    s.LastModifiedUtc
                }).ToList()
                    );

                var info = new Dictionary <string, object>
                {
                    { "count", listData.Count },
                    { "total", Data.Item2 },
                    { "order", Data.Item3 },
                    { "page", page },
                    { "size", size }
                };

                Dictionary <string, object> Result =
                    new ResultFormatter(ApiVersion, General.OK_STATUS_CODE, General.OK_MESSAGE)
                    .Ok(listData, info);
                return(Ok(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 void Should_Success_Validate_Data()
        {
            GarmentInvoiceViewModel nullViewModel = new GarmentInvoiceViewModel();

            Assert.True(nullViewModel.Validate(null).Count() > 0);
            var tomorrow = DateTime.Now.Date.AddDays(+1);
            GarmentInvoiceViewModel viewModel = new GarmentInvoiceViewModel
            {
                invoiceNo     = "",
                invoiceDate   = tomorrow,
                supplier      = { },
                incomeTaxId   = It.IsAny <int>(),
                incomeTaxName = "name",
                incomeTaxNo   = "",
                incomeTaxDate = DateTimeOffset.MinValue,
                incomeTaxRate = 2,
                vatNo         = "",
                vatDate       = DateTimeOffset.MinValue,
                useIncomeTax  = true,
                useVat        = true,
                isPayTax      = true,
                hasInternNote = false,
                currency      = { },
                items         = new List <GarmentInvoiceItemViewModel>
                {
                    new GarmentInvoiceItemViewModel
                    {
                        deliveryOrder = null,

                        details = new List <GarmentInvoiceDetailViewModel>
                        {
                            new GarmentInvoiceDetailViewModel
                            {
                                doQuantity = 0
                            }
                        }
                    }
                }
            };

            Assert.True(viewModel.Validate(null).Count() > 0);

            GarmentInvoiceViewModel viewModels = new GarmentInvoiceViewModel
            {
                invoiceNo     = "",
                invoiceDate   = DateTimeOffset.MinValue,
                supplier      = { },
                incomeTaxId   = It.IsAny <int>(),
                incomeTaxName = "name",
                incomeTaxNo   = "",
                incomeTaxDate = DateTimeOffset.MinValue,
                incomeTaxRate = 2,
                vatNo         = "",
                vatDate       = DateTimeOffset.MinValue,
                useIncomeTax  = true,
                useVat        = true,
                isPayTax      = true,
                hasInternNote = false,
                currency      = new CurrencyViewModel {
                    Id = It.IsAny <int>(), Code = "USD", Symbol = "$", Rate = 13000, Description = ""
                },
                items = new List <GarmentInvoiceItemViewModel>
                {
                    new GarmentInvoiceItemViewModel
                    {
                        deliveryOrder = null,

                        details = null
                    }
                }
            };

            Assert.True(viewModels.Validate(null).Count() > 0);

            GarmentInvoiceViewModel viewModels1 = new GarmentInvoiceViewModel
            {
                invoiceNo      = "",
                invoiceDate    = DateTimeOffset.MinValue,
                supplier       = { },
                incomeTaxId    = It.IsAny <int>(),
                incomeTaxName  = "",
                incomeTaxNo    = "",
                incomeTaxDate  = DateTimeOffset.MinValue,
                incomeTaxRate  = 2,
                vatNo          = "",
                vatDate        = DateTimeOffset.MinValue,
                useIncomeTax   = true,
                useVat         = true,
                isPayTax       = true,
                poSerialNumber = "any",
                hasInternNote  = false,
                currency       = new CurrencyViewModel {
                    Id = It.IsAny <int>(), Code = "USD", Symbol = "$", Rate = 13000, Description = ""
                },
                items = new List <GarmentInvoiceItemViewModel>
                {
                    new GarmentInvoiceItemViewModel
                    {
                        deliveryOrder = null,

                        details = null
                    }
                }
            };

            Assert.True(viewModels1.Validate(null).Count() > 0);
        }
        public void Should_Success_Validate_Data()
        {
            Mock <IServiceProvider> serviceProvider = new Mock <IServiceProvider>();

            serviceProvider.Setup(x => x.GetService(typeof(PurchasingDbContext)))
            .Returns(_dbContext(GetCurrentMethod()));

            GarmentInvoiceViewModel nullViewModel = new GarmentInvoiceViewModel();

            Assert.True(nullViewModel.Validate(null).Count() > 0);
            var tomorrow = DateTime.Now.Date.AddDays(+1);


            GarmentInvoiceViewModel viewModel = new GarmentInvoiceViewModel
            {
                invoiceNo     = "",
                invoiceDate   = tomorrow,
                supplier      = { },
                incomeTaxId   = It.IsAny <int>(),
                incomeTaxName = "name",
                incomeTaxNo   = "",
                incomeTaxDate = DateTimeOffset.MinValue,
                incomeTaxRate = 2,
                vatNo         = "",
                vatId         = It.IsAny <int>(),
                vatRate       = 10,
                vatDate       = DateTimeOffset.MinValue,
                useIncomeTax  = true,
                useVat        = true,
                isPayTax      = true,
                hasInternNote = false,
                currency      = { },
                items         = new List <GarmentInvoiceItemViewModel>
                {
                    new GarmentInvoiceItemViewModel
                    {
                        deliveryOrder = null,

                        details = new List <GarmentInvoiceDetailViewModel>
                        {
                            new GarmentInvoiceDetailViewModel
                            {
                                doQuantity = 0
                            }
                        }
                    }
                }
            };

            System.ComponentModel.DataAnnotations.ValidationContext garmentInvoiceValidate1 = new System.ComponentModel.DataAnnotations.ValidationContext(viewModel, serviceProvider.Object, null);
            Assert.True(viewModel.Validate(garmentInvoiceValidate1).Count() > 0);


            GarmentInvoiceViewModel viewModels = new GarmentInvoiceViewModel
            {
                invoiceNo     = "",
                invoiceDate   = DateTimeOffset.MinValue,
                supplier      = { },
                incomeTaxId   = It.IsAny <int>(),
                incomeTaxName = "name",
                incomeTaxNo   = "",
                incomeTaxDate = DateTimeOffset.MinValue,
                incomeTaxRate = 2,
                vatNo         = "",
                vatId         = It.IsAny <int>(),
                vatRate       = 10,
                vatDate       = DateTimeOffset.MinValue,
                useIncomeTax  = true,
                useVat        = true,
                isPayTax      = true,
                hasInternNote = false,
                currency      = new CurrencyViewModel {
                    Id = It.IsAny <int>(), Code = "USD", Symbol = "$", Rate = 13000, Description = ""
                },
                items = new List <GarmentInvoiceItemViewModel>
                {
                    new GarmentInvoiceItemViewModel
                    {
                        deliveryOrder = null,

                        details = null
                    }
                }
            };

            System.ComponentModel.DataAnnotations.ValidationContext garmentInvoiceValidate11 = new System.ComponentModel.DataAnnotations.ValidationContext(viewModels, serviceProvider.Object, null);

            Assert.True(viewModels.Validate(garmentInvoiceValidate11).Count() > 0);

            GarmentInvoiceViewModel viewModels1 = new GarmentInvoiceViewModel
            {
                invoiceNo      = "",
                invoiceDate    = DateTimeOffset.MinValue,
                supplier       = { },
                incomeTaxId    = It.IsAny <int>(),
                incomeTaxName  = "",
                incomeTaxNo    = "",
                incomeTaxDate  = DateTimeOffset.MinValue,
                incomeTaxRate  = 2,
                vatNo          = "",
                vatId          = It.IsAny <int>(),
                vatRate        = 10,
                vatDate        = DateTimeOffset.MinValue,
                useIncomeTax   = true,
                useVat         = true,
                isPayTax       = true,
                poSerialNumber = "any",
                hasInternNote  = false,
                currency       = new CurrencyViewModel {
                    Id = It.IsAny <int>(), Code = "USD", Symbol = "$", Rate = 13000, Description = ""
                },
                items = new List <GarmentInvoiceItemViewModel>
                {
                    new GarmentInvoiceItemViewModel
                    {
                        deliveryOrder = null,

                        details = null
                    }
                }
            };

            System.ComponentModel.DataAnnotations.ValidationContext garmentInvoiceValidate12 = new System.ComponentModel.DataAnnotations.ValidationContext(viewModels1, serviceProvider.Object, null);
            Assert.True(viewModels1.Validate(garmentInvoiceValidate12).Count() > 0);

            GarmentInvoiceViewModel viewModels12 = new GarmentInvoiceViewModel
            {
                invoiceNo      = "",
                invoiceDate    = DateTimeOffset.MinValue,
                supplier       = { },
                incomeTaxId    = It.IsAny <int>(),
                incomeTaxName  = "",
                incomeTaxNo    = "",
                incomeTaxDate  = DateTimeOffset.MinValue,
                incomeTaxRate  = 2,
                vatNo          = "",
                vatId          = It.IsAny <int>(),
                vatRate        = 10,
                vatDate        = DateTimeOffset.MinValue,
                useIncomeTax   = true,
                useVat         = true,
                isPayTax       = true,
                poSerialNumber = "any",
                hasInternNote  = false,
                currency       = new CurrencyViewModel {
                    Id = It.IsAny <int>(), Code = "USD", Symbol = "$", Rate = 13000, Description = ""
                },
                items = new List <GarmentInvoiceItemViewModel>
                {
                    new GarmentInvoiceItemViewModel
                    {
                        deliveryOrder = new GarmentDeliveryOrderViewModel {
                            doNo        = "test1",
                            arrivalDate = tomorrow,
                            doDate      = tomorrow
                        },

                        details = null
                    },

                    new GarmentInvoiceItemViewModel
                    {
                        deliveryOrder = new GarmentDeliveryOrderViewModel {
                            doNo        = "test1",
                            arrivalDate = tomorrow,
                            doDate      = tomorrow
                        },

                        details = null
                    }
                }
            };

            System.ComponentModel.DataAnnotations.ValidationContext garmentInvoiceValidate13 = new System.ComponentModel.DataAnnotations.ValidationContext(viewModels12, serviceProvider.Object, null);
            Assert.True(viewModels12.Validate(garmentInvoiceValidate13).Count() > 0);
        }
        public IActionResult Get(int page = 1, int size = 25, string order = "{}", string keyword = null, string filter = "{}")
        {
            try
            {
                identityService.Username = User.Claims.Single(p => p.Type.Equals("username")).Value;

                var Data = facade.Read(page, size, order, keyword, filter);

                var viewModel = mapper.Map <List <GarmentInternNoteViewModel> >(Data.Item1);

                foreach (var d in viewModel)
                {
                    foreach (var item in d.items)
                    {
                        GarmentInvoice garmentInvoice = invoiceFacade.ReadById((int)item.garmentInvoice.Id);
                        if (garmentInvoice != null)
                        {
                            GarmentInvoiceViewModel invoiceViewModel = mapper.Map <GarmentInvoiceViewModel>(garmentInvoice);

                            item.garmentInvoice.items = invoiceViewModel.items;
                        }
                        foreach (var detail in item.details)
                        {
                            var deliveryOrder = deliveryOrderFacade.ReadById((int)detail.deliveryOrder.Id);
                            if (deliveryOrder != null)
                            {
                                var deliveryOrderViewModel = mapper.Map <GarmentDeliveryOrderViewModel>(deliveryOrder);
                                detail.deliveryOrder.items = deliveryOrderViewModel.items;
                            }
                        }
                    }
                }

                List <object> listData = new List <object>();
                listData.AddRange(
                    viewModel.AsQueryable().Select(s => new
                {
                    s.Id,
                    s.inNo,
                    s.inDate,
                    supplier = new { s.supplier.Name },
                    items    = s.items.Select(i => new {
                        i.garmentInvoice,
                        details = i.details.Select(d => new
                        {
                            d.deliveryOrder
                        }).ToList(),
                    }).ToList(),
                    s.CreatedBy,
                    s.LastModifiedUtc
                }).ToList()
                    );

                var info = new Dictionary <string, object>
                {
                    { "count", listData.Count },
                    { "total", Data.Item2 },
                    { "order", Data.Item3 },
                    { "page", page },
                    { "size", size }
                };

                Dictionary <string, object> Result =
                    new ResultFormatter(ApiVersion, General.OK_STATUS_CODE, General.OK_MESSAGE)
                    .Ok(listData, info);
                return(Ok(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));
            }
        }