Code: Select all
// get the contents of the text file
$receipt = file_get_contents('receipt.txt');
// break it into an array of parts
$parts = explode('-', $receipt);
if ($parts[0] != date('Y')) {
$parts[0] = date('Y');
$parts[1] = '0000';
$parts[2] = '0000';
}
if ($parts[2] <= 9998) {
$parts[2]++;
$parts[2] = sprintf('%04d', $parts[2]);
}
else {
$parts[2] = '0001';
$parts[1]++;
$parts[1] = sprintf('%04d', $parts[1]);
}
// rebuild the number and reassign to $receipt
$receipt = implode('-', $parts);
$file = fopen('receipt.txt', 'w');
fwrite($file, $receipt);
fclose($file);I would like the number to be displayed like this: 000-0000
I am aware that I need to change the actual number in my "receipt.txt" folder to the seven digit layout, but I can't figure out how to modify the code to work properly and increase the receipt number by 1 each time an order is placed.
Can anyone help me out with this?