diff --git a/app/Http/Controllers/BaseController.php b/app/Http/Controllers/BaseController.php index 43e72c20051b..03a5eb4e07ff 100644 --- a/app/Http/Controllers/BaseController.php +++ b/app/Http/Controllers/BaseController.php @@ -140,6 +140,7 @@ class BaseController extends Controller 'company.quotes.invitations.company', 'company.quotes.documents', 'company.tasks.documents', + // 'company.tasks.project', 'company.subscriptions', 'company.tax_rates', 'company.tokens_hashed', @@ -458,7 +459,7 @@ class BaseController extends Controller } }, 'company.tasks' => function ($query) use ($updated_at, $user) { - $query->where('updated_at', '>=', $updated_at)->with('documents'); + $query->where('updated_at', '>=', $updated_at)->with('project','documents'); if (! $user->hasPermission('view_task')) { $query->whereNested(function ($query) use ($user) { diff --git a/app/Models/Project.php b/app/Models/Project.php index be9784d0a83a..ca00a95d8ddc 100644 --- a/app/Models/Project.php +++ b/app/Models/Project.php @@ -75,6 +75,10 @@ class Project extends BaseModel 'number', ]; + protected $with = [ + 'documents', + ]; + public function getEntityType() { return self::class; diff --git a/app/Models/Task.php b/app/Models/Task.php index 16903f6fff62..f1716b15a870 100644 --- a/app/Models/Task.php +++ b/app/Models/Task.php @@ -131,6 +131,10 @@ class Task extends BaseModel 'deleted_at' => 'timestamp', ]; + protected $with = [ + // 'project', + ]; + protected $touches = []; public function getEntityType() diff --git a/app/Services/Invoice/AutoBillInvoice.php b/app/Services/Invoice/AutoBillInvoice.php index 50ce340e88c4..b0d81c5c9af5 100644 --- a/app/Services/Invoice/AutoBillInvoice.php +++ b/app/Services/Invoice/AutoBillInvoice.php @@ -77,8 +77,6 @@ class AutoBillInvoice extends AbstractService return; } - nlog($this->invoice->toArray()); - $amount = 0; $invoice_total = 0; @@ -236,9 +234,7 @@ class AutoBillInvoice extends AbstractService //if we have paid the invoice in full using credits, then we need to fire the event if($this->invoice->balance == 0) { - event(new InvoiceWasPaid($this->invoice, $payment, $payment->company, Ninja::eventVars())); - } return $this->invoice @@ -267,8 +263,6 @@ class AutoBillInvoice extends AbstractService ->orderBy('created_at') ->get(); - nlog($unapplied_payments->pluck("id")); - $available_unapplied_balance = $unapplied_payments->sum('amount') - $unapplied_payments->sum('applied'); nlog("available unapplied balance = {$available_unapplied_balance}"); @@ -291,7 +285,10 @@ class AutoBillInvoice extends AbstractService if ($payment_balance > $this->invoice->partial) { $payload = ['client_id' => $this->invoice->client_id, 'invoices' => [['invoice_id' => $this->invoice->id,'amount' => $this->invoice->partial]]]; $payment_repo->save($payload, $payment); - break; + + $this->invoice = $this->invoice->fresh(); + + return $this; } else { $payload = ['client_id' => $this->invoice->client_id, 'invoices' => [['invoice_id' => $this->invoice->id,'amount' => $payment_balance]]]; $payment_repo->save($payload, $payment); @@ -303,7 +300,10 @@ class AutoBillInvoice extends AbstractService $payload = ['client_id' => $this->invoice->client_id, 'invoices' => [['invoice_id' => $this->invoice->id,'amount' => $this->invoice->balance]]]; $payment_repo->save($payload, $payment); - break; + $this->invoice = $this->invoice->fresh(); + + return $this; + } else { $payload = ['client_id' => $this->invoice->client_id, 'invoices' => [['invoice_id' => $this->invoice->id,'amount' => $payment_balance]]]; @@ -312,9 +312,8 @@ class AutoBillInvoice extends AbstractService } } - $this->invoice = $this->invoice->fresh(); - if((int)$this->invoice->balance == 0) { + event(new InvoiceWasPaid($this->invoice, $payment, $payment->company, Ninja::eventVars())); return $this; } } diff --git a/app/Transformers/CompanyTransformer.php b/app/Transformers/CompanyTransformer.php index e8941e1111a0..9b838f542fe5 100644 --- a/app/Transformers/CompanyTransformer.php +++ b/app/Transformers/CompanyTransformer.php @@ -205,7 +205,7 @@ class CompanyTransformer extends EntityTransformer 'invoice_task_item_description' => (bool) $company->invoice_task_item_description, 'origin_tax_data' => $company->origin_tax_data ?: new \stdClass(), 'smtp_host' => (string)$company->smtp_host ?? '', - 'smtp_port' => (string)$company->smtp_port ?? '', + 'smtp_port' => (int)$company->smtp_port ?? 25, 'smtp_encryption' => (string)$company->smtp_encryption ?? 'tls', 'smtp_username' => $company->smtp_username ? '********' : '', 'smtp_password' => $company->smtp_password ? '********' : '', diff --git a/app/Transformers/ProjectTransformer.php b/app/Transformers/ProjectTransformer.php index 729552b58e69..6f66dd23f15c 100644 --- a/app/Transformers/ProjectTransformer.php +++ b/app/Transformers/ProjectTransformer.php @@ -41,7 +41,10 @@ class ProjectTransformer extends EntityTransformer { $transformer = new DocumentTransformer($this->serializer); - return $this->includeCollection($project->documents, $transformer, Document::class); + if($project->documents) + return $this->includeCollection($project->documents, $transformer, Document::class); + + return null; } public function includeClient(Project $project): \League\Fractal\Resource\Item diff --git a/app/Transformers/TaskTransformer.php b/app/Transformers/TaskTransformer.php index 131789b32ff6..1bfcf64e9b51 100644 --- a/app/Transformers/TaskTransformer.php +++ b/app/Transformers/TaskTransformer.php @@ -100,11 +100,10 @@ class TaskTransformer extends EntityTransformer { $transformer = new ProjectTransformer($this->serializer); - if (!$task->project) { - return null; - } + if ($task->project) + return $this->includeItem($task->project, $transformer, Project::class); - return $this->includeItem($task->project, $transformer, Project::class); + return null; } public function transform(Task $task)