customer_ajax.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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) {
  11. JSON::fail("Customer not found.");
  12. }
  13. $user = Core::$user;
  14. if(!$user->hasPermission($customer)) {
  15. throw new RuntimeException(__("No permission."));
  16. }
  17. switch($action) {
  18. case "get-locations":
  19. $search = new LocationSearch($customer, $user);
  20. $id = http::value("id", "int");
  21. $internal_id = http::value("internal_id", "trim");
  22. $name = http::value("name", "trim");
  23. $legal_entity_name = http::value("legal_entity_name", "trim");
  24. $include_archived = http::value("include_archived", "int");
  25. $include_closed = http::value("include_closed", "int");
  26. $min_date = http::value("min_date");
  27. $max_date = http::value("max_date");
  28. $filter = http::value("filter");
  29. $search->setId($id);
  30. $search->setInternalId($internal_id);
  31. $search->setName($name);
  32. $search->setLegalEntityName($legal_entity_name);
  33. $search->setIncludeArchived((bool) $include_archived);
  34. $search->setIncludeClosed((bool) $include_closed);
  35. $search->setMinTestDate($min_date);
  36. $search->setMaxTestDate($max_date);
  37. $search->setFilter($filter);
  38. $locations = $search->run();
  39. $output = LocationHelper::getMarkerDataForLocations($locations, $min_date, $max_date, ["user" => $user]);
  40. JSON::success([
  41. "locations" => $output
  42. ]);
  43. break;
  44. }