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 ( ) } 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 ( {I18n.t('DEFINE_PENALITE')} { this.tauxPenalite1Comp = comp }}> { this.setState({tauxPenalite1}); }} style={styles.input} > { this.tauxPenalite2Comp = comp }}> { this.setState({tauxPenalite2}); }} style={styles.input} > { this.tauxPenalite3Comp = comp }}> { this.setState({tauxPenalite3}); }} style={styles.input} > { this.passwordAnim = comp }}> { this.setState({password}) }} style={styles.input} > { 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 }); } } }}/> { this.setState({ displayDialogSavePenalite: false }); }}/> ) } 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 ( {I18n.t('AGENT_INFORMATION')} {`${item.lastname} | ${item.email}`} {`${item.email} | ${item.phone}`} {`${item.adresse}`} Déclaration {`${this.state.item.amount}`} {`${I18n.t('CREATION_DATE')}: ${created_at.format(" Do MMMM YYYY à HH:mm")}`} {`${I18n.t('UPDATE_DATE')}: ${updated_at.format(" Do MMMM YYYY à HH:mm")}`} {I18n.t('TAXES')} { this.state.item.royalties_fees.map(item => ( { this.setState({penality: item, displayDialogSavePenalite: true}) }} activeOpacity={0.9}> {item.id_revenue_order} {`Imputation: ${item.imputation}`} {`${item.name}`} {`${item.amount}`} {moment(moment.tz(item.created_at, moment.tz.guess()).format()).fromNow()} )) } ); } renderDetailTaxe = () => { return ( Bonjour ) } render() { return ( <> {this.renderDialogSavePenalite()} {this.state.displayLoader && this.renderLoader()} {this.state.isSubmitClick && this.renderDialogResponse()} { { this.props.navigation.pop() }} /> { this.renderDetailPenalite() } } ); } } 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, }, })