firstcommit

This commit is contained in:
2024-05-16 09:31:08 +05:45
commit 34d9672cb8
1396 changed files with 86482 additions and 0 deletions

View File

@ -0,0 +1,135 @@
<?php
namespace Modules\Customer\Http\Controllers;
use App\Http\Controllers\Controller;
use Flasher\Prime\FlasherInterface;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Modules\Admin\Repositories\FieldInterface;
use Modules\Admin\Services\AdminService;
use Modules\Customer\Repositories\CustomerInterface;
use Modules\User\Repositories\UserInterface;
class CustomerController extends Controller
{
private $userRepository;
private $customerRepository;
private $fieldRepository;
public function __construct(
FieldInterface $fieldRepository,
UserInterface $userRepository,
CustomerInterface $customerRepository
) {
$this->userRepository = $userRepository;
$this->fieldRepository = $fieldRepository;
$this->customerRepository = $customerRepository;
}
/**
* Display a listing of the resource.
*/
public function index()
{
$data['title'] = 'Customer List';
$data['customers'] = $this->customerRepository->findAll();
return view('customer::customer.index', $data);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
$data['title'] = 'Create Customer';
$data['editable'] = false;
toastr()->success('Hello');
return view('customer::customer.create', $data);
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
try {
$inputData = $request->all();
$this->customerRepository->create($inputData);
} catch (\Throwable $th) {
toastr()->error($th->getMessage());
}
toastr()->success('Hello');
return redirect()->route('customer.index');
}
/**
* Show the specified resource.
*/
public function show($id)
{
$data['title'] = 'Show Customer';
$data['customer'] = $this->customerRepository->getCustomerById($id);
return view('customer::customer.show', $data);
}
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
$data['title'] = 'Edit Customer';
$data['editable'] = true;
$data['customer'] = $this->customerRepository->getCustomerById($id);
return view('customer::customer.edit', $data);
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, $id): RedirectResponse
{
$inputData = $request->except(['_method', '_token']);
try {
$this->customerRepository->update($id, $inputData);
flash()->success('Customer updated succesfully');
} catch (\Throwable $th) {
flash()->error($th->getMessage());
}
return redirect()->route('customer.index');
}
/**
* Remove the specified resource from storage.
*/
public function destroy($id)
{
try {
$CustomerModel = $this->customerRepository->getCustomerById($id);
$CustomerModel->delete();
flash()->success('Customer deleted succesfully');
} catch (\Throwable $th) {
flash()->error($th->getMessage());
}
return response()->json(['status' => true, 'message' => 'Customer deleted succesfully']);
}
}

View File

View File

@ -0,0 +1,34 @@
<?php
namespace Modules\Customer\Models;
use Illuminate\Database\Eloquent\Model;
class Customer extends Model
{
protected $table = 'tbl_customers';
protected $fillable = [
'first_name',
'last_name',
'contact',
'phone',
'email',
'address',
'company_name',
'company_pan',
'company_address',
'company_contact',
'company_phone',
'profile_pic',
'remarks'
];
public $appends = ['customer_name'];
public function getCustomerNameAttribute()
{
return $this->last_name ? "{$this->first_name} {$this->last_name}" : $this->first_name;
}
}

View File

View File

View File

