Example #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Asset::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['TGL' => $this->TGL, 'KAS_BANK' => $this->KAS_BANK, 'TRAN_JALAN' => $this->TRAN_JALAN, 'INV_LAIN' => $this->INV_LAIN, 'STOK_SAHAM' => $this->STOK_SAHAM, 'HUTANG' => $this->HUTANG, 'HUT_LANCAR' => $this->HUT_LANCAR, 'MODAL' => $this->MODAL, 'CAD_LABA' => $this->CAD_LABA, 'LABA_JALAN' => $this->LABA_JALAN, 'UNIT' => $this->UNIT, 'NAV' => $this->NAV, 'TUMBUH' => $this->TUMBUH]);
     //if(!empty($start)){
     //$query->andFilterWhere(['between', 'TGL', $this->start, $this->end]);
     $query->andFilterWhere(['>=', 'TGL', $this->start]);
     //}
     //if(!empty($end)){
     $query->andFilterWhere(['<=', 'TGL', $this->end]);
     //}
     return $dataProvider;
 }
 /**
  *  Validates and stores an update to an asset maintenance
  *
  * @see AssetMaintenancesController::postEdit() method that stores the data
  * @author  Vincent Sposato <*****@*****.**>
  * @param int $assetMaintenanceId
  * @version v1.0
  * @since [v1.8]
  * @return mixed
  */
 public function postEdit($assetMaintenanceId = null)
 {
     // get the POST data
     $new = Input::all();
     // Check if the asset maintenance exists
     if (is_null($assetMaintenance = AssetMaintenance::find($assetMaintenanceId))) {
         // Redirect to the asset maintenance management page
         return redirect()->to('admin/asset_maintenances')->with('error', trans('admin/asset_maintenances/message.not_found'));
     } elseif (!Company::isCurrentUserHasAccess($assetMaintenance->asset)) {
         return static::getInsufficientPermissionsRedirect();
     }
     if (e(Input::get('supplier_id')) == '') {
         $assetMaintenance->supplier_id = null;
     } else {
         $assetMaintenance->supplier_id = e(Input::get('supplier_id'));
     }
     if (e(Input::get('is_warranty')) == '') {
         $assetMaintenance->is_warranty = 0;
     } else {
         $assetMaintenance->is_warranty = e(Input::get('is_warranty'));
     }
     if (e(Input::get('cost')) == '') {
         $assetMaintenance->cost = '';
     } else {
         $assetMaintenance->cost = e(Input::get('cost'));
     }
     if (e(Input::get('notes')) == '') {
         $assetMaintenance->notes = null;
     } else {
         $assetMaintenance->notes = e(Input::get('notes'));
     }
     $asset = Asset::find(e(Input::get('asset_id')));
     if (!Company::isCurrentUserHasAccess($asset)) {
         return static::getInsufficientPermissionsRedirect();
     }
     // Save the asset maintenance data
     $assetMaintenance->asset_id = e(Input::get('asset_id'));
     $assetMaintenance->asset_maintenance_type = e(Input::get('asset_maintenance_type'));
     $assetMaintenance->title = e(Input::get('title'));
     $assetMaintenance->start_date = e(Input::get('start_date'));
     $assetMaintenance->completion_date = e(Input::get('completion_date'));
     if ($assetMaintenance->completion_date == "" || $assetMaintenance->completion_date == "0000-00-00") {
         $assetMaintenance->completion_date = null;
         if ($assetMaintenance->asset_maintenance_time !== 0 || !is_null($assetMaintenance->asset_maintenance_time)) {
             $assetMaintenance->asset_maintenance_time = null;
         }
     }
     if ($assetMaintenance->completion_date !== "" && $assetMaintenance->completion_date !== "0000-00-00" && $assetMaintenance->start_date !== "" && $assetMaintenance->start_date !== "0000-00-00") {
         $startDate = Carbon::parse($assetMaintenance->start_date);
         $completionDate = Carbon::parse($assetMaintenance->completion_date);
         $assetMaintenance->asset_maintenance_time = $completionDate->diffInDays($startDate);
     }
     // Was the asset maintenance created?
     if ($assetMaintenance->save()) {
         // Redirect to the new asset maintenance page
         return redirect()->to("admin/asset_maintenances")->with('success', trans('admin/asset_maintenances/message.create.success'));
     }
     return redirect()->back()->withInput()->withErrors($assetMaintenance->getErrors());
 }
