PageRenderTime 40ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/CmsWeb/Areas/Finance/Models/BatchImport/StewardshipTechnology.cs

https://github.com/vs06/bvcms
C# | 76 lines | 65 code | 5 blank | 6 comment | 7 complexity | 2f98e08f5e80b70638f1787c53570f5d MD5 | raw file
  1. /* Author: David Carroll
  2. * Copyright (c) 2008, 2009 Bellevue Baptist Church
  3. * Licensed under the GNU General Public License (GPL v2)
  4. * you may not use this code except in compliance with the License.
  5. * You may obtain a copy of the License at http://bvcms.codeplex.com/license
  6. */
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using UtilityExtensions;
  11. using CmsData;
  12. using CmsData.Codes;
  13. using System.Diagnostics;
  14. using System.Text.RegularExpressions;
  15. using System.IO;
  16. using LumenWorks.Framework.IO.Csv;
  17. namespace CmsWeb.Models
  18. {
  19. public partial class BatchImportContributions
  20. {
  21. public static int? BatchProcessStewardshipTechnology(CsvReader csv, DateTime date, int? fundid)
  22. {
  23. var fundList = (from f in DbUtil.Db.ContributionFunds
  24. select new
  25. {
  26. f.FundId,
  27. f.FundName
  28. }).ToList();
  29. var cols = csv.GetFieldHeaders();
  30. BundleHeader bh = null;
  31. var firstfund = FirstFundId();
  32. var list = new List<depositRecord>();
  33. csv.ReadNextRecord();
  34. while (csv.ReadNextRecord())
  35. list.Add(new depositRecord()
  36. {
  37. date = csv[1].ToDate(),
  38. account = csv[6],
  39. amount = csv[2],
  40. checkno = csv[0],
  41. type = csv[3],
  42. });
  43. DateTime? prevbatch = null;
  44. foreach(var r in list.OrderBy(rr => rr.date))
  45. {
  46. if (r.date != prevbatch)
  47. {
  48. if (bh != null)
  49. FinishBundle(bh);
  50. bh = GetBundleHeader(r.date ?? date, DateTime.Now, BundleTypeCode.Online);
  51. bh.DepositDate = r.date;
  52. prevbatch = r.date;
  53. }
  54. BundleDetail bd;
  55. var fid = (from f in fundList
  56. where f.FundName == r.type
  57. select f.FundId).SingleOrDefault();
  58. if(fid > 0)
  59. bd = AddContributionDetail(r.date ?? date, fid, r.amount, r.checkno, "", r.account);
  60. else
  61. {
  62. bd = AddContributionDetail(r.date ?? date, fundid ?? firstfund, r.amount, r.checkno, "", r.account);
  63. bd.Contribution.ContributionDesc = "Used default fund (fund requested: {0})".Fmt(r.type);
  64. }
  65. bh.BundleDetails.Add(bd);
  66. }
  67. FinishBundle(bh);
  68. return bh.BundleHeaderId;
  69. }
  70. }
  71. }