Ejemplo n.º 1
0
        public PurchasingMemoDetailTextileDto Read(int id)
        {
            var model = _dbContext.PurchasingMemoDetailTextiles.FirstOrDefault(entity => entity.Id == id);


            if (model != null)
            {
                var memoIsCreated = _dbContext.PurchasingMemoTextiles.Any(entity => entity.MemoDetailId == model.Id);
                var result        = new PurchasingMemoDetailTextileDto(model.Date, new DivisionDto(model.DivisionId, model.DivisionCode, model.DivisionName), new CurrencyDto(model.CurrencyId, model.CurrencyCode, model.CurrencyRate), model.SupplierIsImport, model.Type, new List <FormItemDto>(), new List <FormDetailDto>(), model.Remark, model.Id, model.DocumentNo, memoIsCreated);

                if (model.Type == PurchasingMemoType.Disposition)
                {
                    var items            = _dbContext.PurchasingMemoDetailTextileItems.Where(entity => entity.PurchasingMemoDetailTextileId == model.Id).ToList();
                    var itemIds          = items.Select(item => item.Id).ToList();
                    var details          = _dbContext.PurchasingMemoDetailTextileDetails.Where(entity => entity.PurchasingMemoDetailTextileId == model.Id && itemIds.Contains(entity.PurchasingMemoDetailTextileItemId)).ToList();
                    var detailIds        = details.Select(detail => detail.Id).ToList();
                    var unitReceiptNotes = _dbContext.PurchasingMemoDetailTextileUnitReceiptNotes.Where(entity => entity.PurchasingMemoDetailTextileId == model.Id && itemIds.Contains(entity.PurchasingMemoDetailTextileItemId) && detailIds.Contains(entity.PurchasingMemoDetailTextileDetailId)).ToList();

                    foreach (var item in items)
                    {
                        var itemDetails = details.Where(detail => detail.PurchasingMemoDetailTextileItemId == item.Id).ToList();
                        var disposition = new DispositionDto(item.DispositionId, item.DispositionNo, item.DispositionDate, new List <FormDetailDto>());

                        foreach (var itemDetail in itemDetails)
                        {
                            var detailUnitReceiptNotes = unitReceiptNotes.Where(unitReceiptNote => unitReceiptNote.PurchasingMemoDetailTextileDetailId == itemDetail.Id).Select(unitReceiptNote => new UnitReceiptNoteDto(unitReceiptNote.UnitReceiptNoteId, unitReceiptNote.UnitReceiptNoteNo, unitReceiptNote.UnitReceiptNoteDate)).ToList();
                            var expenditure            = new ExpenditureDto(itemDetail.ExpenditureId, itemDetail.ExpenditureNo, itemDetail.ExpenditureDate);
                            var supplier         = new SupplierDto(itemDetail.SupplierId, itemDetail.SupplierCode, itemDetail.SupplierName);
                            var unitPaymentOrder = new UnitPaymentOrderDto(itemDetail.UnitPaymentOrderId, itemDetail.UnitPaymentOrderNo, itemDetail.UnitPaymentOrderDate);
                            disposition.Details.Add(new FormDetailDto(expenditure, supplier, itemDetail.Remark, unitPaymentOrder, detailUnitReceiptNotes, itemDetail.PurchaseAmountCurrency, itemDetail.PurchaseAmount, itemDetail.PaymentAmountCurrency, itemDetail.PaymentAmount));
                        }

                        result.Items.Add(new FormItemDto(disposition));
                    }
                }
                else
                {
                    var details          = _dbContext.PurchasingMemoDetailTextileDetails.Where(entity => entity.PurchasingMemoDetailTextileId == model.Id).ToList();
                    var detailIds        = details.Select(detail => detail.Id).ToList();
                    var unitReceiptNotes = _dbContext.PurchasingMemoDetailTextileUnitReceiptNotes.Where(entity => entity.PurchasingMemoDetailTextileId == model.Id && detailIds.Contains(entity.PurchasingMemoDetailTextileDetailId)).ToList();


                    foreach (var itemDetail in details)
                    {
                        var detailUnitReceiptNotes = unitReceiptNotes.Where(unitReceiptNote => unitReceiptNote.PurchasingMemoDetailTextileDetailId == itemDetail.Id).Select(unitReceiptNote => new UnitReceiptNoteDto(unitReceiptNote.UnitReceiptNoteId, unitReceiptNote.UnitReceiptNoteNo, unitReceiptNote.UnitReceiptNoteDate)).ToList();
                        var expenditure            = new ExpenditureDto(itemDetail.ExpenditureId, itemDetail.ExpenditureNo, itemDetail.ExpenditureDate);
                        var supplier         = new SupplierDto(itemDetail.SupplierId, itemDetail.SupplierCode, itemDetail.SupplierName);
                        var unitPaymentOrder = new UnitPaymentOrderDto(itemDetail.UnitPaymentOrderId, itemDetail.UnitPaymentOrderNo, itemDetail.UnitPaymentOrderDate);
                        result.Details.Add(new FormDetailDto(expenditure, supplier, itemDetail.Remark, unitPaymentOrder, detailUnitReceiptNotes, itemDetail.PurchaseAmountCurrency, itemDetail.PurchaseAmount, itemDetail.PaymentAmountCurrency, itemDetail.PaymentAmount));
                    }
                }

                return(result);
            }
            else
            {
                return(null);
            }
        }
 public FormDetailDto(ExpenditureDto expenditure, SupplierDto supplier, string remark, UnitPaymentOrderDto unitPaymentOder, List <UnitReceiptNoteDto> unitReceiptNotes, double purchaseAmountCurrency, double purchaseAmount, double paymentAmountCurrency, double paymentAmount)
 {
     Expenditure            = expenditure;
     Supplier               = supplier;
     Remark                 = remark;
     UnitPaymentOder        = unitPaymentOder;
     UnitReceiptNotes       = unitReceiptNotes;
     PurchaseAmountCurrency = purchaseAmountCurrency;
     PurchaseAmount         = purchaseAmount;
     PaymentAmountCurrency  = paymentAmountCurrency;
     PaymentAmount          = paymentAmount;
 }