@connect-plus-online/ogabai-integrations 0.0.87 → 0.0.92

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/index.cjs.js CHANGED
@@ -3718,9 +3718,112 @@ var createExpenseService = (client) => ({
3718
3718
  defaultRootFields: [...expenseListIntegration.responseFields],
3719
3719
  defaultNestedFields: expenseListIntegration.nestedFields
3720
3720
  }
3721
- )
3721
+ ),
3722
+ getExpensesByStaffId(req) {
3723
+ return this.getExpenses({
3724
+ expense: {
3725
+ ...req.filter,
3726
+ dispenseStaffIds: [req.staffId]
3727
+ },
3728
+ limit: req.limit,
3729
+ skip: req.limit
3730
+ });
3731
+ },
3732
+ requestExpenseDispense(req) {
3733
+ return this.createExpense({
3734
+ expense: {
3735
+ ...req.expense,
3736
+ expenseType: "staffRequest"
3737
+ }
3738
+ });
3739
+ }
3722
3740
  });
3723
3741
 
3742
+ // src/services/sales/expense-dispense.service.ts
3743
+ var createExpenseDispenseService = (client) => {
3744
+ const expenseService = createExpenseService(client);
3745
+ const transactionService = createTransactionService(client);
3746
+ return {
3747
+ getExpensesDispensedByStore: async (req) => {
3748
+ return await transactionService.getTransactions({
3749
+ transaction: {
3750
+ ...req.filter,
3751
+ storeId: req.storeId,
3752
+ transactionType: "expense"
3753
+ },
3754
+ limit: req.limit,
3755
+ skip: req.skip || 0
3756
+ });
3757
+ },
3758
+ getExpensesDispensedByStaff: async (req) => {
3759
+ return await transactionService.getTransactions({
3760
+ transaction: {
3761
+ ...req.filter,
3762
+ createdById: req.staffId,
3763
+ transactionType: "expense"
3764
+ },
3765
+ limit: req.limit,
3766
+ skip: req.skip || 0
3767
+ });
3768
+ },
3769
+ dispenseExpense: async (req) => {
3770
+ const { amountPaid, narration, createdById, expenseId } = req.expenseDispense;
3771
+ const expenseRes = await expenseService.getExpense({
3772
+ expense: {
3773
+ id: expenseId
3774
+ }
3775
+ });
3776
+ if (!expenseRes || !expenseRes.expense) {
3777
+ throw new Error("Expense not found");
3778
+ }
3779
+ const expense = expenseRes.expense;
3780
+ if (expense && !expense.dispenseStaffIds.includes(createdById)) {
3781
+ throw new Error("Staff not authorized to dispense this expense");
3782
+ }
3783
+ const transaction = await transactionService.addTransaction({
3784
+ transaction: {
3785
+ transactionType: "expense",
3786
+ amountPaid,
3787
+ narration,
3788
+ createdById,
3789
+ expenseId
3790
+ }
3791
+ });
3792
+ return transaction || void 0;
3793
+ },
3794
+ async approveExpenseDispense(req) {
3795
+ const { expenseId, addToExpenseList = false } = req;
3796
+ const expenseRes = await expenseService.getExpense({
3797
+ expense: {
3798
+ id: expenseId
3799
+ }
3800
+ });
3801
+ if (!expenseRes || !expenseRes.expense) {
3802
+ throw new Error("Expense not found");
3803
+ }
3804
+ const expense = expenseRes.expense;
3805
+ if (expense.expenseType !== "staffRequest") {
3806
+ throw new Error("Only staff requested expenses can be approved for dispense");
3807
+ }
3808
+ const transaction = await this.dispenseExpense({
3809
+ expenseDispense: {
3810
+ expenseId,
3811
+ amountPaid: expense.amount,
3812
+ narration: expense.narration || "Approved expense dispense",
3813
+ createdById: expense.createdById
3814
+ }
3815
+ });
3816
+ await expenseService.updateExpense({
3817
+ expenseId,
3818
+ expense: {
3819
+ expenseType: addToExpenseList ? "operation" : "staffRequestFulfilled"
3820
+ }
3821
+ });
3822
+ return transaction || null;
3823
+ }
3824
+ };
3825
+ };
3826
+
3724
3827
  exports.APPLICATION_FEATURES = APPLICATION_FEATURES;
3725
3828
  exports.AuthenticationError = AuthenticationError;
3726
3829
  exports.GraphQLClient = GraphQLClient;
@@ -3757,6 +3860,7 @@ exports.compose = compose;
3757
3860
  exports.createAuthService = createAuthService;
3758
3861
  exports.createCustomerService = createCustomerService;
3759
3862
  exports.createExpenseCategoryService = createExpenseCategoryService;
3863
+ exports.createExpenseDispenseService = createExpenseDispenseService;
3760
3864
  exports.createExpenseService = createExpenseService;
3761
3865
  exports.createOrderService = createOrderService;
3762
3866
  exports.createPackageService = createPackageService;