ikinci temizlik tamamlandı
This commit is contained in:
@@ -0,0 +1,179 @@
|
||||
<?php
|
||||
|
||||
$baseQuery = apply_welded_filter(db("weld_logs"));
|
||||
|
||||
$subcontractors = clone $baseQuery;
|
||||
$subcontractors = $subcontractors
|
||||
->select("ste_subcontractor")
|
||||
->whereNotNull("ste_subcontractor")
|
||||
->distinct()
|
||||
->pluck("ste_subcontractor")
|
||||
->toArray();
|
||||
|
||||
$monthly = apply_welded_filter(db("weld_logs"))
|
||||
->select(DB::raw('(SUM(CASE WHEN type_of_joint = "S" THEN nps_1 ELSE 0 END) + 0) as sum_S'),
|
||||
DB::raw('(SUM(CASE WHEN type_of_joint = "F" THEN nps_1 ELSE 0 END) + 0) as sum_F'))
|
||||
->selectRaw("(SUM(nps_1) + 0) AS total_nps");
|
||||
|
||||
foreach ($subcontractors as $subcontractor) {
|
||||
$safeSubcontractor = addslashes($subcontractor);
|
||||
$monthly->selectRaw(
|
||||
"(SUM(CASE WHEN ste_subcontractor = '{$safeSubcontractor}' THEN nps_1 ELSE 0 END) + 0) as " . str_slug($subcontractor, "_")
|
||||
);
|
||||
}
|
||||
|
||||
$monthly = $monthly
|
||||
->selectRaw('DATE_FORMAT(welding_date, "%m.%y") as month')
|
||||
->whereNotNull("welding_date")
|
||||
->groupByRaw('DATE_FORMAT(welding_date, "%m.%y")')
|
||||
->orderByRaw('MIN(welding_date) ASC')
|
||||
->get();
|
||||
|
||||
// String değerleri float'a dönüştür ve null değerleri 0 yap
|
||||
foreach ($monthly as $item) {
|
||||
$item->sum_S = (float) ($item->sum_S ?? 0);
|
||||
$item->sum_F = (float) ($item->sum_F ?? 0);
|
||||
$item->total_nps = (float) ($item->total_nps ?? 0);
|
||||
|
||||
foreach ($subcontractors as $subcontractor) {
|
||||
$fieldName = str_slug($subcontractor, "_");
|
||||
if (isset($item->$fieldName)) {
|
||||
$item->$fieldName = (float) ($item->$fieldName ?? 0);
|
||||
} else {
|
||||
$item->$fieldName = 0.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Debug için veriyi kontrol et
|
||||
// dd($monthly->toArray());
|
||||
|
||||
?>
|
||||
<script>
|
||||
const dataSource = <?php echo json_encode_tr($monthly) ?>;
|
||||
|
||||
$(() => {
|
||||
$('#monthlyProgress').dxChart({
|
||||
palette: 'colored',
|
||||
dataSource: dataSource,
|
||||
commonSeriesSettings: {
|
||||
argumentField: 'month',
|
||||
},
|
||||
series: [{
|
||||
valueField: 'sum_F',
|
||||
name: 'Field',
|
||||
type: 'bar',
|
||||
color: '#008fd8',
|
||||
visible: true,
|
||||
}, {
|
||||
valueField: 'sum_S',
|
||||
name: 'Shop',
|
||||
type: 'bar',
|
||||
color: '#ff6b6b',
|
||||
visible: true,
|
||||
}, {
|
||||
type: 'spline',
|
||||
valueField: 'total_nps',
|
||||
name: 'TOTAL',
|
||||
color: '#00d084',
|
||||
point: {
|
||||
visible: true,
|
||||
size: 6,
|
||||
},
|
||||
visible: true,
|
||||
},
|
||||
@foreach($subcontractors AS $subcontractor)
|
||||
{
|
||||
type: 'spline',
|
||||
valueField: '{{str_slug($subcontractor, "_")}}',
|
||||
name: '{{$subcontractor}}',
|
||||
point: {
|
||||
visible: true,
|
||||
size: 6,
|
||||
},
|
||||
visible: true,
|
||||
},
|
||||
@endforeach
|
||||
|
||||
],
|
||||
valueAxis: {
|
||||
grid: {
|
||||
visible: true,
|
||||
},
|
||||
title: {
|
||||
text: 'NPS Values',
|
||||
},
|
||||
min: 0,
|
||||
max: function() {
|
||||
// En yüksek değeri bul ve %20 margin ekle
|
||||
let maxValue = 0;
|
||||
dataSource.forEach(function(item) {
|
||||
maxValue = Math.max(maxValue, item.sum_F || 0, item.sum_S || 0, item.total_nps || 0);
|
||||
@foreach($subcontractors AS $subcontractor)
|
||||
maxValue = Math.max(maxValue, item.{{str_slug($subcontractor, "_")}} || 0);
|
||||
@endforeach
|
||||
});
|
||||
return Math.ceil(maxValue * 1.2);
|
||||
}(),
|
||||
tickInterval: function() {
|
||||
// Tick aralığını otomatik hesapla
|
||||
let maxValue = 0;
|
||||
dataSource.forEach(function(item) {
|
||||
maxValue = Math.max(maxValue, item.sum_F || 0, item.sum_S || 0, item.total_nps || 0);
|
||||
@foreach($subcontractors AS $subcontractor)
|
||||
maxValue = Math.max(maxValue, item.{{str_slug($subcontractor, "_")}} || 0);
|
||||
@endforeach
|
||||
});
|
||||
return Math.ceil(maxValue / 10);
|
||||
}(),
|
||||
},
|
||||
argumentAxis: {
|
||||
grid: {
|
||||
visible: true,
|
||||
},
|
||||
},
|
||||
tooltip: {
|
||||
enabled: true,
|
||||
shared: true,
|
||||
format: {
|
||||
type: 'largeNumber',
|
||||
precision: 2,
|
||||
},
|
||||
},
|
||||
legend: {
|
||||
verticalAlignment: 'bottom',
|
||||
horizontalAlignment: 'center',
|
||||
},
|
||||
export: {
|
||||
enabled: true,
|
||||
},
|
||||
title: {
|
||||
text: '{{e2("Monthly Progress")}}',
|
||||
},
|
||||
onContentReady: function(e) {
|
||||
// Chart yüklendiğinde veri kontrolü
|
||||
console.log('Chart data:', e.component.option('dataSource'));
|
||||
|
||||
// Y ekseni değerlerini düzenle
|
||||
let valueAxis = e.component.getArgumentAxis();
|
||||
let maxValue = 0;
|
||||
dataSource.forEach(function(item) {
|
||||
maxValue = Math.max(maxValue, item.sum_F || 0, item.sum_S || 0, item.total_nps || 0);
|
||||
@foreach($subcontractors AS $subcontractor)
|
||||
maxValue = Math.max(maxValue, item.{{str_slug($subcontractor, "_")}} || 0);
|
||||
@endforeach
|
||||
});
|
||||
|
||||
// Y ekseni maksimum değerini ayarla
|
||||
e.component.option('valueAxis.max', Math.ceil(maxValue * 1.2));
|
||||
e.component.option('valueAxis.tickInterval', Math.ceil(maxValue / 8));
|
||||
},
|
||||
onSeriesClick: function(e) {
|
||||
// Series tıklandığında detay bilgisi
|
||||
console.log('Series clicked:', e.seriesName, 'Value:', e.value);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
</script>
|
||||
<div id="monthlyProgress"></div>
|
||||
Reference in New Issue
Block a user