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

66 lines
1.6 KiB
PHP

<?php namespace Romanah\Gokbakja\Models;
use Model;
use Carbon\Carbon;
use DB;
/**
* Model
*/
class Production extends Model
{
use \October\Rain\Database\Traits\Validation;
use \October\Rain\Database\Traits\SoftDelete;
protected $dates = ['deleted_at'];
public $hasMany = [
'pivot_production' => [
'Romanah\Gokbakja\Models\PivotProduction',
'key' => 'production_id',
'softDelete' => true
],
'pivot_production_calculation' => [
'Romanah\Gokbakja\Models\ProductionCalculate',
'key' => 'production_id',
'softDelete' => true
]
];
public $belongsTo = [
'excruiter' => [
'Romanah\Gokbakja\Models\Excruiter',
'key' => 'excruiter_id'
],
'shift' => [
'Romanah\Gokbakja\Models\Shift',
'key' => 'shift_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'))
->orderBy('id', 'DESC')
->groupby('year','month', 'day');
}
/**
* @var string The database table used by the model.
*/
public $table = 'romanah_gokbakja_production';
/**
* @var array Validation rules
*/
public $rules = [
'all_amount' => 'required',
];
public $customMessages = [
'all_amount.required' => 'Jemi diýen hökman doldurylmalydyr.',
];
}