@ -0,0 +1,117 @@
<?php
namespace Modules\Customer\Providers;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;
use Modules\Customer\Repositories\CustomerInterface;
use Modules\Customer\Repositories\CustomerRepository;
class CustomerServiceProvider extends ServiceProvider
{
protected string $moduleName = 'Customer';
protected string $moduleNameLower = 'customer';
/**
* Boot the application events.
*/
public function boot(): void
{
$this->registerCommands();
$this->registerCommandSchedules();
$this->registerTranslations();
$this->registerConfig();
$this->registerViews();
$this->loadMigrationsFrom(module_path($this->moduleName, 'database/migrations'));
}
/**
* Register the service provider.
*/
public function register(): void
{
$this->app->bind(CustomerInterface::class, CustomerRepository::class);
$this->app->register(RouteServiceProvider::class);
}
/**
* Register commands in the format of Command::class
*/
protected function registerCommands(): void
{
// $this->commands([]);
}
/**
* Register command Schedules.
*/
protected function registerCommandSchedules(): void
{
// $this->app->booted(function () {
// $schedule = $this->app->make(Schedule::class);
// $schedule->command('inspire')->hourly();
// });
}
/**
* Register translations.
*/
public function registerTranslations(): void
{
$langPath = resource_path('lang/modules/' . $this->moduleNameLower);
if (is_dir($langPath)) {
$this->loadTranslationsFrom($langPath, $this->moduleNameLower);
$this->loadJsonTranslationsFrom($langPath);
} else {
$this->loadTranslationsFrom(module_path($this->moduleName, 'lang'), $this->moduleNameLower);
$this->loadJsonTranslationsFrom(module_path($this->moduleName, 'lang'));
}
}
/**
* Register config.
*/
protected function registerConfig(): void
{
$this->publishes([module_path($this->moduleName, 'config/config.php') => config_path($this->moduleNameLower . '.php')], 'config');
$this->mergeConfigFrom(module_path($this->moduleName, 'config/config.php'), $this->moduleNameLower);
}
/**
* Register views.
*/
public function registerViews(): void
{
$viewPath = resource_path('views/modules/' . $this->moduleNameLower);
$sourcePath = module_path($this->moduleName, 'resources/views');
$this->publishes([$sourcePath => $viewPath], ['views', $this->moduleNameLower . '-module-views']);
$this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->moduleNameLower);
$componentNamespace = str_replace('/', '\\', config('modules.namespace') . '\\' . $this->moduleName . '\\' . ltrim(config('modules.paths.generator.component-class.path'), config('modules.paths.app_folder', '')));
Blade::componentNamespace($componentNamespace, $this->moduleNameLower);
}
/**
* Get the services provided by the provider.
*/
public function provides(): array
{
return [];
}
private function getPublishableViewPaths(): array
{
$paths = [];
foreach (config('view.paths') as $path) {
if (is_dir($path . '/modules/' . $this->moduleNameLower)) {
$paths[] = $path . '/modules/' . $this->moduleNameLower;
}
}
return $paths;
}
}

View File

@ -0,0 +1,49 @@
<?php
namespace Modules\Customer\Providers;
use Illuminate\Support\Facades\Route;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
class RouteServiceProvider extends ServiceProvider
{
/**
* Called before routes are registered.
*
* Register any model bindings or pattern based filters.
*/
public function boot(): void
{
parent::boot();
}
/**
* Define the routes for the application.
*/
public function map(): void
{
$this->mapApiRoutes();
$this->mapWebRoutes();
}
/**
* Define the "web" routes for the application.
*
* These routes all receive session state, CSRF protection, etc.
*/
protected function mapWebRoutes(): void
{
Route::middleware('web')->group(module_path('Customer', '/routes/web.php'));
}
/**
* Define the "api" routes for the application.
*
* These routes are typically stateless.
*/
protected function mapApiRoutes(): void
{
Route::middleware('api')->prefix('api')->name('api.')->group(module_path('Customer', '/routes/api.php'));
}
}

View File

@ -0,0 +1,15 @@
<?php
namespace Modules\Customer\Repositories;
interface CustomerInterface
{
public function findAll();
public function getCustomerById($CustomerId);
public function getCustomerByEmail($email);
public function delete($CustomerId);
public function create($CustomerDetails);
public function update($CustomerId, array $newDetails);
public function pluck();
}

View File

@ -0,0 +1,51 @@
<?php
namespace Modules\Customer\Repositories;
use Illuminate\Support\Facades\DB;
use Modules\Customer\Models\Customer;
class CustomerRepository implements CustomerInterface
{
public function findAll()
{
return Customer::when(true, function ($query) {
// if (auth()->user()->hasRole('Customer')) {
// $user = \Auth::user();
// $query->where('id', $user->Customer_id);
// }
})->paginate(20);
}
public function getCustomerById($CustomerId)
{
return Customer::findOrFail($CustomerId);
}
public function getCustomerByEmail($email)
{
return Customer::where('email', $email)->first();
}
public function delete($CustomerId)
{
Customer::destroy($CustomerId);
}
public function create($CustomerDetails)
{
return Customer::create($CustomerDetails);
}
public function update($CustomerId, array $newDetails)
{
return Customer::whereId($CustomerId)->update($newDetails);
}
public function pluck()
{
return Customer::pluck(DB::raw("IFNULL(CONCAT(first_name, ' ', last_name), first_name) AS customer_name"), 'id');
}
}

