Lots of changes
This commit is contained in:
@@ -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()
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user