196 if (result === "nrp") { 197 const nrpCount = currentNrp + 1; 198 const reachedMax = nrpCount >= MAX_NRP; 199 const next = reachedMax ? null : new Date(Date.parse(now) + NRP_HIDE_MS).toISOString(); 200 if (isReservationResource(resourceType)) { 201 return { 202 nrpCount, cycle, 203 fields: { 204 ...base, 205 nrp_count: nrpCount, 206 followup_status: reachedMax ? "ko" : "nrp_waiting", 207 next_followup_at: next, 208 status: reachedMax ? "completed" : "nrp", 209 commercial_outcome: reachedMax ? "unreachable_max" : "unreachable", 210 commercial_notes: appendNote(resource.commercial_notes, notes), 211 outcome_at: reachedMax ? now : null, 212 last_attempt_at: now, 213 next_attempt_at: next, 214 commercial_id: clean(resource.commercial_id) || commercialId, 215 claimed_by: clean(resource.claimed_by) || commercialId, 216 }, 217 }; 218 } 219 return { 220 nrpCount, cycle, 221 fields: { 222 ...base, 223 nrp_count: nrpCount, 224 // The completed attempt remains in last_followup_appel_id; this slot 225 // is reserved for an active attempt, not the previous NRP. 226 followup_appel_id: null, 227 followup_status: reachedMax ? "ko" : "nrp_waiting", 228 next_followup_at: next, 229 status: "manque", 230 issue: reachedMax ? "injoignable" : "nrp", 231 motif: reachedMax ? "nrp_4" : `nrp_${nrpCount}`, 232 notes: appendNote(resource.notes, notes), 233 missed_pool_status: reachedMax ? "done" : "claimed", 234 missed_pool_visible_at: next, 235 missed_claimed_by: clean(resource.missed_claimed_by) || clean(resource.commercial_id) || commercialId, 236 missed_claimed_at: now, 237 missed_claim_expires_at: reachedMax ? null : new Date(Date.parse(next) + 24 * 60 * 60 * 1000).toISOString(), 238 }, 239 }; 240 } 241 242 const terminalStatus = result === "contacted" ? "contacted" : result === "sale" ? "sale" : "lost"; 243 const common = { 244 ...base, 245 nrp_count: currentNrp, 246 followup_status: terminalStatus, 247 next_followup_at: null, 248 }; 249 if (isReservationResource(resourceType)) { 250 return { 251 nrpCount: currentNrp, cycle, 252 fields: { 253 ...common, 254 status: "completed", 255 commercial_outcome: terminalStatus, 256 commercial_notes: appendNote(resource.commercial_notes, notes),