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

코드정리

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