Devoluciones: modelo y sync
Lo agregué a la base de datos y se sincroniza con un modal que se abre desde la chismosa
This commit is contained in:
		
							parent
							
								
									aab05541b2
								
							
						
					
					
						commit
						14361a858e
					
				
					 9 changed files with 134 additions and 4 deletions
				
			
		|  | @ -97,5 +97,16 @@ class SubpedidoController extends Controller | |||
|         $subpedido->toggleAprobacion($valid['aprobacion']); | ||||
|         return new SubpedidoResource($subpedido); | ||||
|     } | ||||
|      | ||||
|     public function syncDevoluciones(Subpedido $subpedido) { | ||||
|         if ($subpedido->aprobado) return new SubpedidoResource($subpedido); | ||||
| 
 | ||||
|         $valid = request()->validate([ | ||||
|             'total' => 'required|min:0', | ||||
|             'notas' => 'required', | ||||
|         ]); | ||||
|         $subpedido->syncDevoluciones($valid['total'], $valid['notas']); | ||||
| 
 | ||||
|         return new SubpedidoResource($subpedido); | ||||
|     } | ||||
| } | ||||
|  |  | |||
|  | @ -24,7 +24,9 @@ class SubpedidoResource extends JsonResource | |||
|             'total' => number_format($this->getTotal(),0), | ||||
|             'grupo_de_compra' => $this->grupoDeCompra, | ||||
|             'productos' => $this->productos, | ||||
|             'aprobado' => (bool) $this->aprobado | ||||
|             'aprobado' => (bool) $this->aprobado, | ||||
|             'devoluciones_total' => (double) $this->devoluciones_total, | ||||
|             'devoluciones_notas' => $this->devoluciones_notas | ||||
|         ]; | ||||
|     } | ||||
| } | ||||
|  |  | |||
|  | @ -11,7 +11,7 @@ use App\Filtros\FiltroDeSubpedido; | |||
| class Subpedido extends Model | ||||
| { | ||||
|   public $timestamps = false; | ||||
|   protected $fillable = ['grupo_de_compra_id', 'aprobado', 'nombre']; | ||||
|   protected $fillable = ['grupo_de_compra_id', 'aprobado', 'nombre', 'devoluciones_total', 'devoluciones_notas']; | ||||
| 
 | ||||
|   public function productos() | ||||
|   { | ||||
|  | @ -66,7 +66,7 @@ class Subpedido extends Model | |||
| 
 | ||||
|   public function getTotal() | ||||
|   { | ||||
|     return $this->totalSinBonos() + $this->getSubtotalBDT() + $this->getSubtotalBonos(); | ||||
|     return $this->totalSinBonos() + $this->getSubtotalBDT() + $this->getSubtotalBonos() - $this->getDevoluciones(); | ||||
|   } | ||||
| 
 | ||||
|   //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.
 | ||||
|  | @ -94,5 +94,17 @@ class Subpedido extends Model | |||
|       $view = view("pdfgen.subpedido_tabla", ["subpedido" => $this]); | ||||
|       return $view->render(); | ||||
|   } | ||||
| 
 | ||||
|    | ||||
|   public function getDevoluciones() { | ||||
|     return $this->devoluciones_total; | ||||
|   } | ||||
|    | ||||
|   public function getNotasDevoluciones() { | ||||
|     return $this->devoluciones_notas; | ||||
|   } | ||||
|   public function syncDevoluciones(float $total, string $notas) { | ||||
|     $this->devoluciones_total = $total; | ||||
|     $this->devoluciones_notas = $notas; | ||||
|     $this->save(); | ||||
|   } | ||||
| } | ||||
|  |  | |||
|  | @ -18,6 +18,8 @@ class CreateSubpedidosTable extends Migration | |||
|             $table->string('nombre'); | ||||
|             $table->foreignId('grupo_de_compra_id'); | ||||
|             $table->boolean('aprobado')->default(false); | ||||
|             $table->double('devoluciones_total', 10, 2)->default(0); | ||||
|             $table->string('devoluciones_notas')->default(""); | ||||
|             $table->timestamps(); | ||||
|         }); | ||||
| 
 | ||||
|  |  | |||
							
								
								
									
										16
									
								
								resources/js/app.js
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										16
									
								
								resources/js/app.js
									
										
									
									
										vendored
									
									
								
							|  | @ -98,6 +98,22 @@ const app = new Vue({ | |||
|             this.$toast('Pedido actualizado exitosamente') | ||||
|           }); | ||||
|       }); | ||||
|       // Actualizar monto y notas de devoluciones
 | ||||
|       Event.$on('sync-devoluciones', (total, notas) => { | ||||
|         if (this.pedido.aprobado) { | ||||
|           this.$toast('No se puede modificar un pedido ya aprobado', 2000); | ||||
|           return; | ||||
|         } | ||||
|          | ||||
|         axios.post("api/subpedidos/" + this.pedido.id + "/sync_devoluciones", { | ||||
|           total: total, | ||||
|           notas: notas, | ||||
|         }).then((response) => { | ||||
|           this.pedido = response.data.data; | ||||
|           this.$toast('Pedido actualizado'); | ||||
|         }); | ||||
|       }); | ||||
| 
 | ||||
