<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use DB;

class Mcp extends Model{
    use HasFactory;
    protected $table = 'mcp';
    
    protected $fillable = [
        'name',
        'amount',
        'profit',
        'gst_percentage',
        'gst',
        'total_profit',
        'car_model',
        'status',
        'created_at',
    ];

     public function export($slug){
        $collection = DB::table('mcp')
        				->select('mcp.name','car_model.name as car_model_name','mcp.amount','mcp.profit','mcp.gst_percentage','mcp.gst','mcp.total_profit','mcp.status')
        				->leftjoin('car_model' ,'car_model.id' ,'mcp.car_model');

        if($slug != 'all')
            $collection->where(['mcp.status' => $slug]);
        
        $data = $collection->get();
        
        if($data->isNotEmpty()){
            return $data;
        }else{
            return null;
        }
    }


    
}
