예제 #1
0
        public async void Should_Error_Update_Data()
        {
            var facade = new GarmentInternNoteFacades(_dbContext(GetCurrentMethod()), ServiceProvider);
            GarmentInternNote            data = dataUtil(facade, GetCurrentMethod()).GetNewData();
            List <GarmentInternNoteItem> item = new List <GarmentInternNoteItem>(data.Items);

            data.Items.Add(new GarmentInternNoteItem
            {
                InvoiceId   = It.IsAny <int>(),
                InvoiceDate = DateTimeOffset.Now,
                InvoiceNo   = "donos",
                TotalAmount = 2000,
                Details     = null
            });

            var ResponseUpdate = await facade.Update((int)data.Id, data, USERNAME);

            Assert.NotEqual(ResponseUpdate, 0);
            var newItem = new GarmentInternNoteItem
            {
                InvoiceId   = It.IsAny <int>(),
                InvoiceDate = DateTimeOffset.Now,
                InvoiceNo   = "dono",
                TotalAmount = 2000,
                Details     = null
            };
            List <GarmentInternNoteItem> Newitems = new List <GarmentInternNoteItem>(data.Items);

            Newitems.Add(newItem);
            data.Items = Newitems;

            Exception errorNullItems = await Assert.ThrowsAsync <Exception>(async() => await facade.Update((int)data.Id, data, USERNAME));

            Assert.NotNull(errorNullItems.Message);
        }
        public SPBDto(GarmentInternNote internNote, List <GarmentInvoice> invoices, List <GarmentInternNoteItem> internNoteItems, List <GarmentInternNoteDetail> internNoteDetails, List <GarmentCorrectionNote> corrections, List <GarmentCorrectionNoteItem> correctionItems) : this(internNote, invoices, internNoteItems, internNoteDetails)
        {
            var selectedInternalNoteItems   = internNoteItems.Where(element => element.GarmentINId == internNote.Id).ToList();
            var selectedInternalNoteItemIds = selectedInternalNoteItems.Select(element => element.Id).ToList();
            var selectedInvoiceIds          = selectedInternalNoteItems.Select(element => element.InvoiceId).ToList();

            var selectedInternalNoteDetails = internNoteDetails.Where(element => selectedInternalNoteItemIds.Contains(element.GarmentItemINId)).ToList();
            var selectedDOIds       = selectedInternalNoteDetails.Select(element => element.DOId).ToList();
            var selectedCorrections = corrections.Where(element => selectedDOIds.Contains(element.DOId)).ToList();

            Amount = invoices.Where(element => selectedInvoiceIds.Contains(element.Id)).Sum(element => element.TotalAmount);

            var correctionAmount = selectedCorrections.Sum(element =>
            {
                var selectedCorrectionItems = correctionItems.Where(item => item.GCorrectionId == element.Id);

                var total = 0.0;
                if (element.CorrectionType.ToUpper() == "RETUR")
                {
                    total = (double)selectedCorrectionItems.Sum(item => item.PricePerDealUnitAfter * item.Quantity);
                }
                else
                {
                    total = (double)element.TotalCorrection;
                }

                return(total);
            });

            Amount += correctionAmount;
            var invoiceIds     = selectedInternalNoteItems.Select(item => item.InvoiceId).ToList();
            var elementInvoice = invoices.FirstOrDefault(entity => invoiceIds.Contains(entity.Id));

            UnitCosts = selectedInternalNoteDetails.Select(detail => new UnitCostDto(detail, selectedInternalNoteItems, internNote, elementInvoice)).ToList();
        }
예제 #3
0
        public SPBDto(GarmentInternNote element, List <GarmentInvoice> invoices, List <GarmentInternNoteItem> internNoteItems, List <GarmentInternNoteDetail> internNoteDetails)
        {
            Id   = element.Id;
            No   = element.INNo;
            Date = element.INDate;

            var invoiceIds     = element.Items.Select(item => item.InvoiceId).ToList();
            var elementInvoice = invoices.FirstOrDefault(entity => invoiceIds.Contains(entity.Id));


            Supplier = new SupplierDto(element);


            if (elementInvoice != null)
            {
                Division     = new DivisionDto("", "0", "GARMENT");
                UseVat       = elementInvoice.UseVat;
                UseIncomeTax = elementInvoice.UseIncomeTax;
                IncomeTax    = new IncomeTaxDto(elementInvoice.IncomeTaxId, elementInvoice.IncomeTaxName, elementInvoice.IncomeTaxRate);
                IncomeTaxBy  = elementInvoice.IsPayTax ? "Dan Liris" : "Supplier";
            }

            var selectedInternNoteItems   = internNoteItems.Where(item => item.GarmentINId == element.Id).ToList();
            var selectedInternNoteItemIds = selectedInternNoteItems.Select(item => item.Id).ToList();
            var selectedInternNoteDetails = internNoteDetails.Where(detail => selectedInternNoteItemIds.Contains(detail.GarmentItemINId)).ToList();

            UnitCosts = selectedInternNoteDetails.Select(detail => new UnitCostDto(detail, selectedInternNoteItems, element, elementInvoice)).ToList();
            Amount    = selectedInternNoteDetails.Sum(detail => detail.PriceTotal);
        }
        public IActionResult GetInternNotePDF(int id)
        {
            try
            {
                identityService.Username = User.Claims.Single(p => p.Type.Equals("username")).Value;
                identityService.Token    = Request.Headers["Authorization"].FirstOrDefault().Replace("Bearer ", "");

                var indexAcceptPdf = Request.Headers["Accept"].ToList().IndexOf("application/pdf");

                GarmentInternNote          model     = facade.ReadById(id);
                GarmentInternNoteViewModel viewModel = mapper.Map <GarmentInternNoteViewModel>(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());

                    foreach (var item in viewModel.items)
                    {
                        var garmentInvoice          = invoiceFacade.ReadById((int)item.garmentInvoice.Id);
                        var garmentInvoiceViewModel = mapper.Map <GarmentInvoiceViewModel>(garmentInvoice);
                        item.garmentInvoice = garmentInvoiceViewModel;

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

                    GarmentInternNotePDFTemplate PdfTemplateLocal = new GarmentInternNotePDFTemplate();
                    MemoryStream stream = PdfTemplateLocal.GeneratePdfTemplate(viewModel, serviceProvider, clientTimeZoneOffset, deliveryOrderFacade);

                    return(new FileStreamResult(stream, "application/pdf")
                    {
                        FileDownloadName = $"{viewModel.inNo}.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));
            }
        }
예제 #5
0
        public async Task <int> Create(GarmentInternNote m, bool isImport, string user, int clientTimeZoneOffset = 7)
        {
            int Created = 0;

            using (var transaction = this.dbContext.Database.BeginTransaction())
            {
                try
                {
                    EntityExtension.FlagForCreate(m, user, USER_AGENT);

                    m.INNo = await GenerateNo(m, isImport, clientTimeZoneOffset);

                    m.INDate = DateTimeOffset.Now;

                    foreach (var item in m.Items)
                    {
                        GarmentInvoice garmentInvoice = this.dbContext.GarmentInvoices.FirstOrDefault(s => s.Id == item.InvoiceId);
                        if (garmentInvoice != null)
                        {
                            garmentInvoice.HasInternNote = true;
                        }
                        EntityExtension.FlagForCreate(item, user, USER_AGENT);
                        foreach (var detail in item.Details)
                        {
                            GarmentDeliveryOrder         garmentDeliveryOrder  = this.dbContext.GarmentDeliveryOrders.FirstOrDefault(s => s.Id == detail.DOId);
                            GarmentInternalPurchaseOrder internalPurchaseOrder = this.dbContext.GarmentInternalPurchaseOrders.FirstOrDefault(s => s.RONo.Equals(detail.RONo));
                            if (internalPurchaseOrder != null)
                            {
                                detail.UnitId   = internalPurchaseOrder.UnitId;
                                detail.UnitCode = internalPurchaseOrder.UnitCode;
                                detail.UnitName = internalPurchaseOrder.UnitName;
                            }
                            if (garmentDeliveryOrder != null)
                            {
                                garmentDeliveryOrder.InternNo = m.INNo;
                            }
                            EntityExtension.FlagForCreate(detail, user, USER_AGENT);

                            await _garmentDebtBalanceService.UpdateFromInternalNote((int)detail.DOId, new InternalNoteFormDto((int)m.Id, m.INNo));
                        }
                    }

                    this.dbSet.Add(m);

                    Created = await dbContext.SaveChangesAsync();

                    transaction.Commit();
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                    throw new Exception(e.Message);
                }
            }

            return(Created);
        }
        public InternalNoteDto(GarmentInternNote internalNote, List <GarmentInvoiceInternNoteViewModel> internalNoteInvoices)
        {
            Id         = (int)internalNote.Id;
            DocumentNo = internalNote.INNo;
            Date       = internalNote.INDate;
            DueDate    = internalNote.Items.FirstOrDefault().Details.FirstOrDefault().PaymentDueDate;
            Supplier   = new SupplierDto(internalNote.SupplierId, internalNote.SupplierName, internalNote.SupplierCode);
            DPP        = internalNoteInvoices.Sum(internalNoteInvoice => internalNoteInvoice.GarmentInvoices.TotalAmount);

            TotalAmount = internalNoteInvoices.Sum(element =>
            {
                var total = element.GarmentInvoices.TotalAmount;

                if (element.GarmentInvoices.UseVat && element.GarmentInvoices.IsPayVat)
                {
                    total += element.GarmentInvoices.TotalAmount * 0.1;
                }

                if (element.GarmentInvoices.UseIncomeTax && element.GarmentInvoices.IsPayTax)
                {
                    total -= element.GarmentInvoices.TotalAmount * (element.GarmentInvoices.IncomeTaxRate / 100);
                }

                return(total);
            });

            VATAmount = internalNoteInvoices.Sum(element =>
            {
                var total = 0.0;

                if (element.GarmentInvoices.UseVat && element.GarmentInvoices.IsPayVat)
                {
                    total += element.GarmentInvoices.TotalAmount * 0.1;
                }

                return(total);
            });

            IncomeTaxAmount = internalNoteInvoices.Sum(element =>
            {
                var total = 0.0;

                if (element.GarmentInvoices.UseIncomeTax && element.GarmentInvoices.IsPayTax)
                {
                    total += element.GarmentInvoices.TotalAmount * (element.GarmentInvoices.IncomeTaxRate / 100);
                }

                return(total);
            });

            Currency = new CurrencyDto(internalNote.CurrencyId, internalNote.CurrencyCode, internalNote.CurrencyRate);
            Items    = internalNoteInvoices.Select(internalNoteInvoice => new InternalNoteInvoiceDto(internalNoteInvoice)).ToList();
        }
        public async Task <int> Create(GarmentInternNote m, bool isImport, string user, int clientTimeZoneOffset = 7)
        {
            int Created = 0;

            using (var transaction = this.dbContext.Database.BeginTransaction())
            {
                try
                {
                    EntityExtension.FlagForCreate(m, user, USER_AGENT);

                    m.INNo = await GenerateNo(m, isImport, clientTimeZoneOffset);

                    m.INDate = DateTimeOffset.Now;

                    foreach (var item in m.Items)
                    {
                        foreach (var detail in item.Details)
                        {
                            GarmentExternalPurchaseOrderItem eksternalPurchaseOrderItem = this.dbContext.GarmentExternalPurchaseOrderItems.FirstOrDefault(s => s.GarmentEPOId == detail.EPOId);
                            GarmentInternalPurchaseOrder     internalPurchaseOrder      = this.dbContext.GarmentInternalPurchaseOrders.FirstOrDefault(s => s.Id == eksternalPurchaseOrderItem.POId);
                            detail.UnitId   = internalPurchaseOrder.UnitId;
                            detail.UnitCode = internalPurchaseOrder.UnitCode;
                            detail.UnitName = internalPurchaseOrder.UnitName;
                            EntityExtension.FlagForCreate(detail, user, USER_AGENT);
                        }
                        GarmentInvoice garmentInvoice = this.dbContext.GarmentInvoices.FirstOrDefault(s => s.Id == item.InvoiceId);
                        garmentInvoice.HasInternNote = true;

                        EntityExtension.FlagForCreate(item, user, USER_AGENT);
                    }

                    this.dbSet.Add(m);

                    Created = await dbContext.SaveChangesAsync();

                    transaction.Commit();
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                    throw new Exception(e.Message);
                }
            }

            return(Created);
        }
        public async Task <int> Update(int id, GarmentInternNote m, string user, int clientTimeZoneOffset = 7)
        {
            int Updated = 0;

            using (var transaction = dbContext.Database.BeginTransaction())
            {
                try
                {
                    var oldM = this.dbSet.AsNoTracking()
                               .SingleOrDefault(gi => gi.Id == id && !gi.IsDeleted);

                    if (oldM != null && oldM.Id == id)
                    {
                        EntityExtension.FlagForUpdate(m, user, USER_AGENT);
                        foreach (var item in m.Items)
                        {
                            foreach (var detail in item.Details)
                            {
                                EntityExtension.FlagForCreate(detail, user, "Facade");
                            }
                            //GarmentInvoice garmentInvoice = this.dbContext.GarmentInvoices.FirstOrDefault(s => s.Id == item.InvoiceId);
                            //garmentInvoice.HasInternNote = true;

                            EntityExtension.FlagForCreate(item, user, USER_AGENT);
                        }

                        dbSet.Update(m);

                        Updated = await dbContext.SaveChangesAsync();

                        transaction.Commit();
                    }
                    else
                    {
                        throw new Exception("Invalid Id");
                    }
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                    throw new Exception(e.Message);
                }
            }

            return(Updated);
        }
        public async Task Should_Success_Update_Data2()
        {
            var dbContext          = _dbContext(GetCurrentMethod());
            var facade             = new GarmentInternNoteFacades(dbContext, ServiceProvider);
            var facadeDO           = new GarmentDeliveryOrderFacade(ServiceProvider, dbContext);
            GarmentInternNote data = await dataUtil(facade, GetCurrentMethod()).GetNewData();

            GarmentInternNoteItem item = await dataUtil(facade, GetCurrentMethod()).GetNewDataItem(USERNAME);

            var ResponseUpdate = await facade.Update((int)data.Id, data, USERNAME);

            Assert.NotEqual(0, ResponseUpdate);

            List <GarmentInternNoteItem> Newitems = new List <GarmentInternNoteItem>(data.Items);

            Newitems.Add(item);
            data.Items = Newitems;

            var ResponseUpdate1 = await facade.Update((int)data.Id, data, USERNAME);

            Assert.NotEqual(0, ResponseUpdate);

            dbContext.Entry(data).State = EntityState.Detached;
            foreach (var items in data.Items)
            {
                dbContext.Entry(items).State = EntityState.Detached;
                foreach (var detail in items.Details)
                {
                    dbContext.Entry(detail).State = EntityState.Detached;
                }
            }

            var newData = dbContext.GarmentInternNotes.AsNoTracking()
                          .Include(m => m.Items)
                          .ThenInclude(i => i.Details)
                          .FirstOrDefault(m => m.Id == data.Id);

            newData.Items = newData.Items.Take(1).ToList();

            var ResponseUpdate2 = await facade.Update((int)newData.Id, newData, USERNAME);

            Assert.NotEqual(0, ResponseUpdate2);
        }
예제 #10
0
        public SPBDto(GarmentInternNote element, List <GarmentInvoice> invoices)
        {
            Id   = element.Id;
            No   = element.INNo;
            Date = element.INDate;

            var invoiceIds     = element.Items.Select(item => item.InvoiceId).ToList();
            var elementInvoice = invoices.FirstOrDefault(entity => invoiceIds.Contains(entity.Id));

            Amount = element.Items.SelectMany(item => item.Details).Sum(detail => detail.PriceTotal);

            if (elementInvoice != null)
            {
                UseVat       = elementInvoice.UseVat;
                UseIncomeTax = elementInvoice.UseIncomeTax;
                IncomeTax    = new IncomeTaxDto(elementInvoice.IncomeTaxId, elementInvoice.IncomeTaxName, elementInvoice.IncomeTaxRate);
                IncomeTaxBy  = elementInvoice.IsPayTax ? "Dan Liris" : "Supplier";
            }
        }
예제 #11
0
        public async void Should_Success_Update_Data()
        {
            var facade   = new GarmentInternNoteFacades(_dbContext(GetCurrentMethod()), ServiceProvider);
            var facadeDO = new GarmentDeliveryOrderFacade(ServiceProvider, _dbContext(GetCurrentMethod()));
            GarmentInternNote     data = dataUtil(facade, GetCurrentMethod()).GetNewData();
            GarmentInternNoteItem item = await dataUtil(facade, GetCurrentMethod()).GetNewDataItem(USERNAME);

            var ResponseUpdate = await facade.Update((int)data.Id, data, USERNAME);

            Assert.NotEqual(ResponseUpdate, 0);

            List <GarmentInternNoteItem> Newitems = new List <GarmentInternNoteItem>(data.Items);

            Newitems.Add(item);
            data.Items = Newitems;

            var ResponseUpdate1 = await facade.Update((int)data.Id, data, USERNAME);

            Assert.NotEqual(ResponseUpdate1, 0);
        }
예제 #12
0
        public void ShouldSuccess_UpdateSPB_with_NonGarmentDivision()
        {
            //Setup
            PurchasingDbContext dbContext         = GetDbContext(GetCurrentAsyncMethod());
            GarmentInternNote   garmentInternNote = new GarmentInternNote();

            garmentInternNote.Id          = 1;
            garmentInternNote.IsCreatedVB = false;

            dbContext.GarmentInternNotes.Add(garmentInternNote);
            var serviceProviderMock = GetServiceProvider();

            var data = dataUtil(dbContext).GetTestData_VBRequestPOExternal();

            //Act
            VBRequestPOExternalService service = new VBRequestPOExternalService(dbContext, serviceProviderMock.Object);
            var result  = service.UpdateSPB("", 1);
            var result2 = service.UpdateSPB("GARMENT", 1);

            //Assert
            Assert.NotEqual(0, result);
            Assert.NotEqual(0, result2);
        }
        async Task <string> GenerateNo(GarmentInternNote model, bool isImport, int clientTimeZoneOffset)
        {
            DateTimeOffset dateTimeOffsetNow = DateTimeOffset.Now;
            string         Month             = dateTimeOffsetNow.ToOffset(new TimeSpan(clientTimeZoneOffset, 0, 0)).ToString("MM");
            string         Year     = dateTimeOffsetNow.ToOffset(new TimeSpan(clientTimeZoneOffset, 0, 0)).ToString("yy");
            string         Supplier = isImport ? "I" : "L";

            string no      = $"NI{Year}{Month}";
            int    Padding = 4;

            var lastNo = await this.dbSet.Where(w => w.INNo.StartsWith(no) && w.INNo.EndsWith(Supplier) && !w.IsDeleted).OrderByDescending(o => o.INNo).FirstOrDefaultAsync();

            if (lastNo == null)
            {
                return(no + "1".PadLeft(Padding, '0') + Supplier);
            }
            else
            {
                //int lastNoNumber = Int32.Parse(lastNo.INNo.Replace(no, "")) + 1;
                int.TryParse(lastNo.INNo.Replace(no, "").Replace(Supplier, ""), out int lastno1);
                int lastNoNumber = lastno1 + 1;
                return(no + lastNoNumber.ToString().PadLeft(Padding, '0') + Supplier);
            }
        }
예제 #14
0
        public async Task <int> Update(int id, GarmentInternNote m, string user, int clientTimeZoneOffset = 7)
        {
            int Updated = 0;

            using (var transaction = dbContext.Database.BeginTransaction())
            {
                try
                {
                    if (m.Items != null)
                    {
                        double         total     = 0;
                        HashSet <long> detailIds = GetGarmentInternNoteId(id);
                        foreach (var itemId in detailIds)
                        {
                            GarmentInternNoteItem data = m.Items.FirstOrDefault(prop => prop.Id.Equals(itemId));
                            if (data == null)
                            {
                                GarmentInternNoteItem dataItem = dbContext.GarmentInternNoteItems.FirstOrDefault(prop => prop.Id.Equals(itemId));
                                EntityExtension.FlagForDelete(dataItem, user, USER_AGENT);
                                var            Details         = dbContext.GarmentInternNoteDetails.Where(prop => prop.GarmentItemINId.Equals(itemId)).ToList();
                                GarmentInvoice garmentInvoices = dbContext.GarmentInvoices.FirstOrDefault(s => s.Id.Equals(dataItem.InvoiceId));
                                if (garmentInvoices != null)
                                {
                                    garmentInvoices.HasInternNote = false;
                                }
                                foreach (GarmentInternNoteDetail detail in Details)
                                {
                                    GarmentDeliveryOrder garmentDeliveryOrder = this.dbContext.GarmentDeliveryOrders.FirstOrDefault(s => s.Id == detail.DOId);
                                    garmentDeliveryOrder.InternNo = null;

                                    EntityExtension.FlagForDelete(detail, user, USER_AGENT);
                                }
                            }
                            else
                            {
                                EntityExtension.FlagForUpdate(data, user, USER_AGENT);
                            }

                            foreach (GarmentInternNoteItem item in m.Items)
                            {
                                total += item.TotalAmount;
                                if (item.Id <= 0)
                                {
                                    GarmentInvoice garmentInvoice = this.dbContext.GarmentInvoices.FirstOrDefault(s => s.Id == item.InvoiceId);
                                    if (garmentInvoice != null)
                                    {
                                        garmentInvoice.HasInternNote = true;
                                    }
                                    EntityExtension.FlagForCreate(item, user, USER_AGENT);
                                }
                                else
                                {
                                    EntityExtension.FlagForUpdate(item, user, USER_AGENT);
                                }

                                foreach (GarmentInternNoteDetail detail in item.Details)
                                {
                                    if (item.Id <= 0)
                                    {
                                        GarmentDeliveryOrder         garmentDeliveryOrder  = this.dbContext.GarmentDeliveryOrders.FirstOrDefault(s => s.Id == detail.DOId);
                                        GarmentInternalPurchaseOrder internalPurchaseOrder = this.dbContext.GarmentInternalPurchaseOrders.FirstOrDefault(s => s.RONo == detail.RONo);
                                        if (internalPurchaseOrder != null)
                                        {
                                            detail.UnitId   = internalPurchaseOrder.UnitId;
                                            detail.UnitCode = internalPurchaseOrder.UnitCode;
                                            detail.UnitName = internalPurchaseOrder.UnitName;
                                        }
                                        if (garmentDeliveryOrder != null)
                                        {
                                            garmentDeliveryOrder.InternNo = m.INNo;
                                        }
                                        EntityExtension.FlagForCreate(detail, user, USER_AGENT);
                                    }
                                    else
                                    {
                                        EntityExtension.FlagForUpdate(detail, user, USER_AGENT);
                                    }
                                }
                            }
                        }
                    }
                    EntityExtension.FlagForUpdate(m, user, USER_AGENT);
                    this.dbSet.Update(m);
                    Updated = await dbContext.SaveChangesAsync();

                    transaction.Commit();
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                    throw new Exception(e.Message);
                }
            }

            return(Updated);
        }
예제 #15
0
        public UnitCostDto(GarmentInternNoteDetail detail, List <GarmentInternNoteItem> internNoteItems, GarmentInternNote element, GarmentInvoice elementInvoice)
        {
            Unit = new UnitDto(detail.UnitId, detail.UnitCode, detail.UnitName, "", "0", "");

            var total = detail.PriceTotal;

            if (elementInvoice != null)
            {
                if (elementInvoice.UseVat)
                {
                    total += detail.PriceTotal * 0.1;
                }

                if (elementInvoice.UseIncomeTax && !elementInvoice.IsPayTax)
                {
                    total -= detail.PriceTotal * (elementInvoice.IncomeTaxRate / 100);
                }
            }

            PriceTotal = detail.PriceTotal;
            Amount     = total;
        }
        public ReportIndexDto(GarmentDeliveryOrder garmentDeliveryOrders, GarmentBeacukaiItem deliveryOrderCustoms, GarmentDeliveryOrderItem deliveryOrderItems, GarmentInvoiceItem deliveryOrderInvoiceItems, GarmentInvoice deliveryOrderInvoices, GarmentExternalPurchaseOrder deliveryOrderExternalPurchaseOrders, GarmentInternNoteDetail deliveryOrderInternalNoteDetails, GarmentInternNoteItem deliveryOrderInternalNoteItems, GarmentInternNote deliveryOrderInternalNotes)
        {
            if (deliveryOrderCustoms != null)
            {
                CustomsArrivalDate = deliveryOrderCustoms.ArrivalDate;
            }

            if (deliveryOrderExternalPurchaseOrders != null)
            {
                SupplierId             = deliveryOrderExternalPurchaseOrders.SupplierId;
                SupplierName           = deliveryOrderExternalPurchaseOrders.SupplierName;
                IsImportSupplier       = deliveryOrderExternalPurchaseOrders.SupplierImport;
                AccountingCategoryName = deliveryOrderExternalPurchaseOrders.Category;
                PurchasingCategoryName = deliveryOrderExternalPurchaseOrders.Category;
            }

            var dppAmount = 0.0;

            if (deliveryOrderInternalNoteDetails != null)
            {
                ProductName          = deliveryOrderInternalNoteDetails.ProductName;
                InternalNoteQuantity = deliveryOrderInternalNoteDetails.Quantity;
                dppAmount            = deliveryOrderInternalNoteDetails.PriceTotal;
                Total = dppAmount;
            }

            if (garmentDeliveryOrders != null)
            {
                GarmentDeliveryOrderId = (int)garmentDeliveryOrders.Id;
                GarmentDeliveryOrderNo = garmentDeliveryOrders.DONo;
                BillNo      = garmentDeliveryOrders.BillNo;
                PaymentBill = garmentDeliveryOrders.PaymentBill;
            }

            if (deliveryOrderInvoices != null)
            {
                InvoiceId = (int)deliveryOrderInvoices.Id;
                InvoiceNo = deliveryOrderInvoices.InvoiceNo;
                VATNo     = deliveryOrderInvoices.VatNo;

                var vatAmount = 0.0;
                if (deliveryOrderInvoices.UseVat && deliveryOrderInvoices.IsPayVat)
                {
                    vatAmount = dppAmount * 0.1;
                    Total    += vatAmount;
                }

                var incomeTaxAmount = 0.0;
                if (deliveryOrderInvoices.UseIncomeTax && deliveryOrderInvoices.IsPayTax)
                {
                    incomeTaxAmount = dppAmount * deliveryOrderInvoices.IncomeTaxRate / 100;
                    Total          += incomeTaxAmount;
                }

                VATAmount       = vatAmount;
                IncomeTaxAmount = incomeTaxAmount;
            }
        }
 public SPBDtoItem(GarmentInternNote element, GarmentInternNoteItem item)
 {
     Date   = element.INDate;
     Remark = element.Remark;
     Amount = item.TotalAmount;
 }
예제 #18
0
 public GarmentInternalNoteDto(GarmentInternNote internalNote, List <GarmentInvoiceInternNoteViewModel> internalNoteInvoices)
 {
     InternalNote = new InternalNoteDto(internalNote, internalNoteInvoices);
 }
예제 #19
0
        public List <GarmentDispositionPaymentReportDto> GetReportByDate(DateTimeOffset startDate, DateTimeOffset endDate)
        {
            var dispositions = _dbContext.GarmentDispositionPurchases.Where(entity => entity.CreatedUtc >= startDate.DateTime && entity.CreatedUtc <= endDate.DateTime).ToList();

            var result = new List <GarmentDispositionPaymentReportDto>();

            if (dispositions.Count > 0)
            {
                var dispositionIds         = dispositions.Select(element => element.Id).ToList();
                var dispositionItems       = _dbContext.GarmentDispositionPurchaseItems.Where(entity => dispositionIds.Contains(entity.GarmentDispositionPurchaseId)).ToList();
                var dispositionItemIds     = dispositionItems.Select(element => element.Id).ToList();
                var dispositionDetails     = _dbContext.GarmentDispositionPurchaseDetailss.Where(entity => dispositionItemIds.Contains(entity.GarmentDispositionPurchaseItemId)).ToList();
                var epoIds                 = dispositionItems.Select(element => (long)element.EPOId).ToList();
                var externalPurchaseOrders = _dbContext.GarmentExternalPurchaseOrders.Where(entity => epoIds.Contains(entity.Id)).ToList();
                var deliveryOrderItems     = _dbContext.GarmentDeliveryOrderItems.Where(entity => epoIds.Contains(entity.EPOId)).ToList();
                var deliveryOrderItemIds   = deliveryOrderItems.Select(element => element.Id).ToList();
                var deliveryOrderIds       = deliveryOrderItems.Select(element => element.GarmentDOId).ToList();
                var deliveryOrderDetails   = _dbContext.GarmentDeliveryOrderDetails.Where(entity => deliveryOrderItemIds.Contains(entity.GarmentDOItemId)).ToList();
                var deliveryOrderDetailIds = deliveryOrderDetails.Select(entity => entity.Id).ToList();
                var deliveryOrders         = _dbContext.GarmentDeliveryOrders.Where(entity => deliveryOrderIds.Contains(entity.Id)).ToList();
                var customItems            = _dbContext.GarmentBeacukaiItems.Where(entity => deliveryOrderIds.Contains(entity.GarmentDOId)).ToList();
                var customIds              = customItems.Select(entity => entity.BeacukaiId).ToList();
                var customs                = _dbContext.GarmentBeacukais.Where(entity => customIds.Contains(entity.Id)).ToList();
                var unitReceiptNoteItems   = _dbContext.GarmentUnitReceiptNoteItems.Where(entity => deliveryOrderDetailIds.Contains(entity.DODetailId)).ToList();
                var unitReceiptNoteIds     = unitReceiptNoteItems.Select(element => element.URNId).ToList();
                var unitReceiptNotes       = _dbContext.GarmentUnitReceiptNotes.Where(entity => unitReceiptNoteIds.Contains(entity.Id)).ToList();
                var internalNoteDetails    = _dbContext.GarmentInternNoteDetails.Where(entity => deliveryOrderIds.Contains(entity.DOId)).ToList();
                var internalNoteItemIds    = internalNoteDetails.Select(element => element.GarmentItemINId).ToList();
                var internalNoteItems      = _dbContext.GarmentInternNoteItems.Where(entity => internalNoteItemIds.Contains(entity.Id)).ToList();
                var internalNoteIds        = internalNoteItems.Select(element => element.GarmentINId).ToList();
                var internalNotes          = _dbContext.GarmentInternNotes.Where(entity => internalNoteIds.Contains(entity.Id)).ToList();

                foreach (var dispositionItem in dispositionItems)
                {
                    var disposition                 = dispositions.FirstOrDefault(element => element.Id == dispositionItem.GarmentDispositionPurchaseId);
                    var externalPurchaseOrder       = externalPurchaseOrders.FirstOrDefault(element => element.Id == dispositionItem.EPOId);
                    var selectedDispoositionDetails = dispositionDetails.Where(element => element.GarmentDispositionPurchaseItemId == dispositionItem.Id).ToList();
                    var deliveryOrderItem           = deliveryOrderItems.FirstOrDefault(element => element.EPOId == dispositionItem.EPOId);
                    if (deliveryOrderItem == null)
                    {
                        deliveryOrderItem = new GarmentDeliveryOrderItem();
                    }

                    var deliveryOrder = deliveryOrders.FirstOrDefault(element => deliveryOrderItem.GarmentDOId == element.Id);
                    if (deliveryOrder == null)
                    {
                        deliveryOrder = new GarmentDeliveryOrder();
                    }

                    var selectedDeliveryOrderDetails   = deliveryOrderDetails.Where(element => element.GarmentDOItemId == deliveryOrderItem.Id).ToList();
                    var selectedDeliveryOrderDetailIds = selectedDeliveryOrderDetails.Select(element => element.Id).ToList();

                    var customItem = customItems.FirstOrDefault(element => element.GarmentDOId == deliveryOrder.Id);
                    if (customItem == null)
                    {
                        customItem = new GarmentBeacukaiItem();
                    }

                    var custom = customs.FirstOrDefault(element => customItem.BeacukaiId == element.Id);
                    if (custom == null)
                    {
                        custom = new GarmentBeacukai();
                    }

                    var unitReceiptNoteItem = unitReceiptNoteItems.FirstOrDefault(element => selectedDeliveryOrderDetailIds.Contains(element.DODetailId));
                    if (unitReceiptNoteItem == null)
                    {
                        unitReceiptNoteItem = new GarmentUnitReceiptNoteItem();
                    }

                    var unitReceiptNote = unitReceiptNotes.FirstOrDefault(element => element.Id == unitReceiptNoteItem.URNId);
                    if (unitReceiptNote == null)
                    {
                        unitReceiptNote = new GarmentUnitReceiptNote();
                    }

                    var internalNoteDetail = internalNoteDetails.FirstOrDefault(element => element.DOId == deliveryOrder.Id);
                    if (internalNoteDetail == null)
                    {
                        internalNoteDetail = new GarmentInternNoteDetail();
                    }

                    var internalNoteItem = internalNoteItems.FirstOrDefault(element => element.Id == internalNoteDetail.GarmentItemINId);
                    if (internalNoteItem == null)
                    {
                        internalNoteItem = new GarmentInternNoteItem();
                    }

                    var internalNote = internalNotes.FirstOrDefault(element => element.Id == internalNoteItem.GarmentINId);
                    if (internalNote == null)
                    {
                        internalNote = new GarmentInternNote();
                    }

                    var customDate = (DateTimeOffset?)null;
                    if (custom.Id > 0)
                    {
                        customDate = custom.BeacukaiDate;
                    }

                    var internalNoteDate = (DateTimeOffset?)null;
                    if (internalNote.Id > 0)
                    {
                        internalNoteDate = internalNote.INDate;
                    }

                    result.Add(new GarmentDispositionPaymentReportDto(
                                   disposition.Id,
                                   disposition.DispositionNo,
                                   disposition.CreatedUtc,
                                   disposition.DueDate,
                                   disposition.InvoiceProformaNo,
                                   disposition.SupplierId,
                                   disposition.SupplierCode,
                                   disposition.SupplierName,
                                   disposition.CurrencyId,
                                   dispositionItem.CurrencyCode,
                                   dispositionItem.CurrencyRate,
                                   disposition.Dpp,
                                   disposition.VAT,
                                   disposition.IncomeTax,
                                   disposition.OtherCost,
                                   disposition.Amount,
                                   0,
                                   disposition.Category,
                                   disposition.Category,
                                   externalPurchaseOrder != null? (int)externalPurchaseOrder.Id:0,
                                   externalPurchaseOrder != null? externalPurchaseOrder.EPONo:string.Empty,
                                   selectedDispoositionDetails.Sum(sum => sum.QTYPaid),
                                   deliveryOrder.Id > 0 ? (int)deliveryOrder.Id : 0,
                                   deliveryOrder.Id > 0 ? deliveryOrder.DONo : "",
                                   deliveryOrder.Id > 0 ? selectedDeliveryOrderDetails.Sum(sum => sum.DOQuantity) : 0,
                                   deliveryOrder.Id > 0 ? deliveryOrder.PaymentBill : "",
                                   deliveryOrder.Id > 0 ? deliveryOrder.BillNo : "",
                                   custom.Id > 0 ? (int)custom.Id : 0,
                                   custom.Id > 0 ? custom.BeacukaiNo : "",
                                   customDate,
                                   unitReceiptNote.Id > 0 ? (int)unitReceiptNote.Id : 0,
                                   unitReceiptNote.Id > 0 ? unitReceiptNote.URNNo : "",
                                   internalNote.Id > 0 ? (int)internalNote.Id : 0,
                                   internalNote.Id > 0 ? internalNote.INNo : "",
                                   internalNoteDate,
                                   disposition.CreatedBy
                                   ));
                }
            }

            return(result);
        }
        public async Task <GarmentInternNote> GetNewData(GarmentInvoice invo = null)
        {
            var garmentInvoice = invo ?? await Task.Run(() => garmentInvoiceDataUtil.GetTestDataViewModel("User"));

            List <GarmentInternNoteDetail> garmentInternNoteDetails = new List <GarmentInternNoteDetail>();

            foreach (var item in garmentInvoice.Items)
            {
                foreach (var detail in item.Details)
                {
                    garmentInternNoteDetails.Add(new GarmentInternNoteDetail
                    {
                        EPOId          = detail.EPOId,
                        EPONo          = detail.EPONo,
                        POSerialNumber = detail.POSerialNumber,
                        Quantity       = (long)detail.DOQuantity,
                        RONo           = detail.RONo,

                        DOId   = item.DeliveryOrderId,
                        DONo   = item.DeliveryOrderNo,
                        DODate = item.DODate,

                        ProductId   = detail.ProductId,
                        ProductCode = detail.ProductCode,
                        ProductName = detail.ProductName,

                        PaymentType   = item.PaymentType,
                        PaymentMethod = item.PaymentMethod,

                        PaymentDueDate = item.DODate.AddDays(detail.PaymentDueDays),

                        UOMId   = detail.UomId,
                        UOMUnit = detail.UomUnit,

                        PricePerDealUnit = detail.PricePerDealUnit,
                        PriceTotal       = detail.PricePerDealUnit * detail.PricePerDealUnit,
                    });
                }
            }



            List <GarmentInternNoteItem> garmentInternNoteItems = new List <GarmentInternNoteItem>
            {
                new GarmentInternNoteItem
                {
                    InvoiceId   = garmentInvoice.Id,
                    InvoiceNo   = garmentInvoice.InvoiceNo,
                    InvoiceDate = garmentInvoice.InvoiceDate,
                    TotalAmount = 20000,
                    Details     = garmentInternNoteDetails
                }
            };

            GarmentInternNote garmentInternNote = new GarmentInternNote
            {
                INNo   = "NI1234L",
                INDate = new DateTimeOffset(),

                SupplierId   = garmentInvoice.SupplierId,
                SupplierCode = garmentInvoice.SupplierCode,
                SupplierName = garmentInvoice.SupplierCode,

                CurrencyId   = garmentInvoice.CurrencyId,
                CurrencyCode = garmentInvoice.CurrencyCode,
                CurrencyRate = 5,


                Remark = null,

                Items = garmentInternNoteItems
            };

            return(garmentInternNote);
        }
예제 #21
0
 public SupplierDto(GarmentInternNote element)
 {
     Id   = (int)element.SupplierId.GetValueOrDefault();
     Code = element.SupplierCode;
     Name = element.SupplierName;
 }