Example #3
0
 public function actionExportPdfDetail($tgl)
 {
     $dates = $this->getDates($tgl);
     $asset = Asset::find()->where(['TGL' => $dates[0]])->one();
     $assetat = Assetat::find()->where(['TGL' => $dates[2]])->one();
     $searchModel = new IndikatorSearch(['TGL' => $tgl]);
     $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
     $html = $this->renderPartial('_detail_pdf', ['asset' => $asset, 'assetat' => $assetat, 'dataProvider' => $dataProvider, 'dates' => $dates]);
     //function mPDF($mode='',$format='A4',$default_font_size=0,$default_font='',$mgl=15,$mgr=15,$mgt=16,$mgb=16,$mgh=9,$mgf=9, $orientation='P') {
     $mpdf = new \mPDF('c', 'A4', 0, '', 15, 10, 15, 10, 10, 10);
     $header = ['L' => ['content' => date('d-M-Y H:i:s'), 'font-family' => 'sans', 'font-style' => '', 'font-size' => '9'], 'C' => [], 'R' => ['content' => 'Page {PAGENO} of {nbpg}', 'font-family' => 'sans', 'font-style' => '', 'font-size' => '9'], 'line' => 1];
     $mpdf->SetFooter($header, 'O');
     $mpdf->SetDisplayMode('fullpage');
     $mpdf->list_indent_first_level = 0;
     // 1 or 0 - whether to indent the first level of a list
     $mpdf->WriteHTML($html);
     $mpdf->Output($this->id . '_' . date('YmdHis') . '.pdf', 'D');
     exit;
 }
Example #4
0
 public function postBulkCheckout(Request $request)
 {
     $this->validate($request, ["assigned_to" => 'required']);
     $user = User::find(e(Input::get('assigned_to')));
     $admin = Auth::user();
     $asset_ids = array_filter(Input::get('selected_assets'));
     if (Input::has('checkout_at') && Input::get('checkout_at') != date("Y-m-d")) {
         $checkout_at = e(Input::get('checkout_at'));
     } else {
         $checkout_at = date("Y-m-d H:i:s");
     }
     if (Input::has('expected_checkin')) {
         $expected_checkin = e(Input::get('expected_checkin'));
     } else {
         $expected_checkin = '';
     }
     $has_errors = false;
     $errors = [];
     DB::transaction(function () use($user, $admin, $checkout_at, $expected_checkin, $errors, $asset_ids) {
         foreach ($asset_ids as $asset_id) {
             $asset = Asset::find($asset_id);
             $error = $asset->checkOutToUser($user, $admin, $checkout_at, $expected_checkin, e(Input::get('note')), null);
             if ($error) {
                 $has_errors = true;
                 array_merge_recursive($errors, $asset->getErrors()->toArray());
             }
         }
     });
     if (!$errors) {
         // Redirect to the new asset page
         return redirect()->to("hardware")->with('success', trans('admin/hardware/message.checkout.success'));
     }
     // Redirect to the asset management page with error
     return redirect()->to("hardware/bulk-checkout")->with('error', trans('admin/hardware/message.checkout.error'))->withErrors($errors);
 }
