@ -8,165 +8,148 @@ use App\Models\MaterialResource;
class RequestMaterialController extends Controller
class RequestMaterialController extends Controller
{
{
public function add(Request $request){
public function add(Request $request){
$this->validate($request, [
$this->validate($request, [
'proyek_id' => 'required',
'proyek_id' => 'required',
'description' => 'required',
'description' => 'required',
'required_date' => 'required',
'required_date' => 'required',
'qty' => 'required',
'qty' => 'required',
'uom' => 'required',
'uom' => 'required',
'fom_date' => 'required',
'fom_date' => 'required',
]);
]);
$data = $request->all();
$data = $request->all();
$data['status'] = "fom";
$data['status'] = "fom";
$data['created_by'] = $this->currentName;
$data['created_by'] = $this->currentName;
$result = RequestMaterial::create($data);
$result = RequestMaterial::create($data);
if(!$result)
if($result){
return response()->json(['status'=>'failed','message'=>'Failed to add!','code'=> 500], 500);
return response()->json(['status'=>'success','message'=>'request material successfully!', 'data'=>$result, 'code'=>200], 200);
}else{
return response()->json(['status'=>'success','message'=>'Data added!', 'data'=>$result, 'code'=>200], 200);
return response()->json(['status'=>'failed','message'=>'request material failed!','code'=>400], 400);
}
}
}
public function edit($id){
if(empty($id) || !is_int((int)$id))
public function edit($id){
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
if(!$id || (int) $id < 0 | | $ id = =""){
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
$result = RequestMaterial::find($id);
die();
}
if($result)
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200);
$result = RequestMaterial::find($id);
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404);
if($result){
}
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200);
}else{
public function delete($id)
return response()->json(['status'=>'failed','message'=>'failed get data request material, please try again later!','code'=>400], 400);
{
}
$data = RequestMaterial::find($id);
}
if($data)
$delete = $data->delete();
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>404], 404);
if($delete)
return response()->json(['status'=>'success','message'=>'Data deleted!','code'=>200], 200);
public function delete($id)
return response()->json(['status'=>'failed','message'=>'Failed to delete!','code'=> 500], 500);
{
}
$data = RequestMaterial::find($id);
public function search(Request $request)
if($data){
{
$delete = $data->delete();
$payload = $request->all();
}else{
$dataBuilder = $this->setUpPayload($payload, 'm_req_material');
return response()->json(['status'=>'failed','message'=>'data request material not found!','code'=>400], 400);
$builder = $dataBuilder['builder'];
die();
$countBuilder = $dataBuilder['count'];
}
$dataGet = $builder->get();
$totalRecord = $countBuilder->count();
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
if($delete){
}
return response()->json(['status'=>'success','message'=>'request material successfully deleted!','code'=>200], 200);
}else{
public function list()
return response()->json(['status'=>'failed','message'=>'request material failed deleted!','code'=>400], 400);
{
}
$data = RequestMaterial::all();
}
$countData = $data->count();
public function search(Request $request)
if($data)
{
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200);
$payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'm_req_material');
return response()->json(['status'=>'failed','message'=>'failed get list request material, please try again later!','code'=>400], 400);
$builder = $dataBuilder['builder'];
}
$countBuilder = $dataBuilder['count'];
$dataGet = $builder->get();
public function update(Request $request, $id)
$totalRecord = $countBuilder->count();
{
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
$dataForm = $request->all();
}
if(!$id || (int) $id < 0 | | $ id = =""){
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
public function list()
die();
{
}
$data = RequestMaterial::all();
$data = RequestMaterial::find($id);
$countData = $data->count();
if($data){
if(!isset($dataForm['status'])){
if($data){
$resultUpdate = $data->update($request->all());
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200);
if($resultUpdate){
}else{
return response()->json(['status'=>'success','message'=>'request material successfully updated!','code'=>200], 200);
return response()->json(['status'=>'failed','message'=>'failed get list request material, please try again later!','code'=>400], 400);
}else{
}
return response()->json(['status'=>'failed','message'=>'request material failed updated!','code'=>400], 400);
}
}
die();
public function update(Request $request, $id)
}
{
if($dataForm['status']=="receipt to warehouse"){
$dataForm = $request->all();
$dataM = MaterialResource::where('name', 'ilike', $data->description)->first();
if(!$id || (int) $id < 0 | | $ id = =""){
if($dataM){
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
$result = $data->update($request->all());
die();
$payloadMQty = $dataM->qty + $data->qty_received;
}
$resultUpdateM = MaterialResource::where('id', $dataM->id)->update(['qty' => $payloadMQty]);
$data = RequestMaterial::find($id);
return response()->json(['status'=>'success', 'code'=>200], 200);
if($data){
}else{
if(!isset($dataForm['status'])){
$result = $data->update($request->all());
$resultUpdate = $data->update($request->all());
$dataPayloadM = array(
if($resultUpdate){
"name" => $dataForm['description'],
return response()->json(['status'=>'success','message'=>'request material successfully updated!','code'=>200], 200);
"uom" => $dataForm['uom'],
}else{
"unit_price" => 0,
return response()->json(['status'=>'failed','message'=>'request material failed updated!','code'=>400], 400);
"description" => $dataForm['description'],
}
"qty" => $data->qty_received,
die();
"status" => "Barang tersedia",
}
"created_by" => $this->currentName
if($dataForm['status']=="receipt to warehouse"){
);
$dataM = MaterialResource::where('name', 'ilike', $data->description)->first();
$result = MaterialResource::create($dataPayloadM);
if($dataM){
if($result){
$result = $data->update($request->all());
return response()->json(['status'=>'success','message'=>'add data material resource successfully!','code'=>200], 200);
$payloadMQty = $dataM->qty + $data->qty_received;
}else{
$resultUpdateM = MaterialResource::where('id', $dataM->id)->update(['qty' => $payloadMQty]);
return response()->json(['status'=>'failed','message'=>'add data material resource failed!','code'=>400], 400);
return response()->json(['status'=>'success', 'code'=>200], 200);
}
}else{
}
$result = $data->update($request->all());
$dataPayloadM = array(
}else if($dataForm['status']=="receipt to site"){
"name" => $dataForm['description'],
$result = $data->update($request->all());
"uom" => $dataForm['uom'],
$dataM = MaterialResource::where('name', 'ilike', $data->description)->first();
"unit_price" => 0,
if($dataM){
"description" => $dataForm['description'],
$result = $data->update($request->all());
"qty" => $data->qty_received,
$payloadMQty = $dataM->qty - $data->qty_received;
"status" => "Barang tersedia",
"created_by" => $this->currentName
if($payloadMQty < 0 ) {
);
return response()->json(['status'=>'failed','message'=>'update status receipt to site request material resource failed, because material is not exist in warehouse!','code'=>400], 400);
$result = MaterialResource::create($dataPayloadM);
die();
if($result){
}
return response()->json(['status'=>'success','message'=>'add data material resource successfully!','code'=>200], 200);
$resultUpdateM = MaterialResource::where('id', $dataM->id)->update(['qty' => $payloadMQty]);
}else{
return response()->json(['status'=>'success', 'message'=>'request material status receipt to site successfully updated!','code'=>200], 200);
return response()->json(['status'=>'failed','message'=>'add data material resource failed!','code'=>400], 400);
}else{
}
return response()->json(['status'=>'failed','message'=>'update status receipt to site request material resource failed, because material is not exist in warehouse!','code'=>400], 400);
}
}
}else{
}else if($dataForm['status']=="receipt to site"){
$resultUpdate = $data->update($request->all());
$result = $data->update($request->all());
if($resultUpdate){
$dataM = MaterialResource::where('name', 'ilike', $data->description)->first();
return response()->json(['status'=>'success','message'=>'request material successfully updated!','code'=>200], 200);
if($dataM){
}else{
$result = $data->update($request->all());
return response()->json(['status'=>'failed','message'=>'request material failed updated!','code'=>400], 400);
$payloadMQty = $dataM->qty - $data->qty_received;
}
}
if($payloadMQty < 0 ) {
}else{
return response()->json(['status'=>'failed','message'=>'update status receipt to site request material resource failed, because material is not exist in warehouse!','code'=>400], 400);
return response()->json(['status'=>'failed','message'=>'data request material not found!','code'=>400], 400);
die();
die();
}
}
$resultUpdateM = MaterialResource::where('id', $dataM->id)->update(['qty' => $payloadMQty]);
}
return response()->json(['status'=>'success', 'message'=>'request material status receipt to site successfully updated!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'update status receipt to site request material resource failed, because material is not exist in warehouse!','code'=>400], 400);
}
}else{
$resultUpdate = $data->update($request->all());
if($resultUpdate){
return response()->json(['status'=>'success','message'=>'request material successfully updated!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'request material failed updated!','code'=>400], 400);
}
}
}else{
return response()->json(['status'=>'failed','message'=>'data request material not found!','code'=>400], 400);
die();
}
}
}
}