mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-04-19 11:14:06 +00:00
Invoice time support (#269)
* Changed invoice date to datetime * Fixed code style errors * Update TimeFormatsController.php * Update TimeFormatter.php * Update TimeFormatsController namespace * Fix missing comma in language file * Fix formatting --------- Co-authored-by: troky <troky2001@yahoo.com>
This commit is contained in:
committed by
GitHub
parent
32e03b98a3
commit
f52b73f517
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V1\Admin\General;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Space\TimeFormatter;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class TimeFormatsController extends Controller
|
||||
{
|
||||
/**
|
||||
* Handle the incoming request.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function __invoke(Request $request)
|
||||
{
|
||||
return response()->json([
|
||||
'time_formats' => TimeFormatter::get_list(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -46,6 +46,16 @@ class CloneInvoiceController extends Controller
|
||||
|
||||
$exchange_rate = $invoice->exchange_rate;
|
||||
|
||||
$dateFormat = 'Y-m-d';
|
||||
$invoiceTimeEnabled = CompanySetting::getSetting(
|
||||
'invoice_use_time',
|
||||
$request->header('company')
|
||||
);
|
||||
|
||||
if ($invoiceTimeEnabled === 'YES') {
|
||||
$dateFormat .= ' H:i';
|
||||
}
|
||||
|
||||
$newInvoice = Invoice::create([
|
||||
'invoice_date' => $date->format('Y-m-d'),
|
||||
'due_date' => $due_date,
|
||||
|
||||
@@ -38,6 +38,15 @@ class CompanySettingRequest extends FormRequest
|
||||
'carbon_date_format' => [
|
||||
'required',
|
||||
],
|
||||
'moment_time_format' => [
|
||||
'required',
|
||||
],
|
||||
'carbon_time_format' => [
|
||||
'required',
|
||||
],
|
||||
'invoice_use_time' => [
|
||||
'required',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -227,6 +227,9 @@ class Company extends Model implements HasMedia
|
||||
'fiscal_year' => '1-12',
|
||||
'carbon_date_format' => 'Y/m/d',
|
||||
'moment_date_format' => 'YYYY/MM/DD',
|
||||
'carbon_time_format' => 'H:i',
|
||||
'moment_time_format' => 'HH:mm',
|
||||
'invoice_use_time' => 'NO',
|
||||
'notification_email' => 'noreply@invoiceshelf.com',
|
||||
'notify_invoice_viewed' => 'NO',
|
||||
'notify_estimate_viewed' => 'NO',
|
||||
|
||||
@@ -195,6 +195,12 @@ class Invoice extends Model implements HasMedia
|
||||
public function getFormattedInvoiceDateAttribute($value)
|
||||
{
|
||||
$dateFormat = CompanySetting::getSetting('carbon_date_format', $this->company_id);
|
||||
$timeFormat = CompanySetting::getSetting('carbon_time_format', $this->company_id);
|
||||
$invoiceTimeEnabled = CompanySetting::getSetting('invoice_use_time', $this->company_id);
|
||||
|
||||
if ($invoiceTimeEnabled === 'YES') {
|
||||
$dateFormat .= ' '.$timeFormat;
|
||||
}
|
||||
|
||||
return Carbon::parse($this->invoice_date)->translatedFormat($dateFormat);
|
||||
}
|
||||
|
||||
34
app/Space/TimeFormatter.php
Normal file
34
app/Space/TimeFormatter.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Space;
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
class TimeFormatter
|
||||
{
|
||||
protected static $formats = [
|
||||
[
|
||||
'carbon_format' => 'H:i',
|
||||
'moment_format' => 'HH:mm',
|
||||
],
|
||||
[
|
||||
'carbon_format' => 'g:i a',
|
||||
'moment_format' => 'h:mm a',
|
||||
],
|
||||
];
|
||||
|
||||
public static function get_list()
|
||||
{
|
||||
$new = [];
|
||||
|
||||
foreach (static::$formats as $format) {
|
||||
$new[] = [
|
||||
'display_time' => Carbon::now()->format($format['carbon_format']),
|
||||
'carbon_format_value' => $format['carbon_format'],
|
||||
'moment_format_value' => $format['moment_format'],
|
||||
];
|
||||
}
|
||||
|
||||
return $new;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user