/** * 删除账目 */ function delete_bill() { $billTypeFlag = (int) $_REQUEST['billTypeFlag']; $billId = (int) $_REQUEST['billId']; $code = '0'; $billService = new BillService(); switch ($billTypeFlag) { case 0: case 1: $billService->deleteNormalBill($billId, $billTypeFlag); break; case 2: case 3: $billService->deleteTransferBill($billId, $billTypeFlag); break; case 5: case 6: $billService->deleteDebtBill($billId, $billTypeFlag); break; case 4: case 7: $billService->deleteRepayBill($billId, $billTypeFlag); break; } $output = array('retCode' => $code); echo get_json($output); }
/** * 收支趋势基础数据初始化 */ function init_trend_statistic_data() { $userId = (int) $_SESSION['userId']; $code = '0'; // 获取首次记账年份,生成年份列表 $billService = new BillService(); $firstBillTime = $billService->getFirstBillTime($userId); $yearList = array(); if ($firstBillTime != null) { $firstYear = (int) date('Y', $firstBillTime); $nowYear = (int) date('Y'); if ($firstYear > $nowYear) { for ($i = $firstYear; $i <= $nowYear; $i++) { $yearList[] = array('yearVal' => (string) $i, 'yearStr' => (string) $i); } } } else { $yearList[] = array('yearVal' => date('Y'), 'yearStr' => date('Y')); } // 加载账户列表 $accountService = new AccountService(); $accountList = $accountService->getAccountSimpleList($userId, null); // 加载收支类别列表 $billTypeService = new BillTypeService(); $billTypeList = $billTypeService->getBillTypeSimpleList($userId, null); $output = array('retCode' => $code, 'yearList' => $yearList, 'accountList' => $accountList, 'billTypeList' => $billTypeList); echo get_json($output); }
/** * 删除账户 */ function delete_account() { $userId = $_SESSION['userId']; $accountId = $_REQUEST['accountId']; $accountTypeFlag = $_REQUEST['accountTypeFlag']; $code = '0'; // 校验该用户下的账户数 $accountService = new AccountService(); $accountCount = $accountService->countAccount($userId, $accountTypeFlag); if ($accountCount == 1) { // 只剩一组帐户不能再删除 $code = 'mustHaveAccount'; } else { $billService = new BillService(); //校验账户下是否有记账 if ($billService->countBill(null, $accountId, null) > 0 || $billService->countBillDebtRelated($accountId) > 0) { $code = 'existBillInAccount'; } else { $accountDefault = get_user_config('accountDefault'); if ($accountId == $accountDefault) { //如果删除的是默认账户 //取按照accountId排序最小的账户作为默认 $minId = $accountService->getMinAccountId($userId); set_user_config('accountDefault', $minId); //更新到用户表 $userService = new UserService(); $userService->updateConfig($userId, $_SESSION['userDetail']['user_config']); } $accountService->deleteAccount($accountId); } } $output = array('retCode' => $code); echo get_json($output); }
/** * 删除收支类别 */ function delete_bill_type() { $billTypeId = $_REQUEST['billTypeId']; $code = '0'; $billService = new BillService(); // 校验类别下是否有记账 if ($billService->countBill(null, null, $billTypeId) > 0) { $code = 'existBillInBillType'; } else { $billTypeService = new BillTypeService(); $billTypeService->deleteBillType($billTypeId); } $output = array('retCode' => $code); echo get_json($output); }