karz sargytlary done
This commit is contained in:
@@ -75,8 +75,25 @@ const CreateLoanOrderScreen = () => {
|
||||
const [guarantorPassportSerie, setGuarantorPassportSerie] = useState('');
|
||||
const [guarantorPassportId, setGuarantorPassportId] = useState('');
|
||||
|
||||
// Guarantor 2 fields (visible when loan_amount > 20000)
|
||||
const [guarantor2Name, setGuarantor2Name] = useState('');
|
||||
const [guarantor2Surname, setGuarantor2Surname] = useState('');
|
||||
const [guarantor2Patro, setGuarantor2Patro] = useState('');
|
||||
|
||||
const [guarantor2CardNumber, setGuarantor2CardNumber] = useState('');
|
||||
const [guarantor2CardName, setGuarantor2CardName] = useState('');
|
||||
const [guarantor2CardMonth, setGuarantor2CardMonth] = useState('');
|
||||
const [guarantor2CardYear, setGuarantor2CardYear] = useState('');
|
||||
|
||||
const [guarantor2PassportSerie, setGuarantor2PassportSerie] = useState('');
|
||||
const [guarantor2PassportId, setGuarantor2PassportId] = useState('');
|
||||
|
||||
const [submitted, setSubmitted] = useState(false);
|
||||
|
||||
// Compute if second guarantor is required (loan amount > 20000)
|
||||
const loanAmountNum = parseInt(loanAmount) || 0;
|
||||
const needsSecondGuarantor = loanAmountNum > 20000;
|
||||
|
||||
const req = (l) => `${l} *`;
|
||||
|
||||
const [passportOne, setPassportOne] = useState(null);
|
||||
@@ -119,6 +136,11 @@ const CreateLoanOrderScreen = () => {
|
||||
setGuarantorCardNumber(formatted);
|
||||
};
|
||||
|
||||
const handleGuarantor2CardNumberChange = (text) => {
|
||||
const formatted = formatCardNumber(text);
|
||||
setGuarantor2CardNumber(formatted);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (user) {
|
||||
if (user.passport_serie) setPassportSerie(user.passport_serie);
|
||||
@@ -159,7 +181,9 @@ const CreateLoanOrderScreen = () => {
|
||||
|
||||
const handleSubmit = async () => {
|
||||
setSubmitted(true);
|
||||
if (!loanType || !loanAmount || !region || !branchId || !customerName || !customerSurname || !passportSerie || !passportId || !passportGivenAt || !passportGivenBy || !bornAt || !bornPlace || !phone || !phoneHome || !education || !marriageStatus || !passportAddress || !realAddress || !workCompany || !workCompanyAccNum || !workRegion || !workProvinceId || !workPosition || !workSalary || !workStartedAt || !passportOne || !passportTwo || !passportThree || !passportFour || !cardNumber || !cardName || !cardMonth || !cardYear || !guarantorName || !guarantorSurname || !guarantorCardNumber || !guarantorCardName || !guarantorCardMonth || !guarantorCardYear || !guarantorPassportSerie || !guarantorPassportId ) {
|
||||
if (
|
||||
!loanType || !loanAmount || !region || !branchId || !customerName || !customerSurname || !passportSerie || !passportId || !passportGivenAt || !passportGivenBy || !bornAt || !bornPlace || !phone || !phoneHome || !education || !marriageStatus || !passportAddress || !realAddress || !workCompany || !workCompanyAccNum || !workRegion || !workProvinceId || !workPosition || !workSalary || !workStartedAt || !passportOne || !passportTwo || !passportThree || !passportFour || !cardNumber || !cardName || !cardMonth || !cardYear || !guarantorName || !guarantorSurname || !guarantorCardNumber || !guarantorCardName || !guarantorCardMonth || !guarantorCardYear || !guarantorPassportSerie || !guarantorPassportId || (needsSecondGuarantor && ( !guarantor2Name || !guarantor2Surname || !guarantor2CardNumber || !guarantor2CardName || !guarantor2CardMonth || !guarantor2CardYear || !guarantor2PassportSerie || !guarantor2PassportId ))
|
||||
) {
|
||||
Alert.alert('Error', 'Fill all required fields');
|
||||
return;
|
||||
}
|
||||
@@ -225,6 +249,22 @@ const CreateLoanOrderScreen = () => {
|
||||
appendField('guarantor_passport_serie', guarantorPassportSerie);
|
||||
appendField('guarantor_passport_id', guarantorPassportId);
|
||||
|
||||
// Guarantor 2 info
|
||||
if (needsSecondGuarantor) {
|
||||
appendField('guarantor_2_name', guarantor2Name);
|
||||
appendField('guarantor_2_surname', guarantor2Surname);
|
||||
appendField('guarantor_2_patronic_name', guarantor2Patro);
|
||||
|
||||
const rawGuarantor2Card = guarantor2CardNumber.replace(/[^0-9]/g, '');
|
||||
appendField('guarantor_2_card_number', rawGuarantor2Card);
|
||||
appendField('guarantor_2_card_name', guarantor2CardName);
|
||||
appendField('guarantor_2_card_month', guarantor2CardMonth);
|
||||
appendField('guarantor_2_card_year', guarantor2CardYear);
|
||||
|
||||
appendField('guarantor_2_passport_serie', guarantor2PassportSerie);
|
||||
appendField('guarantor_2_passport_id', guarantor2PassportId);
|
||||
}
|
||||
|
||||
const addImage = (field, uri) => {
|
||||
if (!uri) return;
|
||||
const fileName = uri.split('/').pop();
|
||||
@@ -345,11 +385,29 @@ const CreateLoanOrderScreen = () => {
|
||||
<Input label={req('Kartdaky ady')} value={guarantorCardName} onChangeText={setGuarantorCardName} error={submitted && !guarantorCardName} />
|
||||
<SelectInput label={req('Möhleti (aý)')} value={guarantorCardMonth} options={monthOptions} onValueChange={setGuarantorCardMonth} placeholder="Saýla" error={submitted && !guarantorCardMonth} />
|
||||
<SelectInput label={req('Möhleti (ýyl)')} value={guarantorCardYear} options={yearOptions} onValueChange={setGuarantorCardYear} placeholder="Saýla" error={submitted && !guarantorCardYear} />
|
||||
|
||||
|
||||
{/* Guarantor passport */}
|
||||
<SelectInput label={req('Pasport seriýasy')} value={guarantorPassportSerie} options={passportSeriesOptions} onValueChange={setGuarantorPassportSerie} placeholder="Saýla" error={submitted && !guarantorPassportSerie} />
|
||||
<Input label={req('Pasport belgisi')} value={guarantorPassportId} onChangeText={setGuarantorPassportId} keyboardType="numeric" error={submitted && !guarantorPassportId} />
|
||||
|
||||
|
||||
{needsSecondGuarantor && (
|
||||
<>
|
||||
<Text style={[styles.title, { marginTop: 24 }]}>Ikinji zamun barada maglumat</Text>
|
||||
|
||||
<Input label={req('Zamunyň ady')} value={guarantor2Name} onChangeText={setGuarantor2Name} error={submitted && needsSecondGuarantor && !guarantor2Name} />
|
||||
<Input label={req('Zamunyň familiýasy')} value={guarantor2Surname} onChangeText={setGuarantor2Surname} error={submitted && needsSecondGuarantor && !guarantor2Surname} />
|
||||
<Input label="Zamunyň atasynyň ady" value={guarantor2Patro} onChangeText={setGuarantor2Patro} />
|
||||
|
||||
<Input label={req('Kart belgisi')} placeholder="xxxx-xxxx-xxxx-xxxx" value={guarantor2CardNumber} onChangeText={handleGuarantor2CardNumberChange} keyboardType="numeric" error={submitted && needsSecondGuarantor && !guarantor2CardNumber} />
|
||||
<Input label={req('Kartdaky ady')} value={guarantor2CardName} onChangeText={setGuarantor2CardName} error={submitted && needsSecondGuarantor && !guarantor2CardName} />
|
||||
<SelectInput label={req('Möhleti (aý)')} value={guarantor2CardMonth} options={monthOptions} onValueChange={setGuarantor2CardMonth} placeholder="Saýla" error={submitted && needsSecondGuarantor && !guarantor2CardMonth} />
|
||||
<SelectInput label={req('Möhleti (ýyl)')} value={guarantor2CardYear} options={yearOptions} onValueChange={setGuarantor2CardYear} placeholder="Saýla" error={submitted && needsSecondGuarantor && !guarantor2CardYear} />
|
||||
|
||||
<SelectInput label={req('Pasport seriýasy')} value={guarantor2PassportSerie} options={passportSeriesOptions} onValueChange={setGuarantor2PassportSerie} placeholder="Saýla" error={submitted && needsSecondGuarantor && !guarantor2PassportSerie} />
|
||||
<Input label={req('Pasport belgisi')} value={guarantor2PassportId} onChangeText={setGuarantor2PassportId} keyboardType="numeric" error={submitted && needsSecondGuarantor && !guarantor2PassportId} />
|
||||
</>
|
||||
)}
|
||||
|
||||
<TouchableOpacity style={styles.submitBtn} onPress={handleSubmit} disabled={loading}>
|
||||
{loading ? <ActivityIndicator color={COLORS.white} /> : <Text style={styles.submitText}>Ýatda sakla</Text>}
|
||||
</TouchableOpacity>
|
||||
|
||||
Reference in New Issue
Block a user