Esempio n. 1
0
 public static function process($action = 'list', $id = null, $filters = array())
 {
     $node = isset($_SESSION['admin_node']) ? $_SESSION['admin_node'] : \GOTEO_NODE;
     // métodos de pago
     $methods = Model\Invest::methods();
     // estados del proyecto
     $status = Model\Project::status();
     // estados de aporte
     $investStatus = Model\Invest::status();
     // listado de proyectos
     $projects = Model\Invest::projects(false, $node);
     // usuarios cofinanciadores
     $users = Model\Invest::users(true);
     // campañas que tienen aportes
     $calls = Model\Invest::calls();
     // extras
     $types = array('donative' => 'Solo los donativos', 'anonymous' => 'Solo los anónimos', 'manual' => 'Solo los manuales', 'campaign' => 'Solo con riego');
     if ($action == 'csv') {
         $invest = Model\Invest::getPreapproval($id);
         foreach ($invest as $value) {
             $csv[] = array($value->id, $value->amount);
         }
         $fileName = "axes_" . date("YmdHis") . ".csv";
         header("Content-Disposition: attachment; filename=\"{$filename}\"");
         header("Content-type: application/octet-stream");
         header("Pragma: no-cache");
         header("Expires: 0");
         $fp = fopen('php://output', 'w');
         foreach ($csv as $fields) {
             fputcsv($fp, $fields);
         }
         fclose($fp);
         exit;
     }
     if ($action == 'dopay') {
         $query = \Goteo\Core\Model::query("\n                    SELECT  *\n                    FROM  invest\n                    WHERE   invest.project = ?\n                    AND     (invest.status = 0\n                        OR (invest.method = 'tpv'\n                            AND invest.status = 1\n                        )\n                        OR (invest.method = 'cash'\n                            AND invest.status = 1\n                        )\n                    )\n                    AND (invest.campaign IS NULL OR invest.campaign = 0)\n                    ", array($id));
         $invests = $query->fetchAll(\PDO::FETCH_CLASS, '\\Goteo\\Model\\Invest');
         foreach ($invests as $key => $invest) {
             if ($invest->setPayment(date("YmdHis"))) {
                 $invest->setStatus(1);
                 Model\Invest::setDetail($invest->id, 'executed', 'Preapproval has been executed, has initiated the chained payment. Process cron / execute');
                 if ($invest->issue) {
                     Model\Invest::unsetIssue($invest->id);
                     Model\Invest::setDetail($invest->id, 'issue-solved', 'The incidence has been resolved upon success by the automatic process');
                 }
             }
         }
         Message::Info("処理しました");
         throw new Redirection('/admin/projects/list');
         exit;
     }
     // detalles del aporte
     if ($action == 'details') {
         $invest = Model\Invest::get($id);
         $project = Model\Project::get($invest->project);
         $userData = Model\User::get($invest->user);
         if (!empty($invest->droped)) {
             $droped = Model\Invest::get($invest->droped);
         } else {
             $droped = null;
         }
         if ($project->node != $node) {
             throw new Redirection('/admin/invests');
         }
         return new View('view/admin/index.html.php', array('folder' => 'invests', 'file' => 'details', 'invest' => $invest, 'project' => $project, 'user' => $userData, 'status' => $status, 'investStatus' => $investStatus, 'droped' => $droped, 'calls' => $calls));
     }
     // listado de aportes
     if ($filters['filtered'] == 'yes') {
         if (!empty($filters['calls'])) {
             $filters['types'] = '';
         }
         $list = Model\Invest::getList($filters, $node, 999);
     } else {
         $list = array();
     }
     $viewData = array('folder' => 'invests', 'file' => 'list', 'list' => $list, 'filters' => $filters, 'projects' => $projects, 'users' => $users, 'calls' => $calls, 'methods' => $methods, 'types' => $types, 'investStatus' => $investStatus);
     return new View('view/admin/index.html.php', $viewData);
 }