Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
js-e006
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Hugo Villagra
js-e006
Commits
0a8f30f6
You need to sign in or sign up before continuing.
Commit
0a8f30f6
authored
Nov 13, 2018
by
roshka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1.0
parents
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
206 additions
and
0 deletions
+206
-0
Ejercicio.html
+13
-0
Ejercicio.js
+186
-0
Readme.md
+7
-0
No files found.
Ejercicio.html
0 → 100644
View file @
0a8f30f6
<!DOCTYPE html>
<html
lang=
"es"
>
<head>
<title></title>
<meta
charset=
"UTF-8"
>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1"
>
</head>
<body>
<script
src=
"Ejercicio.js"
></script>
</body>
</html>
\ No newline at end of file
Ejercicio.js
0 → 100644
View file @
0a8f30f6
let
meses
=
[
'01'
,
'02'
,
'03'
,
'04'
,
'05'
,
'06'
,
'07'
,
'08'
,
'09'
,
'10'
,
'11'
,
'12'
];
let
fechas
=
[
"22/01/2018"
,
"30/02/2018"
,
"02/01/2018"
,
"20/12/2018"
,
"19/03/2018"
,
"18/03/2018"
,
"30/04/2018"
,
"04/04/2018"
,
"05/05/2017"
,
"20/09/2018"
];
let
tipos_facturas
=
[
'contado'
,
'credito'
];
let
correos
=
[
'outlook'
,
'gmail'
,
'yahoo'
];
let
estado_factura
=
[
'activo'
,
'anulado'
];
let
estados_cliente
=
[
'activo'
,
'inactivo'
];
let
direcciones
=
[
'Melo de Portugal'
,
'Cacique Lambare'
,
'Manduvira'
,
'Chile'
,
'14 de mayo'
,
'Juan de Zalazar'
,
'Teniente colman'
,
'Gobernador Irala'
,
'Eusebio Ayala'
,
'Mariscal Lopez'
,
"Juan de Garai"
,
"Avenida 5ta"
,
'Colon'
,
'España'
,
'Antequera'
,
'Peru'
,
'Perirossi'
,
'Rca Argentina'
];
let
nombres
=
[
'Carlos'
,
'Mario'
,
'Luis'
,
'Hugo'
,
'Monica'
,
'Carolina'
,
'Pedro'
,
'Pablo'
,
'Cristina'
,
'Melisa'
,
'Leonardo'
,
'Miguel'
,
'Lucia'
];
let
opcion_cobrado
=
[
true
,
false
];
let
facturas
=
[];
let
clientes
=
[];
let
detallesFactura
=
[];
//Vamos a cargar los clientes
for
(
let
i
=
0
;
i
<
100
;
i
++
){
//Creamos los datos del cliente
let
cliente
=
new
Object
();
cliente
.
id_cliente
=
i
+
1
;
cliente
.
nombre
=
nombres
[
parseInt
(
13
*
Math
.
random
())];
cliente
.
ruc
=
parseInt
((
1
+
3
*
Math
.
random
()))
+
""
+
parseInt
((
9
*
Math
.
random
()))
+
""
+
parseInt
((
9
*
Math
.
random
()))
+
""
+
parseInt
((
9
*
Math
.
random
()))
+
""
+
parseInt
((
9
*
Math
.
random
()))
+
""
+
parseInt
((
9
*
Math
.
random
()))
+
""
+
parseInt
((
9
*
Math
.
random
()))
+
"-"
+
parseInt
((
9
*
Math
.
random
()));
cliente
.
email
=
cliente
.
nombre
+
"@"
+
correos
[
parseInt
(
3
*
Math
.
random
())]
+
".com"
;
cliente
.
direccion
=
direcciones
[
parseInt
(
direcciones
.
length
*
Math
.
random
())]
+
"nro "
+
parseInt
(
2000
*
Math
.
random
());
cliente
.
estado
=
estados_cliente
[
parseInt
(
2
*
Math
.
random
())];
cliente
.
aTexto
=
function
(){
return
"Id cliente: "
+
cliente
.
id_cliente
+
"
\
n"
+
"Nombre: "
+
cliente
.
nombre
+
"
\
n"
+
"RUC: "
+
cliente
.
ruc
+
"
\
n"
+
"Email: "
+
cliente
.
email
+
"
\
n"
+
"Direccion: "
+
cliente
.
direccion
+
"
\
n"
+
"Estado: "
+
cliente
.
estado
+
"
\
n"
};
clientes
.
push
(
cliente
);
};
//vamos a cargar las facturas
for
(
let
i
=
0
;
i
<
100
;
i
++
){
//Cargamos los datos de la factura del cliente
let
factura
=
new
Object
();
factura
.
id_factura
=
i
+
1
;
factura
.
fecha
=
fechas
[
parseInt
(
fechas
.
length
*
Math
.
random
())];
factura
.
cliente
=
i
+
1
;
factura
.
monto
=
parseInt
(
5000000
*
Math
.
random
());
factura
.
tipo_factura
=
tipos_facturas
[
parseInt
(
2
*
Math
.
random
())];
factura
.
cobrado
=
opcion_cobrado
[
parseInt
(
2
*
Math
.
random
())]
factura
.
estado
=
estado_factura
[
parseInt
(
2
*
Math
.
random
())];
factura
.
aTexto
=
function
(){
return
"Factura: "
+
factura
.
id_factura
+
"
\
n"
+
"Fecha de factura: "
+
factura
.
fecha
+
"
\
n"
+
"Cliente: "
+
factura
.
cliente
+
"
\
n"
+
"Monto: "
+
factura
.
monto
+
"
\
n"
+
"Tipo de factura: "
+
factura
.
tipo_factura
+
"
\
n"
+
"Cobrado: "
+
factura
.
cobrado
+
"
\
n"
+
"Estado: "
+
factura
.
estado
+
"
\
n"
};
//Cargamos la factura en el array
facturas
.
push
(
factura
);
}
//vamos a cargar los detalles de facturas
for
(
let
i
=
0
;
i
<
100
;
i
++
){
let
detalle_factura
=
new
Object
();
detalle_factura
.
id_detalle
=
i
+
1
;
detalle_factura
.
id_factura
=
i
+
1
;
detalle_factura
.
cod_producto
=
parseInt
(
500000000
*
Math
.
random
());
detalle_factura
.
cantidad
=
parseInt
(
1
+
20
*
Math
.
random
());
detalle_factura
.
precio
=
parseInt
(
500000
*
Math
.
random
());
detalle_factura
.
total_linea
=
parseInt
(
1
+
20
*
Math
.
random
());
detalle_factura
.
aTexto
=
function
(){
return
"Id detalle: "
+
detalle_factura
.
id_detalle
+
"
\
n"
+
"Id Factura: "
+
detalle_factura
.
id_factura
+
"
\
n"
+
"Codigo producto; "
+
detalle_factura
.
cod_producto
+
"
\
n"
+
"Cantidad: "
+
detalle_factura
.
cantidad
+
"
\
n"
+
"Precio: "
+
detalle_factura
.
precio
+
"
\
n"
+
"Total Linea: "
+
detalle_factura
.
total_linea
+
"
\
n"
};
detallesFactura
.
push
(
detalle_factura
);
}
//Mostrar todas las facturas con estado cobrado
console
.
log
(
"Los cobrados son: "
);
for
(
let
i
=
0
;
i
<
facturas
.
length
;
i
++
){
if
(
facturas
[
i
].
cobrado
){
console
.
log
(
facturas
[
i
].
aTexto
());
}
}
//Calcular el total de las facturas cobradas
let
total
=
0
;
for
(
let
i
=
0
;
i
<
facturas
.
length
;
i
++
){
if
(
facturas
[
i
].
cobrado
){
total
=
total
+
facturas
[
i
].
monto
;
}
}
console
.
log
(
"El total del mondo facturas cobradas son: "
+
total
);
//Dado una fecha determinada obtener todas las facturas que correspondan a esa fecha
let
esEncontrado
=
false
;
while
(
!
esEncontrado
){
let
fecha
=
prompt
(
"Ingrese la fecha de la factura a buscar (formato dd/mm/aaaa)"
);
console
.
log
(
"Las fechas son:"
)
for
(
let
i
=
0
;
i
<
facturas
.
length
;
i
++
){
if
(
fecha
==
facturas
[
i
].
fecha
){
console
.
log
(
facturas
[
i
].
aTexto
());
esEncontrado
=
true
;
}
}
if
(
esEncontrado
==
false
){
alert
(
"No existe al menos una factura que contenga la fecha"
);
}
}
//Obtener todas las facturas de tipo contado o credito segun seleccione el usuario
let
opcion
=
prompt
(
"Ingrese el numero de una de la opciones:
\
n"
+
"1-Contado
\
n"
+
"2-Credito"
);
console
.
log
(
"Las facturas son (de acuerdo a tipo de factura): "
);
if
(
opcion
==
1
){
for
(
let
i
=
0
;
i
<
facturas
.
length
;
i
++
){
if
(
facturas
[
i
].
tipo_factura
==
"contado"
){
console
.
log
(
facturas
[
i
].
aTexto
());
}
}
}
else
if
(
opcion
==
2
){
for
(
let
i
=
0
;
i
<
facturas
.
length
;
i
++
){
if
(
facturas
[
i
].
tipo_factura
==
"credito"
){
console
.
log
(
facturas
[
i
].
aTexto
());
}
}
}
//Dado un codigo de cliente obtener todas las facturas que corresponden a ese cliente
let
encontrado
=
false
;
while
(
!
encontrado
){
let
seleccion
=
prompt
(
"Ingrese la id del cliente"
);
console
.
log
(
"Las facturas por id cliente son: "
);
for
(
let
i
=
0
;
i
<
facturas
.
length
;
i
++
){
if
(
seleccion
==
facturas
[
i
].
cliente
){
console
.
log
(
facturas
[
i
].
aTexto
());
encontrado
=
true
;
}
}
if
(
!
encontrado
){
alert
(
"No existe al menos una factura cargada con el cliente"
);
}
}
//Mostrar la cabecera y el detalle de una factura en un objeto nuevo
let
correcto
=
false
;
while
(
!
correcto
){
let
seleccion
=
prompt
(
"Ingrese el numero de factura"
);
if
(
seleccion
>=
0
&&
seleccion
<
facturas
.
length
){
console
.
log
(
"La factura: "
);
console
.
log
(
facturas
[
seleccion
].
aTexto
());
console
.
log
(
"Sus detalles: "
);
encontrado
=
false
;
for
(
let
i
=
0
;
i
<
detallesFactura
.
length
;
i
++
){
if
(
facturas
[
seleccion
].
id_factura
==
detallesFactura
[
i
].
id_factura
){
console
.
log
(
detallesFactura
[
i
].
aTexto
());
encontrado
=
true
;
}
}
if
(
!
encontrado
){
alert
(
"No se cargo al menos un detalle de la factura"
);
}
else
{
correcto
=
true
;
}
}
}
Readme.md
0 → 100644
View file @
0a8f30f6
## Indicaciones
-
Los resultados del ejercicio están en un único archivo .js
-
Los resultados se van ejecutando se acuerdo al orden del ejercicio correspondiente
-
Las entradas se realizan en un prompt, y la salida aparecen en la consola.
-
Para ejecutar el programa, abrir el archivo Ejercicio.html
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment