1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00

Project number

This commit is contained in:
David Bomba 2020-10-20 10:55:14 +11:00
parent 840696ad3c
commit 686f12261d
4 changed files with 50 additions and 1 deletions

View File

@ -24,6 +24,7 @@ use App\Models\Project;
use App\Repositories\ProjectRepository;
use App\Transformers\ProjectTransformer;
use App\Utils\Traits\BulkOptions;
use App\Utils\Traits\GeneratesCounter;
use App\Utils\Traits\MakesHash;
use App\Utils\Traits\SavesDocuments;
use Illuminate\Http\Request;
@ -36,7 +37,8 @@ class ProjectController extends BaseController
{
use MakesHash;
use SavesDocuments;
use GeneratesCounter;
protected $entity_type = Project::class;
protected $entity_transformer = ProjectTransformer::class;
@ -353,6 +355,7 @@ class ProjectController extends BaseController
{
$project = ProjectFactory::create(auth()->user()->company()->id, auth()->user()->id);
$project->fill($request->all());
$project->number = $this->getNextProjectNumber($request->getClient($request->input('client_id')));
$project->save();
if ($request->has('documents')) {

View File

@ -12,6 +12,7 @@
namespace App\Http\Requests\Project;
use App\Http\Requests\Request;
use App\Models\Client;
use App\Models\Project;
use App\Utils\Traits\MakesHash;
@ -51,4 +52,9 @@ class StoreProjectRequest extends Request
$this->replace($input);
}
public function getClient($client_id)
{
return Client::find($client_id);
}
}

View File

@ -48,6 +48,7 @@ class ProjectTransformer extends EntityTransformer
'assigned_user_id' => (string) $this->encodePrimaryKey($project->assigned_user_id),
'client_id' => (string) $this->encodePrimaryKey($project->client_id),
'name' => $project->name ?: '',
'number' => $project->number,
'created_at' => (int) $project->created_at,
'updated_at' => (int) $project->updated_at,
'archived_at' => (int) $project->deleted_at,

View File

@ -16,6 +16,7 @@ use App\Models\Credit;
use App\Models\Expense;
use App\Models\Invoice;
use App\Models\Payment;
use App\Models\Project;
use App\Models\Quote;
use App\Models\RecurringInvoice;
use App\Models\Timezone;
@ -225,6 +226,44 @@ trait GeneratesCounter
return (string) $payment_number;
}
/**
* Project Number Generator.
* @return string The project number
*/
public function getNextProjectNumber(Client $client) :string
{
//Reset counters if enabled
$this->resetCounters($client);
$is_client_counter = false;
//todo handle if we have specific client patterns in the future
$pattern = $client->company->settings->project_number_pattern;
//Determine if we are using client_counters
if (strpos($pattern, 'client_counter') === false) {
$counter = $client->company->settings->project_number_counter;
} else {
$counter = $client->settings->project_number_counter;
$is_client_counter = true;
}
//Return a valid counter
$pattern = '';
$padding = $client->getSetting('counter_padding');
$project_number = $this->checkEntityNumber(Project::class, $client, $counter, $padding, $pattern);
//increment the correct invoice_number Counter (company vs client)
if ($is_client_counter) {
$this->incrementCounter($client, 'project_number_counter');
} else {
$this->incrementCounter($client->company, 'project_number_counter');
}
return (string) $project_number;
}
/**
* Gets the next client number.
*