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, modifyPenalityAction, modifyPenalityReset, 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 axios from "axios"; import {getOnePenality} 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 PenalityTaxeDetail 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, displayDialogModifyPenalite: false, displayDialogDeletePenalite: false, tauxPenalite: 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.modifyPenalityReset(); 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; } renderModifyResponse = () => { const {errorModifyAvis, resultModifyAvis, resultCancelDemand, errorCancelDemand} = this.props; if (errorModifyAvis !== null) { if (typeof errorModifyAvis.data !== 'undefined') { Alert.alert( I18n.t("ERROR_TREATMENT_REQUEST"), errorModifyAvis.data.error, [ { text: I18n.t("OK"), onPress: () => { this.props.modifyAvisImpositionReset(); } } ], {cancelable: false} ); } } if (resultModifyAvis !== null) { console.log("resultModifyAvis", resultModifyAvis); if (resultModifyAvis.status === 200) { if (this.state.isModify) { Alert.alert( I18n.t("SUCCESS"), I18n.t("ORDRE_RECETTE_MODIFY_SUCCES"), [ { text: I18n.t("OK"), onPress: () => { this.props.navigation.goBack(); this.props.modifyAvisImpositionReset(); } } ], {cancelable: false} ); } else { Alert.alert( I18n.t("SUCCESS"), I18n.t("ORDRE_RECETTE_SUCCES"), [ { text: I18n.t("OK"), onPress: () => { this.props.navigation.goBack(); this.props.modifyAvisImpositionReset(); } } ], {cancelable: false} ); } } } } renderLabelState = (state) => { if (state === 0) return I18n.t('NO_TREAT') else if (state === 1) return I18n.t('TREAT') else return I18n.t('REFUSED') } renderLoader = () => { return ( ) } renderDialogResponse = () => { const {resultModifyPenality, errorModifyPenality, resultDeletePenality, errorDeletePenality} = this.props; if (errorModifyPenality !== null) { if (typeof errorModifyPenality.data !== 'undefined') { Alert.alert( I18n.t("ERROR_LABLE"), errorModifyPenality.data.error, [ { text: I18n.t("OK"), onPress: () => { this.props.modifyPenalityReset(); } } ], {cancelable: false} ) } } if (resultModifyPenality !== null) { if (resultModifyPenality.response !== null) { Alert.alert( I18n.t("SUCCESS"), resultModifyPenality.response, [ { text: I18n.t("OK"), onPress: () => { this.props.modifyPenalityReset(); this.setState({ displayLoader: false, isSubmitClick: false }); this.refreshScreen(this.state.item.id); } } ], {cancelable: false} ) } } if (errorDeletePenality !== null) { if (typeof errorDeletePenality.data !== 'undefined') { Alert.alert( I18n.t("ERROR_LABLE"), errorDeletePenality.data.error, [ { text: I18n.t("OK"), onPress: () => { this.props.deletePenalityReset(); } } ], {cancelable: false} ) } } if (resultDeletePenality !== null) { if (resultDeletePenality.response !== null) { Alert.alert( I18n.t("SUCCESS"), resultDeletePenality.response, [ { text: I18n.t("OK"), onPress: () => { this.props.deletePenalityReset(); this.setState({ 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, tauxPenalite: null }); }) .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: () => { } } ], {cancelable: false} ) }); } renderDialogModifyPenalite = () => { console.log("Current penalite", this.state.penality); return ( {I18n.t('MODIFY_PENALITE')} { this.tauxPenaliteComp = comp }}> { this.setState({tauxPenalite}); }} style={styles.input} > { this.passwordAnim = comp }}> { this.setState({password}) }} style={styles.input} > { if (this.checkOrShake(this.state.tauxPenalite, this.tauxPenaliteComp)) { if (this.checkOrShake(this.state.password, this.passwordAnim)) { this.props.modifyPenalityAction(this.state.penality.id, { id_super: this.state.user.agentId, password: this.state.password, id_royalty_fee: this.state.penality.id_royalty_fee, penalty_rate: this.state.tauxPenalite }); this.setState({ displayDialogModifyPenalite: false, displayLoader: true, isSubmitClick: true }); } } }}/> { this.setState({ displayDialogModifyPenalite: false }); }}/> ) } renderDialogDeletePenalite = () => { return ( {I18n.t('DELETE_PENALITE')} { this.passwordAnim = comp }}> { this.setState({password}) }} style={styles.input} > { if (this.checkOrShake(this.state.password, this.passwordAnim)) { this.props.deletePenalityAction(this.state.penality.id, { id_super: this.state.user.agentId, password: this.state.password, id_royalty_fee: this.state.penality.id_royalty_fee }); this.setState({ displayDialogDeletePenalite: false, displayLoader: true, isSubmitClick: true }); } }}/> { this.setState({ displayDialogDeletePenalite: false }); }}/> ) } renderBottomSheetOption = () => { return ( { this.bottomSheet = ref }} itemDivider={3} backButtonEnabled={true} coverScreen={false} title="Create" options={[ { title: I18n.t('MODIFY_PENALITE'), icon: ( ), onPress: () => { this.setState({ displayDialogModifyPenalite: true }); this.bottomSheet.close(); } }, { title: I18n.t('DELETE_PENALITE'), icon: ( ), onPress: () => { this.setState({ displayDialogDeletePenalite: true }); this.bottomSheet.close(); } } ]} isOpen={false} /> ) } _renderTabIndicator() { let tabs = [ { text: I18n.t('PENALITE'), iconSource: "edit" }, { text: I18n.t('TAXES'), iconSource: "edit" } ] return ; } renderDetailPenalite = () => { const {resultGetUniqueDemand} = this.props; 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('PENALITE')} { this.state.item.penalties.map(item => ( { item.n_order === 1 && { this.setState({penality: item, displayDialogModifyPenalite: true}) }} activeOpacity={0.9}> } { item.n_order === 1 && { this.setState({penality: item, displayDialogDeletePenalite: true}) }} activeOpacity={0.9}> } {item.id_revenue_order} {`Imputation: ${item.imputation}`} {`${item.name}`} {item.n_order === 1 && {`${I18n.t('TAUX')}: ${item.rate}%`} } {`${item.n_order === 1 ? item.amount : item.tax_amount}`} {moment(moment.tz(item.created_at, moment.tz.guess()).format()).fromNow()} {` ${I18n.t("YEAR")}: ${item.year}`} )) } {/* { this.royalties_fees_anim = comp }} style={{ width: responsiveWidth(100), height: 60, marginTop: 20, alignSelf: 'center', borderRadius: 10, paddingLeft: 20, paddingRight: 20, backgroundColor: 'white' }}> { this.setState({royalties_fees: value}, () => { console.log("royalties_fees", this.state.royalties_fees) }); }} valueExtractor={(value) => { return value }} labelExtractor={(value) => { return value.name + ' - ' + value.amount }} /> { this.ordreRecetteAnim = comp }}> { this.setState({ordreRecetteId}) }} style={styles.input} > { this.passwordAnim = comp }}> { this.setState({password}) }} style={styles.input} > */} ); } renderDetailTaxe = () => { return ( Bonjour ) } render() { return ( <> {this.renderModifyResponse()} {this.renderBottomSheetOption()} {this.renderDialogModifyPenalite()} {this.renderDialogDeletePenalite()} {this.state.displayLoader && this.renderLoader()} {this.state.isSubmitClick && this.renderDialogResponse()} {(this.state.triggerTreatmentClick || this.state.triggerCancelClick) && this.renderModifyResponse()} { { 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, loadingModifyPenality: state.modifyPenalityReducer.loading, resultModifyPenality: state.modifyPenalityReducer.result, errorModifyPenality: state.modifyPenalityReducer.error, loadingDeletePenality: state.deletePenalityReducer.loading, resultDeletePenality: state.deletePenalityReducer.result, errorDeletePenality: state.deletePenalityReducer.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, modifyPenalityAction, modifyPenalityReset, }, dispatch); export default connect(mapStateToProps, mapDispatchToProps)(PenalityTaxeDetail); 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, }, })