Exemplo n.º 1
0
        static void Main(string[] args)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.InitialDirectory = "P:\\RALFG\\Common Files\\Commissions & Insurance\\Commission Statements\\2017\\NACOLAH-Life\\";
            ofd.Filter           = "PDF files (*.pdf)|*.pdf";
            ofd.FilterIndex      = 1;
            ofd.RestoreDirectory = true;
            DialogResult result  = ofd.ShowDialog();
            string       pdfPath = "";

            if (result == DialogResult.OK)
            {
                pdfPath  = ofd.FileName;
                fileName = System.IO.Path.GetFileName(pdfPath);
            }
            else
            {
                Environment.Exit(0);
            }

            pages   = new List <string>();
            entries = new List <Entry>();

            try {
                //StringBuilder text = new StringBuilder();
                PdfReader pdfReader = new PdfReader(pdfPath);
                for (int page = 1; page <= pdfReader.NumberOfPages; page++)
                {
                    ITextExtractionStrategy strategy = new SimpleTextExtractionStrategy();
                    string currentText = PdfTextExtractor.GetTextFromPage(pdfReader, page, strategy);
                    //text.Append(System.Environment.NewLine);
                    //text.Append("\n Page Number:" + page);
                    //text.Append(System.Environment.NewLine);
                    currentText = Encoding.UTF8.GetString(ASCIIEncoding.Convert(Encoding.Default, Encoding.UTF8,
                                                                                Encoding.Default.GetBytes(currentText)));
                    //text.Append(currentText);
                    //pdfReader.Close();
                    pages.Add(currentText);
                }
                int i = 0;

                while (i < pages.Count)
                {
                    lineNum = 0;
                    Console.WriteLine("\nPage " + (++pageNum));

                    if (pages[i].Length == 0)
                    {
                        pages.RemoveAt(i);
                        Console.WriteLine("Found Empty Page");
                    }
                    else if (pages[i].Contains("A G E N T S U M M A R Y P A G E"))
                    {
                        pages.RemoveAt(i);
                        Console.WriteLine("Found Summary Page");
                    }
                    else if (pages[i].Contains("A N N U A L I Z E D"))
                    {
                        string[] aLines = pages[i].Split('\n');
                        foreach (string aLine in aLines)
                        {
                            Console.Write("Line " + (++lineNum) + ", ");
                            AnnualLine tempAL = getAnnualLine(aLine.Trim());

                            if (tempAL != null)
                            {
                                //System.out.println(tempAL);
                                bool found = false;
                                for (int j = entries.Count - 1; j >= 0; j--)
                                {
                                    if (entries[j].getName() == tempAL.name && entries[j].getPolicyNum() == tempAL.policyNum)
                                    {
                                        entries[j].addAnnualLine(tempAL);
                                        found = true;
                                        break;
                                    }
                                }

                                if (!found)
                                {
                                    Console.WriteLine("WARNING: COULD NOT FIND MATCH, DUMPING AL and matching on last policy match\n\n" + tempAL);
                                    for (int j = entries.Count - 1; j >= 0; j--)
                                    {
                                        if (entries[j].getPolicyNum() == tempAL.policyNum)
                                        {
                                            entries[j].addAnnualLine(tempAL);
                                            found = true;
                                            break;
                                        }
                                    }
                                }
                                if (!found)
                                {
                                    Console.WriteLine("ERROR: Cannot find any match by policy for annualized line.\nManual intervention requied");
                                }
                            }
                        }
                        i++;
                    }
                    else if (pages[i].Contains("C O M M I S S I O N S T A T E M E N T"))
                    {
                        string[] cLines = pages[i].Split('\n');
                        foreach (string cLine in cLines)
                        {
                            Console.Write("Line " + (++lineNum) + ", ");
                            CommLine tempCL = getCommLine(cLine.Trim());
                            if (tempCL != null)
                            {
                                bool found = false;
                                foreach (Entry e in entries)
                                {
                                    if (e.getName() == tempCL.name && e.getPolicyNum() == tempCL.policyNum && e.getRate() == tempCL.cRate * 100)
                                    {
                                        e.addCommLine(tempCL);
                                        found = true;
                                        break;
                                    }
                                }

                                if (!found)
                                {
                                    Entry tempE = new Entry(tempCL.name, tempCL.policyNum, tempCL.cRate);
                                    tempE.addCommLine(tempCL);
                                    entries.Add(tempE);
                                }
                            }
                        }
                        i++;
                    }
                    else
                    {
                        Console.WriteLine("WARNING: page not found: Dumping:\n\n");
                        Console.WriteLine(pages[i]);
                        i++;
                    } //end if
                }     //end while

                Console.WriteLine("Finished Scanning for empty pages");
                List <Entry> annuals = new List <Entry>();
                foreach (Entry e in entries)
                {
                    e.printOut();
                    if (e.getAnnualLines().Count > 0)
                    {
                        annuals.Add(e);
                    }
                }

                writeToExcel();
            }
            catch (Exception e) {
                Console.WriteLine(e);
            }
        }
