migrate to gtea from bistbucket

This commit is contained in:
2026-03-15 17:08:23 +07:00
commit 129ca2260c
3716 changed files with 566316 additions and 0 deletions

View File

@@ -0,0 +1,165 @@
<?php
namespace Modules\Restaurant\Repositories;
use App\Abstracts\EntityRepository;
use Exception;
use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Query\Builder;
use Modules\Restaurant\Models\AddonFood;
use Symfony\Component\HttpFoundation\Response;
class AddonFoodRepository extends EntityRepository
{
public string $table = AddonFood::TABLE_NAME;
protected array $fillableColumns = [
'restaurant_id',
'food_item_id',
'addon_id',
'status',
'created_at',
'updated_at',
'deleted_at',
];
protected function getQuery(): Builder
{
return parent::getQuery();
}
protected function getFilterData(array $filterData = []): array
{
$defaultArgs = [
'perPage' => 10,
'search' => '',
'orderBy' => 'id',
'order' => 'desc',
'with_deleted' => false,
];
return array_merge($defaultArgs, $filterData);
}
private function getAddonFoodQuery(): Builder
{
return $this->getQuery()
->select(
"{$this->table}.id",
"{$this->table}.restaurant_id",
"{$this->table}.food_item_id",
"{$this->table}.addon_id",
"{$this->table}.status",
"{$this->table}.created_at",
"{$this->table}.updated_at",
"{$this->table}.deleted_at",
);
}
protected function filterSearchQuery(Builder|EloquentBuilder $query, string $searchedText): Builder
{
$searchable = "%$searchedText%";
return $query->where("{$this->table}.food_item_id", 'LIKE', $searchable)
->orWhere("{$this->table}.addon_id", 'LIKE', $searchable);
}
public function getAll(array $filterData = []): Paginator
{
$filter = $this->getFilterData($filterData);
$query = $this->getAddonFoodQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
if (! empty($filter['search'])) {
$query = $this->filterSearchQuery($query, $filter['search']);
}
return $query
->orderBy($filter['orderBy'], $filter['order'])
->paginate($filter['perPage']);
}
public function getCount(array $filterData = []): int
{
$filter = $this->getFilterData($filterData);
$query = $this->getQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
return $query->count();
}
/**
* @throws Exception
*/
public function getByColumn(string $columnName, $columnValue, array $selects = ['*']): ?object
{
$item = $this->getAddonFoodQuery()
->where($columnName, $columnValue)
->first($selects);
if (empty($item)) {
throw new Exception(
$this->getExceptionMessage(static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE),
Response::HTTP_NOT_FOUND
);
}
return $item;
}
/**
* @throws Exception
*/
public function create(array $data): object
{
$data = $this->prepareForDB($data);
$id = $this->getQuery()->insertGetId($data);
return AddonFood::find($id);
}
/**
* @throws Exception
*/
public function update(int $id, array $data): object
{
$item = AddonFood::findOrFail($id);
$data = $this->prepareForDB($data, $item);
parent::update($id, $data);
return $this->getById($id);
}
/**
* @throws Exception
*/
public function prepareForDB(array $data, ?object $item = null): array
{
$data = parent::prepareForDB($data, $item);
if (empty($item)) {
$data['created_at'] = now();
$data['restaurant_id'] = $this->getCurrentRestaurantId();
$data['status'] = 1;
} else {
$data['updated_at'] = now();
}
return $data;
}
protected function getExceptionMessages(): array
{
return [
static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE => 'AddonFood does not exist.',
static::MESSAGE_ITEM_COULD_NOT_BE_DELETED => 'AddonFood could not be deleted.',
];
}
}

View File

@@ -0,0 +1,169 @@
<?php
namespace Modules\Restaurant\Repositories;
use App\Abstracts\EntityRepository;
use Exception;
use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Query\Builder;
use Modules\Restaurant\Models\Addon;
use Symfony\Component\HttpFoundation\Response;
class AddonRepository extends EntityRepository
{
public string $table = Addon::TABLE_NAME;
protected array $fillableColumns = [
'restaurant_id',
'name',
'price',
'vat',
'pst',
'status',
'created_at',
'updated_at',
'deleted_at',
];
protected function getQuery(): Builder
{
return parent::getQuery();
}
protected function getFilterData(array $filterData = []): array
{
$defaultArgs = [
'perPage' => 10,
'search' => '',
'orderBy' => 'id',
'order' => 'desc',
'with_deleted' => false,
];
return array_merge($defaultArgs, $filterData);
}
private function getAddonQuery(): Builder
{
return $this->getQuery()
->select(
"{$this->table}.id",
"{$this->table}.restaurant_id",
"{$this->table}.name",
"{$this->table}.price",
"{$this->table}.vat",
"{$this->table}.pst",
"{$this->table}.status",
"{$this->table}.created_at",
"{$this->table}.updated_at",
"{$this->table}.deleted_at",
);
}
protected function filterSearchQuery(Builder|EloquentBuilder $query, string $searchedText): Builder
{
$searchable = "%$searchedText%";
return $query->where("{$this->table}.name", 'LIKE', $searchable)
->orWhere("{$this->table}.status", 'LIKE', $searchable);
}
public function getAll(array $filterData = []): Paginator
{
$filter = $this->getFilterData($filterData);
$query = $this->getAddonQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
if (! empty($filter['search'])) {
$query = $this->filterSearchQuery($query, $filter['search']);
}
return $query
->orderBy($filter['orderBy'], $filter['order'])
->paginate($filter['perPage']);
}
public function getCount(array $filterData = []): int
{
$filter = $this->getFilterData($filterData);
$query = $this->getQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
return $query->count();
}
/**
* @throws Exception
*/
public function getByColumn(string $columnName, $columnValue, array $selects = ['*']): ?object
{
$item = $this->getAddonQuery()
->where($columnName, $columnValue)
->first($selects);
if (empty($item)) {
throw new Exception(
$this->getExceptionMessage(static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE),
Response::HTTP_NOT_FOUND
);
}
return $item;
}
/**
* @throws Exception
*/
public function create(array $data): object
{
$data = $this->prepareForDB($data);
$id = $this->getQuery()->insertGetId($data);
return Addon::find($id);
}
/**
* @throws Exception
*/
public function update(int $id, array $data): object
{
$item = Addon::findOrFail($id);
$data = $this->prepareForDB($data, $item);
parent::update($id, $data);
return $this->getById($id);
}
/**
* @throws Exception
*/
public function prepareForDB(array $data, ?object $item = null): array
{
$data = parent::prepareForDB($data, $item);
if (empty($item)) {
$data['created_at'] = now();
$data['restaurant_id'] = $this->getCurrentRestaurantId();
$data['status'] = 1;
} else {
$data['updated_at'] = now();
}
return $data;
}
protected function getExceptionMessages(): array
{
return [
static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE => 'Addon does not exist.',
static::MESSAGE_ITEM_COULD_NOT_BE_DELETED => 'Addon could not be deleted.',
];
}
}

View File

@@ -0,0 +1,172 @@
<?php
namespace Modules\Restaurant\Repositories;
use App\Abstracts\EntityRepository;
use Exception;
use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Query\Builder;
use Modules\Restaurant\Models\CustomerAddress;
use Symfony\Component\HttpFoundation\Response;
class CustomerAddressRepository extends EntityRepository
{
public string $table = CustomerAddress::TABLE_NAME;
protected array $fillableColumns = [
'user_id',
'label',
'address_line_1',
'address_line_2',
'city',
'postal_code',
'latitude',
'longitude',
'is_default',
];
protected function getQuery(): Builder
{
return parent::getQuery();
}
protected function getFilterData(array $filterData = []): array
{
$defaultArgs = [
'perPage' => 10,
'search' => '',
'orderBy' => 'id',
'order' => 'desc',
'with_deleted' => false,
];
return array_merge($defaultArgs, $filterData);
}
private function getCustomerAddressQuery(): Builder
{
return $this->getQuery()
->select(
"{$this->table}.id",
"{$this->table}.restaurant_id",
"{$this->table}.user_id",
"{$this->table}.label",
"{$this->table}.address_line_1",
"{$this->table}.address_line_2",
"{$this->table}.city",
"{$this->table}.postal_code",
"{$this->table}.latitude",
"{$this->table}.longitude",
"{$this->table}.is_default",
"{$this->table}.created_at",
"{$this->table}.deleted_at"
);
}
protected function filterSearchQuery(Builder|EloquentBuilder $query, string $searchedText): Builder
{
$searchable = "%$searchedText%";
return $query->where("{$this->table}.name", 'LIKE', $searchable)
->orWhere("{$this->table}.status", 'LIKE', $searchable);
}
public function getAll(array $filterData = []): Paginator
{
$filter = $this->getFilterData($filterData);
$query = $this->getCustomerAddressQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
if (! empty($filter['search'])) {
$query = $this->filterSearchQuery($query, $filter['search']);
}
return $query
->orderBy($filter['orderBy'], $filter['order'])
->paginate($filter['perPage']);
}
public function getCount(array $filterData = []): int
{
$filter = $this->getFilterData($filterData);
$query = $this->getQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
return $query->count();
}
/**
* @throws Exception
*/
public function getByColumn(string $columnName, $columnValue, array $selects = ['*']): ?object
{
$item = $this->getCustomerAddressQuery()
->where($columnName, $columnValue)
->first($selects);
if (empty($item)) {
throw new Exception(
$this->getExceptionMessage(static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE),
Response::HTTP_NOT_FOUND
);
}
return $item;
}
/**
* @throws Exception
*/
public function create(array $data): object
{
$data = $this->prepareForDB($data);
$id = $this->getQuery()->insertGetId($data);
return CustomerAddress::find($id);
}
/**
* @throws Exception
*/
public function update(int $id, array $data): object
{
$item = CustomerAddress::findOrFail($id);
$data = $this->prepareForDB($data, $item);
parent::update($id, $data);
return $this->getById($id);
}
/**
* @throws Exception
*/
public function prepareForDB(array $data, ?object $item = null): array
{
$data = parent::prepareForDB($data, $item);
if (empty($item)) {
$data['created_at'] = now();
$data['restaurant_id'] = $this->getCurrentRestaurantId();
$data['status'] = 1;
} else {
$data['updated_at'] = now();
}
return $data;
}
protected function getExceptionMessages(): array
{
return [
static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE => 'CustomerAddress does not exist.',
static::MESSAGE_ITEM_COULD_NOT_BE_DELETED => 'CustomerAddress could not be deleted.',
];
}
}

View File

@@ -0,0 +1,204 @@
<?php
namespace Modules\Restaurant\Repositories;
use App\Abstracts\EntityRepository;
use Exception;
use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Query\Builder;
use Modules\Restaurant\Models\Customer;
use Symfony\Component\HttpFoundation\Response;
class CustomerRepository extends EntityRepository
{
public string $table = Customer::TABLE_NAME;
protected array $fillableColumns = [
'restaurant_id',
'customer_code',
'name',
'username',
'email',
'phone',
'password',
'otp_code',
'role_id',
'isVerified',
'email_verified_at',
'avatar',
'address',
'gender',
'date_of_birth',
'nid',
'platform',
'device_info',
'last_active_time',
'meta',
'status',
];
protected function getQuery(): Builder
{
return parent::getQuery();
}
protected function getFilterData(array $filterData = []): array
{
$defaultArgs = [
'perPage' => 10,
'search' => '',
'orderBy' => 'id',
'order' => 'desc',
'with_deleted' => false,
];
return array_merge($defaultArgs, $filterData);
}
private function getCustomerQuery(): Builder
{
return $this->getQuery()
->select(
"{$this->table}.id",
"{$this->table}.restaurant_id",
"{$this->table}.customer_code",
"{$this->table}.name",
"{$this->table}.username",
"{$this->table}.email",
"{$this->table}.phone",
"{$this->table}.password",
"{$this->table}.otp_code",
"{$this->table}.role_id",
"{$this->table}.isVerified",
"{$this->table}.email_verified_at",
"{$this->table}.avatar",
"{$this->table}.address",
"{$this->table}.gender",
"{$this->table}.date_of_birth",
"{$this->table}.nid",
"{$this->table}.platform",
"{$this->table}.device_info",
"{$this->table}.last_active_time",
"{$this->table}.meta",
"{$this->table}.status",
"{$this->table}.created_at",
"{$this->table}.updated_at",
"{$this->table}.deleted_at",
);
}
protected function filterSearchQuery(Builder|EloquentBuilder $query, string $searchedText): Builder
{
$searchable = "%$searchedText%";
return $query->where("{$this->table}.name", 'LIKE', $searchable)
->orWhere("{$this->table}.status", 'LIKE', $searchable);
}
public function getAll(array $filterData = []): Paginator
{
$filter = $this->getFilterData($filterData);
$query = $this->getCustomerQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
if (! empty($filter['search'])) {
$query = $this->filterSearchQuery($query, $filter['search']);
}
return $query
->orderBy($filter['orderBy'], $filter['order'])
->paginate($filter['perPage']);
}
public function getCount(array $filterData = []): int
{
$filter = $this->getFilterData($filterData);
$query = $this->getQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
return $query->count();
}
/**
* @throws Exception
*/
public function getByColumn(string $columnName, $columnValue, array $selects = ['*']): ?object
{
$item = $this->getCustomerQuery()
->where($columnName, $columnValue)
->first($selects);
if (empty($item)) {
throw new Exception(
$this->getExceptionMessage(static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE),
Response::HTTP_NOT_FOUND
);
}
return $item;
}
/**
* @throws Exception
*/
public function create(array $data): object
{
$data = $this->prepareForDB($data);
$id = $this->getQuery()->insertGetId($data);
return Customer::find($id);
}
/**
* @throws Exception
*/
public function update(int $id, array $data): object
{
$item = Customer::findOrFail($id);
$data = $this->prepareForDB($data, $item);
parent::update($id, $data);
return $this->getById($id);
}
/**
* @throws Exception
*/
public function prepareForDB(array $data, ?object $item = null): array
{
$data = parent::prepareForDB($data, $item);
if (empty($item)) {
$data['created_at'] = now();
$data['restaurant_id'] = $this->getCurrentRestaurantId();
$data['status'] = 1;
if (! empty($data['avatar']) && $data['avatar'] instanceof \Illuminate\Http\UploadedFile) {
$data['avatar'] = fileUploader('customers/', 'png', $data['avatar']);
}
} else {
if (! empty($data['avatar']) && $data['avatar'] instanceof \Illuminate\Http\UploadedFile) {
$data['avatar'] = fileUploader('customers/', 'png', $data['avatar'], $item->avatar);
}
$data['updated_at'] = now();
}
return $data;
}
protected function getExceptionMessages(): array
{
return [
static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE => 'Customer does not exist.',
static::MESSAGE_ITEM_COULD_NOT_BE_DELETED => 'Customer could not be deleted.',
];
}
}

View File

