<?php

use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Auth;
use App\Http\Controllers\AuthController;
use App\Http\Controllers\Admin\DashboardController;
use App\Http\Controllers\Admin\UserController;
use App\Http\Controllers\Admin\RoleController;
use App\Http\Controllers\Admin\ProfileController;
use App\Http\Controllers\Admin\NotificationController;
use App\Http\Controllers\Admin\CompanyController;
use App\Http\Controllers\Admin\PlanController;
use App\Http\Controllers\Admin\AttendanceController;
use App\Http\Controllers\Admin\TeacherAttendanceController;
use App\Http\Controllers\Admin\TeacherController;
use App\Http\Controllers\Admin\WebsiteSettingController;

use App\Http\Controllers\Admin\hrms\AdminTaxController;


//======= account and finance
use App\Http\Controllers\Admin\accounting\BankingController;
use App\Http\Controllers\Admin\accounting\ItemController;
use App\Http\Controllers\Admin\accounting\CustomerController;
use App\Http\Controllers\Admin\accounting\PurchaseOrderController;
use App\Http\Controllers\Admin\accounting\InvoiceController;
use App\Http\Controllers\Admin\accounting\QuotesController;
use App\Http\Controllers\Admin\accounting\DeliveryChallanController;
use App\Http\Controllers\Admin\accounting\CreditNoteController;
use App\Http\Controllers\Admin\accounting\DebitNoteController;
use App\Http\Controllers\Admin\accounting\PurchaseBillController;
use App\Http\Controllers\Admin\accounting\ExpenseController;
use App\Http\Controllers\Admin\accounting\PaymentController;
use App\Http\Controllers\Admin\accounting\AdvancePaymentController;
use App\Http\Controllers\Admin\accounting\MasterController;
use App\Http\Controllers\Admin\accounting\AccountantController;
use App\Http\Controllers\Admin\accounting\ReportController;
use App\Http\Controllers\Admin\accounting\InventoryController;




