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