1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-17 16:42:48 +01:00
This commit is contained in:
Hillel Coren 2013-12-11 22:37:49 +02:00
parent 730b5695ea
commit cf7106e8ac
12 changed files with 0 additions and 587 deletions

View File

@ -1,18 +0,0 @@
<?php
return array(
'connections' => array(
'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'ninja',
'username' => 'ninja',
'password' => 'ninja',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
)
)
);

View File

@ -1,280 +0,0 @@
<?php
class RecurringInvoiceController extends \BaseController {
public function index()
{
return View::make('list', array(
'entityType'=>ENTITY_RECURRING_INVOICE,
'title' => '- Invoices',
'columns'=>['checkbox', 'Client', 'Total', 'How Often', 'Start Date', 'End Date', 'Action']
));
}
public function getDatatable($clientPublicId = null)
{
$query = DB::table('recurring_invoices')
->join('clients', 'clients.id', '=', 'recurring_invoices.client_id')
->join('frequencies', 'recurring_invoices.frequency_id', '=', 'frequencies.id')
->where('recurring_invoices.account_id', '=', Auth::user()->account_id)
->where('recurring_invoices.deleted_at', '=', null)
->select('clients.public_id as client_public_id', 'clients.name as client_name', 'recurring_invoices.public_id', 'total', 'frequencies.name as frequency', 'start_date', 'end_date');
if ($clientPublicId) {
$query->where('clients.public_id', '=', $clientPublicId);
}
$table = Datatable::query($query);
if (!$clientPublicId) {
$table->addColumn('checkbox', function($model) { return '<input type="checkbox" name="ids[]" value="' . $model->public_id . '">'; });
}
//$table->addColumn('invoice_number', function($model) { return link_to('invoices/' . $model->public_id . '/edit', $model->invoice_number); });
if (!$clientPublicId) {
$table->addColumn('client', function($model) { return link_to('clients/' . $model->client_public_id, $model->client_name); });
}
return $table->addColumn('total', function($model) { return '$' . money_format('%i', $model->total); })
->addColumn('frequency', function($model) { return $model->frequency; })
->addColumn('start_date', function($model) { return Utils::fromSqlDate($model->start_date); })
->addColumn('end_date', function($model) { return Utils::fromSqlDate($model->end_date); })
->addColumn('dropdown', function($model)
{
return '<div class="btn-group tr-action" style="visibility:hidden;">
<button type="button" class="btn btn-xs btn-default dropdown-toggle" data-toggle="dropdown">
Select <span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu">
<li><a href="' . URL::to('invoices/'.$model->public_id.'/edit') . '">Edit Recurring Invoice</a></li>
<li class="divider"></li>
<li><a href="' . URL::to('invoices/'.$model->public_id.'/archive') . '">Archive Recurring Invoice</a></li>
<li><a href="javascript:deleteEntity(' . $model->public_id . ')">Delete Recurring Invoice</a></li>
</ul>
</div>';
})
->orderColumns('client','total','how_often','start_date','end_date')
->make();
}
public function edit($publicId)
{
$invoice = RecurringInvoice::scope($publicId)->with('account.country', 'client', 'invoice_items')->firstOrFail();
Utils::trackViewed($invoice->getName() . ' - ' . $invoice->client->name, ENTITY_RECURRING_INVOICE);
$data = array(
'account' => $invoice->account,
'invoice' => $invoice,
'method' => 'PUT',
'url' => 'recurring_invoices/' . $publicId,
'title' => '- ' . $invoice->getName(),
'client' => $invoice->client);
$data = array_merge($data, InvoiceController::getViewModel(true));
return View::make('invoices.edit', $data);
}
public function create($clientPublicId = 0)
{
$client = null;
$invoiceNumber = Auth::user()->account->getNextInvoiceNumber();
$account = Account::with('country')->findOrFail(Auth::user()->account_id);
if ($clientPublicId) {
$client = Client::scope($clientPublicId)->firstOrFail();
}
$data = array(
'account' => $account,
'invoice' => null,
'invoiceNumber' => $invoiceNumber,
'method' => 'POST',
'url' => 'recurring_invoices',
'title' => '- New Recurring Invoice',
'client' => $client,
'items' => json_decode(Input::old('items')));
$data = array_merge($data, InvoiceController::getViewModel(true));
return View::make('invoices.edit', $data);
}
public function store()
{
return RecurringInvoiceController::save();
}
private function save($publicId = null)
{
$action = Input::get('action');
if ($action == 'archive' || $action == 'delete')
{
return RecurringInvoiceController::bulk();
}
$rules = array(
'client' => 'required',
);
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails()) {
return Redirect::to('invoices/create')
->withInput()
->withErrors($validator);
} else {
$clientPublicId = Input::get('client');
if ($clientPublicId == "-1")
{
$client = Client::createNew();
$client->name = trim(Input::get('name'));
$client->work_phone = trim(Input::get('work_phone'));
$client->address1 = trim(Input::get('address1'));
$client->address2 = trim(Input::get('address2'));
$client->city = trim(Input::get('city'));
$client->state = trim(Input::get('state'));
$client->postal_code = trim(Input::get('postal_code'));
if (Input::get('country_id')) {
$client->country_id = Input::get('country_id');
}
$client->save();
$clientId = $client->id;
$contact = Contact::createNew();
$contact->is_primary = true;
$contact->first_name = trim(Input::get('first_name'));
$contact->last_name = trim(Input::get('last_name'));
$contact->phone = trim(Input::get('phone'));
$contact->email = trim(Input::get('email'));
$client->contacts()->save($contact);
}
else
{
$client = Client::scope($clientPublicId)->with('contacts')->firstOrFail();
$contact = $client->contacts()->first();
}
if ($publicId) {
$invoice = RecurringInvoice::scope($publicId)->firstOrFail();
$invoice->invoice_items()->forceDelete();
} else {
$invoice = RecurringInvoice::createNew();
}
$invoice->client_id = $client->id;
$invoice->discount = 0;
$invoice->frequency_id = Input::get('frequency');
$invoice->start_date = Utils::toSqlDate(Input::get('start_date', null));
$invoice->end_date = Utils::toSqlDate(Input::get('end_date', null));
$invoice->notes = Input::get('notes');
$client->invoices()->save($invoice);
$items = json_decode(Input::get('items'));
$total = 0;
foreach ($items as $item)
{
if (!isset($item->cost)) {
$item->cost = 0;
}
if (!isset($item->qty)) {
$item->qty = 0;
}
$total += floatval($item->qty) * floatval($item->cost);
}
$invoice->total = $total;
$invoice->save();
foreach ($items as $item)
{
if (!$item->cost && !$item->qty && !$item->product_key && !$item->notes)
{
continue;
}
if ($item->product_key)
{
$product = Product::findProductByKey(trim($item->product_key));
if (!$product)
{
$product = Product::createNew();
$product->product_key = trim($item->product_key);
}
/*
$product->notes = $item->notes;
$product->cost = $item->cost;
$product->qty = $item->qty;
*/
$product->save();
}
$invoiceItem = RecurringInvoiceItem::createNew();
$invoiceItem->product_id = isset($product) ? $product->id : null;
$invoiceItem->product_key = trim($item->product_key);
$invoiceItem->notes = trim($item->notes);
$invoiceItem->cost = floatval($item->cost);
$invoiceItem->qty = floatval($item->qty);
$invoice->invoice_items()->save($invoiceItem);
}
Session::flash('message', 'Successfully saved recurring invoice');
$url = 'recurring_invoices/' . $invoice->public_id . '/edit';
return Redirect::to($url);
}
}
/**
* Display the specified resource.
*
* @param int $id
* @return Response
*/
public function show($publicId)
{
return Redirect::to('recurring_invoices/'.$publicId.'/edit');
}
/**
* Update the specified resource in storage.
*
* @param int $id
* @return Response
*/
public function update($publicId)
{
return RecurringInvoiceController::save($publicId);
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return Response
*/
public function bulk()
{
$action = Input::get('action');
$ids = Input::get('id') ? Input::get('id') : Input::get('ids');
$invoices = RecurringInvoice::scope($ids)->get();
foreach ($invoices as $invoice) {
if ($action == 'archive') {
$invoice->delete();
} else if ($action == 'delete') {
$invoice->forceDelete();
}
}
$message = Utils::pluralize('Successfully '.$action.'d ? recurring invoice', count($ids));
Session::flash('message', $message);
return Redirect::to('invoices');
}
}

