MMCT TEAM
Server IP : 103.191.208.50  /  Your IP : 216.73.216.53
Web Server : LiteSpeed
System : Linux orion.herosite.pro 4.18.0-553.53.1.lve.el8.x86_64 #1 SMP Wed May 28 17:01:02 UTC 2025 x86_64
User : celkcksm ( 1031)
PHP Version : 7.4.33
Disable Function : show_source, system, shell_exec, passthru, popen, exec
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0755) :  /home/celkcksm/hrms.ncriptech.com/app/Services/Management/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/celkcksm/hrms.ncriptech.com/app/Services/Management/NoteService.php
<?php

namespace App\Services\Management;

use App\Services\Core\BaseService;
use Illuminate\Support\Facades\DB;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Facades\Validator;
use App\Helpers\CoreApp\Traits\DateHandler;
use App\Helpers\CoreApp\Traits\CurrencyTrait;
use App\Helpers\CoreApp\Traits\ApiReturnFormatTrait;
use App\Helpers\CoreApp\Traits\InvoiceGenerateTrait;
use App\Models\coreApp\Relationship\RelationshipTrait;
use App\Models\Management\Notes;
use Illuminate\Support\Facades\Log;

class NoteService extends BaseService
{
    use RelationshipTrait, DateHandler, InvoiceGenerateTrait, CurrencyTrait, ApiReturnFormatTrait;

    public function __construct(Notes $notes)
    {
        $this->model = $notes;
    }

    // store the
    public function store($request)
    {

        $validator = Validator::make(\request()->all(), [
            'description' => 'required',
        ]);

        if ($validator->fails()) {
            return $this->responseWithError(_trans('message.Description field is required'), 'id', 404);
        }
        DB::beginTransaction();
        try {
            $project = DB::table('projects')->where('id', $request->project_id)->first();
            if (!$project) {
                return $this->responseWithError(__('Project not found'), [], 400);
            }
            $data = [
                'company_id' => auth()->user()->company_id,
                'project_id' => $request->project_id,
                'description' => $request->description,
                'user_id' => auth()->user()->id,
                'show_to_customer' => @$request->show_to_customer == 1  ? 33 : 22,
                'last_activity' => date('Y-m-d H:i:s'),
            ];
            $note = $this->model->create($data);            
            \App\Models\Management\ProjectActivity::CreateActivityLog(auth()->user()->company_id, $request->project_id, auth()->id(), 'Created Notes')->save();
            DB::commit();
            return $this->responseWithSuccess(_trans('message.Note created successfully.'), $note);
        } catch (\Throwable $th) {
            DB::rollBack();
            return $this->responseExceptionError($th->getMessage(), [], 400);
        }
    }

    function update($request, $id)
    {

        $validator = Validator::make(\request()->all(), [
            'description' => 'required',
        ]);

        if ($validator->fails()) {
            return $this->responseWithError(_trans('message.Description field is required'), 'id', 404);
        }
        DB::beginTransaction();
        try {
            $note = $this->model->where(['id' => $id, 'company_id' => auth()->user()->company_id])->first();
            if (!$note) {
                return $this->responseWithError(_trans('message.Note not found'), 'id', 404);
            }
            $note->description       = $request->description;
            $note->show_to_customer  = @$request->show_to_customer == 1  ? 33 : 22;
            $note->last_activity     = date('Y-m-d H:i:s', time());
            $note->save();            
            \App\Models\Management\ProjectActivity::CreateActivityLog(auth()->user()->company_id, $note->project_id, auth()->id(), 'Updated Notes')->save();
            DB::commit();
            return $this->responseWithSuccess(_trans('message.Note Updated successfully.'), $note);
        } catch (\Throwable $th) {
            DB::rollBack();
            return $this->responseWithError($th->getMessage(), [], 400);
        }
    }


    function delete($id)
    {
        $note = $this->model->where(['id' => $id, 'company_id' => auth()->user()->company_id])->first();
        if (!$note) {
            return $this->responseWithError(_trans('message.Note not found'), 'id', 404);
        }
        try {
            \App\Models\Management\ProjectActivity::CreateActivityLog(auth()->user()->company_id, $note->project_id, auth()->id(), 'Deleted Notes')->save();
            $note->delete();            
            return $this->responseWithSuccess(_trans('message.Note Delete successfully.'), $note);
        } catch (\Throwable $th) {
            return $this->responseExceptionError($th->getMessage(), [], 400);
        }
    }
}

MMCT - 2023