<?php

use App\Model\account\JournalModel;

Auth::routes();
// Language Controller
Route::get('/en', 'LanguageController@en')->name('en');
Route::get('/km', 'LanguageController@km')->name('km');
Auth::routes(['verify' => true]);
Route::group(['namespace' => 'FrontEnd'], function () {
    Route::GET('/', 'HomeController@home')->name('home');
});
Route::group(['middleware' => 'seller', ['auth'], 'namespace' => 'seller'], function () {
    route::resource('seller-dashboard', 'SellerDashboardController');
});
//item
Route::group(['middleware' => 'Administrator', ['auth'], 'namespace' => 'Administrator\product'], function () {
    route::resource('product-color', 'ColorController');
    route::resource('product-size', 'SizeController');
    route::resource('product-brand', 'BrandController');
    route::resource('category', 'CategoryController');
    route::resource('unit', 'UnitController');
    route::resource('products', 'ProductController');
    route::resource('material', 'MaterialController');
    route::resource('fabric', 'FabricController');
    route::resource('cut-piece', 'CutPieceController');

    route::GET('get-edit-brand/{id}', 'BrandController@get_edit')->name('get-edit-brand');
    route::POST('update-brand', 'BrandController@update')->name('update-brand');
    route::match(['GET', 'POST'], 'brand-import-excel', 'BrandController@import_excel')->name('brand-import-excel');

    route::GET('get-edit-size/{id}', 'SizeController@get_edit')->name('get-edit-size');
    route::POST('update-size', 'SizeController@update')->name('update-size');
    route::match(['GET', 'POST'], 'size-import-excel', 'SizeController@import_excel')->name('size-import-excel');

    route::match(['GET', 'POST'], 'category-import-excel', 'CategoryController@import_excel')->name('category-import-excel');

    route::GET('get-material/{id}', 'MaterialController@get_material')->name('get-material');
    route::GET('get-product/{id}', 'ProductController@get_product')->name('get-product');
    route::GET('material-destroy/{id}', 'MaterialController@delete')->name('material-destroy');
    route::GET('fabric-destroy/{id}', 'FabricController@delete')->name('fabric-destroy');
    route::GET('cut-piece-destroy/{id}', 'CutPieceController@delete')->name('cut-piece-destroy');

    route::GET('view-products', 'ProductController@view_product')->name('products.view');
    Route::GET('show-products/{id}', 'ProductController@show')->name('products.show');
    Route::GET('products-status', 'ProductController@product_changeStatus')->name('products.status');

    route::GET('delete-products/{id}', 'ProductController@destroy')->name('products.delete');
    route::GET('datatable-products-list', 'ProductController@datatable_products_list')->name('datatable_products');

    Route::GET('products-print-barcode', 'ProductController@print_barcode')->name('products-print-barcode');
    Route::match(['GET', 'POST'], 'products-import-exel', 'ProductController@import_exel')->name('products-import-exel');
    Route::match(['GET', 'POST'], 'fabric-import-exel', 'FabricController@import_exel')->name('fabric-import-exel');
    Route::match(['GET', 'POST'], 'material-import-exel', 'MaterialController@import_exel')->name('material-import-exel');
    Route::match(['GET', 'POST'], 'products-upload-image', 'ProductController@upload_image')->name('products-upload-image');
    Route::get('products-image-list', 'ProductController@img_list')->name('products-image-list');

    route::match(['GET', 'POST'], 'color-import-excel', 'ColorController@import_excel')->name('color-import-excel');
    route::match(['GET', 'POST'], 'unit-import-excel', 'UnitController@import_excel')->name('Unit-import-excel');


});
//====================PeoPle======================
Route::group(['middleware' => 'pos', ['auth'], 'namespace' => 'Administrator\people'], function () {
    Route::resource('customer', 'CustomerController');
    route::resource('driver', 'DriverController');
    Route::resource('users', 'UserController');
    Route::match(['POST', 'GET'], 'user-status/{user_id}', 'UserController@user_status')->name('user-status');
});
Route::group(['middleware' => 'Administrator', ['auth'], 'namespace' => 'Administrator\people'], function () {
    route::resource('tailor', 'TailorController');
    route::resource('suppliers', 'SupplierController');
    route::GET('get-edit-tailor/{id}', 'TailorController@get_edit')->name('get-edit-tailor');
    route::POST('update-tailor', 'TailorController@update')->name('update-tailor');
    Route::get('suppliers-delete', 'SupplierController@delete_sup')->name('suppliers.delete');
    route::GET('show-new-suppliers', 'SupplierController@get_new_suppliers');
    route::GET('datatable-history-suppliers', 'SupplierController@datatable_history_suppliers')->name('datatable_history_suppliers');
});

