Remove app/Space folder and extract model business logic into services

Relocate all 14 files from the catch-all app/Space namespace into proper
locations: data providers to Support/Formatters, installation utilities to
Services/Installation, PDF utils to Services/Pdf, module/update classes to
Services/Module and Services/Update, SiteApi trait to Traits, and helpers
to Support.

Extract ~1,400 lines of business logic from 8 fat models (Invoice, Payment,
Estimate, RecurringInvoice, Company, Customer, Expense, User) into 9 new
service classes with constructor injection. Controllers now depend on
services instead of calling static model methods. Shared item/tax creation
logic consolidated into DocumentItemService.
This commit is contained in:
Darko Gjorgjijoski
2026-04-03 15:37:22 +02:00
parent 23ff69026e
commit 0ce88ab817
98 changed files with 1703 additions and 1563 deletions

View File

@@ -0,0 +1,58 @@
<?php
namespace App\Support\Formatters;
use Carbon\Carbon;
class DateFormatter
{
protected static $formats = [
[
'carbon_format' => 'Y M d',
'moment_format' => 'YYYY MMM DD',
],
[
'carbon_format' => 'd M Y',
'moment_format' => 'DD MMM YYYY',
],
[
'carbon_format' => 'd/m/Y',
'moment_format' => 'DD/MM/YYYY',
],
[
'carbon_format' => 'd.m.Y',
'moment_format' => 'DD.MM.YYYY',
],
[
'carbon_format' => 'd-m-Y',
'moment_format' => 'DD-MM-YYYY',
],
[
'carbon_format' => 'm/d/Y',
'moment_format' => 'MM/DD/YYYY',
],
[
'carbon_format' => 'Y/m/d',
'moment_format' => ' YYYY/MM/DD',
],
[
'carbon_format' => 'Y-m-d',
'moment_format' => 'YYYY-MM-DD',
],
];
public static function get_list()
{
$new = [];
foreach (static::$formats as $format) {
$new[] = [
'display_date' => Carbon::now()->translatedFormat($format['carbon_format']),
'carbon_format_value' => $format['carbon_format'],
'moment_format_value' => $format['moment_format'],
];
}
return $new;
}
}

View File

@@ -0,0 +1,34 @@
<?php
namespace App\Support\Formatters;
use Carbon\Carbon;
class TimeFormatter
{
protected static $formats = [
[
'carbon_format' => 'H:i',
'moment_format' => 'HH:mm',
],
[
'carbon_format' => 'g:i a',
'moment_format' => 'h:mm a',
],
];
public static function get_list()
{
$new = [];
foreach (static::$formats as $format) {
$new[] = [
'display_time' => Carbon::now()->format($format['carbon_format']),
'carbon_format_value' => $format['carbon_format'],
'moment_format_value' => $format['moment_format'],
];
}
return $new;
}
}

View File

