-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
67 lines (61 loc) · 2.92 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using COA.Common;
using COA.EnterpriseServices.Creditors;
using COA.SettlementFix.CreditorServiceWcf;
using System;
using System.Linq;
namespace COA.SettlementFix
{
internal class Program
{
private static void Main(string[] args)
{
var settingsProxy = new SettingsProxy();
var quickbaseConnectionString = settingsProxy.GetConnectionString(SettingsProxy.Databases.Quickbase);
// gather creditors with out-of-sync status (SQL <=> QuickBase)
var creditors = DBWrapper.ExecuteCommand(quickbaseConnectionString, cmd =>
{
cmd.CommandText = @"select
responseStatus.CreditorID
, responseStatus.ResponseDate
, responseStatus.RejectReasonID
, responseStatus.RejectReasonComment
, responseStatus.[Status Name] AttemptedStatus
, sa.[Date Created] AttemptCreated
, currentStatus.[**Creditor Status] CurrentStatus
, cl.[Enrolled Client Name] ClientName
, cr.[Account #] AccountNumber
, cr.[Current Balance] CurrentBalance
, pro.[Creditor Name] CreditorName
, sa.[Record ID#] SettlementAttemptId
from
(
select cr.CreditorID, st.[Status Name], cr.ResponseDate, cr.RejectReasonID, cr.RejectReasonComment, row_number() over (partition by cr.CreditorID order by cr.ResponseDate desc) RowNum
from CreditorResponse cr (nolock)
join QB_Creditor_Status_Types st (nolock) on st.[Record ID#] = cr.CreditorStatusTypeID
where cr.ResponseDate > '9/16/2020'
) responseStatus
cross apply dbo.[udfQB_Creditor_**CreditorStatus](responseStatus.CreditorID) currentStatus
join QB_Creditors cr (nolock) on cr.[Record ID#] = responseStatus.CreditorID
join QB_COA_Creditor pro (nolock) on pro.[Record ID#] = cr.[Related Current Creditor Primary]
join QB_Client cl (nolock) on cl.[Record ID#] = cr.[Related Client]
join QB_Settlement_Attempt sa (nolock) on sa.[Record ID#] = currentStatus.[Max Settlement Attempt Record ID]
where responseStatus.RowNum = 1
and currentStatus.[**Creditor Status] in ('Offer Made Pending', 'Waiting for SIF')
and responseStatus.ResponseDate > sa.[Date Created]
order by cl.[Enrolled Client Name]";
return cmd.ToList<Creditor>();
});
var client = new ServiceClient();
foreach (var creditor in creditors)
{
Console.WriteLine($"Updating {creditor.CreditorName} (creditor ID {creditor.CreditorId}, attempt {creditor.SettlementAttemptId}) for client {creditor.ClientName} to status {creditor.AttemptedStatus}");
var result = client.UpdateSettlementAttempt(new SettlementAttemptUpdate
{
SettlementAttemptId = creditor.SettlementAttemptId,
CreditorStatusType = creditor.AttemptedStatus.ToEnum<CreditorStatusType>(),
Notes = creditor.RejectReasonComment
});
}
}
}
}