mirror of
https://github.com/opensourcepos/opensourcepos.git
synced 2025-12-23 17:47:54 -05:00
Improve code style and PSR-12 compliance (#4204)
* Improve code style and PSR-12 compliance - refactored code formatting to adhere to PSR-12 guidelines - standardized coding conventions across the codebase - added missing framework files and reverted markup changes - reformatted arrays for enhanced readability - updated language files for consistent styling and clarity - minor miscellaneous improvements
This commit is contained in:
@@ -21,4 +21,3 @@ node_modules/
|
||||
*.log
|
||||
app/writable/session/*
|
||||
!app/writable/session/index.html
|
||||
|
||||
|
||||
@@ -1,22 +1,15 @@
|
||||
# editorconfig.org
|
||||
|
||||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
end_of_line = lf
|
||||
indent_size = 4
|
||||
indent_style = tab
|
||||
indent_style = space
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
max_line_length = 120
|
||||
tab_width = 4
|
||||
|
||||
[{*.cjs,*.js}]
|
||||
indent_style = tab
|
||||
|
||||
[{*.ctp,*.hphp,*.inc,*.module,*.php,*.php4,*.php5,*.phtml}]
|
||||
indent_style = tab
|
||||
|
||||
[{*.har,*.jsb2,*.jsb3,*.json,.babelrc,.eslintrc,.prettierrc,.stylelintrc,bowerrc,composer.lock,jest.config}]
|
||||
indent_style = tab
|
||||
|
||||
[{*.htm,*.html,*.ng,*.sht,*.shtm,*.shtml}]
|
||||
indent_style = tab
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
||||
|
||||
25
.env
25
.env
@@ -5,10 +5,10 @@
|
||||
CI_ENVIRONMENT = production
|
||||
CI_DEBUG = false
|
||||
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
# APP
|
||||
#--------------------------------------------------------------------
|
||||
|
||||
app.appTimezone = 'UTC'
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
@@ -44,6 +44,7 @@ database.tests.port = 3306
|
||||
#--------------------------------------------------------------------
|
||||
# EMAIL
|
||||
#--------------------------------------------------------------------
|
||||
|
||||
email.SMTPHost = ''
|
||||
email.SMTPUser = ''
|
||||
email.SMTPPass = ''
|
||||
@@ -64,21 +65,21 @@ encryption.key = ''
|
||||
honeypot.hidden = true
|
||||
honeypot.label = 'Fill This Field'
|
||||
honeypot.name = 'honeypot'
|
||||
honeypot.template = '<label>{label}</label><input type="text" name="{name}" value=""/>'
|
||||
honeypot.template = '<label>{label}</label><input type="text" name="{name}" value="">'
|
||||
honeypot.container = '<div style="display:none">{template}</div>'
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
# LOGGER
|
||||
# - 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
|
||||
# - 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
|
||||
#--------------------------------------------------------------------
|
||||
|
||||
logger.threshold = 0
|
||||
|
||||
22
.env-example
22
.env-example
@@ -37,16 +37,16 @@ encryption.key = ''
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
# LOGGER
|
||||
# - 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
|
||||
# - 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
|
||||
#--------------------------------------------------------------------
|
||||
|
||||
logger.threshold = 0
|
||||
@@ -59,5 +59,5 @@ app.db_log_enabled = false
|
||||
honeypot.hidden = true
|
||||
honeypot.label = 'Fill This Field'
|
||||
honeypot.name = 'honeypot'
|
||||
honeypot.template = '<label>{label}</label><input type="text" name="{name}" value=""/>'
|
||||
honeypot.template = '<label>{label}</label><input type="text" name="{name}" value="">'
|
||||
honeypot.container = '<div style="display:none">{template}</div>'
|
||||
|
||||
@@ -29,7 +29,7 @@ $finder = Finder::create()
|
||||
]);
|
||||
|
||||
$overrides = [
|
||||
// for updating to coding-standard
|
||||
// For updating to coding-standard
|
||||
'modernize_strpos' => true,
|
||||
];
|
||||
|
||||
|
||||
@@ -17,17 +17,17 @@ script:
|
||||
- version=$(grep application_version app/Config/App.php | sed "s/.*=\s'\(.*\)';/\1/g")
|
||||
- sed -i 's/production/development/g' .env
|
||||
- sed -i "s/commit_sha1 = 'dev'/commit_sha1 = '$rev'/g" app/Config/OSPOS.php
|
||||
- echo "$version-$branch-$rev"
|
||||
- echo "$version-$branch-$rev"
|
||||
- npm version "$version-$branch-$rev" --force || true
|
||||
- sed -i 's/opensourcepos.tar.gz/opensourcepos.$version.tgz/g' package.json
|
||||
- npm ci && npm install -g gulp && npm run build
|
||||
- npm ci && npm install -g gulp && npm run build
|
||||
- docker build . --target ospos -t ospos
|
||||
- docker build app/Database/ -t "jekkos/opensourcepos:sql-$TAG"
|
||||
env:
|
||||
global:
|
||||
- BRANCH=$(echo ${TRAVIS_BRANCH} | sed s/feature\\///)
|
||||
- TAG=${TRAVIS_TAG:-$BRANCH}
|
||||
- date=`date +%Y%m%d%H%M%S` && branch=${TRAVIS_BRANCH} && rev=`git rev-parse --short=6 HEAD`
|
||||
- date=`date +%Y%m%d%H%M%S` && branch=${TRAVIS_BRANCH} && rev=`git rev-parse --short=6 HEAD`
|
||||
after_success:
|
||||
- docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD" && docker tag "ospos:latest"
|
||||
"jekkos/opensourcepos:$TAG" && docker push "jekkos/opensourcepos:$TAG" && docker push "jekkos/opensourcepos:sql-$TAG"
|
||||
|
||||
@@ -2,7 +2,7 @@ FROM php:8.2-apache AS ospos
|
||||
LABEL maintainer="jekkos"
|
||||
|
||||
RUN apt update && apt-get install -y libicu-dev libgd-dev
|
||||
RUN a2enmod rewrite
|
||||
RUN a2enmod rewrite
|
||||
RUN docker-php-ext-install mysqli bcmath intl gd
|
||||
RUN echo "date.timezone = \"\${PHP_TIMEZONE}\"" > /usr/local/etc/php/conf.d/timezone.ini
|
||||
|
||||
@@ -18,7 +18,7 @@ COPY --from=composer /usr/bin/composer /usr/bin/composer
|
||||
RUN apt-get install -y libzip-dev wget git
|
||||
RUN wget https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh -O /bin/wait-for-it.sh && chmod +x /bin/wait-for-it.sh
|
||||
RUN docker-php-ext-install zip
|
||||
RUN composer install -d/app
|
||||
RUN composer install -d/app
|
||||
#RUN sed -i 's/backupGlobals="true"/backupGlobals="false"/g' /app/tests/phpunit.xml
|
||||
WORKDIR /app/tests
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<IfModule authz_core_module>
|
||||
Require all denied
|
||||
Require all denied
|
||||
</IfModule>
|
||||
<IfModule !authz_core_module>
|
||||
Deny from all
|
||||
Deny from all
|
||||
</IfModule>
|
||||
|
||||
@@ -40,7 +40,7 @@ class App extends BaseConfig
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public bool $https_on; //Set in the constructor
|
||||
public bool $https_on; // Set in the constructor
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
@@ -52,7 +52,7 @@ class App extends BaseConfig
|
||||
*
|
||||
* E.g., http://example.com/
|
||||
*/
|
||||
public string $baseURL; //Defined in the constructor
|
||||
public string $baseURL; // Defined in the constructor
|
||||
|
||||
/**
|
||||
* Allowed Hostnames in the Site URL other than the hostname in the baseURL.
|
||||
@@ -278,7 +278,7 @@ class App extends BaseConfig
|
||||
* @see http://www.html5rocks.com/en/tutorials/security/content-security-policy/
|
||||
* @see http://www.w3.org/TR/CSP/
|
||||
*/
|
||||
public bool $CSPEnabled = false; //TODO: Currently CSP3 tags are not supported so enabling this causes problems with script-src-elem, style-src-attr and style-src-elem
|
||||
public bool $CSPEnabled = false; // TODO: Currently CSP3 tags are not supported so enabling this causes problems with script-src-elem, style-src-attr and style-src-elem
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
@@ -42,7 +42,7 @@ class Autoload extends AutoloadConfig
|
||||
public $psr4 = [
|
||||
APP_NAMESPACE => APPPATH,
|
||||
'Config' => APPPATH . 'Config',
|
||||
'dompdf' => APPPATH . 'ThirdParty/dompdf/src'
|
||||
'dompdf' => APPPATH . 'ThirdParty/dompdf/src'
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -63,112 +63,112 @@ class Autoload extends AutoloadConfig
|
||||
* @var array<string, string>
|
||||
*/
|
||||
public $classmap = [
|
||||
//Controllers
|
||||
'Attributes' => '/App/Controllers/Attributes.php',
|
||||
'Cashups' => '/App/Controllers/Cashups.php',
|
||||
'Config' => '/App/Controllers/Config.php',
|
||||
'Customers' => '/App/Controllers/Customers.php',
|
||||
'Employees' => '/App/Controllers/Employees.php',
|
||||
'Expenses' => '/App/Controllers/Expenses.php',
|
||||
// Controllers
|
||||
'Attributes' => '/App/Controllers/Attributes.php',
|
||||
'Cashups' => '/App/Controllers/Cashups.php',
|
||||
'Config' => '/App/Controllers/Config.php',
|
||||
'Customers' => '/App/Controllers/Customers.php',
|
||||
'Employees' => '/App/Controllers/Employees.php',
|
||||
'Expenses' => '/App/Controllers/Expenses.php',
|
||||
'Expenses_categories' => '/App/Controllers/Expenses_categories.php',
|
||||
'Giftcards' => '/App/Controllers/Giftcards.php',
|
||||
'Home' => '/App/Controllers/Home.php',
|
||||
'Item_kits' => '/App/Controllers/Item_kits.php',
|
||||
'Items' => '/App/Controllers/Items.php',
|
||||
'Login' => '/App/Controllers/Login.php',
|
||||
'Messages' => '/App/Controllers/Messages.php',
|
||||
'No_access' => '/App/Controllers/No_access.php',
|
||||
'Office' => '/App/Controllers/Office.php',
|
||||
'Persons' => '/App/Controllers/Persons.php',
|
||||
'Receivings' => '/App/Controllers/Receivings.php',
|
||||
'Reports' => '/App/Controllers/Reports.php',
|
||||
'Sales' => '/App/Controllers/Sales.php',
|
||||
'Secure_Controller' => '/App/Controllers/Secure_Controller.php',
|
||||
'Suppliers' => '/App/Controllers/Suppliers.php',
|
||||
'Tax_categories' => '/App/Controllers/Tax_categories.php',
|
||||
'Tax_codes' => '/App/Controllers/Tax_codes.php',
|
||||
'Tax_jurisdictions' => '/App/Controllers/Tax_jurisdictions.php',
|
||||
'Taxes' => '/App/Controllers/Taxes.php',
|
||||
'Giftcards' => '/App/Controllers/Giftcards.php',
|
||||
'Home' => '/App/Controllers/Home.php',
|
||||
'Item_kits' => '/App/Controllers/Item_kits.php',
|
||||
'Items' => '/App/Controllers/Items.php',
|
||||
'Login' => '/App/Controllers/Login.php',
|
||||
'Messages' => '/App/Controllers/Messages.php',
|
||||
'No_access' => '/App/Controllers/No_access.php',
|
||||
'Office' => '/App/Controllers/Office.php',
|
||||
'Persons' => '/App/Controllers/Persons.php',
|
||||
'Receivings' => '/App/Controllers/Receivings.php',
|
||||
'Reports' => '/App/Controllers/Reports.php',
|
||||
'Sales' => '/App/Controllers/Sales.php',
|
||||
'Secure_Controller' => '/App/Controllers/Secure_Controller.php',
|
||||
'Suppliers' => '/App/Controllers/Suppliers.php',
|
||||
'Tax_categories' => '/App/Controllers/Tax_categories.php',
|
||||
'Tax_codes' => '/App/Controllers/Tax_codes.php',
|
||||
'Tax_jurisdictions' => '/App/Controllers/Tax_jurisdictions.php',
|
||||
'Taxes' => '/App/Controllers/Taxes.php',
|
||||
|
||||
//Models
|
||||
'Appconfig' => '/App/Models/Appconfig.php',
|
||||
'Attribute' => '/App/Models/Attribute.php',
|
||||
'Cashup' => '/App/Models/Cashup.php',
|
||||
'Customer' => '/App/Models/Customer.php',
|
||||
// Models
|
||||
'Appconfig' => '/App/Models/Appconfig.php',
|
||||
'Attribute' => '/App/Models/Attribute.php',
|
||||
'Cashup' => '/App/Models/Cashup.php',
|
||||
'Customer' => '/App/Models/Customer.php',
|
||||
'Customer_rewards' => '/App/Models/Customer_rewards.php',
|
||||
'Dinner_table' => '/App/Models/Dinner_table.php',
|
||||
'Employee' => '/App/Models/Employee.php',
|
||||
'Expense' => '/App/Models/Expense.php',
|
||||
'Dinner_table' => '/App/Models/Dinner_table.php',
|
||||
'Employee' => '/App/Models/Employee.php',
|
||||
'Expense' => '/App/Models/Expense.php',
|
||||
'Expense_category' => '/App/Models/Expense_category.php',
|
||||
'Giftcard' => '/App/Models/Giftcard.php',
|
||||
'Inventory' => '/App/Models/Inventory.php',
|
||||
'Item_kit' => '/App/Models/Item_kit.php',
|
||||
'Item_kit_items' => '/App/Models/Item_kit_items.php',
|
||||
'Item_quantity' => '/App/Models/Item_quantity.php',
|
||||
'Item_taxes' => '/App/Models/Item_taxes.php',
|
||||
'Module' => '/App/Models/Module.php',
|
||||
'Person' => '/App/Models/Person.php',
|
||||
'Receiving' => '/App/Models/Receiving.php',
|
||||
'Rewards' => '/App/Models/Rewards.php',
|
||||
'Sale' => '/App/Models/Sale.php',
|
||||
'Stock_location' => '/App/Models/Stock_location.php',
|
||||
'Supplier' => '/App/Models/Supplier.php',
|
||||
'Tax' => '/App/Models/Tax.php',
|
||||
'Tax_category' => '/App/Models/Tax_category.php',
|
||||
'Tax_code' => '/App/Models/Tax_code.php',
|
||||
'Giftcard' => '/App/Models/Giftcard.php',
|
||||
'Inventory' => '/App/Models/Inventory.php',
|
||||
'Item_kit' => '/App/Models/Item_kit.php',
|
||||
'Item_kit_items' => '/App/Models/Item_kit_items.php',
|
||||
'Item_quantity' => '/App/Models/Item_quantity.php',
|
||||
'Item_taxes' => '/App/Models/Item_taxes.php',
|
||||
'Module' => '/App/Models/Module.php',
|
||||
'Person' => '/App/Models/Person.php',
|
||||
'Receiving' => '/App/Models/Receiving.php',
|
||||
'Rewards' => '/App/Models/Rewards.php',
|
||||
'Sale' => '/App/Models/Sale.php',
|
||||
'Stock_location' => '/App/Models/Stock_location.php',
|
||||
'Supplier' => '/App/Models/Supplier.php',
|
||||
'Tax' => '/App/Models/Tax.php',
|
||||
'Tax_category' => '/App/Models/Tax_category.php',
|
||||
'Tax_code' => '/App/Models/Tax_code.php',
|
||||
'Tax_jurisdiction' => '/App/Models/Tax_jurisdiction.php',
|
||||
|
||||
//Reports
|
||||
'Report' => '/App/Models/Reports/Report.php',
|
||||
'Detailed_receiving' => '/App/Models/Reports/Detailed_receiving.php',
|
||||
'Detailed_sales' => '/App/Models/Reports/Detailed_sales.php',
|
||||
'Inventory_low' => '/App/Models/Reports/Inventory_low.php',
|
||||
'Inventory_summary' => '/App/Models/Reports/Inventory_summary.php',
|
||||
'Specific_customer' => '/App/Models/Reports/Specific_customer.php',
|
||||
'Specific_discount' => '/App/Models/Reports/Specific_discount.php',
|
||||
'Specific_employee' => '/App/Models/Reports/Specific_employee.php',
|
||||
'Specific_supplier' => '/App/Models/Reports/Specific_supplier.php',
|
||||
'Summary_categories' => '/App/Models/Reports/Summary_categories.php',
|
||||
'Summary_customers' => '/App/Models/Reports/Summary_customers.php',
|
||||
'Summary_discounts' => '/App/Models/Reports/Summary_discounts.php',
|
||||
'Summary_employees' => '/App/Models/Reports/Summary_employees.php',
|
||||
// Reports
|
||||
'Report' => '/App/Models/Reports/Report.php',
|
||||
'Detailed_receiving' => '/App/Models/Reports/Detailed_receiving.php',
|
||||
'Detailed_sales' => '/App/Models/Reports/Detailed_sales.php',
|
||||
'Inventory_low' => '/App/Models/Reports/Inventory_low.php',
|
||||
'Inventory_summary' => '/App/Models/Reports/Inventory_summary.php',
|
||||
'Specific_customer' => '/App/Models/Reports/Specific_customer.php',
|
||||
'Specific_discount' => '/App/Models/Reports/Specific_discount.php',
|
||||
'Specific_employee' => '/App/Models/Reports/Specific_employee.php',
|
||||
'Specific_supplier' => '/App/Models/Reports/Specific_supplier.php',
|
||||
'Summary_categories' => '/App/Models/Reports/Summary_categories.php',
|
||||
'Summary_customers' => '/App/Models/Reports/Summary_customers.php',
|
||||
'Summary_discounts' => '/App/Models/Reports/Summary_discounts.php',
|
||||
'Summary_employees' => '/App/Models/Reports/Summary_employees.php',
|
||||
'Summary_expenses_categories' => '/App/Models/Reports/Summary_expenses_categories.php',
|
||||
'Summary_items' => '/App/Models/Reports/Summary_items.php',
|
||||
'Summary_payments' => '/App/Models/Reports/Summary_payments.php',
|
||||
'Summary_report' => '/App/Models/Reports/Summary_report.php',
|
||||
'Summary_sales' => '/App/Models/Reports/Summary_sales.php',
|
||||
'Summary_sales_taxes' => '/App/Models/Reports/Summary_sales_taxes.php',
|
||||
'Summary_suppliers' => '/App/Models/Reports/Summary_suppliers.php',
|
||||
'Summary_taxes' => '/App/Models/Reports/Summary_taxes.php',
|
||||
'Summary_items' => '/App/Models/Reports/Summary_items.php',
|
||||
'Summary_payments' => '/App/Models/Reports/Summary_payments.php',
|
||||
'Summary_report' => '/App/Models/Reports/Summary_report.php',
|
||||
'Summary_sales' => '/App/Models/Reports/Summary_sales.php',
|
||||
'Summary_sales_taxes' => '/App/Models/Reports/Summary_sales_taxes.php',
|
||||
'Summary_suppliers' => '/App/Models/Reports/Summary_suppliers.php',
|
||||
'Summary_taxes' => '/App/Models/Reports/Summary_taxes.php',
|
||||
|
||||
//Tokens
|
||||
'Token' => '/App/Models/Tokens/Token.php',
|
||||
'Token_barcode_ean' => '/App/Models/Tokens/Token_barcode_ean.php',
|
||||
'Token_barcode_price' => '/App/Models/Tokens/Token_barcode_price.php',
|
||||
'Token_barcode_weight' => '/App/Models/Tokens/Token_barcode_weight.php',
|
||||
'Token_customer' => '/App/Models/Tokens/Token_customer.php',
|
||||
'Token_invoice_count' => '/App/Models/Tokens/Token_invoice_count.php',
|
||||
'Token_invoice_sequence' => '/App/Models/Tokens/Token_invoice_sequence.php',
|
||||
'Token_quote_sequence' => '/App/Models/Tokens/Token_quote_sequence.php',
|
||||
// Tokens
|
||||
'Token' => '/App/Models/Tokens/Token.php',
|
||||
'Token_barcode_ean' => '/App/Models/Tokens/Token_barcode_ean.php',
|
||||
'Token_barcode_price' => '/App/Models/Tokens/Token_barcode_price.php',
|
||||
'Token_barcode_weight' => '/App/Models/Tokens/Token_barcode_weight.php',
|
||||
'Token_customer' => '/App/Models/Tokens/Token_customer.php',
|
||||
'Token_invoice_count' => '/App/Models/Tokens/Token_invoice_count.php',
|
||||
'Token_invoice_sequence' => '/App/Models/Tokens/Token_invoice_sequence.php',
|
||||
'Token_quote_sequence' => '/App/Models/Tokens/Token_quote_sequence.php',
|
||||
'Token_suspended_invoice_count' => '/App/Models/Tokens/Token_suspended_invoice_count.php',
|
||||
'Token_work_order_sequence' => '/App/Models/Tokens/Token_work_order_sequence.php',
|
||||
'Token_year_invoice_count' => '/App/Models/Tokens/Token_year_invoice_count.php',
|
||||
'Token_year_quote_count' => '/App/Models/Tokens/Token_year_quote_count.php',
|
||||
'Token_work_order_sequence' => '/App/Models/Tokens/Token_work_order_sequence.php',
|
||||
'Token_year_invoice_count' => '/App/Models/Tokens/Token_year_invoice_count.php',
|
||||
'Token_year_quote_count' => '/App/Models/Tokens/Token_year_quote_count.php',
|
||||
|
||||
//Libraries
|
||||
'Barcode_lib' => '/App/Libraries/Barcode_lib.php',
|
||||
'Email_lib' => '/App/Libraries/Email_lib.php',
|
||||
'Item_lib' => '/App/Libraries/Item_lib.php',
|
||||
// Libraries
|
||||
'Barcode_lib' => '/App/Libraries/Barcode_lib.php',
|
||||
'Email_lib' => '/App/Libraries/Email_lib.php',
|
||||
'Item_lib' => '/App/Libraries/Item_lib.php',
|
||||
'Mailchimp_lib' => '/App/Libraries/Mailchimp_lib.php',
|
||||
'MY_Email' => '/App/Libraries/MY_Email.php',
|
||||
'MY_Migration' => '/App/Libraries/MY_Migration.php',
|
||||
'Receving_lib' => '/App/Libraries/Receiving_lib.php',
|
||||
'Sale_lib' => '/App/Libraries/Sale_lib.php',
|
||||
'Sms_lib' => '/App/Libraries/Sms_lib.php',
|
||||
'Tax_lib' => '/App/Libraries/Tax_lib.php',
|
||||
'Token_lib' => '/App/Libraries/Token_lib.php',
|
||||
'MY_Email' => '/App/Libraries/MY_Email.php',
|
||||
'MY_Migration' => '/App/Libraries/MY_Migration.php',
|
||||
'Receving_lib' => '/App/Libraries/Receiving_lib.php',
|
||||
'Sale_lib' => '/App/Libraries/Sale_lib.php',
|
||||
'Sms_lib' => '/App/Libraries/Sms_lib.php',
|
||||
'Tax_lib' => '/App/Libraries/Tax_lib.php',
|
||||
'Token_lib' => '/App/Libraries/Token_lib.php',
|
||||
|
||||
//Miscellaneous
|
||||
// Miscellaneous
|
||||
'Rounding_mode' => '/App/Models/Enums/Rounding_mode.php'
|
||||
];
|
||||
|
||||
|
||||
@@ -41,10 +41,9 @@ 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);
|
||||
defined('DEFAULT_DATE') || define('DEFAULT_DATE', mktime(0, 0, 0, 1, 1, 2010));
|
||||
defined('DEFAULT_DATE') || define('DEFAULT_DATE', mktime(0, 0, 0, 1, 1, 2010));
|
||||
defined('DEFAULT_DATETIME') || define('DEFAULT_DATETIME', mktime(0, 0, 0, 1, 1, 2010));
|
||||
defined('NOW') || define('NOW', time());
|
||||
|
||||
defined('NOW') || define('NOW', time());
|
||||
|
||||
/*
|
||||
| --------------------------------------------------------------------------
|
||||
|
||||
@@ -25,23 +25,23 @@ class Database extends Config
|
||||
* @var array<string, mixed>
|
||||
*/
|
||||
public array $default = [
|
||||
'DSN' => '',
|
||||
'hostname' => 'localhost',
|
||||
'username' => 'admin',
|
||||
'password' => 'pointofsale',
|
||||
'database' => 'ospos',
|
||||
'DBDriver' => 'MySQLi',
|
||||
'DBPrefix' => 'ospos_',
|
||||
'pConnect' => false,
|
||||
'DBDebug' => (ENVIRONMENT !== 'production'),
|
||||
'charset' => 'utf8mb4',
|
||||
'DBCollat' => 'utf8mb4_general_ci',
|
||||
'swapPre' => '',
|
||||
'encrypt' => false,
|
||||
'compress' => false,
|
||||
'strictOn' => false,
|
||||
'failover' => [],
|
||||
'port' => 3306,
|
||||
'DSN' => '',
|
||||
'hostname' => 'localhost',
|
||||
'username' => 'admin',
|
||||
'password' => 'pointofsale',
|
||||
'database' => 'ospos',
|
||||
'DBDriver' => 'MySQLi',
|
||||
'DBPrefix' => 'ospos_',
|
||||
'pConnect' => false,
|
||||
'DBDebug' => (ENVIRONMENT !== 'production'),
|
||||
'charset' => 'utf8mb4',
|
||||
'DBCollat' => 'utf8mb4_general_ci',
|
||||
'swapPre' => '',
|
||||
'encrypt' => false,
|
||||
'compress' => false,
|
||||
'strictOn' => false,
|
||||
'failover' => [],
|
||||
'port' => 3306,
|
||||
'dateFormat' => [
|
||||
'date' => 'Y-m-d',
|
||||
'datetime' => 'Y-m-d H:i:s',
|
||||
@@ -50,31 +50,30 @@ class Database extends Config
|
||||
];
|
||||
|
||||
/**
|
||||
* This database connection is used when
|
||||
* running PHPUnit database tests.
|
||||
* This database connection is used when running PHPUnit database tests.
|
||||
*
|
||||
* @var array<string, mixed>
|
||||
*/
|
||||
public array $tests = [
|
||||
'DSN' => '',
|
||||
'hostname' => 'localhost',
|
||||
'username' => 'admin',
|
||||
'password' => 'pointofsale',
|
||||
'database' => 'ospos',
|
||||
'DBDriver' => 'MySQLi',
|
||||
'DBPrefix' => 'ospos_',
|
||||
'pConnect' => false,
|
||||
'DBDebug' => (ENVIRONMENT !== 'production'),
|
||||
'charset' => 'utf8mb4',
|
||||
'DBCollat' => 'utf8mb4_general_ci',
|
||||
'swapPre' => '',
|
||||
'encrypt' => false,
|
||||
'compress' => false,
|
||||
'strictOn' => false,
|
||||
'failover' => [],
|
||||
'port' => 3306,
|
||||
'foreignKeys' => true,
|
||||
'busyTimeout' => 1000,
|
||||
'DSN' => '',
|
||||
'hostname' => 'localhost',
|
||||
'username' => 'admin',
|
||||
'password' => 'pointofsale',
|
||||
'database' => 'ospos',
|
||||
'DBDriver' => 'MySQLi',
|
||||
'DBPrefix' => 'ospos_',
|
||||
'pConnect' => false,
|
||||
'DBDebug' => (ENVIRONMENT !== 'production'),
|
||||
'charset' => 'utf8mb4',
|
||||
'DBCollat' => 'utf8mb4_general_ci',
|
||||
'swapPre' => '',
|
||||
'encrypt' => false,
|
||||
'compress' => false,
|
||||
'strictOn' => false,
|
||||
'failover' => [],
|
||||
'port' => 3306,
|
||||
'foreignKeys' => true,
|
||||
'busyTimeout' => 1000,
|
||||
'dateFormat' => [
|
||||
'date' => 'Y-m-d',
|
||||
'datetime' => 'Y-m-d H:i:s',
|
||||
@@ -83,32 +82,31 @@ class Database extends Config
|
||||
];
|
||||
|
||||
/**
|
||||
* This database connection is used when
|
||||
* developing against non-production data.
|
||||
* This database connection is used when developing against non-production data.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $development = [
|
||||
'DSN' => '',
|
||||
'hostname' => 'localhost',
|
||||
'username' => 'admin',
|
||||
'password' => 'pointofsale',
|
||||
'database' => 'ospos',
|
||||
'DBDriver' => 'MySQLi',
|
||||
'DBPrefix' => 'ospos_',
|
||||
'pConnect' => false,
|
||||
'DBDebug' => (ENVIRONMENT !== 'production'),
|
||||
'charset' => 'utf8mb4',
|
||||
'DBCollat' => 'utf8mb4_general_ci',
|
||||
'swapPre' => '',
|
||||
'encrypt' => false,
|
||||
'compress' => false,
|
||||
'strictOn' => false,
|
||||
'failover' => [],
|
||||
'port' => 3306,
|
||||
'foreignKeys' => true,
|
||||
'busyTimeout' => 1000,
|
||||
'dateFormat' => [
|
||||
'DSN' => '',
|
||||
'hostname' => 'localhost',
|
||||
'username' => 'admin',
|
||||
'password' => 'pointofsale',
|
||||
'database' => 'ospos',
|
||||
'DBDriver' => 'MySQLi',
|
||||
'DBPrefix' => 'ospos_',
|
||||
'pConnect' => false,
|
||||
'DBDebug' => (ENVIRONMENT !== 'production'),
|
||||
'charset' => 'utf8mb4',
|
||||
'DBCollat' => 'utf8mb4_general_ci',
|
||||
'swapPre' => '',
|
||||
'encrypt' => false,
|
||||
'compress' => false,
|
||||
'strictOn' => false,
|
||||
'failover' => [],
|
||||
'port' => 3306,
|
||||
'foreignKeys' => true,
|
||||
'busyTimeout' => 1000,
|
||||
'dateFormat' => [
|
||||
'date' => 'Y-m-d',
|
||||
'datetime' => 'Y-m-d H:i:s',
|
||||
'time' => 'H:i:s',
|
||||
@@ -122,8 +120,7 @@ class Database extends Config
|
||||
// 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.
|
||||
switch(ENVIRONMENT)
|
||||
{
|
||||
switch (ENVIRONMENT) {
|
||||
case 'testing':
|
||||
$this->defaultGroup = 'tests';
|
||||
break;
|
||||
@@ -132,8 +129,7 @@ class Database extends Config
|
||||
break;
|
||||
}
|
||||
|
||||
foreach ([&$this->development, &$this->tests, &$this->default] as &$config)
|
||||
{
|
||||
foreach ([&$this->development, &$this->tests, &$this->default] as &$config) {
|
||||
$config['hostname'] = !getenv('MYSQL_HOST_NAME') ? $config['hostname'] : getenv('MYSQL_HOST_NAME');
|
||||
$config['username'] = !getenv('MYSQL_USERNAME') ? $config['username'] : getenv('MYSQL_USERNAME');
|
||||
$config['password'] = !getenv('MYSQL_PASSWORD') ? $config['password'] : getenv('MYSQL_PASSWORD');
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
|
||||
namespace Config;
|
||||
|
||||
use App\Events\Db_log;
|
||||
use App\Events\Load_config;
|
||||
use App\Events\Method;
|
||||
use CodeIgniter\Events\Events;
|
||||
use CodeIgniter\Exceptions\FrameworkException;
|
||||
use CodeIgniter\HotReloader\HotReloader;
|
||||
use App\Events\Db_log;
|
||||
use App\Events\Load_config;
|
||||
use App\Events\Method;
|
||||
|
||||
/*
|
||||
* --------------------------------------------------------------------
|
||||
|
||||
@@ -80,7 +80,7 @@ class Exceptions extends BaseConfig
|
||||
*/
|
||||
public string $deprecationLogLevel = LogLevel::WARNING;
|
||||
|
||||
/**
|
||||
/*
|
||||
* DEFINE THE HANDLERS USED
|
||||
* --------------------------------------------------------------------------
|
||||
* Given the HTTP status code, returns exception handler that
|
||||
|
||||
@@ -70,7 +70,7 @@ class Filters extends BaseFilters
|
||||
public array $globals = [
|
||||
'before' => [
|
||||
'honeypot',
|
||||
//'csrf' => ['except' => 'login'], //TODO: Temporarily disable CSRF until we get everything sorted.
|
||||
// 'csrf' => ['except' => 'login'], // TODO: Temporarily disable CSRF until we get everything sorted
|
||||
'invalidchars',
|
||||
],
|
||||
'after' => [
|
||||
|
||||
@@ -494,8 +494,7 @@ class Mimes
|
||||
{
|
||||
$extension = trim(strtolower($extension), '. ');
|
||||
|
||||
if (!array_key_exists($extension, static::$mimes))
|
||||
{
|
||||
if (! array_key_exists($extension, static::$mimes)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ use CodeIgniter\Config\BaseConfig;
|
||||
class OSPOS extends BaseConfig
|
||||
{
|
||||
public array $settings;
|
||||
public string $commit_sha1 = 'dev'; //TODO: Travis scripts need to be updated to replace this with the commit hash on build
|
||||
public string $commit_sha1 = 'dev'; // TODO: Travis scripts need to be updated to replace this with the commit hash on build
|
||||
private CacheInterface $cache;
|
||||
|
||||
public function __construct()
|
||||
@@ -31,15 +31,11 @@ class OSPOS extends BaseConfig
|
||||
{
|
||||
$cache = $this->cache->get('settings');
|
||||
|
||||
if($cache)
|
||||
{
|
||||
if ($cache) {
|
||||
$this->settings = decode_array($cache);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$appconfig = model(Appconfig::class);
|
||||
foreach($appconfig->get_all()->getResult() as $app_config)
|
||||
{
|
||||
foreach ($appconfig->get_all()->getResult() as $app_config) {
|
||||
$this->settings[$app_config->key] = $app_config->value;
|
||||
}
|
||||
$this->cache->save('settings', encode_array($this->settings));
|
||||
|
||||
@@ -43,19 +43,19 @@ class Pager extends BaseConfig
|
||||
* Source code from http://stackoverflow.com/questions/20088779/bootstrap-3-pagination-with-codeigniter
|
||||
*/
|
||||
public $config = [
|
||||
'full_tag_open' => "<ul class='pagination pagination-sm'>",
|
||||
'full_tag_close' => '</ul>',
|
||||
'num_tag_open' => '<li>',
|
||||
'num_tag_close' => '</li>',
|
||||
'cur_tag_open' => "<li class='disabled'><li class='active'><a href='#'>",
|
||||
'cur_tag_close' => "<span class='sr-only'></span></a></li>",
|
||||
'next_tag_open' => "<li>",
|
||||
'next_tagl_close' => "</li>",
|
||||
'prev_tag_open' => "<li>",
|
||||
'prev_tagl_close' => "</li>",
|
||||
'first_tag_open' => "<li>",
|
||||
'first_tagl_close' => "</li>",
|
||||
'last_tag_open' => "<li>",
|
||||
'last_tagl_close' => "</li>"
|
||||
'full_tag_open' => '<ul class="pagination pagination-sm">',
|
||||
'full_tag_close' => '</ul>',
|
||||
'num_tag_open' => '<li>',
|
||||
'num_tag_close' => '</li>',
|
||||
'cur_tag_open' => '<li class="disabled"><li class="active"><a href="#">',
|
||||
'cur_tag_close' => '<span class="sr-only"></span></a></li>',
|
||||
'next_tag_open' => '<li>',
|
||||
'next_tagl_close' => '</li>',
|
||||
'prev_tag_open' => '<li>',
|
||||
'prev_tagl_close' => '</li>',
|
||||
'first_tag_open' => '<li>',
|
||||
'first_tagl_close' => '</li>',
|
||||
'last_tag_open' => '<li>',
|
||||
'last_tagl_close' => '</li>'
|
||||
];
|
||||
}
|
||||
|
||||
@@ -61,13 +61,11 @@ class Services extends BaseService
|
||||
|
||||
public static function htmlPurifier($getShared = true)
|
||||
{
|
||||
if ($getShared)
|
||||
{
|
||||
if ($getShared) {
|
||||
return static::getSharedInstance('htmlPurifier');
|
||||
}
|
||||
|
||||
if (!isset(static::$htmlPurifier))
|
||||
{
|
||||
if (!isset(static::$htmlPurifier)) {
|
||||
$config = HTMLPurifier_Config::createDefault();
|
||||
static::$htmlPurifier = new HTMLPurifier($config);
|
||||
}
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
|
||||
namespace Config;
|
||||
|
||||
use App\Config\Validation\OSPOSRules;
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
use CodeIgniter\Validation\StrictRules\CreditCardRules;
|
||||
use CodeIgniter\Validation\StrictRules\FileRules;
|
||||
use CodeIgniter\Validation\StrictRules\FormatRules;
|
||||
use CodeIgniter\Validation\StrictRules\Rules;
|
||||
use App\Config\Validation\OSPOSRules;
|
||||
|
||||
class Validation extends BaseConfig
|
||||
{
|
||||
@@ -26,7 +26,7 @@ class Validation extends BaseConfig
|
||||
FormatRules::class,
|
||||
FileRules::class,
|
||||
CreditCardRules::class,
|
||||
OSPOSRules::class
|
||||
OSPOSRules::class,
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace App\Config\Validation;
|
||||
|
||||
use App\Models\Employee;
|
||||
@@ -25,35 +26,31 @@ class OSPOSRules
|
||||
* @return bool True if validation passes or false if there are errors.
|
||||
* @noinspection PhpUnused
|
||||
*/
|
||||
public function login_check(string $username, string $fields , array $data, ?string &$error = null): bool
|
||||
public function login_check(string $username, string $fields, array $data, ?string &$error = null): bool
|
||||
{
|
||||
$employee = model(Employee::class);
|
||||
$this->request = Services::request();
|
||||
$this->config = config(OSPOS::class)->settings;
|
||||
|
||||
//Installation Check
|
||||
if(!$this->installation_check())
|
||||
{
|
||||
// Installation Check
|
||||
if (!$this->installation_check()) {
|
||||
$error = lang('Login.invalid_installation');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$password = $data['password'];
|
||||
if(!$employee->login($username, $password))
|
||||
{
|
||||
if (!$employee->login($username, $password)) {
|
||||
$error = lang('Login.invalid_username_and_password');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$gcaptcha_enabled = array_key_exists('gcaptcha_enable', $this->config) && $this->config['gcaptcha_enable'];
|
||||
if($gcaptcha_enabled)
|
||||
{
|
||||
if ($gcaptcha_enabled) {
|
||||
$g_recaptcha_response = $this->request->getPost('g-recaptcha-response');
|
||||
|
||||
if(!$this->gcaptcha_check($g_recaptcha_response))
|
||||
{
|
||||
if (!$this->gcaptcha_check($g_recaptcha_response)) {
|
||||
$error = lang('Login.invalid_gcaptcha');
|
||||
|
||||
return false;
|
||||
@@ -71,8 +68,7 @@ class OSPOSRules
|
||||
*/
|
||||
private function gcaptcha_check($response): bool
|
||||
{
|
||||
if(!empty($response))
|
||||
{
|
||||
if (!empty($response)) {
|
||||
$check = [
|
||||
'secret' => $this->config['gcaptcha_secret_key'],
|
||||
'response' => $response,
|
||||
@@ -92,8 +88,7 @@ class OSPOSRules
|
||||
|
||||
$status = json_decode($result, true);
|
||||
|
||||
if(!empty($status['success']))
|
||||
{
|
||||
if (!empty($status['success'])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -112,19 +107,17 @@ class OSPOSRules
|
||||
$required_extensions = ['bcmath', 'intl', 'gd', 'openssl', 'mbstring', 'curl', 'xml', 'json'];
|
||||
$pattern = '/';
|
||||
|
||||
foreach($required_extensions as $extension)
|
||||
{
|
||||
foreach ($required_extensions as $extension) {
|
||||
$pattern .= '(?=.*\b' . preg_quote($extension, '/') . '\b)';
|
||||
}
|
||||
|
||||
$pattern .= '/i';
|
||||
$is_installed = preg_match($pattern, $installed_extensions);
|
||||
|
||||
if(!$is_installed)
|
||||
{
|
||||
if (!$is_installed) {
|
||||
log_message('error', '[ERROR] Check your php.ini.');
|
||||
log_message('error',"PHP installed extensions: $installed_extensions");
|
||||
log_message('error','PHP required extensions: ' . implode(', ', $required_extensions));
|
||||
log_message('error', "PHP installed extensions: $installed_extensions");
|
||||
log_message('error', 'PHP required extensions: ' . implode(', ', $required_extensions));
|
||||
}
|
||||
|
||||
return $is_installed;
|
||||
|
||||
@@ -48,8 +48,7 @@ class Attributes extends Secure_Controller
|
||||
$total_rows = $this->attribute->get_found_rows($search);
|
||||
|
||||
$data_rows = [];
|
||||
foreach($attributes->getResult() as $attribute_row)
|
||||
{
|
||||
foreach ($attributes->getResult() as $attribute_row) {
|
||||
$attribute_row->definition_flags = $this->get_attributes($attribute_row->definition_flags);
|
||||
$data_rows[] = get_attribute_definition_data_row($attribute_row);
|
||||
}
|
||||
@@ -102,61 +101,50 @@ class Attributes extends Secure_Controller
|
||||
|
||||
$flags = (empty($this->request->getPost('definition_flags'))) ? [] : $this->request->getPost('definition_flags', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
|
||||
|
||||
foreach($flags as $flag)
|
||||
{
|
||||
foreach ($flags as $flag) {
|
||||
$definition_flags |= $flag;
|
||||
}
|
||||
|
||||
//Save definition data
|
||||
// Save definition data
|
||||
$definition_data = [
|
||||
'definition_name' => $this->request->getPost('definition_name'),
|
||||
'definition_unit' => $this->request->getPost('definition_unit') != '' ? $this->request->getPost('definition_unit') : null,
|
||||
'definition_name' => $this->request->getPost('definition_name'),
|
||||
'definition_unit' => $this->request->getPost('definition_unit') != '' ? $this->request->getPost('definition_unit') : null,
|
||||
'definition_flags' => $definition_flags,
|
||||
'definition_fk' => $this->request->getPost('definition_group') != '' ? $this->request->getPost('definition_group') : null
|
||||
'definition_fk' => $this->request->getPost('definition_group') != '' ? $this->request->getPost('definition_group') : null
|
||||
];
|
||||
|
||||
if ($this->request->getPost('definition_type') != null)
|
||||
{
|
||||
if ($this->request->getPost('definition_type') != null) {
|
||||
$definition_data['definition_type'] = DEFINITION_TYPES[$this->request->getPost('definition_type')];
|
||||
}
|
||||
|
||||
$definition_name = $definition_data['definition_name'];
|
||||
|
||||
if($this->attribute->save_definition($definition_data, $definition_id))
|
||||
{
|
||||
//New definition
|
||||
if($definition_id == NO_DEFINITION_ID)
|
||||
{
|
||||
if ($this->attribute->save_definition($definition_data, $definition_id)) {
|
||||
// New definition
|
||||
if ($definition_id == NO_DEFINITION_ID) {
|
||||
$definition_values = json_decode(html_entity_decode($this->request->getPost('definition_values')));
|
||||
|
||||
foreach($definition_values as $definition_value)
|
||||
{
|
||||
foreach ($definition_values as $definition_value) {
|
||||
$this->attribute->saveAttributeValue($definition_value, $definition_data['definition_id']);
|
||||
}
|
||||
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'message' => lang('Attributes.definition_successful_adding') . ' ' . $definition_name,
|
||||
'id' => $definition_data['definition_id']
|
||||
'id' => $definition_data['definition_id']
|
||||
]);
|
||||
}
|
||||
//Existing definition
|
||||
else
|
||||
{
|
||||
} else { // Existing definition
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'message' => lang('Attributes.definition_successful_updating') . ' ' . $definition_name,
|
||||
'id' => $definition_id
|
||||
'id' => $definition_id
|
||||
]);
|
||||
}
|
||||
}
|
||||
//Failure
|
||||
else
|
||||
{
|
||||
} else { // Failure
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'message' => lang('Attributes.definition_error_adding_updating', [$definition_name]),
|
||||
'id' => NEW_ENTRY
|
||||
'id' => NEW_ENTRY
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -194,10 +182,8 @@ class Attributes extends Secure_Controller
|
||||
private function get_attributes(int $definition_flags = 0): array
|
||||
{
|
||||
$definition_flag_names = [];
|
||||
foreach (Attribute::get_definition_flags() as $id => $term)
|
||||
{
|
||||
if ($id & $definition_flags)
|
||||
{
|
||||
foreach (Attribute::get_definition_flags() as $id => $term) {
|
||||
if ($id & $definition_flags) {
|
||||
$definition_flag_names[$id] = lang('Attributes.' . strtolower($term) . '_visibility');
|
||||
}
|
||||
}
|
||||
@@ -211,8 +197,7 @@ class Attributes extends Secure_Controller
|
||||
public function getView(int $definition_id = NO_DEFINITION_ID): void
|
||||
{
|
||||
$info = $this->attribute->getAttributeInfo($definition_id);
|
||||
foreach(get_object_vars($info) as $property => $value)
|
||||
{
|
||||
foreach (get_object_vars($info) as $property => $value) {
|
||||
$info->$property = $value;
|
||||
}
|
||||
|
||||
@@ -250,13 +235,10 @@ class Attributes extends Secure_Controller
|
||||
{
|
||||
$attributes_to_delete = $this->request->getPost('ids', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
|
||||
|
||||
if($this->attribute->delete_definition_list($attributes_to_delete))
|
||||
{
|
||||
if ($this->attribute->delete_definition_list($attributes_to_delete)) {
|
||||
$message = lang('Attributes.definition_successful_deleted') . ' ' . count($attributes_to_delete) . ' ' . lang('Attributes.definition_one_or_multiple');
|
||||
echo json_encode(['success' => true, 'message' => $message]);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
echo json_encode(['success' => false, 'message' => lang('Attributes.definition_cannot_be_deleted')]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,19 +49,18 @@ class Cashups extends Secure_Controller
|
||||
$sort = $this->sanitizeSortColumn(cashup_headers(), $this->request->getGet('sort', FILTER_SANITIZE_FULL_SPECIAL_CHARS), 'cashup_id');
|
||||
$order = $this->request->getGet('order', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
|
||||
$filters = [
|
||||
'start_date' => $this->request->getGet('start_date', FILTER_SANITIZE_FULL_SPECIAL_CHARS), //TODO: Is this the best way to filter dates
|
||||
'end_date' => $this->request->getGet('end_date', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
|
||||
'is_deleted' => false
|
||||
'start_date' => $this->request->getGet('start_date', FILTER_SANITIZE_FULL_SPECIAL_CHARS), // TODO: Is this the best way to filter dates
|
||||
'end_date' => $this->request->getGet('end_date', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
|
||||
'is_deleted' => false
|
||||
];
|
||||
|
||||
// check if any filter is set in the multiselect dropdown
|
||||
// Check if any filter is set in the multiselect dropdown
|
||||
$request_filters = array_fill_keys($this->request->getGet('filters', FILTER_SANITIZE_FULL_SPECIAL_CHARS) ?? [], true);
|
||||
$filters = array_merge($filters, $request_filters);
|
||||
$cash_ups = $this->cashup->search($search, $filters, $limit, $offset, $sort, $order);
|
||||
$total_rows = $this->cashup->get_found_rows($search, $filters);
|
||||
$data_rows = [];
|
||||
foreach($cash_ups->getResult() as $cash_up)
|
||||
{
|
||||
foreach ($cash_ups->getResult() as $cash_up) {
|
||||
$data_rows[] = get_cash_up_data_row($cash_up);
|
||||
}
|
||||
|
||||
@@ -77,10 +76,8 @@ class Cashups extends Secure_Controller
|
||||
$data = [];
|
||||
|
||||
$data['employees'] = [];
|
||||
foreach($this->employee->get_all()->getResult() as $employee)
|
||||
{
|
||||
foreach(get_object_vars($employee) as $property => $value)
|
||||
{
|
||||
foreach ($this->employee->get_all()->getResult() as $employee) {
|
||||
foreach (get_object_vars($employee) as $property => $value) {
|
||||
$employee->$property = $value;
|
||||
}
|
||||
|
||||
@@ -89,110 +86,92 @@ class Cashups extends Secure_Controller
|
||||
|
||||
$cash_ups_info = $this->cashup->get_info($cashup_id);
|
||||
|
||||
foreach(get_object_vars($cash_ups_info) as $property => $value)
|
||||
{
|
||||
foreach (get_object_vars($cash_ups_info) as $property => $value) {
|
||||
$cash_ups_info->$property = $value;
|
||||
}
|
||||
|
||||
// open cashup
|
||||
if($cash_ups_info->cashup_id == NEW_ENTRY)
|
||||
{
|
||||
// Open cashup
|
||||
if ($cash_ups_info->cashup_id == NEW_ENTRY) {
|
||||
$cash_ups_info->open_date = date('Y-m-d H:i:s');
|
||||
$cash_ups_info->close_date = $cash_ups_info->open_date;
|
||||
$cash_ups_info->open_employee_id = $this->employee->get_logged_in_employee_info()->person_id;
|
||||
$cash_ups_info->close_employee_id = $this->employee->get_logged_in_employee_info()->person_id;
|
||||
}
|
||||
// if all the amounts are null or 0 that means it's a close cashup
|
||||
elseif(floatval($cash_ups_info->closed_amount_cash) == 0
|
||||
// If all the amounts are null or 0 that means it's a close cashup
|
||||
elseif (
|
||||
floatval($cash_ups_info->closed_amount_cash) == 0
|
||||
&& floatval($cash_ups_info->closed_amount_due) == 0
|
||||
&& floatval($cash_ups_info->closed_amount_card) == 0
|
||||
&& floatval($cash_ups_info->closed_amount_check) == 0)
|
||||
{
|
||||
// set the close date and time to the actual as this is a close session
|
||||
&& floatval($cash_ups_info->closed_amount_check) == 0
|
||||
) {
|
||||
// Set the close date and time to the actual as this is a close session
|
||||
$cash_ups_info->close_date = date('Y-m-d H:i:s');
|
||||
|
||||
// the closed amount starts with the open amount -/+ any trasferred amount
|
||||
// The closed amount starts with the open amount -/+ any trasferred amount
|
||||
$cash_ups_info->closed_amount_cash = $cash_ups_info->open_amount_cash + $cash_ups_info->transfer_amount_cash;
|
||||
|
||||
// if it's date mode only and not date & time truncate the open and end date to date only
|
||||
if(empty($this->config['date_or_time_format']))
|
||||
{
|
||||
if($cash_ups_info->open_date != null)
|
||||
{
|
||||
// If it's date mode only and not date & time truncate the open and end date to date only
|
||||
if (empty($this->config['date_or_time_format'])) {
|
||||
if ($cash_ups_info->open_date != null) {
|
||||
$start_date = substr($cash_ups_info->open_date, 0, 10);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$start_date = null;
|
||||
}
|
||||
if($cash_ups_info->close_date != null)
|
||||
{
|
||||
if ($cash_ups_info->close_date != null) {
|
||||
$end_date = substr($cash_ups_info->close_date, 0, 10);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$end_date = null;
|
||||
}
|
||||
// search for all the payments given the time range
|
||||
// Search for all the payments given the time range
|
||||
$inputs = [
|
||||
'start_date' => $start_date,
|
||||
'end_date' => $end_date,
|
||||
'sale_type' => 'complete',
|
||||
'start_date' => $start_date,
|
||||
'end_date' => $end_date,
|
||||
'sale_type' => 'complete',
|
||||
'location_id' => 'all'
|
||||
];
|
||||
}
|
||||
else
|
||||
{
|
||||
// search for all the payments given the time range
|
||||
} else {
|
||||
// Search for all the payments given the time range
|
||||
$inputs = [
|
||||
'start_date' => $cash_ups_info->open_date,
|
||||
'end_date' => $cash_ups_info->close_date,
|
||||
'sale_type' => 'complete',
|
||||
'start_date' => $cash_ups_info->open_date,
|
||||
'end_date' => $cash_ups_info->close_date,
|
||||
'sale_type' => 'complete',
|
||||
'location_id' => 'all'
|
||||
];
|
||||
}
|
||||
|
||||
// get all the transactions payment summaries
|
||||
// Get all the transactions payment summaries
|
||||
$reports_data = $this->summary_payments->getData($inputs);
|
||||
|
||||
foreach($reports_data as $row)
|
||||
{
|
||||
if($row['trans_group'] == lang('Reports.trans_payments'))
|
||||
{
|
||||
if($row['trans_type'] == lang('Sales.cash'))
|
||||
{
|
||||
foreach ($reports_data as $row) {
|
||||
if ($row['trans_group'] == lang('Reports.trans_payments')) {
|
||||
if ($row['trans_type'] == lang('Sales.cash')) {
|
||||
$cash_ups_info->closed_amount_cash += $row['trans_amount'];
|
||||
}
|
||||
elseif($row['trans_type'] == lang('Sales.due'))
|
||||
{
|
||||
} elseif ($row['trans_type'] == lang('Sales.due')) {
|
||||
$cash_ups_info->closed_amount_due += $row['trans_amount'];
|
||||
}
|
||||
elseif($row['trans_type'] == lang('Sales.debit') ||
|
||||
$row['trans_type'] == lang('Sales.credit'))
|
||||
{
|
||||
} elseif (
|
||||
$row['trans_type'] == lang('Sales.debit') ||
|
||||
$row['trans_type'] == lang('Sales.credit')
|
||||
) {
|
||||
$cash_ups_info->closed_amount_card += $row['trans_amount'];
|
||||
}
|
||||
elseif($row['trans_type'] == lang('Sales.check'))
|
||||
{
|
||||
} elseif ($row['trans_type'] == lang('Sales.check')) {
|
||||
$cash_ups_info->closed_amount_check += $row['trans_amount'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// lookup expenses paid in cash
|
||||
// Lookup expenses paid in cash
|
||||
$filters = [
|
||||
'only_cash' => true,
|
||||
'only_due' => false,
|
||||
'only_check' => false,
|
||||
'only_credit' => false,
|
||||
'only_debit' => false,
|
||||
'is_deleted' => false
|
||||
'only_cash' => true,
|
||||
'only_due' => false,
|
||||
'only_check' => false,
|
||||
'only_credit' => false,
|
||||
'only_debit' => false,
|
||||
'is_deleted' => false
|
||||
];
|
||||
|
||||
$payments = $this->expense->get_payments_summary('', array_merge($inputs, $filters));
|
||||
|
||||
foreach($payments as $row)
|
||||
{
|
||||
foreach ($payments as $row) {
|
||||
$cash_ups_info->closed_amount_cash -= $row['amount'];
|
||||
}
|
||||
|
||||
@@ -229,36 +208,30 @@ class Cashups extends Secure_Controller
|
||||
$close_date_formatter = date_create_from_format($this->config['dateformat'] . ' ' . $this->config['timeformat'], $close_date);
|
||||
|
||||
$cash_up_data = [
|
||||
'open_date' => $open_date_formatter->format('Y-m-d H:i:s'),
|
||||
'close_date' => $close_date_formatter->format('Y-m-d H:i:s'),
|
||||
'open_amount_cash' => parse_decimals($this->request->getPost('open_amount_cash')),
|
||||
'open_date' => $open_date_formatter->format('Y-m-d H:i:s'),
|
||||
'close_date' => $close_date_formatter->format('Y-m-d H:i:s'),
|
||||
'open_amount_cash' => parse_decimals($this->request->getPost('open_amount_cash')),
|
||||
'transfer_amount_cash' => parse_decimals($this->request->getPost('transfer_amount_cash')),
|
||||
'closed_amount_cash' => parse_decimals($this->request->getPost('closed_amount_cash')),
|
||||
'closed_amount_due' => parse_decimals($this->request->getPost('closed_amount_due')),
|
||||
'closed_amount_card' => parse_decimals($this->request->getPost('closed_amount_card')),
|
||||
'closed_amount_check' => parse_decimals($this->request->getPost('closed_amount_check')),
|
||||
'closed_amount_total' => parse_decimals($this->request->getPost('closed_amount_total')),
|
||||
'note' => $this->request->getPost('note') != null,
|
||||
'description' => $this->request->getPost('description', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
|
||||
'open_employee_id' => $this->request->getPost('open_employee_id', FILTER_SANITIZE_NUMBER_INT),
|
||||
'close_employee_id' => $this->request->getPost('close_employee_id', FILTER_SANITIZE_NUMBER_INT),
|
||||
'deleted' => $this->request->getPost('deleted') != null
|
||||
'closed_amount_cash' => parse_decimals($this->request->getPost('closed_amount_cash')),
|
||||
'closed_amount_due' => parse_decimals($this->request->getPost('closed_amount_due')),
|
||||
'closed_amount_card' => parse_decimals($this->request->getPost('closed_amount_card')),
|
||||
'closed_amount_check' => parse_decimals($this->request->getPost('closed_amount_check')),
|
||||
'closed_amount_total' => parse_decimals($this->request->getPost('closed_amount_total')),
|
||||
'note' => $this->request->getPost('note') != null,
|
||||
'description' => $this->request->getPost('description', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
|
||||
'open_employee_id' => $this->request->getPost('open_employee_id', FILTER_SANITIZE_NUMBER_INT),
|
||||
'close_employee_id' => $this->request->getPost('close_employee_id', FILTER_SANITIZE_NUMBER_INT),
|
||||
'deleted' => $this->request->getPost('deleted') != null
|
||||
];
|
||||
|
||||
if($this->cashup->save_value($cash_up_data, $cashup_id))
|
||||
{
|
||||
//New cashup_id
|
||||
if($cashup_id == NEW_ENTRY)
|
||||
{
|
||||
if ($this->cashup->save_value($cash_up_data, $cashup_id)) {
|
||||
// New cashup_id
|
||||
if ($cashup_id == NEW_ENTRY) {
|
||||
echo json_encode(['success' => true, 'message' => lang('Cashups.successful_adding'), 'id' => $cash_up_data['cashup_id']]);
|
||||
}
|
||||
else // Existing Cashup
|
||||
{
|
||||
} else { // Existing Cashup
|
||||
echo json_encode(['success' => true, 'message' => lang('Cashups.successful_updating'), 'id' => $cashup_id]);
|
||||
}
|
||||
}
|
||||
else//failure
|
||||
{
|
||||
} else { // Failure
|
||||
echo json_encode(['success' => false, 'message' => lang('Cashups.error_adding_updating'), 'id' => NEW_ENTRY]);
|
||||
}
|
||||
}
|
||||
@@ -270,12 +243,9 @@ class Cashups extends Secure_Controller
|
||||
{
|
||||
$cash_ups_to_delete = $this->request->getPost('ids', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
|
||||
|
||||
if($this->cashup->delete_list($cash_ups_to_delete))
|
||||
{
|
||||
if ($this->cashup->delete_list($cash_ups_to_delete)) {
|
||||
echo json_encode(['success' => true, 'message' => lang('Cashups.successful_deleted') . ' ' . count($cash_ups_to_delete) . ' ' . lang('Cashups.one_or_multiple'), 'ids' => $cash_ups_to_delete]);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
echo json_encode(['success' => false, 'message' => lang('Cashups.cannot_be_deleted'), 'ids' => $cash_ups_to_delete]);
|
||||
}
|
||||
}
|
||||
@@ -295,15 +265,15 @@ class Cashups extends Secure_Controller
|
||||
$closed_amount_card = parse_decimals($this->request->getPost('closed_amount_card'));
|
||||
$closed_amount_check = parse_decimals($this->request->getPost('closed_amount_check'));
|
||||
|
||||
$total = $this->_calculate_total($open_amount_cash, $transfer_amount_cash, $closed_amount_due, $closed_amount_cash, $closed_amount_card, $closed_amount_check); //TODO: hungarian notation
|
||||
$total = $this->_calculate_total($open_amount_cash, $transfer_amount_cash, $closed_amount_due, $closed_amount_cash, $closed_amount_card, $closed_amount_check); // TODO: hungarian notation
|
||||
|
||||
echo json_encode(['total' => to_currency_no_money($total)]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate total
|
||||
*/
|
||||
private function _calculate_total(float $open_amount_cash, float $transfer_amount_cash, float $closed_amount_due, float $closed_amount_cash, float $closed_amount_card, $closed_amount_check): float //TODO: need to get rid of hungarian notation here. Also, the signature is pretty long. Perhaps they need to go into an object or array?
|
||||
* Calculate total
|
||||
*/
|
||||
private function _calculate_total(float $open_amount_cash, float $transfer_amount_cash, float $closed_amount_due, float $closed_amount_cash, float $closed_amount_card, $closed_amount_check): float // TODO: need to get rid of hungarian notation here. Also, the signature is pretty long. Perhaps they need to go into an object or array?
|
||||
{
|
||||
return ($closed_amount_cash - $open_amount_cash - $transfer_amount_cash + $closed_amount_due + $closed_amount_card + $closed_amount_check);
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ class Config extends Secure_Controller
|
||||
/**
|
||||
* This function loads all the licenses starting with the first one being OSPOS one
|
||||
*/
|
||||
private function _licenses(): array //TODO: remove hungarian notation. Super long function. Perhaps we need to refactor out functions?
|
||||
private function _licenses(): array // TODO: remove hungarian notation. Super long function. Perhaps we need to refactor out functions?
|
||||
{
|
||||
$i = 0;
|
||||
$composer = false;
|
||||
@@ -88,10 +88,10 @@ class Config extends Secure_Controller
|
||||
$license[$i]['text'] = 'LICENSE file must be in OSPOS license directory. You are not allowed to use OSPOS application until the distribution copy of LICENSE file is present.';
|
||||
}
|
||||
|
||||
$dir = new DirectoryIterator('license'); // read all the files in the dir license
|
||||
$dir = new DirectoryIterator('license'); // Read all the files in the dir license
|
||||
|
||||
foreach ($dir as $fileinfo) { //TODO: $fileinfo doesn't match our variable naming convention
|
||||
// license files must be in couples: .version (name & version) & .license (license text)
|
||||
foreach ($dir as $fileinfo) { // TODO: $fileinfo doesn't match our variable naming convention
|
||||
// License files must be in couples: .version (name & version) & .license (license text)
|
||||
if ($fileinfo->isFile()) {
|
||||
if ($fileinfo->getExtension() == 'version') {
|
||||
++$i;
|
||||
@@ -108,19 +108,19 @@ class Config extends Secure_Controller
|
||||
$license[$i]['text'] = $license_text_file . ' file is missing';
|
||||
}
|
||||
} elseif ($fileinfo->getBasename() == 'composer.LICENSES') {
|
||||
// set a flag to indicate that the composer.LICENSES file is available and needs to be attached at the end
|
||||
// Set a flag to indicate that the composer.LICENSES file is available and needs to be attached at the end
|
||||
$composer = true;
|
||||
} elseif ($fileinfo->getBasename() == 'npm-prod.LICENSES') {
|
||||
// set a flag to indicate that the npm-prod.LICENSES file is available and needs to be attached at the end
|
||||
// Set a flag to indicate that the npm-prod.LICENSES file is available and needs to be attached at the end
|
||||
$npmProd = true;
|
||||
} elseif ($fileinfo->getBasename() == 'npm-dev.LICENSES') {
|
||||
// set a flag to indicate that the npm-dev.LICENSES file is available and needs to be attached at the end
|
||||
// Set a flag to indicate that the npm-dev.LICENSES file is available and needs to be attached at the end
|
||||
$npmDev = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// attach the licenses from the LICENSES file generated by composer
|
||||
// Attach the licenses from the LICENSES file generated by Composer
|
||||
if ($composer) {
|
||||
++$i;
|
||||
$license[$i]['title'] = 'Composer Libraries';
|
||||
@@ -147,22 +147,22 @@ class Config extends Secure_Controller
|
||||
}
|
||||
}
|
||||
|
||||
// attach the licenses from the LICENSES file generated by license-report
|
||||
// Attach the licenses from the LICENSES file generated by license-report
|
||||
if ($npmProd) {
|
||||
++$i;
|
||||
$license[$i]['title'] = 'NPM Production Libraries';
|
||||
$license[$i]['text'] = '';
|
||||
|
||||
|
||||
$file = file_get_contents('license/npm-prod.LICENSES');
|
||||
$array = json_decode($file, true);
|
||||
|
||||
|
||||
foreach ($array as $dependency) {
|
||||
$license[$i]['text'] .= "library: {$dependency['name']}\n";
|
||||
$license[$i]['text'] .= "authors: {$dependency['author']}\n";
|
||||
$license[$i]['text'] .= "website: {$dependency['homepage']}\n";
|
||||
$license[$i]['text'] .= "version: {$dependency['installedVersion']}\n";
|
||||
$license[$i]['text'] .= "license: {$dependency['licenseType']}\n";
|
||||
|
||||
|
||||
$license[$i]['text'] .= "\n";
|
||||
}
|
||||
$license[$i]['text'] = rtrim($license[$i]['text'], "\n");
|
||||
@@ -172,17 +172,17 @@ class Config extends Secure_Controller
|
||||
++$i;
|
||||
$license[$i]['title'] = 'NPM Development Libraries';
|
||||
$license[$i]['text'] = '';
|
||||
|
||||
|
||||
$file = file_get_contents('license/npm-dev.LICENSES');
|
||||
$array = json_decode($file, true);
|
||||
|
||||
|
||||
foreach ($array as $dependency) {
|
||||
$license[$i]['text'] .= "library: {$dependency['name']}\n";
|
||||
$license[$i]['text'] .= "authors: {$dependency['author']}\n";
|
||||
$license[$i]['text'] .= "website: {$dependency['homepage']}\n";
|
||||
$license[$i]['text'] .= "version: {$dependency['installedVersion']}\n";
|
||||
$license[$i]['text'] .= "license: {$dependency['licenseType']}\n";
|
||||
|
||||
|
||||
$license[$i]['text'] .= "\n";
|
||||
}
|
||||
$license[$i]['text'] = rtrim($license[$i]['text'], "\n");
|
||||
@@ -195,14 +195,14 @@ class Config extends Secure_Controller
|
||||
* This function loads all the available themes in the dist/bootswatch directory
|
||||
* @return array
|
||||
*/
|
||||
private function _themes(): array //TODO: Hungarian notation
|
||||
private function _themes(): array // TODO: Hungarian notation
|
||||
{
|
||||
$themes = [];
|
||||
|
||||
// read all themes in the dist folder
|
||||
// Read all themes in the dist folder
|
||||
$dir = new DirectoryIterator('resources/bootswatch');
|
||||
|
||||
foreach ($dir as $dirinfo) { //TODO: $dirinfo doesn't follow naming convention
|
||||
foreach ($dir as $dirinfo) { // TODO: $dirinfo doesn't follow naming convention
|
||||
if ($dirinfo->isDir() && !$dirinfo->isDot() && $dirinfo->getFileName() != 'fonts') {
|
||||
$file = $dirinfo->getFileName();
|
||||
$themes[$file] = ucfirst($file);
|
||||
@@ -235,21 +235,21 @@ class Config extends Secure_Controller
|
||||
$data['currency_code'] = $this->config['currency_code'] ?? '';
|
||||
$data['dbVersion'] = mysqli_get_server_info($this->db->getConnection());
|
||||
|
||||
//Load all the license statements, they are already XSS cleaned in the private function
|
||||
// Load all the license statements, they are already XSS cleaned in the private function
|
||||
$data['licenses'] = $this->_licenses();
|
||||
|
||||
//Load all the themes, already XSS cleaned in the private function
|
||||
// Load all the themes, already XSS cleaned in the private function
|
||||
$data['themes'] = $this->_themes();
|
||||
|
||||
//General related fields
|
||||
$image_allowed_types = ['jpg','jpeg','gif','svg','webp','bmp','png','tif','tiff'];
|
||||
// General related fields
|
||||
$image_allowed_types = ['jpg', 'jpeg', 'gif', 'svg', 'webp', 'bmp', 'png', 'tif', 'tiff'];
|
||||
$data['image_allowed_types'] = array_combine($image_allowed_types, $image_allowed_types);
|
||||
$data['selected_image_allowed_types'] = explode(',', $this->config['image_allowed_types']);
|
||||
|
||||
//Integrations Related fields
|
||||
// Integrations Related fields
|
||||
$data['mailchimp'] = [];
|
||||
|
||||
if (check_encryption()) { //TODO: Hungarian notation
|
||||
if (check_encryption()) { // TODO: Hungarian notation
|
||||
if (!isset($this->encrypter)) {
|
||||
helper('security');
|
||||
$this->encrypter = Services::encrypter();
|
||||
@@ -263,7 +263,7 @@ class Config extends Secure_Controller
|
||||
? $this->encrypter->decrypt($this->config['mailchimp_list_id'])
|
||||
: '';
|
||||
|
||||
//Remove any backup of .env created by check_encryption()
|
||||
// Remove any backup of .env created by check_encryption()
|
||||
remove_backup();
|
||||
} else {
|
||||
$data['mailchimp']['api_key'] = '';
|
||||
@@ -288,12 +288,12 @@ class Config extends Secure_Controller
|
||||
$upload_success = empty($upload_data['error']);
|
||||
|
||||
$batch_save_data = [
|
||||
'company' => $this->request->getPost('company'),
|
||||
'address' => $this->request->getPost('address'),
|
||||
'phone' => $this->request->getPost('phone'),
|
||||
'email' => strtolower($this->request->getPost('email', FILTER_SANITIZE_EMAIL)),
|
||||
'fax' => $this->request->getPost('fax'),
|
||||
'website' => $this->request->getPost('website', FILTER_SANITIZE_URL),
|
||||
'company' => $this->request->getPost('company'),
|
||||
'address' => $this->request->getPost('address'),
|
||||
'phone' => $this->request->getPost('phone'),
|
||||
'email' => strtolower($this->request->getPost('email', FILTER_SANITIZE_EMAIL)),
|
||||
'fax' => $this->request->getPost('fax'),
|
||||
'website' => $this->request->getPost('website', FILTER_SANITIZE_URL),
|
||||
'return_policy' => $this->request->getPost('return_policy')
|
||||
];
|
||||
|
||||
@@ -345,8 +345,8 @@ class Config extends Secure_Controller
|
||||
|
||||
$file_info = [
|
||||
'orig_name' => $filename,
|
||||
'raw_name' => $info['filename'],
|
||||
'file_ext' => $file->guessExtension()
|
||||
'raw_name' => $info['filename'],
|
||||
'file_ext' => $file->guessExtension()
|
||||
];
|
||||
|
||||
$file->move(FCPATH . 'uploads/', $file_info['raw_name'] . '.' . $file_info['file_ext'], true);
|
||||
@@ -363,32 +363,32 @@ class Config extends Secure_Controller
|
||||
public function postSaveGeneral(): void
|
||||
{
|
||||
$batch_save_data = [
|
||||
'theme' => $this->request->getPost('theme'),
|
||||
'login_form' => $this->request->getPost('login_form'),
|
||||
'default_sales_discount_type' => $this->request->getPost('default_sales_discount_type') != null,
|
||||
'default_sales_discount' => parse_decimals($this->request->getPost('default_sales_discount')),
|
||||
'default_receivings_discount_type' => $this->request->getPost('default_receivings_discount_type') != null,
|
||||
'default_receivings_discount' => parse_decimals($this->request->getPost('default_receivings_discount')),
|
||||
'enforce_privacy' => $this->request->getPost('enforce_privacy') != null,
|
||||
'theme' => $this->request->getPost('theme'),
|
||||
'login_form' => $this->request->getPost('login_form'),
|
||||
'default_sales_discount_type' => $this->request->getPost('default_sales_discount_type') != null,
|
||||
'default_sales_discount' => parse_decimals($this->request->getPost('default_sales_discount')),
|
||||
'default_receivings_discount_type' => $this->request->getPost('default_receivings_discount_type') != null,
|
||||
'default_receivings_discount' => parse_decimals($this->request->getPost('default_receivings_discount')),
|
||||
'enforce_privacy' => $this->request->getPost('enforce_privacy') != null,
|
||||
'receiving_calculate_average_price' => $this->request->getPost('receiving_calculate_average_price') != null,
|
||||
'lines_per_page' => $this->request->getPost('lines_per_page', FILTER_SANITIZE_NUMBER_INT),
|
||||
'notify_horizontal_position' => $this->request->getPost('notify_horizontal_position'),
|
||||
'notify_vertical_position' => $this->request->getPost('notify_vertical_position'),
|
||||
'image_max_width' => $this->request->getPost('image_max_width', FILTER_SANITIZE_NUMBER_INT),
|
||||
'image_max_height' => $this->request->getPost('image_max_height', FILTER_SANITIZE_NUMBER_INT),
|
||||
'image_max_size' => $this->request->getPost('image_max_size', FILTER_SANITIZE_NUMBER_INT),
|
||||
'image_allowed_types' => implode(',', $this->request->getPost('image_allowed_types')),
|
||||
'gcaptcha_enable' => $this->request->getPost('gcaptcha_enable') != null,
|
||||
'gcaptcha_secret_key' => $this->request->getPost('gcaptcha_secret_key'),
|
||||
'gcaptcha_site_key' => $this->request->getPost('gcaptcha_site_key'),
|
||||
'suggestions_first_column' => $this->request->getPost('suggestions_first_column'),
|
||||
'suggestions_second_column' => $this->request->getPost('suggestions_second_column'),
|
||||
'suggestions_third_column' => $this->request->getPost('suggestions_third_column'),
|
||||
'giftcard_number' => $this->request->getPost('giftcard_number'),
|
||||
'derive_sale_quantity' => $this->request->getPost('derive_sale_quantity') != null,
|
||||
'multi_pack_enabled' => $this->request->getPost('multi_pack_enabled') != null,
|
||||
'include_hsn' => $this->request->getPost('include_hsn') != null,
|
||||
'category_dropdown' => $this->request->getPost('category_dropdown') != null
|
||||
'lines_per_page' => $this->request->getPost('lines_per_page', FILTER_SANITIZE_NUMBER_INT),
|
||||
'notify_horizontal_position' => $this->request->getPost('notify_horizontal_position'),
|
||||
'notify_vertical_position' => $this->request->getPost('notify_vertical_position'),
|
||||
'image_max_width' => $this->request->getPost('image_max_width', FILTER_SANITIZE_NUMBER_INT),
|
||||
'image_max_height' => $this->request->getPost('image_max_height', FILTER_SANITIZE_NUMBER_INT),
|
||||
'image_max_size' => $this->request->getPost('image_max_size', FILTER_SANITIZE_NUMBER_INT),
|
||||
'image_allowed_types' => implode(',', $this->request->getPost('image_allowed_types')),
|
||||
'gcaptcha_enable' => $this->request->getPost('gcaptcha_enable') != null,
|
||||
'gcaptcha_secret_key' => $this->request->getPost('gcaptcha_secret_key'),
|
||||
'gcaptcha_site_key' => $this->request->getPost('gcaptcha_site_key'),
|
||||
'suggestions_first_column' => $this->request->getPost('suggestions_first_column'),
|
||||
'suggestions_second_column' => $this->request->getPost('suggestions_second_column'),
|
||||
'suggestions_third_column' => $this->request->getPost('suggestions_third_column'),
|
||||
'giftcard_number' => $this->request->getPost('giftcard_number'),
|
||||
'derive_sale_quantity' => $this->request->getPost('derive_sale_quantity') != null,
|
||||
'multi_pack_enabled' => $this->request->getPost('multi_pack_enabled') != null,
|
||||
'include_hsn' => $this->request->getPost('include_hsn') != null,
|
||||
'category_dropdown' => $this->request->getPost('category_dropdown') != null
|
||||
];
|
||||
|
||||
$this->module->set_show_office_group($this->request->getPost('show_office_group') != null);
|
||||
@@ -439,11 +439,11 @@ class Config extends Secure_Controller
|
||||
$number_local_example = $fmt->format(1234567890.12300);
|
||||
|
||||
echo json_encode([
|
||||
'success' => $number_local_example != false,
|
||||
'save_number_locale' => $save_number_locale,
|
||||
'success' => $number_local_example != false,
|
||||
'save_number_locale' => $save_number_locale,
|
||||
'number_locale_example' => $number_local_example,
|
||||
'currency_symbol' => $currency_symbol,
|
||||
'currency_code' => $currency_code,
|
||||
'currency_symbol' => $currency_symbol,
|
||||
'currency_code' => $currency_code,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -458,24 +458,24 @@ class Config extends Secure_Controller
|
||||
{
|
||||
$exploded = explode(":", $this->request->getPost('language'));
|
||||
$batch_save_data = [
|
||||
'currency_symbol' => $this->request->getPost('currency_symbol'),
|
||||
'currency_code' => $this->request->getPost('currency_code'),
|
||||
'language_code' => $exploded[0],
|
||||
'language' => $exploded[1],
|
||||
'timezone' => $this->request->getPost('timezone'),
|
||||
'dateformat' => $this->request->getPost('dateformat'),
|
||||
'timeformat' => $this->request->getPost('timeformat'),
|
||||
'thousands_separator' => $this->request->getPost('thousands_separator') != null,
|
||||
'number_locale' => $this->request->getPost('number_locale'),
|
||||
'currency_decimals' => $this->request->getPost('currency_decimals', FILTER_SANITIZE_NUMBER_INT),
|
||||
'tax_decimals' => $this->request->getPost('tax_decimals', FILTER_SANITIZE_NUMBER_INT),
|
||||
'quantity_decimals' => $this->request->getPost('quantity_decimals', FILTER_SANITIZE_NUMBER_INT),
|
||||
'country_codes' => htmlspecialchars($this->request->getPost('country_codes')),
|
||||
'currency_symbol' => $this->request->getPost('currency_symbol'),
|
||||
'currency_code' => $this->request->getPost('currency_code'),
|
||||
'language_code' => $exploded[0],
|
||||
'language' => $exploded[1],
|
||||
'timezone' => $this->request->getPost('timezone'),
|
||||
'dateformat' => $this->request->getPost('dateformat'),
|
||||
'timeformat' => $this->request->getPost('timeformat'),
|
||||
'thousands_separator' => $this->request->getPost('thousands_separator') != null,
|
||||
'number_locale' => $this->request->getPost('number_locale'),
|
||||
'currency_decimals' => $this->request->getPost('currency_decimals', FILTER_SANITIZE_NUMBER_INT),
|
||||
'tax_decimals' => $this->request->getPost('tax_decimals', FILTER_SANITIZE_NUMBER_INT),
|
||||
'quantity_decimals' => $this->request->getPost('quantity_decimals', FILTER_SANITIZE_NUMBER_INT),
|
||||
'country_codes' => htmlspecialchars($this->request->getPost('country_codes')),
|
||||
'payment_options_order' => $this->request->getPost('payment_options_order'),
|
||||
'date_or_time_format' => $this->request->getPost('date_or_time_format') != null,
|
||||
'cash_decimals' => $this->request->getPost('cash_decimals', FILTER_SANITIZE_NUMBER_INT),
|
||||
'cash_rounding_code' => $this->request->getPost('cash_rounding_code'),
|
||||
'financial_year' => $this->request->getPost('financial_year', FILTER_SANITIZE_NUMBER_INT)
|
||||
'date_or_time_format' => $this->request->getPost('date_or_time_format') != null,
|
||||
'cash_decimals' => $this->request->getPost('cash_decimals', FILTER_SANITIZE_NUMBER_INT),
|
||||
'cash_rounding_code' => $this->request->getPost('cash_rounding_code'),
|
||||
'financial_year' => $this->request->getPost('financial_year', FILTER_SANITIZE_NUMBER_INT)
|
||||
];
|
||||
|
||||
$success = $this->appconfig->batch_save($batch_save_data);
|
||||
@@ -499,14 +499,14 @@ class Config extends Secure_Controller
|
||||
}
|
||||
|
||||
$batch_save_data = [
|
||||
'protocol' => $this->request->getPost('protocol'),
|
||||
'mailpath' => $this->request->getPost('mailpath'),
|
||||
'smtp_host' => $this->request->getPost('smtp_host'),
|
||||
'smtp_user' => $this->request->getPost('smtp_user'),
|
||||
'smtp_pass' => $password,
|
||||
'smtp_port' => $this->request->getPost('smtp_port', FILTER_SANITIZE_NUMBER_INT),
|
||||
'protocol' => $this->request->getPost('protocol'),
|
||||
'mailpath' => $this->request->getPost('mailpath'),
|
||||
'smtp_host' => $this->request->getPost('smtp_host'),
|
||||
'smtp_user' => $this->request->getPost('smtp_user'),
|
||||
'smtp_pass' => $password,
|
||||
'smtp_port' => $this->request->getPost('smtp_port', FILTER_SANITIZE_NUMBER_INT),
|
||||
'smtp_timeout' => $this->request->getPost('smtp_timeout', FILTER_SANITIZE_NUMBER_INT),
|
||||
'smtp_crypto' => $this->request->getPost('smtp_crypto')
|
||||
'smtp_crypto' => $this->request->getPost('smtp_crypto')
|
||||
];
|
||||
|
||||
$success = $this->appconfig->batch_save($batch_save_data);
|
||||
@@ -544,7 +544,7 @@ class Config extends Secure_Controller
|
||||
/**
|
||||
* This function fetches all the available lists from Mailchimp for the given API key
|
||||
*/
|
||||
private function _mailchimp(string $api_key = ''): array //TODO: Hungarian notation
|
||||
private function _mailchimp(string $api_key = ''): array // TODO: Hungarian notation
|
||||
{
|
||||
$mailchimp_lib = new Mailchimp_lib(['api_key' => $api_key]);
|
||||
|
||||
@@ -574,8 +574,8 @@ class Config extends Secure_Controller
|
||||
$success = count($lists) > 0;
|
||||
|
||||
echo json_encode([
|
||||
'success' => $success,
|
||||
'message' => lang('Config.mailchimp_key_' . ($success ? '' : 'un') . 'successfully'),
|
||||
'success' => $success,
|
||||
'message' => lang('Config.mailchimp_key_' . ($success ? '' : 'un') . 'successfully'),
|
||||
'mailchimp_lists' => $lists
|
||||
]);
|
||||
}
|
||||
@@ -640,7 +640,7 @@ class Config extends Secure_Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function ajax_tax_categories(): void //TODO: Is this function called anywhere in the code?
|
||||
public function ajax_tax_categories(): void // TODO: Is this function called anywhere in the code?
|
||||
{
|
||||
$tax_categories = $this->tax->get_all_tax_categories()->getResultArray();
|
||||
|
||||
@@ -663,7 +663,7 @@ class Config extends Secure_Controller
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
private function _clear_session_state(): void //TODO: Hungarian notation
|
||||
private function _clear_session_state(): void // TODO: Hungarian notation
|
||||
{
|
||||
$this->sale_lib->clear_sale_location();
|
||||
$this->sale_lib->clear_table();
|
||||
@@ -687,7 +687,7 @@ class Config extends Secure_Controller
|
||||
$not_to_delete = [];
|
||||
foreach ($this->request->getPost() as $key => $value) {
|
||||
if (str_contains($key, 'stock_location')) {
|
||||
// save or update
|
||||
// Save or update
|
||||
foreach ($value as $location_id => $location_name) {
|
||||
$location_data = ['location_name' => $location_name];
|
||||
if ($this->stock_location->save_value($location_data, $location_id)) {
|
||||
@@ -699,7 +699,7 @@ class Config extends Secure_Controller
|
||||
}
|
||||
}
|
||||
|
||||
// all locations not available in post will be deleted now
|
||||
// All locations not available in post will be deleted now
|
||||
$deleted_locations = $this->stock_location->get_all()->getResultArray();
|
||||
|
||||
foreach ($deleted_locations as $location => $location_data) {
|
||||
@@ -732,20 +732,20 @@ class Config extends Secure_Controller
|
||||
|
||||
if ($dinner_table_enable) {
|
||||
$not_to_delete = [];
|
||||
foreach ($this->request->getPost() as $key => $value) { //TODO: Not sure if this is the best way to filter the array
|
||||
foreach ($this->request->getPost() as $key => $value) { // TODO: Not sure if this is the best way to filter the array
|
||||
if (strstr($key, 'dinner_table') && $key != 'dinner_table_enable') {
|
||||
$dinner_table_id = preg_replace("/.*?_(\d+)$/", "$1", $key);
|
||||
$not_to_delete[] = $dinner_table_id;
|
||||
|
||||
// save or update
|
||||
// Save or update
|
||||
$table_data = ['name' => $value];
|
||||
if ($this->dinner_table->save_value($table_data, $dinner_table_id)) {
|
||||
$this->_clear_session_state(); //TODO: Remove hungarian notation.
|
||||
$this->_clear_session_state(); // TODO: Remove hungarian notation.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// all tables not available in post will be deleted now
|
||||
// All tables not available in post will be deleted now
|
||||
$deleted_tables = $this->dinner_table->get_all()->getResultArray();
|
||||
|
||||
foreach ($deleted_tables as $dinner_tables => $table) {
|
||||
@@ -759,7 +759,7 @@ class Config extends Secure_Controller
|
||||
|
||||
$success = $this->db->transStatus();
|
||||
|
||||
echo json_encode(['success' => $success,'message' => lang('Config.saved_' . ($success ? '' : 'un') . 'successfully')]);
|
||||
echo json_encode(['success' => $success, 'message' => lang('Config.saved_' . ($success ? '' : 'un') . 'successfully')]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -775,16 +775,16 @@ class Config extends Secure_Controller
|
||||
$default_tax_2_rate = $this->request->getPost('default_tax_2_rate');
|
||||
|
||||
$batch_save_data = [
|
||||
'default_tax_1_rate' => parse_tax(filter_var($default_tax_1_rate, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION)),
|
||||
'default_tax_1_name' => $this->request->getPost('default_tax_1_name'),
|
||||
'default_tax_2_rate' => parse_tax(filter_var($default_tax_2_rate, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION)),
|
||||
'default_tax_2_name' => $this->request->getPost('default_tax_2_name'),
|
||||
'tax_included' => $this->request->getPost('tax_included') != null,
|
||||
'default_tax_1_rate' => parse_tax(filter_var($default_tax_1_rate, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION)),
|
||||
'default_tax_1_name' => $this->request->getPost('default_tax_1_name'),
|
||||
'default_tax_2_rate' => parse_tax(filter_var($default_tax_2_rate, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION)),
|
||||
'default_tax_2_name' => $this->request->getPost('default_tax_2_name'),
|
||||
'tax_included' => $this->request->getPost('tax_included') != null,
|
||||
'use_destination_based_tax' => $this->request->getPost('use_destination_based_tax') != null,
|
||||
'default_tax_code' => $this->request->getPost('default_tax_code'),
|
||||
'default_tax_category' => $this->request->getPost('default_tax_category'),
|
||||
'default_tax_jurisdiction' => $this->request->getPost('default_tax_jurisdiction'),
|
||||
'tax_id' => $this->request->getPost('tax_id', FILTER_SANITIZE_NUMBER_INT)
|
||||
'default_tax_code' => $this->request->getPost('default_tax_code'),
|
||||
'default_tax_category' => $this->request->getPost('default_tax_category'),
|
||||
'default_tax_jurisdiction' => $this->request->getPost('default_tax_jurisdiction'),
|
||||
'tax_id' => $this->request->getPost('tax_id', FILTER_SANITIZE_NUMBER_INT)
|
||||
];
|
||||
|
||||
$success = $this->appconfig->batch_save($batch_save_data);
|
||||
@@ -825,13 +825,13 @@ class Config extends Secure_Controller
|
||||
|
||||
if (!empty($array_save)) {
|
||||
foreach ($array_save as $key => $value) {
|
||||
// save or update
|
||||
// Save or update
|
||||
$package_data = ['package_name' => $value['package_name'], 'points_percent' => $value['points_percent']];
|
||||
$this->customer_rewards->save_value($package_data, $key); //TODO: reflection exception
|
||||
$this->customer_rewards->save_value($package_data, $key); // TODO: reflection exception
|
||||
}
|
||||
}
|
||||
|
||||
// all packages not available in post will be deleted now
|
||||
// All packages not available in post will be deleted now
|
||||
$deleted_packages = $this->customer_rewards->get_all()->getResultArray();
|
||||
|
||||
foreach ($deleted_packages as $customer_rewards => $reward_category) {
|
||||
@@ -858,21 +858,21 @@ class Config extends Secure_Controller
|
||||
public function postSaveBarcode(): void
|
||||
{
|
||||
$batch_save_data = [
|
||||
'barcode_type' => $this->request->getPost('barcode_type'),
|
||||
'barcode_width' => $this->request->getPost('barcode_width', FILTER_SANITIZE_NUMBER_INT),
|
||||
'barcode_height' => $this->request->getPost('barcode_height', FILTER_SANITIZE_NUMBER_INT),
|
||||
'barcode_font' => $this->request->getPost('barcode_font'),
|
||||
'barcode_font_size' => $this->request->getPost('barcode_font_size', FILTER_SANITIZE_NUMBER_INT),
|
||||
'barcode_first_row' => $this->request->getPost('barcode_first_row'),
|
||||
'barcode_second_row' => $this->request->getPost('barcode_second_row'),
|
||||
'barcode_third_row' => $this->request->getPost('barcode_third_row'),
|
||||
'barcode_num_in_row' => $this->request->getPost('barcode_num_in_row', FILTER_SANITIZE_NUMBER_INT),
|
||||
'barcode_page_width' => $this->request->getPost('barcode_page_width', FILTER_SANITIZE_NUMBER_INT),
|
||||
'barcode_page_cellspacing' => $this->request->getPost('barcode_page_cellspacing', FILTER_SANITIZE_NUMBER_INT),
|
||||
'barcode_type' => $this->request->getPost('barcode_type'),
|
||||
'barcode_width' => $this->request->getPost('barcode_width', FILTER_SANITIZE_NUMBER_INT),
|
||||
'barcode_height' => $this->request->getPost('barcode_height', FILTER_SANITIZE_NUMBER_INT),
|
||||
'barcode_font' => $this->request->getPost('barcode_font'),
|
||||
'barcode_font_size' => $this->request->getPost('barcode_font_size', FILTER_SANITIZE_NUMBER_INT),
|
||||
'barcode_first_row' => $this->request->getPost('barcode_first_row'),
|
||||
'barcode_second_row' => $this->request->getPost('barcode_second_row'),
|
||||
'barcode_third_row' => $this->request->getPost('barcode_third_row'),
|
||||
'barcode_num_in_row' => $this->request->getPost('barcode_num_in_row', FILTER_SANITIZE_NUMBER_INT),
|
||||
'barcode_page_width' => $this->request->getPost('barcode_page_width', FILTER_SANITIZE_NUMBER_INT),
|
||||
'barcode_page_cellspacing' => $this->request->getPost('barcode_page_cellspacing', FILTER_SANITIZE_NUMBER_INT),
|
||||
'barcode_generate_if_empty' => $this->request->getPost('barcode_generate_if_empty') != null,
|
||||
'allow_duplicate_barcodes' => $this->request->getPost('allow_duplicate_barcodes') != null,
|
||||
'barcode_content' => $this->request->getPost('barcode_content'),
|
||||
'barcode_formats' => json_encode($this->request->getPost('barcode_formats'))
|
||||
'allow_duplicate_barcodes' => $this->request->getPost('allow_duplicate_barcodes') != null,
|
||||
'barcode_content' => $this->request->getPost('barcode_content'),
|
||||
'barcode_formats' => json_encode($this->request->getPost('barcode_formats'))
|
||||
];
|
||||
|
||||
$success = $this->appconfig->batch_save($batch_save_data);
|
||||
@@ -890,24 +890,24 @@ class Config extends Secure_Controller
|
||||
public function postSaveReceipt(): void
|
||||
{
|
||||
$batch_save_data = [
|
||||
'receipt_template' => $this->request->getPost('receipt_template'),
|
||||
'receipt_font_size' => $this->request->getPost('receipt_font_size', FILTER_SANITIZE_NUMBER_INT),
|
||||
'print_delay_autoreturn' => $this->request->getPost('print_delay_autoreturn', FILTER_SANITIZE_NUMBER_INT),
|
||||
'receipt_template' => $this->request->getPost('receipt_template'),
|
||||
'receipt_font_size' => $this->request->getPost('receipt_font_size', FILTER_SANITIZE_NUMBER_INT),
|
||||
'print_delay_autoreturn' => $this->request->getPost('print_delay_autoreturn', FILTER_SANITIZE_NUMBER_INT),
|
||||
'email_receipt_check_behaviour' => $this->request->getPost('email_receipt_check_behaviour'),
|
||||
'print_receipt_check_behaviour' => $this->request->getPost('print_receipt_check_behaviour'),
|
||||
'receipt_show_company_name' => $this->request->getPost('receipt_show_company_name') != null,
|
||||
'receipt_show_taxes' => $this->request->getPost('receipt_show_taxes') != null,
|
||||
'receipt_show_tax_ind' => $this->request->getPost('receipt_show_tax_ind') != null,
|
||||
'receipt_show_total_discount' => $this->request->getPost('receipt_show_total_discount') != null,
|
||||
'receipt_show_description' => $this->request->getPost('receipt_show_description') != null,
|
||||
'receipt_show_serialnumber' => $this->request->getPost('receipt_show_serialnumber') != null,
|
||||
'print_silently' => $this->request->getPost('print_silently') != null,
|
||||
'print_header' => $this->request->getPost('print_header') != null,
|
||||
'print_footer' => $this->request->getPost('print_footer') != null,
|
||||
'print_top_margin' => $this->request->getPost('print_top_margin', FILTER_SANITIZE_NUMBER_INT),
|
||||
'print_left_margin' => $this->request->getPost('print_left_margin', FILTER_SANITIZE_NUMBER_INT),
|
||||
'print_bottom_margin' => $this->request->getPost('print_bottom_margin', FILTER_SANITIZE_NUMBER_INT),
|
||||
'print_right_margin' => $this->request->getPost('print_right_margin', FILTER_SANITIZE_NUMBER_INT)
|
||||
'receipt_show_company_name' => $this->request->getPost('receipt_show_company_name') != null,
|
||||
'receipt_show_taxes' => $this->request->getPost('receipt_show_taxes') != null,
|
||||
'receipt_show_tax_ind' => $this->request->getPost('receipt_show_tax_ind') != null,
|
||||
'receipt_show_total_discount' => $this->request->getPost('receipt_show_total_discount') != null,
|
||||
'receipt_show_description' => $this->request->getPost('receipt_show_description') != null,
|
||||
'receipt_show_serialnumber' => $this->request->getPost('receipt_show_serialnumber') != null,
|
||||
'print_silently' => $this->request->getPost('print_silently') != null,
|
||||
'print_header' => $this->request->getPost('print_header') != null,
|
||||
'print_footer' => $this->request->getPost('print_footer') != null,
|
||||
'print_top_margin' => $this->request->getPost('print_top_margin', FILTER_SANITIZE_NUMBER_INT),
|
||||
'print_left_margin' => $this->request->getPost('print_left_margin', FILTER_SANITIZE_NUMBER_INT),
|
||||
'print_bottom_margin' => $this->request->getPost('print_bottom_margin', FILTER_SANITIZE_NUMBER_INT),
|
||||
'print_right_margin' => $this->request->getPost('print_right_margin', FILTER_SANITIZE_NUMBER_INT)
|
||||
];
|
||||
|
||||
$success = $this->appconfig->batch_save($batch_save_data);
|
||||
@@ -925,20 +925,20 @@ class Config extends Secure_Controller
|
||||
public function postSaveInvoice(): void
|
||||
{
|
||||
$batch_save_data = [
|
||||
'invoice_enable' => $this->request->getPost('invoice_enable') != null,
|
||||
'sales_invoice_format' => $this->request->getPost('sales_invoice_format'),
|
||||
'sales_quote_format' => $this->request->getPost('sales_quote_format'),
|
||||
'recv_invoice_format' => $this->request->getPost('recv_invoice_format'),
|
||||
'invoice_default_comments' => $this->request->getPost('invoice_default_comments'),
|
||||
'invoice_email_message' => $this->request->getPost('invoice_email_message'),
|
||||
'line_sequence' => $this->request->getPost('line_sequence'),
|
||||
'last_used_invoice_number' => $this->request->getPost('last_used_invoice_number', FILTER_SANITIZE_NUMBER_INT),
|
||||
'last_used_quote_number' => $this->request->getPost('last_used_quote_number', FILTER_SANITIZE_NUMBER_INT),
|
||||
'quote_default_comments' => $this->request->getPost('quote_default_comments'),
|
||||
'work_order_enable' => $this->request->getPost('work_order_enable') != null,
|
||||
'work_order_format' => $this->request->getPost('work_order_format'),
|
||||
'invoice_enable' => $this->request->getPost('invoice_enable') != null,
|
||||
'sales_invoice_format' => $this->request->getPost('sales_invoice_format'),
|
||||
'sales_quote_format' => $this->request->getPost('sales_quote_format'),
|
||||
'recv_invoice_format' => $this->request->getPost('recv_invoice_format'),
|
||||
'invoice_default_comments' => $this->request->getPost('invoice_default_comments'),
|
||||
'invoice_email_message' => $this->request->getPost('invoice_email_message'),
|
||||
'line_sequence' => $this->request->getPost('line_sequence'),
|
||||
'last_used_invoice_number' => $this->request->getPost('last_used_invoice_number', FILTER_SANITIZE_NUMBER_INT),
|
||||
'last_used_quote_number' => $this->request->getPost('last_used_quote_number', FILTER_SANITIZE_NUMBER_INT),
|
||||
'quote_default_comments' => $this->request->getPost('quote_default_comments'),
|
||||
'work_order_enable' => $this->request->getPost('work_order_enable') != null,
|
||||
'work_order_format' => $this->request->getPost('work_order_format'),
|
||||
'last_used_work_order_number' => $this->request->getPost('last_used_work_order_number', FILTER_SANITIZE_NUMBER_INT),
|
||||
'invoice_type' => $this->request->getPost('invoice_type')
|
||||
'invoice_type' => $this->request->getPost('invoice_type')
|
||||
];
|
||||
|
||||
$success = $this->appconfig->batch_save($batch_save_data);
|
||||
|
||||
@@ -32,12 +32,9 @@ class Customers extends Persons
|
||||
|
||||
$encrypter = Services::encrypter();
|
||||
|
||||
if(!empty($this->config['mailchimp_list_id']))
|
||||
{
|
||||
if (!empty($this->config['mailchimp_list_id'])) {
|
||||
$this->_list_id = $encrypter->decrypt($this->config['mailchimp_list_id']);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$this->_list_id = '';
|
||||
}
|
||||
}
|
||||
@@ -59,12 +56,11 @@ class Customers extends Persons
|
||||
{
|
||||
$person = $this->customer->get_info($row_id);
|
||||
|
||||
// retrieve the total amount the customer spent so far together with min, max and average values
|
||||
$stats = $this->customer->get_stats($person->person_id); //TODO: This and the next 11 lines are duplicated in search(). Extract a method.
|
||||
// Retrieve the total amount the customer spent so far together with min, max and average values
|
||||
$stats = $this->customer->get_stats($person->person_id); // TODO: This and the next 11 lines are duplicated in search(). Extract a method.
|
||||
|
||||
if(empty($stats))
|
||||
{
|
||||
//create object with empty properties.
|
||||
if (empty($stats)) {
|
||||
// Create object with empty properties.
|
||||
$stats = new stdClass();
|
||||
$stats->total = 0;
|
||||
$stats->min = 0;
|
||||
@@ -98,13 +94,11 @@ class Customers extends Persons
|
||||
|
||||
$data_rows = [];
|
||||
|
||||
foreach($customers->getResult() as $person)
|
||||
{
|
||||
// retrieve the total amount the customer spent so far together with min, max and average values
|
||||
$stats = $this->customer->get_stats($person->person_id); //TODO: duplicated... see above
|
||||
if(empty($stats))
|
||||
{
|
||||
//create object with empty properties.
|
||||
foreach ($customers->getResult() as $person) {
|
||||
// Retrieve the total amount the customer spent so far together with min, max and average values
|
||||
$stats = $this->customer->get_stats($person->person_id); // TODO: duplicated... see above
|
||||
if (empty($stats)) {
|
||||
// Create object with empty properties.
|
||||
$stats = new stdClass();
|
||||
$stats->total = 0;
|
||||
$stats->min = 0;
|
||||
@@ -117,7 +111,7 @@ class Customers extends Persons
|
||||
$data_rows[] = get_customer_data_row($person, $stats);
|
||||
}
|
||||
|
||||
echo json_encode (['total' => $total_rows, 'rows' => $data_rows]);
|
||||
echo json_encode(['total' => $total_rows, 'rows' => $data_rows]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -148,17 +142,15 @@ class Customers extends Persons
|
||||
public function getView(int $customer_id = NEW_ENTRY): void
|
||||
{
|
||||
// Set default values
|
||||
if($customer_id == null) $customer_id = NEW_ENTRY;
|
||||
if ($customer_id == null) $customer_id = NEW_ENTRY;
|
||||
|
||||
$info = $this->customer->get_info($customer_id);
|
||||
foreach(get_object_vars($info) as $property => $value)
|
||||
{
|
||||
foreach (get_object_vars($info) as $property => $value) {
|
||||
$info->$property = $value;
|
||||
}
|
||||
$data['person_info'] = $info;
|
||||
|
||||
if(empty($info->person_id) || empty($info->date) || empty($info->employee_id))
|
||||
{
|
||||
if (empty($info->person_id) || empty($info->date) || empty($info->employee_id)) {
|
||||
$data['person_info']->date = date('Y-m-d H:i:s');
|
||||
$data['person_info']->employee_id = $this->employee->get_logged_in_employee_info()->person_id;
|
||||
}
|
||||
@@ -168,18 +160,14 @@ class Customers extends Persons
|
||||
|
||||
$tax_code_info = $this->tax_code->get_info($info->sales_tax_code_id);
|
||||
|
||||
if($tax_code_info->tax_code != null)
|
||||
{
|
||||
if ($tax_code_info->tax_code != null) {
|
||||
$data['sales_tax_code_label'] = $tax_code_info->tax_code . ' ' . $tax_code_info->tax_code_name;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$data['sales_tax_code_label'] = '';
|
||||
}
|
||||
|
||||
$packages = ['' => lang('Items.none')];
|
||||
foreach($this->customer_rewards->get_all()->getResultArray() as $row)
|
||||
{
|
||||
foreach ($this->customer_rewards->get_all()->getResultArray() as $row) {
|
||||
$packages[$row['package_id']] = $row['package_name'];
|
||||
}
|
||||
$data['packages'] = $packages;
|
||||
@@ -187,54 +175,40 @@ class Customers extends Persons
|
||||
|
||||
$data['use_destination_based_tax'] = $this->config['use_destination_based_tax'];
|
||||
|
||||
// retrieve the total amount the customer spent so far together with min, max and average values
|
||||
// Retrieve the total amount the customer spent so far together with min, max and average values
|
||||
$stats = $this->customer->get_stats($customer_id);
|
||||
if(!empty($stats))
|
||||
{
|
||||
foreach(get_object_vars($stats) as $property => $value)
|
||||
{
|
||||
if (!empty($stats)) {
|
||||
foreach (get_object_vars($stats) as $property => $value) {
|
||||
$info->$property = $value;
|
||||
}
|
||||
$data['stats'] = $stats;
|
||||
}
|
||||
|
||||
// retrieve the info from Mailchimp only if there is an email address assigned
|
||||
if(!empty($info->email))
|
||||
{
|
||||
// collect mailchimp customer info
|
||||
if(($mailchimp_info = $this->mailchimp_lib->getMemberInfo($this->_list_id, $info->email)) !== false)
|
||||
{
|
||||
// Retrieve the info from Mailchimp only if there is an email address assigned
|
||||
if (!empty($info->email)) {
|
||||
// Collect Mailchimp customer info
|
||||
if (($mailchimp_info = $this->mailchimp_lib->getMemberInfo($this->_list_id, $info->email)) !== false) {
|
||||
$data['mailchimp_info'] = $mailchimp_info;
|
||||
|
||||
// collect customer mailchimp emails activities (stats)
|
||||
if(($activities = $this->mailchimp_lib->getMemberActivity($this->_list_id, $info->email)) !== false)
|
||||
{
|
||||
if(array_key_exists('activity', $activities))
|
||||
{
|
||||
// Collect customer Mailchimp emails activities (stats)
|
||||
if (($activities = $this->mailchimp_lib->getMemberActivity($this->_list_id, $info->email)) !== false) {
|
||||
if (array_key_exists('activity', $activities)) {
|
||||
$open = 0;
|
||||
$unopen = 0;
|
||||
$click = 0;
|
||||
$total = 0;
|
||||
$lastopen = '';
|
||||
|
||||
foreach($activities['activity'] as $activity)
|
||||
{
|
||||
if($activity['action'] == 'sent')
|
||||
{
|
||||
foreach ($activities['activity'] as $activity) {
|
||||
if ($activity['action'] == 'sent') {
|
||||
++$unopen;
|
||||
}
|
||||
elseif($activity['action'] == 'open')
|
||||
{
|
||||
if(empty($lastopen))
|
||||
{
|
||||
} elseif ($activity['action'] == 'open') {
|
||||
if (empty($lastopen)) {
|
||||
$lastopen = substr($activity['timestamp'], 0, 10);
|
||||
}
|
||||
++$open;
|
||||
}
|
||||
elseif($activity['action'] == 'click')
|
||||
{
|
||||
if(empty($lastopen))
|
||||
{
|
||||
} elseif ($activity['action'] == 'click') {
|
||||
if (empty($lastopen)) {
|
||||
$lastopen = substr($activity['timestamp'], 0, 10);
|
||||
}
|
||||
++$click;
|
||||
@@ -265,44 +239,43 @@ class Customers extends Persons
|
||||
$last_name = $this->request->getPost('last_name');
|
||||
$email = strtolower($this->request->getPost('email', FILTER_SANITIZE_EMAIL));
|
||||
|
||||
// format first and last name properly
|
||||
// Format first and last name properly
|
||||
$first_name = $this->nameize($first_name);
|
||||
$last_name = $this->nameize($last_name);
|
||||
|
||||
$person_data = [
|
||||
'first_name' => $first_name,
|
||||
'last_name' => $last_name,
|
||||
'gender' => $this->request->getPost('gender', FILTER_SANITIZE_NUMBER_INT),
|
||||
'email' => $email,
|
||||
'first_name' => $first_name,
|
||||
'last_name' => $last_name,
|
||||
'gender' => $this->request->getPost('gender', FILTER_SANITIZE_NUMBER_INT),
|
||||
'email' => $email,
|
||||
'phone_number' => $this->request->getPost('phone_number'),
|
||||
'address_1' => $this->request->getPost('address_1'),
|
||||
'address_2' => $this->request->getPost('address_2'),
|
||||
'city' => $this->request->getPost('city'),
|
||||
'state' => $this->request->getPost('state'),
|
||||
'zip' => $this->request->getPost('zip'),
|
||||
'country' => $this->request->getPost('country'),
|
||||
'comments' => $this->request->getPost('comments')
|
||||
'address_1' => $this->request->getPost('address_1'),
|
||||
'address_2' => $this->request->getPost('address_2'),
|
||||
'city' => $this->request->getPost('city'),
|
||||
'state' => $this->request->getPost('state'),
|
||||
'zip' => $this->request->getPost('zip'),
|
||||
'country' => $this->request->getPost('country'),
|
||||
'comments' => $this->request->getPost('comments')
|
||||
];
|
||||
|
||||
$date_formatter = date_create_from_format($this->config['dateformat'] . ' ' . $this->config['timeformat'], $this->request->getPost('date'));
|
||||
|
||||
$customer_data = [
|
||||
'consent' => $this->request->getPost('consent') != null,
|
||||
'account_number' => $this->request->getPost('account_number') == '' ? null : $this->request->getPost('account_number'),
|
||||
'tax_id' => $this->request->getPost('tax_id'),
|
||||
'company_name' => $this->request->getPost('company_name') == '' ? null : $this->request->getPost('company_name'),
|
||||
'discount' => $this->request->getPost('discount') == '' ? 0.00 : parse_decimals($this->request->getPost('discount')),
|
||||
'discount_type' => $this->request->getPost('discount_type') == null ? PERCENT : $this->request->getPost('discount_type', FILTER_SANITIZE_NUMBER_INT),
|
||||
'package_id' => $this->request->getPost('package_id') == '' ? null : $this->request->getPost('package_id'),
|
||||
'taxable' => $this->request->getPost('taxable') != null,
|
||||
'date' => $date_formatter->format('Y-m-d H:i:s'),
|
||||
'employee_id' => $this->request->getPost('employee_id', FILTER_SANITIZE_NUMBER_INT),
|
||||
'consent' => $this->request->getPost('consent') != null,
|
||||
'account_number' => $this->request->getPost('account_number') == '' ? null : $this->request->getPost('account_number'),
|
||||
'tax_id' => $this->request->getPost('tax_id'),
|
||||
'company_name' => $this->request->getPost('company_name') == '' ? null : $this->request->getPost('company_name'),
|
||||
'discount' => $this->request->getPost('discount') == '' ? 0.00 : parse_decimals($this->request->getPost('discount')),
|
||||
'discount_type' => $this->request->getPost('discount_type') == null ? PERCENT : $this->request->getPost('discount_type', FILTER_SANITIZE_NUMBER_INT),
|
||||
'package_id' => $this->request->getPost('package_id') == '' ? null : $this->request->getPost('package_id'),
|
||||
'taxable' => $this->request->getPost('taxable') != null,
|
||||
'date' => $date_formatter->format('Y-m-d H:i:s'),
|
||||
'employee_id' => $this->request->getPost('employee_id', FILTER_SANITIZE_NUMBER_INT),
|
||||
'sales_tax_code_id' => $this->request->getPost('sales_tax_code_id') == '' ? null : $this->request->getPost('sales_tax_code_id', FILTER_SANITIZE_NUMBER_INT)
|
||||
];
|
||||
|
||||
if($this->customer->save_customer($person_data, $customer_data, $customer_id))
|
||||
{
|
||||
// save customer to Mailchimp selected list //TODO: addOrUpdateMember should be refactored... potentially pass an array or object instead of 6 parameters.
|
||||
if ($this->customer->save_customer($person_data, $customer_data, $customer_id)) {
|
||||
// Save customer to Mailchimp selected list // TODO: addOrUpdateMember should be refactored. Potentially pass an array or object instead of 6 parameters.
|
||||
$mailchimp_status = $this->request->getPost('mailchimp_status');
|
||||
$this->mailchimp_lib->addOrUpdateMember(
|
||||
$this->_list_id,
|
||||
@@ -314,29 +287,24 @@ class Customers extends Persons
|
||||
);
|
||||
|
||||
// New customer
|
||||
if($customer_id == NEW_ENTRY)
|
||||
{
|
||||
echo json_encode ([
|
||||
if ($customer_id == NEW_ENTRY) {
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'message' => lang('Customers.successful_adding') . ' ' . $first_name . ' ' . $last_name,
|
||||
'id' => $customer_data['person_id']
|
||||
'id' => $customer_data['person_id']
|
||||
]);
|
||||
}
|
||||
else // Existing customer
|
||||
{
|
||||
echo json_encode ([
|
||||
} else { // Existing customer
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'message' => lang('Customers.successful_updating') . ' ' . $first_name . ' ' . $last_name,
|
||||
'id' => $customer_id
|
||||
'id' => $customer_id
|
||||
]);
|
||||
}
|
||||
}
|
||||
else // Failure
|
||||
{
|
||||
echo json_encode ([
|
||||
} else { // Failure
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'message' => lang('Customers.error_adding_updating') . ' ' . $first_name . ' ' . $last_name,
|
||||
'id' => NEW_ENTRY
|
||||
'id' => NEW_ENTRY
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -380,10 +348,8 @@ class Customers extends Persons
|
||||
|
||||
$count = 0;
|
||||
|
||||
foreach($customers_info->getResult() as $info)
|
||||
{
|
||||
if($this->customer->delete($info->person_id))
|
||||
{
|
||||
foreach ($customers_info->getResult() as $info) {
|
||||
if ($this->customer->delete($info->person_id)) {
|
||||
// remove customer from Mailchimp selected list
|
||||
$this->mailchimp_lib->removeMember($this->_list_id, $info->email);
|
||||
|
||||
@@ -391,14 +357,13 @@ class Customers extends Persons
|
||||
}
|
||||
}
|
||||
|
||||
if($count == count($customers_to_delete))
|
||||
{
|
||||
echo json_encode (['success' => true,
|
||||
'message' => lang('Customers.successful_deleted') . ' ' . $count . ' ' . lang('Customers.one_or_multiple')]);
|
||||
}
|
||||
else
|
||||
{
|
||||
echo json_encode (['success' => false, 'message' => lang('Customers.cannot_be_deleted')]);
|
||||
if ($count == count($customers_to_delete)) {
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'message' => lang('Customers.successful_deleted') . ' ' . $count . ' ' . lang('Customers.one_or_multiple')
|
||||
]);
|
||||
} else {
|
||||
echo json_encode(['success' => false, 'message' => lang('Customers.cannot_be_deleted')]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -434,101 +399,81 @@ class Customers extends Persons
|
||||
*/
|
||||
public function postImportCsvFile(): void
|
||||
{
|
||||
if($_FILES['file_path']['error'] != UPLOAD_ERR_OK)
|
||||
{
|
||||
echo json_encode (['success' => false, 'message' => lang('Customers.csv_import_failed')]);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(($handle = fopen($_FILES['file_path']['tmp_name'], 'r')) !== false)
|
||||
{
|
||||
if ($_FILES['file_path']['error'] != UPLOAD_ERR_OK) {
|
||||
echo json_encode(['success' => false, 'message' => lang('Customers.csv_import_failed')]);
|
||||
} else {
|
||||
if (($handle = fopen($_FILES['file_path']['tmp_name'], 'r')) !== false) {
|
||||
// Skip the first row as it's the table description
|
||||
fgetcsv($handle);
|
||||
$i = 1;
|
||||
|
||||
$failCodes = [];
|
||||
|
||||
while(($data = fgetcsv($handle)) !== false)
|
||||
{
|
||||
while (($data = fgetcsv($handle)) !== false) {
|
||||
$consent = $data[3] == '' ? 0 : 1;
|
||||
|
||||
if(sizeof($data) >= 16 && $consent)
|
||||
{
|
||||
if (sizeof($data) >= 16 && $consent) {
|
||||
$email = strtolower($data[4]);
|
||||
$person_data = [
|
||||
'first_name' => $data[0],
|
||||
'last_name' => $data[1],
|
||||
'gender' => $data[2],
|
||||
'email' => $email,
|
||||
'first_name' => $data[0],
|
||||
'last_name' => $data[1],
|
||||
'gender' => $data[2],
|
||||
'email' => $email,
|
||||
'phone_number' => $data[5],
|
||||
'address_1' => $data[6],
|
||||
'address_2' => $data[7],
|
||||
'city' => $data[8],
|
||||
'state' => $data[9],
|
||||
'zip' => $data[10],
|
||||
'country' => $data[11],
|
||||
'comments' => $data[12]
|
||||
'address_1' => $data[6],
|
||||
'address_2' => $data[7],
|
||||
'city' => $data[8],
|
||||
'state' => $data[9],
|
||||
'zip' => $data[10],
|
||||
'country' => $data[11],
|
||||
'comments' => $data[12]
|
||||
];
|
||||
|
||||
$customer_data = [
|
||||
'consent' => $consent,
|
||||
'company_name' => $data[13],
|
||||
'discount' => $data[15],
|
||||
'consent' => $consent,
|
||||
'company_name' => $data[13],
|
||||
'discount' => $data[15],
|
||||
'discount_type' => $data[16],
|
||||
'taxable' => $data[17] == '' ? 0 : 1,
|
||||
'date' => date('Y-m-d H:i:s'),
|
||||
'employee_id' => $this->employee->get_logged_in_employee_info()->person_id
|
||||
'taxable' => $data[17] == '' ? 0 : 1,
|
||||
'date' => date('Y-m-d H:i:s'),
|
||||
'employee_id' => $this->employee->get_logged_in_employee_info()->person_id
|
||||
];
|
||||
$account_number = $data[14];
|
||||
|
||||
// don't duplicate people with same email
|
||||
// Don't duplicate people with same email
|
||||
$invalidated = $this->customer->check_email_exists($email);
|
||||
|
||||
if($account_number != '')
|
||||
{
|
||||
if ($account_number != '') {
|
||||
$customer_data['account_number'] = $account_number;
|
||||
$invalidated &= $this->customer->check_account_number_exists($account_number);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$invalidated = true;
|
||||
}
|
||||
|
||||
if($invalidated)
|
||||
{
|
||||
if ($invalidated) {
|
||||
$failCodes[] = $i;
|
||||
log_message('error',"Row $i was not imported: Either email or account number already exist or data was invalid.");
|
||||
}
|
||||
elseif($this->customer->save_customer($person_data, $customer_data))
|
||||
{
|
||||
// save customer to Mailchimp selected list
|
||||
log_message('error', "Row $i was not imported: Either email or account number already exist or data was invalid.");
|
||||
} elseif ($this->customer->save_customer($person_data, $customer_data)) {
|
||||
// Save customer to Mailchimp selected list
|
||||
$this->mailchimp_lib->addOrUpdateMember($this->_list_id, $person_data['email'], $person_data['first_name'], '', $person_data['last_name']);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$failCodes[] = $i;
|
||||
}
|
||||
|
||||
++$i;
|
||||
}
|
||||
|
||||
if(count($failCodes) > 0)
|
||||
{
|
||||
if (count($failCodes) > 0) {
|
||||
$message = lang('Customers.csv_import_partially_failed', [count($failCodes), implode(', ', $failCodes)]);
|
||||
|
||||
echo json_encode (['success' => false, 'message' => $message]);
|
||||
echo json_encode(['success' => false, 'message' => $message]);
|
||||
} else {
|
||||
echo json_encode(['success' => true, 'message' => lang('Customers.csv_import_success')]);
|
||||
}
|
||||
else
|
||||
{
|
||||
echo json_encode (['success' => true, 'message' => lang('Customers.csv_import_success')]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
echo json_encode (['success' => false, 'message' => lang('Customers.csv_import_nodata_wrongformat')]);
|
||||
} else {
|
||||
echo json_encode(['success' => false, 'message' => lang('Customers.csv_import_nodata_wrongformat')]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -37,12 +37,11 @@ class Employees extends Persons
|
||||
$total_rows = $this->employee->get_found_rows($search);
|
||||
|
||||
$data_rows = [];
|
||||
foreach($employees->getResult() as $person)
|
||||
{
|
||||
foreach ($employees->getResult() as $person) {
|
||||
$data_rows[] = get_person_data_row($person);
|
||||
}
|
||||
|
||||
echo json_encode (['total' => $total_rows, 'rows' => $data_rows]);
|
||||
echo json_encode(['total' => $total_rows, 'rows' => $data_rows]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -75,16 +74,14 @@ class Employees extends Persons
|
||||
public function getView(int $employee_id = NEW_ENTRY): void
|
||||
{
|
||||
$person_info = $this->employee->get_info($employee_id);
|
||||
foreach(get_object_vars($person_info) as $property => $value)
|
||||
{
|
||||
foreach (get_object_vars($person_info) as $property => $value) {
|
||||
$person_info->$property = $value;
|
||||
}
|
||||
$data['person_info'] = $person_info;
|
||||
$data['employee_id'] = $employee_id;
|
||||
|
||||
$modules = [];
|
||||
foreach($this->module->get_all_modules()->getResult() as $module)
|
||||
{
|
||||
foreach ($this->module->get_all_modules()->getResult() as $module) {
|
||||
$module->grant = $this->employee->has_grant($module->module_id, $person_info->person_id);
|
||||
$module->menu_group = $this->employee->get_menu_group($module->module_id, $person_info->person_id);
|
||||
|
||||
@@ -93,8 +90,7 @@ class Employees extends Persons
|
||||
$data['all_modules'] = $modules;
|
||||
|
||||
$permissions = [];
|
||||
foreach($this->module->get_all_subpermissions()->getResult() as $permission) //TODO: subpermissions does not follow naming standards.
|
||||
{
|
||||
foreach ($this->module->get_all_subpermissions()->getResult() as $permission) { // TODO: subpermissions does not follow naming standards.
|
||||
$permission->permission_id = str_replace(' ', '_', $permission->permission_id);
|
||||
$permission->grant = $this->employee->has_grant($permission->permission_id, $person_info->person_id);
|
||||
|
||||
@@ -110,7 +106,7 @@ class Employees extends Persons
|
||||
*/
|
||||
public function postSave(int $employee_id = NEW_ENTRY): void
|
||||
{
|
||||
$first_name = $this->request->getPost('first_name', FILTER_SANITIZE_FULL_SPECIAL_CHARS); //TODO: duplicated code
|
||||
$first_name = $this->request->getPost('first_name', FILTER_SANITIZE_FULL_SPECIAL_CHARS); // TODO: duplicated code
|
||||
$last_name = $this->request->getPost('last_name', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
|
||||
$email = strtolower($this->request->getPost('email', FILTER_SANITIZE_EMAIL));
|
||||
|
||||
@@ -119,82 +115,71 @@ class Employees extends Persons
|
||||
$last_name = $this->nameize($last_name);
|
||||
|
||||
$person_data = [
|
||||
'first_name' => $first_name,
|
||||
'last_name' => $last_name,
|
||||
'gender' => $this->request->getPost('gender', FILTER_SANITIZE_NUMBER_INT),
|
||||
'email' => $email,
|
||||
'first_name' => $first_name,
|
||||
'last_name' => $last_name,
|
||||
'gender' => $this->request->getPost('gender', FILTER_SANITIZE_NUMBER_INT),
|
||||
'email' => $email,
|
||||
'phone_number' => $this->request->getPost('phone_number', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
|
||||
'address_1' => $this->request->getPost('address_1', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
|
||||
'address_2' => $this->request->getPost('address_2', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
|
||||
'city' => $this->request->getPost('city', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
|
||||
'state' => $this->request->getPost('state', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
|
||||
'zip' => $this->request->getPost('zip', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
|
||||
'country' => $this->request->getPost('country', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
|
||||
'comments' => $this->request->getPost('comments', FILTER_SANITIZE_FULL_SPECIAL_CHARS)
|
||||
'address_1' => $this->request->getPost('address_1', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
|
||||
'address_2' => $this->request->getPost('address_2', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
|
||||
'city' => $this->request->getPost('city', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
|
||||
'state' => $this->request->getPost('state', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
|
||||
'zip' => $this->request->getPost('zip', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
|
||||
'country' => $this->request->getPost('country', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
|
||||
'comments' => $this->request->getPost('comments', FILTER_SANITIZE_FULL_SPECIAL_CHARS)
|
||||
];
|
||||
|
||||
$grants_array = [];
|
||||
foreach($this->module->get_all_permissions()->getResult() as $permission)
|
||||
{
|
||||
foreach ($this->module->get_all_permissions()->getResult() as $permission) {
|
||||
$grants = [];
|
||||
$grant = $this->request->getPost('grant_'.$permission->permission_id) != null ? $this->request->getPost('grant_' . $permission->permission_id, FILTER_SANITIZE_FULL_SPECIAL_CHARS) : '';
|
||||
$grant = $this->request->getPost('grant_' . $permission->permission_id) != null ? $this->request->getPost('grant_' . $permission->permission_id, FILTER_SANITIZE_FULL_SPECIAL_CHARS) : '';
|
||||
|
||||
if($grant == $permission->permission_id)
|
||||
{
|
||||
if ($grant == $permission->permission_id) {
|
||||
$grants['permission_id'] = $permission->permission_id;
|
||||
$grants['menu_group'] = $this->request->getPost('menu_group_'.$permission->permission_id) != null ? $this->request->getPost('menu_group_' . $permission->permission_id, FILTER_SANITIZE_FULL_SPECIAL_CHARS) : '--';
|
||||
$grants['menu_group'] = $this->request->getPost('menu_group_' . $permission->permission_id) != null ? $this->request->getPost('menu_group_' . $permission->permission_id, FILTER_SANITIZE_FULL_SPECIAL_CHARS) : '--';
|
||||
$grants_array[] = $grants;
|
||||
}
|
||||
}
|
||||
|
||||
//Password has been changed OR first time password set
|
||||
if(!empty($this->request->getPost('password')) && ENVIRONMENT != 'testing')
|
||||
{
|
||||
// Password has been changed OR first time password set
|
||||
if (!empty($this->request->getPost('password')) && ENVIRONMENT != 'testing') {
|
||||
$exploded = explode(":", $this->request->getPost('language', FILTER_SANITIZE_FULL_SPECIAL_CHARS));
|
||||
$employee_data = [
|
||||
'username' => $this->request->getPost('username', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
|
||||
'password' => password_hash($this->request->getPost('password'), PASSWORD_DEFAULT),
|
||||
'hash_version' => 2,
|
||||
'username' => $this->request->getPost('username', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
|
||||
'password' => password_hash($this->request->getPost('password'), PASSWORD_DEFAULT),
|
||||
'hash_version' => 2,
|
||||
'language_code' => $exploded[0],
|
||||
'language' => $exploded[1]
|
||||
'language' => $exploded[1]
|
||||
];
|
||||
}
|
||||
else //Password not changed
|
||||
{
|
||||
} else { // Password not changed
|
||||
$exploded = explode(":", $this->request->getPost('language', FILTER_SANITIZE_FULL_SPECIAL_CHARS));
|
||||
$employee_data = [
|
||||
'username' => $this->request->getPost('username', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
|
||||
'language_code' => $exploded[0],
|
||||
'language' => $exploded[1]
|
||||
'username' => $this->request->getPost('username', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
|
||||
'language_code' => $exploded[0],
|
||||
'language' => $exploded[1]
|
||||
];
|
||||
}
|
||||
|
||||
if($this->employee->save_employee($person_data, $employee_data, $grants_array, $employee_id))
|
||||
{
|
||||
if ($this->employee->save_employee($person_data, $employee_data, $grants_array, $employee_id)) {
|
||||
// New employee
|
||||
if($employee_id == NEW_ENTRY)
|
||||
{
|
||||
echo json_encode ([
|
||||
if ($employee_id == NEW_ENTRY) {
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'message' => lang('Employees.successful_adding') . ' ' . $first_name . ' ' . $last_name,
|
||||
'id' => $employee_data['person_id']
|
||||
'id' => $employee_data['person_id']
|
||||
]);
|
||||
}
|
||||
else // Existing employee
|
||||
{
|
||||
echo json_encode ([
|
||||
} else { // Existing employee
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'message' => lang('Employees.successful_updating') . ' ' . $first_name . ' ' . $last_name,
|
||||
'id' => $employee_id
|
||||
'id' => $employee_id
|
||||
]);
|
||||
}
|
||||
}
|
||||
else // Failure
|
||||
{
|
||||
echo json_encode ([
|
||||
} else { // Failure
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'message' => lang('Employees.error_adding_updating') . ' ' . $first_name . ' ' . $last_name,
|
||||
'id' => NEW_ENTRY
|
||||
'id' => NEW_ENTRY
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -206,16 +191,13 @@ class Employees extends Persons
|
||||
{
|
||||
$employees_to_delete = $this->request->getPost('ids', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
|
||||
|
||||
if($this->employee->delete_list($employees_to_delete)) //TODO: this is passing a string, but delete_list expects an array
|
||||
{
|
||||
echo json_encode ([
|
||||
if ($this->employee->delete_list($employees_to_delete)) { // TODO: this is passing a string, but delete_list expects an array
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'message' => lang('Employees.successful_deleted') . ' ' . count($employees_to_delete) . ' ' . lang('Employees.one_or_multiple')
|
||||
]);
|
||||
}
|
||||
else
|
||||
{
|
||||
echo json_encode (['success' => false, 'message' => lang('Employees.cannot_be_deleted')]);
|
||||
} else {
|
||||
echo json_encode(['success' => false, 'message' => lang('Employees.cannot_be_deleted')]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -29,12 +29,12 @@ class Expenses extends Secure_Controller
|
||||
|
||||
// filters that will be loaded in the multiselect dropdown
|
||||
$data['filters'] = [
|
||||
'only_cash' => lang('Expenses.cash_filter'),
|
||||
'only_due' => lang('Expenses.due_filter'),
|
||||
'only_check' => lang('Expenses.check_filter'),
|
||||
'only_cash' => lang('Expenses.cash_filter'),
|
||||
'only_due' => lang('Expenses.due_filter'),
|
||||
'only_check' => lang('Expenses.check_filter'),
|
||||
'only_credit' => lang('Expenses.credit_filter'),
|
||||
'only_debit' => lang('Expenses.debit_filter'),
|
||||
'is_deleted' => lang('Expenses.is_deleted')
|
||||
'only_debit' => lang('Expenses.debit_filter'),
|
||||
'is_deleted' => lang('Expenses.is_deleted')
|
||||
];
|
||||
|
||||
echo view('expenses/manage', $data);
|
||||
@@ -51,17 +51,17 @@ class Expenses extends Secure_Controller
|
||||
$sort = $this->sanitizeSortColumn(expense_headers(), $this->request->getGet('sort', FILTER_SANITIZE_FULL_SPECIAL_CHARS), 'expense_id');
|
||||
$order = $this->request->getGet('order', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
|
||||
$filters = [
|
||||
'start_date' => $this->request->getGet('start_date', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
|
||||
'end_date' => $this->request->getGet('end_date', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
|
||||
'only_cash' => false,
|
||||
'only_due' => false,
|
||||
'only_check' => false,
|
||||
'start_date' => $this->request->getGet('start_date', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
|
||||
'end_date' => $this->request->getGet('end_date', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
|
||||
'only_cash' => false,
|
||||
'only_due' => false,
|
||||
'only_check' => false,
|
||||
'only_credit' => false,
|
||||
'only_debit' => false,
|
||||
'is_deleted' => false
|
||||
'only_debit' => false,
|
||||
'is_deleted' => false
|
||||
];
|
||||
|
||||
// check if any filter is set in the multiselect dropdown
|
||||
// Check if any filter is set in the multiselect dropdown
|
||||
$request_filters = array_fill_keys($this->request->getGet('filters', FILTER_SANITIZE_FULL_SPECIAL_CHARS) ?? [], true);
|
||||
$filters = array_merge($filters, $request_filters);
|
||||
$expenses = $this->expense->search($search, $filters, $limit, $offset, $sort, $order);
|
||||
@@ -70,17 +70,15 @@ class Expenses extends Secure_Controller
|
||||
$payment_summary = get_expenses_manage_payments_summary($payments, $expenses);
|
||||
$data_rows = [];
|
||||
|
||||
foreach($expenses->getResult() as $expense)
|
||||
{
|
||||
foreach ($expenses->getResult() as $expense) {
|
||||
$data_rows[] = get_expenses_data_row($expense);
|
||||
}
|
||||
|
||||
if($total_rows > 0)
|
||||
{
|
||||
if ($total_rows > 0) {
|
||||
$data_rows[] = get_expenses_data_last_row($expenses);
|
||||
}
|
||||
|
||||
echo json_encode (['total' => $total_rows, 'rows' => $data_rows, 'payment_summary' => $payment_summary]);
|
||||
echo json_encode(['total' => $total_rows, 'rows' => $data_rows, 'payment_summary' => $payment_summary]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -89,13 +87,11 @@ class Expenses extends Secure_Controller
|
||||
*/
|
||||
public function getView(int $expense_id = NEW_ENTRY): void
|
||||
{
|
||||
$data = []; //TODO: Duplicated code
|
||||
$data = []; // TODO: Duplicated code
|
||||
|
||||
$data['employees'] = [];
|
||||
foreach($this->employee->get_all()->getResult() as $employee)
|
||||
{
|
||||
foreach(get_object_vars($employee) as $property => $value)
|
||||
{
|
||||
foreach ($this->employee->get_all()->getResult() as $employee) {
|
||||
foreach (get_object_vars($employee) as $property => $value) {
|
||||
$employee->$property = $value;
|
||||
}
|
||||
|
||||
@@ -105,32 +101,28 @@ class Expenses extends Secure_Controller
|
||||
$data['expenses_info'] = $this->expense->get_info($expense_id);
|
||||
|
||||
$expense_categories = [];
|
||||
foreach($this->expense_category->get_all(0, 0, true)->getResultArray() as $row)
|
||||
{
|
||||
foreach ($this->expense_category->get_all(0, 0, true)->getResultArray() as $row) {
|
||||
$expense_categories[$row['expense_category_id']] = $row['category_name'];
|
||||
}
|
||||
$data['expense_categories'] = $expense_categories;
|
||||
|
||||
$expense_id = $data['expenses_info']->expense_id;
|
||||
|
||||
if($expense_id == NEW_ENTRY)
|
||||
{
|
||||
if ($expense_id == NEW_ENTRY) {
|
||||
$data['expenses_info']->date = date('Y-m-d H:i:s');
|
||||
$data['expenses_info']->employee_id = $this->employee->get_logged_in_employee_info()->person_id;
|
||||
}
|
||||
|
||||
$data['payments'] = [];
|
||||
foreach($this->expense->get_expense_payment($expense_id)->getResult() as $payment)
|
||||
{
|
||||
foreach(get_object_vars($payment) as $property => $value)
|
||||
{
|
||||
foreach ($this->expense->get_expense_payment($expense_id)->getResult() as $payment) {
|
||||
foreach (get_object_vars($payment) as $property => $value) {
|
||||
$payment->$property = $value;
|
||||
}
|
||||
|
||||
$data['payments'][] = $payment;
|
||||
}
|
||||
|
||||
// don't allow gift card to be a payment option in a sale transaction edit because it's a complex change
|
||||
// Don't allow gift card to be a payment option in a sale transaction edit because it's a complex change
|
||||
$data['payment_options'] = $this->expense->get_payment_options();
|
||||
|
||||
echo view("expenses/form", $data);
|
||||
@@ -160,33 +152,27 @@ class Expenses extends Secure_Controller
|
||||
$date_formatter = date_create_from_format($config['dateformat'] . ' ' . $config['timeformat'], $newdate);
|
||||
|
||||
$expense_data = [
|
||||
'date' => $date_formatter->format('Y-m-d H:i:s'),
|
||||
'supplier_id' => $this->request->getPost('supplier_id') == '' ? null : $this->request->getPost('supplier_id', FILTER_SANITIZE_NUMBER_INT),
|
||||
'supplier_tax_code' => $this->request->getPost('supplier_tax_code', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
|
||||
'amount' => parse_decimals($this->request->getPost('amount')),
|
||||
'tax_amount' => parse_decimals($this->request->getPost('tax_amount')),
|
||||
'payment_type' => $this->request->getPost('payment_type', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
|
||||
'date' => $date_formatter->format('Y-m-d H:i:s'),
|
||||
'supplier_id' => $this->request->getPost('supplier_id') == '' ? null : $this->request->getPost('supplier_id', FILTER_SANITIZE_NUMBER_INT),
|
||||
'supplier_tax_code' => $this->request->getPost('supplier_tax_code', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
|
||||
'amount' => parse_decimals($this->request->getPost('amount')),
|
||||
'tax_amount' => parse_decimals($this->request->getPost('tax_amount')),
|
||||
'payment_type' => $this->request->getPost('payment_type', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
|
||||
'expense_category_id' => $this->request->getPost('expense_category_id', FILTER_SANITIZE_NUMBER_INT),
|
||||
'description' => $this->request->getPost('description', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
|
||||
'employee_id' => $this->request->getPost('employee_id', FILTER_SANITIZE_NUMBER_INT),
|
||||
'deleted' => $this->request->getPost('deleted') != null
|
||||
'description' => $this->request->getPost('description', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
|
||||
'employee_id' => $this->request->getPost('employee_id', FILTER_SANITIZE_NUMBER_INT),
|
||||
'deleted' => $this->request->getPost('deleted') != null
|
||||
];
|
||||
|
||||
if($this->expense->save_value($expense_data, $expense_id))
|
||||
{
|
||||
//New Expense
|
||||
if($expense_id == NEW_ENTRY)
|
||||
{
|
||||
echo json_encode (['success' => true, 'message' => lang('Expenses.successful_adding'), 'id' => $expense_data['expense_id']]);
|
||||
if ($this->expense->save_value($expense_data, $expense_id)) {
|
||||
// New Expense
|
||||
if ($expense_id == NEW_ENTRY) {
|
||||
echo json_encode(['success' => true, 'message' => lang('Expenses.successful_adding'), 'id' => $expense_data['expense_id']]);
|
||||
} else { // Existing Expense
|
||||
echo json_encode(['success' => true, 'message' => lang('Expenses.successful_updating'), 'id' => $expense_id]);
|
||||
}
|
||||
else // Existing Expense
|
||||
{
|
||||
echo json_encode (['success' => true, 'message' => lang('Expenses.successful_updating'), 'id' => $expense_id]);
|
||||
}
|
||||
}
|
||||
else//failure
|
||||
{
|
||||
echo json_encode (['success' => false, 'message' => lang('Expenses.error_adding_updating'), 'id' => NEW_ENTRY]);
|
||||
} else { // Failure
|
||||
echo json_encode(['success' => false, 'message' => lang('Expenses.error_adding_updating'), 'id' => NEW_ENTRY]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -197,13 +183,10 @@ class Expenses extends Secure_Controller
|
||||
{
|
||||
$expenses_to_delete = $this->request->getPost('ids', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
|
||||
|
||||
if($this->expense->delete_list($expenses_to_delete))
|
||||
{
|
||||
echo json_encode (['success' => true, 'message' => lang('Expenses.successful_deleted') . ' ' . count($expenses_to_delete) . ' ' . lang('Expenses.one_or_multiple'), 'ids' => $expenses_to_delete]);
|
||||
}
|
||||
else
|
||||
{
|
||||
echo json_encode (['success' => false, 'message' => lang('Expenses.cannot_be_deleted'), 'ids' => $expenses_to_delete]);
|
||||
if ($this->expense->delete_list($expenses_to_delete)) {
|
||||
echo json_encode(['success' => true, 'message' => lang('Expenses.successful_deleted') . ' ' . count($expenses_to_delete) . ' ' . lang('Expenses.one_or_multiple'), 'ids' => $expenses_to_delete]);
|
||||
} else {
|
||||
echo json_encode(['success' => false, 'message' => lang('Expenses.cannot_be_deleted'), 'ids' => $expenses_to_delete]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace App\Controllers;
|
||||
use App\Models\Expense_category;
|
||||
use Config\Services;
|
||||
|
||||
class Expenses_categories extends Secure_Controller //TODO: Is this class ever used?
|
||||
class Expenses_categories extends Secure_Controller // TODO: Is this class ever used?
|
||||
{
|
||||
private Expense_category $expense_category;
|
||||
|
||||
@@ -23,7 +23,7 @@ class Expenses_categories extends Secure_Controller //TODO: Is this class eve
|
||||
{
|
||||
$data['table_headers'] = get_expense_category_manage_table_headers();
|
||||
|
||||
echo view('expenses_categories/manage', $data);
|
||||
echo view('expenses_categories/manage', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -41,12 +41,11 @@ class Expenses_categories extends Secure_Controller //TODO: Is this class eve
|
||||
$total_rows = $this->expense_category->get_found_rows($search);
|
||||
|
||||
$data_rows = [];
|
||||
foreach($expense_categories->getResult() as $expense_category)
|
||||
{
|
||||
foreach ($expense_categories->getResult() as $expense_category) {
|
||||
$data_rows[] = get_expense_category_data_row($expense_category);
|
||||
}
|
||||
|
||||
echo json_encode (['total' => $total_rows, 'rows' => $data_rows]);
|
||||
echo json_encode(['total' => $total_rows, 'rows' => $data_rows]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -78,36 +77,30 @@ class Expenses_categories extends Secure_Controller //TODO: Is this class eve
|
||||
public function postSave(int $expense_category_id = NEW_ENTRY): void
|
||||
{
|
||||
$expense_category_data = [
|
||||
'category_name' => $this->request->getPost('category_name', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
|
||||
'category_name' => $this->request->getPost('category_name', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
|
||||
'category_description' => $this->request->getPost('category_description', FILTER_SANITIZE_FULL_SPECIAL_CHARS)
|
||||
];
|
||||
|
||||
if($this->expense_category->save_value($expense_category_data, $expense_category_id))
|
||||
{
|
||||
if ($this->expense_category->save_value($expense_category_data, $expense_category_id)) {
|
||||
// New expense_category
|
||||
if($expense_category_id == NEW_ENTRY)
|
||||
{
|
||||
echo json_encode ([
|
||||
if ($expense_category_id == NEW_ENTRY) {
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'message' => lang('Expenses_categories.successful_adding'),
|
||||
'id' => $expense_category_data['expense_category_id']
|
||||
'id' => $expense_category_data['expense_category_id']
|
||||
]);
|
||||
}
|
||||
else // Existing Expense Category
|
||||
{
|
||||
echo json_encode ([
|
||||
} else { // Existing Expense Category
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'message' => lang('Expenses_categories.successful_updating'),
|
||||
'id' => $expense_category_id
|
||||
'id' => $expense_category_id
|
||||
]);
|
||||
}
|
||||
}
|
||||
else//failure
|
||||
{
|
||||
echo json_encode ([
|
||||
} else { // Failure
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'message' => lang('Expenses_categories.error_adding_updating') . ' ' . $expense_category_data['category_name'],
|
||||
'id' => NEW_ENTRY
|
||||
'id' => NEW_ENTRY
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -119,16 +112,13 @@ class Expenses_categories extends Secure_Controller //TODO: Is this class eve
|
||||
{
|
||||
$expense_category_to_delete = $this->request->getPost('ids', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
|
||||
|
||||
if($this->expense_category->delete_list($expense_category_to_delete)) //TODO: Convert to ternary notation.
|
||||
{
|
||||
if ($this->expense_category->delete_list($expense_category_to_delete)) { // TODO: Convert to ternary notation.
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'message' => lang('Expenses_categories.successful_deleted') . ' ' . count($expense_category_to_delete) . ' ' . lang('Expenses_categories.one_or_multiple')
|
||||
]);
|
||||
}
|
||||
else
|
||||
{
|
||||
echo json_encode (['success' => false, 'message' => lang('Expenses_categories.cannot_be_deleted')]);
|
||||
} else {
|
||||
echo json_encode(['success' => false, 'message' => lang('Expenses_categories.cannot_be_deleted')]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,12 +42,11 @@ class Giftcards extends Secure_Controller
|
||||
$total_rows = $this->giftcard->get_found_rows($search);
|
||||
|
||||
$data_rows = [];
|
||||
foreach($giftcards->getResult() as $giftcard)
|
||||
{
|
||||
foreach ($giftcards->getResult() as $giftcard) {
|
||||
$data_rows[] = get_giftcard_data_row($giftcard);
|
||||
}
|
||||
|
||||
echo json_encode (['total' => $total_rows, 'rows' => $data_rows]);
|
||||
echo json_encode(['total' => $total_rows, 'rows' => $data_rows]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -97,14 +96,11 @@ class Giftcards extends Secure_Controller
|
||||
|
||||
$data['selected_person_name'] = ($giftcard_id > 0 && isset($giftcard_info->person_id)) ? $giftcard_info->first_name . ' ' . $giftcard_info->last_name : '';
|
||||
$data['selected_person_id'] = $giftcard_info->person_id;
|
||||
if($config['giftcard_number'] == 'random')
|
||||
{
|
||||
if ($config['giftcard_number'] == 'random') {
|
||||
$data['giftcard_number'] = $giftcard_id > 0 ? $giftcard_info->giftcard_number : '';
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$max_number_obj = $this->giftcard->get_max_number();
|
||||
$max_giftnumber = isset($max_number_obj) ? $this->giftcard->get_max_number()->giftcard_number : 0; //TODO: variable does not follow naming standard.
|
||||
$max_giftnumber = isset($max_number_obj) ? $this->giftcard->get_max_number()->giftcard_number : 0; // TODO: variable does not follow naming standard.
|
||||
$data['giftcard_number'] = $giftcard_id > 0 ? $giftcard_info->giftcard_number : $max_giftnumber + 1;
|
||||
}
|
||||
$data['giftcard_id'] = $giftcard_id;
|
||||
@@ -121,44 +117,37 @@ class Giftcards extends Secure_Controller
|
||||
{
|
||||
$giftcard_number = $this->request->getPost('giftcard_number', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
|
||||
|
||||
if($giftcard_id == NEW_ENTRY && trim($giftcard_number) == '')
|
||||
{
|
||||
if ($giftcard_id == NEW_ENTRY && trim($giftcard_number) == '') {
|
||||
$giftcard_number = $this->giftcard->generate_unique_giftcard_name($giftcard_number);
|
||||
}
|
||||
|
||||
$giftcard_data = [
|
||||
'record_time' => date('Y-m-d H:i:s'),
|
||||
'record_time' => date('Y-m-d H:i:s'),
|
||||
'giftcard_number' => $giftcard_number,
|
||||
'value' => parse_decimals($this->request->getPost('giftcard_amount')),
|
||||
'person_id' => $this->request->getPost('person_id') == '' ? null : $this->request->getPost('person_id', FILTER_SANITIZE_NUMBER_INT)
|
||||
'value' => parse_decimals($this->request->getPost('giftcard_amount')),
|
||||
'person_id' => $this->request->getPost('person_id') == '' ? null : $this->request->getPost('person_id', FILTER_SANITIZE_NUMBER_INT)
|
||||
];
|
||||
|
||||
if($this->giftcard->save_value($giftcard_data, $giftcard_id))
|
||||
{
|
||||
//New giftcard
|
||||
if($giftcard_id == NEW_ENTRY) //TODO: Constant needed
|
||||
{
|
||||
echo json_encode ([
|
||||
if ($this->giftcard->save_value($giftcard_data, $giftcard_id)) {
|
||||
// New giftcard
|
||||
if ($giftcard_id == NEW_ENTRY) { // TODO: Constant needed
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'message' => lang('Giftcards.successful_adding') . ' ' . $giftcard_data['giftcard_number'],
|
||||
'id' => $giftcard_data['giftcard_id']
|
||||
'id' => $giftcard_data['giftcard_id']
|
||||
]);
|
||||
}
|
||||
else //Existing giftcard
|
||||
{
|
||||
echo json_encode ([
|
||||
} else { // Existing giftcard
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'message' => lang('Giftcards.successful_updating') . ' ' . $giftcard_data['giftcard_number'],
|
||||
'id' => $giftcard_id
|
||||
'id' => $giftcard_id
|
||||
]);
|
||||
}
|
||||
}
|
||||
else //failure
|
||||
{
|
||||
echo json_encode ([
|
||||
} else { // Failure
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'message' => lang('Giftcards.error_adding_updating') . ' ' . $giftcard_data['giftcard_number'],
|
||||
'id' => NEW_ENTRY
|
||||
'id' => NEW_ENTRY
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -173,7 +162,7 @@ class Giftcards extends Secure_Controller
|
||||
{
|
||||
$giftcard_amount = parse_decimals($this->request->getPost('giftcard_amount'));
|
||||
$parsed_value = filter_var($giftcard_amount, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
|
||||
echo json_encode (['success' => $parsed_value !== false && $parsed_value > 0 && $giftcard_amount !== false, 'giftcard_amount' => to_currency_no_money($parsed_value)]);
|
||||
echo json_encode(['success' => $parsed_value !== false && $parsed_value > 0 && $giftcard_amount !== false, 'giftcard_amount' => to_currency_no_money($parsed_value)]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -183,16 +172,13 @@ class Giftcards extends Secure_Controller
|
||||
{
|
||||
$giftcards_to_delete = $this->request->getPost('ids', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
|
||||
|
||||
if($this->giftcard->delete_list($giftcards_to_delete))
|
||||
{
|
||||
echo json_encode ([
|
||||
if ($this->giftcard->delete_list($giftcards_to_delete)) {
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'message' => lang('Giftcards.successful_deleted') . ' ' . count($giftcards_to_delete).' '.lang('Giftcards.one_or_multiple')
|
||||
'message' => lang('Giftcards.successful_deleted') . ' ' . count($giftcards_to_delete) . ' ' . lang('Giftcards.one_or_multiple')
|
||||
]);
|
||||
}
|
||||
else
|
||||
{
|
||||
echo json_encode (['success' => false, 'message' => lang('Giftcards.cannot_be_deleted')]);
|
||||
} else {
|
||||
echo json_encode(['success' => false, 'message' => lang('Giftcards.cannot_be_deleted')]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,11 +37,10 @@ class Home extends Secure_Controller
|
||||
*
|
||||
* @noinspection PhpUnused
|
||||
*/
|
||||
public function getChangePassword(int $employee_id = -1): void //TODO: Replace -1 with a constant
|
||||
public function getChangePassword(int $employee_id = -1): void // TODO: Replace -1 with a constant
|
||||
{
|
||||
$person_info = $this->employee->get_info($employee_id);
|
||||
foreach(get_object_vars($person_info) as $property => $value)
|
||||
{
|
||||
foreach (get_object_vars($person_info) as $property => $value) {
|
||||
$person_info->$property = $value;
|
||||
}
|
||||
$data['person_info'] = $person_info;
|
||||
@@ -52,50 +51,41 @@ class Home extends Secure_Controller
|
||||
/**
|
||||
* Change employee password
|
||||
*/
|
||||
public function postSave(int $employee_id = -1): void //TODO: Replace -1 with a constant
|
||||
public function postSave(int $employee_id = -1): void // TODO: Replace -1 with a constant
|
||||
{
|
||||
if(!empty($this->request->getPost('current_password')) && $employee_id != -1)
|
||||
{
|
||||
if($this->employee->check_password($this->request->getPost('username', FILTER_SANITIZE_FULL_SPECIAL_CHARS), $this->request->getPost('current_password')))
|
||||
{
|
||||
if (!empty($this->request->getPost('current_password')) && $employee_id != -1) {
|
||||
if ($this->employee->check_password($this->request->getPost('username', FILTER_SANITIZE_FULL_SPECIAL_CHARS), $this->request->getPost('current_password'))) {
|
||||
$employee_data = [
|
||||
'username' => $this->request->getPost('username', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
|
||||
'password' => password_hash($this->request->getPost('password'), PASSWORD_DEFAULT),
|
||||
'username' => $this->request->getPost('username', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
|
||||
'password' => password_hash($this->request->getPost('password'), PASSWORD_DEFAULT),
|
||||
'hash_version' => 2
|
||||
];
|
||||
|
||||
if($this->employee->change_password($employee_data, $employee_id))
|
||||
{
|
||||
echo json_encode ([
|
||||
if ($this->employee->change_password($employee_data, $employee_id)) {
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'message' => lang('Employees.successful_change_password'),
|
||||
'id' => $employee_id
|
||||
'id' => $employee_id
|
||||
]);
|
||||
}
|
||||
else//failure
|
||||
{//TODO: Replace -1 with constant
|
||||
echo json_encode ([
|
||||
} else { // Failure // TODO: Replace -1 with constant
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'message' => lang('Employees.unsuccessful_change_password'),
|
||||
'id' => -1
|
||||
'id' => -1
|
||||
]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{//TODO: Replace -1 with constant
|
||||
echo json_encode ([
|
||||
} else { // TODO: Replace -1 with constant
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'message' => lang('Employees.current_password_invalid'),
|
||||
'id' => -1
|
||||
'id' => -1
|
||||
]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{//TODO: Replace -1 with constant
|
||||
echo json_encode ([
|
||||
} else { // TODO: Replace -1 with constant
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'message' => lang('Employees.current_password_invalid'),
|
||||
'id' => -1
|
||||
'id' => -1
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ class Item_kits extends Secure_Controller
|
||||
/**
|
||||
* Add the total cost and retail price to a passed item_kit retrieving the data from each singular item part of the kit
|
||||
*/
|
||||
private function _add_totals_to_item_kit(object $item_kit): object //TODO: Hungarian notation
|
||||
private function _add_totals_to_item_kit(object $item_kit): object // TODO: Hungarian notation
|
||||
{
|
||||
$kit_item_info = $this->item->get_info($item_kit->kit_item_id ?? $item_kit->item_id);
|
||||
|
||||
@@ -35,18 +35,15 @@ class Item_kits extends Secure_Controller
|
||||
$item_kit->total_unit_price = $kit_item_info->unit_price;
|
||||
$total_quantity = 0;
|
||||
|
||||
foreach($this->item_kit_items->get_info($item_kit->item_kit_id) as $item_kit_item)
|
||||
{
|
||||
foreach ($this->item_kit_items->get_info($item_kit->item_kit_id) as $item_kit_item) {
|
||||
$item_info = $this->item->get_info($item_kit_item['item_id']);
|
||||
foreach(get_object_vars($item_info) as $property => $value)
|
||||
{
|
||||
foreach (get_object_vars($item_info) as $property => $value) {
|
||||
$item_info->$property = $value;
|
||||
}
|
||||
|
||||
$item_kit->total_cost_price += $item_info->cost_price * $item_kit_item['quantity'];
|
||||
|
||||
if($item_kit->price_option == PRICE_OPTION_ALL || ($item_kit->price_option == PRICE_OPTION_KIT_STOCK && $item_info->stock_type == HAS_STOCK ))
|
||||
{
|
||||
if ($item_kit->price_option == PRICE_OPTION_ALL || ($item_kit->price_option == PRICE_OPTION_KIT_STOCK && $item_info->stock_type == HAS_STOCK)) {
|
||||
$item_kit->total_unit_price += $item_info->unit_price * $item_kit_item['quantity'];
|
||||
$total_quantity += $item_kit_item['quantity'];
|
||||
}
|
||||
@@ -55,8 +52,8 @@ class Item_kits extends Secure_Controller
|
||||
$discount_fraction = bcdiv($item_kit->kit_discount, '100');
|
||||
|
||||
$item_kit->total_unit_price = $item_kit->total_unit_price - round(($item_kit->kit_discount_type == PERCENT)
|
||||
? bcmul($item_kit->total_unit_price, $discount_fraction)
|
||||
: $item_kit->kit_discount, totals_decimals(), PHP_ROUND_HALF_UP);
|
||||
? bcmul($item_kit->total_unit_price, $discount_fraction)
|
||||
: $item_kit->kit_discount, totals_decimals(), PHP_ROUND_HALF_UP);
|
||||
|
||||
return $item_kit;
|
||||
}
|
||||
@@ -86,14 +83,13 @@ class Item_kits extends Secure_Controller
|
||||
$total_rows = $this->item_kit->get_found_rows($search);
|
||||
|
||||
$data_rows = [];
|
||||
foreach($item_kits->getResult() as $item_kit)
|
||||
{
|
||||
// calculate the total cost and retail price of the Kit, so it can be printed out in the manage table
|
||||
foreach ($item_kits->getResult() as $item_kit) {
|
||||
// Calculate the total cost and retail price of the Kit, so it can be printed out in the manage table
|
||||
$item_kit = $this->_add_totals_to_item_kit($item_kit);
|
||||
$data_rows[] = get_item_kit_data_row($item_kit);
|
||||
}
|
||||
|
||||
echo json_encode (['total' => $total_rows, 'rows' => $data_rows]);
|
||||
echo json_encode(['total' => $total_rows, 'rows' => $data_rows]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -113,7 +109,7 @@ class Item_kits extends Secure_Controller
|
||||
*/
|
||||
public function getRow(int $row_id): void
|
||||
{
|
||||
// calculate the total cost and retail price of the Kit, so it can be added to the table refresh
|
||||
// Calculate the total cost and retail price of the Kit, so it can be added to the table refresh
|
||||
$item_kit = $this->_add_totals_to_item_kit($this->item_kit->get_info($row_id));
|
||||
|
||||
echo json_encode(get_item_kit_data_row($item_kit));
|
||||
@@ -127,8 +123,7 @@ class Item_kits extends Secure_Controller
|
||||
{
|
||||
$info = $this->item_kit->get_info($item_kit_id);
|
||||
|
||||
if($item_kit_id == NEW_ENTRY)
|
||||
{
|
||||
if ($item_kit_id == NEW_ENTRY) {
|
||||
$info->price_option = '0';
|
||||
$info->print_option = PRINT_ALL;
|
||||
$info->kit_item_id = 0;
|
||||
@@ -136,8 +131,7 @@ class Item_kits extends Secure_Controller
|
||||
$info->kit_discount = 0;
|
||||
}
|
||||
|
||||
foreach(get_object_vars($info) as $property => $value)
|
||||
{
|
||||
foreach (get_object_vars($info) as $property => $value) {
|
||||
$info->$property = $value;
|
||||
}
|
||||
|
||||
@@ -145,8 +139,7 @@ class Item_kits extends Secure_Controller
|
||||
|
||||
$items = [];
|
||||
|
||||
foreach($this->item_kit_items->get_info($item_kit_id) as $item_kit_item)
|
||||
{
|
||||
foreach ($this->item_kit_items->get_info($item_kit_id) as $item_kit_item) {
|
||||
$item['kit_sequence'] = $item_kit_item['kit_sequence'];
|
||||
$item['name'] = $this->item->get_info($item_kit_item['item_id'])->name;
|
||||
$item['item_id'] = $item_kit_item['item_id'];
|
||||
@@ -170,74 +163,61 @@ class Item_kits extends Secure_Controller
|
||||
public function postSave(int $item_kit_id = NEW_ENTRY): void
|
||||
{
|
||||
$item_kit_data = [
|
||||
'name' => $this->request->getPost('name'),
|
||||
'item_kit_number' => $this->request->getPost('item_kit_number'),
|
||||
'item_id' => $this->request->getPost('kit_item_id') ? null : intval($this->request->getPost('kit_item_id')),
|
||||
'kit_discount' => parse_decimals($this->request->getPost('kit_discount')),
|
||||
'name' => $this->request->getPost('name'),
|
||||
'item_kit_number' => $this->request->getPost('item_kit_number'),
|
||||
'item_id' => $this->request->getPost('kit_item_id') ? null : intval($this->request->getPost('kit_item_id')),
|
||||
'kit_discount' => parse_decimals($this->request->getPost('kit_discount')),
|
||||
'kit_discount_type' => $this->request->getPost('kit_discount_type') === null ? PERCENT : intval($this->request->getPost('kit_discount_type')),
|
||||
'price_option' => $this->request->getPost('price_option') === null ? PRICE_ALL : intval($this->request->getPost('price_option')),
|
||||
'print_option' => $this->request->getPost('print_option') === null ? PRINT_ALL : intval($this->request->getPost('print_option')),
|
||||
'description' => $this->request->getPost('description')
|
||||
'price_option' => $this->request->getPost('price_option') === null ? PRICE_ALL : intval($this->request->getPost('price_option')),
|
||||
'print_option' => $this->request->getPost('print_option') === null ? PRINT_ALL : intval($this->request->getPost('print_option')),
|
||||
'description' => $this->request->getPost('description')
|
||||
];
|
||||
|
||||
if($this->item_kit->save_value($item_kit_data, $item_kit_id))
|
||||
{
|
||||
if ($this->item_kit->save_value($item_kit_data, $item_kit_id)) {
|
||||
$new_item = false;
|
||||
//New item kit
|
||||
if($item_kit_id == NEW_ENTRY)
|
||||
{
|
||||
// New item kit
|
||||
if ($item_kit_id == NEW_ENTRY) {
|
||||
$item_kit_id = $item_kit_data['item_kit_id'];
|
||||
$new_item = true;
|
||||
}
|
||||
|
||||
$item_kit_items_array = $this->request->getPost('item_kit_qty') === null ? null : $this->request->getPost('item_kit_qty');
|
||||
|
||||
if($item_kit_items_array != null)
|
||||
{
|
||||
if ($item_kit_items_array != null) {
|
||||
$item_kit_items = [];
|
||||
foreach($item_kit_items_array as $item_id => $item_kit_qty)
|
||||
{
|
||||
foreach ($item_kit_items_array as $item_id => $item_kit_qty) {
|
||||
$item_kit_items[] = [
|
||||
'item_id' => $item_id,
|
||||
'quantity' => $item_kit_qty === null ? 0 : parse_quantity($item_kit_qty),
|
||||
'item_id' => $item_id,
|
||||
'quantity' => $item_kit_qty === null ? 0 : parse_quantity($item_kit_qty),
|
||||
'kit_sequence' => $this->request->getPost("item_kit_seq[$item_id]") === null ? 0 : intval($this->request->getPost("item_kit_seq[$item_id]"))
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($item_kit_items))
|
||||
{
|
||||
if (!empty($item_kit_items)) {
|
||||
$success = $this->item_kit_items->save_value($item_kit_items, $item_kit_id);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$success = true;
|
||||
}
|
||||
|
||||
if($new_item)
|
||||
{
|
||||
echo json_encode ([
|
||||
if ($new_item) {
|
||||
echo json_encode([
|
||||
'success' => $success,
|
||||
'message' => lang('Item_kits.successful_adding').' '.$item_kit_data['name'],
|
||||
'id' => $item_kit_id
|
||||
'message' => lang('Item_kits.successful_adding') . ' ' . $item_kit_data['name'],
|
||||
'id' => $item_kit_id
|
||||
]);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
echo json_encode ([
|
||||
} else {
|
||||
echo json_encode([
|
||||
'success' => $success,
|
||||
'message' => lang('Item_kits.successful_updating').' '.$item_kit_data['name'],
|
||||
'id' => $item_kit_id
|
||||
'message' => lang('Item_kits.successful_updating') . ' ' . $item_kit_data['name'],
|
||||
'id' => $item_kit_id
|
||||
]);
|
||||
}
|
||||
}
|
||||
else//failure
|
||||
{
|
||||
echo json_encode ([
|
||||
} else { // Failure
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'message' => lang('Item_kits.error_adding_updating') . ' ' . $item_kit_data['name'],
|
||||
'id' => NEW_ENTRY
|
||||
'id' => NEW_ENTRY
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -249,16 +229,13 @@ class Item_kits extends Secure_Controller
|
||||
{
|
||||
$item_kits_to_delete = $this->request->getPost('ids', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
|
||||
|
||||
if($this->item_kit->delete_list($item_kits_to_delete))
|
||||
{
|
||||
echo json_encode ([
|
||||
if ($this->item_kit->delete_list($item_kits_to_delete)) {
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'message' => lang('Item_kits.successful_deleted') . ' ' . count($item_kits_to_delete) . ' ' . lang('Item_kits.one_or_multiple')
|
||||
]);
|
||||
}
|
||||
else
|
||||
{
|
||||
echo json_encode (['success' => false, 'message' => lang('Item_kits.cannot_be_deleted')]);
|
||||
} else {
|
||||
echo json_encode(['success' => false, 'message' => lang('Item_kits.cannot_be_deleted')]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -287,33 +264,31 @@ class Item_kits extends Secure_Controller
|
||||
$result = [];
|
||||
|
||||
$item_kit_ids = explode(':', $item_kit_ids);
|
||||
foreach($item_kit_ids as $item_kid_id)
|
||||
{
|
||||
// calculate the total cost and retail price of the Kit, so it can be added to the barcode text at the bottom
|
||||
foreach ($item_kit_ids as $item_kid_id) {
|
||||
// Calculate the total cost and retail price of the Kit, so it can be added to the barcode text at the bottom
|
||||
$item_kit = $this->_add_totals_to_item_kit($this->item_kit->get_info($item_kid_id));
|
||||
|
||||
$item_kid_id = 'KIT '. urldecode($item_kid_id);
|
||||
$item_kid_id = 'KIT ' . urldecode($item_kid_id);
|
||||
|
||||
$result[] = [
|
||||
'name' => $item_kit->name,
|
||||
'item_id' => $item_kid_id,
|
||||
'name' => $item_kit->name,
|
||||
'item_id' => $item_kid_id,
|
||||
'item_number' => $item_kid_id,
|
||||
'cost_price' => $item_kit->total_cost_price,
|
||||
'unit_price' => $item_kit->total_unit_price
|
||||
'cost_price' => $item_kit->total_cost_price,
|
||||
'unit_price' => $item_kit->total_unit_price
|
||||
];
|
||||
}
|
||||
|
||||
$data['items'] = $result;
|
||||
$barcode_config = $barcode_lib->get_barcode_config();
|
||||
// in case the selected barcode type is not Code39 or Code128 we set by default Code128
|
||||
// the rationale for this is that EAN codes cannot have strings as seed, so 'KIT ' is not allowed
|
||||
if($barcode_config['barcode_type'] != 'C39' && $barcode_config['barcode_type'] != 'C128')
|
||||
{
|
||||
// In case the selected barcode type is not Code39 or Code128 we set by default Code128
|
||||
// The rationale for this is that EAN codes cannot have strings as seed, so 'KIT ' is not allowed
|
||||
if ($barcode_config['barcode_type'] != 'C39' && $barcode_config['barcode_type'] != 'C128') {
|
||||
$barcode_config['barcode_type'] = 'C128';
|
||||
}
|
||||
$data['barcode_config'] = $barcode_config;
|
||||
|
||||
// display barcodes
|
||||
// Display barcodes
|
||||
echo view("barcodes/barcode_sheet", $data);
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -22,8 +22,7 @@ class Login extends BaseController
|
||||
public function index(): string|RedirectResponse
|
||||
{
|
||||
$this->employee = model(Employee::class);
|
||||
if(!$this->employee->is_logged_in())
|
||||
{
|
||||
if (!$this->employee->is_logged_in()) {
|
||||
$migration = new MY_Migration(config('Migrations'));
|
||||
$config = config(OSPOS::class)->settings;
|
||||
|
||||
@@ -36,36 +35,33 @@ class Login extends BaseController
|
||||
$validation = Services::validation();
|
||||
|
||||
$data = [
|
||||
'has_errors' => false,
|
||||
'is_latest' => $migration->is_latest(),
|
||||
'latest_version' => $migration->get_latest_migration(),
|
||||
'has_errors' => false,
|
||||
'is_latest' => $migration->is_latest(),
|
||||
'latest_version' => $migration->get_latest_migration(),
|
||||
'gcaptcha_enabled' => $gcaptcha_enabled,
|
||||
'config' => $config,
|
||||
'validation' => $validation
|
||||
'config' => $config,
|
||||
'validation' => $validation
|
||||
];
|
||||
|
||||
if($this->request->getMethod() !== 'POST')
|
||||
{
|
||||
if ($this->request->getMethod() !== 'POST') {
|
||||
return view('login', $data);
|
||||
}
|
||||
|
||||
$rules = ['username' => 'required|login_check[data]'];
|
||||
$messages = [
|
||||
'username' => [
|
||||
'required' => lang('Login.required_username'),
|
||||
'required' => lang('Login.required_username'),
|
||||
'login_check' => lang('Login.invalid_username_and_password'),
|
||||
]
|
||||
];
|
||||
|
||||
if(!$this->validate($rules, $messages))
|
||||
{
|
||||
if (!$this->validate($rules, $messages)) {
|
||||
$data['has_errors'] = !empty($validation->getErrors());
|
||||
|
||||
return view('login', $data);
|
||||
}
|
||||
|
||||
if(!$data['is_latest'])
|
||||
{
|
||||
if (!$data['is_latest']) {
|
||||
set_time_limit(3600);
|
||||
|
||||
$migration->setNamespace('App')->latest();
|
||||
|
||||
@@ -34,8 +34,7 @@ class Messages extends Secure_Controller
|
||||
$person = model(Person::class);
|
||||
$info = $person->get_info($person_id);
|
||||
|
||||
foreach(get_object_vars($info) as $property => $value)
|
||||
{
|
||||
foreach (get_object_vars($info) as $property => $value) {
|
||||
$info->$property = $value;
|
||||
}
|
||||
$data['person_info'] = $info;
|
||||
@@ -53,13 +52,10 @@ class Messages extends Secure_Controller
|
||||
|
||||
$response = $this->sms_lib->sendSMS($phone, $message);
|
||||
|
||||
if($response)
|
||||
{
|
||||
echo json_encode (['success' => true, 'message' => lang('Messages.successfully_sent') . ' ' . esc($phone)]);
|
||||
}
|
||||
else
|
||||
{
|
||||
echo json_encode (['success' => false, 'message' => lang('Messages.unsuccessfully_sent') . ' ' . esc($phone)]);
|
||||
if ($response) {
|
||||
echo json_encode(['success' => true, 'message' => lang('Messages.successfully_sent') . ' ' . esc($phone)]);
|
||||
} else {
|
||||
echo json_encode(['success' => false, 'message' => lang('Messages.unsuccessfully_sent') . ' ' . esc($phone)]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,19 +73,16 @@ class Messages extends Secure_Controller
|
||||
|
||||
$response = $this->sms_lib->sendSMS($phone, $message);
|
||||
|
||||
if($response)
|
||||
{
|
||||
echo json_encode ([
|
||||
'success' => true,
|
||||
'message' => lang('Messages.successfully_sent') . ' ' . esc($phone),
|
||||
if ($response) {
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'message' => lang('Messages.successfully_sent') . ' ' . esc($phone),
|
||||
'person_id' => $person_id
|
||||
]);
|
||||
}
|
||||
else
|
||||
{
|
||||
echo json_encode ([
|
||||
'success' => false,
|
||||
'message' => lang('Messages.unsuccessfully_sent') . ' ' . esc($phone),
|
||||
} else {
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'message' => lang('Messages.unsuccessfully_sent') . ' ' . esc($phone),
|
||||
'person_id' => NEW_ENTRY
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -65,7 +65,9 @@ abstract class Persons extends Secure_Controller
|
||||
{
|
||||
$adjusted_name = str_name_case($input);
|
||||
|
||||
//TODO:Use preg_replace to match HTML entities and convert them to lowercase. This is a workaround for https://github.com/tamtamchik/namecase/issues/20
|
||||
return preg_replace_callback('/&[a-zA-Z0-9#]+;/', function($matches) { return strtolower($matches[0]); }, $adjusted_name);
|
||||
// TODO: Use preg_replace to match HTML entities and convert them to lowercase. This is a workaround for https://github.com/tamtamchik/namecase/issues/20
|
||||
return preg_replace_callback('/&[a-zA-Z0-9#]+;/', function ($matches) {
|
||||
return strtolower($matches[0]);
|
||||
}, $adjusted_name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,16 +17,16 @@ use ReflectionException;
|
||||
|
||||
class Receivings extends Secure_Controller
|
||||
{
|
||||
private Receiving_lib $receiving_lib;
|
||||
private Token_lib $token_lib;
|
||||
private Barcode_lib $barcode_lib;
|
||||
private Inventory $inventory;
|
||||
private Item $item;
|
||||
private Item_kit $item_kit;
|
||||
private Receiving $receiving;
|
||||
private Stock_location $stock_location;
|
||||
private Supplier $supplier;
|
||||
private array $config;
|
||||
private Receiving_lib $receiving_lib;
|
||||
private Token_lib $token_lib;
|
||||
private Barcode_lib $barcode_lib;
|
||||
private Inventory $inventory;
|
||||
private Item $item;
|
||||
private Item_kit $item_kit;
|
||||
private Receiving $receiving;
|
||||
private Stock_location $stock_location;
|
||||
private Supplier $supplier;
|
||||
private array $config;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
@@ -92,12 +92,11 @@ class Receivings extends Secure_Controller
|
||||
public function postSelectSupplier(): void
|
||||
{
|
||||
$supplier_id = $this->request->getPost('supplier', FILTER_SANITIZE_NUMBER_INT);
|
||||
if($this->supplier->exists($supplier_id))
|
||||
{
|
||||
if ($this->supplier->exists($supplier_id)) {
|
||||
$this->receiving_lib->set_supplier($supplier_id);
|
||||
}
|
||||
|
||||
$this->_reload(); //TODO: Hungarian notation
|
||||
$this->_reload(); // TODO: Hungarian notation
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -111,20 +110,18 @@ class Receivings extends Secure_Controller
|
||||
$stock_destination = $this->request->getPost('stock_destination', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
|
||||
$stock_source = $this->request->getPost('stock_source', FILTER_SANITIZE_NUMBER_INT);
|
||||
|
||||
if((!$stock_source || $stock_source == $this->receiving_lib->get_stock_source()) &&
|
||||
(!$stock_destination || $stock_destination == $this->receiving_lib->get_stock_destination()))
|
||||
{
|
||||
if ((!$stock_source || $stock_source == $this->receiving_lib->get_stock_source()) &&
|
||||
(!$stock_destination || $stock_destination == $this->receiving_lib->get_stock_destination())
|
||||
) {
|
||||
$this->receiving_lib->clear_reference();
|
||||
$mode = $this->request->getPost('mode', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
|
||||
$this->receiving_lib->set_mode($mode);
|
||||
}
|
||||
elseif($this->stock_location->is_allowed_location($stock_source, 'receivings'))
|
||||
{
|
||||
} elseif ($this->stock_location->is_allowed_location($stock_source, 'receivings')) {
|
||||
$this->receiving_lib->set_stock_source($stock_source);
|
||||
$this->receiving_lib->set_stock_destination($stock_destination);
|
||||
}
|
||||
|
||||
$this->_reload(); //TODO: Hungarian notation
|
||||
$this->_reload(); // TODO: Hungarian notation
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -178,20 +175,15 @@ class Receivings extends Secure_Controller
|
||||
$discount = $this->config['default_receivings_discount'];
|
||||
$discount_type = $this->config['default_receivings_discount_type'];
|
||||
|
||||
if($mode == 'return' && $this->receiving->is_valid_receipt($item_id_or_number_or_item_kit_or_receipt))
|
||||
{
|
||||
if ($mode == 'return' && $this->receiving->is_valid_receipt($item_id_or_number_or_item_kit_or_receipt)) {
|
||||
$this->receiving_lib->return_entire_receiving($item_id_or_number_or_item_kit_or_receipt);
|
||||
}
|
||||
elseif($this->item_kit->is_valid_item_kit($item_id_or_number_or_item_kit_or_receipt))
|
||||
{
|
||||
} elseif ($this->item_kit->is_valid_item_kit($item_id_or_number_or_item_kit_or_receipt)) {
|
||||
$this->receiving_lib->add_item_kit($item_id_or_number_or_item_kit_or_receipt, $item_location, $discount, $discount_type);
|
||||
}
|
||||
elseif(!$this->receiving_lib->add_item($item_id_or_number_or_item_kit_or_receipt, $quantity, $item_location, $discount, $discount_type))
|
||||
{
|
||||
} elseif (!$this->receiving_lib->add_item($item_id_or_number_or_item_kit_or_receipt, $quantity, $item_location, $discount, $discount_type)) {
|
||||
$data['error'] = lang('Receivings.unable_to_add_item');
|
||||
}
|
||||
|
||||
$this->_reload($data); //TODO: Hungarian notation
|
||||
$this->_reload($data); // TODO: Hungarian notation
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -206,7 +198,7 @@ class Receivings extends Secure_Controller
|
||||
$data = [];
|
||||
|
||||
$validation_rule = [
|
||||
'price' => 'trim|required|decimal_locale',
|
||||
'price' => 'trim|required|decimal_locale',
|
||||
'quantity' => 'trim|required|decimal_locale',
|
||||
'discount' => 'trim|permit_empty|decimal_locale',
|
||||
];
|
||||
@@ -215,7 +207,7 @@ class Receivings extends Secure_Controller
|
||||
$quantity = parse_quantity($this->request->getPost('quantity'));
|
||||
$raw_receiving_quantity = parse_quantity($this->request->getPost('receiving_quantity'));
|
||||
|
||||
$description = $this->request->getPost('description', FILTER_SANITIZE_FULL_SPECIAL_CHARS); //TODO: Duplicated code
|
||||
$description = $this->request->getPost('description', FILTER_SANITIZE_FULL_SPECIAL_CHARS); // TODO: Duplicated code
|
||||
$serialnumber = $this->request->getPost('serialnumber', FILTER_SANITIZE_FULL_SPECIAL_CHARS) ?? '';
|
||||
$discount_type = $this->request->getPost('discount_type', FILTER_SANITIZE_NUMBER_INT);
|
||||
$discount = $discount_type
|
||||
@@ -224,16 +216,13 @@ class Receivings extends Secure_Controller
|
||||
|
||||
$receiving_quantity = filter_var($raw_receiving_quantity, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
|
||||
|
||||
if($this->validate($validation_rule))
|
||||
{
|
||||
if ($this->validate($validation_rule)) {
|
||||
$this->receiving_lib->edit_item($item_id, $description, $serialnumber, $quantity, $discount, $discount_type, $price, $receiving_quantity);
|
||||
}
|
||||
else
|
||||
{
|
||||
$data['error']=lang('Receivings.error_editing_item');
|
||||
} else {
|
||||
$data['error'] = lang('Receivings.error_editing_item');
|
||||
}
|
||||
|
||||
$this->_reload($data); //TODO: Hungarian notation
|
||||
$this->_reload($data); // TODO: Hungarian notation
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -248,15 +237,13 @@ class Receivings extends Secure_Controller
|
||||
$data = [];
|
||||
|
||||
$data['suppliers'] = ['' => 'No Supplier'];
|
||||
foreach($this->supplier->get_all()->getResult() as $supplier)
|
||||
{
|
||||
foreach ($this->supplier->get_all()->getResult() as $supplier) {
|
||||
$data['suppliers'][$supplier->person_id] = $supplier->first_name . ' ' . $supplier->last_name;
|
||||
}
|
||||
|
||||
$data['employees'] = [];
|
||||
foreach($this->employee->get_all()->getResult() as $employee)
|
||||
{
|
||||
$data['employees'][$employee->person_id] = $employee->first_name . ' '. $employee->last_name;
|
||||
foreach ($this->employee->get_all()->getResult() as $employee) {
|
||||
$data['employees'][$employee->person_id] = $employee->first_name . ' ' . $employee->last_name;
|
||||
}
|
||||
|
||||
$receiving_info = $this->receiving->get_info($receiving_id)->getRowArray();
|
||||
@@ -278,27 +265,25 @@ class Receivings extends Secure_Controller
|
||||
{
|
||||
$this->receiving_lib->delete_item($item_number);
|
||||
|
||||
$this->_reload(); //TODO: Hungarian notation
|
||||
$this->_reload(); // TODO: Hungarian notation
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function postDelete(int $receiving_id = -1, bool $update_inventory = true) : void
|
||||
public function postDelete(int $receiving_id = -1, bool $update_inventory = true): void
|
||||
{
|
||||
$employee_id = $this->employee->get_logged_in_employee_info()->person_id;
|
||||
$receiving_ids = $receiving_id == -1 ? $this->request->getPost('ids', FILTER_SANITIZE_NUMBER_INT) : [$receiving_id]; //TODO: Replace -1 with constant
|
||||
$receiving_ids = $receiving_id == -1 ? $this->request->getPost('ids', FILTER_SANITIZE_NUMBER_INT) : [$receiving_id]; // TODO: Replace -1 with constant
|
||||
|
||||
if($this->receiving->delete_list($receiving_ids, $employee_id, $update_inventory)) //TODO: Likely need to surround this block of code in a try-catch to catch the ReflectionException
|
||||
{
|
||||
echo json_encode ([
|
||||
if ($this->receiving->delete_list($receiving_ids, $employee_id, $update_inventory)) { // TODO: Likely need to surround this block of code in a try-catch to catch the ReflectionException
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'message' => lang('Receivings.successfully_deleted') . ' ' . count($receiving_ids) . ' ' . lang('Receivings.one_or_multiple'),
|
||||
'ids' => $receiving_ids]);
|
||||
}
|
||||
else
|
||||
{
|
||||
echo json_encode (['success' => false, 'message' => lang('Receivings.cannot_be_deleted')]);
|
||||
'ids' => $receiving_ids
|
||||
]);
|
||||
} else {
|
||||
echo json_encode(['success' => false, 'message' => lang('Receivings.cannot_be_deleted')]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -313,7 +298,7 @@ class Receivings extends Secure_Controller
|
||||
$this->receiving_lib->clear_reference();
|
||||
$this->receiving_lib->remove_supplier();
|
||||
|
||||
$this->_reload(); //TODO: Hungarian notation
|
||||
$this->_reload(); // TODO: Hungarian notation
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -336,8 +321,7 @@ class Receivings extends Secure_Controller
|
||||
$data['payment_type'] = $this->request->getPost('payment_type', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
|
||||
$data['show_stock_locations'] = $this->stock_location->show_locations('receivings');
|
||||
$data['stock_location'] = $this->receiving_lib->get_stock_source();
|
||||
if($this->request->getPost('amount_tendered') != null)
|
||||
{
|
||||
if ($this->request->getPost('amount_tendered') != null) {
|
||||
$data['amount_tendered'] = parse_decimals($this->request->getPost('amount_tendered'));
|
||||
$data['amount_change'] = to_currency($data['amount_tendered'] - $data['total']);
|
||||
}
|
||||
@@ -347,39 +331,32 @@ class Receivings extends Secure_Controller
|
||||
$data['employee'] = $employee_info->first_name . ' ' . $employee_info->last_name;
|
||||
|
||||
$supplier_id = $this->receiving_lib->get_supplier();
|
||||
if($supplier_id != -1)
|
||||
{
|
||||
if ($supplier_id != -1) {
|
||||
$supplier_info = $this->supplier->get_info($supplier_id);
|
||||
$data['supplier'] = $supplier_info->company_name; //TODO: duplicated code
|
||||
$data['supplier'] = $supplier_info->company_name; // TODO: duplicated code
|
||||
$data['first_name'] = $supplier_info->first_name;
|
||||
$data['last_name'] = $supplier_info->last_name;
|
||||
$data['supplier_email'] = $supplier_info->email;
|
||||
$data['supplier_address'] = $supplier_info->address_1;
|
||||
if(!empty($supplier_info->zip) or !empty($supplier_info->city))
|
||||
{
|
||||
if (!empty($supplier_info->zip) or !empty($supplier_info->city)) {
|
||||
$data['supplier_location'] = $supplier_info->zip . ' ' . $supplier_info->city;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$data['supplier_location'] = '';
|
||||
}
|
||||
}
|
||||
|
||||
//SAVE receiving to database
|
||||
// SAVE receiving to database
|
||||
$data['receiving_id'] = 'RECV ' . $this->receiving->save_value($data['cart'], $supplier_id, $employee_id, $data['comment'], $data['reference'], $data['payment_type'], $data['stock_location']);
|
||||
|
||||
if($data['receiving_id'] == 'RECV -1')
|
||||
{
|
||||
if ($data['receiving_id'] == 'RECV -1') {
|
||||
$data['error_message'] = lang('Receivings.transaction_failed');
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$data['barcode'] = $this->barcode_lib->generate_receipt_barcode($data['receiving_id']);
|
||||
}
|
||||
|
||||
$data['print_after_sale'] = $this->receiving_lib->is_print_after_sale();
|
||||
|
||||
echo view("receivings/receipt",$data);
|
||||
echo view("receivings/receipt", $data);
|
||||
|
||||
$this->receiving_lib->clear_all();
|
||||
}
|
||||
@@ -392,22 +369,18 @@ class Receivings extends Secure_Controller
|
||||
*/
|
||||
public function postRequisitionComplete(): void
|
||||
{
|
||||
if($this->receiving_lib->get_stock_source() != $this->receiving_lib->get_stock_destination())
|
||||
{
|
||||
foreach($this->receiving_lib->get_cart() as $item)
|
||||
{
|
||||
if ($this->receiving_lib->get_stock_source() != $this->receiving_lib->get_stock_destination()) {
|
||||
foreach ($this->receiving_lib->get_cart() as $item) {
|
||||
$this->receiving_lib->delete_item($item['line']);
|
||||
$this->receiving_lib->add_item($item['item_id'], $item['quantity'], $this->receiving_lib->get_stock_destination(), $item['discount_type']);
|
||||
$this->receiving_lib->add_item($item['item_id'], -$item['quantity'], $this->receiving_lib->get_stock_source(), $item['discount_type']);
|
||||
}
|
||||
|
||||
$this->postComplete();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$data['error'] = lang('Receivings.error_requisition');
|
||||
|
||||
$this->_reload($data); //TODO: Hungarian notation
|
||||
$this->_reload($data); // TODO: Hungarian notation
|
||||
}
|
||||
}
|
||||
|
||||
@@ -434,21 +407,17 @@ class Receivings extends Secure_Controller
|
||||
$employee_info = $this->employee->get_info($receiving_info['employee_id']);
|
||||
$data['employee'] = $employee_info->first_name . ' ' . $employee_info->last_name;
|
||||
|
||||
$supplier_id = $this->receiving_lib->get_supplier(); //TODO: Duplicated code
|
||||
if($supplier_id != -1)
|
||||
{
|
||||
$supplier_id = $this->receiving_lib->get_supplier(); // TODO: Duplicated code
|
||||
if ($supplier_id != -1) {
|
||||
$supplier_info = $this->supplier->get_info($supplier_id);
|
||||
$data['supplier'] = $supplier_info->company_name;
|
||||
$data['first_name'] = $supplier_info->first_name;
|
||||
$data['last_name'] = $supplier_info->last_name;
|
||||
$data['supplier_email'] = $supplier_info->email;
|
||||
$data['supplier_address'] = $supplier_info->address_1;
|
||||
if(!empty($supplier_info->zip) or !empty($supplier_info->city))
|
||||
{
|
||||
if (!empty($supplier_info->zip) or !empty($supplier_info->city)) {
|
||||
$data['supplier_location'] = $supplier_info->zip . ' ' . $supplier_info->city;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$data['supplier_location'] = '';
|
||||
}
|
||||
}
|
||||
@@ -464,15 +433,14 @@ class Receivings extends Secure_Controller
|
||||
* @param array $data
|
||||
* @return void
|
||||
*/
|
||||
private function _reload(array $data = []): void //TODO: Hungarian notation
|
||||
private function _reload(array $data = []): void // TODO: Hungarian notation
|
||||
{
|
||||
$data['cart'] = $this->receiving_lib->get_cart();
|
||||
$data['modes'] = ['receive' => lang('Receivings.receiving'), 'return' => lang('Receivings.return')];
|
||||
$data['mode'] = $this->receiving_lib->get_mode();
|
||||
$data['stock_locations'] = $this->stock_location->get_allowed_locations('receivings');
|
||||
$data['show_stock_locations'] = count($data['stock_locations']) > 1;
|
||||
if($data['show_stock_locations'])
|
||||
{
|
||||
if ($data['show_stock_locations']) {
|
||||
$data['modes']['requisition'] = lang('Receivings.requisition');
|
||||
$data['stock_source'] = $this->receiving_lib->get_stock_source();
|
||||
$data['stock_destination'] = $this->receiving_lib->get_stock_destination();
|
||||
@@ -486,20 +454,16 @@ class Receivings extends Secure_Controller
|
||||
|
||||
$supplier_id = $this->receiving_lib->get_supplier();
|
||||
|
||||
if($supplier_id != -1) //TODO: Duplicated Code... replace -1 with a constant
|
||||
{
|
||||
if ($supplier_id != -1) { // TODO: Duplicated Code... replace -1 with a constant
|
||||
$supplier_info = $this->supplier->get_info($supplier_id);
|
||||
$data['supplier'] = $supplier_info->company_name;
|
||||
$data['first_name'] = $supplier_info->first_name;
|
||||
$data['last_name'] = $supplier_info->last_name;
|
||||
$data['supplier_email'] = $supplier_info->email;
|
||||
$data['supplier_address'] = $supplier_info->address_1;
|
||||
if(!empty($supplier_info->zip) or !empty($supplier_info->city))
|
||||
{
|
||||
if (!empty($supplier_info->zip) or !empty($supplier_info->city)) {
|
||||
$data['supplier_location'] = $supplier_info->zip . ' ' . $supplier_info->city;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$data['supplier_location'] = '';
|
||||
}
|
||||
}
|
||||
@@ -512,36 +476,33 @@ class Receivings extends Secure_Controller
|
||||
/**
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function postSave(int $receiving_id = -1): void //TODO: Replace -1 with a constant
|
||||
public function postSave(int $receiving_id = -1): void // TODO: Replace -1 with a constant
|
||||
{
|
||||
$newdate = $this->request->getPost('date', FILTER_SANITIZE_FULL_SPECIAL_CHARS); //TODO: newdate does not follow naming conventions
|
||||
$newdate = $this->request->getPost('date', FILTER_SANITIZE_FULL_SPECIAL_CHARS); // TODO: newdate does not follow naming conventions
|
||||
|
||||
$date_formatter = date_create_from_format($this->config['dateformat'] . ' ' . $this->config['timeformat'], $newdate);
|
||||
$receiving_time = $date_formatter->format('Y-m-d H:i:s');
|
||||
|
||||
$receiving_data = [
|
||||
'receiving_time' => $receiving_time,
|
||||
'supplier_id' => $this->request->getPost('supplier_id') ? $this->request->getPost('supplier_id', FILTER_SANITIZE_NUMBER_INT) : null,
|
||||
'employee_id' => $this->request->getPost('employee_id', FILTER_SANITIZE_NUMBER_INT),
|
||||
'comment' => $this->request->getPost('comment', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
|
||||
'reference' => $this->request->getPost('reference') != '' ? $this->request->getPost('reference', FILTER_SANITIZE_FULL_SPECIAL_CHARS) : null
|
||||
'supplier_id' => $this->request->getPost('supplier_id') ? $this->request->getPost('supplier_id', FILTER_SANITIZE_NUMBER_INT) : null,
|
||||
'employee_id' => $this->request->getPost('employee_id', FILTER_SANITIZE_NUMBER_INT),
|
||||
'comment' => $this->request->getPost('comment', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
|
||||
'reference' => $this->request->getPost('reference') != '' ? $this->request->getPost('reference', FILTER_SANITIZE_FULL_SPECIAL_CHARS) : null
|
||||
];
|
||||
|
||||
$this->inventory->update('RECV '.$receiving_id, ['trans_date' => $receiving_time]);
|
||||
if($this->receiving->update($receiving_id, $receiving_data))
|
||||
{
|
||||
echo json_encode ([
|
||||
$this->inventory->update('RECV ' . $receiving_id, ['trans_date' => $receiving_time]);
|
||||
if ($this->receiving->update($receiving_id, $receiving_data)) {
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'message' => lang('Receivings.successfully_updated'),
|
||||
'id' => $receiving_id
|
||||
'id' => $receiving_id
|
||||
]);
|
||||
}
|
||||
else
|
||||
{
|
||||
echo json_encode ([
|
||||
} else {
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'message' => lang('Receivings.unsuccessfully_updated'),
|
||||
'id' => $receiving_id
|
||||
'id' => $receiving_id
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -556,6 +517,6 @@ class Receivings extends Secure_Controller
|
||||
{
|
||||
$this->receiving_lib->clear_all();
|
||||
|
||||
$this->_reload(); //TODO: Hungarian Notation
|
||||
$this->_reload(); // TODO: Hungarian Notation
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -39,28 +39,25 @@ class Secure_Controller extends BaseController
|
||||
$config = config(OSPOS::class)->settings;
|
||||
$validation = Services::validation();
|
||||
|
||||
if(!$this->employee->is_logged_in())
|
||||
{
|
||||
header("Location:".base_url('login'));
|
||||
if (!$this->employee->is_logged_in()) {
|
||||
header("Location:" . base_url('login'));
|
||||
exit();
|
||||
}
|
||||
|
||||
$logged_in_employee_info = $this->employee->get_logged_in_employee_info();
|
||||
if(!$this->employee->has_module_grant($module_id, $logged_in_employee_info->person_id)
|
||||
|| (isset($submodule_id) && !$this->employee->has_module_grant($submodule_id, $logged_in_employee_info->person_id)))
|
||||
{
|
||||
header("Location:".base_url("no_access/$module_id/$submodule_id"));
|
||||
if (
|
||||
!$this->employee->has_module_grant($module_id, $logged_in_employee_info->person_id)
|
||||
|| (isset($submodule_id) && !$this->employee->has_module_grant($submodule_id, $logged_in_employee_info->person_id))
|
||||
) {
|
||||
header("Location:" . base_url("no_access/$module_id/$submodule_id"));
|
||||
exit();
|
||||
}
|
||||
|
||||
// load up global global_view_data visible to all the loaded views
|
||||
// Load up global global_view_data visible to all the loaded views
|
||||
$this->session = session();
|
||||
if($menu_group == null)
|
||||
{
|
||||
if ($menu_group == null) {
|
||||
$menu_group = $this->session->get('menu_group');
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$this->session->set('menu_group', $menu_group);
|
||||
}
|
||||
|
||||
@@ -69,15 +66,14 @@ class Secure_Controller extends BaseController
|
||||
: $this->module->get_allowed_office_modules($logged_in_employee_info->person_id);
|
||||
|
||||
$this->global_view_data = [];
|
||||
foreach($allowed_modules->getResult() as $module)
|
||||
{
|
||||
foreach ($allowed_modules->getResult() as $module) {
|
||||
$this->global_view_data['allowed_modules'][] = $module;
|
||||
}
|
||||
|
||||
$this->global_view_data += [
|
||||
'user_info' => $logged_in_employee_info,
|
||||
'user_info' => $logged_in_employee_info,
|
||||
'controller_name' => $module_id,
|
||||
'config' => $config
|
||||
'config' => $config
|
||||
];
|
||||
view('viewData', $this->global_view_data);
|
||||
}
|
||||
@@ -94,10 +90,8 @@ class Secure_Controller extends BaseController
|
||||
*/
|
||||
public function getCheckNumeric(): void
|
||||
{
|
||||
foreach($this->request->getGet() as $value)
|
||||
{
|
||||
if (parse_decimals($value) === false)
|
||||
{
|
||||
foreach ($this->request->getGet() as $value) {
|
||||
if (parse_decimals($value) === false) {
|
||||
echo 'false';
|
||||
return;
|
||||
}
|
||||
@@ -111,8 +105,7 @@ class Secure_Controller extends BaseController
|
||||
*/
|
||||
public function getConfig($key)
|
||||
{
|
||||
if (isset($config[$key]))
|
||||
{
|
||||
if (isset($config[$key])) {
|
||||
return $config[$key];
|
||||
}
|
||||
}
|
||||
@@ -120,32 +113,50 @@ class Secure_Controller extends BaseController
|
||||
/**
|
||||
* @return false
|
||||
*/
|
||||
public function getIndex() { return false; }
|
||||
public function getIndex()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return false
|
||||
*/
|
||||
public function getSearch() { return false; }
|
||||
public function getSearch()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return false
|
||||
*/
|
||||
public function suggest_search() { return false; }
|
||||
public function suggest_search()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $data_item_id
|
||||
* @return false
|
||||
*/
|
||||
public function getView(int $data_item_id = -1) { return false; }
|
||||
public function getView(int $data_item_id = -1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $data_item_id
|
||||
* @return false
|
||||
*/
|
||||
public function postSave(int $data_item_id = -1) { return false; }
|
||||
public function postSave(int $data_item_id = -1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return false
|
||||
*/
|
||||
public function postDelete() { return false; }
|
||||
public function postDelete()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,14 +56,13 @@ class Suppliers extends Persons
|
||||
|
||||
$data_rows = [];
|
||||
|
||||
foreach($suppliers->getResult() as $supplier)
|
||||
{
|
||||
foreach ($suppliers->getResult() as $supplier) {
|
||||
$row = get_supplier_data_row($supplier);
|
||||
$row['category'] = $this->supplier->get_category_name($row['category']);
|
||||
$data_rows[] = $row;
|
||||
}
|
||||
|
||||
echo json_encode (['total' => $total_rows, 'rows' => $data_rows]);
|
||||
echo json_encode(['total' => $total_rows, 'rows' => $data_rows]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -97,8 +96,7 @@ class Suppliers extends Persons
|
||||
public function getView(int $supplier_id = NEW_ENTRY): void
|
||||
{
|
||||
$info = $this->supplier->get_info($supplier_id);
|
||||
foreach(get_object_vars($info) as $property => $value)
|
||||
{
|
||||
foreach (get_object_vars($info) as $property => $value) {
|
||||
$info->$property = $value;
|
||||
}
|
||||
$data['person_info'] = $info;
|
||||
@@ -115,62 +113,58 @@ class Suppliers extends Persons
|
||||
*/
|
||||
public function postSave(int $supplier_id = NEW_ENTRY): void
|
||||
{
|
||||
$first_name = $this->request->getPost('first_name', FILTER_SANITIZE_FULL_SPECIAL_CHARS); //TODO: Duplicate code
|
||||
$first_name = $this->request->getPost('first_name', FILTER_SANITIZE_FULL_SPECIAL_CHARS); // TODO: Duplicate code
|
||||
$last_name = $this->request->getPost('last_name', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
|
||||
$email = strtolower($this->request->getPost('email', FILTER_SANITIZE_EMAIL));
|
||||
|
||||
// format first and last name properly
|
||||
// Format first and last name properly
|
||||
$first_name = $this->nameize($first_name);
|
||||
$last_name = $this->nameize($last_name);
|
||||
|
||||
$person_data = [
|
||||
'first_name' => $first_name,
|
||||
'last_name' => $last_name,
|
||||
'gender' => $this->request->getPost('gender'),
|
||||
'email' => $email,
|
||||
'first_name' => $first_name,
|
||||
'last_name' => $last_name,
|
||||
'gender' => $this->request->getPost('gender'),
|
||||
'email' => $email,
|
||||
'phone_number' => $this->request->getPost('phone_number', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
|
||||
'address_1' => $this->request->getPost('address_1', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
|
||||
'address_2' => $this->request->getPost('address_2', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
|
||||
'city' => $this->request->getPost('city', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
|
||||
'state' => $this->request->getPost('state', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
|
||||
'zip' => $this->request->getPost('zip', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
|
||||
'country' => $this->request->getPost('country', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
|
||||
'comments' => $this->request->getPost('comments', FILTER_SANITIZE_FULL_SPECIAL_CHARS)
|
||||
'address_1' => $this->request->getPost('address_1', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
|
||||
'address_2' => $this->request->getPost('address_2', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
|
||||
'city' => $this->request->getPost('city', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
|
||||
'state' => $this->request->getPost('state', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
|
||||
'zip' => $this->request->getPost('zip', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
|
||||
'country' => $this->request->getPost('country', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
|
||||
'comments' => $this->request->getPost('comments', FILTER_SANITIZE_FULL_SPECIAL_CHARS)
|
||||
];
|
||||
|
||||
$supplier_data = [
|
||||
'company_name' => $this->request->getPost('company_name', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
|
||||
'agency_name' => $this->request->getPost('agency_name', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
|
||||
'category' => $this->request->getPost('category', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
|
||||
'company_name' => $this->request->getPost('company_name', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
|
||||
'agency_name' => $this->request->getPost('agency_name', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
|
||||
'category' => $this->request->getPost('category', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
|
||||
'account_number' => $this->request->getPost('account_number') == '' ? null : $this->request->getPost('account_number', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
|
||||
'tax_id' => $this->request->getPost('tax_id', FILTER_SANITIZE_NUMBER_INT)
|
||||
'tax_id' => $this->request->getPost('tax_id', FILTER_SANITIZE_NUMBER_INT)
|
||||
];
|
||||
|
||||
if($this->supplier->save_supplier($person_data, $supplier_data, $supplier_id))
|
||||
{
|
||||
//New supplier
|
||||
if($supplier_id == NEW_ENTRY)
|
||||
{
|
||||
echo json_encode ([
|
||||
if ($this->supplier->save_supplier($person_data, $supplier_data, $supplier_id)) {
|
||||
// New supplier
|
||||
if ($supplier_id == NEW_ENTRY) {
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'message' => lang('Suppliers.successful_adding') . ' ' . $supplier_data['company_name'],
|
||||
'id' => $supplier_data['person_id']
|
||||
'id' => $supplier_data['person_id']
|
||||
]);
|
||||
}
|
||||
else //Existing supplier
|
||||
{
|
||||
echo json_encode ([
|
||||
} else { // Existing supplier
|
||||
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'message' => lang('Suppliers.successful_updating') . ' ' . $supplier_data['company_name'],
|
||||
'id' => $supplier_id]);
|
||||
'id' => $supplier_id
|
||||
]);
|
||||
}
|
||||
}
|
||||
else//failure
|
||||
{
|
||||
echo json_encode ([
|
||||
} else { // Failure
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'message' => lang('Suppliers.error_adding_updating') . ' ' . $supplier_data['company_name'],
|
||||
'id' => NEW_ENTRY
|
||||
'id' => NEW_ENTRY
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -184,16 +178,13 @@ class Suppliers extends Persons
|
||||
{
|
||||
$suppliers_to_delete = $this->request->getPost('ids', FILTER_SANITIZE_NUMBER_INT);
|
||||
|
||||
if($this->supplier->delete_list($suppliers_to_delete))
|
||||
{
|
||||
echo json_encode ([
|
||||
if ($this->supplier->delete_list($suppliers_to_delete)) {
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'message' => lang('Suppliers.successful_deleted') . ' ' . count($suppliers_to_delete) . ' ' . lang('Suppliers.one_or_multiple')
|
||||
]);
|
||||
}
|
||||
else
|
||||
{
|
||||
echo json_encode (['success' => false, 'message' => lang('Suppliers.cannot_be_deleted')]);
|
||||
} else {
|
||||
echo json_encode(['success' => false, 'message' => lang('Suppliers.cannot_be_deleted')]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,9 +24,9 @@ class Tax_categories extends Secure_Controller
|
||||
*/
|
||||
public function getIndex(): void
|
||||
{
|
||||
$data['tax_categories_table_headers'] = get_tax_categories_table_headers();
|
||||
$data['tax_categories_table_headers'] = get_tax_categories_table_headers();
|
||||
|
||||
echo view('taxes/tax_categories', $data);
|
||||
echo view('taxes/tax_categories', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -46,12 +46,11 @@ class Tax_categories extends Secure_Controller
|
||||
$total_rows = $this->tax_category->get_found_rows($search);
|
||||
|
||||
$data_rows = [];
|
||||
foreach($tax_categories->getResult() as $tax_category)
|
||||
{
|
||||
foreach ($tax_categories->getResult() as $tax_category) {
|
||||
$data_rows[] = get_tax_categories_data_row($tax_category);
|
||||
}
|
||||
|
||||
echo json_encode (['total' => $total_rows, 'rows' => $data_rows]);
|
||||
echo json_encode(['total' => $total_rows, 'rows' => $data_rows]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -84,37 +83,31 @@ class Tax_categories extends Secure_Controller
|
||||
public function postSave(int $tax_category_id = NEW_ENTRY): void
|
||||
{
|
||||
$tax_category_data = [
|
||||
'tax_category' => $this->request->getPost('tax_category', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
|
||||
'tax_category_code' => $this->request->getPost('tax_category_code', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
|
||||
'tax_category' => $this->request->getPost('tax_category', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
|
||||
'tax_category_code' => $this->request->getPost('tax_category_code', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
|
||||
'tax_group_sequence' => $this->request->getPost('tax_group_sequence', FILTER_SANITIZE_NUMBER_INT)
|
||||
];
|
||||
|
||||
if($this->tax_category->save_value($tax_category_data, $tax_category_id))
|
||||
{
|
||||
if ($this->tax_category->save_value($tax_category_data, $tax_category_id)) {
|
||||
// New tax_category_id
|
||||
if($tax_category_id == NEW_ENTRY)
|
||||
{
|
||||
echo json_encode ([
|
||||
if ($tax_category_id == NEW_ENTRY) {
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'message' => lang('Tax_categories.successful_adding'),
|
||||
'id' => $tax_category_data['tax_category_id']
|
||||
'id' => $tax_category_data['tax_category_id']
|
||||
]);
|
||||
}
|
||||
else
|
||||
{
|
||||
echo json_encode ([
|
||||
} else {
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'message' => lang('Tax_categories.successful_updating'),
|
||||
'id' => $tax_category_id
|
||||
'id' => $tax_category_id
|
||||
]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
echo json_encode ([
|
||||
} else {
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'message' => lang('Tax_categories.error_adding_updating') . ' ' . $tax_category_data['tax_category'],
|
||||
'id' => NEW_ENTRY
|
||||
'id' => NEW_ENTRY
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -126,16 +119,13 @@ class Tax_categories extends Secure_Controller
|
||||
{
|
||||
$tax_categories_to_delete = $this->request->getPost('ids', FILTER_SANITIZE_NUMBER_INT);
|
||||
|
||||
if($this->tax_category->delete_list($tax_categories_to_delete))
|
||||
{
|
||||
echo json_encode ([
|
||||
if ($this->tax_category->delete_list($tax_categories_to_delete)) {
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'message' => lang('Tax_categories.successful_deleted') . ' ' . count($tax_categories_to_delete) . ' ' . lang('Tax_categories.one_or_multiple')
|
||||
]);
|
||||
}
|
||||
else
|
||||
{
|
||||
echo json_encode (['success' => false, 'message' => lang('Tax_categories.cannot_be_deleted')]);
|
||||
} else {
|
||||
echo json_encode(['success' => false, 'message' => lang('Tax_categories.cannot_be_deleted')]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ class Tax_codes extends Secure_Controller
|
||||
*/
|
||||
public function getIndex(): void
|
||||
{
|
||||
echo view('taxes/tax_codes', $this->get_data());
|
||||
echo view('taxes/tax_codes', $this->get_data());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -57,12 +57,11 @@ class Tax_codes extends Secure_Controller
|
||||
|
||||
$data_rows = [];
|
||||
|
||||
foreach($tax_codes->getResult() as $tax_code)
|
||||
{
|
||||
foreach ($tax_codes->getResult() as $tax_code) {
|
||||
$data_rows[] = get_tax_code_data_row($tax_code);
|
||||
}
|
||||
|
||||
echo json_encode (['total' => $total_rows, 'rows' => $data_rows]);
|
||||
echo json_encode(['total' => $total_rows, 'rows' => $data_rows]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -95,37 +94,31 @@ class Tax_codes extends Secure_Controller
|
||||
public function postSave(int $tax_code_id = NEW_ENTRY): void
|
||||
{
|
||||
$tax_code_data = [
|
||||
'tax_code' => $this->request->getPost('tax_code', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
|
||||
'tax_code' => $this->request->getPost('tax_code', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
|
||||
'tax_code_name' => $this->request->getPost('tax_code_name', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
|
||||
'city' => $this->request->getPost('city', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
|
||||
'state' => $this->request->getPost('state', FILTER_SANITIZE_FULL_SPECIAL_CHARS)
|
||||
'city' => $this->request->getPost('city', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
|
||||
'state' => $this->request->getPost('state', FILTER_SANITIZE_FULL_SPECIAL_CHARS)
|
||||
];
|
||||
|
||||
if($this->tax_code->save($tax_code_data))
|
||||
{
|
||||
if($tax_code_id == NEW_ENTRY)
|
||||
{
|
||||
echo json_encode ([
|
||||
if ($this->tax_code->save($tax_code_data)) {
|
||||
if ($tax_code_id == NEW_ENTRY) {
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'message' => lang('Tax_codes.successful_adding'),
|
||||
'id' => $tax_code_data['tax_code_id']
|
||||
'id' => $tax_code_data['tax_code_id']
|
||||
]);
|
||||
}
|
||||
else
|
||||
{
|
||||
echo json_encode ([
|
||||
} else {
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'message' => lang('Tax_codes.successful_updating'),
|
||||
'id' => $tax_code_id
|
||||
'id' => $tax_code_id
|
||||
]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
echo json_encode ([
|
||||
} else {
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'message' => lang('Tax_codes.error_adding_updating') . ' ' . $tax_code_data['tax_code_id'],
|
||||
'id' => NEW_ENTRY
|
||||
'id' => NEW_ENTRY
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -137,16 +130,13 @@ class Tax_codes extends Secure_Controller
|
||||
{
|
||||
$tax_codes_to_delete = $this->request->getPost('ids', FILTER_SANITIZE_NUMBER_INT);
|
||||
|
||||
if($this->tax_code->delete_list($tax_codes_to_delete))
|
||||
{
|
||||
echo json_encode ([
|
||||
if ($this->tax_code->delete_list($tax_codes_to_delete)) {
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'message' => lang('Tax_codes.successful_deleted') . ' ' . count($tax_codes_to_delete) . ' ' . lang('Tax_codes.one_or_multiple')
|
||||
]);
|
||||
}
|
||||
else
|
||||
{
|
||||
echo json_encode (['success' => false, 'message' => lang('Tax_codes.cannot_be_deleted')]);
|
||||
} else {
|
||||
echo json_encode(['success' => false, 'message' => lang('Tax_codes.cannot_be_deleted')]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,9 +27,9 @@ class Tax_jurisdictions extends Secure_Controller
|
||||
*/
|
||||
public function getIndex(): void
|
||||
{
|
||||
$data['table_headers'] = get_tax_jurisdictions_table_headers();
|
||||
$data['table_headers'] = get_tax_jurisdictions_table_headers();
|
||||
|
||||
echo view('taxes/tax_jurisdictions', $data);
|
||||
echo view('taxes/tax_jurisdictions', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -49,12 +49,11 @@ class Tax_jurisdictions extends Secure_Controller
|
||||
$total_rows = $this->tax_jurisdiction->get_found_rows($search);
|
||||
|
||||
$data_rows = [];
|
||||
foreach($tax_jurisdictions->getResult() as $tax_jurisdiction)
|
||||
{
|
||||
foreach ($tax_jurisdictions->getResult() as $tax_jurisdiction) {
|
||||
$data_rows[] = get_tax_jurisdictions_data_row($tax_jurisdiction);
|
||||
}
|
||||
|
||||
echo json_encode (['total' => $total_rows, 'rows' => $data_rows]);
|
||||
echo json_encode(['total' => $total_rows, 'rows' => $data_rows]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -87,35 +86,29 @@ class Tax_jurisdictions extends Secure_Controller
|
||||
public function postSave(int $jurisdiction_id = NEW_ENTRY): void
|
||||
{
|
||||
$tax_jurisdiction_data = [
|
||||
'jurisdiction_name' => $this->request->getPost('jurisdiction_name', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
|
||||
'jurisdiction_name' => $this->request->getPost('jurisdiction_name', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
|
||||
'reporting_authority' => $this->request->getPost('reporting_authority', FILTER_SANITIZE_FULL_SPECIAL_CHARS)
|
||||
];
|
||||
|
||||
if($this->tax_jurisdiction->save_value($tax_jurisdiction_data))
|
||||
{
|
||||
if($jurisdiction_id == NEW_ENTRY)
|
||||
{
|
||||
echo json_encode ([
|
||||
if ($this->tax_jurisdiction->save_value($tax_jurisdiction_data)) {
|
||||
if ($jurisdiction_id == NEW_ENTRY) {
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'message' => lang('Tax_jurisdictions.successful_adding'),
|
||||
'id' => $tax_jurisdiction_data['jurisdiction_id']
|
||||
'id' => $tax_jurisdiction_data['jurisdiction_id']
|
||||
]);
|
||||
}
|
||||
else
|
||||
{
|
||||
echo json_encode ([
|
||||
} else {
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'message' => lang('Tax_jurisdictions.successful_updating'),
|
||||
'id' => $jurisdiction_id
|
||||
'id' => $jurisdiction_id
|
||||
]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
echo json_encode ([
|
||||
} else {
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'message' => lang('Tax_jurisdictions.error_adding_updating') . ' ' . $tax_jurisdiction_data['jurisdiction_name'],
|
||||
'id' => NEW_ENTRY
|
||||
'id' => NEW_ENTRY
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -127,16 +120,13 @@ class Tax_jurisdictions extends Secure_Controller
|
||||
{
|
||||
$tax_jurisdictions_to_delete = $this->request->getPost('ids', FILTER_SANITIZE_NUMBER_INT);
|
||||
|
||||
if($this->tax_jurisdiction->delete_list($tax_jurisdictions_to_delete))
|
||||
{
|
||||
echo json_encode ([
|
||||
if ($this->tax_jurisdiction->delete_list($tax_jurisdictions_to_delete)) {
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'message' => lang('Tax_jurisdictions.successful_deleted') . ' ' . count($tax_jurisdictions_to_delete) . ' ' . lang('Tax_jurisdictions.one_or_multiple')
|
||||
]);
|
||||
}
|
||||
else
|
||||
{
|
||||
echo json_encode (['success' => false, 'message' => lang('Tax_jurisdictions.cannot_be_deleted')]);
|
||||
} else {
|
||||
echo json_encode(['success' => false, 'message' => lang('Tax_jurisdictions.cannot_be_deleted')]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,20 +41,17 @@ class Taxes extends Secure_Controller
|
||||
public function getIndex(): void
|
||||
{
|
||||
$data['tax_codes'] = $this->tax_code->get_all()->getResultArray();
|
||||
if (count($data['tax_codes']) == 0)
|
||||
{
|
||||
if (count($data['tax_codes']) == 0) {
|
||||
$data['tax_codes'] = $this->tax_code->get_empty_row();
|
||||
}
|
||||
|
||||
$data['tax_categories'] = $this->tax_category->get_all()->getResultArray();
|
||||
if (count($data['tax_categories']) == 0)
|
||||
{
|
||||
if (count($data['tax_categories']) == 0) {
|
||||
$data['tax_categories'] = $this->tax_category->get_empty_row();
|
||||
}
|
||||
|
||||
$data['tax_jurisdictions'] = $this->tax_jurisdiction->get_all()->getResultArray();
|
||||
if (count($data['tax_jurisdictions']) == 0)
|
||||
{
|
||||
if (count($data['tax_jurisdictions']) == 0) {
|
||||
$data['tax_jurisdictions'] = $this->tax_jurisdiction->get_empty_row();
|
||||
}
|
||||
|
||||
@@ -62,12 +59,9 @@ class Taxes extends Secure_Controller
|
||||
$data['tax_categories_table_headers'] = get_tax_categories_table_headers();
|
||||
$data['tax_types'] = $this->tax_lib->get_tax_types();
|
||||
|
||||
if($this->config['tax_included'])
|
||||
{
|
||||
if ($this->config['tax_included']) {
|
||||
$data['default_tax_type'] = Tax_lib::TAX_TYPE_INCLUDED;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$data['default_tax_type'] = Tax_lib::TAX_TYPE_EXCLUDED;
|
||||
}
|
||||
|
||||
@@ -94,12 +88,11 @@ class Taxes extends Secure_Controller
|
||||
$total_rows = $this->tax->get_found_rows($search);
|
||||
|
||||
$data_rows = [];
|
||||
foreach($tax_rates->getResult() as $tax_rate_row)
|
||||
{
|
||||
foreach ($tax_rates->getResult() as $tax_rate_row) {
|
||||
$data_rows[] = get_tax_rates_data_row($tax_rate_row);
|
||||
}
|
||||
|
||||
echo json_encode (['total' => $total_rows, 'rows' => $data_rows]);
|
||||
echo json_encode(['total' => $total_rows, 'rows' => $data_rows]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -108,7 +101,7 @@ class Taxes extends Secure_Controller
|
||||
public function suggest_search(): void
|
||||
{
|
||||
$search = $this->request->getPost('term');
|
||||
$suggestions = $this->tax->get_search_suggestions($search); //TODO: There is no get_search_suggestions function in the tax model
|
||||
$suggestions = $this->tax->get_search_suggestions($search); // TODO: There is no get_search_suggestions function in the tax model
|
||||
|
||||
echo json_encode($suggestions);
|
||||
}
|
||||
@@ -146,25 +139,21 @@ class Taxes extends Secure_Controller
|
||||
{
|
||||
$tax_code_info = $this->tax->get_info($tax_code);
|
||||
|
||||
$default_tax_category_id = 1; // Tax category id is always the default tax category //TODO: Replace 1 with constant
|
||||
$default_tax_category = $this->tax->get_tax_category($default_tax_category_id); //TODO: this variable is never used in the code.
|
||||
$default_tax_category_id = 1; // Tax category id is always the default tax category // TODO: Replace 1 with constant
|
||||
$default_tax_category = $this->tax->get_tax_category($default_tax_category_id); // TODO: this variable is never used in the code.
|
||||
|
||||
$tax_rate_info = $this->tax->get_rate_info($tax_code, $default_tax_category_id);
|
||||
|
||||
if($this->config['tax_included'])
|
||||
{
|
||||
if ($this->config['tax_included']) {
|
||||
$data['default_tax_type'] = Tax_lib::TAX_TYPE_INCLUDED;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$data['default_tax_type'] = Tax_lib::TAX_TYPE_EXCLUDED;
|
||||
}
|
||||
|
||||
$data['rounding_options'] = rounding_mode::get_rounding_options();
|
||||
$data['html_rounding_options'] = $this->get_html_rounding_options();
|
||||
|
||||
if($tax_code == NEW_ENTRY)
|
||||
{//TODO: Duplicated code
|
||||
if ($tax_code == NEW_ENTRY) { // TODO: Duplicated code
|
||||
$data['tax_code'] = '';
|
||||
$data['tax_code_name'] = '';
|
||||
$data['tax_code_type'] = '0';
|
||||
@@ -176,9 +165,7 @@ class Taxes extends Secure_Controller
|
||||
$data['tax_category'] = '';
|
||||
$data['add_tax_category'] = '';
|
||||
$data['rounding_code'] = '0';
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$data['tax_code'] = $tax_code;
|
||||
$data['tax_code_name'] = $tax_code_info->tax_code_name;
|
||||
$data['tax_code_type'] = $tax_code_info->tax_code_type;
|
||||
@@ -193,8 +180,7 @@ class Taxes extends Secure_Controller
|
||||
}
|
||||
|
||||
$tax_rates = [];
|
||||
foreach($this->tax->get_tax_code_rate_exceptions($tax_code) as $tax_code_rate) //TODO: get_tax_code_rate_exceptions doesn't exist. This was deleted by @steveireland in https://github.com/opensourcepos/opensourcepos/commit/32204698379c230f2a6756655f40334308023de9#diff-e746bab6720cf5dbf855de6cda68f7aca9ecea7ddd5a39bb852e9b9047a7a838L435 but it's unclear if that was on purpose or accidental.
|
||||
{
|
||||
foreach ($this->tax->get_tax_code_rate_exceptions($tax_code) as $tax_code_rate) { // TODO: get_tax_code_rate_exceptions doesn't exist. This was deleted by @steveireland in https://github.com/opensourcepos/opensourcepos/commit/32204698379c230f2a6756655f40334308023de9#diff-e746bab6720cf5dbf855de6cda68f7aca9ecea7ddd5a39bb852e9b9047a7a838L435 but it's unclear if that was on purpose or accidental.
|
||||
$tax_rate_row = [];
|
||||
$tax_rate_row['rate_tax_category_id'] = $tax_code_rate['rate_tax_category_id'];
|
||||
$tax_rate_row['tax_category'] = $tax_code_rate['tax_category'];
|
||||
@@ -225,16 +211,13 @@ class Taxes extends Secure_Controller
|
||||
$data['tax_category_options'] = $this->tax_lib->get_tax_category_options();
|
||||
$data['tax_jurisdiction_options'] = $this->tax_lib->get_tax_jurisdiction_options();
|
||||
|
||||
if($tax_rate_id == NEW_ENTRY)
|
||||
{
|
||||
if ($tax_rate_id == NEW_ENTRY) {
|
||||
$data['rate_tax_code_id'] = $this->config['default_tax_code'];
|
||||
$data['rate_tax_category_id'] = $this->config['default_tax_category'];
|
||||
$data['rate_jurisdiction_id'] = $this->config['default_tax_jurisdiction'];
|
||||
$data['tax_rounding_code'] = rounding_mode::HALF_UP;
|
||||
$data['tax_rate'] = '0.0000';
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$data['rate_tax_code_id'] = $tax_rate_info->rate_tax_code_id;
|
||||
$data['rate_tax_code'] = $tax_rate_info->tax_code;
|
||||
$data['rate_tax_category_id'] = $tax_rate_info->rate_tax_category_id;
|
||||
@@ -250,11 +233,11 @@ class Taxes extends Secure_Controller
|
||||
* @param int $tax_code
|
||||
* @return void
|
||||
*/
|
||||
public function getView_tax_categories(int $tax_code = NEW_ENTRY): void //TODO: This appears to be called no where in the code.
|
||||
public function getView_tax_categories(int $tax_code = NEW_ENTRY): void // TODO: This appears to be called no where in the code.
|
||||
{
|
||||
$tax_code_info = $this->tax->get_info($tax_code); //TODO: Duplicated Code
|
||||
$tax_code_info = $this->tax->get_info($tax_code); // TODO: Duplicated Code
|
||||
|
||||
$default_tax_category_id = 1; // Tax category id is always the default tax category //TODO: replace with a constant.
|
||||
$default_tax_category_id = 1; // Tax category id is always the default tax category // TODO: replace with a constant.
|
||||
$default_tax_category = $this->tax->get_tax_category($default_tax_category_id);
|
||||
|
||||
$tax_rate_info = $this->tax->get_rate_info($tax_code, $default_tax_category_id);
|
||||
@@ -262,17 +245,13 @@ class Taxes extends Secure_Controller
|
||||
$data['rounding_options'] = rounding_mode::get_rounding_options();
|
||||
$data['html_rounding_options'] = $this->get_html_rounding_options();
|
||||
|
||||
if($this->config['tax_included'])
|
||||
{
|
||||
if ($this->config['tax_included']) {
|
||||
$data['default_tax_type'] = Tax_lib::TAX_TYPE_INCLUDED;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$data['default_tax_type'] = Tax_lib::TAX_TYPE_EXCLUDED;
|
||||
}
|
||||
|
||||
if($tax_code == NEW_ENTRY)
|
||||
{
|
||||
if ($tax_code == NEW_ENTRY) {
|
||||
$data['tax_code'] = '';
|
||||
$data['tax_code_name'] = '';
|
||||
$data['tax_code_type'] = '0';
|
||||
@@ -284,9 +263,7 @@ class Taxes extends Secure_Controller
|
||||
$data['tax_category'] = '';
|
||||
$data['add_tax_category'] = '';
|
||||
$data['rounding_code'] = '0';
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$data['tax_code'] = $tax_code;
|
||||
$data['tax_code_name'] = $tax_code_info->tax_code_name;
|
||||
$data['tax_code_type'] = $tax_code_info->tax_code_type;
|
||||
@@ -301,8 +278,7 @@ class Taxes extends Secure_Controller
|
||||
}
|
||||
|
||||
$tax_rates = [];
|
||||
foreach($this->tax->get_tax_code_rate_exceptions($tax_code) as $tax_code_rate) //TODO: get_tax_code_rate_exceptions doesn't exist in the tax model
|
||||
{
|
||||
foreach ($this->tax->get_tax_code_rate_exceptions($tax_code) as $tax_code_rate) { // TODO: get_tax_code_rate_exceptions doesn't exist in the tax model
|
||||
$tax_rate_row = [];
|
||||
$tax_rate_row['rate_tax_category_id'] = $tax_code_rate['rate_tax_category_id'];
|
||||
$tax_rate_row['tax_category'] = $tax_code_rate['tax_category'];
|
||||
@@ -321,29 +297,25 @@ class Taxes extends Secure_Controller
|
||||
* @param int $tax_code
|
||||
* @return void
|
||||
*/
|
||||
public function getView_tax_jurisdictions(int $tax_code = NEW_ENTRY): void //TODO: This appears to be called no where in the code.
|
||||
public function getView_tax_jurisdictions(int $tax_code = NEW_ENTRY): void // TODO: This appears to be called no where in the code.
|
||||
{
|
||||
$tax_code_info = $this->tax->get_info($tax_code); //TODO: Duplicated code
|
||||
$tax_code_info = $this->tax->get_info($tax_code); // TODO: Duplicated code
|
||||
|
||||
$default_tax_category_id = 1; // Tax category id is always the default tax category
|
||||
$default_tax_category = $this->tax->get_tax_category($default_tax_category_id); //TODO: This variable is not used anywhere in the code
|
||||
$default_tax_category = $this->tax->get_tax_category($default_tax_category_id); // TODO: This variable is not used anywhere in the code
|
||||
|
||||
$tax_rate_info = $this->tax->get_rate_info($tax_code, $default_tax_category_id);
|
||||
|
||||
$data['rounding_options'] = rounding_mode::get_rounding_options();
|
||||
$data['html_rounding_options'] = $this->get_html_rounding_options();
|
||||
|
||||
if($this->config['tax_included'])
|
||||
{
|
||||
if ($this->config['tax_included']) {
|
||||
$data['default_tax_type'] = Tax_lib::TAX_TYPE_INCLUDED;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$data['default_tax_type'] = Tax_lib::TAX_TYPE_EXCLUDED;
|
||||
}
|
||||
|
||||
if($tax_code == NEW_ENTRY)
|
||||
{
|
||||
if ($tax_code == NEW_ENTRY) {
|
||||
$data['tax_code'] = '';
|
||||
$data['tax_code_name'] = '';
|
||||
$data['tax_code_type'] = '0';
|
||||
@@ -355,9 +327,7 @@ class Taxes extends Secure_Controller
|
||||
$data['tax_category'] = '';
|
||||
$data['add_tax_category'] = '';
|
||||
$data['rounding_code'] = '0';
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$data['tax_code'] = $tax_code;
|
||||
$data['tax_code_name'] = $tax_code_info->tax_code_name;
|
||||
$data['tax_code_type'] = $tax_code_info->tax_code_type;
|
||||
@@ -372,8 +342,7 @@ class Taxes extends Secure_Controller
|
||||
}
|
||||
|
||||
$tax_rates = [];
|
||||
foreach($this->tax->get_tax_code_rate_exceptions($tax_code) as $tax_code_rate) //TODO: get_tax_code_rate_exceptions doesn't exist in the tax model
|
||||
{
|
||||
foreach ($this->tax->get_tax_code_rate_exceptions($tax_code) as $tax_code_rate) { // TODO: get_tax_code_rate_exceptions doesn't exist in the tax model
|
||||
$tax_rate_row = [];
|
||||
$tax_rate_row['rate_tax_category_id'] = $tax_code_rate['rate_tax_category_id'];
|
||||
$tax_rate_row['tax_category'] = $tax_code_rate['tax_category'];
|
||||
@@ -405,33 +374,26 @@ class Taxes extends Secure_Controller
|
||||
$tax_category_id = $this->request->getPost('rate_tax_category_id', FILTER_SANITIZE_NUMBER_INT);
|
||||
$tax_rate = parse_tax($this->request->getPost('tax_rate'));
|
||||
|
||||
if ($tax_rate == 0) //TODO: Replace 0 with constant?
|
||||
{
|
||||
$tax_category_info = $this->tax_category->get_info($tax_category_id); //TODO: this variable is not used anywhere in the code
|
||||
if ($tax_rate == 0) { // TODO: Replace 0 with constant?
|
||||
$tax_category_info = $this->tax_category->get_info($tax_category_id); // TODO: this variable is not used anywhere in the code
|
||||
}
|
||||
|
||||
$tax_rate_data = [
|
||||
'rate_tax_code_id' => $this->request->getPost('rate_tax_code_id', FILTER_SANITIZE_NUMBER_INT),
|
||||
'rate_tax_code_id' => $this->request->getPost('rate_tax_code_id', FILTER_SANITIZE_NUMBER_INT),
|
||||
'rate_tax_category_id' => $tax_category_id,
|
||||
'rate_jurisdiction_id' => $this->request->getPost('rate_jurisdiction_id', FILTER_SANITIZE_NUMBER_INT),
|
||||
'tax_rate' => $tax_rate,
|
||||
'tax_rounding_code' => $this->request->getPost('tax_rounding_code', FILTER_SANITIZE_NUMBER_INT)
|
||||
'tax_rate' => $tax_rate,
|
||||
'tax_rounding_code' => $this->request->getPost('tax_rounding_code', FILTER_SANITIZE_NUMBER_INT)
|
||||
];
|
||||
|
||||
if($this->tax->save_value($tax_rate_data, $tax_rate_id))
|
||||
{
|
||||
if($tax_rate_id == NEW_ENTRY)
|
||||
{//TODO: this needs to be replaced with ternary notation
|
||||
echo json_encode (['success' => true, 'message' => lang('Taxes.tax_rate_successfully_added')]);
|
||||
if ($this->tax->save_value($tax_rate_data, $tax_rate_id)) {
|
||||
if ($tax_rate_id == NEW_ENTRY) { // TODO: this needs to be replaced with ternary notation
|
||||
echo json_encode(['success' => true, 'message' => lang('Taxes.tax_rate_successfully_added')]);
|
||||
} else { // Existing tax_code
|
||||
echo json_encode(['success' => true, 'message' => lang('Taxes.tax_rate_successful_updated')]);
|
||||
}
|
||||
else //Existing tax_code
|
||||
{
|
||||
echo json_encode (['success' => true, 'message' => lang('Taxes.tax_rate_successful_updated')]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
echo json_encode (['success' => false, 'message' => lang('Taxes.tax_rate_error_adding_updating')]);
|
||||
} else {
|
||||
echo json_encode(['success' => false, 'message' => lang('Taxes.tax_rate_error_adding_updating')]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -442,12 +404,10 @@ class Taxes extends Secure_Controller
|
||||
{
|
||||
$tax_codes_to_delete = $this->request->getPost('ids', FILTER_SANITIZE_NUMBER_INT);
|
||||
|
||||
if($this->tax->delete_list($tax_codes_to_delete)) //TODO: this needs to be replaced with ternary notation
|
||||
{
|
||||
echo json_encode (['success' => true, 'message' => lang('Taxes.tax_code_successful_deleted')]);
|
||||
} else
|
||||
{
|
||||
echo json_encode (['success' => false, 'message' => lang('Taxes.tax_code_cannot_be_deleted')]);
|
||||
if ($this->tax->delete_list($tax_codes_to_delete)) { // TODO: this needs to be replaced with ternary notation
|
||||
echo json_encode(['success' => true, 'message' => lang('Taxes.tax_code_successful_deleted')]);
|
||||
} else {
|
||||
echo json_encode(['success' => false, 'message' => lang('Taxes.tax_code_cannot_be_deleted')]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -479,21 +439,20 @@ class Taxes extends Secure_Controller
|
||||
$city = $this->request->getPost('city', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
|
||||
$state = $this->request->getPost('state', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
|
||||
|
||||
$array_save = []; //TODO: the naming of this variable is not good.
|
||||
foreach($tax_code_id as $key=>$val)
|
||||
{
|
||||
$array_save = []; // TODO: the naming of this variable is not good.
|
||||
foreach ($tax_code_id as $key => $val) {
|
||||
$array_save[] = [
|
||||
'tax_code_id'=>$val,
|
||||
'tax_code'=>$tax_code[$key],
|
||||
'tax_code_name'=>$tax_code_name[$key],
|
||||
'city'=>$city[$key],
|
||||
'state'=>$state[$key]
|
||||
'tax_code_id' => $val,
|
||||
'tax_code' => $tax_code[$key],
|
||||
'tax_code_name' => $tax_code_name[$key],
|
||||
'city' => $city[$key],
|
||||
'state' => $state[$key]
|
||||
];
|
||||
}
|
||||
|
||||
$success = $this->tax_code->save_tax_codes($array_save);
|
||||
|
||||
echo json_encode ([
|
||||
echo json_encode([
|
||||
'success' => $success,
|
||||
'message' => lang('Taxes.tax_codes_saved_' . ($success ? '' : 'un') . 'successfully')
|
||||
]);
|
||||
@@ -518,35 +477,31 @@ class Taxes extends Secure_Controller
|
||||
$array_save = [];
|
||||
$unique_tax_groups = [];
|
||||
|
||||
foreach($jurisdiction_id as $key => $val)
|
||||
{
|
||||
foreach ($jurisdiction_id as $key => $val) {
|
||||
$array_save[] = [
|
||||
'jurisdiction_id'=>$val,
|
||||
'jurisdiction_name'=>$jurisdiction_name[$key],
|
||||
'tax_group'=>$tax_group[$key],
|
||||
'tax_type'=>$tax_type[$key],
|
||||
'reporting_authority'=>$reporting_authority[$key],
|
||||
'tax_group_sequence'=>$tax_group_sequence[$key],
|
||||
'cascade_sequence'=>$cascade_sequence[$key]
|
||||
'jurisdiction_id' => $val,
|
||||
'jurisdiction_name' => $jurisdiction_name[$key],
|
||||
'tax_group' => $tax_group[$key],
|
||||
'tax_type' => $tax_type[$key],
|
||||
'reporting_authority' => $reporting_authority[$key],
|
||||
'tax_group_sequence' => $tax_group_sequence[$key],
|
||||
'cascade_sequence' => $cascade_sequence[$key]
|
||||
];
|
||||
|
||||
if (in_array($tax_group[$key], $unique_tax_groups)) //TODO: This can be replaced with `in_array($tax_group[$key], $unique_tax_groups)`
|
||||
{
|
||||
echo json_encode ([
|
||||
if (in_array($tax_group[$key], $unique_tax_groups)) { // TODO: This can be replaced with `in_array($tax_group[$key], $unique_tax_groups)`
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'message' => lang('Taxes.tax_group_not_unique', [$tax_group[$key]])
|
||||
]);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$unique_tax_groups[] = $tax_group[$key];
|
||||
}
|
||||
}
|
||||
|
||||
$success = $this->tax_jurisdiction->save_jurisdictions($array_save);
|
||||
|
||||
echo json_encode ([
|
||||
echo json_encode([
|
||||
'success' => $success,
|
||||
'message' => lang('Taxes.tax_jurisdictions_saved_' . ($success ? '' : 'un') . 'successfully')
|
||||
]);
|
||||
@@ -564,20 +519,19 @@ class Taxes extends Secure_Controller
|
||||
$tax_category = $this->request->getPost('tax_category', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
|
||||
$tax_group_sequence = $this->request->getPost('tax_group_sequence', FILTER_SANITIZE_NUMBER_INT);
|
||||
|
||||
$array_save= [];
|
||||
$array_save = [];
|
||||
|
||||
foreach($tax_category_id as $key => $val)
|
||||
{
|
||||
foreach ($tax_category_id as $key => $val) {
|
||||
$array_save[] = [
|
||||
'tax_category_id'=>$val,
|
||||
'tax_category'=>$tax_category[$key],
|
||||
'tax_group_sequence'=>$tax_group_sequence[$key]
|
||||
'tax_category_id' => $val,
|
||||
'tax_category' => $tax_category[$key],
|
||||
'tax_group_sequence' => $tax_group_sequence[$key]
|
||||
];
|
||||
}
|
||||
|
||||
$success = $this->tax_category->save_categories($array_save);
|
||||
|
||||
echo json_encode ([
|
||||
echo json_encode([
|
||||
'success' => $success,
|
||||
'message' => lang('Taxes.tax_categories_saved_' . ($success ? '' : 'un') . 'successfully')
|
||||
]);
|
||||
@@ -619,12 +573,9 @@ class Taxes extends Secure_Controller
|
||||
{
|
||||
$tax_jurisdictions = $this->tax_jurisdiction->get_all()->getResultArray();
|
||||
|
||||
if($this->config['tax_included']) //TODO: ternary notation
|
||||
{
|
||||
if ($this->config['tax_included']) { // TODO: ternary notation
|
||||
$default_tax_type = Tax_lib::TAX_TYPE_INCLUDED;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$default_tax_type = Tax_lib::TAX_TYPE_EXCLUDED;
|
||||
}
|
||||
|
||||
@@ -632,8 +583,8 @@ class Taxes extends Secure_Controller
|
||||
|
||||
echo view('partial/tax_jurisdictions', [
|
||||
'tax_jurisdictions' => $tax_jurisdictions,
|
||||
'tax_types' => $tax_types,
|
||||
'default_tax_type' => $default_tax_type
|
||||
'tax_types' => $tax_types,
|
||||
'default_tax_type' => $default_tax_type
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,8 +23,5 @@ class Migration_Upgrade_To_3_1_1 extends Migration
|
||||
/**
|
||||
* Revert a migration step.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
|
||||
}
|
||||
public function down(): void {}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ use CodeIgniter\Database\ResultInterface;
|
||||
*/
|
||||
class Migration_Sales_Tax_Data extends Migration
|
||||
{
|
||||
public const ROUND_UP = 5; //TODO: These need to be moved to constants.php
|
||||
public const ROUND_UP = 5; // TODO: These need to be moved to constants.php
|
||||
public const ROUND_DOWN = 6;
|
||||
public const HALF_FIVE = 7;
|
||||
public const YES = '1';
|
||||
@@ -26,7 +26,7 @@ class Migration_Sales_Tax_Data extends Migration
|
||||
parent::__construct();
|
||||
$this->appconfig = model(Appconfig::class);
|
||||
}
|
||||
//TODO: we need to figure out why we get a server error when uncommented portions of this migration run
|
||||
// TODO: we need to figure out why we get a server error when uncommented portions of this migration run
|
||||
|
||||
/**
|
||||
* Perform a migration step.
|
||||
@@ -36,12 +36,10 @@ class Migration_Sales_Tax_Data extends Migration
|
||||
$number_of_unmigrated = $this->get_count_of_unmigrated();
|
||||
error_log("Migrating sales tax history. The number of sales that will be migrated is $number_of_unmigrated");
|
||||
|
||||
if($number_of_unmigrated > 0)
|
||||
{
|
||||
if ($number_of_unmigrated > 0) {
|
||||
$unmigrated_invoices = $this->get_unmigrated($number_of_unmigrated)->getResultArray();
|
||||
|
||||
foreach($unmigrated_invoices as $key => $unmigrated_invoice)
|
||||
{
|
||||
foreach ($unmigrated_invoices as $key => $unmigrated_invoice) {
|
||||
$this->upgrade_tax_history_for_sale($unmigrated_invoice['sale_id']);
|
||||
}
|
||||
}
|
||||
@@ -52,9 +50,7 @@ class Migration_Sales_Tax_Data extends Migration
|
||||
/**
|
||||
* Revert a migration step.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
}
|
||||
public function down(): void {}
|
||||
|
||||
/**
|
||||
* @param int $sale_id
|
||||
@@ -66,12 +62,9 @@ class Migration_Sales_Tax_Data extends Migration
|
||||
$tax_included = $this->appconfig->get_value('tax_included', Migration_Sales_Tax_Data::YES) == Migration_Sales_Tax_Data::YES;
|
||||
$customer_sales_tax_support = false;
|
||||
|
||||
if($tax_included) //TODO: Convert to ternary notation.
|
||||
{
|
||||
if ($tax_included) { // TODO: Convert to ternary notation.
|
||||
$tax_type = Migration_Sales_Tax_Data::VAT_TAX;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$tax_type = Migration_Sales_Tax_Data::SALES_TAX;
|
||||
}
|
||||
|
||||
@@ -79,8 +72,7 @@ class Migration_Sales_Tax_Data extends Migration
|
||||
$tax_group_sequence = 0;
|
||||
$items = $this->get_sale_items_for_migration($sale_id)->getResultArray();
|
||||
|
||||
foreach($items as $item)
|
||||
{
|
||||
foreach ($items as $item) {
|
||||
// This computes tax for each line item and adds it to the tax type total
|
||||
$tax_group = (float)$item['percent'] . '% ' . $item['name'];
|
||||
$tax_basis = $this->get_item_total($item['quantity_purchased'], $item['item_unit_price'], $item['discount_percent'], true);
|
||||
@@ -93,9 +85,8 @@ class Migration_Sales_Tax_Data extends Migration
|
||||
$this->update_sales_taxes($sales_taxes, $tax_type, $tax_group, $item['percent'], $tax_basis, $item_tax_amount, $tax_group_sequence, PHP_ROUND_HALF_UP, $sale_id, $item['name']);
|
||||
$tax_group_sequence++;
|
||||
}
|
||||
//Not sure when this would ever kick in, but this is technically the correct logic.
|
||||
if($customer_sales_tax_support) //TODO: This will always evaluate to false
|
||||
{
|
||||
// Not sure when this would ever kick in, but this is technically the correct logic
|
||||
if ($customer_sales_tax_support) { // TODO: This will always evaluate to false
|
||||
$this->apply_invoice_taxing($sales_taxes);
|
||||
}
|
||||
|
||||
@@ -112,7 +103,7 @@ class Migration_Sales_Tax_Data extends Migration
|
||||
$builder = $this->db->table('sales_items_taxes as SIT');
|
||||
$builder->select('SIT.sale_id');
|
||||
$builder->select('ST.sale_id as sales_taxes_sale_id');
|
||||
$builder->join('sales_taxes as ST','SIT.sale_id = ST.sale_id', 'left');
|
||||
$builder->join('sales_taxes as ST', 'SIT.sale_id = ST.sale_id', 'left');
|
||||
$builder->where('ST.sale_id', null);
|
||||
$builder->groupBy('SIT.sale_id');
|
||||
$builder->groupBy('ST.sale_id');
|
||||
@@ -154,8 +145,7 @@ class Migration_Sales_Tax_Data extends Migration
|
||||
. ' as ST ON SIT.sale_id = ST.sale_id WHERE ST.sale_id is null GROUP BY SIT.sale_id, ST.sale_id'
|
||||
. ' ORDER BY SIT.sale_id) as US')->getResultArray();
|
||||
|
||||
if(!$result)
|
||||
{
|
||||
if (!$result) {
|
||||
error_log('Database error in 20170502221506_sales_tax_data.php related to sales_taxes or sales_items_taxes.');
|
||||
return 0;
|
||||
}
|
||||
@@ -190,8 +180,7 @@ class Migration_Sales_Tax_Data extends Migration
|
||||
{
|
||||
$builder = $this->db->Table('sales_taxes');
|
||||
|
||||
foreach($sales_taxes as $line => $sales_tax)
|
||||
{
|
||||
foreach ($sales_taxes as $line => $sales_tax) {
|
||||
$builder->insert($sales_tax);
|
||||
}
|
||||
}
|
||||
@@ -207,8 +196,7 @@ class Migration_Sales_Tax_Data extends Migration
|
||||
{
|
||||
$total = bcmul($quantity, $price);
|
||||
|
||||
if($include_discount)
|
||||
{
|
||||
if ($include_discount) {
|
||||
$discount_amount = $this->get_item_discount($quantity, $price, $discount_percentage);
|
||||
return bcsub($total, $discount_amount);
|
||||
}
|
||||
@@ -228,7 +216,7 @@ class Migration_Sales_Tax_Data extends Migration
|
||||
$discount_fraction = bcdiv($discount, 100);
|
||||
$discount = bcmul($total, $discount_fraction);
|
||||
|
||||
return round($discount, totals_decimals(), PHP_ROUND_HALF_UP); //TODO: I don't think this is currency safe. Round will cast it's first parameter to a float. It also returns a float.
|
||||
return round($discount, totals_decimals(), PHP_ROUND_HALF_UP); // TODO: I don't think this is currency safe. Round will cast it's first parameter to a float. It also returns a float.
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -244,8 +232,7 @@ class Migration_Sales_Tax_Data extends Migration
|
||||
|
||||
$price = $this->get_item_total($quantity, $price, $discount_percentage, true);
|
||||
|
||||
if($tax_included)
|
||||
{
|
||||
if ($tax_included) {
|
||||
$tax_fraction = bcadd('100', $tax_percentage);
|
||||
$tax_fraction = bcdiv($tax_fraction, '100');
|
||||
$price_tax_excl = bcdiv($price, $tax_fraction);
|
||||
@@ -280,26 +267,19 @@ class Migration_Sales_Tax_Data extends Migration
|
||||
*/
|
||||
public function round_number(int $rounding_mode, string $amount, int $decimals): float
|
||||
{
|
||||
if($rounding_mode == Migration_Sales_Tax_Data::ROUND_UP)
|
||||
{
|
||||
$fig = pow(10,$decimals);
|
||||
$rounded_total = (ceil($fig * $amount) + ceil($fig * $amount - ceil($fig * $amount)))/$fig;
|
||||
}
|
||||
elseif($rounding_mode == Migration_Sales_Tax_Data::ROUND_DOWN)
|
||||
{
|
||||
$fig = pow(10,$decimals);
|
||||
$rounded_total = (floor($fig * $amount) + floor($fig * $amount - floor($fig * $amount)))/$fig;
|
||||
}
|
||||
elseif($rounding_mode == Migration_Sales_Tax_Data::HALF_FIVE)
|
||||
{
|
||||
if ($rounding_mode == Migration_Sales_Tax_Data::ROUND_UP) {
|
||||
$fig = pow(10, $decimals);
|
||||
$rounded_total = (ceil($fig * $amount) + ceil($fig * $amount - ceil($fig * $amount))) / $fig;
|
||||
} elseif ($rounding_mode == Migration_Sales_Tax_Data::ROUND_DOWN) {
|
||||
$fig = pow(10, $decimals);
|
||||
$rounded_total = (floor($fig * $amount) + floor($fig * $amount - floor($fig * $amount))) / $fig;
|
||||
} elseif ($rounding_mode == Migration_Sales_Tax_Data::HALF_FIVE) {
|
||||
$rounded_total = round($amount / 5) * 5;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$rounded_total = round($amount, $decimals, $rounding_mode);
|
||||
}
|
||||
|
||||
return $rounded_total; //TODO: I don't think this is currency safe. I think we need to be using bcmath() functions like we are in the rest of the code.
|
||||
return $rounded_total; // TODO: I don't think this is currency safe. I think we need to be using bcmath() functions like we are in the rest of the code.
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -318,30 +298,27 @@ class Migration_Sales_Tax_Data extends Migration
|
||||
*/
|
||||
public function update_sales_taxes(array &$sales_taxes, string $tax_type, string $tax_group, float $tax_rate, string $tax_basis, string $item_tax_amount, int $tax_group_sequence, int $rounding_code, int $sale_id, string $name = '', string $tax_code = ''): void
|
||||
{
|
||||
$tax_group_index = $this->clean('X'.$tax_group);
|
||||
if(!array_key_exists($tax_group_index, $sales_taxes))
|
||||
{
|
||||
$insertkey = $tax_group_index; //TODO: $insertkey does not follow naming conventions.
|
||||
$tax_group_index = $this->clean('X' . $tax_group);
|
||||
if (!array_key_exists($tax_group_index, $sales_taxes)) {
|
||||
$insertkey = $tax_group_index; // TODO: $insertkey does not follow naming conventions.
|
||||
$sales_tax = [
|
||||
$insertkey => [
|
||||
'sale_id' => $sale_id,
|
||||
'tax_type' => $tax_type,
|
||||
'tax_group' => $tax_group,
|
||||
'sale_tax_basis' => $tax_basis,
|
||||
'sale_id' => $sale_id,
|
||||
'tax_type' => $tax_type,
|
||||
'tax_group' => $tax_group,
|
||||
'sale_tax_basis' => $tax_basis,
|
||||
'sale_tax_amount' => $item_tax_amount,
|
||||
'print_sequence' => $tax_group_sequence,
|
||||
'name' => $name,
|
||||
'tax_rate' => $tax_rate,
|
||||
'sales_tax_code' => $tax_code,
|
||||
'rounding_code' => $rounding_code
|
||||
'print_sequence' => $tax_group_sequence,
|
||||
'name' => $name,
|
||||
'tax_rate' => $tax_rate,
|
||||
'sales_tax_code' => $tax_code,
|
||||
'rounding_code' => $rounding_code
|
||||
]
|
||||
];
|
||||
//add to existing array
|
||||
// Add to existing array
|
||||
$sales_taxes += $sales_tax;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Important ... the sales amounts are accumulated for the group at the maximum configurable scale value of 4
|
||||
} else {
|
||||
// Important: the sales amounts are accumulated for the group at the maximum configurable scale value of 4
|
||||
// but the scale will in reality be the scale specified by the tax_decimal configuration value used for sales_items_taxes
|
||||
$sales_taxes[$tax_group_index]['sale_tax_basis'] = bcadd($sales_taxes[$tax_group_index]['sale_tax_basis'], $tax_basis, 4);
|
||||
$sales_taxes[$tax_group_index]['sale_tax_amount'] = bcadd($sales_taxes[$tax_group_index]['sale_tax_amount'], $item_tax_amount, 4);
|
||||
@@ -352,7 +329,7 @@ class Migration_Sales_Tax_Data extends Migration
|
||||
* @param string $string
|
||||
* @return string
|
||||
*/
|
||||
public function clean(string $string): string //TODO: $string is not a good name for this variable
|
||||
public function clean(string $string): string // TODO: $string is not a good name for this variable
|
||||
{
|
||||
$string = str_replace(' ', '-', $string); // Replaces all spaces with hyphens.
|
||||
|
||||
@@ -365,12 +342,10 @@ class Migration_Sales_Tax_Data extends Migration
|
||||
*/
|
||||
public function apply_invoice_taxing(array &$sales_taxes): void
|
||||
{
|
||||
if(!empty($sales_taxes)) //TODO: Duplicated code
|
||||
{
|
||||
if (!empty($sales_taxes)) { // TODO: Duplicated code
|
||||
$sort = [];
|
||||
|
||||
foreach($sales_taxes as $key => $value)
|
||||
{
|
||||
foreach ($sales_taxes as $key => $value) {
|
||||
$sort['print_sequence'][$key] = $value['print_sequence'];
|
||||
}
|
||||
|
||||
@@ -379,8 +354,7 @@ class Migration_Sales_Tax_Data extends Migration
|
||||
|
||||
$decimals = totals_decimals();
|
||||
|
||||
foreach($sales_taxes as $row_number => $sales_tax)
|
||||
{
|
||||
foreach ($sales_taxes as $row_number => $sales_tax) {
|
||||
$sales_taxes[$row_number]['sale_tax_amount'] = $this->get_sales_tax_for_amount($sales_tax['sale_tax_basis'], $sales_tax['tax_rate'], $sales_tax['rounding_code'], $decimals);
|
||||
}
|
||||
}
|
||||
@@ -391,11 +365,9 @@ class Migration_Sales_Tax_Data extends Migration
|
||||
*/
|
||||
public function round_sales_taxes(array &$sales_taxes): void
|
||||
{
|
||||
if(!empty($sales_taxes))
|
||||
{
|
||||
if (!empty($sales_taxes)) {
|
||||
$sort = [];
|
||||
foreach($sales_taxes as $k=>$v)
|
||||
{
|
||||
foreach ($sales_taxes as $k => $v) {
|
||||
$sort['print_sequence'][$k] = $v['print_sequence'];
|
||||
}
|
||||
array_multisort($sort['print_sequence'], SORT_ASC, $sales_taxes);
|
||||
@@ -403,31 +375,25 @@ class Migration_Sales_Tax_Data extends Migration
|
||||
|
||||
$decimals = totals_decimals();
|
||||
|
||||
foreach($sales_taxes as $row_number => $sales_tax)
|
||||
{
|
||||
foreach ($sales_taxes as $row_number => $sales_tax) {
|
||||
$sale_tax_amount = $sales_tax['sale_tax_amount'];
|
||||
$rounding_code = $sales_tax['rounding_code'];
|
||||
$rounded_sale_tax_amount = $sale_tax_amount;
|
||||
|
||||
if ($rounding_code == PHP_ROUND_HALF_UP
|
||||
if (
|
||||
$rounding_code == PHP_ROUND_HALF_UP
|
||||
|| $rounding_code == PHP_ROUND_HALF_DOWN
|
||||
|| $rounding_code == PHP_ROUND_HALF_EVEN
|
||||
|| $rounding_code == PHP_ROUND_HALF_ODD)
|
||||
{
|
||||
|| $rounding_code == PHP_ROUND_HALF_ODD
|
||||
) {
|
||||
$rounded_sale_tax_amount = round($sale_tax_amount, $decimals, $rounding_code);
|
||||
}
|
||||
elseif($rounding_code == Migration_Sales_Tax_Data::ROUND_UP)
|
||||
{
|
||||
} elseif ($rounding_code == Migration_Sales_Tax_Data::ROUND_UP) {
|
||||
$fig = (int) str_pad('1', $decimals, '0');
|
||||
$rounded_sale_tax_amount = (ceil($sale_tax_amount * $fig) / $fig);
|
||||
}
|
||||
elseif($rounding_code == Migration_Sales_Tax_Data::ROUND_DOWN)
|
||||
{
|
||||
} elseif ($rounding_code == Migration_Sales_Tax_Data::ROUND_DOWN) {
|
||||
$fig = (int) str_pad('1', $decimals, '0');
|
||||
$rounded_sale_tax_amount = (floor($sale_tax_amount * $fig) / $fig);
|
||||
}
|
||||
elseif($rounding_code == Migration_Sales_Tax_Data::HALF_FIVE)
|
||||
{
|
||||
} elseif ($rounding_code == Migration_Sales_Tax_Data::HALF_FIVE) {
|
||||
$rounded_sale_tax_amount = round($sale_tax_amount / 5) * 5;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,8 +18,5 @@ class Migration_Upgrade_To_3_2_0 extends Migration
|
||||
/**
|
||||
* Revert a migration step.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
|
||||
}
|
||||
public function down(): void {}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,5 @@ class Migration_Upgrade_To_3_2_1 extends Migration
|
||||
/**
|
||||
* Revert a migration step.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
|
||||
}
|
||||
public function down(): void {}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,5 @@ class Migration_Attributes extends Migration
|
||||
/**
|
||||
* Revert a migration step.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
|
||||
}
|
||||
public function down(): void {}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,5 @@ class Migration_Upgrade_To_3_3_0 extends Migration
|
||||
/**
|
||||
* Revert a migration step.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
|
||||
}
|
||||
public function down(): void {}
|
||||
}
|
||||
|
||||
@@ -11,8 +11,7 @@ class Migration_IndiaGST extends Migration
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
if(!$this->db->fieldExists('sales_tax_code', 'customers'))
|
||||
{
|
||||
if (!$this->db->fieldExists('sales_tax_code', 'customers')) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -24,8 +23,7 @@ class Migration_IndiaGST extends Migration
|
||||
|
||||
$count_of_tax_codes = $this->get_count_of_tax_code_entries();
|
||||
|
||||
if($count_of_tax_codes > 0)
|
||||
{
|
||||
if ($count_of_tax_codes > 0) {
|
||||
$this->migrate_tax_code_data();
|
||||
}
|
||||
|
||||
@@ -33,15 +31,13 @@ class Migration_IndiaGST extends Migration
|
||||
|
||||
$count_of_rate_entries = $this->get_count_of_rate_entries();
|
||||
|
||||
if($count_of_rate_entries > 0)
|
||||
{
|
||||
if ($count_of_rate_entries > 0) {
|
||||
$this->migrate_tax_rates();
|
||||
}
|
||||
|
||||
$count_of_sales_taxes_entries = $this->get_count_of_sales_taxes_entries();
|
||||
|
||||
if($count_of_sales_taxes_entries > 0)
|
||||
{
|
||||
if ($count_of_sales_taxes_entries > 0) {
|
||||
$this->migrate_sales_taxes_data();
|
||||
}
|
||||
|
||||
@@ -53,9 +49,7 @@ class Migration_IndiaGST extends Migration
|
||||
/**
|
||||
* Revert a migration step.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
}
|
||||
public function down(): void {}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
@@ -147,10 +141,10 @@ class Migration_IndiaGST extends Migration
|
||||
*/
|
||||
private function migrate_tax_rates(): void
|
||||
{
|
||||
// create a dummy jurisdiction record and retrieve the jurisdiction rate id
|
||||
// Create a dummy jurisdiction record and retrieve the jurisdiction rate id
|
||||
|
||||
$this->db->query('INSERT INTO ' . $this->db->prefixTable('tax_jurisdictions') . ' (jurisdiction_name, tax_group, tax_type, reporting_authority, '
|
||||
. "tax_group_sequence, cascade_sequence, deleted) VALUES ('Jurisdiction1', 'TaxGroup1', '1', 'Authority1', 1, 0, '0')");
|
||||
. "tax_group_sequence, cascade_sequence, deleted) VALUES ('Jurisdiction1', 'TaxGroup1', '1', 'Authority1', 1, 0, '0')");
|
||||
|
||||
$jurisdiction_id = $this->db->query('SELECT jurisdiction_id FROM ' . $this->db->prefixTable('tax_jurisdictions') . " WHERE jurisdiction_name = 'Jurisdiction1'")->getRow()->jurisdiction_id;
|
||||
|
||||
|
||||
@@ -22,8 +22,5 @@ class Migration_IndiaGST1 extends Migration
|
||||
/**
|
||||
* Revert a migration step.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
}
|
||||
|
||||
public function down(): void {}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,5 @@ class Migration_IndiaGST2 extends Migration
|
||||
/**
|
||||
* Revert a migration step.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
}
|
||||
|
||||
public function down(): void {}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,5 @@ class Migration_decimal_attribute_type extends Migration
|
||||
/**
|
||||
* Revert a migration step.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
|
||||
}
|
||||
public function down(): void {}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,5 @@ class Migration_add_iso_4217 extends Migration
|
||||
/**
|
||||
* Revert a migration step.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
|
||||
}
|
||||
public function down(): void {}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,5 @@ class Migration_PaymentTracking extends Migration
|
||||
/**
|
||||
* Revert a migration step.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
|
||||
}
|
||||
public function down(): void {}
|
||||
}
|
||||
|
||||
@@ -23,8 +23,9 @@ class Migration_RefundTracking extends Migration
|
||||
|
||||
$cash_payment = lang('Sales.cash');
|
||||
|
||||
$this->db->query('CREATE TEMPORARY TABLE IF NOT EXISTS ' . $this->db->prefixTable('migrate_taxes') .
|
||||
' (INDEX(sale_id)) ENGINE=MEMORY
|
||||
$this->db->query(
|
||||
'CREATE TEMPORARY TABLE IF NOT EXISTS ' . $this->db->prefixTable('migrate_taxes') .
|
||||
' (INDEX(sale_id)) ENGINE=MEMORY
|
||||
(
|
||||
SELECT sales.sale_id, SUM(sales_taxes.sale_tax_amount) AS total_taxes
|
||||
FROM ' . $this->db->prefixTable('sales') . ' AS sales
|
||||
@@ -35,10 +36,11 @@ class Migration_RefundTracking extends Migration
|
||||
)'
|
||||
);
|
||||
|
||||
$this->db->query('CREATE TEMPORARY TABLE IF NOT EXISTS ' . $this->db->prefixTable('migrate_sales') .
|
||||
' (INDEX(sale_id)) ENGINE=MEMORY
|
||||
$this->db->query(
|
||||
'CREATE TEMPORARY TABLE IF NOT EXISTS ' . $this->db->prefixTable('migrate_sales') .
|
||||
' (INDEX(sale_id)) ENGINE=MEMORY
|
||||
(
|
||||
SELECT sales.sale_id, '. $trans_amount . ', sales.employee_id, sales.sale_time'
|
||||
SELECT sales.sale_id, ' . $trans_amount . ', sales.employee_id, sales.sale_time'
|
||||
. ' FROM ' . $this->db->prefixTable('sales') . ' AS sales '
|
||||
. 'LEFT OUTER JOIN ' . $this->db->prefixTable('sales_items') . ' AS sales_items '
|
||||
. 'ON sales.sale_id = sales_items.sale_id '
|
||||
@@ -52,10 +54,11 @@ class Migration_RefundTracking extends Migration
|
||||
. 'SET trans_amount = trans_amount + IFNULL((SELECT total_taxes FROM ' . $this->db->prefixTable('migrate_taxes')
|
||||
. ' AS sumpay_taxes WHERE sumpay_items.sale_id = sumpay_taxes.sale_id),0)');
|
||||
|
||||
$this->db->query('CREATE TEMPORARY TABLE IF NOT EXISTS ' . $this->db->prefixTable('migrate_payments') .
|
||||
' (INDEX(sale_id)) ENGINE=MEMORY
|
||||
$this->db->query(
|
||||
'CREATE TEMPORARY TABLE IF NOT EXISTS ' . $this->db->prefixTable('migrate_payments') .
|
||||
' (INDEX(sale_id)) ENGINE=MEMORY
|
||||
(
|
||||
SELECT sales.sale_id, COUNT(sales.sale_id) AS number_payments,
|
||||
SELECT sales.sale_id, COUNT(sales.sale_id) AS number_payments,
|
||||
SUM(sales_payments.payment_amount - sales_payments.cash_refund) AS total_payments
|
||||
FROM ' . $this->db->prefixTable('sales') . ' AS sales
|
||||
LEFT OUTER JOIN ' . $this->db->prefixTable('sales_payments') . ' AS sales_payments
|
||||
@@ -67,8 +70,9 @@ class Migration_RefundTracking extends Migration
|
||||
// You may be asking yourself why the following is not creating a temporary table.
|
||||
// It should be, it originallly was, but there is a bug in MySQL where temporary tables where some SQL statements fail.
|
||||
// The update statement that follows this CREATE TABLE is one of those statements.
|
||||
$this->db->query('CREATE TABLE IF NOT EXISTS ' . $this->db->prefixTable('migrate_refund') .
|
||||
' (INDEX(sale_id)) ENGINE=MEMORY
|
||||
$this->db->query(
|
||||
'CREATE TABLE IF NOT EXISTS ' . $this->db->prefixTable('migrate_refund') .
|
||||
' (INDEX(sale_id)) ENGINE=MEMORY
|
||||
(
|
||||
SELECT a.sale_id, total_payments - trans_amount AS refund_amount
|
||||
FROM ' . $this->db->prefixTable('migrate_sales') . ' AS a
|
||||
@@ -78,21 +82,23 @@ class Migration_RefundTracking extends Migration
|
||||
);
|
||||
|
||||
// Update existing cash transactions with refund amount
|
||||
$this->db->query('UPDATE ' . $this->db->prefixTable('sales_payments') . ' AS a
|
||||
$this->db->query(
|
||||
'UPDATE ' . $this->db->prefixTable('sales_payments') . ' AS a
|
||||
SET a.cash_refund =
|
||||
(SELECT b.refund_amount
|
||||
FROM ' . $this->db->prefixTable('migrate_refund') . ' AS b
|
||||
(SELECT b.refund_amount
|
||||
FROM ' . $this->db->prefixTable('migrate_refund') . ' AS b
|
||||
WHERE a.sale_id = b.sale_id AND a.payment_type = \'' . $cash_payment . '\')
|
||||
WHERE EXISTS
|
||||
(SELECT b.refund_amount
|
||||
FROM ' . $this->db->prefixTable('migrate_refund') . ' AS b
|
||||
(SELECT b.refund_amount
|
||||
FROM ' . $this->db->prefixTable('migrate_refund') . ' AS b
|
||||
WHERE a.sale_id = b.sale_id AND a.payment_type = \'' . $cash_payment . ' \')'
|
||||
);
|
||||
|
||||
// Insert new cash refund transactions for non-cash payments
|
||||
$this->db->query('INSERT INTO ' . $this->db->prefixTable('sales_payments') .
|
||||
' (sale_id, payment_type, employee_id, payment_time, payment_amount, cash_refund)
|
||||
SELECT r.sale_id, \'' . $cash_payment . '\', s.employee_id, sale_time, 0, r.refund_amount
|
||||
$this->db->query(
|
||||
'INSERT INTO ' . $this->db->prefixTable('sales_payments') .
|
||||
' (sale_id, payment_type, employee_id, payment_time, payment_amount, cash_refund)
|
||||
SELECT r.sale_id, \'' . $cash_payment . '\', s.employee_id, sale_time, 0, r.refund_amount
|
||||
FROM ' . $this->db->prefixTable('migrate_refund') . ' AS r
|
||||
JOIN ' . $this->db->prefixTable('sales_payments') . ' AS p ON r.sale_id = p.sale_id
|
||||
JOIN ' . $this->db->prefixTable('migrate_sales') . ' AS s ON r.sale_id = s.sale_id
|
||||
@@ -106,8 +112,5 @@ class Migration_RefundTracking extends Migration
|
||||
/**
|
||||
* Revert a migration step.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
|
||||
}
|
||||
public function down(): void {}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,5 @@ class Migration_DBFix extends Migration
|
||||
/**
|
||||
* Revert a migration step.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
|
||||
}
|
||||
public function down(): void {}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,5 @@ class Migration_fix_attribute_datetime extends Migration
|
||||
/**
|
||||
* Revert a migration step.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
|
||||
}
|
||||
public function down(): void {}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ class Migration_fix_empty_reports extends Migration
|
||||
$location_name = str_replace(' ', '_', $location_name);
|
||||
$builder = $this->db->table('permissions');
|
||||
$builder->set('location_id', 1);
|
||||
$builder->where('permission_id','receivings_' . $location_name);
|
||||
$builder->where('permission_id', 'receivings_' . $location_name);
|
||||
$builder->orWhere('permission_id', 'sales_' . $location_name);
|
||||
$builder->update();
|
||||
}
|
||||
@@ -28,8 +28,5 @@ class Migration_fix_empty_reports extends Migration
|
||||
/**
|
||||
* Revert a migration step.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
|
||||
}
|
||||
public function down(): void {}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,5 @@ class Migration_PaymentDateFix extends Migration
|
||||
/**
|
||||
* Revert a migration step.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
|
||||
}
|
||||
public function down(): void {}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,5 @@ class Migration_SalesChangePrice extends Migration
|
||||
/**
|
||||
* Revert a migration step.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
|
||||
}
|
||||
public function down(): void {}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ class Migration_TaxAmount extends Migration
|
||||
public const HALF_FIVE = 7;
|
||||
public const YES = '1';
|
||||
public const VAT_TAX = '0';
|
||||
public const SALES_TAX = '1'; //TODO: It appears that this constant is never used
|
||||
public const SALES_TAX = '1'; // TODO: It appears that this constant is never used
|
||||
private Appconfig $appconfig;
|
||||
|
||||
public function __construct()
|
||||
@@ -37,21 +37,18 @@ class Migration_TaxAmount extends Migration
|
||||
{
|
||||
$tax_included = ($this->appconfig->get_value('tax_included', Migration_TaxAmount::YES) == Migration_TaxAmount::YES);
|
||||
|
||||
if($tax_included)
|
||||
{
|
||||
if ($tax_included) {
|
||||
$tax_decimals = $this->appconfig->get_value('tax_decimals', 2);
|
||||
$number_of_unmigrated = $this->get_count_of_unmigrated();
|
||||
|
||||
error_log('Migrating sales tax fixing. The number of sales that will be migrated is ' . $number_of_unmigrated);
|
||||
|
||||
if($number_of_unmigrated > 0)
|
||||
{
|
||||
if ($number_of_unmigrated > 0) {
|
||||
$unmigrated_invoices = $this->get_unmigrated($number_of_unmigrated)->getResultArray();
|
||||
$this->db->query('RENAME TABLE ' . $this->db->prefixTable('sales_taxes') . ' TO ' . $this->db->prefixTable('sales_taxes_backup'));
|
||||
$this->db->query('CREATE TABLE ' . $this->db->prefixTable('sales_taxes') . ' LIKE ' . $this->db->prefixTable('sales_taxes_backup'));
|
||||
|
||||
foreach($unmigrated_invoices as $key => $unmigrated_invoice)
|
||||
{
|
||||
foreach ($unmigrated_invoices as $key => $unmigrated_invoice) {
|
||||
$this->upgrade_tax_history_for_sale($unmigrated_invoice['sale_id'], $tax_decimals, true);
|
||||
}
|
||||
$this->db->query('DROP TABLE ' . $this->db->prefixTable('sales_taxes_backup'));
|
||||
@@ -64,10 +61,7 @@ class Migration_TaxAmount extends Migration
|
||||
/**
|
||||
* Revert a migration step.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
|
||||
}
|
||||
public function down(): void {}
|
||||
|
||||
/**
|
||||
* @param int $sale_id
|
||||
@@ -75,7 +69,7 @@ class Migration_TaxAmount extends Migration
|
||||
* @param bool $tax_included
|
||||
* @return void
|
||||
*/
|
||||
private function upgrade_tax_history_for_sale(int $sale_id, string $tax_decimals, bool $tax_included): void //TODO: $tax_included is passed as a parameter but never used in the function body.
|
||||
private function upgrade_tax_history_for_sale(int $sale_id, string $tax_decimals, bool $tax_included): void // TODO: $tax_included is passed as a parameter but never used in the function body.
|
||||
{
|
||||
$customer_sales_tax_support = false;
|
||||
$tax_type = Migration_TaxAmount::VAT_TAX;
|
||||
@@ -83,8 +77,7 @@ class Migration_TaxAmount extends Migration
|
||||
$tax_group_sequence = 0;
|
||||
$items = $this->get_sale_items_for_migration($sale_id)->getResultArray();
|
||||
|
||||
foreach($items as $item)
|
||||
{
|
||||
foreach ($items as $item) {
|
||||
// This computes tax for each line item and adds it to the tax type total
|
||||
$tax_group = (float)$item['percent'] . '% ' . $item['name'];
|
||||
$tax_basis = $this->get_item_total($item['quantity_purchased'], $item['item_unit_price'], $item['discount'], true);
|
||||
@@ -94,8 +87,7 @@ class Migration_TaxAmount extends Migration
|
||||
$tax_group_sequence += 1;
|
||||
}
|
||||
|
||||
if($customer_sales_tax_support) //TODO: This will always evaluate to false.
|
||||
{
|
||||
if ($customer_sales_tax_support) { // TODO: This will always evaluate to false.
|
||||
$this->apply_invoice_taxing($sales_taxes);
|
||||
}
|
||||
|
||||
@@ -133,8 +125,7 @@ class Migration_TaxAmount extends Migration
|
||||
. ' as ST ON SIT.sale_id = ST.sale_id GROUP BY SIT.sale_id, ST.sale_id'
|
||||
. ' ORDER BY SIT.sale_id) as US')->getResultArray();
|
||||
|
||||
if(!$result)
|
||||
{
|
||||
if (!$result) {
|
||||
error_log('Database error in 20200202000000_taxamount.php related to sales_taxes or sales_items_taxes.');
|
||||
return 0;
|
||||
}
|
||||
@@ -190,8 +181,7 @@ class Migration_TaxAmount extends Migration
|
||||
{
|
||||
$builder = $this->db->table('sales_taxes');
|
||||
|
||||
foreach($sales_taxes as $line => $sales_tax)
|
||||
{
|
||||
foreach ($sales_taxes as $line => $sales_tax) {
|
||||
$builder->insert($sales_tax);
|
||||
}
|
||||
}
|
||||
@@ -207,8 +197,7 @@ class Migration_TaxAmount extends Migration
|
||||
{
|
||||
$total = bcmul($quantity, $price);
|
||||
|
||||
if($include_discount)
|
||||
{
|
||||
if ($include_discount) {
|
||||
$total = bcsub($total, bcmul(bcmul($quantity, $price), bcdiv($discount, 100)));
|
||||
}
|
||||
|
||||
@@ -222,7 +211,7 @@ class Migration_TaxAmount extends Migration
|
||||
* @param int $decimals
|
||||
* @return float
|
||||
*/
|
||||
public function get_item_tax(string $tax_basis, string $tax_percentage, int $rounding_mode, int $decimals): float //TODO: is this currency safe?
|
||||
public function get_item_tax(string $tax_basis, string $tax_percentage, int $rounding_mode, int $decimals): float // TODO: is this currency safe?
|
||||
{
|
||||
$tax_fraction = bcdiv(bcadd('100', $tax_percentage), '100');
|
||||
$price_tax_excl = bcdiv($tax_basis, $tax_fraction);
|
||||
@@ -238,7 +227,7 @@ class Migration_TaxAmount extends Migration
|
||||
* @param int $decimals
|
||||
* @return float
|
||||
*/
|
||||
public function get_sales_tax_for_amount(string $tax_basis, string $tax_percentage, int $rounding_mode, int $decimals): float //TODO: is this currency safe?
|
||||
public function get_sales_tax_for_amount(string $tax_basis, string $tax_percentage, int $rounding_mode, int $decimals): float // TODO: is this currency safe?
|
||||
{
|
||||
$tax_fraction = bcdiv($tax_percentage, '100');
|
||||
$tax_amount = bcmul($tax_basis, $tax_fraction);
|
||||
@@ -252,24 +241,17 @@ class Migration_TaxAmount extends Migration
|
||||
* @param int $decimals
|
||||
* @return float
|
||||
*/
|
||||
public function round_number(int $rounding_mode, string $amount, int $decimals): float //TODO: is this currency safe?
|
||||
{//TODO: This needs to be converted to a switch
|
||||
if($rounding_mode == Migration_TaxAmount::ROUND_UP) //TODO: === ?
|
||||
{
|
||||
public function round_number(int $rounding_mode, string $amount, int $decimals): float // TODO: is this currency safe?
|
||||
{ // TODO: This needs to be converted to a switch
|
||||
if ($rounding_mode == Migration_TaxAmount::ROUND_UP) { // TODO: === ?
|
||||
$fig = pow(10, $decimals);
|
||||
$rounded_total = (ceil($fig * $amount) + ceil($fig*$amount - ceil($fig * $amount)))/$fig;
|
||||
}
|
||||
elseif($rounding_mode == Migration_TaxAmount::ROUND_DOWN) //TODO: === ?
|
||||
{
|
||||
$rounded_total = (ceil($fig * $amount) + ceil($fig * $amount - ceil($fig * $amount))) / $fig;
|
||||
} elseif ($rounding_mode == Migration_TaxAmount::ROUND_DOWN) { // TODO: === ?
|
||||
$fig = pow(10, $decimals);
|
||||
$rounded_total = (floor($fig * $amount) + floor($fig * $amount - floor($fig * $amount)))/$fig;
|
||||
}
|
||||
elseif($rounding_mode == Migration_TaxAmount::HALF_FIVE) //TODO: === ?
|
||||
{
|
||||
$rounded_total = (floor($fig * $amount) + floor($fig * $amount - floor($fig * $amount))) / $fig;
|
||||
} elseif ($rounding_mode == Migration_TaxAmount::HALF_FIVE) { // TODO: === ?
|
||||
$rounded_total = round($amount / 5) * 5;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$rounded_total = round($amount, $decimals, $rounding_mode);
|
||||
}
|
||||
|
||||
@@ -294,30 +276,27 @@ class Migration_TaxAmount extends Migration
|
||||
{
|
||||
$tax_group_index = $this->clean('X' . $tax_group);
|
||||
|
||||
if(!array_key_exists($tax_group_index, $sales_taxes))
|
||||
{
|
||||
if (!array_key_exists($tax_group_index, $sales_taxes)) {
|
||||
$insertkey = $tax_group_index;
|
||||
$sales_tax = [
|
||||
$insertkey => [
|
||||
'sale_id' => $sale_id,
|
||||
'tax_type' => $tax_type,
|
||||
'tax_group' => $tax_group,
|
||||
'sale_tax_basis' => $tax_basis,
|
||||
'sale_tax_amount' => $item_tax_amount,
|
||||
'print_sequence' => $tax_group_sequence,
|
||||
'name' => $name,
|
||||
'tax_rate' => $tax_rate,
|
||||
'sale_id' => $sale_id,
|
||||
'tax_type' => $tax_type,
|
||||
'tax_group' => $tax_group,
|
||||
'sale_tax_basis' => $tax_basis,
|
||||
'sale_tax_amount' => $item_tax_amount,
|
||||
'print_sequence' => $tax_group_sequence,
|
||||
'name' => $name,
|
||||
'tax_rate' => $tax_rate,
|
||||
'sales_tax_code_id' => $tax_code,
|
||||
'rounding_code' => $rounding_code
|
||||
'rounding_code' => $rounding_code
|
||||
]
|
||||
];
|
||||
|
||||
//add to existing array
|
||||
// Add to existing array
|
||||
$sales_taxes += $sales_tax;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Important ... the sales amounts are accumulated for the group at the maximum configurable scale value of 4
|
||||
} else {
|
||||
// Important: the sales amounts are accumulated for the group at the maximum configurable scale value of 4
|
||||
// but the scale will in reality be the scale specified by the tax_decimal configuration value used for sales_items_taxes
|
||||
$sales_taxes[$tax_group_index]['sale_tax_basis'] = bcadd($sales_taxes[$tax_group_index]['sale_tax_basis'], $tax_basis, 4);
|
||||
$sales_taxes[$tax_group_index]['sale_tax_amount'] = bcadd($sales_taxes[$tax_group_index]['sale_tax_amount'], $item_tax_amount, 4);
|
||||
@@ -328,7 +307,7 @@ class Migration_TaxAmount extends Migration
|
||||
* @param string $string
|
||||
* @return string
|
||||
*/
|
||||
public function clean(string $string): string //TODO: This can probably go into the migration helper as it's used it more than one migration. Also, $string needs to be refactored to a different name.
|
||||
public function clean(string $string): string // TODO: This can probably go into the migration helper as it's used it more than one migration. Also, $string needs to be refactored to a different name.
|
||||
{
|
||||
$string = str_replace(' ', '-', $string); // Replaces all spaces with hyphens.
|
||||
|
||||
@@ -341,11 +320,9 @@ class Migration_TaxAmount extends Migration
|
||||
*/
|
||||
public function apply_invoice_taxing(array &$sales_taxes): void
|
||||
{
|
||||
if(!empty($sales_taxes)) //TODO: Duplicated code
|
||||
{
|
||||
if (!empty($sales_taxes)) { // TODO: Duplicated code
|
||||
$sort = [];
|
||||
foreach($sales_taxes as $k => $v)
|
||||
{
|
||||
foreach ($sales_taxes as $k => $v) {
|
||||
$sort['print_sequence'][$k] = $v['print_sequence'];
|
||||
}
|
||||
array_multisort($sort['print_sequence'], SORT_ASC, $sales_taxes);
|
||||
@@ -353,8 +330,7 @@ class Migration_TaxAmount extends Migration
|
||||
|
||||
$decimals = totals_decimals();
|
||||
|
||||
foreach($sales_taxes as $row_number => $sales_tax)
|
||||
{
|
||||
foreach ($sales_taxes as $row_number => $sales_tax) {
|
||||
$sales_taxes[$row_number]['sale_tax_amount'] = $this->get_sales_tax_for_amount($sales_tax['sale_tax_basis'], $sales_tax['tax_rate'], $sales_tax['rounding_code'], $decimals);
|
||||
}
|
||||
}
|
||||
@@ -365,12 +341,10 @@ class Migration_TaxAmount extends Migration
|
||||
*/
|
||||
public function round_sales_taxes(array &$sales_taxes): void
|
||||
{
|
||||
if(!empty($sales_taxes))
|
||||
{
|
||||
if (!empty($sales_taxes)) {
|
||||
$sort = [];
|
||||
|
||||
foreach($sales_taxes as $k=>$v)
|
||||
{
|
||||
foreach ($sales_taxes as $k => $v) {
|
||||
$sort['print_sequence'][$k] = $v['print_sequence'];
|
||||
}
|
||||
|
||||
@@ -379,31 +353,25 @@ class Migration_TaxAmount extends Migration
|
||||
|
||||
$decimals = totals_decimals();
|
||||
|
||||
foreach($sales_taxes as $row_number => $sales_tax)
|
||||
{
|
||||
foreach ($sales_taxes as $row_number => $sales_tax) {
|
||||
$sale_tax_amount = $sales_tax['sale_tax_amount'];
|
||||
$rounding_code = $sales_tax['rounding_code'];
|
||||
$rounded_sale_tax_amount = $sale_tax_amount;
|
||||
|
||||
if ($rounding_code == PHP_ROUND_HALF_UP //TODO: This block of if/elseif statements can be converted to a switch.
|
||||
if (
|
||||
$rounding_code == PHP_ROUND_HALF_UP // TODO: This block of if/elseif statements can be converted to a switch.
|
||||
|| $rounding_code == PHP_ROUND_HALF_DOWN
|
||||
|| $rounding_code == PHP_ROUND_HALF_EVEN
|
||||
|| $rounding_code == PHP_ROUND_HALF_ODD)
|
||||
{
|
||||
|| $rounding_code == PHP_ROUND_HALF_ODD
|
||||
) {
|
||||
$rounded_sale_tax_amount = round($sale_tax_amount, $decimals, $rounding_code);
|
||||
}
|
||||
elseif($rounding_code == Migration_TaxAmount::ROUND_UP)
|
||||
{
|
||||
} elseif ($rounding_code == Migration_TaxAmount::ROUND_UP) {
|
||||
$fig = (int) str_pad('1', $decimals, '0');
|
||||
$rounded_sale_tax_amount = (ceil($sale_tax_amount * $fig) / $fig);
|
||||
}
|
||||
elseif($rounding_code == Migration_TaxAmount::ROUND_DOWN)
|
||||
{
|
||||
} elseif ($rounding_code == Migration_TaxAmount::ROUND_DOWN) {
|
||||
$fig = (int) str_pad('1', $decimals, '0');
|
||||
$rounded_sale_tax_amount = (floor($sale_tax_amount * $fig) / $fig);
|
||||
}
|
||||
elseif($rounding_code == Migration_TaxAmount::HALF_FIVE)
|
||||
{
|
||||
} elseif ($rounding_code == Migration_TaxAmount::HALF_FIVE) {
|
||||
$rounded_sale_tax_amount = round($sale_tax_amount / 5) * 5;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,9 +13,9 @@ class Migration_image_upload_defaults extends Migration
|
||||
{
|
||||
$image_values = [
|
||||
['key' => 'image_allowed_types', 'value' => 'gif|jpg|png'],
|
||||
['key' => 'image_max_height', 'value' => '480'],
|
||||
['key' => 'image_max_size', 'value' => '128'],
|
||||
['key' => 'image_max_width', 'value' => '640']
|
||||
['key' => 'image_max_height', 'value' => '480'],
|
||||
['key' => 'image_max_size', 'value' => '128'],
|
||||
['key' => 'image_max_width', 'value' => '640']
|
||||
];
|
||||
|
||||
$builder = $this->db->table('app_config');
|
||||
@@ -28,7 +28,7 @@ class Migration_image_upload_defaults extends Migration
|
||||
public function down(): void
|
||||
{
|
||||
$builder = $this->db->table('app_config');
|
||||
$builder->whereIn('key', ['image_allowed_types','image_max_height','image_max_size','image_max_width']);
|
||||
$builder->whereIn('key', ['image_allowed_types', 'image_max_height', 'image_max_size', 'image_max_width']);
|
||||
$builder->delete();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,5 @@ class Migration_modify_attr_links_constraint extends Migration
|
||||
/**
|
||||
* Revert a migration step.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
}
|
||||
public function down(): void {}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,5 @@ class Migration_add_item_kit_number extends Migration
|
||||
/**
|
||||
* Revert a migration step.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
}
|
||||
public function down(): void {}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,5 @@ class Migration_modify_session_datatype extends Migration
|
||||
/**
|
||||
* Revert a migration step.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
}
|
||||
public function down(): void {}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ class Migration_database_optimizations extends Migration
|
||||
$this->migrate_duplicate_attribute_values(DECIMAL);
|
||||
$this->migrate_duplicate_attribute_values(DATE);
|
||||
|
||||
//Select all attributes that have data in more than one column
|
||||
// Select all attributes that have data in more than one column
|
||||
$builder = $this->db->table('attribute_values');
|
||||
$builder->select('attribute_id, attribute_value, attribute_decimal, attribute_date');
|
||||
$builder->groupStart();
|
||||
@@ -40,9 +40,8 @@ class Migration_database_optimizations extends Migration
|
||||
|
||||
$this->db->transStart();
|
||||
|
||||
//Clean up Attribute values table where there is an attribute value and an attribute_date/attribute_decimal
|
||||
foreach($attribute_values->getResultArray() as $attribute_value)
|
||||
{
|
||||
// Clean up Attribute values table where there is an attribute value and an attribute_date/attribute_decimal
|
||||
foreach ($attribute_values->getResultArray() as $attribute_value) {
|
||||
$builder = $this->db->table('attribute_values');
|
||||
$builder->delete(['attribute_id' => $attribute_value['attribute_id']]);
|
||||
|
||||
@@ -52,19 +51,16 @@ class Migration_database_optimizations extends Migration
|
||||
$builder->where('attribute_id', $attribute_value['attribute_id']);
|
||||
$attribute_links = $builder->get();
|
||||
|
||||
if($attribute_links)
|
||||
{
|
||||
if ($attribute_links) {
|
||||
$builder = $this->db->table('attribute_links');
|
||||
$attribute_links = $attribute_links->getResultArray() ?: [];
|
||||
|
||||
foreach($attribute_links->getResultArray() as $attribute_link)
|
||||
{
|
||||
foreach ($attribute_links->getResultArray() as $attribute_link) {
|
||||
$builder->where('attribute_id', $attribute_link['attribute_id']);
|
||||
$builder->where('item_id', $attribute_link['item_id']);
|
||||
$builder->delete();
|
||||
|
||||
switch($attribute_link['definition_type'])
|
||||
{
|
||||
switch ($attribute_link['definition_type']) {
|
||||
case DECIMAL:
|
||||
$value = $attribute_value['attribute_decimal'];
|
||||
break;
|
||||
@@ -94,7 +90,7 @@ class Migration_database_optimizations extends Migration
|
||||
*/
|
||||
private function migrate_duplicate_attribute_values($attribute_type): void
|
||||
{
|
||||
//Remove duplicate attribute values needed to make attribute_decimals and attribute_dates unique
|
||||
// Remove duplicate attribute values needed to make attribute_decimals and attribute_dates unique
|
||||
$this->db->transStart();
|
||||
|
||||
$column = 'attribute_' . strtolower($attribute_type);
|
||||
@@ -105,8 +101,7 @@ class Migration_database_optimizations extends Migration
|
||||
$builder->having("COUNT($column) > 1");
|
||||
$duplicated_values = $builder->get();
|
||||
|
||||
foreach($duplicated_values->getResultArray() as $duplicated_value)
|
||||
{
|
||||
foreach ($duplicated_values->getResultArray() as $duplicated_value) {
|
||||
$subquery_builder = $this->db->table('attribute_values');
|
||||
$subquery_builder->select('attribute_id');
|
||||
$subquery_builder->where($column, $duplicated_value[$column]);
|
||||
@@ -135,16 +130,14 @@ class Migration_database_optimizations extends Migration
|
||||
$attribute_ids = $attribute_ids_to_fix->getResultArray();
|
||||
$retain_attribute_id = $attribute_ids[0]['attribute_id'];
|
||||
|
||||
foreach($attribute_ids as $attribute_id)
|
||||
{
|
||||
//Update attribute_link with the attribute_id we are keeping
|
||||
foreach ($attribute_ids as $attribute_id) {
|
||||
// Update attribute_link with the attribute_id we are keeping
|
||||
$builder = $this->db->table('attribute_links');
|
||||
$builder->where('attribute_id', $attribute_id['attribute_id']);
|
||||
$builder->update(['attribute_id' => $retain_attribute_id]);
|
||||
|
||||
//Delete the row from attribute_values if it isn't our keeper
|
||||
if($attribute_id['attribute_id'] !== $retain_attribute_id)
|
||||
{
|
||||
// Delete the row from attribute_values if it isn't our keeper
|
||||
if ($attribute_id['attribute_id'] !== $retain_attribute_id) {
|
||||
$builder = $this->db->table('attribute_values');
|
||||
$builder->delete(['attribute_id' => $attribute_id['attribute_id']]);
|
||||
}
|
||||
@@ -154,7 +147,5 @@ class Migration_database_optimizations extends Migration
|
||||
/**
|
||||
* Revert a migration step.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
}
|
||||
public function down(): void {}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ class Migration_remove_duplicate_links extends Migration
|
||||
{
|
||||
$attribute = model(Attribute::class);
|
||||
|
||||
//Remove duplicate attribute links
|
||||
// Remove duplicate attribute links
|
||||
$this->db->transStart();
|
||||
|
||||
$builder = $this->db->table('attribute_links');
|
||||
@@ -43,8 +43,7 @@ class Migration_remove_duplicate_links extends Migration
|
||||
|
||||
$builder = $this->db->table('attribute_links');
|
||||
|
||||
foreach($duplicated_links->getResultArray() as $duplicated_link)
|
||||
{
|
||||
foreach ($duplicated_links->getResultArray() as $duplicated_link) {
|
||||
$builder->where('sale_id', null);
|
||||
$builder->where('receiving_id', null);
|
||||
$builder->where('item_id', $duplicated_link['item_id']);
|
||||
@@ -60,7 +59,5 @@ class Migration_remove_duplicate_links extends Migration
|
||||
/**
|
||||
* Revert a migration step.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
}
|
||||
public function down(): void {}
|
||||
}
|
||||
|
||||
@@ -21,8 +21,5 @@ class Migration_move_expenses_categories extends Migration
|
||||
/**
|
||||
* Revert a migration step.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
|
||||
}
|
||||
public function down(): void {}
|
||||
}
|
||||
|
||||
@@ -32,12 +32,9 @@ class Convert_to_ci4 extends Migration
|
||||
helper('migration');
|
||||
execute_script(APPPATH . 'Database/Migrations/sqlscripts/3.4.0_ci4_conversion.sql');
|
||||
|
||||
if(!empty(config('Encryption')->key))
|
||||
{
|
||||
if (!empty(config('Encryption')->key)) {
|
||||
$this->convert_ci3_encrypted_data();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
check_encryption();
|
||||
}
|
||||
|
||||
@@ -49,10 +46,7 @@ class Convert_to_ci4 extends Migration
|
||||
/**
|
||||
* Revert a migration step.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
|
||||
}
|
||||
public function down(): void {}
|
||||
|
||||
/**
|
||||
* @return RedirectResponse|void
|
||||
@@ -63,15 +57,14 @@ class Convert_to_ci4 extends Migration
|
||||
$appconfig = model(Appconfig::class);
|
||||
|
||||
$ci3_encrypted_data = [
|
||||
'clcdesq_api_key' => '',
|
||||
'clcdesq_api_url' => '',
|
||||
'clcdesq_api_key' => '',
|
||||
'clcdesq_api_url' => '',
|
||||
'mailchimp_api_key' => '',
|
||||
'mailchimp_list_id' => '',
|
||||
'smtp_pass' => ''
|
||||
'smtp_pass' => ''
|
||||
];
|
||||
|
||||
foreach($ci3_encrypted_data as $key => $value)
|
||||
{
|
||||
foreach ($ci3_encrypted_data as $key => $value) {
|
||||
$ci3_encrypted_data[$key] = $appconfig->get_value($key);
|
||||
}
|
||||
|
||||
@@ -79,22 +72,19 @@ class Convert_to_ci4 extends Migration
|
||||
|
||||
check_encryption();
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
$ci4_encrypted_data = $this->encrypt_data($decrypted_data);
|
||||
|
||||
$success = empty(array_diff_assoc($decrypted_data, $this->decrypt_data($ci4_encrypted_data)));
|
||||
if(!$success)
|
||||
{
|
||||
if (!$success) {
|
||||
abort_encryption_conversion();
|
||||
remove_backup();
|
||||
throw new RedirectException('login');
|
||||
}
|
||||
|
||||
$appconfig->batch_save($ci4_encrypted_data);
|
||||
} catch(RedirectException $e)
|
||||
{
|
||||
return redirect()->to('login'); //TODO: Need to figure out how to pass the error to the Login controller so that it gets displayed.
|
||||
} catch (RedirectException $e) {
|
||||
return redirect()->to('login'); // TODO: Need to figure out how to pass the error to the Login controller so that it gets displayed.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,9 +107,8 @@ class Convert_to_ci4 extends Migration
|
||||
$encrypter = Services::encrypter($config);
|
||||
|
||||
$decrypted_data = [];
|
||||
foreach($encrypted_data as $key => $value)
|
||||
{
|
||||
$decrypted_data[$key] = !empty($value) ? $encrypter->decrypt($value): '';
|
||||
foreach ($encrypted_data as $key => $value) {
|
||||
$decrypted_data[$key] = !empty($value) ? $encrypter->decrypt($value) : '';
|
||||
}
|
||||
|
||||
return $decrypted_data;
|
||||
@@ -136,8 +125,7 @@ class Convert_to_ci4 extends Migration
|
||||
$encrypter = Services::encrypter();
|
||||
|
||||
$encrypted_data = [];
|
||||
foreach($plain_data as $key => $value)
|
||||
{
|
||||
foreach ($plain_data as $key => $value) {
|
||||
$encrypted_data[$key] = !empty($value) ? $encrypter->encrypt($value) : '';
|
||||
}
|
||||
|
||||
@@ -155,8 +143,7 @@ class Convert_to_ci4 extends Migration
|
||||
$encrypter = Services::encrypter();
|
||||
|
||||
$decrypted_data = [];
|
||||
foreach($encrypted_data as $key => $value)
|
||||
{
|
||||
foreach ($encrypted_data as $key => $value) {
|
||||
$decrypted_data[$key] = !empty($value) ? $encrypter->decrypt($value) : '';
|
||||
}
|
||||
|
||||
|
||||
@@ -1,27 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Database\Migrations;
|
||||
|
||||
use CodeIgniter\Database\Migration;
|
||||
|
||||
class IntToTinyint extends Migration
|
||||
{
|
||||
/**
|
||||
* Perform a migration step.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
$this->db->query('ALTER TABLE ' . $this->db->prefixTable('customers') . ' MODIFY `consent` tinyint NOT NULL DEFAULT 0');
|
||||
$this->db->query('ALTER TABLE ' . $this->db->prefixTable('cash_up') . ' MODIFY `note` tinyint NOT NULL DEFAULT 0');
|
||||
}
|
||||
|
||||
/**
|
||||
* Revert a migration step.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
$this->db->query('ALTER TABLE ' . $this->db->prefixTable('customers') . ' MODIFY `consent` int NOT NULL DEFAULT 0');
|
||||
$this->db->query('ALTER TABLE ' . $this->db->prefixTable('cash_up') . ' MODIFY `note` int NOT NULL DEFAULT 0');
|
||||
|
||||
}
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace App\Database\Migrations;
|
||||
|
||||
use CodeIgniter\Database\Migration;
|
||||
|
||||
class IntToTinyint extends Migration
|
||||
{
|
||||
/**
|
||||
* Perform a migration step.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
$this->db->query('ALTER TABLE ' . $this->db->prefixTable('customers') . ' MODIFY `consent` tinyint NOT NULL DEFAULT 0');
|
||||
$this->db->query('ALTER TABLE ' . $this->db->prefixTable('cash_up') . ' MODIFY `note` tinyint NOT NULL DEFAULT 0');
|
||||
}
|
||||
|
||||
/**
|
||||
* Revert a migration step.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
$this->db->query('ALTER TABLE ' . $this->db->prefixTable('customers') . ' MODIFY `consent` int NOT NULL DEFAULT 0');
|
||||
$this->db->query('ALTER TABLE ' . $this->db->prefixTable('cash_up') . ' MODIFY `note` int NOT NULL DEFAULT 0');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,14 +12,14 @@ class Migration_add_missing_config extends Migration
|
||||
public function up(): void
|
||||
{
|
||||
$image_values = [
|
||||
['key' => 'account_number', 'value' => ''], // This has no current maintenance, but it's used in Sales
|
||||
['key' => 'category_dropdown', 'value' => ''],
|
||||
['key' => 'smtp_host', 'value' => ''],
|
||||
['key' => 'smtp_user', 'value' => ''],
|
||||
['key' => 'smtp_pass', 'value' => ''],
|
||||
['key' => 'login_form', 'value' => ''],
|
||||
['key' => 'account_number', 'value' => ''], // This has no current maintenance, but it's used in Sales
|
||||
['key' => 'category_dropdown', 'value' => ''],
|
||||
['key' => 'smtp_host', 'value' => ''],
|
||||
['key' => 'smtp_user', 'value' => ''],
|
||||
['key' => 'smtp_pass', 'value' => ''],
|
||||
['key' => 'login_form', 'value' => ''],
|
||||
['key' => 'receiving_calculate_average_price', 'value' => ''],
|
||||
['key' => 'payment_message', 'value' => '']
|
||||
['key' => 'payment_message', 'value' => '']
|
||||
];
|
||||
|
||||
$this->db->table('app_config')->ignore(true)->insertBatch($image_values);
|
||||
@@ -30,6 +30,6 @@ class Migration_add_missing_config extends Migration
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
// no need to remove necessary config values.
|
||||
// No need to remove necessary config values.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,8 +28,7 @@ class Migration_Convert_Barcode_Types extends Migration
|
||||
|
||||
$old_barcode_type = $this->config['barcode_type'];
|
||||
|
||||
switch($old_barcode_type)
|
||||
{
|
||||
switch ($old_barcode_type) {
|
||||
case 'Code39':
|
||||
$new_barcode_type = 'C39';
|
||||
break;
|
||||
@@ -55,8 +54,7 @@ class Migration_Convert_Barcode_Types extends Migration
|
||||
{
|
||||
$new_barcode_type = $this->config['barcode_type'];
|
||||
|
||||
switch($new_barcode_type)
|
||||
{
|
||||
switch ($new_barcode_type) {
|
||||
case 'C39':
|
||||
$old_barcode_type = 'Code39';
|
||||
break;
|
||||
|
||||
@@ -5,7 +5,8 @@ namespace App\Database\Migrations;
|
||||
use CodeIgniter\Database\Migration;
|
||||
use Config\Database;
|
||||
|
||||
class Migration_fix_keys_for_db_upgrade extends Migration {
|
||||
class Migration_fix_keys_for_db_upgrade extends Migration
|
||||
{
|
||||
/**
|
||||
* Perform a migration step.
|
||||
*/
|
||||
@@ -13,16 +14,14 @@ class Migration_fix_keys_for_db_upgrade extends Migration {
|
||||
{
|
||||
$this->db->query("ALTER TABLE `ospos_tax_codes` MODIFY `deleted` tinyint(1) DEFAULT 0 NOT NULL;");
|
||||
|
||||
if (!$this->index_exists('ospos_customers', 'company_name'))
|
||||
{
|
||||
if (!$this->index_exists('ospos_customers', 'company_name')) {
|
||||
$this->db->query("ALTER TABLE `ospos_customers` ADD INDEX(`company_name`)");
|
||||
}
|
||||
|
||||
$checkSql = "SELECT CONSTRAINT_NAME FROM information_schema.TABLE_CONSTRAINTS WHERE CONSTRAINT_SCHEMA = DATABASE() AND TABLE_NAME = '" . $this->db->prefixTable('sales_items_taxes') . "' AND CONSTRAINT_NAME = 'ospos_sales_items_taxes_ibfk_1'";
|
||||
$foreignKeyExists = $this->db->query($checkSql)->getRow();
|
||||
|
||||
if ($foreignKeyExists)
|
||||
{
|
||||
if ($foreignKeyExists) {
|
||||
$this->db->query('ALTER TABLE ' . $this->db->prefixTable('sales_items_taxes') . ' DROP FOREIGN KEY ospos_sales_items_taxes_ibfk_1');
|
||||
}
|
||||
|
||||
@@ -44,8 +43,7 @@ class Migration_fix_keys_for_db_upgrade extends Migration {
|
||||
$checkSql = "SELECT CONSTRAINT_NAME FROM information_schema.TABLE_CONSTRAINTS WHERE CONSTRAINT_SCHEMA = DATABASE() AND TABLE_NAME = '" . $this->db->prefixTable('sales_items_taxes') . "' AND CONSTRAINT_NAME = 'ospos_sales_items_taxes_ibfk_1'";
|
||||
$foreignKeyExists = $this->db->query($checkSql)->getRow();
|
||||
|
||||
if ($foreignKeyExists)
|
||||
{
|
||||
if ($foreignKeyExists) {
|
||||
$this->db->query('ALTER TABLE ' . $this->db->prefixTable('sales_items_taxes') . ' DROP CONSTRAINT ospos_sales_items_taxes_ibfk_1');
|
||||
}
|
||||
|
||||
@@ -58,12 +56,10 @@ class Migration_fix_keys_for_db_upgrade extends Migration {
|
||||
{
|
||||
$result = $this->db->query('SELECT 1 FROM information_schema.columns WHERE table_schema = DATABASE() AND table_name= \'' . $this->db->getPrefix() . "$table' AND column_key = '$index'");
|
||||
|
||||
if ( ! $result->getRowArray())
|
||||
{
|
||||
if (! $result->getRowArray()) {
|
||||
$this->delete_index($table, $index);
|
||||
$forge = Database::forge();
|
||||
$forge->addPrimaryKey($table, '');
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,8 +73,7 @@ class Migration_fix_keys_for_db_upgrade extends Migration {
|
||||
private function delete_index(string $table, string $index): void
|
||||
{
|
||||
|
||||
if ($this->index_exists($table, $index))
|
||||
{
|
||||
if ($this->index_exists($table, $index)) {
|
||||
$forge = Database::forge();
|
||||
$forge->dropKey($table, $index, FALSE);
|
||||
}
|
||||
|
||||
@@ -58,9 +58,8 @@ class fix_duplicate_attributes extends Migration
|
||||
private function remove_duplicate_attributes(ResultInterface $rows_to_keep): void
|
||||
{
|
||||
$attribute = model(Attribute::class);
|
||||
foreach($rows_to_keep->getResult() as $row)
|
||||
{
|
||||
$attribute->deleteAttributeLinks($row->item_id, $row->definition_id); //Deletes all attribute links for the item_id/definition_id combination
|
||||
foreach ($rows_to_keep->getResult() as $row) {
|
||||
$attribute->deleteAttributeLinks($row->item_id, $row->definition_id); // Deletes all attribute links for the item_id/definition_id combination
|
||||
$attribute->saveAttributeLink($row->item_id, $row->definition_id, $row->attribute_id);
|
||||
}
|
||||
}
|
||||
@@ -69,8 +68,5 @@ class fix_duplicate_attributes extends Migration
|
||||
/**
|
||||
* Revert a migration step.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
|
||||
}
|
||||
public function down(): void {}
|
||||
}
|
||||
|
||||
@@ -22,8 +22,5 @@ class Migration_Attributes_fix_cascading_delete extends Migration
|
||||
/**
|
||||
* Revert a migration step.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
|
||||
}
|
||||
public function down(): void {}
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ INSERT INTO `ospos_grants` (`permission_id`, `person_id`, `menu_group`) VALUES
|
||||
|
||||
-- Add columns to save per-user language selection
|
||||
|
||||
ALTER TABLE `ospos_employees`
|
||||
ALTER TABLE `ospos_employees`
|
||||
ADD COLUMN `language` VARCHAR(48) DEFAULT NULL,
|
||||
ADD COLUMN `language_code` VARCHAR(8) DEFAULT NULL;
|
||||
|
||||
@@ -125,13 +125,13 @@ INSERT INTO `ospos_modules` (`name_lang_key`, `desc_lang_key`, `sort`, `module_i
|
||||
INSERT INTO `ospos_permissions` (`permission_id`, `module_id`) VALUES
|
||||
('expenses_categories', 'expenses_categories'),
|
||||
('expenses', 'expenses'),
|
||||
('reports_expenses_categories', 'reports');
|
||||
('reports_expenses_categories', 'reports');
|
||||
|
||||
INSERT INTO `ospos_grants` (`permission_id`, `person_id`) VALUES
|
||||
INSERT INTO `ospos_grants` (`permission_id`, `person_id`) VALUES
|
||||
('expenses', 1),
|
||||
('expenses_categories', 1),
|
||||
('reports_expenses_categories', 1);
|
||||
|
||||
|
||||
|
||||
-- Table structure for table `ospos_expense_categories`
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
-- Add columns to customer table for tracking purposes and explicit consent of data registration
|
||||
|
||||
ALTER TABLE `ospos_customers`
|
||||
ALTER TABLE `ospos_customers`
|
||||
ADD COLUMN `date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
ADD COLUMN `employee_id` int(10) NOT NULL,
|
||||
ADD COLUMN `consent` int(1) NOT NULL DEFAULT '0';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
INSERT INTO
|
||||
INSERT INTO
|
||||
`ospos_app_config` (`key`,`value`)
|
||||
VALUES
|
||||
('currency_code','');
|
||||
|
||||
@@ -180,5 +180,5 @@ ALTER TABLE `ospos_items`
|
||||
DROP COLUMN `custom8`,
|
||||
DROP COLUMN `custom9`,
|
||||
DROP COLUMN `custom10`;
|
||||
|
||||
|
||||
DELETE FROM `ospos_app_config` WHERE `key` IN ('custom1_name','custom2_name','custom3_name','custom4_name','custom5_name','custom6_name','custom7_name','custom8_name','custom9_name','custom10_name');
|
||||
|
||||
@@ -2,4 +2,4 @@ ALTER TABLE ospos_attribute_values
|
||||
ADD COLUMN attribute_decimal DECIMAL(7,3) DEFAULT NULL AFTER attribute_datetime;
|
||||
|
||||
ALTER TABLE ospos_attribute_definitions
|
||||
ADD COLUMN definition_unit VARCHAR(16) DEFAULT NULL AFTER definition_type;
|
||||
ADD COLUMN definition_unit VARCHAR(16) DEFAULT NULL AFTER definition_type;
|
||||
|
||||
@@ -1 +1 @@
|
||||
ALTER TABLE `ospos_attribute_values` CHANGE `attribute_datetime` `attribute_date` DATE DEFAULT NULL;
|
||||
ALTER TABLE `ospos_attribute_values` CHANGE `attribute_datetime` `attribute_date` DATE DEFAULT NULL;
|
||||
|
||||
@@ -2,4 +2,4 @@
|
||||
|
||||
DROP TABLE IF EXISTS `ospos_tax_codes_backup`;
|
||||
DROP TABLE IF EXISTS `ospos_sales_taxes_backup`;
|
||||
DROP TABLE IF EXISTS `ospos_tax_code_rates_backup`;
|
||||
DROP TABLE IF EXISTS `ospos_tax_code_rates_backup`;
|
||||
|
||||
@@ -5,4 +5,4 @@ ALTER TABLE `ospos_attribute_links`
|
||||
ADD CONSTRAINT `ospos_attribute_links_ibfk_4`
|
||||
FOREIGN KEY (`receiving_id`) REFERENCES `ospos_receivings`(`receiving_id`)
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE RESTRICT;
|
||||
ON UPDATE RESTRICT;
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
ALTER TABLE `ospos_item_kits`
|
||||
ADD COLUMN `item_kit_number` VARCHAR(255) DEFAULT NULL AFTER `item_kit_id`,
|
||||
ADD KEY `item_kit_number` (`item_kit_number`);
|
||||
ADD KEY `item_kit_number` (`item_kit_number`);
|
||||
|
||||
@@ -7,7 +7,7 @@ ALTER TABLE ospos_items MODIFY reorder_level decimal(15,0);
|
||||
|
||||
ALTER TABLE ospos_items_taxes MODIFY percent decimal(15,2);
|
||||
|
||||
ALTER TABLE ospos_item_kit_items MODIFY quantity decimal(15,0);
|
||||
ALTER TABLE ospos_item_kit_items MODIFY quantity decimal(15,0);
|
||||
|
||||
ALTER TABLE ospos_receivings_items MODIFY quantity_purchased decimal(15,0);
|
||||
ALTER TABLE ospos_receivings_items MODIFY item_unit_price decimal(15,2);
|
||||
|
||||
@@ -26,18 +26,18 @@ UPDATE `ospos_inventory` SET trans_location = (SELECT MIN(`location_id`) FROM `o
|
||||
ALTER TABLE `ospos_inventory`
|
||||
MODIFY COLUMN trans_location int(11) NOT NULL,
|
||||
ADD KEY `trans_location` (`trans_location`),
|
||||
ADD CONSTRAINT `ospos_inventory_ibfk_3` FOREIGN KEY (`trans_location`) REFERENCES `ospos_stock_locations` (`location_id`);
|
||||
ADD CONSTRAINT `ospos_inventory_ibfk_3` FOREIGN KEY (`trans_location`) REFERENCES `ospos_stock_locations` (`location_id`);
|
||||
|
||||
ALTER TABLE `ospos_receivings_items`
|
||||
ADD COLUMN item_location int(11);
|
||||
|
||||
|
||||
UPDATE `ospos_receivings_items` SET item_location = (SELECT MIN(`location_id`) FROM `ospos_stock_locations`);
|
||||
|
||||
ALTER TABLE ospos_receivings_items
|
||||
MODIFY COLUMN `item_location` INT(11) NOT NULL,
|
||||
ADD KEY `item_location` (`item_location`),
|
||||
ADD CONSTRAINT `ospos_receivings_items_ibfk_3` FOREIGN KEY (`item_location`) REFERENCES `ospos_stock_locations` (`location_id`);
|
||||
|
||||
|
||||
ALTER TABLE `ospos_sales_items`
|
||||
ADD COLUMN `item_location` int(11);
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
INSERT INTO `ospos_app_config` (`key`, `value`) VALUES
|
||||
INSERT INTO `ospos_app_config` (`key`, `value`) VALUES
|
||||
('barcode_content', 'id'),
|
||||
('barcode_first_row', 'category'),
|
||||
('barcode_second_row', 'item_code'),
|
||||
@@ -11,7 +11,7 @@ INSERT INTO `ospos_app_config` (`key`, `value`) VALUES
|
||||
('barcode_type', 'Code39'),
|
||||
('barcode_width', '250'),
|
||||
('company_logo', ''),
|
||||
('barcode_page_width', '100'),
|
||||
('barcode_page_width', '100'),
|
||||
('barcode_page_cellspacing', '20'),
|
||||
('receipt_show_taxes', '0'),
|
||||
('use_invoice_template', '1'),
|
||||
@@ -28,24 +28,24 @@ INSERT INTO `ospos_app_config` (`key`, `value`) VALUES
|
||||
('lines_per_page', '25'),
|
||||
('show_total_discount', '25');
|
||||
|
||||
INSERT IGNORE INTO `ospos_permissions` (permission_id, module_id, location_id)
|
||||
INSERT IGNORE INTO `ospos_permissions` (permission_id, module_id, location_id)
|
||||
(SELECT CONCAT('sales_', location_name), 'sales', location_id FROM ospos_stock_locations);
|
||||
|
||||
INSERT IGNORE INTO `ospos_permissions` (permission_id, module_id, location_id)
|
||||
(SELECT CONCAT('receivings_', location_name), 'receivings', location_id FROM ospos_stock_locations);
|
||||
|
||||
-- add item_pic column to items table
|
||||
ALTER TABLE `ospos_items`
|
||||
ALTER TABLE `ospos_items`
|
||||
ADD COLUMN `item_pic` int(10) DEFAULT NULL;
|
||||
|
||||
ALTER TABLE `ospos_people`
|
||||
ALTER TABLE `ospos_people`
|
||||
ADD COLUMN `gender` int(1) DEFAULT NULL;
|
||||
|
||||
|
||||
-- drop redundant payment_type column in sales, add index to sale_time to speed up sorting
|
||||
ALTER TABLE `ospos_sales`
|
||||
DROP COLUMN `payment_type`,
|
||||
ADD INDEX `sale_time` (`sale_time`);
|
||||
|
||||
|
||||
ALTER TABLE `ospos_customers`
|
||||
ADD COLUMN `company_name` varchar(255) DEFAULT NULL;
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ INSERT INTO `ospos_app_config` (`key`, `value`) VALUES
|
||||
ALTER TABLE `ospos_sales_suspended`
|
||||
DROP KEY `invoice_number`;
|
||||
|
||||
ALTER TABLE `ospos_items`
|
||||
ALTER TABLE `ospos_items`
|
||||
CHANGE COLUMN `item_pic` `pic_id` int(10) DEFAULT NULL;
|
||||
|
||||
-- Clear out emptied comments (0 inserted in comment if empty #192)
|
||||
|
||||
@@ -7,4 +7,4 @@ CREATE TABLE `ospos_sessions` (
|
||||
`data` blob NOT NULL,
|
||||
`timestamp` int(10) unsigned NOT NULL DEFAULT '0',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
@@ -39,7 +39,7 @@ INSERT INTO `ospos_permissions` (`permission_id`, `module_id`) VALUES
|
||||
('receivings_stock', 'receivings');
|
||||
|
||||
-- add permissions for existing stock locations
|
||||
INSERT INTO `ospos_permissions` (permission_id, module_id, location_id)
|
||||
INSERT INTO `ospos_permissions` (permission_id, module_id, location_id)
|
||||
(SELECT CONCAT('items_', location_name), 'items', location_id FROM ospos_stock_locations);
|
||||
|
||||
CREATE TABLE `ospos_grants` (
|
||||
@@ -50,21 +50,21 @@ CREATE TABLE `ospos_grants` (
|
||||
|
||||
ALTER TABLE `ospos_grants`
|
||||
ADD CONSTRAINT `ospos_grants_ibfk_2` foreign key (`person_id`) references `ospos_employees` (`person_id`) ON DELETE CASCADE,
|
||||
ADD CONSTRAINT `ospos_grants_ibfk_1` FOREIGN KEY (`permission_id`) REFERENCES `ospos_permissions`(`permission_id`) ON DELETE CASCADE;
|
||||
ADD CONSTRAINT `ospos_grants_ibfk_1` FOREIGN KEY (`permission_id`) REFERENCES `ospos_permissions`(`permission_id`) ON DELETE CASCADE;
|
||||
|
||||
-- add grants for all employees
|
||||
INSERT INTO `ospos_grants` (`permission_id`, `person_id`) VALUES
|
||||
('reports_customers', 1),
|
||||
('reports_receivings', 1),
|
||||
('reports_receivings', 1),
|
||||
('reports_items', 1),
|
||||
('reports_inventory', 1),
|
||||
('reports_employees', 1),
|
||||
('reports_suppliers', 1),
|
||||
('reports_sales', 1),
|
||||
('reports_categories', 1),
|
||||
('reports_discounts', 1),
|
||||
('reports_payments', 1),
|
||||
('reports_taxes', 1),
|
||||
('reports_discounts', 1),
|
||||
('reports_payments', 1),
|
||||
('reports_taxes', 1),
|
||||
('customers', 1),
|
||||
('employees', 1),
|
||||
('giftcards', 1),
|
||||
@@ -80,28 +80,28 @@ INSERT INTO `ospos_grants` (`permission_id`, `person_id`) VALUES
|
||||
('suppliers', 1);
|
||||
|
||||
-- add config options for tax inclusive sales
|
||||
INSERT INTO `ospos_app_config` (`key`, `value`) VALUES
|
||||
INSERT INTO `ospos_app_config` (`key`, `value`) VALUES
|
||||
('tax_included', '0'),
|
||||
('recv_invoice_format', '$CO'),
|
||||
('sales_invoice_format', '$CO');
|
||||
|
||||
-- add invoice_number column to receivings table
|
||||
ALTER TABLE `ospos_receivings`
|
||||
ALTER TABLE `ospos_receivings`
|
||||
ADD COLUMN `invoice_number` varchar(32) DEFAULT NULL,
|
||||
ADD UNIQUE `invoice_number` (`invoice_number`);
|
||||
|
||||
-- add invoice_number column to sales table
|
||||
ALTER TABLE `ospos_sales`
|
||||
ALTER TABLE `ospos_sales`
|
||||
ADD COLUMN `invoice_number` varchar(32) DEFAULT NULL,
|
||||
ADD UNIQUE `invoice_number` (`invoice_number`);
|
||||
|
||||
-- add invoice_number column to suspended sales table
|
||||
ALTER TABLE `ospos_sales_suspended`
|
||||
ALTER TABLE `ospos_sales_suspended`
|
||||
ADD COLUMN `invoice_number` varchar(32) DEFAULT NULL,
|
||||
ADD UNIQUE `invoice_number` (`invoice_number`);
|
||||
|
||||
|
||||
-- add invoice_number column to receivings table
|
||||
ALTER TABLE `ospos_items`
|
||||
ALTER TABLE `ospos_items`
|
||||
ADD COLUMN `receiving_quantity` int(11) DEFAULT '1',
|
||||
DROP COLUMN `quantity`;
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ SELECT `key`, `value` FROM `phppos`.phppos_app_config WHERE `key` = 'return_pol
|
||||
--
|
||||
|
||||
INSERT INTO `ospos_customers` (`person_id`, `account_number`, `taxable`, `deleted`)
|
||||
SELECT `person_id`, `account_number`, `taxable`, `deleted` FROM `phppos`.phppos_customers;
|
||||
SELECT `person_id`, `account_number`, `taxable`, `deleted` FROM `phppos`.phppos_customers;
|
||||
UPDATE `ospos_customers` c1, `ospos_customers` c2 SET `c1`.`account_number` = NULL WHERE `c1`.`person_id` > `c2`.`person_id` AND `c1`.`account_number` = `c2`.`account_number`;
|
||||
|
||||
--
|
||||
@@ -69,7 +69,7 @@ SELECT `giftcard_id`, `giftcard_number`, `value`, `deleted`, `person_id` FROM `p
|
||||
-- Copy data to table `ospos_inventory`
|
||||
--
|
||||
|
||||
INSERT INTO `ospos_inventory` (`trans_id`, `trans_items`, `trans_user`, `trans_date`, `trans_comment`, `trans_location`, `trans_inventory`)
|
||||
INSERT INTO `ospos_inventory` (`trans_id`, `trans_items`, `trans_user`, `trans_date`, `trans_comment`, `trans_location`, `trans_inventory`)
|
||||
SELECT `trans_id`, `trans_items`, `trans_user`, `trans_date`, `trans_comment`, 1, `trans_inventory` FROM `phppos`.phppos_inventory;
|
||||
|
||||
--
|
||||
@@ -111,21 +111,21 @@ SELECT `first_name`, `last_name`, `phone_number`, `email`, `address_1`, `address
|
||||
-- Copy data to table `ospos_receivings`
|
||||
--
|
||||
|
||||
INSERT INTO `ospos_receivings` (`receiving_time`, `supplier_id`, `employee_id`, `comment`, `receiving_id`, `payment_type`, `reference`)
|
||||
INSERT INTO `ospos_receivings` (`receiving_time`, `supplier_id`, `employee_id`, `comment`, `receiving_id`, `payment_type`, `reference`)
|
||||
SELECT `receiving_time`, `supplier_id`, `employee_id`, `comment`, `receiving_id`, `payment_type`, NULL FROM `phppos`.phppos_receivings;
|
||||
|
||||
--
|
||||
-- Copy data to table `ospos_receivings_items`
|
||||
--
|
||||
|
||||
INSERT INTO `ospos_receivings_items` (`receiving_id`, `item_id`, `description`, `serialnumber`, `line`, `quantity_purchased`, `item_cost_price`, `item_unit_price`, `discount_percent`, `item_location`)
|
||||
INSERT INTO `ospos_receivings_items` (`receiving_id`, `item_id`, `description`, `serialnumber`, `line`, `quantity_purchased`, `item_cost_price`, `item_unit_price`, `discount_percent`, `item_location`)
|
||||
SELECT `receiving_id`, `item_id`, `description`, `serialnumber`, `line`, `quantity_purchased`, `item_cost_price`, `item_unit_price`, `discount_percent`, 1 FROM `phppos`.phppos_receivings_items;
|
||||
|
||||
--
|
||||
-- Copy data to table `ospos_sales`
|
||||
--
|
||||
|
||||
INSERT INTO `ospos_sales` (`sale_time`, `customer_id`, `employee_id`, `comment`, `sale_id`, `invoice_number`)
|
||||
INSERT INTO `ospos_sales` (`sale_time`, `customer_id`, `employee_id`, `comment`, `sale_id`, `invoice_number`)
|
||||
SELECT `sale_time`, `customer_id`, `employee_id`, `comment`, `sale_id`, NULL FROM `phppos`.phppos_sales;
|
||||
|
||||
--
|
||||
@@ -139,14 +139,14 @@ SELECT `sale_id`, `item_id`, `description`, `serialnumber`, `line`, `quantity_pu
|
||||
-- Copy data to table `ospos_sales_items_taxes`
|
||||
--
|
||||
|
||||
INSERT INTO `ospos_sales_items_taxes` (`sale_id`, `item_id`, `line`, `name`, `percent`)
|
||||
INSERT INTO `ospos_sales_items_taxes` (`sale_id`, `item_id`, `line`, `name`, `percent`)
|
||||
SELECT `sale_id`, `item_id`, `line`, `name`, `percent` FROM `phppos`.phppos_sales_items_taxes;
|
||||
|
||||
--
|
||||
-- Copy data to table `ospos_sales_payments`
|
||||
--
|
||||
|
||||
INSERT INTO `ospos_sales_payments` (`sale_id`, `payment_type`, `payment_amount`)
|
||||
INSERT INTO `ospos_sales_payments` (`sale_id`, `payment_type`, `payment_amount`)
|
||||
SELECT `sale_id`, `payment_type`, `payment_amount` FROM `phppos`.phppos_sales_payments;
|
||||
|
||||
--
|
||||
@@ -163,9 +163,9 @@ SELECT `item_id`, 1, `quantity` FROM `phppos`.`phppos_items`;
|
||||
INSERT INTO `ospos_suppliers` (`person_id`, `company_name`, `account_number`, `deleted`)
|
||||
SELECT `person_id`, `company_name`, `account_number`, `deleted` FROM `phppos`.phppos_suppliers;
|
||||
|
||||
--
|
||||
--
|
||||
-- Copy data to table `ospos_dinner_tables`
|
||||
--
|
||||
|
||||
INSERT INTO `ospos_dinner_tables` (`dinner_table_id`, `name`, `status`, `deleted`)
|
||||
SELECT `dinner_table_id`, `name`, `status`, `deleted` FROM `phppos`.phppos_dinner_tables;
|
||||
SELECT `dinner_table_id`, `name`, `status`, `deleted` FROM `phppos`.phppos_dinner_tables;
|
||||
|
||||
@@ -26,4 +26,4 @@ RENAME TABLE `ospos_sales_suspended_items_taxes` TO `phppos_sales_suspended_item
|
||||
RENAME TABLE `ospos_sales_suspended_payments` TO `phppos_sales_suspended_payments`;
|
||||
RENAME TABLE `ospos_sessions` TO `phppos_sessions`;
|
||||
RENAME TABLE `ospos_suppliers` TO `phppos_suppliers`;
|
||||
RENAME TABLE `ospos_dinner_tables` TO `phppos_dinner_tables`;
|
||||
RENAME TABLE `ospos_dinner_tables` TO `phppos_dinner_tables`;
|
||||
|
||||
@@ -16,14 +16,12 @@ class Db_log
|
||||
{
|
||||
$this->config = config('App');
|
||||
|
||||
if($this->config->db_log_enabled)
|
||||
{
|
||||
if ($this->config->db_log_enabled) {
|
||||
$filepath = WRITEPATH . 'logs/Query-log-' . date('Y-m-d') . '.log';
|
||||
$handle = fopen($filepath, "a+");
|
||||
$message = $this->generate_message();
|
||||
|
||||
if(strlen($message) > 0)
|
||||
{
|
||||
if (strlen($message) > 0) {
|
||||
fwrite($handle, $message . "\n\n");
|
||||
}
|
||||
|
||||
@@ -48,8 +46,7 @@ class Db_log
|
||||
. "\n Execution Time: " . $execution_time['time'] . ' ' . $execution_time['unit'];
|
||||
|
||||
$long_query = ($execution_time['unit'] === 's') && ($execution_time['time'] > 0.5);
|
||||
if($long_query)
|
||||
{
|
||||
if ($long_query) {
|
||||
$message .= ' [LONG RUNNING QUERY]';
|
||||
}
|
||||
|
||||
@@ -64,13 +61,10 @@ class Db_log
|
||||
{
|
||||
$unit = 's';
|
||||
|
||||
if($time <= 0.1 && $time > 0.0001)
|
||||
{
|
||||
if ($time <= 0.1 && $time > 0.0001) {
|
||||
$time = $time * 1000;
|
||||
$unit = 'ms';
|
||||
}
|
||||
elseif($time <= 0.0001)
|
||||
{
|
||||
} elseif ($time <= 0.0001) {
|
||||
$time = $time * 1000000;
|
||||
$unit = 'µs';
|
||||
}
|
||||
|
||||
@@ -24,25 +24,23 @@ class Load_config
|
||||
*/
|
||||
public function load_config(): void
|
||||
{
|
||||
//Migrations
|
||||
// Migrations
|
||||
$migration_config = config('Migrations');
|
||||
$migration = new MY_Migration($migration_config);
|
||||
|
||||
$this->session = session();
|
||||
|
||||
//Database Configuration
|
||||
// Database Configuration
|
||||
$config = config(OSPOS::class);
|
||||
|
||||
if (!$migration->is_latest())
|
||||
{
|
||||
if (!$migration->is_latest()) {
|
||||
$this->session->destroy();
|
||||
}
|
||||
|
||||
//Language
|
||||
// Language
|
||||
$language_exists = file_exists('../app/Language/' . current_language_code());
|
||||
|
||||
if(current_language_code() == null || current_language() == null || !$language_exists) //TODO: current_language() is undefined
|
||||
{
|
||||
if (current_language_code() == null || current_language() == null || !$language_exists) { // TODO: current_language() is undefined
|
||||
$config->settings['language'] = 'english';
|
||||
$config->settings['language_code'] = 'en';
|
||||
}
|
||||
@@ -50,7 +48,7 @@ class Load_config
|
||||
$language = Services::language();
|
||||
$language->setLocale($config->settings['language_code']);
|
||||
|
||||
//Time Zone
|
||||
// Time Zone
|
||||
date_default_timezone_set($config->settings['timezone'] ?? ini_get('date.timezone'));
|
||||
|
||||
bcscale(max(2, totals_decimals() + tax_decimals()));
|
||||
|
||||
@@ -13,8 +13,7 @@ class Method
|
||||
|
||||
$post_required = preg_match('/\/(save|delete*|remove*)\/?\d*?/', $url);
|
||||
|
||||
if($post_required && $_SERVER["REQUEST_METHOD"] != "POST" && empty($_POST))
|
||||
{
|
||||
if ($post_required && $_SERVER["REQUEST_METHOD"] != "POST" && empty($_POST)) {
|
||||
echo "Method not allowed";
|
||||
die;
|
||||
}
|
||||
|
||||
@@ -5,17 +5,14 @@
|
||||
*/
|
||||
function create_pdf(string $html, string $filename = ''): string
|
||||
{
|
||||
// need to enable magic quotes for the
|
||||
$dompdf = new Dompdf\Dompdf (['isRemoteEnabled' => true, 'isPhpEnabled' => true]);
|
||||
$dompdf->loadHtml(str_replace (['\n', '\r'], '', $html));
|
||||
// Need to enable magic quotes for the
|
||||
$dompdf = new Dompdf\Dompdf(['isRemoteEnabled' => true, 'isPhpEnabled' => true]);
|
||||
$dompdf->loadHtml(str_replace(['\n', '\r'], '', $html));
|
||||
$dompdf->render();
|
||||
|
||||
if($filename != '')
|
||||
{
|
||||
if ($filename != '') {
|
||||
$dompdf->stream($filename . '.pdf');
|
||||
}
|
||||
else//TODO: Not all paths return a value.
|
||||
{
|
||||
} else { // TODO: Not all paths return a value.
|
||||
return $dompdf->output();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @param array $stock_locations
|
||||
* @param array $attributes
|
||||
* @return string
|
||||
*/
|
||||
|
||||
function generate_import_items_csv(array $stock_locations, array $attributes): string
|
||||
{
|
||||
$csv_headers = pack('CCC',0xef,0xbb,0xbf); //Encode the Byte-Order Mark (BOM) so that UTF-8 File headers display properly in Microsoft Excel
|
||||
$csv_headers = pack('CCC', 0xef, 0xbb, 0xbf); // Encode the Byte-Order Mark (BOM) so that UTF-8 File headers display properly in Microsoft Excel
|
||||
$csv_headers .= 'Id,Barcode,"Item Name",Category,"Supplier ID","Cost Price","Unit Price","Tax 1 Name","Tax 1 Percent","Tax 2 Name","Tax 2 Percent","Reorder Level",Description,"Allow Alt Description","Item has Serial Number",Image,HSN';
|
||||
$csv_headers .= generate_stock_location_headers($stock_locations);
|
||||
$csv_headers .= generate_attribute_headers($attributes);
|
||||
@@ -23,8 +23,7 @@ function generate_stock_location_headers(array $locations): string
|
||||
{
|
||||
$location_headers = '';
|
||||
|
||||
foreach($locations as $location_name)
|
||||
{
|
||||
foreach ($locations as $location_name) {
|
||||
$location_headers .= ',"location_' . $location_name . '"';
|
||||
}
|
||||
|
||||
@@ -40,8 +39,7 @@ function generate_attribute_headers(array $attribute_names): string
|
||||
$attribute_headers = '';
|
||||
unset($attribute_names[-1]);
|
||||
|
||||
foreach($attribute_names as $attribute_name)
|
||||
{
|
||||
foreach ($attribute_names as $attribute_name) {
|
||||
$attribute_headers .= ',"attribute_' . $attribute_name . '"';
|
||||
}
|
||||
|
||||
@@ -57,24 +55,20 @@ function get_csv_file(string $file_name): array
|
||||
{
|
||||
$csv_rows = false;
|
||||
|
||||
if(($csv_file = fopen($file_name,'r')) !== false)
|
||||
{
|
||||
if (($csv_file = fopen($file_name, 'r')) !== false) {
|
||||
helper('security');
|
||||
|
||||
$csv_rows = [];
|
||||
|
||||
//Skip Byte-Order Mark
|
||||
if(bom_exists($csv_file))
|
||||
{
|
||||
// Skip Byte-Order Mark
|
||||
if (bom_exists($csv_file)) {
|
||||
fseek($csv_file, 3);
|
||||
}
|
||||
|
||||
$headers = fgetcsv($csv_file);
|
||||
|
||||
while(($row = fgetcsv($csv_file)) !== false)
|
||||
{
|
||||
if($row !== [null])
|
||||
{
|
||||
while (($row = fgetcsv($csv_file)) !== false) {
|
||||
if ($row !== [null]) {
|
||||
$csv_rows[] = array_combine($headers, $row);
|
||||
}
|
||||
}
|
||||
@@ -98,8 +92,7 @@ function bom_exists(&$file_handle): bool
|
||||
|
||||
$bom = pack('CCC', 0xef, 0xbb, 0xbf);
|
||||
|
||||
if (0 === strncmp($candidate, $bom, 3))
|
||||
{
|
||||
if (0 === strncmp($candidate, $bom, 3)) {
|
||||
$result = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Employee;
|
||||
use Config\OSPOS;
|
||||
|
||||
@@ -13,12 +14,10 @@ function current_language_code(bool $load_system_language = false): string
|
||||
$employee = model(Employee::class);
|
||||
$config = config(OSPOS::class)->settings;
|
||||
|
||||
if($employee->is_logged_in() && !$load_system_language)
|
||||
{
|
||||
if ($employee->is_logged_in() && !$load_system_language) {
|
||||
$employee_info = $employee->get_logged_in_employee_info();
|
||||
|
||||
if(property_exists($employee_info, 'language_code') && !empty($employee_info->language_code))
|
||||
{
|
||||
if (property_exists($employee_info, 'language_code') && !empty($employee_info->language_code)) {
|
||||
return $employee_info->language_code;
|
||||
}
|
||||
}
|
||||
@@ -38,12 +37,10 @@ function current_language(bool $load_system_language = false): string
|
||||
$config = config(OSPOS::class)->settings;
|
||||
|
||||
// Returns the language of the employee if set or system language if not
|
||||
if($employee->is_logged_in() && !$load_system_language)
|
||||
{
|
||||
if ($employee->is_logged_in() && !$load_system_language) {
|
||||
$employee_info = $employee->get_logged_in_employee_info();
|
||||
|
||||
if(property_exists($employee_info, 'language') && !empty($employee_info->language))
|
||||
{
|
||||
if (property_exists($employee_info, 'language') && !empty($employee_info->language)) {
|
||||
return $employee_info->language;
|
||||
}
|
||||
}
|
||||
@@ -59,48 +56,48 @@ function current_language(bool $load_system_language = false): string
|
||||
function get_languages(): array
|
||||
{
|
||||
$languages = [
|
||||
'ar-EG:arabic' => 'Arabic (Egypt)',
|
||||
'ar-LB:arabic' => 'Arabic (Lebanon)',
|
||||
'az:azerbaijani' => 'Azerbaijani',
|
||||
'bg:bulgarian' => 'Bulgarian',
|
||||
'bs:bosnian' => 'Bosnian',
|
||||
'ckb:centralkurdish' => 'Kurdish (Central)',
|
||||
'cs:czech' => 'Czech',
|
||||
'da:danish' => 'Danish',
|
||||
'de-CH:german' => 'German (Switzerland)',
|
||||
'de-DE:german' => 'German (Germany)',
|
||||
'el:greek' => 'Greek',
|
||||
'en:english' => 'English (United States)',
|
||||
'en-GB:english' => 'English (United Kingdom)',
|
||||
'es-ES:spanish' => 'Spanish (Spain)',
|
||||
'es-MX:spanish' => 'Spanish (Mexico)',
|
||||
'fa:persian' => 'Persian',
|
||||
'fr:french' => 'French',
|
||||
'he:hebrew' => 'Hebrew',
|
||||
'hr-HR:croatian' => 'Croatian (Croatia)',
|
||||
'hu:hungarian' => 'Hungarian',
|
||||
'hy:armenian' => 'Armenian',
|
||||
'id:indonesian' => 'Indonesian',
|
||||
'it:italian' => 'Italian',
|
||||
'km:centralkhmer' => 'Khmer (Central)',
|
||||
'lo:lao' => 'Lao',
|
||||
'ml:malayalam' => 'Malayalam',
|
||||
'nb:norwegian' => 'Norwegian Bokmål',
|
||||
'nl-BE:dutch' => 'Dutch (Belgium)',
|
||||
'nl-NL:dutch' => 'Dutch (Netherlands)',
|
||||
'pl:polish' => 'Polish',
|
||||
'pt-BR:portuguese' => 'Portuguese (Brazil)',
|
||||
'ro:romanian' => 'Romanian',
|
||||
'ru:russian' => 'Russian',
|
||||
'sv:swedish' => 'Swedish',
|
||||
'ta:tamil' => 'Tamil',
|
||||
'th:thai' => 'Thai',
|
||||
'tl:tagalog' => 'Tagalog',
|
||||
'tr:turkish' => 'Turkish',
|
||||
'uk:ukrainian' => 'Ukrainian',
|
||||
'ur:urdu' => 'Urdu',
|
||||
'vi:vietnamese' => 'Vietnamese',
|
||||
'zh-Hans:simplified-chinese' => 'Chinese (Simplified)',
|
||||
'ar-EG:arabic' => 'Arabic (Egypt)',
|
||||
'ar-LB:arabic' => 'Arabic (Lebanon)',
|
||||
'az:azerbaijani' => 'Azerbaijani',
|
||||
'bg:bulgarian' => 'Bulgarian',
|
||||
'bs:bosnian' => 'Bosnian',
|
||||
'ckb:centralkurdish' => 'Kurdish (Central)',
|
||||
'cs:czech' => 'Czech',
|
||||
'da:danish' => 'Danish',
|
||||
'de-CH:german' => 'German (Switzerland)',
|
||||
'de-DE:german' => 'German (Germany)',
|
||||
'el:greek' => 'Greek',
|
||||
'en:english' => 'English (United States)',
|
||||
'en-GB:english' => 'English (United Kingdom)',
|
||||
'es-ES:spanish' => 'Spanish (Spain)',
|
||||
'es-MX:spanish' => 'Spanish (Mexico)',
|
||||
'fa:persian' => 'Persian',
|
||||
'fr:french' => 'French',
|
||||
'he:hebrew' => 'Hebrew',
|
||||
'hr-HR:croatian' => 'Croatian (Croatia)',
|
||||
'hu:hungarian' => 'Hungarian',
|
||||
'hy:armenian' => 'Armenian',
|
||||
'id:indonesian' => 'Indonesian',
|
||||
'it:italian' => 'Italian',
|
||||
'km:centralkhmer' => 'Khmer (Central)',
|
||||
'lo:lao' => 'Lao',
|
||||
'ml:malayalam' => 'Malayalam',
|
||||
'nb:norwegian' => 'Norwegian Bokmål',
|
||||
'nl-BE:dutch' => 'Dutch (Belgium)',
|
||||
'nl-NL:dutch' => 'Dutch (Netherlands)',
|
||||
'pl:polish' => 'Polish',
|
||||
'pt-BR:portuguese' => 'Portuguese (Brazil)',
|
||||
'ro:romanian' => 'Romanian',
|
||||
'ru:russian' => 'Russian',
|
||||
'sv:swedish' => 'Swedish',
|
||||
'ta:tamil' => 'Tamil',
|
||||
'th:thai' => 'Thai',
|
||||
'tl:tagalog' => 'Tagalog',
|
||||
'tr:turkish' => 'Turkish',
|
||||
'uk:ukrainian' => 'Ukrainian',
|
||||
'ur:urdu' => 'Urdu',
|
||||
'vi:vietnamese' => 'Vietnamese',
|
||||
'zh-Hans:simplified-chinese' => 'Chinese (Simplified)',
|
||||
'zh-Hant:traditional-chinese' => 'Chinese (Traditional)'
|
||||
];
|
||||
asort($languages);
|
||||
@@ -113,99 +110,99 @@ function get_languages(): array
|
||||
function get_timezones(): array
|
||||
{
|
||||
return [
|
||||
'Pacific/Midway' => '(GMT-11:00) Midway Island, Samoa',
|
||||
'America/Adak' => '(GMT-10:00) Hawaii-Aleutian',
|
||||
'Etc/GMT+10' => '(GMT-10:00) Hawaii',
|
||||
'Pacific/Marquesas' => '(GMT-09:30) Marquesas Islands',
|
||||
'Pacific/Gambier' => '(GMT-09:00) Gambier Islands',
|
||||
'America/Anchorage' => '(GMT-09:00) Alaska',
|
||||
'America/Ensenada' => '(GMT-08:00) Tijuana, Baja California',
|
||||
'Etc/GMT+8' => '(GMT-08:00) Pitcairn Islands',
|
||||
'America/Los_Angeles' => '(GMT-08:00) Pacific Time (US & Canada)',
|
||||
'America/Denver' => '(GMT-07:00) Mountain Time (US & Canada)',
|
||||
'America/Chihuahua' => '(GMT-07:00) Chihuahua, La Paz, Mazatlan',
|
||||
'America/Dawson_Creek' => '(GMT-07:00) Arizona',
|
||||
'America/Belize' => '(GMT-06:00) Saskatchewan, Central America',
|
||||
'America/Mexico_City' => '(GMT-06:00) Guadalajara, Mexico City, Monterrey',
|
||||
'Chile/EasterIsland' => '(GMT-06:00) Easter Island',
|
||||
'America/Chicago' => '(GMT-06:00) Central Time (US & Canada)',
|
||||
'America/New_York' => '(GMT-05:00) Eastern Time (US & Canada)',
|
||||
'America/Cancun' => '(GMT-05:00) Cancun',
|
||||
'America/Havana' => '(GMT-05:00) Cuba',
|
||||
'America/Bogota' => '(GMT-05:00) Bogota, Lima, Quito, Rio Branco',
|
||||
'America/Caracas' => '(GMT-04:30) Caracas',
|
||||
'America/Santiago' => '(GMT-04:00) Santiago',
|
||||
'America/La_Paz' => '(GMT-04:00) La Paz',
|
||||
'Atlantic/Stanley' => '(GMT-04:00) Falkland Islands',
|
||||
'America/Campo_Grande' => '(GMT-04:00) Brazil',
|
||||
'America/Goose_Bay' => '(GMT-04:00) Atlantic Time (Goose Bay)',
|
||||
'America/Glace_Bay' => '(GMT-04:00) Atlantic Time (Canada)',
|
||||
'America/St_Johns' => '(GMT-03:30) Newfoundland',
|
||||
'America/Araguaina' => '(GMT-03:00) UTC-3',
|
||||
'America/Montevideo' => '(GMT-03:00) Montevideo',
|
||||
'America/Miquelon' => '(GMT-03:00) Miquelon, St. Pierre',
|
||||
'America/Godthab' => '(GMT-03:00) Greenland',
|
||||
'Pacific/Midway' => '(GMT-11:00) Midway Island, Samoa',
|
||||
'America/Adak' => '(GMT-10:00) Hawaii-Aleutian',
|
||||
'Etc/GMT+10' => '(GMT-10:00) Hawaii',
|
||||
'Pacific/Marquesas' => '(GMT-09:30) Marquesas Islands',
|
||||
'Pacific/Gambier' => '(GMT-09:00) Gambier Islands',
|
||||
'America/Anchorage' => '(GMT-09:00) Alaska',
|
||||
'America/Ensenada' => '(GMT-08:00) Tijuana, Baja California',
|
||||
'Etc/GMT+8' => '(GMT-08:00) Pitcairn Islands',
|
||||
'America/Los_Angeles' => '(GMT-08:00) Pacific Time (US & Canada)',
|
||||
'America/Denver' => '(GMT-07:00) Mountain Time (US & Canada)',
|
||||
'America/Chihuahua' => '(GMT-07:00) Chihuahua, La Paz, Mazatlan',
|
||||
'America/Dawson_Creek' => '(GMT-07:00) Arizona',
|
||||
'America/Belize' => '(GMT-06:00) Saskatchewan, Central America',
|
||||
'America/Mexico_City' => '(GMT-06:00) Guadalajara, Mexico City, Monterrey',
|
||||
'Chile/EasterIsland' => '(GMT-06:00) Easter Island',
|
||||
'America/Chicago' => '(GMT-06:00) Central Time (US & Canada)',
|
||||
'America/New_York' => '(GMT-05:00) Eastern Time (US & Canada)',
|
||||
'America/Cancun' => '(GMT-05:00) Cancun',
|
||||
'America/Havana' => '(GMT-05:00) Cuba',
|
||||
'America/Bogota' => '(GMT-05:00) Bogota, Lima, Quito, Rio Branco',
|
||||
'America/Caracas' => '(GMT-04:30) Caracas',
|
||||
'America/Santiago' => '(GMT-04:00) Santiago',
|
||||
'America/La_Paz' => '(GMT-04:00) La Paz',
|
||||
'Atlantic/Stanley' => '(GMT-04:00) Falkland Islands',
|
||||
'America/Campo_Grande' => '(GMT-04:00) Brazil',
|
||||
'America/Goose_Bay' => '(GMT-04:00) Atlantic Time (Goose Bay)',
|
||||
'America/Glace_Bay' => '(GMT-04:00) Atlantic Time (Canada)',
|
||||
'America/St_Johns' => '(GMT-03:30) Newfoundland',
|
||||
'America/Araguaina' => '(GMT-03:00) UTC-3',
|
||||
'America/Montevideo' => '(GMT-03:00) Montevideo',
|
||||
'America/Miquelon' => '(GMT-03:00) Miquelon, St. Pierre',
|
||||
'America/Godthab' => '(GMT-03:00) Greenland',
|
||||
'America/Argentina/Buenos_Aires' => '(GMT-03:00) Buenos Aires',
|
||||
'America/Sao_Paulo' => '(GMT-03:00) Brasilia',
|
||||
'America/Noronha' => '(GMT-02:00) Mid-Atlantic',
|
||||
'Atlantic/Cape_Verde' => '(GMT-01:00) Cape Verde Is.',
|
||||
'Atlantic/Azores' => '(GMT-01:00) Azores',
|
||||
'Europe/Belfast' => '(GMT) Greenwich Mean Time : Belfast',
|
||||
'Europe/Dublin' => '(GMT) Greenwich Mean Time : Dublin',
|
||||
'Europe/Lisbon' => '(GMT) Greenwich Mean Time : Lisbon',
|
||||
'Europe/London' => '(GMT) Greenwich Mean Time : London',
|
||||
'Africa/Abidjan' => '(GMT) Monrovia, Reykjavik',
|
||||
'Europe/Amsterdam' => '(GMT+01:00) Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna',
|
||||
'Europe/Belgrade' => '(GMT+01:00) Belgrade, Bratislava, Budapest, Ljubljana, Prague',
|
||||
'Europe/Brussels' => '(GMT+01:00) Brussels, Copenhagen, Madrid, Paris',
|
||||
'Africa/Algiers' => '(GMT+01:00) West Central Africa',
|
||||
'Africa/Windhoek' => '(GMT+01:00) Windhoek',
|
||||
'Asia/Beirut' => '(GMT+02:00) Beirut',
|
||||
'Africa/Cairo' => '(GMT+02:00) Cairo',
|
||||
'Asia/Gaza' => '(GMT+02:00) Gaza',
|
||||
'Africa/Blantyre' => '(GMT+02:00) Harare, Pretoria',
|
||||
'Asia/Jerusalem' => '(GMT+02:00) Jerusalem',
|
||||
'Europe/Minsk' => '(GMT+02:00) Minsk',
|
||||
'Asia/Damascus' => '(GMT+02:00) Syria',
|
||||
'Europe/Moscow' => '(GMT+03:00) Moscow, St. Petersburg, Volgograd',
|
||||
'Africa/Addis_Ababa' => '(GMT+03:00) Nairobi',
|
||||
'Asia/Tehran' => '(GMT+03:30) Tehran',
|
||||
'Asia/Dubai' => '(GMT+04:00) Abu Dhabi, Muscat',
|
||||
'Asia/Yerevan' => '(GMT+04:00) Yerevan',
|
||||
'Asia/Kabul' => '(GMT+04:30) Kabul',
|
||||
'Asia/Baku' => '(GMT+04:00) Baku',
|
||||
'Asia/Yekaterinburg' => '(GMT+05:00) Ekaterinburg',
|
||||
'Asia/Karachi' => '(GMT+05:00) Karachi, Islamabad',
|
||||
'Asia/Tashkent' => '(GMT+05:00) Tashkent',
|
||||
'Asia/Kolkata' => '(GMT+05:30) Chennai, Kolkata, Mumbai, New Delhi',
|
||||
'Asia/Katmandu' => '(GMT+05:45) Kathmandu',
|
||||
'Asia/Dhaka' => '(GMT+06:00) Astana, Dhaka',
|
||||
'Asia/Novosibirsk' => '(GMT+06:00) Novosibirsk',
|
||||
'Asia/Rangoon' => '(GMT+06:30) Yangon (Rangoon)',
|
||||
'Asia/Bangkok' => '(GMT+07:00) Bangkok, Hanoi, Jakarta',
|
||||
'Asia/Krasnoyarsk' => '(GMT+07:00) Krasnoyarsk',
|
||||
'Asia/Hong_Kong' => '(GMT+08:00) Beijing, Chongqing, Hong Kong, Urumqi',
|
||||
'Asia/Irkutsk' => '(GMT+08:00) Irkutsk, Ulaan Bataar',
|
||||
'Australia/Perth' => '(GMT+08:00) Perth',
|
||||
'Australia/Eucla' => '(GMT+08:45) Eucla',
|
||||
'Asia/Tokyo' => '(GMT+09:00) Osaka, Sapporo, Tokyo',
|
||||
'Asia/Seoul' => '(GMT+09:00) Seoul',
|
||||
'Asia/Yakutsk' => '(GMT+09:00) Yakutsk',
|
||||
'Australia/Adelaide' => '(GMT+09:30) Adelaide',
|
||||
'Australia/Darwin' => '(GMT+09:30) Darwin',
|
||||
'Australia/Brisbane' => '(GMT+10:00) Brisbane',
|
||||
'Australia/Hobart' => '(GMT+10:00) Hobart',
|
||||
'Asia/Vladivostok' => '(GMT+10:00) Vladivostok',
|
||||
'Australia/Lord_Howe' => '(GMT+10:30) Lord Howe Island',
|
||||
'Etc/GMT-11' => '(GMT+11:00) Solomon Is., New Caledonia',
|
||||
'Asia/Magadan' => '(GMT+11:00) Magadan',
|
||||
'Pacific/Norfolk' => '(GMT+11:30) Norfolk Island',
|
||||
'Asia/Anadyr' => '(GMT+12:00) Anadyr, Kamchatka',
|
||||
'Pacific/Auckland' => '(GMT+12:00) Auckland, Wellington',
|
||||
'Etc/GMT-12' => '(GMT+12:00) Fiji, Kamchatka, Marshall Is.',
|
||||
'Pacific/Chatham' => '(GMT+12:45) Chatham Islands',
|
||||
'Pacific/Tongatapu' => '(GMT+13:00) Nuku\'alofa',
|
||||
'Pacific/Kiritimati' => '(GMT+14:00) Kiritimati'
|
||||
'America/Sao_Paulo' => '(GMT-03:00) Brasilia',
|
||||
'America/Noronha' => '(GMT-02:00) Mid-Atlantic',
|
||||
'Atlantic/Cape_Verde' => '(GMT-01:00) Cape Verde Is.',
|
||||
'Atlantic/Azores' => '(GMT-01:00) Azores',
|
||||
'Europe/Belfast' => '(GMT) Greenwich Mean Time : Belfast',
|
||||
'Europe/Dublin' => '(GMT) Greenwich Mean Time : Dublin',
|
||||
'Europe/Lisbon' => '(GMT) Greenwich Mean Time : Lisbon',
|
||||
'Europe/London' => '(GMT) Greenwich Mean Time : London',
|
||||
'Africa/Abidjan' => '(GMT) Monrovia, Reykjavik',
|
||||
'Europe/Amsterdam' => '(GMT+01:00) Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna',
|
||||
'Europe/Belgrade' => '(GMT+01:00) Belgrade, Bratislava, Budapest, Ljubljana, Prague',
|
||||
'Europe/Brussels' => '(GMT+01:00) Brussels, Copenhagen, Madrid, Paris',
|
||||
'Africa/Algiers' => '(GMT+01:00) West Central Africa',
|
||||
'Africa/Windhoek' => '(GMT+01:00) Windhoek',
|
||||
'Asia/Beirut' => '(GMT+02:00) Beirut',
|
||||
'Africa/Cairo' => '(GMT+02:00) Cairo',
|
||||
'Asia/Gaza' => '(GMT+02:00) Gaza',
|
||||
'Africa/Blantyre' => '(GMT+02:00) Harare, Pretoria',
|
||||
'Asia/Jerusalem' => '(GMT+02:00) Jerusalem',
|
||||
'Europe/Minsk' => '(GMT+02:00) Minsk',
|
||||
'Asia/Damascus' => '(GMT+02:00) Syria',
|
||||
'Europe/Moscow' => '(GMT+03:00) Moscow, St. Petersburg, Volgograd',
|
||||
'Africa/Addis_Ababa' => '(GMT+03:00) Nairobi',
|
||||
'Asia/Tehran' => '(GMT+03:30) Tehran',
|
||||
'Asia/Dubai' => '(GMT+04:00) Abu Dhabi, Muscat',
|
||||
'Asia/Yerevan' => '(GMT+04:00) Yerevan',
|
||||
'Asia/Kabul' => '(GMT+04:30) Kabul',
|
||||
'Asia/Baku' => '(GMT+04:00) Baku',
|
||||
'Asia/Yekaterinburg' => '(GMT+05:00) Ekaterinburg',
|
||||
'Asia/Karachi' => '(GMT+05:00) Karachi, Islamabad',
|
||||
'Asia/Tashkent' => '(GMT+05:00) Tashkent',
|
||||
'Asia/Kolkata' => '(GMT+05:30) Chennai, Kolkata, Mumbai, New Delhi',
|
||||
'Asia/Katmandu' => '(GMT+05:45) Kathmandu',
|
||||
'Asia/Dhaka' => '(GMT+06:00) Astana, Dhaka',
|
||||
'Asia/Novosibirsk' => '(GMT+06:00) Novosibirsk',
|
||||
'Asia/Rangoon' => '(GMT+06:30) Yangon (Rangoon)',
|
||||
'Asia/Bangkok' => '(GMT+07:00) Bangkok, Hanoi, Jakarta',
|
||||
'Asia/Krasnoyarsk' => '(GMT+07:00) Krasnoyarsk',
|
||||
'Asia/Hong_Kong' => '(GMT+08:00) Beijing, Chongqing, Hong Kong, Urumqi',
|
||||
'Asia/Irkutsk' => '(GMT+08:00) Irkutsk, Ulaan Bataar',
|
||||
'Australia/Perth' => '(GMT+08:00) Perth',
|
||||
'Australia/Eucla' => '(GMT+08:45) Eucla',
|
||||
'Asia/Tokyo' => '(GMT+09:00) Osaka, Sapporo, Tokyo',
|
||||
'Asia/Seoul' => '(GMT+09:00) Seoul',
|
||||
'Asia/Yakutsk' => '(GMT+09:00) Yakutsk',
|
||||
'Australia/Adelaide' => '(GMT+09:30) Adelaide',
|
||||
'Australia/Darwin' => '(GMT+09:30) Darwin',
|
||||
'Australia/Brisbane' => '(GMT+10:00) Brisbane',
|
||||
'Australia/Hobart' => '(GMT+10:00) Hobart',
|
||||
'Asia/Vladivostok' => '(GMT+10:00) Vladivostok',
|
||||
'Australia/Lord_Howe' => '(GMT+10:30) Lord Howe Island',
|
||||
'Etc/GMT-11' => '(GMT+11:00) Solomon Is., New Caledonia',
|
||||
'Asia/Magadan' => '(GMT+11:00) Magadan',
|
||||
'Pacific/Norfolk' => '(GMT+11:30) Norfolk Island',
|
||||
'Asia/Anadyr' => '(GMT+12:00) Anadyr, Kamchatka',
|
||||
'Pacific/Auckland' => '(GMT+12:00) Auckland, Wellington',
|
||||
'Etc/GMT-12' => '(GMT+12:00) Fiji, Kamchatka, Marshall Is.',
|
||||
'Pacific/Chatham' => '(GMT+12:45) Chatham Islands',
|
||||
'Pacific/Tongatapu' => '(GMT+13:00) Nuku\'alofa',
|
||||
'Pacific/Kiritimati' => '(GMT+14:00) Kiritimati'
|
||||
];
|
||||
}
|
||||
|
||||
@@ -231,7 +228,7 @@ function get_dateformats(): array
|
||||
function get_timeformats(): array
|
||||
{
|
||||
return [
|
||||
'H:i:s' => 'hh:mm:ss (24h)',
|
||||
'H:i:s' => 'hh:mm:ss (24h)',
|
||||
'h:i:s a' => 'hh:mm:ss am/pm',
|
||||
'h:i:s A' => 'hh:mm:ss AM/PM'
|
||||
];
|
||||
@@ -246,33 +243,24 @@ function get_payment_options(): array
|
||||
$payments = [];
|
||||
$config = config(OSPOS::class)->settings;
|
||||
|
||||
//TODO: This needs to be switched to a switch statement
|
||||
if($config['payment_options_order'] == 'debitcreditcash') //TODO: ===
|
||||
{
|
||||
// TODO: This needs to be switched to a switch statement
|
||||
if ($config['payment_options_order'] == 'debitcreditcash') { // TODO: ===
|
||||
$payments[lang('Sales.debit')] = lang('Sales.debit');
|
||||
$payments[lang('Sales.credit')] = lang('Sales.credit');
|
||||
$payments[lang('Sales.cash')] = lang('Sales.cash');
|
||||
}
|
||||
elseif($config['payment_options_order'] == 'debitcashcredit') //TODO: ===
|
||||
{
|
||||
} elseif ($config['payment_options_order'] == 'debitcashcredit') { // TODO: ===
|
||||
$payments[lang('Sales.debit')] = lang('Sales.debit');
|
||||
$payments[lang('Sales.cash')] = lang('Sales.cash');
|
||||
$payments[lang('Sales.credit')] = lang('Sales.credit');
|
||||
}
|
||||
elseif($config['payment_options_order'] == 'creditdebitcash') //TODO: ===
|
||||
{
|
||||
} elseif ($config['payment_options_order'] == 'creditdebitcash') { // TODO: ===
|
||||
$payments[lang('Sales.credit')] = lang('Sales.credit');
|
||||
$payments[lang('Sales.debit')] = lang('Sales.debit');
|
||||
$payments[lang('Sales.cash')] = lang('Sales.cash');
|
||||
}
|
||||
elseif($config['payment_options_order'] == 'creditcashdebit') //TODO: ===
|
||||
{
|
||||
} elseif ($config['payment_options_order'] == 'creditcashdebit') { // TODO: ===
|
||||
$payments[lang('Sales.credit')] = lang('Sales.credit');
|
||||
$payments[lang('Sales.cash')] = lang('Sales.cash');
|
||||
$payments[lang('Sales.debit')] = lang('Sales.debit');
|
||||
}
|
||||
else // default: if($config['payment_options_order == 'cashdebitcredit')
|
||||
{
|
||||
} else { // Default: if ($config['payment_options_order == 'cashdebitcredit')
|
||||
$payments[lang('Sales.cash')] = lang('Sales.cash');
|
||||
$payments[lang('Sales.debit')] = lang('Sales.debit');
|
||||
$payments[lang('Sales.credit')] = lang('Sales.credit');
|
||||
@@ -282,8 +270,7 @@ function get_payment_options(): array
|
||||
$payments[lang('Sales.check')] = lang('Sales.check');
|
||||
|
||||
// If India (list of country codes include India) then include Unified Payment Interface
|
||||
if (stripos($config['country_codes'], 'IN') !== false)
|
||||
{
|
||||
if (stripos($config['country_codes'], 'IN') !== false) {
|
||||
$payments[lang('Sales.upi')] = lang('Sales.upi');
|
||||
}
|
||||
|
||||
@@ -388,12 +375,9 @@ function to_currency_tax(?string $number): string
|
||||
{
|
||||
$config = config(OSPOS::class)->settings;
|
||||
|
||||
if($config['tax_included']) //TODO: ternary notation
|
||||
{
|
||||
if ($config['tax_included']) { // TODO: ternary notation
|
||||
return to_decimals($number, 'tax_decimals', NumberFormatter::CURRENCY);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return to_decimals($number, 'currency_decimals', NumberFormatter::CURRENCY);
|
||||
}
|
||||
}
|
||||
@@ -409,10 +393,9 @@ function to_tax_decimals($number): string
|
||||
// It looks like it must be creating a String value on the fly because the form is referring to the index 0 when
|
||||
// there IS no index[0] row in the table
|
||||
|
||||
// taxes that are null, '' or 0 don't need to be displayed
|
||||
// Taxes that are null, '' or 0 don't need to be displayed
|
||||
// NOTE: do not remove this line otherwise the items edit form will show a tax with 0, and it will save it
|
||||
if(empty($number))
|
||||
{
|
||||
if (empty($number)) {
|
||||
return $number;
|
||||
}
|
||||
|
||||
@@ -437,8 +420,7 @@ function to_quantity_decimals(?string $number): string
|
||||
*/
|
||||
function to_decimals(?string $number, ?string $decimals = null, int $type = NumberFormatter::DECIMAL): string
|
||||
{
|
||||
if(!isset($number))
|
||||
{
|
||||
if (!isset($number)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
@@ -447,8 +429,7 @@ function to_decimals(?string $number, ?string $decimals = null, int $type = Numb
|
||||
$fmt->setAttribute(NumberFormatter::MIN_FRACTION_DIGITS, empty($decimals) ? DEFAULT_PRECISION : $config[$decimals]);
|
||||
$fmt->setAttribute(NumberFormatter::MAX_FRACTION_DIGITS, empty($decimals) ? DEFAULT_PRECISION : $config[$decimals]);
|
||||
|
||||
if(empty($config['thousands_separator']))
|
||||
{
|
||||
if (empty($config['thousands_separator'])) {
|
||||
$fmt->setTextAttribute(NumberFormatter::GROUPING_SEPARATOR_SYMBOL, '');
|
||||
}
|
||||
$fmt->setSymbol(NumberFormatter::CURRENCY_SYMBOL, $config['currency_symbol']);
|
||||
@@ -481,8 +462,7 @@ function parse_tax(string $number): mixed
|
||||
*/
|
||||
function parse_decimals(string $number, ?int $decimals = null): mixed
|
||||
{
|
||||
if(empty($number))
|
||||
{
|
||||
if (empty($number)) {
|
||||
return $number;
|
||||
}
|
||||
|
||||
@@ -491,34 +471,28 @@ function parse_decimals(string $number, ?int $decimals = null): mixed
|
||||
|
||||
$fmt = new NumberFormatter($config['number_locale'], NumberFormatter::DECIMAL);
|
||||
|
||||
if(!$decimals)
|
||||
{
|
||||
if (!$decimals) {
|
||||
$decimals = intVal($config['currency_decimals']);
|
||||
$fmt->setAttribute(NumberFormatter::FRACTION_DIGITS, $decimals);
|
||||
}
|
||||
|
||||
if(empty($config['thousands_separator']))
|
||||
{
|
||||
if (empty($config['thousands_separator'])) {
|
||||
$fmt->setTextAttribute(NumberFormatter::GROUPING_SEPARATOR_SYMBOL, '');
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
$locale_safe_number = $fmt->parse($number);
|
||||
|
||||
if (
|
||||
$locale_safe_number === false
|
||||
|| $locale_safe_number > MAX_PRECISION
|
||||
|| $locale_safe_number > 1.e14
|
||||
)
|
||||
{
|
||||
|| $locale_safe_number > MAX_PRECISION
|
||||
|| $locale_safe_number > 1.e14
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (float) $locale_safe_number;
|
||||
}
|
||||
catch(Exception $e)
|
||||
{
|
||||
} catch (Exception $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -542,14 +516,14 @@ function dateformat_momentjs(string $php_format): string
|
||||
'm' => 'MM',
|
||||
'M' => 'MMM',
|
||||
'n' => 'M',
|
||||
't' => '', // no equivalent
|
||||
'L' => '', // no equivalent
|
||||
't' => '', // No equivalent
|
||||
'L' => '', // No equivalent
|
||||
'o' => 'YYYY',
|
||||
'Y' => 'YYYY',
|
||||
'y' => 'YY',
|
||||
'a' => 'a',
|
||||
'A' => 'A',
|
||||
'B' => '', // no equivalent
|
||||
'B' => '', // No equivalent
|
||||
'g' => 'h',
|
||||
'G' => 'H',
|
||||
'h' => 'hh',
|
||||
@@ -557,14 +531,14 @@ function dateformat_momentjs(string $php_format): string
|
||||
'i' => 'mm',
|
||||
's' => 'ss',
|
||||
'u' => 'SSS',
|
||||
'e' => 'zz', // deprecated since version $1.6.0 of moment.js
|
||||
'I' => '', // no equivalent
|
||||
'O' => '', // no equivalent
|
||||
'P' => '', // no equivalent
|
||||
'T' => '', // no equivalent
|
||||
'Z' => '', // no equivalent
|
||||
'c' => '', // no equivalent
|
||||
'r' => '', // no equivalent
|
||||
'e' => 'zz', // Deprecated since version $1.6.0 of moment.js
|
||||
'I' => '', // No equivalent
|
||||
'O' => '', // No equivalent
|
||||
'P' => '', // No equivalent
|
||||
'T' => '', // No equivalent
|
||||
'Z' => '', // No equivalent
|
||||
'c' => '', // No equivalent
|
||||
'r' => '', // No equivalent
|
||||
'U' => 'X'
|
||||
];
|
||||
|
||||
@@ -667,7 +641,7 @@ function dateformat_bootstrap(string $php_format): string
|
||||
* @param string $date
|
||||
* @return bool
|
||||
*/
|
||||
function valid_date(string $date): bool //TODO: need a better name for $date. Perhaps $candidate. Also the function name would be better as is_valid_date()
|
||||
function valid_date(string $date): bool // TODO: need a better name for $date. Perhaps $candidate. Also the function name would be better as is_valid_date()
|
||||
{
|
||||
$config = config(OSPOS::class)->settings;
|
||||
return (DateTime::createFromFormat($config['dateformat'], $date));
|
||||
@@ -677,7 +651,7 @@ function valid_date(string $date): bool //TODO: need a better name for $date.
|
||||
* @param string $decimal
|
||||
* @return bool
|
||||
*/
|
||||
function valid_decimal(string $decimal): bool //TODO: need a better name for $decimal. Perhaps $candidate. Also the function name would be better as is_valid_decimal()
|
||||
function valid_decimal(string $decimal): bool // TODO: need a better name for $decimal. Perhaps $candidate. Also the function name would be better as is_valid_decimal()
|
||||
{
|
||||
return (preg_match('/^(\d*\.)?\d+$/', $decimal) === 1);
|
||||
}
|
||||
@@ -688,7 +662,9 @@ function valid_decimal(string $decimal): bool //TODO: need a better name for
|
||||
*/
|
||||
function encode_array(array $data): array
|
||||
{
|
||||
array_walk($data, function(&$value, $key) { $value = rawurlencode($value);});
|
||||
array_walk($data, function (&$value, $key) {
|
||||
$value = rawurlencode($value);
|
||||
});
|
||||
|
||||
return $data;
|
||||
}
|
||||
@@ -699,7 +675,9 @@ function encode_array(array $data): array
|
||||
*/
|
||||
function decode_array(array $data): array
|
||||
{
|
||||
array_walk($data, function(&$value, $key) { $value = rawurldecode($value);});
|
||||
array_walk($data, function (&$value, $key) {
|
||||
$value = rawurldecode($value);
|
||||
});
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user