<?php

namespace App\Http\Controllers\backend;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Carbon\Carbon;
use App\User;
use App\Models\Sale;


class WorkingController extends Controller
{
    // Find a randomDate between $start_date and $end_date
    private function randomDate(){
        // Convert to timetamps
        $min = strtotime('2020-03-01');
        $max = strtotime(date('Y-m-d'));
    
        // Generate random number using above bounds
        $val = rand($min, $max);
    
        // Convert back to desired date format
        return date('Y-m-d', $val);
    }
    public function index(Request $request){
        //return $this->randomDate();
        //$sales = Sale::whereBetween('id', ['320', '340'])->get();
        $sales = Sale::all();
        foreach($sales as $sale){
            $min = strtotime('2022-4-01');
            $max = strtotime('2022-8-30');
            $val = rand($min, $max);
            $dd = date('Y-m-d', $val);
            
            //$sale->sale_date = $dd;
           // $sale->save();
           return $sale->pyment;
            if($sale->payment){
                foreach($sale->payment as $payment){
                    $payment->payment_date = $dd;
                    $payment->save();
                }
            }
        }
        return $sales;
         
         //$sales = Sale::whereBetween('id', ['171', '190'])->get();
        /* return $sales->sum('grand_total_price');
         dd($sales->sum('grand_total_price'));*/
    }
    
}