This commit is contained in:
parent
a03c3ab6e8
commit
0e416be400
|
@ -33,14 +33,14 @@ const dashboardTrendController = [
|
|||
|
||||
const sales = await (
|
||||
period_type === 'weekly' ?
|
||||
selectThisYearSalesTrendWeekly() :
|
||||
selectThisYearSalesTrendMonthly()
|
||||
selectThisYearSalesTrendWeekly(req.user!.id) :
|
||||
selectThisYearSalesTrendMonthly(req.user!.id)
|
||||
)
|
||||
|
||||
const purchase = await (
|
||||
period_type === 'weekly' ?
|
||||
selectThisYearRestockTrendWeekly() :
|
||||
selectThisYearRestockTrendMonthly()
|
||||
selectThisYearRestockTrendWeekly(req.user!.id) :
|
||||
selectThisYearRestockTrendMonthly(req.user!.id)
|
||||
)
|
||||
|
||||
const result: TAPIResponse = {
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
import { db } from "../../database/MySQL";
|
||||
import { IPurchaseTable } from "../../types/db-model";
|
||||
|
||||
export function selectThisYearRestockTrendMonthly() {
|
||||
export function selectThisYearRestockTrendMonthly(
|
||||
user_id: IPurchaseTable['user_id']
|
||||
) {
|
||||
return db('restocks')
|
||||
.select(
|
||||
db.raw('YEAR(buying_date) AS year'),
|
||||
|
@ -8,11 +11,14 @@ export function selectThisYearRestockTrendMonthly() {
|
|||
db.raw('SUM(amount) AS amount')
|
||||
)
|
||||
.whereRaw('YEAR(buying_date) = YEAR(CURDATE())')
|
||||
.andWhere({ user_id })
|
||||
.groupByRaw('YEAR(buying_date), MONTH(buying_date)')
|
||||
.orderByRaw('YEAR(buying_date), MONTH(buying_date)')
|
||||
}
|
||||
|
||||
export function selectThisYearRestockTrendWeekly() {
|
||||
export function selectThisYearRestockTrendWeekly(
|
||||
user_id: IPurchaseTable['user_id']
|
||||
) {
|
||||
return db('restocks')
|
||||
.select(
|
||||
db.raw('YEAR(buying_date) AS year'),
|
||||
|
@ -20,6 +26,7 @@ export function selectThisYearRestockTrendWeekly() {
|
|||
db.raw('SUM(amount) AS amount')
|
||||
)
|
||||
.whereRaw('YEAR(buying_date) = YEAR(CURDATE())')
|
||||
.andWhere({ user_id })
|
||||
.groupByRaw('YEAR(buying_date), WEEK(buying_date, 1)')
|
||||
.orderByRaw('YEAR(buying_date), WEEK(buying_date, 1)')
|
||||
}
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
import { db } from "../../database/MySQL";
|
||||
import { ITransactionTable } from "../../types/db-model";
|
||||
|
||||
export function selectThisYearSalesTrendMonthly() {
|
||||
export function selectThisYearSalesTrendMonthly(
|
||||
user_id: ITransactionTable['user_id']
|
||||
|
||||
) {
|
||||
return db('transactions')
|
||||
.select(
|
||||
db.raw("YEAR(transaction_date) AS year"),
|
||||
|
@ -8,11 +12,14 @@ export function selectThisYearSalesTrendMonthly() {
|
|||
db.raw("SUM(amount) AS amount")
|
||||
)
|
||||
.whereRaw("YEAR(transaction_date) = YEAR(CURDATE())") // filter tahun ini
|
||||
.andWhere({ user_id })
|
||||
.groupByRaw("YEAR(transaction_date), MONTH(transaction_date)")
|
||||
.orderByRaw("YEAR(transaction_date), MONTH(transaction_date)")
|
||||
}
|
||||
|
||||
export function selectThisYearSalesTrendWeekly() {
|
||||
export function selectThisYearSalesTrendWeekly(
|
||||
user_id: ITransactionTable['user_id']
|
||||
) {
|
||||
return db('transactions')
|
||||
.select(
|
||||
db.raw("YEAR(transaction_date) AS year"),
|
||||
|
@ -20,6 +27,7 @@ export function selectThisYearSalesTrendWeekly() {
|
|||
db.raw("SUM(amount) AS amount")
|
||||
)
|
||||
.whereRaw("YEAR(transaction_date) = YEAR(CURDATE())")
|
||||
.andWhere({ user_id })
|
||||
.groupByRaw("YEAR(transaction_date), WEEK(transaction_date, 1)")
|
||||
.orderByRaw("YEAR(transaction_date), WEEK(transaction_date, 1)")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue