/**
  * Get the validation rules that apply to the request.
  *
  * @return array
  */
 public function rules()
 {
     $type = $this->input('type_request');
     if ($type == 0) {
         return ['name' => 'required|max:255|unique:companies', 'email' => 'required|email|unique:users', 'first_name' => 'required|max:255', 'last_name' => 'required|max:255', 'password' => 'required|min:5|max:20|same:confirm_password', 'confirm_password' => 'required|min:5'];
     } else {
         $email = $this->input('email');
         $name = $this->input('name');
         $user_id = $this->input('user_id');
         $company_id = $this->input('company_id');
         $company = Company::findOrFail($company_id);
         $user = User::findOrFail($user_id);
         if ($user->email == $email) {
             if ($company->name == $name) {
                 return ['first_name' => 'required|max:255', 'last_name' => 'required|max:255', 'password' => 'min:5|max:20', 'new_password' => 'min:5|same:confirm_password'];
             } else {
                 return ['name' => 'required|max:255|unique:companies', 'first_name' => 'required|max:255', 'last_name' => 'required|max:255', 'password' => 'min:5|max:20', 'new_password' => 'min:5|same:confirm_password'];
             }
         } else {
             if ($company->name == $name) {
                 return ['email' => 'required|email|unique:users', 'first_name' => 'required|max:255', 'last_name' => 'required|max:255', 'password' => 'min:5|max:20', 'new_password' => 'min:5|same:confirm_password'];
             } else {
                 return ['name' => 'required|max:255|unique:companies', 'email' => 'required|email|unique:users', 'first_name' => 'required|max:255', 'last_name' => 'required|max:255', 'password' => 'min:5|max:20', 'new_password' => 'min:5|same:confirm_password'];
             }
         }
     }
 }
