|
|
@@ -13,6 +13,7 @@ use RuntimeException;
|
|
|
* @property int $id
|
|
|
* @property int $customer_id
|
|
|
* @property int $address_id
|
|
|
+ * @property int $billing_entity_id
|
|
|
* @property string $name
|
|
|
* @property string $nickname
|
|
|
* @property string $phone
|
|
|
@@ -28,7 +29,7 @@ class Location extends Model {
|
|
|
protected static $table = "location";
|
|
|
protected static $idField = "id";
|
|
|
protected static $fillableFields = [
|
|
|
- "customer_id", "address_id",
|
|
|
+ "customer_id", "address_id", "billing_entity_id",
|
|
|
"name", "nickname", "phone", "fax", "email",
|
|
|
"contact_name", "contact_phone", "contact_email",
|
|
|
"dts_created", "dts_updated", "dts_deleted"
|
|
|
@@ -68,6 +69,18 @@ class Location extends Model {
|
|
|
$customer = Customer::require($customer_id);
|
|
|
}
|
|
|
|
|
|
+ $billing_entity_id = $request->int("billing_entity_id");
|
|
|
+ if($billing_entity_id) {
|
|
|
+ $billing_entity = CustomerEntity::require($billing_entity_id);
|
|
|
+ if(!$billing_entity->belongsToCustomer($customer)) {
|
|
|
+ throw new RuntimeException(__("The billing entity does not belong to the selected customer."));
|
|
|
+ }
|
|
|
+ $location->billing_entity_id = $billing_entity_id;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ $location->billing_entity_id = null;
|
|
|
+ }
|
|
|
+
|
|
|
$location->customer_id = $customer->id;
|
|
|
$location->name = $request->string("name");
|
|
|
$location->nickname = $request->string("nickname");
|
|
|
@@ -123,6 +136,14 @@ class Location extends Model {
|
|
|
return $address ?: new Address();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @return CustomerEntity|null
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ public function getBillingEntity(): ?CustomerEntity {
|
|
|
+ return CustomerEntity::get($this->billing_entity_id);
|
|
|
+ }
|
|
|
+
|
|
|
public function getSlug(): string {
|
|
|
return Util::slug("$this->name $this->id");
|
|
|
}
|