private int Get_last_month_for_budget_planning(ISpreadsheet spreadsheet, int next_unplanned_month)
        {
            string next_unplanned_month_as_string = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(next_unplanned_month);
            var    request_to_enter_month         = String.Format(ReconConsts.EnterMonths, next_unplanned_month_as_string);
            string month  = _input_output.Get_input(request_to_enter_month);
            int    result = 0;

            try
            {
                if (!String.IsNullOrEmpty(month) && Char.IsDigit(month[0]))
                {
                    result = Convert.ToInt32(month);
                    if (result < 1 || result > 12)
                    {
                        result = 0;
                    }
                }
            }
            catch (Exception)
            {
                // Ignore it and return zero by default.
            }

            result = Handle_zero_month_choice_result(result, spreadsheet, next_unplanned_month);
            return(result);
        }
Example #2
0
 public GenerateFiles(IConfig config, ISpreadsheet spreadsheet, IFileSystem fileSystem, IOutputWriter outputWriter)
 {
     this.config       = config;
     this.spreadsheet  = spreadsheet;
     this.fileSystem   = fileSystem;
     this.outputWriter = outputWriter;
 }
Example #3
0
        Load <TThirdPartyType, TOwnedType>(
            ISpreadsheet spreadsheet,
            IFileIO <TOwnedType> pending_file_io,
            ICSVFile <TOwnedType> pending_file,
            IFileIO <TThirdPartyType> third_party_file_io,
            IFileIO <TOwnedType> owned_file_io,
            BudgetingMonths budgeting_months,
            DataLoadingInformation <TThirdPartyType, TOwnedType> data_loading_info,
            IMatcher matcher)
            where TThirdPartyType : ICSVRecord, new()
            where TOwnedType : ICSVRecord, new()
        {
            Load_pending_data(pending_file_io, pending_file, data_loading_info);
            Merge_budget_data(spreadsheet, pending_file, budgeting_months, data_loading_info);
            Merge_other_data(spreadsheet, pending_file, budgeting_months, data_loading_info);
            Generate_ad_hoc_data(spreadsheet, pending_file, budgeting_months, data_loading_info);
            Merge_unreconciled_data(spreadsheet, pending_file, data_loading_info);
            var reconciliator = Load_third_party_and_owned_files_into_reconciliator <TThirdPartyType, TOwnedType>(
                data_loading_info,
                third_party_file_io,
                owned_file_io,
                spreadsheet);
            var reconciliation_interface = Create_reconciliation_interface(data_loading_info, reconciliator, matcher);

            return(reconciliation_interface);
        }
Example #4
0
 public void Do_actions_which_require_third_party_data_access(
     IDataFile <ActualBankRecord> third_party_file,
     IDataFile <BankRecord> owned_file,
     ISpreadsheet spreadsheet,
     IInputOutput input_output)
 {
 }
Example #5
0
 public void Do_actions_which_require_third_party_data_access(
     IDataFile <CredCard2Record> third_party_file,
     IDataFile <CredCard2InOutRecord> owned_file,
     ISpreadsheet spreadsheet,
     IInputOutput input_output)
 {
 }
Example #6
0
        private BudgetingMonths Initialise_budgeting_months <TRecordType>(
            ISpreadsheet spreadsheet,
            BudgetItemListData budget_item_list_data)
            where TRecordType : ICSVRecord, new()
        {
            DateTime next_unplanned_month = _clock.Today_date_time();

            bool do_transaction_budgeting  = Confirm_budgeting(ReconConsts.ConfirmTransactionBudgeting);
            bool do_expected_out_budgeting = Confirm_budgeting(ReconConsts.ConfirmExpectedOutBudgeting);

            var budgeting_months = new BudgetingMonths
            {
                Do_expected_out_budgeting = do_expected_out_budgeting,
                Do_transaction_budgeting  = do_transaction_budgeting
            };

            if (do_transaction_budgeting)
            {
                next_unplanned_month = Get_next_unplanned_month <TRecordType>(spreadsheet, budget_item_list_data);
            }

            budgeting_months.Next_unplanned_month = next_unplanned_month.Month;
            budgeting_months.Start_year           = next_unplanned_month.Year;

            return(budgeting_months);
        }
