@connect-plus-online/ogabai-integrations 0.0.86 → 0.0.88

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
@@ -3225,6 +3225,7 @@ var transactionQuery = [
3225
3225
  "amountPaid",
3226
3226
  "amountTotal",
3227
3227
  "createdAt",
3228
+ "createdById",
3228
3229
  "from",
3229
3230
  "fromWallet",
3230
3231
  "isCredit",
@@ -3717,9 +3718,114 @@ var createExpenseService = (client) => ({
3717
3718
  defaultRootFields: [...expenseListIntegration.responseFields],
3718
3719
  defaultNestedFields: expenseListIntegration.nestedFields
3719
3720
  }
3720
- )
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
+ }
3721
3740
  });
3722
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
+ if (addToExpenseList) {
3817
+ await expenseService.updateExpense({
3818
+ expenseId,
3819
+ expense: {
3820
+ expenseType: "operation"
3821
+ }
3822
+ });
3823
+ }
3824
+ return transaction || null;
3825
+ }
3826
+ };
3827
+ };
3828
+
3723
3829
  exports.APPLICATION_FEATURES = APPLICATION_FEATURES;
3724
3830
  exports.AuthenticationError = AuthenticationError;
3725
3831
  exports.GraphQLClient = GraphQLClient;
@@ -3756,6 +3862,7 @@ exports.compose = compose;
3756
3862
  exports.createAuthService = createAuthService;
3757
3863
  exports.createCustomerService = createCustomerService;
3758
3864
  exports.createExpenseCategoryService = createExpenseCategoryService;
3865
+ exports.createExpenseDispenseService = createExpenseDispenseService;
3759
3866
  exports.createExpenseService = createExpenseService;
3760
3867
  exports.createOrderService = createOrderService;
3761
3868
  exports.createPackageService = createPackageService;