@@ -0,0 +1,169 @@
<?php
namespace Modules\Restaurant\Repositories;
use App\Abstracts\EntityRepository;
use Exception;
use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Query\Builder;
use Modules\Restaurant\Models\DeliveryCharge;
use Symfony\Component\HttpFoundation\Response;
class DeliveryChargeRepository extends EntityRepository
{
public string $table = DeliveryCharge::TABLE_NAME;
protected array $fillableColumns = [
'zone_id',
'restaurant_id',
'type',
'base_charge',
'per_km_charge',
'min_order_amount',
'free_delivery_above',
'is_active',
];
protected function getQuery(): Builder
{
return parent::getQuery();
}
protected function getFilterData(array $filterData = []): array
{
$defaultArgs = [
'perPage' => 10,
'search' => '',
'orderBy' => 'id',
'order' => 'desc',
'with_deleted' => false,
];
return array_merge($defaultArgs, $filterData);
}
private function getDeliveryChargeQuery(): Builder
{
return $this->getQuery()
->select(
"{$this->table}.id",
"{$this->table}.restaurant_id",
"{$this->table}.zone_id",
"{$this->table}.type",
"{$this->table}.base_charge",
"{$this->table}.per_km_charge",
"{$this->table}.min_order_amount",
"{$this->table}.free_delivery_above",
"{$this->table}.is_active",
"{$this->table}.created_at",
"{$this->table}.deleted_at"
);
}
protected function filterSearchQuery(Builder|EloquentBuilder $query, string $searchedText): Builder
{
$searchable = "%$searchedText%";
return $query->where("{$this->table}.name", 'LIKE', $searchable)
->orWhere("{$this->table}.status", 'LIKE', $searchable);
}
public function getAll(array $filterData = []): Paginator
{
$filter = $this->getFilterData($filterData);
$query = $this->getDeliveryChargeQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
if (! empty($filter['search'])) {
$query = $this->filterSearchQuery($query, $filter['search']);
}
return $query
->orderBy($filter['orderBy'], $filter['order'])
->paginate($filter['perPage']);
}
public function getCount(array $filterData = []): int
{
$filter = $this->getFilterData($filterData);
$query = $this->getQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
return $query->count();
}
/**
* @throws Exception
*/
public function getByColumn(string $columnName, $columnValue, array $selects = ['*']): ?object
{
$item = $this->getDeliveryChargeQuery()
->where($columnName, $columnValue)
->first($selects);
if (empty($item)) {
throw new Exception(
$this->getExceptionMessage(static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE),
Response::HTTP_NOT_FOUND
);
}
return $item;
}
/**
* @throws Exception
*/
public function create(array $data): object
{
$data = $this->prepareForDB($data);
$id = $this->getQuery()->insertGetId($data);
return DeliveryCharge::find($id);
}
/**
* @throws Exception
*/
public function update(int $id, array $data): object
{
$item = DeliveryCharge::findOrFail($id);
$data = $this->prepareForDB($data, $item);
parent::update($id, $data);
return $this->getById($id);
}
/**
* @throws Exception
*/
public function prepareForDB(array $data, ?object $item = null): array
{
$data = parent::prepareForDB($data, $item);
if (empty($item)) {
$data['created_at'] = now();
$data['restaurant_id'] = $this->getCurrentRestaurantId();
$data['status'] = 1;
} else {
$data['updated_at'] = now();
}
return $data;
}
protected function getExceptionMessages(): array
{
return [
static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE => 'DeliveryCharge does not exist.',
static::MESSAGE_ITEM_COULD_NOT_BE_DELETED => 'DeliveryCharge could not be deleted.',
];
}
}

View File

@@ -0,0 +1,182 @@
<?php
namespace Modules\Restaurant\Repositories;
use App\Abstracts\EntityRepository;
use Exception;
use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Query\Builder;
use Modules\Restaurant\Models\FoodCategory;
use Symfony\Component\HttpFoundation\Response;
class FoodCategoryRepository extends EntityRepository
{
public string $table = FoodCategory::TABLE_NAME;
protected array $fillableColumns = [
'restaurant_id',
'name',
'image',
'parent_id',
'is_offer',
'start_date',
'end_date',
'status',
'created_at',
'updated_at',
'deleted_at',
];
protected function getQuery(): Builder
{
return parent::getQuery();
}
protected function getFilterData(array $filterData = []): array
{
$defaultArgs = [
'perPage' => 10,
'search' => '',
'orderBy' => 'id',
'order' => 'desc',
'with_deleted' => false,
];
return array_merge($defaultArgs, $filterData);
}
private function getFoodCategoryQuery(): EloquentBuilder
{
return FoodCategory::select(
"{$this->table}.id",
"{$this->table}.restaurant_id",
"{$this->table}.name",
"{$this->table}.slug",
"{$this->table}.image",
"{$this->table}.parent_id",
"{$this->table}.is_offer",
"{$this->table}.start_date",
"{$this->table}.end_date",
"{$this->table}.status",
"{$this->table}.created_at",
"{$this->table}.updated_at",
"{$this->table}.deleted_at"
)
->withCount('foodItems');
}
protected function filterSearchQuery(Builder|EloquentBuilder $query, string $searchedText): Builder
{
$searchable = "%$searchedText%";
return $query->where("{$this->table}.name", 'LIKE', $searchable)
->orWhere("{$this->table}.status", 'LIKE', $searchable);
}
public function getAll(array $filterData = []): Paginator
{
$filter = $this->getFilterData($filterData);
$query = $this->getFoodCategoryQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
if (! empty($filter['search'])) {
$query = $this->filterSearchQuery($query, $filter['search']);
}
return $query
->orderBy($filter['orderBy'], $filter['order'])
->paginate($filter['perPage']);
}
public function getCount(array $filterData = []): int
{
$filter = $this->getFilterData($filterData);
$query = $this->getQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
return $query->count();
}
/**
* @throws Exception
*/
public function getByColumn(string $columnName, $columnValue, array $selects = ['*']): ?object
{
$item = $this->getFoodCategoryQuery()
->where($columnName, $columnValue)
->first($selects);
if (empty($item)) {
throw new Exception(
$this->getExceptionMessage(static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE),
Response::HTTP_NOT_FOUND
);
}
return $item;
}
/**
* @throws Exception
*/
public function create(array $data): object
{
$data = $this->prepareForDB($data);
$id = $this->getQuery()->insertGetId($data);
return FoodCategory::find($id);
}
/**
* @throws Exception
*/
public function update(int $id, array $data): object
{
$item = FoodCategory::findOrFail($id);
$data = $this->prepareForDB($data, $item);
parent::update($id, $data);
return $this->getById($id);
}
/**
* @throws Exception
*/
public function prepareForDB(array $data, ?object $item = null): array
{
$data = parent::prepareForDB($data, $item);
if (empty($item)) {
$data['created_at'] = now();
$data['restaurant_id'] = $this->getCurrentRestaurantId();
$data['status'] = 1;
if (! empty($data['image']) && $data['image'] instanceof \Illuminate\Http\UploadedFile) {
$data['image'] = fileUploader('food_categories/', 'png', $data['image']);
}
} else {
if (! empty($data['image']) && $data['image'] instanceof \Illuminate\Http\UploadedFile) {
$data['image'] = fileUploader('food_categories/', 'png', $data['image'], $item->image);
}
$data['updated_at'] = now();
}
return $data;
}
protected function getExceptionMessages(): array
{
return [
static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE => 'FoodCategory does not exist.',
static::MESSAGE_ITEM_COULD_NOT_BE_DELETED => 'FoodCategory could not be deleted.',
];
}
}

View File

@@ -0,0 +1,349 @@
<?php
namespace Modules\Restaurant\Repositories;
use App\Abstracts\EntityRepository;
use Exception;
use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Query\Builder;
use Illuminate\Support\Facades\DB;
use Modules\Restaurant\Models\FoodItem;
use Symfony\Component\HttpFoundation\Response;
class FoodItemRepository extends EntityRepository
{
public string $table = FoodItem::TABLE_NAME;
protected array $fillableColumns = [
'restaurant_id',
'category_id',
'menu_category_id',
'menu_section_id',
'name',
'slug',
'description',
'food_type',
'points',
'is_featured',
'is_party',
'is_dinner',
'is_lunch',
'is_popular_item',
'is_chef_special',
'image',
'prep_time',
'cooking_time',
'vat',
'pst',
'ingredients_cost',
'allergens',
'notes',
'status',
'created_at',
'updated_at',
'deleted_at',
];
protected function getQuery(): Builder
{
return parent::getQuery();
}
protected function getFilterData(array $filterData = []): array
{
$defaultArgs = [
'perPage' => 10,
'search' => '',
'orderBy' => 'id',
'order' => 'desc',
'with_deleted' => false,
];
return array_merge($defaultArgs, $filterData);
}
private function getFoodItemQuery(): Builder
{
return $this->getQuery()
->select(
"{$this->table}.id",
"{$this->table}.restaurant_id",
"{$this->table}.category_id",
"{$this->table}.menu_category_id",
"{$this->table}.menu_section_id",
"{$this->table}.name",
"{$this->table}.slug",
"{$this->table}.description",
"{$this->table}.food_type",
"{$this->table}.points",
"{$this->table}.is_featured",
"{$this->table}.is_party",
"{$this->table}.is_dinner",
"{$this->table}.is_lunch",
"{$this->table}.is_popular_item",
"{$this->table}.is_chef_special",
"{$this->table}.image",
"{$this->table}.prep_time",
"{$this->table}.cooking_time",
"{$this->table}.vat",
"{$this->table}.pst",
"{$this->table}.ingredients_cost",
"{$this->table}.allergens",
"{$this->table}.notes",
"{$this->table}.status",
"{$this->table}.created_at",
"{$this->table}.updated_at",
"{$this->table}.deleted_at",
);
}
protected function filterSearchQuery(Builder|EloquentBuilder $query, string $searchedText): Builder
{
$searchable = "%$searchedText%";
return $query->where("{$this->table}.name", 'LIKE', $searchable)
->orWhere("{$this->table}.status", 'LIKE', $searchable);
}
public function getAll(array $filterData = []): Paginator
{
$filter = $this->getFilterData($filterData);
$query = $this->getFoodItemQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
if (! empty($filter['search'])) {
$query = $this->filterSearchQuery($query, $filter['search']);
}
return $query
->orderBy($filter['orderBy'], $filter['order'])
->paginate($filter['perPage']);
}
public function getCount(array $filterData = []): int
{
$filter = $this->getFilterData($filterData);
$query = $this->getQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
return $query->count();
}
/**
* @throws Exception
*/
public function getByColumn(string $columnName, $columnValue, array $selects = ['*']): ?object
{
$item = $this->getFoodItemQuery()
->where($columnName, $columnValue)
->first($selects);
if (empty($item)) {
throw new Exception(
$this->getExceptionMessage(static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE),
Response::HTTP_NOT_FOUND
);
}
return $item;
}
/**
* @throws Exception
*/
public function create(array $data): object
{
return DB::transaction(function () use ($data) {
$variants = $data['variants'] ?? [];
unset($data['variants']);
$data = $this->prepareForDB($data);
/** @var FoodItem $food */
$food = FoodItem::create($data);
$this->syncVariants($food, $variants);
return $food->load('variants');
});
}
/**
* @throws Exception
*/
public function update(int $id, array $data): object
{
return DB::transaction(function () use ($id, $data) {
/** @var FoodItem $food */
$food = FoodItem::findOrFail($id);
// Extract variants array
$variants = $data['variants'] ?? [];
unset($data['variants']);
// Update food main data
$data = $this->prepareForDB($data, $food);
$food->update($data);
// Sync only changed variants
$this->syncVariants($food, $variants);
return $food->load('variants');
});
}
/**
* Prepare data for DB insert/update
*/
public function prepareForDB(array $data, ?object $item = null): array
{
if (! empty($data['prep_time'])) {
$data['prep_time'] = date('H:i:s', strtotime($data['prep_time']));
}
if (! empty($data['cooking_time'])) {
$data['cooking_time'] = date('H:i:s', strtotime($data['cooking_time']));
}
$data = parent::prepareForDB($data, $item);
if (! empty($data['image']) && $data['image'] instanceof \Illuminate\Http\UploadedFile) {
$data['image'] = fileUploader('food_items/', 'png', $data['image'], $item->image ?? null);
}
$data['restaurant_id'] = $this->getCurrentRestaurantId();
$data['updated_at'] = now();
if (empty($item)) {
$data['created_at'] = now();
$data['status'] = 1;
}
return $data;
}
/**
* Sync food variants safely
*/
private function syncVariants(FoodItem $food, array $variants): void
{
$existingIds = $food->variants()->pluck('id')->toArray();
$receivedIds = [];
$defaultMarked = false;
foreach ($variants as $variant) {
// Determine default
$isDefault = ! $defaultMarked && ($variant['is_default'] ?? false);
$defaultMarked = $defaultMarked || $isDefault;
// If variant has ID → update
if (! empty($variant['id'])) {
$receivedIds[] = $variant['id'];
$food->variants()
->where('id', $variant['id'])
->update([
'restaurant_id' => $food->restaurant_id,
'name' => $variant['name'],
'sku' => $variant['sku'] ?? $this->generateSku($food, $variant['name']),
'price' => $variant['price'],
'offer_price' => $variant['offer_price'] ?? null,
'discount' => $variant['discount'] ?? 0,
'unit_id' => $variant['unit_id'] ?? 'pcs',
'stock_tracking' => $variant['stock_tracking'] ?? true,
'ingredients_cost' => $variant['ingredients_cost'] ?? 0,
'profit_margin' => $variant['profit_margin'] ?? 0,
'alert_stock_quantity' => $variant['alert_stock_quantity'] ?? null,
'combo_type' => $variant['combo_type'] ?? 'single',
'is_active_offer' => $variant['is_active_offer'] ?? false,
'is_default' => $isDefault,
'updated_at' => now(),
]);
continue;
}
// If no ID → create new variant
$newVariant = $food->variants()->create([
'restaurant_id' => $food->restaurant_id,
'name' => $variant['name'],
'sku' => $this->generateSku($food, $variant['name']),
'price' => $variant['price'],
'offer_price' => $variant['offer_price'] ?? null,
'discount' => $variant['discount'] ?? 0,
'unit_id' => $variant['unit_id'] ?? 'pcs',
'stock_tracking' => $variant['stock_tracking'] ?? true,
'ingredients_cost' => $variant['ingredients_cost'] ?? 0,
'profit_margin' => $variant['profit_margin'] ?? 0,
'alert_stock_quantity' => $variant['alert_stock_quantity'] ?? null,
'combo_type' => $variant['combo_type'] ?? 'single',
'is_active_offer' => $variant['is_active_offer'] ?? false,
'is_default' => $isDefault,
'status' => 1,
'created_at' => now(),
]);
$receivedIds[] = $newVariant->id;
}
// Delete only removed variants
$toDelete = array_diff($existingIds, $receivedIds);
if (! empty($toDelete)) {
$food->variants()->whereIn('id', $toDelete)->delete();
}
}
// private function syncVariants(FoodItem $food, array $variants): void
// {
// $defaultMarked = false;
// foreach ($variants as $variant) {
// $isDefault = ! $defaultMarked && ($variant['is_default'] ?? false);
// $defaultMarked = $defaultMarked || $isDefault;
// $food->variants()->create([
// 'restaurant_id' => $food->restaurant_id,
// 'name' => $variant['name'],
// 'sku' => $this->generateSku($food, $variant['name']),
// 'price' => $variant['price'],
// 'offer_price' => $variant['offer_price'] ?? null,
// 'discount' => $variant['discount'] ?? 0,
// 'unit_id' => $variant['unit_id'] ?? 'pcs',
// 'stock_tracking' => $variant['stock_tracking'] ?? true,
// 'ingredients_cost' => $variant['ingredients_cost'] ?? 0,
// 'profit_margin' => $variant['profit_margin'] ?? 0,
// 'alert_stock_quantity' => $variant['alert_stock_quantity'] ?? null,
// 'combo_type' => $variant['combo_type'] ?? 'single',
// 'is_active_offer' => $variant['is_active_offer'] ?? false,
// 'is_default' => $isDefault,
// 'status' => 1,
// 'created_at' => now(),
// ]);
// }
// }
/**
* Simple SKU generator
*/
private function generateSku(FoodItem $food, string $variantName): string
{
return strtoupper(substr($food->name, 0, 3)).'-'.strtoupper(substr($variantName, 0, 3)).'-'.rand(1000, 9999);
}
protected function getExceptionMessages(): array
{
return [
static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE => 'FoodItem does not exist.',
static::MESSAGE_ITEM_COULD_NOT_BE_DELETED => 'FoodItem could not be deleted.',
];
}
}

