PHP - Como agregar columnas de manera dinamica y que se sumen por fila y columna?

 
Vista:
sin imagen de perfil
Val: 18
Ha aumentado su posición en 6 puestos en PHP (en relación al último mes)
Gráfica de PHP

Como agregar columnas de manera dinamica y que se sumen por fila y columna?

Publicado por Antunez (12 intervenciones) el 04/10/2021 22:32:47
Estoy queriendo hacer un formulario que permita ingresar las ventas de cajeros el limite de cajeros son 5, pero no podría agregar cada dato por cajero porque seria muy enorme la tabla. Al inicio trabaje la tabla de esa manera y las sumas se hacían perfectamente, pero ya de esta forma todo cambiaria y saber si me pueden ayudar en como hacer porque también quiero saber que si por ejemplo agrego dos columnas que los datos de ambos cajeros se puedan ingresar sin problema alguno y se sumen las filas y columnas, aquí esta el código de mi tabla:

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
<table style="margin: 0 auto;">
	<thead>
		<tr>
			<th scope="col" colspan="7" style="text-align: center;"><b>REPORTE DE LIQUIDACION DIARIA<b></th>
		</tr>
		<tr style="text-align: center;">
			<th>Descripción</th>
			<th><select name="c1" style="width: 180px;">
					<?php
 
					  if (!isset($_SESSION['ti'])) {
								$_SESSION['ti'] = $_REQUEST['ti'];
							}
 
							if ($_SESSION['ti']===NULL){
 
							}else{
								echo  $pal = $_SESSION["ti"];}
 
 
						$sql="SELECT * FROM usuario
						      where id_tienda='$pal' and id_cargo='6'";
						$consul= mysqli_query($cone,$sql) or die(mysqli_error($cone));
					?>
 
					<option value=" " style="text-align-last: center;">Elija un cajero</option>
					<?php foreach ($consul as $opc): ?>
						<option value="<?php echo $opc['nombre_us'] ?>"> <?php echo $opc['nombre_us'] ?> </option>
					<?php endforeach ?>
		        </select></th>
 
			<th style="text-align: center;">TOTALES</th>
		</tr>
 
 
 
		<tr style="text-align: center;">
			<th scope="col">Venta contado</th>
			<th><input type="text" maxlength="15" id="n1" name="n1" onkeyup="vc();format(this)" onchange="format(this)"  value="0"></th>
			<th class="ct">L.<input class="tt" id="vct" type="text" onkeyup="format(this)"  readonly value="0" /></th>
		</tr>
 
		<tr style="text-align: center;">
			<th scope="col">Venta credito</th>
			<th><input type="text" maxlength="15" id="vcr1" name="vcr1" onKeyUp="vcr();format(this)" onchange="format(this)"  value="0"></th>
			<th class="ct">L.<input class="tt" id="vcrt" name="vcrt" onkeyup="format(this)" type="text" readonly value="0" /></th>
		</tr>
 
		<tr style="text-align: center;">
			<th scope="col">R. abonos credito</th>
			<th><input type="text" maxlength="15" id="rat1" name="rat1" onKeyUp="ra();format(this)" onchange="format(this)"  value="0"></th>
			<th class="ct">L.<input class="tt" id="rat" name="rat" onkeyup="format(this)" type="text" readonly value="0" /></th>
		</tr>
 
		<tr style="text-align: center;">
			<th scope="col" class="ct">Totales ventas</th>
			<th class="ct">L.<input class="tt" id="total1E" name="tt1e" onchange="format(this)" type="text" readonly value="0" /></th>
			<th class="ct">L.<input class="tt" id="totalE" onchange="format(this)"  type="text" readonly value="0" /></th>
		</tr>
 
		<tr style="text-align: center;">
			<th scope="col">Efectivo</th>
			<th><input type="text" maxlength="15" id="efec1" name="efec1" onKeyUp="efe();format(this)" onchange="format(this)"  value="0"></th>
			<th class="ct">L.<input class="tt" id="eft" name="eft" onkeyup="format(this)" type="text" readonly value="0" /></th>
		</tr>
 
		<tr style="text-align: center;">
			<th scope="col">Cobro en cheque</th>
			<th><input type="text" id="cc1" name="cc1" onKeyUp="cc();format(this)" onchange="format(this)" maxlength="15" value="0"></th>
			<th class="ct">L.<input class="tt" id="cct" name="cct" onkeyup="format(this)" type="text" readonly value="0" /></th>
		</tr>
 
		<tr style="text-align: center;">
			<th scope="col">V./Plla. empleados</th>
			<th><input type="text" id="ve1" name="ve1" onKeyUp="ve();format(this)" onchange="format(this)" maxlength="15" value="0"></th>
			<th class="ct">L.<input class="tt" id="vet" name="vet" onkeyup="format(this)" type="text" readonly value="0" /></th>
		</tr>
 
		<tr style="text-align: center;">
			<th scope="col">V./Plla. socios</th>
			<th><input type="text" id="vs1" onKeyUp="vs();format(this)" onchange="format(this)" maxlength="15" value="0"></th>
			<th class="ct">L.<input class="tt" id="vst" name="vst" onkeyup="format(this)" type="text" readonly value="0" /></th>
		</tr>
 
		<tr style="text-align: center;">
			<th scope="col">Ventas al credito</th>
			<th><input type="text" id="vac1" onKeyUp="vac();format(this)" onchange="format(this)" maxlength="15" value="0"></th>
			<th class="ct">L.<input class="tt" id="vact" name="vact" onkeyup="format(this)" type="text" readonly value="0" /></th>
		</tr>
 
		<tr style="text-align: center;">
			<th scope="col">Notas al credito</th>
			<th><input type="text" id="nc1" onKeyUp="nc();format(this)" onchange="format(this)" maxlength="15" value="0"></th>
			<th class="ct">L.<input class="tt" id="nct" name="nct" onkeyup="format(this)" type="text" readonly value="0" /></th>
		</tr>
 
		<tr style="text-align: center;">
			<th scope="col">R./Caja chica</th>
			<th><input type="text" id="rc1" onKeyUp="rc();format(this)" onchange="format(this)" maxlength="15" value="0"></th>
			<th class="ct">L.<input class="tt" id="rct" name="rct" onkeyup="format(this)" type="text" readonly value="0" /></th>
		</tr>
 
		<tr style="text-align: center;">
			<th scope="col">C./en efectivo</th>
			<th><input type="text" id="ce1" onKeyUp="ce();format(this)" onchange="format(this)" maxlength="15" value="0"></th>
			<th class="ct">L.<input class="tt" id="cet" onkeyup="format(this)" type="text" readonly value="0" /></th>
		</tr>
 
		<tr style="text-align: center;">
			<th scope="col" class="ct">Totales ingresos</th>
			<th class="ct">L.<input class="tt" id="total1M" name="1m" onchange="format(this)" type="text" readonly value="0" /></th>
			<th class="ct">L.<input class="tt" id="totalI" name="tit" onchange="format(this)"  type="text" readonly value="0" /></th>
		</tr>
 
		<tr style="text-align: center;">
			<th scope="col" class="df">Diferencia</th>
			<th class="df">L.<input class="tt" id="difet" name="dif1" onchange="format(this)" type="text" readonly value="0" /></th>
			<th class="df">L.<input class="tt" id="dift" name="dift" onchange="format(this)"  type="text" readonly value="0" /></th><br>
		</tr>
 
	</thead>
    </table>


