0

I need to make an Invoice code with the following template :

INV-YYYYMMDDXXXXX (XXXXX = 5 digit running number)

Then, I write these codes in my 'store' in the Controller

$inv = 'INV-';
$invcode = $request->$inv.date().$invnum;
$invnum = $invnum + 1;

Then I write :

$array  = [
    'InvoiceCode'    => $invcode,
    'InvoiceDate'    => $request->InvoiceDate,
    'TotalPrice'     => $request->TotalPrice,
    'CustomerName'   => $request->CustomerName,
    'CustomerPhone'  => $request->CustomerPhone,
    'CustomerEmail'  => $request->CustomerEmail,
    'CustomerAddress'=> $request->CustomerAddress,
];

But the $invnum is only 1 digit, and I need like 00001 when the 1st Invoice is generated.

How do I create the invoice template? Can anyone help me? Thanks.

Nick
  • 565
  • 4
  • 19
marcato21
  • 3
  • 3

2 Answers2

2

You can use str_pad to add the leading zeros.

$invnum = str_pad($invnum, 5, "0", STR_PAD_LEFT);

See the documentation: http://php.net/manual/en/function.str-pad.php

stlvc
  • 833
  • 5
  • 16
0

You can use str_pad to pad a string.

str_pad($invnum, 5, "0", STR_PAD_LEFT);
libregeek
  • 1,264
  • 11
  • 23