From d123840bfac3a8b29d651c6c560594a9f3f6f1e7 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 29 Oct 2020 10:11:52 +1100 Subject: [PATCH 1/8] Fix for fillable fields --- app/Models/Company.php | 2 ++ app/Models/Task.php | 1 + 2 files changed, 3 insertions(+) diff --git a/app/Models/Company.php b/app/Models/Company.php index c815e7cdcaa7..7295fcc4666b 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -74,6 +74,8 @@ class Company extends BaseModel protected $presenter = CompanyPresenter::class; protected $fillable = [ + 'invoice_expense_documents', + 'invoice_task_documents', 'show_tasks_table', 'mark_expenses_invoiceable', 'mark_expenses_paid', diff --git a/app/Models/Task.php b/app/Models/Task.php index 373ae4f548f3..fcb91bad739b 100644 --- a/app/Models/Task.php +++ b/app/Models/Task.php @@ -37,6 +37,7 @@ class Task extends BaseModel 'status_id', 'status_sort_order', 'invoice_documents', + 'rate', ]; protected $touches = []; From 1bda0190bb1b815c22d565f59a73cd62b9e0a18f Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 29 Oct 2020 10:14:09 +1100 Subject: [PATCH 2/8] fixes for company transformer --- app/Transformers/CompanyTransformer.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Transformers/CompanyTransformer.php b/app/Transformers/CompanyTransformer.php index 258b4dac9e36..20c35e05621b 100644 --- a/app/Transformers/CompanyTransformer.php +++ b/app/Transformers/CompanyTransformer.php @@ -155,6 +155,7 @@ class CompanyTransformer extends EntityTransformer 'invoice_task_timelog' => (bool) $company->invoice_task_timelog, 'auto_start_tasks' => (bool) $company->auto_start_tasks, 'invoice_task_documents' => (bool) $company->invoice_task_documents, + 'show_tasks_table' => (bool) $company->show_tasks_table, 'use_credits_payment' => 'always', //todo remove ]; } From 85eb1a990a25faa8fa76c6a843d8768900570574 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 29 Oct 2020 11:09:51 +1100 Subject: [PATCH 3/8] Fixes for non sticking fields in project --- app/Http/Requests/Project/StoreProjectRequest.php | 2 +- app/Http/Requests/Project/UpdateProjectRequest.php | 4 +++- app/Models/Project.php | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/Http/Requests/Project/StoreProjectRequest.php b/app/Http/Requests/Project/StoreProjectRequest.php index a1c3d0bcf570..7b9c41990ef6 100644 --- a/app/Http/Requests/Project/StoreProjectRequest.php +++ b/app/Http/Requests/Project/StoreProjectRequest.php @@ -37,7 +37,7 @@ class StoreProjectRequest extends Request $rules['name'] = 'required'; $rules['client_id'] = 'required|exists:clients,id,company_id,'.auth()->user()->company()->id; - return $rules; + return $this->globalRules($rules); } protected function prepareForValidation() diff --git a/app/Http/Requests/Project/UpdateProjectRequest.php b/app/Http/Requests/Project/UpdateProjectRequest.php index 3c4c3892f1ad..7a8dd7e04543 100644 --- a/app/Http/Requests/Project/UpdateProjectRequest.php +++ b/app/Http/Requests/Project/UpdateProjectRequest.php @@ -31,7 +31,9 @@ class UpdateProjectRequest extends Request public function rules() { - return []; + $rules = []; + + return $this->globalRules($rules); } protected function prepareForValidation() diff --git a/app/Models/Project.php b/app/Models/Project.php index 19fda5261909..4ca4eeade66c 100644 --- a/app/Models/Project.php +++ b/app/Models/Project.php @@ -37,6 +37,7 @@ class Project extends BaseModel 'custom_value2', 'custom_value3', 'custom_value4', + 'assigned_user_id', ]; public function getEntityType() From dbcfce8bb9d95e6ca2a7dfa6498088808c2c78af Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 29 Oct 2020 11:17:10 +1100 Subject: [PATCH 4/8] Fixes for missing fields in transformers / fillable for vendors and expenses --- app/Models/Vendor.php | 2 +- app/Transformers/ExpenseTransformer.php | 4 +-- ...2020_10_29_001541_vendors_phone_column.php | 30 +++++++++++++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 database/migrations/2020_10_29_001541_vendors_phone_column.php diff --git a/app/Models/Vendor.php b/app/Models/Vendor.php index 87e1a206319f..8fe542e71ab8 100644 --- a/app/Models/Vendor.php +++ b/app/Models/Vendor.php @@ -32,7 +32,7 @@ class Vendor extends BaseModel 'assigned_user_id', 'id_number', 'vat_number', - 'work_phone', + 'phone', 'address1', 'address2', 'city', diff --git a/app/Transformers/ExpenseTransformer.php b/app/Transformers/ExpenseTransformer.php index e3278bd2b8ca..3dba3db520a9 100644 --- a/app/Transformers/ExpenseTransformer.php +++ b/app/Transformers/ExpenseTransformer.php @@ -78,8 +78,8 @@ class ExpenseTransformer extends EntityTransformer 'public_notes' => (string) $expense->public_notes ?: '', 'transaction_reference' => (string) $expense->transaction_reference ?: '', 'transaction_id' => (string) $expense->transaction_id ?: '', - //'date' => $expense->date ?: '', - 'expense_date' => $expense->date ?: '', + 'date' => $expense->date ?: '', + //'expense_date' => $expense->date ?: '', 'number' => (string)$expense->number ?: '', 'payment_date' => $expense->payment_date ?: '', 'custom_value1' => $expense->custom_value1 ?: '', diff --git a/database/migrations/2020_10_29_001541_vendors_phone_column.php b/database/migrations/2020_10_29_001541_vendors_phone_column.php new file mode 100644 index 000000000000..f1cec4e9a616 --- /dev/null +++ b/database/migrations/2020_10_29_001541_vendors_phone_column.php @@ -0,0 +1,30 @@ +renameColumn('work_phone', 'phone'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + // + } +} From 73802c364749276c5c2940ed646dcd70693038eb Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 29 Oct 2020 13:24:12 +1100 Subject: [PATCH 5/8] Task duration / start time helpers --- app/Models/Task.php | 66 +++++++++++++++++++++++++++++ app/Repositories/TaskRepository.php | 5 +++ 2 files changed, 71 insertions(+) diff --git a/app/Models/Task.php b/app/Models/Task.php index fcb91bad739b..204e4bb6cd3e 100644 --- a/app/Models/Task.php +++ b/app/Models/Task.php @@ -15,6 +15,7 @@ use App\Models\Filterable; use App\Utils\Traits\MakesHash; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; +use Illuminate\Support\Carbon; class Task extends BaseModel { @@ -81,4 +82,69 @@ class Task extends BaseModel { return $this->belongsTo(Project::class); } + + + + + + + + + + + public static function calcstart_time() + { + $parts = json_decode($this->time_log) ?: []; + + if (count($parts)) { + return Carbon::createFromTimeStamp($parts[0][0]); + } else { + return ''; + } + } + + public function getLaststart_time() + { + $parts = json_decode($this->time_log) ?: []; + + if (count($parts)) { + $index = count($parts) - 1; + + return $parts[$index][0]; + } else { + return ''; + } + + } + + public static function calcDuration($start_time_cutoff = 0, $end_time_cutoff = 0) + { + $duration = 0; + $parts = json_decode($this->time_log) ?: []; + + foreach ($parts as $part) { + $start_time = $part[0]; + if (count($part) == 1 || ! $part[1]) { + $end_time = time(); + } else { + $end_time = $part[1]; + } + + if ($start_time_cutoff) { + $start_time = max($start_time, $start_time_cutoff); + } + if ($end_time_cutoff) { + $end_time = min($end_time, $end_time_cutoff); + } + + $duration += max($end_time - $start_time, 0); + } + + return round($duration); + } + + + + + } diff --git a/app/Repositories/TaskRepository.php b/app/Repositories/TaskRepository.php index d55d3495459d..cf3ea2df3802 100644 --- a/app/Repositories/TaskRepository.php +++ b/app/Repositories/TaskRepository.php @@ -50,6 +50,11 @@ class TaskRepository extends BaseRepository { $task->fill($data); + + if(!$task->start_time) + $task->start_time = $task->calcStartTime(); + + $task->duration = $task->calcDuration(); $task->save(); if (array_key_exists('documents', $data)) { From e891238db0f0b5a6f720ccbfc07c0948bc2d2fb8 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 29 Oct 2020 13:55:26 +1100 Subject: [PATCH 6/8] Set next_send_date to null when balance == 0 --- app/Services/Invoice/InvoiceService.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/Services/Invoice/InvoiceService.php b/app/Services/Invoice/InvoiceService.php index 4ec63141df4c..da1393e21409 100644 --- a/app/Services/Invoice/InvoiceService.php +++ b/app/Services/Invoice/InvoiceService.php @@ -113,6 +113,9 @@ class InvoiceService { $this->invoice = (new UpdateBalance($this->invoice, $balance_adjustment))->run(); + if((int)$this->invoice->balance == 0) + $this->invoice->next_send_date = null; + return $this; } From bc688985e1f1f6c0ecf91023487ce4d8e75fa97b Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 29 Oct 2020 14:34:29 +1100 Subject: [PATCH 7/8] Set next_send_date to null when balance == 0 --- app/Models/Task.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Models/Task.php b/app/Models/Task.php index 204e4bb6cd3e..11f32f6a23a8 100644 --- a/app/Models/Task.php +++ b/app/Models/Task.php @@ -92,7 +92,7 @@ class Task extends BaseModel - public static function calcstart_time() + public function calcStartTime() { $parts = json_decode($this->time_log) ?: []; @@ -103,7 +103,7 @@ class Task extends BaseModel } } - public function getLaststart_time() + public function getLastStartTime() { $parts = json_decode($this->time_log) ?: []; @@ -117,7 +117,7 @@ class Task extends BaseModel } - public static function calcDuration($start_time_cutoff = 0, $end_time_cutoff = 0) + public function calcDuration($start_time_cutoff = 0, $end_time_cutoff = 0) { $duration = 0; $parts = json_decode($this->time_log) ?: []; From c21ad042ce0312bb6a2761cee28c63117c2e5b61 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 29 Oct 2020 15:47:44 +1100 Subject: [PATCH 8/8] fixes for payment notifications --- app/Jobs/Mail/EntityPaidMailer.php | 29 ++++++++++++------- app/Listeners/Payment/PaymentNotification.php | 6 +--- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/app/Jobs/Mail/EntityPaidMailer.php b/app/Jobs/Mail/EntityPaidMailer.php index f476f1ec6120..ffb5f525d838 100644 --- a/app/Jobs/Mail/EntityPaidMailer.php +++ b/app/Jobs/Mail/EntityPaidMailer.php @@ -53,11 +53,11 @@ class EntityPaidMailer extends BaseMailerJob implements ShouldQueue * @param $user * @param $company */ - public function __construct($payment, $user, $company) + public function __construct($payment, $company) { $this->company = $company; - $this->user = $user; + $this->user = $payment->user; $this->payment = $payment; @@ -82,16 +82,25 @@ class EntityPaidMailer extends BaseMailerJob implements ShouldQueue //if we need to set an email driver do it now $this->setMailDriver(); - $mail_obj = (new EntityPaidObject($this->payment))->build(); - $mail_obj->from = [$this->payment->user->email, $this->payment->user->present()->name()]; + try { - //send email - Mail::to($this->user->email) - ->send(new EntityNotificationMailer($mail_obj)); + $mail_obj = (new EntityPaidObject($this->payment))->build(); + $mail_obj->from = [$this->payment->user->email, $this->payment->user->present()->name()]; - //catch errors - if (count(Mail::failures()) > 0) { - return $this->logMailError(Mail::failures(), $this->payment->client); + //send email + Mail::to($this->user->email) + ->send(new EntityNotificationMailer($mail_obj)); + + } catch (Swift_TransportException $e) { + $this->failed($e->getMessage()); + //$this->entityEmailFailed($e->getMessage()); } + + if (count(Mail::failures()) > 0) { + $this->logMailError(Mail::failures(), $this->entity->client); + } else { + // $this->entityEmailSucceeded(); + } + } } diff --git a/app/Listeners/Payment/PaymentNotification.php b/app/Listeners/Payment/PaymentNotification.php index d5cedad39aae..8bf809f35f71 100644 --- a/app/Listeners/Payment/PaymentNotification.php +++ b/app/Listeners/Payment/PaymentNotification.php @@ -62,11 +62,8 @@ class PaymentNotification implements ShouldQueue if (($key = array_search('mail', $methods)) !== false) { unset($methods[$key]); - //Fire mail notification here!!! - //This allows us better control of how we - //handle the mailer + EntityPaidMailer::dispatch($payment, $payment->company); - EntityPaidMailer::dispatch($payment, $user, $payment->company); } $notification = new NewPaymentNotification($payment, $payment->company); @@ -84,7 +81,6 @@ class PaymentNotification implements ShouldQueue } /*Google Analytics Track Revenue*/ - if (isset($payment->company->google_analytics_key)) { $this->trackRevenue($event); }