feat(settlement): v4.0.6 酒厂 T+3 每 3 天出一期并与订单完全比对

含现场提货入账、零应付仍出账、核对补生成,以及线上历史账单修复 SQL。
This commit is contained in:
2026-08-31 17:27:38 +08:00
parent ac94f5f5de
commit f35e1a3ba5
15 changed files with 782 additions and 84 deletions
+59 -14
View File
@@ -1,14 +1,18 @@
import { describe, expect, it } from 'vitest';
import {
addShanghaiDays,
isWineryIssueDay,
listWineryIssueDays,
previousShanghaiMonth,
shanghaiLaggedIssueWindow,
shanghaiMonthLastInstant,
shanghaiMonthRange,
shanghaiPeriodYmds,
shanghaiT1DayWindow,
shanghaiWineryPeriodWindow,
shanghaiYmd,
startOfShanghaiDay,
wineryIssueDateFromCompletedAt,
} from './shanghai-date';
describe('shanghaiYmd / startOfShanghaiDay', () => {
@@ -46,7 +50,7 @@ describe('shanghaiT1DayWindow', () => {
});
describe('shanghaiLaggedIssueWindow', () => {
it('酒厂 T+3:出账日是今天,纳入 3 天前完成的订单', () => {
it('旧日滞后:出账日是今天,纳入 3 天前完成的订单', () => {
const { start, end, billDate } = shanghaiLaggedIssueWindow(
new Date('2026-08-31T00:00:00.000Z'),
3,
@@ -57,6 +61,55 @@ describe('shanghaiLaggedIssueWindow', () => {
});
});
describe('酒厂 T+3 每 3 天一期', () => {
const epoch = '2026-08-01';
const period = 3;
it('出账日:8/4、8/7、8/28;非 8/5、8/29', () => {
expect(isWineryIssueDay(new Date('2026-08-04T00:00:00+08:00'), period, epoch)).toBe(true);
expect(isWineryIssueDay(new Date('2026-08-07T00:00:00+08:00'), period, epoch)).toBe(true);
expect(isWineryIssueDay(new Date('2026-08-28T00:00:00+08:00'), period, epoch)).toBe(true);
expect(isWineryIssueDay(new Date('2026-08-01T00:00:00+08:00'), period, epoch)).toBe(false);
expect(isWineryIssueDay(new Date('2026-08-05T00:00:00+08:00'), period, epoch)).toBe(false);
expect(isWineryIssueDay(new Date('2026-08-29T00:00:00+08:00'), period, epoch)).toBe(false);
});
it('窗口:出账日 8/28 → 完成日 [8/25, 8/28)', () => {
const { start, end, billDate } = shanghaiWineryPeriodWindow(
new Date('2026-08-28T00:00:00+08:00'),
period,
);
expect(shanghaiYmd(billDate)).toBe('2026-08-28');
expect(shanghaiYmd(start)).toBe('2026-08-25');
expect(shanghaiYmd(end)).toBe('2026-08-28');
});
it('完成日归属出账日', () => {
expect(
shanghaiYmd(wineryIssueDateFromCompletedAt(new Date('2026-08-01T04:00:00.000Z'), period, epoch)),
).toBe('2026-08-04');
expect(
shanghaiYmd(wineryIssueDateFromCompletedAt(new Date('2026-08-03T04:00:00.000Z'), period, epoch)),
).toBe('2026-08-04');
expect(
shanghaiYmd(wineryIssueDateFromCompletedAt(new Date('2026-08-04T04:00:00.000Z'), period, epoch)),
).toBe('2026-08-07');
expect(
shanghaiYmd(wineryIssueDateFromCompletedAt(new Date('2026-08-27T04:00:00.000Z'), period, epoch)),
).toBe('2026-08-28');
});
it('listWineryIssueDays 只返回周期日', () => {
const days = listWineryIssueDays(
new Date('2026-08-01T00:00:00+08:00'),
new Date('2026-08-10T00:00:00+08:00'),
period,
epoch,
).map(shanghaiYmd);
expect(days).toEqual(['2026-08-04', '2026-08-07', '2026-08-10']);
});
});
describe('addShanghaiDays', () => {
it('跨月跨年按北京日历加减', () => {
expect(shanghaiYmd(addShanghaiDays(new Date('2026-08-31T16:00:00.000Z'), 1))).toBe(
@@ -78,23 +131,15 @@ describe('shanghaiMonthRange', () => {
it('UTC 月末 23:59:59 不会把账期止日滚成下月', () => {
const periodStart = new Date('2026-08-01T00:00:00.000Z');
expect(shanghaiPeriodYmds(periodStart)).toEqual({
periodStart: '2026-08-01',
periodEnd: '2026-08-31',
});
const ymds = shanghaiPeriodYmds(periodStart);
expect(ymds.periodStart).toBe('2026-08-01');
expect(ymds.periodEnd).toBe('2026-08-31');
});
});
describe('previousShanghaiMonth', () => {
it('北京 9 月 1 日 08:00UTC 9/1 00:00取 8 月', () => {
expect(previousShanghaiMonth(new Date('2026-09-01T00:00:00.000Z'))).toEqual({
year: 2026,
month: 8,
});
});
it('北京 9 月 1 日 00:30UTC 8/31 16:30)取 8 月,不因 UTC 仍是 8 月而错到 7 月', () => {
expect(previousShanghaiMonth(new Date('2026-08-31T16:30:00.000Z'))).toEqual({
it('北京 9 月 1 日取上月为 8 月', () => {
expect(previousShanghaiMonth(new Date('2026-08-31T16:00:00.000Z'))).toEqual({
year: 2026,
month: 8,
});