digikhata-mashreq-sdk 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -0
- package/README.md +37 -0
- package/lib/module/App.js +41 -0
- package/lib/module/App.js.map +1 -0
- package/lib/module/app/assets/Icons/Bill.png +0 -0
- package/lib/module/app/assets/Icons/Cash.png +0 -0
- package/lib/module/app/assets/Icons/Expense.png +0 -0
- package/lib/module/app/assets/Icons/Staff.png +0 -0
- package/lib/module/app/assets/Icons/Stock.png +0 -0
- package/lib/module/app/assets/images/bill.png +0 -0
- package/lib/module/app/assets/images/book.png +0 -0
- package/lib/module/app/assets/images/digiKhataSolo256.png +0 -0
- package/lib/module/app/assets/images/money.png +0 -0
- package/lib/module/app/assets/images/staff.png +0 -0
- package/lib/module/app/assets/images/stock.png +0 -0
- package/lib/module/app/assets/images/svgviewer-png-output-white.png +0 -0
- package/lib/module/app/components/Balance.js +153 -0
- package/lib/module/app/components/Balance.js.map +1 -0
- package/lib/module/app/components/CountryPhoneInput.js +271 -0
- package/lib/module/app/components/CountryPhoneInput.js.map +1 -0
- package/lib/module/app/components/Entries.js +89 -0
- package/lib/module/app/components/Entries.js.map +1 -0
- package/lib/module/app/components/SearchBar.js +70 -0
- package/lib/module/app/components/SearchBar.js.map +1 -0
- package/lib/module/app/components/Transaction.js +108 -0
- package/lib/module/app/components/Transaction.js.map +1 -0
- package/lib/module/app/components/User.js +109 -0
- package/lib/module/app/components/User.js.map +1 -0
- package/lib/module/app/components/index.js +10 -0
- package/lib/module/app/components/index.js.map +1 -0
- package/lib/module/app/database/clients.js +149 -0
- package/lib/module/app/database/clients.js.map +1 -0
- package/lib/module/app/database/database.js +9 -0
- package/lib/module/app/database/database.js.map +1 -0
- package/lib/module/app/database/schema.js +525 -0
- package/lib/module/app/database/schema.js.map +1 -0
- package/lib/module/app/navigation/BottomTabs/BottomTabs.js +29 -0
- package/lib/module/app/navigation/BottomTabs/BottomTabs.js.map +1 -0
- package/lib/module/app/navigation/Drawer/Drawer.js +13 -0
- package/lib/module/app/navigation/Drawer/Drawer.js.map +1 -0
- package/lib/module/app/navigation/HomeStack/HomeStack.js +36 -0
- package/lib/module/app/navigation/HomeStack/HomeStack.js.map +1 -0
- package/lib/module/app/navigation/Root.js +26 -0
- package/lib/module/app/navigation/Root.js.map +1 -0
- package/lib/module/app/navigation/index.js +7 -0
- package/lib/module/app/navigation/index.js.map +1 -0
- package/lib/module/app/redux/Store.js +10 -0
- package/lib/module/app/redux/Store.js.map +1 -0
- package/lib/module/app/redux/reducers/client/client_actions.js +2 -0
- package/lib/module/app/redux/reducers/client/client_actions.js.map +1 -0
- package/lib/module/app/redux/reducers/client/client_reducers.js +26 -0
- package/lib/module/app/redux/reducers/client/client_reducers.js.map +1 -0
- package/lib/module/app/redux/reducers/client/client_types.js +7 -0
- package/lib/module/app/redux/reducers/client/client_types.js.map +1 -0
- package/lib/module/app/screens/AddScreen.js +200 -0
- package/lib/module/app/screens/AddScreen.js.map +1 -0
- package/lib/module/app/screens/Banks.js +126 -0
- package/lib/module/app/screens/Banks.js.map +1 -0
- package/lib/module/app/screens/CustomerEntries.js +475 -0
- package/lib/module/app/screens/CustomerEntries.js.map +1 -0
- package/lib/module/app/screens/Customers.js +233 -0
- package/lib/module/app/screens/Customers.js.map +1 -0
- package/lib/module/app/screens/Entry.js +696 -0
- package/lib/module/app/screens/Entry.js.map +1 -0
- package/lib/module/app/screens/HomeScreen.js +176 -0
- package/lib/module/app/screens/HomeScreen.js.map +1 -0
- package/lib/module/app/screens/SelectBusiness.js +201 -0
- package/lib/module/app/screens/SelectBusiness.js.map +1 -0
- package/lib/module/app/screens/Splash.js +51 -0
- package/lib/module/app/screens/Splash.js.map +1 -0
- package/lib/module/app/screens/Suppliers.js +222 -0
- package/lib/module/app/screens/Suppliers.js.map +1 -0
- package/lib/module/app/screens/TransactionDetails.js +301 -0
- package/lib/module/app/screens/TransactionDetails.js.map +1 -0
- package/lib/module/app/screens/index.js +14 -0
- package/lib/module/app/screens/index.js.map +1 -0
- package/lib/module/app/themes/config.js +156 -0
- package/lib/module/app/themes/config.js.map +1 -0
- package/lib/module/app/utils/countries.json +1930 -0
- package/lib/module/declarations.d.js +2 -0
- package/lib/module/declarations.d.js.map +1 -0
- package/lib/module/index.js +5 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/typescript/babel.config.d.ts +10 -0
- package/lib/typescript/babel.config.d.ts.map +1 -0
- package/lib/typescript/eslint.config.d.mts +3 -0
- package/lib/typescript/eslint.config.d.mts.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/App.d.ts +2 -0
- package/lib/typescript/src/App.d.ts.map +1 -0
- package/lib/typescript/src/app/components/Balance.d.ts +8 -0
- package/lib/typescript/src/app/components/Balance.d.ts.map +1 -0
- package/lib/typescript/src/app/components/CountryPhoneInput.d.ts +6 -0
- package/lib/typescript/src/app/components/CountryPhoneInput.d.ts.map +1 -0
- package/lib/typescript/src/app/components/Entries.d.ts +4 -0
- package/lib/typescript/src/app/components/Entries.d.ts.map +1 -0
- package/lib/typescript/src/app/components/SearchBar.d.ts +6 -0
- package/lib/typescript/src/app/components/SearchBar.d.ts.map +1 -0
- package/lib/typescript/src/app/components/Transaction.d.ts +11 -0
- package/lib/typescript/src/app/components/Transaction.d.ts.map +1 -0
- package/lib/typescript/src/app/components/User.d.ts +10 -0
- package/lib/typescript/src/app/components/User.d.ts.map +1 -0
- package/lib/typescript/src/app/components/index.d.ts +8 -0
- package/lib/typescript/src/app/components/index.d.ts.map +1 -0
- package/lib/typescript/src/app/database/clients.d.ts +9 -0
- package/lib/typescript/src/app/database/clients.d.ts.map +1 -0
- package/lib/typescript/src/app/database/database.d.ts +3 -0
- package/lib/typescript/src/app/database/database.d.ts.map +1 -0
- package/lib/typescript/src/app/database/schema.d.ts +2 -0
- package/lib/typescript/src/app/database/schema.d.ts.map +1 -0
- package/lib/typescript/src/app/navigation/BottomTabs/BottomTabs.d.ts +2 -0
- package/lib/typescript/src/app/navigation/BottomTabs/BottomTabs.d.ts.map +1 -0
- package/lib/typescript/src/app/navigation/Drawer/Drawer.d.ts +2 -0
- package/lib/typescript/src/app/navigation/Drawer/Drawer.d.ts.map +1 -0
- package/lib/typescript/src/app/navigation/HomeStack/HomeStack.d.ts +2 -0
- package/lib/typescript/src/app/navigation/HomeStack/HomeStack.d.ts.map +1 -0
- package/lib/typescript/src/app/navigation/Root.d.ts +2 -0
- package/lib/typescript/src/app/navigation/Root.d.ts.map +1 -0
- package/lib/typescript/src/app/navigation/index.d.ts +5 -0
- package/lib/typescript/src/app/navigation/index.d.ts.map +1 -0
- package/lib/typescript/src/app/redux/Store.d.ts +2 -0
- package/lib/typescript/src/app/redux/Store.d.ts.map +1 -0
- package/lib/typescript/src/app/redux/reducers/client/client_actions.d.ts +1 -0
- package/lib/typescript/src/app/redux/reducers/client/client_actions.d.ts.map +1 -0
- package/lib/typescript/src/app/redux/reducers/client/client_reducers.d.ts +3 -0
- package/lib/typescript/src/app/redux/reducers/client/client_reducers.d.ts.map +1 -0
- package/lib/typescript/src/app/redux/reducers/client/client_types.d.ts +5 -0
- package/lib/typescript/src/app/redux/reducers/client/client_types.d.ts.map +1 -0
- package/lib/typescript/src/app/screens/AddScreen.d.ts +5 -0
- package/lib/typescript/src/app/screens/AddScreen.d.ts.map +1 -0
- package/lib/typescript/src/app/screens/Banks.d.ts +2 -0
- package/lib/typescript/src/app/screens/Banks.d.ts.map +1 -0
- package/lib/typescript/src/app/screens/CustomerEntries.d.ts +5 -0
- package/lib/typescript/src/app/screens/CustomerEntries.d.ts.map +1 -0
- package/lib/typescript/src/app/screens/Customers.d.ts +4 -0
- package/lib/typescript/src/app/screens/Customers.d.ts.map +1 -0
- package/lib/typescript/src/app/screens/Entry.d.ts +5 -0
- package/lib/typescript/src/app/screens/Entry.d.ts.map +1 -0
- package/lib/typescript/src/app/screens/HomeScreen.d.ts +4 -0
- package/lib/typescript/src/app/screens/HomeScreen.d.ts.map +1 -0
- package/lib/typescript/src/app/screens/SelectBusiness.d.ts +4 -0
- package/lib/typescript/src/app/screens/SelectBusiness.d.ts.map +1 -0
- package/lib/typescript/src/app/screens/Splash.d.ts +4 -0
- package/lib/typescript/src/app/screens/Splash.d.ts.map +1 -0
- package/lib/typescript/src/app/screens/Suppliers.d.ts +4 -0
- package/lib/typescript/src/app/screens/Suppliers.d.ts.map +1 -0
- package/lib/typescript/src/app/screens/TransactionDetails.d.ts +5 -0
- package/lib/typescript/src/app/screens/TransactionDetails.d.ts.map +1 -0
- package/lib/typescript/src/app/screens/index.d.ts +12 -0
- package/lib/typescript/src/app/screens/index.d.ts.map +1 -0
- package/lib/typescript/src/app/themes/config.d.ts +63 -0
- package/lib/typescript/src/app/themes/config.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +3 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/package.json +154 -0
- package/src/App.js +41 -0
- package/src/app/assets/Icons/Bill.png +0 -0
- package/src/app/assets/Icons/Cash.png +0 -0
- package/src/app/assets/Icons/Expense.png +0 -0
- package/src/app/assets/Icons/Staff.png +0 -0
- package/src/app/assets/Icons/Stock.png +0 -0
- package/src/app/assets/images/bill.png +0 -0
- package/src/app/assets/images/book.png +0 -0
- package/src/app/assets/images/digiKhataSolo256.png +0 -0
- package/src/app/assets/images/money.png +0 -0
- package/src/app/assets/images/staff.png +0 -0
- package/src/app/assets/images/stock.png +0 -0
- package/src/app/assets/images/svgviewer-png-output-white.png +0 -0
- package/src/app/components/Balance.js +122 -0
- package/src/app/components/CountryPhoneInput.js +286 -0
- package/src/app/components/Entries.js +75 -0
- package/src/app/components/SearchBar.js +64 -0
- package/src/app/components/Transaction.js +91 -0
- package/src/app/components/User.js +85 -0
- package/src/app/components/index.js +15 -0
- package/src/app/database/clients.js +207 -0
- package/src/app/database/database.js +9 -0
- package/src/app/database/schema.js +525 -0
- package/src/app/navigation/BottomTabs/BottomTabs.js +27 -0
- package/src/app/navigation/Drawer/Drawer.js +10 -0
- package/src/app/navigation/HomeStack/HomeStack.js +43 -0
- package/src/app/navigation/Root.js +32 -0
- package/src/app/navigation/index.js +9 -0
- package/src/app/redux/Store.js +9 -0
- package/src/app/redux/reducers/client/client_actions.js +0 -0
- package/src/app/redux/reducers/client/client_reducers.js +30 -0
- package/src/app/redux/reducers/client/client_types.js +5 -0
- package/src/app/screens/AddScreen.js +185 -0
- package/src/app/screens/Banks.js +151 -0
- package/src/app/screens/CustomerEntries.js +402 -0
- package/src/app/screens/Customers.js +240 -0
- package/src/app/screens/Entry.js +658 -0
- package/src/app/screens/HomeScreen.js +146 -0
- package/src/app/screens/SelectBusiness.js +177 -0
- package/src/app/screens/Splash.js +43 -0
- package/src/app/screens/Suppliers.js +228 -0
- package/src/app/screens/TransactionDetails.js +199 -0
- package/src/app/screens/index.js +23 -0
- package/src/app/themes/config.js +185 -0
- package/src/app/utils/countries.json +1930 -0
- package/src/declarations.d.ts +1 -0
- package/src/index.tsx +3 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { View, Text, TouchableOpacity, StyleSheet } from 'react-native'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
import { COLORS, FONT_MEDIUM, FONT_NORMAL } from '../themes/config'
|
|
4
|
+
import Ionicons from "react-native-vector-icons/Ionicons"
|
|
5
|
+
|
|
6
|
+
export default function Transaction({ date, notes, billNo, isAttachment, balance, firstCell, secondCell, onPress }) {
|
|
7
|
+
return (
|
|
8
|
+
<TouchableOpacity
|
|
9
|
+
style={Styles._mainContainer}
|
|
10
|
+
activeOpacity={0.8}
|
|
11
|
+
onPress={onPress}
|
|
12
|
+
>
|
|
13
|
+
<View style={Styles._entriesCell}>
|
|
14
|
+
<Text style={Styles._dateText}>{date}</Text>
|
|
15
|
+
{notes ? <Text style={Styles._billNo}>{notes}</Text> : null}
|
|
16
|
+
{billNo ? <Text style={Styles._billNo}>Bill No. {billNo}</Text> : null}
|
|
17
|
+
{isAttachment && (
|
|
18
|
+
<Ionicons
|
|
19
|
+
name={"attach"}
|
|
20
|
+
color={COLORS.darkGrey}
|
|
21
|
+
size={20}
|
|
22
|
+
/>
|
|
23
|
+
)}
|
|
24
|
+
{balance !== null && balance !== undefined && (
|
|
25
|
+
<Text
|
|
26
|
+
style={[
|
|
27
|
+
Styles._balanceText,
|
|
28
|
+
{ color: balance < 0 ? "red" : "green" }
|
|
29
|
+
]}
|
|
30
|
+
>
|
|
31
|
+
Bal. Rs {Math.abs(balance)}
|
|
32
|
+
</Text>
|
|
33
|
+
)}
|
|
34
|
+
</View>
|
|
35
|
+
|
|
36
|
+
<View style={Styles._firstCell}>
|
|
37
|
+
<Text style={{ color: "red", fontFamily: FONT_MEDIUM, fontSize: 12 }}>
|
|
38
|
+
{firstCell}
|
|
39
|
+
</Text>
|
|
40
|
+
</View>
|
|
41
|
+
<View style={Styles._secondCell}>
|
|
42
|
+
<Text style={{ color: "green", fontFamily: FONT_MEDIUM, fontSize: 12 }}>
|
|
43
|
+
{secondCell}
|
|
44
|
+
</Text>
|
|
45
|
+
</View>
|
|
46
|
+
</TouchableOpacity>
|
|
47
|
+
)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const Styles = StyleSheet.create({
|
|
51
|
+
_mainContainer: {
|
|
52
|
+
width: "100%",
|
|
53
|
+
flexDirection: "row",
|
|
54
|
+
borderBottomColor: COLORS.darkGrey,
|
|
55
|
+
borderBottomWidth: 0.7,
|
|
56
|
+
},
|
|
57
|
+
_entriesCell: {
|
|
58
|
+
width: "50%",
|
|
59
|
+
alignItems: "flex-start",
|
|
60
|
+
paddingLeft: 5,
|
|
61
|
+
gap: 3,
|
|
62
|
+
paddingVertical: 10
|
|
63
|
+
},
|
|
64
|
+
_firstCell: {
|
|
65
|
+
width: "25%",
|
|
66
|
+
backgroundColor: "rgba(250,0,0,0.1)",
|
|
67
|
+
alignItems: "flex-end",
|
|
68
|
+
justifyContent: "center",
|
|
69
|
+
paddingRight: 5
|
|
70
|
+
},
|
|
71
|
+
_secondCell: {
|
|
72
|
+
width: "25%",
|
|
73
|
+
alignItems: "flex-end",
|
|
74
|
+
justifyContent: "center",
|
|
75
|
+
paddingRight: 5,
|
|
76
|
+
},
|
|
77
|
+
_dateText: {
|
|
78
|
+
color: COLORS.darkGrey,
|
|
79
|
+
fontSize: 12,
|
|
80
|
+
fontFamily: FONT_MEDIUM
|
|
81
|
+
},
|
|
82
|
+
_billNo: {
|
|
83
|
+
color: COLORS.blackColor,
|
|
84
|
+
fontSize: 12,
|
|
85
|
+
fontFamily: FONT_MEDIUM
|
|
86
|
+
},
|
|
87
|
+
_balanceText: {
|
|
88
|
+
fontFamily: FONT_NORMAL,
|
|
89
|
+
fontSize: 12
|
|
90
|
+
},
|
|
91
|
+
})
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { View, Text, TouchableOpacity, StyleSheet } from 'react-native'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
import { COLORS, FONT_BOLD, FONT_MEDIUM, FONT_NORMAL, getAvatar, WP } from '../themes/config'
|
|
4
|
+
|
|
5
|
+
export default function User({ name, addedAt, amount, type, avatarColor = 'red', onPress, clientType }) {
|
|
6
|
+
return (
|
|
7
|
+
<TouchableOpacity
|
|
8
|
+
style={Styles._mainContainer}
|
|
9
|
+
activeOpacity={0.8}
|
|
10
|
+
onPress={onPress}
|
|
11
|
+
>
|
|
12
|
+
<View style={Styles._avatarMain}>
|
|
13
|
+
<Text style={[Styles._avatarText, { color: avatarColor }]}>{getAvatar(name)}</Text>
|
|
14
|
+
</View>
|
|
15
|
+
|
|
16
|
+
<View style={Styles._detailsMain}>
|
|
17
|
+
<Text style={Styles._name}>{name}</Text>
|
|
18
|
+
<Text style={Styles._addedAt}>{addedAt}</Text>
|
|
19
|
+
</View>
|
|
20
|
+
<View style={Styles._amount}>
|
|
21
|
+
<Text style={[Styles._amountTxt, { color: type == "receivable" ? "green" : type == "payable" ? "red" : COLORS.blackColor }]}>Rs {amount}</Text>
|
|
22
|
+
<Text style={Styles._amountTxt}>{type == "receivable" ? "You'll Give" : type == "payable" ? (clientType == 0 ? "You'll Get" : "Received") : ""}</Text>
|
|
23
|
+
</View>
|
|
24
|
+
</TouchableOpacity>
|
|
25
|
+
)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const Styles = StyleSheet.create({
|
|
29
|
+
_mainContainer: {
|
|
30
|
+
width: WP(94),
|
|
31
|
+
height: 60,
|
|
32
|
+
flexDirection: "row",
|
|
33
|
+
backgroundColor: COLORS.whiteColor,
|
|
34
|
+
alignItems: "center",
|
|
35
|
+
marginVertical: 7
|
|
36
|
+
},
|
|
37
|
+
_avatarMain: {
|
|
38
|
+
width: 47,
|
|
39
|
+
height: 47,
|
|
40
|
+
backgroundColor: COLORS.lightGrey,
|
|
41
|
+
borderRadius: 100,
|
|
42
|
+
justifyContent: "center",
|
|
43
|
+
alignItems: "center",
|
|
44
|
+
},
|
|
45
|
+
_avatarText: {
|
|
46
|
+
fontFamily: FONT_NORMAL,
|
|
47
|
+
fontSize: 16,
|
|
48
|
+
color: COLORS.primaryColor
|
|
49
|
+
},
|
|
50
|
+
_detailsMain: {
|
|
51
|
+
width: '60%',
|
|
52
|
+
height: "100%",
|
|
53
|
+
justifyContent: "center",
|
|
54
|
+
paddingLeft: 15,
|
|
55
|
+
borderBottomColor: COLORS.grey,
|
|
56
|
+
borderBottomWidth: 0.7,
|
|
57
|
+
gap: 4
|
|
58
|
+
// backgroundColor: "lightblue"
|
|
59
|
+
},
|
|
60
|
+
_name: {
|
|
61
|
+
color: COLORS.blackColor,
|
|
62
|
+
fontFamily: FONT_MEDIUM,
|
|
63
|
+
fontSize: 13
|
|
64
|
+
},
|
|
65
|
+
_addedAt: {
|
|
66
|
+
color: COLORS.grey,
|
|
67
|
+
fontFamily: FONT_MEDIUM,
|
|
68
|
+
fontSize: 11,
|
|
69
|
+
},
|
|
70
|
+
_amountTxt: {
|
|
71
|
+
color: COLORS.grey,
|
|
72
|
+
fontFamily: FONT_NORMAL,
|
|
73
|
+
fontSize: 12,
|
|
74
|
+
},
|
|
75
|
+
_amount: {
|
|
76
|
+
width: "25%",
|
|
77
|
+
// backgroundColor:"red",
|
|
78
|
+
height: "100%",
|
|
79
|
+
borderBottomColor: COLORS.grey,
|
|
80
|
+
borderBottomWidth: 0.7,
|
|
81
|
+
justifyContent: "center",
|
|
82
|
+
alignItems: "center",
|
|
83
|
+
gap: 3
|
|
84
|
+
},
|
|
85
|
+
})
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import Balance from "./Balance";
|
|
2
|
+
import Entries from "./Entries";
|
|
3
|
+
import SearchBar from "./SearchBar";
|
|
4
|
+
import User from "./User";
|
|
5
|
+
import CountryPhoneInput from "./CountryPhoneInput";
|
|
6
|
+
import Transaction from "./Transaction";
|
|
7
|
+
|
|
8
|
+
export {
|
|
9
|
+
Balance,
|
|
10
|
+
Entries,
|
|
11
|
+
SearchBar,
|
|
12
|
+
User,
|
|
13
|
+
CountryPhoneInput,
|
|
14
|
+
Transaction,
|
|
15
|
+
}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import db from "./database";
|
|
2
|
+
|
|
3
|
+
export const addClient = (name, phoneNum, type) => {
|
|
4
|
+
return new Promise((resolve, reject) => {
|
|
5
|
+
// Default JSON for status
|
|
6
|
+
const defaultStatus = JSON.stringify({
|
|
7
|
+
flat: "",
|
|
8
|
+
landmark: "",
|
|
9
|
+
pincode: "",
|
|
10
|
+
city: "",
|
|
11
|
+
state: ""
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
db.transaction((tx) => {
|
|
15
|
+
tx.executeSql(
|
|
16
|
+
"INSERT INTO Clients (name, phone, type, status) VALUES (?, ?, ?, ?)",
|
|
17
|
+
[name, phoneNum, type, defaultStatus],
|
|
18
|
+
(txObj, resultSet) => resolve(resultSet),
|
|
19
|
+
(txObj, error) => reject(error)
|
|
20
|
+
);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const getAllClients = () => {
|
|
26
|
+
return new Promise((resolve, reject) => {
|
|
27
|
+
db.transaction(tx => {
|
|
28
|
+
tx.executeSql(
|
|
29
|
+
"SELECT * FROM Clients",
|
|
30
|
+
[],
|
|
31
|
+
(txObj, resultSet) => {
|
|
32
|
+
let results = [];
|
|
33
|
+
for (let i = 0; i < resultSet.rows.length; i++) {
|
|
34
|
+
results.push(resultSet.rows.item(i));
|
|
35
|
+
}
|
|
36
|
+
resolve(results);
|
|
37
|
+
},
|
|
38
|
+
(txObj, error) => {
|
|
39
|
+
reject(error);
|
|
40
|
+
}
|
|
41
|
+
);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export const deleteClientById = (id) => {
|
|
47
|
+
return new Promise((resolve, reject) => {
|
|
48
|
+
db.transaction(tx => {
|
|
49
|
+
tx.executeSql(
|
|
50
|
+
"DELETE FROM Clients WHERE id = ?;",
|
|
51
|
+
[id],
|
|
52
|
+
(txObj, resultSet) => {
|
|
53
|
+
if (resultSet.rowsAffected > 0) {
|
|
54
|
+
resolve(true); // deleted successfully
|
|
55
|
+
} else {
|
|
56
|
+
resolve(false); // no row with this id
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
(txObj, error) => {
|
|
60
|
+
reject(error);
|
|
61
|
+
}
|
|
62
|
+
);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export const getClientsByType = (type) => {
|
|
68
|
+
return new Promise((resolve, reject) => {
|
|
69
|
+
db.transaction((tx) => {
|
|
70
|
+
tx.executeSql(
|
|
71
|
+
`SELECT
|
|
72
|
+
c.id,
|
|
73
|
+
c.name,
|
|
74
|
+
c.type,
|
|
75
|
+
IFNULL(SUM(t.amount), 0) AS total_amount,
|
|
76
|
+
IFNULL(SUM(t.subamount), 0) AS total_subamount,
|
|
77
|
+
IFNULL(MAX(t.created_at), DATETIME('now')) AS latest_created_at,
|
|
78
|
+
IFNULL(MAX(t.updated_at), DATETIME('now')) AS latest_updated_at
|
|
79
|
+
FROM Clients c
|
|
80
|
+
LEFT JOIN Transactions t
|
|
81
|
+
ON c.id = t.customer_id
|
|
82
|
+
WHERE c.type = ?
|
|
83
|
+
GROUP BY c.id, c.name, c.type;`,
|
|
84
|
+
[type],
|
|
85
|
+
(txObj, resultSet) => {
|
|
86
|
+
let data = [];
|
|
87
|
+
for (let i = 0; i < resultSet.rows.length; i++) {
|
|
88
|
+
data.push(resultSet.rows.item(i));
|
|
89
|
+
}
|
|
90
|
+
resolve(data);
|
|
91
|
+
},
|
|
92
|
+
(txObj, error) => {
|
|
93
|
+
reject(error);
|
|
94
|
+
}
|
|
95
|
+
);
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
export const addTransaction = (customer_id, amount, subamount, notes, date, local_path) => {
|
|
101
|
+
return new Promise((resolve, reject) => {
|
|
102
|
+
db.transaction((tx) => {
|
|
103
|
+
tx.executeSql(
|
|
104
|
+
"INSERT INTO Transactions (customer_id, amount, subamount, notes, date, local_path) VALUES (?, ?, ?, ?, ?, ?)",
|
|
105
|
+
[customer_id, amount, subamount, notes, date, local_path],
|
|
106
|
+
(txObj, resultSet) => resolve(resultSet),
|
|
107
|
+
(txObj, error) => reject(error)
|
|
108
|
+
);
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
export const getClientDetails = (id) => {
|
|
114
|
+
return new Promise((resolve, reject) => {
|
|
115
|
+
db.transaction((tx) => {
|
|
116
|
+
tx.executeSql(
|
|
117
|
+
"SELECT * FROM Clients WHERE id = ?",
|
|
118
|
+
[id],
|
|
119
|
+
(txObj, resultSet) => {
|
|
120
|
+
if (resultSet.rows.length > 0) {
|
|
121
|
+
resolve(resultSet.rows.item(0)); // return the first (and only) row
|
|
122
|
+
} else {
|
|
123
|
+
resolve(null); // no client found
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
(txObj, error) => {
|
|
127
|
+
reject(error);
|
|
128
|
+
}
|
|
129
|
+
);
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
export const getClientTransactions = (client_id) => {
|
|
135
|
+
return new Promise((resolve, reject) => {
|
|
136
|
+
db.transaction((tx) => {
|
|
137
|
+
// Step 1: Get all transactions for the client
|
|
138
|
+
tx.executeSql(
|
|
139
|
+
"SELECT * FROM Transactions WHERE customer_id = ? ORDER BY created_at DESC",
|
|
140
|
+
[client_id],
|
|
141
|
+
(txObj, resultSet) => {
|
|
142
|
+
const transactions = [];
|
|
143
|
+
for (let i = 0; i < resultSet.rows.length; i++) {
|
|
144
|
+
transactions.push({
|
|
145
|
+
...resultSet.rows.item(i),
|
|
146
|
+
attachments: [] // prepare attachments array
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (transactions.length === 0) {
|
|
151
|
+
resolve([]); // no transactions → return empty array
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Step 2: Collect transaction IDs
|
|
156
|
+
const trxIds = transactions.map((t) => t.id);
|
|
157
|
+
|
|
158
|
+
// Step 3: Query all attachments for these trxIds
|
|
159
|
+
const placeholders = trxIds.map(() => "?").join(",");
|
|
160
|
+
tx.executeSql(
|
|
161
|
+
`SELECT * FROM TransactionImages WHERE trxId IN (${placeholders})`,
|
|
162
|
+
trxIds,
|
|
163
|
+
(txObj2, resultSet2) => {
|
|
164
|
+
const attachments = [];
|
|
165
|
+
for (let i = 0; i < resultSet2.rows.length; i++) {
|
|
166
|
+
attachments.push(resultSet2.rows.item(i));
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Step 4: Merge attachments into transactions
|
|
170
|
+
const transactionMap = {};
|
|
171
|
+
transactions.forEach((t) => {
|
|
172
|
+
transactionMap[t.id] = t;
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
attachments.forEach((att) => {
|
|
176
|
+
if (transactionMap[att.trxId]) {
|
|
177
|
+
transactionMap[att.trxId].attachments.push(att);
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
resolve(transactions);
|
|
182
|
+
},
|
|
183
|
+
(txObj2, error) => reject(error)
|
|
184
|
+
);
|
|
185
|
+
},
|
|
186
|
+
(txObj, error) => reject(error)
|
|
187
|
+
);
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
export const addTransactionImages = (trxId, local_path) => {
|
|
194
|
+
return new Promise((resolve, reject) => {
|
|
195
|
+
db.transaction((tx) => {
|
|
196
|
+
tx.executeSql(
|
|
197
|
+
"INSERT INTO TransactionImages (trxId, local_path, created_at, updated_at) VALUES (?, ?, datetime('now'), datetime('now'))",
|
|
198
|
+
[trxId, local_path],
|
|
199
|
+
(txObj, resultSet) => resolve(resultSet),
|
|
200
|
+
(txObj, error) => reject(error)
|
|
201
|
+
);
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
|