Compare commits
	
		
			2 commits
		
	
	
		
			be4ea4906a
			...
			a88e7ffb87
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| a88e7ffb87 | |||
| 
							 | 
						60e8725ac3 | 
					 5 changed files with 53 additions and 16 deletions
				
			
		| 
						 | 
					@ -34,23 +34,32 @@ class GrupoDeCompra extends Model
 | 
				
			||||||
      $mpdf->Output();
 | 
					      $mpdf->Output();
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  public function exportarPedidoEnCSV(){
 | 
					  //Asume que los productos están gruadados en orden de fila
 | 
				
			||||||
    $productos = Producto::pluck('id','fila')->all();
 | 
					  private function obtenerTemplateDeFilasVacias(){
 | 
				
			||||||
    $ultima_fila = end(array_keys($productos));
 | 
					    $productosFilaID = Producto::productosFilaID();
 | 
				
			||||||
    $productos_en_pedido = DB::table('pedidos_aprobados')->where('grupo_de_compra_id',$this->id)->get()->keyBy('producto_id');
 | 
					    $productosIDNombre = Producto::productosIDNombre();
 | 
				
			||||||
 | 
					    $num_fila = 1;
 | 
				
			||||||
    $records = [];
 | 
					    $template = [];
 | 
				
			||||||
    for ($i=1; $i <= $ultima_fila; $i++) {
 | 
					    foreach ($productosFilaID as $fila => $id) {
 | 
				
			||||||
      if ($productos[$i]) {
 | 
					      for ($i = $num_fila; $i < $fila; $i++) {
 | 
				
			||||||
        if ($productos_en_pedido[$productos[$i]]){
 | 
					        $template[$i] = ["", "0"];
 | 
				
			||||||
          $producto_en_pedido = $productos_en_pedido[$productos[$i]];
 | 
					 | 
				
			||||||
          $records[] = [$producto_en_pedido->producto_nombre,$producto_en_pedido->cantidad_pedida];
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
          $records[] = ['producto no pedido',0];
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
      } else {
 | 
					 | 
				
			||||||
        $records[] = ['',''];
 | 
					 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					      $template[$fila] = [$productosIDNombre[$id], "0"];
 | 
				
			||||||
 | 
					      $num_fila = $fila+1;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    return $template;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  public function exportarPedidoEnCSV(){
 | 
				
			||||||
 | 
					    $productos_en_pedido = DB::table('pedidos_aprobados')->where('grupo_de_compra_id',$this->id)->get()->keyBy('producto_id');
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    //si no hay pedidos aprobados, salir
 | 
				
			||||||
 | 
					    if ($productos_en_pedido->count() == 0) { \Log::debug("El grupo de compra ". $this->nombre . " no tiene pedidos aprobados."); return; }
 | 
				
			||||||
 | 
					    $records = $this->obtenerTemplateDeFilasVacias();
 | 
				
			||||||
 | 
					    $productos_id_fila = Producto::productosIdFila();
 | 
				
			||||||
 | 
					    foreach ($productos_en_pedido as $id => $producto_pedido){
 | 
				
			||||||
 | 
					      $fila = $productos_id_fila[$id];
 | 
				
			||||||
 | 
					      $records[$fila][1] = $producto_pedido->cantidad_pedida;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    try {
 | 
					    try {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4,6 +4,7 @@ namespace App\Http\Controllers;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use App\GrupoDeCompra;
 | 
					use App\GrupoDeCompra;
 | 
				
			||||||
use Illuminate\Http\Request;
 | 
					use Illuminate\Http\Request;
 | 
				
			||||||
 | 
					use Response;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class AdminController extends Controller
 | 
					class AdminController extends Controller
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
| 
						 | 
					@ -19,4 +20,10 @@ class AdminController extends Controller
 | 
				
			||||||
    public function exportarPlanillasAPdf(GrupoDeCompra $gdc) {
 | 
					    public function exportarPlanillasAPdf(GrupoDeCompra $gdc) {
 | 
				
			||||||
        return $gdc->exportarPlanillasAPdf();
 | 
					        return $gdc->exportarPlanillasAPdf();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function exportarPedidoACSV(GrupoDeCompra $gdc) {
 | 
				
			||||||
 | 
					        $gdc->exportarPedidoEnCSV();
 | 
				
			||||||
 | 
					        $file = resource_path('csv/exports/'.$gdc->nombre.'.csv');
 | 
				
			||||||
 | 
					        return response()->download($file);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -32,5 +32,17 @@ class Producto extends Model
 | 
				
			||||||
  {
 | 
					  {
 | 
				
			||||||
      return $request->has('paginar') && intval($request->input('paginar')) ? intval($request->input('paginar')) : self::$paginarPorDefecto;
 | 
					      return $request->has('paginar') && intval($request->input('paginar')) ? intval($request->input('paginar')) : self::$paginarPorDefecto;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  public static function productosIDFila() {
 | 
				
			||||||
 | 
					    return Producto::pluck('fila', 'id',)->all();
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  public static function productosFilaID() {
 | 
				
			||||||
 | 
					    return Producto::pluck('id', 'fila',)->all();
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  public static function productosIDNombre() {
 | 
				
			||||||
 | 
					    return Producto::pluck('nombre', 'id',)->all();
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,6 +1,14 @@
 | 
				
			||||||
<template>
 | 
					<template>
 | 
				
			||||||
    <div class="container is-max-widescreen is-max-desktop animate__animated" :class="animation" v-show="!init">
 | 
					    <div class="container is-max-widescreen is-max-desktop animate__animated" :class="animation" v-show="!init">
 | 
				
			||||||
        <div class="buttons is-right">
 | 
					        <div class="buttons is-right">
 | 
				
			||||||
 | 
					            <a class="button is-success" :href="'/admin/exportar-pedido-a-csv/'+gdc">
 | 
				
			||||||
 | 
					                <span>
 | 
				
			||||||
 | 
					                    Exportar pedido barrial
 | 
				
			||||||
 | 
					                </span>
 | 
				
			||||||
 | 
					                <span class="icon is-small">
 | 
				
			||||||
 | 
					                    <i class="fas fa-download"></i>
 | 
				
			||||||
 | 
					                </span>
 | 
				
			||||||
 | 
					            </a>
 | 
				
			||||||
            <a class="button is-info" :href="'/admin/exportar-planillas-a-pdf/'+gdc">
 | 
					            <a class="button is-info" :href="'/admin/exportar-planillas-a-pdf/'+gdc">
 | 
				
			||||||
                <span>
 | 
					                <span>
 | 
				
			||||||
                    Imprimir Planillas
 | 
					                    Imprimir Planillas
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -35,6 +35,7 @@ Route::get('/admin/obtener_sesion', function() {
 | 
				
			||||||
})->name('admin_obtener_sesion');
 | 
					})->name('admin_obtener_sesion');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Route::get('/admin/exportar-planillas-a-pdf/{gdc}', 'AdminController@exportarPlanillasAPdf');
 | 
					Route::get('/admin/exportar-planillas-a-pdf/{gdc}', 'AdminController@exportarPlanillasAPdf');
 | 
				
			||||||
 | 
					Route::get('/admin/exportar-pedido-a-csv/{gdc}', 'AdminController@exportarPedidoACSV');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Route::middleware(['auth', 'admin'])->group( function () {
 | 
					Route::middleware(['auth', 'admin'])->group( function () {
 | 
				
			||||||
    //Route::get('/admin/exportar-planillas-a-pdf/{gdc}', 'AdminController@exportarPlanillasAPdf');
 | 
					    //Route::get('/admin/exportar-planillas-a-pdf/{gdc}', 'AdminController@exportarPlanillasAPdf');
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue