Пример #1
0
        private void reporteDePagosToolStripMenuItem_Click(object sender, EventArgs e)
        {
            PaymentsReport reportForm = new PaymentsReport();

            reportForm.MdiParent = this;
            reportForm.Show();
        }
        // private List<PaymentsReport> _paymentsReport;
        public List <PaymentsReport> GetReport(PaymentsReport paymentsReport)
        {
            var x            = new List <PaymentsReport>();
            var paymentsItem = new PaymentsReport();

            paymentsItem.VehicleName = "Auto";
            x.Add(paymentsItem);
            return(x);
        }
        public List <PaymentsReport> GetReport(int year)
        {
            // Get vehicles, using vehicle service or vehicle repository to get data
            List <PaymentsReport> paymentsReport = new List <PaymentsReport>();

            var vehicles     = _vehicleService.GetVehicles();
            var payments     = _paymentRepository.Get();
            var paymentsYear = year;

            foreach (var vehicle in vehicles)
            {
                var reportItem = new PaymentsReport();
                reportItem.VehicleId   = vehicle.Id;
                reportItem.VehicleName = vehicle.Registration + ' ' + vehicle.Mark;

                // Get payments by vehicle id

                // 1 = all
                var vehiclePayments = payments.Where(p => p.VehicleId == vehicle.Id && p.Day.Year == paymentsYear).ToList();

                // var vehiclePayments = payments.Where(p => p.VehicleId == vehicle.Id && p.Day.Year == paymentsYear).ToList();

                // Filter by Payments, group by quartal
                var vehicleFuelPayments      = vehiclePayments.Where(p => p.Fuel != null);
                var vehicleServicePayments   = vehiclePayments.Where(p => p.Service != null);
                var vehiclePartsPayments     = vehiclePayments.Where(p => p.Parts != null);
                var vehicleInsurancePayments = vehiclePayments.Where(p => p.Insurance != null);
                var vehicleTaxPayments       = vehiclePayments.Where(p => p.Tax != null);

                var vehicleQuarterlyFuelPayments = vehicleFuelPayments.GroupBy(item => ((item.Day.Month - 1) / 3),
                                                                               (key, group) => new PaymentQuartal(key + 1, group.Sum(p => p.Fuel))).ToList();

                var vehicleQuarterlyServicePayments = vehicleServicePayments.GroupBy(item => ((item.Day.Month - 1) / 3),
                                                                                     (key, group) => new PaymentQuartal(key + 1, group.Sum(p => p.Service))).ToList();

                var vehicleQuarterlyPartsPayments = vehiclePartsPayments.GroupBy(item => ((item.Day.Month - 1) / 3),
                                                                                 (key, group) => new PaymentQuartal(key + 1, group.Sum(p => p.Parts))).ToList();

                var vehicleQuarterlyInsurancePayments = vehicleInsurancePayments.GroupBy(item => ((item.Day.Month - 1) / 3),
                                                                                         (key, group) => new PaymentQuartal(key + 1, group.Sum(p => p.Insurance))).ToList();

                var vehicleQuarterlyTaxPayments = vehicleTaxPayments.GroupBy(item => ((item.Day.Month - 1) / 3),
                                                                             (key, group) => new PaymentQuartal(key + 1, group.Sum(p => p.Tax))).ToList();

                reportItem.Fuel      = new List <PaymentQuartal>();
                reportItem.Service   = new List <PaymentQuartal>();
                reportItem.Parts     = new List <PaymentQuartal>();
                reportItem.Insurance = new List <PaymentQuartal>();
                reportItem.Tax       = new List <PaymentQuartal>();
                var collectionList = new List <PaymentQuartal>();

                reportItem.QuarterlySum = new List <PaymentQuartal>();

                foreach (var p in vehicleQuarterlyFuelPayments)
                {
                    reportItem.Fuel.Add(p);
                    collectionList.Add(p);
                }

                foreach (var p in vehicleQuarterlyServicePayments)
                {
                    reportItem.Service.Add(p);
                    collectionList.Add(p);
                }

                foreach (var p in vehicleQuarterlyPartsPayments)
                {
                    reportItem.Parts.Add(p);
                    collectionList.Add(p);
                }
                foreach (var p in vehicleQuarterlyInsurancePayments)
                {
                    reportItem.Insurance.Add(p);
                    collectionList.Add(p);
                }
                foreach (var p in vehicleQuarterlyTaxPayments)
                {
                    reportItem.Tax.Add(p);
                    collectionList.Add(p);
                }

                // Sum payments per quartal
                for (int i = 1; i <= 4; i++)
                {
                    var reportListItem = new PaymentQuartal();
                    reportListItem.QuartalSum = collectionList.Where(a => a.Quartal == i).Sum(s => s.QuartalSum);
                    reportListItem.Quartal    = i;
                    reportItem.QuarterlySum.Add(reportListItem);
                }

                // Payments per year
                reportItem.YearlySum = collectionList.Sum(s => s.QuartalSum);

                // Adding assorted items
                paymentsReport.Add(reportItem);
            }

            // Return report
            return(paymentsReport);
        }