#!/bin/bash
# Mobdie v1.5.1 — retrait des fichiers deplaces par le rangement.
# A lancer depuis la racine de l application, APRES extraction de l archive.
set -u
if [ ! -f artisan ] || [ ! -d app ]; then echo "ERREUR : lancez ce script depuis ~/public_html/app.mobdie.ma"; exit 1; fi
n=0
if [ -e "RAPPORT-FINAL.md" ]; then rm -f "RAPPORT-FINAL.md" && n=$((n+1)); fi
if [ -e "RAPPORT-UX-2026-07.md" ]; then rm -f "RAPPORT-UX-2026-07.md" && n=$((n+1)); fi
if [ -e "RAPPORT-V1.2-2026-07.md" ]; then rm -f "RAPPORT-V1.2-2026-07.md" && n=$((n+1)); fi
if [ -e "RAPPORT-V1.3.1.md" ]; then rm -f "RAPPORT-V1.3.1.md" && n=$((n+1)); fi
if [ -e "RAPPORT-V1.3.2.md" ]; then rm -f "RAPPORT-V1.3.2.md" && n=$((n+1)); fi
if [ -e "RAPPORT-V1.3.4.md" ]; then rm -f "RAPPORT-V1.3.4.md" && n=$((n+1)); fi
if [ -e "RAPPORT-V1.3.5.md" ]; then rm -f "RAPPORT-V1.3.5.md" && n=$((n+1)); fi
if [ -e "RAPPORT-V1.3.6.md" ]; then rm -f "RAPPORT-V1.3.6.md" && n=$((n+1)); fi
if [ -e "RAPPORT-V1.3.7.md" ]; then rm -f "RAPPORT-V1.3.7.md" && n=$((n+1)); fi
if [ -e "RAPPORT-V1.3.8.md" ]; then rm -f "RAPPORT-V1.3.8.md" && n=$((n+1)); fi
if [ -e "RAPPORT-V1.3.md" ]; then rm -f "RAPPORT-V1.3.md" && n=$((n+1)); fi
if [ -e "RAPPORT-V1.4.4.md" ]; then rm -f "RAPPORT-V1.4.4.md" && n=$((n+1)); fi
if [ -e "RAPPORT-V1.4.7.md" ]; then rm -f "RAPPORT-V1.4.7.md" && n=$((n+1)); fi
if [ -e "RAPPORT-V1.4.8.md" ]; then rm -f "RAPPORT-V1.4.8.md" && n=$((n+1)); fi
if [ -e "RAPPORT-V1.4.9.md" ]; then rm -f "RAPPORT-V1.4.9.md" && n=$((n+1)); fi
if [ -e "RAPPORT-V1.4.md" ]; then rm -f "RAPPORT-V1.4.md" && n=$((n+1)); fi
if [ -e "app/Console/Commands/ApparierPretForsa.php" ]; then rm -f "app/Console/Commands/ApparierPretForsa.php" && n=$((n+1)); fi
if [ -e "app/Console/Commands/CorrigerModeleIa.php" ]; then rm -f "app/Console/Commands/CorrigerModeleIa.php" && n=$((n+1)); fi
if [ -e "app/Console/Commands/ImportComptabilite.php" ]; then rm -f "app/Console/Commands/ImportComptabilite.php" && n=$((n+1)); fi
if [ -e "app/Console/Commands/ImportDomiciliation.php" ]; then rm -f "app/Console/Commands/ImportDomiciliation.php" && n=$((n+1)); fi
if [ -e "app/Console/Commands/ImporterFacturesHistoriques.php" ]; then rm -f "app/Console/Commands/ImporterFacturesHistoriques.php" && n=$((n+1)); fi
if [ -e "app/Console/Commands/NormaliserArchive.php" ]; then rm -f "app/Console/Commands/NormaliserArchive.php" && n=$((n+1)); fi
if [ -e "app/Console/Commands/RattacherComptesCourants.php" ]; then rm -f "app/Console/Commands/RattacherComptesCourants.php" && n=$((n+1)); fi
if [ -e "app/Console/Commands/ReconstruireTiers.php" ]; then rm -f "app/Console/Commands/ReconstruireTiers.php" && n=$((n+1)); fi
if [ -e "app/Console/Commands/RenommerArchive.php" ]; then rm -f "app/Console/Commands/RenommerArchive.php" && n=$((n+1)); fi
if [ -e "app/Console/Commands/RepererCompteCourant.php" ]; then rm -f "app/Console/Commands/RepererCompteCourant.php" && n=$((n+1)); fi
if [ -e "app/Console/Commands/RepererPiecesEtrangeres.php" ]; then rm -f "app/Console/Commands/RepererPiecesEtrangeres.php" && n=$((n+1)); fi
if [ -e "app/Console/Commands/VentilerTva.php" ]; then rm -f "app/Console/Commands/VentilerTva.php" && n=$((n+1)); fi
if [ -e "app/Exceptions/FacturePriseEnSerieException.php" ]; then rm -f "app/Exceptions/FacturePriseEnSerieException.php" && n=$((n+1)); fi
if [ -e "app/Filament/Pages/EnvoyerUnMessage.php" ]; then rm -f "app/Filament/Pages/EnvoyerUnMessage.php" && n=$((n+1)); fi
if [ -e "app/Filament/Resources/Accounts/AccountResource.php" ]; then rm -f "app/Filament/Resources/Accounts/AccountResource.php" && n=$((n+1)); fi
if [ -e "app/Filament/Resources/Accounts/Pages/ManageAccounts.php" ]; then rm -f "app/Filament/Resources/Accounts/Pages/ManageAccounts.php" && n=$((n+1)); fi
if [ -e "app/Filament/Resources/Courriers/CourrierResource.php" ]; then rm -f "app/Filament/Resources/Courriers/CourrierResource.php" && n=$((n+1)); fi
if [ -e "app/Filament/Resources/Courriers/Pages/ManageCourriers.php" ]; then rm -f "app/Filament/Resources/Courriers/Pages/ManageCourriers.php" && n=$((n+1)); fi
if [ -e "app/Filament/Resources/EmailTemplates/EmailTemplateResource.php" ]; then rm -f "app/Filament/Resources/EmailTemplates/EmailTemplateResource.php" && n=$((n+1)); fi
if [ -e "app/Filament/Resources/EmailTemplates/Pages/ManageEmailTemplates.php" ]; then rm -f "app/Filament/Resources/EmailTemplates/Pages/ManageEmailTemplates.php" && n=$((n+1)); fi
if [ -e "app/Filament/Resources/Invoices/InvoiceResource.php" ]; then rm -f "app/Filament/Resources/Invoices/InvoiceResource.php" && n=$((n+1)); fi
if [ -e "app/Filament/Resources/Invoices/Pages/CreateInvoice.php" ]; then rm -f "app/Filament/Resources/Invoices/Pages/CreateInvoice.php" && n=$((n+1)); fi
if [ -e "app/Filament/Resources/Invoices/Pages/EditInvoice.php" ]; then rm -f "app/Filament/Resources/Invoices/Pages/EditInvoice.php" && n=$((n+1)); fi
if [ -e "app/Filament/Resources/Invoices/Pages/ListInvoices.php" ]; then rm -f "app/Filament/Resources/Invoices/Pages/ListInvoices.php" && n=$((n+1)); fi
if [ -e "app/Filament/Resources/Invoices/Schemas/InvoiceForm.php" ]; then rm -f "app/Filament/Resources/Invoices/Schemas/InvoiceForm.php" && n=$((n+1)); fi
if [ -e "app/Filament/Resources/Invoices/Tables/InvoicesTable.php" ]; then rm -f "app/Filament/Resources/Invoices/Tables/InvoicesTable.php" && n=$((n+1)); fi
if [ -e "app/Filament/Resources/Lenders/LenderResource.php" ]; then rm -f "app/Filament/Resources/Lenders/LenderResource.php" && n=$((n+1)); fi
if [ -e "app/Filament/Resources/Lenders/Pages/ManageLenders.php" ]; then rm -f "app/Filament/Resources/Lenders/Pages/ManageLenders.php" && n=$((n+1)); fi
if [ -e "app/Filament/Resources/Quotes/Pages/CreateQuote.php" ]; then rm -f "app/Filament/Resources/Quotes/Pages/CreateQuote.php" && n=$((n+1)); fi
if [ -e "app/Filament/Resources/Quotes/Pages/EditQuote.php" ]; then rm -f "app/Filament/Resources/Quotes/Pages/EditQuote.php" && n=$((n+1)); fi
if [ -e "app/Filament/Resources/Quotes/Pages/ListQuotes.php" ]; then rm -f "app/Filament/Resources/Quotes/Pages/ListQuotes.php" && n=$((n+1)); fi
if [ -e "app/Filament/Resources/Quotes/QuoteResource.php" ]; then rm -f "app/Filament/Resources/Quotes/QuoteResource.php" && n=$((n+1)); fi
if [ -e "app/Filament/Resources/Quotes/Schemas/QuoteForm.php" ]; then rm -f "app/Filament/Resources/Quotes/Schemas/QuoteForm.php" && n=$((n+1)); fi
if [ -e "app/Filament/Resources/Quotes/Tables/QuotesTable.php" ]; then rm -f "app/Filament/Resources/Quotes/Tables/QuotesTable.php" && n=$((n+1)); fi
if [ -e "app/Filament/Resources/RawArchiveLines/Pages/ListRawArchiveLines.php" ]; then rm -f "app/Filament/Resources/RawArchiveLines/Pages/ListRawArchiveLines.php" && n=$((n+1)); fi
if [ -e "app/Filament/Resources/RawArchiveLines/RawArchiveLineResource.php" ]; then rm -f "app/Filament/Resources/RawArchiveLines/RawArchiveLineResource.php" && n=$((n+1)); fi
if [ -e "app/Filament/Resources/RecurringCharges/Pages/ManageRecurringCharges.php" ]; then rm -f "app/Filament/Resources/RecurringCharges/Pages/ManageRecurringCharges.php" && n=$((n+1)); fi
if [ -e "app/Filament/Resources/RecurringCharges/RecurringChargeResource.php" ]; then rm -f "app/Filament/Resources/RecurringCharges/RecurringChargeResource.php" && n=$((n+1)); fi
if [ -e "app/Filament/Resources/Tiers/Pages/ManageTiers.php" ]; then rm -f "app/Filament/Resources/Tiers/Pages/ManageTiers.php" && n=$((n+1)); fi
if [ -e "app/Filament/Resources/Tiers/TierResource.php" ]; then rm -f "app/Filament/Resources/Tiers/TierResource.php" && n=$((n+1)); fi
if [ -e "app/Filament/Resources/TransactionCategories/Pages/ManageTransactionCategories.php" ]; then rm -f "app/Filament/Resources/TransactionCategories/Pages/ManageTransactionCategories.php" && n=$((n+1)); fi
if [ -e "app/Filament/Resources/TransactionCategories/TransactionCategoryResource.php" ]; then rm -f "app/Filament/Resources/TransactionCategories/TransactionCategoryResource.php" && n=$((n+1)); fi
if [ -e "app/Filament/Resources/Transactions/Pages/ManageTransactions.php" ]; then rm -f "app/Filament/Resources/Transactions/Pages/ManageTransactions.php" && n=$((n+1)); fi
if [ -e "app/Filament/Resources/Transactions/TransactionResource.php" ]; then rm -f "app/Filament/Resources/Transactions/TransactionResource.php" && n=$((n+1)); fi
if [ -e "app/Mail/AlerteInterneMail.php" ]; then rm -f "app/Mail/AlerteInterneMail.php" && n=$((n+1)); fi
if [ -e "app/Mail/DocumentCommercialMail.php" ]; then rm -f "app/Mail/DocumentCommercialMail.php" && n=$((n+1)); fi
if [ -e "app/Mail/MessageMail.php" ]; then rm -f "app/Mail/MessageMail.php" && n=$((n+1)); fi
if [ -e "app/Mail/RelanceClientMail.php" ]; then rm -f "app/Mail/RelanceClientMail.php" && n=$((n+1)); fi
if [ -e "app/Models/Account.php" ]; then rm -f "app/Models/Account.php" && n=$((n+1)); fi
if [ -e "app/Models/Courrier.php" ]; then rm -f "app/Models/Courrier.php" && n=$((n+1)); fi
if [ -e "app/Models/EmailTemplate.php" ]; then rm -f "app/Models/EmailTemplate.php" && n=$((n+1)); fi
if [ -e "app/Models/Invoice.php" ]; then rm -f "app/Models/Invoice.php" && n=$((n+1)); fi
if [ -e "app/Models/InvoiceLine.php" ]; then rm -f "app/Models/InvoiceLine.php" && n=$((n+1)); fi
if [ -e "app/Models/Lender.php" ]; then rm -f "app/Models/Lender.php" && n=$((n+1)); fi
if [ -e "app/Models/LoanInstallment.php" ]; then rm -f "app/Models/LoanInstallment.php" && n=$((n+1)); fi
if [ -e "app/Models/LoanSchedule.php" ]; then rm -f "app/Models/LoanSchedule.php" && n=$((n+1)); fi
if [ -e "app/Models/Quote.php" ]; then rm -f "app/Models/Quote.php" && n=$((n+1)); fi
if [ -e "app/Models/QuoteLine.php" ]; then rm -f "app/Models/QuoteLine.php" && n=$((n+1)); fi
if [ -e "app/Models/RawArchiveLine.php" ]; then rm -f "app/Models/RawArchiveLine.php" && n=$((n+1)); fi
if [ -e "app/Models/RecurringCharge.php" ]; then rm -f "app/Models/RecurringCharge.php" && n=$((n+1)); fi
if [ -e "app/Models/RecurringChargeOccurrence.php" ]; then rm -f "app/Models/RecurringChargeOccurrence.php" && n=$((n+1)); fi
if [ -e "app/Models/Tier.php" ]; then rm -f "app/Models/Tier.php" && n=$((n+1)); fi
if [ -e "app/Models/Transaction.php" ]; then rm -f "app/Models/Transaction.php" && n=$((n+1)); fi
if [ -e "app/Models/TransactionCategory.php" ]; then rm -f "app/Models/TransactionCategory.php" && n=$((n+1)); fi
if [ -e "app/Observers/MouvementCompteCourantObserver.php" ]; then rm -f "app/Observers/MouvementCompteCourantObserver.php" && n=$((n+1)); fi
if [ -e "app/Policies/InvoicePolicy.php" ]; then rm -f "app/Policies/InvoicePolicy.php" && n=$((n+1)); fi
if [ -e "app/Policies/QuotePolicy.php" ]; then rm -f "app/Policies/QuotePolicy.php" && n=$((n+1)); fi
if [ -e "app/Services/AppariementPretForsa.php" ]; then rm -f "app/Services/AppariementPretForsa.php" && n=$((n+1)); fi
if [ -e "app/Services/ComptaReport.php" ]; then rm -f "app/Services/ComptaReport.php" && n=$((n+1)); fi
if [ -e "app/Services/CompteCourantAssocie.php" ]; then rm -f "app/Services/CompteCourantAssocie.php" && n=$((n+1)); fi
if [ -e "app/Services/DestinatairesEmail.php" ]; then rm -f "app/Services/DestinatairesEmail.php" && n=$((n+1)); fi
if [ -e "app/Services/EnvoiEmail.php" ]; then rm -f "app/Services/EnvoiEmail.php" && n=$((n+1)); fi
if [ -e "app/Services/FacturePdf.php" ]; then rm -f "app/Services/FacturePdf.php" && n=$((n+1)); fi
if [ -e "app/Services/Invoices/IntegriteSerie.php" ]; then rm -f "app/Services/Invoices/IntegriteSerie.php" && n=$((n+1)); fi
if [ -e "app/Services/Invoices/InvoiceService.php" ]; then rm -f "app/Services/Invoices/InvoiceService.php" && n=$((n+1)); fi
if [ -e "app/Services/JournalExport.php" ]; then rm -f "app/Services/JournalExport.php" && n=$((n+1)); fi
if [ -e "app/Services/Messagerie.php" ]; then rm -f "app/Services/Messagerie.php" && n=$((n+1)); fi
if [ -e "app/Services/Quotes/QuoteService.php" ]; then rm -f "app/Services/Quotes/QuoteService.php" && n=$((n+1)); fi
if [ -e "app/Services/RattachementCompteCourant.php" ]; then rm -f "app/Services/RattachementCompteCourant.php" && n=$((n+1)); fi
if [ -e "app/Services/RecurringChargeService.php" ]; then rm -f "app/Services/RecurringChargeService.php" && n=$((n+1)); fi
if [ -e "app/Support/CompteCourant.php" ]; then rm -f "app/Support/CompteCourant.php" && n=$((n+1)); fi
if [ -e "app/Support/Numerotation.php" ]; then rm -f "app/Support/Numerotation.php" && n=$((n+1)); fi
if [ -e "resources/views/emails/marque.blade.php" ]; then rm -f "resources/views/emails/marque.blade.php" && n=$((n+1)); fi
if [ -e "tests/Feature/AppariementPretForsaTest.php" ]; then rm -f "tests/Feature/AppariementPretForsaTest.php" && n=$((n+1)); fi
if [ -e "tests/Feature/ChaineFacturationTest.php" ]; then rm -f "tests/Feature/ChaineFacturationTest.php" && n=$((n+1)); fi
if [ -e "tests/Feature/ComptabiliteTest.php" ]; then rm -f "tests/Feature/ComptabiliteTest.php" && n=$((n+1)); fi
if [ -e "tests/Feature/CompteCourantAssocieTest.php" ]; then rm -f "tests/Feature/CompteCourantAssocieTest.php" && n=$((n+1)); fi
if [ -e "tests/Feature/CompteCourantUnifieTest.php" ]; then rm -f "tests/Feature/CompteCourantUnifieTest.php" && n=$((n+1)); fi
if [ -e "tests/Feature/CpcHorsTaxesTest.php" ]; then rm -f "tests/Feature/CpcHorsTaxesTest.php" && n=$((n+1)); fi
if [ -e "tests/Feature/EmailDocumentTest.php" ]; then rm -f "tests/Feature/EmailDocumentTest.php" && n=$((n+1)); fi
if [ -e "tests/Feature/EnvoiEmailTest.php" ]; then rm -f "tests/Feature/EnvoiEmailTest.php" && n=$((n+1)); fi
if [ -e "tests/Feature/FacturationTest.php" ]; then rm -f "tests/Feature/FacturationTest.php" && n=$((n+1)); fi
if [ -e "tests/Feature/FacturationV14Test.php" ]; then rm -f "tests/Feature/FacturationV14Test.php" && n=$((n+1)); fi
if [ -e "tests/Feature/JournalTest.php" ]; then rm -f "tests/Feature/JournalTest.php" && n=$((n+1)); fi
if [ -e "tests/Feature/NumerotationTest.php" ]; then rm -f "tests/Feature/NumerotationTest.php" && n=$((n+1)); fi
if [ -e "tests/Feature/RapportsComptablesTest.php" ]; then rm -f "tests/Feature/RapportsComptablesTest.php" && n=$((n+1)); fi
if [ -e "tests/Feature/RattachementCompteCourantTest.php" ]; then rm -f "tests/Feature/RattachementCompteCourantTest.php" && n=$((n+1)); fi
if [ -e "tests/Feature/RenduPdfTest.php" ]; then rm -f "tests/Feature/RenduPdfTest.php" && n=$((n+1)); fi
if [ -e "tests/Feature/RepriseFacturesHistoriquesTest.php" ]; then rm -f "tests/Feature/RepriseFacturesHistoriquesTest.php" && n=$((n+1)); fi
if [ -e "tests/Feature/SerieDesFacturesTest.php" ]; then rm -f "tests/Feature/SerieDesFacturesTest.php" && n=$((n+1)); fi
if [ -e "tests/Feature/ZoneEnvoiTest.php" ]; then rm -f "tests/Feature/ZoneEnvoiTest.php" && n=$((n+1)); fi
find app resources/views -type d -empty -delete 2>/dev/null
echo "$n fichier(s) deplace(s) retire(s)."
restants=$(find app -name "*.php" -newermt "1970-01-01" | wc -l); echo "$restants fichiers PHP dans app/ apres nettoyage."
