Commit afb6793d by Angel MAS

discounts coupons

parent 654716c2
<?php
namespace Onestartup\Shop\Controller;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Yajra\Datatables\Datatables;
use Onestartup\Shop\Model\DiscountCoupon as Coupon;
class DiscountCouponController extends Controller
{
/**
* Display a listing of the resource.
* @return Response
*/
public function index()
{
$coupons = Coupon::paginate(25);
return view('shop::coupon.index')
->with('coupons', $coupons);
}
/**
* Store a newly created resource in storage.
* @param Request $request
* @return Response
*/
public function store(Request $request)
{
$coupon = new Coupon($request->all());
$coupon->save();
return redirect()
->back()
->with('message_success', 'Cupon de descuento agregado correctamente');
}
/**
* Show the form for editing the specified resource.
* @return Response
*/
public function edit($id)
{
$coupon = Coupon::find($id);
return view('shop::coupon.edit')
->with('coupon', $coupon);
}
/**
* Update the specified resource in storage.
* @param Request $request
* @return Response
*/
public function update(Request $request, $id)
{
$coupon = Coupon::find($id);
$coupon->fill($request->all());
$coupon->save();
return redirect()
->back()
->with('message_success', 'Cupon de descuento actualizado correctamente');
}
/**
* Remove the specified resource from storage.
* @return Response
*/
public function destroy($id)
{
$coupon = Coupon::find($id);
$coupon->delete();
return redirect()
->back()
->with('message_danger', 'Cupon de descuento eliminado correctamente');
}
}
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateDiscountCouponsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('discount_coupons', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('code')->unique();
$table->string('type');
$table->string('value');
$table->boolean('active')->default(true);
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('discount_coupons');
}
}
<?php
namespace Onestartup\Shop\Model;
use Illuminate\Database\Eloquent\Model;
class DiscountCoupon extends Model
{
protected $table = "discount_coupons";
protected $fillable = [
'name',
'code',
'type',
'value',
'active'
];
}
......@@ -4,6 +4,7 @@ Route::group(['middleware' => ['web', 'auth', 'is_admin']], function(){
Route::resource('admin/shop/product', 'Onestartup\Shop\Controller\AdminProductController', ['as'=>'admin.shop']);
Route::resource('admin/shop/category', 'Onestartup\Shop\Controller\CategoryController', ['as'=>'admin.shop']);
Route::resource('admin/shop/coupon', 'Onestartup\Shop\Controller\DiscountCouponController', ['as'=>'admin.shop']);
Route::resource('admin/shop/extra-fields', 'Onestartup\Shop\Controller\ExtraFieldController', ['as'=>'admin.shop']);
......
@extends('crm-admin::main-layout')
@section('content')
<div class='row'>
<div class='col-md-12'>
<div class='box'>
<div class='box-header dark'>
<h2>Actualizar información</h2>
</div>
<div class='box-body'>
<div class='col-md-12'>
{!! Form::model($coupon,['route'=> ['admin.shop.coupon.update',$coupon->id],"method"=>"PUT", 'enctype'=>'multipart/form-data']) !!}
@include('shop::coupon.fields')
</div>
</div>
<div class='dker p-a text-right'>
<div class='col-md-12'>
<a class='btn danger' href="{{route('admin.shop.coupon.index')}}">Cancelar</a>
{!! Form::submit('Actualizar información', ['class'=>'btn dark']) !!}
{!! Form::close() !!}
</div>
</div>
</div>
</div>
</div>
@endsection
<div class="form-group">
{!! Form::label('name', 'Nombre *') !!}
{!! Form::text('name', null, ["class"=>"form-control", "required"=>"required", "placeholder"=>"Coloque aquí el nombre del codigo"]) !!}
</div>
<div class="form-group">
{!! Form::label('code', 'Código del descuento *') !!}
{!! Form::text('code', null, ["class"=>"form-control", "required"=>"required", "placeholder"=>"Coloque aquí el codigo promocional"]) !!}
</div>
<div class="form-group">
{!! Form::label('type', 'Tipo de descuento') !!}
{!! Form::select('type', ['Efectivo'=>'Efectivo', 'Porcentaje'=>'Porcentaje'], null, ["class"=>"form-control", "required"=>"required"]) !!}
</div>
<div class="form-group">
{!! Form::label('value', 'Valor a descontar') !!}
{!! Form::text('value', null, ["class"=>"form-control", "placeholder"=>"Coloque el porcentaje o cantidad"]) !!}
</div>
<div class="form-group">
{!! Form::label('active', 'Estado') !!}
{!! Form::select('active', [true=>'Activo', false=>'Inactivo'], null, ["class"=>"form-control", "required"=>"required"]) !!}
</div>
@extends('crm-admin::main-layout')
@section('content')
@php
setlocale(LC_MONETARY, 'en_US');
@endphp
<div class='row'>
<div class='col-md-12 collapse' id='agregarCategoria'>
<div class='box'>
<div class='box-header dark'>
<h2>
Agregar nueva promoción
<span></span>
<a aria-expanded='false' class='btn btn-xs btn-danger button-ml' data-toggle='collapse' href='#agregarCategoria'>
Cancelar
</a>
</h2>
</div>
<div class='box-body'>
<div class='col-md-12'>
{!! Form::open(['route'=> 'admin.shop.coupon.store','method'=>'POST']) !!}
@include('shop::coupon.fields')
<div class='form-group'>
<button class='btn btn-primary' type='submit'>
Registrar
</button>
</div>
{!! Form::close() !!}
</div>
</div>
</div>
</div>
<div class='col-md-12'>
<div class='box'>
<div class='box-header dark'>
<h2>
Listado de promociones
<span>
<a aria-expanded='false' class='btn btn-xs btn-info button-ml' data-toggle='collapse' href='#agregarCategoria'>
<i class='fas fa-plus'></i>
Agregar nueva
</a>
</span>
</h2>
</div>
<div class='box-body'>
<div class='col-md-12'>
<table class='table'>
<tr>
<th>#</th>
<th>Promocion</th>
<th>Tipo</th>
<th>Valor</th>
<th></th>
</tr>
@foreach ($coupons as $coupon)
<tr>
<td> {{$coupon->id}}</td>
<td>
<p> {{$coupon->name}}</p>
<p>
Codigo
<b> {{$coupon->code}}</b>
</p>
</td>
<td> {{$coupon->type}}</td>
<td>
@if($coupon->type == 'Efectivo')
{{money_format('%(#10n', $coupon->value)}}
@endif
@if($coupon->type == 'Porcentaje')
% {{$coupon->value}}
@endif
</td>
<td>
{!! Form::open(['route'=> ['admin.shop.coupon.destroy',$coupon->id],'method'=>'DELETE'])!!}
<button class='btn btn-danger btn-xs button-mb' onclick="return confirm('¿Estás seguro de eliminar este elemento?');" type='submit'>
<i class='fas fa-trash-alt icon-special-size'></i>
Eliminar
</button>
{!! Form::close()!!}
<a class='btn btn-xs accent' href="{{route('admin.shop.coupon.edit', $coupon->id)}}">
<i class='fas fa-edit icon-special-size'></i>
Editar
</a>
</td>
@endforeach
</tr>
</table>
</div>
</div>
<div class='dker p-a text-right'>
{{ $coupons->links() }}
</div>
</div>
</div>
</div>
@endsection
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment