This commit is contained in:
Shohrat 2023-10-01 02:55:49 +05:00
parent e41b01863f
commit 427d61c66c
21 changed files with 482 additions and 19 deletions

View File

@ -8,6 +8,7 @@ use Romanah\Gokbakja\Models\Production as ProductionModel;
use Romanah\Gokbakja\Models\ProductionMachine as ProductionMachineModel;
use Romanah\Gokbakja\Models\PivotProduction as PivotProductionModel;
use Redirect;
use Carbon\Carbon;
use Flash;
class Production extends ComponentBase
@ -40,28 +41,63 @@ class Production extends ComponentBase
$productionMachine = ProductionMachineModel::where('id', $createProductionMachine->id)->with(['machine.employee', 'machine.mechanic', 'machine.building'])->first();
// dd($productionMachine->machine->name);
if($productionMachine){
if ($productionMachine) {
$updateResult = ProductionMachineModel::where('id', $productionMachine->id)
->update(array(
'employee_id' => $productionMachine->machine->employee->id,
'mechanic_id' => $productionMachine->machine->mechanic->id,
'employee_name' => $productionMachine->machine->employee->name,
'mechanic_name' => $productionMachine->machine->mechanic->name,
'building_name' => $productionMachine->machine->building->name,
));
->update(array(
'employee_id' => $productionMachine->machine->employee->id,
'mechanic_id' => $productionMachine->machine->mechanic->id,
'employee_name' => $productionMachine->machine->employee->name,
'mechanic_name' => $productionMachine->machine->mechanic->name,
'building_name' => $productionMachine->machine->building->name,
));
}
if ($createProductionMachine && $updateResult) {
Flash::success("Hasabat Ustunlikli Goşuldy");
return Redirect::refresh();
}
}
function onCalculateAvg(){
$currentDate = Carbon::now()->timezone('UTC +05:00');
$currentDateFormat = $currentDate->format('Y-m-d');
$data = post();
$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));
$calcAvgPerc = ($sumPercentage + (int) $data["field_value"]) / ($sumPercentageCount + 1);
// $calcAvgAmount = ($sumPercentage + (int) $data["field_value"]) / ($sumPercentageCount + 1);
$allData = array(
"avg_percentage" => $calcAvgPerc,
"avg_amount" => '000'
);
return $allData;
// dd($currentDateFormat);
}
public function onCreateProduction()
{
$user = \Auth::user();
$currentDate = Carbon::now()->timezone('UTC +05:00');
// $this["currentMonth"] = $currentDate->format('m');
$data = post();
$createProduction = new ProductionModel();
@ -69,12 +105,15 @@ class Production extends ComponentBase
$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 = 1;
$createProduction->save();
$products = ProductModel::where("report", "simple")->get();
for ($x = 0; $x < count($products); $x++) {
$fieldName = "product_".$products[$x]->code;
$fieldName = "product_" . $products[$x]->code;
$createPivotProduction = new PivotProductionModel();
$createPivotProduction->production_id = $createProduction->id;
@ -90,7 +129,6 @@ class Production extends ComponentBase
Flash::success("Hasabat Ustunlikli Goşuldy");
return Redirect::refresh();
}
}
public function onUpdateProduction()

View File

@ -0,0 +1,18 @@
<?php namespace Romanah\Gokbakja\Controllers;
use Backend\Classes\Controller;
use BackendMenu;
class Excruiter extends Controller
{
public $implement = [ 'Backend\Behaviors\ListController', 'Backend\Behaviors\FormController' ];
public $listConfig = 'config_list.yaml';
public $formConfig = 'config_form.yaml';
public function __construct()
{
parent::__construct();
BackendMenu::setContext('Romanah.Gokbakja', 'main-menu-item6', 'side-menu-item2');
}
}

View File

@ -0,0 +1,18 @@
<div data-control="toolbar">
<a href="<?= Backend::url('romanah/gokbakja/excruiter/create') ?>" class="btn btn-primary oc-icon-plus"><?= e(trans('backend::lang.form.create')) ?></a>
<button
class="btn btn-default oc-icon-trash-o"
disabled="disabled"
onclick="$(this).data('request-data', {
checked: $('.control-list').listWidget('getChecked')
})"
data-request="onDelete"
data-request-confirm="<?= e(trans('backend::lang.list.delete_selected_confirm')) ?>"
data-trigger-action="enable"
data-trigger=".control-list input[type=checkbox]"
data-trigger-condition="checked"
data-request-success="$(this).prop('disabled', true)"
data-stripe-load-indicator>
<?= e(trans('backend::lang.list.delete_selected')) ?>
</button>
</div>

View File

@ -0,0 +1,10 @@
name: Excruiter
form: $/romanah/gokbakja/models/excruiter/fields.yaml
modelClass: Romanah\Gokbakja\Models\Excruiter
defaultRedirect: romanah/gokbakja/excruiter
create:
redirect: 'romanah/gokbakja/excruiter/update/:id'
redirectClose: romanah/gokbakja/excruiter
update:
redirect: romanah/gokbakja/excruiter
redirectClose: romanah/gokbakja/excruiter

View File

@ -0,0 +1,12 @@
list: $/romanah/gokbakja/models/excruiter/columns.yaml
modelClass: Romanah\Gokbakja\Models\Excruiter
title: Excruiter
noRecordsMessage: 'backend::lang.list.no_records'
showSetup: true
showCheckboxes: true
recordsPerPage: 20
toolbar:
buttons: list_toolbar
search:
prompt: 'backend::lang.list.search_prompt'
recordUrl: 'romanah/gokbakja/excruiter/update/:id'

View File

@ -0,0 +1,46 @@
<?php Block::put('breadcrumb') ?>
<ul>
<li><a href="<?= Backend::url('romanah/gokbakja/excruiter') ?>">Excruiter</a></li>
<li><?= e($this->pageTitle) ?></li>
</ul>
<?php Block::endPut() ?>
<?php if (!$this->fatalError): ?>
<?= Form::open(['class' => 'layout']) ?>
<div class="layout-row">
<?= $this->formRender() ?>
</div>
<div class="form-buttons">
<div class="loading-indicator-container">
<button
type="submit"
data-request="onSave"
data-hotkey="ctrl+s, cmd+s"
data-load-indicator="<?= e(trans('backend::lang.form.saving')) ?>"
class="btn btn-primary">
<?= e(trans('backend::lang.form.create')) ?>
</button>
<button
type="button"
data-request="onSave"
data-request-data="close:1"
data-hotkey="ctrl+enter, cmd+enter"
data-load-indicator="<?= e(trans('backend::lang.form.saving')) ?>"
class="btn btn-default">
<?= e(trans('backend::lang.form.create_and_close')) ?>
</button>
<span class="btn-text">
<?= e(trans('backend::lang.form.or')) ?> <a href="<?= Backend::url('romanah/gokbakja/excruiter') ?>"><?= e(trans('backend::lang.form.cancel')) ?></a>
</span>
</div>
</div>
<?= Form::close() ?>
<?php else: ?>
<p class="flash-message static error"><?= e(trans($this->fatalError)) ?></p>
<p><a href="<?= Backend::url('romanah/gokbakja/excruiter') ?>" class="btn btn-default"><?= e(trans('backend::lang.form.return_to_list')) ?></a></p>
<?php endif ?>

View File

@ -0,0 +1 @@
<?= $this->listRender() ?>

View File

@ -0,0 +1,22 @@
<?php Block::put('breadcrumb') ?>
<ul>
<li><a href="<?= Backend::url('romanah/gokbakja/excruiter') ?>">Excruiter</a></li>
<li><?= e($this->pageTitle) ?></li>
</ul>
<?php Block::endPut() ?>
<?php if (!$this->fatalError): ?>
<div class="form-preview">
<?= $this->formRenderPreview() ?>
</div>
<?php else: ?>
<p class="flash-message static error"><?= e($this->fatalError) ?></p>
<?php endif ?>
<p>
<a href="<?= Backend::url('romanah/gokbakja/excruiter') ?>" class="btn btn-default oc-icon-chevron-left">
<?= e(trans('backend::lang.form.return_to_list')) ?>
</a>
</p>

View File

