<?php

// use Illuminate\Support\Facades\Route;
// use App\Http\Controllers\DashboardController;
// // use App\Http\Controllers\CarController;
// use App\Http\Controllers\CarController;
// use App\Http\Controllers\CustomerController;
// use Illuminate\Support\Facades\DB;
// // use App\Http\Controllers\CarSalesController;



// use App\Http\Controllers\Auth\AuthenticatedSessionController;
// use App\Http\Controllers\Auth\RegisteredUserController;






// /*
// |--------------------------------------------------------------------------
// | Web Routes
// |--------------------------------------------------------------------------
// |
// | Here is where you can register web routes for your application. These
// | routes are loaded by the RouteServiceProvider within a group which
// | contains the "web" middleware group. Now create something great!
// |
// */


// Route::get('/login', [AuthenticatedSessionController::class, 'create'])->name('login');
// Route::post('/login', [AuthenticatedSessionController::class, 'store']);
// Route::get('/register', [RegisteredUserController::class, 'create'])->name('register');
// Route::post('/register', [RegisteredUserController::class, 'store']);
// Route::post('/logout', [AuthenticatedSessionController::class, 'destroy'])->name('logout');






// Route::get('/', function () {
//     return view('welcome');
// });

// Route::get('/dashboard', [DashboardController::class, 'index'])->name('dashboard');
// // manage cars
// Route::get('/cars', [CarController::class, 'index'])->name('cars.index');
// Route::get('/cars/create', [CarController::class, 'create'])->name('cars.create');
// Route::post('/cars', [CarController::class, 'store'])->name('cars.store');

// Route::post('/cars/{id}', [CarController::class, 'update'])->name('cars.update');


// //Route::put('/cars/{id}', [CarController::class, 'update'])->name('cars.update');
// Route::delete('/cars/{id}', [CarController::class, 'destroy'])->name('cars.destroy');



// Route::get('/cars/{car}/print', [CarController::class, 'print'])
//      ->name('cars.print');





// /*
// |--------------------------------------------------------------------------
// | Web Routes
// |--------------------------------------------------------------------------
// |
// | Here is where you can register web routes for your application. These
// | routes are loaded by the RouteServiceProvider within a group which
// | contains the "web" middleware group. Now create something great!
// |
// */




// //cars insertion routes
// Route::get('/cars/create', [CarController::class, 'create'])->name('cars.create');
// Route::post('/cars', [CarController::class, 'store'])->name('cars.store');  
// Route::get('/cars/print/{id}', [CarController::class, 'print'])->name('cars.print');


// // view data
// Route::get('/cars', [CarController::class, 'index'])->name('cars.index');
// Route::delete('/cars/{id}', [CarController::class, 'destroy'])->name('cars.destroy');

// // all reports routs
// Route::get('/cars-reports', [CarController::class, 'indexreports'])->name('cars.reports');
// Route::get('/cars-reports/{id}', [CarController::class, 'showreports'])->name('cars.showreports');



// Route::resource('customers', CustomerController::class);

// // SAles
// Route::post('/save-sale-info', [CarController::class, 'saveSaleInfo'])->name('save.sale.info');
// Route::get('/cars/{car}/sell', [CarController::class, 'showSaleForm'])->name('cars.sell');
// Route::get('/cars/sale-entry', [CarController::class, 'createSaleEntry'])->name('cars.sale-entry');
// Route::get('/cars/{id}/sell', [CarController::class, 'showSaleForm'])->name('cars.sell');
// Route::post('/cars/sale/save', [CarController::class, 'saveSaleInfo'])->name('save.sale.info');
// Route::get('/car-sales', [CarController::class, 'showSales'])->name('car.sales');


// // Show individual sale
// Route::get('/car-sales/{id}', [CarController::class, 'showSale'])->name('car.sales.show');






// // Delete sale
// Route::delete('/car-sales/{id}', [CarController::class, 'destroySale'])->name('car.sales.destroy');

// // invoice view
// Route::get('/car-sales/{id}', [CarController::class, 'showSale'])->name('car.sales.show');

// // Invoice Print
// Route::get('/car-sales/print/{id}', [CarController::class, 'printInvoice'])->name('car.sales.print');






// // edit Report routes

// Route::get('/cars/{id}/edit', [CarController::class, 'edit'])->name('cars.edit');
// Route::put('/cars/{id}', [CarController::class, 'update'])->name('cars.update');
// Route::resource('cars', CarController::class);


