private static function getViewModel($invoice)
{
$recurringHelp = '';
$recurringDueDateHelp = '';
$recurringDueDates = [];
foreach (preg_split("/((\r?\n)|(\r\n?))/", trans('texts.recurring_help')) as $line) {
$parts = explode('=>', $line);
if (count($parts) > 1) {
$line = $parts[0] . ' => ' . Utils::processVariables($parts[0]);
$recurringHelp .= '<li>' . strip_tags($line) . '</li>';
} else {
$recurringHelp .= $line;
}
}
foreach (preg_split("/((\r?\n)|(\r\n?))/", trans('texts.recurring_due_date_help')) as $line) {
$parts = explode('=>', $line);
if (count($parts) > 1) {
$line = $parts[0] . ' => ' . Utils::processVariables($parts[0]);
$recurringDueDateHelp .= '<li>' . strip_tags($line) . '</li>';
} else {
$recurringDueDateHelp .= $line;
}
}
// Create due date options
$recurringDueDates = [trans('texts.use_client_terms') => ['value' => '', 'class' => 'monthly weekly']];
$ends = ['th', 'st', 'nd', 'rd', 'th', 'th', 'th', 'th', 'th', 'th'];
for ($i = 1; $i < 31; $i++) {
if ($i >= 11 && $i <= 13) {
$ordinal = $i . 'th';
} else {
$ordinal = $i . $ends[$i % 10];
}
$dayStr = str_pad($i, 2, '0', STR_PAD_LEFT);
$str = trans('texts.day_of_month', ['ordinal' => $ordinal]);
$recurringDueDates[$str] = ['value' => "1998-01-{$dayStr}", 'data-num' => $i, 'class' => 'monthly'];
}
$recurringDueDates[trans('texts.last_day_of_month')] = ['value' => '1998-01-31', 'data-num' => 31, 'class' => 'monthly'];
$daysOfWeek = [trans('texts.sunday'), trans('texts.monday'), trans('texts.tuesday'), trans('texts.wednesday'), trans('texts.thursday'), trans('texts.friday'), trans('texts.saturday')];
foreach (['1st', '2nd', '3rd', '4th'] as $i => $ordinal) {
foreach ($daysOfWeek as $j => $dayOfWeek) {
$str = trans('texts.day_of_week_after', ['ordinal' => $ordinal, 'day' => $dayOfWeek]);
$day = $i * 7 + $j + 1;
$dayStr = str_pad($day, 2, '0', STR_PAD_LEFT);
$recurringDueDates[$str] = ['value' => "1998-02-{$dayStr}", 'data-num' => $day, 'class' => 'weekly'];
}
}
// Tax rate $options
$account = Auth::user()->account;
$rates = TaxRate::scope()->orderBy('name')->get();
$options = [];
$defaultTax = false;
foreach ($rates as $rate) {
$options[$rate->rate . ' ' . $rate->name] = $rate->name . ' ' . ($rate->rate + 0) . '%';
// load default invoice tax
if ($rate->id == $account->default_tax_rate_id) {
$defaultTax = $rate;
}
}
// Check for any taxes which have been deleted
if ($invoice->exists) {
foreach ($invoice->getTaxes() as $key => $rate) {
if (isset($options[$key])) {
continue;
}
$options[$key] = $rate['name'] . ' ' . $rate['rate'] . '%';
}
}
return ['data' => Input::old('data'), 'account' => Auth::user()->account->load('country'), 'products' => Product::scope()->with('default_tax_rate')->orderBy('product_key')->get(), 'taxRateOptions' => $options, 'defaultTax' => $defaultTax, 'currencies' => Cache::get('currencies'), 'sizes' => Cache::get('sizes'), 'paymentTerms' => Cache::get('paymentTerms'), 'invoiceDesigns' => InvoiceDesign::getDesigns(), 'invoiceFonts' => Cache::get('fonts'), 'frequencies' => [1 => trans('texts.freq_weekly'), 2 => trans('texts.freq_two_weeks'), 3 => trans('texts.freq_four_weeks'), 4 => trans('texts.freq_monthly'), 5 => trans('texts.freq_three_months'), 6 => trans('texts.freq_six_months'), 7 => trans('texts.freq_annually')], 'recurringDueDates' => $recurringDueDates, 'recurringHelp' => $recurringHelp, 'recurringDueDateHelp' => $recurringDueDateHelp, 'invoiceLabels' => Auth::user()->account->getInvoiceLabels(), 'tasks' => Session::get('tasks') ? json_encode(Session::get('tasks')) : null, 'expenseCurrencyId' => Session::get('expenseCurrencyId') ?: null, 'expenses' => Session::get('expenses') ? Expense::scope(Session::get('expenses'))->with('documents', 'expense_category')->get() : []];
}