Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $arrInsert = [];
- $arrDelete = [];
- if (!is_null($input['insert'])) {
- foreach ($input['insert'] as $value) { //loop งานที่ต้องบันทึก
- if ($value['type'] == 'area') { //ถ้าถูกเลือกพื้นที่มา
- //ดึงข้อมูลงานที่เลือกมา
- $workSelects = WorkSelect::where("area_id", $value['area_id'])->get();
- foreach ($workSelects as $workSelect) {
- $arrInsert[] = [
- 'user_technician_id' => $value['user_technician_id'],
- 'type' => 'area',
- 'work_select_id' => $workSelect->select_id,
- 'area_id' => $workSelect->area_id,
- 'qty' => $workSelect->qty,
- 'price' => $workSelect->technician_price,
- 'user_created' => $user->id,
- 'created_at' => dateTimeNow(),
- ];
- }
- } elseif ($value['type'] == 'work') { //ถ้าถูกแตกงานมา
- $arrInsert[] = [
- 'user_technician_id' => $value['user_technician_id'],
- 'type' => 'work',
- 'work_select_id' => $value['work_select_id'],
- 'area_id' => $value['area_id'],
- 'qty' => $value['qty'],
- 'price' => $value['price'],
- 'user_created' => $user->id,
- 'created_at' => dateTimeNow(),
- ];
- } //end if
- }
- if (isset($arrInsert)) { //ถ้ามีข้อมูล
- //บันทึกการแตกงาน
- WorkQuotationTechnician::insert($arrInsert);
- }
- } //end if(!is_null($input['insert']))
- if (!is_null($input['update'])) {
- foreach ($input['update'] as $value) { //loop งานที่ต้องแก้ไข
- if ($value['type'] == 'area') { //ถ้าถูกเลือกพื้นที่มา
- foreach ($value['id'] as $workId) {
- $update = WorkQuotationTechnician::find($workId);
- $update->user_technician_id = $value['user_technician_id'];
- $update->save();
- }
- } elseif ($value['type'] == 'work') { //ถ้าถูกแตกงานมา
- $update = WorkQuotationTechnician::find($value['id']);
- $update->user_technician_id = $value['user_technician_id'];
- $update->qty = $value['qty'];
- $update->price = $value['price'];
- $update->save();
- }
- }
- } //end if(!is_null($input['update']))
- if (!is_null($input['delete'])) {
- foreach ($input['delete'] as $value) { //loop งานที่ต้องลบ
- $arrDelete[] = $value;
- }
- if (isset($arrDelete)) {
- WorkQuotationTechnician::whereIn('id', $arrDelete)->delete();
- }
- } //end if(!is_null($input['delete']))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement