added discounts to product

added located date to Carbon
pull/44/head
A1Gard 6 months ago
parent a57e934a52
commit 585e0cfecc

@ -17,7 +17,7 @@ class DiscountController extends XController
// protected $_MODEL_ = Discount::class; // protected $_MODEL_ = Discount::class;
// protected $SAVE_REQUEST = DiscountSaveRequest::class; // protected $SAVE_REQUEST = DiscountSaveRequest::class;
protected $cols = ['title','code','expire']; protected $cols = ['title','code','expire','product_id'];
protected $extra_cols = ['id']; protected $extra_cols = ['id'];
protected $searchable = ['title','code','body']; protected $searchable = ['title','code','body'];

@ -32,6 +32,17 @@ class AppServiceProvider extends ServiceProvider
$dt = TDate::GetInstance(); $dt = TDate::GetInstance();
return $dt->PDate($format, self::this()->timestamp); return $dt->PDate($format, self::this()->timestamp);
}); });
Carbon::macro('ldate', function ($format) {
if (self::this()->timestamp == 0){
return null;
}
if (config('app.locale') == 'fa'){
$format = str_replace('-','/',$format);
return self::this()->jdate($format);
}else{
return date($format,self::this()->timestamp);
}
});
} }

@ -63,8 +63,8 @@
xlang="{{config('app.locale')}}" xlang="{{config('app.locale')}}"
xid="product_id" xid="product_id"
xname="product_id" xname="product_id"
@error('category_id') :err="true" @enderror @error('product_id') :err="true" @enderror
xvalue='{{old('product_id',$item->product_id??null)}}' xvalue='{{old('product_id',$item->product_id??request()->get('product_id'))}}'
:close-on-Select="true"></searchable-select> :close-on-Select="true"></searchable-select>
</div> </div>
</div> </div>
@ -97,10 +97,10 @@
<div class="col-md-12 mt-3"> <div class="col-md-12 mt-3">
<div class="form-group"> <div class="form-group">
<label for="body"> <label for="body">
{{__('Post Text')}} {{__('Description')}}
</label> </label>
<textarea name="body" class="ckeditorx form-control @error('body') is-invalid @enderror" <textarea name="body" class="ckeditorx form-control @error('body') is-invalid @enderror"
placeholder="{{__('Post Text')}}" placeholder="{{__('Description')}}"
rows="8">{{old('body',$item->body??null)}}</textarea> rows="8">{{old('body',$item->body??null)}}</textarea>
{{-- @trix(\App\Post::class, 'body')--}} {{-- @trix(\App\Post::class, 'body')--}}
@ -126,7 +126,7 @@
{{__('Amount')}} {{__('Amount')}}
</label> </label>
<currency-input xname="amount" xid="amount" @error('amount') <currency-input xname="amount" xid="amount" @error('amount') xtitle="{{__('Title')}}"
:err="true" @enderror :xvalue="{{old('amount',$item->amount??null)}}"></currency-input> :err="true" @enderror :xvalue="{{old('amount',$item->amount??null)}}"></currency-input>
</div> </div>
</div> </div>

@ -23,12 +23,12 @@
<label for="tags" class="mt-2"> <label for="tags" class="mt-2">
{{__("Tags")}} {{__("Tags")}}
</label> </label>
<tag-input xname="tags" splitter=",," xid="tags" <tag-input xname="tags" splitter=",," xid="tags"
xtitle="{{__("Tags, Press enter")}}" xtitle="{{__("Tags, Press enter")}}"
@if(isset($item)) @if(isset($item))
xvalue="{{old('title',implode(',,',$item->tags->pluck('name')->toArray()??''))}}" xvalue="{{old('title',implode(',,',$item->tags->pluck('name')->toArray()??''))}}"
@endif @endif
></tag-input> ></tag-input>
</div> </div>
<div class="col-md-6"> <div class="col-md-6">
@ -54,124 +54,124 @@
rows="8">{{old('table',$item->table??null)}}</textarea> rows="8">{{old('table',$item->table??null)}}</textarea>
</div> </div>
</div> </div>
<div class="accordion mt-2" id="accordionExample"> <hr>
<div class="accordion-item"> <h4 class="my-4">
<h2 class="accordion-header" id="headingTwo"> {{__("Discounts")}}
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" <a href="{{route('admin.discount.create')}}?product_id={{$item->id??null}}" class="btn btn-light float-end">
data-bs-target="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo"> <i class="ri-add-line"></i>
{{__("Discounts")}} {{__("Add new discount")}}
</button> </a>
</h2> </h4>
<div id="collapseTwo" class="accordion-collapse collapse" aria-labelledby="headingTwo" <table class="table" id="discounts">
data-bs-parent="#accordionExample"> <tr>
<div class="accordion-body"> <th>
<table class="table" id="discounts"> {{__("Title")}}
<tr> </th>
<th> <th>
{{__("Type")}} {{__("Type")}}
</th> </th>
<th> <th>
{{__("Amount")}} {{__("Amount")}}
</th> </th>
<th> <th>
{{__("Discount code")}} {{__("Discount code")}}
</th> </th>
<th> <th>
{{__("Expire date")}} {{__("Expire date")}}
</th> </th>
<th> <th>
- -
</th> </th>
</tr> </tr>
@if(isset($item)) @if(isset($item))
@foreach($item->discounts as $dis) @foreach($item->discounts as $dis)
<tr> <tr>
<td> <td>
{{$dis->type}} {{$dis->title}}
</td> </td>
<td> <td>
{{$dis->amount}} {{$dis->type}}
</td> </td>
<td> <td>
{{$dis->code}} {{number_format($dis->amount)}}
</td> @if($dis->type == "PERCENT")
<td> %
{{$dis->expire->jdate('Y/m/d')}}
</td>
<td>
<button type="button" class="btn btn-danger" data-id="{{$dis->id}}">
<span class="ri-close-line"></span>
</button>
</td>
</tr>
@endforeach
@endif @endif
</table> </td>
<input type="hidden" id="discount-rem" name="discount[remove]" value="[]"> <td>
{{$dis->code}}
</td>
<td>
{{$dis->expire->ldate('Y-m-d H:i:s')}}
</td>
<td>
<a href="{{ route('admin.discount.destroy',$dis->id) }}" class="btn btn-danger" data-id="{{$dis->id}}">
<span class="ri-close-line"></span>
</a>
<a href="{{route('admin.discount.edit',$dis->id)}}" class="btn btn-primary ms-1">
<i class="ri-edit-line"></i>
</a>
</td>
</tr>
@endforeach
@endif
</table>
</div>
</div>
</div>
<div class="accordion-item">
<h2 class="accordion-header" id="headingThree">
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse"
data-bs-target="#collapseThree" aria-expanded="false" aria-controls="collapseThree">
{{__("New Discount")}}
</button>
</h2>
<div id="collapseThree" class="accordion-collapse collapse" aria-labelledby="headingThree"
data-bs-parent="#accordionExample">
<div class="accordion-body">
<table class="table" id="new-discount">
<thead>
<tr>
<th>
{{__("Type")}}
</th>
<th>
{{__("Amount")}}
</th>
{{-- <th>--}}
{{-- {{__("Discount code")}}--}}
{{-- </th>--}}
<th>
{{__("Expire date")}}
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<label>
{{__("by price")}}
<input type="radio" checked name="discount[type]" value="price">
</label>
&nbsp;
&nbsp;
<label>
{{__("by percent")}}
<input type="radio" name="discount[type]" value="percent">
</label>
</td>
<td>
<input type="text" id="price-amount" placeholder="{{__("Amount")}}"
name="discount[amount]" class="form-control">
</td>
{{-- <td>--}}
{{-- <input type="text" placeholder="{{__("Discount code")}}" name="discount[code]" class="form-control">--}}
{{-- </td>--}}
<td>
<input placeholder="{{__("Expire date")}}" type="text" data-reuslt="#exp-date"
class="form-control dtp">
<input type="hidden" name="discount[expire]" id="exp-date">
</td>
<td>
</td>
</tr> {{--<div class="row">--}}
</tbody> {{-- <div class="col-md-6">--}}
</table> {{-- <div class="form-group mt-4">--}}
</div> {{-- <label for="title">--}}
</div> {{-- {{__('Title')}}--}}
</div> {{-- </label>--}}
</div> {{-- <input name="discount[type]" type="text" id="title"--}}
{{-- class="form-control @error('discount.type') is-invalid @enderror"--}}
{{-- placeholder="{{__('Title')}}" value="{{old('discount.type')}}"/>--}}
{{-- </div>--}}
{{-- <div class="form-group mt-4">--}}
{{-- <label for="type">--}}
{{-- {{__('Type')}}--}}
{{-- </label>--}}
{{-- <select name="discount[type]" id="type"--}}
{{-- class="form-control @error('type') is-invalid @enderror">--}}
{{-- @foreach(\App\Models\Discount::$doscount_type as $k => $v)--}}
{{-- <option--}}
{{-- value="{{ $v }}" {{ old("discount",\App\Models\Discount::$doscount_type[0]) == $v ? "selected" : "" }}>{{ __($v) }}</option>--}}
{{-- @endforeach--}}
{{-- </select>--}}
{{-- </div>--}}
{{-- <div class="form-group mt-4">--}}
{{-- <label for="amount">--}}
{{-- {{__('Amount')}}--}}
{{-- </label>--}}
{{-- <currency-input xname="discount[amount]" xid="amount" xtitle="{{__('Amount')}}"--}}
{{-- @error('amount')--}}
{{-- :err="true"--}}
{{-- @enderror :xvalue="{{old('discount.amount')}}"></currency-input>--}}
{{-- </div>--}}
{{-- <div class="form-group mt-4">--}}
{{-- <label for="expire">--}}
{{-- {{__('Expire date')}}--}}
{{-- </label>--}}
{{-- <vue-datetime-picker-input--}}
{{-- :xmin="{{strtotime('yesterday')}}"--}}
{{-- xid="dp" xname="discount[expire]" xshow="datetime" xtitle="Expire date" def-tab="1"--}}
{{-- :timepicker="true"--}}
{{-- ></vue-datetime-picker-input>--}}
{{-- </div>--}}
{{-- </div>--}}
{{-- <div class="col-6 mt-3">--}}
{{-- <div class="form-group">--}}
{{-- <label for="body">--}}
{{-- {{__('Description')}}--}}
{{-- </label>--}}
{{-- <textarea name="body" class="ckeditorx form-control @error('body') is-invalid @enderror"--}}
{{-- placeholder="{{__('Description')}}"--}}
{{-- rows="4">{{old('body',$item->body??null)}}</textarea>--}}
{{-- </div>--}}
{{-- </div>--}}
{{--</div>--}}

@ -190,6 +190,14 @@
{{ $item->category?->name??'-' }} {{ $item->category?->name??'-' }}
</a> </a>
@break @break
@case($col == 'product_id')
<a href="{{route('admin.product.edit',$item->product?->slug)}}">
{{ $item->product?->name??'-' }}
</a>
@break
@case($col == 'expire')
{{$item->expire->ldate("Y-m-d")}}
@break
@default @default
{{$item->$col}} {{$item->$col}}
@endswitch @endswitch

Loading…
Cancel
Save