/** * Metodo que calcula el porcentaje de los tipos de gasto del usuario pasado * como parametro en funcion del rango de fechas pasado como parametro. * Para realizar el calculo, primero obtiene todos los gastos y la cantidad * numerica de gasto que representan. Despues se invoca a un metodo privado * para conocer el total de gasto del usuario y se calculan los porcentajes * de cada tipo de gasto. Finalmente, se crea un tipo de gasto especial que * representa el porcentaje de gasto de aquellos gastos que no tengan ningun * tipo de gasto asignado. */ public function findByOwnerAndFilterWithPercents($owner, $startDate, $endDate) { $stmt = $this->db->prepare("SELECT SUM(s.quantity) as 'spending.quantity',\n t.idType as 'type.id',\n t.name as 'type.name'\n FROM SPENDING s LEFT JOIN TYPE_SPENDING ts ON s.idSpending = ts.spending LEFT JOIN TYPE t on ts.type = t.idType\n WHERE s.owner = ? AND s.dateSpending BETWEEN ? AND ? AND ts.spending IS NOT NULL GROUP BY ts.type"); $stmt->execute(array($owner, $startDate, $endDate)); $types_db = $stmt->fetchAll(PDO::FETCH_ASSOC); if (sizeof($types_db)) { $total = $this->getTotal($owner, $startDate, $endDate); $types = []; foreach ($types_db as $type_loop) { $type = new Type(); $type->setName($type_loop['type.name']); $percent = $type_loop["spending.quantity"] * 100 / $total; array_push($types, array("typename" => $type->getName(), "percent" => round($percent, 2), "total" => (double) $type_loop["spending.quantity"])); } $totalWithoutType = $this->getTotalSpendingsWithoutType($owner, $startDate, $endDate); if ($totalWithoutType != 0) { $percentSpecialType = $totalWithoutType * 100 / $total; $specialType = new Type(); $specialType->setName("Without category"); array_push($types, array("typename" => $specialType->getName(), "percent" => round($percentSpecialType, 2), "total" => (double) $totalWithoutType)); } return $types; } else { return NULL; } }
public function create($data) { $currentUser = parent::authenticateUser(); $type = new Type(); if (!$this->typeDAO->isNewType($data->name)) { header($this->server->getServerProtocol() . ' 400 Bad request'); echo "This type already exits"; return; } if (isset($data->name)) { $type->setName($data->name); $type->setOwner($currentUser->getLogin()); try { $idType = $this->typeDAO->save($type); header($this->server->getServerProtocol() . ' 201 Created'); header($this->server->getRequestUri() . "/" . $idType); header('Content-Type: application/json'); } catch (ValidationException $e) { header($this->server->getServerProtocol() . ' 400 Bad request'); echo json_encode($e->getErrors()); } } }
function showEditTypeGeneralRes() { $displaySysAdmin = new DisplaySysAdmin(); $survey = new Survey($_SESSION['SUID']); $tyd = getFromSessionParams('tyd'); $content = ""; if ($tyd != '') { //edit $type = $survey->getType($tyd); $_SESSION['TYD'] = $tyd; $content = $displaySysAdmin->displaySuccess(Language::messageTypeChanged(loadvar(SETTING_NAME))); } else { //add section! if (loadvar(SETTING_NAME) != "") { $type = new Type(); $type->setSuid($_SESSION['SUID']); $_SESSION['TYD'] = $type->getTyd(); $content = $displaySysAdmin->displaySuccess(Language::messageTypeAdded(loadvar(SETTING_NAME))); } } $checker = new Checker($_SESSION['SUID']); if ($tyd == '') { $checks = $checker->checkTypeName(loadvar(SETTING_NAME)); if (sizeof($checks) > 0) { $content = implode("<br/>", $checks); return $this->showAddType($content); } } //ADD ALL SORTS OF CHECKS!! if ($tyd != '' || loadvar(SETTING_NAME) != "") { $type->setName(trim(loadvar(SETTING_NAME))); $type->setAnswerType(loadvar(SETTING_ANSWERTYPE)); $type->setAnswerTypeCustom(loadvar(SETTING_ANSWERTYPE_CUSTOM)); $type->setOptionsText(loadvarAllowHTML(SETTING_OPTIONS)); $type->setArray(loadvar(SETTING_ARRAY)); $type->setKeep(loadvar(SETTING_KEEP)); $answertype = loadvar(SETTING_ANSWERTYPE); if (inArray($answertype, array(ANSWER_TYPE_NONE, ANSWER_TYPE_SECTION))) { $type->setHidden(HIDDEN_YES); } else { $type->setHidden(loadvar(SETTING_HIDDEN)); } if ($type->getInputMask() == "") { switch ($answertype) { case ANSWER_TYPE_INTEGER: $type->setInputMask(INPUTMASK_INTEGER); break; case ANSWER_TYPE_DOUBLE: $type->setInputMask(INPUTMASK_DOUBLE); break; case ANSWER_TYPE_RANGE: $type->setInputMask(INPUTMASK_INTEGER); break; default: $type->setInputMask(null); break; } } $type->save(); $checker = new Checker($_SESSION['SUID']); $checks = $checker->checkType($type); if (sizeof($checks) > 0) { $content .= $displaySysAdmin->displayError(implode("<br/>", $checks)); } } /* compile */ $compiler = new Compiler($_SESSION['SUID'], getSurveyVersion($survey)); $mess = $compiler->generateTypes(array($type)); $vars = $survey->getVariableDescriptivesOfType($tyd); $mess = $compiler->generateVariableDescriptives($vars); $mess = $compiler->generateGetFills($vars); $mess = $compiler->generateInlineFields($vars); /* update last page */ $_SESSION['LASTPAGE'] = substr($_SESSION['LASTPAGE'], 0, strripos($_SESSION['LASTPAGE'], "res")); if ($tyd != '') { return $displaySysAdmin->showEditType($_SESSION['TYD'], $content); } else { return $displaySysAdmin->showSurvey($content); } }
* * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ include "prepend.inc.php"; $Server = getData("Server", "integer"); $User = getData("User"); $Typename = getData("Typename"); $html = "<h1> Database " . $DB->Name($Server) . " - Type " . $Typename . "</h1>"; if ($Typename) { $type = new Type($Server); $type->setOwner($User); $type->setName($Typename); $type->getData(); $html .= "<table border=0><tr><th>Tag</th><th>Value</th></tr>"; $html .= "<tr><td>Name</td><td>" . $type->name . "</td></tr>"; $html .= "<tr><td>Owner</td><td>" . $type->owner . "</td></tr>"; $html .= "<tr><td>Created</td><td>" . $type->created . "</td></tr>"; $html .= "<tr><td>Last Modified</td><td>" . $type->lastmodified . "</td></tr>"; $html .= "<tr><td>Status</td><td>" . $type->status . "</td></tr>"; $html .= "</table>"; $html .= "<P><B>Type body:</b><br>"; $html .= nl2br($type->sql) . "<br>"; $html .= "</P>"; } $page = new Page("Type Properties"); $page->setHead(); $page->setBody();