mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-05-23 13:24:42 +00:00
store invoice profile
This commit is contained in:
@@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Oasis;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Http\Resources\Oasis\InvoiceProfileCollection;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
class InvoiceProfileController extends Controller
|
||||||
|
{
|
||||||
|
public function store(Request $request)
|
||||||
|
{
|
||||||
|
$profile = \Auth::user()
|
||||||
|
->invoiceProfile()
|
||||||
|
->create([
|
||||||
|
'logo' => store_avatar($request, 'logo') ?? null,
|
||||||
|
'stamp' => store_avatar($request, 'stamp') ?? null,
|
||||||
|
'company' => $request->company,
|
||||||
|
'email' => $request->email,
|
||||||
|
'ico' => $request->ico,
|
||||||
|
'dic' => $request->dic,
|
||||||
|
'ic_dph' => $request->ic_dph,
|
||||||
|
'registration_notes' => $request->registration_notes,
|
||||||
|
'author' => $request->author,
|
||||||
|
'address' => $request->address,
|
||||||
|
'state' => $request->state,
|
||||||
|
'city' => $request->city,
|
||||||
|
'postal_code' => $request->postal_code,
|
||||||
|
'country' => $request->country,
|
||||||
|
'phone' => $request->phone,
|
||||||
|
'bank' => $request->bank,
|
||||||
|
'iban' => $request->iban,
|
||||||
|
'swift' => $request->swift,
|
||||||
|
]);
|
||||||
|
|
||||||
|
return response(
|
||||||
|
new InvoiceProfileCollection($profile), 201
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests\Oasis;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class StoreInvoiceProfileRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function authorize()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'logo' => 'sometimes|file',
|
||||||
|
'stamp' => 'sometimes|file',
|
||||||
|
'company' => 'required|string',
|
||||||
|
'email' => 'required|email',
|
||||||
|
'ico' => 'sometimes|string|nullable',
|
||||||
|
'dic' => 'sometimes|string|nullable',
|
||||||
|
'ic_dph' => 'sometimes|string|nullable',
|
||||||
|
'registration_notes' => 'sometimes|string|nullable',
|
||||||
|
'author' => 'required|string',
|
||||||
|
'address' => 'required|string',
|
||||||
|
'state' => 'required|string',
|
||||||
|
'city' => 'required|string',
|
||||||
|
'postal_code' => 'required|string',
|
||||||
|
'country' => 'required|string',
|
||||||
|
'phone' => 'required|string',
|
||||||
|
'bank' => 'required|string',
|
||||||
|
'iban' => 'required|string',
|
||||||
|
'swift' => 'required|string',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Resources\Oasis;
|
||||||
|
|
||||||
|
use Illuminate\Http\Resources\Json\ResourceCollection;
|
||||||
|
|
||||||
|
class InvoiceProfileCollection extends ResourceCollection
|
||||||
|
{
|
||||||
|
public $collects = InvoiceProfileResource::class;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transform the resource collection into an array.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @return \Illuminate\Support\Collection
|
||||||
|
*/
|
||||||
|
public function toArray($request)
|
||||||
|
{
|
||||||
|
return $this->collection;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Resources\Oasis;
|
||||||
|
|
||||||
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||||||
|
use Laravel\Cashier\Cashier;
|
||||||
|
|
||||||
|
class InvoiceProfileResource extends JsonResource
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Transform the resource into an array.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function toArray($request)
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'data' => [
|
||||||
|
'id' => $this->id,
|
||||||
|
'type' => 'invoice-profile',
|
||||||
|
'attributes' => [
|
||||||
|
'logo' => $this->logo,
|
||||||
|
'stamp' => $this->stamp,
|
||||||
|
'company' => $this->company,
|
||||||
|
'email' => $this->email,
|
||||||
|
'ico' => $this->ico,
|
||||||
|
'dic' => $this->dic,
|
||||||
|
'ic_dph' => $this->ic_dph,
|
||||||
|
'registration_notes' => $this->registration_notes,
|
||||||
|
'author' => $this->author,
|
||||||
|
'address' => $this->address,
|
||||||
|
'state' => $this->state,
|
||||||
|
'city' => $this->city,
|
||||||
|
'postal_code' => $this->postal_code,
|
||||||
|
'country' => $this->country,
|
||||||
|
'phone' => $this->phone,
|
||||||
|
'bank' => $this->bank,
|
||||||
|
'iban' => $this->iban,
|
||||||
|
'swift' => $this->swift,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
+4
-1
@@ -3,6 +3,7 @@
|
|||||||
use App\Http\Controllers\Oasis\AdminController;
|
use App\Http\Controllers\Oasis\AdminController;
|
||||||
use App\Http\Controllers\Oasis\ClientController;
|
use App\Http\Controllers\Oasis\ClientController;
|
||||||
use App\Http\Controllers\Oasis\InvoiceController;
|
use App\Http\Controllers\Oasis\InvoiceController;
|
||||||
|
use App\Http\Controllers\Oasis\InvoiceProfileController;
|
||||||
use App\Http\Controllers\Oasis\SubscriptionController;
|
use App\Http\Controllers\Oasis\SubscriptionController;
|
||||||
use App\Services\Oasis\OasisDevService;
|
use App\Services\Oasis\OasisDevService;
|
||||||
|
|
||||||
@@ -23,12 +24,14 @@ Route::group(['middleware' => 'api', 'prefix' => '/api/oasis'], function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Invoices
|
// Invoices
|
||||||
Route::group(['prefix' => 'invoices'], function () {
|
Route::group(['middleware' => 'auth:sanctum', 'prefix' => 'invoices'], function () {
|
||||||
Route::get('/regular', [InvoiceController::class, 'get_all_regular_invoices']);
|
Route::get('/regular', [InvoiceController::class, 'get_all_regular_invoices']);
|
||||||
Route::get('/advance', [InvoiceController::class, 'get_all_advance_invoices']);
|
Route::get('/advance', [InvoiceController::class, 'get_all_advance_invoices']);
|
||||||
Route::get('/search', [InvoiceController::class, 'search']);
|
Route::get('/search', [InvoiceController::class, 'search']);
|
||||||
|
|
||||||
Route::post('/', [InvoiceController::class, 'store']);
|
Route::post('/', [InvoiceController::class, 'store']);
|
||||||
|
|
||||||
|
Route::post('/profile', [InvoiceProfileController::class, 'store']);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Clients
|
// Clients
|
||||||
|
|||||||
@@ -0,0 +1,64 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\Oasis;
|
||||||
|
|
||||||
|
use App\Models\Oasis\InvoiceProfile;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||||
|
use Illuminate\Http\UploadedFile;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
use Laravel\Sanctum\Sanctum;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class OasisInvoiceProfileTest extends TestCase
|
||||||
|
{
|
||||||
|
use DatabaseMigrations;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function user_store_invoice_profile_with_images()
|
||||||
|
{
|
||||||
|
Storage::fake('local');
|
||||||
|
|
||||||
|
$image = UploadedFile::fake()
|
||||||
|
->image('fake-image.jpg');
|
||||||
|
|
||||||
|
$user = User::factory(User::class)
|
||||||
|
->create(['role' => 'user']);
|
||||||
|
|
||||||
|
Sanctum::actingAs($user);
|
||||||
|
|
||||||
|
$this->postJson('/api/oasis/invoices/profile', [
|
||||||
|
'logo' => $image,
|
||||||
|
'stamp' => $image,
|
||||||
|
'company' => 'VueFileManager Inc.',
|
||||||
|
'email' => 'howdy@hi5ve.digital',
|
||||||
|
'ico' => '11111111',
|
||||||
|
'dic' => '11111111',
|
||||||
|
'ic_dph' => 'SK20002313123',
|
||||||
|
'registration_notes' => 'Some registration notes',
|
||||||
|
'author' => 'John Doe',
|
||||||
|
'address' => 'Does 11',
|
||||||
|
'state' => 'Slovakia',
|
||||||
|
'city' => 'Bratislava',
|
||||||
|
'postal_code' => '04001',
|
||||||
|
'country' => 'SK',
|
||||||
|
'phone' => '+421950123456',
|
||||||
|
'bank' => 'Fio Banka',
|
||||||
|
'iban' => 'SK20000054236423624',
|
||||||
|
'swift' => 'FIOZXXX',
|
||||||
|
])->assertStatus(201);
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('invoice_profiles', [
|
||||||
|
'user_id' => $user->id,
|
||||||
|
'company' => 'VueFileManager Inc.',
|
||||||
|
'email' => 'howdy@hi5ve.digital',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$profile = InvoiceProfile::first();
|
||||||
|
|
||||||
|
Storage::disk('local')->assertExists($profile->logo);
|
||||||
|
Storage::disk('local')->assertExists($profile->stamp);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user