@ -0,0 +1,54 @@
<?php Block::put('breadcrumb') ?>
<ul>
<li><a href="<?= Backend::url('romanah/gokbakja/excruiter') ?>">Excruiter</a></li>
<li><?= e($this->pageTitle) ?></li>
</ul>
<?php Block::endPut() ?>
<?php if (!$this->fatalError): ?>
<?= Form::open(['class' => 'layout']) ?>
<div class="layout-row">
<?= $this->formRender() ?>
</div>
<div class="form-buttons">
<div class="loading-indicator-container">
<button
type="submit"
data-request="onSave"
data-request-data="redirect:0"
data-hotkey="ctrl+s, cmd+s"
data-load-indicator="<?= e(trans('backend::lang.form.saving')) ?>"
class="btn btn-primary">
<?= e(trans('backend::lang.form.save')) ?>
</button>
<button
type="button"
data-request="onSave"
data-request-data="close:1"
data-hotkey="ctrl+enter, cmd+enter"
data-load-indicator="<?= e(trans('backend::lang.form.saving')) ?>"
class="btn btn-default">
<?= e(trans('backend::lang.form.save_and_close')) ?>
</button>
<button
type="button"
class="oc-icon-trash-o btn-icon danger pull-right"
data-request="onDelete"
data-load-indicator="<?= e(trans('backend::lang.form.deleting')) ?>"
data-request-confirm="<?= e(trans('backend::lang.form.confirm_delete')) ?>">
</button>
<span class="btn-text">
<?= e(trans('backend::lang.form.or')) ?> <a href="<?= Backend::url('romanah/gokbakja/excruiter') ?>"><?= e(trans('backend::lang.form.cancel')) ?></a>
</span>
</div>
</div>
<?= Form::close() ?>
<?php else: ?>
<p class="flash-message static error"><?= e(trans($this->fatalError)) ?></p>
<p><a href="<?= Backend::url('romanah/gokbakja/excruiter') ?>" class="btn btn-default"><?= e(trans('backend::lang.form.return_to_list')) ?></a></p>
<?php endif ?>

View File

@ -0,0 +1,33 @@
<?php namespace Romanah\Gokbakja\Models;
use Model;
/**
* Model
*/
class Excruiter extends Model
{
use \October\Rain\Database\Traits\Validation;
use \October\Rain\Database\Traits\SoftDelete;
protected $dates = ['deleted_at'];
public $hasMany = [
'production' => [
'Romanah\Gokbakja\Models\Production',
'key' => 'excruiter_id'
]
];
/**
* @var string The database table used by the model.
*/
public $table = 'romanah_gokbakja_excruiter';
/**
* @var array Validation rules
*/
public $rules = [
];
}

View File

