<commit_before><?php

namespace Coyote\Listeners;

use Carbon\Carbon;
use Coyote\Events\JobWasSaved;
use Coyote\Events\PaymentPaid;
use Coyote\Notifications\SuccessfulPaymentNotification;
use Coyote\Payment;
use Illuminate\Database\Connection;
use Illuminate\Contracts\Queue\ShouldQueue;
use Coyote\Services\Invoice\Enumerator as InvoiceEnumerator;
use Coyote\Services\Invoice\Pdf as InvoicePdf;

class BoostJobOffer implements ShouldQueue
{
    /**
     * @var InvoiceEnumerator
     */
    private $enumerator;

    /**
     * @var InvoicePdf
     */
    private $pdf;

    /**
     * @param InvoiceEnumerator $enumerator
     * @param InvoicePdf $pdf
     */
    public function __construct(InvoiceEnumerator $enumerator, InvoicePdf $pdf)
    {
        $this->enumerator = $enumerator;
        $this->pdf = $pdf;
    }

    /**
     * Handle the event.
     *
     * @param  PaymentPaid  $event
     * @return void
     */
    public function handle(PaymentPaid $event)
    {
        app(Connection::class)->transaction(function () use ($event) {
            $pdf = null;

            // set up invoice only if firm name was provided. it's required!
            if ($event->payment->invoice->name) {
                // set up invoice number since it's already paid.
                $this->enumerator->enumerate($event->payment->invoice);
                // create pdf
                $pdf = $this->pdf->create($event->payment);
            }

            $event->payment->status_id = Payment::PAID;

            // establish plan's finish date
            $event->payment->starts_at = Carbon::now();
            $event->payment->ends_at = Carbon::now()->addDays($event->payment->days);

            $event->payment->save();

            // boost job offer so it's on the top of the list
            $event->payment->job->boost = true;
            $event->payment->job->deadline_at = max($event->payment->job->deadline_at, $event->payment->ends_at);
            $event->payment->job->save();

            // payment is done. remove any pending payments (if any...)
            $event->payment->job->payments()->where('status_id', Payment::NEW)->delete();

            // reindex job offer
            event(new JobWasSaved($event->payment->job));

            // send email with invoice
            $event->user->notify(
                new SuccessfulPaymentNotification($event->payment, $pdf)
            );
        });
    }
}<commit_msg>ustawiamy date w momencie zaplaty<commit_after><?php

namespace Coyote\Listeners;

use Carbon\Carbon;
use Coyote\Events\JobWasSaved;
use Coyote\Events\PaymentPaid;
use Coyote\Notifications\SuccessfulPaymentNotification;
use Coyote\Payment;
use Illuminate\Database\Connection;
use Illuminate\Contracts\Queue\ShouldQueue;
use Coyote\Services\Invoice\Enumerator as InvoiceEnumerator;
use Coyote\Services\Invoice\Pdf as InvoicePdf;

class BoostJobOffer implements ShouldQueue
{
    /**
     * @var InvoiceEnumerator
     */
    private $enumerator;

    /**
     * @var InvoicePdf
     */
    private $pdf;

    /**
     * @param InvoiceEnumerator $enumerator
     * @param InvoicePdf $pdf
     */
    public function __construct(InvoiceEnumerator $enumerator, InvoicePdf $pdf)
    {
        $this->enumerator = $enumerator;
        $this->pdf = $pdf;
    }

    /**
     * Handle the event.
     *
     * @param  PaymentPaid  $event
     * @return void
     */
    public function handle(PaymentPaid $event)
    {
        app(Connection::class)->transaction(function () use ($event) {
            $pdf = null;

            // set up invoice only if firm name was provided. it's required!
            if ($event->payment->invoice->name) {
                // set up invoice number since it's already paid.
                $this->enumerator->enumerate($event->payment->invoice);
                // create pdf
                $pdf = $this->pdf->create($event->payment);
            }

            $event->payment->status_id = Payment::PAID;

            // establish plan's finish date
            $event->payment->starts_at = Carbon::now();
            $event->payment->ends_at = Carbon::now()->addDays($event->payment->days);

            $event->payment->save();

            // boost job offer so it's on the top of the list
            $event->payment->job->boost = true;
            $event->payment->job->boost_at = Carbon::now();
            $event->payment->job->deadline_at = max($event->payment->job->deadline_at, $event->payment->ends_at);
            $event->payment->job->save();

            // payment is done. remove any pending payments (if any...)
            $event->payment->job->payments()->where('status_id', Payment::NEW)->delete();

            // reindex job offer
            event(new JobWasSaved($event->payment->job));

            // send email with invoice
            $event->user->notify(
                new SuccessfulPaymentNotification($event->payment, $pdf)
            );
        });
    }
}
{'fraction_non_alphanumeric': 0.13436744560838035, 'fraction_numerical': 0.0, 'mean_word_length': 2.188824662813102, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 102, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2111974', 'n_tokens_mistral': 1448, 'n_tokens_neox': 1384, 'n_words': 302}