public function store(RequesitionItemUploadRequest $request, UploadRequesitionItem $upload, $id) { $requesition = Requesition::find($id); $file = $request->file('file'); $upload->upload($file->getRealPath(), $id); if (empty($upload->getErrors()) && !empty($upload->getData())) { $responseSave = $upload->save($requesition); Log::debug('update-requesition-item: save', [$responseSave]); flash()->success(trans('requesition.label.name'), trans('requesition_item_upload.message_alert.success')); return ['status' => 'success', 'urlRedirect' => url("/requesitions/add-products/{$id}")]; } return ['status' => 'error', 'errors' => $upload->getErrors()]; }
public function cutStock(Requesition $requesition) { $error = false; $items = $requesition->items()->where('status', Requesition::SUCCESS)->get(); foreach ($items as $item) { $stockTem["{$item->product_id}_{$item->location_id}"] = self::where('product_id', $item->product_id)->where('location_id', $item->location_id)->first(); $stock = $stockTem["{$item->product_id}_{$item->location_id}"]; if ($stock->qty < $item->qty) { $error = true; Log::warning('cus-stock: item is not enouge.', ['requesition_id' => $item->requesition_id, 'product' => $stock->product_id, 'location' => $stock->location_id, 'item-qty' => $item->qty, 'stock' => $stock->qty]); } } if ($error) { flash()->error(trans('requesition.label.name'), trans('requesition.message_alert.requesition_error_case_item_not_enouge')); return; } foreach ($items as $item) { $stock = $stockTem["{$item->product_id}_{$item->location_id}"]; $stock->qty = $stock->qty - $item->qty; Log::info('cut-stock: success', ['requesition_id' => $item->requesition_id, 'product' => $stock->product_id, 'location' => $stock->location_id, 'item-qty' => $item->qty, 'stock-after-cus' => $stock->qty]); $stock->save(); } }
public function editMulti() { $rules = ['project_id' => ['project_id' => 'required'], 'site_id' => ['site_id' => 'required|max:255'], 'site_name' => ['site_name' => 'required|max:255'], 'receive_company_name' => ['receive_company_name' => 'required|max:255'], 'receive_contact_name' => ['receive_contact_name' => 'required|max:255'], 'receive_phone' => ['receive_phone' => 'required|max:255'], 'receive_date' => ['receive_date' => 'required|date_format:Y-m-d']]; $pk = request()->get('pk'); $value = request()->get('value'); $attribute = request()->get('name'); $data = [$attribute => $value]; $validator = Validator::make($data, $rules[$attribute]); if ($validator->passes()) { $requisition = Requesition::find($pk); if ($attribute == 'project_id') { $requisition->{$attribute} = $value; $requisition->project_code = Project::find($value)->code; } else { $requisition->{$attribute} = $value; } $requisition->save(); return Response::json('success', 200); } return Response::json($validator->errors()->first($attribute), 422); }