CoolCMS API

StockDocumentFormTrait

Stock document form per type (`add?type=1..4`, edit of a draft).

Saves a draft (status 0) as an object graph (owned movements collection); the Api StockDocumentManager::beforeSave enforces DRAFT and allows editing only a draft. IMPORTANT: stock effects never go through save, only through the service action post(); otherwise the posting rules (stock checks, batch pairing) would be bypassed. The "save and post" button saves the draft and calls post() through the bridge.

Lines use a server Multiplier (not a client multiplier) because every line carries its own instance of the stock item Picker (StockItemLinePickerTrait; an issue also has a batch picker). Signs: receipt +q, issue -q, transfer -q (post() regenerates +q for the target); post() applies abs() to an issue and rejects a positive transfer line. The warehouse is stored on the movement too (association); post() reuses the existing draft line and does not overwrite warehouse_id on it.

Table of Contents

Methods

createComponentEditForm()  : Form
addDocumentHeaderFields()  : void
addDocumentLinesMultiplier()  : void
Limit taken from the raw HTTP data (`onAnchor`), with `$maxCopies` as a second defense.
addWarehouseSelect()  : SelectBox
buildMovements()  : ArrayCollection<int, StockMovement>
cmpZero()  : int
currencyOptions()  : array<int, NotTranslate>
Currency codes are ready data, not a key, hence `NotTranslate`.
currencyRef()  : Currency|null
currentUserId()  : int|null
dateOrNull()  : DateTime|null
`<input type=date>`: strict parser (see `StrictDateInput`), not `new DateTime()`.
documentRows()  : array<int, array<string, mixed>|ArrayHash<string|int, mixed>>
persistDraft()  : StockDocument|null
Builds and saves the draft; returns the saved entity (with id) or null (flash on error).
processSaveAndPostDocument()  : bool
Saves the draft and posts it; redirects on success (also when only posting failed: the draft is saved).
saveDocumentForm()  : bool
setDocumentFormDefaults()  : void
signedQuantity()  : string
Draft sign by type: receipt +q, issue/transfer -q.
stockItemRef()  : StockItem
stockItemSnapshots()  : array<int, array{0: string, 1: string}>
supplierRef()  : Supplier|null
warehouseName()  : string
Warehouse name in the current language, falling back to the first non-empty translation.
warehouseRef()  : Warehouse|null

Methods

addDocumentLinesMultiplier()

Limit taken from the raw HTTP data (`onAnchor`), with `$maxCopies` as a second defense.

private addDocumentLinesMultiplier(Form $form) : void
Parameters
$form : Form

addWarehouseSelect()

private addWarehouseSelect(Form $form, string $name, string $labelKey) : SelectBox
Parameters
$form : Form
$name : string
$labelKey : string
Return values
SelectBox

buildMovements()

private buildMovements(ArrayHash<string|int, mixed> $values, StockDocument $document, int|null $warehouseId, string|null &$error) : ArrayCollection<int, StockMovement>
Parameters
$values : ArrayHash<string|int, mixed>
$document : StockDocument
$warehouseId : int|null
$error : string|null
Return values
ArrayCollection<int, StockMovement>

currencyOptions()

Currency codes are ready data, not a key, hence `NotTranslate`.

private currencyOptions() : array<int, NotTranslate>
Return values
array<int, NotTranslate>

dateOrNull()

`<input type=date>`: strict parser (see `StrictDateInput`), not `new DateTime()`.

private dateOrNull(mixed $value) : DateTime|null
Parameters
$value : mixed
Return values
DateTime|null

documentRows()

private documentRows(mixed $rows) : array<int, array<string, mixed>|ArrayHash<string|int, mixed>>
Parameters
$rows : mixed
Return values
array<int, array<string, mixed>|ArrayHash<string|int, mixed>>

persistDraft()

Builds and saves the draft; returns the saved entity (with id) or null (flash on error).

private persistDraft(ArrayHash<string|int, mixed> $values) : StockDocument|null
Parameters
$values : ArrayHash<string|int, mixed>
Return values
StockDocument|null

processSaveAndPostDocument()

Saves the draft and posts it; redirects on success (also when only posting failed: the draft is saved).

private processSaveAndPostDocument(ArrayHash<string|int, mixed> $values) : bool

Returns false only when the draft was not saved (flash shown).

Parameters
$values : ArrayHash<string|int, mixed>
Return values
bool

saveDocumentForm()

private saveDocumentForm(ArrayHash<string|int, mixed> $values) : bool
Parameters
$values : ArrayHash<string|int, mixed>
Return values
bool

signedQuantity()

Draft sign by type: receipt +q, issue/transfer -q.

private signedQuantity(string $quantity) : string
Parameters
$quantity : string
Return values
string

stockItemSnapshots()

private stockItemSnapshots(array<int, int> $ids) : array<int, array{0: string, 1: string}>
Parameters
$ids : array<int, int>
Return values
array<int, array{0: string, 1: string}> —

id => [code, name]

warehouseName()

Warehouse name in the current language, falling back to the first non-empty translation.

private warehouseName(Warehouse $warehouse) : string

Iterates the typed getTranslations() (Collection<WarehouseText>); shared with the stocktake screen.

Parameters
$warehouse : Warehouse
Return values
string
On this page

Search results