Commit d4207d12 authored by Soo Hyun Kim's avatar Soo Hyun Kim
Browse files

0804 select form 머지 전 푸쉬

parent 45a9945d
...@@ -9,17 +9,17 @@ import moneyApi from './db/postMoney.api'; ...@@ -9,17 +9,17 @@ import moneyApi from './db/postMoney.api';
import { getDate } from './utils/dateFunction' import { getDate } from './utils/dateFunction'
const INIT_ASSETSTYPE = { const INIT_ASSETSTYPE = {
id: 0, id: 1,
value: '', value: '',
} }
const INIT_CATEGORY = { const INIT_CATEGORY = {
id: 0, id: 1,
value: '', value: '',
} }
const INIT_SUBCATEGORY = { const INIT_SUBCATEGORY = {
id: 0, id: 1,
value: '', value: '',
foreign_id: 0, foreign_id: 0,
} }
...@@ -28,7 +28,7 @@ const PostMoney = ({navigation}) => { ...@@ -28,7 +28,7 @@ const PostMoney = ({navigation}) => {
const [selectedIndex, setSelectedIndex] = useState(0) const [selectedIndex, setSelectedIndex] = useState(0)
const [date, setDate] = useState(getDate()) const [date, setDate] = useState(getDate())
const [contents, setContents] = useState('') const [contents, setContents] = useState('')
const [price, setPrice] = useState(0) const [price, setPrice] = useState('')
const [asset_type, setAsset_type] = useState([]) const [asset_type, setAsset_type] = useState([])
const [selected_asset_type, setSelected_asset_type] = useState(INIT_ASSETSTYPE) const [selected_asset_type, setSelected_asset_type] = useState(INIT_ASSETSTYPE)
const [selected_deposit_asset_type, setSelected_deposit_asset_type] = useState(INIT_ASSETSTYPE) const [selected_deposit_asset_type, setSelected_deposit_asset_type] = useState(INIT_ASSETSTYPE)
...@@ -36,6 +36,8 @@ const PostMoney = ({navigation}) => { ...@@ -36,6 +36,8 @@ const PostMoney = ({navigation}) => {
const [selected_cat, setSelected_cat] = useState(INIT_CATEGORY) const [selected_cat, setSelected_cat] = useState(INIT_CATEGORY)
const [subcategories, setSubcategories] = useState([]) const [subcategories, setSubcategories] = useState([])
const [selected_subcat, setSelected_subcat] = useState(INIT_SUBCATEGORY) const [selected_subcat, setSelected_subcat] = useState(INIT_SUBCATEGORY)
const [success, setSuccess] = useState(false)
useEffect(() => { useEffect(() => {
loadCat() loadCat()
...@@ -47,7 +49,7 @@ const PostMoney = ({navigation}) => { ...@@ -47,7 +49,7 @@ const PostMoney = ({navigation}) => {
const initData = () => { const initData = () => {
setDate(getDate()) setDate(getDate())
setContents('') setContents('')
setPrice(0) setPrice('')
setSelected_asset_type(INIT_ASSETSTYPE) setSelected_asset_type(INIT_ASSETSTYPE)
setSelected_cat(INIT_CATEGORY) setSelected_cat(INIT_CATEGORY)
setSelected_subcat(INIT_SUBCATEGORY) setSelected_subcat(INIT_SUBCATEGORY)
...@@ -59,15 +61,20 @@ const PostMoney = ({navigation}) => { ...@@ -59,15 +61,20 @@ const PostMoney = ({navigation}) => {
'| contents: ', contents, '| contents: ', contents,
'| price: ', price, '| price: ', price,
'| selected_asset_type: ', selected_asset_type.id, '| selected_asset_type: ', selected_asset_type.id,
(selectedIndex === 2 ? { ['selected_deposit_asset_type']: selected_deposit_asset_type.id } : null), '| 이동일 때 ', (selectedIndex === 2 ? { ['selected_deposit_asset_type']: selected_deposit_asset_type.id } : null),
'| selected_cat: ', selected_cat.id, '| selected_cat: ', selected_cat.id,
'| selected_subcat: ', selected_subcat.id) '| selected_subcat: ', selected_subcat.id)
const insertData = async () => { const insertData = async () => {
try { try {
let type = selectedIndex + 1; let type = selectedIndex + 1;
const result = await moneyApi.insertMoney([type, date, contents, price, selected_asset_type.id, selected_cat.id, selected_subcat.id]) if (type === 3) {
console.log(result) await moneyApi.insertMoney([type, date, contents, -price, selected_asset_type.id, selected_cat.id, selected_subcat.id])
await moneyApi.insertMoney([type, date, contents, price, selected_deposit_asset_type.id, selected_cat.id, selected_subcat.id])
} else {
await moneyApi.insertMoney([type, date, contents, price, selected_asset_type.id, selected_cat.id, selected_subcat.id])
}
setSuccess(true)
} catch (error) { } catch (error) {
console.log('error in insert data', error) console.log('error in insert data', error)
} }
...@@ -110,6 +117,11 @@ const PostMoney = ({navigation}) => { ...@@ -110,6 +117,11 @@ const PostMoney = ({navigation}) => {
navigation.navigate('EditOption', 0) navigation.navigate('EditOption', 0)
} }
if(success){
initData()
setSuccess(false)
}
return ( return (
<View> <View>
<View> <View>
...@@ -125,6 +137,7 @@ const PostMoney = ({navigation}) => { ...@@ -125,6 +137,7 @@ const PostMoney = ({navigation}) => {
<InputBox <InputBox
inputTitle="내용" inputTitle="내용"
placeholder="내용을 입력하세요" placeholder="내용을 입력하세요"
value={contents}
onChangeText={ onChangeText={
(contents) => setContents(contents) (contents) => setContents(contents)
} }
...@@ -133,6 +146,7 @@ const PostMoney = ({navigation}) => { ...@@ -133,6 +146,7 @@ const PostMoney = ({navigation}) => {
<InputBox <InputBox
inputTitle="금액" inputTitle="금액"
placeholder="금액을 입력하세요" placeholder="금액을 입력하세요"
value={price}
onChangeText={ onChangeText={
(price) => setPrice(price) (price) => setPrice(price)
} }
......
...@@ -3,7 +3,7 @@ import { StyleSheet, TouchableOpacity, TouchableWithoutFeedback, View, Text, Mod ...@@ -3,7 +3,7 @@ import { StyleSheet, TouchableOpacity, TouchableWithoutFeedback, View, Text, Mod
import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons'; import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons';
const INIT_SUBCATEGORY = { const INIT_SUBCATEGORY = {
id: 0, id: 1,
value: '', value: '',
foreign_id: 0, foreign_id: 0,
} }
...@@ -60,6 +60,7 @@ const SelectForm = ({ ...@@ -60,6 +60,7 @@ const SelectForm = ({
onSubValueChange(INIT_SUBCATEGORY) onSubValueChange(INIT_SUBCATEGORY)
modalClose() modalClose()
} else { } else {
newOption.unshift({id: 1, value: '기타'})
if (newOption.length % 3 == 0) { if (newOption.length % 3 == 0) {
setSubOption(newOption) setSubOption(newOption)
setSubOptionShow(true) setSubOptionShow(true)
......
...@@ -9,7 +9,7 @@ const insertMoney = async (moneyData) => { ...@@ -9,7 +9,7 @@ const insertMoney = async (moneyData) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
db.transaction((tx) => { db.transaction((tx) => {
console.log("데이터 삽입하기"); console.log("데이터 삽입하기");
tx.executeSql('INSERT INTO Money (type, date, contents, price, asset_type, category, subcategory) VALUES (?,?,?,?,?,?,?);', tx.executeSql('INSERT INTO Money (type_id, date, contents, price, assets_id, category_id, subcategory_id) VALUES (?,?,?,?,?,?,?);',
moneyData, moneyData,
(error) => console.log(error)) (error) => console.log(error))
resolve('데이터 삽입 완료'); resolve('데이터 삽입 완료');
...@@ -25,7 +25,8 @@ const selectCategories = async (type_id) => { ...@@ -25,7 +25,8 @@ const selectCategories = async (type_id) => {
const [txn, results] = await tx.executeSql(`SELECT * FROM categories WHERE type_id=${type_id}`); const [txn, results] = await tx.executeSql(`SELECT * FROM categories WHERE type_id=${type_id}`);
console.log('item length', results.rows.length); console.log('item length', results.rows.length);
const temp = []; const temp = [];
for (let i = 0; i < 3*(Math.ceil(results.rows.length/3)); i++) { temp.push({id: 1, value:'기타'});
for (let i = 0; i < 3*(Math.ceil((results.rows.length+1)/3))-1; i++) {
if (i<results.rows.length){ if (i<results.rows.length){
const tempId = results.rows.item(i).category_id; const tempId = results.rows.item(i).category_id;
const tempName = results.rows.item(i).category_name; const tempName = results.rows.item(i).category_name;
...@@ -68,7 +69,7 @@ const selectAssetsType = async () => { ...@@ -68,7 +69,7 @@ const selectAssetsType = async () => {
const [txn, results] = await tx.executeSql('SELECT * FROM assets_type'); const [txn, results] = await tx.executeSql('SELECT * FROM assets_type');
console.log('item length', results.rows.length); console.log('item length', results.rows.length);
const temp = []; const temp = [];
for (let i = 0; i < 3*(Math.ceil(results.rows.length/3)); i++) { for (let i = 0; i < 3*(Math.ceil((results.rows.length)/3)); i++) {
if (i<results.rows.length){ if (i<results.rows.length){
const tempId = results.rows.item(i).assets_id; const tempId = results.rows.item(i).assets_id;
const tempName = results.rows.item(i).assets_name; const tempName = results.rows.item(i).assets_name;
......
export function getDate () { export function getDate () {
const date = new Date(); const date = new Date();
const tempY = date.getFullYear(); const tempY = date.getFullYear();
let tempM = date.getMonth(); let tempM = date.getMonth()+1;
tempM = tempM > 9 ? tempM : "0" + tempM; tempM = tempM > 9 ? tempM : "0" + tempM;
let tempD = date.getDate(); let tempD = date.getDate();
tempD = tempD > 9 ? tempD : "0" + tempD; tempD = tempD > 9 ? tempD : "0" + tempD;
console.log(`${tempY}-${tempM}-${tempD}`)
return `${tempY}-${tempM}-${tempD}` return `${tempY}-${tempM}-${tempD}`
} }
\ No newline at end of file
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