BillTimberlinePoster.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  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. .Add(x=>x.ApprovalStatus)
  244. );
  245. model.SetColumns(Columns.None<BillLine>().Add(x => x.ID)
  246. .Add(x => x.BillLink.ID)
  247. .Add(x => x.TaxCode.Code)
  248. .Add(x => x.CostCentre.Code)
  249. .Add(x => x.IncTax)
  250. .Add(x => x.Tax)
  251. .Add(x => x.Description)
  252. .Add(x => x.PurchaseGL.Code)
  253. .Add(x => x.OrderItem.ID)
  254. .Add(x => x.Job.JobNumber),
  255. alias: "Bill_BillLine");
  256. model.AddChildTable<BillLine, PurchaseOrderItem>(x => x.OrderItem.ID, x => x.ID, isdefault: true,
  257. parentalias: "Bill_BillLine", childalias: "POItem",
  258. columns: Columns.None<PurchaseOrderItem>().Add(x => x.ID)
  259. .Add(x => x.PurchaseOrderLink.PONumber)
  260. .Add(x => x.Qty)
  261. .Add(x => x.Description)
  262. .Add(x => x.Cost)
  263. .Add(x => x.CostCentre.Code)
  264. .Add(x => x.PurchaseGL.Code)
  265. .Add(x => x.PostedReference)
  266. .Add(x => x.Job.ID)
  267. .Add(x => x.Job.JobNumber)
  268. .AddDimensionsColumns(x => x.Dimensions, Dimensions.ColumnsType.Local));
  269. model.AddChildTable<PurchaseOrderItem, PurchaseOrderItemAllocation>(x => x.ID, x => x.Item.ID, isdefault: true,
  270. parentalias: "POItem", childalias: "Allocations",
  271. columns: Columns.None<PurchaseOrderItemAllocation>()
  272. .Add(x => x.Item.ID)
  273. .Add(x => x.Quantity)
  274. .Add(x => x.PostedReference)
  275. .Add(x => x.Job.ID)
  276. .Add(x => x.Job.JobNumber));
  277. Script?.Execute(methodname: "BeforePost", parameters: new object[] { model });
  278. return true;
  279. }
  280. private bool ProcessHeader(IDataModel<Bill> model, Bill bill, BillTimberlineHeader header)
  281. {
  282. return Script?.Execute(methodname: "ProcessHeader", parameters: new object[] { model, bill, header }) != false;
  283. }
  284. private bool ProcessLine(IDataModel<Bill> model, BillLine bill, PurchaseOrderItem? item, PurchaseOrderItemAllocation? allocation, BillTimberlineDistribution distribution)
  285. {
  286. return Script?.Execute(methodname: "ProcessLine", parameters: new object?[] { model, bill, item, allocation, distribution }) != false;
  287. }
  288. private class LineData(IJob job, double poCost, double poQty, IPostableFragment<PurchaseOrder> item, double qty)
  289. {
  290. public IJob Job { get; set; } = job;
  291. public double POCost { get; set; } = poCost;
  292. public double POQty { get; set; } = poQty;
  293. public IPostableFragment<PurchaseOrder> Item { get; set; } = item;
  294. public double Qty { get; set; } = qty;
  295. }
  296. private BillTimberlineResult DoProcess(IDataModel<Bill> model)
  297. {
  298. var result = new BillTimberlineResult();
  299. var lines = model.GetTable<BillLine>("Bill_BillLine").ToObjects<BillLine>()
  300. .GroupBy(x => x.BillLink.ID).ToDictionary(x => x.Key, x => x.ToList());
  301. var purchaseOrderItems = model.GetTable<PurchaseOrderItem>("POItem").ToObjects<PurchaseOrderItem>()
  302. .ToDictionary(x => x.ID, x => x);
  303. var allocations = model.GetTable<PurchaseOrderItemAllocation>("Allocations").ToObjects<PurchaseOrderItemAllocation>()
  304. .GroupBy(x => x.Item.ID)
  305. .ToDictionary(x => x.Key, x => x.ToList());
  306. var bills = model.GetTable<Bill>().ToObjects<Bill>();
  307. if(bills.Any(x => x.ApprovalStatus != BillApprovalStatus.Approved))
  308. {
  309. throw new PostFailedMessageException("We can't process unapproved bills; please approve all bills before processing.");
  310. }
  311. foreach (var bill in bills)
  312. {
  313. if(bill.Number.Length > 15)
  314. {
  315. result.AddFailed(bill, "Bill Number cannot be more than 15 digits in length.");
  316. continue;
  317. }
  318. var apif = new BillTimberlineHeader
  319. {
  320. Vendor = bill.SupplierLink.Code,
  321. Invoice = bill.Number,
  322. Description = bill.Description,
  323. Amount = Math.Round(bill.IncTax, 4),
  324. Tax = Math.Round(bill.Tax, 4),
  325. // DiscountOffered
  326. // Misc. Deduction
  327. InvoiceDate = bill.BillDate,
  328. // DateReceived doesn't exist
  329. DiscountDate = bill.BillDate,
  330. PaymentDate = bill.PaymentDate,
  331. AccountingDate = bill.AccountingDate,
  332. // InvoiceCode1
  333. // InvoiceCode2
  334. // SmryPayeeName
  335. // SmryPayeeAddress1
  336. // SmryPayeeAddress2
  337. // SmryPayeeCity
  338. // SmryPayeeState
  339. // SmryPayeeZip
  340. };
  341. if (!ProcessHeader(model, bill, apif))
  342. {
  343. result.AddFailed(bill, "Failed by script.");
  344. continue;
  345. }
  346. var success = true;
  347. var billLines = lines.GetValueOrDefault(bill.ID) ?? new List<BillLine>();
  348. foreach (var billLine in billLines)
  349. {
  350. BillTimberlineDistribution CreateLine()
  351. {
  352. var apdf = new BillTimberlineDistribution
  353. {
  354. // Equipment
  355. // EQ Cost Code
  356. // Extra
  357. // Cost Code
  358. // Category
  359. /// BL STd Item
  360. // Reserved
  361. ExpenseAccount = billLine.PurchaseGL.Code,
  362. // AP Account
  363. // Taxable Payments
  364. TaxGroup = billLine.TaxCode.Code,
  365. // Tax Liability
  366. // Discount OFfered
  367. // Retainage
  368. // MIsc Deduction
  369. // Tax Payments Exempt
  370. // Dist Code
  371. // Misc Entry 1
  372. // Misc Units 1
  373. // Misc Entry 2
  374. // Misc Units 2
  375. // Meter
  376. Description = billLine.Description,
  377. // Authorization
  378. // Joint Payee
  379. };
  380. return apdf;
  381. }
  382. var lineData = new List<LineData>();
  383. if (purchaseOrderItems.TryGetValue(billLine.OrderItem.ID, out var poItem))
  384. {
  385. var dimensions = poItem.Dimensions.Copy();
  386. var poCost = poItem.Cost;
  387. var poQty = poItem.Qty;
  388. DimensionUtils.ConvertDimensions(
  389. dimensions,
  390. ref poQty,
  391. ref poCost,
  392. Client<ProductDimensionUnit>.Provider
  393. );
  394. if(allocations.TryGetValue(billLine.OrderItem.ID, out var poias))
  395. {
  396. var remQty = poQty - poias.Sum(x => x.Quantity);
  397. if(remQty != 0.0)
  398. {
  399. lineData.Add(new(poItem.Job, poCost, poQty, poItem, remQty));
  400. }
  401. lineData.AddRange(poias.Select(x => new LineData(x.Job, poCost, poQty, x, x.Quantity)));
  402. }
  403. else
  404. {
  405. lineData.Add(new(poItem.Job, poCost, poQty, poItem, poQty));
  406. }
  407. foreach(var line in lineData)
  408. {
  409. var apdf = CreateLine();
  410. apdf.Commitment = poItem.PurchaseOrderLink.PONumber;
  411. apdf.ExpenseAccount = poItem.PurchaseGL.Code;
  412. if(line.Job.ID != Guid.Empty)
  413. {
  414. apdf.Job = line.Job.JobNumber;
  415. apdf.CostCode = poItem.CostCentre.Code;
  416. }
  417. if (int.TryParse(line.Item.PostedReference, out var itemNumber))
  418. {
  419. apdf.CommitmentLineItem = itemNumber;
  420. billLine.PostedReference = line.Item.PostedReference;
  421. }
  422. apdf.Units = Math.Round(line.Qty, 4);
  423. apdf.UnitCost = Math.Round(line.POCost, 4);
  424. apdf.Description = poItem.Description.NotWhiteSpaceOr(apdf.Description);
  425. apdf.Tax = Math.Round(billLine.Tax * line.Qty / line.POQty, 4);
  426. apdf.Amount = Math.Round(billLine.IncTax * line.Qty / line.POQty, 4);
  427. if (!ProcessLine(model, billLine, poItem, line.Item as PurchaseOrderItemAllocation, apdf))
  428. {
  429. success = false;
  430. break;
  431. }
  432. apif.Distributions.Add(apdf);
  433. }
  434. }
  435. else
  436. {
  437. var apdf = CreateLine();
  438. apdf.Job = billLine.Job.JobNumber;
  439. apdf.CostCode = billLine.CostCentre.Code;
  440. apdf.Amount = Math.Round(billLine.IncTax, 4);
  441. apdf.Tax = Math.Round(billLine.Tax, 4);
  442. if (!ProcessLine(model, billLine, null, null, apdf))
  443. {
  444. success = false;
  445. break;
  446. }
  447. apif.Distributions.Add(apdf);
  448. }
  449. }
  450. if (success)
  451. {
  452. foreach(var billLine in billLines)
  453. {
  454. result.AddFragment(billLine);
  455. }
  456. result.AddSuccess(bill, apif);
  457. }
  458. else
  459. {
  460. result.AddFailed(bill, "Failed by script.");
  461. }
  462. }
  463. return result;
  464. }
  465. public IPostResult<Bill> Process(IDataModel<Bill> model)
  466. {
  467. var result = DoProcess(model);
  468. var dlg = new SaveFileDialog()
  469. {
  470. Filter = "CSV Files (*.csv)|*.csv"
  471. };
  472. if (dlg.ShowDialog() == true)
  473. {
  474. using (var writer = new StreamWriter(dlg.FileName))
  475. {
  476. using var csv = new CsvWriter(writer, CultureInfo.InvariantCulture);
  477. foreach (var apif in result.Exports)
  478. {
  479. csv.WriteRecord(apif);
  480. csv.NextRecord();
  481. foreach (var apdf in apif.Distributions)
  482. {
  483. csv.WriteRecord(apdf);
  484. csv.NextRecord();
  485. }
  486. }
  487. }
  488. while (true)
  489. {
  490. var logDlg = new OpenFileDialog
  491. {
  492. InitialDirectory = Path.GetDirectoryName(dlg.FileName),
  493. FileName = "APREJECT.txt",
  494. Filter = "All Files (*.*) | *.*",
  495. Title = "Please select APREJECT.txt"
  496. };
  497. if (logDlg.ShowDialog() == true)
  498. {
  499. var rejectedHeaders = new List<BillTimberlineHeader?>();
  500. using (var reader = new StreamReader(logDlg.FileName))
  501. {
  502. using var csv = new CsvReader(reader, new CsvConfiguration(CultureInfo.InvariantCulture)
  503. {
  504. HasHeaderRecord = false
  505. });
  506. var i = 1;
  507. while (csv.Read())
  508. {
  509. var id = csv.GetField(0);
  510. if (id == "APIF")
  511. {
  512. var header = csv.GetRecord<BillTimberlineHeader>();
  513. if (header is not null)
  514. {
  515. var entry = result.Items.FirstOrDefault(x => x.Item2?.Invoice.Equals(header.Invoice) == true);
  516. if (entry is not null)
  517. {
  518. (entry.Item1 as IPostable).FailPost("");
  519. }
  520. }
  521. else
  522. {
  523. Logger.Send(LogType.Error, "", "Bill Timberline export: Unable to parse header from CSV line in rejection file.");
  524. MessageBox.Show($"Invalid line {i} in file; skipping.");
  525. }
  526. }
  527. else if (id == "APDF")
  528. {
  529. // Ignoring these because the reject file contains the header as well, and we don't need to fail BillLines, because
  530. // they aren't postable.
  531. /*var line = csv.GetRecord<BillTimberlineDistribution>();
  532. if (line is not null)
  533. {
  534. var entry = result.Items.FirstOrDefault(x => x.Item2?.Invoice.Equals(line.Invoice) == true);
  535. if (entry is not null)
  536. {
  537. (entry.Item1 as IPostable).FailPost("");
  538. }
  539. }
  540. else
  541. {
  542. Logger.Send(LogType.Error, "", "Bill Timberline export: Unable to parse line from CSV line in rejection file.");
  543. MessageBox.Show("Invalid line in file; skipping.");
  544. }*/
  545. }
  546. ++i;
  547. }
  548. }
  549. return result;
  550. }
  551. else
  552. {
  553. if (MessageBox.Show("Do you wish to cancel the export?", "Cancel Export?", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
  554. {
  555. throw new PostCancelledException();
  556. }
  557. else if (MessageBox.Show("Did everything post successfully?", "Successful?", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
  558. {
  559. return result;
  560. }
  561. }
  562. }
  563. }
  564. else
  565. {
  566. throw new PostCancelledException();
  567. }
  568. }
  569. public void AfterPost(IDataModel<Bill> model, IPostResult<Bill> result)
  570. {
  571. Script?.Execute(methodname: "AfterPost", parameters: new object[] { model });
  572. }
  573. }
  574. public class BillTimberlinePosterEngine<T> : TimberlinePosterEngine<Bill, BillTimberlineSettings>
  575. {
  576. }