Commit 822a6710 authored by Choi Ga Young's avatar Choi Ga Young
Browse files

코드정리

parent d513a4bd
import React, { useState, useEffect } from 'react';
import { useFocusEffect } from '@react-navigation/native';
import ChartM from './ChartM';
import ChartY from './ChartY';
import chartApi from './db/chartData.api';
import ButtonsForm from './components/ButtonsForm';
import { View, Dimensions } from 'react-native';
import { View } from 'react-native';
const Analy = () => {
const date = new Date();
const [year, setYear] = useState(date.getFullYear());
const [month, setMonth] = useState(date.getMonth());
const [resDataM, setResDataM] = useState([]);
const [resDataY, setResDataY] = useState([]);
const [selectedIndex, setSelectedIndex] = useState(0);
const todayM = date.getMonth();
const todayY = date.getFullYear();
const getDataM = async () => {
try {
const resdata = await chartApi.outMoney({ year: year, month: month })
console.log('db res M', resdata)
return resdata
} catch (error) {
console.log('error in getDataM', error)
......@@ -25,7 +28,6 @@ const Analy = () => {
const getDataY = async () => {
try {
const resdata = await chartApi.yearMoney({ year: year })
console.log('db res Y', resdata)
setResDataY(resdata)
} catch (error) {
......@@ -35,7 +37,6 @@ const Analy = () => {
const calPercentage = async () => {
const resPrice = await getDataM()
//console.log('어떻게 생겼니', resPrice)
let totalP = 0;
for (let i = 0; i < resPrice.length; i++) {
......@@ -47,10 +48,15 @@ const Analy = () => {
setResDataM(resPrice)
}
useEffect(() => {
getDataY()
calPercentage()
}, [])
useFocusEffect(
React.useCallback(() => {
setMonth(todayM)
setYear(todayY)
getDataY()
calPercentage()
}, [])
);
useEffect(() => {
setResDataM([])
calPercentage()
......@@ -59,11 +65,12 @@ const Analy = () => {
useEffect(() => {
getDataY()
}, [year])
return (
<>
<View>
<ButtonsForm
onPress={(index) => setSelectedIndex(index)}
onPress={(index) => { setSelectedIndex(index), setYear(todayY) }}
selectedIndex={selectedIndex}
group={["월간", "연간"]} />
</View>
......
import React, { useEffect, useState } from 'react';
import { SafeAreaView, View, Text, StyleSheet, FlatList } from 'react-native';
import calApi from './db/calendarInfo.api';
const DetailItem = ({ item }) => {
return (
......@@ -12,20 +11,17 @@ const DetailItem = ({ item }) => {
}}>
<Text style={[style.itemText, item.type === 1 ? style.inputColor : style.outputColor]}>{item.category}</Text>
<Text style={[style.itemTextNum, style.Font]}>{item.contents}</Text>
<Text style={[style.itemTextNum, style.Font]}>{item.price}</Text>
<Text style={[style.itemTextNum, style.Font]}>{(item.price).toLocaleString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")}</Text>
</View>
</>
);
};
const DetailInfo = ({ route }) => {
console.log('route', route.params)
console.log('---------------------------')
const [resData, setResData] = useState([])
const getDetailData = async () => {
try {
const resdata = await calApi.detailData({ findDate: route.params })
console.log('resdata', resdata)
setResData(resdata)
} catch (error) {
console.log('error in getDetailData', error)
......@@ -43,14 +39,14 @@ const DetailInfo = ({ route }) => {
<>
<SafeAreaView>
{
resData.length != 0 ? <FlatList
resData.length !== 0 ? <FlatList
data={resData}
renderItem={renderDetail}
keyExtractor={item => item.id}
/> : <View style={{ marginTop: "20%" }}>
/> : <View style={{ margin: "20%" }}>
<Text style={{ textAlign: "center", fontSize: 20, fontFamily: 'GowunDodum-Regular' }}>내역이 없습니다.</Text>
</View>
}
}
</SafeAreaView>
</>
)
......
import React, { useState, useEffect } from 'react';
import React from 'react';
import { FlatList, View, Text, StyleSheet, Dimensions } from 'react-native';
import { Button } from 'react-native-elements';
import Ionicons from 'react-native-vector-icons/Ionicons';
......@@ -15,9 +15,8 @@ const ChartItem = ({ item }) => {
borderWidth: 1, borderTopWidth: 0,
}}>
<Text style={[style.itemText, style.Font]}>{item.name}</Text>
<Text style={[style.itemTextNum, style.Font]}>{item.total}</Text>
<Text style={[style.itemTextNum, style.Font]}>{(item.total).toLocaleString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")}</Text>
<Text style={[style.itemTextNum, style.Font]}>{item.percentage}%</Text>
<Text></Text>
</View>
</>
);
......@@ -31,18 +30,15 @@ const ChartM = ({
setMonth
}) => {
const chartConfig = {
backgroundGradientFrom: "#abbcd6", //좌측 색
backgroundGradientFrom: "#abbcd6",
backgroundGradientFromOpacity: 0.5,
backgroundGradientTo: "#E6DDC5", // 우측 색
backgroundGradientTo: "#E6DDC5",
backgroundGradientToOpacity: 0.2,
backgroundColor: "#ffffff", // 어디에 적용된건지 잘 모르겠음
color: (opacity = 1) => `rgba(0, 93, 232, ${opacity})`, // data의 색상 계산할 때 사용하는 함수
//color: (opacity = 1) => `rgba(255, 255, 255, ${opacity})`,
color: (opacity = 1) => `rgba(0, 93, 232, ${opacity})`,
strokeWidth: 2, // optional, default 3
barPercentage: 0.5, // 그래프 width
useShadowColorFromDataset: false,// optional, default is false
//fillShadowGradient: 'blue',
fillShadowGradientOpacity: 1, // 좀 더 진하게만 할 뿐 단색 설정은 못하는 것 같음
fillShadowGradientOpacity: 1,
};
......@@ -67,8 +63,6 @@ const ChartM = ({
setMonth(month + 1)
}
}
console.log('sdfaslfsakflf', resDataM)
return (
<>
<View style={{ flexDirection: 'row' }}>
......@@ -82,11 +76,11 @@ const ChartM = ({
</View>
<View>
{
resDataM.length != 0 ?
resDataM.length !== 0 ?
< PieChart
data={resDataM}
width={screenWidth}
height={screenHeight / 3} //그래프의 높이가 커지기만
height={screenHeight / 3}
chartConfig={chartConfig}
accessor={"total"}
backgroundColor={"#ffffff"}
......
......@@ -10,9 +10,9 @@ const screenHeight = Dimensions.get("window").height;
const ChartY = ({ resDataY, year, setYear }) => {
const chartConfig = {
backgroundGradientFrom: "#ffffff", //좌측 색
backgroundGradientFrom: "#ffffff",
backgroundGradientFromOpacity: 1,
backgroundGradientTo: "#ffffff", // 우측 색
backgroundGradientTo: "#ffffff",
backgroundGradientToOpacity: 1,
color: (opacity = 1) => `rgba(48, 48, 48, ${opacity})`,
strokeWidth: 2, // optional, default 3
......
import React, { useState, useEffect } from 'react';
import { StyleSheet, Text, View, FlatList, TouchableOpacity, Modal, Alert, TouchableWithoutFeedback, Keyboard } from 'react-native';
import { StyleSheet, View, FlatList, TouchableOpacity, Modal, TouchableWithoutFeedback, Keyboard } from 'react-native';
import TodoItem from './components/TodoItem';
import Ionicons from 'react-native-vector-icons/Ionicons';
import ButtonsForm from './components/ButtonsForm';
......@@ -8,12 +8,12 @@ import { TabView } from 'react-native-elements';
import deptApi from './db/deptPage.api';
function DeptPage({ navigation }) {
const [lend, setLend] = useState([]) //빌려준
const [dept, setDept] = useState([]) //빌린
const [lend, setLend] = useState([])
const [dept, setDept] = useState([])
const [selectedIndex, setSelectedIndex] = useState(0)
const [modallOpen, setModallOpen] = useState(false);
const loadLend = async () => { //빌려준
const loadLend = async () => {
try {
const deptArray = await deptApi.selectLoan("빌려준금액")
......@@ -23,7 +23,7 @@ function DeptPage({ navigation }) {
}
}
const loadDept = async () => { //빌림
const loadDept = async () => {
try {
const deptArray = await deptApi.selectLoan("빌린금액")
setDept(deptArray);
......@@ -44,7 +44,7 @@ function DeptPage({ navigation }) {
info['loan'] = "빌려준금액"
}
await deptApi.insertDept(info)
setModallOpen(false); //modal이 보여지지 않게
setModallOpen(false);
loadLoan()
}
......@@ -53,12 +53,10 @@ function DeptPage({ navigation }) {
loadLoan()
}
useEffect(() => { //처음 화면에 띄어지는거
useEffect(() => {
loadLoan()
}, [])
console.log(selectedIndex)
return (
<TouchableWithoutFeedback onPress={() => {
Keyboard.dismiss();
......@@ -133,14 +131,14 @@ const style = StyleSheet.create({
},
modalToggle: {
borderWidth: 1,
borderColor: 'gray', //gray
borderColor: 'gray',
padding: 5,
borderRadius: 10,
alignSelf: 'center', //위치를 center로
alignSelf: 'center',
},
modalContent: {
flex: 1, //이후 유용한 키보드를 추가하려고 ex)dismissing keyboard
flex: 1,
}
});
......
......@@ -10,7 +10,6 @@ const INIT_OPTION = { id: 0, value: '' }
const INIT_SUBOPTION = { id: 0, value: '', foreign_id: 0 }
const EditOption = ({ route }) => {
console.log('catEdit: type_id ', route.params)
const type = route.params ? 'category' : 'asset'
const type_id = route.params
......@@ -20,8 +19,8 @@ const EditOption = ({ route }) => {
const [modalOpen, setModalOpen] = useState(false)
const modalClose = () => { setModalOpen(false); setOption(INIT_OPTION) }
const [error, setError] = useState("");
const [loading, setLoading] = useState(false);
// const [error, setError] = useState("");
// const [loading, setLoading] = useState(false);
useEffect(() => {
loadOptions()
......@@ -66,14 +65,12 @@ const EditOption = ({ route }) => {
try {
if (type === 'asset') {
const res = await editApi.deleteOption('assets_type', { id: item.id, name: 'assets' })
console.log(res)
} else if (type === 'category') {
if (item.foreign_id && item.foreign_id > 0) {
const res = await editApi.deleteOption('subcategories', { id: item.id, name: 'subcategory'})
return console.log(res)
}
const res = await editApi.deleteOption('categories', { id: item.id, name: 'category' })
console.log(res)
}
} catch (error) {
......@@ -86,14 +83,12 @@ const EditOption = ({ route }) => {
try {
if (type === 'asset') {
const res = await editApi.addOption('assets_type', { name: 'assets', value: option.value })
console.log(res)
} else if (type === 'category') {
if (option.foreign_id && option.foreign_id > 0) {
const res = await editApi.addOption('subcategories', { name: 'subcategory', value: option.value, foreign_name: 'category', foreign_id: option.foreign_id })
return console.log(res)
}
const res = await editApi.addOption('categories', { name: 'category', value: option.value, foreign_name: 'type', foreign_id: type_id })
console.log(res)
}
} catch (error) {
......@@ -154,7 +149,6 @@ const EditOption = ({ route }) => {
return (
<>
{console.log(option)}
<View>
<FlatList
data={options}
......
import { DEBUG, enablePromise, openDatabase } from 'react-native-sqlite-storage';
import { SafeAreaView, StyleSheet, Text, View, TextInput, FlatList, Button } from 'react-native';
import React, { useEffect, useState } from 'react';
import { SafeAreaView, StyleSheet, Text, View, TextInput, Button } from 'react-native';
import React, { useState } from 'react';
DEBUG(true);
enablePromise(true);
......@@ -8,7 +8,7 @@ enablePromise(true);
const db = openDatabase({
name: 'MyMoney',
location: 'default',
createFromLocation: '~MyMoney.db', // android/src/main/assets/TestDB.db 파일을 위치 시킴
createFromLocation: '~MyMoney.db',
});
const QueryFunc = async (Query) => {
......@@ -22,7 +22,7 @@ function InsertCat() {
console.log('money db')
const populateDatabase = async DB => {
await DB.transaction(queryMoney); // 반드시 (await db)를 해야 프라미스가 성공
await DB.transaction(queryMoney);
};
const loadAndQueryDB = async () => {
......@@ -36,7 +36,6 @@ function InsertCat() {
const insertCategory = async () => {
QueryFunc(async (tx) => {
console.log("카테고리 정보 저장");
await tx.executeSql('INSERT INTO categories (category_name) VALUES (?);',
[cat],
() => { console.log("카테고리 삽입 성공"); },
......@@ -46,7 +45,6 @@ function InsertCat() {
const insertAsset = async () => {
QueryFunc(async (tx) => {
console.log("자산 정보 저장");
await tx.executeSql('INSERT INTO assets_type (assets_name) VALUES (?);',
[asset],
() => { console.log("자산 삽입 성공"); },
......
......@@ -8,9 +8,6 @@ import DeptPage from './DeptPage';
function MainScreen({ navigation }) {
const [number, onChangeNumber] = useState(null);
const [modalOpen, setModalOpen] = useState(false);
// const [reviews, setReviews] = useState([
// { title: 'aa', rating: 5, body: 'bb', key: '1' },
// ]);
const [open, setOpen] = useState(false)
return (
......@@ -38,8 +35,8 @@ function MainScreen({ navigation }) {
/>
<SpeedDial
isOpen={open}
icon={{ name: 'edit', color: '#fff' }} //연필모양
openIcon={{ name: 'close', color: '#fff' }} //x모양
icon={{ name: 'edit', color: '#fff' }}
openIcon={{ name: 'close', color: '#fff' }}
onOpen={() => setOpen(!open)}
onClose={() => setOpen(!open)}
>
......@@ -61,7 +58,7 @@ function MainScreen({ navigation }) {
name='close'
color='red'
size={24}
style={{ ...style.modalToggle, ...style.modalClose }} //...은 중괄호를 풀어서 합치려고 이용함
style={{ ...style.modalToggle, ...style.modalClose }}
onPress={() => setModalOpen(false)}
/>
<DeptPage />
......
......@@ -12,7 +12,6 @@ function MemoPage({ navigation }) {
const loadMemos = async () => {
try {
const memoArray = await memoApi.selectMemo()
console.log('memoload', memoArray)
setMemos(memoArray);
} catch (error) {
console.log('error in load memos ( MemoPage.js )', error)
......@@ -38,7 +37,7 @@ function MemoPage({ navigation }) {
<TouchableWithoutFeedback onPress={() => {
Keyboard.dismiss();
}}>
<View Style={style.container}>
<View Style={style.container}>
<View style={{ width: '100%', height: '95%' }} >
<View style={{ width: '100%', height: '80%' }}>
<View >
......@@ -77,11 +76,6 @@ function MemoPage({ navigation }) {
);
}
const style = StyleSheet.create({
container: {
flex: 1,
......@@ -89,10 +83,10 @@ const style = StyleSheet.create({
},
modalToggle: {
borderWidth: 1,
borderColor: 'gray', //gray
borderColor: 'gray',
padding: 5,
borderRadius: 10,
alignSelf: 'center', //위치를 center로
alignSelf: 'center',
},
modalContent: {
......
......@@ -13,7 +13,6 @@ const Montly = ({ navigation }) => {
const getData = async () => {
try {
const resDBdata = await calApi.getFullData({ year: year, month: month })
console.log('db res', totalM)
setTotalM(resDBdata)
} catch (error) {
console.log('error in getData', error)
......
import React, { useState, useEffect } from 'react';
import { View, Text, StyleSheet, Button } from 'react-native';
import { View, StyleSheet} from 'react-native';
import InputBox from './components/InputBox';
import ButtonsForm from './components/ButtonsForm';
import SelectForm from './components/SelectForm';
......@@ -47,7 +47,7 @@ const PostMoney = ({ navigation }) => {
}, [selectedIndex])
const initData = () => {
setDate(getDate())
setDate(getDateStr())
setContents('')
setPrice('')
setSelected_asset_type(INIT_ASSETSTYPE)
......@@ -83,7 +83,6 @@ const PostMoney = ({ navigation }) => {
const loadCat = async () => {
try {
const catArray = await moneyApi.selectCategories(selectedIndex + 1)
console.log('catload', catArray)
setCategories(catArray);
} catch (error) {
console.log('error in load categories ( postMoney.js )', error)
......@@ -93,7 +92,6 @@ const PostMoney = ({ navigation }) => {
const loadSubCat = async () => {
try {
const subCatArray = await moneyApi.selectSubCategories()
console.log('catload', subCatArray)
setSubcategories(subCatArray);
} catch (error) {
console.log('error in load categories ( postMoney.js )', error)
......@@ -119,7 +117,6 @@ const PostMoney = ({ navigation }) => {
if (success) {
initData()
setSuccess(false)
}
......
......@@ -34,11 +34,6 @@ const style = StyleSheet.create({
alignItems: "center",
backgroundColor: '#f5f5f5'
},
// text: {
// color: "#808080",
// fontSize: 24,
// fontFamily: 'GowunDodum-Regular'
// },
selectedButton: {
backgroundColor: '#bfd3f2'
},
......
......@@ -19,24 +19,6 @@ const DateItem = ({ dateitem, textColor, onPress, flatListHeight }) => {
</TouchableOpacity>
);
};
const INIT_Data = [
{
date: "2021-06-28",
type: { 'input': 10000, 'output': 1000 },
},
{
date: "2021-07-01",
type: { 'input': 50000, 'output': 3500 },
},
{
date: "2021-07-11",
type: { 'input': 100000, 'output': 2000 },
},
{
date: "2021-08-14",
type: { 'input': 15000, 'output': 2010 },
},
];
function Calendar({
navigation,
......@@ -48,28 +30,26 @@ function Calendar({
todayM,
todayY,
}) {
//console.log('MData', MData)
const date = new Date();
const [flatListHeight, setFlatListHeight] = useState(400)
const prevLast = new Date(year, month, 0); //이전 달의 마지막 날
const thisFirst = new Date(year, month, 1); //이번 달의 첫째 날
const thisLast = new Date(year, month + 1, 0); //이번 달의 마지막 날
const prevLast = new Date(year, month, 0);
const thisFirst = new Date(year, month, 1);
const thisLast = new Date(year, month + 1, 0);
const thisFirstDay = thisFirst.getDay(); //이번 달 첫번 째 요일
const prevLastDate = prevLast.getDate(); //이전 달 마지막 날짜
const thisLastDate = thisLast.getDate(); //이번 달 마지막 날짜
const thisLastDay = thisLast.getDay(); //이번 달 마지막 요일
const thisFirstDay = thisFirst.getDay();
const prevLastDate = prevLast.getDate();
const thisLastDate = thisLast.getDate();
const thisLastDay = thisLast.getDay();
// 이번 달 달력에 쓰일 날짜들. 이전달 다음달 전부 포함
const Dates = [];
const DBDates = [];
if (thisFirstDay !== 0) { // 첫째 날이 일요일이 아니라면
if (thisFirstDay !== 0) {
for (let i = 0; i < thisFirstDay; i++) {
Dates.unshift({ date: new Date(year, month - 1, prevLastDate - i) })
}
}
for (let i = 1; i <= thisLastDate; i++) { //이번 달 날짜
for (let i = 1; i <= thisLastDate; i++) {
Dates.push({ date: new Date(year, month, i) })
}
for (let i = 1; i <= 6 - thisLastDay; i++) {
......
import React, { useState } from "react";
import { Button, View, Text, StyleSheet, Pressable } from "react-native";
import { View, Text, StyleSheet, Pressable } from "react-native";
import DateTimePickerModal from "react-native-modal-datetime-picker";
import { getDateStr } from '../utils/dateFunction';
......
......@@ -61,7 +61,7 @@ const SelectForm = ({
modalClose()
} else {
newOption.unshift({id: 1, value: '기타'})
if (newOption.length % 3 == 0) {
if (newOption.length % 3 == 0) { //여기 ===해야하지않나?
setSubOption(newOption)
setSubOptionShow(true)
} else {
......
import React from 'react';
import { StyleSheet, Pressable, Text, View } from 'react-native';
import { StyleSheet, Pressable, Text } from 'react-native';
const StyledButton = (props) => {
return (
......
import React, { Component } from 'react';
import { View, Text, Button, StyleSheet } from 'react-native';
import React from 'react';
import { View, StyleSheet } from 'react-native';
import CalendarStrip from 'react-native-calendar-strip';
// import moment from 'moment';
const WeeklyCalendar = (props) => {
return (
<View>
<CalendarStrip
......
import React from 'react';
import { StyleSheet, Text, TouchableOpacity, View } from 'react-native';
import { StyleSheet, Text, View } from 'react-native';
import Ionicons from 'react-native-vector-icons/Ionicons';
function TodoItem({ item, onDeleteHandle }) {
return (
<View style={styles.item}>
......@@ -22,12 +20,12 @@ const styles = StyleSheet.create({
item: {
padding: 16,
marginTop: 16,
borderColor: '#bbb', //light grey
borderColor: '#bbb',
borderWidth: 1,
borderStyle: 'd',
borderStyle: 'dashed', //little line
borderStyle: 'dashed',
borderRadius: 10,
flexDirection: 'row' //같은 행에 있도록
flexDirection: 'row'
},
itemText: {
fontFamily: 'GowunDodum-Regular',
......
import { DEBUG, enablePromise } from 'react-native-sqlite-storage';
import getDb from './moneyDB'
import { getDateStr } from '../utils/dateFunction';
DEBUG(true);
enablePromise(true);
const getFullData = async ({ year, month }) => {
const thisFirst = new Date(year, month, 1); //이번 달의 첫째 날
const thisLast = new Date(year, month + 1, 0); //이번 달의 마지막 날
const thisFirst = new Date(year, month, 1);
const thisLast = new Date(year, month + 1, 0);
const db = await getDb();
return new Promise((res, rej) => {
db.transaction(async (tx) => {
console.log('월간 데이터');
const [txn, results] = await tx.executeSql(`SELECT date, type_id, sum(price) as total from money where date BETWEEN "${String(thisFirst.toJSON()).split(/T/)[0]}" and "${String(thisLast.toJSON()).split(/T/)[0]}" group by date, type_id`);
const [txn, results] = await tx.executeSql(`SELECT date, type_id, sum(price) as total from money where date BETWEEN "${getDateStr(thisFirst)}" and "${getDateStr(thisLast)}" group by date, type_id`);
const temp = [];
console.log('lelel', results.rows.length)
if (results.rows.length != 0) {
if (results.rows.item(0).type_id === 1) {
temp.push({ date: results.rows.item(0).date, type: { 'input': results.rows.item(0).total } })
......@@ -41,25 +40,20 @@ const getFullData = async ({ year, month }) => {
}
}
}
console.log('결과 확인', temp)
res(temp)
})
})
}
const detailData = async ({ findDate }) => {
console.log('findData', findDate)
const db = await getDb();
return new Promise((res, rej) => {
db.transaction(async (tx) => {
console.log('월간 세부 데이터');
const [txn, results] = await tx.executeSql(`SELECT money.type_id, category_name, contents, price FROM money inner JOIN categories on money.category_id = categories.category_id WHERE date="${findDate}"`);
const temp = [];
for (let i = 0; i < results.rows.length; i++) {
console.log('item check', results.rows.item(i));
temp.push({ id: i, category: results.rows.item(i).category_name, contents: results.rows.item(i).contents, price: results.rows.item(i).price, type: results.rows.item(i).type_id })
}
//console.log('temp', temp)
res(temp);
})
})
......
import { DEBUG, enablePromise } from 'react-native-sqlite-storage';
import getDb from './moneyDB'
import { getDate } from '../utils/dateFunction'
import { getDateStr } from '../utils/dateFunction'
DEBUG(true);
enablePromise(true);
......@@ -13,25 +13,21 @@ const colorArr = [
]
const outMoney = async ({ year, month }) => {
const thisFirst = new Date(year, month, 1); //이번 달의 첫째 날
const thisLast = new Date(year, month + 1, 0); //이번 달의 마지막 날
const thisFirst = new Date(year, month, 1);
const thisLast = new Date(year, month + 1, 0);
const db = await getDb();
return new Promise((res, rej) => {
db.transaction(async (tx) => {
console.log('차트 페이지');
const [txn, results] = await tx.executeSql(`SELECT category_id, category_name, sum(price) as total from (SELECT money.type_id, price, money.category_id, category_name FROM money inner JOIN categories on money.category_id = categories.category_id where date BETWEEN "${getDate(thisFirst)}" and "${getDate(thisLast)}") WHERE type_id=2 group by category_id`);
const [txn, results] = await tx.executeSql(`SELECT category_id, category_name, sum(price) as total from (SELECT money.type_id, price, money.category_id, category_name FROM money inner JOIN categories on money.category_id = categories.category_id where date BETWEEN "${getDateStr(thisFirst)}" and "${getDateStr(thisLast)}") WHERE type_id=2 group by category_id`);
const temp = [];
for (let i = 0; i < results.rows.length; i++) {
console.log('chart', results.rows.item(i))
temp.push({
name: results.rows.item(i).category_name,
total: results.rows.item(i).total,
color: colorArr[i], legendFontColor: "#7F7F7F",
legendFontSize: 15
})
console.log('chart temp', temp)
res(temp)
}
})
......@@ -39,13 +35,12 @@ const outMoney = async ({ year, month }) => {
}
const yearMoney = async ({ year }) => {
const yearFirst = new Date(year, 0, 1); //1월 1일
const yearLast = new Date(year, 12, 0); //12월 31일
const yearFirst = new Date(year, 0, 1);
const yearLast = new Date(year, 12, 0);
const db = await getDb();
console.log('year', yearFirst, '|', yearLast)
return new Promise((res, rej) => {
db.transaction(async (tx) => {
console.log('차트페이지 연간')
const [txn, results] = await tx.executeSql(`SELECT strftime('%m',date) as month, type_id, sum(price) as total from money where strftime('%Y', date)= "${year}" GROUP by strftime('%m', date), type_id `);
const temp1 = [];
const temp2 = [];
......@@ -53,7 +48,6 @@ const yearMoney = async ({ year }) => {
let temparr2 = new Array(12).fill(0)
for (let i = 0; i < results.rows.length; i++) {
console.log('year res check', results.rows.item(i))
if (results.rows.item(i).type_id === 1) {
let idx = Number(results.rows.item(i).month)
temparr1[idx - 1] = results.rows.item(i).total
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment