1
0

customer_ajax.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php /** @noinspection PhpUnhandledExceptionInspection */
  2. /**
  3. * @var int $id
  4. * @var string $action
  5. */
  6. use Helpers\LocationHelper;
  7. use Searches\LocationSearch;
  8. JSON::header();
  9. $customer = Customer::get($id);
  10. if(!$customer) JSON::fail("Customer not found.");
  11. if(!Core::$user->hasPermission($customer)) throw new Exception(__("No permission."));
  12. switch($action) {
  13. case "get-locations":
  14. $search = new LocationSearch($customer);
  15. $id = http::value("id", "int");
  16. $internal_id = http::value("internal_id", "trim");
  17. $name = http::value("name", "trim");
  18. $legal_entity_name = http::value("legal_entity_name", "trim");
  19. $include_archived = http::value("include_archived", "int");
  20. $include_closed = http::value("include_closed", "int");
  21. $min_date = http::value("min_date");
  22. $max_date = http::value("max_date");
  23. $filter = http::value("filter");
  24. $search->setId($id);
  25. $search->setInternalId($internal_id);
  26. $search->setName($name);
  27. $search->setLegalEntityName($legal_entity_name);
  28. $search->setIncludeArchived((bool) $include_archived);
  29. $search->setIncludeClosed((bool) $include_closed);
  30. $search->setMinTestDate($min_date);
  31. $search->setMaxTestDate($max_date);
  32. $search->setFilter($filter);
  33. $locations = $search->run();
  34. $output = LocationHelper::getMarkerDataForLocations($locations, $min_date, $max_date);
  35. JSON::success([
  36. "locations" => $output
  37. ]);
  38. break;
  39. }