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