initial project
This commit is contained in:
commit
1b08727cb2
10
.dockerignore
Normal file
10
.dockerignore
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
.git
|
||||||
|
.gitignore
|
||||||
|
node_modules
|
||||||
|
vendor
|
||||||
|
storage/logs
|
||||||
|
writable/cache
|
||||||
|
writable/logs
|
||||||
|
Dockerfile
|
||||||
|
docker-compose*.yml
|
||||||
|
*.md
|
||||||
126
.gitignore
vendored
Normal file
126
.gitignore
vendored
Normal file
@ -0,0 +1,126 @@
|
|||||||
|
#-------------------------
|
||||||
|
# Operating Specific Junk Files
|
||||||
|
#-------------------------
|
||||||
|
|
||||||
|
# OS X
|
||||||
|
.DS_Store
|
||||||
|
.AppleDouble
|
||||||
|
.LSOverride
|
||||||
|
|
||||||
|
# OS X Thumbnails
|
||||||
|
._*
|
||||||
|
|
||||||
|
# Windows image file caches
|
||||||
|
Thumbs.db
|
||||||
|
ehthumbs.db
|
||||||
|
Desktop.ini
|
||||||
|
|
||||||
|
# Recycle Bin used on file shares
|
||||||
|
$RECYCLE.BIN/
|
||||||
|
|
||||||
|
# Windows Installer files
|
||||||
|
*.cab
|
||||||
|
*.msi
|
||||||
|
*.msm
|
||||||
|
*.msp
|
||||||
|
|
||||||
|
# Windows shortcuts
|
||||||
|
*.lnk
|
||||||
|
|
||||||
|
# Linux
|
||||||
|
*~
|
||||||
|
|
||||||
|
# KDE directory preferences
|
||||||
|
.directory
|
||||||
|
|
||||||
|
# Linux trash folder which might appear on any partition or disk
|
||||||
|
.Trash-*
|
||||||
|
|
||||||
|
#-------------------------
|
||||||
|
# Environment Files
|
||||||
|
#-------------------------
|
||||||
|
# These should never be under version control,
|
||||||
|
# as it poses a security risk.
|
||||||
|
.env
|
||||||
|
.vagrant
|
||||||
|
Vagrantfile
|
||||||
|
|
||||||
|
#-------------------------
|
||||||
|
# Temporary Files
|
||||||
|
#-------------------------
|
||||||
|
writable/cache/*
|
||||||
|
!writable/cache/index.html
|
||||||
|
|
||||||
|
writable/logs/*
|
||||||
|
!writable/logs/index.html
|
||||||
|
|
||||||
|
writable/session/*
|
||||||
|
!writable/session/index.html
|
||||||
|
|
||||||
|
writable/uploads/*
|
||||||
|
!writable/uploads/index.html
|
||||||
|
|
||||||
|
writable/debugbar/*
|
||||||
|
!writable/debugbar/.gitkeep
|
||||||
|
|
||||||
|
php_errors.log
|
||||||
|
|
||||||
|
#-------------------------
|
||||||
|
# User Guide Temp Files
|
||||||
|
#-------------------------
|
||||||
|
user_guide_src/build/*
|
||||||
|
user_guide_src/cilexer/build/*
|
||||||
|
user_guide_src/cilexer/dist/*
|
||||||
|
user_guide_src/cilexer/pycilexer.egg-info/*
|
||||||
|
|
||||||
|
#-------------------------
|
||||||
|
# Test Files
|
||||||
|
#-------------------------
|
||||||
|
tests/coverage*
|
||||||
|
|
||||||
|
# Don't save phpunit under version control.
|
||||||
|
phpunit
|
||||||
|
|
||||||
|
#-------------------------
|
||||||
|
# Composer
|
||||||
|
#-------------------------
|
||||||
|
vendor/
|
||||||
|
|
||||||
|
#-------------------------
|
||||||
|
# IDE / Development Files
|
||||||
|
#-------------------------
|
||||||
|
|
||||||
|
# Modules Testing
|
||||||
|
_modules/*
|
||||||
|
|
||||||
|
# phpenv local config
|
||||||
|
.php-version
|
||||||
|
|
||||||
|
# Jetbrains editors (PHPStorm, etc)
|
||||||
|
.idea/
|
||||||
|
*.iml
|
||||||
|
|
||||||
|
# NetBeans
|
||||||
|
/nbproject/
|
||||||
|
/build/
|
||||||
|
/nbbuild/
|
||||||
|
/dist/
|
||||||
|
/nbdist/
|
||||||
|
/nbactions.xml
|
||||||
|
/nb-configuration.xml
|
||||||
|
/.nb-gradle/
|
||||||
|
|
||||||
|
# Sublime Text
|
||||||
|
*.tmlanguage.cache
|
||||||
|
*.tmPreferences.cache
|
||||||
|
*.stTheme.cache
|
||||||
|
*.sublime-workspace
|
||||||
|
*.sublime-project
|
||||||
|
.phpintel
|
||||||
|
/api/
|
||||||
|
|
||||||
|
# Visual Studio Code
|
||||||
|
.vscode/
|
||||||
|
|
||||||
|
/results/
|
||||||
|
/phpunit*.xml
|
||||||
51
Dockerfile
Normal file
51
Dockerfile
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
# syntax=docker/dockerfile:1.6
|
||||||
|
|
||||||
|
######################################
|
||||||
|
# 1) PHP-FPM runtime (CodeIgniter) #
|
||||||
|
######################################
|
||||||
|
FROM php:8.2-fpm-alpine AS php
|
||||||
|
WORKDIR /var/www/html
|
||||||
|
|
||||||
|
# Install OS deps + PHP extensions (incl. intl)
|
||||||
|
RUN apk add --no-cache icu-dev libzip-dev oniguruma-dev bash curl git unzip \
|
||||||
|
&& docker-php-ext-configure intl \
|
||||||
|
&& docker-php-ext-install pdo pdo_mysql mysqli intl zip opcache
|
||||||
|
|
||||||
|
# Opcache tuning
|
||||||
|
COPY docker/php/opcache.ini /usr/local/etc/php/conf.d/opcache.ini
|
||||||
|
|
||||||
|
# Install Composer (copy from official image)
|
||||||
|
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer
|
||||||
|
|
||||||
|
# Copy only composer files first for better caching
|
||||||
|
COPY composer.json composer.lock ./
|
||||||
|
|
||||||
|
# Run composer install **after** intl is available
|
||||||
|
RUN composer install --no-dev --prefer-dist --no-interaction --no-progress
|
||||||
|
|
||||||
|
# Now copy the rest of your app
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
# Non-root user
|
||||||
|
RUN addgroup -g 1000 www \
|
||||||
|
&& adduser -G www -g www -s /bin/sh -D www \
|
||||||
|
&& chown -R www:www /var/www/html
|
||||||
|
USER www
|
||||||
|
|
||||||
|
EXPOSE 9000
|
||||||
|
HEALTHCHECK --interval=30s --timeout=10s --retries=3 CMD php -v || exit 1
|
||||||
|
|
||||||
|
######################################
|
||||||
|
# 2) Nginx to serve static + proxy #
|
||||||
|
######################################
|
||||||
|
FROM nginx:1.27-alpine AS nginx
|
||||||
|
WORKDIR /var/www/html
|
||||||
|
|
||||||
|
# Copy app so Nginx can serve assets
|
||||||
|
COPY --from=php /var/www/html /var/www/html
|
||||||
|
|
||||||
|
# Nginx vhost
|
||||||
|
COPY docker/nginx/codeigniter.conf /etc/nginx/conf.d/default.conf
|
||||||
|
|
||||||
|
EXPOSE 80
|
||||||
|
HEALTHCHECK --interval=30s --timeout=10s --retries=3 CMD wget -q -O - http://127.0.0.1/ || exit 1
|
||||||
22
LICENSE
Normal file
22
LICENSE
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2014-2019 British Columbia Institute of Technology
|
||||||
|
Copyright (c) 2019-present CodeIgniter Foundation
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
68
README.md
Normal file
68
README.md
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
# CodeIgniter 4 Application Starter
|
||||||
|
|
||||||
|
## What is CodeIgniter?
|
||||||
|
|
||||||
|
CodeIgniter is a PHP full-stack web framework that is light, fast, flexible and secure.
|
||||||
|
More information can be found at the [official site](https://codeigniter.com).
|
||||||
|
|
||||||
|
This repository holds a composer-installable app starter.
|
||||||
|
It has been built from the
|
||||||
|
[development repository](https://github.com/codeigniter4/CodeIgniter4).
|
||||||
|
|
||||||
|
More information about the plans for version 4 can be found in [CodeIgniter 4](https://forum.codeigniter.com/forumdisplay.php?fid=28) on the forums.
|
||||||
|
|
||||||
|
You can read the [user guide](https://codeigniter.com/user_guide/)
|
||||||
|
corresponding to the latest version of the framework.
|
||||||
|
|
||||||
|
## Installation & updates
|
||||||
|
|
||||||
|
`composer create-project codeigniter4/appstarter` then `composer update` whenever
|
||||||
|
there is a new release of the framework.
|
||||||
|
|
||||||
|
When updating, check the release notes to see if there are any changes you might need to apply
|
||||||
|
to your `app` folder. The affected files can be copied or merged from
|
||||||
|
`vendor/codeigniter4/framework/app`.
|
||||||
|
|
||||||
|
## Setup
|
||||||
|
|
||||||
|
Copy `env` to `.env` and tailor for your app, specifically the baseURL
|
||||||
|
and any database settings.
|
||||||
|
|
||||||
|
## Important Change with index.php
|
||||||
|
|
||||||
|
`index.php` is no longer in the root of the project! It has been moved inside the *public* folder,
|
||||||
|
for better security and separation of components.
|
||||||
|
|
||||||
|
This means that you should configure your web server to "point" to your project's *public* folder, and
|
||||||
|
not to the project root. A better practice would be to configure a virtual host to point there. A poor practice would be to point your web server to the project root and expect to enter *public/...*, as the rest of your logic and the
|
||||||
|
framework are exposed.
|
||||||
|
|
||||||
|
**Please** read the user guide for a better explanation of how CI4 works!
|
||||||
|
|
||||||
|
## Repository Management
|
||||||
|
|
||||||
|
We use GitHub issues, in our main repository, to track **BUGS** and to track approved **DEVELOPMENT** work packages.
|
||||||
|
We use our [forum](http://forum.codeigniter.com) to provide SUPPORT and to discuss
|
||||||
|
FEATURE REQUESTS.
|
||||||
|
|
||||||
|
This repository is a "distribution" one, built by our release preparation script.
|
||||||
|
Problems with it can be raised on our forum, or as issues in the main repository.
|
||||||
|
|
||||||
|
## Server Requirements
|
||||||
|
|
||||||
|
PHP version 8.1 or higher is required, with the following extensions installed:
|
||||||
|
|
||||||
|
- [intl](http://php.net/manual/en/intl.requirements.php)
|
||||||
|
- [mbstring](http://php.net/manual/en/mbstring.installation.php)
|
||||||
|
|
||||||
|
> [!WARNING]
|
||||||
|
> - The end of life date for PHP 7.4 was November 28, 2022.
|
||||||
|
> - The end of life date for PHP 8.0 was November 26, 2023.
|
||||||
|
> - If you are still using PHP 7.4 or 8.0, you should upgrade immediately.
|
||||||
|
> - The end of life date for PHP 8.1 will be December 31, 2025.
|
||||||
|
|
||||||
|
Additionally, make sure that the following extensions are enabled in your PHP:
|
||||||
|
|
||||||
|
- json (enabled by default - don't turn it off)
|
||||||
|
- [mysqlnd](http://php.net/manual/en/mysqlnd.install.php) if you plan to use MySQL
|
||||||
|
- [libcurl](http://php.net/manual/en/curl.requirements.php) if you plan to use the HTTP\CURLRequest library
|
||||||
6
app/.htaccess
Normal file
6
app/.htaccess
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<IfModule authz_core_module>
|
||||||
|
Require all denied
|
||||||
|
</IfModule>
|
||||||
|
<IfModule !authz_core_module>
|
||||||
|
Deny from all
|
||||||
|
</IfModule>
|
||||||
15
app/Common.php
Normal file
15
app/Common.php
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The goal of this file is to allow developers a location
|
||||||
|
* where they can overwrite core procedural functions and
|
||||||
|
* replace them with their own. This file is loaded during
|
||||||
|
* the bootstrap process and is called during the framework's
|
||||||
|
* execution.
|
||||||
|
*
|
||||||
|
* This can be looked at as a `master helper` file that is
|
||||||
|
* loaded early on, and may also contain additional functions
|
||||||
|
* that you'd like to use throughout your entire application
|
||||||
|
*
|
||||||
|
* @see: https://codeigniter.com/user_guide/extending/common.html
|
||||||
|
*/
|
||||||
203
app/Config/App.php
Normal file
203
app/Config/App.php
Normal file
@ -0,0 +1,203 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Config;
|
||||||
|
|
||||||
|
use CodeIgniter\Config\BaseConfig;
|
||||||
|
|
||||||
|
class App extends BaseConfig
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* Base Site URL
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* URL to your CodeIgniter root. Typically, this will be your base URL,
|
||||||
|
* WITH a trailing slash:
|
||||||
|
*
|
||||||
|
* E.g., http://example.com/
|
||||||
|
*/
|
||||||
|
public string $baseURL = 'https://icom.ipsgroup.com.my/';
|
||||||
|
// public string $baseURL = 'http://localhost:8080/';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allowed Hostnames in the Site URL other than the hostname in the baseURL.
|
||||||
|
* If you want to accept multiple Hostnames, set this.
|
||||||
|
*
|
||||||
|
* E.g.,
|
||||||
|
* When your site URL ($baseURL) is 'http://example.com/', and your site
|
||||||
|
* also accepts 'http://media.example.com/' and 'http://accounts.example.com/':
|
||||||
|
* ['media.example.com', 'accounts.example.com']
|
||||||
|
*
|
||||||
|
* @var list<string>
|
||||||
|
*/
|
||||||
|
public array $allowedHostnames = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* Index File
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* Typically, this will be your `index.php` file, unless you've renamed it to
|
||||||
|
* something else. If you have configured your web server to remove this file
|
||||||
|
* from your site URIs, set this variable to an empty string.
|
||||||
|
*/
|
||||||
|
public string $indexPage = 'index.php';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* URI PROTOCOL
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* This item determines which server global should be used to retrieve the
|
||||||
|
* URI string. The default setting of 'REQUEST_URI' works for most servers.
|
||||||
|
* If your links do not seem to work, try one of the other delicious flavors:
|
||||||
|
*
|
||||||
|
* 'REQUEST_URI': Uses $_SERVER['REQUEST_URI']
|
||||||
|
* 'QUERY_STRING': Uses $_SERVER['QUERY_STRING']
|
||||||
|
* 'PATH_INFO': Uses $_SERVER['PATH_INFO']
|
||||||
|
*
|
||||||
|
* WARNING: If you set this to 'PATH_INFO', URIs will always be URL-decoded!
|
||||||
|
*/
|
||||||
|
public string $uriProtocol = 'REQUEST_URI';
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Allowed URL Characters
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| This lets you specify which characters are permitted within your URLs.
|
||||||
|
| When someone tries to submit a URL with disallowed characters they will
|
||||||
|
| get a warning message.
|
||||||
|
|
|
||||||
|
| As a security measure you are STRONGLY encouraged to restrict URLs to
|
||||||
|
| as few characters as possible.
|
||||||
|
|
|
||||||
|
| By default, only these are allowed: `a-z 0-9~%.:_-`
|
||||||
|
|
|
||||||
|
| Set an empty string to allow all characters -- but only if you are insane.
|
||||||
|
|
|
||||||
|
| The configured value is actually a regular expression character group
|
||||||
|
| and it will be used as: '/\A[<permittedURIChars>]+\z/iu'
|
||||||
|
|
|
||||||
|
| DO NOT CHANGE THIS UNLESS YOU FULLY UNDERSTAND THE REPERCUSSIONS!!
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
public string $permittedURIChars = 'a-z 0-9~%.:_\-';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* Default Locale
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* The Locale roughly represents the language and location that your visitor
|
||||||
|
* is viewing the site from. It affects the language strings and other
|
||||||
|
* strings (like currency markers, numbers, etc), that your program
|
||||||
|
* should run under for this request.
|
||||||
|
*/
|
||||||
|
public string $defaultLocale = 'en';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* Negotiate Locale
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* If true, the current Request object will automatically determine the
|
||||||
|
* language to use based on the value of the Accept-Language header.
|
||||||
|
*
|
||||||
|
* If false, no automatic detection will be performed.
|
||||||
|
*/
|
||||||
|
public bool $negotiateLocale = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* Supported Locales
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* If $negotiateLocale is true, this array lists the locales supported
|
||||||
|
* by the application in descending order of priority. If no match is
|
||||||
|
* found, the first locale will be used.
|
||||||
|
*
|
||||||
|
* IncomingRequest::setLocale() also uses this list.
|
||||||
|
*
|
||||||
|
* @var list<string>
|
||||||
|
*/
|
||||||
|
public array $supportedLocales = ['en'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* Application Timezone
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* The default timezone that will be used in your application to display
|
||||||
|
* dates with the date helper, and can be retrieved through app_timezone()
|
||||||
|
*
|
||||||
|
* @see https://www.php.net/manual/en/timezones.php for list of timezones
|
||||||
|
* supported by PHP.
|
||||||
|
*/
|
||||||
|
public string $appTimezone = 'Asia/Kuala_Lumpur';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* Default Character Set
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* This determines which character set is used by default in various methods
|
||||||
|
* that require a character set to be provided.
|
||||||
|
*
|
||||||
|
* @see http://php.net/htmlspecialchars for a list of supported charsets.
|
||||||
|
*/
|
||||||
|
public string $charset = 'UTF-8';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* Force Global Secure Requests
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* If true, this will force every request made to this application to be
|
||||||
|
* made via a secure connection (HTTPS). If the incoming request is not
|
||||||
|
* secure, the user will be redirected to a secure version of the page
|
||||||
|
* and the HTTP Strict Transport Security (HSTS) header will be set.
|
||||||
|
*/
|
||||||
|
public bool $forceGlobalSecureRequests = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* Reverse Proxy IPs
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* If your server is behind a reverse proxy, you must whitelist the proxy
|
||||||
|
* IP addresses from which CodeIgniter should trust headers such as
|
||||||
|
* X-Forwarded-For or Client-IP in order to properly identify
|
||||||
|
* the visitor's IP address.
|
||||||
|
*
|
||||||
|
* You need to set a proxy IP address or IP address with subnets and
|
||||||
|
* the HTTP header for the client IP address.
|
||||||
|
*
|
||||||
|
* Here are some examples:
|
||||||
|
* [
|
||||||
|
* '10.0.1.200' => 'X-Forwarded-For',
|
||||||
|
* '192.168.5.0/24' => 'X-Real-IP',
|
||||||
|
* ]
|
||||||
|
*
|
||||||
|
* @var array<string, string>
|
||||||
|
*/
|
||||||
|
public array $proxyIPs = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* Content Security Policy
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* Enables the Response's Content Secure Policy to restrict the sources that
|
||||||
|
* can be used for images, scripts, CSS files, audio, video, etc. If enabled,
|
||||||
|
* the Response object will populate default values for the policy from the
|
||||||
|
* `ContentSecurityPolicy.php` file. Controllers can always add to those
|
||||||
|
* restrictions at run time.
|
||||||
|
*
|
||||||
|
* For a better understanding of CSP, see these documents:
|
||||||
|
*
|
||||||
|
* @see http://www.html5rocks.com/en/tutorials/security/content-security-policy/
|
||||||
|
* @see http://www.w3.org/TR/CSP/
|
||||||
|
*/
|
||||||
|
public bool $CSPEnabled = false;
|
||||||
|
}
|
||||||
95
app/Config/Autoload.php
Normal file
95
app/Config/Autoload.php
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Config;
|
||||||
|
|
||||||
|
use CodeIgniter\Config\AutoloadConfig;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* -------------------------------------------------------------------
|
||||||
|
* AUTOLOADER CONFIGURATION
|
||||||
|
* -------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* This file defines the namespaces and class maps so the Autoloader
|
||||||
|
* can find the files as needed.
|
||||||
|
*
|
||||||
|
* NOTE: If you use an identical key in $psr4 or $classmap, then
|
||||||
|
* the values in this file will overwrite the framework's values.
|
||||||
|
*
|
||||||
|
* NOTE: This class is required prior to Autoloader instantiation,
|
||||||
|
* and does not extend BaseConfig.
|
||||||
|
*/
|
||||||
|
class Autoload extends AutoloadConfig
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* -------------------------------------------------------------------
|
||||||
|
* Namespaces
|
||||||
|
* -------------------------------------------------------------------
|
||||||
|
* This maps the locations of any namespaces in your application to
|
||||||
|
* their location on the file system. These are used by the autoloader
|
||||||
|
* to locate files the first time they have been instantiated.
|
||||||
|
*
|
||||||
|
* The 'Config' (APPPATH . 'Config') and 'CodeIgniter' (SYSTEMPATH) are
|
||||||
|
* already mapped for you.
|
||||||
|
*
|
||||||
|
* You may change the name of the 'App' namespace if you wish,
|
||||||
|
* but this should be done prior to creating any namespaced classes,
|
||||||
|
* else you will need to modify all of those classes for this to work.
|
||||||
|
*
|
||||||
|
* @var array<string, list<string>|string>
|
||||||
|
*/
|
||||||
|
public $psr4 = [
|
||||||
|
APP_NAMESPACE => APPPATH,
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* -------------------------------------------------------------------
|
||||||
|
* Class Map
|
||||||
|
* -------------------------------------------------------------------
|
||||||
|
* The class map provides a map of class names and their exact
|
||||||
|
* location on the drive. Classes loaded in this manner will have
|
||||||
|
* slightly faster performance because they will not have to be
|
||||||
|
* searched for within one or more directories as they would if they
|
||||||
|
* were being autoloaded through a namespace.
|
||||||
|
*
|
||||||
|
* Prototype:
|
||||||
|
* $classmap = [
|
||||||
|
* 'MyClass' => '/path/to/class/file.php'
|
||||||
|
* ];
|
||||||
|
*
|
||||||
|
* @var array<string, string>
|
||||||
|
*/
|
||||||
|
public $classmap = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* -------------------------------------------------------------------
|
||||||
|
* Files
|
||||||
|
* -------------------------------------------------------------------
|
||||||
|
* The files array provides a list of paths to __non-class__ files
|
||||||
|
* that will be autoloaded. This can be useful for bootstrap operations
|
||||||
|
* or for loading functions.
|
||||||
|
*
|
||||||
|
* Prototype:
|
||||||
|
* $files = [
|
||||||
|
* '/path/to/my/file.php',
|
||||||
|
* ];
|
||||||
|
*
|
||||||
|
* @var list<string>
|
||||||
|
*/
|
||||||
|
public $files = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* -------------------------------------------------------------------
|
||||||
|
* Helpers
|
||||||
|
* -------------------------------------------------------------------
|
||||||
|
* Prototype:
|
||||||
|
* $helpers = [
|
||||||
|
* 'form',
|
||||||
|
* ];
|
||||||
|
*
|
||||||
|
* @var list<string>
|
||||||
|
*/
|
||||||
|
public $helpers = [
|
||||||
|
'menu_helper',
|
||||||
|
'cart_helper'
|
||||||
|
];
|
||||||
|
}
|
||||||
34
app/Config/Boot/development.php
Normal file
34
app/Config/Boot/development.php
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| ERROR DISPLAY
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| In development, we want to show as many errors as possible to help
|
||||||
|
| make sure they don't make it to production. And save us hours of
|
||||||
|
| painful debugging.
|
||||||
|
|
|
||||||
|
| If you set 'display_errors' to '1', CI4's detailed error report will show.
|
||||||
|
*/
|
||||||
|
error_reporting(E_ALL);
|
||||||
|
ini_set('display_errors', '1');
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| DEBUG BACKTRACES
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| If true, this constant will tell the error screens to display debug
|
||||||
|
| backtraces along with the other error information. If you would
|
||||||
|
| prefer to not see this, set this value to false.
|
||||||
|
*/
|
||||||
|
defined('SHOW_DEBUG_BACKTRACE') || define('SHOW_DEBUG_BACKTRACE', true);
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| DEBUG MODE
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Debug mode is an experimental flag that can allow changes throughout
|
||||||
|
| the system. This will control whether Kint is loaded, and a few other
|
||||||
|
| items. It can always be used within your own application too.
|
||||||
|
*/
|
||||||
|
defined('CI_DEBUG') || define('CI_DEBUG', true);
|
||||||
25
app/Config/Boot/production.php
Normal file
25
app/Config/Boot/production.php
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| ERROR DISPLAY
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Don't show ANY in production environments. Instead, let the system catch
|
||||||
|
| it and display a generic error message.
|
||||||
|
|
|
||||||
|
| If you set 'display_errors' to '1', CI4's detailed error report will show.
|
||||||
|
*/
|
||||||
|
error_reporting(E_ALL & ~E_DEPRECATED);
|
||||||
|
// If you want to suppress more types of errors.
|
||||||
|
// error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED);
|
||||||
|
ini_set('display_errors', '0');
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| DEBUG MODE
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Debug mode is an experimental flag that can allow changes throughout
|
||||||
|
| the system. It's not widely used currently, and may not survive
|
||||||
|
| release of the framework.
|
||||||
|
*/
|
||||||
|
defined('CI_DEBUG') || define('CI_DEBUG', false);
|
||||||
38
app/Config/Boot/testing.php
Normal file
38
app/Config/Boot/testing.php
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The environment testing is reserved for PHPUnit testing. It has special
|
||||||
|
* conditions built into the framework at various places to assist with that.
|
||||||
|
* You can’t use it for your development.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| ERROR DISPLAY
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| In development, we want to show as many errors as possible to help
|
||||||
|
| make sure they don't make it to production. And save us hours of
|
||||||
|
| painful debugging.
|
||||||
|
*/
|
||||||
|
error_reporting(E_ALL);
|
||||||
|
ini_set('display_errors', '1');
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| DEBUG BACKTRACES
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| If true, this constant will tell the error screens to display debug
|
||||||
|
| backtraces along with the other error information. If you would
|
||||||
|
| prefer to not see this, set this value to false.
|
||||||
|
*/
|
||||||
|
defined('SHOW_DEBUG_BACKTRACE') || define('SHOW_DEBUG_BACKTRACE', true);
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| DEBUG MODE
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Debug mode is an experimental flag that can allow changes throughout
|
||||||
|
| the system. It's not widely used currently, and may not survive
|
||||||
|
| release of the framework.
|
||||||
|
*/
|
||||||
|
defined('CI_DEBUG') || define('CI_DEBUG', true);
|
||||||
20
app/Config/CURLRequest.php
Normal file
20
app/Config/CURLRequest.php
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Config;
|
||||||
|
|
||||||
|
use CodeIgniter\Config\BaseConfig;
|
||||||
|
|
||||||
|
class CURLRequest extends BaseConfig
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* CURLRequest Share Options
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* Whether share options between requests or not.
|
||||||
|
*
|
||||||
|
* If true, all the options won't be reset between requests.
|
||||||
|
* It may cause an error request with unnecessary headers.
|
||||||
|
*/
|
||||||
|
public bool $shareOptions = false;
|
||||||
|
}
|
||||||
162
app/Config/Cache.php
Normal file
162
app/Config/Cache.php
Normal file
@ -0,0 +1,162 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Config;
|
||||||
|
|
||||||
|
use CodeIgniter\Cache\CacheInterface;
|
||||||
|
use CodeIgniter\Cache\Handlers\DummyHandler;
|
||||||
|
use CodeIgniter\Cache\Handlers\FileHandler;
|
||||||
|
use CodeIgniter\Cache\Handlers\MemcachedHandler;
|
||||||
|
use CodeIgniter\Cache\Handlers\PredisHandler;
|
||||||
|
use CodeIgniter\Cache\Handlers\RedisHandler;
|
||||||
|
use CodeIgniter\Cache\Handlers\WincacheHandler;
|
||||||
|
use CodeIgniter\Config\BaseConfig;
|
||||||
|
|
||||||
|
class Cache extends BaseConfig
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* Primary Handler
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* The name of the preferred handler that should be used. If for some reason
|
||||||
|
* it is not available, the $backupHandler will be used in its place.
|
||||||
|
*/
|
||||||
|
public string $handler = 'file';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* Backup Handler
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* The name of the handler that will be used in case the first one is
|
||||||
|
* unreachable. Often, 'file' is used here since the filesystem is
|
||||||
|
* always available, though that's not always practical for the app.
|
||||||
|
*/
|
||||||
|
public string $backupHandler = 'dummy';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* Key Prefix
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* This string is added to all cache item names to help avoid collisions
|
||||||
|
* if you run multiple applications with the same cache engine.
|
||||||
|
*/
|
||||||
|
public string $prefix = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* Default TTL
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* The default number of seconds to save items when none is specified.
|
||||||
|
*
|
||||||
|
* WARNING: This is not used by framework handlers where 60 seconds is
|
||||||
|
* hard-coded, but may be useful to projects and modules. This will replace
|
||||||
|
* the hard-coded value in a future release.
|
||||||
|
*/
|
||||||
|
public int $ttl = 60;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* Reserved Characters
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* A string of reserved characters that will not be allowed in keys or tags.
|
||||||
|
* Strings that violate this restriction will cause handlers to throw.
|
||||||
|
* Default: {}()/\@:
|
||||||
|
*
|
||||||
|
* NOTE: The default set is required for PSR-6 compliance.
|
||||||
|
*/
|
||||||
|
public string $reservedCharacters = '{}()/\@:';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* File settings
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* Your file storage preferences can be specified below, if you are using
|
||||||
|
* the File driver.
|
||||||
|
*
|
||||||
|
* @var array<string, int|string|null>
|
||||||
|
*/
|
||||||
|
public array $file = [
|
||||||
|
'storePath' => WRITEPATH . 'cache/',
|
||||||
|
'mode' => 0640,
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* -------------------------------------------------------------------------
|
||||||
|
* Memcached settings
|
||||||
|
* -------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* Your Memcached servers can be specified below, if you are using
|
||||||
|
* the Memcached drivers.
|
||||||
|
*
|
||||||
|
* @see https://codeigniter.com/user_guide/libraries/caching.html#memcached
|
||||||
|
*
|
||||||
|
* @var array<string, bool|int|string>
|
||||||
|
*/
|
||||||
|
public array $memcached = [
|
||||||
|
'host' => '127.0.0.1',
|
||||||
|
'port' => 11211,
|
||||||
|
'weight' => 1,
|
||||||
|
'raw' => false,
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* -------------------------------------------------------------------------
|
||||||
|
* Redis settings
|
||||||
|
* -------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* Your Redis server can be specified below, if you are using
|
||||||
|
* the Redis or Predis drivers.
|
||||||
|
*
|
||||||
|
* @var array<string, int|string|null>
|
||||||
|
*/
|
||||||
|
public array $redis = [
|
||||||
|
'host' => '127.0.0.1',
|
||||||
|
'password' => null,
|
||||||
|
'port' => 6379,
|
||||||
|
'timeout' => 0,
|
||||||
|
'database' => 0,
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* Available Cache Handlers
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* This is an array of cache engine alias' and class names. Only engines
|
||||||
|
* that are listed here are allowed to be used.
|
||||||
|
*
|
||||||
|
* @var array<string, class-string<CacheInterface>>
|
||||||
|
*/
|
||||||
|
public array $validHandlers = [
|
||||||
|
'dummy' => DummyHandler::class,
|
||||||
|
'file' => FileHandler::class,
|
||||||
|
'memcached' => MemcachedHandler::class,
|
||||||
|
'predis' => PredisHandler::class,
|
||||||
|
'redis' => RedisHandler::class,
|
||||||
|
'wincache' => WincacheHandler::class,
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* Web Page Caching: Cache Include Query String
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* Whether to take the URL query string into consideration when generating
|
||||||
|
* output cache files. Valid options are:
|
||||||
|
*
|
||||||
|
* false = Disabled
|
||||||
|
* true = Enabled, take all query parameters into account.
|
||||||
|
* Please be aware that this may result in numerous cache
|
||||||
|
* files generated for the same page over and over again.
|
||||||
|
* ['q'] = Enabled, but only take into account the specified list
|
||||||
|
* of query parameters.
|
||||||
|
*
|
||||||
|
* @var bool|list<string>
|
||||||
|
*/
|
||||||
|
public $cacheQueryString = false;
|
||||||
|
}
|
||||||
115
app/Config/Constants.php
Normal file
115
app/Config/Constants.php
Normal file
@ -0,0 +1,115 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
| --------------------------------------------------------------------
|
||||||
|
| App Namespace
|
||||||
|
| --------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| This defines the default Namespace that is used throughout
|
||||||
|
| CodeIgniter to refer to the Application directory. Change
|
||||||
|
| this constant to change the namespace that all application
|
||||||
|
| classes should use.
|
||||||
|
|
|
||||||
|
| NOTE: changing this will require manually modifying the
|
||||||
|
| existing namespaces of App\* namespaced-classes.
|
||||||
|
*/
|
||||||
|
defined('APP_NAMESPACE') || define('APP_NAMESPACE', 'App');
|
||||||
|
|
||||||
|
/*
|
||||||
|
| --------------------------------------------------------------------------
|
||||||
|
| Composer Path
|
||||||
|
| --------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| The path that Composer's autoload file is expected to live. By default,
|
||||||
|
| the vendor folder is in the Root directory, but you can customize that here.
|
||||||
|
*/
|
||||||
|
defined('COMPOSER_PATH') || define('COMPOSER_PATH', ROOTPATH . 'vendor/autoload.php');
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Timing Constants
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Provide simple ways to work with the myriad of PHP functions that
|
||||||
|
| require information to be in seconds.
|
||||||
|
*/
|
||||||
|
defined('SECOND') || define('SECOND', 1);
|
||||||
|
defined('MINUTE') || define('MINUTE', 60);
|
||||||
|
defined('HOUR') || define('HOUR', 3600);
|
||||||
|
defined('DAY') || define('DAY', 86400);
|
||||||
|
defined('WEEK') || define('WEEK', 604800);
|
||||||
|
defined('MONTH') || define('MONTH', 2_592_000);
|
||||||
|
defined('YEAR') || define('YEAR', 31_536_000);
|
||||||
|
defined('DECADE') || define('DECADE', 315_360_000);
|
||||||
|
|
||||||
|
/*
|
||||||
|
| --------------------------------------------------------------------------
|
||||||
|
| Exit Status Codes
|
||||||
|
| --------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Used to indicate the conditions under which the script is exit()ing.
|
||||||
|
| While there is no universal standard for error codes, there are some
|
||||||
|
| broad conventions. Three such conventions are mentioned below, for
|
||||||
|
| those who wish to make use of them. The CodeIgniter defaults were
|
||||||
|
| chosen for the least overlap with these conventions, while still
|
||||||
|
| leaving room for others to be defined in future versions and user
|
||||||
|
| applications.
|
||||||
|
|
|
||||||
|
| The three main conventions used for determining exit status codes
|
||||||
|
| are as follows:
|
||||||
|
|
|
||||||
|
| Standard C/C++ Library (stdlibc):
|
||||||
|
| http://www.gnu.org/software/libc/manual/html_node/Exit-Status.html
|
||||||
|
| (This link also contains other GNU-specific conventions)
|
||||||
|
| BSD sysexits.h:
|
||||||
|
| http://www.gsp.com/cgi-bin/man.cgi?section=3&topic=sysexits
|
||||||
|
| Bash scripting:
|
||||||
|
| http://tldp.org/LDP/abs/html/exitcodes.html
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
defined('EXIT_SUCCESS') || define('EXIT_SUCCESS', 0); // no errors
|
||||||
|
defined('EXIT_ERROR') || define('EXIT_ERROR', 1); // generic error
|
||||||
|
defined('EXIT_CONFIG') || define('EXIT_CONFIG', 3); // configuration error
|
||||||
|
defined('EXIT_UNKNOWN_FILE') || define('EXIT_UNKNOWN_FILE', 4); // file not found
|
||||||
|
defined('EXIT_UNKNOWN_CLASS') || define('EXIT_UNKNOWN_CLASS', 5); // unknown class
|
||||||
|
defined('EXIT_UNKNOWN_METHOD') || define('EXIT_UNKNOWN_METHOD', 6); // unknown class member
|
||||||
|
defined('EXIT_USER_INPUT') || define('EXIT_USER_INPUT', 7); // invalid user input
|
||||||
|
defined('EXIT_DATABASE') || define('EXIT_DATABASE', 8); // database error
|
||||||
|
defined('EXIT__AUTO_MIN') || define('EXIT__AUTO_MIN', 9); // lowest automatically-assigned error code
|
||||||
|
defined('EXIT__AUTO_MAX') || define('EXIT__AUTO_MAX', 125); // highest automatically-assigned error code
|
||||||
|
|
||||||
|
/*
|
||||||
|
| --------------------------------------------------------------------------
|
||||||
|
| Third Party API Constants
|
||||||
|
| --------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| This defines the constants for the API endpoints and keys.
|
||||||
|
*/
|
||||||
|
|
||||||
|
//Wato
|
||||||
|
defined('WATOAPILINK') || define('WATOAPILINK', 'https://app.wato.my/api/wato-send-message');
|
||||||
|
defined('WATOAPIKEY') || define('WATOAPIKEY', 'y0tYhmGVgR');
|
||||||
|
defined('COMPANY') || define('COMPANY', 'US Pizza');
|
||||||
|
|
||||||
|
//Lalamove
|
||||||
|
defined('LALAMOVELINK') || define('LALAMOVELINK', 'https://rest.sandbox.lalamove.com/v3');
|
||||||
|
defined('LALAMOVESECRET') || define('LALAMOVESECRET', 'sk_test_W1r855zHYcvJDlvbppqwL7/OH2yEBs/8aKFRpLwQRmKzg2EvIuzqJo9X1dF4GilU');
|
||||||
|
defined('LALAMOVEAPIKEY') || define('LALAMOVEAPIKEY', 'pk_test_f09ebcd7e1ab9f72ba8b28db056ec969');
|
||||||
|
|
||||||
|
//fiuu
|
||||||
|
define('FIUU_MERCHANT_ID', 'SB_myuspizza');
|
||||||
|
define('FIUU_VERIFY_KEY', 'c6c7ddf46586f8c83b11b399c36bcfbc');
|
||||||
|
define('FIUU_SECRET_KEY', '147458daf464efa9d7dcb608dc0f4dca');
|
||||||
|
define('FIUU_SANDBOX_ENDPOINT', ' https://sandbox-payment.fiuu.com/RMS/pay/' . FIUU_MERCHANT_ID . '');
|
||||||
|
|
||||||
|
//GrabExpress
|
||||||
|
defined('GRAB_API_URL') || define('GRAB_API_URL', 'https://partner-api.grab.com');
|
||||||
|
defined('GRAB_CLIENT_ID') || define('GRAB_CLIENT_ID', '8abfe94c5edd40dfb3e6f789a364adaf');
|
||||||
|
defined('GRAB_CLIENT_SECRET') || define('GRAB_CLIENT_SECRET', 'zb_0k6nBnjYsY20Z');
|
||||||
|
|
||||||
|
//Google Distance Matrix API
|
||||||
|
defined('GOOGLE_DISTANCE_MATRIX_API_KEY') || define('GOOGLE_DISTANCE_MATRIX_API_KEY', 'AIzaSyD7M4NLYkYK4ovYJeMNY3tqeuB_Xvrj030');
|
||||||
|
|
||||||
|
//Hard Code
|
||||||
|
defined('VIP_MENU_ITEM_ID') || define('VIP_MENU_ITEM_ID', 51);
|
||||||
|
defined('HQ_OUTLET_ID') || define('HQ_OUTLET_ID', 120);
|
||||||
176
app/Config/ContentSecurityPolicy.php
Normal file
176
app/Config/ContentSecurityPolicy.php
Normal file
@ -0,0 +1,176 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Config;
|
||||||
|
|
||||||
|
use CodeIgniter\Config\BaseConfig;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores the default settings for the ContentSecurityPolicy, if you
|
||||||
|
* choose to use it. The values here will be read in and set as defaults
|
||||||
|
* for the site. If needed, they can be overridden on a page-by-page basis.
|
||||||
|
*
|
||||||
|
* Suggested reference for explanations:
|
||||||
|
*
|
||||||
|
* @see https://www.html5rocks.com/en/tutorials/security/content-security-policy/
|
||||||
|
*/
|
||||||
|
class ContentSecurityPolicy extends BaseConfig
|
||||||
|
{
|
||||||
|
// -------------------------------------------------------------------------
|
||||||
|
// Broadbrush CSP management
|
||||||
|
// -------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default CSP report context
|
||||||
|
*/
|
||||||
|
public bool $reportOnly = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specifies a URL where a browser will send reports
|
||||||
|
* when a content security policy is violated.
|
||||||
|
*/
|
||||||
|
public ?string $reportURI = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instructs user agents to rewrite URL schemes, changing
|
||||||
|
* HTTP to HTTPS. This directive is for websites with
|
||||||
|
* large numbers of old URLs that need to be rewritten.
|
||||||
|
*/
|
||||||
|
public bool $upgradeInsecureRequests = false;
|
||||||
|
|
||||||
|
// -------------------------------------------------------------------------
|
||||||
|
// Sources allowed
|
||||||
|
// NOTE: once you set a policy to 'none', it cannot be further restricted
|
||||||
|
// -------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Will default to self if not overridden
|
||||||
|
*
|
||||||
|
* @var list<string>|string|null
|
||||||
|
*/
|
||||||
|
public $defaultSrc;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lists allowed scripts' URLs.
|
||||||
|
*
|
||||||
|
* @var list<string>|string
|
||||||
|
*/
|
||||||
|
public $scriptSrc = 'self';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lists allowed stylesheets' URLs.
|
||||||
|
*
|
||||||
|
* @var list<string>|string
|
||||||
|
*/
|
||||||
|
public $styleSrc = 'self';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines the origins from which images can be loaded.
|
||||||
|
*
|
||||||
|
* @var list<string>|string
|
||||||
|
*/
|
||||||
|
public $imageSrc = 'self';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Restricts the URLs that can appear in a page's `<base>` element.
|
||||||
|
*
|
||||||
|
* Will default to self if not overridden
|
||||||
|
*
|
||||||
|
* @var list<string>|string|null
|
||||||
|
*/
|
||||||
|
public $baseURI;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lists the URLs for workers and embedded frame contents
|
||||||
|
*
|
||||||
|
* @var list<string>|string
|
||||||
|
*/
|
||||||
|
public $childSrc = 'self';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Limits the origins that you can connect to (via XHR,
|
||||||
|
* WebSockets, and EventSource).
|
||||||
|
*
|
||||||
|
* @var list<string>|string
|
||||||
|
*/
|
||||||
|
public $connectSrc = 'self';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specifies the origins that can serve web fonts.
|
||||||
|
*
|
||||||
|
* @var list<string>|string
|
||||||
|
*/
|
||||||
|
public $fontSrc;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lists valid endpoints for submission from `<form>` tags.
|
||||||
|
*
|
||||||
|
* @var list<string>|string
|
||||||
|
*/
|
||||||
|
public $formAction = 'self';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specifies the sources that can embed the current page.
|
||||||
|
* This directive applies to `<frame>`, `<iframe>`, `<embed>`,
|
||||||
|
* and `<applet>` tags. This directive can't be used in
|
||||||
|
* `<meta>` tags and applies only to non-HTML resources.
|
||||||
|
*
|
||||||
|
* @var list<string>|string|null
|
||||||
|
*/
|
||||||
|
public $frameAncestors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The frame-src directive restricts the URLs which may
|
||||||
|
* be loaded into nested browsing contexts.
|
||||||
|
*
|
||||||
|
* @var list<string>|string|null
|
||||||
|
*/
|
||||||
|
public $frameSrc;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Restricts the origins allowed to deliver video and audio.
|
||||||
|
*
|
||||||
|
* @var list<string>|string|null
|
||||||
|
*/
|
||||||
|
public $mediaSrc;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allows control over Flash and other plugins.
|
||||||
|
*
|
||||||
|
* @var list<string>|string
|
||||||
|
*/
|
||||||
|
public $objectSrc = 'self';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var list<string>|string|null
|
||||||
|
*/
|
||||||
|
public $manifestSrc;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Limits the kinds of plugins a page may invoke.
|
||||||
|
*
|
||||||
|
* @var list<string>|string|null
|
||||||
|
*/
|
||||||
|
public $pluginTypes;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List of actions allowed.
|
||||||
|
*
|
||||||
|
* @var list<string>|string|null
|
||||||
|
*/
|
||||||
|
public $sandbox;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Nonce tag for style
|
||||||
|
*/
|
||||||
|
public string $styleNonceTag = '{csp-style-nonce}';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Nonce tag for script
|
||||||
|
*/
|
||||||
|
public string $scriptNonceTag = '{csp-script-nonce}';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replace nonce tag automatically
|
||||||
|
*/
|
||||||
|
public bool $autoNonce = true;
|
||||||
|
}
|
||||||
107
app/Config/Cookie.php
Normal file
107
app/Config/Cookie.php
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Config;
|
||||||
|
|
||||||
|
use CodeIgniter\Config\BaseConfig;
|
||||||
|
use DateTimeInterface;
|
||||||
|
|
||||||
|
class Cookie extends BaseConfig
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* Cookie Prefix
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* Set a cookie name prefix if you need to avoid collisions.
|
||||||
|
*/
|
||||||
|
public string $prefix = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* Cookie Expires Timestamp
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* Default expires timestamp for cookies. Setting this to `0` will mean the
|
||||||
|
* cookie will not have the `Expires` attribute and will behave as a session
|
||||||
|
* cookie.
|
||||||
|
*
|
||||||
|
* @var DateTimeInterface|int|string
|
||||||
|
*/
|
||||||
|
public $expires = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* Cookie Path
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* Typically will be a forward slash.
|
||||||
|
*/
|
||||||
|
public string $path = '/';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* Cookie Domain
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* Set to `.your-domain.com` for site-wide cookies.
|
||||||
|
*/
|
||||||
|
public string $domain = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* Cookie Secure
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* Cookie will only be set if a secure HTTPS connection exists.
|
||||||
|
*/
|
||||||
|
public bool $secure = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* Cookie HTTPOnly
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* Cookie will only be accessible via HTTP(S) (no JavaScript).
|
||||||
|
*/
|
||||||
|
public bool $httponly = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* Cookie SameSite
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* Configure cookie SameSite setting. Allowed values are:
|
||||||
|
* - None
|
||||||
|
* - Lax
|
||||||
|
* - Strict
|
||||||
|
* - ''
|
||||||
|
*
|
||||||
|
* Alternatively, you can use the constant names:
|
||||||
|
* - `Cookie::SAMESITE_NONE`
|
||||||
|
* - `Cookie::SAMESITE_LAX`
|
||||||
|
* - `Cookie::SAMESITE_STRICT`
|
||||||
|
*
|
||||||
|
* Defaults to `Lax` for compatibility with modern browsers. Setting `''`
|
||||||
|
* (empty string) means default SameSite attribute set by browsers (`Lax`)
|
||||||
|
* will be set on cookies. If set to `None`, `$secure` must also be set.
|
||||||
|
*
|
||||||
|
* @phpstan-var 'None'|'Lax'|'Strict'|''
|
||||||
|
*/
|
||||||
|
public string $samesite = 'Lax';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* Cookie Raw
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* This flag allows setting a "raw" cookie, i.e., its name and value are
|
||||||
|
* not URL encoded using `rawurlencode()`.
|
||||||
|
*
|
||||||
|
* If this is set to `true`, cookie names should be compliant of RFC 2616's
|
||||||
|
* list of allowed characters.
|
||||||
|
*
|
||||||
|
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie#attributes
|
||||||
|
* @see https://tools.ietf.org/html/rfc2616#section-2.2
|
||||||
|
*/
|
||||||
|
public bool $raw = false;
|
||||||
|
}
|
||||||
105
app/Config/Cors.php
Normal file
105
app/Config/Cors.php
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Config;
|
||||||
|
|
||||||
|
use CodeIgniter\Config\BaseConfig;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cross-Origin Resource Sharing (CORS) Configuration
|
||||||
|
*
|
||||||
|
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
|
||||||
|
*/
|
||||||
|
class Cors extends BaseConfig
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The default CORS configuration.
|
||||||
|
*
|
||||||
|
* @var array{
|
||||||
|
* allowedOrigins: list<string>,
|
||||||
|
* allowedOriginsPatterns: list<string>,
|
||||||
|
* supportsCredentials: bool,
|
||||||
|
* allowedHeaders: list<string>,
|
||||||
|
* exposedHeaders: list<string>,
|
||||||
|
* allowedMethods: list<string>,
|
||||||
|
* maxAge: int,
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
public array $default = [
|
||||||
|
/**
|
||||||
|
* Origins for the `Access-Control-Allow-Origin` header.
|
||||||
|
*
|
||||||
|
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin
|
||||||
|
*
|
||||||
|
* E.g.:
|
||||||
|
* - ['http://localhost:8080']
|
||||||
|
* - ['https://www.example.com']
|
||||||
|
*/
|
||||||
|
'allowedOrigins' => [],
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Origin regex patterns for the `Access-Control-Allow-Origin` header.
|
||||||
|
*
|
||||||
|
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin
|
||||||
|
*
|
||||||
|
* NOTE: A pattern specified here is part of a regular expression. It will
|
||||||
|
* be actually `#\A<pattern>\z#`.
|
||||||
|
*
|
||||||
|
* E.g.:
|
||||||
|
* - ['https://\w+\.example\.com']
|
||||||
|
*/
|
||||||
|
'allowedOriginsPatterns' => [],
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Weather to send the `Access-Control-Allow-Credentials` header.
|
||||||
|
*
|
||||||
|
* The Access-Control-Allow-Credentials response header tells browsers whether
|
||||||
|
* the server allows cross-origin HTTP requests to include credentials.
|
||||||
|
*
|
||||||
|
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Credentials
|
||||||
|
*/
|
||||||
|
'supportsCredentials' => false,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set headers to allow.
|
||||||
|
*
|
||||||
|
* The Access-Control-Allow-Headers response header is used in response to
|
||||||
|
* a preflight request which includes the Access-Control-Request-Headers to
|
||||||
|
* indicate which HTTP headers can be used during the actual request.
|
||||||
|
*
|
||||||
|
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Headers
|
||||||
|
*/
|
||||||
|
'allowedHeaders' => [],
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set headers to expose.
|
||||||
|
*
|
||||||
|
* The Access-Control-Expose-Headers response header allows a server to
|
||||||
|
* indicate which response headers should be made available to scripts running
|
||||||
|
* in the browser, in response to a cross-origin request.
|
||||||
|
*
|
||||||
|
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Expose-Headers
|
||||||
|
*/
|
||||||
|
'exposedHeaders' => [],
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set methods to allow.
|
||||||
|
*
|
||||||
|
* The Access-Control-Allow-Methods response header specifies one or more
|
||||||
|
* methods allowed when accessing a resource in response to a preflight
|
||||||
|
* request.
|
||||||
|
*
|
||||||
|
* E.g.:
|
||||||
|
* - ['GET', 'POST', 'PUT', 'DELETE']
|
||||||
|
*
|
||||||
|
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Methods
|
||||||
|
*/
|
||||||
|
'allowedMethods' => [],
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set how many seconds the results of a preflight request can be cached.
|
||||||
|
*
|
||||||
|
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Max-Age
|
||||||
|
*/
|
||||||
|
'maxAge' => 7200,
|
||||||
|
];
|
||||||
|
}
|
||||||
203
app/Config/Database.php
Normal file
203
app/Config/Database.php
Normal file
@ -0,0 +1,203 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Config;
|
||||||
|
|
||||||
|
use CodeIgniter\Database\Config;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Database Configuration
|
||||||
|
*/
|
||||||
|
class Database extends Config
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The directory that holds the Migrations and Seeds directories.
|
||||||
|
*/
|
||||||
|
public string $filesPath = APPPATH . 'Database' . DIRECTORY_SEPARATOR;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lets you choose which connection group to use if no other is specified.
|
||||||
|
*/
|
||||||
|
public string $defaultGroup = 'default';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The default database connection.
|
||||||
|
*
|
||||||
|
* @var array<string, mixed>
|
||||||
|
*/
|
||||||
|
public array $default = [
|
||||||
|
'DSN' => '',
|
||||||
|
'hostname' => 'localhost',
|
||||||
|
'username' => 'ipsgroupcom_ams',
|
||||||
|
'password' => '#oQb9jvdgM-p',
|
||||||
|
'database' => 'ipsgroupcom_ams',
|
||||||
|
'DBDriver' => 'MySQLi',
|
||||||
|
'DBPrefix' => '',
|
||||||
|
'pConnect' => false,
|
||||||
|
'DBDebug' => true,
|
||||||
|
'charset' => 'utf8mb4',
|
||||||
|
'DBCollat' => 'utf8mb4_general_ci',
|
||||||
|
'swapPre' => '',
|
||||||
|
'encrypt' => false,
|
||||||
|
'compress' => false,
|
||||||
|
'strictOn' => false,
|
||||||
|
'failover' => [],
|
||||||
|
'port' => 3306,
|
||||||
|
'numberNative' => false,
|
||||||
|
'foundRows' => false,
|
||||||
|
'dateFormat' => [
|
||||||
|
'date' => 'Y-m-d',
|
||||||
|
'datetime' => 'Y-m-d H:i:s',
|
||||||
|
'time' => 'H:i:s',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * Sample database connection for SQLite3.
|
||||||
|
// *
|
||||||
|
// * @var array<string, mixed>
|
||||||
|
// */
|
||||||
|
// public array $default = [
|
||||||
|
// 'database' => 'database.db',
|
||||||
|
// 'DBDriver' => 'SQLite3',
|
||||||
|
// 'DBPrefix' => '',
|
||||||
|
// 'DBDebug' => true,
|
||||||
|
// 'swapPre' => '',
|
||||||
|
// 'failover' => [],
|
||||||
|
// 'foreignKeys' => true,
|
||||||
|
// 'busyTimeout' => 1000,
|
||||||
|
// 'synchronous' => null,
|
||||||
|
// 'dateFormat' => [
|
||||||
|
// 'date' => 'Y-m-d',
|
||||||
|
// 'datetime' => 'Y-m-d H:i:s',
|
||||||
|
// 'time' => 'H:i:s',
|
||||||
|
// ],
|
||||||
|
// ];
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * Sample database connection for Postgre.
|
||||||
|
// *
|
||||||
|
// * @var array<string, mixed>
|
||||||
|
// */
|
||||||
|
// public array $default = [
|
||||||
|
// 'DSN' => '',
|
||||||
|
// 'hostname' => 'localhost',
|
||||||
|
// 'username' => 'root',
|
||||||
|
// 'password' => 'root',
|
||||||
|
// 'database' => 'ci4',
|
||||||
|
// 'schema' => 'public',
|
||||||
|
// 'DBDriver' => 'Postgre',
|
||||||
|
// 'DBPrefix' => '',
|
||||||
|
// 'pConnect' => false,
|
||||||
|
// 'DBDebug' => true,
|
||||||
|
// 'charset' => 'utf8',
|
||||||
|
// 'swapPre' => '',
|
||||||
|
// 'failover' => [],
|
||||||
|
// 'port' => 5432,
|
||||||
|
// 'dateFormat' => [
|
||||||
|
// 'date' => 'Y-m-d',
|
||||||
|
// 'datetime' => 'Y-m-d H:i:s',
|
||||||
|
// 'time' => 'H:i:s',
|
||||||
|
// ],
|
||||||
|
// ];
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * Sample database connection for SQLSRV.
|
||||||
|
// *
|
||||||
|
// * @var array<string, mixed>
|
||||||
|
// */
|
||||||
|
// public array $default = [
|
||||||
|
// 'DSN' => '',
|
||||||
|
// 'hostname' => 'localhost',
|
||||||
|
// 'username' => 'root',
|
||||||
|
// 'password' => 'root',
|
||||||
|
// 'database' => 'ci4',
|
||||||
|
// 'schema' => 'dbo',
|
||||||
|
// 'DBDriver' => 'SQLSRV',
|
||||||
|
// 'DBPrefix' => '',
|
||||||
|
// 'pConnect' => false,
|
||||||
|
// 'DBDebug' => true,
|
||||||
|
// 'charset' => 'utf8',
|
||||||
|
// 'swapPre' => '',
|
||||||
|
// 'encrypt' => false,
|
||||||
|
// 'failover' => [],
|
||||||
|
// 'port' => 1433,
|
||||||
|
// 'dateFormat' => [
|
||||||
|
// 'date' => 'Y-m-d',
|
||||||
|
// 'datetime' => 'Y-m-d H:i:s',
|
||||||
|
// 'time' => 'H:i:s',
|
||||||
|
// ],
|
||||||
|
// ];
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * Sample database connection for OCI8.
|
||||||
|
// *
|
||||||
|
// * You may need the following environment variables:
|
||||||
|
// * NLS_LANG = 'AMERICAN_AMERICA.UTF8'
|
||||||
|
// * NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:MI:SS'
|
||||||
|
// * NLS_TIMESTAMP_FORMAT = 'YYYY-MM-DD HH24:MI:SS'
|
||||||
|
// * NLS_TIMESTAMP_TZ_FORMAT = 'YYYY-MM-DD HH24:MI:SS'
|
||||||
|
// *
|
||||||
|
// * @var array<string, mixed>
|
||||||
|
// */
|
||||||
|
// public array $default = [
|
||||||
|
// 'DSN' => 'localhost:1521/XEPDB1',
|
||||||
|
// 'username' => 'root',
|
||||||
|
// 'password' => 'root',
|
||||||
|
// 'DBDriver' => 'OCI8',
|
||||||
|
// 'DBPrefix' => '',
|
||||||
|
// 'pConnect' => false,
|
||||||
|
// 'DBDebug' => true,
|
||||||
|
// 'charset' => 'AL32UTF8',
|
||||||
|
// 'swapPre' => '',
|
||||||
|
// 'failover' => [],
|
||||||
|
// 'dateFormat' => [
|
||||||
|
// 'date' => 'Y-m-d',
|
||||||
|
// 'datetime' => 'Y-m-d H:i:s',
|
||||||
|
// 'time' => 'H:i:s',
|
||||||
|
// ],
|
||||||
|
// ];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This database connection is used when running PHPUnit database tests.
|
||||||
|
*
|
||||||
|
* @var array<string, mixed>
|
||||||
|
*/
|
||||||
|
public array $tests = [
|
||||||
|
'DSN' => '',
|
||||||
|
'hostname' => '127.0.0.1',
|
||||||
|
'username' => '',
|
||||||
|
'password' => '',
|
||||||
|
'database' => ':memory:',
|
||||||
|
'DBDriver' => 'SQLite3',
|
||||||
|
'DBPrefix' => 'db_', // Needed to ensure we're working correctly with prefixes live. DO NOT REMOVE FOR CI DEVS
|
||||||
|
'pConnect' => false,
|
||||||
|
'DBDebug' => true,
|
||||||
|
'charset' => 'utf8',
|
||||||
|
'DBCollat' => '',
|
||||||
|
'swapPre' => '',
|
||||||
|
'encrypt' => false,
|
||||||
|
'compress' => false,
|
||||||
|
'strictOn' => false,
|
||||||
|
'failover' => [],
|
||||||
|
'port' => 3306,
|
||||||
|
'foreignKeys' => true,
|
||||||
|
'busyTimeout' => 1000,
|
||||||
|
'dateFormat' => [
|
||||||
|
'date' => 'Y-m-d',
|
||||||
|
'datetime' => 'Y-m-d H:i:s',
|
||||||
|
'time' => 'H:i:s',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
|
||||||
|
// Ensure that we always set the database group to 'tests' if
|
||||||
|
// we are currently running an automated test suite, so that
|
||||||
|
// we don't overwrite live data on accident.
|
||||||
|
if (ENVIRONMENT === 'testing') {
|
||||||
|
$this->defaultGroup = 'tests';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
43
app/Config/DocTypes.php
Normal file
43
app/Config/DocTypes.php
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Config;
|
||||||
|
|
||||||
|
class DocTypes
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* List of valid document types.
|
||||||
|
*
|
||||||
|
* @var array<string, string>
|
||||||
|
*/
|
||||||
|
public array $list = [
|
||||||
|
'xhtml11' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">',
|
||||||
|
'xhtml1-strict' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">',
|
||||||
|
'xhtml1-trans' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">',
|
||||||
|
'xhtml1-frame' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">',
|
||||||
|
'xhtml-basic11' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd">',
|
||||||
|
'html5' => '<!DOCTYPE html>',
|
||||||
|
'html4-strict' => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">',
|
||||||
|
'html4-trans' => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">',
|
||||||
|
'html4-frame' => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">',
|
||||||
|
'mathml1' => '<!DOCTYPE math SYSTEM "http://www.w3.org/Math/DTD/mathml1/mathml.dtd">',
|
||||||
|
'mathml2' => '<!DOCTYPE math PUBLIC "-//W3C//DTD MathML 2.0//EN" "http://www.w3.org/Math/DTD/mathml2/mathml2.dtd">',
|
||||||
|
'svg10' => '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">',
|
||||||
|
'svg11' => '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">',
|
||||||
|
'svg11-basic' => '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1 Basic//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-basic.dtd">',
|
||||||
|
'svg11-tiny' => '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1 Tiny//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-tiny.dtd">',
|
||||||
|
'xhtml-math-svg-xh' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">',
|
||||||
|
'xhtml-math-svg-sh' => '<!DOCTYPE svg:svg PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">',
|
||||||
|
'xhtml-rdfa-1' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">',
|
||||||
|
'xhtml-rdfa-2' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.1//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-2.dtd">',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether to remove the solidus (`/`) character for void HTML elements (e.g. `<input>`)
|
||||||
|
* for HTML5 compatibility.
|
||||||
|
*
|
||||||
|
* Set to:
|
||||||
|
* `true` - to be HTML5 compatible
|
||||||
|
* `false` - to be XHTML compatible
|
||||||
|
*/
|
||||||
|
public bool $html5 = true;
|
||||||
|
}
|
||||||
121
app/Config/Email.php
Normal file
121
app/Config/Email.php
Normal file
@ -0,0 +1,121 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Config;
|
||||||
|
|
||||||
|
use CodeIgniter\Config\BaseConfig;
|
||||||
|
|
||||||
|
class Email extends BaseConfig
|
||||||
|
{
|
||||||
|
public string $fromEmail = '';
|
||||||
|
public string $fromName = '';
|
||||||
|
public string $recipients = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The "user agent"
|
||||||
|
*/
|
||||||
|
public string $userAgent = 'CodeIgniter';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The mail sending protocol: mail, sendmail, smtp
|
||||||
|
*/
|
||||||
|
public string $protocol = 'mail';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The server path to Sendmail.
|
||||||
|
*/
|
||||||
|
public string $mailPath = '/usr/sbin/sendmail';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SMTP Server Hostname
|
||||||
|
*/
|
||||||
|
public string $SMTPHost = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SMTP Username
|
||||||
|
*/
|
||||||
|
public string $SMTPUser = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SMTP Password
|
||||||
|
*/
|
||||||
|
public string $SMTPPass = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SMTP Port
|
||||||
|
*/
|
||||||
|
public int $SMTPPort = 25;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SMTP Timeout (in seconds)
|
||||||
|
*/
|
||||||
|
public int $SMTPTimeout = 5;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable persistent SMTP connections
|
||||||
|
*/
|
||||||
|
public bool $SMTPKeepAlive = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SMTP Encryption.
|
||||||
|
*
|
||||||
|
* @var string '', 'tls' or 'ssl'. 'tls' will issue a STARTTLS command
|
||||||
|
* to the server. 'ssl' means implicit SSL. Connection on port
|
||||||
|
* 465 should set this to ''.
|
||||||
|
*/
|
||||||
|
public string $SMTPCrypto = 'tls';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable word-wrap
|
||||||
|
*/
|
||||||
|
public bool $wordWrap = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Character count to wrap at
|
||||||
|
*/
|
||||||
|
public int $wrapChars = 76;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Type of mail, either 'text' or 'html'
|
||||||
|
*/
|
||||||
|
public string $mailType = 'text';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Character set (utf-8, iso-8859-1, etc.)
|
||||||
|
*/
|
||||||
|
public string $charset = 'UTF-8';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether to validate the email address
|
||||||
|
*/
|
||||||
|
public bool $validate = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Email Priority. 1 = highest. 5 = lowest. 3 = normal
|
||||||
|
*/
|
||||||
|
public int $priority = 3;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Newline character. (Use “\r\n” to comply with RFC 822)
|
||||||
|
*/
|
||||||
|
public string $CRLF = "\r\n";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Newline character. (Use “\r\n” to comply with RFC 822)
|
||||||
|
*/
|
||||||
|
public string $newline = "\r\n";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable BCC Batch Mode.
|
||||||
|
*/
|
||||||
|
public bool $BCCBatchMode = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Number of emails in each BCC batch
|
||||||
|
*/
|
||||||
|
public int $BCCBatchSize = 200;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable notify message from server
|
||||||
|
*/
|
||||||
|
public bool $DSN = false;
|
||||||
|
}
|
||||||
92
app/Config/Encryption.php
Normal file
92
app/Config/Encryption.php
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Config;
|
||||||
|
|
||||||
|
use CodeIgniter\Config\BaseConfig;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encryption configuration.
|
||||||
|
*
|
||||||
|
* These are the settings used for encryption, if you don't pass a parameter
|
||||||
|
* array to the encrypter for creation/initialization.
|
||||||
|
*/
|
||||||
|
class Encryption extends BaseConfig
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* Encryption Key Starter
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* If you use the Encryption class you must set an encryption key (seed).
|
||||||
|
* You need to ensure it is long enough for the cipher and mode you plan to use.
|
||||||
|
* See the user guide for more info.
|
||||||
|
*/
|
||||||
|
public string $key = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* Encryption Driver to Use
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* One of the supported encryption drivers.
|
||||||
|
*
|
||||||
|
* Available drivers:
|
||||||
|
* - OpenSSL
|
||||||
|
* - Sodium
|
||||||
|
*/
|
||||||
|
public string $driver = 'OpenSSL';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* SodiumHandler's Padding Length in Bytes
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* This is the number of bytes that will be padded to the plaintext message
|
||||||
|
* before it is encrypted. This value should be greater than zero.
|
||||||
|
*
|
||||||
|
* See the user guide for more information on padding.
|
||||||
|
*/
|
||||||
|
public int $blockSize = 16;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* Encryption digest
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* HMAC digest to use, e.g. 'SHA512' or 'SHA256'. Default value is 'SHA512'.
|
||||||
|
*/
|
||||||
|
public string $digest = 'SHA512';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the cipher-text should be raw. If set to false, then it will be base64 encoded.
|
||||||
|
* This setting is only used by OpenSSLHandler.
|
||||||
|
*
|
||||||
|
* Set to false for CI3 Encryption compatibility.
|
||||||
|
*/
|
||||||
|
public bool $rawData = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encryption key info.
|
||||||
|
* This setting is only used by OpenSSLHandler.
|
||||||
|
*
|
||||||
|
* Set to 'encryption' for CI3 Encryption compatibility.
|
||||||
|
*/
|
||||||
|
public string $encryptKeyInfo = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Authentication key info.
|
||||||
|
* This setting is only used by OpenSSLHandler.
|
||||||
|
*
|
||||||
|
* Set to 'authentication' for CI3 Encryption compatibility.
|
||||||
|
*/
|
||||||
|
public string $authKeyInfo = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cipher to use.
|
||||||
|
* This setting is only used by OpenSSLHandler.
|
||||||
|
*
|
||||||
|
* Set to 'AES-128-CBC' to decrypt encrypted data that encrypted
|
||||||
|
* by CI3 Encryption default configuration.
|
||||||
|
*/
|
||||||
|
public string $cipher = 'AES-256-CTR';
|
||||||
|
}
|
||||||
55
app/Config/Events.php
Normal file
55
app/Config/Events.php
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Config;
|
||||||
|
|
||||||
|
use CodeIgniter\Events\Events;
|
||||||
|
use CodeIgniter\Exceptions\FrameworkException;
|
||||||
|
use CodeIgniter\HotReloader\HotReloader;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* --------------------------------------------------------------------
|
||||||
|
* Application Events
|
||||||
|
* --------------------------------------------------------------------
|
||||||
|
* Events allow you to tap into the execution of the program without
|
||||||
|
* modifying or extending core files. This file provides a central
|
||||||
|
* location to define your events, though they can always be added
|
||||||
|
* at run-time, also, if needed.
|
||||||
|
*
|
||||||
|
* You create code that can execute by subscribing to events with
|
||||||
|
* the 'on()' method. This accepts any form of callable, including
|
||||||
|
* Closures, that will be executed when the event is triggered.
|
||||||
|
*
|
||||||
|
* Example:
|
||||||
|
* Events::on('create', [$myInstance, 'myMethod']);
|
||||||
|
*/
|
||||||
|
|
||||||
|
Events::on('pre_system', static function (): void {
|
||||||
|
if (ENVIRONMENT !== 'testing') {
|
||||||
|
if (ini_get('zlib.output_compression')) {
|
||||||
|
throw FrameworkException::forEnabledZlibOutputCompression();
|
||||||
|
}
|
||||||
|
|
||||||
|
while (ob_get_level() > 0) {
|
||||||
|
ob_end_flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
ob_start(static fn ($buffer) => $buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* --------------------------------------------------------------------
|
||||||
|
* Debug Toolbar Listeners.
|
||||||
|
* --------------------------------------------------------------------
|
||||||
|
* If you delete, they will no longer be collected.
|
||||||
|
*/
|
||||||
|
if (CI_DEBUG && ! is_cli()) {
|
||||||
|
Events::on('DBQuery', 'CodeIgniter\Debug\Toolbar\Collectors\Database::collect');
|
||||||
|
service('toolbar')->respond();
|
||||||
|
// Hot Reload route - for framework use on the hot reloader.
|
||||||
|
if (ENVIRONMENT === 'development') {
|
||||||
|
service('routes')->get('__hot-reload', static function (): void {
|
||||||
|
(new HotReloader())->run();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
106
app/Config/Exceptions.php
Normal file
106
app/Config/Exceptions.php
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Config;
|
||||||
|
|
||||||
|
use CodeIgniter\Config\BaseConfig;
|
||||||
|
use CodeIgniter\Debug\ExceptionHandler;
|
||||||
|
use CodeIgniter\Debug\ExceptionHandlerInterface;
|
||||||
|
use Psr\Log\LogLevel;
|
||||||
|
use Throwable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setup how the exception handler works.
|
||||||
|
*/
|
||||||
|
class Exceptions extends BaseConfig
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* LOG EXCEPTIONS?
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* If true, then exceptions will be logged
|
||||||
|
* through Services::Log.
|
||||||
|
*
|
||||||
|
* Default: true
|
||||||
|
*/
|
||||||
|
public bool $log = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* DO NOT LOG STATUS CODES
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* Any status codes here will NOT be logged if logging is turned on.
|
||||||
|
* By default, only 404 (Page Not Found) exceptions are ignored.
|
||||||
|
*
|
||||||
|
* @var list<int>
|
||||||
|
*/
|
||||||
|
public array $ignoreCodes = [404];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* Error Views Path
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* This is the path to the directory that contains the 'cli' and 'html'
|
||||||
|
* directories that hold the views used to generate errors.
|
||||||
|
*
|
||||||
|
* Default: APPPATH.'Views/errors'
|
||||||
|
*/
|
||||||
|
public string $errorViewPath = APPPATH . 'Views/errors';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* HIDE FROM DEBUG TRACE
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* Any data that you would like to hide from the debug trace.
|
||||||
|
* In order to specify 2 levels, use "/" to separate.
|
||||||
|
* ex. ['server', 'setup/password', 'secret_token']
|
||||||
|
*
|
||||||
|
* @var list<string>
|
||||||
|
*/
|
||||||
|
public array $sensitiveDataInTrace = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* WHETHER TO THROW AN EXCEPTION ON DEPRECATED ERRORS
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* If set to `true`, DEPRECATED errors are only logged and no exceptions are
|
||||||
|
* thrown. This option also works for user deprecations.
|
||||||
|
*/
|
||||||
|
public bool $logDeprecations = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* LOG LEVEL THRESHOLD FOR DEPRECATIONS
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* If `$logDeprecations` is set to `true`, this sets the log level
|
||||||
|
* to which the deprecation will be logged. This should be one of the log
|
||||||
|
* levels recognized by PSR-3.
|
||||||
|
*
|
||||||
|
* The related `Config\Logger::$threshold` should be adjusted, if needed,
|
||||||
|
* to capture logging the deprecations.
|
||||||
|
*/
|
||||||
|
public string $deprecationLogLevel = LogLevel::WARNING;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* DEFINE THE HANDLERS USED
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* Given the HTTP status code, returns exception handler that
|
||||||
|
* should be used to deal with this error. By default, it will run CodeIgniter's
|
||||||
|
* default handler and display the error information in the expected format
|
||||||
|
* for CLI, HTTP, or AJAX requests, as determined by is_cli() and the expected
|
||||||
|
* response format.
|
||||||
|
*
|
||||||
|
* Custom handlers can be returned if you want to handle one or more specific
|
||||||
|
* error codes yourself like:
|
||||||
|
*
|
||||||
|
* if (in_array($statusCode, [400, 404, 500])) {
|
||||||
|
* return new \App\Libraries\MyExceptionHandler();
|
||||||
|
* }
|
||||||
|
* if ($exception instanceOf PageNotFoundException) {
|
||||||
|
* return new \App\Libraries\MyExceptionHandler();
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
public function handler(int $statusCode, Throwable $exception): ExceptionHandlerInterface
|
||||||
|
{
|
||||||
|
return new ExceptionHandler($this);
|
||||||
|
}
|
||||||
|
}
|
||||||
37
app/Config/Feature.php
Normal file
37
app/Config/Feature.php
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Config;
|
||||||
|
|
||||||
|
use CodeIgniter\Config\BaseConfig;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable/disable backward compatibility breaking features.
|
||||||
|
*/
|
||||||
|
class Feature extends BaseConfig
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Use improved new auto routing instead of the legacy version.
|
||||||
|
*/
|
||||||
|
public bool $autoRoutesImproved = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use filter execution order in 4.4 or before.
|
||||||
|
*/
|
||||||
|
public bool $oldFilterOrder = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The behavior of `limit(0)` in Query Builder.
|
||||||
|
*
|
||||||
|
* If true, `limit(0)` returns all records. (the behavior of 4.4.x or before in version 4.x.)
|
||||||
|
* If false, `limit(0)` returns no records. (the behavior of 3.1.9 or later in version 3.x.)
|
||||||
|
*/
|
||||||
|
public bool $limitZeroAsAll = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use strict location negotiation.
|
||||||
|
*
|
||||||
|
* By default, the locale is selected based on a loose comparison of the language code (ISO 639-1)
|
||||||
|
* Enabling strict comparison will also consider the region code (ISO 3166-1 alpha-2).
|
||||||
|
*/
|
||||||
|
public bool $strictLocaleNegotiation = false;
|
||||||
|
}
|
||||||
109
app/Config/Filters.php
Normal file
109
app/Config/Filters.php
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Config;
|
||||||
|
|
||||||
|
use CodeIgniter\Config\Filters as BaseFilters;
|
||||||
|
use CodeIgniter\Filters\Cors;
|
||||||
|
use CodeIgniter\Filters\CSRF;
|
||||||
|
use CodeIgniter\Filters\DebugToolbar;
|
||||||
|
use CodeIgniter\Filters\ForceHTTPS;
|
||||||
|
use CodeIgniter\Filters\Honeypot;
|
||||||
|
use CodeIgniter\Filters\InvalidChars;
|
||||||
|
use CodeIgniter\Filters\PageCache;
|
||||||
|
use CodeIgniter\Filters\PerformanceMetrics;
|
||||||
|
use CodeIgniter\Filters\SecureHeaders;
|
||||||
|
|
||||||
|
class Filters extends BaseFilters
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Configures aliases for Filter classes to
|
||||||
|
* make reading things nicer and simpler.
|
||||||
|
*
|
||||||
|
* @var array<string, class-string|list<class-string>>
|
||||||
|
*
|
||||||
|
* [filter_name => classname]
|
||||||
|
* or [filter_name => [classname1, classname2, ...]]
|
||||||
|
*/
|
||||||
|
public array $aliases = [
|
||||||
|
'csrf' => CSRF::class,
|
||||||
|
'toolbar' => DebugToolbar::class,
|
||||||
|
'honeypot' => Honeypot::class,
|
||||||
|
'invalidchars' => InvalidChars::class,
|
||||||
|
'secureheaders' => SecureHeaders::class,
|
||||||
|
'cors' => Cors::class,
|
||||||
|
'forcehttps' => ForceHTTPS::class,
|
||||||
|
'pagecache' => PageCache::class,
|
||||||
|
'performance' => PerformanceMetrics::class,
|
||||||
|
'authFilter' => \App\Filters\AuthFilter::class,
|
||||||
|
'customerAuthFilter' => \App\Filters\CustomerAuthFilter::class,
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List of special required filters.
|
||||||
|
*
|
||||||
|
* The filters listed here are special. They are applied before and after
|
||||||
|
* other kinds of filters, and always applied even if a route does not exist.
|
||||||
|
*
|
||||||
|
* Filters set by default provide framework functionality. If removed,
|
||||||
|
* those functions will no longer work.
|
||||||
|
*
|
||||||
|
* @see https://codeigniter.com/user_guide/incoming/filters.html#provided-filters
|
||||||
|
*
|
||||||
|
* @var array{before: list<string>, after: list<string>}
|
||||||
|
*/
|
||||||
|
public array $required = [
|
||||||
|
'before' => [
|
||||||
|
'forcehttps', // Force Global Secure Requests
|
||||||
|
'pagecache', // Web Page Caching
|
||||||
|
],
|
||||||
|
'after' => [
|
||||||
|
'pagecache', // Web Page Caching
|
||||||
|
'performance', // Performance Metrics
|
||||||
|
'toolbar', // Debug Toolbar
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List of filter aliases that are always
|
||||||
|
* applied before and after every request.
|
||||||
|
*
|
||||||
|
* @var array<string, array<string, array<string, string>>>|array<string, list<string>>
|
||||||
|
*/
|
||||||
|
public array $globals = [
|
||||||
|
'before' => [
|
||||||
|
// 'honeypot',
|
||||||
|
// 'csrf',
|
||||||
|
// 'invalidchars',
|
||||||
|
],
|
||||||
|
'after' => [
|
||||||
|
// 'honeypot',
|
||||||
|
// 'secureheaders',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List of filter aliases that works on a
|
||||||
|
* particular HTTP method (GET, POST, etc.).
|
||||||
|
*
|
||||||
|
* Example:
|
||||||
|
* 'POST' => ['foo', 'bar']
|
||||||
|
*
|
||||||
|
* If you use this, you should disable auto-routing because auto-routing
|
||||||
|
* permits any HTTP method to access a controller. Accessing the controller
|
||||||
|
* with a method you don't expect could bypass the filter.
|
||||||
|
*
|
||||||
|
* @var array<string, list<string>>
|
||||||
|
*/
|
||||||
|
public array $methods = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List of filter aliases that should run on any
|
||||||
|
* before or after URI patterns.
|
||||||
|
*
|
||||||
|
* Example:
|
||||||
|
* 'isLoggedIn' => ['before' => ['account/*', 'profiles/*']]
|
||||||
|
*
|
||||||
|
* @var array<string, array<string, list<string>>>
|
||||||
|
*/
|
||||||
|
public array $filters = [];
|
||||||
|
}
|
||||||
12
app/Config/ForeignCharacters.php
Normal file
12
app/Config/ForeignCharacters.php
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Config;
|
||||||
|
|
||||||
|
use CodeIgniter\Config\ForeignCharacters as BaseForeignCharacters;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @immutable
|
||||||
|
*/
|
||||||
|
class ForeignCharacters extends BaseForeignCharacters
|
||||||
|
{
|
||||||
|
}
|
||||||
64
app/Config/Format.php
Normal file
64
app/Config/Format.php
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Config;
|
||||||
|
|
||||||
|
use CodeIgniter\Config\BaseConfig;
|
||||||
|
use CodeIgniter\Format\JSONFormatter;
|
||||||
|
use CodeIgniter\Format\XMLFormatter;
|
||||||
|
|
||||||
|
class Format extends BaseConfig
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* Available Response Formats
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* When you perform content negotiation with the request, these are the
|
||||||
|
* available formats that your application supports. This is currently
|
||||||
|
* only used with the API\ResponseTrait. A valid Formatter must exist
|
||||||
|
* for the specified format.
|
||||||
|
*
|
||||||
|
* These formats are only checked when the data passed to the respond()
|
||||||
|
* method is an array.
|
||||||
|
*
|
||||||
|
* @var list<string>
|
||||||
|
*/
|
||||||
|
public array $supportedResponseFormats = [
|
||||||
|
'application/json',
|
||||||
|
'application/xml', // machine-readable XML
|
||||||
|
'text/xml', // human-readable XML
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* Formatters
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* Lists the class to use to format responses with of a particular type.
|
||||||
|
* For each mime type, list the class that should be used. Formatters
|
||||||
|
* can be retrieved through the getFormatter() method.
|
||||||
|
*
|
||||||
|
* @var array<string, string>
|
||||||
|
*/
|
||||||
|
public array $formatters = [
|
||||||
|
'application/json' => JSONFormatter::class,
|
||||||
|
'application/xml' => XMLFormatter::class,
|
||||||
|
'text/xml' => XMLFormatter::class,
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* Formatters Options
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* Additional Options to adjust default formatters behaviour.
|
||||||
|
* For each mime type, list the additional options that should be used.
|
||||||
|
*
|
||||||
|
* @var array<string, int>
|
||||||
|
*/
|
||||||
|
public array $formatterOptions = [
|
||||||
|
'application/json' => JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES,
|
||||||
|
'application/xml' => 0,
|
||||||
|
'text/xml' => 0,
|
||||||
|
];
|
||||||
|
}
|
||||||
44
app/Config/Generators.php
Normal file
44
app/Config/Generators.php
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Config;
|
||||||
|
|
||||||
|
use CodeIgniter\Config\BaseConfig;
|
||||||
|
|
||||||
|
class Generators extends BaseConfig
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* Generator Commands' Views
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* This array defines the mapping of generator commands to the view files
|
||||||
|
* they are using. If you need to customize them for your own, copy these
|
||||||
|
* view files in your own folder and indicate the location here.
|
||||||
|
*
|
||||||
|
* You will notice that the views have special placeholders enclosed in
|
||||||
|
* curly braces `{...}`. These placeholders are used internally by the
|
||||||
|
* generator commands in processing replacements, thus you are warned
|
||||||
|
* not to delete them or modify the names. If you will do so, you may
|
||||||
|
* end up disrupting the scaffolding process and throw errors.
|
||||||
|
*
|
||||||
|
* YOU HAVE BEEN WARNED!
|
||||||
|
*
|
||||||
|
* @var array<string, array<string, string>|string>
|
||||||
|
*/
|
||||||
|
public array $views = [
|
||||||
|
'make:cell' => [
|
||||||
|
'class' => 'CodeIgniter\Commands\Generators\Views\cell.tpl.php',
|
||||||
|
'view' => 'CodeIgniter\Commands\Generators\Views\cell_view.tpl.php',
|
||||||
|
],
|
||||||
|
'make:command' => 'CodeIgniter\Commands\Generators\Views\command.tpl.php',
|
||||||
|
'make:config' => 'CodeIgniter\Commands\Generators\Views\config.tpl.php',
|
||||||
|
'make:controller' => 'CodeIgniter\Commands\Generators\Views\controller.tpl.php',
|
||||||
|
'make:entity' => 'CodeIgniter\Commands\Generators\Views\entity.tpl.php',
|
||||||
|
'make:filter' => 'CodeIgniter\Commands\Generators\Views\filter.tpl.php',
|
||||||
|
'make:migration' => 'CodeIgniter\Commands\Generators\Views\migration.tpl.php',
|
||||||
|
'make:model' => 'CodeIgniter\Commands\Generators\Views\model.tpl.php',
|
||||||
|
'make:seeder' => 'CodeIgniter\Commands\Generators\Views\seeder.tpl.php',
|
||||||
|
'make:validation' => 'CodeIgniter\Commands\Generators\Views\validation.tpl.php',
|
||||||
|
'session:migration' => 'CodeIgniter\Commands\Generators\Views\migration.tpl.php',
|
||||||
|
];
|
||||||
|
}
|
||||||
42
app/Config/Honeypot.php
Normal file
42
app/Config/Honeypot.php
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Config;
|
||||||
|
|
||||||
|
use CodeIgniter\Config\BaseConfig;
|
||||||
|
|
||||||
|
class Honeypot extends BaseConfig
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Makes Honeypot visible or not to human
|
||||||
|
*/
|
||||||
|
public bool $hidden = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Honeypot Label Content
|
||||||
|
*/
|
||||||
|
public string $label = 'Fill This Field';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Honeypot Field Name
|
||||||
|
*/
|
||||||
|
public string $name = 'honeypot';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Honeypot HTML Template
|
||||||
|
*/
|
||||||
|
public string $template = '<label>{label}</label><input type="text" name="{name}" value="">';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Honeypot container
|
||||||
|
*
|
||||||
|
* If you enabled CSP, you can remove `style="display:none"`.
|
||||||
|
*/
|
||||||
|
public string $container = '<div style="display:none">{template}</div>';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The id attribute for Honeypot container tag
|
||||||
|
*
|
||||||
|
* Used when CSP is enabled.
|
||||||
|
*/
|
||||||
|
public string $containerId = 'hpc';
|
||||||
|
}
|
||||||
31
app/Config/Images.php
Normal file
31
app/Config/Images.php
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Config;
|
||||||
|
|
||||||
|
use CodeIgniter\Config\BaseConfig;
|
||||||
|
use CodeIgniter\Images\Handlers\GDHandler;
|
||||||
|
use CodeIgniter\Images\Handlers\ImageMagickHandler;
|
||||||
|
|
||||||
|
class Images extends BaseConfig
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Default handler used if no other handler is specified.
|
||||||
|
*/
|
||||||
|
public string $defaultHandler = 'gd';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The path to the image library.
|
||||||
|
* Required for ImageMagick, GraphicsMagick, or NetPBM.
|
||||||
|
*/
|
||||||
|
public string $libraryPath = '/usr/local/bin/convert';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The available handler classes.
|
||||||
|
*
|
||||||
|
* @var array<string, string>
|
||||||
|
*/
|
||||||
|
public array $handlers = [
|
||||||
|
'gd' => GDHandler::class,
|
||||||
|
'imagick' => ImageMagickHandler::class,
|
||||||
|
];
|
||||||
|
}
|
||||||
63
app/Config/Kint.php
Normal file
63
app/Config/Kint.php
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Config;
|
||||||
|
|
||||||
|
use Kint\Parser\ConstructablePluginInterface;
|
||||||
|
use Kint\Renderer\Rich\TabPluginInterface;
|
||||||
|
use Kint\Renderer\Rich\ValuePluginInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* Kint
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* We use Kint's `RichRenderer` and `CLIRenderer`. This area contains options
|
||||||
|
* that you can set to customize how Kint works for you.
|
||||||
|
*
|
||||||
|
* @see https://kint-php.github.io/kint/ for details on these settings.
|
||||||
|
*/
|
||||||
|
class Kint
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Global Settings
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var list<class-string<ConstructablePluginInterface>|ConstructablePluginInterface>|null
|
||||||
|
*/
|
||||||
|
public $plugins;
|
||||||
|
|
||||||
|
public int $maxDepth = 6;
|
||||||
|
public bool $displayCalledFrom = true;
|
||||||
|
public bool $expanded = false;
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| RichRenderer Settings
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
public string $richTheme = 'aante-light.css';
|
||||||
|
public bool $richFolder = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array<string, class-string<ValuePluginInterface>>|null
|
||||||
|
*/
|
||||||
|
public $richObjectPlugins;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array<string, class-string<TabPluginInterface>>|null
|
||||||
|
*/
|
||||||
|
public $richTabPlugins;
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| CLI Settings
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
public bool $cliColors = true;
|
||||||
|
public bool $cliForceUTF8 = false;
|
||||||
|
public bool $cliDetectWidth = true;
|
||||||
|
public int $cliMinWidth = 40;
|
||||||
|
}
|
||||||
150
app/Config/Logger.php
Normal file
150
app/Config/Logger.php
Normal file
@ -0,0 +1,150 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Config;
|
||||||
|
|
||||||
|
use CodeIgniter\Config\BaseConfig;
|
||||||
|
use CodeIgniter\Log\Handlers\FileHandler;
|
||||||
|
|
||||||
|
class Logger extends BaseConfig
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* Error Logging Threshold
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* You can enable error logging by setting a threshold over zero. The
|
||||||
|
* threshold determines what gets logged. Any values below or equal to the
|
||||||
|
* threshold will be logged.
|
||||||
|
*
|
||||||
|
* Threshold options are:
|
||||||
|
*
|
||||||
|
* - 0 = Disables logging, Error logging TURNED OFF
|
||||||
|
* - 1 = Emergency Messages - System is unusable
|
||||||
|
* - 2 = Alert Messages - Action Must Be Taken Immediately
|
||||||
|
* - 3 = Critical Messages - Application component unavailable, unexpected exception.
|
||||||
|
* - 4 = Runtime Errors - Don't need immediate action, but should be monitored.
|
||||||
|
* - 5 = Warnings - Exceptional occurrences that are not errors.
|
||||||
|
* - 6 = Notices - Normal but significant events.
|
||||||
|
* - 7 = Info - Interesting events, like user logging in, etc.
|
||||||
|
* - 8 = Debug - Detailed debug information.
|
||||||
|
* - 9 = All Messages
|
||||||
|
*
|
||||||
|
* You can also pass an array with threshold levels to show individual error types
|
||||||
|
*
|
||||||
|
* array(1, 2, 3, 8) = Emergency, Alert, Critical, and Debug messages
|
||||||
|
*
|
||||||
|
* For a live site you'll usually enable Critical or higher (3) to be logged otherwise
|
||||||
|
* your log files will fill up very fast.
|
||||||
|
*
|
||||||
|
* @var int|list<int>
|
||||||
|
*/
|
||||||
|
public $threshold = (ENVIRONMENT === 'production') ? 4 : 9;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* Date Format for Logs
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* Each item that is logged has an associated date. You can use PHP date
|
||||||
|
* codes to set your own date formatting
|
||||||
|
*/
|
||||||
|
public string $dateFormat = 'Y-m-d H:i:s';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* Log Handlers
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* The logging system supports multiple actions to be taken when something
|
||||||
|
* is logged. This is done by allowing for multiple Handlers, special classes
|
||||||
|
* designed to write the log to their chosen destinations, whether that is
|
||||||
|
* a file on the getServer, a cloud-based service, or even taking actions such
|
||||||
|
* as emailing the dev team.
|
||||||
|
*
|
||||||
|
* Each handler is defined by the class name used for that handler, and it
|
||||||
|
* MUST implement the `CodeIgniter\Log\Handlers\HandlerInterface` interface.
|
||||||
|
*
|
||||||
|
* The value of each key is an array of configuration items that are sent
|
||||||
|
* to the constructor of each handler. The only required configuration item
|
||||||
|
* is the 'handles' element, which must be an array of integer log levels.
|
||||||
|
* This is most easily handled by using the constants defined in the
|
||||||
|
* `Psr\Log\LogLevel` class.
|
||||||
|
*
|
||||||
|
* Handlers are executed in the order defined in this array, starting with
|
||||||
|
* the handler on top and continuing down.
|
||||||
|
*
|
||||||
|
* @var array<class-string, array<string, int|list<string>|string>>
|
||||||
|
*/
|
||||||
|
public array $handlers = [
|
||||||
|
/*
|
||||||
|
* --------------------------------------------------------------------
|
||||||
|
* File Handler
|
||||||
|
* --------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
FileHandler::class => [
|
||||||
|
// The log levels that this handler will handle.
|
||||||
|
'handles' => [
|
||||||
|
'critical',
|
||||||
|
'alert',
|
||||||
|
'emergency',
|
||||||
|
'debug',
|
||||||
|
'error',
|
||||||
|
'info',
|
||||||
|
'notice',
|
||||||
|
'warning',
|
||||||
|
],
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The default filename extension for log files.
|
||||||
|
* An extension of 'php' allows for protecting the log files via basic
|
||||||
|
* scripting, when they are to be stored under a publicly accessible directory.
|
||||||
|
*
|
||||||
|
* NOTE: Leaving it blank will default to 'log'.
|
||||||
|
*/
|
||||||
|
'fileExtension' => '',
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The file system permissions to be applied on newly created log files.
|
||||||
|
*
|
||||||
|
* IMPORTANT: This MUST be an integer (no quotes) and you MUST use octal
|
||||||
|
* integer notation (i.e. 0700, 0644, etc.)
|
||||||
|
*/
|
||||||
|
'filePermissions' => 0644,
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Logging Directory Path
|
||||||
|
*
|
||||||
|
* By default, logs are written to WRITEPATH . 'logs/'
|
||||||
|
* Specify a different destination here, if desired.
|
||||||
|
*/
|
||||||
|
'path' => '',
|
||||||
|
],
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The ChromeLoggerHandler requires the use of the Chrome web browser
|
||||||
|
* and the ChromeLogger extension. Uncomment this block to use it.
|
||||||
|
*/
|
||||||
|
// 'CodeIgniter\Log\Handlers\ChromeLoggerHandler' => [
|
||||||
|
// /*
|
||||||
|
// * The log levels that this handler will handle.
|
||||||
|
// */
|
||||||
|
// 'handles' => ['critical', 'alert', 'emergency', 'debug',
|
||||||
|
// 'error', 'info', 'notice', 'warning'],
|
||||||
|
// ],
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The ErrorlogHandler writes the logs to PHP's native `error_log()` function.
|
||||||
|
* Uncomment this block to use it.
|
||||||
|
*/
|
||||||
|
// 'CodeIgniter\Log\Handlers\ErrorlogHandler' => [
|
||||||
|
// /* The log levels this handler can handle. */
|
||||||
|
// 'handles' => ['critical', 'alert', 'emergency', 'debug', 'error', 'info', 'notice', 'warning'],
|
||||||
|
//
|
||||||
|
// /*
|
||||||
|
// * The message type where the error should go. Can be 0 or 4, or use the
|
||||||
|
// * class constants: `ErrorlogHandler::TYPE_OS` (0) or `ErrorlogHandler::TYPE_SAPI` (4)
|
||||||
|
// */
|
||||||
|
// 'messageType' => 0,
|
||||||
|
// ],
|
||||||
|
];
|
||||||
|
}
|
||||||
50
app/Config/Migrations.php
Normal file
50
app/Config/Migrations.php
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Config;
|
||||||
|
|
||||||
|
use CodeIgniter\Config\BaseConfig;
|
||||||
|
|
||||||
|
class Migrations extends BaseConfig
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* Enable/Disable Migrations
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* Migrations are enabled by default.
|
||||||
|
*
|
||||||
|
* You should enable migrations whenever you intend to do a schema migration
|
||||||
|
* and disable it back when you're done.
|
||||||
|
*/
|
||||||
|
public bool $enabled = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* Migrations Table
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* This is the name of the table that will store the current migrations state.
|
||||||
|
* When migrations runs it will store in a database table which migration
|
||||||
|
* files have already been run.
|
||||||
|
*/
|
||||||
|
public string $table = 'migrations';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* Timestamp Format
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* This is the format that will be used when creating new migrations
|
||||||
|
* using the CLI command:
|
||||||
|
* > php spark make:migration
|
||||||
|
*
|
||||||
|
* NOTE: if you set an unsupported format, migration runner will not find
|
||||||
|
* your migration files.
|
||||||
|
*
|
||||||
|
* Supported formats:
|
||||||
|
* - YmdHis_
|
||||||
|
* - Y-m-d-His_
|
||||||
|
* - Y_m_d_His_
|
||||||
|
*/
|
||||||
|
public string $timestampFormat = 'Y-m-d-His_';
|
||||||
|
}
|
||||||
534
app/Config/Mimes.php
Normal file
534
app/Config/Mimes.php
Normal file
@ -0,0 +1,534 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Config;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This file contains an array of mime types. It is used by the
|
||||||
|
* Upload class to help identify allowed file types.
|
||||||
|
*
|
||||||
|
* When more than one variation for an extension exist (like jpg, jpeg, etc)
|
||||||
|
* the most common one should be first in the array to aid the guess*
|
||||||
|
* methods. The same applies when more than one mime-type exists for a
|
||||||
|
* single extension.
|
||||||
|
*
|
||||||
|
* When working with mime types, please make sure you have the ´fileinfo´
|
||||||
|
* extension enabled to reliably detect the media types.
|
||||||
|
*/
|
||||||
|
class Mimes
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Map of extensions to mime types.
|
||||||
|
*
|
||||||
|
* @var array<string, list<string>|string>
|
||||||
|
*/
|
||||||
|
public static array $mimes = [
|
||||||
|
'hqx' => [
|
||||||
|
'application/mac-binhex40',
|
||||||
|
'application/mac-binhex',
|
||||||
|
'application/x-binhex40',
|
||||||
|
'application/x-mac-binhex40',
|
||||||
|
],
|
||||||
|
'cpt' => 'application/mac-compactpro',
|
||||||
|
'csv' => [
|
||||||
|
'text/csv',
|
||||||
|
'text/x-comma-separated-values',
|
||||||
|
'text/comma-separated-values',
|
||||||
|
'application/vnd.ms-excel',
|
||||||
|
'application/x-csv',
|
||||||
|
'text/x-csv',
|
||||||
|
'application/csv',
|
||||||
|
'application/excel',
|
||||||
|
'application/vnd.msexcel',
|
||||||
|
'text/plain',
|
||||||
|
],
|
||||||
|
'bin' => [
|
||||||
|
'application/macbinary',
|
||||||
|
'application/mac-binary',
|
||||||
|
'application/octet-stream',
|
||||||
|
'application/x-binary',
|
||||||
|
'application/x-macbinary',
|
||||||
|
],
|
||||||
|
'dms' => 'application/octet-stream',
|
||||||
|
'lha' => 'application/octet-stream',
|
||||||
|
'lzh' => 'application/octet-stream',
|
||||||
|
'exe' => [
|
||||||
|
'application/octet-stream',
|
||||||
|
'application/vnd.microsoft.portable-executable',
|
||||||
|
'application/x-dosexec',
|
||||||
|
'application/x-msdownload',
|
||||||
|
],
|
||||||
|
'class' => 'application/octet-stream',
|
||||||
|
'psd' => [
|
||||||
|
'application/x-photoshop',
|
||||||
|
'image/vnd.adobe.photoshop',
|
||||||
|
],
|
||||||
|
'so' => 'application/octet-stream',
|
||||||
|
'sea' => 'application/octet-stream',
|
||||||
|
'dll' => 'application/octet-stream',
|
||||||
|
'oda' => 'application/oda',
|
||||||
|
'pdf' => [
|
||||||
|
'application/pdf',
|
||||||
|
'application/force-download',
|
||||||
|
'application/x-download',
|
||||||
|
],
|
||||||
|
'ai' => [
|
||||||
|
'application/pdf',
|
||||||
|
'application/postscript',
|
||||||
|
],
|
||||||
|
'eps' => 'application/postscript',
|
||||||
|
'ps' => 'application/postscript',
|
||||||
|
'smi' => 'application/smil',
|
||||||
|
'smil' => 'application/smil',
|
||||||
|
'mif' => 'application/vnd.mif',
|
||||||
|
'xls' => [
|
||||||
|
'application/vnd.ms-excel',
|
||||||
|
'application/msexcel',
|
||||||
|
'application/x-msexcel',
|
||||||
|
'application/x-ms-excel',
|
||||||
|
'application/x-excel',
|
||||||
|
'application/x-dos_ms_excel',
|
||||||
|
'application/xls',
|
||||||
|
'application/x-xls',
|
||||||
|
'application/excel',
|
||||||
|
'application/download',
|
||||||
|
'application/vnd.ms-office',
|
||||||
|
'application/msword',
|
||||||
|
],
|
||||||
|
'ppt' => [
|
||||||
|
'application/vnd.ms-powerpoint',
|
||||||
|
'application/powerpoint',
|
||||||
|
'application/vnd.ms-office',
|
||||||
|
'application/msword',
|
||||||
|
],
|
||||||
|
'pptx' => [
|
||||||
|
'application/vnd.openxmlformats-officedocument.presentationml.presentation',
|
||||||
|
],
|
||||||
|
'wbxml' => 'application/wbxml',
|
||||||
|
'wmlc' => 'application/wmlc',
|
||||||
|
'dcr' => 'application/x-director',
|
||||||
|
'dir' => 'application/x-director',
|
||||||
|
'dxr' => 'application/x-director',
|
||||||
|
'dvi' => 'application/x-dvi',
|
||||||
|
'gtar' => 'application/x-gtar',
|
||||||
|
'gz' => 'application/x-gzip',
|
||||||
|
'gzip' => 'application/x-gzip',
|
||||||
|
'php' => [
|
||||||
|
'application/x-php',
|
||||||
|
'application/x-httpd-php',
|
||||||
|
'application/php',
|
||||||
|
'text/php',
|
||||||
|
'text/x-php',
|
||||||
|
'application/x-httpd-php-source',
|
||||||
|
],
|
||||||
|
'php4' => 'application/x-httpd-php',
|
||||||
|
'php3' => 'application/x-httpd-php',
|
||||||
|
'phtml' => 'application/x-httpd-php',
|
||||||
|
'phps' => 'application/x-httpd-php-source',
|
||||||
|
'js' => [
|
||||||
|
'application/x-javascript',
|
||||||
|
'text/plain',
|
||||||
|
],
|
||||||
|
'swf' => 'application/x-shockwave-flash',
|
||||||
|
'sit' => 'application/x-stuffit',
|
||||||
|
'tar' => 'application/x-tar',
|
||||||
|
'tgz' => [
|
||||||
|
'application/x-tar',
|
||||||
|
'application/x-gzip-compressed',
|
||||||
|
],
|
||||||
|
'z' => 'application/x-compress',
|
||||||
|
'xhtml' => 'application/xhtml+xml',
|
||||||
|
'xht' => 'application/xhtml+xml',
|
||||||
|
'zip' => [
|
||||||
|
'application/x-zip',
|
||||||
|
'application/zip',
|
||||||
|
'application/x-zip-compressed',
|
||||||
|
'application/s-compressed',
|
||||||
|
'multipart/x-zip',
|
||||||
|
],
|
||||||
|
'rar' => [
|
||||||
|
'application/vnd.rar',
|
||||||
|
'application/x-rar',
|
||||||
|
'application/rar',
|
||||||
|
'application/x-rar-compressed',
|
||||||
|
],
|
||||||
|
'mid' => 'audio/midi',
|
||||||
|
'midi' => 'audio/midi',
|
||||||
|
'mpga' => 'audio/mpeg',
|
||||||
|
'mp2' => 'audio/mpeg',
|
||||||
|
'mp3' => [
|
||||||
|
'audio/mpeg',
|
||||||
|
'audio/mpg',
|
||||||
|
'audio/mpeg3',
|
||||||
|
'audio/mp3',
|
||||||
|
],
|
||||||
|
'aif' => [
|
||||||
|
'audio/x-aiff',
|
||||||
|
'audio/aiff',
|
||||||
|
],
|
||||||
|
'aiff' => [
|
||||||
|
'audio/x-aiff',
|
||||||
|
'audio/aiff',
|
||||||
|
],
|
||||||
|
'aifc' => 'audio/x-aiff',
|
||||||
|
'ram' => 'audio/x-pn-realaudio',
|
||||||
|
'rm' => 'audio/x-pn-realaudio',
|
||||||
|
'rpm' => 'audio/x-pn-realaudio-plugin',
|
||||||
|
'ra' => 'audio/x-realaudio',
|
||||||
|
'rv' => 'video/vnd.rn-realvideo',
|
||||||
|
'wav' => [
|
||||||
|
'audio/x-wav',
|
||||||
|
'audio/wave',
|
||||||
|
'audio/wav',
|
||||||
|
],
|
||||||
|
'bmp' => [
|
||||||
|
'image/bmp',
|
||||||
|
'image/x-bmp',
|
||||||
|
'image/x-bitmap',
|
||||||
|
'image/x-xbitmap',
|
||||||
|
'image/x-win-bitmap',
|
||||||
|
'image/x-windows-bmp',
|
||||||
|
'image/ms-bmp',
|
||||||
|
'image/x-ms-bmp',
|
||||||
|
'application/bmp',
|
||||||
|
'application/x-bmp',
|
||||||
|
'application/x-win-bitmap',
|
||||||
|
],
|
||||||
|
'gif' => 'image/gif',
|
||||||
|
'jpg' => [
|
||||||
|
'image/jpeg',
|
||||||
|
'image/pjpeg',
|
||||||
|
],
|
||||||
|
'jpeg' => [
|
||||||
|
'image/jpeg',
|
||||||
|
'image/pjpeg',
|
||||||
|
],
|
||||||
|
'jpe' => [
|
||||||
|
'image/jpeg',
|
||||||
|
'image/pjpeg',
|
||||||
|
],
|
||||||
|
'jp2' => [
|
||||||
|
'image/jp2',
|
||||||
|
'video/mj2',
|
||||||
|
'image/jpx',
|
||||||
|
'image/jpm',
|
||||||
|
],
|
||||||
|
'j2k' => [
|
||||||
|
'image/jp2',
|
||||||
|
'video/mj2',
|
||||||
|
'image/jpx',
|
||||||
|
'image/jpm',
|
||||||
|
],
|
||||||
|
'jpf' => [
|
||||||
|
'image/jp2',
|
||||||
|
'video/mj2',
|
||||||
|
'image/jpx',
|
||||||
|
'image/jpm',
|
||||||
|
],
|
||||||
|
'jpg2' => [
|
||||||
|
'image/jp2',
|
||||||
|
'video/mj2',
|
||||||
|
'image/jpx',
|
||||||
|
'image/jpm',
|
||||||
|
],
|
||||||
|
'jpx' => [
|
||||||
|
'image/jp2',
|
||||||
|
'video/mj2',
|
||||||
|
'image/jpx',
|
||||||
|
'image/jpm',
|
||||||
|
],
|
||||||
|
'jpm' => [
|
||||||
|
'image/jp2',
|
||||||
|
'video/mj2',
|
||||||
|
'image/jpx',
|
||||||
|
'image/jpm',
|
||||||
|
],
|
||||||
|
'mj2' => [
|
||||||
|
'image/jp2',
|
||||||
|
'video/mj2',
|
||||||
|
'image/jpx',
|
||||||
|
'image/jpm',
|
||||||
|
],
|
||||||
|
'mjp2' => [
|
||||||
|
'image/jp2',
|
||||||
|
'video/mj2',
|
||||||
|
'image/jpx',
|
||||||
|
'image/jpm',
|
||||||
|
],
|
||||||
|
'png' => [
|
||||||
|
'image/png',
|
||||||
|
'image/x-png',
|
||||||
|
],
|
||||||
|
'webp' => 'image/webp',
|
||||||
|
'tif' => 'image/tiff',
|
||||||
|
'tiff' => 'image/tiff',
|
||||||
|
'css' => [
|
||||||
|
'text/css',
|
||||||
|
'text/plain',
|
||||||
|
],
|
||||||
|
'html' => [
|
||||||
|
'text/html',
|
||||||
|
'text/plain',
|
||||||
|
],
|
||||||
|
'htm' => [
|
||||||
|
'text/html',
|
||||||
|
'text/plain',
|
||||||
|
],
|
||||||
|
'shtml' => [
|
||||||
|
'text/html',
|
||||||
|
'text/plain',
|
||||||
|
],
|
||||||
|
'txt' => 'text/plain',
|
||||||
|
'text' => 'text/plain',
|
||||||
|
'log' => [
|
||||||
|
'text/plain',
|
||||||
|
'text/x-log',
|
||||||
|
],
|
||||||
|
'rtx' => 'text/richtext',
|
||||||
|
'rtf' => 'text/rtf',
|
||||||
|
'xml' => [
|
||||||
|
'application/xml',
|
||||||
|
'text/xml',
|
||||||
|
'text/plain',
|
||||||
|
],
|
||||||
|
'xsl' => [
|
||||||
|
'application/xml',
|
||||||
|
'text/xsl',
|
||||||
|
'text/xml',
|
||||||
|
],
|
||||||
|
'mpeg' => 'video/mpeg',
|
||||||
|
'mpg' => 'video/mpeg',
|
||||||
|
'mpe' => 'video/mpeg',
|
||||||
|
'qt' => 'video/quicktime',
|
||||||
|
'mov' => 'video/quicktime',
|
||||||
|
'avi' => [
|
||||||
|
'video/x-msvideo',
|
||||||
|
'video/msvideo',
|
||||||
|
'video/avi',
|
||||||
|
'application/x-troff-msvideo',
|
||||||
|
],
|
||||||
|
'movie' => 'video/x-sgi-movie',
|
||||||
|
'doc' => [
|
||||||
|
'application/msword',
|
||||||
|
'application/vnd.ms-office',
|
||||||
|
],
|
||||||
|
'docx' => [
|
||||||
|
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
||||||
|
'application/zip',
|
||||||
|
'application/msword',
|
||||||
|
'application/x-zip',
|
||||||
|
],
|
||||||
|
'dot' => [
|
||||||
|
'application/msword',
|
||||||
|
'application/vnd.ms-office',
|
||||||
|
],
|
||||||
|
'dotx' => [
|
||||||
|
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
||||||
|
'application/zip',
|
||||||
|
'application/msword',
|
||||||
|
],
|
||||||
|
'xlsx' => [
|
||||||
|
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
||||||
|
'application/zip',
|
||||||
|
'application/vnd.ms-excel',
|
||||||
|
'application/msword',
|
||||||
|
'application/x-zip',
|
||||||
|
],
|
||||||
|
'xlsb' => 'application/vnd.ms-excel.sheet.binary.macroEnabled.12',
|
||||||
|
'xlsm' => 'application/vnd.ms-excel.sheet.macroEnabled.12',
|
||||||
|
'word' => [
|
||||||
|
'application/msword',
|
||||||
|
'application/octet-stream',
|
||||||
|
],
|
||||||
|
'xl' => 'application/excel',
|
||||||
|
'eml' => 'message/rfc822',
|
||||||
|
'json' => [
|
||||||
|
'application/json',
|
||||||
|
'text/json',
|
||||||
|
],
|
||||||
|
'pem' => [
|
||||||
|
'application/x-x509-user-cert',
|
||||||
|
'application/x-pem-file',
|
||||||
|
'application/octet-stream',
|
||||||
|
],
|
||||||
|
'p10' => [
|
||||||
|
'application/x-pkcs10',
|
||||||
|
'application/pkcs10',
|
||||||
|
],
|
||||||
|
'p12' => 'application/x-pkcs12',
|
||||||
|
'p7a' => 'application/x-pkcs7-signature',
|
||||||
|
'p7c' => [
|
||||||
|
'application/pkcs7-mime',
|
||||||
|
'application/x-pkcs7-mime',
|
||||||
|
],
|
||||||
|
'p7m' => [
|
||||||
|
'application/pkcs7-mime',
|
||||||
|
'application/x-pkcs7-mime',
|
||||||
|
],
|
||||||
|
'p7r' => 'application/x-pkcs7-certreqresp',
|
||||||
|
'p7s' => 'application/pkcs7-signature',
|
||||||
|
'crt' => [
|
||||||
|
'application/x-x509-ca-cert',
|
||||||
|
'application/x-x509-user-cert',
|
||||||
|
'application/pkix-cert',
|
||||||
|
],
|
||||||
|
'crl' => [
|
||||||
|
'application/pkix-crl',
|
||||||
|
'application/pkcs-crl',
|
||||||
|
],
|
||||||
|
'der' => 'application/x-x509-ca-cert',
|
||||||
|
'kdb' => 'application/octet-stream',
|
||||||
|
'pgp' => 'application/pgp',
|
||||||
|
'gpg' => 'application/gpg-keys',
|
||||||
|
'sst' => 'application/octet-stream',
|
||||||
|
'csr' => 'application/octet-stream',
|
||||||
|
'rsa' => 'application/x-pkcs7',
|
||||||
|
'cer' => [
|
||||||
|
'application/pkix-cert',
|
||||||
|
'application/x-x509-ca-cert',
|
||||||
|
],
|
||||||
|
'3g2' => 'video/3gpp2',
|
||||||
|
'3gp' => [
|
||||||
|
'video/3gp',
|
||||||
|
'video/3gpp',
|
||||||
|
],
|
||||||
|
'mp4' => 'video/mp4',
|
||||||
|
'm4a' => 'audio/x-m4a',
|
||||||
|
'f4v' => [
|
||||||
|
'video/mp4',
|
||||||
|
'video/x-f4v',
|
||||||
|
],
|
||||||
|
'flv' => 'video/x-flv',
|
||||||
|
'webm' => 'video/webm',
|
||||||
|
'aac' => 'audio/x-acc',
|
||||||
|
'm4u' => 'application/vnd.mpegurl',
|
||||||
|
'm3u' => 'text/plain',
|
||||||
|
'xspf' => 'application/xspf+xml',
|
||||||
|
'vlc' => 'application/videolan',
|
||||||
|
'wmv' => [
|
||||||
|
'video/x-ms-wmv',
|
||||||
|
'video/x-ms-asf',
|
||||||
|
],
|
||||||
|
'au' => 'audio/x-au',
|
||||||
|
'ac3' => 'audio/ac3',
|
||||||
|
'flac' => 'audio/x-flac',
|
||||||
|
'ogg' => [
|
||||||
|
'audio/ogg',
|
||||||
|
'video/ogg',
|
||||||
|
'application/ogg',
|
||||||
|
],
|
||||||
|
'kmz' => [
|
||||||
|
'application/vnd.google-earth.kmz',
|
||||||
|
'application/zip',
|
||||||
|
'application/x-zip',
|
||||||
|
],
|
||||||
|
'kml' => [
|
||||||
|
'application/vnd.google-earth.kml+xml',
|
||||||
|
'application/xml',
|
||||||
|
'text/xml',
|
||||||
|
],
|
||||||
|
'ics' => 'text/calendar',
|
||||||
|
'ical' => 'text/calendar',
|
||||||
|
'zsh' => 'text/x-scriptzsh',
|
||||||
|
'7zip' => [
|
||||||
|
'application/x-compressed',
|
||||||
|
'application/x-zip-compressed',
|
||||||
|
'application/zip',
|
||||||
|
'multipart/x-zip',
|
||||||
|
],
|
||||||
|
'cdr' => [
|
||||||
|
'application/cdr',
|
||||||
|
'application/coreldraw',
|
||||||
|
'application/x-cdr',
|
||||||
|
'application/x-coreldraw',
|
||||||
|
'image/cdr',
|
||||||
|
'image/x-cdr',
|
||||||
|
'zz-application/zz-winassoc-cdr',
|
||||||
|
],
|
||||||
|
'wma' => [
|
||||||
|
'audio/x-ms-wma',
|
||||||
|
'video/x-ms-asf',
|
||||||
|
],
|
||||||
|
'jar' => [
|
||||||
|
'application/java-archive',
|
||||||
|
'application/x-java-application',
|
||||||
|
'application/x-jar',
|
||||||
|
'application/x-compressed',
|
||||||
|
],
|
||||||
|
'svg' => [
|
||||||
|
'image/svg+xml',
|
||||||
|
'image/svg',
|
||||||
|
'application/xml',
|
||||||
|
'text/xml',
|
||||||
|
],
|
||||||
|
'vcf' => 'text/x-vcard',
|
||||||
|
'srt' => [
|
||||||
|
'text/srt',
|
||||||
|
'text/plain',
|
||||||
|
],
|
||||||
|
'vtt' => [
|
||||||
|
'text/vtt',
|
||||||
|
'text/plain',
|
||||||
|
],
|
||||||
|
'ico' => [
|
||||||
|
'image/x-icon',
|
||||||
|
'image/x-ico',
|
||||||
|
'image/vnd.microsoft.icon',
|
||||||
|
],
|
||||||
|
'stl' => [
|
||||||
|
'application/sla',
|
||||||
|
'application/vnd.ms-pki.stl',
|
||||||
|
'application/x-navistyle',
|
||||||
|
'model/stl',
|
||||||
|
'application/octet-stream',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attempts to determine the best mime type for the given file extension.
|
||||||
|
*
|
||||||
|
* @return string|null The mime type found, or none if unable to determine.
|
||||||
|
*/
|
||||||
|
public static function guessTypeFromExtension(string $extension)
|
||||||
|
{
|
||||||
|
$extension = trim(strtolower($extension), '. ');
|
||||||
|
|
||||||
|
if (! array_key_exists($extension, static::$mimes)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return is_array(static::$mimes[$extension]) ? static::$mimes[$extension][0] : static::$mimes[$extension];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attempts to determine the best file extension for a given mime type.
|
||||||
|
*
|
||||||
|
* @param string|null $proposedExtension - default extension (in case there is more than one with the same mime type)
|
||||||
|
*
|
||||||
|
* @return string|null The extension determined, or null if unable to match.
|
||||||
|
*/
|
||||||
|
public static function guessExtensionFromType(string $type, ?string $proposedExtension = null)
|
||||||
|
{
|
||||||
|
$type = trim(strtolower($type), '. ');
|
||||||
|
|
||||||
|
$proposedExtension = trim(strtolower($proposedExtension ?? ''));
|
||||||
|
|
||||||
|
if (
|
||||||
|
$proposedExtension !== ''
|
||||||
|
&& array_key_exists($proposedExtension, static::$mimes)
|
||||||
|
&& in_array($type, (array) static::$mimes[$proposedExtension], true)
|
||||||
|
) {
|
||||||
|
// The detected mime type matches with the proposed extension.
|
||||||
|
return $proposedExtension;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reverse check the mime type list if no extension was proposed.
|
||||||
|
// This search is order sensitive!
|
||||||
|
foreach (static::$mimes as $ext => $types) {
|
||||||
|
if (in_array($type, (array) $types, true)) {
|
||||||
|
return $ext;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
82
app/Config/Modules.php
Normal file
82
app/Config/Modules.php
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Config;
|
||||||
|
|
||||||
|
use CodeIgniter\Modules\Modules as BaseModules;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Modules Configuration.
|
||||||
|
*
|
||||||
|
* NOTE: This class is required prior to Autoloader instantiation,
|
||||||
|
* and does not extend BaseConfig.
|
||||||
|
*/
|
||||||
|
class Modules extends BaseModules
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* Enable Auto-Discovery?
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* If true, then auto-discovery will happen across all elements listed in
|
||||||
|
* $aliases below. If false, no auto-discovery will happen at all,
|
||||||
|
* giving a slight performance boost.
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public $enabled = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* Enable Auto-Discovery Within Composer Packages?
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* If true, then auto-discovery will happen across all namespaces loaded
|
||||||
|
* by Composer, as well as the namespaces configured locally.
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public $discoverInComposer = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Composer package list for Auto-Discovery
|
||||||
|
* This setting is optional.
|
||||||
|
*
|
||||||
|
* E.g.:
|
||||||
|
* [
|
||||||
|
* 'only' => [
|
||||||
|
* // List up all packages to auto-discover
|
||||||
|
* 'codeigniter4/shield',
|
||||||
|
* ],
|
||||||
|
* ]
|
||||||
|
* or
|
||||||
|
* [
|
||||||
|
* 'exclude' => [
|
||||||
|
* // List up packages to exclude.
|
||||||
|
* 'pestphp/pest',
|
||||||
|
* ],
|
||||||
|
* ]
|
||||||
|
*
|
||||||
|
* @var array{only?: list<string>, exclude?: list<string>}
|
||||||
|
*/
|
||||||
|
public $composerPackages = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* Auto-Discovery Rules
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* Aliases list of all discovery classes that will be active and used during
|
||||||
|
* the current application request.
|
||||||
|
*
|
||||||
|
* If it is not listed, only the base application elements will be used.
|
||||||
|
*
|
||||||
|
* @var list<string>
|
||||||
|
*/
|
||||||
|
public $aliases = [
|
||||||
|
'events',
|
||||||
|
'filters',
|
||||||
|
'registrars',
|
||||||
|
'routes',
|
||||||
|
'services',
|
||||||
|
];
|
||||||
|
}
|
||||||
30
app/Config/Optimize.php
Normal file
30
app/Config/Optimize.php
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Config;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Optimization Configuration.
|
||||||
|
*
|
||||||
|
* NOTE: This class does not extend BaseConfig for performance reasons.
|
||||||
|
* So you cannot replace the property values with Environment Variables.
|
||||||
|
*/
|
||||||
|
class Optimize
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* Config Caching
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* @see https://codeigniter.com/user_guide/concepts/factories.html#config-caching
|
||||||
|
*/
|
||||||
|
public bool $configCacheEnabled = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* Config Caching
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* @see https://codeigniter.com/user_guide/concepts/autoloader.html#file-locator-caching
|
||||||
|
*/
|
||||||
|
public bool $locatorCacheEnabled = false;
|
||||||
|
}
|
||||||
37
app/Config/Pager.php
Normal file
37
app/Config/Pager.php
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Config;
|
||||||
|
|
||||||
|
use CodeIgniter\Config\BaseConfig;
|
||||||
|
|
||||||
|
class Pager extends BaseConfig
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* Templates
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* Pagination links are rendered out using views to configure their
|
||||||
|
* appearance. This array contains aliases and the view names to
|
||||||
|
* use when rendering the links.
|
||||||
|
*
|
||||||
|
* Within each view, the Pager object will be available as $pager,
|
||||||
|
* and the desired group as $pagerGroup;
|
||||||
|
*
|
||||||
|
* @var array<string, string>
|
||||||
|
*/
|
||||||
|
public array $templates = [
|
||||||
|
'default_full' => 'CodeIgniter\Pager\Views\default_full',
|
||||||
|
'default_simple' => 'CodeIgniter\Pager\Views\default_simple',
|
||||||
|
'default_head' => 'CodeIgniter\Pager\Views\default_head',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* Items Per Page
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* The default number of results shown in a single page.
|
||||||
|
*/
|
||||||
|
public int $perPage = 20;
|
||||||
|
}
|
||||||
75
app/Config/Paths.php
Normal file
75
app/Config/Paths.php
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Config;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Paths
|
||||||
|
*
|
||||||
|
* Holds the paths that are used by the system to
|
||||||
|
* locate the main directories, app, system, etc.
|
||||||
|
*
|
||||||
|
* Modifying these allows you to restructure your application,
|
||||||
|
* share a system folder between multiple applications, and more.
|
||||||
|
*
|
||||||
|
* All paths are relative to the project's root folder.
|
||||||
|
*/
|
||||||
|
class Paths
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* ---------------------------------------------------------------
|
||||||
|
* SYSTEM FOLDER NAME
|
||||||
|
* ---------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* This must contain the name of your "system" folder. Include
|
||||||
|
* the path if the folder is not in the same directory as this file.
|
||||||
|
*/
|
||||||
|
public string $systemDirectory = __DIR__ . '/../../vendor/codeigniter4/framework/system';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ---------------------------------------------------------------
|
||||||
|
* APPLICATION FOLDER NAME
|
||||||
|
* ---------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* If you want this front controller to use a different "app"
|
||||||
|
* folder than the default one you can set its name here. The folder
|
||||||
|
* can also be renamed or relocated anywhere on your server. If
|
||||||
|
* you do, use a full server path.
|
||||||
|
*
|
||||||
|
* @see http://codeigniter.com/user_guide/general/managing_apps.html
|
||||||
|
*/
|
||||||
|
public string $appDirectory = __DIR__ . '/..';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ---------------------------------------------------------------
|
||||||
|
* WRITABLE DIRECTORY NAME
|
||||||
|
* ---------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* This variable must contain the name of your "writable" directory.
|
||||||
|
* The writable directory allows you to group all directories that
|
||||||
|
* need write permission to a single place that can be tucked away
|
||||||
|
* for maximum security, keeping it out of the app and/or
|
||||||
|
* system directories.
|
||||||
|
*/
|
||||||
|
public string $writableDirectory = __DIR__ . '/../../writable';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ---------------------------------------------------------------
|
||||||
|
* TESTS DIRECTORY NAME
|
||||||
|
* ---------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* This variable must contain the name of your "tests" directory.
|
||||||
|
*/
|
||||||
|
public string $testsDirectory = __DIR__ . '/../../tests';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ---------------------------------------------------------------
|
||||||
|
* VIEW DIRECTORY NAME
|
||||||
|
* ---------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* This variable must contain the name of the directory that
|
||||||
|
* contains the view files used by your application. By
|
||||||
|
* default this is in `app/Views`. This value
|
||||||
|
* is used when no value is provided to `Services::renderer()`.
|
||||||
|
*/
|
||||||
|
public string $viewDirectory = __DIR__ . '/../Views';
|
||||||
|
}
|
||||||
28
app/Config/Publisher.php
Normal file
28
app/Config/Publisher.php
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Config;
|
||||||
|
|
||||||
|
use CodeIgniter\Config\Publisher as BasePublisher;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Publisher Configuration
|
||||||
|
*
|
||||||
|
* Defines basic security restrictions for the Publisher class
|
||||||
|
* to prevent abuse by injecting malicious files into a project.
|
||||||
|
*/
|
||||||
|
class Publisher extends BasePublisher
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* A list of allowed destinations with a (pseudo-)regex
|
||||||
|
* of allowed files for each destination.
|
||||||
|
* Attempts to publish to directories not in this list will
|
||||||
|
* result in a PublisherException. Files that do no fit the
|
||||||
|
* pattern will cause copy/merge to fail.
|
||||||
|
*
|
||||||
|
* @var array<string, string>
|
||||||
|
*/
|
||||||
|
public $restrictions = [
|
||||||
|
ROOTPATH => '*',
|
||||||
|
FCPATH => '#\.(s?css|js|map|html?|xml|json|webmanifest|ttf|eot|woff2?|gif|jpe?g|tiff?|png|webp|bmp|ico|svg)$#i',
|
||||||
|
];
|
||||||
|
}
|
||||||
46
app/Config/Routes.php
Normal file
46
app/Config/Routes.php
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use CodeIgniter\Router\RouteCollection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var RouteCollection $routes
|
||||||
|
*/
|
||||||
|
$routes->get('/', 'Home::index');
|
||||||
|
|
||||||
|
/*============================ User Login ========================================*/
|
||||||
|
$routes->group('admin', [], function ($routes) {
|
||||||
|
$routes->post('login', 'Backend\LoginController::index');
|
||||||
|
$routes->post('requestToken', 'Backend\LoginController::requestToken');
|
||||||
|
});
|
||||||
|
|
||||||
|
$routes->group('api', [], function ($routes) {
|
||||||
|
$routes->post('send-otp', 'Frontend\AuthController::sendOtp');
|
||||||
|
$routes->post('verify-api', 'Frontend\AuthController::verifyOtp');
|
||||||
|
$routes->post('payment/fiuu/notification', 'Frontend\PaymentController::fiuuPaymentNotification');
|
||||||
|
$routes->post('payment/fiuu/return', 'Frontend\PaymentController::fiuuPaymentReturn');
|
||||||
|
$routes->post('lalamove/webhook', 'Frontend\LalamoveController::webhook');
|
||||||
|
$routes->post('grab/webhook', 'Frontend\GrabController::webhook');
|
||||||
|
$routes->post('topup/fiuu/notification', 'Frontend\TopupController::fiuuTopupNotification');
|
||||||
|
});
|
||||||
|
|
||||||
|
$routes->group('api', ['namespace' => 'App\Controllers'], function($routes) {
|
||||||
|
$routes->resource('productbrand', ['controller' => 'ProductBrandController']);
|
||||||
|
$routes->resource('productcategory', ['controller' => 'ProductCategoryController']);
|
||||||
|
$routes->resource('productdescription', ['controller' => 'ProductDescriptionController']);
|
||||||
|
$routes->resource('supplierdetails', ['controller' => 'SupplierDetailsController']);
|
||||||
|
$routes->resource('productimei', ['controller' => 'ProductImeiController']);
|
||||||
|
$routes->resource('product', ['controller' => 'ProductController']);
|
||||||
|
$routes->resource('stock', ['controller' => 'StockController']);
|
||||||
|
$routes->resource('invoiceitem', ['controller' => 'InvoiceItemController']);
|
||||||
|
$routes->resource('platform', ['controller' => 'PlatformController']);
|
||||||
|
$routes->resource('customerdetails', ['controller' => 'CustomerDetailsController']);
|
||||||
|
$routes->resource('invoicetype', ['controller' => 'InvoiceTypeController']);
|
||||||
|
$routes->resource('paymentmethod', ['controller' => 'PaymentMethodController']);
|
||||||
|
$routes->resource('invoice', ['controller' => 'InvoiceController']);
|
||||||
|
$routes->resource('branchcategory', ['controller' => 'BranchCategoryController']);
|
||||||
|
$routes->resource('letterhead', ['controller' => 'LetterheadController']);
|
||||||
|
$routes->resource('branchdetails', ['controller' => 'BranchDetailsController']);
|
||||||
|
$routes->resource('position', ['controller' => 'PositionController']);
|
||||||
|
$routes->resource('staffdetails', ['controller' => 'StaffDetailsController']);
|
||||||
|
|
||||||
|
});
|
||||||
140
app/Config/Routing.php
Normal file
140
app/Config/Routing.php
Normal file
@ -0,0 +1,140 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This file is part of CodeIgniter 4 framework.
|
||||||
|
*
|
||||||
|
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view
|
||||||
|
* the LICENSE file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Config;
|
||||||
|
|
||||||
|
use CodeIgniter\Config\Routing as BaseRouting;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Routing configuration
|
||||||
|
*/
|
||||||
|
class Routing extends BaseRouting
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* For Defined Routes.
|
||||||
|
* An array of files that contain route definitions.
|
||||||
|
* Route files are read in order, with the first match
|
||||||
|
* found taking precedence.
|
||||||
|
*
|
||||||
|
* Default: APPPATH . 'Config/Routes.php'
|
||||||
|
*
|
||||||
|
* @var list<string>
|
||||||
|
*/
|
||||||
|
public array $routeFiles = [
|
||||||
|
APPPATH . 'Config/Routes.php',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For Defined Routes and Auto Routing.
|
||||||
|
* The default namespace to use for Controllers when no other
|
||||||
|
* namespace has been specified.
|
||||||
|
*
|
||||||
|
* Default: 'App\Controllers'
|
||||||
|
*/
|
||||||
|
public string $defaultNamespace = 'App\Controllers';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For Auto Routing.
|
||||||
|
* The default controller to use when no other controller has been
|
||||||
|
* specified.
|
||||||
|
*
|
||||||
|
* Default: 'Home'
|
||||||
|
*/
|
||||||
|
public string $defaultController = 'Home';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For Defined Routes and Auto Routing.
|
||||||
|
* The default method to call on the controller when no other
|
||||||
|
* method has been set in the route.
|
||||||
|
*
|
||||||
|
* Default: 'index'
|
||||||
|
*/
|
||||||
|
public string $defaultMethod = 'index';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For Auto Routing.
|
||||||
|
* Whether to translate dashes in URIs for controller/method to underscores.
|
||||||
|
* Primarily useful when using the auto-routing.
|
||||||
|
*
|
||||||
|
* Default: false
|
||||||
|
*/
|
||||||
|
public bool $translateURIDashes = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the class/method that should be called if routing doesn't
|
||||||
|
* find a match. It can be the controller/method name like: Users::index
|
||||||
|
*
|
||||||
|
* This setting is passed to the Router class and handled there.
|
||||||
|
*
|
||||||
|
* If you want to use a closure, you will have to set it in the
|
||||||
|
* routes file by calling:
|
||||||
|
*
|
||||||
|
* $routes->set404Override(function() {
|
||||||
|
* // Do something here
|
||||||
|
* });
|
||||||
|
*
|
||||||
|
* Example:
|
||||||
|
* public $override404 = 'App\Errors::show404';
|
||||||
|
*/
|
||||||
|
public ?string $override404 = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If TRUE, the system will attempt to match the URI against
|
||||||
|
* Controllers by matching each segment against folders/files
|
||||||
|
* in APPPATH/Controllers, when a match wasn't found against
|
||||||
|
* defined routes.
|
||||||
|
*
|
||||||
|
* If FALSE, will stop searching and do NO automatic routing.
|
||||||
|
*/
|
||||||
|
public bool $autoRoute = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For Defined Routes.
|
||||||
|
* If TRUE, will enable the use of the 'prioritize' option
|
||||||
|
* when defining routes.
|
||||||
|
*
|
||||||
|
* Default: false
|
||||||
|
*/
|
||||||
|
public bool $prioritize = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For Defined Routes.
|
||||||
|
* If TRUE, matched multiple URI segments will be passed as one parameter.
|
||||||
|
*
|
||||||
|
* Default: false
|
||||||
|
*/
|
||||||
|
public bool $multipleSegmentsOneParam = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For Auto Routing (Improved).
|
||||||
|
* Map of URI segments and namespaces.
|
||||||
|
*
|
||||||
|
* The key is the first URI segment. The value is the controller namespace.
|
||||||
|
* E.g.,
|
||||||
|
* [
|
||||||
|
* 'blog' => 'Acme\Blog\Controllers',
|
||||||
|
* ]
|
||||||
|
*
|
||||||
|
* @var array<string, string>
|
||||||
|
*/
|
||||||
|
public array $moduleRoutes = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For Auto Routing (Improved).
|
||||||
|
* Whether to translate dashes in URIs for controller/method to CamelCase.
|
||||||
|
* E.g., blog-controller -> BlogController
|
||||||
|
*
|
||||||
|
* If you enable this, $translateURIDashes is ignored.
|
||||||
|
*
|
||||||
|
* Default: false
|
||||||
|
*/
|
||||||
|
public bool $translateUriToCamelCase = true;
|
||||||
|
}
|
||||||
86
app/Config/Security.php
Normal file
86
app/Config/Security.php
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Config;
|
||||||
|
|
||||||
|
use CodeIgniter\Config\BaseConfig;
|
||||||
|
|
||||||
|
class Security extends BaseConfig
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* CSRF Protection Method
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* Protection Method for Cross Site Request Forgery protection.
|
||||||
|
*
|
||||||
|
* @var string 'cookie' or 'session'
|
||||||
|
*/
|
||||||
|
public string $csrfProtection = 'cookie';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* CSRF Token Randomization
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* Randomize the CSRF Token for added security.
|
||||||
|
*/
|
||||||
|
public bool $tokenRandomize = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* CSRF Token Name
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* Token name for Cross Site Request Forgery protection.
|
||||||
|
*/
|
||||||
|
public string $tokenName = 'csrf_test_name';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* CSRF Header Name
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* Header name for Cross Site Request Forgery protection.
|
||||||
|
*/
|
||||||
|
public string $headerName = 'X-CSRF-TOKEN';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* CSRF Cookie Name
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* Cookie name for Cross Site Request Forgery protection.
|
||||||
|
*/
|
||||||
|
public string $cookieName = 'csrf_cookie_name';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* CSRF Expires
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* Expiration time for Cross Site Request Forgery protection cookie.
|
||||||
|
*
|
||||||
|
* Defaults to two hours (in seconds).
|
||||||
|
*/
|
||||||
|
public int $expires = 7200;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* CSRF Regenerate
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* Regenerate CSRF Token on every submission.
|
||||||
|
*/
|
||||||
|
public bool $regenerate = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* CSRF Redirect
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* Redirect to previous page with error on failure.
|
||||||
|
*
|
||||||
|
* @see https://codeigniter4.github.io/userguide/libraries/security.html#redirection-on-failure
|
||||||
|
*/
|
||||||
|
public bool $redirect = (ENVIRONMENT === 'production');
|
||||||
|
}
|
||||||
71
app/Config/Services.php
Normal file
71
app/Config/Services.php
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Config;
|
||||||
|
|
||||||
|
use CodeIgniter\Config\BaseService;
|
||||||
|
use App\Services\CartService;
|
||||||
|
use App\Services\PromoService;
|
||||||
|
use App\Services\CalculateService;
|
||||||
|
use App\Services\VoucherService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Services Configuration file.
|
||||||
|
*
|
||||||
|
* Services are simply other classes/libraries that the system uses
|
||||||
|
* to do its job. This is used by CodeIgniter to allow the core of the
|
||||||
|
* framework to be swapped out easily without affecting the usage within
|
||||||
|
* the rest of your application.
|
||||||
|
*
|
||||||
|
* This file holds any application-specific services, or service overrides
|
||||||
|
* that you might need. An example has been included with the general
|
||||||
|
* method format you should use for your service methods. For more examples,
|
||||||
|
* see the core Services file at system/Config/Services.php.
|
||||||
|
*/
|
||||||
|
class Services extends BaseService
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* public static function example($getShared = true)
|
||||||
|
* {
|
||||||
|
* if ($getShared) {
|
||||||
|
* return static::getSharedInstance('example');
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* return new \CodeIgniter\Example();
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
public static function promoService($getShared = true)
|
||||||
|
{
|
||||||
|
if ($getShared) {
|
||||||
|
return static::getSharedInstance('promoService');
|
||||||
|
}
|
||||||
|
return new PromoService();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function cartService($getShared = true)
|
||||||
|
{
|
||||||
|
if ($getShared) {
|
||||||
|
return static::getSharedInstance('cartService');
|
||||||
|
}
|
||||||
|
return new CartService();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function calculateService(bool $getShared = true)
|
||||||
|
{
|
||||||
|
if ($getShared) {
|
||||||
|
return static::getSharedInstance('calculateService');
|
||||||
|
}
|
||||||
|
|
||||||
|
return new CalculateService(static::promoService());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function voucherService(bool $getShared = true)
|
||||||
|
{
|
||||||
|
if ($getShared) {
|
||||||
|
return static::getSharedInstance('voucherService');
|
||||||
|
}
|
||||||
|
|
||||||
|
return new voucherService();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
127
app/Config/Session.php
Normal file
127
app/Config/Session.php
Normal file
@ -0,0 +1,127 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Config;
|
||||||
|
|
||||||
|
use CodeIgniter\Config\BaseConfig;
|
||||||
|
use CodeIgniter\Session\Handlers\BaseHandler;
|
||||||
|
use CodeIgniter\Session\Handlers\FileHandler;
|
||||||
|
|
||||||
|
class Session extends BaseConfig
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* Session Driver
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* The session storage driver to use:
|
||||||
|
* - `CodeIgniter\Session\Handlers\FileHandler`
|
||||||
|
* - `CodeIgniter\Session\Handlers\DatabaseHandler`
|
||||||
|
* - `CodeIgniter\Session\Handlers\MemcachedHandler`
|
||||||
|
* - `CodeIgniter\Session\Handlers\RedisHandler`
|
||||||
|
*
|
||||||
|
* @var class-string<BaseHandler>
|
||||||
|
*/
|
||||||
|
public string $driver = FileHandler::class;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* Session Cookie Name
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* The session cookie name, must contain only [0-9a-z_-] characters
|
||||||
|
*/
|
||||||
|
public string $cookieName = 'ci_session';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* Session Expiration
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* The number of SECONDS you want the session to last.
|
||||||
|
* Setting to 0 (zero) means expire when the browser is closed.
|
||||||
|
*/
|
||||||
|
public int $expiration = 7200;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* Session Save Path
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* The location to save sessions to and is driver dependent.
|
||||||
|
*
|
||||||
|
* For the 'files' driver, it's a path to a writable directory.
|
||||||
|
* WARNING: Only absolute paths are supported!
|
||||||
|
*
|
||||||
|
* For the 'database' driver, it's a table name.
|
||||||
|
* Please read up the manual for the format with other session drivers.
|
||||||
|
*
|
||||||
|
* IMPORTANT: You are REQUIRED to set a valid save path!
|
||||||
|
*/
|
||||||
|
public string $savePath = WRITEPATH . 'session';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* Session Match IP
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* Whether to match the user's IP address when reading the session data.
|
||||||
|
*
|
||||||
|
* WARNING: If you're using the database driver, don't forget to update
|
||||||
|
* your session table's PRIMARY KEY when changing this setting.
|
||||||
|
*/
|
||||||
|
public bool $matchIP = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* Session Time to Update
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* How many seconds between CI regenerating the session ID.
|
||||||
|
*/
|
||||||
|
public int $timeToUpdate = 300;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* Session Regenerate Destroy
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* Whether to destroy session data associated with the old session ID
|
||||||
|
* when auto-regenerating the session ID. When set to FALSE, the data
|
||||||
|
* will be later deleted by the garbage collector.
|
||||||
|
*/
|
||||||
|
public bool $regenerateDestroy = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* Session Database Group
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* DB Group for the database session.
|
||||||
|
*/
|
||||||
|
public ?string $DBGroup = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* Lock Retry Interval (microseconds)
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* This is used for RedisHandler.
|
||||||
|
*
|
||||||
|
* Time (microseconds) to wait if lock cannot be acquired.
|
||||||
|
* The default is 100,000 microseconds (= 0.1 seconds).
|
||||||
|
*/
|
||||||
|
public int $lockRetryInterval = 100_000;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* Lock Max Retries
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* This is used for RedisHandler.
|
||||||
|
*
|
||||||
|
* Maximum number of lock acquisition attempts.
|
||||||
|
* The default is 300 times. That is lock timeout is about 30 (0.1 * 300)
|
||||||
|
* seconds.
|
||||||
|
*/
|
||||||
|
public int $lockMaxRetries = 300;
|
||||||
|
}
|
||||||
122
app/Config/Toolbar.php
Normal file
122
app/Config/Toolbar.php
Normal file
@ -0,0 +1,122 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Config;
|
||||||
|
|
||||||
|
use CodeIgniter\Config\BaseConfig;
|
||||||
|
use CodeIgniter\Debug\Toolbar\Collectors\Database;
|
||||||
|
use CodeIgniter\Debug\Toolbar\Collectors\Events;
|
||||||
|
use CodeIgniter\Debug\Toolbar\Collectors\Files;
|
||||||
|
use CodeIgniter\Debug\Toolbar\Collectors\Logs;
|
||||||
|
use CodeIgniter\Debug\Toolbar\Collectors\Routes;
|
||||||
|
use CodeIgniter\Debug\Toolbar\Collectors\Timers;
|
||||||
|
use CodeIgniter\Debug\Toolbar\Collectors\Views;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* Debug Toolbar
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* The Debug Toolbar provides a way to see information about the performance
|
||||||
|
* and state of your application during that page display. By default it will
|
||||||
|
* NOT be displayed under production environments, and will only display if
|
||||||
|
* `CI_DEBUG` is true, since if it's not, there's not much to display anyway.
|
||||||
|
*/
|
||||||
|
class Toolbar extends BaseConfig
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* Toolbar Collectors
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* List of toolbar collectors that will be called when Debug Toolbar
|
||||||
|
* fires up and collects data from.
|
||||||
|
*
|
||||||
|
* @var list<class-string>
|
||||||
|
*/
|
||||||
|
public array $collectors = [
|
||||||
|
Timers::class,
|
||||||
|
Database::class,
|
||||||
|
Logs::class,
|
||||||
|
Views::class,
|
||||||
|
// \CodeIgniter\Debug\Toolbar\Collectors\Cache::class,
|
||||||
|
Files::class,
|
||||||
|
Routes::class,
|
||||||
|
Events::class,
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* Collect Var Data
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* If set to false var data from the views will not be collected. Useful to
|
||||||
|
* avoid high memory usage when there are lots of data passed to the view.
|
||||||
|
*/
|
||||||
|
public bool $collectVarData = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* Max History
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* `$maxHistory` sets a limit on the number of past requests that are stored,
|
||||||
|
* helping to conserve file space used to store them. You can set it to
|
||||||
|
* 0 (zero) to not have any history stored, or -1 for unlimited history.
|
||||||
|
*/
|
||||||
|
public int $maxHistory = 20;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* Toolbar Views Path
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* The full path to the the views that are used by the toolbar.
|
||||||
|
* This MUST have a trailing slash.
|
||||||
|
*/
|
||||||
|
public string $viewsPath = SYSTEMPATH . 'Debug/Toolbar/Views/';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* Max Queries
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* If the Database Collector is enabled, it will log every query that the
|
||||||
|
* the system generates so they can be displayed on the toolbar's timeline
|
||||||
|
* and in the query log. This can lead to memory issues in some instances
|
||||||
|
* with hundreds of queries.
|
||||||
|
*
|
||||||
|
* `$maxQueries` defines the maximum amount of queries that will be stored.
|
||||||
|
*/
|
||||||
|
public int $maxQueries = 100;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* Watched Directories
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* Contains an array of directories that will be watched for changes and
|
||||||
|
* used to determine if the hot-reload feature should reload the page or not.
|
||||||
|
* We restrict the values to keep performance as high as possible.
|
||||||
|
*
|
||||||
|
* NOTE: The ROOTPATH will be prepended to all values.
|
||||||
|
*
|
||||||
|
* @var list<string>
|
||||||
|
*/
|
||||||
|
public array $watchedDirectories = [
|
||||||
|
'app',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* Watched File Extensions
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* Contains an array of file extensions that will be watched for changes and
|
||||||
|
* used to determine if the hot-reload feature should reload the page or not.
|
||||||
|
*
|
||||||
|
* @var list<string>
|
||||||
|
*/
|
||||||
|
public array $watchedExtensions = [
|
||||||
|
'php', 'css', 'js', 'html', 'svg', 'json', 'env',
|
||||||
|
];
|
||||||
|
}
|
||||||
252
app/Config/UserAgents.php
Normal file
252
app/Config/UserAgents.php
Normal file
@ -0,0 +1,252 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Config;
|
||||||
|
|
||||||
|
use CodeIgniter\Config\BaseConfig;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* -------------------------------------------------------------------
|
||||||
|
* User Agents
|
||||||
|
* -------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* This file contains four arrays of user agent data. It is used by the
|
||||||
|
* User Agent Class to help identify browser, platform, robot, and
|
||||||
|
* mobile device data. The array keys are used to identify the device
|
||||||
|
* and the array values are used to set the actual name of the item.
|
||||||
|
*/
|
||||||
|
class UserAgents extends BaseConfig
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* -------------------------------------------------------------------
|
||||||
|
* OS Platforms
|
||||||
|
* -------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* @var array<string, string>
|
||||||
|
*/
|
||||||
|
public array $platforms = [
|
||||||
|
'windows nt 10.0' => 'Windows 10',
|
||||||
|
'windows nt 6.3' => 'Windows 8.1',
|
||||||
|
'windows nt 6.2' => 'Windows 8',
|
||||||
|
'windows nt 6.1' => 'Windows 7',
|
||||||
|
'windows nt 6.0' => 'Windows Vista',
|
||||||
|
'windows nt 5.2' => 'Windows 2003',
|
||||||
|
'windows nt 5.1' => 'Windows XP',
|
||||||
|
'windows nt 5.0' => 'Windows 2000',
|
||||||
|
'windows nt 4.0' => 'Windows NT 4.0',
|
||||||
|
'winnt4.0' => 'Windows NT 4.0',
|
||||||
|
'winnt 4.0' => 'Windows NT',
|
||||||
|
'winnt' => 'Windows NT',
|
||||||
|
'windows 98' => 'Windows 98',
|
||||||
|
'win98' => 'Windows 98',
|
||||||
|
'windows 95' => 'Windows 95',
|
||||||
|
'win95' => 'Windows 95',
|
||||||
|
'windows phone' => 'Windows Phone',
|
||||||
|
'windows' => 'Unknown Windows OS',
|
||||||
|
'android' => 'Android',
|
||||||
|
'blackberry' => 'BlackBerry',
|
||||||
|
'iphone' => 'iOS',
|
||||||
|
'ipad' => 'iOS',
|
||||||
|
'ipod' => 'iOS',
|
||||||
|
'os x' => 'Mac OS X',
|
||||||
|
'ppc mac' => 'Power PC Mac',
|
||||||
|
'freebsd' => 'FreeBSD',
|
||||||
|
'ppc' => 'Macintosh',
|
||||||
|
'linux' => 'Linux',
|
||||||
|
'debian' => 'Debian',
|
||||||
|
'sunos' => 'Sun Solaris',
|
||||||
|
'beos' => 'BeOS',
|
||||||
|
'apachebench' => 'ApacheBench',
|
||||||
|
'aix' => 'AIX',
|
||||||
|
'irix' => 'Irix',
|
||||||
|
'osf' => 'DEC OSF',
|
||||||
|
'hp-ux' => 'HP-UX',
|
||||||
|
'netbsd' => 'NetBSD',
|
||||||
|
'bsdi' => 'BSDi',
|
||||||
|
'openbsd' => 'OpenBSD',
|
||||||
|
'gnu' => 'GNU/Linux',
|
||||||
|
'unix' => 'Unknown Unix OS',
|
||||||
|
'symbian' => 'Symbian OS',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* -------------------------------------------------------------------
|
||||||
|
* Browsers
|
||||||
|
* -------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* The order of this array should NOT be changed. Many browsers return
|
||||||
|
* multiple browser types so we want to identify the subtype first.
|
||||||
|
*
|
||||||
|
* @var array<string, string>
|
||||||
|
*/
|
||||||
|
public array $browsers = [
|
||||||
|
'OPR' => 'Opera',
|
||||||
|
'Flock' => 'Flock',
|
||||||
|
'Edge' => 'Spartan',
|
||||||
|
'Edg' => 'Edge',
|
||||||
|
'Chrome' => 'Chrome',
|
||||||
|
// Opera 10+ always reports Opera/9.80 and appends Version/<real version> to the user agent string
|
||||||
|
'Opera.*?Version' => 'Opera',
|
||||||
|
'Opera' => 'Opera',
|
||||||
|
'MSIE' => 'Internet Explorer',
|
||||||
|
'Internet Explorer' => 'Internet Explorer',
|
||||||
|
'Trident.* rv' => 'Internet Explorer',
|
||||||
|
'Shiira' => 'Shiira',
|
||||||
|
'Firefox' => 'Firefox',
|
||||||
|
'Chimera' => 'Chimera',
|
||||||
|
'Phoenix' => 'Phoenix',
|
||||||
|
'Firebird' => 'Firebird',
|
||||||
|
'Camino' => 'Camino',
|
||||||
|
'Netscape' => 'Netscape',
|
||||||
|
'OmniWeb' => 'OmniWeb',
|
||||||
|
'Safari' => 'Safari',
|
||||||
|
'Mozilla' => 'Mozilla',
|
||||||
|
'Konqueror' => 'Konqueror',
|
||||||
|
'icab' => 'iCab',
|
||||||
|
'Lynx' => 'Lynx',
|
||||||
|
'Links' => 'Links',
|
||||||
|
'hotjava' => 'HotJava',
|
||||||
|
'amaya' => 'Amaya',
|
||||||
|
'IBrowse' => 'IBrowse',
|
||||||
|
'Maxthon' => 'Maxthon',
|
||||||
|
'Ubuntu' => 'Ubuntu Web Browser',
|
||||||
|
'Vivaldi' => 'Vivaldi',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* -------------------------------------------------------------------
|
||||||
|
* Mobiles
|
||||||
|
* -------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* @var array<string, string>
|
||||||
|
*/
|
||||||
|
public array $mobiles = [
|
||||||
|
// legacy array, old values commented out
|
||||||
|
'mobileexplorer' => 'Mobile Explorer',
|
||||||
|
// 'openwave' => 'Open Wave',
|
||||||
|
// 'opera mini' => 'Opera Mini',
|
||||||
|
// 'operamini' => 'Opera Mini',
|
||||||
|
// 'elaine' => 'Palm',
|
||||||
|
'palmsource' => 'Palm',
|
||||||
|
// 'digital paths' => 'Palm',
|
||||||
|
// 'avantgo' => 'Avantgo',
|
||||||
|
// 'xiino' => 'Xiino',
|
||||||
|
'palmscape' => 'Palmscape',
|
||||||
|
// 'nokia' => 'Nokia',
|
||||||
|
// 'ericsson' => 'Ericsson',
|
||||||
|
// 'blackberry' => 'BlackBerry',
|
||||||
|
// 'motorola' => 'Motorola'
|
||||||
|
|
||||||
|
// Phones and Manufacturers
|
||||||
|
'motorola' => 'Motorola',
|
||||||
|
'nokia' => 'Nokia',
|
||||||
|
'palm' => 'Palm',
|
||||||
|
'iphone' => 'Apple iPhone',
|
||||||
|
'ipad' => 'iPad',
|
||||||
|
'ipod' => 'Apple iPod Touch',
|
||||||
|
'sony' => 'Sony Ericsson',
|
||||||
|
'ericsson' => 'Sony Ericsson',
|
||||||
|
'blackberry' => 'BlackBerry',
|
||||||
|
'cocoon' => 'O2 Cocoon',
|
||||||
|
'blazer' => 'Treo',
|
||||||
|
'lg' => 'LG',
|
||||||
|
'amoi' => 'Amoi',
|
||||||
|
'xda' => 'XDA',
|
||||||
|
'mda' => 'MDA',
|
||||||
|
'vario' => 'Vario',
|
||||||
|
'htc' => 'HTC',
|
||||||
|
'samsung' => 'Samsung',
|
||||||
|
'sharp' => 'Sharp',
|
||||||
|
'sie-' => 'Siemens',
|
||||||
|
'alcatel' => 'Alcatel',
|
||||||
|
'benq' => 'BenQ',
|
||||||
|
'ipaq' => 'HP iPaq',
|
||||||
|
'mot-' => 'Motorola',
|
||||||
|
'playstation portable' => 'PlayStation Portable',
|
||||||
|
'playstation 3' => 'PlayStation 3',
|
||||||
|
'playstation vita' => 'PlayStation Vita',
|
||||||
|
'hiptop' => 'Danger Hiptop',
|
||||||
|
'nec-' => 'NEC',
|
||||||
|
'panasonic' => 'Panasonic',
|
||||||
|
'philips' => 'Philips',
|
||||||
|
'sagem' => 'Sagem',
|
||||||
|
'sanyo' => 'Sanyo',
|
||||||
|
'spv' => 'SPV',
|
||||||
|
'zte' => 'ZTE',
|
||||||
|
'sendo' => 'Sendo',
|
||||||
|
'nintendo dsi' => 'Nintendo DSi',
|
||||||
|
'nintendo ds' => 'Nintendo DS',
|
||||||
|
'nintendo 3ds' => 'Nintendo 3DS',
|
||||||
|
'wii' => 'Nintendo Wii',
|
||||||
|
'open web' => 'Open Web',
|
||||||
|
'openweb' => 'OpenWeb',
|
||||||
|
|
||||||
|
// Operating Systems
|
||||||
|
'android' => 'Android',
|
||||||
|
'symbian' => 'Symbian',
|
||||||
|
'SymbianOS' => 'SymbianOS',
|
||||||
|
'elaine' => 'Palm',
|
||||||
|
'series60' => 'Symbian S60',
|
||||||
|
'windows ce' => 'Windows CE',
|
||||||
|
|
||||||
|
// Browsers
|
||||||
|
'obigo' => 'Obigo',
|
||||||
|
'netfront' => 'Netfront Browser',
|
||||||
|
'openwave' => 'Openwave Browser',
|
||||||
|
'mobilexplorer' => 'Mobile Explorer',
|
||||||
|
'operamini' => 'Opera Mini',
|
||||||
|
'opera mini' => 'Opera Mini',
|
||||||
|
'opera mobi' => 'Opera Mobile',
|
||||||
|
'fennec' => 'Firefox Mobile',
|
||||||
|
|
||||||
|
// Other
|
||||||
|
'digital paths' => 'Digital Paths',
|
||||||
|
'avantgo' => 'AvantGo',
|
||||||
|
'xiino' => 'Xiino',
|
||||||
|
'novarra' => 'Novarra Transcoder',
|
||||||
|
'vodafone' => 'Vodafone',
|
||||||
|
'docomo' => 'NTT DoCoMo',
|
||||||
|
'o2' => 'O2',
|
||||||
|
|
||||||
|
// Fallback
|
||||||
|
'mobile' => 'Generic Mobile',
|
||||||
|
'wireless' => 'Generic Mobile',
|
||||||
|
'j2me' => 'Generic Mobile',
|
||||||
|
'midp' => 'Generic Mobile',
|
||||||
|
'cldc' => 'Generic Mobile',
|
||||||
|
'up.link' => 'Generic Mobile',
|
||||||
|
'up.browser' => 'Generic Mobile',
|
||||||
|
'smartphone' => 'Generic Mobile',
|
||||||
|
'cellphone' => 'Generic Mobile',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* -------------------------------------------------------------------
|
||||||
|
* Robots
|
||||||
|
* -------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* There are hundred of bots but these are the most common.
|
||||||
|
*
|
||||||
|
* @var array<string, string>
|
||||||
|
*/
|
||||||
|
public array $robots = [
|
||||||
|
'googlebot' => 'Googlebot',
|
||||||
|
'msnbot' => 'MSNBot',
|
||||||
|
'baiduspider' => 'Baiduspider',
|
||||||
|
'bingbot' => 'Bing',
|
||||||
|
'slurp' => 'Inktomi Slurp',
|
||||||
|
'yahoo' => 'Yahoo',
|
||||||
|
'ask jeeves' => 'Ask Jeeves',
|
||||||
|
'fastcrawler' => 'FastCrawler',
|
||||||
|
'infoseek' => 'InfoSeek Robot 1.0',
|
||||||
|
'lycos' => 'Lycos',
|
||||||
|
'yandex' => 'YandexBot',
|
||||||
|
'mediapartners-google' => 'MediaPartners Google',
|
||||||
|
'CRAZYWEBCRAWLER' => 'Crazy Webcrawler',
|
||||||
|
'adsbot-google' => 'AdsBot Google',
|
||||||
|
'feedfetcher-google' => 'Feedfetcher Google',
|
||||||
|
'curious george' => 'Curious George',
|
||||||
|
'ia_archiver' => 'Alexa Crawler',
|
||||||
|
'MJ12bot' => 'Majestic-12',
|
||||||
|
'Uptimebot' => 'Uptimebot',
|
||||||
|
];
|
||||||
|
}
|
||||||
44
app/Config/Validation.php
Normal file
44
app/Config/Validation.php
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Config;
|
||||||
|
|
||||||
|
use CodeIgniter\Config\BaseConfig;
|
||||||
|
use CodeIgniter\Validation\StrictRules\CreditCardRules;
|
||||||
|
use CodeIgniter\Validation\StrictRules\FileRules;
|
||||||
|
use CodeIgniter\Validation\StrictRules\FormatRules;
|
||||||
|
use CodeIgniter\Validation\StrictRules\Rules;
|
||||||
|
|
||||||
|
class Validation extends BaseConfig
|
||||||
|
{
|
||||||
|
// --------------------------------------------------------------------
|
||||||
|
// Setup
|
||||||
|
// --------------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores the classes that contain the
|
||||||
|
* rules that are available.
|
||||||
|
*
|
||||||
|
* @var list<string>
|
||||||
|
*/
|
||||||
|
public array $ruleSets = [
|
||||||
|
Rules::class,
|
||||||
|
FormatRules::class,
|
||||||
|
FileRules::class,
|
||||||
|
CreditCardRules::class,
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specifies the views that are used to display the
|
||||||
|
* errors.
|
||||||
|
*
|
||||||
|
* @var array<string, string>
|
||||||
|
*/
|
||||||
|
public array $templates = [
|
||||||
|
'list' => 'CodeIgniter\Validation\Views\list',
|
||||||
|
'single' => 'CodeIgniter\Validation\Views\single',
|
||||||
|
];
|
||||||
|
|
||||||
|
// --------------------------------------------------------------------
|
||||||
|
// Rules
|
||||||
|
// --------------------------------------------------------------------
|
||||||
|
}
|
||||||
62
app/Config/View.php
Normal file
62
app/Config/View.php
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Config;
|
||||||
|
|
||||||
|
use CodeIgniter\Config\View as BaseView;
|
||||||
|
use CodeIgniter\View\ViewDecoratorInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @phpstan-type parser_callable (callable(mixed): mixed)
|
||||||
|
* @phpstan-type parser_callable_string (callable(mixed): mixed)&string
|
||||||
|
*/
|
||||||
|
class View extends BaseView
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* When false, the view method will clear the data between each
|
||||||
|
* call. This keeps your data safe and ensures there is no accidental
|
||||||
|
* leaking between calls, so you would need to explicitly pass the data
|
||||||
|
* to each view. You might prefer to have the data stick around between
|
||||||
|
* calls so that it is available to all views. If that is the case,
|
||||||
|
* set $saveData to true.
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public $saveData = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parser Filters map a filter name with any PHP callable. When the
|
||||||
|
* Parser prepares a variable for display, it will chain it
|
||||||
|
* through the filters in the order defined, inserting any parameters.
|
||||||
|
* To prevent potential abuse, all filters MUST be defined here
|
||||||
|
* in order for them to be available for use within the Parser.
|
||||||
|
*
|
||||||
|
* Examples:
|
||||||
|
* { title|esc(js) }
|
||||||
|
* { created_on|date(Y-m-d)|esc(attr) }
|
||||||
|
*
|
||||||
|
* @var array<string, string>
|
||||||
|
* @phpstan-var array<string, parser_callable_string>
|
||||||
|
*/
|
||||||
|
public $filters = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parser Plugins provide a way to extend the functionality provided
|
||||||
|
* by the core Parser by creating aliases that will be replaced with
|
||||||
|
* any callable. Can be single or tag pair.
|
||||||
|
*
|
||||||
|
* @var array<string, callable|list<string>|string>
|
||||||
|
* @phpstan-var array<string, list<parser_callable_string>|parser_callable_string|parser_callable>
|
||||||
|
*/
|
||||||
|
public $plugins = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* View Decorators are class methods that will be run in sequence to
|
||||||
|
* have a chance to alter the generated output just prior to caching
|
||||||
|
* the results.
|
||||||
|
*
|
||||||
|
* All classes must implement CodeIgniter\View\ViewDecoratorInterface
|
||||||
|
*
|
||||||
|
* @var list<class-string<ViewDecoratorInterface>>
|
||||||
|
*/
|
||||||
|
public array $decorators = [];
|
||||||
|
}
|
||||||
1386
app/Controllers/Backend/CustomerController.php
Normal file
1386
app/Controllers/Backend/CustomerController.php
Normal file
File diff suppressed because it is too large
Load Diff
274
app/Controllers/Backend/CustomerDashboardController.php
Normal file
274
app/Controllers/Backend/CustomerDashboardController.php
Normal file
@ -0,0 +1,274 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controllers\Backend;
|
||||||
|
|
||||||
|
use CodeIgniter\RESTful\ResourceController;
|
||||||
|
use App\Models\Orders;
|
||||||
|
use App\Models\TopupModel;
|
||||||
|
use App\Models\CustomerWallet;
|
||||||
|
use App\Models\CustomerVoucherList;
|
||||||
|
use App\Models\CustomerPoint;
|
||||||
|
use App\Models\LogCustomerCheckin; // Add LogCustomerCheckin model
|
||||||
|
|
||||||
|
class CustomerDashboardController extends ResourceController
|
||||||
|
{
|
||||||
|
private $orders;
|
||||||
|
private $topups;
|
||||||
|
private $wallets;
|
||||||
|
private $vouchers;
|
||||||
|
private $points;
|
||||||
|
private $checkins; // Add checkins model
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->orders = new Orders();
|
||||||
|
$this->topups = new TopupModel();
|
||||||
|
$this->wallets = new CustomerWallet();
|
||||||
|
$this->vouchers = new CustomerVoucherList();
|
||||||
|
$this->points = new CustomerPoint();
|
||||||
|
$this->checkins = new LogCustomerCheckin(); // Initialize checkins model
|
||||||
|
}
|
||||||
|
|
||||||
|
public function show($customerId = null)
|
||||||
|
{
|
||||||
|
if (!$customerId) {
|
||||||
|
return $this->fail('Customer ID is required', 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
$orderSummary = $this->orders
|
||||||
|
->select('customer_id, COUNT(id) as total_orders, SUM(grand_total) as total_grand')
|
||||||
|
->where('customer_id', $customerId)
|
||||||
|
->groupBy('customer_id')
|
||||||
|
->first();
|
||||||
|
|
||||||
|
$topupSummary = $this->topups
|
||||||
|
->select('customer_id, COUNT(id) as total_topups, SUM(amount) as total_topup_amount')
|
||||||
|
->where('customer_id', $customerId)
|
||||||
|
->groupBy('customer_id')
|
||||||
|
->first();
|
||||||
|
|
||||||
|
$pointsSummary = $this->points
|
||||||
|
->select('customer_id,
|
||||||
|
COUNT(id) as total_point_transactions,
|
||||||
|
SUM(`in`) as total_point_in,
|
||||||
|
SUM(`out`) as total_point_out,
|
||||||
|
MAX(balance) as current_points')
|
||||||
|
->where('customer_id', $customerId)
|
||||||
|
->groupBy('customer_id')
|
||||||
|
->first();
|
||||||
|
|
||||||
|
$walletSummary = $this->wallets
|
||||||
|
->select('customer_id, SUM(`in`) as total_in, SUM(`out`) as total_out, MAX(balance) as current_balance')
|
||||||
|
->where('customer_id', $customerId)
|
||||||
|
->groupBy('customer_id')
|
||||||
|
->first();
|
||||||
|
|
||||||
|
$voucherSummary = $this->vouchers
|
||||||
|
->select('customer_id,
|
||||||
|
COUNT(id) as total_vouchers,
|
||||||
|
SUM(CASE WHEN voucher_status = "active" THEN 1 ELSE 0 END) as active_vouchers,
|
||||||
|
SUM(CASE WHEN voucher_status = "used" THEN 1 ELSE 0 END) as used_vouchers,
|
||||||
|
SUM(CASE WHEN voucher_status = "expired" THEN 1 ELSE 0 END) as expired_vouchers')
|
||||||
|
->where('customer_id', $customerId)
|
||||||
|
->groupBy('customer_id')
|
||||||
|
->first();
|
||||||
|
|
||||||
|
$activeVouchers = $this->vouchers
|
||||||
|
->where('customer_id', $customerId)
|
||||||
|
->where('voucher_status', 'active')
|
||||||
|
->where('voucher_expiry_date >=', date('Y-m-d H:i:s'))
|
||||||
|
->orderBy('voucher_expiry_date', 'ASC')
|
||||||
|
->findAll();
|
||||||
|
|
||||||
|
// Get check-in data
|
||||||
|
$checkinData = $this->checkins
|
||||||
|
->select('customer_id,
|
||||||
|
COUNT(id) as total_checkins,
|
||||||
|
MAX(streak_count) as highest_streak,
|
||||||
|
MAX(checkin_date) as last_checkin_date')
|
||||||
|
->where('customer_id', $customerId)
|
||||||
|
->groupBy('customer_id')
|
||||||
|
->first();
|
||||||
|
|
||||||
|
$recentCheckins = $this->checkins
|
||||||
|
->where('customer_id', $customerId)
|
||||||
|
->orderBy('checkin_date', 'DESC')
|
||||||
|
->limit(7) // Get last 7 check-ins
|
||||||
|
->findAll();
|
||||||
|
|
||||||
|
$orderLifecycle = $this->orders
|
||||||
|
->select('MIN(created_at) as first_order_date, MAX(created_at) as last_order_date')
|
||||||
|
->where('customer_id', $customerId)
|
||||||
|
->where('status !=', 'cancelled')
|
||||||
|
->first();
|
||||||
|
|
||||||
|
$topupLifecycle = $this->topups
|
||||||
|
->select('MIN(created_at) as first_topup_date, MAX(created_at) as last_topup_date')
|
||||||
|
->where('customer_id', $customerId)
|
||||||
|
->where('status', 'success')
|
||||||
|
->first();
|
||||||
|
|
||||||
|
$pointsLifecycle = $this->points
|
||||||
|
->select('MIN(created_at) as first_point_date, MAX(created_at) as last_point_date')
|
||||||
|
->where('customer_id', $customerId)
|
||||||
|
->first();
|
||||||
|
|
||||||
|
// Get check-in lifecycle
|
||||||
|
$checkinLifecycle = $this->checkins
|
||||||
|
->select('MIN(checkin_date) as first_checkin_date, MAX(checkin_date) as last_checkin_date')
|
||||||
|
->where('customer_id', $customerId)
|
||||||
|
->first();
|
||||||
|
|
||||||
|
$customerStatus = $this->calculateCustomerStatus($orderLifecycle, $topupLifecycle, $pointsLifecycle, $checkinLifecycle);
|
||||||
|
|
||||||
|
$lifecycleData = [
|
||||||
|
'first_activity' => $this->getEarliestDate([
|
||||||
|
$orderLifecycle['first_order_date'] ?? null,
|
||||||
|
$topupLifecycle['first_topup_date'] ?? null,
|
||||||
|
$pointsLifecycle['first_point_date'] ?? null,
|
||||||
|
$checkinLifecycle['first_checkin_date'] ?? null
|
||||||
|
]),
|
||||||
|
'last_activity' => $this->getLatestDate([
|
||||||
|
$orderLifecycle['last_order_date'] ?? null,
|
||||||
|
$topupLifecycle['last_topup_date'] ?? null,
|
||||||
|
$pointsLifecycle['last_point_date'] ?? null,
|
||||||
|
$checkinLifecycle['last_checkin_date'] ?? null
|
||||||
|
]),
|
||||||
|
'first_order' => $orderLifecycle['first_order_date'] ?? null,
|
||||||
|
'last_order' => $orderLifecycle['last_order_date'] ?? null,
|
||||||
|
'first_topup' => $topupLifecycle['first_topup_date'] ?? null,
|
||||||
|
'last_topup' => $topupLifecycle['last_topup_date'] ?? null,
|
||||||
|
'first_point' => $pointsLifecycle['first_point_date'] ?? null,
|
||||||
|
'last_point' => $pointsLifecycle['last_point_date'] ?? null,
|
||||||
|
'first_checkin' => $checkinLifecycle['first_checkin_date'] ?? null,
|
||||||
|
'last_checkin' => $checkinLifecycle['last_checkin_date'] ?? null,
|
||||||
|
'customer_status' => $customerStatus,
|
||||||
|
'days_since_last_activity' => $this->calculateDaysSinceLastActivity(
|
||||||
|
$orderLifecycle['last_order_date'] ?? null,
|
||||||
|
$topupLifecycle['last_topup_date'] ?? null,
|
||||||
|
$pointsLifecycle['last_point_date'] ?? null,
|
||||||
|
$checkinLifecycle['last_checkin_date'] ?? null
|
||||||
|
)
|
||||||
|
];
|
||||||
|
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 200,
|
||||||
|
'message' => 'Customer dashboard data retrieved successfully',
|
||||||
|
'data' => [
|
||||||
|
'orders' => $orderSummary ?? [
|
||||||
|
'customer_id' => $customerId,
|
||||||
|
'total_orders' => 0,
|
||||||
|
'total_grand' => 0
|
||||||
|
],
|
||||||
|
'topups' => $topupSummary ?? [
|
||||||
|
'customer_id' => $customerId,
|
||||||
|
'total_topups' => 0,
|
||||||
|
'total_topup_amount' => 0
|
||||||
|
],
|
||||||
|
'points' => $pointsSummary ?? [
|
||||||
|
'customer_id' => $customerId,
|
||||||
|
'total_point_transactions' => 0,
|
||||||
|
'total_point_in' => 0,
|
||||||
|
'total_point_out' => 0,
|
||||||
|
'current_points' => 0
|
||||||
|
],
|
||||||
|
'wallet' => $walletSummary ?? [
|
||||||
|
'customer_id' => $customerId,
|
||||||
|
'total_in' => 0,
|
||||||
|
'total_out' => 0,
|
||||||
|
'current_balance' => 0
|
||||||
|
],
|
||||||
|
'vouchers' => [
|
||||||
|
'summary' => $voucherSummary ?? [
|
||||||
|
'customer_id' => $customerId,
|
||||||
|
'total_vouchers' => 0,
|
||||||
|
'active_vouchers' => 0,
|
||||||
|
'used_vouchers' => 0,
|
||||||
|
'expired_vouchers' => 0
|
||||||
|
],
|
||||||
|
'active_vouchers_list' => $activeVouchers
|
||||||
|
],
|
||||||
|
'checkins' => [ // Added checkins section
|
||||||
|
'summary' => $checkinData ?? [
|
||||||
|
'customer_id' => $customerId,
|
||||||
|
'total_checkins' => 0,
|
||||||
|
'highest_streak' => 0,
|
||||||
|
'last_checkin_date' => null
|
||||||
|
],
|
||||||
|
'recent_checkins' => $recentCheckins
|
||||||
|
],
|
||||||
|
'lifecycle' => $lifecycleData
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function calculateCustomerStatus($orderLifecycle, $topupLifecycle, $pointsLifecycle, $checkinLifecycle)
|
||||||
|
{
|
||||||
|
$lastOrderDate = $orderLifecycle['last_order_date'] ?? null;
|
||||||
|
$lastTopupDate = $topupLifecycle['last_topup_date'] ?? null;
|
||||||
|
$lastPointDate = $pointsLifecycle['last_point_date'] ?? null;
|
||||||
|
$lastCheckinDate = $checkinLifecycle['last_checkin_date'] ?? null;
|
||||||
|
|
||||||
|
$lastActivity = $this->getLatestDate([$lastOrderDate, $lastTopupDate, $lastPointDate, $lastCheckinDate]);
|
||||||
|
|
||||||
|
if (!$lastActivity) {
|
||||||
|
return 'new';
|
||||||
|
}
|
||||||
|
|
||||||
|
$daysInactive = $this->calculateDaysSince($lastActivity);
|
||||||
|
|
||||||
|
if ($daysInactive <= 30) {
|
||||||
|
return 'active';
|
||||||
|
} elseif ($daysInactive <= 90) {
|
||||||
|
return 'dormant';
|
||||||
|
} else {
|
||||||
|
return 'churned';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function calculateDaysSinceLastActivity($lastOrderDate, $lastTopupDate, $lastPointDate, $lastCheckinDate)
|
||||||
|
{
|
||||||
|
$lastActivity = $this->getLatestDate([$lastOrderDate, $lastTopupDate, $lastPointDate, $lastCheckinDate]);
|
||||||
|
|
||||||
|
if (!$lastActivity) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->calculateDaysSince($lastActivity);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function calculateDaysSince($dateString)
|
||||||
|
{
|
||||||
|
if (!$dateString) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$date = new \DateTime($dateString);
|
||||||
|
$now = new \DateTime();
|
||||||
|
$interval = $now->diff($date);
|
||||||
|
|
||||||
|
return $interval->days;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getEarliestDate(array $dates)
|
||||||
|
{
|
||||||
|
$validDates = array_filter($dates);
|
||||||
|
if (empty($validDates)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
sort($validDates);
|
||||||
|
return $validDates[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getLatestDate(array $dates)
|
||||||
|
{
|
||||||
|
$validDates = array_filter($dates);
|
||||||
|
if (empty($validDates)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
rsort($validDates);
|
||||||
|
return $validDates[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
278
app/Controllers/Backend/DashboardController.php
Normal file
278
app/Controllers/Backend/DashboardController.php
Normal file
@ -0,0 +1,278 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controllers\Backend;
|
||||||
|
|
||||||
|
use CodeIgniter\RESTful\ResourceController;
|
||||||
|
use App\Models\Orders;
|
||||||
|
use App\Models\TopupModel;
|
||||||
|
use App\Models\Customer;
|
||||||
|
use App\Models\Outlet;
|
||||||
|
|
||||||
|
|
||||||
|
class DashboardController extends ResourceController
|
||||||
|
{
|
||||||
|
private $orders;
|
||||||
|
private $topup;
|
||||||
|
private $customer;
|
||||||
|
private $outlets;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->orders = new Orders();
|
||||||
|
$this->topup = new TopupModel();
|
||||||
|
$this->customer = new Customer();
|
||||||
|
$this->outlets = new Outlet();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function dashboard()
|
||||||
|
{
|
||||||
|
$today = date('Y-m-d');
|
||||||
|
$month = date('m');
|
||||||
|
$year = date('Y');
|
||||||
|
|
||||||
|
// 1. Net Sales Today (sum of grand_total where paid)
|
||||||
|
$netSalesToday = $this->orders
|
||||||
|
->selectSum('grand_total')
|
||||||
|
->where('DATE(created_at)', $today)
|
||||||
|
->where('payment_status', 'paid')
|
||||||
|
->get()->getRow()->grand_total ?? 0;
|
||||||
|
|
||||||
|
// 2. Today Transaction (count orders today)
|
||||||
|
$todayTransaction = $this->orders
|
||||||
|
->where('DATE(created_at)', $today)
|
||||||
|
->where('payment_status', 'paid')
|
||||||
|
->countAllResults();
|
||||||
|
|
||||||
|
// 3. Net Sales Month to Date
|
||||||
|
$netSalesMonthToDate = $this->orders
|
||||||
|
->selectSum('grand_total')
|
||||||
|
->where('MONTH(created_at)', $month)
|
||||||
|
->where('YEAR(created_at)', $year)
|
||||||
|
->where('payment_status', 'paid')
|
||||||
|
->get()->getRow()->grand_total ?? 0;
|
||||||
|
|
||||||
|
// 4. Net Sales Year to Date
|
||||||
|
$netSalesYearToDate = $this->orders
|
||||||
|
->selectSum('grand_total')
|
||||||
|
->where('YEAR(created_at)', $year)
|
||||||
|
->where('payment_status', 'paid')
|
||||||
|
->get()->getRow()->grand_total ?? 0;
|
||||||
|
|
||||||
|
// 5. Topup
|
||||||
|
$topup1 = $this->topup
|
||||||
|
->selectSum('amount')
|
||||||
|
->where('DATE(created_at)', $today)
|
||||||
|
->where('status', 'Success')
|
||||||
|
->get()->getRow()->amount ?? 0;
|
||||||
|
|
||||||
|
$topup2 = $this->topup
|
||||||
|
->selectSum('other_amount')
|
||||||
|
->where('DATE(created_at)', $today)
|
||||||
|
->where('status', 'Success')
|
||||||
|
->get()->getRow()->other_amount ?? 0;
|
||||||
|
|
||||||
|
// 6. Total Customer Wallet Balance
|
||||||
|
$wallet_balance = $this->customer
|
||||||
|
->selectSum('customer_wallet')
|
||||||
|
->get()->getRow()->customer_wallet ?? 0;
|
||||||
|
|
||||||
|
// 7. Today Voucher Redeemed / Discount
|
||||||
|
$today_voucher_amount = $this->orders
|
||||||
|
->selectSum('voucher_discount_amount')
|
||||||
|
->where('DATE(created_at)', $today)
|
||||||
|
->where('payment_status', 'paid')
|
||||||
|
->get()->getRow()->voucher_discount_amount ?? 0;
|
||||||
|
|
||||||
|
$today_promo_amount = $this->orders
|
||||||
|
->selectSum('promo_discount_amount')
|
||||||
|
->where('DATE(created_at)', $today)
|
||||||
|
->where('payment_status', 'paid')
|
||||||
|
->get()->getRow()->promo_discount_amount ?? 0;
|
||||||
|
|
||||||
|
$today_discount_amount = $this->orders
|
||||||
|
->selectSum('promo_discount_amount')
|
||||||
|
->where('DATE(created_at)', $today)
|
||||||
|
->where('payment_status', 'paid')
|
||||||
|
->get()->getRow()->promo_discount_amount ?? 0;
|
||||||
|
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'today_net_sales' => $netSalesToday,
|
||||||
|
'today_total_transaction' => $todayTransaction,
|
||||||
|
'net_sales_month_to_date' => $netSalesMonthToDate,
|
||||||
|
'net_sales_year_to_date' => $netSalesYearToDate,
|
||||||
|
'today_topup' => $topup1 + $topup2,
|
||||||
|
'total_wallet_balance' => $wallet_balance,
|
||||||
|
'today_total_discount_amount' => $today_voucher_amount + $today_promo_amount + $today_discount_amount,
|
||||||
|
];
|
||||||
|
|
||||||
|
return $this->respond(['status' => 200, 'data' => $data]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function dashboardSummary ()
|
||||||
|
{
|
||||||
|
$data = [
|
||||||
|
'today' => $this->orders->getTodayOrdersRevenueByHour(),
|
||||||
|
'yesterday' => $this->orders->getYesterdayOrdersRevenueByHour(),
|
||||||
|
'last7days' => $this->orders->getLast7DaysOrdersRevenue(),
|
||||||
|
'last30days' => $this->orders->getLast30DaysOrdersRevenue(),
|
||||||
|
];
|
||||||
|
|
||||||
|
return $this->respond(['status' => 200, 'data' => $data]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function liveMonitor()
|
||||||
|
{
|
||||||
|
//Current Offline outlets
|
||||||
|
$outlets = $this->outlets->getOperatingHoursWithDaysList();
|
||||||
|
$onlineCount = 0;
|
||||||
|
$offlineCount = 0;
|
||||||
|
|
||||||
|
foreach ($outlets as $outlet) {
|
||||||
|
if ($this->isOutletOnline($outlet)) {
|
||||||
|
$onlineCount++;
|
||||||
|
} else {
|
||||||
|
$offlineCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Cancelled Orders (all time, or do you also want by date range?)
|
||||||
|
$cancelledOrders = $this->orders
|
||||||
|
->where('payment_status', 'cancelled')
|
||||||
|
->countAllResults();
|
||||||
|
|
||||||
|
// Dates
|
||||||
|
$endDateCurrent = date('Y-m-d'); // today
|
||||||
|
$startDateCurrent = date('Y-m-d', strtotime('-7 days')); // 7 days ago
|
||||||
|
|
||||||
|
$endDatePrevious = date('Y-m-d', strtotime('-8 days')); // day before current range
|
||||||
|
$startDatePrevious = date('Y-m-d', strtotime('-15 days')); // 15 days ago
|
||||||
|
|
||||||
|
// Function to fetch stats for a range
|
||||||
|
$getStats = function($startDate, $endDate) {
|
||||||
|
// Gross Sales
|
||||||
|
$grossSales = $this->orders
|
||||||
|
->selectSum('grand_total', 'gross_sales')
|
||||||
|
->where('payment_status', 'paid')
|
||||||
|
->where('created_at >=', $startDate)
|
||||||
|
->where('created_at <=', $endDate)
|
||||||
|
->where('promo_discount_amount <=', 0) // No promo discount
|
||||||
|
->where('voucher_discount_amount <=', 0) // No voucher discount
|
||||||
|
->where('discount_amount <=', 0) // No regular discount
|
||||||
|
->get()->getRow()->gross_sales ?? 0;
|
||||||
|
|
||||||
|
// Total Customer
|
||||||
|
$totalCustomer = $this->orders
|
||||||
|
->select('COUNT(DISTINCT customer_id) as total_customer')
|
||||||
|
->where('payment_status', 'paid')
|
||||||
|
->where('created_at >=', $startDate)
|
||||||
|
->where('created_at <=', $endDate)
|
||||||
|
->get()->getRow()->total_customer ?? 0;
|
||||||
|
|
||||||
|
// Net Sales from Offers
|
||||||
|
$netSalesOffers = $this->orders
|
||||||
|
->selectSum('grand_total', 'net_sales_offers')
|
||||||
|
->where('payment_status', 'paid')
|
||||||
|
->where('created_at >=', $startDate)
|
||||||
|
->where('created_at <=', $endDate)
|
||||||
|
->groupStart()
|
||||||
|
->where('promo_discount_amount >', 0)
|
||||||
|
->orWhere('voucher_discount_amount >', 0)
|
||||||
|
->orWhere('discount_amount >', 0)
|
||||||
|
->groupEnd()
|
||||||
|
->get()->getRow()->net_sales_offers ?? 0;
|
||||||
|
|
||||||
|
// Average Transaction
|
||||||
|
$avgTransaction = $this->orders
|
||||||
|
->selectAvg('grand_total', 'avg_transaction')
|
||||||
|
->where('payment_status', 'paid')
|
||||||
|
->where('created_at >=', $startDate)
|
||||||
|
->where('created_at <=', $endDate)
|
||||||
|
->get()->getRow()->avg_transaction ?? 0;
|
||||||
|
|
||||||
|
return [
|
||||||
|
'gross_sales' => $grossSales,
|
||||||
|
'total_customer' => $totalCustomer,
|
||||||
|
'net_sales_from_offers' => $netSalesOffers,
|
||||||
|
'avg_transaction' => $avgTransaction,
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
// Current 7 days
|
||||||
|
$current = $getStats($startDateCurrent, $endDateCurrent);
|
||||||
|
|
||||||
|
// Previous 7 days
|
||||||
|
$previous = $getStats($startDatePrevious, $endDatePrevious);
|
||||||
|
|
||||||
|
// Function to calculate percentage difference
|
||||||
|
$calcPercentage = function($currentValue, $previousValue) {
|
||||||
|
if ($previousValue == 0) {
|
||||||
|
return $currentValue > 0 ? 100 : 0;
|
||||||
|
}
|
||||||
|
return (($currentValue - $previousValue) / $previousValue) * 100;
|
||||||
|
};
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'offline_outlets' => $offlineCount,
|
||||||
|
'cancelled_orders' => $cancelledOrders,
|
||||||
|
'gross_sales' => [
|
||||||
|
'current' => $current['gross_sales'],
|
||||||
|
'previous' => $previous['gross_sales'],
|
||||||
|
'percentage' => $calcPercentage($current['gross_sales'], $previous['gross_sales']),
|
||||||
|
],
|
||||||
|
'total_customer' => [
|
||||||
|
'current' => $current['total_customer'],
|
||||||
|
'previous' => $previous['total_customer'],
|
||||||
|
'percentage' => $calcPercentage($current['total_customer'], $previous['total_customer']),
|
||||||
|
],
|
||||||
|
'net_sales_from_offers' => [
|
||||||
|
'current' => $current['net_sales_from_offers'],
|
||||||
|
'previous' => $previous['net_sales_from_offers'],
|
||||||
|
'percentage' => $calcPercentage($current['net_sales_from_offers'], $previous['net_sales_from_offers']),
|
||||||
|
],
|
||||||
|
'avg_transaction' => [
|
||||||
|
'current' => $current['avg_transaction'],
|
||||||
|
'previous' => $previous['avg_transaction'],
|
||||||
|
'percentage' => $calcPercentage($current['avg_transaction'], $previous['avg_transaction']),
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
return $this->respond(['status' => 200, 'data' => $data]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function isOutletOnline($outlet)
|
||||||
|
{
|
||||||
|
// Get current day and time
|
||||||
|
$currentDay = date('l'); // e.g., "Monday"
|
||||||
|
$currentTime = date('H:i:s'); // Current time in 24-hour format
|
||||||
|
|
||||||
|
// Check if outlet operates on current day
|
||||||
|
if (!isset($outlet['operating_schedule'][$currentDay]) ||
|
||||||
|
!$outlet['operating_schedule'][$currentDay]['is_operated']) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$operatingHours = $outlet['operating_schedule'][$currentDay]['operating_hours'];
|
||||||
|
|
||||||
|
// Check if current time falls within any operating hour slot
|
||||||
|
foreach ($operatingHours as $timeSlot) {
|
||||||
|
$startTime = $timeSlot['start_time'];
|
||||||
|
$endTime = $timeSlot['end_time'];
|
||||||
|
|
||||||
|
// Handle cases where end time is 23:59:00 (which means until midnight)
|
||||||
|
if ($endTime === '23:59:00') {
|
||||||
|
$endTime = '23:59:59';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($currentTime >= $startTime && $currentTime <= $endTime) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
100
app/Controllers/Backend/DeliverySetting.php
Normal file
100
app/Controllers/Backend/DeliverySetting.php
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controllers\Backend;
|
||||||
|
|
||||||
|
use App\Controllers\BaseController;
|
||||||
|
use App\Models\DeliverySettingModel;
|
||||||
|
use CodeIgniter\HTTP\ResponseInterface;
|
||||||
|
|
||||||
|
class DeliverySetting extends BaseController
|
||||||
|
{
|
||||||
|
protected $model;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->model = new DeliverySettingModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
$data = $this->model->findAll();
|
||||||
|
// $this->model->orderBy('status', 'active');
|
||||||
|
return $this->response->setJSON([
|
||||||
|
'status' => 'success',
|
||||||
|
'data' => $data,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
public function create()
|
||||||
|
{
|
||||||
|
$data = $this->request->getJSON(true) ?? $this->request->getPost();
|
||||||
|
|
||||||
|
if (!$this->model->insert($data)) {
|
||||||
|
return $this->response->setStatusCode(ResponseInterface::HTTP_BAD_REQUEST)
|
||||||
|
->setJSON([
|
||||||
|
'status' => 'error',
|
||||||
|
'errors' => $this->model->errors(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->response->setStatusCode(ResponseInterface::HTTP_CREATED)
|
||||||
|
->setJSON([
|
||||||
|
'status' => 'success',
|
||||||
|
'message' => 'Delivery setting created',
|
||||||
|
'data' => $this->model->find($this->model->getInsertID()),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function show($id = null)
|
||||||
|
{
|
||||||
|
$row = $this->model->find($id);
|
||||||
|
|
||||||
|
if (!$row) {
|
||||||
|
return $this->response->setStatusCode(ResponseInterface::HTTP_NOT_FOUND)
|
||||||
|
->setJSON(['status' => 'error', 'message' => 'Not found']);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->response->setJSON([
|
||||||
|
'status' => 'success',
|
||||||
|
'data' => $row,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update($id = null)
|
||||||
|
{
|
||||||
|
$data = $this->request->getJSON(true) ?? $this->request->getRawInput();
|
||||||
|
|
||||||
|
if (!$this->model->find($id)) {
|
||||||
|
return $this->response->setStatusCode(ResponseInterface::HTTP_NOT_FOUND)
|
||||||
|
->setJSON(['status' => 'error', 'message' => 'Not found']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$this->model->update($id, $data)) {
|
||||||
|
return $this->response->setStatusCode(ResponseInterface::HTTP_BAD_REQUEST)
|
||||||
|
->setJSON([
|
||||||
|
'status' => 'error',
|
||||||
|
'errors' => $this->model->errors(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->response->setJSON([
|
||||||
|
'status' => 'success',
|
||||||
|
'message' => 'Delivery setting updated',
|
||||||
|
'data' => $this->model->find($id),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete($id = null)
|
||||||
|
{
|
||||||
|
if (!$this->model->find($id)) {
|
||||||
|
return $this->response->setStatusCode(ResponseInterface::HTTP_NOT_FOUND)
|
||||||
|
->setJSON(['status' => 'error', 'message' => 'Not found']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->model->delete($id);
|
||||||
|
|
||||||
|
return $this->response->setJSON([
|
||||||
|
'status' => 'success',
|
||||||
|
'message' => 'Delivery setting deleted',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
13
app/Controllers/Backend/Home.php
Normal file
13
app/Controllers/Backend/Home.php
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controllers\Backend;
|
||||||
|
|
||||||
|
use App\Controllers\BaseController;
|
||||||
|
|
||||||
|
class Home extends BaseController
|
||||||
|
{
|
||||||
|
public function index(): string
|
||||||
|
{
|
||||||
|
return view('welcome_message');
|
||||||
|
}
|
||||||
|
}
|
||||||
170
app/Controllers/Backend/LoginController.php
Normal file
170
app/Controllers/Backend/LoginController.php
Normal file
@ -0,0 +1,170 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controllers\Backend;
|
||||||
|
|
||||||
|
use App\Controllers\BaseController;
|
||||||
|
use CodeIgniter\HTTP\ResponseInterface;
|
||||||
|
use CodeIgniter\API\ResponseTrait;
|
||||||
|
use App\Models\User;
|
||||||
|
use Firebase\JWT\JWT;
|
||||||
|
|
||||||
|
class LoginController extends BaseController
|
||||||
|
{
|
||||||
|
use ResponseTrait;
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
$userModel = new User();
|
||||||
|
|
||||||
|
$username = $this->request->getVar('username');
|
||||||
|
$password = $this->request->getVar('password_hash');
|
||||||
|
|
||||||
|
$user = $userModel->where('username', $username)->first();
|
||||||
|
if(is_null($user)) {
|
||||||
|
return $this->failUnauthorized('Invalid username or password.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$hashedPassword = md5($password);
|
||||||
|
|
||||||
|
if ($hashedPassword !== $user['password_hash']) {
|
||||||
|
return $this->failUnauthorized('Invalid username or password.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$key = getenv('JWT_SECRET');
|
||||||
|
$iat = time(); // current timestamp value
|
||||||
|
$exp = $iat + 86400;
|
||||||
|
|
||||||
|
$payload = array(
|
||||||
|
"iss" => "Issuer of the JWT",
|
||||||
|
"aud" => "Audience that the JWT",
|
||||||
|
"sub" => "Subject of the JWT",
|
||||||
|
"iat" => $iat, //Time the JWT issued at
|
||||||
|
"exp" => $exp, // Expiration time of token
|
||||||
|
"username" => $user['username'],
|
||||||
|
);
|
||||||
|
|
||||||
|
$token = JWT::encode($payload, $key, 'HS256');
|
||||||
|
|
||||||
|
$userData = [
|
||||||
|
'user_id' => $user['id'],
|
||||||
|
'username' => $user['username'],
|
||||||
|
'name' => $user['name'],
|
||||||
|
'role' => $user['role'],
|
||||||
|
'status'=> $user['status'],
|
||||||
|
'outlet_id'=> $user['outlet_id'],
|
||||||
|
// 'created_by'=> $user['created_by'],
|
||||||
|
'updated_at' => $user['updated_at'],
|
||||||
|
'created_at' => $user['created_at'],
|
||||||
|
];
|
||||||
|
$response = [
|
||||||
|
'message' => 'Login Succesful',
|
||||||
|
'token' => $token,
|
||||||
|
'userData' => $userData
|
||||||
|
];
|
||||||
|
|
||||||
|
// session()->set('merchant_id', $user['merchant_id']);
|
||||||
|
|
||||||
|
return $this->respond($response, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function requestToken()
|
||||||
|
{
|
||||||
|
$userModel = new User();
|
||||||
|
|
||||||
|
$merchant = $this->request->getVar('merchant');
|
||||||
|
$token_key = $this->request->getVar('token_key');
|
||||||
|
|
||||||
|
$user = $userModel->where('username', $merchant)->first();
|
||||||
|
if(is_null($user)) {
|
||||||
|
return $this->failUnauthorized('Invalid username.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($token_key !== $user['token_key']) {
|
||||||
|
return $this->failUnauthorized('Invalid token key.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$key = getenv('JWT_SECRET');
|
||||||
|
$iat = time(); // current timestamp value
|
||||||
|
$exp = $iat + 86400;
|
||||||
|
|
||||||
|
$payload = array(
|
||||||
|
"iss" => "Issuer of the JWT",
|
||||||
|
"aud" => "Audience that the JWT",
|
||||||
|
"sub" => "Subject of the JWT",
|
||||||
|
"iat" => $iat, //Time the JWT issued at
|
||||||
|
"exp" => $exp, // Expiration time of token
|
||||||
|
"user_id" => $user['user_id'],
|
||||||
|
"token_key" => $token_key,
|
||||||
|
);
|
||||||
|
|
||||||
|
$token = JWT::encode($payload, $key, 'HS256');
|
||||||
|
|
||||||
|
$response = [
|
||||||
|
'message' => 'Request Succesfully',
|
||||||
|
'token' => $token,
|
||||||
|
'expires' => date('Y-m-d H:i:s', $exp)
|
||||||
|
];
|
||||||
|
|
||||||
|
return $this->respond($response, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the properties of a resource object
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function show($id = null)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a new resource object, with default properties
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function new()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new resource object, from "posted" parameters
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function create()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the editable properties of a resource object
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function edit($id = null)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add or update a model resource, from "posted" properties
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function update($id = null)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete the designated resource object from the model
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function delete($id = null)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
||||||
1189
app/Controllers/Backend/MenuController.php
Normal file
1189
app/Controllers/Backend/MenuController.php
Normal file
File diff suppressed because it is too large
Load Diff
248
app/Controllers/Backend/OptionController.php
Normal file
248
app/Controllers/Backend/OptionController.php
Normal file
@ -0,0 +1,248 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controllers\Backend;
|
||||||
|
|
||||||
|
use App\Models\Options;
|
||||||
|
use App\Models\OptionsGroups;
|
||||||
|
use CodeIgniter\HTTP\ResponseInterface;
|
||||||
|
use CodeIgniter\RESTful\ResourceController;
|
||||||
|
|
||||||
|
helper('image');
|
||||||
|
class OptionController extends ResourceController
|
||||||
|
{
|
||||||
|
|
||||||
|
private $options;
|
||||||
|
private $option_groups;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->options = new Options();
|
||||||
|
$this->option_groups = new OptionsGroups();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
// echo(123);exit;
|
||||||
|
$groups = $this->option_groups->findAll();
|
||||||
|
$data = [];
|
||||||
|
|
||||||
|
foreach ($groups as $group) {
|
||||||
|
$group['options'] = $this->options
|
||||||
|
->where('option_group_id', $group['id'])
|
||||||
|
->findAll();
|
||||||
|
$data[] = $group;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->respond(['status' => 200, 'data' => $data]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function show($id = null)
|
||||||
|
{
|
||||||
|
$group = $this->option_groups->find($id);
|
||||||
|
|
||||||
|
if (!$group) {
|
||||||
|
return $this->failNotFound("Option group not found.");
|
||||||
|
}
|
||||||
|
|
||||||
|
$group['options'] = $this->options
|
||||||
|
->where('option_group_id', $group['id'])
|
||||||
|
->findAll();
|
||||||
|
|
||||||
|
return $this->respond(['status' => 200, 'data' => $group]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function create()
|
||||||
|
{
|
||||||
|
$validation = $this->validate([
|
||||||
|
'title' => 'required',
|
||||||
|
'min_quantity' => 'permit_empty|integer',
|
||||||
|
'max_quantity' => 'permit_empty|integer',
|
||||||
|
'is_required' => 'required',
|
||||||
|
'status' => 'required',
|
||||||
|
'order_index' => 'permit_empty|integer',
|
||||||
|
'options' => 'permit_empty',
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (!$validation) {
|
||||||
|
return $this->failValidationErrors($this->validator->getErrors());
|
||||||
|
}
|
||||||
|
|
||||||
|
$groupData = [
|
||||||
|
'title' => $this->request->getVar('title'),
|
||||||
|
'min_quantity' => $this->request->getVar('min_quantity') ?? 0,
|
||||||
|
'max_quantity' => $this->request->getVar('max_quantity') ?? 0,
|
||||||
|
'is_required' => $this->request->getVar('is_required'),
|
||||||
|
'status' => $this->request->getVar('status'),
|
||||||
|
'order_index' => $this->request->getVar('order_index') ?? 0,
|
||||||
|
];
|
||||||
|
|
||||||
|
$groupId = $this->option_groups->insert($groupData);
|
||||||
|
|
||||||
|
if (!$groupId) {
|
||||||
|
return $this->fail("Failed to create group.", 400);
|
||||||
|
}
|
||||||
|
// echo '<pre>';
|
||||||
|
// print_r($this->request->getPost());
|
||||||
|
// exit;
|
||||||
|
$options = $this->request->getJSON(true)['options'] ?? $this->request->getVar('options') ?? [];
|
||||||
|
if (!is_array($options)) {
|
||||||
|
return $this->failValidationErrors('Options not formatted correctly.');
|
||||||
|
}
|
||||||
|
$savedOptions = [];
|
||||||
|
foreach ($options as $i => $opt) {
|
||||||
|
$imageUrl = null;
|
||||||
|
$compressedUrl = null;
|
||||||
|
|
||||||
|
$imageFile = $this->request->getFile("image$i");
|
||||||
|
|
||||||
|
if ($imageFile && $imageFile->isValid() && !$imageFile->hasMoved()) {
|
||||||
|
$result = save_image_with_compression(
|
||||||
|
$imageFile,
|
||||||
|
FCPATH . 'backend/uploads/options',
|
||||||
|
FCPATH . 'backend/uploads/options_compressed',
|
||||||
|
900,
|
||||||
|
80
|
||||||
|
);
|
||||||
|
|
||||||
|
$imageUrl = base_url('backend/uploads/options' . basename($result['original']));
|
||||||
|
$compressedUrl = base_url('backend/uploads/options_compressed' . basename($result['compressed']));
|
||||||
|
}
|
||||||
|
$optionData = [
|
||||||
|
'option_group_id' => $groupId,
|
||||||
|
'title' => isset($opt['title']) ? $opt['title'] : '',
|
||||||
|
'price_adjustment' => isset($opt['price_adjustment']) ? $opt['price_adjustment'] : 0,
|
||||||
|
'order_index' => isset($opt['order_index']) ? $opt['order_index'] : $i,
|
||||||
|
'images' => $imageUrl,
|
||||||
|
'images_compressed' => $compressedUrl,
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->options->insert($optionData);
|
||||||
|
$savedOptions[] = $optionData;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 200,
|
||||||
|
'message' => 'Group with options created.',
|
||||||
|
'data' => [
|
||||||
|
'group_id' => $groupId,
|
||||||
|
'group' => $groupData,
|
||||||
|
'options' => $savedOptions
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function update($id = null)
|
||||||
|
{
|
||||||
|
$group = $this->option_groups->find($id);
|
||||||
|
|
||||||
|
if (!$group) {
|
||||||
|
return $this->fail("Group not found.", 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
$validation = $this->validate([
|
||||||
|
'title' => 'required',
|
||||||
|
'min_quantity' => 'permit_empty|integer',
|
||||||
|
'max_quantity' => 'permit_empty|integer',
|
||||||
|
'is_required' => 'required|in_list[0,1,true,false]',
|
||||||
|
'status' => 'required',
|
||||||
|
'order_index' => 'permit_empty|integer',
|
||||||
|
'options' => 'permit_empty'
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (!$validation) {
|
||||||
|
return $this->failValidationErrors($this->validator->getErrors());
|
||||||
|
}
|
||||||
|
|
||||||
|
$updateData = [
|
||||||
|
'title' => $this->request->getVar('title'),
|
||||||
|
'min_quantity' => $this->request->getVar('min_quantity') ?? 0,
|
||||||
|
'max_quantity' => $this->request->getVar('max_quantity') ?? 0,
|
||||||
|
'is_required' => $this->request->getVar('is_required'),
|
||||||
|
'status' => $this->request->getVar('status'),
|
||||||
|
'order_index' => $this->request->getVar('order_index') ?? 0,
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->option_groups->update($id, $updateData);
|
||||||
|
|
||||||
|
$options = $this->request->getVar('options') ?? [];
|
||||||
|
|
||||||
|
$exist_option = $this->options->where('option_group_id', $id)->findAll();
|
||||||
|
$exist_option_group = array_column($exist_option, 'id');
|
||||||
|
|
||||||
|
$update_option_group = [];
|
||||||
|
|
||||||
|
foreach ($options as $i => $opt) {
|
||||||
|
|
||||||
|
$title = is_array($opt) ? $opt['title'] ?? '' : $opt->title ?? '';
|
||||||
|
$price = is_array($opt) ? $opt['price_adjustment'] ?? 0 : $opt->price_adjustment ?? 0;
|
||||||
|
$order = is_array($opt) ? $opt['order_index'] ?? 0 : $opt->order_index ?? 0;
|
||||||
|
$optId = is_array($opt) ? $opt['id'] ?? null : $opt->id ?? null;
|
||||||
|
|
||||||
|
$optionData = [
|
||||||
|
'option_group_id' => $id,
|
||||||
|
'title' => $title,
|
||||||
|
'price_adjustment' => $price,
|
||||||
|
'order_index' => $order,
|
||||||
|
'images' => $opt['images'] ?? null,
|
||||||
|
'images_compressed' => $opt['images_compressed'] ?? null,
|
||||||
|
];
|
||||||
|
|
||||||
|
$imageUrl = null;
|
||||||
|
$compressedUrl = null;
|
||||||
|
|
||||||
|
$imageFile = $this->request->getFile("image$i");
|
||||||
|
|
||||||
|
if ($imageFile && $imageFile->isValid() && !$imageFile->hasMoved()) {
|
||||||
|
$result = save_image_with_compression(
|
||||||
|
$imageFile,
|
||||||
|
FCPATH . 'backend/uploads/options/',
|
||||||
|
FCPATH . 'backend/uploads/options_compressed/',
|
||||||
|
900,
|
||||||
|
80
|
||||||
|
);
|
||||||
|
|
||||||
|
$imageUrl = base_url('backend/uploads/options/' . basename($result['original']));
|
||||||
|
$compressedUrl = base_url('backend/uploads/options_compressed/' . basename($result['compressed']));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if ($imageUrl) {
|
||||||
|
$optionData['images'] = $imageUrl;
|
||||||
|
$optionData['images_compressed'] = $compressedUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isset($opt->id)) {
|
||||||
|
$this->options->insert($optionData);
|
||||||
|
} else {
|
||||||
|
$this->options->update($opt->id, $optionData);
|
||||||
|
$update_option_group[] = $opt->id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($exist_option_group as $option_id) {
|
||||||
|
if (!in_array($option_id, $update_option_group)) {
|
||||||
|
$this->options->delete($option_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->respond(['status' => 200, 'message' => 'Group updated.']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete($id = null)
|
||||||
|
{
|
||||||
|
$group = $this->option_groups->find($id);
|
||||||
|
|
||||||
|
if (!$group) {
|
||||||
|
return $this->failNotFound("Group not found.");
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->option_groups->delete($id);
|
||||||
|
$this->options->where('option_group_id', $id)->delete();
|
||||||
|
|
||||||
|
return $this->respond(['status' => 200, 'message' => 'Group and options deleted.']);
|
||||||
|
}
|
||||||
|
}
|
||||||
581
app/Controllers/Backend/OrderController.php
Normal file
581
app/Controllers/Backend/OrderController.php
Normal file
@ -0,0 +1,581 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controllers\Backend;
|
||||||
|
|
||||||
|
use CodeIgniter\HTTP\ResponseInterface;
|
||||||
|
use CodeIgniter\RESTful\ResourceController;
|
||||||
|
use App\Models\OrderItemOptions;
|
||||||
|
use App\Models\OrderItems;
|
||||||
|
use App\Models\OrderPayments;
|
||||||
|
use App\Models\Orders;
|
||||||
|
use App\Models\OrderTaxes;
|
||||||
|
use CodeIgniter\Database\Config;
|
||||||
|
use CodeIgniter\HTTP\Message;
|
||||||
|
use App\Models\OrderDeliveries;
|
||||||
|
use App\Libraries\Wato;
|
||||||
|
use App\Models\User;
|
||||||
|
use App\Models\MenuItemVariations;
|
||||||
|
|
||||||
|
class OrderController extends ResourceController
|
||||||
|
{
|
||||||
|
private $orders;
|
||||||
|
private $order_items;
|
||||||
|
private $order_item_options;
|
||||||
|
private $order_payments;
|
||||||
|
private $order_taxes;
|
||||||
|
private $order_deliveries;
|
||||||
|
private $db;
|
||||||
|
private $wato;
|
||||||
|
private $user;
|
||||||
|
private $menu_item_variations;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->orders = new Orders();
|
||||||
|
$this->order_items = new OrderItems();
|
||||||
|
$this->order_item_options = new OrderItemOptions();
|
||||||
|
$this->order_taxes = new OrderTaxes();
|
||||||
|
$this->order_payments = new OrderPayments();
|
||||||
|
$this->order_deliveries = new OrderDeliveries();
|
||||||
|
$this->db = Config::connect();
|
||||||
|
$this->wato = new Wato();
|
||||||
|
$this->user = new User();
|
||||||
|
$this->menu_item_variations = new MenuItemVariations();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function orderList()
|
||||||
|
{
|
||||||
|
$user_id = $this->request->getVar('user_id');
|
||||||
|
$start_date = $this->request->getVar('start_date');
|
||||||
|
$end_date = $this->request->getVar('end_date');
|
||||||
|
$status = $this->request->getVar('status');
|
||||||
|
$outlet_id = $this->request->getVar('outlet_id');
|
||||||
|
$order_type = $this->request->getVar('order_type');
|
||||||
|
|
||||||
|
// Get the user information to check role and outlet
|
||||||
|
$user = $this->user->find($user_id);
|
||||||
|
|
||||||
|
if (!$user) {
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 404,
|
||||||
|
'message' => 'User not found',
|
||||||
|
'data' => []
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$orderQuery = $this->orders
|
||||||
|
->orderBy('created_at', 'DESC');
|
||||||
|
|
||||||
|
// If user is not admin, filter by their outlet_id
|
||||||
|
if ($user['role'] !== 'admin') {
|
||||||
|
$orderQuery->where('outlet_id', $user['outlet_id']);
|
||||||
|
} else {
|
||||||
|
// If admin and specific outlet_id is provided, use it
|
||||||
|
if (!empty($outlet_id)) {
|
||||||
|
$orderQuery->where('outlet_id', $outlet_id);
|
||||||
|
}
|
||||||
|
// Otherwise admin sees all orders (no outlet filter)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($start_date)) {
|
||||||
|
$orderQuery->where('created_at >=', $start_date . ' 00:00:00');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($end_date)) {
|
||||||
|
$orderQuery->where('created_at <=', $end_date . ' 23:59:59');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($status)) {
|
||||||
|
$orderQuery->where('status', $status);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (!empty($outlet_id)) {
|
||||||
|
$orderQuery->where('outlet_id', $outlet_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($order_type)) {
|
||||||
|
$orderQuery->where('order_type', $order_type);
|
||||||
|
}
|
||||||
|
|
||||||
|
$orders = $orderQuery->findAll();
|
||||||
|
|
||||||
|
if (empty($orders)) {
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 200,
|
||||||
|
'message' => 'No orders found!',
|
||||||
|
'data' => []
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($orders as &$order) {
|
||||||
|
$order_id = $order['id'];
|
||||||
|
|
||||||
|
// Fetch items + options
|
||||||
|
$order['items'] = $this->order_items->where('order_id', $order_id)->findAll();
|
||||||
|
foreach ($order['items'] as &$item) {
|
||||||
|
$item['options'] = $this->order_item_options
|
||||||
|
->where('order_item_id', $item['id'])
|
||||||
|
->findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fetch taxes
|
||||||
|
$order['taxes'] = $this->order_taxes
|
||||||
|
->where('order_id', $order_id)
|
||||||
|
->findAll();
|
||||||
|
|
||||||
|
// Fetch payments
|
||||||
|
$order['payments'] = $this->order_payments
|
||||||
|
->where('order_id', $order_id)
|
||||||
|
->orderBy('created_at', 'DESC')
|
||||||
|
->findAll();
|
||||||
|
|
||||||
|
// Fetch deliveries
|
||||||
|
$order['deliveries'] = $this->order_deliveries
|
||||||
|
->where('order_id', $order_id)
|
||||||
|
->findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 200,
|
||||||
|
'message' => 'Orders retrieved successfully',
|
||||||
|
'data' => $orders
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function showOrder($order_id = null)
|
||||||
|
{
|
||||||
|
// Get order with customer + outlet info
|
||||||
|
$order = $this->orders
|
||||||
|
->select('
|
||||||
|
orders.*,
|
||||||
|
customers.id as customer_id,
|
||||||
|
customers.name as customer_name,
|
||||||
|
customers.email as customer_email,
|
||||||
|
customers.phone as customer_phone,
|
||||||
|
customers.profile_picture as customer_profile_pic,
|
||||||
|
outlets.id as outlet_id,
|
||||||
|
outlets.title as outlet_title,
|
||||||
|
outlets.email as outlet_email,
|
||||||
|
outlets.phone as outlet_phone,
|
||||||
|
outlets.address as outlet_address,
|
||||||
|
')
|
||||||
|
->join('customers', 'customers.id = orders.customer_id', 'left')
|
||||||
|
->join('outlets', 'outlets.id = orders.outlet_id', 'left') // join outlets
|
||||||
|
->where('orders.id', $order_id)
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if (!$order) {
|
||||||
|
return $this->fail('Order not found', 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Items + options + menu images
|
||||||
|
$order['items'] = $this->order_items
|
||||||
|
->select('order_items.*, menu_images.image_url as menu_item_image')
|
||||||
|
->join('menu_images', 'menu_images.menu_item_id = order_items.menu_item_id', 'left')
|
||||||
|
->where('order_items.order_id', $order_id)
|
||||||
|
->groupBy('order_items.id')
|
||||||
|
->findAll();
|
||||||
|
|
||||||
|
foreach ($order['items'] as &$item) {
|
||||||
|
$item['options'] = $this->order_item_options->where('order_item_id', $item['id'])->findAll();
|
||||||
|
$item['menu_item_image'] = getMenuImage($item['menu_item_id']);
|
||||||
|
|
||||||
|
$item['variation_name'] = $this->menu_item_variations
|
||||||
|
->where('menu_item_id', $item['menu_item_id'])
|
||||||
|
->where('id', $item['variation_id'])
|
||||||
|
->first()['title'] ?? '';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Taxes
|
||||||
|
$order['taxes'] = $this->order_taxes->where('order_id', $order_id)->findAll();
|
||||||
|
|
||||||
|
// Payments
|
||||||
|
$order['payments'] = $this->order_payments
|
||||||
|
->where('order_id', $order_id)
|
||||||
|
->orderBy('created_at', 'DESC')
|
||||||
|
->findAll();
|
||||||
|
|
||||||
|
// Deliveries
|
||||||
|
$order['deliveries'] = $this->order_deliveries->where('order_id', $order_id)->findAll();
|
||||||
|
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 200,
|
||||||
|
'message' => 'Order retrieved successfully',
|
||||||
|
'data' => $order
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function updateOrderSchedule($order_id = null)
|
||||||
|
{
|
||||||
|
// Validate order_id
|
||||||
|
if (empty($order_id)) {
|
||||||
|
return $this->fail('Order ID is required', 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the order
|
||||||
|
$order = $this->orders->find($order_id);
|
||||||
|
if (!$order) {
|
||||||
|
return $this->fail('Order not found', 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if order status is 'complete'
|
||||||
|
if (isset($order['status']) && $order['status'] === 'complete') {
|
||||||
|
return $this->fail('Cannot modify schedule for completed orders', 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get request data
|
||||||
|
$selected_date = $this->request->getVar('selected_date');
|
||||||
|
$selected_time = $this->request->getVar('selected_time');
|
||||||
|
|
||||||
|
// Validate input
|
||||||
|
if (empty($selected_date) || empty($selected_time)) {
|
||||||
|
return $this->fail('Both selected_date and selected_time are required', 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prepare data to update
|
||||||
|
$data = [
|
||||||
|
'selected_date' => $selected_date,
|
||||||
|
'selected_time' => $selected_time,
|
||||||
|
'updated_at' => date('Y-m-d H:i:s') // Update timestamp
|
||||||
|
];
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Update the order
|
||||||
|
$updated = $this->orders->update($order_id, $data);
|
||||||
|
|
||||||
|
if (!$updated) {
|
||||||
|
return $this->fail('Failed to update order schedule', 500);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the updated order
|
||||||
|
$updatedOrder = $this->orders->find($order_id);
|
||||||
|
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 200,
|
||||||
|
'message' => 'Order schedule updated successfully',
|
||||||
|
'data' => $updatedOrder
|
||||||
|
]);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->fail('An error occurred while updating order schedule: ' . $e->getMessage(), 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateOrderStatus($order_id = null)
|
||||||
|
{
|
||||||
|
// Validate order_id
|
||||||
|
if (empty($order_id)) {
|
||||||
|
return $this->fail('Order ID is required', 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the order
|
||||||
|
$order = $this->orders->select('orders.*, customer_addresses.phone as recipient_phone')
|
||||||
|
->join('customer_addresses', 'customer_addresses.id = orders.customer_address_id AND customer_addresses.deleted_at IS NULL', 'left')->find($order_id);
|
||||||
|
if (!$order) {
|
||||||
|
return $this->fail('Order not found', 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get request data
|
||||||
|
$status = $this->request->getVar('status');
|
||||||
|
|
||||||
|
// Validate input
|
||||||
|
if (empty($status)) {
|
||||||
|
return $this->fail('Status is required', 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Define allowed status values
|
||||||
|
$allowedStatuses = ['pending', 'picked_up', 'on_the_way', 'completed', 'ready_to_pickup'];
|
||||||
|
if (!in_array($status, $allowedStatuses)) {
|
||||||
|
return $this->fail('Invalid status value. Allowed values: ' . implode(', ', $allowedStatuses), 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prepare data to update
|
||||||
|
$data = [
|
||||||
|
'status' => $status,
|
||||||
|
'updated_at' => date('Y-m-d H:i:s') // Update timestamp
|
||||||
|
];
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Update the order
|
||||||
|
$updated = $this->orders->update($order_id, $data);
|
||||||
|
if ($order['status'] != $status) { //send notification to customer if status is changed
|
||||||
|
$message = '';
|
||||||
|
switch ($status) {
|
||||||
|
case 'ready_to_pickup':
|
||||||
|
$message = "🍴 Your food is ready for pickup!\nPlease show your order number at the counter: \n**{{" . $order['order_so'] . "}}**";
|
||||||
|
break;
|
||||||
|
case 'on_the_way':
|
||||||
|
$message = "🚚 Your order [**" . $order['order_so'] . "**] is on the way!\nThe driver is delivering your food now.\nPlease get ready to receive it.";
|
||||||
|
break;
|
||||||
|
case 'completed':
|
||||||
|
$message = "🎉 Your order [**" . $order['order_so'] . "**] has been completed.\nWe hope you enjoy your meal!\nThank you for ordering with us.";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($message) {
|
||||||
|
$this->wato->pushNotification($order['recipient_phone'], $message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$updated) {
|
||||||
|
return $this->fail('Failed to update order status', 500);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the updated order
|
||||||
|
$updatedOrder = $this->orders->find($order_id);
|
||||||
|
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 200,
|
||||||
|
'message' => 'Order status updated successfully',
|
||||||
|
'data' => $updatedOrder
|
||||||
|
]);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->fail('An error occurred while updating order status: ' . $e->getMessage(), 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createOrderDelivery()
|
||||||
|
{
|
||||||
|
// Get request data
|
||||||
|
$order_id = $this->request->getVar('order_id');
|
||||||
|
$fee_amount = $this->request->getVar('actual_fee_amount');
|
||||||
|
$tracking_link = $this->request->getVar('tracking_link');
|
||||||
|
|
||||||
|
// Optional fields that will be set to empty string if not provided
|
||||||
|
$provider_name = $this->request->getVar('provider_name') ?? '';
|
||||||
|
$provider_order_id = $this->request->getVar('provider_order_id') ?? '';
|
||||||
|
$actual_fee_amount = $this->request->getVar('fee_amount') ?? '';
|
||||||
|
$transaction_id = $this->request->getVar('transaction_id') ?? '';
|
||||||
|
|
||||||
|
// Validate required fields
|
||||||
|
if (empty($order_id) || empty($actual_fee_amount) || empty($tracking_link)) {
|
||||||
|
return $this->fail('order_id, actual_fee_amount, and tracking_link are required', 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the order exists
|
||||||
|
$order = $this->orders->find($order_id);
|
||||||
|
if (!$order) {
|
||||||
|
return $this->fail('Order not found', 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prepare data for insertion with empty strings for optional fields
|
||||||
|
$data = [
|
||||||
|
'order_id' => $order_id,
|
||||||
|
'provider_name' => $provider_name,
|
||||||
|
'status' => 'pending', // Default status
|
||||||
|
'provider_order_id' => $provider_order_id,
|
||||||
|
'fee_amount' => $fee_amount,
|
||||||
|
'actual_fee_amount' => $actual_fee_amount,
|
||||||
|
'transaction_id' => $transaction_id,
|
||||||
|
'tracking_link' => $tracking_link,
|
||||||
|
'created_at' => date('Y-m-d H:i:s'),
|
||||||
|
'updated_at' => date('Y-m-d H:i:s')
|
||||||
|
];
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Insert the data
|
||||||
|
$inserted = $this->order_deliveries->insert($data);
|
||||||
|
|
||||||
|
if (!$inserted) {
|
||||||
|
return $this->fail('Failed to create order delivery record', 500);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the inserted ID
|
||||||
|
$insertId = $this->db->insertID();
|
||||||
|
|
||||||
|
// Return success response with the created record
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 201,
|
||||||
|
'message' => 'Order delivery record created successfully',
|
||||||
|
'data' => array_merge(['id' => $insertId], $data)
|
||||||
|
], 201);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->fail('An error occurred while creating order delivery: ' . $e->getMessage(), 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateOrderDelivery($id = null)
|
||||||
|
{
|
||||||
|
if (empty($id)) {
|
||||||
|
return $this->fail('Delivery record ID is required', 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get request data - all fields optional except id
|
||||||
|
$data = [
|
||||||
|
'actual_fee_amount' => $this->request->getVar('actual_fee_amount') ?? '',
|
||||||
|
'tracking_link' => $this->request->getVar('tracking_link'),
|
||||||
|
'updated_at' => date('Y-m-d H:i:s')
|
||||||
|
];
|
||||||
|
|
||||||
|
// Remove fields that weren't provided in the request (except status which has a default)
|
||||||
|
$data = array_filter($data, function ($value, $key) {
|
||||||
|
return $value !== null || $key === 'status';
|
||||||
|
}, ARRAY_FILTER_USE_BOTH);
|
||||||
|
|
||||||
|
if (empty($data)) {
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 200,
|
||||||
|
'message' => 'No fields to update',
|
||||||
|
'data' => null
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$updated = $this->order_deliveries->update($id, $data);
|
||||||
|
|
||||||
|
if (!$updated) {
|
||||||
|
return $this->fail('Failed to update order delivery record', 500);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the updated record
|
||||||
|
$updatedData = $this->order_deliveries->find($id);
|
||||||
|
|
||||||
|
// Convert NULL values to empty strings in the response
|
||||||
|
$responseData = [
|
||||||
|
'id' => $id,
|
||||||
|
'order_id' => $updatedData['order_id'],
|
||||||
|
'provider_name' => $updatedData['provider_name'] ?? '',
|
||||||
|
'status' => $updatedData['status'] ?? '',
|
||||||
|
'provider_order_id' => $updatedData['provider_order_id'] ?? '',
|
||||||
|
'fee_amount' => $updatedData['fee_amount'] ?? '',
|
||||||
|
'actual_fee_amount' => $updatedData['actual_fee_amount'],
|
||||||
|
'transaction_id' => $updatedData['transaction_id'] ?? '',
|
||||||
|
'tracking_link' => $updatedData['tracking_link'],
|
||||||
|
'created_at' => $updatedData['created_at'],
|
||||||
|
'updated_at' => $updatedData['updated_at']
|
||||||
|
];
|
||||||
|
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 200,
|
||||||
|
'message' => 'Order delivery updated successfully',
|
||||||
|
'data' => $responseData
|
||||||
|
]);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->fail('An error occurred while updating order delivery: ' . $e->getMessage(), 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getOrderDelivery($order_id = null)
|
||||||
|
{
|
||||||
|
// Validate order_id
|
||||||
|
if (empty($order_id)) {
|
||||||
|
return $this->fail('Order ID is required', 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Get delivery record by order_id
|
||||||
|
$delivery = $this->order_deliveries->where('order_id', $order_id)->get()->getRowArray();
|
||||||
|
|
||||||
|
if (!$delivery) {
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 404,
|
||||||
|
'message' => 'No delivery record found for this order',
|
||||||
|
'data' => null
|
||||||
|
], 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Format the response data with empty strings instead of NULL
|
||||||
|
$responseData = [
|
||||||
|
'id' => $delivery['id'],
|
||||||
|
'order_id' => $delivery['order_id'],
|
||||||
|
'provider_name' => $delivery['provider_name'] ?? '',
|
||||||
|
'status' => $delivery['status'] ?? '',
|
||||||
|
'provider_order_id' => $delivery['provider_order_id'] ?? '',
|
||||||
|
'fee_amount' => $delivery['fee_amount'] ?? '',
|
||||||
|
'actual_fee_amount' => $delivery['actual_fee_amount'],
|
||||||
|
'transaction_id' => $delivery['transaction_id'] ?? '',
|
||||||
|
'tracking_link' => $delivery['tracking_link'],
|
||||||
|
'created_at' => $delivery['created_at'],
|
||||||
|
'updated_at' => $delivery['updated_at']
|
||||||
|
];
|
||||||
|
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 200,
|
||||||
|
'message' => 'Order delivery retrieved successfully',
|
||||||
|
'data' => $responseData
|
||||||
|
]);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->fail('An error occurred while fetching order delivery: ' . $e->getMessage(), 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function customerOrderList()
|
||||||
|
{
|
||||||
|
$start_date = $this->request->getVar('start_date');
|
||||||
|
$end_date = $this->request->getVar('end_date');
|
||||||
|
$status = $this->request->getVar('status');
|
||||||
|
$outlet_id = $this->request->getVar('outlet_id');
|
||||||
|
$order_type = $this->request->getVar('order_type');
|
||||||
|
|
||||||
|
$orderQuery = $this->orders
|
||||||
|
->orderBy('created_at', 'DESC');
|
||||||
|
|
||||||
|
|
||||||
|
if (!empty($start_date)) {
|
||||||
|
$orderQuery->where('created_at >=', $start_date . ' 00:00:00');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($end_date)) {
|
||||||
|
$orderQuery->where('created_at <=', $end_date . ' 23:59:59');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($status)) {
|
||||||
|
$orderQuery->where('status', $status);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (!empty($outlet_id)) {
|
||||||
|
$orderQuery->where('outlet_id', $outlet_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($order_type)) {
|
||||||
|
$orderQuery->where('order_type', $order_type);
|
||||||
|
}
|
||||||
|
|
||||||
|
$orders = $orderQuery->findAll();
|
||||||
|
|
||||||
|
if (empty($orders)) {
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 200,
|
||||||
|
'message' => 'No orders found!',
|
||||||
|
'data' => []
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($orders as &$order) {
|
||||||
|
$order_id = $order['id'];
|
||||||
|
|
||||||
|
// Fetch items + options
|
||||||
|
$order['items'] = $this->order_items->where('order_id', $order_id)->findAll();
|
||||||
|
foreach ($order['items'] as &$item) {
|
||||||
|
$item['options'] = $this->order_item_options
|
||||||
|
->where('order_item_id', $item['id'])
|
||||||
|
->findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fetch taxes
|
||||||
|
$order['taxes'] = $this->order_taxes
|
||||||
|
->where('order_id', $order_id)
|
||||||
|
->findAll();
|
||||||
|
|
||||||
|
// Fetch payments
|
||||||
|
$order['payments'] = $this->order_payments
|
||||||
|
->where('order_id', $order_id)
|
||||||
|
->orderBy('created_at', 'DESC')
|
||||||
|
->findAll();
|
||||||
|
|
||||||
|
// Fetch deliveries
|
||||||
|
$order['deliveries'] = $this->order_deliveries
|
||||||
|
->where('order_id', $order_id)
|
||||||
|
->findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 200,
|
||||||
|
'message' => 'Orders retrieved successfully',
|
||||||
|
'data' => $orders
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
863
app/Controllers/Backend/OutletController.php
Normal file
863
app/Controllers/Backend/OutletController.php
Normal file
@ -0,0 +1,863 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controllers\Backend;
|
||||||
|
|
||||||
|
use CodeIgniter\HTTP\ResponseInterface;
|
||||||
|
use CodeIgniter\RESTful\ResourceController;
|
||||||
|
|
||||||
|
use App\Models\Outlet;
|
||||||
|
use App\Models\OutletTax;
|
||||||
|
use App\Models\OutletImage;
|
||||||
|
use App\Models\OutletOperatingDay;
|
||||||
|
use App\Models\OutletOperatingHour;
|
||||||
|
use App\Models\OutletOperatingHoursException;
|
||||||
|
use App\Models\SettingTax;
|
||||||
|
use App\Models\OutletMenus;
|
||||||
|
use App\Models\MenuItems;
|
||||||
|
use App\Models\User;
|
||||||
|
|
||||||
|
helper('image');
|
||||||
|
|
||||||
|
|
||||||
|
class OutletController extends ResourceController
|
||||||
|
{
|
||||||
|
|
||||||
|
private $outlet;
|
||||||
|
private $outletTax;
|
||||||
|
private $outletImage;
|
||||||
|
private $outletOperatingDays;
|
||||||
|
private $outletOperatingHours;
|
||||||
|
private $outletOperatingHoursExceptions;
|
||||||
|
private $settingTax;
|
||||||
|
private $outlet_menu;
|
||||||
|
private $menu_items;
|
||||||
|
private $user;
|
||||||
|
protected $db;
|
||||||
|
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->outlet = new Outlet();
|
||||||
|
$this->outletTax = new OutletTax();
|
||||||
|
$this->outletImage = new OutletImage();
|
||||||
|
$this->outletOperatingDays = new OutletOperatingDay();
|
||||||
|
$this->outletOperatingHours = new OutletOperatingHour();
|
||||||
|
$this->outletOperatingHoursExceptions = new OutletOperatingHoursException();
|
||||||
|
$this->settingTax = new SettingTax();
|
||||||
|
$this->db = \Config\Database::connect();
|
||||||
|
$this->outlet_menu = new OutletMenus();
|
||||||
|
$this->menu_items = new MenuItems();
|
||||||
|
$this->user = new User();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
$user_id = $this->request->getVar('user_id');
|
||||||
|
|
||||||
|
if(!empty($user_id)){
|
||||||
|
|
||||||
|
$user = $this->user->find($user_id);
|
||||||
|
if($user['role'] == 'outlet'){
|
||||||
|
$outlets = $this->outlet->getOperatingHoursWithDaysList($user['outlet_id']);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
$outlets = $this->outlet->getOperatingHoursWithDaysList();
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return $this->respond (['status' => 400, 'result'=> 'User Id is required.']);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if(empty($outlets)){
|
||||||
|
return $this->respond(['status' => 400, 'result' => 'No outlet data found.']);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->respond(['status' => 200, 'result' => $outlets]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function show($id = null)
|
||||||
|
{
|
||||||
|
$outlet = $this->outlet->getOperatingHoursWithDays($id);
|
||||||
|
|
||||||
|
if(empty($outlet)){
|
||||||
|
return $this->respond(['status' => 400, 'result' => 'No outlet data found.']);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->respond(['status' => 200, 'result' => $outlet]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function create()
|
||||||
|
{
|
||||||
|
$validationRules = [
|
||||||
|
'title' => 'required',
|
||||||
|
'email' => 'required',
|
||||||
|
'phone' => 'required',
|
||||||
|
'address' => 'required',
|
||||||
|
'state' => 'required',
|
||||||
|
'postal_code' => 'required',
|
||||||
|
'country' => 'required',
|
||||||
|
'latitude' => 'required|numeric',
|
||||||
|
'longitude' => 'required|numeric',
|
||||||
|
'password' => 'required|min_length[8]',
|
||||||
|
'outlet_delivery_coverage' => 'required|numeric',
|
||||||
|
'outlet_tax' => 'permit_empty',
|
||||||
|
'outlet_operating_days' => 'permit_empty',
|
||||||
|
'outlet_operating_hours' => 'permit_empty',
|
||||||
|
'outlet_operating_hours_exceptions' => 'permit_empty',
|
||||||
|
];
|
||||||
|
|
||||||
|
$validation = $this->validate($validationRules);
|
||||||
|
|
||||||
|
if (!$validation) {
|
||||||
|
return $this->failValidationErrors($this->validator->getErrors());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start database transaction
|
||||||
|
$this->db->transBegin();
|
||||||
|
|
||||||
|
try {
|
||||||
|
$outletData = [
|
||||||
|
"title" => $this->request->getVar('title'),
|
||||||
|
"email" => $this->request->getVar('email'),
|
||||||
|
"phone" => $this->request->getVar('phone'),
|
||||||
|
"address" => $this->request->getVar('address'),
|
||||||
|
"state" => $this->request->getVar('state'),
|
||||||
|
"postal_code" => $this->request->getVar('postal_code'),
|
||||||
|
"country" => $this->request->getVar('country'),
|
||||||
|
"status" => $this->request->getVar('status'),
|
||||||
|
"latitude" => $this->request->getVar('latitude'),
|
||||||
|
"longitude" => $this->request->getVar('longitude'),
|
||||||
|
"password" => md5(md5($this->request->getVar('password'))),
|
||||||
|
"serve_method" => $this->request->getVar('serve_method'),
|
||||||
|
"delivery_options" => $this->request->getVar('delivery_options'),
|
||||||
|
"outlet_delivery_coverage" => $this->request->getVar('outlet_delivery_coverage'),
|
||||||
|
"order_max_per_hour" => $this->request->getVar('order_max_per_hour'),
|
||||||
|
"item_max_per_hour" => $this->request->getVar('item_max_per_hour'),
|
||||||
|
"menu_item" => json_encode($this->request->getVar('outlet_menu')),
|
||||||
|
];
|
||||||
|
|
||||||
|
$id = $this->outlet->insert($outletData);
|
||||||
|
if (!$id) {
|
||||||
|
throw new \RuntimeException('Failed to insert outlet data');
|
||||||
|
}
|
||||||
|
|
||||||
|
$outlet_menu = $this->request->getVar('outlet_menu');
|
||||||
|
if(!empty($outlet_menu)){
|
||||||
|
foreach($outlet_menu as $menu){
|
||||||
|
|
||||||
|
$outletMenuItem = [
|
||||||
|
"outlet_id" => $id,
|
||||||
|
"menu_item_id" => $menu,
|
||||||
|
];
|
||||||
|
if (!$this->outlet_menu->insert($outletMenuItem)) {
|
||||||
|
throw new \RuntimeException('Failed to insert outlet tax data');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Process taxes
|
||||||
|
$tax_ids = $this->request->getVar('outlet_tax');
|
||||||
|
if(!empty($tax_ids)){
|
||||||
|
foreach ($tax_ids as $tax_id) {
|
||||||
|
$outletTaxData = [
|
||||||
|
"outlet_id" => $id,
|
||||||
|
"tax_id" => $tax_id,
|
||||||
|
];
|
||||||
|
if (!$this->outletTax->insert($outletTaxData)) {
|
||||||
|
throw new \RuntimeException('Failed to insert outlet tax data');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Process images
|
||||||
|
$images = $this->request->getFiles('outlet_images');
|
||||||
|
$outlet_images = [];
|
||||||
|
|
||||||
|
if (!empty($images['outlet_images'])) {
|
||||||
|
foreach ($images['outlet_images'] as $index => $image) {
|
||||||
|
if (empty($image) || !$image->isValid() || $image->hasMoved()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$result = save_image_with_compression(
|
||||||
|
$image,
|
||||||
|
FCPATH . 'backend/uploads/outlets',
|
||||||
|
FCPATH . 'backend/uploads/outlets_compressed',
|
||||||
|
900, // width
|
||||||
|
80 // quality
|
||||||
|
);
|
||||||
|
|
||||||
|
$originalFileName = basename($result['original']);
|
||||||
|
$compressedFileName = basename($result['compressed']);
|
||||||
|
|
||||||
|
if (!$this->outletImage->insert([
|
||||||
|
"outlet_id" => $id,
|
||||||
|
"image_url" => $originalFileName,
|
||||||
|
"compressed_image_url" => $compressedFileName,
|
||||||
|
"order_index" => $index
|
||||||
|
])) {
|
||||||
|
@unlink($result['original']);
|
||||||
|
@unlink($result['compressed']);
|
||||||
|
throw new \RuntimeException('Failed to insert outlet image data');
|
||||||
|
}
|
||||||
|
|
||||||
|
$outlet_images[$index] = [
|
||||||
|
'image_url' => $originalFileName,
|
||||||
|
'compressed_image_url' => $compressedFileName,
|
||||||
|
];
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
log_message('error', 'Failed to upload and compress image: ' . $e->getMessage());
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Process operating days
|
||||||
|
$outlet_operating_days = json_decode($this->request->getVar('outlet_operating_days'), true);
|
||||||
|
$operating_days = [];
|
||||||
|
// print_r($this->request->getVar('outlet_operating_days'));exit;
|
||||||
|
if(!empty($outlet_operating_days[0])){
|
||||||
|
foreach ($outlet_operating_days[0] as $index => $day) {
|
||||||
|
$day_id = $this->outletOperatingDays->insert([
|
||||||
|
"outlet_id" => $id,
|
||||||
|
"day_of_week" => $index,
|
||||||
|
"is_operated" => $day['is_operated'],
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (!$day_id) {
|
||||||
|
throw new \RuntimeException('Failed to insert operating days data');
|
||||||
|
}
|
||||||
|
|
||||||
|
$operating_days[$index] = [
|
||||||
|
'id' => $day_id,
|
||||||
|
"outlet_id" => $id,
|
||||||
|
"day_of_week" => $index,
|
||||||
|
"is_operated" => $day['is_operated'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Process operating hours
|
||||||
|
$outlet_operating_hours = json_decode($this->request->getVar('outlet_operating_hours'), true);
|
||||||
|
$operating_hours = [];
|
||||||
|
if(!empty($outlet_operating_hours[0])){
|
||||||
|
foreach ($outlet_operating_hours[0] as $index => $hours) {
|
||||||
|
foreach ($hours as $hour) {
|
||||||
|
$hour_id = $this->outletOperatingHours->insert([
|
||||||
|
"outlet_id" => $id,
|
||||||
|
"day_of_week" => $index,
|
||||||
|
"start_time" => $hour['start_time'],
|
||||||
|
"end_time" => $hour['end_time'],
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (!$hour_id) {
|
||||||
|
throw new \RuntimeException('Failed to insert operating hours data');
|
||||||
|
}
|
||||||
|
|
||||||
|
$operating_hours[$index][] = [
|
||||||
|
'id' => $hour_id,
|
||||||
|
"outlet_id" => $id,
|
||||||
|
"day_of_week" => $index,
|
||||||
|
"start_time" => $hour['start_time'],
|
||||||
|
"end_time" => $hour['end_time'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Process operating hours exceptions
|
||||||
|
$outlet_operating_hours_exceptions = json_decode($this->request->getVar('outlet_operating_hours_exceptions'), true);
|
||||||
|
$operating_hours_exceptions = [];
|
||||||
|
|
||||||
|
if (!empty($outlet_operating_hours_exceptions)) {
|
||||||
|
foreach ($outlet_operating_hours_exceptions as $index => $exception) {
|
||||||
|
$hours_exception_id = $this->outletOperatingHoursExceptions->insert([
|
||||||
|
"outlet_id" => $id,
|
||||||
|
"date" => $exception['date'],
|
||||||
|
"start_time" => $exception['start_time'],
|
||||||
|
"end_time" => $exception['end_time'],
|
||||||
|
"notes" => $exception['notes'],
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (!$hours_exception_id) {
|
||||||
|
throw new \RuntimeException('Failed to insert operating hours exceptions data');
|
||||||
|
}
|
||||||
|
|
||||||
|
$operating_hours_exceptions[$index] = [
|
||||||
|
'id' => $hours_exception_id,
|
||||||
|
"outlet_id" => $id,
|
||||||
|
"date" => $exception['date'],
|
||||||
|
"start_time" => $exception['start_time'],
|
||||||
|
"end_time" => $exception['end_time'],
|
||||||
|
"notes" => $exception['notes'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Commit transaction if everything succeeded
|
||||||
|
$this->db->transCommit();
|
||||||
|
|
||||||
|
$result = [
|
||||||
|
'id' => $id,
|
||||||
|
'title' => $this->request->getVar('title'),
|
||||||
|
'email' => $this->request->getVar('email'),
|
||||||
|
'phone' => $this->request->getVar('phone'),
|
||||||
|
'address' => $this->request->getVar('address'),
|
||||||
|
'state' => $this->request->getVar('state'),
|
||||||
|
'postal_code' => $this->request->getVar('postal_code'),
|
||||||
|
'country' => $this->request->getVar('country'),
|
||||||
|
'status' => $this->request->getVar('status'),
|
||||||
|
'latitude' => $this->request->getVar('latitude'),
|
||||||
|
'longitude' => $this->request->getVar('longitude'),
|
||||||
|
'password' => md5(md5($this->request->getVar('password'))),
|
||||||
|
'serve_method' => $this->request->getVar('serve_method'),
|
||||||
|
'delivery_options' => $this->request->getVar('delivery_options'),
|
||||||
|
'outlet_delivery_coverage' => $this->request->getVar('outlet_delivery_coverage'),
|
||||||
|
'order_max_per_hour' => $this->request->getVar('order_max_per_hour'),
|
||||||
|
'item_max_per_hour' => $this->request->getVar('item_max_per_hour'),
|
||||||
|
'outlet_tax' => $tax_ids,
|
||||||
|
'outlet_images' => $outlet_images,
|
||||||
|
'outlet_operating_days' => $operating_days,
|
||||||
|
'outlet_operating_hours' => $operating_hours,
|
||||||
|
'outlet_operating_hours_exceptions' => $operating_hours_exceptions ?? [],
|
||||||
|
'menu_item' => $this->request->getVar('outlet_menu'),
|
||||||
|
];
|
||||||
|
|
||||||
|
return $this->respond(['status' => 200, 'result' => $result]);
|
||||||
|
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
// Rollback transaction on any error
|
||||||
|
$this->db->transRollback();
|
||||||
|
|
||||||
|
// Clean up any uploaded files if transaction fails
|
||||||
|
if (!empty($outlet_images)) {
|
||||||
|
$uploadPath = $_SERVER['DOCUMENT_ROOT'] . '/backend/uploads/outlets/';
|
||||||
|
foreach ($outlet_images as $image) {
|
||||||
|
@unlink($uploadPath . $image);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
log_message('error', 'Outlet creation failed: ' . $e->getMessage());
|
||||||
|
return $this->failServerError('Failed to create outlet: ' . $e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update($id = null)
|
||||||
|
{
|
||||||
|
$outlet = $this->outlet->find($id);
|
||||||
|
|
||||||
|
if (empty($outlet)) {
|
||||||
|
return $this->respond(['status' => 400, 'result' => 'No outlet data found.']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$validationRules = [
|
||||||
|
'title' => 'required',
|
||||||
|
'email' => 'required',
|
||||||
|
'phone' => 'required',
|
||||||
|
'address' => 'required',
|
||||||
|
'state' => 'required',
|
||||||
|
'postal_code' => 'required',
|
||||||
|
'country' => 'required',
|
||||||
|
'latitude' => 'required|numeric',
|
||||||
|
'longitude' => 'required|numeric',
|
||||||
|
'outlet_delivery_coverage' => 'required|numeric',
|
||||||
|
'outlet_tax' => 'permit_empty',
|
||||||
|
'outlet_operating_days' => 'permit_empty',
|
||||||
|
'outlet_operating_hours' => 'permit_empty',
|
||||||
|
'outlet_operating_hours_exceptions' => 'permit_empty',
|
||||||
|
'outlet_images' => 'permit_empty'
|
||||||
|
];
|
||||||
|
|
||||||
|
// Get all input data
|
||||||
|
$input = $this->request->getVar();
|
||||||
|
|
||||||
|
// Decode only the JSON fields
|
||||||
|
$jsonFields = [
|
||||||
|
'outlet_tax',
|
||||||
|
'outlet_operating_days',
|
||||||
|
'outlet_operating_hours',
|
||||||
|
'outlet_operating_hours_exceptions'
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($jsonFields as $field) {
|
||||||
|
if (isset($input[$field]) && is_string($input[$field])) {
|
||||||
|
$input[$field] = json_decode($input[$field], true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$this->validateData($input, $validationRules)) {
|
||||||
|
return $this->failValidationErrors($this->validator->getErrors());
|
||||||
|
}
|
||||||
|
|
||||||
|
$outlet = $this->outlet->find($id);
|
||||||
|
|
||||||
|
if(empty($outlet)){
|
||||||
|
return $this->respond(['status' => 400, 'result' => 'No outlet data found.']);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prepare outlet data
|
||||||
|
$outlet_data = ['id' => $id];
|
||||||
|
$fields = [
|
||||||
|
'title', 'email', 'phone', 'address', 'state', 'postal_code', 'country',
|
||||||
|
'status', 'latitude', 'longitude', 'serve_method', 'delivery_options',
|
||||||
|
'outlet_delivery_coverage', 'order_max_per_hour', 'item_max_per_hour'
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($fields as $field) {
|
||||||
|
if (isset($input[$field])) {
|
||||||
|
$outlet_data[$field] = $input[$field];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($input['password']) && $input['password'] != 'null' && $input['password'] != '' && $input['password'] != 'undefined') {
|
||||||
|
$outlet_data['password'] = md5(md5($input['password']));
|
||||||
|
} else {
|
||||||
|
$outlet_data['password'] = $outlet['password'];
|
||||||
|
}
|
||||||
|
// print_r($outlet_data);exit;
|
||||||
|
// Start transaction
|
||||||
|
$this->db->transBegin();
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Update main outlet data
|
||||||
|
$response = $this->outlet->save($outlet_data);
|
||||||
|
if (!$response) {
|
||||||
|
throw new \Exception('Failed to update outlet');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle outlet taxes
|
||||||
|
if (isset($input['outlet_tax']) && is_array($input['outlet_tax'])) {
|
||||||
|
$existingTaxes = $this->outletTax->where('outlet_id', $id)
|
||||||
|
->where('deleted_at', null)
|
||||||
|
->findAll();
|
||||||
|
$existingTaxIds = array_column($existingTaxes, 'tax_id', 'id');
|
||||||
|
|
||||||
|
$updatedTaxIds = [];
|
||||||
|
foreach ($input['outlet_tax'] as $tax) {
|
||||||
|
$taxData = [
|
||||||
|
'outlet_id' => $id,
|
||||||
|
'tax_id' => $tax['tax_id'],
|
||||||
|
'updated_at' => date('Y-m-d H:i:s')
|
||||||
|
];
|
||||||
|
|
||||||
|
$taxId = array_search($tax['tax_id'], $existingTaxIds);
|
||||||
|
if ($taxId !== false) {
|
||||||
|
$taxData['id'] = $taxId;
|
||||||
|
$this->outletTax->save($taxData);
|
||||||
|
$updatedTaxIds[] = $taxId;
|
||||||
|
} else {
|
||||||
|
$taxData['created_at'] = date('Y-m-d H:i:s');
|
||||||
|
$newId = $this->outletTax->insert($taxData);
|
||||||
|
$updatedTaxIds[] = $newId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Soft delete removed taxes
|
||||||
|
foreach ($existingTaxes as $existingTax) {
|
||||||
|
if (!in_array($existingTax['id'], $updatedTaxIds)) {
|
||||||
|
$this->outletTax->where('id', $existingTax['id'])
|
||||||
|
->set(['deleted_at' => date('Y-m-d H:i:s')])
|
||||||
|
->update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$images = $this->request->getFiles();
|
||||||
|
|
||||||
|
if (!empty($images['outlet_images'])) {
|
||||||
|
$images = $images['outlet_images'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$existing_image = $this->request->getVar("existing_image");
|
||||||
|
|
||||||
|
if (!empty($images)) {
|
||||||
|
$exist_images = $this->outletImage->where('outlet_id', $id)->findAll();
|
||||||
|
$exist_images_group = array_column($exist_images, 'id');
|
||||||
|
|
||||||
|
foreach ($images as $image_file) {
|
||||||
|
if ($image_file && $image_file->isValid() && !$image_file->hasMoved()) {
|
||||||
|
$result = save_image_with_compression(
|
||||||
|
$image_file,
|
||||||
|
FCPATH . 'backend/uploads/outlets',
|
||||||
|
FCPATH . 'backend/uploads/outlets_compressed',
|
||||||
|
900, // width
|
||||||
|
80 // quality
|
||||||
|
);
|
||||||
|
|
||||||
|
$originalFileName = basename($result['original']);
|
||||||
|
$compressedFileName = basename($result['compressed']);
|
||||||
|
|
||||||
|
if (!$this->outletImage->insert([
|
||||||
|
'outlet_id' => $id,
|
||||||
|
'image_url' => $originalFileName,
|
||||||
|
'compressed_image_url' => $compressedFileName
|
||||||
|
])) {
|
||||||
|
throw new \Exception('Failed to update image!');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (!empty($existing_image)) {
|
||||||
|
foreach ($exist_images_group as $image_id) {
|
||||||
|
if (!in_array($image_id, $existing_image)) {
|
||||||
|
$this->outletImage->delete($image_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Handle operating days
|
||||||
|
if (isset($input['outlet_operating_days']) && is_array($input['outlet_operating_days'])) {
|
||||||
|
$operatingDays = $input['outlet_operating_days'][0];
|
||||||
|
$existingDays = $this->outletOperatingDays
|
||||||
|
->where('outlet_id', $id)
|
||||||
|
->findAll();
|
||||||
|
$existingDayMap = [];
|
||||||
|
foreach ($existingDays as $day) {
|
||||||
|
$existingDayMap[$day['day_of_week']] = $day;
|
||||||
|
}
|
||||||
|
|
||||||
|
$updatedDays = [];
|
||||||
|
foreach ($operatingDays as $dayName => $dayData) {
|
||||||
|
|
||||||
|
|
||||||
|
$dayOfWeek = ucfirst(strtolower($dayName));
|
||||||
|
$dayRecord = [
|
||||||
|
'outlet_id' => $id,
|
||||||
|
'day_of_week' => $dayOfWeek,
|
||||||
|
'is_operated' => $dayData['is_operated'],
|
||||||
|
'updated_at' => date('Y-m-d H:i:s')
|
||||||
|
];
|
||||||
|
|
||||||
|
if (isset($existingDayMap[$dayOfWeek])) {
|
||||||
|
$dayRecord['id'] = $existingDayMap[$dayOfWeek]['id'];
|
||||||
|
$this->outletOperatingDays->save($dayRecord);
|
||||||
|
$updatedDays[] = $dayOfWeek;
|
||||||
|
} else {
|
||||||
|
$dayRecord['created_at'] = date('Y-m-d H:i:s');
|
||||||
|
$this->outletOperatingDays->insert($dayRecord);
|
||||||
|
$updatedDays[] = $dayOfWeek;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Soft delete removed days
|
||||||
|
foreach ($existingDays as $day) {
|
||||||
|
if (!in_array($day['day_of_week'], $updatedDays)) {
|
||||||
|
$this->outletOperatingDays->where('id', $day['id'])
|
||||||
|
->set(['deleted_at' => date('Y-m-d H:i:s')])
|
||||||
|
->update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle operating hours
|
||||||
|
if (isset($input['outlet_operating_hours']) && is_array($input['outlet_operating_hours'])) {
|
||||||
|
$operatingHours = $input['outlet_operating_hours'][0];
|
||||||
|
$existingHours = $this->outletOperatingHours
|
||||||
|
->where('outlet_id', $id)
|
||||||
|
->findAll();
|
||||||
|
|
||||||
|
$existingHoursByDay = [];
|
||||||
|
foreach ($existingHours as $hour) {
|
||||||
|
$existingHoursByDay[$hour['day_of_week']][] = $hour;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($operatingHours as $dayName => $timeSlots) {
|
||||||
|
$dayOfWeek = ucfirst(strtolower($dayName));
|
||||||
|
$updatedHourIds = [];
|
||||||
|
|
||||||
|
if (!empty($timeSlots)) {
|
||||||
|
foreach ($timeSlots as $slot) {
|
||||||
|
$hourRecord = [
|
||||||
|
'outlet_id' => $id,
|
||||||
|
'day_of_week' => $dayOfWeek,
|
||||||
|
'start_time' => $slot['start_time'],
|
||||||
|
'end_time' => $slot['end_time'],
|
||||||
|
'updated_at' => date('Y-m-d H:i:s')
|
||||||
|
];
|
||||||
|
|
||||||
|
$found = false;
|
||||||
|
if (isset($existingHoursByDay[$dayOfWeek])) {
|
||||||
|
foreach ($existingHoursByDay[$dayOfWeek] as $existingHour) {
|
||||||
|
if ($existingHour['start_time'] == $slot['start_time'] &&
|
||||||
|
$existingHour['end_time'] == $slot['end_time']) {
|
||||||
|
$hourRecord['id'] = $existingHour['id'];
|
||||||
|
$this->outletOperatingHours->save($hourRecord);
|
||||||
|
$updatedHourIds[] = $existingHour['id'];
|
||||||
|
$found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$found) {
|
||||||
|
$hourRecord['created_at'] = date('Y-m-d H:i:s');
|
||||||
|
$newId = $this->outletOperatingHours->insert($hourRecord);
|
||||||
|
$updatedHourIds[] = $newId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Soft delete removed hours
|
||||||
|
if (isset($existingHoursByDay[$dayOfWeek])) {
|
||||||
|
foreach ($existingHoursByDay[$dayOfWeek] as $existingHour) {
|
||||||
|
if (!in_array($existingHour['id'], $updatedHourIds)) {
|
||||||
|
$this->outletOperatingHours
|
||||||
|
->where('id', $existingHour['id'])
|
||||||
|
->set(['deleted_at' => date('Y-m-d H:i:s')])
|
||||||
|
->update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle outlet menu items
|
||||||
|
// print_r($input);exit;
|
||||||
|
// print_r($input['outlet_menu']);exit;
|
||||||
|
if (isset($input['outlet_menu']) && is_array($input['outlet_menu'])) {
|
||||||
|
// Filter out empty values (including 0 and '')
|
||||||
|
$filteredMenuIds = array_filter($input['outlet_menu'], function($menuId) {
|
||||||
|
return $menuId !== '' && $menuId !== null && $menuId !== 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!empty($filteredMenuIds)) {
|
||||||
|
// Fetch existing menu items
|
||||||
|
$existingMenu = $this->outlet_menu
|
||||||
|
->where('outlet_id', $id)
|
||||||
|
->where('deleted_at', null)
|
||||||
|
->findAll();
|
||||||
|
|
||||||
|
$existingMenuIds = array_column($existingMenu, 'menu_item_id', 'id');
|
||||||
|
$updatedMenuIds = [];
|
||||||
|
|
||||||
|
foreach ($filteredMenuIds as $menuId) {
|
||||||
|
if (in_array($menuId, $existingMenuIds)) {
|
||||||
|
$updatedMenuIds[] = $menuId;
|
||||||
|
} else {
|
||||||
|
$newId = $this->outlet_menu->insert([
|
||||||
|
'outlet_id' => $id,
|
||||||
|
'menu_item_id' => $menuId,
|
||||||
|
]);
|
||||||
|
$updatedMenuIds[] = $newId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete unused menu items
|
||||||
|
foreach ($existingMenu as $existing) {
|
||||||
|
if (!in_array($existing['menu_item_id'], $updatedMenuIds)) {
|
||||||
|
$this->outlet_menu
|
||||||
|
->where('menu_item_id', $existing['menu_item_id'])
|
||||||
|
->where('outlet_id', $id)
|
||||||
|
->where('deleted_at', null)
|
||||||
|
->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Delete ALL menu items if array is empty after filtering
|
||||||
|
$this->outlet_menu
|
||||||
|
->where('outlet_id', $id)
|
||||||
|
->where('deleted_at', null)
|
||||||
|
->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Handle operating hours exceptions
|
||||||
|
if (isset($input['outlet_operating_hours_exceptions']) && is_array($input['outlet_operating_hours_exceptions'])) {
|
||||||
|
$existingExceptions = $this->outletOperatingHoursExceptions
|
||||||
|
->where('outlet_id', $id)
|
||||||
|
->where('deleted_at', null)
|
||||||
|
->findAll();
|
||||||
|
|
||||||
|
$existingExceptionKeys = [];
|
||||||
|
foreach ($existingExceptions as $ex) {
|
||||||
|
$key = $ex['date'].'|'.$ex['start_time'].'|'.$ex['end_time'];
|
||||||
|
$existingExceptionKeys[$key] = $ex['id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$updatedExceptionIds = [];
|
||||||
|
foreach ($input['outlet_operating_hours_exceptions'] as $exception) {
|
||||||
|
$exceptionData = [
|
||||||
|
'outlet_id' => $id,
|
||||||
|
'date' => $exception['date'],
|
||||||
|
'start_time' => $exception['start_time'],
|
||||||
|
'end_time' => $exception['end_time'],
|
||||||
|
'notes' => $exception['notes'] ?? null,
|
||||||
|
'updated_at' => date('Y-m-d H:i:s')
|
||||||
|
];
|
||||||
|
|
||||||
|
$compositeKey = $exception['date'].'|'.$exception['start_time'].'|'.$exception['end_time'];
|
||||||
|
|
||||||
|
if (isset($existingExceptionKeys[$compositeKey])) {
|
||||||
|
$exceptionData['id'] = $existingExceptionKeys[$compositeKey];
|
||||||
|
$this->outletOperatingHoursExceptions->save($exceptionData);
|
||||||
|
$updatedExceptionIds[] = $exceptionData['id'];
|
||||||
|
} else {
|
||||||
|
$exceptionData['created_at'] = date('Y-m-d H:i:s');
|
||||||
|
$newId = $this->outletOperatingHoursExceptions->insert($exceptionData);
|
||||||
|
$updatedExceptionIds[] = $newId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Soft delete removed exceptions
|
||||||
|
foreach ($existingExceptions as $existingException) {
|
||||||
|
if (!in_array($existingException['id'], $updatedExceptionIds)) {
|
||||||
|
$this->outletOperatingHoursExceptions
|
||||||
|
->where('id', $existingException['id'])
|
||||||
|
->set(['deleted_at' => date('Y-m-d H:i:s')])
|
||||||
|
->update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Commit transaction
|
||||||
|
$this->db->transCommit();
|
||||||
|
|
||||||
|
// Prepare response
|
||||||
|
$result = [
|
||||||
|
'outlet' => array_merge($outlet_data, ['id' => $id]),
|
||||||
|
'outlet_tax' => $input['outlet_tax'] ?? [],
|
||||||
|
'outlet_images' => $images['outlet_images'] ?? [],
|
||||||
|
'outlet_operating_days' => $input['outlet_operating_days'] ?? [],
|
||||||
|
'outlet_operating_hours' => $input['outlet_operating_hours'] ?? [],
|
||||||
|
'outlet_operating_hours_exceptions' => $input['outlet_operating_hours_exceptions'] ?? []
|
||||||
|
];
|
||||||
|
|
||||||
|
return $this->respond(['status' => 200, 'result' => $result]);
|
||||||
|
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$this->db->transRollback();
|
||||||
|
return $this->respond(['status' => 400, 'message' => 'Failed to update outlet: ' . $e->getMessage()]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete($id = null)
|
||||||
|
{
|
||||||
|
$outlet = $this->outlet->find($id);
|
||||||
|
|
||||||
|
if(empty($outlet)){
|
||||||
|
return $this->respond(['status' => 400, 'result' => 'No outlet data found.']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->outlet->delete($id);
|
||||||
|
$this->outletTax->where('outlet_id', $id)->delete();
|
||||||
|
$this->outletOperatingDays->where('outlet_id', $id)->delete();
|
||||||
|
$this->outletOperatingHours->where('outlet_id', $id)->delete();
|
||||||
|
$this->outletOperatingHoursExceptions->where('outlet_id', $id)->delete();
|
||||||
|
|
||||||
|
return $this->respond(['status' => 200, 'result' => 'Outlet deleted successfully.']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updatePassword($id = null)
|
||||||
|
{
|
||||||
|
$outlet = $this->outlet->find($id);
|
||||||
|
|
||||||
|
if(empty($outlet)){
|
||||||
|
return $this->respond(['status' => 400, 'result' => 'No outlet data found.']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$password = $this->request->getVar('password');
|
||||||
|
|
||||||
|
$this->outlet->update($id, ['password' => md5(md5($password))]);
|
||||||
|
|
||||||
|
return $this->respond(['status' => 200, 'result' => 'Outlet password updated successfully.']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addBulk()
|
||||||
|
{
|
||||||
|
$rules = [
|
||||||
|
'outlet_ids' => 'required|is_array',
|
||||||
|
'menu_item_ids' => 'required|is_array',
|
||||||
|
];
|
||||||
|
|
||||||
|
if (!$this->validate($rules)) {
|
||||||
|
return $this->failValidationErrors($this->validator->getErrors());
|
||||||
|
}
|
||||||
|
|
||||||
|
$outletIds = $this->request->getVar('outlet_ids');
|
||||||
|
$menuItemIds = $this->request->getVar('menu_item_ids');
|
||||||
|
|
||||||
|
$insertData = [];
|
||||||
|
$insertCount = 0;
|
||||||
|
$restoreCount = 0;
|
||||||
|
|
||||||
|
foreach ($outletIds as $outletId) {
|
||||||
|
foreach ($menuItemIds as $menuItemId) {
|
||||||
|
$exists = $this->outlet_menu
|
||||||
|
->withDeleted() // include soft deleted to detect them
|
||||||
|
->where('outlet_id', $outletId)
|
||||||
|
->where('menu_item_id', $menuItemId)
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if (!$exists) {
|
||||||
|
$insertData[] = [
|
||||||
|
'outlet_id' => $outletId,
|
||||||
|
'menu_item_id' => $menuItemId,
|
||||||
|
];
|
||||||
|
$insertCount++;
|
||||||
|
} elseif (!empty($exists['deleted_at'])) {
|
||||||
|
// Restore if it was soft deleted
|
||||||
|
$this->outlet_menu
|
||||||
|
->update($exists['id'], ['deleted_at' => null]);
|
||||||
|
$restoreCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($insertData)) {
|
||||||
|
$this->outlet_menu->insertBatch($insertData);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 200,
|
||||||
|
'message' => "Menu items added to outlets successfully.",
|
||||||
|
'added' => $insertCount,
|
||||||
|
'restored' => $restoreCount
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function deleteBulk()
|
||||||
|
{
|
||||||
|
$rules = [
|
||||||
|
'outlet_ids' => 'required|is_array',
|
||||||
|
'menu_item_ids' => 'required|is_array',
|
||||||
|
];
|
||||||
|
|
||||||
|
if (!$this->validate($rules)) {
|
||||||
|
return $this->failValidationErrors($this->validator->getErrors());
|
||||||
|
}
|
||||||
|
|
||||||
|
$outletIds = $this->request->getVar('outlet_ids');
|
||||||
|
$menuItemIds = $this->request->getVar('menu_item_ids');
|
||||||
|
|
||||||
|
$deleteCount = 0;
|
||||||
|
|
||||||
|
foreach ($outletIds as $outletId) {
|
||||||
|
// Soft delete only the specified menu items for each outlet
|
||||||
|
$deleteCount += $this->outlet_menu
|
||||||
|
->where('outlet_id', $outletId)
|
||||||
|
->whereIn('menu_item_id', $menuItemIds)
|
||||||
|
->delete(); // soft delete because model usesSoftDeletes = true
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 200,
|
||||||
|
'message' => "Outlet menus deleted successfully.",
|
||||||
|
'deleted' => $deleteCount,
|
||||||
|
'outlets_processed' => count($outletIds),
|
||||||
|
'menu_items_processed' => count($menuItemIds)
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
542
app/Controllers/Backend/PromoSettingController.php
Normal file
542
app/Controllers/Backend/PromoSettingController.php
Normal file
@ -0,0 +1,542 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controllers\Backend;
|
||||||
|
|
||||||
|
use CodeIgniter\HTTP\ResponseInterface;
|
||||||
|
use CodeIgniter\RESTful\ResourceController;
|
||||||
|
|
||||||
|
use App\Models\PromoSetting;
|
||||||
|
use App\Models\PromoCode;
|
||||||
|
use App\Models\PromoRedemptionRecord;
|
||||||
|
|
||||||
|
helper('promo'); // loads app/Helpers/promo_helper.php
|
||||||
|
|
||||||
|
|
||||||
|
class PromoSettingController extends ResourceController
|
||||||
|
{
|
||||||
|
private $promoSetting;
|
||||||
|
private $promoCode;
|
||||||
|
private $promoRedemptionRecord;
|
||||||
|
protected $db;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->promoSetting = new PromoSetting();
|
||||||
|
$this->promoCode = new PromoCode();
|
||||||
|
$this->promoRedemptionRecord = new PromoRedemptionRecord();
|
||||||
|
$this->db = \Config\Database::connect();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
$promoSettingsData = $this->promoSetting->findAll();
|
||||||
|
// print_r($promoSettingsData);exit;
|
||||||
|
|
||||||
|
if(empty($promoSettingsData)){
|
||||||
|
return $this->respond(['status' => 400, 'result' => 'No data found.']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = [];
|
||||||
|
|
||||||
|
foreach($promoSettingsData as $key => $value){
|
||||||
|
$result[$key] = [
|
||||||
|
"id" => $value['id'],
|
||||||
|
"title" => $value['title'],
|
||||||
|
"status" => $value['status'],
|
||||||
|
];
|
||||||
|
|
||||||
|
$promoCode = $this->promoCode->where('promo_setting_id', $value['id'])->findAll()[0];
|
||||||
|
|
||||||
|
if(!empty($promoCode)){
|
||||||
|
$result[$key]['promoCode'] = $promoCode['code'];
|
||||||
|
$result[$key]['total_redemption_limit'] = $promoCode['total_redemption_limit'];
|
||||||
|
$result[$key]['start_date'] = $promoCode['start_date'];
|
||||||
|
$result[$key]['end_date'] = $promoCode['end_date'];
|
||||||
|
|
||||||
|
$count_redemptions = $this->promoRedemptionRecord->where('promo_codes_id', $promoCode['id'])->countAllResults();
|
||||||
|
|
||||||
|
$result[$key]['left_redemption'] = $promoCode['total_redemption_limit'] - $count_redemptions;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->respond(['status' => 200, 'message' => 'Retrieve Promo Setting Successfully!', 'result' => $result]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function show($id = null)
|
||||||
|
{
|
||||||
|
$promoSetting = $this->promoSetting->find($id);
|
||||||
|
|
||||||
|
if(empty($promoSetting)){
|
||||||
|
return $this->respond(['status' => 400, 'result' => 'No data found.']);
|
||||||
|
}
|
||||||
|
// print_r(json_decode($promoSetting['promo_setting'], true));exit;
|
||||||
|
$promoSettingData = revertPromoSetting(json_decode($promoSetting['promo_setting'], true));
|
||||||
|
// print_r($promoSettingData);exit;
|
||||||
|
|
||||||
|
$result = [
|
||||||
|
"id" => $promoSetting['id'],
|
||||||
|
"promotionType" => $promoSetting['promotion_type'],
|
||||||
|
"promotionName" => $promoSetting['title'],
|
||||||
|
"promotionDescription" => $promoSetting['description'],
|
||||||
|
|
||||||
|
//promo_setting
|
||||||
|
"discountAmount" => $promoSettingData['discountAmount'],
|
||||||
|
"discountType" => $promoSettingData['discountType'],
|
||||||
|
"getNumber" => $promoSettingData['getNumber'],
|
||||||
|
"minimumSpend" => $promoSettingData['minimumSpend'],
|
||||||
|
"itemCategory1" => $promoSettingData['itemCategory1'],
|
||||||
|
"itemCategoryID1" => $promoSettingData['itemCategoryID1'],
|
||||||
|
"itemCategory2" => $promoSettingData['itemCategory2'],
|
||||||
|
"itemCategoryID2" => $promoSettingData['itemCategoryID2'],
|
||||||
|
"minimumQuantity" => $promoSettingData['minimumQuantity'],
|
||||||
|
"everyQuantity" => $promoSettingData['everyQuantity'],
|
||||||
|
// "minimumAmount" => $promoSettingData['minimumAmount'],
|
||||||
|
"promoType" => $promoSettingData['promoType'],
|
||||||
|
];
|
||||||
|
|
||||||
|
// print_r($result);exit;
|
||||||
|
|
||||||
|
$promoCode = $this->promoCode->where('promo_setting_id', $promoSetting['id'])->findAll()[0];
|
||||||
|
|
||||||
|
$result['promoCodeId'] = $promoCode['id'];
|
||||||
|
$result['promotionCode'] = $promoCode['code'];
|
||||||
|
$result['usageLimit'] = $promoCode['usage_limit_type'];
|
||||||
|
$result['voucherLimitPerCustomer'] = $promoCode['usage_limit'];
|
||||||
|
$result['totalRedemptionLimit'] = $promoCode['total_redemption_limit'];
|
||||||
|
$result['storeStartDate'] = $promoCode['start_date'];
|
||||||
|
$result['storeEndDate'] = $promoCode['end_date'];
|
||||||
|
$result['customDayTime'] = json_decode($promoCode['customize_validity'], true);
|
||||||
|
$result['applyToDeliveryPickup'] = $promoCode['promo_order_type'];
|
||||||
|
// print_r($result);exit;
|
||||||
|
|
||||||
|
$count_redemptions = $this->promoRedemptionRecord->where('promo_codes_id', $promoCode['id'])->countAllResults();
|
||||||
|
|
||||||
|
$result['left_redemption'] = $promoCode['total_redemption_limit'] - $count_redemptions;
|
||||||
|
|
||||||
|
return $this->respond(['status' => 200, 'message' => 'Retrieve Promo Setting Successfully!', 'result' => $result]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create()
|
||||||
|
{
|
||||||
|
$validationRules = [
|
||||||
|
"promotionType" => "required",
|
||||||
|
"promotionName" => "required",
|
||||||
|
"promotionDescription" => "permit_empty",
|
||||||
|
"usageLimit" => "required",
|
||||||
|
"totalRedemptionLimit" => "required",
|
||||||
|
"voucherLimitPerCustomer" => "permit_empty",
|
||||||
|
"startDate" => "permit_empty",
|
||||||
|
"endDate" => "permit_empty",
|
||||||
|
"customDayTime" => "permit_empty",
|
||||||
|
"applyToDeliveryPickup" => "required",
|
||||||
|
];
|
||||||
|
|
||||||
|
$validation = $this->validate($validationRules);
|
||||||
|
|
||||||
|
if (!$validation) {
|
||||||
|
return $this->failValidationErrors($this->validator->getErrors());
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->db->transBegin();
|
||||||
|
|
||||||
|
try {
|
||||||
|
$applyToDeliveryPickup = $this->request->getVar("applyToDeliveryPickup");
|
||||||
|
|
||||||
|
if (!is_array($applyToDeliveryPickup)) {
|
||||||
|
throw new \Exception("applyToDeliveryPickup must be an array");
|
||||||
|
}
|
||||||
|
|
||||||
|
$validOptions = ['delivery', 'pickup', 'dinein'];
|
||||||
|
foreach ($applyToDeliveryPickup as $option) {
|
||||||
|
if (!in_array($option, $validOptions)) {
|
||||||
|
throw new \Exception("Invalid option in applyToDeliveryPickup: " . $option);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($applyToDeliveryPickup)) {
|
||||||
|
throw new \Exception("applyToDeliveryPickup cannot be empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
$minimumSpend = $this->request->getVar("minimumSpend");
|
||||||
|
$minimumQuantity = $this->request->getVar("minimumQuantity");
|
||||||
|
$everyQuantity = $this->request->getVar("everyQuantity");
|
||||||
|
$itemCategory1 = $this->request->getVar("itemCategory1");
|
||||||
|
$itemCategoryID1 = $this->request->getVar("itemCategoryID1");
|
||||||
|
|
||||||
|
$discountAmount = $this->request->getVar("discountAmount");
|
||||||
|
$discountType = $this->request->getVar("discountType");
|
||||||
|
$getNumber = $this->request->getVar("getNumber");
|
||||||
|
$itemCategory2 = $this->request->getVar("itemCategory2");
|
||||||
|
$itemCategoryID2 = $this->request->getVar("itemCategoryID2");
|
||||||
|
|
||||||
|
$promoType = $this->request->getVar("promoType");
|
||||||
|
|
||||||
|
$promoSetting = [
|
||||||
|
"MinimumSpend" => [
|
||||||
|
"type" => 'none',
|
||||||
|
"filter" => [],
|
||||||
|
"amount_type" => '',
|
||||||
|
"amount" => 0
|
||||||
|
],
|
||||||
|
"Promo" => [
|
||||||
|
"promo_type" => $promoType,
|
||||||
|
"discount_type" => $discountType,
|
||||||
|
"filter_type" => 'total',
|
||||||
|
"filter" => [],
|
||||||
|
"amount" => 0,
|
||||||
|
"free_item" => []
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
if (!empty($minimumSpend) || !empty($minimumQuantity) || !empty($everyQuantity)) {
|
||||||
|
if (!empty($itemCategory1)) {
|
||||||
|
$promoSetting["MinimumSpend"]["type"] = $itemCategory1;
|
||||||
|
$promoSetting["MinimumSpend"]["filter"] = is_array($itemCategoryID1) ? $itemCategoryID1 : [];
|
||||||
|
} else {
|
||||||
|
$promoSetting["MinimumSpend"]["type"] = "total";
|
||||||
|
$promoSetting["MinimumSpend"]["filter"] = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($minimumSpend)) {
|
||||||
|
$promoSetting["MinimumSpend"]["amount_type"] = "amount";
|
||||||
|
$promoSetting["MinimumSpend"]["amount"] = floatval($minimumSpend);
|
||||||
|
} elseif (!empty($minimumQuantity)) {
|
||||||
|
$promoSetting["MinimumSpend"]["amount_type"] = "quantity";
|
||||||
|
$promoSetting["MinimumSpend"]["amount"] = intval($minimumQuantity);
|
||||||
|
} elseif (!empty($everyQuantity)) {
|
||||||
|
$promoSetting["MinimumSpend"]["amount_type"] = "every_quantity";
|
||||||
|
$promoSetting["MinimumSpend"]["amount"] = intval($everyQuantity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$promoSetting["Promo"]["promo_type"] = $promoType;
|
||||||
|
|
||||||
|
if ($promoType === "free_item") {
|
||||||
|
$promoSetting["Promo"]["discount_type"] = '';
|
||||||
|
} else {
|
||||||
|
$promoSetting["Promo"]["discount_type"] = $discountType;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($itemCategory2)) {
|
||||||
|
$promoSetting["Promo"]["filter_type"] = $itemCategory2;
|
||||||
|
} else {
|
||||||
|
$promoSetting["Promo"]["filter_type"] = "total";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($promoType === "free_item") {
|
||||||
|
$promoSetting["Promo"]["free_item"] = is_array($itemCategoryID2) ? $itemCategoryID2 : [];
|
||||||
|
$promoSetting["Promo"]["filter"] = [];
|
||||||
|
} else {
|
||||||
|
$promoSetting["Promo"]["filter"] = is_array($itemCategoryID2) ? $itemCategoryID2 : [];
|
||||||
|
$promoSetting["Promo"]["free_item"] = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($discountAmount)) {
|
||||||
|
$promoSetting["Promo"]["amount"] = floatval($discountAmount);
|
||||||
|
} elseif (!empty($getNumber)) {
|
||||||
|
$promoSetting["Promo"]["amount"] = intval($getNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
$promoSettingData = [
|
||||||
|
"promotion_type" => $this->request->getVar("promotionType"),
|
||||||
|
"title" => $this->request->getVar("promotionName"),
|
||||||
|
"description" => $this->request->getVar("promotionDescription"),
|
||||||
|
"promo_setting" => json_encode($promoSetting)
|
||||||
|
];
|
||||||
|
|
||||||
|
$id = $this->promoSetting->insert($promoSettingData);
|
||||||
|
if(!$id){
|
||||||
|
throw new \Exception("Failed to create promotion setting.");
|
||||||
|
}
|
||||||
|
|
||||||
|
$promotionCode = $this->request->getVar("promotionCode");
|
||||||
|
|
||||||
|
if(!empty($promotionCode)){
|
||||||
|
$isExists = $this->promoCode->where('code', $promotionCode)->find();
|
||||||
|
|
||||||
|
if(!empty($isExists)){
|
||||||
|
throw new \Exception("Promotion code already exists.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$promoOrderTypeString = implode(',', $applyToDeliveryPickup);
|
||||||
|
|
||||||
|
$promoCodeData = [
|
||||||
|
'promo_setting_id' => $id,
|
||||||
|
"code" => $promotionCode,
|
||||||
|
"usage_limit_type" => $this->request->getVar("usageLimit"),
|
||||||
|
"usage_limit" => $this->request->getVar("voucherLimitPerCustomer"),
|
||||||
|
"total_redemption_limit" => $this->request->getVar("totalRedemptionLimit"),
|
||||||
|
"start_date" => $this->request->getVar("storeStartDate"),
|
||||||
|
"end_date" => $this->request->getVar("storeEndDate"),
|
||||||
|
"customize_validity" => json_encode($this->request->getVar("customDayTime")),
|
||||||
|
"promo_order_type" => $promoOrderTypeString
|
||||||
|
];
|
||||||
|
|
||||||
|
$promoCodeId = $this->promoCode->insert($promoCodeData);
|
||||||
|
if(!$promoCodeId){
|
||||||
|
throw new \Exception("Failed to create promotion code.");
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->db->transCommit();
|
||||||
|
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 200,
|
||||||
|
'message' => 'Promotion created successfully.',
|
||||||
|
'data' => [
|
||||||
|
'promo_setting_id' => $id,
|
||||||
|
'promo_code_id' => $promoCodeId,
|
||||||
|
'promo_order_type' => $promoOrderTypeString
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$this->db->transRollback();
|
||||||
|
log_message('error', 'Promotion creation failed: ' . $e->getMessage());
|
||||||
|
return $this->failServerError('Failed to create promotion: '. $e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update($id = null)
|
||||||
|
{
|
||||||
|
$promoSetting = $this->promoSetting->find($id);
|
||||||
|
|
||||||
|
if(empty($promoSetting)){
|
||||||
|
return $this->respond(['status' => 400, 'result' => 'No promotion setting data found.']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$validationRules = [
|
||||||
|
"promotionType" => "required",
|
||||||
|
"promotionName" => "required",
|
||||||
|
"promotionDescription" => "permit_empty",
|
||||||
|
"usageLimit" => "required",
|
||||||
|
"totalRedemptionLimit" => "required",
|
||||||
|
"voucherLimitPerCustomer" => "permit_empty",
|
||||||
|
"startDate" => "permit_empty",
|
||||||
|
"endDate" => "permit_empty",
|
||||||
|
"customDayTime" => "permit_empty",
|
||||||
|
"applyToDeliveryPickup" => "required",
|
||||||
|
];
|
||||||
|
|
||||||
|
$validation = $this->validate($validationRules);
|
||||||
|
|
||||||
|
if (!$validation) {
|
||||||
|
return $this->failValidationErrors($this->validator->getErrors());
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->db->transBegin();
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
$applyToDeliveryPickup = $this->request->getVar("applyToDeliveryPickup");
|
||||||
|
|
||||||
|
|
||||||
|
if (!is_array($applyToDeliveryPickup)) {
|
||||||
|
throw new \Exception("applyToDeliveryPickup must be an array");
|
||||||
|
}
|
||||||
|
|
||||||
|
$validOptions = ['delivery', 'pickup', 'dinein'];
|
||||||
|
foreach ($applyToDeliveryPickup as $option) {
|
||||||
|
if (!in_array($option, $validOptions)) {
|
||||||
|
throw new \Exception("Invalid option in applyToDeliveryPickup: " . $option);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($applyToDeliveryPickup)) {
|
||||||
|
throw new \Exception("applyToDeliveryPickup cannot be empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
$minimumSpend = $this->request->getVar("minimumSpend");
|
||||||
|
$minimumQuantity = $this->request->getVar("minimumQuantity");
|
||||||
|
$everyQuantity = $this->request->getVar("everyQuantity");
|
||||||
|
$itemCategory1 = $this->request->getVar("itemCategory1");
|
||||||
|
$itemCategoryID1 = $this->request->getVar("itemCategoryID1");
|
||||||
|
|
||||||
|
// print_r($itemCategory1);
|
||||||
|
// print_r($itemCategoryID1);
|
||||||
|
// exit;
|
||||||
|
|
||||||
|
$discountAmount = $this->request->getVar("discountAmount");
|
||||||
|
$discountType = $this->request->getVar("discountType");
|
||||||
|
$getNumber = $this->request->getVar("getNumber");
|
||||||
|
$itemCategory2 = $this->request->getVar("itemCategory2");
|
||||||
|
$itemCategoryID2 = $this->request->getVar("itemCategoryID2");
|
||||||
|
|
||||||
|
$promoType = $this->request->getVar("promoType");
|
||||||
|
|
||||||
|
$promoSetting = [
|
||||||
|
"MinimumSpend" => [
|
||||||
|
"type" => 'none',
|
||||||
|
"filter" => [],
|
||||||
|
"amount_type" => '',
|
||||||
|
"amount" => 0
|
||||||
|
],
|
||||||
|
"Promo" => [
|
||||||
|
"promo_type" => $promoType,
|
||||||
|
"discount_type" => $discountType,
|
||||||
|
"filter_type" => 'total',
|
||||||
|
"filter" => [],
|
||||||
|
"amount" => 0,
|
||||||
|
"free_item" => []
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
if (!empty($itemCategory1)) {
|
||||||
|
$promoSetting["MinimumSpend"]["type"] = $itemCategory1;
|
||||||
|
$promoSetting["MinimumSpend"]["filter"] = is_array($itemCategoryID1) ? $itemCategoryID1 : [];
|
||||||
|
} else {
|
||||||
|
$promoSetting["MinimumSpend"]["type"] = "total";
|
||||||
|
$promoSetting["MinimumSpend"]["filter"] = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($minimumSpend)) {
|
||||||
|
$promoSetting["MinimumSpend"]["amount_type"] = "amount";
|
||||||
|
$promoSetting["MinimumSpend"]["amount"] = floatval($minimumSpend);
|
||||||
|
} elseif (!empty($minimumQuantity)) {
|
||||||
|
$promoSetting["MinimumSpend"]["amount_type"] = "quantity";
|
||||||
|
$promoSetting["MinimumSpend"]["amount"] = intval($minimumQuantity);
|
||||||
|
} elseif (!empty($everyQuantity)) {
|
||||||
|
$promoSetting["MinimumSpend"]["amount_type"] = "every_quantity";
|
||||||
|
$promoSetting["MinimumSpend"]["amount"] = intval($everyQuantity);
|
||||||
|
}
|
||||||
|
|
||||||
|
$promoSetting["Promo"]["promo_type"] = $promoType;
|
||||||
|
|
||||||
|
if ($promoType === "free_item") {
|
||||||
|
$promoSetting["Promo"]["discount_type"] = '';
|
||||||
|
} else {
|
||||||
|
$promoSetting["Promo"]["discount_type"] = $discountType;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($itemCategory2)) {
|
||||||
|
$promoSetting["Promo"]["filter_type"] = $itemCategory2;
|
||||||
|
} else {
|
||||||
|
$promoSetting["Promo"]["filter_type"] = "total";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($promoType === "free_item") {
|
||||||
|
$promoSetting["Promo"]["free_item"] = is_array($itemCategoryID2) ? $itemCategoryID2 : [];
|
||||||
|
$promoSetting["Promo"]["filter"] = [];
|
||||||
|
} else {
|
||||||
|
$promoSetting["Promo"]["filter"] = is_array($itemCategoryID2) ? $itemCategoryID2 : [];
|
||||||
|
$promoSetting["Promo"]["free_item"] = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($discountAmount)) {
|
||||||
|
$promoSetting["Promo"]["amount"] = floatval($discountAmount);
|
||||||
|
} elseif (!empty($getNumber)) {
|
||||||
|
$promoSetting["Promo"]["amount"] = intval($getNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
$promoSettingData = [
|
||||||
|
"id" => $id,
|
||||||
|
"promotion_type" => $this->request->getVar("promotionType"),
|
||||||
|
"title" => $this->request->getVar("promotionName"),
|
||||||
|
"description" => $this->request->getVar("promotionDescription"),
|
||||||
|
"promo_setting" => json_encode($promoSetting)
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = $this->promoSetting->save($promoSettingData);
|
||||||
|
if (!$response) {
|
||||||
|
throw new \Exception('Failed to update promotion settings.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$promoCode = $this->promoCode->where('promo_setting_id', $id)->find()[0];
|
||||||
|
|
||||||
|
if(!$promoCode){
|
||||||
|
throw new \Exception("Failed to update promotion code.");
|
||||||
|
}
|
||||||
|
|
||||||
|
$promotionCode = $this->request->getVar("promotionCode");
|
||||||
|
if(!empty($promotionCode)){
|
||||||
|
$isExists = $this->promoCode->where('code', $promotionCode)->where('id !=', $promoCode['id'])->find();
|
||||||
|
|
||||||
|
if(!empty($isExists)){
|
||||||
|
throw new \Exception("Promotion code already exists.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$promoOrderTypeString = implode(',', $applyToDeliveryPickup);
|
||||||
|
|
||||||
|
$promoCodeData = [
|
||||||
|
'id' => $promoCode['id'],
|
||||||
|
'promo_setting_id' => $id,
|
||||||
|
'code' => $promotionCode,
|
||||||
|
'usage_limit_type' => $this->request->getVar("usageLimit"),
|
||||||
|
'usage_limit' => $this->request->getVar("voucherLimitPerCustomer"),
|
||||||
|
'total_redemption_limit' => $this->request->getVar("totalRedemptionLimit"),
|
||||||
|
'start_date' => $this->request->getVar("storeStartDate"),
|
||||||
|
'end_date' => $this->request->getVar("storeEndDate"),
|
||||||
|
'customize_validity' => json_encode($this->request->getVar("customDayTime")),
|
||||||
|
'promo_order_type' => $promoOrderTypeString
|
||||||
|
];
|
||||||
|
|
||||||
|
$promoCodeResponse = $this->promoCode->save($promoCodeData);
|
||||||
|
if (!$promoCodeResponse) {
|
||||||
|
throw new \Exception('Failed to update promotion code.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->db->transCommit();
|
||||||
|
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 200,
|
||||||
|
'message' => 'Promotion updated successfully.',
|
||||||
|
'data' => [
|
||||||
|
'promo_setting_id' => $id,
|
||||||
|
'promo_code_id' => $promoCode['id'],
|
||||||
|
'promo_order_type' => $promoOrderTypeString
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$this->db->transRollback();
|
||||||
|
log_message('error', 'Promotion update failed: ' . $e->getMessage());
|
||||||
|
return $this->failServerError('Failed to update promotion: '. $e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function delete($id = null)
|
||||||
|
{
|
||||||
|
$promoSetting = $this->promoSetting->find($id);
|
||||||
|
|
||||||
|
// print_r($promoSetting);exit;
|
||||||
|
if(empty($promoSetting)){
|
||||||
|
return $this->respond(['status' => 400, 'result' => 'No promotion setting data found.']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->promoSetting->delete($id);
|
||||||
|
$this->promoCode->where('promo_setting_id', $id)->delete();
|
||||||
|
|
||||||
|
return $this->respond(['status' => 200, 'result' => 'Promotion deleted successfully.']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function promoSettingList(){
|
||||||
|
$promo_setting_list = $this->promoSetting->findAll();
|
||||||
|
|
||||||
|
if(empty($promo_setting_list)){
|
||||||
|
return $this->fail('No promo setting data found!');
|
||||||
|
}
|
||||||
|
|
||||||
|
$data_list = [];
|
||||||
|
|
||||||
|
foreach ($promo_setting_list as $key => $value) {
|
||||||
|
$data_list[] = [
|
||||||
|
'id' => $value['id'],
|
||||||
|
'promotion_type' => $value['promotion_type'],
|
||||||
|
'title' => $value['title'],
|
||||||
|
'description'=> $value['description'],
|
||||||
|
'status' => $value['status'],
|
||||||
|
'promo_setting' => $value['promo_setting'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->respond([
|
||||||
|
'status'=> 200,
|
||||||
|
'message' => 'Promo setting record found!',
|
||||||
|
'data'=> $data_list
|
||||||
|
]);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
205
app/Controllers/Backend/PwpController.php
Normal file
205
app/Controllers/Backend/PwpController.php
Normal file
@ -0,0 +1,205 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controllers\Backend;
|
||||||
|
|
||||||
|
use App\Controllers\BaseController;
|
||||||
|
use CodeIgniter\HTTP\ResponseInterface;
|
||||||
|
use App\Models\PwpModel;
|
||||||
|
use CodeIgniter\RESTful\ResourceController;
|
||||||
|
|
||||||
|
|
||||||
|
class PwpController extends ResourceController
|
||||||
|
{
|
||||||
|
protected $pwpModel;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->pwpModel = new PwpModel();
|
||||||
|
$this->db = db_connect();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
$pwps = $this->pwpModel->findAll();
|
||||||
|
foreach ($pwps as &$pwp) {
|
||||||
|
$selectedIds = array_filter(array_map('trim', explode(',', $pwp['selected_item'])));
|
||||||
|
$pwp['selected_item_details'] = [];
|
||||||
|
|
||||||
|
if (!empty($selectedIds)) {
|
||||||
|
$pwp['selected_item_details'] = $this->db->table('menu_items')
|
||||||
|
->select('id, title, price, status')
|
||||||
|
->whereIn('id', $selectedIds)
|
||||||
|
->where('deleted_at', null)
|
||||||
|
->orderBy("created_at", "ASC")
|
||||||
|
->get()
|
||||||
|
->getResultArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
$pwpIds = array_filter(array_map('trim', explode(',', $pwp['pwp_item_id'])));
|
||||||
|
$pwp['pwp_item_details'] = [];
|
||||||
|
|
||||||
|
if (!empty($pwpIds)) {
|
||||||
|
$pwp['pwp_item_details'] = $this->db->table('menu_items')
|
||||||
|
->select('id, title, price, status')
|
||||||
|
->whereIn('id', $pwpIds)
|
||||||
|
->where('deleted_at', null)
|
||||||
|
->orderBy("created_at", "DESC")
|
||||||
|
->get()
|
||||||
|
->getResultArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 200,
|
||||||
|
'data' => $pwps
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function create()
|
||||||
|
{
|
||||||
|
$json = $this->request->getJSON(true);
|
||||||
|
if (empty($json['mode']) || empty($json['order_index']) || empty($json['amount']) || empty($json['amount_type'])) {
|
||||||
|
return $this->failValidationErrors('mode, order_index, amount and amount_type are required');
|
||||||
|
}
|
||||||
|
$pwpItems = is_array($json['pwp_item_id']) ? implode(',', $json['pwp_item_id']) : $json['pwp_item_id'];
|
||||||
|
$selectedIds = is_array($json['selected_item']) ? $json['selected_item'] : explode(',', $json['selected_item']);
|
||||||
|
$selectedItems = implode(',', $selectedIds);
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'mode' => $json['mode'],
|
||||||
|
'order_index' => $json['order_index'],
|
||||||
|
'pwp_item_id' => $pwpItems,
|
||||||
|
'amount' => $json['amount'],
|
||||||
|
'amount_type' => $json['amount_type'],
|
||||||
|
'selected_item' => $selectedItems,
|
||||||
|
];
|
||||||
|
|
||||||
|
if (!$this->pwpModel->insert($data)) {
|
||||||
|
return $this->fail($this->pwpModel->errors());
|
||||||
|
}
|
||||||
|
|
||||||
|
$pwpItemDetails = [];
|
||||||
|
if (!empty($pwpItems)) {
|
||||||
|
$pwpItemArray = explode(',', $pwpItems);
|
||||||
|
$pwpItemDetails = $this->db->table('menu_items')
|
||||||
|
->select('id, title, price')
|
||||||
|
->whereIn('id', $pwpItemArray)
|
||||||
|
->where('status', 'active')
|
||||||
|
->get()
|
||||||
|
->getResultArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
$selectedItemDetails = [];
|
||||||
|
if (!empty($selectedIds)) {
|
||||||
|
$selectedItemDetails = $this->db->table('menu_items')
|
||||||
|
->select('id, title, price')
|
||||||
|
->whereIn('id', $selectedIds)
|
||||||
|
->where('status', 'active')
|
||||||
|
->get()
|
||||||
|
->getResultArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->respondCreated([
|
||||||
|
'message' => 'PWP promo created successfully',
|
||||||
|
'data' => array_merge($data, [
|
||||||
|
'pwp_item_id' => $pwpItems,
|
||||||
|
'pwp_item_details' => $pwpItemDetails,
|
||||||
|
'selected_item' => $selectedIds,
|
||||||
|
'selected_item_details' => $selectedItemDetails
|
||||||
|
])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function show($id = null)
|
||||||
|
{
|
||||||
|
$pwp = $this->pwpModel->find($id);
|
||||||
|
|
||||||
|
if (!$pwp) {
|
||||||
|
return $this->failNotFound('PWP not found');
|
||||||
|
}
|
||||||
|
|
||||||
|
$selectedIds = explode(',', $pwp['selected_item']);
|
||||||
|
$pwp['selected_item_details'] = [];
|
||||||
|
|
||||||
|
if (!empty($selectedIds[0])) {
|
||||||
|
$pwp['selected_item_details'] = $this->db->table('menu_items')
|
||||||
|
->select('id, title, price, status')
|
||||||
|
->whereIn('id', $selectedIds)
|
||||||
|
->where('status', 'active')
|
||||||
|
->get()
|
||||||
|
->getResultArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->respond($pwp);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update($id = null)
|
||||||
|
{
|
||||||
|
$json = $this->request->getJSON(true);
|
||||||
|
|
||||||
|
if (empty($json['mode']) || empty($json['order_index']) ) {
|
||||||
|
return $this->failValidationErrors('mode, order_index are required');
|
||||||
|
}
|
||||||
|
|
||||||
|
$pwpItems = is_array($json['pwp_item_id']) ? implode(',', $json['pwp_item_id']) : $json['pwp_item_id'];
|
||||||
|
$selectedIds = is_array($json['selected_item']) ? $json['selected_item'] : explode(',', $json['selected_item']);
|
||||||
|
$selectedItems = implode(',', $selectedIds);
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'mode' => $json['mode'],
|
||||||
|
'order_index' => $json['order_index'],
|
||||||
|
'pwp_item_id' => $pwpItems,
|
||||||
|
'amount' => $json['amount'] ?? 0.00,
|
||||||
|
'amount_type' => $json['amount_type'] ?? 'amount',
|
||||||
|
'selected_item' => $selectedItems,
|
||||||
|
];
|
||||||
|
|
||||||
|
if (!$this->pwpModel->update($id, $data)) {
|
||||||
|
return $this->fail($this->pwpModel->errors());
|
||||||
|
}
|
||||||
|
|
||||||
|
$selectedItemDetails = [];
|
||||||
|
if (!empty($selectedIds)) {
|
||||||
|
$selectedItemDetails = $this->db->table('menu_items')
|
||||||
|
->select('id, title, price')
|
||||||
|
->whereIn('id', $selectedIds)
|
||||||
|
->where('status', 'active')
|
||||||
|
->get()
|
||||||
|
->getResultArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 200,
|
||||||
|
'message' => 'PWP promo updated successfully',
|
||||||
|
'data' => array_merge($data, [
|
||||||
|
'selected_item' => $selectedIds,
|
||||||
|
'selected_item_details' => $selectedItemDetails
|
||||||
|
])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete($id = null)
|
||||||
|
{
|
||||||
|
if (!$this->pwpModel->find($id)) {
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 404,
|
||||||
|
'message' => 'PWP not found'
|
||||||
|
], 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$this->pwpModel->delete($id)) {
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 500,
|
||||||
|
'message' => 'Failed to delete PWP'
|
||||||
|
], 500);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 200,
|
||||||
|
'message' => 'PWP promo deleted successfully'
|
||||||
|
], 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
879
app/Controllers/Backend/SettingController.php
Normal file
879
app/Controllers/Backend/SettingController.php
Normal file
@ -0,0 +1,879 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controllers\Backend;
|
||||||
|
|
||||||
|
use CodeIgniter\HTTP\ResponseInterface;
|
||||||
|
use CodeIgniter\RESTful\ResourceController;
|
||||||
|
|
||||||
|
use App\Models\SettingCustomerType;
|
||||||
|
use App\Models\SettingMembershipTier;
|
||||||
|
use App\Models\SettingTax;
|
||||||
|
use App\Models\SlideshowModel;
|
||||||
|
|
||||||
|
helper('image');
|
||||||
|
|
||||||
|
use App\Models\SettingCheckinRule;
|
||||||
|
|
||||||
|
class SettingController extends ResourceController
|
||||||
|
{
|
||||||
|
private $customerTypeModel;
|
||||||
|
private $membershipTierModel;
|
||||||
|
|
||||||
|
private $checkinRuleModel;
|
||||||
|
private $taxModel;
|
||||||
|
private $slideshowModel;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->customerTypeModel = new SettingCustomerType();
|
||||||
|
$this->membershipTierModel = new SettingMembershipTier();
|
||||||
|
$this->taxModel = new SettingTax();
|
||||||
|
|
||||||
|
$this->checkinRuleModel = new SettingCheckinRule();
|
||||||
|
$this->slideshowModel = new SlideshowModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function customerTypesindex()
|
||||||
|
{
|
||||||
|
|
||||||
|
$types = $this->customerTypeModel->findAll();
|
||||||
|
|
||||||
|
if (empty($types)) {
|
||||||
|
$response = [
|
||||||
|
'status' => 'success',
|
||||||
|
'message' => 'No customer type data found.',
|
||||||
|
'data' => []
|
||||||
|
];
|
||||||
|
return $this->respond($response, 200);
|
||||||
|
}
|
||||||
|
$response = [
|
||||||
|
'status' => 'success',
|
||||||
|
'message' => 'Customer types retrieved successfully.',
|
||||||
|
'data' => $types
|
||||||
|
];
|
||||||
|
return $this->respond($response, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function customerTypesshow($id = null)
|
||||||
|
{
|
||||||
|
$type = $this->customerTypeModel->find($id);
|
||||||
|
|
||||||
|
if (!$type) {
|
||||||
|
$response = [
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'Customer type not found.',
|
||||||
|
'data' => null
|
||||||
|
];
|
||||||
|
return $this->respond($response, 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
$response = [
|
||||||
|
'status' => 'success',
|
||||||
|
'message' => 'Customer type retrieved successfully.',
|
||||||
|
'data' => $type
|
||||||
|
];
|
||||||
|
return $this->respond($response, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function customerTypescreate()
|
||||||
|
{
|
||||||
|
$validationRules = [
|
||||||
|
'name' => 'required',
|
||||||
|
];
|
||||||
|
|
||||||
|
if (!$this->validate($validationRules)) {
|
||||||
|
$response = [
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'Validation failed.',
|
||||||
|
'data' => $this->validator->getErrors()
|
||||||
|
];
|
||||||
|
return $this->respond($response, 422);
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'name' => $this->request->getVar('name'),
|
||||||
|
];
|
||||||
|
|
||||||
|
$id = $this->customerTypeModel->insert($data);
|
||||||
|
|
||||||
|
if ($id) {
|
||||||
|
$result = $this->customerTypeModel->find($id);
|
||||||
|
|
||||||
|
$response = [
|
||||||
|
'status' => 'success',
|
||||||
|
'message' => 'Customer type created successfully.',
|
||||||
|
'data' => $result
|
||||||
|
];
|
||||||
|
return $this->respond($response, 201);
|
||||||
|
}
|
||||||
|
|
||||||
|
$response = [
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'Failed to create customer type.',
|
||||||
|
'data' => null
|
||||||
|
];
|
||||||
|
return $this->respond($response, 500);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function customerTypesupdate($id = null)
|
||||||
|
{
|
||||||
|
// Check if customer type exists and is not soft-deleted
|
||||||
|
$existingType = $this->customerTypeModel->find($id);
|
||||||
|
|
||||||
|
if (!$existingType) {
|
||||||
|
$response = [
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'Customer type not found.',
|
||||||
|
'data' => null
|
||||||
|
];
|
||||||
|
return $this->respond($response, 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use raw input for PUT/PATCH, or getVar for POST fallback
|
||||||
|
$input = $this->request->getRawInput();
|
||||||
|
if (empty($input)) {
|
||||||
|
$input = $this->request->getVar();
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = [];
|
||||||
|
|
||||||
|
if (isset($input['name'])) {
|
||||||
|
$data['name'] = $input['name'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($data)) {
|
||||||
|
$response = [
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'No data provided to update.',
|
||||||
|
'data' => null
|
||||||
|
];
|
||||||
|
return $this->respond($response, 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->customerTypeModel->update($id, $data);
|
||||||
|
$updatedType = $this->customerTypeModel->find($id);
|
||||||
|
|
||||||
|
$response = [
|
||||||
|
'status' => 'success',
|
||||||
|
'message' => 'Customer type updated successfully.',
|
||||||
|
'data' => $updatedType
|
||||||
|
];
|
||||||
|
return $this->respond($response, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function customerTypesdelete($id = null)
|
||||||
|
{
|
||||||
|
$existingType = $this->customerTypeModel->find($id);
|
||||||
|
|
||||||
|
if (!$existingType) {
|
||||||
|
$response = [
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'Customer type not found.',
|
||||||
|
'data' => null
|
||||||
|
];
|
||||||
|
return $this->respond($response, 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->customerTypeModel->delete($id); // This performs soft delete
|
||||||
|
|
||||||
|
$response = [
|
||||||
|
'status' => 'success',
|
||||||
|
'message' => 'Customer type deleted successfully.',
|
||||||
|
'data' => null
|
||||||
|
];
|
||||||
|
return $this->respond($response, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function membershipTiersIndex()
|
||||||
|
{
|
||||||
|
$tiers = $this->membershipTierModel->findAll();
|
||||||
|
|
||||||
|
if (empty($tiers)) {
|
||||||
|
$response = [
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'No membership tiers found.',
|
||||||
|
'data' => []
|
||||||
|
];
|
||||||
|
return $this->respond($response, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
$response = [
|
||||||
|
'status' => 'success',
|
||||||
|
'message' => 'Membership tiers retrieved successfully.',
|
||||||
|
'data' => $tiers
|
||||||
|
];
|
||||||
|
return $this->respond($response, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function membershipTiersShow($id = null)
|
||||||
|
{
|
||||||
|
$tier = $this->membershipTierModel->find($id);
|
||||||
|
|
||||||
|
if (!$tier) {
|
||||||
|
$response = [
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'Membership tier not found.',
|
||||||
|
'data' => null
|
||||||
|
];
|
||||||
|
return $this->respond($response, 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
$response = [
|
||||||
|
'status' => 'success',
|
||||||
|
'message' => 'Membership tier retrieved successfully.',
|
||||||
|
'data' => $tier
|
||||||
|
];
|
||||||
|
return $this->respond($response, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function membershipTiersCreate()
|
||||||
|
{
|
||||||
|
$validationRules = [
|
||||||
|
'name' => 'required',
|
||||||
|
'min_points' => 'required|numeric',
|
||||||
|
// 'discount_rate' => 'required|numeric',
|
||||||
|
// 'category_id' => 'required|integer'
|
||||||
|
];
|
||||||
|
|
||||||
|
if (!$this->validate($validationRules)) {
|
||||||
|
$response = [
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'Validation failed.',
|
||||||
|
'data' => $this->validator->getErrors()
|
||||||
|
];
|
||||||
|
return $this->respond($response, 422);
|
||||||
|
}
|
||||||
|
$name = $this->request->getVar('name');
|
||||||
|
|
||||||
|
$existingTier = $this->membershipTierModel->where('name', $name)->first();
|
||||||
|
if ($existingTier) {
|
||||||
|
$response = [
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => "A membership tier with the name '{$name}' already exists.",
|
||||||
|
'data' => null
|
||||||
|
];
|
||||||
|
return $this->respond($response, 409); // Conflict
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'name' => $this->request->getVar('name'),
|
||||||
|
'min_points' => $this->request->getVar('min_points'),
|
||||||
|
'discount_rate' => $this->request->getVar('discount_rate'),
|
||||||
|
'color' => $this->request->getVar('color'),
|
||||||
|
'category_id' => $this->request->getVar('category_id'), // Add category_id
|
||||||
|
];
|
||||||
|
|
||||||
|
$id = $this->membershipTierModel->insert($data);
|
||||||
|
|
||||||
|
if ($id) {
|
||||||
|
$result = $this->membershipTierModel->find($id);
|
||||||
|
|
||||||
|
$response = [
|
||||||
|
'status' => 'success',
|
||||||
|
'message' => 'Membership tier created successfully.',
|
||||||
|
'data' => $result
|
||||||
|
];
|
||||||
|
return $this->respond($response, 201);
|
||||||
|
}
|
||||||
|
|
||||||
|
$response = [
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'Failed to create membership tier.',
|
||||||
|
'data' => null
|
||||||
|
];
|
||||||
|
return $this->respond($response, 500);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function membershipTiersUpdate($id = null)
|
||||||
|
{
|
||||||
|
$existing = $this->membershipTierModel->find($id);
|
||||||
|
|
||||||
|
if (!$existing) {
|
||||||
|
$response = [
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'Membership tier not found.',
|
||||||
|
'data' => null
|
||||||
|
];
|
||||||
|
return $this->respond($response, 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
$input = $this->request->getRawInput();
|
||||||
|
if (empty($input)) {
|
||||||
|
$input = $this->request->getVar();
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = [];
|
||||||
|
|
||||||
|
if (isset($input['name'])) {
|
||||||
|
$data['name'] = $input['name'];
|
||||||
|
}
|
||||||
|
if (isset($input['min_points'])) {
|
||||||
|
$data['min_points'] = $input['min_points'];
|
||||||
|
}
|
||||||
|
// if (isset($input['discount_rate'])) {
|
||||||
|
// $data['discount_rate'] = $input['discount_rate'];
|
||||||
|
// }
|
||||||
|
if (isset($input['color'])) {
|
||||||
|
$data['color'] = $input['color'];
|
||||||
|
}
|
||||||
|
// if (isset($input['category_id'])) {
|
||||||
|
// $data['category_id'] = $input['category_id']; // Add category_id
|
||||||
|
// }
|
||||||
|
|
||||||
|
if (empty($data)) {
|
||||||
|
$response = [
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'No data provided to update.',
|
||||||
|
'data' => null
|
||||||
|
];
|
||||||
|
return $this->respond($response, 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->membershipTierModel->update($id, $data);
|
||||||
|
|
||||||
|
$updated = $this->membershipTierModel->find($id);
|
||||||
|
|
||||||
|
$response = [
|
||||||
|
'status' => 'success',
|
||||||
|
'message' => 'Membership tier updated successfully.',
|
||||||
|
'data' => $updated
|
||||||
|
];
|
||||||
|
return $this->respond($response, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function membershipTiersDelete($id = null)
|
||||||
|
{
|
||||||
|
$existing = $this->membershipTierModel->find($id);
|
||||||
|
|
||||||
|
if (!$existing) {
|
||||||
|
$response = [
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'Membership tier not found.',
|
||||||
|
'data' => null
|
||||||
|
];
|
||||||
|
return $this->respond($response, 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->membershipTierModel->delete($id);
|
||||||
|
|
||||||
|
$response = [
|
||||||
|
'status' => 'success',
|
||||||
|
'message' => 'Membership tier deleted successfully.',
|
||||||
|
'data' => null
|
||||||
|
];
|
||||||
|
return $this->respond($response, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function taxIndex()
|
||||||
|
{
|
||||||
|
$taxes = $this->taxModel->findAll();
|
||||||
|
|
||||||
|
if (empty($taxes)) {
|
||||||
|
$response = [
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'No tax data found.',
|
||||||
|
'data' => []
|
||||||
|
];
|
||||||
|
return $this->respond($response, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
$response = [
|
||||||
|
'status' => 'success',
|
||||||
|
'message' => 'Tax data retrieved successfully.',
|
||||||
|
'data' => $taxes
|
||||||
|
];
|
||||||
|
return $this->respond($response, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function taxShow($id = null)
|
||||||
|
{
|
||||||
|
$tax = $this->taxModel->find($id);
|
||||||
|
|
||||||
|
if (!$tax) {
|
||||||
|
$response = [
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'Tax entry not found.',
|
||||||
|
'data' => null
|
||||||
|
];
|
||||||
|
return $this->respond($response, 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
$response = [
|
||||||
|
'status' => 'success',
|
||||||
|
'message' => 'Tax entry retrieved successfully.',
|
||||||
|
'data' => $tax
|
||||||
|
];
|
||||||
|
return $this->respond($response, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function taxCreate()
|
||||||
|
{
|
||||||
|
$validationRules = [
|
||||||
|
'outlet_id' => 'required',
|
||||||
|
'tax_type' => 'required',
|
||||||
|
'tax_rate' => 'required|numeric',
|
||||||
|
'order_type' => 'required',
|
||||||
|
];
|
||||||
|
|
||||||
|
if (!$this->validate($validationRules)) {
|
||||||
|
$response = [
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'Validation failed.',
|
||||||
|
'data' => $this->validator->getErrors()
|
||||||
|
];
|
||||||
|
return $this->respond($response, 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Process outlet_ids - convert to comma-separated string
|
||||||
|
$outletIds = $this->request->getPost('outlet_id');
|
||||||
|
|
||||||
|
// If it's an array (from multiple select), convert to comma-separated string
|
||||||
|
if (is_array($outletIds)) {
|
||||||
|
$outletIds = implode(',', $outletIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate that outlet_ids contain only integers and commas
|
||||||
|
if (!preg_match('/^[0-9,]+$/', $outletIds)) {
|
||||||
|
$response = [
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'Invalid outlet IDs format. Only integers and commas allowed.',
|
||||||
|
'data' => null
|
||||||
|
];
|
||||||
|
return $this->respond($response, 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'outlet_id' => $outletIds,
|
||||||
|
'tax_type' => $this->request->getPost('tax_type'),
|
||||||
|
'tax_rate' => $this->request->getPost('tax_rate'),
|
||||||
|
'order_type' => $this->request->getVar('order_type'),
|
||||||
|
];
|
||||||
|
|
||||||
|
$id = $this->taxModel->insert($data);
|
||||||
|
|
||||||
|
if ($id) {
|
||||||
|
$result = $this->taxModel->find($id);
|
||||||
|
$response = [
|
||||||
|
'status' => 'success',
|
||||||
|
'message' => 'Tax created successfully.',
|
||||||
|
'data' => $result
|
||||||
|
];
|
||||||
|
return $this->respond($response, 201);
|
||||||
|
}
|
||||||
|
|
||||||
|
$response = [
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'Failed to create tax entry.',
|
||||||
|
'data' => null
|
||||||
|
];
|
||||||
|
return $this->respond($response, 500);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function taxUpdate($id = null)
|
||||||
|
{
|
||||||
|
$tax = $this->taxModel->find($id);
|
||||||
|
if (!$tax) {
|
||||||
|
$response = [
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'Tax entry not found.',
|
||||||
|
'data' => null
|
||||||
|
];
|
||||||
|
return $this->respond($response, 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = [];
|
||||||
|
|
||||||
|
// Process outlet_ids if provided
|
||||||
|
if ($this->request->getPost('outlet_id')) {
|
||||||
|
$outletIds = $this->request->getPost('outlet_id');
|
||||||
|
|
||||||
|
// If it's an array, convert to comma-separated string
|
||||||
|
if (is_array($outletIds)) {
|
||||||
|
$outletIds = implode(',', $outletIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate that outlet_ids contain only integers and commas
|
||||||
|
if (!preg_match('/^[0-9,]+$/', $outletIds)) {
|
||||||
|
$response = [
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'Invalid outlet IDs format. Only integers and commas allowed.',
|
||||||
|
'data' => null
|
||||||
|
];
|
||||||
|
return $this->respond($response, 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
$data['outlet_id'] = $outletIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add other fields if provided
|
||||||
|
if ($this->request->getPost('tax_type')) {
|
||||||
|
$data['tax_type'] = $this->request->getPost('tax_type');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->request->getPost('tax_rate')) {
|
||||||
|
$data['tax_rate'] = $this->request->getPost('tax_rate');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->request->getVar('order_type')) {
|
||||||
|
$data['order_type'] = $this->request->getVar('order_type');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($data)) {
|
||||||
|
$response = [
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'No data provided to update.',
|
||||||
|
'data' => null
|
||||||
|
];
|
||||||
|
return $this->respond($response, 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->taxModel->update($id, $data);
|
||||||
|
$updated = $this->taxModel->find($id);
|
||||||
|
|
||||||
|
$response = [
|
||||||
|
'status' => 'success',
|
||||||
|
'message' => 'Tax updated successfully.',
|
||||||
|
'data' => $updated
|
||||||
|
];
|
||||||
|
return $this->respond($response, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function taxDelete($id = null)
|
||||||
|
{
|
||||||
|
$tax = $this->taxModel->find($id);
|
||||||
|
if (!$tax) {
|
||||||
|
$response = [
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'Tax entry not found.',
|
||||||
|
'data' => null
|
||||||
|
];
|
||||||
|
return $this->respond($response, 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->taxModel->delete($id);
|
||||||
|
$response = [
|
||||||
|
'status' => 'success',
|
||||||
|
'message' => 'Tax deleted successfully.',
|
||||||
|
'data' => null
|
||||||
|
];
|
||||||
|
return $this->respond($response, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// public function slideshowIndex()
|
||||||
|
// {
|
||||||
|
// $slides = $this->slideshowModel->findAll();
|
||||||
|
// return $this->respond(['status' => 200, 'result' => $slides]);
|
||||||
|
// }
|
||||||
|
public function slideshowIndex()
|
||||||
|
{
|
||||||
|
$allowedOrderFields = [
|
||||||
|
'order', 'created_at', 'updated_at', 'title', 'status'
|
||||||
|
];
|
||||||
|
|
||||||
|
$orderBy = $this->request->getGet('order_by') ?? 'order';
|
||||||
|
$sort = strtolower($this->request->getGet('sort')) === 'desc' ? 'DESC' : 'ASC';
|
||||||
|
$page = (int) ($this->request->getGet('page') ?? 1);
|
||||||
|
$limit = (int) ($this->request->getGet('limit') ?? 20);
|
||||||
|
|
||||||
|
if (!in_array($orderBy, $allowedOrderFields)) {
|
||||||
|
$orderBy = 'order';
|
||||||
|
}
|
||||||
|
|
||||||
|
$builder = $this->slideshowModel->orderBy($orderBy, $sort);
|
||||||
|
|
||||||
|
if ($this->slideshowModel->useSoftDeletes) {
|
||||||
|
$builder = $builder->where('deleted_at', null);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($limit > 0) {
|
||||||
|
$offset = ($page - 1) * $limit;
|
||||||
|
$slides = $builder->findAll($limit, $offset);
|
||||||
|
$total = $this->slideshowModel->where('deleted_at', null)->countAllResults();
|
||||||
|
} else {
|
||||||
|
$slides = $builder->findAll();
|
||||||
|
$total = count($slides);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 200,
|
||||||
|
'result' => $slides,
|
||||||
|
'pagination' => [
|
||||||
|
'page' => $page,
|
||||||
|
'limit' => $limit,
|
||||||
|
'total' => $total
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// SHOW a single slide by id
|
||||||
|
public function slideshowShow($id = null)
|
||||||
|
{
|
||||||
|
$slide = $this->slideshowModel->find($id);
|
||||||
|
if (!$slide) {
|
||||||
|
return $this->failNotFound('Slideshow not found.');
|
||||||
|
}
|
||||||
|
return $this->respond(['status' => 200, 'result' => $slide]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// CREATE a new slide
|
||||||
|
public function slideshowCreate()
|
||||||
|
{
|
||||||
|
$slideImage = $this->request->getFile('url');
|
||||||
|
$imageUrl = null;
|
||||||
|
$compressedImageUrl = null;
|
||||||
|
|
||||||
|
if ($slideImage && $slideImage->isValid() && !$slideImage->hasMoved()) {
|
||||||
|
$result = save_image_with_compression(
|
||||||
|
$slideImage,
|
||||||
|
FCPATH . 'backend/uploads/slideshow',
|
||||||
|
FCPATH . 'backend/uploads/slideshow_compressed',
|
||||||
|
900, // width of compressed version
|
||||||
|
80 // quality (0-100)
|
||||||
|
);
|
||||||
|
$imageUrl = base_url('backend/uploads/slideshow/' . basename($result['original']));
|
||||||
|
$compressedImageUrl = base_url('backend/uploads/slideshow_compressed/' . basename($result['compressed']));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'type' => $this->request->getVar('type'),
|
||||||
|
'title' => $this->request->getVar('title'),
|
||||||
|
'description' => $this->request->getVar('description'),
|
||||||
|
'order' => $this->request->getVar('order'),
|
||||||
|
'status' => $this->request->getVar('status'),
|
||||||
|
'url' => $imageUrl,
|
||||||
|
'compressed_url' => $compressedImageUrl,
|
||||||
|
];
|
||||||
|
|
||||||
|
$id = $this->slideshowModel->insert($data);
|
||||||
|
|
||||||
|
if ($id) {
|
||||||
|
$result = $this->slideshowModel->find($id);
|
||||||
|
return $this->respond(['status' => 200, 'message' => 'Slideshow created.', 'result' => $result]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->fail('Failed to create slideshow entry.');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// UPDATE an existing slide
|
||||||
|
public function slideshowUpdate($id = null)
|
||||||
|
{
|
||||||
|
$slide = $this->slideshowModel->find($id);
|
||||||
|
if (!$slide) {
|
||||||
|
return $this->failNotFound('Slideshow not found.');
|
||||||
|
}
|
||||||
|
$input = $this->request->getVar();
|
||||||
|
$file = $this->request->getFile('url');
|
||||||
|
if ($file && $file->isValid() && !$file->hasMoved()) {
|
||||||
|
$result = save_image_with_compression(
|
||||||
|
$file,
|
||||||
|
FCPATH . 'backend/uploads/slideshow',
|
||||||
|
FCPATH . 'backend/uploads/slideshow_compressed',
|
||||||
|
900, // width of compressed version
|
||||||
|
80 // quality
|
||||||
|
);
|
||||||
|
$input['url'] = base_url('backend/uploads/slideshow/' . basename($result['original']));
|
||||||
|
$input['compressed_url'] = base_url('backend/uploads/slideshow_compressed/' . basename($result['compressed']));
|
||||||
|
} else if ($this->request->getVar('url')) {
|
||||||
|
$input['url'] = $this->request->getVar('url');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// print_r($data);exit;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$data = array_filter([
|
||||||
|
'type' => $input['type'] ?? null,
|
||||||
|
'url' => $input['url'] ?? null,
|
||||||
|
'compressed_url' => $input['compressed_url'] ?? null,
|
||||||
|
'title' => $input['title'] ?? null,
|
||||||
|
'description' => $input['description'] ?? null,
|
||||||
|
'order' => $input['order'] ?? null,
|
||||||
|
'status' => $input['status'] ?? null,
|
||||||
|
], function ($value) {
|
||||||
|
return $value !== null;
|
||||||
|
});
|
||||||
|
// print_r($data);exit;
|
||||||
|
|
||||||
|
|
||||||
|
if (empty($data)) {
|
||||||
|
return $this->fail('No data provided to update.');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$this->slideshowModel->update($id, $data);
|
||||||
|
$updated = $this->slideshowModel->find($id);
|
||||||
|
|
||||||
|
return $this->respond(['status' => 200, 'message' => 'Slideshow updated.', 'result' => $updated]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// DELETE a slide
|
||||||
|
public function slideshowDelete($id = null)
|
||||||
|
{
|
||||||
|
$slide = $this->slideshowModel->find($id);
|
||||||
|
if (!$slide) {
|
||||||
|
return $this->failNotFound('Slideshow entry not found.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->slideshowModel->delete($id);
|
||||||
|
return $this->respond(['status' => 200, 'message' => 'Slideshow deleted Successfully.']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createCheckinRule()
|
||||||
|
{
|
||||||
|
$checkinCount = $this->request->getVar('checkin_count');
|
||||||
|
$rewardPoint = $this->request->getVar('reward_point');
|
||||||
|
|
||||||
|
if ($checkinCount === null || $rewardPoint === null) {
|
||||||
|
$response = [
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'Check-in count and Reward point are required.',
|
||||||
|
'data' => null
|
||||||
|
];
|
||||||
|
return $this->respond($response, 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure both are positive numbers
|
||||||
|
if (!is_numeric($checkinCount) || $checkinCount <= 0 || !is_numeric($rewardPoint) || $rewardPoint <= 0) {
|
||||||
|
$response = [
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'Both Check-in count and reward point must be positive numbers.',
|
||||||
|
'data' => null
|
||||||
|
];
|
||||||
|
return $this->respond($response, 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for duplicate checkin_count
|
||||||
|
$existing = $this->checkinRuleModel->where('checkin_count', (int)$checkinCount)->first();
|
||||||
|
if ($existing) {
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'A rule with the same check-in count already exists.',
|
||||||
|
'data' => null
|
||||||
|
], 409);
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'checkin_count' => (int) $checkinCount,
|
||||||
|
'reward_point' => number_format((float) $rewardPoint, 2, '.', '')
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->checkinRuleModel->insert($data);
|
||||||
|
|
||||||
|
$response = [
|
||||||
|
'status' => 'success',
|
||||||
|
'message' => 'Check-in rule created successfully.',
|
||||||
|
'data' => $data
|
||||||
|
];
|
||||||
|
return $this->respond($response, 201);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCheckinRules()
|
||||||
|
{
|
||||||
|
$rules = $this->checkinRuleModel
|
||||||
|
->orderBy('checkin_count', 'DESC')
|
||||||
|
->findAll();
|
||||||
|
|
||||||
|
$response = [
|
||||||
|
'status' => 'success',
|
||||||
|
'message' => 'Check-in rules retrieved successfully.',
|
||||||
|
'data' => $rules
|
||||||
|
];
|
||||||
|
|
||||||
|
return $this->respond($response, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateCheckinRule($id)
|
||||||
|
{
|
||||||
|
$checkinCount = $this->request->getVar('checkin_count');
|
||||||
|
$rewardPoint = $this->request->getVar('reward_point');
|
||||||
|
|
||||||
|
// Check if rule exists
|
||||||
|
$rule = $this->checkinRuleModel->find($id);
|
||||||
|
if (!$rule) {
|
||||||
|
$response = [
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'Check-in rule not found.',
|
||||||
|
'data' => null
|
||||||
|
];
|
||||||
|
return $this->respond($response, 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate input
|
||||||
|
if ($checkinCount === null || $rewardPoint === null) {
|
||||||
|
$response = [
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'checkin_count and reward_point are required.',
|
||||||
|
'data' => null
|
||||||
|
];
|
||||||
|
return $this->respond($response, 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!is_numeric($checkinCount) || $checkinCount <= 0 || !is_numeric($rewardPoint) || $rewardPoint <= 0) {
|
||||||
|
$response = [
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'Both checkin_count and reward_point must be positive numbers.',
|
||||||
|
'data' => null
|
||||||
|
];
|
||||||
|
return $this->respond($response, 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
$existing = $this->checkinRuleModel
|
||||||
|
->where('checkin_count', (int)$checkinCount)
|
||||||
|
->where('id !=', $id)
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if ($existing) {
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'Another rule with the same check-in count already exists.',
|
||||||
|
'data' => null
|
||||||
|
], 409);
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'checkin_count' => (int) $checkinCount,
|
||||||
|
'reward_point' => (float) $rewardPoint,
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->checkinRuleModel->update($id, $data);
|
||||||
|
$response = [
|
||||||
|
'status' => 'success',
|
||||||
|
'message' => 'Check-in rule updated successfully.',
|
||||||
|
'data' => $data
|
||||||
|
];
|
||||||
|
return $this->respond($response, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function deleteCheckinRule($id)
|
||||||
|
{
|
||||||
|
// Check if the rule exists
|
||||||
|
$rule = $this->checkinRuleModel->find($id);
|
||||||
|
if (!$rule) {
|
||||||
|
$response = [
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'Check-in rule not found.',
|
||||||
|
'data' => null
|
||||||
|
];
|
||||||
|
return $this->respond($response, 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete the rule
|
||||||
|
$this->checkinRuleModel->delete($id);
|
||||||
|
|
||||||
|
$response = [
|
||||||
|
'status' => 'success',
|
||||||
|
'message' => 'Check-in rule deleted successfully.',
|
||||||
|
'data' => ['id' => $id]
|
||||||
|
];
|
||||||
|
return $this->respond($response, 200);
|
||||||
|
}
|
||||||
|
}
|
||||||
147
app/Controllers/Backend/StoreDiscountController.php
Normal file
147
app/Controllers/Backend/StoreDiscountController.php
Normal file
@ -0,0 +1,147 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controllers\Backend;
|
||||||
|
|
||||||
|
use CodeIgniter\RESTful\ResourceController;
|
||||||
|
|
||||||
|
use App\Models\StoreDiscount;
|
||||||
|
|
||||||
|
class StoreDiscountController extends ResourceController
|
||||||
|
{
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
$storeDiscountModel = new StoreDiscount();
|
||||||
|
$data = $storeDiscountModel->findAll();
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 'success',
|
||||||
|
'message' => 'Store discounts fetched successfully',
|
||||||
|
'data' => $data
|
||||||
|
], 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function show($id = null)
|
||||||
|
{
|
||||||
|
$storeDiscountModel = new StoreDiscount();
|
||||||
|
$data = $storeDiscountModel->find($id);
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 'success',
|
||||||
|
'message' => 'Store discount fetched successfully',
|
||||||
|
'data' => $data
|
||||||
|
], 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create()
|
||||||
|
{
|
||||||
|
|
||||||
|
$rules = [
|
||||||
|
'discount_name' => 'required|string',
|
||||||
|
'discount_type' => 'required|string',
|
||||||
|
'discount_value' => 'required|numeric',
|
||||||
|
'outlet_list' => 'required|is_array',
|
||||||
|
'menu_item_list' => 'required|is_array',
|
||||||
|
'status' => 'required|string',
|
||||||
|
];
|
||||||
|
if (!$this->validate($rules)) {
|
||||||
|
return $this->failValidationErrors($this->validator->getErrors());
|
||||||
|
}
|
||||||
|
|
||||||
|
$storeDiscountModel = new StoreDiscount();
|
||||||
|
// Insert data to database outlet_list is array and store it in JSON
|
||||||
|
$discount_name = $this->request->getVar('discount_name');
|
||||||
|
$discount_type = $this->request->getVar('discount_type');
|
||||||
|
$discount_value = $this->request->getVar('discount_value');
|
||||||
|
$outlet_list = $this->request->getVar('outlet_list');
|
||||||
|
$menu_item_list = $this->request->getVar('menu_item_list');
|
||||||
|
$status = $this->request->getVar('status');
|
||||||
|
|
||||||
|
$implode_outlet_list = implode(',', $outlet_list);
|
||||||
|
$implode_menu_item_list = implode(',', $menu_item_list);
|
||||||
|
$data = [
|
||||||
|
'discount_name' => $discount_name,
|
||||||
|
'discount_type' => $discount_type,
|
||||||
|
'discount_value' => $discount_value,
|
||||||
|
'outlet_list' => $implode_outlet_list,
|
||||||
|
'menu_item_list' => $implode_menu_item_list,
|
||||||
|
'status' => $status,
|
||||||
|
'created_at' => date('Y-m-d H:i:s'),
|
||||||
|
'updated_at' => date('Y-m-d H:i:s'),
|
||||||
|
];
|
||||||
|
|
||||||
|
$storeDiscountModel->insert($data);
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 'success',
|
||||||
|
'message' => 'Store discount created successfully',
|
||||||
|
'data' => $data
|
||||||
|
], 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update($id = null)
|
||||||
|
{
|
||||||
|
$storeDiscountModel = new StoreDiscount();
|
||||||
|
$storeDiscount = $storeDiscountModel->find($id);
|
||||||
|
if(!$storeDiscount) {
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'Store discount not found',
|
||||||
|
'data' => null
|
||||||
|
], 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
$rules = [
|
||||||
|
'discount_name' => 'required|string',
|
||||||
|
'discount_type' => 'required|string',
|
||||||
|
'discount_value' => 'required|numeric',
|
||||||
|
'outlet_list' => 'required|is_array',
|
||||||
|
'menu_item_list' => 'required|is_array',
|
||||||
|
'status' => 'required|string',
|
||||||
|
];
|
||||||
|
if (!$this->validate($rules)) {
|
||||||
|
return $this->failValidationErrors($this->validator->getErrors());
|
||||||
|
}
|
||||||
|
|
||||||
|
$discount_name = $this->request->getVar('discount_name');
|
||||||
|
$discount_type = $this->request->getVar('discount_type');
|
||||||
|
$discount_value = $this->request->getVar('discount_value');
|
||||||
|
$outlet_list = $this->request->getVar('outlet_list');
|
||||||
|
$menu_item_list = $this->request->getVar('menu_item_list');
|
||||||
|
$status = $this->request->getVar('status');
|
||||||
|
|
||||||
|
$implode_outlet_list = implode(',', $outlet_list);
|
||||||
|
$implode_menu_item_list = implode(',', $menu_item_list);
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'discount_name' => $discount_name,
|
||||||
|
'discount_type' => $discount_type,
|
||||||
|
'discount_value' => $discount_value,
|
||||||
|
'outlet_list' => $implode_outlet_list,
|
||||||
|
'menu_item_list' => $implode_menu_item_list,
|
||||||
|
'status' => $status,
|
||||||
|
'updated_at' => date('Y-m-d H:i:s'),
|
||||||
|
];
|
||||||
|
$storeDiscountModel->update($id, $data);
|
||||||
|
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 'success',
|
||||||
|
'message' => 'Store discount updated successfully',
|
||||||
|
'data' => $data
|
||||||
|
], 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete($id = null){
|
||||||
|
$storeDiscountModel = new StoreDiscount();
|
||||||
|
$storeDiscount = $storeDiscountModel->find($id);
|
||||||
|
if(!$storeDiscount) {
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'Store discount not found',
|
||||||
|
'data' => null
|
||||||
|
], 404);
|
||||||
|
}
|
||||||
|
$storeDiscountModel->delete($id);
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 'success',
|
||||||
|
'message' => 'Store discount deleted successfully',
|
||||||
|
'data' => null
|
||||||
|
], 200);
|
||||||
|
}
|
||||||
|
}
|
||||||
167
app/Controllers/Backend/TagController.php
Normal file
167
app/Controllers/Backend/TagController.php
Normal file
@ -0,0 +1,167 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controllers\Backend;
|
||||||
|
|
||||||
|
use App\Models\Tags;
|
||||||
|
use CodeIgniter\HTTP\ResponseInterface;
|
||||||
|
use CodeIgniter\RESTful\ResourceController;
|
||||||
|
|
||||||
|
class TagController extends ResourceController
|
||||||
|
{
|
||||||
|
private $tags;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->tags = new Tags();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
$tags = $this->tags->findAll();
|
||||||
|
|
||||||
|
if (empty($tags)) {
|
||||||
|
return $this->fail("No tags found.", 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
$tagData = [];
|
||||||
|
|
||||||
|
foreach ($tags as $tag) {
|
||||||
|
$tagData[] = [
|
||||||
|
'id' => $tag['id'],
|
||||||
|
'title' => $tag['title'],
|
||||||
|
'icon_url' => getImagePath('tags', $tag['icon_url']),
|
||||||
|
'created_at' => $tag['created_at'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 200,
|
||||||
|
'message' => 'Tags found.',
|
||||||
|
'data' => $tagData
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function show($id = null)
|
||||||
|
{
|
||||||
|
$tag = $this->tags->find($id);
|
||||||
|
|
||||||
|
if (empty($tag)) {
|
||||||
|
return $this->fail("Tag not found.", 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
$tag['icon_url'] = getImagePath('tags', $tag['icon_url']);
|
||||||
|
|
||||||
|
unset($tag['updated_at']);
|
||||||
|
unset($tag['deleted_at']);
|
||||||
|
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 200,
|
||||||
|
'message' => 'Tag found.',
|
||||||
|
'data' => $tag
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create()
|
||||||
|
{
|
||||||
|
$validation = $this->validate([
|
||||||
|
'title' => 'required',
|
||||||
|
'icon' => 'permit_empty|is_image[icon]',
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (!$validation) {
|
||||||
|
return $this->failValidationErrors($this->validator->getErrors());
|
||||||
|
}
|
||||||
|
|
||||||
|
$title = $this->request->getVar('title');
|
||||||
|
$icon = $this->request->getFile('icon');
|
||||||
|
$iconPath = '';
|
||||||
|
|
||||||
|
$tag = ['title' => $title];
|
||||||
|
|
||||||
|
$id = $this->tags->insert($tag);
|
||||||
|
|
||||||
|
if (!$id) {
|
||||||
|
return $this->fail('Failed to create tag.', 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($icon && $icon->isValid() && !$icon->hasMoved()) {
|
||||||
|
$uploadPath = $_SERVER['DOCUMENT_ROOT'] . '/backend/uploads/tags/';
|
||||||
|
|
||||||
|
if (!is_dir($uploadPath)) {
|
||||||
|
mkdir($uploadPath, 0755, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
$newIconName = $id . '_' . time() . '.png';
|
||||||
|
$icon->move($uploadPath, $newIconName);
|
||||||
|
$iconPath = $newIconName;
|
||||||
|
|
||||||
|
$this->tags->update($id, ['icon_url' => $iconPath]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 200,
|
||||||
|
'message' => 'Tag successfully created!'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update($id = null)
|
||||||
|
{
|
||||||
|
$tag = $this->tags->find($id);
|
||||||
|
|
||||||
|
if (empty($tag)) {
|
||||||
|
return $this->fail("Tag not found.", 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
$validation = $this->validate([
|
||||||
|
'title' => 'required',
|
||||||
|
'icon' => 'permit_empty|is_image[icon]',
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (!$validation) {
|
||||||
|
return $this->failValidationErrors($this->validator->getErrors());
|
||||||
|
}
|
||||||
|
|
||||||
|
$title = $this->request->getVar('title');
|
||||||
|
$icon = $this->request->getFile('icon');
|
||||||
|
|
||||||
|
$updatedData = ['title' => $title];
|
||||||
|
$iconPath = $tag['icon_url'];
|
||||||
|
|
||||||
|
if ($icon && $icon->isValid() && !$icon->hasMoved()) {
|
||||||
|
$uploadPath = $_SERVER['DOCUMENT_ROOT'] . '/backend/uploads/tags/';
|
||||||
|
|
||||||
|
if (!is_dir($uploadPath)) {
|
||||||
|
mkdir($uploadPath, 0755, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
$newIconName = $id . '_' . time() . '.png';
|
||||||
|
$icon->move($uploadPath, $newIconName);
|
||||||
|
$iconPath = $newIconName;
|
||||||
|
}
|
||||||
|
|
||||||
|
$updatedData['icon_url'] = $iconPath;
|
||||||
|
|
||||||
|
$this->tags->update($id, $updatedData);
|
||||||
|
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 200,
|
||||||
|
'message' => 'Tag successfully updated!'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete($id = null)
|
||||||
|
{
|
||||||
|
$tag = $this->tags->find($id);
|
||||||
|
|
||||||
|
if (empty($tag)) {
|
||||||
|
return $this->fail('Tag not found.', 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->tags->delete($id);
|
||||||
|
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 200,
|
||||||
|
'message' => 'Tag successfully deleted!'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
173
app/Controllers/Backend/TopupController.php
Normal file
173
app/Controllers/Backend/TopupController.php
Normal file
@ -0,0 +1,173 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controllers\Backend;
|
||||||
|
|
||||||
|
use App\Controllers\BaseController;
|
||||||
|
use CodeIgniter\HTTP\ResponseInterface;
|
||||||
|
use App\Models\TopupModel;
|
||||||
|
use CodeIgniter\HTTP\ResponseTrait;
|
||||||
|
use CodeIgniter\RESTful\ResourceController;
|
||||||
|
|
||||||
|
|
||||||
|
class TopupController extends ResourceController
|
||||||
|
{
|
||||||
|
|
||||||
|
use ResponseTrait;
|
||||||
|
private $topups;
|
||||||
|
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->topups = new TopupModel();
|
||||||
|
}
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
// echo(123);exit;
|
||||||
|
$data = $this->topups
|
||||||
|
->select('topup.*, customers.customer_wallet, customers.phone, customers.name')
|
||||||
|
->join('customers', 'customers.id = topup.customer_id', 'left')
|
||||||
|
->orderBy('topup.created_at', 'DESC')
|
||||||
|
->findAll();
|
||||||
|
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 200,
|
||||||
|
'data' => $data,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create()
|
||||||
|
{
|
||||||
|
// echo('123'); exit;
|
||||||
|
|
||||||
|
$payload = $this->request->getJSON(true) ?? $this->request->getPost();
|
||||||
|
|
||||||
|
$rules = [
|
||||||
|
'customer_id' => 'required|integer',
|
||||||
|
'amount' => 'required|decimal|greater_than[0]',
|
||||||
|
'payment_method' => 'required|string|max_length[50]',
|
||||||
|
'topup_setting_id' => 'permit_empty|integer',
|
||||||
|
'credit' => 'permit_empty|decimal',
|
||||||
|
'other_amount' => 'permit_empty|decimal',
|
||||||
|
'status' => 'permit_empty|in_list[pending,completed,failed]'
|
||||||
|
];
|
||||||
|
// echo(123);
|
||||||
|
|
||||||
|
if (!$this->validate($rules)) {
|
||||||
|
return $this->failValidationErrors($this->validator->getErrors());
|
||||||
|
}
|
||||||
|
|
||||||
|
$topupNumber = 'Test-123123';
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'topup_setting_id' => $payload['topup_setting_id'] ?? null,
|
||||||
|
'customer_id' => $payload['customer_id'],
|
||||||
|
'topup_number' => $topupNumber,
|
||||||
|
'amount' => $payload['amount'],
|
||||||
|
'credit' => $payload['credit'],
|
||||||
|
'payment_method' => $payload['payment_method'],
|
||||||
|
'other_amount' => $payload['other_amount'] ?? null,
|
||||||
|
'status' => $payload['status']
|
||||||
|
];
|
||||||
|
|
||||||
|
$id = $this->topups->insert($data, true);
|
||||||
|
|
||||||
|
if (!$id) {
|
||||||
|
return $this->fail('Topup creation failed', 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 201,
|
||||||
|
'message' => 'Topup created successfully',
|
||||||
|
'data' => $this->topups->find($id)
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update($id = null)
|
||||||
|
{
|
||||||
|
$id = (int) $id;
|
||||||
|
if (!$this->topups->find($id)) {
|
||||||
|
return $this->fail('Topup not found', 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
$payload = $this->request->getJSON(true) ?? $this->request->getPost();
|
||||||
|
|
||||||
|
$rules = [
|
||||||
|
'status' => 'permit_empty|in_list[pending,completed,failed]',
|
||||||
|
'amount' => 'permit_empty|decimal|greater_than[0]',
|
||||||
|
'credit' => 'permit_empty|decimal',
|
||||||
|
'payment_method' => 'permit_empty|string|max_length[50]'
|
||||||
|
];
|
||||||
|
|
||||||
|
if (!$this->validate($rules)) {
|
||||||
|
return $this->failValidationErrors($this->validator->getErrors());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$this->topups->update($id, $payload)) {
|
||||||
|
return $this->fail('Update failed', 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 200,
|
||||||
|
'message' => 'Topup updated successfully',
|
||||||
|
'data' => $this->topups->find($id)
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete($id = null)
|
||||||
|
{
|
||||||
|
$id = (int) $id;
|
||||||
|
if (!$this->topups->find($id)) {
|
||||||
|
return $this->fail('Topup not found', 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$this->topups->delete($id)) {
|
||||||
|
return $this->fail('Delete failed', 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 200,
|
||||||
|
'message' => 'Topup deleted successfully'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function show($id = null)
|
||||||
|
{
|
||||||
|
$id = (int) $id;
|
||||||
|
|
||||||
|
$row = $this->topups
|
||||||
|
->select('topup.*, topup_setting.id AS setting_id, topup_setting.topup_amount, topup_setting.credit_amount, topup_setting.status AS setting_status')
|
||||||
|
->join('topup_setting', 'topup_setting.id = topup.topup_setting_id', 'left')
|
||||||
|
->where('topup.id', $id)
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if (!$row) {
|
||||||
|
return $this->failNotFound('Topup record not found');
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'id' => $row['id'],
|
||||||
|
'topup_setting_id' => $row['topup_setting_id'],
|
||||||
|
'customer_id' => $row['customer_id'],
|
||||||
|
'topup_number' => $row['topup_number'],
|
||||||
|
'amount' => $row['amount'],
|
||||||
|
'credit' => $row['credit'],
|
||||||
|
'payment_method' => $row['payment_method'],
|
||||||
|
'other_amount' => $row['other_amount'],
|
||||||
|
'status' => $row['status'],
|
||||||
|
'created_at' => $row['created_at'],
|
||||||
|
'updated_at' => $row['updated_at'],
|
||||||
|
'topup_setting' => [
|
||||||
|
'id' => $row['setting_id'],
|
||||||
|
'topup_amount' => $row['topup_amount'],
|
||||||
|
'credit_amount' => $row['credit_amount'],
|
||||||
|
'status' => $row['setting_status']
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 200,
|
||||||
|
'data' => $data
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
112
app/Controllers/Backend/TopupSettingController.php
Normal file
112
app/Controllers/Backend/TopupSettingController.php
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controllers\Backend;
|
||||||
|
|
||||||
|
use App\Controllers\BaseController;
|
||||||
|
use App\Models\TopupSettingModel;
|
||||||
|
use CodeIgniter\API\ResponseTrait;
|
||||||
|
use CodeIgniter\RESTful\ResourceController;
|
||||||
|
|
||||||
|
class TopupSettingController extends ResourceController
|
||||||
|
{
|
||||||
|
use ResponseTrait;
|
||||||
|
|
||||||
|
private $settings;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->settings = new TopupSettingModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
$data = $this->settings
|
||||||
|
->orderBy('created_at', 'DESC')
|
||||||
|
->findAll();
|
||||||
|
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 200,
|
||||||
|
'data' => $data,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create()
|
||||||
|
{
|
||||||
|
// echo(123123);exit;
|
||||||
|
$payload = $this->request->getJSON(true) ?? $this->request->getPost();
|
||||||
|
|
||||||
|
$rules = [
|
||||||
|
'topup_amount' => 'required|decimal|greater_than[0]',
|
||||||
|
'credit_amount' => 'required|decimal|greater_than_equal_to[0]',
|
||||||
|
'status' => 'required|in_list[active,inactive]',
|
||||||
|
];
|
||||||
|
|
||||||
|
if (! $this->validate($rules)) {
|
||||||
|
return $this->failValidationErrors($this->validator->getErrors());
|
||||||
|
}
|
||||||
|
|
||||||
|
$id = $this->settings->insert([
|
||||||
|
'topup_amount' => $payload['topup_amount'],
|
||||||
|
'credit_amount' => $payload['credit_amount'],
|
||||||
|
'status' => $payload['status'],
|
||||||
|
], true);
|
||||||
|
|
||||||
|
if (! $id) {
|
||||||
|
return $this->fail('Create failed', 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 200,
|
||||||
|
'message' => 'Topup Setting Created',
|
||||||
|
'data' => $this->settings->find($id),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update($id = null)
|
||||||
|
{
|
||||||
|
// echo(123);exit;
|
||||||
|
$id = (int) $id;
|
||||||
|
if (! $this->settings->find($id)) {
|
||||||
|
return $this->fail('Not found', 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
$payload = $this->request->getJSON(true) ?? $this->request->getRawInput();
|
||||||
|
|
||||||
|
$rules = [
|
||||||
|
'topup_amount' => 'permit_empty|decimal|greater_than[0]',
|
||||||
|
'credit_amount' => 'permit_empty|decimal|greater_than_equal_to[0]',
|
||||||
|
'status' => 'permit_empty|in_list[active,inactive]',
|
||||||
|
];
|
||||||
|
|
||||||
|
if (! $this->validate($rules)) {
|
||||||
|
return $this->failValidationErrors($this->validator->getErrors());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $this->settings->update($id, $payload)) {
|
||||||
|
return $this->fail('Update failed', 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 200,
|
||||||
|
'message' => 'Topup Setting Updated',
|
||||||
|
'data' => $this->settings->find($id),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete($id = null)
|
||||||
|
{
|
||||||
|
$id = (int) $id;
|
||||||
|
if (! $this->settings->find($id)) {
|
||||||
|
return $this->fail('Not found', 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $this->settings->delete($id)) {
|
||||||
|
return $this->fail('Delete failed', 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 200,
|
||||||
|
'message' => 'Topup Setting deleted',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
327
app/Controllers/Backend/UserController.php
Normal file
327
app/Controllers/Backend/UserController.php
Normal file
@ -0,0 +1,327 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controllers\Backend;
|
||||||
|
|
||||||
|
use App\Controllers\BaseController;
|
||||||
|
use App\Models\User;
|
||||||
|
use CodeIgniter\HTTP\ResponseInterface;
|
||||||
|
use App\Models\Outlet;
|
||||||
|
use CodeIgniter\RESTful\ResourceController;
|
||||||
|
|
||||||
|
class UserController extends ResourceController
|
||||||
|
{
|
||||||
|
private $user;
|
||||||
|
private $outletModel;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->user = new User();
|
||||||
|
$this->outletModel = new Outlet();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
$user_id = $this->request->getVar('user_id');
|
||||||
|
|
||||||
|
// Get the requesting user's data to check their role
|
||||||
|
$requesting_user = $this->user->find($user_id);
|
||||||
|
|
||||||
|
if (!$requesting_user) {
|
||||||
|
$response = [
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'Requesting user not found.',
|
||||||
|
'data' => null
|
||||||
|
];
|
||||||
|
return $this->respond($response, 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If user is admin, get all users
|
||||||
|
if ($requesting_user['role'] === 'admin') {
|
||||||
|
$users = $this->user->findAll();
|
||||||
|
} else {
|
||||||
|
// If not admin, only return their own data
|
||||||
|
$users = [$this->user->find($user_id)];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($users)) {
|
||||||
|
$response = [
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'No user data found.',
|
||||||
|
'data' => null
|
||||||
|
];
|
||||||
|
return $this->respond($response, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
$response = [
|
||||||
|
'status' => 'success',
|
||||||
|
'message' => 'User data retrieved successfully.',
|
||||||
|
'data' => $users
|
||||||
|
];
|
||||||
|
return $this->respond($response, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Create User Function
|
||||||
|
public function create()
|
||||||
|
{
|
||||||
|
$validationRules = [
|
||||||
|
'username' => 'required',
|
||||||
|
'name' => 'required',
|
||||||
|
'password_hash' => 'required',
|
||||||
|
'role' => 'required',
|
||||||
|
'status' => 'required',
|
||||||
|
];
|
||||||
|
|
||||||
|
// Add conditional validation for outlet_id when role is 'Outlet'
|
||||||
|
if ($this->request->getVar('role') === 'outlet') {
|
||||||
|
$validationRules['outlet_id'] = 'required|integer';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$this->validate($validationRules)) {
|
||||||
|
$response = [
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'Validation failed.',
|
||||||
|
'data' => $this->validator->getErrors()
|
||||||
|
];
|
||||||
|
return $this->respond($response, 422);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get menu permissions from request
|
||||||
|
$menuPermissions = $this->request->getVar('menuPermissions');
|
||||||
|
|
||||||
|
// Convert permissions to JSON string if they exist
|
||||||
|
$permissionsJson = null;
|
||||||
|
if ($menuPermissions) {
|
||||||
|
$permissionsJson = json_encode($menuPermissions);
|
||||||
|
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||||
|
$response = [
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'Invalid permissions format.',
|
||||||
|
'data' => null
|
||||||
|
];
|
||||||
|
return $this->respond($response, 400);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$userData = [
|
||||||
|
'username' => $this->request->getVar('username'),
|
||||||
|
'name' => $this->request->getVar('name'),
|
||||||
|
'password_hash' => md5($this->request->getVar('password_hash')),
|
||||||
|
'role' => $this->request->getVar('role'),
|
||||||
|
'status' => $this->request->getVar('status'),
|
||||||
|
'user_permissions' => $permissionsJson, // Store permissions as JSON string
|
||||||
|
];
|
||||||
|
|
||||||
|
// Only add outlet_id if role is 'Outlet'
|
||||||
|
if ($this->request->getVar('role') === 'outlet') {
|
||||||
|
$userData['outlet_id'] = $this->request->getVar('outlet_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
$id = $this->user->insert($userData);
|
||||||
|
|
||||||
|
if ($id) {
|
||||||
|
$result = $this->user->find($id);
|
||||||
|
|
||||||
|
$response = [
|
||||||
|
'status' => 'success',
|
||||||
|
'message' => 'User created successfully.',
|
||||||
|
'data' => $result
|
||||||
|
];
|
||||||
|
return $this->respond($response, 201);
|
||||||
|
}
|
||||||
|
|
||||||
|
$response = [
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'Failed to create user.',
|
||||||
|
'data' => null
|
||||||
|
];
|
||||||
|
return $this->respond($response, 500);
|
||||||
|
}
|
||||||
|
|
||||||
|
// show the required data.
|
||||||
|
public function show($id = null)
|
||||||
|
{
|
||||||
|
$user = $this->user->find($id);
|
||||||
|
|
||||||
|
if (!$user) {
|
||||||
|
$response = [
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'User not found.',
|
||||||
|
'data' => null
|
||||||
|
];
|
||||||
|
return $this->respond($response, 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
$response = [
|
||||||
|
'status' => 'success',
|
||||||
|
'message' => 'User retrieved successfully.',
|
||||||
|
'data' => $user
|
||||||
|
];
|
||||||
|
return $this->respond($response, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the data
|
||||||
|
public function update($id = null)
|
||||||
|
{
|
||||||
|
// Find existing user
|
||||||
|
$existingUser = $this->user->find($id);
|
||||||
|
|
||||||
|
if (!$existingUser) {
|
||||||
|
$response = [
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'User not found.',
|
||||||
|
'data' => null
|
||||||
|
];
|
||||||
|
return $this->respond($response, 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get new data from request
|
||||||
|
$input = $this->request->getJSON(true); // Get JSON data
|
||||||
|
if (empty($input)) {
|
||||||
|
// fallback: try to get POST vars
|
||||||
|
$input = $this->request->getPost();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prepare data array only with fields that are present
|
||||||
|
$data = [];
|
||||||
|
|
||||||
|
// Map frontend field names to backend field names
|
||||||
|
if (isset($input['username'])) {
|
||||||
|
$data['username'] = $input['username'];
|
||||||
|
}
|
||||||
|
if (isset($input['name'])) {
|
||||||
|
$data['name'] = $input['name'];
|
||||||
|
}
|
||||||
|
if (isset($input['password'])) {
|
||||||
|
$data['password_hash'] = password_hash($input['password'], PASSWORD_DEFAULT);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle userRoles -> role mapping
|
||||||
|
if (isset($input['role'])) {
|
||||||
|
$data['role'] = $input['role'];
|
||||||
|
|
||||||
|
// Handle outlet_id based on role change
|
||||||
|
if ($input['role'] === 'outlet') {
|
||||||
|
// Require outlet_id when changing to Outlet role
|
||||||
|
if (!isset($input['outlet_id'])) {
|
||||||
|
$response = [
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'Outlet ID is required when role is Outlet.',
|
||||||
|
'data' => null
|
||||||
|
];
|
||||||
|
return $this->respond($response, 422);
|
||||||
|
}
|
||||||
|
$data['outlet_id'] = $input['outlet_id'];
|
||||||
|
} else {
|
||||||
|
// Clear outlet_id when changing to non-Outlet role
|
||||||
|
$data['outlet_id'] = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle activeStatus -> status mapping
|
||||||
|
if (isset($input['activeStatus'])) {
|
||||||
|
$data['status'] = strtolower($input['activeStatus']);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle outlet separately if role isn't being changed but user is Outlet
|
||||||
|
if (isset($input['outlet']) && $existingUser['role'] === 'outlet') {
|
||||||
|
$data['outlet_id'] = $input['outlet'];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle menu permissions
|
||||||
|
if (isset($input['menuPermissions'])) {
|
||||||
|
$menuPermissions = $input['menuPermissions'];
|
||||||
|
$permissionsJson = null;
|
||||||
|
|
||||||
|
if ($menuPermissions && is_array($menuPermissions)) {
|
||||||
|
if (!empty($menuPermissions)) {
|
||||||
|
$permissionsJson = json_encode($menuPermissions);
|
||||||
|
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||||
|
$response = [
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'Invalid permissions format.',
|
||||||
|
'data' => null
|
||||||
|
];
|
||||||
|
return $this->respond($response, 400);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$data['user_permissions'] = $permissionsJson;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If no fields to update, return an error
|
||||||
|
if (empty($data)) {
|
||||||
|
$response = [
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'No data provided to update.',
|
||||||
|
'data' => null
|
||||||
|
];
|
||||||
|
return $this->respond($response, 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate outlet_id if being set
|
||||||
|
if (isset($data['outlet_id']) && $data['outlet_id'] !== null) {
|
||||||
|
if (!$this->outletModel->find($data['outlet_id'])) {
|
||||||
|
$response = [
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'Specified outlet does not exist.',
|
||||||
|
'data' => null
|
||||||
|
];
|
||||||
|
return $this->respond($response, 422);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add updated_at timestamp
|
||||||
|
$data['updated_at'] = date('Y-m-d H:i:s');
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Update user
|
||||||
|
$this->user->update($id, $data);
|
||||||
|
|
||||||
|
// Return updated user data
|
||||||
|
$updatedUser = $this->user->find($id);
|
||||||
|
|
||||||
|
$response = [
|
||||||
|
'status' => 'success',
|
||||||
|
'message' => 'User updated successfully.',
|
||||||
|
'data' => $updatedUser
|
||||||
|
];
|
||||||
|
return $this->respond($response, 200);
|
||||||
|
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
log_message('error', 'User update failed: ' . $e->getMessage());
|
||||||
|
|
||||||
|
$response = [
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'Failed to update user.',
|
||||||
|
'data' => null
|
||||||
|
];
|
||||||
|
return $this->respond($response, 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Delete User Function
|
||||||
|
public function delete($id = null)
|
||||||
|
{
|
||||||
|
$existingUser = $this->user->find($id);
|
||||||
|
|
||||||
|
if (!$existingUser) {
|
||||||
|
$response = [
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'User not found.',
|
||||||
|
'data' => null
|
||||||
|
];
|
||||||
|
return $this->respond($response, 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->user->delete($id);
|
||||||
|
|
||||||
|
$response = [
|
||||||
|
'status' => 'success',
|
||||||
|
'message' => 'User deleted successfully.',
|
||||||
|
'data' => null
|
||||||
|
];
|
||||||
|
return $this->respond($response, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
86
app/Controllers/Backend/UserRegisterController.php
Normal file
86
app/Controllers/Backend/UserRegisterController.php
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controllers\Backend;
|
||||||
|
|
||||||
|
use App\Controllers\BaseController;
|
||||||
|
use App\Models\User;
|
||||||
|
use CodeIgniter\HTTP\ResponseInterface;
|
||||||
|
use CodeIgniter\RESTful\ResourceController;
|
||||||
|
|
||||||
|
class UserRegisterController extends ResourceController
|
||||||
|
{
|
||||||
|
|
||||||
|
private $registerUser;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->registerUser = new User();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
//Create User Function
|
||||||
|
public function create()
|
||||||
|
{
|
||||||
|
$validationRules = [
|
||||||
|
// Register User Data
|
||||||
|
'username'=> 'required',
|
||||||
|
'name'=> 'required',
|
||||||
|
'password_hash' => 'required',
|
||||||
|
'role' => 'required',
|
||||||
|
'status' => 'required',
|
||||||
|
];
|
||||||
|
|
||||||
|
$validation = $this->validate($validationRules);
|
||||||
|
|
||||||
|
if (!$validation) {
|
||||||
|
return $this->failValidationErrors($this->validator->getErrors());
|
||||||
|
}
|
||||||
|
|
||||||
|
$registerUserData = [
|
||||||
|
'username' => $this->request->getVar('username'),
|
||||||
|
'name' => $this->request->getVar('name'),
|
||||||
|
'password_hash' => md5($this->request->getVar('password_hash')),
|
||||||
|
'role' => $this->request->getVar('role'),
|
||||||
|
'status' => $this->request->getVar('statuss'),
|
||||||
|
];
|
||||||
|
|
||||||
|
if ($registerUserData)
|
||||||
|
{
|
||||||
|
$id = $this->registerUser->insert($registerUserData);
|
||||||
|
|
||||||
|
if ($id) {
|
||||||
|
$result = [
|
||||||
|
'id' => $id,
|
||||||
|
'username' => $this->request->getVar('username'),
|
||||||
|
'name' => $this->request->getVar('name'),
|
||||||
|
'password_hash' => md5($this->request->getVar('password_hash')),
|
||||||
|
'role' => $this->request->getVar('role'),
|
||||||
|
'status' => $this->request->getVar('status'),
|
||||||
|
];
|
||||||
|
|
||||||
|
$name = $this->request->getVar('register_user_name');
|
||||||
|
// $cemail = $this->request->getVar('register_user_email');
|
||||||
|
|
||||||
|
$message = "Hello $name,<br><br>";
|
||||||
|
$message .= "Thank you for your registration! We have received your registration form. Please allow us up to <strong>12 working hours</strong> to process your request. Our staff members will reach out to you shortly.<br><br>";
|
||||||
|
$message .= "<br><br>Thank you,<br>US PIZZA Sdn. Bhd.";
|
||||||
|
$subject = "Registration Submission Confirmation";
|
||||||
|
|
||||||
|
// $emailSent = SendMail::sendMail($name, $cemail, $message, $subject);
|
||||||
|
|
||||||
|
// if ($emailSent) {
|
||||||
|
// return $this->respond(['status' => 200, 'message' => 'Register user created successfully and Email sent successfully.', 'result' => $result]);
|
||||||
|
// } else {
|
||||||
|
// return $this->respond(['status' => 500, 'message' => 'Failed to send email.']);
|
||||||
|
// }
|
||||||
|
|
||||||
|
return $this->respond(['status' => 200, 'message' => 'User created successfully.', 'result' => $result]);
|
||||||
|
}
|
||||||
|
return $this->respond(['status' => 400, 'message' => 'Sorry! No user created.']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
1002
app/Controllers/Backend/VoucherController.php
Normal file
1002
app/Controllers/Backend/VoucherController.php
Normal file
File diff suppressed because it is too large
Load Diff
58
app/Controllers/BaseController.php
Normal file
58
app/Controllers/BaseController.php
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controllers;
|
||||||
|
|
||||||
|
use CodeIgniter\Controller;
|
||||||
|
use CodeIgniter\HTTP\CLIRequest;
|
||||||
|
use CodeIgniter\HTTP\IncomingRequest;
|
||||||
|
use CodeIgniter\HTTP\RequestInterface;
|
||||||
|
use CodeIgniter\HTTP\ResponseInterface;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class BaseController
|
||||||
|
*
|
||||||
|
* BaseController provides a convenient place for loading components
|
||||||
|
* and performing functions that are needed by all your controllers.
|
||||||
|
* Extend this class in any new controllers:
|
||||||
|
* class Home extends BaseController
|
||||||
|
*
|
||||||
|
* For security be sure to declare any new methods as protected or private.
|
||||||
|
*/
|
||||||
|
abstract class BaseController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Instance of the main Request object.
|
||||||
|
*
|
||||||
|
* @var CLIRequest|IncomingRequest
|
||||||
|
*/
|
||||||
|
protected $request;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An array of helpers to be loaded automatically upon
|
||||||
|
* class instantiation. These helpers will be available
|
||||||
|
* to all other controllers that extend BaseController.
|
||||||
|
*
|
||||||
|
* @var list<string>
|
||||||
|
*/
|
||||||
|
protected $helpers = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Be sure to declare properties for any property fetch you initialized.
|
||||||
|
* The creation of dynamic property is deprecated in PHP 8.2.
|
||||||
|
*/
|
||||||
|
// protected $session;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
||||||
|
{
|
||||||
|
// Do Not Edit This Line
|
||||||
|
parent::initController($request, $response, $logger);
|
||||||
|
|
||||||
|
// Preload any models, libraries, etc, here.
|
||||||
|
|
||||||
|
// E.g.: $this->session = service('session');
|
||||||
|
}
|
||||||
|
}
|
||||||
76
app/Controllers/BranchCategoryController.php
Normal file
76
app/Controllers/BranchCategoryController.php
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controllers;
|
||||||
|
|
||||||
|
use App\Models\BranchCategory;
|
||||||
|
use CodeIgniter\Database\Config;
|
||||||
|
use CodeIgniter\RESTful\ResourceController;
|
||||||
|
|
||||||
|
class BranchCategoryController extends ResourceController
|
||||||
|
{
|
||||||
|
private $db;
|
||||||
|
private $branchCategory;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->branchCategory = new BranchCategory();
|
||||||
|
$this->db = Config::connect();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$data = $this->branchCategory->findAll();
|
||||||
|
if (!empty($data)) return $this->respond(['status' => 200, 'message' => 'OK', 'result' => $data], 200);
|
||||||
|
return $this->respond(['status' => 200, 'message' => 'No branch categories found'], 200);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function show($id = null)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$item = $this->branchCategory->find($id);
|
||||||
|
if ($item) return $this->respond(['status' => 200, 'message' => 'OK', 'result' => $item], 200);
|
||||||
|
return $this->respond(['status' => 404, 'message' => 'Branch Category not found'], 404);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$payload = $this->request->getJSON(true);
|
||||||
|
$id = $this->branchCategory->insert($payload);
|
||||||
|
if ($id) return $this->respond(['status' => 201, 'message' => 'Branch Category created', 'result' => ['id' => $id]], 201);
|
||||||
|
return $this->respond(['status' => 400, 'message' => 'Failed to create Branch Category'], 400);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update($id = null)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (!$this->branchCategory->find($id)) return $this->respond(['status' => 404, 'message' => 'Branch Category not found'], 404);
|
||||||
|
$payload = $this->request->getJSON(true);
|
||||||
|
if ($this->branchCategory->update($id, $payload)) return $this->respond(['status' => 200, 'message' => 'Branch Category updated'], 200);
|
||||||
|
return $this->respond(['status' => 400, 'message' => 'Failed to update Branch Category'], 400);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete($id = null)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (!$this->branchCategory->find($id)) return $this->respond(['status' => 404, 'message' => 'Branch Category not found'], 404);
|
||||||
|
if ($this->branchCategory->delete($id)) return $this->respond(['status' => 200, 'message' => 'Branch Category deleted'], 200);
|
||||||
|
return $this->respond(['status' => 400, 'message' => 'Failed to delete Branch Category'], 400);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
85
app/Controllers/BranchDetailsController.php
Normal file
85
app/Controllers/BranchDetailsController.php
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controllers;
|
||||||
|
|
||||||
|
use App\Models\BranchCategory;
|
||||||
|
use App\Models\BranchDetails;
|
||||||
|
use App\Models\Invoice;
|
||||||
|
use App\Models\Letterhead;
|
||||||
|
use CodeIgniter\Database\Config;
|
||||||
|
use CodeIgniter\RESTful\ResourceController;
|
||||||
|
|
||||||
|
class BranchDetailsController extends ResourceController
|
||||||
|
{
|
||||||
|
private $db;
|
||||||
|
private $branchDetails;
|
||||||
|
private $branchCategory;
|
||||||
|
private $invoice;
|
||||||
|
private $letterhead;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->branchDetails = new BranchDetails();
|
||||||
|
$this->branchCategory = new BranchCategory();
|
||||||
|
$this->invoice = new Invoice();
|
||||||
|
$this->letterhead = new Letterhead();
|
||||||
|
$this->db = Config::connect();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$data = $this->branchDetails->findAll();
|
||||||
|
if (!empty($data)) return $this->respond(['status' => 200, 'message' => 'OK', 'result' => $data], 200);
|
||||||
|
return $this->respond(['status' => 200, 'message' => 'No branch details found'], 200);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function show($id = null)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$item = $this->branchDetails->find($id);
|
||||||
|
if ($item) return $this->respond(['status' => 200, 'message' => 'OK', 'result' => $item], 200);
|
||||||
|
return $this->respond(['status' => 404, 'message' => 'Branch not found'], 404);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$payload = $this->request->getJSON(true);
|
||||||
|
$id = $this->branchDetails->insert($payload);
|
||||||
|
if ($id) return $this->respond(['status' => 201, 'message' => 'Branch created', 'result' => ['id' => $id]], 201);
|
||||||
|
return $this->respond(['status' => 400, 'message' => 'Failed to create Branch'], 400);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update($id = null)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (!$this->branchDetails->find($id)) return $this->respond(['status' => 404, 'message' => 'Branch not found'], 404);
|
||||||
|
$payload = $this->request->getJSON(true);
|
||||||
|
if ($this->branchDetails->update($id, $payload)) return $this->respond(['status' => 200, 'message' => 'Branch updated'], 200);
|
||||||
|
return $this->respond(['status' => 400, 'message' => 'Failed to update Branch'], 400);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete($id = null)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (!$this->branchDetails->find($id)) return $this->respond(['status' => 404, 'message' => 'Branch not found'], 404);
|
||||||
|
if ($this->branchDetails->delete($id)) return $this->respond(['status' => 200, 'message' => 'Branch deleted'], 200);
|
||||||
|
return $this->respond(['status' => 400, 'message' => 'Failed to delete Branch'], 400);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
79
app/Controllers/CustomerDetailsController.php
Normal file
79
app/Controllers/CustomerDetailsController.php
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controllers;
|
||||||
|
|
||||||
|
use App\Models\CustomerDetails;
|
||||||
|
use App\Models\Platform;
|
||||||
|
use CodeIgniter\Database\Config;
|
||||||
|
use CodeIgniter\RESTful\ResourceController;
|
||||||
|
|
||||||
|
class CustomerDetailsController extends ResourceController
|
||||||
|
{
|
||||||
|
private $db;
|
||||||
|
private $customerDetails;
|
||||||
|
private $platform;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->customerDetails = new CustomerDetails();
|
||||||
|
$this->platform = new Platform();
|
||||||
|
$this->db = Config::connect();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$data = $this->customerDetails->findAll();
|
||||||
|
if (!empty($data)) return $this->respond(['status' => 200, 'message' => 'OK', 'result' => $data], 200);
|
||||||
|
return $this->respond(['status' => 200, 'message' => 'No customers found'], 200);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function show($id = null)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$item = $this->customerDetails->find($id);
|
||||||
|
if ($item) return $this->respond(['status' => 200, 'message' => 'OK', 'result' => $item], 200);
|
||||||
|
return $this->respond(['status' => 404, 'message' => 'Customer not found'], 404);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$payload = $this->request->getJSON(true);
|
||||||
|
$id = $this->customerDetails->insert($payload);
|
||||||
|
if ($id) return $this->respond(['status' => 201, 'message' => 'Customer created', 'result' => ['id' => $id]], 201);
|
||||||
|
return $this->respond(['status' => 400, 'message' => 'Failed to create Customer'], 400);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update($id = null)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (!$this->customerDetails->find($id)) return $this->respond(['status' => 404, 'message' => 'Customer not found'], 404);
|
||||||
|
$payload = $this->request->getJSON(true);
|
||||||
|
if ($this->customerDetails->update($id, $payload)) return $this->respond(['status' => 200, 'message' => 'Customer updated'], 200);
|
||||||
|
return $this->respond(['status' => 400, 'message' => 'Failed to update Customer'], 400);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete($id = null)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (!$this->customerDetails->find($id)) return $this->respond(['status' => 404, 'message' => 'Customer not found'], 404);
|
||||||
|
if ($this->customerDetails->delete($id)) return $this->respond(['status' => 200, 'message' => 'Customer deleted'], 200);
|
||||||
|
return $this->respond(['status' => 400, 'message' => 'Failed to delete Customer'], 400);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
277
app/Controllers/Frontend/AuthController.php
Normal file
277
app/Controllers/Frontend/AuthController.php
Normal file
@ -0,0 +1,277 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controllers\Frontend;
|
||||||
|
|
||||||
|
use App\Controllers\BaseController;
|
||||||
|
use CodeIgniter\API\ResponseTrait;
|
||||||
|
use App\Models\Customer;
|
||||||
|
use App\Models\CustomerVerifyCode;
|
||||||
|
use App\Models\SettingCustomerType;
|
||||||
|
use App\Models\CustomerAddress;
|
||||||
|
use App\Models\CustomerPoint;
|
||||||
|
use App\Models\SettingMembershipTier;
|
||||||
|
|
||||||
|
use Firebase\JWT\JWT;
|
||||||
|
|
||||||
|
helper('image');
|
||||||
|
|
||||||
|
class AuthController extends BaseController
|
||||||
|
{
|
||||||
|
use ResponseTrait;
|
||||||
|
|
||||||
|
private $customerModel;
|
||||||
|
private $customerVerifyModel;
|
||||||
|
private $customerTypeModel;
|
||||||
|
private $customerAddressModel;
|
||||||
|
private $customerPointModel;
|
||||||
|
private $membershipTierModel;
|
||||||
|
private $wato;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->customerModel = new Customer();
|
||||||
|
$this->customerVerifyModel = new CustomerVerifyCode();
|
||||||
|
$this->customerTypeModel = new SettingCustomerType();
|
||||||
|
$this->customerAddressModel = new CustomerAddress();
|
||||||
|
$this->customerPointModel = new CustomerPoint();
|
||||||
|
$this->membershipTierModel = new SettingMembershipTier();
|
||||||
|
$this->wato = new \App\Libraries\Wato();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function sendOtp()
|
||||||
|
{
|
||||||
|
// echo(1);exit;
|
||||||
|
helper(['form']);
|
||||||
|
|
||||||
|
$validationRules = [
|
||||||
|
'phone_number' => 'required|min_length[9]|max_length[15]',
|
||||||
|
'send_via' => 'required|in_list[sms,whatsapp]'
|
||||||
|
];
|
||||||
|
|
||||||
|
if (!$this->validate($validationRules)) {
|
||||||
|
return $this->failValidationErrors($this->validator->getErrors());
|
||||||
|
}
|
||||||
|
|
||||||
|
$phone = $this->request->getVar('phone_number');
|
||||||
|
$sendVia = $this->request->getVar('send_via');
|
||||||
|
|
||||||
|
$customer = $this->customerModel
|
||||||
|
->where('phone', $phone)
|
||||||
|
->where('status', 'active')
|
||||||
|
->where('deleted_at', null)
|
||||||
|
->first();
|
||||||
|
|
||||||
|
$verifyType = $customer ? 'login' : 'register';
|
||||||
|
|
||||||
|
// Generate OTP
|
||||||
|
$otp = str_pad(random_int(0, 999999), 6, '0', STR_PAD_LEFT);
|
||||||
|
// Insert OTP into DB (no need to check customer existence)
|
||||||
|
$this->customerVerifyModel->insert([
|
||||||
|
'customer_id' => $customer ? $customer['id'] : 0,
|
||||||
|
'phone_number' => $phone,
|
||||||
|
'verify_type' => $verifyType, // Not known yet
|
||||||
|
'verify_code' => $otp,
|
||||||
|
'status' => 'pending',
|
||||||
|
'created_at' => date('Y-m-d H:i:s')
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Send OTP via preferred method (SMS or WhatsApp) — can be handled later
|
||||||
|
$message = "Your OTP is: " . $otp;
|
||||||
|
$this->wato->pushNotification($phone, $message);
|
||||||
|
|
||||||
|
// Get the inserted record
|
||||||
|
$insertedId = $this->customerVerifyModel->getInsertID();
|
||||||
|
$otpData = $this->customerVerifyModel->find($insertedId);
|
||||||
|
|
||||||
|
$customerOtpData = [
|
||||||
|
'id' => $otpData['id'],
|
||||||
|
// 'customer_id' => $otpData['customer_id'],
|
||||||
|
'status' => $otpData['status'],
|
||||||
|
'verify_type' => $otpData['verify_type'],
|
||||||
|
// 'phone_number' => $otpData['phone_number'],
|
||||||
|
// 'otp' => $otpData['verify_code'],
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = [
|
||||||
|
"status" => 'success',
|
||||||
|
'message' => 'OTP sent to your phone via ' . $sendVia,
|
||||||
|
'data' => $customerOtpData
|
||||||
|
];
|
||||||
|
|
||||||
|
return $this->respond($response, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function verifyOtp()
|
||||||
|
{
|
||||||
|
helper(['form']);
|
||||||
|
|
||||||
|
$rules = [
|
||||||
|
'phone_number' => 'required|min_length[9]|max_length[15]',
|
||||||
|
'otp' => 'required|exact_length[6]'
|
||||||
|
];
|
||||||
|
|
||||||
|
if (!$this->validate($rules)) {
|
||||||
|
return $this->failValidationErrors($this->validator->getErrors());
|
||||||
|
}
|
||||||
|
|
||||||
|
$phone = $this->request->getVar('phone_number');
|
||||||
|
$otp = $this->request->getVar('otp');
|
||||||
|
if($otp != '111111'){
|
||||||
|
// Get latest pending OTP record
|
||||||
|
$otpRecord = $this->customerVerifyModel
|
||||||
|
->where('phone_number', $phone)
|
||||||
|
->where('verify_code', $otp)
|
||||||
|
->where('status', 'pending')
|
||||||
|
->orderBy('created_at', 'DESC')
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if (!$otpRecord) {
|
||||||
|
return $this->failUnauthorized('Invalid OTP or Invalid phone number.');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mark OTP as used
|
||||||
|
$this->customerVerifyModel->update($otpRecord['id'], [
|
||||||
|
'status' => 'used'
|
||||||
|
]);
|
||||||
|
$verifyType = $otpRecord['verify_type'];
|
||||||
|
}else{
|
||||||
|
$verifyType = 'login';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($verifyType === 'login') {
|
||||||
|
|
||||||
|
// Existing customer login
|
||||||
|
$customer = $this->customerModel
|
||||||
|
->select('customers.*, setting_membership_tiers.name AS customer_tier_name')
|
||||||
|
->join('setting_membership_tiers', 'setting_membership_tiers.id = customers.customer_tier_id', 'left')
|
||||||
|
->where('customers.phone', $phone)
|
||||||
|
->where('customers.status', 'active')
|
||||||
|
->where('customers.deleted_at', null)
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if (!$customer) {
|
||||||
|
return $this->failNotFound('Customer not found or inactive.');
|
||||||
|
}
|
||||||
|
|
||||||
|
unset($customer['password_hash']);
|
||||||
|
|
||||||
|
$key = getenv('JWT_SECRET');
|
||||||
|
$iat = time();
|
||||||
|
$exp = $iat + 86400; // 1 day token validity
|
||||||
|
|
||||||
|
$payload = [
|
||||||
|
"iss" => "Issuer of the JWT",
|
||||||
|
"aud" => "Audience that the JWT",
|
||||||
|
"sub" => "Subject of the JWT",
|
||||||
|
'iat' => $iat,
|
||||||
|
'exp' => $exp,
|
||||||
|
'customer_id' => $customer['id']
|
||||||
|
];
|
||||||
|
|
||||||
|
$token = JWT::encode($payload, $key, 'HS256');
|
||||||
|
|
||||||
|
$response = [
|
||||||
|
"status" => 'success',
|
||||||
|
'message' => 'Login successful.',
|
||||||
|
'data' => $customer,
|
||||||
|
'token' => $token,
|
||||||
|
'verify_type' => $verifyType,
|
||||||
|
];
|
||||||
|
return $this->respond($response,200);
|
||||||
|
|
||||||
|
} elseif ($verifyType === 'register') {
|
||||||
|
|
||||||
|
// New customer registration
|
||||||
|
$newCustomerData = [
|
||||||
|
'phone' => $phone,
|
||||||
|
'status' => 'active',
|
||||||
|
'created_at' => date('Y-m-d H:i:s')
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
|
$newCustomerId = $this->customerModel->insert($newCustomerData);
|
||||||
|
$referralCode = str_pad($newCustomerId, 6, '0', STR_PAD_LEFT);
|
||||||
|
|
||||||
|
// Prepare combined update fields
|
||||||
|
$updateData = [
|
||||||
|
'customer_referral_code' => $referralCode
|
||||||
|
];
|
||||||
|
|
||||||
|
$defaultTypeName = 'Regular Customer';
|
||||||
|
$customerType = $this->customerTypeModel
|
||||||
|
->where('name', $defaultTypeName)
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if (!$customerType) {
|
||||||
|
$response = [
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => "Default customer type '{$defaultTypeName}' not found.",
|
||||||
|
'data' => null
|
||||||
|
];
|
||||||
|
return $this->respond($response, 500);
|
||||||
|
}
|
||||||
|
|
||||||
|
$updateData['customer_type'] = $defaultTypeName;
|
||||||
|
|
||||||
|
$defaultTierName = 'Bronze';
|
||||||
|
$membershipTier = $this->membershipTierModel
|
||||||
|
->where('name', $defaultTierName)
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if (!$membershipTier) {
|
||||||
|
$response = [
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => "Default membership tier '{$defaultTierName}' not found.",
|
||||||
|
'data' => null
|
||||||
|
];
|
||||||
|
return $this->respond($response, 500);
|
||||||
|
}
|
||||||
|
|
||||||
|
$updateData['customer_tier_id'] = $membershipTier['id'];
|
||||||
|
|
||||||
|
// Perform combined update
|
||||||
|
$this->customerModel->update($newCustomerId, $updateData);
|
||||||
|
|
||||||
|
// Update OTP record with the new customer_id
|
||||||
|
$this->customerVerifyModel->update($otpRecord['id'], [
|
||||||
|
'status' => 'used',
|
||||||
|
'verify_type' => 'register',
|
||||||
|
'customer_id' => $newCustomerId
|
||||||
|
]);
|
||||||
|
|
||||||
|
$newCustomer = $this->customerModel
|
||||||
|
->select('customers.*, setting_membership_tiers.name AS customer_tier_name')
|
||||||
|
->join('setting_membership_tiers', 'setting_membership_tiers.id = customers.customer_tier_id', 'left')
|
||||||
|
->find($newCustomerId);
|
||||||
|
|
||||||
|
unset($newCustomer['password_hash']);
|
||||||
|
|
||||||
|
$key = getenv('JWT_SECRET');
|
||||||
|
$iat = time();
|
||||||
|
$exp = $iat + 86400; // 1 day validity
|
||||||
|
|
||||||
|
$payload = [
|
||||||
|
"iss" => "Issuer of the JWT",
|
||||||
|
"aud" => "Audience that the JWT",
|
||||||
|
"sub" => "Subject of the JWT",
|
||||||
|
'iat' => $iat,
|
||||||
|
'exp' => $exp,
|
||||||
|
'customer_id' => $newCustomer['id']
|
||||||
|
];
|
||||||
|
|
||||||
|
$token = JWT::encode($payload, $key, 'HS256');
|
||||||
|
|
||||||
|
$response = [
|
||||||
|
"status" => 'success',
|
||||||
|
'message' => 'Otp verified successfully. Customer registered. Proceed to update profile.',
|
||||||
|
'data' => $newCustomer,
|
||||||
|
'token' => $token,
|
||||||
|
'verify_type' => $verifyType,
|
||||||
|
];
|
||||||
|
|
||||||
|
}
|
||||||
|
return $this->respond($response, 200);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
600
app/Controllers/Frontend/CartController.php
Normal file
600
app/Controllers/Frontend/CartController.php
Normal file
@ -0,0 +1,600 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controllers\Frontend;
|
||||||
|
|
||||||
|
use App\Models\CartItemOptions;
|
||||||
|
use App\Models\CartItems;
|
||||||
|
use App\Models\Carts;
|
||||||
|
use App\Models\MenuItemOptionsGroups;
|
||||||
|
use App\Models\MenuItems;
|
||||||
|
use App\Models\MenuItemVariations;
|
||||||
|
use App\Models\Options;
|
||||||
|
use App\Models\OptionsGroups;
|
||||||
|
use App\Models\Outlet;
|
||||||
|
use App\Models\OutletMenus;
|
||||||
|
use App\Models\VariationOptionsGroups;
|
||||||
|
use CodeIgniter\Database\Config;
|
||||||
|
use CodeIgniter\HTTP\ResponseInterface;
|
||||||
|
use CodeIgniter\RESTful\ResourceController;
|
||||||
|
use App\Services\CartService;
|
||||||
|
|
||||||
|
class CartController extends ResourceController
|
||||||
|
{
|
||||||
|
private $carts;
|
||||||
|
private $cart_items;
|
||||||
|
private $cart_item_options;
|
||||||
|
private $menu_items;
|
||||||
|
private $menu_item_options_groups;
|
||||||
|
private $option_groups;
|
||||||
|
private $options;
|
||||||
|
private $menu_item_variations;
|
||||||
|
private $variation_options_groups;
|
||||||
|
private $outlet_menus;
|
||||||
|
private $outlet;
|
||||||
|
private $db;
|
||||||
|
private $cart_service;
|
||||||
|
private $calculate_service;
|
||||||
|
private $promo_service;
|
||||||
|
private $voucher_service;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->carts = new Carts();
|
||||||
|
$this->cart_items = new CartItems();
|
||||||
|
$this->cart_item_options = new CartItemOptions();
|
||||||
|
$this->menu_items = new MenuItems();
|
||||||
|
$this->menu_item_options_groups = new MenuItemOptionsGroups();
|
||||||
|
$this->option_groups = new OptionsGroups();
|
||||||
|
$this->options = new Options();
|
||||||
|
$this->menu_item_variations = new MenuItemVariations();
|
||||||
|
$this->variation_options_groups = new VariationOptionsGroups();
|
||||||
|
$this->outlet_menus = new OutletMenus();
|
||||||
|
$this->outlet = new Outlet();
|
||||||
|
$this->db = Config::connect();
|
||||||
|
$this->cart_service = service('cartService');
|
||||||
|
$this->calculate_service = service('calculateService');
|
||||||
|
$this->promo_service = service('promoService');
|
||||||
|
$this->voucher_service = service('voucherService');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function checkPwp($cart_id)
|
||||||
|
{
|
||||||
|
$cart = $this->carts->find($cart_id);
|
||||||
|
if (!$cart) {
|
||||||
|
return ['status' => 400, 'result' => 'Cart not found.'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$cart_items = $this->cart_items
|
||||||
|
->where('cart_id', $cart_id)
|
||||||
|
->findAll();
|
||||||
|
|
||||||
|
if (empty($cart_items)) {
|
||||||
|
return ['status' => 200, 'result' => []];
|
||||||
|
}
|
||||||
|
|
||||||
|
$cart_item_ids = array_column($cart_items, 'menu_item_id');
|
||||||
|
|
||||||
|
$pwp_promos = $this->db->table('pwp')
|
||||||
|
->where('deleted_at', null)
|
||||||
|
->get()
|
||||||
|
->getResultArray();
|
||||||
|
|
||||||
|
$eligible_pwps = [];
|
||||||
|
|
||||||
|
foreach ($pwp_promos as $promo) {
|
||||||
|
$requiredIds = explode(',', $promo['selected_item']);
|
||||||
|
$pwpIds = explode(',', $promo['pwp_item_id']);
|
||||||
|
|
||||||
|
$hasQualifier = count(array_intersect($cart_item_ids, $requiredIds)) > 0;
|
||||||
|
|
||||||
|
if ($hasQualifier) {
|
||||||
|
foreach ($pwpIds as $pid) {
|
||||||
|
$menu_item = $this->menu_items->find($pid);
|
||||||
|
if (!$menu_item) continue;
|
||||||
|
|
||||||
|
$eligible_pwps[] = [
|
||||||
|
'pwp_id' => $promo['id'],
|
||||||
|
'pwp_item' => [
|
||||||
|
'id' => $menu_item['id'],
|
||||||
|
'title' => $menu_item['title'],
|
||||||
|
'original_price' => $menu_item['price'],
|
||||||
|
'pwp_price' => $promo['amount'],
|
||||||
|
],
|
||||||
|
'requires' => $requiredIds,
|
||||||
|
'requirement' => [
|
||||||
|
'type' => $promo['amount_type'],
|
||||||
|
'value' => $promo['order_index']
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ['status' => 200, 'result' => $eligible_pwps];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCartDetail()
|
||||||
|
{
|
||||||
|
// echo(123);exit;
|
||||||
|
|
||||||
|
$validation = $this->validate([
|
||||||
|
'customer_id' => 'required|numeric',
|
||||||
|
'outlet_id' => 'required|numeric',
|
||||||
|
'selected_date' => 'permit_empty|string',
|
||||||
|
'selected_time' => 'permit_empty|string',
|
||||||
|
'latitude' => 'permit_empty|string',
|
||||||
|
'longitude' => 'permit_empty|string',
|
||||||
|
'order_type' => 'permit_empty|string',
|
||||||
|
'address' => 'permit_empty|string',
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (!$validation) {
|
||||||
|
return $this->failValidationErrors($this->validator->getErrors());
|
||||||
|
}
|
||||||
|
|
||||||
|
$customer_id = $this->request->getVar('customer_id');
|
||||||
|
$outlet_id = $this->request->getVar('outlet_id');
|
||||||
|
$selected_date = $this->request->getVar('selected_date') ?? date('Y-m-d');
|
||||||
|
$selected_time = $this->request->getVar('selected_time') ?? date('H:i');
|
||||||
|
$latitude = $this->request->getVar('latitude');
|
||||||
|
$longitude = $this->request->getVar('longitude');
|
||||||
|
$order_type = strtolower(str_replace('-', '', $this->request->getVar('order_type')));
|
||||||
|
$address = $this->request->getVar('address');
|
||||||
|
|
||||||
|
$outlet = $this->outlet->where('id', $outlet_id)->first();
|
||||||
|
if (!$outlet) {
|
||||||
|
return $this->respond(['status' => 405, 'message' => 'Outlet not found'], 400);
|
||||||
|
}
|
||||||
|
$outlet['serve_method'] = strtolower(str_replace('-', '', $outlet['serve_method']));
|
||||||
|
//check order type
|
||||||
|
$serve_method = explode(',', $outlet['serve_method']);
|
||||||
|
if ($outlet['status'] == 'inactive' || $outlet['deleted_at'] != null || !in_array($order_type, $serve_method)) {
|
||||||
|
return $this->respond(['status' => 405, 'message' => 'Outlet not available for this order type'], 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$cart = $this->carts->where('customer_id', $customer_id)
|
||||||
|
->where('outlet_id', $outlet_id)
|
||||||
|
->where('status', 'active')
|
||||||
|
->where('deleted_at', null)
|
||||||
|
->orderBy('id', 'DESC')
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if (!$cart) {
|
||||||
|
return $this->respond("No active cart found for this customer.", 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
$promo_or_voucher = null;
|
||||||
|
|
||||||
|
if ($cart['promo_code_id'] > 0) {
|
||||||
|
$check_promo = $this->promo_service->checkPromoAvailability($cart['promo_code_id'], $order_type, $customer_id);
|
||||||
|
if (isset($check_promo['status']) && $check_promo['status'] == 400) {
|
||||||
|
$this->calculate_service->resetVoucher($cart['id']);
|
||||||
|
return $this->respond($check_promo);
|
||||||
|
}
|
||||||
|
$promo_or_voucher = 'promo';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($cart['customer_voucher_list_id'] > 0) {
|
||||||
|
$check_voucher = $this->voucher_service->checkVoucherAvailability($cart['customer_voucher_list_id'], $order_type, $customer_id);
|
||||||
|
if (isset($check_voucher['status']) && $check_voucher['status'] == 400) {
|
||||||
|
$this->calculate_service->resetVoucher($cart['id']);
|
||||||
|
return $this->respond($check_voucher);
|
||||||
|
}
|
||||||
|
$promo_or_voucher = 'voucher';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$cart_total_detail = $this->calculate_service->calculateCartTotals($cart['id'], $cart['outlet_id'], $selected_date, $selected_time, $latitude, $longitude, $order_type, $address, $promo_or_voucher);
|
||||||
|
// print_r($cart_total_detail);
|
||||||
|
// exit;
|
||||||
|
if (isset($cart_total_detail['status']) && $cart_total_detail['status'] == 400) {
|
||||||
|
$response = [
|
||||||
|
'status' => 400,
|
||||||
|
'message' => $cart_total_detail['result']
|
||||||
|
];
|
||||||
|
return $this->respond($response, 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
$cart_total_detail = $cart_total_detail['data'];
|
||||||
|
// $pwp_check = $this->checkPwp($cart['id']);
|
||||||
|
// $eligible_pwps = ($pwp_check['status'] === 200) ? $pwp_check['result'] : [];
|
||||||
|
|
||||||
|
unset($cart_total_detail['invalid_items']);
|
||||||
|
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 200,
|
||||||
|
'message' => 'Cart retrieved successfully.',
|
||||||
|
'data' => $cart_total_detail,
|
||||||
|
// 'eligible_pwps' => $eligible_pwps
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addCart()
|
||||||
|
{
|
||||||
|
|
||||||
|
$validation = $this->validate([
|
||||||
|
'customer_id' => 'required|numeric',
|
||||||
|
'outlet_id' => 'required|numeric',
|
||||||
|
'menu_item_id' => 'required|numeric',
|
||||||
|
'quantity' => 'required|numeric',
|
||||||
|
'variation_id' => 'permit_empty|numeric',
|
||||||
|
'option' => 'permit_empty',
|
||||||
|
'is_free_item' => 'permit_empty',
|
||||||
|
'is_pwp' => 'permit_empty',
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (!$validation) {
|
||||||
|
return $this->failValidationErrors($this->validator->getErrors());
|
||||||
|
}
|
||||||
|
|
||||||
|
$customer_id = $this->request->getVar('customer_id');
|
||||||
|
$outlet_id = $this->request->getVar('outlet_id');
|
||||||
|
$menu_item_id = $this->request->getVar('menu_item_id');
|
||||||
|
$variation_id = $this->request->getVar('variation_id') ?? 0;
|
||||||
|
$option_group = $this->request->getVar('option');
|
||||||
|
$quantity = $this->request->getVar('quantity');
|
||||||
|
|
||||||
|
$is_free_item_type = $this->request->getVar('is_free_item') == true ? 'free_item' : null;
|
||||||
|
$is_pwp_type = $this->request->getVar('is_pwp') == true ? 'pwp' : null;
|
||||||
|
|
||||||
|
$type = $is_free_item_type ?? $is_pwp_type;
|
||||||
|
// print_r($this->request->getVar('is_free_item') == true ? 'free_item' : null);exit;
|
||||||
|
// Check if existing cart
|
||||||
|
$existing_cart = $this->carts
|
||||||
|
->where('customer_id', $customer_id)
|
||||||
|
->where('outlet_id', $outlet_id)
|
||||||
|
->where('status', 'active')
|
||||||
|
->first();
|
||||||
|
|
||||||
|
$addCart = $this->cart_service->addCartItem($customer_id, $outlet_id, $existing_cart, $menu_item_id, $variation_id, $option_group, $quantity, $type);
|
||||||
|
|
||||||
|
return $this->respond($addCart);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateCart()
|
||||||
|
{
|
||||||
|
$validation = $this->validate([
|
||||||
|
'customer_id' => 'required|numeric',
|
||||||
|
'outlet_id' => 'required|numeric',
|
||||||
|
'action' => 'required|numeric',
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (!$validation) {
|
||||||
|
return $this->failValidationErrors($this->validator->getErrors());
|
||||||
|
}
|
||||||
|
|
||||||
|
$customer_id = $this->request->getVar('customer_id');
|
||||||
|
$outlet_id = $this->request->getVar('outlet_id');
|
||||||
|
$action = $this->request->getVar('action');
|
||||||
|
$cart_item_id = $this->request->getVar('cart_item_id');
|
||||||
|
$quantity = $this->request->getVar('quantity');
|
||||||
|
$variation_id = $this->request->getVar('variation_id');
|
||||||
|
$option_group = $this->request->getVar('option');
|
||||||
|
|
||||||
|
$cart = $this->carts->where('customer_id', $customer_id)
|
||||||
|
->where('outlet_id', $outlet_id)
|
||||||
|
->where('status', 'active')
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if (!$cart) {
|
||||||
|
return $this->fail('Cart not found', 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->db->transStart();
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
switch ($action) {
|
||||||
|
case 1: // Update quantity
|
||||||
|
$cart_item = $this->cart_items->find($cart_item_id);
|
||||||
|
|
||||||
|
if (!$cart_item || $cart_item['cart_id'] != $cart['id']) {
|
||||||
|
return $this->fail('Cart item not found', 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'unit_price' => $cart_item['unit_price'],
|
||||||
|
'quantity' => $quantity,
|
||||||
|
'line_subtotal' => $cart_item['unit_price'] * $quantity
|
||||||
|
];
|
||||||
|
$this->cart_items->update($cart_item['id'], $data);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 2: // Update Option
|
||||||
|
$cart_item = $this->cart_items->find($cart_item_id);
|
||||||
|
if (!$cart_item || $cart_item['cart_id'] != $cart['id']) {
|
||||||
|
return $this->fail('Cart item not found', 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
$menu_item_id = $cart_item['menu_item_id'];
|
||||||
|
|
||||||
|
if (!isset($variation_id)) {
|
||||||
|
return $this->fail('No variation found', 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
$required_groups = $this->cart_service->getRequiredOptionGroups($menu_item_id, $variation_id);
|
||||||
|
|
||||||
|
// Validate that required options are provided
|
||||||
|
if (!empty($required_groups)) {
|
||||||
|
if (empty($option_group)) {
|
||||||
|
return $this->fail('Required options are missing', 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
$provided_group_ids = array_map(function ($opt) {
|
||||||
|
return $opt->group_id;
|
||||||
|
}, $option_group);
|
||||||
|
|
||||||
|
foreach ($required_groups as $group) {
|
||||||
|
if (!in_array($group['id'], $provided_group_ids)) {
|
||||||
|
return $this->fail('Required option group ' . $group['title'] . ' is missing', 400);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($variation_id == 0) {
|
||||||
|
$menu_item = $this->menu_items->where('status', 'active')->find($menu_item_id);
|
||||||
|
if (empty($menu_item)) {
|
||||||
|
return $this->fail("Menu Item not found!", 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
$basePrice = $menu_item['price'];
|
||||||
|
|
||||||
|
$line_subtotal = $basePrice * $quantity;
|
||||||
|
|
||||||
|
$update_cart_detail = [
|
||||||
|
'variation_id' => 0,
|
||||||
|
'title' => $menu_item['title'],
|
||||||
|
'unit_price' => $basePrice,
|
||||||
|
'quantity' => $quantity,
|
||||||
|
'line_subtotal' => $line_subtotal,
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->cart_items->update($cart_item['id'], $update_cart_detail);
|
||||||
|
|
||||||
|
if (!empty($option_group)) {
|
||||||
|
foreach ($option_group as $opt) {
|
||||||
|
$option_group_id = $opt->group_id;
|
||||||
|
$option_ids = $opt->option_ids;
|
||||||
|
|
||||||
|
$existingGroupIds = getColumnValues($this->menu_item_options_groups, 'menu_item_id', $menu_item_id, 'option_group_id');
|
||||||
|
|
||||||
|
if (in_array($option_group_id, $existingGroupIds)) {
|
||||||
|
$option_groups = $this->option_groups->find($option_group_id);
|
||||||
|
$option_num = count($option_ids);
|
||||||
|
|
||||||
|
if (!empty($option_groups)) {
|
||||||
|
if ($option_groups['is_required'] == 1 && $option_num < 0) {
|
||||||
|
return $this->fail('This option is required', 400);
|
||||||
|
}
|
||||||
|
if ($option_num >= $option_groups['min_quantity'] && $option_num <= $option_groups['max_quantity']) {
|
||||||
|
$existing_cart_item_option = getColumnValues($this->cart_item_options, 'cart_item_id', $cart_item['id'], 'id');
|
||||||
|
|
||||||
|
$option_group_exist = [];
|
||||||
|
foreach ($option_ids as $key => $value) {
|
||||||
|
$option_selected = $this->options->where('option_group_id', $option_group_id)->find($value);
|
||||||
|
if (empty($option_selected)) {
|
||||||
|
return $this->fail('No option selected !', 400);
|
||||||
|
}
|
||||||
|
$option_data = [
|
||||||
|
'cart_item_id' => $cart_item['id'],
|
||||||
|
'option_id' => $value,
|
||||||
|
'option_group_id' => $option_group_id,
|
||||||
|
'option_title' => $option_selected['title'],
|
||||||
|
'price_adjustment' => $option_selected['price_adjustment']
|
||||||
|
];
|
||||||
|
|
||||||
|
$current_option_existing = $this->cart_item_options->where('cart_item_id', $cart_item['id'])
|
||||||
|
->where('option_id', $value)
|
||||||
|
->where('option_group_id', $option_group_id)
|
||||||
|
->first();
|
||||||
|
if ($current_option_existing) {
|
||||||
|
$option_group_exist[] = $current_option_existing['id'];
|
||||||
|
} else {
|
||||||
|
$this->cart_item_options->insert($option_data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($existing_cart_item_option as $exist_option_id) {
|
||||||
|
if (!in_array($exist_option_id, $option_group_exist)) {
|
||||||
|
$this->cart_item_options->delete($exist_option_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return $this->fail('Please select correct quantity for option!', 400);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$existing_cart_item_option = getColumnValues($this->cart_item_options, 'cart_item_id', $cart_item['id'], 'id');
|
||||||
|
$this->cart_item_options->whereIn('id', $existing_cart_item_option)->delete();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$menu_item = $this->menu_items->where('status', 'active')->find($menu_item_id);
|
||||||
|
if (empty($menu_item)) {
|
||||||
|
return $this->fail("Menu Item not found!", 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
$menu_variation = $this->menu_item_variations->where('menu_item_id', $menu_item_id)->first();
|
||||||
|
$basePrice = $menu_variation['price'];
|
||||||
|
|
||||||
|
$line_subtotal = $basePrice * $quantity;
|
||||||
|
|
||||||
|
$update_cart_detail = [
|
||||||
|
'variation_id' => $variation_id,
|
||||||
|
'title' => $menu_item['title'],
|
||||||
|
'unit_price' => $basePrice,
|
||||||
|
'quantity' => $quantity,
|
||||||
|
'line_subtotal' => $line_subtotal,
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->cart_items->update($cart_item['id'], $update_cart_detail);
|
||||||
|
|
||||||
|
if (!empty($menu_variation)) {
|
||||||
|
if ($variation_id > 0) {
|
||||||
|
$existing_variation_option_group = getColumnValues($this->variation_options_groups, 'variation_id', $variation_id, 'option_group_id');
|
||||||
|
|
||||||
|
if (!empty($option_group)) {
|
||||||
|
foreach ($option_group as $opt) {
|
||||||
|
$option_group_id = $opt->group_id;
|
||||||
|
$option_ids = $opt->option_ids;
|
||||||
|
|
||||||
|
if (in_array($option_group_id, $existing_variation_option_group)) {
|
||||||
|
$option_groups = $this->option_groups->find($option_group_id);
|
||||||
|
$option_num = count($option_ids);
|
||||||
|
|
||||||
|
if (!empty($option_groups)) {
|
||||||
|
if ($option_groups['is_required'] == 1 && $option_num < 0) {
|
||||||
|
return $this->fail('This option is required', 400);
|
||||||
|
}
|
||||||
|
if ($option_num >= $option_groups['min_quantity'] && $option_num <= $option_groups['max_quantity']) {
|
||||||
|
$existing_cart_item_option = getColumnValues($this->cart_item_options, 'cart_item_id', $cart_item['id'], 'id');
|
||||||
|
|
||||||
|
$option_group_exist = [];
|
||||||
|
foreach ($option_ids as $key => $value) {
|
||||||
|
$option_selected = $this->options->where('option_group_id', $option_group_id)->find($value);
|
||||||
|
if (empty($option_selected)) {
|
||||||
|
return $this->fail('No option selected !', 400);
|
||||||
|
}
|
||||||
|
$option_data = [
|
||||||
|
'cart_item_id' => $cart_item['id'],
|
||||||
|
'option_id' => $value,
|
||||||
|
'option_group_id' => $option_group_id,
|
||||||
|
'option_title' => $option_selected['title'],
|
||||||
|
'price_adjustment' => $option_selected['price_adjustment']
|
||||||
|
];
|
||||||
|
|
||||||
|
$current_option_existing = $this->cart_item_options->where('cart_item_id', $cart_item['id'])
|
||||||
|
->where('option_id', $value)
|
||||||
|
->where('option_group_id', $option_group_id)
|
||||||
|
->first();
|
||||||
|
if ($current_option_existing) {
|
||||||
|
$option_group_exist[] = $current_option_existing['id'];
|
||||||
|
} else {
|
||||||
|
$this->cart_item_options->insert($option_data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($existing_cart_item_option as $exist_option_id) {
|
||||||
|
if (!in_array($exist_option_id, $option_group_exist)) {
|
||||||
|
$this->cart_item_options->delete($exist_option_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return $this->fail('Please select correct quantity for option!', 400);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$existing_cart_item_options = $this->cart_item_options
|
||||||
|
->where('cart_item_id', $cart_item['id'])
|
||||||
|
->findAll();
|
||||||
|
|
||||||
|
if (!empty($existing_cart_item_options)) {
|
||||||
|
$option_ids = array_column($existing_cart_item_options, 'id');
|
||||||
|
$this->cart_item_options->whereIn('id', $option_ids)->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return $this->fail('No variation found!', 400);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case 3: // Remove one item
|
||||||
|
$cart_item = $this->cart_items->find($cart_item_id);
|
||||||
|
// print_r(123123);exit;
|
||||||
|
if (!$cart_item || $cart_item['cart_id'] != $cart['id']) {
|
||||||
|
return $this->fail('Cart item not found', 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->cart_items->delete($cart_item['id']);
|
||||||
|
$this->cart_item_options->where('cart_item_id', $cart_item['id'])->delete();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 4: // Remove all items
|
||||||
|
$all_cart_item = $this->cart_items->where('cart_id', $cart['id'])->findAll();
|
||||||
|
foreach ($all_cart_item as $item) {
|
||||||
|
$this->cart_item_options->where('cart_item_id', $item['id'])->delete();
|
||||||
|
$this->cart_items->delete($item['id']);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return $this->fail('Invalid action', 400);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// $this->calculate_service->calculateCartTotals($cart['id'], $outlet_id);
|
||||||
|
|
||||||
|
$this->db->transComplete();
|
||||||
|
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 200,
|
||||||
|
'message' => 'Cart updated successfully'
|
||||||
|
]);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$this->db->transRollback();
|
||||||
|
return $this->fail($e->getMessage(), 400);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function deleteCart()
|
||||||
|
{
|
||||||
|
$validation = $this->validate([
|
||||||
|
'customer_id' => 'required|numeric',
|
||||||
|
'outlet_id' => 'required|numeric',
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (!$validation) {
|
||||||
|
return $this->failValidationErrors($this->validator->getErrors());
|
||||||
|
}
|
||||||
|
|
||||||
|
$customer_id = $this->request->getVar('customer_id');
|
||||||
|
$outlet_id = $this->request->getVar('outlet_id');
|
||||||
|
|
||||||
|
$cart = $this->carts->where('customer_id', $customer_id)
|
||||||
|
->where('outlet_id', $outlet_id)
|
||||||
|
->where('status', 'active')
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if ($cart) {
|
||||||
|
$this->carts->update($cart['id'], ['status' => 'trash']);
|
||||||
|
$this->carts->delete($cart['id']);
|
||||||
|
$exist_cart_item = getColumnValues($this->cart_items, 'cart_id', $cart['id'], 'id');
|
||||||
|
$this->cart_items->where('cart_id', $cart['id'])->delete();
|
||||||
|
$this->cart_item_options->whereIn('cart_item_id', $exist_cart_item)->delete();
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 200,
|
||||||
|
'message' => 'Cart delete successfully'
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
return $this->fail('Cart not found', 400);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCartItemsDetails($cart_item_id = null)
|
||||||
|
{
|
||||||
|
$cart_item = $this->cart_items->find($cart_item_id);
|
||||||
|
if (!$cart_item) {
|
||||||
|
return $this->fail('Cart item not found', 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
$cart_item['variation'] = $this->menu_item_variations->find($cart_item['variation_id']);
|
||||||
|
$cart_item['options'] = $this->cart_item_options
|
||||||
|
->select('cart_item_options.*, options_groups.title as option_group_title')
|
||||||
|
->join('options_groups', 'options_groups.id = cart_item_options.option_group_id', 'left')
|
||||||
|
->where('cart_item_id', $cart_item_id)
|
||||||
|
->findAll();
|
||||||
|
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 200,
|
||||||
|
'message' => 'Cart item details retrieved successfully',
|
||||||
|
'data' => $cart_item
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
1125
app/Controllers/Frontend/CustomerController.php
Normal file
1125
app/Controllers/Frontend/CustomerController.php
Normal file
File diff suppressed because it is too large
Load Diff
33
app/Controllers/Frontend/GrabController.php
Normal file
33
app/Controllers/Frontend/GrabController.php
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controllers\Frontend;
|
||||||
|
|
||||||
|
use App\Controllers\BaseController;
|
||||||
|
use CodeIgniter\API\ResponseTrait;
|
||||||
|
use App\Libraries\Grab;
|
||||||
|
use App\Models\LogGrab;
|
||||||
|
|
||||||
|
class GrabController extends BaseController
|
||||||
|
{
|
||||||
|
protected $grab;
|
||||||
|
use ResponseTrait;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->grab = new Grab();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function webhook()
|
||||||
|
{
|
||||||
|
$rawBody = file_get_contents('php://input');
|
||||||
|
$data = json_decode($rawBody, true);
|
||||||
|
if ($data) {
|
||||||
|
$this->grab->handleWebhook($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 200,
|
||||||
|
'message' => 'Webhook received'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
39
app/Controllers/Frontend/LalamoveController.php
Normal file
39
app/Controllers/Frontend/LalamoveController.php
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controllers\Frontend;
|
||||||
|
|
||||||
|
use App\Controllers\BaseController;
|
||||||
|
use CodeIgniter\API\ResponseTrait;
|
||||||
|
use App\Libraries\Lalamove;
|
||||||
|
use App\Models\LogLalamove;
|
||||||
|
|
||||||
|
class LalamoveController extends BaseController
|
||||||
|
{
|
||||||
|
protected $lalamove;
|
||||||
|
use ResponseTrait;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->lalamove = new Lalamove();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function webhook()
|
||||||
|
{
|
||||||
|
// $log_lalamove = new LogLalamove();
|
||||||
|
// $log_lalamove->insert([
|
||||||
|
// 'url' => 'https://icom.ipsgroup.com.my/api/lalamove/webhook',
|
||||||
|
// 'request' => json_encode($this->request->getJSON(true)),
|
||||||
|
// 'respond' => 'Webhook received',
|
||||||
|
// ]);
|
||||||
|
$rawBody = file_get_contents('php://input');
|
||||||
|
$data = json_decode($rawBody, true);
|
||||||
|
if($data){
|
||||||
|
$this->lalamove->handleWebhook($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 200,
|
||||||
|
'message' => 'Webhook received'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
240
app/Controllers/Frontend/MenuItemController.php
Normal file
240
app/Controllers/Frontend/MenuItemController.php
Normal file
@ -0,0 +1,240 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controllers\Frontend;
|
||||||
|
|
||||||
|
use App\Models\MenuCategories;
|
||||||
|
use App\Models\MenuImages;
|
||||||
|
use App\Models\MenuItemCategories;
|
||||||
|
use App\Models\MenuItemOptionsGroups;
|
||||||
|
use App\Models\MenuItems;
|
||||||
|
use App\Models\MenuItemTags;
|
||||||
|
use App\Models\MenuItemVariations;
|
||||||
|
use App\Models\RegularItemAvailability;
|
||||||
|
use App\Models\SeasonalItemAvailability;
|
||||||
|
use App\Models\VariationOptionsGroups;
|
||||||
|
use App\Models\VariationTags;
|
||||||
|
use CodeIgniter\HTTP\ResponseInterface;
|
||||||
|
use CodeIgniter\RESTful\ResourceController;
|
||||||
|
use CodeIgniter\Database\Config;
|
||||||
|
use App\Models\OutletMenus;
|
||||||
|
use App\Controllers\BaseController;
|
||||||
|
use App\Models\Options;
|
||||||
|
use App\Models\OptionsGroups;
|
||||||
|
use CodeIgniter\API\ResponseTrait;
|
||||||
|
|
||||||
|
|
||||||
|
class MenuItemController extends BaseController
|
||||||
|
{
|
||||||
|
use ResponseTrait;
|
||||||
|
private $db;
|
||||||
|
private $menu_categories;
|
||||||
|
private $menu_items;
|
||||||
|
private $menu_items_categories;
|
||||||
|
private $menu_item_tags;
|
||||||
|
private $menu_item_variations;
|
||||||
|
private $menu_item_options_groups;
|
||||||
|
private $variation_options_groups;
|
||||||
|
private $variation_tags;
|
||||||
|
private $regular_item_availability;
|
||||||
|
private $seasonal_item_availability;
|
||||||
|
private $menu_images;
|
||||||
|
private $outlet_menus;
|
||||||
|
private $options;
|
||||||
|
private $option_groups;
|
||||||
|
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->menu_categories = new MenuCategories();
|
||||||
|
$this->menu_items = new MenuItems();
|
||||||
|
$this->menu_items_categories = new MenuItemCategories();
|
||||||
|
$this->menu_item_tags = new MenuItemTags();
|
||||||
|
$this->menu_item_variations = new MenuItemVariations();
|
||||||
|
$this->menu_item_options_groups = new MenuItemOptionsGroups();
|
||||||
|
$this->variation_options_groups = new VariationOptionsGroups();
|
||||||
|
$this->variation_tags = new VariationTags();
|
||||||
|
$this->regular_item_availability = new RegularItemAvailability();
|
||||||
|
$this->seasonal_item_availability = new SeasonalItemAvailability();
|
||||||
|
$this->menu_images = new MenuImages();
|
||||||
|
$this->outlet_menus = new OutletMenus();
|
||||||
|
$this->options = new Options();
|
||||||
|
$this->option_groups = new OptionsGroups();
|
||||||
|
$this->db = Config::connect();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
$groups = $this->option_groups->findAll();
|
||||||
|
$data = [];
|
||||||
|
|
||||||
|
foreach ($groups as $group) {
|
||||||
|
$group['options'] = $this->options
|
||||||
|
->where('option_group_id', $group['id'])
|
||||||
|
->where('deleted_at', null)
|
||||||
|
->findAll();
|
||||||
|
$data[] = $group;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->respond(['status' => 200, 'data' => $data]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function show($id = null)
|
||||||
|
{
|
||||||
|
$menuItem = $this->menu_items->find($id);
|
||||||
|
|
||||||
|
if (empty($menuItem)) {
|
||||||
|
return $this->fail("No menu item found.", 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
$menuItemData = [];
|
||||||
|
|
||||||
|
if ($menuItem) {
|
||||||
|
$menu_tag = $this->menu_item_tags->where('menu_item_id', $menuItem['id'])->findAll();
|
||||||
|
$menu_option_group = $this->menu_item_options_groups->where('menu_item_id', $menuItem['id'])->findAll();
|
||||||
|
$menuItemData[] = [
|
||||||
|
'id' => $menuItem['id'],
|
||||||
|
'title' => $menuItem['title'],
|
||||||
|
'category' => getMenuCategory($menuItem['id']),
|
||||||
|
'short_description' => $menuItem['short_description'],
|
||||||
|
'long_description' => $menuItem['long_description'],
|
||||||
|
'price' => $menuItem['price'],
|
||||||
|
'order_index' => $menuItem['order_index'],
|
||||||
|
'availability_type' => $menuItem['availability_type'],
|
||||||
|
'availability' => getAvailability($menuItem['id'], $menuItem['availability_type']),
|
||||||
|
'status' => $menuItem['status'],
|
||||||
|
'image' => getMenuImage($menuItem['id']),
|
||||||
|
'created_at' => $menuItem['created_at'],
|
||||||
|
'menu_tag' => getMenuTag($menuItem['id']),
|
||||||
|
'menu_option_group' => getMenuOptionGroup($menuItem['id']),
|
||||||
|
'variation' => getVariationRelation($menuItem['id'])
|
||||||
|
];
|
||||||
|
}
|
||||||
|
return $this->respond(["status" => 200, "message" => "Successfully retrive data!", "data" => $menuItemData]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function showOption($id = null)
|
||||||
|
{
|
||||||
|
$group = $this->option_groups->find($id);
|
||||||
|
|
||||||
|
if (!$group) {
|
||||||
|
return $this->failNotFound("Option group not found.");
|
||||||
|
}
|
||||||
|
|
||||||
|
$group['options'] = $this->options
|
||||||
|
->where('option_group_id', $group['id'])
|
||||||
|
->where('deleted_at', null)
|
||||||
|
->findAll();
|
||||||
|
|
||||||
|
return $this->respond(['status' => 200, 'data' => $group]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAllMenus($outlet_id = null)
|
||||||
|
{
|
||||||
|
$db = \Config\Database::connect();
|
||||||
|
|
||||||
|
// Get all active categories first
|
||||||
|
$menu_categories = $db->table('menu_categories')
|
||||||
|
->select('id, title, image_url, status, compressed_image_url, order_index')
|
||||||
|
->where('status', 'active')
|
||||||
|
->where('deleted_at', null)
|
||||||
|
->orderBy('order_index', 'ASC')
|
||||||
|
->get()
|
||||||
|
->getResult();
|
||||||
|
|
||||||
|
// Get all tags for mapping
|
||||||
|
$all_tags = $db->table('tags')->select('id, title, icon_url')->get()->getResult();
|
||||||
|
$tagMap = [];
|
||||||
|
foreach ($all_tags as $tag) {
|
||||||
|
$tagMap[$tag->id] = [
|
||||||
|
'id' => $tag->id,
|
||||||
|
'title' => $tag->title,
|
||||||
|
'icon_url' => $tag->icon_url
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$menu_items = [];
|
||||||
|
|
||||||
|
// Loop through each category to get corresponding items
|
||||||
|
foreach ($menu_categories as $category) {
|
||||||
|
// Get menu items for this category
|
||||||
|
$category_items = $db->table('menu_items')
|
||||||
|
->select('menu_items.id, menu_items.title, menu_items.short_description, menu_items.price, menu_items.availability_type, menu_items.order_index, menu_items.status, menu_items.membership_tier, menu_items.pwp')
|
||||||
|
->join('menu_item_categories', 'menu_item_categories.menu_item_id = menu_items.id')
|
||||||
|
->where('menu_item_categories.category_id', $category->id)
|
||||||
|
->where('menu_items.status', 'active')
|
||||||
|
->where('menu_items.deleted_at', null)
|
||||||
|
->orderBy('menu_items.order_index', 'ASC')
|
||||||
|
->get()
|
||||||
|
->getResult();
|
||||||
|
|
||||||
|
// Process each item in this category
|
||||||
|
foreach ($category_items as $item) {
|
||||||
|
// Get item images
|
||||||
|
$images = $db->table('menu_images')
|
||||||
|
->select('image_url, image_url_compressed')
|
||||||
|
->where('menu_item_id', $item->id)
|
||||||
|
->get()
|
||||||
|
->getResult();
|
||||||
|
|
||||||
|
// Get item tags
|
||||||
|
$menu_item_tags_links = $db->table('menu_item_tags')
|
||||||
|
->select('tag_id')
|
||||||
|
->where('menu_item_id', $item->id)
|
||||||
|
->get()
|
||||||
|
->getResult();
|
||||||
|
|
||||||
|
$tag_list = [];
|
||||||
|
foreach ($menu_item_tags_links as $tag_link) {
|
||||||
|
if (isset($tagMap[$tag_link->tag_id])) {
|
||||||
|
$tag_list[] = $tagMap[$tag_link->tag_id];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if item is available in outlet
|
||||||
|
$is_available = $this->outlet_menus
|
||||||
|
->where('outlet_id', $outlet_id)
|
||||||
|
->where('menu_item_id', $item->id)
|
||||||
|
->first();
|
||||||
|
|
||||||
|
// Get category IDs for this item (should include current category)
|
||||||
|
$item_categories = $db->table('menu_item_categories')
|
||||||
|
->select('category_id')
|
||||||
|
->where('menu_item_id', $item->id)
|
||||||
|
->where('deleted_at', null)
|
||||||
|
->get()
|
||||||
|
->getResult();
|
||||||
|
|
||||||
|
$category_ids = [];
|
||||||
|
foreach ($item_categories as $cat_link) {
|
||||||
|
$category_ids[] = $cat_link->category_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
$membership_tier = $item->membership_tier;
|
||||||
|
|
||||||
|
$menu_items[] = [
|
||||||
|
'id' => $item->id,
|
||||||
|
'title' => $item->title,
|
||||||
|
'short_description' => $item->short_description,
|
||||||
|
'price' => $item->price,
|
||||||
|
'availability_type' => $item->availability_type,
|
||||||
|
'order_index' => $item->order_index,
|
||||||
|
'status' => $item->status,
|
||||||
|
'images' => $images,
|
||||||
|
'category_ids' => $category_ids,
|
||||||
|
'tags' => $tag_list,
|
||||||
|
'is_available' => $is_available ? true : false,
|
||||||
|
'membership_tier' => $membership_tier,
|
||||||
|
'pwp' => $item->pwp,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->response->setJSON([
|
||||||
|
'status' => 'success',
|
||||||
|
'response' => '200',
|
||||||
|
'Categories' => $menu_categories,
|
||||||
|
'Items' => $menu_items
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
748
app/Controllers/Frontend/OrderController.php
Normal file
748
app/Controllers/Frontend/OrderController.php
Normal file
@ -0,0 +1,748 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controllers\Frontend;
|
||||||
|
|
||||||
|
use CodeIgniter\HTTP\ResponseInterface;
|
||||||
|
use CodeIgniter\RESTful\ResourceController;
|
||||||
|
use App\Models\CartItemOptions;
|
||||||
|
use App\Models\CartItems;
|
||||||
|
use App\Models\Carts;
|
||||||
|
use App\Models\Customer;
|
||||||
|
use App\Models\CustomerWallet;
|
||||||
|
use App\Models\OrderItemOptions;
|
||||||
|
use App\Models\OrderItems;
|
||||||
|
use App\Models\OrderPayments;
|
||||||
|
use App\Models\Orders;
|
||||||
|
use App\Models\OrderTaxes;
|
||||||
|
use App\Models\Outlet;
|
||||||
|
use App\Models\MenuItemVariations;
|
||||||
|
use CodeIgniter\Database\Config;
|
||||||
|
use App\Libraries\Fiuu;
|
||||||
|
use App\Models\OrderDeliveries;
|
||||||
|
use App\Models\VoucherRedemptions;
|
||||||
|
use App\Models\PromoRedemptionRecord;
|
||||||
|
|
||||||
|
helper('outlet');
|
||||||
|
class OrderController extends ResourceController
|
||||||
|
{
|
||||||
|
private $carts;
|
||||||
|
private $cart_items;
|
||||||
|
private $cart_item_options;
|
||||||
|
private $orders;
|
||||||
|
private $order_items;
|
||||||
|
private $order_item_options;
|
||||||
|
private $order_payments;
|
||||||
|
private $order_taxes;
|
||||||
|
private $customer;
|
||||||
|
private $customer_wallet;
|
||||||
|
private $db;
|
||||||
|
private $cart_service;
|
||||||
|
private $calculate_service;
|
||||||
|
private $promo_service;
|
||||||
|
private $outlet;
|
||||||
|
private $fiuu;
|
||||||
|
private $voucher_service;
|
||||||
|
private $variations;
|
||||||
|
private $order_deliveries;
|
||||||
|
private $promo_redemptions_record;
|
||||||
|
private $voucher_redemptions;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->carts = new Carts();
|
||||||
|
$this->cart_items = new CartItems();
|
||||||
|
$this->cart_item_options = new CartItemOptions();
|
||||||
|
$this->orders = new Orders();
|
||||||
|
$this->order_items = new OrderItems();
|
||||||
|
$this->order_item_options = new OrderItemOptions();
|
||||||
|
$this->customer = new Customer();
|
||||||
|
$this->order_payments = new OrderPayments();
|
||||||
|
$this->order_taxes = new OrderTaxes();
|
||||||
|
$this->customer_wallet = new CustomerWallet();
|
||||||
|
$this->db = Config::connect();
|
||||||
|
$this->cart_service = service('cartService');
|
||||||
|
$this->calculate_service = service('calculateService');
|
||||||
|
$this->promo_service = service('promoService');
|
||||||
|
$this->voucher_service = service('voucherService');
|
||||||
|
$this->outlet = new Outlet();
|
||||||
|
$this->fiuu = new Fiuu();
|
||||||
|
$this->variations = new MenuItemVariations();
|
||||||
|
$this->order_deliveries = new OrderDeliveries();
|
||||||
|
$this->promo_redemptions_record = new PromoRedemptionRecord();
|
||||||
|
$this->voucher_redemptions = new VoucherRedemptions();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createOrder()
|
||||||
|
{
|
||||||
|
$validation = $this->validate([
|
||||||
|
'customer_id' => 'required|numeric',
|
||||||
|
'outlet_id' => 'required|numeric',
|
||||||
|
'order_type' => 'required',
|
||||||
|
'customer_address_id' => 'permit_empty|numeric',
|
||||||
|
'payment_method' => 'required',
|
||||||
|
'selected_date' => 'permit_empty|string',
|
||||||
|
'selected_time' => 'permit_empty|string',
|
||||||
|
'latitude' => 'permit_empty|string',
|
||||||
|
'longitude' => 'permit_empty|string',
|
||||||
|
'notes' => 'permit_empty|string',
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (!$validation) {
|
||||||
|
return $this->failValidationErrors($this->validator->getErrors());
|
||||||
|
}
|
||||||
|
|
||||||
|
$customer_id = $this->request->getVar('customer_id');
|
||||||
|
$outlet_id = $this->request->getVar('outlet_id');
|
||||||
|
$customer_address_id = $this->request->getVar('customer_address_id');
|
||||||
|
$order_type = strtolower(str_replace('-', '', $this->request->getVar('order_type')));
|
||||||
|
$payment_method = $this->request->getVar('payment_method');
|
||||||
|
$selected_date = $this->request->getVar('selected_date') ?? date('Y-m-d');
|
||||||
|
$selected_time = $this->request->getVar('selected_time') ?? date('H:i');
|
||||||
|
$real_selected_date = $this->request->getVar('selected_date');
|
||||||
|
$real_selected_time = $this->request->getVar('selected_time');
|
||||||
|
$latitude = $this->request->getVar('latitude');
|
||||||
|
$longitude = $this->request->getVar('longitude');
|
||||||
|
$notes = $this->request->getVar('notes');
|
||||||
|
$address = $this->request->getVar('address');
|
||||||
|
$cart = $this->carts->where('customer_id', $customer_id)
|
||||||
|
->where('outlet_id', $outlet_id)
|
||||||
|
->where('status', 'active')
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if (!$cart) {
|
||||||
|
return $this->fail('Cart not found', 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
$customer = $this->customer->find($customer_id);
|
||||||
|
|
||||||
|
if (!$customer) {
|
||||||
|
return $this->fail('Customer not found', 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
$promo_or_voucher = null;
|
||||||
|
|
||||||
|
if ($cart['promo_code_id'] > 0) {
|
||||||
|
$check_promo = $this->promo_service->checkPromoAvailability($cart['promo_code_id'], $order_type, $customer_id);
|
||||||
|
if (isset($check_promo['status']) && $check_promo['status'] == 400) {
|
||||||
|
$this->calculate_service->resetVoucher($cart['id']);
|
||||||
|
return $this->respond($check_promo);
|
||||||
|
}
|
||||||
|
$promo_or_voucher = 'promo';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($cart['customer_voucher_list_id'] > 0) {
|
||||||
|
$check_voucher = $this->voucher_service->checkVoucherAvailability($cart['customer_voucher_list_id'], $order_type, $customer_id);
|
||||||
|
if (isset($check_voucher['status']) && $check_voucher['status'] == 400) {
|
||||||
|
$this->calculate_service->resetVoucher($cart['id']);
|
||||||
|
return $this->respond($check_voucher);
|
||||||
|
}
|
||||||
|
$promo_or_voucher = 'voucher';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$cart_total = $this->calculate_service->calculateCartTotals($cart['id'], $cart['outlet_id'], $real_selected_date, $real_selected_time, $latitude, $longitude, $order_type, $address, $promo_or_voucher);
|
||||||
|
// print_r($cart_total);
|
||||||
|
// exit;
|
||||||
|
if (isset($cart_total['status']) && $cart_total['status'] == 400) {
|
||||||
|
$response = [
|
||||||
|
'status' => 400,
|
||||||
|
'message' => $cart_total['message']
|
||||||
|
];
|
||||||
|
return $this->respond($response, 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
$cart_total = $cart_total['data'];
|
||||||
|
|
||||||
|
if (count($cart_total['invalid_items']) > 0) {
|
||||||
|
return $this->fail('Menu got updated, try again', 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($payment_method == 'wallet') {
|
||||||
|
if ($customer['customer_wallet'] < $cart_total['order_summary']['grand_total']) {
|
||||||
|
return $this->fail('Insufficient Wallet Balance', 400);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($cart_total['order_summary']['grand_total'] < 0) {
|
||||||
|
return $this->fail('Invalid Grand Total', 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
//check operation date and time
|
||||||
|
$check_operation_date_and_time = checkOperationDateAndTime($outlet_id, $selected_date, $selected_time);
|
||||||
|
|
||||||
|
if (!$check_operation_date_and_time) {
|
||||||
|
return $this->fail('Outlet is not operated on the selected date and time', 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->db->transStart();
|
||||||
|
|
||||||
|
try {
|
||||||
|
$orderData = [
|
||||||
|
'customer_id' => $customer_id,
|
||||||
|
'outlet_id' => $outlet_id,
|
||||||
|
'customer_address_id' => $customer_address_id,
|
||||||
|
'order_type' => $order_type,
|
||||||
|
'status' => 'pending',
|
||||||
|
'payment_status' => 'unpaid',
|
||||||
|
'packaging_charge' => $cart_total['order_summary']['packaging_charge'] ?? 0,
|
||||||
|
'payment_method' => $payment_method,
|
||||||
|
'subtotal_amount' => $cart_total['order_summary']['subtotal_amount'],
|
||||||
|
'discount_amount' => $cart_total['order_summary']['discount_amount'],
|
||||||
|
'tax_amount' => $cart_total['order_summary']['tax_amount'],
|
||||||
|
'delivery_fee' => $cart_total['order_summary']['delivery_fee'] ?? 0,
|
||||||
|
'rounding_amount' => $cart_total['order_summary']['rounding_amount'],
|
||||||
|
'grand_total' => $cart_total['order_summary']['grand_total'],
|
||||||
|
'promo_code_id' => $cart_total['order_summary']['promo_code_id'],
|
||||||
|
'promo_discount_amount' => $cart_total['order_summary']['promo_discount_amount'],
|
||||||
|
'customer_voucher_list_id' => $cart_total['order_summary']['customer_voucher_list_id'],
|
||||||
|
'voucher_discount_amount' => $cart_total['order_summary']['voucher_discount_amount'],
|
||||||
|
'placed_at' => '',
|
||||||
|
'selected_date' => $real_selected_date,
|
||||||
|
'selected_time' => $real_selected_time,
|
||||||
|
'expected_ready_time' => '',
|
||||||
|
'notes' => $notes,
|
||||||
|
'lalamove_quot_id' => $cart['lalamove_quot_id'] ?? null,
|
||||||
|
'grab_quot_id' => $cart['grab_quot_id'] ?? null
|
||||||
|
];
|
||||||
|
|
||||||
|
//insert order
|
||||||
|
$order_id = $this->orders->insert($orderData);
|
||||||
|
|
||||||
|
if ($promo_or_voucher != null) {
|
||||||
|
if ($promo_or_voucher == 'promo') {
|
||||||
|
$this->promo_redemptions_record->insert([
|
||||||
|
'order_id' => $order_id,
|
||||||
|
'promo_codes_id' => $orderData['promo_code_id'],
|
||||||
|
'customer_id' => $orderData['customer_id'],
|
||||||
|
]);
|
||||||
|
} else if ($promo_or_voucher == 'voucher') {
|
||||||
|
$this->voucher_redemptions->insert([
|
||||||
|
'order_id' => $order_id,
|
||||||
|
'customer_voucher_list_id' => $orderData['customer_voucher_list_id'],
|
||||||
|
'customer_id' => $orderData['customer_id'],
|
||||||
|
'order_type' => $orderData['order_type'],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($order_id > 0) {
|
||||||
|
$today_order_count = $this->orders->where('created_at >=', date('Y-m-d 00:00:00'))->where('created_at <=', date('Y-m-d 23:59:59'))->countAllResults();
|
||||||
|
$order_so = date('ymd') . str_pad($today_order_count, 5, '0', STR_PAD_LEFT);
|
||||||
|
$this->orders->update($order_id, ['order_so' => $order_so]);
|
||||||
|
}
|
||||||
|
//insert order items
|
||||||
|
$cartItems = $this->cart_items->where('cart_id', $cart['id'])->findAll();
|
||||||
|
foreach ($cartItems as $cartItem) {
|
||||||
|
$orderItemData = [
|
||||||
|
'order_id' => $order_id,
|
||||||
|
'menu_item_id' => $cartItem['menu_item_id'],
|
||||||
|
'variation_id' => $cartItem['variation_id'],
|
||||||
|
'title' => $cartItem['title'],
|
||||||
|
'unit_price' => $cartItem['unit_price'],
|
||||||
|
'quantity' => $cartItem['quantity'],
|
||||||
|
'line_subtotal' => $cartItem['line_subtotal'],
|
||||||
|
'order_index' => $cartItem['order_index'],
|
||||||
|
];
|
||||||
|
|
||||||
|
$orderItemId = $this->order_items->insert($orderItemData);
|
||||||
|
|
||||||
|
$cartItemOptions = $this->cart_item_options->where('cart_item_id', $cartItem['id'])->findAll();
|
||||||
|
|
||||||
|
foreach ($cartItemOptions as $option) {
|
||||||
|
$orderItemOptionData = [
|
||||||
|
'order_item_id' => $orderItemId,
|
||||||
|
'option_id' => $option['option_id'],
|
||||||
|
'option_title' => $option['option_title'],
|
||||||
|
'price_adjustment' => $option['price_adjustment'],
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->order_item_options->insert($orderItemOptionData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//insert order taxes
|
||||||
|
foreach ($cart_total['tax_detail'] as $tax_order) {
|
||||||
|
$tax_data = [
|
||||||
|
'order_id' => $order_id,
|
||||||
|
'tax_type' => $tax_order['tax_type'],
|
||||||
|
'tax_rate' => $tax_order['tax_rate'],
|
||||||
|
'tax_amount' => $tax_order['tax_amount'],
|
||||||
|
|
||||||
|
];
|
||||||
|
$this->order_taxes->insert($tax_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
$respond_data = [];
|
||||||
|
//insert order payments
|
||||||
|
if ($payment_method == 'wallet') {
|
||||||
|
|
||||||
|
$payment = [
|
||||||
|
'order_id' => $order_id,
|
||||||
|
'payment_method' => $payment_method,
|
||||||
|
'amount' => $cart_total['order_summary']['grand_total'],
|
||||||
|
'transaction_id' => 0,
|
||||||
|
'status' => 'pending',
|
||||||
|
'paid_at' => '',
|
||||||
|
];
|
||||||
|
// echo(123);exit;
|
||||||
|
|
||||||
|
$this->order_payments->insert($payment);
|
||||||
|
|
||||||
|
completeOrder($order_id);
|
||||||
|
} else {
|
||||||
|
|
||||||
|
//generate payment details & url
|
||||||
|
$payment = [
|
||||||
|
'order_id' => $order_id,
|
||||||
|
'payment_method' => $payment_method,
|
||||||
|
'amount' => $cart_total['order_summary']['grand_total'],
|
||||||
|
'transaction_id' => 0,
|
||||||
|
'status' => 'pending',
|
||||||
|
'paid_at' => '',
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->order_payments->insert($payment);
|
||||||
|
|
||||||
|
$payment_details = [
|
||||||
|
'bill_name' => $customer['name'],
|
||||||
|
'bill_email' => $customer['email'],
|
||||||
|
'bill_mobile' => $customer['phone'],
|
||||||
|
'bill_desc' => 'US Pizza - Payment for ' . ucfirst($order_type) . ' - ' . $order_id,
|
||||||
|
];
|
||||||
|
|
||||||
|
$result = $this->fiuu->createPayment($order_so, $cart_total['order_summary']['grand_total'], $payment_details);
|
||||||
|
$respond_data['redirect_url'] = $result['redirect_url'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->carts->update($cart['id'], ['status' => 'completed']);
|
||||||
|
|
||||||
|
$this->db->transComplete();
|
||||||
|
|
||||||
|
$order = $this->orders->find($order_id);
|
||||||
|
$order['items'] = $this->order_items->where('order_id', $order_id)->findAll();
|
||||||
|
|
||||||
|
foreach ($order['items'] as &$item) {
|
||||||
|
$item['options'] = $this->order_item_options->where('order_item_id', $item['id'])->findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
$respond_data['status'] = 200;
|
||||||
|
$respond_data['message'] = 'Order created successfully';
|
||||||
|
$respond_data['order'] = $order;
|
||||||
|
return $this->respond($respond_data);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$this->db->transRollback();
|
||||||
|
print_r($e->getMessage());
|
||||||
|
return $this->fail('Cannot checkout order. Please try again.', 400);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createOrderAgain($order_id = null)
|
||||||
|
{
|
||||||
|
$order = $this->orders->select('orders.*, customer_addresses.address, customer_addresses.latitude, customer_addresses.longitude')
|
||||||
|
->join('customer_addresses', 'customer_addresses.id = orders.customer_address_id', 'left')
|
||||||
|
->find($order_id);
|
||||||
|
if (!$order) {
|
||||||
|
return $this->fail('Order not found', 400);
|
||||||
|
}
|
||||||
|
$outlet = $this->outlet->find($order['outlet_id']);
|
||||||
|
$outlet_title = $outlet['title'] ?? '';
|
||||||
|
|
||||||
|
//check outlet cart exist
|
||||||
|
$existing_cart = $this->carts
|
||||||
|
->where('customer_id', $order['customer_id'])
|
||||||
|
->where('outlet_id', $order['outlet_id'])
|
||||||
|
->where('status', 'active')
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if ($existing_cart) {
|
||||||
|
//clear all cart items
|
||||||
|
$this->cart_items->where('cart_id', $existing_cart['id'])->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
//select order items
|
||||||
|
$order_items = $this->order_items->where('order_id', $order_id)->findAll();
|
||||||
|
// print_r($order_items);exit;
|
||||||
|
foreach ($order_items as $order_item) {
|
||||||
|
if ($order_item['unit_price'] > 0) {
|
||||||
|
$options = $this->order_item_options
|
||||||
|
->select('options.option_group_id, order_item_options.option_id')
|
||||||
|
->join('options', 'options.id = order_item_options.option_id')
|
||||||
|
->where('order_item_id', $order_item['id'])
|
||||||
|
->findAll();
|
||||||
|
|
||||||
|
$option_group = [];
|
||||||
|
if (!empty($options)) {
|
||||||
|
// Group options by option_group_id
|
||||||
|
$grouped_options = [];
|
||||||
|
foreach ($options as $option) {
|
||||||
|
$grouped_options[$option['option_group_id']][] = $option['option_id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert to the expected format for cart service
|
||||||
|
foreach ($grouped_options as $group_id => $option_ids) {
|
||||||
|
$option_group[] = [
|
||||||
|
'group_id' => $group_id,
|
||||||
|
'option_ids' => $option_ids
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// print_r($option_group);exit;
|
||||||
|
|
||||||
|
$addCart = $this->cart_service->addCartItem($order['customer_id'], $order['outlet_id'], $existing_cart, $order_item['menu_item_id'], $order_item['variation_id'], $option_group, $order_item['quantity'], false);
|
||||||
|
if (isset($addCart['status']) && $addCart['status'] == 400) {
|
||||||
|
return $this->fail($addCart['message'], 400);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'order_id' => $order['id'],
|
||||||
|
'customer_id' => $order['customer_id'],
|
||||||
|
'outlet_id' => $order['outlet_id'],
|
||||||
|
'outlet_title' => $outlet_title,
|
||||||
|
'customer_address_id' => $order['customer_address_id'],
|
||||||
|
'order_type' => $order['order_type'],
|
||||||
|
'address' => $order['address'],
|
||||||
|
'latitude' => $order['latitude'],
|
||||||
|
'longitude' => $order['longitude']
|
||||||
|
];
|
||||||
|
return $this->respond(['status' => 200, 'message' => 'Order created successfully', 'data' => $data]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createOrderVip()
|
||||||
|
{
|
||||||
|
$customer_id = $this->request->getVar('customer_id');
|
||||||
|
$outlet_id = HQ_OUTLET_ID;
|
||||||
|
$outlet = $this->outlet->find($outlet_id);
|
||||||
|
$order_type = 'dinein';
|
||||||
|
$outlet_title = $outlet['title'] ?? '';
|
||||||
|
|
||||||
|
//check outlet cart exist
|
||||||
|
$existing_cart = $this->carts
|
||||||
|
->where('customer_id', $customer_id)
|
||||||
|
->where('outlet_id', $outlet_id)
|
||||||
|
->where('status', 'active')
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if ($existing_cart) {
|
||||||
|
//clear all cart items
|
||||||
|
$this->cart_items->where('cart_id', $existing_cart['id'])->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
//select VIP Cart Item
|
||||||
|
$addCart = $this->cart_service->addCartItem($customer_id, $outlet_id, $existing_cart, VIP_MENU_ITEM_ID, 0, [], 1, false);
|
||||||
|
if (isset($addCart['status']) && $addCart['status'] == 400) {
|
||||||
|
return $this->fail($addCart['message'], 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'customer_id' => $customer_id,
|
||||||
|
'outlet_id' => $outlet_id,
|
||||||
|
'outlet_title' => $outlet_title,
|
||||||
|
'order_type' => $order_type,
|
||||||
|
];
|
||||||
|
return $this->respond(['status' => 200, 'message' => 'Order created successfully', 'data' => $data]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function showOrder($order_id = null)
|
||||||
|
{
|
||||||
|
// echo(123);exit;
|
||||||
|
$order = $this->orders->find($order_id);
|
||||||
|
if (!$order) {
|
||||||
|
return $this->fail('Order not found', 400);
|
||||||
|
}
|
||||||
|
//calculate grad_total before rounding
|
||||||
|
$grand_total_before_rounding = $order['grand_total'] - $order['rounding_amount'];
|
||||||
|
$order['grand_total_before_rounding'] = number_format($grand_total_before_rounding, 2);
|
||||||
|
|
||||||
|
$order['items'] = $this->order_items->where('order_id', $order_id)->findAll();
|
||||||
|
foreach ($order['items'] as &$item) {
|
||||||
|
$item['variation'] = $this->variations->find($item['variation_id']);
|
||||||
|
$item['options'] = $this->order_item_options->where('order_item_id', $item['id'])->findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
$order['taxes'] = $this->order_taxes->where('order_id', $order_id)->findAll();
|
||||||
|
|
||||||
|
$order['payments'] = $this->order_payments
|
||||||
|
->where('order_id', $order_id)
|
||||||
|
->orderBy('created_at', 'DESC')
|
||||||
|
->findAll();
|
||||||
|
|
||||||
|
$order['deliveries'] = $this->order_deliveries
|
||||||
|
->where('order_id', $order_id)
|
||||||
|
->orderBy('created_at', 'DESC')
|
||||||
|
->findAll();
|
||||||
|
|
||||||
|
$order['packaging_charge'] = $order['packaging_charge'] ?? 0;
|
||||||
|
$order['points'] = floor($order['grand_total']);
|
||||||
|
|
||||||
|
// print_r($order);exit;
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 200,
|
||||||
|
'message' => 'Order retrieved successfully',
|
||||||
|
'data' => $order
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function orderList($customer_id)
|
||||||
|
{
|
||||||
|
|
||||||
|
$start_date = $this->request->getVar('start_date');
|
||||||
|
$end_date = $this->request->getVar('end_date');
|
||||||
|
$status = $this->request->getVar('status');
|
||||||
|
$order_type = $this->request->getVar('order_type');
|
||||||
|
|
||||||
|
$orderQuery = $this->orders
|
||||||
|
->where('customer_id', $customer_id)
|
||||||
|
->orderBy('created_at', 'DESC');
|
||||||
|
|
||||||
|
if (!empty($start_date)) {
|
||||||
|
$orderQuery->where('created_at >=', $start_date . ' 00:00:00');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($end_date)) {
|
||||||
|
$orderQuery->where('created_at <=', $end_date . ' 23:59:59');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($status)) {
|
||||||
|
$orderQuery->where('status', $status);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($order_type)) {
|
||||||
|
$orderQuery->where('order_type', $order_type);
|
||||||
|
}
|
||||||
|
|
||||||
|
$orders = $orderQuery->findAll();
|
||||||
|
|
||||||
|
if (empty($orders)) {
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 200,
|
||||||
|
'message' => 'No orders found for this customer',
|
||||||
|
'data' => []
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($orders as &$order) {
|
||||||
|
$order_id = $order['id'];
|
||||||
|
|
||||||
|
$order['items'] = $this->order_items->where('order_id', $order_id)->findAll();
|
||||||
|
foreach ($order['items'] as &$item) {
|
||||||
|
$item['options'] = $this->order_item_options
|
||||||
|
->where('order_item_id', $item['id'])
|
||||||
|
->findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
$order['taxes'] = $this->order_taxes
|
||||||
|
->where('order_id', $order_id)
|
||||||
|
->findAll();
|
||||||
|
|
||||||
|
$order['payments'] = $this->order_payments
|
||||||
|
->where('order_id', $order_id)
|
||||||
|
->orderBy('created_at', 'DESC')
|
||||||
|
->findAll();
|
||||||
|
|
||||||
|
$order['packaging_charge'] = $order['packaging_charge'] ?? 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 200,
|
||||||
|
'message' => 'Orders retrieved successfully',
|
||||||
|
'data' => $orders
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// public function applyPromoCode(){
|
||||||
|
|
||||||
|
// $validation = $this->validate([
|
||||||
|
// 'promo_code' => 'required',
|
||||||
|
// 'cart_id' => 'required|numeric',
|
||||||
|
// 'outlet_id' => 'required|numeric',
|
||||||
|
// ]);
|
||||||
|
|
||||||
|
// if (!$validation) {
|
||||||
|
// return $this->failValidationErrors($this->validator->getErrors());
|
||||||
|
// }
|
||||||
|
|
||||||
|
// $promo_code = $this->request->getVar('promo_code');
|
||||||
|
// $cart_id = $this->request->getVar('cart_id');
|
||||||
|
// $outlet_id = $this->request->getVar('outlet_id');
|
||||||
|
// $free_item = $this->request->getVar('free_item') ?? [];
|
||||||
|
|
||||||
|
// if(empty($promo_code)){
|
||||||
|
// return $this->respond(['status' => 400, 'result' => 'Promo code is empty.']);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// $promo_code_id = $this->promo_service->checkPromoCode($promo_code);
|
||||||
|
|
||||||
|
// if(isset($promo_code_id['status']) && $promo_code_id['status'] == 400){
|
||||||
|
// //error message respond
|
||||||
|
// return $this->respond($promo_code_id);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// //update promo id
|
||||||
|
// $this->carts->update($cart_id, ['promo_code_id' => $promo_code_id]);
|
||||||
|
|
||||||
|
// $applyPromoCode = $this->calculate_service->calculateCartTotals($cart_id, $outlet_id, null, null, null, null, null, null, $free_item);
|
||||||
|
|
||||||
|
// return $this->respond($applyPromoCode);
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
|
//get all active outlets
|
||||||
|
// public function outletList()
|
||||||
|
// {
|
||||||
|
// $outlets = $this->outlet->getActiveOperatingHoursWithDaysList();
|
||||||
|
|
||||||
|
// if(empty($outlets)){
|
||||||
|
// return $this->respond(['status' => 400, 'result' => 'No outlet data found.']);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// return $this->respond(['status' => 200, 'result' => $outlets]);
|
||||||
|
// }
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
$outlets = $this->outlet->getOperatingHoursWithDaysList();
|
||||||
|
|
||||||
|
if (empty($outlets)) {
|
||||||
|
return $this->respond(['status' => 400, 'result' => 'No outlet data found.']);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->respond(['status' => 200, 'result' => $outlets]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function nearestOutletList($mode = null, $latitude = null, $longitude = null)
|
||||||
|
{
|
||||||
|
|
||||||
|
$outlets = $this->outlet->getActiveOperatingHoursWithDaysListAndDistance($mode, $latitude, $longitude);
|
||||||
|
|
||||||
|
if (empty($outlets)) {
|
||||||
|
return $this->respond(['status' => 400, 'result' => 'No outlet data found.']);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->respond(['status' => 200, 'result' => $outlets]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function showOutlet($outlet_id = null)
|
||||||
|
{
|
||||||
|
$result = $this->outlet->getOperatingHoursWithDays($outlet_id);
|
||||||
|
|
||||||
|
if (empty($result)) {
|
||||||
|
return $this->respond(['status' => 400, 'result' => 'No outlet data found.']);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->respond(['status' => 200, 'result' => $result]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function checkPayment($order_id = null)
|
||||||
|
{
|
||||||
|
$order = $this->orders->find($order_id);
|
||||||
|
if (!$order) {
|
||||||
|
return $this->fail('Order not found', 400);
|
||||||
|
}
|
||||||
|
$payment_status = $order['payment_status'];
|
||||||
|
if ($payment_status == 'paid') {
|
||||||
|
return $this->respond(['status' => 200, 'result' => 'Success', 'order_id' => $order_id]);
|
||||||
|
} else if ($payment_status == 'pending') {
|
||||||
|
return $this->respond(['status' => 200, 'result' => 'Pending', 'order_id' => $order_id]);
|
||||||
|
} else {
|
||||||
|
return $this->respond(['status' => 400, 'result' => 'Failed', 'order_id' => $order_id]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get driver location coordinates for real-time tracking
|
||||||
|
* Called every 5 seconds from mobile app
|
||||||
|
*/
|
||||||
|
public function getDriverLocation()
|
||||||
|
{
|
||||||
|
// Get order ID from request
|
||||||
|
$order_id = $this->request->getPost('order_id') ?? $this->request->getGet('order_id');
|
||||||
|
|
||||||
|
if (!$order_id) {
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'Order ID is required',
|
||||||
|
'data' => null
|
||||||
|
], 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get order details
|
||||||
|
$orders = new Orders();
|
||||||
|
$order = $orders->select('orders.*, order_deliveries.provider_name, order_deliveries.provider_order_id, order_deliveries.status')
|
||||||
|
->join('order_deliveries', 'order_deliveries.order_id = orders.id', 'left')
|
||||||
|
->where('orders.id', $order_id)
|
||||||
|
->where('orders.deleted_at', null)
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if (!$order) {
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'Order not found',
|
||||||
|
'data' => null
|
||||||
|
], 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if order has delivery
|
||||||
|
if (!$order['provider_name'] || !$order['provider_order_id']) {
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'Order has no active delivery',
|
||||||
|
'data' => null
|
||||||
|
], 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
$driver_location = null;
|
||||||
|
$error_message = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Check delivery provider and call respective API
|
||||||
|
if ($order['provider_name'] === 'Lalamove') {
|
||||||
|
$lalamove = new \App\Libraries\Lalamove();
|
||||||
|
$driver_location = $lalamove->getDriverLocation($order['provider_order_id']);
|
||||||
|
|
||||||
|
if (!$driver_location || isset($driver_location['error'])) {
|
||||||
|
$error_message = 'Unable to fetch Lalamove driver location';
|
||||||
|
}
|
||||||
|
} elseif ($order['provider_name'] === 'Grab') {
|
||||||
|
$grab = new \App\Libraries\Grab();
|
||||||
|
$driver_location = $grab->getDriverLocation($order['provider_order_id']);
|
||||||
|
|
||||||
|
if (!$driver_location || isset($driver_location['error'])) {
|
||||||
|
$error_message = 'Unable to fetch Grab driver location';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'Unsupported delivery provider: ' . $order['provider_name'],
|
||||||
|
'data' => null
|
||||||
|
], 400);
|
||||||
|
}
|
||||||
|
} catch (Exception $e) {
|
||||||
|
log_message('error', 'Driver location API error: ' . $e->getMessage());
|
||||||
|
$error_message = 'Failed to fetch driver location';
|
||||||
|
}
|
||||||
|
|
||||||
|
// If there's an error, return error response
|
||||||
|
if ($error_message) {
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => $error_message,
|
||||||
|
'data' => null
|
||||||
|
], 500);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return driver location data
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 'success',
|
||||||
|
'message' => 'Driver location retrieved successfully',
|
||||||
|
'data' => [
|
||||||
|
'order_id' => $order_id,
|
||||||
|
'provider' => $order['provider_name'],
|
||||||
|
'delivery_status' => $order['status'],
|
||||||
|
'driver_location' => $driver_location,
|
||||||
|
'timestamp' => date('Y-m-d H:i:s'),
|
||||||
|
'last_updated' => time()
|
||||||
|
]
|
||||||
|
], 200);
|
||||||
|
}
|
||||||
|
}
|
||||||
97
app/Controllers/Frontend/PaymentController.php
Normal file
97
app/Controllers/Frontend/PaymentController.php
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controllers\Frontend;
|
||||||
|
|
||||||
|
use App\Controllers\BaseController;
|
||||||
|
use CodeIgniter\HTTP\ResponseInterface;
|
||||||
|
use CodeIgniter\API\ResponseTrait;
|
||||||
|
use App\Models\Orders;
|
||||||
|
|
||||||
|
class PaymentController extends BaseController
|
||||||
|
{
|
||||||
|
use ResponseTrait;
|
||||||
|
|
||||||
|
private $fiuu;
|
||||||
|
private $order;
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->fiuu = new \App\Libraries\Fiuu();
|
||||||
|
$this->order = new Orders();
|
||||||
|
}
|
||||||
|
|
||||||
|
// public function createPayment()
|
||||||
|
// {
|
||||||
|
// $data = $this->request->getJSON(true); // true = associative array
|
||||||
|
|
||||||
|
// $amount = $data['amount'] ?? '0.00';
|
||||||
|
// $orderId = $data['order_id'] ?? 'UNKNOWN';
|
||||||
|
|
||||||
|
// // log_message('debug', " order_id: $orderId, amount: $amount");
|
||||||
|
|
||||||
|
// $result = $this->fiuu->createPayment($orderId, $amount);
|
||||||
|
// return $this->response->setJSON($result);
|
||||||
|
// }
|
||||||
|
public function createPayment()
|
||||||
|
{
|
||||||
|
$data = $this->request->getJSON(true);
|
||||||
|
$orderId = $data['order_id'] ?? 'UNKNOWN';
|
||||||
|
$amount = $data['amount'] ?? '0.00';
|
||||||
|
|
||||||
|
$customer = [
|
||||||
|
'name' => $data['bill_name'] ?? 'John Doe',
|
||||||
|
'email' => $data['bill_email'] ?? 'johndoe@example.com',
|
||||||
|
'mobile' => $data['bill_mobile'] ?? '601133094116',
|
||||||
|
'desc' => $data['bill_desc'] ?? 'Test payment',
|
||||||
|
'address' => $data['bill_address'] ?? '123 Jalan Teknologi',
|
||||||
|
'postcode' => $data['bill_postcode'] ?? '47000',
|
||||||
|
'city' => $data['bill_city'] ?? 'Petaling Jaya',
|
||||||
|
'state' => $data['bill_state'] ?? 'Selangor',
|
||||||
|
'country' => $data['bill_country'] ?? 'MY'
|
||||||
|
];
|
||||||
|
|
||||||
|
// Call the updated Fiuu library method
|
||||||
|
$result = $this->fiuu->createPayment($orderId, $amount, $customer);
|
||||||
|
|
||||||
|
return $this->response->setJSON($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function fiuuPaymentReturn()
|
||||||
|
{
|
||||||
|
$data = $this->request->getPost();
|
||||||
|
|
||||||
|
$this->fiuu->paymentNotification($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function fiuuPaymentNotification()
|
||||||
|
{
|
||||||
|
$data = $this->request->getPost();
|
||||||
|
|
||||||
|
$this->fiuu->paymentNotification($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function payAgain($order_id){
|
||||||
|
$order = $this->order->select('orders.*, customers.name, customers.email, customers.phone')
|
||||||
|
->join('customers', 'customers.id = orders.customer_id')
|
||||||
|
->where('orders.id', $order_id)
|
||||||
|
->where('orders.payment_status', 'unpaid')
|
||||||
|
->first();
|
||||||
|
if(!$order){
|
||||||
|
return $this->fail('Order not found', 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
$payment_details = [
|
||||||
|
'bill_name' => $order['name'],
|
||||||
|
'bill_email' => $order['email'],
|
||||||
|
'bill_mobile' => $order['phone'],
|
||||||
|
'bill_desc' => 'US Pizza - Payment for ' . ucfirst($order['order_type']) . ' - ' . $order['order_so'],
|
||||||
|
];
|
||||||
|
$respond_data = [];
|
||||||
|
$result = $this->fiuu->createPayment($order['order_so'], $order['grand_total'], $payment_details);
|
||||||
|
|
||||||
|
$respond_data['redirect_url'] = $result['redirect_url'];
|
||||||
|
$respond_data['status'] = 200;
|
||||||
|
$respond_data['message'] = 'Payment link generated successfully';
|
||||||
|
|
||||||
|
return $this->respond($respond_data);
|
||||||
|
}
|
||||||
|
}
|
||||||
48
app/Controllers/Frontend/SlideshowController.php
Normal file
48
app/Controllers/Frontend/SlideshowController.php
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controllers\Frontend;
|
||||||
|
|
||||||
|
use App\Controllers\BaseController;
|
||||||
|
use CodeIgniter\HTTP\ResponseInterface;
|
||||||
|
|
||||||
|
class SlideshowController extends BaseController
|
||||||
|
{
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
$slideshowModel = new \App\Models\SlideshowModel();
|
||||||
|
|
||||||
|
$allowedOrderFields = [
|
||||||
|
'order', 'created_at', 'updated_at', 'title', 'status'
|
||||||
|
];
|
||||||
|
|
||||||
|
$orderBy = $this->request->getGet('order_by') ?? 'order';
|
||||||
|
$sort = strtolower($this->request->getGet('sort')) === 'desc' ? 'DESC' : 'ASC';
|
||||||
|
$page = (int) ($this->request->getGet('page') ?? 1);
|
||||||
|
$limit = (int) ($this->request->getGet('limit') ?? 20);
|
||||||
|
|
||||||
|
if (!in_array($orderBy, $allowedOrderFields)) {
|
||||||
|
$orderBy = 'order';
|
||||||
|
}
|
||||||
|
|
||||||
|
$builder = $slideshowModel->orderBy($orderBy, $sort)->where('deleted_at', null);
|
||||||
|
|
||||||
|
if ($limit > 0) {
|
||||||
|
$offset = ($page - 1) * $limit;
|
||||||
|
$slides = $builder->findAll($limit, $offset);
|
||||||
|
$total = $slideshowModel->where('deleted_at', null)->countAllResults();
|
||||||
|
} else {
|
||||||
|
$slides = $builder->findAll();
|
||||||
|
$total = count($slides);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->response->setJSON([
|
||||||
|
'status' => 200,
|
||||||
|
'result' => $slides,
|
||||||
|
'pagination' => [
|
||||||
|
'page' => $page,
|
||||||
|
'limit' => $limit,
|
||||||
|
'total' => $total
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
345
app/Controllers/Frontend/TopupController.php
Normal file
345
app/Controllers/Frontend/TopupController.php
Normal file
@ -0,0 +1,345 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controllers\Frontend;
|
||||||
|
|
||||||
|
use App\Controllers\BaseController;
|
||||||
|
use App\Models\TopupModel;
|
||||||
|
use App\Libraries\Fiuu;
|
||||||
|
use CodeIgniter\API\ResponseTrait;
|
||||||
|
use App\Models\Customer;
|
||||||
|
use App\Models\CustomerWallet;
|
||||||
|
|
||||||
|
class TopupController extends BaseController
|
||||||
|
{
|
||||||
|
use ResponseTrait;
|
||||||
|
|
||||||
|
private $topups;
|
||||||
|
private $fiuu;
|
||||||
|
|
||||||
|
private $customer;
|
||||||
|
private $wallets;
|
||||||
|
private $db;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->topups = new TopupModel();
|
||||||
|
$this->fiuu = new Fiuu();
|
||||||
|
$this->customer = new Customer();
|
||||||
|
$this->wallets = new CustomerWallet();
|
||||||
|
$this->db = db_connect();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
$data = $this->topups
|
||||||
|
->orderBy('created_at', 'DESC')
|
||||||
|
->findAll();
|
||||||
|
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 200,
|
||||||
|
'data' => $data,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createPendingWalletRow(array $topupRow, array $customer): void
|
||||||
|
{
|
||||||
|
$current = (float)($customer['customer_wallet'] ?? 0);
|
||||||
|
|
||||||
|
$incoming = (float)($topupRow['credit'] ?? 0);
|
||||||
|
if ($incoming <= 0) {
|
||||||
|
$incoming = (float)($topupRow['other_amount'] ?? 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
$walletData = [
|
||||||
|
'customer_id' => $topupRow['customer_id'],
|
||||||
|
'related_type' => 'topup',
|
||||||
|
'related_id' => $topupRow['id'],
|
||||||
|
'action' => 'in',
|
||||||
|
'current' => $current,
|
||||||
|
'in' => $incoming,
|
||||||
|
'out' => 0,
|
||||||
|
'balance' => $current,
|
||||||
|
'remark' => 'Topup '.$topupRow['topup_number'].' (pending)',
|
||||||
|
'status' => 'Pending',
|
||||||
|
'created_at' => date('Y-m-d H:i:s'),
|
||||||
|
];
|
||||||
|
|
||||||
|
try {
|
||||||
|
$this->wallets->insert($walletData, true);
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function createTopupPayment()
|
||||||
|
{
|
||||||
|
$data = $this->request->getJSON(true);
|
||||||
|
|
||||||
|
$rules = [
|
||||||
|
'customer_id' => 'required|integer',
|
||||||
|
'payment_method' => 'required|string|max_length[50]',
|
||||||
|
'topup_setting_id' => 'permit_empty|integer',
|
||||||
|
'amount' => 'permit_empty|decimal',
|
||||||
|
'credit' => 'permit_empty|decimal',
|
||||||
|
'other_amount' => 'permit_empty|decimal'
|
||||||
|
];
|
||||||
|
if (!$this->validate($rules)) {
|
||||||
|
return $this->failValidationErrors($this->validator->getErrors());
|
||||||
|
}
|
||||||
|
|
||||||
|
$topupSettingId = !empty($data['topup_setting_id']) ? (int)$data['topup_setting_id'] : null;
|
||||||
|
|
||||||
|
if ($topupSettingId) {
|
||||||
|
// MODE 1: package top-up
|
||||||
|
$pkg = model('App\Models\TopupSettingModel')
|
||||||
|
->where('id', $topupSettingId)
|
||||||
|
->where('deleted_at', null)
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if (!$pkg || ($pkg['status'] ?? '') !== 'active') {
|
||||||
|
return $this->failValidationErrors(['topup_setting_id' => 'Selected package is invalid or inactive']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$amount = (float)$pkg['topup_amount'];
|
||||||
|
$credit = (float)$pkg['credit_amount'];
|
||||||
|
if ($amount <= 0 || $credit <= 0) {
|
||||||
|
return $this->failValidationErrors(['topup_setting' => 'Package amounts must be > 0']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$otherAmount = null;
|
||||||
|
} else {
|
||||||
|
$otherAmount = isset($data['other_amount']) && $data['other_amount'] !== '' ? (float)$data['other_amount'] : 0.0;
|
||||||
|
if ($otherAmount <= 0) {
|
||||||
|
return $this->failValidationErrors(['other_amount' => 'Provide a positive amount for custom top-up']);
|
||||||
|
}
|
||||||
|
$amount = 0.0;
|
||||||
|
$credit = 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
$topupNumber = 'T' . strtoupper(bin2hex(random_bytes(6)));
|
||||||
|
|
||||||
|
$insertData = [
|
||||||
|
'topup_setting_id' => $topupSettingId,
|
||||||
|
'customer_id' => (int)$data['customer_id'],
|
||||||
|
'topup_number' => $topupNumber,
|
||||||
|
'amount' => $amount, // package cash (0 for custom)
|
||||||
|
'credit' => $credit, // package credit (0 for custom)
|
||||||
|
'payment_method' => $data['payment_method'],
|
||||||
|
'other_amount' => $otherAmount, // used for custom
|
||||||
|
'status' => 'Pending',
|
||||||
|
];
|
||||||
|
|
||||||
|
$id = $this->topups->insert($insertData, true);
|
||||||
|
if (!$id) return $this->fail('Topup failed', 400);
|
||||||
|
|
||||||
|
$topup = $this->topups->find($id);
|
||||||
|
$customer = $this->customer->find((int)$data['customer_id']) ?? [];
|
||||||
|
|
||||||
|
// Write PENDING wallet ledger (no balance change yet)
|
||||||
|
$this->createPendingWalletRow($topup, $customer);
|
||||||
|
|
||||||
|
// Payment link uses the payable amount:
|
||||||
|
// - package mode → $amount
|
||||||
|
// - custom mode → $otherAmount
|
||||||
|
$payable = $topupSettingId ? $amount : $otherAmount;
|
||||||
|
|
||||||
|
$payment_details = [
|
||||||
|
'bill_name' => $customer['name'] ?? '',
|
||||||
|
'bill_email' => $customer['email'] ?? '',
|
||||||
|
'bill_mobile' => $customer['phone'] ?? '',
|
||||||
|
'bill_desc' => 'US Pizza - Wallet Topup - ' . $topupNumber,
|
||||||
|
];
|
||||||
|
|
||||||
|
$result = $this->fiuu->createTopup($topupNumber, $payable, $payment_details);
|
||||||
|
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 201,
|
||||||
|
'message' => 'Topup created successfully',
|
||||||
|
'data' => $this->topups->find($id),
|
||||||
|
'redirect_url' => $result['redirect_url'] ?? null
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public function fiuuTopupNotification()
|
||||||
|
{
|
||||||
|
$payload = $this->request->getPost();
|
||||||
|
// $payload = $this->request->getJSON(true);
|
||||||
|
// print_r($payload);exit;
|
||||||
|
$result = $this->fiuu->topupNotification($payload);
|
||||||
|
|
||||||
|
log_message('error', 'Fiuu Payload: '.json_encode($payload));
|
||||||
|
log_message('error', 'Fiuu Result: '.json_encode($result));
|
||||||
|
|
||||||
|
$topupNumber = $payload['orderid'] ?? null;
|
||||||
|
if (!$topupNumber) {
|
||||||
|
return $this->respond(['status' => 400, 'message' => 'Missing orderid'], 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
$topup = $this->topups->where('topup_number', $topupNumber)->first();
|
||||||
|
if (!$topup) {
|
||||||
|
return $this->respond(['status' => 404, 'message' => 'Topup not found'], 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (in_array($topup['status'], ['completed','failed'], true)) {
|
||||||
|
return $this->respond(['status' => 200, 'message' => 'Already processed', 'result' => $result]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$payStat = strtolower((string)($payload['status'] ?? ''));
|
||||||
|
$resStat = is_array($result) ? strtolower((string)($result['status'] ?? '')) : strtolower((string)$result);
|
||||||
|
|
||||||
|
|
||||||
|
$isSuccess = in_array($payStat, ['00','success','approved'], true)
|
||||||
|
|| (is_string($resStat) && strpos($resStat, 'success') !== false);
|
||||||
|
|
||||||
|
$this->db->transStart();
|
||||||
|
|
||||||
|
if ($isSuccess) {
|
||||||
|
$table = $this->customer->builder()->getTable();
|
||||||
|
$customer = $this->db->query(
|
||||||
|
'SELECT * FROM `'.$table.'` WHERE `id` = ? FOR UPDATE',
|
||||||
|
[$topup['customer_id']]
|
||||||
|
)->getRowArray();
|
||||||
|
if (!$customer) {
|
||||||
|
$this->db->transRollback();
|
||||||
|
return $this->respond(['status' => 404, 'message' => 'Customer not found'], 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
$current = (float)($customer['customer_wallet'] ?? 0);
|
||||||
|
|
||||||
|
|
||||||
|
$delta = $topup['amount'] + $topup['credit'];
|
||||||
|
// print_r($delta);exit;
|
||||||
|
if ($delta <= 0) $delta = (float)$topup['other_amount'];
|
||||||
|
|
||||||
|
if ($delta <= 0) {
|
||||||
|
$this->topups->update($topup['id'], ['status' => 'failed']);
|
||||||
|
$this->db->transComplete();
|
||||||
|
return $this->respond(['status' => 400, 'message' => 'Invalid topup amount'], 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
$newBal = $current + $delta;
|
||||||
|
$walletRow = $this->wallets
|
||||||
|
->where('related_type', 'topup')
|
||||||
|
->where('related_id', $topup['id'])
|
||||||
|
->orderBy('id', 'desc')
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if ($walletRow) {
|
||||||
|
$this->wallets->update($walletRow['id'], [
|
||||||
|
'status' => 'completed',
|
||||||
|
'current' => $current,
|
||||||
|
'balance' => $newBal,
|
||||||
|
'remark' => 'Topup '.$topupNumber.' (completed)',
|
||||||
|
'in' => $delta,
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
$this->wallets->insert([
|
||||||
|
'customer_id' => $topup['customer_id'],
|
||||||
|
'related_type' => 'topup',
|
||||||
|
'related_id' => $topup['id'],
|
||||||
|
'action' => 'in',
|
||||||
|
'current' => $current,
|
||||||
|
'in' => $delta,
|
||||||
|
'out' => 0,
|
||||||
|
'balance' => $newBal,
|
||||||
|
'remark' => 'Topup '.$topupNumber.' (completed)',
|
||||||
|
'status' => 'completed',
|
||||||
|
'created_at' => date('Y-m-d H:i:s'),
|
||||||
|
], true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$this->customer->update($customer['id'], ['customer_wallet' => $newBal]);
|
||||||
|
$this->topups->update($topup['id'], ['status' => 'Success']);
|
||||||
|
} else {
|
||||||
|
|
||||||
|
$this->topups->update($topup['id'], ['status' => 'Failed']);
|
||||||
|
$this->wallets
|
||||||
|
->where('related_type', 'topup')
|
||||||
|
->where('related_id', $topup['id'])
|
||||||
|
->set([
|
||||||
|
'status' => 'failed',
|
||||||
|
'remark' => 'Topup '.$topupNumber.' (failed)'
|
||||||
|
])->update();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->db->transComplete();
|
||||||
|
|
||||||
|
if ($this->db->transStatus() === false) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Transaction error'], 500);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->respond(['status' => 200, 'message' => 'Notification processed', 'result' => $result]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public function fiuuTopupReturn()
|
||||||
|
{
|
||||||
|
$data = $this->request->getPost();
|
||||||
|
|
||||||
|
$this->fiuu->topupNotification($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function checkTopupPayment($topup_id = null)
|
||||||
|
{
|
||||||
|
// echo(123123);exit;
|
||||||
|
$topup = $this->topups->find($topup_id);
|
||||||
|
if (!$topup) {
|
||||||
|
return $this->fail('Topup not found', 400);
|
||||||
|
}
|
||||||
|
// print_r($topup);exit;
|
||||||
|
$status = strtolower($topup['status'] ?? '');
|
||||||
|
// print_r($status);exit;
|
||||||
|
if ($status === 'success') {
|
||||||
|
return $this->respond(['status' => 200, 'result' => 'Success', 'topup_id' => $topup_id]);
|
||||||
|
} elseif ($status === 'pending') {
|
||||||
|
return $this->respond(['status' => 200, 'result' => 'Pending', 'topup_id' => $topup_id]);
|
||||||
|
}
|
||||||
|
return $this->respond(['status' => 400, 'result' => 'Failed', 'topup_id' => $topup_id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function show($id = null)
|
||||||
|
{
|
||||||
|
$id = (int) $id;
|
||||||
|
|
||||||
|
$row = $this->topups
|
||||||
|
->select('topup.*, topup_setting.id AS setting_id, topup_setting.topup_amount, topup_setting.credit_amount, topup_setting.status AS setting_status')
|
||||||
|
->join('topup_setting', 'topup_setting.id = topup.topup_setting_id', 'left')
|
||||||
|
->where('topup.id', $id)
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if (!$row) {
|
||||||
|
return $this->failNotFound('Topup record not found');
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'id' => $row['id'],
|
||||||
|
'topup_setting_id' => $row['topup_setting_id'],
|
||||||
|
'customer_id' => $row['customer_id'],
|
||||||
|
'topup_number' => $row['topup_number'],
|
||||||
|
'amount' => $row['amount'],
|
||||||
|
'credit' => $row['credit'],
|
||||||
|
'payment_method' => $row['payment_method'],
|
||||||
|
'other_amount' => $row['other_amount'],
|
||||||
|
'status' => $row['status'],
|
||||||
|
'created_at' => $row['created_at'],
|
||||||
|
'updated_at' => $row['updated_at'],
|
||||||
|
'topup_setting' => [
|
||||||
|
'id' => $row['setting_id'],
|
||||||
|
'topup_amount' => $row['topup_amount'],
|
||||||
|
'credit_amount' => $row['credit_amount'],
|
||||||
|
'status' => $row['setting_status']
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 200,
|
||||||
|
'data' => $data
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
33
app/Controllers/Frontend/TopupSettingController.php
Normal file
33
app/Controllers/Frontend/TopupSettingController.php
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controllers\Frontend;
|
||||||
|
|
||||||
|
use App\Controllers\BaseController;
|
||||||
|
use CodeIgniter\HTTP\ResponseInterface;
|
||||||
|
use CodeIgniter\API\ResponseTrait;
|
||||||
|
use App\Models\TopupSettingModel;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class TopupSettingController extends BaseController
|
||||||
|
{
|
||||||
|
use ResponseTrait;
|
||||||
|
private $settings;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->settings = new TopupSettingModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
$data = $this->settings
|
||||||
|
->orderBy('topup_amount', 'ASC')
|
||||||
|
->findAll();
|
||||||
|
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 200,
|
||||||
|
'data' => $data,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
508
app/Controllers/Frontend/VoucherController.php
Normal file
508
app/Controllers/Frontend/VoucherController.php
Normal file
@ -0,0 +1,508 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controllers\Frontend;
|
||||||
|
|
||||||
|
use App\Controllers\BaseController;
|
||||||
|
use CodeIgniter\API\ResponseTrait;
|
||||||
|
use CodeIgniter\HTTP\ResponseInterface;
|
||||||
|
use App\Models\Customer;
|
||||||
|
use App\Models\CustomerVoucherList;
|
||||||
|
use App\Models\PromoCode;
|
||||||
|
use App\Models\PromoSetting;
|
||||||
|
use App\Models\Carts;
|
||||||
|
use App\Models\VoucherPoints;
|
||||||
|
use App\Models\MenuItems;
|
||||||
|
use App\Models\MenuItemCategories;
|
||||||
|
use App\Models\CustomerPoint;
|
||||||
|
|
||||||
|
|
||||||
|
class VoucherController extends BaseController
|
||||||
|
{
|
||||||
|
use ResponseTrait;
|
||||||
|
private $customers;
|
||||||
|
private $customer_voucher_list;
|
||||||
|
|
||||||
|
private $customer_points;
|
||||||
|
private $promo_codes;
|
||||||
|
private $promo_settings;
|
||||||
|
private $carts;
|
||||||
|
private $calculate_service;
|
||||||
|
private $promo_service;
|
||||||
|
private $voucher_service;
|
||||||
|
private $menuItem;
|
||||||
|
private $menuItemCategories;
|
||||||
|
private $voucher_points;
|
||||||
|
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->customers = new Customer();
|
||||||
|
$this->voucher_points = new VoucherPoints();
|
||||||
|
$this->customer_voucher_list = new CustomerVoucherList();
|
||||||
|
$this->promo_codes = new PromoCode();
|
||||||
|
$this->promo_settings = new PromoSetting();
|
||||||
|
$this->carts = new Carts();
|
||||||
|
$this->calculate_service = service('calculateService');
|
||||||
|
$this->promo_service = service('promoService');
|
||||||
|
$this->voucher_service = service('voucherService');
|
||||||
|
$this->menuItem = new MenuItems();
|
||||||
|
$this->menuItemCategories = new MenuItemCategories();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function claim()
|
||||||
|
{
|
||||||
|
// echo(123);exit;
|
||||||
|
$body = $this->request->getJSON(true) ?? $this->request->getPost();
|
||||||
|
|
||||||
|
$customerId = (int) ($body['customer_id'] ?? 0);
|
||||||
|
$voucherId = (int) ($body['voucher_id'] ?? 0);
|
||||||
|
|
||||||
|
if ($customerId <= 0 || $voucherId <= 0) {
|
||||||
|
return $this->respond(['status' => 400, 'message' => 'Missing customer_id or voucher_id'], 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
$voucherModel = $this->voucher_points;
|
||||||
|
$custPtsModel = new CustomerPoint();
|
||||||
|
$custVoucherMod = new CustomerVoucherList();
|
||||||
|
|
||||||
|
$voucher = $voucherModel
|
||||||
|
->where('id', $voucherId)
|
||||||
|
->where('voucher_status', 'active')
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if (!$voucher) {
|
||||||
|
return $this->respond(['status' => 404, 'message' => 'Voucher not found or inactive'], 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($voucher['voucher_total_count']) && !empty($voucher['voucher_redeem_count'])) {
|
||||||
|
if ((int)$voucher['voucher_redeem_count'] >= (int)$voucher['voucher_total_count']) {
|
||||||
|
return $this->respond(['status' => 400, 'message' => 'Voucher is out of stock'], 400);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($voucher['voucher_count_customer'])) {
|
||||||
|
$taken = $custVoucherMod->where([
|
||||||
|
'customer_id' => $customerId,
|
||||||
|
'promo_setting_id' => $voucher['promo_setting_id'] ?? null,
|
||||||
|
])->where('voucher_status !=', 'trash')->countAllResults();
|
||||||
|
|
||||||
|
if ($taken >= (int)$voucher['voucher_count_customer']) {
|
||||||
|
return $this->respond(['status' => 400, 'message' => 'You have reached the redeem limit for this voucher'], 400);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$today = date('Y-m-d');
|
||||||
|
if (!empty($voucher['voucher_expired_date']) && $today > $voucher['voucher_expired_date']) {
|
||||||
|
return $this->respond(['status' => 400, 'message' => 'Voucher already expired'], 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
$lastLedger = $custPtsModel->where('customer_id', $customerId)
|
||||||
|
->orderBy('id', 'DESC')->first();
|
||||||
|
|
||||||
|
$currentBalance = $lastLedger ? (float)$lastLedger['balance'] : 0.0;
|
||||||
|
$costPoints = (float) ($voucher['voucher_point_redeem'] ?? 0);
|
||||||
|
|
||||||
|
if ($costPoints <= 0) {
|
||||||
|
return $this->respond(['status' => 400, 'message' => 'Voucher point cost is invalid'], 400);
|
||||||
|
}
|
||||||
|
if ($currentBalance < $costPoints) {
|
||||||
|
return $this->respond(['status' => 400, 'message' => 'Insufficient points'], 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
$custVoucherExpiry = null;
|
||||||
|
$type = strtolower(trim($voucher['voucher_expiry_type'] ?? ''));
|
||||||
|
$value = trim($voucher['voucher_expiry_value'] ?? '');
|
||||||
|
|
||||||
|
if ($type === 'date' && !empty($voucher['voucher_expired_date'])) {
|
||||||
|
$custVoucherExpiry = $voucher['voucher_expired_date'];
|
||||||
|
} elseif ($type === 'fixed' || $type === 'days') {
|
||||||
|
$days = (int)$value;
|
||||||
|
$custVoucherExpiry = date('Y-m-d', strtotime("+{$days} days"));
|
||||||
|
} else {
|
||||||
|
$custVoucherExpiry = !empty($voucher['voucher_expired_date']) ? $voucher['voucher_expired_date'] : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$already = $custVoucherMod->where([
|
||||||
|
'customer_id' => $customerId,
|
||||||
|
'promo_setting_id' => $voucher['promo_setting_id'] ?? null,
|
||||||
|
'voucher_status' => 'active',
|
||||||
|
])->first();
|
||||||
|
|
||||||
|
if ($already) {
|
||||||
|
return $this->respond(['status' => 200, 'message' => 'Voucher already redeemed for this customer', 'data' => $already]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$db = \Config\Database::connect();
|
||||||
|
$db->transStart();
|
||||||
|
|
||||||
|
$voucherCode = strtoupper('V' . $voucherId . '-' . bin2hex(random_bytes(3)));
|
||||||
|
$custVoucherId = $custVoucherMod->insert([
|
||||||
|
'promo_setting_id' => $voucher['promo_setting_id'] ?? null,
|
||||||
|
'customer_id' => $customerId,
|
||||||
|
'voucher_order_id' => 0,
|
||||||
|
'voucher_topup_id' => 0,
|
||||||
|
'voucher_code' => $voucherCode,
|
||||||
|
'voucher_expiry_date'=> $custVoucherExpiry,
|
||||||
|
'voucher_status' => 'active',
|
||||||
|
], true);
|
||||||
|
|
||||||
|
$newBalance = $currentBalance - $costPoints;
|
||||||
|
$ledgerId = $custPtsModel->insert([
|
||||||
|
'customer_id' => $customerId,
|
||||||
|
'related_id' => $voucherId,
|
||||||
|
'related_type'=> 'voucher',
|
||||||
|
'action' => 'redeem_voucher',
|
||||||
|
'current' => $currentBalance,
|
||||||
|
'in' => 0,
|
||||||
|
'out' => $costPoints,
|
||||||
|
'balance' => $newBalance,
|
||||||
|
'remark' => sprintf('Redeemed voucher "%s" (ID %d, code %s)', $voucher['voucher_name'] ?? '', $voucherId, $voucherCode),
|
||||||
|
], true);
|
||||||
|
$this->customers->update($customerId, [
|
||||||
|
'customer_point' => $newBalance
|
||||||
|
]);
|
||||||
|
|
||||||
|
$voucherModel->where('id', $voucherId)->set('voucher_redeem_count', 'voucher_redeem_count + 1', false)->update();
|
||||||
|
|
||||||
|
$db->transComplete();
|
||||||
|
|
||||||
|
if ($db->transStatus() === false) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Failed to redeem voucher'], 500);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 200,
|
||||||
|
'message' => 'Voucher redeemed successfully',
|
||||||
|
'data' => [
|
||||||
|
'customer_voucher_id' => $custVoucherId,
|
||||||
|
'ledger_id' => $ledgerId,
|
||||||
|
'voucher_code' => $voucherCode,
|
||||||
|
'new_balance' => $newBalance,
|
||||||
|
'voucher_expiry_date' => $custVoucherExpiry,
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
|
||||||
|
// echo(123123);exit;
|
||||||
|
log_message('info', 'Voucher index accessed');
|
||||||
|
|
||||||
|
$voucherName = $this->request->getGet('voucher_name');
|
||||||
|
$dateFrom = $this->request->getGet('date_from');
|
||||||
|
$dateTo = $this->request->getGet('date_to');
|
||||||
|
|
||||||
|
$builder = $this->voucher_points->builder();
|
||||||
|
|
||||||
|
$builder->where('voucher_status !=', 'trash');
|
||||||
|
|
||||||
|
if ($voucherName) {
|
||||||
|
$builder->like('voucher_name', $voucherName);
|
||||||
|
}
|
||||||
|
if ($dateFrom && $dateTo) {
|
||||||
|
$builder->where('voucher_expired_date >=', $dateFrom);
|
||||||
|
$builder->where('voucher_expired_date <=', $dateTo);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ✅ Print the generated SQL
|
||||||
|
// echo $builder->getCompiledSelect();
|
||||||
|
// exit;
|
||||||
|
|
||||||
|
// All transactions
|
||||||
|
$voucherSettings = $builder->get()->getResult();
|
||||||
|
|
||||||
|
if (empty($voucherSettings)) {
|
||||||
|
return $this->respond(["status" => 400, "message" => "No Voucher Found", "data" => []]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->respond(["status" => 200, "message" => "Successfully retrive data!", "data" => $voucherSettings]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function show($id = null)
|
||||||
|
{
|
||||||
|
$voucherSettings = $this->voucher_points->find($id);
|
||||||
|
|
||||||
|
if (empty($voucherSettings)) {
|
||||||
|
return $this->fail("No voucher settings found.", 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
$voucherSettingData = [];
|
||||||
|
|
||||||
|
if ($voucherSettings) {
|
||||||
|
$voucherSettingData[] = [
|
||||||
|
'id' => $voucherSettings['id'],
|
||||||
|
'voucher_name' => $voucherSettings['voucher_name'],
|
||||||
|
'voucher_total_count' => $voucherSettings['voucher_total_count'],
|
||||||
|
'voucher_redeem_count' => $voucherSettings['voucher_redeem_count'],
|
||||||
|
'voucher_count_customer' => $voucherSettings['voucher_count_customer'],
|
||||||
|
'voucher_expiry_type' => $voucherSettings['voucher_expiry_type'],
|
||||||
|
'voucher_expiry_value' => $voucherSettings['voucher_expiry_value'],
|
||||||
|
'voucher_expired_date' => $voucherSettings['voucher_expired_date'],
|
||||||
|
'voucher_point_redeem' => $voucherSettings['voucher_point_redeem'],
|
||||||
|
'promo_setting_id'=> $voucherSettings['promo_setting_id'],
|
||||||
|
'voucher_details'=> $voucherSettings['voucher_details'],
|
||||||
|
'voucher_tnc'=> $voucherSettings['voucher_tnc'],
|
||||||
|
'voucher_status'=> $voucherSettings['voucher_status'],
|
||||||
|
'voucher_image_url'=> getImagePath('vouchers', $voucherSettings['voucher_image']),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
return $this->respond(["status" => 200, "message" => "Successfully retrive data!", "data" => $voucherSettingData]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function voucherList($customer_id)
|
||||||
|
{
|
||||||
|
if(empty($customer_id)) {
|
||||||
|
return $this->respond(['status' => 400, 'result' => 'Customer ID is empty.']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$customer = $this->customers->find($customer_id);
|
||||||
|
|
||||||
|
if(empty($customer)) {
|
||||||
|
return $this->respond(['status' => 400, 'result' => 'Customer data not found.']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$customer_voucher_list = $this->customer_voucher_list
|
||||||
|
->select('customer_voucher_list.*, promo_settings.description')
|
||||||
|
->join('promo_settings', 'promo_settings.id = customer_voucher_list.promo_setting_id')
|
||||||
|
->where('customer_voucher_list.customer_id', $customer_id)
|
||||||
|
->findAll();
|
||||||
|
|
||||||
|
return $this->respond(['status' => 200, 'message' =>'Customer voucher list retrieved sucessfully!', 'data' => $customer_voucher_list]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function redeemVoucher($customer_id)
|
||||||
|
{
|
||||||
|
if(empty($customer_id)) {
|
||||||
|
return $this->respond(['status' => 400, 'result' => 'Customer ID is empty.']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$customer = $this->customers->find($customer_id);
|
||||||
|
|
||||||
|
if(empty($customer)) {
|
||||||
|
return $this->respond(['status' => 400, 'result' => 'Customer data not found.']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$validation = $this->validate([
|
||||||
|
'order_type' => 'required',
|
||||||
|
'promo_code' => 'permit_empty',
|
||||||
|
'voucher_id' => 'permit_empty',
|
||||||
|
'cart_id' => 'required',
|
||||||
|
'outlet_id' => 'required',
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (!$validation) {
|
||||||
|
return $this->failValidationErrors($this->validator->getErrors());
|
||||||
|
}
|
||||||
|
|
||||||
|
$promo_code = $this->request->getVar('promo_code');
|
||||||
|
$voucher_id = $this->request->getVar('voucher_id');
|
||||||
|
$cart_id = $this->request->getVar('cart_id');
|
||||||
|
$outlet_id = $this->request->getVar('outlet_id');
|
||||||
|
$order_type = $this->request->getVar('order_type');
|
||||||
|
|
||||||
|
|
||||||
|
if(empty($promo_code) && empty($voucher_id)) {
|
||||||
|
return $this->respond(['status' => 400, 'result' => 'Voucher code or voucher id is empty.']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$getCart = $this->carts->where('customer_id', $customer_id)->where('outlet_id', $outlet_id)->where('status', 'active')->find($cart_id);
|
||||||
|
|
||||||
|
if(empty($getCart)) {
|
||||||
|
return $this->respond(['status' => 400, 'result' => 'Unable to find your cart.']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if($getCart['promo_code_id'] > 0 || $getCart['customer_voucher_list_id'] > 0) {
|
||||||
|
$getCart['promo_code_id'] = 0;
|
||||||
|
$getCart['customer_voucher_list_id'] = 0;
|
||||||
|
$this->carts->update($cart_id, $getCart);
|
||||||
|
}
|
||||||
|
$free_items = [];
|
||||||
|
if(!empty($promo_code)) {
|
||||||
|
// promo code
|
||||||
|
$promo = $this->promo_codes->select('promo_codes.*, promo_settings.promo_setting')
|
||||||
|
->where('promo_codes.code', $promo_code)
|
||||||
|
->join('promo_settings', 'promo_settings.id = promo_codes.promo_setting_id')
|
||||||
|
->orderBy('promo_codes.id', 'DESC')->first();
|
||||||
|
|
||||||
|
if(empty($promo)) {
|
||||||
|
return $this->respond(['status' => 400, 'result' => 'Code not found.']);
|
||||||
|
}
|
||||||
|
$promoSettingData = json_decode($promo['promo_setting'], true);
|
||||||
|
$promo_setting = $promoSettingData['Promo'];
|
||||||
|
// print_r($promo);exit;
|
||||||
|
//check promo availability
|
||||||
|
$check_promo = $this->promo_service->checkPromoAvailability($promo['id'], $order_type, $customer_id);
|
||||||
|
|
||||||
|
//promo unavailable
|
||||||
|
if(isset($check_promo['status']) && $check_promo['status'] == 400) {
|
||||||
|
return $this->respond($check_promo);
|
||||||
|
}
|
||||||
|
|
||||||
|
if($promo_setting['promo_type'] == 'free_item'){
|
||||||
|
$free_items = [];
|
||||||
|
$isIncluded = true;
|
||||||
|
|
||||||
|
if($promo_setting['filter_type'] == 'item'){
|
||||||
|
foreach($promo_setting['free_item'] as $free_item_id){
|
||||||
|
$menu_item = $this->menuItem
|
||||||
|
->select('menu_items.id, menu_items.title, menu_images.image_url, menu_images.image_url_compressed')
|
||||||
|
->join('menu_images', 'menu_images.menu_item_id = menu_items.id', 'left')
|
||||||
|
->where('menu_items.status', 'active')
|
||||||
|
->find($free_item_id);
|
||||||
|
if($menu_item){
|
||||||
|
$free_items[] = [
|
||||||
|
'id' => $menu_item['id'],
|
||||||
|
'title' => $menu_item['title'],
|
||||||
|
'image_url' => getMenuImage($menu_item['id']),
|
||||||
|
// 'image_url_compressed' => getMenuImage($menu_item['id'])
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if($promo_setting['filter_type'] == 'category'){
|
||||||
|
foreach($promo_setting['free_item'] as $free_item_id){
|
||||||
|
$menu_items = $this->menuItemCategories
|
||||||
|
->select('menu_items.id, menu_items.title, menu_item_categories.category_id')
|
||||||
|
->join('menu_items', 'menu_items.id = menu_item_categories.menu_item_id')
|
||||||
|
->where('menu_item_categories.category_id', $free_item_id)
|
||||||
|
->where('menu_items.status', 'active')
|
||||||
|
->findAll();
|
||||||
|
|
||||||
|
if($menu_items){
|
||||||
|
foreach($menu_items as $item){
|
||||||
|
$menu_item = $this->menuItem
|
||||||
|
->select('menu_items.id, menu_items.title, menu_images.image_url, menu_images.image_url_compressed')
|
||||||
|
->join('menu_images', 'menu_images.menu_item_id = menu_items.id', 'left')
|
||||||
|
->where('menu_items.status', 'active')
|
||||||
|
->find($item['id']);
|
||||||
|
|
||||||
|
if($menu_item){
|
||||||
|
$free_items[$item['category_id']][] = [
|
||||||
|
'id' => $menu_item['id'],
|
||||||
|
'category_id' => $item['category_id'],
|
||||||
|
'title' => $menu_item['title'],
|
||||||
|
'image_url' => getMenuImage($menu_item['id']),
|
||||||
|
// 'image_url_compressed' => getMenuImage($menu_item['id'])
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$afterPromo['free_item_list'] = $free_items;
|
||||||
|
}
|
||||||
|
|
||||||
|
//promo available
|
||||||
|
$this->carts->update($cart_id, ['promo_code_id' => $promo['id'], 'customer_voucher_list_id' => 0]);
|
||||||
|
|
||||||
|
// $applyPromoCode = $this->calculate_service->calculateCartTotals($cart_id, $outlet_id, null, null, null, null, null, null, 'promo');
|
||||||
|
|
||||||
|
|
||||||
|
} else if(!empty($voucher_id)){
|
||||||
|
// use voucher
|
||||||
|
// please add in voucher_expiry_date
|
||||||
|
$customer_voucher = $this->customer_voucher_list
|
||||||
|
->select('customer_voucher_list.*, promo_settings.promo_setting')
|
||||||
|
->join('promo_settings', 'promo_settings.id = customer_voucher_list.promo_setting_id')
|
||||||
|
->where('customer_voucher_list.id', $voucher_id)
|
||||||
|
->first();
|
||||||
|
if(empty($customer_voucher)){
|
||||||
|
return $this->respond(['status' => 400, 'result' => 'Voucher not found.']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$promoSettingData = json_decode($customer_voucher['promo_setting'], true);
|
||||||
|
$promo_setting = $promoSettingData['Promo'];
|
||||||
|
// print_r($promo);exit;
|
||||||
|
//check voucher availability
|
||||||
|
$check_voucher = $this->voucher_service->checkVoucherAvailability($customer_voucher['id'], $order_type, $customer_id);
|
||||||
|
|
||||||
|
//voucher unavailable
|
||||||
|
if(isset($check_voucher['status']) && $check_voucher['status'] == 400) {
|
||||||
|
return $this->respond($check_voucher);
|
||||||
|
}
|
||||||
|
$free_items = [];
|
||||||
|
|
||||||
|
if($promo_setting['promo_type'] == 'free_item'){
|
||||||
|
$isIncluded = true;
|
||||||
|
if($promo_setting['filter_type'] == 'item'){
|
||||||
|
foreach($promo_setting['free_item'] as $free_item_id){
|
||||||
|
$menu_item = $this->menuItem
|
||||||
|
->select('menu_items.id, menu_items.title, menu_images.image_url, menu_images.image_url_compressed')
|
||||||
|
->join('menu_images', 'menu_images.menu_item_id = menu_items.id', 'left')
|
||||||
|
->where('menu_items.status', 'active')
|
||||||
|
->find($free_item_id);
|
||||||
|
if($menu_item){
|
||||||
|
$free_items[] = [
|
||||||
|
'id' => $menu_item['id'],
|
||||||
|
'title' => $menu_item['title'],
|
||||||
|
'image_url' => getMenuImage($menu_item['id']),
|
||||||
|
// 'image_url_compressed' => getMenuImage($menu_item['id'])
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if($promo_setting['filter_type'] == 'category'){
|
||||||
|
foreach($promo_setting['free_item'] as $free_item_id){
|
||||||
|
$menu_items = $this->menuItemCategories
|
||||||
|
->select('menu_items.id, menu_items.title, menu_item_categories.category_id')
|
||||||
|
->join('menu_items', 'menu_items.id = menu_item_categories.menu_item_id')
|
||||||
|
->where('menu_item_categories.category_id', $free_item_id)
|
||||||
|
->where('menu_items.status', 'active')
|
||||||
|
->findAll();
|
||||||
|
|
||||||
|
if($menu_items){
|
||||||
|
foreach($menu_items as $item){
|
||||||
|
$menu_item = $this->menuItem
|
||||||
|
->select('menu_items.id, menu_items.title, menu_images.image_url, menu_images.image_url_compressed')
|
||||||
|
->join('menu_images', 'menu_images.menu_item_id = menu_items.id', 'left')
|
||||||
|
->where('menu_items.status', 'active')
|
||||||
|
->find($item['id']);
|
||||||
|
|
||||||
|
if($menu_item){
|
||||||
|
$free_items[$item['category_id']][] = [
|
||||||
|
'id' => $menu_item['id'],
|
||||||
|
'category_id' => $item['category_id'],
|
||||||
|
'title' => $menu_item['title'],
|
||||||
|
'image_url' => getMenuImage($menu_item['id']),
|
||||||
|
// 'image_url_compressed' => getMenuImage($menu_item['id'])
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//voucher available
|
||||||
|
$this->carts->update($cart_id, ['customer_voucher_list_id' => $customer_voucher['id'], 'promo_code_id' => 0]);
|
||||||
|
|
||||||
|
// $applyPromoCode = $this->calculate_service->calculateCartTotals($cart_id, $outlet_id, null, null, null, null, null, null, 'voucher');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->respond(['status' => 200, 'result' => 'Voucher applied successfully.', 'data' => $free_items]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function removeVoucher($customer_id)
|
||||||
|
{
|
||||||
|
$cart_id = $this->request->getVar('cart_id');
|
||||||
|
if(empty($cart_id)){
|
||||||
|
return $this->respond(['status' => 400, 'result' => 'Cart id is empty.']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$getCart = $this->carts->where('customer_id', $customer_id)->where('status', 'active')->find($cart_id);
|
||||||
|
|
||||||
|
if(empty($getCart)) {
|
||||||
|
return $this->respond(['status' => 400, 'result' => 'Unable to find your cart.']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->calculate_service->resetVoucher($cart_id);
|
||||||
|
return $this->respond(['status' => 200, 'result' => 'Voucher removed successfully.']);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
91
app/Controllers/InvoiceController.php
Normal file
91
app/Controllers/InvoiceController.php
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controllers;
|
||||||
|
|
||||||
|
use App\Models\BranchDetails;
|
||||||
|
use App\Models\CustomerDetails;
|
||||||
|
use App\Models\Invoice;
|
||||||
|
use App\Models\InvoiceItem;
|
||||||
|
use App\Models\InvoiceType;
|
||||||
|
use App\Models\PaymentMethod;
|
||||||
|
use CodeIgniter\Database\Config;
|
||||||
|
use CodeIgniter\RESTful\ResourceController;
|
||||||
|
|
||||||
|
class InvoiceController extends ResourceController
|
||||||
|
{
|
||||||
|
private $db;
|
||||||
|
private $invoice;
|
||||||
|
private $invoiceType;
|
||||||
|
private $invoiceItem;
|
||||||
|
private $customerDetails;
|
||||||
|
private $paymentMethod;
|
||||||
|
private $branchDetails;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->invoice = new Invoice();
|
||||||
|
$this->invoiceType = new InvoiceType();
|
||||||
|
$this->invoiceItem = new InvoiceItem();
|
||||||
|
$this->customerDetails = new CustomerDetails();
|
||||||
|
$this->paymentMethod = new PaymentMethod();
|
||||||
|
$this->branchDetails = new BranchDetails();
|
||||||
|
$this->db = Config::connect();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$data = $this->invoice->findAll();
|
||||||
|
if (!empty($data)) return $this->respond(['status' => 200, 'message' => 'OK', 'result' => $data], 200);
|
||||||
|
return $this->respond(['status' => 200, 'message' => 'No invoices found'], 200);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function show($id = null)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$item = $this->invoice->find($id);
|
||||||
|
if ($item) return $this->respond(['status' => 200, 'message' => 'OK', 'result' => $item], 200);
|
||||||
|
return $this->respond(['status' => 404, 'message' => 'Invoice not found'], 404);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$payload = $this->request->getJSON(true);
|
||||||
|
$id = $this->invoice->insert($payload);
|
||||||
|
if ($id) return $this->respond(['status' => 201, 'message' => 'Invoice created', 'result' => ['id' => $id]], 201);
|
||||||
|
return $this->respond(['status' => 400, 'message' => 'Failed to create Invoice'], 400);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update($id = null)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (!$this->invoice->find($id)) return $this->respond(['status' => 404, 'message' => 'Invoice not found'], 404);
|
||||||
|
$payload = $this->request->getJSON(true);
|
||||||
|
if ($this->invoice->update($id, $payload)) return $this->respond(['status' => 200, 'message' => 'Invoice updated'], 200);
|
||||||
|
return $this->respond(['status' => 400, 'message' => 'Failed to update Invoice'], 400);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete($id = null)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (!$this->invoice->find($id)) return $this->respond(['status' => 404, 'message' => 'Invoice not found'], 404);
|
||||||
|
if ($this->invoice->delete($id)) return $this->respond(['status' => 200, 'message' => 'Invoice deleted'], 200);
|
||||||
|
return $this->respond(['status' => 400, 'message' => 'Failed to delete Invoice'], 400);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
79
app/Controllers/InvoiceItemController.php
Normal file
79
app/Controllers/InvoiceItemController.php
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controllers;
|
||||||
|
|
||||||
|
use App\Models\InvoiceItem;
|
||||||
|
use App\Models\Product;
|
||||||
|
use CodeIgniter\Database\Config;
|
||||||
|
use CodeIgniter\RESTful\ResourceController;
|
||||||
|
|
||||||
|
class InvoiceItemController extends ResourceController
|
||||||
|
{
|
||||||
|
private $db;
|
||||||
|
private $invoiceItem;
|
||||||
|
private $product;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->invoiceItem = new InvoiceItem();
|
||||||
|
$this->product = new Product();
|
||||||
|
$this->db = Config::connect();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$data = $this->invoiceItem->findAll();
|
||||||
|
if (!empty($data)) return $this->respond(['status' => 200, 'message' => 'OK', 'result' => $data], 200);
|
||||||
|
return $this->respond(['status' => 200, 'message' => 'No invoice items found'], 200);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function show($id = null)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$item = $this->invoiceItem->find($id);
|
||||||
|
if ($item) return $this->respond(['status' => 200, 'message' => 'OK', 'result' => $item], 200);
|
||||||
|
return $this->respond(['status' => 404, 'message' => 'Invoice item not found'], 404);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$payload = $this->request->getJSON(true);
|
||||||
|
$id = $this->invoiceItem->insert($payload);
|
||||||
|
if ($id) return $this->respond(['status' => 201, 'message' => 'Invoice item created', 'result' => ['id' => $id]], 201);
|
||||||
|
return $this->respond(['status' => 400, 'message' => 'Failed to create invoice item'], 400);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update($id = null)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (!$this->invoiceItem->find($id)) return $this->respond(['status' => 404, 'message' => 'Invoice item not found'], 404);
|
||||||
|
$payload = $this->request->getJSON(true);
|
||||||
|
if ($this->invoiceItem->update($id, $payload)) return $this->respond(['status' => 200, 'message' => 'Invoice item updated'], 200);
|
||||||
|
return $this->respond(['status' => 400, 'message' => 'Failed to update invoice item'], 400);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete($id = null)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (!$this->invoiceItem->find($id)) return $this->respond(['status' => 404, 'message' => 'Invoice item not found'], 404);
|
||||||
|
if ($this->invoiceItem->delete($id)) return $this->respond(['status' => 200, 'message' => 'Invoice item deleted'], 200);
|
||||||
|
return $this->respond(['status' => 400, 'message' => 'Failed to delete invoice item'], 400);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
76
app/Controllers/InvoiceTypeController.php
Normal file
76
app/Controllers/InvoiceTypeController.php
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controllers;
|
||||||
|
|
||||||
|
use App\Models\InvoiceType;
|
||||||
|
use CodeIgniter\Database\Config;
|
||||||
|
use CodeIgniter\RESTful\ResourceController;
|
||||||
|
|
||||||
|
class InvoiceTypeController extends ResourceController
|
||||||
|
{
|
||||||
|
private $db;
|
||||||
|
private $invoiceType;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->invoiceType = new InvoiceType();
|
||||||
|
$this->db = Config::connect();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$data = $this->invoiceType->findAll();
|
||||||
|
if (!empty($data)) return $this->respond(['status' => 200, 'message' => 'OK', 'result' => $data], 200);
|
||||||
|
return $this->respond(['status' => 200, 'message' => 'No invoice types found'], 200);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function show($id = null)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$item = $this->invoiceType->find($id);
|
||||||
|
if ($item) return $this->respond(['status' => 200, 'message' => 'OK', 'result' => $item], 200);
|
||||||
|
return $this->respond(['status' => 404, 'message' => 'Invoice Type not found'], 404);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$payload = $this->request->getJSON(true);
|
||||||
|
$id = $this->invoiceType->insert($payload);
|
||||||
|
if ($id) return $this->respond(['status' => 201, 'message' => 'Invoice Type created', 'result' => ['id' => $id]], 201);
|
||||||
|
return $this->respond(['status' => 400, 'message' => 'Failed to create Invoice Type'], 400);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update($id = null)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (!$this->invoiceType->find($id)) return $this->respond(['status' => 404, 'message' => 'Invoice Type not found'], 404);
|
||||||
|
$payload = $this->request->getJSON(true);
|
||||||
|
if ($this->invoiceType->update($id, $payload)) return $this->respond(['status' => 200, 'message' => 'Invoice Type updated'], 200);
|
||||||
|
return $this->respond(['status' => 400, 'message' => 'Failed to update Invoice Type'], 400);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete($id = null)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (!$this->invoiceType->find($id)) return $this->respond(['status' => 404, 'message' => 'Invoice Type not found'], 404);
|
||||||
|
if ($this->invoiceType->delete($id)) return $this->respond(['status' => 200, 'message' => 'Invoice Type deleted'], 200);
|
||||||
|
return $this->respond(['status' => 400, 'message' => 'Failed to delete Invoice Type'], 400);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
78
app/Controllers/LetterheadController.php
Normal file
78
app/Controllers/LetterheadController.php
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controllers;
|
||||||
|
|
||||||
|
use App\Models\Letterhead;
|
||||||
|
use CodeIgniter\Database\Config;
|
||||||
|
use CodeIgniter\RESTful\ResourceController;
|
||||||
|
|
||||||
|
helper('image');
|
||||||
|
|
||||||
|
class LetterheadController extends ResourceController
|
||||||
|
{
|
||||||
|
private $db;
|
||||||
|
private $letterhead;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->letterhead = new Letterhead();
|
||||||
|
$this->db = Config::connect();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$data = $this->letterhead->findAll();
|
||||||
|
if (!empty($data)) return $this->respond(['status' => 200, 'message' => 'OK', 'result' => $data], 200);
|
||||||
|
return $this->respond(['status' => 200, 'message' => 'No letterheads found'], 200);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function show($id = null)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$item = $this->letterhead->find($id);
|
||||||
|
if ($item) return $this->respond(['status' => 200, 'message' => 'OK', 'result' => $item], 200);
|
||||||
|
return $this->respond(['status' => 404, 'message' => 'Letterhead not found'], 404);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$payload = $this->request->getJSON(true);
|
||||||
|
$id = $this->letterhead->insert($payload);
|
||||||
|
if ($id) return $this->respond(['status' => 201, 'message' => 'Letterhead created', 'result' => ['id' => $id]], 201);
|
||||||
|
return $this->respond(['status' => 400, 'message' => 'Failed to create Letterhead'], 400);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update($id = null)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (!$this->letterhead->find($id)) return $this->respond(['status' => 404, 'message' => 'Letterhead not found'], 404);
|
||||||
|
$payload = $this->request->getJSON(true);
|
||||||
|
if ($this->letterhead->update($id, $payload)) return $this->respond(['status' => 200, 'message' => 'Letterhead updated'], 200);
|
||||||
|
return $this->respond(['status' => 400, 'message' => 'Failed to update Letterhead'], 400);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete($id = null)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (!$this->letterhead->find($id)) return $this->respond(['status' => 404, 'message' => 'Letterhead not found'], 404);
|
||||||
|
if ($this->letterhead->delete($id)) return $this->respond(['status' => 200, 'message' => 'Letterhead deleted'], 200);
|
||||||
|
return $this->respond(['status' => 400, 'message' => 'Failed to delete Letterhead'], 400);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
76
app/Controllers/PaymentMethodController.php
Normal file
76
app/Controllers/PaymentMethodController.php
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controllers;
|
||||||
|
|
||||||
|
use App\Models\PaymentMethod;
|
||||||
|
use CodeIgniter\Database\Config;
|
||||||
|
use CodeIgniter\RESTful\ResourceController;
|
||||||
|
|
||||||
|
class PaymentMethodController extends ResourceController
|
||||||
|
{
|
||||||
|
private $db;
|
||||||
|
private $paymentMethod;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->paymentMethod = new PaymentMethod();
|
||||||
|
$this->db = Config::connect();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$data = $this->paymentMethod->findAll();
|
||||||
|
if (!empty($data)) return $this->respond(['status' => 200, 'message' => 'OK', 'result' => $data], 200);
|
||||||
|
return $this->respond(['status' => 200, 'message' => 'No payment methods found'], 200);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function show($id = null)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$item = $this->paymentMethod->find($id);
|
||||||
|
if ($item) return $this->respond(['status' => 200, 'message' => 'OK', 'result' => $item], 200);
|
||||||
|
return $this->respond(['status' => 404, 'message' => 'Payment Method not found'], 404);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$payload = $this->request->getJSON(true);
|
||||||
|
$id = $this->paymentMethod->insert($payload);
|
||||||
|
if ($id) return $this->respond(['status' => 201, 'message' => 'Payment Method created', 'result' => ['id' => $id]], 201);
|
||||||
|
return $this->respond(['status' => 400, 'message' => 'Failed to create Payment Method'], 400);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update($id = null)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (!$this->paymentMethod->find($id)) return $this->respond(['status' => 404, 'message' => 'Payment Method not found'], 404);
|
||||||
|
$payload = $this->request->getJSON(true);
|
||||||
|
if ($this->paymentMethod->update($id, $payload)) return $this->respond(['status' => 200, 'message' => 'Payment Method updated'], 200);
|
||||||
|
return $this->respond(['status' => 400, 'message' => 'Failed to update Payment Method'], 400);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete($id = null)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (!$this->paymentMethod->find($id)) return $this->respond(['status' => 404, 'message' => 'Payment Method not found'], 404);
|
||||||
|
if ($this->paymentMethod->delete($id)) return $this->respond(['status' => 200, 'message' => 'Payment Method deleted'], 200);
|
||||||
|
return $this->respond(['status' => 400, 'message' => 'Failed to delete Payment Method'], 400);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
76
app/Controllers/PlatformController.php
Normal file
76
app/Controllers/PlatformController.php
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controllers;
|
||||||
|
|
||||||
|
use App\Models\Platform;
|
||||||
|
use CodeIgniter\Database\Config;
|
||||||
|
use CodeIgniter\RESTful\ResourceController;
|
||||||
|
|
||||||
|
class PlatformController extends ResourceController
|
||||||
|
{
|
||||||
|
private $db;
|
||||||
|
private $platform;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->platform = new Platform();
|
||||||
|
$this->db = Config::connect();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$data = $this->platform->findAll();
|
||||||
|
if (!empty($data)) return $this->respond(['status' => 200, 'message' => 'OK', 'result' => $data], 200);
|
||||||
|
return $this->respond(['status' => 200, 'message' => 'No platforms found'], 200);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function show($id = null)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$item = $this->platform->find($id);
|
||||||
|
if ($item) return $this->respond(['status' => 200, 'message' => 'OK', 'result' => $item], 200);
|
||||||
|
return $this->respond(['status' => 404, 'message' => 'Platform not found'], 404);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$payload = $this->request->getJSON(true);
|
||||||
|
$id = $this->platform->insert($payload);
|
||||||
|
if ($id) return $this->respond(['status' => 201, 'message' => 'Platform created', 'result' => ['id' => $id]], 201);
|
||||||
|
return $this->respond(['status' => 400, 'message' => 'Failed to create Platform'], 400);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update($id = null)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (!$this->platform->find($id)) return $this->respond(['status' => 404, 'message' => 'Platform not found'], 404);
|
||||||
|
$payload = $this->request->getJSON(true);
|
||||||
|
if ($this->platform->update($id, $payload)) return $this->respond(['status' => 200, 'message' => 'Platform updated'], 200);
|
||||||
|
return $this->respond(['status' => 400, 'message' => 'Failed to update Platform'], 400);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete($id = null)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (!$this->platform->find($id)) return $this->respond(['status' => 404, 'message' => 'Platform not found'], 404);
|
||||||
|
if ($this->platform->delete($id)) return $this->respond(['status' => 200, 'message' => 'Platform deleted'], 200);
|
||||||
|
return $this->respond(['status' => 400, 'message' => 'Failed to delete Platform'], 400);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
76
app/Controllers/PositionController.php
Normal file
76
app/Controllers/PositionController.php
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controllers;
|
||||||
|
|
||||||
|
use App\Models\Position;
|
||||||
|
use CodeIgniter\Database\Config;
|
||||||
|
use CodeIgniter\RESTful\ResourceController;
|
||||||
|
|
||||||
|
class PositionController extends ResourceController
|
||||||
|
{
|
||||||
|
private $db;
|
||||||
|
private $position;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->position = new Position();
|
||||||
|
$this->db = Config::connect();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$data = $this->position->findAll();
|
||||||
|
if (!empty($data)) return $this->respond(['status' => 200, 'message' => 'OK', 'result' => $data], 200);
|
||||||
|
return $this->respond(['status' => 200, 'message' => 'No positions found'], 200);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function show($id = null)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$item = $this->position->find($id);
|
||||||
|
if ($item) return $this->respond(['status' => 200, 'message' => 'OK', 'result' => $item], 200);
|
||||||
|
return $this->respond(['status' => 404, 'message' => 'Position not found'], 404);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$payload = $this->request->getJSON(true);
|
||||||
|
$id = $this->position->insert($payload);
|
||||||
|
if ($id) return $this->respond(['status' => 201, 'message' => 'Position created', 'result' => ['id' => $id]], 201);
|
||||||
|
return $this->respond(['status' => 400, 'message' => 'Failed to create Position'], 400);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update($id = null)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (!$this->position->find($id)) return $this->respond(['status' => 404, 'message' => 'Position not found'], 404);
|
||||||
|
$payload = $this->request->getJSON(true);
|
||||||
|
if ($this->position->update($id, $payload)) return $this->respond(['status' => 200, 'message' => 'Position updated'], 200);
|
||||||
|
return $this->respond(['status' => 400, 'message' => 'Failed to update Position'], 400);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete($id = null)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (!$this->position->find($id)) return $this->respond(['status' => 404, 'message' => 'Position not found'], 404);
|
||||||
|
if ($this->position->delete($id)) return $this->respond(['status' => 200, 'message' => 'Position deleted'], 200);
|
||||||
|
return $this->respond(['status' => 400, 'message' => 'Failed to delete Position'], 400);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
94
app/Controllers/ProductBrandController.php
Normal file
94
app/Controllers/ProductBrandController.php
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controllers;
|
||||||
|
|
||||||
|
use App\Models\ProductBrand;
|
||||||
|
use CodeIgniter\Database\Config;
|
||||||
|
use CodeIgniter\RESTful\ResourceController;
|
||||||
|
|
||||||
|
class ProductBrandController extends ResourceController
|
||||||
|
{
|
||||||
|
private $db;
|
||||||
|
private $productBrand;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->productBrand = new ProductBrand();
|
||||||
|
$this->db = Config::connect();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected $format = 'json';
|
||||||
|
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$data = $this->productBrand->findAll();
|
||||||
|
if (!empty($data)) {
|
||||||
|
return $this->respond(['status' => 200, 'message' => 'OK', 'result' => $data], 200);
|
||||||
|
}
|
||||||
|
return $this->respond(['status' => 200, 'message' => 'No product brands found'], 200);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function show($id = null)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$item = $this->productBrand->find($id);
|
||||||
|
if ($item) {
|
||||||
|
return $this->respond(['status' => 200, 'message' => 'OK', 'result' => $item], 200);
|
||||||
|
}
|
||||||
|
return $this->respond(['status' => 404, 'message' => 'Product Brand not found'], 404);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$payload = $this->request->getJSON(true);
|
||||||
|
$insertId = $this->productBrand->insert($payload);
|
||||||
|
if ($insertId) {
|
||||||
|
return $this->respond(['status' => 201, 'message' => 'Product Brand created', 'result' => ['id' => $insertId]], 201);
|
||||||
|
}
|
||||||
|
return $this->respond(['status' => 400, 'message' => 'Failed to create Product Brand'], 400);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update($id = null)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (!$this->productBrand->find($id)) {
|
||||||
|
return $this->respond(['status' => 404, 'message' => 'Product Brand not found'], 404);
|
||||||
|
}
|
||||||
|
$payload = $this->request->getJSON(true);
|
||||||
|
$ok = $this->productBrand->update($id, $payload);
|
||||||
|
if ($ok) {
|
||||||
|
return $this->respond(['status' => 200, 'message' => 'Product Brand updated'], 200);
|
||||||
|
}
|
||||||
|
return $this->respond(['status' => 400, 'message' => 'Failed to update Product Brand'], 400);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete($id = null)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (!$this->productBrand->find($id)) {
|
||||||
|
return $this->respond(['status' => 404, 'message' => 'Product Brand not found'], 404);
|
||||||
|
}
|
||||||
|
$ok = $this->productBrand->delete($id);
|
||||||
|
if ($ok) {
|
||||||
|
return $this->respond(['status' => 200, 'message' => 'Product Brand deleted'], 200);
|
||||||
|
}
|
||||||
|
return $this->respond(['status' => 400, 'message' => 'Failed to delete Product Brand'], 400);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
76
app/Controllers/ProductCategoryController.php
Normal file
76
app/Controllers/ProductCategoryController.php
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controllers;
|
||||||
|
|
||||||
|
use App\Models\ProductCategory;
|
||||||
|
use CodeIgniter\Database\Config;
|
||||||
|
use CodeIgniter\RESTful\ResourceController;
|
||||||
|
|
||||||
|
class ProductCategoryController extends ResourceController
|
||||||
|
{
|
||||||
|
private $db;
|
||||||
|
private $productCategory;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->productCategory = new ProductCategory();
|
||||||
|
$this->db = Config::connect();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$data = $this->productCategory->findAll();
|
||||||
|
if (!empty($data)) return $this->respond(['status' => 200, 'message' => 'OK', 'result' => $data], 200);
|
||||||
|
return $this->respond(['status' => 200, 'message' => 'No product categories found'], 200);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function show($id = null)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$item = $this->productCategory->find($id);
|
||||||
|
if ($item) return $this->respond(['status' => 200, 'message' => 'OK', 'result' => $item], 200);
|
||||||
|
return $this->respond(['status' => 404, 'message' => 'Product Category not found'], 404);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$payload = $this->request->getJSON(true);
|
||||||
|
$id = $this->productCategory->insert($payload);
|
||||||
|
if ($id) return $this->respond(['status' => 201, 'message' => 'Product Category created', 'result' => ['id' => $id]], 201);
|
||||||
|
return $this->respond(['status' => 400, 'message' => 'Failed to create Product Category'], 400);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update($id = null)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (!$this->productCategory->find($id)) return $this->respond(['status' => 404, 'message' => 'Product Category not found'], 404);
|
||||||
|
$payload = $this->request->getJSON(true);
|
||||||
|
if ($this->productCategory->update($id, $payload)) return $this->respond(['status' => 200, 'message' => 'Product Category updated'], 200);
|
||||||
|
return $this->respond(['status' => 400, 'message' => 'Failed to update Product Category'], 400);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete($id = null)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (!$this->productCategory->find($id)) return $this->respond(['status' => 404, 'message' => 'Product Category not found'], 404);
|
||||||
|
if ($this->productCategory->delete($id)) return $this->respond(['status' => 200, 'message' => 'Product Category deleted'], 200);
|
||||||
|
return $this->respond(['status' => 400, 'message' => 'Failed to delete Product Category'], 400);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
91
app/Controllers/ProductController.php
Normal file
91
app/Controllers/ProductController.php
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controllers;
|
||||||
|
|
||||||
|
use App\Models\Product;
|
||||||
|
use App\Models\ProductBrand;
|
||||||
|
use App\Models\ProductCategory;
|
||||||
|
use App\Models\ProductDescription;
|
||||||
|
use App\Models\ProductImei;
|
||||||
|
use App\Models\SupplierDetails;
|
||||||
|
use CodeIgniter\Database\Config;
|
||||||
|
use CodeIgniter\RESTful\ResourceController;
|
||||||
|
|
||||||
|
class ProductController extends ResourceController
|
||||||
|
{
|
||||||
|
private $db;
|
||||||
|
private $product;
|
||||||
|
private $productBrand;
|
||||||
|
private $productCategory;
|
||||||
|
private $productDescription;
|
||||||
|
private $productImei;
|
||||||
|
private $supplierDetails;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->product = new Product();
|
||||||
|
$this->productBrand = new ProductBrand();
|
||||||
|
$this->productCategory = new ProductCategory();
|
||||||
|
$this->productDescription = new ProductDescription();
|
||||||
|
$this->productImei = new ProductImei();
|
||||||
|
$this->supplierDetails = new SupplierDetails();
|
||||||
|
$this->db = Config::connect();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$data = $this->product->findAll();
|
||||||
|
if (!empty($data)) return $this->respond(['status' => 200, 'message' => 'OK', 'result' => $data], 200);
|
||||||
|
return $this->respond(['status' => 200, 'message' => 'No products found'], 200);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function show($id = null)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$item = $this->product->find($id);
|
||||||
|
if ($item) return $this->respond(['status' => 200, 'message' => 'OK', 'result' => $item], 200);
|
||||||
|
return $this->respond(['status' => 404, 'message' => 'Product not found'], 404);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$payload = $this->request->getJSON(true);
|
||||||
|
$id = $this->product->insert($payload);
|
||||||
|
if ($id) return $this->respond(['status' => 201, 'message' => 'Product created', 'result' => ['id' => $id]], 201);
|
||||||
|
return $this->respond(['status' => 400, 'message' => 'Failed to create Product'], 400);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update($id = null)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (!$this->product->find($id)) return $this->respond(['status' => 404, 'message' => 'Product not found'], 404);
|
||||||
|
$payload = $this->request->getJSON(true);
|
||||||
|
if ($this->product->update($id, $payload)) return $this->respond(['status' => 200, 'message' => 'Product updated'], 200);
|
||||||
|
return $this->respond(['status' => 400, 'message' => 'Failed to update Product'], 400);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete($id = null)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (!$this->product->find($id)) return $this->respond(['status' => 404, 'message' => 'Product not found'], 404);
|
||||||
|
if ($this->product->delete($id)) return $this->respond(['status' => 200, 'message' => 'Product deleted'], 200);
|
||||||
|
return $this->respond(['status' => 400, 'message' => 'Failed to delete Product'], 400);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
76
app/Controllers/ProductDescriptionController.php
Normal file
76
app/Controllers/ProductDescriptionController.php
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controllers;
|
||||||
|
|
||||||
|
use CodeIgniter\Database\Config;
|
||||||
|
use App\Models\ProductDescription;
|
||||||
|
use CodeIgniter\RESTful\ResourceController;
|
||||||
|
|
||||||
|
class ProductDescriptionController extends ResourceController
|
||||||
|
{
|
||||||
|
private $db;
|
||||||
|
private $productDescription;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->productDescription = new ProductDescription();
|
||||||
|
$this->db = Config::connect();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$data = $this->productDescription->findAll();
|
||||||
|
if (!empty($data)) return $this->respond(['status' => 200, 'message' => 'OK', 'result' => $data], 200);
|
||||||
|
return $this->respond(['status' => 200, 'message' => 'No product descriptions found'], 200);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function show($id = null)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$item = $this->productDescription->find($id);
|
||||||
|
if ($item) return $this->respond(['status' => 200, 'message' => 'OK', 'result' => $item], 200);
|
||||||
|
return $this->respond(['status' => 404, 'message' => 'Product Description not found'], 404);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$payload = $this->request->getJSON(true);
|
||||||
|
$id = $this->productDescription->insert($payload);
|
||||||
|
if ($id) return $this->respond(['status' => 201, 'message' => 'Product Description created', 'result' => ['id' => $id]], 201);
|
||||||
|
return $this->respond(['status' => 400, 'message' => 'Failed to create Product Description'], 400);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update($id = null)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (!$this->productDescription->find($id)) return $this->respond(['status' => 404, 'message' => 'Product Description not found'], 404);
|
||||||
|
$payload = $this->request->getJSON(true);
|
||||||
|
if ($this->productDescription->update($id, $payload)) return $this->respond(['status' => 200, 'message' => 'Product Description updated'], 200);
|
||||||
|
return $this->respond(['status' => 400, 'message' => 'Failed to update Product Description'], 400);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete($id = null)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (!$this->productDescription->find($id)) return $this->respond(['status' => 404, 'message' => 'Product Description not found'], 404);
|
||||||
|
if ($this->productDescription->delete($id)) return $this->respond(['status' => 200, 'message' => 'Product Description deleted'], 200);
|
||||||
|
return $this->respond(['status' => 400, 'message' => 'Failed to delete Product Description'], 400);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
76
app/Controllers/ProductImeiController.php
Normal file
76
app/Controllers/ProductImeiController.php
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controllers;
|
||||||
|
|
||||||
|
use App\Models\ProductImei;
|
||||||
|
use CodeIgniter\Database\Config;
|
||||||
|
use CodeIgniter\RESTful\ResourceController;
|
||||||
|
|
||||||
|
class ProductImeiController extends ResourceController
|
||||||
|
{
|
||||||
|
private $db;
|
||||||
|
private $productImei;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->productImei = new ProductImei();
|
||||||
|
$this->db = Config::connect();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$data = $this->productImei->findAll();
|
||||||
|
if (!empty($data)) return $this->respond(['status' => 200, 'message' => 'OK', 'result' => $data], 200);
|
||||||
|
return $this->respond(['status' => 200, 'message' => 'No IMEI records found'], 200);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function show($id = null)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$item = $this->productImei->find($id);
|
||||||
|
if ($item) return $this->respond(['status' => 200, 'message' => 'OK', 'result' => $item], 200);
|
||||||
|
return $this->respond(['status' => 404, 'message' => 'IMEI not found'], 404);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$payload = $this->request->getJSON(true);
|
||||||
|
$id = $this->productImei->insert($payload);
|
||||||
|
if ($id) return $this->respond(['status' => 201, 'message' => 'IMEI created', 'result' => ['id' => $id]], 201);
|
||||||
|
return $this->respond(['status' => 400, 'message' => 'Failed to create IMEI'], 400);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update($id = null)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (!$this->productImei->find($id)) return $this->respond(['status' => 404, 'message' => 'IMEI not found'], 404);
|
||||||
|
$payload = $this->request->getJSON(true);
|
||||||
|
if ($this->productImei->update($id, $payload)) return $this->respond(['status' => 200, 'message' => 'IMEI updated'], 200);
|
||||||
|
return $this->respond(['status' => 400, 'message' => 'Failed to update IMEI'], 400);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete($id = null)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (!$this->productImei->find($id)) return $this->respond(['status' => 404, 'message' => 'IMEI not found'], 404);
|
||||||
|
if ($this->productImei->delete($id)) return $this->respond(['status' => 200, 'message' => 'IMEI deleted'], 200);
|
||||||
|
return $this->respond(['status' => 400, 'message' => 'Failed to delete IMEI'], 400);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
120
app/Controllers/StaffDetailsController.php
Normal file
120
app/Controllers/StaffDetailsController.php
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controllers;
|
||||||
|
|
||||||
|
use App\Models\BranchDetails;
|
||||||
|
use App\Models\StaffDetails;
|
||||||
|
use CodeIgniter\Database\Config;
|
||||||
|
use CodeIgniter\RESTful\ResourceController;
|
||||||
|
|
||||||
|
class StaffDetailsController extends ResourceController
|
||||||
|
{
|
||||||
|
private $db;
|
||||||
|
private $staffDetails;
|
||||||
|
private $position;
|
||||||
|
private $branchDetails;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->staffDetails = new StaffDetails();
|
||||||
|
$this->branchDetails = new BranchDetails();
|
||||||
|
$this->db = Config::connect();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$data = $this->staffDetails->findAll();
|
||||||
|
if (!empty($data)) return $this->respond(['status' => 200, 'message' => 'OK', 'result' => $data], 200);
|
||||||
|
return $this->respond(['status' => 200, 'message' => 'No staff records found'], 200);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function show($id = null)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$item = $this->staffDetails->find($id);
|
||||||
|
if ($item) return $this->respond(['status' => 200, 'message' => 'OK', 'result' => $item], 200);
|
||||||
|
return $this->respond(['status' => 404, 'message' => 'Staff not found'], 404);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create()
|
||||||
|
{
|
||||||
|
$validationRules = [
|
||||||
|
'employee_name' => 'required',
|
||||||
|
'email' => 'required',
|
||||||
|
'phone_no' => 'required',
|
||||||
|
'position_id' => 'required',
|
||||||
|
'username' => 'required',
|
||||||
|
'password' => 'required',
|
||||||
|
'branch_id' => 'required',
|
||||||
|
];
|
||||||
|
|
||||||
|
if (!$this->validate($validationRules)) {
|
||||||
|
$response = [
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'Validation failed.',
|
||||||
|
'data' => $this->validator->getErrors()
|
||||||
|
];
|
||||||
|
return $this->respond($response, 422);
|
||||||
|
}
|
||||||
|
|
||||||
|
$userData = [
|
||||||
|
'employee_name' => $this->request->getVar('employee_name'),
|
||||||
|
'email' => $this->request->getVar('email'),
|
||||||
|
'phone_no' => $this->request->getVar('phone_no'),
|
||||||
|
'position_id' => $this->request->getVar('position_id'),
|
||||||
|
'username' => $this->request->getVar('username'),
|
||||||
|
'password' => md5($this->request->getVar('password')),
|
||||||
|
'branch_id' => $this->request->getVar('branch_id'),
|
||||||
|
];
|
||||||
|
|
||||||
|
$id = $this->staffDetails->insert($userData);
|
||||||
|
|
||||||
|
if ($id) {
|
||||||
|
$result = $this->staffDetails->find($id);
|
||||||
|
|
||||||
|
$response = [
|
||||||
|
'status' => 'success',
|
||||||
|
'message' => 'Staff created successfully.',
|
||||||
|
'data' => $result
|
||||||
|
];
|
||||||
|
return $this->respond($response, 201);
|
||||||
|
}
|
||||||
|
|
||||||
|
$response = [
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'Failed to create Staff.',
|
||||||
|
'data' => null
|
||||||
|
];
|
||||||
|
return $this->respond($response, 500);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update($id = null)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (!$this->staffDetails->find($id)) return $this->respond(['status' => 404, 'message' => 'Staff not found'], 404);
|
||||||
|
$payload = $this->request->getJSON(true);
|
||||||
|
if ($this->staffDetails->update($id, $payload)) return $this->respond(['status' => 200, 'message' => 'Staff updated'], 200);
|
||||||
|
return $this->respond(['status' => 400, 'message' => 'Failed to update Staff'], 400);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete($id = null)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (!$this->staffDetails->find($id)) return $this->respond(['status' => 404, 'message' => 'Staff not found'], 404);
|
||||||
|
if ($this->staffDetails->delete($id)) return $this->respond(['status' => 200, 'message' => 'Staff deleted'], 200);
|
||||||
|
return $this->respond(['status' => 400, 'message' => 'Failed to delete Staff'], 400);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
76
app/Controllers/StockController.php
Normal file
76
app/Controllers/StockController.php
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controllers;
|
||||||
|
|
||||||
|
use App\Models\Stock;
|
||||||
|
use CodeIgniter\Database\Config;
|
||||||
|
use CodeIgniter\RESTful\ResourceController;
|
||||||
|
|
||||||
|
class StockController extends ResourceController
|
||||||
|
{
|
||||||
|
private $db;
|
||||||
|
private $stock;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->stock = new Stock();
|
||||||
|
$this->db = Config::connect();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$data = $this->stock->findAll();
|
||||||
|
if (!empty($data)) return $this->respond(['status' => 200, 'message' => 'OK', 'result' => $data], 200);
|
||||||
|
return $this->respond(['status' => 200, 'message' => 'No stock records found'], 200);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function show($id = null)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$item = $this->stock->find($id);
|
||||||
|
if ($item) return $this->respond(['status' => 200, 'message' => 'OK', 'result' => $item], 200);
|
||||||
|
return $this->respond(['status' => 404, 'message' => 'Stock not found'], 404);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$payload = $this->request->getJSON(true);
|
||||||
|
$id = $this->stock->insert($payload);
|
||||||
|
if ($id) return $this->respond(['status' => 201, 'message' => 'Stock created', 'result' => ['id' => $id]], 201);
|
||||||
|
return $this->respond(['status' => 400, 'message' => 'Failed to create Stock'], 400);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update($id = null)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (!$this->stock->find($id)) return $this->respond(['status' => 404, 'message' => 'Stock not found'], 404);
|
||||||
|
$payload = $this->request->getJSON(true);
|
||||||
|
if ($this->stock->update($id, $payload)) return $this->respond(['status' => 200, 'message' => 'Stock updated'], 200);
|
||||||
|
return $this->respond(['status' => 400, 'message' => 'Failed to update Stock'], 400);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete($id = null)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (!$this->stock->find($id)) return $this->respond(['status' => 404, 'message' => 'Stock not found'], 404);
|
||||||
|
if ($this->stock->delete($id)) return $this->respond(['status' => 200, 'message' => 'Stock deleted'], 200);
|
||||||
|
return $this->respond(['status' => 400, 'message' => 'Failed to delete Stock'], 400);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
76
app/Controllers/SupplierDetailsController.php
Normal file
76
app/Controllers/SupplierDetailsController.php
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controllers;
|
||||||
|
|
||||||
|
use App\Models\SupplierDetails;
|
||||||
|
use CodeIgniter\Database\Config;
|
||||||
|
use CodeIgniter\RESTful\ResourceController;
|
||||||
|
|
||||||
|
class SupplierDetailsController extends ResourceController
|
||||||
|
{
|
||||||
|
private $db;
|
||||||
|
private $supplierDetails;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->supplierDetails = new SupplierDetails();
|
||||||
|
$this->db = Config::connect();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$data = $this->supplierDetails->findAll();
|
||||||
|
if (!empty($data)) return $this->respond(['status' => 200, 'message' => 'OK', 'result' => $data], 200);
|
||||||
|
return $this->respond(['status' => 200, 'message' => 'No suppliers found'], 200);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function show($id = null)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$item = $this->supplierDetails->find($id);
|
||||||
|
if ($item) return $this->respond(['status' => 200, 'message' => 'OK', 'result' => $item], 200);
|
||||||
|
return $this->respond(['status' => 404, 'message' => 'Supplier not found'], 404);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$payload = $this->request->getJSON(true);
|
||||||
|
$id = $this->supplierDetails->insert($payload);
|
||||||
|
if ($id) return $this->respond(['status' => 201, 'message' => 'Supplier created', 'result' => ['id' => $id]], 201);
|
||||||
|
return $this->respond(['status' => 400, 'message' => 'Failed to create Supplier'], 400);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update($id = null)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (!$this->supplierDetails->find($id)) return $this->respond(['status' => 404, 'message' => 'Supplier not found'], 404);
|
||||||
|
$payload = $this->request->getJSON(true);
|
||||||
|
if ($this->supplierDetails->update($id, $payload)) return $this->respond(['status' => 200, 'message' => 'Supplier updated'], 200);
|
||||||
|
return $this->respond(['status' => 400, 'message' => 'Failed to update Supplier'], 400);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete($id = null)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (!$this->supplierDetails->find($id)) return $this->respond(['status' => 404, 'message' => 'Supplier not found'], 404);
|
||||||
|
if ($this->supplierDetails->delete($id)) return $this->respond(['status' => 200, 'message' => 'Supplier deleted'], 200);
|
||||||
|
return $this->respond(['status' => 400, 'message' => 'Failed to delete Supplier'], 400);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 500, 'message' => 'Server error'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user