예제 #1
0
 public function getDetailData($id, $postData, $properties)
 {
     $templateId = $postData['templateId'];
     $pdContractData = PdContractData::getTableName();
     $pdContractTemplateAttribute = PdContractTemplateAttribute::getTableName();
     $pdCodeContractAttribute = PdCodeContractAttribute::getTableName();
     $pdContractQtyFormula = PdContractQtyFormula::getTableName();
     $contractDataSet = PdContractData::join($pdCodeContractAttribute, "{$pdContractData}.ATTRIBUTE_ID", '=', "{$pdCodeContractAttribute}.ID")->leftJoin($pdContractQtyFormula, "{$pdCodeContractAttribute}.FORMULA_ID", '=', "{$pdContractQtyFormula}.ID")->where("{$pdContractData}.CONTRACT_ID", '=', $id)->select("{$pdContractData}.*", "{$pdContractData}.CONTRACT_ID as CONTRACT_ID_INDEX", "{$pdContractData}.ATTRIBUTE_ID as ATTRIBUTE_ID_INDEX", "{$pdCodeContractAttribute}.ID as DT_RowId", "{$pdCodeContractAttribute}.ID as {$pdContractData}", "{$pdCodeContractAttribute}.NAME as CONTRACT_ID", "{$pdCodeContractAttribute}.CODE as ATTRIBUTE_ID", "{$pdCodeContractAttribute}.ID as ID", "{$pdContractQtyFormula}.NAME as FORMULA")->get();
     $selects = ["{$pdCodeContractAttribute}.ID as DT_RowId", "{$pdCodeContractAttribute}.ID as {$pdContractData}", "{$pdCodeContractAttribute}.NAME as CONTRACT_ID", "{$pdCodeContractAttribute}.CODE as ATTRIBUTE_ID", "{$pdCodeContractAttribute}.ID", "{$pdCodeContractAttribute}.FORMULA_ID as FORMULA", "{$pdCodeContractAttribute}.ID as ATTRIBUTE_ID_INDEX", "{$pdContractQtyFormula}.NAME as FORMULA", \DB::raw("{$id} as CONTRACT_ID_INDEX")];
     foreach ($properties as $property) {
         $columnName = $property['data'];
         if ($columnName != 'CONTRACT_ID' && $columnName != 'ATTRIBUTE_ID' && $columnName != 'ID') {
             $selects[] = \DB::raw("null as {$columnName}");
         }
     }
     $templateQuery = PdContractTemplateAttribute::join($pdCodeContractAttribute, "{$pdContractTemplateAttribute}.ATTRIBUTE", '=', "{$pdCodeContractAttribute}.ID")->leftJoin($pdContractQtyFormula, "{$pdCodeContractAttribute}.FORMULA_ID", '=', "{$pdContractQtyFormula}.ID")->where("{$pdContractTemplateAttribute}.CONTRACT_TEMPLATE", '=', $templateId)->where("{$pdContractTemplateAttribute}.ACTIVE", '=', 1)->select($selects);
     // 										    	->get();
     $existAttributes = $contractDataSet->pluck('DT_RowId');
     if (count($existAttributes) > 0) {
         $templateQuery->whereNotIn("{$pdCodeContractAttribute}.ID", $existAttributes);
     }
     $templateDataSet = $templateQuery->get();
     $dataSet = $contractDataSet->merge($templateDataSet);
     return $dataSet;
 }
예제 #2
0
 public function loadData($contractId, $postData)
 {
     $pdContractYear = PdContractYear::getTableName();
     $pdContractCalculation = PdContractCalculation::getTableName();
     $contractYears = PdContractYear::join($pdContractCalculation, "{$pdContractYear}.CALCULATION_ID", '=', "{$pdContractCalculation}.ID")->where("{$pdContractYear}.CONTRACT_ID", '=', $contractId)->select("{$pdContractYear}.FORMULA_VALUE", "{$pdContractYear}.YEAR", "{$pdContractCalculation}.FORMULA_ID")->orderBy("{$pdContractYear}.YEAR", 'desc')->get();
     $propertiesArray = [(object) ['data' => 'NAME', 'title' => 'Contract Quantity', 'width' => 150], (object) ['data' => 'DESCRIPTION', 'title' => 'Description', 'width' => 400]];
     $pdContractQtyFormula = PdContractQtyFormula::getTableName();
     $data = PdContractQtyFormula::select("ID as DT_RowId", "{$pdContractQtyFormula}.*")->get();
     $years = $contractYears->groupBy("YEAR");
     if ($years->count() > 0) {
         foreach ($years as $year => $set) {
             $yearField = "year{$year}";
             $propertiesArray[] = (object) ['data' => $yearField, 'title' => "{$year}", 'DATA_METHOD' => 0, 'INPUT_TYPE' => 2];
             $formulaGroups = $set->groupBy("FORMULA_ID");
             $data = $data->each(function ($item, $key) use($yearField, $formulaGroups) {
                 $item->{$yearField} = $formulaGroups[$item->ID][0]->FORMULA_VALUE;
             });
         }
     }
     $properties = collect($propertiesArray);
     $results['properties'] = $properties;
     $results['dataSet'] = $data;
     $results['postData'] = $postData;
     return $results;
 }
예제 #3
0
 public static function findManyWithConfig($updatedIds)
 {
     $pdContractData = static::getTableName();
     $pdCodeContractAttribute = PdCodeContractAttribute::getTableName();
     $pdContractQtyFormula = PdContractQtyFormula::getTableName();
     $result = PdContractData::join($pdCodeContractAttribute, "{$pdContractData}.ATTRIBUTE_ID", '=', "{$pdCodeContractAttribute}.ID")->leftJoin($pdContractQtyFormula, "{$pdCodeContractAttribute}.FORMULA_ID", '=', "{$pdContractQtyFormula}.ID")->whereIn("{$pdContractData}.ID", $updatedIds)->select("{$pdContractData}.*", "{$pdContractData}.CONTRACT_ID as CONTRACT_ID_INDEX", "{$pdContractData}.ATTRIBUTE_ID as ATTRIBUTE_ID_INDEX", "{$pdCodeContractAttribute}.ID as DT_RowId", "{$pdCodeContractAttribute}.ID as {$pdContractData}", "{$pdCodeContractAttribute}.NAME as CONTRACT_ID", "{$pdCodeContractAttribute}.CODE as ATTRIBUTE_ID", "{$pdCodeContractAttribute}.ID as ID", "{$pdContractQtyFormula}.NAME as FORMULA")->get();
     return $result;
 }