1
00:00:07,560 --> 00:00:14,730
In this video, let's work on the tool to balance the total expenses and then the total income.

2
00:00:14,940 --> 00:00:20,610
Well, before I continue, I want to give the expenses a color of red.

3
00:00:20,850 --> 00:00:28,920
So let's get back to the components, and that is our C component dashboard and then the account details.

4
00:00:29,010 --> 00:00:34,200
So let's allocate the expenses to to balance here expenses.

5
00:00:34,200 --> 00:00:43,200
And for this one, I want to give it a color of red and give this one as 400 or let's see, 600.

6
00:00:43,200 --> 00:00:43,560
Yeah.

7
00:00:43,740 --> 00:00:45,720
So let's save it and let's see.

8
00:00:45,720 --> 00:00:47,280
And indeed, we have it.

9
00:00:47,460 --> 00:00:49,420
What about the income?

10
00:00:49,440 --> 00:00:52,710
I want to give it a color of green.

11
00:00:53,160 --> 00:00:57,960
So the income is this one 9000, which is this one?

12
00:00:58,260 --> 00:01:02,910
I want to give it a color of green for success.

13
00:01:04,110 --> 00:01:05,960
Yes, yes, yes, yes, yes.

14
00:01:05,970 --> 00:01:08,070
So I think this one's okay.

15
00:01:08,160 --> 00:01:09,910
So how can we calculate?

16
00:01:09,930 --> 00:01:14,100
Guys, remember, we have two types of transactions.

17
00:01:14,130 --> 00:01:17,250
You see, we have income and then the expenses.

18
00:01:17,430 --> 00:01:25,200
So we are going to look through to find all transaction by type income and then you are going to use

19
00:01:25,200 --> 00:01:31,020
reduce to add up and also and the same way for expenses.

20
00:01:31,020 --> 00:01:33,210
And we can do this one in two ways.

21
00:01:33,300 --> 00:01:41,370
One is we are going to filter out all transaction with a TIBCO income and then after that we are going

22
00:01:41,370 --> 00:01:43,220
to use reduce contacts.

23
00:01:43,230 --> 00:01:45,090
So let's have a comment here.

24
00:01:45,450 --> 00:01:51,810
So the first one is going to be as calculates the total income calculate.

25
00:01:55,580 --> 00:01:56,870
To a tight income.

26
00:01:57,080 --> 00:01:58,280
And here we go.

27
00:01:58,550 --> 00:02:05,260
Cost total income is equal to the account.

28
00:02:05,280 --> 00:02:11,780
Remember, we have all the transactions and then we are going to use reduce to reduce that.

29
00:02:12,110 --> 00:02:19,730
So here you go and I'll pass in a callback function as that and I have the first variable as a accumulator

30
00:02:19,730 --> 00:02:22,220
and then the actual transaction.

31
00:02:22,910 --> 00:02:30,620
So in case you are not familiar with the reduced method and the essays of this course, I cover them

32
00:02:30,620 --> 00:02:31,430
in details.

33
00:02:31,430 --> 00:02:32,150
But don't worry.

34
00:02:32,150 --> 00:02:38,750
I've explained to you as I move on to inside here, I'm going to pass in the callback function.

35
00:02:38,750 --> 00:02:40,670
I'll start the next one.

36
00:02:40,670 --> 00:02:42,500
Going to be the initialize.

37
00:02:42,710 --> 00:02:45,170
So by default I'll provide zero.

38
00:02:45,410 --> 00:02:52,910
And inside here, if you console.log the account as accumulator, you're going to see that by default

39
00:02:52,910 --> 00:02:54,260
you're going to be zero.

40
00:02:54,260 --> 00:02:59,600
So upon every loop you're going to add the transaction amount.

41
00:02:59,600 --> 00:03:06,860
But before we continue, unless we make some checking here and here we go on a transaction, if the

42
00:03:06,860 --> 00:03:14,930
transaction type, if you console.log the transaction, you're going to see what is called transaction

43
00:03:14,930 --> 00:03:19,550
type if it is equal to income.

44
00:03:22,340 --> 00:03:34,940
Then we are going to add up, retain the account plus the transaction dot amount else retained the account

45
00:03:35,300 --> 00:03:36,570
that is in share one.

46
00:03:36,600 --> 00:03:37,120
Great.

47
00:03:37,130 --> 00:03:46,190
So here if you consider that log the console, that log the total income.

48
00:03:46,640 --> 00:03:47,420
Let's see.

49
00:03:48,050 --> 00:03:51,680
So let's check the console and let's see what we have.

50
00:03:52,250 --> 00:03:59,630
Line number 21, we have zero, which is this where is so weird, right?

51
00:04:00,050 --> 00:04:03,920
I think our condition here is not working well.

52
00:04:03,950 --> 00:04:11,990
So let's try to console, log this to make sure if you're going to have true or false, let's save it.

53
00:04:11,990 --> 00:04:13,400
And now let's see.

54
00:04:14,270 --> 00:04:20,360
You can see that we have false meaning that our condition is not correct.

55
00:04:20,779 --> 00:04:25,310
So let's console.log the transaction type and let's see.

56
00:04:25,840 --> 00:04:32,860
I see we have undefined meaning I'm making some typing mistake about the transfer.

