use Cubedesigners\UserDatabase\Jobs\ApplyPermissionsToUsers;
use Cubedesigners\UserDatabase\Permissions;
use Cubedesigners\UserDatabase\SubForms\Address;
+use Cubedesigners\UserDatabase\SubForms\AddressAndCompanyName;
use Cubist\Backpack\Magic\Fields\Checkbox;
+use Cubist\Backpack\Magic\Fields\Hidden;
use Cubist\Backpack\Magic\Fields\Integer;
-use Cubist\Backpack\Magic\Fields\Range;
use Cubist\Backpack\Magic\Fields\Text;
use Cubist\Backpack\Magic\Models\CubistMagicAbstractModel;
+use Cubist\Locale\Country;
use Illuminate\Database\Eloquent\Builder;
class Company extends CubistMagicAbstractModel
$this->addField(['name' => 'billing_address',
'type' => 'BunchOfFields',
- 'bunch' => Address::class,
+ 'bunch' => AddressAndCompanyName::class,
'label' => __('Adresse de facturation'),
+ 'hint' => __('Ne remplir que les champs qui diffèrent de l\'adresse indiquée ci-dessus'),
'tab' => __('Adresses')]);
+ $this->addField('c_billing_address', Hidden::class);
$this->addField([
'name' => 'users',
'read_only' => true]);
}
-
$this->addField(['name' => 'c_unpaid',
'label' => __('Impayés'),
'type' => Integer::class,
return $res;
}
+ public function onSaving(): bool
+ {
+ $this->setComposedAttributes();
+ return parent::onSaving();
+ }
+
public function onSaved(): bool
{
ApplyPermissionsToUsers::dispatch();
return parent::onSaved();
}
+
+ protected function setComposedAttributes()
+ {
+ $billingAddress = ($this->billing_address['name'] ?: $this->name) . "\n";
+ $billingAddress .= ($this->billing_address['address'] ?: $this->address['address']) . "\n";
+ $billingAddress .= ($this->billing_address['postcode'] ?: $this->address['postcode']) . ' ' . ($this->billing_address['city'] ?: $this->address['city']) . "\n";
+ $country = ($this->billing_address['country'] ?: $this->address['country']);
+ if ($country !== 'FR') {
+ $billingAddress .= Country::translate($country, 'en');
+ }
+ $this->c_billing_address = trim($billingAddress);
+ }
}