Route::group(['middleware' => 'Administrator', ['auth'], 'namespace' => 'Administrator\setup'], function () {
    Route::resource('branch', 'BranchController');
    Route::resource('packers', 'PackerController');
    Route::post('insert-branch', 'BranchController@insertBranch')->name('insert.branch');
    Route::resource('member-package', 'MemberPackageController');
    Route::resource('member-type', 'MemberTypeController');
    Route::match(['GET', 'POST'], 'member-package-import-exel', 'MemberPackageController@import_exel')->name('member-package-import-exel');
    route::match(['GET', 'POST'], 'member-type-import-excel', 'MemberTypeController@import_excel')->name('member-type-import-excel');
});
Route::group(['middleware' => 'pos', ['auth'], 'namespace' => 'Administrator\setup'], function () {
    route::resource('warehouse', 'WarehouseController');
    route::get('warehouse-delete', 'WarehouseController@destroy_wh')->name('warehouse.delete');
    route::get('/warehouse-changeStatus', 'WarehouseController@warehouse_changeStatus')->name('warehouse_changeStatus');
});
Route::group(['middleware' => 'Administrator', ['auth'], 'namespace' => 'Administrator'], function () {
    Route::resource('roles', 'RoleController');
    Route::resource('permissions', 'PermissionController');

    Route::resource('currency', 'CurrencyController');
    Route::get('seller', 'people\UserController@seller')->name('seller.index');
    route::get('currency-changeStatus', 'CurrencyController@currency_changeStatus')->name('currency-changeStatus');
    Route::GET('app-dashboard', 'DashboardAdministratorController@index')->name('app_dashboard');
    Route::GET('currency-history', 'CurrencyController@history')->name('currency-history');

});

