Beispiel #1
0
        //Get : Payments/GeneratePaymentHistory
        public ActionResult GeneratePaymentHistoryReport(
            int?ShippingAccountId,
            DateTime?StartingDate,
            DateTime?EndingDate,
            string sortOrder,
            int?currentShippingAccountId,
            DateTime?currentStartingDate,
            DateTime?currentEndingDate,
            int?page)
        {
            if (ShippingAccountId == null)
            {
                ShippingAccountId = currentShippingAccountId;
            }

            // Instantiate an instance of the PaymentsReportViewModel and the PaymentsSearchViewModel.
            var PaymentReport = new PaymentsReportViewModel();

            PaymentReport.PaymentSearch = new PaymentsSearchViewModel();

            // Code for paging.
            ViewBag.CurrentSort = sortOrder;
            int pageSize   = 5;
            int pageNumber = (page ?? 1);

            // Retain search conditions for sorting.
            if (StartingDate == null)
            {
                StartingDate = currentStartingDate;
            }
            if (EndingDate == null)
            {
                EndingDate = currentEndingDate;
            }
            if (ShippingAccountId == null)
            {
                ShippingAccountId = currentShippingAccountId;
            }
            else
            {
                page = 1;
            }
            ViewBag.CurrentShippingAccountId = ShippingAccountId;
            ViewBag.CurrentStartingDate      = StartingDate;
            ViewBag.CurrentEndingDate        = EndingDate;


            // Populate the ShippingAccountId dropdown list.
            var shippingAccountQuery = db.Invoices.Select(s => s.UserName).Distinct().OrderBy(s => s);
            var hehe = db.ShippingAccounts.Where(m => shippingAccountQuery.Contains(m.UserName)).Select(m => m.ShippingAccountID).Distinct().OrderBy(m => m);


            var n = (new SelectList(hehe)).ToList();

            foreach (SelectListItem k in n)
            {
                k.Value = k.Text;
            }
            n.Insert(0, new SelectListItem
            {
                Text  = "All",
                Value = "0"
            });
            int haha = 0;

            for (int i = 0; i < n.Count(); i++)
            {
                if (n.ElementAt(i).Value == ShippingAccountId.ToString())
                {
                    haha = i;
                    break;
                }
            }
            foreach (var item in n)
            {
                if (item.Value == ShippingAccountId.ToString())
                {
                    item.Selected = true;
                }
            }
            PaymentReport.PaymentSearch.ShippingAccounts  = n;
            PaymentReport.PaymentSearch.ShippingAccountId = ShippingAccountId == null ? 0 : (int)ShippingAccountId;
            //Initialize the query to retrieve payments using the PaymentsListViewModel.
            var list = new List <PaymentsListViewModel>();

            foreach (Invoice v in db.Invoices)
            {
                PaymentsListViewModel m = new PaymentsListViewModel();
                Shipment ship           = db.Shipments.Where(a => a.WaybillID == v.WaybillID).First();
                m.WaybillId          = v.WaybillID;
                m.ShippingAccountId  = v.PayerCharacter == "Recipient" ? ship.RecipientShippingAccountID : ship.ShippingAccountID;
                m.ShipDate           = (DateTime)ship.PickupDate;
                m.RecipientName      = ship.RecipientName;
                m.OriginCity         = ship.Origin;
                m.DestinationCity    = ship.Destination;
                m.ServiceType        = db.ServiceTypes.Single(a => a.Type == ship.ServiceType).Type;
                m.TotalPaymentAmount = v.PaymentAmount;
                m.PaymentDescription = v.PaymentDescription;
                list.Add(m);
            }
            var paymentQuery = list.AsQueryable();

            // Add the condition to select a spefic shipping account if shipping account id is not null.
            if (ShippingAccountId != 0 && ShippingAccountId != null)
            {
                // TODO: Construct the LINQ query to retrive only the shipments for the specified shipping account id.
                paymentQuery = paymentQuery.Where(s => s.ShippingAccountId == ShippingAccountId);
            }

            if ((StartingDate != null) && (EndingDate != null))
            {
                paymentQuery = paymentQuery.Where(s => (s.ShipDate > StartingDate && s.ShipDate < EndingDate));
            }
            else
            {
                // Return an empty result if no shipping account id has been selected.
                PaymentReport.PaymentList = new PaymentsListViewModel[0].ToPagedList(pageNumber, pageSize);
            }

            // Code for sorting on ServiceType, ShippedDate, DeliveredDate, RecipientName, Origin, Destination
            ViewBag.ServiceTypeSortParm   = sortOrder == "serviceType" ? "serviceType_desc" : "serviceType";
            ViewBag.ShippedDateSortParm   = sortOrder == "shippedDate" ? "shippedDate_desc" : "shippedDate";
            ViewBag.RecipientNameSortParm = sortOrder == "recipientName" ? "recipientName_desc" : "recipientName";
            ViewBag.OriginSortParm        = sortOrder == "origin" ? "origin_desc" : "origin";
            ViewBag.DestinationSortParm   = sortOrder == "destination" ? "destination_desc" : "destination";
            ViewBag.InvoiceAmountSortParm = sortOrder == "invoiceAmount" ? "invoiceAmount_desc" : "invoiceAmount";
            switch (sortOrder)
            {
            case "serviceType_desc":
                paymentQuery = paymentQuery.OrderByDescending(s => s.ServiceType);
                break;

            case "serviceType":
                paymentQuery = paymentQuery.OrderBy(s => s.ServiceType);
                break;

            case "shippedDate_desc":
                paymentQuery = paymentQuery.OrderByDescending(s => s.ShipDate);
                break;

            case "shippedDate":
                paymentQuery = paymentQuery.OrderBy(s => s.ShipDate);
                break;

            case "recipientName_desc":
                paymentQuery = paymentQuery.OrderByDescending(s => s.RecipientName);
                break;

            case "recipientName":
                paymentQuery = paymentQuery.OrderBy(s => s.RecipientName);
                break;

            case "origin_desc":
                paymentQuery = paymentQuery.OrderByDescending(s => s.OriginCity);
                break;

            case "origin":
                paymentQuery = paymentQuery.OrderBy(s => s.OriginCity);
                break;

            case "destination_desc":
                paymentQuery = paymentQuery.OrderByDescending(s => s.DestinationCity);
                break;

            case "destination":
                paymentQuery = paymentQuery.OrderBy(s => s.DestinationCity);
                break;

            case "invoiceAmount_desc":
                paymentQuery = paymentQuery.OrderByDescending(s => s.TotalPaymentAmount);
                break;

            case "invoiceAmount":
                paymentQuery = paymentQuery.OrderBy(s => s.TotalPaymentAmount);
                break;

            default:
                paymentQuery = paymentQuery.OrderBy(s => s.WaybillId);
                break;
            }
            PaymentReport.PaymentList = paymentQuery.ToPagedList(pageNumber, pageSize);
            return(View(PaymentReport));
        }
Beispiel #2
0
        // GET: Shipments/GenerateHistoryReport
        public ActionResult GenerateHistoryReport(int?ShippingAccountId, string sortOrder, string ServiceType, DateTime?ShippedDate, DateTime?DeliveredDate, string RecipientName, string Origin, string Destination, string currentServiceType, DateTime?currentShippedDate, DateTime?currentDeliveredDate, string currentRecipientName, string currentOrigin, string currentDestination, int?currentShippingAccountId, int?page,
                                                  DateTime?FromShippedDate, DateTime?FromDeliveredDate, DateTime?CURRENTToShippedDate, DateTime?CURRENTToDeliveredDate
                                                  //to be done
                                                  /*string From_Year, string From_Month, string From_Day, string UNTIL_Year, string UNTIL_Month, string UNTIL_Day*/
                                                  )
        {
            // Instantiate an instance of the ShipmentsReportViewModel and the ShipmentsSearchViewModel.
            var shipmentSearch = new ShipmentsReportViewModel();

            shipmentSearch.Shipment = new ShipmentsSearchViewModel();

            //Code for paging
            ViewBag.CurrentSort = sortOrder;
            int pageSize   = 5;
            int pageNumber = (page ?? 1);

            //DateRangeSearch
            if (FromShippedDate == null)
            {
                FromShippedDate = CURRENTToShippedDate;
            }
            else
            {
                page = 1;
            }

            if (FromDeliveredDate == null)
            {
                FromDeliveredDate = CURRENTToDeliveredDate;
            }
            else
            {
                page = 1;
            }

            //Retain search condition for sorting
            if (ShippingAccountId == null) //ServiceType == null && ShippedDate == null && DeliveredDate == null && RecipientName == null && Origin == null && Destination == null
            {
                ShippingAccountId = currentShippingAccountId;
                ServiceType       = currentServiceType;
                ShippedDate       = currentShippedDate;
                DeliveredDate     = currentDeliveredDate;
                RecipientName     = currentRecipientName;
                Origin            = currentOrigin;
                Destination       = currentDestination;
            }
            else
            {
                page = 1;
            }
            ViewBag.CurrentShippingAccountId = ShippingAccountId.GetValueOrDefault(); //ViewBag.CurrentShippingAccountId = ShippingAccountId; does not make visible error in my understanding

            ViewBag.CurrentServiceType   = currentServiceType;
            ViewBag.CurrentShippedDate   = currentShippedDate;
            ViewBag.CurrentDeliveredDate = currentDeliveredDate;
            ViewBag.CurrentRecipientName = currentRecipientName;
            ViewBag.CurrentOrigin        = currentOrigin;
            ViewBag.CurrentDestination   = currentDestination;


            // Populate the ShippingAccountId dropdown list.
            shipmentSearch.Shipment.ShippingAccounts  = PopulateShippingAccountsDropdownList().ToList();
            shipmentSearch.Shipment.ShippingAccountId = currentShippingAccountId ?? default(int);

            // Initialize the query to retrieve shipments using the ShipmentsListViewModel.
            var shipmentQuery = from s in db.Shipments
                                //orderby s.WaybillId
                                where ShippingAccountId == s.ShippingAccountId
                                select new ShipmentsListViewModel
            {
                WaybillId         = s.WaybillId,
                ServiceType       = s.ServiceType,
                ShippedDate       = s.ShippedDate,
                DeliveredDate     = s.DeliveredDate,
                RecipientName     = s.RecipientName,
                NumberOfPackages  = s.NumberOfPackages,
                Origin            = s.Origin,
                Destination       = s.Destination,
                ShippingAccountId = s.ShippingAccountId
            };

            //DateRangeSearch
            // Add the condition to select a spefic ShippedDate user input if ShippedDate is not null.
            if (FromShippedDate != null)
            {
                // TODO: Construct the LINQ query to retrive only the shipments for the specified shipping account id.
                shipmentQuery = shipmentQuery.Where(a => a.ShippedDate >= FromShippedDate).OrderBy(b => b.WaybillId);
            }
            // Add the condition to select a spefic ShippedDate user input if ShippedDate is not null.
            if (FromDeliveredDate != null)
            {
                // TODO: Construct the LINQ query to retrive only the shipments for the specified shipping account id.
                shipmentQuery = shipmentQuery.Where(a => a.DeliveredDate <= FromDeliveredDate).OrderBy(b => b.WaybillId);
            }
            if (User.IsInRole("Employee"))
            {
                return(View(db.Shipments.ToList()));
            }

            // Add the condition to select a spefic shipping account if shipping account id is not null.
            if (ShippingAccountId != null)
            {
                // TODO: Construct the LINQ query to retrive only the shipments for the specified shipping account id.
                shipmentQuery = shipmentQuery.Where(a => a.ShippingAccountId == ShippingAccountId).OrderBy(b => b.WaybillId);
            }

            /*           else
             *         {
             *             // Return an empty result if no shipping account id has been selected.
             *             shipmentSearch.Shipments = new ShipmentsListViewModel[0];
             *         }
             */
            //Code for osrting on WaybillId, ServiceType, ShippedDate, DeliveredDate, RecipientName, Origin and Destination
            ViewBag.ServiceTypeSortParm   = string.IsNullOrEmpty(sortOrder) ? "ServiceType_desc" : "ServiceType";
            ViewBag.ShippedDateSortParm   = string.IsNullOrEmpty(sortOrder) ? "ShippedDate_desc" : "ShippedDate";
            ViewBag.DeliveredDateSortParm = string.IsNullOrEmpty(sortOrder) ? "DeliveredDate_desc" : "DeliveredDate";
            ViewBag.RecipientNameSortParm = string.IsNullOrEmpty(sortOrder) ? "RecipientName_desc" : "RecipientName";
            ViewBag.OriginSortParm        = string.IsNullOrEmpty(sortOrder) ? "Origin_desc" : "Origin";
            ViewBag.DestinationSortParm   = string.IsNullOrEmpty(sortOrder) ? "Destination_desc" : "Destination";
            switch (sortOrder)
            {
            case "ServiceType_desc":
                shipmentQuery = shipmentQuery.OrderByDescending(s => s.ServiceType);
                break;

            case "ShippedDate_desc":
                shipmentQuery = shipmentQuery.OrderByDescending(s => s.ShippedDate);
                break;

            case "DeliveredDate_desc":
                shipmentQuery = shipmentQuery.OrderByDescending(s => s.DeliveredDate);
                break;

            case "RecipientName_desc":
                shipmentQuery = shipmentQuery.OrderByDescending(s => s.RecipientName);
                break;

            case "Origin_desc":
                shipmentQuery = shipmentQuery.OrderByDescending(s => s.Origin);
                break;

            case "Destination_desc":
                shipmentQuery = shipmentQuery.OrderByDescending(s => s.Destination);
                break;

            case "ServiceType":
                shipmentQuery = shipmentQuery.OrderBy(s => s.ServiceType);
                break;

            case "ShippedDate":
                shipmentQuery = shipmentQuery.OrderBy(s => s.ShippedDate);
                break;

            case "DeliveredDate":
                shipmentQuery = shipmentQuery.OrderBy(s => s.DeliveredDate);
                break;

            case "RecipientName":
                shipmentQuery = shipmentQuery.OrderBy(s => s.RecipientName);
                break;

            case "Origin":
                shipmentQuery = shipmentQuery.OrderBy(s => s.Origin);
                break;

            case "Destination":
                shipmentQuery = shipmentQuery.OrderBy(s => s.Destination);
                break;

            default:
                break;
            }
            //  shipmentSearch.Shipments = shipmentQuery.ToList();
            shipmentSearch.Shipments = shipmentQuery.ToPagedList(pageNumber, pageSize);
            return(View(shipmentSearch));
        }
