Inheritance: extends EntityModel, use trait Illuminate\Database\Eloquent\SoftDeletes
コード例 #1
0
 public function update(UpdateTaxRateRequest $request, $publicId)
 {
     $taxRate = TaxRate::scope($publicId)->firstOrFail();
     $this->taxRateRepo->save($request->input(), $taxRate);
     Session::flash('message', trans('texts.updated_tax_rate'));
     return Redirect::to('settings/' . ACCOUNT_TAX_RATES);
 }
コード例 #2
0
 public function save($taxRates)
 {
     $taxRateIds = [];
     foreach ($taxRates as $record) {
         if (!isset($record->rate) || isset($record->is_deleted) && $record->is_deleted) {
             continue;
         }
         if (!isset($record->name) || !trim($record->name)) {
             continue;
         }
         if ($record->public_id) {
             $taxRate = TaxRate::scope($record->public_id)->firstOrFail();
         } else {
             $taxRate = TaxRate::createNew();
         }
         $taxRate->rate = Utils::parseFloat($record->rate);
         $taxRate->name = trim($record->name);
         $taxRate->save();
         $taxRateIds[] = $taxRate->public_id;
     }
     $taxRates = TaxRate::scope()->get();
     foreach ($taxRates as $taxRate) {
         if (!in_array($taxRate->public_id, $taxRateIds)) {
             $taxRate->delete();
         }
     }
 }
コード例 #3
0
 public function archive($publicId)
 {
     $tax_rate = TaxRate::scope($publicId)->firstOrFail();
     $tax_rate->delete();
     Session::flash('message', trans('texts.archived_tax_rate'));
     return Redirect::to('settings/' . ACCOUNT_TAX_RATES);
 }
コード例 #4
0
 public function update(UpdateTaxRateRequest $request, $taxRatePublicId)
 {
     $taxRate = TaxRate::scope($taxRatePublicId)->firstOrFail();
     if ($request->action == ACTION_ARCHIVE) {
         $this->taxRateRepo->archive($taxRate);
         $transformer = new TaxRateTransformer(Auth::user()->account, $request->serializer);
         $data = $this->createItem($taxRate, $transformer, 'tax_rates');
         return $this->response($data);
     } else {
         return $this->save($request, $taxRate);
     }
 }
コード例 #5
0
 public function save($data, $taxRate = false)
 {
     if (!$taxRate) {
         if (isset($data['public_id'])) {
             $taxRate = TaxRate::scope($data['public_id'])->firstOrFail();
         } else {
             $taxRate = TaxRate::createNew();
         }
     }
     $taxRate->fill($data);
     $taxRate->save();
     return $taxRate;
 }
コード例 #6
0
 private function save($publicId = false)
 {
     if ($publicId) {
         $taxRate = TaxRate::scope($publicId)->firstOrFail();
     } else {
         $taxRate = TaxRate::createNew();
     }
     $taxRate->name = trim(Input::get('name'));
     $taxRate->rate = Utils::parseFloat(Input::get('rate'));
     $taxRate->save();
     $message = $publicId ? trans('texts.updated_tax_rate') : trans('texts.created_tax_rate');
     Session::flash('message', $message);
     return Redirect::to('settings/' . ACCOUNT_TAX_RATES);
 }
コード例 #7
0
 public function save($data, $taxRate = null)
 {
     if ($taxRate) {
         // do nothing
     } elseif (isset($data['public_id'])) {
         $taxRate = TaxRate::scope($data['public_id'])->firstOrFail();
         \Log::warning('Entity not set in tax rate repo save');
     } else {
         $taxRate = TaxRate::createNew();
     }
     $taxRate->fill($data);
     $taxRate->save();
     return $taxRate;
 }