View File

@ -1,88 +0,0 @@
<?php
class RecurringInvoice extends EntityModel
{
protected $hidden = array('id', 'account_id', 'client_id', 'created_at', 'updated_at', 'deleted_at');
public function account()
{
return $this->belongsTo('Account');
}
public function client()
{
return $this->belongsTo('Client');
}
public function invoice_items()
{
return $this->hasMany('RecurringInvoiceItem');
}
public function freqency()
{
return $this->belongsTo('Frequency');
}
public function getName()
{
return $this->start_date;
}
public function getEntityType()
{
return ENTITY_RECURRING_INVOICE;
}
public function shouldSendToday()
{
$dayOfWeekToday = date('w');
$dayOfWeekStart = date('w', strtotime($this->start_date));
$dayOfMonthToday = date('j');
$dayOfMonthStart = date('j', strtotime($this->start_date));
if (!$this->last_sent_date) {
$daysSinceLastSent = 0;
$monthsSinceLastSent = 0;
} else {
$date1 = new DateTime($this->last_sent_date);
$date2 = new DateTime();
$diff = $date2->diff($date1);
$daysSinceLastSent = $diff->format("%a");
$monthsSinceLastSent = ($diff->format('%y') * 12) + $diff->format('%m');
if ($daysSinceLastSent == 0) {
return false;
}
}
switch ($this->frequency_id)
{
case FREQUENCY_WEEKLY:
return $dayOfWeekStart == $dayOfWeekToday;
case FREQUENCY_TWO_WEEKS:
return $dayOfWeekStart == $dayOfWeekToday && (!$daysSinceLastSent || $daysSinceLastSent == 14);
case FREQUENCY_FOUR_WEEKS:
return $dayOfWeekStart == $dayOfWeekToday && (!$daysSinceLastSent || $daysSinceLastSent == 28);
case FREQUENCY_MONTHLY:
return $dayOfMonthStart == $dayOfMonthToday || $daysSinceLastSent > 31;
case FREQUENCY_THREE_MONTHS:
return ($dayOfMonthStart == $dayOfMonthToday && (!$daysSinceLastSent || $monthsSinceLastSent == 3)) || $daysSinceLastSent > (3 * 31);
case FREQUENCY_SIX_MONTHS:
return ($dayOfMonthStart == $dayOfMonthToday && (!$daysSinceLastSent || $monthsSinceLastSent == 6)) || $daysSinceLastSent > (6 * 31);
case FREQUENCY_ANNUALLY:
return ($dayOfMonthStart == $dayOfMonthToday && (!$daysSinceLastSent || $monthsSinceLastSent == 12)) || $daysSinceLastSent > (12 *31);
default:
echo "Error: invalid frequency_id - ".$this->frequency_id; exit; //TODO_FIX
break;
}
return false;
}
}
RecurringInvoice::created(function($invoice)
{
Activity::createInvoice($invoice, true);
});