// // edit Invoice routes
// // routes/web.php

// Route::get('cars/sales/{id}/edit', [CarController::class, 'editSale'])->name('edit.sale.info');

// // Define the route for updating a sale using the PUT method
// Route::put('cars/sale/save/{id}', [CarController::class, 'updateSale'])->name('update.sale.info');


// // Route::post('cars/sales/{id}/update', [CarController::class, 'updateSale'])->name('update.sale.info');





















use Illuminate\Support\Facades\Route;
use App\Http\Controllers\DashboardController;
use App\Http\Controllers\CarController;
use App\Http\Controllers\CustomerController;
use App\Http\Controllers\Auth\AuthenticatedSessionController;
use App\Http\Controllers\Auth\RegisteredUserController;
use App\Http\Controllers\UserController;
use App\Http\Controllers\PurchaseInvoiceController;
use App\Http\Controllers\CommissionController;

use App\Http\Controllers\ExpenseController;
use App\Http\Controllers\ExpenseHeadController;

use App\Http\Controllers\InvestorController;

use App\Http\Controllers\InvestmentController;

use App\Http\Controllers\Auth\ForgotPasswordController;
use App\Http\Controllers\Auth\ResetPasswordController;



// Complaint Cell 

use App\Http\Controllers\ComplaintCellController;

Route::get('/complaint-cell',[ComplaintCellController::class,'create'])->name('complaint.create');

Route::post('/complaint-cell',[ComplaintCellController::class,'store'])->name('complaint.store');


/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
*/

// Public Routes (No login required)
Route::get('/login', [AuthenticatedSessionController::class, 'create'])->name('login');
Route::post('/login', [AuthenticatedSessionController::class, 'store']);
Route::get('/register-karoo', [RegisteredUserController::class, 'create'])->name('register');
Route::post('/register-karoo', [RegisteredUserController::class, 'store']);
Route::post('/logout', [AuthenticatedSessionController::class, 'destroy'])->name('logout');
Route::get('/users', [RegisteredUserController::class, 'index'])->name('users.index');


