157 lines
4.6 KiB
PHP
157 lines
4.6 KiB
PHP
<?php
|
|
|
|
if (!function_exists('get_current_date_time')) {
|
|
function get_current_date_time()
|
|
{
|
|
$datetime = new \DateTime('now');
|
|
|
|
return $datetime->format('Y-m-d H:i:s');
|
|
}
|
|
}
|
|
|
|
// if (!function_exists('get_current_date')) {
|
|
// function get_current_date()
|
|
// {
|
|
// return date("Y-m-d");
|
|
// }
|
|
// }
|
|
if (!function_exists('get_current_date')) {
|
|
function get_current_date($format = null)
|
|
{
|
|
$format = $format ?: "Y-m-d";
|
|
return date($format);
|
|
}
|
|
}
|
|
|
|
if (!function_exists('get_date_time_format')) {
|
|
function get_date_time_format($val)
|
|
{
|
|
$date = new \DateTime($val, new \DateTimeZone('Asia/Kolkata'));
|
|
|
|
return $date->format('Y-m-d H:i:s');
|
|
}
|
|
}
|
|
|
|
if (!function_exists('get_date_format')) {
|
|
function get_date_format($DateValue)
|
|
{
|
|
$date = \DateTime::createFromFormat('d/m/Y', $DateValue);
|
|
|
|
if ($date === false) {
|
|
return false;
|
|
}
|
|
|
|
$retDate = $date->format('Y-m-d');
|
|
|
|
return $retDate;
|
|
}
|
|
}
|
|
|
|
// if (!function_exists('format_date')) {
|
|
// function format_date($dateString)
|
|
// {
|
|
// return date('Y-m-d', strtotime($dateString));
|
|
// }
|
|
// }
|
|
|
|
// if (!function_exists('format_date')) {
|
|
// function format_date($dateString, $days = 0)
|
|
// {
|
|
// $date = strtotime($dateString);
|
|
// // Subtract the specified number of days from the current date if $days is provided
|
|
// if ($days != 0) {
|
|
// $date = strtotime("-$days day", $date);
|
|
// }
|
|
// return date('Y-m-d', $date);
|
|
// }
|
|
// }
|
|
|
|
if (!function_exists('format_date')) {
|
|
function format_date($dateString, $days = 0,$format = 'Y-m-d')
|
|
{
|
|
// Check if the input is already a Unix timestamp
|
|
if (is_numeric($dateString) && (string) (int) $dateString === $dateString) {
|
|
$date = strtotime($dateString);
|
|
} else {
|
|
// Use date_create() to create a DateTime object
|
|
$date = date_create($dateString);
|
|
}
|
|
|
|
// If $date is false, meaning parsing failed, return null
|
|
if (!$date) {
|
|
return null;
|
|
}
|
|
|
|
// Subtract the specified number of days from the date if $days is provided
|
|
if ($days != 0) {
|
|
// If $date is a Unix timestamp, modify it using strtotime()
|
|
if (is_numeric($dateString) && (string) (int) $dateString === $dateString) {
|
|
$date = strtotime("-$days day", $date);
|
|
} else {
|
|
// If $date is a DateTime object, modify it using DateTime::modify()
|
|
date_modify($date, "-$days day");
|
|
}
|
|
}
|
|
|
|
// If $date is a Unix timestamp, format it using date()
|
|
if (is_numeric($dateString) && (string) (int) $dateString === $dateString) {
|
|
return date($format, $date);
|
|
} else {
|
|
// If $date is a DateTime object, format it using DateTime::format()
|
|
return date_format($date, $format);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!function_exists('get_financial_year')) {
|
|
function get_financial_year($date = null)
|
|
{
|
|
// If no date is provided, use the current date
|
|
$date = $date ?: date('Y-m-d');
|
|
|
|
// Extract the year from the date
|
|
$year = date('Y', strtotime($date));
|
|
|
|
// Determine the financial year based on your business logic
|
|
// Adjust this logic according to your organization's financial year cycle
|
|
if (date('n', strtotime($date)) < 4) {
|
|
// If the month is before April, use the previous year
|
|
$financialYear = ($year - 1) . '-' . $year;
|
|
} else {
|
|
// If the month is April or later, use the current year
|
|
$financialYear = $year . '-' . ($year + 1);
|
|
}
|
|
|
|
return $financialYear;
|
|
}
|
|
}
|
|
|
|
if (!function_exists('generate_pos_number')) {
|
|
function generate_pos_number($last_pono)
|
|
{
|
|
$currentYear = date("Y");
|
|
$finYear = get_financial_year(); // Get it From DateTime Helper
|
|
|
|
// if(here have to check fin year if there is a change means both are same means ){
|
|
// $counter = $counter + 1;
|
|
// }else{
|
|
// $counter = 1;
|
|
// }
|
|
|
|
$result = explode('/', $last_pono);
|
|
$requestedFinYear = $result[1];
|
|
$leftPad = $result[0];
|
|
$digit = 5;
|
|
|
|
if($requestedFinYear == $finYear){
|
|
$number = ((int)$result[2])+1;
|
|
$PoNo = $leftPad . '/' . $finYear . '/' . $number;
|
|
}else{
|
|
$counter = 1;
|
|
$PoNo = $leftPad . '/' . $finYear . '/' . str_pad($counter, $digit, '0', STR_PAD_LEFT);
|
|
}
|
|
|
|
return $PoNo;
|
|
}
|
|
}
|