33 lines
743 B
PHP
33 lines
743 B
PHP
<?php
|
|
|
|
use CodeIgniter\HTTP\IncomingRequest;
|
|
|
|
|
|
|
|
|
|
/**
|
|
* Retrieve and store stock month based on request method.
|
|
*
|
|
* @param IncomingRequest $request
|
|
* @return string
|
|
*/
|
|
function getStockMonth(IncomingRequest $request): string
|
|
{
|
|
$session = session();
|
|
|
|
if ($request->getMethod() === 'POST') {
|
|
$monthInput = $request->getPost('month');
|
|
$date = DateTime::createFromFormat('d-M-Y', '01-' . $monthInput);
|
|
$formattedDate = $date ? $date->format('Y-m') : date('Y-m');
|
|
$session->set('stock_month', $formattedDate);
|
|
$month = $formattedDate;
|
|
} else {
|
|
$month = $session->get('stock_month');
|
|
if (empty($month)) {
|
|
$month = date('Y-m');
|
|
}
|
|
}
|
|
|
|
return $month;
|
|
}
|