Compare commits
No commits in common. "bc7b7e2f22eb92aa835c866fbb7937dccd2deeb5" and "0200160aa881f23fd7ad33d7da4576d699930a63" have entirely different histories.
bc7b7e2f22
...
0200160aa8
7 changed files with 3 additions and 168 deletions
|
@ -7,7 +7,6 @@ use Illuminate\Http\Request;
|
|||
use App\Filtros\FiltroDeSubpedido;
|
||||
use App\Subpedido;
|
||||
use App\GrupoDeCompra;
|
||||
use App\Http\Resources\SubpedidoResource;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
|
||||
|
@ -54,15 +53,4 @@ class SubpedidoController extends Controller
|
|||
]
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param \App\Subpedido $subpedido
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show(Subpedido $subpedido)
|
||||
{
|
||||
return new SubpedidoResource($subpedido);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class SubpedidoResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'nombre' => $this->nombre,
|
||||
'subtotal_productos' => $this->getSubtotalProductos(),
|
||||
'subtotal_bonos' => $this->getSubtotalBonos(),
|
||||
'bonos_de_transporte' => $this->cantidadBDT(),
|
||||
'subtotal_bonos_de_transporte' => $this->getSubtotalBDT(),
|
||||
'total' => $this->getTotal(),
|
||||
'grupo_de_compra' => $this->grupoDeCompra
|
||||
];
|
||||
}
|
||||
}
|
|
@ -15,77 +15,18 @@ class Subpedido extends Model
|
|||
|
||||
public function productos()
|
||||
{
|
||||
return $this->belongsToMany('App\Producto')->withPivot(["cantidad"]);
|
||||
return $this->belongsToMany('App\Producto','pedidos_productos')->withPivot(["cantidad"]);
|
||||
}
|
||||
|
||||
//Bonos del MPS, Sororo, etc. NO devuelve bonos de transporte
|
||||
private function bonos()
|
||||
{
|
||||
return $this->productos()->where('bono',1);
|
||||
}
|
||||
|
||||
private function productosSinBonos()
|
||||
{
|
||||
return $this->productos()->where('bono',false);
|
||||
}
|
||||
|
||||
|
||||
public function grupoDeCompra()
|
||||
{
|
||||
return $this->belongsTo('App\GrupoDeCompra');
|
||||
}
|
||||
|
||||
//Permite que se apliquen los filtros al hacer una request (por ejemplo, de búsqueda)
|
||||
//Este método permite que se apliquen los filtros al hacer una request (por ejemplo, de búsqueda)
|
||||
public function scopeFiltrar($query, FiltroDeSubpedido $filtros)
|
||||
{
|
||||
return $filtros->aplicar($query);
|
||||
}
|
||||
|
||||
//Subtotal de dinero de productos del pedido, sin bonos ni transporte
|
||||
public function getSubtotalProductos()
|
||||
{
|
||||
return $this->productosSinBonos()->sum('total');
|
||||
}
|
||||
|
||||
//Cantidad de bonos de transporte
|
||||
public function cantidadBDT()
|
||||
{
|
||||
return ceil($this->getSubtotalProductos() / 500);
|
||||
}
|
||||
|
||||
//Subtotal de dinero de bonos de transporte
|
||||
public function getSubtotalBDT()
|
||||
{
|
||||
return $this->cantidadBDT() * 15;
|
||||
}
|
||||
|
||||
//Subtotal de dinero de bonos (MPS, Sororo, etc)
|
||||
public function getSubtotalBonos()
|
||||
{
|
||||
return $this->bonos()->sum('total');
|
||||
}
|
||||
|
||||
|
||||
public function getTotal()
|
||||
{
|
||||
return $this->getSubtotalProductos() + $this->getSubtotalBDT() + $this->getSubtotalBonos();
|
||||
}
|
||||
|
||||
//Actualiza el pedido, agregando o quitando del subpedido según sea necesario. Debe ser llamado desde el controlador de subpedidos, luego de validar que los parámetros $producto y $cantidad son correctos. También calcula el subtotal por producto.
|
||||
public function syncProducto(Producto $producto, Int $cantidad) {
|
||||
if ($cantidad){
|
||||
//si la cantidad es 1 o más se agrega el producto o actualiza la cantidad
|
||||
$this->productos()->syncWithoutDetaching([
|
||||
$producto->id => [
|
||||
'cantidad' => $cantidad,
|
||||
'total' => $cantidad * $producto->precio
|
||||
]
|
||||
]);
|
||||
|
||||
} else {
|
||||
//si la cantidad es 0, se elimina el producto del subpedido
|
||||
$this->productos()->detach($producto->id);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AgregarColumnaBonoATablaDeProductos extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('productos', function (Blueprint $table) {
|
||||
$table->boolean('bono')->after('apto_celiacxs');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('productos', function (Blueprint $table) {
|
||||
$table->dropColumn('bono');
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AgregarColumnaTotalATablaDeProductoSubpedido extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('producto_subpedido', function (Blueprint $table) {
|
||||
$table->double('total',10,2)->after('cantidad')->default(0);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('producto_subpedido', function (Blueprint $table) {
|
||||
$table->dropColumn('total');
|
||||
});
|
||||
}
|
||||
}
|
|
@ -27,8 +27,7 @@ class ProductoSeeder extends Seeder
|
|||
'precio' => $registro['precio'],
|
||||
'proveedor_id' => isset($registro['proveedor']) ? Proveedor::firstOrCreate([
|
||||
'nombre' => $registro['proveedor']
|
||||
])->id : null,
|
||||
'bono' => $registro['categoria'] == 'BONOS Y FINANCIAMIENTO SORORO'
|
||||
])->id : null
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,6 @@ Route::middleware('api')->group(function () {
|
|||
|
||||
Route::prefix('subpedidos')->group(function () {
|
||||
Route::get('/','Api\SubpedidoController@index');
|
||||
Route::get('{subpedido}','Api\SubpedidoController@show');
|
||||
Route::post('/','Api\SubpedidoController@store');
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue