diff --git a/app/Console/Commands/DemoMode.php b/app/Console/Commands/DemoMode.php index e468b3f1c6..0ce7529660 100644 --- a/app/Console/Commands/DemoMode.php +++ b/app/Console/Commands/DemoMode.php @@ -7,6 +7,7 @@ use App\Events\Invoice\InvoiceWasCreated; use App\Factory\InvoiceFactory; use App\Factory\InvoiceItemFactory; use App\Helpers\Invoice\InvoiceSum; +use App\Jobs\Ninja\CompanySizeCheck; use App\Jobs\Util\VersionCheck; use App\Models\CompanyToken; use App\Models\Country; @@ -79,6 +80,9 @@ class DemoMode extends Command $this->createSmallAccount(); VersionCheck::dispatchNow(); + + CompanySizeCheck::dispatchNow(); + } @@ -360,7 +364,7 @@ class DemoMode extends Command $this->invoice_repo->markSent($invoice); - if (rand(0, 1)) { + if ((bool)rand(0, 2)) { $invoice = $invoice->service()->markPaid()->save(); diff --git a/app/DataMapper/CompanySettings.php b/app/DataMapper/CompanySettings.php index fe523721f1..65c98a14a3 100644 --- a/app/DataMapper/CompanySettings.php +++ b/app/DataMapper/CompanySettings.php @@ -27,6 +27,8 @@ class CompanySettings extends BaseSettings public $auto_archive_invoice = false; public $lock_sent_invoices = false; + public $lock_invoices = 'off'; //off,when_sent,when_paid + public $enable_client_portal_tasks = false; public $enable_client_portal_password = false; public $enable_client_portal = true; //implemented @@ -236,6 +238,7 @@ class CompanySettings extends BaseSettings public $client_portal_privacy_policy = ''; public static $casts = [ + 'lock_invoices' => 'string', 'client_portal_terms' => 'string', 'client_portal_privacy_policy' => 'string', 'client_can_register' => 'bool', diff --git a/app/Factory/CompanyFactory.php b/app/Factory/CompanyFactory.php index 44eaf27523..d5a1649231 100644 --- a/app/Factory/CompanyFactory.php +++ b/app/Factory/CompanyFactory.php @@ -34,7 +34,7 @@ class CompanyFactory //$company->custom_fields = (object) ['invoice1' => '1', 'invoice2' => '2', 'client1'=>'3']; $company->custom_fields = (object) []; $company->subdomain = ''; - $company->enabled_modules = 4095; + $company->enabled_modules = 4095; //16383 return $company; } diff --git a/app/Http/Controllers/PingController.php b/app/Http/Controllers/PingController.php index 175463fa9d..a3db94d940 100644 --- a/app/Http/Controllers/PingController.php +++ b/app/Http/Controllers/PingController.php @@ -23,6 +23,9 @@ class PingController extends BaseController */ public function index() { - return response()->json(['company_name' => auth()->user()->getCompany()->present()->name() - auth()->user()->present()->name()], 200); + return response()->json( + ['company_name' => auth()->user()->getCompany()->present()->name(), + 'user_name' => auth()->user()->present()->name(), + ], 200); } } diff --git a/app/Http/Middleware/PasswordProtection.php b/app/Http/Middleware/PasswordProtection.php index ce91d95313..eb43ff9b74 100644 --- a/app/Http/Middleware/PasswordProtection.php +++ b/app/Http/Middleware/PasswordProtection.php @@ -41,7 +41,7 @@ class PasswordProtection } } elseif (Cache::get(auth()->user()->email."_logged_in")) { Cache::pull(auth()->user()->email."_logged_in"); - Cache::add(auth()->user()->email."_logged_in", Str::random(64), now()->addMinutes(10)); + Cache::add(auth()->user()->email."_logged_in", Str::random(64), now()->addMinutes(30)); return $next($request); } else { @@ -52,7 +52,7 @@ class PasswordProtection return response()->json($error, 412); } - Cache::add(auth()->user()->email."_logged_in", Str::random(64), now()->addMinutes(10)); + Cache::add(auth()->user()->email."_logged_in", Str::random(64), now()->addMinutes(30)); return $next($request); } diff --git a/app/Models/Client.php b/app/Models/Client.php index 7624067aac..3ad2876eaf 100644 --- a/app/Models/Client.php +++ b/app/Models/Client.php @@ -116,6 +116,8 @@ class Client extends BaseModel implements HasLocalePreference 'deleted_at' => 'timestamp', ]; + protected $touches = ['company']; + public function getEntityType() { return Client::class; diff --git a/app/Models/ClientContact.php b/app/Models/ClientContact.php index 73580b2ed8..425b9a09fc 100644 --- a/app/Models/ClientContact.php +++ b/app/Models/ClientContact.php @@ -37,6 +37,8 @@ class ClientContact extends Authenticatable implements HasLocalePreference /* Used to authenticate a contact */ protected $guard = 'contact'; + protected $touches = ['client']; + /* Allow microtime timestamps */ protected $dateFormat = 'Y-m-d H:i:s.u'; diff --git a/app/Models/Company.php b/app/Models/Company.php index 39e084fdcd..2dc887c1f1 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -65,6 +65,22 @@ class Company extends BaseModel const ENTITY_RECURRING_TASK = 'task'; const ENTITY_RECURRING_QUOTE = 'recurring_quote'; + // const int kModuleRecurringInvoices = 1; + // const int kModuleCredits = 2; + // const int kModuleQuotes = 4; + // const int kModuleTasks = 8; + // const int kModuleExpenses = 16; + // const int kModuleProjects = 32; + // const int kModuleVendors = 64; + // const int kModuleTickets = 128; + // const int kModuleProposals = 256; + // const int kModuleRecurringExpenses = 512; + // const int kModuleRecurringTasks = 1024; + // const int kModuleRecurringQuotes = 2048; + // kModuleInvoices = 4096; + // kModulePayments = 8192; + // 16383 + protected $presenter = 'App\Models\Presenters\CompanyPresenter'; protected $fillable = [ diff --git a/app/Models/CompanyGateway.php b/app/Models/CompanyGateway.php index 3d667610e4..dd1ba7c355 100644 --- a/app/Models/CompanyGateway.php +++ b/app/Models/CompanyGateway.php @@ -58,6 +58,8 @@ class CompanyGateway extends BaseModel // return json_decode($this->attributes['fees_and_limits']); // } + protected $touches = ['company']; + public function getEntityType() { return CompanyGateway::class; diff --git a/app/Models/CompanyLedger.php b/app/Models/CompanyLedger.php index b5e660a6b9..9d0bc73d49 100644 --- a/app/Models/CompanyLedger.php +++ b/app/Models/CompanyLedger.php @@ -27,6 +27,8 @@ class CompanyLedger extends Model 'deleted_at' => 'timestamp', ]; + protected $touches = ['company']; + public function getEntityType() { return CompanyLedger::class; diff --git a/app/Models/CompanyToken.php b/app/Models/CompanyToken.php index 1e12652aa2..ddbb7b0ef5 100644 --- a/app/Models/CompanyToken.php +++ b/app/Models/CompanyToken.php @@ -27,6 +27,9 @@ class CompanyToken extends BaseModel protected $with = [ ]; + protected $touches = ['company']; + + public function getEntityType() { return CompanyToken::class; diff --git a/app/Models/CompanyUser.php b/app/Models/CompanyUser.php index 5f7b5713c2..1eef8f3e0a 100644 --- a/app/Models/CompanyUser.php +++ b/app/Models/CompanyUser.php @@ -48,6 +48,8 @@ class CompanyUser extends Pivot 'slack_webhook_url', ]; + protected $touches = ['company']; + public function getEntityType() { return CompanyUser::class; diff --git a/app/Models/Credit.php b/app/Models/Credit.php index 944ca7c9aa..9a1d2485bd 100644 --- a/app/Models/Credit.php +++ b/app/Models/Credit.php @@ -78,6 +78,8 @@ class Credit extends BaseModel 'deleted_at' => 'timestamp', ]; + protected $touches = ['company']; + const STATUS_DRAFT = 1; const STATUS_SENT = 2; const STATUS_PARTIAL = 3; diff --git a/app/Models/CreditInvitation.php b/app/Models/CreditInvitation.php index c1171e752d..4cb800289b 100644 --- a/app/Models/CreditInvitation.php +++ b/app/Models/CreditInvitation.php @@ -37,6 +37,8 @@ class CreditInvitation extends BaseModel // 'company', ]; + protected $touches = ['credit']; + public function getEntityType() { return CreditInvitation::class; diff --git a/app/Models/Expense.php b/app/Models/Expense.php index 460215af79..f9bb522510 100644 --- a/app/Models/Expense.php +++ b/app/Models/Expense.php @@ -59,6 +59,8 @@ class Expense extends BaseModel 'created_at' => 'timestamp', 'deleted_at' => 'timestamp', ]; + + protected $touches = ['company']; public function getEntityType() { diff --git a/app/Models/GroupSetting.php b/app/Models/GroupSetting.php index 6ab76f8fca..41f5d6ac66 100644 --- a/app/Models/GroupSetting.php +++ b/app/Models/GroupSetting.php @@ -40,6 +40,8 @@ class GroupSetting extends StaticModel 'settings' ]; + protected $touches = ['company']; + public function company() { return $this->belongsTo(Company::class); diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index fb60aa9486..a77a5d89a3 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -56,6 +56,8 @@ class Invoice extends BaseModel protected $presenter = 'App\Models\Presenters\InvoicePresenter'; + protected $touches = ['company']; + protected $hidden = [ 'id', 'private_notes', diff --git a/app/Models/InvoiceInvitation.php b/app/Models/InvoiceInvitation.php index 466ec9fd75..7ecbed228f 100644 --- a/app/Models/InvoiceInvitation.php +++ b/app/Models/InvoiceInvitation.php @@ -36,6 +36,9 @@ class InvoiceInvitation extends BaseModel // 'company', ]; + protected $touches = ['invoice']; + + public function getEntityType() { return InvoiceInvitation::class; diff --git a/app/Models/Payment.php b/app/Models/Payment.php index 64b7e8edf0..d76b283905 100644 --- a/app/Models/Payment.php +++ b/app/Models/Payment.php @@ -81,6 +81,8 @@ class Payment extends BaseModel 'paymentables', ]; + protected $touches = ['company']; + public function getEntityType() { return Payment::class; diff --git a/app/Models/Product.php b/app/Models/Product.php index d6cf016ad6..bc965b0623 100644 --- a/app/Models/Product.php +++ b/app/Models/Product.php @@ -40,6 +40,8 @@ class Product extends BaseModel 'tax_rate3', ]; + protected $touches = ['company']; + public function getEntityType() { return Product::class; diff --git a/app/Models/Project.php b/app/Models/Project.php index 9ac53ca4ef..8b262b6280 100644 --- a/app/Models/Project.php +++ b/app/Models/Project.php @@ -42,6 +42,8 @@ class Project extends BaseModel return Project::class; } + protected $touches = ['company']; + /** * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ diff --git a/app/Models/Proposal.php b/app/Models/Proposal.php index d31500e7d8..b6c40696b3 100644 --- a/app/Models/Proposal.php +++ b/app/Models/Proposal.php @@ -22,6 +22,8 @@ class Proposal extends BaseModel 'id', ]; + protected $touches = ['company']; + public function getEntityType() { return Proposal::class; diff --git a/app/Models/Quote.php b/app/Models/Quote.php index ccb8d743de..e5a42b45c0 100644 --- a/app/Models/Quote.php +++ b/app/Models/Quote.php @@ -42,6 +42,8 @@ class Quote extends BaseModel protected $presenter = 'App\Models\Presenters\QuotePresenter'; + protected $touches = ['company']; + protected $fillable = [ 'assigned_user_id', 'number', diff --git a/app/Models/QuoteInvitation.php b/app/Models/QuoteInvitation.php index 5bef00af9f..4a794ce52a 100644 --- a/app/Models/QuoteInvitation.php +++ b/app/Models/QuoteInvitation.php @@ -31,6 +31,8 @@ class QuoteInvitation extends BaseModel 'client_contact_id', ]; + protected $touches = ['quote']; + public function getEntityType() { return QuoteInvitation::class; diff --git a/app/Models/RecurringInvoice.php b/app/Models/RecurringInvoice.php index 2a6c20621f..a3ee5cbcb8 100644 --- a/app/Models/RecurringInvoice.php +++ b/app/Models/RecurringInvoice.php @@ -112,6 +112,8 @@ class RecurringInvoice extends BaseModel 'status' ]; + protected $touches = ['company']; + public function getEntityType() { return RecurringInvoice::class; diff --git a/app/Models/RecurringInvoiceInvitation.php b/app/Models/RecurringInvoiceInvitation.php index d991a60fa0..7c43225a03 100644 --- a/app/Models/RecurringInvoiceInvitation.php +++ b/app/Models/RecurringInvoiceInvitation.php @@ -18,6 +18,8 @@ class RecurringInvoiceInvitation extends BaseModel { use MakesDates; + protected $touches = ['recurring_invoice']; + public function getEntityType() { return RecurringInvoiceInvitation::class; diff --git a/app/Models/RecurringQuote.php b/app/Models/RecurringQuote.php index 7d3fd0c873..eec9dc473c 100644 --- a/app/Models/RecurringQuote.php +++ b/app/Models/RecurringQuote.php @@ -81,6 +81,8 @@ class RecurringQuote extends BaseModel 'start_date', ]; + protected $touches = ['company']; + protected $casts = [ 'line_items' => 'object', 'backup' => 'object', diff --git a/app/Models/Task.php b/app/Models/Task.php index 8880c08c76..5974c24ad0 100644 --- a/app/Models/Task.php +++ b/app/Models/Task.php @@ -30,6 +30,8 @@ class Task extends BaseModel 'time_log', ]; + protected $touches = ['company']; + protected $casts = [ 'updated_at' => 'timestamp', 'created_at' => 'timestamp', @@ -40,6 +42,11 @@ class Task extends BaseModel return Task::class; } + public function company() + { + return $this->belongsTo(Company::class); + } + public function documents() { return $this->morphMany(Document::class, 'documentable'); diff --git a/app/Models/Vendor.php b/app/Models/Vendor.php index 289eae635c..5a208842d8 100644 --- a/app/Models/Vendor.php +++ b/app/Models/Vendor.php @@ -53,6 +53,8 @@ class Vendor extends BaseModel 'deleted_at' => 'timestamp', ]; + protected $touches = ['company']; + protected $with = [ // 'contacts', ]; diff --git a/app/Models/VendorContact.php b/app/Models/VendorContact.php index 952cbcc92e..09ff548259 100644 --- a/app/Models/VendorContact.php +++ b/app/Models/VendorContact.php @@ -37,6 +37,8 @@ class VendorContact extends Authenticatable implements HasLocalePreference /* Used to authenticate a vendor */ protected $guard = 'vendor'; + protected $touches = ['vendor']; + /* Allow microtime timestamps */ protected $dateFormat = 'Y-m-d H:i:s.u';