Example #7
0
        public void Write(ISpreadsheet ss, string fileName, Func <object, string> converter = null)
        {
            using (StreamWriter sw = new StreamWriter(fileName))
            {
                if (this.HasColNames)
                {
                    if (this.HasRowNames)
                    {
                        sw.Write(FullDelimiter);
                    }

                    sw.WriteLine(WriteFields(ss.ColNames));
                }

                for (int rowIndex = 0; rowIndex < ss.NumRows; ++rowIndex)
                {
                    if (this.HasRowNames)
                    {
                        sw.Write(WriteField(ss.RowNames[rowIndex]));
                        sw.Write(FullDelimiter);
                    }

                    IEnumerable row = ss.Rows[rowIndex];

                    if (converter == null)
                    {
                        sw.WriteLine(WriteFields(row));
                    }
                    else
                    {
                        sw.WriteLine(WriteFields(row.Cast <object>().Select(converter)));
                    }
                }
            }
        }
        private void Update_bank_balance(
            ActualBankOutFile actual_bank_out_file,
            ISpreadsheet spreadsheet,
            IInputOutput input_output)
        {
            input_output.Output_line("Writing bank balance to spreadsheet...");

            IList <ActualBankRecord> potential_balance_rows = actual_bank_out_file.Get_potential_balance_rows().ToList();

            if (!potential_balance_rows.Any())
            {
                input_output.Output_line("");
                input_output.Get_generic_input(ReconConsts.CantFindBalanceRow);
            }
            else
            {
                ActualBankRecord balance_row = Choose_balance_row(potential_balance_rows, input_output);

                string balance_description = String.Format(
                    ReconConsts.BankBalanceDescription,
                    ReconConsts.Bank_descriptor,
                    balance_row.Description,
                    balance_row.Main_amount().To_csv_string(true),
                    balance_row.Date.ToString(@"dd\/MM\/yyyy"));

                spreadsheet.Update_balance_on_totals_sheet(
                    Codes.Bank_bal,
                    balance_row.Balance,
                    balance_description,
                    balance_column: ReconConsts.BankBalanceAmountColumn,
                    text_column: ReconConsts.BankBalanceTextColumn,
                    code_column: ReconConsts.BankBalanceCodeColumn,
                    input_output: input_output);
            }
        }
Example #9
0
        private void _btnOk_Click(object sender, EventArgs e)
        {
            List <string>     results = new List <string>();
            SpreadsheetReader ssr     = new SpreadsheetReader();

            foreach (QueuedExport q in this.listBox1.Items)
            {
                ISpreadsheet ss = q.Target.ExportData();

                if (ss == null)
                {
                    results.Add("NO-DATA: " + q.ToString());
                }
                else
                {
                    try
                    {
                        ssr.Write(ss, q.FileName);
                        results.Add("SUCCESS: " + q.ToString());
                    }
                    catch
                    {
                        results.Add("ERROR: " + q.ToString());
                    }
                }
            }

            FrmInputMultiLine.ShowFixed(this, this.Text, "Export", null, string.Join("\r\n\r\n", results));
        }
Example #10
0
 public void Merge_bespoke_data_with_pending_file(
     IInputOutput input_output,
     ISpreadsheet spreadsheet,
     ICSVFile <BankRecord> pending_file,
     BudgetingMonths budgeting_months,
     DataLoadingInformation <ActualBankRecord, BankRecord> data_loading_info)
 {
 }
Example #11
0
 public void Generate_ad_hoc_data(
     IInputOutput input_output,
     ISpreadsheet spreadsheet,
     ICSVFile <BankRecord> pending_file,
     BudgetingMonths budgeting_months,
     DataLoadingInformation <ActualBankRecord, BankRecord> data_loading_info)
 {
 }
Example #12
0
 public void Generate_ad_hoc_data(
     IInputOutput input_output,
     ISpreadsheet spreadsheet,
     ICSVFile <CredCard2InOutRecord> pending_file,
     BudgetingMonths budgeting_months,
     DataLoadingInformation <CredCard2Record, CredCard2InOutRecord> data_loading_info)
 {
 }
