From 9c74e989599c7b5a64f919ab84da3dbdffe57c80 Mon Sep 17 00:00:00 2001
From: Azfar Arsyad <45238748+Arpax17@users.noreply.github.com>
Date: Sun, 5 Dec 2021 16:58:02 +0800
Subject: [PATCH] update
---
app/Http/Controllers/PenggunaController.php | 79 +++++-
app/Models/User.php | 2 +-
config/app.php | 2 +
config/dompdf.php | 244 ++++++++++++++++++
database/factories/UserFactory.php | 2 +-
.../2014_10_12_000000_create_users_table.php | 2 +-
..._11_10_134257_create_permission_tables.php | 5 +-
database/seeders/RolesSeeder.php | 115 +++++++--
resources/views/includes/header.blade.php | 2 +-
resources/views/includes/sidebar.blade.php | 4 +-
resources/views/pdf/edit.blade.php | 54 ++++
resources/views/pdf/penggunapdf.blade.php | 66 +++++
resources/views/pdf/rolespdf.blade.php | 54 ++++
resources/views/pdf/tarafpdf.blade.php | 61 +++++
resources/views/pdf/testpdf.blade.php | 1 -
.../views/pengurusanpengguna/index.blade.php | 93 +++----
.../views/pengurusanpengguna/roles.blade.php | 67 ++---
.../views/pengurusanpengguna/show.blade.php | 5 +-
.../pengurusanpengguna/showrole.blade.php | 57 ++++
.../pengurusanpengguna/showtaraf.blade.php | 31 ++-
.../views/pengurusanpengguna/taraf.blade.php | 1 +
resources/views/welcome.blade.php | 4 +-
routes/web.php | 4 +-
23 files changed, 823 insertions(+), 132 deletions(-)
create mode 100644 config/dompdf.php
create mode 100644 resources/views/pdf/edit.blade.php
create mode 100644 resources/views/pdf/penggunapdf.blade.php
create mode 100644 resources/views/pdf/rolespdf.blade.php
create mode 100644 resources/views/pdf/tarafpdf.blade.php
delete mode 100644 resources/views/pdf/testpdf.blade.php
create mode 100644 resources/views/pengurusanpengguna/showrole.blade.php
diff --git a/app/Http/Controllers/PenggunaController.php b/app/Http/Controllers/PenggunaController.php
index 47aa511d..fb283890 100644
--- a/app/Http/Controllers/PenggunaController.php
+++ b/app/Http/Controllers/PenggunaController.php
@@ -7,6 +7,7 @@ use Spatie\Permission\Models\Role;
use Spatie\Permission\Models\Permission;
use Illuminate\Support\Facades\Auth;
use App\Models\User;
+use PDF;
class PenggunaController extends Controller
{
@@ -64,7 +65,7 @@ class PenggunaController extends Controller
// dd($arraytaraf);
$user->syncRoles($arraytaraf);
return redirect()->route('pengguna.index')
- ->with('success','Tukar Taraf Berjaya');
+ ->with('success','Kemaskini Berjaya');
}
public function delete($userid)
@@ -120,12 +121,12 @@ class PenggunaController extends Controller
// $user = Auth::user();
// $user->assignRole('admin');
return redirect()->route('pengguna.taraf')
- ->with('success','Tukar Roles Berjaya');
+ ->with('success','Kemaskini Berjaya');
}
- public function deletetaraf($roleid)
+ public function deletetaraf($tarafid)
{
- $taraf = Role::where('id','=',$roleid)->first();
+ $taraf = Role::where('id','=',$tarafid)->first();
$taraf->delete();
return redirect()->route('pengguna.taraf')
@@ -140,6 +141,20 @@ class PenggunaController extends Controller
return view('pengurusanpengguna.roles',compact('allpermission'));
}
+ public function showrole($roleid) //roles = permissions in db
+ {
+ $permission = Permission::where('id','=',$roleid)->first();
+ // $user = Auth::user();
+ // $user->assignRole('admin');
+ return view('pengurusanpengguna.showrole',compact('permission'));
+ }
+
+ public function storerole(Request $request)
+ {
+ $role = Permission::where('id','=',$request->idrole)->first();
+ return redirect()->route('pengguna.roles')
+ ->with('success','Kemaskini Berjaya');
+ }
public function updateroles(Request $request)
{
$user = User::where('id','=',$request->id);
@@ -160,12 +175,58 @@ class PenggunaController extends Controller
public function export(Request $request)
{
- dd(request()->all());
- $data = $request;
- $pdf = PDF::loadView('pdf.testpdf', $data);
- return $pdf->download('invoice.pdf');
+ if($request->type =='Role' || $request->type =='Permission')
+ {
+ $model_name = '\\Spatie\\Permission\\Models\\'.$request->type;
+ }
+ else
+ {
+ $model_name = '\\App\\Models\\'.$request->type;
+ }
+
+ dd($request->checkboxdata);
+ if($request->checkboxdata)
+ {
+ if($request->type == 'User')
+ {
+ $data = $model_name::whereIn('id',$request->checkboxdata)->with('roles')->get();
+
+ }
+ else{
+ $data = $model_name::whereIn('id',$request->checkboxdata)->get();
+ }
+ }
+ else
+ {
+ if($request->type == 'User')
+ {
+ $data = $model_name::with('roles')->get();
+ }
+ else{
+ $data = $model_name::all();
+ }
+
+ }
+ // return view('pdf.edit',compact('data')); //page for editing
+ // dd($data);
+ if($request->type =='Role')
+ {
+ $pdf = PDF::loadView('pdf.tarafpdf',compact('data'));
+ return $pdf->download('Taraf.pdf');
+ }
+ elseif($request->type =='User')
+ {
+ // return view('pdf.edit',compact('data')); //page for editing
+ $pdf = PDF::loadView('pdf.penggunapdf',compact('data'));
+ return $pdf->download('Pengguna.pdf');
+ }
+ elseif($request->type =='Permission')
+ {
+ return view('pdf.edit',compact('data')); //page for editing
+ // $pdf = PDF::loadView('pdf.rolespdf',compact('data'));
+ // return $pdf->download('Roles.pdf');
+ }
}
-
}
\ No newline at end of file
diff --git a/app/Models/User.php b/app/Models/User.php
index 5699aa14..feb41de4 100644
--- a/app/Models/User.php
+++ b/app/Models/User.php
@@ -19,7 +19,7 @@ class User extends Authenticatable
* @var string[]
*/
protected $fillable = [
- 'nama',
+ 'name',
'email',
'password',
'kodcaw',
diff --git a/config/app.php b/config/app.php
index a8d1a82e..bfcc7a51 100644
--- a/config/app.php
+++ b/config/app.php
@@ -174,6 +174,7 @@ return [
// App\Providers\BroadcastServiceProvider::class,
App\Providers\EventServiceProvider::class,
App\Providers\RouteServiceProvider::class,
+ Barryvdh\DomPDF\ServiceProvider::class,
],
@@ -229,6 +230,7 @@ return [
'URL' => Illuminate\Support\Facades\URL::class,
'Validator' => Illuminate\Support\Facades\Validator::class,
'View' => Illuminate\Support\Facades\View::class,
+ 'PDF' => Barryvdh\DomPDF\Facade::class,
],
diff --git a/config/dompdf.php b/config/dompdf.php
new file mode 100644
index 00000000..9a993058
--- /dev/null
+++ b/config/dompdf.php
@@ -0,0 +1,244 @@
+ false, // Throw an Exception on warnings from dompdf
+ 'orientation' => 'portrait',
+ 'defines' => array(
+ /**
+ * The location of the DOMPDF font directory
+ *
+ * The location of the directory where DOMPDF will store fonts and font metrics
+ * Note: This directory must exist and be writable by the webserver process.
+ * *Please note the trailing slash.*
+ *
+ * Notes regarding fonts:
+ * Additional .afm font metrics can be added by executing load_font.php from command line.
+ *
+ * Only the original "Base 14 fonts" are present on all pdf viewers. Additional fonts must
+ * be embedded in the pdf file or the PDF may not display correctly. This can significantly
+ * increase file size unless font subsetting is enabled. Before embedding a font please
+ * review your rights under the font license.
+ *
+ * Any font specification in the source HTML is translated to the closest font available
+ * in the font directory.
+ *
+ * The pdf standard "Base 14 fonts" are:
+ * Courier, Courier-Bold, Courier-BoldOblique, Courier-Oblique,
+ * Helvetica, Helvetica-Bold, Helvetica-BoldOblique, Helvetica-Oblique,
+ * Times-Roman, Times-Bold, Times-BoldItalic, Times-Italic,
+ * Symbol, ZapfDingbats.
+ */
+ "font_dir" => storage_path('fonts/'), // advised by dompdf (https://github.com/dompdf/dompdf/pull/782)
+
+ /**
+ * The location of the DOMPDF font cache directory
+ *
+ * This directory contains the cached font metrics for the fonts used by DOMPDF.
+ * This directory can be the same as DOMPDF_FONT_DIR
+ *
+ * Note: This directory must exist and be writable by the webserver process.
+ */
+ "font_cache" => storage_path('fonts/'),
+
+ /**
+ * The location of a temporary directory.
+ *
+ * The directory specified must be writeable by the webserver process.
+ * The temporary directory is required to download remote images and when
+ * using the PFDLib back end.
+ */
+ "temp_dir" => sys_get_temp_dir(),
+
+ /**
+ * ==== IMPORTANT ====
+ *
+ * dompdf's "chroot": Prevents dompdf from accessing system files or other
+ * files on the webserver. All local files opened by dompdf must be in a
+ * subdirectory of this directory. DO NOT set it to '/' since this could
+ * allow an attacker to use dompdf to read any files on the server. This
+ * should be an absolute path.
+ * This is only checked on command line call by dompdf.php, but not by
+ * direct class use like:
+ * $dompdf = new DOMPDF(); $dompdf->load_html($htmldata); $dompdf->render(); $pdfdata = $dompdf->output();
+ */
+ "chroot" => realpath(base_path()),
+
+ /**
+ * Whether to enable font subsetting or not.
+ */
+ "enable_font_subsetting" => false,
+
+ /**
+ * The PDF rendering backend to use
+ *
+ * Valid settings are 'PDFLib', 'CPDF' (the bundled R&OS PDF class), 'GD' and
+ * 'auto'. 'auto' will look for PDFLib and use it if found, or if not it will
+ * fall back on CPDF. 'GD' renders PDFs to graphic files. {@link
+ * Canvas_Factory} ultimately determines which rendering class to instantiate
+ * based on this setting.
+ *
+ * Both PDFLib & CPDF rendering backends provide sufficient rendering
+ * capabilities for dompdf, however additional features (e.g. object,
+ * image and font support, etc.) differ between backends. Please see
+ * {@link PDFLib_Adapter} for more information on the PDFLib backend
+ * and {@link CPDF_Adapter} and lib/class.pdf.php for more information
+ * on CPDF. Also see the documentation for each backend at the links
+ * below.
+ *
+ * The GD rendering backend is a little different than PDFLib and
+ * CPDF. Several features of CPDF and PDFLib are not supported or do
+ * not make any sense when creating image files. For example,
+ * multiple pages are not supported, nor are PDF 'objects'. Have a
+ * look at {@link GD_Adapter} for more information. GD support is
+ * experimental, so use it at your own risk.
+ *
+ * @link http://www.pdflib.com
+ * @link http://www.ros.co.nz/pdf
+ * @link http://www.php.net/image
+ */
+ "pdf_backend" => "CPDF",
+
+ /**
+ * PDFlib license key
+ *
+ * If you are using a licensed, commercial version of PDFlib, specify
+ * your license key here. If you are using PDFlib-Lite or are evaluating
+ * the commercial version of PDFlib, comment out this setting.
+ *
+ * @link http://www.pdflib.com
+ *
+ * If pdflib present in web server and auto or selected explicitely above,
+ * a real license code must exist!
+ */
+ //"DOMPDF_PDFLIB_LICENSE" => "your license key here",
+
+ /**
+ * html target media view which should be rendered into pdf.
+ * List of types and parsing rules for future extensions:
+ * http://www.w3.org/TR/REC-html40/types.html
+ * screen, tty, tv, projection, handheld, print, braille, aural, all
+ * Note: aural is deprecated in CSS 2.1 because it is replaced by speech in CSS 3.
+ * Note, even though the generated pdf file is intended for print output,
+ * the desired content might be different (e.g. screen or projection view of html file).
+ * Therefore allow specification of content here.
+ */
+ "default_media_type" => "screen",
+
+ /**
+ * The default paper size.
+ *
+ * North America standard is "letter"; other countries generally "a4"
+ *
+ * @see CPDF_Adapter::PAPER_SIZES for valid sizes ('letter', 'legal', 'A4', etc.)
+ */
+ "default_paper_size" => "a4",
+
+ /**
+ * The default font family
+ *
+ * Used if no suitable fonts can be found. This must exist in the font folder.
+ * @var string
+ */
+ "default_font" => "serif",
+
+ /**
+ * Image DPI setting
+ *
+ * This setting determines the default DPI setting for images and fonts. The
+ * DPI may be overridden for inline images by explictly setting the
+ * image's width & height style attributes (i.e. if the image's native
+ * width is 600 pixels and you specify the image's width as 72 points,
+ * the image will have a DPI of 600 in the rendered PDF. The DPI of
+ * background images can not be overridden and is controlled entirely
+ * via this parameter.
+ *
+ * For the purposes of DOMPDF, pixels per inch (PPI) = dots per inch (DPI).
+ * If a size in html is given as px (or without unit as image size),
+ * this tells the corresponding size in pt.
+ * This adjusts the relative sizes to be similar to the rendering of the
+ * html page in a reference browser.
+ *
+ * In pdf, always 1 pt = 1/72 inch
+ *
+ * Rendering resolution of various browsers in px per inch:
+ * Windows Firefox and Internet Explorer:
+ * SystemControl->Display properties->FontResolution: Default:96, largefonts:120, custom:?
+ * Linux Firefox:
+ * about:config *resolution: Default:96
+ * (xorg screen dimension in mm and Desktop font dpi settings are ignored)
+ *
+ * Take care about extra font/image zoom factor of browser.
+ *
+ * In images, size in pixel attribute, img css style, are overriding
+ * the real image dimension in px for rendering.
+ *
+ * @var int
+ */
+ "dpi" => 96,
+
+ /**
+ * Enable inline PHP
+ *
+ * If this setting is set to true then DOMPDF will automatically evaluate
+ * inline PHP contained within tags.
+ *
+ * Enabling this for documents you do not trust (e.g. arbitrary remote html
+ * pages) is a security risk. Set this option to false if you wish to process
+ * untrusted documents.
+ *
+ * @var bool
+ */
+ "enable_php" => false,
+
+ /**
+ * Enable inline Javascript
+ *
+ * If this setting is set to true then DOMPDF will automatically insert
+ * JavaScript code contained within tags.
+ *
+ * @var bool
+ */
+ "enable_javascript" => true,
+
+ /**
+ * Enable remote file access
+ *
+ * If this setting is set to true, DOMPDF will access remote sites for
+ * images and CSS files as required.
+ * This is required for part of test case www/test/image_variants.html through www/examples.php
+ *
+ * Attention!
+ * This can be a security risk, in particular in combination with DOMPDF_ENABLE_PHP and
+ * allowing remote access to dompdf.php or on allowing remote html code to be passed to
+ * $dompdf = new DOMPDF(, $dompdf->load_html(...,
+ * This allows anonymous users to download legally doubtful internet content which on
+ * tracing back appears to being downloaded by your server, or allows malicious php code
+ * in remote html pages to be executed by your server with your account privileges.
+ *
+ * @var bool
+ */
+ "enable_remote" => true,
+
+ /**
+ * A ratio applied to the fonts height to be more like browsers' line height
+ */
+ "font_height_ratio" => 1.1,
+
+ /**
+ * Use the more-than-experimental HTML5 Lib parser
+ */
+ "enable_html5_parser" => false,
+ ),
+
+
+);
diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php
index d0efd5ca..28902841 100644
--- a/database/factories/UserFactory.php
+++ b/database/factories/UserFactory.php
@@ -15,7 +15,7 @@ class UserFactory extends Factory
public function definition()
{
return [
- 'nama' => $this->faker->name(),
+ 'name' => $this->faker->name(),
'email' => $this->faker->unique()->safeEmail(),
't_daftar' => now(),
'status' => 'active',
diff --git a/database/migrations/2014_10_12_000000_create_users_table.php b/database/migrations/2014_10_12_000000_create_users_table.php
index 323d8de4..884955f8 100644
--- a/database/migrations/2014_10_12_000000_create_users_table.php
+++ b/database/migrations/2014_10_12_000000_create_users_table.php
@@ -15,7 +15,7 @@ class CreateUsersTable extends Migration
{
Schema::create('users', function (Blueprint $table) {
$table->id();
- $table->string('nama');
+ $table->string('name');
$table->string('kodcaw')->nullable();
$table->string('nokp')->nullable();
$table->string('bank_acc_pembeli')->nullable();
diff --git a/database/migrations/2021_11_10_134257_create_permission_tables.php b/database/migrations/2021_11_10_134257_create_permission_tables.php
index f20ef752..e0f39112 100644
--- a/database/migrations/2021_11_10_134257_create_permission_tables.php
+++ b/database/migrations/2021_11_10_134257_create_permission_tables.php
@@ -27,11 +27,12 @@ class CreatePermissionTables extends Migration
Schema::create($tableNames['permissions'], function (Blueprint $table) {
$table->bigIncrements('id');
- $table->string('name'); // For MySQL 8.0 use string('name', 125);
+ $table->string('name');
+ $table->string('description'); // For MySQL 8.0 use string('name', 125);
$table->string('guard_name'); // For MySQL 8.0 use string('guard_name', 125);
$table->timestamps();
- $table->unique(['name', 'guard_name']);
+ $table->unique(['name','description','guard_name']);
});
Schema::create($tableNames['roles'], function (Blueprint $table) use ($teams, $columnNames) {
diff --git a/database/seeders/RolesSeeder.php b/database/seeders/RolesSeeder.php
index 1f4a4f91..75a448c7 100644
--- a/database/seeders/RolesSeeder.php
+++ b/database/seeders/RolesSeeder.php
@@ -21,33 +21,92 @@ class RolesSeeder extends Seeder
// create permissions
//admin
- Permission::create(['name' => 'pengguna']);
- Permission::create(['name' => 'pengurusanlelongan']);
- Permission::create(['name' => 'analisa']);
+ Permission::create([
+ 'name' => 'pengguna',
+ 'description' => 'Pengurusan Pengguna'
+ ]);
+ Permission::create([
+ 'name' => 'pengurusanlelongan',
+ 'description' => 'Pengurusan Lelong'
+ ]);
+ Permission::create([
+ 'name' => 'analisa',
+ 'description' => 'Analisa lelong'
+ ]);
+
//khazanah
- Permission::create(['name' => 'semakanmarhun']);
- Permission::create(['name' => 'kemaskinimarhun']);
+ Permission::create([
+ 'name' => 'semakanmarhun',
+ 'description' => 'Semakan marhun'
+ ]);
+ Permission::create([
+ 'name' => 'kemaskinimarhun',
+ 'description' => 'Kemaskini marhun'
+ ]);
+
//teller
- Permission::create(['name' => 'pengesahanbayarancash']);
+ Permission::create([
+ 'name' => 'pengesahanbayarancash',
+ 'description' => 'Pengesahan bayaran pembida di cawangan (cash)'
+ ]);
+
//pengurus cawangan
- Permission::create(['name' => 'pendaftaranpembida']);
- Permission::create(['name' => 'jananotis']);
+ Permission::create([
+ 'name' => 'pendaftaranpembida',
+ 'description' => 'Pemdaftaran pembida di cawangan'
+ ]);
+ Permission::create([
+ 'name' => 'jananotis',
+ 'description' => 'Jana Notis Lelong'
+ ]);
+
//jurulelong
- Permission::create(['name' => 'pendaftaranbatch']);
- Permission::create(['name' => 'kemaskinihargaasas']);
- Permission::create(['name' => 'import']);
- Permission::create(['name' => 'lelongan']);
- Permission::create(['name' => 'janapemenang']);
+ Permission::create([
+ 'name' => 'pendaftaranbatch',
+ 'description' => 'Daftar batch lelong'
+ ]);
+ Permission::create([
+ 'name' => 'kemaskinihargaasas',
+ 'description' => 'Kemaskini harga asas mengikut harga emas semasa'
+ ]);
+ Permission::create([
+ 'name' => 'import',
+ 'description' => 'Import senarai marhun cawangan to LIVE'
+ ]);
+ Permission::create([
+ 'name' => 'lelongan',
+ 'description' => '(online/offline) lelong mengikut cawangan'
+ ]);
+ Permission::create([
+ 'name' => 'janapemenang',
+ 'description' => 'Pemilihan pemenang bagi bidaan paling tinggi'
+ ]);
+
//operasi
- //Permission::create(['name' => 'pendaftaranbatch']); di jurulelong dah ada
- Permission::create(['name' => 'report']);
- Permission::create(['name' => 'tangguhan']);
+ Permission::create([
+ 'name' => 'report',
+ 'description' => 'Full report lelongan'
+ ]);
+ Permission::create([
+ 'name' => 'tangguhan',
+ 'description' => 'Tangguh lelong'
+ ]);
+
//account
- Permission::create(['name' => 'pengesahanbayaran']);
+ Permission::create([
+ 'name' => 'pengesahanbayaran',
+ 'description' => 'Pengesahan pembayaran pembida dalam akaun yang dibuat melalui (cdm,fpx)'
+ ]);
+
//pembida
- // Permission::create(['name' => 'pendaftaranpembida']); di pc dah ada
- Permission::create(['name' => 'bidaan']);
- Permission::create(['name' => 'pembayaran']);
+ Permission::create([
+ 'name' => 'bidaan',
+ 'description' => 'Pendaftaran bagi yang belum mempunyai akaun di cawangan ataupun kata laluan atas talian'
+ ]);
+ Permission::create([
+ 'name' => 'pembayaran',
+ 'description' => 'Pembayaran pemenang'
+ ]);
// create roles and assign existing permissions
$role1 = Role::create(['name' => 'admin']);
@@ -92,56 +151,56 @@ class RolesSeeder extends Seeder
// create demo users
$user = \App\Models\User::factory()->create([
- 'nama' => 'Admin',
+ 'name' => 'Admin',
'username' => 'Admin',
'email' => 'admin@example.com',
]);
$user->assignRole($role1);
$user = \App\Models\User::factory()->create([
- 'nama' => 'Khazanah',
+ 'name' => 'Khazanah',
'username' => 'Khazanah',
'email' => 'khazanah@example.com',
]);
$user->assignRole($role2);
$user = \App\Models\User::factory()->create([
- 'nama' => 'Teller',
+ 'name' => 'Teller',
'username' => 'Teller',
'email' => 'teller@example.com',
]);
$user->assignRole($role3);
$user = \App\Models\User::factory()->create([
- 'nama' => 'Pengurus Cawangan',
+ 'name' => 'Pengurus Cawangan',
'username' => 'PC',
'email' => 'penguruscawangan@example.com',
]);
$user->assignRole($role4);
$user = \App\Models\User::factory()->create([
- 'nama' => 'Juru Lelong',
+ 'name' => 'Juru Lelong',
'username' => 'Juru Lelong',
'email' => 'jurulelong@example.com',
]);
$user->assignRole($role5);
$user = \App\Models\User::factory()->create([
- 'nama' => 'Operasi',
+ 'name' => 'Operasi',
'username' => 'Operasi',
'email' => 'operasi@example.com',
]);
$user->assignRole($role6);
$user = \App\Models\User::factory()->create([
- 'nama' => 'Account',
+ 'name' => 'Account',
'username' => 'Account',
'email' => 'account@example.com',
]);
$user->assignRole($role7);
$user = \App\Models\User::factory()->create([
- 'nama' => 'Pembida',
+ 'name' => 'Pembida',
'username' => 'Pembida',
'email' => 'pembida@example.com',
]);
diff --git a/resources/views/includes/header.blade.php b/resources/views/includes/header.blade.php
index 768d0e89..d5a9c799 100644
--- a/resources/views/includes/header.blade.php
+++ b/resources/views/includes/header.blade.php
@@ -20,7 +20,7 @@
-->
{{ $message }}
| - | Roles | -Action | -
|---|---|---|
| - | {{ $role->name }} - | -
- |
-
| + | Roles | +Keterangan | +Action | +
|---|---|---|---|
| + | {{ $role->name }} | +{{ $role->description }} | +
+ |
+
{{ $message }}
+{{ $message }}