1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-05 18:52:44 +01:00

Merge pull request #4432 from turbo124/v5-develop

V5 develop
This commit is contained in:
David Bomba 2020-12-05 20:02:22 +11:00 committed by GitHub
commit 944a226977
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 644 additions and 361 deletions

View File

@ -1 +1 @@
5.0.31
5.0.32

View File

@ -146,7 +146,8 @@ class CreateEntityPdf implements ShouldQueue
->build();
//todo - move this to the client creation stage so we don't keep hitting this unnecessarily
// Storage::makeDirectory($path, 0775);
//info("make dir => {$path}");
//Storage::makeDirectory($path, 0775);
$pdf = null;

View File

@ -37,7 +37,9 @@ class UploadAvatar implements ShouldQueue
{
//make dir
Storage::makeDirectory($this->directory, 0775);
// info("avatar dir creation => ". $this->directory);
// Storage::makeDirectory($this->directory, 0775);
$tmp_file = sha1(time()).'.png';

View File

@ -84,7 +84,7 @@ class GenerateDeliveryNote
->design($template)
->build();
Storage::makeDirectory($this->invoice->client->invoice_filepath(), 0775);
// Storage::makeDirectory($this->invoice->client->invoice_filepath(), 0775);
$pdf = $this->makePdf(null, null, $maker->getCompiledHTML());

View File

@ -37,17 +37,23 @@ class HandleRestore extends AbstractService
foreach($this->invoice->payments as $payment)
{
//restore the payment record
$payment->restore();
//determine the paymentable amount before paymentable restoration
$pre_restore_amount = $payment->paymentables()
->where('paymentable_type', '=', 'invoices')
->sum(\DB::raw('amount'));
//restore the paymentables
$payment->paymentables()
->where('paymentable_type', '=', 'invoices')
->where('paymentable_id', $this->invoice->id)
->restore();
//determine the post restore paymentable amount (we need to increment the payment amount by the difference between pre and post)
$payment_amount = $payment->paymentables()
->where('paymentable_type', '=', 'invoices')
->where('paymentable_id', $this->invoice->id)
->sum(\DB::raw('amount'));
info($payment->amount . " == " . $payment_amount);
@ -57,22 +63,20 @@ class HandleRestore extends AbstractService
$payment->is_deleted = false;
$payment->save();
$this->payment_total += $payment_amount;
}
else {
$payment->is_deleted = false;
$payment->amount += $this->payment_total;
$payment->applied += $this->payment_total;
$payment->amount += ($payment_amount - $pre_restore_amount);
$payment->applied += ($payment_amount - $pre_restore_amount);
$payment->save();
$this->payment_total += ($payment_amount - $pre_restore_amount);
}
$this->payment_total += $payment_amount;
}
//adjust ledger balance
$this->invoice->ledger()->updateInvoiceBalance($this->invoice->balance, 'Restored invoice {$this->invoice->number}')->save();

View File

@ -77,7 +77,7 @@ class Phantom
$phantom_url = "https://phantomjscloud.com/api/browser/v2/{$key}/?request=%7Burl:%22{$url}%22,renderType:%22pdf%22%7D";
$pdf = CurlUtils::get($phantom_url);
Storage::makeDirectory($path, 0775);
// Storage::makeDirectory($path, 0775);
$instance = Storage::disk(config('filesystems.default'))->put($file_path, $pdf);

View File