Tbla

El combobox me carga los cajeros segun en la tienda que serian inicien y si los el id_usuarios se guarden tambien en otra tabla

Este seria el código de guardar
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
<?php
include "conexion/db.php";
 
$code= $_POST['c5'];
$a= $_POST['a1'];
$b= $_POST['a2'];
$c= $_POST['a3'];
$d= $_POST['a4'];
$e= $_POST['a5'];
$f= $_POST['a6'];
$g= $_POST['a7'];
$h= $_POST['a8'];
$i= $_POST['a9'];
$j= $_POST['ab1'];
$k= $_POST['ab2'];
$l= $_POST['ab3'];
$m= $_POST['ab4'];
$n= $_POST['ab5'];
 
$query="insert into caj_ldi(user, vc, vcr, rabo, efe, tcat, tsta, cc, ve, vs, ver, nc, rcc, ce, fecha) values('$code' ,'$a', '$b', '$c', '$d', '$e', '$f', '$g', '$h', '$i', '$j', '$k', '$l', '$m', '$n')";
$resul= $cone->query($query);
}
 
 
if($resul){
    echo "Datos guardados correctamente";
    header('Location: http://'.$server.'/Proyecto/Menu');
}else{
    print '<script>';
	print 'alert("No fue posible guardar los datos");';
	print 'location.href="http://'.$server.'/Proyecto/ldi';
    print '</script>';
?>


Y este es el codigo que usaba para sumar por columna y es practicamente el mismo por columna
1
2
3
4
5
6
7
8
9
10
11
12
13
14
//------SUMA DE TOTALES----
function c1(){
  //SUMAR TOTALES VETICAL:
  var t1 = parseFloat(document.getElementById("n1").value.replace(/,/g, '')) || 0;
  var t2 = parseFloat(document.getElementById("vcr1").value.replace(/,/g, '')) || 0;
  var t3 = parseFloat(document.getElementById("rat1").value.replace(/,/g, '')) || 0;
  var resut = t1 + t2 + t3;
  resut.toFixed(2);
  document.getElementById("total1E").value = resut;
  format(document.getElementById("total1E"));
 
  difg();
  total_ventas();
}
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