diff --git a/Admin/Install/db.json b/Admin/Install/db.json index 8145876..d42f4c4 100755 --- a/Admin/Install/db.json +++ b/Admin/Install/db.json @@ -683,7 +683,7 @@ "name": "billing_bill_subscription_pattern_numberofoccurrences", "type": "TINYINT(1)", "null": false - }, + } } }, "billing_bill_responsible": { diff --git a/Models/Bill.php b/Models/Bill.php index 2ff439e..e5536dc 100755 --- a/Models/Bill.php +++ b/Models/Bill.php @@ -398,7 +398,7 @@ class Bill implements \JsonSerializable * @var int * @since 1.0.0 */ - private int $reference = 0; + public int $reference = 0; /** * Media files @@ -452,7 +452,7 @@ class Bill implements \JsonSerializable */ public function buildNumber() : void { - $this->number = \str_replace( + $this->number = \str_replace( [ '{y}', '{m}', @@ -465,7 +465,7 @@ class Bill implements \JsonSerializable $this->createdAt->format('m'), $this->createdAt->format('d'), $this->id, - \is_int($this->type) ? $this->type : $this->type->getId(), + $this->type->getId(), ], $this->numberFormat ); @@ -680,6 +680,10 @@ class Bill implements \JsonSerializable */ public function getMediaByType(int $type = null) : array { + if ($type === null) { + return $this->media; + } + $files = []; foreach ($this->media as $file) { if ($file->type !== null && $file->type->getId() === $type) { diff --git a/Models/PurchaseBillMapper.php b/Models/PurchaseBillMapper.php index f0407c0..433e095 100755 --- a/Models/PurchaseBillMapper.php +++ b/Models/PurchaseBillMapper.php @@ -89,7 +89,7 @@ final class PurchaseBillMapper extends BillMapper ->andWhere(self::TABLE . '.billing_bill_performance_date', '>=', $start) ->andWhere(self::TABLE . '.billing_bill_performance_date', '<=', $end) ->execute() - ->fetch(); + ?->fetch(); return new Money((int) $result[0]); } @@ -106,7 +106,7 @@ final class PurchaseBillMapper extends BillMapper ->andWhere(self::TABLE . '.billing_bill_performance_date', '>=', $start) ->andWhere(self::TABLE . '.billing_bill_performance_date', '<=', $end) ->execute() - ->fetch(); + ?->fetch(); return new Money((int) $result[0]); } @@ -125,7 +125,7 @@ final class PurchaseBillMapper extends BillMapper ->andWhere(self::TABLE . '.billing_bill_performance_date', '>=', $start) ->andWhere(self::TABLE . '.billing_bill_performance_date', '<=', $end) ->execute() - ->fetch(); + ?->fetch(); return new Money($result === false || $result[1] == 0 ? 0 : (int) (((int) $result[0]) / ((int) $result[1]))); } @@ -145,7 +145,7 @@ final class PurchaseBillMapper extends BillMapper ->orderBy('billing_bill_id', 'DESC') ->limit(1) ->execute() - ->fetch(); + ?->fetch(); return $result === false ? null : new \DateTimeImmutable($result[0]); } @@ -163,7 +163,7 @@ final class PurchaseBillMapper extends BillMapper ->orderBy('billing_bill_id', 'DESC') ->limit(1) ->execute() - ->fetch(); + ?->fetch(); return $result === false ? null : new \DateTimeImmutable($result[0]); } @@ -195,6 +195,7 @@ final class PurchaseBillMapper extends BillMapper ->where(BillElementMapper::TABLE . '_d1.billing_bill_element_item', '=', $id) ->limit($limit); + /** @phpstan-ignore-next-line */ if (!empty(self::CREATED_AT)) { $query->orderBy(self::TABLE . '_d1.' . self::COLUMNS[self::CREATED_AT]['name'], 'DESC'); } else { @@ -213,6 +214,7 @@ final class PurchaseBillMapper extends BillMapper $query->where(self::TABLE . '_d1.billing_bill_supplier', '=', $id) ->limit($limit); + /** @phpstan-ignore-next-line */ if (!empty(self::CREATED_AT)) { $query->orderBy(self::TABLE . '_d1.' . self::COLUMNS[self::CREATED_AT]['name'], 'DESC'); } else { @@ -264,9 +266,9 @@ final class PurchaseBillMapper extends BillMapper ->andWhere(self::TABLE . '.billing_bill_performance_date', '<=', $end) ->groupBy(CountryMapper::TABLE . '.country_region') ->execute() - ->fetchAll(\PDO::FETCH_KEY_PAIR); + ?->fetchAll(\PDO::FETCH_KEY_PAIR); - return $result; + return $result ?? []; } /** @@ -289,9 +291,9 @@ final class PurchaseBillMapper extends BillMapper ->orderBy('net_purchase', 'DESC') ->limit($limit) ->execute() - ->fetchAll(\PDO::FETCH_KEY_PAIR); + ?->fetchAll(\PDO::FETCH_KEY_PAIR); - return $result; + return $result ?? []; } /** @@ -312,9 +314,9 @@ final class PurchaseBillMapper extends BillMapper ->groupBy('year', 'month') ->orderBy(['year', 'month'], ['ASC', 'ASC']) ->execute() - ->fetchAll(); + ?->fetchAll(); - return $result; + return $result ?? []; } /** @@ -333,8 +335,8 @@ final class PurchaseBillMapper extends BillMapper ->groupBy('year', 'month') ->orderBy(['year', 'month'], ['ASC', 'ASC']) ->execute() - ->fetchAll(); + ?->fetchAll(); - return $result; + return $result ?? []; } } diff --git a/Models/SalesBillMapper.php b/Models/SalesBillMapper.php index 920fa7e..b76ed20 100755 --- a/Models/SalesBillMapper.php +++ b/Models/SalesBillMapper.php @@ -89,7 +89,7 @@ final class SalesBillMapper extends BillMapper ->andWhere(self::TABLE . '.billing_bill_performance_date', '>=', $start) ->andWhere(self::TABLE . '.billing_bill_performance_date', '<=', $end) ->execute() - ->fetch(); + ?->fetch(); return new Money((int) $result[0]); } @@ -106,7 +106,7 @@ final class SalesBillMapper extends BillMapper ->andWhere(self::TABLE . '.billing_bill_performance_date', '>=', $start) ->andWhere(self::TABLE . '.billing_bill_performance_date', '<=', $end) ->execute() - ->fetch(); + ?->fetch(); return new Money((int) $result[0]); } @@ -125,7 +125,7 @@ final class SalesBillMapper extends BillMapper ->andWhere(self::TABLE . '.billing_bill_performance_date', '>=', $start) ->andWhere(self::TABLE . '.billing_bill_performance_date', '<=', $end) ->execute() - ->fetch(); + ?->fetch(); return new Money($result === false || $result[1] == 0 ? 0 : (int) (((int) $result[0]) / ((int) $result[1]))); } @@ -145,7 +145,7 @@ final class SalesBillMapper extends BillMapper ->orderBy('billing_bill_id', 'DESC') ->limit(1) ->execute() - ->fetch(); + ?->fetch(); return $result === false ? null : new \DateTimeImmutable($result[0]); } @@ -163,7 +163,7 @@ final class SalesBillMapper extends BillMapper ->orderBy('billing_bill_id', 'DESC') ->limit(1) ->execute() - ->fetch(); + ?->fetch(); return $result === false ? null : new \DateTimeImmutable($result[0]); } @@ -195,6 +195,7 @@ final class SalesBillMapper extends BillMapper ->where(BillElementMapper::TABLE . '_d1.billing_bill_element_item', '=', $id) ->limit($limit); + /** @phpstan-ignore-next-line */ if (!empty(self::CREATED_AT)) { $query->orderBy(self::TABLE . '_d1.' . self::COLUMNS[self::CREATED_AT]['name'], 'DESC'); } else { @@ -213,6 +214,7 @@ final class SalesBillMapper extends BillMapper $query->where(self::TABLE . '_d1.billing_bill_client', '=', $id) ->limit($limit); + /** @phpstan-ignore-next-line */ if (!empty(self::CREATED_AT)) { $query->orderBy(self::TABLE . '_d1.' . self::COLUMNS[self::CREATED_AT]['name'], 'DESC'); } else { @@ -258,6 +260,7 @@ final class SalesBillMapper extends BillMapper ->where(BillElementMapper::TABLE . '_d1.billing_bill_element_item', '=', $id) ->limit($limit = 10); + /** @phpstan-ignore-next-line */ if (!empty(self::CREATED_AT)) { $query->orderBy(self::TABLE . '_d1.' . self::COLUMNS[self::CREATED_AT]['name'], 'DESC'); } else { @@ -278,6 +281,7 @@ final class SalesBillMapper extends BillMapper ->where(self::TABLE . '_d1.billing_bill_client', '=', $client) ->limit($limit = 10); + /** @phpstan-ignore-next-line */ if (!empty(self::CREATED_AT)) { $query->orderBy(self::TABLE . '_d1.' . self::COLUMNS[self::CREATED_AT]['name'], 'DESC'); } else { @@ -305,9 +309,9 @@ final class SalesBillMapper extends BillMapper ->andWhere(self::TABLE . '.billing_bill_performance_date', '<=', $end) ->groupBy(CountryMapper::TABLE . '.country_region') ->execute() - ->fetchAll(\PDO::FETCH_KEY_PAIR); + ?->fetchAll(\PDO::FETCH_KEY_PAIR); - return $result; + return $result ?? []; } /** @@ -330,9 +334,9 @@ final class SalesBillMapper extends BillMapper ->orderBy('net_sales', 'DESC') ->limit($limit) ->execute() - ->fetchAll(\PDO::FETCH_KEY_PAIR); + ?->fetchAll(\PDO::FETCH_KEY_PAIR); - return $result; + return $result ?? []; } /** @@ -354,9 +358,9 @@ final class SalesBillMapper extends BillMapper ->groupBy('year', 'month') ->orderBy(['year', 'month'], ['ASC', 'ASC']) ->execute() - ->fetchAll(); + ?->fetchAll(); - return $result; + return $result ?? []; } /** @@ -376,8 +380,8 @@ final class SalesBillMapper extends BillMapper ->groupBy('year', 'month') ->orderBy(['year', 'month'], ['ASC', 'ASC']) ->execute() - ->fetchAll(); + ?->fetchAll(); - return $result; + return $result ?? []; } } diff --git a/tests/Bootstrap.php b/tests/Bootstrap.php index d46fd31..b5d36a8 100755 --- a/tests/Bootstrap.php +++ b/tests/Bootstrap.php @@ -257,6 +257,25 @@ $CONFIG = [ 'root' => '/', 'https' => false, ], + 'app' => [ + 'path' => __DIR__, + 'default' => [ + 'app' => 'Backend', + 'id' => 'backend', + 'lang' => 'en', + 'theme' => 'Backend', + 'org' => 1, + ], + 'domains' => [ + '127.0.0.1' => [ + 'app' => 'Backend', + 'id' => 'backend', + 'lang' => 'en', + 'theme' => 'Backend', + 'org' => 1, + ], + ], + ], 'socket' => [ 'master' => [ 'host' => '127.0.0.1',