'', 'R' => round2($R), 'A' => 0, 'A_o' => null, 'details' => array() ); if ($T % $L === 0) { $N = $T / $L; $result['type'] = 'equal_no_remainder'; $result['A'] = round2($R / $N); $result['details'] = array('N' => $N); } else { $fullPeriods = floor($T / $L); $remainder = $T % $L; if ($type_payment === 'equal_payments') { $N = $fullPeriods + 1; $result['type'] = 'equal_with_remainder'; $result['A'] = round2($R / $N); $result['details'] = array( 'fullPeriods' => $fullPeriods, 'remainder' => $remainder, 'N' => $N ); } else { $Am = $R / $T; $result['type'] = 'decreasing'; $result['A'] = round2($Am * $L); $result['A_o'] = round2($Am * $remainder); $result['details'] = array( 'fullPeriods' => $fullPeriods, 'remainder' => $remainder, 'T' => $T ); } } $compare = array( 'R' => array('frontend' => floatval($calculation_info['R']), 'backend' => $result['R']), 'A' => array('frontend' => floatval($calculation_info['A']), 'backend' => $result['A']), 'A_o' => array('frontend' => isset($calculation_info['A_o']) ? floatval($calculation_info['A_o']) : null, 'backend' => $result['A_o']) ); foreach ($compare as $key => $val) { echo "$key: frontend = {$val['frontend']}, backend = {$val['backend']}"; if ($val['frontend'] == $val['backend']) { echo " ✅ OK"; } else { echo " ❌ НЕ СОВПАДАЕТ"; } echo "\n"; } foreach (array('R', 'A', 'A_o') as $key) { $calculation_info[$key] = isset($result[$key]) ? $result[$key] : null; } if ($apartment_id && $user_id && is_array($calculation_info)) { $jsonData = mysql_real_escape_string(json_encode($calculation_info, JSON_UNESCAPED_UNICODE)); $new_installment_price = isset($calculation_info['P']) ? floatval($calculation_info['P']) : 0; $sql_check = "SELECT id FROM sended_pdf_complexes WHERE id_agent = '$user_id' AND id_object = '$apartment_id' AND sent_catalog_id = '$catalog_id'"; $res_check = mysql_query($sql_check); if (mysql_num_rows($res_check) > 0) { $sql_update = "UPDATE sended_pdf_complexes SET calculation_data = '$jsonData', new_installment_price = '$new_installment_price' WHERE id_agent = '$user_id' AND id_object = '$apartment_id' AND sent_catalog_id = '$catalog_id' "; mysql_query($sql_update); } } ?>