invoiceninja/app/controllers/PaymentController.php

82 lines
2.5 KiB
PHP
Raw Normal View History

2013-11-26 14:45:07 +02:00
<?php
class PaymentController extends \BaseController
{
public function index()
{
2013-12-04 00:00:01 +02:00
return View::make('list', array(
'entityType'=>ENTITY_PAYMENT,
'title' => '- Payments',
'columns'=>['checkbox', 'Transaction Reference', 'Client', 'Amount', 'Payment Date']
));
2013-11-26 14:45:07 +02:00
}
2013-12-04 18:20:14 +02:00
public function getDatatable($clientPublicId = null)
2013-11-26 14:45:07 +02:00
{
2013-12-03 19:32:33 +02:00
$collection = Payment::scope()->with('invoice.client');
2013-11-29 14:09:21 +02:00
2013-12-04 18:20:14 +02:00
if ($clientPublicId) {
$clientId = Client::getPrivateId($clientPublicId);
2013-11-29 14:09:21 +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-11-29 14:09:21 +02:00
}
2013-12-04 00:00:01 +02:00
$table->addColumn('transaction_reference', function($model) { return $model->transaction_reference; });
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-04 00:00:01 +02:00
}
return $table->addColumn('amount', function($model) { return '$' . $model->amount; })
->addColumn('date', function($model) { return timestampToDateTimeString($model->created_at); })
2013-11-26 14:45:07 +02:00
->orderColumns('client')
->make();
}
2013-12-04 18:20:14 +02:00
public function create()
{
$data = array(
'payment' => null,
'method' => 'POST',
'url' => 'payments',
'title' => '- New Payment');
return View::make('payments.edit', $data);
}
public function edit($publicId)
{
$payment = Payment::scope($publicId)->firstOrFail();
$data = array(
'payment' => $payment,
'method' => 'PUT',
'url' => 'payments/' . $publicId,
'title' => '- Edit Payment');
return View::make('payments.edit', $data);
}
public function archive($publicId)
2013-12-01 22:58:25 +02:00
{
2013-12-04 18:20:14 +02:00
$payment = Payment::scope($publicId)->firstOrFail();
2013-12-01 22:58:25 +02:00
$payment->delete();
Session::flash('message', 'Successfully archived payment');
return Redirect::to('payments');
}
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
$payment = Payment::scope($publicId)->firstOrFail();
2013-12-01 22:58:25 +02:00
$payment->forceDelete();
Session::flash('message', 'Successfully deleted payment');
return Redirect::to('payments');
}
2013-11-26 14:45:07 +02:00
}