Skip to content

Commit bf06e6e

Browse files
committed
Change /issues/549
1 parent 5c219c9 commit bf06e6e

32 files changed

+583
-443
lines changed

app/Http/Controllers/Planning/PlanningController.php

Lines changed: 85 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -17,132 +17,148 @@ public function index(Request $request)
1717
$startDate = $request->input('start_date', Carbon::now()->format('Y-m-d'));
1818
$endDate = $request->input('end_date', Carbon::now()->addMonths(1)->format('Y-m-d')); // Default, 1 month from today
1919

20-
// Retrieve the state of the display_hours_diff checkbox
20+
// Retrieve the state of the display_hours_diff checkbox
2121
$displayHoursDiff = $request->input('display_hours_diff', false);
2222

2323
// Check that the start date is not greater than the end date
2424
if (Carbon::parse($startDate)->gt(Carbon::parse($endDate))) {
2525
return redirect()->route('production.load.planning')->withErrors(['The start date must be before or equal to the end date.']);
2626
}
2727

28+
// Retrieve tasks and services
29+
$taches = $this->getTasks($startDate, $endDate);
30+
$services = $this->getServices();
2831

29-
// Dans votre contrôleur ou ailleurs où vous avez besoin de cette information
30-
$countTaskNullRessource = Task::whereNotNull('order_lines_id')->whereDoesntHave('resources')->count();
31-
32-
// Collect Tasks
33-
$taches = Task::with('service')
34-
->whereBetween('end_date', [$startDate, $endDate])
35-
->whereNotNull('order_lines_id')
36-
->where(function (Builder $query) {
37-
return $query->where('tasks.type', 1)
38-
->orWhere('tasks.type', 7);
39-
})->get();
40-
41-
if($taches->count() < 1 && $countTaskNullRessource < 1){
42-
return redirect()->route('production.task')->with('error', 'No tosk in planning');
32+
// Check if there are no tasks
33+
if ($taches->isEmpty() && $this->countTaskNullRessource() < 1) {
34+
return redirect()->route('production.task')->with('error', 'No task in planning');
4335
}
4436

45-
$countTaskNullDate = Task::whereNull('end_date')
46-
->whereNotNull('order_lines_id')
47-
->where(function (Builder $query) {
48-
return $query->where('tasks.type', 1)
49-
->orWhere('tasks.type', 7);
50-
})
51-
->get();
52-
$countTaskNullDate = $countTaskNullDate->count();
53-
// Collect service
54-
$services = MethodsServices::where(function (Builder $query) {
55-
return $query->where('type', 1)
56-
->orWhere('type', 7);
57-
})->get();
58-
59-
// Array to store the hours worked by service and by day
37+
// Calculate hours worked and tasks per service per day
38+
[$hoursWorkedPerServiceDay, $tasksPerServiceDay] = $this->calculateHoursAndTasks($taches);
39+
40+
// Calculate load rates per service per day
41+
$rateChargePerServiceDay = $this->calculateLoadRates($hoursWorkedPerServiceDay);
42+
43+
// Create a data structure for load rates
44+
$structureRateLoad = $this->createLoadRateStructure($rateChargePerServiceDay);
45+
46+
// Generate all possible dates between the start and end dates
47+
$possibleDates = $this->generatePossibleDates($startDate, $endDate);
48+
49+
// Count tasks with null end date
50+
$countTaskNullDate = $this->countTaskNullDate();
51+
52+
// Count tasks with null resources
53+
$countTaskNullRessource = $this->countTaskNullRessource();
54+
55+
return view('workflow/planning-index', compact('taches', 'countTaskNullRessource', 'countTaskNullDate', 'tasksPerServiceDay', 'structureRateLoad', 'services', 'possibleDates', 'startDate', 'endDate', 'displayHoursDiff'));
56+
}
57+
58+
private function getTasks($startDate, $endDate)
59+
{
60+
return Task::with('service')
61+
->whereBetween('end_date', [$startDate, $endDate])
62+
->whereNotNull('order_lines_id')
63+
->where(function (Builder $query) {
64+
return $query->where('tasks.type', 1)
65+
->orWhere('tasks.type', 7);
66+
})->get();
67+
}
68+
69+
private function getServices()
70+
{
71+
return MethodsServices::where(function (Builder $query) {
72+
return $query->where('type', 1)
73+
->orWhere('type', 7);
74+
})->get();
75+
}
76+
77+
private function countTaskNullRessource()
78+
{
79+
return Task::whereNotNull('order_lines_id')->whereDoesntHave('resources')->count();
80+
}
81+
82+
private function countTaskNullDate()
83+
{
84+
return Task::whereNull('end_date')
85+
->whereNotNull('order_lines_id')
86+
->where(function (Builder $query) {
87+
return $query->where('tasks.type', 1)
88+
->orWhere('tasks.type', 7);
89+
})->count();
90+
}
91+
92+
private function calculateHoursAndTasks($taches)
93+
{
6094
$hoursWorkedPerServiceDay = [];
61-
// Array to store tasks by department and day
6295
$tasksPerServiceDay = [];
6396

64-
// Browse tasks and calculate hours worked for each service and day
6597
foreach ($taches as $tache) {
6698
$serviceId = $tache['methods_services_id'];
6799
$jour = (new Carbon($tache['end_date']))->format('Y-m-d'); // Convert the date to Y-m-d format
68-
69-
// Check if the service already exists in the array
100+
101+
// Calculate hours worked
70102
if (!isset($hoursWorkedPerServiceDay[$serviceId])) {
71103
$hoursWorkedPerServiceDay[$serviceId] = [];
72104
}
73-
74-
// Add the hours worked to the existing sum for the service and the day
75105
if (!isset($hoursWorkedPerServiceDay[$serviceId][$jour])) {
76106
$hoursWorkedPerServiceDay[$serviceId][$jour] = $tache->TotalTime();
77107
} else {
78108
$hoursWorkedPerServiceDay[$serviceId][$jour] += $tache->TotalTime();
79109
}
80110

81-
// Section for add task id in tooltip cell
82-
// Check if the service already exists in the array
111+
// Collect tasks per service per day
83112
if (!isset($tasksPerServiceDay[$serviceId])) {
84113
$tasksPerServiceDay[$serviceId] = [];
85114
}
86-
87-
// Check if the day already exists in the array
88115
if (!isset($tasksPerServiceDay[$serviceId][$jour])) {
89116
$tasksPerServiceDay[$serviceId][$jour] = [];
90117
}
91-
92-
/// Add the task ID to the table corresponding to the service and the day
93118
$tasksPerServiceDay[$serviceId][$jour][] = $tache->id;
94119
}
95120

96-
// Array to store load rates per service and per day
121+
return [$hoursWorkedPerServiceDay, $tasksPerServiceDay];
122+
}
123+
124+
private function calculateLoadRates($hoursWorkedPerServiceDay)
125+
{
97126
$rateChargePerServiceDay = [];
127+
$capacityHebdoService = 16; // Hypothetical weekly capacity of 16 hours
98128

99-
/// Browse the hours worked by service and by day and calculate the load rates
100129
foreach ($hoursWorkedPerServiceDay as $serviceId => $hoursPerDay) {
101130
foreach ($hoursPerDay as $jour => $HoursWorked) {
102-
//currently the capacity is fixed, see in the future
103-
$capacityHebdoService = 16; // Hypothetical weekly capacity of 16 hours
104-
105-
// Calculate the percentage charge rate
106131
$chargeRate = ($HoursWorked / $capacityHebdoService) * 100;
107-
108-
// Store the charge rate in the array
109132
$rateChargePerServiceDay[$serviceId][$jour] = $chargeRate;
110133
}
111134
}
112135

113-
// Create a data structure for load rates
136+
return $rateChargePerServiceDay;
137+
}
138+
139+
private function createLoadRateStructure($rateChargePerServiceDay)
140+
{
114141
$structureRateLoad = [];
142+
115143
foreach ($rateChargePerServiceDay as $serviceId => $tauxParJour) {
116144
foreach ($tauxParJour as $jour => $taux) {
117145
$structureRateLoad[$jour][$serviceId] = $taux;
118146
}
119147
}
120148

121-
// Extract all unique dates from each array into $rateChargePerServiceDay
122-
$allDatesUniques = [$startDate];
123-
foreach ($rateChargePerServiceDay as $ratePerService) {
124-
$datesService = array_keys($ratePerService);
125-
$allDatesUniques = array_merge($allDatesUniques, $datesService);
126-
}
127-
128-
// Remove duplicates and sort unique dates
129-
$allDatesUniques = array_unique($allDatesUniques);
130-
sort($allDatesUniques);
131-
132-
// Get smallest and largest date
133-
$minDate = min($allDatesUniques);
134-
$maxDate = max($allDatesUniques);
149+
return $structureRateLoad;
150+
}
135151

