<?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'
        ]
    ];

    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 = [
    ];
}
