simba-mobile-cad3/app/screens/wallet/regisseur/PenalityDeclarationDetail.js

887 lines
32 KiB
JavaScript
Raw Normal View History

2025-01-07 09:47:45 +00:00
import React, {Component} from 'react'
import {
ActivityIndicator,
Alert, Image,
Platform,
ProgressBarAndroid,
ScrollView, StatusBar,
StyleSheet,
Text,
TouchableOpacity,
View
} from 'react-native'
import Button from 'apsl-react-native-button'
import {responsiveFontSize, responsiveHeight, responsiveWidth} from 'react-native-responsive-dimensions'
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import {readUser} from "../../../webservice/AuthApi";
import I18n from "react-native-i18n";
import {creditDemandResetReducer, treatCreditDemand} from '../../../webservice/CreditTreatDemandApi';
import {creditCancelResetReducer, treatCancelDemand} from '../../../webservice/CreditCancelDemandeApi';
import {connect} from 'react-redux';
import {bindActionCreators} from 'redux';
import Toast from 'react-native-root-toast';
import {Color} from '../../../config/Color'
import isNil from 'lodash/isNil';
import isEqual from 'lodash/isEqual';
import {getNanoCreditUniqueDemandsAction, getNanoCreditUniqueDemandsReset} from '../../../webservice/user/NanoCreditApi'
import {cancelDemandGroupAction, treatDemandGroupAction, treatDemandGroupReset} from '../../../webservice/NanoCreditApi'
import * as Animatable from "react-native-animatable";
import {Dropdown} from "react-native-material-dropdown-v2";
import {Fumi} from "react-native-textinput-effects";
import FontAwesomeIcon from "react-native-vector-icons/FontAwesome";
import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons';
import Entypo from 'react-native-vector-icons/Entypo';
import BottomSheet from 'react-native-js-bottom-sheet';
import {
deletePenalityAction, deletePenalityReset,
modifyAvisImpositionReset,
modifyOrdreRecetteAction, savePenalityAction, savePenalityReset, saveActifSocietyAction, saveActifSocietyReset,
saveOrdreRecetteAction
} from "../../../webservice/regisseur/WalletRegisseurApi";
import Dialog from "react-native-dialog";
import {ProgressDialog} from "react-native-simple-dialogs";
import {IndicatorViewPager, PagerTabIndicator} from "react-native-best-viewpager";
import {store} from "../../../redux/store";
import {
fetchSavePenalityError,
fetchSavePenalityPending,
fetchSavePenalitySuccess
} from "../../../redux/actions/WalletActions";
import axios from "axios";
import {getOnePenality, penalityUrl} from "../../../webservice/IlinkConstants";
import {Appbar, Provider} from "react-native-paper";
let moment = require('moment-timezone')
var colorback = 'white'
let theme = require('../../../utils/theme.json');
const route = require("../../../route.json");
class PenalityDeclarationDetail extends Component {
static navigatorStyle = {
navBarBackgroundColor: theme.accentLight,
statusBarColor: theme.accent,
navBarTextColor: '#FFFFFF',
navBarButtonColor: '#FFFFFF',
};
static navigationOptions = ({navigation}) => {
return {
drawerLabel: () => null,
title: navigation.getParam("isModify", false) ? I18n.t('ORDRE_RECETTE') + ' N°' + navigation.getParam("item", null).id_revenue_order
: I18n.t('AVIS_IMPOSITION') + ' N°' + navigation.getParam("item", null).id_tax_notice,
headerTintColor: 'white',
headerStyle: {
backgroundColor: Color.primaryColor,
marginTop: -20,
color: 'white'
},
headerTitleStyle: {
color: "white"
},
}
};
constructor(props) {
super(props);
this.state = {
displayAmountModifyDialog: false,
/* statut: sta, */
user: null,
networks: [],
loadingTreat: false,
loadingCancel: false,
triggerTreatmentClick: false,
triggerCancelClick: false,
color: colorback,
montant: null,
royalties_fees: null,
isBtnModifyAmountEnabled: false,
id: this.props.navigation.getParam("id", null),
item: this.props.navigation.getParam("item", null),
password: null,
isModify: this.props.navigation.getParam("isModify", false),
assign_network: false,
ordreRecetteId: this.props.navigation.getParam("isModify", false) ? this.props.navigation.getParam("item", null).id_revenue_order : null,
displayDialogSavePenalite: false,
displayDialogDeletePenalite: false,
tauxPenalite1: null,
tauxPenalite2: null,
tauxPenalite3: null,
penality: {},
displayLoader: false,
isSubmitClick: false
};
console.log("STATE", this.state);
this.currentLocale = I18n.locale.includes("fr") ? "fr" : "en-gb";
moment.locale(this.currentLocale);
this.props.savePenalityReset();
this.props.deletePenalityReset();
this.willFocus = this.props.navigation.addListener(
'willFocus',
payload => {
this.refreshScreen(this.state.item.id);
});
}
componentDidMount() {
readUser().then((user) => {
if (user) {
if (user !== undefined) {
this.setState({user});
}
}
});
}
displayToast = (message) => {
Toast.show(message, {
duration: Toast.durations.LONG,
position: Toast.positions.BOTTOM,
backgroundColor: Color.primaryColor,
shadow: true,
animation: true,
hideOnPress: true,
delay: 0,
onShow: () => {
// calls on toast\`s appear animation start
},
onShown: () => {
// calls on toast\`s appear animation end.
},
onHide: () => {
// calls on toast\`s hide animation start.
},
onHidden: () => {
// calls on toast\`s hide animation end.
}
});
}
ckeckIfFieldIsOK(champ) {
return (isNil(champ) || isEqual(champ.length, 0));
}
checkOrShake(champ, view) {
let res = false;
if (champ !== undefined && champ !== null && champ.length > 0) {
res = true;
} else {
view.shake(800)
}
return res;
}
renderLoader = () => {
return (
<ProgressDialog
visible={this.state.displayLoader}
title={I18n.t('LOADING')}
message={I18n.t('LOADING_PROGRESS')}
/>
)
}
renderDialogResponse = () => {
const {resultSavePenality, errorSavePenality} = this.props;
if (errorSavePenality !== null) {
if (typeof errorSavePenality.data !== 'undefined') {
Alert.alert(
I18n.t("ERROR_LABLE"),
errorSavePenality.data.error,
[
{
text: I18n.t("OK"), onPress: () => {
this.props.savePenalityReset();
this.setState({
tauxPenalite1: null,
tauxPenalite2: null,
tauxPenalite3: null,
displayLoader: false,
isSubmitClick: false
});
}
}
],
{cancelable: false}
)
}
}
if (resultSavePenality !== null) {
if (resultSavePenality.response !== null) {
Alert.alert(
I18n.t("SUCCESS"),
resultSavePenality.response,
[
{
text: I18n.t("OK"), onPress: () => {
this.props.savePenalityReset();
this.setState({
tauxPenalite1: null,
tauxPenalite2: null,
tauxPenalite3: null,
displayLoader: false,
isSubmitClick: false
});
this.refreshScreen(this.state.item.id);
}
}
],
{cancelable: false}
)
}
}
}
refreshScreen = (id) => {
const auth = store.getState().authKeyReducer;
const authKey = auth !== null ? `${auth.authKey.token_type} ${auth.authKey.access_token}` : '';
axios({
url: `${getOnePenality}/${id}`,
method: 'GET',
headers: {
'Authorization': authKey,
'X-Localization': I18n.currentLocale()
}
})
.then(response => {
console.log("RESPONSE", response);
this.setState({
item: response.data.response
});
})
.catch(error => {
let message = "";
if (error.response)
message = error.response
else if (error.request)
message = error.request
else
message = error.request;
Alert.alert(
I18n.t("ERROR_LABLE"),
message.data.error,
[
{
text: I18n.t("OK"), onPress: () => {
this.props.savePenalityReset();
this.setState({
tauxPenalite1: null,
tauxPenalite2: null,
tauxPenalite3: null,
displayLoader: false,
isSubmitClick: false
});
}
}
],
{cancelable: false}
)
});
}
renderDialogSavePenalite = () => {
let year = new Date();
console.log(this.state.penality);
return (
<Dialog.Container contentStyle={{width: responsiveWidth(80)}} useNativeDriver={true}
visible={this.state.displayDialogSavePenalite}>
<Dialog.Title>{I18n.t('DEFINE_PENALITE')}</Dialog.Title>
<View>
<View
style={{width: "100%"}}>
<Animatable.View ref={(comp) => {
this.tauxPenalite1Comp = comp
}}>
<Fumi iconClass={FontAwesomeIcon}
label={`${I18n.t('PENALITES')} ${Number(parseInt(this.state.item.year) - 1)} (%)`}
iconColor={'#f95a25'}
iconSize={20}
keyboardType={"numeric"}
iconName={"edit"}
value={this.state.tauxPenalite1}
onChangeText={(tauxPenalite1) => {
this.setState({tauxPenalite1});
}}
style={styles.input}
>
</Fumi>
</Animatable.View>
<Animatable.View ref={(comp) => {
this.tauxPenalite2Comp = comp
}}>
<Fumi iconClass={FontAwesomeIcon}
label={`${I18n.t('PENALITES')} ${Number(parseInt(this.state.item.year) - 2)} (%)`}
iconColor={'#f95a25'}
iconSize={20}
keyboardType={"numeric"}
iconName={"edit"}
value={this.state.tauxPenalite2}
onChangeText={(tauxPenalite2) => {
this.setState({tauxPenalite2});
}}
style={styles.input}
>
</Fumi>
</Animatable.View>
<Animatable.View ref={(comp) => {
this.tauxPenalite3Comp = comp
}}>
<Fumi iconClass={FontAwesomeIcon}
label={`${I18n.t('PENALITES')} ${Number(parseInt(this.state.item.year) - 3)} (%)`}
iconColor={'#f95a25'}
iconSize={20}
keyboardType={"numeric"}
iconName={"edit"}
value={this.state.tauxPenalite3}
onChangeText={(tauxPenalite3) => {
this.setState({tauxPenalite3});
}}
style={styles.input}
>
</Fumi>
</Animatable.View>
<Animatable.View ref={(comp) => {
this.passwordAnim = comp
}}>
<Fumi iconClass={FontAwesomeIcon} iconName={'lock'}
label={I18n.t('PASSWORD')}
iconColor={'#f95a25'}
iconSize={20}
secureTextEntry={true}
value={this.state.password}
onChangeText={(password) => {
this.setState({password})
}}
style={styles.input}
>
</Fumi>
</Animatable.View>
</View>
</View>
<Dialog.Button bold={true} label={I18n.t('SUBMIT_LABEL')} onPress={() => {
if (this.checkOrShake(this.state.password, this.passwordAnim)) {
if ((this.state.penality.id_tax_penalty_year_N_1 !== null && this.state.tauxPenalite1 !== null) ||
(this.state.penality.id_tax_penalty_year_N_2 !== null && this.state.tauxPenalite2 !== null) ||
(this.state.penality.id_tax_penalty_year_N_3 !== null && this.state.tauxPenalite3 !== null)) {
let message = I18n.t("YOU_HAVE_DEFINED_PENALITY_FOR_THIS_YEAR") + "\n" +
(this.state.penality.id_tax_penalty_year_N_1 !== null ? Number(parseInt(this.state.item.year) - 1) : "") + "\n" +
(this.state.penality.id_tax_penalty_year_N_2 !== null ? Number(parseInt(this.state.item.year) - 2) : "") + "\n" +
(this.state.penality.id_tax_penalty_year_N_3 !== null ? Number(parseInt(this.state.item.year) - 3) : "") + "\n";
Alert.alert(
I18n.t("ERROR_LABLE"),
message,
[
{
text: I18n.t("OK"), onPress: () => {
this.props.savePenalityReset();
this.setState({
tauxPenalite1: null,
tauxPenalite2: null,
tauxPenalite3: null
});
}
}
],
{cancelable: false}
)
} else {
this.props.savePenalityAction({
id_super: this.state.user.agentId,
password: this.state.password,
id_royalty_fee: this.state.penality.id_royalty_fee,
penalty_rate_for_year_n_1: this.state.tauxPenalite1,
penalty_rate_for_year_n_2: this.state.tauxPenalite2,
penalty_rate_for_year_n_3: this.state.tauxPenalite3
});
this.setState({
displayDialogSavePenalite: false,
displayLoader: true,
isSubmitClick: true
});
}
}
}}/>
<Dialog.Button bold={true} label={I18n.t('CANCEL_LABEL')} onPress={() => {
this.setState({
displayDialogSavePenalite: false
});
}}/>
</Dialog.Container>
)
}
renderDetailPenalite = () => {
const {item} = this.state;
let created_at = moment.tz(item.created_at, moment.tz.guess()).format();
let updated_at = moment.tz(item.updated_at, moment.tz.guess()).format();
created_at = moment(created_at);
updated_at = moment(updated_at);
let taxe_name = {name: ""};
if (this.state.isModify)
taxe_name = {name: this.state.item.tax_name};
console.log("tax_name", taxe_name)
return (<ScrollView style={styles.container}>
<View
style={styles.cardcontainer}
>
<Text style={{
fontSize: 17,
fontWeight: 'bold',
color: 'black',
marginLeft: responsiveWidth(5)
}}>
{I18n.t('AGENT_INFORMATION')}
</Text>
<View style={{
flexDirection: 'row',
justifyContent: 'flex-start'
}}>
<Icon name='account'
size={28}
color={theme.accent}
style={{
marginLeft: 20
}}
/>
<Text style={styles.simpleuser}>{`${item.lastname} | ${item.email}`}</Text>
</View>
<View style={{
flexDirection: 'row',
justifyContent: 'flex-start'
}}>
<Icon name='email'
size={28}
color={theme.accent}
style={{
marginLeft: 20
}}
/>
<Text style={styles.simpleuser}>{`${item.email} | ${item.phone}`}</Text>
</View>
<View style={{
flexDirection: 'row',
justifyContent: 'flex-start'
}}>
<Icon name='map-marker'
size={28}
color={theme.accent}
style={{
marginLeft: 20
}}
/>
<Text style={styles.simpleuser}>{`${item.adresse}`}</Text>
</View>
</View>
<View
style={styles.cardcontainer}
>
<Text style={{
fontSize: 17,
fontWeight: 'bold',
color: 'black',
marginLeft: responsiveWidth(5)
}}>
Déclaration
</Text>
<View style={{
flexDirection: 'row',
justifyContent: 'flex-start'
}}>
<Icon name="cash"
size={28}
color={theme.accent}
style={{
marginLeft: 20
}}
/>
<Text
style={styles.simpleuser}>{`${this.state.item.amount}`}</Text>
</View>
<View style={{
flexDirection: 'row',
justifyContent: 'flex-start'
}}>
<Icon name='calendar'
size={28}
color={theme.accent}
style={{
marginLeft: 20
}}
/>
<Text
style={styles.simpleuser}>{`${I18n.t('CREATION_DATE')}: ${created_at.format(" Do MMMM YYYY à HH:mm")}`}</Text>
</View>
<View style={{
flexDirection: 'row',
justifyContent: 'flex-start'
}}>
<Icon name='calendar'
size={28}
color={theme.accent}
style={{
marginLeft: 20
}}
/>
<Text
style={styles.simpleuser}>{`${I18n.t('UPDATE_DATE')}: ${updated_at.format(" Do MMMM YYYY à HH:mm")}`}</Text>
</View>
</View>
<View style={styles.cardcontainer}>
<Text style={{
fontSize: 17,
fontWeight: 'bold',
color: 'black',
marginLeft: responsiveWidth(5)
}}>
{I18n.t('TAXES')}
</Text>
{
this.state.item.royalties_fees.map(item => (
<View
style={styles.checkboxContainer}>
<View style={{width: 25}}>
<TouchableOpacity
style={[styles.contain], {
backgroundColor: Color.accentColor,
alignItems: "center",
justifyContent: "center",
position: "absolute",
width: 25,
zIndex: 10,
top: 50,
height: 25,
borderRadius: 11}}
onPress={() => {
this.setState({penality: item, displayDialogSavePenalite: true})
}}
activeOpacity={0.9}>
<View>
<View>
<Icon name={'plus'} color={Color.whiteColor} size={20}/>
</View>
</View>
</TouchableOpacity>
</View>
<View style={styles.paymentItem}>
<View style={styles.content}>
<Text style={styles.title}>{item.id_revenue_order}</Text>
<Text
style={styles.description}>{`Imputation: ${item.imputation}`}</Text>
<Text
style={styles.description}>{`${item.name}`}</Text>
<View style={styles.timeContent}>
<View style={{alignContent: 'flex-start', flex: 1, flexDirection: 'row'}}>
<Text style={{
fontWeight: 'bold', marginLeft: 20,
marginBottom: 10,
}}>
{`${item.amount}`}
</Text>
<View
style={{
alignContent: 'flex-start',
flexDirection: 'row',
marginLeft: 20
}}>
<Icon name="clock"
style={[styles.descriptionIcon], {color: Color.accentColor, marginTop: 5}}/>
<Text
style={styles.time}>{moment(moment.tz(item.created_at, moment.tz.guess()).format()).fromNow()}</Text>
</View>
</View>
</View>
</View>
</View>
</View>
))
}
</View>
</ScrollView>);
}
renderDetailTaxe = () => {
return (
<View style={styles.container}>
<View style={styles.cardcontainer}>
<Text>Bonjour</Text>
</View>
</View>
)
}
render() {
return (
<>
{this.renderDialogSavePenalite()}
{this.state.displayLoader && this.renderLoader()}
{this.state.isSubmitClick && this.renderDialogResponse()}
{
<Provider>
<View style={{flex: 1}}
>
<StatusBar
backgroundColor={theme.primaryDark}
barStyle="light-content"
translucent={false}
/>
<Appbar.Header dark={true} style={{backgroundColor: theme.primary}}>
<Appbar.BackAction
onPress={() => {
this.props.navigation.pop()
}}
/>
<Appbar.Content
title={I18n.t('PENALITE_MANAGE')}
subtitle={I18n.t('DEFINE_PENALITE')}
/>
</Appbar.Header>
{
this.renderDetailPenalite()
}
</View>
</Provider>
}
</>
);
}
}
const mapStateToProps = state => ({
loadingGetUniqueDemand: state.getUniqueDemandsGroupReducer.loading,
resultGetUniqueDemand: state.getUniqueDemandsGroupReducer.result,
errorGetUniqueDemand: state.getUniqueDemandsGroupReducer.error,
loadingModifyAvis: state.modifyAvisImpositionReducer.loading,
resultModifyAvis: state.modifyAvisImpositionReducer.result,
errorModifyAvis: state.modifyAvisImpositionReducer.error,
loadingSavePenality: state.savePenalityReducer.loading,
resultSavePenality: state.savePenalityReducer.result,
errorSavePenality: state.savePenalityReducer.error,
});
const mapDispatchToProps = dispatch => bindActionCreators({
getNanoCreditUniqueDemandsAction: getNanoCreditUniqueDemandsAction,
getNanoCreditUniqueDemandsReset: getNanoCreditUniqueDemandsReset,
treatDemandGroupAction: treatDemandGroupAction,
cancelDemandGroupAction: cancelDemandGroupAction,
treatDemandGroupReset: treatDemandGroupReset,
treatCreditDemand: treatCreditDemand,
creditDemandResetReducer: creditDemandResetReducer,
treatCancelDemand: treatCancelDemand,
creditCancelResetReducer: creditCancelResetReducer,
saveOrdreRecetteAction,
modifyAvisImpositionReset,
modifyOrdreRecetteAction,
deletePenalityAction,
deletePenalityReset,
savePenalityAction,
savePenalityReset,
}, dispatch);
export default connect(mapStateToProps, mapDispatchToProps)(PenalityDeclarationDetail);
const styles = StyleSheet.create({
container: {
flex: 1,
},
btnstyle: {},
inputAmountText: {
...Platform.select({
android: {
borderBottomColor: Color.borderColor,
borderBottomWidth: 0.5,
}
})
},
simpleuser: {
marginLeft: responsiveWidth(2),
fontSize: 16,
color: '#3E3E3E'
},
textbtnstyle: {
color: "white",
fontWeight: "bold",
fontSize: 18
},
input: {
height: 60,
marginTop: responsiveHeight(2),
marginLeft: responsiveWidth(5),
marginRight: responsiveWidth(5),
borderRadius: 5,
borderWidth: 1
},
cardcontainer1: {
justifyContent: 'space-evenly',
flex: 2,
marginRight: 3,
marginLeft: 3,
},
cardcontainer: {
margin: 3,
marginTop: 25
},
checkboxContainer: {
flexDirection: "row",
},
checkbox: {
alignSelf: "center",
color: "white"
},
contentPicker: {
padding: 10,
paddingBottom: 0,
marginBottom: 0,
borderRadius: 8,
flex: 1,
alignItems: "center"
},
contain: {flexDirection: "row"},
thumb: {
borderRadius: 30,
marginRight: 10
},
point: {
width: 25,
height: 25,
borderRadius: 11,
alignItems: "center",
justifyContent: "center",
position: "absolute",
right: 9,
bottom: 0
},
paymentItem: {
flexDirection: "row",
alignItems: "center",
justifyContent: "space-between",
width: "100%",
borderBottomColor: '#EEE',
borderBottomWidth: 1
},
listStyle: {
backgroundColor: 'white'
},
bottomSeparator: {
width: responsiveWidth(100),
height: 5,
justifyContent: 'center',
alignSelf: 'center',
backgroundColor: '#EEE',
},
description: {
fontSize: responsiveFontSize(1.8),
color: '#4f5b62',
marginLeft: 20,
},
timeContent: {
justifyContent: 'space-between',
flex: 1,
marginTop: 10,
marginBottom: 5,
flexDirection: 'row',
},
time: {
fontWeight: 'bold',
marginRight: 20,
marginBottom: 10,
color: theme.accent,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
dateText: {
marginLeft: responsiveWidth(13),
marginBottom: 20,
fontSize: 17,
},
titlecontent: {
fontSize: 17,
marginLeft: responsiveWidth(10),
color: 'black'
},
title: {
fontSize: 20,
marginLeft: 20,
color: 'black',
fontWeight: 'bold'
},
content: {
flex: 1,
flexDirection: 'column',
paddingTop: 0,
},
})