View File

@@ -0,0 +1,175 @@
<?php
namespace Modules\Restaurant\Repositories;
use App\Abstracts\EntityRepository;
use Exception;
use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Query\Builder;
use Modules\Restaurant\Models\FoodVariantIngredient;
use Symfony\Component\HttpFoundation\Response;
class FoodVariantIngredientRepository extends EntityRepository
{
public string $table = FoodVariantIngredient::TABLE_NAME;
protected array $fillableColumns = [
'restaurant_id',
'food_variant_id',
'ingredient_id',
'quantity',
'wastage_percentage',
'unit_conversion_factor',
'optional',
'notes',
'status',
'created_at',
'updated_at',
'deleted_at',
];
protected function getQuery(): Builder
{
return parent::getQuery();
}
protected function getFilterData(array $filterData = []): array
{
$defaultArgs = [
'perPage' => 10,
'search' => '',
'orderBy' => 'id',
'order' => 'desc',
'with_deleted' => false,
];
return array_merge($defaultArgs, $filterData);
}
private function getFoodVariantIngredientQuery(): Builder
{
return $this->getQuery()
->select(
"{$this->table}.id",
"{$this->table}.restaurant_id",
"{$this->table}.food_variant_id",
"{$this->table}.ingredient_id",
"{$this->table}.quantity",
"{$this->table}.wastage_percentage",
"{$this->table}.unit_conversion_factor",
"{$this->table}.optional",
"{$this->table}.notes",
"{$this->table}.status",
"{$this->table}.created_at",
"{$this->table}.updated_at",
"{$this->table}.deleted_at",
);
}
protected function filterSearchQuery(Builder|EloquentBuilder $query, string $searchedText): Builder
{
$searchable = "%$searchedText%";
return $query->where("{$this->table}.name", 'LIKE', $searchable)
->orWhere("{$this->table}.status", 'LIKE', $searchable);
}
public function getAll(array $filterData = []): Paginator
{
$filter = $this->getFilterData($filterData);
$query = $this->getFoodVariantIngredientQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
if (! empty($filter['search'])) {
$query = $this->filterSearchQuery($query, $filter['search']);
}
return $query
->orderBy($filter['orderBy'], $filter['order'])
->paginate($filter['perPage']);
}
public function getCount(array $filterData = []): int
{
$filter = $this->getFilterData($filterData);
$query = $this->getQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
return $query->count();
}
/**
* @throws Exception
*/
public function getByColumn(string $columnName, $columnValue, array $selects = ['*']): ?object
{
$item = $this->getFoodVariantIngredientQuery()
->where($columnName, $columnValue)
->first($selects);
if (empty($item)) {
throw new Exception(
$this->getExceptionMessage(static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE),
Response::HTTP_NOT_FOUND
);
}
return $item;
}
/**
* @throws Exception
*/
public function create(array $data): object
{
$data = $this->prepareForDB($data);
$id = $this->getQuery()->insertGetId($data);
return FoodVariantIngredient::find($id);
}
/**
* @throws Exception
*/
public function update(int $id, array $data): object
{
$item = FoodVariantIngredient::findOrFail($id);
$data = $this->prepareForDB($data, $item);
parent::update($id, $data);
return $this->getById($id);
}
/**
* @throws Exception
*/
public function prepareForDB(array $data, ?object $item = null): array
{
$data = parent::prepareForDB($data, $item);
if (empty($item)) {
$data['created_at'] = now();
$data['restaurant_id'] = $this->getCurrentRestaurantId();
$data['status'] = 1;
} else {
$data['updated_at'] = now();
}
return $data;
}
protected function getExceptionMessages(): array
{
return [
static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE => 'FoodVariantIngredient does not exist.',
static::MESSAGE_ITEM_COULD_NOT_BE_DELETED => 'FoodVariantIngredient could not be deleted.',
];
}
}

View File

@@ -0,0 +1,208 @@
<?php
namespace Modules\Restaurant\Repositories;
use App\Abstracts\EntityRepository;
use Exception;
use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Query\Builder;
use Modules\Restaurant\Models\FoodVariant;
use Symfony\Component\HttpFoundation\Response;
class FoodVariantRepository extends EntityRepository
{
public string $table = FoodVariant::TABLE_NAME;
protected array $fillableColumns = [
'restaurant_id',
'food_item_id',
'name',
'sku',
'barcode',
'price',
'offer_price',
'discount',
'unit_id',
'image',
'description',
'is_default',
'stock_tracking',
'ingredients_cost',
'profit_margin',
'alert_stock_quantity',
'combo_type',
'is_active_offer',
'offer_start_at',
'offer_end_at',
'status',
'created_at',
'updated_at',
'deleted_at',
];
protected function getQuery(): Builder
{
return parent::getQuery();
}
protected function getFilterData(array $filterData = []): array
{
$defaultArgs = [
'perPage' => 10,
'search' => '',
'orderBy' => 'id',
'order' => 'desc',
'with_deleted' => false,
];
return array_merge($defaultArgs, $filterData);
}
private function getFoodVariantQuery(): Builder
{
return $this->getQuery()
->select(
"{$this->table}.id",
"{$this->table}.restaurant_id",
"{$this->table}.food_item_id",
"{$this->table}.name",
"{$this->table}.sku",
"{$this->table}.barcode",
"{$this->table}.price",
"{$this->table}.offer_price",
"{$this->table}.discount",
"{$this->table}.unit_id",
'units.name as unit_name', // ⬅️ ADDED
"{$this->table}.image",
"{$this->table}.description",
"{$this->table}.is_default",
"{$this->table}.stock_tracking",
"{$this->table}.ingredients_cost",
"{$this->table}.profit_margin",
"{$this->table}.alert_stock_quantity",
"{$this->table}.combo_type",
"{$this->table}.is_active_offer",
"{$this->table}.offer_start_at",
"{$this->table}.offer_end_at",
"{$this->table}.status",
"{$this->table}.created_at",
"{$this->table}.updated_at",
"{$this->table}.deleted_at",
)
->leftJoin('units', 'units.id', '=', "{$this->table}.unit_id"); // ⬅️ JOIN ADDED
}
protected function filterSearchQuery(Builder|EloquentBuilder $query, string $searchedText): Builder
{
$searchable = "%$searchedText%";
return $query->where("{$this->table}.name", 'LIKE', $searchable)
->orWhere("{$this->table}.status", 'LIKE', $searchable);
}
public function getAll(array $filterData = []): Paginator
{
$filter = $this->getFilterData($filterData);
$query = $this->getFoodVariantQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
if (! empty($filter['search'])) {
$query = $this->filterSearchQuery($query, $filter['search']);
}
return $query
->orderBy($filter['orderBy'], $filter['order'])
->paginate($filter['perPage']);
}
public function getCount(array $filterData = []): int
{
$filter = $this->getFilterData($filterData);
$query = $this->getQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
return $query->count();
}
/**
* @throws Exception
*/
public function getByColumn(string $columnName, $columnValue, array $selects = ['*']): ?object
{
$item = $this->getFoodVariantQuery()
->where($columnName, $columnValue)
->first($selects);
if (empty($item)) {
throw new Exception(
$this->getExceptionMessage(static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE),
Response::HTTP_NOT_FOUND
);
}
return $item;
}
/**
* @throws Exception
*/
public function create(array $data): object
{
$data = $this->prepareForDB($data);
$id = $this->getQuery()->insertGetId($data);
return FoodVariant::find($id);
}
/**
* @throws Exception
*/
public function update(int $id, array $data): object
{
$item = FoodVariant::findOrFail($id);
$data = $this->prepareForDB($data, $item);
parent::update($id, $data);
return $this->getById($id);
}
/**
* @throws Exception
*/
public function prepareForDB(array $data, ?object $item = null): array
{
$data = parent::prepareForDB($data, $item);
if (empty($item)) {
$data['created_at'] = now();
$data['restaurant_id'] = $this->getCurrentRestaurantId();
$data['status'] = 1;
if (! empty($data['image']) && $data['image'] instanceof \Illuminate\Http\UploadedFile) {
$data['image'] = fileUploader('food_items/', 'png', $data['image']);
}
} else {
if (! empty($data['image']) && $data['image'] instanceof \Illuminate\Http\UploadedFile) {
$data['image'] = fileUploader('food_items/', 'png', $data['image'], $item->image);
}
$data['updated_at'] = now();
}
return $data;
}
protected function getExceptionMessages(): array
{
return [
static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE => 'FoodVariant does not exist.',
static::MESSAGE_ITEM_COULD_NOT_BE_DELETED => 'FoodVariant could not be deleted.',
];
}
}

View File

@@ -0,0 +1,187 @@
<?php
namespace Modules\Restaurant\Repositories;
use App\Abstracts\EntityRepository;
use Exception;
use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Query\Builder;
use Modules\Restaurant\Models\FoodWaste;
use Symfony\Component\HttpFoundation\Response;
class FoodWasteRepository extends EntityRepository
{
public string $table = FoodWaste::TABLE_NAME;
protected array $fillableColumns = [
'restaurant_id',
'food_item_id',
'food_variant_id',
'quantity',
'unit_cost',
'reason',
'notes',
'wasted_by',
'approved_by',
'wasted_at',
'status',
];
protected function getQuery(): Builder
{
return parent::getQuery();
}
protected function getFilterData(array $filterData = []): array
{
$defaultArgs = [
'perPage' => 10,
'search' => '',
'orderBy' => 'id',
'order' => 'desc',
'with_deleted' => false,
];
return array_merge($defaultArgs, $filterData);
}
private function getFoodWasteQuery(): Builder
{
return $this->getQuery()
->leftJoin('food_items', 'food_items.id', '=', 'food_wastes.food_item_id')
->leftJoin('food_variants', 'food_variants.id', '=', 'food_wastes.food_variant_id')
->select(
"{$this->table}.id",
"{$this->table}.restaurant_id",
"{$this->table}.food_item_id",
'food_items.name as food_item_name',
"{$this->table}.food_variant_id",
'food_variants.name as food_variant_name',
"{$this->table}.quantity",
"{$this->table}.unit_cost",
"{$this->table}.reason",
"{$this->table}.notes",
"{$this->table}.wasted_by",
"{$this->table}.approved_by",
"{$this->table}.wasted_at",
"{$this->table}.status",
"{$this->table}.created_at",
"{$this->table}.deleted_at"
);
}
protected function filterSearchQuery(Builder|EloquentBuilder $query, string $searchedText): Builder
{
$searchable = "%$searchedText%";
return $query->where("{$this->table}.food_item_id", 'LIKE', $searchable)
->orWhere("{$this->table}.status", 'LIKE', $searchable);
}
public function getAll(array $filterData = []): Paginator
{
$filter = $this->getFilterData($filterData);
$query = $this->getFoodWasteQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
if (! empty($filter['search'])) {
$query = $this->filterSearchQuery($query, $filter['search']);
}
return $query
->orderBy($filter['orderBy'], $filter['order'])
->paginate($filter['perPage']);
}
public function getCount(array $filterData = []): int
{
$filter = $this->getFilterData($filterData);
$query = $this->getQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
return $query->count();
}
/**
* @throws Exception
*/
public function getByColumn(string $columnName, $columnValue, array $selects = ['*']): ?object
{
$item = $this->getFoodWasteQuery()
->where($columnName, $columnValue)
->first($selects);
if (empty($item)) {
throw new Exception(
$this->getExceptionMessage(static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE),
Response::HTTP_NOT_FOUND
);
}
return $item;
}
/**
* @throws Exception
*/
public function create(array $data): object
{
$data = $this->prepareForDB($data);
$id = $this->getQuery()->insertGetId($data);
return FoodWaste::find($id);
}
/**
* @throws Exception
*/
public function update(int $id, array $data): object
{
$item = FoodWaste::findOrFail($id);
$data = $this->prepareForDB($data, $item);
parent::update($id, $data);
return $this->getById($id);
}
/**
* @throws Exception
*/
public function prepareForDB(array $data, ?object $item = null): array
{
$data = parent::prepareForDB($data, $item);
if (empty($item)) {
$data['created_at'] = now();
$data['restaurant_id'] = $this->getCurrentRestaurantId();
$data['status'] = 1;
if (! empty($data['image']) && $data['image'] instanceof \Illuminate\Http\UploadedFile) {
$data['image'] = fileUploader('Restaurant/', 'png', $data['image']);
}
} else {
if (! empty($data['image']) && $data['image'] instanceof \Illuminate\Http\UploadedFile) {
$data['image'] = fileUploader('Restaurant/', 'png', $data['image'], $item->image);
}
$data['updated_at'] = now();
}
return $data;
}
protected function getExceptionMessages(): array
{
return [
static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE => 'FoodWaste does not exist.',
static::MESSAGE_ITEM_COULD_NOT_BE_DELETED => 'FoodWaste could not be deleted.',
];
}
}

View File

@@ -0,0 +1,8 @@
<?php
namespace Modules\Restaurant\Repositories;
class IngredientDamageRepository
{
//
}

View File

@@ -0,0 +1,200 @@
<?php
namespace Modules\Restaurant\Repositories;
use App\Abstracts\EntityRepository;
use Exception;
use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Query\Builder;
use Modules\Restaurant\Models\Ingredient;
use Symfony\Component\HttpFoundation\Response;
class IngredientRepository extends EntityRepository
{
public string $table = Ingredient::TABLE_NAME;
protected array $fillableColumns = [
'restaurant_id',
'name',
'unit_id',
'stock_quantity',
'cost_per_unit',
'low_stock_alert',
'supplier_id',
'last_purchase_price',
'last_purchase_date',
'conversion_factor',
'reserved_quantity',
'wastage_quantity',
'category',
'notes',
'status',
'image',
'created_at',
'updated_at',
'deleted_at',
];
protected function getQuery(): Builder
{
return parent::getQuery();
}
protected function getFilterData(array $filterData = []): array
{
$defaultArgs = [
'perPage' => 10,
'search' => '',
'orderBy' => 'id',
'order' => 'desc',
'with_deleted' => false,
];
return array_merge($defaultArgs, $filterData);
}
private function getIngredientQuery(): Builder
{
return $this->getQuery()
->select(
"{$this->table}.id",
"{$this->table}.restaurant_id",
"{$this->table}.name",
"{$this->table}.unit_id",
'units.name as unit_name',
'units.short_name as unit_short_name',
"{$this->table}.stock_quantity",
"{$this->table}.cost_per_unit",
"{$this->table}.low_stock_alert",
"{$this->table}.supplier_id",
"{$this->table}.last_purchase_price",
"{$this->table}.last_purchase_date",
"{$this->table}.conversion_factor",
"{$this->table}.reserved_quantity",
"{$this->table}.wastage_quantity",
"{$this->table}.category",
"{$this->table}.notes",
"{$this->table}.image",
"{$this->table}.status",
"{$this->table}.created_at",
"{$this->table}.updated_at",
"{$this->table}.deleted_at"
)
->leftJoin('units', "{$this->table}.unit_id", '=', 'units.id');
}
protected function filterSearchQuery(Builder|EloquentBuilder $query, string $searchedText): Builder
{
$searchable = "%$searchedText%";
return $query->where("{$this->table}.name", 'LIKE', $searchable)
->orWhere("{$this->table}.status", 'LIKE', $searchable);
}
public function getAll(array $filterData = []): Paginator
{
$filter = $this->getFilterData($filterData);
$query = $this->getIngredientQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
if (! empty($filter['search'])) {
$query = $this->filterSearchQuery($query, $filter['search']);
}
return $query
->orderBy($filter['orderBy'], $filter['order'])
->paginate($filter['perPage']);
}
public function getCount(array $filterData = []): int
{
$filter = $this->getFilterData($filterData);
$query = $this->getQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
return $query->count();
}
/**
* @throws Exception
*/
public function getByColumn(string $columnName, $columnValue, array $selects = ['*']): ?object
{
$item = $this->getIngredientQuery()
->where($columnName, $columnValue)
->first($selects);
if (empty($item)) {
throw new Exception(
$this->getExceptionMessage(static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE),
Response::HTTP_NOT_FOUND
);
}
return $item;
}
/**
* @throws Exception
*/
public function create(array $data): object
{
$data = $this->prepareForDB($data);
$id = $this->getQuery()->insertGetId($data);
return Ingredient::find($id);
}
/**
* @throws Exception
*/
public function update(int $id, array $data): object
{
$item = Ingredient::findOrFail($id);
$data = $this->prepareForDB($data, $item);
parent::update($id, $data);
return $this->getById($id);
}
/**
* @throws Exception
*/
public function prepareForDB(array $data, ?object $item = null): array
{
$data = parent::prepareForDB($data, $item);
if (empty($item)) {
$data['created_at'] = now();
$data['restaurant_id'] = $this->getCurrentRestaurantId();
$data['status'] = 1;
if (! empty($data['image']) && $data['image'] instanceof \Illuminate\Http\UploadedFile) {
$data['image'] = fileUploader('ingredients/', 'png', $data['image']);
}
} else {
if (! empty($data['image']) && $data['image'] instanceof \Illuminate\Http\UploadedFile) {
$data['image'] = fileUploader('ingredients/', 'png', $data['image'], $item->image);
}
$data['updated_at'] = now();
}
return $data;
}
protected function getExceptionMessages(): array
{
return [
static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE => 'Ingredient does not exist.',
static::MESSAGE_ITEM_COULD_NOT_BE_DELETED => 'Ingredient could not be deleted.',
];
}
}

View File

@@ -0,0 +1,179 @@
<?php
namespace Modules\Restaurant\Repositories;
use App\Abstracts\EntityRepository;
use Exception;
use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Query\Builder;
use Modules\Restaurant\Models\KitchenAssign;
use Symfony\Component\HttpFoundation\Response;
class KitchenAssignRepository extends EntityRepository
{
public string $table = KitchenAssign::TABLE_NAME;
protected array $fillableColumns = [
'restaurant_id',
'kitchen_id',
'user_id',
'status',
'created_at',
'updated_at',
'deleted_at',
];
protected function getQuery(): Builder
{
return parent::getQuery();
}
protected function getFilterData(array $filterData = []): array
{
$defaultArgs = [
'perPage' => 10,
'search' => '',
'orderBy' => 'id',
'order' => 'desc',
'with_deleted' => false,
];
return array_merge($defaultArgs, $filterData);
}
private function getKitchenAssignQuery(): Builder
{
return $this->getQuery()
->select(
"{$this->table}.id",
"{$this->table}.restaurant_id",
'restaurants.name as restaurant_name',
"{$this->table}.kitchen_id",
'kitchens.name as kitchen_name',
"{$this->table}.user_id",
'users.first_name as user_name',
"{$this->table}.status",
"{$this->table}.created_at",
"{$this->table}.deleted_at"
)
->leftJoin('restaurants', 'restaurants.id', '=', "{$this->table}.restaurant_id")
->leftJoin('kitchens', 'kitchens.id', '=', "{$this->table}.kitchen_id")
->leftJoin('users', 'users.id', '=', "{$this->table}.user_id");
}
protected function filterSearchQuery(Builder|EloquentBuilder $query, string $searchedText): Builder
{
$searchable = "%$searchedText%";
return $query->where("{$this->table}.kitchen_id", 'LIKE', $searchable)
->orWhere("{$this->table}.user_id", 'LIKE', $searchable)
->orWhere("{$this->table}.status", 'LIKE', $searchable);
}
public function getAll(array $filterData = []): Paginator
{
$filter = $this->getFilterData($filterData);
$query = $this->getKitchenAssignQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
if (! empty($filter['search'])) {
$query = $this->filterSearchQuery($query, $filter['search']);
}
return $query
->orderBy($filter['orderBy'], $filter['order'])
->paginate($filter['perPage']);
}
public function getCount(array $filterData = []): int
{
$filter = $this->getFilterData($filterData);
$query = $this->getQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
return $query->count();
}
/**
* @throws Exception
*/
public function getByColumn(string $columnName, $columnValue, array $selects = ['*']): ?object
{
$item = $this->getKitchenAssignQuery()
->where($columnName, $columnValue)
->first($selects);
if (empty($item)) {
throw new Exception(
$this->getExceptionMessage(static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE),
Response::HTTP_NOT_FOUND
);
}
return $item;
}
/**
* @throws Exception
*/
public function create(array $data): object
{
$data = $this->prepareForDB($data);
$id = $this->getQuery()->insertGetId($data);
return KitchenAssign::find($id);
}
/**
* @throws Exception
*/
public function update(int $id, array $data): object
{
$item = KitchenAssign::findOrFail($id);
$data = $this->prepareForDB($data, $item);
parent::update($id, $data);
return $this->getById($id);
}
/**
* @throws Exception
*/
public function prepareForDB(array $data, ?object $item = null): array
{
$data = parent::prepareForDB($data, $item);
if (empty($item)) {
$data['created_at'] = now();
$data['restaurant_id'] = $this->getCurrentRestaurantId();
$data['status'] = 1;
if (! empty($data['image']) && $data['image'] instanceof \Illuminate\Http\UploadedFile) {
$data['image'] = fileUploader('Restaurant/', 'png', $data['image']);
}
} else {
if (! empty($data['image']) && $data['image'] instanceof \Illuminate\Http\UploadedFile) {
$data['image'] = fileUploader('Restaurant/', 'png', $data['image'], $item->image);
}
$data['updated_at'] = now();
}
return $data;
}
protected function getExceptionMessages(): array
{
return [
static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE => 'KitchenAssign does not exist.',
static::MESSAGE_ITEM_COULD_NOT_BE_DELETED => 'KitchenAssign could not be deleted.',
];
}
}

View File

@@ -0,0 +1,172 @@
<?php
namespace Modules\Restaurant\Repositories;
use App\Abstracts\EntityRepository;
use Exception;
use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Query\Builder;
use Modules\Restaurant\Models\Kitchen;
use Symfony\Component\HttpFoundation\Response;
class KitchenRepository extends EntityRepository
{
public string $table = Kitchen::TABLE_NAME;
protected array $fillableColumns = [
'restaurant_id',
'name',
'serial',
'status',
'created_at',
'updated_at',
'deleted_at',
];
protected function getQuery(): Builder
{
return parent::getQuery();
}
protected function getFilterData(array $filterData = []): array
{
$defaultArgs = [
'perPage' => 10,
'search' => '',
'orderBy' => 'id',
'order' => 'desc',
'with_deleted' => false,
];
return array_merge($defaultArgs, $filterData);
}
private function getKitchenQuery(): Builder
{
return $this->getQuery()
->select(
"{$this->table}.id",
"{$this->table}.restaurant_id",
"{$this->table}.name",
"{$this->table}.serial",
"{$this->table}.status",
"{$this->table}.created_at",
"{$this->table}.deleted_at"
);
}
protected function filterSearchQuery(Builder|EloquentBuilder $query, string $searchedText): Builder
{
$searchable = "%$searchedText%";
return $query->where("{$this->table}.name", 'LIKE', $searchable)
->orWhere("{$this->table}.status", 'LIKE', $searchable);
}
public function getAll(array $filterData = []): Paginator
{
$filter = $this->getFilterData($filterData);
$query = $this->getKitchenQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
if (! empty($filter['search'])) {
$query = $this->filterSearchQuery($query, $filter['search']);
}
return $query
->orderBy($filter['orderBy'], $filter['order'])
->paginate($filter['perPage']);
}
public function getCount(array $filterData = []): int
{
$filter = $this->getFilterData($filterData);
$query = $this->getQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
return $query->count();
}
/**
* @throws Exception
*/
public function getByColumn(string $columnName, $columnValue, array $selects = ['*']): ?object
{
$item = $this->getKitchenQuery()
->where($columnName, $columnValue)
->first($selects);
if (empty($item)) {
throw new Exception(
$this->getExceptionMessage(static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE),
Response::HTTP_NOT_FOUND
);
}
return $item;
}
/**
* @throws Exception
*/
public function create(array $data): object
{
$data = $this->prepareForDB($data);
$id = $this->getQuery()->insertGetId($data);
return Kitchen::find($id);
}
/**
* @throws Exception
*/
public function update(int $id, array $data): object
{
$item = Kitchen::findOrFail($id);
$data = $this->prepareForDB($data, $item);
parent::update($id, $data);
return $this->getById($id);
}
/**
* @throws Exception
*/
public function prepareForDB(array $data, ?object $item = null): array
{
$data = parent::prepareForDB($data, $item);
if (empty($item)) {
$data['created_at'] = now();
$data['restaurant_id'] = $this->getCurrentRestaurantId();
$data['status'] = 1;
if (! empty($data['image']) && $data['image'] instanceof \Illuminate\Http\UploadedFile) {
$data['image'] = fileUploader('Restaurant/', 'png', $data['image']);
}
} else {
if (! empty($data['image']) && $data['image'] instanceof \Illuminate\Http\UploadedFile) {
$data['image'] = fileUploader('Restaurant/', 'png', $data['image'], $item->image);
}
$data['updated_at'] = now();
}
return $data;
}
protected function getExceptionMessages(): array
{
return [
static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE => 'Kitchen does not exist.',
static::MESSAGE_ITEM_COULD_NOT_BE_DELETED => 'Kitchen could not be deleted.',
];
}
}

View File

@@ -0,0 +1,188 @@
<?php
namespace Modules\Restaurant\Repositories;
use App\Abstracts\EntityRepository;
use Exception;
use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Query\Builder;
use Illuminate\Support\Facades\Auth;
use Modules\Restaurant\Models\LoyaltyPoint;
use Symfony\Component\HttpFoundation\Response;
class LoyaltyPointRepository extends EntityRepository
{
public string $table = LoyaltyPoint::TABLE_NAME;
protected array $fillableColumns = [
'restaurant_id',
'user_id',
'order_id',
'food_item_id',
'points',
'type',
'reason',
'status',
'created_at',
'updated_at',
'deleted_at',
];
protected function getQuery(): Builder
{
return parent::getQuery();
}
protected function getFilterData(array $filterData = []): array
{
$defaultArgs = [
'perPage' => 10,
'search' => '',
'orderBy' => 'id',
'order' => 'desc',
'with_deleted' => false,
];
return array_merge($defaultArgs, $filterData);
}
private function getLoyaltyPointQuery(): Builder
{
return $this->getQuery()
->leftJoin('users', 'users.id', '=', "{$this->table}.user_id")
->leftJoin('food_items', 'food_items.id', '=', "{$this->table}.food_item_id")
->leftJoin('orders', 'orders.id', '=', "{$this->table}.order_id")
->select(
"{$this->table}.id",
"{$this->table}.restaurant_id",
"{$this->table}.user_id",
'users.first_name as user_name',
"{$this->table}.order_id",
'orders.order_number as order_number',
"{$this->table}.food_item_id",
'food_items.name as food_item_name',
"{$this->table}.points",
"{$this->table}.type",
"{$this->table}.reason",
"{$this->table}.status",
"{$this->table}.created_at",
"{$this->table}.updated_at",
"{$this->table}.deleted_at",
);
}
protected function filterSearchQuery(Builder|EloquentBuilder $query, string $searchedText): Builder
{
$searchable = "%$searchedText%";
return $query->where("{$this->table}.name", 'LIKE', $searchable)
->orWhere("{$this->table}.status", 'LIKE', $searchable);
}
public function getAll(array $filterData = []): Paginator
{
$filter = $this->getFilterData($filterData);
$query = $this->getLoyaltyPointQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
if (! empty($filter['search'])) {
$query = $this->filterSearchQuery($query, $filter['search']);
}
return $query
->orderBy($filter['orderBy'], $filter['order'])
->paginate($filter['perPage']);
}
public function getCount(array $filterData = []): int
{
$filter = $this->getFilterData($filterData);
$query = $this->getQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
return $query->count();
}
/**
* @throws Exception
*/
public function getByColumn(string $columnName, $columnValue, array $selects = ['*']): ?object
{
$item = $this->getLoyaltyPointQuery()
->where($columnName, $columnValue)
->first($selects);
if (empty($item)) {
throw new Exception(
$this->getExceptionMessage(static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE),
Response::HTTP_NOT_FOUND
);
}
return $item;
}
/**
* @throws Exception
*/
public function create(array $data): object
{
$data = $this->prepareForDB($data);
$id = $this->getQuery()->insertGetId($data);
return LoyaltyPoint::find($id);
}
/**
* @throws Exception
*/
public function update(int $id, array $data): object
{
$item = LoyaltyPoint::findOrFail($id);
$data = $this->prepareForDB($data, $item);
parent::update($id, $data);
return $this->getById($id);
}
/**
* @throws Exception
*/
public function prepareForDB(array $data, ?object $item = null): array
{
$data = parent::prepareForDB($data, $item);
if (empty($item)) {
$data['created_at'] = now();
$data['restaurant_id'] = $this->getCurrentRestaurantId();
$data['user_id'] = Auth::id();
if (! empty($data['image']) && $data['image'] instanceof \Illuminate\Http\UploadedFile) {
$data['image'] = fileUploader('Restaurant/', 'png', $data['image']);
}
} else {
if (! empty($data['image']) && $data['image'] instanceof \Illuminate\Http\UploadedFile) {
$data['image'] = fileUploader('Restaurant/', 'png', $data['image'], $item->image);
}
$data['updated_at'] = now();
}
return $data;
}
protected function getExceptionMessages(): array
{
return [
static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE => 'LoyaltyPoint does not exist.',
static::MESSAGE_ITEM_COULD_NOT_BE_DELETED => 'LoyaltyPoint could not be deleted.',
];
}
}

