Skip to content

Commit e2b4f3b

Browse files
committed
1 parent 20093ec commit e2b4f3b

File tree

9 files changed

+238
-11
lines changed

9 files changed

+238
-11
lines changed

app/Http/Controllers/Workflow/OrdersController.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
use App\Http\Controllers\Controller;
1111
use App\Services\CustomFieldService;
1212
use App\Services\OrderCalculatorService;
13+
use App\Services\OrderInvoiceDataService;
14+
use App\Services\OrderBusinessBalanceService;
1315
use App\Http\Requests\Workflow\UpdateOrderRequest;
1416

1517
class OrdersController extends Controller
@@ -19,15 +21,21 @@ class OrdersController extends Controller
1921
protected $SelectDataService;
2022
protected $orderKPIService;
2123
protected $customFieldService;
24+
protected $OrderBusinessBalanceService;
25+
protected $OrderInvoiceDataService;
2226

2327
public function __construct(
2428
SelectDataService $SelectDataService,
2529
OrderKPIService $orderKPIService,
26-
CustomFieldService $customFieldService
30+
CustomFieldService $customFieldService,
31+
OrderBusinessBalanceService $OrderBusinessBalanceService,
32+
OrderInvoiceDataService $OrderInvoiceDataService,
2733
){
2834
$this->SelectDataService = $SelectDataService;
2935
$this->orderKPIService = $orderKPIService;
3036
$this->customFieldService = $customFieldService;
37+
$this->OrderBusinessBalanceService = $OrderBusinessBalanceService;
38+
$this->OrderInvoiceDataService = $OrderInvoiceDataService;
3139
}
3240

3341
/**
@@ -73,6 +81,11 @@ public function show(Orders $id)
7381
$TotalServiceSettingTime = $OrderCalculatorService->getTotalSettingTimeByService();
7482
$TotalServiceCost = $OrderCalculatorService->getTotalCostByService();
7583
$TotalServicePrice = $OrderCalculatorService->getTotalPriceByService();
84+
85+
$businessBalance = $this->OrderBusinessBalanceService->getBusinessBalance($id);
86+
$businessBalancetotals = $this->OrderBusinessBalanceService->getBusinessBalanceTotals($id);
87+
$invoicedAmount = $this->OrderInvoiceDataService->getInvoicingAmount($id);
88+
$receivedPayment = $this->OrderInvoiceDataService->getInvoicingReceivedPayment($id);
7689

7790
list($previousUrl, $nextUrl) = $this->getNextPrevious(new Orders(), $id->id);
7891
$CustomFields = $this->customFieldService->getCustomFieldsWithValues('order', $id->id);
@@ -95,6 +108,10 @@ public function show(Orders $id)
95108
'previousUrl' => $previousUrl,
96109
'nextUrl' => $nextUrl,
97110
'CustomFields' => $CustomFields,
111+
'businessBalance' => $businessBalance,
112+
'businessBalancetotals' => $businessBalancetotals,
113+
'invoicedAmount' => $invoicedAmount,
114+
'receivedPayment' => $receivedPayment,
98115
]);
99116
}
100117

app/Livewire/TaskManage.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ public function updateTask(){
428428
// Update line
429429
Task::find($this->taskId)->fill([
430430
'ordre' => $this->ordre,
431+
'label' => $this->label,
431432
'methods_services_id' => $this->methods_services_id,
432433
'component_id' => $this->component_id,
433434
'seting_time' => $this->seting_time,

app/Models/Planning/Task.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,21 @@ public function ProductTime()
150150
return $this->GetOrderQtyLine()*$this->unit_time;
151151
}
152152

153+
public function TotalCost()
154+
{
155+
return round($this->GetOrderQtyLine()*$this->unit_cost,2);
156+
}
157+
158+
public function TotalPrice()
159+
{
160+
return round($this->GetOrderQtyLine()*$this->unit_price,2);
161+
}
162+
153163
public function Margin()
154164
{
155165
return round((($this->unit_price/$this->unit_cost)-1)*100,2);
156166
}
167+
157168

158169
public function TotalTime()
159170
{
@@ -189,6 +200,11 @@ public function getTotalLogTime()
189200
return round(($this->getTotalLogStartTime()-$this->getTotalLogEndTime())/3600,2);
190201
}
191202

203+
public function getTotalRealizedCost()
204+
{
205+
return round($this->getTotalLogTime()*$this->service->hourly_rate,2);
206+
}
207+
192208
public function progress()
193209
{
194210
if($this->TotalTime() <= 0){
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
3+
namespace App\Services;
4+
5+
use App\Models\Workflow\Orders;
6+
7+
class OrderBusinessBalanceService
8+
{
9+
public function getBusinessBalance($order)
10+
{
11+
$orderLines = $order->orderLines; // Récupère toutes les lignes de commande
12+
$businessBalance = [];
13+
14+
foreach ($orderLines as $line) {
15+
16+
$tasks = $line->task; // Collection de tâches
17+
18+
foreach ($tasks as $task) {
19+
$service = $task->service;
20+
$taskName = $service ? $service->label : 'Service non défini';
21+
22+
if (!isset($businessBalance[$taskName])) {
23+
$businessBalance[$taskName] = [
24+
'total_hours' => $task->TotalTime(),
25+
'total_cost' => $task->TotalCost(),
26+
'total_price' => $task->TotalPrice(),
27+
'realized_hours' => $task->getTotalLogTime(),
28+
'realized_cost' => $task->getTotalRealizedCost(),
29+
// Calcul de l'écart
30+
'difference_hours' => $task->TotalTime()-$task->getTotalLogTime(),
31+
'difference_cost' => $task->TotalCost()-0,
32+
];
33+
}
34+
else{
35+
// Cumul des heures et coûts
36+
$businessBalance[$taskName]['total_hours'] += $task->TotalTime();
37+
$businessBalance[$taskName]['total_cost'] += $task->TotalCost();
38+
$businessBalance[$taskName]['total_price'] += $task->TotalPrice();
39+
$businessBalance[$taskName]['realized_hours'] += $task->getTotalLogTime();
40+
$businessBalance[$taskName]['realized_cost'] += $task->getTotalRealizedCost();
41+
// Calcul de l'écart
42+
$businessBalance[$taskName]['difference_hours'] = $businessBalance[$taskName]['total_hours'] - $businessBalance[$taskName]['realized_hours'];
43+
$businessBalance[$taskName]['difference_cost'] = $businessBalance[$taskName]['total_cost'] - $businessBalance[$taskName]['realized_cost'];
44+
}
45+
46+
}
47+
}
48+
return $businessBalance;
49+
}
50+
51+
public function getBusinessBalanceTotals($order)
52+
{
53+
$businessBalance = $this->getBusinessBalance($order);
54+
55+
$totals = [
56+
'total_hours' => 0,
57+
'total_cost' => 0,
58+
'total_price' => 0,
59+
'realized_hours' => 0,
60+
'realized_cost' => 0,
61+
'difference_hours' => 0,
62+
'difference_cost' => 0,
63+
];
64+
65+
foreach ($businessBalance as $details) {
66+
$totals['total_hours'] += $details['total_hours'];
67+
$totals['total_cost'] += $details['total_cost'];
68+
$totals['total_price'] += $details['total_price'];
69+
$totals['realized_hours'] += $details['realized_hours'];
70+
$totals['realized_cost'] += $details['realized_cost'];
71+
$totals['difference_hours'] += $details['difference_hours'];
72+
$totals['difference_cost'] += $details['difference_cost'];
73+
}
74+
75+
return $totals;
76+
}
77+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace App\Services;
4+
5+
class OrderInvoiceDataService
6+
{
7+
public function getInvoicingAmount($order)
8+
{
9+
// Amount invoiced (total invoices sent)
10+
$invoicedAmount = $order->orderLines->sum(function ($line) {
11+
// Check that the 'invoiceLines' relation is well defined
12+
return $line->invoiceLines->sum(function ($invoiceLine) use ($line) {
13+
return $invoiceLine->qty * $line->selling_price;
14+
});
15+
});
16+
17+
return $invoicedAmount;
18+
}
19+
20+
public function getInvoicingReceivedPayment($order)
21+
{
22+
$receivedPayment = $order->orderLines->sum(function ($line) {
23+
return $line->invoiceLines->sum(function ($invoiceLine) use ($line) {
24+
// Check that the invoice line is paid (invoice status = 5)
25+
if ($invoiceLine->invoice_status == 5) {
26+
return $invoiceLine->qty * $line->selling_price;
27+
}
28+
return 0;
29+
});
30+
});
31+
32+
return $receivedPayment;
33+
}
34+
}

resources/lang/en/general_content.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,8 @@
216216
'start_date_trans_key' => 'Start date',
217217
'end_date_trans_key' => 'End date',
218218
'date_time_trans_key' => 'Date time',
219+
'hour_trans_key' => 'Your',
220+
'hours_trans_key' => 'Yours',
219221
'task_trans_key' => 'Task',
220222
'nc_trans_key' => 'NC',
221223
'failure_trans_key' => 'Failure',
@@ -649,6 +651,11 @@
649651
'order_type_trans_key' => 'Order type',
650652
'customer_type_order_trans_key' => 'Customer sales order',
651653
'internal_type_order_trans_key' => 'Internal sales order',
654+
'forecast_margin_trans_key' => 'Forecast margin',
655+
'current_margin_trans_key' => 'Current margin',
656+
'manufacturing_range_trans_key' => 'Manufacturing range',
657+
'accomplished_trans_key' => 'Accomplished',
658+
'gap_trans_key' => 'Gap',
652659

653660
'info_statu_trans_key' => 'The document status does not allow adding / modifying / deleting lines.',
654661

@@ -660,7 +667,6 @@
660667
'load_planning_info_1_trans_key' => 'Currently the charge per day is stuck at 16 hours',
661668
'display_hours_diff_trans_key' => 'Time difference',
662669

663-
664670
//WORKFLOW
665671
'workflow_trans_key' => 'Workflow',
666672
'workflow_info_1_trans_key' => 'The views are configured in the \'Your company\' page.',
@@ -742,7 +748,8 @@
742748
'average_payment_time_trans_key' => 'Average payment time',
743749
'late_payment_time_trans_key' => 'Late payment rate',
744750
'incoterm_trans_key' => 'Incoterm',
745-
751+
'still_invoiced_trans_key' => 'Still to be invoiced',
752+
746753
//CREDIT NOTE
747754
'credit_notes_trans_key' => 'Credit notes',
748755
'credit_note_trans_key' => 'Credit note',

resources/lang/fr/general_content.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,8 @@
216216
'start_date_trans_key' => 'Date de début',
217217
'end_date_trans_key' => 'Date de fin',
218218
'date_time_trans_key' => 'Date et heure',
219+
'hour_trans_key' => 'Heure',
220+
'hours_trans_key' => 'Heures',
219221
'task_trans_key' => 'Tache',
220222
'nc_trans_key' => 'NC',
221223
'failure_trans_key' => 'Défaillance',
@@ -649,7 +651,12 @@
649651
'order_type_trans_key' => 'Type de commande',
650652
'customer_type_order_trans_key' => 'Commande client',
651653
'internal_type_order_trans_key' => 'Commande interne',
652-
654+
'forecast_margin_trans_key' => 'Marge prévisionnelle',
655+
'current_margin_trans_key' => 'Marge courante',
656+
'manufacturing_range_trans_key' => 'Gamme',
657+
'accomplished_trans_key' => 'Réalisé',
658+
'gap_trans_key' => 'Ecart',
659+
653660
'info_statu_trans_key' => 'Le statut du document ne permet pas d\'ajouter/modifier/supprimer des lignes.',
654661

655662
'scheduling_trans_key' => 'Scheduling',
@@ -721,12 +728,13 @@
721728
'new_delivery_note_trans_key' => 'Nouveau bon de livraison',
722729
'tracking_number_note_trans_key' => 'Numéro de suivis',
723730
'packaging_trans_key' => 'Packaging',
731+
'new_packaging_trans_key' => 'Nouveau packaging',
724732

725733
//INVOICE
726734
'invoices_trans_key' => 'Factures',
727735
'invoice_trans_key' => 'Facture',
728736
'invoices_request_trans_key' => 'Attente de facture',
729-
'invoices_list_trans_key' => 'Factures liste',
737+
'invoices_list_trans_key' => 'Factures liste',
730738
'invoices_export_trans_key' => 'Exporter ligne de facture',
731739
'others_trans_key' => 'Autres',
732740
'new_invoice_trans_key' => 'Nouvelle facture',
@@ -740,6 +748,7 @@
740748
'average_payment_time_trans_key' => 'Délai moyen de paiement',
741749
'late_payment_time_trans_key' => 'Taux de retard de paiement',
742750
'incoterm_trans_key' => 'Incoterm',
751+
'still_invoiced_trans_key' => 'Reste à facturer',
743752

744753
//CREDIT NOTE
745754
'credit_notes_trans_key' => 'Avoirs',

resources/views/include/sub-total-price.blade.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
<table class="table table-hover">
33
<tr>
44
<td style="width:50%">{{ __('general_content.sub_total_trans_key') }} :</td>
5-
<td>{{ $subPrice }} {{ $Factory->curency }} </td>
5+
<td>{{ number_format( $subPrice , 2)}} {{ $Factory->curency }} </td>
66
</tr>
77
@forelse($vatPrice as $key => $value)
88
<tr>
9-
<td>{{ __('general_content.tax_trans_key') }} <?= $vatPrice[$key][0] ?> %</td>
10-
<td colspan="4"><?= $vatPrice[$key][1] ?> {{ $Factory->curency }}</td>
9+
<td>{{ __('general_content.tax_trans_key') }} {{ $vatPrice[$key][0] }} %</td>
10+
<td colspan="4">{{ number_format( $vatPrice[$key][1] , 2)}} {{ $Factory->curency }}</td>
1111
</tr>
1212
@empty
1313
<tr>
@@ -17,7 +17,7 @@
1717
@endforelse
1818
<tr>
1919
<td>{{ __('general_content.total_trans_key') }} :</td>
20-
<td>{{ $totalPrices }} {{ $Factory->curency }}</td>
20+
<td>{{ number_format($totalPrices, 2) }} {{ $Factory->curency }}</td>
2121
</tr>
2222
</table>
2323
</div>

0 commit comments

Comments
 (0)