@@ -131,9 +131,39 @@ function override_child_entry_input_value( $entry, $field, $child_form, $input_i
131131 $ child_entry = GFAPI ::get_entry ( $ child_entry_id );
132132 $ value = GFCommon::replace_variables ( $ default_value , $ child_form , $ child_entry );
133133 GFAPI ::update_entry_field ( $ child_entry_id , $ input_id , $ value );
134+
135+ // If because of the field update, any formula evaluation should be done on the entry.
136+ $ this ->reprocess_form_calculations ( $ child_entry_id );
134137 }
135138
136139 }
140+
141+ function reprocess_form_calculations ( $ entry_id ) {
142+ $ entry = GFAPI ::get_entry ( $ entry_id );
143+ $ form = GFAPI ::get_form ( $ entry ['form_id ' ] );
144+
145+ foreach ( $ form ['fields ' ] as $ field ) {
146+ // Only process calculation fields
147+ if ( $ field ->enableCalculation && $ field ->calculationFormula ) {
148+ $ field_id = $ field ->id ;
149+
150+ // Retrieve the formula for this field and process. First check for GPDTC calculations because of ':' calculations.
151+ if ( is_callable ( array ( gp_date_time_calculator (), 'modify_calculation_formula ' ) ) ) {
152+ $ formula = gp_date_time_calculator ()->modify_calculation_formula ( $ field ->calculationFormula , $ field , $ form , $ entry );
153+ }
154+
155+ // Process any other filter customization over it.
156+ $ formula = apply_filters ( 'gform_calculation_formula ' , $ formula , $ form , $ field , $ entry );
157+
158+ // Process/Calculate the formula
159+ $ parsed_formula = GFCommon::replace_variables ( $ formula , $ form , $ entry , false , false , false , 'text ' );
160+ $ calculated_value = eval ( 'return ' . $ parsed_formula . '; ' );
161+
162+ // Update the entry with the recalculated value
163+ GFAPI ::update_entry_field ( $ entry_id , $ field_id , $ calculated_value );
164+ }
165+ }
166+ }
137167}
138168
139169# -------------------------------------------------
0 commit comments