// Protected Routes (Login Required)
Route::middleware(['auth'])->group(function () {

    // Manage Users Routes
    Route::get('/users', [RegisteredUserController::class, 'index'])->name('users.index');
    Route::delete('/users/{id}', [UserController::class, 'destroy'])->name('users.destroy');



    

    // Show the form to request a password reset link
    Route::get('forgot-password', [ForgotPasswordController::class, 'showLinkRequestForm'])
        ->name('password.request');

    // Handle sending of reset link email
    Route::post('forgot-password', [ForgotPasswordController::class, 'sendResetLinkEmail'])
        ->name('password.email');

    // Show reset password form with token
    Route::get('reset-password/{token}', [ResetPasswordController::class, 'showResetForm'])
        ->name('password.reset');

    // Handle resetting the password
    Route::post('reset-password', [ResetPasswordController::class, 'reset'])
        ->name('password.update');

    // Route::get('/', function () {
    //     return view('welcome');
    // });

    Route::get('/', [DashboardController::class, 'index'])->name('dashboard');

    // Manage cars
    Route::resource('cars', CarController::class);
    Route::get('/cars/{car}/print', [CarController::class, 'print'])->name('cars.print');
    Route::get('/cars-reports', [CarController::class, 'indexreports'])->name('cars.reports');
    Route::get('/cars-reports/{id}', [CarController::class, 'showreports'])->name('cars.showreports');

    // Renew reverse
    Route::post('/cars/{car}/renew', [CarController::class, 'renew'])->name('cars.renew');


    // Sales
    Route::post('/save-sale-info', [CarController::class, 'saveSaleInfo'])->name('save.sale.info');
    Route::get('/cars/{car}/sell', [CarController::class, 'showSaleForm'])->name('cars.sell');
    Route::get('/cars/sale-entry', [CarController::class, 'createSaleEntry'])->name('cars.sale-entry');
    Route::post('/cars/sale/save', [CarController::class, 'saveSaleInfo'])->name('save.sale.info');
    Route::get('/car-sales', [CarController::class, 'showSales'])->name('car.sales');
    Route::get('/car-sales/{id}', [CarController::class, 'showSale'])->name('car.sales.show');
    Route::delete('/car-sales/{id}', [CarController::class, 'destroySale'])->name('car.sales.destroy');
    // first page
    Route::get('/car-sales/print/{id}', [CarController::class, 'printInvoice'])->name('car.sales.print');
    // second page
    Route::get('/car-sales/print2/{id}', [CarController::class, 'printInvoice2'])->name('car.sales.print2');


    // Edit and Update
    Route::get('/cars/{id}/edit', [CarController::class, 'edit'])->name('cars.edit');
    Route::put('/cars/{id}', [CarController::class, 'update'])->name('cars.update');

    Route::get('cars/sales/{id}/edit', [CarController::class, 'editSale'])->name('edit.sale.info');
    Route::put('cars/sale/save/{id}', [CarController::class, 'updateSale'])->name('update.sale.info');

    // Customers
    Route::resource('customers', CustomerController::class);
    Route::get('/customers/edit-unique/{id}', [CustomerController::class, 'editUnique'])->name('customers.editUnique');
    Route::put('/customers/update-unique/{id}', [CustomerController::class, 'updateUnique'])->name('customers.updateUnique');




    Route::get('/purchase-invoice/create', [PurchaseInvoiceController::class, 'create'])->name('purchase-invoice.create');
    Route::post('/purchase-invoice', [PurchaseInvoiceController::class, 'store'])->name('purchase-invoice.store');
    Route::resource('purchase-invoice', PurchaseInvoiceController::class);


    /// new for puchase and inpection mutual
    Route::get('/cars/create/{invoice?}', [CarController::class, 'create'])->name('cars.create');
    Route::get('/purchase-invoice/report/{id}', [PurchaseInvoiceController::class, 'report'])->name('purchase-invoice.report');

    // print purchase
    Route::get('/purchase-invoice/print/{id}', [PurchaseInvoiceController::class, 'print'])->name('purchase-invoice.print');

    // update invoice amount
    Route::patch('cars/sale/update-payment/{id}', [CarController::class, 'updatePayment'])->name('car.sales.update.payment');

    // invoice note update
    Route::post('/sales/{id}/update-note', [CarController::class, 'updateNote'])->name('sales.updateNote');


    // commission routes
    Route::post('/car-sales/{id}/commission', [CarController::class, 'storeCommission']) ->name('car.sales.store.commission');

    Route::resource('commissions', CommissionController::class);

    Route::get('/commission-reports', [App\Http\Controllers\CommissionReportController::class, 'index'])->name('commissions.reports');
    
    // routes/web.php
    Route::get('/commission-reports', [CommissionController::class, 'reports'])->name('commission.reports');
    
    // investments
    // Route::resource('investments', App\Http\Controllers\InvestmentController::class);

    Route::resource('investors', InvestorController::class)->only(['index','store']);
    Route::post('investors/{investor}/investment', [InvestorController::class, 'addInvestment'])->name('investors.addInvestment');
    Route::get('/investors/{investor}/statement', [InvestorController::class, 'statement'])
    ->name('investors.statement');


    // Expense routes
    Route::resource('expense-heads', ExpenseHeadController::class)->only(['index','store','destroy']);
    Route::resource('expenses', ExpenseController::class)->only(['index','store','destroy', 'edit', 'update']);



    Route::resource('investments', InvestmentController::class);




    // Complaint Cell 


    Route::get('/complaint-cell',[ComplaintCellController::class,'create'])->name('complaint.create');

    Route::post('/complaint-cell',[ComplaintCellController::class,'store'])->name('complaint.store');

    Route::get('/complaint-cell/list', [ComplaintCellController::class,'index'])->name('complaint.index');




    Route::get('/complaint-cell/{id}/edit', [ComplaintCellController::class, 'edit'])->name('complaint.edit');
    Route::put('/complaint-cell/{id}', [ComplaintCellController::class, 'update'])->name('complaint.update');
    


    Route::get('/complaint/export', [ComplaintCellController::class,'exportView'])->name('complaint.export.view');

    Route::post('/complaint/export', [ComplaintCellController::class,'export'] )->name('complaint.export');



    Route::post('/complaint/status',[ComplaintCellController::class,'storeStatus'])->name('complaint.status.store');
    


    Route::get('/complaint/{id}/print', [ComplaintCellController::class,'print'])->name('complaint.print');


    
    //New routes

    Route::get('/complaint/against/{id}', [ComplaintCellController::class,'getAgainst'] )->name('complaint.against');



    Route::post('/complaint/{id}/verify', [ComplaintCellController::class,'verifyComplaint'] ) ->name('complaint.verify');



    Route::get('/complaint/irrelevant', [ComplaintCellController::class,'irrelevant']) ->name('complaint.irrelevant');


});
