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 $SAVE_REQUEST = DiscountSaveRequest::class;
protected $cols = ['title','code','expire'];
protected $cols = ['title','code','expire','product_id'];
protected $extra_cols = ['id'];
protected $searchable = ['title','code','body'];

@ -32,6 +32,17 @@ class AppServiceProvider extends ServiceProvider
$dt = TDate::GetInstance();
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')}}"
xid="product_id"
xname="product_id"
@error('category_id') :err="true" @enderror
xvalue='{{old('product_id',$item->product_id??null)}}'
@error('product_id') :err="true" @enderror
xvalue='{{old('product_id',$item->product_id??request()->get('product_id'))}}'
:close-on-Select="true"></searchable-select>
</div>
</div>
@ -97,10 +97,10 @@
<div class="col-md-12 mt-3">
<div class="form-group">
<label for="body">
{{__('Post Text')}}
{{__('Description')}}
</label>
<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>
{{-- @trix(\App\Post::class, 'body')--}}
@ -126,7 +126,7 @@
{{__('Amount')}}
</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>
</div>
</div>

@ -54,19 +54,19 @@
rows="8">{{old('table',$item->table??null)}}</textarea>
</div>
</div>
<div class="accordion mt-2" id="accordionExample">
<div class="accordion-item">
<h2 class="accordion-header" id="headingTwo">
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse"
data-bs-target="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
<hr>
<h4 class="my-4">
{{__("Discounts")}}
</button>
</h2>
<div id="collapseTwo" class="accordion-collapse collapse" aria-labelledby="headingTwo"
data-bs-parent="#accordionExample">
<div class="accordion-body">
<a href="{{route('admin.discount.create')}}?product_id={{$item->id??null}}" class="btn btn-light float-end">
<i class="ri-add-line"></i>
{{__("Add new discount")}}
</a>
</h4>
<table class="table" id="discounts">
<tr>
<th>
{{__("Title")}}
</th>
<th>
{{__("Type")}}
</th>
@ -86,92 +86,92 @@
@if(isset($item))
@foreach($item->discounts as $dis)
<tr>
<td>
{{$dis->title}}
</td>
<td>
{{$dis->type}}
</td>
<td>
{{$dis->amount}}
{{number_format($dis->amount)}}
@if($dis->type == "PERCENT")
%
@endif
</td>
<td>
{{$dis->code}}
</td>
<td>
{{$dis->expire->jdate('Y/m/d')}}
{{$dis->expire->ldate('Y-m-d H:i:s')}}
</td>
<td>
<button type="button" class="btn btn-danger" data-id="{{$dis->id}}">
<a href="{{ route('admin.discount.destroy',$dis->id) }}" class="btn btn-danger" data-id="{{$dis->id}}">
<span class="ri-close-line"></span>
</button>
</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>
<input type="hidden" id="discount-rem" name="discount[remove]" value="[]">
</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>
</tbody>
</table>
</div>
</div>
</div>
</div>
{{--<div class="row">--}}
{{-- <div class="col-md-6">--}}
{{-- <div class="form-group mt-4">--}}
{{-- <label for="title">--}}
{{-- {{__('Title')}}--}}
{{-- </label>--}}
{{-- <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??'-' }}
</a>
@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
{{$item->$col}}
@endswitch

Loading…
Cancel
Save