Skip to content

P2 #342

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

P2 #342

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
Binary file added app/.DS_Store
Binary file not shown.
77 changes: 77 additions & 0 deletions app/Api/v1/Controllers/DashboardApi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php
namespace App\Api\v1\Controllers;
use App\Http\Controllers\Controller;
use App\Models\Client;
use App\Models\Invoice;
use App\Models\Lead;
use App\Models\Offer;
use App\Models\Project;
use App\Models\Task;
use App\Models\User;
use App\Services\Creation\CreationTracker;
use App\Services\Earnings\EarningsService;
use App\Services\Product\ProductService;
use App\Services\Project\ProjectService;

class DashboardApi extends Controller
{
public function index()
{
$clients=Client::count();
$users=User::count();
$projects=Project::count();
$leads=Lead::count();
$offers=Offer::count();
$invoices=Invoice::count();
$tasks=Task::count();
$year=now()->year;
$month=now()->month;

$projectservice=new ProjectService();
$openedprojects=$projectservice->getSumOpened();
$canceledprojects=$projectservice->getSumCanceled();
$inprogressprojects=$projectservice->getSumInprogress();
$completedprojects=$projectservice->getSumCompleted();
$blockedprojects=$projectservice->getSumBlocked();


$creationservice=new CreationTracker();
$creationdatasheet=$creationservice->tracker(15);


$productservice=new ProductService();
$bestproducts=$productservice->getTopProductsMonthly(3);


$earningservice=new EarningsService();
$daybydayearnings=$earningservice->getDaybyDayEarnings($year,$month);
$monthearnings=$earningservice->getMonthlyEarnings($year,$month);
$annualearnings=$earningservice->getAnnualEarnings($year);
$globalearnings=$earningservice->getGlobalEarnings();



return response()->json([
'clients' => $clients,
'users' => $users,
'projects' => $projects,
'leads' => $leads,
'offers' => $offers,
'tasks'=>$tasks,
'invoices' => $invoices,
'openedprojects' => $openedprojects,
'canceledprojects' => $canceledprojects,
'inprogressprojects' => $inprogressprojects,
'completedprojects' => $completedprojects,
'blockedprojects' => $blockedprojects,
'creationdatasheet' => $creationdatasheet,
'bestproducts' => $bestproducts,
'daybydayearnings' => $daybydayearnings,
'monthlyearnings' => $monthearnings,
'annualearnings' => $annualearnings,
'globalearnings' => $globalearnings,
]);

}
}
?>
35 changes: 35 additions & 0 deletions app/Enums/LeadStatus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace App\Enums;

use App\Models\Status;

class LeadStatus
{
public static function open()
{
return Status::where(
['title'=>'Open', 'source_type'=>'App\Models\Lead']
)->first();
}
public static function pending()
{
return Status::where(
['title'=>'Pending', 'source_type'=>'App\Models\Lead']
)->first();
}

public static function waitingclient()
{
return Status::where(
['title'=>'Waiting client', 'source_type'=>'App\Models\Lead']
)->first();
}
public static function closed()
{
return Status::where(
['title'=>'Closed', 'source_type'=>'App\Models\Lead']
)->first();
}

}
40 changes: 40 additions & 0 deletions app/Enums/ProjectStatus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace App\Enums;

use App\Models\Status;

class ProjectStatus
{
public static function open()
{
return Status::where(
['title'=>'Open', 'source_type'=>'App\Models\Project']
)->first();
}
public static function closed(){
return Status::where(
['title'=>'Closed', 'source_type'=>'App\Models\Project']
)->first();
}
public static function inProgress(){
return Status::where(
['title'=>'In-progress', 'source_type'=>'App\Models\Project']
)->first();
}
public static function blocked(){
return Status::where(
['title'=>'Blocked', 'source_type'=>'App\Models\Project']
)->first();
}
public static function completed(){
return Status::where(
['title'=>'Completed', 'source_type'=>'App\Models\Project']
)->first();
}
public static function cancelled(){
return Status::where(
['title'=>'Cancelled', 'source_type'=>'App\Models\Project']
)->first();
}
}
Binary file added app/Http/.DS_Store
Binary file not shown.
26 changes: 25 additions & 1 deletion app/Http/Controllers/Auth/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;

