- added supplier name for role admin
This commit is contained in:
parent
05690dcf5a
commit
04d2ed62ec
|
@ -5,7 +5,9 @@ import {
|
|||
Header,
|
||||
Post,
|
||||
Body,
|
||||
Request, Param, ParseUUIDPipe,
|
||||
Request,
|
||||
Param,
|
||||
ParseUUIDPipe,
|
||||
} from '@nestjs/common';
|
||||
import { Response } from 'express';
|
||||
import { TransactionService } from './transaction.service';
|
||||
|
@ -29,6 +31,7 @@ export class ExcelController {
|
|||
const result = await this.transactionService.exportDataExcel(
|
||||
exportTransactionDto.dateStart,
|
||||
id,
|
||||
req.user,
|
||||
);
|
||||
|
||||
res.download(`${result}`);
|
||||
|
|
|
@ -46,6 +46,7 @@ import { CallbackPartner } from './entities/callback-partner.entity';
|
|||
import { doAuthorizeHemat } from '../helper/sihemat-authorization';
|
||||
import { ProductHistoryStatusService } from '../product/history-status/history-status.service';
|
||||
import { Workbook } from 'exceljs';
|
||||
import moment from "moment";
|
||||
|
||||
@Injectable()
|
||||
export class TransactionService {
|
||||
|
@ -1878,7 +1879,6 @@ export class TransactionService {
|
|||
.addSelect('product.name', 'name')
|
||||
.addSelect('product_price.price', 'product_price')
|
||||
.addSelect('product_price.mark_up_price', 'mark_up_price')
|
||||
.addSelect('product.name', 'supplier_name')
|
||||
.addSelect('supplier.name', 'supplier_name')
|
||||
.orderBy('transaction.created_at', 'DESC');
|
||||
|
||||
|
@ -2140,7 +2140,7 @@ export class TransactionService {
|
|||
});
|
||||
}
|
||||
|
||||
async exportDataExcel(startDate, user: any) {
|
||||
async exportDataExcel(startDate, user: any, currentUser: any) {
|
||||
const userData = await this.userService.findExist(user);
|
||||
|
||||
let userBySupperior = [];
|
||||
|
@ -2194,6 +2194,7 @@ export class TransactionService {
|
|||
|
||||
.addSelect('product.name', 'product_name')
|
||||
.addSelect('product.code', 'product_code')
|
||||
.addSelect('supplier.name', 'supplier_name')
|
||||
.addSelect('transaction.amount', 'price')
|
||||
.addSelect('transaction.balance_remaining', 'balance_remaining')
|
||||
.addSelect('userData.name', 'buyer')
|
||||
|
@ -2251,7 +2252,23 @@ export class TransactionService {
|
|||
|
||||
// now do stuff with each item
|
||||
const moment = require("moment");
|
||||
|
||||
if (currentUser.username == 'admin') {
|
||||
dataSorted.push({
|
||||
product_name: item.product_name,
|
||||
product_code: item.product_code,
|
||||
supplier_name: item.supplier_name,
|
||||
price: item.price,
|
||||
balance_remaining: item.balance_remaining,
|
||||
buyer: item.buyer,
|
||||
destination: item.destination,
|
||||
transaction_code: item.transaction_code,
|
||||
status: item.status,
|
||||
serial_number: item.serial_number,
|
||||
partner_trx_id: item.partner_trx_id,
|
||||
transaction_date: moment(new Date (item.transaction_date).toISOString().replace('Z', ' ').replace('T', ' ')).format("MM-DD-YYYY HH:mm:ss"),
|
||||
failed_reason: item.failed_reason,
|
||||
});
|
||||
} else {
|
||||
dataSorted.push({
|
||||
product_name: item.product_name,
|
||||
product_code: item.product_code,
|
||||
|
@ -2267,6 +2284,7 @@ export class TransactionService {
|
|||
failed_reason: item.failed_reason,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
dataSorted.forEach((doc) => {
|
||||
rows.push(Object.values(doc));
|
||||
|
@ -2286,6 +2304,23 @@ export class TransactionService {
|
|||
sheet.addRows(rows);
|
||||
|
||||
//customize column
|
||||
if (currentUser.username == 'admin') {
|
||||
sheet.columns = [
|
||||
{header: 'Nama Produk', key: 'product_name'},
|
||||
{header: 'Kode Produk', key: 'product_code'},
|
||||
{header: 'Supplier', key: 'supplier_name'},
|
||||
{header: 'Harga', key: 'price'},
|
||||
{header: 'Sisa Saldo', key: 'balance_remaining'},
|
||||
{header: 'Pembeli', key: 'buyer'},
|
||||
{header: 'Tujuan', key: 'destination'},
|
||||
{header: 'Kode Transaksi', key: 'transaction_code'},
|
||||
{header: 'Status', key: 'status'},
|
||||
{header: 'No Seri', key: 'serial_number'},
|
||||
{header: 'IDTrx Mitra', key: 'partner_trx_id'},
|
||||
{header: 'Tanggal Transaksi', key: 'transaction_date'},
|
||||
{header: 'Alasan Gagal', key: 'failed_reason'},
|
||||
];
|
||||
} else {
|
||||
sheet.columns = [
|
||||
{header: 'Nama Produk', key: 'product_name'},
|
||||
{header: 'Kode Produk', key: 'product_code'},
|
||||
|
@ -2300,6 +2335,7 @@ export class TransactionService {
|
|||
{header: 'Tanggal Transaksi', key: 'transaction_date'},
|
||||
{header: 'Alasan Gagal', key: 'failed_reason'},
|
||||
];
|
||||
}
|
||||
|
||||
this.styleSheet(sheet)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user