2013-12-01 21:58:25 +01: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-03 23:00:01 +01:00
|
|
|
'title' => '- Credits',
|
2013-12-01 21:58:25 +01:00
|
|
|
'columns'=>['checkbox', 'Credit Number', 'Client', 'Amount', 'Credit Date']
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getDatatable($clientId = null)
|
|
|
|
{
|
2013-12-03 18:32:33 +01:00
|
|
|
$collection = Credit::scope()->with('client');
|
2013-12-01 21:58:25 +01:00
|
|
|
|
|
|
|
if ($clientId) {
|
|
|
|
$collection->where('client_id','=',$clientId);
|
|
|
|
}
|
|
|
|
|
|
|
|
$table = Datatable::collection($collection->get());
|
|
|
|
|
|
|
|
if (!$clientId) {
|
|
|
|
$table->addColumn('checkbox', function($model) { return '<input type="checkbox" name="ids[]" value="' . $model->id . '">'; });
|
|
|
|
}
|
|
|
|
|
|
|
|
$table->addColumn('credit_number', function($model) { return $model->credit_number; });
|
|
|
|
|
|
|
|
if (!$clientId) {
|
|
|
|
$table->addColumn('client', function($model) { return link_to('clients/' . $model->client->id, $model->client->name); });
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function archive($id)
|
|
|
|
{
|
2013-12-03 18:32:33 +01:00
|
|
|
$credit = Credit::scope()->findOrFail($id);
|
2013-12-01 21:58:25 +01:00
|
|
|
$creidt->delete();
|
|
|
|
|
|
|
|
Session::flash('message', 'Successfully archived credit ' . $credit->credit_number);
|
|
|
|
return Redirect::to('credits');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function delete($id)
|
|
|
|
{
|
2013-12-03 18:32:33 +01:00
|
|
|
$credit = Credit::scope()->findOrFail($id);
|
2013-12-01 21:58:25 +01:00
|
|
|
$credit->forceDelete();
|
|
|
|
|
|
|
|
Session::flash('message', 'Successfully deleted credit ' . $credit->credit_number);
|
|
|
|
return Redirect::to('credits');
|
|
|
|
}
|
|
|
|
}
|