Commit 077f60f2 by Angel MAS

formulario de facturación

parent d6bb8da5
...@@ -14,6 +14,7 @@ use Onestartup\Shop\Model\ShippingAddres as Addres; ...@@ -14,6 +14,7 @@ use Onestartup\Shop\Model\ShippingAddres as Addres;
use Onestartup\Shop\Model\SaleShop as Sale; use Onestartup\Shop\Model\SaleShop as Sale;
use Onestartup\Shop\Model\DetailShop as Item; use Onestartup\Shop\Model\DetailShop as Item;
use Onestartup\Shop\Model\DiscountCoupon as Coupon; use Onestartup\Shop\Model\DiscountCoupon as Coupon;
use Onestartup\Shop\Model\Billing;
use Onestartup\Shop\Payment\MP; use Onestartup\Shop\Payment\MP;
use Onestartup\Shop\Notifications\PaymentClient; use Onestartup\Shop\Notifications\PaymentClient;
...@@ -43,15 +44,15 @@ class CartController extends Controller ...@@ -43,15 +44,15 @@ class CartController extends Controller
public function __construct() public function __construct()
{ {
if (!\Session::has('cart')) { if (!\Session::has('cart')) {
\Session::put('cart', array()); \Session::put('cart', array());
} }
setlocale(LC_MONETARY, 'en_US'); setlocale(LC_MONETARY, 'en_US');
$this->util = new Util(); $this->util = new Util();
} }
public function show() public function show()
{ {
$total = $this->total(); $total = $this->total();
$cart = \Session::get('cart'); $cart = \Session::get('cart');
...@@ -841,12 +842,12 @@ public function shipping() ...@@ -841,12 +842,12 @@ public function shipping()
} }
} else{ } else{
$msg = 'Lo sentimos este código de descuento ya expiró :('; $msg = 'Lo sentimos este código de descuento ya expiró :(';
} }
} }
$data = [ $data = [
'valid'=>$valid, 'valid'=>$valid,
'msg'=>$msg, 'msg'=>$msg,
'amount'=>money_format('%(#10n',$descuento), 'amount'=>money_format('%(#10n',$descuento),
...@@ -859,17 +860,119 @@ public function shipping() ...@@ -859,17 +860,119 @@ public function shipping()
} }
public function search(Request $request) public function getDiscount2($sale)
{ {
$error = ['error' => 'Sin resultados, ingrese otros campos para la búsqueda.'];
if($request->has('text')) { $client = $sale->client;
$addres = $client->shipping;
$cost_shipping = $addres->shipping_price->cost;
$products = Product::search($request->get('text'))->get();
return $products->count() ? $products : $error;
} $coupon = Coupon::where('code', $sale->coupon)->first();
return $error;
$descuento = 0;
$total = 0;
$total_without = 0;
$data = [];
foreach ($sale->products as $product) {
$aux = $product->pivot->quantity * $product->infoSale->sale_price;
$total += $aux;
$total_without += $aux;
}
if ($coupon != null) {
if ($total >= $coupon->min_sale) {
if ($coupon->type == 'Efectivo') {
$descuento = $coupon->value;
}
if ($coupon->type == 'Porcentaje') {
$descuento = ($coupon->value/100) * $total;
}
}
} }
$data = [
'amount' => money_format('%(#10n',$descuento),
'amount_unformated' => $descuento,
'total' => money_format('%(#10n', (($total+$cost_shipping)-$descuento)),
'total_unformated' => ($total+$cost_shipping)-$descuento,
'shipping' => money_format('%(#10n',$cost_shipping),
'shipping_unformated' => $cost_shipping,
'total_without'=> money_format('%(#10n',$total_without),
'total_without_unformated'=> $total_without
];
return $data;
}
public function search(Request $request)
{
$error = ['error' => 'Sin resultados, ingrese otros campos para la búsqueda.'];
if($request->has('text')) {
$products = Product::search($request->get('text'))->get();
return $products->count() ? $products : $error;
}
return $error;
}
public function facturacion($order_id)
{
$id_decript = \Crypt::decryptString($order_id);
$order = Sale::find($id_decript);
$data = null;
$client = $order->client;
$products = $order->products;
$addres = $client->shipping;
$billing = new Billing();
if ($order->billing()->count() > 0 ) {
$billing = $order->billing;;
}
$data = $this->getDiscount2($order);
return view('shop-public::cart.facturacion')
->with('order', $order)
->with('order_id', $order_id)
->with('billing', $billing)
->with('client', $client)
->with('data', $data)
->with('products', $products)
->with('total', 0)
->with('addres', $addres);
}
public function facturacionStore(Request $request, $order_id)
{
$id_decript = \Crypt::decryptString($order_id);
$order = Sale::find($id_decript);
$billing = null;
if ($order->billing()->count() <= 0 ) {
$billing = new Billing($request->all());
$order->billing()->save($billing);
}
return redirect()
->route('root')
->with('billing', 'billing');
}
} }
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateBillingsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('billings', function (Blueprint $table) {
$table->increments('id');
$table->string('razon');
$table->string('rfc');
$table->string('correo');
$table->string('cp');
$table->string('calle');
$table->string('numero');
$table->string('colonia');
$table->string('ciudad');
$table->string('estado');
$table->tinyInteger('status')->default(0);
$table->integer('sale_id')->unsigned();
$table->foreign('sale_id')->references('id')->on('sale_shops');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('billings');
}
}
<?php
namespace Onestartup\Shop\Model;
use Illuminate\Database\Eloquent\Model;
class Billing extends Model
{
protected $table = 'billings';
protected $fillable = [
'razon',
'rfc',
'correo',
'cp',
'calle',
'numero',
'colonia',
'ciudad',
'estado',
'sale_id'
];
public function sale()
{
return $this->belongsTo('Onestartup\Shop\Model\SaleShop', 'sale_id');
}
}
...@@ -34,4 +34,10 @@ class SaleShop extends Model ...@@ -34,4 +34,10 @@ class SaleShop extends Model
'product_id') 'product_id')
->withPivot('quantity'); ->withPivot('quantity');
} }
public function billing()
{
return $this->hasOne('Onestartup\Shop\Model\Billing', 'sale_id');
}
} }
...@@ -111,4 +111,8 @@ Route::group(['middleware' => ['web']], function(){ ...@@ -111,4 +111,8 @@ Route::group(['middleware' => ['web']], function(){
Route::get('get/coupon', 'Onestartup\Shop\Controller\CartController@discount')->name('cart.discount'); Route::get('get/coupon', 'Onestartup\Shop\Controller\CartController@discount')->name('cart.discount');
Route::get('/search', 'Onestartup\Shop\Controller\CartController@search')->name('api.search'); Route::get('/search', 'Onestartup\Shop\Controller\CartController@search')->name('api.search');
Route::get('/cart/facturacion/{order_id}', 'Onestartup\Shop\Controller\CartController@facturacion')->name('cart.facturacion');
Route::put('/cart/facturacion/{order_id}', 'Onestartup\Shop\Controller\CartController@facturacionStore')->name('facturacion.store');
}); });
...@@ -22,7 +22,7 @@ setlocale(LC_MONETARY, 'en_US'); ...@@ -22,7 +22,7 @@ setlocale(LC_MONETARY, 'en_US');
</li> </li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link block" href="" data-toggle="tab" data-target="#tab-3"> <a class="nav-link block" href="" data-toggle="tab" data-target="#tab-3">
<h6>Envio</h6> <h6>Envio y factura</h6>
</a> </a>
</li> </li>
</ul> </ul>
...@@ -183,7 +183,7 @@ setlocale(LC_MONETARY, 'en_US'); ...@@ -183,7 +183,7 @@ setlocale(LC_MONETARY, 'en_US');
<div class="box"> <div class="box">
<div class="box-body"> <div class="box-body">
<div class="row"> <div class="row">
<div class="col-md-8 offset-2"> <div class="col-md-6">
Direccion de entrega:<br> Direccion de entrega:<br>
<b>{{$shipping->calle}}, # {{$shipping->numero}}, col. {{$shipping->colonia}}</b><br> <b>{{$shipping->calle}}, # {{$shipping->numero}}, col. {{$shipping->colonia}}</b><br>
...@@ -196,8 +196,31 @@ setlocale(LC_MONETARY, 'en_US'); ...@@ -196,8 +196,31 @@ setlocale(LC_MONETARY, 'en_US');
<span class="label warning">{{$sale->shipping_status}}</span> <span class="label warning">{{$sale->shipping_status}}</span>
</div>
<div class="col-md-6">
@if($sale->billing()->count() > 0)
<h4>Datos de facturación</h4>
Dirección: <br>
Calle {{$sale->billing->calle}} numero {{$sale->billing->numero}}, Col. {{$sale->billing->colonia}}
<br>
{{$sale->billing->ciudad}}, {{$sale->billing->estado}}. C.P. {{$sale->billing->cp}}
<br>
Razón social: <b>{{$sale->billing->razon}}</b><br>
R.F.C. <b>{{$sale->billing->rfc}}</b><br>
Correo electrónico:<b>{{$sale->billing->correo}}</b>
<br><br>
<h6>Liga de formulario de facturación</h6>
<a target="blank" href="{{route('cart.facturacion', \Crypt::encryptString($sale->id))}}">
Visitar link
</a>
@else
<br><br>
<h6>Liga de formulario de facturación</h6>
<a target="blank" href="{{route('cart.facturacion', \Crypt::encryptString($sale->id))}}">
Visitar link
</a>
@endif
</div> </div>
</div> </div>
</div> </div>
......
...@@ -44,6 +44,11 @@ Datos de envio: ...@@ -44,6 +44,11 @@ Datos de envio:
- *** {{$shipping->ciudad}}, {{$shipping->estado}}, C.P. {{$shipping->cp}}*** - *** {{$shipping->ciudad}}, {{$shipping->estado}}, C.P. {{$shipping->cp}}***
- Referencias: *** {{$shipping->referencias}} *** - Referencias: *** {{$shipping->referencias}} ***
- Requiere factura: *** {{$shipping->facturacion}} *** - Requiere factura: *** {{$shipping->facturacion}} ***
@if($shipping->facturacion == 'Si')
[Rellenar formulario de facturación]({{route('cart.facturacion', \Crypt::encryptString($order->id))}})
@endif
@endcomponent @endcomponent
Gracias por tu compra,<br> Gracias por tu compra,<br>
......
@extends('shop-public::layout')
@section('pageTitle', 'Finalizar compra')
@section('content')
@php
setlocale(LC_MONETARY, 'en_US');
@endphp
<section>
<h4>Detalle de la orden</h4>
<table class="table" style="width: 60%;">
<thead>
<tr>
<th>Producto</th>
<th>Precio</th>
<th>Cantidad</th>
<th>Subtotal</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach($products as $product)
<tr align="center">
<td>{{$product->name}}</td>
<td>{{money_format('%(#10n', $product->infoSale->sale_price)}}</td>
<td>{{$product->pivot->quantity}}</td>
<td>
{{money_format('%(#10n', ($product->infoSale->sale_price * $product->pivot->quantity))}}
</td>
</tr>
@endforeach
@if($order->coupon != null)
<tr align="center">
<td>Descuento: {{$order->coupon}}</td>
<td> - {{$data['amount']}}</td>
<td>1</td>
<td> - {{$data['amount']}}</td>
</tr>
@endif
<tr align="center">
<td> Envio </td>
<td> {{$data['shipping']}} </td>
<td> 1 </td>
<td> {{$data['shipping']}} </td>
</tr>
</tbody>
<tr>
<td colspan="3" align="right">
Total + Envio:
</td>
<td align="center">
{{$data['total']}}
</td>
</tr>
</table>
</section>
<h4>Formulario de pago</h4>
<section>
{!! Form::model($billing,['route'=> ['facturacion.store', $order_id],"method"=>"PUT"]) !!}
@include('shop-public::forms.fields-facturacion')
{!! Form::submit('Enviar información', ['class'=>'btn btn-primary']) !!}
{!! Form::close() !!}
</section>
@endsection
<div class="form-group">
{!! Form::label('razon', 'Nombre o razón social', ['class'=>'form-control']) !!}
{!! Form::text('razon', null, ['class'=>'form-control','required'=>'required']) !!}
</div>
<div class="form-group">
{!! Form::label('rfc', 'RFC', ['class'=>'form-control']) !!}
{!! Form::text('rfc', null, ['class'=>'form-control','required'=>'required']) !!}
</div>
<div class="form-group">
{!! Form::label('correo', 'Correo electrónico', ['class'=>'form-control']) !!}
{!! Form::text('correo', null, ['class'=>'form-control','required'=>'required']) !!}
</div>
<div class="form-group">
{!! Form::label('calle', 'Calle', ['class'=>'form-control']) !!}
{!! Form::text('calle', null, ['class'=>'form-control','required'=>'required']) !!}
</div>
<div class="form-group">
{!! Form::label('numero', 'Numero', ['class'=>'form-control']) !!}
{!! Form::text('numero', null, ['class'=>'form-control','required'=>'required']) !!}
</div>
<div class="form-group">
{!! Form::label('colonia', 'Colonia', ['class'=>'form-control']) !!}
{!! Form::text('colonia', null, ['class'=>'form-control','required'=>'required']) !!}
</div>
<div class="form-group">
{!! Form::label('estado', 'Estado', ['class'=>'form-control']) !!}
{!! Form::text('estado', null, ['class'=>'form-control','required'=>'required']) !!}
</div>
<div class="form-group">
{!! Form::label('ciudad', 'Ciudad o delegación', ['class'=>'form-control']) !!}
{!! Form::text('ciudad', null, ['class'=>'form-control','required'=>'required']) !!}
</div>
<div class="form-group">
{!! Form::label('cp', 'Codigo postal', ['class'=>'form-control']) !!}
{!! Form::text('cp', null, ['class'=>'form-control','required'=>'required']) !!}
</div>
...@@ -86,6 +86,14 @@ $util = new Onestartup\Shop\Libs\Util(); ...@@ -86,6 +86,14 @@ $util = new Onestartup\Shop\Libs\Util();
</script> </script>
@endif @endif
@if(Session::has('billing'))
<script type="text/javascript">
swal("Petición exitosa",
"Enviaremos la factura a tu correo electrónico",
"success")
</script>
@endif
@if(Session::has('url_ficha')) @if(Session::has('url_ficha'))
<script> <script>
......
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