<?php

use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Log;
use App\Http\Controllers\HomeController;
use App\Http\Controllers\MailController;
use App\Http\Controllers\RoleController;
use App\Http\Controllers\PermissionController;
use App\Http\Controllers\DataController;
use App\Http\Controllers\QuotationController;
use App\Http\Controllers\InvoiceController;
use App\Http\Controllers\CompanyController;
use App\Http\Controllers\UserController;
use App\Http\Controllers\PIController;
use App\Http\Controllers\CreditNoteController;
use App\Http\Controllers\ProductController;
use App\Http\Controllers\InventoryController;
use App\Http\Controllers\QuotationDataController;
use App\Http\Controllers\GeneratenumberController;
use App\Http\Controllers\BankDetailsController;

/*
|--------------------------------------------------------------------------
| 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('/', function () {
	
    return view('welcome');
});

Route::get('/thankyou', function () {
    return view('pages.thank_you');
});

Route::get('/profile', function () {
    return view('pages.profile');
});


Route::post('quotation-postmail',[MailController::class,'quotationsendmail'])->name('quotation-postmail');
Route::post('pi-postmail',[MailController::class,'pisendmail'])->name('pi-postmail');
Route::post('invoice-postmail',[MailController::class,'invoicesendmail'])->name('invoice-postmail');
Route::get('quotation-approval/{value}/{id}',[QuotationDataController::class,'Approval'])->name('quotation-approval');

Route::post('generatenumber',[GeneratenumberController::class,'generatenumber'])->name('generatenumber');


Auth::routes();

//Route::get('home', HomeController::class@index')->name('home');

Route::get('home', [HomeController::class, 'index'])->name('home');

// Route::group(['middleware' => ['auth']], function() {
    Route::resource('roles',RoleController::class);
    Route::resource('permissions',PermissionController::class);
    Route::resource('users',UserController::class);
    Route::resource('quotations',QuotationController::class);
    Route::get('/logout', [HomeController::class,'logout']);
    Route::get('getCity', [DataController::class,'getCity'])->name('City');
	Route::get('getStateFromcity', [DataController::class,'getStateFromCity'])->name('findStateFromCity');
	Route::get('getCityState', [DataController::class,'getCityState'])->name('findStateForCity');
	Route::post('city-store/{city?}{state_title?}',[DataController::class,'addCity'])->name('city-store');

	Route::get('exportFromttb', [InvoiceController::class,'ExportFromTTB'])->name('exportFromttb');
	Route::get('exportFromttbData', [InvoiceController::class,'getExportDatafromDate'])->name('exportFromttbData');
	Route::get('exportFromCPQData', [InvoiceController::class,'getExportDatafromDateCPQ'])->name('exportFromCPQData');
	Route::get('getExportFromCPQData', [InvoiceController::class,'getExportedData'])->name('getExportFromCPQData');
	
	Route::get('jsonCreate', [InvoiceController::class,'generateSingleInvoiceJson'])->name('jsonCreate');


// });


Route::group(['middleware' => ['auth']], function() {
    
    Route::get('iteams',[IteamController::class,'index'])->name('iteams.index');
    Route::get('createiteam/{id}',[IteamController::class,'create'])->name('iteams.createiteam');
    Route::patch('storeiteam',[IteamController::class,'store'])->name('iteams.storeiteam');
    Route::get('showiteam/{id}',[IteamController::class,'show'])->name('iteams.showiteam');
    Route::get('edititeam/{id}',[IteamController::class,'edit'])->name('iteams.edititeam');
    Route::patch('updateiteam/{id}',[IteamController::class,'update'])->name('iteams.updateiteam');
    Route::get('deleteiteam/{id}',[IteamController::class,'destroy'])->name('iteams.deleteiteam');
    Route::post('checkiteam',[IteamController::class,'check'])->name('iteams.checkiteam');
    Route::post('visiblecheck',[IteamController::class,'visiblecheck'])->name('iteams.visiblecheck');
    
});
    
Route::group(['middleware' => ['auth']], function() {
    
    Route::post('storerelation',[RelationController::class,'store'])->name('iteams.storerelation');
    Route::get('showrelation/{id}',[RelationController::class,'show'])->name('iteams.showrelation');
    Route::get('createrelation/{id}',[RelationController::class,'create'])->name('iteams.createrelation');
    Route::get('editrelation/{id}',[RelationController::class,'edit'])->name('iteams.editrelation');
    

});

Route::group(['middleware' => ['auth']], function() {

    Route::get('attributes',[AttributeController::class,'index'])->name('attributes.index');
    Route::get('create',[AttributeController::class,'create'])->name('attributes.create');
    Route::post('store',[AttributeController::class,'store'])->name('attributes.store');
    Route::get('delete/{id}',[AttributeController::class,'destroy'])->name('attributes.delete');
    Route::get('edit/{id}',[AttributeController::class,'edit'])->name('attributes.edit');
    Route::patch('update/{id}',[AttributeController::class,'update'])->name('attributes.update');
    
    Route::post('check',[AttributeController::class,'check'])->name('attributes.check');
    Route::post('checkdeletable',[AttributeController::class,'checkdeletable'])->name('attributes.checkdeletable');
});
 

Route::group(['middleware' => ['auth']], function() {
    
    Route::get('companies',[CompanyController::class,'index'])->name('companies');
    Route::post('companies-store',[CompanyController::class,'store'])->name('companies-store');
    Route::post('companies-edit',[CompanyController::class,'edit'])->name('companies-edit');
    Route::post('companies-update',[CompanyController::class,'update'])->name('companies-update');
    Route::post('companies-validation',[CompanyController::class,'validation'])->name('companies-validation');

    
    Route::post('destroycompany',[CompanyController::class,'destroy'])->name('destroycompany');

    Route::post('destroycompanyperm',[CompanyController::class,'destroyperm'])->name('destroycompanyperm');
    
    Route::post('trashcompany',[CompanyController::class,'trash'])->name('trashcompany');

    Route::post('restorecompany',[CompanyController::class,'restore'])->name('restorecompany');
    

    Route::post('destroyaddress',[CompanyController::class,'destroyShippingaddress'])->name('destroyaddress');
    
    Route::post('additionofaddress',[CompanyController::class,'NewShippingaddress'])->name('additionofaddress');
    
});


Route::group(['middleware' => ['auth']], function() {
     
    Route::post('quotation-store',[QuotationController::class,'store'])->name('quotation-store');

    Route::get('quotation-show/{id}',[QuotationController::class,'show'])->name('quotation-show');

    

    Route::post('product-store',[QuotationController::class,'productstore'])->name('product-store');

    Route::get('getCompany', [QuotationDataController::class,'getCompany'])->name('Company');

    Route::get('Companyfortable', [QuotationDataController::class,'getCompanyfortable'])->name('Companyfortable');

    Route::get('getcompanydetails', [QuotationDataController::class,'getCompanyDetails'])->name('getcompanydetails');

    Route::get('findBillingAddressFromCompny', [QuotationDataController::class,'getCompanyBillingAddress'])->name('findBillingAddressFromCompny');
    
    Route::get('findShippingAddressFromCompny', [QuotationDataController::class,'getCompanyShippingAddress'])->name('findShippingAddressFromCompny');
    
    Route::get('invoicelayout/{id}', [QuotationController::class,'invoicelayout'])->name('invoicelayout');

    Route::get('update', [QuotationController::class,'update'])->name('update');

    Route::get('getproduct', [QuotationDataController::class,'getproduct'])->name('getproduct');

    Route::get('getproductdetails', [QuotationDataController::class,'getproductdetails'])->name('getproductdetails');

    Route::get('quotation-mail', [QuotationController::class,'getmail'])->name('quotation-mail');

    Route::post('product-price',[QuotationDataController::class,'ckeckprice'])->name('product-price');

    Route::post('check-price',[QuotationDataController::class,'checkprice'])->name('check-price');

    Route::post('get-quotationdetail',[QuotationDataController::class,'getquotation'])->name('get-quotationdetail');
 
    Route::post('getproductname',[QuotationDataController::class,'getproductname'])->name('getproductname');

    Route::post('quotation-trash',[QuotationController::class,'trash'])->name('quotation-trash');

    Route::post('quotation-restore',[QuotationController::class,'restore'])->name('quotation-restore');

    Route::post('quotation-remove',[QuotationController::class,'destroy'])->name('quotation-remove');

    Route::post('quotation-removeperm',[QuotationController::class,'destroyperm'])->name('quotation-removeperm');

    Route::post('quotation-removeunsaved',[QuotationController::class,'destroyunsaved'])->name('quotation-removeunsaved');

    Route::post('quotation-setapproval',[QuotationDataController::class,'setapproval'])->name('quotation-setapproval');
    
     
});

 
 

Route::group(['middleware' => ['auth']], function() {
    
    Route::get('pi-index',[PIController::class,'index'])->name('pi-index');

    Route::get('pi-show/{id}',[PIController::class,'show'])->name('pi-show');

    Route::post('pi-store',[PIController::class,'store'])->name('pi-store');
 
    
    Route::post('pi-movetrash',[PIController::class,'destroy'])->name('pi-movetrash');
    

    Route::post('pi-viewtrash',[PIController::class,'trash'])->name('pi-viewtrash');

    Route::post('pi-restore',[PIController::class,'restore'])->name('pi-restore');
     
    Route::post('pi-removeperm',[PIController::class,'destroyperm'])->name('pi-removeperm');
    
    Route::get('get-quotationforpi', [PIDataController::class,'getquotation'])->name('get-quotationforpi');

    Route::post('getpidetail', [PIDataController::class,'getpidetail'])->name('getpidetail');

    Route::get('getquotationdetailsforpi', [PIDataController::class,'getquotationdetail'])->name('getquotationdetailsforpi');

    Route::post('pi-printoption', [PIDataController::class,'printoption'])->name('pi-printoption');
    

});


Route::group(['middleware' => ['auth']], function() {



    //product routes
    
        Route::get('products', [ProductController::class,'index'])->name('products');
    
        Route::get('products-add', [ProductController::class,'create'])->name('add_product');
    
        Route::post('products-save', [ProductController::class,'store'])->name('save_product');
    
        Route::get('products-search/{type}', [ProductController::class,'searchProduct'])->name('search_product');
    
        
    
        Route::get('products-view/{id}', [ProductController::class,'viewDetail'])->name('view_product_detail');
    
        Route::get('products-edit/{id}/{type}', [ProductController::class,'edit'])->name('edit_product');
    
        Route::post('products-update/{id}/{type}', [ProductController::class,'update'])->name('update_product');
    
        Route::get('product-serial-no', [ProductController::class,'getProductSerailNo'])->name('product_serial_no');
	
		Route::post('set-serial-no-master',[ProductController::class,'setSerialNoMaster'])->name('set_serial_no_master');
		Route::get('product-serial-no-barcode', [ProductController::class,'getProductSerailNoForBarcode'])->name('product_serial_no_barcode');

        //inventory routes
    
        Route::get('inventory', [InventoryController::class,'index'])->name('inventory');
    
        Route::get('inventory-dispatch', [InventoryController::class,'dispatchProduct'])->name('dispatch_product');
    
        Route::post('inventory/saveDispatch', [InventoryController::class,'saveDispatchProduct'])->name('save_dispatch_product');
    
        Route::get('inventory-sattlement', [InventoryController::class,'sattelementProduct'])->name('sattelment_product');
    
        Route::post('inventory/saveSattelment', [InventoryController::class,'saveSattelmentProduct'])->name('save_sattlement_product');
    
        Route::get('inventory/checkQuantity', [InventoryController::class,'checkIfQuantity'])->name('check_quantity');
    
        Route::get('invoice/search',[InventoryController::class,'searchInvoiceWithSKU'])->name('search_invoice');
    
        Route::get('print-barcode', [InventoryController::class,'printBarcode'])->name('barcode_print');
    
        Route::post('print-barcode-log', [InventoryController::class,'logPrintBarcode'])->name('log_barcode_print');
    
         Route::get('barcode-log', [InventoryController::class,'viewBarcodePrintLog'])->name('barcode_print_log_view');
    
        
    
    //    custom products routes
    
        Route::get('custom-products', [CustomProductController::class,'index'])->name('custom_products');
    
        Route::get('custom-products-add', [CustomProductController::class,'create'])->name('add_custom_product');
    
        Route::get('custom-products/import', [CustomProductController::class,'importFile'])->name('import_custom_product');
    
        Route::post('custom-products/save-file-data', [CustomProductController::class,'saveImportFileAndData'])->name('save_import_file_data');
    
        Route::post('custom-products/save', [CustomProductController::class,'store'])->name('save_custom_product');
    
        Route::get('custom-products/check-if-product', [CustomProductController::class,'isExistProduct'])->name('is_exist_product');
    
        Route::get('products/delete', [CustomProductController::class,'destroy'])->name('delete_product');
    

    
   
});


Route::group(['middleware' => ['auth']], function() 
{
	Route::post('invoice-store-without-pi',[InvoiceController::class,'storeInvoiceWithoutPi'])->name('invoice-store-without-pi');

	
	Route::post('product-store-invoice',[InvoiceController::class,'productstore'])->name('product-store-invoice');

    Route::get('invoice-index',[InvoiceController::class,'index'])->name('invoice-index');
    Route::get('bank-detail',[InvoiceController::class,'getBankDetails'])->name('bank-detail');

    Route::post('invoice-store',[InvoiceController::class,'store'])->name('invoice-store');

    Route::get('invoice-show/{id}',[InvoiceController::class,'show'])->name('invoice-show');

    Route::post('invoice-shippingshow',[InvoiceController::class,'shippingshow'])->name('invoice-shippingshow');
    
    Route::post('invoice-shippingadd',[InvoiceController::class,'shippingadd'])->name('invoice-shippingadd');

    Route::post('invoice-getdetailsforlabel',[InvoiceController::class,'detailsforlabel'])->name('invoice-getdetailsforlabel');
    
    Route::post('getinvoicedetail', [InvoiceController::class,'getinvoicedetail'])->name('getinvoicedetail');
    
    Route::post('invoice-viewtrash',[InvoiceController::class,'trash'])->name('invoice-viewtrash');

    Route::post('invoice-movetrash',[InvoiceController::class,'destroy'])->name('invoice-movetrash');

    Route::post('invoice-removeperm',[InvoiceController::class,'destroyperm'])->name('invoice-removeperm');

    Route::post('invoice-restore',[InvoiceController::class,'restore'])->name('invoice-restore');
    Route::post('invoice-cancel',[InvoiceController::class,'cancel'])->name('invoice-cancel');

    Route::get('invoice-getpi',[InvoiceController::class,'getpi'])->name('invoice-getpi');

    Route::get('invoice-pidetail',[InvoiceController::class,'pidetails'])->name('invoice-pidetail');

    Route::post('set-serialno',[InvoiceController::class,'setserialno'])->name('set-serialno');
    Route::post('get-serial-no',[InvoiceController::class,'getSerialNoData'])->name('get-serialno');
    

    Route::get('invoice-get-invoice',[InvoiceController::class,'getInvocieForSelect2'])->name('invoice-for-select2');
    // Route::get('cron','GeneratenumberController@cron')->name('cron');

    Route::get('cron-index',[CronController::class,'index'])->name('cron-index');

    Route::get('bank_details-index',[BankDetailsController::class,'index'])->name('bank_details-index');

    Route::post('run-cron',[GeneratenumberController::class,'cron'])->name('run-cron');

    Route::post('bankdetail-store',[BankDetailsController::class,'store'])->name('bankdetail-store');

    Route::post('getbankdetail',[BankDetailsController::class,'getdetail'])->name('getbankdetail');
   
    Route::post('bankdetail-update',[BankDetailsController::class,'update'])->name('bankdetail-update');

    Route::post('bankdetail-movetrash',[BankDetailsController::class,'destroy'])->name('bankdetail-movetrash');
    
    Route::post('bankdetail-trash',[BankDetailsController::class,'trash'])->name('bankdetail-trash');

    Route::post('bankdetail-deleteperm',[BankDetailsController::class,'destroyperm'])->name('bankdetail-deleteperm');

    Route::post('bankdetail-restore',[BankDetailsController::class,'restore'])->name('bankdetail-restore');

    
    Route::get('credit-note',[CreditNoteController::class,'index'])->name('credit-note-index');
	
	//--------------v2.0.0-------------------------------------//
	Route::post('invoice-removeunsaved',[InvoiceController::class,'destroyunsaved'])->name('invoice-removeunsaved');

});