View File

@@ -0,0 +1,170 @@
<?php
namespace Modules\Restaurant\Repositories;
use App\Abstracts\EntityRepository;
use Exception;
use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Query\Builder;
use Modules\Restaurant\Models\LoyaltyPointSetting;
use Symfony\Component\HttpFoundation\Response;
class LoyaltyPointSettingRepository extends EntityRepository
{
public string $table = LoyaltyPointSetting::TABLE_NAME;
protected array $fillableColumns = [
'restaurant_id',
'name',
'from_amount',
'to_amount',
'amount',
'earn_point',
'status',
'created_at',
'updated_at',
'deleted_at',
];
protected function getQuery(): Builder
{
return parent::getQuery();
}
protected function getFilterData(array $filterData = []): array
{
$defaultArgs = [
'perPage' => 10,
'search' => '',
'orderBy' => 'id',
'order' => 'desc',
'with_deleted' => false,
];
return array_merge($defaultArgs, $filterData);
}
private function getLoyaltyPointSettingQuery(): Builder
{
return $this->getQuery()
->select(
"{$this->table}.id",
"{$this->table}.restaurant_id",
"{$this->table}.name",
"{$this->table}.from_amount",
"{$this->table}.to_amount",
"{$this->table}.amount",
"{$this->table}.earn_point",
"{$this->table}.status",
"{$this->table}.created_at",
"{$this->table}.deleted_at"
);
}
protected function filterSearchQuery(Builder|EloquentBuilder $query, string $searchedText): Builder
{
$searchable = "%$searchedText%";
return $query->where("{$this->table}.amount", 'LIKE', $searchable)
->orWhere("{$this->table}.status", 'LIKE', $searchable);
}
public function getAll(array $filterData = []): Paginator
{
$filter = $this->getFilterData($filterData);
$query = $this->getLoyaltyPointSettingQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
if (! empty($filter['search'])) {
$query = $this->filterSearchQuery($query, $filter['search']);
}
return $query
->orderBy($filter['orderBy'], $filter['order'])
->paginate($filter['perPage']);
}
public function getCount(array $filterData = []): int
{
$filter = $this->getFilterData($filterData);
$query = $this->getQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
return $query->count();
}
/**
* @throws Exception
*/
public function getByColumn(string $columnName, $columnValue, array $selects = ['*']): ?object
{
$item = $this->getLoyaltyPointSettingQuery()
->where($columnName, $columnValue)
->first($selects);
if (empty($item)) {
throw new Exception(
$this->getExceptionMessage(static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE),
Response::HTTP_NOT_FOUND
);
}
return $item;
}
/**
* @throws Exception
*/
public function create(array $data): object
{
$data = $this->prepareForDB($data);
$id = $this->getQuery()->insertGetId($data);
return LoyaltyPointSetting::find($id);
}
/**
* @throws Exception
*/
public function update(int $id, array $data): object
{
$item = LoyaltyPointSetting::findOrFail($id);
$data = $this->prepareForDB($data, $item);
parent::update($id, $data);
return $this->getById($id);
}
/**
* @throws Exception
*/
public function prepareForDB(array $data, ?object $item = null): array
{
$data = parent::prepareForDB($data, $item);
if (empty($item)) {
$data['created_at'] = now();
$data['restaurant_id'] = $this->getCurrentRestaurantId();
$data['status'] = 1;
} else {
$data['updated_at'] = now();
}
return $data;
}
protected function getExceptionMessages(): array
{
return [
static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE => 'LoyaltyPointSetting does not exist.',
static::MESSAGE_ITEM_COULD_NOT_BE_DELETED => 'LoyaltyPointSetting could not be deleted.',
];
}
}

View File

@@ -0,0 +1,182 @@
<?php
namespace Modules\Restaurant\Repositories;
use App\Abstracts\EntityRepository;
use Exception;
use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Query\Builder;
use Illuminate\Support\Facades\Auth;
use Modules\Restaurant\Models\LoyaltyRedemption;
use Symfony\Component\HttpFoundation\Response;
class LoyaltyRedemptionRepository extends EntityRepository
{
public string $table = LoyaltyRedemption::TABLE_NAME;
protected array $fillableColumns = [
'restaurant_id',
'user_id',
'food_item_id',
'points_used',
'price',
'status',
'created_at',
'updated_at',
'deleted_at',
];
protected function getQuery(): Builder
{
return parent::getQuery();
}
protected function getFilterData(array $filterData = []): array
{
$defaultArgs = [
'perPage' => 10,
'search' => '',
'orderBy' => 'id',
'order' => 'desc',
'with_deleted' => false,
];
return array_merge($defaultArgs, $filterData);
}
private function getLoyaltyRedemptionQuery(): Builder
{
return $this->getQuery()
->leftJoin('users', 'users.id', '=', "{$this->table}.user_id")
->leftJoin('food_items', 'food_items.id', '=', "{$this->table}.food_item_id")
->select(
"{$this->table}.id",
"{$this->table}.restaurant_id",
"{$this->table}.user_id",
'users.first_name as user_name',
"{$this->table}.food_item_id",
'food_items.name as food_item_name',
"{$this->table}.points_used",
"{$this->table}.price",
"{$this->table}.status",
"{$this->table}.created_at",
"{$this->table}.updated_at",
"{$this->table}.deleted_at"
);
}
protected function filterSearchQuery(Builder|EloquentBuilder $query, string $searchedText): Builder
{
$searchable = "%$searchedText%";
return $query->where("{$this->table}.name", 'LIKE', $searchable)
->orWhere("{$this->table}.status", 'LIKE', $searchable);
}
public function getAll(array $filterData = []): Paginator
{
$filter = $this->getFilterData($filterData);
$query = $this->getLoyaltyRedemptionQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
if (! empty($filter['search'])) {
$query = $this->filterSearchQuery($query, $filter['search']);
}
return $query
->orderBy($filter['orderBy'], $filter['order'])
->paginate($filter['perPage']);
}
public function getCount(array $filterData = []): int
{
$filter = $this->getFilterData($filterData);
$query = $this->getQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
return $query->count();
}
/**
* @throws Exception
*/
public function getByColumn(string $columnName, $columnValue, array $selects = ['*']): ?object
{
$item = $this->getLoyaltyRedemptionQuery()
->where($columnName, $columnValue)
->first($selects);
if (empty($item)) {
throw new Exception(
$this->getExceptionMessage(static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE),
Response::HTTP_NOT_FOUND
);
}
return $item;
}
/**
* @throws Exception
*/
public function create(array $data): object
{
$data = $this->prepareForDB($data);
$id = $this->getQuery()->insertGetId($data);
return LoyaltyRedemption::find($id);
}
/**
* @throws Exception
*/
public function update(int $id, array $data): object
{
$item = LoyaltyRedemption::findOrFail($id);
$data = $this->prepareForDB($data, $item);
parent::update($id, $data);
return $this->getById($id);
}
/**
* @throws Exception
*/
public function prepareForDB(array $data, ?object $item = null): array
{
$data = parent::prepareForDB($data, $item);
if (empty($item)) {
$data['created_at'] = now();
$data['restaurant_id'] = $this->getCurrentRestaurantId();
$data['user_id'] = Auth::id();
if (! empty($data['image']) && $data['image'] instanceof \Illuminate\Http\UploadedFile) {
$data['image'] = fileUploader('Restaurant/', 'png', $data['image']);
}
} else {
if (! empty($data['image']) && $data['image'] instanceof \Illuminate\Http\UploadedFile) {
$data['image'] = fileUploader('Restaurant/', 'png', $data['image'], $item->image);
}
$data['updated_at'] = now();
}
return $data;
}
protected function getExceptionMessages(): array
{
return [
static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE => 'LoyaltyRedemption does not exist.',
static::MESSAGE_ITEM_COULD_NOT_BE_DELETED => 'LoyaltyRedemption could not be deleted.',
];
}
}

View File

@@ -0,0 +1,179 @@
<?php
namespace Modules\Restaurant\Repositories;
use App\Abstracts\EntityRepository;
use Exception;
use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Query\Builder;
use Modules\Restaurant\Models\MenuCategory;
use Symfony\Component\HttpFoundation\Response;
class MenuCategoryRepository extends EntityRepository
{
public string $table = MenuCategory::TABLE_NAME;
protected array $fillableColumns = [
'restaurant_id',
'name',
'slug',
'icon',
'description',
'priority',
'status',
'created_at',
'updated_at',
'deleted_at',
];
protected function getQuery(): Builder
{
return parent::getQuery();
}
protected function getFilterData(array $filterData = []): array
{
$defaultArgs = [
'perPage' => 10,
'search' => '',
'orderBy' => 'id',
'order' => 'desc',
'with_deleted' => false,
];
return array_merge($defaultArgs, $filterData);
}
private function getMenuCategoryQuery(): Builder
{
return $this->getQuery()
->select(
"{$this->table}.id",
"{$this->table}.restaurant_id",
"{$this->table}.name",
"{$this->table}.slug",
"{$this->table}.icon",
"{$this->table}.description",
"{$this->table}.priority",
"{$this->table}.status",
"{$this->table}.created_at",
"{$this->table}.updated_at",
"{$this->table}.deleted_at",
);
}
protected function filterSearchQuery(Builder|EloquentBuilder $query, string $searchedText): Builder
{
$searchable = "%$searchedText%";
return $query->where("{$this->table}.name", 'LIKE', $searchable)
->orWhere("{$this->table}.status", 'LIKE', $searchable);
}
public function getAll(array $filterData = []): Paginator
{
$filter = $this->getFilterData($filterData);
$query = $this->getMenuCategoryQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
if (! empty($filter['search'])) {
$query = $this->filterSearchQuery($query, $filter['search']);
}
return $query
->orderBy($filter['orderBy'], $filter['order'])
->paginate($filter['perPage']);
}
public function getCount(array $filterData = []): int
{
$filter = $this->getFilterData($filterData);
$query = $this->getQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
return $query->count();
}
/**
* @throws Exception
*/
public function getByColumn(string $columnName, $columnValue, array $selects = ['*']): ?object
{
$item = $this->getMenuCategoryQuery()
->where($columnName, $columnValue)
->first($selects);
if (empty($item)) {
throw new Exception(
$this->getExceptionMessage(static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE),
Response::HTTP_NOT_FOUND
);
}
return $item;
}
/**
* @throws Exception
*/
public function create(array $data): object
{
$data = $this->prepareForDB($data);
$id = $this->getQuery()->insertGetId($data);
return MenuCategory::find($id);
}
/**
* @throws Exception
*/
public function update(int $id, array $data): object
{
$item = MenuCategory::findOrFail($id);
$data = $this->prepareForDB($data, $item);
parent::update($id, $data);
return $this->getById($id);
}
/**
* @throws Exception
*/
public function prepareForDB(array $data, ?object $item = null): array
{
$data = parent::prepareForDB($data, $item);
if (empty($item)) {
$data['created_at'] = now();
$data['restaurant_id'] = $this->getCurrentRestaurantId();
$data['status'] = 1;
if (! empty($data['icon']) && $data['icon'] instanceof \Illuminate\Http\UploadedFile) {
$data['icon'] = fileUploader('menu_categories/', 'png', $data['icon']);
}
} else {
if (! empty($data['icon']) && $data['icon'] instanceof \Illuminate\Http\UploadedFile) {
$data['icon'] = fileUploader('menu_categories/', 'png', $data['icon'], $item->icon);
}
$data['updated_at'] = now();
}
return $data;
}
protected function getExceptionMessages(): array
{
return [
static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE => 'MenuCategory does not exist.',
static::MESSAGE_ITEM_COULD_NOT_BE_DELETED => 'MenuCategory could not be deleted.',
];
}
}

View File

@@ -0,0 +1,173 @@
<?php
namespace Modules\Restaurant\Repositories;
use App\Abstracts\EntityRepository;
use Exception;
use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Query\Builder;
use Modules\Restaurant\Models\MenuSection;
use Symfony\Component\HttpFoundation\Response;
class MenuSectionRepository extends EntityRepository
{
public string $table = MenuSection::TABLE_NAME;
protected array $fillableColumns = [
'restaurant_id',
'menu_category_id',
'name',
'slug',
'description',
'priority',
'status',
'created_at',
'updated_at',
'deleted_at',
];
protected function getQuery(): Builder
{
return parent::getQuery();
}
protected function getFilterData(array $filterData = []): array
{
$defaultArgs = [
'perPage' => 10,
'search' => '',
'orderBy' => 'id',
'order' => 'desc',
'with_deleted' => false,
];
return array_merge($defaultArgs, $filterData);
}
private function getMenuSectionQuery(): Builder
{
return $this->getQuery()
->select(
"{$this->table}.id",
"{$this->table}.restaurant_id",
"{$this->table}.menu_category_id",
'menu_categories.name as category_name',
"{$this->table}.name",
"{$this->table}.slug",
"{$this->table}.description",
"{$this->table}.priority",
"{$this->table}.status",
"{$this->table}.created_at",
"{$this->table}.updated_at",
"{$this->table}.deleted_at"
)
->leftJoin('menu_categories', 'menu_categories.id', '=', "{$this->table}.menu_category_id");
}
protected function filterSearchQuery(Builder|EloquentBuilder $query, string $searchedText): Builder
{
$searchable = "%$searchedText%";
return $query->where("{$this->table}.name", 'LIKE', $searchable)
->orWhere("{$this->table}.status", 'LIKE', $searchable);
}
public function getAll(array $filterData = []): Paginator
{
$filter = $this->getFilterData($filterData);
$query = $this->getMenuSectionQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
if (! empty($filter['search'])) {
$query = $this->filterSearchQuery($query, $filter['search']);
}
return $query
->orderBy($filter['orderBy'], $filter['order'])
->paginate($filter['perPage']);
}
public function getCount(array $filterData = []): int
{
$filter = $this->getFilterData($filterData);
$query = $this->getQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
return $query->count();
}
/**
* @throws Exception
*/
public function getByColumn(string $columnName, $columnValue, array $selects = ['*']): ?object
{
$item = $this->getMenuSectionQuery()
->where($columnName, $columnValue)
->first($selects);
if (empty($item)) {
throw new Exception(
$this->getExceptionMessage(static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE),
Response::HTTP_NOT_FOUND
);
}
return $item;
}
/**
* @throws Exception
*/
public function create(array $data): object
{
$data = $this->prepareForDB($data);
$id = $this->getQuery()->insertGetId($data);
return MenuSection::find($id);
}
/**
* @throws Exception
*/
public function update(int $id, array $data): object
{
$item = MenuSection::findOrFail($id);
$data = $this->prepareForDB($data, $item);
parent::update($id, $data);
return $this->getById($id);
}
/**
* @throws Exception
*/
public function prepareForDB(array $data, ?object $item = null): array
{
$data = parent::prepareForDB($data, $item);
if (empty($item)) {
$data['created_at'] = now();
$data['restaurant_id'] = $this->getCurrentRestaurantId();
$data['status'] = 1;
} else {
$data['updated_at'] = now();
}
return $data;
}
protected function getExceptionMessages(): array
{
return [
static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE => 'MenuSection does not exist.',
static::MESSAGE_ITEM_COULD_NOT_BE_DELETED => 'MenuSection could not be deleted.',
];
}
}

