|
|
@@ -31,39 +31,22 @@ else {
|
|
|
|
|
|
$core->addBreadcrumb($_SERVER["REQUEST_URI"], $title);
|
|
|
|
|
|
-$address = $customer->getAddress();
|
|
|
-
|
|
|
$request = Request::fromPost();
|
|
|
|
|
|
$submit = $request->int("submit");
|
|
|
if($submit) {
|
|
|
-
|
|
|
try {
|
|
|
$user->requireValidCsrfToken();
|
|
|
|
|
|
- $customer->name = $request->string("name");
|
|
|
- $customer->phone = $request->string("phone");
|
|
|
- $customer->fax = $request->string("fax");
|
|
|
- $customer->email = $request->email("email");
|
|
|
- $customer->vat_number = $request->string("vat_number");
|
|
|
-
|
|
|
- $address->address_1 = $request->string("address_1");
|
|
|
- $address->address_2 = $request->string("address_2");
|
|
|
- $address->city = $request->string("city");
|
|
|
- $address->county = $request->string("county");
|
|
|
- $address->postal_code = $request->string("postal_code");
|
|
|
- $address->country = $request->string("country");
|
|
|
- $address->latitude = $request->float("latitude");
|
|
|
- $address->longitude = $request->float("longitude");
|
|
|
-
|
|
|
- if(!$customer->name) {
|
|
|
- throw new RuntimeException(__("Name is required."));
|
|
|
- }
|
|
|
+ $customer = Customer::updateFromRequest($request, $customer);
|
|
|
|
|
|
- $address->commit();
|
|
|
+ $create_location = $request->int("create_location");
|
|
|
+ if($create_location) {
|
|
|
+ $location = new Location();
|
|
|
|
|
|
- $customer->address_id = $address->id;
|
|
|
- $customer->commit();
|
|
|
+ $location->dts_created = Database::dts();
|
|
|
+ Location::updateFromRequest($request, $location, $customer);
|
|
|
+ }
|
|
|
|
|
|
Session::addAlert("success", __("Customer saved successfully."));
|
|
|
Http::redirect($customer->getUrl());
|
|
|
@@ -73,10 +56,12 @@ if($submit) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+$core->addScript("/js/entity-form.js");
|
|
|
+
|
|
|
View::include("header");
|
|
|
View::include("entity_form", [
|
|
|
"title" => $title,
|
|
|
"model" => $customer,
|
|
|
- "address" => $address
|
|
|
+ "address" => $customer->getAddress()
|
|
|
]);
|
|
|
View::include("footer");
|