diff --git a/app/Jobs/Company/UpdateCompanyLedgerWithInvoice.php b/app/Jobs/Company/UpdateCompanyLedgerWithInvoice.php index ddec4f9ec974..75d096d21c74 100644 --- a/app/Jobs/Company/UpdateCompanyLedgerWithInvoice.php +++ b/app/Jobs/Company/UpdateCompanyLedgerWithInvoice.php @@ -56,6 +56,7 @@ class UpdateCompanyLedgerWithInvoice if($ledger) $balance = $ledger->balance; +\Log::error("adjusting balance {$balance}"); $company_ledger = CompanyLedgerFactory::create($this->invoice->company_id, $this->invoice->user_id); $company_ledger->client_id = $this->invoice->client_id; diff --git a/app/Jobs/Invoice/MarkInvoicePaid.php b/app/Jobs/Invoice/MarkInvoicePaid.php index fdf069549ab0..c24fbb40ab23 100644 --- a/app/Jobs/Invoice/MarkInvoicePaid.php +++ b/app/Jobs/Invoice/MarkInvoicePaid.php @@ -9,7 +9,7 @@ * @license https://opensource.org/licenses/AAL */ -namespace Jobs\Invoice; +namespace App\Jobs\Invoice; use App\Events\Payment\PaymentWasCreated; use App\Factory\PaymentFactory; @@ -23,7 +23,6 @@ use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; -use Illuminate\Support\Facades\Log; class MarkInvoicePaid implements ShouldQueue { @@ -68,6 +67,6 @@ class MarkInvoicePaid implements ShouldQueue UpdateCompanyLedgerWithPayment::dispatchNow($payment, $payment->amount); - return $invoice; + return $this->invoice; } } diff --git a/app/Listeners/Activity/PaymentCreatedActivity.php b/app/Listeners/Activity/PaymentCreatedActivity.php index c14a0fd9e046..cd6dc7d01821 100644 --- a/app/Listeners/Activity/PaymentCreatedActivity.php +++ b/app/Listeners/Activity/PaymentCreatedActivity.php @@ -42,8 +42,6 @@ class PaymentCreatedActivity implements ShouldQueue $payment = $event->payment; $invoices = $payment->invoices; - - \Log::error($invoices->count()); $fields = new \stdClass; diff --git a/app/PaymentDrivers/BasePaymentDriver.php b/app/PaymentDrivers/BasePaymentDriver.php index 662fb3f53b9f..4c95dc199fa5 100644 --- a/app/PaymentDrivers/BasePaymentDriver.php +++ b/app/PaymentDrivers/BasePaymentDriver.php @@ -252,14 +252,9 @@ class BasePaymentDriver ->whereClientId($this->client->id) ->get(); - \Log::error($hashed_ids); - \Log::error($invoices->count()); - $payment->invoices()->sync($invoices); $payment->save(); - \Log::error(print_r($payment,1)); - return $payment; } } \ No newline at end of file diff --git a/app/Repositories/InvoiceRepository.php b/app/Repositories/InvoiceRepository.php index 0ad98a8936d9..555c636e963a 100644 --- a/app/Repositories/InvoiceRepository.php +++ b/app/Repositories/InvoiceRepository.php @@ -108,6 +108,8 @@ class InvoiceRepository extends BaseRepository $this->markInvitationsSent(); $invoice->save(); +\Log::error("marking sent"); + UpdateCompanyLedgerWithInvoice::dispatchNow($this->invoice, $this->balance); return $invoice; diff --git a/database/seeds/RandomDataSeeder.php b/database/seeds/RandomDataSeeder.php index 4db888806d0c..df7fde5c2016 100644 --- a/database/seeds/RandomDataSeeder.php +++ b/database/seeds/RandomDataSeeder.php @@ -6,6 +6,7 @@ use App\DataMapper\DefaultSettings; use App\Events\Invoice\InvoiceWasMarkedSent; use App\Events\Invoice\InvoiceWasUpdated; use App\Helpers\Invoice\InvoiceCalc; +use App\Listeners\Invoice\CreateInvoiceInvitation; use App\Models\Account; use App\Models\Client; use App\Models\ClientContact; @@ -16,6 +17,7 @@ use App\Models\GroupSetting; use App\Models\Invoice; use App\Models\User; use App\Models\UserAccount; +use App\Repositories\InvoiceRepository; use Illuminate\Database\Seeder; use Illuminate\Support\Facades\Log; @@ -109,16 +111,21 @@ class RandomDataSeeder extends Seeder factory(\App\Models\Invoice::class,500)->create(['user_id' => $user->id, 'company_id' => $company->id, 'client_id' => $client->id, 'settings' => ClientSettings::buildClientSettings($company->settings, $client->settings)]); $invoices = Invoice::all(); + $invoice_repo = new InvoiceRepository(); - $invoices->each(function ($invoice){ + $invoices->each(function ($invoice) use($invoice_repo){ - $invoice_calc = new InvoiceCalc($invoice, $invoice->settings); + $invoice_calc = new InvoiceCalc($invoice, $invoice->settings); - $invoice = $invoice_calc->build()->getInvoice(); - - $invoice->save(); + $invoice = $invoice_calc->build()->getInvoice(); + + $invoice->save(); - event(new InvoiceWasMarkedSent($invoice)); + event(new CreateInvoiceInvitation($invoice)); + + $invoice_repo->markSent($invoice); + + event(new InvoiceWasMarkedSent($invoice)); }); /** Recurring Invoice Factory */