<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use DB;
use App\Jobs\Demo;
use App\Jobs\HSN;
use App\Jobs\price;

class GeneratenumberController extends Controller
{
   public function generatenumber(Request $request)
   {
        if($request->po_number)
        {
            
            $data=DB::table('p_i_s')->get('pi_no')->last();
            
            return response()->json($data);
        }
 
        if($request->quotation_number)
        {
            
            $data=DB::table('quotations')->get('quotation_no')->last();
            
            return response()->json($data);
        }

        if($request->company_code)
        {
            
            $data=DB::table('companies')->get('company_code')->last();
            
            return response()->json($data);
        }

        
        if($request->invoice_number)
        {
            if($request->type == "cpq")
				$data=DB::table('invoices')->where('invoice_no','not like','%GRO%')->get('invoice_no')->last();
            else
				$data=DB::table('invoices')->where('invoice_no','like','%GRO%')->get('invoice_no')->last();

            return response()->json($data);
        }
        
   }     
   
           public function cron(Request $request)
            {
                if($request->id==1)
                {
                    $data=HSN::dispatch();
                    
                    return response()->json($data);
                    
                }
                if($request->id==2)
                {
                    $data=price::dispatch();
                    return response()->json($data);
                }
            }
}
