PHP - Como mejorar codigo php para contar

 
Vista:

Como mejorar codigo php para contar

Publicado por Maria Perez (2 intervenciones) el 08/10/2013 22:12:54
Hola como puedo mejorar este codigo para que me cuente el total de documentos que genera la consulta mostrada en el pdf:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
$miconexion->consulta($sql);
	$array_data = array();
	$array_titulo = array();
	$array_sub_tipo = array();
 
	while ($data = $miconexion->arreglo_registros_asociado()){
		$array_data[] = $data;
	}
 
	$sql = "SELECT distinct des_cor_doc from sacd.func_rep_sacd0015 ('$param_fecha_desde', '$param_fecha_hasta',0,0,0) ".
		" AS (id_tipo_doc integer, des_cor_doc character varying(20), id_tpo_carta character varying, cod_carta character varying(60), des_doc character varying(80), id_contrato integer, id_proyecto integer,".
		" id_documento character varying(40), id_revision character varying(2), ver_rev integer, color_div integer,dif_dias text, fec_top text,".
		" id_unidad integer, men_insp character varying, dia_ama integer, desc_prior character varying(20), id_carta character varying(30), fec_sal timestamp without time zone,".
		" nom character varying, desc_cort character varying(10), res text)";
 
	$sql .= $where;
	$sql .= " ORDER BY des_cor_doc";
 
if (count($array_tabla) >0) {
		$PDFRep->Ln(5);
		$PDFRep->FontAndCell('Arial','B',10,30,5,'Total Documentos: '.count($array_data),'T',0,'L',false);
 
	}
	else {
		$PDFRep->Ln(10);
		$PDFRep->FontAndCell('Arial','B',7,20,5,'La Consulta NO arrojo resultados !!',"",0,'L',false);
	}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de xve
Val: 3.943
Oro
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

Como mejorar codigo php para contar

Publicado por xve (6935 intervenciones) el 09/10/2013 07:47:12
Hola Maria, una vez realizada la consulta sql, puedes hacer un
1
count()
del resultado la ejecución de la misma...
Aqui no muestra como ejecutas la consulta sql... si nos lo muestras te indico como, ok?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Como mejorar codigo php para contar

Publicado por maria perez (2 intervenciones) el 09/10/2013 18:10:31
hola este es todo el codigo, te agradezco si me ayudas a que esta linea $PDFRep->FontAndCell('Arial','B',10,30,5,'Total Documentos: '.count($array_data),'T',0,'L',false);
cuente el total de los documentos.

Saludos y Gracias

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
<?php
session_start();
	require_once '../../../../clases/basicas/class.PDF.php';
	require_once '../../../../librerias/funciones.php';
	require_once '../../../../librerias/inc_fecha.php';
	require_once '../../../../librerias/phplot/phplot.php';
 
 
	if (isset($_GET))
	{
		$param_fecha_desde = @cambiaf_a_postgres($_GET['fecha_desde']);
		$param_fecha_hasta = @cambiaf_a_postgres($_GET['fecha_hasta']);
		$param_contrato = @$_GET['contrato'];
		$param_proyecto = @$_GET['proyecto'];
		$param_recibidas = @$_GET['tipo_cartas'];
		$param_tipo_carta = @$_GET['por_tipo_carta'];
	}
	else
	{
		exit();
	}
 
 
 
	function leyenda (PDF $PDFRep, $arreglo_width){
		$x_width = array_sum($arreglo_width);
 
		$PDFRep->SetFillColor(255,255,255);
		$PDFRep->SetDrawColor(51,51,153);
		$PDFRep->FontAndCell('Arial','B',7,$x_width,5,'Situaci&#65533;n',"LTR",0,'L',true);
		$PDFRep->Ln(5);
		$PDFRep->FontAndCell('Arial','B',7,$x_width,5,'No Asignado [?] Revisor [R]  Supervisor [S]  Jefe Dpto [J]  Por Carta [C]  Concluido [!]',"LBR",0,'L',true);
	}
 
	function  getSituacion($status){
 
		switch ($status) {
			case "NO ASIGNADO":	$res = "?"; break;
			case "REVISOR":		$res = "R"; break;
			case "SUPERVISOR":	$res = "S"; break;
			case "JEFE DPTO.":	$res = "J"; break;
			case "POR CARTA":	$res = "C"; break;
			case "CONCLUIDO":	$res = "!"; break;
		}
		return $res;
	}
	/******************
		Generando el PDF
	*******************/
	setlocale(LC_TIME,'es_ES','es_ES.ISO8859-1','es_ES.UTF8','sp','spanish','es_VE','es_VE.ISO8859-1','es_VE.UTF8');
	$miconexion = conectarse_sacd();
 
	$sql = "SELECT * from sacd.func_rep_sacd0015 ('$param_fecha_desde', '$param_fecha_hasta',0,0,0) ".
		" AS (id_tipo_doc integer, des_cor_doc character varying(20), id_tipo_carta character varying, cod_carta character varying(60), des_doc character varying(80), id_contrato integer, id_proyecto integer,".
		" id_documento character varying(40), id_revision character varying(2), ver_rev integer, color_div integer,dif_dias text, fec_top text,".
		" id_unidad integer, men_insp character varying, dia_ama integer, desc_prior character varying(20), id_carta character varying(30), fec_sal timestamp without time zone,".
		" nom character varying, desc_cort character varying(10), res text)";
 
 
	$flag = true;
	if (strlen($param_contrato) > 0){
		if ($flag) $where = " WHERE ";
		$where .= " id_contrato = ". $param_contrato;
		$flag = false;
	}
	if (strlen($param_proyecto) > 0){
		if ($flag)
			$where = " WHERE ";
		else
			$where .= " AND ";
 
		$where .= " id_proyecto = ". $param_proyecto;
		$flag = false;
	}
	if ($param_recibidas == 0){
		// recibidas de los contrario son las enviadas
		if ($flag)
			$where = " WHERE ";
		else
			$where .= " AND ";
 
		//$where .= " cod_carta Is Not Null and cod_carta <> 'N/A' ";
		$where .= " cod_carta Is Not Null ";
		$flag = false;
	}
 
	// solo aplica para cartas enviadas
	if (strlen($param_tipo_carta)>0 && $param_recibidas == 1 ){
		if ($flag)
			$where = " WHERE ";
		else
			$where .= " AND ";
 
		$where .= "  id_carta LIKE '%$param_tipo_carta%'";
		$flag = false;
	}
 
	$sql .= $where;
	$sql .= " ORDER BY id_tipo_carta";
	//print_r($sql); exit(0);
 
	$miconexion->consulta($sql);
	$array_data = array();
	$array_titulo = array();
	$array_sub_tipo = array();
 
	while ($data = $miconexion->arreglo_registros_asociado()){
		$array_data[] = $data;
	}
 
	$sql = "SELECT distinct des_cor_doc from sacd.func_rep_sacd0015 ('$param_fecha_desde', '$param_fecha_hasta',0,0,0) ".
		" AS (id_tipo_doc integer, des_cor_doc character varying(20), id_tpo_carta character varying, cod_carta character varying(60), des_doc character varying(80), id_contrato integer, id_proyecto integer,".
		" id_documento character varying(40), id_revision character varying(2), ver_rev integer, color_div integer,dif_dias text, fec_top text,".
		" id_unidad integer, men_insp character varying, dia_ama integer, desc_prior character varying(20), id_carta character varying(30), fec_sal timestamp without time zone,".
		" nom character varying, desc_cort character varying(10), res text)";
 
	$sql .= $where;
	$sql .= " ORDER BY des_cor_doc";
 
	//print_r($sql); exit(0);
	$miconexion->consulta($sql);
 
	while ($data = $miconexion->arreglo_registros_asociado()){
		$array_sub_tipo[] = $data['des_cor_doc'];
	}
 
	$array_tabla = array();
 
	foreach ($array_sub_tipo as $key => $valor){
		$array_tabla[$valor]= array();
 
		foreach ($array_data as $clave => $row){
			if ($row['des_cor_doc'] == $valor) {
				$array_tabla[$valor][($row['cod_carta']== 'N/A')? $row['id_documento']:$row['cod_carta']] = array($row['nom'],$row['id_revision'], $row['ver_rev'], $row['id_carta'], $row['desc_prior'],  $row['color_div'],$row['fec_top'], $row['dif_dias'], $row['res'],$row['id_unidad']);
			}
		}
	}
	//Obteniendo descripcion de unidades
	$sql = "SELECT nom_proyecto FROM sacd.proyecto WHERE id_proyecto = $param_proyecto ";
	$miconexion->consulta($sql);
 
	while ($data = $miconexion->arreglo_registros_asociado()){
		$desc_proyecto = $data['nom_proyecto'];
	}
 
	$sql = "SELECT nom_con FROM sacd.contrato WHERE id_contrato = $param_contrato and id_proyecto = $param_proyecto ";
	$miconexion->consulta($sql);
 
	while ($data = $miconexion->arreglo_registros_asociado()){
		$desc_contrato = $data['nom_con'];
	}
 
	$id_division = $_SESSION["sacd_division"];
	$sql = "SELECT id_unidad, des_corta FROM sacd.unidad WHERE id_division = $id_division AND id_unidad <> 0 ORDER BY des_corta";
	$miconexion->consulta($sql);
 
	$array_unidades = array();
 
	while ($data = $miconexion->arreglo_registros_asociado()){
		$array_unidades[$data['id_unidad']] = $data['des_corta'];
	}
 
	$array_res = array("?"=>0, "R"=>0, "S"=>0, "J"=>0, "C"=>0,"!"=>0 );
 
	if ($param_recibidas == 0 ) $cartas = "RECIBIDAS";
	else $cartas = "ENVIADAS";
 
	// cargar titulos de la tabla	
	$array_titulo = array_merge(array("Carta","Documento","R","V", "Carta de Respuesta", "Prioridad","  ", "Ent. Prog.", "Dias"),$array_unidades);
 
	$fecha_actual = date("Y-m-d");
	$fill_blanco = "255,255,255";
	$fill_azul= "51,51,153";
	$fill_gris = "192,192,192";
	$fill_grisoscuro = "197,197,197";
	$fill_amarillo = "255,255,0";
	$fill_verde = "0,255,0";
	$fill_rojo = "255,0,0";
 
	$titulo = 'MOVIMIENTO DE CORRESPONDENCIAS '.$cartas;
	$subtitulo1 = 'CONTRATO: '. $desc_contrato;
	$subtitulo2 = 'PROYECTO: '. $desc_proyecto;
 
	$parametros = 'Desde '.FormatFechaDMA($param_fecha_desde).' Hasta '.FormatFechaDMA($param_fecha_hasta);
	$PDFRep = new PDF('L');
	$PDFRep->EstablecerParametrosReporte($parametros);
	$PDFRep->EstablecerTitulo($titulo);
	$PDFRep->AddPage();
	$PDFRep->Ln(5);
	$num_lineas = 1;
	$altos = ceil(($PDFRep->GetStringWidth($subtitulo1)/($PDFRep->w-30))) * 5;
	$PDFRep->FontAndCellWordWrap('Arial','B',10,$PDFRep->w-30,$altos,$subtitulo1,'0',0,'L',false,'',5);
	$PDFRep->Ln($altos);
	$PDFRep->Ln(5);
	$num_lineas += ceil($altos/5);
	$num_lineas += 1;
	$altos = ceil($PDFRep->GetStringWidth($subtitulo2)/($PDFRep->w-30)) * 5;
	$PDFRep->FontAndCellWordWrap('Arial','B',10,$PDFRep->w-30,$altos,$subtitulo2,'0',0,'L',false,'',5);
	$PDFRep->Ln($altos);
	$num_lineas += ceil($altos/5);
 
	//Imprimiendo Tabla
	$array_width = array(25,60,5,5,40,15,8,15,8);
	foreach ($array_unidades as $key=> $values){
		array_push($array_width,8);
	}
 
	$max_lineas = 20;
	$nro_linea = $num_lineas;
	$header = true;
 
	foreach ($array_tabla as $key_tabla => $fila)
	{
		$PDFRep->Ln(5);
		$PDFRep->FontAndCell('Arial','',7,30,5,$key_tabla,"",0,'L',false);
 
		if ($nro_linea == 0 || $header)
		{
			$count = 0;
			list($rojo,$verde,$azul) = split( '[|/.,-]',$fill_azul);
			$PDFRep->SetFillColor($rojo,$verde,$azul);
			$PDFRep->SetTextColor(255,255,255);
 
			$PDFRep->Ln(5);
 
			foreach (array_values($array_titulo) as $titulo)
			{
				$x_width = $array_width[$count++];
				$PDFRep->FontAndCell('Arial','B',7,$x_width,5,$titulo,1,0,'C',true);
			}
			$PDFRep->Ln(5);
			$nro_linea ++;
			list($rojo,$verde,$azul) = split( '[|/.,-]',$fill_blanco);
			$PDFRep->SetFillColor($rojo,$verde,$azul);
			$PDFRep->SetTextColor(0,0,0);
		}
 
		foreach ($fila as $key => $doc)
		{
			$count = 0;
			$PDFRep->SetTextColor(0,0,0);
 
			foreach ($doc as $detalle) {
				if ($count == 6) {
					//semaforo
					$PDFRep->FontAndCellWordWrap('Arial','',7,$array_width[$count++],$alto,'','TB',0,'C',false,'',3.5);
 
					switch ($detalle) {
					 	case  0: list($rojo,$verde,$azul) = split( '[|/.,-]',$fill_verde);
					 			 break;
					 	case -1: list($rojo,$verde,$azul) = split( '[|/.,-]',$fill_amarillo);
					 			 break;
					 	case  1: list($rojo,$verde,$azul) = split( '[|/.,-]',$fill_rojo);
					 			 break;
					 }
 
					$PDFRep->SetFillColor($rojo,$verde,$azul);
					$PDFRep->Circle($PDFRep->GetX()-4,$PDFRep->GetY()+2,1.5,'F');
					list($rojo,$verde,$azul) = split( '[|/.,-]',$fill_blanco);
					$PDFRep->SetFillColor($rojo,$verde,$azul);
				}
				else {
					if ($count == 0) {
						$alto1 = (ceil(($PDFRep->GetStringWidth($doc[0])+10)/$array_width[1])) * 5;
						$alto2 = (ceil(($PDFRep->GetStringWidth($key)+10)/$array_width[0])) * 5;
 
						if ($alto1 > $alto2)
							$alto = $alto1;
						else
							$alto = $alto2;
 
						$PDFRep->FontAndCellWordWrap('Arial','',7,$array_width[$count++],$alto,$key,1,0,'C',false,'',3.5);
					}
					if ($count <=8 ) {
						$PDFRep->FontAndCellWordWrap('Arial','',7,$array_width[$count++],$alto,$detalle,'TB',0,'J',false,'',3.5);
					}
					else {
						// unidades
						if ($count == 9) { $res = $detalle; $count++; }
						else {
							foreach ($array_unidades as $unidad => $descripcion){
								if ($unidad == $detalle) {
									if ($count == count($array_titulo)) {
										$PDFRep->FontAndCellWordWrap('Arial','',7,$array_width[$count -1],$alto,getSituacion($res),'TBR',0,'C',false,'',3.5);
									}
									else {
										$PDFRep->FontAndCellWordWrap('Arial','',7,$array_width[$count -1],$alto,getSituacion($res),'TB',0,'C',false,'',3.5);
									}
								}
								else {
									if ($count == count($array_titulo))
										$PDFRep->FontAndCellWordWrap('Arial','',7,$array_width[$count -1],$alto,' ','TBR',0,'C',false,'',3.5);
									else
										$PDFRep->FontAndCellWordWrap('Arial','',7,$array_width[$count -1],$alto,' ','TB',0,'C',false,'',3.5);
 
								}
								$count++;
							}
						}
 
					}
				}
 
				if (($nro_linea) >= $max_lineas)
				{
					$PDFRep->Ln(5);
					if ($nro_linea < $max_lineas + 3) leyenda($PDFRep, $array_width);
					$PDFRep->AddPage();
					$PDFRep->Ln(5);
					$nro_linea = 0;
					$header = false;
				}
				else {
					$header = true;
				}
			}
			$PDFRep->Ln($alto);
 
			if ($alto > 5)
				$nro_linea = $nro_linea + ($alto /5);
			else
				$nro_linea ++;
			//break;
 
			if (($nro_linea) >= $max_lineas)
			{
				$PDFRep->Ln(5);
				if ($nro_linea < $max_lineas + 3) leyenda($PDFRep, $array_width);
				$PDFRep->AddPage();
				$PDFRep->Ln(5);
				$nro_linea = 0;
				$header = false;
			}
			else {
				$header = true;
			}
		}
 
		//Salto de Pagina por si se Acaban las Lineas
		if (($nro_linea) >= $max_lineas)
		{
			$PDFRep->Ln(5);
			if ($nro_linea < $max_lineas + 3) leyenda($PDFRep, $array_width);
			$PDFRep->AddPage();
			$PDFRep->Ln(5);
			$nro_linea = 0;
			$header = false;
		}
		else {
			$header = true;
		}
	}
 
	if (count($array_data) >0) {
		$PDFRep->Ln(5);
		$PDFRep->FontAndCell('Arial','B',10,30,5,'Total Documentos: '.count($array_data),'T',0,'L',false);
 
	}
	else {
		$PDFRep->Ln(10);
		$PDFRep->FontAndCell('Arial','B',7,20,5,'La Consulta NO arrojo resultados !!',"",0,'L',false);
	}
 
	$PDFRep->Ln(10);
	leyenda($PDFRep, $array_width);
	$nro_linea = 0;
	$PDFRep->Output('sacd0015.pdf','I');
?>
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar