added Avisa theme part

added customer controller to profile
WIP: complete
pull/49/head
A1Gard 5 months ago
parent 01ae09b208
commit 35b2ba64eb

@ -6,6 +6,7 @@ use App\Http\Controllers\Controller;
use App\Http\Controllers\XController;
use App\Http\Requests\CustomerSaveRequest;
use App\Models\Access;
use App\Models\Credit;
use App\Models\Customer;
use Illuminate\Http\Request;
use App\Helper;
@ -50,11 +51,18 @@ class CustomerController extends XController
{
$customer->name = $request->input('name');
$customer->address = $request->input('address');
$customer->state = $request->input('state');
$customer->credit = $request->input('credit')??0 ;
$customer->city = $request->input('city');
$customer->postal_code = $request->input('postal_code');
if ($customer->credit != $request->input('credit')){
$diff = $request->input('credit') - $customer->credit;
$customer->credit = $request->input('credit')??0 ;
$cr = new Credit();
$cr->customer_id = $customer->id;
$cr->amount = $diff;
$cr->data = json_encode([
'user_id' => auth()->user()->id,
'message' => __("Increase / decrease by Admin"),
]);
$cr->save();
}
if ($request->has('email')) {
$customer->email = $request->input('email');
}

@ -123,12 +123,19 @@ class CardController extends Controller
$inv->total_price = $total;
$inv->save();
return [$inv,$inv->orders];
// clear shopping card
// self::clear();
return [$inv, $inv->orders];
}
public static function clear()
{
if (auth('customer')->check()){
$customer = auth('customer')->user();
$customer->card = null;
$customer->save();
}
\Cookie::expire('card');
\Cookie::expire('q');
return true;

@ -422,11 +422,6 @@ class ClientController extends Controller
}
}
public function profile()
{
return auth('customer')->user();
}
public function sendSms(Request $request)
{

@ -0,0 +1,50 @@
<?php
namespace App\Http\Controllers;
use App\Models\Invoice;
use Illuminate\Http\Request;
use Illuminate\Validation\Rules\In;
class CustomerController extends Controller
{
//
public function __construct()
{
if (!auth('customer')->check()) {
return redirect()->route('client.sign-in');
}
}
public function profile()
{
$area = 'customer';
$title = __("Profile");
$subtitle = 'You information';
return view('client.default-list', compact('area', 'title', 'subtitle'));return auth('customer')->user();
}
public function save(Request $request){
$request->validate([
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'email', 'max:255'],
'mobile' => ['required', 'string', 'max:255'],
'password' => ['nullable', 'string', 'min:8', 'confirmed'],
]);
$customer = auth('customer')->user();
$customer->name = $request->name;
$customer->email = $request->email;
$customer->mobile = $request->mobile;
if ($request->has('password') && trim($request->input('password')) != ''){
$customer->password = bcrypt($request->password);
}
$customer->save();
return redirect()->route('client.profile')->with('message', __('Profile updated successfully'));
}
public function invoice(Invoice $invoice){
return $invoice;
}
}

@ -24,7 +24,7 @@ class CustomerSaveRequest extends FormRequest
return [
//
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:customers,email'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:customers,email,'.$this->id],
'password' => ['nullable', 'string', 'min:6', 'confirmed'],
'mobile'=> ['required', 'string', 'min:10'],
];

@ -7,5 +7,8 @@ use Illuminate\Database\Eloquent\Model;
class Credit extends Model
{
use HasFactory;
public function invoice(){
return $this->belongsTo(Invoice::class);
}
}

