1+ using System ;
2+ using System . Collections . Generic ;
3+ using App . AL . Utils . Funding ;
4+ using App . DL . Enum ;
5+ using App . DL . Model . Funding ;
6+ using App . DL . Repository . User ;
7+ using App . PL . Transformer . Funding ;
8+ using App . PL . Transformer . User ;
9+ using Micron . AL . Config . CLI ;
10+ using Micron . DL . Module . CLI ;
11+ using Newtonsoft . Json . Linq ;
12+
13+ namespace App . AL . CLI . Finding {
14+ public class ApproveInvoice : BaseCommand , ICliCommand {
15+ public override string Signature { get ; } = "approve-invoice" ;
16+
17+ public ApproveInvoice ( ) {
18+ StrOutput = new List < string > ( ) ;
19+ }
20+
21+ public CliResult Execute ( ) {
22+ Output ( "Approving invoice" ) ;
23+ Output ( "Type invoice id:" ) ;
24+
25+ var id = Convert . ToInt32 ( Console . ReadLine ( ) ) ;
26+ var invoice = Invoice . Find ( id ) ;
27+ if ( invoice == null ) {
28+ Output ( $ "Invoice with id { id } not found") ;
29+ return new CliResult ( CliExitCode . NotFound , StrOutput ) ;
30+ }
31+
32+ Output ( "Invoice:" ) ;
33+ Output ( JObject . FromObject ( invoice ) . ToString ( ) ) ;
34+ Output ( "Transformed invoice:" ) ;
35+ Output ( new InvoiceTransformer ( ) . Transform ( invoice ) . ToString ( ) ) ;
36+ Output ( "Invoice user:" ) ;
37+ Output ( JObject . FromObject ( invoice . User ( ) ) . ToString ( ) ) ;
38+
39+ if ( invoice . status != InvoiceStatus . RequiresConfirmation ) {
40+ Output ( "Invoice has invalid status - allowed only: " + InvoiceStatus . RequiresConfirmation ) ;
41+ return new CliResult ( CliExitCode . UnknownError , StrOutput ) ;
42+ }
43+
44+ var isApproving = Ask ( "Approve that invoice?" ) ;
45+
46+ if ( ! isApproving ) {
47+ Output ( "Aborted." ) ;
48+ return new CliResult ( CliExitCode . Ok , StrOutput ) ;
49+ }
50+
51+ Output ( "Approving invoice..." ) ;
52+
53+ invoice = InvoiceUtils . ConfirmInvoice ( invoice ) ;
54+
55+ var isProcessing = Ask ( "Process confirmed invoice?" ) ;
56+
57+ if ( ! isProcessing ) {
58+ return new CliResult ( CliExitCode . Ok , StrOutput ) ;
59+ }
60+
61+ var balance = UserBalanceRepository . Find ( invoice . User ( ) ) ;
62+
63+ Output ( "Balance before:" ) ;
64+ Output ( new UserBalanceTransformer ( ) . Transform ( balance ) . ToString ( ) ) ;
65+
66+ Output ( "Processing invoice..." ) ;
67+ invoice = InvoiceUtils . ProcessConfirmedInvoice ( invoice ) ;
68+ Output ( "Invoice processing finished..." ) ;
69+
70+ Output ( "Balance after:" ) ;
71+ Output ( new UserBalanceTransformer ( ) . Transform ( balance . Refresh ( ) ) . ToString ( ) ) ;
72+
73+ Output ( "Transformed invoice:" ) ;
74+ Output ( new InvoiceTransformer ( ) . Transform ( invoice ) . ToString ( ) ) ;
75+
76+ return new CliResult ( CliExitCode . Ok , StrOutput ) ;
77+ }
78+ }
79+ }
0 commit comments