コード例 #8
0
 private static function getViewModel()
 {
     // 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;
         }
     }
     return ['entityType' => ENTITY_QUOTE, 'account' => Auth::user()->account, 'products' => Product::scope()->orderBy('id')->get(['product_key', 'notes', 'cost', 'qty']), 'taxRateOptions' => $options, 'defaultTax' => $defaultTax, 'countries' => Cache::get('countries'), 'clients' => Client::scope()->with('contacts', 'country')->orderBy('name')->get(), 'taxRates' => TaxRate::scope()->orderBy('name')->get(), 'currencies' => Cache::get('currencies'), 'sizes' => Cache::get('sizes'), 'paymentTerms' => Cache::get('paymentTerms'), 'languages' => Cache::get('languages'), 'industries' => Cache::get('industries'), 'invoiceDesigns' => InvoiceDesign::getDesigns(), 'invoiceFonts' => Cache::get('fonts'), 'invoiceLabels' => Auth::user()->account->getInvoiceLabels(), 'isRecurring' => false];
 }
コード例 #9
0
 private static function getViewModel()
 {
     $recurringHelp = '';
     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;
         }
     }
     return ['data' => Input::old('data'), 'account' => Auth::user()->account->load('country'), 'products' => Product::scope()->with('default_tax_rate')->orderBy('id')->get(), 'countries' => Cache::get('countries'), 'taxRates' => TaxRate::scope()->orderBy('name')->get(), 'currencies' => Cache::get('currencies'), 'languages' => Cache::get('languages'), 'sizes' => Cache::get('sizes'), 'paymentTerms' => Cache::get('paymentTerms'), 'industries' => Cache::get('industries'), 'invoiceDesigns' => InvoiceDesign::getDesigns(), 'frequencies' => array(1 => 'Weekly', 2 => 'Two weeks', 3 => 'Four weeks', 4 => 'Monthly', 5 => 'Three months', 6 => 'Six months', 7 => 'Annually'), 'recurringHelp' => $recurringHelp, 'invoiceLabels' => Auth::user()->account->getInvoiceLabels(), 'tasks' => Session::get('tasks') ? json_encode(Session::get('tasks')) : null];
 }
コード例 #10
0
 public function edit($publicId)
 {
     $data = ['taxRate' => TaxRate::scope($publicId)->firstOrFail(), 'method' => 'PUT', 'url' => 'tax_rates/' . $publicId, 'title' => trans('texts.edit_tax_rate')];
     return View::make('accounts.tax_rate', $data);
 }
コード例 #11
0
 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() : []];
 }
コード例 #12
0
 private static function getViewModel()
 {
     return ['entityType' => ENTITY_QUOTE, 'account' => Auth::user()->account, 'products' => Product::scope()->orderBy('id')->get(array('product_key', 'notes', 'cost', 'qty')), 'countries' => Cache::get('countries'), 'clients' => Client::scope()->with('contacts', 'country')->orderBy('name')->get(), 'taxRates' => TaxRate::scope()->orderBy('name')->get(), 'currencies' => Cache::get('currencies'), 'sizes' => Cache::get('sizes'), 'paymentTerms' => Cache::get('paymentTerms'), 'industries' => Cache::get('industries'), 'invoiceDesigns' => InvoiceDesign::availableDesigns(), 'invoiceLabels' => Auth::user()->account->getInvoiceLabels()];
 }
