Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 127 |
|
0.00% |
0 / 5 |
CRAP | n/a |
0 / 0 |
|
| calculaGastosdeCuentaT | |
0.00% |
0 / 18 |
|
0.00% |
0 / 1 |
30 | |||
| leeLimitesPCG | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| revisaLimitesPCG | |
0.00% |
0 / 39 |
|
0.00% |
0 / 1 |
506 | |||
| generaHtmlPlantillasCtaG | |
0.00% |
0 / 37 |
|
0.00% |
0 / 1 |
306 | |||
| calculaFechaAutomaticaCTG | |
0.00% |
0 / 30 |
|
0.00% |
0 / 1 |
72 | |||
| 1 | <?php |
| 2 | |
| 3 | function calculaGastosdeCuentaT($cuentaT_id='') |
| 4 | { |
| 5 | global $gIAParametros; |
| 6 | |
| 7 | if(empty($cuentaT_id)) |
| 8 | return 0.00; |
| 9 | |
| 10 | $diasParaContabilizar = 0; |
| 11 | |
| 12 | $diasParaContabilizarParam = $gIAParametros['numero_dias_contabilizar_gastos_cuentat']; |
| 13 | |
| 14 | $diadelMes = date('d'); |
| 15 | $diasdelMes = date('t'); |
| 16 | |
| 17 | if($diasParaContabilizarParam > $diasdelMes) |
| 18 | $diasParaContabilizarParam = $diasdelMes; |
| 19 | |
| 20 | $diasParaContabilizar = $diadelMes % $diasParaContabilizarParam; |
| 21 | |
| 22 | if($diadelMes == 31 && $diasParaContabilizar<$diasParaContabilizarParam) |
| 23 | $diasParaContabilizar = $diasParaContabilizarParam + $diasParaContabilizar; |
| 24 | |
| 25 | //echo "<pre>$diasParaContabilizar</pre>"; |
| 26 | //$diasParaContabilizar--; |
| 27 | |
| 28 | $diaCGInicial = ''; |
| 29 | $diaCGFinal = ''; |
| 30 | |
| 31 | $diaCGInicial = new DateTime(date('Y-m-d')); |
| 32 | $diaCGInicial->modify("-$diasParaContabilizar day"); |
| 33 | $diaCGInicial = $diaCGInicial->format('Y-m-d'); |
| 34 | |
| 35 | $diaCGFinal = new DateTime(date('Y-m-d')); |
| 36 | //$diaCGFinal->modify("+1 day"); |
| 37 | $diaCGFinal = $diaCGFinal->format('Y-m-d'); |
| 38 | |
| 39 | //$sql="SELECT * FROM cuentat_gasto WHERE activo='Si' AND cuentaT_id='$cuentaT_id' AND fecha>'$diaCGInicial' AND fecha<='$diaCGFinal'"; |
| 40 | //$arr_gastosCtaT = ia_sqlArrayIndx($sql); |
| 41 | |
| 42 | //echo "diaCGInicial:$diaCGInicial<br />"; |
| 43 | //echo "diaCGFinal:$diaCGFinal<br />"; |
| 44 | $sql = "SELECT SUM(egreso) FROM cuentat_gasto WHERE activo='Si' AND cuentaT_id='$cuentaT_id' AND fecha between '$diaCGInicial' AND '$diaCGFinal'"; |
| 45 | //echo "sql:$sql<br />"; |
| 46 | $gastosAcumulados = ia_singleread($sql); |
| 47 | |
| 48 | return $gastosAcumulados; |
| 49 | } |
| 50 | |
| 51 | function leeLimitesPCG($pID) |
| 52 | { |
| 53 | $limPCG = array('monto_maximo' => 0.00, |
| 54 | 'periodicidad_mensual' => 0, |
| 55 | 'num_veces_utilizar' => 0, |
| 56 | 'fecha_primer_mov' => 0, |
| 57 | 'fecha_ultimo_mov' => 0, |
| 58 | 'num_veces_utilizado' => 0, |
| 59 | 'fecha_inicio_validez' => 0, |
| 60 | 'fecha_expiracion' => 0 |
| 61 | ); |
| 62 | if(empty($pID)) |
| 63 | return $limPCG; |
| 64 | |
| 65 | return ia_singleton("SELECT * FROM plantilla_cuentat_gasto WHERE plantilla_cuentat_gasto_id='$pID'"); |
| 66 | } |
| 67 | |
| 68 | function revisaLimitesPCG($pID='', $monto=0.00, $insert=true, $fecha_ref = "") |
| 69 | { |
| 70 | $retVal = array('gastoAprobado' => false, 'PCGenDB' => array(), 'Error' => ''); |
| 71 | |
| 72 | $now = empty($fecha_ref) ? strtotime("now") : strtotime($fecha_ref); |
| 73 | |
| 74 | // $fecha_ref = empty($fecha_ref) ? date('Y-m-d') : $fecha_ref; |
| 75 | |
| 76 | if(empty($pID) || empty($monto)) |
| 77 | return $retVal; |
| 78 | |
| 79 | $PCGenDB = ia_singleton("SELECT * FROM plantilla_cuentat_gasto WHERE plantilla_cuentat_gasto_id='$pID'"); |
| 80 | |
| 81 | if($PCGenDB['tiene_restricciones'] == 'No') |
| 82 | return array('gastoAprobado' => true, 'PCGenDB' => $PCGenDB, 'Error' => ''); |
| 83 | |
| 84 | $PCGenDB['fecha_inicio_validez'] = !empty($PCGenDB['fecha_inicio_validez']) ? strtotime($PCGenDB['fecha_inicio_validez']) : false; |
| 85 | $PCGenDB['fecha_expiracion'] = !empty($PCGenDB['fecha_expiracion']) ? strtotime($PCGenDB['fecha_expiracion']) : false; |
| 86 | $monto = echonf($monto, true, 2, ""); |
| 87 | $PCGenDB['monto_maximo'] = echonf($PCGenDB['monto_maximo'], true, 2, ""); |
| 88 | $retVal['PCGenDB'] = $PCGenDB; |
| 89 | |
| 90 | //echo "<pre>".print_r($PCGenDB, true)."</pre>monto: $monto<br />now: $now"; |
| 91 | |
| 92 | if(empty($PCGenDB)) |
| 93 | return $retVal; |
| 94 | |
| 95 | if(!empty($PCGenDB['fecha_inicio_validez']) && $PCGenDB['fecha_inicio_validez'] > $now) |
| 96 | { |
| 97 | //echo "fecha_inicio_validez: $PCGenDB[fecha_inicio_validez]<br />now: $now"; |
| 98 | //$retVal['Error'] = "fecha_inicio_validez: $PCGenDB[fecha_inicio_validez]<br />now: $now"; |
| 99 | return $retVal; |
| 100 | } |
| 101 | |
| 102 | if(!empty($PCGenDB['fecha_expiracion']) && $PCGenDB['fecha_expiracion'] < $now) |
| 103 | { |
| 104 | //echo "fecha_expiracion: $PCGenDB[fecha_expiracion]<br />now: $now"; |
| 105 | //$retVal['Error'] = "fecha_expiracion: $PCGenDB[fecha_expiracion]<br />now: $now"; |
| 106 | return $retVal; |
| 107 | } |
| 108 | |
| 109 | if($monto > $PCGenDB['monto_maximo']) |
| 110 | { |
| 111 | //echo "monto: $monto<br />monto_maximo: $PCGenDB[monto_maximo]"; |
| 112 | //$retVal['Error'] = "monto: $monto<br />monto_maximo: $PCGenDB[monto_maximo]"; |
| 113 | return $retVal; |
| 114 | } |
| 115 | |
| 116 | if($insert && !empty($PCGenDB['num_veces_utilizar']) && $PCGenDB['num_veces_utilizado'] > $PCGenDB['num_veces_utilizar']) |
| 117 | { |
| 118 | //echo "num_veces_utilizar: $PCGenDB[num_veces_utilizar]<br />num_veces_utilizado: $PCGenDB[num_veces_utilizado]"; |
| 119 | //$retVal['Error'] = "num_veces_utilizar: $PCGenDB[num_veces_utilizar]<br />num_veces_utilizado: $PCGenDB[num_veces_utilizado]"; |
| 120 | return $retVal; |
| 121 | } |
| 122 | |
| 123 | if($insert && !empty($PCGenDB['periodicidad_semanal'])) |
| 124 | { |
| 125 | $lunes = date('Y-m-d', strtotime('monday this week', $now)) . " 00:00:00"; |
| 126 | $domingo = date('Y-m-d', strtotime('sunday this week', $now)) ." 23:59:59"; |
| 127 | $sql = "SELECT COUNT(cuentat_gasto_id) FROM cuentat_gasto WHERE activo='Si' AND fecha BETWEEN '$lunes' AND '$domingo' AND plantilla_cuentat_gasto_id='$pID'"; |
| 128 | $vecesSemana = ia_singleread($sql); |
| 129 | // echo "periodicidad_semanal<br>".$sql; |
| 130 | if($vecesSemana >= $PCGenDB['periodicidad_semanal']) |
| 131 | { |
| 132 | //echo "periodicidad_semanal: $PCGenDB[periodicidad_semanal]<br />vecesSemana: $vecesSemana<br />lunes:$lunes<br />domingo:$domingo"; |
| 133 | //$retVal['Error'] = "periodicidad_semanal: $PCGenDB[periodicidad_semanal]<br />vecesSemana: $vecesSemana<br />lunes:$lunes<br />domingo:$domingo"; |
| 134 | return $retVal; |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | if($insert && !empty($PCGenDB['periodicidad_mensual'])) |
| 139 | { |
| 140 | $mesActual = date("Y-m", $now); |
| 141 | $primerdiamesActual = date('Y-m-01', strtotime($mesActual)); |
| 142 | $ultimodiamesActual = date('Y-m-t', strtotime($mesActual)); |
| 143 | |
| 144 | $sql = "SELECT COUNT(cuentat_gasto_id) FROM cuentat_gasto WHERE activo='Si' AND fecha between '$primerdiamesActual' AND '$ultimodiamesActual' AND plantilla_cuentat_gasto_id='$pID'"; |
| 145 | |
| 146 | // echo "periodicidad_mensual:<br>".$sql; |
| 147 | |
| 148 | $vecesMes = ia_singleread($sql); |
| 149 | //$vecesMes = ia_singleread("SELECT COUNT(cuentat_gasto_id) FROM cuentat_gasto WHERE activo='Si' AND |
| 150 | // fecha LIKE '$mesActual%' AND plantilla_cuentat_gasto_id='$pID'"); |
| 151 | if($vecesMes >= $PCGenDB['periodicidad_mensual']) |
| 152 | { |
| 153 | //echo "periodicidad_mensual: $PCGenDB[periodicidad_mensual]<br />vecesMes: $vecesMes<br />mesActual:$mesActual"; |
| 154 | //$retVal['Error'] = "periodicidad_mensual: $PCGenDB[periodicidad_mensual]<br />vecesMes: $vecesMes<br />mesActual:$mesActual"; |
| 155 | return $retVal; |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | $retVal['gastoAprobado'] = true; |
| 160 | |
| 161 | return $retVal; |
| 162 | |
| 163 | } |
| 164 | |
| 165 | function generaHtmlPlantillasCtaG($aoh = 'h', $todas = false) |
| 166 | { |
| 167 | if(empty($aoh)) |
| 168 | $aoh = 'h'; |
| 169 | |
| 170 | $todas = $todas && usuarioTipoRony(1); |
| 171 | |
| 172 | $arrPlantillas = ia_sqlArray("SELECT * FROM plantilla_cuentat_gasto WHERE 1 ORDER BY tiene_restricciones DESC, orden ASC", "plantilla_cuentat_gasto_id"); |
| 173 | |
| 174 | foreach($arrPlantillas as &$tmplt) |
| 175 | { |
| 176 | $tmplt['campos'] = substr(preg_replace('/\\\\n|\\\\t|\\\\/', '', $tmplt['campos']), 1, -1); |
| 177 | $cAu = false; |
| 178 | $tmp = json_decode($tmplt['campos']); |
| 179 | foreach($tmp as $k=>&$f) |
| 180 | if($f->type == 'campoAutomatico') |
| 181 | { |
| 182 | $cAu = true; |
| 183 | $f->nombre = property_exists($f, 'nombre') ? ia_htmlentities($f->nombre) : 'SIN NOMBRE'; |
| 184 | foreach($f->values as $i=>&$v) |
| 185 | $v->result = ia_htmlentities(calculaFechaAutomaticaCTG($v->value)); |
| 186 | } |
| 187 | if($cAu) |
| 188 | $tmplt['campos'] = json_encode($tmp); |
| 189 | } |
| 190 | |
| 191 | if($aoh=='a') |
| 192 | return $arrPlantillas; |
| 193 | |
| 194 | $dcr=''; $dsr=''; $html=''; |
| 195 | |
| 196 | foreach($arrPlantillas as $k=>$v) |
| 197 | { |
| 198 | //echo "<pre>".print_r($v, true)."</pre>"; |
| 199 | if($v['activa']!='Si') |
| 200 | continue; |
| 201 | |
| 202 | $title = "Monto máximo: $ ".echonf($v['monto_maximo'], true)." "; |
| 203 | |
| 204 | if(!$todas && $v['pausado']=='Si') |
| 205 | { |
| 206 | $btn = "delete.png"; |
| 207 | $hl = "void(0)"; |
| 208 | } |
| 209 | else |
| 210 | { |
| 211 | $btn = "add.png"; |
| 212 | //$hl = "llenaRemarksconPlantilla(\"$k\")"; |
| 213 | $hl = "nuevoGastoCuentaT(\"$k\")"; |
| 214 | } |
| 215 | if($v['tiene_restricciones'] == 'Si') |
| 216 | { |
| 217 | if($v['periodicidad_mensual'] > 0) |
| 218 | $title.="¿Cuántas veces al mes? $v[periodicidad_mensual] "; |
| 219 | if($v['periodicidad_semanal'] > 0) |
| 220 | $title.="¿Cuántas veces a la semana? $v[periodicidad_semanal] "; |
| 221 | $dcr.="<div id='$k' class='ui-menu ui-widget ui-widget-content ui-corner-all' style='padding:3px;'><a href='javascript:void(0);' onclick='$hl' style='text-decoration: none;' title='$title'><strong style='background-color:#$v[bkgcolor]; color:#$v[color];'> $v[nombre] </strong><img src='../img/$btn' width='14' height='14' alt='$title' title='$title' /></a></div>"; |
| 222 | } |
| 223 | else |
| 224 | { |
| 225 | $dsr.="<div id='$k' class='ui-menu ui-widget ui-widget-content ui-corner-all' style='padding:3px;'><a href='javascript:void(0);' onclick='$hl' style='text-decoration: none;' title='$title'><strong style='background-color:#$v[bkgcolor]; color:#$v[color];'> $v[nombre] </strong><img src='../img/$btn' width='14' height='14' alt='$title' title='$title' /></a></div>"; |
| 226 | } |
| 227 | } |
| 228 | $html='<div id="plantillasSinRestriccion" class="ui-widget ui-widget-header ui-corner-all" style="float: left; width: 49%; text-align:left;"><strong>-= SIN RESTRICCIONES =-</strong><hr/>'.$dsr.'</div>'; |
| 229 | $html.='<div id="plantillasConRestriccion" class="ui-widget ui-widget-header ui-corner-all" style="float: left; width: 49%; text-align:left;"><strong>-= CON RESTRICCIONES =-</strong><hr/>'.$dcr.'</div>'; |
| 230 | |
| 231 | return $html; |
| 232 | } |
| 233 | |
| 234 | function calculaFechaAutomaticaCTG($str='mes') |
| 235 | { |
| 236 | global $gIAData; |
| 237 | switch ($str) |
| 238 | { |
| 239 | case 'numsemana': |
| 240 | return date('W'); |
| 241 | break; |
| 242 | |
| 243 | case 'nummes': |
| 244 | return date('m'); |
| 245 | break; |
| 246 | |
| 247 | case 'diassemana': |
| 248 | $day = date('w') - 1; |
| 249 | $lunes = strtotime('-'.$day.' days'); |
| 250 | $dom = strtotime('+'.(6-$day).' days'); |
| 251 | $week_start = date('d', $lunes); |
| 252 | $week_end = date('d', $dom); |
| 253 | $month1 = strtoupper($gIAData['monthLong'][date('n', $lunes)]); |
| 254 | $month2 = strtoupper($gIAData['monthLong'][date('n', $dom)]); |
| 255 | if($month1 == $month2) |
| 256 | $ret = "DEL $week_start AL $week_end DE $month1."; |
| 257 | else |
| 258 | $ret = "DEL $week_start DE $month1 AL $week_end DE $month2."; |
| 259 | return $ret; |
| 260 | |
| 261 | break; |
| 262 | |
| 263 | case 'diassemanapasada': |
| 264 | $lunes = strtotime('monday last week'); |
| 265 | $dom = strtotime('sunday last week'); |
| 266 | $week_start = date('d', $lunes); |
| 267 | $week_end = date('d', $dom); |
| 268 | $month1 = strtoupper($gIAData['monthLong'][date('n', $lunes)]); |
| 269 | $month2 = strtoupper($gIAData['monthLong'][date('n', $dom)]); |
| 270 | if($month1 == $month2) |
| 271 | $ret = "DEL $week_start AL $week_end DE $month1."; |
| 272 | else |
| 273 | $ret = "DEL $week_start DE $month1 AL $week_end DE $month2."; |
| 274 | return $ret; |
| 275 | break; |
| 276 | |
| 277 | case 'mes': |
| 278 | return strtoupper($gIAData['monthLong'][date('n')]); |
| 279 | break; |
| 280 | } |
| 281 | } |