program eps;

uses crt,dos;

//Esta constante va a ser la cantidad de clientes en la BD
Const
	N = 5;

type
	t_fecha = record
		dia:		string;
		mes:		string;
		anio:		string;
	end;

	t_r_cliente = record
		codigo:		integer;
		nombre:		string[100];
		direccion:	string[100];
		deuda:		LongInt;
		fecha:		t_fecha;
		lectura: 	integer;
		lectura_ant:integer;
		sw:			0..1;
	end;
	
	t_v_cliente = array[1..N] of t_r_cliente;
	
	t_a_cliente = file of t_v_cliente;
	
	t_r_pago = record
		codigo:		integer;
		fecha:		t_fecha;
		cantidad:	integer;
		sw:			0..1;
	end;
	
	t_v_pago = array[1..N] of t_r_pago;
	
	t_a_pago = file of t_v_pago;
	
	t_archivotexto = text;
	t_vCadena = array[1..N] of string;
	

var
	a_cliente:	t_a_cliente;
	v_cliente:	t_v_cliente;
	
	a_pago:		t_a_pago;
	v_pago:		t_v_pago;
	
	contrata: 	t_archivotexto;
	vCadena:	t_vCadena;
	
	a_factura:	t_archivotexto;
	
	o:		char;
	
	sz:			byte;


procedure marco;
var
	i: integer;
begin

