Skip to content

Commit a5df559

Browse files
committed
1 parent a7469d7 commit a5df559

15 files changed

+305
-49
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
3+
namespace App\Exports;
4+
5+
use App\Models\Accounting\AccountingEntry;
6+
use Maatwebsite\Excel\Concerns\WithMapping;
7+
use Maatwebsite\Excel\Concerns\WithHeadings;
8+
use Maatwebsite\Excel\Concerns\FromCollection;
9+
10+
class AccountingEntryLinesExport implements FromCollection , WithHeadings, WithMapping
11+
{
12+
13+
private $AccountingEntryId;
14+
15+
Public function __construct($AccountingEntryId)
16+
{
17+
$this->AccountingEntryId = $AccountingEntryId;
18+
}
19+
20+
public function headings(): array
21+
{
22+
return [
23+
'JOURNAL_CODE',
24+
'JOURNAL_LABEL',
25+
'SEQUENCE_NUMBER',
26+
'ACCOUNTING_DATE',
27+
'ACCOUNT_NUMBER',
28+
'ACCOUNT_LABEL',
29+
'JUSTIFICATION_REFERENCE',
30+
'JUSTIFICATION_DATE',
31+
'AUXILIARY_ACCOUNT_NUMBER',
32+
'AUXILIARY_ACCOUNT_LABEL',
33+
'DOCUMENT_REFERENCE',
34+
'DOCUMENT_DATE',
35+
'ENTRY_LABEL',
36+
'DEBIT_AMOUNT',
37+
'CREDIT_AMOUNT',
38+
'ENTRY_LETTERING',
39+
'LETTERING_DATE',
40+
'VALIDATION_DATE',
41+
'CURRENCY_CODE',
42+
'INVOICE_LINE_ID',
43+
'PURCHASE_INVOICE_LINE_ID',
44+
];
45+
}
46+
47+
public function map($AccountingEntry): array
48+
{
49+
return [
50+
$AccountingEntry->journal_code,
51+
$AccountingEntry->journal_label,
52+
$AccountingEntry->sequence_number,
53+
$AccountingEntry->accounting_date->format('Y-m-d'), // Format de date
54+
$AccountingEntry->account_number,
55+
$AccountingEntry->account_label,
56+
$AccountingEntry->justification_reference,
57+
$AccountingEntry->justification_date->format('Y-m-d'), // Format de date
58+
$AccountingEntry->auxiliary_account_number,
59+
$AccountingEntry->auxiliary_account_label,
60+
$AccountingEntry->document_reference,
61+
$AccountingEntry->document_date->format('Y-m-d'), // Format de date
62+
$AccountingEntry->entry_label,
63+
$AccountingEntry->debit_amount,
64+
$AccountingEntry->credit_amount,
65+
$AccountingEntry->entry_lettering,
66+
optional($AccountingEntry->lettering_date)->format('Y-m-d'), // Peut être null, on utilise `optional()`
67+
$AccountingEntry->validation_date->format('Y-m-d'), // Format de date
68+
$AccountingEntry->currency_code,
69+
$AccountingEntry->invoice_line_id,
70+
$AccountingEntry->purchase_invoice_line_id,
71+
];
72+
}
73+
74+
public function collection()
75+
{
76+
return AccountingEntry::whereIn('id', $this->AccountingEntryId)->get();
77+
78+
}
79+
}

app/Http/Controllers/Workflow/InvoicesController.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -195,12 +195,4 @@ public function update(UpdateInvoiceRequest $request)
195195

196196
return redirect()->route('invoices.show', ['id' => $Invoice->id])->with('success', 'Successfully updated Invoice');
197197
}
198-
199-
/**
200-
* @return \Illuminate\Contracts\View\View
201-
*/
202-
public function export()
203-
{
204-
return view('workflow/invoice-lines-export');
205-
}
206198
}

app/Livewire/FecExportLines.php

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
<?php
2+
3+
namespace App\Livewire;
4+
5+
use Livewire\Component;
6+
use Illuminate\Http\Response;
7+
use Illuminate\Support\Collection;
8+
use Maatwebsite\Excel\Facades\Excel;
9+
use App\Models\Accounting\AccountingEntry;
10+
use App\Exports\AccountingEntryLinesExport;
11+
12+
class FecExportLines extends Component
13+
{
14+
public $FecExportLineslist;
15+
public $data = [];
16+
17+
//export
18+
public Collection $selectedFecLine;
19+
20+
// Filtres
21+
public $journal_code_filters = ['ACHAT', 'VENT']; // Par défaut, on affiche ACHAT et VENT
22+
public $start_date;
23+
public $end_date;
24+
25+
public function mount()
26+
{
27+
$this->selectedFecLine = collect();
28+
}
29+
30+
public function render()
31+
{
32+
// Filtrer les lignes d'entrée comptable
33+
$query = AccountingEntry::where('exported', false);
34+
35+
// Appliquer le filtre sur journal_code
36+
if (!empty($this->journal_code_filters)) {
37+
$query->whereIn('journal_code', $this->journal_code_filters);
38+
}
39+
40+
// Appliquer le filtre sur la plage de dates
41+
if ($this->start_date) {
42+
$query->where('accounting_date', '>=', $this->start_date);
43+
}
44+
if ($this->end_date) {
45+
$query->where('accounting_date', '<=', $this->end_date);
46+
}
47+
48+
$this->FecExportLineslist= $query->get();
49+
50+
return view('livewire.fec-export-lines', [
51+
'FecExportLineslist' => $this->FecExportLineslist,
52+
]);
53+
}
54+
55+
private function getSelectedFecLine()
56+
{
57+
return $this->selectedFecLine->filter(fn($p) => $p)->keys();
58+
}
59+
60+
public function export($ext)
61+
{
62+
if(!in_array($ext, ['csv', 'xlsx', 'pdf'])){
63+
abort(Response::HTTP_NOT_FOUND);
64+
}
65+
66+
// Utiliser les ids sélectionnés
67+
$selectedFecLines = $this->selectedFecLine->filter(fn($p) => $p);
68+
69+
// Marquer les lignes comme exportées
70+
AccountingEntry::whereIn('id', $selectedFecLines)->update(['exported' => true]);
71+
72+
73+
// Vider la collection après l'export
74+
$this->selectedFecLine = collect();
75+
76+
return Excel::download(new AccountingEntryLinesExport($selectedFecLines), 'FecLines.'. $ext);
77+
78+
}
79+
80+
// Mise à jour du filtre journal_code
81+
public function toggleJournalCodeFilter($code)
82+
{
83+
if (in_array($code, $this->journal_code_filters)) {
84+
$this->journal_code_filters = array_diff($this->journal_code_filters, [$code]);
85+
} else {
86+
$this->journal_code_filters[] = $code;
87+
}
88+
}
89+
90+
public function applyFilters()
91+
{
92+
// Rafraîchir la composante pour appliquer les filtres
93+
$this->render();
94+
}
95+
96+
public function toggleSelected($id)
97+
{
98+
// Ajouter ou retirer de la collection
99+
if ($this->selectedFecLine->contains($id)) {
100+
$this->selectedFecLine = $this->selectedFecLine->filter(fn($line) => $line != $id);
101+
} else {
102+
$this->selectedFecLine->push($id);
103+
}
104+
}
105+
}

app/Livewire/InvoiceExportLines.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
class InvoiceExportLines extends Component
1313
{
1414
public $InvoiceExportLineslist;
15-
public $code, $label, $companies_id, $companies_addresses_id, $companies_contacts_id, $user_id;
1615
public $data = [];
1716

1817
//export
@@ -23,7 +22,6 @@ public function mount()
2322
$this->selectedInvoiceLine = collect();
2423
}
2524

26-
2725
public function render()
2826
{
2927
$InvoiceExportLineslist = $this->InvoiceExportLineslist = InvoiceLines::where('exported', false) // Filter only non-exported lines

app/Models/Accounting/AccountingEntry.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class AccountingEntry extends Model
3030
'currency_code',
3131
'invoice_line_id',
3232
'purchase_invoice_line_id',
33+
'exported'
3334
];
3435

3536
// Cast to specific data types
@@ -38,9 +39,9 @@ class AccountingEntry extends Model
3839
'justification_date' => 'date',
3940
'lettering_date' => 'date',
4041
'validation_date' => 'date',
42+
'document_date' => 'date',
4143
'debit_amount' => 'decimal:2',
4244
'credit_amount' => 'decimal:2',
43-
'currency_code' => 'decimal:2',
4445
];
4546

4647
// Example relationships (if necessary)

config/adminlte.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -434,12 +434,6 @@
434434
'url' => 'invoices',
435435
'icon_color' => 'warning',
436436
],
437-
[
438-
'text' => 'export_invoices_lines_list_trans_key',
439-
'url' => 'invoices/export',
440-
'icon_color' => 'info',
441-
],
442-
443437
[
444438
'text' => 'credit_notes_trans_key',
445439
'url' => 'credit-notes',

database/migrations/2024_10_21_214507_create_accounting_entries_table.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public function up(): void
3434
$table->string('currency_code', 15)->nullable(); // Montant en devise
3535
$table->unsignedBigInteger('invoice_line_id', 3)->nullable();
3636
$table->unsignedBigInteger('purchase_invoice_line_id', 3)->nullable();
37+
$table->boolean('exported')->default(false);
3738
$table->timestamps(); // Created at and updated at
3839
});
3940
}

resources/lang/en/general_content.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@
6565
'with_serial_number_trans_key' => 'With serial number',
6666
'sale_trans_key' => 'Sale',
6767
'purchase_stock_trans_key' => 'Purchase (stock)',
68-
'tax_trans_key' => 'Tax',
6968
'advance_payment_trans_key' => 'Advance payment',
7069
'advance_payment_vat_trans_key' => 'Advance payment (with VAT)',
7170
'productive_trans_key' => 'Productive',
@@ -350,6 +349,7 @@
350349
'permission_trans_key' => 'Permission',
351350
'role_in_permissions_trans_key' => 'Roles in permissions',
352351
'estimated_budget_trans_key' => 'Estimated Budget',
352+
'export_fec_trans_key' => 'Export FEC',
353353
'customer_import_trans_key' => 'Customer import',
354354
'quotes_import_trans_key' => 'Quotes import',
355355
'orders_import_trans_key' => 'Orders import',

resources/lang/fr/general_content.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@
6565
'with_serial_number_trans_key' => 'Avec numéro de lot',
6666
'sale_trans_key' => 'Vente',
6767
'purchase_stock_trans_key' => 'Achat (stock)',
68-
'tax_trans_key' => 'Taxe',
6968
'advance_payment_trans_key' => 'Acompte',
7069
'advance_payment_vat_trans_key' => 'Acompte avec TVA',
7170
'productive_trans_key' => 'Productive',
@@ -350,6 +349,7 @@
350349
'permission_trans_key' => 'Permission',
351350
'role_in_permissions_trans_key' => 'Rôles dans les permissions',
352351
'estimated_budget_trans_key' => 'Objectif CA',
352+
'export_fec_trans_key' => 'Export FEC',
353353
'customer_import_trans_key' => 'Import client',
354354
'quotes_import_trans_key' => 'Import devis',
355355
'orders_import_trans_key' => 'Import commande',

resources/views/admin/factory-import-export.blade.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,23 @@
1010
<div class="card">
1111
<div class="card-header p-2">
1212
<ul class="nav nav-pills">
13-
<li class="nav-item "><a class="nav-link active" href="#CustomerImport" data-toggle="tab">{{ __('general_content.customer_import_trans_key') }}</a></li>
13+
<li class="nav-item "><a class="nav-link active" href="#FECExport" data-toggle="tab">{{ __('general_content.export_fec_trans_key') }}</a></li>
14+
<li class="nav-item "><a class="nav-link" href="#InvoicesExport" data-toggle="tab">{{ __('general_content.invoices_export_trans_key') }}</a></li>
15+
<li class="nav-item "><a class="nav-link" href="#CustomerImport" data-toggle="tab">{{ __('general_content.customer_import_trans_key') }}</a></li>
1416
<li class="nav-item "><a class="nav-link" href="#QuotesImport" data-toggle="tab">{{ __('general_content.quotes_import_trans_key') }}</a></li>
1517
<li class="nav-item "><a class="nav-link" href="#OrderImport" data-toggle="tab">{{ __('general_content.orders_import_trans_key') }}</a></li>
1618
<li class="nav-item "><a class="nav-link" href="#ProductImport" data-toggle="tab">{{ __('general_content.products_import_trans_key') }}</a></li>
1719
</ul>
1820
</div>
1921
<div class="card-body">
2022
<div class="tab-content">
21-
<div class="tab-pane active" id="CustomerImport">
23+
<div class="tab-pane active" id="FECExport">
24+
@livewire('fec-export-lines')
25+
</div>
26+
<div class="tab-pane" id="InvoicesExport">
27+
@livewire('invoice-export-lines')
28+
</div>
29+
<div class="tab-pane" id="CustomerImport">
2230
@include('include.alert-result')
2331
<form method="POST" action="{{ route('companies.import') }}" enctype="multipart/form-data">
2432
@csrf

0 commit comments

Comments
 (0)