Example #13
0
        private DateTime Get_next_unplanned_month <TRecordType>(
            ISpreadsheet spreadsheet,
            BudgetItemListData budget_item_list_data)
            where TRecordType : ICSVRecord, new()
        {
            DateTime default_month        = _clock.Today_date_time();
            DateTime next_unplanned_month = default_month;
            bool     bad_input            = false;

            try
            {
                next_unplanned_month = spreadsheet.Get_next_unplanned_month <TRecordType>(budget_item_list_data);
            }
            catch (MonthlyBudgetedRowNotFoundException exception)
            {
                string new_month = _input_output.Get_input(String.Format(ReconConsts.CantFindPreviousBudgetRow, exception.Message));
                try
                {
                    if (!String.IsNullOrEmpty(new_month) && Char.IsDigit(new_month[0]))
                    {
                        int actual_month = Convert.ToInt32(new_month);
                        if (actual_month < 1 || actual_month > 12)
                        {
                            bad_input = true;
                        }
                        else
                        {
                            var year = default_month.Year;
                            if (actual_month < default_month.Month)
                            {
                                if (Month_is_smaller_because_end_of_year(actual_month, default_month.Month))
                                {
                                    year++;
                                }
                            }
                            next_unplanned_month = new DateTime(year, actual_month, 1);
                        }
                    }
                    else
                    {
                        bad_input = true;
                    }
                }
                catch (Exception)
                {
                    bad_input = true;
                }
            }

            if (bad_input)
            {
                _input_output.Output_line(ReconConsts.DefaultUnplannedMonth);
                next_unplanned_month = default_month;
            }

            return(next_unplanned_month);
        }
        private void Update_owed_CHB(IInputOutput input_output, ISpreadsheet spreadsheet, BudgetingMonths budgeting_months)
        {
            var input = input_output.Get_input("Do you want to add to the CHB total? The answer is probably No if you're not doing monthly transaction budgeting this time. Enter y/Y for Yes.");

            if (!String.IsNullOrEmpty(input) && input.ToUpper() == "Y")
            {
                spreadsheet.Update_owed_CHB(budgeting_months);
            }
        }
Example #15
0
        public void Merge_bespoke_data_with_pending_file(
            IInputOutput input_output,
            ISpreadsheet spreadsheet,
            ICSVFile <CredCard2InOutRecord> pending_file,
            BudgetingMonths budgeting_months,
            DataLoadingInformation <CredCard2Record, CredCard2InOutRecord> data_loading_info)
        {
            var most_recent_cred_card_direct_debit = spreadsheet.Get_most_recent_row_containing_text <BankRecord>(
                MainSheetNames.Bank_out,
                ReconConsts.Cred_card2_dd_description,
                new List <int> {
                ReconConsts.DescriptionColumn, ReconConsts.DdDescriptionColumn
            });

            var statement_date = new DateTime();
            var next_date      = most_recent_cred_card_direct_debit.Date.AddMonths(1);
            var input          = input_output.Get_input(string.Format(
                                                            ReconConsts.AskForCredCardDirectDebit,
                                                            ReconConsts.Cred_card2_name,
                                                            next_date.ToShortDateString()));
            double new_balance = 0;

            while (input != "0")
            {
                if (double.TryParse(input, out new_balance))
                {
                    new_balance = new_balance * -1;
                    pending_file.Records.Add(new CredCard2InOutRecord
                    {
                        Date                = next_date,
                        Description         = ReconConsts.Cred_card2_regular_pymt_description,
                        Unreconciled_amount = new_balance
                    });
                }
                statement_date = next_date.AddMonths(-1);
                next_date      = next_date.Date.AddMonths(1);
                input          = input_output.Get_input(string.Format(
                                                            ReconConsts.AskForCredCardDirectDebit,
                                                            ReconConsts.Cred_card2_name,
                                                            next_date.ToShortDateString()));
            }

            if (!new_balance.Double_equals(0))
            {
                spreadsheet.Update_balance_on_totals_sheet(
                    Codes.Cred_card2_bal,
                    new_balance,
                    string.Format(
                        ReconConsts.CredCardBalanceDescription,
                        ReconConsts.Cred_card2_name,
                        $"{statement_date.ToString("MMM")} {statement_date.Year}"),
                    balance_column: 5,
                    text_column: 6,
                    code_column: 4,
                    input_output: input_output);
            }
        }
 private void Merge_other_data <TThirdPartyType, TOwnedType>(
     ISpreadsheet spreadsheet,
     ICSVFile <TOwnedType> pending_file,
     BudgetingMonths budgeting_months,
     DataLoadingInformation <TThirdPartyType, TOwnedType> data_loading_info)
     where TThirdPartyType : ICSVRecord, new()
     where TOwnedType : ICSVRecord, new()
 {
     data_loading_info.Loader.Merge_bespoke_data_with_pending_file(_input_output, spreadsheet, pending_file, budgeting_months, data_loading_info);
 }