136-
// Generate all dates between the smallest and largest date
152+
private function generatePossibleDates($startDate, $endDate)
153+
{
137154
$possibleDates = [];
138155
$currentDate = $startDate;
156+
139157
while ($currentDate <= $endDate) {
140158
$possibleDates[] = $currentDate;
141159
$currentDate = date('Y-m-d', strtotime($currentDate . ' +1 day'));
142160
}
143161

144-
145-
return view('workflow/planning-index', compact('taches', 'countTaskNullRessource', 'countTaskNullDate', 'tasksPerServiceDay', 'structureRateLoad', 'services', 'possibleDates', 'startDate', 'endDate', 'displayHoursDiff'));
146-
162+
return $possibleDates;
147163
}
148164
}

app/Http/Controllers/SearchController.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55
use Illuminate\Http\Request;
66
use App\Models\Workflow\Orders;
77
use App\Models\Workflow\Quotes;
8+
use App\Models\Products\Products;
89
use App\Models\Workflow\Invoices;
910
use App\Models\Workflow\Deliverys;
1011
use App\Models\Companies\Companies;
11-
use App\Models\Products\Products;
12+
use App\Models\Purchases\PurchaseReceipt;
13+
use App\Models\Purchases\Purchases;
14+
use App\Models\Workflow\CreditNotes;
1215
use Illuminate\Support\Facades\Log;
1316
use ProtoneMedia\LaravelCrossEloquentSearch\Search;
1417