//===============================Production Request============================================
Route::group(['middleware' => 'Administrator', ['auth'], 'namespace' => 'Administrator\production'], function () {
    route::resource('production-request', 'ProductionRequestController');

    Route::get('production-delete/{production_id}', 'ProductionRequestController@destroy')->name('production-delete');

    Route::match(['GET', 'POST'], 'production-request-add-more', 'ProductionRequestController@add_more')->name('production-request-add-more');
    Route::get('production-request-generate-template', 'ProductionRequestController@gen_template')->name('production-request-generate-template');
    Route::get('production-request-get-return-item-list/{production_id}', 'ProductionRequestController@get_return_item_list')->name('production-request-get-return-item-list');
    Route::get('production-request-get-cut-piece-stock-by-tailor', 'ProductionRequestController@getCutPieceStock')->name('production-request-get-cut-piece-stock-by-tailor');
    Route::match(['GET', 'POST'], 'production-request-get-return-item-form/{production_id}', 'ProductionRequestController@get_return_item_form')->name('production-request-get-return-item-form');
    Route::get('production-done-view/{done_id}', 'ProductionRequestController@view_done')->name('production-done-view');
    Route::get('production-request-done/{production_id}', 'ProductionRequestController@done')->name('production-request-done');
    //===============================Production Cutting============================================
    Route::resource('production-cutting', 'ProductionCuttingController');
    Route::post('production-cutting-approve-status', 'ProductionCuttingController@update_status')->name('production-cutting-approve-status');

    // show return item and import stock
    Route::get('get-production-cutting-return', 'ProductionCuttingController@return_cutting')->name('get-production-cutting-return');
    Route::post('import-production-cutting-to-stock', 'ProductionCuttingController@import_stock')->name('import-production-cutting-to-stock');

    // get done and save
    Route::get('get-cut-piece-exported', 'ProductionCuttingController@get_exported')->name('get-cut-piece-exported');
    Route::post('done-cut-piece-exported', 'ProductionCuttingController@save_exported')->name('done-cut-piece-exported');

    // show return history
    Route::get('production-cutting-return-history/{id}', 'ProductionCuttingController@return_history')->name('production-cutting.return-history');


    //===============================Production Packing============================================
    Route::resource('production-packing', 'PackingController');
    Route::match(['POST', 'GET'], 'production-packing-import-stock/{id}', 'PackingController@import_stock')->name('production-packing-import-stock');
    Route::match(['POST', 'GET'], 'production-packing-return-to-production/{id}', 'PackingController@return_production')->name('production-packing-return-to-production');
    Route::match(['POST', 'GET'], 'production-packing-done/{id}', 'PackingController@done')->name('production-packing-done');
    Route::get('production-packing-import-stock-list/{id}', 'PackingController@import_list')->name('production-packing-import-stock-list');
    Route::get('production-packing-return-to-production-list/{id}', 'PackingController@return_list')->name('production-packing-return-to-production-list');
    Route::get('production-packing-import-show/{id}', 'PackingController@show_import')->name('production-packing-import-show');
    Route::match(['POST', 'GET'], 'production-packing-add-payment/{packing}', 'PackingController@add_payment')->name('production-packing-add-payment');
    Route::get('production-packing-payment-list/{packing}', 'PackingController@payment_list')->name('production-packing-payment-list');

    //===============================Production Template============================================
    Route::resource('production-template', 'ProductionTemplateController');
    Route::get('production-template-find-material-unit', 'ProductionTemplateController@find_material_detail')->name('production-template-find-material-unit');
    Route::get('production-template-find-material-price', 'ProductionTemplateController@find_material_price')->name('production-template-find-material-price');


    Route::resource('production-payments', 'ProductionPaymentController');
    Route::get('tailor-payable', 'ProductionPaymentController@tailor_payable')->name('tailor-payable');
    Route::get('tailor-stock-item', 'ProductionPaymentController@tailor_stock')->name('tailor-stock-item');
    Route::get('production-item-cost', 'ProductionPaymentController@item_cost')->name('production-item-cost');

});

//++++++++++++++++++++++++++ Branch +++++++++++++++++++++++++++++
Route::group(['middleware' => 'Branch', ['auth'], 'namespace' => 'Branch'], function () {
    Route::resource('dashboard-branch', 'BranchDashboardController');
    //-------------------------------Seller Request--------------------------------------------
    Route::resource('saller-request', 'SallerRequestController');
    Route::get('update-status-saller-request/{status}', 'SallerRequestController@update_status');
    Route::get('update-seen-saller-request', 'SallerRequestController@update_seen')->name('update-seen-sale-request');
});
route::get('/currency-checkbox', 'Administrator\people\UserController@currency_checkbox')->name('currency-checkbox');

//===============================Stock adjustment============================================
Route::group(['middleware' => 'pos', ['auth'], 'namespace' => 'Administrator\stock_adjustment'], function () {
    Route::resource('stock-adjustment', 'StockAdjustmentController');
});

//===============================CRM============================================
Route::group(['middleware' => 'pos', ['auth'], 'namespace' => 'CRM'], function () {
    Route::resource('prospect', 'LeadController');
    Route::resource('task', 'CRMTaskController');
    Route::resource('prospect-source', 'LeadSourceController');
    Route::patch('prospect-close-deal/{id?}', 'LeadController@closeDeal')->name('prospect.close_deal');
    Route::patch('task-complete/{id?}', 'CRMTaskController@complete')->name('task.complete');
    Route::get('prospect-report', 'LeadController@report');
    Route::get('prospect-report', 'LeadController@reportProspect');
    Route::get('upcoming-task', 'LeadController@upcoming_task')->name('upcoming-task');
    Route::get('abandon-prospect', 'LeadController@abandon_prospect')->name('abandon-prospect');
    Route::get('get-prospects', 'LeadController@get_prospects')->name('get-prospects');
    Route::get('prospect-destroy/{id}', 'LeadController@destroy')->name('prospect.destroy');
    Route::match(['PATCH', 'GET'], 'prospect-change-impression/{id}', 'LeadController@change_impression')->name('prospect-change-impression');
    Route::match(['PATCH', 'GET'], 'prospect-change-subject/{id}', 'LeadController@change_subject')->name('prospect-change-subject');
});