View File

@@ -0,0 +1,181 @@
<?php
namespace Modules\Restaurant\Repositories;
use App\Abstracts\EntityRepository;
use Exception;
use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Query\Builder;
use Modules\Restaurant\Models\MenuType;
use Symfony\Component\HttpFoundation\Response;
class MenuTypeRepository extends EntityRepository
{
public string $table = MenuType::TABLE_NAME;
protected array $fillableColumns = [
'restaurant_id',
'name',
'slug',
'icon',
'description',
'display_order',
'status',
'is_default',
'created_at',
'updated_at',
'deleted_at',
];
protected function getQuery(): Builder
{
return parent::getQuery();
}
protected function getFilterData(array $filterData = []): array
{
$defaultArgs = [
'perPage' => 10,
'search' => '',
'orderBy' => 'id',
'order' => 'desc',
'with_deleted' => false,
];
return array_merge($defaultArgs, $filterData);
}
private function getMenuTypeQuery(): Builder
{
return $this->getQuery()
->select(
"{$this->table}.id",
"{$this->table}.restaurant_id",
"{$this->table}.name",
"{$this->table}.slug",
"{$this->table}.icon",
"{$this->table}.description",
"{$this->table}.display_order",
"{$this->table}.status",
"{$this->table}.is_default",
"{$this->table}.created_at",
"{$this->table}.updated_at",
"{$this->table}.deleted_at",
);
}
protected function filterSearchQuery(Builder|EloquentBuilder $query, string $searchedText): Builder
{
$searchable = "%$searchedText%";
return $query->where("{$this->table}.name", 'LIKE', $searchable)
->orWhere("{$this->table}.status", 'LIKE', $searchable);
}
public function getAll(array $filterData = []): Paginator
{
$filter = $this->getFilterData($filterData);
$query = $this->getMenuTypeQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
if (! empty($filter['search'])) {
$query = $this->filterSearchQuery($query, $filter['search']);
}
return $query
->orderBy($filter['orderBy'], $filter['order'])
->paginate($filter['perPage']);
}
public function getCount(array $filterData = []): int
{
$filter = $this->getFilterData($filterData);
$query = $this->getQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
return $query->count();
}
/**
* @throws Exception
*/
public function getByColumn(string $columnName, $columnValue, array $selects = ['*']): ?object
{
$item = $this->getMenuTypeQuery()
->where($columnName, $columnValue)
->first($selects);
if (empty($item)) {
throw new Exception(
$this->getExceptionMessage(static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE),
Response::HTTP_NOT_FOUND
);
}
return $item;
}
/**
* @throws Exception
*/
public function create(array $data): object
{
$data = $this->prepareForDB($data);
$id = $this->getQuery()->insertGetId($data);
return MenuType::find($id);
}
/**
* @throws Exception
*/
public function update(int $id, array $data): object
{
$item = MenuType::findOrFail($id);
$data = $this->prepareForDB($data, $item);
parent::update($id, $data);
return $this->getById($id);
}
/**
* @throws Exception
*/
public function prepareForDB(array $data, ?object $item = null): array
{
$data = parent::prepareForDB($data, $item);
if (empty($item)) {
$data['created_at'] = now();
$data['restaurant_id'] = $this->getCurrentRestaurantId();
$data['status'] = 1;
if (! empty($data['icon']) && $data['icon'] instanceof \Illuminate\Http\UploadedFile) {
$data['icon'] = fileUploader('menu_types/', 'png', $data['icon']);
}
} else {
if (! empty($data['icon']) && $data['icon'] instanceof \Illuminate\Http\UploadedFile) {
$data['icon'] = fileUploader('menu_types/', 'png', $data['icon'], $item->icon);
}
$data['updated_at'] = now();
}
return $data;
}
protected function getExceptionMessages(): array
{
return [
static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE => 'MenuType does not exist.',
static::MESSAGE_ITEM_COULD_NOT_BE_DELETED => 'MenuType could not be deleted.',
];
}
}

View File

@@ -0,0 +1,169 @@
<?php
namespace Modules\Restaurant\Repositories;
use App\Abstracts\EntityRepository;
use Exception;
use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Query\Builder;
use Modules\Restaurant\Models\OrderTracking;
use Symfony\Component\HttpFoundation\Response;
class OrderTrackingRepository extends EntityRepository
{
public string $table = OrderTracking::TABLE_NAME;
protected array $fillableColumns = [
'order_id',
'delivery_boy_id',
'status',
'latitude',
'longitude',
'location_name',
'note',
'tracked_at',
];
protected function getQuery(): Builder
{
return parent::getQuery();
}
protected function getFilterData(array $filterData = []): array
{
$defaultArgs = [
'perPage' => 10,
'search' => '',
'orderBy' => 'id',
'order' => 'desc',
'with_deleted' => false,
];
return array_merge($defaultArgs, $filterData);
}
private function getOrderTrackingQuery(): Builder
{
return $this->getQuery()
->select(
"{$this->table}.id",
"{$this->table}.order_id",
"{$this->table}.delivery_boy_id",
"{$this->table}.status",
"{$this->table}.latitude",
"{$this->table}.longitude",
"{$this->table}.location_name",
"{$this->table}.note",
"{$this->table}.tracked_at",
"{$this->table}.created_at",
"{$this->table}.deleted_at"
);
}
protected function filterSearchQuery(Builder|EloquentBuilder $query, string $searchedText): Builder
{
$searchable = "%$searchedText%";
return $query->where("{$this->table}.name", 'LIKE', $searchable)
->orWhere("{$this->table}.status", 'LIKE', $searchable);
}
public function getAll(array $filterData = []): Paginator
{
$filter = $this->getFilterData($filterData);
$query = $this->getOrderTrackingQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
if (! empty($filter['search'])) {
$query = $this->filterSearchQuery($query, $filter['search']);
}
return $query
->orderBy($filter['orderBy'], $filter['order'])
->paginate($filter['perPage']);
}
public function getCount(array $filterData = []): int
{
$filter = $this->getFilterData($filterData);
$query = $this->getQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
return $query->count();
}
/**
* @throws Exception
*/
public function getByColumn(string $columnName, $columnValue, array $selects = ['*']): ?object
{
$item = $this->getOrderTrackingQuery()
->where($columnName, $columnValue)
->first($selects);
if (empty($item)) {
throw new Exception(
$this->getExceptionMessage(static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE),
Response::HTTP_NOT_FOUND
);
}
return $item;
}
/**
* @throws Exception
*/
public function create(array $data): object
{
$data = $this->prepareForDB($data);
$id = $this->getQuery()->insertGetId($data);
return OrderTracking::find($id);
}
/**
* @throws Exception
*/
public function update(int $id, array $data): object
{
$item = OrderTracking::findOrFail($id);
$data = $this->prepareForDB($data, $item);
parent::update($id, $data);
return $this->getById($id);
}
/**
* @throws Exception
*/
public function prepareForDB(array $data, ?object $item = null): array
{
$data = parent::prepareForDB($data, $item);
if (empty($item)) {
$data['created_at'] = now();
$data['restaurant_id'] = $this->getCurrentRestaurantId();
$data['status'] = 1;
} else {
$data['updated_at'] = now();
}
return $data;
}
protected function getExceptionMessages(): array
{
return [
static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE => 'OrderTracking does not exist.',
static::MESSAGE_ITEM_COULD_NOT_BE_DELETED => 'OrderTracking could not be deleted.',
];
}
}

View File

@@ -0,0 +1,169 @@
<?php
namespace Modules\Restaurant\Repositories;
use App\Abstracts\EntityRepository;
use Exception;
use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Query\Builder;
use Modules\Restaurant\Models\PaymentMethod;
use Symfony\Component\HttpFoundation\Response;
class PaymentMethodRepository extends EntityRepository
{
public string $table = PaymentMethod::TABLE_NAME;
protected array $fillableColumns = [
'restaurant_id',
'name',
'type',
'credentials',
'is_default',
'status',
'created_at',
'updated_at',
'deleted_at',
];
protected function getQuery(): Builder
{
return parent::getQuery();
}
protected function getFilterData(array $filterData = []): array
{
$defaultArgs = [
'perPage' => 10,
'search' => '',
'orderBy' => 'id',
'order' => 'desc',
'with_deleted' => false,
];
return array_merge($defaultArgs, $filterData);
}
private function getPaymentMethodQuery(): Builder
{
return $this->getQuery()
->select(
"{$this->table}.id",
"{$this->table}.restaurant_id",
"{$this->table}.name",
"{$this->table}.type",
"{$this->table}.credentials",
"{$this->table}.is_default",
"{$this->table}.status",
"{$this->table}.created_at",
"{$this->table}.updated_at",
"{$this->table}.deleted_at",
);
}
protected function filterSearchQuery(Builder|EloquentBuilder $query, string $searchedText): Builder
{
$searchable = "%$searchedText%";
return $query->where("{$this->table}.name", 'LIKE', $searchable)
->orWhere("{$this->table}.status", 'LIKE', $searchable);
}
public function getAll(array $filterData = []): Paginator
{
$filter = $this->getFilterData($filterData);
$query = $this->getPaymentMethodQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
if (! empty($filter['search'])) {
$query = $this->filterSearchQuery($query, $filter['search']);
}
return $query
->orderBy($filter['orderBy'], $filter['order'])
->paginate($filter['perPage']);
}
public function getCount(array $filterData = []): int
{
$filter = $this->getFilterData($filterData);
$query = $this->getQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
return $query->count();
}
/**
* @throws Exception
*/
public function getByColumn(string $columnName, $columnValue, array $selects = ['*']): ?object
{
$item = $this->getPaymentMethodQuery()
->where($columnName, $columnValue)
->first($selects);
if (empty($item)) {
throw new Exception(
$this->getExceptionMessage(static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE),
Response::HTTP_NOT_FOUND
);
}
return $item;
}
/**
* @throws Exception
*/
public function create(array $data): object
{
$data = $this->prepareForDB($data);
$id = $this->getQuery()->insertGetId($data);
return PaymentMethod::find($id);
}
/**
* @throws Exception
*/
public function update(int $id, array $data): object
{
$item = PaymentMethod::findOrFail($id);
$data = $this->prepareForDB($data, $item);
parent::update($id, $data);
return $this->getById($id);
}
/**
* @throws Exception
*/
public function prepareForDB(array $data, ?object $item = null): array
{
$data = parent::prepareForDB($data, $item);
if (empty($item)) {
$data['created_at'] = now();
$data['restaurant_id'] = $this->getCurrentRestaurantId();
$data['status'] = 1;
} else {
$data['updated_at'] = now();
}
return $data;
}
protected function getExceptionMessages(): array
{
return [
static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE => 'PaymentMethod does not exist.',
static::MESSAGE_ITEM_COULD_NOT_BE_DELETED => 'PaymentMethod could not be deleted.',
];
}
}

View File

@@ -0,0 +1,98 @@
<?php
namespace Modules\Restaurant\Repositories;
use Modules\Restaurant\Models\Purchase;
class PurchaseRepository
{
public function getAll($filters)
{
$restaurantId = getUserRestaurantId();
$query = Purchase::with([
'supplier:id,name,phone',
'creator:id,first_name',
'items.ingredient:id,name,unit_id',
])
->where('restaurant_id', $restaurantId);
/*
|--------------------------------------------------------------------------
| 🔍 Search Filters
|--------------------------------------------------------------------------
*/
if (! empty($filters['search'])) {
$search = $filters['search'];
$query->where(function ($q) use ($search) {
$q->where('invoice_no', 'like', "%{$search}%")
->orWhereHas('supplier', function ($sq) use ($search) {
$sq->where('name', 'like', "%{$search}%")
->orWhere('phone', 'like', "%{$search}%");
});
});
}
/*
|--------------------------------------------------------------------------
| 🔎 Filter: Supplier
|--------------------------------------------------------------------------
*/
if (! empty($filters['supplier_id'])) {
$query->where('supplier_id', $filters['supplier_id']);
}
/*
|--------------------------------------------------------------------------
| 📅 Filter: Purchase Date Range
|--------------------------------------------------------------------------
*/
if (! empty($filters['start_date']) && ! empty($filters['end_date'])) {
$query->whereBetween('purchase_date', [
$filters['start_date'],
$filters['end_date'],
]);
}
/*
|--------------------------------------------------------------------------
| 🧾 Filter: Payment Status
|--------------------------------------------------------------------------
*/
if (! empty($filters['payment_status'])) {
$query->where('payment_status', $filters['payment_status']);
}
/*
|--------------------------------------------------------------------------
| 🧰 Filter: Purchase Type
|--------------------------------------------------------------------------
*/
if (! empty($filters['purchase_type'])) {
$query->where('purchase_type', $filters['purchase_type']);
}
/*
|--------------------------------------------------------------------------
| 🔽 Sorting
|--------------------------------------------------------------------------
| sort_by = any column (id, invoice_no, purchase_date)
| sort_order = asc / desc
*/
$sortBy = $filters['sort_by'] ?? 'id';
$sortOrder = $filters['sort_order'] ?? 'desc';
$query->orderBy($sortBy, $sortOrder);
/*
|--------------------------------------------------------------------------
| 📄 Pagination
|--------------------------------------------------------------------------
*/
$perPage = $filters['per_page'] ?? 15;
return $query->paginate($perPage);
}
}

View File

