Loan paid off letter
This commit is contained in:
221
src/screens/Loan/CreateLoanPaidOffLetterOrderScreen.js
Normal file
221
src/screens/Loan/CreateLoanPaidOffLetterOrderScreen.js
Normal file
@@ -0,0 +1,221 @@
|
||||
import React, { useState } from 'react';
|
||||
import { Text, StyleSheet, TouchableOpacity, ActivityIndicator, Alert, ScrollView, SafeAreaView } from 'react-native';
|
||||
import { Ionicons } from '@expo/vector-icons';
|
||||
import { useNavigation } from '@react-navigation/native';
|
||||
import { COLORS } from '../../constants/colors';
|
||||
import Input from '../../components/Input';
|
||||
import { StatusBar } from 'expo-status-bar';
|
||||
import apiService from '../../services/apiService';
|
||||
|
||||
const CreateLoanPaidOffLetterOrderScreen = () => {
|
||||
const navigation = useNavigation();
|
||||
|
||||
// Form states (required fields only)
|
||||
const [region, setRegion] = useState('');
|
||||
const [branchId, setBranchId] = useState('');
|
||||
const [customerName, setCustomerName] = useState('');
|
||||
const [customerSurname, setCustomerSurname] = useState('');
|
||||
const [passportSerie, setPassportSerie] = useState('');
|
||||
const [passportId, setPassportId] = useState('');
|
||||
const [bornAt, setBornAt] = useState('');
|
||||
const [phone, setPhone] = useState('');
|
||||
const [contractNumber, setContractNumber] = useState('');
|
||||
const [contractDate, setContractDate] = useState('');
|
||||
const [loanAmount, setLoanAmount] = useState('');
|
||||
const [loanReason, setLoanReason] = useState('');
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
const handleSubmit = async () => {
|
||||
// Basic validation – ensure all required fields are filled
|
||||
if (
|
||||
!region ||
|
||||
!branchId ||
|
||||
!customerName ||
|
||||
!customerSurname ||
|
||||
!passportSerie ||
|
||||
!passportId ||
|
||||
!bornAt ||
|
||||
!phone ||
|
||||
!contractNumber ||
|
||||
!contractDate ||
|
||||
!loanAmount ||
|
||||
!loanReason
|
||||
) {
|
||||
Alert.alert('Error', 'Please fill in all required fields');
|
||||
return;
|
||||
}
|
||||
|
||||
const payload = {
|
||||
region,
|
||||
branch_id: parseInt(branchId),
|
||||
customer_name: customerName,
|
||||
customer_surname: customerSurname,
|
||||
passport_serie: passportSerie,
|
||||
passport_id: parseInt(passportId),
|
||||
born_at: bornAt,
|
||||
phone: parseInt(phone),
|
||||
loan_contract_number: contractNumber,
|
||||
loan_contract_date: contractDate,
|
||||
loan_amount: loanAmount,
|
||||
loan_reason: loanReason,
|
||||
};
|
||||
|
||||
try {
|
||||
setLoading(true);
|
||||
const res = await apiService.createLoanPaidOffLetterOrder(payload);
|
||||
setLoading(false);
|
||||
|
||||
if (res.success) {
|
||||
Alert.alert('Success', res.message || 'Order created successfully', [
|
||||
{ text: 'OK', onPress: () => navigation.goBack() },
|
||||
]);
|
||||
} else {
|
||||
Alert.alert('Error', res.error || 'Could not create order');
|
||||
}
|
||||
} catch (error) {
|
||||
setLoading(false);
|
||||
Alert.alert('Error', error.message || 'Could not create order');
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<SafeAreaView style={styles.container}>
|
||||
<StatusBar style="dark" />
|
||||
<TouchableOpacity style={styles.backBtn} onPress={() => navigation.goBack()}>
|
||||
<Ionicons name="arrow-back" size={24} color={COLORS.textPrimary} />
|
||||
</TouchableOpacity>
|
||||
|
||||
<ScrollView contentContainerStyle={{ paddingBottom: 40 }} showsVerticalScrollIndicator={false}>
|
||||
<Text style={styles.title}>Täze güwanama sargyt et</Text>
|
||||
|
||||
{/* Region & Branch */}
|
||||
<Input
|
||||
label="Region (ag, ak, mr, ... )"
|
||||
placeholder="mr"
|
||||
value={region}
|
||||
onChangeText={setRegion}
|
||||
autoCapitalize="none"
|
||||
/>
|
||||
<Input
|
||||
label="Şahamça ID-si"
|
||||
placeholder="12"
|
||||
value={branchId}
|
||||
onChangeText={setBranchId}
|
||||
keyboardType="numeric"
|
||||
/>
|
||||
|
||||
{/* Customer */}
|
||||
<Input
|
||||
label="Ady"
|
||||
placeholder="Mahmyt"
|
||||
value={customerName}
|
||||
onChangeText={setCustomerName}
|
||||
/>
|
||||
<Input
|
||||
label="Familiýasy"
|
||||
placeholder="Allaberdiyev"
|
||||
value={customerSurname}
|
||||
onChangeText={setCustomerSurname}
|
||||
/>
|
||||
|
||||
{/* Passport */}
|
||||
<Input
|
||||
label="Passport seriýasy"
|
||||
placeholder="I-AS"
|
||||
value={passportSerie}
|
||||
onChangeText={setPassportSerie}
|
||||
autoCapitalize="characters"
|
||||
/>
|
||||
<Input
|
||||
label="Passport nomeri"
|
||||
placeholder="100999"
|
||||
value={passportId}
|
||||
onChangeText={setPassportId}
|
||||
keyboardType="numeric"
|
||||
/>
|
||||
|
||||
{/* Other personal */}
|
||||
<Input
|
||||
label="Doglan senesi (DD.MM.YYYY)"
|
||||
placeholder="10.10.2000"
|
||||
value={bornAt}
|
||||
onChangeText={setBornAt}
|
||||
/>
|
||||
<Input
|
||||
label="Telefon belgi (+9936...)"
|
||||
placeholder="65999990"
|
||||
value={phone}
|
||||
onChangeText={setPhone}
|
||||
keyboardType="numeric"
|
||||
/>
|
||||
|
||||
{/* Loan contract */}
|
||||
<Input
|
||||
label="Karz şertnama nomeri"
|
||||
placeholder="3242358989234"
|
||||
value={contractNumber}
|
||||
onChangeText={setContractNumber}
|
||||
/>
|
||||
<Input
|
||||
label="Karz şertnama senesi"
|
||||
placeholder="20.04.2022"
|
||||
value={contractDate}
|
||||
onChangeText={setContractDate}
|
||||
/>
|
||||
<Input
|
||||
label="Karz mukdary"
|
||||
placeholder="20000"
|
||||
value={loanAmount}
|
||||
onChangeText={setLoanAmount}
|
||||
keyboardType="numeric"
|
||||
/>
|
||||
<Input
|
||||
label="Karz maksady"
|
||||
placeholder="Puldan pul gazanmak üçin"
|
||||
value={loanReason}
|
||||
onChangeText={setLoanReason}
|
||||
/>
|
||||
|
||||
<TouchableOpacity style={styles.submitBtn} onPress={handleSubmit} disabled={loading}>
|
||||
{loading ? (
|
||||
<ActivityIndicator color={COLORS.white} />
|
||||
) : (
|
||||
<Text style={styles.submitText}>Ýatda sakla</Text>
|
||||
)}
|
||||
</TouchableOpacity>
|
||||
</ScrollView>
|
||||
</SafeAreaView>
|
||||
);
|
||||
};
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
container: {
|
||||
flex: 1,
|
||||
backgroundColor: COLORS.backgroundSecondary,
|
||||
paddingHorizontal: 24,
|
||||
paddingTop: 40,
|
||||
},
|
||||
backBtn: {
|
||||
marginBottom: 24,
|
||||
},
|
||||
title: {
|
||||
fontSize: 24,
|
||||
fontWeight: 'bold',
|
||||
color: COLORS.textPrimary,
|
||||
marginBottom: 24,
|
||||
},
|
||||
submitBtn: {
|
||||
marginTop: 32,
|
||||
backgroundColor: COLORS.primary,
|
||||
paddingVertical: 16,
|
||||
borderRadius: 8,
|
||||
alignItems: 'center',
|
||||
},
|
||||
submitText: {
|
||||
color: COLORS.white,
|
||||
fontSize: 16,
|
||||
fontWeight: '600',
|
||||
},
|
||||
});
|
||||
|
||||
export default CreateLoanPaidOffLetterOrderScreen;
|
||||
Reference in New Issue
Block a user