@@ -0,0 +1,431 @@
<?php
namespace App\Support\Formatters;
class TimeZones
{
public static function get_list()
{
return [
['value' => 'Pacific/Midway', 'key' => '(UTC-11:00) Midway'],
['value' => 'Pacific/Niue', 'key' => '(UTC-11:00) Niue'],
['value' => 'Pacific/Pago_Pago', 'key' => '(UTC-11:00) Pago Pago'],
['value' => 'America/Adak', 'key' => '(UTC-10:00) Adak'],
['value' => 'Pacific/Honolulu', 'key' => '(UTC-10:00) Honolulu'],
['value' => 'Pacific/Johnston', 'key' => '(UTC-10:00) Johnston'],
['value' => 'Pacific/Rarotonga', 'key' => '(UTC-10:00) Rarotonga'],
['value' => 'Pacific/Tahiti', 'key' => '(UTC-10:00) Tahiti'],
['value' => 'Pacific/Marquesas', 'key' => '(UTC-09:30) Marquesas'],
['value' => 'America/Anchorage', 'key' => '(UTC-09:00) Anchorage'],
['value' => 'Pacific/Gambier', 'key' => '(UTC-09:00) Gambier'],
['value' => 'America/Juneau', 'key' => '(UTC-09:00) Juneau'],
['value' => 'America/Nome', 'key' => '(UTC-09:00) Nome'],
['value' => 'America/Sitka', 'key' => '(UTC-09:00) Sitka'],
['value' => 'America/Yakutat', 'key' => '(UTC-09:00) Yakutat'],
['value' => 'America/Dawson', 'key' => '(UTC-08:00) Dawson'],
['value' => 'America/Los_Angeles', 'key' => '(UTC-08:00) Los Angeles'],
['value' => 'America/Metlakatla', 'key' => '(UTC-08:00) Metlakatla'],
['value' => 'Pacific/Pitcairn', 'key' => '(UTC-08:00) Pitcairn'],
['value' => 'America/Santa_Isabel', 'key' => '(UTC-08:00) Santa Isabel'],
['value' => 'America/Tijuana', 'key' => '(UTC-08:00) Tijuana'],
['value' => 'America/Vancouver', 'key' => '(UTC-08:00) Vancouver'],
['value' => 'America/Whitehorse', 'key' => '(UTC-08:00) Whitehorse'],
['value' => 'America/Boise', 'key' => '(UTC-07:00) Boise'],
['value' => 'America/Cambridge_Bay', 'key' => '(UTC-07:00) Cambridge Bay'],
['value' => 'America/Chihuahua', 'key' => '(UTC-07:00) Chihuahua'],
['value' => 'America/Creston', 'key' => '(UTC-07:00) Creston'],
['value' => 'America/Dawson_Creek', 'key' => '(UTC-07:00) Dawson Creek'],
['value' => 'America/Denver', 'key' => '(UTC-07:00) Denver'],
['value' => 'America/Edmonton', 'key' => '(UTC-07:00) Edmonton'],
['value' => 'America/Hermosillo', 'key' => '(UTC-07:00) Hermosillo'],
['value' => 'America/Inuvik', 'key' => '(UTC-07:00) Inuvik'],
['value' => 'America/Mazatlan', 'key' => '(UTC-07:00) Mazatlan'],
['value' => 'America/Ojinaga', 'key' => '(UTC-07:00) Ojinaga'],
['value' => 'America/Phoenix', 'key' => '(UTC-07:00) Phoenix'],
['value' => 'America/Shiprock', 'key' => '(UTC-07:00) Shiprock'],
['value' => 'America/Yellowknife', 'key' => '(UTC-07:00) Yellowknife'],
['value' => 'America/Bahia_Banderas', 'key' => '(UTC-06:00) Bahia Banderas'],
['value' => 'America/Belize', 'key' => '(UTC-06:00) Belize'],
['value' => 'America/North_Dakota/Beulah', 'key' => '(UTC-06:00) Beulah'],
['value' => 'America/Cancun', 'key' => '(UTC-06:00) Cancun'],
['value' => 'America/North_Dakota/Center', 'key' => '(UTC-06:00) Center'],
['value' => 'America/Chicago', 'key' => '(UTC-06:00) Chicago'],
['value' => 'America/Costa_Rica', 'key' => '(UTC-06:00) Costa Rica'],
['value' => 'Pacific/Easter', 'key' => '(UTC-06:00) Easter'],
['value' => 'America/El_Salvador', 'key' => '(UTC-06:00) El Salvador'],
['value' => 'Pacific/Galapagos', 'key' => '(UTC-06:00) Galapagos'],
['value' => 'America/Guatemala', 'key' => '(UTC-06:00) Guatemala'],
['value' => 'America/Indiana/Knox', 'key' => '(UTC-06:00) Knox'],
['value' => 'America/Managua', 'key' => '(UTC-06:00) Managua'],
['value' => 'America/Matamoros', 'key' => '(UTC-06:00) Matamoros'],
['value' => 'America/Menominee', 'key' => '(UTC-06:00) Menominee'],
['value' => 'America/Merida', 'key' => '(UTC-06:00) Merida'],
['value' => 'America/Mexico_City', 'key' => '(UTC-06:00) Mexico City'],
['value' => 'America/Monterrey', 'key' => '(UTC-06:00) Monterrey'],
['value' => 'America/North_Dakota/New_Salem', 'key' => '(UTC-06:00) New Salem'],
['value' => 'America/Rainy_River', 'key' => '(UTC-06:00) Rainy River'],
['value' => 'America/Rankin_Inlet', 'key' => '(UTC-06:00) Rankin Inlet'],
['value' => 'America/Regina', 'key' => '(UTC-06:00) Regina'],
['value' => 'America/Resolute', 'key' => '(UTC-06:00) Resolute'],
['value' => 'America/Swift_Current', 'key' => '(UTC-06:00) Swift Current'],
['value' => 'America/Tegucigalpa', 'key' => '(UTC-06:00) Tegucigalpa'],
['value' => 'America/Indiana/Tell_City', 'key' => '(UTC-06:00) Tell City'],
['value' => 'America/Winnipeg', 'key' => '(UTC-06:00) Winnipeg'],
['value' => 'America/Atikokan', 'key' => '(UTC-05:00) Atikokan'],
['value' => 'America/Bogota', 'key' => '(UTC-05:00) Bogota'],
['value' => 'America/Cayman', 'key' => '(UTC-05:00) Cayman'],
['value' => 'America/Detroit', 'key' => '(UTC-05:00) Detroit'],
['value' => 'America/Grand_Turk', 'key' => '(UTC-05:00) Grand Turk'],
['value' => 'America/Guayaquil', 'key' => '(UTC-05:00) Guayaquil'],
['value' => 'America/Havana', 'key' => '(UTC-05:00) Havana'],
['value' => 'America/Indiana/Indianapolis', 'key' => '(UTC-05:00) Indianapolis'],
['value' => 'America/Iqaluit', 'key' => '(UTC-05:00) Iqaluit'],
['value' => 'America/Jamaica', 'key' => '(UTC-05:00) Jamaica'],
['value' => 'America/Lima', 'key' => '(UTC-05:00) Lima'],
['value' => 'America/Kentucky/Louisville', 'key' => '(UTC-05:00) Louisville'],
['value' => 'America/Indiana/Marengo', 'key' => '(UTC-05:00) Marengo'],
['value' => 'America/Kentucky/Monticello', 'key' => '(UTC-05:00) Monticello'],
['value' => 'America/Montreal', 'key' => '(UTC-05:00) Montreal'],
['value' => 'America/Nassau', 'key' => '(UTC-05:00) Nassau'],
['value' => 'America/New_York', 'key' => '(UTC-05:00) New York'],
['value' => 'America/Nipigon', 'key' => '(UTC-05:00) Nipigon'],
['value' => 'America/Panama', 'key' => '(UTC-05:00) Panama'],
['value' => 'America/Pangnirtung', 'key' => '(UTC-05:00) Pangnirtung'],
['value' => 'America/Indiana/Petersburg', 'key' => '(UTC-05:00) Petersburg'],
['value' => 'America/Port-au-Prince', 'key' => '(UTC-05:00) Port-au-Prince'],
['value' => 'America/Thunder_Bay', 'key' => '(UTC-05:00) Thunder Bay'],
['value' => 'America/Toronto', 'key' => '(UTC-05:00) Toronto'],
['value' => 'America/Indiana/Vevay', 'key' => '(UTC-05:00) Vevay'],
['value' => 'America/Indiana/Vincennes', 'key' => '(UTC-05:00) Vincennes'],
['value' => 'America/Indiana/Winamac', 'key' => '(UTC-05:00) Winamac'],
['value' => 'America/Caracas', 'key' => '(UTC-04:30) Caracas'],
['value' => 'America/Anguilla', 'key' => '(UTC-04:00) Anguilla'],
['value' => 'America/Antigua', 'key' => '(UTC-04:00) Antigua'],
['value' => 'America/Aruba', 'key' => '(UTC-04:00) Aruba'],
['value' => 'America/Asuncion', 'key' => '(UTC-04:00) Asuncion'],
['value' => 'America/Barbados', 'key' => '(UTC-04:00) Barbados'],
['value' => 'Atlantic/Bermuda', 'key' => '(UTC-04:00) Bermuda'],
['value' => 'America/Blanc-Sablon', 'key' => '(UTC-04:00) Blanc-Sablon'],
['value' => 'America/Boa_Vista', 'key' => '(UTC-04:00) Boa Vista'],
['value' => 'America/Campo_Grande', 'key' => '(UTC-04:00) Campo Grande'],
['value' => 'America/Cuiaba', 'key' => '(UTC-04:00) Cuiaba'],
['value' => 'America/Curacao', 'key' => '(UTC-04:00) Curacao'],
['value' => 'America/Dominica', 'key' => '(UTC-04:00) Dominica'],
['value' => 'America/Eirunepe', 'key' => '(UTC-04:00) Eirunepe'],
['value' => 'America/Glace_Bay', 'key' => '(UTC-04:00) Glace Bay'],
['value' => 'America/Goose_Bay', 'key' => '(UTC-04:00) Goose Bay'],
['value' => 'America/Grenada', 'key' => '(UTC-04:00) Grenada'],
['value' => 'America/Guadeloupe', 'key' => '(UTC-04:00) Guadeloupe'],
['value' => 'America/Guyana', 'key' => '(UTC-04:00) Guyana'],
['value' => 'America/Halifax', 'key' => '(UTC-04:00) Halifax'],
['value' => 'America/Kralendijk', 'key' => '(UTC-04:00) Kralendijk'],
['value' => 'America/La_Paz', 'key' => '(UTC-04:00) La Paz'],
['value' => 'America/Lower_Princes', 'key' => '(UTC-04:00) Lower Princes'],
['value' => 'America/Manaus', 'key' => '(UTC-04:00) Manaus'],
['value' => 'America/Marigot', 'key' => '(UTC-04:00) Marigot'],
['value' => 'America/Martinique', 'key' => '(UTC-04:00) Martinique'],
['value' => 'America/Moncton', 'key' => '(UTC-04:00) Moncton'],
['value' => 'America/Montserrat', 'key' => '(UTC-04:00) Montserrat'],
['value' => 'Antarctica/Palmer', 'key' => '(UTC-04:00) Palmer'],
['value' => 'America/Port_of_Spain', 'key' => '(UTC-04:00) Port of Spain'],
['value' => 'America/Porto_Velho', 'key' => '(UTC-04:00) Porto Velho'],
['value' => 'America/Puerto_Rico', 'key' => '(UTC-04:00) Puerto Rico'],
['value' => 'America/Rio_Branco', 'key' => '(UTC-04:00) Rio Branco'],
['value' => 'America/Santiago', 'key' => '(UTC-04:00) Santiago'],
['value' => 'America/Santo_Domingo', 'key' => '(UTC-04:00) Santo Domingo'],
['value' => 'America/St_Barthelemy', 'key' => '(UTC-04:00) St. Barthelemy'],
['value' => 'America/St_Kitts', 'key' => '(UTC-04:00) St. Kitts'],
['value' => 'America/St_Lucia', 'key' => '(UTC-04:00) St. Lucia'],
['value' => 'America/St_Thomas', 'key' => '(UTC-04:00) St. Thomas'],
['value' => 'America/St_Vincent', 'key' => '(UTC-04:00) St. Vincent'],
['value' => 'America/Thule', 'key' => '(UTC-04:00) Thule'],
['value' => 'America/Tortola', 'key' => '(UTC-04:00) Tortola'],
['value' => 'America/St_Johns', 'key' => '(UTC-03:30) St. Johns'],
['value' => 'America/Araguaina', 'key' => '(UTC-03:00) Araguaina'],
['value' => 'America/Bahia', 'key' => '(UTC-03:00) Bahia'],
['value' => 'America/Belem', 'key' => '(UTC-03:00) Belem'],
['value' => 'America/Argentina/Buenos_Aires', 'key' => '(UTC-03:00) Buenos Aires'],
['value' => 'America/Argentina/Catamarca', 'key' => '(UTC-03:00) Catamarca'],
['value' => 'America/Cayenne', 'key' => '(UTC-03:00) Cayenne'],
['value' => 'America/Argentina/Cordoba', 'key' => '(UTC-03:00) Cordoba'],
['value' => 'America/Fortaleza', 'key' => '(UTC-03:00) Fortaleza'],
['value' => 'America/Godthab', 'key' => '(UTC-03:00) Godthab'],
['value' => 'America/Argentina/Jujuy', 'key' => '(UTC-03:00) Jujuy'],
['value' => 'America/Argentina/La_Rioja', 'key' => '(UTC-03:00) La Rioja'],
['value' => 'America/Maceio', 'key' => '(UTC-03:00) Maceio'],
['value' => 'America/Argentina/Mendoza', 'key' => '(UTC-03:00) Mendoza'],
['value' => 'America/Miquelon', 'key' => '(UTC-03:00) Miquelon'],
['value' => 'America/Montevideo', 'key' => '(UTC-03:00) Montevideo'],
['value' => 'America/Paramaribo', 'key' => '(UTC-03:00) Paramaribo'],
['value' => 'America/Recife', 'key' => '(UTC-03:00) Recife'],
['value' => 'America/Argentina/Rio_Gallegos', 'key' => '(UTC-03:00) Rio Gallegos'],
['value' => 'Antarctica/Rothera', 'key' => '(UTC-03:00) Rothera'],
['value' => 'America/Argentina/Salta', 'key' => '(UTC-03:00) Salta'],
['value' => 'America/Argentina/San_Juan', 'key' => '(UTC-03:00) San Juan'],
['value' => 'America/Argentina/San_Luis', 'key' => '(UTC-03:00) San Luis'],
['value' => 'America/Santarem', 'key' => '(UTC-03:00) Santarem'],
['value' => 'America/Sao_Paulo', 'key' => '(UTC-03:00) Sao Paulo'],
['value' => 'Atlantic/Stanley', 'key' => '(UTC-03:00) Stanley'],
['value' => 'America/Argentina/Tucuman', 'key' => '(UTC-03:00) Tucuman'],
['value' => 'America/Argentina/Ushuaia', 'key' => '(UTC-03:00) Ushuaia'],
['value' => 'America/Noronha', 'key' => '(UTC-02:00) Noronha'],
['value' => 'Atlantic/South_Georgia', 'key' => '(UTC-02:00) South Georgia'],
['value' => 'Atlantic/Azores', 'key' => '(UTC-01:00) Azores'],
['value' => 'Atlantic/Cape_Verde', 'key' => '(UTC-01:00) Cape Verde'],
['value' => 'America/Scoresbysund', 'key' => '(UTC-01:00) Scoresbysund'],
['value' => 'Africa/Abidjan', 'key' => '(UTC+00:00) Abidjan'],
['value' => 'Africa/Accra', 'key' => '(UTC+00:00) Accra'],
['value' => 'Africa/Bamako', 'key' => '(UTC+00:00) Bamako'],
['value' => 'Africa/Banjul', 'key' => '(UTC+00:00) Banjul'],
['value' => 'Africa/Bissau', 'key' => '(UTC+00:00) Bissau'],
['value' => 'Atlantic/Canary', 'key' => '(UTC+00:00) Canary'],
['value' => 'Africa/Casablanca', 'key' => '(UTC+00:00) Casablanca'],
['value' => 'Africa/Conakry', 'key' => '(UTC+00:00) Conakry'],
['value' => 'Africa/Dakar', 'key' => '(UTC+00:00) Dakar'],
['value' => 'America/Danmarkshavn', 'key' => '(UTC+00:00) Danmarkshavn'],
['value' => 'Europe/Dublin', 'key' => '(UTC+00:00) Dublin'],
['value' => 'Africa/El_Aaiun', 'key' => '(UTC+00:00) El Aaiun'],
['value' => 'Atlantic/Faroe', 'key' => '(UTC+00:00) Faroe'],
['value' => 'Africa/Freetown', 'key' => '(UTC+00:00) Freetown'],
['value' => 'Europe/Guernsey', 'key' => '(UTC+00:00) Guernsey'],
['value' => 'Europe/Isle_of_Man', 'key' => '(UTC+00:00) Isle of Man'],
['value' => 'Europe/Jersey', 'key' => '(UTC+00:00) Jersey'],
['value' => 'Europe/Lisbon', 'key' => '(UTC+00:00) Lisbon'],
['value' => 'Africa/Lome', 'key' => '(UTC+00:00) Lome'],
['value' => 'Europe/London', 'key' => '(UTC+00:00) London'],
['value' => 'Atlantic/Madeira', 'key' => '(UTC+00:00) Madeira'],
['value' => 'Africa/Monrovia', 'key' => '(UTC+00:00) Monrovia'],
['value' => 'Africa/Nouakchott', 'key' => '(UTC+00:00) Nouakchott'],
['value' => 'Africa/Ouagadougou', 'key' => '(UTC+00:00) Ouagadougou'],
['value' => 'Atlantic/Reykjavik', 'key' => '(UTC+00:00) Reykjavik'],
['value' => 'Africa/Sao_Tome', 'key' => '(UTC+00:00) Sao Tome'],
['value' => 'Atlantic/St_Helena', 'key' => '(UTC+00:00) St. Helena'],
['value' => 'UTC', 'key' => '(UTC+00:00) UTC'],
['value' => 'Africa/Algiers', 'key' => '(UTC+01:00) Algiers'],
['value' => 'Europe/Amsterdam', 'key' => '(UTC+01:00) Amsterdam'],
['value' => 'Europe/Andorra', 'key' => '(UTC+01:00) Andorra'],
['value' => 'Africa/Bangui', 'key' => '(UTC+01:00) Bangui'],
['value' => 'Europe/Belgrade', 'key' => '(UTC+01:00) Belgrade'],
['value' => 'Europe/Berlin', 'key' => '(UTC+01:00) Berlin'],
['value' => 'Europe/Bratislava', 'key' => '(UTC+01:00) Bratislava'],
['value' => 'Africa/Brazzaville', 'key' => '(UTC+01:00) Brazzaville'],
['value' => 'Europe/Brussels', 'key' => '(UTC+01:00) Brussels'],
['value' => 'Europe/Budapest', 'key' => '(UTC+01:00) Budapest'],
['value' => 'Europe/Busingen', 'key' => '(UTC+01:00) Busingen'],
['value' => 'Africa/Ceuta', 'key' => '(UTC+01:00) Ceuta'],
['value' => 'Europe/Copenhagen', 'key' => '(UTC+01:00) Copenhagen'],
['value' => 'Africa/Douala', 'key' => '(UTC+01:00) Douala'],
['value' => 'Europe/Gibraltar', 'key' => '(UTC+01:00) Gibraltar'],
['value' => 'Africa/Kinshasa', 'key' => '(UTC+01:00) Kinshasa'],
['value' => 'Africa/Lagos', 'key' => '(UTC+01:00) Lagos'],
['value' => 'Africa/Libreville', 'key' => '(UTC+01:00) Libreville'],
['value' => 'Europe/Ljubljana', 'key' => '(UTC+01:00) Ljubljana'],
['value' => 'Arctic/Longyearbyen', 'key' => '(UTC+01:00) Longyearbyen'],
['value' => 'Africa/Luanda', 'key' => '(UTC+01:00) Luanda'],
['value' => 'Europe/Luxembourg', 'key' => '(UTC+01:00) Luxembourg'],
['value' => 'Europe/Madrid', 'key' => '(UTC+01:00) Madrid'],
['value' => 'Africa/Malabo', 'key' => '(UTC+01:00) Malabo'],
['value' => 'Europe/Malta', 'key' => '(UTC+01:00) Malta'],
['value' => 'Europe/Monaco', 'key' => '(UTC+01:00) Monaco'],
['value' => 'Africa/Ndjamena', 'key' => '(UTC+01:00) Ndjamena'],
['value' => 'Africa/Niamey', 'key' => '(UTC+01:00) Niamey'],
['value' => 'Europe/Oslo', 'key' => '(UTC+01:00) Oslo'],
['value' => 'Europe/Paris', 'key' => '(UTC+01:00) Paris'],
['value' => 'Europe/Podgorica', 'key' => '(UTC+01:00) Podgorica'],
['value' => 'Africa/Porto-Novo', 'key' => '(UTC+01:00) Porto-Novo'],
['value' => 'Europe/Prague', 'key' => '(UTC+01:00) Prague'],
['value' => 'Europe/Rome', 'key' => '(UTC+01:00) Rome'],
['value' => 'Europe/San_Marino', 'key' => '(UTC+01:00) San Marino'],
['value' => 'Europe/Sarajevo', 'key' => '(UTC+01:00) Sarajevo'],
['value' => 'Europe/Skopje', 'key' => '(UTC+01:00) Skopje'],
['value' => 'Europe/Stockholm', 'key' => '(UTC+01:00) Stockholm'],
['value' => 'Europe/Tirane', 'key' => '(UTC+01:00) Tirane'],
['value' => 'Africa/Tripoli', 'key' => '(UTC+01:00) Tripoli'],
['value' => 'Africa/Tunis', 'key' => '(UTC+01:00) Tunis'],
['value' => 'Europe/Vaduz', 'key' => '(UTC+01:00) Vaduz'],
['value' => 'Europe/Vatican', 'key' => '(UTC+01:00) Vatican'],
['value' => 'Europe/Vienna', 'key' => '(UTC+01:00) Vienna'],
['value' => 'Europe/Warsaw', 'key' => '(UTC+01:00) Warsaw'],
['value' => 'Africa/Windhoek', 'key' => '(UTC+01:00) Windhoek'],
['value' => 'Europe/Zagreb', 'key' => '(UTC+01:00) Zagreb'],
['value' => 'Europe/Zurich', 'key' => '(UTC+01:00) Zurich'],
['value' => 'Europe/Athens', 'key' => '(UTC+02:00) Athens'],
['value' => 'Asia/Beirut', 'key' => '(UTC+02:00) Beirut'],
['value' => 'Africa/Blantyre', 'key' => '(UTC+02:00) Blantyre'],
['value' => 'Europe/Bucharest', 'key' => '(UTC+02:00) Bucharest'],
['value' => 'Africa/Bujumbura', 'key' => '(UTC+02:00) Bujumbura'],
['value' => 'Africa/Cairo', 'key' => '(UTC+02:00) Cairo'],
['value' => 'Europe/Chisinau', 'key' => '(UTC+02:00) Chisinau'],
['value' => 'Asia/Damascus', 'key' => '(UTC+02:00) Damascus'],
['value' => 'Africa/Gaborone', 'key' => '(UTC+02:00) Gaborone'],
['value' => 'Asia/Gaza', 'key' => '(UTC+02:00) Gaza'],
['value' => 'Africa/Harare', 'key' => '(UTC+02:00) Harare'],
['value' => 'Asia/Hebron', 'key' => '(UTC+02:00) Hebron'],
['value' => 'Europe/Helsinki', 'key' => '(UTC+02:00) Helsinki'],
['value' => 'Europe/Istanbul', 'key' => '(UTC+02:00) Istanbul'],
['value' => 'Asia/Jerusalem', 'key' => '(UTC+02:00) Jerusalem'],
['value' => 'Africa/Johannesburg', 'key' => '(UTC+02:00) Johannesburg'],
['value' => 'Europe/Kiev', 'key' => '(UTC+02:00) Kiev'],
['value' => 'Africa/Kigali', 'key' => '(UTC+02:00) Kigali'],
['value' => 'Africa/Lubumbashi', 'key' => '(UTC+02:00) Lubumbashi'],
['value' => 'Africa/Lusaka', 'key' => '(UTC+02:00) Lusaka'],
['value' => 'Africa/Maputo', 'key' => '(UTC+02:00) Maputo'],
['value' => 'Europe/Mariehamn', 'key' => '(UTC+02:00) Mariehamn'],
['value' => 'Africa/Maseru', 'key' => '(UTC+02:00) Maseru'],
['value' => 'Africa/Mbabane', 'key' => '(UTC+02:00) Mbabane'],
['value' => 'Asia/Nicosia', 'key' => '(UTC+02:00) Nicosia'],
['value' => 'Europe/Riga', 'key' => '(UTC+02:00) Riga'],
['value' => 'Europe/Simferopol', 'key' => '(UTC+02:00) Simferopol'],
['value' => 'Europe/Sofia', 'key' => '(UTC+02:00) Sofia'],
['value' => 'Europe/Tallinn', 'key' => '(UTC+02:00) Tallinn'],
['value' => 'Europe/Uzhgorod', 'key' => '(UTC+02:00) Uzhgorod'],
['value' => 'Europe/Vilnius', 'key' => '(UTC+02:00) Vilnius'],
['value' => 'Europe/Zaporozhye', 'key' => '(UTC+02:00) Zaporozhye'],
['value' => 'Africa/Addis_Ababa', 'key' => '(UTC+03:00) Addis Ababa'],
['value' => 'Asia/Aden', 'key' => '(UTC+03:00) Aden'],
['value' => 'Asia/Amman', 'key' => '(UTC+03:00) Amman'],
['value' => 'Indian/Antananarivo', 'key' => '(UTC+03:00) Antananarivo'],
['value' => 'Africa/Asmara', 'key' => '(UTC+03:00) Asmara'],
['value' => 'Asia/Baghdad', 'key' => '(UTC+03:00) Baghdad'],
['value' => 'Asia/Bahrain', 'key' => '(UTC+03:00) Bahrain'],
['value' => 'Indian/Comoro', 'key' => '(UTC+03:00) Comoro'],
['value' => 'Africa/Dar_es_Salaam', 'key' => '(UTC+03:00) Dar es Salaam'],
['value' => 'Africa/Djibouti', 'key' => '(UTC+03:00) Djibouti'],
['value' => 'Africa/Juba', 'key' => '(UTC+03:00) Juba'],
['value' => 'Europe/Kaliningrad', 'key' => '(UTC+03:00) Kaliningrad'],
['value' => 'Africa/Kampala', 'key' => '(UTC+03:00) Kampala'],
['value' => 'Africa/Khartoum', 'key' => '(UTC+03:00) Khartoum'],
['value' => 'Asia/Kuwait', 'key' => '(UTC+03:00) Kuwait'],
['value' => 'Indian/Mayotte', 'key' => '(UTC+03:00) Mayotte'],
['value' => 'Europe/Minsk', 'key' => '(UTC+03:00) Minsk'],
['value' => 'Africa/Mogadishu', 'key' => '(UTC+03:00) Mogadishu'],
['value' => 'Africa/Nairobi', 'key' => '(UTC+03:00) Nairobi'],
['value' => 'Asia/Qatar', 'key' => '(UTC+03:00) Qatar'],
['value' => 'Asia/Riyadh', 'key' => '(UTC+03:00) Riyadh'],
['value' => 'Antarctica/Syowa', 'key' => '(UTC+03:00) Syowa'],
['value' => 'Asia/Tehran', 'key' => '(UTC+03:30) Tehran'],
['value' => 'Asia/Baku', 'key' => '(UTC+04:00) Baku'],
['value' => 'Asia/Dubai', 'key' => '(UTC+04:00) Dubai'],
['value' => 'Indian/Mahe', 'key' => '(UTC+04:00) Mahe'],
['value' => 'Indian/Mauritius', 'key' => '(UTC+04:00) Mauritius'],
['value' => 'Europe/Moscow', 'key' => '(UTC+04:00) Moscow'],
['value' => 'Asia/Muscat', 'key' => '(UTC+04:00) Muscat'],
['value' => 'Indian/Reunion', 'key' => '(UTC+04:00) Reunion'],
['value' => 'Europe/Samara', 'key' => '(UTC+04:00) Samara'],
['value' => 'Asia/Tbilisi', 'key' => '(UTC+04:00) Tbilisi'],
['value' => 'Europe/Volgograd', 'key' => '(UTC+04:00) Volgograd'],
['value' => 'Asia/Yerevan', 'key' => '(UTC+04:00) Yerevan'],
['value' => 'Asia/Kabul', 'key' => '(UTC+04:30) Kabul'],
['value' => 'Asia/Aqtau', 'key' => '(UTC+05:00) Aqtau'],
['value' => 'Asia/Aqtobe', 'key' => '(UTC+05:00) Aqtobe'],
['value' => 'Asia/Ashgabat', 'key' => '(UTC+05:00) Ashgabat'],
['value' => 'Asia/Dushanbe', 'key' => '(UTC+05:00) Dushanbe'],
['value' => 'Asia/Karachi', 'key' => '(UTC+05:00) Karachi'],
['value' => 'Indian/Kerguelen', 'key' => '(UTC+05:00) Kerguelen'],
['value' => 'Indian/Maldives', 'key' => '(UTC+05:00) Maldives'],
['value' => 'Antarctica/Mawson', 'key' => '(UTC+05:00) Mawson'],
['value' => 'Asia/Oral', 'key' => '(UTC+05:00) Oral'],
['value' => 'Asia/Samarkand', 'key' => '(UTC+05:00) Samarkand'],
['value' => 'Asia/Tashkent', 'key' => '(UTC+05:00) Tashkent'],
['value' => 'Asia/Colombo', 'key' => '(UTC+05:30) Colombo'],
['value' => 'Asia/Kolkata', 'key' => '(UTC+05:30) Kolkata'],
['value' => 'Asia/Kathmandu', 'key' => '(UTC+05:45) Kathmandu'],
['value' => 'Asia/Almaty', 'key' => '(UTC+06:00) Almaty'],
['value' => 'Asia/Bishkek', 'key' => '(UTC+06:00) Bishkek'],
['value' => 'Indian/Chagos', 'key' => '(UTC+06:00) Chagos'],
['value' => 'Asia/Dhaka', 'key' => '(UTC+06:00) Dhaka'],
['value' => 'Asia/Qyzylorda', 'key' => '(UTC+06:00) Qyzylorda'],
['value' => 'Asia/Thimphu', 'key' => '(UTC+06:00) Thimphu'],
['value' => 'Antarctica/Vostok', 'key' => '(UTC+06:00) Vostok'],
['value' => 'Asia/Yekaterinburg', 'key' => '(UTC+06:00) Yekaterinburg'],
['value' => 'Indian/Cocos', 'key' => '(UTC+06:30) Cocos'],
['value' => 'Asia/Rangoon', 'key' => '(UTC+06:30) Rangoon'],
['value' => 'Asia/Bangkok', 'key' => '(UTC+07:00) Bangkok'],
['value' => 'Indian/Christmas', 'key' => '(UTC+07:00) Christmas'],
['value' => 'Antarctica/Davis', 'key' => '(UTC+07:00) Davis'],
['value' => 'Asia/Ho_Chi_Minh', 'key' => '(UTC+07:00) Ho Chi Minh'],
['value' => 'Asia/Hovd', 'key' => '(UTC+07:00) Hovd'],
['value' => 'Asia/Jakarta', 'key' => '(UTC+07:00) Jakarta'],
['value' => 'Asia/Novokuznetsk', 'key' => '(UTC+07:00) Novokuznetsk'],
['value' => 'Asia/Novosibirsk', 'key' => '(UTC+07:00) Novosibirsk'],
['value' => 'Asia/Omsk', 'key' => '(UTC+07:00) Omsk'],
['value' => 'Asia/Phnom_Penh', 'key' => '(UTC+07:00) Phnom Penh'],
['value' => 'Asia/Pontianak', 'key' => '(UTC+07:00) Pontianak'],
['value' => 'Asia/Vientiane', 'key' => '(UTC+07:00) Vientiane'],
['value' => 'Asia/Brunei', 'key' => '(UTC+08:00) Brunei'],
['value' => 'Antarctica/Casey', 'key' => '(UTC+08:00) Casey'],
['value' => 'Asia/Choibalsan', 'key' => '(UTC+08:00) Choibalsan'],
['value' => 'Asia/Chongqing', 'key' => '(UTC+08:00) Chongqing'],
['value' => 'Asia/Harbin', 'key' => '(UTC+08:00) Harbin'],
['value' => 'Asia/Hong_Kong', 'key' => '(UTC+08:00) Hong Kong'],
['value' => 'Asia/Kashgar', 'key' => '(UTC+08:00) Kashgar'],
['value' => 'Asia/Krasnoyarsk', 'key' => '(UTC+08:00) Krasnoyarsk'],
['value' => 'Asia/Kuala_Lumpur', 'key' => '(UTC+08:00) Kuala Lumpur'],
['value' => 'Asia/Kuching', 'key' => '(UTC+08:00) Kuching'],
['value' => 'Asia/Macau', 'key' => '(UTC+08:00) Macau'],
['value' => 'Asia/Makassar', 'key' => '(UTC+08:00) Makassar'],
['value' => 'Asia/Manila', 'key' => '(UTC+08:00) Manila'],
['value' => 'Australia/Perth', 'key' => '(UTC+08:00) Perth'],
['value' => 'Asia/Shanghai', 'key' => '(UTC+08:00) Shanghai'],
['value' => 'Asia/Singapore', 'key' => '(UTC+08:00) Singapore'],
['value' => 'Asia/Taipei', 'key' => '(UTC+08:00) Taipei'],
['value' => 'Asia/Ulaanbaatar', 'key' => '(UTC+08:00) Ulaanbaatar'],
['value' => 'Asia/Urumqi', 'key' => '(UTC+08:00) Urumqi'],
['value' => 'Australia/Eucla', 'key' => '(UTC+08:45) Eucla'],
['value' => 'Asia/Dili', 'key' => '(UTC+09:00) Dili'],
['value' => 'Asia/Irkutsk', 'key' => '(UTC+09:00) Irkutsk'],
['value' => 'Asia/Jayapura', 'key' => '(UTC+09:00) Jayapura'],
['value' => 'Pacific/Palau', 'key' => '(UTC+09:00) Palau'],
['value' => 'Asia/Pyongyang', 'key' => '(UTC+09:00) Pyongyang'],
['value' => 'Asia/Seoul', 'key' => '(UTC+09:00) Seoul'],
['value' => 'Asia/Tokyo', 'key' => '(UTC+09:00) Tokyo'],
['value' => 'Australia/Adelaide', 'key' => '(UTC+09:30) Adelaide'],
['value' => 'Australia/Broken_Hill', 'key' => '(UTC+09:30) Broken Hill'],
['value' => 'Australia/Darwin', 'key' => '(UTC+09:30) Darwin'],
['value' => 'Australia/Brisbane', 'key' => '(UTC+10:00) Brisbane'],
['value' => 'Pacific/Chuuk', 'key' => '(UTC+10:00) Chuuk'],
['value' => 'Australia/Currie', 'key' => '(UTC+10:00) Currie'],
['value' => 'Antarctica/DumontDUrville', 'key' => '(UTC+10:00) DumontDUrville'],
['value' => 'Pacific/Guam', 'key' => '(UTC+10:00) Guam'],
['value' => 'Australia/Hobart', 'key' => '(UTC+10:00) Hobart'],
['value' => 'Asia/Khandyga', 'key' => '(UTC+10:00) Khandyga'],
['value' => 'Australia/Lindeman', 'key' => '(UTC+10:00) Lindeman'],
['value' => 'Australia/Melbourne', 'key' => '(UTC+10:00) Melbourne'],
['value' => 'Pacific/Port_Moresby', 'key' => '(UTC+10:00) Port Moresby'],
['value' => 'Pacific/Saipan', 'key' => '(UTC+10:00) Saipan'],
['value' => 'Australia/Sydney', 'key' => '(UTC+10:00) Sydney'],
['value' => 'Asia/Yakutsk', 'key' => '(UTC+10:00) Yakutsk'],
['value' => 'Australia/Lord_Howe', 'key' => '(UTC+10:30) Lord Howe'],
['value' => 'Pacific/Efate', 'key' => '(UTC+11:00) Efate'],
['value' => 'Pacific/Guadalcanal', 'key' => '(UTC+11:00) Guadalcanal'],
['value' => 'Pacific/Kosrae', 'key' => '(UTC+11:00) Kosrae'],
['value' => 'Antarctica/Macquarie', 'key' => '(UTC+11:00) Macquarie'],
['value' => 'Pacific/Noumea', 'key' => '(UTC+11:00) Noumea'],
['value' => 'Pacific/Pohnpei', 'key' => '(UTC+11:00) Pohnpei'],
['value' => 'Asia/Sakhalin', 'key' => '(UTC+11:00) Sakhalin'],
['value' => 'Asia/Ust-Nera', 'key' => '(UTC+11:00) Ust-Nera'],
['value' => 'Asia/Vladivostok', 'key' => '(UTC+11:00) Vladivostok'],
['value' => 'Pacific/Norfolk', 'key' => '(UTC+11:30) Norfolk'],
['value' => 'Asia/Anadyr', 'key' => '(UTC+12:00) Anadyr'],
['value' => 'Pacific/Auckland', 'key' => '(UTC+12:00) Auckland'],
['value' => 'Pacific/Fiji', 'key' => '(UTC+12:00) Fiji'],
['value' => 'Pacific/Funafuti', 'key' => '(UTC+12:00) Funafuti'],
['value' => 'Asia/Kamchatka', 'key' => '(UTC+12:00) Kamchatka'],
['value' => 'Pacific/Kwajalein', 'key' => '(UTC+12:00) Kwajalein'],
['value' => 'Asia/Magadan', 'key' => '(UTC+12:00) Magadan'],
['value' => 'Pacific/Majuro', 'key' => '(UTC+12:00) Majuro'],
['value' => 'Antarctica/McMurdo', 'key' => '(UTC+12:00) McMurdo'],
['value' => 'Pacific/Nauru', 'key' => '(UTC+12:00) Nauru'],
['value' => 'Antarctica/South_Pole', 'key' => '(UTC+12:00) South Pole'],
['value' => 'Pacific/Tarawa', 'key' => '(UTC+12:00) Tarawa'],
['value' => 'Pacific/Wake', 'key' => '(UTC+12:00) Wake'],
['value' => 'Pacific/Wallis', 'key' => '(UTC+12:00) Wallis'],
['value' => 'Pacific/Chatham', 'key' => '(UTC+12:45) Chatham'],
['value' => 'Pacific/Apia', 'key' => '(UTC+13:00) Apia'],
['value' => 'Pacific/Enderbury', 'key' => '(UTC+13:00) Enderbury'],
['value' => 'Pacific/Fakaofo', 'key' => '(UTC+13:00) Fakaofo'],
['value' => 'Pacific/Tongatapu', 'key' => '(UTC+13:00) Tongatapu'],
['value' => 'Pacific/Kiritimati', 'key' => '(UTC+14:00) Kiritimati'],
];
}
}