@@ -0,0 +1,197 @@
<?php
namespace Modules\Restaurant\Repositories;
use App\Abstracts\EntityRepository;
use Exception;
use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Query\Builder;
use Modules\Restaurant\Models\QRMenuSetting;
use Symfony\Component\HttpFoundation\Response;
class QRMenuSettingRepository extends EntityRepository
{
public string $table = QRMenuSetting::TABLE_NAME;
protected array $fillableColumns = [
'restaurant_id',
'name',
'menu_title',
'logo',
'menu_url',
'primary_color',
'secondary_color',
'bg_color',
'template',
'description',
'qr_code_url',
'wifi_name',
'wifi_ssid',
'wifi_password',
'status',
'created_at',
'updated_at',
'deleted_at',
];
protected function getQuery(): Builder
{
return parent::getQuery();
}
protected function getFilterData(array $filterData = []): array
{
$defaultArgs = [
'perPage' => 10,
'search' => '',
'orderBy' => 'id',
'order' => 'desc',
'with_deleted' => false,
];
return array_merge($defaultArgs, $filterData);
}
private function getQRMenuSettingQuery(): Builder
{
return $this->getQuery()
->leftJoin('restaurants', 'restaurants.id', '=', "{$this->table}.restaurant_id")
->select(
"{$this->table}.id",
"{$this->table}.restaurant_id",
'restaurants.name as restaurant_name',
"{$this->table}.name",
"{$this->table}.menu_title",
"{$this->table}.logo",
"{$this->table}.menu_url",
"{$this->table}.primary_color",
"{$this->table}.secondary_color",
"{$this->table}.bg_color",
"{$this->table}.template",
"{$this->table}.description",
"{$this->table}.qr_code_url",
"{$this->table}.wifi_name",
"{$this->table}.wifi_ssid",
"{$this->table}.wifi_password",
"{$this->table}.status",
"{$this->table}.created_at",
"{$this->table}.updated_at",
"{$this->table}.deleted_at",
);
}
protected function filterSearchQuery(Builder|EloquentBuilder $query, string $searchedText): Builder
{
$searchable = "%$searchedText%";
return $query->where("{$this->table}.name", 'LIKE', $searchable)
->orWhere("{$this->table}.status", 'LIKE', $searchable);
}
public function getAll(array $filterData = []): Paginator
{
$filter = $this->getFilterData($filterData);
$query = $this->getQRMenuSettingQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
if (! empty($filter['search'])) {
$query = $this->filterSearchQuery($query, $filter['search']);
}
return $query
->orderBy($filter['orderBy'], $filter['order'])
->paginate($filter['perPage']);
}
public function getCount(array $filterData = []): int
{
$filter = $this->getFilterData($filterData);
$query = $this->getQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
return $query->count();
}
/**
* @throws Exception
*/
public function getByColumn(string $columnName, $columnValue, array $selects = ['*']): ?object
{
$item = $this->getQRMenuSettingQuery()
->where($columnName, $columnValue)
->first($selects);
if (empty($item)) {
throw new Exception(
$this->getExceptionMessage(static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE),
Response::HTTP_NOT_FOUND
);
}
return $item;
}
/**
* @throws Exception
*/
public function create(array $data): object
{
$data = $this->prepareForDB($data);
$id = $this->getQuery()->insertGetId($data);
return QRMenuSetting::find($id);
}
/**
* @throws Exception
*/
public function update(int $id, array $data): object
{
$item = QRMenuSetting::findOrFail($id);
$data = $this->prepareForDB($data, $item);
parent::update($id, $data);
return $this->getById($id);
}
/**
* @throws Exception
*/
public function prepareForDB(array $data, ?object $item = null): array
{
$data = parent::prepareForDB($data, $item);
if (empty($item)) {
$data['created_at'] = now();
$data['restaurant_id'] = $this->getCurrentRestaurantId();
$data['status'] = 1;
if (! empty($data['logo']) && $data['logo'] instanceof \Illuminate\Http\UploadedFile) {
$data['logo'] = fileUploader('qr_setting_images/', 'png', $data['logo']);
}
} else {
if (! empty($data['logo']) && $data['logo'] instanceof \Illuminate\Http\UploadedFile) {
$data['logo'] = fileUploader('qr_setting_images/', 'png', $data['logo'], $item->logo);
}
$data['updated_at'] = now();
}
return $data;
}
protected function getExceptionMessages(): array
{
return [
static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE => 'QRMenuSetting does not exist.',
static::MESSAGE_ITEM_COULD_NOT_BE_DELETED => 'QRMenuSetting could not be deleted.',
];
}
}

View File

@@ -0,0 +1,87 @@
<?php
namespace Modules\Restaurant\Repositories;
use Exception;
use Modules\Restaurant\Models\Reservation;
use Modules\Restaurant\Models\ReservationUnavailable;
class ReservationRepository
{
public function getAll(array $filters = [])
{
$query = Reservation::with(['table', 'customer']);
if (! empty($filters['restaurant_id'])) {
$query->where('restaurant_id', $filters['restaurant_id']);
}
if (! empty($filters['date'])) {
$query->whereDate('reservation_date', $filters['date']);
}
if (! empty($filters['status'])) {
$query->where('status', $filters['status']);
}
if (! empty($filters['search'])) {
$search = $filters['search'];
$query->where(function ($q) use ($search) {
$q->where('note', 'like', "%$search%");
});
}
$sortBy = $filters['sort_by'] ?? 'reservation_date';
$sortOrder = $filters['sort_order'] ?? 'desc';
$query->orderBy($sortBy, $sortOrder);
$perPage = $filters['perPage'] ?? 10;
return $query->paginate($perPage);
}
public function store(array $data)
{
$this->checkAvailability($data);
return Reservation::create($data);
}
public function checkAvailability(array $data)
{
$date = $data['reservation_date'];
$start = $data['start_time'];
$end = $data['end_time'];
$tableId = $data['table_id'];
// check unavailable tables
$unavailable = ReservationUnavailable::where('table_id', $tableId)
->where('date', $date)
->where(function ($q) use ($start, $end) {
$q->whereBetween('start_time', [$start, $end])
->orWhereBetween('end_time', [$start, $end]);
})
->exists();
if ($unavailable) {
throw new Exception('This table is unavailable for the selected time.');
}
// check existing reservations
$conflict = Reservation::where('table_id', $tableId)
->where('reservation_date', $date)
->where(function ($q) use ($start, $end) {
$q->whereBetween('start_time', [$start, $end])
->orWhereBetween('end_time', [$start, $end]);
})
->whereNotIn('status', ['cancelled'])
->exists();
if ($conflict) {
throw new Exception('This table is already booked for the selected time.');
}
return true;
}
}

View File

@@ -0,0 +1,166 @@
<?php
namespace Modules\Restaurant\Repositories;
use App\Abstracts\EntityRepository;
use Exception;
use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Query\Builder;
use Modules\Restaurant\Models\ReservationSetting;
use Symfony\Component\HttpFoundation\Response;
class ReservationSettingRepository extends EntityRepository
{
public string $table = ReservationSetting::TABLE_NAME;
protected array $fillableColumns = [
'restaurant_id',
'start_time',
'end_time',
'max_reservation',
'status',
'created_at',
'updated_at',
'deleted_at',
];
protected function getQuery(): Builder
{
return parent::getQuery();
}
protected function getFilterData(array $filterData = []): array
{
$defaultArgs = [
'perPage' => 10,
'search' => '',
'orderBy' => 'id',
'order' => 'desc',
'with_deleted' => false,
];
return array_merge($defaultArgs, $filterData);
}
private function getReservationSettingQuery(): Builder
{
return $this->getQuery()
->select(
"{$this->table}.id",
"{$this->table}.restaurant_id",
"{$this->table}.start_time",
"{$this->table}.end_time",
"{$this->table}.max_reservation",
"{$this->table}.status",
"{$this->table}.created_at",
"{$this->table}.deleted_at"
);
}
protected function filterSearchQuery(Builder|EloquentBuilder $query, string $searchedText): Builder
{
$searchable = "%$searchedText%";
return $query->where("{$this->table}.name", 'LIKE', $searchable)
->orWhere("{$this->table}.status", 'LIKE', $searchable);
}
public function getAll(array $filterData = []): Paginator
{
$filter = $this->getFilterData($filterData);
$query = $this->getReservationSettingQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
if (! empty($filter['search'])) {
$query = $this->filterSearchQuery($query, $filter['search']);
}
return $query
->orderBy($filter['orderBy'], $filter['order'])
->paginate($filter['perPage']);
}
public function getCount(array $filterData = []): int
{
$filter = $this->getFilterData($filterData);
$query = $this->getQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
return $query->count();
}
/**
* @throws Exception
*/
public function getByColumn(string $columnName, $columnValue, array $selects = ['*']): ?object
{
$item = $this->getReservationSettingQuery()
->where($columnName, $columnValue)
->first($selects);
if (empty($item)) {
throw new Exception(
$this->getExceptionMessage(static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE),
Response::HTTP_NOT_FOUND
);
}
return $item;
}
/**
* @throws Exception
*/
public function create(array $data): object
{
$data = $this->prepareForDB($data);
$id = $this->getQuery()->insertGetId($data);
return ReservationSetting::find($id);
}
/**
* @throws Exception
*/
public function update(int $id, array $data): object
{
$item = ReservationSetting::findOrFail($id);
$data = $this->prepareForDB($data, $item);
parent::update($id, $data);
return $this->getById($id);
}
/**
* @throws Exception
*/
public function prepareForDB(array $data, ?object $item = null): array
{
$data = parent::prepareForDB($data, $item);
if (empty($item)) {
$data['created_at'] = now();
$data['restaurant_id'] = $this->getCurrentRestaurantId();
$data['status'] = 1;
} else {
$data['updated_at'] = now();
}
return $data;
}
protected function getExceptionMessages(): array
{
return [
static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE => 'ReservationSetting does not exist.',
static::MESSAGE_ITEM_COULD_NOT_BE_DELETED => 'ReservationSetting could not be deleted.',
];
}
}

View File

@@ -0,0 +1,229 @@
<?php
namespace Modules\Restaurant\Repositories;
use App\Abstracts\EntityRepository;
use Exception;
use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Query\Builder;
use Modules\Restaurant\Models\Supplier;
use Symfony\Component\HttpFoundation\Response;
class SupplierRepository extends EntityRepository
{
public string $table = Supplier::TABLE_NAME;
protected array $fillableColumns = [
'restaurant_id',
'name',
'phone',
'company_name',
'contact_person',
'alternate_phone',
'email',
'website',
'image',
'address',
'city',
'state',
'country',
'postal_code',
'tax_number',
'bank_name',
'bank_account_name',
'bank_account_number',
'ifsc_code',
'opening_balance',
'opening_balance_date',
'due',
'balance',
'supply_type',
'payment_terms',
'credit_limit',
'rating',
'notes',
'contract_file',
'trade_license',
'nid_number',
'status',
'created_at',
'updated_at',
'deleted_at',
];
protected function getQuery(): Builder
{
return parent::getQuery();
}
protected function getFilterData(array $filterData = []): array
{
$defaultArgs = [
'perPage' => 10,
'search' => '',
'orderBy' => 'id',
'order' => 'desc',
'with_deleted' => false,
];
return array_merge($defaultArgs, $filterData);
}
private function getSupplierQuery(): Builder
{
return $this->getQuery()
->select(
"{$this->table}.id",
"{$this->table}.restaurant_id",
"{$this->table}.name",
"{$this->table}.phone",
"{$this->table}.company_name",
"{$this->table}.contact_person",
"{$this->table}.alternate_phone",
"{$this->table}.email",
"{$this->table}.website",
"{$this->table}.image",
"{$this->table}.address",
"{$this->table}.city",
"{$this->table}.state",
"{$this->table}.country",
"{$this->table}.postal_code",
"{$this->table}.tax_number",
"{$this->table}.bank_name",
"{$this->table}.bank_account_name",
"{$this->table}.bank_account_number",
"{$this->table}.ifsc_code",
"{$this->table}.opening_balance",
"{$this->table}.opening_balance_date",
"{$this->table}.due",
"{$this->table}.balance",
"{$this->table}.supply_type",
"{$this->table}.payment_terms",
"{$this->table}.credit_limit",
"{$this->table}.rating",
"{$this->table}.notes",
"{$this->table}.contract_file",
"{$this->table}.trade_license",
"{$this->table}.nid_number",
"{$this->table}.status",
"{$this->table}.created_at",
"{$this->table}.updated_at",
"{$this->table}.deleted_at",
);
}
protected function filterSearchQuery(Builder|EloquentBuilder $query, string $searchedText): Builder
{
$searchable = "%$searchedText%";
return $query->where("{$this->table}.name", 'LIKE', $searchable)
->orWhere("{$this->table}.status", 'LIKE', $searchable);
}
public function getAll(array $filterData = []): Paginator
{
$filter = $this->getFilterData($filterData);
$query = $this->getSupplierQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
if (! empty($filter['search'])) {
$query = $this->filterSearchQuery($query, $filter['search']);
}
return $query
->orderBy($filter['orderBy'], $filter['order'])
->paginate($filter['perPage']);
}
public function getCount(array $filterData = []): int
{
$filter = $this->getFilterData($filterData);
$query = $this->getQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
return $query->count();
}
/**
* @throws Exception
*/
public function getByColumn(string $columnName, $columnValue, array $selects = ['*']): ?object
{
$item = $this->getSupplierQuery()
->where($columnName, $columnValue)
->first($selects);
if (empty($item)) {
throw new Exception(
$this->getExceptionMessage(static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE),
Response::HTTP_NOT_FOUND
);
}
return $item;
}
/**
* @throws Exception
*/
public function create(array $data): object
{
$data = $this->prepareForDB($data);
$id = $this->getQuery()->insertGetId($data);
return Supplier::find($id);
}
/**
* @throws Exception
*/
public function update(int $id, array $data): object
{
$item = Supplier::findOrFail($id);
$data = $this->prepareForDB($data, $item);
parent::update($id, $data);
return $this->getById($id);
}
/**
* @throws Exception
*/
public function prepareForDB(array $data, ?object $item = null): array
{
$data = parent::prepareForDB($data, $item);
if (empty($item)) {
$data['created_at'] = now();
$data['restaurant_id'] = $this->getCurrentRestaurantId();
$data['status'] = 1;
if (! empty($data['image']) && $data['image'] instanceof \Illuminate\Http\UploadedFile) {
$data['image'] = fileUploader('suppliers/', 'png', $data['image']);
}
} else {
if (! empty($data['image']) && $data['image'] instanceof \Illuminate\Http\UploadedFile) {
$data['image'] = fileUploader('suppliers/', 'png', $data['image'], $item->image);
}
$data['updated_at'] = now();
}
return $data;
}
protected function getExceptionMessages(): array
{
return [
static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE => 'Supplier does not exist.',
static::MESSAGE_ITEM_COULD_NOT_BE_DELETED => 'Supplier could not be deleted.',
];
}
}

View File

