# `Sp_Bd_bi_Lostorder` (procedure)

> 丢单原因分析


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

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `tStartDate` | `datetime` |
| 2 | IN | `tEndDate` | `datetime` |
| 3 | IN | `sCustomerIdpro` | `varchar(100)` |
| 4 | IN | `sBrId` | `varchar(100)` |
| 5 | IN | `sSuId` | `varchar(100)` |
| 6 | OUT | `sCode` | `int` |
| 7 | OUT | `sReturn` | `varchar(5000)` |

## Body

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

## Narrative

**Business context:** 客户估价分析 → 报价&估计管理 → 销售管理 — dashboard chart procedure that classifies a customer's quotations into "lost-by-status" buckets versus "已成交订单" (closed-deal orders) for a given date window. Header: 丢单原因分析.

**What it does:** Reads `viw_quoquotation` for one `sCustomerId=sCustomerIdpro` inside `[tStartDate,tEndDate]`, splits rows into two groups: rows whose `sId` does NOT appear as `viw_salsalesorder.sSrcId` (lost — grouped by `sType` lost-reason; empty `sType` rewritten to `Fun_Sis_GetConstNew('','sOrderNotCustomer','',...)` = 未走客户确认流程直接下单), and rows that DO appear (won — labelled `Fun_Sis_GetConstNew('','sCompleteOrder','',...)`). Aggregates `dProductMoney` per bucket into temp `Tmp_bi_Lostorder(sName,sValue)`, then emits a single `{"data":[{"x":...,"y":...}...], "hasLegend":true, "subTitle":"<sTotalAmount>", ...}` JSON string into `sReturn` for the dashboard widget.

**Invocation:** Embedded in `gdsconfigformmaster` form `16758336770001677223131387683300` (客户估价分析) under module `101251240115015967857770020` (报价&估计管理 → 销售管理). No Java caller or other procedure references this name.
