Exemple #1
0
        static void TryABN(ProcessedInvoice inv)
        {
            if (String.IsNullOrEmpty(inv.ABN))
            {
                PromptTextDialog promptTextDialog = new PromptTextDialog();
                promptTextDialog.SetCaption("Can't find ABN, please specify $$");
                promptTextDialog.ShowDialog();
                inv.ABN = promptTextDialog.Text;
            }


            if (!ABNHelper.DoesABNExist(inv.ABN))
            {
                string text     = $"ABN Not found: {inv.ABN}, would you like to create a new folder for {inv.ABN}?";
                var    response = MessageBox.Show(text, "ABN not found", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.Yes);

                if (response == MessageBoxResult.Yes)
                {
                    NewABN newABN = new NewABN();
                    newABN.InvoiceFile = inv.FilePath;
                    newABN.DataContext = new ABNData()
                    {
                        ABN = inv.ABN, Email = inv.Email, Phone = inv.Phone, CompanyName = inv.CompanyName
                    };
                    newABN.Show();
                }
            }

            string path  = ABNHelper.GetDirectory(inv.ABN);
            string iPath = path + @"\Invoices\";


            ABNHelper.CreateDirectoryFromPath(iPath);

            string tPath = iPath + System.IO.Path.GetFileName(inv.FilePath);

            if (!File.Exists(tPath))
            {
                File.Copy(inv.FilePath, tPath, false);
            }

            InvoiceHelper.OnInvoiceAdded();
        }
Exemple #2
0
        private static ProcessedInvoice ProcessInvoice(string result, string path)
        {
            Regex rx = new Regex(@"ABN[:]([ \d]*?)$", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace | RegexOptions.Multiline);
            //  Regex rx = new Regex(@"(\d{3}\s*\d{3}\s*\d{3}\s*\d{2})|(\d{2}\s *\d{3}\s *\d{3}\s*\d{3})", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
            Regex email = new Regex(@"[\w\d\-]*[@][\w\d\-]*(.com.au|.com)", RegexOptions.Compiled | RegexOptions.IgnoreCase);
            Regex phone = new Regex(@"(?:\+?61|0)[2-478 ](?:[ -]?[0-9]){8}", RegexOptions.Compiled | RegexOptions.IgnoreCase);



            Match emailMatch = email.Match(result);
            Group abnMatch   = rx.Match(result).Groups[1];
            Match phoneMatch = phone.Match(result);

            string abn = abnMatch.Value;


            string input = new WebClient().DownloadString(@"https://abr.business.gov.au/ABN/View?id=" + abn.Replace(" ", ""));

            // string text =


            Regex           abnRegistered = new Regex(@"<th>Goods &amp;.*\s+<td>\s*(.*)", RegexOptions.Compiled | RegexOptions.IgnoreCase);
            MatchCollection abnCollection = abnRegistered.Matches(input);
            string          gstRegistered = "";

            foreach (Match match in abnCollection)
            {
                GroupCollection groups = match.Groups;
                gstRegistered = groups[1].Value.Replace("&nbsp;", " ");
            }

            //string potentialCompanyName = FindLargestText(result);

            ProcessedInvoice processedInvoice = new ProcessedInvoice()
            {
                ABN = abn, GstRegistered = gstRegistered, Email = emailMatch.Value, Phone = phoneMatch.Value, FilePath = path
            };

            Console.WriteLine(abn);
            return(processedInvoice);
        }