Example #17
0
        public Main(ILobby lobby, IEventRunner eventRunner, IDiscordHandler discord, ISpreadsheet sheet, ScriptInput input) : base(eventRunner)
        {
            _lobby       = lobby;
            _discord     = discord;
            _eventRunner = eventRunner;
            _sheet       = sheet;
            _input       = input;

            _sorter = new LobbySort(eventRunner, lobby, input.CaptainA, input.CaptainB);
        }
Example #18
0
 private void Generate_ad_hoc_data <TThirdPartyType, TOwnedType>(
     ISpreadsheet spreadsheet,
     ICSVFile <TOwnedType> pending_file,
     BudgetingMonths budgeting_months,
     DataLoadingInformation <TThirdPartyType, TOwnedType> data_loading_info)
     where TThirdPartyType : ICSVRecord, new()
     where TOwnedType : ICSVRecord, new()
 {
     _input_output.Output_line("Generating ad hoc data...");
     data_loading_info.Loader.Generate_ad_hoc_data(_input_output, spreadsheet, pending_file, budgeting_months, data_loading_info);
 }
Example #19
0
        public IList <string> FullProcess(ISpreadsheet spreadsheet, IMapGraphic mapGraphic, IEnumerable <IMapGraphicConverter> converters, string outputFolderPath, RenderPreferences preferences, Products products)
        {
            var countyIds = spreadsheet
                            .Where(x => x.HasTruthyValue(products))
                            .Select(x => x[ID_COLUMN]);

            try
            {
                mapGraphic.FillReferenceBoxes(preferences.DefaultColor);
                mapGraphic.FillCounties(preferences.DefaultColor);
                mapGraphic.StrokeReferenceBoxes(preferences.LineColor);
                mapGraphic.StrokeOuterBorder(preferences.LineColor);
                mapGraphic.Fill(preferences.PresenceColor, countyIds);
                mapGraphic.Fill(preferences.PresenceColor, ELEMENTID_REF_PRESENCE_BOX);
                if (!preferences.ShowCountyNames)
                {
                    mapGraphic.HideCountyNames();
                }
                if (preferences.ShowCountyLines)
                {
                    mapGraphic.StrokeCounties(preferences.LineColor);
                }
                else
                {
                    mapGraphic.ReduceStrokeCounties();
                    mapGraphic.StrokeCounties(preferences.DefaultColor);
                    mapGraphic.Stroke(preferences.PresenceColor, countyIds);
                }
                mapGraphic.SetText(ELEMENTID_REF_PRESENCE_TEXT, products.GetWithPresenceText());
                mapGraphic.SetText(ELEMENTID_REF_NO_PRESENCE_TEXT, products.GetWithoutPresenceText());
            }
            catch
            {
                throw new ApplicationException("Error applying color to elements, verify elementIds and SVG file.");
            }

            var resultFileNames = new List <string>();
            var baseFilename    = Path.Combine(outputFolderPath, string.Format("COPsync-presence-map-{0:yyyyMMddHHmmss}", DateTime.Now));

            foreach (var converter in converters)
            {
                try
                {
                    var convertedFilename = Path.ChangeExtension(baseFilename, converter.DefaultExtension);
                    converter.Convert(mapGraphic, convertedFilename);
                    resultFileNames.Add(convertedFilename);
                }
                catch (Exception e)
                {
                    throw new ApplicationException(string.Format("Error converting the file using {0}:\n{1}", converter.GetType(), e.Message));
                }
            }
            return(resultFileNames);
        }
 public void Do_actions_which_require_third_party_data_access(
     IDataFile <ActualBankRecord> third_party_file,
     IDataFile <BankRecord> owned_file,
     ISpreadsheet spreadsheet,
     IInputOutput input_output)
 {
     Update_bank_balance(
         (third_party_file as ActualBankOutFile),
         spreadsheet,
         input_output);
 }
        private void Update_weekly_item(
            IInputOutput input_output,
            ISpreadsheet spreadsheet,
            BudgetingMonths budgeting_months,
            string item,
            string budget_code,
            string expected_out_code)
        {
            var week_getter = new WeekGetter(input_output, new Clock());
            var weeks       = week_getter.Decide_num_weeks(item, budgeting_months);

            spreadsheet.Update_expected_out(weeks.NumWeeks, budget_code, expected_out_code);
        }
        private DateTime Get_next_unplanned_month(ISpreadsheet spreadsheet)
        {
            DateTime default_month        = DateTime.Today;
            DateTime next_unplanned_month = default_month;
            bool     bad_input            = false;

            try
            {
                next_unplanned_month = spreadsheet.Get_next_unplanned_month();
            }
            catch (Exception)
            {
                string new_month = _input_output.Get_input(ReconConsts.CantFindMortgageRow);
                try
                {
                    if (!String.IsNullOrEmpty(new_month) && Char.IsDigit(new_month[0]))
                    {
                        int actual_month = Convert.ToInt32(new_month);
                        if (actual_month < 1 || actual_month > 12)
                        {
                            bad_input = true;
                        }
                        else
                        {
                            var year = default_month.Year;
                            if (actual_month < default_month.Month)
                            {
                                year++;
                            }
                            next_unplanned_month = new DateTime(year, actual_month, 1);
                        }
                    }
                    else
                    {
                        bad_input = true;
                    }
                }
                catch (Exception)
                {
                    bad_input = true;
                }
            }

            if (bad_input)
            {
                _input_output.Output_line(ReconConsts.DefaultUnplannedMonth);
                next_unplanned_month = default_month;
            }

            return(next_unplanned_month);
        }
