mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-05-17 18:55:02 +00:00
- removed invoicing from oasis
This commit is contained in:
@@ -1,130 +0,0 @@
|
||||
<?php
|
||||
namespace App\Http\Controllers\Oasis;
|
||||
|
||||
use Auth;
|
||||
use App\Models\Oasis\Client;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Oasis\StoreClientRequest;
|
||||
use Illuminate\Contracts\Foundation\Application;
|
||||
use Illuminate\Contracts\Routing\ResponseFactory;
|
||||
use App\Http\Resources\Oasis\OasisInvoiceCollection;
|
||||
use App\Http\Resources\Oasis\OasisViewClientResource;
|
||||
use App\Http\Resources\Oasis\OasisViewClientCollection;
|
||||
|
||||
class ClientController extends Controller
|
||||
{
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$clients = Client::sortable(['created_at', 'DESC'])
|
||||
->whereUserId(Auth::id())
|
||||
->get();
|
||||
|
||||
return response(
|
||||
new OasisViewClientCollection($clients),
|
||||
200
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param StoreClientRequest $request
|
||||
* @return Application|ResponseFactory|Response
|
||||
*/
|
||||
public function store(StoreClientRequest $request)
|
||||
{
|
||||
$client = $request->user()
|
||||
->clients()
|
||||
->create([
|
||||
'avatar' => store_avatar($request, 'avatar') ?? null,
|
||||
'name' => $request->name,
|
||||
'email' => $request->email ?? null,
|
||||
'phone_number' => $request->phone_number ?? null,
|
||||
'address' => $request->address,
|
||||
'city' => $request->city,
|
||||
'postal_code' => $request->postal_code,
|
||||
'country' => $request->country,
|
||||
'ico' => $request->ico ?? null,
|
||||
'dic' => $request->dic ?? null,
|
||||
'ic_dph' => $request->ic_dph ?? null,
|
||||
]);
|
||||
|
||||
return response(
|
||||
new OasisViewClientResource($client),
|
||||
201
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Client $client
|
||||
* @return Application|ResponseFactory|Response
|
||||
*/
|
||||
public function show(Client $client)
|
||||
{
|
||||
return response(new OasisViewClientResource($client), 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Client $client
|
||||
* @param Request $request
|
||||
* @return Application|ResponseFactory|Response
|
||||
*/
|
||||
public function update(Client $client, Request $request)
|
||||
{
|
||||
// Store image if exist
|
||||
if ($request->hasFile($request->name)) {
|
||||
// Find and update image path
|
||||
$client->update([
|
||||
$request->name => store_avatar($request, $request->name),
|
||||
]);
|
||||
|
||||
return response('Done', 204);
|
||||
}
|
||||
|
||||
$client->update(
|
||||
make_single_input($request)
|
||||
);
|
||||
|
||||
return response('Done', 204);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Client $client
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function destroy(Client $client)
|
||||
{
|
||||
$client->delete();
|
||||
|
||||
return response('Done', 204);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Client $client
|
||||
* @return Application|ResponseFactory|Response
|
||||
*/
|
||||
public function show_invoices(Client $client)
|
||||
{
|
||||
return response(new OasisInvoiceCollection($client->invoices), 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function search()
|
||||
{
|
||||
$query = remove_accents(request()->input('query'));
|
||||
|
||||
$results = Client::search($query)
|
||||
->where('user_id', request()->user()->id)
|
||||
->get();
|
||||
|
||||
return response(
|
||||
new OasisViewClientCollection($results),
|
||||
200
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,287 +0,0 @@
|
||||
<?php
|
||||
namespace App\Http\Controllers\Oasis;
|
||||
|
||||
use Auth;
|
||||
use Storage;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Str;
|
||||
use App\Models\Oasis\Client;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Oasis\Invoice;
|
||||
use Illuminate\Http\Response;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use App\Http\Requests\Oasis\ShareInvoiceRequest;
|
||||
use App\Http\Requests\Oasis\StoreInvoiceRequest;
|
||||
use Illuminate\Contracts\Foundation\Application;
|
||||
use Illuminate\Contracts\Routing\ResponseFactory;
|
||||
use App\Http\Resources\Oasis\OasisInvoiceResource;
|
||||
use App\Http\Resources\Oasis\OasisViewInvoiceResource;
|
||||
use App\Http\Resources\Oasis\OasisViewInvoiceCollection;
|
||||
use App\Notifications\Oasis\InvoiceDeliveryNotification;
|
||||
|
||||
class InvoiceController extends Controller
|
||||
{
|
||||
/**
|
||||
* @return Application|ResponseFactory|Response
|
||||
*/
|
||||
public function get_all_regular_invoices()
|
||||
{
|
||||
$invoices = Invoice::sortable(['created_at', 'DESC'])
|
||||
->whereUserId(Auth::id())
|
||||
->whereInvoiceType('regular-invoice')
|
||||
->get();
|
||||
|
||||
return response(
|
||||
new OasisViewInvoiceCollection($invoices),
|
||||
200
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Application|ResponseFactory|Response
|
||||
*/
|
||||
public function get_all_advance_invoices()
|
||||
{
|
||||
$invoices = Invoice::sortable(['created_at', 'DESC'])
|
||||
->whereUserId(Auth::id())
|
||||
->whereInvoiceType('advance-invoice')
|
||||
->get();
|
||||
|
||||
return response(
|
||||
new OasisViewInvoiceCollection($invoices),
|
||||
200
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Invoice $invoice
|
||||
* @return Application|ResponseFactory|Response
|
||||
*/
|
||||
public function get_single_invoice(Invoice $invoice)
|
||||
{
|
||||
return response(
|
||||
new OasisInvoiceResource($invoice),
|
||||
200
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Invoice $invoice
|
||||
* @return \Symfony\Component\HttpFoundation\StreamedResponse
|
||||
*/
|
||||
public function download_invoice(Invoice $invoice)
|
||||
{
|
||||
if (! Storage::exists(invoice_path($invoice))) {
|
||||
abort(404, 'Not Found');
|
||||
}
|
||||
|
||||
return Storage::download(invoice_path($invoice), "invoice-{$invoice->id}.pdf");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Application|ResponseFactory|Response
|
||||
*/
|
||||
public function search()
|
||||
{
|
||||
$results = Invoice::search(
|
||||
remove_accents(request()->input('query'))
|
||||
)
|
||||
->where('user_id', request()->user()->id)
|
||||
->where('invoice_type', request()->input('type'))
|
||||
->get();
|
||||
|
||||
return response(
|
||||
new OasisViewInvoiceCollection($results),
|
||||
200
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store and generate new invoice
|
||||
*
|
||||
* @param StoreInvoiceRequest $request
|
||||
* @return Application|ResponseFactory|Response
|
||||
*/
|
||||
public function store(StoreInvoiceRequest $request)
|
||||
{
|
||||
$client = $this->getOrStoreClient($request);
|
||||
$user = $request->user();
|
||||
|
||||
$invoice = Invoice::create([
|
||||
'user_id' => $user->id,
|
||||
'client_id' => $client->id ?? null,
|
||||
'invoice_type' => $request->invoice_type,
|
||||
'invoice_number' => $request->invoice_number,
|
||||
'variable_number' => $request->variable_number,
|
||||
'delivery_at' => $request->delivery_at,
|
||||
'discount_type' => $request->discount_type ?? null,
|
||||
'discount_rate' => $request->discount_rate ?? null,
|
||||
'items' => json_decode($request->items),
|
||||
'user' => $user->invoiceProfile,
|
||||
'client' => [
|
||||
'email' => $client->email ?? $request->client_email,
|
||||
'name' => $client->name ?? $request->client_name,
|
||||
'address' => $client->address ?? $request->client_address,
|
||||
'city' => $client->city ?? $request->client_city,
|
||||
'postal_code' => $client->postal_code ?? $request->client_postal_code,
|
||||
'country' => $client->country ?? $request->client_country,
|
||||
'ico' => $client->ico ?? $request->client_ico,
|
||||
'dic' => $client->dic ?? $request->client_dic ?? null,
|
||||
'ic_dph' => $client->ic_dph ?? $request->client_ic_dph ?? null,
|
||||
],
|
||||
]);
|
||||
|
||||
// Generate PDF
|
||||
\PDF::loadView('oasis.invoices.invoice', [
|
||||
'invoice' => Invoice::find($invoice->id),
|
||||
'user' => $user,
|
||||
])
|
||||
->setPaper('a4')
|
||||
->setOrientation('portrait')
|
||||
->save(
|
||||
storage_path("app/files/{$user->id}/invoice-{$invoice->id}.pdf")
|
||||
);
|
||||
|
||||
if ($request->send_invoice && $invoice->client['email']) {
|
||||
Notification::route('mail', $invoice->client['email'])->notify(
|
||||
new InvoiceDeliveryNotification($user, $invoice)
|
||||
);
|
||||
}
|
||||
|
||||
return response(
|
||||
new OasisViewInvoiceResource($invoice),
|
||||
201
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store and generate new invoice
|
||||
*
|
||||
* @param Request $request
|
||||
* @param Invoice $invoice
|
||||
* @return Application|ResponseFactory|Response
|
||||
*/
|
||||
public function update(StoreInvoiceRequest $request, Invoice $invoice)
|
||||
{
|
||||
$user = $request->user();
|
||||
|
||||
$invoice->update([
|
||||
'invoice_number' => $request->invoice_number,
|
||||
'variable_number' => $request->variable_number,
|
||||
'delivery_at' => $request->delivery_at,
|
||||
'discount_type' => $request->discount_type ?? null,
|
||||
'discount_rate' => $request->discount_rate ?? null,
|
||||
'items' => json_decode($request->items),
|
||||
]);
|
||||
|
||||
Storage::delete(invoice_path($invoice));
|
||||
|
||||
// Generate PDF
|
||||
\PDF::loadView('oasis.invoices.invoice', [
|
||||
'invoice' => Invoice::find($invoice->id),
|
||||
'user' => $user,
|
||||
])
|
||||
->setPaper('a4')
|
||||
->setOrientation('portrait')
|
||||
->save(
|
||||
storage_path("app/files/{$user->id}/invoice-{$invoice->id}.pdf")
|
||||
);
|
||||
|
||||
if ($request->send_invoice && $invoice->client['email']) {
|
||||
Notification::route('mail', $invoice->client['email'])->notify(
|
||||
new InvoiceDeliveryNotification($user, $invoice)
|
||||
);
|
||||
}
|
||||
|
||||
return response(
|
||||
'Done',
|
||||
204
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Share invoice via email
|
||||
*
|
||||
* @param ShareInvoiceRequest $request
|
||||
* @param Invoice $invoice
|
||||
*/
|
||||
public function share(ShareInvoiceRequest $request, Invoice $invoice)
|
||||
{
|
||||
Notification::route('mail', $request->email)
|
||||
->notify(
|
||||
new InvoiceDeliveryNotification($request->user(), $invoice)
|
||||
);
|
||||
|
||||
return response(
|
||||
'Done',
|
||||
204
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Invoice $invoice
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function destroy(Invoice $invoice)
|
||||
{
|
||||
$invoice->delete();
|
||||
|
||||
return response('Done', 204);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get data for frontend invoice creator
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function editor()
|
||||
{
|
||||
$user = Auth::user();
|
||||
|
||||
return [
|
||||
'isVatPayer' => $user->invoiceProfile->ic_dph ?? false,
|
||||
'latestInvoiceNumber' => $user->regularInvoices->first()
|
||||
? (int) $user->regularInvoices->first()->invoice_number
|
||||
: null,
|
||||
'recommendedInvoiceNumber' => $user->regularInvoices->first()
|
||||
? (int) $user->regularInvoices->first()->invoice_number + 1
|
||||
: Carbon::now()->format('Y') . '0001',
|
||||
'clients' => $user->clients->map(function ($client) {
|
||||
return [
|
||||
'label' => $client->name,
|
||||
'value' => $client->id,
|
||||
];
|
||||
}),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param StoreInvoiceRequest $request
|
||||
* @return mixed
|
||||
*/
|
||||
private function getOrStoreClient(StoreInvoiceRequest $request)
|
||||
{
|
||||
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 ?? null,
|
||||
'dic' => $request->client_dic ?? null,
|
||||
'ic_dph' => $request->client_ic_dph ?? null,
|
||||
]);
|
||||
}
|
||||
|
||||
return Client::whereUserId($request->user()->id)
|
||||
->whereId($request->client)
|
||||
->first();
|
||||
}
|
||||
}
|
||||
@@ -1,90 +0,0 @@
|
||||
<?php
|
||||
namespace App\Http\Controllers\Oasis;
|
||||
|
||||
use Auth;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Oasis\InvoiceProfile;
|
||||
use Illuminate\Contracts\Foundation\Application;
|
||||
use Illuminate\Contracts\Routing\ResponseFactory;
|
||||
use App\Http\Resources\Oasis\InvoiceProfileResource;
|
||||
|
||||
class InvoiceProfileController extends Controller
|
||||
{
|
||||
/**
|
||||
* @return Application|ResponseFactory|Response
|
||||
*/
|
||||
public function show()
|
||||
{
|
||||
$user = Auth::user();
|
||||
|
||||
if ($user->invoiceProfile) {
|
||||
return response(
|
||||
new InvoiceProfileResource($user->invoiceProfile),
|
||||
200
|
||||
);
|
||||
}
|
||||
|
||||
return response("Profile didn't exists", 404);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return Application|ResponseFactory|Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$profile = InvoiceProfile::create([
|
||||
'user_id' => $request->user()->id,
|
||||
'logo' => store_system_image($request, 'logo') ?? null,
|
||||
'stamp' => store_system_image($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 InvoiceProfileResource($profile),
|
||||
201
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request)
|
||||
{
|
||||
// Store image if exist
|
||||
if ($request->hasFile($request->name)) {
|
||||
// Find and update image path
|
||||
$request->user()
|
||||
->invoiceProfile()
|
||||
->update([
|
||||
$request->name => store_system_image($request, $request->name),
|
||||
]);
|
||||
|
||||
return response('Done', 204);
|
||||
}
|
||||
|
||||
$request->user()
|
||||
->invoiceProfile()
|
||||
->update(make_single_input($request));
|
||||
|
||||
return response('Done', 204);
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
<?php
|
||||
namespace App\Http\Requests\Oasis;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class ShareInvoiceRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'email' => 'required|email',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
<?php
|
||||
namespace App\Http\Requests\Oasis;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class StoreClientRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'avatar' => 'sometimes|nullable',
|
||||
'name' => 'required|string',
|
||||
'email' => 'sometimes|email|nullable',
|
||||
'phone_number' => 'sometimes|string|nullable',
|
||||
'address' => 'required|string',
|
||||
'city' => 'required|string',
|
||||
'postal_code' => 'required|string',
|
||||
'country' => 'required|string',
|
||||
'ico' => 'required|string',
|
||||
'dic' => 'required|string|nullable',
|
||||
'ic_dph' => 'sometimes|string|nullable',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
<?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',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
<?php
|
||||
namespace App\Http\Requests\Oasis;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class StoreInvoiceRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'invoice_type' => 'sometimes|string',
|
||||
'invoice_number' => 'required|string',
|
||||
'variable_number' => 'required|string',
|
||||
'client' => 'sometimes|required',
|
||||
'items' => 'required|string',
|
||||
'discount_type' => 'sometimes|string',
|
||||
'discount_rate' => 'sometimes|integer',
|
||||
'delivery_at' => 'required|date',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
<?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 array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'data' => $this->collection,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
<?php
|
||||
namespace App\Http\Resources\Oasis;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
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,
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
<?php
|
||||
namespace App\Http\Resources\Oasis;
|
||||
|
||||
use Illuminate\Http\Resources\Json\ResourceCollection;
|
||||
|
||||
class OasisInvoiceCollection extends ResourceCollection
|
||||
{
|
||||
public $collects = OasisInvoiceResource::class;
|
||||
|
||||
/**
|
||||
* Transform the resource collection into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'data' => $this->collection,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
<?php
|
||||
namespace App\Http\Resources\Oasis;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class OasisInvoiceResource 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',
|
||||
'attributes' => [
|
||||
'name' => $this->client['name'] . ' ' . format_to_currency($this->total_net, $this->currency),
|
||||
'invoice_number' => $this->invoice_number,
|
||||
'variable_number' => $this->variable_number,
|
||||
'invoice_type' => $this->invoice_type,
|
||||
'delivery_at' => $this->delivery_at,
|
||||
'items' => $this->items,
|
||||
'discount_type' => $this->discount_type,
|
||||
'discount_rate' => $this->discount_rate,
|
||||
'client' => $this->client,
|
||||
'total' => format_to_currency($this->total_net, $this->currency),
|
||||
'file_url' => "/oasis/invoice/$this->id",
|
||||
'mimetype' => 'pdf',
|
||||
'created_at' => format_date($this->created_at, '%d. %B. %Y'),
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
<?php
|
||||
namespace App\Http\Resources\Oasis;
|
||||
|
||||
use Illuminate\Http\Resources\Json\ResourceCollection;
|
||||
|
||||
class OasisViewClientCollection extends ResourceCollection
|
||||
{
|
||||
public $collects = OasisViewClientResource::class;
|
||||
|
||||
/**
|
||||
* Transform the resource collection into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return $this->collection;
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
<?php
|
||||
namespace App\Http\Resources\Oasis;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class OasisViewClientResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
$total_net = \DB::table('invoices')
|
||||
->whereClientId($this->id)
|
||||
->sum('total_net');
|
||||
|
||||
$total_invoices = \DB::table('invoices')
|
||||
->whereClientId($this->id)
|
||||
->count();
|
||||
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'type' => 'client',
|
||||
'created_at' => format_date($this->created_at, '%d. %B %Y'),
|
||||
|
||||
'totalNet' => format_to_currency($total_net, 'CZK'),
|
||||
'totalInvoices' => $total_invoices,
|
||||
|
||||
'avatar' => $this->avatar,
|
||||
'name' => $this->name,
|
||||
'email' => $this->email,
|
||||
'phone_number' => $this->phone_number,
|
||||
'address' => $this->address,
|
||||
'city' => $this->city,
|
||||
'postal_code' => $this->postal_code,
|
||||
'country' => $this->country,
|
||||
'ico' => $this->ico,
|
||||
'dic' => $this->dic,
|
||||
'ic_dph' => $this->ic_dph,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
<?php
|
||||
namespace App\Http\Resources\Oasis;
|
||||
|
||||
use Illuminate\Http\Resources\Json\ResourceCollection;
|
||||
|
||||
class OasisViewInvoiceCollection extends ResourceCollection
|
||||
{
|
||||
public $collects = OasisViewInvoiceResource::class;
|
||||
|
||||
/**
|
||||
* Transform the resource collection into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return $this->collection;
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
<?php
|
||||
namespace App\Http\Resources\Oasis;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class OasisViewInvoiceResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'client_id' => $this->client_id,
|
||||
'name' => $this->client['name'] . ' ' . format_to_currency($this->total_net, $this->currency),
|
||||
'invoice_number' => $this->invoice_number,
|
||||
'total' => format_to_currency($this->total_net, $this->currency),
|
||||
'file_url' => "/oasis/invoice/$this->id",
|
||||
'client_name' => $this->client['name'],
|
||||
'mimetype' => 'pdf',
|
||||
'type' => 'invoice',
|
||||
'created_at' => format_date($this->created_at, '%d. %B. %Y'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,210 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Laravel\Cashier\Cashier;
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @return bool
|
||||
*/
|
||||
function is_route($name)
|
||||
{
|
||||
return Route::currentRouteName() === $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $filepath
|
||||
* @return string
|
||||
*/
|
||||
function base64_from_storage_image($filepath)
|
||||
{
|
||||
if (is_null($filepath)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (! Storage::exists($filepath)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return 'data:' . Storage::mimeType($filepath) . ';base64,' . base64_encode(Storage::get($filepath));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return invoice path to storage
|
||||
*
|
||||
* @param $invoice
|
||||
* @return string
|
||||
*/
|
||||
function invoice_path($invoice)
|
||||
{
|
||||
return "files/{$invoice->user_id}/invoice-{$invoice->id}.pdf";
|
||||
}
|
||||
|
||||
/**
|
||||
* Get only tax for single invoice item
|
||||
*
|
||||
* @param $item
|
||||
* @return float|int|string
|
||||
*/
|
||||
function invoice_item_only_tax_price($item)
|
||||
{
|
||||
return ($item['price'] * $item['amount']) * ($item['tax_rate'] / 100);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get item price with tax for single invoice item
|
||||
*
|
||||
* @param $item
|
||||
* @return float|int|string
|
||||
*/
|
||||
function invoice_item_with_tax_price($item)
|
||||
{
|
||||
return ($item['price'] * $item['amount']) * ($item['tax_rate'] / 100 + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $invoice
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
function invoice_tax_base($invoice)
|
||||
{
|
||||
$bag = collect([]);
|
||||
|
||||
// Count tax base
|
||||
foreach ($invoice['items'] as $item) {
|
||||
if (! $bag->firstWhere('rate', $item['tax_rate'])) {
|
||||
$bag->push([
|
||||
'rate' => $item['tax_rate'],
|
||||
'total' => $item['price'] * $item['amount'],
|
||||
]);
|
||||
} else {
|
||||
$bag->map(function ($bagItem) use ($item) {
|
||||
if ($bagItem['rate'] === $item['tax_rate']) {
|
||||
$bagItem['total'] += ($item['price'] * $item['amount']);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Count discount
|
||||
if ($invoice['discount_type']) {
|
||||
return $bag->map(function ($bagItem) use ($invoice) {
|
||||
if ($invoice['discount_type'] === 'percent') {
|
||||
$bagItem['total'] -= $bagItem['total'] * ($invoice['discount_rate'] / 100);
|
||||
}
|
||||
|
||||
if ($invoice['discount_type'] === 'value') {
|
||||
$percentage_of_discount = $invoice['discount_rate'] / (invoice_total($invoice) + $invoice['discount_rate']);
|
||||
|
||||
$bagItem['total'] -= $bagItem['total'] * $percentage_of_discount;
|
||||
}
|
||||
|
||||
return $bagItem;
|
||||
});
|
||||
}
|
||||
|
||||
return $bag;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $invoice
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
function invoice_tax_summary($invoice)
|
||||
{
|
||||
$bag = collect([]);
|
||||
|
||||
// Count tax base
|
||||
foreach ($invoice['items'] as $item) {
|
||||
if (! $bag->firstWhere('rate', $item['tax_rate'])) {
|
||||
$bag->push([
|
||||
'rate' => $item['tax_rate'],
|
||||
'total' => ($item['price'] * $item['amount']) * ($item['tax_rate'] / 100),
|
||||
]);
|
||||
} else {
|
||||
$bag->map(function ($bagItem) use ($item) {
|
||||
if ($bagItem['rate'] === $item['tax_rate']) {
|
||||
$bagItem['total'] += ($item['price'] * $item['amount']) * ($item['tax_rate'] / 100);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Count discount
|
||||
if ($invoice['discount_type']) {
|
||||
return $bag->map(function ($bagItem) use ($invoice) {
|
||||
if ($invoice['discount_type'] === 'percent') {
|
||||
$bagItem['total'] -= $bagItem['total'] * ($invoice['discount_rate'] / 100);
|
||||
}
|
||||
|
||||
if ($invoice['discount_type'] === 'value') {
|
||||
$percentage_of_discount = $invoice['discount_rate'] / (invoice_total($invoice) + $invoice['discount_rate']);
|
||||
|
||||
$bagItem['total'] -= $bagItem['total'] * $percentage_of_discount;
|
||||
}
|
||||
|
||||
return $bagItem;
|
||||
});
|
||||
}
|
||||
|
||||
return $bag;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $invoice
|
||||
* @return float|int|string
|
||||
*/
|
||||
function invoice_total($invoice)
|
||||
{
|
||||
$total = 0;
|
||||
|
||||
foreach ($invoice['items'] as $item) {
|
||||
$total_without_tax = $item['amount'] * $item['price'];
|
||||
|
||||
if ($invoice['user']['ic_dph'] && $item['tax_rate']) {
|
||||
$total_without_tax += $total_without_tax * ($item['tax_rate'] / 100);
|
||||
}
|
||||
|
||||
$total += $total_without_tax;
|
||||
}
|
||||
|
||||
if ($invoice['discount_type']) {
|
||||
if ($invoice['discount_type'] === 'percent') {
|
||||
$total -= $total * ($invoice['discount_rate'] / 100);
|
||||
}
|
||||
|
||||
if ($invoice['discount_type'] === 'value') {
|
||||
$total -= $invoice['discount_rate'];
|
||||
}
|
||||
}
|
||||
|
||||
return $total;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $invoice
|
||||
* @param false $format
|
||||
* @return float|int|string
|
||||
*/
|
||||
function invoice_total_tax($invoice)
|
||||
{
|
||||
$total = 0;
|
||||
|
||||
foreach ($invoice['items'] as $item) {
|
||||
$total += ($item['amount'] * $item['price']) * ($item['tax_rate'] / 100);
|
||||
}
|
||||
|
||||
return $total;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @param string $currency
|
||||
* @param string $locale
|
||||
* @return string
|
||||
*/
|
||||
function format_to_currency($value, $currency = 'CZK', $locale = 'cs')
|
||||
{
|
||||
$amount = round($value, 2) * 100;
|
||||
|
||||
return Cashier::formatAmount((int) $amount, $currency, $locale);
|
||||
}
|
||||
+926
-843
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user