BillTimberlinePoster.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  1. using Comal.Classes;
  2. using CsvHelper;
  3. using CsvHelper.Configuration;
  4. using CsvHelper.Configuration.Attributes;
  5. using FastReport.Utils;
  6. using InABox.Clients;
  7. using InABox.Core;
  8. using InABox.Core.Postable;
  9. using InABox.Poster.Timberline;
  10. using InABox.Scripting;
  11. using Microsoft.Win32;
  12. using NPOI.SS.Formula.Functions;
  13. using PRSDimensionUtils;
  14. using System.Collections.Generic;
  15. using System.Globalization;
  16. using System.IO;
  17. using System.Linq;
  18. using System.Text;
  19. using System.Threading.Tasks;
  20. using System.Windows;
  21. using static System.Windows.Forms.VisualStyles.VisualStyleElement;
  22. using Columns = InABox.Core.Columns;
  23. namespace PRS.Shared;
  24. public class BillTimberlineHeader
  25. {
  26. [Ignore]
  27. public List<BillTimberlineDistribution> Distributions { get; set; } = new();
  28. [Index(0)]
  29. public string RecordID { get; set; } = "APIF";
  30. [Index(1)]
  31. [TypeConverter(typeof(TimberlinePosterStringConverter), 10)]
  32. public string Vendor { get; set; } = "";
  33. [Ignore]
  34. private string _invoice = "";
  35. [Index(2)]
  36. [TypeConverter(typeof(TimberlinePosterStringConverter), 15)]
  37. public string Invoice
  38. {
  39. get => _invoice;
  40. set => _invoice = TimberlinePosterStringConverter.ConvertString(value, 15);
  41. }
  42. [Index(3)]
  43. [TypeConverter(typeof(TimberlinePosterStringConverter), 30)]
  44. public string Description { get; set; } = "";
  45. [Index(4)]
  46. public double Amount { get; set; }
  47. [Index(5)]
  48. public double Tax { get; set; }
  49. [Index(6)]
  50. public double DiscountOffered { get; set; }
  51. [Index(7)]
  52. public double MiscDeduction { get; set; }
  53. [Index(8)]
  54. [TypeConverter(typeof(TimberlinePosterDateConverter))]
  55. public DateTime InvoiceDate { get; set; }
  56. [Index(9)]
  57. [TypeConverter(typeof(TimberlinePosterDateConverter))]
  58. public DateTime DateReceived { get; set; }
  59. [Index(10)]
  60. [TypeConverter(typeof(TimberlinePosterDateConverter))]
  61. public DateTime DiscountDate { get; set; }
  62. [Index(11)]
  63. [TypeConverter(typeof(TimberlinePosterDateConverter))]
  64. public DateTime PaymentDate { get; set; }
  65. [Index(12)]
  66. [TypeConverter(typeof(TimberlinePosterDateConverter))]
  67. public DateTime AccountingDate { get; set; }
  68. [Index(13)]
  69. [TypeConverter(typeof(TimberlinePosterStringConverter), 10)]
  70. public string InvoiceCode1 { get; set; } = "";
  71. [Index(14)]
  72. [TypeConverter(typeof(TimberlinePosterStringConverter), 10)]
  73. public string InvoiceCode2 { get; set; } = "";
  74. [Index(15)]
  75. [TypeConverter(typeof(TimberlinePosterStringConverter), 30)]
  76. public string SmryPayeeName { get; set; } = "";
  77. [Index(16)]
  78. [TypeConverter(typeof(TimberlinePosterStringConverter), 33)]
  79. public string SmryPayeeAddress1 { get; set; } = "";
  80. [Index(17)]
  81. [TypeConverter(typeof(TimberlinePosterStringConverter), 33)]
  82. public string SmryPayeeAddress2 { get; set; } = "";
  83. [Index(18)]
  84. [TypeConverter(typeof(TimberlinePosterStringConverter), 15)]
  85. public string SmryPayeeCity { get; set; } = "";
  86. [Index(19)]
  87. [TypeConverter(typeof(TimberlinePosterStringConverter), 4)]
  88. public string SmryPayeeState { get; set; } = "";
  89. [Index(20)]
  90. [TypeConverter(typeof(TimberlinePosterStringConverter), 10)]
  91. public string SmryPayeeZip { get; set; } = "";
  92. }
  93. public class BillTimberlineDistribution
  94. {
  95. [Index(0)]
  96. public string RecordID { get; set; } = "APDF";
  97. [Index(1)]
  98. [TypeConverter(typeof(TimberlinePosterStringConverter), 12)]
  99. public string Commitment { get; set; } = "";
  100. [Index(2)]
  101. public int CommitmentLineItem { get; set; }
  102. [Index(3)]
  103. [TypeConverter(typeof(TimberlinePosterStringConverter), 7)]
  104. public string Equipment { get; set; } = "";
  105. [Index(4)]
  106. [TypeConverter(typeof(TimberlinePosterStringConverter), 6)]
  107. public string EQCostCode { get; set; } = "";
  108. [Index(5)]
  109. [TypeConverter(typeof(TimberlinePosterStringConverter), 6)]
  110. public string Job { get; set; } = "";
  111. [Index(6)]
  112. [TypeConverter(typeof(TimberlinePosterStringConverter), 10)]
  113. public string Extra { get; set; } = "";
  114. [Index(7)]
  115. [TypeConverter(typeof(TimberlinePosterStringConverter), 7)]
  116. public string CostCode { get; set; } = "";
  117. [Index(8)]
  118. [TypeConverter(typeof(TimberlinePosterStringConverter), 3)]
  119. public string Category { get; set; } = "";
  120. [Index(9)]
  121. [TypeConverter(typeof(TimberlinePosterStringConverter), 10)]
  122. public string BLStdItem { get; set; } = "";
  123. [Index(10)]
  124. [TypeConverter(typeof(TimberlinePosterStringConverter), 8)]
  125. public string Reserved { get; set; } = "";
  126. [Index(11)]
  127. [TypeConverter(typeof(TimberlinePosterStringConverter), int.MaxValue)] // int.MaxValue because it was chopping the accounts in PRS
  128. public string ExpenseAccount { get; set; } = "";
  129. [Index(12)]
  130. [TypeConverter(typeof(TimberlinePosterStringConverter), int.MaxValue)] // int.MaxValue because it was chopping the accounts in PRS
  131. public string APAccount { get; set; } = "";
  132. [Index(13)]
  133. public double TaxablePayments { get; set; }
  134. [Index(14)]
  135. [TypeConverter(typeof(TimberlinePosterStringConverter), 6)]
  136. public string TaxGroup { get; set; } = "";
  137. [Index(15)]
  138. public double Units { get; set; }
  139. [Index(16)]
  140. public double UnitCost { get; set; }
  141. [Index(17)]
  142. public double Amount { get; set; }
  143. [Index(18)]
  144. public double Tax { get; set; }
  145. [Index(19)]
  146. public double TaxLiability { get; set; }
  147. [Index(20)]
  148. public double DiscountOffered { get; set; }
  149. [Index(21)]
  150. public double Retainage { get; set; }
  151. [Index(22)]
  152. public double MiscDeduction { get; set; }
  153. [Index(23)]
  154. [BooleanTrueValues("t", "T", "1", "Y", "y")]
  155. [BooleanFalseValues("f", "F", "0", "N", "n")]
  156. public bool TaxablePaymentsExempt { get; set; }
  157. [Index(24)]
  158. [TypeConverter(typeof(TimberlinePosterStringConverter), 10)]
  159. public string DistCode { get; set; } = "";
  160. [Index(25)]
  161. [TypeConverter(typeof(TimberlinePosterStringConverter), 10)]
  162. public string Draw { get; set; } = "";
  163. [Index(26)]
  164. [TypeConverter(typeof(TimberlinePosterStringConverter), 10)]
  165. public string MiscEntry1 { get; set; } = "";
  166. [Index(27)]
  167. public double MiscEntryUnits1 { get; set; }
  168. [Index(28)]
  169. [TypeConverter(typeof(TimberlinePosterStringConverter), 10)]
  170. public string MiscEntry2 { get; set; } = "";
  171. [Index(29)]
  172. public double MiscEntryUnits2 { get; set; }
  173. [Index(30)]
  174. public double MeterOdometer { get; set; }
  175. [Index(31)]
  176. [TypeConverter(typeof(TimberlinePosterStringConverter), 30)]
  177. public string Description { get; set; } = "";
  178. [Index(32)]
  179. [TypeConverter(typeof(TimberlinePosterStringConverter), 10)]
  180. public string Authorization { get; set; } = "";
  181. [Index(33)]
  182. [TypeConverter(typeof(TimberlinePosterStringConverter), 30)]
  183. public string JointPayee { get; set; } = "";
  184. }
  185. public class BillTimberlineSettings : TimberlinePosterSettings<Bill>
  186. {
  187. protected override string DefaultScript()
  188. {
  189. return @"
  190. using PRS.Shared;
  191. using InABox.Core;
  192. using System.Collections.Generic;
  193. public class Module
  194. {
  195. public void BeforePost(IDataModel<Bill> model)
  196. {
  197. // Perform pre-processing
  198. }
  199. public bool ProcessHeader(IDataModel<Bill> model, Bill bill, BillTimberlineHeader header)
  200. {
  201. // Do extra processing for a header line; return false to fail this header
  202. return true;
  203. }
  204. public bool ProcessLine(IDataModel<Bill> model, BillLine bill, PurchaseOrderItem? item, PurchaseOrderItemAllocation? allocation, BillTimberlineDistribution distribution)
  205. {
  206. // Do extra processing for a distribution line; return false to fail this header. The BillLine will be split based on the allocations on the purchase order,
  207. // so that information is given here to with 'item' and 'allocation'; these are both 'null' if the bill isn't linked to a PurchaseOrderItem,
  208. // and 'allocation' is 'null' if the line corresponds to the primary allocation, based on the job number of the PurchaseOrderItem.
  209. return true;
  210. }
  211. public void AfterPost(IDataModel<Bill> model)
  212. {
  213. // Perform post-processing;
  214. }
  215. }";
  216. }
  217. }
  218. public class BillTimberlineResult : TimberlinePostResult<BillTimberlineHeader, Bill>
  219. {
  220. }
  221. public class BillTimberlinePoster : ITimberlinePoster<Bill, BillTimberlineSettings>
  222. {
  223. public ScriptDocument? Script { get; set; }
  224. public BillTimberlineSettings Settings { get; set; }
  225. public bool BeforePost(IDataModel<Bill> model)
  226. {
  227. foreach(var (name, table) in model.ModelTables)
  228. {
  229. table.IsDefault = false;
  230. }
  231. model.SetIsDefault<Bill>(true);
  232. model.SetIsDefault<BillLine>(true, "Bill_BillLine");
  233. model.SetColumns(Columns.None<Bill>().Add(x => x.ID)
  234. .Add(x => x.SupplierLink.Code)
  235. .Add(x => x.Description)
  236. .Add(x => x.Number)
  237. .Add(x => x.IncTax)
  238. .Add(x => x.Tax)
  239. .Add(x => x.BillDate)
  240. .Add(x => x.AccountingDate)
  241. .Add(x => x.PaymentDate)
  242. .Add(x => x.IsApproved));
  243. model.SetColumns(Columns.None<BillLine>().Add(x => x.ID)
  244. .Add(x => x.BillLink.ID)
  245. .Add(x => x.TaxCode.Code)
  246. .Add(x => x.CostCentre.Code)
  247. .Add(x => x.IncTax)
  248. .Add(x => x.Tax)
  249. .Add(x => x.Description)
  250. .Add(x => x.PurchaseGL.Code)
  251. .Add(x => x.OrderItem.ID)
  252. .Add(x => x.Job.JobNumber),
  253. alias: "Bill_BillLine");
  254. model.AddChildTable<BillLine, PurchaseOrderItem>(x => x.OrderItem.ID, x => x.ID, isdefault: true,
  255. parentalias: "Bill_BillLine", childalias: "POItem",
  256. columns: Columns.None<PurchaseOrderItem>().Add(x => x.ID)
  257. .Add(x => x.PurchaseOrderLink.PONumber)
  258. .Add(x => x.Qty)
  259. .Add(x => x.Description)
  260. .Add(x => x.Cost)
  261. .Add(x => x.CostCentre.Code)
  262. .Add(x => x.PurchaseGL.Code)
  263. .Add(x => x.PostedReference)
  264. .Add(x => x.Job.ID)
  265. .Add(x => x.Job.JobNumber)
  266. .AddDimensionsColumns(x => x.Dimensions, Dimensions.ColumnsType.Local));
  267. model.AddChildTable<PurchaseOrderItem, PurchaseOrderItemAllocation>(x => x.ID, x => x.Item.ID, isdefault: true,
  268. parentalias: "POItem", childalias: "Allocations",
  269. columns: Columns.None<PurchaseOrderItemAllocation>()
  270. .Add(x => x.Item.ID)
  271. .Add(x => x.Quantity)
  272. .Add(x => x.PostedReference)
  273. .Add(x => x.Job.ID)
  274. .Add(x => x.Job.JobNumber));
  275. Script?.Execute(methodname: "BeforePost", parameters: new object[] { model });
  276. return true;
  277. }
  278. private bool ProcessHeader(IDataModel<Bill> model, Bill bill, BillTimberlineHeader header)
  279. {
  280. return Script?.Execute(methodname: "ProcessHeader", parameters: new object[] { model, bill, header }) != false;
  281. }
  282. private bool ProcessLine(IDataModel<Bill> model, BillLine bill, PurchaseOrderItem? item, PurchaseOrderItemAllocation? allocation, BillTimberlineDistribution distribution)
  283. {
  284. return Script?.Execute(methodname: "ProcessLine", parameters: new object?[] { model, bill, item, allocation, distribution }) != false;
  285. }
  286. private class LineData(IJob job, double poCost, double poQty, IPostableFragment<PurchaseOrder> item, double qty)
  287. {
  288. public IJob Job { get; set; } = job;
  289. public double POCost { get; set; } = poCost;
  290. public double POQty { get; set; } = poQty;
  291. public IPostableFragment<PurchaseOrder> Item { get; set; } = item;
  292. public double Qty { get; set; } = qty;
  293. }
  294. private BillTimberlineResult DoProcess(IDataModel<Bill> model)
  295. {
  296. var result = new BillTimberlineResult();
  297. var lines = model.GetTable<BillLine>("Bill_BillLine").ToObjects<BillLine>()
  298. .GroupBy(x => x.BillLink.ID).ToDictionary(x => x.Key, x => x.ToList());
  299. var purchaseOrderItems = model.GetTable<PurchaseOrderItem>("POItem").ToObjects<PurchaseOrderItem>()
  300. .ToDictionary(x => x.ID, x => x);
  301. var allocations = model.GetTable<PurchaseOrderItemAllocation>("Allocations").ToObjects<PurchaseOrderItemAllocation>()
  302. .GroupBy(x => x.Item.ID)
  303. .ToDictionary(x => x.Key, x => x.ToList());
  304. var bills = model.GetTable<Bill>().ToObjects<Bill>();
  305. if(bills.Any(x => !x.IsApproved))
  306. {
  307. throw new PostFailedMessageException("We can't process unapproved bills; please approve all bills before processing.");
  308. }
  309. foreach (var bill in bills)
  310. {
  311. if(bill.Number.Length > 15)
  312. {
  313. result.AddFailed(bill, "Bill Number cannot be more than 15 digits in length.");
  314. continue;
  315. }
  316. var apif = new BillTimberlineHeader
  317. {
  318. Vendor = bill.SupplierLink.Code,
  319. Invoice = bill.Number,
  320. Description = bill.Description,
  321. Amount = Math.Round(bill.IncTax, 4),
  322. Tax = Math.Round(bill.Tax, 4),
  323. // DiscountOffered
  324. // Misc. Deduction
  325. InvoiceDate = bill.BillDate,
  326. // DateReceived doesn't exist
  327. DiscountDate = bill.BillDate,
  328. PaymentDate = bill.PaymentDate,
  329. AccountingDate = bill.AccountingDate,
  330. // InvoiceCode1
  331. // InvoiceCode2
  332. // SmryPayeeName
  333. // SmryPayeeAddress1
  334. // SmryPayeeAddress2
  335. // SmryPayeeCity
  336. // SmryPayeeState
  337. // SmryPayeeZip
  338. };
  339. if (!ProcessHeader(model, bill, apif))
  340. {
  341. result.AddFailed(bill, "Failed by script.");
  342. continue;
  343. }
  344. var success = true;
  345. var billLines = lines.GetValueOrDefault(bill.ID) ?? new List<BillLine>();
  346. foreach (var billLine in billLines)
  347. {
  348. BillTimberlineDistribution CreateLine()
  349. {
  350. var apdf = new BillTimberlineDistribution
  351. {
  352. // Equipment
  353. // EQ Cost Code
  354. // Extra
  355. // Cost Code
  356. // Category
  357. /// BL STd Item
  358. // Reserved
  359. ExpenseAccount = billLine.PurchaseGL.Code,
  360. // AP Account
  361. // Taxable Payments
  362. TaxGroup = billLine.TaxCode.Code,
  363. // Tax Liability
  364. // Discount OFfered
  365. // Retainage
  366. // MIsc Deduction
  367. // Tax Payments Exempt
  368. // Dist Code
  369. // Misc Entry 1
  370. // Misc Units 1
  371. // Misc Entry 2
  372. // Misc Units 2
  373. // Meter
  374. Description = billLine.Description,
  375. // Authorization
  376. // Joint Payee
  377. };
  378. return apdf;
  379. }
  380. var lineData = new List<LineData>();
  381. if (purchaseOrderItems.TryGetValue(billLine.OrderItem.ID, out var poItem))
  382. {
  383. var dimensions = poItem.Dimensions.Copy();
  384. var qty = DimensionUtils.ConvertDimensions(dimensions, poItem.Qty, Client<ProductDimensionUnit>.Provider);
  385. var poCost = poItem.Cost;
  386. var poQty = poItem.Qty;
  387. if (!qty.IsEffectivelyEqual(poItem.Qty))
  388. {
  389. poCost = poItem.Cost * poItem.Qty / (qty.IsEffectivelyEqual(0.0) ? 1.0 : qty);
  390. poQty = qty;
  391. }
  392. if(allocations.TryGetValue(billLine.OrderItem.ID, out var poias))
  393. {
  394. var remQty = poQty - poias.Sum(x => x.Quantity);
  395. if(remQty != 0.0)
  396. {
  397. lineData.Add(new(poItem.Job, poCost, poQty, poItem, remQty));
  398. }
  399. lineData.AddRange(poias.Select(x => new LineData(x.Job, poCost, poQty, x, x.Quantity)));
  400. }
  401. else
  402. {
  403. lineData.Add(new(poItem.Job, poCost, poQty, poItem, poQty));
  404. }
  405. foreach(var line in lineData)
  406. {
  407. var apdf = CreateLine();
  408. apdf.Commitment = poItem.PurchaseOrderLink.PONumber;
  409. apdf.ExpenseAccount = poItem.PurchaseGL.Code;
  410. if(line.Job.ID != Guid.Empty)
  411. {
  412. apdf.Job = line.Job.JobNumber;
  413. apdf.CostCode = poItem.CostCentre.Code;
  414. }
  415. if (int.TryParse(line.Item.PostedReference, out var itemNumber))
  416. {
  417. apdf.CommitmentLineItem = itemNumber;
  418. billLine.PostedReference = line.Item.PostedReference;
  419. }
  420. apdf.Units = Math.Round(line.Qty, 4);
  421. apdf.UnitCost = Math.Round(line.POCost, 4);
  422. apdf.Description = poItem.Description.NotWhiteSpaceOr(apdf.Description);
  423. apdf.Tax = Math.Round(billLine.Tax * line.Qty / line.POQty, 4);
  424. apdf.Amount = Math.Round(billLine.IncTax * line.Qty / line.POQty, 4);
  425. if (!ProcessLine(model, billLine, poItem, line.Item as PurchaseOrderItemAllocation, apdf))
  426. {
  427. success = false;
  428. break;
  429. }
  430. apif.Distributions.Add(apdf);
  431. }
  432. }
  433. else
  434. {
  435. var apdf = CreateLine();
  436. apdf.Job = billLine.Job.JobNumber;
  437. apdf.CostCode = billLine.CostCentre.Code;
  438. apdf.Amount = Math.Round(billLine.IncTax, 4);
  439. apdf.Tax = Math.Round(billLine.Tax, 4);
  440. if (!ProcessLine(model, billLine, null, null, apdf))
  441. {
  442. success = false;
  443. break;
  444. }
  445. apif.Distributions.Add(apdf);
  446. }
  447. }
  448. if (success)
  449. {
  450. foreach(var billLine in billLines)
  451. {
  452. result.AddFragment(billLine);
  453. }
  454. result.AddSuccess(bill, apif);
  455. }
  456. else
  457. {
  458. result.AddFailed(bill, "Failed by script.");
  459. }
  460. }
  461. return result;
  462. }
  463. public IPostResult<Bill> Process(IDataModel<Bill> model)
  464. {
  465. var result = DoProcess(model);
  466. var dlg = new SaveFileDialog()
  467. {
  468. Filter = "CSV Files (*.csv)|*.csv"
  469. };
  470. if (dlg.ShowDialog() == true)
  471. {
  472. using (var writer = new StreamWriter(dlg.FileName))
  473. {
  474. using var csv = new CsvWriter(writer, CultureInfo.InvariantCulture);
  475. foreach (var apif in result.Exports)
  476. {
  477. csv.WriteRecord(apif);
  478. csv.NextRecord();
  479. foreach (var apdf in apif.Distributions)
  480. {
  481. csv.WriteRecord(apdf);
  482. csv.NextRecord();
  483. }
  484. }
  485. }
  486. while (true)
  487. {
  488. var logDlg = new OpenFileDialog
  489. {
  490. InitialDirectory = Path.GetDirectoryName(dlg.FileName),
  491. FileName = "APREJECT.txt",
  492. Filter = "All Files (*.*) | *.*",
  493. Title = "Please select APREJECT.txt"
  494. };
  495. if (logDlg.ShowDialog() == true)
  496. {
  497. var rejectedHeaders = new List<BillTimberlineHeader?>();
  498. using (var reader = new StreamReader(logDlg.FileName))
  499. {
  500. using var csv = new CsvReader(reader, new CsvConfiguration(CultureInfo.InvariantCulture)
  501. {
  502. HasHeaderRecord = false
  503. });
  504. var i = 1;
  505. while (csv.Read())
  506. {
  507. var id = csv.GetField(0);
  508. if (id == "APIF")
  509. {
  510. var header = csv.GetRecord<BillTimberlineHeader>();
  511. if (header is not null)
  512. {
  513. var entry = result.Items.FirstOrDefault(x => x.Item2?.Invoice.Equals(header.Invoice) == true);
  514. if (entry is not null)
  515. {
  516. (entry.Item1 as IPostable).FailPost("");
  517. }
  518. }
  519. else
  520. {
  521. Logger.Send(LogType.Error, "", "Bill Timberline export: Unable to parse header from CSV line in rejection file.");
  522. MessageBox.Show($"Invalid line {i} in file; skipping.");
  523. }
  524. }
  525. else if (id == "APDF")
  526. {
  527. // Ignoring these because the reject file contains the header as well, and we don't need to fail BillLines, because
  528. // they aren't postable.
  529. /*var line = csv.GetRecord<BillTimberlineDistribution>();
  530. if (line is not null)
  531. {
  532. var entry = result.Items.FirstOrDefault(x => x.Item2?.Invoice.Equals(line.Invoice) == true);
  533. if (entry is not null)
  534. {
  535. (entry.Item1 as IPostable).FailPost("");
  536. }
  537. }
  538. else
  539. {
  540. Logger.Send(LogType.Error, "", "Bill Timberline export: Unable to parse line from CSV line in rejection file.");
  541. MessageBox.Show("Invalid line in file; skipping.");
  542. }*/
  543. }
  544. ++i;
  545. }
  546. }
  547. return result;
  548. }
  549. else
  550. {
  551. if (MessageBox.Show("Do you wish to cancel the export?", "Cancel Export?", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
  552. {
  553. throw new PostCancelledException();
  554. }
  555. else if (MessageBox.Show("Did everything post successfully?", "Successful?", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
  556. {
  557. return result;
  558. }
  559. }
  560. }
  561. }
  562. else
  563. {
  564. throw new PostCancelledException();
  565. }
  566. }
  567. public void AfterPost(IDataModel<Bill> model, IPostResult<Bill> result)
  568. {
  569. Script?.Execute(methodname: "AfterPost", parameters: new object[] { model });
  570. }
  571. }
  572. public class BillTimberlinePosterEngine<T> : TimberlinePosterEngine<Bill, BillTimberlineSettings>
  573. {
  574. }