View File

@ -0,0 +1,30 @@
{
"name": "nwidart/customer",
"description": "",
"authors": [
{
"name": "Nicolas Widart",
"email": "n.widart@gmail.com"
}
],
"extra": {
"laravel": {
"providers": [],
"aliases": {
}
}
},
"autoload": {
"psr-4": {
"Modules\\Customer\\": "app/",
"Modules\\Customer\\Database\\Factories\\": "database/factories/",
"Modules\\Customer\\Database\\Seeders\\": "database/seeders/"
}
},
"autoload-dev": {
"psr-4": {
"Modules\\Customer\\Tests\\": "tests/"
}
}
}

View File

View File

@ -0,0 +1,5 @@
<?php
return [
'name' => 'Customer',
];

View File

@ -0,0 +1,43 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('tbl_customers', function (Blueprint $table) {
$table->id();
$table->string('first_name')->nullable();
$table->string('last_name')->nullable();
$table->string('contact')->nullable();
$table->string('phone')->nullable();
$table->string('email')->nullable();
$table->text('address')->nullable();
$table->string('company_name')->nullable();
$table->string('company_pan')->nullable();
$table->text('company_address')->nullable();
$table->string('company_contact')->nullable();
$table->string('company_phone')->nullable();
$table->string('profile_pic')->nullable();
$table->unsignedBigInteger('createdBy')->nullable();
$table->unsignedBigInteger('updatedBy')->nullable();
$table->integer('status')->nullable()->default(11);
$table->text('remarks')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('tbl_customers');
}
};

View File

@ -0,0 +1,16 @@
<?php
namespace Modules\Customer\database\seeders;
use Illuminate\Database\Seeder;
class CustomerDatabaseSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
// $this->call([]);
}
}

View File

@ -0,0 +1,11 @@
{
"name": "Customer",
"alias": "customer",
"description": "",
"keywords": [],
"priority": 0,
"providers": [
"Modules\\Customer\\Providers\\CustomerServiceProvider"
],
"files": []
}

View File

@ -0,0 +1,15 @@
{
"private": true,
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build"
},
"devDependencies": {
"axios": "^1.1.2",
"laravel-vite-plugin": "^0.7.5",
"sass": "^1.69.5",
"postcss": "^8.3.7",
"vite": "^4.0.0"
}
}

View File

@ -0,0 +1,15 @@
@extends('layouts.app')
@section('content')
<div class="page-content">
<div class="container-fluid">
@include('layouts.partials.breadcrumb', ['title' => $title])
{{ html()->form('POST')->route('customer.store')->class(['needs-validation'])->attributes(['novalidate', 'enctype' => 'multipart/form-data'])->open() }}
@include('customer::customer.partials.action')
{{ html()->form()->close() }}
</div>
</div>
@endsection

View File

@ -0,0 +1,27 @@
@extends('layouts.app')
@section('content')
<div class="page-content">
<div class="container-fluid">
<!-- start page title -->
@include('layouts.partials.breadcrumb', ['title' => $title])
<!-- end page title -->
{{ html()->modelForm($customer, 'PUT')->route('customer.update', $customer->id)->class(['needs-validation'])->attributes(['novalidate', 'enctype' => 'multipart/form-data'])->open() }}
@include('customer::customer.partials.action')
{{ html()->closeModelForm() }}
<!--end row-->
</div>
<!-- container-fluid -->
</div>
@endsection

View File

