customer_ajax.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php /** @noinspection PhpUnhandledExceptionInspection */
  2. /**
  3. * @var int $id
  4. * @var string $action
  5. */
  6. use Helpers\LocationHelper;
  7. JSON::header();
  8. $customer = Customer::get($id);
  9. if(!$customer) JSON::fail("Customer not found.");
  10. if(!Core::$user->hasPermission($customer)) throw new Exception(__("No permission."));
  11. switch($action) {
  12. case "get-locations":
  13. $nvp = [
  14. "customer_id" => $customer->id,
  15. "archived" => 0,
  16. "closed" => 0
  17. ];
  18. $id = http::value("id", "int");
  19. $internal_id = http::value("internal_id", "trim");
  20. $name = http::value("name", "trim");
  21. $legal_entity_name = http::value("legal_entity_name", "trim");
  22. $include_archived = http::value("include_archived", "int");
  23. $include_closed = http::value("include_closed", "int");
  24. $min_date = http::value("min_date");
  25. $max_date = http::value("max_date");
  26. if($id) $nvp["id"] = $id;
  27. if($internal_id) $nvp["internal_id"] = db::escape($internal_id);
  28. if($name) $nvp["name"] = Constraint::contains($name);
  29. if($legal_entity_name) $nvp["$legal_entity_name"] = Constraint::contains($legal_entity_name);
  30. if($include_archived) unset($nvp["archived"]);
  31. if($include_closed) unset($nvp["closed"]);
  32. $locations = Location::query($nvp, ["sort" => "name", "order" => "asc"]);
  33. $output = LocationHelper::getMarkerDataForLocations($locations, $min_date, $max_date);
  34. JSON::success([
  35. "locations" => $output
  36. ]);
  37. break;
  38. }