# `FUN_MATERIALS_SMAIL` (function)

> 两变都小于305的材料（单位CM）


- **Type:** FUNCTION
- **Returns:** `decimal(18,6)`
- **Deterministic:** NO
- **SQL data access:** CONTAINS SQL

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `dQty` | `decimal(18,6)` |
| 2 | IN | `dWidth` | `decimal(18,6)` |
| 3 | IN | `dLength` | `decimal(18,6)` |

## Body

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

## Narrative

**Business context:** Material-cutting estimator for the printing/box-making workshop — computes how many full sheets ("整根") are needed to fulfill `dQty` pieces at `dLength × dWidth` (cm), assuming a 305 cm stock sheet and reusing offcuts. Header gloss: "两变都小于305的材料（单位CM）" (both dimensions under 305 cm).

**What it does:** Swaps so length ≥ width, peels off whole stock-sheet multiples for any dimension > 305, then runs a greedy bin-packing loop tracking the running offcut (`clys`) and a JSON queue of reusable scraps (`jsonlist`) — each piece consumes length then width, replenishing `clys = 305 - dLength` when exhausted. Returns full-sheet count + scrap-sheet count.

**Invocation:** Status: appears orphaned. No form-master, module-hook, other-routine, or xly-src caller. Candidate for maintainer audit.
