Commit a61dbfed by Angel MAS

implementado facturacion

parent 2e37c729
...@@ -458,4 +458,100 @@ class AdminProductController extends Controller ...@@ -458,4 +458,100 @@ class AdminProductController extends Controller
} }
public function facturar(Request $request, $sale_id)
{
$sale = Sale::find($sale_id);
$billing = $sale->billing;
$products = $sale->products;
$conceptos = [];
//return $products;
$emisor = \FacturaDigital::emisor()
->setRegimenFiscal('612')
->getData();
$receptor = \FacturaDigital::receptor()
->setRfc($billing->rfc)
->setNombre($billing->razon)
->setUsoCFDI($billing->uso_cfdi)
->setCalle($billing->calle)
->setNoExt($billing->numero)
->setColonia($billing->colonia)
->setMunicipio($billing->ciudad)
->setEstado($billing->estado)
->setPais('Mexico')
->setCodigoPostal($billing->cp)
->getData();
foreach ($products as $product) {
$concepto = \FacturaDigital::concepto()
->setClaveProdServ($product->categoria_sat->clave_producto)
->setNoIdentificacion($product->id)
->setCantidad($product->pivot->quantity)
->setClaveUnidad($product->categoria_sat->clave_unidad)
->setUnidad($product->categoria_sat->unidad)
->setDescripcion($product->name)
->setValorUnitario($product->infoSale->sale_price)
->getData();
array_push($conceptos, $concepto);
}
$lista = \FacturaDigital::listaConceptos();
$lista->setConceptos($conceptos);
$totales = $lista->getTotalConceptos();
$factura = \FacturaDigital::setSerie('F')
->setFolio('71278')
->setFecha('AUTO')
->setFormaPago('01')
->setCondicionesDePago('Pago de contado')
->setMoneda('MXN')
->setTipoCambio('1')
->setTipoDeComprobante('I')
->setMetodoPago('PUE')
->setLugarExpedicion('67150') //C.P.
->setLeyendaFolio('Factura')
->setSubTotal($totales['totalConceptos'])
//->setDescuento('30.00')
->setTotal($totales['totalConceptos'] + $totales['totalImpuestos'] );
$impuesto = \FacturaDigital::impuesto()
->getData($totales['totalImpuestos']);
$factura->setEmisor($emisor);
$factura->setReceptor($receptor);
$factura->setConceptos($lista->getData());
$factura->setImpuestos($impuesto);
$factura_final = $factura->enviar();
if ($factura_final['codigo'] == 200) {
$billing->uuid=$factura_final['cfdi']['UUID'];
$billing->pdf=$factura_final['cfdi']['PDF'];
$billing->xml=$factura_final['cfdi']['XML'];
$billing->status = 1;
$billing->save();
$enviar = $factura->enviarCorreo($factura_final['cfdi']['UUID'], $billing->correo, '');
if ($enviar) {
return redirect()->back()->with('message_success', "Factura enviada por correo");
} else {
return redirect()->back()->with('message_warning', "No se pudo enviar la factura");
}
} else {
return redirect()->back()->with('message_danger', $factura_final['mensaje']);
}
}
} }
...@@ -24,6 +24,8 @@ class OrderDataTable extends DataTable ...@@ -24,6 +24,8 @@ class OrderDataTable extends DataTable
->addColumn('orden', function(Sale $sale) { ->addColumn('orden', function(Sale $sale) {
$estado = ""; $estado = "";
$html = ""; $html = "";
$facturacion = $sale->facturacion != null ? $sale->facturacion : 'N/A';
$enviar_factura = "<br><b><span class='label warning'>Datos no proporcionados aún</span></b>";
if ($sale->status == 0) { if ($sale->status == 0) {
$estado = "<span class='label danger'>Cancelado</span>"; $estado = "<span class='label danger'>Cancelado</span>";
} }
...@@ -47,6 +49,24 @@ class OrderDataTable extends DataTable ...@@ -47,6 +49,24 @@ class OrderDataTable extends DataTable
} else { } else {
$html = "Estado: <b>$estado</b><br>Tipo: <b>$sale->payment_type</b> <br>Transaccion:<br><b>$sale->transaction_id</b><br>Envio: <b>Recojer en la tienda</b>"; $html = "Estado: <b>$estado</b><br>Tipo: <b>$sale->payment_type</b> <br>Transaccion:<br><b>$sale->transaction_id</b><br>Envio: <b>Recojer en la tienda</b>";
} }
$html = $html."<br>Requiere factura: <b><span class='label info'>".$facturacion."</span></b>";
if ($facturacion == "Si") {
if ($sale->billing()->count() > 0) {
$billing = $sale->billing;
$enviar_factura = "<br><b><span class='label warning'>Factura pendiente</span></b>";
if ($billing->status == 1 ) {
$enviar_factura = "<br><b><span class='label success'>Factura enviada</span></b>";
}
if ($billing->status == 2 ) {
$enviar_factura = "<br><b><span class='label danger'>Factura cancelada</span></b>";
}
}
$html = $html.$enviar_factura;
}
return $html; return $html;
}) })
...@@ -65,7 +85,7 @@ class OrderDataTable extends DataTable ...@@ -65,7 +85,7 @@ class OrderDataTable extends DataTable
*/ */
public function query(Sale $model) public function query(Sale $model)
{ {
return $model->select(['id', 'client_id', 'status', 'payment_type','transaction_id', 'total', 'created_at'])->where('status', '!=', 0)->orderBy('id', 'desc'); return $model->select(['id', 'client_id', 'status', 'payment_type','transaction_id', 'total', 'facturacion','created_at'])->where('status', '!=', 0)->orderBy('id', 'desc');
} }
/** /**
......
...@@ -11,6 +11,10 @@ Route::group(['middleware' => ['web', 'auth', 'is_admin']], function(){ ...@@ -11,6 +11,10 @@ Route::group(['middleware' => ['web', 'auth', 'is_admin']], function(){
Route::resource('admin/shop/shipping', 'Onestartup\Shop\Controller\ShippingPriceController', ['as'=>'admin.shop']); Route::resource('admin/shop/shipping', 'Onestartup\Shop\Controller\ShippingPriceController', ['as'=>'admin.shop']);
Route::put('admin/shop/facturar/{sale_id}',
'Onestartup\Shop\Controller\AdminProductController@facturar')
->name('admin.shop.facturar');
Route::delete('admin-shop-category/delete/cover{id}', Route::delete('admin-shop-category/delete/cover{id}',
'Onestartup\Shop\Controller\CategoryController@deleteCover') 'Onestartup\Shop\Controller\CategoryController@deleteCover')
->name('admin-shop-category.delete.cover'); ->name('admin-shop-category.delete.cover');
......
...@@ -237,12 +237,34 @@ setlocale(LC_MONETARY, 'en_US'); ...@@ -237,12 +237,34 @@ setlocale(LC_MONETARY, 'en_US');
</div> </div>
<div class="col-md-6"> <div class="col-md-6">
<h4>Datos de facturación</h4>
<p> <p>
¿Requiere factura? <b>{{$sale->facturacion}}</b> ¿Requiere factura? <b>{{$sale->facturacion}}</b>
</p> </p>
@if($sale->billing()->count() > 0) @if($sale->billing()->count() > 0)
<h4>Datos de facturación</h4>
Dirección: <br> @if($sale->billing->status == 0)
<b>Factura Pendiente</b><br>
{!! Form::model($sale,['route'=> ['admin.shop.facturar',$sale->id],"method"=>"PUT"]) !!}
{!! Form::submit('Crear y enviar factura', ['class'=>'btn-xs primary']) !!}
{!! Form::close() !!}
<br>
@endif
@if($sale->billing->status == 1)
<b>Factura Enviada</b><br>
<a href="#" class="btn btn-xs primary">Reenviar factura por correo</a>
<br>
UUID: <b>{{$sale->billing->uuid}}</b><br>
PDF: <a href="{{$sale->billing->pdf}}" target="blank">{{$sale->billing->pdf}}</a><br>
XML: <a href="{{$sale->billing->xml}}" target="blank">{{$sale->billing->xml}}</a><br>
@endif
@if($sale->billing->status == 2)
Factura Cancelada
@endif
<br>Dirección: <br>
Calle {{$sale->billing->calle}} numero {{$sale->billing->numero}}, Col. {{$sale->billing->colonia}} Calle {{$sale->billing->calle}} numero {{$sale->billing->numero}}, Col. {{$sale->billing->colonia}}
<br> <br>
{{$sale->billing->ciudad}}, {{$sale->billing->estado}}. C.P. {{$sale->billing->cp}} {{$sale->billing->ciudad}}, {{$sale->billing->estado}}. C.P. {{$sale->billing->cp}}
......
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