diff --git a/app/Http/Controllers/QuoteController.php b/app/Http/Controllers/QuoteController.php index ee18a597d046..9578c4ad962f 100644 --- a/app/Http/Controllers/QuoteController.php +++ b/app/Http/Controllers/QuoteController.php @@ -675,7 +675,7 @@ class QuoteController extends BaseController return $this->listResponse($quote); break; case 'email': - $this->quote->service()->sendEmail(); + $quote->service()->sendEmail(); return response()->json(['message'=>'email sent'], 200); break; case 'mark_sent': diff --git a/app/Jobs/Invoice/EmailInvoice.php b/app/Jobs/Invoice/EmailInvoice.php index b2bf3391c859..4d7ee0380059 100644 --- a/app/Jobs/Invoice/EmailInvoice.php +++ b/app/Jobs/Invoice/EmailInvoice.php @@ -94,12 +94,16 @@ class EmailInvoice extends BaseMailerJob implements ShouldQueue } if (count(Mail::failures()) > 0) { - return $this->logMailError(Mail::failures(), $this->invoice->client); + $this->logMailError(Mail::failures(), $this->invoice->client); } else{ event(new InvoiceWasEmailed($this->invoice_invitation, $this->company, Ninja::eventVars())); } + /* Mark invoice sent */ + $this->invoice_invitation->invoice->service()->markSent()->save(); + + } diff --git a/app/Jobs/Quote/EmailQuote.php b/app/Jobs/Quote/EmailQuote.php index ebbd5540c83e..58a1193e2ffd 100644 --- a/app/Jobs/Quote/EmailQuote.php +++ b/app/Jobs/Quote/EmailQuote.php @@ -59,6 +59,9 @@ class EmailQuote implements ShouldQueue if (count(Mail::failures()) > 0) { return $this->logMailError(Mail::failures()); } + + $this->quote_invitation->quote->markSent()->save(); + } private function logMailError($errors) diff --git a/app/Models/Credit.php b/app/Models/Credit.php index 70691cbd780b..40bc648246fb 100644 --- a/app/Models/Credit.php +++ b/app/Models/Credit.php @@ -122,6 +122,11 @@ class Credit extends BaseModel return $this->belongsTo(User::class, 'assigned_user_id', 'id'); } + public function history() + { + return $this->hasManyThrough(Backup::class, Activity::class); + } + public function company() { return $this->belongsTo(Company::class); diff --git a/app/Models/Quote.php b/app/Models/Quote.php index df0035c1bae5..f344d0f1607d 100644 --- a/app/Models/Quote.php +++ b/app/Models/Quote.php @@ -127,6 +127,11 @@ class Quote extends BaseModel return $this->belongsTo(Company::class); } + public function history() + { + return $this->hasManyThrough(Backup::class, Activity::class); + } + public function user() { return $this->belongsTo(User::class)->withTrashed(); diff --git a/app/Transformers/CreditTransformer.php b/app/Transformers/CreditTransformer.php index 1d18564364ab..f0fff6897f8c 100644 --- a/app/Transformers/CreditTransformer.php +++ b/app/Transformers/CreditTransformer.php @@ -11,11 +11,13 @@ namespace App\Transformers; +use App\Models\Backup; use App\Models\Credit; use App\Models\CreditInvitation; use App\Models\Document; use App\Transformers\CreditInvitationTransformer; use App\Transformers\DocumentTransformer; +use App\Transformers\InvoiceHistoryTransformer; use App\Utils\Traits\MakesHash; class CreditTransformer extends EntityTransformer @@ -25,15 +27,23 @@ class CreditTransformer extends EntityTransformer protected $defaultIncludes = [ 'invitations', 'documents', + 'history', ]; protected $availableIncludes = [ 'invitations', - // 'payments', + 'history', // 'client', 'documents', ]; + public function includeHistory(Credit $credit) + { + $transformer = new InvoiceHistoryTransformer($this->serializer); + + return $this->includeCollection($credit->history, $transformer, Backup::class); + } + public function includeInvitations(Credit $credit) { $transformer = new CreditInvitationTransformer($this->serializer); diff --git a/app/Transformers/InvoiceHistoryTransformer.php b/app/Transformers/InvoiceHistoryTransformer.php index 891fab4de0eb..76aefc1d028c 100644 --- a/app/Transformers/InvoiceHistoryTransformer.php +++ b/app/Transformers/InvoiceHistoryTransformer.php @@ -11,7 +11,9 @@ namespace App\Transformers; +use App\Models\Activity; use App\Models\Backup; +use App\Transformers\ActivityTransformer; use App\Utils\Traits\MakesHash; class InvoiceHistoryTransformer extends EntityTransformer @@ -19,9 +21,11 @@ class InvoiceHistoryTransformer extends EntityTransformer use MakesHash; protected $defaultIncludes = [ + 'activity' ]; protected $availableIncludes = [ + 'activity' ]; public function transform(Backup $backup) @@ -35,4 +39,11 @@ class InvoiceHistoryTransformer extends EntityTransformer 'updated_at' => (int)$backup->updated_at, ]; } + + public function includeActivity(Backup $backup) + { + $transformer = new ActivityTransformer($this->serializer); + + return $this->includeCollection($backup->activity, $transformer, Activity::class); + } } diff --git a/app/Transformers/QuoteTransformer.php b/app/Transformers/QuoteTransformer.php index 9720df11197c..b49b23aa86bc 100644 --- a/app/Transformers/QuoteTransformer.php +++ b/app/Transformers/QuoteTransformer.php @@ -11,10 +11,12 @@ namespace App\Transformers; +use App\Models\Backup; use App\Models\Document; use App\Models\Quote; use App\Models\QuoteInvitation; use App\Transformers\DocumentTransformer; +use App\Transformers\InvoiceHistoryTransformer; use App\Transformers\QuoteInvitationTransformer; use App\Utils\Traits\MakesHash; @@ -25,15 +27,24 @@ class QuoteTransformer extends EntityTransformer protected $defaultIncludes = [ 'invitations', 'documents', + 'history' ]; protected $availableIncludes = [ 'invitations', 'documents', + 'history' // 'payments', // 'client', ]; + public function includeHistory(Quote $quote) + { + $transformer = new InvoiceHistoryTransformer($this->serializer); + + return $this->includeCollection($quote->history, $transformer, Backup::class); + } + public function includeInvitations(Quote $quote) { $transformer = new QuoteInvitationTransformer($this->serializer); diff --git a/database/migrations/2020_08_13_212702_add_reminder_sent_fields_to_entity_tables.php b/database/migrations/2020_08_13_212702_add_reminder_sent_fields_to_entity_tables.php new file mode 100644 index 000000000000..8019e76efd53 --- /dev/null +++ b/database/migrations/2020_08_13_212702_add_reminder_sent_fields_to_entity_tables.php @@ -0,0 +1,52 @@ +unsignedInteger('quote_id')->nullable(); + }); + + Schema::table('quotes', function (Blueprint $table) { + $table->date('reminder1_sent')->nullable(); + $table->date('reminder2_sent')->nullable(); + $table->date('reminder3_sent')->nullable(); + $table->date('reminder_last_sent')->nullable(); + }); + + Schema::table('invoices', function (Blueprint $table) { + $table->date('reminder1_sent')->nullable(); + $table->date('reminder2_sent')->nullable(); + $table->date('reminder3_sent')->nullable(); + $table->date('reminder_last_sent')->nullable(); + }); + + Schema::table('credits', function (Blueprint $table) { + $table->date('reminder1_sent')->nullable(); + $table->date('reminder2_sent')->nullable(); + $table->date('reminder3_sent')->nullable(); + $table->date('reminder_last_sent')->nullable(); + }); + + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + + } +}