From 10eea7064579a88fb8cd027618d47588e2c08f29 Mon Sep 17 00:00:00 2001 From: Muhammad Sulaiman Yusuf Date: Tue, 12 Jul 2022 00:14:22 +0700 Subject: [PATCH] calc update --- activity_log.txt | 18 +- .../Controllers/RequestMaterialController.php | 305 +++++++++--------- app/Models/AssignMaterial.php | 2 +- 3 files changed, 159 insertions(+), 166 deletions(-) diff --git a/activity_log.txt b/activity_log.txt index adef32d..1c6c2d1 100755 --- a/activity_log.txt +++ b/activity_log.txt @@ -1,10 +1,20 @@ -2022-07-11 20:20:30: Project Plan -Added: (10000 * 5), Cost plan old: 0 | 50000_ +2022-07-12 00:13:26: 1379 Penentuan harga project +Added: (10000000 * 1), Cost plan old: 0 | +10000000 Data type (double * double), double | double Data type origin (double * NULL), string | double ------ -2022-07-11 20:21:26: Project Plan -Deleted: (10000 * 5), Cost plan old: 50000 | -0_ +2022-07-12 00:13:32: 1378 Contract Management +Deleted: (10000000 * 1), Cost plan old: 20000000 | -10000000 +Data type (double * double), double | double +Data type origin (double * double), string | double +------ +2022-07-12 00:13:38: 1377 Brainstorming peningkatan layanan masyarakat +Deleted: (10000000 * 1), Cost plan old: 20000000 | -10000000 +Data type (double * double), double | double +Data type origin (double * double), string | double +------ +2022-07-12 00:13:47: 1379 Penentuan harga project +Deleted: (10000000 * 1), Cost plan old: 10000000 | -0 Data type (double * double), double | double Data type origin (double * double), string | double ------ diff --git a/app/Http/Controllers/RequestMaterialController.php b/app/Http/Controllers/RequestMaterialController.php index 7a45ab5..2360ec1 100644 --- a/app/Http/Controllers/RequestMaterialController.php +++ b/app/Http/Controllers/RequestMaterialController.php @@ -8,165 +8,148 @@ use App\Models\MaterialResource; class RequestMaterialController extends Controller { - public function add(Request $request){ - - $this->validate($request, [ - 'proyek_id' => 'required', - 'description' => 'required', - 'required_date' => 'required', - 'qty' => 'required', - 'uom' => 'required', - 'fom_date' => 'required', - ]); - - $data = $request->all(); - - $data['status'] = "fom"; - $data['created_by'] = $this->currentName; - - $result = RequestMaterial::create($data); - - if($result){ - return response()->json(['status'=>'success','message'=>'request material successfully!', 'data'=>$result, 'code'=>200], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'request material failed!','code'=>400], 400); - } - } - - public function edit($id){ - if(!$id || (int) $id < 0 || $id==""){ - return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); - die(); - } - - $result = RequestMaterial::find($id); - - if($result){ - return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'failed get data request material, please try again later!','code'=>400], 400); - } - } - - - - - - - - public function delete($id) - { - $data = RequestMaterial::find($id); - - if($data){ - $delete = $data->delete(); - }else{ - return response()->json(['status'=>'failed','message'=>'data request material not found!','code'=>400], 400); - die(); - } - - - if($delete){ - return response()->json(['status'=>'success','message'=>'request material successfully deleted!','code'=>200], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'request material failed deleted!','code'=>400], 400); - } - } - - public function search(Request $request) - { - $payload = $request->all(); - $dataBuilder = $this->setUpPayload($payload, 'm_req_material'); - $builder = $dataBuilder['builder']; - $countBuilder = $dataBuilder['count']; - $dataGet = $builder->get(); - $totalRecord = $countBuilder->count(); - return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); - } - - public function list() - { - $data = RequestMaterial::all(); - $countData = $data->count(); - - if($data){ - return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'failed get list request material, please try again later!','code'=>400], 400); - } - } - - public function update(Request $request, $id) - { - $dataForm = $request->all(); - if(!$id || (int) $id < 0 || $id==""){ - return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); - die(); - } - $data = RequestMaterial::find($id); - if($data){ - if(!isset($dataForm['status'])){ - $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); - } - die(); - } - if($dataForm['status']=="receipt to warehouse"){ - $dataM = MaterialResource::where('name', 'ilike', $data->description)->first(); - if($dataM){ - $result = $data->update($request->all()); - $payloadMQty = $dataM->qty + $data->qty_received; - $resultUpdateM = MaterialResource::where('id', $dataM->id)->update(['qty' => $payloadMQty]); - return response()->json(['status'=>'success', 'code'=>200], 200); - }else{ - $result = $data->update($request->all()); - $dataPayloadM = array( - "name" => $dataForm['description'], - "uom" => $dataForm['uom'], - "unit_price" => 0, - "description" => $dataForm['description'], - "qty" => $data->qty_received, - "status" => "Barang tersedia", - "created_by" => $this->currentName - ); - $result = MaterialResource::create($dataPayloadM); - if($result){ - return response()->json(['status'=>'success','message'=>'add data material resource successfully!','code'=>200], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'add data material resource failed!','code'=>400], 400); - } - } - - }else if($dataForm['status']=="receipt to site"){ - $result = $data->update($request->all()); - $dataM = MaterialResource::where('name', 'ilike', $data->description)->first(); - if($dataM){ - $result = $data->update($request->all()); - $payloadMQty = $dataM->qty - $data->qty_received; - - 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); - 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(); - } - } + public function add(Request $request){ + $this->validate($request, [ + 'proyek_id' => 'required', + 'description' => 'required', + 'required_date' => 'required', + 'qty' => 'required', + 'uom' => 'required', + 'fom_date' => 'required', + ]); + + $data = $request->all(); + + $data['status'] = "fom"; + $data['created_by'] = $this->currentName; + + $result = RequestMaterial::create($data); + + if(!$result) + return response()->json(['status'=>'failed','message'=>'Failed to add!','code'=> 500], 500); + + return response()->json(['status'=>'success','message'=>'Data added!', 'data'=>$result, 'code'=>200], 200); + } + + public function edit($id){ + if(empty($id) || !is_int((int)$id)) + return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + + $result = RequestMaterial::find($id); + + if($result) + return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); + + return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); + } + + public function delete($id) + { + $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); + + return response()->json(['status'=>'failed','message'=>'Failed to delete!','code'=> 500], 500); + } + + public function search(Request $request) + { + $payload = $request->all(); + $dataBuilder = $this->setUpPayload($payload, 'm_req_material'); + $builder = $dataBuilder['builder']; + $countBuilder = $dataBuilder['count']; + $dataGet = $builder->get(); + $totalRecord = $countBuilder->count(); + return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); + } + + public function list() + { + $data = RequestMaterial::all(); + $countData = $data->count(); + + if($data) + return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); + + return response()->json(['status'=>'failed','message'=>'failed get list request material, please try again later!','code'=>400], 400); + } + + public function update(Request $request, $id) + { + $dataForm = $request->all(); + if(!$id || (int) $id < 0 || $id==""){ + return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + die(); + } + $data = RequestMaterial::find($id); + if($data){ + if(!isset($dataForm['status'])){ + $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); + } + die(); + } + if($dataForm['status']=="receipt to warehouse"){ + $dataM = MaterialResource::where('name', 'ilike', $data->description)->first(); + if($dataM){ + $result = $data->update($request->all()); + $payloadMQty = $dataM->qty + $data->qty_received; + $resultUpdateM = MaterialResource::where('id', $dataM->id)->update(['qty' => $payloadMQty]); + return response()->json(['status'=>'success', 'code'=>200], 200); + }else{ + $result = $data->update($request->all()); + $dataPayloadM = array( + "name" => $dataForm['description'], + "uom" => $dataForm['uom'], + "unit_price" => 0, + "description" => $dataForm['description'], + "qty" => $data->qty_received, + "status" => "Barang tersedia", + "created_by" => $this->currentName + ); + $result = MaterialResource::create($dataPayloadM); + if($result){ + return response()->json(['status'=>'success','message'=>'add data material resource successfully!','code'=>200], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'add data material resource failed!','code'=>400], 400); + } + } + + }else if($dataForm['status']=="receipt to site"){ + $result = $data->update($request->all()); + $dataM = MaterialResource::where('name', 'ilike', $data->description)->first(); + if($dataM){ + $result = $data->update($request->all()); + $payloadMQty = $dataM->qty - $data->qty_received; + + 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); + 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(); + } + } } diff --git a/app/Models/AssignMaterial.php b/app/Models/AssignMaterial.php index 7060c5c..297b525 100644 --- a/app/Models/AssignMaterial.php +++ b/app/Models/AssignMaterial.php @@ -35,7 +35,7 @@ class AssignMaterial extends Model $activity->save(); $msg = Carbon::now()->toDateTimeString() . ": ".$activity->id." ".$activity->name.PHP_EOL; - $msg .= "Added: ".$material->desc." (".floatval($material->price)." * ".floatval($data->qty_planning)."), Cost plan old: ".$old." | +".$activity->rencana_biayaPHP_EOL; + $msg .= "Added: ".$material->desc." (".floatval($material->price)." * ".floatval($data->qty_planning)."), Cost plan old: ".$old." | +".$activity->rencana_biaya.PHP_EOL; $msg .= "Data type (".gettype(floatval($material->price))." * ".gettype(floatval($material->qty_planning))."), ".gettype(floatval($old))." | ".gettype(floatval($activity->rencana_biaya)).PHP_EOL; $msg .= "Data type origin (".gettype($material->price)." * ".gettype($material->qty_planning)."), ".gettype($old)." | ".gettype($activity->rencana_biaya).PHP_EOL; $msg .= "------".PHP_EOL;