//For de n+2 a N-2 (el tamaño de la pantalla N es 80x24)
	for i:= 3 to 78 do
	begin
		gotoxy(i,2); write(#205);
        gotoxy(i,24); write(#205);
        gotoxy(i,4); write(#205);
    end;
    for i:= 3 to 23 do
    begin
		gotoxy(2,i); write(#186);
        gotoxy(79,i); write(#186);
    end;
    
    gotoxy(2,2); write(#201);
    gotoxy(79,2); write(#187);
    gotoxy(2,24); write(#200);
    gotoxy(79,24); write(#188);
    gotoxy(2,22); write(#204);
    gotoxy(79,22); write(#185);

end;  //Marco


function validar(entrada:string):boolean;
Var
     e_aux, _err : Integer;
begin
	validar := false;
		
	Val(entrada, e_aux, _err) ;
    if _err = 0 then 
		validar := true;
end;

procedure abrir(Var a_cliente: t_a_cliente;
				 var a_factura: t_archivotexto);
begin

	assign(a_cliente, 'clientes.eps');
	assign(a_factura,'factura.txt');
	assign(a_pago,'pagos.eps');
{$i-}
	reset(a_cliente);
{$i+}
	if IOResult <> 0 then
		rewrite(a_cliente);
		
{$i-}
	reset(a_factura);
{$i+}
	if IOResult <> 0 then
		rewrite(a_factura);
	
	close(a_factura);
	
{$i-}
	reset(a_pago);
{$i+}

	if IOResult <> 0 then
		rewrite(a_pago);
			
end;

procedure escribir(Var a_cliente: t_a_cliente;
					var v_cliente: t_v_cliente);
begin
    // assign(a_cliente,'clientes.eps');
     rewrite(a_cliente);
     write(a_cliente,v_cliente);
     close(a_cliente);
end;

procedure escribir_pago(var a_pago: t_a_pago;
						 var v_pago: t_v_pago);
begin
	rewrite(a_pago);
	write(a_pago,v_pago);
	close(a_pago);
	
end;
						 
						 
procedure leer(Var a_cliente: t_a_cliente; Var v_cliente: t_v_cliente);

begin
	reset(a_cliente);
	seek(a_cliente,0);
	while not(eof(a_cliente)) do
		read(a_cliente,v_cliente);
    close(a_cliente);

end;

procedure leer_pagos(var a_pago: t_a_pago; var V_pago: t_v_pago);
begin
	reset(a_pago);
	seek(a_pago,0);
	while not(eof(a_pago)) do
		read(a_pago,v_pago);
	close(a_pago);
end;
					  

procedure agregar_clientes(var v_cliente: t_v_cliente);
var
	i: integer;		
	str_fecha: string[20];
	continuar: char;
	cargado: boolean;
	str_aux: string;
	
begin

	cargado := false;

	repeat
	begin
		i:=0;
		cargado := false;
		while not (cargado) and (i<=N) do
		//for i:=1 to N do
		begin
			inc(i);
			if (v_cliente[i].sw = 0) then
			begin
				with v_cliente[i] do
				begin
					clrscr;
					marco;
					gotoxy(25,3); writeln('-----INGRESO DE DATOS CLIENTE------');
					
					repeat
						gotoxy(20,6); write('Ingrese el codigo: ');
						readln(str_aux);
					until validar(str_aux);
					val(str_aux,codigo);
					
					gotoxy(20,7); write('Ingrese el nombre: ');
					readln(nombre);
					
					gotoxy(20,8); write('Ingrese la direccion: ');
					readln(direccion);
					
					repeat
						gotoxy(20,9); write('Ingrese la deuda actual: ');
						readln(str_aux);
					until validar(str_aux);
					val(str_aux,deuda);
					
					repeat
						gotoxy(20,10); write('Ultima fecha de pago [DD/MM/AAAA]: ');
						readln(str_fecha);
					until length(str_fecha) = 10;
					
					repeat
						gotoxy(20,11); write('Ingrese lectura del medidor: '); 
						readln(str_aux);
					until validar(str_aux);
					val(str_aux,lectura);
					
					//"Activa" el registro
					sw := 1;
					
					//Separa la fecha			
					fecha.dia := str_fecha[1] + str_fecha[2];
					fecha.mes := str_fecha[4] + str_fecha[5];
					fecha.anio := str_fecha[7] + str_fecha[8]+ str_fecha[9] + str_fecha[10]
				end;
			
				//v_cliente[i] := r_cliente;	
				cargado := true;
			end;
							
			
		end;
		
		
		gotoxy(25,15); write('Desea cargar otro registro? [S/N]: ');
		readln(continuar);
	end;		
	until (upcase(continuar) = 'N');
	
	escribir(a_cliente,v_cliente);
	
end; //Cargar

//Ordena el vector usando burbuja por CODIGO DE CLIENTE
procedure ordenar(var v_cliente:t_v_cliente);
var
	i,j: integer;
	aux : t_r_cliente;
	
begin
	for i:=1 to n-1 do
		for j:=1 to n-i do
			if ((v_cliente[j].codigo > v_cliente[j+1].codigo) and
			((v_cliente[j].sw = 1) and (v_cliente[j+1].sw = 1))) then
			
			begin
				aux := v_cliente[j];
				v_cliente[j] := v_cliente[j+1];
				v_cliente[j+1] := aux;
			end;
end;

//Busca el codigo pasado y devuelve la posicion en el vector, 
//sino lo encuenta, entonces regresa 0

function buscar(v_cliente:t_v_cliente; codigo: integer):integer;
var
	i : integer;
	r_aux: t_r_cliente;
begin

	buscar := 0;
	
	for i:=1 to N do
	begin
		r_aux := v_cliente[i];
		if codigo = r_aux.codigo then
			buscar := i;
	end;
		
end;	

//Registra y/o modifica pagos de los clientes
procedure registro_pagos(var a_pago:t_a_pago;
						  var v_pago: t_v_pago;
						  var v_cliente: t_v_cliente);
var
	Anyo, Mes_x, Dia_x, sem:word;
	i,j, opcion_mod, int_aux: integer;
	str_aux,continuar: string;
	cargado: boolean;
begin

	GetDate(anyo,mes_x,dia_x, sem);


	repeat
		clrscr;
		marco;
		gotoxy(15,3); writeln('SISTEMA DE REGISTRO Y MODIFICACION DE PAGO DE CLIENTES');
		gotoxy(25,5); Writeln('1.- Registrar Pago');
		gotoxy(25,6); Writeln('2.- Listar Pagos Realizados');
		repeat
		begin
			gotoxy(25,10); write('Ingrese opcion: ');
			readln(str_aux);
		end;
		until validar(str_aux);
		
		val(str_aux,opcion_mod);

		
	until (opcion_mod = 1) or (opcion_mod = 2) or (opcion_mod = 3);
	
	if opcion_mod = 1 then
	begin
		repeat
		begin
			i:=0;
			cargado := false;
			while not (cargado) and (i<=N) do
			//for i:=1 to N do
			begin
				inc(i);
				if (v_pago[i].sw = 0) then
				begin
					with v_pago[i] do
					begin
						clrscr;
						marco;
						gotoxy(25,3);
						writeln('----- REGISTRO DE PAGOS DE CLIENTE -----');
						
						repeat
							gotoxy(25,6); write('Ingrese el codigo del cliente: ');
							readln(str_aux);
						until validar(str_aux);
						val(str_aux,codigo);
						
						int_aux := buscar(v_cliente,codigo);
						
						//Si el codigo no existe, da error y se sale inmediatamente!
						if int_aux = 0 then
						begin
							gotoxy(25,12); writeln('Codigo no existente, intente de nuevo...');
							gotoxy(25,14); writeln('Presione una tecla para continuar...');
							readkey;
							exit;
						end;
						
											
						repeat
							gotoxy(25,9); write('Ingrese la cantidad a pagar: ');
							readln(str_aux);
						until validar(str_aux);
						val(str_aux,cantidad);
						
						//"Activa" el registro
						sw := 1;
						
						//Separa la fecha y la guarda en vector de clientes
						str(Dia_x,str_aux);
							fecha.dia := str_aux;
							v_cliente[i].fecha.dia := str_aux;
						str(Mes_x,str_aux);
							fecha.mes := str_aux;
							v_cliente[i].fecha.mes := str_aux;
						str(anyo,str_aux);
							fecha.anio := str_aux;
							v_cliente[i].fecha.anio := str_aux;
							
						//Modifica la deuda en el vector de clientes:
						v_cliente[i].deuda := v_cliente[i].deuda - cantidad;
						escribir(a_cliente,v_cliente);
					end;
				
					cargado := true;
					
				end;
								
				
			end;
			
			gotoxy(25,15); write('Desea registrar otro pago? [S/N]: ');
			readln(continuar);
		end;		
		until (upcase(continuar) = 'N');
	end;
	
	if (opcion_mod = 2) then
	begin
		clrscr;
				
		j:=5;
		
		for i:=1 to N do
		begin

		if (v_pago[i].sw = 1) then
			with v_pago[i] do
			begin
				int_aux := buscar(v_cliente,codigo);
				gotoxy(4,j); write(codigo);
				gotoxy(10,j); write(v_cliente[int_aux].nombre);
				gotoxy(26,j); write(cantidad, ' Bs.F');
				gotoxy(47,j); write(v_cliente[int_aux].deuda,' Bs.F');
				gotoxy(60,j); write(fecha.dia + '/' + fecha.mes + '/' + fecha.anio);
				gotoxy(72,j); write(v_cliente[int_aux].lectura,'/',v_cliente[int_aux].lectura_ant);
				inc(j);
			end;
		end;
		textbackground(black);
		//marco;
		
		gotoxy(4,3); write('Cod');
		
		for i:=3 to 24 do begin
			gotoxy(8,i); write(#186);
		end;
		
		gotoxy(13,3); write('Nombre');
		
		for i:=3 to 24 do begin
			gotoxy(24,i); write(#186);
		end;
		
		gotoxy(28,3); write('Cantidad Pagada');
		
		for i:=3 to 24 do begin
			gotoxy(45,i); write(#186);
		end;
		
		gotoxy(50,3); write('Deuda');
		
		for i:=3 to 24 do begin
			gotoxy(58,i); write(#186);
		end;
		
		gotoxy(61,3); write('Ult.Pago');
		for i:=3 to 24 do begin
			gotoxy(70,i); write(#186);
		end;
		gotoxy(72,3); write('Lectura');
		gotoxy(66,3);
		marco;
			
		readkey;
	
	end;
	
	//Escribe los cambios al archivo!
	rewrite(a_pago);
	write(a_pago,v_pago);
	close(a_pago);
			
end;


procedure imprimir(v_cliente: t_v_cliente);
var 
	i,j: integer;
	
begin

	leer(a_cliente,v_cliente);
	ordenar(v_cliente);
	clrscr;
	textbackground(black);
	marco;
	
	gotoxy(4,3); write('Cod');
	
	for i:=3 to 24 do begin
		gotoxy(8,i); write(#186);
	end;
	
	gotoxy(13,3); write('Nombre');
	
	for i:=3 to 24 do begin
		gotoxy(24,i); write(#186);
	end;
	
	gotoxy(33,3); write('Direccion');
	
	for i:=3 to 24 do begin
		gotoxy(49,i); write(#186);
	end;
	
	gotoxy(52,3); write('Deuda');
	
	for i:=3 to 24 do begin
		gotoxy(58,i); write(#186);
	end;
	
	gotoxy(61,3); write('Ult.Pago');
	for i:=3 to 24 do begin
		gotoxy(70,i); write(#186);
	end;
	gotoxy(72,3); write('Lectura');
	gotoxy(66,3);
	
	j:=5;
	
	for i:=1 to N do
	begin

	
	if (v_cliente[i].sw = 1) then
		with v_cliente[i] do
		begin
			gotoxy(4,j); write(codigo);
			gotoxy(10,j); write(nombre);
			gotoxy(26,j); write(direccion);
			gotoxy(52,j); write(deuda);
			gotoxy(60,j); write(fecha.dia + '/' + fecha.mes + '/' + fecha.anio);
			gotoxy(72,j); write(lectura,'/',lectura_ant);
			inc(j);
		end;
	end;
	marco;
		
	readkey;
	
end;



procedure modificar_cliente(var v_cliente:t_v_cliente);
var
	C_cliente, posi, opcion_mod: integer;
	s_aux, seguro: string;
	
begin
	repeat
		clrscr;
		marco;
		gotoxy(35,3); writeln('MODIFICACION DE CLIENTE');
		gotoxy(20,6); write('Ingrese codigo del cliente a modificar: ');
		readln(C_cliente);
	
		posi := buscar(v_cliente,c_cliente);
		if posi = 0 then
		begin
			gotoxy(25,12); writeln('Codigo no existente, intente de nuevo...');
			gotoxy(25,14); writeln('Presione una tecla para continuar...');
			readkey;
			exit;
		end;
		
		repeat
			clrscr;
			marco;
			gotoxy(35,3); writeln('MODIFICACION DE CLIENTE');
			gotoxy(35,5); Writeln('1.- Modificar Nombre');
			gotoxy(35,6); Writeln('2.- Modificar Direccion');
			gotoxy(35,7); Writeln('3.- Modificar Codigo');
			gotoxy(35,8); Writeln('4.- ELIMINAR Cliente');
			gotoxy(25,10); write('Ingrese opcion: '); readln(opcion_mod);
		until (opcion_mod = 1) or (opcion_mod = 2) or (opcion_mod = 3) or (opcion_mod = 4);
		
		if opcion_mod = 1 then
		begin
			gotoxy(25,12); write('Ingrese nuevo nombre: ');
			readln(s_aux);
			v_cliente[posi].nombre := s_aux;
		end;
		
		if opcion_mod = 2 then
		begin
			gotoxy(25,12); write('Ingrese nueva direccion: ');
			readln(s_aux);
			v_cliente[posi].direccion := s_aux;
		end;
		
		if opcion_mod = 3 then
		begin
			gotoxy(25,12); write('Ingresa nuevo codigo [ENTERO]: ');
			readln(c_cliente);
			v_cliente[posi].codigo := c_cliente;
		end;
		
		if opcion_mod = 4 then
		begin
			repeat
			gotoxy(25,12); Write('ESTA SEGURO? [S/N]: ');
			readln(seguro);
			
			until (upcase(seguro) = 'S') or (upcase(seguro) = 'N');
			
			if upcase(seguro) = 'S' then
			begin
				v_cliente[posi].sw := 0;
				gotoxy(25,14); Writeln('Cliente eliminado Satisfactoriamente...');
				gotoxy(25,16); Writeln('Presione una tecla para continuar...');
				readkey;
			end;
		end;
			
	until posi <> 0;
	
	escribir(a_cliente,v_cliente);
	
end;
		

function leer_contrata(var contrata:t_archivotexto;
						var vCadena:t_vCadena;
						var sz:byte): boolean;
var
	cad_aux : string;
	
begin
	leer_contrata := false;
	assign(contrata,'contrata.txt');
{$i-}
	reset(contrata);
{$i+}
	if ioresult <> 0 then
	begin
		exit;
	end
	else
	begin
		leer_contrata := true;
		sz := 1;
		while not eof(contrata) do
		begin
			readln(contrata,cad_aux);
			vCadena[sz] := cad_aux;
			inc(sz);
		end;
		
		
		close(contrata);
	end;	
	
	
end;

function archivo_factura: integer;
var
	f : file of integer;
	n : integer;
begin
	n:=1001;
	assign(f,'n_factura.dat');
	
{$i-}
	reset(f);
{$i+}
	if IOResult <> 0 then
	begin
		rewrite(f);
		n:=1001;
		write(f,n);
		archivo_factura := n;
	end
	else
	begin
		read(f,n);
		rewrite(f);
		write(f,n+1);
		archivo_factura := n+1;
	end;	
	
	close(f);

end;

procedure factura(var a_factura: t_archivotexto;
				   codigo: integer;
				   paso:boolean);
var
	Anyo, Mes_x, Dia_x, sem:word;
	fecha_pago: string;
	n_factura : integer;
	monto,total:integer;
begin
	append(a_factura);
	
	writeln(a_factura);
	
	GetDate(anyo,mes_x,dia_x, sem);
	
	n_factura := archivo_factura;
	
	monto:= 100;
	total := 150;
	
	with v_cliente[codigo] do
	begin
		fecha_pago := fecha.dia + '/' + fecha.mes + '/' + fecha.anio;
	end;
	
	clrscr;
	
	if paso then
	begin
	
		gotoxy(20,1);writeln('+-------+-------+-------+-------+-------+');
		gotoxy(20,2);writeln('|               SENIAT                  |');
		gotoxy(20,3);writeln('|              EPS, C.A.                |');       
		gotoxy(20,4);writeln('+          RIF: J-20037350-7            +');
		gotoxy(20,5);writeln('|-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-|');
		gotoxy(20,6);writeln('|   AV. Atlantico UNEG- Sede Atlantico  |');
		gotoxy(20,7);writeln('|       Puerto Ordaz, Edo. Bolivar.     |');
		gotoxy(20,8);writeln('+            Zona Postal 8050           +');
		gotoxy(20,9);writeln('| FACTURA #                      ',n_factura:4,'   |');
		gotoxy(20,10);writeln('| FECHA:',dia_x,'/',mes_x,'/',anyo);
		gotoxy(60,10);writeln('|');
		gotoxy(20,11);writeln('|---------------------------------------|');
		gotoxy(20,12);writeln('+           DATOS DEL CLIENTE           +');
		gotoxy(20,13);write('| NOMBRE: ',v_cliente[codigo].Nombre);
		gotoxy(60,13);writeln('|');
		gotoxy(20,14);writeln('| CODIGO CLIENTE: ',codigo);
		gotoxy(60,14);writeln('|');

		gotoxy(20,15);writeln('|---------------------------------------|');
		gotoxy(20,16);writeln('+ ULTIMA FECHA DE PAGO ==>   ',fecha_pago);
		gotoxy(60,16);writeln('+');

		gotoxy(20,17);writeln('| DEUDA =================>   ',v_cliente[codigo].Deuda);
		gotoxy(60,17);writeln('|');

		gotoxy(20,18);writeln('| LECTURA DEL MEDIDOR ===>   ',v_cliente[codigo].Lectura);
		gotoxy(60,18);writeln('|');
		gotoxy(20,19);writeln('|---------------------------------------|'); 
		gotoxy(20,20);writeln('+ MONTO A PAGAR              ',monto:6);
		gotoxy(60,20);writeln('+');

		gotoxy(20,21);writeln('| TOTAL + IVA ===========>   ',total:6);
		gotoxy(60,21);writeln('|');

		gotoxy(20,22);writeln('|                                       |');
		gotoxy(20,23);writeln('+-------+-------+-------+-------+-------+');
	 
	end;
	
	writeln(a_factura);
	writeln(a_factura,'+--------+-------+--------+-------+--------+');
    writeln(a_factura,'               SENIAT                  ');
    writeln(a_factura,'              EPS, C.A.                ');       
	writeln(a_factura,'          RIF: J-20037350-7            ');
	writeln(a_factura,'-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-');
	writeln(a_factura,'   AV. Atlantico UNEG- Sede Atlantico  ');
	writeln(a_factura,'       Puerto Ordaz, Edo. Bolivar.     ');
	writeln(a_factura,'            Zona Postal 8050           ');
	writeln(a_factura,' FACTURA #                      ',n_factura:4,'   ');
	writeln(a_factura,' FECHA:',dia_x,'/',mes_x,'/',anyo,'           ');
	writeln(a_factura,'------------------------------------------');
	writeln(a_factura,' DATOS DEL CLIENTE                     ');
	writeln(a_factura,' ',v_cliente[codigo].Nombre);
	writeln(a_factura,' CODIGO CLIENTE: ',codigo,'                     ');
	writeln(a_factura,'------------------------------------------');
	writeln(a_factura,' ULTIMA FECHA DE PAGO ==>   ',fecha_pago,' ');
	writeln(a_factura,' DEUDA =================>   ',v_cliente[codigo].Deuda,'     ');
	writeln(a_factura,' LECTURA DEL MEDIDOR ===>   ',v_cliente[codigo].Lectura,'     ');
	writeln(a_factura,'------------------------------------------'); 
	writeln(a_factura,' MONTO A PAGAR              ',monto:6,'     ');
	writeln(a_factura,' TOTAL + IVA ===========>   ',total:6,'     ');
	writeln(a_factura,'                                       ');
	writeln(a_factura,'+--------+-------+--------+-------+--------+');
	
	close(a_factura);
	
	readkey;

end;

procedure tratar_contrata(vCadena:t_vCadena; sz: byte;
							var v_cliente:t_v_cliente);
var
	i: integer;
	cadena, aux: string;
	codigo, lectura, ubi, res: integer;
	reg_aux: t_r_cliente;
	flag : boolean;
	
begin
	flag := false;
	for i:=1 to sz-1 do
	begin
		cadena := vCadena[i];

		ubi := Pos(',',cadena);
		delete(cadena,ubi,1);
		aux := Copy(cadena,1,ubi-1);
		val(aux,codigo);
		aux := Copy(cadena,ubi,length(cadena));
		val(aux,lectura);
		
		res := buscar(v_cliente,codigo);
		reg_aux := v_cliente[res];

		if res <> 0 then 
		begin
			//writeln('Modificado: ', reg_aux.lectura, ' por: ',lectura);
			reg_aux.lectura_ant := reg_aux.lectura;
			reg_aux.lectura := lectura;
			v_cliente[res] := reg_aux;
			escribir(a_cliente,v_cliente);
			flag := true;
			
			factura(a_factura,codigo,true);
			readkey;
			
		end	
		else
		begin
			clrscr;
			marco;
			gotoxy(35,3); writeln('HA OCURRIDO UN ERROR');

			gotoxy(25,8); writeln('Codigo Numero: ',codigo,' No encontrado');
			gotoxy(25,9); writeln('Verifique que los datos sean correctos.');
			gotoxy(25,10); writeln('Presione una tecla para continuar...');
			flag := false;
			readkey;
		end;
		
		//DEBUG		
		//writeln('Codigo: ', codigo);
		//writeln('Lectura: ', lectura);
		//writeln('|-----------------|');
		
				
		//modificar_lectura(codigo,lectura);
	
	end;
	
	if not flag then 
	begin
		gotoxy(20,5);
		writeln('Ocurrio al menos un error, verifique su archivo contrata.txt');
		gotoxy(30,6);
		writeln('Presione una tecla para continuar...');
		readkey;
	end;
	
end;

procedure contratista;
begin
	if leer_contrata(contrata,vCadena,sz) then
		tratar_contrata(vCadena, sz, v_cliente)
	else
	begin
		clrscr;
		marco;
		gotoxy(35,3); writeln('HA OCURRIDO UN ERROR');
		
		gotoxy(20,8); writeln('  ----- OCURRIO UN ERROR -> VERIFIQUE QUE EL ARCHIVO EXISTA -----');
		gotoxy(20,9); writeln('  -----        PRESIONE UNA TECLA PARA CONTINUAR...         -----');
	end;
	readkey;
	
end;

procedure portada;
begin
	
	textcolor(lightgreen);
	
	
	gotoxy(10,25); writeln('EEEEEEEEEEEEEEEEEEEEEE PPPPPPPPPPPPPPPPP       SSSSSSSSSSSSSSS ');
	gotoxy(10,25); writeln('E::::::::::::::::::::E P::::::::::::::::P    SS:::::::::::::::S');
	gotoxy(10,25); writeln('E::::::::::::::::::::E P::::::PPPPPP:::::P  S:::::SSSSSS::::::S');
	gotoxy(10,25); writeln('EE::::::EEEEEEEEE::::E PP:::::P     P:::::P S:::::S     SSSSSSS');
	gotoxy(10,25); writeln('  E:::::E       EEEEEE   P::::P     P:::::P S:::::S            ');
	gotoxy(10,25); writeln('  E:::::E                P::::P     P:::::P S:::::S            ');
	gotoxy(10,25); writeln('  E::::::EEEEEEEEEE      P::::PPPPPP:::::P   S::::SSSS         ');
	gotoxy(10,25); writeln('  E:::::::::::::::E      P:::::::::::::PP     SS::::::SSSSS    ');
	gotoxy(10,25); writeln('  E:::::::::::::::E      P::::PPPPPPPPP         SSS::::::::SS  ');
	gotoxy(10,25); writeln('  E::::::EEEEEEEEEE      P::::P                    SSSSSS::::S ');
	gotoxy(10,25); writeln('  E:::::E                P::::P                         S:::::S');
	gotoxy(10,25); writeln('  E:::::E       EEEEEE   P::::P                         S:::::S');
	gotoxy(10,25); writeln('EE::::::EEEEEEEE:::::E PP::::::PP           SSSSSSS     S:::::S');
	gotoxy(10,25); writeln('E::::::::::::::::::::E P::::::::P           S::::::SSSSSS:::::S');
	gotoxy(10,25); writeln('E::::::::::::::::::::E P::::::::P           S:::::::::::::::SS ');
	gotoxy(10,25); writeln('EEEEEEEEEEEEEEEEEEEEEE PPPPPPPPPP            SSSSSSSSSSSSSSS   ');
	gotoxy(10,25); writeln('_______________________________________________________________');
	gotoxy(10,25); writeln('             Electrificacion Pirata Sinloo, C.A.               ');
	gotoxy(10,25); writeln('_______________________________________________________________');
	marco;
	
	gotoxy(60,3); writeln('RIF: J-19121719-3');
	repeat
	until keypressed;
end;

Procedure Opcion(Var O: Char);
Begin
	Repeat
	Begin
		ClrScr;
		Writeln;
		gotoxy(10,3); 
		Writeln (' = MENU PRINCIPAL = Sistema de Administracion de EPS, C.A =');
		gotoxy(25,6); Writeln (' [A] - Agregar Clientes');
		gotoxy(25,7); Writeln (' [C] - Consultar Clientes');
		gotoxy(25,8); Writeln (' [M] - Modificar Clientes');
		gotoxy(25,9); Writeln (' [P] - Agregar o Modificar Pagos');
		gotoxy(25,10); Writeln (' [L] - Leer datos contratista');
		gotoxy(25,12); Writeln (' [S] - Salir del Sistema');
		gotoxy(25,13); Writeln (' ===================================');
		gotoxy(25,14); Writeln;
		gotoxy(28,15); Write (' Ingrese Opcion: ');
		gotoxy(25,17); Writeln (' ===================================');
		marco;
		gotoxy(45,15);
		Readln (O);
		O:=UpCase (O);
	End;
	Until (O='A') or (O='C') or (O='I')
				   or (O='L') or (O='S')
				    or (O='M') or (O='F')
					 or (O='P');
End;
	

//Programa Principal

begin
	portada;
	marco;
	
	abrir(a_cliente, a_factura);
	leer(a_cliente,v_cliente);
	leer_pagos(a_pago,v_pago);
	
	Repeat
		Opcion (O);
		Case O of
		'A': agregar_clientes(v_cliente);
		'C': imprimir(v_cliente);
		'L': contratista;
		'M': modificar_cliente(v_cliente);
		'P': registro_pagos(a_pago,v_pago,v_cliente);
		End;	
	Until (O='S');
	
	readkey;
	
end.