use Illuminate\Validation\ValidationException;
class LoginController extends Controller
{
/*
Expand Down Expand Up @@ -36,4 +36,28 @@ public function __construct()
{
$this->middleware('guest', ['except' => 'logout']);
}

public function apiLogin(Request $request)
{
try {
$this->validate($request, [
'email' => 'required|email',
'password' => 'required|string',
]);
if ($this->attemptLogin($request)) {
$user = $this->guard()->user();
return response()->json(['success' => true, 'message' => 'connexion', 'user' => $user]);
}

return response()->json(['success' => false, 'message' => 'Authentication failed.Please try again.']);
}
catch (ValidationException $e) {
return response()->json(['success' => false, 'message' => 'Login failed ','errors' => $e->errors()]);
}
catch (\Exception $e) {
return response()->json(['success' => false, 'message' => 'Login failed: '.$e->getMessage()]);
}

}

}
47 changes: 47 additions & 0 deletions app/Http/Controllers/ConfigurationRemiseController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace App\Http\Controllers;



use App\Models\ConfigurationRemise;
use Illuminate\Http\Request;

class ConfigurationRemiseController extends Controller
{
public function index()
{
return response()->json(ConfigurationRemise::first());
}

public function update(Request $request){

try {
$request->validate([
'discount' => 'required|numeric|min:0|max:100'
]);
$remise=ConfigurationRemise::first();
if (!$remise) {
$remise = new ConfigurationRemise();
}
$remise->discount=$request->discount;
$remise->save();
}
catch (\Illuminate\Validation\ValidationException $e) {
return response()->json([
'message' => 'Erreur de validation des données: '.$e->errors(),
'success' => false,
]);
}
catch (\Exception $e) {
return response()->json([
'message' => 'Une erreur interne s\'est produite: '. $e->getMessage(),
'success' =>false ,
]);
}
return response()->json([
'message' => 'Discount configuration successfully updated.',
'success' =>true,
]);
}
}
33 changes: 31 additions & 2 deletions app/Http/Controllers/DepartmentsController.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Ramsey\Uuid\Uuid;
use Session;
use App\Http\Requests;
use App\Models\Department;
use App\Http\Requests\Department\StoreDepartmentRequest;
use Datatables;
Expand All @@ -17,6 +17,35 @@ public function __construct()
$this->middleware('is.demo', ['only' => ['destroy']]);
}


/*
* Importer departement
* */
public function import(Request $request)
{
$request->validate(['csv_file' => 'required|file|mimes:csv,txt']);
$csvfile=$request->file('csv_file');
try {
DB::beginTransaction();
if(($handle=fopen($csvfile,"r"))!==false){
$firstRow = fgetcsv($handle, 1000, ';');
while(($data=fgetcsv($handle, 1000, ';')) !== false){
$row=array_combine($firstRow, $data);
$department=new Department($row);
$department->save();
}
fclose($handle);
}
DB::commit();
}
catch(\Exception $e){
DB::rollback();
echo $e->getMessage();
}
return redirect()->route('departments.index')->with('success', 'Departments imported');
}


/**
* @return mixed
*/
Expand Down
53 changes: 53 additions & 0 deletions app/Http/Controllers/ImportController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace App\Http\Controllers;

use App\Models\Status;
use Illuminate\Http\Request;
use App\Services\import\ImportService;
use Dotenv\Exception\ValidationException;
use Illuminate\Support\Facades\DB;

class ImportController extends Controller
{
public function index()
{
return view('upload.index');
}
public function upload(Request $request)
{
try {
$request->validate([
'file1'=>'required|file|mimes:csv,txt',
'file2'=>'required|file|mimes:csv,txt',
'file3'=>'required|file|mimes:csv,txt',
]);
$csvfile1=$request->file('file1');
$csvfile2=$request->file('file2');
$csvfile3=$request->file('file3');

DB::beginTransaction();
$myimportservice=new ImportService();
$myimportservice->handlefile1($csvfile1);
$myimportservice->handlefile2($csvfile2);
$myimportservice->handlefile3($csvfile3);

DB::commit();
session()->flash('flash_message', __('Files successfully imported'));
}
catch (ValidationException $e)
{
DB::rollback();
session()->flash('flash_message_warning', $e->getMessage());
}
catch (\Exception $e)
{
DB::rollback();
#echo $e->getMessage();
session()->flash('flash_message_warning', $e->getMessage());

}
#var_dump(Status::typeOfLead());
return redirect()->back();
}
}
Loading