Exemplo n.º 2
0
 public void addAnnualLine(AnnualLine al)
 {
     annualLines.Add(al);
 }
Exemplo n.º 3
0
        public static AnnualLine getAnnualLine(String s)
        {
            AnnualLine al = null;

            String[] tokens     = null;
            String   name       = "";
            String   policyNum  = null;
            String   accDate    = "";
            String   issueDate  = "";
            int      mopd       = 0;
            double   beginBal   = 0.0;
            double   currAdv    = 0.0;
            double   commApp    = 0.0;
            double   chargeBack = 0.0;
            double   endBal     = 0.0;
            bool     stop       = false;
            int      pIndex     = -1;

            tokens = s.Split(new Char[0], StringSplitOptions.RemoveEmptyEntries);
            if (stop)
            {
                Console.WriteLine("should be bere");
            }
            for (int i = 0; i < tokens.Length; i++)
            {
                if (tokens[i].StartsWith("LB") || tokens[i].StartsWith("L0"))
                {
                    policyNum = tokens[i];
                    stop      = true;
                    pIndex    = i;
                    break;
                }
            }

            if (policyNum == null || policyNum == "")
            {
                //System.err.println("Couldn't find policy number on comm line");
                return(null);
            }

            bool twoNames  = false;
            bool threeName = false;

            name = "*" + tokens[0];
            if (!tokens[1].StartsWith("LB") && !tokens[1].StartsWith("L0"))
            {
                twoNames = true;
                name     = name += (" " + tokens[1]);
            }

            if (twoNames && !tokens[2].StartsWith("LB") && !tokens[2].StartsWith("L0"))
            {
                threeName = true;
                name      = name += (" " + tokens[2]);
            }
            name = name.Trim().Replace(",", "");

            if (name.Length < 3)
            {
                Console.WriteLine("Bad Name");
            }

            bool foundAcct = false;

            String regexStr = "^[0-3]?[0-9]/[0-3]?[0-9]/(?:[0-9]{2})?[0-9]{2}$";
            Regex  regex    = new Regex(regexStr);
            int    index    = -1;
            int    lastDate = -1;

            for (int i = 0; i < tokens.Length; i++)
            {
                if (regex.Match(tokens[i]).Success)
                {
                    if (foundAcct == false)
                    {
                        foundAcct = true;
                        accDate   = tokens[i];
                        index     = i;
                    }
                    else
                    {
                        issueDate = tokens[i];
                        index     = i;
                        break;
                    }
                }
            }
            lastDate = index;
            index++;
            mopd = Convert.ToInt32(tokens[index]);
            index++;
            beginBal = Convert.ToDouble(tokens[index].Replace("$", "").Replace("-", ""));
            index++;
            currAdv = Convert.ToDouble(tokens[index].Replace("$", "").Replace("-", ""));
            index++;
            commApp = Convert.ToDouble(tokens[index].Replace("$", "").Replace("-", ""));
            index++;
            chargeBack = Convert.ToDouble(tokens[index].Replace("$", "").Replace("-", ""));
            index++;
            endBal = Convert.ToDouble(tokens[index].Replace("$", "").Replace("-", ""));

            al = new AnnualLine(name, policyNum, accDate, issueDate, mopd, beginBal, currAdv, commApp, chargeBack, endBal);
            return(al);
        }