Example #23
0
        public GenerateFilesTests()
        {
            this.configMock = new Mock <IConfig>();
            this.config     = this.configMock.Object;

            this.spreadsheetMock = new Mock <ISpreadsheet>();
            this.spreadsheet     = this.spreadsheetMock.Object;

            this.fileSystemMock = new Mock <IFileSystem>();
            this.fileSystem     = this.fileSystemMock.Object;

            this.outputWriterMock = new Mock <IOutputWriter>();
            this.outputWriter     = this.outputWriterMock.Object;
        }
 private void Merge_budget_data <TThirdPartyType, TOwnedType>(
     ISpreadsheet spreadsheet,
     ICSVFile <TOwnedType> pending_file,
     BudgetingMonths budgeting_months,
     DataLoadingInformation <TThirdPartyType, TOwnedType> data_loading_info)
     where TThirdPartyType : ICSVRecord, new()
     where TOwnedType : ICSVRecord, new()
 {
     _input_output.Output_line("Merging budget data with pending data...");
     spreadsheet.Add_budgeted_monthly_data_to_pending_file(budgeting_months, pending_file, data_loading_info.Monthly_budget_data);
     if (null != data_loading_info.Annual_budget_data)
     {
         spreadsheet.Add_budgeted_annual_data_to_pending_file(budgeting_months, pending_file, data_loading_info.Annual_budget_data);
     }
 }
        private void Merge_unreconciled_data <TThirdPartyType, TOwnedType>(
            ISpreadsheet spreadsheet,
            ICSVFile <TOwnedType> pending_file,
            DataLoadingInformation <TThirdPartyType, TOwnedType> data_loading_info)
            where TThirdPartyType : ICSVRecord, new()
            where TOwnedType : ICSVRecord, new()
        {
            _input_output.Output_line("Merging unreconciled rows from spreadsheet with pending and budget data...");
            spreadsheet.Add_unreconciled_rows_to_csv_file <TOwnedType>(data_loading_info.Sheet_name, pending_file);

            _input_output.Output_line("Copying merged data (from pending, unreconciled, and budgeting) into main 'owned' csv file...");
            pending_file.Update_source_lines_for_output(data_loading_info.Loading_separator);
            pending_file.Write_to_file_as_source_lines(data_loading_info.File_paths.Owned_file_name);

            _input_output.Output_line("...");
        }
        private void Update_monthly_item(
            IInputOutput input_output,
            ISpreadsheet spreadsheet,
            BudgetingMonths budgeting_months,
            string item,
            string budget_code,
            string expected_out_code)
        {
            var input      = input_output.Get_input(Num_months_question(budgeting_months, item));
            var num_months = 0;

            if (int.TryParse(input, out num_months))
            {
                spreadsheet.Update_expected_out(num_months, budget_code, expected_out_code);
            }
        }
        public BudgetingMonths Recursively_ask_for_budgeting_months(ISpreadsheet spreadsheet)
        {
            DateTime next_unplanned_month           = Get_next_unplanned_month(spreadsheet);
            int      last_month_for_budget_planning = Get_last_month_for_budget_planning(spreadsheet, next_unplanned_month.Month);
            var      budgeting_months = new BudgetingMonths
            {
                Next_unplanned_month           = next_unplanned_month.Month,
                Last_month_for_budget_planning = last_month_for_budget_planning,
                Start_year = next_unplanned_month.Year
            };

            if (last_month_for_budget_planning != 0)
            {
                budgeting_months.Last_month_for_budget_planning = Confirm_budgeting_month_choices_with_user(budgeting_months, spreadsheet);
            }
            return(budgeting_months);
        }
        public void Merge_bespoke_data_with_pending_file(
            IInputOutput input_output,
            ISpreadsheet spreadsheet,
            ICSVFile <BankRecord> pending_file,
            BudgetingMonths budgeting_months,
            DataLoadingInformation <ActualBankRecord, BankRecord> data_loading_info)
        {
            input_output.Output_line(ReconConsts.Loading_expenses);
            _expected_income_csv_file.Load(false);

            spreadsheet.Add_unreconciled_rows_to_csv_file <ExpectedIncomeRecord>(MainSheetNames.Expected_in, _expected_income_file.File);
            _expected_income_csv_file.Populate_source_records_from_records();
            _expected_income_file.Filter_for_employer_expenses_and_bank_transactions_only();

            _expected_income_file.Copy_to_pending_file(pending_file);
            _expected_income_csv_file.Populate_records_from_original_file_load();
        }
