<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\UserPermissionController;
use App\Http\Middleware\AuthMiddleware;
use App\Http\Controllers\AuthController;
use App\Http\Controllers\loginController;
use App\Http\Controllers\UserController;
use App\Http\Controllers\Roles;
use App\Http\Controllers\PropertyController;
use App\Http\Controllers\CurrencyController;
use App\Http\Controllers\AccountsController;
use App\Http\Controllers\TaxController;
use App\Http\Controllers\ModulesController;
use App\Http\Controllers\CustomerController;
use App\Http\Controllers\SuppliersController;
use App\Http\Controllers\TenantsController;
use App\Http\Controllers\FloorController;
use App\Http\Controllers\RoomsController;
use App\Http\Controllers\ProcessJournalController;
use App\Http\Controllers\InvoiceController;
use App\Http\Controllers\ReceiptController;
use App\Http\Controllers\ProcessCashBookController;
use App\Http\Controllers\StatementsController;
use App\Http\Controllers\TransactionsListingController;
use App\Http\Controllers\AgeingAnalysisController;

// Ageing Analysis Routes
Route::get('/ageing/add', [AgeingAnalysisController::class, 'index'])->name('ageing.add');
Route::post('/ageing/add', [AgeingAnalysisController::class, 'store'])->name('ageing.add');
Route::get('/ageing/edit/{id}', [AgeingAnalysisController::class, 'edit'])->name('ageing.edit');
Route::put('/ageing/update/{id}', [AgeingAnalysisController::class, 'update'])->name('ageing.update');
Route::delete('/ageing/delete/{id}', [AgeingAnalysisController::class, 'destroy'])->name('ageing.delete');
// Route::get('/', function () { return view('login');});
// Route::post('/login', [loginController::class,'login'])->name('login');
// Route::get('/', function () { return view('login');})->name('logout');
Route::get('/', [AuthController::class,'login'])->name('');
Route::post('/login', [AuthController::class,'auth_login'])->name('');
Route::get('logout', [AuthController::class,'logout'])->name('');
//Landing Module

