mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
New code for bills.
This commit is contained in:
@@ -16,6 +16,47 @@ use View;
|
||||
*/
|
||||
class ExpandedForm
|
||||
{
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @param null $value
|
||||
* @param array $options
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function integer($name, $value = null, array $options = [])
|
||||
{
|
||||
$label = $this->label($name, $options);
|
||||
$options = $this->expandOptionArray($name, $label, $options);
|
||||
$classes = $this->getHolderClasses($name);
|
||||
$value = $this->fillFieldValue($name, $value);
|
||||
$options['step'] = '1';
|
||||
$html = \View::make('form.integer', compact('classes', 'name', 'label', 'value', 'options'))->render();
|
||||
|
||||
return $html;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @param null $value
|
||||
* @param array $options
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function tags($name, $value = null, array $options = [])
|
||||
{
|
||||
$label = $this->label($name, $options);
|
||||
$options = $this->expandOptionArray($name, $label, $options);
|
||||
$classes = $this->getHolderClasses($name);
|
||||
$value = $this->fillFieldValue($name, $value);
|
||||
$options['data-role'] = 'tagsinput';
|
||||
$html = \View::make('form.tags', compact('classes', 'name', 'label', 'value', 'options'))->render();
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @param null $value
|
||||
|
@@ -15,31 +15,93 @@ class Navigation
|
||||
|
||||
|
||||
/**
|
||||
* @param Carbon $date
|
||||
* @param $repeatFrequency
|
||||
* @param Carbon $theDate
|
||||
* @param $repeatFreq
|
||||
* @param $skip
|
||||
*
|
||||
* @return string
|
||||
* @return \Carbon\Carbon
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function periodShow(Carbon $date, $repeatFrequency)
|
||||
public function addPeriod(Carbon $theDate, $repeatFreq, $skip)
|
||||
{
|
||||
$formatMap = [
|
||||
'daily' => 'j F Y',
|
||||
'week' => '\W\e\e\k W, Y',
|
||||
'weekly' => '\W\e\e\k W, Y',
|
||||
'quarter' => 'F Y',
|
||||
'month' => 'F Y',
|
||||
'monthly' => 'F Y',
|
||||
'year' => 'Y',
|
||||
'yearly' => 'Y',
|
||||
$date = clone $theDate;
|
||||
$add = ($skip + 1);
|
||||
|
||||
$functionMap = [
|
||||
'daily' => 'addDays',
|
||||
'weekly' => 'addWeeks',
|
||||
'week' => 'addWeeks',
|
||||
'month' => 'addMonths',
|
||||
'monthly' => 'addMonths',
|
||||
'quarter' => 'addMonths',
|
||||
'quarterly' => 'addMonths',
|
||||
'half-year' => 'addMonths',
|
||||
'year' => 'addYears',
|
||||
'yearly' => 'addYears',
|
||||
];
|
||||
if (isset($formatMap[$repeatFrequency])) {
|
||||
return $date->format($formatMap[$repeatFrequency]);
|
||||
$modifierMap = [
|
||||
'quarter' => 3,
|
||||
'quarterly' => 3,
|
||||
'half-year' => 6,
|
||||
];
|
||||
if (!isset($functionMap[$repeatFreq])) {
|
||||
throw new FireflyException('Cannot do addPeriod for $repeat_freq "' . $repeatFreq . '"');
|
||||
}
|
||||
throw new FireflyException('No date formats for frequency "' . $repeatFrequency . '"!');
|
||||
if (isset($modifierMap[$repeatFreq])) {
|
||||
$add = $add * $modifierMap[$repeatFreq];
|
||||
}
|
||||
$function = $functionMap[$repeatFreq];
|
||||
$date->$function($add);
|
||||
|
||||
return $date;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $theCurrentEnd
|
||||
* @param $repeatFreq
|
||||
*
|
||||
* @return Carbon
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function endOfPeriod(Carbon $theCurrentEnd, $repeatFreq)
|
||||
{
|
||||
$currentEnd = clone $theCurrentEnd;
|
||||
|
||||
$functionMap = [
|
||||
'daily' => 'addDay',
|
||||
'week' => 'addWeek',
|
||||
'weekly' => 'addWeek',
|
||||
'month' => 'addMonth',
|
||||
'monthly' => 'addMonth',
|
||||
'quarter' => 'addMonths',
|
||||
'quarterly' => 'addMonths',
|
||||
'half-year' => 'addMonths',
|
||||
'year' => 'addYear',
|
||||
'yearly' => 'addYear',
|
||||
];
|
||||
$modifierMap = [
|
||||
'quarter' => 3,
|
||||
'quarterly' => 3,
|
||||
'half-year' => 6,
|
||||
];
|
||||
|
||||
$subDay = ['week', 'weekly', 'month', 'monthly', 'quarter', 'quarterly', 'half-year', 'year', 'yearly'];
|
||||
|
||||
if (!isset($functionMap[$repeatFreq])) {
|
||||
throw new FireflyException('Cannot do endOfPeriod for $repeat_freq ' . $repeatFreq);
|
||||
}
|
||||
$function = $functionMap[$repeatFreq];
|
||||
if (isset($modifierMap[$repeatFreq])) {
|
||||
$currentEnd->$function($modifierMap[$repeatFreq]);
|
||||
} else {
|
||||
$currentEnd->$function();
|
||||
}
|
||||
if (in_array($repeatFreq, $subDay)) {
|
||||
$currentEnd->subDay();
|
||||
}
|
||||
|
||||
return $currentEnd;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $range
|
||||
@@ -154,6 +216,72 @@ class Navigation
|
||||
throw new FireflyException('No _periodName() for range "' . $range . '"');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $date
|
||||
* @param $repeatFrequency
|
||||
*
|
||||
* @return string
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function periodShow(Carbon $date, $repeatFrequency)
|
||||
{
|
||||
$formatMap = [
|
||||
'daily' => 'j F Y',
|
||||
'week' => '\W\e\e\k W, Y',
|
||||
'weekly' => '\W\e\e\k W, Y',
|
||||
'quarter' => 'F Y',
|
||||
'month' => 'F Y',
|
||||
'monthly' => 'F Y',
|
||||
'year' => 'Y',
|
||||
'yearly' => 'Y',
|
||||
|
||||
];
|
||||
if (isset($formatMap[$repeatFrequency])) {
|
||||
return $date->format($formatMap[$repeatFrequency]);
|
||||
}
|
||||
throw new FireflyException('No date formats for frequency "' . $repeatFrequency . '"!');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $theDate
|
||||
* @param $repeatFreq
|
||||
*
|
||||
* @return Carbon
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function startOfPeriod(Carbon $theDate, $repeatFreq)
|
||||
{
|
||||
$date = clone $theDate;
|
||||
|
||||
$functionMap = [
|
||||
'daily' => 'startOfDay',
|
||||
'week' => 'startOfWeek',
|
||||
'weekly' => 'startOfWeek',
|
||||
'month' => 'startOfMonth',
|
||||
'monthly' => 'startOfMonth',
|
||||
'quarter' => 'firstOfQuarter',
|
||||
'quartly' => 'firstOfQuarter',
|
||||
'year' => 'startOfYear',
|
||||
'yearly' => 'startOfYear',
|
||||
];
|
||||
if (isset($functionMap[$repeatFreq])) {
|
||||
$function = $functionMap[$repeatFreq];
|
||||
$date->$function();
|
||||
|
||||
return $date;
|
||||
}
|
||||
if ($repeatFreq == 'half-year') {
|
||||
$month = intval($date->format('m'));
|
||||
$date->startOfYear();
|
||||
if ($month >= 7) {
|
||||
$date->addMonths(6);
|
||||
}
|
||||
|
||||
return $date;
|
||||
}
|
||||
throw new FireflyException('Cannot do startOfPeriod for $repeat_freq ' . $repeatFreq);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $range
|
||||
* @param Carbon $start
|
||||
@@ -224,47 +352,5 @@ class Navigation
|
||||
throw new FireflyException('updateStartDate cannot handle $range ' . $range);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $theDate
|
||||
* @param $repeatFreq
|
||||
* @param $skip
|
||||
*
|
||||
* @return \Carbon\Carbon
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function addPeriod(Carbon $theDate, $repeatFreq, $skip)
|
||||
{
|
||||
$date = clone $theDate;
|
||||
$add = ($skip + 1);
|
||||
|
||||
$functionMap = [
|
||||
'daily' => 'addDays',
|
||||
'weekly' => 'addWeeks',
|
||||
'week' => 'addWeeks',
|
||||
'month' => 'addMonths',
|
||||
'monthly' => 'addMonths',
|
||||
'quarter' => 'addMonths',
|
||||
'quarterly' => 'addMonths',
|
||||
'half-year' => 'addMonths',
|
||||
'year' => 'addYears',
|
||||
'yearly' => 'addYears',
|
||||
];
|
||||
$modifierMap = [
|
||||
'quarter' => 3,
|
||||
'quarterly' => 3,
|
||||
'half-year' => 6,
|
||||
];
|
||||
if (!isset($functionMap[$repeatFreq])) {
|
||||
throw new FireflyException('Cannot do addPeriod for $repeat_freq "' . $repeatFreq . '"');
|
||||
}
|
||||
if (isset($modifierMap[$repeatFreq])) {
|
||||
$add = $add * $modifierMap[$repeatFreq];
|
||||
}
|
||||
$function = $functionMap[$repeatFreq];
|
||||
$date->$function($add);
|
||||
|
||||
return $date;
|
||||
}
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user