@ -0,0 +1,78 @@
@extends('layouts.app')
@section('content')
<div class="page-content">
<div class="container-fluid">
@include('layouts.partials.breadcrumb', ['title' => $title])
<div class="mb-2 text-end">
@can('customer.create')
<a href="{{ route('customer.create') }}" class="btn btn-success btn-md waves-effect waves-light"><i
class="ri-add-fill me-1 align-bottom"></i> Add</a>
@endcan
</div>
<div class="row">
<div class="col-lg-12">
<div class="card">
<div class="card-body">
<div class="table-responsive">
<table id="buttons-datatables" class="display table-sm table-bordered table"
style="width:100%">
<thead>
<tr>
<th>S.N</th>
<th>Customer Name</th>
<th>Email</th>
<th>Contact</th>
<th>Address</th>
<th>Company</th>
<th>Action</th>
</tr>
</thead>
<tbody>
@forelse ($customers as $key => $customer)
<tr>
<td>{{ $key + 1 }}</td>
<td>{{ $customer->customer_name }}</td>
<td>{{ $customer->email }}</td>
<td>{{ $customer->contact }}</td>
<td>{{ $customer->address }}</td>
<td>{{ $customer->company_name }}</td>
<td>
<div class="hstack flex-wrap gap-3">
@can('customer.show')
<a href="{{ route('customer.show', $customer->id) }}"
class="link-info fs-15">
<i class="ri-eye-line"></i>
</a>
@endcan
@can('customer.edit')
<a href="{{ route('customer.edit', $customer->id) }}"
class="link-success fs-15 edit-item-btn"><i
class="ri-edit-2-line"></i></a>
@endcan
@can('customer.destroy')
<a href="javascript:void(0);"
data-link="{{ route('customer.destroy', $customer->id) }}"
data-id="{{ $customer->id }}"
class="link-danger fs-15 remove-item-btn"><i
class="ri-delete-bin-line"></i></a>
@endcan
</div>
</td>
</tr>
@empty
@endforelse
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<!--end row-->
</div>
</div>
@endsection

View File

@ -0,0 +1,96 @@
<div class="row">
<div class="col-lg-12">
<div class="card">
<div class="card-body">
<div class="row gy-3">
<div class="col-md-4">
{{ html()->label('First Name')->class('form-label') }}
{{ html()->text('first_name')->class('form-control')->placeholder('First Name')->required() }}
</div>
<div class="col-md-4">
{{ html()->label('Last Name')->class('form-label') }}
{{ html()->text('last_name')->class('form-control')->placeholder('Last Name')->required() }}
</div>
<div class="col-md-4">
{{ html()->label('Email')->class('form-label') }}
{{ html()->email('email')->class('form-control')->placeholder('Email Address')->required() }}
{{ html()->div('Please enter email')->class('invalid-feedback') }}
</div>
<div class="col-md-4">
{{ html()->label('Phone Number')->class('form-label') }}
{{ html()->text('phone')->class('form-control')->placeholder('Phone Number') }}
</div>
<div class="col-md-4">
{{ html()->label('Contact Number')->class('form-label') }}
{{ html()->text('contact')->class('form-control')->placeholder('Contact Number') }}
</div>
<div class="col-md-4">
{{ html()->label('Address')->class('form-label') }}
{{ html()->text('address')->class('form-control')->placeholder('Enter Full Address') }}
</div>
</div>
<div class="row my-4">
<div class="col-md-12">
<span class="fs-6 fw-bold">Company Details</span>
</div>
</div>
<div class="row gy-3">
<div class="col-md-4">
{{ html()->label('Name')->class('form-label') }}
{{ html()->text('company_name')->class('form-control')->placeholder('Company Name')->required() }}
</div>
<div class="col-md-4">
{{ html()->label('Address')->class('form-label') }}
{{ html()->text('company_address')->class('form-control')->placeholder('Company Address')->required() }}
</div>
<div class="col-md-4">
{{ html()->label('Phone')->class('form-label') }}
{{ html()->text('company_phone')->class('form-control')->placeholder('Company Phone')->required() }}
</div>
<div class="col-md-4">
{{ html()->label('Contact')->class('form-label') }}
{{ html()->text('company_contact')->class('form-control')->placeholder('Company Contact')->required() }}
</div>
<div class="col-md-4">
{{ html()->label('PAN')->class('form-label') }}
{{ html()->text('company_pan')->class('form-control')->placeholder('Company PAN')->required() }}
</div>
<div class="col-md-12">
{{ html()->label('Remarks')->class('form-label') }}
{{ html()->textarea('remarks')->class('form-control')->placeholder('Enter Remarks') }}
</div>
<x-form-buttons :editable="$editable" label="Add" href="{{ route('customer.index') }}" />
</div>
</div>
<!-- end card body -->
</div>
<!-- end card -->
</div>
</div>
@push('js')
<script src="{{asset('assets/js/pages/form-validation.init.js')}}"></script>
@endpush

