public function run() { $faker = Faker::create(); foreach (range(1, 10) as $index) { $size = rand(100, 300); $user_id = rand(1, 10); UnitType::create(['name' => $faker->word(), 'project_id' => rand(1, 7), 'building_area' => $size, 'land_area' => $size + rand(100, 300), 'base_price' => rand(100000000, 500000000), 'added_facility_price' => rand(1000000, 5000000), 'added_area_price' => rand(1000000, 5000000), 'created_by' => $user_id, 'changed_by' => $user_id, 'change_reason' => $faker->realText(100)]); } }
public static function setUnitType($newUnitType) { if (UnitType::exists($newUnitTye)) { $db = self::getInstance(); $user = new User(); $userId = $user->data()->id; $sql = "UPDATE `Unit` SET `Unit`.`UnitType` = ? WHERE `Unit`.`Name` = ? AND `Unit`.`user` = ?;"; if ($db->query($sql, [$newUnitType, $userId])) { return true; } else { return false; } } else { return false; } }
public static function delete($id) { $connection = Flight::dbMain(); try { /* Begin Transaction */ $connection->beginTransaction(); /*Query 1 Select unit*/ $sql = "SELECT * FROM unit WHERE id = :id;"; $query = $connection->prepare($sql); $query->bindParam(':id', $id, PDO::PARAM_INT); $query->execute(); $rows = $query->fetchAll(PDO::FETCH_ASSOC); $row = $rows[0]; $unit = new Unit(); $unit->Id = (int) $row['id']; $unit->Imei = $row['unit_imei']; $unit->DtCreated = $row['unit_dt_created']; $unit->SerialNumber = $row['unit_serial_number']; $unit->Sim = Sim::select($row['sim_id']); $unit->UnitStatus = UnitStatus::select($row['e_status_unit_id']); $unit->UnitType = UnitType::select($row['unit_type_id']); $unit->Company = Company::select($row['company_id']); /*Query 2 Delete unit*/ $sql = "\n\t\t\tDELETE FROM unit \n\t\t\tWHERE\n\t\t\tid = :id"; $query = $connection->prepare($sql); $query->bindParam(':id', $id, PDO::PARAM_INT); $query->execute(); /*Query 3 Drop data_unit.imei table*/ $year = date('Y'); $schema = "app_data_{$year}"; $imei = $unit->Imei; $tableName = "data_{$imei}"; $sql = "\n\t\t\t\n\t\t\tDROP TABLE IF EXISTS {$schema}.{$tableName};\n\n\t\t\t"; $query = $connection->prepare($sql); $query->execute(); $connection->commit(); $result = new Result(); $result->Status = Result::DELETED; $result->Message = 'Done'; $result->Id = $id; return $result; } catch (PDOException $pdoException) { $connection->rollBack(); throw $pdoException; } catch (Exception $exception) { $connection->rollBack(); throw $exception; } finally { $connection = null; } }
/** * function for send ajax request to view * * @return Response */ public function listingJson() { $query = UnitType::select('id', 'name', 'project_id', 'building_area', 'base_price', 'changed_by')->with('User')->with('Project')->get(); return Datatable::collection($query)->addColumn('name', function ($model) { return ucfirst($model->name); })->addColumn('project_id', function ($model) { // return $model->project_id; return ucfirst($model->project->name); })->addColumn('building_area', function ($model) { return $model->building_area; })->addColumn('base_price', function ($model) { return $model->base_price; })->addColumn('changed_by', function ($model) { return $model->user->name; })->addColumn('show', function ($model) { return '<a href="' . action('UnitTypesController@detail', $model->id) . '" class="btn btn-small btn-primary btn-constant"><i class="fa fa-eye fa-fw"></i></a>'; })->addColumn('edit', function ($model) { return '<a href="' . action('UnitTypesController@edit', $model->id) . '" class="btn btn-small btn-success btn-constant"><i class="fa fa-edit fa-fw"></i></a>'; })->addColumn('delete', function ($model) { return '<form action="' . action('UnitTypesController@delete', $model->id) . '" method="POST"><button type="submit" class="btn btn-small btn-danger btn-constant" onclick = "return confirm(\'Are you sure?\')"><i class="fa fa-times fa-fw"></i></button></form>'; })->searchColumns('block', 'additional_land_area', 'status_id')->orderColumns('id', 'block', 'unit_type_id', 'additional_land_area', 'additional_facility')->make(); }
</div> <div class="row"> <div class="col-md-3"> Unit Type <span class="pull-right">:</span> </div> <div class="col-md-9"> <a href="{{ URL::action('UnitTypesController@detail', $unit->unit_type_id) }}">{{{ucfirst($unit->unitType->name)}}}</a> </div> </div> <div class="row"> <div class="col-md-3"> Project Name <span class="pull-right">:</span> </div> <div class="col-md-9"> <?php $unit_type = UnitType::findOrFail($unit->unitType->id); ?> <a href="{{ URL::action('ProjectsController@detail', $unit_type->project->id) }}">{{{ucfirst($unit_type->project->name)}}}</a> </div> </div> <div class="row"> <div class="col-md-3"> Additional Land Area <span class="pull-right">:</span> </div> <div class="col-md-9"> {{{$unit->additional_land_area}}} meters </div> </div> <div class="row"> <div class="col-md-3"> Additional Facility <span class="pull-right">:</span>
Flight::ok($object); } catch (Exception $exception) { Flight::error($exception); } }); Flight::route('PUT /v1/main/unittype/@id', function ($id) { try { $object = UnitType::update($id); Flight::ok($object); } catch (Exception $exception) { Flight::error($exception); } }); Flight::route('DELETE /v1/main/unittype/@id', function ($id) { try { $object = UnitType::delete($id); Flight::ok($object); } catch (Exception $exception) { Flight::error($exception); } }); //============================================================================= //UnitStatus //============================================================================= Flight::route('GET /v1/main/unitstatus', function () { try { $array = UnitStatus::selectAll(); Flight::ok($array); } catch (Exception $exception) { Flight::error($exception); }
/** * function for send ajax request to view * * @return Response */ public function listingJson() { $query = BookedUnit::select('id', 'unit_id', 'customer_id', 'is_valid', 'changed_by')->with('User')->with('Unit')->with('Customer')->get(); return Datatable::collection($query)->addColumn('unit_id_block', function ($model) { return ucfirst($model->unit->block); })->addColumn('unit_id', function ($model) { $unit_type = UnitType::findOrFail($model->unit->id); return ucfirst($unit_type->name); // return $model->unit_id; })->addColumn('customer_id', function ($model) { return $model->customer->name; // return $model->project->name . $model->project_id; })->addColumn('is_valid', function ($model) { $is_valid = $model->is_valid == '1' ? 'Yes' : 'No'; return $is_valid; })->addColumn('changed_by', function ($model) { return $model->user->name; })->addColumn('show', function ($model) { return '<a href="' . action('BookedUnitsController@detail', $model->id) . '" class="btn btn-small btn-primary btn-constant"><i class="fa fa-eye fa-fw"></i></a>'; })->addColumn('edit', function ($model) { return '<a href="' . action('BookedUnitsController@edit', $model->id) . '" class="btn btn-small btn-success btn-constant"><i class="fa fa-edit fa-fw"></i></a>'; })->addColumn('delete', function ($model) { return '<form action="' . action('BookedUnitsController@delete', $model->id) . '" method="POST"><button type="submit" class="btn btn-small btn-danger btn-constant" onclick = "return confirm(\'Are you sure?\')"><i class="fa fa-times fa-fw"></i></button></form>'; })->searchColumns('id', 'unit_id_block', 'customer_id')->orderColumns('id', 'unit_id_block', 'customer_id', 'is_valid', 'changed_by')->make(); }