add: get History Deposit
This commit is contained in:
		| @@ -48,7 +48,7 @@ export class TransactionController { | ||||
|     @Request() req, | ||||
|   ) { | ||||
|     return { | ||||
|       data: await this.transactionService.addPartnerSaldo( | ||||
|       data: await this.transactionService.addSupplierSaldo( | ||||
|         addSaldoSupplier, | ||||
|         req.user, | ||||
|       ), | ||||
| @@ -88,7 +88,7 @@ export class TransactionController { | ||||
|   } | ||||
|  | ||||
|   @Get('history') | ||||
|   async findByCategories( | ||||
|   async getHistoryTransactionUser( | ||||
|     @Query('page') page: number, | ||||
|     @Query('pageSize') pageSize: number, | ||||
|     @Request() req, | ||||
| @@ -106,6 +106,27 @@ export class TransactionController { | ||||
|     }; | ||||
|   } | ||||
|  | ||||
|   @Get('history-deposit') | ||||
|   async getHistoryDepositUser( | ||||
|     @Query('page') page: number, | ||||
|     @Query('pageSize') pageSize: number, | ||||
|     @Query('user-destination') userDestination: string, | ||||
|     @Request() req, | ||||
|   ) { | ||||
|     const data = await this.transactionService.topUpHistoryByUser( | ||||
|       page, | ||||
|       req.user.userId, | ||||
|       userDestination, | ||||
|       pageSize, | ||||
|     ); | ||||
|  | ||||
|     return { | ||||
|       ...data, | ||||
|       statusCode: HttpStatus.OK, | ||||
|       message: 'success', | ||||
|     }; | ||||
|   } | ||||
|  | ||||
|   @Get('deposit-return') | ||||
|   async findDepositReturn( | ||||
|     @Query('page') page: number, | ||||
|   | ||||
| @@ -10,7 +10,12 @@ import { CoaService } from './coa.service'; | ||||
| import * as uuid from 'uuid'; | ||||
| import { uniq } from 'lodash'; | ||||
| import { Decimal } from 'decimal.js'; | ||||
| import { balanceType, coaType, statusTransaction, typeTransaction } from '../helper/enum-list'; | ||||
| import { | ||||
|   balanceType, | ||||
|   coaType, | ||||
|   statusTransaction, | ||||
|   typeTransaction, | ||||
| } from '../helper/enum-list'; | ||||
| import { ProductService } from '../product/product.service'; | ||||
| import { CreateJournalDto } from './dto/create-journal.dto'; | ||||
| import { UsersService } from 'src/users/users.service'; | ||||
| @@ -44,7 +49,7 @@ export class TransactionService { | ||||
|     private connection: Connection, | ||||
|   ) {} | ||||
|  | ||||
|   async addPartnerSaldo(addSaldoSupplier: AddSaldoSupplier, currentUser: any) { | ||||
|   async addSupplierSaldo(addSaldoSupplier: AddSaldoSupplier, currentUser: any) { | ||||
|     const supplier = await this.supplierService.findByCode( | ||||
|       addSaldoSupplier.supplier, | ||||
|     ); | ||||
| @@ -137,6 +142,7 @@ export class TransactionService { | ||||
|       const coaBudget = await this.coaService.findByName( | ||||
|         `${coaType[coaType.BUDGET]}-${supplier.code}`, | ||||
|       ); | ||||
|  | ||||
|       if (coaBudget.amount < distributeTransactionDto.amount) { | ||||
|         throw new HttpException( | ||||
|           { | ||||
| @@ -146,6 +152,7 @@ export class TransactionService { | ||||
|           HttpStatus.INTERNAL_SERVER_ERROR, | ||||
|         ); | ||||
|       } | ||||
|  | ||||
|       const coaContraBudget = await this.coaService.findByName( | ||||
|         `${coaType[coaType.CONTRA_BUDGET]}-${supplier.code}`, | ||||
|       ); | ||||
| @@ -318,8 +325,12 @@ export class TransactionService { | ||||
|         userData, | ||||
|       ); | ||||
|       profit = supervisorData | ||||
|         .map((item) => item.credit) | ||||
|         .reduce((prev, curr) => prev + curr, 0); | ||||
|         .map((item) => { | ||||
|           return item.credit; | ||||
|         }) | ||||
|         .reduce((prev, curr) => { | ||||
|           return prev + curr; | ||||
|         }, 0); | ||||
|     } | ||||
|  | ||||
|     //GET COA | ||||
| @@ -585,6 +596,36 @@ export class TransactionService { | ||||
|     }; | ||||
|   } | ||||
|  | ||||
|   async topUpHistoryByUser( | ||||
|     page: number, | ||||
|     user: string, | ||||
|     destinationUser: string, | ||||
|     pageSize?: number, | ||||
|   ) { | ||||
|     const baseQuery = this.transactionRepository | ||||
|       .createQueryBuilder('transaction') | ||||
|       .where( | ||||
|         'transaction.user = :id and transaction.type = 0 and transaction.user_destination = :destinationId', | ||||
|         { | ||||
|           id: user, | ||||
|           destinationId: destinationUser, | ||||
|         }, | ||||
|       ) | ||||
|       .select(['id', 'created_at as transaction_date', 'amount']); | ||||
|  | ||||
|     const data = await baseQuery | ||||
|       .offset(page * (pageSize || 10)) | ||||
|       .limit(pageSize || 10) | ||||
|       .getRawMany(); | ||||
|  | ||||
|     const totalData = await baseQuery.getCount(); | ||||
|  | ||||
|     return { | ||||
|       data, | ||||
|       count: totalData, | ||||
|     }; | ||||
|   } | ||||
|  | ||||
|   async findApprovalDepositReturn(id: string) { | ||||
|     try { | ||||
|       return await this.transactionRepository.findOneOrFail({ | ||||
| @@ -668,6 +709,7 @@ export class TransactionService { | ||||
|         const commissionValue = await this.commissionService.findOne( | ||||
|           it.roles.id, | ||||
|         ); | ||||
|  | ||||
|         return { | ||||
|           coa_id: coaAccount.id, | ||||
|           credit: (totalPrice * commissionValue.commission) / 100, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user