Example #5
0
 /**
  * Validate and store checkout data.
  *
  * @author [A. Gianotto] [<*****@*****.**>]
  * @see ComponentsController::getCheckout() method that returns the form.
  * @since [v3.0]
  * @param int $componentId
  * @return Redirect
  */
 public function postCheckout(Request $request, $componentId)
 {
     // Check if the component exists
     if (is_null($component = Component::find($componentId))) {
         // Redirect to the component management page with error
         return redirect()->to('components')->with('error', trans('admin/components/message.not_found'));
     } elseif (!Company::isCurrentUserHasAccess($component)) {
         return redirect()->to('admin/components')->with('error', trans('general.insufficient_permissions'));
     }
     $max_to_checkout = $component->numRemaining();
     $validator = Validator::make($request->all(), ["asset_id" => "required", "assigned_qty" => "required|numeric|between:1,{$max_to_checkout}"]);
     if ($validator->fails()) {
         return redirect()->back()->withErrors($validator)->withInput();
     }
     $admin_user = Auth::user();
     $asset_id = e(Input::get('asset_id'));
     // Check if the user exists
     if (is_null($asset = Asset::find($asset_id))) {
         // Redirect to the component management page with error
         return redirect()->to('admin/components')->with('error', trans('admin/components/message.asset_does_not_exist'));
     }
     // Update the component data
     $component->asset_id = $asset_id;
     $component->assets()->attach($component->id, array('component_id' => $component->id, 'user_id' => $admin_user->id, 'created_at' => date('Y-m-d h:i:s'), 'assigned_qty' => e(Input::get('assigned_qty')), 'asset_id' => $asset_id));
     $logaction = new Actionlog();
     $logaction->component_id = $component->id;
     $logaction->asset_id = $asset_id;
     $logaction->asset_type = 'component';
     $logaction->location_id = $asset->location_id;
     $logaction->user_id = Auth::user()->id;
     $logaction->note = e(Input::get('note'));
     $settings = Setting::getSettings();
     if ($settings->slack_endpoint) {
         $slack_settings = ['username' => $settings->botname, 'channel' => $settings->slack_channel, 'link_names' => true];
         $client = new \Maknz\Slack\Client($settings->slack_endpoint, $slack_settings);
         try {
             $client->attach(['color' => 'good', 'fields' => [['title' => 'Checked Out:', 'value' => strtoupper($logaction->asset_type) . ' <' . config('app.url') . '/admin/components/' . $component->id . '/view' . '|' . $component->name . '> checked out to <' . config('app.url') . '/hardware/' . $asset->id . '/view|' . $asset->showAssetName() . '> by <' . config('app.url') . '/admin/users/' . $admin_user->id . '/view' . '|' . $admin_user->fullName() . '>.'], ['title' => 'Note:', 'value' => e($logaction->note)]]])->send('Component Checked Out');
         } catch (Exception $e) {
         }
     }
     $log = $logaction->logaction('checkout');
     // Redirect to the new component page
     return redirect()->to("admin/components")->with('success', trans('admin/components/message.checkout.success'));
 }
 /**
  * Validates and stores the license checkout action.
  *
  * @todo Switch to using a FormRequest for validation here.
  * @author [A. Gianotto] [<*****@*****.**>]
  * @since [v1.0]
  * @param int $seatId
  * @return Redirect
  */
 public function postCheckout($seatId)
 {
     $licenseseat = LicenseSeat::find($seatId);
     $assigned_to = e(Input::get('assigned_to'));
     $asset_id = e(Input::get('asset_id'));
     $user = Auth::user();
     if (!Company::isCurrentUserHasAccess($licenseseat->license)) {
         return redirect()->to('admin/licenses')->with('error', trans('general.insufficient_permissions'));
     }
     // Declare the rules for the form validation
     $rules = array('note' => 'string', 'asset_id' => 'required_without:assigned_to');
     // Create a new validator instance from our validation rules
     $validator = Validator::make(Input::all(), $rules);
     // If validation fails, we'll exit the operation now.
     if ($validator->fails()) {
         // Ooops.. something went wrong
         return redirect()->back()->withInput()->withErrors($validator);
     }
     if ($assigned_to != '') {
         // Check if the user exists
         if (is_null($is_assigned_to = User::find($assigned_to))) {
             // Redirect to the asset management page with error
             return redirect()->to('admin/licenses')->with('error', trans('admin/licenses/message.user_does_not_exist'));
         }
     }
     if ($asset_id != '') {
         if (is_null($asset = Asset::find($asset_id))) {
             // Redirect to the asset management page with error
             return redirect()->to('admin/licenses')->with('error', trans('admin/licenses/message.asset_does_not_exist'));
         }
         if ($asset->assigned_to != '' && $asset->assigned_to != $assigned_to && $assigned_to != '') {
             return redirect()->to('admin/licenses')->with('error', trans('admin/licenses/message.owner_doesnt_match_asset'));
         }
     }
     // Check if the asset exists
     if (is_null($licenseseat)) {
         // Redirect to the asset management page with error
         return redirect()->to('admin/licenses')->with('error', trans('admin/licenses/message.not_found'));
     }
     if (Input::get('asset_id') == '') {
         $licenseseat->asset_id = null;
     } else {
         $licenseseat->asset_id = e(Input::get('asset_id'));
     }
     // Update the asset data
     if (e(Input::get('assigned_to')) == '') {
         $licenseseat->assigned_to = null;
     } else {
         $licenseseat->assigned_to = e(Input::get('assigned_to'));
     }
     // Was the asset updated?
     if ($licenseseat->save()) {
         $logaction = new Actionlog();
         //$logaction->location_id = $assigned_to->location_id;
         $logaction->asset_type = 'software';
         $logaction->user_id = Auth::user()->id;
         $logaction->note = e(Input::get('note'));
         $logaction->asset_id = $licenseseat->license_id;
         $license = License::find($licenseseat->license_id);
         $settings = Setting::getSettings();
         // Update the asset data
         if (e(Input::get('assigned_to')) == '') {
             $logaction->checkedout_to = null;
             $slack_msg = strtoupper($logaction->asset_type) . ' license <' . config('app.url') . '/admin/licenses/' . $license->id . '/view' . '|' . $license->name . '> checked out to <' . config('app.url') . '/hardware/' . $asset->id . '/view|' . $asset->showAssetName() . '> by <' . config('app.url') . '/admin/users/' . $user->id . '/view' . '|' . $user->fullName() . '>.';
         } else {
             $logaction->checkedout_to = e(Input::get('assigned_to'));
             $slack_msg = strtoupper($logaction->asset_type) . ' license <' . config('app.url') . '/admin/licenses/' . $license->id . '/view' . '|' . $license->name . '> checked out to <' . config('app.url') . '/admin/users/' . $user->id . '/view|' . $is_assigned_to->fullName() . '> by <' . config('app.url') . '/admin/users/' . $user->id . '/view' . '|' . $user->fullName() . '>.';
         }
         if ($settings->slack_endpoint) {
             $slack_settings = ['username' => $settings->botname, 'channel' => $settings->slack_channel, 'link_names' => true];
             $client = new \Maknz\Slack\Client($settings->slack_endpoint, $slack_settings);
             try {
                 $client->attach(['color' => 'good', 'fields' => [['title' => 'Checked Out:', 'value' => $slack_msg], ['title' => 'Note:', 'value' => e($logaction->note)]]])->send('License Checked Out');
             } catch (Exception $e) {
             }
         }
         $log = $logaction->logaction('checkout');
         // Redirect to the new asset page
         return redirect()->to("admin/licenses")->with('success', trans('admin/licenses/message.checkout.success'));
     }
     // Redirect to the asset management page with error
     return redirect()->to('admin/licenses/$assetId/checkout')->with('error', trans('admin/licenses/message.create.error'))->with('license', new License());
 }