View File

@ -1,6 +0,0 @@
<?php
class RecurringInvoiceItem extends EntityModel
{
}

View File

@ -1,55 +0,0 @@
<table class="table {{ $class = str_random(8) }}">
<colgroup>
@for ($i = 0; $i < count($columns); $i++)
<col class="con{{ $i }}" />
@endfor
</colgroup>
<thead>
<tr>
@foreach($columns as $i => $c)
<th align="center" valign="middle" class="head{{ $i }}">
@if ($c == 'checkbox' && $haeCheckboxes = true)
<input type="checkbox" id="selectAll"/>
@else
{{ $c }}
@endif
</th>
@endforeach
</tr>
</thead>
<tbody>
@foreach($data as $d)
<tr>
@foreach($d as $dd)
<td>{{ $dd }}</td>
@endforeach
</tr>
@endforeach
</tbody>
</table>
<script type="text/javascript">
jQuery(document).ready(function(){
// dynamic table
jQuery('.{{ $class }}').dataTable({
// Disable sorting on the first column
@if ($haeCheckboxes)
"aoColumnDefs" : [ {
'bSortable' : false,
'aTargets' : [ 0 ]
} ],
@endif
@foreach ($options as $k => $o)
{{ json_encode($k) }}: {{ json_encode($o) }},
@endforeach
@foreach ($callbacks as $k => $o)
{{ json_encode($k) }}: {{ $o }},
@endforeach
"fnDrawCallback": function(oSettings) {
//jQuery.uniform.update();
if (window.onDatatableReady) {
window.onDatatableReady();
}
}
});
});
</script>

View File

@ -1,4 +0,0 @@
@extends('master')
@section('content')
<h2>Hello</h2>
@stop

View File

@ -1,82 +0,0 @@
@extends('master')
@section('content')
<style type="text/css">
body {
padding-top: 40px;
padding-bottom: 40px;
background-color: #eee !important;
}
.form-signin {
max-width: 330px;
padding: 15px;
margin: 0 auto;
}
.form-signin .form-signin-heading,
.form-signin .checkbox {
margin-bottom: 10px;
}
.form-signin .checkbox {
font-weight: normal;
}
.form-signin .form-control {
position: relative;
font-size: 16px;
height: auto;
padding: 10px;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.form-signin .form-control:focus {
z-index: 2;
}
.form-signin input[type="text"] {
margin-bottom: -1px;
border-bottom-left-radius: 0;
border-bottom-right-radius: 0;
}
.form-signin input[type="password"] {
margin-bottom: 10px;
border-top-left-radius: 0;
border-top-right-radius: 0;
}
</style>
<div class="container">
{{ Form::open(array('url' => 'user/login', 'class' => 'form-signin')) }}
<h2 class="form-signin-heading">Please sign in</h2>
<p>
{{ $errors->first('email') }}
{{ $errors->first('password') }}
</p>
<p>
{{ Form::text('email', Input::old('email'), array('placeholder' => 'Email address')) }}
{{ Form::password('password', array('placeholder' => 'Password')) }}
</p>
<p>{{ Button::primary_submit('Sign In', array('class' => 'btn-lg'))->block() }}</p>
{{ link_to('user/forgot_password', 'Recover your password') }}
<!-- if there are login errors, show them here -->
@if ( Session::get('error') )
<div class="alert alert-error">{{{ Session::get('error') }}}</div>
@endif
@if ( Session::get('notice') )
<div class="alert">{{{ Session::get('notice') }}}</div>
@endif
{{ Form::close() }}
</div>
@stop

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long