Beispiel #3
0
        public ActionResult GeneratePaymentHistoryReport(
            int?ShippingAccountId,
            int?WaybillId,
            DateTime?StartingDate,
            DateTime?EndingDate,
            string sortOrder,
            int?currentShippingAccountId,
            int?currentWaybillId,
            DateTime?currentStartingDate,
            DateTime?currentEndingDate,
            int?page)
        {
            // Instantiate an instance of the PaymentsReportViewModel and the PaymentsSearchViewModel.
            var PaymentReport = new PaymentsReportViewModel();

            PaymentReport.PaymentSearch = new PaymentsSearchViewModel();

            // Code for paging.
            ViewBag.CurrentSort = sortOrder;
            int pageSize   = 5;
            int pageNumber = (page ?? 1);

            // Retain search conditions for sorting.
            if (StartingDate == null)
            {
                StartingDate = currentStartingDate;
            }
            if (EndingDate == null)
            {
                EndingDate = currentEndingDate;
            }
            if (ShippingAccountId == null)
            {
                ShippingAccountId = currentShippingAccountId;
            }
            if (WaybillId == null)
            {
                WaybillId = currentWaybillId;
            }
            else
            {
                page = 1;
            }
            ViewBag.CurrentShippingAccountId = ShippingAccountId;
            ViewBag.CurrentWaybillId         = WaybillId;
            ViewBag.CurrentStartingDate      = StartingDate;
            ViewBag.CurrentEndingDate        = EndingDate;

            PaymentReport.PaymentSearch.ShippingAccountId = ShippingAccountId == null ? 0 : (int)ShippingAccountId;
            PaymentReport.PaymentSearch.WaybillId         = WaybillId == null ? 0 : (int)WaybillId;
            // Populate the ShippingAccountId dropdown list.

            if (User.IsInRole("Employee"))
            {
                var n = PopulateShippingAccountsDropdownList().ToList();
                foreach (SelectListItem k in n)
                {
                    k.Value = k.Text;
                }
                n.Insert(0, new SelectListItem
                {
                    Text  = "All",
                    Value = "0"
                });
                int haha = 0;
                for (int i = 0; i < n.Count(); i++)
                {
                    if (n.ElementAt(i).Value == ShippingAccountId.ToString())
                    {
                        haha = i;
                        break;
                    }
                }
                foreach (var item in n)
                {
                    if (item.Value == ShippingAccountId.ToString())
                    {
                        item.Selected = true;
                    }
                }
                PaymentReport.PaymentSearch.ShippingAccounts = n;
                if (!(ShippingAccountId == 0 || ShippingAccountId == null))
                {
                    string accountusername = db.ShippingAccounts.Single(i => i.ShippingAccountId == ShippingAccountId).UserName;
                    PaymentReport.PaymentSearch.WaybillIds = new SelectList(db.Payments.Where(o => o.UserName == accountusername).Select(o => o.WaybillID).Distinct()).ToList();
                }
                else
                {
                    IQueryable <int> foo = Enumerable.Empty <int>().AsQueryable();
                    foo = foo.Concat(new int[] { 0 });
                    PaymentReport.PaymentSearch.WaybillIds = new SelectList(foo).ToList();
                }
            }
            else
            {
                PaymentReport.PaymentSearch.ShippingAccounts = null;
                string accountusername = GetCurrentAccount().UserName;
                PaymentReport.PaymentSearch.WaybillIds = new SelectList(db.Payments.Where(o => o.UserName == accountusername).Select(o => o.WaybillID).Distinct()).ToList();
            }

            //Initialize the query to retrieve payments using the PaymentsListViewModel.
            var list = new List <PaymentsListViewModel>();

            foreach (Payment v in db.Payments)
            {
                PaymentsListViewModel m = new PaymentsListViewModel();
                Shipment ship           = db.Shipments.SingleOrDefault(a => a.WaybillId == v.WaybillID);
                m.WaybillId          = v.WaybillID;
                m.ShippingAccountId  = v.PayerCharacter == "Recipient" ? ship.RecipientShippingAccountID : ship.SenderShippingAccountID;
                m.ShipDate           = (DateTime)ship.PickupDate;
                m.RecipientName      = ship.RecipientFullName;
                m.OriginCity         = ship.Origin;
                m.DestinationCity    = ship.Destination;
                m.ServiceType        = db.ServiceTypes.Single(a => a.ServiceTypeID == ship.ServiceTypeID).Type;
                m.TotalPaymentAmount = v.PaymentAmount;
                m.PaymentDescription = v.PaymentDescription;
                m.CurrencyCode       = v.CurrencyCode;

                ShippingAccount lala_account  = db.ShippingAccounts.Single(a => a.UserName == v.UserName);
                Shipment        lala_shipment = db.Shipments.Single(a => a.WaybillId == v.WaybillID);
                m.SenderReferenceNumber = lala_shipment.ReferenceNumber;
                m.SenderFullName        = "";
                if (lala_shipment.SenderShippingAccount is PersonalShippingAccount)
                {
                    PersonalShippingAccount temp = (PersonalShippingAccount)db.ShippingAccounts.Single(a => a.ShippingAccountId == lala_shipment.SenderShippingAccountID);
                    m.SenderFullName = temp.FirstName + temp.LastName;
                }
                else
                {
                    BusinessShippingAccount temp = (BusinessShippingAccount)db.ShippingAccounts.Single(a => a.ShippingAccountId == lala_shipment.SenderShippingAccountID);
                    m.SenderFullName = temp.ContactPersonName;
                }
                m.SenderMailingAddress     = lala_shipment.SenderShippingAccount.ProvinceCode + ", " + lala_shipment.SenderShippingAccount.City + ", " + lala_shipment.SenderShippingAccount.StreetInformation + ", " + lala_shipment.SenderShippingAccount.BuildingInformation;
                m.RecipientFullName        = lala_shipment.RecipientFullName;
                m.RecipientDeliveryAddress = lala_shipment.RecipientDeliveryProvince + ", " + lala_shipment.RecipientDeliveryCity + ", " + lala_shipment.RecipientDeliveryStreet + ", " + lala_shipment.RecipientDeliveryBuilding;
                m.CreditCardType           = lala_account.Type;
                m.CreditCardNumber         = lala_account.Number.Substring(lala_account.Number.Length - 4);
                m.AuthorizationCode        = v.AuthorizationCode;

                m.Packages = lala_shipment.Packages;
                list.Add(m);
            }
            var paymentQuery = list.AsQueryable();

            // Add the condition to select a spefic shipping account if shipping account id is not null.

            if (User.IsInRole("Employee"))
            {
                if (ShippingAccountId != 0 && ShippingAccountId != null)
                {
                    paymentQuery = paymentQuery.Where(s => s.ShippingAccountId == ShippingAccountId);
                    if (WaybillId != 0 && WaybillId != null)
                    {
                        paymentQuery = paymentQuery.Where(s => s.WaybillId == WaybillId);
                    }
                }
            }
            else
            {
                int accountid = GetCurrentAccount().ShippingAccountId;
                ViewBag.lala = accountid;
                paymentQuery = paymentQuery.Where(p => p.ShippingAccountId == accountid);
                if (WaybillId != 0 && WaybillId != null)
                {
                    paymentQuery = paymentQuery.Where(s => s.WaybillId == WaybillId);
                }
            }


            if ((StartingDate != null) && (EndingDate != null))
            {
                paymentQuery = paymentQuery.Where(s => (s.ShipDate > StartingDate && s.ShipDate < EndingDate));
            }
            else
            {
                // Return an empty result if no shipping account id has been selected.
                PaymentReport.PaymentList = new PaymentsListViewModel[0].ToPagedList(pageNumber, pageSize);
            }

            // Code for sorting on ServiceType, ShippedDate, DeliveredDate, RecipientName, Origin, Destination
            ViewBag.ServiceTypeSortParm   = sortOrder == "serviceType" ? "serviceType_desc" : "serviceType";
            ViewBag.ShippedDateSortParm   = sortOrder == "shippedDate" ? "shippedDate_desc" : "shippedDate";
            ViewBag.RecipientNameSortParm = sortOrder == "recipientName" ? "recipientName_desc" : "recipientName";
            ViewBag.OriginSortParm        = sortOrder == "origin" ? "origin_desc" : "origin";
            ViewBag.DestinationSortParm   = sortOrder == "destination" ? "destination_desc" : "destination";
            ViewBag.InvoiceAmountSortParm = sortOrder == "invoiceAmount" ? "invoiceAmount_desc" : "invoiceAmount";
            switch (sortOrder)
            {
            case "serviceType_desc":
                paymentQuery = paymentQuery.OrderByDescending(s => s.ServiceType);
                break;

            case "serviceType":
                paymentQuery = paymentQuery.OrderBy(s => s.ServiceType);
                break;

            case "shippedDate_desc":
                paymentQuery = paymentQuery.OrderByDescending(s => s.ShipDate);
                break;

            case "shippedDate":
                paymentQuery = paymentQuery.OrderBy(s => s.ShipDate);
                break;

            case "recipientName_desc":
                paymentQuery = paymentQuery.OrderByDescending(s => s.RecipientName);
                break;

            case "recipientName":
                paymentQuery = paymentQuery.OrderBy(s => s.RecipientName);
                break;

            case "origin_desc":
                paymentQuery = paymentQuery.OrderByDescending(s => s.OriginCity);
                break;

            case "origin":
                paymentQuery = paymentQuery.OrderBy(s => s.OriginCity);
                break;

            case "destination_desc":
                paymentQuery = paymentQuery.OrderByDescending(s => s.DestinationCity);
                break;

            case "destination":
                paymentQuery = paymentQuery.OrderBy(s => s.DestinationCity);
                break;

            case "invoiceAmount_desc":
                paymentQuery = paymentQuery.OrderByDescending(s => s.TotalPaymentAmount);
                break;

            case "invoiceAmount":
                paymentQuery = paymentQuery.OrderBy(s => s.TotalPaymentAmount);
                break;

            default:
                paymentQuery = paymentQuery.OrderBy(s => s.WaybillId);
                break;
            }
            PaymentReport.PaymentList = paymentQuery.ToPagedList(pageNumber, pageSize);
            if (ShippingAccountId != null && ShippingAccountId != 0 && WaybillId != 0 && WaybillId != null)
            {
                ViewBag.ShowShipmentPackages = true;
            }
            else
            {
                ViewBag.ShowShipmentPackages = null;
            }
            return(View(PaymentReport));
        }