mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-11-03 22:47:32 -05:00 
			
		
		
		
	
						commit
						f36fa185dc
					
				@ -1 +1 @@
 | 
			
		||||
5.5.72
 | 
			
		||||
5.5.73
 | 
			
		||||
@ -615,7 +615,7 @@ class PaymentController extends BaseController
 | 
			
		||||
                }
 | 
			
		||||
                break;
 | 
			
		||||
            case 'email_receipt':
 | 
			
		||||
                $this->payment->service()->sendEmail();
 | 
			
		||||
                $payment->service()->sendEmail();
 | 
			
		||||
 | 
			
		||||
                if (! $bulk) {
 | 
			
		||||
                    return $this->itemResponse($payment);
 | 
			
		||||
 | 
			
		||||
@ -177,7 +177,7 @@ class PreviewController extends BaseController
 | 
			
		||||
 | 
			
		||||
    public function design(DesignPreviewRequest $request)
 | 
			
		||||
    {
 | 
			
		||||
        if (Ninja::isHosted() && $request->getHost() != 'preview.invoicing.co') {
 | 
			
		||||
        if (Ninja::isHosted() && in_array($request->getHost(),  ['preview.invoicing.co','staging.invoicing.co'])) {
 | 
			
		||||
            return response()->json(['message' => 'This server cannot handle this request.'], 400);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@ -340,7 +340,7 @@ class PreviewController extends BaseController
 | 
			
		||||
 | 
			
		||||
    public function live(PreviewInvoiceRequest $request)
 | 
			
		||||
    {
 | 
			
		||||
        if (Ninja::isHosted() && $request->getHost() != 'preview.invoicing.co') {
 | 
			
		||||
        if (Ninja::isHosted() && !in_array($request->getHost(),  ['preview.invoicing.co', 'staging.invoicing.co'])) {
 | 
			
		||||
            return response()->json(['message' => 'This server cannot handle this request.'], 400);
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
 | 
			
		||||
@ -22,6 +22,6 @@ class ShowSchedulerRequest extends Request
 | 
			
		||||
     */
 | 
			
		||||
    public function authorize() : bool
 | 
			
		||||
    {
 | 
			
		||||
        return auth()->user()->can('view', $this->scheduler);
 | 
			
		||||
        return auth()->user()->can('view', $this->task_scheduler);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -23,7 +23,7 @@ class UpdateSchedulerRequest extends Request
 | 
			
		||||
     */
 | 
			
		||||
    public function authorize(): bool
 | 
			
		||||
    {
 | 
			
		||||
        return auth()->user()->isAdmin();
 | 
			
		||||
        return auth()->user()->isAdmin() && $this->task_scheduler->company_id == auth()->user()->company()->id;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function rules(): array
 | 
			
		||||
 | 
			
		||||
@ -49,7 +49,7 @@ class EmailPayment implements ShouldQueue
 | 
			
		||||
     * @param $contact
 | 
			
		||||
     * @param $company
 | 
			
		||||
     */
 | 
			
		||||
    public function __construct(Payment $payment, Company $company, ClientContact $contact)
 | 
			
		||||
    public function __construct(Payment $payment, Company $company, ?ClientContact $contact)
 | 
			
		||||
    {
 | 
			
		||||
        $this->payment = $payment;
 | 
			
		||||
        $this->contact = $contact;
 | 
			
		||||
@ -60,7 +60,6 @@ class EmailPayment implements ShouldQueue
 | 
			
		||||
    /**
 | 
			
		||||
     * Execute the job.
 | 
			
		||||
     *
 | 
			
		||||
     *
 | 
			
		||||
     * @return void
 | 
			
		||||
     */
 | 
			
		||||
    public function handle()
 | 
			
		||||
@ -73,6 +72,10 @@ class EmailPayment implements ShouldQueue
 | 
			
		||||
            MultiDB::setDb($this->company->db);
 | 
			
		||||
 | 
			
		||||
            $this->payment->load('invoices');
 | 
			
		||||
 | 
			
		||||
            if(!$this->contact)
 | 
			
		||||
                $this->contact = $this->payment->client->contacts()->first();
 | 
			
		||||
                
 | 
			
		||||
            $this->contact->load('client');
 | 
			
		||||
 | 
			
		||||
            $email_builder = (new PaymentEmailEngine($this->payment, $this->contact))->build();
 | 
			
		||||
@ -90,7 +93,7 @@ class EmailPayment implements ShouldQueue
 | 
			
		||||
            $nmo->company = $this->company;
 | 
			
		||||
            $nmo->entity = $this->payment;
 | 
			
		||||
 | 
			
		||||
            NinjaMailerJob::dispatch($nmo);
 | 
			
		||||
            (new NinjaMailerJob($nmo))->handle();
 | 
			
		||||
 | 
			
		||||
            event(new PaymentWasEmailed($this->payment, $this->payment->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@ -99,7 +99,7 @@ class EmailRefundPayment implements ShouldQueue
 | 
			
		||||
            $nmo->company = $this->company;
 | 
			
		||||
            $nmo->entity = $this->payment;
 | 
			
		||||
 | 
			
		||||
            NinjaMailerJob::dispatch($nmo);
 | 
			
		||||
            (new NinjaMailerJob($nmo))->handle();
 | 
			
		||||
 | 
			
		||||
            event(new PaymentWasEmailed($this->payment, $this->payment->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@ -26,7 +26,7 @@ class UnlinkFile implements ShouldQueue
 | 
			
		||||
 | 
			
		||||
    protected $disk;
 | 
			
		||||
 | 
			
		||||
    public function __construct(string $disk, string $file_path)
 | 
			
		||||
    public function __construct(string $disk, ?string $file_path)
 | 
			
		||||
    {
 | 
			
		||||
        $this->file_path = $file_path;
 | 
			
		||||
        $this->disk = $disk;
 | 
			
		||||
@ -40,7 +40,7 @@ class UnlinkFile implements ShouldQueue
 | 
			
		||||
    public function handle()
 | 
			
		||||
    {
 | 
			
		||||
        /* Do not delete files if we are on the sync queue*/
 | 
			
		||||
        if (config('queue.default') == 'sync') {
 | 
			
		||||
        if (config('queue.default') == 'sync' || ! $this->file_path) {
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -389,6 +389,7 @@ class PaymentEmailEngine extends BaseEmailEngine
 | 
			
		||||
    private function buildViewButton(string $link, string $text): string
 | 
			
		||||
    {
 | 
			
		||||
        return '
 | 
			
		||||
<div>
 | 
			
		||||
<!--[if (gte mso 9)|(IE)]>
 | 
			
		||||
<table align="center" cellspacing="0" cellpadding="0" style="width: 600px;">
 | 
			
		||||
    <tr>
 | 
			
		||||
@ -409,6 +410,7 @@ class PaymentEmailEngine extends BaseEmailEngine
 | 
			
		||||
    </tr>
 | 
			
		||||
</table>
 | 
			
		||||
<![endif]-->
 | 
			
		||||
</div>
 | 
			
		||||
        ';
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -114,7 +114,7 @@ class ApplyPaymentAmount extends AbstractService
 | 
			
		||||
            $exchange_rate = new CurrencyApi();
 | 
			
		||||
 | 
			
		||||
            $payment->exchange_rate = $exchange_rate->exchangeRate($client_currency, $company_currency, Carbon::parse($payment->date));
 | 
			
		||||
            //$payment->exchange_currency_id = $client_currency; // 23/06/2021
 | 
			
		||||
 | 
			
		||||
            $payment->exchange_currency_id = $company_currency;
 | 
			
		||||
 | 
			
		||||
            $payment->saveQuietly();
 | 
			
		||||
 | 
			
		||||
@ -103,7 +103,6 @@ class InvoiceService
 | 
			
		||||
     * @param  Payment $payment        The Payment
 | 
			
		||||
     * @param  float   $payment_amount The Payment amount
 | 
			
		||||
     * @return InvoiceService          Parent class object
 | 
			
		||||
     * @deprecated 24-11-2022 - cannot find any references to this method anywhere
 | 
			
		||||
     */
 | 
			
		||||
    public function applyPayment(Payment $payment, float $payment_amount)
 | 
			
		||||
    {
 | 
			
		||||
 | 
			
		||||
@ -20,16 +20,8 @@ use App\Utils\Ninja;
 | 
			
		||||
 | 
			
		||||
class MarkSent extends AbstractService
 | 
			
		||||
{
 | 
			
		||||
    public $client;
 | 
			
		||||
 | 
			
		||||
    public $invoice;
 | 
			
		||||
 | 
			
		||||
    public function __construct(Client $client, Invoice $invoice)
 | 
			
		||||
    {
 | 
			
		||||
        $this->client = $client;
 | 
			
		||||
 | 
			
		||||
        $this->invoice = $invoice;
 | 
			
		||||
    }
 | 
			
		||||
    public function __construct(public Client $client, public Invoice $invoice)
 | 
			
		||||
    {}
 | 
			
		||||
 | 
			
		||||
    public function run($fire_webhook = false)
 | 
			
		||||
    {
 | 
			
		||||
 | 
			
		||||
@ -35,7 +35,7 @@ class LedgerService
 | 
			
		||||
 | 
			
		||||
        $this->entity->company_ledger()->save($company_ledger);
 | 
			
		||||
 | 
			
		||||
        ClientLedgerBalanceUpdate::dispatch($this->entity->company, $this->entity->client)->delay(now()->addSeconds(rand(30, 300)));
 | 
			
		||||
        ClientLedgerBalanceUpdate::dispatch($this->entity->company, $this->entity->client)->delay(rand(3, 13));
 | 
			
		||||
 | 
			
		||||
        return $this;
 | 
			
		||||
    }
 | 
			
		||||
@ -51,7 +51,7 @@ class LedgerService
 | 
			
		||||
 | 
			
		||||
        $this->entity->company_ledger()->save($company_ledger);
 | 
			
		||||
 | 
			
		||||
        ClientLedgerBalanceUpdate::dispatch($this->entity->company, $this->entity->client)->delay(now()->addSeconds(rand(30, 300)));
 | 
			
		||||
        ClientLedgerBalanceUpdate::dispatch($this->entity->company, $this->entity->client)->delay(rand(3, 13));
 | 
			
		||||
 | 
			
		||||
        return $this;
 | 
			
		||||
    }
 | 
			
		||||
@ -67,7 +67,7 @@ class LedgerService
 | 
			
		||||
 | 
			
		||||
        $this->entity->company_ledger()->save($company_ledger);
 | 
			
		||||
 | 
			
		||||
        ClientLedgerBalanceUpdate::dispatch($this->entity->company, $this->entity->client)->delay(now()->addSeconds(rand(30, 300)));
 | 
			
		||||
        ClientLedgerBalanceUpdate::dispatch($this->entity->company, $this->entity->client)->delay(rand(3, 13));
 | 
			
		||||
 | 
			
		||||
        return $this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -11,20 +11,15 @@
 | 
			
		||||
 | 
			
		||||
namespace App\Services\Payment;
 | 
			
		||||
 | 
			
		||||
use App\Models\Payment;
 | 
			
		||||
use App\Models\ClientContact;
 | 
			
		||||
use App\Jobs\Payment\EmailPayment;
 | 
			
		||||
 | 
			
		||||
class SendEmail
 | 
			
		||||
{
 | 
			
		||||
    public $payment;
 | 
			
		||||
 | 
			
		||||
    public $contact;
 | 
			
		||||
 | 
			
		||||
    public function __construct($payment, $contact)
 | 
			
		||||
    {
 | 
			
		||||
        $this->payment = $payment;
 | 
			
		||||
 | 
			
		||||
        $this->contact = $contact;
 | 
			
		||||
    }
 | 
			
		||||
    public function __construct(public Payment $payment, public ?ClientContact $contact)
 | 
			
		||||
    {}
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Builds the correct template to send.
 | 
			
		||||
@ -34,18 +29,16 @@ class SendEmail
 | 
			
		||||
    {
 | 
			
		||||
        $this->payment->load('company', 'client.contacts', 'invoices');
 | 
			
		||||
 | 
			
		||||
        $contact = $this->payment->client->contacts()->first();
 | 
			
		||||
        if(!$this->contact)
 | 
			
		||||
            $this->contact = $this->payment->client->contacts()->first();
 | 
			
		||||
 | 
			
		||||
        // if ($contact?->email)
 | 
			
		||||
        //     EmailPayment::dispatch($this->payment, $this->payment->company, $contact)->delay(now()->addSeconds(2));
 | 
			
		||||
        // $this->payment->invoices->sortByDesc('id')->first(function ($invoice) {
 | 
			
		||||
        //     $invoice->invitations->each(function ($invitation) {
 | 
			
		||||
        //         if (!$invitation->contact->trashed() && $invitation->contact->email) {
 | 
			
		||||
                    EmailPayment::dispatch($this->payment, $this->payment->company, $this->contact);
 | 
			
		||||
        //         }
 | 
			
		||||
        //     });
 | 
			
		||||
        // });
 | 
			
		||||
        
 | 
			
		||||
 | 
			
		||||
        $this->payment->invoices->sortByDesc('id')->first(function ($invoice) {
 | 
			
		||||
            $invoice->invitations->each(function ($invitation) {
 | 
			
		||||
                if (!$invitation->contact->trashed() && $invitation->contact->email) {
 | 
			
		||||
                    EmailPayment::dispatch($this->payment, $this->payment->company, $invitation->contact)->delay(now()->addSeconds(2));
 | 
			
		||||
                }
 | 
			
		||||
            });
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -979,6 +979,7 @@ html {
 | 
			
		||||
    private function buildViewButton(string $link, string $text): string
 | 
			
		||||
    {
 | 
			
		||||
        return '
 | 
			
		||||
<div>
 | 
			
		||||
<!--[if (gte mso 9)|(IE)]>
 | 
			
		||||
<table align="center" cellspacing="0" cellpadding="0" style="width: 600px;">
 | 
			
		||||
    <tr>
 | 
			
		||||
@ -999,6 +1000,7 @@ html {
 | 
			
		||||
    </tr>
 | 
			
		||||
</table>
 | 
			
		||||
<![endif]-->
 | 
			
		||||
</div>
 | 
			
		||||
        ';
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -22,9 +22,7 @@ trait Uploadable
 | 
			
		||||
{
 | 
			
		||||
    public function removeLogo($company)
 | 
			
		||||
    {
 | 
			
		||||
        //if (Storage::disk(config('filesystems.default'))->exists($company->settings->company_logo)) {
 | 
			
		||||
        (new UnlinkFile(config('filesystems.default'), $company->settings->company_logo))->handle();
 | 
			
		||||
        //}
 | 
			
		||||
        (new UnlinkFile(config('filesystems.default'), $company?->settings?->company_logo))->handle();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function uploadLogo($file, $company, $entity)
 | 
			
		||||
 | 
			
		||||
@ -808,6 +808,7 @@ html {
 | 
			
		||||
    private function buildViewButton(string $link, string $text): string
 | 
			
		||||
    {
 | 
			
		||||
        return '
 | 
			
		||||
<div>
 | 
			
		||||
<!--[if (gte mso 9)|(IE)]>
 | 
			
		||||
<table align="center" cellspacing="0" cellpadding="0" style="width: 600px;">
 | 
			
		||||
    <tr>
 | 
			
		||||
@ -828,10 +829,10 @@ html {
 | 
			
		||||
    </tr>
 | 
			
		||||
</table>
 | 
			
		||||
<![endif]-->
 | 
			
		||||
</div>
 | 
			
		||||
        ';
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        return '
 | 
			
		||||
            <table border="0" cellspacing="0" cellpadding="0" align="center">
 | 
			
		||||
                <tr style="border: 0 !important; ">
 | 
			
		||||
 | 
			
		||||
@ -14,8 +14,8 @@ return [
 | 
			
		||||
    'require_https' => env('REQUIRE_HTTPS', true),
 | 
			
		||||
    'app_url' => rtrim(env('APP_URL', ''), '/'),
 | 
			
		||||
    'app_domain' => env('APP_DOMAIN', 'invoicing.co'),
 | 
			
		||||
    'app_version' => '5.5.72',
 | 
			
		||||
    'app_tag' => '5.5.72',
 | 
			
		||||
    'app_version' => '5.5.73',
 | 
			
		||||
    'app_tag' => '5.5.73',
 | 
			
		||||
    'minimum_client_version' => '5.0.16',
 | 
			
		||||
    'terms_version' => '1.0.1',
 | 
			
		||||
    'api_secret' => env('API_SECRET', ''),
 | 
			
		||||
 | 
			
		||||
@ -230,8 +230,13 @@ class PaymentTest extends TestCase
 | 
			
		||||
 | 
			
		||||
    public function testStorePaymentWithClientId()
 | 
			
		||||
    {
 | 
			
		||||
        $client = ClientFactory::create($this->company->id, $this->user->id);
 | 
			
		||||
        $client->save();
 | 
			
		||||
        $client = Client::factory()->create(['company_id' =>$this->company->id, 'user_id' => $this->user->id]);
 | 
			
		||||
        ClientContact::factory()->create([
 | 
			
		||||
            'user_id' => $this->user->id,
 | 
			
		||||
            'client_id' => $client->id,
 | 
			
		||||
            'company_id' => $this->company->id,
 | 
			
		||||
            'is_primary' => 1,
 | 
			
		||||
        ]);
 | 
			
		||||
 | 
			
		||||
        $invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
 | 
			
		||||
        $invoice->client_id = $client->id;
 | 
			
		||||
@ -289,8 +294,14 @@ class PaymentTest extends TestCase
 | 
			
		||||
 | 
			
		||||
    public function testStorePaymentWithNoInvoiecs()
 | 
			
		||||
    {
 | 
			
		||||
        $client = ClientFactory::create($this->company->id, $this->user->id);
 | 
			
		||||
        $client->save();
 | 
			
		||||
        $client = Client::factory()->create(['company_id' =>$this->company->id, 'user_id' => $this->user->id]);
 | 
			
		||||
        ClientContact::factory()->create([
 | 
			
		||||
            'user_id' => $this->user->id,
 | 
			
		||||
            'client_id' => $client->id,
 | 
			
		||||
            'company_id' => $this->company->id,
 | 
			
		||||
            'is_primary' => 1,
 | 
			
		||||
        ]);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        $invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
 | 
			
		||||
        $invoice->client_id = $client->id;
 | 
			
		||||
@ -336,16 +347,15 @@ class PaymentTest extends TestCase
 | 
			
		||||
    {
 | 
			
		||||
        $invoice = null;
 | 
			
		||||
 | 
			
		||||
        $client = ClientFactory::create($this->company->id, $this->user->id);
 | 
			
		||||
        $client->save();
 | 
			
		||||
 | 
			
		||||
        $client = Client::factory()->create(['company_id' =>$this->company->id, 'user_id' => $this->user->id]);
 | 
			
		||||
        ClientContact::factory()->create([
 | 
			
		||||
            'user_id' => $this->user->id,
 | 
			
		||||
            'client_id' => $client->id,
 | 
			
		||||
            'company_id' =>$this->company->id,
 | 
			
		||||
            'is_primary' => true,
 | 
			
		||||
            'company_id' => $this->company->id,
 | 
			
		||||
            'is_primary' => 1,
 | 
			
		||||
        ]);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        $invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
 | 
			
		||||
        $invoice->client_id = $client->id;
 | 
			
		||||
 | 
			
		||||
@ -626,8 +636,14 @@ class PaymentTest extends TestCase
 | 
			
		||||
    {
 | 
			
		||||
        $invoice = null;
 | 
			
		||||
 | 
			
		||||
        $client = ClientFactory::create($this->company->id, $this->user->id);
 | 
			
		||||
        $client->save();
 | 
			
		||||
        $client = Client::factory()->create(['company_id' =>$this->company->id, 'user_id' => $this->user->id]);
 | 
			
		||||
        ClientContact::factory()->create([
 | 
			
		||||
            'user_id' => $this->user->id,
 | 
			
		||||
            'client_id' => $client->id,
 | 
			
		||||
            'company_id' => $this->company->id,
 | 
			
		||||
            'is_primary' => 1,
 | 
			
		||||
        ]);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        $invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
 | 
			
		||||
        $invoice->client_id = $client->id;
 | 
			
		||||
@ -686,8 +702,14 @@ class PaymentTest extends TestCase
 | 
			
		||||
    {
 | 
			
		||||
        $invoice = null;
 | 
			
		||||
 | 
			
		||||
        $client = ClientFactory::create($this->company->id, $this->user->id);
 | 
			
		||||
        $client->save();
 | 
			
		||||
        $client = Client::factory()->create(['company_id' =>$this->company->id, 'user_id' => $this->user->id]);
 | 
			
		||||
        ClientContact::factory()->create([
 | 
			
		||||
            'user_id' => $this->user->id,
 | 
			
		||||
            'client_id' => $client->id,
 | 
			
		||||
            'company_id' => $this->company->id,
 | 
			
		||||
            'is_primary' => 1,
 | 
			
		||||
        ]);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        $invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
 | 
			
		||||
        $invoice->client_id = $client->id;
 | 
			
		||||
@ -739,8 +761,13 @@ class PaymentTest extends TestCase
 | 
			
		||||
    {
 | 
			
		||||
        $invoice = null;
 | 
			
		||||
 | 
			
		||||
        $client = ClientFactory::create($this->company->id, $this->user->id);
 | 
			
		||||
        $client->save();
 | 
			
		||||
        $client = Client::factory()->create(['company_id' =>$this->company->id, 'user_id' => $this->user->id]);
 | 
			
		||||
        ClientContact::factory()->create([
 | 
			
		||||
            'user_id' => $this->user->id,
 | 
			
		||||
            'client_id' => $client->id,
 | 
			
		||||
            'company_id' => $this->company->id,
 | 
			
		||||
            'is_primary' => 1,
 | 
			
		||||
        ]);
 | 
			
		||||
 | 
			
		||||
        $invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
 | 
			
		||||
        $invoice->client_id = $client->id;
 | 
			
		||||
@ -799,8 +826,14 @@ class PaymentTest extends TestCase
 | 
			
		||||
    {
 | 
			
		||||
        $invoice = null;
 | 
			
		||||
 | 
			
		||||
        $client = ClientFactory::create($this->company->id, $this->user->id);
 | 
			
		||||
        $client->save();
 | 
			
		||||
        $client = Client::factory()->create(['company_id' =>$this->company->id, 'user_id' => $this->user->id]);
 | 
			
		||||
        ClientContact::factory()->create([
 | 
			
		||||
            'user_id' => $this->user->id,
 | 
			
		||||
            'client_id' => $client->id,
 | 
			
		||||
            'company_id' => $this->company->id,
 | 
			
		||||
            'is_primary' => 1,
 | 
			
		||||
        ]);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        $invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
 | 
			
		||||
        $invoice->client_id = $client->id;
 | 
			
		||||
@ -898,8 +931,13 @@ class PaymentTest extends TestCase
 | 
			
		||||
    {
 | 
			
		||||
        $invoice = null;
 | 
			
		||||
 | 
			
		||||
        $client = ClientFactory::create($this->company->id, $this->user->id);
 | 
			
		||||
        $client->save();
 | 
			
		||||
        $client = Client::factory()->create(['company_id' =>$this->company->id, 'user_id' => $this->user->id]);
 | 
			
		||||
        ClientContact::factory()->create([
 | 
			
		||||
            'user_id' => $this->user->id,
 | 
			
		||||
            'client_id' => $client->id,
 | 
			
		||||
            'company_id' => $this->company->id,
 | 
			
		||||
            'is_primary' => 1,
 | 
			
		||||
        ]);
 | 
			
		||||
 | 
			
		||||
        $invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
 | 
			
		||||
        $invoice->client_id = $client->id;
 | 
			
		||||
@ -944,59 +982,18 @@ class PaymentTest extends TestCase
 | 
			
		||||
        $this->assertEquals($payment->amount, 20);
 | 
			
		||||
        $this->assertEquals($payment->applied, 10);
 | 
			
		||||
 | 
			
		||||
        // $invoice = null;
 | 
			
		||||
        // $invoice = InvoiceFactory::create($this->company->id, $this->user->id);//stub the company and user_id
 | 
			
		||||
        // $invoice->client_id = $client->id;
 | 
			
		||||
 | 
			
		||||
        // $invoice->line_items = $this->buildLineItems();
 | 
			
		||||
        // $invoice->uses_inclusive_taxes = false;
 | 
			
		||||
 | 
			
		||||
        // $invoice->save();
 | 
			
		||||
 | 
			
		||||
        // $invoice_calc = new InvoiceSum($invoice);
 | 
			
		||||
        // $invoice_calc->build();
 | 
			
		||||
 | 
			
		||||
        // $invoice = $invoice_calc->getInvoice();
 | 
			
		||||
        // $invoice->save();
 | 
			
		||||
        // $invoice->service()->markSent()->createInvitations()->save();
 | 
			
		||||
 | 
			
		||||
        // $data = [
 | 
			
		||||
        //     'amount' => 20.0,
 | 
			
		||||
        //     'client_id' => $this->encodePrimaryKey($client->id),
 | 
			
		||||
        //     'invoices' => [
 | 
			
		||||
        //             [
 | 
			
		||||
        //                 'invoice_id' => $this->encodePrimaryKey($invoice->id),
 | 
			
		||||
        //                 'amount' => 10,
 | 
			
		||||
        //             ]
 | 
			
		||||
        //         ],
 | 
			
		||||
        //     'date' => '2019/12/12',
 | 
			
		||||
        // ];
 | 
			
		||||
 | 
			
		||||
        // $response = false;
 | 
			
		||||
 | 
			
		||||
        // try {
 | 
			
		||||
        //     $response = $this->withHeaders([
 | 
			
		||||
        //         'X-API-SECRET' => config('ninja.api_secret'),
 | 
			
		||||
        //         'X-API-TOKEN' => $this->token,
 | 
			
		||||
        //     ])->put('/api/v1/payments/'.$this->encodePrimaryKey($payment->id), $data);
 | 
			
		||||
        // } catch (ValidationException $e) {
 | 
			
		||||
        //     $message = json_decode($e->validator->getMessageBag(), 1);
 | 
			
		||||
        //     \Log::error(print_r($e->validator->getMessageBag(), 1));
 | 
			
		||||
 | 
			
		||||
        //     $this->assertTrue(array_key_exists('invoices', $message));
 | 
			
		||||
        // }
 | 
			
		||||
 | 
			
		||||
        // $response->assertStatus(200);
 | 
			
		||||
 | 
			
		||||
        // $arr = $response->json();
 | 
			
		||||
 | 
			
		||||
        // $this->assertEquals(20, $arr['data']['applied']);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testStorePaymentWithNoAmountField()
 | 
			
		||||
    {
 | 
			
		||||
        $client = ClientFactory::create($this->company->id, $this->user->id);
 | 
			
		||||
        $client->save();
 | 
			
		||||
        $client = Client::factory()->create(['company_id' =>$this->company->id, 'user_id' => $this->user->id]);
 | 
			
		||||
        ClientContact::factory()->create([
 | 
			
		||||
            'user_id' => $this->user->id,
 | 
			
		||||
            'client_id' => $client->id,
 | 
			
		||||
            'company_id' => $this->company->id,
 | 
			
		||||
            'is_primary' => 1,
 | 
			
		||||
        ]);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        $invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
 | 
			
		||||
        $invoice->client_id = $client->id;
 | 
			
		||||
@ -1055,8 +1052,13 @@ class PaymentTest extends TestCase
 | 
			
		||||
 | 
			
		||||
    public function testStorePaymentWithZeroAmountField()
 | 
			
		||||
    {
 | 
			
		||||
        $client = ClientFactory::create($this->company->id, $this->user->id);
 | 
			
		||||
        $client->save();
 | 
			
		||||
        $client = Client::factory()->create(['company_id' =>$this->company->id, 'user_id' => $this->user->id]);
 | 
			
		||||
        ClientContact::factory()->create([
 | 
			
		||||
            'user_id' => $this->user->id,
 | 
			
		||||
            'client_id' => $client->id,
 | 
			
		||||
            'company_id' => $this->company->id,
 | 
			
		||||
            'is_primary' => 1,
 | 
			
		||||
        ]);
 | 
			
		||||
 | 
			
		||||
        $invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
 | 
			
		||||
        $invoice->client_id = $client->id;
 | 
			
		||||
@ -1109,11 +1111,22 @@ class PaymentTest extends TestCase
 | 
			
		||||
 | 
			
		||||
    public function testPaymentForInvoicesFromDifferentClients()
 | 
			
		||||
    {
 | 
			
		||||
        $client1 = ClientFactory::create($this->company->id, $this->user->id);
 | 
			
		||||
        $client1->save();
 | 
			
		||||
        $client1 = Client::factory()->create(['company_id' =>$this->company->id, 'user_id' => $this->user->id]);
 | 
			
		||||
        ClientContact::factory()->create([
 | 
			
		||||
            'user_id' => $this->user->id,
 | 
			
		||||
            'client_id' => $client1->id,
 | 
			
		||||
            'company_id' => $this->company->id,
 | 
			
		||||
            'is_primary' => 1,
 | 
			
		||||
        ]);
 | 
			
		||||
 | 
			
		||||
        $client2 = ClientFactory::create($this->company->id, $this->user->id);
 | 
			
		||||
        $client2->save();
 | 
			
		||||
 | 
			
		||||
        $client2 = Client::factory()->create(['company_id' =>$this->company->id, 'user_id' => $this->user->id]);
 | 
			
		||||
        ClientContact::factory()->create([
 | 
			
		||||
            'user_id' => $this->user->id,
 | 
			
		||||
            'client_id' => $client2->id,
 | 
			
		||||
            'company_id' => $this->company->id,
 | 
			
		||||
            'is_primary' => 1,
 | 
			
		||||
        ]);
 | 
			
		||||
 | 
			
		||||
        $invoice1 = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
 | 
			
		||||
        $invoice1->client_id = $client1->id;
 | 
			
		||||
@ -1175,8 +1188,13 @@ class PaymentTest extends TestCase
 | 
			
		||||
 | 
			
		||||
    public function testPaymentWithSameInvoiceMultipleTimes()
 | 
			
		||||
    {
 | 
			
		||||
        $client1 = ClientFactory::create($this->company->id, $this->user->id);
 | 
			
		||||
        $client1->save();
 | 
			
		||||
        $client1 = Client::factory()->create(['company_id' =>$this->company->id, 'user_id' => $this->user->id]);
 | 
			
		||||
        ClientContact::factory()->create([
 | 
			
		||||
            'user_id' => $this->user->id,
 | 
			
		||||
            'client_id' => $client1->id,
 | 
			
		||||
            'company_id' => $this->company->id,
 | 
			
		||||
            'is_primary' => 1,
 | 
			
		||||
        ]);
 | 
			
		||||
 | 
			
		||||
        $invoice1 = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
 | 
			
		||||
        $invoice1->client_id = $client1->id;
 | 
			
		||||
@ -1227,8 +1245,13 @@ class PaymentTest extends TestCase
 | 
			
		||||
 | 
			
		||||
    public function testStorePaymentWithCredits()
 | 
			
		||||
    {
 | 
			
		||||
        $client = ClientFactory::create($this->company->id, $this->user->id);
 | 
			
		||||
        $client->save();
 | 
			
		||||
        $client = Client::factory()->create(['company_id' =>$this->company->id, 'user_id' => $this->user->id]);
 | 
			
		||||
        ClientContact::factory()->create([
 | 
			
		||||
            'user_id' => $this->user->id,
 | 
			
		||||
            'client_id' => $client->id,
 | 
			
		||||
            'company_id' => $this->company->id,
 | 
			
		||||
            'is_primary' => 1,
 | 
			
		||||
        ]);
 | 
			
		||||
 | 
			
		||||
        $invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
 | 
			
		||||
        $invoice->client_id = $client->id;
 | 
			
		||||
@ -1310,7 +1333,14 @@ class PaymentTest extends TestCase
 | 
			
		||||
        $settings = ClientSettings::defaults();
 | 
			
		||||
        $settings->currency_id = '2';
 | 
			
		||||
 | 
			
		||||
        $client = ClientFactory::create($this->company->id, $this->user->id);
 | 
			
		||||
        $client = Client::factory()->create(['company_id' =>$this->company->id, 'user_id' => $this->user->id]);
 | 
			
		||||
        ClientContact::factory()->create([
 | 
			
		||||
            'user_id' => $this->user->id,
 | 
			
		||||
            'client_id' => $client->id,
 | 
			
		||||
            'company_id' => $this->company->id,
 | 
			
		||||
            'is_primary' => 1,
 | 
			
		||||
        ]);
 | 
			
		||||
 | 
			
		||||
        $client->settings = $settings;
 | 
			
		||||
        $client->save();
 | 
			
		||||
 | 
			
		||||
@ -1374,8 +1404,14 @@ class PaymentTest extends TestCase
 | 
			
		||||
    {
 | 
			
		||||
        $invoice = null;
 | 
			
		||||
 | 
			
		||||
        $client = ClientFactory::create($this->company->id, $this->user->id);
 | 
			
		||||
        $client->save();
 | 
			
		||||
        $client = Client::factory()->create(['company_id' =>$this->company->id, 'user_id' => $this->user->id]);
 | 
			
		||||
        ClientContact::factory()->create([
 | 
			
		||||
            'user_id' => $this->user->id,
 | 
			
		||||
            'client_id' => $client->id,
 | 
			
		||||
            'company_id' => $this->company->id,
 | 
			
		||||
            'is_primary' => 1,
 | 
			
		||||
        ]);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        $invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
 | 
			
		||||
        $invoice->client_id = $client->id;
 | 
			
		||||
@ -1453,8 +1489,14 @@ class PaymentTest extends TestCase
 | 
			
		||||
    {
 | 
			
		||||
        $invoice = null;
 | 
			
		||||
 | 
			
		||||
        $client = ClientFactory::create($this->company->id, $this->user->id);
 | 
			
		||||
        $client->save();
 | 
			
		||||
        $client = Client::factory()->create(['company_id' =>$this->company->id, 'user_id' => $this->user->id]);
 | 
			
		||||
        ClientContact::factory()->create([
 | 
			
		||||
            'user_id' => $this->user->id,
 | 
			
		||||
            'client_id' => $client->id,
 | 
			
		||||
            'company_id' => $this->company->id,
 | 
			
		||||
            'is_primary' => 1,
 | 
			
		||||
        ]);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        $invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
 | 
			
		||||
        $invoice->client_id = $client->id;
 | 
			
		||||
 | 
			
		||||
@ -54,6 +54,22 @@ class SchedulerTest extends TestCase
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    public function testSchedulerGet2()
 | 
			
		||||
    {
 | 
			
		||||
        
 | 
			
		||||
        $scheduler = SchedulerFactory::create($this->company->id, $this->user->id);
 | 
			
		||||
 | 
			
		||||
        $response = $this->withHeaders([
 | 
			
		||||
            'X-API-SECRET' => config('ninja.api_secret'),
 | 
			
		||||
            'X-API-TOKEN' => $this->token,
 | 
			
		||||
        ])->get('/api/v1/task_schedulers/'.$this->encodePrimaryKey($scheduler->id));
 | 
			
		||||
 | 
			
		||||
        $response->assertStatus(200);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    public function testCustomDateRanges()
 | 
			
		||||
    {
 | 
			
		||||
        $data = [
 | 
			
		||||
@ -619,21 +635,6 @@ class SchedulerTest extends TestCase
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    // public function testSchedulerPut()
 | 
			
		||||
    // {
 | 
			
		||||
    //     $data = [
 | 
			
		||||
    //         'description' => $this->faker->firstName(),
 | 
			
		||||
    //     ];
 | 
			
		||||
 | 
			
		||||
    //     $response = $this->withHeaders([
 | 
			
		||||
    //         'X-API-SECRET' => config('ninja.api_secret'),
 | 
			
		||||
    //         'X-API-TOKEN' => $this->token,
 | 
			
		||||
    //     ])->put('/api/v1/task_schedulers/'.$this->encodePrimaryKey($this->task->id), $data);
 | 
			
		||||
 | 
			
		||||
    //     $response->assertStatus(200);
 | 
			
		||||
    // }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    // public function testSchedulerCantBeCreatedWithWrongData()
 | 
			
		||||
    // {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user