| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- <?php
- namespace App;
- /**
- * Class Company
- * @property int $id
- * @property int $address_id
- * @property string $name
- * @property string $phone
- * @property string $fax
- * @property string $email
- * @property string $company_number
- * @property string $vat_number
- * @property string $invoice_footer
- * @property string $dts_created
- * @property string $dts_updated
- * @property string $dts_deleted
- */
- class Company extends Model {
- protected static $table = "company";
- protected static $idField = "id";
- protected static $fillableFields = [
- "address_id",
- "name", "phone", "fax", "email",
- "company_number", "vat_number", "invoice_footer",
- "dts_created", "dts_updated", "dts_deleted"
- ];
- // Static methods
- /**
- * @return Company[]
- */
- public static function getAll(): array {
- return self::query([], ["sort" => "name"]);
- }
- public static function getOptions(): array {
- $options = [];
- foreach(self::getAll() as $company) {
- $options[$company->id] = $company->name;
- }
- return $options;
- }
- // Object methods
- /**
- * @return Address
- * @throws \Exception
- */
- public function getAddress(): Address {
- $address = Address::get($this->address_id);
- return $address ?: new Address();
- }
- public function getSlug(): string {
- return Util::slug("$this->name $this->id");
- }
- public function getUrl(): string {
- return sprintf("/companies/%s", $this->getSlug());
- }
- /**
- * @return CompanyBankDetails
- */
- public function getBankDetailsForCurrency(string $currency): CompanyBankDetails {
- $details = CompanyBankDetails::queryOne(["company_id" => $this->id, "currency" => $currency]);
- if(!$details) {
- $details = new CompanyBankDetails();
- $details->company_id = $this->id;
- $details->currency = $currency;
- $details->dts_created = Database::dts();
- }
- return $details;
- }
- public function getInvoiceFooterHtml(): string {
- return nl2br(htmlspecialchars($this->invoice_footer));
- }
- }
|