57
00:04:32,870 --> 00:04:34,340
Oh sorry.

58
00:04:34,970 --> 00:04:38,330
It is spelling of transaction as is here.

59
00:04:38,600 --> 00:04:39,740
So I believe you guys.

60
00:04:39,740 --> 00:04:40,070
Sorry.

61
00:04:40,070 --> 00:04:42,860
So we're going to be transaction with s.

62
00:04:43,370 --> 00:04:46,760
We see how one word and one letter can confuse us.

63
00:04:46,760 --> 00:04:48,620
So let's save it and let's see.

64
00:04:48,680 --> 00:04:52,460
And I have $5,000, so let's see.

65
00:04:52,460 --> 00:04:54,890
Well, so let's check it out and see.

66
00:04:54,890 --> 00:04:57,890
Yeah, we have one with income 5000.

67
00:04:57,890 --> 00:05:09,560
So if I get back to back end and I want to add a transaction of income and sum around, let me change

68
00:05:09,560 --> 00:05:16,520
this one to let's see 1000 and call this one as I got this one for my salary to support my project.

69
00:05:16,520 --> 00:05:17,810
So it's sent.

70
00:05:19,170 --> 00:05:21,060
And let me refresh it.

71
00:05:21,940 --> 00:05:24,290
And let me check the cargo some.

72
00:05:24,410 --> 00:05:25,060
This one.

73
00:05:25,420 --> 00:05:27,040
Let me check the console.

74
00:05:27,040 --> 00:05:35,320
And I got 6000 because 5000 plus 1000 is equal to 6000.

75
00:05:35,320 --> 00:05:38,620
So now I can replace with this one by remember.

76
00:05:39,040 --> 00:05:46,620
In case a user add that initial balance to the account upon creating, we need to add that one.

77
00:05:46,630 --> 00:05:53,590
Let's console.log the account and let's add the transaction and let's add the initial balance.

78
00:05:53,590 --> 00:05:57,640
So let's look at the account on line number four.

79
00:05:57,670 --> 00:05:59,440
So let's get back to the coin.

80
00:05:59,450 --> 00:06:03,910
So again, line number 12, which is this one?

81
00:06:04,000 --> 00:06:06,730
Oh yeah, this one, the last one.

82
00:06:06,730 --> 00:06:12,730
And let's look at the initial balance for this account, yet you can see that this account have initial

83
00:06:12,730 --> 00:06:14,740
balance of 1000.

84
00:06:14,950 --> 00:06:21,070
So what you're going to do is that we are going to add plus the initial balance.

85
00:06:21,250 --> 00:06:26,260
So inside the value here where we are displaying it.

86
00:06:26,260 --> 00:06:29,770
So inside where we have the total balance.

87
00:06:30,490 --> 00:06:40,000
So now inside the total income, which is this one, total expenses and income, we are going to add

88
00:06:40,000 --> 00:06:40,690
the value.

89
00:06:40,710 --> 00:06:42,460
So here are going to be.

90
00:06:43,980 --> 00:06:56,160
Dollar sign carrier base is going to be the total income and then plus the account Dot's initial balance.

91
00:06:59,760 --> 00:07:03,600
So we are going to have what is called 7000, right?

92
00:07:03,600 --> 00:07:06,120
So let's see, let's check it out.

93
00:07:06,120 --> 00:07:08,880
And indeed we have 7000.

94
00:07:08,880 --> 00:07:11,550
So why from the duplicate dollars here.

95
00:07:12,150 --> 00:07:13,830
Yeah, so let's see.

96
00:07:13,830 --> 00:07:16,620
And indeed this is my total income.

97
00:07:16,620 --> 00:07:19,110
So what would be the total expenses?

98
00:07:19,110 --> 00:07:21,630
So we're going to be copy and paste.

99
00:07:21,630 --> 00:07:25,050
So here you go and we are going to copy this one.

100
00:07:25,470 --> 00:07:30,840
And down here, let's pass it here and going to be total expenses

101
00:07:33,540 --> 00:07:43,980
and here is going to be as total expenses and here type is expenses and that is it.

102
00:07:43,980 --> 00:07:52,770
So let's inject inside the expenses placeholder, which is this, and here we go.

103
00:07:54,090 --> 00:07:54,710
Sorry.

104
00:07:56,280 --> 00:07:56,850
Here.

105
00:07:59,320 --> 00:08:01,030
Total expenses.

106
00:08:01,030 --> 00:08:01,520
Yeah.

107
00:08:02,930 --> 00:08:03,650
Then you see.

108
00:08:03,650 --> 00:08:07,760
Yeah, we have 10,000 because we have two expenses.

109
00:08:07,760 --> 00:08:11,690
One 5000, one 5000 equal to 10,000.

110
00:08:11,690 --> 00:08:14,210
So what about the total balance?

111
00:08:14,420 --> 00:08:15,710
I'm going to pretty easy, right?

112
00:08:15,890 --> 00:08:16,910
Just subtracting.

113
00:08:16,910 --> 00:08:31,730
So here we are going to subtract the total income plus the accounts, the initial balance, initial

114
00:08:31,730 --> 00:08:35,870
balance then minus the total expenses.

115
00:08:37,460 --> 00:08:38,929
And here you go.

116
00:08:38,929 --> 00:08:40,659
And indeed we are of.

