-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathegress.php
More file actions
218 lines (177 loc) · 6.52 KB
/
egress.php
File metadata and controls
218 lines (177 loc) · 6.52 KB
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
<?php include('./includes/conn.php');
$titulo = "Egress";
include ("head.php");
setlocale(LC_MONETARY, 'en_US');
$mysqli = con_start();
$countM = 0;
$countI = 0;
$id = 1;
$smtp = $mysqli->prepare("SELECT t.amount, t.monthly,
EXTRACT(MONTH FROM t.created), t.created, t.id_trans, t.description
FROM Transaction t
WHERE t.id_user = 1 AND t.is_active = 1 AND t.type = 2");
$smtp->bind_param("i", $id);
$smtp->execute();
$smtp->store_result();
$smtp->bind_result($amount, $monthly, $month, $date, $idt, $desc);
while ($smtp->fetch()) {
if($monthly == 1){
$retM[$countM][0] = $amount;
$retM[$countM][1] = $idt;
$retM[$countM][2] = $desc;
$countM++;
} elseif($monthly == 0){
$retI[$month][] = array($amount, $idt);
}
}
$smtp->free_result();
$smtp->close();
function getMonth ($i){
switch ($i) {
case 1:
return "Enero";
case 2:
return "Febrero";
case 3:
return "Marzo";
case 4:
return "Abril";
case 5:
return "Mayo";
case 6:
return "Junio";
case 7:
return "Julio";
case 8:
return "Agosto";
case 9:
return "Septiembre";
case 10:
return "Octubre";
case 11:
return "Noviembre";
case 12:
return "Diciembre";
}
}
?>
<div class="container">
<div class="row">
<div class="col-lg-12" style="padding: 80px 0 0;">
<div class="mdl-card__title mdl-card--expand">
<!-- title -->
<h2 class="mdl-card__title-text">Perdida de cada mes</h2>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6 mdl-card mdl-shadow--2dp">
<div class="mdl-card__supporting-text monthly_ingress">
<!-- body -->
<div class="table-responsive">
<table class="table">
<thead>
<th>Cantidad</th>
<th>Descripcion</th>
<th>Acción</th>
</thead>
<tbody id="tbodyIngresos">
<?php
for($i = 0; $i < count($retM); $i++){
echo "<tr>";
echo "<td style='background-color: #E7BAB6;' >- " . money_format('%(#5n',$retM[$i][0]) . "</td>";
echo "<td>".$retM[$i][2]."</td>";
echo "<td><button class='remove' data-id='".$retM[$i][1]."' value='remove' style='color:green;'>Quitar perdida</button></td>";
echo "</tr>";
}
?>
</tbody>
</table>
</div>
</div>
<div class="mdl-card__actions mdl-card--border">
<!-- button -->
<input id="ingresoFijo" class="monthlyInput" type="text" name="amount" placeholder="100" style="color:black;">
<input id="desc" class="monthlyInput" type="text" name="desc" placeholder="Compra de materiales" style="color:black;">
<button style="color:red;" class="insertMonthly mdl-button mdl-js-button mdl-js-ripple-effect"
data-idu='1'>Registra deuda mensual</button>
</div>
</div>
<div class="col-md-6">
<?php
for($i = 0; $i < 13; $i++){
if(count($retI[$i]) > 0){
$row = "<div class='table-responsive'>";
$row .= "<table class='table'>";
$row .= "<thead>";
$row .= "<th colspan='3'>" . getMonth($i). "</th>";
$row .= "</thead>";
$row .= "<tbody>";
#body
for($j = 0; $j < count($retI[$i]); $j++){
$row .= "<tr>";
$row .= "<td style='background-color: #E7BAB6;'>- ". money_format('%(#5n',$retI[$i][$j][0]). "</td>";
$row .= "<td> Descripcion</td>";
$row .= "<td><button class='remove' data-id='".$retI[$i][$j][1]."' value='remove' style='color:green;'>Quitar adeudo</button></td>";
$row .= "</tr>";
}
$row .= "</tbody>";
$row .= "</table>";
$row .= "<div class='mdl-card__actions mdl-card--border'>";
$row .= "<input id='ingresoFijo' class='monthlyInput' type='text' name='amount' placeholder='100' style='color:black;'>";
$row .= "<button style='color:red;' class='insertMonthly mdl-button mdl-js-button mdl-js-ripple-effect' data-idu='1'>Pagaste dinero en ".getMonth($i) . "</button>";
$row .= "</div>";
#button
echo $row;
}
}
?>
</div>
</div>
</div>
<script>
$(document).ready(function() {
$('#egress').addClass("active");
});
$('.insertMonthly').on('click', function (e) {
e.preventDefault();
var idu = $(this).attr('data-idu');
var row = $('#tbodyIngresos');
var amount = $('#ingresoFijo').val();
var desc = $('#desc').val();
var button = $(this);
$.ajax({
type: 'post',
url: './createMonthlyDebt.php',
data: {idu:idu, amount: amount, desc: desc},
success: function (json) {
if ($.trim(json)!=0) {
var newRow = "<tr>";
newRow += "<td style='background-color: #E7BAB6;'>- " + amount + ".00</td>";
newRow += "<td>"+desc+"</td>";
newRow += "<td><button class='remove' data-id='"+$.trim(json)+"' value='remove' style='color:red;'>Quitar ganancia</button>";
newRow += "</tr>";
$(row).append(newRow);
}
}
});
});
$('.remove').on('click', function (e) {
console.log("clicked", this);
e.preventDefault();
var id = $(this).attr('data-id');
var button = $(this);
$.ajax({
type: 'post',
url: './removeTransaction.php',
data: {id:id},
success: function (json) {
$(button).parent().parent().hide("slow");
},
error: function (json) {
console.log(json);
}
});
});
</script>
<?php include("foot.php") ?>