private async Task <PurchasingDispositionBaseResponseViewModel> JoinReportAsync(int page, int size, string order, string filter, DateTimeOffset?dateFrom, DateTimeOffset?dateTo, int offSet)
        {
            var expeditionData = DbSet.Include(entity => entity.Items).ToList();
            var purchasingDispositionResponse = await GetPurchasingDispositionAsync(1, int.MaxValue, order, filter);

            List <PurchasingDispositionViewModel> data = purchasingDispositionResponse.data;

            List <PurchasingDispositionReportViewModel> result = new List <PurchasingDispositionReportViewModel>();

            DateTimeOffset dateFromFilter = (dateFrom == null ? new DateTime(1970, 1, 1) : dateFrom.Value.Date);
            DateTimeOffset dateToFilter   = (dateTo == null ? DateTimeOffset.UtcNow.Date : dateTo.Value.Date);

            data = data.Where(x => x.CreatedUtc.AddHours(offSet).Date >= dateFromFilter &&
                              x.CreatedUtc.AddHours(offSet).Date <= dateToFilter).ToList();

            //if (dateFrom == null && dateTo == null)
            //{
            //    data = data
            //        .Where(x => DateTimeOffset.MinValue.Date <= x.CreatedUtc.AddHours(offSet).Date
            //            && x.CreatedUtc.AddHours(offSet).Date <= DateTime.UtcNow.Date).ToList();
            //}
            //else if (dateFrom == null && dateTo != null)
            //{
            //    data = data
            //        .Where(x => DateTimeOffset.MinValue.Date <= x.CreatedUtc.AddHours(offSet).Date
            //            && x.CreatedUtc.AddHours(offSet).Date <= dateTo.Value.Date).ToList();
            //}
            //else if (dateTo == null && dateFrom != null)
            //{
            //    data = data
            //        .Where(x => dateFrom.Value.Date <= x.CreatedUtc.AddHours(offSet).Date
            //            && x.CreatedUtc.AddHours(offSet).Date <= DateTime.UtcNow.Date).ToList();
            //}
            //else
            //{
            //    data = data
            //        .Where(x => dateFrom.Value.Date <= x.CreatedUtc.AddHours(offSet).Date
            //            && x.CreatedUtc.AddHours(offSet).Date <= dateTo.Value.Date).ToList();
            //}

            foreach (var item in data)
            {
                List <UnitPaymentOrderViewModel> dataupo = new List <UnitPaymentOrderViewModel>();
                List <string> dono  = new List <string>();
                List <string> urnno = new List <string>();
                //var expedition = DbContext.PurchasingDispositionExpeditions.Where(x => x.DispositionNo == item.DispositionNo).Include(x => x.Items).FirstOrDefault();
                var expedition = expeditionData.OrderByDescending(a => a.LastModifiedUtc).FirstOrDefault(x => x.DispositionNo == item.DispositionNo);
                if (expedition != null)
                {
                    foreach (var item2 in expedition.Items)
                    {
                        var epo = item2.EPOId != null?GetExternalPurchaseOrderNo(item2.EPOId) : null;

                        item2.EPONo = epo != null ? epo.no : "-";
                        //var DO = epo != null ? GetDeliveryOrderNo(epo.no) : null;
                        var upo = GetUnitPaymentOrder(item2.EPONo);
                        foreach (var i in upo)
                        {
                            dataupo.Add(i);
                            foreach (var t in i.items)
                            {
                                dono.Add(t.unitReceiptNote.deliveryOrder.no);
                                urnno.Add(t.unitReceiptNote.no);
                            }
                        }
                    }
                }



                PurchasingDispositionReportViewModel vm = new PurchasingDispositionReportViewModel()
                {
                    BankExpenditureNoteDate    = expedition == null || expedition.BankExpenditureNoteDate == DateTimeOffset.MinValue ? null : expedition.BankExpenditureNoteDate,
                    DispositionNo              = item.DispositionNo,
                    BankExpenditureNoteNo      = expedition?.BankExpenditureNoteNo,
                    BankExpenditureNotePPHDate = expedition == null || expedition.BankExpenditureNotePPHDate == DateTimeOffset.MinValue ? null : expedition.BankExpenditureNotePPHDate,
                    BankExpenditureNotePPHNo   = expedition?.BankExpenditureNotePPHNo,
                    CashierDivisionDate        = expedition == null || expedition.CashierDivisionDate == DateTimeOffset.MinValue ? null : expedition.CashierDivisionDate,
                    CreatedUtc     = item.CreatedUtc,
                    InvoiceNo      = item.ProformaNo,
                    PaymentDueDate = item.PaymentDueDate,
                    Position       = item.Position,
                    SentToVerificationDivisionDate = expedition == null ? null : new DateTimeOffset?(expedition.CreatedUtc),
                    SendDate = expedition == null ? null : ((expedition.Position == ExpeditionPosition.CASHIER_DIVISION || expedition.Position == ExpeditionPosition.SEND_TO_CASHIER_DIVISION) && expedition.SendToCashierDivisionDate != DateTimeOffset.MinValue) ? expedition.SendToCashierDivisionDate :
                               ((expedition.Position == ExpeditionPosition.SEND_TO_PURCHASING_DIVISION) && expedition.SendToPurchasingDivisionDate != DateTimeOffset.MinValue) ? expedition.SendToPurchasingDivisionDate : null,
                    SupplierName             = item.Supplier.name,
                    VerificationDivisionDate = expedition == null || expedition.VerificationDivisionDate == DateTimeOffset.MinValue ? null : expedition.VerificationDivisionDate,
                    VerifyDate              = expedition == null || expedition.VerifyDate == DateTimeOffset.MinValue ? null : expedition.VerifyDate,
                    Staff                   = item == null ? "" : item.CreatedBy,
                    PayToSupplier           = expedition != null ? expedition.PayToSupplier : 0,
                    Currency                = expedition != null ? expedition.CurrencyCode : "",
                    CurrencyRate            = item.Currency.rate,
                    Category                = expedition != null ? expedition.CategoryName : "",
                    Division                = expedition != null ? expedition.DivisionName : "",
                    Unit                    = expedition != null?string.Join("\n", expedition.Items.Select(expeditionItem => $"- {expeditionItem.UnitName}")) : "",
                    DPP                     = expedition != null ? (decimal)expedition.DPP : 0,
                    DueDateDays             = 0,
                    ExternalPurchaseOrderNo = expedition != null?string.Join(" & ", expedition.Items.Select(expeditionItem => $" {expeditionItem.EPONo}")) : "",
                                                  IncomeTax          = expedition != null ? (decimal)expedition.IncomeTaxValue : 0,
                                                  VAT                = expedition != null ? (decimal)expedition.VatValue : 0,
                                                  Total              = expedition != null ? (decimal)expedition.TotalPaid : 0,
                                                  VerifiedBy         = expedition != null ? expedition.VerificationDivisionBy : "",
                                                  UnitPaymentOrderNo = dataupo != null?string.Join(" & ", dataupo.Select(upono => $" {upono.no}").Distinct()) : "",
                                                                           UnitPaymentOrderDate                                                           = dataupo != null?string.Join(" & ", dataupo.Select(upodate => $" {upodate.date.Value.Date.ToString("dd MMM yyyy")}").Distinct()) : "",
                                                                                                                             DONo                         = dataupo != null?string.Join(" & ", dono.Distinct()) : "",
                                                                                                                                                    UrnNo = dataupo != null?string.Join(" & ", urnno.Distinct()) : "",
                };
                result.Add(vm);
            }
            foreach (var i in result)
            {
                i.ExternalPurchaseOrderNo = i.ExternalPurchaseOrderNo == "" ? "-" : i.ExternalPurchaseOrderNo;
            }
            return(new PurchasingDispositionBaseResponseViewModel
            {
                info = purchasingDispositionResponse.info,
                data = result
            });
        }
