addio-admin-sdk 1.7.141 → 1.7.143
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/dist/Interfaces/CashDrawers/index.d.ts +37 -0
- package/dist/Interfaces/CashDrawers/index.js +20 -0
- package/dist/Interfaces/CashDrawers/index.js.map +1 -0
- package/dist/Interfaces/Space/index.d.ts +4 -0
- package/dist/Interfaces/Space/index.js +4 -2
- package/dist/Interfaces/Space/index.js.map +1 -1
- package/dist/lib/CashDrawerShift/index.d.ts +83 -0
- package/dist/lib/CashDrawerShift/index.js +206 -0
- package/dist/lib/CashDrawerShift/index.js.map +1 -0
- package/dist/lib/Space/index.d.ts +82 -0
- package/dist/lib/Space/index.js +157 -2
- package/dist/lib/Space/index.js.map +1 -1
- package/dist/utils/tcgService.js +22 -14
- package/dist/utils/tcgService.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export interface ICashDrawer {
|
|
2
|
+
readonly id: string;
|
|
3
|
+
readonly nickname: string;
|
|
4
|
+
readonly drawer_number?: number;
|
|
5
|
+
readonly active: boolean;
|
|
6
|
+
}
|
|
7
|
+
export interface ICashDrawerShift {
|
|
8
|
+
readonly id?: string;
|
|
9
|
+
readonly cash_drawer_id: string;
|
|
10
|
+
readonly opened_details: ICashDrawerShiftDetails;
|
|
11
|
+
readonly closed_details?: ICashDrawerShiftDetails;
|
|
12
|
+
readonly is_open: boolean;
|
|
13
|
+
}
|
|
14
|
+
interface ICashDrawerShiftDetails {
|
|
15
|
+
readonly date: Date;
|
|
16
|
+
readonly by_user: string;
|
|
17
|
+
}
|
|
18
|
+
export interface ICashDrawerInteraction {
|
|
19
|
+
readonly id?: string;
|
|
20
|
+
readonly date: Date;
|
|
21
|
+
readonly action: CashDrawerActionEnum;
|
|
22
|
+
readonly user: string;
|
|
23
|
+
readonly amount: number;
|
|
24
|
+
readonly cash_drawer_id: string;
|
|
25
|
+
readonly shift_id: string;
|
|
26
|
+
readonly reason?: string;
|
|
27
|
+
}
|
|
28
|
+
export declare enum CashDrawerActionEnum {
|
|
29
|
+
OPEN_SHIFT = "start_shift",
|
|
30
|
+
ORDER_CASH_IN = "order_cash_in",
|
|
31
|
+
ORDER_CASH_OUT = "order_cash_out",
|
|
32
|
+
MANUAL_CASH_IN = "manual_cash_in",
|
|
33
|
+
MANUAL_CASH_OUT = "manual_cash_out",
|
|
34
|
+
END_SHIFT = "end_shift"
|
|
35
|
+
}
|
|
36
|
+
export declare const getDefaultCashDrawer: () => ICashDrawer;
|
|
37
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDefaultCashDrawer = exports.CashDrawerActionEnum = void 0;
|
|
4
|
+
const uuid_1 = require("uuid");
|
|
5
|
+
var CashDrawerActionEnum;
|
|
6
|
+
(function (CashDrawerActionEnum) {
|
|
7
|
+
CashDrawerActionEnum["OPEN_SHIFT"] = "start_shift";
|
|
8
|
+
CashDrawerActionEnum["ORDER_CASH_IN"] = "order_cash_in";
|
|
9
|
+
CashDrawerActionEnum["ORDER_CASH_OUT"] = "order_cash_out";
|
|
10
|
+
CashDrawerActionEnum["MANUAL_CASH_IN"] = "manual_cash_in";
|
|
11
|
+
CashDrawerActionEnum["MANUAL_CASH_OUT"] = "manual_cash_out";
|
|
12
|
+
CashDrawerActionEnum["END_SHIFT"] = "end_shift";
|
|
13
|
+
})(CashDrawerActionEnum = exports.CashDrawerActionEnum || (exports.CashDrawerActionEnum = {}));
|
|
14
|
+
const getDefaultCashDrawer = () => ({
|
|
15
|
+
id: (0, uuid_1.v4)(),
|
|
16
|
+
nickname: '',
|
|
17
|
+
active: true
|
|
18
|
+
});
|
|
19
|
+
exports.getDefaultCashDrawer = getDefaultCashDrawer;
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/Interfaces/CashDrawers/index.ts"],"names":[],"mappings":";;;AAAA,+BAAyB;AAiCzB,IAAY,oBAOX;AAPD,WAAY,oBAAoB;IAC/B,kDAA0B,CAAA;IAC1B,uDAA+B,CAAA;IAC/B,yDAAiC,CAAA;IACjC,yDAAiC,CAAA;IACjC,2DAAmC,CAAA;IACnC,+CAAuB,CAAA;AACxB,CAAC,EAPW,oBAAoB,GAApB,4BAAoB,KAApB,4BAAoB,QAO/B;AAEM,MAAM,oBAAoB,GAAG,GAAgB,EAAE,CAAC,CAAC;IACvD,EAAE,EAAE,IAAA,SAAE,GAAE;IACR,QAAQ,EAAE,EAAE;IACZ,MAAM,EAAE,IAAI;CACZ,CAAC,CAAA;AAJW,QAAA,oBAAoB,wBAI/B"}
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
import Space from '../../lib/Space';
|
|
10
10
|
import IAddress from '../Address';
|
|
11
11
|
import { CustomPaymentTypeEnum, PaymentTypeEnum } from '../Cart';
|
|
12
|
+
import { ICashDrawer } from '../CashDrawers';
|
|
12
13
|
import { ISliderContent, ISliderOptions } from '../CMS';
|
|
13
14
|
import { InventoryPriorityTypeEnum } from '../Inventory';
|
|
14
15
|
import { IBankType } from '../PromiseToPurchase/BankType';
|
|
@@ -167,6 +168,7 @@ export default interface ISpace {
|
|
|
167
168
|
readonly pos_settings?: {
|
|
168
169
|
readonly auto_lock_delay?: number | null;
|
|
169
170
|
};
|
|
171
|
+
readonly cash_drawers?: ICashDrawer[];
|
|
170
172
|
readonly other?: {
|
|
171
173
|
readonly auto_fill_title_with_image_name?: {
|
|
172
174
|
readonly is_active: boolean;
|
|
@@ -358,11 +360,13 @@ export interface ISpaceOptions {
|
|
|
358
360
|
readonly space_has_bookings?: boolean;
|
|
359
361
|
readonly has_pos?: boolean;
|
|
360
362
|
readonly allow_custom_prices_in_categories?: boolean;
|
|
363
|
+
readonly can_manage_cash_drawers?: boolean;
|
|
361
364
|
};
|
|
362
365
|
readonly pos?: {
|
|
363
366
|
readonly has_custom_pos?: boolean;
|
|
364
367
|
readonly is_public?: boolean;
|
|
365
368
|
readonly can_put_carts_on_hold?: boolean;
|
|
369
|
+
readonly must_assign_cash_drawer?: boolean;
|
|
366
370
|
};
|
|
367
371
|
readonly booking?: {
|
|
368
372
|
readonly set_store_for_booking_inventory_management?: boolean;
|
|
@@ -84,12 +84,14 @@ const getDefaultSpaceOptions = () => ({
|
|
|
84
84
|
allow_refunds: false,
|
|
85
85
|
space_has_bookings: false,
|
|
86
86
|
has_pos: false,
|
|
87
|
-
allow_custom_prices_in_categories: false
|
|
87
|
+
allow_custom_prices_in_categories: false,
|
|
88
|
+
can_manage_cash_drawers: false
|
|
88
89
|
},
|
|
89
90
|
pos: {
|
|
90
91
|
has_custom_pos: false,
|
|
91
92
|
is_public: false,
|
|
92
|
-
can_put_carts_on_hold: false
|
|
93
|
+
can_put_carts_on_hold: false,
|
|
94
|
+
must_assign_cash_drawer: false
|
|
93
95
|
},
|
|
94
96
|
booking: {
|
|
95
97
|
set_store_for_booking_inventory_management: false
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/Interfaces/Space/index.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;AAIH,kCAAgE;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/Interfaces/Space/index.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;AAIH,kCAAgE;AAOhE,gDAAqE;AAySrE,uEAAuE;AACvE,IAAY,oBA2BX;AA3BD,WAAY,oBAAoB;IAC/B,mDAA2B,CAAA;IAC3B,0DAAkC,CAAA;IAClC,iDAAyB,CAAA;IACzB,+CAAuB,CAAA;IACvB,uCAAe,CAAA;IACf,yCAAiB,CAAA;IACjB,6CAAqB,CAAA;IACrB,+CAAuB,CAAA;IACvB,mDAA2B,CAAA;IAC3B,6CAAqB,CAAA;IACrB,qCAAa,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|
|
2
|
+
import { BaseServiceClass } from '../baseService';
|
|
3
|
+
import Space from '../Space';
|
|
4
|
+
export default class CashDrawerShift extends BaseServiceClass<ICashDrawerShift> {
|
|
5
|
+
private _space;
|
|
6
|
+
private _cashDrawerId;
|
|
7
|
+
constructor(space: Space, cashDrawerId: string, _data: ICashDrawerShift, _collection: {
|
|
8
|
+
path: string;
|
|
9
|
+
}, _user: string);
|
|
10
|
+
data: () => ICashDrawerShift;
|
|
11
|
+
save: (partialShift?: Partial<ICashDrawerShift>) => Promise<boolean>;
|
|
12
|
+
/**
|
|
13
|
+
* Delete function overriden so it can't be called though class
|
|
14
|
+
*/
|
|
15
|
+
delete: () => Promise<boolean>;
|
|
16
|
+
/**
|
|
17
|
+
* Get cash drawer interaction string for specified action, in specified locale.
|
|
18
|
+
* @static
|
|
19
|
+
* @param action A streamlined enum of cash drawer actions - supports all EXCEPT manual actions (MANUAL_CASH_IN and MANUAL_CASH_OUT)
|
|
20
|
+
* @param locale Optionnal. The local to use. Defaults to 'fr'.
|
|
21
|
+
* @param orderRef Optionnal. Order ref number to add to string. Only used in ORDER type actions, and defaults to 'ND' if undefined.
|
|
22
|
+
* @returns The translated string.
|
|
23
|
+
*/
|
|
24
|
+
static getTranslatedGenericInteractionReason: (action: Exclude<CashDrawerActionEnum, CashDrawerActionEnum.MANUAL_CASH_IN | CashDrawerActionEnum.MANUAL_CASH_OUT>, locale: string | undefined, orderRef?: string) => string;
|
|
25
|
+
/**
|
|
26
|
+
* Create a new open shift entry, and save result to database. Also calls function to generate the corresponding interaction.
|
|
27
|
+
* @static
|
|
28
|
+
* @param amountInDrawer The cash amount in drawer on open.
|
|
29
|
+
* @param space Space obj instance.
|
|
30
|
+
* @param associatedDrawerId The cash drawer id associated to shift
|
|
31
|
+
* @param userEmail The user that initiated cash drawer opening.
|
|
32
|
+
* @throws If something goes wrong on save for new shift obj.
|
|
33
|
+
* @returns The newly generated CashDrawerShift instance.
|
|
34
|
+
*/
|
|
35
|
+
static openShift: (amountInDrawer: number, space: Space, associatedDrawerId: string, userEmail: string) => Promise<CashDrawerShift>;
|
|
36
|
+
/**
|
|
37
|
+
* Generates a new CashDrawerInteraction with provided data and saves entry to database.
|
|
38
|
+
* @private
|
|
39
|
+
* @param type The action done on cash drawer
|
|
40
|
+
* @param amount The amount of cash "moved" with the interaction.
|
|
41
|
+
* @param options.reason The string reason for the interaction. Will either be generated string for all "normal" interactions, or a user generated string if a manual interaction.
|
|
42
|
+
* @throws If current shift data has no ID set (meaning it was never saved to database).
|
|
43
|
+
* @returns If the interaction was saved successfully.
|
|
44
|
+
*/
|
|
45
|
+
private _saveNewInteraction;
|
|
46
|
+
/**
|
|
47
|
+
* Generate data needed to close the shift and update data in database. Also calls function to generate corresponding interaction.
|
|
48
|
+
* @param amountInDrawer The cash amount in drawer on close
|
|
49
|
+
* @param userEmail Optionnal. If user who initiated the close if different from the class initiating user. Defaults to value sent to constructor if undefined.
|
|
50
|
+
* @throws If shift is not currently "open".
|
|
51
|
+
* @throws If something goes wrong on saving Shift.
|
|
52
|
+
* @returns If close was successfull.
|
|
53
|
+
*/
|
|
54
|
+
closeShift: (amountInDrawer: number, userEmail?: string) => Promise<boolean>;
|
|
55
|
+
/**
|
|
56
|
+
* Calls function to generate and save new interaction for cash added to drawer.
|
|
57
|
+
* @param amount The cash amount added to the drawer
|
|
58
|
+
* @param type The interaction type. Either 'from_order' or 'manual'
|
|
59
|
+
* @param options.reason The reason for the added cash interaction.
|
|
60
|
+
* @param options.userEmail Optionnal. If user who added cash to drawer is different from the class initiating user. Defaults to value sent to constructor if undefined.
|
|
61
|
+
* @throws If shift is not currently "open".
|
|
62
|
+
* @throws If something goes wrong on saving Shift.
|
|
63
|
+
* @returns If interaction was saved successfully or not
|
|
64
|
+
*/
|
|
65
|
+
newCashIn: (amount: number, type: 'manual' | 'from_order', options: {
|
|
66
|
+
reason: string;
|
|
67
|
+
userEmail?: string;
|
|
68
|
+
}) => Promise<boolean>;
|
|
69
|
+
/**
|
|
70
|
+
* Calls function to generate and save new interaction for cash removed from drawer.
|
|
71
|
+
* @param amount The cash amount removed from the drawer
|
|
72
|
+
* @param type The interaction type. Either 'from_order' or 'manual'
|
|
73
|
+
* @param options.reason The reason for the removed cash interaction.
|
|
74
|
+
* @param options.userEmail Optionnal. If user who removed cash from drawer is different from the class initiating user. Defaults to value sent to constructor if undefined.
|
|
75
|
+
* @throws If shift is not currently "open".
|
|
76
|
+
* @throws If something goes wrong on saving Shift.
|
|
77
|
+
* @returns If interaction was saved successfully or not
|
|
78
|
+
*/
|
|
79
|
+
newCashOut: (amount: number, type: 'manual' | 'from_order', options: {
|
|
80
|
+
reason: string;
|
|
81
|
+
userEmail?: string;
|
|
82
|
+
}) => Promise<boolean>;
|
|
83
|
+
}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
var _a;
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
const CashDrawers_1 = require("../../Interfaces/CashDrawers");
|
|
8
|
+
const DatabaseService_1 = __importDefault(require("../../services/database/DatabaseService"));
|
|
9
|
+
const locale_1 = require("../../utils/locale");
|
|
10
|
+
const baseService_1 = require("../baseService");
|
|
11
|
+
class CashDrawerShift extends baseService_1.BaseServiceClass {
|
|
12
|
+
constructor(space, cashDrawerId, _data, _collection, _user) {
|
|
13
|
+
super(_data, _collection, _user);
|
|
14
|
+
// ---------------------------------------------------------------
|
|
15
|
+
// #region DEFAULT CLASS FUNCTIONS
|
|
16
|
+
this.data = () => this._data;
|
|
17
|
+
this.save = async (partialShift) => {
|
|
18
|
+
const superSave = await super.save(partialShift || {}, undefined, true, undefined, undefined, undefined, !!partialShift);
|
|
19
|
+
if (typeof superSave == 'string' && !this._data.id)
|
|
20
|
+
this._data = Object.assign(Object.assign({}, this._data), { id: superSave });
|
|
21
|
+
return !!superSave;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Delete function overriden so it can't be called though class
|
|
25
|
+
*/
|
|
26
|
+
this.delete = async () => {
|
|
27
|
+
console.log("Can't delete a shift like this! Returning.");
|
|
28
|
+
return false;
|
|
29
|
+
};
|
|
30
|
+
// #endregion
|
|
31
|
+
// ---------------------------------------------------------------
|
|
32
|
+
// #region SPECIFIC FUNCTIONS
|
|
33
|
+
/**
|
|
34
|
+
* Generates a new CashDrawerInteraction with provided data and saves entry to database.
|
|
35
|
+
* @private
|
|
36
|
+
* @param type The action done on cash drawer
|
|
37
|
+
* @param amount The amount of cash "moved" with the interaction.
|
|
38
|
+
* @param options.reason The string reason for the interaction. Will either be generated string for all "normal" interactions, or a user generated string if a manual interaction.
|
|
39
|
+
* @throws If current shift data has no ID set (meaning it was never saved to database).
|
|
40
|
+
* @returns If the interaction was saved successfully.
|
|
41
|
+
*/
|
|
42
|
+
this._saveNewInteraction = async (type, amount, options) => {
|
|
43
|
+
if (!this._data.id)
|
|
44
|
+
throw new Error("Shift was never saved to database, can't create new interaction! Returning.");
|
|
45
|
+
// Construct data from info provided and drawer + shift ids
|
|
46
|
+
const interactionData = {
|
|
47
|
+
cash_drawer_id: this._cashDrawerId,
|
|
48
|
+
shift_id: this._data.id,
|
|
49
|
+
date: new Date(),
|
|
50
|
+
action: type,
|
|
51
|
+
user: options.userEmail || this._user,
|
|
52
|
+
amount,
|
|
53
|
+
reason: options.reason
|
|
54
|
+
};
|
|
55
|
+
// Save new entry to database
|
|
56
|
+
const saved = await DatabaseService_1.default.addDocument(DatabaseService_1.default.asCollectionObject(this._space.getRef().path, this._space.getRef().id + '/cash_drawer_interactions').path, interactionData);
|
|
57
|
+
return !!saved;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Generate data needed to close the shift and update data in database. Also calls function to generate corresponding interaction.
|
|
61
|
+
* @param amountInDrawer The cash amount in drawer on close
|
|
62
|
+
* @param userEmail Optionnal. If user who initiated the close if different from the class initiating user. Defaults to value sent to constructor if undefined.
|
|
63
|
+
* @throws If shift is not currently "open".
|
|
64
|
+
* @throws If something goes wrong on saving Shift.
|
|
65
|
+
* @returns If close was successfull.
|
|
66
|
+
*/
|
|
67
|
+
this.closeShift = async (amountInDrawer, userEmail) => {
|
|
68
|
+
if (!this._data.is_open)
|
|
69
|
+
throw new Error("Shift not opened, can't close! Returning.");
|
|
70
|
+
if (!!this._data.closed_details)
|
|
71
|
+
throw new Error('Shift already closed! Returning.');
|
|
72
|
+
// Save new data to close shift
|
|
73
|
+
const closed = await this.save({
|
|
74
|
+
id: this._data.id,
|
|
75
|
+
closed_details: { date: new Date(), by_user: userEmail || this._user },
|
|
76
|
+
is_open: false
|
|
77
|
+
});
|
|
78
|
+
// generate new entry in interactions collection with current info
|
|
79
|
+
try {
|
|
80
|
+
const spaceLocale = this._space.preferences.default.locale();
|
|
81
|
+
await this._saveNewInteraction(CashDrawers_1.CashDrawerActionEnum.END_SHIFT, amountInDrawer, {
|
|
82
|
+
userEmail,
|
|
83
|
+
reason: CashDrawerShift.getTranslatedGenericInteractionReason(CashDrawers_1.CashDrawerActionEnum.END_SHIFT, spaceLocale)
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
catch (e) {
|
|
87
|
+
console.log('error on creating interaction for shift close: ', e.toString());
|
|
88
|
+
}
|
|
89
|
+
return !!closed;
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* Calls function to generate and save new interaction for cash added to drawer.
|
|
93
|
+
* @param amount The cash amount added to the drawer
|
|
94
|
+
* @param type The interaction type. Either 'from_order' or 'manual'
|
|
95
|
+
* @param options.reason The reason for the added cash interaction.
|
|
96
|
+
* @param options.userEmail Optionnal. If user who added cash to drawer is different from the class initiating user. Defaults to value sent to constructor if undefined.
|
|
97
|
+
* @throws If shift is not currently "open".
|
|
98
|
+
* @throws If something goes wrong on saving Shift.
|
|
99
|
+
* @returns If interaction was saved successfully or not
|
|
100
|
+
*/
|
|
101
|
+
this.newCashIn = async (amount, type, options) => {
|
|
102
|
+
if (!this._data.is_open)
|
|
103
|
+
throw new Error("Shift not opened, can't add cash! Returning.");
|
|
104
|
+
if (!!this._data.closed_details)
|
|
105
|
+
throw new Error("Shift already closed, can't add cash! Returning.");
|
|
106
|
+
let savedInteraction = false;
|
|
107
|
+
// generate new entry in interactions collection from provided info
|
|
108
|
+
try {
|
|
109
|
+
savedInteraction = await this._saveNewInteraction(type == 'manual' ? CashDrawers_1.CashDrawerActionEnum.MANUAL_CASH_IN : CashDrawers_1.CashDrawerActionEnum.ORDER_CASH_IN, amount, options);
|
|
110
|
+
}
|
|
111
|
+
catch (e) {
|
|
112
|
+
console.log('error on saving new cash in interaction: ', e.toString());
|
|
113
|
+
}
|
|
114
|
+
return savedInteraction;
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* Calls function to generate and save new interaction for cash removed from drawer.
|
|
118
|
+
* @param amount The cash amount removed from the drawer
|
|
119
|
+
* @param type The interaction type. Either 'from_order' or 'manual'
|
|
120
|
+
* @param options.reason The reason for the removed cash interaction.
|
|
121
|
+
* @param options.userEmail Optionnal. If user who removed cash from drawer is different from the class initiating user. Defaults to value sent to constructor if undefined.
|
|
122
|
+
* @throws If shift is not currently "open".
|
|
123
|
+
* @throws If something goes wrong on saving Shift.
|
|
124
|
+
* @returns If interaction was saved successfully or not
|
|
125
|
+
*/
|
|
126
|
+
this.newCashOut = async (amount, type, options) => {
|
|
127
|
+
if (!this._data.is_open)
|
|
128
|
+
throw new Error("Shift not opened, can't remove cash! Returning.");
|
|
129
|
+
if (!!this._data.closed_details)
|
|
130
|
+
throw new Error("Shift already closed, can't remove cash! Returning.");
|
|
131
|
+
// generate new entry in interactions collection from provided info
|
|
132
|
+
let savedInteraction = false;
|
|
133
|
+
try {
|
|
134
|
+
savedInteraction = await this._saveNewInteraction(type == 'manual' ? CashDrawers_1.CashDrawerActionEnum.MANUAL_CASH_OUT : CashDrawers_1.CashDrawerActionEnum.ORDER_CASH_OUT, amount, options);
|
|
135
|
+
}
|
|
136
|
+
catch (e) {
|
|
137
|
+
console.log('error on saving new cash out interaction: ', e.toString());
|
|
138
|
+
}
|
|
139
|
+
return savedInteraction;
|
|
140
|
+
};
|
|
141
|
+
this._space = space;
|
|
142
|
+
this._cashDrawerId = cashDrawerId;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
exports.default = CashDrawerShift;
|
|
146
|
+
_a = CashDrawerShift;
|
|
147
|
+
// #endregion
|
|
148
|
+
// ---------------------------------------------------------------
|
|
149
|
+
// #region STATIC FUNCTIONS
|
|
150
|
+
/**
|
|
151
|
+
* Get cash drawer interaction string for specified action, in specified locale.
|
|
152
|
+
* @static
|
|
153
|
+
* @param action A streamlined enum of cash drawer actions - supports all EXCEPT manual actions (MANUAL_CASH_IN and MANUAL_CASH_OUT)
|
|
154
|
+
* @param locale Optionnal. The local to use. Defaults to 'fr'.
|
|
155
|
+
* @param orderRef Optionnal. Order ref number to add to string. Only used in ORDER type actions, and defaults to 'ND' if undefined.
|
|
156
|
+
* @returns The translated string.
|
|
157
|
+
*/
|
|
158
|
+
CashDrawerShift.getTranslatedGenericInteractionReason = (action, locale, orderRef) => {
|
|
159
|
+
switch (action) {
|
|
160
|
+
case CashDrawers_1.CashDrawerActionEnum.OPEN_SHIFT:
|
|
161
|
+
return (0, locale_1.translateILang)({ fr: 'Ouverture de caisse/Début de chiffre', en: 'Drawer open/Shift start' }, locale);
|
|
162
|
+
case CashDrawers_1.CashDrawerActionEnum.END_SHIFT:
|
|
163
|
+
return (0, locale_1.translateILang)({ fr: 'Fermeture de caisse/Fin de chiffre', en: 'Drawer close/Shift end' }, locale);
|
|
164
|
+
case CashDrawers_1.CashDrawerActionEnum.ORDER_CASH_IN:
|
|
165
|
+
return (0, locale_1.translateILang)({ fr: 'Remboursement ou rachat pour la commande #{num}', en: 'Refund or buyback for order #{num}' }, locale, { num: orderRef || 'ND' });
|
|
166
|
+
case CashDrawers_1.CashDrawerActionEnum.ORDER_CASH_OUT:
|
|
167
|
+
return (0, locale_1.translateILang)({ fr: "Transaction d'achat pour la commande #{num}", en: 'Transaction for order #{num}' }, locale, { num: orderRef || 'ND' });
|
|
168
|
+
default:
|
|
169
|
+
return '';
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
/**
|
|
173
|
+
* Create a new open shift entry, and save result to database. Also calls function to generate the corresponding interaction.
|
|
174
|
+
* @static
|
|
175
|
+
* @param amountInDrawer The cash amount in drawer on open.
|
|
176
|
+
* @param space Space obj instance.
|
|
177
|
+
* @param associatedDrawerId The cash drawer id associated to shift
|
|
178
|
+
* @param userEmail The user that initiated cash drawer opening.
|
|
179
|
+
* @throws If something goes wrong on save for new shift obj.
|
|
180
|
+
* @returns The newly generated CashDrawerShift instance.
|
|
181
|
+
*/
|
|
182
|
+
CashDrawerShift.openShift = async (amountInDrawer, space, associatedDrawerId, userEmail) => {
|
|
183
|
+
// generate data for shift
|
|
184
|
+
const newShiftData = {
|
|
185
|
+
cash_drawer_id: associatedDrawerId,
|
|
186
|
+
opened_details: { date: new Date(), by_user: userEmail },
|
|
187
|
+
is_open: true
|
|
188
|
+
};
|
|
189
|
+
// construct obj and save to database
|
|
190
|
+
const newShiftObj = new CashDrawerShift(space, associatedDrawerId, newShiftData, DatabaseService_1.default.asCollectionObject(space.getRef().path, space.getRef().id + '/cash_drawer_shifts'), userEmail);
|
|
191
|
+
await newShiftObj.save();
|
|
192
|
+
// generate new entry in interactions collection with current info
|
|
193
|
+
try {
|
|
194
|
+
const spaceLocale = space.preferences.default.locale();
|
|
195
|
+
await newShiftObj._saveNewInteraction(CashDrawers_1.CashDrawerActionEnum.OPEN_SHIFT, amountInDrawer, {
|
|
196
|
+
userEmail,
|
|
197
|
+
reason: CashDrawerShift.getTranslatedGenericInteractionReason(CashDrawers_1.CashDrawerActionEnum.OPEN_SHIFT, spaceLocale)
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
catch (e) {
|
|
201
|
+
console.log('error on saving interaction for shift open: ', e.toString());
|
|
202
|
+
}
|
|
203
|
+
// return the instance created for furher operations
|
|
204
|
+
return newShiftObj;
|
|
205
|
+
};
|
|
206
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/CashDrawerShift/index.ts"],"names":[],"mappings":";;;;;;AAAA,8DAA6G;AAC7G,8FAAqE;AACrE,+CAAmD;AACnD,gDAAiD;AAGjD,MAAqB,eAAgB,SAAQ,8BAAkC;IAI9E,YACC,KAAY,EACZ,YAAoB,EACpB,KAAuB,EACvB,WAA6B,EAC7B,KAAa;QAEb,KAAK,CAAC,KAAK,EAAE,WAAW,EAAE,KAAK,CAAC,CAAA;QAKjC,kEAAkE;QAClE,kCAAkC;QAC3B,SAAI,GAAG,GAAqB,EAAE,CAAC,IAAI,CAAC,KAAyB,CAAA;QAE7D,SAAI,GAAG,KAAK,EAAE,YAAwC,EAAoB,EAAE;YAClF,MAAM,SAAS,GAAG,MAAM,KAAK,CAAC,IAAI,CACjC,YAAY,IAAI,EAAE,EAClB,SAAS,EACT,IAAI,EACJ,SAAS,EACT,SAAS,EACT,SAAS,EACT,CAAC,CAAC,YAAY,CACd,CAAA;YAED,IAAI,OAAO,SAAS,IAAI,QAAQ,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;gBAAE,IAAI,CAAC,KAAK,mCAAQ,IAAI,CAAC,KAAK,KAAE,EAAE,EAAE,SAAS,GAAE,CAAA;YACjG,OAAO,CAAC,CAAC,SAAS,CAAA;QACnB,CAAC,CAAA;QAED;;WAEG;QACI,WAAM,GAAG,KAAK,IAAsB,EAAE;YAC5C,OAAO,CAAC,GAAG,CAAC,4CAA4C,CAAC,CAAA;YACzD,OAAO,KAAK,CAAA;QACb,CAAC,CAAA;QAyFD,aAAa;QAEb,kEAAkE;QAClE,6BAA6B;QAE7B;;;;;;;;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OAAO,CAAC,MAAM,EAAE,CAAA;QACtD,MAAM,WAAW,CAAC,mBAAmB,CAAC,kCAAoB,CAAC,UAAU,EAAE,cAAc,EAAE;YACtF,SAAS;YACT,MAAM,EAAE,eAAe,CAAC,qCAAqC,CAAC,kCAAoB,CAAC,UAAU,EAAE,WAAW,CAAC;SAC3G,CAAC,CAAA;KACF;IAAC,OAAO,CAAC,EAAE;QACX,OAAO,CAAC,GAAG,CAAC,8CAA8C,EAAG,CAAW,CAAC,QAAQ,EAAE,CAAC,CAAA;KACpF;IAED,oDAAoD;IACpD,OAAO,WAAW,CAAA;AACnB,CAAC,CAAA"}
|
|
@@ -64,6 +64,8 @@ import { MenuPositionEnum } from '../../Interfaces/Menu';
|
|
|
64
64
|
import Menu from '../../lib/Menu';
|
|
65
65
|
import Note from '../Note';
|
|
66
66
|
import { NoteTypeEnum } from '../../Interfaces/Note';
|
|
67
|
+
import { CashDrawerActionEnum, ICashDrawer, ICashDrawerInteraction } from '../../Interfaces/CashDrawers';
|
|
68
|
+
import CashDrawerShift from '../CashDrawerShift';
|
|
67
69
|
/**
|
|
68
70
|
* Class Space
|
|
69
71
|
* A Space represent a company.
|
|
@@ -597,6 +599,63 @@ export default class Space {
|
|
|
597
599
|
* Retourne tous les menus actifs
|
|
598
600
|
*/
|
|
599
601
|
private _getAllActiveMenus;
|
|
602
|
+
/**
|
|
603
|
+
* Utils to check and return current space cash drawers. Throws an error if space does not has corresponding feature set, or if id provided and same id not found in current cash drawers.
|
|
604
|
+
* @param idToCheck Optionnal. Cart drawer id to check in current space data.
|
|
605
|
+
*/
|
|
606
|
+
private _checkCurrentSpaceDataForCashDrawer;
|
|
607
|
+
/**
|
|
608
|
+
* Generates new cash drawer from data provided, and saves to cash_drawer array in Space data.
|
|
609
|
+
* @param data.nickname Nickname for cash drawer (required)
|
|
610
|
+
* @param data.drawerNumber Optionnal. Number for given cash drawer
|
|
611
|
+
* @throws If feature for cash drawers is not set in space_options
|
|
612
|
+
* @returns {ICashDrawer[]} Space's cash drawer array with newly added drawer at last index
|
|
613
|
+
*/
|
|
614
|
+
private _createNewCashDrawer;
|
|
615
|
+
/**
|
|
616
|
+
* Updates existing cash drawer from data provided, and saves to cash_drawer array in Space data.
|
|
617
|
+
* @param id Id for the cash drawer to update
|
|
618
|
+
* @param data.nickname Nickname for cash drawer (required)
|
|
619
|
+
* @param data.drawerNumber Optionnal. Number for given cash drawer
|
|
620
|
+
* @throws If feature for cash drawers is not set in space_options
|
|
621
|
+
* @throws If same drawer id not found in current space data cash drawers.
|
|
622
|
+
* @returns Updated space cash drawer array
|
|
623
|
+
*/
|
|
624
|
+
private _editCashDrawer;
|
|
625
|
+
/**
|
|
626
|
+
* Toggles active property for existing cash drawer, and saves to cash_drawer array in Space data.
|
|
627
|
+
* @param id Id for the cash drawer to toggle
|
|
628
|
+
* @throws If feature for cash drawers is not set in space_options
|
|
629
|
+
* @throws If same drawer id not found in current space data cash drawers.
|
|
630
|
+
* @returns Updated space cash drawer array
|
|
631
|
+
*/
|
|
632
|
+
private _toggleCashDrawer;
|
|
633
|
+
/**
|
|
634
|
+
* Checks if an open shift is found for a corresponding cash drawer id.
|
|
635
|
+
* @param id The cash drawer id
|
|
636
|
+
* @returns If open shift found for drawer.
|
|
637
|
+
*/
|
|
638
|
+
private _checkIfOpenShiftExistsForDrawer;
|
|
639
|
+
/**
|
|
640
|
+
* Fetch corresponding open shift for a given drawer ID.
|
|
641
|
+
* @param id Id for the cash drawer to search.
|
|
642
|
+
* @throws If feature for cash drawers is not set in space_options
|
|
643
|
+
* @throws If same drawer id not found in current space data cash drawers.
|
|
644
|
+
* @returns Found shift or undefined
|
|
645
|
+
*/
|
|
646
|
+
private _getOpenShiftForDrawer;
|
|
647
|
+
/**
|
|
648
|
+
* Fetch all cash drawer interaction history entries for specified options. All options are optionnal.
|
|
649
|
+
* @param options.drawerId Specific cash drawer Id
|
|
650
|
+
* @param options.shiftId Specific shift Id
|
|
651
|
+
* @param options.action Specific action type
|
|
652
|
+
* @param options.userEmail Specific user email that generated interaction
|
|
653
|
+
* @param options.dates Specific dates to filter results. If options.dates if provided, start date is obligatory, and end date optionnal.
|
|
654
|
+
* @throws If feature for cash drawers is not set in space_options
|
|
655
|
+
* @throws If same drawer id not found in current space data cash drawers.
|
|
656
|
+
* @returns Array of corresponding Interaction history entries, ordered by oldest to newest. If not date provided in options, returns max 100 entries. Else returns all found.
|
|
657
|
+
*/
|
|
658
|
+
private _getInteractionHistoryForDrawer;
|
|
600
659
|
attributes: {
|
|
601
660
|
get: (options?: IQueryOptions) => Promise<Attribute[]>;
|
|
602
661
|
add: (attribute: IAttribute) => Promise<void>;
|
|
@@ -1044,6 +1103,29 @@ export default class Space {
|
|
|
1044
1103
|
getActiveBySlug: (slug: MenuPositionEnum) => Promise<Menu | undefined>;
|
|
1045
1104
|
getAllActive: () => Promise<Menu[]>;
|
|
1046
1105
|
};
|
|
1106
|
+
cashDrawers: {
|
|
1107
|
+
create: (data: {
|
|
1108
|
+
nickname: string;
|
|
1109
|
+
drawerNumber?: number;
|
|
1110
|
+
}) => Promise<ICashDrawer[]>;
|
|
1111
|
+
edit: (id: string, data: {
|
|
1112
|
+
nickname: string;
|
|
1113
|
+
drawerNumber?: number;
|
|
1114
|
+
}) => Promise<ICashDrawer[]>;
|
|
1115
|
+
toggle: (id: string) => Promise<ICashDrawer[]>;
|
|
1116
|
+
hasOpenShift: (drawerId: string) => Promise<boolean>;
|
|
1117
|
+
getOpenShift: (drawerId: string) => Promise<CashDrawerShift | undefined>;
|
|
1118
|
+
getInteractionHistory: (options?: {
|
|
1119
|
+
drawerId?: string;
|
|
1120
|
+
shiftId?: string;
|
|
1121
|
+
action?: CashDrawerActionEnum;
|
|
1122
|
+
userEmail?: string;
|
|
1123
|
+
dates?: {
|
|
1124
|
+
start: Date;
|
|
1125
|
+
end?: Date;
|
|
1126
|
+
};
|
|
1127
|
+
}) => Promise<ICashDrawerInteraction[]>;
|
|
1128
|
+
};
|
|
1047
1129
|
/**
|
|
1048
1130
|
* Get all space properties
|
|
1049
1131
|
*/
|