Aronaman
4 months ago
455
2
Laravel

invoice no increment

Posted 4 months ago by Aronaman

my problem #1expNum +1 remove all zero and make 2 instade of 0002

	   $now=Carbon::now();
            $firstDateYear=$now->startOfYear();

            $record = Invoice::latest()->first();
            if(!is_null($record)){
                $expNum = explode('-', $record->recp_no);
                    //check first day in a year
                if ($firstDateYear->isToday() ){
                    $nextInvoiceNumber = date('Y').'-0001';
                } else {
                    //increase 1 with last invoice number
                    $nextInvoiceNumber = $expNum[0].'-'. $expNum[1]+1;

//error  dd($nextInvoiceNumber)  "A non well formed numeric value encountered"
                }

            }else{
            $nextInvoiceNumber =date('Y').'-0000';
            }

any one please better way to do this !!!

Please sign in or create an account to participate in this conversation.