FactUploader
in package
Class responsible for uploading and managing fact data, including validation, database interaction, and parsing from external sources like Excel files.
Table of Contents
Constants
- FACT_VALIDATION_RULES = ['module_code' => 'string|default:MOD-000001', 'company_plant_code' => 'string|required|min_length:10|max_length:128', 'company_plant_id' => 'int|required', 'location_code' => 'string|required|min_length:2|max_length:128', 'location_id' => 'int|required', 'datapoint_id' => 'int|required', 'datapoint_code' => 'string|required|min_length:3|max_length:128', 'kpi_code' => 'string|required|min_length:10|max_length:128', 'kpi_id' => 'int|required', 'currency_code' => 'string|required|min_length:3|max_length:128', 'currency_id' => 'int|required', 'unit_code' => 'string|required|min_length:3|max_length:128', 'unit_id' => 'int|required', 'date' => 'string|required|date:Y-m-d', 'date_id' => 'string|required', 'date_dateid' => 'int|required', 'qty' => 'float|required', 'amount_currency' => 'float|nullable', 'amount_percent' => 'float|nullable', 'amount_text' => 'string', 'notes' => 'string']
Properties
- $companyPlant : CompanyPlant
- $currencyMap : array<string|int, mixed>
- $datapointMap : array<string|int, mixed>
- $dataValidator : DataValidator
- $db : MySql
- $kpiMap : array<string|int, mixed>
- $locationMap : array<string|int, mixed>
- $timeMap : array<string|int, mixed>
- $unitMap : array<string|int, mixed>
Methods
- __construct() : mixed
- parseExcelFile() : array<string|int, mixed>
- Parse the data in an excel file into array
- save() : bool
- Save the facts
- validateFacts() : array<string|int, mixed>
- Validate facts data
- getCurrencyMap() : array<string, int>
- Retrun an array mapping currency codes to their ID
- getDatapointsMap() : array<string, int>
- Retrun an array mapping datapoint codes to their ID
- getKpiMap() : array<string, int>
- Retrun an array mapping KPI codes to their ID
- getLocationMap() : array<string, int>
- Retrun an array mapping Location codes to their ID
- getTimeMap() : array<string, int>
- Retrun an array mapping date_id codes to their date_dataid
- getUnitsMap() : array<string, int>
- Retrun an array mapping units codes to their ID
Constants
FACT_VALIDATION_RULES
private
mixed
FACT_VALIDATION_RULES
= ['module_code' => 'string|default:MOD-000001', 'company_plant_code' => 'string|required|min_length:10|max_length:128', 'company_plant_id' => 'int|required', 'location_code' => 'string|required|min_length:2|max_length:128', 'location_id' => 'int|required', 'datapoint_id' => 'int|required', 'datapoint_code' => 'string|required|min_length:3|max_length:128', 'kpi_code' => 'string|required|min_length:10|max_length:128', 'kpi_id' => 'int|required', 'currency_code' => 'string|required|min_length:3|max_length:128', 'currency_id' => 'int|required', 'unit_code' => 'string|required|min_length:3|max_length:128', 'unit_id' => 'int|required', 'date' => 'string|required|date:Y-m-d', 'date_id' => 'string|required', 'date_dateid' => 'int|required', 'qty' => 'float|required', 'amount_currency' => 'float|nullable', 'amount_percent' => 'float|nullable', 'amount_text' => 'string', 'notes' => 'string']
Properties
$companyPlant
private
CompanyPlant
$companyPlant
$currencyMap
private
array<string|int, mixed>
$currencyMap
= []
$datapointMap
private
array<string|int, mixed>
$datapointMap
= []
$dataValidator
private
DataValidator
$dataValidator
$db
private
MySql
$db
$kpiMap
private
array<string|int, mixed>
$kpiMap
= []
$locationMap
private
array<string|int, mixed>
$locationMap
= []
$timeMap
private
array<string|int, mixed>
$timeMap
= []
$unitMap
private
array<string|int, mixed>
$unitMap
= []
Methods
__construct()
public
__construct(MySql $db, DataValidator $dataValidator, CompanyPlant $companyPlant) : mixed
Parameters
- $db : MySql
- $dataValidator : DataValidator
- $companyPlant : CompanyPlant
parseExcelFile()
Parse the data in an excel file into array
public
parseExcelFile(string $file) : array<string|int, mixed>
Parameters
- $file : string
Tags
Return values
array<string|int, mixed>save()
Save the facts
public
save(array<string|int, mixed> $facts, array<string|int, mixed> $user) : bool
Parameters
- $facts : array<string|int, mixed>
- $user : array<string|int, mixed>
Return values
boolvalidateFacts()
Validate facts data
public
validateFacts(array<string|int, mixed> $data) : array<string|int, mixed>
Parameters
- $data : array<string|int, mixed>
Return values
array<string|int, mixed>getCurrencyMap()
Retrun an array mapping currency codes to their ID
private
getCurrencyMap(array<string|int, mixed> $codes) : array<string, int>
Parameters
- $codes : array<string|int, mixed>
Return values
array<string, int>getDatapointsMap()
Retrun an array mapping datapoint codes to their ID
private
getDatapointsMap(array<string|int, mixed> $codes) : array<string, int>
Parameters
- $codes : array<string|int, mixed>
Return values
array<string, int>getKpiMap()
Retrun an array mapping KPI codes to their ID
private
getKpiMap(array<string|int, mixed> $codes) : array<string, int>
Parameters
- $codes : array<string|int, mixed>
Return values
array<string, int>getLocationMap()
Retrun an array mapping Location codes to their ID
private
getLocationMap(array<string|int, mixed> $codes) : array<string, int>
Parameters
- $codes : array<string|int, mixed>
Return values
array<string, int>getTimeMap()
Retrun an array mapping date_id codes to their date_dataid
private
getTimeMap() : array<string, int>
Return values
array<string, int>getUnitsMap()
Retrun an array mapping units codes to their ID
private
getUnitsMap(array<string|int, mixed> $codes) : array<string, int>
Parameters
- $codes : array<string|int, mixed>