Example #29
0
        public static void StrategyCommand()
        {
            ISpreadsheet spreadsheet = null;
            Owner        Mike        = new Owner();
            bool         repeat      = true;

            while (repeat)
            {
                Console.WriteLine("This is the strategy pattern. It allows algorithms to be selected at runtime.");
                Console.WriteLine("Enter in a document to work on: 1)Balance Sheet 2) Tax form 3)HR Form. ");
                string input = Console.ReadLine();

                switch (input)
                {
                case "1":
                    spreadsheet = new BalanceSheetForm();
                    break;

                case "2":
                    spreadsheet = new TaxForm();
                    break;

                case "3":
                    spreadsheet = new HRForm();
                    break;

                default:
                    spreadsheet = new Null();
                    break;
                }
                Mike.SetSpreadsheet(spreadsheet);
                Mike.WorkOn();

                Console.Write("Go again? Y/N: ");
                string go = Console.ReadLine();
                if (go == "Y" || go == "y")
                {
                    repeat = true;
                }
                else
                {
                    repeat = false;
                }
            }
        }
        public void Generate_ad_hoc_data(
            IInputOutput input_output,
            ISpreadsheet spreadsheet,
            ICSVFile <BankRecord> pending_file,
            BudgetingMonths budgeting_months,
            DataLoadingInformation <ActualBankRecord, BankRecord> data_loading_info)
        {
            if (budgeting_months.Do_expected_out_budgeting)
            {
                Update_owed_CHB(input_output, spreadsheet, budgeting_months);

                Update_weekly_item(input_output, spreadsheet, budgeting_months, "weekly spends", Codes.Code004, Codes.Code074);
                Update_weekly_item(input_output, spreadsheet, budgeting_months, "grocery shopping", Codes.Code005, Codes.Code075);

                Update_monthly_item(input_output, spreadsheet, budgeting_months, "yoga", Codes.Code078, Codes.Code078);
                Update_monthly_item(input_output, spreadsheet, budgeting_months, "fuel", Codes.Code006, Codes.Code006);
                Update_monthly_item(input_output, spreadsheet, budgeting_months, "vet", Codes.Code007, Codes.Code007);
                Update_monthly_item(input_output, spreadsheet, budgeting_months, "domain hosting", Codes.Code011, Codes.Code011);
            }
        }