Ejemplo n.º 1
0
        /// <summary>
        /// Construct a file footer for use in the output ach_file.
        /// Will account for any changes made in memory while the file was opened.
        /// </summary>
        /// <param name="file_lines">all of the lines associated with the file.</param>
        /// <returns>File footer as a string.</returns>
        public string construct_file_footer(string[] file_lines)
        {
            int batch_count         = 0;
            int block_count         = 0;
            int entry_addenda_count = 0;
            int entry_hash          = 0;
            int total_debit_dollar  = 0;
            int total_credit_dollar = 0;

#if UPDATE_20190807 // going forward remove this item.
#else
            string reserved = "";
#endif

            // the plus 1 is for this record.
            int m = file_lines.Length + 1;
            while (m % 10 != 0)
            {
                m++;
            }
            // now we need to divide by 10 to get the block count.
            // I don't know how I deleted the div 10...
            block_count = m / 10;


            int try_parse_out = 0;
            // okay - we'll need to accumulate the entries in batch_lines.
            for (int i = 0; i < file_lines.Length; i++)
            {
                switch (file_lines[i][0])
                {
                case '5':
                    batch_count += 1;
                    break;

                case '6':
                    var t_code = FORMS.ENTRY_FORM.field_map["Trans. Code"];
                    var a_code = FORMS.ENTRY_FORM.field_map["Amount     "];
                    var h_code = FORMS.ENTRY_FORM.field_map["Routing Num"];
                    var amount = file_lines[i].Substring(a_code.Item1, a_code.Item2);
                    entry_addenda_count++;
                    if (new List <string> {
                        "27", "37"
                    }.Contains(file_lines[i].Substring(t_code.Item1, t_code.Item2)))                                       // debit
                    {
                        Int32.TryParse(amount, out try_parse_out);
                        total_debit_dollar += try_parse_out;
                    }
                    else if (new List <string> {
                        "22", "32"
                    }.Contains(file_lines[i].Substring(t_code.Item1, t_code.Item2)))                                            // credit
                    {
                        Int32.TryParse(amount, out try_parse_out);
                        total_credit_dollar += try_parse_out;
                    }
                    else     //if (new List<string> { }.Contains(batch_lines[i].Substring(t_code.Item1, t_code.Item2))) // prenote
                    {
                        // prenotes don't require action.
                    }
                    Int32.TryParse(file_lines[i].Substring(h_code.Item1, h_code.Item2), out try_parse_out);
                    entry_hash += try_parse_out;
                    // reset try_parse_out.
                    break;

                case '7':
                    entry_addenda_count += 1;
                    break;

                case '8':
                    break;

                default:     // don't don anything.
                    break;
                }
                try_parse_out = 0;
            }

            string file_out = "";
            file_out += "9";
            file_out += GLOBALS._trun(GLOBALS._pad(batch_count.ToString(), GLOBALS.file_fields["batch count "].Item2, '0'), GLOBALS.file_fields["batch count "].Item2);
            file_out += GLOBALS._trun(GLOBALS._pad(block_count.ToString(), GLOBALS.file_fields["block count "].Item2, '0'), GLOBALS.file_fields["block count "].Item2);
            file_out += GLOBALS._trun(GLOBALS._pad(entry_addenda_count.ToString(), GLOBALS.file_fields["entadd count"].Item2, '0'), GLOBALS.file_fields["entadd count"].Item2);
            file_out += GLOBALS._trun(GLOBALS._pad(entry_hash.ToString(), GLOBALS.file_fields["entry hash  "].Item2, '0'), GLOBALS.file_fields["entry hash  "].Item2);
            file_out += GLOBALS._trun(GLOBALS._pad(total_debit_dollar.ToString(), GLOBALS.file_fields["debit  cont."].Item2, '0'), GLOBALS.file_fields["debit  cont."].Item2);
            file_out += GLOBALS._trun(GLOBALS._pad(total_credit_dollar.ToString(), GLOBALS.file_fields["credit cont."].Item2, '0'), GLOBALS.file_fields["credit cont."].Item2);
            file_out += GLOBALS._trun(GLOBALS._pad("", GLOBALS.file_fields["reserved    "].Item2), GLOBALS.file_fields["reserved    "].Item2);

#if DEBUG
            //
            Console.WriteLine(file_out);
#endif

            return(file_out); // placeholder.
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Construct a batch footer based on the contents of a series of batch_lines.
        /// </summary>
        /// <param name="batch_lines">Batch contents</param>
        /// <returns>batch footer matching the batch lines;</returns>
        public string construct_batch_footer(string[] batch_lines)
        {
            string class_code      = "";
            string current_batch   = "";
            int    hash            = 0;
            int    entry_add_count = 0;
            int    debit_dollar    = 0;
            int    credit_dollar   = 0;
            string company_id      = ""; // we'll need to extract from the original.
            string MAC             = ""; // extract from the original;
            string originatingdfi  = ""; // extract from the original.
            string batch_number    = ""; // extract from original.

            int try_parse_out = 0;

            // okay - we'll need to accumulate the entries in batch_lines.
            for (int i = 0; i < batch_lines.Length; i++)
            {
                switch (batch_lines[i][0])
                {
                case '5':
                    break;

                case '6':
                    var t_code = FORMS.ENTRY_FORM.field_map["Trans. Code"];
                    var a_code = FORMS.ENTRY_FORM.field_map["Amount     "];
                    var h_code = FORMS.ENTRY_FORM.field_map["Routing Num"];
                    var amount = batch_lines[i].Substring(a_code.Item1, a_code.Item2);
                    entry_add_count++;
                    if (new List <string> {
                        "27", "37"
                    }.Contains(batch_lines[i].Substring(t_code.Item1, t_code.Item2)))                                     // debit
                    {
                        Int32.TryParse(amount, out try_parse_out);
                        debit_dollar += try_parse_out;
                    }
                    else if (new List <string> {
                        "22", "32"
                    }.Contains(batch_lines[i].Substring(t_code.Item1, t_code.Item2)))                                           // credit
                    {
                        Int32.TryParse(amount, out try_parse_out);
                        credit_dollar += try_parse_out;
                    }
                    else     //if (new List<string> { }.Contains(batch_lines[i].Substring(t_code.Item1, t_code.Item2))) // prenote
                    {
                        // prenotes don't require action.
                    }
                    Int32.TryParse(batch_lines[i].Substring(h_code.Item1, h_code.Item2), out try_parse_out);
                    hash += try_parse_out;
                    // reset try_parse_out.
                    break;

                case '7':
                    entry_add_count += 1;
                    break;

                case '8':
                    break;

                default:     // don't don anything.
                    break;
                }
                try_parse_out = 0;
            }

            // once again - extract and pad.
            class_code = GLOBALS._trun(GLOBALS._pad(batch_footer.Substring(GLOBALS.batch_fields["service code"].Item1, GLOBALS.batch_fields["service code"].Item2), GLOBALS.batch_fields["service code"].Item2), GLOBALS.batch_fields["service code"].Item2);

            // extract and pad.
            current_batch = GLOBALS._trun(GLOBALS._pad(batch_footer.Substring(GLOBALS.batch_fields["batch number"].Item1, GLOBALS.batch_fields["batch number"].Item2), GLOBALS.batch_fields["batch number"].Item2), GLOBALS.batch_fields["batch number"].Item2);

            // extract and pad (again)
            company_id = GLOBALS._trun(GLOBALS._pad(batch_footer.Substring(GLOBALS.batch_fields["company iden"].Item1, GLOBALS.batch_fields["company iden"].Item2), GLOBALS.batch_fields["company iden"].Item2), GLOBALS.batch_fields["company iden"].Item2);

            //
            MAC = GLOBALS._trun(GLOBALS._pad(batch_footer.Substring(GLOBALS.batch_fields["message auth"].Item1, GLOBALS.batch_fields["message auth"].Item2), GLOBALS.batch_fields["message auth"].Item2), GLOBALS.batch_fields["message auth"].Item2);

            //
            originatingdfi = GLOBALS._trun(GLOBALS._pad(batch_footer.Substring(GLOBALS.batch_fields["origin route"].Item1, GLOBALS.batch_fields["origin route"].Item2), GLOBALS.batch_fields["origin route"].Item2), GLOBALS.batch_fields["origin route"].Item2);

            // redundant?
            batch_number = current_batch;

            string batch_out = "";

            batch_out += GLOBALS.trun_(GLOBALS.pad_("8", 1), 1);
            batch_out += class_code;
            batch_out += GLOBALS._trun(GLOBALS._pad(entry_add_count.ToString(), GLOBALS.batch_fields["entadd count"].Item2, '0'), GLOBALS.batch_fields["entadd count"].Item2);
            batch_out += GLOBALS._trun(GLOBALS._pad(hash.ToString(), GLOBALS.batch_fields["entry hash  "].Item2, '0'), GLOBALS.batch_fields["entry hash  "].Item2);
            batch_out += GLOBALS._trun(GLOBALS._pad(debit_dollar.ToString(), GLOBALS.batch_fields["debit contr."].Item2, '0'), GLOBALS.batch_fields["debit contr."].Item2);
            batch_out += GLOBALS._trun(GLOBALS._pad(credit_dollar.ToString(), GLOBALS.batch_fields["credit cont."].Item2, '0'), GLOBALS.batch_fields["credit cont."].Item2);
            batch_out += company_id;
            batch_out += MAC;
            batch_out += GLOBALS.pad_("", GLOBALS.batch_fields["reserved    "].Item2); // this should handle the output.
            batch_out += originatingdfi;
            batch_out += batch_number;
            //batch_out += GLOBALS.trun_(GLOBALS.pad_(""))
#if DEBUG
            Console.WriteLine(batch_out);
#endif
            return(batch_out);
        }