Commit b0f662b1 by Giang Tran

update caculatorprofitloss

parent b0c4f993
import I18n from '../helper/i18/i18n' import I18n from '../helper/i18/i18n';
export const RadioBuySale = [ export const RadioBuySale = [
{label: I18n.t('Buy'), value: 0}, {label: I18n.t('Buy'), value: 'BUY_IN'},
{label: I18n.t('Sale'), value: 1} {label: I18n.t('Sale'), value: 'SELL_OUT'},
] ];
...@@ -4,8 +4,13 @@ import {RadioBuySale} from '../../../Config/constants'; ...@@ -4,8 +4,13 @@ import {RadioBuySale} from '../../../Config/constants';
import I18n from '../../../helper/i18/i18n'; import I18n from '../../../helper/i18/i18n';
import {checkFormatArray} from '../../../Config/Functions'; import {checkFormatArray} from '../../../Config/Functions';
import {showAlert, TYPE} from '../../../components/DropdownAlert'; import {showAlert, TYPE} from '../../../components/DropdownAlert';
import {getTransactionListByCategory} from '../../../apis/Functions/Transaction'; import {
getTransactionListByCategory,
getProfitLost,
} from '../../../apis/Functions/Transaction';
import {Platform} from 'react-native'; import {Platform} from 'react-native';
import {showLoading, hideLoading} from '../../../actions/loadingAction';
import {connect} from 'react-redux';
const CalculatorProfitLoss = (props) => { const CalculatorProfitLoss = (props) => {
const [dataProduct, setDataProduct] = useState([]); const [dataProduct, setDataProduct] = useState([]);
...@@ -16,8 +21,8 @@ const CalculatorProfitLoss = (props) => { ...@@ -16,8 +21,8 @@ const CalculatorProfitLoss = (props) => {
const [openPrice, setOpenPrice] = useState(null); const [openPrice, setOpenPrice] = useState(null);
const [closeStatusPrice, setCloseStatusPrice] = useState(null); const [closeStatusPrice, setCloseStatusPrice] = useState(null);
useEffect(() => { useEffect(() => {
getProductData() getProductData();
}, []) }, []);
const getProductData = async () => { const getProductData = async () => {
const res = await getTransactionListByCategory({ const res = await getTransactionListByCategory({
...@@ -31,12 +36,11 @@ const CalculatorProfitLoss = (props) => { ...@@ -31,12 +36,11 @@ const CalculatorProfitLoss = (props) => {
if (res.status == 200 && res.data.code == 200) { if (res.status == 200 && res.data.code == 200) {
setDataProduct(res.data.data); setDataProduct(res.data.data);
} else { } else {
showAlert(TYPE.ERROR, I18n.t('Notification', I18n.t('Can_not_get_data'))) showAlert(TYPE.ERROR, I18n.t('Notification', I18n.t('Can_not_get_data')));
} }
}; };
const onCalculator = async () => {
const onCalculator = () => {
const titles = [ const titles = [
I18n.t('Product'), I18n.t('Product'),
I18n.t('LotTransactionNumber'), I18n.t('LotTransactionNumber'),
...@@ -51,28 +55,56 @@ const CalculatorProfitLoss = (props) => { ...@@ -51,28 +55,56 @@ const CalculatorProfitLoss = (props) => {
]); ]);
if (index === true) { if (index === true) {
let newData = [...dataCalculator] props.showLoading();
newData.push({
name: product.name, const res = await getProfitLost({
status: RadioBuySale[transactionType].label, commodity_id: product.id,
slot_number: 6, platform: Platform.OS,
profit_loss_usd: 639324325, transaction_type: transactionType,
profit_loss_vnd: 1234349235455, lot_number: lotTransactionNumber,
}) open_price: openPrice,
setDataCalculator(newData) close_price: closeStatusPrice,
setLotTransactionNumber(null) });
setOpenPrice(null) props.hideLoading();
setCloseStatusPrice(null) if (res.status == 200 && res.data.code == 200) {
const newList = [res.data.data].concat(dataCalculator);
setDataCalculator(newList);
setLotTransactionNumber(null);
setOpenPrice(null);
setCloseStatusPrice(null);
} else {
showAlert(
TYPE.ERROR,
I18n.t('Notification', I18n.t('Can_not_get_data')),
);
}
// let newData = [...dataCalculator]
// newData.push({
// name: product.name,
// status: RadioBuySale[transactionType].label,
// slot_number: 6,
// profit_loss_usd: 639324325,
// profit_loss_vnd: 1234349235455,
// })
// setDataCalculator(newData)
// setLotTransactionNumber(null)
// setOpenPrice(null)
// setCloseStatusPrice(null)
} else { } else {
showAlert(TYPE.ERROR, I18n.t('Notification'), `${I18n.t('Please_fill_in')}${titles[index]}`) showAlert(
TYPE.ERROR,
I18n.t('Notification'),
`${I18n.t('Please_fill_in')}${titles[index]}`,
);
} }
}; };
const onDelete = () => { const onDelete = () => {
setDataCalculator([]) setDataCalculator([]);
setLotTransactionNumber(null) setLotTransactionNumber(null);
setOpenPrice(null) setOpenPrice(null);
setCloseStatusPrice(null) setCloseStatusPrice(null);
}; };
const setLotNumber = (text) => { const setLotNumber = (text) => {
...@@ -105,4 +137,11 @@ const CalculatorProfitLoss = (props) => { ...@@ -105,4 +137,11 @@ const CalculatorProfitLoss = (props) => {
); );
}; };
export default CalculatorProfitLoss; const mapStateToProps = (state) => {
return {
user: state.userReducer,
};
};
export default connect(mapStateToProps, {showLoading, hideLoading})(
CalculatorProfitLoss,
);
import React, {Component} from 'react'; import React, {Component} from 'react';
import {View, Text, StyleSheet, TouchableOpacity, FlatList, ScrollView} from 'react-native'; import {
View,
Text,
StyleSheet,
TouchableOpacity,
FlatList,
ScrollView,
} from 'react-native';
import HeaderBack from '../../../components/Header/HeaderBack'; import HeaderBack from '../../../components/Header/HeaderBack';
import {getFontXD, HEIGHTXD, toPriceVnd, WIDTHXD} from '../../../Config/Functions'; import {
getFontXD,
HEIGHTXD,
toPriceVnd,
WIDTHXD,
} from '../../../Config/Functions';
import I18n from '../../../helper/i18/i18n'; import I18n from '../../../helper/i18/i18n';
import PickerItem from '../../../components/Picker/PickerItem'; import PickerItem from '../../../components/Picker/PickerItem';
import R from '../../../assets/R'; import R from '../../../assets/R';
...@@ -9,17 +21,19 @@ import RadioForm from 'react-native-simple-radio-button'; ...@@ -9,17 +21,19 @@ import RadioForm from 'react-native-simple-radio-button';
import {RadioBuySale} from '../../../Config/constants'; import {RadioBuySale} from '../../../Config/constants';
import TextMoney from '../../../components/Input/InputMoney'; import TextMoney from '../../../components/Input/InputMoney';
import ItemCalculator from './ItemCalculator'; import ItemCalculator from './ItemCalculator';
import AppText from '../../../components/AppText';
const CalculatorProfitLossView = (props) => { const CalculatorProfitLossView = (props) => {
return ( return (
<View style={{flex: 1, flexDirection: 'column', backgroundColor: 'white'}}> <View style={{flex: 1, flexDirection: 'column', backgroundColor: 'white'}}>
<HeaderBack title={'CalculatorProfitLoss'} isWhite={true}/> <HeaderBack title={'CalculatorProfitLoss'} isWhite={true} />
<ScrollView> <ScrollView>
<View style={{paddingHorizontal: WIDTHXD(60), paddingVertical: HEIGHTXD(60)}}> <View
<Text style={{
style={styles.textTitle}> paddingHorizontal: WIDTHXD(60),
{I18n.t('Product')} paddingVertical: HEIGHTXD(60),
</Text> }}>
<Text style={styles.textTitle}>{I18n.t('Product')}</Text>
<PickerItem <PickerItem
data={props.dataProduct} data={props.dataProduct}
onValueChange={(value, item) => { onValueChange={(value, item) => {
...@@ -29,10 +43,9 @@ const CalculatorProfitLossView = (props) => { ...@@ -29,10 +43,9 @@ const CalculatorProfitLossView = (props) => {
iconSize={WIDTHXD(40)} iconSize={WIDTHXD(40)}
iconColor={R.colors.black} iconColor={R.colors.black}
/> />
<Text <AppText style={[styles.textTitle, {marginTop: HEIGHTXD(30)}]}>
style={[styles.textTitle, {marginTop: HEIGHTXD(30)}]}>
{I18n.t('Tradding')} {I18n.t('Tradding')}
</Text> </AppText>
<View style={{width: WIDTHXD(600), height: HEIGHTXD(85)}}> <View style={{width: WIDTHXD(600), height: HEIGHTXD(85)}}>
<RadioForm <RadioForm
radio_props={RadioBuySale} radio_props={RadioBuySale}
...@@ -70,22 +83,30 @@ const CalculatorProfitLossView = (props) => { ...@@ -70,22 +83,30 @@ const CalculatorProfitLossView = (props) => {
value={toPriceVnd(props.closeStatusPrice)} value={toPriceVnd(props.closeStatusPrice)}
titleStyle={{marginTop: HEIGHTXD(20), fontSize: getFontXD(39)}} titleStyle={{marginTop: HEIGHTXD(20), fontSize: getFontXD(39)}}
/> />
<View style={{ <View
style={{
width: '100%', width: '100%',
flexDirection: 'row', flexDirection: 'row',
justifyContent: 'center', justifyContent: 'center',
alignItems: 'center', alignItems: 'center',
marginTop: HEIGHTXD(50), marginTop: HEIGHTXD(50),
}}> }}>
<TouchableOpacity onPress={() => { <TouchableOpacity
onPress={() => {
props.onDelete(); props.onDelete();
}} style={[styles.btn, {backgroundColor: R.colors.red2, marginRight: WIDTHXD(72)}]}> }}
style={[
styles.btn,
{backgroundColor: R.colors.red2, marginRight: WIDTHXD(72)},
]}>
<Text style={styles.txtButton}>{I18n.t('Delete')}</Text> <Text style={styles.txtButton}>{I18n.t('Delete')}</Text>
</TouchableOpacity> </TouchableOpacity>
<TouchableOpacity onPress={() => { <TouchableOpacity
onPress={() => {
props.onCalculator(); props.onCalculator();
}} style={styles.btn}> }}
<Text style={styles.txtButton}>{I18n.t('Calculator')}</Text> style={styles.btn}>
<Text style={styles.txtButton}>{I18n.t('Caculate')}</Text>
</TouchableOpacity> </TouchableOpacity>
</View> </View>
</View> </View>
...@@ -93,8 +114,12 @@ const CalculatorProfitLossView = (props) => { ...@@ -93,8 +114,12 @@ const CalculatorProfitLossView = (props) => {
style={{paddingBottom: HEIGHTXD(15), backgroundColor: R.colors.white}} style={{paddingBottom: HEIGHTXD(15), backgroundColor: R.colors.white}}
keyExtractor={(item) => item.id} keyExtractor={(item) => item.id}
data={props.dataCalculator} data={props.dataCalculator}
renderItem={({item, index}) => <ItemCalculator item={item} renderItem={({item, index}) => (
isLastItem={index === props.dataCalculator.length - 1}/>} <ItemCalculator
item={item}
isLastItem={index === props.dataCalculator.length - 1}
/>
)}
/> />
</ScrollView> </ScrollView>
</View> </View>
......
...@@ -4,12 +4,18 @@ import { ...@@ -4,12 +4,18 @@ import {
TouchableOpacity, TouchableOpacity,
Text, Text,
LayoutAnimation, LayoutAnimation,
StyleSheet StyleSheet,
} from 'react-native'; } from 'react-native';
import R from '../../../assets/R'; import R from '../../../assets/R';
import Ionicons from 'react-native-vector-icons/Ionicons'; import Ionicons from 'react-native-vector-icons/Ionicons';
import {getFontXD, getLineHeightXD, HEIGHTXD, toPriceVnd, WIDTHXD} from '../../../Config/Functions'; import {
getFontXD,
getLineHeightXD,
HEIGHTXD,
toPriceVnd,
WIDTHXD,
} from '../../../Config/Functions';
import I18n from '../../../helper/i18/i18n'; import I18n from '../../../helper/i18/i18n';
import TextField from '../../../components/TextField'; import TextField from '../../../components/TextField';
import {RadioBuySale} from '../../../Config/constants'; import {RadioBuySale} from '../../../Config/constants';
...@@ -29,66 +35,78 @@ const ItemCalculator = (props) => { ...@@ -29,66 +35,78 @@ const ItemCalculator = (props) => {
springDamping: 1.7, springDamping: 1.7,
}, },
}); });
setExpanded(!expanded) setExpanded(!expanded);
}; };
console.log(props.item.transaction_type);
return ( return (
<View style={[styles.container, {marginBottom: props.isLastItem? HEIGHTXD(100) : HEIGHTXD(30)}]}> <View
style={[
styles.container,
{marginBottom: props.isLastItem ? HEIGHTXD(100) : HEIGHTXD(30)},
]}>
<TouchableOpacity <TouchableOpacity
onPress={() => changeLayout()} onPress={() => changeLayout()}
style={[styles.flexTitle, { borderBottomWidth: expanded === true ? 0.3 : 0, paddingHorizontal: WIDTHXD(30) }]} style={[
> styles.flexTitle,
{
borderBottomWidth: expanded === true ? 0.3 : 0,
paddingHorizontal: WIDTHXD(30),
},
]}>
<Text style={styles.title}>{props.item.name}</Text> <Text style={styles.title}>{props.item.name}</Text>
{expanded === true ? ( {expanded === true ? (
<Ionicons <Ionicons
name='chevron-up' name="chevron-up"
size={WIDTHXD(50)} size={WIDTHXD(50)}
style={{ marginRight: WIDTHXD(25) }} style={{marginRight: WIDTHXD(25)}}
color={R.colors.iconGray} color={R.colors.iconGray}
/> />
) : ( ) : (
<Ionicons <Ionicons
name='chevron-down' name="chevron-down"
size={WIDTHXD(50)} size={WIDTHXD(50)}
style={{ marginRight: WIDTHXD(25) }} style={{marginRight: WIDTHXD(25)}}
color={R.colors.iconGray} color={R.colors.iconGray}
/> />
)} )}
</TouchableOpacity> </TouchableOpacity>
{expanded ? {expanded ? (
<View style={{paddingVertical: HEIGHTXD(20)}}> <View style={{paddingVertical: HEIGHTXD(20)}}>
<TextField <TextField
title={I18n.t('Status')} title={I18n.t('Status')}
content={props.item.status} content={I18n.t(props.item.transaction_type)}
color={props.item.status == RadioBuySale[0].label ? R.colors.green : R.colors.red2} color={
props.item.transaction_type == 'SELL_OUT'
? R.colors.green
: R.colors.red2
}
/> />
<TextField <TextField
title={I18n.t('SlotNumber')} title={I18n.t('SlotNumber')}
content={props.item.slot_number} content={props.item.lot_number}
/> />
<TextField <TextField
title={`${I18n.t('ProfitLoss')} (USD)`} title={`${I18n.t('ProfitLoss')} (USD)`}
content={toPriceVnd(props.item.profit_loss_usd)} content={toPriceVnd(props.item.profit.USD)}
/> />
<TextField <TextField
title={`${I18n.t('ProfitLoss')} (VNĐ)`} title={`${I18n.t('ProfitLoss')} (VNĐ)`}
content={toPriceVnd(props.item.profit_loss_vnd)} content={toPriceVnd(props.item.profit.VND)}
/> />
</View> </View>
: null ) : null}
}
</View> </View>
) );
};
} export default ItemCalculator;
export default ItemCalculator
const styles = StyleSheet.create({ const styles = StyleSheet.create({
container: { container: {
backgroundColor: R.colors.white, backgroundColor: R.colors.white,
borderColor: R.colors.borderGray, borderColor: R.colors.borderGray,
borderWidth: 0.3, borderWidth: 0.3,
marginHorizontal: WIDTHXD(40), marginHorizontal: WIDTHXD(40),
marginBottom: HEIGHTXD(30) marginBottom: HEIGHTXD(30),
}, },
flexTitle: { flexTitle: {
flexDirection: 'row', flexDirection: 'row',
...@@ -102,4 +120,4 @@ const styles = StyleSheet.create({ ...@@ -102,4 +120,4 @@ const styles = StyleSheet.create({
lineHeight: getLineHeightXD(56), lineHeight: getLineHeightXD(56),
color: R.colors.black, color: R.colors.black,
}, },
}) });
...@@ -15,3 +15,8 @@ export const sendRequest = async (body) => ...@@ -15,3 +15,8 @@ export const sendRequest = async (body) =>
PostData(url.urlSendRequest, body) PostData(url.urlSendRequest, body)
.then((res) => res) .then((res) => res)
.catch((err) => err); .catch((err) => err);
export const getProfitLost = async (body) =>
PostData(url.urlProfitLost, body)
.then((res) => res)
.catch((err) => err);
import {GetData} from '../helpers'; import {GetData, PostData} from '../helpers';
import url from '../url'; import url from '../url';
...@@ -16,3 +16,8 @@ export const getContractDescription = async (id) => ...@@ -16,3 +16,8 @@ export const getContractDescription = async (id) =>
GetData(`${url.urlGetContractDescription}${id}`) GetData(`${url.urlGetContractDescription}${id}`)
.then((res) => res) .then((res) => res)
.catch((err) => err); .catch((err) => err);
export const getProfitLost = async (body) =>
PostData(url.urlProfitLost, body)
.then((res) => res)
.catch((err) => err);
...@@ -53,4 +53,6 @@ export default { ...@@ -53,4 +53,6 @@ export default {
urlFeedback: root + 'api/v1/customers/send-feedback', urlFeedback: root + 'api/v1/customers/send-feedback',
urlSendRequest: root + 'api/v1/customers/send-request', urlSendRequest: root + 'api/v1/customers/send-request',
urlProfitLost: root + 'api/v1/customers/calculate-profit',
}; };
import React from 'react' import React from 'react';
import { import {View, Text, StyleSheet} from 'react-native';
View,
Text,
StyleSheet
} from 'react-native'
import R from '../assets/R'; import R from '../assets/R';
import {getFontXD, HEIGHTXD, WIDTHXD} from '../Config/Functions'; import {getFontXD, HEIGHTXD, WIDTHXD} from '../Config/Functions';
const TextField = (props) => { const TextField = (props) => {
const {color} = props const {color} = props;
return ( return (
<View style={[styles.row, { paddingVertical: WIDTHXD(15) }]}> <View style={[styles.row, {paddingVertical: WIDTHXD(15)}]}>
<Text style={styles.title}>{props.title}</Text> <Text style={styles.title}>{props.title}</Text>
<Text style={[styles.content, color && {color}]}>{props.content}</Text> <Text style={[styles.content, color && {color}]}>{props.content}</Text>
</View> </View>
) );
} };
export default TextField export default TextField;
const styles = StyleSheet.create({ const styles = StyleSheet.create({
row: { row: {
paddingHorizontal: HEIGHTXD(30), paddingHorizontal: HEIGHTXD(30),
...@@ -25,11 +21,11 @@ const styles = StyleSheet.create({ ...@@ -25,11 +21,11 @@ const styles = StyleSheet.create({
title: { title: {
flex: 2.7, flex: 2.7,
fontSize: getFontXD(36), fontSize: getFontXD(36),
color: R.colors.color777 color: R.colors.color777,
}, },
content: { content: {
flex: 3.5, flex: 3.5,
fontSize: getFontXD(36), fontSize: getFontXD(36),
color: R.colors.black, color: R.colors.black,
}, },
}) });
...@@ -272,4 +272,6 @@ export default { ...@@ -272,4 +272,6 @@ export default {
CloseStatusPrice: 'Close stauts price', CloseStatusPrice: 'Close stauts price',
SlotNumber: 'Slot number', SlotNumber: 'Slot number',
ProfitLoss: 'Profit/Loss', ProfitLoss: 'Profit/Loss',
BUY_IN: 'Buy in',
SELL_OUT: 'Sell out',
}; };
...@@ -257,4 +257,14 @@ export default { ...@@ -257,4 +257,14 @@ export default {
ConvertUSD: 'Quy đổi USD/Tấn', ConvertUSD: 'Quy đổi USD/Tấn',
Saturday: 'Thứ 7', Saturday: 'Thứ 7',
Sunday: 'Chủ nhật', Sunday: 'Chủ nhật',
LotTransactionNumber: 'Số lot giao dịch',
OpenPrice: 'Giá mở trạng thái',
CloseStatusPrice: 'Giá đóng trạng thái',
Buy: 'Mua',
Sale: 'Bán',
SlotNumber: 'Số lót',
ProfitLoss: 'Lãi/lỗ',
CalculatorProfitLoss: 'Tính lãi lỗ',
BUY_IN: 'Mua vào',
SELL_OUT: 'Bán ra',
}; };
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