import React, { useState } from 'react'; import { View, Text, FlatList, StyleSheet, TouchableOpacity, Alert } from 'react-native'; import { InsideHeader, Loader } from '../../Component/Index'; import colors from '../../Constant/Color'; import { CreditCard, Calendar, User, DollarSign, ArrowRight } from 'lucide-react-native'; import { useSelector } from 'react-redux'; import { useOfflineTenderPurchase } from '../../Services/BBPS/Hooks'; import { useNavigation } from '@react-navigation/native'; import NavigationString from '../../Constant/NavigationString'; const ProceedToPurTender = () => { const navigation: any = useNavigation(); const [loading, setLoading] = useState(false); const SelectedPurchaseList = useSelector((state: any) => state.selectPurchaseTender); const { mutate, isPending } = useOfflineTenderPurchase() const calculateTotalAmount = (item: any) => { const gstAmount = (Number(item.documentFees) + Number(item.portalCharge)) * (Number(item.gst) / 100); const payableAmount = Number(item.documentFees) + Number(item.portalCharge) + gstAmount; return payableAmount } const handleOfflinePurchase = async () => { const orderNo = `ORD${Date.now()}`; const body = { tenderDetails: SelectedPurchaseList.map((item: any, index:number) => ({ gst: item.gst, regId: item.regId || 0, deptId: item.deptId || 1, gstAmount: item.gst / 100, payableAmount: calculateTotalAmount(item), portalCharge: item.portalCharge, tenderFees: item.documentFees, tenderId: item.tenderId, tenderNumber: item.tenderNumber, tenderStatus: item.tenderStatus ?? "", tenderType: item.tenderType ?? "", isPurchased: item.purchaseStatus ?? false, totalPayableAmount: calculateTotalAmount(item), percentageAmount: calculateTotalAmount(item) / 100, newTenderDocumentFees: item.documentFees * index + 1, })), orderNo: orderNo, }; console.log("tender offline body : ", body) try { mutate(body, { onSuccess: (res) => { console.log(res, '---------------------purchsase response'); Alert.alert('Offline Purchase Successful!', `Order No: ${orderNo}`); navigation.goBack() }, onError: (error) => { console.log(error, "================purchse Error"); } }) } catch (error) { console.log("purchase offline error", error); } } const handlePurchase = (type: 'online' | 'offline') => { setLoading(true); setTimeout(() => { setLoading(false); type === 'online' ? Alert.alert('Online Purchase Successful!') : handleOfflinePurchase(); }, 1200); }; const renderItem = ({ item }: { item: any[0] }) => ( {item.auctionNumber} {item.auctionPattern} End Date: {item.purchaseEnd} Tender No: {item.tenderNumber} Tender Fees: ₹{item.documentFees} GST ({item.gst}%): ₹{item.gst / 100} Portal Charge: ₹{item.portalCharge} Total: ₹{calculateTotalAmount(item)} ); return ( item.tenderId.toString()} contentContainerStyle={styles.container} /> handlePurchase('online')} > Purchase Online handlePurchase('offline')} > Purchase Offline {loading && ( )} ); }; export default ProceedToPurTender; const styles = StyleSheet.create({ screen: { flex: 1, }, container: { padding: 16, paddingBottom: 120, }, card: { backgroundColor: '#fff', borderRadius: 16, padding: 16, marginBottom: 16, elevation: 5, shadowColor: '#000', shadowOpacity: 0.12, shadowOffset: { width: 0, height: 3 }, shadowRadius: 8, }, cardHeader: { flexDirection: 'row', justifyContent: 'space-between', marginBottom: 12, }, title: { fontSize: 16, fontWeight: '700', color: '#0F172A', }, pattern: { fontSize: 14, color: colors.primary, fontWeight: '600', }, cardRow: { flexDirection: 'row', alignItems: 'center', gap: 6, marginBottom: 4, }, text: { fontSize: 14, color: '#555', }, totalRow: { marginTop: 10, backgroundColor: colors.primary, borderRadius: 12, paddingVertical: 10, flexDirection: 'row', justifyContent: 'center', alignItems: 'center', gap: 8, }, total: { fontSize: 15, fontWeight: '700', color: '#fff', }, bottomButtonContainer: { position: 'absolute', bottom: 0, left: 0, flexDirection: 'row', backgroundColor: colors.white, width: '100%', paddingVertical: 20, paddingHorizontal: 10, elevation: 5 }, button: { flex: 1, backgroundColor: colors.primary, paddingVertical: 14, borderRadius: 12, alignItems: 'center', flexDirection: 'row', justifyContent: 'center', }, buttonText: { color: '#fff', fontWeight: '700', fontSize: 14, }, loadingOverlay: { ...StyleSheet.absoluteFillObject, backgroundColor: 'rgba(0,0,0,0.2)', justifyContent: 'center', alignItems: 'center', zIndex: 10, }, });