loan order screen update

This commit is contained in:
2025-07-04 23:50:28 +05:00
parent 6d79420f68
commit c93ef94125
2 changed files with 77 additions and 26 deletions

View File

@@ -9,11 +9,13 @@ import DateInput from '../../components/DateInput';
import { API_CONFIG } from '../../constants/api';
import apiService from '../../services/apiService';
import { useAuth } from '../../contexts/AuthContext';
import { useBaseEnums } from '../../contexts/BaseEnumsContext';
import { StatusBar } from 'expo-status-bar';
const CreateLoanOrderScreen = () => {
const navigation = useNavigation();
const { user } = useAuth();
const { getOptions } = useBaseEnums();
const [loanType, setLoanType] = useState('');
const [loanAmount, setLoanAmount] = useState('');
@@ -31,6 +33,25 @@ const CreateLoanOrderScreen = () => {
const [loanTypeOptions, setLoanTypeOptions] = useState([]);
const [regionOptions, setRegionOptions] = 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({});
useEffect(() => {
@@ -46,24 +67,17 @@ const CreateLoanOrderScreen = () => {
}
}
const fetchEnums = async () => {
try {
const res = await fetch(`${API_CONFIG.BASE_URL}/base-app-enums`);
const enums = await res.json();
const regions = Object.entries(enums.regions || {}).map(([value, label]) => ({ value, label }));
setRegionOptions(regions);
const pSeries = Object.keys(enums.passport_series || {}).map((key) => ({ value: key, label: key }));
setPassportSeriesOptions(pSeries);
} catch {}
};
const baseRegions = getOptions('regions');
const pSeries = getOptions('passport_series');
const loanTypes = getOptions('loan_types');
const educ = getOptions('educations');
const marriages = getOptions('marriage_statuses');
const fetchLoanTypes = async () => {
try {
const res = await fetch(`${API_CONFIG.BASE_URL}/loan-types`);
const list = await res.json();
setLoanTypeOptions(list.map((lt) => ({ value: lt.id, label: lt.name })));
} catch {}
};
setRegionOptions(baseRegions);
setPassportSeriesOptions(pSeries);
setLoanTypeOptions(loanTypes);
setEducationOptions(educ);
setMarriageOptions(marriages);
const fetchBranches = async () => {
try {
@@ -73,15 +87,13 @@ const CreateLoanOrderScreen = () => {
} catch {}
};
fetchEnums();
fetchLoanTypes();
fetchBranches();
}, []);
const branchOptions = region && branchesByRegion[region] ? branchesByRegion[region].map((b) => ({ label: b.name, value: b.id })) : [];
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');
return;
}
@@ -94,10 +106,27 @@ const CreateLoanOrderScreen = () => {
customer_name: customerName,
customer_surname: customerSurname,
customer_patronic_name: customerPatro || null,
education,
marriage_status: marriageStatus,
passport_address: passportAddress,
real_address: realAddress,
passport_serie: passportSerie,
passport_id: passportId.trim(),
passport_given_at: passportGivenAt,
passport_given_by: passportGivenBy,
born_place: bornPlace,
born_at: bornAt,
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);
@@ -130,11 +159,31 @@ const CreateLoanOrderScreen = () => {
<Input label="Familiýasy" placeholder="Allaberdiyev" value={customerSurname} onChangeText={setCustomerSurname} />
<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" />
<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} />
<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}>
{loading ? <ActivityIndicator color={COLORS.white} /> : <Text style={styles.submitText}>Ýatda sakla</Text>}

View File

@@ -43,8 +43,8 @@ const LoanOrdersScreen = () => {
};
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() : '';
return (
@@ -53,9 +53,11 @@ const LoanOrdersScreen = () => {
<Text style={styles.circleText}>{item.id}</Text>
</View>
<View style={styles.cardContent}>
<Text style={styles.passportText}>{passportLine}</Text>
<Text style={styles.accountLabel}>{amountLine}</Text>
<Text style={styles.accountValue}>{item.loan_amount || '-'}</Text>
<Text style={styles.passportText}>{item.loan_type}</Text>
<Text style={styles.accountLabel}>{amountLine}
<Text style={{ color: COLORS.textPrimary }}>{amount}</Text>
</Text>
<Text style={styles.dateText}>{created}</Text>
</View>
</TouchableOpacity>
@@ -125,7 +127,7 @@ const styles = StyleSheet.create({
passportText: { fontWeight: '700', color: COLORS.textPrimary, marginBottom: 4 },
accountLabel: { color: COLORS.textSecondary, fontSize: 14 },
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' },
emptyText: { fontSize: 16, color: COLORS.textSecondary },
fab: {