Example #7
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $staff = Asset::find($id);
     $staff->delete();
     return redirect()->route('asset.index')->withMessage('Asset Item Deleted')->withStatus('success');
 }
Example #8
0
 /**
  * Save bulk deleted.
  *
  * @author [A. Gianotto] [<*****@*****.**>]
  * @param  array  $assets
  * @since [v2.0]
  * @return View
  */
 public function postBulkDelete($assets = null)
 {
     if (!Company::isCurrentUserAuthorized()) {
         return redirect()->to('hardware')->with('error', trans('general.insufficient_permissions'));
     } elseif (Input::has('bulk_edit')) {
         //$assets = Input::get('bulk_edit');
         $assets = Asset::find(Input::get('bulk_edit'));
         //print_r($assets);
         foreach ($assets as $asset) {
             //echo '<li>'.$asset;
             $update_array['deleted_at'] = date('Y-m-d h:i:s');
             $update_array['assigned_to'] = null;
             if (DB::table('assets')->where('id', $asset->id)->update($update_array)) {
                 $logaction = new Actionlog();
                 $logaction->asset_id = $asset->id;
                 $logaction->asset_type = 'hardware';
                 $logaction->created_at = date("Y-m-d H:i:s");
                 $logaction->user_id = Auth::user()->id;
                 $log = $logaction->logaction('deleted');
             }
         }
         // endforeach
         return redirect()->to("hardware")->with('success', trans('admin/hardware/message.delete.success'));
         // no values given, nothing to update
     } else {
         return redirect()->to("hardware")->with('info', trans('admin/hardware/message.delete.nothing_updated'));
     }
     // Something weird happened here - default to hardware
     return redirect()->to("hardware");
 }
 public function getAcceptAsset($logID = null)
 {
     if (!($findlog = DB::table('asset_logs')->where('id', '=', $logID)->first())) {
         echo 'no record';
         //return redirect()->to('account')->with('error', trans('admin/hardware/message.does_not_exist'));
     }
     $user = Auth::user();
     if ($user->id != $findlog->checkedout_to) {
         return redirect()->to('account/view-assets')->with('error', trans('admin/users/message.error.incorrect_user_accepted'));
     }
     // Asset
     if ($findlog->asset_id != '' && $findlog->asset_type == 'hardware') {
         $item = Asset::find($findlog->asset_id);
         // software
     } elseif ($findlog->asset_id != '' && $findlog->asset_type == 'software') {
         $item = License::find($findlog->asset_id);
         // accessories
     } elseif ($findlog->accessory_id != '') {
         $item = Accessory::find($findlog->accessory_id);
         // consumable
     } elseif ($findlog->consumable_id != '') {
         $item = Consumable::find($findlog->consumable_id);
         // components
     } elseif ($findlog->component_id != '') {
         $item = Component::find($findlog->component_id);
     }
     // Check if the asset exists
     if (is_null($item)) {
         // Redirect to the asset management page
         return redirect()->to('account')->with('error', trans('admin/hardware/message.does_not_exist'));
     } elseif (!Company::isCurrentUserHasAccess($item)) {
         return redirect()->route('requestable-assets')->with('error', trans('general.insufficient_permissions'));
     } else {
         return View::make('account/accept-asset', compact('item'))->with('findlog', $findlog);
     }
 }