loan order screen update
This commit is contained in:
@@ -9,11 +9,13 @@ import DateInput from '../../components/DateInput';
|
|||||||
import { API_CONFIG } from '../../constants/api';
|
import { API_CONFIG } from '../../constants/api';
|
||||||
import apiService from '../../services/apiService';
|
import apiService from '../../services/apiService';
|
||||||
import { useAuth } from '../../contexts/AuthContext';
|
import { useAuth } from '../../contexts/AuthContext';
|
||||||
|
import { useBaseEnums } from '../../contexts/BaseEnumsContext';
|
||||||
import { StatusBar } from 'expo-status-bar';
|
import { StatusBar } from 'expo-status-bar';
|
||||||
|
|
||||||
const CreateLoanOrderScreen = () => {
|
const CreateLoanOrderScreen = () => {
|
||||||
const navigation = useNavigation();
|
const navigation = useNavigation();
|
||||||
const { user } = useAuth();
|
const { user } = useAuth();
|
||||||
|
const { getOptions } = useBaseEnums();
|
||||||
|
|
||||||
const [loanType, setLoanType] = useState('');
|
const [loanType, setLoanType] = useState('');
|
||||||
const [loanAmount, setLoanAmount] = useState('');
|
const [loanAmount, setLoanAmount] = useState('');
|
||||||
@@ -31,6 +33,25 @@ const CreateLoanOrderScreen = () => {
|
|||||||
const [loanTypeOptions, setLoanTypeOptions] = useState([]);
|
const [loanTypeOptions, setLoanTypeOptions] = useState([]);
|
||||||
const [regionOptions, setRegionOptions] = useState([]);
|
const [regionOptions, setRegionOptions] = useState([]);
|
||||||
const [passportSeriesOptions, setPassportSeriesOptions] = useState([]);
|
const [passportSeriesOptions, setPassportSeriesOptions] = useState([]);
|
||||||
|
const [educationOptions, setEducationOptions] = useState([]);
|
||||||
|
const [marriageOptions, setMarriageOptions] = useState([]);
|
||||||
|
const [education, setEducation] = useState('');
|
||||||
|
const [marriageStatus, setMarriageStatus] = useState('');
|
||||||
|
const [passportAddress, setPassportAddress] = useState('');
|
||||||
|
const [realAddress, setRealAddress] = useState('');
|
||||||
|
const [passportGivenAt, setPassportGivenAt] = useState('');
|
||||||
|
const [passportGivenBy, setPassportGivenBy] = useState('');
|
||||||
|
const [bornPlace, setBornPlace] = useState('');
|
||||||
|
const [email, setEmail] = useState('');
|
||||||
|
const [phoneAdditional, setPhoneAdditional] = useState('');
|
||||||
|
const [phoneHome, setPhoneHome] = useState('');
|
||||||
|
const [workCompany, setWorkCompany] = useState('');
|
||||||
|
const [workCompanyAccNum, setWorkCompanyAccNum] = useState('');
|
||||||
|
const [workRegion, setWorkRegion] = useState('');
|
||||||
|
const [workProvinceId, setWorkProvinceId] = useState('');
|
||||||
|
const [workPosition, setWorkPosition] = useState('');
|
||||||
|
const [workSalary, setWorkSalary] = useState('');
|
||||||
|
const [workStartedAt, setWorkStartedAt] = useState('');
|
||||||
const [branchesByRegion, setBranchesByRegion] = useState({});
|
const [branchesByRegion, setBranchesByRegion] = useState({});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -46,24 +67,17 @@ const CreateLoanOrderScreen = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const fetchEnums = async () => {
|
const baseRegions = getOptions('regions');
|
||||||
try {
|
const pSeries = getOptions('passport_series');
|
||||||
const res = await fetch(`${API_CONFIG.BASE_URL}/base-app-enums`);
|
const loanTypes = getOptions('loan_types');
|
||||||
const enums = await res.json();
|
const educ = getOptions('educations');
|
||||||
const regions = Object.entries(enums.regions || {}).map(([value, label]) => ({ value, label }));
|
const marriages = getOptions('marriage_statuses');
|
||||||
setRegionOptions(regions);
|
|
||||||
const pSeries = Object.keys(enums.passport_series || {}).map((key) => ({ value: key, label: key }));
|
|
||||||
setPassportSeriesOptions(pSeries);
|
|
||||||
} catch {}
|
|
||||||
};
|
|
||||||
|
|
||||||
const fetchLoanTypes = async () => {
|
setRegionOptions(baseRegions);
|
||||||
try {
|
setPassportSeriesOptions(pSeries);
|
||||||
const res = await fetch(`${API_CONFIG.BASE_URL}/loan-types`);
|
setLoanTypeOptions(loanTypes);
|
||||||
const list = await res.json();
|
setEducationOptions(educ);
|
||||||
setLoanTypeOptions(list.map((lt) => ({ value: lt.id, label: lt.name })));
|
setMarriageOptions(marriages);
|
||||||
} catch {}
|
|
||||||
};
|
|
||||||
|
|
||||||
const fetchBranches = async () => {
|
const fetchBranches = async () => {
|
||||||
try {
|
try {
|
||||||
@@ -73,15 +87,13 @@ const CreateLoanOrderScreen = () => {
|
|||||||
} catch {}
|
} catch {}
|
||||||
};
|
};
|
||||||
|
|
||||||
fetchEnums();
|
|
||||||
fetchLoanTypes();
|
|
||||||
fetchBranches();
|
fetchBranches();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const branchOptions = region && branchesByRegion[region] ? branchesByRegion[region].map((b) => ({ label: b.name, value: b.id })) : [];
|
const branchOptions = region && branchesByRegion[region] ? branchesByRegion[region].map((b) => ({ label: b.name, value: b.id })) : [];
|
||||||
|
|
||||||
const handleSubmit = async () => {
|
const handleSubmit = async () => {
|
||||||
if (!loanType || !loanAmount || !region || !branchId || !customerName || !customerSurname || !passportSerie || !passportId || !bornAt || !phone) {
|
if (!loanType || !loanAmount || !region || !branchId || !customerName || !customerSurname || !passportSerie || !passportId || !bornAt || !phone || !education || !marriageStatus || !passportAddress || !realAddress) {
|
||||||
Alert.alert('Error', 'Fill all required fields');
|
Alert.alert('Error', 'Fill all required fields');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -94,10 +106,27 @@ const CreateLoanOrderScreen = () => {
|
|||||||
customer_name: customerName,
|
customer_name: customerName,
|
||||||
customer_surname: customerSurname,
|
customer_surname: customerSurname,
|
||||||
customer_patronic_name: customerPatro || null,
|
customer_patronic_name: customerPatro || null,
|
||||||
|
education,
|
||||||
|
marriage_status: marriageStatus,
|
||||||
|
passport_address: passportAddress,
|
||||||
|
real_address: realAddress,
|
||||||
passport_serie: passportSerie,
|
passport_serie: passportSerie,
|
||||||
passport_id: passportId.trim(),
|
passport_id: passportId.trim(),
|
||||||
|
passport_given_at: passportGivenAt,
|
||||||
|
passport_given_by: passportGivenBy,
|
||||||
|
born_place: bornPlace,
|
||||||
born_at: bornAt,
|
born_at: bornAt,
|
||||||
phone: parseInt(phone),
|
phone: parseInt(phone),
|
||||||
|
email: email || null,
|
||||||
|
phone_additional: phoneAdditional ? parseInt(phoneAdditional) : null,
|
||||||
|
phone_home: phoneHome || null,
|
||||||
|
work_company: workCompany || null,
|
||||||
|
work_company_accountant_number: workCompanyAccNum || null,
|
||||||
|
work_region: workRegion || null,
|
||||||
|
work_province_id: workProvinceId ? parseInt(workProvinceId) : null,
|
||||||
|
work_position: workPosition || null,
|
||||||
|
work_salary: workSalary ? parseInt(workSalary) : null,
|
||||||
|
work_started_at: workStartedAt || null,
|
||||||
};
|
};
|
||||||
|
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
@@ -130,11 +159,31 @@ const CreateLoanOrderScreen = () => {
|
|||||||
<Input label="Familiýasy" placeholder="Allaberdiyev" value={customerSurname} onChangeText={setCustomerSurname} />
|
<Input label="Familiýasy" placeholder="Allaberdiyev" value={customerSurname} onChangeText={setCustomerSurname} />
|
||||||
<Input label="Atasynyň ady" placeholder="" value={customerPatro} onChangeText={setCustomerPatro} />
|
<Input label="Atasynyň ady" placeholder="" value={customerPatro} onChangeText={setCustomerPatro} />
|
||||||
|
|
||||||
|
<SelectInput label="Bilimi" value={education} options={educationOptions} onValueChange={setEducation} placeholder="Saýla" />
|
||||||
|
<SelectInput label="Maşgala ýagdaýy" value={marriageStatus} options={marriageOptions} onValueChange={setMarriageStatus} placeholder="Saýla" />
|
||||||
|
|
||||||
|
<Input label="Ýazgy edilen salgyňyz" placeholder="Kemine 100/190" value={passportAddress} onChangeText={setPassportAddress} />
|
||||||
|
<Input label="Häzirki ýaşaýyş ýeri" placeholder="Kemine 100/200" value={realAddress} onChangeText={setRealAddress} />
|
||||||
|
|
||||||
<SelectInput label="Passport seriýasy" value={passportSerie} options={passportSeriesOptions} onValueChange={setPassportSerie} placeholder="Saýla" />
|
<SelectInput label="Passport seriýasy" value={passportSerie} options={passportSeriesOptions} onValueChange={setPassportSerie} placeholder="Saýla" />
|
||||||
<Input label="Passport nomeri" placeholder="100999" value={passportId} onChangeText={setPassportId} keyboardType="numeric" />
|
<Input label="Passport nomeri" placeholder="100999" value={passportId} onChangeText={setPassportId} keyboardType="numeric" />
|
||||||
|
<DateInput label="Passport berlen senesi" value={passportGivenAt} onChange={setPassportGivenAt} />
|
||||||
|
<Input label="Kim tarapyndan berildi" placeholder="Ashgabat polisiýasy tarapyndan" value={passportGivenBy} onChangeText={setPassportGivenBy} />
|
||||||
|
<Input label="Doglan ýeri (passport)" placeholder="Ashgabat" value={bornPlace} onChangeText={setBornPlace} />
|
||||||
|
<Input label="E-poçta" placeholder="example@mail.com" value={email} onChangeText={setEmail} keyboardType="email-address" />
|
||||||
|
|
||||||
<DateInput label="Doglan senesi" value={bornAt} onChange={setBornAt} />
|
<DateInput label="Doglan senesi" value={bornAt} onChange={setBornAt} />
|
||||||
<Input label="Telefon (+9936...)" value={phone} onChangeText={setPhone} keyboardType="numeric" />
|
<Input label="Telefon (+9936...)" value={phone} onChangeText={setPhone} keyboardType="numeric" />
|
||||||
|
<Input label="Telefon goşmaça" value={phoneAdditional} onChangeText={setPhoneAdditional} keyboardType="numeric" />
|
||||||
|
<Input label="Öý telefony" value={phoneHome} onChangeText={setPhoneHome} />
|
||||||
|
|
||||||
|
<Input label="Işleýän edaranyň/kärhananyň ady" value={workCompany} onChangeText={setWorkCompany} />
|
||||||
|
<Input label="Işgärler bölüminiň iş belgisi" value={workCompanyAccNum} onChangeText={setWorkCompanyAccNum} />
|
||||||
|
<SelectInput label="Işleýän welaýatyňyz" value={workRegion} options={regionOptions} onValueChange={(val)=>{setWorkRegion(val); setWorkProvinceId('');}} placeholder="Saýla" />
|
||||||
|
<SelectInput label="Işleýän etrabyňyz" value={workProvinceId} options={workRegion && branchesByRegion[workRegion] ? branchesByRegion[workRegion].map(b=>({label:b.name,value:b.id})) : []} onValueChange={setWorkProvinceId} placeholder="Saýla" disabled={!workRegion} />
|
||||||
|
<Input label="Wezipe" value={workPosition} onChangeText={setWorkPosition} />
|
||||||
|
<Input label="Zähmet haky" value={workSalary} onChangeText={setWorkSalary} keyboardType="numeric" />
|
||||||
|
<DateInput label="Işe başlan wagtyňyz" value={workStartedAt} onChange={setWorkStartedAt} />
|
||||||
|
|
||||||
<TouchableOpacity style={styles.submitBtn} onPress={handleSubmit} disabled={loading}>
|
<TouchableOpacity style={styles.submitBtn} onPress={handleSubmit} disabled={loading}>
|
||||||
{loading ? <ActivityIndicator color={COLORS.white} /> : <Text style={styles.submitText}>Ýatda sakla</Text>}
|
{loading ? <ActivityIndicator color={COLORS.white} /> : <Text style={styles.submitText}>Ýatda sakla</Text>}
|
||||||
|
|||||||
@@ -43,8 +43,8 @@ const LoanOrdersScreen = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const renderItem = ({ item }) => {
|
const renderItem = ({ item }) => {
|
||||||
const passportLine = `Pasport: ${item.passport_serie} ${item.passport_id}`;
|
const amountLine = `Karz mukdary: `;
|
||||||
const amountLine = `Karz mukdary:`;
|
const amount = (item.loan_amount + ' TMT') || '-';
|
||||||
const created = item.created_at ? new Date(item.created_at).toLocaleDateString() : '';
|
const created = item.created_at ? new Date(item.created_at).toLocaleDateString() : '';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -53,9 +53,11 @@ const LoanOrdersScreen = () => {
|
|||||||
<Text style={styles.circleText}>{item.id}</Text>
|
<Text style={styles.circleText}>{item.id}</Text>
|
||||||
</View>
|
</View>
|
||||||
<View style={styles.cardContent}>
|
<View style={styles.cardContent}>
|
||||||
<Text style={styles.passportText}>{passportLine}</Text>
|
<Text style={styles.passportText}>{item.loan_type}</Text>
|
||||||
<Text style={styles.accountLabel}>{amountLine}</Text>
|
<Text style={styles.accountLabel}>{amountLine}
|
||||||
<Text style={styles.accountValue}>{item.loan_amount || '-'}</Text>
|
<Text style={{ color: COLORS.textPrimary }}>{amount}</Text>
|
||||||
|
</Text>
|
||||||
|
|
||||||
<Text style={styles.dateText}>{created}</Text>
|
<Text style={styles.dateText}>{created}</Text>
|
||||||
</View>
|
</View>
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
@@ -125,7 +127,7 @@ const styles = StyleSheet.create({
|
|||||||
passportText: { fontWeight: '700', color: COLORS.textPrimary, marginBottom: 4 },
|
passportText: { fontWeight: '700', color: COLORS.textPrimary, marginBottom: 4 },
|
||||||
accountLabel: { color: COLORS.textSecondary, fontSize: 14 },
|
accountLabel: { color: COLORS.textSecondary, fontSize: 14 },
|
||||||
accountValue: { color: COLORS.textPrimary, marginBottom: 4 },
|
accountValue: { color: COLORS.textPrimary, marginBottom: 4 },
|
||||||
dateText: { color: COLORS.textSecondary, fontSize: 12 },
|
dateText: { color: COLORS.textSecondary, fontSize: 12, textAlign: 'right' },
|
||||||
emptyContainer: { flex: 1, justifyContent: 'center', alignItems: 'center' },
|
emptyContainer: { flex: 1, justifyContent: 'center', alignItems: 'center' },
|
||||||
emptyText: { fontSize: 16, color: COLORS.textSecondary },
|
emptyText: { fontSize: 16, color: COLORS.textSecondary },
|
||||||
fab: {
|
fab: {
|
||||||
|
|||||||
Reference in New Issue
Block a user