@ -21,6 +21,13 @@ class Production extends Model
]
];
public $belongsTo = [
'excruiter' => [
'Romanah\Gokbakja\Models\Excruiter',
'key' => 'excruiter_id'
]
];
public function scopeGetByGroup($query)
{
return $query->select('id', 'created_at', 'all_amount', 'note', DB::raw('count(id) as `data`'), DB::raw("DATE_FORMAT(created_at, '%d-%m-%Y') new_date"), DB::raw('YEAR(created_at) year, MONTH(created_at) month, DAY(created_at) day'))

View File

@ -0,0 +1,10 @@
columns:
id:
label: id
type: number
name:
label: name
type: text
note:
label: note
type: text

View File

@ -0,0 +1,9 @@
fields:
name:
label: Name
span: auto
type: text
note:
label: Note
span: auto
type: textarea

View File

@ -11,3 +11,8 @@ columns:
note:
label: note
type: text
excruiter_id:
label: Ekskruiter
type: text
select: name
relation: excruiter

View File

@ -5,9 +5,21 @@ fields:
type: number
date:
label: Date
mode: date
span: auto
type: datepicker
note:
label: Note
span: auto
type: textarea
time:
label: Time
mode: time
span: auto
type: datepicker
excruiter:
label: Ekskruiter
span: auto
nameFrom: name
descriptionFrom: description
type: relation

View File

@ -65,3 +65,7 @@ navigation:
label: Enjamlar
url: romanah/gokbakja/machine
icon: icon-codepen
side-menu-item2:
label: Eksruiterler
url: romanah/gokbakja/excruiter
icon: icon-steam

View File

@ -0,0 +1,26 @@
<?php namespace Romanah\Gokbakja\Updates;
use Schema;
use October\Rain\Database\Updates\Migration;
class BuilderTableCreateRomanahGokbakjaExcruiter extends Migration
{
public function up()
{
Schema::create('romanah_gokbakja_excruiter', function($table)
{
$table->engine = 'InnoDB';
$table->increments('id')->unsigned();
$table->timestamp('created_at')->nullable();
$table->timestamp('updated_at')->nullable();
$table->timestamp('deleted_at')->nullable();
$table->text('name')->nullable();
$table->text('note')->nullable();
});
}
public function down()
{
Schema::dropIfExists('romanah_gokbakja_excruiter');
}
}

View File

@ -0,0 +1,25 @@
<?php namespace Romanah\Gokbakja\Updates;
use Schema;
use October\Rain\Database\Updates\Migration;
class BuilderTableUpdateRomanahGokbakjaProduction5 extends Migration
{
public function up()
{
Schema::table('romanah_gokbakja_production', function($table)
{
$table->time('time');
$table->date('date')->nullable()->unsigned(false)->default(null)->comment(null)->change();
});
}
public function down()
{
Schema::table('romanah_gokbakja_production', function($table)
{
$table->dropColumn('time');
$table->dateTime('date')->nullable()->unsigned(false)->default(null)->comment(null)->change();
});
}
}

View File

@ -0,0 +1,23 @@
<?php namespace Romanah\Gokbakja\Updates;
use Schema;
use October\Rain\Database\Updates\Migration;
class BuilderTableUpdateRomanahGokbakjaProduction6 extends Migration
{
public function up()
{
Schema::table('romanah_gokbakja_production', function($table)
{
$table->integer('excruiter_id');
});
}
public function down()
{
Schema::table('romanah_gokbakja_production', function($table)
{
$table->dropColumn('excruiter_id');
});
}
}

View File

@ -111,3 +111,12 @@
1.0.38:
- 'Updated table romanah_gokbakja_production_machine'
- builder_table_update_romanah_gokbakja_production_machine_4.php
1.0.39:
- 'Updated table romanah_gokbakja_production'
- builder_table_update_romanah_gokbakja_production_5.php
1.0.40:
- 'Created table romanah_gokbakja_excruiter'
- builder_table_create_romanah_gokbakja_excruiter.php
1.0.41:
- 'Updated table romanah_gokbakja_production'
- builder_table_update_romanah_gokbakja_production_6.php

View File

@ -26,7 +26,9 @@ function onStart(){
$this["currentMonth"] = $currentDate->format('m');
$this["currentYear"] = $currentDate->format('Y');
$this["productions"] = Romanah\Gokbakja\Models\Production::whereDate('created_at', date($currentDateFormat))->with(['pivot_production'])->get();
$this["productions"] = Romanah\Gokbakja\Models\Production::whereDate('created_at', date($currentDateFormat))->with(['pivot_production'])->orderBy('id', 'DESC')->get();
$this["productCounts"] = Romanah\Gokbakja\Models\Product::where('report', 'simple')->count();
}
?>
@ -52,7 +54,7 @@ function onStart(){
<div class="container-fluid">
<div class="row">
<div class="col-lg-6">
<!-- <div class="col-lg-4">
<a href="/all-productions/{{currentMonth}}" class="card bg-primary text-white-50">
<div class="card-body">
<h5 class="mb-4 text-white"><i class="mdi mdi-bullseye-arrow me-3"></i> HEMMESI</h5>
@ -60,14 +62,16 @@ function onStart(){
</div>
</a>
</div>
<div class="col-lg-6">
<div class="col-lg-4">
<a href="/report-production/{{currentYear}}" class="card bg-primary text-white-50">
<div class="card-body">
<h5 class="mb-4 text-white"><i class="mdi mdi-bullseye-arrow me-3"></i> ORTAÇA ÖNÜMÇILIK</h5>
<p class="card-text">Bu bölümde ortaça önümçilik boýunça hasabat.</p>
</div>
</a>
</div>
</div> -->
<!-- <div class="col-lg-4">
<div class="card bg-primary text-white-50">
<div class="card-body">
@ -79,6 +83,26 @@ function onStart(){
</div> -->
</div>
<div class="row">
<div class="col-lg">
<a class="card bg-success text-white-50">
<div class="card-body">
<h5 class="mb-4 text-white" id="percentage"><i class="mdi mdi-bullseye-arrow me-3"></i> 0 %</h5>
<p class="card-text" id="all_amount">JEMI: 0 kg</p>
</div>
</a>
</div>
{% for key, record in records %}
<div class="col-lg col-sm">
<a class="card bg-info text-white-50">
<div class="card-body">
<h5 class="mb-4 text-white" id="avg_percentage_{{record.id}}"><i class="mdi mdi-bullseye-arrow me-3"></i> 0 %</h5>
<p class="card-text" id="avg_amount_{{record.id}}">ORTAÇA: 0 kg</p>
</div>
</a>
</div>
{% endfor %}
</div>
<!-- end row -->
<div class="row">
<div class="col-md-12">
@ -99,7 +123,10 @@ function onStart(){
</div> -->
</div>
<p id="product_count" style="color: transparent;position: absolute;">{{productCounts}}</p>
{% for key, record in records %}
<p id="product_id_{{key}}" style="color: transparent;font-size: 1;position: absolute;">{{record.id}}</p>
{% endfor %}
<div class="table-responsive" style="margin-bottom: 20px;">
<table class="table mb-0">
@ -110,11 +137,12 @@ function onStart(){
<th style="background: #daddff;">Täze maglumat</th>
<th style="background: #daddff;">
<input type="number" name="all_amount" class="form-control"
placeholder="JEMI">
placeholder="JEMI" onchange="getAllAmount(this.value);">
</th>
{% for key, record in records %}
<th style="background: #daddff;">
<input type="number" name="product_{{record.code}}" class="form-control"
<input type="number" onchange="getValues();" step="0.01"
name="product_{{record.code}}" id="product_{{key}}" class="form-control"
placeholder="{{record.name}} %">
</th>
{% endfor %}
@ -152,7 +180,8 @@ function onStart(){
{% for key, report in productions %}
<tr>
<td style="font-weight: bold;width: 5%;">{{key + 1}}</td>
<td><a href="#" style="font-weight: bold;color: #0005c5;">{{report.created_at|date('d.m.Y |
<td><a href="#"
style="font-weight: bold;color: #0005c5;">{{report.created_at|date('d.m.Y |
H:i')}}</a></td>
<td style="text-align: center;">
<span class="badge badge-soft-success"
@ -160,7 +189,11 @@ function onStart(){
</td>
{% for product in report.pivot_production %}
<td>{{product.amount_percentage}} % {% if product.amount != 0 %}<br> <span style="font-size: 12px;color: darkgray;"> {{product.amount|number_format}} kg</span> {% endif %}</td>
<td>{{product.amount_percentage|number_format(2)}} %
<!-- {% if product.amount != 0 %}<br>
<span style="font-size: 12px;color: darkgray;"> {{product.amount|number_format}}
kg</span> {% endif %} -->
</td>
{% endfor %}
<td style="font-weight: bold;color: #0005c5;">{{report.note}}</td>
@ -191,3 +224,51 @@ function onStart(){
</div>
{% partial 'dataTableJs' %}
{% put scripts %}
<script>
function getAllAmount(amount) {
//var all_amount = document.getElementById("all_amount").value;
$('#all_amount').html(`JEMI: ` + amount + ` kg`);
}
function getValues() {
var prodCount = document.getElementById('product_count').innerHTML;
var fieldValues = [];
// console.log(prodCount);
for (let i = 0; i < prodCount; i++) {
var prod = document.getElementById("product_" + i).value;
var prodId = document.getElementById("product_id_" + i).innerHTML;
fieldValues[i] = prod ? parseFloat(prod) : 0;
calculate(prodId, prod);
//console.log("q" + i + ": " + prod);
}
var all = eval(fieldValues.join('+'));
$('#percentage').html(`<i class="mdi mdi-bullseye-arrow me-3"></i> ` + all.toFixed(2) + ` %`);
// console.log(fieldValues);
// console.log(eval(fieldValues.join('+')));
// return eval(fieldValues.join('+'));
}
function calculate(prodId, value) {
$.request('onCalculateAvg', {
data: {'prod_id': prodId, 'field_value': value},
success: function (data) {
$('#avg_percentage_' + prodId).html(`<i class="mdi mdi-bullseye-arrow me-3"></i> `+ data.avg_percentage +` %`);
$('#avg_amount_' + prodId).html(`ORTAÇA: `+ data.avg_amount +` kg`);
}
});
}
</script>
{% endput %}