/*
|--------------------------------------------------------------------------
| 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('/', [AuthController::class, 'login']);
// login Get POST
Route::get('/login', [AuthController::class, 'login']);
Route::post('/login', [AuthController::class, 'makeLogin'])->name('login');
Route::get('/logout', [AuthController::class, 'logout']);
Route::get('/plan/expired', [PlanController::class, 'expired'])->name('plan.expired');


Route::group(['middleware' => 'auth'], function () {
    Route::middleware(['planexpire'])->group(function () {
        
        Route::group(['middleware'=>'role:view-plan'],function(){
            Route::get('upgrade-plan',[PlanController::class,'allPlan']);
            Route::post('purchase-plan',[PlanController::class,'store']);
       });

            Route::get('dashboard', [DashboardController::class, 'dashboard'])->name('dashboard');
            
            
                //usher routes end
                
                //visitor category
                Route::group(['middleware' => 'role:add-category'],function () {
                    Route::get('category-list',[VisitorCategoryController::class,'index']);
                    Route::get('add-category',[VisitorCategoryController::class,'create']);
                    Route::post('save-category',[VisitorCategoryController::class,'saveCategory']);
                    Route::get('category-edit/{id}',[VisitorCategoryController::class,'editCategory']);
                    Route::post('edit-category/{id}',[VisitorCategoryController::class,'updateCategory']);
                    Route::get('category-delete/{id}',[VisitorCategoryController::class,'deleteCategory']);
                    Route::post('delete-multiple-category',[VisitorCategoryController::class,'deleteMultiple']);
                });
                //company
                /*Route::get('company-list',[CompanyController::class,'index']);
                Route::get('add-company',[CompanyController::class,'addCompany']);
                Route::post('register-company',[CompanyController::class,'storeCompany']);
                Route::get('view-company/{id}',[CompanyController::class,'viewCompany']);
                Route::get('edit-company/{id}',[CompanyController::class,'editCompany']);
                Route::post('edit-company',[CompanyController::class,'updateCompany']);
                Route::get('delete-company/{id}',[CompanyController::class,'delete']);
                Route::post('filter-company',[CompanyController::class,'filterCompany']);
                Route::post('search-company',[CompanyController::class,'searchCompany']);
                Route::get('export-company',[CompanyController::class,'export']);
                Route::post('import-company',[CompanyController::class,'import']);
                Route::post('company-delete-multiple',[CompanyController::class,"deleteMultiple"]);
            */
            
            

            Route::get('profile', [ProfileController::class, 'profile']);
            Route::get('edit-profile', [ProfileController::class, 'edit_profile']);
            Route::post('edit-profile', [ProfileController::class, 'save_edit_profile']);
            Route::get('change-password', [ProfileController::class, 'change_password']);
            Route::post('change-password', [ProfileController::class, 'save_change_password']);
            Route::post('two-factor-change', [ProfileController::class, 'twoFactorCheck']);
            Route::post('change-loggedin-school', [ProfileController::class, 'change_school_session'])->name('change-loggedin-school');
            // Profile end =

            //notification
            Route::get('hrms/notification',[NotificationController::class,'index']);
            Route::get('hrms/add-notification',[NotificationController::class,'create']);
            Route::post('hrms/save-notification',[NotificationController::class,'saveNotification']);
            Route::get('hrms/edit-notification/{id}',[NotificationController::class,'editNotification']);
            Route::post('hrms/delete-notification',[NotificationController::class,'destroy']);
            Route::post('hrms/delete-multiple-notification',[NotificationController::class,'multipleDelete']);
            Route::post('hrms/notification-read',[NotificationController::class,'readStatus']);
            Route::get('hrms/view-notification/{id}',[NotificationController::class,'viewNotification']);


            //admin plan
            
            Route::get('plan',[PlanController::class,'index']);
            Route::get('add-notification',[PlanController::class,'create']);
            Route::post('save-notification',[PlanController::class,'saveNotification']);
            Route::get('edit-notification/{id}',[PlanController::class,'editNotification']);
            Route::post('delete-notification',[PlanController::class,'destroy']);
            Route::post('delete-multiple-notification',[PlanController::class,'multipleDelete']);


        //user routes
        // Users list ================================================
        Route::group(['middleware' => 'role:view-user'], function () {
            Route::get('users', [UserController::class, 'index']);
            Route::get('view-user/{id}', [UserController::class, 'show']);

            // Add User
            Route::group(['middleware' => 'role:add-user'], function () {
                Route::get('add-user', [UserController::class, 'create']);
                Route::post('add-user', [UserController::class, 'store']);
                Route::get('import-user', [UserController::class, 'importUser']);
                Route::post('import', [UserController::class, 'import'])->name('import');
            });

            // Edit User
            Route::group(['middleware' => 'role:edit-user'], function () {
                Route::get('user-password-reset/{id}', [UserController::class, 'user_password_reset']);
                Route::post('reset-user-password', [UserController::class, 'save_user_password_reset']);
                Route::get('edit-user/{id}', [UserController::class, 'edit']);
                Route::post('edit-user/{id}', [UserController::class, 'update']);
                // make admission
                Route::get('admin/make-admission/{id}', [UserController::class, 'makeAdmission']);
                Route::post('admin/make-admission/{id}', [UserController::class, 'saveAdmission']);
            });

            // Delete User
            Route::group(['middleware' => 'role:delete-user'], function () {
                Route::get('delete-user/{id}', [UserController::class, 'destroy']);
                Route::post('delete-multiple-users', [UserController::class, 'destroyAll']);
            });

            // View Users Devices
            Route::group(['middleware' => 'role:view-user-device'], function () {
                Route::get('devices/{id}', [UserController::class, 'userDeviceList']);
            });

            // Edit Delete Users Devices
            Route::group(['middleware' => 'role:delete-user-device'], function () {
                Route::get('device-delete/{id}', [UserController::class, 'deviceDestroy']);
                Route::post('device-change-status', [UserController::class, 'deviceChangeStatus']);
            });

            //========== website settings routes
            Route::get('account/website-settings',[WebsiteSettingController::class,'index']);
            Route::post('account/add-admin-detail',[WebsiteSettingController::class,'addAdminDetail']);
            Route::post('account/add-tax-slab',[WebsiteSettingController::class,'addTaxSlab']);
            Route::post('account/delete-tax-slab',[WebsiteSettingController::class,'deleteTax']);

            //=========== accountant routes
            Route::get('account/accounts-list',[AccountantController::class,'index']);

            //================ reports
            Route::get('hrms/reports',[ReportController::class,'index']);
        });
        // End Users list ==============================================

        // Roles & Permissions =========================================
        Route::group(['middleware' => 'role:view-role'], function () {
            Route::get('roles', [RoleController::class, 'index']);
            Route::get('view-role/{id}', [RoleController::class, 'show']);

            // add
            Route::group(['middleware' => 'role:add-role'], function () {
                Route::get('add-role', [RoleController::class, 'create']);
                Route::post('add-role', [RoleController::class, 'store']);
            });

            // edit
            Route::group(['middleware' => 'role:edit-role'], function () {
                Route::get('edit-role/{id}', [RoleController::class, 'edit']);
                Route::post('edit-role/{id}', [RoleController::class, 'update']);
            });

            // delete
            Route::group(['middleware' => 'role:delete-role'], function () {
                Route::get('delete-role/{id}', [RoleController::class, 'destroy']);
            });

            // view permission
            Route::group(['middleware' => 'role:view-role-permission'], function () {
                Route::get('permission/{id?}', [RoleController::class, 'permission_index']);
            });

            // Add edit delete permission
            Route::group(['middleware' => 'role:edit-role-permission'], function () {
                Route::get('add-permission/{role_id}', [RoleController::class, 'permission_create']);
                Route::post('add-permission/{role_id}', [RoleController::class, 'permission_store']);
                Route::get('delete-permission/{id}', [RoleController::class, 'permission_destroy']);
                // Create New Permission
                Route::post('add-new-permission', [RoleController::class, 'permission_add_new_permission']);
            });
        });
        // End Roles & Permissions ==========================

               
        //country code 
         
        Route::post('fetch-state',[CompanyController::class,'fetachState']);
        Route::post('search-city',[CompanyController::class,'searchCity']);
        Route::post('add-city',[CompanyController::class,'addCity']);
        Route::get('fetch-city',[CompanyController::class,'fetchCity']);

        


        //========================= account and finance routes ====================
        Route::group(['middleware' => 'role:view-bank'],function () {
                
            Route::get('account/bank',[BankingController::class,'index']);
            Route::get('account/add-bank',[BankingController::class,'create']);

            Route::group(['middleware' => 'role:add-bank'],function () {
                Route::post('account/add-bank',[BankingController::class,'store']);
            });
            Route::group(['middleware' => 'role:edit-bank'],function () {
                Route::get('account/edit-bank/{id}',[BankingController::class,'edit']);
            });
            Route::group(['middleware' => 'role:delete-bank'],function () {
                Route::delete('account/delete-bank',[BankingController::class,'delete']);
            });
            
        });

        Route::get('account/item',[ItemController::class,'index']);
        Route::get('account/add-item',[ItemController::class,'create']);
        Route::post('account/add-item',[ItemController::class,'store']);
        Route::get('account/edit-item/{id}',[ItemController::class,'edit']);
        Route::delete('account/delete-item',[ItemController::class,'delete']);

        Route::get('account/category',[ItemController::class,'categoryIndex']);
        Route::post('account/add-category',[ItemController::class,'addCategory']);
        Route::post('account/delete-category',[ItemController::class,'deleteCategory']);

        Route::post('account/add-unit',[ItemController::class,'addUnit']);
        Route::get('account/unit',[ItemController::class,'unitIndex']);
        Route::post('account/delete-unit',[ItemController::class,'deleteUnit']);
        Route::post('account/import-items',[ItemController::class,'importItems']);
        Route::get('account/export-items',[ItemController::class,'exportItems']);
        Route::post('account/multiple-delete-item',[ItemController::class,'deleteMultiple']);
        Route::post('account/delete-item',[ItemController::class,'delete']);
        Route::post('account/multiple-delete-unit',[ItemController::class,'multipleDeleteUnit']);
        Route::post('account/multiple-delete-category',[ItemController::class,'multipleDeleteCategory']);


        Route::get('account/vendor',[CustomerController::class,'index']);
        Route::get('account/add-vendor',[CustomerController::class,'vendorCreate']);
        Route::post('account/add-vendor',[CustomerController::class,'vendorStore']);
        Route::get('account/edit-vendor/{id}',[CustomerController::class,'vendorEdit']);
        Route::post('account/delete-multiple-vendor',[CustomerController::class,'deleteMultipleVendor']);
        Route::post('account/delete-vendor',[CustomerController::class,'deleteVendor']);

        
        Route::get('account/customer',[CustomerController::class,'customerIndex']);
        Route::get('account/add-customer',[CustomerController::class,'customerCreate']);
        Route::post('account/add-customer',[CustomerController::class,'customerStore']);
        Route::get('account/edit-customer/{id}',[CustomerController::class,'customerEdit']);
        Route::post('account/delete-multiple-vendor',[CustomerController::class,'deleteMultipleVendor']);
        Route::post('account/delete-vendor',[CustomerController::class,'deleteVendor']);
        Route::post('account/import-customer',[CustomerController::class,'importCustomer']);
        Route::get('account/export-customer',[CustomerController::class,'exportCustomer']);
        Route::post('account/import-vendor',[CustomerController::class,'importVendor']);
        Route::get('account/export-vendor',[CustomerController::class,'exportVendor']);

        Route::get('account/purchase-order',[PurchaseOrderController::class,'index']);
        Route::get('account/add-purchase-order',[PurchaseOrderController::class,'purchaseCreate']);
        Route::post('account/add-purchase-order',[PurchaseOrderController::class,'storePurchase']);
        Route::post('account/purchase-order-status',[PurchaseOrderController::class,'purchaseOrderStatus']);
        Route::post('account/delete-multiple-purchase-order',[PurchaseOrderController::class,'multipleDelete']);
        Route::post('account/delete-purchase-order',[PurchaseOrderController::class,'deletePurchase']);
        Route::get('account/edit-purchase-order/{id}',[PurchaseOrderController::class,'editPurchase']);
        Route::get('account/export-purchase-order',[PurchaseOrderController::class,'export']);
        
        Route::get('account/invoice',[InvoiceController::class,'index']);
        Route::get('account/add-invoice',[InvoiceController::class,'addInvoice']);
        Route::post('account/fetch-item',[InvoiceController::class,'fetchItem']);
        Route::post('account/add-invoice',[InvoiceController::class,'storeInvoice']);
        Route::get('account/edit-invoice/{id}',[InvoiceController::class,'editInvoice']);
        Route::post('account/delete-invoice',[InvoiceController::class,'deleteInvoice']);
        Route::post('account/multiple-delete-invoice',[InvoiceController::class,'deleteMultiple']);
        Route::get('account/get-invoice/{id}',[InvoiceController::class,'getInvoice']);
        Route::get('account/export-invoice',[InvoiceController::class,'exportInvoice']);
        Route::get('account/view-invoice/{id}',[InvoiceController::class,'viewInvoice']);
        

        Route::get('account/quotes',[QuotesController::class,'index']);
        Route::get('account/add-quotes',[QuotesController::class,'addQuotes']);
        Route::post('account/add-quotes',[QuotesController::class,'storeQuotes']);
        Route::get('account/edit-quotes/{id}',[QuotesController::class,'editQuotes']);
        Route::post('account/delete-quotes',[QuotesController::class,'deleteQuotes']);
        Route::post('account/multiple-delete-quotes',[QuotesController::class,'deleteMultiple']);
        Route::post('account/quotes-status-change',[QuotesController::class,'statusChange']);
        Route::get('account/export-quotes',[QuotesController::class,'export']);

        Route::get('account/delivery-challan',[DeliveryChallanController::class,'index']);
        Route::get('account/add-delivery-challan',[DeliveryChallanController::class,'create']);
        Route::post('account/add-delivery-challan',[DeliveryChallanController::class,'store']);
        Route::get('account/edit-delivery-challan/{id}',[DeliveryChallanController::class,'edit']);
        Route::post('account/delete-delivery-challan',[DeliveryChallanController::class,'delete']);
        Route::post('account/multiple-delete-delivery-challan',[DeliveryChallanController::class,'deleteMultiple']);
        Route::get('account/export-delivery-challan',[DeliveryChallanController::class,'export']);
        // Route::post('account/quotes-status-change',[QuotesController::class,'statusChange']);

        Route::get('account/credit-note',[CreditNoteController::class,'index']);
        Route::get('account/add-credit-note',[CreditNoteController::class,'create']);
        Route::post('account/add-credit-note',[CreditNoteController::class,'store']);
        Route::get('account/edit-credit-note/{id}',[CreditNoteController::class,'edit']);
        Route::post('account/delete-credit-note',[CreditNoteController::class,'delete']);
        Route::post('account/multiple-delete-credit-note',[CreditNoteController::class,'deleteMultiple']);
        Route::post('account/fetch-invoice-details',[CreditNoteController::class,'fetchInvoiceDetails']);
        Route::post('account/credit-note-status-change',[CreditNoteController::class,'statusChange']);
        Route::get('account/export-credit-note',[CreditNoteController::class,'export']);
        
        
        Route::get('account/debit-note',[DebitNoteController::class,'index']);
        Route::get('account/add-debit-note',[DebitNoteController::class,'create']);
        Route::post('account/add-debit-note',[DebitNoteController::class,'store']);
        Route::get('account/edit-debit-note/{id}',[DebitNoteController::class,'edit']);
        Route::post('account/delete-debit-note',[DebitNoteController::class,'delete']);
        Route::post('account/multiple-delete-debit-note',[DebitNoteController::class,'deleteMultiple']);
        Route::get('account/export-debit-note',[DebitNoteController::class,'export']);
        Route::post('account/debit-note-status-change',[DebitNoteController::class,'statusChange']);
        Route::post('account/fetch-bill-details',[DebitNoteController::class,'fetchBillDetails']);
        
        Route::get('account/purchase-bill',[PurchaseBillController::class,'index']);
        Route::get('account/add-purchase-bill',[PurchaseBillController::class,'create']);
        Route::post('account/add-purchase-bill',[PurchaseBillController::class,'store']);
        Route::get('account/edit-purchase-bill/{id}',[PurchaseBillController::class,'edit']);
        Route::post('account/delete-purchase-bill',[PurchaseBillController::class,'delete']);
        Route::post('account/multiple-delete-purchase-bill',[PurchaseBillController::class,'deleteMultiple']);
        Route::get('account/view-purchase-bill/{id}',[PurchaseBillController::class,'viewPurchaseBill']);
        Route::get('account/export-purchase-bill',[PurchaseBillController::class,'export']);
        Route::post('account/fetch-po-number',[PurchaseBillController::class,'fetchPurchaseOrder']);
        Route::get('account/view-purchase-bill-details/{id}',[PurchaseBillController::class,'showBill']);
        

        Route::get('account/expenses',[ExpenseController::class,'index']);
        Route::get('account/add-expenses',[ExpenseController::class,'create']);
        Route::post('account/add-expenses',[ExpenseController::class,'store']);
        Route::get('account/edit-expenses/{id}',[ExpenseController::class,'edit']);
        Route::post('account/delete-expenses',[ExpenseController::class,'delete']);
        Route::post('account/multiple-delete-expenses',[ExpenseController::class,'deleteMultiple']);
        Route::get('account/export-expenses',[ExpenseController::class,'export']);


        Route::post('account/add-account-expense',[ExpenseController::class,'addAccountExpense']);

        Route::get('account/payment',[PaymentController::class,'index']);
        Route::get('account/add-payment-receive',[PaymentController::class,'create']);
        Route::get('account/edit-payment-receive/{id}',[PaymentController::class,'edit']);
        Route::post('account/add-payment',[PaymentController::class,'store']);

        Route::post('account/delete-payment',[PaymentController::class,'delete']);
        Route::post('account/multiple-delete-payment',[PaymentController::class,'deleteMultiple']);
        Route::get('account/export-payment',[PaymentController::class,'export']);
        Route::post('account/add-payment-receive',[PaymentController::class,'storePaymentReceive']);
        Route::get('account/get-receipt/{id}',[PaymentController::class,'getReceipt']);


        Route::get('account/add-payment-made',[PaymentController::class,'paymentMadeAdd']);
        Route::post('account/add-payment-made',[PaymentController::class,'savePaymentMade']);
        Route::get('account/edit-payment-made/{id}',[PaymentController::class,'editPaymentMade']);

        Route::get('account/add-advance-payment-receive',[AdvancePaymentController::class,'advancePaymentReceive']);
        Route::post('account/add-advance-payment-receive',[AdvancePaymentController::class,'saveAdvancePaymentReceive']);

        Route::get('account/advance-payment',[AdvancePaymentController::class,'index']);
        Route::get('account/add-advance-payment-made',[AdvancePaymentController::class,'advancePaymentMade']);
        Route::post('account/add-advance-payment-made',[AdvancePaymentController::class,'saveAdvancePaymentMade']);
        Route::get('account/edit-advance-payment/{id}',[AdvancePaymentController::class,'edit']);
        Route::get('account/advance-payment-receipt/{id}',[AdvancePaymentController::class,'getReceipt']);
        Route::post('account/delete-advance-payment',[AdvancePaymentController::class,'delete']);
        Route::post('account/multiple-delete-advance-payment',[AdvancePaymentController::class,'deleteMultiple']);
        Route::get('account/export-advance-payment',[AdvancePaymentController::class,'export']);
        
        Route::get('account/expense-create',[MasterController::class,'index']);
        Route::post('account/delete-master-expense',[MasterController::class,'delete']);
        Route::post('account/multiple-delete-account-expenses',[MasterController::class,'deleteMultiple']);
           
            //=======fetch account
        
        // Account routes
        Route::prefix('account')->group(function () {
            // List views
            Route::get('fetch-bank', [AccountantController::class, 'index'])->name('account.bank');
            Route::get('fetch-cash', [AccountantController::class, 'cash'])->name('account.cash');
            Route::get('fetch-client', [AccountantController::class, 'client'])->name('account.client');
            Route::get('fetch-vendor', [AccountantController::class, 'vendor'])->name('account.vendor');
            Route::get('fetch-sales', [AccountantController::class, 'sales'])->name('account.sales');
            Route::get('fetch-purchase', [AccountantController::class, 'purchase'])->name('account.purchase');
            Route::get('fetch-expenses', [AccountantController::class, 'expenses']);
            Route::get('fetch-gst-received', [AccountantController::class, 'gstReceived']);
            Route::get('fetch-gst-payable', [AccountantController::class, 'gstPayable']);
        
        });

        // Reports routes
        Route::prefix('account')->group(function () {
            // List views
            Route::get('trial-balance', [ReportController::class, 'trial_balance']);
            Route::get('profit-and-loss',[ReportController::class, 'profit_and_loss']);
            //Route::get('day-book',[ReportController::class, 'dayBook']);
            Route::get('all-transactions',[ReportController::class, 'allTransaction']);
            Route::get('export-profit-and-loss',[ReportController::class, 'export_pl']);
            Route::get('balance-sheet',[ReportController::class, 'balanceSheet']);
            Route::get('export-balance-sheet',[ReportController::class, 'exportBalanceSheet']);
            Route::get('export-daily-transactions',[ReportController::class, 'exportDayBook']);

            //inventory
            Route::get('inventory', [InventoryController::class, 'index']);
            Route::get('inventory-items-details/{id}', [InventoryController::class, 'viewSoldItem']);
                       
                      
        });

        

           
            //=========== end account and finance =================================
    });      

});
Route::post("visitor-otp",[AuthController::class,"visitorOtp"]);
Route::post("visitor-otp-verify",[AuthController::class,"visitorOtpVerify"]);
Route::post("visitor-reset-password",[AuthController::class,"visitorResetPassword"]);