@ -25,7 +25,7 @@
],
"type": "project",
"require": {
"php": ">=7.3",
"php": "^7.3|^7.4",
"ext-json": "*",
"asgrim/ofxparser": "^1.2",
"authorizenet/authorizenet": "^2.0",
@ -66,7 +66,6 @@
"require-dev": {
"anahkiasen/former": "^4.2",
"barryvdh/laravel-debugbar": "^3.4",
"brianium/paratest": "^5.0",
"darkaonline/l5-swagger": "^8.0",
"facade/ignition": "^2.3.6",
"filp/whoops": "^2.7",

626
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -60,7 +60,8 @@ return [
'public' => [
'driver' => 'local',
'root' => 'storage/',
'root' => public_path('storage'),
//'root' => 'storage/',
// 'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',

View File

@ -12,7 +12,7 @@ return [
'require_https' => env('REQUIRE_HTTPS', true),
'app_url' => rtrim(env('APP_URL', ''), '/').'/',
'app_domain' => env('APP_DOMAIN', ''),
'app_version' => '5.0.31',
'app_version' => '5.0.32',
'minimum_client_version' => '5.0.16',
'terms_version' => '1.0.1',
'api_secret' => env('API_SECRET', false),

View File

@ -0,0 +1,328 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace Tests\Feature;
use App\Factory\InvoiceItemFactory;
use App\Models\Client;
use App\Models\Invoice;
use App\Models\Payment;
use App\Utils\Traits\MakesHash;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Routing\Middleware\ThrottleRequests;
use Tests\MockAccountData;
use Tests\TestCase;
/**
* @test
*/
class DeleteInvoiceTest extends TestCase
{
use DatabaseTransactions;
use MockAccountData;
use MakesHash;
public function setUp() :void
{
parent::setUp();
$this->makeTestData();
$this->withoutMiddleware(
ThrottleRequests::class
);
}
/**
* @covers App\Services\Invoice\MarkInvoiceDeleted
*/
public function testInvoiceDeletion()
{
$data = [
'name' => 'A Nice Client',
];
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post('/api/v1/clients', $data);
$response->assertStatus(200);
$arr = $response->json();
$client_hash_id = $arr['data']['id'];
$client = Client::find($this->decodePrimaryKey($client_hash_id));
$this->assertEquals($client->balance, 0);
$this->assertEquals($client->paid_to_date, 0);
//create new invoice.
$line_items = [];
$item = InvoiceItemFactory::create();
$item->quantity = 1;
$item->cost = 10;
$line_items[] = (array)$item;
$item = InvoiceItemFactory::create();
$item->quantity = 1;
$item->cost = 10;
$line_items[] = (array)$item;
$invoice = [
'status_id' => 1,
'number' => '',
'discount' => 0,
'is_amount_discount' => 1,
'po_number' => '3434343',
'public_notes' => 'notes',
'is_deleted' => 0,
'custom_value1' => 0,
'custom_value2' => 0,
'custom_value3' => 0,
'custom_value4' => 0,
'client_id' => $client_hash_id,
'line_items' => (array)$line_items,
];
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post('/api/v1/invoices/', $invoice)
->assertStatus(200);
$arr = $response->json();
$invoice_one_hashed_id = $arr['data']['id'];
$invoice = Invoice::find($this->decodePrimaryKey($invoice_one_hashed_id));
$invoice = $invoice->service()->markSent()->save();
$this->assertEquals(20, $invoice->balance);
$this->assertEquals(20, $invoice->client->balance);
//delete invoice
$data = [
'ids' => [$invoice_one_hashed_id],
];
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post('/api/v1/invoices/bulk?action=delete', $data)->assertStatus(200);
$invoice = $invoice->fresh();
$this->assertEquals(20, $invoice->balance);
$this->assertEquals(0, $invoice->client->balance);
$this->assertTrue((bool)$invoice->is_deleted);
$this->assertNotNull($invoice->deleted_at);
//delete invoice
$data = [
'ids' => [$invoice_one_hashed_id],
];
//restore invoice
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post('/api/v1/invoices/bulk?action=restore', $data)->assertStatus(200);
$invoice = $invoice->fresh();
$this->assertEquals(20, $invoice->balance);
$this->assertFalse((bool)$invoice->is_deleted);
$this->assertNull($invoice->deleted_at);
$this->assertEquals(20, $invoice->client->fresh()->balance);
}
/**
* @covers App\Services\Invoice\HandleRestore
*/
public function testInvoiceDeletionAndRestoration()
{
//create new client
$data = [
'name' => 'A Nice Client',
];
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post('/api/v1/clients', $data);
$response->assertStatus(200);
$arr = $response->json();
$client_hash_id = $arr['data']['id'];
$client = Client::find($this->decodePrimaryKey($client_hash_id));
$this->assertEquals($client->balance, 0);
$this->assertEquals($client->paid_to_date, 0);
//create new invoice.
$line_items = [];
$item = InvoiceItemFactory::create();
$item->quantity = 1;
$item->cost = 10;
$line_items[] = (array)$item;
$item = InvoiceItemFactory::create();
$item->quantity = 1;
$item->cost = 10;
$line_items[] = (array)$item;
$invoice = [
'status_id' => 1,
'number' => '',
'discount' => 0,
'is_amount_discount' => 1,
'po_number' => '3434343',
'public_notes' => 'notes',
'is_deleted' => 0,
'custom_value1' => 0,
'custom_value2' => 0,
'custom_value3' => 0,
'custom_value4' => 0,
'client_id' => $client_hash_id,
'line_items' => (array)$line_items,
];
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post('/api/v1/invoices/', $invoice)
->assertStatus(200);
$arr = $response->json();
$invoice_one_hashed_id = $arr['data']['id'];
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post('/api/v1/invoices/', $invoice)
->assertStatus(200);
$arr = $response->json();
$invoice_two_hashed_id = $arr['data']['id'];
//mark as paid
$data = [
'amount' => 40.0,
'client_id' => $client_hash_id,
'invoices' => [
[
'invoice_id' => $invoice_one_hashed_id,
'amount' => 20.0,
],
[
'invoice_id' => $invoice_two_hashed_id,
'amount' => 20.0,
],
],
'date' => '2020/12/01',
];
$response = false;
try {
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post('/api/v1/payments?include=invoices', $data);
} catch (ValidationException $e) {
$message = json_decode($e->validator->getMessageBag(), 1);
}
$arr = $response->json();
$response->assertStatus(200);
$payment_hashed_id = $arr['data']['id'];
$invoice_one = Invoice::find($this->decodePrimaryKey($invoice_one_hashed_id));
$invoice_two = Invoice::find($this->decodePrimaryKey($invoice_two_hashed_id));
$payment = Payment::find($this->decodePrimaryKey($payment_hashed_id));
$this->assertEquals(20, $invoice_one->company_ledger->sortByDesc('id')->first()->balance);
//test balance
$this->assertEquals($invoice_one->amount, 20);
$this->assertEquals($invoice_one->balance, 0);
$this->assertEquals($invoice_two->amount, 20);
$this->assertEquals($invoice_two->balance, 0);
$this->assertEquals($client->fresh()->paid_to_date, 40);
$this->assertEquals($client->balance, 0);
//hydrate associated payment
$this->assertEquals($payment->amount, 40);
$this->assertEquals($payment->applied, 40);
//delete invoice
$data = [
'ids' => [$invoice_one_hashed_id],
];
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post('/api/v1/invoices/bulk?action=delete', $data);
$arr = $response->json();
$this->assertTrue($arr['data'][0]['is_deleted']);
$this->assertEquals(20, $client->fresh()->paid_to_date);
$this->assertEquals(0, $client->fresh()->balance);
$this->assertEquals(20, $payment->fresh()->applied);
$this->assertEquals(20, $payment->fresh()->amount);
$invoice_one = $invoice_one->fresh();
$this->assertTrue((bool)$invoice_one->is_deleted);
$this->assertNotNull($invoice_one->deleted_at);
//restore invoice
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post('/api/v1/invoices/bulk?action=restore', $data);
$arr = $response->json();
$this->assertFalse($arr['data'][0]['is_deleted']);
$invoice_one = $invoice_one->fresh();
$this->assertFalse((bool)$invoice_one->is_deleted);
$this->assertNull($invoice_one->deleted_at);
$payment = $payment->fresh();
$this->assertEquals(40, $payment->fresh()->applied);
$this->assertEquals(40, $payment->fresh()->amount);
$this->assertEquals(40, $client->fresh()->paid_to_date);
}
}

View File

@ -47,6 +47,7 @@ use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\Storage;
/**
* Class MockAccountData.
@ -157,6 +158,9 @@ trait MockAccountData
'account_id' => $this->account->id,
]);
Storage::makeDirectory($this->company->company_key.'/documents', 0755, true);
Storage::makeDirectory($this->company->company_key.'/images', 0755, true);
$settings = CompanySettings::defaults();
$settings->company_logo = 'https://www.invoiceninja.com/wp-content/uploads/2019/01/InvoiceNinja-Logo-Round-300x300.png';
@ -219,6 +223,10 @@ trait MockAccountData
'company_id' => $this->company->id,
]);
Storage::makeDirectory($this->company->company_key.'/'.$this->client->client_hash.'/invoices', 0755, true);
Storage::makeDirectory($this->company->company_key.'/'.$this->client->client_hash.'/credits', 0755, true);
Storage::makeDirectory($this->company->company_key.'/'.$this->client->client_hash.'/quotes', 0755, true);
$contact = ClientContact::factory()->create([
'user_id' => $this->user->id,
'client_id' => $this->client->id,