| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471 |
- <?php /** @noinspection PhpUnhandledExceptionInspection */
- /**
- * @var Project $project
- * @var Template[] $templates
- * @var Customer $customer
- * @var int[] $location_ids
- * @var Location[] $locations
- * @var Template $template
- */
- $user = Core::$user;
- // Get test counts for current year cycle
- $tests = Test::query([
- "status" => Constraint::notEquals(Test::STATUS_CANCELLED),
- "location_id" => array_column($locations, "id"),
- "dts_start" => $customer->getYearCycleConstraint(TIMEZONE),
- ]);
- $test_counts = [];
- foreach($tests as $test) {
- if(!isset($test_counts[$test->location_id])) {
- $test_counts[$test->location_id] = 0;
- }
- if($test->isCompleted()) {
- $test_counts[$test->location_id]++;
- }
- }
- $latest_tests = $customer->getLatestTestByLocation();
- $dt_start = $project->getDateTimeStart();
- $dt_deadline = $project->getDateTimeDeadline();
- $dt_report = $project->getDateTimeReport() ?: null;
- $date_report = $dt_report ? $dt_report->format("Y-m-d") : "";
- $date_invoice = $project->invoice_date;
- $name_readonly = $project->id ? "" : "readonly";
- $autogen_checked = $project->id ? "" : "checked";
- // Figure out which locations are selected
- $tests = [];
- $location_test = [];
- if($project->id) {
- $tests = $project->getTests();
- foreach($tests as $test) {
- $location_test[$test->location_id] = $test;
- }
- }
- $selected_locations = array_filter($locations, static function(Location $l) use ($location_ids) { return in_array($l->id, $location_ids, false); });
- $deselected_locations = array_filter($locations, static function(Location $l) use ($location_ids) { return !in_array($l->id, $location_ids, false); });
- /**
- * @param Location[] $locations
- * @param bool $selected
- * @return void
- */
- $output_locations = static function(array $locations, bool $selected) use ($location_test, $test_counts, $customer, $latest_tests, $user) {
- foreach($locations as $location) {
- $address = $location->getDisplayAddress(["address_1", "address_2", "city", "postal_code"]);
- $filter_parts = array_filter([
- $address, $location->name
- ]);
- $filter = strtolower(implode("", $filter_parts));
- $button_class = $selected ? "danger" : "success";
- $button_text = $selected ? "Deselect" : "Select";
- $icon = $selected ? "times" : "check";
- $test = $location_test[$location->id] ?? null;
- $test_status = $test_class = "";
- if($test) {
- $test_status = $test->getStatusText();
- $test_class = $test->getStatusClass();
- }
- ?>
- <div class="list-group-item" data-location-id="<?=$location->id?>" data-internal-id="<?=htmlspecialchars($location->internal_id)?>" data-name="<?=htmlspecialchars($location->name)?>" data-filter-value="<?=htmlspecialchars($filter)?>">
- <div class="row no-gutters">
- <div class="col-2 text-right">
- <?=$location->id?>
- </div>
- <div class="col hover-container px-3">
- <a href="/account/locations/<?=$location->id?>" target="_blank"><?=htmlspecialchars($location->name)?></a>
- <a class="visible-on-hover float-right" href="/account/locations/<?=$location->id?>/edit" target="_blank"><i class="fal fa-pencil"></i> Edit</a>
- <div>
- <?php
- if($test) {
- ?>
- <div class="badge badge-<?=$test_class?>">
- <?=htmlspecialchars($test_status)?>
- </div>
- <?php
- }
- if($location->internal_id) {
- ?>
- <span class="badge badge-primary">Internal ID: <?=htmlspecialchars($location->internal_id)?></span>
- <?php
- }
- ?>
- </div>
- <small><?=htmlspecialchars($address)?></small><br />
- <small>
- <strong>Last Test:</strong>
- <?php
- $test = $latest_tests[$location->id] ?? null;
- if($test) {
- $test->renderTestStatus($user);
- }
- else {
- ?>
- None
- <?php
- }
- ?>
- </small><br />
- <small title="<?=htmlspecialchars(__("Number of tests completed between %s", $customer->getDisplayYearCycle()))?>">
- <strong>Completed:</strong>
- <?=htmlspecialchars(sprintf("%d / %d", $test_counts[$location->id] ?? 0, $location->annual_test_count))?>
- </small>
- </div>
- <div class="col-auto align-self-center text-right">
- <button class="btn btn-outline-<?=$button_class?>" type="button">
- <i class="fas fa-<?=$icon?>"></i>
- <span class="sr-only"><?=htmlspecialchars($button_text)?></span>
- </button>
- </div>
- </div>
- </div>
- <?php
- }
- }
- ?>
- <div class="container mt-3 py-4">
- <h2>
- <?=($project->id ? "Edit" : "Add")?>
- Project for <span id="customer-name"><?=htmlspecialchars($customer->name)?></span>
- </h2>
- <input type="hidden" id="project-id" value="<?=$project->id?>" />
- <input type="hidden" id="initial-template-keys" value="<?=htmlspecialchars(json_encode($project->getTemplateKeys()))?>" />
- <form method="post" id="project-form">
- <h3>Project Details</h3>
- <div class="row">
- <div class="col-lg">
- <div class="row mb-1">
- <label class="col-sm-4 col-form-label" for="name">Name</label>
- <div class="col-sm">
- <input class="form-control" type="text" name="name" id="name" placeholder="Enter name" value="<?=htmlspecialchars($project->name)?>" required <?=$name_readonly?> />
- <div class="custom-control custom-switch">
- <input type="checkbox" class="custom-control-input" id="autogen-name" <?=$autogen_checked?> />
- <label class="custom-control-label" for="autogen-name">Auto-fill name</label>
- </div>
- </div>
- </div>
- <div class="row mb-1">
- <label class="col-sm-4 col-form-label" for="template-id">Template</label>
- <div class="col-sm">
- <select class="form-control" name="template_id" id="template-id" required>
- <?php
- foreach($templates as $template) {
- $selected = ((int) $template->id === (int) $project->template_id) ? "selected" : "";
- $keys = $template->getTemplateKeys();
- $keys_json = json_encode($keys);
- ?>
- <option value="<?=$template->id?>" data-keys="<?=htmlspecialchars($keys_json)?>" <?=$selected?>>
- <?=htmlspecialchars($template->name)?>
- </option>
- <?php
- }
- ?>
- </select>
- </div>
- </div>
- <div id="template-extra-fields-row" class="row mb-1 collapse">
- <div class="col-sm-4"></div>
- <div id="template-extra-fields-container" class="col-sm">
- </div>
- </div>
- <div class="row mb-1">
- <label class="col-sm-4 col-form-label" for="test-count">Test Count</label>
- <div class="col-sm">
- <input class="form-control" type="number" name="test_count" id="test-count" placeholder="Enter test count" value="<?=htmlspecialchars($project->test_count)?>" required />
- </div>
- </div>
- <div class="row mb-1">
- <label class="col-sm-4 col-form-label" for="default-customer-fee">Default Customer Fee</label>
- <div class="col-sm">
- <div class="input-group">
- <div class="input-group-prepend">
- <span class="input-group-text">£</span>
- </div>
- <input class="form-control" type="number" name="default_customer_fee" min=0" max="999.99" step="0.01" id="default-customer-fee" placeholder="Enter default customer fee" value="<?=htmlspecialchars($project->default_customer_fee)?>" required />
- </div>
- </div>
- </div>
- <div class="row mb-1">
- <label class="col-sm-4 col-form-label" for="default-retest-fee">Default Retest Fee</label>
- <div class="col-sm">
- <div class="input-group">
- <div class="input-group-prepend">
- <span class="input-group-text">£</span>
- </div>
- <input class="form-control" type="number" name="default_retest_fee" min=0" max="999.99" step="0.01" id="default-retest-fee" placeholder="Enter default retest fee" value="<?=htmlspecialchars($project->default_retest_fee)?>" />
- </div>
- </div>
- </div>
- <div class="row mb-1">
- <label class="col-sm-4 col-form-label" for="default-tester-fee">Default Tester Fee</label>
- <div class="col-sm">
- <div class="input-group">
- <div class="input-group-prepend">
- <span class="input-group-text">£</span>
- </div>
- <input class="form-control" type="number" name="default_tester_fee" min="0" max="999.99" step="0.01" id="default-tester-fee" placeholder="Enter default tester fee" value="<?=htmlspecialchars($project->default_tester_fee)?>" required />
- </div>
- </div>
- </div>
- <div class="row mb-1">
- <label class="col-sm-4 col-form-label" for="time-of-day">Time of Day</label>
- <div class="col-sm">
- <select class="form-control" name="time_of_day" id="time-of-day" required>
- <?php
- foreach(Project::getTimeOfDayOptions() as $value => $display) {
- $selected = ($value === $project->time_of_day) ? "selected" : "";
- ?>
- <option value="<?=$value?>" <?=$selected?>><?=htmlspecialchars($display)?></option>
- <?php
- }
- ?>
- </select>
- </div>
- </div>
- <div class="row mb-1">
- <label class="col-sm-4 col-form-label" for="tester-can-claim">Tester Can Claim</label>
- <div class="col-sm">
- <select class="form-control" name="tester_can_claim" id="tester-can-claim">
- <?php
- foreach(Form::BOOLEAN_OPTIONS as $value => $display) {
- $selected = ($value === (int) $project->tester_can_claim) ? "selected" : "";
- ?>
- <option value="<?=$value?>" <?=$selected?>><?=htmlspecialchars($display)?></option>
- <?php
- }
- ?>
- </select>
- <small class="form-text text-muted">Tests will appear in "Find Tests" for testers.</small>
- </div>
- </div>
- </div>
- <div class="col-lg">
- <div class="row mb-1">
- <label class="col-sm-4 col-form-label" for="min-age">Min. Age</label>
- <div class="col-sm">
- <input class="form-control" type="number" name="min_age" id="min-age" placeholder="Enter minimum age" value="<?=htmlspecialchars($project->min_age)?>" required />
- </div>
- </div>
- <div class="row mb-1">
- <label class="col-sm-4 col-form-label" for="max-age">Max. Age</label>
- <div class="col-sm">
- <input class="form-control" type="number" name="max_age" id="max-age" placeholder="Enter maximum age" value="<?=htmlspecialchars($project->max_age)?>" required />
- </div>
- </div>
- <div class="row mb-1">
- <label class="col-sm-4 col-form-label" for="date-start">Start Date</label>
- <div class="col-sm">
- <input class="form-control" type="date" name="date_start" id="date-start" value="<?=$dt_start->format("Y-m-d")?>" required />
- </div>
- </div>
- <div class="row mb-1">
- <label class="col-sm-4 col-form-label" for="date-deadline">Deadline</label>
- <div class="col-sm">
- <input class="form-control" type="date" name="date_deadline" id="date-deadline" value="<?=$dt_deadline->format("Y-m-d")?>" required />
- </div>
- </div>
- <div class="row mb-1">
- <label class="col-sm-4 col-form-label" for="date-report">Report Month</label>
- <div class="col-sm">
- <input class="form-control" type="date" name="date_report" id="date-report" value="<?=$date_report?>" />
- </div>
- </div>
- <div class="row mb-1">
- <label class="col-sm-4 col-form-label" for="date-invoice">Invoice Date</label>
- <div class="col-sm">
- <input class="form-control" type="date" name="date_invoice" id="date-invoice" value="<?=$date_invoice?>" />
- </div>
- </div>
- <div class="row mb-1">
- <label class="col-sm-4 col-form-label" for="browse-time">Browse Time (Mins)</label>
- <div class="col-sm">
- <input class="form-control" type="number" name="browse_time" id="browse-time" value="<?=$project->browse_time?>" min="0" placeholder="Enter browse time" required />
- </div>
- </div>
- <div class="row mb-1">
- <label class="col-sm-4 col-form-label" for="play-money">Play Money</label>
- <div class="col-sm">
- <input class="form-control" type="number" name="play_money" id="play-money" value="<?=$project->play_money?>" min="0" step="any" placeholder="Enter play money" />
- </div>
- </div>
- <div class="row mb-1">
- <label class="col-sm-4 col-form-label" for="play-time">Play Time (Mins)</label>
- <div class="col-sm">
- <input class="form-control" type="number" name="play_time" id="play-time" value="<?=$project->play_time?>" min="0" placeholder="Enter play time" required />
- </div>
- </div>
- </div>
- </div>
- <?php
- if($project->id) {
- ?>
- <hr />
- <div class="row">
- <div class="col">
- <h3>Template Overrides</h3>
- </div>
- <div class="col-auto">
- <a class="btn btn-outline-primary" href="/account/projects/<?=$project->id?>/edit/template-overrides">Edit</a>
- </div>
- </div>
- <?php
- $overrides = $project->getTemplateOverrides();
- if(empty($overrides)) {
- ?>
- <div class="alert alert-info">There are no template overrides configured for this project.</div>
- <?php
- }
- else {
- $fields = $template->getFields();
- ?>
- <table class="table table-bordered table-hover">
- <thead>
- <tr>
- <th>Field</th>
- <th>Element</th>
- <th>Value</th>
- </tr>
- </thead>
- <tbody>
- <?php
- foreach($overrides as $override) {
- ?>
- <tr>
- <td>
- <?=htmlspecialchars($fields[$override->field]->label)?>
- </td>
- <td>
- <?=ucfirst($override->element)?>
- </td>
- <td>
- <?=htmlspecialchars($override->value)?>
- </td>
- </tr>
- <?php
- }
- ?>
- </tbody>
- </table>
- <?php
- }
- }
- ?>
- <hr />
- <input type="hidden" name="location_ids" id="location-ids" value="<?=implode(", ", $location_ids)?>" />
- <h3>Project Locations</h3>
- <?php
- if($project->id) {
- ?>
- <div class="alert alert-warning">
- <div class="row">
- <div class="col-auto">
- <i class="fal fa-exclamation-triangle"></i>
- </div>
- <div class="col pl-0">
- Please be aware that deselecting a location will cancel the test for the project no matter its current status.<br />
- <strong>This action cannot be undone, you have been warned!</strong>
- </div>
- </div>
- </div>
- <?php
- }
- ?>
- <div class="row">
- <div class="col-md mb-3">
- <h4>Selected</h4>
- <div class="card">
- <div class="card-body">
- <div class="input-group">
- <div class="input-group-prepend">
- <label class="input-group-text" for="selected-filter">
- Filter
- </label>
- </div>
- <input class="form-control" id="selected-filter" type="text" placeholder="Enter name, address, ID or internal ID" data-filter-target="#selected-locations-list-group" />
- </div>
- <div class="alert alert-info mt-3 mb-0" id="selected-locations-alert">
- No locations selected for testing.
- </div>
- </div>
- <div class="list-group list-group-flush limit-height-2" id="selected-locations-list-group">
- <?php
- $output_locations($selected_locations, true);
- ?>
- </div>
- </div>
- </div>
- <div class="col-md mb-3">
- <h4>Not Selected</h4>
- <div class="card">
- <div class="card-body">
- <div class="input-group">
- <div class="input-group-prepend">
- <label class="input-group-text" for="not-selected-filter">
- Filter
- </label>
- </div>
- <input id="not-selected-filter" class="form-control" type="text" placeholder="Enter name, address, ID or internal ID" data-filter-target="#not-selected-locations-list-group" />
- </div>
- <div class="alert alert-info mt-3 mb-0" id="not-selected-locations-alert">
- No additional locations are available for testing.
- </div>
- </div>
- <div class="list-group list-group-flush limit-height-2" id="not-selected-locations-list-group">
- <?php
- $output_locations($deselected_locations, false);
- ?>
- </div>
- </div>
- </div>
- </div>
- <hr />
- <button class="btn btn-primary" type="submit">Submit</button>
- <input type="hidden" name="submit" value="<?=$_SESSION["csrf_token"]?>" />
- </form>
- </div>
|