public function testDelete()
 {
     $idDelete = Part::all()->last()['id'];
     $this->seeInDatabase('parts', ['id' => $idDelete]);
     $this->visit('/part/destroy/' . $idDelete);
     $this->seeIsSoftDeletedInDatabase('parts', ['id' => $idDelete]);
 }
Exemple #2
0
 public static function boot()
 {
     parent::boot();
     Part::creating(function ($parts) {
         $parts->company_id = $parts->company_id ?: Auth::user()['company_id'];
     });
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::table('parts')->delete();
     Part::forceCreate(['vehicle_id' => 1, 'vendor_id' => 2, 'part_type_id' => 10, 'part_model_id' => 2, 'cost' => 200, 'name' => 'Part Name', 'number' => '123456', 'miliage' => 250, 'position' => 2, 'lifecycle' => 500, 'company_id' => 1]);
     Part::forceCreate(['vehicle_id' => 1, 'vendor_id' => 2, 'part_type_id' => 11, 'part_id' => 1, 'part_model_id' => 2, 'cost' => 200, 'name' => 'Part Sensor', 'number' => '123456', 'miliage' => 250, 'position' => 2, 'lifecycle' => 500, 'company_id' => 1]);
     Part::forceCreate(['vehicle_id' => 1, 'vendor_id' => 2, 'part_type_id' => 10, 'part_model_id' => 2, 'cost' => 200, 'name' => 'Part Name', 'number' => '123456', 'miliage' => 250, 'position' => 3, 'lifecycle' => 500, 'company_id' => 1]);
     Part::forceCreate(['vehicle_id' => 1, 'vendor_id' => 2, 'part_type_id' => 11, 'part_id' => 3, 'part_model_id' => 2, 'cost' => 200, 'name' => 'Part Sensor', 'number' => '123456', 'miliage' => 250, 'position' => 3, 'lifecycle' => 500, 'company_id' => 1]);
 }
 public function testSort()
 {
     $idPart = Part::select('parts.id')->join('types', 'types.id', '=', 'parts.part_type_id')->where('types.entity_key', 'part')->where('types.name', 'sensor')->first()['id'];
     factory(\App\Entities\TireSensor::class)->create(['part_id' => $idPart]);
     $url = '/part/' . $idPart . '/edit?id=&temperature=&pressure=&battery=&latitude=&longitude=&number=';
     $this->visit($url . '&sort=temperature-asc')->see('mdl-cell--1-col mdl-data-table__cell--non-numeric">');
     $this->visit($url . '&sort=id-asc')->see('mdl-cell--1-col mdl-data-table__cell--non-numeric">');
     $this->visit($url . '&sort=vehicle-desc')->see('mdl-cell--1-col mdl-data-table__cell--non-numeric">');
     $this->visit($url . '&sort=vehicle-asc')->see('mdl-cell--1-col mdl-data-table__cell--non-numeric">');
     $this->visit($url . '&sort=part-type-desc')->see('mdl-cell--1-col mdl-data-table__cell--non-numeric">');
     $this->visit($url . '&sort=part-type-asc')->see('mdl-cell--1-col mdl-data-table__cell--non-numeric">');
     $this->visit($url . '&sort=cost-desc')->see('mdl-cell--1-col mdl-data-table__cell--non-numeric">');
     $this->visit($url . '&sort=cost-asc')->see('mdl-cell--1-col mdl-data-table__cell--non-numeric">');
 }
 private function getFleetTireAndSensorParts(&$partsData, $vehicleId = null, $partsIds = null)
 {
     $partsQuery = Part::select('parts.id', 'parts.position', 'parts.vehicle_id')->join('types', 'parts.part_type_id', '=', 'types.id')->whereNotNull('parts.vehicle_id')->where('parts.company_id', Auth::user()['company_id'])->where('types.name', 'sensor');
     if (!empty($vehicleId)) {
         $partsQuery = $partsQuery->where('parts.vehicle_id', $vehicleId);
     }
     if (!empty($partsIds)) {
         $partsQuery = $partsQuery->whereIn('parts.id', $partsIds);
     }
     $partsResult = $partsQuery->get();
     $parts = [];
     $partsData = [];
     if (count($partsResult) > 0) {
         foreach ($partsResult as $part) {
             $parts[] = $part->id;
             $partsData[$part->id]['position'] = $part->position;
             $partsData[$part->id]['vehicle_id'] = $part->vehicle_id;
         }
     }
     return $parts;
 }
