Example #1
0
 public function initProductionFilterGroup($workspace, $extras = null)
 {
     if ($workspace) {
         $pid = $workspace->PRODUCTION_UNIT_ID;
         $aid = $workspace->AREA_ID;
         $fid = $workspace->W_FACILITY_ID;
     } else {
         $pid = 0;
         $aid = 0;
         $fid = 0;
     }
     $productionUnits = LoProductionUnit::all(['ID', 'NAME']);
     $currentProductUnit = ProductionGroupComposer::getCurrentSelect($productionUnits, $pid);
     $areas = $currentProductUnit->LoArea()->getResults();
     $currentArea = ProductionGroupComposer::getCurrentSelect($areas, $aid);
     $facilities = $currentArea->Facility()->getResults();
     $currentFacility = ProductionGroupComposer::getCurrentSelect($facilities, $fid);
     $productionFilterGroup = ['LoProductionUnit' => ProductionGroupComposer::getFilterArray('LoProductionUnit', $productionUnits, $currentProductUnit), 'LoArea' => ProductionGroupComposer::getFilterArray('LoArea', $areas, $currentArea), 'Facility' => ProductionGroupComposer::getFilterArray('Facility', $facilities, $currentFacility)];
     $currentObject = $currentFacility;
     foreach ($extras as $source => $model) {
         $option = $this->getExtraOptions($productionFilterGroup, $model, $source);
         if ($option && array_key_exists($source, $option) && array_key_exists("object", $option[$source])) {
             $currentObject = $option[$source]["object"];
         }
         $rs = ProductionGroupComposer::initExtraDependence($productionFilterGroup, $model, $currentObject, $option);
         $eCollection = $rs['collection'];
         $modelName = $rs['model'];
         $extraFilter = ProductionGroupComposer::getCurrentSelect($eCollection);
         $productionFilterGroup[$modelName] = ProductionGroupComposer::getFilterArray($modelName, $eCollection, $extraFilter, $model);
     }
     return $productionFilterGroup;
 }
Example #2
0
 public function getCodes(Request $request)
 {
     $options = $request->only('type', 'value', 'dependences', 'extra');
     $bunde = $options['extra'];
     $type = $options['type'];
     if ($type == 'date_end' || $type == 'date_begin') {
         $unit = new CustomizeDateCollection($type, $options['value']);
     } else {
         $mdl = 'App\\Models\\' . $type;
         $unit = $mdl::find($options['value']);
     }
     $originUnit = $unit;
     $results = [];
     $currentUnits = [$type => $unit];
     foreach ($options['dependences'] as $model) {
         $modelName = $model;
         $currentId = null;
         $sourceUnit = $unit;
         $isAdd = true;
         if (is_array($model)) {
             if (array_key_exists("source", $model)) {
                 $currentSourceName = $model["source"];
                 $sourceUnit = array_key_exists($currentSourceName, $currentUnits) ? $currentUnits[$currentSourceName] : $originUnit;
             } else {
                 $sourceUnit = $originUnit;
             }
             $modelName = $model["name"];
             $isAdd = !array_key_exists("independent", $model) || !$model["independent"];
         }
         if ($sourceUnit != null) {
             $rs = ProductionGroupComposer::initExtraDependence($results, $model, $sourceUnit, $bunde);
             $eCollection = $rs['collection'];
             $modelName = $rs['model'];
             $currentId = $rs['currentId'];
         } else {
             break;
         }
         if (is_string($model) && array_key_exists($model, config("constants.subProductFilterMapping")) && array_key_exists('default', config("constants.subProductFilterMapping")[$model])) {
             $eCollection[] = config("constants.subProductFilterMapping")[$model]['default'];
         }
         $unit = ProductionGroupComposer::getCurrentSelect($eCollection, $currentId);
         $currentUnits[$modelName] = $unit;
         $filterArray = ProductionGroupComposer::getFilterArray($modelName, $eCollection, $unit);
         if ($isAdd) {
             $results[] = $filterArray;
         }
     }
     return response($results, 200)->header('Content-Type', 'application/json');
 }