g_sto/plugins/romanah/gokbakja/components/Production.php

606 lines
27 KiB
PHP
Raw Normal View History

2023-09-17 19:12:00 +00:00
<?php
namespace Romanah\Gokbakja\Components;
use Cms\Classes\ComponentBase;
2023-09-18 20:22:50 +00:00
use Romanah\Gokbakja\Models\Product as ProductModel;
2023-09-17 19:12:00 +00:00
use Romanah\Gokbakja\Models\Production as ProductionModel;
2023-10-18 21:12:32 +00:00
use Romanah\Gokbakja\Models\ProductionCalculate as ProductionCalculateModel;
2023-10-10 22:29:27 +00:00
use Romanah\Gokbakja\Models\Excruiter as ExcruiterModel;
2023-10-18 21:12:32 +00:00
use Romanah\Gokbakja\Models\Shift as ShiftModel;
2023-09-23 20:10:26 +00:00
use Romanah\Gokbakja\Models\ProductionMachine as ProductionMachineModel;
2023-09-17 19:12:00 +00:00
use Romanah\Gokbakja\Models\PivotProduction as PivotProductionModel;
use Redirect;
2023-09-30 21:55:49 +00:00
use Carbon\Carbon;
2023-09-17 19:12:00 +00:00
use Flash;
2023-10-02 22:15:33 +00:00
use DB;
2023-10-10 22:29:27 +00:00
use October\Rain\Support\Facades\Flash as FacadesFlash;
2023-10-18 21:12:32 +00:00
use Romanah\Gokbakja\Controllers\Excruiter;
2023-09-17 19:12:00 +00:00
class Production extends ComponentBase
{
public function componentDetails()
{
return [
'name' => 'Production',
'description' => 'productions settings'
];
}
2023-10-02 22:15:33 +00:00
2023-10-10 22:29:27 +00:00
public function onReportProduction()
{
2023-11-19 19:59:08 +00:00
$currentDate = Carbon::now();
2023-10-10 22:29:27 +00:00
$currentDateFormat = $currentDate->format('Y-m-d');
$data = post();
$productions = ProductionModel::with(['pivot_production', 'excruiter', 'shift'])->orderBy('id', 'DESC');
2023-10-11 16:29:51 +00:00
$productionsCalc = ProductionModel::orderBy('id', 'DESC');
2023-10-10 22:29:27 +00:00
2023-10-19 21:07:33 +00:00
$productionsCalcPivot = ProductionCalculateModel::orderBy('id', 'DESC');
2023-10-10 22:29:27 +00:00
$start = Carbon::parse($data["start"])->format('Y-m-d');
$end = Carbon::parse($data["end"])->format('Y-m-d');
2023-10-11 22:11:21 +00:00
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');
2023-10-10 22:29:27 +00:00
2023-10-11 22:11:21 +00:00
$excruiter = $data["excruiter_id"];
$shiftId = $data["shift_id"];
2023-10-10 22:29:27 +00:00
2023-10-11 22:11:21 +00:00
if ($excruiter) {
$productions->where("excruiter_id", $excruiter);
$productionsCalc->where("excruiter_id", $excruiter);
2023-10-19 21:07:33 +00:00
$productionsCalcPivot->where("excruiter_id", $excruiter);
2023-10-11 22:11:21 +00:00
}
2023-10-10 22:29:27 +00:00
2023-10-11 22:11:21 +00:00
if ($shiftId) {
$productions->where("shift_id", $shiftId);
$productionsCalc->where("shift_id", $shiftId);
2023-10-19 21:07:33 +00:00
$productionsCalcPivot->where("shift_id", $shiftId);
2023-10-11 22:11:21 +00:00
}
if ($start != $currentDateFormat) {
2023-10-19 21:07:33 +00:00
$productions->whereBetween('date', [$start, $end]);
2023-10-11 16:29:51 +00:00
2023-10-19 21:07:33 +00:00
$calc = $productionsCalc->select(DB::raw('MAX(time) AS max_time'), DB::raw('MIN(time) AS min_time'))
->whereBetween('date', [$start, $end])->first();
2023-10-11 16:29:51 +00:00
2023-10-11 22:11:21 +00:00
$diffMinutes = Carbon::parse($calc->max_time)->diffInMinutes($calc->min_time);
$calcTimeDiff = floor($diffMinutes / 60) . ' sagat ' . ($diffMinutes - floor($diffMinutes / 60) * 60) . ' minut';
2023-10-19 21:07:33 +00:00
$productionsCalcPivot->whereBetween('date', [$start, $end]);
2023-10-11 22:11:21 +00:00
// dd($max);
// $min = $productions->select(DB::raw("MIN(id)"));
2023-10-11 16:29:51 +00:00
2023-10-11 22:11:21 +00:00
}
2023-10-10 22:29:27 +00:00
2023-10-11 22:11:21 +00:00
$productionsFiltered = $productions->get();
2023-10-19 21:07:33 +00:00
$calculationAmount = $productionsCalcPivot->sum("amount_calc");
2023-10-10 22:29:27 +00:00
2023-10-19 21:07:33 +00:00
//dd($calculationAmount);
2023-10-11 16:29:51 +00:00
2023-10-11 22:11:21 +00:00
$html_data = '';
for ($x = 0; $x < count($productionsFiltered); $x++) {
2023-10-23 22:37:45 +00:00
$date = "";
if($productionsFiltered[$x]->date != null){
$date = Carbon::parse($productionsFiltered[$x]->date)->format('d.m.Y').' | '.Carbon::parse($productionsFiltered[$x]->time)->format('H:i');
}else{
$date = "";
}
2023-10-11 22:11:21 +00:00
// dd($productionsFiltered[0]->shift->desc);
$html_data .= '<tr>
<td style="font-weight: bold;width: 5%;">' . ($x + 1) . '</td>
2023-10-23 22:37:45 +00:00
<td><a href="#" style="font-weight: bold;color: #0005c5;">' . $date . '</a></td>
2023-10-11 22:11:21 +00:00
<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>';
2023-10-10 22:29:27 +00:00
for ($i = 0; $i < count($productionsFiltered[$x]->pivot_production); $i++) {
2023-11-26 12:04:31 +00:00
$html_data .= '<td> <a href="#">' . number_format($productionsFiltered[$x]->pivot_production[$i]->amount_percentage, 2) . '% </a></td>';
2023-10-10 22:29:27 +00:00
}
2023-10-11 22:11:21 +00:00
$html_data .= '<td style="font-weight: bold;color: #0005c5;">' . $productionsFiltered[$x]->note . '</td>
</tr>';
}
2023-10-10 22:29:27 +00:00
2023-10-11 22:11:21 +00:00
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>
2023-10-11 16:29:51 +00:00
</div>
</div>
2023-10-11 22:11:21 +00:00
<div class="col-md-4">
<div class="card bg-info text-white-50">
<div class="card-body">
2023-10-19 21:07:33 +00:00
<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($calculationAmount) . ' kg</h5>
2023-10-11 22:11:21 +00:00
</div>
2023-10-11 16:29:51 +00:00
</div>
</div>
2023-10-11 22:11:21 +00:00
'
];
} else {
Flash::error("Yalnyshlyk bar!!");
}
2023-10-10 22:29:27 +00:00
}
}
2023-10-02 22:15:33 +00:00
public function onCalculateReportDaily()
{
2023-11-19 19:59:08 +00:00
$currentDate = Carbon::now();
2023-10-02 22:15:33 +00:00
$currentDateFormat = $currentDate->format('Y-m-d');
$data = post();
$excruiter = $this->param("excruiter");
2023-10-18 21:12:32 +00:00
$currentExcrutier = ExcruiterModel::where("id", $excruiter)->first();
2023-10-02 22:15:33 +00:00
2023-10-11 16:29:51 +00:00
$productionsCalc = ProductionModel::orderBy('id', 'DESC');
2023-10-18 21:12:32 +00:00
$calc = $productionsCalc->select(DB::raw('MAX(time) AS max_time'), DB::raw('MIN(time) AS min_time'))
->whereDate('date', date($currentDateFormat))->where('excruiter_id', $excruiter)->first();
2023-10-11 16:29:51 +00:00
$diffMinutes = Carbon::parse($calc->max_time)->diffInMinutes($calc->min_time);
2023-10-18 21:12:32 +00:00
$timeCalc = floor($diffMinutes / 60) . ' sagat ' . ($diffMinutes - floor($diffMinutes / 60) * 60) . ' minut';
2023-10-02 22:15:33 +00:00
2023-10-18 21:12:32 +00:00
$countDailyChanges = ProductionModel::whereDate('date', date($currentDateFormat))->where('excruiter_id', $excruiter)->get();
2023-10-02 22:15:33 +00:00
2023-10-18 21:12:32 +00:00
$products = ProductModel::where('report', 'simple')->get();
// dd(count($countDailyChanges));
2023-11-19 19:59:08 +00:00
$dailyCalculated = ProductionCalculateModel::whereDate("date", date($currentDateFormat))->where("excruiter_id", $excruiter)->sum("amount_calc");
2023-10-02 22:15:33 +00:00
2023-11-19 19:59:08 +00:00
if ((count($countDailyChanges) > 0) && ($dailyCalculated)) {
2023-10-02 22:15:33 +00:00
2023-10-18 21:12:32 +00:00
$dailyCalculated = ProductionCalculateModel::whereDate("date", date($currentDateFormat))->where("excruiter_id", $excruiter)->sum("amount_calc");
2023-10-02 22:15:33 +00:00
2023-10-18 21:12:32 +00:00
//sagatda ortacaha hasaplama
2023-10-19 21:07:33 +00:00
$html_data2 = '';
2023-10-10 22:29:27 +00:00
// gunluk hasabat
$html_data = '<div class="row">';
2023-11-19 19:59:08 +00:00
$html_data .= '<h4 style="margin-top: 20px;margin-bottom: 20px;">JEMI IŞLENEN ÇIG MAL (ekstrudor: ' . $currentExcrutier->name . ')</h4>';
2023-10-10 22:29:27 +00:00
2023-11-19 19:59:08 +00:00
$html_data .= '<div class="col-md-2">
2023-10-02 22:15:33 +00:00
<a class="card bg-success text-white-50">
<div class="card-body">
<h5 class="mb-4 text-white"><i
2023-10-19 21:07:33 +00:00
class="mdi mdi-bullseye-arrow me-3"></i>' . $timeCalc . '</h5>
2023-10-02 22:15:33 +00:00
<hr>
2023-10-18 21:12:32 +00:00
<p class="card-text" style="font-size: 15px;color: white;">JEMI IŞLENEN: ' . $dailyCalculated . ' kg</p>
2023-10-02 22:15:33 +00:00
</div>
</a>
</div>';
2023-10-10 22:29:27 +00:00
2023-10-18 21:12:32 +00:00
//sagatda ortacaha hasaplama
$html_data2 .= '<div class="row">';
2023-11-19 19:59:08 +00:00
$html_data2 .= '<h4 style="margin-top: 20px;margin-bottom: 20px;">SAGATDA ORTAÇA (ekstrudor: ' . $currentExcrutier->name . ')</h4>';
2023-10-10 22:29:27 +00:00
2023-11-19 19:59:08 +00:00
$html_data2 .= '<div class="col-md-2">
2023-10-10 22:29:27 +00:00
<a class="card bg-success text-white-50">
<div class="card-body">
<h5 class="mb-4 text-white"><i
2023-10-19 21:07:33 +00:00
class="mdi mdi-bullseye-arrow me-3"></i>' . $timeCalc . '</h5>
2023-10-10 22:29:27 +00:00
<hr>
2023-10-18 21:12:32 +00:00
<p class="card-text" style="font-size: 15px;color: white;">SAGATDA ORTAÇA: ' . number_format($dailyCalculated / floor($diffMinutes / 60), 2) . ' kg</p>
2023-10-10 22:29:27 +00:00
</div>
</a>
</div>';
2023-10-02 22:15:33 +00:00
2023-10-18 21:12:32 +00:00
for ($x = 0; $x < count($products); $x++) {
$productCalc = ProductionCalculateModel::whereDate('date', date($currentDateFormat))->where('excruiter_id', $excruiter)->where("product_id", $products[$x]->id)->sum('amount_calc');
$productCalcPercentage = ProductionCalculateModel::whereDate('date', date($currentDateFormat))->where('excruiter_id', $excruiter)->where("product_id", $products[$x]->id)->orderBy('id', 'DESC')->first();
2023-10-10 22:29:27 +00:00
// $diff = $pivotLasts[$x]->amount - $pivotFirsts[$x]->amount;
// $diffPerc = ($diff * 100) / $producedAll;
2023-11-19 19:59:08 +00:00
$html_data .= '<div class="col-md-2">
2023-10-10 22:29:27 +00:00
<a class="card bg-info text-white-50">
<div class="card-body">
2023-11-19 19:59:08 +00:00
<h5 class="mb-4 text-white"><i class="mdi mdi-bullseye-arrow me-3"></i>' . (number_format($productCalc, 2)) . ' kg</h5>
2023-10-10 22:29:27 +00:00
<hr>
2023-11-19 19:59:08 +00:00
<p class="card-text" style="font-size: 15px;color: white;">' . $products[$x]->code . ' : ' . ($productCalcPercentage->amount_percentage) . ' %</p>
2023-10-10 22:29:27 +00:00
</div>
</a>
</div>';
2023-11-19 19:59:08 +00:00
$html_data2 .= '<div class="col-md-2">
2023-10-18 21:12:32 +00:00
<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>' . number_format($productCalc / floor($diffMinutes / 60), 2) . ' kg</h5>
<hr>
2023-11-19 19:59:08 +00:00
<p class="card-text" style="font-size: 15px;color: white;">' . $products[$x]->code . ' : ' . ($productCalcPercentage->amount_percentage) . ' %</p>
2023-10-18 21:12:32 +00:00
</div>
</a>
</div>';
}
2023-10-11 16:29:51 +00:00
2023-10-18 21:12:32 +00:00
$html_data .= '</div>';
$html_data2 .= '</div>';
2023-10-10 22:29:27 +00:00
2023-10-18 21:12:32 +00:00
//ekstrudorlar b-ca
$excruiters = ExcruiterModel::get();
2023-10-11 16:29:51 +00:00
2023-10-18 21:12:32 +00:00
$html_data3 = '<div class="row">';
2023-10-11 16:29:51 +00:00
2023-10-18 21:12:32 +00:00
for ($x = 0; $x < count($excruiters); $x++) {
2023-10-11 16:29:51 +00:00
$productionsCalc = ProductionModel::orderBy('id', 'DESC');
2023-10-18 21:12:32 +00:00
$calc = $productionsCalc->select(DB::raw('MAX(time) AS max_time'), DB::raw('MIN(time) AS min_time'))
->whereDate('date', date($currentDateFormat))->where('excruiter_id', $excruiters[$x]->id)->first();
2023-10-11 16:29:51 +00:00
2023-10-18 21:12:32 +00:00
$diffMinutes = Carbon::parse($calc->max_time)->diffInMinutes($calc->min_time);
2023-10-11 16:29:51 +00:00
2023-10-18 21:12:32 +00:00
$timeCalc = floor($diffMinutes / 60) . ' sagat ' . ($diffMinutes - floor($diffMinutes / 60) * 60) . ' minut';
2023-10-10 22:29:27 +00:00
2023-10-18 21:12:32 +00:00
$productCalc = ProductionCalculateModel::whereDate('date', date($currentDateFormat))->where('excruiter_id', $excruiters[$x]->id)->sum('amount_calc');
2023-10-10 22:29:27 +00:00
2023-11-19 19:59:08 +00:00
$html_data3 .= '<h4 style="margin-top: 20px;margin-bottom: 20px;">JEMI IŞLENEN ÇIG MAL (ekstrudor: ' . $excruiters[$x]->name . ')</h4>';
2023-10-10 22:29:27 +00:00
2023-11-19 19:59:08 +00:00
$html_data3 .= '<div class="col-md-2">
2023-10-18 21:12:32 +00:00
<a class="card bg-success text-white-50">
<div class="card-body">
<h5 class="mb-4 text-white"><i
2023-10-19 21:07:33 +00:00
class="mdi mdi-bullseye-arrow me-3"></i>' . $timeCalc . '</h5>
2023-10-18 21:12:32 +00:00
<hr>
2023-11-19 19:59:08 +00:00
<p class="card-text" style="font-size: 15px;color: white;">JEMI IŞLENEN: ' . number_format($dailyCalculated, 2) . ' kg</p>
2023-10-18 21:12:32 +00:00
</div>
</a>
</div>';
2023-10-10 22:29:27 +00:00
2023-10-18 21:12:32 +00:00
for ($i = 0; $i < count($products); $i++) {
2023-10-10 22:29:27 +00:00
2023-10-18 21:12:32 +00:00
$productCalc = ProductionCalculateModel::whereDate('date', date($currentDateFormat))->where('excruiter_id', $excruiters[$x]->id)->where("product_id", $products[$i]->id)->sum('amount_calc');
2023-10-10 22:29:27 +00:00
2023-10-18 21:12:32 +00:00
$productCalcPercentage = ProductionCalculateModel::whereDate('date', date($currentDateFormat))->where('excruiter_id', $excruiters[$x]->id)->where("product_id", $products[$i]->id)->orderBy('id', 'DESC')->first();
2023-10-11 16:29:51 +00:00
2023-11-19 19:59:08 +00:00
$html_data3 .= '<div class="col-md-2">
2023-10-18 21:12:32 +00:00
<a class="card bg-info text-white-50">
<div class="card-body">
2023-11-19 19:59:08 +00:00
<h5 class="mb-4 text-white"><i class="mdi mdi-bullseye-arrow me-3"></i>' . (number_format($productCalc, 2)) . ' kg</h5>
2023-10-18 21:12:32 +00:00
<hr>
2023-11-19 19:59:08 +00:00
<p class="card-text" style="font-size: 15px;color: white;">' . $products[$i]->code . ' : ' . ($productCalcPercentage->amount_percentage ?? 0) . ' %</p>
2023-10-18 21:12:32 +00:00
</div>
</a>
</div>';
}
}
$html_data3 .= '</div>';
2023-10-11 16:29:51 +00:00
2023-10-10 22:29:27 +00:00
2023-10-18 21:12:32 +00:00
//smenlar boyuncha
$shifts = ShiftModel::get();
2023-10-10 22:29:27 +00:00
$html_data4 = '<h4 style="margin-top: 20px;margin-bottom: 20px;">SMENLAR BOÝUNÇA</h4>';
2023-10-18 21:12:32 +00:00
2023-10-10 22:29:27 +00:00
$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>Wagty</th>
2023-10-18 21:12:32 +00:00
<th>Jemi</th>';
2023-10-10 22:29:27 +00:00
$html_data4 .= '</tr>
</thead><tbody>';
2023-10-18 21:12:32 +00:00
$sumTimeDiffs = 0;
$productAllCalc = 0;
2023-10-10 22:29:27 +00:00
2023-10-18 21:12:32 +00:00
for ($i = 0; $i < count($shifts); $i++) {
2023-10-10 22:29:27 +00:00
2023-10-18 21:12:32 +00:00
$productionsCalc = ProductionModel::orderBy('id', 'DESC');
$calc = $productionsCalc->select(DB::raw('MAX(time) AS max_time'), DB::raw('MIN(time) AS min_time'))
->whereDate('date', date($currentDateFormat))->where('shift_id', $shifts[$i]->id)->first();
2023-10-10 22:29:27 +00:00
2023-10-11 16:29:51 +00:00
$diffMinutes = Carbon::parse($calc->max_time)->diffInMinutes($calc->min_time);
2023-10-10 22:29:27 +00:00
2023-10-18 21:12:32 +00:00
$sumTimeDiffs += $diffMinutes;
2023-10-10 22:29:27 +00:00
2023-10-18 21:12:32 +00:00
$timeCalc = floor($diffMinutes / 60) . ' sagat ' . ($diffMinutes - floor($diffMinutes / 60) * 60) . ' minut';
2023-10-10 22:29:27 +00:00
2023-10-18 21:12:32 +00:00
$productCalc = ProductionCalculateModel::whereDate('date', date($currentDateFormat))->where('shift_id', $shifts[$i]->id)->sum('amount_calc');
2023-10-10 22:29:27 +00:00
2023-10-18 21:12:32 +00:00
$productAllCalc += $productCalc;
2023-10-10 22:29:27 +00:00
2023-10-18 21:12:32 +00:00
$html_data4 .= '<tr>
<th scope="row">' . ($i + 1) . '</th>
<td style="font-weight: bold;color: #0005c5;">' . $shifts[$i]->desc . '(' . $shifts[$i]->start . ' - ' . $shifts[$i]->end . ')</td>
2023-10-19 21:07:33 +00:00
<td>' . $timeCalc . '</td>
2023-10-10 22:29:27 +00:00
2023-10-18 21:12:32 +00:00
<td>' . $productCalc . ' kg</td>';
2023-10-10 22:29:27 +00:00
$html_data4 .= '</tr>';
}
2023-10-18 21:12:32 +00:00
$timeAllCalc = floor($sumTimeDiffs / 60) . ' sagat ' . ($sumTimeDiffs - floor($sumTimeDiffs / 60) * 60) . ' minut';
$html_data4 .= '<tr>
<th scope="row" colspan="2">JEMI</th>
2023-10-19 21:07:33 +00:00
<td>' . $timeAllCalc . '</td>
2023-10-11 16:29:51 +00:00
2023-10-18 21:12:32 +00:00
<td>' . $productAllCalc . ' kg</td>';
$html_data4 .= '</tr>';
2023-10-10 22:29:27 +00:00
$html_data4 .= ' </tbody>
</table></div></div></div>';
2023-10-18 21:12:32 +00:00
2023-10-10 22:29:27 +00:00
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!'
];
}
2023-10-02 22:15:33 +00:00
}
function onCalculateAvg()
{
2023-11-19 19:59:08 +00:00
$currentDate = Carbon::now();
2023-09-30 21:55:49 +00:00
$currentDateFormat = $currentDate->format('Y-m-d');
2023-10-19 21:07:33 +00:00
$excruiter = $this->param("excruiter");
2023-09-30 21:55:49 +00:00
$data = post();
2023-10-19 21:07:33 +00:00
$enteredDate = Carbon::parse($data["date"])->format('Y-m-d');
2023-09-23 20:10:26 +00:00
2023-10-19 21:07:33 +00:00
$todayProductionsCount = ProductionModel::whereDate('date', date($enteredDate))->where("excruiter_id", $excruiter)->count();
2023-09-30 21:55:49 +00:00
2023-11-19 19:59:08 +00:00
if ($todayProductionsCount > 0) {
2023-10-02 22:15:33 +00:00
2023-10-19 21:07:33 +00:00
$todayProductionsGet = ProductionModel::whereDate('date', date($enteredDate))->where("excruiter_id", $excruiter)->orderBy("id", "DESC")->first();
2023-09-30 21:55:49 +00:00
2023-10-19 21:07:33 +00:00
$productionPivot = PivotProductionModel::where('production_id', $todayProductionsGet->id)->where("product_id", $data["prod_id"])->first();
2023-10-02 22:15:33 +00:00
2023-11-19 19:59:08 +00:00
if(!$productionPivot){
$amountPERC = 0;
}else{
$amountPERC = $productionPivot->amount_percentage;
}
$diffAllAMount = ((float) $data["all_amount"] - (float) $todayProductionsGet->all_amount) ?? 0;
2023-10-02 22:15:33 +00:00
2023-10-19 21:07:33 +00:00
$calculatedAmount = (float)(((float) $data["field_value"] ?? 0) / 100) * ((float) $diffAllAMount);
2023-10-02 22:15:33 +00:00
$allData = array(
2023-11-19 19:59:08 +00:00
"product_name" => $productionPivot->product_code ?? "Haryt yok",
"avg_percentage" => number_format($amountPERC, 2),
2023-10-19 21:07:33 +00:00
"avg_amount" => number_format($calculatedAmount, 2),
"headerq" => "Çig Mallar Boýunça (Soňky üýtgeşme: " . $diffAllAMount . " kg)"
2023-10-02 22:15:33 +00:00
);
} else {
$allData = array(
2023-10-19 21:07:33 +00:00
// "product_name" => $productionPivot->product_name,
2023-10-02 22:15:33 +00:00
"avg_percentage" => number_format(0, 2),
"avg_amount" => number_format(0, 2)
);
}
2023-09-30 21:55:49 +00:00
return $allData;
2023-09-23 20:10:26 +00:00
}
2023-09-17 19:12:00 +00:00
2023-10-19 21:07:33 +00:00
2023-10-02 22:15:33 +00:00
public function onUpdatePivotProduction()
2023-09-17 19:12:00 +00:00
{
$user = \Auth::user();
2023-11-19 19:59:08 +00:00
$currentDate = Carbon::now();
2023-09-30 21:55:49 +00:00
// $this["currentMonth"] = $currentDate->format('m');
2023-10-02 22:15:33 +00:00
$data = post();
2023-09-30 21:55:49 +00:00
2023-10-19 21:07:33 +00:00
// dd($data);
2023-10-02 22:15:33 +00:00
$updatePivotProduction = PivotProductionModel::where("id", $data["product_id"])->first();
2023-09-30 21:55:49 +00:00
2023-10-02 22:15:33 +00:00
$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();
2023-09-17 19:12:00 +00:00
2023-10-19 21:07:33 +00:00
$productionCalulate = ProductionCalculateModel::where("production_id", $updatePivotProduction->production_id)->where("prev_pivot_id", $updatePivotProduction->id)->first();
// dd($production);
if ($productionCalulate != null) {
$diffCalc = (float) ((float) $productionCalulate->amount_calc * 100) / (float) $productionCalulate->amount_percentage;
$productionCalulate->amount_calc = (float)(((float) $data[$fieldName] ?? 0) / 100) * ((float) $diffCalc);
$productionCalulate->amount_percentage = (float) $data[$fieldName] ?? 0;
$productionCalulate->save();
}
2023-10-02 22:15:33 +00:00
if ($updatePivotProduction) {
Flash::success("Hasabat Ustunlikli Üýtgedildi");
return Redirect::refresh();
2023-09-18 20:22:50 +00:00
}
2023-10-02 22:15:33 +00:00
}
public function onCreateProduction()
{
$user = \Auth::user();
2023-11-19 19:59:08 +00:00
$currentDate = Carbon::now();
2023-10-02 22:15:33 +00:00
// $this["currentMonth"] = $currentDate->format('m');
$data = post();
$excruiter = $this->param("excruiter");
if ($excruiter == 0) {
2023-10-18 21:12:32 +00:00
Flash::error("Ekstrudor Saýla!");
2023-09-18 20:22:50 +00:00
return Redirect::refresh();
2023-10-02 22:15:33 +00:00
} else {
$createProduction = new ProductionModel();
$createProduction->all_amount = $data["all_amount"];
$createProduction->note = $data["note"];
$createProduction->user_id = $user->id;
2023-10-18 21:12:32 +00:00
$createProduction->date = Carbon::parse($data["date"])->format('Y-m-d');
$createProduction->time = Carbon::parse($data["time"])->format('H:i:s');
2023-10-02 22:15:33 +00:00
$createProduction->excruiter_id = $excruiter;
$createProduction->shift_id = $data["shift_id"];
$createProduction->save();
2023-11-26 12:04:31 +00:00
$products = ProductModel::where("report", "simple")->orderBy('order', 'ASC')->get();
2023-10-02 22:15:33 +00:00
for ($x = 0; $x < count($products); $x++) {
2023-11-19 19:59:08 +00:00
$fieldName = "product_" . $products[$x]->id;
2023-10-02 22:15:33 +00:00
$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);
2023-10-18 21:12:32 +00:00
$createPivotProduction->date = Carbon::parse($data["date"])->format('Y-m-d');
$createPivotProduction->time = Carbon::parse($data["time"])->format('H:i:s');
2023-10-02 22:15:33 +00:00
$createPivotProduction->save();
}
2023-10-18 21:12:32 +00:00
$todayProductionsCount = ProductionModel::whereDate('date', date($createProduction->date))->where("excruiter_id", $excruiter)->count();
2023-10-19 21:07:33 +00:00
if ($todayProductionsCount > 1) {
// $todayProductionsGetLast = ProductionModel::whereDate('date', date($createProduction->date))->where("excruiter_id", $excruiter)->orderBy("id", "DESC")->first();
2023-10-18 21:12:32 +00:00
$todayProductionsGet = ProductionModel::whereDate('date', date($createProduction->date))->where("excruiter_id", $excruiter)->orderBy("id", "DESC")->skip(1)->first();
$productionPivots = PivotProductionModel::where('production_id', $todayProductionsGet->id)->get();
$diffAllAmount = ($createProduction->all_amount - $todayProductionsGet->all_amount);
for ($x = 0; $x < count($productionPivots); $x++) {
2023-10-19 21:07:33 +00:00
$currentPivot = PivotProductionModel::where("production_id", $createProduction->id)->where("product_id", $productionPivots[$x]->product_id)->first();
2023-10-18 21:12:32 +00:00
$createCalculate = new ProductionCalculateModel();
$createCalculate->production_id = $todayProductionsGet->id;
$createCalculate->product_id = $productionPivots[$x]->product_id;
$createCalculate->amount_calc = (float)(((float) $productionPivots[$x]->amount_percentage ?? 0) / 100) * ((float) $diffAllAmount);
$createCalculate->excruiter_id = $todayProductionsGet->excruiter_id;
$createCalculate->shift_id = $todayProductionsGet->shift_id;
$createCalculate->amount_percentage = $productionPivots[$x]->amount_percentage;
2023-10-19 21:07:33 +00:00
$createCalculate->current_pivot_id = $currentPivot->id;
$createCalculate->prev_pivot_id = $productionPivots[$x]->id;
2023-10-18 21:12:32 +00:00
$createCalculate->date = $productionPivots[$x]->date;
$createCalculate->time = $productionPivots[$x]->time;
$createCalculate->save();
}
}
2023-10-02 22:15:33 +00:00
if ($createProduction && $createPivotProduction) {
Flash::success("Hasabat Ustunlikli Goşuldy");
return Redirect::refresh();
}
2023-09-18 20:22:50 +00:00
}
2023-09-17 19:12:00 +00:00
}
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();
}
2023-10-29 19:54:41 +00:00
public function onDeleteProduction()
{
$id = post('id');
$item = ProductionModel::Find($id);
$item->delete();
if ($item) {
Flash::success("Hasabat Ustunlikli Pozuldy");
return Redirect::refresh();
}
}
2023-09-17 19:12:00 +00:00
2023-10-18 21:12:32 +00:00
2023-09-17 19:12:00 +00:00
}