609 lines
28 KiB
PHP
609 lines
28 KiB
PHP
<?php
|
|
|
|
namespace Romanah\Gokbakja\Components;
|
|
|
|
use Cms\Classes\ComponentBase;
|
|
use Romanah\Gokbakja\Models\Product as ProductModel;
|
|
use Romanah\Gokbakja\Models\Production as ProductionModel;
|
|
use Romanah\Gokbakja\Models\Excruiter as ExcruiterModel;
|
|
use Romanah\Gokbakja\Models\ProductionMachine as ProductionMachineModel;
|
|
use Romanah\Gokbakja\Models\PivotProduction as PivotProductionModel;
|
|
use Redirect;
|
|
use Carbon\Carbon;
|
|
use Flash;
|
|
use DB;
|
|
use October\Rain\Support\Facades\Flash as FacadesFlash;
|
|
|
|
class Production extends ComponentBase
|
|
{
|
|
|
|
|
|
public function componentDetails()
|
|
{
|
|
return [
|
|
'name' => 'Production',
|
|
'description' => 'productions settings'
|
|
];
|
|
}
|
|
|
|
|
|
public function onReportProduction()
|
|
{
|
|
|
|
$currentDate = Carbon::now()->timezone('UTC +05:00');
|
|
$currentDateFormat = $currentDate->format('Y-m-d');
|
|
|
|
$data = post();
|
|
|
|
|
|
|
|
|
|
$productions = ProductionModel::with(['pivot_production', 'excruiter', 'shift'])->orderBy('id', 'DESC');
|
|
$productionsCalc = ProductionModel::orderBy('id', 'DESC');
|
|
|
|
$start = Carbon::parse($data["start"])->format('Y-m-d');
|
|
$end = Carbon::parse($data["end"])->format('Y-m-d');
|
|
|
|
|
|
if ($start == $currentDateFormat) {
|
|
Flash::error("Sene Saylan!");
|
|
} else {
|
|
$startView = Carbon::parse($data["start"])->format('d.m.Y');
|
|
$endView = Carbon::parse($data["end"])->format('d.m.Y');
|
|
|
|
$excruiter = $data["excruiter_id"];
|
|
$shiftId = $data["shift_id"];
|
|
|
|
|
|
if ($excruiter) {
|
|
$productions->where("excruiter_id", $excruiter);
|
|
$productionsCalc->where("excruiter_id", $excruiter);
|
|
}
|
|
|
|
if ($shiftId) {
|
|
$productions->where("shift_id", $shiftId);
|
|
$productionsCalc->where("shift_id", $shiftId);
|
|
}
|
|
|
|
if ($start != $currentDateFormat) {
|
|
$productions->whereBetween('created_at', [$start, $end]);
|
|
|
|
$calc = $productionsCalc->select(DB::raw('MAX(all_amount) - MIN(all_amount) AS amount_subtraction'), DB::raw('MAX(all_amount) AS max_amount'), DB::raw('MIN(all_amount) AS min_amount'), DB::raw('MAX(time) AS max_time'), DB::raw('MIN(time) AS min_time'))
|
|
->whereBetween('created_at', [$start, $end])->first();
|
|
|
|
$diffMinutes = Carbon::parse($calc->max_time)->diffInMinutes($calc->min_time);
|
|
$calcTimeDiff = floor($diffMinutes / 60) . ' sagat ' . ($diffMinutes - floor($diffMinutes / 60) * 60) . ' minut';
|
|
// dd($max);
|
|
// $min = $productions->select(DB::raw("MIN(id)"));
|
|
|
|
|
|
}
|
|
|
|
$productionsFiltered = $productions->get();
|
|
|
|
|
|
$html_data = '';
|
|
for ($x = 0; $x < count($productionsFiltered); $x++) {
|
|
// dd($productionsFiltered[0]->shift->desc);
|
|
$html_data .= '<tr>
|
|
<td style="font-weight: bold;width: 5%;">' . ($x + 1) . '</td>
|
|
<td><a href="#" style="font-weight: bold;color: #0005c5;">' . $productionsFiltered[$x]->created_at->format("d.m.Y | H:i") . '</a></td>
|
|
<td><a href="#" style="font-weight: bold;color: #1e2038;">' . $productionsFiltered[$x]->shift->desc . '</a></td>
|
|
<td style="text-align: center;">
|
|
<span class="badge badge-soft-info"
|
|
style="font-size: 14px;">' . $productionsFiltered[$x]->excruiter->name . '</span>
|
|
</td>
|
|
<td style="text-align: center;">
|
|
<span class="badge badge-soft-success"
|
|
style="font-size: 14px;">' . number_format($productionsFiltered[$x]->all_amount) . ' kg</span>
|
|
</td>';
|
|
|
|
|
|
for ($i = 0; $i < count($productionsFiltered[$x]->pivot_production); $i++) {
|
|
$html_data .= '<td> <a href="#">' . number_format($productionsFiltered[$x]->pivot_production[$i]->amount_percentage) . '% </a></td>';
|
|
}
|
|
|
|
$html_data .= '<td style="font-weight: bold;color: #0005c5;">' . $productionsFiltered[$x]->note . '</td>
|
|
</tr>';
|
|
}
|
|
|
|
if ($productionsFiltered) {
|
|
return [
|
|
'#production_report_datas' => $html_data,
|
|
// '#exampleModalFullscreenLabel' => '<font style="color: darkgreen;text-decoration: underline;font-weight: bold;">'. $startView .' - '. $endView .'</font> seneleri aralygynda güni jemi',
|
|
'#report_dynamic' => ' <div class="col-md-4">
|
|
<h3 class="card-title" style="font-size: 22px;color: #1e2038;">Çig Mallar Boýunça Umumy</h3>
|
|
<p class="card-title-desc" style="color: #6c6ff5;">Hasabat</p>
|
|
</div>
|
|
<div class="col-md-4">
|
|
<div class="card bg-info text-white-50">
|
|
<div class="card-body">
|
|
<h5 class="text-white" style="text-transform: uppercase;margin-bottom: 0;"><i class="mdi mdi-bullseye-arrow me-3"></i>Sarp Edilen Wagt: ' . $calcTimeDiff . ' sany</h5>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-4">
|
|
<div class="card bg-info text-white-50">
|
|
<div class="card-body">
|
|
<h5 class="text-white" style="text-transform: uppercase;margin-bottom: 0;"><i class="mdi mdi-bullseye-arrow me-3"></i>Sarp Edilen Çig mal: ' . number_format($calc->amount_subtraction) . ' kg</h5>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
'
|
|
];
|
|
} else {
|
|
Flash::error("Yalnyshlyk bar!!");
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
public function onCalculateReportDaily()
|
|
{
|
|
$currentDate = Carbon::now()->timezone('UTC +05:00');
|
|
|
|
$currentDateFormat = $currentDate->format('Y-m-d');
|
|
|
|
$data = post();
|
|
|
|
$excruiter = $this->param("excruiter");
|
|
|
|
|
|
$currentDateLast = ProductionModel::whereDate('created_at', date($currentDateFormat))->where('excruiter_id', $excruiter)->with("excruiter")->orderBy('id', 'DESC')->first();
|
|
$currentDateFirst = ProductionModel::whereDate('created_at', date($currentDateFormat))->where('excruiter_id', $excruiter)->orderBy('id', 'ASC')->first();
|
|
|
|
$productionsCalc = ProductionModel::orderBy('id', 'DESC');
|
|
|
|
$calc = $productionsCalc->select(DB::raw('MAX(all_amount) - MIN(all_amount) AS amount_subtraction'), DB::raw('MAX(all_amount) AS max_amount'), DB::raw('MIN(all_amount) AS min_amount'), DB::raw('MAX(time) AS max_time'), DB::raw('MIN(time) AS min_time'))
|
|
->whereDate('created_at', date($currentDateFormat))->where('excruiter_id', $excruiter)->first();
|
|
|
|
$diffMinutes = Carbon::parse($calc->max_time)->diffInMinutes($calc->min_time);
|
|
|
|
// $calcTimeDiff = floor($diffMinutes / 60) . ' sagat ' . ($diffMinutes - floor($diffMinutes / 60) * 60) . ' minut';
|
|
|
|
|
|
// $diffMinutes = Carbon::parse($currentDateLast->time)->diffInMinutes($currentDateFirst->time);
|
|
|
|
$currentDateProductionAll = ProductionModel::whereDate('created_at', date($currentDateFormat))->where('excruiter_id', $excruiter)->avg('all_amount');
|
|
|
|
|
|
// $testq = PivotProductionModel::whereDate('created_at', date($currentDateFormat))
|
|
// ->where('excruiter_id', $excruiter)
|
|
// ->select('id', 'product_name', 'excruiter_id',DB::raw('round(AVG(amount),0) as average'), DB::raw('round(AVG(amount_percentage),0) as average_percentage'))
|
|
// ->groupBy('product_id')
|
|
// ->get();
|
|
|
|
$pivotFirsts = PivotProductionModel::where('production_id', $currentDateFirst->id)->get();
|
|
$pivotLasts = PivotProductionModel::where('production_id', $currentDateLast->id)->get();
|
|
|
|
|
|
|
|
$allData = array(
|
|
"all" => array(
|
|
"hours" => floor($diffMinutes / 60) . ' sagat ' . ($diffMinutes - floor($diffMinutes / 60) * 60) . ' minut',
|
|
"avg_all_amount" => number_format($currentDateProductionAll, 2),
|
|
)
|
|
);
|
|
|
|
$producedAll = $calc->amount_subtraction;
|
|
|
|
$countDailyChanges = ProductionModel::whereDate('created_at', date($currentDateFormat))->where('excruiter_id', $excruiter)->get();
|
|
|
|
// dd(count($countDailyChanges));
|
|
|
|
if (count($countDailyChanges) > 1) {
|
|
// gunluk hasabat
|
|
$html_data = '<div class="row">';
|
|
$html_data .= '<h4 style="margin-top: 20px;margin-bottom: 20px;">JEMI IŞLENEN ÇIG MAL (ekskruiter: ' . $currentDateLast->excruiter->name . ')</h4>';
|
|
|
|
$html_data .= '<div class="col-lg">
|
|
<a class="card bg-success text-white-50">
|
|
<div class="card-body">
|
|
<h5 class="mb-4 text-white"><i
|
|
class="mdi mdi-bullseye-arrow me-3"></i>' . $allData["all"]["hours"] . '</h5>
|
|
<hr>
|
|
<p class="card-text" style="font-size: 15px;color: white;">JEMI IŞLENEN: ' . $producedAll . ' kg</p>
|
|
</div>
|
|
</a>
|
|
</div>';
|
|
|
|
for ($x = 0; $x < count($pivotLasts); $x++) {
|
|
// $diff = $pivotLasts[$x]->amount - $pivotFirsts[$x]->amount;
|
|
// $diffPerc = ($diff * 100) / $producedAll;
|
|
$calculatedPercentage = (float) ($pivotLasts[$x]->amount_percentage / 100) * (float) $producedAll;
|
|
|
|
$html_data .= '<div class="col-lg">
|
|
<a class="card bg-info text-white-50">
|
|
<div class="card-body">
|
|
<h5 class="mb-4 text-white"><i class="mdi mdi-bullseye-arrow me-3"></i>' . ($calculatedPercentage) . ' kg</h5>
|
|
<hr>
|
|
<p class="card-text" style="font-size: 15px;color: white;">' . $pivotLasts[$x]->product_name . ' : ' . ($pivotLasts[$x]->amount_percentage) . ' %</p>
|
|
</div>
|
|
</a>
|
|
</div>';
|
|
}
|
|
|
|
$html_data .= '</div>';
|
|
|
|
$hourCount = floor($diffMinutes / 60) . '.' . ($diffMinutes - floor($diffMinutes / 60) * 60);
|
|
$avgProducedHour = $producedAll / $hourCount;
|
|
|
|
|
|
|
|
// sagatda ortacha hasbat
|
|
$html_data2 = '<div class="row">';
|
|
$html_data2 .= '<h4 style="margin-top: 20px;margin-bottom: 20px;">SAGATDA ORTAÇA SARP EDIŞ HASABATY (ekskruiter: ' . $currentDateLast->excruiter->name . ')</h4>';
|
|
|
|
$html_data2 .= '<div class="col-lg">
|
|
<a class="card bg-success text-white-50">
|
|
<div class="card-body">
|
|
<h5 class="mb-4 text-white"><i
|
|
class="mdi mdi-bullseye-arrow me-3"></i>' . $allData["all"]["hours"] . '</h5>
|
|
<hr>
|
|
<p class="card-text" style="font-size: 15px;color: white;">Sagatda Ortaça: ' . (number_format($avgProducedHour, 2)) . ' kg</p>
|
|
</div>
|
|
</a>
|
|
</div>';
|
|
|
|
for ($x = 0; $x < count($pivotLasts); $x++) {
|
|
// $diff = $pivotLasts[$x]->amount - $pivotFirsts[$x]->amount;
|
|
// $diffPerc = ($diff * 100) / $producedAll;
|
|
$calculatedPercentage = (float) ($pivotLasts[$x]->amount_percentage / 100) * (float) $producedAll;
|
|
$calculatePercentageHour = (float) (($calculatedPercentage / $hourCount) * 100) / (float) $producedAll;
|
|
|
|
$html_data2 .= '<div class="col-lg">
|
|
<a class="card bg-info text-white-50">
|
|
<div class="card-body">
|
|
<h5 class="mb-4 text-white"><i class="mdi mdi-bullseye-arrow me-3"></i> Sagatda: ' . (number_format(($calculatedPercentage / $hourCount), 2)) . ' kg</h5>
|
|
<hr>
|
|
<p class="card-text" style="font-size: 15px;color: white;">' . $pivotLasts[$x]->product_name . ' : ' . (number_format($calculatePercentageHour, 2)) . ' %</p>
|
|
</div>
|
|
</a>
|
|
</div>';
|
|
}
|
|
|
|
$html_data2 .= '</div>';
|
|
|
|
|
|
$html_data3 = '';
|
|
|
|
$currentDateExcruiters = ProductionModel::whereDate('created_at', date($currentDateFormat))->groupBy("excruiter_id")->orderBy('id', 'DESC')->with("excruiter")->get();
|
|
|
|
|
|
|
|
for ($i = 0; $i < count($currentDateExcruiters); $i++) {
|
|
|
|
$currentDateLastExc = ProductionModel::whereDate('created_at', date($currentDateFormat))->where('excruiter_id', $currentDateExcruiters[$i]->excruiter_id)->orderBy('id', 'DESC')->first();
|
|
|
|
// $currentDateFirstExc = ProductionModel::whereDate('created_at', date($currentDateFormat))->where('excruiter_id', $currentDateExcruiters[$i]->excruiter_id)->orderBy('id', 'ASC')->first();
|
|
|
|
/////////////
|
|
|
|
|
|
$productionsCalc = ProductionModel::orderBy('id', 'DESC');
|
|
|
|
$calc = $productionsCalc->select(DB::raw('MAX(all_amount) - MIN(all_amount) AS amount_subtraction'), DB::raw('MAX(all_amount) AS max_amount'), DB::raw('MIN(all_amount) AS min_amount'), DB::raw('MAX(time) AS max_time'), DB::raw('MIN(time) AS min_time'))
|
|
->whereDate('created_at', date($currentDateFormat))->where('excruiter_id', $currentDateExcruiters[$i]->excruiter_id)->first();
|
|
|
|
$diffMinutesExc = Carbon::parse($calc->max_time)->diffInMinutes($calc->min_time);
|
|
|
|
|
|
/////////////
|
|
|
|
// $diffMinutesExc = Carbon::parse($currentDateLastExc->time)->diffInMinutes($currentDateFirstExc->time);
|
|
|
|
$hourCountExc = floor($diffMinutesExc / 60) . ' sagat ' . ($diffMinutesExc - floor($diffMinutesExc / 60) * 60) . ' minut';
|
|
|
|
$allAmountExc = $calc->amount_subtraction;
|
|
|
|
// dd($currentDateFirstExc);
|
|
$html_data3 .= '<div class="row">';
|
|
$html_data3 .= '<h4 style="margin-top: 20px;margin-bottom: 20px;">' . $currentDateExcruiters[$i]->excruiter->name . ' - işlenen çig mallar boýunça.</h4>';
|
|
|
|
|
|
$html_data3 .= '<div class="col-lg">
|
|
<a class="card bg-success text-white-50">
|
|
<div class="card-body">
|
|
<h5 class="mb-4 text-white"><i
|
|
class="mdi mdi-bullseye-arrow me-3"></i>' . $hourCountExc . '</h5>
|
|
<hr>
|
|
<p class="card-text" style="font-size: 15px;color: white;">Jemi Işlenen: ' . (number_format($allAmountExc)) . ' kg</p>
|
|
</div>
|
|
</a>
|
|
</div>';
|
|
|
|
$excruiterDatas = PivotProductionModel::where('production_id', $currentDateLastExc->id)->get();
|
|
// $pivotLasts = PivotProductionModel::where('production_id', $currentDateLast->id)->get();
|
|
|
|
// \Log::info($excruiterDatas);
|
|
for ($ii = 0; $ii < count($excruiterDatas); $ii++) {
|
|
// $diff = $pivotLasts[$x]->amount - $pivotFirsts[$x]->amount;
|
|
// $diffPerc = ($diff * 100) / $producedAll;
|
|
$calculatedPercentage = (float) ($excruiterDatas[$ii]->amount_percentage / 100) * (float) $allAmountExc;
|
|
|
|
$html_data3 .= '<div class="col-lg">
|
|
<a class="card bg-info text-white-50">
|
|
<div class="card-body">
|
|
<h5 class="mb-4 text-white"><i class="mdi mdi-bullseye-arrow me-3"></i>' . ($calculatedPercentage) . ' kg</h5>
|
|
<hr>
|
|
<p class="card-text" style="font-size: 15px;color: white;">' . $excruiterDatas[$ii]->product_name . ' : ' . ($excruiterDatas[$ii]->amount_percentage) . ' %</p>
|
|
</div>
|
|
</a>
|
|
</div>';
|
|
}
|
|
$html_data3 .= '</div><hr>';
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$currentDateShifts = ProductionModel::whereDate('created_at', date($currentDateFormat))
|
|
// ->where("excruiter_id", $excruiter)
|
|
->with(["shift", "excruiter", "pivot_production"])
|
|
->groupBy("shift_id", "excruiter_id")
|
|
// ->max("id")
|
|
->orderBy('excruiter_id', 'DESC')
|
|
// ->distinct()
|
|
->get();
|
|
|
|
// dd($currentDateShifts);
|
|
// $products = ProductModel::where("report", "simple")->get();
|
|
|
|
|
|
$html_data4 = '<h4 style="margin-top: 20px;margin-bottom: 20px;">SMENLAR BOÝUNÇA</h4>';
|
|
$html_data4 .= '<div class="container-fluid"><div class="row"><div class="col-md-12">';
|
|
|
|
$html_data4 .= '<table id="datatable-buttons" class="table table-striped table-bordered dt-responsive nowrap"
|
|
style="border-collapse: collapse; border-spacing: 0; width: 100%;">
|
|
|
|
<thead>
|
|
<tr>
|
|
<th>#</th>
|
|
<th>Smen</th>
|
|
<th>Ekskruiter</th>
|
|
<th>Wagty</th>
|
|
<th>Jemi</th>
|
|
';
|
|
// for ($ii = 0; $ii < count($currentDateShifts[0]->pivot_production); $ii++) {
|
|
// $html_data4 .= '<th>' . $currentDateShifts[0]->pivot_production[$ii]->product_name . '</th>';
|
|
// }
|
|
$html_data4 .= '</tr>
|
|
</thead><tbody>';
|
|
|
|
|
|
|
|
for ($i = 0; $i < count($currentDateShifts); $i++) {
|
|
|
|
$productionsCalc = ProductionModel::orderBy('id', 'DESC')->whereDate('created_at', date($currentDateFormat));
|
|
|
|
$calc = $productionsCalc->select(DB::raw('MAX(all_amount) - MIN(all_amount) AS amount_subtraction'), DB::raw('MAX(all_amount) AS max_amount'), DB::raw('MIN(all_amount) AS min_amount'), DB::raw('MAX(time) AS max_time'), DB::raw('MIN(time) AS min_time'))
|
|
->where('shift_id', $currentDateShifts[$i]->shift_id)->where('excruiter_id', $currentDateShifts[$i]->excruiter_id)->first();
|
|
|
|
$diffMinutes = Carbon::parse($calc->max_time)->diffInMinutes($calc->min_time);
|
|
|
|
$hourCountShift = floor($diffMinutes / 60) . ' sagat ' . ($diffMinutes - floor($diffMinutes / 60) * 60) . ' minut';
|
|
|
|
$html_data4 .= '<tr>
|
|
<th scope="row">' . ($i + 1) . '</th>
|
|
<td style="font-weight: bold;color: #0005c5;">' . $currentDateShifts[$i]->shift->desc . '(' . $currentDateShifts[$i]->shift->start . ' - ' . $currentDateShifts[$i]->shift->end . ')</td>
|
|
<td><span class="badge badge-soft-info"
|
|
style="font-size: 14px;">' . $currentDateShifts[$i]->excruiter->name . '</span></td>
|
|
<td>' . $hourCountShift . '</td>
|
|
<td>' . $calc->amount_subtraction . ' kg</td>';
|
|
|
|
|
|
// for ($x = 0; $x < count($pivotShiftLasts); $x++) {
|
|
|
|
// $calculatedPercentageShift = (float) ($pivotShiftLasts[$x]->amount_percentage / 100) * (float) $allAmountShift;
|
|
|
|
// $html_data4 .= '<td>' . ($calculatedPercentageShift) . ' kg </td>';
|
|
// }
|
|
|
|
|
|
$html_data4 .= '</tr>';
|
|
}
|
|
|
|
$html_data4 .= ' <tr>
|
|
|
|
</tr>';
|
|
$html_data4 .= ' </tbody>
|
|
</table></div></div></div>';
|
|
|
|
return [
|
|
'#calculation_of_day' => $html_data,
|
|
'#avg_of_day' => $html_data2,
|
|
'#excruiter_daily_report' => $html_data3,
|
|
'#shift_daily_report' => $html_data4
|
|
];
|
|
} else {
|
|
|
|
return [
|
|
'#calculation_of_day' => 'Gunluk Hasabat üçin 2-nji üýtgeşmeleri girizmeli!',
|
|
'#excruiter_daily_report' => 'Gunluk Hasabat üçin 2-nji üýtgeşmeleri girizmeli!',
|
|
'#shift_daily_report' => 'Gunluk Hasabat üçin 2-nji üýtgeşmeleri girizmeli!'
|
|
];
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function onCalculateAvg()
|
|
{
|
|
$currentDate = Carbon::now()->timezone('UTC +05:00');
|
|
|
|
$currentDateFormat = $currentDate->format('Y-m-d');
|
|
|
|
$data = post();
|
|
|
|
$product = ProductModel::where('id', $data["prod_id"])->first();
|
|
|
|
$sumPercentage = PivotProductionModel::where('product_id', $data["prod_id"])->whereDate('created_at', date($currentDateFormat))->sum('amount_percentage');
|
|
|
|
$sumPercentageCount = PivotProductionModel::where('product_id', $data["prod_id"])->whereDate('created_at', date($currentDateFormat))->count('amount_percentage');
|
|
|
|
|
|
$sumAmount = PivotProductionModel::where('product_id', $data["prod_id"])->whereDate('created_at', date($currentDateFormat))->sum('amount');
|
|
|
|
$sumAmountcount = PivotProductionModel::where('product_id', $data["prod_id"])->whereDate('created_at', date($currentDateFormat))->count('amount');
|
|
|
|
// dd($sumPercentage / $sumPercentageCount);
|
|
// dd(($sumPercentage + (int) $data["field_value"]) / ($sumPercentageCount + 1));
|
|
|
|
if ($sumPercentage != 0) {
|
|
|
|
$calcAvgPerc = ($sumPercentage + (float) $data["field_value"]) / ($sumPercentageCount + 1);
|
|
|
|
// $convertedToKgAvg = ((int) $data["field_value"] / 100) * ((int) $data["all_amount"]);
|
|
$convertedToKgSum = ((float) $data["field_value"] / 100) * ((float) $data["all_amount"]);
|
|
$convertToCount = $sumAmountcount + 1;
|
|
|
|
$calculateAvgAmount = ($convertedToKgSum + $sumAmount) / $convertToCount;
|
|
|
|
$allData = array(
|
|
"product_name" => $product->name,
|
|
"avg_percentage" => number_format($calcAvgPerc, 2),
|
|
"avg_amount" => number_format($calculateAvgAmount, 2)
|
|
);
|
|
} else {
|
|
$allData = array(
|
|
"product_name" => $product->name,
|
|
"avg_percentage" => number_format(0, 2),
|
|
"avg_amount" => number_format(0, 2)
|
|
);
|
|
}
|
|
// $calcAvgAmount = ($sumPercentage + (int) $data["field_value"]) / ($sumPercentageCount + 1);
|
|
|
|
|
|
|
|
|
|
return $allData;
|
|
// dd($currentDateFormat);
|
|
}
|
|
|
|
public function onUpdatePivotProduction()
|
|
{
|
|
$user = \Auth::user();
|
|
|
|
$currentDate = Carbon::now()->timezone('UTC +05:00');
|
|
|
|
// $this["currentMonth"] = $currentDate->format('m');
|
|
$data = post();
|
|
|
|
$updatePivotProduction = PivotProductionModel::where("id", $data["product_id"])->first();
|
|
|
|
$production = ProductionModel::where("id", $updatePivotProduction->production_id)->first();
|
|
$fieldName = "product_" . $data["product_id"];
|
|
|
|
$updatePivotProduction->amount_percentage = (float) $data[$fieldName] ?? 0;
|
|
$updatePivotProduction->amount = (((float) $data[$fieldName] ?? 0) / 100) * ((float) $production->all_amount);
|
|
$updatePivotProduction->save();
|
|
|
|
|
|
if ($updatePivotProduction) {
|
|
Flash::success("Hasabat Ustunlikli Üýtgedildi");
|
|
return Redirect::refresh();
|
|
}
|
|
}
|
|
|
|
public function onCreateProduction()
|
|
{
|
|
$user = \Auth::user();
|
|
|
|
$currentDate = Carbon::now()->timezone('UTC +05:00');
|
|
|
|
// $this["currentMonth"] = $currentDate->format('m');
|
|
$data = post();
|
|
$excruiter = $this->param("excruiter");
|
|
|
|
if ($excruiter == 0) {
|
|
Flash::error("Ekskruiter Saýla!");
|
|
return Redirect::refresh();
|
|
} else {
|
|
$createProduction = new ProductionModel();
|
|
|
|
$createProduction->all_amount = $data["all_amount"];
|
|
$createProduction->note = $data["note"];
|
|
$createProduction->user_id = $user->id;
|
|
$createProduction->date = $currentDate->format('Y-m-d');
|
|
$createProduction->time = $currentDate->format('H:i:s');
|
|
$createProduction->excruiter_id = $excruiter;
|
|
$createProduction->shift_id = $data["shift_id"];
|
|
$createProduction->save();
|
|
|
|
$products = ProductModel::where("report", "simple")->get();
|
|
|
|
for ($x = 0; $x < count($products); $x++) {
|
|
$fieldName = "product_" . $products[$x]->code;
|
|
|
|
$createPivotProduction = new PivotProductionModel();
|
|
$createPivotProduction->production_id = $createProduction->id;
|
|
$createPivotProduction->product_id = $products[$x]->id;
|
|
$createPivotProduction->amount_percentage = (float) $data[$fieldName] ?? 0;
|
|
$createPivotProduction->product_name = $products[$x]->name;
|
|
$createPivotProduction->product_code = $products[$x]->code;
|
|
$createProduction->excruiter_id = $excruiter;
|
|
$createPivotProduction->amount = (float)(((float) $data[$fieldName] ?? 0) / 100) * ((float) $createProduction->all_amount);
|
|
|
|
$createPivotProduction->date = $currentDate->format('Y-m-d');
|
|
$createPivotProduction->time = $currentDate->format('H:i:s');
|
|
$createPivotProduction->save();
|
|
}
|
|
|
|
if ($createProduction && $createPivotProduction) {
|
|
Flash::success("Hasabat Ustunlikli Goşuldy");
|
|
return Redirect::refresh();
|
|
}
|
|
}
|
|
}
|
|
|
|
public function onUpdateProduction()
|
|
{
|
|
$user = \Auth::user();
|
|
$data = post();
|
|
|
|
$updateResult = ActionModel::where('id', $data["id"])
|
|
->update(array(
|
|
'product_id' => $data["product_id"],
|
|
'amount' => $data["quantity"],
|
|
'stock_id' => $data["stock_id"],
|
|
'note' => $data["note"],
|
|
'transport_no' => $data["transport_no"],
|
|
'driver' => $data["driver"],
|
|
'user_id' => $user->id,
|
|
));
|
|
// $createResult = DollorModel::create([]);
|
|
|
|
// dd($data);
|
|
if ($updateResult) {
|
|
Flash::success("Action Ustunlikli Uytgedildi");
|
|
return Redirect::refresh();
|
|
}
|
|
}
|
|
|
|
|
|
public function onGetProduction()
|
|
{
|
|
$id = post('id');
|
|
return ActionModel::where('id', $id)->first();
|
|
}
|
|
|
|
// public function onDeleteProduction()
|
|
// {
|
|
// $id = post('id');
|
|
|
|
// $item = ActionModel::Find($id);
|
|
// $item->delete();
|
|
|
|
// if ($item) {
|
|
// Flash::success("Action Ustunlikli Pozuldy");
|
|
// return Redirect::refresh();
|
|
// }
|
|
// }
|
|
|
|
|
|
}
|