Пример #1
0
        private void RunProdGoal()
        {
            //If adding the unearned column, need more space. Set report to landscape.
            if (checkAllProv.Checked)
            {
                for (int i = 0; i < listProv.Items.Count; i++)
                {
                    listProv.SetSelected(i, true);
                }
            }
            if (checkAllClin.Checked)
            {
                for (int i = 0; i < listClin.Items.Count; i++)
                {
                    listClin.SetSelected(i, true);
                }
            }
            _dateFrom = PIn.Date(textDateFrom.Text);
            _dateTo   = PIn.Date(textDateTo.Text);
            List <Provider> listProvs = checkAllProv.Checked?_listProviders:
                                        listProv.SelectedIndices.Count > 0?listProv.SelectedIndices.OfType <int>().Select(x => _listFilteredProviders[x]).ToList():new List <Provider>();
            List <Clinic> listClinics            = new List <Clinic>();
            List <long>   listSelectedClinicNums = new List <long>();

            if (PrefC.HasClinicsEnabled)
            {
                if (listClin.SelectedIndices.Count > 0)
                {
                    int offset = Security.CurUser.ClinicIsRestricted?0:1;
                    listClinics.AddRange(listClin.SelectedIndices.OfType <int>()
                                         .Select(x => offset == 1 && x == 0?new Clinic {
                        ClinicNum = 0, Abbr = Lan.g(this, "Unassigned")
                    }:_listClinics[x - offset]));
                }
                //Check here for multi clinic schedule overlap and give notification.
                listSelectedClinicNums = listClinics.Select(x => x.ClinicNum).ToList();
                var listConflicts = listProvs
                                    .Select(x => new { x.Abbr, listScheds = Schedules.GetClinicOverlapsForProv(_dateFrom, _dateTo, x.ProvNum, listSelectedClinicNums) })
                                    .Where(x => x.listScheds.Count > 0).ToList();
                if (listConflicts.Count > 0)
                {
                    string errorMsg = "This report is designed to show production goals by clinic and provider.  You have one or more providers during the "
                                      + "specified period that are scheduled in more than one clinic at the same time.  Due to this, production goals cannot be reported "
                                      + "accurately.\r\nTo run this report, please fix your scheduling so each provider is only scheduled at one clinic at a time, or select "
                                      + "different providers or clinics.\r\nIn the mean time, you can run regular production and income reports instead.\r\n\r\n"
                                      + "Conflicts:\r\n"
                                      + string.Join("\r\n", listConflicts
                                                    .SelectMany(x => x.listScheds
                                                                .Select(y => x.Abbr + " " + y.SchedDate.ToShortDateString() + " " + y.StartTime.ToShortTimeString() + " - " + y.StopTime.ToShortTimeString())));
                    MsgBoxCopyPaste msgBox = new MsgBoxCopyPaste(errorMsg);
                    msgBox.ShowDialog();
                    return;
                }
            }
            ReportComplex report        = new ReportComplex(true, false);
            bool          hasAllClinics = checkAllClin.Checked && listSelectedClinicNums.Contains(0) &&
                                          Clinics.GetDeepCopy().Select(x => x.ClinicNum).All(x => x.In(listSelectedClinicNums));

            using (DataSet ds = RpProdGoal.GetData(_dateFrom, _dateTo, listProvs, listClinics, checkAllProv.Checked, hasAllClinics, GetWriteoffType()))
                using (DataTable dt = ds.Tables["Total"])
                    using (DataTable dtClinic = PrefC.HasClinicsEnabled?ds.Tables["Clinic"]:new DataTable())
                        using (Font font = new Font("Tahoma", 8, FontStyle.Regular)) {
                            report.ReportName = "MonthlyP&IGoals";
                            report.AddTitle("Title", Lan.g(this, "Monthly Production Goal"));
                            report.AddSubTitle("PracName", PrefC.GetString(PrefName.PracticeTitle));
                            report.AddSubTitle("Date", _dateFrom.ToShortDateString() + " - " + _dateTo.ToShortDateString());
                            report.AddSubTitle("Providers", checkAllProv.Checked?Lan.g(this, "All Providers"):listProvs.Count == 0?"":string.Join(", ", listProvs.Select(x => x.Abbr)));
                            if (PrefC.HasClinicsEnabled)
                            {
                                report.AddSubTitle("Clinics", hasAllClinics?Lan.g(this, "All Clinics"):listClinics.Count == 0?"":string.Join(", ", listClinics.Select(x => x.Abbr)));
                            }
                            //setup query
                            QueryObject query;
                            if (PrefC.HasClinicsEnabled && checkClinicBreakdown.Checked)
                            {
                                query = report.AddQuery(dtClinic, "", "Clinic", SplitByKind.Value, 1, true);
                            }
                            else
                            {
                                query = report.AddQuery(dt, "", "", SplitByKind.None, 1, true);
                            }
                            // add columns to report
                            int dateWidth        = 70;
                            int weekdayWidth     = 65;
                            int prodWidth        = 90;
                            int prodGoalWidth    = 90;
                            int schedWidth       = 85;
                            int adjWidth         = 85;
                            int writeoffWidth    = 95;
                            int writeoffestwidth = 95;
                            int writeoffadjwidth = 70;
                            int totProdWidth     = 90;
                            int summaryOffSetY   = 30;
                            int groups           = 1;
                            if (PrefC.HasClinicsEnabled && listClin.SelectedIndices.Count > 1 && checkClinicBreakdown.Checked)
                            {
                                groups = 2;
                            }
                            for (int i = 0; i < groups; i++) //groups will be 1 or 2 if there are clinic breakdowns
                            {
                                if (i > 0)                   //If more than one clinic selected, we want to add a table to the end of the report that totals all the clinics together
                                {
                                    query = report.AddQuery(dt, "Totals", "", SplitByKind.None, 2, true);
                                }
                                query.AddColumn("Date", dateWidth, FieldValueType.String, font);
                                query.AddColumn("Weekday", weekdayWidth, FieldValueType.String, font);
                                query.AddColumn("Production", prodWidth, FieldValueType.Number, font);
                                query.AddColumn("Prod Goal", prodGoalWidth, FieldValueType.Number, font);
                                query.AddColumn("Scheduled", schedWidth, FieldValueType.Number, font);
                                query.AddColumn("Adjusts", adjWidth, FieldValueType.Number, font);
                                if (GetWriteoffType() == PPOWriteoffDateCalc.ClaimPayDate)
                                {
                                    query.AddColumn("Writeoff Est", writeoffestwidth, FieldValueType.Number, font);
                                    query.AddColumn("Writeoff Adj", writeoffadjwidth, FieldValueType.Number, font);
                                }
                                else
                                {
                                    query.AddColumn("Writeoff", writeoffWidth, FieldValueType.Number, font);
                                }
                                query.AddColumn("Tot Prod", totProdWidth, FieldValueType.Number, font);
                            }
                            string colNameAlign = "Writeoff" + (GetWriteoffType() == PPOWriteoffDateCalc.ClaimPayDate?" Est":"");//Column used to align the summary fields.
                            string summaryText  = "Total Production (Production + Scheduled + Adjustments - Writeoff"
                                                  + (GetWriteoffType() == PPOWriteoffDateCalc.ClaimPayDate?" Ests - Writeoff Adjs":"s") + "): ";
                            query.AddGroupSummaryField(summaryText, colNameAlign, "Tot Prod", SummaryOperation.Sum, new List <int> {
                                groups
                            }, Color.Black,
                                                       new Font("Tahoma", 9, FontStyle.Bold), 75, summaryOffSetY);
                            report.AddPageNum();
                            // execute query
                            if (!report.SubmitQueries())
                            {
                                return;
                            }
                            // display report
                            using (FormReportComplex FormR = new FormReportComplex(report)) {
                                FormR.ShowDialog();
                            }
                        }
        }