Commit 718fd224 by Pancholin

Merge branch 'master' of bunkrbit.com:bsabbath/onestartup-shop

parents 136b3ffb f0adc493
......@@ -94,6 +94,23 @@ SCOUT_QUEUE=true
php artisan scout:import 'Onestartup\Shop\Model\ProductShop'
```
# Facturacion
Agregar al archivo database/seeds/DatabaseSeeder.php
```
$this->call(CreateUsoCfdiCatalog::class);
$this->call(CreateUnidadesSeed::class);
$this->call(CreateClavesProductosSeed::class);
```
Correr migraciones y seeders
```
php artisan migrate --seed
```
......
......@@ -22,6 +22,15 @@ use Onestartup\Shop\Libs\Util;
use Onestartup\Shop\Requests\RequestProduct;
use Onestartup\Shop\Requests\RequestProductInfo;
use Onestartup\Shop\Payment\MP;
use PayPal\Api\Amount;
use PayPal\Api\Refund;
use PayPal\Api\Sale as SalePaypal;
use PayPal\Rest\ApiContext;
use PayPal\Auth\OAuthTokenCredential;
use PayPal\Api\Payer;
use PayPal\Api\Payment;
class AdminProductController extends Controller
{
......@@ -314,6 +323,10 @@ class AdminProductController extends Controller
$estado = "En proceso";
}
if ($sale->status == 4) {
$estado = "Cancelado/Reembolsado";
}
return view('shop::clients.orden')
->with('sale', $sale)
->with('client', $client)
......@@ -358,4 +371,86 @@ class AdminProductController extends Controller
->with('message_success', 'Información agregada correctamente');
}
/**
* Reembolsa pagos hechos con tarjeta
* @param [type] $sale_id [description]
* @return [type] [description]
*/
public function refund($sale_id)
{
//$paymentInfo = $mp->get_payment ("3799582572");
//$result = $mp->refund_payment("3799582572");
//$paymentInfo = $mp->get_payment ($sale->transaction_id);
$sale = Sale::find($sale_id);
$mp = new MP(env('AC_MERCADO_PAGO'));
$result = $mp->refund_payment($sale->transaction_id);
$old = $sale->status;
$sale->status = 4;
$sale->save();
$this->util->stock_change($sale, $old);
dd($result);
return redirect()->back()->with('message_success', 'Se realizo el reembolso correctamente');
}
public function refundPaypal($sale_id)
{
$saleLocal = Sale::find($sale_id);
$apiContext = new ApiContext(
new OAuthTokenCredential(
env('CLIENT_ID_PAYPAL'),
env('SECRET_PAYPAL')
)
);
$apiContext->setConfig(
array(
'log.LogEnabled' => true,
'log.FileName' => base_path().'/Paypal.log',
'log.LogLevel' => 'DEBUG',
'mode' => env('PAYPAL_MODE'),
)
);
$payment = Payment::get($saleLocal->transaction_id, $apiContext);
//dd($payment->transactions[0]->related_resources[0]->sale->id);
$amt = new Amount();
$amt->setTotal($saleLocal->total)
->setCurrency('MXN');
$refund = new Refund();
$refund->setAmount($amt);
$sale = new SalePaypal();
$sale->setId($payment->transactions[0]->related_resources[0]->sale->id);
try {
$refundedSale = $sale->refund($refund, $apiContext);
$old = $saleLocal->status;
$saleLocal->status = 4;
$saleLocal->save();
$this->util->stock_change($saleLocal, $old);
return redirect()->back()->with('message_success', 'Se realizo el reembolso correctamente');
//dd($refundedSale);
} catch (PayPal\Exception\PayPalConnectionException $ex) {
echo $ex->getCode();
echo $ex->getData();
die($ex);
} catch (Exception $ex) {
die($ex);
}
}
}
......@@ -15,6 +15,7 @@ use Onestartup\Shop\Model\SaleShop as Sale;
use Onestartup\Shop\Model\DetailShop as Item;
use Onestartup\Shop\Model\DiscountCoupon as Coupon;
use Onestartup\Shop\Model\Billing;
use Onestartup\Shop\Model\UsoCfdi;
use Onestartup\Shop\Payment\MP;
use Onestartup\Shop\Notifications\PaymentClient;
......@@ -988,6 +989,11 @@ public function facturacion($order_id)
$addres = $client->shipping;
$billing = new Billing();
$uso_cfdi = UsoCfdi::select(
\DB::raw("CONCAT(descripcion,' - Persona Física ',fisica, ', Persona Moral ', moral) AS resumen"),'clave_uso')
->pluck('resumen', 'clave_uso');
if ($order->billing()->count() > 0 ) {
$billing = $order->billing;;
}
......@@ -1002,6 +1008,7 @@ public function facturacion($order_id)
->with('data', $data)
->with('products', $products)
->with('total', 0)
->with('uso_cfdi', $uso_cfdi)
->with('addres', $addres);
......
......@@ -39,6 +39,9 @@ class OrderDataTable extends DataTable
if ($sale->status == 3) {
$estado = "<span class='label primary'>En proceso</span>";
}
if ($sale->status == 4) {
$estado = "<span class='label danger'>Reembolsado</span>";
}
if ($sale->client->shipping != null) {
$html = "Estado: <b>$estado</b><br>Tipo: <b>$sale->payment_type</b> <br>Transaccion:<br><b>$sale->transaction_id</b><br>Envio: <b>".$sale->client->shipping->shipping_price->name."</b>";
} else {
......
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateUsoCfdisTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('uso_cfdis', function (Blueprint $table) {
$table->increments('id');
$table->string('clave_uso');
$table->string('descripcion');
$table->string('fisica')->default('SI');
$table->string('moral');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('uso_cfdis');
}
}
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddUuidToBillingsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('billings', function (Blueprint $table) {
$table->string('uso_cfdi')->nullable();
$table->string('folio')->nullable();
$table->string('uuid', 355)->nullable();
$table->string('pdf', 355)->nullable();
$table->string('xml', 355)->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('billings', function (Blueprint $table) {
$table->dropColumn('uso_cfdi');
$table->dropColumn('folio');
$table->dropColumn('uuid');
$table->dropColumn('pdf');
$table->dropColumn('xml');
});
}
}
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateUnidadsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('unidades', function (Blueprint $table) {
$table->increments('id');
$table->string('clave');
$table->string('nombre');
$table->string('tipo');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('unidades');
}
}
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateClavesProductosTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('claves_productos', function (Blueprint $table) {
$table->increments('id');
$table->string('clave');
$table->string('descripcion', 355);
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('claves_productos');
}
}
......@@ -17,7 +17,12 @@ class Billing extends Model
'colonia',
'ciudad',
'estado',
'sale_id'
'sale_id',
'uso_cfdi',
'folio',
'uuid',
'pdf',
'xml'
];
public function sale()
......
<?php
namespace Onestartup\Shop\Model;
use Illuminate\Database\Eloquent\Model;
class ClavesProducto extends Model
{
protected $table = 'claves_productos';
protected $fillable = [
'clave',
'descripcion',
];
}
<?php
namespace Onestartup\Shop\Model;
use Illuminate\Database\Eloquent\Model;
class Unidad extends Model
{
protected $table = 'unidades';
protected $fillable = [
'clave',
'nombre',
'tipo'
];
}
<?php
namespace Onestartup\Shop\Model;
use Illuminate\Database\Eloquent\Model;
class UsoCfdi extends Model
{
protected $table = 'uso_cfdis';
protected $fillable = ['clave_uso', 'descripcion', 'fisica', 'moral'];
}
......@@ -70,6 +70,14 @@ Route::group(['middleware' => ['web', 'auth', 'is_admin']], function(){
'Onestartup\Shop\Controller\AdminProductController@stock')
->name('admin-shop-client.stock');
Route::put('admin/shop/refund/{sale_id}',
'Onestartup\Shop\Controller\AdminProductController@refund')
->name('admin-shop-client.refund');
Route::put('admin/shop/refundPaypal/{sale_id}',
'Onestartup\Shop\Controller\AdminProductController@refundPaypal')
->name('admin-shop-client.refundPaypal');
});
......
This source diff could not be displayed because it is too large. You can view the blob instead.
<?php
namespace Onestartup\Shop\Seed;
use Illuminate\Database\Seeder;
use Onestartup\Shop\Model\Unidad;
class CreateUnidadesSeed extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
if (Unidad::count() == 0) {
Unidad::create([
'clave' => 'H87',
'nombre' => 'Pieza',
'tipo' => 'Múltiplos / Fracciones / Decimales'
]);
Unidad::create([
'clave' => 'EA',
'nombre' => 'Elemento',
'tipo' => 'Unidades de venta'
]);
Unidad::create([
'clave' => 'E48',
'nombre' => 'Unidad de Servicio',
'tipo' => 'Unidades específicas de la industria (varias)'
]);
Unidad::create([
'clave' => 'ACT',
'nombre' => 'Actividad',
'tipo' => 'Unidades de venta'
]);
Unidad::create([
'clave' => 'KGM',
'nombre' => 'Kilogramo',
'tipo' => 'Mecánica'
]);
Unidad::create([
'clave' => 'E51',
'nombre' => 'Trabajo',
'tipo' => 'Unidades específicas de la industria (varias)'
]);
Unidad::create([
'clave' => 'A9',
'nombre' => 'Tarifa',
'tipo' => 'Diversos'
]);
Unidad::create(['clave'=> 'MTR', 'nombre'=>'Metro', 'tipo'=>'Tiempo y Espacio']);
Unidad::create(['clave'=> 'AB', 'nombre'=>'Paquete a granel', 'tipo'=>'Diversos']);
Unidad::create(['clave'=> 'BB', 'nombre'=>'Caja base', 'tipo'=>'Unidades específicas de la industria (varias)']);
Unidad::create(['clave'=> 'KT', 'nombre'=>'Kit', 'tipo'=>'Unidades de venta']);
Unidad::create(['clave'=> 'SET', 'nombre'=>'Conjunto', 'tipo'=>'Unidades de venta']);
Unidad::create(['clave'=> 'LTR', 'nombre'=>'Litro', 'tipo'=>'Tiempo y Espacio']);
Unidad::create(['clave'=> 'XBX', 'nombre'=>'Caja', 'tipo'=>'Unidades de empaque']);
Unidad::create(['clave'=> 'MON', 'nombre'=>'Mes', 'tipo'=>'Tiempo y Espacio']);
Unidad::create(['clave'=> 'HUR', 'nombre'=>'Hora', 'tipo'=>'Tiempo y Espacio']);
Unidad::create(['clave'=> 'MTK', 'nombre'=>'Metro cuadrado', 'tipo'=>'Tiempo y Espacio']);
Unidad::create(['clave'=> '11', 'nombre'=>'Equipos', 'tipo'=>'Diversos']);
Unidad::create(['clave'=> 'MGM', 'nombre'=>'Miligramo', 'tipo'=>'Mecánica']);
Unidad::create(['clave'=> 'XPK', 'nombre'=>'Paquete', 'tipo'=>'Unidades de empaque']);
Unidad::create(['clave'=> 'XKI', 'nombre'=>'Kit (Conjunto de piezas)', 'tipo'=>'Unidades de empaque']);
Unidad::create(['clave'=> 'AS', 'nombre'=>'Variedad', 'tipo'=>'Diversos']);
Unidad::create(['clave'=> 'GRM', 'nombre'=>'Gramo', 'tipo'=>'Mecánica']);
Unidad::create(['clave'=> 'PR', 'nombre'=>'Par', 'tipo'=>'Números enteros / Números / Ratios']);
Unidad::create(['clave'=> 'DPC', 'nombre'=>'Docenas de piezas', 'tipo'=>'Unidades de venta']);
Unidad::create(['clave'=> 'xun', 'nombre'=>'Unidad', 'tipo'=>'Unidades de empaque']);
Unidad::create(['clave'=> 'DAY', 'nombre'=>'Día', 'tipo'=>'Tiempo y Espacio']);
Unidad::create(['clave'=> 'XLT', 'nombre'=>'Lote', 'tipo'=>'Unidades de empaque']);
Unidad::create(['clave'=> '10', 'nombre'=>'Grupos', 'tipo'=>'Diversos']);
Unidad::create(['clave'=> 'MLT', 'nombre'=>'Mililitro', 'tipo'=>'Tiempo y Espacio']);
Unidad::create(['clave'=> 'E54', 'nombre'=>'Viaje', 'tipo'=>'Unidades específicas de la industria (varias)']);
}
}
}
<?php
namespace Onestartup\Shop\Seed;
use Illuminate\Database\Seeder;
use Onestartup\Shop\Model\UsoCfdi;
class CreateUsoCfdiCatalog extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
if (UsoCfdi::count() == 0) {
UsoCfdi::create([
'clave_uso' => 'G01',
'descripcion' => 'Adquisición de mercancias',
'fisica' => 'SI',
'moral' => 'SI',
]);
UsoCfdi::create([
'clave_uso' => 'G02',
'descripcion' => 'Devoluciones, descuentos o bonificaciones',
'fisica' => 'SI',
'moral' => 'SI',
]);
UsoCfdi::create([
'clave_uso' => 'G03',
'descripcion' => 'Gastos en general',
'fisica' => 'SI',
'moral' => 'SI',
]);
UsoCfdi::create([
'clave_uso' => 'I01',
'descripcion' => 'Construcciones',
'fisica' => 'SI',
'moral' => 'SI',
]);
UsoCfdi::create([
'clave_uso' => 'I02',
'descripcion' => 'Mobilario y equipo de oficina por inversiones',
'fisica' => 'SI',
'moral' => 'SI',
]);
UsoCfdi::create([
'clave_uso' => 'I03',
'descripcion' => 'Equipo de transporte',
'fisica' => 'SI',
'moral' => 'SI',
]);
UsoCfdi::create([
'clave_uso' => 'I04',
'descripcion' => 'Equipo de computo y accesorios',
'fisica' => 'SI',
'moral' => 'SI',
]);
UsoCfdi::create([
'clave_uso' => 'I05',
'descripcion' => 'Dados, troqueles, moldes, matrices y herramental',
'fisica' => 'SI',
'moral' => 'SI',
]);
UsoCfdi::create([
'clave_uso' => 'I06',
'descripcion' => 'Comunicaciones telefónicas',
'fisica' => 'SI',
'moral' => 'SI',
]);
UsoCfdi::create([
'clave_uso' => 'I07',
'descripcion' => 'Comunicaciones satelitales',
'fisica' => 'SI',
'moral' => 'SI',
]);
UsoCfdi::create([
'clave_uso' => 'I08',
'descripcion' => 'Otra maquinaria y equipo',
'fisica' => 'SI',
'moral' => 'SI',
]);
UsoCfdi::create([
'clave_uso' => 'D01',
'descripcion' => 'Honorarios médicos, dentales y gastos hospitalarios.',
'fisica' => 'SI',
'moral' => 'NO',
]);
UsoCfdi::create([
'clave_uso' => 'D02',
'descripcion' => 'Gastos médicos por incapacidad o discapacidad.',
'fisica' => 'SI',
'moral' => 'NO',
]);
UsoCfdi::create([
'clave_uso' => 'D03',
'descripcion' => 'Gastos funerales.',
'fisica' => 'SI',
'moral' => 'NO',
]);
UsoCfdi::create([
'clave_uso' => 'D04',
'descripcion' => 'Donativos.',
'fisica' => 'SI',
'moral' => 'NO',
]);
UsoCfdi::create([
'clave_uso' => 'D05',
'descripcion' => 'Intereses reales efectivamente pagados por créditos hipotecarios (casa habitación).',
'fisica' => 'SI',
'moral' => 'NO',
]);
UsoCfdi::create([
'clave_uso' => 'D06',
'descripcion' => 'Aportaciones voluntarias al SAR.',
'fisica' => 'SI',
'moral' => 'NO',
]);
UsoCfdi::create([
'clave_uso' => 'D07',
'descripcion' => 'Primas por seguros de gastos médicos.',
'fisica' => 'SI',
'moral' => 'NO',
]);
UsoCfdi::create([
'clave_uso' => 'D08',
'descripcion' => 'Gastos de transportación escolar obligatoria.',
'fisica' => 'SI',
'moral' => 'NO',
]);
UsoCfdi::create([
'clave_uso' => 'D09',
'descripcion' => 'Depósitos en cuentas para el ahorro, primas que tengan como base planes de pensiones.',
'fisica' => 'SI',
'moral' => 'NO',
]);
UsoCfdi::create([
'clave_uso' => 'D010',
'descripcion' => 'Pagos por servicios educativos (colegiaturas).',
'fisica' => 'SI',
'moral' => 'NO',
]);
UsoCfdi::create([
'clave_uso' => 'P01',
'descripcion' => 'Por definir',
'fisica' => 'SI',
'moral' => 'SI',
]);
}
}
}
@extends('crm-admin::main-layout')
@section('breadcrumb')
<li class="breadcrumb-item">
<a href="{{route('home')}}">Home</a>
</li>
<li class="breadcrumb-item">
<a href="{{route('admin-shop-client.orders')}}">Tienda</a>
</li>
<li class="breadcrumb-item active">
Detalle orden #{{$sale->id}}
</li>
@endsection
@section('content')
@php
setlocale(LC_MONETARY, 'en_US');
......@@ -170,6 +182,23 @@ setlocale(LC_MONETARY, 'en_US');
</tfoot>
</tbody>
</table>
@if($sale->status == 2)
@if($sale->payment_type == 'Tarjeta')
{!! Form::model($sale,['route'=> ['admin-shop-client.refund', $sale->id],"method"=>"PUT", "onsubmit"=>"if(!confirm('¿Estas seguro de devolver el dinero?')){return false;}"]) !!}
{!! Form::submit('Reembolsar efectivo a tarjeta', ['class'=>'btn btn-warning']) !!}
{!! Form::close() !!}
@endif
@if($sale->payment_type == 'Pay Pal')
{!! Form::model($sale,['route'=> ['admin-shop-client.refundPaypal', $sale->id],"method"=>"PUT", "onsubmit"=>"if(!confirm('¿Estas seguro de devolver el dinero?')){return false;}"]) !!}
{!! Form::submit('Reembolsar efectivo a cuenta de paypal', ['class'=>'btn btn-warning']) !!}
{!! Form::close() !!}
@endif
@endif
</div>
</div>
</div>
......@@ -277,7 +306,7 @@ setlocale(LC_MONETARY, 'en_US');
<div class="form-group">
{!! Form::label('status', 'Estatus del envio', ['class'=>'form-control-label']) !!}
{!! Form::select('status', [0=>'Cancelado',1=>'Pendiente',2=>'Pagado',3=>'En proceso'], null, ['class' => 'form-control select2', 'required'=>'required']) !!}
{!! Form::select('status', [0=>'Cancelado',1=>'Pendiente',2=>'Pagado',3=>'En proceso',4=>'Cancelado/Reembolsado'], null, ['class' => 'form-control select2', 'required'=>'required']) !!}
</div>
<br>
{!! Form::submit('Actualizar', ['class'=>'btn btn-danger btn-block']) !!}
......
......@@ -40,3 +40,8 @@
{!! Form::label('cp', 'Codigo postal', ['class'=>'form-control']) !!}
{!! Form::text('cp', null, ['class'=>'form-control','required'=>'required']) !!}
</div>
<div class="form-group">
{!! Form::label('uso_cfdi', 'Uso del CFDI', ['class'=>'form-control']) !!}
{!! Form::select('uso_cfdi', $uso_cfdi, null, ['class'=>'form-control','required'=>'required']) !!}
</div>
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