Docsity

Desarrollo de Sistema de Ventas con Laravel: Modelos, Rutas y Vistas - Prof. Quezada, Exámenes de Programación Web y Tecnologías

Vista previa parcial del texto

¡Descarga Desarrollo de Sistema de Ventas con Laravel: Modelos, Rutas y Vistas - Prof. Quezada y más Exámenes en PDF de Programación Web y Tecnologías solo en Docsity!

DOCUMENTO DE VENTA

LARAVEL

Crear las siguientes tablas: Tabla : Clientes Tabla: Tipo Llenar los siguientes registros en la tabla tipo: Tabla: Parametros Llenar los siguientes registros en la tabla parámetros:

Tabla: cabeceraventas Tabla: detalleventas MODELOS Modelo Tipo hasMany('App\CabeceraVenta','tipo_id','tipo_id'); } }

protected $table = 'detalleventas'; public $timestamps = false; protected $fillable = [ 'precio', 'cantidad', ]; public function ventas() { return $this->hasOne(CabeceraVenta::class,'venta_id','venta_id'); } public function productos() { return $this- >hasMany('App\Producto','producto_id','producto_id'); } } Modelo Parametro where('tipo_id', '=', $tipo_id)

  • >update([ 'numeracion' => $numeracion]); return true; }catch(Exception $ex){ return false;

Cliente hasMany('App\CabeceraVenta','cliente_id','cliente_id'); } } Producto php namespace App; use Illuminate\Database\Eloquent\Model; use DB; class Producto extends Model { protected $table = 'productos'; protected $primaryKey = 'producto_id'; public $timestamps = false;

Agregar en la plantilla los yield(‘script’)

Página para descargar librerías de calendario bootstrap-datepicker.

https://bootstrap-datepicker.readthedocs.io/en/latest/

@section('estilos')

@section('script')

https://developer.snapappointments.com/bootstrap-select/

@section('estilos')

@section('script')

Archivo de rutas web.php

Route::resource('venta', 'VentaController'); Route::get('EncontrarProducto/{producto_id}', 'VentaController@ProductoCodigo'); /* datos productos / Route::get('EncontrarProducto/{producto_id}', 'VentaController@ProductoCodig o'); / datos tipos */ Route::get('EncontrarTipo/{descripcion}', 'VentaController@PorTipo');

Programando el archive index.blade.php

@extends('layouts.plantilla') @section('contenido')

LISTADO DE VENTAS Nuevo Registro

Buscar

Creando la vista create.blade.php

@extends('layouts.plantilla') @section('estilos')

@endsection @section('contenido')

Registrar Venta

@csrf

Fecha

Tipo

@foreach($tipo as $itemtipo)

@endforeach

No Doc. :

Cliente

@foreach($cliente as $itemcliente)

@endforeach

Precio

Cantidad

Agregar al carrito

OPCIONES CODIGO DESCRIPCIÓN UNIDAD CANTIDAD P.VENTA IMPORTE

Total :

Registrar Cancelar

@endsection @section('script')

@endsection

Archivo Createdoc.js

var cont= 0 ; var total= 0 ;

$(".alert").removeClass("hidden"); $(".alert").addClass("alert-danger"); $(".alert").html("×"+ "Error! " + mensaje + "."); $('.alert').delay( 5000 ).hide( 400 ); } function agregarDetalle() { ruc=$("#ruc").val(); if (ruc=='') { mostrarMensajeError("Por favor seleccione el Cliente"); return false; } descripcion = $('#producto_id option:selected').text(); if (descripcion=='Seleccione Producto') { mostrarMensajeError("Por favor seleccione el Producto"); return false; } let cantidad=$("#cantidad").val(); let stock= $("#stock").val(); if (cantidad=='' || Number(cantidad)== 0 || cantidad==null) { mostrarMensajeError("Por favor ingrese cantidad del producto"); return false; } if (cantidad<= 0 ) { mostrarMensajeError("Por favor debe escribir cantidad del producto m ayor a 0"); return false; } if (Number(cantidad)>Number(stock)) { mostrarMensajeError("No se tiene tal cantidad de producto solo hay "

  • stock); return false; } pventa=$("#precio").val(); if (pventa=='' || pventa== 0 ) {

mostrarMensajeError("Por favor ingrese precio de venta del producto" ); return false; } cod_producto=$("#producto_id").val(); /* Buscar que codigo de producto no se repita */ var i= 0 ; var band=false; while (i'+ descripcion +''+number_format(subtotal[cont], 2 )+''; $('#detalles').append(fila);

return parseFloat( 0 ).toFixed(decimals); // si es mayor o menor que cero retorno el valor formateado como numero amount = '' + amount.toFixed(decimals); var amount_parts = amount.split('.'), regexp = /(\d+)(\d{3})/; while (regexp.test(amount_parts[ 0 ])) amount_parts[ 0 ] = amount_parts[ 0 ].replace(regexp, '$1' + ',' + '$2') ; return amount_parts.join('.'); }

Controlador

paginate($this::PAGINATION); return view('movimiento.registro ventas.index',compact('venta')); } /**

  • Show the form for creating a new resource.
  • @return \Illuminate\Http\Response / public function create() { $cliente=DB::table('clientes')->get(); $producto=DB::table('productos')->get(); $tipo=Tipo::all(); $tipou=Tipo::select('tipo_id','descripcion')- >orderBy('tipo_id','DESC')->get(); $parametros=Parametro::findOrFail($tipou[ 0 ]->tipo_id); return view('movimiento.registro ventas.create',compact('tipo','para metros','cliente','producto')); } /*
  • Store a newly created resource in storage.
  • @param \Illuminate\Http\Request $request
  • @return \Illuminate\Http\Response / public function store(Request $request) { try { DB::beginTransaction(); / Grabar Cabecera / / Obtiene codigo cliente a partir del dni */ $cliente=Cliente::where('ruc_dni','=',$request->ruc)->get(); $cliente_id=$cliente[ 0 ]->cliente_id; $venta=new CabeceraVenta(); $venta->cliente_id=$cliente_id; $venta->nrodoc=$request->get('nrodoc'); $venta->tipo_id=$request->seltipo; $arr = explode('/', $request->fecha); $nFecha = $arr[ 2 ].'-'.$arr[ 1 ].'-'.$arr[ 0 ]; $venta->fecha_venta=$nFecha; if ($request->seltipo='2') { $venta->total=$request->total; $venta->subtotal='0'; $venta->igv='0'; }