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
Pedro Rolon
js-e006
Commits
356ce7f6
Commit
356ce7f6
authored
Nov 07, 2018
by
Pedro Rolon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Se agregaron los arhivos correspondientes al ejercicio!
parents
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
229 additions
and
0 deletions
+229
-0
README.md
+3
-0
js-e006.js
+226
-0
No files found.
README.md
0 → 100644
View file @
356ce7f6
# Anotaciones
*
Como hay varios ejercicios, comenté el
**console.log()**
de todos. Para ver las salidas, hay que entrar y descomentar por cada ejercicio.
\ No newline at end of file
js-e006.js
0 → 100644
View file @
356ce7f6
console
.
log
(
"Como hay varios ejercicios, comenté el console.log() de todos."
);
console
.
log
(
"Para ver las salidas, hay que entrar y descomentar por cada ejercicio."
);
/*****************************************************************************/
/***********1. Definir un objeto factura,detalle_factura y cliente************/
/*****************************************************************************/
var
clienteObjeto
=
{
id_cliente
:
1
,
nombre
:
"Pedro"
,
ruc
:
"896321-9"
,
email
:
"pedro@hotmail.com"
,
direccion
:
"Dr. Gaspar Rodriguez"
,
estado
:
"activo"
};
var
facturaObjeto
=
{
id_factura
:
1
,
fecha
:
"10/11/2018"
,
cliente
:
clienteObjeto
,
monto
:
75000
,
tipo_factura
:
"contado"
,
cobrado
:
true
,
estado
:
"activo"
};
var
detalle_facturaObjeto
=
{
id_detalle
:
1
,
id_factura
:
1
,
cod_producto
:
1
,
cantidad
:
5
,
precio
:
15000
,
total_linea
:
3
};
/*****************************************************************************/
/****** 2. Crear un array con 100 elementos cargados aleatoriamente **********/
/*****************************************************************************/
function
aleatorio
(
limite_inferior
,
limite_superior
)
{
return
Math
.
round
(
Math
.
random
()
*
(
limite_superior
-
limite_inferior
)
+
limite_inferior
);
}
//Array de nombres, para elegir luego aleatoriamente
nombres
=
[
"Pedro"
,
"Pablo"
,
"Lujan"
,
"Lucas"
,
"Adriana"
,
"Eli"
,
"Christian"
,
"Rodrigo"
,
"Fatima"
,
"Analia"
,
"Bruno"
,
"Adrian"
,
"Xiomara"
,
"Genaro"
,
"Kevin"
,
"Enrique"
,
"Emanuel"
,
"Alejandro"
,
"Kattiana"
,
"Yeruti"
,
"Rocio"
,
"Lizzie"
,
"Delmis"
,
"Lorena"
,
"Mirna"
,
"Araceli"
,
"Genoveva"
,
"Maria"
,
"Alessandra"
];
//Array de ruc, para elegir aleatoriamente
direcciones
=
[
"Mcal. Lopez"
,
"Gaspar Rodriguez de Francia"
,
"Avelino Martinez"
,
"Calle'i"
,
"Cerro Cora"
,
"Pitiantuta"
,
"Gral. Aquino"
,
"Mcal. Estigarriba"
,
"Eusebio Ayala"
,
"Camboriu"
,
"14 de mayo"
,
"Pedro Juan Caballero"
,
"Rosario"
,
"Primer Presidente"
,
"Independencia Nacional"
];
estados
=
[
"activo"
,
"inactivo"
];
tiposFactura
=
[
"contado"
,
"credito"
];
cobrados
=
[
true
,
false
];
clientes
=
[];
facturas
=
[];
detallesFactura
=
[];
for
(
i
=
0
;
i
<
100
;
i
++
){
//Para tener el correo con el mismo nombre
nombreAleatorio
=
aleatorio
(
0
,
nombres
.
length
-
1
);
clientes
.
push
({
id_cliente
:
i
,
nombre
:
nombres
[
nombreAleatorio
],
ruc
:
aleatorio
(
158482
,
8941894
),
email
:
nombres
[
nombreAleatorio
]
+
"@hotmail.com"
,
direccion
:
direcciones
[
aleatorio
(
0
,
direcciones
.
length
-
1
)],
estado
:
estados
[
aleatorio
(
0
,
estados
.
length
-
1
)]
});
facturas
.
push
({
id_factura
:
i
,
fecha
:
aleatorio
(
1
,
28
)
+
"/"
+
aleatorio
(
1
,
12
)
+
"/"
+
aleatorio
(
2008
,
2018
),
cliente
:
clientes
[
aleatorio
(
0
,
clientes
.
length
-
1
)],
monto
:
aleatorio
(
10000
,
1000000
),
tipo_factura
:
tiposFactura
[
aleatorio
(
0
,
tiposFactura
.
length
-
1
)],
cobrado
:
cobrados
[
aleatorio
(
0
,
cobrados
.
length
-
1
)],
estado
:
estados
[
aleatorio
(
0
,
estados
.
length
-
1
)]
});
detallesFactura
.
push
({
id_detalle
:
i
,
id_factura
:
facturas
[
aleatorio
(
0
,
facturas
.
length
-
1
)].
id_factura
,
cod_producto
:
aleatorio
(
1
,
100
),
cantidad
:
aleatorio
(
1
,
10
),
precio
:
aleatorio
(
10000
,
1000000
),
total_linea
:
aleatorio
(
1
,
10
)
});
}
//console.log(clientes);
//console.log(facturas);
//console.log(detallesFactura);
/*****************************************************************************/
/********** 3. Mostrar todas las facturas con estado cobrado *****************/
/*****************************************************************************/
//La impresión está comentada, descomentar para ver el resultado
contador
=
0
;
for
(
i
=
0
;
i
<
100
;
i
++
){
if
(
facturas
[
i
].
cobrado
){
//console.log(facturas[i]);
//Contador para ver si cambia la cantidad;
contador
++
;
}
}
//console.log(contador);
/*****************************************************************************/
/************ 4. Calcular el total de las facturas cobradas ******************/
/*****************************************************************************/
total
=
0
;
for
(
i
=
0
;
i
<
100
;
i
++
){
if
(
facturas
[
i
].
cobrado
){
//console.log(facturas[i]);
total
+=
facturas
[
i
].
monto
;
}
}
//console.log(total);
/*******************************************************************************************/
/** 5. Dado una fecha determinada obtener todas las facturas que correspondan a esa fecha **/
/*******************************************************************************************/
total
=
0
;
inputFecha
=
"10/11/2016"
;
//Agregué uno más para probar! Porque es muy baja la probabilidad de que se produzca aleatoriamente
//La fecha que busco
facturas
.
push
({
id_factura
:
100
,
fecha
:
10
+
"/"
+
11
+
"/"
+
2016
,
cliente
:
clientes
[
aleatorio
(
0
,
clientes
.
length
-
1
)],
monto
:
aleatorio
(
10000
,
1000000
),
tipo_factura
:
tiposFactura
[
aleatorio
(
0
,
tiposFactura
.
length
-
1
)],
cobrado
:
cobrados
[
aleatorio
(
0
,
cobrados
.
length
-
1
)],
estado
:
estados
[
aleatorio
(
0
,
estados
.
length
-
1
)]
});
//Las impresiones para probar estan todas comentadas!
for
(
i
=
0
;
i
<
101
;
i
++
){
if
(
facturas
[
i
].
fecha
==
inputFecha
){
//console.log(facturas[i]);
total
+=
facturas
[
i
].
monto
;
}
}
//console.log(total);
/*******************************************************************************************/
/*** 6. Obtener todas las facturas de tipo contado o credito según seleccione el usuario ***/
/*******************************************************************************************/
input
=
"contado"
;
input
=
"credito"
;
contador
=
0
;
for
(
i
=
0
;
i
<
101
;
i
++
){
if
(
facturas
[
i
].
tipo_factura
==
input
){
//console.log(facturas[i]);
contador
++
;
}
}
//console.log(contador);
/*******************************************************************************************/
/** 7. Dado un codigo de cliente obtener todas las facturas que corresponden a ese cliente */
/*******************************************************************************************/
inputCodigo
=
5
;
contador
=
0
;
for
(
i
=
0
;
i
<
101
;
i
++
){
if
(
facturas
[
i
].
cliente
.
id_cliente
==
inputCodigo
){
//console.log(facturas[i]);
contador
++
;
}
}
//console.log(contador);
/*******************************************************************************************/
/********** 10. Mostrar la cabecera y el detalle de una factura en un objeto nuevo *********/
/*******************************************************************************************/
nuevoFactura
=
facturas
[
aleatorio
(
0
,
facturas
.
length
-
1
)];
let
nuevoDetalleFactura
;
for
(
i
=
0
;
i
<
100
;
i
++
){
if
(
detallesFactura
[
i
].
id_factura
==
nuevoFactura
.
id_factura
){
nuevoDetalleFactura
=
detallesFactura
[
i
];
break
;
}
}
//console.log(nuevoDetalleFactura);
\ 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