<?php

namespace App\Service\Expance;

use App\Models\Expance;
use Carbon\Carbon;

class ExpanceService
{
    public static function store(array $data)
    {


        $collect = collect($data)->except(['_token', 'reference_no']);

        $lastExpanse = Expance::orderByDesc('id')->first();

        $reference = invoice_no($lastExpanse?->id ?? false, 'EXP');


        Expance::create($collect->merge(['shop_id' => auth()->user()->shop_id, 'create_by' => auth()->user()->id, 'reference_no' => $reference])->toArray());
    }

    public static function update(array $data, $id)
    {

        $collect = collect($data);
        Expance::where('id', $id)->update($collect->merge(['create_by' => auth()->user()->id])->toArray());
    }
}
