function close_op($args) { $opid = (int) $_POST['opid']; $targetcat = (int) $_POST['targetcat']; $amount = (int) $_POST['amount']; $account = (int) $_POST['account']; die(json_encode($this->model->CloseOp($opid, $targetcat, $amount, $account))); }
/** * Возвращает фин. цели * @return void */ public function initUserTargets() { $this->user_targets = array(); // Ежели нет пользователя - всё это не нужно. if (!$this->getId()) { return; } $this->user_targets = array(); $this->user_targets['user_targets'] = array(); $userTargets = $this->db->select("\n SELECT\n t.id, t.category_id as category,\n t.title,\n t.amount,\n DATE_FORMAT(t.date_begin,'%d.%m.%Y') as start,\n DATE_FORMAT(t.date_end,'%d.%m.%Y') as end,\n t.percent_done,\n t.forecast_done,\n t.visible,\n t.photo,\n t.url,\n t.comment,\n t.target_account_id AS account,\n t.amount_done,\n t.close,\n t.done,\n (SELECT b.money FROM target_bill b WHERE b.target_id = t.id ORDER BY b.dt_create ASC LIMIT 1) AS money\n FROM target t\n WHERE t.user_id = ?\n ORDER BY t.date_end ASC\n LIMIT ?d,?d;", $this->getId(), 0, 20); while (list(, $target) = each($userTargets)) { $this->user_targets['user_targets'][$target['id']] = $target; } unset($userTargets); if (!isset(Core::getInstance()->user)) { Core::getInstance()->user = $this; } $target = new Targets_Model(); $popTargets = $target->getPopList(); $this->user_targets['pop_targets'] = $popTargets['list']; }
/** * Редактирует событие * @param $args array mixed Какие-нибудь аргументы * @return void */ function edit(array $args = array()) { //тип редактируемой операции $operationId = 0; $operation = array(); if (array_key_exists(0, $args) && is_numeric($args[0]) && $args[0]) { $operationId = (int) $args[0]; } elseif (isset($this->request->post['id']) && $this->request->post['id']) { $operationId = $this->request->post['id']; } // Получаем данные по редактируемой операции (а если нет ид, то и даных фиг..) if ($operationId) { $operation = $this->model->getOperation(Core::getInstance()->user->getId(), $operationId); $initType = $operation['type']; } else { $operation = array(); } if (_Core_Request::getCurrent()->method == 'POST') { // Определяем массив данных для обработки $operation = array('id' => $operationId, 'type' => isset($this->request->post['type']) ? $this->request->post['type'] : $operation['type'], 'account' => $this->request->post['account'], 'amount' => $this->request->post['amount'], 'category' => isset($this->request->post['category']) ? $this->request->post['category'] : null, 'date' => null, 'comment' => isset($this->request->post['comment']) ? $this->request->post['comment'] : '', 'tags' => isset($this->request->post['tags']) ? $this->request->post['tags'] : $operation['tags'], 'convert' => isset($this->request->post['convert']) ? $this->request->post['convert'] : array(), 'close' => isset($this->request->post['close']) ? $this->request->post['close'] : array(), 'currency' => isset($this->request->post['currency']) ? $this->request->post['currency'] : array(), 'toAccount' => isset($this->request->post['toAccount']) ? $this->request->post['toAccount'] : null, 'target' => isset($this->request->post['target']) ? $this->request->post['target'] : null, 'accepted' => isset($this->request->post['accepted']) ? (int) $this->request->post['accepted'] : 1); // Если дата передана массивом (PDA) ... if (is_array($this->request->post['date'])) { $operation['date'] = $this->request->post['date']['day'] . '.' . $this->request->post['date']['month'] . '.' . $this->request->post['date']['year']; } elseif (empty($this->request->post['date'])) { $operation['date'] = date("d.m.Y"); } else { $operation['date'] = $this->request->post['date']; } $operation = $this->model->checkData($operation); if (is_null($operation['type'])) { $this->model->errorData['id'] = 'Не удалось изменить операцию'; } // Если нет ошибок - проводим операцию if (count($this->model->errorData) == 0) { //если изменили тип операции if ($operation['type'] != $initType) { if ($initType == Operation::TYPE_TARGET) { $this->model->deleteTargetOperation($operation['id']); } else { $this->model->deleteOperation($operation['id']); } //удалили операцию. вот теперь создадим новую switch ($operation['type']) { //Расход case Operation::TYPE_WASTE: $operation['amount'] = abs($operation['amount']) * -1; $this->model->add($operation['type'], $operation['amount'], $operation['date'], $operation['category'], $operation['comment'], $operation['account'], $operation['tags']); break; // Доход // Доход case Operation::TYPE_PROFIT: $this->model->add($operation['type'], $operation['amount'], $operation['date'], $operation['category'], $operation['comment'], $operation['account'], $operation['tags']); break; // Перевод со счёта // Перевод со счёта case Operation::TYPE_TRANSFER: $operation['category'] = -1; $this->model->addTransfer($operation['amount'], $operation['convert'], $operation['currency'], $operation['date'], $operation['account'], $operation['toAccount'], $operation['comment'], $operation['tags']); break; // Перевод на финансовую цель // Перевод на финансовую цель case Operation::TYPE_TARGET: $target = new Targets_Model(); $target->addTargetOperation($operation['account'], $operation['target'], $operation['amount'], $operation['comment'], $operation['date'], $operation['close']); //@FIXME Сделать автоматическое получение нового списка операций, при удачном добавлении //exit(json_encode($target->getLastList(0, 100))); break; } } // а иначе редактируем по старому, конкретную операцию switch ($operation['type']) { case Operation::TYPE_WASTE: //Расход $operation['amount'] = abs($operation['amount']) * -1; $this->model->edit($operation['type'], $operation['id'], $operation['amount'], $operation['date'], $operation['category'], $operation['comment'], $operation['account'], $operation['tags']); break; case Operation::TYPE_PROFIT: //Доход $operation['amount'] = abs($operation['amount']); $this->model->edit($operation['type'], $operation['id'], $operation['amount'], $operation['date'], $operation['category'], $operation['comment'], $operation['account'], $operation['tags']); break; case Operation::TYPE_TRANSFER: // Перевод со счёта $operation['category'] = null; $this->model->editTransfer($operation['id'], $operation['amount'], $operation['convert'], $operation['date'], $operation['account'], $operation['toAccount'], $operation['comment'], $operation['tags']); break; case Operation::TYPE_TARGET: // Перевод на финансовую цель см. в модуле фин.цели $target = new Targets_Model(); $target->editTargetOperation($operation['id'], $operation['amount'], $operation['date'], $operation['target'], $operation['account'], $operation['comment'], $operation['close']); break; } // #856. fixed by Jet. выводим разные сообщения для обычной и PDA версии $text = ''; if (_Core_TemplateEngine::getResponseMode($this->request) == "json") { $text = "Операция успешно изменена."; } else { $text = "Операция успешно изменена. <a href='/operation/last'>последние операции</a>"; } $this->tpl->assign('result', array('text' => $text)); } else { $this->tpl->assign('error', array('text' => implode(" \n", $this->model->errorData))); } } // Переделываем дату изменённую в checkData для вставки в mysql обратно в человеческий вид $operation['date'] = date('d.m.Y', strtotime($operation['date'])); $this->tpl->assign('operation', $operation); $this->tpl->assign('name_page', 'operations/edit'); }
/** * Удаляет операцию перевода на финцель * @param int $id * @return bool */ function deleteTargetOperation($id = 0) { $tr_id = $this->db->select("SELECT target_id FROM target_bill WHERE id=?", $id); $this->db->query("DELETE FROM target_bill WHERE id=? AND user_id=?", $id, $this->_user->getId()); $targ = new Targets_Model(); $targ->staticTargetUpdate($tr_id[0]['target_id']); $this->_user->initUserTargets(); $this->_user->save(); return true; }
/** * Удалить счёт * * @param oldUser $user * @param array $param */ public function delete(oldUser $user, $param) { $fin = new Targets_Model(); $noFinTarget = $fin->countTargetsOnAccount($param['id']); // если ноль значит удаляем if ($noFinTarget > 0) { return 'cel'; } return Account_Model::delete($user->getId(), $param['id']); }