Route::group(['middleware'=> 'useradmin'], function () {
    Route::get('/Landing', [PropertyController::class, 'index'])->name('landing');

    //Roles Module
    Route::get('users/role', [Roles::class,'addRole'])->name("roles");
    Route::post("users/role", [Roles::class,"insertRole"])->name("");
    Route::post('/users/role/edit/{id}', [Roles::class,'updateRole'])->name('updateRole');
    Route::get('/Deleterole/{id}', [Roles::class,'deleteRole'])->name('deleteRole');

    // Route::post("users/role/add", [Roles::class,"insert"])->name("");
    // Route::put("users/role/{id}", [Roles::class,"upDateRole"])->name("");
    // Route::post("users/role/edit/{id}", [Roles::class,"update"])->name("");
    // Route::get("users/role/delete/{id}", [Roles::class,"delete"])->name("");

    //users module
    Route::get('users', [UserController::class,'list'])->name("");
    Route::get("users/add", [UserController::class,"add"])->name("");
    Route::post("users/add", [UserController::class,"insert"])->name("");
    Route::get("users/edit/{id}", [UserController::class,"edit"])->name("");
    Route::post("users/edit/{id}", [UserController::class,"update"])->name("");
    Route::get("users/delete/{id}", [UserController::class,"delete"])->name("");
    //User permissions
    Route::get('users/permissions/{id}', [UserController::class, 'addPermissions'])->name('user-permissions.addPermissions');
    Route::post('users/permissions/{id}', [UserController::class, 'savePermissions'])->name('user-permissions.savePermissions');

    // //trnasactions
    // Route::get('/fetch-transactions', [StatementsController::class, 'fetchAllTransactions'])->name('fetchAllTransactions');
    // Route::post('/fetch-transactions', [StatementsController::class, 'fetchAllTransactions'])->name('fetchAllTransactions');
    Route::get('/profile', [UserController::class, 'profile'])->name('users.profile');
    Route::post('/profile/update', [UserController::class, 'updateProfile'])->name('users.update_profile');
    Route::post('/profile/change-password', [UserController::class, 'changePassword'])->name('users.change_password');

    //property Module
Route::post('/Landing', [PropertyController::class,'Save'])->name('createProperty');
Route::get('/property/{code}/{name}', [PropertyController::class, 'showPropertyDetails'])->name('property.details');
Route::get('/propertyDelete/{code}/{name}', [PropertyController::class, 'deletePropertyDetails'])->name('property.delete');
Route::post('/EditLanding', [PropertyController::class,'Edit'])->name('editProperty');

//Currency module
Route::get('/Currency', [CurrencyController::class, 'index'])->name('Currency');
Route::post('/AddCurrency', [CurrencyController::class,'savecurrency'])->name('addcurrency');
Route::post('/EditCurrency', [CurrencyController::class,'editcurrency'])->name('editcurrency');
Route::get('/DeleteCurrency/{id}', [CurrencyController::class,'deletecurrency'])->name('deletecurrency');


//Tax module
Route::get('/Tax', [TaxController::class, 'index'])->name('tax');
Route::post('/AddTax', [TaxController::class,'addtax'])->name('addtax');
Route::post('/EditTax', [TaxController::class,'edittax'])->name('edittax');
Route::get('/DeleteTax/{id}', [TaxController::class,'deletetax'])->name('deletetax');


//Cash Book module
Route::get('/CashBook', [ModulesController::class, 'index'])->name('cashbook');
Route::post('/AddCashBook', [ModulesController::class,'addcashbook'])->name('addcashbook');
Route::post('/EditCashBook', [ModulesController::class,'editcashbook'])->name('editcashbook');
Route::get('/DeleteCashBook/{id}', [ModulesController::class,'deletecashbook'])->name('deletecashbook');



//Journals module
Route::get('/Journals', [ModulesController::class, 'journalsindex'])->name('journals');
Route::post('/AddJournal', [ModulesController::class,'addjournals'])->name('addjournals');
Route::post('/EditJournal', [ModulesController::class,'editjournals'])->name('editjournals');
Route::get('/DeleteJournal/{id}', [ModulesController::class,'deletejournals'])->name('deletejournals');

//Transaction Types module
Route::get('/TransactionTypes', [ModulesController::class, 'otheraccountsindex'])->name('otheraccounts');
Route::post('/AddOtherAccounts', [ModulesController::class,'addotheraccounts'])->name('addotheraccounts');
Route::post('/EditOtherAccounts', [ModulesController::class,'editotheraccounts'])->name('editotheraccounts');
Route::get('/DeleteOtherAccounts/{id}', [ModulesController::class,'deleteotheraccounts'])->name('deleteotheraccounts');



//Customer module
Route::get('/Customers', [CustomerController::class, 'index'])->name('customers');
Route::post('/AddCustomers', [CustomerController::class,'addcustomers'])->name('addcustomers');
Route::post('/EditCustomers', [CustomerController::class,'editcustomers'])->name('editcustomers');
Route::get('/DeleteCustomers/{id}', [CustomerController::class,'deletecustomers'])->name('deletecustomers');



//Suppliers module
Route::get('/Suppliers', [SuppliersController::class, 'index'])->name('suppliers');
Route::post('/AddSuppliers', [SuppliersController::class,'addsuppliers'])->name('addsuppliers');
Route::post('/EditSuppliers', [SuppliersController::class,'editsuppliers'])->name('editsuppliers');
Route::get('/DeleteSuppliers/{id}', [SuppliersController::class,'deletesuppliers'])->name('deletesuppliers');


//Tenants module
Route::get('/Tenants', [TenantsController::class, 'index'])->name('tenants');
Route::post('/AddTenants', [TenantsController::class,'addtenants'])->name('addtenants');
Route::post('/EditTenants', [TenantsController::class,'edittenants'])->name('edittenants');
Route::get('/DeleteTenants/{id}', [TenantsController::class,'deletetenants'])->name('deletetenants');


//Floors module
Route::get('/Floor', [FloorController::class, 'index'])->name('floors');
Route::post('/AddFloor', [FloorController::class,'addfloors'])->name('addfloors');
Route::post('/EditFloor', [FloorController::class,'editfloors'])->name('editfloors');
Route::get('/DeleteFloor/{id}', [FloorController::class,'deletefloors'])->name('deletefloors');


//Rooms module
Route::get('/Rooms', [RoomsController::class, 'index'])->name('rooms');
Route::post('/AddRooms', [RoomsController::class,'addrooms'])->name('addrooms');
Route::post('/EditRooms', [RoomsController::class,'editrooms'])->name('editrooms');
Route::get('/DeleteRooms/{id}', [RoomsController::class,'deleterooms'])->name('deleterooms');


//Home Currency module
Route::get('/HomeCurrency', [CurrencyController::class, 'homecurrencyindex'])->name('homeCurrency');
Route::post('/AddHomeCurrency', [CurrencyController::class,'savehomecurrency'])->name('addhomecurrency');
Route::post('/EditHomeCurrency', [CurrencyController::class,'edithomecurrency'])->name('edithomecurrency');
Route::get('/DeleteHomeCurrency/{id}', [CurrencyController::class,'deletehomecurrency'])->name('deletehomecurrency');


//rates

Route::get('/Rates', [CurrencyController::class, 'ratesindex'])->name('Rates');
Route::post('/AddRate', [CurrencyController::class,'saveRate'])->name('addRate');



//Account Type
Route::get('/AccountTypes', [AccountsController::class, 'index'])->name('accountType');
Route::post('/AddAccountTypes', [AccountsController::class,'Save'])->name('addAccountType');
Route::post('/EditAccountTypes', [AccountsController::class,'Edit'])->name('editAccountType');
Route::get('/DeleteAccountTypes/{id}', [AccountsController::class, 'deleteAccountTypes'])->name('deleteAccountTypes');

//Chart Of Accounts
Route::get('/MainAccounts', [AccountsController::class, 'mainAccountsIndex'])->name('mainAccounts');
Route::post('/AddMainAccounts', [AccountsController::class,'saveMainAccount'])->name('addMainAccount');
Route::post('/EditMainAccounts', [AccountsController::class,'editMainAccount'])->name('editMainAccount');
Route::get('/DeleteMainAccount/{id}', [AccountsController::class, 'deleteMainAccount'])->name('deleteMainAccount');
Route::get('/SubAccounts/{id}/{name}', [AccountsController::class, 'subAccountsIndex'])->name('subAccounts');
Route::post('/AddSubAccounts', [AccountsController::class,'saveSubAccount'])->name('addSubAccount');
Route::post('/EditSubAccounts', [AccountsController::class,'editSubAccount'])->name('editSubAccount');
Route::get('/DeleteSubAccounts/{id}/{AccCode}/{AccName}', [AccountsController::class,'deleteSubAccount'])->name('deleteSubAccount');

Route::get('/Dashboard', function () { return view('Dashboard');})->name('Dashboard');
//Journal Prossessing
Route::get('/JournalProcessing', function () { return view('JournalProcessing');})->name('journalprocessing');
Route::get('/ProcessJournal/{Type}', [ProcessJournalController::class, 'index'])->name('processjournal');
Route::post('/JournalTransaction', [ProcessJournalController::class,'savejournaltransaction'])->name('savejournaltransaction');
//Invoice
Route::get('/Invoice/{Type}', [InvoiceController::class, 'index'])->name('invoice');
Route::post('/SaveInvoice', [InvoiceController::class,'savetransaction'])->name('savetransaction');
Route::get('/PrintInvoice/{type}/{invoice}', [InvoiceController::class,'printinvoice'])->name('printinvoice');
Route::get('/DeleteInvoice/{ID}/{type}', [InvoiceController::class, 'deleteinvoice'])->name('deleteinvoice');
Route::post('/EditInvoice', [InvoiceController::class,'edittransaction'])->name('edittransaction');
//Bank Accounts
Route::get('/Bank', [AccountsController::class, 'bankIndex'])->name('bankIndex');
Route::post('/AddBank', [AccountsController::class,'savebank'])->name('savebank');
Route::post('/EditBank', [AccountsController::class,'editbank'])->name('editbank');
Route::get('/DeleteBank/{id}', [AccountsController::class, 'deletebank'])->name('deletebank');
//Receipt
Route::get('/Receipt/{Type}', [ReceiptController::class, 'index'])->name('receipt');
Route::post('/SaveReceipt', [ReceiptController::class,'savetransaction'])->name('savereceipt');
Route::get('/PrintReceipt/{type}/{invoice}', [ReceiptController::class,'printreceipt'])->name('printreceipt');
Route::get('/DeleteReceipt/{ID}/{type}', [ReceiptController::class, 'deletereceipt'])->name('deletereceipt');
Route::post('/EditReceipt', [ReceiptController::class,'edittransaction'])->name('editreceipt');
Route::get('/get-references/{accountcode}', [ReceiptController::class, 'getReferences'])->name('get-references');
//Cash Book
// Handle both with and without Type parameter
Route::get('/ProcessCashBook/{type?}', [ProcessCashBookController::class, 'index'])
    ->name('ProcessCashBook');
Route::post('/SaveProcessCashBook', [ProcessCashBookController::class,'savetransaction'])->name('saveProcessCashBook');

//Reports Statements
Route::get('/Statements/{Type}', [StatementsController::class, 'index'])->name('statements');
Route::post('/fetchTransactions', [StatementsController::class, 'fetchTransactions'])->name('fetchTransactions');
//Transaction Listing
Route::get('/TransactionListing/{Type}', [TransactionsListingController::class, 'index'])->name('Transactionlisting');
Route::post('/fetchTransactionsListing', [TransactionsListingController::class, 'fetchTransactions'])->name('fetchTransactionsListing');
//Affiliates Listings
Route::get('/Affiliateslisting/{Type}', [TenantsController::class, 'Affiliateslisting'])->name('Affiliateslisting');
Route::post('/Affiliateslisting', [TenantsController::class, 'fetchAffiliateslisting'])->name('fetchAffiliateslisting');
//ChartOfAccountsReport
Route::get('/ChartOfAccountsReport', [StatementsController::class, 'PrintChartOfAccounts'])->name('ChartOfAccountsReport');
Route::post('/ChartOfAccountsReport', [StatementsController::class, 'fetchAccountsByType'])->name('fetchChartOfAccounts');
//Cash Book Reports
Route::get('/CashBookReport', [StatementsController::class, 'indexCashBook'])->name('cashbookreport');
Route::post('/CashBookReport', [StatementsController::class, 'fetchCashBookReport'])->name('fetchCashBookReport');
//GL Reports
Route::get('/GeneralLedgerReport', [StatementsController::class, 'indexGeneralLedger'])->name('GeneralLedgerReport');
Route::post('/GeneralLedgerReport', [StatementsController::class, 'fetchGeneralLedger'])->name('fetchGeneralLedger');
//Tax Reports
Route::get('/TaxReport', [StatementsController::class, 'indexTax'])->name('TaxReport');
Route::post('/TaxReport', [StatementsController::class, 'fetchTax'])->name('fetchTax');
//summary Reports
Route::get('/RentSummaryReport', [StatementsController::class, 'indexRent'])->name('RentSummaryReport');
Route::post('/RentSummaryReport/data', [StatementsController::class, 'RentSummaryReport'])->name('RentSummaryReport.data');
//outstanding rent
Route::get('/OutstandingRentReport', [StatementsController::class, 'indexRentoutstanding'])->name('OutstandingRentReport');
Route::post('/OutstandingRentReport/data', [StatementsController::class, 'OutstandingRentReport'])->name('OutstandingRentReport.data');
//rent coollection report
Route::get('/RentCollectionReport', [StatementsController::class, 'indexRentCollection'])->name('RentCollectionReport');
Route::post('/RentCollectionReport/data', [StatementsController::class, 'RentCollectionReport'])->name('RentCollectionReport.data');
//Age Analysis Report
Route::get('/AgeAnalysisReport', [StatementsController::class, 'indexAgeAnalysis'])->name('AgeAnalysisReport');
Route::post('/AgeAnalysisReport/data', [StatementsController::class, 'AgeAnalysisReport'])->name('AgeAnalysisReport.data');

});