196
app/Support/helpers.php Normal file
View File

@@ -0,0 +1,196 @@
<?php
use App\Models\CompanySetting;
use App\Models\Currency;
use App\Models\CustomField;
use App\Models\Setting;
use App\Services\Installation\InstallUtils;
use Illuminate\Support\Str;
/**
* Get company setting
*
* @return string
*/
function get_company_setting($key, $company_id)
{
if (! InstallUtils::isDbCreated()) {
return null;
}
return CompanySetting::getSetting($key, $company_id);
}
/**
* Get app setting
*
* @param $company_id
* @return string
*/
function get_app_setting($key)
{
if (! InstallUtils::isDbCreated()) {
return null;
}
return Setting::getSetting($key);
}
/**
* Get page title
*
* @return string
*/
function get_page_title($company_id)
{
if (! InstallUtils::isDbCreated()) {
return null;
}
$routeName = Route::currentRouteName();
$defaultPageTitle = 'InvoiceShelf - Self Hosted Invoicing Platform';
if ($routeName === 'customer.dashboard') {
$pageTitle = CompanySetting::getSetting('customer_portal_page_title', $company_id);
return $pageTitle ? $pageTitle : $defaultPageTitle;
}
$pageTitle = Setting::getSetting('admin_page_title');
return $pageTitle ? $pageTitle : $defaultPageTitle;
}
/**
* Set Active Path
*
* @param string $active
* @return string
*/
function set_active($path, $active = 'active')
{
return call_user_func_array('Request::is', (array) $path) ? $active : '';
}
/**
* @return mixed
*/
function is_url($path)
{
return call_user_func_array('Request::is', (array) $path);
}
/**
* @return string
*/
function getCustomFieldValueKey(string $type)
{
switch ($type) {
case 'Input':
return 'string_answer';
case 'TextArea':
return 'string_answer';
case 'Phone':
return 'number_answer';
case 'Url':
return 'string_answer';
case 'Number':
return 'number_answer';
case 'Dropdown':
return 'string_answer';
case 'Switch':
return 'boolean_answer';
case 'Date':
return 'date_answer';
case 'Time':
return 'time_answer';
case 'DateTime':
return 'date_time_answer';
default:
return 'string_answer';
}
}
/**
* @return formated_money
*/
function format_money_pdf($money, $currency = null)
{
$money = $money / 100;
if (! $currency) {
$currency = Currency::findOrFail(CompanySetting::getSetting('currency', 1));
}
$format_money = number_format(
$money,
$currency->precision,
$currency->decimal_separator,
$currency->thousand_separator
);
$currency_with_symbol = '';
if ($currency->swap_currency_symbol) {
$currency_with_symbol = $format_money.'<span style="font-family: DejaVu Sans;">'.$currency->symbol.'</span>';
} else {
$currency_with_symbol = '<span style="font-family: DejaVu Sans;">'.$currency->symbol.'</span>'.$format_money;
}
return $currency_with_symbol;
}
/**
* @param $string
* @return string
*/
function clean_slug($model, $title, $id = 0)
{
// Normalize the title
$slug = Str::upper('CUSTOM_'.$model.'_'.Str::slug($title, '_'));
// Get any that could possibly be related.
// This cuts the queries down by doing it once.
$allSlugs = getRelatedSlugs($model, $slug, $id);
// If we haven't used it before then we are all good.
if (! $allSlugs->contains('slug', $slug)) {
return $slug;
}
// Just append numbers like a savage until we find not used.
for ($i = 1; $i <= 10; $i++) {
$newSlug = $slug.'_'.$i;
if (! $allSlugs->contains('slug', $newSlug)) {
return $newSlug;
}
}
throw new Exception('Can not create a unique slug');
}
function getRelatedSlugs($type, $slug, $id = 0)
{
return CustomField::select('slug')->where('slug', 'like', $slug.'%')
->where('model_type', $type)
->where('id', '<>', $id)
->get();
}
function respondJson($error, $message)
{
return response()->json([
'error' => $error,
'message' => $message,
], 422);
}