@ -13,9 +13,9 @@ return new class extends Migration
{
Schema::create('credits', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('amount');
$table->bigInteger('amount');
$table->unsignedBigInteger('customer_id');
$table->unsignedBigInteger('invoice_id');
$table->unsignedBigInteger('invoice_id')->nullable();
$table->text('data')->nullable()->default(null);
$table->softDeletes();
$table->timestamps();

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 6.3 KiB

@ -0,0 +1,16 @@
document.addEventListener('DOMContentLoaded', function () {
if (document.querySelectorAll('.tab-control a').length > 0) {
document.querySelectorAll('.tab-control a')?.forEach(function (el) {
el.addEventListener('click', function () {
try {
document.querySelector('.tab-control a.active').classList.remove('active');
this.classList.add('active');
document.querySelector('.tab.active').classList.remove('active');
document.querySelector(this.getAttribute('href')).classList.add('active');
} catch {
}
});
});
}
});

@ -78,3 +78,13 @@ body{
height: 25px;
border: 1px solid gray;
}
#tabs-content{
.tab{
display: none;
&.active{
display: block;
}
}
}

@ -77,7 +77,7 @@
{{__('Credit')}}
</label>
<currency-input :xvalue="{{old('credit',$item->credit??0)}}"
name="credit" xid="credit"
xname="credit" xid="credit"
@error('credit') :err="true" @enderror>
</currency-input>
</div>

@ -0,0 +1,340 @@
<section id='AvisaCustomer'>
<div class="{{gfx()['container']}}">
<div class="row">
<div class="col-lg-3">
<img src="{{asset('assets/default/unknown.svg')}}" alt="[avatar]" class="avisa-avatar">
<div class="text-center ">
{{__("Welcome back")}}
<br>
<strong>
{{auth('customer')->user()->name}}
</strong>
</div>
<ul class="tab-control" id="avisa-tabs">
<li>
<a href="#summary" class="active">
<i class="ri-home-2-line"></i>
{{__("Summary")}}
</a>
</li>
<li>
<a href="#invoices">
<i class="ri-file-list-3-line"></i>
{{__("Invoices")}}
</a>
</li>
<li>
<a href="#profile">
<i class="ri-user-3-line"></i>
{{__("Profile")}}
</a>
</li>
<li>
<a href="#addresses">
<i class="ri-map-pin-user-line"></i>
{{__("Addresses")}}
</a>
</li>
<li>
<a href="#credit">
<i class="ri-bank-card-2-line"></i>
{{__("Credit")}}
</a>
</li>
<li>
<a href="#tickets">
<i class="ri-inbox-2-line"></i>
{{__("Tickets")}}
</a>
</li>
<li>
<a href="#tickets">
<i class="ri-mail-add-line"></i>
{{__("Submit new ticket")}}
</a>
</li>
<li>
<a href="#comments">
<i class="ri-message-2-line"></i>
{{__("Comments")}}
</a>
</li>
<li>
<a href="{{route('client.sign-out')}}">
<i class="ri-logout-box-line"></i>
{{__("Sign-out")}}
</a>
</li>
</ul>
</div>
<div class="col-lg-9" id="tabs-content">
<div class="mt-lg-5 mb-lg-5"> &nbsp;</div>
<div class="mt-lg-5 mb-lg-5"> &nbsp;</div>
@include('components.err')
<div class="tab active" id="summary">
<div class="row">
<div class="avisa-grid col-lg-3 col-md-6">
<div class="grid-item">
<i class="ri-list-check-3"></i>
<h2>
{{number_format(auth('customer')->user()->invoices()->count())}}
</h2>
<h3>
{{__("Invoices")}}
</h3>
</div>
</div>
<div class="avisa-grid col-lg-3 col-md-6">
<div class="grid-item">
<i class="ri-bank-card-2-line"></i>
<h3>
{{__("Credits")}}
</h3>
<h2>
{{number_format(auth('customer')->user()->credit)}}
{{config('app.currency.symbol')}}
</h2>
</div>
</div>
<div class="avisa-grid col-lg-3 col-md-6">
<div class="grid-item">
<i class="ri-message-3-line"></i>
<h2>
{{number_format(auth('customer')->user()->tickets()->count())}}
</h2>
<h3>
{{__("Tickets")}}
</h3>
</div>
</div>
<div class="avisa-grid col-lg-3 col-md-6">
<div class="grid-item">
<i class="ri-map-pin-line"></i>
<h2>
{{number_format(auth('customer')->user()->addresses()->count())}}
</h2>
<h3>
{{__("Addresses")}}
</h3>
</div>
</div>
</div>
@if(cardCount() > 0)
<div class="alert alert-info mt-4">
<a href="{{ route('client.card') }}" class="btn btn-primary float-end">
{{__("Continue")}}
</a>
<h5 class="alert-heading">
{{__("System notification")}}
</h5>
{{__("You have some products in your shopping card.")}}
<br>
</div>
@endif
@if( auth('customer')->user()->name == null || trim(auth('customer')->user()->name) == '')
<div class="alert alert-danger mt-4">
<h5 class="alert-heading">
{{__("System notification")}}
</h5>
{{__("Your information is insufficient, Please complete your information")}}
</div>
@endif
@if( auth('customer')->user()->addresses()->count() == 0)
<div class="alert alert-danger mt-4">
<h5 class="alert-heading">
{{__("System notification")}}
</h5>
{{__("You need at least one address to order, Please add address")}}
</div>
@endif
</div>
<div class="tab" id="invoices">
<table class="table table-striped text-center">
<tr>
<th>
#
</th>
<th>
{{__("Datetime")}}
</th>
<th>
{{__("Orders count")}}
</th>
<th>
{{__("Total price")}}
</th>
<th>
{{__("Status")}}
</th>
<th>
-
</th>
</tr>
@foreach(auth('customer')->user()->invoices as $inv)
<tr>
<td>
{{$inv->hash}}
</td>
<td>
{{$inv->created_at->ldate('Y-m-d H:i')}}
</td>
<td>
{{number_format($inv->count)}}
</td>
<td>
<b>
{{number_format($inv->total_price)}}
{{config('app.currency.symbol')}}
</b>
</td>
<td>
<span class="inv-{{$inv->status}}">
{{__($inv->status)}}
</span>
</td>
<td style="width: 170px">
<a href="{{ route('client.invoice',$inv->hash) }}"
class="btn btn-outline-primary btn-sm ">
<i class="ri-eye-line"></i>
</a>
@if($inv->status == 'PENDING')
<a href="#" class="btn btn-outline-primary btn-sm ms-2">
<i class="ri-secure-payment-line"></i>
{{__("Pay now")}}
</a>
@endif
</td>
</tr>
@endforeach
</table>
</div>
<div class="tab" id="profile">
<div class="alert alert-info">
{{__("If you want to change the password, choose both the same. Otherwise, leave the password field blank.")}}
</div>
<form action="{{route('client.profile.save')}}" method="post">
@csrf
<div class="row">
<div class="col-md-4 mt-3">
<div class="form-group">
<label for="name">
{{__('Name')}}
</label>
<input name="name" type="text"
class="form-control @error('name') is-invalid @enderror"
placeholder="{{__('Name')}}"
value="{{old('name',auth('customer')->user()->name??null)}}"/>
</div>
</div>
<div class="col-md-4 mt-3">
<div class="form-group">
<label for="email">
{{__('Email')}}
</label>
<input name="email" type="email"
class="form-control @error('email') is-invalid @enderror"
placeholder="{{__('Email')}}"
value="{{old('email',auth('customer')->user()->email??null)}}"/>
</div>
</div>
<div class="col-md-4 mt-3">
<div class="form-group">
<label for="mobile">
{{__('Mobile')}}
</label>
<input name="mobile" type="text" @if(config('app.sign.sms')) readonly
@endif class="form-control @error('mobile') is-invalid @enderror"
placeholder="{{__('Mobile')}}"
value="{{old('mobile',auth('customer')->user()->mobile??null)}}"
min-length="10"/>
</div>
</div>
<div class="col-md-6 mt-3">
<div class="form-group">
<label for="password">
{{__('Password')}}
</label>
<input name="password" type="password"
class="form-control @error('password') is-invalid @enderror"
placeholder="{{__('Password')}}" value="{{old('password',''??null)}}"/>
</div>
</div>
<div class="col-md-6 mt-3">
<div class="form-group">
<label for="password_confirmation">
{{__('password repeat')}}
</label>
<input name="password_confirmation" type="password"
class="form-control @error('password_confirmation') is-invalid @enderror"
placeholder="{{__('password repeat')}}"
value="{{old('password_confirmation',$item->password_confirmation??null)}}"/>
</div>
</div>
<div class="col-md-12">
<label> &nbsp;</label>
<input name="" type="submit" class="btn btn-primary mt-3 w-100 "
value="{{__('Save')}}"/>
</div>
</div>
</form>
</div>
<div class="tab" id="credit">
<div class="avisa-grid">
<div class="grid-item">
<i class="ri-bank-card-2-line"></i>
<h3>
{{__("Credits")}}
</h3>
<h2>
{{number_format(auth('customer')->user()->credit)}}
{{config('app.currency.symbol')}}
</h2>
</div>
</div>
<h5 class="my-3">
{{__("Credit history")}}
</h5>
@foreach(auth('customer')->user()->credits as $cr)
<div class="alert alert-info">
@if($cr->invoice_id != null)
<a href="{{ route('client.invoice',$cr->invoice()->hash) }}"
class="btn btn-outline-primary btn-sm ">
<i class="ri-eye-line"></i>
</a>
@endif
[{{$cr->created_at->ldate('Y-m-d H:i')}}]
<b class="ms-4">
{{number_format($cr->amount)}} {{config('app.currency.symbol')}}
</b>
@php($data = json_decode($cr->data))
@if(isset($data->message))
<i class="ms-4">
{{$data->message}}
</i>
@endif
</div>
@endforeach
{{-- WIP add credit manual--}}
</div>
<div class="tab" id="tickets">
{{-- WIP tikets--}}
</div>
<div class="tab" id="comments">
{{-- WIP comments--}}
</div>
<div class="tab" id="submit-ticket">
{{-- WIP submit new ticket --}}
</div>
<div class="tab" id="addresses">
{{-- WIP submit new ticket --}}
</div>
</div>
</div>
</div>
</section>

@ -0,0 +1,10 @@
{
"name": "AvisaCustomer",
"version": "1.0",
"author": "xStack",
"email": "xshop@xstack.ir",
"license": "GPL-3.0-or-later",
"url": "https:\/\/xstack.ir",
"author_url": "https:\/\/4xmen.ir",
"packages": []
}

@ -0,0 +1,21 @@
<?php
namespace Resources\Views\Segments;
use App\Models\Part;
class AvisaCustomer
{
public static function onAdd(Part $part = null)
{
}
public static function onRemove(Part $part = null)
{
}
public static function onMount(Part $part = null)
{
return $part;
}
}

@ -0,0 +1,93 @@
#AvisaCustomer {
padding: 2rem 0;
.avisa-avatar {
height: 128px;
width: 128px;
display: block;
border-radius: 50%;
object-fit: cover;
margin: auto;
}
#avisa-tabs {
list-style: none;
padding: 1rem 0;
margin: 1rem 0;
border-radius: var(--xshop-border-radius);
background: var(--xshop-primary);
li {
a {
padding: .5rem 1rem;
color: var(--xshop-diff);
display: block;
font-size: 20px;
transition: 500ms;
&.active, &:hover {
background: var(--xshop-secondary);
color: var(--xshop-diff2);
}
}
i{
margin: 0 1rem;
}
}
}
.avisa-grid{
.grid-item{
overflow: hidden;
height: 200px;
border-radius: var(--xshop-border-radius);
position: relative;
display: flex;
align-items: center;
justify-content: center;
i{
position: absolute;
transform: rotateZ(-17deg);
inset-inline-start: 7%;
top: -10%;
font-size: 75px;
opacity: .3;
}
h3{
position: absolute;
left: 0;
right: 0;
bottom: .2rem;
text-align: center;
opacity: .7;
}
}
&:nth-child(1){
.grid-item{
background: rgba(248, 170, 0, 0.63);
}
}
&:nth-child(2){
.grid-item{
background: rgba(184, 11, 109, 0.63);
}
}
&:nth-child(3){
.grid-item{
background: rgba(11, 184, 123, 0.63);
}
}
&:nth-child(4){
.grid-item{
background: rgba(11, 112, 184, 0.63);
}
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 86 KiB

@ -375,7 +375,9 @@ Route::middleware([\App\Http\Middleware\VisitorCounter::class])
Route::get('/card/discount/{code}', [\App\Http\Controllers\CardController::class,'discount'])->name('card.discount');
Route::get('/card', [\App\Http\Controllers\CardController::class,'index'])->name('card');
Route::get('/cardClear',[\App\Http\Controllers\CardController::class,'clearing'])->name('card.clear');
Route::get('/profile', [\App\Http\Controllers\ClientController::class,'profile'])->name('profile');
Route::get('/profile', [\App\Http\Controllers\CustomerController::class,'profile'])->name('profile');
Route::post('/profile/save', [\App\Http\Controllers\CustomerController::class,'save'])->name('profile.save');
Route::get('/invoice/{invoice}', [\App\Http\Controllers\CustomerController::class,'invoice'])->name('invoice');
Route::get('/products', [\App\Http\Controllers\ClientController::class,'products'])->name('products');
Route::get('/attachments', [\App\Http\Controllers\ClientController::class,'attachments'])->name('attachments');
Route::get('/attachment/{attachment}', [\App\Http\Controllers\ClientController::class,'attachment'])->name('attachment');

Loading…
Cancel
Save