@@ -0,0 +1,195 @@
<?php
namespace Modules\Restaurant\Repositories;
use App\Abstracts\EntityRepository;
use Exception;
use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Query\Builder;
use Modules\Restaurant\Models\Table;
use Symfony\Component\HttpFoundation\Response;
class TableRepository extends EntityRepository
{
public string $table = Table::TABLE_NAME;
protected array $fillableColumns = [
'restaurant_id',
'name',
'serial',
'section',
'location',
'table_type',
'capacity',
'is_bookable',
'qr_code',
'image',
'position_x',
'position_y',
'rotation',
'z_index',
'status',
'created_at',
'updated_at',
'deleted_at',
];
protected function getQuery(): Builder
{
return parent::getQuery();
}
protected function getFilterData(array $filterData = []): array
{
$defaultArgs = [
'perPage' => 10,
'search' => '',
'orderBy' => 'id',
'order' => 'desc',
'with_deleted' => false,
];
return array_merge($defaultArgs, $filterData);
}
private function getTableQuery(): Builder
{
return $this->getQuery()
->select(
"{$this->table}.id",
"{$this->table}.restaurant_id",
"{$this->table}.name",
"{$this->table}.serial",
"{$this->table}.section",
"{$this->table}.location",
"{$this->table}.table_type",
"{$this->table}.capacity",
"{$this->table}.is_bookable",
"{$this->table}.qr_code",
"{$this->table}.image",
"{$this->table}.position_x",
"{$this->table}.position_y",
"{$this->table}.rotation",
"{$this->table}.z_index",
"{$this->table}.status",
"{$this->table}.created_at",
"{$this->table}.updated_at",
"{$this->table}.deleted_at"
);
}
protected function filterSearchQuery(Builder|EloquentBuilder $query, string $searchedText): Builder
{
$searchable = "%$searchedText%";
return $query->where("{$this->table}.name", 'LIKE', $searchable)
->orWhere("{$this->table}.status", 'LIKE', $searchable);
}
public function getAll(array $filterData = []): Paginator
{
$filter = $this->getFilterData($filterData);
$query = $this->getTableQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
if (! empty($filter['search'])) {
$query = $this->filterSearchQuery($query, $filter['search']);
}
return $query
->orderBy($filter['orderBy'], $filter['order'])
->paginate($filter['perPage']);
}
public function getCount(array $filterData = []): int
{
$filter = $this->getFilterData($filterData);
$query = $this->getQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
return $query->count();
}
/**
* @throws Exception
*/
public function getByColumn(string $columnName, $columnValue, array $selects = ['*']): ?object
{
$item = $this->getTableQuery()
->where($columnName, $columnValue)
->first($selects);
if (empty($item)) {
throw new Exception(
$this->getExceptionMessage(static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE),
Response::HTTP_NOT_FOUND
);
}
return $item;
}
/**
* @throws Exception
*/
public function create(array $data): object
{
$data = $this->prepareForDB($data);
$id = $this->getQuery()->insertGetId($data);
return Table::find($id);
}
/**
* @throws Exception
*/
public function update(int $id, array $data): object
{
$item = Table::findOrFail($id);
$data = $this->prepareForDB($data, $item);
parent::update($id, $data);
return $this->getById($id);
}
/**
* @throws Exception
*/
public function prepareForDB(array $data, ?object $item = null): array
{
$data = parent::prepareForDB($data, $item);
if (empty($item)) {
$data['created_at'] = now();
$data['restaurant_id'] = $this->getCurrentRestaurantId();
$data['status'] = 1;
if (! empty($data['image']) && $data['image'] instanceof \Illuminate\Http\UploadedFile) {
$data['image'] = fileUploader('table_images/', 'png', $data['image']);
}
} else {
if (! empty($data['image']) && $data['image'] instanceof \Illuminate\Http\UploadedFile) {
$data['image'] = fileUploader('table_images/', 'png', $data['image'], $item->image);
}
$data['updated_at'] = now();
}
return $data;
}
protected function getExceptionMessages(): array
{
return [
static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE => 'Table does not exist.',
static::MESSAGE_ITEM_COULD_NOT_BE_DELETED => 'Table could not be deleted.',
];
}
}

View File

@@ -0,0 +1,178 @@
<?php
namespace Modules\Restaurant\Repositories;
use App\Abstracts\EntityRepository;
use Exception;
use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Query\Builder;
use Modules\Restaurant\Models\TaxSetting;
use Symfony\Component\HttpFoundation\Response;
class TaxSettingRepository extends EntityRepository
{
public string $table = TaxSetting::TABLE_NAME;
protected array $fillableColumns = [
'restaurant_id',
'name',
'reg_no',
'type',
'value',
'is_default',
'status',
'created_at',
'updated_at',
'deleted_at',
];
protected function getQuery(): Builder
{
return parent::getQuery();
}
protected function getFilterData(array $filterData = []): array
{
$defaultArgs = [
'perPage' => 10,
'search' => '',
'orderBy' => 'id',
'order' => 'desc',
'with_deleted' => false,
];
return array_merge($defaultArgs, $filterData);
}
private function getTaxSettingQuery(): Builder
{
return $this->getQuery()
->select(
"{$this->table}.id",
"{$this->table}.restaurant_id",
"{$this->table}.name",
"{$this->table}.reg_no",
"{$this->table}.type",
"{$this->table}.value",
"{$this->table}.is_default",
"{$this->table}.status",
"{$this->table}.created_at",
"{$this->table}.deleted_at"
);
}
protected function filterSearchQuery(Builder|EloquentBuilder $query, string $searchedText): Builder
{
$searchable = "%$searchedText%";
return $query->where("{$this->table}.name", 'LIKE', $searchable)
->orWhere("{$this->table}.status", 'LIKE', $searchable);
}
public function getAll(array $filterData = []): Paginator
{
$filter = $this->getFilterData($filterData);
$query = $this->getTaxSettingQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
if (! empty($filter['search'])) {
$query = $this->filterSearchQuery($query, $filter['search']);
}
return $query
->orderBy($filter['orderBy'], $filter['order'])
->paginate($filter['perPage']);
}
public function getCount(array $filterData = []): int
{
$filter = $this->getFilterData($filterData);
$query = $this->getQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
return $query->count();
}
/**
* @throws Exception
*/
public function getByColumn(string $columnName, $columnValue, array $selects = ['*']): ?object
{
$item = $this->getTaxSettingQuery()
->where($columnName, $columnValue)
->first($selects);
if (empty($item)) {
throw new Exception(
$this->getExceptionMessage(static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE),
Response::HTTP_NOT_FOUND
);
}
return $item;
}
/**
* @throws Exception
*/
public function create(array $data): object
{
$data = $this->prepareForDB($data);
$id = $this->getQuery()->insertGetId($data);
return TaxSetting::find($id);
}
/**
* @throws Exception
*/
public function update(int $id, array $data): object
{
$item = TaxSetting::findOrFail($id);
$data = $this->prepareForDB($data, $item);
parent::update($id, $data);
return $this->getById($id);
}
/**
* @throws Exception
*/
public function prepareForDB(array $data, ?object $item = null): array
{
$data = parent::prepareForDB($data, $item);
if (empty($item)) {
$data['created_at'] = now();
$data['restaurant_id'] = $this->getCurrentRestaurantId();
$data['status'] = 1;
if (! empty($data['image']) && $data['image'] instanceof \Illuminate\Http\UploadedFile) {
$data['image'] = fileUploader('Restaurant/', 'png', $data['image']);
}
} else {
if (! empty($data['image']) && $data['image'] instanceof \Illuminate\Http\UploadedFile) {
$data['image'] = fileUploader('Restaurant/', 'png', $data['image'], $item->image);
}
$data['updated_at'] = now();
}
return $data;
}
protected function getExceptionMessages(): array
{
return [
static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE => 'TaxSetting does not exist.',
static::MESSAGE_ITEM_COULD_NOT_BE_DELETED => 'TaxSetting could not be deleted.',
];
}
}

View File

@@ -0,0 +1,188 @@
<?php
namespace Modules\Restaurant\Repositories;
use App\Abstracts\EntityRepository;
use Exception;
use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Query\Builder;
use Modules\Restaurant\Models\Unit;
use Symfony\Component\HttpFoundation\Response;
class UnitRepository extends EntityRepository
{
public string $table = Unit::TABLE_NAME;
protected array $fillableColumns = [
'restaurant_id',
'user_id',
'name',
'short_name',
'type',
'base_unit_id',
'operator',
'operator_value',
'priority',
'version',
'is_default',
'status',
'created_at',
'updated_at',
'deleted_at',
];
protected function getQuery(): Builder
{
return parent::getQuery();
}
protected function getFilterData(array $filterData = []): array
{
$defaultArgs = [
'perPage' => 10,
'search' => '',
'orderBy' => 'id',
'order' => 'desc',
'with_deleted' => false,
];
return array_merge($defaultArgs, $filterData);
}
private function getUnitQuery(): Builder
{
return $this->getQuery()
->select(
"{$this->table}.id",
"{$this->table}.restaurant_id",
"{$this->table}.user_id",
"{$this->table}.name",
"{$this->table}.short_name",
"{$this->table}.type",
"{$this->table}.base_unit_id",
"{$this->table}.operator",
"{$this->table}.operator_value",
"{$this->table}.priority",
"{$this->table}.version",
"{$this->table}.is_default",
"{$this->table}.status",
"{$this->table}.created_at",
"{$this->table}.deleted_at"
);
}
protected function filterSearchQuery(Builder|EloquentBuilder $query, string $searchedText): Builder
{
$searchable = "%$searchedText%";
return $query->where("{$this->table}.name", 'LIKE', $searchable)
->orWhere("{$this->table}.short_name", 'LIKE', $searchable);
}
public function getAll(array $filterData = []): Paginator
{
$filter = $this->getFilterData($filterData);
$query = $this->getUnitQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
if (! empty($filter['search'])) {
$query = $this->filterSearchQuery($query, $filter['search']);
}
return $query
->orderBy($filter['orderBy'], $filter['order'])
->paginate($filter['perPage']);
}
public function getCount(array $filterData = []): int
{
$filter = $this->getFilterData($filterData);
$query = $this->getQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
return $query->count();
}
/**
* @throws Exception
*/
public function getByColumn(string $columnName, $columnValue, array $selects = ['*']): ?object
{
$item = $this->getUnitQuery()
->where($columnName, $columnValue)
->first($selects);
if (empty($item)) {
throw new Exception(
$this->getExceptionMessage(static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE),
Response::HTTP_NOT_FOUND
);
}
return $item;
}
/**
* @throws Exception
*/
public function create(array $data): object
{
$data = $this->prepareForDB($data);
$id = $this->getQuery()->insertGetId($data);
return Unit::find($id);
}
/**
* @throws Exception
*/
public function update(int $id, array $data): object
{
$item = Unit::findOrFail($id);
$data = $this->prepareForDB($data, $item);
parent::update($id, $data);
return $this->getById($id);
}
/**
* @throws Exception
*/
public function prepareForDB(array $data, ?object $item = null): array
{
$data = parent::prepareForDB($data, $item);
if (empty($item)) {
$data['created_at'] = now();
$data['restaurant_id'] = $this->getCurrentRestaurantId();
$data['status'] = 1;
if (! empty($data['image']) && $data['image'] instanceof \Illuminate\Http\UploadedFile) {
$data['image'] = fileUploader('Restaurant/', 'png', $data['image']);
}
} else {
if (! empty($data['image']) && $data['image'] instanceof \Illuminate\Http\UploadedFile) {
$data['image'] = fileUploader('Restaurant/', 'png', $data['image'], $item->image);
}
$data['updated_at'] = now();
}
return $data;
}
protected function getExceptionMessages(): array
{
return [
static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE => 'Unit does not exist.',
static::MESSAGE_ITEM_COULD_NOT_BE_DELETED => 'Unit could not be deleted.',
];
}
}

View File

@@ -0,0 +1,167 @@
<?php
namespace Modules\Restaurant\Repositories;
use App\Abstracts\EntityRepository;
use Exception;
use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Query\Builder;
use Modules\Restaurant\Models\Zone;
use Symfony\Component\HttpFoundation\Response;
class ZoneRepository extends EntityRepository
{
public string $table = Zone::TABLE_NAME;
protected array $fillableColumns = [
'name',
'code',
'description',
'coordinates',
'is_active',
'created_at',
'updated_at',
'deleted_at',
];
protected function getQuery(): Builder
{
return parent::getQuery();
}
protected function getFilterData(array $filterData = []): array
{
$defaultArgs = [
'perPage' => 10,
'search' => '',
'orderBy' => 'id',
'order' => 'desc',
'with_deleted' => false,
];
return array_merge($defaultArgs, $filterData);
}
private function getZoneQuery(): Builder
{
return $this->getQuery()
->select(
"{$this->table}.id",
"{$this->table}.name",
"{$this->table}.code",
"{$this->table}.description",
"{$this->table}.coordinates",
"{$this->table}.is_active",
"{$this->table}.created_at",
"{$this->table}.updated_at",
"{$this->table}.deleted_at"
);
}
protected function filterSearchQuery(Builder|EloquentBuilder $query, string $searchedText): Builder
{
$searchable = "%$searchedText%";
return $query->where("{$this->table}.name", 'LIKE', $searchable)
->orWhere("{$this->table}.status", 'LIKE', $searchable);
}
public function getAll(array $filterData = []): Paginator
{
$filter = $this->getFilterData($filterData);
$query = $this->getZoneQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
if (! empty($filter['search'])) {
$query = $this->filterSearchQuery($query, $filter['search']);
}
return $query
->orderBy($filter['orderBy'], $filter['order'])
->paginate($filter['perPage']);
}
public function getCount(array $filterData = []): int
{
$filter = $this->getFilterData($filterData);
$query = $this->getQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
return $query->count();
}
/**
* @throws Exception
*/
public function getByColumn(string $columnName, $columnValue, array $selects = ['*']): ?object
{
$item = $this->getZoneQuery()
->where($columnName, $columnValue)
->first($selects);
if (empty($item)) {
throw new Exception(
$this->getExceptionMessage(static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE),
Response::HTTP_NOT_FOUND
);
}
return $item;
}
/**
* @throws Exception
*/
public function create(array $data): object
{
$data = $this->prepareForDB($data);
$id = $this->getQuery()->insertGetId($data);
return Zone::find($id);
}
/**
* @throws Exception
*/
public function update(int $id, array $data): object
{
$item = Zone::findOrFail($id);
$data = $this->prepareForDB($data, $item);
parent::update($id, $data);
return $this->getById($id);
}
/**
* @throws Exception
*/
public function prepareForDB(array $data, ?object $item = null): array
{
$data = parent::prepareForDB($data, $item);
if (empty($item)) {
$data['created_at'] = now();
$data['restaurant_id'] = $this->getCurrentRestaurantId();
$data['status'] = 1;
} else {
$data['updated_at'] = now();
}
return $data;
}
protected function getExceptionMessages(): array
{
return [
static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE => 'Zone does not exist.',
static::MESSAGE_ITEM_COULD_NOT_BE_DELETED => 'Zone could not be deleted.',
];
}
}