invoiceninja/app/controllers/CreditController.php

63 lines
2.1 KiB
PHP
Raw Normal View History

2013-12-01 22:58:25 +02:00
<?php
class CreditController extends \BaseController {
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
return View::make('list', array(
'entityType'=>ENTITY_CREDIT,
2013-12-04 00:00:01 +02:00
'title' => '- Credits',
2013-12-01 22:58:25 +02:00
'columns'=>['checkbox', 'Credit Number', 'Client', 'Amount', 'Credit Date']
));
}
2013-12-04 18:20:14 +02:00
public function getDatatable($clientPublicId = null)
2013-12-01 22:58:25 +02:00
{
2013-12-03 19:32:33 +02:00
$collection = Credit::scope()->with('client');
2013-12-01 22:58:25 +02:00
2013-12-04 18:20:14 +02:00
if ($clientPublicId) {
$clientId = Client::getPrivateId($clientPublicId);
2013-12-01 22:58:25 +02:00
$collection->where('client_id','=',$clientId);
}
$table = Datatable::collection($collection->get());
2013-12-04 18:20:14 +02:00
if (!$clientPublicId) {
$table->addColumn('checkbox', function($model) { return '<input type="checkbox" name="ids[]" value="' . $model->public_id . '">'; });
2013-12-01 22:58:25 +02:00
}
$table->addColumn('credit_number', function($model) { return $model->credit_number; });
2013-12-04 18:20:14 +02:00
if (!$clientPublicId) {
$table->addColumn('client', function($model) { return link_to('clients/' . $model->client->public_id, $model->client->name); });
2013-12-01 22:58:25 +02:00
}
return $table->addColumn('amount', function($model){ return '$' . money_format('%i', $model->amount); })
->addColumn('credit_date', function($model) { return (new Carbon($model->credit_date))->toFormattedDateString(); })
->orderColumns('number')
->make();
}
2013-12-04 18:20:14 +02:00
public function archive($publicId)
2013-12-01 22:58:25 +02:00
{
2013-12-04 18:20:14 +02:00
$credit = Credit::scope($publicId)->firstOrFail();
2013-12-01 22:58:25 +02:00
$creidt->delete();
Session::flash('message', 'Successfully archived credit ' . $credit->credit_number);
return Redirect::to('credits');
}
2013-12-04 18:20:14 +02:00
public function delete($publicId)
2013-12-01 22:58:25 +02:00
{
2013-12-04 18:20:14 +02:00
$credit = Credit::scope($publicId)->firstOrFail();
2013-12-01 22:58:25 +02:00
$credit->forceDelete();
Session::flash('message', 'Successfully deleted credit ' . $credit->credit_number);
return Redirect::to('credits');
}
}