コード例 #13
0
 private static function getViewModel()
 {
     $recurringHelp = '';
     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;
         }
     }
     $recurringDueDateHelp = '';
     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 = array(trans('texts.use_client_terms') => array('value' => '', 'class' => 'monthly weekly'));
     $ends = array('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', array('ordinal' => $ordinal));
         $recurringDueDates[$str] = array('value' => "1998-01-{$dayStr}", 'data-num' => $i, 'class' => 'monthly');
     }
     $recurringDueDates[trans('texts.last_day_of_month')] = array('value' => "1998-01-31", 'data-num' => 31, 'class' => 'monthly');
     $daysOfWeek = array(trans('texts.sunday'), trans('texts.monday'), trans('texts.tuesday'), trans('texts.wednesday'), trans('texts.thursday'), trans('texts.friday'), trans('texts.saturday'));
     foreach (array('1st', '2nd', '3rd', '4th') as $i => $ordinal) {
         foreach ($daysOfWeek as $j => $dayOfWeek) {
             $str = trans('texts.day_of_week_after', array('ordinal' => $ordinal, 'day' => $dayOfWeek));
             $day = $i * 7 + $j + 1;
             $dayStr = str_pad($day, 2, '0', STR_PAD_LEFT);
             $recurringDueDates[$str] = array('value' => "1998-02-{$dayStr}", 'data-num' => $day, 'class' => 'weekly');
         }
     }
     return ['data' => Input::old('data'), 'account' => Auth::user()->account->load('country'), 'products' => Product::scope()->with('default_tax_rate')->orderBy('product_key')->get(), 'taxRates' => TaxRate::scope()->orderBy('name')->get(), 'currencies' => Cache::get('currencies'), 'languages' => Cache::get('languages'), 'sizes' => Cache::get('sizes'), 'paymentTerms' => Cache::get('paymentTerms'), 'industries' => Cache::get('industries'), 'invoiceDesigns' => InvoiceDesign::getDesigns(), 'invoiceFonts' => Cache::get('fonts'), 'frequencies' => array(1 => 'Weekly', 2 => 'Two weeks', 3 => 'Four weeks', 4 => 'Monthly', 5 => 'Three months', 6 => 'Six months', 7 => 'Annually'), 'recurringDueDates' => $recurringDueDates, 'recurringHelp' => $recurringHelp, 'recurringDueDateHelp' => $recurringDueDateHelp, 'invoiceLabels' => Auth::user()->account->getInvoiceLabels(), 'tasks' => Session::get('tasks') ? json_encode(Session::get('tasks')) : null, 'expenses' => Session::get('expenses') ? json_encode(Session::get('expenses')) : null, 'expenseCurrencyId' => Session::get('expenseCurrencyId') ?: null];
 }
コード例 #14
0
 private static function getViewModel()
 {
     return ['data' => Input::old('data'), 'account' => Auth::user()->account, 'sizes' => Cache::get('sizes'), 'paymentTerms' => Cache::get('paymentTerms'), 'industries' => Cache::get('industries'), 'currencies' => Cache::get('currencies'), 'languages' => Cache::get('languages'), 'countries' => Cache::get('countries'), 'customLabel1' => Auth::user()->account->custom_vendor_label1, 'customLabel2' => Auth::user()->account->custom_vendor_label2, 'categories' => ExpenseCategory::whereAccountId(Auth::user()->account_id)->orderBy('name')->get(), 'taxRates' => TaxRate::scope()->orderBy('name')->get()];
 }
コード例 #15
0
 public function index()
 {
     $taxRates = TaxRate::scope()->withTrashed()->orderBy('created_at', 'desc');
     return $this->listResponse($taxRates);
 }
コード例 #16
0
 /**
  * @return \Illuminate\Contracts\View\View
  */
 private function showTaxRates()
 {
     $data = ['account' => Auth::user()->account, 'title' => trans('texts.tax_rates'), 'taxRates' => TaxRate::scope()->get(['id', 'name', 'rate'])];
     return View::make('accounts.tax_rates', $data);
 }
コード例 #17
0
 public function create()
 {
     $account = Auth::user()->account;
     $data = ['account' => $account, 'taxRates' => $account->invoice_item_taxes ? TaxRate::scope()->get(['id', 'name', 'rate']) : null, 'product' => null, 'method' => 'POST', 'url' => 'products', 'title' => trans('texts.create_product')];
     return View::make('accounts.product', $data);
 }
コード例 #18
0
 private static function getViewModel()
 {
     $recurringHelp = '';
     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;
         }
     }
     return ['account' => Auth::user()->account, 'products' => Product::scope()->orderBy('id')->get(array('product_key', 'notes', 'cost', 'qty')), 'countries' => Cache::get('countries'), 'clients' => Client::scope()->with('contacts', 'country')->orderBy('name')->get(), 'taxRates' => TaxRate::scope()->orderBy('name')->get(), 'currencies' => Cache::get('currencies'), 'sizes' => Cache::get('sizes'), 'paymentTerms' => Cache::get('paymentTerms'), 'industries' => Cache::get('industries'), 'invoiceDesigns' => InvoiceDesign::availableDesigns(), 'frequencies' => array(1 => 'Weekly', 2 => 'Two weeks', 3 => 'Four weeks', 4 => 'Monthly', 5 => 'Three months', 6 => 'Six months', 7 => 'Annually'), 'recurringHelp' => $recurringHelp];
 }