Exemple #2
0
        private async Task <PurchasingDispositionBaseResponseViewModel> JoinReportAsync(int page, int size, string order, string filter, DateTimeOffset?dateFrom, DateTimeOffset?dateTo, int offSet)
        {
            var expeditionData = DbSet.ToList();
            var purchasingDispositionResponse = await GetPurchasingDispositionAsync(page, size, order, filter);

            List <PurchasingDispositionViewModel> data = purchasingDispositionResponse.data;

            List <PurchasingDispositionReportViewModel> result = new List <PurchasingDispositionReportViewModel>();

            DateTimeOffset dateFromFilter = (dateFrom == null ? new DateTime(1970, 1, 1) : dateFrom.Value.Date);
            DateTimeOffset dateToFilter   = (dateTo == null ? DateTimeOffset.UtcNow.Date : dateTo.Value.Date);

            data = data.Where(x => x.CreatedUtc.AddHours(offSet).Date >= dateFromFilter &&
                              x.CreatedUtc.AddHours(offSet).Date <= dateToFilter).ToList();

            //if (dateFrom == null && dateTo == null)
            //{
            //    data = data
            //        .Where(x => DateTimeOffset.MinValue.Date <= x.CreatedUtc.AddHours(offSet).Date
            //            && x.CreatedUtc.AddHours(offSet).Date <= DateTime.UtcNow.Date).ToList();
            //}
            //else if (dateFrom == null && dateTo != null)
            //{
            //    data = data
            //        .Where(x => DateTimeOffset.MinValue.Date <= x.CreatedUtc.AddHours(offSet).Date
            //            && x.CreatedUtc.AddHours(offSet).Date <= dateTo.Value.Date).ToList();
            //}
            //else if (dateTo == null && dateFrom != null)
            //{
            //    data = data
            //        .Where(x => dateFrom.Value.Date <= x.CreatedUtc.AddHours(offSet).Date
            //            && x.CreatedUtc.AddHours(offSet).Date <= DateTime.UtcNow.Date).ToList();
            //}
            //else
            //{
            //    data = data
            //        .Where(x => dateFrom.Value.Date <= x.CreatedUtc.AddHours(offSet).Date
            //            && x.CreatedUtc.AddHours(offSet).Date <= dateTo.Value.Date).ToList();
            //}

            foreach (var item in data)
            {
                var expedition = expeditionData.OrderByDescending(a => a.LastModifiedUtc).FirstOrDefault(x => x.DispositionNo == item.DispositionNo);
                PurchasingDispositionReportViewModel vm = new PurchasingDispositionReportViewModel()
                {
                    BankExpenditureNoteDate    = expedition == null || expedition.BankExpenditureNoteDate == DateTimeOffset.MinValue ? null : expedition.BankExpenditureNoteDate,
                    DispositionNo              = item.DispositionNo,
                    BankExpenditureNoteNo      = expedition?.BankExpenditureNoteNo,
                    BankExpenditureNotePPHDate = expedition == null || expedition.BankExpenditureNotePPHDate == DateTimeOffset.MinValue ? null : expedition.BankExpenditureNotePPHDate,
                    BankExpenditureNotePPHNo   = expedition?.BankExpenditureNotePPHNo,
                    CashierDivisionDate        = expedition == null || expedition.CashierDivisionDate == DateTimeOffset.MinValue ? null : expedition.CashierDivisionDate,
                    CreatedUtc     = item.CreatedUtc,
                    InvoiceNo      = item.ProformaNo,
                    PaymentDueDate = item.PaymentDueDate,
                    Position       = item.Position,
                    SentToVerificationDivisionDate = expedition == null ? null : new DateTimeOffset?(expedition.CreatedUtc),
                    SendDate = expedition == null ? null : ((expedition.Position == ExpeditionPosition.CASHIER_DIVISION || expedition.Position == ExpeditionPosition.SEND_TO_CASHIER_DIVISION) && expedition.SendToCashierDivisionDate != DateTimeOffset.MinValue) ? expedition.SendToCashierDivisionDate :
                               ((expedition.Position == ExpeditionPosition.SEND_TO_PURCHASING_DIVISION) && expedition.SendToPurchasingDivisionDate != DateTimeOffset.MinValue) ? expedition.SendToPurchasingDivisionDate : null,
                    SupplierName             = item.Supplier.name,
                    VerificationDivisionDate = expedition == null || expedition.VerificationDivisionDate == DateTimeOffset.MinValue ? null : expedition.VerificationDivisionDate,
                    VerifyDate    = expedition == null || expedition.VerifyDate == DateTimeOffset.MinValue ? null : expedition.VerifyDate,
                    Staff         = item == null ? "" : item.CreatedBy,
                    PayToSupplier = expedition != null ? expedition.PayToSupplier : 0,
                    Currency      = expedition != null ? expedition.CurrencyCode : ""
                };
                result.Add(vm);
            }
            return(new PurchasingDispositionBaseResponseViewModel
            {
                info = purchasingDispositionResponse.info,
                data = result
            });
        }