1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 08:21:34 +02:00
invoiceninja/app/Http/Controllers/PaymentTermController.php

139 lines
3.2 KiB
PHP
Raw Normal View History

2017-01-30 20:40:43 +01:00
<?php
namespace App\Http\Controllers;
2016-01-07 20:39:51 +01:00
use App\Models\PaymentTerm;
use App\Services\PaymentTermService;
use Auth;
2017-01-30 20:40:43 +01:00
use Input;
use Redirect;
use Session;
use URL;
use Utils;
use View;
2016-01-07 20:39:51 +01:00
class PaymentTermController extends BaseController
{
/**
* @var PaymentTermService
*/
2016-01-07 20:39:51 +01:00
protected $paymentTermService;
/**
* PaymentTermController constructor.
2017-01-30 20:40:43 +01:00
*
* @param PaymentTermService $paymentTermService
*/
2016-01-07 20:39:51 +01:00
public function __construct(PaymentTermService $paymentTermService)
{
2016-03-02 14:36:42 +01:00
//parent::__construct();
2016-01-07 20:39:51 +01:00
$this->paymentTermService = $paymentTermService;
}
/**
* @return \Illuminate\Http\RedirectResponse
*/
2016-01-07 20:39:51 +01:00
public function index()
{
return Redirect::to('settings/' . ACCOUNT_PAYMENT_TERMS);
}
/**
* @return \Illuminate\Http\JsonResponse
*/
2016-01-07 20:39:51 +01:00
public function getDatatable()
{
$accountId = Auth::user()->account_id;
return $this->paymentTermService->getDatatable($accountId);
2016-01-07 20:39:51 +01:00
}
/**
* @param $publicId
2017-01-30 20:40:43 +01:00
*
* @return \Illuminate\Contracts\View\View
*/
2016-01-07 20:39:51 +01:00
public function edit($publicId)
{
$data = [
'paymentTerm' => PaymentTerm::scope($publicId)->firstOrFail(),
'method' => 'PUT',
'url' => 'payment_terms/'.$publicId,
'title' => trans('texts.edit_payment_term'),
];
return View::make('accounts.payment_term', $data);
}
/**
* @return \Illuminate\Contracts\View\View
*/
2016-01-07 20:39:51 +01:00
public function create()
{
$data = [
'paymentTerm' => null,
'method' => 'POST',
'url' => 'payment_terms',
'title' => trans('texts.create_payment_term'),
];
return View::make('accounts.payment_term', $data);
}
/**
* @return \Illuminate\Http\RedirectResponse
*/
2016-01-07 20:39:51 +01:00
public function store()
{
return $this->save();
}
/**
* @param $publicId
2017-01-30 20:40:43 +01:00
*
* @return \Illuminate\Http\RedirectResponse
*/
2016-01-07 20:39:51 +01:00
public function update($publicId)
{
return $this->save($publicId);
}
/**
* @param bool $publicId
2017-01-30 20:40:43 +01:00
*
* @return \Illuminate\Http\RedirectResponse
*/
2016-01-07 20:39:51 +01:00
private function save($publicId = false)
{
if ($publicId) {
$paymentTerm = PaymentTerm::scope($publicId)->firstOrFail();
} else {
$paymentTerm = PaymentTerm::createNew();
}
2017-01-30 20:40:43 +01:00
$paymentTerm->num_days = Utils::parseInt(Input::get('num_days'));
$paymentTerm->name = 'Net ' . $paymentTerm->num_days;
2016-01-07 20:39:51 +01:00
$paymentTerm->save();
$message = $publicId ? trans('texts.updated_payment_term') : trans('texts.created_payment_term');
Session::flash('message', $message);
return Redirect::to('settings/' . ACCOUNT_PAYMENT_TERMS);
}
/**
* @return \Illuminate\Http\RedirectResponse
*/
2016-01-07 20:39:51 +01:00
public function bulk()
{
$action = Input::get('bulk_action');
2017-01-30 20:40:43 +01:00
$ids = Input::get('bulk_public_id');
$count = $this->paymentTermService->bulk($ids, $action);
2016-01-07 20:39:51 +01:00
Session::flash('message', trans('texts.archived_payment_term'));
return Redirect::to('settings/' . ACCOUNT_PAYMENT_TERMS);
}
}