//===============================Public Route============================================
Route::get('get-notification-alert', 'Administrator\DashboardAdministratorController@getAlert')->name('get-notification-alert');




Route::get('select2-search-customer', 'Administrator\people\CustomerController@search_customer')->name('select2-search-customer');
Route::get('select2-search-product', 'Administrator\product\ProductController@search_product')->name('select2-search-product');
Route::get('select2-search-sale', 'pos\POSController@search_sale')->name('select2-search-sale');
Route::get('find-fabric', 'Administrator\production\ProductionCuttingController@find_fabric')->name('find-fabric');


Route::post('find-warehouse-by-branch', 'Administrator\setup\WarehouseController@get_select_warehouse')->name('find-warehouse-by-branch');
Route::post('find-warehouse-by-type', 'Administrator\setup\WarehouseController@find_warehouse_by_type')->name('find-warehouse-by-type');
Route::get('get-available-tailor-by-type', 'Administrator\setup\WarehouseController@getAvailableTailor')->name('get-available-tailor-by-type');
Route::get('search-product-by-name-code', 'Administrator\product\ProductController@getProductByCodename')->name('search-product-by-name-code');
Route::get('get-size-code-by-id', 'Administrator\product\ProductController@getSizeCode')->name('get-size-code-by-id');
Route::get('select2-search-lead', 'CRM\LeadController@search_lead')->name('select2-search-lead');

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

    Route::get('/clear-data', function () {


        $url = Request::url();
        if ($url === 'https://shr-brand-test.nsohost.com/clear-data'||$url === 'http://127.0.0.1:8000/clear-data') {
            DB::table('nso007_journal')->truncate();
            DB::table('nso007_user_cash_in_out')->truncate();
            DB::table('nso007_transfer_stock')->truncate();
            DB::table('nso007_transfer_stock_detail')->truncate();
            DB::table('nso007_stocks')->truncate();
            DB::table('nso007_sales_history')->truncate();
            DB::table('nso007_sales')->truncate();
            DB::table('nso007_sale_details_history')->truncate();
            DB::table('nso007_sale_details')->truncate();
            DB::table('nso007_purchases')->truncate();
            DB::table('nso007_purchase_order_detail')->truncate();
            DB::table('nso007_purchase_order')->truncate();
            DB::table('nso007_purchase_details')->truncate();
            DB::table('nso007_production_request_detail')->truncate();
            DB::table('nso007_production_request')->truncate();
            DB::table('nso007_production_packing_done_detail')->truncate();
            DB::table('nso007_production_packing_done')->truncate();
            DB::table('nso007_production_packing_detail')->truncate();
            DB::table('nso007_production_packing')->truncate();
            DB::table('nso007_production_done_detail')->truncate();
            DB::table('nso007_production_done')->truncate();
            DB::table('nso007_production_cutting_detail')->truncate();
            DB::table('nso007_production_cutting_cut_piece_size')->truncate();
            DB::table('nso007_production_cutting')->truncate();
            DB::table('nso007_product_return_detail')->truncate();
            DB::table('nso007_product_return')->truncate();
            DB::table('nso007_payment_detail')->truncate();
            DB::table('nso007_payment')->truncate();
            DB::table('nso007_journal')->truncate();
            DB::table('nso007_item_request_detail')->truncate();
            DB::table('nso007_item_request')->truncate();
            DB::table('nso007_cost_of_sold')->truncate();
            DB::table('nso007_clear_tailor_ar')->truncate();
            DB::table('nso007_adjustment_details')->truncate();
            DB::table('nso007_adjustment')->truncate();
            DB::table('nso007_track_stock')->truncate();
            DB::table('other_income_expenses')->truncate();
            return "Data is cleared";
        }
        return "no no bb";

    });
});
