| 1 | //! Verzonnen kaarten voor `--demo` (geen echte BC-gegevens, geen echte personen). |
| 2 | |
| 3 | use kvt_sleutels::links::bc_url; |
| 4 | use kvt_sleutels::{ |
| 5 | Card, CardField, CardKind, CardLinks, CardRef, FieldRef, SearchResult, StoredToken, |
| 6 | }; |
| 7 | |
| 8 | use super::DEFAULT_COMPANY as COMPANY; |
| 9 | |
| 10 | pub(super) fn token() -> StoredToken { |
| 11 | StoredToken { |
| 12 | token: String::new(), |
| 13 | expires_at: i64::MAX, |
| 14 | email: "dana.demo@example.com".to_owned(), |
| 15 | name: "Dana Demo".to_owned(), |
| 16 | } |
| 17 | } |
| 18 | |
| 19 | pub(super) fn companies() -> Vec<String> { |
| 20 | vec![COMPANY.to_owned(), "KVT Germany".to_owned()] |
| 21 | } |
| 22 | |
| 23 | fn field(key: &str, label: &str, value: &str) -> CardField { |
| 24 | CardField { |
| 25 | key: key.to_owned(), |
| 26 | label: label.to_owned(), |
| 27 | value: value.to_owned(), |
| 28 | date: None, |
| 29 | reference: None, |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | fn reference(key: &str, label: &str, kind: CardKind, company: &str, no: &str) -> CardField { |
| 34 | CardField { |
| 35 | reference: Some(FieldRef { |
| 36 | kind: kind.api_name().to_owned(), |
| 37 | no: no.to_owned(), |
| 38 | bc_url: bc_url(kind, company, no, None), |
| 39 | }), |
| 40 | ..field(key, label, no) |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | struct Entry { |
| 45 | kind: CardKind, |
| 46 | no: &'static str, |
| 47 | title: &'static str, |
| 48 | subtitle: &'static str, |
| 49 | } |
| 50 | |
| 51 | const ENTRIES: [Entry; 8] = [ |
| 52 | Entry { |
| 53 | kind: CardKind::Werkorder, |
| 54 | no: "WO2699001", |
| 55 | title: "Onderhoud 500 uur", |
| 56 | subtitle: "MS Voorbeeld", |
| 57 | }, |
| 58 | Entry { |
| 59 | kind: CardKind::Werkorder, |
| 60 | no: "WO2699002", |
| 61 | title: "Inspectie generator", |
| 62 | subtitle: "Pontveer Demo", |
| 63 | }, |
| 64 | Entry { |
| 65 | kind: CardKind::Project, |
| 66 | no: "PRJ2699001", |
| 67 | title: "Nieuwbouw aandrijving", |
| 68 | subtitle: "Rederij Voorbeeld", |
| 69 | }, |
| 70 | Entry { |
| 71 | kind: CardKind::Project, |
| 72 | no: "PRJ2699002", |
| 73 | title: "Retrofit noodstroom", |
| 74 | subtitle: "Haven Demo", |
| 75 | }, |
| 76 | Entry { |
| 77 | kind: CardKind::Contract, |
| 78 | no: "CT2699001", |
| 79 | title: "Onderhoudscontract vloot", |
| 80 | subtitle: "Rederij Voorbeeld", |
| 81 | }, |
| 82 | Entry { |
| 83 | kind: CardKind::Klant, |
| 84 | no: "269901", |
| 85 | title: "Rederij Voorbeeld", |
| 86 | subtitle: "Rotterdam", |
| 87 | }, |
| 88 | Entry { |
| 89 | kind: CardKind::Component, |
| 90 | no: "COM2699001", |
| 91 | title: "Hoofdmotor bakboord", |
| 92 | subtitle: "MS Voorbeeld", |
| 93 | }, |
| 94 | Entry { |
| 95 | kind: CardKind::Artikel, |
| 96 | no: "2699001", |
| 97 | title: "Brandstoffilter 12 µm", |
| 98 | subtitle: "Filters", |
| 99 | }, |
| 100 | ]; |
| 101 | |
| 102 | pub(super) fn card(reference_to: &CardRef) -> Option<Card> { |
| 103 | let entry = ENTRIES |
| 104 | .iter() |
| 105 | .find(|entry| entry.kind == reference_to.kind && entry.no == reference_to.no)?; |
| 106 | let company = reference_to.company.as_str(); |
| 107 | let fields = match entry.kind { |
| 108 | CardKind::Werkorder => vec![ |
| 109 | field("Main_Entity_Description", "Object", entry.subtitle), |
| 110 | field("Sell_to_Name", "Klant", "Rederij Voorbeeld"), |
| 111 | field("Component_Description", "Component", "Hoofdmotor"), |
| 112 | field("Task_Code", "Taakcode", "OH-500"), |
| 113 | field("Status", "Status", "Gepland"), |
| 114 | field("Start_Date", "Begindatum", "15 jan 2026"), |
| 115 | field("End_Date", "Einddatum", "16 jan 2026"), |
| 116 | field("Resource_Name", "Monteur", "Mara Lindqvist"), |
| 117 | field( |
| 118 | "KVT_Service_Coordinator", |
| 119 | "Servicecoördinator", |
| 120 | "Jonas Ortega", |
| 121 | ), |
| 122 | reference( |
| 123 | "Job_No", |
| 124 | "Project", |
| 125 | CardKind::Project, |
| 126 | company, |
| 127 | "PRJ2699001", |
| 128 | ), |
| 129 | reference( |
| 130 | "Contract_No", |
| 131 | "Contract", |
| 132 | CardKind::Contract, |
| 133 | company, |
| 134 | "CT2699001", |
| 135 | ), |
| 136 | ], |
| 137 | CardKind::Project => vec![ |
| 138 | field("Sell_to_Customer_Name", "Klant", entry.subtitle), |
| 139 | field("Status", "Status", "Open"), |
| 140 | field("Starting_Date", "Begindatum", "2 feb 2026"), |
| 141 | field("Ending_Date", "Einddatum", "30 jun 2026"), |
| 142 | field("Project_Manager", "Projectleider", "Priya Nair"), |
| 143 | reference( |
| 144 | "KVT_Contract_No", |
| 145 | "Contract", |
| 146 | CardKind::Contract, |
| 147 | company, |
| 148 | "CT2699001", |
| 149 | ), |
| 150 | ], |
| 151 | CardKind::Contract => vec![ |
| 152 | field("Name", "Klant", entry.subtitle), |
| 153 | field("Contract_Type", "Soort", "Onderhoud"), |
| 154 | field("Document_Status", "Status", "Getekend"), |
| 155 | field("Starting_Date", "Begindatum", "1 jan 2026"), |
| 156 | field("End_Date", "Einddatum", "31 dec 2028"), |
| 157 | field( |
| 158 | "KVT_Service_Coordinator", |
| 159 | "Servicecoördinator", |
| 160 | "Jonas Ortega", |
| 161 | ), |
| 162 | ], |
| 163 | CardKind::Klant => vec![ |
| 164 | field("City", "Plaats", entry.subtitle), |
| 165 | field("Country_Region_Code", "Land", "NL"), |
| 166 | field("Salesperson_Code", "Verkoper", "DEMO"), |
| 167 | field("Service_Zone_Code", "Servicezone", "ZUID"), |
| 168 | ], |
| 169 | CardKind::Component => vec![ |
| 170 | field("Main_Entity_Description", "Object", entry.subtitle), |
| 171 | field("Serial_No", "Serienummer", "SN-DEMO-0001"), |
| 172 | reference( |
| 173 | "Sell_to_Customer_No", |
| 174 | "Klant", |
| 175 | CardKind::Klant, |
| 176 | company, |
| 177 | "269901", |
| 178 | ), |
| 179 | field("Manufacturer_Code", "Fabrikant", "DEMO"), |
| 180 | reference( |
| 181 | "Part_Item_No", |
| 182 | "Artikel", |
| 183 | CardKind::Artikel, |
| 184 | company, |
| 185 | "2699001", |
| 186 | ), |
| 187 | ], |
| 188 | CardKind::Artikel => vec![ |
| 189 | field("Item_Category_Code", "Categorie", entry.subtitle), |
| 190 | field("Base_Unit_of_Measure", "Eenheid", "STUK"), |
| 191 | field("LVS_Manufacturer_Code", "Fabrikant", "DEMO"), |
| 192 | field("Inventory", "Voorraad", "12"), |
| 193 | ], |
| 194 | }; |
| 195 | Some(Card { |
| 196 | kind: entry.kind.api_name().to_owned(), |
| 197 | type_label: entry.kind.label_nl().to_owned(), |
| 198 | company: company.to_owned(), |
| 199 | no: entry.no.to_owned(), |
| 200 | title: entry.title.to_owned(), |
| 201 | subtitle: entry.subtitle.to_owned(), |
| 202 | fields, |
| 203 | links: CardLinks { |
| 204 | bc: bc_url(entry.kind, company, entry.no, None), |
| 205 | daedalus: (entry.kind == CardKind::Werkorder).then(|| { |
| 206 | format!( |
| 207 | "https://sleutels.kvt.nl/daedalus/index.php?workorder={}", |
| 208 | entry.no |
| 209 | ) |
| 210 | }), |
| 211 | }, |
| 212 | }) |
| 213 | } |
| 214 | |
| 215 | pub(super) fn search(kind: CardKind, company: &str, query: &str) -> Vec<SearchResult> { |
| 216 | let query = query.trim().to_lowercase(); |
| 217 | ENTRIES |
| 218 | .iter() |
| 219 | .filter(|entry| entry.kind == kind) |
| 220 | .filter(|entry| { |
| 221 | entry.no.to_lowercase().contains(&query) || entry.title.to_lowercase().contains(&query) |
| 222 | }) |
| 223 | .map(|entry| SearchResult { |
| 224 | kind: kind.api_name().to_owned(), |
| 225 | company: company.to_owned(), |
| 226 | no: entry.no.to_owned(), |
| 227 | title: entry.title.to_owned(), |
| 228 | subtitle: entry.subtitle.to_owned(), |
| 229 | bc_url: bc_url(kind, company, entry.no, None), |
| 230 | }) |
| 231 | .collect() |
| 232 | } |
| 233 | |
| 234 | pub(super) fn ponos_groups() -> Vec<kvt_sleutels::ponos::PonosGroup> { |
| 235 | ["ICT", "Service Noord", "Werkplaats"] |
| 236 | .into_iter() |
| 237 | .enumerate() |
| 238 | .map(|(index, name)| kvt_sleutels::ponos::PonosGroup { |
| 239 | id: format!("demo-group-{index}"), |
| 240 | name: name.to_owned(), |
| 241 | is_virtual: false, |
| 242 | can_create_tasks: true, |
| 243 | has_task_access: true, |
| 244 | }) |
| 245 | .collect() |
| 246 | } |
| 247 | |
| 248 | pub(super) fn my_tasks() -> Vec<kvt_sleutels::ponos::PonosTask> { |
| 249 | let today = chrono::Local::now().date_naive(); |
| 250 | let task = |id: &str, group: &str, title: &str, status: &str, due: Option<i64>| { |
| 251 | kvt_sleutels::ponos::PonosTask { |
| 252 | id: id.to_owned(), |
| 253 | group_id: "demo-group-0".to_owned(), |
| 254 | home_group_id: "demo-group-0".to_owned(), |
| 255 | home_group_name: group.to_owned(), |
| 256 | title: title.to_owned(), |
| 257 | status: status.to_owned(), |
| 258 | due_date: due |
| 259 | .map(|days| { |
| 260 | (today + chrono::Duration::days(days)) |
| 261 | .format("%Y-%m-%d") |
| 262 | .to_string() |
| 263 | }) |
| 264 | .unwrap_or_default(), |
| 265 | } |
| 266 | }; |
| 267 | kvt_sleutels::ponos::sort_open(vec![ |
| 268 | task( |
| 269 | "demo-task-1", |
| 270 | "ICT", |
| 271 | "Laptop klaarzetten voor nieuwe collega", |
| 272 | "todo", |
| 273 | Some(-1), |
| 274 | ), |
| 275 | task( |
| 276 | "demo-task-2", |
| 277 | "Service Noord", |
| 278 | "Rapport WO2699001 nakijken", |
| 279 | "in_progress", |
| 280 | Some(2), |
| 281 | ), |
| 282 | task( |
| 283 | "demo-task-3", |
| 284 | "Werkplaats", |
| 285 | "Brandstoffilters bestellen", |
| 286 | "todo", |
| 287 | Some(9), |
| 288 | ), |
| 289 | task( |
| 290 | "demo-task-4", |
| 291 | "ICT", |
| 292 | "Printer receptie controleren", |
| 293 | "todo", |
| 294 | None, |
| 295 | ), |
| 296 | ]) |
| 297 | } |
| 298 | |
| 299 | /// Twee verzonnen werkorders in de zichtbare periode. |
| 300 | pub(super) fn planning( |
| 301 | from: chrono::DateTime<chrono::Utc>, |
| 302 | to: chrono::DateTime<chrono::Utc>, |
| 303 | ) -> Vec<chatsvc::CalendarEvent> { |
| 304 | use chrono::Duration; |
| 305 | let day = |offset: i64| { |
| 306 | (from.with_timezone(&chrono::Local).date_naive() + Duration::days(offset)) |
| 307 | .format("%Y-%m-%d") |
| 308 | .to_string() |
| 309 | }; |
| 310 | let at = |offset: i64, hour: u32| { |
| 311 | let date = from.with_timezone(&chrono::Local).date_naive() + Duration::days(offset); |
| 312 | date.and_hms_opt(hour, 0, 0) |
| 313 | .and_then(|moment| moment.and_local_timezone(chrono::Local).single()) |
| 314 | .map(|moment| moment.to_rfc3339()) |
| 315 | .unwrap_or_default() |
| 316 | }; |
| 317 | let event = |no: &str, title: &str, object: &str, all_day: bool, start: String, end: String| { |
| 318 | kvt_sleutels::planning::PlanningEvent { |
| 319 | id: format!("{no}@{COMPANY}"), |
| 320 | workorder: no.to_owned(), |
| 321 | company: COMPANY.to_owned(), |
| 322 | title: format!("{no} · {title}"), |
| 323 | object: object.to_owned(), |
| 324 | component: "Hoofdmotor".to_owned(), |
| 325 | status: "Gepland".to_owned(), |
| 326 | all_day, |
| 327 | start, |
| 328 | end, |
| 329 | url: format!("https://sleutels.kvt.nl/daedalus/index.php?workorder={no}"), |
| 330 | } |
| 331 | }; |
| 332 | [ |
| 333 | event( |
| 334 | "WO2699001", |
| 335 | "Onderhoud 500 uur", |
| 336 | "MS Voorbeeld", |
| 337 | true, |
| 338 | day(1), |
| 339 | day(3), |
| 340 | ), |
| 341 | event( |
| 342 | "WO2699002", |
| 343 | "Inspectie generator", |
| 344 | "Pontveer Demo", |
| 345 | false, |
| 346 | at(3, 8), |
| 347 | at(3, 12), |
| 348 | ), |
| 349 | ] |
| 350 | .iter() |
| 351 | .filter_map(super::calendar::calendar_event) |
| 352 | .filter(|event| event.end > from && event.start < to) |
| 353 | .collect() |
| 354 | } |