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.
Files changed (203) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +37 -0
  3. package/lib/module/App.js +41 -0
  4. package/lib/module/App.js.map +1 -0
  5. package/lib/module/app/assets/Icons/Bill.png +0 -0
  6. package/lib/module/app/assets/Icons/Cash.png +0 -0
  7. package/lib/module/app/assets/Icons/Expense.png +0 -0
  8. package/lib/module/app/assets/Icons/Staff.png +0 -0
  9. package/lib/module/app/assets/Icons/Stock.png +0 -0
  10. package/lib/module/app/assets/images/bill.png +0 -0
  11. package/lib/module/app/assets/images/book.png +0 -0
  12. package/lib/module/app/assets/images/digiKhataSolo256.png +0 -0
  13. package/lib/module/app/assets/images/money.png +0 -0
  14. package/lib/module/app/assets/images/staff.png +0 -0
  15. package/lib/module/app/assets/images/stock.png +0 -0
  16. package/lib/module/app/assets/images/svgviewer-png-output-white.png +0 -0
  17. package/lib/module/app/components/Balance.js +153 -0
  18. package/lib/module/app/components/Balance.js.map +1 -0
  19. package/lib/module/app/components/CountryPhoneInput.js +271 -0
  20. package/lib/module/app/components/CountryPhoneInput.js.map +1 -0
  21. package/lib/module/app/components/Entries.js +89 -0
  22. package/lib/module/app/components/Entries.js.map +1 -0
  23. package/lib/module/app/components/SearchBar.js +70 -0
  24. package/lib/module/app/components/SearchBar.js.map +1 -0
  25. package/lib/module/app/components/Transaction.js +108 -0
  26. package/lib/module/app/components/Transaction.js.map +1 -0
  27. package/lib/module/app/components/User.js +109 -0
  28. package/lib/module/app/components/User.js.map +1 -0
  29. package/lib/module/app/components/index.js +10 -0
  30. package/lib/module/app/components/index.js.map +1 -0
  31. package/lib/module/app/database/clients.js +149 -0
  32. package/lib/module/app/database/clients.js.map +1 -0
  33. package/lib/module/app/database/database.js +9 -0
  34. package/lib/module/app/database/database.js.map +1 -0
  35. package/lib/module/app/database/schema.js +525 -0
  36. package/lib/module/app/database/schema.js.map +1 -0
  37. package/lib/module/app/navigation/BottomTabs/BottomTabs.js +29 -0
  38. package/lib/module/app/navigation/BottomTabs/BottomTabs.js.map +1 -0
  39. package/lib/module/app/navigation/Drawer/Drawer.js +13 -0
  40. package/lib/module/app/navigation/Drawer/Drawer.js.map +1 -0
  41. package/lib/module/app/navigation/HomeStack/HomeStack.js +36 -0
  42. package/lib/module/app/navigation/HomeStack/HomeStack.js.map +1 -0
  43. package/lib/module/app/navigation/Root.js +26 -0
  44. package/lib/module/app/navigation/Root.js.map +1 -0
  45. package/lib/module/app/navigation/index.js +7 -0
  46. package/lib/module/app/navigation/index.js.map +1 -0
  47. package/lib/module/app/redux/Store.js +10 -0
  48. package/lib/module/app/redux/Store.js.map +1 -0
  49. package/lib/module/app/redux/reducers/client/client_actions.js +2 -0
  50. package/lib/module/app/redux/reducers/client/client_actions.js.map +1 -0
  51. package/lib/module/app/redux/reducers/client/client_reducers.js +26 -0
  52. package/lib/module/app/redux/reducers/client/client_reducers.js.map +1 -0
  53. package/lib/module/app/redux/reducers/client/client_types.js +7 -0
  54. package/lib/module/app/redux/reducers/client/client_types.js.map +1 -0
  55. package/lib/module/app/screens/AddScreen.js +200 -0
  56. package/lib/module/app/screens/AddScreen.js.map +1 -0
  57. package/lib/module/app/screens/Banks.js +126 -0
  58. package/lib/module/app/screens/Banks.js.map +1 -0
  59. package/lib/module/app/screens/CustomerEntries.js +475 -0
  60. package/lib/module/app/screens/CustomerEntries.js.map +1 -0
  61. package/lib/module/app/screens/Customers.js +233 -0
  62. package/lib/module/app/screens/Customers.js.map +1 -0
  63. package/lib/module/app/screens/Entry.js +696 -0
  64. package/lib/module/app/screens/Entry.js.map +1 -0
  65. package/lib/module/app/screens/HomeScreen.js +176 -0
  66. package/lib/module/app/screens/HomeScreen.js.map +1 -0
  67. package/lib/module/app/screens/SelectBusiness.js +201 -0
  68. package/lib/module/app/screens/SelectBusiness.js.map +1 -0
  69. package/lib/module/app/screens/Splash.js +51 -0
  70. package/lib/module/app/screens/Splash.js.map +1 -0
  71. package/lib/module/app/screens/Suppliers.js +222 -0
  72. package/lib/module/app/screens/Suppliers.js.map +1 -0
  73. package/lib/module/app/screens/TransactionDetails.js +301 -0
  74. package/lib/module/app/screens/TransactionDetails.js.map +1 -0
  75. package/lib/module/app/screens/index.js +14 -0
  76. package/lib/module/app/screens/index.js.map +1 -0
  77. package/lib/module/app/themes/config.js +156 -0
  78. package/lib/module/app/themes/config.js.map +1 -0
  79. package/lib/module/app/utils/countries.json +1930 -0
  80. package/lib/module/declarations.d.js +2 -0
  81. package/lib/module/declarations.d.js.map +1 -0
  82. package/lib/module/index.js +5 -0
  83. package/lib/module/index.js.map +1 -0
  84. package/lib/module/package.json +1 -0
  85. package/lib/typescript/babel.config.d.ts +10 -0
  86. package/lib/typescript/babel.config.d.ts.map +1 -0
  87. package/lib/typescript/eslint.config.d.mts +3 -0
  88. package/lib/typescript/eslint.config.d.mts.map +1 -0
  89. package/lib/typescript/package.json +1 -0
  90. package/lib/typescript/src/App.d.ts +2 -0
  91. package/lib/typescript/src/App.d.ts.map +1 -0
  92. package/lib/typescript/src/app/components/Balance.d.ts +8 -0
  93. package/lib/typescript/src/app/components/Balance.d.ts.map +1 -0
  94. package/lib/typescript/src/app/components/CountryPhoneInput.d.ts +6 -0
  95. package/lib/typescript/src/app/components/CountryPhoneInput.d.ts.map +1 -0
  96. package/lib/typescript/src/app/components/Entries.d.ts +4 -0
  97. package/lib/typescript/src/app/components/Entries.d.ts.map +1 -0
  98. package/lib/typescript/src/app/components/SearchBar.d.ts +6 -0
  99. package/lib/typescript/src/app/components/SearchBar.d.ts.map +1 -0
  100. package/lib/typescript/src/app/components/Transaction.d.ts +11 -0
  101. package/lib/typescript/src/app/components/Transaction.d.ts.map +1 -0
  102. package/lib/typescript/src/app/components/User.d.ts +10 -0
  103. package/lib/typescript/src/app/components/User.d.ts.map +1 -0
  104. package/lib/typescript/src/app/components/index.d.ts +8 -0
  105. package/lib/typescript/src/app/components/index.d.ts.map +1 -0
  106. package/lib/typescript/src/app/database/clients.d.ts +9 -0
  107. package/lib/typescript/src/app/database/clients.d.ts.map +1 -0
  108. package/lib/typescript/src/app/database/database.d.ts +3 -0
  109. package/lib/typescript/src/app/database/database.d.ts.map +1 -0
  110. package/lib/typescript/src/app/database/schema.d.ts +2 -0
  111. package/lib/typescript/src/app/database/schema.d.ts.map +1 -0
  112. package/lib/typescript/src/app/navigation/BottomTabs/BottomTabs.d.ts +2 -0
  113. package/lib/typescript/src/app/navigation/BottomTabs/BottomTabs.d.ts.map +1 -0
  114. package/lib/typescript/src/app/navigation/Drawer/Drawer.d.ts +2 -0
  115. package/lib/typescript/src/app/navigation/Drawer/Drawer.d.ts.map +1 -0
  116. package/lib/typescript/src/app/navigation/HomeStack/HomeStack.d.ts +2 -0
  117. package/lib/typescript/src/app/navigation/HomeStack/HomeStack.d.ts.map +1 -0
  118. package/lib/typescript/src/app/navigation/Root.d.ts +2 -0
  119. package/lib/typescript/src/app/navigation/Root.d.ts.map +1 -0
  120. package/lib/typescript/src/app/navigation/index.d.ts +5 -0
  121. package/lib/typescript/src/app/navigation/index.d.ts.map +1 -0
  122. package/lib/typescript/src/app/redux/Store.d.ts +2 -0
  123. package/lib/typescript/src/app/redux/Store.d.ts.map +1 -0
  124. package/lib/typescript/src/app/redux/reducers/client/client_actions.d.ts +1 -0
  125. package/lib/typescript/src/app/redux/reducers/client/client_actions.d.ts.map +1 -0
  126. package/lib/typescript/src/app/redux/reducers/client/client_reducers.d.ts +3 -0
  127. package/lib/typescript/src/app/redux/reducers/client/client_reducers.d.ts.map +1 -0
  128. package/lib/typescript/src/app/redux/reducers/client/client_types.d.ts +5 -0
  129. package/lib/typescript/src/app/redux/reducers/client/client_types.d.ts.map +1 -0
  130. package/lib/typescript/src/app/screens/AddScreen.d.ts +5 -0
  131. package/lib/typescript/src/app/screens/AddScreen.d.ts.map +1 -0
  132. package/lib/typescript/src/app/screens/Banks.d.ts +2 -0
  133. package/lib/typescript/src/app/screens/Banks.d.ts.map +1 -0
  134. package/lib/typescript/src/app/screens/CustomerEntries.d.ts +5 -0
  135. package/lib/typescript/src/app/screens/CustomerEntries.d.ts.map +1 -0
  136. package/lib/typescript/src/app/screens/Customers.d.ts +4 -0
  137. package/lib/typescript/src/app/screens/Customers.d.ts.map +1 -0
  138. package/lib/typescript/src/app/screens/Entry.d.ts +5 -0
  139. package/lib/typescript/src/app/screens/Entry.d.ts.map +1 -0
  140. package/lib/typescript/src/app/screens/HomeScreen.d.ts +4 -0
  141. package/lib/typescript/src/app/screens/HomeScreen.d.ts.map +1 -0
  142. package/lib/typescript/src/app/screens/SelectBusiness.d.ts +4 -0
  143. package/lib/typescript/src/app/screens/SelectBusiness.d.ts.map +1 -0
  144. package/lib/typescript/src/app/screens/Splash.d.ts +4 -0
  145. package/lib/typescript/src/app/screens/Splash.d.ts.map +1 -0
  146. package/lib/typescript/src/app/screens/Suppliers.d.ts +4 -0
  147. package/lib/typescript/src/app/screens/Suppliers.d.ts.map +1 -0
  148. package/lib/typescript/src/app/screens/TransactionDetails.d.ts +5 -0
  149. package/lib/typescript/src/app/screens/TransactionDetails.d.ts.map +1 -0
  150. package/lib/typescript/src/app/screens/index.d.ts +12 -0
  151. package/lib/typescript/src/app/screens/index.d.ts.map +1 -0
  152. package/lib/typescript/src/app/themes/config.d.ts +63 -0
  153. package/lib/typescript/src/app/themes/config.d.ts.map +1 -0
  154. package/lib/typescript/src/index.d.ts +3 -0
  155. package/lib/typescript/src/index.d.ts.map +1 -0
  156. package/package.json +154 -0
  157. package/src/App.js +41 -0
  158. package/src/app/assets/Icons/Bill.png +0 -0
  159. package/src/app/assets/Icons/Cash.png +0 -0
  160. package/src/app/assets/Icons/Expense.png +0 -0
  161. package/src/app/assets/Icons/Staff.png +0 -0
  162. package/src/app/assets/Icons/Stock.png +0 -0
  163. package/src/app/assets/images/bill.png +0 -0
  164. package/src/app/assets/images/book.png +0 -0
  165. package/src/app/assets/images/digiKhataSolo256.png +0 -0
  166. package/src/app/assets/images/money.png +0 -0
  167. package/src/app/assets/images/staff.png +0 -0
  168. package/src/app/assets/images/stock.png +0 -0
  169. package/src/app/assets/images/svgviewer-png-output-white.png +0 -0
  170. package/src/app/components/Balance.js +122 -0
  171. package/src/app/components/CountryPhoneInput.js +286 -0
  172. package/src/app/components/Entries.js +75 -0
  173. package/src/app/components/SearchBar.js +64 -0
  174. package/src/app/components/Transaction.js +91 -0
  175. package/src/app/components/User.js +85 -0
  176. package/src/app/components/index.js +15 -0
  177. package/src/app/database/clients.js +207 -0
  178. package/src/app/database/database.js +9 -0
  179. package/src/app/database/schema.js +525 -0
  180. package/src/app/navigation/BottomTabs/BottomTabs.js +27 -0
  181. package/src/app/navigation/Drawer/Drawer.js +10 -0
  182. package/src/app/navigation/HomeStack/HomeStack.js +43 -0
  183. package/src/app/navigation/Root.js +32 -0
  184. package/src/app/navigation/index.js +9 -0
  185. package/src/app/redux/Store.js +9 -0
  186. package/src/app/redux/reducers/client/client_actions.js +0 -0
  187. package/src/app/redux/reducers/client/client_reducers.js +30 -0
  188. package/src/app/redux/reducers/client/client_types.js +5 -0
  189. package/src/app/screens/AddScreen.js +185 -0
  190. package/src/app/screens/Banks.js +151 -0
  191. package/src/app/screens/CustomerEntries.js +402 -0
  192. package/src/app/screens/Customers.js +240 -0
  193. package/src/app/screens/Entry.js +658 -0
  194. package/src/app/screens/HomeScreen.js +146 -0
  195. package/src/app/screens/SelectBusiness.js +177 -0
  196. package/src/app/screens/Splash.js +43 -0
  197. package/src/app/screens/Suppliers.js +228 -0
  198. package/src/app/screens/TransactionDetails.js +199 -0
  199. package/src/app/screens/index.js +23 -0
  200. package/src/app/themes/config.js +185 -0
  201. package/src/app/utils/countries.json +1930 -0
  202. package/src/declarations.d.ts +1 -0
  203. 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
+
@@ -0,0 +1,9 @@
1
+ import SQLite from "react-native-sqlite-storage";
2
+
3
+ const db = SQLite.openDatabase(
4
+ { name: "app.db", location: "default" },
5
+ () => console.log("Database opened"),
6
+ (error) => console.log("DB Error: ", error)
7
+ );
8
+
9
+ export default db;