Lots of changes
This commit is contained in:
@@ -15,13 +15,26 @@ public function __construct(LarapexChart $chart)
|
||||
|
||||
public function build($options = null)
|
||||
{
|
||||
$data = \App\Models\ClientCase::query()
|
||||
->selectRaw('EXTRACT(MONTH from created_at) as month, COUNT(id) as count')
|
||||
->limit(6)
|
||||
->whereRaw('EXTRACT(MONTH from created_at) > EXTRACT(MONTH from (NOW() - INTERVAL \'6 month\')) ')
|
||||
->groupByRaw('EXTRACT(MONTH from created_at)')
|
||||
->orderByRaw('EXTRACT(MONTH from created_at)')
|
||||
->get();
|
||||
|
||||
$months = $data->pluck('month')->map(
|
||||
fn($nu)
|
||||
=> \DateTime::createFromFormat('!m', $nu)->format('F'))->toArray();
|
||||
|
||||
$newCases = $data->pluck('count')->toArray();
|
||||
|
||||
return $this->chart->areaChart()
|
||||
->setTitle('Contracts during last six months.')
|
||||
->setSubtitle('New and Completed.')
|
||||
->addData('New', [4, 9, 5, 2, 1, 8])
|
||||
->addData('Completed', [7, 2, 7, 2, 5, 4])
|
||||
->setTitle('Cases during last six months.')
|
||||
->addData('New cases', $newCases)
|
||||
//->addData('Completed', [7, 2, 7, 2, 5, 4])
|
||||
->setColors(['#1A56DB', '#ff6384'])
|
||||
->setXAxis(['January', 'February', 'March', 'April', 'May', 'June'])
|
||||
->setXAxis($months)
|
||||
->setToolbar(true)
|
||||
->toVue();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,190 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\ClientCase;
|
||||
use App\Models\Contract;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
|
||||
class ClientCaseContoller extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index(ClientCase $clientCase, Request $request)
|
||||
{
|
||||
return Inertia::render('Cases/Index', [
|
||||
'client_cases' => $clientCase::with(['person'])
|
||||
->when($request->input('search'), fn($que, $search) =>
|
||||
$que->whereHas(
|
||||
'person',
|
||||
fn($q) => $q->where('full_name', 'like', '%' . $search . '%')
|
||||
)
|
||||
)
|
||||
->where('active', 1)
|
||||
->orderByDesc('created_at')
|
||||
->paginate(15)
|
||||
->withQueryString(),
|
||||
'filters' => $request->only(['search'])
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
$cuuid = $request->input('client_uuid');
|
||||
|
||||
$client = \App\Models\Client::where('uuid', $cuuid)->firstOrFail();
|
||||
|
||||
if( isset($client->id) ){
|
||||
|
||||
\DB::transaction(function() use ($request, $client){
|
||||
$pq = $request->input('person');
|
||||
|
||||
$person = $client->person()->create([
|
||||
'nu' => rand(100000,200000),
|
||||
'first_name' => $pq['first_name'],
|
||||
'last_name' => $pq['last_name'],
|
||||
'full_name' => $pq['full_name'],
|
||||
'gender' => null,
|
||||
'birthday' => null,
|
||||
'tax_number' => null,
|
||||
'social_security_number' => null,
|
||||
'description' => 'sdwwf',
|
||||
'group_id' => 2,
|
||||
'type_id' => 1
|
||||
]);
|
||||
|
||||
$person->addresses()->create([
|
||||
'address' => $pq['address']['address'],
|
||||
'country' => $pq['address']['country'],
|
||||
'type_id' => $pq['address']['type_id']
|
||||
]);
|
||||
|
||||
$person->clientCase()->create([
|
||||
'client_id' => $client->id
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
return to_route('client.show', $client);
|
||||
}
|
||||
|
||||
public function storeContract(ClientCase $clientCase, Request $request)
|
||||
{
|
||||
|
||||
\DB::transaction(function() use ($request, $clientCase){
|
||||
|
||||
//Create contract
|
||||
$clientCase->contracts()->create([
|
||||
'reference' => $request->input('reference'),
|
||||
'start_date' => date('Y-m-d', strtotime($request->input('start_date'))),
|
||||
'type_id' => $request->input('type_id')
|
||||
]);
|
||||
|
||||
});
|
||||
|
||||
return to_route('clientCase.show', $clientCase);
|
||||
}
|
||||
|
||||
public function updateContract(ClientCase $clientCase, String $uuid, Request $request)
|
||||
{
|
||||
$contract = Contract::where('uuid', $uuid)->firstOrFail();
|
||||
|
||||
\DB::transaction(function() use ($request, $contract){
|
||||
$contract->update([
|
||||
'reference' => $request->input('reference'),
|
||||
'type_id' => $request->input('type_id')
|
||||
]);
|
||||
|
||||
});
|
||||
|
||||
return to_route('clientCase.show', $clientCase);
|
||||
}
|
||||
|
||||
public function storeActivity(ClientCase $clientCase, Request $request) {
|
||||
|
||||
$attributes = $request->validate([
|
||||
'due_date' => 'nullable|date',
|
||||
'amount' => 'nullable|decimal:0,4',
|
||||
'note' => 'string',
|
||||
'action_id' => 'exists:\App\Models\Action,id',
|
||||
'decision_id' => 'exists:\App\Models\Decision,id'
|
||||
]);
|
||||
|
||||
//Create activity
|
||||
$clientCase->activities()->create($attributes);
|
||||
|
||||
return to_route('clientCase.show', $clientCase);
|
||||
|
||||
}
|
||||
|
||||
public function deleteContract(ClientCase $clientCase, String $uuid, Request $request) {
|
||||
$contract = Contract::where('uuid', $uuid)->firstOrFail();
|
||||
|
||||
\DB::transaction(function() use ($request, $contract){
|
||||
$contract->delete();
|
||||
});
|
||||
|
||||
return to_route('clientCase.show', $clientCase);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(ClientCase $clientCase)
|
||||
{
|
||||
$case = $clientCase::with([
|
||||
'person' => fn($que) => $que->with('addresses')
|
||||
])->where('active', 1)->findOrFail($clientCase->id);
|
||||
|
||||
return Inertia::render('Cases/Show', [
|
||||
'client' => $case->client()->with('person', fn($q) => $q->with(['addresses']))->firstOrFail(),
|
||||
'client_case' => $case,
|
||||
'contracts' => $case->contracts()
|
||||
->with(['type'])
|
||||
->orderByDesc('created_at')->get(),
|
||||
'activities' => $case->activities()->with(['action', 'decision'])
|
||||
->orderByDesc('created_at')
|
||||
->paginate(15),
|
||||
'contract_types' => \App\Models\ContractType::whereNull('deleted_at')->get(),
|
||||
'actions' => \App\Models\Action::with('decisions')->get()
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@@ -2,66 +2,84 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Person\Person;
|
||||
use Auth;
|
||||
use App\Models\Client;
|
||||
use DB;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
|
||||
class ClientController extends Controller
|
||||
{
|
||||
public function index(Person $person){
|
||||
public function index(Client $client, Request $request){
|
||||
return Inertia::render('Client/Index',[
|
||||
'persons' => $person::with(['group','type'])
|
||||
->selectRaw('person.*,(select count(id) from contracts where client_id=person.id) as contracts')
|
||||
->whereHas('group', fn($que) => $que->where('deleted','=',0))
|
||||
->whereHas('type', fn($que) => $que->where('deleted','=',0))
|
||||
->where([
|
||||
['person.active','=',1],
|
||||
['person.group_id','=',1]
|
||||
])->get(),
|
||||
'create_url' => route('client.store'),
|
||||
'person_types' => \App\Models\Person\PersonType::all(['id','name','description'])
|
||||
->where('deleted','=',0)
|
||||
'clients' => $client::query()
|
||||
->with('person')
|
||||
->when($request->input('search'), fn($que, $search) =>
|
||||
$que->whereHas(
|
||||
'person',
|
||||
fn($q) => $q->where('full_name', 'like', '%' . $search . '%')
|
||||
)
|
||||
)
|
||||
->where('active', 1)
|
||||
->orderByDesc('created_at')
|
||||
->paginate(15)
|
||||
->withQueryString(),
|
||||
'filters' => $request->only(['search'])
|
||||
]);
|
||||
}
|
||||
|
||||
public function show($uuid) {
|
||||
public function show(Client $client, Request $request) {
|
||||
|
||||
$data = $client::query()
|
||||
->with(['person' => fn($que) => $que->with('addresses')])
|
||||
->findOrFail($client->id);
|
||||
|
||||
return Inertia::render('Client/Show', [
|
||||
'client' => Person::with(['group','type','addresses','contracts'])->where('uuid', $uuid)->firstOrFail()
|
||||
'client' => $data,
|
||||
'client_cases' => $data->clientCases()
|
||||
->with('person')
|
||||
->when($request->input('search'), fn($que, $search) =>
|
||||
$que->whereHas(
|
||||
'person',
|
||||
fn($q) => $q->where('full_name', 'like', '%' . $search . '%')
|
||||
)
|
||||
)
|
||||
->where('active', 1)
|
||||
->orderByDesc('created_at')
|
||||
->paginate(15)
|
||||
->withQueryString(),
|
||||
'filters' => $request->only(['search'])
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$reqAddress = $request->input('address');
|
||||
$userId = Auth::user()->id;
|
||||
|
||||
$address = [
|
||||
'address' => $reqAddress['address'],
|
||||
'country' => $reqAddress['country'],
|
||||
'type_id' => $reqAddress['type_id'],
|
||||
'person_id' => 0,
|
||||
'user_id' => $userId
|
||||
];
|
||||
DB::transaction(function() use ($request){
|
||||
$address = $request->input('address');
|
||||
$person = \App\Models\Person\Person::create([
|
||||
'nu' => rand(100000,200000),
|
||||
'first_name' => $request->input('first_name'),
|
||||
'last_name' => $request->input('last_name'),
|
||||
'full_name' => $request->input('full_name'),
|
||||
'gender' => null,
|
||||
'birthday' => null,
|
||||
'tax_number' => null,
|
||||
'social_security_number' => null,
|
||||
'description' => 'sdwwf',
|
||||
'group_id' => 1,
|
||||
'type_id' => 2
|
||||
]);
|
||||
|
||||
$pid = Person::create([
|
||||
'nu' => rand(100000,200000),
|
||||
'first_name' => $request->input('first_name'),
|
||||
'last_name' => $request->input('last_name'),
|
||||
'full_name' => $request->input('full_name'),
|
||||
'gender' => null,
|
||||
'birthday' => null,
|
||||
'tax_number' => null,
|
||||
'social_security_number' => null,
|
||||
'description' => 'sdwwf',
|
||||
'group_id' => 1,
|
||||
'type_id' => 2,
|
||||
'user_id' => $userId
|
||||
])->id;
|
||||
$person->addresses()->create([
|
||||
'address' => $address['address'],
|
||||
'country' => $address['country'],
|
||||
'type_id' => $address['type_id']
|
||||
]);
|
||||
|
||||
$address['person_id'] = $pid;
|
||||
$person->client()->create();
|
||||
});
|
||||
|
||||
\App\Models\Person\PersonAddress::create($address);
|
||||
//\App\Models\Person\PersonAddress::create($address);
|
||||
|
||||
return to_route('client');
|
||||
|
||||
|
||||
@@ -2,60 +2,60 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Contract;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
|
||||
|
||||
class ContractController extends Controller
|
||||
{
|
||||
|
||||
public function index(Contract $contract) {
|
||||
return Inertia::render('Contract/Index', [
|
||||
'contracts' => $contract::with(['type', 'debtor'])
|
||||
->where('active', 1)
|
||||
->orderByDesc('created_at')
|
||||
->paginate(10),
|
||||
'person_types' => \App\Models\Person\PersonType::all(['id', 'name', 'description'])
|
||||
->where('deleted', 0)
|
||||
]);
|
||||
}
|
||||
|
||||
public function show(Contract $contract){
|
||||
return inertia('Contract/Show', [
|
||||
'contract' => $contract::with(['type', 'client', 'debtor'])->findOrFail($contract->id)
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$cuuid = $request->input('client_uuid');
|
||||
$userId = \Auth::user()->id;
|
||||
$pReqPer = $request->input('person');
|
||||
$pReqCont = $request->input('contract');
|
||||
|
||||
$cid = \DB::table('person')->where('uuid', $cuuid)->firstOrFail('id')->id;
|
||||
$uuid = $request->input('client_case_uuid');
|
||||
|
||||
$clientCase = \App\Models\ClientCase::where('uuid', $uuid)->firstOrFail();
|
||||
|
||||
|
||||
if(!empty($cid)){
|
||||
if( isset($clientCase->id) ){
|
||||
|
||||
$pid = \App\Models\Person\Person::create([
|
||||
'nu' => rand(100000,200000),
|
||||
'first_name' => $pReqPer['first_name'],
|
||||
'last_name' => $pReqPer['last_name'],
|
||||
'full_name' => $pReqPer['full_name'],
|
||||
'gender' => null,
|
||||
'birthday' => null,
|
||||
'tax_number' => null,
|
||||
'social_security_number' => null,
|
||||
'description' => 'sdwwf',
|
||||
'group_id' => 2,
|
||||
'type_id' => 1,
|
||||
'user_id' => $userId
|
||||
])->id;
|
||||
\DB::transaction(function() use ($request, $clientCase){
|
||||
|
||||
//Create contract
|
||||
$clientCase->contracts()->create([
|
||||
'reference' => $request->input('reference'),
|
||||
'start_date' => date('Y-m-d', strtotime($request->input('start_date'))),
|
||||
'type_id' => $request->input('type_id')
|
||||
]);
|
||||
|
||||
$address = [
|
||||
'address' => $pReqPer['address']['address'],
|
||||
'country' => $pReqPer['address']['country'],
|
||||
'type_id' => $pReqPer['address']['type_id'],
|
||||
'person_id' => $pid,
|
||||
'user_id' => $userId
|
||||
];
|
||||
|
||||
$contract = [
|
||||
'reference' => $pReqCont['reference'],
|
||||
'start_date' => date('Y-m-d', strtotime($pReqCont['start_date'])),
|
||||
'client_id' => $cid,
|
||||
'debtor_id' => $pid,
|
||||
'type_id' => $pReqCont['type_id']
|
||||
];
|
||||
|
||||
\App\Models\Person\PersonAddress::create($address);
|
||||
\App\Models\Contract::create($contract);
|
||||
});
|
||||
}
|
||||
|
||||
return to_route('client.show', ['uuid' => $cuuid]);
|
||||
return to_route('clientCase.show', $clientCase);
|
||||
}
|
||||
|
||||
public function update(Contract $contract, Request $request){
|
||||
$contract->update([
|
||||
'referenca' => $request->input('referenca'),
|
||||
'type_id' => $request->input('type_id')
|
||||
]);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
|
||||
class SettingController extends Controller
|
||||
{
|
||||
//
|
||||
|
||||
public function index(Request $request){
|
||||
|
||||
return Inertia::render('Settings/Index', [
|
||||
'actions' => \App\Models\Action::query()
|
||||
->with('decisions', fn($q) => $q->get(['decisions.id']))
|
||||
->get(),
|
||||
'decisions' => \App\Models\Decision::query()
|
||||
->with('actions', fn($q) => $q->get(['actions.id']))
|
||||
->get()
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
|
||||
class Action extends Model
|
||||
{
|
||||
/** @use HasFactory<\Database\Factories\ActionFactory> */
|
||||
use HasFactory;
|
||||
|
||||
public function decisions(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(\App\Models\Decision::class);
|
||||
}
|
||||
|
||||
public function segment(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(\App\Models\Segment::class);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Activity extends Model
|
||||
{
|
||||
/** @use HasFactory<\Database\Factories\ActivityFactory> */
|
||||
use HasFactory;
|
||||
use SoftDeletes;
|
||||
|
||||
protected $fillable = [
|
||||
'due_date',
|
||||
'amount',
|
||||
'note',
|
||||
'action_id',
|
||||
'decision_id'
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'action_id',
|
||||
'decision_id',
|
||||
'client_case_id',
|
||||
'contract_id'
|
||||
];
|
||||
|
||||
public function action(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(\App\Models\Action::class);
|
||||
}
|
||||
|
||||
public function decision(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(\App\Models\Decision::class);
|
||||
}
|
||||
|
||||
public function clientCase(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(\App\Models\ClientCase::class);
|
||||
}
|
||||
|
||||
public function contract(): BelongsTo|null
|
||||
{
|
||||
return $this->belongsTo(\App\Models\Contract::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Traits\Uuid;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Client extends Model
|
||||
{
|
||||
/** @use HasFactory<\Database\Factories\ClientFactory> */
|
||||
use HasFactory;
|
||||
use Uuid;
|
||||
|
||||
protected $fillable = [
|
||||
'person_id'
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'id',
|
||||
'person_id',
|
||||
];
|
||||
|
||||
public function person(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(\App\Models\Person\Person::class);
|
||||
}
|
||||
|
||||
public function clientCases(): HasMany
|
||||
{
|
||||
return $this->hasMany(\App\Models\ClientCase::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Traits\Uuid;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class ClientCase extends Model
|
||||
{
|
||||
/** @use HasFactory<\Database\Factories\ClientCaseFactory> */
|
||||
use HasFactory;
|
||||
use Uuid;
|
||||
|
||||
protected $fillable = [
|
||||
'client_id'
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'id',
|
||||
'client_id',
|
||||
'person_id'
|
||||
];
|
||||
|
||||
public function client(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(\App\Models\Client::class);
|
||||
}
|
||||
|
||||
public function person(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(\App\Models\Person\Person::class);
|
||||
}
|
||||
|
||||
public function contracts(): HasMany
|
||||
{
|
||||
return $this->hasMany(\App\Models\Contract::class);
|
||||
}
|
||||
|
||||
public function activities(): HasMany
|
||||
{
|
||||
return $this->hasMany(\App\Models\Activity::class);
|
||||
}
|
||||
}
|
||||
+10
-4
@@ -7,26 +7,27 @@
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Contract extends Model
|
||||
{
|
||||
/** @use HasFactory<\Database\Factories\ContractFactory> */
|
||||
use HasFactory;
|
||||
use Uuid;
|
||||
use SoftDeletes;
|
||||
|
||||
protected $fillable = [
|
||||
'reference',
|
||||
'start_date',
|
||||
'end_date',
|
||||
'client_id',
|
||||
'debtor_id',
|
||||
'client_case_id',
|
||||
'type_id',
|
||||
'description'
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'client_id',
|
||||
'debtor_id',
|
||||
'id',
|
||||
'client_case_id',
|
||||
'type_id'
|
||||
];
|
||||
|
||||
@@ -35,6 +36,11 @@ public function type(): BelongsTo
|
||||
return $this->belongsTo(\App\Models\ContractType::class, 'type_id');
|
||||
}
|
||||
|
||||
public function client(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(\App\Models\Person\Person::class, 'client_id');
|
||||
}
|
||||
|
||||
public function debtor(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(\App\Models\Person\Person::class, 'debtor_id');
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Decision extends Model
|
||||
{
|
||||
/** @use HasFactory<\Database\Factories\DecisionFactory> */
|
||||
use HasFactory;
|
||||
|
||||
public function actions(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(\App\Models\Action::class);
|
||||
}
|
||||
|
||||
public function events(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(\App\Models\Event::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Event extends Model
|
||||
{
|
||||
/** @use HasFactory<\Database\Factories\EventFactory> */
|
||||
use HasFactory;
|
||||
}
|
||||
@@ -7,6 +7,7 @@
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
|
||||
class Person extends Model
|
||||
@@ -43,6 +44,14 @@ class Person extends Model
|
||||
'user_id'
|
||||
];
|
||||
|
||||
protected static function booted(){
|
||||
static::creating(function (Person $person) {
|
||||
if(!isset($person->user_id)){
|
||||
$person->user_id = auth()->id();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public function phones(): HasMany
|
||||
{
|
||||
@@ -68,16 +77,14 @@ public function type(): BelongsTo
|
||||
return $this->belongsTo(\App\Models\Person\PersonType::class, 'type_id');
|
||||
}
|
||||
|
||||
public function contracts(): HasMany
|
||||
public function client(): HasOne
|
||||
{
|
||||
return $this->hasMany(\App\Models\Contract::class, 'client_id')
|
||||
->with('debtor', fn($que) =>
|
||||
$que->with(['type', 'group'])
|
||||
->whereHas('type', fn($tque) => $tque->where('deleted','=',0))
|
||||
->whereHas('group', fn($tque) => $tque->where('deleted','=',0))
|
||||
->where('active','=',1))
|
||||
->with('type', fn($que) => $que->where('deleted','=',0))
|
||||
->where('active', '=', 1);
|
||||
return $this->hasOne(\App\Models\Client::class);
|
||||
}
|
||||
|
||||
public function clientCase(): HasOne
|
||||
{
|
||||
return $this->hasOne(\App\Models\ClientCase::class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,6 +26,12 @@ class PersonAddress extends Model
|
||||
'deleted'
|
||||
];
|
||||
|
||||
protected static function booted(){
|
||||
static::creating(function (PersonAddress $address) {
|
||||
$address->user_id = auth()->id();
|
||||
});
|
||||
}
|
||||
|
||||
public function person(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(\App\Models\Person\Person::class);
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Illuminate\Foundation\Application;
|
||||
use Inertia\Inertia;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
@@ -12,6 +14,10 @@ class AppServiceProvider extends ServiceProvider
|
||||
public function register(): void
|
||||
{
|
||||
//
|
||||
Inertia::share([
|
||||
'laravelVersion' => Application::VERSION,
|
||||
'phpVersion' => PHP_VERSION
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user