View File

@ -0,0 +1,49 @@
@extends('layouts.app')
@section('content')
<div class="page-content">
<div class="container-fluid">
@include('layouts.partials.breadcrumb', ['title' => $title])
<div class="row">
<div class="col-md-8">
<div class="card card-body p-4">
<div>
<div class="table-responsive">
<table class="table-borderless mb-0 table">
<tbody>
<tr>
<th><span class="fw-medium">Customer Name</span></th>
<td>{{ $customer->customer_name }}</td>
</tr>
<tr>
<th><span class="fw-medium">Email</span></th>
<td>{{ $customer->email }}</td>
</tr>
<tr>
<th><span class="fw-medium">Phone</span></th>
<td>{{ $customer->contact }}</td>
</tr>
<tr>
<th><span class="fw-medium">Permanent Address</span></th>
<td>{{ $customer->permanent_address }}</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div class="mb-3 text-end">
<a href="{{ route('customer.index') }}" class="btn btn-secondary w-sm">Back</a>
</div>
</div>
</div>
</div>
</div>
@endsection
@push('js')
<script src="{{ asset('assets/js/pages/form-validation.init.js') }}"></script>
@endpush

View File

@ -0,0 +1,7 @@
@extends('customer::layouts.master')
@section('content')
<h1>Hello World</h1>
<p>Module: {!! config('customer.name') !!}</p>
@endsection

View File

@ -0,0 +1,29 @@
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="csrf-token" content="{{ csrf_token() }}">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Customer Module - {{ config('app.name', 'Laravel') }}</title>
<meta name="description" content="{{ $description ?? '' }}">
<meta name="keywords" content="{{ $keywords ?? '' }}">
<meta name="author" content="{{ $author ?? '' }}">
<!-- Fonts -->
<link rel="preconnect" href="https://fonts.bunny.net">
<link href="https://fonts.bunny.net/css?family=figtree:400,500,600&display=swap" rel="stylesheet" />
{{-- Vite CSS --}}
{{-- {{ module_vite('build-customer', 'resources/assets/sass/app.scss') }} --}}
</head>
<body>
@yield('content')
{{-- Vite JS --}}
{{-- {{ module_vite('build-customer', 'resources/assets/js/app.js') }} --}}
</body>

View File

View File

@ -0,0 +1,19 @@
<?php
use Illuminate\Support\Facades\Route;
use Modules\Customer\Http\Controllers\CustomerController;
/*
*--------------------------------------------------------------------------
* API Routes
*--------------------------------------------------------------------------
*
* Here is where you can register API routes for your application. These
* routes are loaded by the RouteServiceProvider within a group which
* is assigned the "api" middleware group. Enjoy building your API!
*
*/
Route::middleware(['auth:sanctum'])->prefix('v1')->group(function () {
Route::apiResource('customer', CustomerController::class)->names('customer');
});

View File

@ -0,0 +1,19 @@
<?php
use Illuminate\Support\Facades\Route;
use Modules\Customer\Http\Controllers\CustomerController;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::group([], function () {
Route::resource('customer', CustomerController::class)->names('customer');
});

View File

@ -0,0 +1,26 @@
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
export default defineConfig({
build: {
outDir: '../../public/build-customer',
emptyOutDir: true,
manifest: true,
},
plugins: [
laravel({
publicDirectory: '../../public',
buildDirectory: 'build-customer',
input: [
__dirname + '/resources/assets/sass/app.scss',
__dirname + '/resources/assets/js/app.js'
],
refresh: true,
}),
],
});
//export const paths = [
// 'Modules/Customer/resources/assets/sass/app.scss',
// 'Modules/Customer/resources/assets/js/app.js',
//];