Exemple #2
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function edit($id)
 {
     $project = \App\Project::findOrFail($id);
     $yearslist = \App\Year::lists('year', 'id');
     $companies = \App\Company::findOrFail($project->company_id);
     $officers_for_dropdown = \App\Officer::lists('last_name', 'id');
     return view('pages.project.edit', compact('project', 'companies', 'officers_for_dropdown', 'yearslist'));
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     $company = Company::findOrFail($id);
     $this->validate($request, ['name' => 'required|unique:companies,name,' . $id . '|max:255']);
     $company->name = $request->input('name');
     $company->description = $request->input('description', "");
     $company->save();
     return redirect()->route('company.index');
 }
 public function destroy($id)
 {
     $company = Company::findOrFail($id);
     $company->delete();
     session()->flash('flash_message_danger', 'Empresa borrada correctamente.');
     //        Si flash_message_important esta presente, el mensaje no desaparece hasta que el usuario lo cierre
     //        session()->flash('flash_message_important', true);
     return redirect('empresas');
 }
 /**
  * @return company  The return value is suspended Company instance.
  */
 public function methodToInvoke($params)
 {
     // check does all parameters are sent
     $requiredParams = ['companyId'];
     $this->checkParameters($params, $requiredParams);
     $company = Company::findOrFail($params['companyId']);
     $company->suspend();
     $company->save();
     return $company;
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Request $request)
 {
     $array_sale_order = ['name' => 'SO' . \DB::table('sale_orders')->max('id'), 'sale_order_time' => Input::get('sale_datetime'), 'subTotal' => Input::get('subtotal'), 'discount' => Input::get('discount'), 'total' => Input::get('total'), 'type' => Input::get('type'), 'partner_id' => Input::get('partner_id'), 'paymentMethod_id' => Input::get('paymentMethod_id')];
     $sale_order_id = SaleOrder::create($array_sale_order);
     $lines = sizeof(Input::get('sale_order_line_product_id'));
     $products_ids = Input::get('sale_order_line_product_id');
     $products_name_ids = Input::get('sale_order_line_name');
     $products_qty_ids = Input::get('sale_order_line_qty');
     $products_unitPrice_ids = Input::get('sale_order_line_unitPrice');
     $products_subTotal_ids = Input::get('sale_order_line_subtotal');
     for ($i = 0; $i < $lines; $i++) {
         $sale_line = ['name' => $products_name_ids[$i], 'qty' => $products_qty_ids[$i], 'unitPrice' => $products_unitPrice_ids[$i], 'subTotal' => $products_subTotal_ids[$i], 'sale_order_id' => $sale_order_id->id, 'product_id' => $products_ids[$i]];
         SaleOrderLine::create($sale_line);
     }
     $saleOrder = $sale_order_id;
     $company = Company::findOrFail(1);
     if (Input::get('type') === 'saleOrder') {
         return view('POS.partials.ticket_report', compact('saleOrder', 'company'));
     } else {
         return view('POS.partials.invoice', compact('saleOrder', 'company'));
     }
 }
 function ordered($date_from_user)
 {
     $arr = [];
     $date_from_user = new Carbon\Carbon($this->formated_date($date_from_user));
     if (!is_null($this->orders)) {
         foreach ($this->orders as $order) {
             $from = new Carbon\Carbon($this->formated_date($order->from));
             $to = new Carbon\Carbon($this->formated_date($order->to));
             if ($date_from_user->between($from, $to)) {
                 //$order = \App\Order::where('from', $from)->where('to', $to)->first();
                 $user = \App\User::findOrFail($order->user_id);
                 $name = $user->name;
                 $company = \App\Company::findOrFail($user->company_id);
                 $updated_time = $order->updated_at;
                 // return array('name'=>$name, 'updated_at'=>$updated_time->toDateTimeString(), 'company'=>$company->name);
                 array_push($arr, array('name' => $name, 'updated_at' => $updated_time->toDateTimeString(), 'company' => $company->name));
             }
         }
     }
     return $arr;
     //print_r($arr);
     //echo count($arr);
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int $id
  * @return Response
  */
 public function destroy($id)
 {
     $company = Company::findOrFail($id);
     $company->delete();
     return redirect('company');
 }
 public function update($id, CompanyRequest $request)
 {
     $company = Company::findOrFail($id);
     $company->update($request->all());
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $user = User::findOrFail($id);
     $date = new \DateTime();
     //this returns the current date time
     //$dtStr = $date->format('Y-m-d-H-i-s');
     //$user->email = $dtStr . '_' . $user->email;
     $user->status = 'INACTIVE';
     $user->inactive_date = $date;
     $user->save();
     $user_role = Auth::user()->role->id;
     $users = $this->getActiveCompanyUsers(null);
     $message = 'You have successfully disabled ' . $user->last_name . ', ' . $user->first_name;
     if ($user_role == 1) {
         $company = Company::findOrFail(Auth::user()->company_id);
         return view('company.show', ['company' => $company, 'users' => $users, 'message' => $message]);
     } else {
         $keyword = '';
         \Session::flash('message', 'You have successfully disabled ' . $user->last_name . ', ' . $user->first_name);
         return Redirect::action('CompanyUserController@index');
     }
 }
Exemple #11
0
 /**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @param  int  $id
  * @return Response
  */
 public function update(Request $request, $id)
 {
     if (Auth::user()->hasRole('member')) {
         $id = Company::where('comUserId', '=', Auth::user()->id)->first()->comId;
     }
     $a = Company::findOrFail($id);
     if (!$a->validate(Input::all())) {
         return redirect('company/' . $id . '/edit')->withErrors($a->errors())->withInput();
     }
     $a->fill(Input::all());
     $a->save();
     Flash::success('Company is updated');
     return Redirect::to('company');
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $company = Company::findOrFail($id);
     $company->delete();
     return redirect()->route('settings.company.index');
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function delete($id)
 {
     $company = Company::findOrFail($id);
     //goals
     DB::table('goal_managements')->whereIn('user_id', function ($query) use($company) {
         $query->select('id')->from('users')->whereRaw('users.company_id = ?', array($company->id));
     })->delete();
     //points
     DB::table('points')->where('company_id', '=', $company->id)->delete();
     //points_audit
     DB::table('point_audits')->where('company_id', '=', $company->id)->delete();
     //sales
     DB::table('sales')->where('company_id', '=', $company->id)->delete();
     //sales_audits
     DB::table('sale_audits')->where('company_id', '=', $company->id)->delete();
     //user_passwords
     DB::table('user_passwords')->whereIn('user_id', function ($query) use($company) {
         $query->select('id')->from('users')->whereRaw('users.company_id = ?', array($company->id));
     })->delete();
     //users
     DB::table('users')->where('company_id', '=', $company->id)->delete();
     //company
     DB::table('companies')->where('id', '=', $company->id)->delete();
     \Session::flash('message', 'You have successfully delete ' . $company->name);
     $keyword = '';
     $companies = Company::paginate(15);
     return view('company.list', compact('companies', 'keyword'));
 }
 /**
  * Return the tooltips in Json.
  *
  * @return Response
  */
 public function tooltips(Request $request)
 {
     $rp_arr = [];
     $user = \Auth::user();
     $data = $request->json()->get('data');
     if ($user->role->name == ('admin' or 'root')) {
         for ($i = 0; $i < count($data); $i++) {
             $location_id = \App\Location::where('name', $data[$i]['location'])->first()['id'];
             $from = Carbon::parse($data[$i]['from']);
             $to = Carbon::parse($data[$i]['to']);
             $orders = \App\Order::where('from', $from)->where('to', $to)->where('location_id', $location_id)->get();
             $tooltip = '';
             for ($j = 0; $j < count($orders); $j++) {
                 $thisUser = \App\User::findOrFail($orders[$j]->user_id);
                 $company = \App\Company::findOrFail($thisUser->company_id);
                 if ($j != 0) {
                     $tooltip .= "\r\n";
                 }
                 $tooltip .= "Ordered by " . $thisUser->name . " from " . $company->name . " at " . $orders[$j]->created_at;
             }
             array_push($rp_arr, ['from' => \Carbon\Carbon::parse($from)->format('d-m-Y'), 'to' => \Carbon\Carbon::parse($to)->format('d-m-Y'), 'location' => $data[$i]['location'], 'tooltip' => $tooltip]);
         }
     } elseif ($user->role->name == 'staff') {
         for ($i = 0; $i < count($data); $i++) {
             $location_id = \App\Location::where('name', $data[$i]['location'])->first()['id'];
             $from = Carbon::parse($data[$i]['from']);
             $to = Carbon::parse($data[$i]['to']);
             $orders = \App\Order::where('from', $from)->where('to', $to)->where('location_id', $location_id)->get();
             $tooltip = '';
             for ($j = 0; $j < count($orders); $j++) {
                 $thisUser = \App\User::findOrFail($orders[$j]->user_id);
                 if ($thisUser->company_id == $user->company_id) {
                     $company = \App\Company::findOrFail($thisUser->company_id);
                     if ($j != 0) {
                         $tooltip .= "\r\n";
                     }
                     $tooltip .= "Ordered by " . $thisUser->name . " from " . $company->name . " at " . $orders[$j]->created_at;
                 }
             }
             array_push($rp_arr, ['from' => \Carbon\Carbon::parse($from)->format('d-m-Y'), 'to' => \Carbon\Carbon::parse($to)->format('d-m-Y'), 'location' => $data[$i]['location'], 'tooltip' => $tooltip]);
         }
     }
     return response()->json(['data' => $rp_arr]);
 }
 public function test_suspend_company_with_command_on_expiration_date()
 {
     $expirationDate = new Carbon('2017-06-30');
     $company = factory(Company::class)->create();
     $user = factory(User::class, 'admin')->create();
     $this->actingAs($user)->visit('/company/' . $company->id . '/edit')->see($company->name)->see('name="licence_expire_at"')->type($expirationDate->toDateString(), 'licence_expire_at')->press('Save Edit')->seeInDatabase('companies', ['id' => $company->id, 'licence_expire_at' => $expirationDate->toDateString(), 'is_suspended' => false])->seeInDatabase('schedules', ['who_object' => Company::class, 'who_id' => $company->id, 'run_at' => $expirationDate->toDateString(), 'action' => ActionCommandSuspendCompanyCommand::class]);
     // enter to testing time - set date to be expiration date
     Carbon::setTestNow($expirationDate);
     $company = Company::findOrFail($company->id);
     $this->assertEquals(false, $company->is_suspended);
     $results = \App\Model\ActionQueue\ActionCommandScheduled::run();
     $company = Company::findOrFail($company->id);
     $this->assertEquals(true, $company->is_suspended);
     // exit from testing time - reset current time
     Carbon::setTestNow();
 }
 /**
  * Update the specified resource in storage.
  * PUT /companies/{id}
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id, Request $request)
 {
     if (!$request->input('name_commercial')) {
         $request->merge(['name_commercial' => $request->input('name_fiscal')]);
     }
     $company = Company::findOrFail($id);
     $address = Address::findOrFail($company->address_id);
     $this->validate($request, Company::$rules);
     $request->merge(['alias' => $address->alias]);
     // Alias is mandatory!
     $this->validate($request, ['address' => Address::$rules]);
     $company->update($request->all());
     $request->merge($request->input('address'));
     // also replace
     $address->update($request->except(['address']));
     return redirect('companies')->with('info', l('This record has been successfully updated &#58&#58 (:id) ', ['id' => $id], 'layouts') . $request->get('name_commercial'));
 }
 function update(CreateCompanyRequest $request, $id)
 {
     $company = Company::findOrFail($id);
     $company->update($request->all());
     return redirect('companies');
 }
 public function activate($id)
 {
     $company = Company::findOrFail($id);
     $company->status = 'ACTIVE';
     $company->save();
     $date = new \DateTime();
     DB::table('users')->where('company_id', $id)->update(array('status' => 'ACTIVE', 'active_date' => $date));
     \Session::flash('message', 'You have successfully activated ' . $company->name);
     $keyword = '';
     $companies = Company::paginate(15);
     return view('company.list', compact('companies', 'keyword'));
 }
Exemple #19
0
 public function getCurrentCompanyAttribute()
 {
     $company = \App\Company::findOrFail($this->current_company_id);
     return $company;
 }
 public function findCompany(Route $route)
 {
     $this->company = \App\Company::findOrFail($route->getParameter('company'));
 }
 /**
  * Prepare data used to send email message
  */
 public function prepare()
 {
     $company = Company::findOrFail($this->companyId);
     $this->receiverObj = new ActionCommandMailReceiver();
     $this->receiverMethodParams = ['mailSubject' => 'Licence Reminder', 'mailFromEmail' => env('MAIL_FROM_ADDRESS'), 'mailFromName' => env('MAIL_FROM_NAME'), 'mailToEmail' => $company->email, 'mailToName' => $company->name, 'template' => 'emails.company-reminder', 'data' => ['company' => $company]];
 }
 public function destroy($id)
 {
     $company = Company::findOrFail($id);
     $company->delete();
     return true;
 }
 public function remove($id)
 {
     $license = License::findOrFail($id);
     $date = new \DateTime();
     //this returns the current date time
     $license->user_id = 0;
     $license->save();
     if ($license->user_id != 0) {
         DB::table('users')->where('id', $license->user_id)->update(array('status' => 'INACTIVE', 'inactive_date' => $date));
     }
     \Session::flash('message', 'You have successfully remove user for this License');
     $company = Company::findOrFail($license->company_id);
     $licenses = License::whereRaw('company_id like ? order by id', array($license->company_id))->paginate(15)->appends(Input::except('page'));
     return view('licenses.list', compact('company', 'licenses'));
 }
Exemple #24
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function ConfirmDelete($id)
 {
     # Get the Company to be deleted
     $company = \App\Company::findOrFail($id);
     return view('pages.company.delete', compact('company'));
 }