Exemple #6
0
 public function setUp($lang = null)
 {
     $company = Company::forceCreate(['name' => $this->name . ' Inc.']);
     $company->save();
     $this->setUserProperties($company, $lang);
     $this->createGenericTypes($company);
     $typeTire = Type::forceCreate(['entity_key' => 'part', 'name' => Lang::get('setup.tire'), 'company_id' => $company->id]);
     $typeSensor = Type::forceCreate(['entity_key' => 'part', 'name' => Lang::get('setup.sensor'), 'company_id' => $company->id]);
     $typeCar = Type::forceCreate(['entity_key' => 'vehicle', 'name' => Lang::get('setup.car'), 'company_id' => $company->id]);
     $typeTruck = Type::forceCreate(['entity_key' => 'vehicle', 'name' => Lang::get('setup.truck'), 'company_id' => $company->id]);
     $typeVendor = Type::forceCreate(['entity_key' => 'contact', 'name' => Lang::get('setup.vendor'), 'company_id' => $company->id]);
     $typeDriver = Type::forceCreate(['entity_key' => 'contact', 'name' => Lang::get('setup.driver'), 'company_id' => $company->id]);
     $contactDetail = $this->createContact($this->name, $company->id);
     $company->contact_id = $contactDetail->id;
     $company->save();
     $contactVendor = Contact::forceCreate(['company_id' => $company->id, 'contact_type_id' => $typeVendor->id, 'name' => Lang::get('setup.GenericVendor'), 'license_no' => '123456']);
     Contact::forceCreate(['company_id' => $company->id, 'contact_type_id' => $typeDriver->id, 'name' => Lang::get('setup.GenericDriver'), 'license_no' => '123456']);
     $modelCar = Model::forceCreate(['model_type_id' => $typeCar->id, 'vendor_id' => $contactVendor->id, 'name' => Lang::get('setup.GenericCar'), 'company_id' => $company->id]);
     Model::forceCreate(['model_type_id' => $typeTruck->id, 'vendor_id' => $contactVendor->id, 'name' => Lang::get('setup.GenericTruck'), 'company_id' => $company->id]);
     Model::forceCreate(['model_type_id' => $typeTire->id, 'name' => Lang::get('setup.GenericTire'), 'company_id' => $company->id]);
     $modelSensor = Model::forceCreate(['model_type_id' => $typeSensor->id, 'name' => Lang::get('setup.GenericSensor'), 'company_id' => $company->id]);
     $vehicle = Vehicle::forceCreate(['model_vehicle_id' => $modelCar->id, 'number' => Lang::get('setup.VehiclePlate'), 'initial_miliage' => 123, 'actual_miliage' => 123, 'cost' => 50000, 'description' => Lang::get('setup.GenericVehicle'), 'company_id' => $company->id]);
     Part::forceCreate(['vehicle_id' => $vehicle->id, 'vendor_id' => $contactVendor->id, 'part_type_id' => $typeSensor->id, 'part_model_id' => $modelSensor->id, 'cost' => 1, 'name' => Lang::get('setup.GenericSensor'), 'number' => '0000000001', 'miliage' => 1, 'position' => 1, 'lifecycle' => 1, 'company_id' => $company->id]);
 }
 public function testDeleteExecutive()
 {
     $this->get('/part/destroy/' . Part::all()->last()['id'])->assertResponseStatus(302);
 }
 public function testPositionAdd()
 {
     $this->post('/tires/position/add', ['part_id' => Part::where('position', 0)->first()['id'], 'position' => 2, 'vehicle_id' => 1, "_token" => csrf_token()])->assertResponseStatus(200);
 }
 public function getTireAndSensorData($inputs)
 {
     $tire = Part::join('types', 'parts.part_type_id', '=', 'types.id')->where('parts.position', $inputs['position'])->where('parts.vehicle_id', $inputs['vehicle_id'])->where('parts.company_id', Auth::user()['company_id'])->where('types.name', 'tire')->first();
     $objTire = new \stdClass();
     if (!empty($tire)) {
         $sensor = TireSensor::join('parts', 'tire_sensor.part_id', '=', 'parts.id')->join('types', 'parts.part_type_id', '=', 'types.id')->where('parts.part_id', $tire->id)->where('parts.position', $inputs['position'])->where('parts.vehicle_id', $inputs['vehicle_id'])->where('parts.company_id', Auth::user()['company_id'])->where('types.name', 'sensor')->orderBy('parts.id', 'desc')->first();
         $objTire->position = HelperRepository::manageEmptyValue($tire->position);
         $objTire->number = HelperRepository::manageEmptyValue($tire->number);
         $objTire->model = HelperRepository::manageEmptyValue($tire->partModel->name);
         $objTire->lifecycle = HelperRepository::manageEmptyValue($tire->lifecycle);
         $objTire->miliage = HelperRepository::manageEmptyValue($tire->miliage);
     } else {
         $objTire->position = "";
         $objTire->number = "";
         $objTire->model = "";
         $objTire->lifecycle = "";
         $objTire->miliage = "";
     }
     if (!empty($sensor)) {
         $objTire->temperature = HelperRepository::manageEmptyValue($sensor->temperature);
         $objTire->pressure = HelperRepository::manageEmptyValue($sensor->pressure);
         $objTire->battery = HelperRepository::manageEmptyValue($sensor->battery);
         $objTire->sensorNumber = HelperRepository::manageEmptyValue($sensor->number);
     } else {
         $objTire->temperature = "";
         $objTire->pressure = "";
         $objTire->battery = "";
         $objTire->sensorNumber = "";
     }
     return $objTire;
 }
 public function getTiresTypeId()
 {
     $result = Part::select('types.id')->join('models', 'parts.part_model_id', '=', 'models.id')->join('types', 'parts.part_type_id', '=', 'types.id')->where('parts.company_id', Auth::user()['company_id'])->where('types.name', 'tire')->first();
     if (!empty($result->id)) {
         return $result->id;
     } else {
         return null;
     }
 }
 public static function getParts($idCurrentPart = null, $optionalChoice = false)
 {
     $parts = Part::where('company_id', Auth::user()['company_id']);
     if (!empty($idCurrentPart)) {
         $parts = $parts->where('id', '!=', $idCurrentPart);
     }
     $parts = $parts->lists('number', 'id');
     if ($optionalChoice) {
         $parts->prepend("", "");
     }
     return $parts;
 }