<?php

use Carbon\Carbon;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Route;
/*
|--------------------------------------------------------------------------
| 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 () {

//    $arr = [
//     "Wal-Mart Stores",
//     "Exxon Mobil",
//     "Chevron",
//     "Berkshire Hathaway",
//     "Apple",
//     "Phillips 66",
//     "General Motors",
//     "Ford Motor",
//     "General Electric",
//     "Valero Energy",
//     "AT&T",
//     "CVS Caremark",
//     "Fannie Mae",
//     "UnitedHealth Group",
//     "McKesson",
//     "Verizon Communications",
//     "Hewlett-Packard",
//     "J.P. Morgan Chase & Co.",
//     "Costco Wholesale",
//     "Express Scripts Holding",
//     "Bank of America",
//     "Cardinal Health",
//     "International Business Machines",
//     "Kroger",
//     "Marathon Petroleum",
//     "Citigroup",
//     "Archer Daniels Midland",
//     "AmerisourceBergen",
//     "Wells Fargo",
//     "Boeing",
//     "Procter & Gamble",
//     "Freddie Mac",
//     "Home Depot",
//     "Microsoft",
//     "Amazon.com",
//     "Target",
//     "Walgreen Co.",
//     "WellPoint",
//     "Johnson & Johnson",
//     "American International Group",
//     "State Farm Insurance Cos.",
//     "MetLife",
//     "PepsiCo",
//     "Comcast",
//     "United Technologies",
//     "Google",
//     "ConocoPhillips",
//     "Dow Chemical",
//     "Caterpillar",
//     "United Parcel Service",
//     "Pfizer",
//     "Lowe’s Companies",
//     "Intel Corporation",
//     "Energy Transfer Equity, L.P.",
//     "Cisco Systems, Inc.",
//     "Enterprise Products Partners L.P.",
//     "Aetna Inc.",
//     "The Coca-Cola Company",
//     "Lockheed Martin Corporation",
//     "Best Buy Co., Inc.",
//     "The Walt Disney Company",
//     "CHS Inc.",
//     "Sysco Corporation",
//     "FedEx Corporation",
//     "Merck & Co., Inc.",
//     "INTL FCStone Inc.",
//     "Safeway Inc.",
//     "Johnson Controls, Inc.",
//     "Ingram Micro Inc.",
//     "Plains GP Holdings, L.P.",
//     "World Fuel Services Corporation",
//     "Prudential Financial, Inc.",
//     "Humana Inc.",
//     "The Goldman Sachs Group, Inc.",
//     "Tesoro Corporation",
//     "Liberty Mutual Holding Company Inc.",
//     "Honeywell International Inc.",
//     "United Continental Holdings, Inc.",
//     "HCA Holdings, Inc.",
//     "Deere & Company",
//     "Delta Air Lines, Inc.",
//     "Oracle Corporation",
//     "Morgan Stanley",
//     "Hess Corporation",
//     "Twenty-First Century Fox, Inc.",
//     "E.I. du Pont de Nemours and Company",
//     "Sears Holdings Corporation",
//     "New York Life Insurance Company",
//     "Mondelez International, Inc.",
//     "American Express Company",
//     "Nationwide Mutual Insurance Co.",
//     "The Allstate Corporation",
//     "Tyson Foods, Inc.",
//     "Supervalu Inc.",
//     "TIAA-CREF",
//     "Massachusetts Mutual Life Insurance Company",
//     "CIGNA Corporation",
//     "DIRECTV",
//     "General Dynamics Corporation",
//     "Philip Morris International Inc.",
//     "3M Company",
//     "Time Warner Inc.",
//     "Halliburton Company",
//     "Publix Super Markets, Inc.",
//     "International Paper Company",
//     "McDonald’s Corporation",
//     "Macy’s, Inc.",
//     "The TJX Companies, Inc.",
//     "Fluor Corporation",
//     "Northwestern Mutual Life Insurance Company,Inc.",
//     "Tech Data Corporation",
//     "American Airlines Group Inc.",
//     "The Hartford Financial Services Group, Inc.",
//     "The Travelers Companies, Inc.",
//     "Nike, Inc.",
//     "Occidental Petroleum Corporation",
//     "Avnet, Inc.",
//     "Rite Aid Corporation",
//     "Exelon Corporation",
//     "Qualcomm Incorporated",
//     "Emerson Electric Co.",
//     "Northrop Grumman Corporation",
//     "Duke Energy Corporation",
//     "Capital One Financial Corporation",
//     "Aflac Incorporated",
//     "Raytheon Company",
//     "Staples, Inc.",
//     "EMC Corporation",
//     "Eli Lilly and Company",
//     "Alcoa Inc.",
//     "National Oilwell Varco, Inc.",
//     "Baker Hughes Incorporated",
//     "US Foods, Inc.",
//     "Time Warner Cable Inc.",
//     "Union Pacific Corporation",
//     "Abbott Laboratories",
//     "Xerox Corporation",
//     "Arrow Electronics, Inc",
//     "Kimberly-Clark Corporation",
//     "U.S. Bancorp",
//     "United Services Automobile Association",
//     "Freeport-McMoRan Copper & Gold Inc.",
//     "Icahn Enterprises L.P.",
//     "ManpowerGroup Inc.",
//     "HollyFrontier Corporation",
//     "Global Partners LP",
//     "The Goodyear Tire & Rubber Company",
//     "PBF Energy Inc.",
//     "Danaher Corporation",
//     "Nucor Corporation",
//     "Kohl’s Corporation",
//     "AbbVie Inc.",
//     "Whirlpool Corporation",
//     "Amgen Inc.",
//     "Jabil Circuit, Inc.",
//     "Kraft Foods Group, Inc.",
//     "The Progressive Corporation",
//     "CenturyLink, Inc.",
//     "General Mills, Inc.",
//     "Southwest Airlines Co.",
//     "Altria Group, Inc.",
//     "AutoNation, Inc.",
//     "Chesapeake Energy Corporation",
//     "Dollar General Corporation",
//     "TRW Automotive Holdings Corp.",
//     "United States Steel Corporation",
//     "Colgate-Palmolive Company",
//     "Cummins Inc.",
//     "PACCAR Inc",
//     "The Southern Company",
//     "Illinois Tool Works Inc.",
//     "The PNC Financial Services Group, Inc.",
//     "Medtronic, Inc.",
//     "The AES Corporation",
//     "Murphy USA Inc.",
//     "Bristol-Myers Squibb Company",
//     "Lear Corporation",
//     "The Gap, Inc.",
//     "Apache Corporation",
//     "eBay Inc.",
//     "The Bank of New York Mellon Corporation",
//     "CBS Corporation",
//     "PG&E Corporation",
//     "ConAgra Foods, Inc.",
//     "Computer Sciences Corporation",
//     "American Electric Power Company, Inc.",
//     "Western Digital Corporation",
//     "Marathon Oil Corporation",
//     "Baxter International Inc.",
//     "PPG Industries, Inc.",
//     "NextEra Energy, Inc.",
//     "Community Health Systems, Inc.",
//     "Loews Corporation",
//     "Penske Automotive Group, Inc.",
//     "FirstEnergy Corp.",
//     "Starbucks Corporation",
//     "Monsanto Company",
//     "Kellogg Company",
//     "Land O’Lakes, Inc.",
//     "ONEOK, Inc.",
//     "Omnicom Group Inc.",
//     "Anadarko Petroleum Corporation",
//     "EOG Resources, Inc.",
//     "DISH Network Corporation",
//     "Genuine Parts Company",
//     "Kinder Morgan, Inc.",
//     "Waste Management, Inc.",
//     "The Chubb Corporation",
//     "Aramark Holdings Corporation",
//     "Viacom Inc.",
//     "Las Vegas Sands Corp.",
//     "Dominion Resources, Inc.",
//     "Ecolab Inc.",
//     "Smithfield Foods, Inc.",
//     "Thermo Fisher Scientific Inc.",
//     "Yum! Brands, Inc.",
//     "Parker-Hannifin Corporation",
//     "Whole Foods Market, Inc.",
//     "Marriott International, Inc.",
//     "C. H. Robinson Worldwide, Inc.",
//     "L-3 Communications Holdings, Inc.",
//     "Edison International",
//     "Toys “R” Us, Inc.",
//     "Nordstrom, Inc.",
//     "Consolidated Edison, Inc.",
//     "Marsh & McLennan Companies, Inc.",
//     "Texas Instruments Incorporated",
//     "Textron Inc.",
//     "Tenet Healthcare Corporation",
//     "DaVita HealthCare Partners Inc.",
//     "CSX Corporation",
//     "Lincoln National Corporation",
//     "Praxair, Inc.",
//     "PPL Corporation",
//     "J.C. Penney Company, Inc.",
//     "Peter Kiewit Sons’, Inc.",
//     "Jacobs Engineering Group Inc.",
//     "Visa Inc.",
//     "H.J. Heinz Company",
//     "CarMax, Inc.",
//     "V.F. Corporation",
//     "Entergy Corporation",
//     "Automatic Data Processing, Inc.",
//     "NRG Energy, Inc.",
//     "Guardian Life Ins. Co. of America",
//     "Liberty Interactive Corporation",
//     "Norfolk Southern Corporation",
//     "Office Depot, Inc.",
//     "Ameriprise Financial, Inc.",
//     "Gilead Sciences, Inc.",
//     "Centene Corporation",
//     "Leucadia National Corporation",
//     "Huntsman Corporation",
//     "Health Net, Inc.",
//     "Stanley Black & Decker, Inc.",
//     "URS Corporation",
//     "Xcel Energy Inc.",
//     "Bed Bath & Beyond Inc.",
//     "Navistar International Corporation",
//     "Synnex Corporation",
//     "First Data Corporation",
//     "AGCO Corporation",
//     "L Brands, Inc.",
//     "Hertz Global Holdings, Inc.",
//     "CDW Corporation",
//     "CST Brands, Inc.",
//     "Sempra Energy",
//     "R.R. Donnelley & Sons Company",
//     "BB&T Corporation",
//     "Devon Energy Corporation",
//     "Family Dollar Stores, Inc.",
//     "Unum Group",
//     "Ally Financial Inc.",
//     "Reinsurance Group of America, Incorporated",
//     "State Street Corporation",
//     "Air Products & Chemicals, Inc.",
//     "Ross Stores, Inc.",
//     "The Sherwin-Williams Company",
//     "The Estée Lauder Companies Inc.",
//     "BlackRock, Inc.",
//     "Western Refining, Inc.",
//     "Avon Products, Inc.",
//     "The Mosaic Company",
//     "Public Service Enterprise Group Incorporated",
//     "Dean Foods Company",
//     "Cameron International Corporation",
//     "MGM Resorts International",
//     "KKR & Co. L.P.",
//     "Hilton Worldwide Holdings Inc.",
//     "DTE Energy Company",
//     "Genworth Financial, Inc.",
//     "Henry Schein, Inc.",
//     "Rock-Tenn Company",
//     "WellCare Health Plans, Inc.",
//     "W.W. Grainger, Inc.",
//     "Discover Financial Services",
//     "Eastman Chemical Company",
//     "Principal Financial Group, Inc.",
//     "Reliance Steel & Aluminum Co.",
//     "AutoZone, Inc.",
//     "Dover Corporation",
//     "Micron Technology, Inc.",
//     "Owens & Minor, Inc.",
//     "Assurant, Inc.",
//     "GameStop Corp.",
//     "Stryker Corporation",
//     "Group 1 Automotive, Inc.",
//     "Cognizant Technology Solutions Corporation",
//     "Sonic Automotive, Inc.",
//     "Autoliv, Inc.",
//     "Hormel Foods Corporation",
//     "Motorola Solutions, Inc.",
//     "Crown Holdings, Inc.",
//     "SunTrust Banks, Inc.",
//     "Campbell Soup Company",
//     "Fidelity National Financial, Inc.",
//     "HD Supply Holdings, Inc.",
//     "Caesars Entertainment Corporation",
//     "Darden Restaurants, Inc.",
//     "Weyerhaeuser Company",
//     "Ball Corporation",
//     "Precision Castparts Corp.",
//     "Masco Corporation",
//     "Universal Health Services, Inc.",
//     "Republic Services, Inc.",
//     "MasterCard Incorporated",
//     "Newmont Mining Corporation",
//     "Broadcom Corporation",
//     "Reynolds American Inc.",
//     "PVH Corp.",
//     "Charter Communications, Inc.",
//     "AECOM Technology Corporation",
//     "CenterPoint Energy, Inc.",
//     "Pacific Life",
//     "Thrivent Financial for Lutherans",
//     "Becton, Dickinson and Company",
//     "Franklin Resources, Inc.",
//     "Tenneco Inc.",
//     "TravelCenters of America LLC",
//     "Avis Budget Group, Inc.",
//     "Facebook, Inc.",
//     "Dollar Tree, Inc.",
//     "Corning Incorporated",
//     "Ashland Inc.",
//     "Sealed Air Corporation",
//     "Core-Mark Holding Company, Inc.",
//     "Oshkosh Corporation",
//     "Coca-Cola Enterprises, Inc.",
//     "WESCO International, Inc.",
//     "Applied Materials, Inc.",
//     "Visteon Corporation",
//     "BorgWarner Inc.",
//     "Spectrum Group International, Inc.",
//     "Oaktree Capital Group, LLC",
//     "Steel Dynamics, Inc.",
//     "Jarden Corporation",
//     "Mohawk Industries, Inc.",
//     "Terex Corporation",
//     "Northeast Utilities",
//     "KBR, Inc.",
//     "Fifth Third Bancorp",
//     "UGI Corporation",
//     "CBRE Group, Inc.",
//     "Quest Diagnostics Incorporated",
//     "Peabody Energy Corporation",
//     "The Hershey Company",
//     "Boston Scientific Corporation",
//     "FMC Technologies, Inc.",
//     "The Interpublic Group of Companies, Inc.",
//     "Commercial Metals Company",
//     "The Pantry, Inc.",
//     "Owens-Illinois, Inc.",
//     "American Family Ins. Group",
//     "Ralph Lauren Corporation",
//     "Biogen Idec Inc.",
//     "PetSmart, Inc.",
//     "Mylan Inc.",
//     "Symantec Corporation",
//     "Ameren Corporation",
//     "The Williams Companies, Inc.",
//     "Barnes & Noble, Inc.",
//     "Huntington Ingalls Industries, Inc.",
//     "The Priceline Group Inc.",
//     "Agilent Technologies, Inc.",
//     "Dana Holding Corporation",
//     "Dillard’s, Inc.",
//     "Seaboard Corporation",
//     "Vanguard Health Systems, Inc.",
//     "Casey’s General Stores, Inc.",
//     "O’Reilly Automotive, Inc.",
//     "The Blackstone Group L.P.",
//     "Mutual of Omaha Insurance Company",
//     "Molina Healthcare, Inc.",
//     "CMS Energy Corporation",
//     "Targa Resources Corp.",
//     "Quanta Services, Inc.",
//     "Cablevision Systems Corporation",
//     "Avery Dennison Corporation",
//     "Celanese Corporation",
//     "Foot Locker, Inc.",
//     "Celgene Corporation",
//     "Advance Auto Parts, Inc.",
//     "Mattel, Inc.",
//     "Live Nation Entertainment, Inc.",
//     "General Cable Corporation",
//     "Ryder System, Inc.",
//     "EMCOR Group, Inc.",
//     "Allergan, Inc.",
//     "W.R. Berkley Corporation",
//     "Rockwell Automation, Inc.",
//     "NetApp, Inc.",
//     "Ingredion Incorporated",
//     "Level 3 Communications, Inc.",
//     "Calpine Corporation",
//     "Omnicare, Inc.",
//     "Erie Insurance Group",
//     "SLM Corporation",
//     "D.R. Horton, Inc.",
//     "CC Media Holdings, Inc.",
//     "Anixter International Inc.",
//     "Dick’s Sporting Goods, Inc.",
//     "SanDisk Corporation",
//     "NCR Corporation",
//     "Starwood Hotels & Resorts Worldwide, Inc.",
//     "Expeditors International of Washington, Inc.",
//     "Fidelity National Information Services, Inc.",
//     "United Natural Foods, Inc.",
//     "Auto-Owners Insurance Group",
//     "Windstream Holdings, Inc.",
//     "Dr Pepper Snapple Group, Inc.",
//     "Lennar Corporation",
//     "Sanmina",
//     "Harley-Davidson, Inc.",
//     "CONSOL Energy Inc.",
//     "The J.M. Smucker Company",
//     "Newell Rubbermaid Inc.",
//     "CH2M HILL Companies, Ltd.",
//     "Energy Future Holdings Corp.",
//     "Susser Holdings Corporation",
//     "Laboratory Corporation of America Holdings",
//     "Kindred Healthcare, Inc.",
//     "Leidos Holdings Inc.",
//     "Booz Allen Hamilton Holding Corp.",
//     "The Jones Financial Companies,L.L.L.P.",
//     "Cliffs Natural Resources Inc.",
//     "PulteGroup, Inc.",
//     "Regions Financial Corporation",
//     "NiSource Inc.",
//     "Graybar Electric Company, Inc.",
//     "Integrys Energy Group, Inc.",
//     "The Clorox Company",
//     "Wynn Resorts, Limited",
//     "The Andersons, Inc.",
//     "J.B. Hunt Transport Services, Inc.",
//     "AK Steel Holding Corporation",
//     "Harbinger Group Inc.",
//     "MeadWestvaco Corporation",
//     "The Western Union Company",
//     "The Charles Schwab Corporation",
//     "Discovery Communications, Inc.",
//     "Spectra Energy Corp",
//     "St. Jude Medical, Inc.",
//     "CF Industries Holdings, Inc.",
//     "Con-way Inc.",
//     "Old Republic International Corporation",
//     "JetBlue Airways Corporation",
//     "Calumet Specialty Products Partners, L.P.",
//     "Kelly Services, Inc.",
//     "Domtar Corporation",
//     "Murphy Oil Corporation",
//     "Harris Corporation",
//     "Asbury Automotive Group, Inc.",
//     "Big Lots, Inc.",
//     "Advanced Micro Devices, Inc.",
//     "Owens Corning",
//     "Realogy Holdings Corp.",
//     "Host Hotels & Resorts, Inc.",
//     "MRC Global Inc.",
//     "Simon Property Group, Inc.",
//     "Tractor Supply Company",
//     "Gannett Co., Inc.",
//     "Alaska Air Group, Inc.",
//     "Insight Enterprises, Inc.",
//     "McGraw Hill Financial, Inc.",
//     "Buckeye Partners, L.P.",
//     "Quintiles Transnational Holdings Inc.",
//     "American Financial Group, Inc.",
//     "United Stationers Inc.",
//     "Coach, Inc.",
//     "LKQ Corporation",
//     "Noble Energy, Inc.",
//     "Bemis Company, Inc.",
//     "Joy Global Inc.",
//     "Wyndham Worldwide Corporation",
//     "NII Holdings, Inc.",
//     "Lorillard, Inc.",
//     "Alleghany Corporation",
//     "Airgas, Inc.",
//     "First American Financial Corporation",
//     "United Rentals, Inc."
//    ];
//    for($i = 0; $i < sizeof($arr); $i++){
//     DB::table('suppliers')->insert([
//         'company_id' => 5,
//         'name'  => $arr[$i],
//         'email' => "clinicplus{$i}@gmail.com",
//         'phone' => rand(999999999, 9999999999),
//         'tin_number' => rand(999999999, 9999999999),
//         'address' => 'Kigali, Kicukiro',
//         'created_by' => 3
//     ]);
//    }
// });

// Route::get('/unit', function(){
//     $arr = [
//         'G',
//         'Mg',
//         'L',
//         'Ml',
//         '%',
//         'Number',
//         'Meter',
//         'Cm',
//         'Piece',
//         'Tablet',
//         'Flacon',
//         'Strip',
//         'Bottle',
//         'Vial',
//         'Ampoule',
//         'Roll',
//         'Box',
//         'Pair',
//         'Set',
//         'Blister',
//         'Catheter',
//         'Blad',
//         'Sterile',
//         'Lancet',
//         'Tip',
//         'Container',
//         'Cell'
//     ];
//     $max = DB::table('units')->max('id') + 1; 
//     DB::statement("ALTER TABLE units AUTO_INCREMENT =  $max");
//     // for($i = 0; $i < sizeof($arr); $i++){
//     //     DB::table('units')->insert([
//     //         'name' => $arr[$i]
//     //     ]);
//     //    }
// });

// Route::get('/products',function(){
// $max = DB::table('products')->max('id') + 1; 
// DB::statement("ALTER TABLE products AUTO_INCREMENT =  $max");

// $max2 = DB::table('stock_receives')->max('id') + 1; 
// DB::statement("ALTER TABLE stock_receives AUTO_INCREMENT =  $max2");

// $max3 = DB::table('stockin_histories')->max('id') + 1; 
// DB::statement("ALTER TABLE stockin_histories AUTO_INCREMENT =  $max3");

// $receivedId = DB::table('stock_receives')->insertGetId([
//     'reference' => generateReference(20),
//     'company_id' => 1,
//     'date_received' => Carbon::now()->format('Y-m-d'),
//     'supplier_id'   => 1,
//     'amount'        => 0,
//     'vat'           => 'exclusive',
//     ]);
    
    // $products = DB::table('Sheet1')->get();  
    // foreach ($products as $product) {
    //     $productId = DB::table('products')->insertGetId([
    //         'code'=>generateRowCode(),
    //         'reference'=>generateReference(20),
    //         'company_id'=>1,
    //         'name'=>strtoupper($product->Product_Name),
    //         'cost_price'=> $product->cost_price,
    //         'category_id'=>$product->Category,
    //         'quantity'=>0,
    //         'created_by'=>2,
    //     ]);

        // DB::table('stockin_histories')->insert([
        //     'stockin_id' => $receivedId,
        //     'product_id' => $productId,	
        //     'quantity'   => $product->Quantity,	
        //     'price'      => 0,
        //     'expiration_date' => $product->Expiration_date ?? NULL,	
        //     'barcode'    => $product->Batch_Code ?? NULL
        // ]);
//    }
// });

// // Update Products Code
// Route::get('/products',function(){
//     $products = DB::table('products')
//                     ->join('stockin_histories', 'products.id', '=', 'stockin_histories.product_id')
//                     ->select('products.id','products.quantity','products.cost_price','products.code')
//                     ->orderBy('products.id')
//                     ->get();
//     foreach ($products as $product) {
//         $exp = DB::table('stockin_histories')->select(DB::raw('MAX(stockin_histories.expiration_date) as expiration_date'))->where('product_id',$product->id)->first();
//         DB::table('product_changes')->insert([
//             'product_id'    => $product->id,
//             'quantity'      => $product->quantity,
//             'price'         => $product->cost_price,
//             'batch_nber'    => $product->code ?? '000',
//             'expiration_date'  => $exp->expiration_date,
//             'created_by'     => 2
//         ]);
//     }
// });
