Update Corporate Activation
This commit is contained in:
@@ -27,7 +27,8 @@ class CorporateController extends Controller
|
|||||||
{
|
{
|
||||||
$corporates = Corporate::query()
|
$corporates = Corporate::query()
|
||||||
->when($request->search, function ($query, $search) {
|
->when($request->search, function ($query, $search) {
|
||||||
return $query->where('name', 'LIKE', '%'.$search.'%');
|
return $query->where('name', 'LIKE', '%'.$search.'%')
|
||||||
|
->orWhere('code', 'LIKE', '%'.$search.'%');
|
||||||
})
|
})
|
||||||
->with('currentPolicy')
|
->with('currentPolicy')
|
||||||
->withCount([
|
->withCount([
|
||||||
@@ -35,7 +36,7 @@ class CorporateController extends Controller
|
|||||||
'corporatePlans',
|
'corporatePlans',
|
||||||
'corporateBenefits'
|
'corporateBenefits'
|
||||||
])
|
])
|
||||||
->paginate(2);
|
->paginate(10);
|
||||||
|
|
||||||
return $corporates;
|
return $corporates;
|
||||||
}
|
}
|
||||||
@@ -183,6 +184,24 @@ class CorporateController extends Controller
|
|||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function activation(Request $request, $corporate_id) {
|
||||||
|
$request->validate([
|
||||||
|
'active' => 'required'
|
||||||
|
]);
|
||||||
|
|
||||||
|
// abort(404);
|
||||||
|
|
||||||
|
$corporate = Corporate::findOrFail($corporate_id);
|
||||||
|
$corporate->active = $request->active == '1';
|
||||||
|
|
||||||
|
if ($corporate->save()) {
|
||||||
|
return response()->json([
|
||||||
|
'corporate' => $corporate,
|
||||||
|
'message' => 'Status Updated Successfully'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function importPlanBenefit(Request $request, $corporate_id)
|
public function importPlanBenefit(Request $request, $corporate_id)
|
||||||
{
|
{
|
||||||
$request->validate([
|
$request->validate([
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ Route::prefix('internal')->group(function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
Route::resource('corporates', CorporateController::class);
|
Route::resource('corporates', CorporateController::class);
|
||||||
|
Route::put('corporates/{corporate_id}/activation', [CorporateController::class, 'activation']);
|
||||||
Route::post('corporates/{corporate_id}/import-plan-benefit', [CorporateController::class, 'importPlanBenefit']);
|
Route::post('corporates/{corporate_id}/import-plan-benefit', [CorporateController::class, 'importPlanBenefit']);
|
||||||
|
|
||||||
Route::get('corporates/{corporate_id}/corporate-plans', [CorporatePlanController::class, 'index']);
|
Route::get('corporates/{corporate_id}/corporate-plans', [CorporatePlanController::class, 'index']);
|
||||||
|
|||||||
@@ -116,6 +116,7 @@ export default function PlanList() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const handleInactiveAction = (formularium : any) => {
|
const handleInactiveAction = (formularium : any) => {
|
||||||
|
enqueueSnackbar('Fuck yuo'), { variant: 'error' });
|
||||||
axios
|
axios
|
||||||
.put('/corporates/'+corporate_id+'/formulariums/'+formularium.id+'/activate')
|
.put('/corporates/'+corporate_id+'/formulariums/'+formularium.id+'/activate')
|
||||||
.then(() => {
|
.then(() => {
|
||||||
@@ -135,7 +136,8 @@ export default function PlanList() {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
enqueueSnackbar(error.message ?? 'Failed Processing Request', { variant: 'error' });
|
console.log(error)
|
||||||
|
enqueueSnackbar(error.data?.message ?? (error.message ?? 'Failed Processing Request'), { variant: 'error' });
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import { LaravelPaginatedData } from '../../@types/paginated-data';
|
|||||||
import HeaderBreadcrumbs from '../../components/HeaderBreadcrumbs';
|
import HeaderBreadcrumbs from '../../components/HeaderBreadcrumbs';
|
||||||
import BasePagination from '../../components/BasePagination';
|
import BasePagination from '../../components/BasePagination';
|
||||||
import { fCurrency } from '../../utils/formatNumber';
|
import { fCurrency } from '../../utils/formatNumber';
|
||||||
|
import { enqueueSnackbar } from 'notistack';
|
||||||
|
|
||||||
export default function Corporates() {
|
export default function Corporates() {
|
||||||
const { themeStretch } = useSettings();
|
const { themeStretch } = useSettings();
|
||||||
@@ -223,7 +224,7 @@ export default function Corporates() {
|
|||||||
{/* </Grid> */}
|
{/* </Grid> */}
|
||||||
</Stack>
|
</Stack>
|
||||||
|
|
||||||
<Button type='hidden' sx={{ display: 'none' }}>Search</Button>
|
<Button type='submit' sx={{ display: 'none' }}>Search</Button>
|
||||||
</form>
|
</form>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -234,6 +235,29 @@ export default function Corporates() {
|
|||||||
const { row } = props;
|
const { row } = props;
|
||||||
const [open, setOpen] = React.useState(false);
|
const [open, setOpen] = React.useState(false);
|
||||||
|
|
||||||
|
const handleActivate = (model: any, status: string) => {
|
||||||
|
axios.put(`/corporates/${row.id}/activation`, {
|
||||||
|
// service_code: service.service_code,
|
||||||
|
active: status == 'active'
|
||||||
|
})
|
||||||
|
.then((res) => {
|
||||||
|
setDataTableData({
|
||||||
|
...dataTableData,
|
||||||
|
data: dataTableData.data.map((model) => {
|
||||||
|
let updatedModel = model
|
||||||
|
if (row.id == model.id) {
|
||||||
|
updatedModel.active = res.data.corporate.active
|
||||||
|
}
|
||||||
|
return updatedModel
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
// console.log('asdasd', error.response.data.message)
|
||||||
|
enqueueSnackbar(error.response.data.message ?? error.message ?? 'Failed Processing Request', { variant: 'error' });
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
<TableRow sx={{ '& > *': { borderBottom: 'unset' } }}>
|
<TableRow sx={{ '& > *': { borderBottom: 'unset' } }}>
|
||||||
@@ -248,7 +272,10 @@ export default function Corporates() {
|
|||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell align="left">{row.code}</TableCell>
|
<TableCell align="left">{row.code}</TableCell>
|
||||||
<TableCell align="left">{row.name}</TableCell>
|
<TableCell align="left">{row.name}</TableCell>
|
||||||
<TableCell align="left"><Button variant="outlined" color="success" size="small">Active</Button></TableCell>
|
<TableCell align="left">
|
||||||
|
{( row.active == 1 && <Button variant="outlined" color="success" size="small" onClick={() => { handleActivate(row, 'inactive') }}>Active</Button> )}
|
||||||
|
{( row.active != 1 && <Button variant="outlined" color="error" size="small" onClick={() => { handleActivate(row, 'active') }}>Inactive</Button> )}
|
||||||
|
</TableCell>
|
||||||
<TableCell align="right">
|
<TableCell align="right">
|
||||||
<Stack direction="row" justifyContent="flex-end" spacing={1}>
|
<Stack direction="row" justifyContent="flex-end" spacing={1}>
|
||||||
<Link to={"/corporates/" + row.id + "/edit"}><Button variant="outlined" color="primary" size="small">Edit</Button></ Link>
|
<Link to={"/corporates/" + row.id + "/edit"}><Button variant="outlined" color="primary" size="small">Edit</Button></ Link>
|
||||||
@@ -368,7 +395,7 @@ export default function Corporates() {
|
|||||||
<Table aria-label="collapsible table">
|
<Table aria-label="collapsible table">
|
||||||
<TableBody>
|
<TableBody>
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TableCell style={headStyle} align="left">#</TableCell>
|
<TableCell style={headStyle} align="left" width={50} />
|
||||||
<TableCell style={headStyle} align="left">Code</TableCell>
|
<TableCell style={headStyle} align="left">Code</TableCell>
|
||||||
<TableCell style={headStyle} align="left">Name</TableCell>
|
<TableCell style={headStyle} align="left">Name</TableCell>
|
||||||
<TableCell style={headStyle} align="left" width={100}>Status</TableCell>
|
<TableCell style={headStyle} align="left" width={100}>Status</TableCell>
|
||||||
|
|||||||
Reference in New Issue
Block a user