|       Event.$on('aprobacion-subpedido', (subpedidoId, aprobado) => { | ||||
|         axios.post("/api/admin/subpedidos/" + subpedidoId + "/aprobacion", { | ||||
|           aprobacion: aprobado | ||||
|  |  | |||
|  | @ -25,6 +25,19 @@ | |||
|                 <th></th> | ||||
|                 <th></th> | ||||
|             </tr> | ||||
|             <tr> | ||||
|                 <th><p :title="this.$root.pedido.devoluciones_notas">Devoluciones</p></th> | ||||
|                 <th class="has-text-right"></th> | ||||
|                 <th class="has-text-right">-{{ this.$root.pedido.devoluciones_total }}</th> | ||||
|                 <th> | ||||
|                     <button @click.capture="modificarDevoluciones()" class="button is-warning"> | ||||
|                         <span class="icon"> | ||||
|                             <i class="fas fa-edit"></i> | ||||
|                         </span> | ||||
|                     </button> | ||||
|                 </th> | ||||
|                 <th></th> | ||||
|             </tr> | ||||
|             <tr> | ||||
|                 <th>Total total</th> | ||||
|                 <th></th> | ||||
|  | @ -65,6 +78,11 @@ | |||
|                 return this.$limpiarInt(this.$root.pedido.total) | ||||
|             } | ||||
|         }, | ||||
|         methods: { | ||||
|             modificarDevoluciones: function() { | ||||
|                 Event.$emit("modificar-devoluciones"); | ||||
|             }, | ||||
|         } | ||||
|     } | ||||
| </script> | ||||
| 
 | ||||
|  |  | |||
							
								
								
									
										67
									
								
								resources/js/components/DevolucionesModal.vue
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										67
									
								
								resources/js/components/DevolucionesModal.vue
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,67 @@ | |||
| <template> | ||||
| 	<div v-bind:class="visible ? 'is-active modal' : 'modal'"> | ||||
|         <div class="modal-background"></div> | ||||
|         <div class="modal-card"> | ||||
|             <header class="modal-card-head"> | ||||
|                 <p class="modal-card-title">Devoluciones</p> | ||||
|                 <button class="delete" aria-label="close" @click.capture="cerrar"></button> | ||||
|             </header> | ||||
|             <section class="modal-card-body"> | ||||
|                 <div class="field has-addons is-centered is-thin-centered"> | ||||
|                     <p class="control"> | ||||
|                         Total: | ||||
|                         <input id="total" class="input" type="number" v-model="total" style="text-align: center"> | ||||
|                     </p> | ||||
|                 </div> | ||||
|                 <div class="field has-addons is-centered is-thin-centered"> | ||||
|                     <p class="control"> | ||||
|                         Notas: | ||||
|                         <input id="notas" class="input" type="text" v-model.text="notas"> | ||||
|                     </p> | ||||
|                 </div> | ||||
|             </section> | ||||
|             <footer class="modal-card-foot"> | ||||
|                 <button class="button is-success" @click="modificar">Aceptar</button> | ||||
|                 <button class="button" @click.capture="cerrar">Cancelar</button> | ||||
|             </footer> | ||||
|         </div> | ||||
|     </div> | ||||
| </template> | ||||
| 
 | ||||
| <script> | ||||
|     export default { | ||||
|         data() { | ||||
|             return { | ||||
|                 visible: false, | ||||
|                 total: 0, | ||||
|                 notas: "", | ||||
|             } | ||||
|         }, | ||||
|         computed: { | ||||
|             miga: function() { | ||||
|                 return { | ||||
|                     nombre: "Devoluciones", | ||||
|                     href: "#devoluciones", | ||||
|                 } | ||||
|             }, | ||||
|         }, | ||||
|         methods: { | ||||
| 		    cerrar() { | ||||
| 		        this.visible = false; | ||||
| 		        Event.$emit("migas-pop"); | ||||
| 		    }, | ||||
|             modificar() { | ||||
|                 Event.$emit('sync-devoluciones', this.total, this.notas); | ||||
|                 this.cerrar(); | ||||
|             } | ||||
|         }, | ||||
|         mounted() { | ||||
|             Event.$on('modificar-devoluciones', () => { | ||||
|                 this.visible = true; | ||||
|                 this.total = this.$root.pedido.devoluciones_total; | ||||
|                 this.notas = this.$root.pedido.devoluciones_notas; | ||||
|                 Event.$emit("migas-agregar", this.miga); | ||||
|             }); | ||||
|         }, | ||||
|     } | ||||
| </script> | ||||
|  | @ -5,4 +5,5 @@ | |||
| <categorias-container></categorias-container> | ||||
| <productos-container></productos-container> | ||||
| <producto-modal></producto-modal> | ||||
| <devoluciones-modal></devoluciones-modal> | ||||
| @endsection | ||||
|  |  | |||
|  | @ -40,6 +40,7 @@ Route::middleware('api')->group(function () { | |||
|         Route::get('{subpedido}','Api\SubpedidoController@show'); | ||||
|         Route::post('/','Api\SubpedidoController@store'); | ||||
|         Route::post('/{subpedido}/sync', 'Api\SubpedidoController@syncProductos'); | ||||
|         Route::post('/{subpedido}/sync_devoluciones', 'Api\SubpedidoController@syncDevoluciones'); | ||||
|     }); | ||||
| 
 | ||||
|     Route::prefix('admin')->group(function () { | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 Rodrigo
						Rodrigo