mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/unity.git
synced 2026-08-19 04:13:58 +00:00
contract generate
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\User\Api;
|
||||
|
||||
use Auth;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
use App\Http\Modules\User\ContractModule;
|
||||
|
||||
use App\Http\Controllers\User\BaseController;
|
||||
|
||||
class ContractController extends BaseController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function list(Request $request)
|
||||
{
|
||||
$contract = ContractModule::list($request);
|
||||
return $contract;
|
||||
}
|
||||
|
||||
public function show(Request $request, $hash_id)
|
||||
{
|
||||
$contract = ContractModule::show($request, $hash_id);
|
||||
return $contract;
|
||||
}
|
||||
|
||||
public function generate(Request $request)
|
||||
{
|
||||
$contract = ContractModule::generate($request);
|
||||
return $contract;
|
||||
}
|
||||
|
||||
public function update(Request $request, $hash_id)
|
||||
{
|
||||
$contract = ContractModule::update($request, $hash_id);
|
||||
return $contract;
|
||||
}
|
||||
|
||||
public function delete(Request $request, $hash_id)
|
||||
{
|
||||
$contract = ContractModule::delete($request, $hash_id);
|
||||
return $contract;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,272 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Modules\User;
|
||||
|
||||
use Auth;
|
||||
use App\Models\Contract;
|
||||
use App\Models\ContractLog;
|
||||
use App\Models\ContractTemplate;
|
||||
use App\Models\ContractObligation;
|
||||
|
||||
use App\Http\Modules\User\ContractObligationModule;
|
||||
use App\Http\Modules\User\ContractObligationDependencyModule;
|
||||
|
||||
use App\Http\Rules\User\UnderCheck;
|
||||
use App\Http\Rules\User\ExistCheck;
|
||||
|
||||
use App\Http\Helpers\General;
|
||||
use App\Http\Helpers\Hasher;
|
||||
use Carbon\Carbon;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
use App\Http\Controllers\User\BaseController;
|
||||
|
||||
class ContractModule extends BaseController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public static function list(Request $request)
|
||||
{
|
||||
General::storeCachePerviousQuery($request->query(), 'contract_query');
|
||||
|
||||
$name = $request->get('name', null);
|
||||
$status = $request->get('status', []);
|
||||
$page = $request->get('page', null);
|
||||
$limit = $request->get('limit', 10);
|
||||
|
||||
$query = Contract::query();
|
||||
|
||||
if (strlen($name) > 0) {
|
||||
$query->where('name', 'like', '%' . $name . '%');
|
||||
}
|
||||
|
||||
if (!empty($status) > 0) {
|
||||
$query->whereIn('status', $status);
|
||||
}
|
||||
|
||||
$query->where('user_id', Auth::guard('user-api')->user()->id);
|
||||
|
||||
$query->orderBy('id', 'desc');
|
||||
|
||||
$params = [
|
||||
'name' => $name,
|
||||
'status' => $status,
|
||||
'page' => $page
|
||||
];
|
||||
|
||||
$contract_list = $query->paginate($limit);
|
||||
|
||||
$extract = [];
|
||||
foreach ($contract_list as $key => $row) {
|
||||
$extract[] = $row;
|
||||
|
||||
}
|
||||
$pagination = General::paginationGenerator($contract_list, $params, $extract);
|
||||
|
||||
return $pagination;
|
||||
}
|
||||
|
||||
public static function show(Request $request, $hash_id)
|
||||
{
|
||||
$id = Hasher::decode('contracts', $hash_id);
|
||||
$user_id = Auth::guard('user-api')->user()->id;
|
||||
$contract = Contract::
|
||||
where('id', $id)
|
||||
->where('user_id', $user_id)
|
||||
->first();
|
||||
if ($contract) {
|
||||
$data = General::returnData($contract, '');
|
||||
return response()->json($data);
|
||||
}
|
||||
$data = General::returnNotFoundData();
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
public static function generate(Request $request)
|
||||
{
|
||||
$validation = ContractModule::validation($request);
|
||||
if (!$validation->status) {
|
||||
return response()->json($validation, 422);
|
||||
}
|
||||
|
||||
DB::beginTransaction();
|
||||
|
||||
$contract_template_id = $request->input('contract_template_id');
|
||||
$contract_template_id = Hasher::decode('contract_templates', $contract_template_id[0]);
|
||||
$contarct_template = ContractTemplate::find($contract_template_id);
|
||||
|
||||
$contract = new Contract();
|
||||
$contract->user_id = Auth::guard('user-api')->user()->id;
|
||||
$contract->contract_template_id = $contarct_template->id;
|
||||
$contract->name = $contarct_template->name;
|
||||
$contract->in_time_contract_template = json_encode($contarct_template);
|
||||
$contract->status = config('constants.contact.status.pending');
|
||||
$contract->save();
|
||||
|
||||
// generate contract obligation
|
||||
$contract_template_obligation_list = $contarct_template->contract_template_obligation()
|
||||
->orderBy('sequence', 'asc')
|
||||
->where('status', config('constants.contract_template_obligation.status.active'))
|
||||
->get();
|
||||
|
||||
foreach ($contract_template_obligation_list as $key => $row) {
|
||||
$request->request->add([
|
||||
'contract_template_obligation_id' => [$row->hash_id],
|
||||
'contract_id' => [$contract->hash_id]
|
||||
]);
|
||||
|
||||
$contract_obligation = ContractObligationModule::generate($request);
|
||||
}
|
||||
|
||||
// generate contract dependency
|
||||
foreach ($contract_template_obligation_list as $key => $row) {
|
||||
$contract_template_obligation_dependency = $row->contract_template_obligation_dependency()
|
||||
->where('status', config('constants.contract_template_obligation_dependency.status.active'))
|
||||
->get();
|
||||
|
||||
if (!empty($contract_template_obligation_dependency[0])) {
|
||||
$contract_obligation = ContractObligation::
|
||||
where('contract_id', $contract->id)
|
||||
->where('contract_template_obligation_id', $contract_template_obligation_dependency[0]->contract_template_obligation_id)
|
||||
->first();
|
||||
|
||||
$depend_contract_obligation = ContractObligation::
|
||||
where('contract_id', $contract->id)
|
||||
->where('contract_template_obligation_id', $contract_template_obligation_dependency[0]->depend_contract_template_obligation_id)
|
||||
->first();
|
||||
|
||||
$request->request->add([
|
||||
'contract_obligation_id' => [$contract_obligation->hash_id],
|
||||
'depend_contract_obligation_id' => [$depend_contract_obligation->hash_id]
|
||||
]);
|
||||
$contract_obligation_dependency = ContractObligationDependencyModule::generate($request);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// log
|
||||
ContractModule::makeLog($contract->id, 'user (' . Auth::guard('user-api')->user()->id . ') created');
|
||||
|
||||
// DB::commit();
|
||||
|
||||
$query_string = General::getCachePerviousQuery('contract_query');
|
||||
$data = General::returnData($contract, $query_string);
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
public static function update(Request $request, $hash_id)
|
||||
{
|
||||
$id = Hasher::decode('contracts', $hash_id);
|
||||
$validation = ContractModule::validation($request, $hash_id, 'PUT');
|
||||
if (!$validation->status) {
|
||||
return response()->json($validation, 422);
|
||||
}
|
||||
|
||||
DB::beginTransaction();
|
||||
|
||||
$name = $request->input('name');
|
||||
$complete_day_range = $request->input('complete_day_range');
|
||||
|
||||
$contract = Contract::find($id);
|
||||
$contract->name = $name ?? $contract->name;
|
||||
$contract->complete_day_range = $complete_day_range ?? $contract->complete_day_range;
|
||||
$contract->update();
|
||||
|
||||
|
||||
|
||||
|
||||
// log
|
||||
ContractModule::makeLog($contract->id, 'user (' . Auth::guard('user-api')->user()->id . ') updated');
|
||||
|
||||
DB::commit();
|
||||
|
||||
$query_string = General::getCachePerviousQuery('contract_query');
|
||||
$data = General::returnData($contract, $query_string);
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
public static function delete(Request $request, $hash_id)
|
||||
{
|
||||
$id = Hasher::decode('contracts', $hash_id);
|
||||
$validation = ContractModule::validation($request, $hash_id, 'DEL');
|
||||
if (!$validation->status) {
|
||||
return response()->json($validation, 422);
|
||||
}
|
||||
|
||||
DB::beginTransaction();
|
||||
|
||||
$contract = Contract::find($id);
|
||||
$contract->status = config('constants.contact_template.status.delete');
|
||||
$contract->update();
|
||||
|
||||
// log
|
||||
ContractModule::makeLog($contract->id, 'user (' . Auth::guard('user-api')->user()->id . ') delete');
|
||||
|
||||
DB::commit();
|
||||
|
||||
$query_string = General::getCachePerviousQuery('contract_query');
|
||||
$data = General::returnData($contract, $query_string);
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
|
||||
private static function validation(Request $request, $id = '', $method = 'POST')
|
||||
{
|
||||
$data = $request->all();
|
||||
$rule= [];
|
||||
|
||||
if ($method == 'POST') {
|
||||
$rule = [
|
||||
'contract_template_id' => ['required', new UnderCheck('contract_template'), new ExistCheck('contract_template')]
|
||||
];
|
||||
}
|
||||
|
||||
if ($method == 'PUT') {
|
||||
$data['id'] = $id;
|
||||
$rule = [
|
||||
'id' => [new UnderCheck('contract'), new ExistCheck('contract')],
|
||||
'name' => 'required',
|
||||
'complete_day_range' => 'required|numeric|gt:-1'
|
||||
];
|
||||
}
|
||||
|
||||
if ($method == 'DEL') {
|
||||
$data['id'] = $id;
|
||||
$rule = [
|
||||
'id' => [new UnderCheck('contract'), new ExistCheck('contract')],
|
||||
];
|
||||
}
|
||||
|
||||
$validator = Validator::make($data, $rule, config('error_code'));
|
||||
|
||||
$errors = $validator->errors();
|
||||
|
||||
if ($validator->fails()) {
|
||||
$data = General::returnErrorData($errors);
|
||||
return $data;
|
||||
}
|
||||
else {
|
||||
return (object)['status' => true];
|
||||
}
|
||||
}
|
||||
|
||||
public static function makeLog($id = '', $remark = '')
|
||||
{
|
||||
$contract = Contract::find($id);
|
||||
$contract_log = new ContractLog();
|
||||
$contract_log->contract_id = $contract->id;
|
||||
$contract_log->history = json_encode($contract);
|
||||
$contract_log->remark = $remark;
|
||||
$contract_log->save();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Modules\User;
|
||||
|
||||
use Auth;
|
||||
use App\Models\ContractObligationDependency;
|
||||
use App\Models\ContractObligation;
|
||||
|
||||
use App\Http\Modules\User\ContractObligationModule;
|
||||
|
||||
use App\Http\Rules\User\UnderCheck;
|
||||
use App\Http\Rules\User\ExistCheck;
|
||||
|
||||
use App\Http\Helpers\General;
|
||||
use App\Http\Helpers\Hasher;
|
||||
use Carbon\Carbon;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
use App\Http\Controllers\User\BaseController;
|
||||
|
||||
class ContractObligationDependencyModule extends BaseController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public static function list(Request $request)
|
||||
{
|
||||
General::storeCachePerviousQuery($request->query(), 'contract_query');
|
||||
|
||||
$name = $request->get('name', null);
|
||||
$status = $request->get('status', []);
|
||||
$page = $request->get('page', null);
|
||||
$limit = $request->get('limit', 10);
|
||||
|
||||
$query = ContractObligationDependency::query();
|
||||
|
||||
if (strlen($name) > 0) {
|
||||
$query->where('name', 'like', '%' . $name . '%');
|
||||
}
|
||||
|
||||
if (!empty($status) > 0) {
|
||||
$query->whereIn('status', $status);
|
||||
}
|
||||
|
||||
$query->where('user_id', Auth::guard('user-api')->user()->id);
|
||||
|
||||
$query->orderBy('id', 'desc');
|
||||
|
||||
$params = [
|
||||
'name' => $name,
|
||||
'status' => $status,
|
||||
'page' => $page
|
||||
];
|
||||
|
||||
$contract_list = $query->paginate($limit);
|
||||
|
||||
$extract = [];
|
||||
foreach ($contract_list as $key => $row) {
|
||||
$extract[] = $row;
|
||||
|
||||
}
|
||||
$pagination = General::paginationGenerator($contract_list, $params, $extract);
|
||||
|
||||
return $pagination;
|
||||
}
|
||||
|
||||
public static function show(Request $request, $hash_id)
|
||||
{
|
||||
$id = Hasher::decode('contracts', $hash_id);
|
||||
$user_id = Auth::guard('user-api')->user()->id;
|
||||
$contract = Contract::
|
||||
where('id', $id)
|
||||
->where('user_id', $user_id)
|
||||
->first();
|
||||
if ($contract) {
|
||||
$data = General::returnData($contract, '');
|
||||
return response()->json($data);
|
||||
}
|
||||
$data = General::returnNotFoundData();
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
public static function generate(Request $request)
|
||||
{
|
||||
$validation = ContractObligationDependencyModule::validation($request);
|
||||
if (!$validation->status) {
|
||||
return response()->json($validation, 422);
|
||||
}
|
||||
|
||||
DB::beginTransaction();
|
||||
|
||||
$contract_obligation_id = $request->input('contract_obligation_id');
|
||||
$contract_obligation_id = Hasher::decode('contract_obligations', $contract_obligation_id[0]);
|
||||
$contract_obligation = ContractObligation::find($contract_obligation_id);
|
||||
|
||||
$depend_contract_obligation_id = $request->input('depend_contract_obligation_id');
|
||||
$depend_contract_obligation_id = Hasher::decode('contract_obligations', $depend_contract_obligation_id[0]);
|
||||
$depend_contract_obligation = ContractObligation::find($depend_contract_obligation_id);
|
||||
|
||||
$contract_obligation_dependency = new ContractObligationDependency();
|
||||
$contract_obligation_dependency->user_id = Auth::guard('user-api')->user()->id;
|
||||
$contract_obligation_dependency->contract_obligation_id = $contract_obligation->id;
|
||||
$contract_obligation_dependency->depend_contract_obligation_id = $depend_contract_obligation->id;
|
||||
$contract_obligation_dependency->status = config('constants.contract_dependency.status.active');
|
||||
$contract_obligation_dependency->save();
|
||||
|
||||
// log
|
||||
ContractObligationModule::makeLog($contract_obligation->id, 'user (' . Auth::guard('user-api')->user()->id . ') created dependency');
|
||||
|
||||
DB::commit();
|
||||
|
||||
$query_string = General::getCachePerviousQuery('contract_query');
|
||||
$data = General::returnData($contract_obligation, $query_string);
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
private static function validation(Request $request, $id = '', $method = 'POST')
|
||||
{
|
||||
$data = $request->all();
|
||||
$rule= [];
|
||||
|
||||
if ($method == 'POST') {
|
||||
|
||||
}
|
||||
|
||||
if ($method == 'PUT') {
|
||||
|
||||
}
|
||||
|
||||
if ($method == 'DEL') {
|
||||
$data['id'] = $id;
|
||||
$rule = [
|
||||
'id' => [new UnderCheck('contract'), new ExistCheck('contract')],
|
||||
];
|
||||
}
|
||||
|
||||
$validator = Validator::make($data, $rule, config('error_code'));
|
||||
|
||||
$errors = $validator->errors();
|
||||
|
||||
if ($validator->fails()) {
|
||||
$data = General::returnErrorData($errors);
|
||||
return $data;
|
||||
}
|
||||
else {
|
||||
return (object)['status' => true];
|
||||
}
|
||||
}
|
||||
|
||||
public static function makeLog($id = '', $remark = '')
|
||||
{
|
||||
$contract_obligation = ContractObligation::find($id);
|
||||
$contract_obligation_log = new ContractObligationLog();
|
||||
$contract_obligation_log->contract_obligation_id = $contract_obligation->id;
|
||||
$contract_obligation_log->history = json_encode($contract_obligation);
|
||||
$contract_obligation_log->remark = $remark;
|
||||
$contract_obligation_log->save();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Modules\User;
|
||||
|
||||
use Auth;
|
||||
use App\Models\ContractObligation;
|
||||
use App\Models\ContractObligationLog;
|
||||
use App\Models\Contract;
|
||||
use App\Models\ContractTemplateObligation;
|
||||
|
||||
use App\Http\Helpers\General;
|
||||
use App\Http\Helpers\Hasher;
|
||||
use Carbon\Carbon;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
use App\Http\Controllers\User\BaseController;
|
||||
|
||||
class ContractObligationModule extends BaseController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public static function list(Request $request)
|
||||
{
|
||||
General::storeCachePerviousQuery($request->query(), 'contract_query');
|
||||
|
||||
$name = $request->get('name', null);
|
||||
$status = $request->get('status', []);
|
||||
$page = $request->get('page', null);
|
||||
$limit = $request->get('limit', 10);
|
||||
|
||||
$query = Contract::query();
|
||||
|
||||
if (strlen($name) > 0) {
|
||||
$query->where('name', 'like', '%' . $name . '%');
|
||||
}
|
||||
|
||||
if (!empty($status) > 0) {
|
||||
$query->whereIn('status', $status);
|
||||
}
|
||||
|
||||
$query->where('user_id', Auth::guard('user-api')->user()->id);
|
||||
|
||||
$query->orderBy('id', 'desc');
|
||||
|
||||
$params = [
|
||||
'name' => $name,
|
||||
'status' => $status,
|
||||
'page' => $page
|
||||
];
|
||||
|
||||
$contract_list = $query->paginate($limit);
|
||||
|
||||
$extract = [];
|
||||
foreach ($contract_list as $key => $row) {
|
||||
$extract[] = $row;
|
||||
|
||||
}
|
||||
$pagination = General::paginationGenerator($contract_list, $params, $extract);
|
||||
|
||||
return $pagination;
|
||||
}
|
||||
|
||||
public static function show(Request $request, $hash_id)
|
||||
{
|
||||
$id = Hasher::decode('contracts', $hash_id);
|
||||
$user_id = Auth::guard('user-api')->user()->id;
|
||||
$contract = Contract::
|
||||
where('id', $id)
|
||||
->where('user_id', $user_id)
|
||||
->first();
|
||||
if ($contract) {
|
||||
$data = General::returnData($contract, '');
|
||||
return response()->json($data);
|
||||
}
|
||||
$data = General::returnNotFoundData();
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
public static function generate(Request $request)
|
||||
{
|
||||
$validation = ContractObligationModule::validation($request);
|
||||
if (!$validation->status) {
|
||||
return response()->json($validation, 422);
|
||||
}
|
||||
|
||||
DB::beginTransaction();
|
||||
|
||||
$contract_id = $request->input('contract_id');
|
||||
$contract_id = Hasher::decode('contracts', $contract_id[0]);
|
||||
$contract = Contract::find($contract_id);
|
||||
|
||||
$contract_template_obligation_id = $request->input('contract_template_obligation_id');
|
||||
$contract_template_obligation_id = Hasher::decode('contract_template_obligations', $contract_template_obligation_id[0]);
|
||||
$contract_template_obligation = ContractTemplateObligation::find($contract_template_obligation_id);
|
||||
|
||||
$contract_obligation = new ContractObligation();
|
||||
$contract_obligation->user_id = Auth::guard('user-api')->user()->id;
|
||||
$contract_obligation->contract_id = $contract->id;
|
||||
$contract_obligation->contract_template_obligation_id = $contract_template_obligation->id;
|
||||
$contract_obligation->name = $contract_template_obligation->name;
|
||||
$contract_obligation->content = json_encode($contract_template_obligation->content);
|
||||
$contract_obligation->must_complete = $contract_template_obligation->must_complete;
|
||||
$contract_obligation->must_accept = $contract_template_obligation->must_accept;
|
||||
$contract_obligation->in_time_contract_obligation_template = json_encode($contract_template_obligation);
|
||||
$contract_obligation->type = $contract_template_obligation->type;
|
||||
$contract_obligation->status = config('constants.contact.status.pending');
|
||||
$contract_obligation->save();
|
||||
|
||||
// log
|
||||
ContractObligationModule::makeLog($contract_obligation->id, 'user (' . Auth::guard('user-api')->user()->id . ') created');
|
||||
|
||||
DB::commit();
|
||||
|
||||
$query_string = General::getCachePerviousQuery('contract_query');
|
||||
$data = General::returnData($contract, $query_string);
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
private static function validation(Request $request, $id = '', $method = 'POST')
|
||||
{
|
||||
$data = $request->all();
|
||||
$rule= [];
|
||||
|
||||
if ($method == 'POST') {
|
||||
|
||||
}
|
||||
|
||||
if ($method == 'PUT') {
|
||||
|
||||
}
|
||||
|
||||
if ($method == 'DEL') {
|
||||
$data['id'] = $id;
|
||||
$rule = [
|
||||
'id' => [new UnderCheck('contract_obligation'), new ExistCheck('contract_obligation')],
|
||||
];
|
||||
}
|
||||
|
||||
$validator = Validator::make($data, $rule, config('error_code'));
|
||||
|
||||
$errors = $validator->errors();
|
||||
|
||||
if ($validator->fails()) {
|
||||
$data = General::returnErrorData($errors);
|
||||
return $data;
|
||||
}
|
||||
else {
|
||||
return (object)['status' => true];
|
||||
}
|
||||
}
|
||||
|
||||
public static function makeLog($id = '', $remark = '')
|
||||
{
|
||||
$contract_obligation = ContractObligation::find($id);
|
||||
$contract_obligation_log = new ContractObligationLog();
|
||||
$contract_obligation_log->contract_obligation_id = $contract_obligation->id;
|
||||
$contract_obligation_log->history = json_encode($contract_obligation);
|
||||
$contract_obligation_log->remark = $remark;
|
||||
$contract_obligation_log->save();
|
||||
}
|
||||
}
|
||||
@@ -70,7 +70,10 @@ class ContractTemplateModule extends BaseController
|
||||
public static function show(Request $request, $hash_id)
|
||||
{
|
||||
$id = Hasher::decode('contract_templates', $hash_id);
|
||||
$contract_template = ContractTemplate::find($id);
|
||||
$contract_template = ContractTemplate::
|
||||
where('id', $id)
|
||||
->where('user_id', $user_id)
|
||||
->first();
|
||||
if ($contract_template) {
|
||||
$data = General::returnData($contract_template, '');
|
||||
return response()->json($data);
|
||||
|
||||
+35
-2
@@ -2,10 +2,43 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use App\Http\Helpers\Hasher;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class Contract extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
protected $table = 'contracts';
|
||||
|
||||
protected $appends = ['hash_id', 'contract_obligation_list'];
|
||||
|
||||
protected $hidden = [
|
||||
'id', 'in_time_contract_template',
|
||||
];
|
||||
|
||||
public function contract_obligation()
|
||||
{
|
||||
return $this->hasMany('App\Models\ContractObligation', 'contract_id');
|
||||
}
|
||||
|
||||
public function getHashIdAttribute()
|
||||
{
|
||||
return Hasher::encode('contracts', $this->id);
|
||||
}
|
||||
|
||||
public function getContractObligationListAttribute()
|
||||
{
|
||||
return $this->contract_obligation()->get()->makeHidden(['contract_list']);
|
||||
}
|
||||
|
||||
public function getUpdatedAtAttribute($date)
|
||||
{
|
||||
return $date ? Carbon::parse($date)->timezone('Asia/Kuala_Lumpur')->format('Y-m-d') : '';
|
||||
}
|
||||
|
||||
public function getCreatedAtAttribute($date)
|
||||
{
|
||||
return $date ? Carbon::parse($date)->timezone('Asia/Kuala_Lumpur')->format('Y-m-d') : '';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,10 +2,72 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use App\Http\Helpers\Hasher;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class ContractObligation extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
protected $table = 'contract_obligations';
|
||||
|
||||
protected $appends = [
|
||||
'hash_id',
|
||||
'contract_list',
|
||||
'contract_obligation_dependency_list',
|
||||
'depend_contract_obligation_dependency_list'
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'id', 'in_time_contract_obligation_template',
|
||||
];
|
||||
|
||||
public function contract()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Contract', 'contract_id');
|
||||
}
|
||||
|
||||
public function contract_obligation_dependency()
|
||||
{
|
||||
return $this->hasMany('App\Models\ContractObligationDependency', 'contract_obligation_id');
|
||||
}
|
||||
|
||||
public function depend_contract_obligation_dependency()
|
||||
{
|
||||
return $this->hasMany('App\Models\ContractObligationDependency', 'depend_contract_obligation_id');
|
||||
}
|
||||
|
||||
public function getHashIdAttribute()
|
||||
{
|
||||
return Hasher::encode('contract_obligations', $this->id);
|
||||
}
|
||||
|
||||
public function getContractListAttribute()
|
||||
{
|
||||
return $this->contract()->get()->makeHidden(['contract_obligation_list']);
|
||||
}
|
||||
|
||||
public function getContractObligationDependencyListAttribute()
|
||||
{
|
||||
return $this->contract_obligation_dependency()
|
||||
->where('status', config('constants.contract_obligation.status.active'))
|
||||
->get()->makeHidden(['contract_obligation_list', 'depend_contract_obligation_list']);
|
||||
}
|
||||
|
||||
public function getDependContractObligationDependencyListAttribute()
|
||||
{
|
||||
return $this->depend_contract_obligation_dependency()
|
||||
->where('status', config('constants.contract_obligation.status.active'))
|
||||
->get()->makeHidden(['contract_obligation_list', 'depend_contract_obligation_list']);
|
||||
}
|
||||
|
||||
public function getUpdatedAtAttribute($date)
|
||||
{
|
||||
return $date ? Carbon::parse($date)->timezone('Asia/Kuala_Lumpur')->format('Y-m-d') : '';
|
||||
}
|
||||
|
||||
public function getCreatedAtAttribute($date)
|
||||
{
|
||||
return $date ? Carbon::parse($date)->timezone('Asia/Kuala_Lumpur')->format('Y-m-d') : '';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,11 @@ class ContractTemplate extends Model
|
||||
|
||||
public function getContractTemplateObligationListAttribute()
|
||||
{
|
||||
return $this->contract_template_obligation()->get()->makeHidden(['contract_template_list']);
|
||||
return $this->contract_template_obligation()
|
||||
->orderBy('sequence', 'asc')
|
||||
->where('status', config('constants.contract_template_obligation.status.active'))
|
||||
->get()
|
||||
->makeHidden(['contract_template_list']);
|
||||
}
|
||||
|
||||
public function getUpdatedAtAttribute($date)
|
||||
|
||||
@@ -69,7 +69,7 @@ class ContractTemplateObligation extends Model
|
||||
|
||||
public function getContractTemplateObligationDependencyStructure($contract_template_obligation_id = [], $contract_template_obligation_id_structure = [])
|
||||
{
|
||||
$contract_template_obligation_id = Hasher::decode('contract_template_obligations', $contract_template_obligation_id[0]);
|
||||
$contract_template_obligation_id = !empty($contract_template_obligation_id) ? Hasher::decode('contract_template_obligations', $contract_template_obligation_id[0]) : $this->id;
|
||||
$contract_template_obligation = ContractTemplateObligation::find($contract_template_obligation_id);
|
||||
|
||||
if (!empty($contract_template_obligation->contract_template_obligation_dependency_list)) {
|
||||
|
||||
+15
-1
@@ -39,6 +39,13 @@
|
||||
'pending' => 9
|
||||
]
|
||||
],
|
||||
'contact' => [
|
||||
'status' => [
|
||||
'active' => 1,
|
||||
'delete' => 2,
|
||||
'pending' => 9
|
||||
]
|
||||
],
|
||||
'contract_obligation' => [
|
||||
'complete_status' => [
|
||||
'pending' => 9,
|
||||
@@ -54,5 +61,12 @@
|
||||
'offer_service' => 2,
|
||||
'received_service' => 3,
|
||||
]
|
||||
]
|
||||
],
|
||||
'contract_dependency' => [
|
||||
'status' => [
|
||||
'active' => 1,
|
||||
'delete' => 2,
|
||||
'pending' => 9
|
||||
]
|
||||
],
|
||||
];
|
||||
@@ -11,6 +11,7 @@
|
||||
'required_if' => 'REQUIRED',
|
||||
'email' => 'EMAIL_ERROR',
|
||||
'unique' => 'UNIQUE_ERRO',
|
||||
'date' => 'DATE_INVALID',
|
||||
'confirmed' => 'CONFIRM_ERROR',
|
||||
'obligation_depend_error' => 'OBLIGATION_DEPEND_ERROR',
|
||||
'min' => [
|
||||
|
||||
@@ -19,9 +19,12 @@ class CreateContractObligationsTable extends Migration
|
||||
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
|
||||
$table->bigInteger('contract_id')->unsigned()->nullable();
|
||||
$table->foreign('contract_id')->references('id')->on('contracts')->onDelete('cascade');
|
||||
$table->bigInteger('contract_template_obligation_id')->unsigned()->nullable();
|
||||
$table->foreign('contract_template_obligation_id', 'co_cto_id')->references('id')->on('contract_template_obligations')->onDelete('cascade');
|
||||
$table->bigInteger('contract_entity_id')->unsigned()->nullable();
|
||||
$table->foreign('contract_entity_id')->references('id')->on('contract_entities')->onDelete('cascade');
|
||||
$table->string('name')->nullable();
|
||||
$table->float('sequence', 4, 2)->nullable();
|
||||
$table->string('reference')->nullable();
|
||||
$table->json('content')->nullable();
|
||||
$table->integer('must_complete')->nullable()->default(1);
|
||||
@@ -29,6 +32,7 @@ class CreateContractObligationsTable extends Migration
|
||||
$table->integer('complete_status')->nullable()->default(1);
|
||||
$table->integer('accept_status')->nullable()->default(1);
|
||||
$table->integer('type')->nullable()->default(1);
|
||||
$table->json('in_time_contract_obligation_template');
|
||||
$table->integer('status')->nullable()->default(1);
|
||||
$table->timestamp('completed_at')->nullable();
|
||||
$table->timestamp('failed_at')->nullable();
|
||||
|
||||
@@ -21,6 +21,7 @@ class SodaVendorContractObligationsTableSeeder extends Seeder
|
||||
'id' => 1,
|
||||
'user_id' => 2,
|
||||
'contract_id' => 1,
|
||||
'contract_template_obligation_id' => 1,
|
||||
'contract_entity_id' => 1,
|
||||
'name' => 'user insert coin and select soda at vendor machine',
|
||||
'reference' => null,
|
||||
@@ -30,6 +31,7 @@ class SodaVendorContractObligationsTableSeeder extends Seeder
|
||||
'complete_status' => config('constants.contract_obligation.complete_status.pending'),
|
||||
'accept_status' => config('constants.contract_obligation.accept_status.pending'),
|
||||
'type' => config('constants.contract_obligation.type.money'),
|
||||
'in_time_contract_obligation_template' => json_encode([]),
|
||||
'status' => 1,
|
||||
'completed_at' => null,
|
||||
'failed_at' => null,
|
||||
@@ -42,6 +44,7 @@ class SodaVendorContractObligationsTableSeeder extends Seeder
|
||||
'id' => 2,
|
||||
'user_id' => 2,
|
||||
'contract_id' => 1,
|
||||
'contract_template_obligation_id' => 2,
|
||||
'contract_entity_id' => 2,
|
||||
'name' => 'vendor machine drop selected soda to user',
|
||||
'reference' => null,
|
||||
@@ -51,6 +54,7 @@ class SodaVendorContractObligationsTableSeeder extends Seeder
|
||||
'complete_status' => config('constants.contract_obligation.complete_status.pending'),
|
||||
'accept_status' => config('constants.contract_obligation.accept_status.pending'),
|
||||
'type' => config('constants.contract_obligation.type.offer_service'),
|
||||
'in_time_contract_obligation_template' => json_encode([]),
|
||||
'status' => 1,
|
||||
'completed_at' => null,
|
||||
'failed_at' => null,
|
||||
@@ -63,6 +67,7 @@ class SodaVendorContractObligationsTableSeeder extends Seeder
|
||||
'id' => 3,
|
||||
'user_id' => 2,
|
||||
'contract_id' => 1,
|
||||
'contract_template_obligation_id' => 3,
|
||||
'contract_entity_id' => 2,
|
||||
'name' => 'user pickup the soda',
|
||||
'reference' => null,
|
||||
@@ -72,6 +77,7 @@ class SodaVendorContractObligationsTableSeeder extends Seeder
|
||||
'complete_status' => config('constants.contract_obligation.complete_status.pending'),
|
||||
'accept_status' => config('constants.contract_obligation.accept_status.pending'),
|
||||
'type' => config('constants.contract_obligation.type.offer_service'),
|
||||
'in_time_contract_obligation_template' => json_encode([]),
|
||||
'status' => 1,
|
||||
'completed_at' => Carbon::now(),
|
||||
'failed_at' => null,
|
||||
|
||||
@@ -208,6 +208,32 @@ Route::group(['namespace' => 'User', 'prefix' => 'user-backsys/api'], function (
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
// Contract
|
||||
Route::prefix('contract')->group(function () {
|
||||
Route::get('list',
|
||||
[
|
||||
'as' => 'api.contract.list',
|
||||
'uses' => 'ContractController@list',
|
||||
'middleware' => ['permission:view contract']
|
||||
]
|
||||
);
|
||||
Route::get('show/{hash_id}',
|
||||
[
|
||||
'as' => 'api.contract.show',
|
||||
'uses' => 'ContractController@show',
|
||||
'middleware' => ['permission:view contract']
|
||||
]
|
||||
);
|
||||
Route::post('generate',
|
||||
[
|
||||
'as' => 'api.contract.generate',
|
||||
'uses' => 'ContractController@generate',
|
||||
'middleware' => ['permission:add contract']
|
||||
]
|
||||
);
|
||||
});
|
||||
|
||||
// contract generate
|
||||
// contract assign entity
|
||||
// contract active
|
||||
|
||||
Reference in New Issue
Block a user