mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-18 16:22:14 +00:00
backend refactored
This commit is contained in:
@@ -5,7 +5,7 @@ APP_DEBUG=true
|
|||||||
APP_URL=http://localhost
|
APP_URL=http://localhost
|
||||||
APP_DEMO=false
|
APP_DEMO=false
|
||||||
|
|
||||||
LOG_CHANNEL=stack
|
LOG_CHANNEL=daily
|
||||||
|
|
||||||
DB_CONNECTION=sqlite
|
DB_CONNECTION=sqlite
|
||||||
DB_HOST=null
|
DB_HOST=null
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ use App\Models\Oasis\Invoice;
|
|||||||
use App\Notifications\Oasis\InvoiceDeliveryNotification;
|
use App\Notifications\Oasis\InvoiceDeliveryNotification;
|
||||||
use App\Notifications\SharedSendViaEmail;
|
use App\Notifications\SharedSendViaEmail;
|
||||||
use Auth;
|
use Auth;
|
||||||
|
use Illuminate\Contracts\Auth\Authenticatable;
|
||||||
use Illuminate\Contracts\Foundation\Application;
|
use Illuminate\Contracts\Foundation\Application;
|
||||||
use Illuminate\Contracts\Routing\ResponseFactory;
|
use Illuminate\Contracts\Routing\ResponseFactory;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
@@ -57,43 +58,18 @@ class InvoiceController extends Controller
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Store and generate new invoice
|
||||||
|
*
|
||||||
* @param StoreInvoiceRequest $request
|
* @param StoreInvoiceRequest $request
|
||||||
* @return Application|ResponseFactory|Response
|
* @return Application|ResponseFactory|Response
|
||||||
*/
|
*/
|
||||||
public function store(StoreInvoiceRequest $request)
|
public function store(StoreInvoiceRequest $request)
|
||||||
{
|
{
|
||||||
$user = Auth::user();
|
$client = $this->getOrStoreClient($request);
|
||||||
|
|
||||||
// Store client
|
|
||||||
if (! Str::isUuid($request->client) && $request->store_client) {
|
|
||||||
|
|
||||||
$client = $user->clients()->create([
|
|
||||||
'name' => $request->client_name,
|
|
||||||
'address' => $request->client_address,
|
|
||||||
'city' => $request->client_city,
|
|
||||||
'postal_code' => $request->client_postal_code,
|
|
||||||
'country' => $request->client_country,
|
|
||||||
'ico' => $request->client_ico,
|
|
||||||
|
|
||||||
'avatar' => store_avatar($request, 'client_avatar') ?? null,
|
|
||||||
'email' => $request->client_email ?? null,
|
|
||||||
'phone_number' => $request->client_phone_number ?? null,
|
|
||||||
'dic' => $request->client_dic ?? null,
|
|
||||||
'ic_dph' => $request->client_ic_dph ?? null,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get client
|
|
||||||
if (Str::isUuid($request->client)) {
|
|
||||||
|
|
||||||
$client = Client::whereUserIdAndId($user->id, $request->client)->first();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Store invoice
|
|
||||||
$invoice = Invoice::create([
|
$invoice = Invoice::create([
|
||||||
'user_id' => $user->id,
|
'user_id' => $request->user()->id,
|
||||||
'invoice_type' => $request->invoice_type,
|
'invoice_type' => $request->invoice_type,
|
||||||
'invoice_number' => $request->invoice_number,
|
'invoice_number' => $request->invoice_number,
|
||||||
'variable_number' => $request->variable_number,
|
'variable_number' => $request->variable_number,
|
||||||
@@ -116,12 +92,46 @@ class InvoiceController extends Controller
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
if ($request->send_invoice && $invoice->client['email']) {
|
if ($request->send_invoice && $invoice->client['email']) {
|
||||||
|
|
||||||
Notification::route('mail', $invoice->client['email'])
|
Notification::route('mail', $invoice->client['email'])
|
||||||
->notify(new InvoiceDeliveryNotification($user));
|
->notify(new InvoiceDeliveryNotification($request->user()));
|
||||||
}
|
}
|
||||||
|
|
||||||
return response(
|
return response(
|
||||||
new OasisInvoiceResource($invoice), 201
|
new OasisInvoiceResource($invoice), 201
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param StoreInvoiceRequest $request
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
private function getOrStoreClient(StoreInvoiceRequest $request)
|
||||||
|
{
|
||||||
|
// Store new client
|
||||||
|
if (!Str::isUuid($request->client) && $request->store_client) {
|
||||||
|
|
||||||
|
return $request->user()->clients()->create([
|
||||||
|
'avatar' => store_avatar($request, 'client_avatar') ?? null,
|
||||||
|
'name' => $request->client_name,
|
||||||
|
'email' => $request->client_email ?? null,
|
||||||
|
'phone_number' => $request->client_phone_number ?? null,
|
||||||
|
'address' => $request->client_address,
|
||||||
|
'city' => $request->client_city,
|
||||||
|
'postal_code' => $request->client_postal_code,
|
||||||
|
'country' => $request->client_country,
|
||||||
|
'ico' => $request->client_ico,
|
||||||
|
'dic' => $request->client_dic ?? null,
|
||||||
|
'ic_dph' => $request->client_ic_dph ?? null,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get client
|
||||||
|
if (Str::isUuid($request->client)) {
|
||||||
|
|
||||||
|
return Client::whereUserId($request->user()->id)
|
||||||
|
->whereId($request->client)
|
||||||
|
->first();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,9 @@ use Illuminate\Support\Str;
|
|||||||
use Laravel\Scout\Searchable;
|
use Laravel\Scout\Searchable;
|
||||||
use TeamTNT\TNTSearch\Indexer\TNTIndexer;
|
use TeamTNT\TNTSearch\Indexer\TNTIndexer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @method static whereUserId($id)
|
||||||
|
*/
|
||||||
class Client extends Model
|
class Client extends Model
|
||||||
{
|
{
|
||||||
use HasFactory, Searchable;
|
use HasFactory, Searchable;
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ class InvoiceDeliveryNotification extends Notification
|
|||||||
public function toMail($notifiable)
|
public function toMail($notifiable)
|
||||||
{
|
{
|
||||||
return (new MailMessage)
|
return (new MailMessage)
|
||||||
->subject(__t('New invoice'))
|
->subject('New invoice')
|
||||||
->greeting(__t('mail_greeting'))
|
->greeting(__t('mail_greeting'))
|
||||||
->line($this->user->settings->name . ' sent you an invoice.')
|
->line($this->user->settings->name . ' sent you an invoice.')
|
||||||
->salutation(__t('mail_salutation'));
|
->salutation(__t('mail_salutation'));
|
||||||
|
|||||||
@@ -19,267 +19,36 @@ class OasisInvoiceTest extends TestCase
|
|||||||
{
|
{
|
||||||
use DatabaseMigrations, Queueable;
|
use DatabaseMigrations, Queueable;
|
||||||
|
|
||||||
/**
|
public function __construct()
|
||||||
* @test
|
|
||||||
*/
|
|
||||||
public function it_test_invoice_factory()
|
|
||||||
{
|
{
|
||||||
$invoice = Invoice::factory(Invoice::class)
|
parent::__construct();
|
||||||
->create();
|
|
||||||
|
|
||||||
$this->assertDatabaseHas('invoices', [
|
$this->items = [
|
||||||
'id' => $invoice->id,
|
[
|
||||||
]);
|
'description' => 'Test 1',
|
||||||
}
|
'amount' => 1,
|
||||||
|
'tax_rate' => 20,
|
||||||
/**
|
'price' => 200,
|
||||||
* @test
|
|
||||||
*/
|
|
||||||
public function user_create_new_invoice_with_storing_new_client()
|
|
||||||
{
|
|
||||||
Notification::fake();
|
|
||||||
Storage::fake('local');
|
|
||||||
|
|
||||||
$user = User::factory(User::class)
|
|
||||||
->create(['role' => 'user']);
|
|
||||||
|
|
||||||
Sanctum::actingAs($user);
|
|
||||||
|
|
||||||
$avatar = UploadedFile::fake()
|
|
||||||
->image('fake-image.jpg');
|
|
||||||
|
|
||||||
$this->postJson('/api/oasis/invoices', [
|
|
||||||
'invoice_type' => 'regular-invoice',
|
|
||||||
'invoice_number' => '2120001',
|
|
||||||
'variable_number' => '2120001',
|
|
||||||
'client' => 'others',
|
|
||||||
'client_avatar' => $avatar,
|
|
||||||
'client_name' => 'VueFileManager Inc.',
|
|
||||||
'client_email' => 'howdy@hi5ve.digital',
|
|
||||||
'client_phone_number' => '+421 950 123 456',
|
|
||||||
'client_address' => 'Does 12',
|
|
||||||
'client_city' => 'Bratislava',
|
|
||||||
'client_postal_code' => '076 54',
|
|
||||||
'client_country' => 'SK',
|
|
||||||
'client_ico' => 11111111,
|
|
||||||
'client_dic' => 11111111,
|
|
||||||
'client_ic_dph' => 'SK11111111',
|
|
||||||
'items' => [
|
|
||||||
[
|
|
||||||
'description' => 'Test 1',
|
|
||||||
'amount' => 1,
|
|
||||||
'tax_rate' => 20,
|
|
||||||
'price' => 200,
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'description' => 'Test 2',
|
|
||||||
'amount' => 3,
|
|
||||||
'tax_rate' => 20,
|
|
||||||
'price' => 500,
|
|
||||||
],
|
|
||||||
],
|
],
|
||||||
'discount_type' => 'percent',
|
[
|
||||||
'discount_rate' => 10,
|
'description' => 'Test 2',
|
||||||
'delivery_at' => Carbon::now()->addWeek(),
|
'amount' => 3,
|
||||||
'store_client' => true,
|
'tax_rate' => 20,
|
||||||
'send_invoice' => true,
|
'price' => 500,
|
||||||
])->assertStatus(201);
|
|
||||||
|
|
||||||
$this->assertDatabaseHas('invoices', [
|
|
||||||
'invoice_number' => '2120001',
|
|
||||||
'user_id' => $user->id,
|
|
||||||
'items' => json_encode([
|
|
||||||
[
|
|
||||||
'description' => 'Test 1',
|
|
||||||
'amount' => 1,
|
|
||||||
'tax_rate' => 20,
|
|
||||||
'price' => 200,
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'description' => 'Test 2',
|
|
||||||
'amount' => 3,
|
|
||||||
'tax_rate' => 20,
|
|
||||||
'price' => 500,
|
|
||||||
],
|
|
||||||
]),
|
|
||||||
'client' => json_encode([
|
|
||||||
'email' => 'howdy@hi5ve.digital',
|
|
||||||
'name' => 'VueFileManager Inc.',
|
|
||||||
'address' => 'Does 12',
|
|
||||||
'city' => 'Bratislava',
|
|
||||||
'postal_code' => '076 54',
|
|
||||||
'country' => 'SK',
|
|
||||||
'ico' => 11111111,
|
|
||||||
'dic' => 11111111,
|
|
||||||
'ic_dph' => 'SK11111111',
|
|
||||||
]),
|
|
||||||
]);
|
|
||||||
|
|
||||||
$this->assertDatabaseHas('clients', [
|
|
||||||
'user_id' => $user->id,
|
|
||||||
'name' => 'VueFileManager Inc.',
|
|
||||||
'email' => 'howdy@hi5ve.digital',
|
|
||||||
]);
|
|
||||||
|
|
||||||
Storage::disk('local')
|
|
||||||
->assertExists(Client::first()->getRawOriginal('avatar'));
|
|
||||||
|
|
||||||
Notification::assertTimesSent(1, InvoiceDeliveryNotification::class);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @test
|
|
||||||
*/
|
|
||||||
public function user_create_new_invoice_without_storing_client()
|
|
||||||
{
|
|
||||||
Notification::fake();
|
|
||||||
Storage::fake('local');
|
|
||||||
|
|
||||||
$user = User::factory(User::class)
|
|
||||||
->create(['role' => 'user']);
|
|
||||||
|
|
||||||
Sanctum::actingAs($user);
|
|
||||||
|
|
||||||
$this->postJson('/api/oasis/invoices', [
|
|
||||||
'invoice_type' => 'regular-invoice',
|
|
||||||
'invoice_number' => '2120001',
|
|
||||||
'variable_number' => '2120001',
|
|
||||||
'client' => 'others',
|
|
||||||
'client_name' => 'VueFileManager Inc.',
|
|
||||||
'client_email' => 'howdy@hi5ve.digital',
|
|
||||||
'client_phone_number' => '+421 950 123 456',
|
|
||||||
'client_address' => 'Does 12',
|
|
||||||
'client_city' => 'Bratislava',
|
|
||||||
'client_postal_code' => '076 54',
|
|
||||||
'client_country' => 'SK',
|
|
||||||
'client_ico' => 11111111,
|
|
||||||
'client_dic' => 11111111,
|
|
||||||
'client_ic_dph' => 'SK11111111',
|
|
||||||
'items' => [
|
|
||||||
[
|
|
||||||
'description' => 'Test 1',
|
|
||||||
'amount' => 1,
|
|
||||||
'tax_rate' => 20,
|
|
||||||
'price' => 200,
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'description' => 'Test 2',
|
|
||||||
'amount' => 3,
|
|
||||||
'tax_rate' => 20,
|
|
||||||
'price' => 500,
|
|
||||||
],
|
|
||||||
],
|
],
|
||||||
'discount_type' => 'percent',
|
];
|
||||||
'discount_rate' => 10,
|
|
||||||
'delivery_at' => Carbon::now()->addWeek(),
|
|
||||||
'store_client' => false,
|
|
||||||
'send_invoice' => true,
|
|
||||||
])->assertStatus(201);
|
|
||||||
|
|
||||||
$this->assertDatabaseHas('invoices', [
|
$this->client = [
|
||||||
'invoice_number' => '2120001',
|
'email' => 'howdy@hi5ve.digital',
|
||||||
'user_id' => $user->id,
|
'name' => 'VueFileManager Inc.',
|
||||||
'items' => json_encode([
|
'address' => 'Does 12',
|
||||||
[
|
'city' => 'Bratislava',
|
||||||
'description' => 'Test 1',
|
'postal_code' => '076 54',
|
||||||
'amount' => 1,
|
'country' => 'SK',
|
||||||
'tax_rate' => 20,
|
'ico' => 11111111,
|
||||||
'price' => 200,
|
'dic' => 11111111,
|
||||||
],
|
'ic_dph' => 'SK11111111',
|
||||||
[
|
];
|
||||||
'description' => 'Test 2',
|
|
||||||
'amount' => 3,
|
|
||||||
'tax_rate' => 20,
|
|
||||||
'price' => 500,
|
|
||||||
],
|
|
||||||
]),
|
|
||||||
'client' => json_encode([
|
|
||||||
'email' => 'howdy@hi5ve.digital',
|
|
||||||
'name' => 'VueFileManager Inc.',
|
|
||||||
'address' => 'Does 12',
|
|
||||||
'city' => 'Bratislava',
|
|
||||||
'postal_code' => '076 54',
|
|
||||||
'country' => 'SK',
|
|
||||||
'ico' => 11111111,
|
|
||||||
'dic' => 11111111,
|
|
||||||
'ic_dph' => 'SK11111111',
|
|
||||||
]),
|
|
||||||
]);
|
|
||||||
|
|
||||||
$this->assertDatabaseMissing('clients', [
|
|
||||||
'name' => 'VueFileManager Inc.',
|
|
||||||
'email' => 'howdy@hi5ve.digital',
|
|
||||||
]);
|
|
||||||
|
|
||||||
Notification::assertTimesSent(1, InvoiceDeliveryNotification::class);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @test
|
|
||||||
*/
|
|
||||||
public function user_create_new_invoice_with_existing_client()
|
|
||||||
{
|
|
||||||
Notification::fake();
|
|
||||||
Storage::fake('local');
|
|
||||||
|
|
||||||
$user = User::factory(User::class)
|
|
||||||
->create(['role' => 'user']);
|
|
||||||
|
|
||||||
Sanctum::actingAs($user);
|
|
||||||
|
|
||||||
$client = Client::factory(Client::class)
|
|
||||||
->create([
|
|
||||||
'user_id' => $user->id,
|
|
||||||
'name' => 'VueFileManager Inc.',
|
|
||||||
'email' => 'howdy@hi5ve.digital',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$this->postJson('/api/oasis/invoices', [
|
|
||||||
'invoice_type' => 'regular-invoice',
|
|
||||||
'invoice_number' => '2120001',
|
|
||||||
'variable_number' => '2120001',
|
|
||||||
'client' => $client->id,
|
|
||||||
'items' => [
|
|
||||||
[
|
|
||||||
'description' => 'Test 1',
|
|
||||||
'amount' => 1,
|
|
||||||
'tax_rate' => 20,
|
|
||||||
'price' => 200,
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'description' => 'Test 2',
|
|
||||||
'amount' => 3,
|
|
||||||
'tax_rate' => 20,
|
|
||||||
'price' => 500,
|
|
||||||
],
|
|
||||||
],
|
|
||||||
'discount_type' => 'percent',
|
|
||||||
'discount_rate' => 10,
|
|
||||||
'delivery_at' => Carbon::now()->addWeek(),
|
|
||||||
'send_invoice' => true,
|
|
||||||
])->assertStatus(201);
|
|
||||||
|
|
||||||
$this->assertDatabaseHas('invoices', [
|
|
||||||
'invoice_number' => '2120001',
|
|
||||||
'user_id' => $user->id,
|
|
||||||
'client_id' => $client->id,
|
|
||||||
'items' => json_encode([
|
|
||||||
[
|
|
||||||
'description' => 'Test 1',
|
|
||||||
'amount' => 1,
|
|
||||||
'tax_rate' => 20,
|
|
||||||
'price' => 200,
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'description' => 'Test 2',
|
|
||||||
'amount' => 3,
|
|
||||||
'tax_rate' => 20,
|
|
||||||
'price' => 500,
|
|
||||||
],
|
|
||||||
]),
|
|
||||||
]);
|
|
||||||
|
|
||||||
Notification::assertTimesSent(1, InvoiceDeliveryNotification::class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -384,6 +153,276 @@ class OasisInvoiceTest extends TestCase
|
|||||||
$this->assertEquals('40,00 Kč', invoice_total_tax($invoice, true));
|
$this->assertEquals('40,00 Kč', invoice_total_tax($invoice, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function it_test_invoice_factory()
|
||||||
|
{
|
||||||
|
$invoice = Invoice::factory(Invoice::class)
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('invoices', [
|
||||||
|
'id' => $invoice->id,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function user_create_new_invoice_with_storing_new_client()
|
||||||
|
{
|
||||||
|
Notification::fake();
|
||||||
|
Storage::fake('local');
|
||||||
|
|
||||||
|
$user = User::factory(User::class)
|
||||||
|
->create(['role' => 'user']);
|
||||||
|
|
||||||
|
Sanctum::actingAs($user);
|
||||||
|
|
||||||
|
$avatar = UploadedFile::fake()
|
||||||
|
->image('fake-image.jpg');
|
||||||
|
|
||||||
|
$this->postJson('/api/oasis/invoices', [
|
||||||
|
'invoice_type' => 'regular-invoice',
|
||||||
|
'invoice_number' => '2120001',
|
||||||
|
'variable_number' => '2120001',
|
||||||
|
'items' => $this->items,
|
||||||
|
'discount_type' => 'percent',
|
||||||
|
'discount_rate' => 10,
|
||||||
|
'delivery_at' => Carbon::now()->addWeek(),
|
||||||
|
'store_client' => true,
|
||||||
|
'send_invoice' => true,
|
||||||
|
|
||||||
|
'client' => 'others',
|
||||||
|
'client_avatar' => $avatar,
|
||||||
|
'client_name' => 'VueFileManager Inc.',
|
||||||
|
'client_email' => 'howdy@hi5ve.digital',
|
||||||
|
'client_phone_number' => '+421 950 123 456',
|
||||||
|
'client_address' => 'Does 12',
|
||||||
|
'client_city' => 'Bratislava',
|
||||||
|
'client_postal_code' => '076 54',
|
||||||
|
'client_country' => 'SK',
|
||||||
|
'client_ico' => 11111111,
|
||||||
|
'client_dic' => 11111111,
|
||||||
|
'client_ic_dph' => 'SK11111111',
|
||||||
|
])->assertStatus(201);
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('invoices', [
|
||||||
|
'invoice_number' => '2120001',
|
||||||
|
'user_id' => $user->id,
|
||||||
|
'items' => json_encode($this->items),
|
||||||
|
'client' => json_encode($this->client),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('clients', [
|
||||||
|
'user_id' => $user->id,
|
||||||
|
'name' => 'VueFileManager Inc.',
|
||||||
|
'email' => 'howdy@hi5ve.digital',
|
||||||
|
]);
|
||||||
|
|
||||||
|
Storage::disk('local')
|
||||||
|
->assertExists(Client::first()->getRawOriginal('avatar'));
|
||||||
|
|
||||||
|
Notification::assertTimesSent(1, InvoiceDeliveryNotification::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function user_create_new_invoice_with_storing_new_client_without_avatar_and_mail()
|
||||||
|
{
|
||||||
|
Notification::fake();
|
||||||
|
|
||||||
|
$user = User::factory(User::class)
|
||||||
|
->create(['role' => 'user']);
|
||||||
|
|
||||||
|
Sanctum::actingAs($user);
|
||||||
|
|
||||||
|
$this->postJson('/api/oasis/invoices', [
|
||||||
|
'invoice_type' => 'regular-invoice',
|
||||||
|
'invoice_number' => '2120001',
|
||||||
|
'variable_number' => '2120001',
|
||||||
|
'items' => $this->items,
|
||||||
|
'discount_type' => 'percent',
|
||||||
|
'discount_rate' => 10,
|
||||||
|
'delivery_at' => Carbon::now()->addWeek(),
|
||||||
|
'store_client' => true,
|
||||||
|
'send_invoice' => true,
|
||||||
|
|
||||||
|
'client' => 'others',
|
||||||
|
'client_avatar' => null,
|
||||||
|
'client_name' => 'VueFileManager Inc.',
|
||||||
|
'client_email' => null,
|
||||||
|
'client_phone_number' => '+421 950 123 456',
|
||||||
|
'client_address' => 'Does 12',
|
||||||
|
'client_city' => 'Bratislava',
|
||||||
|
'client_postal_code' => '076 54',
|
||||||
|
'client_country' => 'SK',
|
||||||
|
'client_ico' => 11111111,
|
||||||
|
'client_dic' => 11111111,
|
||||||
|
'client_ic_dph' => 'SK11111111',
|
||||||
|
])->assertStatus(201);
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('invoices', [
|
||||||
|
'invoice_number' => '2120001',
|
||||||
|
'user_id' => $user->id,
|
||||||
|
'items' => json_encode($this->items),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('clients', [
|
||||||
|
'user_id' => $user->id,
|
||||||
|
'name' => 'VueFileManager Inc.',
|
||||||
|
]);
|
||||||
|
|
||||||
|
Notification::assertNothingSent();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function user_create_new_invoice_without_storing_client_without_avatar_and_mail()
|
||||||
|
{
|
||||||
|
Notification::fake();
|
||||||
|
|
||||||
|
$user = User::factory(User::class)
|
||||||
|
->create(['role' => 'user']);
|
||||||
|
|
||||||
|
Sanctum::actingAs($user);
|
||||||
|
|
||||||
|
$this->postJson('/api/oasis/invoices', [
|
||||||
|
'invoice_type' => 'regular-invoice',
|
||||||
|
'invoice_number' => '2120001',
|
||||||
|
'variable_number' => '2120001',
|
||||||
|
'items' => $this->items,
|
||||||
|
'discount_type' => 'percent',
|
||||||
|
'discount_rate' => 10,
|
||||||
|
'delivery_at' => Carbon::now()->addWeek(),
|
||||||
|
'store_client' => false,
|
||||||
|
'send_invoice' => false,
|
||||||
|
|
||||||
|
'client' => 'others',
|
||||||
|
'client_avatar' => null,
|
||||||
|
'client_name' => 'VueFileManager Inc.',
|
||||||
|
'client_email' => 'howdy@hi5ve.digital',
|
||||||
|
'client_phone_number' => '+421 950 123 456',
|
||||||
|
'client_address' => 'Does 12',
|
||||||
|
'client_city' => 'Bratislava',
|
||||||
|
'client_postal_code' => '076 54',
|
||||||
|
'client_country' => 'SK',
|
||||||
|
'client_ico' => 11111111,
|
||||||
|
'client_dic' => 11111111,
|
||||||
|
'client_ic_dph' => 'SK11111111',
|
||||||
|
])->assertStatus(201);
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('invoices', [
|
||||||
|
'invoice_number' => '2120001',
|
||||||
|
'user_id' => $user->id,
|
||||||
|
'items' => json_encode($this->items),
|
||||||
|
'client' => json_encode($this->client),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertDatabaseMissing('clients', [
|
||||||
|
'user_id' => $user->id,
|
||||||
|
'name' => 'VueFileManager Inc.',
|
||||||
|
]);
|
||||||
|
|
||||||
|
Notification::assertNothingSent();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function user_create_new_invoice_without_storing_client()
|
||||||
|
{
|
||||||
|
Notification::fake();
|
||||||
|
Storage::fake('local');
|
||||||
|
|
||||||
|
$user = User::factory(User::class)
|
||||||
|
->create(['role' => 'user']);
|
||||||
|
|
||||||
|
Sanctum::actingAs($user);
|
||||||
|
|
||||||
|
$this->postJson('/api/oasis/invoices', [
|
||||||
|
'invoice_type' => 'regular-invoice',
|
||||||
|
'invoice_number' => '2120001',
|
||||||
|
'variable_number' => '2120001',
|
||||||
|
'items' => $this->items,
|
||||||
|
'discount_type' => 'percent',
|
||||||
|
'discount_rate' => 10,
|
||||||
|
'delivery_at' => Carbon::now()->addWeek(),
|
||||||
|
'store_client' => false,
|
||||||
|
'send_invoice' => true,
|
||||||
|
|
||||||
|
'client' => 'others',
|
||||||
|
'client_name' => 'VueFileManager Inc.',
|
||||||
|
'client_email' => 'howdy@hi5ve.digital',
|
||||||
|
'client_phone_number' => '+421 950 123 456',
|
||||||
|
'client_address' => 'Does 12',
|
||||||
|
'client_city' => 'Bratislava',
|
||||||
|
'client_postal_code' => '076 54',
|
||||||
|
'client_country' => 'SK',
|
||||||
|
'client_ico' => 11111111,
|
||||||
|
'client_dic' => 11111111,
|
||||||
|
'client_ic_dph' => 'SK11111111',
|
||||||
|
])->assertStatus(201);
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('invoices', [
|
||||||
|
'invoice_number' => '2120001',
|
||||||
|
'user_id' => $user->id,
|
||||||
|
'items' => json_encode($this->items),
|
||||||
|
'client' => json_encode($this->client),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertDatabaseMissing('clients', [
|
||||||
|
'name' => 'VueFileManager Inc.',
|
||||||
|
'email' => 'howdy@hi5ve.digital',
|
||||||
|
]);
|
||||||
|
|
||||||
|
Notification::assertTimesSent(1, InvoiceDeliveryNotification::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function user_create_new_invoice_with_existing_client()
|
||||||
|
{
|
||||||
|
Notification::fake();
|
||||||
|
Storage::fake('local');
|
||||||
|
|
||||||
|
$user = User::factory(User::class)
|
||||||
|
->create(['role' => 'user']);
|
||||||
|
|
||||||
|
Sanctum::actingAs($user);
|
||||||
|
|
||||||
|
$client = Client::factory(Client::class)
|
||||||
|
->create([
|
||||||
|
'user_id' => $user->id,
|
||||||
|
'name' => 'VueFileManager Inc.',
|
||||||
|
'email' => 'howdy@hi5ve.digital',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->postJson('/api/oasis/invoices', [
|
||||||
|
'invoice_type' => 'regular-invoice',
|
||||||
|
'invoice_number' => '2120001',
|
||||||
|
'variable_number' => '2120001',
|
||||||
|
'client' => $client->id,
|
||||||
|
'items' => $this->items,
|
||||||
|
'discount_type' => 'percent',
|
||||||
|
'discount_rate' => 10,
|
||||||
|
'delivery_at' => Carbon::now()->addWeek(),
|
||||||
|
'send_invoice' => true,
|
||||||
|
])->assertStatus(201);
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('invoices', [
|
||||||
|
'invoice_number' => '2120001',
|
||||||
|
'user_id' => $user->id,
|
||||||
|
'client_id' => $client->id,
|
||||||
|
'items' => json_encode($this->items),
|
||||||
|
]);
|
||||||
|
|
||||||
|
Notification::assertTimesSent(1, InvoiceDeliveryNotification::class);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user