# `Sp_viw_accordercostanalysis` (procedure)


- **Type:** PROCEDURE
- **Deterministic:** NO
- **SQL data access:** CONTAINS SQL

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `tStartDate` | `datetime` |
| 2 | IN | `tEndDate` | `datetime` |
| 3 | IN | `sWorkOrderNo` | `varchar(100)` |
| 4 | IN | `sOrderNo` | `varchar(100)` |
| 5 | IN | `sProductNo` | `varchar(100)` |
| 6 | IN | `sProductName` | `varchar(100)` |
| 7 | IN | `sLoginId` | `varchar(100)` |
| 8 | IN | `sBrId` | `varchar(100)` |
| 9 | IN | `sSuId` | `varchar(100)` |
| 10 | IN | `bFilter` | `longtext` |
| 11 | IN | `pageNum` | `int` |
| 12 | IN | `pageSize` | `int` |
| 13 | OUT | `totalCount` | `int` |
| 14 | IN | `countCloumn` | `longtext` |
| 15 | OUT | `countMapJson` | `longtext` |
| 16 | IN | `sFilterOrderBy` | `longtext` |
| 17 | IN | `sGroupby_select_sql` | `longtext` |
| 18 | IN | `sGroupby_group_sql` | `longtext` |

## Body

_Body is not pre-cached. To inspect: `mysql --defaults-file=~/.my.cnf -e 'SHOW CREATE PROCEDURE `Sp_viw_accordercostanalysis`'`._

## Narrative

**Business context:** 财务/成本管理 → 成本分析 — paged data-source proc for the 订单成本分析 report (`accordercostanalysis`). Aggregates per-product cost/expense totals over a date range so finance can see materials, labour, and up to 22 user-defined `dInitExpense{N}Money` expense buckets aligned with the sales-order foreign-money totals.

**What it does:** Defaults `tStartDate=NOW()-1 MONTH`, `tEndDate=NOW()`. Looks up the current `sysaccountperiod` for the dates, then accumulates per-product quantities/money (`dProductQty`, `dNoCheckingQty`, `dProductForeignMoney`, `dProductTaxMoney`, `dInitFatherMoney`, `dInitExpense1Money` … `dInitExpense22Money`) into temp `accordercostanalysis` rows. Hands the final SQL to `sp_groupby` (the standard paging/grouping helper) so `pageNum`/`pageSize`/`bFilter`/`countCloumn` work as in any report proc.

**Invocation:** Status: appears orphaned in the live DB. The paged-report signature matches the form-data-source pattern, but no `gdsconfigformmaster` references it, no gdsmodule hook, no other proc, and the only xly-src hit is its own install script `script/标版/30100101/Sp_viw_accordercostanalysis.sql`. Likely retired or waiting on a form `sSqlStr` registration. Candidate for maintainer audit.
