예제 #1
0
 public function destory()
 {
     try {
         \DB::beginTransaction();
         $product = Product::find(\Request::get('product_id'));
         $product->status = 'STOP';
         $product->save();
         \DB::commit();
     } catch (exception $e) {
         \DB::rollback();
         return \Response::json(['result' => 'success']);
     }
     return \Response::json(['result' => 'success']);
 }
 public function getCheckuser()
 {
     $sessionfb = Session::get('sessionfb');
     dd($sessionfb);
     $userfb = Session::get('userfb');
     $check = User::checkuser($userfb, $nh);
     //kiem tra id nha hang
     //kiem tra check, neu khong co nguoi dung trong db
     if ($check == false) {
         if (!NhaHang::checkid($nh)) {
             return Redirect::to('/error');
         } else {
             DB::beginTransaction();
             try {
                 $user = User::createuser($userfb, htmlentities($_SERVER['HTTP_USER_AGENT']), $nh);
                 $code = Code::createcode($userfb, $type, $nh);
                 DB::commit();
             } catch (Exception $e) {
                 //If there are any exceptions, rollback the transaction
                 DB::rollback();
             }
             //Everything worked perfectly. Commit the transaction
             $user = $userfb->asArray();
             $user['fb_id'] = $user['id'];
             Session::put('user', (object) $user);
             return Redirect::to('/hello');
         }
     } else {
         $user = $check;
         $user->save();
         $c = false;
         $arrs = Code::where('fb_id', $user->fb_id)->get();
         foreach ($arrs as $arr) {
             if ($nh == $arr->nhahang_id) {
                 $c = true;
                 break;
             }
         }
         if (!$c) {
             $code = Code::createcode($userfb, $type, $nh);
             Session::put('user', $user);
             return Redirect::to('/hello');
         } else {
             Session::put('user', $user);
             return Redirect::to('/hello');
         }
     }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(Request $request)
 {
     $this->validate($request, ['prompt' => 'required|max:100|unique_with:forms, formgroup = form_group_id, formtype = form_type_id', 'formgroup' => 'required|not_in:0', 'formtype' => 'required|not_in:0']);
     \DB::beginTransaction();
     try {
         $form = new Form();
         $form->form_group_id = $request->formgroup;
         $form->form_type_id = $request->formtype;
         $form->prompt = $request->prompt;
         $form->required = $request->required == '1' ? 1 : 0;
         $form->expected_answer = $request->expected_answer == '1' ? 1 : 0;
         $form->exempt = $request->exempt == '1' ? 1 : 0;
         $form->save();
         if ($request->formtype == 9) {
             $multiData = array();
             foreach ($request->multiselect as $option) {
                 $multiData[] = array('form_id' => $form->id, 'multi_select_id' => $option);
             }
             if (count($multiData) > 0) {
                 FormMultiSelect::insert($multiData);
             }
         }
         if ($request->formtype == 10) {
             $singleData = array();
             foreach ($request->singleselect as $option) {
                 $singleData[] = array('form_id' => $form->id, 'single_select_id' => $option);
             }
             if (count($singleData) > 0) {
                 FormSingleSelect::insert($singleData);
             }
         }
         if ($request->formtype == 11) {
             if ($request->has('formula')) {
                 $formformula = new FormFormula();
                 $formformula->form_id = $form->id;
                 $formformula->formula = $request->formula;
                 $formformula->save();
             }
         }
         \DB::commit();
         Session::flash('flash_message', 'Form successfully added!');
         return redirect()->route("form.index");
     } catch (Exception $e) {
         DB::rollBack();
         return redirect()->back();
     }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(Request $request)
 {
     $this->validate($request, ['distributor' => 'required|max:100|unique_with:distributors, distributor_code = distributor_code', 'distributor_code' => 'required|not_in:0']);
     \DB::beginTransaction();
     try {
         $distributor = new Distributor();
         $distributor->distributor_code = $request->distributor_code;
         $distributor->distributor = $request->distributor;
         $distributor->save();
         \DB::commit();
         Session::flash('flash_message', 'Distributor successfully added!');
         return redirect()->route("distributor.index");
     } catch (Exception $e) {
         DB::rollBack();
         return redirect()->back();
     }
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @param  int  $id
  * @return Response
  */
 public function update(Request $request, $id)
 {
     $matrix = GradeMatrix::findOrFail($id);
     $this->validate($request, ['desc' => 'required|max:100|unique_with:grade_matrixs, passing = passing,' . $id, 'passing' => 'required|not_in:0']);
     \DB::beginTransaction();
     try {
         $matrix->desc = $request->desc;
         $matrix->passing = $request->passing;
         $matrix->update();
         \DB::commit();
         Session::flash('flash_message', 'Grade Matrix successfully updated!');
         return redirect()->route("gradematrix.edit", [$id]);
     } catch (Exception $e) {
         DB::rollBack();
         return redirect()->back();
     }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Requests\AddTask $request)
 {
     try {
         \DB::beginTransaction();
         $task = new Task();
         $task->fill($request->only('title', 'description', 'deadline'));
         $task->user_id = auth()->user()->id;
         $task->save();
         \DB::commit();
         flash()->success('Task added to list successfully.');
         return redirect()->back();
     } catch (\Exception $e) {
         \DB::rollback();
         flash()->error($e->getMessage());
         return redirect()->back()->withInput();
     }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(Request $request)
 {
     $this->validate($request, ['region' => 'required|max:100|unique_with:regions, region_code = region_code', 'region_code' => 'required|not_in:0']);
     \DB::beginTransaction();
     try {
         $region = new Region();
         $region->region_code = $request->region_code;
         $region->region = $request->region;
         $region->save();
         \DB::commit();
         Session::flash('flash_message', 'Region successfully added!');
         return redirect()->route("region.index");
     } catch (Exception $e) {
         DB::rollBack();
         return redirect()->back();
     }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(Request $request)
 {
     $this->validate($request, ['area' => 'required|max:100|unique_with:areas, customer = customer_id', 'customer' => 'required|not_in:0']);
     \DB::beginTransaction();
     try {
         $area = new Area();
         $area->customer_id = $request->customer;
         $area->area = $request->area;
         $area->save();
         \DB::commit();
         Session::flash('flash_message', 'Area successfully added!');
         return redirect()->route("area.index");
     } catch (Exception $e) {
         DB::rollBack();
         return redirect()->back();
     }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $this->validate($request, ['brand' => 'required|max:100|unique_with:secondary_displays, category = category_id', 'category' => 'required|not_in:0']);
     \DB::beginTransaction();
     try {
         $display = new SecondaryDisplay();
         $display->category_id = $request->category;
         $display->brand = $request->brand;
         $display->save();
         \DB::commit();
         Session::flash('flash_message', 'Secondary Display successfully added!');
         return redirect()->route("secondarydisplay.index");
     } catch (Exception $e) {
         DB::rollBack();
         return redirect()->back();
     }
 }
예제 #10
0
 public function restoreStockForProduct(Request $request)
 {
     $purchaseOrderId = $request->input('purchase_order_id');
     $productId = $request->input('product_id');
     try {
         \DB::beginTransaction();
         // First restore the stock levels for the product deleted from the PO
         $this->workOrderSchedulerService->restoreStockForProducts($purchaseOrderId, $productId);
         // Now delete any workorders for this product generated by the PO
         $this->workOrderSchedulerService->deleteWorkOrdersForPo($purchaseOrderId, $productId);
         // Finally delete the actual purchaseOrderProduct row
         $this->workOrderSchedulerService->deletePurchaseOrderProduct($purchaseOrderId, $productId);
         \DB::commit();
     } catch (\Exception $ex) {
         \DB::rollBack();
         throw $ex;
     }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(Request $request)
 {
     $this->validate($request, ['customer' => 'required|max:100|unique_with:customers, customer_code = customer_code, account = account_id', 'customer_code' => 'required|not_in:0', 'account' => 'required|not_in:0']);
     \DB::beginTransaction();
     try {
         $customer = new Customer();
         $customer->account_id = $request->account;
         $customer->customer_code = $request->customer_code;
         $customer->customer = $request->customer;
         $customer->save();
         \DB::commit();
         Session::flash('flash_message', 'Customer successfully added!');
         return redirect()->route("customer.index");
     } catch (Exception $e) {
         DB::rollBack();
         return redirect()->back();
     }
 }
예제 #12
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(Request $request)
 {
     $this->validate($request, ['name' => 'required|max:100']);
     \DB::beginTransaction();
     try {
         $role = new Role();
         $role->name = $request->name;
         $role->display_name = $request->display_name;
         $role->description = $request->description;
         $role->save();
         \DB::commit();
         Session::flash('flash_message', 'Role successfully added!');
         return redirect()->route("role.index");
     } catch (Exception $e) {
         DB::rollBack();
         return redirect()->back();
     }
 }
 public function update($id)
 {
     try {
         \DB::beginTransaction();
         $userObject = \App\Models\User::find($id);
         if (empty($userObject)) {
             return \Redirect::back()->withErrors('Unable to update the password');
         }
         $data = \Input::all();
         if (!empty($userObject->password)) {
             if (empty($data['old_password']) || empty($data['new_password']) || empty($data['re_type_password'])) {
                 return \Redirect::back()->withErrors('All Three Fields are required');
             }
             $old_password = $data['old_password'];
         } else {
             if (empty($data['new_password']) || empty($data['re_type_password'])) {
                 return \Redirect::back()->withErrors('Both Fields are required');
             }
         }
         $new_password = $data['new_password'];
         $re_type_password = $data['re_type_password'];
         if ($new_password != $re_type_password) {
             return \Redirect::back()->withErrors('Passwords do not match');
         }
         if (!empty($old_password)) {
             if ($old_password == $re_type_password) {
                 return \Redirect::back()->withErrors('New password and current password are same');
             }
             if (!\Hash::check($old_password, $userObject->password)) {
                 return \Redirect::back()->withErrors('Incorrect Old Password');
             }
         }
         $userObject->password = bcrypt($new_password);
         if (!$userObject->save()) {
             $errors = $userObject->getErrors();
             return Redirect::back()->withErrors($errors);
         }
         \DB::commit();
         \Flash::success('Login password updated successfully');
         return redirect(url('/account/password'));
     } catch (\Exception $e) {
         abort(500);
     }
 }
예제 #14
0
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     $user = User::findorFail($id);
     $this->validate($request, ['name' => 'required|max:100', 'email' => 'required|max:100|email', 'username' => 'required|max:100']);
     \DB::beginTransaction();
     try {
         $user->name = strtoupper($request->name);
         $user->email = strtolower($request->email);
         $user->username = $request->username;
         $user->active = $request->active ? 1 : 0;
         $user->update();
         \DB::commit();
         Session::flash('flash_message', 'User successfully updated!');
         return redirect()->route("user.edit", [$id]);
     } catch (Exception $e) {
         DB::rollBack();
         return redirect()->back();
     }
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @param  int  $id
  * @return Response
  */
 public function update(Request $request, $id)
 {
     $category = FormCategory::findOrFail($id);
     $this->validate($request, ['category' => 'required|max:100|unique_with:form_categories,' . $id]);
     \DB::beginTransaction();
     try {
         $category->category = $request->category;
         $category->secondary_display = $request->secondary_display ? 1 : 0;
         $category->osa_tagging = $request->osa_tagging ? 1 : 0;
         $category->sos_tagging = $request->sos_tagging ? 1 : 0;
         $category->custom = $request->custom ? 1 : 0;
         $category->perfect_store = $request->perfect_store ? 1 : 0;
         $category->update();
         \DB::commit();
         Session::flash('flash_message', 'Form Catagory successfully updated!');
         return redirect()->route("formcategory.edit", [$id]);
     } catch (Exception $e) {
         DB::rollBack();
         return redirect()->back();
     }
 }
예제 #16
0
 public function product_submit()
 {
     $data = \Request::input();
     try {
         \DB::beginTransaction();
         $order = new Order();
         $order->product_id = $data['product_id'];
         $order->user_id = \Auth::user()->id;
         $order->quantity = $data['item_count'];
         $order->status = 'Inprogress';
         $order->save();
         // 견적서 메일 발송
         //\Event::fire('order.send_mail', [$data]);
         \DB::commit();
     } catch (exception $e) {
         \DB::rollback();
         #return \Response::json(['result' => 'error']);
     }
     #return \Response::json(['result' => 'success']);
     return \Redirect()->route('order_product', 1);
     // 영업사원 user_id 로 변경 해야 함.
 }
 public function store(Request $request)
 {
     $this->validate($request, ['app_name' => 'required|max:100']);
     \DB::beginTransaction();
     try {
         $settings = Setting::find(1);
         if (!empty($settings)) {
             $settings->app_name = $request->app_name;
             $settings->update();
         } else {
             $settings = new Setting();
             $settings->app_name = $request->app_name;
             $settings->save();
         }
         \DB::commit();
         Session::flash('flash_message', 'Settings successfully updated!');
         return redirect()->back();
     } catch (Exception $e) {
         DB::rollBack();
         return redirect()->back();
     }
 }
예제 #18
0
 public function save(Request $request, $id = null)
 {
     if (!$this->user->isAdmin()) {
         return redirect('crews');
     }
     \DB::beginTransaction();
     $crew = Crew::findOrNew($id);
     $crew->name = $request->input('name');
     $crew->comments = $request->input('comments');
     $crew->save();
     // Save crew members.
     \DB::table('crew_members')->where('crew_id', '=', $crew->id)->delete();
     foreach (explode(',', $request->input('members')) as $member) {
         $user = User::whereUsername($member)->first();
         if ($user) {
             $crewMember = new CrewMember();
             $crewMember->user_id = $user->id;
             $crewMember->crew_id = $crew->id;
             $crewMember->save();
         }
     }
     // Save availability dates.
     \DB::table('crew_unavailabilities')->where('crew_id', '=', $crew->id)->delete();
     foreach ($request->input('unavailabilities') as $unavail) {
         if (empty($unavail['start_date']) && empty($unavail['end_date'])) {
             continue;
         }
         $date = new \App\Model\CrewUnavailability();
         $date->crew_id = $crew->id;
         $date->start_date = $unavail['start_date'];
         $date->end_date = $unavail['end_date'];
         $date->save();
     }
     \DB::commit();
     return redirect('crews');
 }
예제 #19
0
 public function put(Request $request, $id)
 {
     //return $request->all();
     if (strtolower($request->input('id')) == strtolower($id)) {
         $manday = Manday::find($id);
         if (count($manday) > 0) {
             //\DB::beginTransaction();
             $manday->custcount = $request->input('custcount');
             $manday->headspend = $request->input('headspend');
             $manday->empcount = $request->input('empcount');
             $manday->workhrs = $request->input('workhrs');
             $manday->breakhrs = $request->input('breakhrs');
             $manday->loading = $request->input('loading');
             \DB::beginTransaction();
             //Start transaction!
             try {
                 $manday->save();
                 try {
                     foreach ($request->input('manskeddtls') as $mandtl) {
                         $n = Mandtl::find($mandtl['id']);
                         if (count($manday) > 0) {
                             $n->daytype = $mandtl['daytype'];
                             $n->timestart = $mandtl['timestart'];
                             $n->breakstart = $mandtl['breakstart'];
                             $n->breakend = $mandtl['breakend'];
                             $n->timeend = $mandtl['timeend'];
                             $n->workhrs = $mandtl['workhrs'];
                             $n->breakhrs = $mandtl['breakhrs'];
                             $n->loading = $mandtl['loading'];
                             $n->save();
                         } else {
                             \DB::rollback();
                             return 'no mandtl found!';
                         }
                     }
                 } catch (\Exception $e) {
                     \DB::rollback();
                     throw $e;
                 }
             } catch (\Exception $e) {
                 \DB::rollback();
                 throw $e;
             }
             \DB::commit();
             $manday->load('manskeddtls');
             return $manday;
             //return $request->input('manskeddtls');
         }
     }
     return redirect(URL::previous());
     //return ['iid' => $request->input('id'),  'rid'=>$id];
 }
예제 #20
0
 public function post(Request $request)
 {
     //
     $this->validate($request, ['date' => 'required|date|max:10', 'weekno' => 'required']);
     // check weekno if exist
     $mansked = Mansked::whereWeekno($request->input('weekno'))->get();
     if (count($mansked) > 0) {
         return redirect('/branch/mansked/add')->withErrors(['message' => 'Week ' . $request->input('weekno') . ' already created!'])->withInput();
     }
     //$mansked = array_shift($mansked);
     $mansked = new Mansked();
     //return $mansked->getRefno();
     $mansked->refno = $mansked->getRefno();
     $mansked->date = $request->input('date');
     $mansked->weekno = $request->input('weekno');
     $mansked->branchid = $request->input('branchid');
     $mansked->managerid = $request->input('managerid');
     $mansked->mancost = $request->input('mancost');
     $mansked->notes = $request->input('notes');
     $mansked->id = $mansked->get_uid();
     $mandays = [];
     foreach ($mansked->getDaysByWeekNo($request->input('weekno')) as $key => $date) {
         $manday = new Manday();
         $manday->date = $date;
         $manday->id = $manday->get_uid();
         array_push($mandays, $manday);
     }
     \DB::beginTransaction();
     //Start transaction!
     try {
         $mansked->save();
         try {
             $mansked->manskeddays()->saveMany($mandays);
         } catch (\Exception $e) {
             \DB::rollback();
             throw $e;
         }
     } catch (\Exception $e) {
         \DB::rollback();
         throw $e;
     }
     \DB::commit();
     //$mansked->id
     //return $id;
     //return dd($mansked);
     $mansked->load('manskeddays');
     foreach ($mansked->manskeddays as $manskedday) {
         foreach ($this->employees as $employee) {
             $mandtl = new Mandtl();
             $mandtl->employeeid = $employee->id;
             $mandtl->id = $mandtl->get_uid();
             $manskedday->manskeddtls()->save($mandtl);
         }
     }
     return $mansked;
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @param  int  $id
  * @return Response
  */
 public function update(Request $request, $id)
 {
     // dd($request->all());
     $this->validate($request, ['store' => 'required|max:100|unique_with:stores, store_code = store_code,' . $id, 'store_code' => 'required', 'distributor' => 'required|not_in:0', 'template' => 'required|not_in:0', 'passing' => 'required|not_in:0']);
     \DB::beginTransaction();
     try {
         $store = Store::findOrFail($id);
         $store->distributor_id = $request->distributor;
         $store->store_code = $request->store_code;
         $store->store = $request->store;
         $store->grade_matrix_id = $request->passing;
         $store->audit_template_id = $request->template;
         $store->update();
         StoreSosTag::where('store_id', $store->id)->delete();
         if (!empty($request->cat)) {
             foreach ($request->cat as $key => $value) {
                 $data[] = ['store_id' => $store->id, 'form_category_id' => $key, 'sos_tag_id' => $value];
             }
             StoreSosTag::insert($data);
         }
         \DB::commit();
         Session::flash('flash_message', 'Store successfully updated!');
         return redirect()->route("store.edit", [$id]);
     } catch (Exception $e) {
         DB::rollBack();
         return redirect()->back();
     }
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @param  int  $id
  * @return Response
  */
 public function update(Request $request, $id)
 {
     $group = FormGroup::findOrFail($id);
     $this->validate($request, ['group_desc' => 'required||max:100|unique_with:form_groups,' . $id]);
     \DB::beginTransaction();
     try {
         $group->group_desc = strtoupper($request->group_desc);
         $group->secondary_display = $request->secondary_display ? 1 : 0;
         $group->osa = $request->osa ? 1 : 0;
         $group->sos = $request->sos ? 1 : 0;
         $group->custom = $request->custom ? 1 : 0;
         $group->perfect_store = $request->perfect_store ? 1 : 0;
         $group->update();
         \DB::commit();
         Session::flash('flash_message', 'Form Group successfully updated!');
         return redirect()->route("formgroup.edit", [$id]);
     } catch (Exception $e) {
         DB::rollBack();
         return redirect()->back();
     }
 }
예제 #23
0
 public function syncWithJira($id = NULL)
 {
     try {
         \DB::beginTransaction();
         if ($id != NULL) {
             Project::findOrFail($id)->syncWithJira();
         } else {
             foreach (Project::all() as $project) {
                 $project->syncWithJira();
             }
         }
         \DB::commit();
     } catch (\Exception $e) {
         \DB::rollBack();
         throw $e;
     }
     return 'synced succesfully';
 }
 public function storeform(Request $request, $id)
 {
     // dd($request->all());
     $this->validate($request, ['category' => 'required', 'group' => 'required', 'prompt' => 'required', 'formtype' => 'required']);
     \DB::beginTransaction();
     try {
         $template = AuditTemplate::find($id);
         $form_type = FormType::find($request->formtype);
         $prompt = $request->prompt;
         foreach ($request->category as $cat_id) {
             $category = FormCategory::find($cat_id);
             $cat_order = 1;
             $a_cat_id = 0;
             $clast_cnt = AuditTemplateCategory::getLastOrder($template->id);
             if (empty($clast_cnt)) {
                 $a_cat = AuditTemplateCategory::create(['category_order' => $cat_order, 'audit_template_id' => $template->id, 'category_id' => $category->id]);
                 $a_cat_id = $a_cat->id;
             } else {
                 $cat = AuditTemplateCategory::categoryExist($template->id, $category->id);
                 if (empty($cat)) {
                     $cat_order = $clast_cnt->category_order + 1;
                     $a_cat = AuditTemplateCategory::create(['category_order' => $cat_order, 'audit_template_id' => $template->id, 'category_id' => $category->id]);
                     $a_cat_id = $a_cat->id;
                 } else {
                     $a_cat_id = $cat->id;
                 }
             }
             foreach ($request->group as $grp_id) {
                 $group = FormGroup::find($grp_id);
                 $grp_order = 1;
                 $a_grp_id = 0;
                 $glast_cnt = AuditTemplateGroup::getLastOrder($a_cat_id);
                 if (empty($glast_cnt)) {
                     $a_grp = AuditTemplateGroup::create(['group_order' => $grp_order, 'audit_template_category_id' => $a_cat_id, 'form_group_id' => $group->id]);
                     $a_grp_id = $a_grp->id;
                 } else {
                     $grp = AuditTemplateGroup::categoryExist($a_cat_id, $group->id);
                     if (empty($grp)) {
                         $grp_order = $glast_cnt->group_order + 1;
                         $a_grp = AuditTemplateGroup::create(['group_order' => $grp_order, 'audit_template_category_id' => $a_cat_id, 'form_group_id' => $group->id]);
                         $a_grp_id = $a_grp->id;
                     } else {
                         $a_grp_id = $grp->id;
                     }
                 }
                 $form = Form::create(array('audit_template_id' => $template->id, 'form_type_id' => $form_type->id, 'prompt' => strtoupper($prompt), 'required' => $request->required == '1' ? 1 : 0, 'expected_answer' => $request->expected_answer == '1' ? 1 : 0, 'exempt' => $request->exempt == '1' ? 1 : 0));
                 if ($request->formtype == 9) {
                     $multiData = array();
                     foreach ($request->multiselect as $option) {
                         $multiData[] = array('form_id' => $form->id, 'multi_select_id' => $option);
                     }
                     if (count($multiData) > 0) {
                         FormMultiSelect::insert($multiData);
                     }
                 }
                 if ($request->formtype == 10) {
                     $singleData = array();
                     foreach ($request->singleselect as $option) {
                         $singleData[] = array('form_id' => $form->id, 'single_select_id' => $option);
                     }
                     if (count($singleData) > 0) {
                         FormSingleSelect::insert($singleData);
                     }
                 }
                 if ($request->formtype == 11) {
                     if ($request->has('formula')) {
                         $text = $request->formula;
                         preg_match_all('/:(.*?):/', $text, $matches);
                         $index = array();
                         foreach ($matches[1] as $value) {
                             $split_up = explode('_', $value);
                             $last_item = $split_up[count($split_up) - 1];
                             $index[] = $last_item;
                         }
                         $formula1 = $text;
                         foreach ($matches[1] as $key => $a) {
                             $formula1 = str_replace(':' . $a . ':', $index[$key], $formula1);
                         }
                         $formformula = new FormFormula();
                         $formformula->form_id = $form->id;
                         $formformula->formula = $formula1;
                         $formformula->formula_desc = $request->formula;
                         $formformula->save();
                     }
                 }
                 if ($request->formtype == 12) {
                     if ($request->has('condition')) {
                     }
                 }
                 $order = 1;
                 $a_frm_id = 0;
                 $last_cnt = AuditTemplateForm::getLastOrder($a_grp_id);
                 if (!empty($last_cnt)) {
                     $order = $last_cnt->order + 1;
                 }
                 AuditTemplateForm::insert(array('audit_template_group_id' => $a_grp_id, 'order' => $order, 'audit_template_id' => $template->id, 'form_id' => $form->id));
             }
         }
         \DB::commit();
         Session::flash('flash_message', 'Template successfully added!');
         return redirect()->route("audittemplate.form", $id);
     } catch (Exception $e) {
         DB::rollBack();
         Session::flash('flash_message', 'An error occured in adding form!');
         return redirect()->back();
     }
 }
예제 #25
0
 public function put(Request $request, $id)
 {
     //return $request->all();
     if (strtolower($request->input('id')) == strtolower($id)) {
         $manday = Manday::find($id);
         if (count($manday) > 0) {
             //\DB::beginTransaction();
             $manday->custcount = $request->input('custcount');
             $manday->headspend = $request->input('headspend');
             $manday->empcount = $request->input('empcount');
             $manday->workhrs = $request->input('workhrs');
             $manday->breakhrs = $request->input('breakhrs');
             $manday->overload = $request->input('overload');
             $manday->underload = $request->input('underload');
             \DB::beginTransaction();
             //Start transaction!
             try {
                 $manday->save();
                 try {
                     foreach ($request->input('manskeddtls') as $mandtl) {
                         $n = Mandtl::find($mandtl['id']);
                         if (count($n) > 0) {
                             //dd(count($n));
                             foreach ($mandtl as $key => $value) {
                                 if ($mandtl['timestart'] == 'off') {
                                     $n->breakstart = 'off';
                                     $n->breakend = 'off';
                                     $n->timeend = 'off';
                                 }
                                 $n->{$key} = $value;
                             }
                             $n->save();
                         } else {
                             //dd($mandtl);
                             $m = new Mandtl();
                             foreach ($mandtl as $key => $value) {
                                 if ($key == 'id') {
                                     $m->id = $m->get_uid();
                                 } else {
                                     $m->{$key} = $value;
                                 }
                             }
                             $m->mandayid = $request->input('id');
                             $m->save();
                             //\DB::rollback();
                             //return 'no mandtl found!';
                         }
                     }
                 } catch (\Exception $e) {
                     \DB::rollback();
                     throw $e;
                 }
             } catch (\Exception $e) {
                 \DB::rollback();
                 throw $e;
             }
             \DB::commit();
             //$manday->load('manskeddtls');
             //return $manday;
             //return $request->input('manskeddtls');
         }
     }
     return redirect('/task/manday/' . $manday->lid())->with('alert-success', 'Record saved!');
     //return ['iid' => $request->input('id'),  'rid'=>$id];
 }
 public function updateLinks(Request $request)
 {
     $updatelink = new UpdateLinkRequest();
     $validator = Validator::make($request->all(), $updatelink->rules(), $updatelink->messages());
     if ($validator->fails()) {
         return response()->json(['success' => false, 'errors' => $validator->errors()->toArray()], 400);
     }
     $userID = $request->user_id;
     $links = $request->links;
     \DB::beginTransaction();
     $link = User::find($userID)->links;
     for ($i = 0; $i < count($links); $i++) {
         $reflink = $link->find($links[$i]['id']);
         $reflink->link = $links[$i]['link'];
         $reflink->save();
         try {
             if (!$reflink) {
                 throw new \Exception('We Have Restricted You From Editing Others Link!');
             }
         } catch (\Exception $e) {
             \DB::rollback();
             $errors = ['ExceptionError' => $e->getMessage()];
             return response()->json(['success' => false, 'errors' => $errors], 400);
             // Failed Creation
         }
     }
     \DB::commit();
     return response()->json(['success' => true, 'message' => 'Link Have Been Renamed!'], 200);
 }
예제 #27
0
 public function copyMansked(Request $request)
 {
     $this->validate($request, ['lweekno' => 'required', 'nweekno' => 'required', 'year' => 'required', 'lmanskedid' => 'required']);
     $mansked1 = Mansked::whereWeekno($request->input('nweekno'))->where('year', $request->input('year'))->where('branchid', $request->user()->branchid)->get();
     if (count($mansked1) > 0) {
         return redirect('/task/mansked')->withErrors(['message' => 'Manpower Schedule Week ' . $request->input('nweekno') . ' already exist!'])->withInput();
     }
     $mansked = Mansked::find($request->input('lmanskedid'));
     if (count($mansked) <= 0) {
         return redirect('/task/mansked')->withErrors(['message' => 'Pointer Week ' . $request->input('lweekno') . ' not found!'])->withInput();
     }
     $mansked->load('manskeddays');
     $mandays = $mansked->manskeddays;
     foreach ($mandays as $manday) {
         $manday->load('manskeddtls');
     }
     $new_mansked = new Mansked();
     //return $mansked->getRefno();
     $new_mansked->refno = $new_mansked->getRefno();
     $new_mansked->date = $mansked->date->format('Y-m-d');
     $new_mansked->weekno = $request->input('nweekno');
     $new_mansked->year = $request->input('year');
     $new_mansked->branchid = $mansked->branchid;
     $new_mansked->managerid = $mansked->managerid;
     $new_mansked->mancost = $mansked->mancost;
     $new_mansked->notes = $mansked->notes;
     $new_mansked->id = $mansked->get_uid();
     \DB::beginTransaction();
     //Start transaction!
     $new_mandays = [];
     foreach ($new_mansked->getDaysByWeekNo($request->input('nweekno'), $request->input('year')) as $key => $date) {
         $new_manday = new Manday();
         $new_manday->date = $date->format('Y-m-d');
         $new_manday->custcount = $mandays[$key]->custcount;
         $new_manday->headspend = $mandays[$key]->headspend;
         $new_manday->empcount = $mandays[$key]->empcount;
         $new_manday->workhrs = $mandays[$key]->workhrs;
         $new_manday->breakhrs = $mandays[$key]->breakhrs;
         $new_manday->overload = $mandays[$key]->overload;
         $new_manday->underload = $mandays[$key]->underload;
         $new_manday->id = $new_manday->get_uid();
         $new_mandtls = [];
         foreach ($mandays[$key]->manskeddtls as $mandtl) {
             $new_mandtl = new Mandtl();
             $new_mandtl->employeeid = $mandtl->employeeid;
             $new_mandtl->daytype = $mandtl->daytype;
             $new_mandtl->timestart = $mandtl->timestart;
             $new_mandtl->breakstart = $mandtl->breakstart;
             $new_mandtl->breakend = $mandtl->breakend;
             $new_mandtl->timeend = $mandtl->timeend;
             $new_mandtl->workhrs = $mandtl->workhrs;
             $new_mandtl->breakhrs = $mandtl->breakhrs;
             $new_mandtl->loading = $mandtl->loading;
             $new_mandtl->id = $new_mandtl->get_uid();
             array_push($new_mandtls, $new_mandtl);
         }
         try {
             $new_manday->manskeddtls()->saveMany($new_mandtls);
         } catch (\Exception $e) {
             \DB::rollback();
             throw $e;
         }
         array_push($new_mandays, $new_manday);
     }
     try {
         $new_mansked->save();
         try {
             $new_mansked->manskeddays()->saveMany($new_mandays);
         } catch (\Exception $e) {
             \DB::rollback();
             throw $e;
         }
     } catch (\Exception $e) {
         \DB::rollback();
         throw $e;
     }
     \DB::commit();
     return redirect('/task/mansked')->with(['new' => true])->with('alert-success', 'Week ' . $request->input('lweekno') . ' successfully copied!');
     $new_mansked->load('manskeddays');
     $new_mandays = $new_mansked->manskeddays;
     foreach ($new_mandays as $new_manday) {
         $new_manday->load('manskeddtls');
     }
     return $new_mansked;
 }
예제 #28
0
 private function relateVn($parent_vn_id, $child_vn_id)
 {
     if (!empty($parent_vn_id) && !empty($child_vn_id)) {
         \DB::beginTransaction();
         try {
             $parent_relation = VnRelation::firstOrNew(['vn_id' => $parent_vn_id]);
             if (is_null($parent_relation->group_id)) {
                 $max_group_id = VnRelation::max('group_id') || 0;
                 if (!$max_group_id) {
                     $max_group_id++;
                 }
                 $parent_relation->group_id = $max_group_id;
             }
             $parent_relation->vn_id = $parent_vn_id;
             $exec_parent_relation = $parent_relation->save();
             $child_relation = VnRelation::firstOrNew(['vn_id' => $child_vn_id]);
             if (is_null($child_relation->group_id)) {
                 $child_relation->group_id = $parent_relation->group_id;
             }
             $child_relation->vn_id = $child_vn_id;
             $exec_child_relation = $child_relation->save();
         } catch (\Exception $e) {
             \DB::rollback();
             throw $e;
         }
         if ($exec_parent_relation && $exec_child_relation) {
             \DB::commit();
             return true;
         } else {
             \DB::rollback();
             throw new \Symfony\Component\HttpKernel\Exception\ConflictHttpException();
         }
     }
 }
예제 #29
0
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     $lookup = OsaLookup::findOrFail($id);
     $messages = ['unique_with' => 'This combination of selection already exists.'];
     $this->validate($request, ['customer_id' => 'required|unique_with:osa_lookups, regions = region_id, distributors = distributor_id, store_id = store_id, templates = template_id,' . $id, 'regions' => 'required', 'distributors' => 'required', 'store_id' => 'required', 'templates' => 'required'], $messages);
     \DB::beginTransaction();
     try {
         $lookup->customer_id = $request->customer_id;
         $lookup->region_id = $request->regions;
         $lookup->distributor_id = $request->distributors;
         $lookup->store_id = $request->stores;
         $lookup->template_id = $request->templates;
         $lookup->update();
         OsaLookupTarget::where('osa_lookup_id', $lookup->id)->delete();
         foreach ($request->target as $category_id => $value) {
             if ($category_id > 0) {
                 if (!empty($value)) {
                     $newlookup = new OsaLookupTarget();
                     $newlookup->osa_lookup_id = $lookup->id;
                     $newlookup->category_id = $category_id;
                     $newlookup->target = $value;
                     $newlookup->total = $request->total[$category_id];
                     $newlookup->save();
                 }
             }
         }
         \DB::commit();
         Session::flash('flash_message', 'OSA Lookup successfully updated!');
         return redirect()->route("osalookup.edit", [$id]);
     } catch (Exception $e) {
         dd($e);
         DB::rollBack();
         return redirect()->back();
     }
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     $store = Store::findOrFail($id);
     $this->validate($request, ['store_id' => 'required', 'brands' => 'required']);
     \DB::beginTransaction();
     try {
         SecondaryDisplayLookup::where('store_id', $store->id)->delete();
         foreach ($request->brands as $value) {
             SecondaryDisplayLookup::create(['store_id' => $store->id, 'secondary_display_id' => $value]);
         }
         \DB::commit();
         Session::flash('flash_message', 'Secondary Display Lookup successfully updated!');
         return redirect()->route("secondarylookup.edit", [$id]);
     } catch (Exception $e) {
         DB::rollBack();
         return redirect()->back();
     }
 }