-
Notifications
You must be signed in to change notification settings - Fork 0
How to import data from CSV file
In this example we import / update the materials
-
The function for import in the object:
public function importMaterialData($data, $mappings = []){\Application\Controller\Log::getInstance()->AddRow('mappings importCsv');// import into parent with mapped parent via external relations$mappings = array("nrcrt" => "nrcrt","articol" => "articol","longname" => "longname","importuom" => "importuom","cosuppliercode" => "cosuppliercode","gestimpl" => "gestimpl");$this->importParentCsv(0, "Pmamaterial", $data, $mappings);} -
The function for import in Workspace:
public function importMaterialData($data){$log = \Application\Controller\Log::getInstance();$log->AddRow('ImportMaterials >-on parent --> ' . json_encode($data));$dataNew = json_decode($data, true);$log->AddRow('ImportMaterials >-on parent --> ' . json_encode($dataNew));\Application\Controller\Log::getInstance()->AddRow('mappings importCsv');$mappings = array("nrcrt" => "nrcrt","articol" => "articol","longname" => "longname","importuom" => "importuom","cosuppliercode" => "cosuppliercode","gestimpl" => "gestimpl");// import into parent with mapped parent via external relations$this->importParentCsv($this->getIdAsString(), "Pmamaterial", $dataNew[0], $mappings);return "MATERIALS DATA IMPORTED";}
3.The function in reactfixture(This is an exmple):
`$data = array(`
`"name" => "adminimport_csv_material",`
`"actionExecution" => "inputform",`
`"viewId" => "viewId",`
`"link" => "Importa din fisier CSV/Excel",`
`"type" => "list",`
`"parentType" => "Workspace",`
`"objectType" => "Pmamaterial",`
`"method" => "importDialogMaterial",`
`"serviceName" => "",`
`"serviceMethod" => "",`
`"template" => "",`
`"scope" => "user"`
`);`
`$mObj->createAndAdd($typeComp, (string)$returnComponentMaterialGrid, $typeContextmenu, $data);`
`$workspaceD->createField($viewId, "importDialogMaterial", \Application\Document\Field::TYPE_FILE, "", "fileName", "Fisier CSV/EXCEL", true, "", "");`
`$workspaceD->createField($viewId, "importDialogMaterial", \Application\Document\Field::TYPE_BUTTON, "", "save", "Importă/actualizează materiale", true, "method", "", "importMaterialData(@fileName@);", "", "showMessage(\"@name@\");");`
- Observations!
- The CSV file must contain columns from "mappings" and vice versa, and as a delimiter we use ";".
- On the server the import time lasts, we have to wait until all the data is imported.
- Locally only part of the CSV file is imported.
tes