@@ -54,6 +54,10 @@ frappe.ui.form.on("Full and Final Statement", {
54
54
frm . events . get_outstanding_statements ( frm ) ;
55
55
} ,
56
56
57
+ total_asset_recovery_cost : function ( frm ) {
58
+ frm . trigger ( "calculate_total_receivable_amt" ) ;
59
+ } ,
60
+
57
61
get_outstanding_statements : function ( frm ) {
58
62
if ( frm . doc . employee ) {
59
63
frappe . call ( {
@@ -66,6 +70,45 @@ frappe.ui.form.on("Full and Final Statement", {
66
70
}
67
71
} ,
68
72
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
+
69
112
create_journal_entry : function ( frm ) {
70
113
frappe . call ( {
71
114
method : "create_journal_entry" ,
@@ -80,7 +123,7 @@ frappe.ui.form.on("Full and Final Statement", {
80
123
81
124
frappe . ui . form . on ( "Full and Final Outstanding Statement" , {
82
125
reference_document : function ( frm , cdt , cdn ) {
83
- var child = locals [ 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,20 +141,20 @@ frappe.ui.form.on("Full and Final Outstanding Statement", {
98
141
}
99
142
} ,
100
143
101
- amount : function ( frm , cdt , cdn ) {
102
- let amount = 0 ;
144
+ amount : function ( frm , cdt , cdn ) {
103
145
const child_row = locals [ cdt ] [ cdn ] ;
104
146
const table = child_row . parentfield ;
105
147
106
- frm . doc [ table ] ?. forEach ( row => amount += row . amount ) ;
107
-
108
148
if ( table === "payables" ) {
109
- frm . set_value ( "total_payable_amount" , flt ( amount ) ) ;
149
+ frm . trigger ( "calculate_total_payable_amt" ) ;
110
150
} else {
111
- frm . set_value (
112
- "total_receivable_amount" ,
113
- flt ( amount ) + flt ( frm . doc . total_asset_recovery_cost )
114
- ) ;
151
+ frm . trigger ( "calculate_total_receivable_amt" ) ;
115
152
}
116
- }
153
+ } ,
154
+ } ) ;
155
+
156
+ frappe . ui . form . on ( "Full and Final Asset" , {
157
+ cost : function ( frm , _cdt , _cdn ) {
158
+ frm . trigger ( "calculate_total_receivable_amt" ) ;
159
+ } ,
117
160
} ) ;
0 commit comments