simba-mobile-cud/app/screens/wallet/regisseur/OrdreRecetteDetail.js

862 lines
32 KiB
JavaScript
Raw Normal View History

2025-01-07 09:47:45 +00:00
import React, {Component} from 'react'
import {ActivityIndicator, Alert, Platform, ProgressBarAndroid, ScrollView, StyleSheet, Text, View} from 'react-native'
import Button from 'apsl-react-native-button'
import {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 {
getOrdreRecetteDetailAction,
getOrdreRecetteReset,
modifyAvisImpositionReset,
modifyOrdreRecetteAction,
saveOrdreRecetteAction
} from "../../../webservice/regisseur/WalletRegisseurApi";
import {store} from "../../../redux/store";
import axios from "axios";
import {getOneTaxNoticeUrl} from "../../../webservice/IlinkConstants";
import {displayToast} from "../../../utils/UtilsFunction";
let typesta = 0
let moment = require('moment-timezone')
var colorback = 'white'
let theme = require('../../../utils/theme.json');
const route = require("../../../route.json");
class OrdonnanceDetail 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),
codeAgent: this.props.navigation.getParam("codeAgent", null),
assign_network: false,
ordreRecetteId: this.props.navigation.getParam("isModify", false) ? this.props.navigation.getParam("item", null).id_revenue_order : null,
number_of_days: this.props.navigation.getParam("isModify", false) ? this.props.navigation.getParam("item", null).number_of_days !== null ? '' + this.props.navigation.getParam("item", null).number_of_days : '' : 0,
penality_fees: null,
tax_notice_amount: this.props.navigation.getParam("item", null).tax_notice_amount
};
console.log("STATE", this.state);
this.currentLocale = I18n.locale.includes("fr") ? "fr" : "en-gb";
this.props.modifyAvisImpositionReset();
moment.locale(this.currentLocale);
}
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));
}
refreshScreen = (id) => {
const auth = store.getState().authKeyReducer;
const authKey = auth !== null ? `${auth.authKey.token_type} ${auth.authKey.access_token}` : '';
console.log(`URL: ${getOneTaxNoticeUrl}/${id}`);
axios({
url: `${getOneTaxNoticeUrl}/${id}`,
method: 'GET',
headers: {
'Authorization': authKey,
'X-Localization': I18n.currentLocale()
}
})
.then(response => {
console.log("RESPONSE", response);
if (!this.state.isModify) {
if (response.data.response.penalties.length === 0 && response.data.response.royalties_fees.length === 0)
this.props.navigation.goBack();
else {
this.setState({
item: response.data.response,
tax_notice_amount: response.data.response.tax_notice_amount,
royalties_fees: null,
penality_fees: null
});
}
} else {
this.setState({
item: response.data.response,
tax_notice_amount: response.data.response.tax_notice_amount,
royalties_fees: null,
penality_fees: null
});
}
})
.catch(error => {
console.log("ERROR", error);
let message = "";
if (error.response)
message = error.response
else if (error.request)
message = error.request
else
message = error.request;
console.log("Message d'erreur", message);
});
}
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"),
resultModifyAvis.response,
[
{
text: I18n.t("OK"), onPress: () => {
this.props.navigation.pop(2);
this.props.modifyAvisImpositionReset();
this.props.getOrdreRecetteDetailAction(this.state.codeAgent);
this.refreshScreen(this.state.item.id);
}
}
],
{cancelable: false}
);
} else {
Alert.alert(
I18n.t("SUCCESS"),
resultModifyAvis.response,
[
{
text: I18n.t("OK"), onPress: () => {
this.props.navigation.pop(2);
this.props.modifyAvisImpositionReset();
this.refreshScreen(this.state.item.id);
this.props.getOrdreRecetteReset();
}
}
],
{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 (
<View style={{flex: 1, justifyContent: 'center', alignItems: 'center'}}>
{Platform.OS === 'android'
?
(
<>
<ProgressBarAndroid/>
<Text>{I18n.t('LOADING_DOTS')}</Text>
</>
) :
<>
<ActivityIndicator size="large" color={'#ccc'}/>
<Text>{I18n.t('LOADING_DOTS')}</Text>
</>
}
</View>
)
}
renderDetail = () => {
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 (<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)
}}>
{I18n.t('TAXE_INFORMATION')}
</Text>
{
!isNil(this.state.tax_notice_amount) &&
<View style={{
flexDirection: 'row',
justifyContent: 'flex-start'
}}>
<Icon name="cash"
size={28}
color={theme.accent}
style={{
marginLeft: 20
}}
/>
<Text
style={styles.simpleuser}>{`${this.state.tax_notice_amount}`}</Text>
</View>
}
{
this.state.isModify &&
<>
<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} (${I18n.t('AMOUNT_ORDRE_RECETTE')})`}</Text>
</View>
<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.penalties_amount} (${I18n.t('PENALITE_INCLUSE')})`}</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('EMISSION_DATE')}: ${issue_date.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 style={{
flex: 1,
flexDirection: 'row',
justifyContent: 'flex-start'
}}>
</View>
</View>
<Animatable.View ref={(comp) => {
this.royalties_fees_anim = comp
}}
style={{
width: responsiveWidth(100),
height: 60,
marginTop: 20,
alignSelf: 'center',
borderRadius: 10,
paddingLeft: 20,
paddingRight: 20,
backgroundColor: 'white'
}}>
<Dropdown
label={this.state.isModify ? this.state.item.prototype === "T" ? I18n.t('TAXES') : I18n.t('PENALITES') : I18n.t('TAXES')}
disabled={this.state.isModify}
data={this.state.isModify ? [] : item.royalties_fees}
useNativeDriver={true}
value={this.state.isModify ? this.state.item.tax_name : this.state.royalties_fees === null ? "" :
this.state.royalties_fees}
onChangeText={(value, index, data) => {
this.setState({royalties_fees: value, penality_fees: null}, () => {
console.log("royalties_fees", this.state.royalties_fees)
});
}}
valueExtractor={(value) => {
return value
}}
labelExtractor={(value) => {
return value.name + ' - ' + value.amount
}}
/>
</Animatable.View>
{this.state.royalties_fees !== null &&
<View style={{flexDirection: "column", paddingTop: 5, marginLeft: 25}}>
<Text primaryColor caption1>
{`${I18n.t('AMOUNT')}: ${this.state.royalties_fees.amount}`}
</Text>
<Text primaryColor caption1>
{`${I18n.t('PENALITE_INCLUSE')}: ${this.state.royalties_fees.penalties_amount}`}
</Text>
</View>}
{/* {
!this.state.isModify &&
<Animatable.View ref={(comp) => {
this.penalities_anim = comp
}}
style={{
width: responsiveWidth(100),
height: 60,
marginTop: 20,
alignSelf: 'center',
borderRadius: 10,
paddingLeft: 20,
paddingRight: 20,
backgroundColor: 'white'
}}>
<Dropdown
label={I18n.t('PENALITES')}
data={item.penalties}
useNativeDriver={true}
onChangeText={(value, index, data) => {
fetchRecalculatePenality(value.id).then((response) => {
let penalities = item.penalties;
penalities = penalities.map(penality => {
if (penality.id === value.id)
return response.data.response;
else
return penality;
});
this.setState({
tax_notice_amount: response.data.response.tax_notice_amount,
penality_fees: response.data.response,
royalties_fees: null
}, () => {
console.log("ITEM", this.state.item);
console.log("PENALTIES", this.state.penality_fees);
});
}).catch((error) => {
});
}}
valueExtractor={(value) => {
return value
}}
labelExtractor={(value) => {
return this.state.penality_fees !== null
? value.id === this.state.penality_fees.id
? this.state.penality_fees.name + ' - ' + this.state.penality_fees.total_amount
: value.total_amount + ' - ' + value.name
: value.total_amount + ' - ' + value.name;
}}
/>
</Animatable.View>
}*/}
{
this.state.royalties_fees !== null ? (
this.state.royalties_fees.billing_period === 'jour' &&
(<Animatable.View ref={(comp) => {
this.ordreRecetteAnim = comp
}}>
<Fumi iconClass={FontAwesomeIcon} iconName={'calendar'}
label={I18n.t('NUMBER_OF_DAYS')}
iconColor={'#f95a25'}
iconSize={20}
keyboardType='numeric'
value={this.state.number_of_days}
onChangeText={(number_of_days) => {
this.setState({number_of_days})
}}
style={styles.input}
>
</Fumi>
</Animatable.View>)
) : null
}
{
this.state.penality_fees !== null ? (
this.state.penality_fees.billing_period === 'jour' &&
(<Animatable.View ref={(comp) => {
this.ordreRecetteAnim = comp
}}>
<Fumi iconClass={FontAwesomeIcon} iconName={'calendar'}
label={I18n.t('NUMBER_OF_DAYS')}
iconColor={'#f95a25'}
iconSize={20}
keyboardType='numeric'
value={this.state.number_of_days}
onChangeText={(number_of_days) => {
this.setState({number_of_days})
}}
style={styles.input}
>
</Fumi>
</Animatable.View>)
) : null
}
{
this.state.isModify ?
this.state.item.tax_billing_period === 'jour' &&
<Animatable.View ref={(comp) => {
this.ordreRecetteAnim = comp
}}>
<Fumi iconClass={FontAwesomeIcon} iconName={'calendar'}
label={I18n.t('NUMBER_OF_DAYS')}
iconColor={'#f95a25'}
iconSize={20}
keyboardType='numeric'
value={this.state.number_of_days}
onChangeText={(number_of_days) => {
this.setState({number_of_days})
}}
style={styles.input}
>
</Fumi>
</Animatable.View>
: null
}
<Animatable.View ref={(comp) => {
this.ordreRecetteAnim = comp
}}>
<Fumi iconClass={FontAwesomeIcon} iconName={'file'}
label={I18n.t('ORDRE_DE_RECETTE_NUMBER')}
iconColor={'#f95a25'}
iconSize={20}
value={this.state.ordreRecetteId}
onChangeText={(ordreRecetteId) => {
this.setState({ordreRecetteId})
}}
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 style={{
flexDirection: 'row',
paddingTop: 10
}}>
<View style={{
flex: 1,
alignItems: 'center'
}}>
<Button
style={{
borderColor: 'transparent',
borderRadius: 6,
marginLeft: 5,
marginRight: 5,
backgroundColor: 'green'
}}
isLoading={this.props.loadingModifyAvis}
onPress={() => {
this.setState({loadingModifyAvis: true});
this.onSubmitModificationAvisImposition();
}}
disabled={true}
textStyle={styles.textbtnstyle}
>
{this.state.isModify ? I18n.t('MODIFY') : I18n.t('SAVE')}
</Button>
</View>
</View>
</ScrollView>);
}
onSubmitModificationAvisImposition = () => {
const {password, item, taxes, assign_network, ordreRecetteId, number_of_days} = this.state;
if (this.ckeckIfFieldIsOK(this.state.royalties_fees) && this.ckeckIfFieldIsOK(this.state.penality_fees) && !this.state.isModify) {
this.royalties_fees_anim.shake(200);
} else if (this.ckeckIfFieldIsOK(ordreRecetteId)) {
this.ordreRecetteAnim.shake(200);
} else if (this.ckeckIfFieldIsOK(ordreRecetteId)) {
this.ordreRecetteAnim.shake(200);
} else if (this.ckeckIfFieldIsOK(password)) {
this.passwordAnim.shake(200);
} else if (number_of_days <= 0 && number_of_days > 366) {
displayToast(I18n.t('NUMBER_OF_DAYS_INCORRECT'));
} else {
let dataToSubmit = {};
if (this.state.isModify) {
dataToSubmit = {
id_super: parseInt(this.state.user.agentId),
id_revenue_order: ordreRecetteId,
password: password,
id_tax_notice: parseInt(item.id),
}
if (this.state.item.tax_billing_period === 'jour')
dataToSubmit['number_of_days'] = number_of_days;
this.props.modifyOrdreRecetteAction(item.id, dataToSubmit);
} else {
if (this.state.penality_fees === null) {
dataToSubmit = {
id_super: parseInt(this.state.user.agentId),
id_revenue_order: ordreRecetteId,
password: password,
id_tax_notice: parseInt(item.id),
id_royalty_fee: this.state.royalties_fees.id,
}
if (this.state.royalties_fees.billing_period === 'jour')
dataToSubmit['number_of_days'] = number_of_days;
} else {
dataToSubmit = {
id_super: parseInt(this.state.user.agentId),
id_revenue_order: ordreRecetteId,
password: password,
id_tax_notice: parseInt(item.id),
id_tax_penalty: this.state.penality_fees.id
}
if (this.state.penality_fees.billing_period === 'jour')
dataToSubmit['number_of_days'] = number_of_days;
}
this.props.saveOrdreRecetteAction(dataToSubmit);
}
}
}
render() {
console.log("PENALITIES", this.state.penality_fees);
return (
<>
{this.renderModifyResponse()}
{
this.renderDetail()
}
</>
);
}
}
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,
});
const mapDispatchToProps = dispatch => bindActionCreators({
getNanoCreditUniqueDemandsAction: getNanoCreditUniqueDemandsAction,
getNanoCreditUniqueDemandsReset: getNanoCreditUniqueDemandsReset,
treatDemandGroupAction: treatDemandGroupAction,
cancelDemandGroupAction: cancelDemandGroupAction,
treatDemandGroupReset: treatDemandGroupReset,
treatCreditDemand: treatCreditDemand,
creditDemandResetReducer: creditDemandResetReducer,
treatCancelDemand: treatCancelDemand,
creditCancelResetReducer: creditCancelResetReducer,
saveOrdreRecetteAction,
modifyAvisImpositionReset,
getOrdreRecetteDetailAction,
getOrdreRecetteReset,
modifyOrdreRecetteAction
}, dispatch);
export default connect(mapStateToProps, mapDispatchToProps)(OrdonnanceDetail);
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",
marginBottom: 20,
},
checkbox: {
alignSelf: "center",
color: "white"
},
})