ordering-ui-react-native 0.22.12 → 0.22.13

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ordering-ui-react-native",
3
- "version": "0.22.12",
3
+ "version": "0.22.13",
4
4
  "description": "Reusable components made in react native",
5
5
  "main": "src/index.tsx",
6
6
  "author": "ordering.inc",
@@ -61,22 +61,22 @@ export const usePrinterCommands = () => {
61
61
  return formattedDate
62
62
  }
63
63
 
64
- const generateProductsText = (order: any) => {
64
+ const generateProductsText = (order: any, { endLine }: any) => {
65
65
  const list: any = []
66
66
 
67
67
  if (order?.products.length) {
68
68
  order?.products.map((product: any) => {
69
- list.push(`${product?.quantity} ${product?.name} \t ${parsePrice(product.total ?? getProductPrice(product))}\n`)
69
+ list.push(`${product?.quantity} ${product?.name} \t ${parsePrice(product.total ?? getProductPrice(product))}${endLine}`)
70
70
 
71
71
  if (product?.ingredients?.length) {
72
- list.push({ text: `\t ${t('INGREDIENTS', 'Ingredients')}:\n`, props: { fontSize: 10 } })
72
+ list.push({ text: `\t ${t('INGREDIENTS', 'Ingredients')}:${endLine}`, props: { fontSize: 10 } })
73
73
  product?.ingredients?.map((ingredient: any) => {
74
- list.push({ text: `\t ${t('NO', 'No')} ${ingredient.name}\n` , fontSize: 10 })
74
+ list.push({ text: `\t ${t('NO', 'No')} ${ingredient.name}${endLine}` , fontSize: 10 })
75
75
  })
76
76
  }
77
77
 
78
78
  product.options?.map((option: any) => {
79
- list.push({ text: `\t ${option.name}\n`, props: { fontSize: 10 } })
79
+ list.push({ text: `\t ${option.name}${endLine}`, props: { fontSize: 10 } })
80
80
 
81
81
  option.suboptions?.map((suboption: any) => {
82
82
  const { quantity, name, position, price } = suboption
@@ -87,23 +87,23 @@ export const usePrinterCommands = () => {
87
87
  : `${quantity} x ${name} +${parsePrice(price)}`
88
88
  : 'No'
89
89
 
90
- list.push({ text: `\t\t ${string}\n`, props: { fontSize: 10 } })
90
+ list.push({ text: `\t\t ${string}${endLine}`, props: { fontSize: 10 } })
91
91
  })
92
92
  })
93
93
 
94
94
  if (product.comment) {
95
- list.push({ text: `\t ${t('COMMENT', 'Comment')}\n`, props: { fontSize: 10 } })
96
- list.push({ text: `\t\t ${product.comment}\n`, props: { fontSize: 10 } })
95
+ list.push({ text: `\t ${t('COMMENT', 'Comment')}${endLine}`, props: { fontSize: 10 } })
96
+ list.push({ text: `\t\t ${product.comment}${endLine}`, props: { fontSize: 10 } })
97
97
  }
98
98
 
99
- list.push('_separator_\n')
99
+ list.push('_separator_')
100
100
  })
101
101
  }
102
102
 
103
103
  return list
104
104
  }
105
105
 
106
- const paymethodsList = (order: any) => {
106
+ const paymethodsList = (order: any, { endLine }: any) => {
107
107
  const list: any = []
108
108
 
109
109
  if (order?.payment_events?.length > 0) {
@@ -116,7 +116,7 @@ export const usePrinterCommands = () => {
116
116
  ? parsePrice(order?.cash, { currency: order?.currency })
117
117
  : `-${parsePrice(event?.amount, { currency: order?.currency })}`
118
118
 
119
- list.push(`${payment} \t ${amount}\n`)
119
+ list.push(`${payment} \t ${amount}${endLine}`)
120
120
  })
121
121
  }
122
122
 
@@ -126,60 +126,61 @@ export const usePrinterCommands = () => {
126
126
  const generateCommands = (order: any, printMode: string = 'append') => {
127
127
  let commands: any = [];
128
128
 
129
+ const isAppendMode = printMode === 'append'
130
+ const jumpLine = isAppendMode ? '\n' : ' '
131
+ const endLine = isAppendMode ? '\n' : ''
132
+
129
133
  const textProps = { fontSize: 12 }
130
134
 
131
135
  const appends: any = [
132
- { text: `${t('ORDER_NO', 'Order No.')} ${order.id}\n`, props: { fontSize: 16 } },
133
- ' ',
134
- `${order.orderStatus}\n`,
135
- { text: `${t('ORDER_TYPE', 'Order Type')}: ${deliveryStatus[order?.delivery_type]}\n`, props: { fontSize: 14 } },
136
- { text: `${t(`PAYMENT_METHOD${paymethodsLength(order) > 1 ? 'S' : ''}`, `Payment method${paymethodsLength(order) > 1 ? 's' : ''}`)}: ${handlePaymethodsListString(order)}\n`, props: { fontSize: 14 } },
137
- `${!!order?.delivery_option ? `${t('DELIVERY_PREFERENCE', 'Delivery Preference')}: ${t(order?.delivery_option?.name?.toUpperCase()?.replace(/ /g, '_'), order?.delivery_option?.name)}\n` : '\n'}`,
138
- `${t('DELIVERY_DATE', 'Delivery Date')}: ${deliveryDate(order)}\n`,
139
- '_separator_\n',
140
- { text: `${t('CUSTOMER_DETAILS', 'Customer details')}\n`, props: { fontSize: 14 } },
141
- `${t('FULL_NAME', 'Full Name')}: ${customerName(order)}\n`,
142
- `${t('EMAIL', 'Email')}: ${order?.customer?.email}\n`,
143
- `${!!order?.customer?.cellphone ? `${t('MOBILE_PHONE', 'Mobile Phone')}: ${order?.customer?.cellphone}\n` : '\n'}`,
144
- `${!!order?.customer?.phone ? `${t('MOBILE_PHONE', 'Mobile Phone')}: ${order?.customer?.phone}\n` : '\n'}`,
145
- `${t('FULL_ADDRESS', 'Full Addres')}: ${order?.customer?.address}\n`,
146
- `${!!order?.customer?.internal_number ? `${t('INTERNAL_NUMBER', 'Internal Number')}: ${order?.customer?.internal_number}\n` : '\n'}`,
147
- `${!!order?.customer?.zipcode ? `${t('ZIPCODE', 'Zipcode')}: ${order?.customer?.zipcode}\n` : '\n'}`,
148
- '_separator_\n',
149
- { text: `${t('BUSINESS_DETAILS', 'Business details')}\n`, props: { fontSize: 14 } },
150
- `${order?.business?.name}\n`,
151
- `${order?.business?.email}\n`,
152
- `${!!order?.business?.cellphone ? `${t('BUSINESS_PHONE', 'Business Phone')}: ${order?.business?.cellphone}\n` : '\n'}`,
153
- `${!!order?.business?.phone ? `${t('BUSINESS_PHONE', 'Business Phone')}: ${order?.business?.phone}\n` : '\n'}`,
154
- `${t('ADDRESS', 'Address')}: ${order?.business?.address}\n`,
155
- `${!!order?.business?.address_notes ? `${t('SPECIAL_ADDRESS', 'Special Address')}: ${order?.business?.address_notes}\n` : '\n'}`,
156
- '_separator_\n',
157
- { text: `${t('ORDER_DETAILS', 'Order Details')}\n`, props: { fontSize: 14 } },
158
- `${!!order?.comment ? `${t('ORDER_COMMENT', 'Order Comment')}: ${order?.comment}\n` : '\n'}`,
159
- ...generateProductsText(order),
160
- ' ',
161
- `${t('SUBTOTAL', 'Subtotal')} \t\t ${parsePrice(order.tax_type === 1 ? (order?.summary?.subtotal + order?.summary?.tax) ?? 0 : order?.summary?.subtotal ?? 0)}\n`,
162
- `${order?.summary?.discount > 0 ? `${order?.offer_type === 1 ? `${t('DISCOUNT', 'Discount')} (${verifyDecimals(order?.offer_rate, parsePrice)}%)\n` : t('DISCOUNT', 'Discount')} \t\t ${parsePrice(order?.summary?.discount)}\n` : '\n'}`,
163
- `${order?.tax_type !== 1 ? `${t('TAX', 'Tax')} (${verifyDecimals(order?.summary?.tax_rate, parseNumber)}%) \t\t ${parsePrice(order?.summary?.tax ?? 0)}\n` : '\n'}`,
164
- `${order?.summary?.delivery_price > 0 && order.delivery_type !== 2 ? `${t('DELIVERY_FEE', 'Delivery Fee')} \t\t ${parsePrice(order?.summary?.delivery_price ?? 0)}\n` : '\n'}`,
165
- `${(order?.summary?.driver_tip > 0 || order?.driver_tip > 0) && order.delivery_type !== 2 ? `${t('DRIVER_TIP', 'Driver tip')} ${percentTip(order) ? `(${percentTip(order)}%)` : ''} \t\t ${parsePrice(order?.summary?.driver_tip ?? 0)}\n` : '\n'}`,
166
- `${order?.summary?.service_fee > 0 ? `${t('SERVICE_FEE', 'Service Fee')} (${verifyDecimals(order?.summary?.service_fee, parseNumber)}%) \t\t ${parsePrice(order?.summary?.service_fee ?? 0)}\n` : '\n'}`,
167
- '_separator_\n',
168
- `${t('TOTAL', 'Total')} \t\t ${parsePrice(order?.summary?.total ?? 0)}\n`,
169
- ' ',
170
- `${order?.payment_events?.length > 0 ? `${t('PAYMENTS', 'Payments')}\n` : '\n'}`,
171
- ...paymethodsList(order),
172
- ' ',
173
- '\n',
174
- ' ',
175
- '\n',
136
+ { text: `${t('ORDER_NO', 'Order No.')} ${order.id}${endLine}`, props: { fontSize: 16 } },
137
+ jumpLine,
138
+ `${order.orderStatus}${endLine}`,
139
+ { text: `${t('ORDER_TYPE', 'Order Type')}: ${deliveryStatus[order?.delivery_type]}${endLine}`, props: { fontSize: 14 } },
140
+ { text: `${t(`PAYMENT_METHOD${paymethodsLength(order) > 1 ? 'S' : ''}`, `Payment method${paymethodsLength(order) > 1 ? 's' : ''}`)}: ${handlePaymethodsListString(order)}${endLine}`, props: { fontSize: 14 } },
141
+ `${!!order?.delivery_option ? `${t('DELIVERY_PREFERENCE', 'Delivery Preference')}: ${t(order?.delivery_option?.name?.toUpperCase()?.replace(/ /g, '_'), order?.delivery_option?.name)}${endLine}` : ''}`,
142
+ `${t('DELIVERY_DATE', 'Delivery Date')}: ${deliveryDate(order)}${endLine}`,
143
+ '_separator_',
144
+ { text: `${t('CUSTOMER_DETAILS', 'Customer details')}${endLine}`, props: { fontSize: 14 } },
145
+ `${t('FULL_NAME', 'Full Name')}: ${customerName(order)}${endLine}`,
146
+ `${t('EMAIL', 'Email')}: ${order?.customer?.email}${endLine}`,
147
+ `${!!order?.customer?.cellphone ? `${t('MOBILE_PHONE', 'Mobile Phone')}: ${order?.customer?.cellphone}${endLine}` : ''}`,
148
+ `${!!order?.customer?.phone ? `${t('MOBILE_PHONE', 'Mobile Phone')}: ${order?.customer?.phone}${endLine}` : ''}`,
149
+ `${t('FULL_ADDRESS', 'Full Addres')}: ${order?.customer?.address}${endLine}`,
150
+ `${!!order?.customer?.internal_number ? `${t('INTERNAL_NUMBER', 'Internal Number')}: ${order?.customer?.internal_number}${endLine}` : ''}`,
151
+ `${!!order?.customer?.zipcode ? `${t('ZIPCODE', 'Zipcode')}: ${order?.customer?.zipcode}${endLine}` : ''}`,
152
+ '_separator_',
153
+ { text: `${t('BUSINESS_DETAILS', 'Business details')}${endLine}`, props: { fontSize: 14 } },
154
+ `${order?.business?.name}${endLine}`,
155
+ `${order?.business?.email}${endLine}`,
156
+ `${!!order?.business?.cellphone ? `${t('BUSINESS_PHONE', 'Business Phone')}: ${order?.business?.cellphone}${endLine}` : ''}`,
157
+ `${!!order?.business?.phone ? `${t('BUSINESS_PHONE', 'Business Phone')}: ${order?.business?.phone}${endLine}` : ''}`,
158
+ `${t('ADDRESS', 'Address')}: ${order?.business?.address}${endLine}`,
159
+ `${!!order?.business?.address_notes ? `${t('SPECIAL_ADDRESS', 'Special Address')}: ${order?.business?.address_notes}${endLine}` : ''}`,
160
+ '_separator_',
161
+ { text: `${t('ORDER_DETAILS', 'Order Details')}${endLine}`, props: { fontSize: 14 } },
162
+ `${!!order?.comment ? `${t('ORDER_COMMENT', 'Order Comment')}: ${order?.comment}${endLine}` : ''}`,
163
+ ...generateProductsText(order, { endLine }),
164
+ `${t('SUBTOTAL', 'Subtotal')} \t\t ${parsePrice(order.tax_type === 1 ? (order?.summary?.subtotal + order?.summary?.tax) ?? 0 : order?.summary?.subtotal ?? 0)}${endLine}`,
165
+ `${order?.summary?.discount > 0 ? `${order?.offer_type === 1 ? `${t('DISCOUNT', 'Discount')} (${verifyDecimals(order?.offer_rate, parsePrice)}%)${endLine}` : t('DISCOUNT', 'Discount')} \t\t ${parsePrice(order?.summary?.discount)}${endLine}` : ''}`,
166
+ `${order?.tax_type !== 1 ? `${t('TAX', 'Tax')} (${verifyDecimals(order?.summary?.tax_rate, parseNumber)}%) \t\t ${parsePrice(order?.summary?.tax ?? 0)}${endLine}` : ''}`,
167
+ `${order?.summary?.delivery_price > 0 && order.delivery_type !== 2 ? `${t('DELIVERY_FEE', 'Delivery Fee')} \t\t ${parsePrice(order?.summary?.delivery_price ?? 0)}${endLine}` : ''}`,
168
+ `${(order?.summary?.driver_tip > 0 || order?.driver_tip > 0) && order.delivery_type !== 2 ? `${t('DRIVER_TIP', 'Driver tip')} ${percentTip(order) ? `(${percentTip(order)}%)` : ''} \t\t ${parsePrice(order?.summary?.driver_tip ?? 0)}${endLine}` : ''}`,
169
+ `${order?.summary?.service_fee > 0 ? `${t('SERVICE_FEE', 'Service Fee')} (${verifyDecimals(order?.summary?.service_fee, parseNumber)}%) \t\t ${parsePrice(order?.summary?.service_fee ?? 0)}${endLine}` : ''}`,
170
+ '_separator_',
171
+ `${t('TOTAL', 'Total')} \t\t ${parsePrice(order?.summary?.total ?? 0)}${endLine}`,
172
+ jumpLine,
173
+ `${order?.payment_events?.length > 0 ? `${t('PAYMENTS', 'Payments')}${endLine}` : ''}`,
174
+ ...paymethodsList(order, { endLine }),
175
+ jumpLine,
176
+ jumpLine,
176
177
  ]
177
178
 
178
179
  commands = [
179
180
  ...commands,
180
181
  ...appends.map((append: any) => {
181
182
  return append === '_separator_'
182
- ? { [printMode]: '---------------------------------------' }
183
+ ? { [printMode]: `---------------------------------------${endLine}` }
183
184
  : {
184
185
  [printMode]: append?.text ?? append,
185
186
  ...textProps,