@@ -39,7 +42,10 @@ public function showNavbarSearchResults(Request $request)
3942
->add(Orders::class, ['code', 'label'])
4043
->add(Deliverys::class, ['code', 'label'])
4144
->add(Invoices::class, ['code', 'label'])
45+
->add(CreditNotes::class, ['code', 'label'])
4246
->add(Products::class, ['code', 'label'])
47+
->add(Purchases::class, ['code', 'label'])
48+
->add(PurchaseReceipt::class, ['code', 'label'])
4349
->beginWithWildcard()
4450
->orderByModel([
4551
Companies::class, Quotes::class, Orders::class, Deliverys::class, Invoices::class,Products::class,

app/Http/Controllers/Workflow/DeliverysController.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace App\Http\Controllers\Workflow;
44

55
use Carbon\Carbon;
6-
use Illuminate\Http\Request;
76
use App\Traits\NextPreviousTrait;
87
use App\Models\Workflow\Deliverys;
98
use App\Models\Workflow\Packaging;

app/Http/Controllers/Workflow/OrdersController.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace App\Http\Controllers\Workflow;
44

5-
use Carbon\Carbon;
65
use App\Models\Workflow\Orders;
76
use App\Services\OrderKPIService;
87
use App\Traits\NextPreviousTrait;

app/Livewire/CompaniesLines.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class CompaniesLines extends Component
2323

2424
public $Companies;
2525

26-
public $LastCompanie = '1';
26+
public $LastCompanie = null;
2727

2828
public $userSelect = [];
2929
public $code, $label;

0 commit comments

Comments
 (0)