commit 19082025
This commit is contained in:
commit
01f3843938
78
.env.example
Normal file
78
.env.example
Normal file
@ -0,0 +1,78 @@
|
||||
#--------------------------------------------------------------------
|
||||
# Example Environment Configuration file
|
||||
#
|
||||
# This file can be used as a starting point for your own
|
||||
# custom .env files, and contains most of the possible settings
|
||||
# available in a default install.
|
||||
#
|
||||
# By default, all of the settings are commented out. If you want
|
||||
# to override the setting, you must un-comment it by removing the '#'
|
||||
# at the beginning of the line.
|
||||
#--------------------------------------------------------------------
|
||||
SYSTEMPATH=''
|
||||
#--------------------------------------------------------------------
|
||||
# ENVIRONMENT
|
||||
#--------------------------------------------------------------------
|
||||
|
||||
CI_ENVIRONMENT = development
|
||||
# CI_ENVIRONMENT = production
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
# APP
|
||||
#--------------------------------------------------------------------
|
||||
|
||||
# app.baseURL = 'http://localhost:8080/'
|
||||
app.baseURL = 'https://motorbike.mg'
|
||||
# If you have trouble with `.`, you could also use `_`.
|
||||
# app_baseURL = ''
|
||||
# app.forceGlobalSecureRequests = false
|
||||
# app.CSPEnabled = false
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
# DATABASE
|
||||
#--------------------------------------------------------------------
|
||||
|
||||
database.default.hostname = localhost
|
||||
database.default.database = motorbike
|
||||
database.default.username = motorbike
|
||||
database.default.password = v81JPgB4pRrSelV
|
||||
database.default.DBDriver = MySQLi
|
||||
database.default.DBPrefix =
|
||||
database.default.port = 3306
|
||||
# database.default.hostname =localhost
|
||||
# database.default.database =motorbike
|
||||
# database.default.username =root
|
||||
# database.default.password =
|
||||
# database.default.DBDriver =MySQLi
|
||||
# database.default.DBPrefix =
|
||||
# database.default.port = 3306
|
||||
|
||||
# If you use MySQLi as tests, first update the values of Config\Database::$tests.
|
||||
# database.tests.hostname = localhost
|
||||
# database.tests.database = ci4_test
|
||||
# database.tests.username = root
|
||||
# database.tests.password = root
|
||||
# database.tests.DBDriver = MySQLi
|
||||
# database.tests.DBPrefix =
|
||||
# database.tests.charset = utf8mb4
|
||||
# database.tests.DBCollat = utf8mb4_general_ci
|
||||
# database.tests.port = 3306
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
# ENCRYPTION
|
||||
#--------------------------------------------------------------------
|
||||
|
||||
# encryption.key =
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
# SESSION
|
||||
#--------------------------------------------------------------------
|
||||
|
||||
# session.driver = 'CodeIgniter\Session\Handlers\FileHandler'
|
||||
# session.savePath = null
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
# LOGGER
|
||||
#--------------------------------------------------------------------
|
||||
|
||||
# logger.threshold = 4
|
||||
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
vendor
|
||||
.env
|
||||
composer.lock
|
||||
12
.vscode/sftp.json
vendored
Normal file
12
.vscode/sftp.json
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"name": "C4M STOCK",
|
||||
"host": "185.70.105.157",
|
||||
"protocol": "sftp",
|
||||
"port": 22,
|
||||
"username": "motorbike",
|
||||
"remotePath": "/home/motorbike/public_html/",
|
||||
"password": "IVrMDogT3XiBcrY",
|
||||
"uploadOnSave": false,
|
||||
"useTempFile": false,
|
||||
"openSsh": false
|
||||
}
|
||||
BIN
WhatsApp Image 2025-07-05 at 13.52.38.jpeg
Normal file
BIN
WhatsApp Image 2025-07-05 at 13.52.38.jpeg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 60 KiB |
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
|
||||
*/
|
||||
206
app/Config/App.php
Normal file
206
app/Config/App.php
Normal file
@ -0,0 +1,206 @@
|
||||
<?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 = 'http://localhost/motorbike';
|
||||
public string $baseURL = 'https://motorbike.mg/';
|
||||
|
||||
public $CI_ENVIRONMENT = 'development';
|
||||
|
||||
|
||||
/**
|
||||
* 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 = '';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* 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 = 'Indian/Antananarivo';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* 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;
|
||||
}
|
||||
99
app/Config/Autoload.php
Normal file
99
app/Config/Autoload.php
Normal file
@ -0,0 +1,99 @@
|
||||
<?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.
|
||||
*
|
||||
* @immutable
|
||||
*/
|
||||
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 '/app' and '/system' directories 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.
|
||||
*
|
||||
* Prototype:
|
||||
* $psr4 = [
|
||||
* 'CodeIgniter' => SYSTEMPATH,
|
||||
* 'App' => APPPATH
|
||||
* ];
|
||||
*
|
||||
* @var array<string, list<string>|string>
|
||||
*/
|
||||
public $psr4 = [
|
||||
APP_NAMESPACE => APPPATH, // For custom app namespace
|
||||
'Config' => APPPATH . 'Config',
|
||||
];
|
||||
|
||||
/**
|
||||
* -------------------------------------------------------------------
|
||||
* 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 = ['global_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);
|
||||
23
app/Config/Boot/production.php
Normal file
23
app/Config/Boot/production.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?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.
|
||||
*/
|
||||
ini_set('display_errors', '0');
|
||||
error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED);
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| 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;
|
||||
}
|
||||
171
app/Config/Cache.php
Normal file
171
app/Config/Cache.php
Normal file
@ -0,0 +1,171 @@
|
||||
<?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';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Cache Directory Path
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* The path to where cache files should be stored, if using a file-based
|
||||
* system.
|
||||
*
|
||||
* @deprecated Use the driver-specific variant under $file
|
||||
*/
|
||||
public string $storePath = WRITEPATH . 'cache/';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* 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,
|
||||
];
|
||||
}
|
||||
94
app/Config/Constants.php
Normal file
94
app/Config/Constants.php
Normal file
@ -0,0 +1,94 @@
|
||||
<?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
|
||||
|
||||
/**
|
||||
* @deprecated Use \CodeIgniter\Events\Events::PRIORITY_LOW instead.
|
||||
*/
|
||||
define('EVENT_PRIORITY_LOW', 200);
|
||||
|
||||
/**
|
||||
* @deprecated Use \CodeIgniter\Events\Events::PRIORITY_NORMAL instead.
|
||||
*/
|
||||
define('EVENT_PRIORITY_NORMAL', 100);
|
||||
|
||||
/**
|
||||
* @deprecated Use \CodeIgniter\Events\Events::PRIORITY_HIGH instead.
|
||||
*/
|
||||
define('EVENT_PRIORITY_HIGH', 10);
|
||||
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;
|
||||
}
|
||||
89
app/Config/Database.php
Normal file
89
app/Config/Database.php
Normal file
@ -0,0 +1,89 @@
|
||||
<?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' => 'root',
|
||||
'password' => '',
|
||||
'database' => 'stock',
|
||||
'DBDriver' => 'MySQLi',
|
||||
'DBPrefix' => '',
|
||||
'pConnect' => false,
|
||||
'DBDebug' => true,
|
||||
'charset' => 'utf8',
|
||||
'DBCollat' => 'utf8_general_ci',
|
||||
'swapPre' => '',
|
||||
'encrypt' => false,
|
||||
'compress' => false,
|
||||
'strictOn' => false,
|
||||
'failover' => [],
|
||||
'port' => 3306,
|
||||
'numberNative' => false,
|
||||
];
|
||||
|
||||
/**
|
||||
* 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' => 'utf8_general_ci',
|
||||
'swapPre' => '',
|
||||
'encrypt' => false,
|
||||
'compress' => false,
|
||||
'strictOn' => false,
|
||||
'failover' => [],
|
||||
'port' => 3306,
|
||||
'foreignKeys' => true,
|
||||
'busyTimeout' => 1000,
|
||||
];
|
||||
|
||||
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';
|
||||
}
|
||||
}
|
||||
}
|
||||
46
app/Config/DocTypes.php
Normal file
46
app/Config/DocTypes.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
/**
|
||||
* @immutable
|
||||
*/
|
||||
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;
|
||||
}
|
||||
53
app/Config/Email.php
Normal file
53
app/Config/Email.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
|
||||
class Email extends BaseConfig
|
||||
{
|
||||
public string $fromEmail = 'rey342505@gmail.com';
|
||||
public string $fromName = 'motorbike';
|
||||
public string $recipients = '';
|
||||
|
||||
public string $userAgent = 'CodeIgniter';
|
||||
|
||||
public string $protocol = 'smtp';
|
||||
|
||||
public string $mailPath = '/usr/sbin/sendmail';
|
||||
|
||||
public string $SMTPHost = 'smtp.gmail.com';
|
||||
|
||||
public string $SMTPUser = 'rey342505@gmail.com';
|
||||
|
||||
public string $SMTPPass = 'loirqovmfuxnasrm'; // Mot de passe d’application (App Password) Gmail
|
||||
|
||||
public int $SMTPPort = 587;
|
||||
|
||||
public int $SMTPTimeout = 30;
|
||||
|
||||
public bool $SMTPKeepAlive = false;
|
||||
|
||||
public string $SMTPCrypto = 'tls';
|
||||
|
||||
public bool $wordWrap = true;
|
||||
|
||||
public int $wrapChars = 76;
|
||||
|
||||
public string $mailType = 'html';
|
||||
|
||||
public string $charset = 'UTF-8';
|
||||
|
||||
public bool $validate = true;
|
||||
|
||||
public int $priority = 3;
|
||||
|
||||
public string $CRLF = "\r\n";
|
||||
|
||||
public string $newline = "\r\n";
|
||||
|
||||
public bool $BCCBatchMode = false;
|
||||
|
||||
public int $BCCBatchSize = 200;
|
||||
|
||||
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 () {
|
||||
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');
|
||||
Services::toolbar()->respond();
|
||||
// Hot Reload route - for framework use on the hot reloader.
|
||||
if (ENVIRONMENT === 'development') {
|
||||
Services::routes()->get('__hot-reload', static function () {
|
||||
(new HotReloader())->run();
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
108
app/Config/Exceptions.php
Normal file
108
app/Config/Exceptions.php
Normal file
@ -0,0 +1,108 @@
|
||||
<?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 = [];
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* LOG DEPRECATIONS INSTEAD OF THROWING?
|
||||
* --------------------------------------------------------------------------
|
||||
* By default, CodeIgniter converts deprecations into exceptions. Also,
|
||||
* starting in PHP 8.1 will cause a lot of deprecated usage warnings.
|
||||
* Use this option to temporarily cease the warnings and instead log those.
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
30
app/Config/Feature.php
Normal file
30
app/Config/Feature.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
|
||||
/**
|
||||
* Enable/disable backward compatibility breaking features.
|
||||
*/
|
||||
class Feature extends BaseConfig
|
||||
{
|
||||
/**
|
||||
* Enable multiple filters for a route or not.
|
||||
*
|
||||
* If you enable this:
|
||||
* - CodeIgniter\CodeIgniter::handleRequest() uses:
|
||||
* - CodeIgniter\Filters\Filters::enableFilters(), instead of enableFilter()
|
||||
* - CodeIgniter\CodeIgniter::tryToRouteIt() uses:
|
||||
* - CodeIgniter\Router\Router::getFilters(), instead of getFilter()
|
||||
* - CodeIgniter\Router\Router::handle() uses:
|
||||
* - property $filtersInfo, instead of $filterInfo
|
||||
* - CodeIgniter\Router\RouteCollection::getFiltersForRoute(), instead of getFilterForRoute()
|
||||
*/
|
||||
public bool $multipleFilters = false;
|
||||
|
||||
/**
|
||||
* Use improved new auto routing instead of the default legacy version.
|
||||
*/
|
||||
public bool $autoRoutesImproved = false;
|
||||
}
|
||||
75
app/Config/Filters.php
Normal file
75
app/Config/Filters.php
Normal file
@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
use CodeIgniter\Filters\CSRF;
|
||||
use CodeIgniter\Filters\DebugToolbar;
|
||||
use CodeIgniter\Filters\Honeypot;
|
||||
use CodeIgniter\Filters\InvalidChars;
|
||||
use CodeIgniter\Filters\SecureHeaders;
|
||||
use App\Filters\LoggedInFilter;
|
||||
|
||||
class Filters extends BaseConfig
|
||||
{
|
||||
/**
|
||||
* 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,
|
||||
'loggedIn' => LoggedInFilter::class, // Add this line
|
||||
'auth' => \App\Filters\AuthCheck::class,
|
||||
'intended' => \App\Filters\PublicCheck::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* 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' => [
|
||||
'auth' => ['except' => ['login', 'register', 'public/*']], // Apply the 'auth' filter globally, except specified routes
|
||||
],
|
||||
'after' => [
|
||||
'toolbar',
|
||||
// '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
|
||||
{
|
||||
}
|
||||
77
app/Config/Format.php
Normal file
77
app/Config/Format.php
Normal file
@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
use CodeIgniter\Format\FormatterInterface;
|
||||
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,
|
||||
];
|
||||
|
||||
/**
|
||||
* A Factory method to return the appropriate formatter for the given mime type.
|
||||
*
|
||||
* @return FormatterInterface
|
||||
*
|
||||
* @deprecated This is an alias of `\CodeIgniter\Format\Format::getFormatter`. Use that instead.
|
||||
*/
|
||||
public function getFormatter(string $mime)
|
||||
{
|
||||
return Services::format()->getFormatter($mime);
|
||||
}
|
||||
}
|
||||
42
app/Config/Generators.php
Normal file
42
app/Config/Generators.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?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, string>
|
||||
*/
|
||||
public array $views = [
|
||||
'make:cell' => 'CodeIgniter\Commands\Generators\Views\cell.tpl.php',
|
||||
'make:cell_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,
|
||||
];
|
||||
}
|
||||
68
app/Config/Kint.php
Normal file
68
app/Config/Kint.php
Normal file
@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
use Kint\Parser\ConstructablePluginInterface;
|
||||
//use Kint\Renderer\AbstractRenderer;
|
||||
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 extends BaseConfig
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| 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 $richSort = null;
|
||||
|
||||
public bool $richFolder = false;
|
||||
//public int $richSort = AbstractRenderer::SORT_FULL;
|
||||
|
||||
/**
|
||||
* @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_';
|
||||
}
|
||||
536
app/Config/Mimes.php
Normal file
536
app/Config/Mimes.php
Normal file
@ -0,0 +1,536 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
/**
|
||||
* Mimes
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* @immutable
|
||||
*/
|
||||
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',
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
84
app/Config/Modules.php
Normal file
84
app/Config/Modules.php
Normal file
@ -0,0 +1,84 @@
|
||||
<?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.
|
||||
*
|
||||
* @immutable
|
||||
*/
|
||||
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',
|
||||
];
|
||||
}
|
||||
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',
|
||||
];
|
||||
}
|
||||
294
app/Config/Routes.php
Normal file
294
app/Config/Routes.php
Normal file
@ -0,0 +1,294 @@
|
||||
<?php
|
||||
|
||||
use App\Controllers\Auth;
|
||||
use App\Controllers\Dashboard;
|
||||
use App\Controllers\UserController;
|
||||
use App\Controllers\BrandController;
|
||||
use App\Controllers\GroupController;
|
||||
use App\Controllers\OrderController;
|
||||
use App\Controllers\StoreController;
|
||||
use App\Controllers\QrCodeController;
|
||||
use App\Controllers\ReportController;
|
||||
use App\Controllers\AttribuController;
|
||||
use App\Controllers\AvanceController;
|
||||
use App\Controllers\CompanyController;
|
||||
use App\Controllers\ProductCOntroller;
|
||||
use App\Controllers\CategoryController;
|
||||
use App\Controllers\MecanicienController;
|
||||
use App\Controllers\NotificationController;
|
||||
use App\Controllers\StatistiqueController;
|
||||
use App\Controllers\RecouvrementController;
|
||||
use App\Controllers\ReservationController;
|
||||
use App\Controllers\SecuriteController;
|
||||
use App\Controllers\SortieCaisseController;
|
||||
use App\Controllers\RemiseController;
|
||||
use App\Controllers\PerformanceController;
|
||||
/**
|
||||
* auth route
|
||||
* the option array filter make a filter,
|
||||
* if the user are already loged in, redirect to dashboard
|
||||
*/
|
||||
$routes->get('/login', [Auth::class, 'login'], ['filter' => 'loggedIn']);
|
||||
$routes->post('/login', [Auth::class, 'loginPost'], ['filter' => 'loggedIn']);
|
||||
$routes->get('test-email', 'TestEmail::index');
|
||||
$routes->get('alerts/check', 'AlertsController::check');
|
||||
$routes->get('check-deadline', 'TestDeadline::index');
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* route to all the rest of web app
|
||||
* the filter do if user not connectet try to acces this route
|
||||
* redirect imediatly iny login
|
||||
*/
|
||||
$routes->group('', ['filter' => 'auth'], function ($routes) {
|
||||
|
||||
/**
|
||||
* dashboard route
|
||||
*/
|
||||
$routes->get('/', [Dashboard::class, 'index']);
|
||||
$routes->get('/ventes', [Auth::class, 'ventes']);
|
||||
$routes->get('/ventes/(:num)', [Auth::class, 'addImage']);
|
||||
$routes->get('/ventes/fetchProductVente/(:num)', [Auth::class, 'fetchProductVente']);
|
||||
$routes->get('/ventes/show/(:num)', [Auth::class, 'getSingle']);
|
||||
$routes->post('/ventes/moreimage/(:num)', [Auth::class, 'uploadImagePub']);
|
||||
$routes->post('/ventes/moreimage/supp/(:num)', [Auth::class, 'delete']);
|
||||
|
||||
/**
|
||||
* route to logout
|
||||
*/
|
||||
$routes->get('/logout', [Auth::class, 'logout']);
|
||||
// Route pour tester les alertes manuellement (à supprimer en production)
|
||||
$routes->get('test-deadline-alerts', 'AvanceController::checkDeadlineAlerts');
|
||||
|
||||
/**
|
||||
* route for the users
|
||||
*/
|
||||
$routes->group('/users', function ($routes) {
|
||||
$routes->get('/', [UserController::class, 'index']);
|
||||
$routes->get('create', [UserController::class, 'create']);
|
||||
$routes->post('create', [UserController::class, 'create']);
|
||||
$routes->get('edit/(:num)', [UserController::class, 'edit']);
|
||||
$routes->post('edit/(:num)', [UserController::class, 'edit']);
|
||||
$routes->get('delete/(:num)', [UserController::class, 'delete']);
|
||||
$routes->post('delete/(:num)', [UserController::class, 'delete']);
|
||||
$routes->get('profile', [UserController::class, 'profile']);
|
||||
$routes->get('fetchProfile/(:num)', [UserController::class, 'fetchProfile']);
|
||||
$routes->get('setting', [UserController::class, 'setting']);
|
||||
$routes->post('setting', [UserController::class, 'setting']);
|
||||
$routes->post('assign_store', [UserController::class, 'assign_store']);
|
||||
$routes->get('login/(:num)', [UserController::class, 'loginToOtherAccount']);
|
||||
$routes->get('fetchUserData', [UserController::class,'fetchUserData']);
|
||||
$routes->post('fetchUserForAssign', [UserController::class,'fetchUserForAssign']);
|
||||
});
|
||||
|
||||
/**
|
||||
* route for the groups
|
||||
*/
|
||||
$routes->group('/groups', function ($routes) {
|
||||
$routes->get('/', [GroupController::class, 'index']);
|
||||
$routes->get('create', [GroupController::class, 'create']);
|
||||
$routes->post('create', [GroupController::class, 'create']);
|
||||
$routes->get('edit/(:num)', [GroupController::class, 'edit']);
|
||||
$routes->post('edit/(:num)', [GroupController::class, 'edit']);
|
||||
$routes->get('delete/(:num)', [GroupController::class, 'delete']);
|
||||
$routes->post('delete/(:num)', [GroupController::class, 'delete']);
|
||||
});
|
||||
|
||||
/**
|
||||
* route for the brands
|
||||
*/
|
||||
$routes->group('/brands', function ($routes) {
|
||||
$routes->get('/', [BrandController::class, 'index']);
|
||||
$routes->get('fetchBrandData', [BrandController::class, 'fetchBrandData']);
|
||||
$routes->post('create', [BrandController::class, 'create']);
|
||||
$routes->post('fetchBrandDataById/(:num)', [BrandController::class, 'fetchBrandDataById']);
|
||||
$routes->post('update/(:num)', [BrandController::class, 'update']);
|
||||
$routes->post('remove', [BrandController::class, 'remove']);
|
||||
});
|
||||
|
||||
/**
|
||||
* route for the category
|
||||
*/
|
||||
$routes->group('/category', function ($routes) {
|
||||
$routes->get('/', [CategoryController::class, 'index']);
|
||||
$routes->get('fetchCategoryData', [CategoryController::class, 'fetchCategoryData']);
|
||||
$routes->post('create', [CategoryController::class, 'create']);
|
||||
$routes->post('fetchCategoryDataById/(:num)', [CategoryController::class, 'fetchCategoryDataById']);
|
||||
$routes->post('update/(:num)', [CategoryController::class, 'update']);
|
||||
$routes->post('remove', [CategoryController::class, 'remove']);
|
||||
});
|
||||
|
||||
/**
|
||||
* route for the stores
|
||||
*/
|
||||
$routes->group('/stores', function ($routes) {
|
||||
$routes->get('/', [StoreController::class, 'index']);
|
||||
$routes->get('fetchStoresData', [StoreController::class, 'fetchStoresData']);
|
||||
$routes->post('fetchStoresDataById/(:num)', [StoreController::class, 'fetchStoresDataById']);
|
||||
$routes->post('create', [StoreController::class, 'create']);
|
||||
$routes->post('update/(:num)', [StoreController::class, 'update']);
|
||||
$routes->post('remove/', [StoreController::class, 'remove']);
|
||||
});
|
||||
|
||||
/**
|
||||
* route for the Securite
|
||||
*/
|
||||
$routes->group('/validateSecurite', function ($routes) {
|
||||
$routes->get('/', [SecuriteController::class, 'index']);
|
||||
$routes->get('fetchSecuriteData', [SecuriteController::class, 'fetchSecuriteData']);
|
||||
$routes->post('fetchSecuriteDataById/(:num)', [SecuriteController::class, 'fetchSecuriteDataById']);
|
||||
$routes->post('update/(:num)', [SecuriteController::class, 'update']);
|
||||
});
|
||||
|
||||
/**
|
||||
* route for the attributes
|
||||
*/
|
||||
$routes->group('/attributes', function ($routes) {
|
||||
$routes->get('/', [AttribuController::class, 'index']);
|
||||
$routes->get('values/(:num)', [AttribuController::class, 'getValue']);
|
||||
$routes->get('fetchAttributeData', [AttribuController::class, 'fetchCategoryData']);
|
||||
$routes->get('fetchAttributeValueData/(:num)', [AttribuController::class, 'fetchCategoryValueData']);
|
||||
$routes->post('fetchAttributeDataById/(:num)', [AttribuController::class, 'fetchAttributeDataById']);
|
||||
$routes->post('fetchAttributeValueById/(:num)', [AttribuController::class, 'fetchAttributeValueById']);
|
||||
$routes->post('create', [AttribuController::class, 'create']);
|
||||
$routes->post('update/(:num)', [AttribuController::class, 'update']);
|
||||
$routes->post('remove', [AttribuController::class, 'remove']);
|
||||
$routes->post('createValue', [AttribuController::class, 'createValue']);
|
||||
$routes->post('updateValue/(:num)', [AttribuController::class, 'updateValue']);
|
||||
$routes->post('removeValue', [AttribuController::class, 'removeValue']);
|
||||
});
|
||||
|
||||
/**
|
||||
* route for the products
|
||||
*/
|
||||
$routes->group('/products', function ($routes) {
|
||||
$routes->get('/', [ProductCOntroller::class, 'index']);
|
||||
$routes->get('fetchProductData', [ProductCOntroller::class, 'fetchProductData']);
|
||||
$routes->get('create', [ProductCOntroller::class, 'create']);
|
||||
$routes->post('create', [ProductCOntroller::class, 'create']);
|
||||
$routes->get('update/(:num)', [ProductCOntroller::class, 'update']);
|
||||
$routes->post('update/(:num)', [ProductCOntroller::class, 'update']);
|
||||
$routes->post('remove', [ProductCOntroller::class, 'remove']);
|
||||
// $routes->get('generateqrcode/(:num)', [QrCodeController::class, 'generate']);
|
||||
$routes->post('assign_store', [ProductCOntroller::class, 'assign_store']);
|
||||
$routes->post('createByExcel', [ProductCOntroller::class, 'createByExcel']);
|
||||
});
|
||||
|
||||
/**
|
||||
* route for the orders
|
||||
*/
|
||||
$routes->group('/orders', function ($routes) {
|
||||
$routes->get('/', [OrderController::class, 'index']);
|
||||
$routes->get('fetchOrdersData', [OrderController::class, 'fetchOrdersData']);
|
||||
$routes->get('create', [OrderController::class, 'create']);
|
||||
$routes->post('create', [OrderController::class, 'create']);
|
||||
$routes->post('getProductValueById', [OrderController::class, 'getProductValueById']);
|
||||
$routes->post('getTableProductRow', [OrderController::class, 'getTableProductRow']);
|
||||
$routes->get('update/(:num)', [OrderController::class, 'update']);
|
||||
$routes->post('update/(:num)', [OrderController::class, 'update']);
|
||||
$routes->get('printDiv/(:num)', [OrderController::class, 'print5']);
|
||||
$routes->get('printDivBL/(:num)', [OrderController::class, 'print7']);
|
||||
$routes->get('printDivBLF/(:num)', [OrderController::class, 'print31']);
|
||||
$routes->post('remove', [OrderController::class, 'remove']);
|
||||
$routes->get('lookOrder/(:num)', [OrderController::class, 'lookOrder']);
|
||||
$routes->get('createFromEspace/(:num)', [OrderController::class, 'createById']);
|
||||
$routes->get('resrevation', [ReservationController::class, 'index']);
|
||||
});
|
||||
|
||||
/**
|
||||
* route for the reports
|
||||
*/
|
||||
$routes->group('/reports', function ($routes) {
|
||||
$routes->get('/', [ReportController::class, 'index']);
|
||||
$routes->post('/', [ReportController::class, 'index']);
|
||||
$routes->get('detail/stock', [ReportController::class, 'stockDetail']);
|
||||
$routes->get('detail/fetctData/(:num)', [ReportController::class, 'fetchProductSodled']);
|
||||
$routes->get('detail/fetctDataStock/(:num)', [ReportController::class, 'fetchProductStock']);
|
||||
$routes->get('detail/fetctDataStock2/(:num)', [ReportController::class, 'fetchProductStock2']);
|
||||
$routes->get('detail/performance', [ReportController::class, 'performancedetail']);
|
||||
$routes->get('detail/fetchPerformances', [ReportController::class, 'fetchPerformances']);
|
||||
});
|
||||
|
||||
/**
|
||||
* route for the company
|
||||
*/
|
||||
$routes->group('/company', function ($routes) {
|
||||
$routes->get('/', [CompanyController::class, 'index']);
|
||||
$routes->post('/', [CompanyController::class, 'index']);
|
||||
});
|
||||
|
||||
/**
|
||||
* route for the users statistic
|
||||
*/
|
||||
$routes->group('/statistic', function ($routes) {
|
||||
$routes->get('/', [StatistiqueController::class, 'index']);
|
||||
$routes->get('(:num)', [StatistiqueController::class, 'singleStat']);
|
||||
});
|
||||
// routes for recouvrement
|
||||
$routes->group('/recouvrement', function ($routes) {
|
||||
$routes->get('/', [RecouvrementController::class, 'index']);
|
||||
$routes->get('fetchRecouvrementData', [RecouvrementController::class, 'fetchRecouvrementData']);
|
||||
$routes->get('fetchTotalRecouvrementData', [RecouvrementController::class, 'fetchTotalRecouvrementData']);
|
||||
$routes->get('fetchTotalData', [RecouvrementController::class, 'fetchTotal']);
|
||||
$routes->post('fetchRecouvrementSingle/(:num)', [RecouvrementController::class, 'fetchRecouvrementSingle']);
|
||||
$routes->post('create', [RecouvrementController::class, 'createRecouvrement']);
|
||||
$routes->post('delete', [RecouvrementController::class, 'removeRecouvrement']);
|
||||
$routes->post('update/(:num)', [RecouvrementController::class, 'updateRecouvrement']);
|
||||
// $routes->put('update/(:num)', 'RecouvrementController::updateRecouvrement/$1');
|
||||
});
|
||||
/**
|
||||
* route for the users mecanicien
|
||||
*/
|
||||
$routes->group('/mecanicien', function ($routes) {
|
||||
$routes->get('/', [MecanicienController::class, 'index']);
|
||||
$routes->get('fetchMecanicien', [MecanicienController::class, 'fetchMecanicien']);
|
||||
// $routes->get('fetchMecanicien_1/(:num)', [MecanicienController::class, 'fetchMecanicien_1']);
|
||||
$routes->post('fetchmecanicienSingle/(:num)', [MecanicienController::class, 'fetchmecanicienSingle']);
|
||||
$routes->post('create', [MecanicienController::class, 'create']);
|
||||
$routes->post('delete', [MecanicienController::class, 'delete']);
|
||||
$routes->post('update/(:num)', [MecanicienController::class, 'update']);
|
||||
$routes->get('fetchMecanicienPerformances', [MecanicienController::class, 'fetchMecanicienPerformances']);
|
||||
|
||||
// $routes->put('update/(:num)', 'MecanicienController::update/$1');
|
||||
});
|
||||
|
||||
$routes->group('/notifications', function ($routes) {
|
||||
$routes->get('/', [NotificationController::class, 'getNotification']);
|
||||
$routes->post('markAsRead/(:num)', [NotificationController::class, 'markAsRead']);
|
||||
});
|
||||
// routes for sortie caisse
|
||||
$routes->group('/sortieCaisse', function ($routes) {
|
||||
$routes->get('/', [SortieCaisseController::class, 'index']);
|
||||
$routes->get('fetchSortieCaisseData', [SortieCaisseController::class, 'fetchSortieCaisseData']);
|
||||
$routes->get('fetchSortieCaisseData1', [SortieCaisseController::class, 'fetchSortieCaisseData1']);
|
||||
$routes->post('fetchSortieCaisseSingle/(:num)', [SortieCaisseController::class, 'fetchSortieCaisseSingle']);
|
||||
$routes->post('createSortieCaisse', [SortieCaisseController::class, 'createSortieCaisse']);
|
||||
// $routes->post('delete', [RecouvrementController::class, 'removeRecouvrement']);
|
||||
$routes->post('updateSortieCaisse/(:num)', [SortieCaisseController::class, 'updateSortieCaisse']);
|
||||
$routes->post('validateSortieCaisse/(:num)', [SortieCaisseController::class, 'validateSortieCaisse']);
|
||||
});
|
||||
|
||||
// remise
|
||||
$routes->group('/remise', function ($routes) {
|
||||
$routes->get('/', [RemiseController::class, 'index']);
|
||||
$routes->get('fetchRemiseData', [RemiseController::class, 'fetchRemiseData']);
|
||||
// $routes->post('delete', [RecouvrementController::class, 'removeRecouvrement']);
|
||||
$routes->post('updateRemise/(:num)', [RemiseController::class, 'updateRemise']);
|
||||
});
|
||||
|
||||
// avance
|
||||
$routes->group('/avances', function ($routes) {
|
||||
$routes->get('/', [AvanceController::class, 'index']);
|
||||
$routes->get('fetchAvanceData', [AvanceController::class, 'fetchAvanceData']);
|
||||
$routes->get('fetchAvanceBecameOrder', [AvanceController::class, 'fetchAvanceBecameOrder']);
|
||||
$routes->get('fetchExpiredAvance', [AvanceController::class, 'fetcheExpiredAvance']);
|
||||
$routes->get('fetchSingleAvance/(:num)', [AvanceController::class, 'fetchSingleAvance']);
|
||||
$routes->post('createAvance', [AvanceController::class, 'createAvance']);
|
||||
$routes->post('deleteAvance', [AvanceController::class, 'removeAvance']);
|
||||
$routes->post('updateAvance/(:num)', [AvanceController::class, 'updateAvance']);
|
||||
});
|
||||
});
|
||||
114
app/Config/Routing.php
Normal file
114
app/Config/Routing.php
Normal file
@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <Conseil@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
|
||||
{
|
||||
/**
|
||||
* 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',
|
||||
];
|
||||
|
||||
/**
|
||||
* The default namespace to use for Controllers when no other
|
||||
* namespace has been specified.
|
||||
*
|
||||
* Default: 'App\Controllers'
|
||||
*/
|
||||
public string $defaultNamespace = 'App\Controllers';
|
||||
|
||||
/**
|
||||
* The default controller to use when no other controller has been
|
||||
* specified.
|
||||
*
|
||||
* Default: 'Home'
|
||||
*/
|
||||
public string $defaultController = 'Home';
|
||||
|
||||
/**
|
||||
* The default method to call on the controller when no other
|
||||
* method has been set in the route.
|
||||
*
|
||||
* Default: 'index'
|
||||
*/
|
||||
public string $defaultMethod = 'index';
|
||||
|
||||
/**
|
||||
* Whether to translate dashes in URIs 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;
|
||||
|
||||
/**
|
||||
* If TRUE, will enable the use of the 'prioritize' option
|
||||
* when defining routes.
|
||||
*
|
||||
* Default: false
|
||||
*/
|
||||
public bool $prioritize = false;
|
||||
|
||||
/**
|
||||
* Map of URI segments and namespaces. For Auto Routing (Improved).
|
||||
*
|
||||
* 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 = [];
|
||||
}
|
||||
101
app/Config/Security.php
Normal file
101
app/Config/Security.php
Normal file
@ -0,0 +1,101 @@
|
||||
<?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.
|
||||
*/
|
||||
public bool $redirect = false;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* CSRF SameSite
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Setting for CSRF SameSite cookie token.
|
||||
*
|
||||
* Allowed values are: None - Lax - Strict - ''.
|
||||
*
|
||||
* Defaults to `Lax` as recommended in this link:
|
||||
*
|
||||
* @see https://portswigger.net/web-security/csrf/samesite-cookies
|
||||
*
|
||||
* @deprecated `Config\Cookie` $samesite property is used.
|
||||
*/
|
||||
public string $samesite = 'Lax';
|
||||
}
|
||||
32
app/Config/Services.php
Normal file
32
app/Config/Services.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseService;
|
||||
|
||||
/**
|
||||
* 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();
|
||||
* }
|
||||
*/
|
||||
}
|
||||
102
app/Config/Session.php
Normal file
102
app/Config/Session.php
Normal file
@ -0,0 +1,102 @@
|
||||
<?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;
|
||||
}
|
||||
126
app/Config/Toolbar.php
Normal file
126
app/Config/Toolbar.php
Normal file
@ -0,0 +1,126 @@
|
||||
<?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;
|
||||
|
||||
public $enabled = true; // Ensure this is set to true
|
||||
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* 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 = [];
|
||||
}
|
||||
233
app/Controllers/AdminController.php
Normal file
233
app/Controllers/AdminController.php
Normal file
@ -0,0 +1,233 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Models\Groups;
|
||||
use App\Models\Company;
|
||||
use CodeIgniter\Controller;
|
||||
use CodeIgniter\HTTP\RequestInterface;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
use CodeIgniter\Logger\LoggerInterface;
|
||||
|
||||
abstract class AdminController extends BaseController
|
||||
{
|
||||
protected $permission = [];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
if (empty(session()->get('user'))) {
|
||||
redirect()->to('/login');
|
||||
} else {
|
||||
$userIfo = session()->get('user');
|
||||
$userId = $userIfo['id'];
|
||||
|
||||
$Groups = new Groups();
|
||||
$group_data = $Groups->getUserGroupByUserId($userId);
|
||||
|
||||
$this->permission = unserialize($group_data['permission']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* finction to verify role of users
|
||||
* @return mixed
|
||||
*/
|
||||
protected function verifyRole(string $role)
|
||||
{
|
||||
if (!in_array( $role, $this->permission)) {
|
||||
redirect()->to('/')->send();
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
// Render template with page data
|
||||
protected function render_template($page = null, $data = [])
|
||||
{
|
||||
$data['user_permission'] = $this->permission;
|
||||
echo view('templates/header', $data);
|
||||
echo view('templates/header_menu', $data);
|
||||
echo view('templates/side_menubar', $data);
|
||||
echo view($page, $data);
|
||||
echo view('templates/footer', $data);
|
||||
}
|
||||
|
||||
// Get company currency using model
|
||||
public function company_currency()
|
||||
{
|
||||
$model_company = new Company();
|
||||
$company_currency = $model_company->getCompanyData(1);
|
||||
$currencies = $this->currency();
|
||||
|
||||
$currency = '';
|
||||
foreach ($currencies as $key => $value) {
|
||||
if ($key == $company_currency['currency']) {
|
||||
$currency = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $currency;
|
||||
}
|
||||
|
||||
// Return currency symbols
|
||||
public function currency()
|
||||
{
|
||||
return [
|
||||
'AED' => 'د.إ', // ?
|
||||
'AFN' => 'Af',
|
||||
'ALL' => 'Lek',
|
||||
'ANG' => 'ƒ',
|
||||
'AOA' => 'Kz', // ?
|
||||
'ARS' => '$',
|
||||
'AUD' => '$',
|
||||
'AWG' => 'ƒ',
|
||||
'AZN' => 'ман',
|
||||
'BAM' => 'KM',
|
||||
'BBD' => '$',
|
||||
'BDT' => '৳', // ?
|
||||
'BGN' => 'лв',
|
||||
'BHD' => '.د.ب', // ?
|
||||
'BIF' => 'FBu', // ?
|
||||
'BMD' => '$',
|
||||
'BND' => '$',
|
||||
'BOB' => '$b',
|
||||
'BRL' => 'R$',
|
||||
'BSD' => '$',
|
||||
'BTN' => 'Nu.', // ?
|
||||
'BWP' => 'P',
|
||||
'BYR' => 'p.',
|
||||
'BZD' => 'BZ$',
|
||||
'CAD' => '$',
|
||||
'CDF' => 'FC',
|
||||
'CHF' => 'CHF',
|
||||
'CLP' => '$',
|
||||
'CNY' => '¥',
|
||||
'COP' => '$',
|
||||
'CRC' => '₡',
|
||||
'CUP' => '⃌',
|
||||
'CVE' => '$', // ?
|
||||
'CZK' => 'Kč',
|
||||
'DJF' => 'Fdj', // ?
|
||||
'DKK' => 'kr',
|
||||
'DOP' => 'RD$',
|
||||
'DZD' => 'دج', // ?
|
||||
'EGP' => '£',
|
||||
'ETB' => 'Br',
|
||||
'EUR' => '€',
|
||||
'FJD' => '$',
|
||||
'FKP' => '£',
|
||||
'GBP' => '£',
|
||||
'GEL' => 'ლ', // ?
|
||||
'GHS' => '¢',
|
||||
'GIP' => '£',
|
||||
'GMD' => 'D', // ?
|
||||
'GNF' => 'FG', // ?
|
||||
'GTQ' => 'Q',
|
||||
'GYD' => '$',
|
||||
'HKD' => '$',
|
||||
'HNL' => 'L',
|
||||
'HRK' => 'kn',
|
||||
'HTG' => 'G', // ?
|
||||
'HUF' => 'Ft',
|
||||
'IDR' => 'Rp',
|
||||
'ILS' => '₪',
|
||||
'INR' => '₹',
|
||||
'IQD' => 'ع.د', // ?
|
||||
'IRR' => '﷼',
|
||||
'ISK' => 'kr',
|
||||
'JEP' => '£',
|
||||
'JMD' => 'J$',
|
||||
'JOD' => 'JD', // ?
|
||||
'JPY' => '¥',
|
||||
'KES' => 'KSh', // ?
|
||||
'KGS' => 'лв',
|
||||
'KHR' => '៛',
|
||||
'KMF' => 'CF', // ?
|
||||
'KPW' => '₩',
|
||||
'KRW' => '₩',
|
||||
'KWD' => 'د.ك', // ?
|
||||
'KYD' => '$',
|
||||
'KZT' => 'лв',
|
||||
'LAK' => '₭',
|
||||
'LBP' => '£',
|
||||
'LKR' => '₨',
|
||||
'LRD' => '$',
|
||||
'LSL' => 'L', // ?
|
||||
'LTL' => 'Lt',
|
||||
'LVL' => 'Ls',
|
||||
'LYD' => 'ل.د', // ?
|
||||
'MAD' => 'د.م.', //?
|
||||
'MDL' => 'L',
|
||||
'MGA' => 'Ar', // ?
|
||||
'MKD' => 'ден',
|
||||
'MMK' => 'K',
|
||||
'MNT' => '₮',
|
||||
'MOP' => 'MOP$', // ?
|
||||
'MRO' => 'UM', // ?
|
||||
'MUR' => '₨', // ?
|
||||
'MVR' => '.ރ', // ?
|
||||
'MWK' => 'MK',
|
||||
'MXN' => '$',
|
||||
'MYR' => 'RM',
|
||||
'MZN' => 'MT',
|
||||
'NAD' => '$',
|
||||
'NGN' => '₦',
|
||||
'NIO' => 'C$',
|
||||
'NOK' => 'kr',
|
||||
'NPR' => '₨',
|
||||
'NZD' => '$',
|
||||
'OMR' => '﷼',
|
||||
'PAB' => 'B/.',
|
||||
'PEN' => 'S/.',
|
||||
'PGK' => 'K', // ?
|
||||
'PHP' => '₱',
|
||||
'PKR' => '₨',
|
||||
'PLN' => 'zł',
|
||||
'PYG' => 'Gs',
|
||||
'QAR' => '﷼',
|
||||
'RON' => 'lei',
|
||||
'RSD' => 'Дин.',
|
||||
'RUB' => 'руб',
|
||||
'RWF' => 'ر.س',
|
||||
'SAR' => '﷼',
|
||||
'SBD' => '$',
|
||||
'SCR' => '₨',
|
||||
'SDG' => '£', // ?
|
||||
'SEK' => 'kr',
|
||||
'SGD' => '$',
|
||||
'SHP' => '£',
|
||||
'SLL' => 'Le', // ?
|
||||
'SOS' => 'S',
|
||||
'SRD' => '$',
|
||||
'STD' => 'Db', // ?
|
||||
'SVC' => '$',
|
||||
'SYP' => '£',
|
||||
'SZL' => 'L', // ?
|
||||
'THB' => '฿',
|
||||
'TJS' => 'TJS', // ? TJS (guess)
|
||||
'TMT' => 'm',
|
||||
'TND' => 'د.ت',
|
||||
'TOP' => 'T$',
|
||||
'TRY' => '₤', // New Turkey Lira (old symbol used)
|
||||
'TTD' => '$',
|
||||
'TWD' => 'NT$',
|
||||
'UAH' => '₴',
|
||||
'UGX' => 'USh',
|
||||
'USD' => '$',
|
||||
'UYU' => '$U',
|
||||
'UZS' => 'лв',
|
||||
'VEF' => 'Bs',
|
||||
'VND' => '₫',
|
||||
'VUV' => 'VT',
|
||||
'WST' => 'WS$',
|
||||
'XAF' => 'FCFA',
|
||||
'XCD' => '$',
|
||||
'XPF' => 'F',
|
||||
'YER' => '﷼',
|
||||
'ZAR' => 'R',
|
||||
'ZMK' => 'ZK', // ?
|
||||
'ZWL' => 'Z$',
|
||||
// ... add the rest of the currencies
|
||||
];
|
||||
}
|
||||
}
|
||||
14
app/Controllers/AlertsController.php
Normal file
14
app/Controllers/AlertsController.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
|
||||
class AlertsController extends BaseController
|
||||
{
|
||||
public function check()
|
||||
{
|
||||
helper('alerts');
|
||||
checkDeadlineAlerts();
|
||||
return "Vérification des alertes effectuée.";
|
||||
}
|
||||
}
|
||||
341
app/Controllers/AttribuController.php
Normal file
341
app/Controllers/AttribuController.php
Normal file
@ -0,0 +1,341 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Models\Attributes;
|
||||
|
||||
class AttribuController extends AdminController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
// Assuming permission is being set from a session
|
||||
helper(['form', 'url']);
|
||||
}
|
||||
|
||||
private $pageTitle = 'Attributes';
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->verifyRole('viewCategory');
|
||||
$data['page_title'] = $this->pageTitle;
|
||||
|
||||
return $this->render_template('attributes/index', $data);
|
||||
}
|
||||
|
||||
public function fetchAttributeDataById(int $id)
|
||||
{
|
||||
if ($id) {
|
||||
$Attributes = new Attributes();
|
||||
$data = $Attributes->getAttributeData($id);
|
||||
return $this->response->setJSON($data);
|
||||
}
|
||||
}
|
||||
|
||||
public function fetchCategoryData()
|
||||
{
|
||||
// Prepare the response array
|
||||
$result = ['data' => []];
|
||||
|
||||
$Attributes = new Attributes();
|
||||
// Get category data
|
||||
$data = $Attributes->getAttributeData(); // Make sure this function exists in your CategoryModel
|
||||
|
||||
// Iterate through each category and build the response
|
||||
foreach ($data as $key => $value) {
|
||||
|
||||
// Initialize button HTML
|
||||
$buttons = '';
|
||||
|
||||
// Check if the user has permission to update
|
||||
if (in_array('updateCategory', $this->permission)) {
|
||||
$buttons .= '<button type="button" class="btn btn-default" onclick="editFunc(' . $value['id'] . ')" data-toggle="modal" data-target="#editModal"><i class="fa fa-pencil"></i></button>';
|
||||
}
|
||||
|
||||
// Check if the user has permission to delete
|
||||
if (in_array('deleteCategory', $this->permission)) {
|
||||
$buttons .= ' <button type="button" class="btn btn-default" onclick="removeFunc(' . $value['id'] . ')" data-toggle="modal" data-target="#removeModal"><i class="fa fa-trash"></i></button>';
|
||||
}
|
||||
// Check if the user has permission to delete
|
||||
if (in_array('deleteCategory', $this->permission)) {
|
||||
$buttons .= ' <a class="btn btn-default" href="values/' . $value['id'] . '"><i class="fa fa-plus"></i></a>';
|
||||
}
|
||||
|
||||
// Determine the status label
|
||||
$status = ($value['active'] == 1) ? '<span class="label label-success">Active</span>' : '<span class="label label-warning">Inactive</span>';
|
||||
$attributCount = $Attributes->countAttributeValue($value['id']);
|
||||
// Add data to the result array
|
||||
$result['data'][] = [
|
||||
$value['name'],
|
||||
$attributCount,
|
||||
$status,
|
||||
$buttons
|
||||
];
|
||||
}
|
||||
// Return the result as JSON
|
||||
return $this->response->setJSON($result);
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$this->verifyRole('createAttribute');
|
||||
$response = [];
|
||||
|
||||
// Set validation rules
|
||||
$validation = \Config\Services::validation();
|
||||
|
||||
$validation->setRules([
|
||||
'attribute_name' => 'required',
|
||||
'active' => 'required',
|
||||
]);
|
||||
|
||||
$validationData = [
|
||||
'attribute_name' => $this->request->getPost('attribute_name'),
|
||||
'active' => $this->request->getPost('active'),
|
||||
];
|
||||
|
||||
$Attributes = new Attributes();
|
||||
|
||||
if ($validation->run($validationData)) {
|
||||
$data = [
|
||||
'name' => $this->request->getPost('attribute_name'),
|
||||
'active' => $this->request->getPost('active'),
|
||||
];
|
||||
|
||||
if ($Attributes->create($data)) {
|
||||
$response['success'] = true;
|
||||
$response['messages'] = 'Crée avec succès';
|
||||
} else {
|
||||
$response['success'] = false;
|
||||
$response['messages'] = 'Erreur dans la base de données lors de la création des informations sur la marque';
|
||||
}
|
||||
} else {
|
||||
$response['success'] = false;
|
||||
$response['messages'] = $validation->getErrors();
|
||||
}
|
||||
|
||||
return $this->response->setJSON($response);
|
||||
}
|
||||
|
||||
public function update(int $id)
|
||||
{
|
||||
$this->verifyRole('updateAttribute');
|
||||
$response = [];
|
||||
|
||||
if ($id) {
|
||||
// Set validation rules
|
||||
$validation = \Config\Services::validation();
|
||||
|
||||
$validation->setRules([
|
||||
'edit_attribute_name' => 'required',
|
||||
'edit_active' => 'required',
|
||||
]);
|
||||
|
||||
$validationData = [
|
||||
'edit_attribute_name' => $this->request->getPost('edit_attribute_name'),
|
||||
'edit_active' => $this->request->getPost('edit_active'),
|
||||
];
|
||||
|
||||
$Attributes = new Attributes();
|
||||
|
||||
if ($validation->run($validationData)) {
|
||||
$data = [
|
||||
'name' => $this->request->getPost('edit_attribute_name'),
|
||||
'active' => $this->request->getPost('edit_active'),
|
||||
];
|
||||
|
||||
if ($Attributes->updateAttribute($data, $id)) {
|
||||
$response['success'] = true;
|
||||
$response['messages'] = 'Succesfully updated';
|
||||
} else {
|
||||
$response['success'] = false;
|
||||
$response['messages'] = 'Error in the database while updated the brand information';
|
||||
}
|
||||
} else {
|
||||
$response['success'] = false;
|
||||
$response['messages'] = $validation->getErrors();
|
||||
}
|
||||
} else {
|
||||
$response['success'] = false;
|
||||
$response['messages'] = 'Error please refresh the page again!!';
|
||||
}
|
||||
return $this->response->setJSON($response);
|
||||
}
|
||||
|
||||
public function remove()
|
||||
{
|
||||
$this->verifyRole('deleteAttribute');
|
||||
$attribute_id = $this->request->getPost('attribute_id');
|
||||
|
||||
if ($attribute_id) {
|
||||
$Attributes = new Attributes();
|
||||
if ($Attributes->delete($attribute_id)) {
|
||||
$response['success'] = true;
|
||||
$response['messages'] = "Successfully removed";
|
||||
} else {
|
||||
$response['success'] = false;
|
||||
$response['messages'] = "Error in the database while removing the brand information";
|
||||
}
|
||||
} else {
|
||||
$response['success'] = false;
|
||||
$response['messages'] = "Refersh the page again!!";
|
||||
}
|
||||
return $this->response->setJSON($response);
|
||||
}
|
||||
|
||||
public function getValue(int $id)
|
||||
{
|
||||
$Attributes = new Attributes();
|
||||
$data['attribute_data'] = $Attributes->getAttributeData($id);
|
||||
$this->verifyRole('viewCategory');
|
||||
$data['page_title'] = $this->pageTitle;
|
||||
// die(var_dump($data));
|
||||
$data['test'] = $id;
|
||||
|
||||
return $this->render_template('attributes/addvalue', $data);
|
||||
}
|
||||
|
||||
public function fetchCategoryValueData(int $id)
|
||||
{
|
||||
if ($id) {
|
||||
// Prepare the response array
|
||||
$result = ['data' => []];
|
||||
|
||||
$Attributes = new Attributes();
|
||||
// Get category data
|
||||
$data = $Attributes->getAttributeValueData($id); // Make sure this function exists in your CategoryModel
|
||||
|
||||
// Iterate through each category and build the response
|
||||
foreach ($data as $key => $value) {
|
||||
|
||||
// Initialize button HTML
|
||||
$buttons = '';
|
||||
|
||||
// Check if the user has permission to update
|
||||
if (in_array('updateCategory', $this->permission)) {
|
||||
$buttons .= '<button type="button" class="btn btn-default" onclick="editFunc(' . $value['id'] . ')" data-toggle="modal" data-target="#editModal"><i class="fa fa-pencil"></i></button>';
|
||||
}
|
||||
|
||||
// Check if the user has permission to delete
|
||||
if (in_array('deleteCategory', $this->permission)) {
|
||||
$buttons .= ' <button type="button" class="btn btn-default" onclick="removeFunc(' . $value['id'] . ')" data-toggle="modal" data-target="#removeModal"><i class="fa fa-trash"></i></button>';
|
||||
}
|
||||
|
||||
// Add data to the result array
|
||||
$result['data'][] = [
|
||||
$value['value'],
|
||||
$buttons
|
||||
];
|
||||
}
|
||||
// Return the result as JSON
|
||||
return $this->response->setJSON($result);
|
||||
}
|
||||
}
|
||||
|
||||
public function createValue()
|
||||
{
|
||||
$this->verifyRole('createAttribute');
|
||||
$response = [];
|
||||
|
||||
// Set validation rules
|
||||
$validation = \Config\Services::validation();
|
||||
|
||||
$validation->setRules([
|
||||
'attribute_value_name' => 'required',
|
||||
'attribute_parent_id' => 'required',
|
||||
]);
|
||||
|
||||
$validationData = [
|
||||
'attribute_value_name' => $this->request->getPost('attribute_value_name'),
|
||||
'attribute_parent_id' => $this->request->getPost('attribute_parent_id'),
|
||||
];
|
||||
|
||||
$Attributes = new Attributes();
|
||||
|
||||
if ($validation->run($validationData)) {
|
||||
$data = [
|
||||
'value' => $this->request->getPost('attribute_value_name'),
|
||||
'attribute_parent_id' => $this->request->getPost('attribute_parent_id'),
|
||||
];
|
||||
|
||||
if ($Attributes->createValue($data)) {
|
||||
$response['success'] = true;
|
||||
$response['messages'] = 'Crée avec succès';
|
||||
} else {
|
||||
$response['success'] = false;
|
||||
$response['messages'] = 'Erreur dans la base de données lors de la création des informations sur la marque';
|
||||
}
|
||||
} else {
|
||||
$response['success'] = false;
|
||||
$response['messages'] = $validation->getErrors();
|
||||
}
|
||||
|
||||
return $this->response->setJSON($response);
|
||||
}
|
||||
|
||||
public function fetchAttributeValueById(int $id)
|
||||
{
|
||||
if ($id) {
|
||||
$Attributes = new Attributes();
|
||||
$data = $Attributes->getAttributeValueById($id);
|
||||
return $this->response->setJSON($data);
|
||||
}
|
||||
}
|
||||
|
||||
public function updateValue(int $id)
|
||||
{
|
||||
$this->verifyRole('updateAttribute');
|
||||
$response = [];
|
||||
|
||||
// Set validation rules
|
||||
$validation = \Config\Services::validation();
|
||||
|
||||
$validation->setRules([
|
||||
'edit_attribute_value_name' => 'required',
|
||||
'attribute_parent_id' => 'required',
|
||||
]);
|
||||
|
||||
$validationData = [
|
||||
'edit_attribute_value_name' => $this->request->getPost('edit_attribute_value_name'),
|
||||
'attribute_parent_id' => $this->request->getPost('attribute_parent_id'),
|
||||
];
|
||||
|
||||
$Attributes = new Attributes();
|
||||
|
||||
if ($validation->run($validationData)) {
|
||||
$data = [
|
||||
'value' => $this->request->getPost('edit_attribute_value_name'),
|
||||
'attribute_parent_id' => $this->request->getPost('attribute_parent_id'),
|
||||
];
|
||||
|
||||
if ($Attributes->updateValue($data, $id)) {
|
||||
$response['success'] = true;
|
||||
$response['messages'] = 'Succesfully updated';
|
||||
} else {
|
||||
$response['success'] = false;
|
||||
$response['messages'] = 'Error in the database while updated the brand information';
|
||||
}
|
||||
} else {
|
||||
$response['success'] = false;
|
||||
$response['messages'] = $validation->getErrors();
|
||||
}
|
||||
|
||||
return $this->response->setJSON($response);
|
||||
}
|
||||
|
||||
public function removeValue()
|
||||
{
|
||||
$response = [];
|
||||
$Attributes = new Attributes();
|
||||
|
||||
if ($this->request->getPost('attribute_value_id') && $Attributes->removeValue($this->request->getPost('attribute_value_id'))) {
|
||||
$response['success'] = true;
|
||||
$response['messages'] = 'Succesfully removed';
|
||||
} else {
|
||||
$response['success'] = false;
|
||||
$response['messages'] = 'Error in the database while updated the brand information';
|
||||
}
|
||||
|
||||
return $this->response->setJSON($response);
|
||||
}
|
||||
}
|
||||
214
app/Controllers/Auth.php
Normal file
214
app/Controllers/Auth.php
Normal file
@ -0,0 +1,214 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Models\ProductImage;
|
||||
use App\Models\Users;
|
||||
use App\Models\Stores;
|
||||
use App\Models\Products;
|
||||
|
||||
class Auth extends AdminController
|
||||
{
|
||||
/**
|
||||
* function who return the view login
|
||||
* @return string
|
||||
*/
|
||||
public function login()
|
||||
{
|
||||
return view('login');
|
||||
}
|
||||
|
||||
private function uploadImage($file)
|
||||
{
|
||||
// Define the upload directory
|
||||
$uploadPath = 'assets/images/product_image';
|
||||
|
||||
// Ensure the directory exists
|
||||
if (!is_dir($uploadPath)) {
|
||||
mkdir($uploadPath, 0777, true);
|
||||
}
|
||||
|
||||
|
||||
// Check if the file is uploaded via the form
|
||||
// $file = $this->request->getFile('images');
|
||||
if ($file && $file->isValid() && !$file->hasMoved()) {
|
||||
// Generate a unique file name
|
||||
$newName = uniqid() . '.' . $file->getExtension();
|
||||
|
||||
// Move the file to the target directory
|
||||
$file->move($uploadPath, $newName);
|
||||
|
||||
// Return the actual file name
|
||||
return $newName;
|
||||
}
|
||||
|
||||
// If an error occurs, return the error message
|
||||
return $file ? $file->getErrorString() : 'No file was uploaded.';
|
||||
}
|
||||
|
||||
/**
|
||||
* function used to login
|
||||
* @return \CodeIgniter\HTTP\RedirectResponse
|
||||
*/
|
||||
public function loginPost()
|
||||
{
|
||||
$email = $this->request->getPost('email');
|
||||
$password = $this->request->getPost('password');
|
||||
|
||||
// Load the model and attempt login
|
||||
$userModel = new Users();
|
||||
|
||||
$user = $userModel->attempt($email, $password);
|
||||
|
||||
if ($user) {
|
||||
// Set user session
|
||||
session()->set('user', $user);
|
||||
|
||||
// Redirect to dashboard
|
||||
return redirect()->to('/');
|
||||
}
|
||||
|
||||
// If login fails, redirect back with an error
|
||||
return redirect()->to('/login')->with('error', 'Invalid email or password.');
|
||||
}
|
||||
|
||||
public function logout()
|
||||
{
|
||||
session()->destroy();
|
||||
return redirect()->to('/login');
|
||||
}
|
||||
|
||||
public function ventes()
|
||||
{
|
||||
$this->verifyRole('viewCom');
|
||||
$data['page_title'] = "Espace commercial";
|
||||
|
||||
$session = session();
|
||||
$user_id = $session->get('user');
|
||||
$data['id'] = $user_id['store_id'];
|
||||
// die(var_dump($user_id['store_id']));
|
||||
|
||||
|
||||
return $this->render_template('commercial/index', $data);
|
||||
}
|
||||
|
||||
public function fetchProductVente(int $id)
|
||||
{
|
||||
// Initialize the response array
|
||||
$result = ['data' => []];
|
||||
$Products = new Products();
|
||||
|
||||
// Fetch product data from the model
|
||||
$data = $Products->getProductDataStore($id); // Ensure this method exists in your ProductModel
|
||||
|
||||
foreach ($data as $key => $value) {
|
||||
|
||||
// Construct buttons
|
||||
$buttons = '';
|
||||
|
||||
if (in_array('viewCom', $this->permission)) {
|
||||
$buttons .= " <a href='/ventes/show/" . $value['id'] . "' class='btn btn-default'><i class='fa fa-eye'></i></a>";
|
||||
}
|
||||
|
||||
if (is_array($this->permission) && in_array('createOrder', $this->permission)) {
|
||||
$buttons .= ($value['qty'] == 1)
|
||||
? " <a href='/orders/createFromEspace/" . $value['id'] . "' class='btn btn-default'><i class='fa fa-shopping-cart'></i></a>"
|
||||
: " <button class='btn btn-default' title='0 en stock'><i class='fa fa-shopping-cart'></i></button>";
|
||||
}
|
||||
|
||||
// Image HTML
|
||||
$img = '<img src="' . base_url('assets/images/product_image/' . $value['image']) . '" alt="' . $value['name'] . '" class="img-circle" width="50" height="50" />';
|
||||
|
||||
// Populate the result data
|
||||
$result['data'][] = [
|
||||
$img,
|
||||
$value['sku'],
|
||||
$value['name'],
|
||||
number_format($value['prix_vente'], 0, ',', ' '),
|
||||
$value['puissance'] . ' CC',
|
||||
$value['numero_de_moteur'],
|
||||
$buttons
|
||||
];
|
||||
}
|
||||
|
||||
// Return JSON response
|
||||
return $this->response->setJSON($result);
|
||||
}
|
||||
|
||||
public function addImage(int $id)
|
||||
{
|
||||
$this->verifyRole('updateProduct');
|
||||
$data['page_title'] = "Espace commercial";
|
||||
$Products = new Products();
|
||||
$ProductImage = new ProductImage();
|
||||
|
||||
$data['products'] = $Products->getProductData($id);
|
||||
$data['galleries'] = $ProductImage->getAll($id);
|
||||
|
||||
return $this->render_template('commercial/addImage', $data);
|
||||
}
|
||||
|
||||
public function uploadImagePub($id)
|
||||
{
|
||||
$this->verifyRole('updateProduct');
|
||||
// die(var_dump($this->request->getFiles()));
|
||||
$files = $this->request->getFiles();
|
||||
$ProductImage = new ProductImage();
|
||||
$isTrue = false;
|
||||
for ($i = 0; $i < count($files['images']); $i++) {
|
||||
$imageName = $this->uploadImage($files['images'][$i]);
|
||||
$data = [
|
||||
'product_id' => $id,
|
||||
'images' => $imageName
|
||||
];
|
||||
|
||||
if ($ProductImage->create($data)) {
|
||||
$isTrue = true;
|
||||
} else {
|
||||
$isTrue = false;
|
||||
}
|
||||
}
|
||||
|
||||
if ($isTrue) {
|
||||
session()->setFlashdata('success', 'Mise à jour réusit');
|
||||
return redirect()->to('/products');
|
||||
} else {
|
||||
session()->setFlashdata('errors', 'Error occurred while creating the product');
|
||||
return redirect()->to('ventes/' . $id);
|
||||
}
|
||||
}
|
||||
|
||||
public function delete(int $id)
|
||||
{
|
||||
$this->verifyRole('updateProduct');
|
||||
$ProductImage = new ProductImage();
|
||||
if ($id) {
|
||||
$result = $ProductImage->deleteOne($id);
|
||||
|
||||
if ($result) {
|
||||
return redirect()->back();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getSingle(int $id)
|
||||
{
|
||||
$data['page_title'] = "Espace commercial";
|
||||
$Products = new Products();
|
||||
$ProductImage = new ProductImage();
|
||||
$Stores = new Stores();
|
||||
|
||||
$data['products'] = $Products->getProductData($id);
|
||||
$data['stores'] = '';
|
||||
$data['galleries'] = $ProductImage->getAll($id);
|
||||
$allStores = $Stores->getActiveStore();
|
||||
|
||||
for ($i = 0; $i < count($allStores); $i++) {
|
||||
if ($allStores[$i]['id'] == $data['products']['store_id']) {
|
||||
$data['stores'] = $allStores[$i]['name'];
|
||||
}
|
||||
}
|
||||
|
||||
return $this->render_template('commercial/single', $data);
|
||||
}
|
||||
}
|
||||
662
app/Controllers/AvanceController.php
Normal file
662
app/Controllers/AvanceController.php
Normal file
@ -0,0 +1,662 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Models\Company;
|
||||
use App\Models\Orders;
|
||||
use App\Models\Products;
|
||||
use App\Models\Avance;
|
||||
use App\Models\User; // Ajout pour récupérer les emails DAF/Directrice
|
||||
|
||||
class AvanceController extends AdminController
|
||||
{
|
||||
private $pageTitle = 'Avances';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->verifyRole('viewAvance');
|
||||
$data['page_title'] = $this->pageTitle;
|
||||
$Products = new Products();
|
||||
$session = session();
|
||||
$users = $session->get('user');
|
||||
$store_id = $users['store_id'];
|
||||
$data['products'] = $Products->getProductDataStore($store_id);
|
||||
return $this->render_template('avances/avance', $data);
|
||||
}
|
||||
|
||||
private function isAdmin($user)
|
||||
{
|
||||
return in_array($user['group_name'], ['Conseil', 'Direction']);
|
||||
}
|
||||
|
||||
private function isCommerciale($user)
|
||||
{
|
||||
return in_array($user['group_name'], ['COMMERCIALE']);
|
||||
}
|
||||
|
||||
private function isCaissier($user)
|
||||
{
|
||||
return in_array($user['group_name'], ['Caissier']);
|
||||
}
|
||||
|
||||
private function buildActionButtons($value, $isAdmin, $isOwner)
|
||||
{
|
||||
$buttons = '';
|
||||
|
||||
if (in_array('updateAvance', $this->permission) && ($isAdmin || $isOwner)) {
|
||||
$buttons .= '<button type="button" class="btn btn-default" onclick="editFunc(' . $value['avance_id'] . ')" title="Modifier">'
|
||||
. '<i class="fa fa-pencil"></i></button> ';
|
||||
}
|
||||
|
||||
if (in_array('deleteAvance', $this->permission) && ($isAdmin || $isOwner)) {
|
||||
$buttons .= '<button type="button" class="btn btn-danger" onclick="removeFunc(' . $value['avance_id'] . ',' . $value['product_id'] . ')" title="Supprimer">'
|
||||
. '<i class="fa fa-trash"></i></button> ';
|
||||
}
|
||||
|
||||
if (in_array('viewAvance', $this->permission) && !$isAdmin) {
|
||||
$buttons .= '<a href="#" data-order-id="' . $value['avance_id'] . '" class="btn btn-default btn-view" title="Voir">'
|
||||
. '<i class="fa fa-eye"></i></a>';
|
||||
}
|
||||
|
||||
return $buttons;
|
||||
}
|
||||
|
||||
private function buildDataRow($value, $product, $isAdmin, $isCommerciale, $isCaissier, $buttons)
|
||||
{
|
||||
$date_time = date('d-m-Y h:i a', strtotime($value['avance_date']));
|
||||
|
||||
if ($isAdmin) {
|
||||
return [
|
||||
$value['customer_name'],
|
||||
$value['customer_phone'],
|
||||
$value['customer_address'],
|
||||
$product->getProductNameById($value['product_id']),
|
||||
number_format((int)$value['gross_amount'], 0, ',', ' '),
|
||||
number_format((int)$value['avance_amount'], 0, ',', ' '),
|
||||
number_format((int)$value['amount_due'], 0, ',', ' '),
|
||||
$date_time,
|
||||
$buttons,
|
||||
];
|
||||
} elseif ($isCommerciale || $isCaissier) {
|
||||
return [
|
||||
$value['avance_id'],
|
||||
$product->getProductNameById($value['product_id']),
|
||||
number_format((int)$value['avance_amount'], 0, ',', ' '),
|
||||
number_format((int)$value['amount_due'], 0, ',', ' '),
|
||||
$date_time,
|
||||
$buttons,
|
||||
];
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
private function fetchAvanceDataGeneric($methodName = 'getAllAvanceData')
|
||||
{
|
||||
helper(['url', 'form']);
|
||||
$Avance = new Avance();
|
||||
$product = new Products();
|
||||
$result = ['data' => []];
|
||||
|
||||
$data = $Avance->$methodName();
|
||||
$session = session();
|
||||
$users = $session->get('user');
|
||||
|
||||
$isAdmin = $this->isAdmin($users);
|
||||
$isCommerciale = $this->isCommerciale($users);
|
||||
$isCaissier = $this->isCaissier($users);
|
||||
|
||||
foreach ($data as $key => $value) {
|
||||
$isOwner = $users['id'] === $value['user_id'];
|
||||
|
||||
$buttons = $this->buildActionButtons($value, $isAdmin, $isOwner);
|
||||
|
||||
$row = $this->buildDataRow($value, $product, $isAdmin, $isCommerciale, $isCaissier, $buttons);
|
||||
|
||||
if (!empty($row)) {
|
||||
$result['data'][] = $row;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->response->setJSON($result);
|
||||
}
|
||||
|
||||
public function fetchAvanceData()
|
||||
{
|
||||
return $this->fetchAvanceDataGeneric('getAllAvanceData');
|
||||
}
|
||||
|
||||
public function fetchAvanceBecameOrder()
|
||||
{
|
||||
return $this->fetchAvanceDataGeneric('getAllAvanceData1');
|
||||
}
|
||||
|
||||
public function fetcheExpiredAvance()
|
||||
{
|
||||
return $this->fetchAvanceDataGeneric('getAllAvanceData2');
|
||||
}
|
||||
|
||||
/**
|
||||
* Méthode pour vérifier et envoyer des emails d'alerte 3 jours avant deadline
|
||||
* À exécuter via CRON job quotidiennement
|
||||
*/
|
||||
public function checkDeadlineAlerts()
|
||||
{
|
||||
try {
|
||||
$Avance = new Avance();
|
||||
$Products = new Products();
|
||||
|
||||
// Récupérer toutes les avances actives non converties en commandes
|
||||
$avances = $Avance->getAvancesNearDeadline(3); // 3 jours avant deadline
|
||||
|
||||
if (!empty($avances)) {
|
||||
foreach ($avances as $avance) {
|
||||
// Vérifier si l'email n'a pas déjà été envoyé pour cette avance
|
||||
if (!$this->hasEmailBeenSent($avance['avance_id'])) {
|
||||
$this->sendDeadlineAlert($avance, $Products);
|
||||
$this->markEmailAsSent($avance['avance_id']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->response->setJSON([
|
||||
'success' => true,
|
||||
'messages' => 'Vérification des alertes terminée',
|
||||
'alerts_sent' => count($avances)
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
log_message('error', "Erreur vérification deadline: " . $e->getMessage());
|
||||
return $this->response->setJSON([
|
||||
'success' => false,
|
||||
'messages' => 'Erreur lors de la vérification des deadlines'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Envoyer un email d'alerte au DAF et à la Directrice
|
||||
*/
|
||||
private function sendDeadlineAlert($avance, $Products)
|
||||
{
|
||||
try {
|
||||
$email = \Config\Services::email();
|
||||
|
||||
// Configuration email (à adapter selon votre config)
|
||||
$email->setFrom('noreply@yourcompany.com', 'Système de Gestion des Avances');
|
||||
|
||||
// Récupérer les emails du DAF et de la Directrice
|
||||
$recipients = $this->getDAFAndDirectriceEmails($avance['store_id']);
|
||||
$email->setTo($recipients);
|
||||
|
||||
$email->setSubject('⚠️ ALERTE: Avance arrive à échéance dans 3 jours');
|
||||
|
||||
// Récupérer le nom du produit
|
||||
$productName = $Products->getProductNameById($avance['product_id']);
|
||||
|
||||
// Calcul des jours restants
|
||||
$deadline = new \DateTime($avance['deadline']);
|
||||
$today = new \DateTime();
|
||||
$daysRemaining = $today->diff($deadline)->days;
|
||||
|
||||
// Corps de l'email
|
||||
$message = $this->buildEmailMessage($avance, $productName, $daysRemaining);
|
||||
$email->setMessage($message);
|
||||
|
||||
// Envoyer l'email
|
||||
if ($email->send()) {
|
||||
log_message('info', "Email d'alerte envoyé pour l'avance ID: " . $avance['avance_id']);
|
||||
return true;
|
||||
} else {
|
||||
log_message('error', "Échec envoi email pour avance ID: " . $avance['avance_id'] . " - " . $email->printDebugger());
|
||||
return false;
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
log_message('error', "Erreur envoi email alerte: " . $e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupérer les emails du DAF et de la Directrice
|
||||
*/
|
||||
private function getDAFAndDirectriceEmails($store_id)
|
||||
{
|
||||
$User = new User();
|
||||
$emails = [];
|
||||
|
||||
// Récupérer les utilisateurs avec les rôles DAF et Direction pour le store donné
|
||||
$dafUsers = $User->getUsersByRole('DAF', $store_id);
|
||||
$directionUsers = $User->getUsersByRole('Direction', $store_id);
|
||||
|
||||
// Extraire les emails
|
||||
foreach ($dafUsers as $user) {
|
||||
if (!empty($user['email'])) {
|
||||
$emails[] = $user['email'];
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($directionUsers as $user) {
|
||||
if (!empty($user['email'])) {
|
||||
$emails[] = $user['email'];
|
||||
}
|
||||
}
|
||||
|
||||
// Si aucun email trouvé, utiliser des emails par défaut (à configurer)
|
||||
if (empty($emails)) {
|
||||
$emails = [
|
||||
'daf@yourcompany.com',
|
||||
'direction@yourcompany.com'
|
||||
];
|
||||
}
|
||||
|
||||
return array_unique($emails); // Éviter les doublons
|
||||
}
|
||||
|
||||
/**
|
||||
* Construire le message de l'email
|
||||
*/
|
||||
private function buildEmailMessage($avance, $productName, $daysRemaining)
|
||||
{
|
||||
$typeAvance = strtoupper($avance['type_avance']);
|
||||
$deadlineFormatted = date('d/m/Y', strtotime($avance['deadline']));
|
||||
$avanceDateFormatted = date('d/m/Y à H:i', strtotime($avance['avance_date']));
|
||||
$amountDueFormatted = number_format($avance['amount_due'], 0, ',', ' ') . ' FCFA';
|
||||
|
||||
$urgencyClass = $daysRemaining <= 1 ? 'style="color: red; font-weight: bold;"' : '';
|
||||
|
||||
return "
|
||||
<html>
|
||||
<head>
|
||||
<style>
|
||||
.container { font-family: Arial, sans-serif; max-width: 600px; margin: 0 auto; }
|
||||
.header { background-color: #f8f9fa; padding: 20px; text-align: center; border-radius: 5px; }
|
||||
.alert { background-color: #fff3cd; border: 1px solid #ffeaa7; padding: 15px; margin: 20px 0; border-radius: 5px; }
|
||||
.details { background-color: #f8f9fa; padding: 15px; margin: 10px 0; border-radius: 5px; }
|
||||
.urgent { color: #dc3545; font-weight: bold; }
|
||||
.footer { margin-top: 30px; padding: 15px; background-color: #e9ecef; border-radius: 5px; font-size: 12px; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class='container'>
|
||||
<div class='header'>
|
||||
<h2>⚠️ ALERTE DEADLINE AVANCE</h2>
|
||||
</div>
|
||||
|
||||
<div class='alert'>
|
||||
<p><strong " . $urgencyClass . ">Une avance arrive à échéance dans {$daysRemaining} jour(s) !</strong></p>
|
||||
</div>
|
||||
|
||||
<div class='details'>
|
||||
<h3>Détails de l'avance :</h3>
|
||||
<ul>
|
||||
<li><strong>ID Avance :</strong> #{$avance['avance_id']}</li>
|
||||
<li><strong>Type d'avance :</strong> {$typeAvance}</li>
|
||||
<li><strong>Client :</strong> {$avance['customer_name']}</li>
|
||||
<li><strong>Téléphone :</strong> {$avance['customer_phone']}</li>
|
||||
<li><strong>Adresse :</strong> {$avance['customer_address']}</li>
|
||||
<li><strong>CIN :</strong> {$avance['customer_cin']}</li>
|
||||
<li><strong>Produit :</strong> {$productName}</li>
|
||||
<li><strong>Montant restant dû :</strong> <span class='urgent'>{$amountDueFormatted}</span></li>
|
||||
<li><strong>Date avance :</strong> {$avanceDateFormatted}</li>
|
||||
<li><strong>Date limite :</strong> <span class='urgent'>{$deadlineFormatted}</span></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class='alert'>
|
||||
<p><strong>Action requise :</strong></p>
|
||||
<p>Veuillez contacter le client pour régulariser le paiement avant l'échéance ou prendre les mesures appropriées.</p>
|
||||
</div>
|
||||
|
||||
<div class='footer'>
|
||||
<p>Cet email a été généré automatiquement par le système de gestion des avances.</p>
|
||||
<p>Date d'envoi : " . date('d/m/Y à H:i') . "</p>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
";
|
||||
}
|
||||
|
||||
/**
|
||||
* Vérifier si un email a déjà été envoyé pour cette avance
|
||||
*/
|
||||
private function hasEmailBeenSent($avance_id)
|
||||
{
|
||||
$db = \Config\Database::connect();
|
||||
$query = $db->query("SELECT id FROM email_alerts WHERE avance_id = ? AND alert_type = 'deadline_3days'", [$avance_id]);
|
||||
return $query->getNumRows() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Marquer l'email comme envoyé
|
||||
*/
|
||||
private function markEmailAsSent($avance_id)
|
||||
{
|
||||
$db = \Config\Database::connect();
|
||||
$data = [
|
||||
'avance_id' => $avance_id,
|
||||
'alert_type' => 'deadline_3days',
|
||||
'sent_date' => date('Y-m-d H:i:s'),
|
||||
'status' => 'sent'
|
||||
];
|
||||
|
||||
$db->table('email_alerts')->insert($data);
|
||||
}
|
||||
|
||||
public function createAvance()
|
||||
{
|
||||
$this->verifyRole('createAvance');
|
||||
|
||||
if ($this->request->getMethod() !== 'post') {
|
||||
return $this->response->setJSON([
|
||||
'success' => false,
|
||||
'messages' => 'Méthode non autorisée'
|
||||
]);
|
||||
}
|
||||
|
||||
try {
|
||||
$session = session();
|
||||
$users = $session->get('user');
|
||||
|
||||
$Avance = new Avance();
|
||||
$Products = new Products();
|
||||
$Notification = new NotificationController();
|
||||
|
||||
$validation = \Config\Services::validation();
|
||||
$validation->setRules([
|
||||
'customer_name_avance' => 'required|min_length[2]',
|
||||
'customer_phone_avance' => 'required',
|
||||
'customer_address_avance' => 'required',
|
||||
'customer_cin_avance' => 'required',
|
||||
'id_product' => 'required|numeric',
|
||||
'avance_amount' => 'required|numeric|greater_than[0]',
|
||||
'type_avance' => 'required|in_list[terre,mere]'
|
||||
]);
|
||||
|
||||
if (!$validation->withRequest($this->request)->run()) {
|
||||
return $this->response->setJSON([
|
||||
'success' => false,
|
||||
'messages' => 'Données invalides: ' . implode(', ', $validation->getErrors())
|
||||
]);
|
||||
}
|
||||
|
||||
$avance_date = date('Y-m-d H:i:s');
|
||||
|
||||
// Calcul automatique de la deadline selon le type d'avance
|
||||
$type_avance = $this->request->getPost('type_avance');
|
||||
if ($type_avance === 'terre') {
|
||||
$deadline = date('Y-m-d', strtotime($avance_date . ' +15 days'));
|
||||
} elseif ($type_avance === 'mere') {
|
||||
$deadline = date('Y-m-d', strtotime($avance_date . ' +2 months'));
|
||||
} else {
|
||||
$deadline = null; // fallback si jamais
|
||||
}
|
||||
|
||||
$data = [
|
||||
'type_avance' => $type_avance,
|
||||
'customer_name' => $this->request->getPost('customer_name_avance'),
|
||||
'customer_address' => $this->request->getPost('customer_address_avance'),
|
||||
'customer_phone' => $this->request->getPost('customer_phone_avance'),
|
||||
'customer_cin' => $this->request->getPost('customer_cin_avance'),
|
||||
'avance_date' => $avance_date,
|
||||
'deadline' => $deadline,
|
||||
'user_id' => $users['id'],
|
||||
'store_id' => $users['store_id'],
|
||||
'product_id' => (int)$this->request->getPost('id_product'),
|
||||
'gross_amount' => (float)$this->request->getPost('gross_amount'),
|
||||
'avance_amount' => (float)$this->request->getPost('avance_amount'),
|
||||
'amount_due' => (float)$this->request->getPost('amount_due'),
|
||||
'is_order' => 0,
|
||||
'active' => 1,
|
||||
];
|
||||
|
||||
if ($avance_id = $Avance->createAvance($data)) {
|
||||
$Products->update($data['product_id'], ['product_sold' => 1]);
|
||||
|
||||
$Notification->createNotification(
|
||||
'Une nouvelle avance a été créée',
|
||||
"Conseil",
|
||||
(int)$users['store_id'],
|
||||
'avances'
|
||||
);
|
||||
|
||||
return $this->response->setJSON([
|
||||
'success' => true,
|
||||
'messages' => 'Avance créée avec succès !',
|
||||
'avance_id' => $avance_id
|
||||
]);
|
||||
} else {
|
||||
return $this->response->setJSON([
|
||||
'success' => false,
|
||||
'messages' => 'Erreur lors de la création de l\'avance'
|
||||
]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
log_message('error', "Erreur création avance: " . $e->getMessage());
|
||||
return $this->response->setJSON([
|
||||
'success' => false,
|
||||
'messages' => 'Une erreur interne est survenue'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function updateAvance(int $id)
|
||||
{
|
||||
$this->verifyRole('updateAvance');
|
||||
|
||||
if ($this->request->getMethod() !== 'post') {
|
||||
return $this->response->setJSON([
|
||||
'success' => false,
|
||||
'messages' => 'Méthode non autorisée'
|
||||
]);
|
||||
}
|
||||
|
||||
try {
|
||||
$session = session();
|
||||
$users = $session->get('user');
|
||||
|
||||
$Avance = new Avance();
|
||||
$Products = new Products();
|
||||
$Orders = new Orders();
|
||||
$Company = new Company();
|
||||
$Notification = new NotificationController();
|
||||
|
||||
$validation = \Config\Services::validation();
|
||||
$validation->setRules([
|
||||
'customer_name_avance_edit' => 'required|min_length[2]',
|
||||
'customer_phone_avance_edit' => 'required',
|
||||
'customer_address_avance_edit' => 'required',
|
||||
'customer_cin_avance_edit' => 'required',
|
||||
'id_product_edit' => 'required|numeric',
|
||||
'avance_amount_edit' => 'required|numeric|greater_than[0]',
|
||||
'type_avance_edit' => 'required|in_list[terre,mere]'
|
||||
]);
|
||||
|
||||
if (!$validation->withRequest($this->request)->run()) {
|
||||
return $this->response->setJSON([
|
||||
'success' => false,
|
||||
'messages' => 'Données invalides: ' . implode(', ', $validation->getErrors())
|
||||
]);
|
||||
}
|
||||
|
||||
// Récupérer la date de création actuelle de l'avance pour recalculer deadline
|
||||
$currentAvance = $Avance->find($id);
|
||||
if (!$currentAvance) {
|
||||
return $this->response->setJSON([
|
||||
'success' => false,
|
||||
'messages' => 'Avance introuvable.'
|
||||
]);
|
||||
}
|
||||
$avance_date = $currentAvance['avance_date'];
|
||||
|
||||
// Calcul automatique deadline selon le type d'avance
|
||||
$type_avance = $this->request->getPost('type_avance_edit');
|
||||
if ($type_avance === 'terre') {
|
||||
$deadline = date('Y-m-d', strtotime($avance_date . ' +15 days'));
|
||||
} elseif ($type_avance === 'mere') {
|
||||
$deadline = date('Y-m-d', strtotime($avance_date . ' +2 months'));
|
||||
} else {
|
||||
$deadline = null;
|
||||
}
|
||||
|
||||
$data = [
|
||||
'type_avance' => $type_avance,
|
||||
'customer_name' => $this->request->getPost('customer_name_avance_edit'),
|
||||
'customer_address' => $this->request->getPost('customer_address_avance_edit'),
|
||||
'customer_phone' => $this->request->getPost('customer_phone_avance_edit'),
|
||||
'customer_cin' => $this->request->getPost('customer_cin_avance_edit'),
|
||||
'gross_amount' => (float)$this->request->getPost('gross_amount_edit'),
|
||||
'avance_amount' => (float)$this->request->getPost('avance_amount_edit'),
|
||||
'amount_due' => (float)$this->request->getPost('amount_due_edit'),
|
||||
'product_id' => (int)$this->request->getPost('id_product_edit'),
|
||||
'deadline' => $deadline,
|
||||
];
|
||||
|
||||
$amount_due = $data['amount_due'];
|
||||
|
||||
if ($amount_due <= 0) {
|
||||
$bill_no = 'BILPR-' . strtoupper(substr(md5(uniqid(mt_rand(), true)), 0, 4));
|
||||
$company = $Company->getCompanyData(1);
|
||||
|
||||
$service_charge_rate = $company['service_charge_value'] ?? 0;
|
||||
$vat_charge_rate = $company['vat_charge_value'] ?? 0;
|
||||
$gross_amount = $data['gross_amount'];
|
||||
$vat_charge = ($gross_amount / 100) * $vat_charge_rate;
|
||||
|
||||
$order_data = [
|
||||
'bill_no' => $bill_no,
|
||||
'customer_name' => $data['customer_name'],
|
||||
'customer_address' => $data['customer_address'],
|
||||
'customer_phone' => $data['customer_phone'],
|
||||
'customer_cin' => $data['customer_cin'],
|
||||
'gross_amount' => $gross_amount,
|
||||
'net_amount' => $gross_amount,
|
||||
'date_time' => date('Y-m-d H:i:s'),
|
||||
'service_charge_rate' => $service_charge_rate,
|
||||
'vat_charge_rate' => $vat_charge_rate,
|
||||
'vat_charge' => $vat_charge,
|
||||
'discount' => 0,
|
||||
'paid_status' => 1,
|
||||
'user_id' => $users['id'],
|
||||
'store_id' => $users['store_id'],
|
||||
'amount_value' => $gross_amount,
|
||||
'rate_value' => $gross_amount,
|
||||
];
|
||||
|
||||
$product_id = [$data['product_id']];
|
||||
|
||||
if ($Orders->create($order_data, $product_id)) {
|
||||
$Avance->updateAvance($id, ['is_order' => 1]);
|
||||
$Notification->createNotification(
|
||||
'Une avance a été convertie en commande',
|
||||
"Conseil",
|
||||
(int)$users['store_id'],
|
||||
'orders'
|
||||
);
|
||||
|
||||
return $this->response->setJSON([
|
||||
'success' => true,
|
||||
'messages' => 'Avance convertie en commande avec succès.'
|
||||
]);
|
||||
} else {
|
||||
return $this->response->setJSON([
|
||||
'success' => false,
|
||||
'messages' => 'Erreur lors de la conversion de l\'avance en commande'
|
||||
]);
|
||||
}
|
||||
} else {
|
||||
if ($Avance->updateAvance($id, $data)) {
|
||||
return $this->response->setJSON([
|
||||
'success' => true,
|
||||
'messages' => 'Avance mise à jour avec succès.'
|
||||
]);
|
||||
} else {
|
||||
return $this->response->setJSON([
|
||||
'success' => false,
|
||||
'messages' => 'Erreur lors de la mise à jour de l\'avance.'
|
||||
]);
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
log_message('error', "Erreur mise à jour avance: " . $e->getMessage());
|
||||
return $this->response->setJSON([
|
||||
'success' => false,
|
||||
'messages' => 'Une erreur interne est survenue'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function removeAvance()
|
||||
{
|
||||
$this->verifyRole('deleteAvance');
|
||||
|
||||
try {
|
||||
$avance_id = $this->request->getPost('avance_id');
|
||||
$product_id = $this->request->getPost('product_id');
|
||||
|
||||
if (!$avance_id || !$product_id) {
|
||||
return $this->response->setJSON([
|
||||
'success' => false,
|
||||
'messages' => 'Données manquantes pour la suppression'
|
||||
]);
|
||||
}
|
||||
|
||||
$Avance = new Avance();
|
||||
$Products = new Products();
|
||||
|
||||
if ($Avance->removeAvance($avance_id)) {
|
||||
$Products->update($product_id, ['product_sold' => 0]);
|
||||
|
||||
return $this->response->setJSON([
|
||||
'success' => true,
|
||||
'messages' => "Avance supprimée avec succès. Le produit peut être réservé à nouveau."
|
||||
]);
|
||||
} else {
|
||||
return $this->response->setJSON([
|
||||
'success' => false,
|
||||
'messages' => "Erreur lors de la suppression de l'avance"
|
||||
]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
log_message('error', "Erreur suppression avance: " . $e->getMessage());
|
||||
return $this->response->setJSON([
|
||||
'success' => false,
|
||||
'messages' => 'Une erreur interne est survenue'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function fetchSingleAvance($avance_id)
|
||||
{
|
||||
$this->verifyRole('updateAvance');
|
||||
|
||||
try {
|
||||
if (!$avance_id || !is_numeric($avance_id)) {
|
||||
return $this->response->setStatusCode(400)->setJSON([
|
||||
'error' => 'ID d\'avance invalide'
|
||||
]);
|
||||
}
|
||||
|
||||
$avanceModel = new Avance();
|
||||
$data = $avanceModel->fetchSingleAvance($avance_id);
|
||||
|
||||
if (!$data) {
|
||||
return $this->response->setStatusCode(404)->setJSON([
|
||||
'error' => 'Avance non trouvée'
|
||||
]);
|
||||
}
|
||||
|
||||
return $this->response->setJSON($data);
|
||||
} catch (\Exception $e) {
|
||||
log_message('error', "Erreur récupération avance: " . $e->getMessage());
|
||||
return $this->response->setStatusCode(500)->setJSON([
|
||||
'error' => 'Erreur interne lors de la récupération de l\'avance'
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
201
app/Controllers/AvanceControlleur.php
Normal file
201
app/Controllers/AvanceControlleur.php
Normal file
@ -0,0 +1,201 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Models\Products;
|
||||
use App\Models\Avance;
|
||||
|
||||
class AvanceController extends AdminController
|
||||
{
|
||||
private $pageTitle = 'Avances';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->verifyRole('viewAvance');
|
||||
$data['page_title'] = $this->pageTitle;
|
||||
|
||||
return $this->render_template('avances/avance', $data);
|
||||
}
|
||||
|
||||
public function fetchAvanceData()
|
||||
{
|
||||
helper(['url', 'form']);
|
||||
$Avance = new Avance();
|
||||
|
||||
$result = ['data' => []];
|
||||
$data = $Avance->getAvanceData();
|
||||
$session = session();
|
||||
$users = $session->get('user');
|
||||
$isAdmin = in_array($users['group_name'], ['Conseil', 'Direction']);
|
||||
$isCommerciale = in_array($users['group_name'], ['COMMERCIALE']);
|
||||
$isCaissier = in_array($users['group_name'], ['Caissier']);
|
||||
foreach ($data as $key => $value) {
|
||||
$isOwner = $users['id'] === $value['user_id'];
|
||||
$date_time = date('d-m-Y h:i a', strtotime($value['avance_date']));
|
||||
|
||||
// Boutons d’action
|
||||
$buttons = '';
|
||||
if (in_array('updateAvance', $this->permission) && ($isAdmin || $isOwner)) {
|
||||
$buttons .= '<button type="button" class="btn btn-default" onclick="editFunc('. $value['avance_id'] .')">'
|
||||
. '<i class="fa fa-pencil"></i></button>';
|
||||
}
|
||||
if (in_array('deleteAvance', $this->permission) && ($isAdmin || $isOwner)) {
|
||||
$buttons .= ' <button type="button" class="btn btn-danger" onclick="removeFunc('.$value['avance_id'].')"><i class="fa fa-trash"></i></button>';
|
||||
}
|
||||
if (in_array('viewAvance', $this->permission) && !$isAdmin) {
|
||||
$buttons .= ' <a href="#" data-order-id="'.$value['id'].'" class="btn btn-default btn-view" title="Voir"><i class="fa fa-eye"></i></a>';
|
||||
}
|
||||
if ($isAdmin) {
|
||||
$row = [
|
||||
$value['customer_name'],
|
||||
$value['customer_phone'],
|
||||
$value['customer_address'],
|
||||
number_format((int)$value['gross_amount'], 0, ',', ' '),
|
||||
number_format((int)$value['avance_amount'], 0, ',', ' '),
|
||||
$date_time,
|
||||
$buttons,
|
||||
];
|
||||
$result['data'][] = $row;
|
||||
}
|
||||
if ($isCommerciale || $isCaissier) {
|
||||
$row = [
|
||||
$value['avance_id'],
|
||||
number_format((int)$value['avance_amount'], 0, ',', ' '),
|
||||
number_format((int)$value['amount_due'], 0, ',', ' '),
|
||||
$date_time,
|
||||
$buttons,
|
||||
];
|
||||
$result['data'][] = $row;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->response->setJSON($result);
|
||||
}
|
||||
|
||||
public function createAvance()
|
||||
{
|
||||
$this->verifyRole('createAvance');
|
||||
$data['page_title'] = $this->pageTitle;
|
||||
|
||||
$validation = \Config\Services::validation();
|
||||
$products = $this->request->getPost('product');
|
||||
|
||||
// Unicité des produits
|
||||
if ($products !== null && count($products) !== count(array_unique($products))) {
|
||||
return redirect()->back()->withInput()->with('errors', ['product' => 'Chaque produit sélectionné doit être unique.']);
|
||||
}
|
||||
|
||||
// Règles de validation
|
||||
$validation->setRules([
|
||||
'product' => 'required'
|
||||
]);
|
||||
|
||||
$validationData = ['product' => $products];
|
||||
$Avance = new Avance();
|
||||
$Products = new Products();
|
||||
$Notification = New NotificationController();
|
||||
|
||||
if ($this->request->getMethod() === 'post' && $validation->run($validationData)) {
|
||||
$session = session();
|
||||
$users = $session->get('user');
|
||||
|
||||
$data = [
|
||||
'customer_name' => $this->request->getPost('customer_name_avance'),
|
||||
'customer_address' => $this->request->getPost('customer_address_avance'),
|
||||
'customer_phone' => $this->request->getPost('customer_phone_avance'),
|
||||
'customer_cin' => $this->request->getPost('customer_cin_avance'),
|
||||
'avance_date' => date('Y-m-d H:i:s'),
|
||||
'user_id' => $users['id'],
|
||||
'store_id' => $users['store_id'],
|
||||
'product_id' => $this->request->getPost('product_id'),
|
||||
'gross_amount' => (float)$this->request->getPost('gross_amount_avance'),
|
||||
'avance_amount' => (float)$this->request->getPost('avance_amount'),
|
||||
'amount_due' => (float)$this->request->getPost('amount_due'),
|
||||
];
|
||||
$posts = $products;
|
||||
|
||||
if($avance_id = $Avance->createAvance($data)){
|
||||
$Notification->createNotification('Une avance a été créé', "Conseil",$users['store_id'], 'avance');
|
||||
return $this->response->setJSON([
|
||||
'success' => true,
|
||||
'messages' => 'Avance créé avec succès !'
|
||||
]);
|
||||
}
|
||||
else{
|
||||
return $this->response->setJSON([
|
||||
'success' => false,
|
||||
'messages' => 'Une erreur est survenue lors de la création d\une avance !'
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function updateAvance(int $id)
|
||||
{
|
||||
$this->verifyRole('updateAvance');
|
||||
$data['page_title'] = $this->pageTitle;
|
||||
|
||||
$Products = new Products();
|
||||
$Avance = new Avance();
|
||||
|
||||
if ($this->request->getMethod() === 'post') {
|
||||
$data = [
|
||||
'customer_name' => $this->request->getPost('customer_name_avance'),
|
||||
'customer_address'=> $this->request->getPost('customer_address_avance'),
|
||||
'customer_phone' => $this->request->getPost('customer_phone_avance'),
|
||||
'customer_cin' => $this->request->getPost('customer_cin_avance'),
|
||||
'avance_amount' => (float)$this->request->getPost('avance_amount'),
|
||||
'amount_due' => (float)$this->request->getPost('amount_due'),
|
||||
];
|
||||
|
||||
if ($Avance->updates($id, $data)) {
|
||||
session()->setFlashData('success', 'Avance mise à jour avec succès.');
|
||||
} else {
|
||||
session()->setFlashData('errors', 'Une erreur est survenue lors de la mise à jour.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function remove()
|
||||
{
|
||||
$this->verifyRole('deleteAvance');
|
||||
$avance_id = $this->request->getPost('avance_id');
|
||||
$response = [];
|
||||
|
||||
$Avance = new Avance();
|
||||
if ($Avance->remove($avance_id)) {
|
||||
$response['success'] = true;
|
||||
$response['messages'] = "Avance Supprimé avec succès";
|
||||
} else {
|
||||
$response['success'] = false;
|
||||
$response['messages'] = "une erreur est survenue lors de la suppression d'une avance";
|
||||
}
|
||||
return $this->response->setJSON($response);
|
||||
}
|
||||
|
||||
public function fetchSingleAvance($avance_id)
|
||||
{
|
||||
$this->verifyRole('updateAvance');
|
||||
|
||||
try {
|
||||
$avanceModel = new Avance();
|
||||
|
||||
$data = $avanceModel->fetchSingleAvance($avance_id);
|
||||
|
||||
return $this->response->setJSON($data);
|
||||
}
|
||||
catch (\Throwable $th) {
|
||||
log_message('error', "Erreur lors de la récupération d'une avance: " . $th->getMessage());
|
||||
|
||||
return $this->response
|
||||
->setStatusCode(500)
|
||||
->setJSON(['error' => 'Une erreur interne est survenue. Lors de la création d\'une avance']);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
22
app/Controllers/BaseController.php
Normal file
22
app/Controllers/BaseController.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
namespace App\Controllers;
|
||||
|
||||
use CodeIgniter\Controller;
|
||||
|
||||
class BaseController extends Controller
|
||||
{
|
||||
protected $helpers = [];
|
||||
|
||||
public function initController(\CodeIgniter\HTTP\RequestInterface $request,
|
||||
\CodeIgniter\HTTP\ResponseInterface $response,
|
||||
\Psr\Log\LoggerInterface $logger)
|
||||
{
|
||||
parent::initController($request, $response, $logger);
|
||||
|
||||
helper('alerts');
|
||||
|
||||
if (function_exists('checkDeadlineAlerts')) {
|
||||
checkDeadlineAlerts();
|
||||
}
|
||||
}
|
||||
}
|
||||
203
app/Controllers/BrandController.php
Normal file
203
app/Controllers/BrandController.php
Normal file
@ -0,0 +1,203 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Models\Brands;
|
||||
|
||||
class BrandController extends AdminController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
// Assuming permission is being set from a session
|
||||
helper(['form', 'url']);
|
||||
}
|
||||
|
||||
private $pageTitle = 'Brands';
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->verifyRole('viewBrand');
|
||||
$data['page_title'] = $this->pageTitle;
|
||||
|
||||
$Brands = new Brands();
|
||||
|
||||
$result = $Brands->getBrandData();
|
||||
$data['results'] = $result;
|
||||
// die(var_dump($data));
|
||||
return $this->render_template('brands/index', $data);
|
||||
}
|
||||
|
||||
public function fetchBrandData()
|
||||
{
|
||||
$result = ['data' => []];
|
||||
|
||||
// Load the model
|
||||
$brandModel = new Brands();
|
||||
$data = $brandModel->getBrandData();
|
||||
|
||||
// Loop through the data
|
||||
foreach ($data as $key => $value) {
|
||||
// Action buttons
|
||||
$buttons = '';
|
||||
|
||||
// Check permissions
|
||||
if (in_array('viewBrand', $this->permission)) {
|
||||
$buttons .= '<button type="button" class="btn btn-default" onclick="editBrand(' . $value['id'] . ')" data-bs-toggle="modal" data-bs-target="#editBrandModal">
|
||||
<i class="fa fa-pencil"></i>
|
||||
</button>';
|
||||
}
|
||||
|
||||
if (in_array('deleteBrand', $this->permission)) {
|
||||
$buttons .= ' <button type="button" class="btn btn-danger" onclick="removeBrand(' . $value['id'] . ')" data-bs-toggle="modal" data-bs-target="#removeBrandModal">
|
||||
<i class="fa fa-trash"></i>
|
||||
</button>';
|
||||
}
|
||||
|
||||
// Status
|
||||
$status = ($value['active'] == 1)
|
||||
? '<span class="label label-success">Active</span>'
|
||||
: '<span class="label label-warning">Inactive</span>';
|
||||
|
||||
// Prepare the data for DataTable
|
||||
$result['data'][$key] = [
|
||||
$value['name'],
|
||||
$status,
|
||||
$buttons,
|
||||
];
|
||||
}
|
||||
|
||||
// Return as JSON response
|
||||
return $this->response->setJSON($result);
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$this->verifyRole('createBrand');
|
||||
|
||||
$response = [];
|
||||
|
||||
// Set validation rules
|
||||
$validation = \Config\Services::validation();
|
||||
|
||||
$validation->setRules([
|
||||
'brand_name' => 'required',
|
||||
'active' => 'required',
|
||||
]);
|
||||
$validationData = [
|
||||
'brand_name' => $this->request->getPost('brand_name'),
|
||||
'active' => $this->request->getPost('active'),
|
||||
];
|
||||
|
||||
$Brands = new Brands();
|
||||
|
||||
if ($validation->run($validationData)) {
|
||||
$data = [
|
||||
'name' => $this->request->getPost('brand_name'),
|
||||
'active' => $this->request->getPost('active'),
|
||||
];
|
||||
|
||||
|
||||
if ($Brands->create($data)) {
|
||||
$response['success'] = true;
|
||||
$response['messages'] = 'Créé avec succès';
|
||||
} else {
|
||||
$response['success'] = false;
|
||||
$response['messages'] = 'Erreur dans la base de données lors de la création des informations sur la marque';
|
||||
}
|
||||
|
||||
} else {
|
||||
$response['success'] = false;
|
||||
$response['messages'] = $validation->getErrors();
|
||||
}
|
||||
|
||||
return $this->response->setJSON($response);
|
||||
|
||||
}
|
||||
|
||||
public function fetchBrandDataById(int $id)
|
||||
{
|
||||
$Brands = new Brands();
|
||||
if ($id) {
|
||||
$data = $Brands->getBrandData($id);
|
||||
return $this->response->setJSON($data);
|
||||
}
|
||||
}
|
||||
|
||||
public function update(int $id)
|
||||
{
|
||||
$this->verifyRole('updateBrand');
|
||||
|
||||
$response = [];
|
||||
|
||||
if ($id) {
|
||||
// Set validation rules
|
||||
$validation = \Config\Services::validation();
|
||||
|
||||
$validation->setRules([
|
||||
'edit_brand_name' => 'required',
|
||||
'edit_active' => 'required',
|
||||
]);
|
||||
|
||||
$validationData = [
|
||||
'edit_brand_name' => $this->request->getPost('edit_brand_name'),
|
||||
'edit_active' => $this->request->getPost('edit_active'),
|
||||
];
|
||||
|
||||
$Brands = new Brands();
|
||||
|
||||
if ($validation->run($validationData)) {
|
||||
$data = [
|
||||
'name' => $this->request->getPost('edit_brand_name'),
|
||||
'active' => $this->request->getPost('edit_active'),
|
||||
];
|
||||
|
||||
if ($Brands->updateBrand($data, $id)) {
|
||||
$response['success'] = true;
|
||||
$response['messages'] = 'Mis à jour avec succès';
|
||||
} else {
|
||||
$response['success'] = false;
|
||||
$response['messages'] = 'Erreur dans la base de données lors de la mise à jour des informations sur la marque';
|
||||
}
|
||||
|
||||
} else {
|
||||
$response['success'] = false;
|
||||
$response['messages'] = $validation->getErrors();
|
||||
}
|
||||
|
||||
} else {
|
||||
$response['success'] = false;
|
||||
$response['messages'] = 'Erreur, veuillez actualiser la page à nouveau !!';
|
||||
}
|
||||
|
||||
return $this->response->setJSON($response);
|
||||
|
||||
}
|
||||
|
||||
public function remove()
|
||||
{
|
||||
$this->verifyRole('deleteBrand');
|
||||
$response = [];
|
||||
|
||||
$brand_id = $this->request->getPost('brand_id');
|
||||
|
||||
if ($brand_id) {
|
||||
$Brands = new Brands();
|
||||
|
||||
if ($Brands->delete($brand_id)) {
|
||||
$response['success'] = true;
|
||||
$response['messages'] = "Supprimé avec succès";
|
||||
} else {
|
||||
$response['success'] = false;
|
||||
$response['messages'] = "Erreur dans la base de données lors de la suppression des informations sur la marque";
|
||||
}
|
||||
|
||||
} else {
|
||||
$response['success'] = false;
|
||||
$response['messages'] = "Référez à nouveau la page !!";
|
||||
}
|
||||
|
||||
return $this->response->setJSON($response);
|
||||
}
|
||||
|
||||
}
|
||||
43
app/Controllers/CaisseController.php
Normal file
43
app/Controllers/CaisseController.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Controllers\AdminController;
|
||||
use App\Models\Caisse;
|
||||
use App\Models\Orders;
|
||||
use CodeIgniter\Controller;
|
||||
class CaisseController extends AdminController{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function createCaisse(){
|
||||
$orderModel = new Orders();
|
||||
$paymentData = $orderModel->getPaymentModes();
|
||||
|
||||
// Initialisation des totaux avec 0 au cas où il n'y aurait pas de données
|
||||
$total = isset($paymentData->total) ? $paymentData->total : 0;
|
||||
$total_mvola1 = isset($paymentData->total_mvola1) ? $paymentData->total_mvola1 : 0;
|
||||
$total_mvola2 = isset($paymentData->total_mvola2) ? $paymentData->total_mvola2 : 0;
|
||||
$total_espece1 = isset($paymentData->total_espece1) ? $paymentData->total_espece1 : 0;
|
||||
$total_espece2 = isset($paymentData->total_espece2) ? $paymentData->total_espece2 : 0;
|
||||
$total_virement_bancaire1 = isset($paymentData->total_virement_bancaire1) ? $paymentData->total_virement_bancaire1 : 0;
|
||||
$total_virement_bancaire2 = isset($paymentData->total_virement_bancaire2) ? $paymentData->total_virement_bancaire2 : 0;
|
||||
// Calcul des totaux pour chaque mode de paiement
|
||||
$total_mvola = $total_mvola1 + $total_mvola2;
|
||||
$total_espece = $total_espece1 + $total_espece2;
|
||||
$total_virement_bancaire = $total_virement_bancaire1 + $total_virement_bancaire2;
|
||||
// Fusion des données dans la variable $data
|
||||
$data = [
|
||||
'total' => $total,
|
||||
'total_mvola' => $total_mvola,
|
||||
'total_espece' => $total_espece,
|
||||
'total_banque' => $total_virement_bancaire,
|
||||
];
|
||||
$caisse = new Caisse();
|
||||
if($data) {
|
||||
return $caisse->updateCaisse($data);
|
||||
}
|
||||
}
|
||||
}
|
||||
15
app/Controllers/CashController.php
Normal file
15
app/Controllers/CashController.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
namespace App\Controllers;
|
||||
|
||||
class CashController extends AdminController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function addInCash()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
187
app/Controllers/CategoryController.php
Normal file
187
app/Controllers/CategoryController.php
Normal file
@ -0,0 +1,187 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Models\Category;
|
||||
|
||||
class CategoryController extends AdminController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
// Assuming permission is being set from a session
|
||||
helper(['form', 'url']);
|
||||
}
|
||||
|
||||
private $pageTitle = 'Categorie';
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->verifyRole('viewCategory');
|
||||
$data['page_title'] = $this->pageTitle;
|
||||
|
||||
return $this->render_template('category/index', $data);
|
||||
}
|
||||
|
||||
public function fetchCategoryData()
|
||||
{
|
||||
// Prepare the response array
|
||||
$result = ['data' => []];
|
||||
$Category = new Category();
|
||||
// Get category data
|
||||
$data = $Category->getCategoryData(); // Make sure this function exists in your CategoryModel
|
||||
|
||||
// Iterate through each category and build the response
|
||||
foreach ($data as $key => $value) {
|
||||
|
||||
// Initialize button HTML
|
||||
$buttons = '';
|
||||
|
||||
// Check if the user has permission to update
|
||||
if (in_array('updateCategory', $this->permission)) {
|
||||
$buttons .= '<button type="button" class="btn btn-default" onclick="editFunc(' . $value['id'] . ')" data-toggle="modal" data-target="#editModal"><i class="fa fa-pencil"></i></button>';
|
||||
}
|
||||
|
||||
// Check if the user has permission to delete
|
||||
if (in_array('deleteCategory', $this->permission)) {
|
||||
$buttons .= ' <button type="button" class="btn btn-default" onclick="removeFunc(' . $value['id'] . ')" data-toggle="modal" data-target="#removeModal"><i class="fa fa-trash"></i></button>';
|
||||
}
|
||||
|
||||
// Determine the status label
|
||||
$status = ($value['active'] == 1) ? '<span class="label label-success">Active</span>' : '<span class="label label-warning">Inactive</span>';
|
||||
|
||||
// Add data to the result array
|
||||
$result['data'][] = [
|
||||
$value['name'],
|
||||
$status,
|
||||
$buttons
|
||||
];
|
||||
}
|
||||
|
||||
// Return the result as JSON
|
||||
return $this->response->setJSON($result);
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$this->verifyRole('createCategory');
|
||||
$response = [];
|
||||
|
||||
// Set validation rules
|
||||
$validation = \Config\Services::validation();
|
||||
|
||||
$validation->setRules([
|
||||
'category_name' => 'required',
|
||||
'active' => 'required',
|
||||
]);
|
||||
|
||||
$validationData = [
|
||||
'category_name' => $this->request->getPost('category_name'),
|
||||
'active' => $this->request->getPost('active'),
|
||||
];
|
||||
|
||||
$Category = new Category();
|
||||
|
||||
if ($validation->run($validationData)) {
|
||||
$data = [
|
||||
'name' => $this->request->getPost('category_name'),
|
||||
'active' => $this->request->getPost('active'),
|
||||
];
|
||||
|
||||
if ($Category->create($data)) {
|
||||
$response['success'] = true;
|
||||
$response['messages'] = 'Créé avec succès';
|
||||
} else {
|
||||
$response['success'] = false;
|
||||
$response['messages'] = 'Erreur dans la base de données lors de la création des informations sur la marque';
|
||||
}
|
||||
|
||||
} else {
|
||||
$response['success'] = false;
|
||||
$response['messages'] = $validation->getErrors();
|
||||
}
|
||||
return $this->response->setJSON($response);
|
||||
}
|
||||
|
||||
public function fetchCategoryDataById(int $id)
|
||||
{
|
||||
if ($id) {
|
||||
$Category = new Category();
|
||||
$data = $Category->getCategoryData($id);
|
||||
return $this->response->setJSON($data);
|
||||
}
|
||||
}
|
||||
|
||||
public function update(int $id)
|
||||
{
|
||||
$this->verifyRole('updateCategory');
|
||||
$response = [];
|
||||
|
||||
if ($id) {
|
||||
// Set validation rules
|
||||
$validation = \Config\Services::validation();
|
||||
|
||||
$validation->setRules([
|
||||
'edit_category_name' => 'required',
|
||||
'edit_active' => 'required',
|
||||
]);
|
||||
|
||||
$validationData = [
|
||||
'edit_category_name' => $this->request->getPost('edit_category_name'),
|
||||
'edit_active' => $this->request->getPost('edit_active'),
|
||||
];
|
||||
|
||||
$Category = new Category();
|
||||
|
||||
if ($validation->run($validationData)) {
|
||||
$data = [
|
||||
'name' => $this->request->getPost('edit_category_name'),
|
||||
'active' => $this->request->getPost('edit_active'),
|
||||
];
|
||||
|
||||
if ($Category->updateCategory($data, $id)) {
|
||||
$response['success'] = true;
|
||||
$response['messages'] = 'Mis à jour avec succès';
|
||||
}
|
||||
else {
|
||||
$response['success'] = false;
|
||||
$response['messages'] = 'Erreur dans la base de données lors de la mise à jour des informations sur la marque';
|
||||
}
|
||||
|
||||
} else {
|
||||
$response['success'] = false;
|
||||
$response['messages'] = $validation->getErrors();
|
||||
}
|
||||
|
||||
} else {
|
||||
$response['success'] = false;
|
||||
$response['messages'] = 'Erreur, veuillez actualiser la page à nouveau !!';
|
||||
}
|
||||
return $this->response->setJSON($response);
|
||||
}
|
||||
|
||||
public function remove()
|
||||
{
|
||||
$this->verifyRole('deleteCategory');
|
||||
$category_id = $this->request->getPost('category_id');
|
||||
|
||||
$response = [];
|
||||
|
||||
if ($category_id) {
|
||||
$Category = new Category();
|
||||
|
||||
if ($Category->remove($category_id)) {
|
||||
$response['success'] = true;
|
||||
$response['messages'] = "Supprimé avec succès";
|
||||
} else {
|
||||
$response['success'] = false;
|
||||
$response['messages'] = "Erreur dans la base de données lors de la suppression des informations sur la marque";
|
||||
}
|
||||
|
||||
} else {
|
||||
$response['success'] = false;
|
||||
$response['messages'] = "Erreur, veuillez actualiser la page à nouveau !!";
|
||||
}
|
||||
return $this->response->setJSON($response);
|
||||
}
|
||||
}
|
||||
68
app/Controllers/CompanyController.php
Normal file
68
app/Controllers/CompanyController.php
Normal file
@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Models\Company;
|
||||
|
||||
class CompanyController extends AdminController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
private $pageTitle = 'Company';
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->verifyRole('updateCompany');
|
||||
|
||||
// Validation rules
|
||||
$validation = \Config\Services::validation();
|
||||
$validation->setRules([
|
||||
'company_name' => 'trim|required',
|
||||
'service_charge_value' => 'trim|integer',
|
||||
'vat_charge_value' => 'trim|integer',
|
||||
'address' => 'trim|required',
|
||||
'message' => 'trim|required',
|
||||
]);
|
||||
|
||||
$Company = new Company();
|
||||
// die(var_dump($validation->getErrors()));
|
||||
if ($this->request->getMethod() == 'post' && $validation->withRequest($this->request)->run()) {
|
||||
// If the form is valid
|
||||
$data = [
|
||||
'company_name' => $this->request->getPost('company_name'),
|
||||
'service_charge_value' => $this->request->getPost('service_charge_value'),
|
||||
'vat_charge_value' => $this->request->getPost('vat_charge_value'),
|
||||
'address' => $this->request->getPost('address'),
|
||||
'phone' => $this->request->getPost('phone'),
|
||||
'phone2' => $this->request->getPost('phone2'),
|
||||
'NIF' => $this->request->getPost('nif'),
|
||||
'STAT' => $this->request->getPost('stat'),
|
||||
'country' => $this->request->getPost('country'),
|
||||
'message' => $this->request->getPost('message'),
|
||||
'currency' => $this->request->getPost('currency'),
|
||||
];
|
||||
|
||||
if ($Company->updateCompany($data, 1)) {
|
||||
session()->setFlashdata('success', 'Successfully updated');
|
||||
return redirect()->to('/company');
|
||||
} else {
|
||||
session()->setFlashdata('errors', 'Error occurred!');
|
||||
return redirect()->to('/company/index');
|
||||
}
|
||||
} else {
|
||||
// If the form is invalid
|
||||
$data = [
|
||||
'currency_symbols' => $this->currency(),
|
||||
'company_data' => $Company->getCompanyData(1),
|
||||
'page_title' => $this->pageTitle,
|
||||
'validation_errors' => $validation->getErrors() // Pass the Validation object
|
||||
];
|
||||
|
||||
return $this->render_template('company/index', $data);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
189
app/Controllers/Dashboard.php
Normal file
189
app/Controllers/Dashboard.php
Normal file
@ -0,0 +1,189 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Models\Avance;
|
||||
use App\Models\Brands;
|
||||
use App\Models\Orders;
|
||||
use App\Models\Products;
|
||||
use App\Models\Stores;
|
||||
use App\Models\Users;
|
||||
use App\Models\Recouvrement;
|
||||
use App\Models\SortieCaisse;
|
||||
class Dashboard extends AdminController
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$productModel = new Products();
|
||||
$orderModel = new Orders();
|
||||
$userModel = new Users();
|
||||
$storeModel = new Stores();
|
||||
$Brancds = new Brands();
|
||||
$allUsers = $userModel->getUserData();
|
||||
$orderPaid = $orderModel->getPaidOrderData();
|
||||
$paymentData = $orderModel->getPaymentModes();
|
||||
$Recouvrement = new Recouvrement();
|
||||
$totalRecouvrement = $Recouvrement->getTotalRecouvrements();
|
||||
$sortieCaisse = new SortieCaisse();
|
||||
$total_sortie_caisse = $sortieCaisse->getTotalSortieCaisse();
|
||||
$total_sortie_caisse1= $total_sortie_caisse->mr;
|
||||
// dd($totalRecouvrement);
|
||||
$total_recouvrement_me = $totalRecouvrement->me;
|
||||
$total_recouvrement_bm = $totalRecouvrement->bm;
|
||||
$total_recouvrement_be = $totalRecouvrement->be;
|
||||
$total_recouvrement_mb = $totalRecouvrement->mb;
|
||||
// total avance
|
||||
$Avance = new Avance();
|
||||
$totalAvance = $Avance->getTotalAvance();
|
||||
$total_avance = $totalAvance->ta;
|
||||
// Initialisation des totaux avec 0 au cas où il n'y aurait pas de données
|
||||
$total = isset($paymentData->total) ? $paymentData->total : 0;
|
||||
$total_mvola1 = isset($paymentData->total_mvola1) ? $paymentData->total_mvola1 : 0;
|
||||
$total_mvola2 = isset($paymentData->total_mvola2) ? $paymentData->total_mvola2 : 0;
|
||||
$total_espece1 = isset($paymentData->total_espece1) ? $paymentData->total_espece1 : 0;
|
||||
$total_espece2 = isset($paymentData->total_espece2) ? $paymentData->total_espece2 : 0;
|
||||
$total_virement_bancaire1 = isset($paymentData->total_virement_bancaire1) ? $paymentData->total_virement_bancaire1 : 0;
|
||||
$total_virement_bancaire2 = isset($paymentData->total_virement_bancaire2) ? $paymentData->total_virement_bancaire2 : 0;
|
||||
|
||||
$total_mvola = $total_mvola1 + $total_mvola2;
|
||||
$total_mvola1 = $total_mvola - $total_recouvrement_me - $total_recouvrement_mb + $total_recouvrement_bm;
|
||||
|
||||
$total_espece = $total_espece1 + $total_espece2;
|
||||
$total_espece1 = $total_espece + $total_recouvrement_me + $total_recouvrement_be - $total_sortie_caisse1 + $total_avance;
|
||||
|
||||
//die("Test Stephane " . $total_recouvrement_me);
|
||||
$total_virement_bancaire = $total_virement_bancaire1 + $total_virement_bancaire2;
|
||||
$total_virement_bancaire1 = $total_virement_bancaire - $total_recouvrement_be -$total_recouvrement_bm + $total_recouvrement_mb;
|
||||
|
||||
// check avance expired
|
||||
$avance = new Avance();
|
||||
$avance->checkExpiredAvance();
|
||||
|
||||
$data = [
|
||||
'total' => $total,
|
||||
'total_mvola' => $total_mvola1,
|
||||
'total_espece' => $total_espece1,
|
||||
'total_virement_bancaire' => $total_virement_bancaire1,
|
||||
'user_permission' => $this->permission,
|
||||
|
||||
];
|
||||
|
||||
$data['total_products'] = $productModel->countTotalProducts();
|
||||
$data['total_paid_orders'] = $orderModel->countTotalPaidOrders();
|
||||
$data['total_users'] = $userModel->countTotalUsers();
|
||||
$data['total_stores'] = $storeModel->countTotalStores();
|
||||
|
||||
|
||||
$newData = [];
|
||||
for ($i=0; $i < count($orderPaid); $i++) {
|
||||
$transitionData = [];
|
||||
for ($k=0; $k < count($allUsers); $k++) {
|
||||
if ($allUsers[$k]['id'] == $orderPaid[$i]['user_id']) {
|
||||
$transitionData2 = [
|
||||
'userId' => $allUsers[$k]['id'],
|
||||
'userName' => $allUsers[$k]['username'],
|
||||
'billId' => $orderPaid[$i]['id'],
|
||||
'billNo' => $orderPaid[$i]['bill_no'],
|
||||
'dateVente' => $orderPaid[$i]['date_time'],
|
||||
'montantNet' => $orderPaid[$i]['net_amount'],
|
||||
];
|
||||
$transitionData[] = $transitionData2;
|
||||
}
|
||||
}
|
||||
$newData[] = $transitionData;
|
||||
}
|
||||
|
||||
//data for the camember in dashboard
|
||||
$totalStoreOrder = $orderModel->getTotalOrderPerStore();
|
||||
$totalOrders = $orderModel->getTotalOrders();
|
||||
$totalOrdersCount = (int) $totalOrders->total_orders;
|
||||
if($totalOrdersCount>0){
|
||||
foreach ($totalStoreOrder as $totalOrdersInStore) {
|
||||
$storeList = $storeModel->getStoreById($totalOrdersInStore->store_id);
|
||||
$labelStore[] = $storeList->name ?? 'Inconnu';
|
||||
$totalPerStore[] = ((int)$totalOrdersInStore->total / $totalOrdersCount) * 100;
|
||||
}
|
||||
}
|
||||
else{
|
||||
$labelStore[] = "zéro vente";
|
||||
$totalPerStore[] = 0;
|
||||
}
|
||||
$data['labelStore'] = json_encode($labelStore);
|
||||
$data['totalPerStore'] = json_encode($totalPerStore);
|
||||
|
||||
// filter to keep non empty array
|
||||
$filteredArray = array_filter($newData, function($item) {
|
||||
return !empty($item); // Keep only non-empty arrays
|
||||
});
|
||||
|
||||
// Re-index the array (optional, if you want sequential keys)
|
||||
$userWhoSoldProducts = array_values($filteredArray);
|
||||
|
||||
// Count occurrences of each userId
|
||||
$userIdCounts = array_reduce($userWhoSoldProducts, function($carry, $item) {
|
||||
$userId = $item[0]['userId'];
|
||||
if (!isset($carry[$userId])) {
|
||||
$carry[$userId] = 0;
|
||||
}
|
||||
$carry[$userId]++;
|
||||
return $carry;
|
||||
}, []);
|
||||
|
||||
$countId = [];
|
||||
foreach ($userIdCounts as $key => $value) {
|
||||
$countId[] = $key;
|
||||
}
|
||||
|
||||
$data['count_id'] = $countId;
|
||||
// Check if the user is an Conseil
|
||||
$session = session();
|
||||
$user_id = $session->get('user');
|
||||
$data['is_admin'] = false;
|
||||
$data['isCommercial'] = false;
|
||||
$data['isChef'] = false;
|
||||
$data['isCaissier'] = false;
|
||||
$data['isMecanicien'] = false;
|
||||
if ($user_id['group_name'] == "Direction" || $user_id['group_name'] == "Conseil") {
|
||||
$data['is_admin'] = true;
|
||||
}
|
||||
|
||||
$data['user_order'] = [];
|
||||
|
||||
if ($user_id['group_name'] == \strtoupper("commerciale")) {
|
||||
$data['isCommercial'] = true;
|
||||
$data['user_order'] = json_encode($orderModel->getSingleStat($user_id['id']), JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP);
|
||||
}
|
||||
if ($user_id['group_name'] == "Cheffe d'Agence") {
|
||||
$data['isChef'] = true;
|
||||
}
|
||||
if ($user_id['group_name'] == "Caissière") {
|
||||
$data['isCaissier'] = true;
|
||||
}
|
||||
if ($user_id['group_name'] == "MECANICIEN") {
|
||||
$data['isMecanicien'] = true;
|
||||
}
|
||||
$data['page_title'] = 'Dashboard';
|
||||
$data['marques_total'] = json_encode($orderModel->getTotalProductvente());
|
||||
$data['marques'] = json_encode($Brancds->getName());
|
||||
$Orders = new Orders();
|
||||
$Products = new Products();
|
||||
$Stores = new Stores();
|
||||
$productVente = $Orders->getTotalProductvente();
|
||||
$produitStock = $Products->getProductData();
|
||||
$stor = $Stores->getActiveStore();
|
||||
|
||||
$data['ventes'] = \json_encode($productVente);
|
||||
$data['stock'] = \json_encode($produitStock);
|
||||
$data['stores'] = $stor;
|
||||
|
||||
// Load the dashboard view with the data
|
||||
return $this->render_template('dashboard', $data);
|
||||
}
|
||||
|
||||
}
|
||||
174
app/Controllers/GroupController.php
Normal file
174
app/Controllers/GroupController.php
Normal file
@ -0,0 +1,174 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Models\Groups;
|
||||
|
||||
class GroupController extends AdminController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
// Assuming permission is being set from a session
|
||||
helper(['form', 'url']);
|
||||
}
|
||||
|
||||
private $pageTitle = 'Groups';
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->verifyRole('viewGroup');
|
||||
$data['page_title'] = $this->pageTitle;
|
||||
|
||||
$Groups = new Groups();
|
||||
$data['groups_data'] = $Groups->getGroupData();
|
||||
|
||||
return $this->render_template('groups/index', $data);
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$this->verifyRole('createGroup');
|
||||
$data['page_title'] = $this->pageTitle;
|
||||
|
||||
$validation = \Config\Services::validation();
|
||||
|
||||
// Set validation rules
|
||||
$validation->setRules([
|
||||
'group_name' => [
|
||||
'label' => 'Group name',
|
||||
'rules' => 'required',
|
||||
'errors' => [
|
||||
'required' => 'The {field} field is required.'
|
||||
]
|
||||
]
|
||||
]);
|
||||
|
||||
// Check if form validation is successful
|
||||
if ($this->request->getMethod() == 'post') {
|
||||
|
||||
if ($validation->withRequest($this->request)->run()) {
|
||||
|
||||
$permission = serialize($this->request->getPost('permission'));
|
||||
$data = [
|
||||
'group_name' => $this->request->getPost('group_name'),
|
||||
'permission' => $permission
|
||||
];
|
||||
|
||||
$groupsModel = new Groups(); // Load Groups model
|
||||
$create = $groupsModel->createGroup($data);
|
||||
// die(var_dump($create));
|
||||
|
||||
if ($create) {
|
||||
session()->setFlashdata('success', 'Creation réussie');
|
||||
return redirect()->to('/groups');
|
||||
} else {
|
||||
session()->setFlashdata('errors', 'Une erreur est survenue !!');
|
||||
return redirect()->to('/groups/create');
|
||||
}
|
||||
} else {
|
||||
// If validation fails, load the form with validation errors
|
||||
$data['validation'] = $validation;
|
||||
|
||||
return $this->render_template('groups/create', $data); // Render the create view
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
return $this->render_template('groups/create', $data); // Render the create view
|
||||
}
|
||||
}
|
||||
|
||||
public function edit($id = null)
|
||||
{
|
||||
$this->verifyRole('updateGroup');
|
||||
$data['page_title'] = $this->pageTitle;
|
||||
|
||||
$groupsModel = new Groups();
|
||||
|
||||
if ($id) {
|
||||
// Set validation rules
|
||||
$validation = \Config\Services::validation();
|
||||
$validation->setRules([
|
||||
'group_name' => 'required',
|
||||
]);
|
||||
|
||||
if ($this->request->getMethod() === 'post') {
|
||||
|
||||
if ($validation->withRequest($this->request)->run()) {
|
||||
// Validation passed
|
||||
$permission = serialize($this->request->getPost('permission'));
|
||||
|
||||
$data = [
|
||||
'group_name' => $this->request->getPost('group_name'),
|
||||
'permission' => $permission,
|
||||
];
|
||||
// die(var_dump($groupsModel->editGroup($data, $id)));
|
||||
// Update group
|
||||
if ($groupsModel->editGroup($data, $id)) {
|
||||
session()->setFlashdata('success', 'Mise à jour réussie');
|
||||
return redirect()->to('/groups');
|
||||
} else {
|
||||
session()->setFlashdata('errors', 'Une erreur est survenue !!');
|
||||
return redirect()->to("/groups/edit/{$id}");
|
||||
}
|
||||
} else {
|
||||
// If validation fails, load the form with validation errors
|
||||
$data['validation'] = $validation;
|
||||
|
||||
return $this->render_template('groups/create', $data); // Render the create view
|
||||
}
|
||||
|
||||
} else {
|
||||
// Validation failed or no POST request
|
||||
$groupData = $groupsModel->find($id); // Fetch group data
|
||||
if (!$groupData) {
|
||||
session()->setFlashdata('errors', 'Group pas trouver!');
|
||||
return redirect()->to('/groups');
|
||||
}
|
||||
|
||||
$data['group_data'] = $groupData;
|
||||
// die(var_dump($data));
|
||||
return $this->render_template('groups/edit', $data);
|
||||
}
|
||||
} else {
|
||||
session()->setFlashdata('errors', 'Group ID ne correspond pas!');
|
||||
return redirect()->to('/groups');
|
||||
}
|
||||
}
|
||||
|
||||
public function delete(int $id = null)
|
||||
{
|
||||
$this->verifyRole('deleteGroup');
|
||||
$data['page_title'] = $this->pageTitle;
|
||||
$groupsModel = new Groups();
|
||||
|
||||
if ($id) {
|
||||
if ($this->request->getMethod() === 'post' && $this->request->getPost('confirm')) {
|
||||
// Check if the group exists in the user group
|
||||
$check = $groupsModel->existInUserGroup($id);
|
||||
if ($check) {
|
||||
session()->setFlashdata('error', 'Group exists in the users');
|
||||
return redirect()->to('/groups');
|
||||
} else {
|
||||
// Delete group
|
||||
if ($groupsModel->delete($id)) {
|
||||
session()->setFlashdata('success', 'Successfully removed');
|
||||
return redirect()->to('/groups');
|
||||
} else {
|
||||
session()->setFlashdata('error', 'Error occurred!!');
|
||||
return redirect()->to("/groups/delete/{$id}");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Show confirmation view
|
||||
$data['id'] = $id;
|
||||
return $this->render_template('groups/delete', $data);
|
||||
}
|
||||
} else {
|
||||
session()->setFlashdata('error', 'Invalid Group ID!');
|
||||
return redirect()->to('/groups');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
368
app/Controllers/MecanicienController.php
Normal file
368
app/Controllers/MecanicienController.php
Normal file
@ -0,0 +1,368 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Models\Mecanicien;
|
||||
use App\Models\Products;
|
||||
use App\Models\Users;
|
||||
|
||||
class MecanicienController extends AdminController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
private $pageTitle = 'Mécanicien';
|
||||
|
||||
public function index()
|
||||
{
|
||||
$data['page_title'] = $this->pageTitle;
|
||||
|
||||
$session = session();
|
||||
$user_id = $session->get('user');
|
||||
// if($user_id CONTAINS MECANICIEN)
|
||||
// is mecanicien true
|
||||
$data['id'] = $user_id['id'];
|
||||
$Products = new Products();
|
||||
$Users = new Users();
|
||||
|
||||
$data['moto'] = $Products->getActiveProductData();
|
||||
$data['users'] = $Users->getUsers();
|
||||
|
||||
return $this->render_template('mecanicien/index', $data);
|
||||
}
|
||||
|
||||
public function fetchmecanicienSingle($id)
|
||||
{
|
||||
// die(var_dump($id));
|
||||
if ($id) {
|
||||
$Mecanicien = new Mecanicien();
|
||||
|
||||
$data = $Mecanicien->getReparationSingle($id);
|
||||
echo json_encode($data);
|
||||
}
|
||||
}
|
||||
|
||||
public function fetchMecanicien()
|
||||
{
|
||||
$Mecanicien = new Mecanicien();
|
||||
$session = session();
|
||||
$user_id = $session->get('user');
|
||||
|
||||
$data['id'] = $user_id['id'];
|
||||
$reparation = $Mecanicien->getReparation($data['id']);
|
||||
$result = ['data' => []];
|
||||
|
||||
function strReparation($repastatus)
|
||||
{
|
||||
$reparation = '';
|
||||
if ($repastatus == 1) {
|
||||
$reparation = 'En cours de réparation';
|
||||
} else if ($repastatus == 2) {
|
||||
$reparation = 'Réparer';
|
||||
} else {
|
||||
$reparation = 'Non réparer';
|
||||
}
|
||||
|
||||
return $reparation;
|
||||
}
|
||||
|
||||
// Iterate through the data
|
||||
foreach ($reparation as $key => $repa) {
|
||||
// Action buttons
|
||||
$buttons = '';
|
||||
// dd($repa['reparationsID']);
|
||||
// Check permissions for updating the store
|
||||
if (in_array('updateMecanicien', $this->permission)) {
|
||||
$buttons .= '<button type="button" class="btn btn-default" onclick="editFunc(' . $repa['reparationsID'] . ')" data-toggle="modal" data-target="#editModal"><i class="fa fa-pencil"></i></button>';
|
||||
}
|
||||
|
||||
// Check permissions for deleting the store
|
||||
if (in_array('deleteMecanicien', $this->permission)) {
|
||||
$buttons .= ' <button type="button" class="btn btn-danger" onclick="removeFunc(' . $repa['reparationsID'] . ')" data-toggle="modal" data-target="#removeModal"><i class="fa fa-trash"></i></button>';
|
||||
}
|
||||
|
||||
$image = '<img src="' . base_url('assets/images/product_image/' . $repa['image']) . '" alt="' . $repa['name'] . '" class="img-circle" width="50" height="50" />';
|
||||
$produit = $repa['sku'];
|
||||
// Status display
|
||||
$status = strReparation($repa['reparation_statut']);
|
||||
$username = $repa['username'];
|
||||
|
||||
$observation = $repa['reparation_observation'];
|
||||
$date_debut = date("d/m/Y", strtotime($repa['reparation_debut']));
|
||||
$date_fin = date("d/m/Y", strtotime($repa['reparation_fin']));
|
||||
// Add the row data
|
||||
$result['data'][$key] = [
|
||||
$image,
|
||||
$produit,
|
||||
$username,
|
||||
$status,
|
||||
$observation,
|
||||
$date_debut,
|
||||
$date_fin,
|
||||
$buttons
|
||||
];
|
||||
}
|
||||
|
||||
// Return data in JSON format
|
||||
return $this->response->setJSON($result);
|
||||
}
|
||||
|
||||
public function fetchMecanicien_1(int $id)
|
||||
{
|
||||
$Mecanicien = new Mecanicien();
|
||||
|
||||
$reparation = $Mecanicien->getReparation($id);
|
||||
$result = ['data' => []];
|
||||
|
||||
// die(var_dump($reparation));
|
||||
// Iterate through the data
|
||||
foreach ($reparation as $key => $repa) {
|
||||
// Action buttons
|
||||
$buttons = '';
|
||||
// dd($repa['reparationsID']);
|
||||
// Check permissions for updating the store
|
||||
if (in_array('updateMecanicien', $this->permission)) {
|
||||
$buttons .= '<button type="button" class="btn btn-default" onclick="editFunc(' . $repa['reparationsID'] . ')" data-toggle="modal" data-target="#editModal"><i class="fa fa-pencil"></i></button>';
|
||||
}
|
||||
|
||||
// Check permissions for deleting the store
|
||||
if (in_array('deleteMecanicien', $this->permission)) {
|
||||
$buttons .= ' <button type="button" class="btn btn-danger" onclick="removeFunc(' . $repa['reparationsID'] . ')" data-toggle="modal" data-target="#removeModal"><i class="fa fa-trash"></i></button>';
|
||||
}
|
||||
|
||||
$image = '<img src="' . base_url('assets/images/product_image/' . $repa['image']) . '" alt="' . $repa['name'] . '" class="img-circle" width="50" height="50" />';
|
||||
$produit = $repa['name'];
|
||||
// Status display
|
||||
$status = $repa['reparation_statut'];
|
||||
$username = $repa['username'];
|
||||
|
||||
$observation = $repa['reparation_observation'];
|
||||
$date_debut = date("d/m/Y", strtotime($repa['reparation_debut']));
|
||||
$date_fin = date("d/m/Y", strtotime($repa['reparation_fin']));
|
||||
|
||||
// Add the row data
|
||||
$result['data'][$key] = [
|
||||
$image,
|
||||
$produit,
|
||||
$username,
|
||||
$status,
|
||||
$observation,
|
||||
$date_debut,
|
||||
$date_fin,
|
||||
$buttons
|
||||
];
|
||||
}
|
||||
|
||||
// Return data in JSON format
|
||||
return $this->response->setJSON($result);
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$this->verifyRole('createMecanicien');
|
||||
$response = [];
|
||||
$data = [];
|
||||
|
||||
$validation = \Config\Services::validation();
|
||||
$validation->setRules([
|
||||
'motos' => 'required',
|
||||
'mecano' => 'required',
|
||||
'statut' => 'required',
|
||||
'observation' => 'required',
|
||||
'date_debut' => 'required',
|
||||
'date_fin' => 'required',
|
||||
]);
|
||||
|
||||
$validationData = [
|
||||
'motos' => $this->request->getPost('motos'),
|
||||
'mecano' => $this->request->getPost('mecano'),
|
||||
'statut' => $this->request->getPost('statut'),
|
||||
'observation' => $this->request->getPost('observation'),
|
||||
'date_debut' => $this->request->getPost('date_debut'),
|
||||
'date_fin' => $this->request->getPost('date_fin'),
|
||||
];
|
||||
|
||||
// Run validation
|
||||
if ($validation->run($validationData)) {
|
||||
// // Prepare data
|
||||
$data = [
|
||||
'user_id' => $this->request->getPost('mecano'),
|
||||
'produit_id' => $this->request->getPost('motos'),
|
||||
'reparation_observation' => $this->request->getPost('observation'),
|
||||
'reparation_statut' => $this->request->getPost('statut'),
|
||||
'reparation_debut' => $this->request->getPost('date_debut'),
|
||||
'reparation_fin' => $this->request->getPost('date_fin'),
|
||||
];
|
||||
|
||||
// Load the model and create the store
|
||||
$Mecanicien = new Mecanicien();
|
||||
if ($Mecanicien->createRepation($data)) {
|
||||
$response['success'] = true;
|
||||
$response['messages'] = 'Créé avec succès';
|
||||
} else {
|
||||
$response['success'] = false;
|
||||
$response['messages'] = 'Erreur de base de données';
|
||||
}
|
||||
} else {
|
||||
// Validation failed, return error messages
|
||||
$response['success'] = false;
|
||||
$response['messages'] = $validation->getErrors();
|
||||
}
|
||||
|
||||
return $this->response->setJSON($response);
|
||||
}
|
||||
|
||||
public function delete()
|
||||
{
|
||||
$this->verifyRole('deleteMecanicien');
|
||||
$response = [];
|
||||
|
||||
$reparation_id = $this->request->getPost('reparation_id');
|
||||
|
||||
if ($reparation_id) {
|
||||
$Mecanicien = new Mecanicien();
|
||||
|
||||
if ($Mecanicien->delete($reparation_id)) {
|
||||
$response['success'] = true;
|
||||
$response['messages'] = "Supprimé avec succès";
|
||||
} else {
|
||||
$response['success'] = false;
|
||||
$response['messages'] = "Erreur dans la base de données lors de la suppression des informations sur la marque";
|
||||
}
|
||||
} else {
|
||||
$response['success'] = false;
|
||||
$response['messages'] = "Référez à nouveau la page !!";
|
||||
}
|
||||
|
||||
return $this->response->setJSON($response);
|
||||
}
|
||||
|
||||
|
||||
public function update(int $id)
|
||||
{
|
||||
$this->verifyRole('updateMecanicien');
|
||||
$response = [];
|
||||
|
||||
if ($id) {
|
||||
// Set validation rules
|
||||
$validation = \Config\Services::validation();
|
||||
|
||||
$validation->setRules([
|
||||
'motos_edit' => 'required',
|
||||
'mecano' => 'required',
|
||||
'statut_edit' => 'required',
|
||||
'observation_edit' => 'required',
|
||||
'date_debut_edit' => 'required',
|
||||
'date_fin_edit' => 'required',
|
||||
]);
|
||||
$statutList = [
|
||||
"1" => "En cours de réparation",
|
||||
"2" => "Reparé",
|
||||
"3" => "Non reparé"
|
||||
];
|
||||
$statut = $this->request->getPost('statut');
|
||||
$validationData = [
|
||||
'motos_edit' => $this->request->getPost('motos'),
|
||||
'mecano' => $this->request->getPost('mecano'),
|
||||
'statut_edit' => $statutList[$statut],
|
||||
'observation_edit' => $this->request->getPost('observation'),
|
||||
'date_debut_edit' => $this->request->getPost('date_debut'),
|
||||
'date_fin_edit' => $this->request->getPost('date_fin'),
|
||||
];
|
||||
|
||||
$Mecanicien = new Mecanicien();
|
||||
|
||||
if ($validation->run($validationData)) {
|
||||
|
||||
$data = [
|
||||
'user_id' => $this->request->getPost('mecano'),
|
||||
'produit_id' => $this->request->getPost('motos'),
|
||||
'reparation_statut' => (int) $this->request->getPost('statut'),
|
||||
'reparation_observation' => $this->request->getPost('observation'),
|
||||
'reparation_debut' => $this->request->getPost('date_debut'),
|
||||
'reparation_fin' => $this->request->getPost('date_fin'),
|
||||
];
|
||||
// echo '<pre>';
|
||||
// die(var_dump($data));
|
||||
|
||||
if ($Mecanicien->updateReparation($data, $id)) {
|
||||
$response['success'] = true;
|
||||
$response['messages'] = 'Mise à jour réussie';
|
||||
} else {
|
||||
$response['success'] = false;
|
||||
$response['messages'] = 'Erreur dans la base de données';
|
||||
}
|
||||
} else {
|
||||
// Validation failed, return error messages
|
||||
$response['success'] = false;
|
||||
$response['messages'] = $validation->getErrors();
|
||||
}
|
||||
} else {
|
||||
$response['success'] = false;
|
||||
$response['messages'] = 'Erreur, veuillez actualiser la page à nouveau !!';
|
||||
}
|
||||
|
||||
return $this->response->setJSON($response);
|
||||
}
|
||||
|
||||
public function fetchMecanicienPerformances()
|
||||
{
|
||||
$Mecanicien = new Mecanicien();
|
||||
$session = session();
|
||||
$users = $session->get('user');
|
||||
|
||||
$data['id'] = $users['id'];
|
||||
$reparation = $Mecanicien->getReparation($data['id']);
|
||||
$result = ['data' => []];
|
||||
|
||||
|
||||
// Iterate through the data
|
||||
if($users['group_name'] == "Conseil" || $users['group_name'] == "Direction"){
|
||||
foreach ($reparation as $key => $repa) {
|
||||
$image = '<img src="' . base_url('assets/images/product_image/' . $repa['image']) . '" alt="' . $repa['name'] . '" class="img-circle" width="50" height="50" />';
|
||||
$produit = esc($repa['name']);
|
||||
$first_name = esc($repa['firstname']);
|
||||
$last_name = esc($repa['lastname']);
|
||||
$user_name = $first_name . ' ' . $last_name;
|
||||
$date_debut = date("d/m/Y", strtotime($repa['reparation_debut']));
|
||||
$date_fin = date("d/m/Y", strtotime($repa['reparation_fin']));
|
||||
// Add the row data
|
||||
$result['data'][$key] = [
|
||||
$user_name,
|
||||
$image,
|
||||
$produit,
|
||||
$repa['sku'],
|
||||
$date_debut,
|
||||
$date_fin,
|
||||
];
|
||||
}
|
||||
return $this->response->setJSON($result);
|
||||
}
|
||||
else{
|
||||
foreach ($reparation as $key => $repa) {
|
||||
$image = '<img src="' . base_url('assets/images/product_image/' . $repa['image']) . '" alt="' . $repa['name'] . '" class="img-circle" width="50" height="50" />';
|
||||
$produit = $repa['name'];
|
||||
// Status display
|
||||
$username = $repa['username'];
|
||||
|
||||
$date_debut = date("d/m/Y", strtotime($repa['reparation_debut']));
|
||||
$date_fin = date("d/m/Y", strtotime($repa['reparation_fin']));
|
||||
// Add the row data
|
||||
$result['data'][$key] = [
|
||||
$image,
|
||||
$produit,
|
||||
$repa['sku'],
|
||||
$date_debut,
|
||||
$date_fin,
|
||||
];
|
||||
}
|
||||
|
||||
// Return data in JSON format
|
||||
return $this->response->setJSON($result);
|
||||
}
|
||||
// Iterate through the data
|
||||
|
||||
}
|
||||
}
|
||||
46
app/Controllers/NotificationController.php
Normal file
46
app/Controllers/NotificationController.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Models\Notification;
|
||||
|
||||
class NotificationController extends AdminController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function getNotification()
|
||||
{
|
||||
$Notification = new Notification();
|
||||
|
||||
$notifications = $Notification->getNotifications();
|
||||
|
||||
return $this->response->setJSON($notifications);
|
||||
}
|
||||
|
||||
public function markAsRead(int $id)
|
||||
{
|
||||
$Notification = new Notification();
|
||||
$Notification->markAsRead($id);
|
||||
|
||||
return $this->response->setJSON(['status' => 'success']);
|
||||
}
|
||||
|
||||
public function createNotification(string $message, string $group, ?int $store_id, ?string $link)
|
||||
{
|
||||
$Notification = new Notification();
|
||||
|
||||
$data = [
|
||||
'message' => $message,
|
||||
'is_read' => 0,
|
||||
'forgroup' => $group,
|
||||
'store_id' => $store_id,
|
||||
'link' => $link,
|
||||
'created_at' => date('Y-m-d H:i:s')
|
||||
];
|
||||
|
||||
$Notification->insertNotification($data);
|
||||
}
|
||||
}
|
||||
1956
app/Controllers/OrderController.php
Normal file
1956
app/Controllers/OrderController.php
Normal file
File diff suppressed because it is too large
Load Diff
156
app/Controllers/PerformanceController.php
Normal file
156
app/Controllers/PerformanceController.php
Normal file
@ -0,0 +1,156 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Controllers\AdminController;
|
||||
use App\Models\OrderItems;
|
||||
use App\Models\Orders;
|
||||
use App\Models\Products;
|
||||
use App\Models\Recouvrement;
|
||||
|
||||
|
||||
class PerformanceController extends AdminController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
private $pageTitle = 'Performance';
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->verifyRole('viewPerformance');
|
||||
|
||||
$data = [
|
||||
'user_permission' => $this->permission,
|
||||
'page_title' => $this->pageTitle
|
||||
];
|
||||
|
||||
$this->render_template('performance/index', $data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function fetchPerformanceData()
|
||||
{
|
||||
helper(['url', 'form']);
|
||||
|
||||
$Orders = new Orders();
|
||||
$OrderItems = new OrderItems();
|
||||
$Products = new Products();
|
||||
|
||||
$draw = intval($this->request->getVar('draw'));
|
||||
$date = $this->request->getGet('date'); // format: YYYY-MM-DD / YYYY-W## / YYYY-MM
|
||||
$type = $this->request->getGet('type'); // 'day', 'week', 'month'
|
||||
|
||||
if (!$type || !$date) {
|
||||
$type = 'day';
|
||||
$date = date('Y-m-d');
|
||||
}
|
||||
|
||||
// Déterminer les données à récupérer
|
||||
if ($type === 'day') {
|
||||
$performance_data = $Orders->getUserPerformanceToday($date);
|
||||
} elseif ($type === 'week') {
|
||||
$performance_data = $Orders->getUserPerformanceByWeek($date);
|
||||
} elseif ($type === 'month') {
|
||||
$performance_data = $Orders->getUserPerformanceByMonth($date);
|
||||
} else {
|
||||
$performance_data = [];
|
||||
}
|
||||
|
||||
$totalOrdersAllUsers = 0;
|
||||
$totalSalesAllUsers = 0;
|
||||
$totalProductPricesAllUsers = 0;
|
||||
$data = [];
|
||||
|
||||
foreach ($performance_data as $value) {
|
||||
$userId = $value['user_id'];
|
||||
$userName = $value['full_name'];
|
||||
$orders = (int) $value['total_user_order'];
|
||||
$sales = (float) $value['total_prix_vente'];
|
||||
$orderIds = $value['order_ids'] ?? [];
|
||||
|
||||
$productIds = $OrderItems->getProductIds($orderIds);
|
||||
$totalProductPrice = $Products->getTotalProductPriceByIds($productIds);
|
||||
|
||||
$totalOrdersAllUsers += $orders;
|
||||
$totalSalesAllUsers += $sales;
|
||||
$totalProductPricesAllUsers += $totalProductPrice;
|
||||
|
||||
|
||||
$data[] = [
|
||||
$userName,
|
||||
number_format($orders, 0, '.', ' '),
|
||||
number_format($sales - $totalProductPrice, 0, '.', ' ') . ' Ar'
|
||||
];
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
return $this->response->setJSON([
|
||||
'data' => $data
|
||||
]);
|
||||
}
|
||||
|
||||
public function fetchTotalPerformanceData()
|
||||
{
|
||||
helper(['url', 'form']);
|
||||
|
||||
$Orders = new Orders();
|
||||
$OrderItems = new OrderItems();
|
||||
$Products = new Products();
|
||||
|
||||
$draw = intval($this->request->getVar('draw'));
|
||||
$date = $this->request->getGet('date'); // format: YYYY-MM-DD / YYYY-W## / YYYY-MM
|
||||
$type = $this->request->getGet('type'); // 'day', 'week', 'month'
|
||||
|
||||
if (!$type || !$date) {
|
||||
$type = 'day';
|
||||
$date = date('Y-m-d');
|
||||
}
|
||||
|
||||
// Déterminer les données à récupérer
|
||||
if ($type === 'day') {
|
||||
$performance_data = $Orders->getUserPerformanceToday($date);
|
||||
} elseif ($type === 'week') {
|
||||
$performance_data = $Orders->getUserPerformanceByWeek($date);
|
||||
} elseif ($type === 'month') {
|
||||
$performance_data = $Orders->getUserPerformanceByMonth($date);
|
||||
} else {
|
||||
$performance_data = [];
|
||||
}
|
||||
|
||||
$totalOrdersAllUsers = 0;
|
||||
$totalSalesAllUsers = 0;
|
||||
$totalProductPricesAllUsers = 0;
|
||||
$data = [];
|
||||
|
||||
foreach ($performance_data as $value) {
|
||||
$userId = $value['user_id'];
|
||||
$userName = $value['full_name'];
|
||||
$orders = (int) $value['total_user_order'];
|
||||
$sales = (float) $value['total_prix_vente'];
|
||||
$orderIds = $value['order_ids'] ?? [];
|
||||
|
||||
$productIds = $OrderItems->getProductIds($orderIds);
|
||||
$totalProductPrice = (float) $Products->getTotalProductPriceByIds($productIds);
|
||||
|
||||
$totalOrdersAllUsers += $orders;
|
||||
$totalSalesAllUsers += $sales;
|
||||
$totalProductPricesAllUsers += $totalProductPrice;
|
||||
|
||||
$data = [
|
||||
"total_commande"=> $orders,
|
||||
"total_benefice"=> number_format($totalSalesAllUsers - $totalProductPricesAllUsers, 0, '.', ' '),
|
||||
];
|
||||
}
|
||||
|
||||
return $this->response->setJSON($data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
500
app/Controllers/ProductCOntroller.php
Normal file
500
app/Controllers/ProductCOntroller.php
Normal file
@ -0,0 +1,500 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Models\Attributes;
|
||||
use App\Models\Brands;
|
||||
use App\Models\Category;
|
||||
use App\Models\FourchettePrix;
|
||||
use App\Models\Notification;
|
||||
use App\Models\Products;
|
||||
use App\Models\Stores;
|
||||
use Config\Services;
|
||||
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\Drawing;
|
||||
|
||||
class ProductCOntroller extends AdminController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
// Assuming permission is being set from a session
|
||||
helper(['form', 'url']);
|
||||
}
|
||||
|
||||
|
||||
private $pageTitle = 'Produits';
|
||||
|
||||
public function index()
|
||||
{
|
||||
$Stores = new Stores();
|
||||
$this->verifyRole('viewProduct');
|
||||
$data['page_title'] = $this->pageTitle;
|
||||
$Product = new Products();
|
||||
$data['motos'] = $Product->getActiveProductData();
|
||||
$data['stores'] = $Stores->getActiveStore();
|
||||
return $this->render_template('products/index', $data);
|
||||
}
|
||||
|
||||
public function assign_store()
|
||||
{
|
||||
// Vérifie que la requête est bien une requête AJAX
|
||||
if (!$this->request->isAJAX()) {
|
||||
$response = Services::response();
|
||||
$response->setStatusCode(404, 'Page Not Found')->send();
|
||||
exit;
|
||||
}
|
||||
|
||||
// Récupère les données POST sous format JSON
|
||||
$data = $this->request->getJSON(true); // Décodage en tableau associatif
|
||||
|
||||
|
||||
if (!isset($data['product_id']) || !isset($data['store_id'])) {
|
||||
return $this->response->setJSON([
|
||||
'success' => false,
|
||||
'message' => 'Paramètres manquants.'
|
||||
])->setStatusCode(400);
|
||||
}
|
||||
|
||||
$product_id = $data['product_id'];
|
||||
$store_id = $data['store_id'];
|
||||
|
||||
$productsModel = new Products();
|
||||
|
||||
// Appeler la méthode assignToStore pour mettre à jour la base de données
|
||||
$result = $productsModel->assignToStore($product_id, $store_id);
|
||||
|
||||
// Répondre en JSON avec le résultat
|
||||
if ($result) {
|
||||
return $this->response->setJSON(['success' => true]);
|
||||
} else {
|
||||
return $this->response->setJSON(['success' => false, 'message' => 'Échec de la mise à jour.']);
|
||||
}
|
||||
}
|
||||
|
||||
public function fetchProductData()
|
||||
{
|
||||
$result = ['data' => []];
|
||||
$Products = new Products();
|
||||
$Stores = new Stores();
|
||||
|
||||
function convertString($name)
|
||||
{
|
||||
return "$name";
|
||||
}
|
||||
|
||||
$data = $Products->getProductData();
|
||||
|
||||
foreach ($data as $key => $value) {
|
||||
|
||||
// Gestion du nom du magasin
|
||||
if ($value['store_id'] == 0) {
|
||||
$store_name = "TOUS";
|
||||
} else {
|
||||
$store_info = $Stores->getStoresData($value['store_id']);
|
||||
$store_name = $store_info && isset($store_info['name']) ? $store_info['name'] : "Inconnu";
|
||||
}
|
||||
|
||||
// Disponibilité
|
||||
$availability = ($value['qty'] > 0) ? '<span class="label label-success">En stock</span>' : '<span class="label label-danger">Rupture</span>';
|
||||
|
||||
// Construction des boutons
|
||||
$buttons = '';
|
||||
if (in_array('updateProduct', $this->permission ?? [])) {
|
||||
$buttons .= '<a href="' . base_url('products/update/' . $value['id']) . '" class="btn btn-default"><i class="fa fa-pencil"></i></a>';
|
||||
}
|
||||
|
||||
if (in_array('deleteProduct', $this->permission ?? [])) {
|
||||
$buttons .= ' <button type="button" class="btn btn-danger" onclick="removeFunc(' . $value['id'] . ')" data-toggle="modal" data-target="#removeModal"><i class="fa fa-trash"></i></button>';
|
||||
}
|
||||
|
||||
if (in_array('updateProduct', $this->permission ?? [])) {
|
||||
$buttons .= ' <a href="ventes/' . $value['id'] . '" class="btn btn-default"><i class="fa fa-image"></i></a>';
|
||||
}
|
||||
|
||||
if (in_array('updateProduct', $this->permission ?? [])) {
|
||||
$buttons .= ' <button class="btn btn-default" onclick="generateQrPdf(' . $value["id"] . ')"><i class="fa fa-qrcode"></i></button>';
|
||||
}
|
||||
|
||||
if (in_array('viewProduct', $this->permission ?? [])) {
|
||||
$buttons .= " <a href='/ventes/show/" . $value['id'] . "' class='btn btn-default'><i class='fa fa-eye'></i></a>";
|
||||
}
|
||||
|
||||
if (in_array('assignStore', $this->permission ?? [])) {
|
||||
$buttons .=
|
||||
'<button type="button" class="btn btn-info assignbtn" title="Assigner sur un magasin" data-magasin="' . $store_name . '" data-products-id="' . $value["id"] . '" data-toggle="modal" data-target="#assignStoreModal">
|
||||
<i class="fa fa-forward"></i>
|
||||
</button>';
|
||||
}
|
||||
$imagePath = 'assets/images/product_image/' . $value['image'];
|
||||
$imageHtml = $value['image'] ?
|
||||
'<img src="' . base_url($imagePath) . '" width="50" height="50" class="img-thumbnail">' :
|
||||
'<div class="no-image">Aucune image</div>';
|
||||
|
||||
// Préparer les données pour DataTables (7 colonnes)
|
||||
$result['data'][$key] = [
|
||||
$value['image'],
|
||||
convertString($value['sku']),
|
||||
$value['name'],
|
||||
$value['price'],
|
||||
$store_name,
|
||||
$availability, // <-- ici la disponibilité ajoutée
|
||||
$buttons
|
||||
];
|
||||
}
|
||||
|
||||
return $this->response->setJSON($result);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function create()
|
||||
{
|
||||
$Products = new Products();
|
||||
$Brands = new Brands();
|
||||
$Category = new Category();
|
||||
$Stores = new Stores();
|
||||
$Notification = new NotificationController();
|
||||
$this->verifyRole('createProduct');
|
||||
$data['page_title'] = $this->pageTitle;
|
||||
// die(var_dump(json_encode($this->request->getPost('categorie[]'))));
|
||||
// Validate form inputs
|
||||
$validation = \Config\Services::validation();
|
||||
$validation->setRules([
|
||||
'nom_de_produit' => 'required',
|
||||
'marque' => 'required',
|
||||
'numero_de_moteur' => 'required',
|
||||
'prix' => 'required|numeric',
|
||||
'price_vente' => 'required|numeric',
|
||||
'puissance' => 'required',
|
||||
'store' => 'required',
|
||||
'availability' => 'required',
|
||||
'price_min' => 'required|numeric',
|
||||
]);
|
||||
|
||||
if ($this->request->getMethod() === 'post' && $validation->withRequest($this->request)->run()) {
|
||||
// die(var_dump($this->request->getPost()));
|
||||
// Handle image upload
|
||||
$upload_image = $this->uploadImage();
|
||||
|
||||
// Prepare data for insertion
|
||||
$product_sold = false;
|
||||
$data = [
|
||||
'name' => $this->request->getPost('nom_de_produit'),
|
||||
'sku' => $this->request->getPost('numero_de_serie'),
|
||||
'price' => $this->request->getPost('prix'),
|
||||
'qty' => 1,
|
||||
'image' => $upload_image,
|
||||
'description' => $this->request->getPost('description'),
|
||||
'numero_de_moteur' => $this->request->getPost('numero_de_moteur'),
|
||||
'marque' => $this->request->getPost('marque'),
|
||||
'chasis' => $this->request->getPost('chasis'),
|
||||
'store_id' => $this->request->getPost('store'),
|
||||
'availability' => $this->request->getPost('availability'),
|
||||
'prix_vente' => $this->request->getPost('price_vente'),
|
||||
'date_arivage' => $this->request->getPost('datea'),
|
||||
'puissance' => $this->request->getPost('puissance'),
|
||||
'cler' => $this->request->getPost('cler'),
|
||||
'categorie_id' => json_encode($this->request->getPost('categorie[]')),
|
||||
'etats' => $this->request->getPost('etats'),
|
||||
'infoManquekit' => $this->request->getPost('infoManquekit'),
|
||||
'info' => $this->request->getPost('info'),
|
||||
'infoManque' => $this->request->getPost('infoManque'),
|
||||
'product_sold' => $product_sold,
|
||||
];
|
||||
$store_id1 = (int)$this->request->getPost('store');
|
||||
// Insert data into the database
|
||||
if ($Products->create($data)) {
|
||||
$data = [
|
||||
'product_id' => $Products->insertID(),
|
||||
'prix_minimal' => $this->request->getPost('price_min'),
|
||||
];
|
||||
$Fourchette = new FourchettePrix();
|
||||
|
||||
$Fourchette->createFourchettePrix($data);
|
||||
session()->setFlashdata('success', 'Créé avec succès');
|
||||
$Notification->createNotification("Un nouveau Produit a été crée", "COMMERCIALE",$store_id1,'product/');
|
||||
return redirect()->to('/products');
|
||||
} else {
|
||||
session()->setFlashdata('errors', 'Error occurred while creating the product');
|
||||
return redirect()->to('products/create');
|
||||
}
|
||||
} else {
|
||||
$data = [
|
||||
'stores' => $Stores->getActiveStore(),
|
||||
'validation' => $validation, // Pass validation errors to the view
|
||||
'page_title' => $this->pageTitle,
|
||||
'marque' => $Brands->getActiveBrands(),
|
||||
'categorie' => $Category->getActiveCategory(),
|
||||
];
|
||||
|
||||
// Render the form view
|
||||
return $this->render_template('products/create', $data);
|
||||
}
|
||||
}
|
||||
|
||||
private function uploadImage()
|
||||
{
|
||||
// Define the upload directory
|
||||
$uploadPath = 'assets/images/product_image';
|
||||
|
||||
// Ensure the directory exists
|
||||
if (!is_dir($uploadPath)) {
|
||||
mkdir($uploadPath, 0777, true);
|
||||
}
|
||||
|
||||
// Check if the file is uploaded via the form
|
||||
$file = $this->request->getFile('product_image');
|
||||
if ($file && $file->isValid() && !$file->hasMoved()) {
|
||||
// Generate a unique file name
|
||||
$newName = uniqid() . '.' . $file->getExtension();
|
||||
|
||||
// Move the file to the target directory
|
||||
$file->move($uploadPath, $newName);
|
||||
|
||||
// Return the actual file name
|
||||
return $newName;
|
||||
}
|
||||
|
||||
// If an error occurs, return the error message
|
||||
return $file ? $file->getErrorString() : 'No file was uploaded.';
|
||||
}
|
||||
|
||||
public function update(int $id)
|
||||
{
|
||||
$Products = new Products();
|
||||
$Stores = new Stores();
|
||||
$Category = new Category();
|
||||
$this->verifyRole('updateProduct');
|
||||
$data['page_title'] = $this->pageTitle;
|
||||
$Brands = new Brands();
|
||||
|
||||
// Validate form inputs
|
||||
$validation = \Config\Services::validation();
|
||||
$validation->setRules([
|
||||
'nom_de_produit' => 'required',
|
||||
'marque' => 'required',
|
||||
]);
|
||||
|
||||
if ($this->request->getMethod() === 'post' && $validation->withRequest($this->request)->run()) {
|
||||
$data = [
|
||||
'name' => $this->request->getPost('nom_de_produit'),
|
||||
'sku' => $this->request->getPost('numero_de_serie'),
|
||||
'price' => $this->request->getPost('price'),
|
||||
'qty' => 1,
|
||||
'description' => $this->request->getPost('description'),
|
||||
'numero_de_moteur' => $this->request->getPost('numero_de_moteur'),
|
||||
'marque' => $this->request->getPost('marque'),
|
||||
'chasis' => $this->request->getPost('chasis'),
|
||||
'store_id' => $this->request->getPost('store'),
|
||||
'availability' => $this->request->getPost('availability'),
|
||||
'prix_vente' => $this->request->getPost('price_vente'),
|
||||
'date_arivage' => $this->request->getPost('datea'),
|
||||
'puissance' => $this->request->getPost('puissance'),
|
||||
'cler' => $this->request->getPost('cler'),
|
||||
'categorie_id' => json_encode($this->request->getPost('categorie[]')),
|
||||
'etats' => $this->request->getPost('etats'),
|
||||
'infoManquekit' => $this->request->getPost('infoManquekit'),
|
||||
'info' => $this->request->getPost('info'),
|
||||
'infoManque' => $this->request->getPost('infoManque'),
|
||||
];
|
||||
// Check if a product image is uploaded
|
||||
if ($this->request->getFile('product_image')->isValid()) {
|
||||
$uploadImage = $this->uploadImage(); // Use the previously provided upload function
|
||||
$uploadData = ['image' => $uploadImage];
|
||||
|
||||
// Update the product with the uploaded image
|
||||
$Products->update($id, $uploadData);
|
||||
}
|
||||
|
||||
if ($Products->updateProduct($data, $id)) {
|
||||
// die(var_dump('tonga eto'));
|
||||
session()->setFlashdata('success', 'Successfully updated');
|
||||
return redirect()->to('/products');
|
||||
} else {
|
||||
session()->setFlashdata('errors', 'Error occurred!!');
|
||||
return redirect()->to('/produtcs/update/' . $id);
|
||||
}
|
||||
} else {
|
||||
|
||||
|
||||
$data = [
|
||||
'stores' => $Stores->getActiveStore(),
|
||||
'validation' => $validation, // Pass validation errors to the view
|
||||
'page_title' => $this->pageTitle,
|
||||
'product_data' => $Products->getProductData($id),
|
||||
'categorie' => $Category->getActiveCategory(),
|
||||
'marque' => $Brands->getActiveBrands()
|
||||
];
|
||||
|
||||
return $this->render_template('products/editbackup', $data);
|
||||
}
|
||||
}
|
||||
|
||||
public function remove()
|
||||
{
|
||||
$this->verifyRole('deleteProduct');
|
||||
$product_id = $this->request->getPost('product_id');
|
||||
$response = [];
|
||||
$Products = new Products();
|
||||
|
||||
if ($product_id) {
|
||||
if ($Products->remove($product_id)) {
|
||||
$response['success'] = true;
|
||||
$response['messages'] = "Successfully removed";
|
||||
} else {
|
||||
$response['success'] = false;
|
||||
$response['messages'] = "Error in the database while removing the product information";
|
||||
}
|
||||
} else {
|
||||
$response['success'] = false;
|
||||
$response['messages'] = "Refersh the page again!!";
|
||||
}
|
||||
// Return JSON response
|
||||
return $this->response->setJSON($response);
|
||||
}
|
||||
|
||||
public function createByExcel()
|
||||
{
|
||||
$this->verifyRole("createProduct");
|
||||
|
||||
try {
|
||||
$file = $this->request->getFile('excel_product');
|
||||
if (!$file || !$file->isValid()) {
|
||||
return $this->response->setJSON([
|
||||
'success' => false,
|
||||
'messages' => "Fichier invalide ou non reçu"
|
||||
]);
|
||||
}
|
||||
|
||||
$ext = strtolower($file->getClientExtension());
|
||||
if (!in_array($ext, ['xls', 'xlsx'])) {
|
||||
return $this->response->setJSON([
|
||||
'success' => false,
|
||||
'messages' => "Seuls les fichiers Excel (.xls, .xlsx) sont acceptés"
|
||||
]);
|
||||
}
|
||||
|
||||
$spreadsheet = IOFactory::load($file->getTempName());
|
||||
$sheet = $spreadsheet->getActiveSheet();
|
||||
$rows = $sheet->toArray();
|
||||
|
||||
if (count($rows) <= 1) {
|
||||
return $this->response->setJSON([
|
||||
'success' => false,
|
||||
'messages' => "Le fichier ne contient pas de données"
|
||||
]);
|
||||
}
|
||||
|
||||
// Récupérer les en-têtes
|
||||
$headers = array_shift($rows);
|
||||
$headers = array_map('strtolower', $headers);
|
||||
|
||||
// Mapping des colonnes Excel vers les champs de la base
|
||||
$columnMapping = [
|
||||
'n° série' => 'sku',
|
||||
'marque' => 'marque',
|
||||
'désignation' => 'name',
|
||||
'fournisseur' => 'info', // À adapter selon votre besoin
|
||||
'date d\'arrivage' => 'date_arivage',
|
||||
'n° moteur' => 'numero_de_moteur',
|
||||
'châssis' => 'chasis',
|
||||
'puissance' => 'puissance',
|
||||
'clé' => 'cler',
|
||||
'prix d\'achat' => 'prix_vente',
|
||||
'prix ar' => 'price',
|
||||
'catégories' => 'categorie_id',
|
||||
'magasin' => 'store_id',
|
||||
'disponibilité' => 'availability',
|
||||
'état' => 'etats',
|
||||
'pièce manquant' => 'infoManque'
|
||||
];
|
||||
|
||||
$ProductsModel = new Products();
|
||||
$BrandsModel = new Brands();
|
||||
$StoresModel = new Stores();
|
||||
$CategoryModel = new Category();
|
||||
|
||||
$countInserted = 0;
|
||||
|
||||
foreach ($rows as $row) {
|
||||
if (empty(array_filter($row))) continue; // Ignore les lignes vides
|
||||
|
||||
$data = [
|
||||
'is_piece' => 0,
|
||||
'product_sold' => 0,
|
||||
'qty' => 1
|
||||
];
|
||||
|
||||
// Mapper chaque colonne
|
||||
foreach ($headers as $index => $header) {
|
||||
$header = trim($header);
|
||||
if (isset($columnMapping[$header]) && isset($row[$index])) {
|
||||
$field = $columnMapping[$header];
|
||||
$value = trim($row[$index]);
|
||||
|
||||
// Traitements spécifiques pour certains champs
|
||||
switch ($field) {
|
||||
case 'marque':
|
||||
// Chercher ou créer la marque
|
||||
$brand = $BrandsModel->where('name', $value)->first();
|
||||
if (!$brand) {
|
||||
$brandId = $BrandsModel->insert(['name' => $value, 'active' => 1]);
|
||||
} else {
|
||||
$brandId = $brand['id'];
|
||||
}
|
||||
$data[$field] = $brandId;
|
||||
break;
|
||||
|
||||
case 'store_id':
|
||||
// Gestion du magasin
|
||||
if ($value == 'TOUS') {
|
||||
$data[$field] = 0;
|
||||
} else {
|
||||
$store = $StoresModel->where('name', $value)->first();
|
||||
$data[$field] = $store ? $store['id'] : 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'date_arivage':
|
||||
// Convertir la date Excel en format MySQL
|
||||
if (is_numeric($value)) {
|
||||
$data[$field] = date('Y-m-d', \PhpOffice\PhpSpreadsheet\Shared\Date::excelToTimestamp($value));
|
||||
} else {
|
||||
$data[$field] = date('Y-m-d', strtotime($value));
|
||||
}
|
||||
break;
|
||||
case 'price':
|
||||
// Nettoyer "1 900 000 Ar" → 1900000.00
|
||||
$cleanedValue = str_replace(['Ar', ' ', ','], '', $value);
|
||||
$data[$field] = (float)$cleanedValue;
|
||||
break;
|
||||
|
||||
default:
|
||||
$data[$field] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Insertion
|
||||
if (!empty($data['name'])) {
|
||||
if ($ProductsModel->insert($data)) {
|
||||
$countInserted++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->response->setJSON([
|
||||
'success' => true,
|
||||
'messages' => "$countInserted produits importés avec succès"
|
||||
]);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return $this->response->setJSON([
|
||||
'success' => false,
|
||||
'messages' => "Erreur lors de l'import: " . $e->getMessage()
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
58
app/Controllers/QrCodeController.php
Normal file
58
app/Controllers/QrCodeController.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use Mpdf\Mpdf;
|
||||
use Endroid\QrCode\Color\Color;
|
||||
use Endroid\QrCode\Builder\Builder;
|
||||
use App\Controllers\AdminController;
|
||||
use Endroid\QrCode\Writer\PngWriter;
|
||||
use Endroid\QrCode\Encoding\Encoding;
|
||||
use Endroid\QrCode\RoundBlockSizeMode;
|
||||
use Endroid\QrCode\ErrorCorrectionLevel;
|
||||
|
||||
|
||||
class QrCodeController extends AdminController
|
||||
{
|
||||
public function generate($id)
|
||||
{
|
||||
// Define the product URL
|
||||
$url = base_url("products/show/$id");
|
||||
|
||||
// if (class_exists(class: \Endroid\QrCode\Builder\Builder::class)) {
|
||||
// echo "Builder class is available!";
|
||||
// } else {
|
||||
// echo "Builder class NOT found!";
|
||||
// }
|
||||
// exit;
|
||||
|
||||
// Create QR Code
|
||||
$result = \Endroid\QrCode\Builder\Builder::create()
|
||||
->writer(new PngWriter())
|
||||
->data($url)
|
||||
->encoding(new Encoding('UTF-8'))
|
||||
->errorCorrectionLevel(ErrorCorrectionLevel::High)
|
||||
->size(300)
|
||||
->margin(10)
|
||||
->roundBlockSizeMode(RoundBlockSizeMode::Margin)
|
||||
->foregroundColor(new Color(0, 0, 0)) // Black
|
||||
->backgroundColor(new Color(255, 255, 255)) // White
|
||||
->build();
|
||||
|
||||
// Get QR Code as PNG string
|
||||
$qrCodeImage = $result->getString();
|
||||
|
||||
die(var_dump($url));
|
||||
// Convert QR Code image to Base64 for embedding in PDF
|
||||
$base64Qr = base64_encode($qrCodeImage);
|
||||
|
||||
// Generate PDF using mPDF
|
||||
$mpdf = new Mpdf();
|
||||
$mpdf->WriteHTML('<h1 style="text-align: center;">QR Code for Product</h1>');
|
||||
$mpdf->WriteHTML('<p style="text-align: center;">Scan this QR code to view the product:</p>');
|
||||
$mpdf->WriteHTML('<div style="text-align: center;"><img src="data:image/png;base64,' . $base64Qr . '" /></div>');
|
||||
|
||||
// Output PDF as download
|
||||
return $mpdf->Output('QRCode_Product_' . $id . '.pdf', 'D');
|
||||
}
|
||||
}
|
||||
410
app/Controllers/RecouvrementController.php
Normal file
410
app/Controllers/RecouvrementController.php
Normal file
@ -0,0 +1,410 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Controllers\AdminController;
|
||||
use App\Models\Orders;
|
||||
use App\Models\Recouvrement;
|
||||
use App\Models\SortieCaisse;
|
||||
use App\Models\Avance;
|
||||
|
||||
class RecouvrementController extends AdminController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
private $pageTitle = 'Recouvrements';
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->verifyRole('viewRecouvrement');
|
||||
|
||||
$data = $this->getTotalsArray();
|
||||
|
||||
$this->render_template('recouvrement/index', $data);
|
||||
}
|
||||
|
||||
|
||||
// Create an AJAX endpoint to access the fetchTotal() function
|
||||
public function getTotalData()
|
||||
{
|
||||
echo $this->fetchTotal();
|
||||
exit;
|
||||
}
|
||||
|
||||
public function fetchTotal()
|
||||
{
|
||||
$data = $this->getTotalsArray();
|
||||
|
||||
return $this->response->setJSON($data);
|
||||
}
|
||||
|
||||
private function getTotalsArray(): array
|
||||
{
|
||||
$orders = new Orders();
|
||||
$recouvrement = new Recouvrement();
|
||||
$sortieCaisse = new SortieCaisse();
|
||||
$avance = new Avance();
|
||||
|
||||
// Récupère les données brutes
|
||||
$paymentData = $orders->getPaymentModes();
|
||||
$total_sortie_caisse = $sortieCaisse->getTotalSortieCaisse()->mr ?? 0;
|
||||
$totalRecouvrement = $recouvrement->getTotalRecouvrements();
|
||||
|
||||
// Totaux recouvrement
|
||||
$me = $totalRecouvrement->me ?? 0;
|
||||
$bm = $totalRecouvrement->bm ?? 0;
|
||||
$be = $totalRecouvrement->be ?? 0;
|
||||
$mb = $totalRecouvrement->mb ?? 0;
|
||||
$ta = $avance->getTotalAvance()->ta ?? 0;
|
||||
|
||||
// Totaux paiements initiaux
|
||||
$t = $paymentData->total ?? 0;
|
||||
$mv1 = $paymentData->total_mvola1 ?? 0;
|
||||
$mv2 = $paymentData->total_mvola2 ?? 0;
|
||||
$es1 = $paymentData->total_espece1 ?? 0;
|
||||
$es2 = $paymentData->total_espece2 ?? 0;
|
||||
$vb1 = $paymentData->total_virement_bancaire1 ?? 0;
|
||||
$vb2 = $paymentData->total_virement_bancaire2 ?? 0;
|
||||
|
||||
// Calculs
|
||||
$total_mvola = $mv1 + $mv2;
|
||||
$mv_calc = $total_mvola - $me - $mb + $bm;
|
||||
|
||||
$total_espece = $es1 + $es2;
|
||||
$es_calc = $total_espece + $me + $be - $total_sortie_caisse + $ta;
|
||||
|
||||
$total_vb = $vb1 + $vb2;
|
||||
$vb_calc = $total_vb - $be - $bm + $mb;
|
||||
|
||||
// Retourne le tableau à utiliser
|
||||
return [
|
||||
'total' => $t,
|
||||
'total_mvola' => $mv_calc,
|
||||
'total_espece' => $es_calc,
|
||||
'total_virement_bancaire' => $vb_calc,
|
||||
'page_title' => $this->pageTitle,
|
||||
'permission' => $this->permission
|
||||
];
|
||||
}
|
||||
|
||||
public function fetchRecouvrementData()
|
||||
{
|
||||
helper(['url', 'form']);
|
||||
$Recouvrement = new Recouvrement();
|
||||
|
||||
// Initialiser les variables pour DataTables
|
||||
$draw = intval($this->request->getVar('draw'));
|
||||
$session = session();
|
||||
$users = $session->get('user');
|
||||
if($users['group_name'] === "Caissière"){
|
||||
$data = $Recouvrement->getAllRecouvrements($users['id'] );
|
||||
$totalRecords = count($data); // Nombre total de recouvrements
|
||||
|
||||
$result = [
|
||||
"draw" => $draw,
|
||||
"recordsTotal" => $totalRecords,
|
||||
"recordsFiltered" => $totalRecords,
|
||||
"data" => []
|
||||
];
|
||||
|
||||
foreach ($data as $key => $value) {
|
||||
$buttons = '';
|
||||
if (in_array('updateRecouvrement', $this->permission)) {
|
||||
$buttons .= '<button type="button" class="btn btn-default" onclick="editFunc(' . $value['recouvrement_id'] . ')" data-toggle="modal" data-target="#updateModal"><i class="fa fa-pencil"></i></button>';
|
||||
}
|
||||
|
||||
if (in_array('deleteRecouvrement', $this->permission)) {
|
||||
$buttons .= ' <button type="button" class="btn btn-danger" onclick="removeFunc(' . $value['recouvrement_id'] . ')" data-toggle="modal" data-target="#removeModal"><i class="fa fa-trash"></i></button>';
|
||||
}
|
||||
$result['data'][$key] = [
|
||||
$value['recouvrement_id'],
|
||||
number_format($value['recouvrement_montant'], 0, '.', ' '),
|
||||
$value['recouvrement_date'],
|
||||
$value['recouvrement_personnel'],
|
||||
$value['send_money'],
|
||||
$value['get_money'],
|
||||
$buttons
|
||||
];
|
||||
}
|
||||
return $this->response->setJSON($result);
|
||||
}
|
||||
|
||||
$data = $Recouvrement->getAllRecouvrements();
|
||||
$totalRecords = count($data); // Nombre total de recouvrements
|
||||
|
||||
$result = [
|
||||
"draw" => $draw,
|
||||
"recordsTotal" => $totalRecords,
|
||||
"recordsFiltered" => $totalRecords,
|
||||
"data" => []
|
||||
];
|
||||
|
||||
foreach ($data as $key => $value) {
|
||||
$buttons = '';
|
||||
if (in_array('updateRecouvrement', $this->permission)) {
|
||||
$buttons .= '<button type="button" class="btn btn-default" onclick="editFunc(' . $value['recouvrement_id'] . ')" data-toggle="modal" data-target="#updateModal"><i class="fa fa-pencil"></i></button>';
|
||||
}
|
||||
|
||||
if (in_array('deleteRecouvrement', $this->permission)) {
|
||||
$buttons .= ' <button type="button" class="btn btn-danger" onclick="removeFunc(' . $value['recouvrement_id'] . ')" data-toggle="modal" data-target="#removeModal"><i class="fa fa-trash"></i></button>';
|
||||
}
|
||||
$result['data'][$key] = [
|
||||
$value['recouvrement_id'],
|
||||
number_format($value['recouvrement_montant'], 0, '.', ' '),
|
||||
$value['recouvrement_date'],
|
||||
$value['recouvrement_personnel'],
|
||||
$value['send_money'],
|
||||
$value['get_money'],
|
||||
$buttons
|
||||
];
|
||||
}
|
||||
return $this->response->setJSON($result);
|
||||
}
|
||||
|
||||
|
||||
public function removeRecouvrement()
|
||||
{
|
||||
$this->verifyRole('deleteRecouvrement');
|
||||
$recouvrement_id = $this->request->getPost('recouvrement_id');
|
||||
|
||||
|
||||
$response = [];
|
||||
|
||||
if ($recouvrement_id) {
|
||||
$Recouvrement = new Recouvrement();
|
||||
if ($Recouvrement->deleteRecouvrement($recouvrement_id)) {
|
||||
$response['success'] = true;
|
||||
$response['messages'] = "Recouvrement supprimé avec succès !";
|
||||
} else {
|
||||
$response['success'] = false;
|
||||
$response['messages'] = "Erreur lors de la suppression du recouvrement.";
|
||||
}
|
||||
} else {
|
||||
$response['success'] = false;
|
||||
$response['messages'] = "Veuillez actualiser la page.";
|
||||
}
|
||||
return $this->response->setJSON($response);
|
||||
}
|
||||
|
||||
public function createRecouvrement()
|
||||
{
|
||||
$this->verifyRole('createRecouvrement');
|
||||
|
||||
$data['page_title'] = $this->pageTitle;
|
||||
|
||||
// echo "<pre>";
|
||||
// die(var_dump($this->request->getPost()));
|
||||
|
||||
// Load validation service
|
||||
$validation = \Config\Services::validation();
|
||||
|
||||
$validation->setRules([
|
||||
'send_mode' => 'required',
|
||||
'get_mode' => 'required',
|
||||
'recouvrement_montant' => 'required',
|
||||
'recouvrement_date' => 'required',
|
||||
]);
|
||||
|
||||
$validationData = [
|
||||
'send_mode' => $this->request->getPost('send_mode'),
|
||||
'get_mode' => $this->request->getPost('get_mode'),
|
||||
'recouvrement_montant' => $this->request->getPost('recouvrement_montant'),
|
||||
'recouvrement_date' => $this->request->getPost('recouvrement_date'),
|
||||
];
|
||||
|
||||
// Set validation rules
|
||||
|
||||
$Notification = new NotificationController();
|
||||
$Recouvrement = new Recouvrement();
|
||||
// $recouvrement_id = $this->request->getPost('recouvrement_id');
|
||||
$session = session();
|
||||
$users = $session->get('user');
|
||||
if ($users && isset($users['firstname'], $users['lastname'])) {
|
||||
$fullname = $users['firstname'] . ' ' . $users['lastname'];
|
||||
}
|
||||
|
||||
// $orders = new Orders();
|
||||
// $Recouvrement = new Recouvrement();
|
||||
// $paymentData = $orders->getPaymentModes();
|
||||
// $totalRecouvrement = $Recouvrement->getTotalRecouvrements();
|
||||
// $total_recouvrement = $totalRecouvrement->total_recouvrement;
|
||||
// Initialisation des totaux avec 0 au cas où il n'y aurait pas de données
|
||||
// $total_mvola1 = isset($paymentData->total_mvola1) ? $paymentData->total_mvola1 : 0;
|
||||
// $total_mvola2 = isset($paymentData->total_mvola2) ? $paymentData->total_mvola2 : 0;
|
||||
|
||||
// $total_mvola = $total_mvola1 + $total_mvola2;
|
||||
// $total_mvola1 = $total_mvola - $total_recouvrement;
|
||||
|
||||
// die(var_dump($data['recouvrement']))
|
||||
|
||||
// if ($data['recouvrement_montant'] <= $total_mvola1) {
|
||||
// if ($Recouvrement->addRecouvrement($data)) {
|
||||
// session()->setFlashdata('success', 'Créé avec succès');
|
||||
|
||||
// $Notification->createNotification("Un nouveau recouvrement crée", "TOUS", 0, 'recouvrement/');
|
||||
// return redirect()->to('recouvrement/');
|
||||
// } else {
|
||||
// session()->setFlashdata('errors', 'Error occurred while creating the product');
|
||||
// return redirect()->to('recouvrement/');
|
||||
// }
|
||||
// } else {
|
||||
// session()->setFlashdata('errors', 'Solde MVOLA insuffisant');
|
||||
// return redirect()->to('recouvrement/');
|
||||
// }
|
||||
|
||||
if ($validation->run($validationData)) {
|
||||
// // Prepare data
|
||||
$session = session();
|
||||
$users = $session->get('user');
|
||||
$data = [
|
||||
'recouvrement_montant' => $this->request->getPost('recouvrement_montant'),
|
||||
'recouvrement_date' => $this->request->getPost('recouvrement_date'),
|
||||
'recouvrement_personnel' => $fullname,
|
||||
'get_money' => $this->request->getPost('get_mode'),
|
||||
'send_money' => $this->request->getPost('send_mode'),
|
||||
'user_id' => $users['id'],
|
||||
'store_id' => $users['store_id'],
|
||||
|
||||
];
|
||||
|
||||
if ($Recouvrement->addRecouvrement($data)) {
|
||||
$Notification->createNotification("Un nouveau recouvrement a été crée", "Direction", (int)$users["store_id"], 'recouvrement');
|
||||
$response['success'] = true;
|
||||
$response['messages'] = 'Recouvrement créé avec succès';
|
||||
} else {
|
||||
$response['success'] = false;
|
||||
$response['messages'] = 'Erreur lors de la création du recouvrement.';
|
||||
}
|
||||
} else {
|
||||
// Validation failed, return error messages
|
||||
$response['success'] = false;
|
||||
$response['messages'] = $validation->getErrors();
|
||||
}
|
||||
|
||||
return $this->response->setJSON($response);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function updateRecouvrement($recouvrement_id)
|
||||
{
|
||||
$this->verifyRole('updateRecouvrement');
|
||||
|
||||
$data['page_title'] = $this->pageTitle;
|
||||
|
||||
// Load validation service
|
||||
$validation = \Config\Services::validation();
|
||||
|
||||
// Set validation rules
|
||||
$validation->setRules([
|
||||
'product[]' => 'required'
|
||||
]);
|
||||
|
||||
$validationData = [
|
||||
'product[]' => $this->request->getPost('product[]')
|
||||
];
|
||||
|
||||
$Recouvrement = new Recouvrement();
|
||||
// $recouvrement_id = (int) $this->request->getPost('recouvrement_id');
|
||||
if ($this->request->getMethod() === 'post') {
|
||||
$data = [
|
||||
'recouvrement_montant' => (int) $this->request->getPost('recouvrement_montant_edit'),
|
||||
'recouvrement_date' => $this->request->getPost('recouvrement_date_edit')
|
||||
|
||||
];
|
||||
if ($Recouvrement->updateRecouvrement($recouvrement_id, $data)) {
|
||||
// $Notification->createNotification("Un nouveau recouvrement crée", "Conseil", $users['store_id'], 'recouvrement');
|
||||
return $this->response->setJSON([
|
||||
'success' => true,
|
||||
'messages' => 'Recouvrement modifié avec succès !'
|
||||
]);
|
||||
} else {
|
||||
return $this->response->setJSON([
|
||||
'success' => false,
|
||||
'messages' => 'Erreur lors de la modification du recouvrement.'
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function fetchRecouvrementSingle($id)
|
||||
{
|
||||
// die(var_dump('hghjbhj'));
|
||||
if ($id) {
|
||||
$recouvrement = new Recouvrement();
|
||||
|
||||
$data = $recouvrement->getRecouvrementSingle($id);
|
||||
echo json_encode($data);
|
||||
}
|
||||
}
|
||||
|
||||
public function fetchTotalRecouvrementData() {
|
||||
helper(['url', 'form']);
|
||||
$Recouvrement = new Recouvrement();
|
||||
$start_date = $this->request->getGet('start_date');
|
||||
$end_date = $this->request->getGet('end_date');
|
||||
if ($start_date && $end_date) {
|
||||
|
||||
// Initialiser les variables pour DataTables
|
||||
$draw = intval($this->request->getVar('draw'));
|
||||
$session = session();
|
||||
$users = $session->get('user');
|
||||
if($users['group_name'] === "Caissière"){
|
||||
$data = $Recouvrement->getTotalRecouvrements($users['id'] );
|
||||
|
||||
$result = [
|
||||
"draw" => $draw,
|
||||
"recordsTotal" => 1,
|
||||
"recordsFiltered" => 1,
|
||||
"data" => []
|
||||
];
|
||||
|
||||
$totalRecouvrement = $Recouvrement->getTotalRecouvrements($users['id'], $start_date, $end_date );
|
||||
$total_recouvrement_me = $totalRecouvrement->me;
|
||||
$total_recouvrement_bm = $totalRecouvrement->bm;
|
||||
$total_recouvrement_be = $totalRecouvrement->be;
|
||||
$total_recouvrement_mb = $totalRecouvrement->mb;
|
||||
$total_recouvrement = $total_recouvrement_me + $total_recouvrement_me + $total_recouvrement_be + $total_recouvrement_mb;
|
||||
$data = [
|
||||
number_format($total_recouvrement_me,0,'.',' '),
|
||||
number_format($total_recouvrement_bm,0,'.',' '),
|
||||
number_format($total_recouvrement_be,0,'.',' '),
|
||||
number_format($total_recouvrement_mb,0,'.',' '),
|
||||
number_format($total_recouvrement,0,'.',' '),
|
||||
];
|
||||
}
|
||||
return $this->response->setJSON($result);
|
||||
}
|
||||
// Initialiser les variables pour DataTables
|
||||
$draw = intval($this->request->getVar('draw'));
|
||||
$session = session();
|
||||
$users = $session->get('user');
|
||||
if($users['group_name'] === "Caissière"){
|
||||
$data = $Recouvrement->getTotalRecouvrements($users['id'] );
|
||||
|
||||
$result = [
|
||||
"draw" => $draw,
|
||||
"recordsTotal" => 1,
|
||||
"recordsFiltered" => 1,
|
||||
"data" => []
|
||||
];
|
||||
$totalRecouvrement = $Recouvrement->getTotalRecouvrements($users['id'] );
|
||||
$total_recouvrement_me = $totalRecouvrement->me;
|
||||
$total_recouvrement_bm = $totalRecouvrement->bm;
|
||||
$total_recouvrement_be = $totalRecouvrement->be;
|
||||
$total_recouvrement_mb = $totalRecouvrement->mb;
|
||||
$total_recouvrement = $total_recouvrement_me + $total_recouvrement_me + $total_recouvrement_be + $total_recouvrement_mb;
|
||||
$data = [
|
||||
number_format($total_recouvrement_me,0,'.',' '),
|
||||
number_format($total_recouvrement_bm,0,'.',' '),
|
||||
number_format($total_recouvrement_be,0,'.',' '),
|
||||
number_format($total_recouvrement_mb,0,'.',' '),
|
||||
number_format($total_recouvrement,0,'.',' '),
|
||||
];
|
||||
}
|
||||
return $this->response->setJSON($result);
|
||||
}
|
||||
}
|
||||
129
app/Controllers/RemiseController.php
Normal file
129
app/Controllers/RemiseController.php
Normal file
@ -0,0 +1,129 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Controllers\AdminController;
|
||||
use App\Models\Notification;
|
||||
use App\Models\Orders;
|
||||
use App\Models\Remise;
|
||||
|
||||
class RemiseController extends AdminController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
private $pageTitle = 'Remise';
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->verifyRole('viewRemise');
|
||||
|
||||
$data = json_decode($this->fetchTotal(),true);
|
||||
|
||||
$this->render_template('demande/index', $data);
|
||||
}
|
||||
|
||||
|
||||
public function fetchTotal(){
|
||||
$data = [
|
||||
'user_permission' => $this->permission,
|
||||
'page_title' => $this->pageTitle
|
||||
];
|
||||
return json_encode($data);
|
||||
}
|
||||
|
||||
|
||||
public function fetchRemiseData()
|
||||
{
|
||||
helper(['url', 'form']);
|
||||
$Remise = new Remise(); // Assure-toi du bon namespace
|
||||
|
||||
$draw = intval($this->request->getVar('draw'));
|
||||
$data = $Remise->getAllDemandeRemiseToday();
|
||||
$totalRecords = count($data);
|
||||
|
||||
$result = [
|
||||
"draw" => $draw,
|
||||
"recordsTotal" => $totalRecords,
|
||||
"recordsFiltered" => $totalRecords,
|
||||
"data" => []
|
||||
];
|
||||
foreach ($data as $key => $value) {
|
||||
$buttons = '';
|
||||
|
||||
if (in_array('validateRemise', $this->permission) && $value['demande_status'] == 'En attente') {
|
||||
$buttons .= '<button type="submit" class="btn btn-success" onclick="valideFunc(' . $value['id_demande'] . ')">';
|
||||
$buttons .= '<i class="fa fa-check-circle"></i>';
|
||||
$buttons .= '</button>';
|
||||
}
|
||||
|
||||
if (in_array('refusedRemise', $this->permission) && $value['demande_status'] == 'En attente') {
|
||||
$buttons .= ' <button type="button" class="btn btn-danger" onclick="refuseFunc(' . $value['id_demande'] . ')">';
|
||||
$buttons .= '<i class="fa fa-times-circle"></i>';
|
||||
$buttons .= '</button>';
|
||||
}
|
||||
// die(var_dump($value));
|
||||
$result['data'][$key] = [
|
||||
$value['id_demande'],
|
||||
$value['product'],
|
||||
number_format($value['total_price'], 0, '.', ' '),
|
||||
number_format($value['montant_demande'], 0, '.', ' '),
|
||||
$value['demande_status'],
|
||||
$buttons
|
||||
];
|
||||
}
|
||||
|
||||
return $this->response->setJSON($result);
|
||||
}
|
||||
|
||||
|
||||
public function updateRemise($id_demande) {
|
||||
$this->verifyRole('validateRemise');
|
||||
|
||||
// Load validation service
|
||||
$validation = \Config\Services::validation();
|
||||
|
||||
$data['page_title'] = $this->pageTitle;
|
||||
|
||||
$validation->setRules([
|
||||
'demande_status' => 'required'
|
||||
]);
|
||||
|
||||
$validationData = [
|
||||
'demande_status' => $this->request->getPost('demande_status')
|
||||
];
|
||||
$data = [
|
||||
'demande_status' => $this->request->getPost('demande_status')
|
||||
];
|
||||
|
||||
$Remise = new Remise();
|
||||
if ($this->request->getMethod()=='post') {
|
||||
$today = date('Y-m-d');
|
||||
$data = [
|
||||
'demande_status' => $this->request->getPost('demande_status'),
|
||||
'date_demande' => $today,
|
||||
];
|
||||
|
||||
if ($Remise->updateRemise($id_demande, $data)) {
|
||||
$remise_product = $Remise->getProductByDemandeId($id_demande);
|
||||
$Notification = new NotificationController();
|
||||
$session = session();
|
||||
$users = $session->get('user');
|
||||
$Notification->createNotification("Une demande de remise a été " . $this->request->getPost('demande_status')." Pour le produit: ".$remise_product,"Caissière",(int)$users['store_id'],'remise/');
|
||||
return $this->response->setJSON([
|
||||
'success' => true,
|
||||
'messages' => 'Vous avez '.$this->request->getPost('demande_status').' la remise'
|
||||
]);
|
||||
} else {
|
||||
return $this->response->setJSON([
|
||||
'success' => false,
|
||||
'messages' => 'Erreur lors de la modification de la remise.'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
336
app/Controllers/ReportController.php
Normal file
336
app/Controllers/ReportController.php
Normal file
@ -0,0 +1,336 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use DateTime;
|
||||
use App\Models\Orders;
|
||||
use App\Models\Stores;
|
||||
use App\Models\Reports;
|
||||
use App\Models\Products;
|
||||
use App\Models\OrderItems;
|
||||
|
||||
class ReportController extends AdminController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
private $pageTitle = 'Reports';
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->verifyRole('viewReports');
|
||||
$data['page_title'] = $this->pageTitle;
|
||||
|
||||
// Get the current year or the selected year from the form
|
||||
$today_year = date('Y');
|
||||
if ($this->request->getPost('select_year')) {
|
||||
$today_year = $this->request->getPost('select_year');
|
||||
}
|
||||
|
||||
// Fetch order data and years
|
||||
$Reports = new Reports();
|
||||
$Orders = new Orders();
|
||||
$Store = new Stores();
|
||||
$parking_data = $Reports->getOrderData($today_year);
|
||||
$data['report_years'] = $Reports->getOrderYear();
|
||||
|
||||
// Process the parking data and calculate total amounts
|
||||
$final_parking_data = [];
|
||||
foreach ($parking_data as $month => $orders) {
|
||||
$total_amount_earned = 0; // Initialize the total amount for the month
|
||||
|
||||
if (!empty($orders)) {
|
||||
foreach ($orders as $order) {
|
||||
$total_amount_earned += (float) $order['net_amount'];
|
||||
}
|
||||
}
|
||||
|
||||
$final_parking_data[$month] = $total_amount_earned;
|
||||
}
|
||||
|
||||
// Data for the camembert (pie chart)
|
||||
$paymentModes = $Orders->getPaymentModes();
|
||||
$total_mvola1 = $paymentModes->total_mvola1;
|
||||
$total_mvola2 = $paymentModes->total_mvola2;
|
||||
$total_espece1 = $paymentModes->total_espece1;
|
||||
$total_espece2 = $paymentModes->total_espece2;
|
||||
$total_banque1 = $paymentModes->total_virement_bancaire1;
|
||||
$total_banque2 = $paymentModes->total_virement_bancaire2;
|
||||
$total_mvola = $total_mvola1 + $total_mvola2;
|
||||
$total_banque = $total_banque1 + $total_banque2;
|
||||
$total_espece = $total_espece1 + $total_espece2;
|
||||
$totalOrders = $Orders->getTotalOrders();
|
||||
$totalAmountPerPaymentModes = ["MVOLA" => $total_mvola, "Espece" => $total_espece, "Virement Bancaire" => $total_banque];
|
||||
$totalOrdersCount = (int) $totalOrders->total_orders;
|
||||
$labels = [];
|
||||
$totals = [];
|
||||
|
||||
if ($totalOrdersCount > 0) {
|
||||
foreach ($totalAmountPerPaymentModes as $mode => $total) {
|
||||
$labels[] = $mode;
|
||||
$totals[] = $total;
|
||||
}
|
||||
}
|
||||
|
||||
$data['labels'] = json_encode($labels);
|
||||
$data['totals'] = json_encode($totals);
|
||||
|
||||
// Prepare data for product chart
|
||||
$OrderItem = new OrderItems();
|
||||
$productTable = $OrderItem->getAllSoldProductToday();
|
||||
|
||||
$product_sold = (int) $productTable->total_product_sold;
|
||||
$unsold_product = (int) $productTable->total_unsold_product;
|
||||
|
||||
$labels1 = ["Produits vendus", "Produits non vendus"];
|
||||
$totals2 = [$product_sold, $unsold_product];
|
||||
|
||||
$data['labels_product'] = json_encode($labels1);
|
||||
$data['totals_product'] = json_encode($totals2);
|
||||
|
||||
// Prepare data for the view
|
||||
$data['selected_year'] = $today_year;
|
||||
$data['company_currency'] = $this->companycurrency();
|
||||
$data['results'] = $final_parking_data;
|
||||
|
||||
// Data for the camembert in dashboard
|
||||
$totalStoreOrder = $Orders->getTotalOrderPerStore();
|
||||
$totalOrders = $Orders->getTotalOrders();
|
||||
$totalOrdersCount = (int) $totalOrders->total_orders;
|
||||
|
||||
// Initialisation des variables pour éviter l'erreur "Undefined variable"
|
||||
$labelStore = [];
|
||||
$totalPerStore = [];
|
||||
|
||||
foreach ($totalStoreOrder as $totalOrdersInStore) {
|
||||
$storeList = $Store->getStoreById($totalOrdersInStore->store_id);
|
||||
$labelStore[] = $storeList->name ?? 'Inconnu';
|
||||
$totalPerStore[] = ((int) $totalOrdersInStore->total / $totalOrdersCount) * 100;
|
||||
}
|
||||
|
||||
$data['labelStore'] = json_encode($labelStore);
|
||||
$data['totalPerStore'] = json_encode($totalPerStore);
|
||||
|
||||
// Load the view
|
||||
return $this->render_template('reports/index', $data);
|
||||
}
|
||||
|
||||
private function companycurrency()
|
||||
{
|
||||
return 'AR'; // Replace with your actual logic for company currency
|
||||
}
|
||||
|
||||
public function stockDetail()
|
||||
{
|
||||
$this->verifyRole('viewReports');
|
||||
$data['page_title'] = $this->pageTitle;
|
||||
$Orders = new Orders();
|
||||
$Products = new Products();
|
||||
$Stores = new Stores();
|
||||
$productVente = $Orders->getTotalProductvente();
|
||||
$produitStock = $Products->getProductData();
|
||||
$stor = $Stores->getActiveStore();
|
||||
|
||||
$data['ventes'] = \json_encode($productVente);
|
||||
$data['stock'] = \json_encode($produitStock);
|
||||
$data['stores'] = $stor;
|
||||
|
||||
// echo '<pre>';
|
||||
// die(var_dump($produitStock));
|
||||
|
||||
return $this->render_template('reports/stockDetail', $data);
|
||||
}
|
||||
|
||||
private function returnName(int $id)
|
||||
{
|
||||
$Stores = new Stores();
|
||||
$stor = $Stores->getActiveStore();
|
||||
$Storename = "";
|
||||
foreach ($stor as $key => $value) {
|
||||
if ($value['id'] == $id) {
|
||||
$Storename = $value['name'];
|
||||
}
|
||||
}
|
||||
|
||||
return $Storename;
|
||||
}
|
||||
|
||||
public function fetchProductSodled(int $id)
|
||||
{
|
||||
$Orders = new Orders();
|
||||
|
||||
$productVente = $Orders->getTotalProductvente2($id);
|
||||
$result = ['data' => []];
|
||||
|
||||
foreach ($productVente as $key => $value) {
|
||||
// die(var_dump($value)); // Debugging: Check what $value contains
|
||||
|
||||
// Add the row data
|
||||
$result['data'][$key] = [
|
||||
$value->sku,
|
||||
$value->date_time,
|
||||
$this->returnName($value->store_id)
|
||||
];
|
||||
}
|
||||
|
||||
// Return data in JSON format
|
||||
return $this->response->setJSON($result);
|
||||
}
|
||||
|
||||
private function checkArrivalDate($dateArivage)
|
||||
{
|
||||
$dateArivage = new DateTime($dateArivage);
|
||||
$today = new DateTime();
|
||||
$interval = $dateArivage->diff($today);
|
||||
|
||||
// Return the date only if it is within the last 15 days
|
||||
return $interval->days . " Jours";
|
||||
}
|
||||
|
||||
public function fetchProductStock(int $id)
|
||||
{
|
||||
$Products = new Products();
|
||||
|
||||
$produitStock = $Products->getProductData2($id);
|
||||
$result = ['data' => []];
|
||||
|
||||
foreach ($produitStock as $key => $value) {
|
||||
// die(var_dump($value)); // Debugging: Check what $value contains
|
||||
|
||||
// Add the row data
|
||||
$result['data'][$key] = [
|
||||
$value['brand_name'],
|
||||
$value['total_product'] . " Motos",
|
||||
$this->returnName($value['store_id'])
|
||||
];
|
||||
}
|
||||
|
||||
// Return data in JSON format
|
||||
return $this->response->setJSON($result);
|
||||
}
|
||||
|
||||
public function fetchProductStock2(int $id)
|
||||
{
|
||||
$Products = new Orders();
|
||||
|
||||
$produitStock = $Products->getOrderVendue();
|
||||
$result = ['data' => []];
|
||||
// echo '<pre>';
|
||||
// die(var_dump($produitStock));
|
||||
|
||||
foreach ($produitStock as $key => $value) {
|
||||
// die(var_dump($value)); // Debugging: Check what $value contains
|
||||
|
||||
// Add the row data
|
||||
$result['data'][$key] = [
|
||||
$value['sku'],
|
||||
$value['qty'],
|
||||
$value['totalNet'],
|
||||
(new DateTime($value['DateTime']))->format('Y-m-d'),
|
||||
$this->returnName($value['store_id'])
|
||||
];
|
||||
}
|
||||
|
||||
// Return data in JSON format
|
||||
return $this->response->setJSON($result);
|
||||
}
|
||||
|
||||
public function performancedetail()
|
||||
{
|
||||
$this->verifyRole('viewReports');
|
||||
$data['page_title'] = $this->pageTitle;
|
||||
$Stores = new Stores();
|
||||
|
||||
// echo '<pre>';
|
||||
// die(var_dump($orderTest));
|
||||
$data['stores'] = $Stores->getActiveStore();
|
||||
|
||||
return $this->render_template('reports/performance', $data);
|
||||
}
|
||||
|
||||
public function fetchPerformances()
|
||||
{
|
||||
$result = ['data' => []];
|
||||
$Orders = new Orders();
|
||||
$session = session();
|
||||
$users = $session->get('user');
|
||||
if ($users['group_name'] === "Conseil" || $users['group_name'] === "Direction" ) {
|
||||
$orderPaid = $Orders->getPerformanceByOrders();
|
||||
foreach ($orderPaid as $key => $value) {
|
||||
$benefice =
|
||||
$result['data'][$key] = [
|
||||
$value['firstname'] . ' ' . $value['lastname'],
|
||||
$value['email'],
|
||||
($value['sku'] == "" ? $value['motoname'] : $value['sku']),
|
||||
(new DateTime($value['datevente']))->format('Y-m-d'),
|
||||
number_format($value['price'],0,'.',' '),
|
||||
number_format($value['prix_vente'],0,'.',' '),
|
||||
$this->returnName($value['store_id']),
|
||||
number_format($value['prix_vente'] - $value['price'],0,'.',' '),
|
||||
];
|
||||
}
|
||||
|
||||
// Return data in JSON format
|
||||
return $this->response->setJSON($result);
|
||||
}
|
||||
if ($users['group_name'] === "Conseil" || $users['group_name'] === "Direction") {
|
||||
$orderPaid = $Orders->getPerformanceByOrders1();
|
||||
foreach ($orderPaid as $key => $value) {
|
||||
$benefice =
|
||||
$result['data'][$key] = [
|
||||
$value['firstname'] . ' ' . $value['lastname'],
|
||||
$value['email'],
|
||||
($value['sku'] == "" ? $value['motoname'] : $value['sku']),
|
||||
(new DateTime($value['datevente']))->format('Y-m-d'),
|
||||
number_format($value['price'],0,'.',' '),
|
||||
number_format($value['prix_vente'],0,'.',' '),
|
||||
$this->returnName($value['store_id']),
|
||||
number_format($value['prix_vente'] - $value['price'],0,'.',' '),
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
// Return data in JSON format
|
||||
return $this->response->setJSON($result);
|
||||
}
|
||||
if ($users['group_name'] === "COMMERCIALE") {
|
||||
$orderPaid = $Orders->getPerformanceByOrders2();
|
||||
foreach ($orderPaid as $key => $value) {
|
||||
$benefice =
|
||||
$result['data'][$key] = [
|
||||
$value['firstname'] . ' ' . $value['lastname'],
|
||||
($value['sku'] == "" ? $value['motoname'] : $value['sku']),
|
||||
(new DateTime($value['datevente']))->format('Y-m-d'),
|
||||
number_format($value['prix_vente'],0,'.',' '),
|
||||
];
|
||||
}
|
||||
|
||||
// Return data in JSON format
|
||||
return $this->response->setJSON($result);
|
||||
}
|
||||
|
||||
if ($users['group_name'] === "Cheffe d'Agence") {
|
||||
$orderPaid = $Orders->getPerformanceByOrders1();
|
||||
foreach ($orderPaid as $key => $value) {
|
||||
$benefice =
|
||||
$result['data'][$key] = [
|
||||
$value['firstname'] . ' ' . $value['lastname'],
|
||||
($value['sku'] == "" ? $value['motoname'] : $value['sku']),
|
||||
(new DateTime($value['datevente']))->format('Y-m-d'),
|
||||
number_format($value['prix_vente'],0,'.',' '),
|
||||
];
|
||||
}
|
||||
|
||||
// Return data in JSON format
|
||||
return $this->response->setJSON($result);
|
||||
}
|
||||
}
|
||||
|
||||
public function fetchmecperformance()
|
||||
{
|
||||
$result = ['data'=> []];
|
||||
|
||||
}
|
||||
}
|
||||
32
app/Controllers/ReservationController.php
Normal file
32
app/Controllers/ReservationController.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Models\Products;
|
||||
|
||||
class ReservationController extends AdminController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
private $pageTitle = "Reservation";
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->verifyRole('viewOrder');
|
||||
$Products = new Products();
|
||||
$userIfo = session()->get('user');
|
||||
$store_id = $userIfo['store_id'];
|
||||
$dataProducts = $Products->getProductData2($store_id);
|
||||
$data['page_title'] = $this->pageTitle;
|
||||
// die(var_dump($dataProducts));
|
||||
$data['product'] = $dataProducts;
|
||||
|
||||
return $this->render_template('reservation/index', $data);
|
||||
}
|
||||
public function addReservation()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
150
app/Controllers/SecuriteController.php
Normal file
150
app/Controllers/SecuriteController.php
Normal file
@ -0,0 +1,150 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Models\Securite;
|
||||
use App\Models\Products;
|
||||
use App\Models\Orders;
|
||||
use App\Models\Stores;
|
||||
|
||||
class SecuriteController extends AdminController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
helper(['form', 'url']);
|
||||
}
|
||||
|
||||
private $pageTitle = 'Validation sortie motos';
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->verifyRole('viewSecurite');
|
||||
$data['page_title'] = $this->pageTitle;
|
||||
|
||||
return $this->render_template('securite/index', $data);
|
||||
}
|
||||
|
||||
public function fetchSecuriteData()
|
||||
{
|
||||
$securiteModel = new Securite();
|
||||
$Products = new Products();
|
||||
$securites = $securiteModel->getAllSecuriteData();
|
||||
$result = ['data' => []];
|
||||
|
||||
foreach ($securites as $securite) {
|
||||
if ($securite['status'] === 'PENDING') {
|
||||
$product = $Products->getProductData($securite['product_id']);
|
||||
if (! $product) continue;
|
||||
|
||||
// Bouton d’action
|
||||
$buttons = in_array('validateCommande1', $this->permission)
|
||||
? '<button type="button" class="btn btn-success" onclick="editFunc(' . $securite['id'] . ')" data-toggle="modal" data-target="#editModal"><i class="fa fa-check"></i></button>'
|
||||
: '';
|
||||
|
||||
// Statut
|
||||
$statut = '<span class="label label-warning">EN ATTENTE DE VALIDATION</span>';
|
||||
|
||||
// Image
|
||||
$img = '<img src="' . base_url('assets/images/product_image/' . $product['image']) . '" '
|
||||
. 'alt="' . esc($product['name']) . '" class="img-circle" width="50" height="50" />';
|
||||
|
||||
$result['data'][] = [
|
||||
'image' => $img,
|
||||
'ugs' => esc($product['sku']),
|
||||
'designation' => esc($product['name']),
|
||||
'statut' => $statut,
|
||||
'action' => $buttons
|
||||
];
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return $this->response->setJSON($result);
|
||||
}
|
||||
|
||||
public function fetchSecuriteDataById($id)
|
||||
{
|
||||
|
||||
if ($id) {
|
||||
$Securite = new Securite();
|
||||
$Orders = new Orders();
|
||||
$Products = new Products();
|
||||
|
||||
$data = $Securite->getSecuriteData($id);
|
||||
$order_data = $Orders->getOrdersDataByBillNo($data['bill_no']);
|
||||
$product = $Products->getProductData($data['product_id']);
|
||||
|
||||
$response = [
|
||||
'image' => base_url('assets/images/product_image/' . $product['image']),
|
||||
'nom' => $product['name'],
|
||||
'ugs' => $product['sku'],
|
||||
'bill_no' => $data['bill_no'],
|
||||
'customer_name' => $order_data['customer_name'],
|
||||
'customer_address' => $order_data['customer_address'],
|
||||
'customer_phone' => $order_data['customer_phone'],
|
||||
'customer_cin' => $order_data['customer_cin'],
|
||||
];
|
||||
|
||||
return $this->response->setJSON($response);
|
||||
}
|
||||
}
|
||||
|
||||
public function update(int $id)
|
||||
{
|
||||
$this->verifyRole('updateCommande1');
|
||||
$storeModel = new Securite();
|
||||
$post = $this->request->getPost();
|
||||
$response = [];
|
||||
|
||||
if ($id && isset($post['status'])) {
|
||||
$data = [
|
||||
'status' => $post['status'],
|
||||
'active' => 0
|
||||
];
|
||||
$session = session();
|
||||
$users = $session->get('user');
|
||||
$Notification = new NotificationController();
|
||||
if ($storeModel->updateSecurite($data, $id)) {
|
||||
if ($post['status'] === "Validé") {
|
||||
$Notification->createNotification('Une commande a été validé', "COMMERCIALE",(int)$users['store_id'], 'orders');
|
||||
}
|
||||
$response = ['success' => true, 'messages' => 'Mise à jour réussie'];
|
||||
} else {
|
||||
$response = ['success' => false, 'messages' => 'Erreur en base lors de la mise à jour'];
|
||||
}
|
||||
} else {
|
||||
$response = ['success' => false, 'messages' => 'ID ou statut manquant'];
|
||||
}
|
||||
|
||||
return $this->response->setJSON($response);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function remove()
|
||||
{
|
||||
$this->verifyRole('deleteCommande1');
|
||||
$response = [];
|
||||
|
||||
$storeId = $this->request->getPost('store_id');
|
||||
|
||||
if ($storeId) {
|
||||
$storeModel = new Stores();
|
||||
|
||||
if ($storeModel->delete($storeId)) {
|
||||
$response['success'] = true;
|
||||
$response['messages'] = "Supprimé avec succès";
|
||||
} else {
|
||||
$response['success'] = false;
|
||||
$response['messages'] = "Erreur dans la base de données lors de la suppression des informations sur la marque";
|
||||
}
|
||||
|
||||
} else {
|
||||
$response['success'] = false;
|
||||
$response['messages'] = "Référez à nouveau la page !!";
|
||||
}
|
||||
|
||||
return $this->response->setJSON($response);
|
||||
}
|
||||
}
|
||||
672
app/Controllers/SortieCaisseController.php
Normal file
672
app/Controllers/SortieCaisseController.php
Normal file
@ -0,0 +1,672 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Controllers\AdminController;
|
||||
use App\Models\SortieCaisse;
|
||||
use App\Models\Orders;
|
||||
use App\Models\Recouvrement;
|
||||
use App\Models\Stores;
|
||||
|
||||
class SortieCaisseController extends AdminController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
private $mapping = [
|
||||
// ----- Raisons Admin -----
|
||||
"Achat de matériel informatique" => [
|
||||
'source_fond' => 'Budget Directionnel',
|
||||
'initiateur_demande' => 'Direction'
|
||||
],
|
||||
"Achat équipement de sécurité" => [
|
||||
'source_fond' => 'Budget Directionnel',
|
||||
'initiateur_demande' => 'Direction'
|
||||
],
|
||||
"Achat mobilier de bureau" => [
|
||||
'source_fond' => 'Budget Directionnel',
|
||||
'initiateur_demande' => 'Direction'
|
||||
],
|
||||
"Paiement salaire des collaborateurs" => [
|
||||
'source_fond' => 'Budget Directionnel',
|
||||
'initiateur_demande' => 'Direction'
|
||||
],
|
||||
"Cotisation sociales" => [
|
||||
'source_fond' => 'Budget Directionnel',
|
||||
'initiateur_demande' => 'Direction'
|
||||
],
|
||||
"Remboursement d'avance moto" => [
|
||||
'source_fond' => 'Budget Directionnel',
|
||||
'initiateur_demande' => 'Direction'
|
||||
],
|
||||
"Payement prime ou endemnité" => [
|
||||
'source_fond' => 'Budget Directionnel',
|
||||
'initiateur_demande' => 'Direction'
|
||||
],
|
||||
"Paiement sous-traitant" => [
|
||||
'source_fond' => 'Budget Directionnel',
|
||||
'initiateur_demande' => 'Direction'
|
||||
],
|
||||
"Frais de formation" => [
|
||||
'source_fond' => 'Budget Directionnel',
|
||||
'initiateur_demande' => 'Direction'
|
||||
],
|
||||
"Paiement loyer" => [
|
||||
'source_fond' => 'Budget Directionnel',
|
||||
'initiateur_demande' => 'Direction'
|
||||
],
|
||||
"Frais de formation externe" => [
|
||||
'source_fond' => 'Budget Directionnel',
|
||||
'initiateur_demande' => 'Direction'
|
||||
],
|
||||
"Abonnement internet" => [
|
||||
'source_fond' => 'Budget Directionnel',
|
||||
'initiateur_demande' => 'Direction'
|
||||
],
|
||||
"Entretien locaux" => [
|
||||
'source_fond' => 'Budget Directionnel',
|
||||
'initiateur_demande' => 'Direction'
|
||||
],
|
||||
"Paiement fournisseur" => [
|
||||
'source_fond' => 'Budget Directionnel',
|
||||
'initiateur_demande' => 'Direction'
|
||||
],
|
||||
"Remboursement de frais" => [
|
||||
'source_fond' => 'Budget Directionnel',
|
||||
'initiateur_demande' => 'Direction'
|
||||
],
|
||||
"Paiement assurance" => [
|
||||
'source_fond' => 'Budget Directionnel',
|
||||
'initiateur_demande' => 'Direction'
|
||||
],
|
||||
"Réparation immobilisation" => [
|
||||
'source_fond' => 'Budget Directionnel',
|
||||
'initiateur_demande' => 'Direction'
|
||||
],
|
||||
"DVD" => [
|
||||
'source_fond' => 'Budget Directionnel',
|
||||
'initiateur_demande' => 'Direction'
|
||||
],
|
||||
"Déclaration fiscale - Déclaration d'impôts" => [
|
||||
'source_fond' => 'Budget Directionnel',
|
||||
'initiateur_demande' => 'Direction'
|
||||
],
|
||||
"Enregistrement des contrats de bail au centre fiscal" => [
|
||||
'source_fond' => 'Budget Directionnel',
|
||||
'initiateur_demande' => 'Direction'
|
||||
],
|
||||
|
||||
// ----- Raisons Caissier -----
|
||||
"Achat materiel - Réparation immobilisation" => [
|
||||
'source_fond' => 'Caisse Courante',
|
||||
'initiateur_demande' => 'Caissière'
|
||||
],
|
||||
"Réparation matériel" => [
|
||||
'source_fond' => 'Caisse Courante',
|
||||
'initiateur_demande' => 'Caissière'
|
||||
],
|
||||
"Maintenance équipement" => [
|
||||
'source_fond' => 'Caisse Courante',
|
||||
'initiateur_demande' => 'Caissière'
|
||||
],
|
||||
"Achats de Matériaux et Fournitures" => [
|
||||
'source_fond' => 'Caisse Courante',
|
||||
'initiateur_demande' => 'Caissière'
|
||||
],
|
||||
"Achat produits de nettoyage" => [
|
||||
'source_fond' => 'Caisse Courante',
|
||||
'initiateur_demande' => 'Caissière'
|
||||
],
|
||||
"Achat consommable informatique" => [
|
||||
'source_fond' => 'Caisse Courante',
|
||||
'initiateur_demande' => 'Caissière'
|
||||
],
|
||||
"Achat petit outillage" => [
|
||||
'source_fond' => 'Caisse Courante',
|
||||
'initiateur_demande' => 'Caissière'
|
||||
],
|
||||
"Avance à un prestataire" => [
|
||||
'source_fond' => 'Caisse Courante',
|
||||
'initiateur_demande' => 'Caissière'
|
||||
],
|
||||
"Payement prestataire" => [
|
||||
'source_fond' => 'Caisse Courante',
|
||||
'initiateur_demande' => 'Caissière'
|
||||
],
|
||||
"Payement éléctricité" => [
|
||||
'source_fond' => 'Caisse Courante',
|
||||
'initiateur_demande' => 'Caissière'
|
||||
],
|
||||
"Frais de mission - Déplacement" => [
|
||||
'source_fond' => 'Caisse Courante',
|
||||
'initiateur_demande' => 'Caissière'
|
||||
],
|
||||
"Achat de carburant" => [
|
||||
'source_fond' => 'Caisse Courante',
|
||||
'initiateur_demande' => 'Caissière'
|
||||
],
|
||||
"Paiement transport marchandise" => [
|
||||
'source_fond' => 'Caisse Courante',
|
||||
'initiateur_demande' => 'Caissière'
|
||||
],
|
||||
"Achat pièces pour réparation moto" => [
|
||||
'source_fond' => 'Caisse Courante',
|
||||
'initiateur_demande' => 'Caissière'
|
||||
],
|
||||
];
|
||||
|
||||
|
||||
private $pageTitle = 'Décaissement';
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->verifyRole('viewSortieCaisse');
|
||||
$admin_options = [
|
||||
"Achat de matériel informatique",
|
||||
"Achat équipement de sécurité",
|
||||
"Achat mobilier de bureau",
|
||||
"Paiement salaire des collaborateurs",
|
||||
"Cotisation sociales",
|
||||
"Remboursement d'avance moto",
|
||||
"Payement prime ou endemnité",
|
||||
"Paiement sous-traitant",
|
||||
"Frais de formation",
|
||||
"Paiement loyer",
|
||||
"Frais de formation externe",
|
||||
"Abonnement internet",
|
||||
"Entretien locaux",
|
||||
"Paiement fournisseur",
|
||||
"Remboursement de frais",
|
||||
"Paiement assurance",
|
||||
"Réparation immobilisation",
|
||||
"DVD",
|
||||
"Déclaration fiscale - Déclaration d'impôts",
|
||||
"Enregistrement des contrats de bail au centre fiscal"
|
||||
];
|
||||
|
||||
$caissier_options = [
|
||||
"Achat materiel - Réparation immobilisation",
|
||||
"Réparation matériel",
|
||||
"Maintenance équipement",
|
||||
"Achats de Matériaux et Fournitures",
|
||||
"Achat produits de nettoyage",
|
||||
"Achat consommable informatique",
|
||||
"Achat petit outillage",
|
||||
"Avance à un prestataire",
|
||||
"Payement prestataire",
|
||||
"Payement éléctricité",
|
||||
"Frais de mission - Déplacement",
|
||||
"Achat de carburant",
|
||||
"Paiement transport marchandise",
|
||||
"Achat pièces pour réparation moto"
|
||||
];
|
||||
|
||||
$Stores = new Stores();
|
||||
$stor = $Stores->getActiveStore();
|
||||
$data = json_decode($this->fetchTotal(),true);
|
||||
$data['admin_options'] = $admin_options;
|
||||
$data['caissier_options'] = $caissier_options;
|
||||
$data['stores'] = $stor;
|
||||
|
||||
$this->render_template('sortieCaisse/index', $data);
|
||||
}
|
||||
|
||||
// Create an AJAX endpoint to access the fetchTotal() function
|
||||
|
||||
public function fetchTotal(){
|
||||
$data = [
|
||||
'user_permission' => $this->permission,
|
||||
'page_title' => $this->pageTitle
|
||||
];
|
||||
return json_encode($data);
|
||||
}
|
||||
|
||||
|
||||
public function fetchSortieCaisseData()
|
||||
{
|
||||
helper(['url', 'form']);
|
||||
$SortieCaisse = new SortieCaisse();
|
||||
|
||||
// Initialiser les variables pour DataTables
|
||||
$draw = intval($this->request->getVar('draw'));
|
||||
|
||||
$data = $SortieCaisse->getAllSortieCaisse();
|
||||
$totalRecords = count($data);
|
||||
|
||||
$session = session();
|
||||
$users = $session->get('user');
|
||||
$result = [
|
||||
"draw" => $draw,
|
||||
"recordsTotal" => $totalRecords,
|
||||
"recordsFiltered" => $totalRecords,
|
||||
"data" => []
|
||||
];
|
||||
|
||||
foreach ($data as $key => $value) {
|
||||
$buttons = '';
|
||||
if (in_array('updateSortieCaisse', $this->permission) && $value['id_sortie'] == $users['id']) {
|
||||
$buttons .= '<button type="button" class="btn btn-default" onclick="editFunc(' . $value['id_sortie'] . ')" data-toggle="modal" data-target="#updateModal"><i class="fa fa-pencil"></i></button>';
|
||||
}
|
||||
if (in_array('validateSortieCaisse', $this->permission)) {
|
||||
$buttons .= '<button type="button" class="btn btn-default" onclick="validateFunc(' . $value['id_sortie'] . ')"><i class="fa fa-check-circle"></i></button>';
|
||||
}
|
||||
// D'éventuelles autres actions peuvent être ajoutées ici
|
||||
$session = session();
|
||||
$users = $session->get('user');
|
||||
if($users["group_name"] === "Caissière"){
|
||||
$result['data'][$key] = [
|
||||
$value['id_sortie'],
|
||||
number_format($value['montant_retire'], 0, '.', ' '),
|
||||
$value['date_retrait'],
|
||||
$value['sortie_personnel'],
|
||||
$value['motif'],
|
||||
$value['statut'],
|
||||
$value['admin_raison'],
|
||||
$buttons
|
||||
];
|
||||
}
|
||||
elseif ($users["group_name"] === "Direction" || $users["group_name"] === "Conseil") {
|
||||
$result['data'][$key] = [
|
||||
$value['id_sortie'],
|
||||
number_format($value['montant_retire'], 0, '.', ' '),
|
||||
$value['date_retrait'],
|
||||
$value['sortie_personnel'],
|
||||
$value['motif'],
|
||||
$value['source_fond'],
|
||||
$value['initiateur_demande'],
|
||||
$this->returnStoreName($value['store_id']),
|
||||
$value['commentaire'],
|
||||
$value['statut'],
|
||||
$buttons
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
return $this->response->setJSON($result);
|
||||
}
|
||||
|
||||
public function fetchSortieCaisseData1()
|
||||
{
|
||||
helper(['url', 'form']);
|
||||
$SortieCaisse = new SortieCaisse();
|
||||
|
||||
// Initialiser les variables pour DataTables
|
||||
$draw = intval($this->request->getVar('draw'));
|
||||
|
||||
$data = $SortieCaisse->getAllSortieCaisse1();
|
||||
$totalRecords = count($data);
|
||||
|
||||
$session = session();
|
||||
$users = $session->get('user');
|
||||
$result = [
|
||||
"draw" => $draw,
|
||||
"recordsTotal" => $totalRecords,
|
||||
"recordsFiltered" => $totalRecords,
|
||||
"data" => []
|
||||
];
|
||||
|
||||
foreach ($data as $key => $value) {
|
||||
$buttons = '';
|
||||
if (in_array('updateSortieCaisse', $this->permission) && $value['id_sortie'] == $users['id']) {
|
||||
$buttons .= '<button type="button" class="btn btn-default" onclick="editFunc(' . $value['id_sortie'] . ')" data-toggle="modal" data-target="#updateModal"><i class="fa fa-pencil"></i></button>';
|
||||
}
|
||||
if (in_array('validateSortieCaisse', $this->permission)) {
|
||||
$buttons .= '<button type="button" class="btn btn-default" onclick="validateFunc(' . $value['id_sortie'] . ')"><i class="fa fa-check-circle"></i></button>';
|
||||
}
|
||||
// D'éventuelles autres actions peuvent être ajoutées ici
|
||||
$session = session();
|
||||
$users = $session->get('user');
|
||||
if($users["group_name"] === "Caissière"){
|
||||
$result['data'][$key] = [
|
||||
$value['id_sortie'],
|
||||
number_format($value['montant_retire'], 0, '.', ' '),
|
||||
$value['date_retrait'],
|
||||
$value['sortie_personnel'],
|
||||
$value['motif'],
|
||||
$value['statut'],
|
||||
$buttons
|
||||
];
|
||||
}
|
||||
elseif ($users["group_name"] === "Direction" || $users["group_name"] === "Conseil") {
|
||||
$result['data'][$key] = [
|
||||
$value['id_sortie'],
|
||||
number_format($value['montant_retire'], 0, '.', ' '),
|
||||
$value['date_retrait'],
|
||||
$value['sortie_personnel'],
|
||||
$value['motif'],
|
||||
$value['source_fond'],
|
||||
$value['initiateur_demande'],
|
||||
$this->returnStoreName($value['store_id']),
|
||||
$value['commentaire'],
|
||||
$value['statut'],
|
||||
$buttons
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
return $this->response->setJSON($result);
|
||||
}
|
||||
|
||||
|
||||
private function returnStoreName(int $id)
|
||||
{
|
||||
$Stores = new Stores();
|
||||
$stor = $Stores->getActiveStore();
|
||||
$Storename = "";
|
||||
foreach ($stor as $key => $value) {
|
||||
if ($value['id'] == $id) {
|
||||
$Storename = $value['name'];
|
||||
}
|
||||
}
|
||||
|
||||
return $Storename;
|
||||
}
|
||||
|
||||
public function createSortieCaisse()
|
||||
{
|
||||
$this->verifyRole('createSortieCaisse');
|
||||
|
||||
$data['page_title'] = $this->pageTitle;
|
||||
|
||||
$validation = \Config\Services::validation();
|
||||
|
||||
$validation->setRules([
|
||||
'montant_retire' => 'required',
|
||||
'motif' => 'required',
|
||||
]);
|
||||
|
||||
|
||||
$validationData = [
|
||||
'montant_retire' => $this->request->getPost('montant_retire'),
|
||||
'motif' => $this->request->getPost('motif_select'),
|
||||
];
|
||||
|
||||
|
||||
// Set validation rules
|
||||
$orders = new Orders();
|
||||
$Recouvrement = new Recouvrement();
|
||||
$paymentData = $orders->getPaymentModes();
|
||||
$sortieCaisse = new SortieCaisse();
|
||||
$total_sortie_caisse = $sortieCaisse->getTotalSortieCaisse();
|
||||
$total_sortie_caisse1= $total_sortie_caisse->mr;
|
||||
$totalRecouvrement = $Recouvrement->getTotalRecouvrements();
|
||||
//me MVOLA => ESPECE
|
||||
//bm BANQUE => MVOLA
|
||||
//be BANQUE => ESPECE
|
||||
//mb MVOLA => BANQUE
|
||||
$total_recouvrement_me = $totalRecouvrement->me;
|
||||
$total_recouvrement_bm = $totalRecouvrement->bm;
|
||||
$total_recouvrement_be = $totalRecouvrement->be;
|
||||
$total_recouvrement_mb = $totalRecouvrement->mb;
|
||||
|
||||
// Initialisation des totaux avec 0 au cas où il n'y aurait pas de données
|
||||
$total = isset($paymentData->total) ? $paymentData->total : 0;
|
||||
$total_espece1 = isset($paymentData->total_espece1) ? $paymentData->total_espece1 : 0;
|
||||
$total_espece2 = isset($paymentData->total_espece2) ? $paymentData->total_espece2 : 0;
|
||||
|
||||
$total_espece = $total_espece1 + $total_espece2;
|
||||
$total_espece1 = $total_espece + $total_recouvrement_me + $total_recouvrement_be - $total_sortie_caisse1;
|
||||
|
||||
|
||||
|
||||
|
||||
$Notification = new NotificationController();
|
||||
// $recouvrement_id = $this->request->getPost('recouvrement_id');
|
||||
$session = session();
|
||||
$users = $session->get('user');
|
||||
if ($users && isset($users['firstname'], $users['lastname'])) {
|
||||
$fullname = $users['firstname'] . ' ' . $users['lastname'];
|
||||
}
|
||||
|
||||
// Motif venant du select ou du champ "Autre"
|
||||
$motif = $this->request->getPost('motif_select');
|
||||
$source_fond ='';
|
||||
$initiateur_demande = '';
|
||||
$binaryData = "";
|
||||
$mimeType = "";
|
||||
if (isset($mapping[$motif])) {
|
||||
$source_fond = $this->mapping[$motif]['source_fond'];
|
||||
$initiateur_demande = $this->mapping[$motif]['initiateur_demande'];
|
||||
}
|
||||
|
||||
$file = $this->request->getFile('sortie_preuve');
|
||||
|
||||
|
||||
if (
|
||||
$file
|
||||
&& $file->isValid()
|
||||
&& $file->getError() !== UPLOAD_ERR_NO_FILE
|
||||
&& ($tmpName = $file->getTempName())
|
||||
&& file_exists($tmpName)
|
||||
) {
|
||||
|
||||
$binaryData = file_get_contents($tmpName);
|
||||
|
||||
$mimeType = $file->getClientMimeType();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if ($validation->run($validationData)) {
|
||||
$data = [
|
||||
'montant_retire' => $this->request->getPost('montant_retire'),
|
||||
'date_retrait' => date('Y-m-d'),
|
||||
'motif' => $this->request->getPost('motif_select'),
|
||||
'commentaire' => $this->request->getPost('sortie_commentaire'),
|
||||
'fournisseur' => $this->request->getPost('sortie_fournisseur'),
|
||||
'nif_cin' => $this->request->getPost('sortie_nif'),
|
||||
'statistique' => $this->request->getPost('sortie_statistique'),
|
||||
'telephone' => $this->request->getPost('sortie_phone'),
|
||||
'code_postal' => $this->request->getPost('sortie_adresse'),
|
||||
'source_fond' => $source_fond,
|
||||
'initiateur_demande' => $initiateur_demande,
|
||||
'store_id' => $users['store_id'],
|
||||
'preuve_achat' => $binaryData,
|
||||
'mime_type' => $mimeType,
|
||||
'statut' => "En attente",
|
||||
'user_id' => $users['id'],
|
||||
'sortie_personnel' => $fullname
|
||||
];
|
||||
|
||||
|
||||
if ((int)$this->request->getPost('montant_retire') > $total_espece1) {
|
||||
if($sortieCaisse->addSortieCaisse($data)){
|
||||
$Notification->createNotification("Une demande décaissement a été enregistré", "Conseil", (int)$users['store_id'], 'sortieCaisse');
|
||||
$response['success'] = true;
|
||||
$response['messages'] = 'Décaissement enregistré avec succès';
|
||||
}
|
||||
else {
|
||||
return $this->response->setJSON([
|
||||
'success' => false,
|
||||
'messages' => 'Erreur lors de la modification du décaissement. Veuillez réessayer.'
|
||||
]);
|
||||
}
|
||||
|
||||
} else {
|
||||
$response['success'] = false;
|
||||
$response['messages'] = 'Décaissements échoués — fonds en espèce insuffisants';
|
||||
}
|
||||
} else {
|
||||
// Validation failed, return error messages
|
||||
$response['success'] = false;
|
||||
$response['messages'] = $validation->getErrors();
|
||||
}
|
||||
|
||||
return $this->response->setJSON($response);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function updateSortieCaisse($id_sortie)
|
||||
{
|
||||
$this->verifyRole('updateSortieCaisse');
|
||||
|
||||
$data['page_title'] = $this->pageTitle;
|
||||
|
||||
// Load validation service
|
||||
$validation = \Config\Services::validation();
|
||||
|
||||
|
||||
$SortieCaisse = new SortieCaisse();
|
||||
$orders = new Orders();
|
||||
$Recouvrement = new Recouvrement();
|
||||
$paymentData = $orders->getPaymentModes();
|
||||
$sortieCaisse = new SortieCaisse();
|
||||
$total_sortie_caisse = $sortieCaisse->getTotalSortieCaisse();
|
||||
$total_sortie_caisse1= $total_sortie_caisse->mr;
|
||||
$totalRecouvrement = $Recouvrement->getTotalRecouvrements();
|
||||
|
||||
$total_recouvrement_me = $totalRecouvrement->me;
|
||||
$total_recouvrement_bm = $totalRecouvrement->bm;
|
||||
$total_recouvrement_be = $totalRecouvrement->be;
|
||||
$total_recouvrement_mb = $totalRecouvrement->mb;
|
||||
|
||||
// Initialisation des totaux avec 0 au cas où il n'y aurait pas de données
|
||||
$total = isset($paymentData->total) ? $paymentData->total : 0;
|
||||
$total_espece1 = isset($paymentData->total_espece1) ? $paymentData->total_espece1 : 0;
|
||||
$total_espece2 = isset($paymentData->total_espece2) ? $paymentData->total_espece2 : 0;
|
||||
|
||||
$total_espece = $total_espece1 + $total_espece2;
|
||||
$total_espece1 = $total_espece + $total_recouvrement_me + $total_recouvrement_be - $total_sortie_caisse1;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if ($this->request->getMethod() === 'post') {
|
||||
$session = session();
|
||||
$users = $session->get('user');
|
||||
if ($users && isset($users['firstname'], $users['lastname'])) {
|
||||
$fullname = $users['firstname'] . ' ' . $users['lastname'];
|
||||
}
|
||||
|
||||
// Motif venant du select ou du champ "Autre"
|
||||
$motif = $this->request->getPost('motif_select');
|
||||
|
||||
|
||||
if (isset($mapping[$motif])) {
|
||||
$source_fond = $this->mapping[$motif]['source_fond'];
|
||||
$initiateur_demande = $this->mapping[$motif]['initiateur_demande'];
|
||||
}
|
||||
|
||||
// Récupération de l'objet UploadedFile
|
||||
$file = $this->request->getFile('sortie_preuve_edit');
|
||||
|
||||
if ($file && $file->isValid() && ! $file->hasMoved()) {
|
||||
// Récupère le chemin temporaire
|
||||
$tmpName = $file->getTempName();
|
||||
// Lit tout le contenu binaire
|
||||
$binaryData = file_get_contents($tmpName);
|
||||
// Récupère le Mime-Type pour le stocker si besoin
|
||||
$mimeType = $file->getClientMimeType();
|
||||
} else {
|
||||
$binaryData = null;
|
||||
$mimeType = null;
|
||||
}
|
||||
$data = [
|
||||
'montant_retire' => $this->request->getPost('montant_retire_edit'),
|
||||
'date_retrait' => date('Y-m-d'),
|
||||
'motif' => $this->request->getPost('motif_select'),
|
||||
'commentaire' => $this->request->getPost('sortie_commentaire_edit'),
|
||||
'fournisseur' => $this->request->getPost('sortie_fournisseur_edit'),
|
||||
'nif_cin' => $this->request->getPost('sortie_nif_edit'),
|
||||
'statistique' => $this->request->getPost('sortie_statistique_edit'),
|
||||
'telephone' => $this->request->getPost('sortie_phone_edit'),
|
||||
'code_postal' => $this->request->getPost('sortie_adresse_edit'),
|
||||
'sortie_personnel' => $fullname,
|
||||
'source_fond' => $source_fond,
|
||||
'initiateur_demande' => $initiateur_demande,
|
||||
'store_id' => $users['store_id'],
|
||||
'preuve_achat' => $binaryData,
|
||||
'mime_type' => $mimeType
|
||||
];
|
||||
|
||||
|
||||
$Notification = new NotificationController();
|
||||
if ((int) $this->request->getPost('sortie_montant_edit') > $total_espece1) {
|
||||
if($SortieCaisse->updateSortieCaisse($id_sortie, $data)){
|
||||
return $this->response->setJSON([
|
||||
'success' => true,
|
||||
'messages' => 'Décaissement modifié avec succès !'
|
||||
]);
|
||||
}
|
||||
else {
|
||||
return $this->response->setJSON([
|
||||
'success' => false,
|
||||
'messages' => 'Erreur lors de la modification du décaissement. Veuillez réessayer.'
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
return $this->response->setJSON([
|
||||
'success' => false,
|
||||
'messages' => 'Décaissements échoués — fonds en espèce insuffisants'
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function fetchSortieCaisseSingle($id)
|
||||
{
|
||||
if ($id) {
|
||||
$SortieCaisse = new SortieCaisse();
|
||||
|
||||
$data = $SortieCaisse->getSortieCaisseSingle($id);
|
||||
echo json_encode($data);
|
||||
}
|
||||
}
|
||||
|
||||
public function validateSortieCaisse($id_sortie) {
|
||||
$this->verifyRole('validateSortieCaisse');
|
||||
|
||||
$data['page_title'] = $this->pageTitle;
|
||||
|
||||
|
||||
if ($this->request->getMethod() === 'post') {
|
||||
$data = [
|
||||
'admin_raison' => $this->request->getPost('admin_raison'),
|
||||
'statut' => $this->request->getPost('statut'),
|
||||
|
||||
];
|
||||
$session = session();
|
||||
$users = $session->get('user');
|
||||
$SortieCaisse = new SortieCaisse();
|
||||
$Notification = new NotificationController();
|
||||
|
||||
if($SortieCaisse->updateSortieCaisse($id_sortie, $data) && $this->request->getPost('statut') === "Valider"){
|
||||
$Notification->createNotification("Décaissement validé avec succès", "Caissière", (int)$users["store_id"], 'sortieCaisse');
|
||||
return $this->response->setJSON([
|
||||
'success' => true,
|
||||
'messages' => 'Décaissement modifié avec succès !'
|
||||
]);
|
||||
}
|
||||
elseif($SortieCaisse->updateSortieCaisse($id_sortie, $data) && $this->request->getPost('statut') === "Refuser"){
|
||||
$Notification->createNotification("un décaissement a été réfusé", "Caissière", (int)$users["store_id"], 'sortieCaisse');
|
||||
return $this->response->setJSON([
|
||||
'success' => true,
|
||||
'messages' => 'Décaissement modifié avec succès !'
|
||||
]);
|
||||
}
|
||||
elseif($SortieCaisse->updateSortieCaisse($id_sortie, $data) && $this->request->getPost('statut') === "En attente"){
|
||||
$Notification->createNotification("Décaissement mis en attente", "Caissière", (int)$users["store_id"], 'sortieCaisse');
|
||||
return $this->response->setJSON([
|
||||
'success' => true,
|
||||
'messages' => 'Décaissement modifié avec succès !'
|
||||
]);
|
||||
}
|
||||
else {
|
||||
return $this->response->setJSON([
|
||||
'success' => false,
|
||||
'messages' => 'Erreur lors de la modification du décaissement. Veuillez réessayer.'
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
174
app/Controllers/StatistiqueController.php
Normal file
174
app/Controllers/StatistiqueController.php
Normal file
@ -0,0 +1,174 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Models\Groups;
|
||||
use App\Models\Orders;
|
||||
use App\Models\Products;
|
||||
use App\Models\Stores;
|
||||
use App\Models\Users;
|
||||
|
||||
class StatistiqueController extends AdminController
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$orderModel = new Orders();
|
||||
$userModel = new Users();
|
||||
$storeModel = new Stores();
|
||||
|
||||
// 7 is the role Commercial
|
||||
$allUsers = $userModel->getUsersByGroup();
|
||||
$orderPaid = $orderModel->getPaidOrderData();
|
||||
|
||||
$newData = [];
|
||||
for ($i = 0; $i < count($orderPaid); $i++) {
|
||||
$transitionData = [];
|
||||
for ($k = 0; $k < count($allUsers); $k++) {
|
||||
if ($allUsers[$k]['id'] == $orderPaid[$i]['user_id']) {
|
||||
$transitionData2 = [
|
||||
'userId' => $allUsers[$k]['id'],
|
||||
'userName' => $allUsers[$k]['username'],
|
||||
'billId' => $orderPaid[$i]['id'],
|
||||
'billNo' => $orderPaid[$i]['bill_no'],
|
||||
'dateVente' => $orderPaid[$i]['date_time'],
|
||||
'montantNet' => $orderPaid[$i]['net_amount'],
|
||||
];
|
||||
$transitionData[] = $transitionData2;
|
||||
}
|
||||
}
|
||||
$newData[] = $transitionData;
|
||||
}
|
||||
|
||||
// filter to keep non empty array
|
||||
$filteredArray = array_filter($newData, function ($item) {
|
||||
return !empty($item); // Keep only non-empty arrays
|
||||
});
|
||||
|
||||
|
||||
// Re-index the array (optional, if you want sequential keys)
|
||||
$userWhoSoldProducts = array_values($filteredArray);
|
||||
|
||||
// Count occurrences of each userId
|
||||
$userIdCounts = array_reduce($userWhoSoldProducts, function($carry, $item) {
|
||||
$userId = $item[0]['userId'];
|
||||
if (!isset($carry[$userId])) {
|
||||
$carry[$userId] = 0;
|
||||
}
|
||||
$carry[$userId]++;
|
||||
return $carry;
|
||||
}, []);
|
||||
|
||||
foreach ($allUsers as &$user) {
|
||||
$userId = (int)$user['id'];
|
||||
if (isset($userIdCounts[$userId])) {
|
||||
$user['totalVente'] = $userIdCounts[$userId];
|
||||
} else {
|
||||
$user['totalVente'] = 0; // or any default value you want to assign if the user ID is not found in $userIdCount
|
||||
}
|
||||
}
|
||||
|
||||
$data['allUsers'] = $allUsers;
|
||||
$data['page_title'] = 'Statistique';
|
||||
// Check if the user is an Conseil
|
||||
$session = session();
|
||||
$user_id = $session->get('user');
|
||||
// $data['is_admin'] = ($user_id['id'] == 1);
|
||||
// echo '<pre>';
|
||||
// var_dump($allUsers);
|
||||
// echo '</pre>';
|
||||
$data['is_admin'] = false;
|
||||
|
||||
if ($user_id['group_name'] == "Direction" || $user_id['group_name'] == "Conseil") {
|
||||
$data['is_admin'] = true;
|
||||
}
|
||||
|
||||
// echo '<pre>';
|
||||
// die(var_dump($newData));
|
||||
|
||||
return $this->render_template('statistic/index', $data);
|
||||
}
|
||||
|
||||
public function testindex()
|
||||
{
|
||||
// Sample data
|
||||
$data = [
|
||||
[
|
||||
[
|
||||
"userId" => "7",
|
||||
"userName" => "Billy",
|
||||
"billId" => "10",
|
||||
"billNo" => "BILPR-500F",
|
||||
"dateVente" => "2025-01-25 14:33:54",
|
||||
"montantNet" => "638580.96"
|
||||
]
|
||||
],
|
||||
// [
|
||||
// [
|
||||
// "userId" => "9",
|
||||
// "userName" => "john does",
|
||||
// "billId" => "5",
|
||||
// "billNo" => "BILPR-3D87",
|
||||
// "dateVente" => "2025-01-19 14:33:54",
|
||||
// "montantNet" => "12.90"
|
||||
// ]
|
||||
// ],
|
||||
[
|
||||
[
|
||||
"userId" => "7",
|
||||
"userName" => "Billy",
|
||||
"billId" => "4",
|
||||
"billNo" => "BILPR-A004",
|
||||
"dateVente" => "2025-01-18 14:33:54",
|
||||
"montantNet" => "12.90"
|
||||
]
|
||||
]
|
||||
// [
|
||||
// [
|
||||
// "userId" => "9",
|
||||
// "userName" => "john does",
|
||||
// "billId" => "3",
|
||||
// "billNo" => "BILPR-7C26",
|
||||
// "dateVente" => "2025-01-17 14:33:54",
|
||||
// "montantNet" => "438.60"
|
||||
// ]
|
||||
// ]
|
||||
];
|
||||
|
||||
// Process data
|
||||
$userData = [];
|
||||
foreach ($data as $entry) {
|
||||
$record = $entry[0];
|
||||
$userId = $record['userId'];
|
||||
$userName = $record['userName'];
|
||||
|
||||
// Ensure user exists in the array
|
||||
if (!isset($userData[$userId])) {
|
||||
$userData[$userId] = [
|
||||
'name' => $userName,
|
||||
'dates' => [],
|
||||
'values' => []
|
||||
];
|
||||
}
|
||||
|
||||
// Store date and montantNet
|
||||
$userData[$userId]['dates'][] = $record['dateVente'];
|
||||
$userData[$userId]['values'][] = (float) $record['montantNet'];
|
||||
}
|
||||
|
||||
$data['userData'] = json_encode($userData);
|
||||
$data['page_title'] = 'Statistique';
|
||||
// die(var_dump($data));
|
||||
// return view('chart_view', ['userData' => json_encode($userData)]);
|
||||
return $this->render_template('statistic/single', $data);
|
||||
}
|
||||
|
||||
public function singleStat(int $id)
|
||||
{
|
||||
$Order = new Orders();
|
||||
|
||||
$data['user_order'] = json_encode($Order->getSingleStat($id), JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP);
|
||||
$data['page_title'] = 'Statistique';
|
||||
|
||||
return $this->render_template('statistic/single', $data);
|
||||
}
|
||||
}
|
||||
193
app/Controllers/StoreController.php
Normal file
193
app/Controllers/StoreController.php
Normal file
@ -0,0 +1,193 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Models\Stores;
|
||||
|
||||
class StoreController extends AdminController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
// Assuming permission is being set from a session
|
||||
helper(['form', 'url']);
|
||||
}
|
||||
|
||||
private $pageTitle = 'Stores';
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->verifyRole('viewStore');
|
||||
$data['page_title'] = $this->pageTitle;
|
||||
|
||||
return $this->render_template('stores/index', $data);
|
||||
}
|
||||
|
||||
public function fetchStoresDataById($id)
|
||||
{
|
||||
if($id) {
|
||||
$Stores = new Stores();
|
||||
|
||||
$data = $Stores->getStoresData($id);
|
||||
echo json_encode($data);
|
||||
}
|
||||
}
|
||||
|
||||
public function fetchStoresData()
|
||||
{
|
||||
$storeModel = new Stores(); // Load the StoreModel
|
||||
$stores = $storeModel->findAll(); // Fetch all data
|
||||
$result = ['data' => []];
|
||||
|
||||
// Iterate through the data
|
||||
foreach ($stores as $key => $store) {
|
||||
// Action buttons
|
||||
$buttons = '';
|
||||
|
||||
// Check permissions for updating the store
|
||||
if (in_array('updateStore', $this->permission)) {
|
||||
$buttons .= '<button type="button" class="btn btn-default" onclick="editFunc(' . $store['id'] . ')" data-toggle="modal" data-target="#editModal"><i class="fa fa-pencil"></i></button>';
|
||||
}
|
||||
|
||||
// Check permissions for deleting the store
|
||||
if (in_array('deleteStore', $this->permission)) {
|
||||
$buttons .= ' <button type="button" class="btn btn-danger" onclick="removeFunc(' . $store['id'] . ')" data-toggle="modal" data-target="#removeModal"><i class="fa fa-trash"></i></button>';
|
||||
}
|
||||
|
||||
// Status display
|
||||
$status = ($store['active'] == 1)
|
||||
? '<span class="label label-success">Active</span>'
|
||||
: '<span class="label label-warning">Inactive</span>';
|
||||
|
||||
// Add the row data
|
||||
$result['data'][$key] = [
|
||||
$store['name'], // Store name
|
||||
$status, // Active or inactive status
|
||||
$buttons // Action buttons
|
||||
];
|
||||
}
|
||||
|
||||
// Return data in JSON format
|
||||
return $this->response->setJSON($result);
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$this->verifyRole('createStore');
|
||||
$response = [];
|
||||
|
||||
// Set validation rules
|
||||
$validation = \Config\Services::validation();
|
||||
$validation->setRules([
|
||||
'store_name' => 'required',
|
||||
'active' => 'required',
|
||||
]);
|
||||
|
||||
$validationData = [
|
||||
'store_name' => $this->request->getPost('store_name'),
|
||||
'active' => $this->request->getPost('active'),
|
||||
];
|
||||
|
||||
// Run validation
|
||||
if ($validation->run($validationData)) {
|
||||
// // Prepare data
|
||||
$data = [
|
||||
'name' => $this->request->getPost('store_name'),
|
||||
'active' => $this->request->getPost('active'),
|
||||
];
|
||||
|
||||
// Load the model and create the store
|
||||
$storeModel = new Stores();
|
||||
if ($storeModel->createStore($data)) {
|
||||
$response['success'] = true;
|
||||
$response['messages'] = 'Successfully created';
|
||||
} else {
|
||||
$response['success'] = false;
|
||||
$response['messages'] = 'Error in the database while creating the store';
|
||||
}
|
||||
} else {
|
||||
// Validation failed, return error messages
|
||||
$response['success'] = false;
|
||||
$response['messages'] = $validation->getErrors();
|
||||
}
|
||||
|
||||
return $this->response->setJSON($response);
|
||||
}
|
||||
|
||||
public function update(int $id)
|
||||
{
|
||||
$this->verifyRole('updateStore');
|
||||
$response = [];
|
||||
// die(var_dump($this->request->getPost()));
|
||||
if ($id) {
|
||||
// Set validation rules
|
||||
$validation = \Config\Services::validation();
|
||||
|
||||
$validation->setRules([
|
||||
'edit_store_name' => 'required',
|
||||
'edit_active' => 'required',
|
||||
]);
|
||||
|
||||
$validationData = [
|
||||
'edit_store_name' => $this->request->getPost('edit_store_name'),
|
||||
'edit_active' => $this->request->getPost('edit_active'),
|
||||
];
|
||||
|
||||
$storeModel = new Stores();
|
||||
|
||||
if ($validation->run($validationData)) {
|
||||
|
||||
$data = [
|
||||
'name' => $this->request->getPost('edit_store_name'),
|
||||
'active' => $this->request->getPost('edit_active'),
|
||||
];
|
||||
|
||||
if ($storeModel->updateStore($data, $id)) {
|
||||
$response['success'] = true;
|
||||
$response['messages'] = 'Mise à jour réussie';
|
||||
} else {
|
||||
$response['success'] = false;
|
||||
$response['messages'] = 'Erreur dans la base de données lors de la mise à jour du magasin';
|
||||
}
|
||||
|
||||
} else {
|
||||
// Validation failed, return error messages
|
||||
$response['success'] = false;
|
||||
$response['messages'] = $validation->getErrors();
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
$response['success'] = false;
|
||||
$response['messages'] = 'Erreur, veuillez actualiser la page à nouveau !!';
|
||||
}
|
||||
|
||||
return $this->response->setJSON($response);
|
||||
}
|
||||
|
||||
public function remove()
|
||||
{
|
||||
$this->verifyRole('deleteStore');
|
||||
$response = [];
|
||||
|
||||
$storeId = $this->request->getPost('store_id');
|
||||
|
||||
if ($storeId) {
|
||||
$storeModel = new Stores();
|
||||
|
||||
if ($storeModel->delete($storeId)) {
|
||||
$response['success'] = true;
|
||||
$response['messages'] = "Supprimé avec succès";
|
||||
} else {
|
||||
$response['success'] = false;
|
||||
$response['messages'] = "Erreur dans la base de données lors de la suppression des informations sur la marque";
|
||||
}
|
||||
|
||||
} else {
|
||||
$response['success'] = false;
|
||||
$response['messages'] = "Référez à nouveau la page !!";
|
||||
}
|
||||
|
||||
return $this->response->setJSON($response);
|
||||
}
|
||||
}
|
||||
25
app/Controllers/TestDeadline.php
Normal file
25
app/Controllers/TestDeadline.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use CodeIgniter\Controller;
|
||||
|
||||
class TestDeadline extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
// Charger le helper qui contient ta fonction
|
||||
helper('alerts'); // si ton fichier s'appelle alerts_helper.php
|
||||
|
||||
// 🔹 Supprimer le cache 24h pour forcer l'exécution
|
||||
$cacheFile = WRITEPATH . 'cache/check_deadline_last_run.txt';
|
||||
if (file_exists($cacheFile)) {
|
||||
unlink($cacheFile);
|
||||
}
|
||||
|
||||
// Lancer la vérification
|
||||
checkDeadlineAlerts();
|
||||
|
||||
echo "✅ Test de l'envoi d'alertes terminé.";
|
||||
}
|
||||
}
|
||||
551
app/Controllers/UserController.php
Normal file
551
app/Controllers/UserController.php
Normal file
@ -0,0 +1,551 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Models\Groups;
|
||||
use App\Models\Users;
|
||||
use App\Models\Stores;
|
||||
use Config\Services;
|
||||
|
||||
class UserController extends AdminController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
// Assuming permission is being set from a session
|
||||
helper(['form', 'url']);
|
||||
}
|
||||
|
||||
/**
|
||||
* title of the page
|
||||
* @var string
|
||||
*/
|
||||
private $pageTitle = 'User';
|
||||
private $pageTitle2 = 'Profile';
|
||||
|
||||
/**
|
||||
* get all users
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$this->verifyRole('viewUser');
|
||||
|
||||
$Users = new Users();
|
||||
$userData = $Users->getUserData();
|
||||
$result = [];
|
||||
$Stores = new Stores();
|
||||
foreach ($userData as $key => $value) {
|
||||
if (is_numeric($value['store_id']))
|
||||
$value['store_id'] = $value['store_id'] == 0 ? "TOUS" : $Stores->getStoresData($value['store_id'])["name"];
|
||||
$result[$key]['user_info'] = $value;
|
||||
$group = $Users->getUserGroup($value['id']);
|
||||
|
||||
$result[$key]['user_group'] = $group;
|
||||
}
|
||||
|
||||
$data['user_data'] = $result;
|
||||
|
||||
$session = session();
|
||||
$usersSession = $session->get('user');
|
||||
$data['groupName'] = $usersSession['group_name'];
|
||||
|
||||
// die(var_dump($usersSession['group_name']));
|
||||
$data['page_title'] = $this->pageTitle;
|
||||
$data['stores'] = $Stores->getActiveStore();
|
||||
|
||||
return $this->render_template('users/index', $data);
|
||||
}
|
||||
|
||||
public function fetchUserData()
|
||||
{
|
||||
$this->verifyRole('viewUser');
|
||||
|
||||
try {
|
||||
$Users = new Users();
|
||||
$userData = $Users->getUserData();
|
||||
$result = [];
|
||||
$Stores = new Stores();
|
||||
|
||||
foreach ($userData as $key => $value) {
|
||||
$buttons = '';
|
||||
|
||||
if (in_array('updateUser', $this->permission)) {
|
||||
$buttons .= '<button type="button" class="btn btn-default" onclick="editFunc(' . $value['id'] . ')">'
|
||||
. '<i class="fa fa-pencil"></i>'
|
||||
. '</button>';
|
||||
|
||||
}
|
||||
|
||||
if (in_array('deleteUser', $this->permission)) {
|
||||
$buttons .= ' <button type="button" '
|
||||
. 'class="btn btn-danger" '
|
||||
. 'data-toggle="modal" '
|
||||
. 'data-target="#removeModal" '
|
||||
. 'data-id="' . $value['id'] . '">'
|
||||
. '<i class="fa fa-trash"></i>'
|
||||
. '</button>';
|
||||
}
|
||||
if (in_array('viewProfile', $this->permission)) {
|
||||
$buttons .= ' <button
|
||||
type="button"
|
||||
class="btn btn-success" data-toggle="modal"
|
||||
data-target="#profileModal"
|
||||
onclick="profileFunc(' . $value['id'] . ')"
|
||||
title="Voir le profil">
|
||||
<i class="fa fa-user"></i>
|
||||
</button>';
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (in_array('viewUser', $this->permission)) {
|
||||
$buttons .= ' <button type="button" class="btn btn-info" onclick="loginFunc(' . $value['id'] . ')"><i class="fa fa-chevron-right"></i></button>';
|
||||
}
|
||||
|
||||
if (in_array('assignerUser', $this->permission)) {
|
||||
$buttons .= '<button type="button" class="btn btn-info" onclick="assignFunc(' . $value['id'] . ')">
|
||||
<i class="fa fa-cog"></i>
|
||||
</button>';
|
||||
}
|
||||
$group_data = $Users->getUserWithGroupName($value['id']);
|
||||
// die(var_dump($group_data['group_name']));
|
||||
$result[] = [
|
||||
$value['firstname'],
|
||||
$value['lastname'],
|
||||
$value['email'],
|
||||
$value['phone'],
|
||||
$Stores->getStoresName($value['store_id']),
|
||||
$group_data['group_name'],
|
||||
$buttons
|
||||
];
|
||||
}
|
||||
|
||||
return $this->response->setJSON(['data' => $result]);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return $this->response->setJSON([
|
||||
'data' => [],
|
||||
'error' => true,
|
||||
'message' => 'Erreur lors de la récupération des données utilisateur : ' . $e->getMessage()
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function assign_store()
|
||||
{
|
||||
// Vérifie que la requête est bien une requête AJAX
|
||||
if (!$this->request->isAJAX()) {
|
||||
$response = Services::response();
|
||||
$response->setStatusCode(404, 'Page Not Found')->send();
|
||||
exit;
|
||||
}
|
||||
|
||||
// Récupère les données POST sous format JSON
|
||||
$user_id = $this->request->getPost('user_id');
|
||||
$store_id = $this->request->getPost('store_id');
|
||||
$Users = new Users();
|
||||
|
||||
if (!isset($user_id) || !isset($store_id)) {
|
||||
return $this->response->setJSON([
|
||||
'success' => false,
|
||||
'message' => 'Paramètres manquants.'
|
||||
])->setStatusCode(400);
|
||||
}
|
||||
|
||||
$user_id1 = $user_id;
|
||||
$store_id1 = $store_id;
|
||||
|
||||
$usersModel = new Users();
|
||||
// die(var_dump([$user_id, $store_id]));
|
||||
// Appeler la méthode assignToStore pour mettre à jour la base de données
|
||||
$result = $usersModel->assignToStore($user_id1, $store_id1);
|
||||
|
||||
// Répondre en JSON avec le résultat
|
||||
if ($result) {
|
||||
return $this->response->setJSON(['success' => true, 'message' => 'Mise è jour réusit.']);
|
||||
} else {
|
||||
return $this->response->setJSON(['success' => false, 'message' => 'Échec de la mise à jour.']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function create()
|
||||
{
|
||||
// ini_set('display_errors', 1);
|
||||
// ini_set('display_startup_errors', 1);
|
||||
// error_reporting(E_ALL);
|
||||
|
||||
$this->verifyRole('createUser');
|
||||
// Define validation rules
|
||||
$validationRules = [
|
||||
'groups' => [
|
||||
'label' => 'Group',
|
||||
'rules' => 'required'
|
||||
],
|
||||
'username' => [
|
||||
'label' => 'Username',
|
||||
'rules' => 'required|trim|min_length[5]|is_unique[users.username]'
|
||||
],
|
||||
'email' => [
|
||||
'label' => 'Email',
|
||||
'rules' => 'required|trim|valid_email|is_unique[users.email]'
|
||||
],
|
||||
'password' => [
|
||||
'label' => 'Password',
|
||||
'rules' => 'required|trim|min_length[8]'
|
||||
],
|
||||
'cpassword' => [
|
||||
'label' => 'Confirm Password',
|
||||
'rules' => 'required|trim|matches[password]'
|
||||
],
|
||||
'fname' => [
|
||||
'label' => 'First Name',
|
||||
'rules' => 'required|trim'
|
||||
]
|
||||
];
|
||||
|
||||
$Groups = new Groups();
|
||||
$Users = new Users();
|
||||
$data['page_title'] = $this->pageTitle;
|
||||
|
||||
// Check if it's a POST request before validating
|
||||
if ($this->request->getMethod() === 'post') {
|
||||
// Load validation service and run validation
|
||||
if (!$this->validate($validationRules)) {
|
||||
|
||||
// Validation failed, load view with errors
|
||||
$groupData = $Groups->getGroupData(); // Assuming model_groups is loaded
|
||||
$data['group_data'] = $groupData;
|
||||
$data['validation'] = $this->validator; // Pass validation instance to the view
|
||||
$Stores = new Stores();
|
||||
$data['stores'] = $Stores->getActiveStore();
|
||||
|
||||
return $this->render_template('users/create', $data);
|
||||
}
|
||||
|
||||
// Validation passed, process form data
|
||||
$password = $this->passwordHash($this->request->getPost('password')); // Update hashing logic if needed
|
||||
|
||||
$data = [
|
||||
'username' => $this->request->getPost('username'),
|
||||
'password' => $password,
|
||||
'email' => $this->request->getPost('email'),
|
||||
'firstname' => $this->request->getPost('fname'),
|
||||
'lastname' => $this->request->getPost('lname'),
|
||||
'phone' => $this->request->getPost('phone'),
|
||||
'gender' => $this->request->getPost('gender'),
|
||||
'store_id' => $this->request->getPost('store'),
|
||||
];
|
||||
|
||||
$create = $Users->create($data, $this->request->getPost('groups'));
|
||||
|
||||
if ($create) {
|
||||
// Success
|
||||
return redirect()->to('/users')->with('success', 'Successfully created');
|
||||
} else {
|
||||
// Error
|
||||
return redirect()->to('/users/create')->with('error', 'Error occurred!!');
|
||||
}
|
||||
}
|
||||
$Stores = new Stores();
|
||||
|
||||
// If it's not a POST request, just render the create page with no validation errors
|
||||
$groupData = $Groups->getGroupData();
|
||||
$data['group_data'] = $groupData;
|
||||
$data['stores'] = $Stores->getActiveStore();
|
||||
return $this->render_template('users/create', $data);
|
||||
}
|
||||
|
||||
|
||||
public function passwordHash($pass = '')
|
||||
{
|
||||
if ($pass) {
|
||||
$password = password_hash($pass, PASSWORD_DEFAULT);
|
||||
return $password;
|
||||
}
|
||||
}
|
||||
|
||||
public function edit(int $id = null)
|
||||
{
|
||||
$this->verifyRole('updateUser');
|
||||
$data['page_title'] = $this->pageTitle;
|
||||
|
||||
$validation = \Config\Services::validation();
|
||||
$usersModel = new Users();
|
||||
$groupsModel = new Groups();
|
||||
|
||||
// Define validation rules
|
||||
$validationRules = [
|
||||
'groups' => 'required',
|
||||
'username' => 'required|trim|min_length[5]|max_length[12]',
|
||||
'email' => 'required|trim|valid_email',
|
||||
'fname' => 'required|trim',
|
||||
];
|
||||
|
||||
// Check if the ID exists in the request
|
||||
if ($id) {
|
||||
// Check if it's a POST request before validating
|
||||
if ($this->request->getMethod() === 'post') {
|
||||
// Validate the form
|
||||
if (!$this->validate($validationRules)) {
|
||||
// Validation failed
|
||||
$data['validation'] = $validation;
|
||||
$data['user_data'] = $usersModel->getUserData($id);
|
||||
$data['user_group'] = $usersModel->getUserGroup($id);
|
||||
$data['group_data'] = $groupsModel->getGroupData();
|
||||
return $this->render_template('users/edit', $data);
|
||||
}
|
||||
|
||||
// If password is empty, skip password validation
|
||||
$password = '';
|
||||
if ($this->request->getPost('password') && $this->request->getPost('cpassword')) {
|
||||
$validation->setRule('password', 'Password', 'required|min_length[8]');
|
||||
$validation->setRule('cpassword', 'Confirm Password', 'required|matches[password]');
|
||||
|
||||
if (!$this->validate($validationRules)) {
|
||||
// Validation failed for password
|
||||
$data['validation'] = $validation;
|
||||
$data['user_data'] = $usersModel->getUserData($id);
|
||||
$data['user_group'] = $usersModel->getUserGroup($id);
|
||||
$data['group_data'] = $groupsModel->getGroupData();
|
||||
return $this->render_template('users/edit', $data);
|
||||
}
|
||||
$password = password_hash($this->request->getPost('password'), PASSWORD_DEFAULT); // Hash the password
|
||||
}
|
||||
|
||||
// Prepare user data for update
|
||||
$data = [
|
||||
'username' => $this->request->getPost('username'),
|
||||
'password' => $password ?: $this->request->getPost('password'), // If no new password, keep the old one
|
||||
'email' => $this->request->getPost('email'),
|
||||
'firstname' => $this->request->getPost('fname'),
|
||||
'lastname' => $this->request->getPost('lname'),
|
||||
'phone' => $this->request->getPost('phone'),
|
||||
'gender' => $this->request->getPost('gender'),
|
||||
];
|
||||
|
||||
$groupId = $this->request->getPost('groups');
|
||||
|
||||
// Update user
|
||||
$update = $usersModel->edit($data, $id, $groupId);
|
||||
|
||||
if ($update) {
|
||||
session()->setFlashdata('success', 'Successfully updated');
|
||||
return redirect()->to('/users');
|
||||
} else {
|
||||
session()->setFlashdata('errors', 'Error occurred!');
|
||||
return redirect()->to("/users/edit/{$id}");
|
||||
}
|
||||
}
|
||||
|
||||
// If it's not a POST request (initial load), load user data
|
||||
$data['user_data'] = $usersModel->getUserData($id);
|
||||
$data['user_group'] = $usersModel->getUserGroup($id);
|
||||
$data['group_data'] = $groupsModel->getGroupData();
|
||||
|
||||
return $this->render_template('users/edit', $data);
|
||||
}
|
||||
|
||||
// If no ID is provided, you can handle the error or redirect
|
||||
return redirect()->to('/users');
|
||||
}
|
||||
|
||||
|
||||
// supression utilisateur
|
||||
|
||||
|
||||
public function delete($id)
|
||||
{
|
||||
$this->verifyRole('deleteUser');
|
||||
|
||||
if (!$id) {
|
||||
return $this->response->setJSON(['success' => false, 'message' => 'ID manquant']);
|
||||
}
|
||||
|
||||
$usersModel = new Users();
|
||||
$delete = $usersModel->delete($id);
|
||||
|
||||
if ($delete) {
|
||||
return $this->response->setJSON(['success' => true, 'message' => 'Supprimé avec succès']);
|
||||
} else {
|
||||
return $this->response->setJSON(['success' => false, 'message' => 'Échec de la suppression']);
|
||||
}
|
||||
}
|
||||
|
||||
public function profile()
|
||||
{
|
||||
$this->verifyRole('viewProfile');
|
||||
$user = session()->get('user');
|
||||
$userId = $user['id'];
|
||||
|
||||
$Users = new Users();
|
||||
$Store = new Stores();
|
||||
$data['user_data'] = $Users->getUserData($userId);
|
||||
$data['store_name']= $Store->getStoreById($data['user_data']['store_id']);
|
||||
$data['page_title'] = $this->pageTitle2;
|
||||
$data['user_group'] = $Users->getUserGroup($userId);
|
||||
|
||||
return $this->render_template('users/profile', $data);
|
||||
}
|
||||
|
||||
public function setting()
|
||||
{
|
||||
$this->verifyRole('updateSetting');
|
||||
$user = session()->get('user');
|
||||
$userId = $user['id'];
|
||||
|
||||
if ($userId) {
|
||||
$validation = \Config\Services::validation();
|
||||
|
||||
// Set validation rules
|
||||
$validation->setRules([
|
||||
'username' => 'required|trim|min_length[5]|max_length[12]',
|
||||
'email' => 'required|trim|valid_email',
|
||||
'fname' => 'required|trim',
|
||||
]);
|
||||
$Users = new Users();
|
||||
// If validation passes for the first set of rules
|
||||
if ($this->request->getMethod() === 'post' && $validation->withRequest($this->request)->run()) {
|
||||
// Handle the case when password is not being updated
|
||||
if (empty($this->request->getPost('password')) && empty($this->request->getPost('cpassword'))) {
|
||||
|
||||
$data = [
|
||||
'username' => $this->request->getPost('username'),
|
||||
'email' => $this->request->getPost('email'),
|
||||
'firstname' => $this->request->getPost('fname'),
|
||||
'lastname' => $this->request->getPost('lname'),
|
||||
'phone' => $this->request->getPost('phone'),
|
||||
'gender' => $this->request->getPost('gender'),
|
||||
];
|
||||
$update = $Users->update($userId, $data);
|
||||
// die(var_dump($update));
|
||||
|
||||
if ($update) {
|
||||
return redirect()->to('/users/setting')->with('success', 'Successfully updated');
|
||||
} else {
|
||||
return redirect()->back()->with('errors', 'Error occurred!')->withInput();
|
||||
}
|
||||
} else {
|
||||
// Additional validation for password
|
||||
$validation->setRules([
|
||||
'password' => 'required|min_length[8]',
|
||||
'cpassword' => 'required|matches[password]',
|
||||
]);
|
||||
|
||||
if ($validation->withRequest($this->request)->run()) {
|
||||
$password = password_hash($this->request->getPost('password'), PASSWORD_DEFAULT);
|
||||
|
||||
$data = [
|
||||
'username' => $this->request->getPost('username'),
|
||||
'password' => $password,
|
||||
'email' => $this->request->getPost('email'),
|
||||
'firstname' => $this->request->getPost('fname'),
|
||||
'lastname' => $this->request->getPost('lname'),
|
||||
'phone' => $this->request->getPost('phone'),
|
||||
'gender' => $this->request->getPost('gender'),
|
||||
];
|
||||
|
||||
$update = $Users->update($userId, $data);
|
||||
|
||||
if ($update) {
|
||||
return redirect()->to('/users/setting')->with('success', 'Successfully updated');
|
||||
} else {
|
||||
return redirect()->back()->with('errors', 'Error occurred!')->withInput();
|
||||
}
|
||||
} else {
|
||||
// Handle validation errors for password
|
||||
return redirect()->back()->with('errors', $validation->getErrors())->withInput();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
$userData = $Users->find($userId);
|
||||
|
||||
$groupModel = new Groups(); // Assuming you have a GroupModel
|
||||
$groups = $groupModel->findAll();
|
||||
|
||||
$data = [
|
||||
'user_data' => $userData,
|
||||
'group_data' => $groups,
|
||||
'validation' => $validation->getErrors(),
|
||||
'page_title' => 'Paramètre',
|
||||
];
|
||||
|
||||
return $this->render_template('users/setting', $data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function loginToOtherAccount(int $id)
|
||||
{
|
||||
$Users = new Users();
|
||||
|
||||
$userInfo = $Users->getUserData($id);
|
||||
|
||||
$email = $userInfo['email'];
|
||||
$password = $userInfo['password'];
|
||||
$user = $Users->attempt($email, $password, "connected_inside");
|
||||
// die(var_dump($user));
|
||||
|
||||
if ($user) {
|
||||
// Set user session
|
||||
session()->set('user', $user);
|
||||
// Redirect to dashboard
|
||||
return redirect()->to('/');
|
||||
}
|
||||
}
|
||||
|
||||
public function fetchProfile($id)
|
||||
{
|
||||
$this->verifyRole('viewProfile');
|
||||
|
||||
$Users = new Users();
|
||||
$Store = new Stores();
|
||||
|
||||
$user_data = $Users->getUserData($id);
|
||||
if (!$user_data) {
|
||||
return $this->response->setStatusCode(404)->setBody('Utilisateur introuvable');
|
||||
}
|
||||
|
||||
$store_name = $Store->getStoreById($user_data['store_id']);
|
||||
$user_group = $Users->getUserGroup($id);
|
||||
|
||||
$data =[
|
||||
'user_data' => $user_data,
|
||||
'store_name' => $store_name,
|
||||
'user_group' => $user_group
|
||||
];
|
||||
return $this->response->setJSON([$data]);
|
||||
}
|
||||
|
||||
public function fetchUserForAssign()
|
||||
{
|
||||
if (!$this->request->isAJAX()) {
|
||||
return $this->response->setStatusCode(404)->setJSON(['message' => 'Requête invalide']);
|
||||
}
|
||||
|
||||
$user_id = $this->request->getPost('user_id');
|
||||
$userModel = new Users();
|
||||
$storeModel = new Stores();
|
||||
|
||||
$user = $userModel->getUserDataForAssign($user_id);
|
||||
$stores = $storeModel->getAllStores();
|
||||
|
||||
if (!$user) {
|
||||
return $this->response->setJSON(['success' => false, 'message' => 'Utilisateur introuvable']);
|
||||
}
|
||||
|
||||
return $this->response->setJSON([
|
||||
'success' => true,
|
||||
'user' => [
|
||||
'id' => $user['id'],
|
||||
'name' => $user['firstname'] . ' ' . $user['lastname'],
|
||||
'role' => $user['group_name'],
|
||||
'current_store' => $user['store_name'],
|
||||
],
|
||||
'stores' => $stores
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
145
app/Controllers/test.html
Normal file
145
app/Controllers/test.html
Normal file
@ -0,0 +1,145 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="stylesheet" href="' . base_url('assets/bower_components/bootstrap/dist/css/bootstrap.min.css') . '">
|
||||
<style>
|
||||
body { font-size: 14px; font-family: Arial, sans-serif; }
|
||||
.invoice-container {
|
||||
max-width: 350px; /* Réduire la largeur du cadre */
|
||||
margin: 20px auto;
|
||||
padding: 20px;
|
||||
border: 2px solid #007bff; /* Bordure plus visible */
|
||||
border-radius: 10px;
|
||||
background: #f0f8ff; /* Couleur de fond plus douce */
|
||||
}
|
||||
.invoice-header {
|
||||
background: #007bff;
|
||||
color: white;
|
||||
text-align: center;
|
||||
font-size: 18px;
|
||||
font-weight: bold;
|
||||
padding: 10px;
|
||||
border-radius: 10px 10px 0 0;
|
||||
}
|
||||
.invoice-footer {
|
||||
background: #343a40;
|
||||
color: white;
|
||||
text-align: center;
|
||||
font-size: 14px;
|
||||
padding: 10px;
|
||||
border-radius: 0 0 10px 10px;
|
||||
margin-top: 12px;
|
||||
}
|
||||
table { width: 100%; border-collapse: collapse; }
|
||||
th, td { padding: 8px; text-align: left; border-bottom: 1px solid #ddd; }
|
||||
th { background: #e9ecef; }
|
||||
p, strong { color: #333; }
|
||||
</style>
|
||||
</head>
|
||||
<body onload="window.print();">
|
||||
<div class="invoice-container">
|
||||
<div class="invoice-header">
|
||||
' . esc($company_info['company_name']) . '
|
||||
</div>
|
||||
<p><strong>Facture ID:</strong> ' . esc($order_data['bill_no']) . '</p>
|
||||
<p><strong>Nom:</strong> ' . esc($order_data['customer_name']) . '</p>
|
||||
<p><strong>Adresse:</strong> ' . esc($order_data['customer_address']) . '</p>
|
||||
<p><strong>Téléphone:</strong> ' . esc($order_data['customer_phone']) . '</p>
|
||||
|
||||
<div style="display: flex;align-items: center;justify-content: space-around;margin-bottom: 3%;">
|
||||
<div>
|
||||
<p>Signature du client</p>
|
||||
</div>
|
||||
<div>
|
||||
<p>Signature du commercial</p>
|
||||
</div>
|
||||
</div>
|
||||
<table class="table table-bordered">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Produit</th>
|
||||
<th>Qté</th>
|
||||
<th>Prix</th>
|
||||
<th>Total</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>';
|
||||
|
||||
foreach ($orders_items as $item) {
|
||||
$product_data = $Products->getProductData($item['product_id']);
|
||||
$html .= '<tr>
|
||||
<td>' . esc($product_data['name']) . '</td>
|
||||
<td>' . esc($item['qty']) . '</td>
|
||||
<td>' . number_format((float)$item['rate'], 2, '.', ' ') . '</td>
|
||||
<td>' . number_format((float)$item['amount'], 2, '.', ' ') . '</td>
|
||||
</tr>';
|
||||
}
|
||||
|
||||
$html .= ' </tbody>
|
||||
</table>
|
||||
<table class="table">
|
||||
<tr>
|
||||
<th>Total:</th>
|
||||
<td>' . number_format((float)$order_data['gross_amount'], 2, '.', ' ') . '</td>
|
||||
</tr>';
|
||||
|
||||
if (!empty($order_data['service_charge']) && (float)$order_data['service_charge'] > 0) {
|
||||
$html .= '<tr>
|
||||
<th>Frais de service:</th>
|
||||
<td>' . number_format((float)$order_data['service_charge'], 2, '.', ' ') . '</td>
|
||||
</tr>';
|
||||
}
|
||||
|
||||
if (!empty($order_data['vat_charge']) && (float)$order_data['vat_charge'] > 0) {
|
||||
$html .= '<tr>
|
||||
<th>TVA:</th>
|
||||
<td>' . number_format((float)$order_data['vat_charge'], 2, '.', ' ') . '</td>
|
||||
</tr>';
|
||||
}
|
||||
|
||||
$html .= '<tr>
|
||||
<th>Réduction:</th>
|
||||
<td>' . number_format((float)$order_data['discount'], 2, '.', ' ') . '</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Total à payer:</th>
|
||||
<td><strong>' . number_format((float)$order_data['net_amount'], 2, '.', ' ') . '</strong></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Statut:</th>
|
||||
<td>' . $paid_status . '</td>
|
||||
</tr>';
|
||||
|
||||
// Vérification et ajout des informations de paiement
|
||||
if (!empty($order_data['order_payment_mode'])) {
|
||||
$html .= '<tr>
|
||||
<th>Mode de paiement:</th>
|
||||
<td><strong>' . esc($order_data['order_payment_mode']) . '</strong></td>
|
||||
</tr>';
|
||||
}
|
||||
|
||||
if (!empty($order_data['tranche_1'])) {
|
||||
$html .= '<tr>
|
||||
<th>Tranche 1:</th>
|
||||
<td><strong>' . number_format((float)$order_data['tranche_1'], 2, '.', ' ') . '</strong></td>
|
||||
</tr>';
|
||||
}
|
||||
|
||||
if (!empty($order_data['tranche_2'])) {
|
||||
$html .= '<tr>
|
||||
<th>Tranche 2:</th>
|
||||
<td><strong>' . number_format((float)$order_data['tranche_2'], 2, '.', ' ') . '</strong></td>
|
||||
</tr>';
|
||||
}
|
||||
|
||||
$html .= '</table>
|
||||
|
||||
<div class="invoice-footer">
|
||||
Merci pour votre achat !<br>
|
||||
<strong>' . esc($company_info['company_name']) . '</strong>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
0
app/Database/Migrations/.gitkeep
Normal file
0
app/Database/Migrations/.gitkeep
Normal file
0
app/Database/Seeds/.gitkeep
Normal file
0
app/Database/Seeds/.gitkeep
Normal file
0
app/Filters/.gitkeep
Normal file
0
app/Filters/.gitkeep
Normal file
51
app/Filters/AuthCheck.php
Normal file
51
app/Filters/AuthCheck.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filters;
|
||||
|
||||
use CodeIgniter\Filters\FilterInterface;
|
||||
use CodeIgniter\HTTP\RequestInterface;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
|
||||
class AuthCheck implements FilterInterface
|
||||
{
|
||||
/**
|
||||
* Do whatever processing this filter needs to do.
|
||||
* By default it should not return anything during
|
||||
* normal execution. However, when an abnormal state
|
||||
* is found, it should return an instance of
|
||||
* CodeIgniter\HTTP\Response. If it does, script
|
||||
* execution will end and that Response will be
|
||||
* sent back to the client, allowing for error pages,
|
||||
* redirects, etc.
|
||||
*
|
||||
* @param RequestInterface $request
|
||||
* @param array|null $arguments
|
||||
*
|
||||
* @return RequestInterface|ResponseInterface|string|void
|
||||
*/
|
||||
public function before(RequestInterface $request, $arguments = null)
|
||||
{
|
||||
// Check if the user session exists
|
||||
if (!session()->get('user')) {
|
||||
// Redirect to login if not authenticated
|
||||
return redirect()->to('/login');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows After filters to inspect and modify the response
|
||||
* object as needed. This method does not allow any way
|
||||
* to stop execution of other after filters, short of
|
||||
* throwing an Exception or Error.
|
||||
*
|
||||
* @param RequestInterface $request
|
||||
* @param ResponseInterface $response
|
||||
* @param array|null $arguments
|
||||
*
|
||||
* @return ResponseInterface|void
|
||||
*/
|
||||
public function after(RequestInterface $request, ResponseInterface $response, $arguments = null)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
51
app/Filters/LoggedInFilter.php
Normal file
51
app/Filters/LoggedInFilter.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filters;
|
||||
|
||||
use CodeIgniter\Filters\FilterInterface;
|
||||
use CodeIgniter\HTTP\RequestInterface;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
|
||||
class LoggedInFilter implements FilterInterface
|
||||
{
|
||||
/**
|
||||
* Do whatever processing this filter needs to do.
|
||||
* By default it should not return anything during
|
||||
* normal execution. However, when an abnormal state
|
||||
* is found, it should return an instance of
|
||||
* CodeIgniter\HTTP\Response. If it does, script
|
||||
* execution will end and that Response will be
|
||||
* sent back to the client, allowing for error pages,
|
||||
* redirects, etc.
|
||||
*
|
||||
* @param RequestInterface $request
|
||||
* @param array|null $arguments
|
||||
*
|
||||
* @return RequestInterface|ResponseInterface|string|void
|
||||
*/
|
||||
public function before(RequestInterface $request, $arguments = null)
|
||||
{
|
||||
// Check if the user is logged in
|
||||
if (session()->has('user')) {
|
||||
// Redirect to the dashboard or any other protected page
|
||||
return redirect()->to('/');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows After filters to inspect and modify the response
|
||||
* object as needed. This method does not allow any way
|
||||
* to stop execution of other after filters, short of
|
||||
* throwing an Exception or Error.
|
||||
*
|
||||
* @param RequestInterface $request
|
||||
* @param ResponseInterface $response
|
||||
* @param array|null $arguments
|
||||
*
|
||||
* @return ResponseInterface|void
|
||||
*/
|
||||
public function after(RequestInterface $request, ResponseInterface $response, $arguments = null)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
53
app/Filters/PublicCheck.php
Normal file
53
app/Filters/PublicCheck.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filters;
|
||||
|
||||
use CodeIgniter\Filters\FilterInterface;
|
||||
use CodeIgniter\HTTP\RequestInterface;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
|
||||
class PublicCheck implements FilterInterface
|
||||
{
|
||||
/**
|
||||
* Do whatever processing this filter needs to do.
|
||||
* By default it should not return anything during
|
||||
* normal execution. However, when an abnormal state
|
||||
* is found, it should return an instance of
|
||||
* CodeIgniter\HTTP\Response. If it does, script
|
||||
* execution will end and that Response will be
|
||||
* sent back to the client, allowing for error pages,
|
||||
* redirects, etc.
|
||||
*
|
||||
* @param RequestInterface $request
|
||||
* @param array|null $arguments
|
||||
*
|
||||
* @return RequestInterface|ResponseInterface|string|void
|
||||
*/
|
||||
public function before(RequestInterface $request, $arguments = null)
|
||||
{
|
||||
// Check if the user session exists
|
||||
if (!session()->get('user')) {
|
||||
// Store the current URL in session so it can be accessed after login
|
||||
session()->set('redirect_url', current_url());
|
||||
// Redirect to login if not authenticated
|
||||
return redirect()->to('/login');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows After filters to inspect and modify the response
|
||||
* object as needed. This method does not allow any way
|
||||
* to stop execution of other after filters, short of
|
||||
* throwing an Exception or Error.
|
||||
*
|
||||
* @param RequestInterface $request
|
||||
* @param ResponseInterface $response
|
||||
* @param array|null $arguments
|
||||
*
|
||||
* @return ResponseInterface|void
|
||||
*/
|
||||
public function after(RequestInterface $request, ResponseInterface $response, $arguments = null)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
0
app/Helpers/.gitkeep
Normal file
0
app/Helpers/.gitkeep
Normal file
176
app/Helpers/alerts_helper.php
Normal file
176
app/Helpers/alerts_helper.php
Normal file
@ -0,0 +1,176 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Users;
|
||||
use App\Models\Avance;
|
||||
use App\Models\AlertMail;
|
||||
|
||||
function checkDeadlineAlerts()
|
||||
{
|
||||
log_message('info', "=== DÉBUT checkDeadlineAlerts ===");
|
||||
|
||||
$cacheFile = WRITEPATH . 'cache/check_deadline_last_run.txt';
|
||||
|
||||
// On enlève la vérification de 24h pour s'assurer que le script tourne quotidiennement
|
||||
file_put_contents($cacheFile, time());
|
||||
|
||||
$avanceModel = new Avance();
|
||||
$alertMailModel = new AlertMail();
|
||||
$usersModel = new Users();
|
||||
|
||||
$today = date('Y-m-d');
|
||||
log_message('info', "Date du jour: {$today}");
|
||||
|
||||
// Modification pour vérifier les avances dans 0-3 jours
|
||||
$avances = $avanceModel
|
||||
->where('DATE(deadline) >=', $today) // Inclut le jour même
|
||||
->where('DATE(deadline) <=', date('Y-m-d', strtotime('+3 days')))
|
||||
->where('active', 1)
|
||||
->findAll();
|
||||
|
||||
log_message('info', "Nombre d'avances trouvées (0-3 jours): " . count($avances));
|
||||
|
||||
$users = $usersModel->select('users.email, users.firstname, users.lastname')
|
||||
->join('user_group', 'user_group.user_id = users.id')
|
||||
->join('groups', 'groups.id = user_group.group_id')
|
||||
->where('groups.group_name', 'DAF')
|
||||
->findAll();
|
||||
|
||||
log_message('info', "Utilisateurs DAF trouvés: " . json_encode($users));
|
||||
|
||||
$emails = array_column($users, 'email');
|
||||
log_message('info', "Emails extraits: " . json_encode($emails));
|
||||
|
||||
if (empty($emails)) {
|
||||
log_message('error', "Aucun email DAF trouvé");
|
||||
|
||||
$db = \Config\Database::connect();
|
||||
$allGroups = $db->query("SELECT DISTINCT group_name FROM groups")->getResult();
|
||||
log_message('info', "Groupes disponibles: " . json_encode($allGroups));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($avances as $avance) {
|
||||
$deadline = date('Y-m-d', strtotime($avance['deadline']));
|
||||
$daysLeft = (int) ceil((strtotime($deadline) - strtotime($today)) / 86400);
|
||||
|
||||
log_message('info', "Avance ID: {$avance['avance_id']}, Deadline: {$deadline}, Jours restants: {$daysLeft}");
|
||||
|
||||
// Modification des types d'alerte pour 0, 1, 2, 3 jours
|
||||
$alertType = match($daysLeft) {
|
||||
3 => 'deadline_3_days',
|
||||
2 => 'deadline_2_days',
|
||||
1 => 'deadline_1_day',
|
||||
0 => 'deadline_today',
|
||||
default => null,
|
||||
};
|
||||
|
||||
if ($alertType === null) {
|
||||
log_message('info', "Pas d'alerte nécessaire pour {$daysLeft} jours restants");
|
||||
continue;
|
||||
}
|
||||
|
||||
log_message('info', "Type d'alerte: {$alertType}");
|
||||
|
||||
// Vérification si l'alerte a déjà été envoyée
|
||||
$alreadySent = $alertMailModel
|
||||
->where('avance_id', $avance['avance_id'])
|
||||
->where('alert_type', $alertType)
|
||||
->first();
|
||||
|
||||
if ($alreadySent) {
|
||||
log_message('info', "Alerte déjà envoyée pour avance_id={$avance['avance_id']} type={$alertType}");
|
||||
continue;
|
||||
}
|
||||
|
||||
// Message modifié pour inclure le cas du jour même
|
||||
$urgencyText = $daysLeft === 0 ? "ÉCHÉANCE AUJOURD'HUI" : "{$daysLeft} jour(s) restant(s)";
|
||||
$message = "
|
||||
<h3>⚠️ URGENT : Avance approchant de la deadline</h3>
|
||||
<p><strong>ID Avance :</strong> {$avance['avance_id']}</p>
|
||||
<p><strong>Client :</strong> {$avance['customer_name']}</p>
|
||||
<p><strong>Montant avance :</strong> " . number_format($avance['avance_amount'], 0, ',', ' ') . " Ar</p>
|
||||
<p><strong>Montant dû :</strong> " . number_format($avance['amount_due'], 0, ',', ' ') . " Ar</p>
|
||||
<p><strong>Deadline :</strong> {$deadline}</p>
|
||||
<p><strong>Statut :</strong> <span style='color: red; font-weight: bold;'>{$urgencyText}</span></p>
|
||||
<p><strong>Téléphone client :</strong> {$avance['customer_phone']}</p>
|
||||
<p><strong>Adresse client :</strong> {$avance['customer_address']}</p>
|
||||
<hr>
|
||||
<p><em>Cette avance " . ($daysLeft === 0 ? "arrive à échéance aujourd'hui" : "arrivera à échéance dans {$daysLeft} jour(s)") . ". Action requise immédiatement.</em></p>
|
||||
";
|
||||
|
||||
$emailsSent = 0;
|
||||
foreach ($emails as $to) {
|
||||
log_message('info', "Tentative d'envoi email à: {$to}");
|
||||
|
||||
$subject = $daysLeft === 0
|
||||
? "⚠️ AVANCE URGENTE - ÉCHÉANCE AUJOURD'HUI"
|
||||
: "⚠️ AVANCE URGENTE - {$daysLeft} jour(s) restant(s)";
|
||||
|
||||
if (sendEmailInBackground($to, $subject, $message)) {
|
||||
$emailsSent++;
|
||||
log_message('info', "Email envoyé avec succès à: {$to}");
|
||||
} else {
|
||||
log_message('error', "Échec envoi email à: {$to}");
|
||||
}
|
||||
}
|
||||
|
||||
if ($emailsSent > 0) {
|
||||
log_message('info', "Insertion alerte pour avance_id={$avance['avance_id']} avec type {$alertType}");
|
||||
$alertMailModel->insert([
|
||||
'avance_id' => $avance['avance_id'],
|
||||
'alert_type' => $alertType,
|
||||
'sent_date' => date('Y-m-d H:i:s'),
|
||||
'status' => 'sent',
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
]);
|
||||
} else {
|
||||
log_message('error', "Aucun email envoyé pour avance_id={$avance['avance_id']} avec type {$alertType}");
|
||||
}
|
||||
}
|
||||
|
||||
log_message('info', "=== FIN checkDeadlineAlerts ===");
|
||||
}
|
||||
|
||||
function sendEmailInBackground($to, $subject, $message)
|
||||
{
|
||||
try {
|
||||
log_message('info', "Préparation envoi email à: {$to}");
|
||||
|
||||
$email = \Config\Services::email();
|
||||
|
||||
$config = [
|
||||
'protocol' => 'smtp',
|
||||
'SMTPHost' => 'smtp.gmail.com',
|
||||
'SMTPUser' => 'rey342505@gmail.com',
|
||||
'SMTPPass' => 'loirqovmfuxnasrm',
|
||||
'SMTPPort' => 587,
|
||||
'SMTPCrypto' => 'tls',
|
||||
'mailType' => 'html',
|
||||
'charset' => 'utf-8',
|
||||
'newline' => "\r\n"
|
||||
];
|
||||
|
||||
$email->initialize($config);
|
||||
|
||||
$email->setFrom('rey342505@gmail.com', 'Système Motorbike - Alertes Avances');
|
||||
$email->setTo($to);
|
||||
$email->setSubject($subject);
|
||||
$email->setMessage($message);
|
||||
|
||||
log_message('info', "Configuration email terminée, tentative d'envoi...");
|
||||
|
||||
if (!$email->send()) {
|
||||
$debugInfo = $email->printDebugger(['headers']);
|
||||
log_message('error', "Erreur email à {$to}: " . print_r($debugInfo, true));
|
||||
return false;
|
||||
}
|
||||
|
||||
log_message('info', "Email envoyé avec succès à: {$to}");
|
||||
return true;
|
||||
|
||||
} catch (\Exception $e) {
|
||||
log_message('error', "Exception email à {$to}: " . $e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
15
app/Helpers/global_helper.php
Normal file
15
app/Helpers/global_helper.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
if (!function_exists('set_user_permission')) {
|
||||
function set_user_permission($permissions)
|
||||
{
|
||||
$GLOBALS['user_permission'] = $permissions;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('get_user_permission')) {
|
||||
function get_user_permission()
|
||||
{
|
||||
return isset($GLOBALS['user_permission']) ? $GLOBALS['user_permission'] : [];
|
||||
}
|
||||
}
|
||||
0
app/Language/.gitkeep
Normal file
0
app/Language/.gitkeep
Normal file
4
app/Language/en/Validation.php
Normal file
4
app/Language/en/Validation.php
Normal file
@ -0,0 +1,4 @@
|
||||
<?php
|
||||
|
||||
// override core en language system validation or define your own en language validation message
|
||||
return [];
|
||||
0
app/Libraries/.gitkeep
Normal file
0
app/Libraries/.gitkeep
Normal file
0
app/Models/.gitkeep
Normal file
0
app/Models/.gitkeep
Normal file
21
app/Models/AlertMail.php
Normal file
21
app/Models/AlertMail.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use CodeIgniter\Model;
|
||||
|
||||
class AlertMail extends Model
|
||||
{
|
||||
protected $table = 'email_alerts';
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
protected $allowedFields = [
|
||||
'avance_id',
|
||||
'alert_type',
|
||||
'sent_date',
|
||||
'status',
|
||||
'created_at',
|
||||
];
|
||||
|
||||
// Pas de fonction checkDeadlineAlerts ici !
|
||||
}
|
||||
72
app/Models/Assignation.php
Normal file
72
app/Models/Assignation.php
Normal file
@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use CodeIgniter\Model;
|
||||
|
||||
class Assignation extends Model
|
||||
{
|
||||
/**
|
||||
* table users name
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'affect_product';
|
||||
protected $primaryKey = 'id';
|
||||
protected $allowedFields = ['product_id', 'store_id', 'qty'];
|
||||
|
||||
public function affecterProduits($produitId, $quantite, $pointDeVenteId)
|
||||
{
|
||||
// Charger les modèles
|
||||
$produitModel = new Products();
|
||||
$pointDeVenteModel = new Stores();
|
||||
|
||||
// Récupérer le produit avec son stock et son point de vente principal
|
||||
$produit = $produitModel->find($produitId);
|
||||
|
||||
// Récupérer le point de vente principal
|
||||
$pointDeVentePrincipal = $pointDeVenteModel->find($produit['store_id']);
|
||||
|
||||
// Vérifier que le stock du produit principal est suffisant
|
||||
if ($produit['qty'] < $quantite) {
|
||||
return 'Stock insuffisant dans le point de vente principal';
|
||||
}
|
||||
|
||||
// Commencer une transaction pour s'assurer de l'intégrité des données
|
||||
$db = \Config\Database::connect();
|
||||
$db->transStart();
|
||||
|
||||
// 1. Réduire le stock du point de vente principal
|
||||
$newStockPrincipal = $pointDeVentePrincipal['stock'] - $quantite;
|
||||
$pointDeVenteModel->update($produit['point_vente_principal_id'], ['stock' => $newStockPrincipal]);
|
||||
|
||||
// 2. Augmenter le stock du point de vente cible
|
||||
$pointDeVente = $pointDeVenteModel->find($pointDeVenteId);
|
||||
$newStockVente = $pointDeVente['stock'] + $quantite;
|
||||
$pointDeVenteModel->update($pointDeVenteId, ['stock' => $newStockVente]);
|
||||
|
||||
// 3. Ajouter un enregistrement dans la table d'affectation
|
||||
$affectationModel = new AffectationProduitModel();
|
||||
$affectationModel->insert([
|
||||
'produit_id' => $produitId,
|
||||
'point_vente_id' => $pointDeVenteId,
|
||||
'quantite' => $quantite,
|
||||
'date_affectation' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
|
||||
// Si tout s'est bien passé, valider la transaction
|
||||
$db->transComplete();
|
||||
|
||||
// Vérifier si la transaction a réussi
|
||||
if ($db->transStatus() === FALSE) {
|
||||
return 'Une erreur est survenue lors de l\'affectation';
|
||||
}
|
||||
|
||||
return 'Affectation réussie';
|
||||
}
|
||||
|
||||
public function principalAffect(array $data)
|
||||
{
|
||||
return $this->insert($data);
|
||||
}
|
||||
|
||||
}
|
||||
151
app/Models/Attributes.php
Normal file
151
app/Models/Attributes.php
Normal file
@ -0,0 +1,151 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use CodeIgniter\Model;
|
||||
|
||||
class Attributes extends Model
|
||||
{
|
||||
/**
|
||||
* table users name
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'attributes';
|
||||
protected $primaryKey = 'id';
|
||||
protected $allowedFields = ['name', 'active'];
|
||||
|
||||
/**
|
||||
* get active attribute data
|
||||
* @return array
|
||||
*/
|
||||
public function getActiveAttributeData()
|
||||
{
|
||||
return $this->where('active', 1)->findAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* get data by id or all
|
||||
* @param int $id
|
||||
* @return array|object|null
|
||||
*/
|
||||
public function getAttributeData(int $id = null)
|
||||
{
|
||||
if ($id) {
|
||||
return $this->find($id); // Find by id
|
||||
}
|
||||
return $this->findAll(); // Get all
|
||||
}
|
||||
|
||||
/**
|
||||
* Count attribute values
|
||||
* @param mixed $id
|
||||
* @return int|string
|
||||
*/
|
||||
public function countAttributeValue($id = null)
|
||||
{
|
||||
if ($id) {
|
||||
return $this->builder('attribute_value')->where('attribute_parent_id', $id)->countAllResults();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get attribute value data by attribute_parent_id
|
||||
* @param mixed $id
|
||||
* @return array
|
||||
*/
|
||||
public function getAttributeValueData($id = null)
|
||||
{
|
||||
return $this->builder('attribute_value')->where('attribute_parent_id', $id)->get()->getResultArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get attribute value by id
|
||||
* @param mixed $id
|
||||
* @return array|null
|
||||
*/
|
||||
public function getAttributeValueById($id = null)
|
||||
{
|
||||
return $this->builder('attribute_value')->where('id', $id)->get()->getRowArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert attribute data
|
||||
* @param mixed $data
|
||||
* @return bool|int|string
|
||||
*/
|
||||
public function create($data)
|
||||
{
|
||||
if ($data) {
|
||||
return $this->insert($data); // Returns true/false based on success
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update attribute data
|
||||
* @param mixed $data
|
||||
* @param mixed $id
|
||||
* @return bool
|
||||
*/
|
||||
public function updateAttribute($data, $id)
|
||||
{
|
||||
if ($data && $id) {
|
||||
return $this->update($id, $data); // Returns true/false based on success
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove attribute data
|
||||
* @param mixed $id
|
||||
* @return bool|\CodeIgniter\Database\BaseResult
|
||||
*/
|
||||
public function remove($id)
|
||||
{
|
||||
if ($id) {
|
||||
return $this->delete($id); // Returns true/false based on success
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert attribute value
|
||||
* @param mixed $data
|
||||
* @return bool|\CodeIgniter\Database\BaseResult|\CodeIgniter\Database\Query
|
||||
*/
|
||||
public function createValue($data)
|
||||
{
|
||||
if ($data) {
|
||||
return $this->builder('attribute_value')->insert($data); // Insert into attribute_value table
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update attribute value
|
||||
* @param mixed $data
|
||||
* @param mixed $id
|
||||
* @return bool
|
||||
*/
|
||||
public function updateValue($data, $id)
|
||||
{
|
||||
if ($data && $id) {
|
||||
return $this->builder('attribute_value')->where('id', $id)->update($data); // Update attribute_value table
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove attribute value
|
||||
* @param mixed $id
|
||||
* @return bool|string
|
||||
*/
|
||||
public function removeValue($id)
|
||||
{
|
||||
if ($id) {
|
||||
return $this->builder('attribute_value')->where('id', $id)->delete(); // Delete from attribute_value table
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
0
app/Models/Auth.php
Normal file
0
app/Models/Auth.php
Normal file
292
app/Models/Avance.php
Normal file
292
app/Models/Avance.php
Normal file
@ -0,0 +1,292 @@
|
||||
<?php
|
||||
namespace App\Models;
|
||||
|
||||
use CodeIgniter\Model;
|
||||
|
||||
class Avance extends Model {
|
||||
protected $table = 'avances';
|
||||
protected $primaryKey = 'avance_id';
|
||||
|
||||
protected $allowedFields = [
|
||||
'avance_amount', 'avance_date','user_id',
|
||||
'customer_name', 'customer_address', 'customer_phone', 'customer_cin',
|
||||
'gross_amount','amount_due','product_id','is_order','active','store_id',
|
||||
'type_avance', 'deadline' // Ajout du champ type et deadline
|
||||
];
|
||||
|
||||
public function createAvance(array $data) {
|
||||
try {
|
||||
// Si la date de création n'est pas définie, on prend aujourd'hui
|
||||
if (empty($data['avance_date'])) {
|
||||
$data['avance_date'] = date('Y-m-d');
|
||||
}
|
||||
|
||||
// Calcul de la deadline en fonction du type
|
||||
if (!empty($data['type'])) {
|
||||
if (strtolower($data['type']) === 'avance sur terre') {
|
||||
$data['deadline'] = date('Y-m-d', strtotime($data['avance_date'] . ' +15 days'));
|
||||
} elseif (strtolower($data['type']) === 'avance sur mer') {
|
||||
$data['deadline'] = date('Y-m-d', strtotime($data['avance_date'] . ' +2 months'));
|
||||
}
|
||||
}
|
||||
|
||||
return $this->insert($data);
|
||||
} catch (\Exception $e) {
|
||||
log_message('error', 'Erreur lors de l\'ajout de l\'avance : ' . $e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function updateAvance(int $id, array $data) {
|
||||
if ($id <= 0) {
|
||||
log_message('error', 'ID invalide pour la mise à jour du recouvrement : ' . $id);
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
// Recalcul de la deadline si le type change
|
||||
if (!empty($data['type']) && !empty($data['avance_date'])) {
|
||||
if (strtolower($data['type']) === 'avance sur terre') {
|
||||
$data['deadline'] = date('Y-m-d', strtotime($data['avance_date'] . ' +15 days'));
|
||||
} elseif (strtolower($data['type']) === 'avance sur mer') {
|
||||
$data['deadline'] = date('Y-m-d', strtotime($data['avance_date'] . ' +2 months'));
|
||||
}
|
||||
}
|
||||
return $this->update($id, $data);
|
||||
} catch (\Exception $e) {
|
||||
log_message('error', 'Erreur lors de la mise à jour de l\'avance : ' . $e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// 📌 Le reste de tes fonctions restent inchangées
|
||||
public function getAllAvanceData(int $id=null) {
|
||||
$session = session();
|
||||
$users = $session->get('user');
|
||||
$isAdmin = in_array($users['group_name'], ['Conseil', 'Direction']);
|
||||
if($isAdmin) {
|
||||
if($id){
|
||||
try {
|
||||
return $this->where('user_id',$id)
|
||||
->where('is_order',0)
|
||||
->where('active',1)
|
||||
->orderBy('avance_date', 'DESC')
|
||||
->findAll();
|
||||
} catch (\Exception $e) {
|
||||
log_message('error', 'Erreur lors de la récupération des recouvrements : ' . $e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
try {
|
||||
return $this
|
||||
->where('is_order',0)
|
||||
->where('active',1)
|
||||
->orderBy('avance_date', 'DESC')
|
||||
->findAll();
|
||||
} catch (\Exception $e) {
|
||||
log_message('error', 'Erreur lors de la récupération des recouvrements : ' . $e->getMessage());
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if($id){
|
||||
try {
|
||||
return $this->where('user_id',$id)
|
||||
->where('is_order',0)
|
||||
->where('active',1)
|
||||
->where('store_id',$users['store_id'])
|
||||
->orderBy('avance_date', 'DESC')
|
||||
->findAll();
|
||||
} catch (\Exception $e) {
|
||||
log_message('error', 'Erreur lors de la récupération des recouvrements : ' . $e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
try {
|
||||
return $this
|
||||
->where('is_order',0)
|
||||
->where('active',1)
|
||||
->where('store_id',$users['store_id'])
|
||||
->orderBy('avance_date', 'DESC')
|
||||
->findAll();
|
||||
} catch (\Exception $e) {
|
||||
log_message('error', 'Erreur lors de la récupération des recouvrements : ' . $e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function fetchSingleAvance(int $avance_id){
|
||||
return $this->where('avance_id',$avance_id)->first();
|
||||
}
|
||||
|
||||
public function removeAvance(int $avance_id){
|
||||
return $this->delete($avance_id);
|
||||
}
|
||||
|
||||
public function getTotalAvance() {
|
||||
$session = session();
|
||||
$users = $session->get('user');
|
||||
$isAdmin = in_array($users['group_name'], ['Conseil', 'Direction']);
|
||||
if($isAdmin) {
|
||||
try {
|
||||
return $this->select('SUM(avance_amount) AS ta')
|
||||
->where('is_order', 0)
|
||||
->get()
|
||||
->getRowObject();
|
||||
} catch (\Exception $e) {
|
||||
log_message('error', 'Erreur lors du total du montant des avances : ' . $e->getMessage());
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
return $this->select('SUM(avance_amount) AS ta')
|
||||
->where('is_order', 0)
|
||||
->where('store_id',$users['store_id'])
|
||||
->get()
|
||||
->getRowObject();
|
||||
} catch (\Exception $e) {
|
||||
log_message('error', 'Erreur lors du total du montant des avances : ' . $e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getAllAvanceData1(int $id=null) {
|
||||
$session = session();
|
||||
$users = $session->get('user');
|
||||
$isAdmin = in_array($users['group_name'], ['Conseil', 'Direction']);
|
||||
if($isAdmin) {
|
||||
if($id){
|
||||
try {
|
||||
return $this->where('user_id',$id)
|
||||
->where('is_order',1)
|
||||
->where('active',1)
|
||||
->orderBy('avance_date', 'DESC')
|
||||
->findAll();
|
||||
} catch (\Exception $e) {
|
||||
log_message('error', 'Erreur lors de la récupération des recouvrements : ' . $e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
try {
|
||||
return $this
|
||||
->where('is_order',1)
|
||||
->where('active',1)
|
||||
->orderBy('avance_date', 'DESC')
|
||||
->findAll();
|
||||
} catch (\Exception $e) {
|
||||
log_message('error', 'Erreur lors de la récupération des recouvrements : ' . $e->getMessage());
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if($id){
|
||||
try {
|
||||
return $this->where('user_id',$id)
|
||||
->where('is_order',1)
|
||||
->where('active',1)
|
||||
->where('store_id',$users['store_id'])
|
||||
->orderBy('avance_date', 'DESC')
|
||||
->findAll();
|
||||
} catch (\Exception $e) {
|
||||
log_message('error', 'Erreur lors de la récupération des recouvrements : ' . $e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
try {
|
||||
return $this
|
||||
->where('is_order',0)
|
||||
->orderBy('avance_date', 'DESC')
|
||||
->findAll();
|
||||
} catch (\Exception $e) {
|
||||
log_message('error', 'Erreur lors de la récupération des recouvrements : ' . $e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getAllAvanceData2(int $id=null) {
|
||||
$session = session();
|
||||
$users = $session->get('user');
|
||||
$isAdmin = in_array($users['group_name'], ['Conseil', 'Direction']);
|
||||
if($isAdmin) {
|
||||
if($id){
|
||||
try {
|
||||
return $this->where('user_id',$id)
|
||||
->where('is_order',0)
|
||||
->where('active',0)
|
||||
->orderBy('avance_date', 'DESC')
|
||||
->findAll();
|
||||
} catch (\Exception $e) {
|
||||
log_message('error', 'Erreur lors de la récupération des recouvrements : ' . $e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
try {
|
||||
return $this
|
||||
->where('is_order',0)
|
||||
->where('active',0)
|
||||
->orderBy('avance_date', 'DESC')
|
||||
->findAll();
|
||||
} catch (\Exception $e) {
|
||||
log_message('error', 'Erreur lors de la récupération des recouvrements : ' . $e->getMessage());
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if($id){
|
||||
try {
|
||||
return $this->where('user_id',$id)
|
||||
->where('is_order',0)
|
||||
->where('active',0)
|
||||
->where('store_id',$users['store_id'])
|
||||
->orderBy('avance_date', 'DESC')
|
||||
->findAll();
|
||||
} catch (\Exception $e) {
|
||||
log_message('error', 'Erreur lors de la récupération des recouvrements : ' . $e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
try {
|
||||
return $this
|
||||
->where('is_order',0)
|
||||
->where('active',0)
|
||||
->where('store_id',$users['store_id'])
|
||||
->orderBy('avance_date', 'DESC')
|
||||
->findAll();
|
||||
} catch (\Exception $e) {
|
||||
log_message('error', 'Erreur lors de la récupération des recouvrements : ' . $e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function checkExpiredAvance() {
|
||||
$now = date('Y-m-d');
|
||||
$avances = $this->where('active', '1')
|
||||
->where('deadline <', $now)
|
||||
->findAll();
|
||||
|
||||
if (!empty($avances)) {
|
||||
$productModel = new Products();
|
||||
|
||||
foreach ($avances as $avance) {
|
||||
$this->update($avance['avance_id'], ['active' => '0']);
|
||||
$productModel->update($avance['product_id'], ['product_sold' => 0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Récupérer les avances qui arrivent à échéance dans X jours
|
||||
*/
|
||||
public function getAvancesNearDeadline($days = 3)
|
||||
{
|
||||
$alertDate = date('Y-m-d', strtotime("+{$days} days"));
|
||||
|
||||
return $this->select('avances.*, users.store_id')
|
||||
->join('users', 'users.id = avances.user_id')
|
||||
->where('avances.is_order', 0)
|
||||
->where('avances.active', 1)
|
||||
->where('avances.amount_due >', 0)
|
||||
->where('DATE(avances.deadline)', $alertDate)
|
||||
->findAll();
|
||||
}
|
||||
}
|
||||
|
||||
115
app/Models/Brands.php
Normal file
115
app/Models/Brands.php
Normal file
@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use CodeIgniter\Model;
|
||||
|
||||
class Brands extends Model
|
||||
{
|
||||
/**
|
||||
* table name
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'brands';
|
||||
protected $primaryKey = 'id'; // Primary key column
|
||||
protected $allowedFields = ['name', 'active'];
|
||||
|
||||
/**
|
||||
* Get active brands information
|
||||
* @return array
|
||||
*/
|
||||
public function getActiveBrands()
|
||||
{
|
||||
return $this->where('active', 1)->findAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get brand data by id or all
|
||||
* @param mixed $id
|
||||
* @return array|object|null
|
||||
*/
|
||||
public function getBrandData($id = null)
|
||||
{
|
||||
if ($id) {
|
||||
return $this->find($id); // Find by id
|
||||
}
|
||||
return $this->findAll(); // Get all
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert new brand
|
||||
* @param mixed $data
|
||||
* @return bool|int|string
|
||||
*/
|
||||
public function create($data)
|
||||
{
|
||||
if ($data) {
|
||||
return $this->insert($data); // Insert data and return true/false based on success
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update brand data
|
||||
* @param mixed $data
|
||||
* @param mixed $id
|
||||
* @return bool
|
||||
*/
|
||||
public function updateBrand($data, $id)
|
||||
{
|
||||
if ($data && $id) {
|
||||
return $this->update($id, $data); // Update data by id
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete brand
|
||||
* @param mixed $id
|
||||
* @return bool|\CodeIgniter\Database\BaseResult
|
||||
*/
|
||||
public function remove($id)
|
||||
{
|
||||
if ($id) {
|
||||
return $this->delete($id); // Delete by id
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return $this->db->table('brands')->select('name')->where('active', 1)->get()->getResult();
|
||||
}
|
||||
|
||||
public function getNameById(int $id)
|
||||
{
|
||||
return $this->select('name')->where('active', 1)
|
||||
->where('id', $id)->first();
|
||||
}
|
||||
|
||||
public function getOrCreateIdByName(string $name): int
|
||||
{
|
||||
$normalized = trim($name);
|
||||
|
||||
$brand = $this
|
||||
->where('name', $normalized)
|
||||
->first();
|
||||
|
||||
if ($brand) {
|
||||
return (int) $brand[$this->primaryKey];
|
||||
}
|
||||
|
||||
$newData = [
|
||||
'name' => $normalized,
|
||||
'active' => 1,
|
||||
];
|
||||
|
||||
$insertedId = $this->insert($newData);
|
||||
|
||||
if (! $insertedId) {
|
||||
throw new \RuntimeException('Impossible de créer le brand « ' . $normalized . ' »');
|
||||
}
|
||||
|
||||
return (int) $insertedId;
|
||||
}
|
||||
}
|
||||
95
app/Models/Caisse.php
Normal file
95
app/Models/Caisse.php
Normal file
@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use CodeIgniter\Model;
|
||||
|
||||
class Caisse extends Model{
|
||||
/**
|
||||
* table name
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'caisse';
|
||||
protected $primaryKey = 'caisse_id';
|
||||
protected $allowedFields = ['caisse_total', 'caisse_mvola', 'caisse_espece', 'caisse_banque'];
|
||||
|
||||
|
||||
public function getCaisseById($id = 1) {
|
||||
return $this->where('caisse_id', $id)->first();
|
||||
}
|
||||
|
||||
|
||||
public function updateCaisse($data) {
|
||||
try {
|
||||
$id = 1;
|
||||
if ($this->update($id, $data)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} catch (\Exception $e) {
|
||||
log_message('error', 'Erreur lors de la mise à jour de la caisse : ' . $e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function updateCaissePerRecouvrement($montant) {
|
||||
try {
|
||||
$this->transStart();
|
||||
|
||||
$this->set('caisse_espece', 'caisse_espece + ' . (float)$montant, false);
|
||||
$this->where('caisse_id', 1);
|
||||
$this->update();
|
||||
|
||||
$this->set('caisse_mvola', 'caisse_mvola - ' . (float)$montant, false);
|
||||
$this->where('caisse_id', 1);
|
||||
$this->update();
|
||||
|
||||
if ($this->transStatus() === false) {
|
||||
$this->transRollback();
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->transComplete();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
$this->transRollback();
|
||||
log_message('error', 'Erreur lors de la mise à jour de la caisse : ' . $e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function updateCaissePerOrders($p1, $p2, $operation = '+', $p3 = null, $destination = 'banque') {
|
||||
$caisse = $this->where('caisse_id', 1)->first();
|
||||
|
||||
if (!$caisse) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
$data = [
|
||||
'caisse_total' => $caisse['caisse_total'] + $p1,
|
||||
];
|
||||
|
||||
if ($operation == '+') {
|
||||
$data['caisse_mvola'] = $caisse['caisse_mvola'] + $p2;
|
||||
} elseif ($operation == '-') {
|
||||
$data['caisse_mvola'] = $caisse['caisse_mvola'] - $p2;
|
||||
}
|
||||
|
||||
if ($p3 !== null) {
|
||||
if ($destination === 'banque') {
|
||||
$data['caisse_banque'] = $caisse['caisse_banque'] + $p3;
|
||||
} elseif ($destination === 'espece') {
|
||||
$data['caisse_espece'] = $caisse['caisse_espece'] + $p3;
|
||||
}
|
||||
}
|
||||
|
||||
// Exécuter la mise à jour
|
||||
return $this->update(1, $data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
17
app/Models/Cash.php
Normal file
17
app/Models/Cash.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use CodeIgniter\Model;
|
||||
|
||||
class Cash extends Model
|
||||
{
|
||||
protected $table = 'cashtransaction';
|
||||
protected $primaryKey = 'id';
|
||||
protected $allowedFields = ['montant_caisse', 'montant_mvola', 'montant_banque'];
|
||||
|
||||
public function create()
|
||||
{
|
||||
$transaction = $this->db->table('orders');
|
||||
}
|
||||
}
|
||||
114
app/Models/Category.php
Normal file
114
app/Models/Category.php
Normal file
@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use CodeIgniter\Model;
|
||||
|
||||
class Category extends Model
|
||||
{
|
||||
/**
|
||||
* table name
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'categories';
|
||||
protected $primaryKey = 'id';
|
||||
protected $allowedFields = ['name', 'active'];
|
||||
|
||||
/**
|
||||
* Get active categories information
|
||||
* @return array
|
||||
*/
|
||||
public function getActiveCategory()
|
||||
{
|
||||
return $this->where('active', 1)->findAll(); // Get active categories
|
||||
}
|
||||
|
||||
/**
|
||||
* Get category data by id or all
|
||||
* @param mixed $id
|
||||
* @return array|object|null
|
||||
*/
|
||||
public function getCategoryData($id = null)
|
||||
{
|
||||
if ($id) {
|
||||
return $this->find($id); // Find by id
|
||||
}
|
||||
return $this->findAll(); // Get all
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert new category
|
||||
* @param mixed $data
|
||||
* @return bool|int|string
|
||||
*/
|
||||
public function create($data)
|
||||
{
|
||||
if ($data) {
|
||||
return $this->insert($data); // Insert data and return true/false based on success
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update category data
|
||||
* @param mixed $data
|
||||
* @param mixed $id
|
||||
* @return bool
|
||||
*/
|
||||
public function updateCategory($data, $id)
|
||||
{
|
||||
if ($data && $id) {
|
||||
return $this->update($id, $data); // Update data by id
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete category
|
||||
* @param mixed $id
|
||||
* @return bool|\CodeIgniter\Database\BaseResult
|
||||
*/
|
||||
public function remove($id)
|
||||
{
|
||||
if ($id) {
|
||||
return $this->delete($id); // Delete by id
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getOrCreateIdByName(string $name): int
|
||||
{
|
||||
$normalized = trim($name);
|
||||
|
||||
$brand = $this
|
||||
->where('name', $normalized)
|
||||
->first();
|
||||
|
||||
if ($brand) {
|
||||
return (int) $brand[$this->primaryKey];
|
||||
}
|
||||
|
||||
$newData = [
|
||||
'name' => $normalized,
|
||||
'active' => 1,
|
||||
];
|
||||
|
||||
$insertedId = $this->insert($newData);
|
||||
|
||||
if (! $insertedId) {
|
||||
throw new \RuntimeException('Impossible de créer le brand « ' . $normalized . ' »');
|
||||
}
|
||||
|
||||
return (int) $insertedId;
|
||||
}
|
||||
public function getNameById(string $id)
|
||||
{
|
||||
$result = $this->select('name')
|
||||
->where('id', $id)
|
||||
->first();
|
||||
|
||||
return $result ? $result['name'] : '';
|
||||
}
|
||||
|
||||
}
|
||||
45
app/Models/Company.php
Normal file
45
app/Models/Company.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use CodeIgniter\Model;
|
||||
|
||||
class Company extends Model
|
||||
{
|
||||
/**
|
||||
* table name
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'company';
|
||||
// List all the fields that are allowed to be updated or inserted
|
||||
protected $allowedFields = [
|
||||
'company_name', 'service_charge_value', 'vat_charge_value', 'address', 'phone', 'phone2', 'NIF', 'STAT', 'country', 'message', 'currency',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get company data by id or all
|
||||
* @param mixed $id
|
||||
* @return array<float|int|object|string|null>|object|null
|
||||
*/
|
||||
public function getCompanyData($id = null)
|
||||
{
|
||||
if ($id) {
|
||||
return $this->find($id); // Find by id
|
||||
}
|
||||
return null; // Return null if no id is provided
|
||||
}
|
||||
|
||||
/**
|
||||
* Update company data
|
||||
* @param mixed $data
|
||||
* @param mixed $id
|
||||
* @return bool
|
||||
*/
|
||||
public function updateCompany($data, $id)
|
||||
{
|
||||
if ($data && $id) {
|
||||
return $this->update($id, $data); // Update data by id
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user