@@ -54,7 +54,11 @@ frappe.ui.form.on('Full and Final Statement', {
54
54
frm . events . get_outstanding_statements ( frm ) ;
55
55
} ,
56
56
57
- get_outstanding_statements : function ( frm ) {
57
+ total_asset_recovery_cost : function ( frm ) {
58
+ frm . trigger ( "calculate_total_receivable_amt" ) ;
59
+ } ,
60
+
61
+ get_outstanding_statements : function ( frm ) {
58
62
if ( frm . doc . employee ) {
59
63
frappe . call ( {
60
64
method : "get_outstanding_statements" ,
@@ -66,7 +70,46 @@ frappe.ui.form.on('Full and Final Statement', {
66
70
}
67
71
} ,
68
72
69
- create_journal_entry : function ( frm ) {
73
+ calculate_total_payable_amt : function ( frm ) {
74
+ let total_payable_amount = 0 ;
75
+
76
+ frm . doc . payables ?. forEach (
77
+ ( row ) => ( total_payable_amount += flt ( row . amount , precision ( "amount" , row ) ) ) ,
78
+ ) ;
79
+ frm . set_value (
80
+ "total_payable_amount" ,
81
+ flt ( total_payable_amount , precision ( "total_payable_amount" ) ) ,
82
+ ) ;
83
+ } ,
84
+
85
+ calculate_total_receivable_amt : function ( frm ) {
86
+ let total_asset_recovery_cost = 0 ;
87
+ let total_receivable_amount = 0 ;
88
+
89
+ frm . doc . assets_allocated ?. forEach ( ( row ) => {
90
+ if ( row . action === "Recover Cost" ) {
91
+ total_asset_recovery_cost += flt ( row . cost , precision ( "cost" , row ) ) ;
92
+ }
93
+ } ) ;
94
+
95
+ frm . doc . receivables ?. forEach (
96
+ ( row ) => ( total_receivable_amount += flt ( row . amount , precision ( "amount" , row ) ) ) ,
97
+ ) ;
98
+
99
+ frm . set_value (
100
+ "total_asset_recovery_cost" ,
101
+ flt ( total_asset_recovery_cost , precision ( "total_asset_recovery_cost" ) ) ,
102
+ ) ;
103
+ frm . set_value (
104
+ "total_receivable_amount" ,
105
+ flt (
106
+ total_asset_recovery_cost + total_receivable_amount ,
107
+ precision ( "total_receivable_amount" ) ,
108
+ ) ,
109
+ ) ;
110
+ } ,
111
+
112
+ create_journal_entry : function ( frm ) {
70
113
frappe . call ( {
71
114
method : "create_journal_entry" ,
72
115
doc : frm . doc ,
@@ -79,8 +122,8 @@ frappe.ui.form.on('Full and Final Statement', {
79
122
} ) ;
80
123
81
124
frappe . ui . form . on ( "Full and Final Outstanding Statement" , {
82
- reference_document : function ( frm , cdt , cdn ) {
83
- var child = locals [ cdt ] [ cdn ] ;
125
+ reference_document : function ( frm , cdt , cdn ) {
126
+ const child = locals [ cdt ] [ cdn ] ;
84
127
if ( child . reference_document_type && child . reference_document ) {
85
128
frappe . call ( {
86
129
method : "hrms.hr.doctype.full_and_final_statement.full_and_final_statement.get_account_and_amount" ,
@@ -98,18 +141,20 @@ frappe.ui.form.on("Full and Final Outstanding Statement", {
98
141
}
99
142
} ,
100
143
101
- amount : function ( frm ) {
102
- var total_payable_amount = 0 ;
103
- var total_receivable_amount = 0 ;
144
+ amount : function ( frm , cdt , cdn ) {
145
+ const child_row = locals [ cdt ] [ cdn ] ;
146
+ const table = child_row . parentfield ;
104
147
105
- frm . doc . payables . forEach ( element => {
106
- total_payable_amount = total_payable_amount + element . amount ;
107
- } ) ;
148
+ if ( table === "payables" ) {
149
+ frm . trigger ( "calculate_total_payable_amt" ) ;
150
+ } else {
151
+ frm . trigger ( "calculate_total_receivable_amt" ) ;
152
+ }
153
+ } ,
154
+ } ) ;
108
155
109
- frm . doc . receivables . forEach ( element => {
110
- total_receivable_amount = total_receivable_amount + element . amount ;
111
- } ) ;
112
- frm . set_value ( "total_payable_amount" , flt ( total_payable_amount ) ) ;
113
- frm . set_value ( "total_receivable_amount" , flt ( total_receivable_amount ) ) ;
114
- }
156
+ frappe . ui . form . on ( "Full and Final Asset" , {
157
+ cost : function ( frm , _cdt , _cdn ) {
158
+ frm . trigger ( "calculate_total_receivable_amt" ) ;
159
+ } ,
115
160
} ) ;
0 commit comments