import React, { useState } from 'react'; import { ImageBackground } from 'react-native'; import { View, Text, StyleSheet, TouchableOpacity, ScrollView, PermissionsAndroid } from 'react-native'; import { BluetoothManager, BluetoothEscposPrinter, BluetoothTscPrinter } from 'react-native-bluetooth-escpos-printer'; import { Ionicons } from '@expo/vector-icons'; import * as Print from 'expo-print'; const requestBlueToothConnect = async () => { try { const granted = await PermissionsAndroid.request( PermissionsAndroid.PERMISSIONS.BLUETOOTH_CONNECT, { title: 'Cool Photo App Camera Permission', message: 'Cool Photo App needs access to your camera ' + 'so you can take awesome pictures.', buttonNeutral: 'Ask Me Later', buttonNegative: 'Cancel', buttonPositive: 'OK', }, ); if (granted === PermissionsAndroid.RESULTS.GRANTED) { console.log('You can use bluetooth connect'); } else { console.log('Camera permission denied'); } } catch (err) { console.warn(err); } }; const requestBlueToothScan = async () => { try { const granted = await PermissionsAndroid.request( PermissionsAndroid.PERMISSIONS.BLUETOOTH_SCAN, { title: 'Cool Photo App Camera Permission', message: 'Cool Photo App needs access to your camera ' + 'so you can take awesome pictures.', buttonNeutral: 'Ask Me Later', buttonNegative: 'Cancel', buttonPositive: 'OK', }, ); if (granted === PermissionsAndroid.RESULTS.GRANTED) { console.log('You can use bluetooth scan'); } else { console.log('Camera permission denied'); } } catch (err) { console.warn(err); } }; const requestAccessFine = async () => { try { const granted = await PermissionsAndroid.request( PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION, { title: 'Cool Photo App Camera Permission', message: 'Cool Photo App needs access to your camera ' + 'so you can take awesome pictures.', buttonNeutral: 'Ask Me Later', buttonNegative: 'Cancel', buttonPositive: 'OK', }, ); if (granted === PermissionsAndroid.RESULTS.GRANTED) { console.log('You can use bluetooth scan'); } else { console.log('Camera permission denied'); } } catch (err) { console.warn(err); } }; const formatNumber = function (number: any) { return number.toLocaleString('id-ID', { minimumFractionDigits: 0, maximumFractionDigits: 0 }); } const ListProduk = function (prop:any) { let data = prop.data return <> {data && Array.isArray(data) && data.map((s:any, k:any) => <> {s?.name} Rp {formatNumber(Number(s.harga))} / {s?.satuan} Quantity : {s?.qty} {s?.satuan} Rp {formatNumber(Number(s.qty) * Number(s.harga))} )} } const DetailOrder = ({ act, config, order, orderlist}: any) => { const [showBlue, setShowBlue] = useState(false); const [blueList, setBlueList] = useState(''); const printStruk = async function(){ const html = `

CV. KBS

Jl. Mangga No 10, DENPASAR

ORDER CODE

:

S00030

DATE & TIME

:

30/07/2024 12:30:00

SALES CODE

:

SALES-0001

CUSTOMER


NAME

:

Eddy Brock

ADDRESS

:

-

PHONE NUMBER

:

-

PRODUCT
QTY
UNIT PRICE
AMOUNT
A1-F12
2
1.550.500
3.100.000
SUBTOTAL BEFORE TAX
Rp 3.100.000
TAX
Rp 341.000
TOTAL
Rp 3.441.000
`; await Print.printAsync({ html, // printerUrl: selectedPrinter?.url, // iOS only }); /* await requestBlueToothConnect(); await requestBlueToothScan(); await requestAccessFine(); setShowBlue(true) BluetoothManager.isBluetoothEnabled().then((enabled:any) => { if(enabled){ BluetoothManager.scanDevices() .then((s:any) => { console.log(s); setBlueList(JSON.stringify(s)) }, (er:any) => { console.log(er) }); } }); */ } return ( <> {showBlue?<> {(`bluetooth`).toUpperCase()} {blueList} :<>} {(`detail Order`).toUpperCase()} { act(false); }}> {`< Back`} Order : {order?.name} Customer Name : {(order?.cus).toUpperCase()} Email : {(order?.email)} Address : {(order?.street)} {(`products`).toUpperCase()} {(`Detail Order`).toUpperCase()} Sub Total Rp {(formatNumber(Number(order?.amount_untaxed)))} Tax (11%) Rp {(formatNumber(Number(order?.amount_tax)))} Discount - TOTAL Rp {(formatNumber(Number(order?.amount_total)))} {(`PRINT`).toUpperCase()} {(`VIEW INVOICE`).toUpperCase()} {(`Send`).toUpperCase()} ); }; const styles = StyleSheet.create({ title: { fontSize: 32, fontWeight: 'bold', marginVertical: 10, }, date: { fontSize: 16, color: '#888', marginBottom: 20, }, info: { marginBottom: 20, }, infoText: { fontSize: 16, marginBottom: 5, }, divider: { borderBottomColor: '#000', borderBottomWidth: 1, marginVertical: 10, }, itemRow: { flexDirection: 'row', justifyContent: 'space-between', marginVertical: 5, }, itemText: { fontSize: 18, }, itemTextSatuan: { fontSize: 18, textAlign: 'center' }, totalRow: { flexDirection: 'row', justifyContent: 'space-between', marginVertical: 10, }, totalText: { fontSize: 24, fontWeight: 'bold', }, button: { borderRadius: 8, padding: 4, alignItems: 'center', marginHorizontal: 5, marginVertical:10, height: 50 }, buttonText: { color: '#fff', fontSize: 16, fontWeight: 'bold', }, }); export default DetailOrder;