mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-05 18:52:44 +01:00
Project numbers
This commit is contained in:
parent
f9062e75d6
commit
86d472fa05
@ -266,6 +266,7 @@ class ProjectController extends BaseController
|
||||
}
|
||||
|
||||
$project->fill($request->all());
|
||||
$project->number = empty($project->number) ? $this->getNextProjectNumber($project) : $project->number;
|
||||
$project->save();
|
||||
|
||||
return $this->itemResponse($project->fresh());
|
||||
@ -360,9 +361,13 @@ 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(empty($project->number)){
|
||||
$project->number = $this->getNextProjectNumber($project);
|
||||
$project->save();
|
||||
}
|
||||
|
||||
if ($request->has('documents')) {
|
||||
$this->saveDocuments($request->input('documents'), $project);
|
||||
}
|
||||
|
@ -36,6 +36,7 @@ class StoreProjectRequest extends Request
|
||||
|
||||
$rules['name'] = 'required';
|
||||
$rules['client_id'] = 'required|exists:clients,id,company_id,'.auth()->user()->company()->id;
|
||||
$rules['number'] = 'unique:projects,number,'.$this->id.',id,company_id,'.auth()->user()->company()->id;
|
||||
|
||||
return $this->globalRules($rules);
|
||||
}
|
||||
|
@ -33,6 +33,10 @@ class UpdateProjectRequest extends Request
|
||||
{
|
||||
$rules = [];
|
||||
|
||||
if ($this->input('number')) {
|
||||
$rules['number'] = 'unique:projects,number,'.$this->id.',id,company_id,'.$this->project->company_id;
|
||||
}
|
||||
|
||||
return $this->globalRules($rules);
|
||||
}
|
||||
|
||||
|
@ -50,18 +50,12 @@ class ExpenseRepository extends BaseRepository
|
||||
{
|
||||
$expense->fill($data);
|
||||
$expense->number = empty($expense->number) ? $this->getNextExpenseNumber($expense) : $expense->number;
|
||||
|
||||
$expense->save();
|
||||
|
||||
|
||||
if (array_key_exists('documents', $data)) {
|
||||
$this->saveDocuments($data['documents'], $expense);
|
||||
}
|
||||
|
||||
// if ($expense->id_number == "" || !$expense->id_number) {
|
||||
// $expense->id_number = $this->getNextExpenseNumber($expense);
|
||||
// } //todo write tests for this and make sure that custom expense numbers also works as expected from here
|
||||
|
||||
return $expense;
|
||||
}
|
||||
|
||||
|
@ -230,45 +230,6 @@ trait GeneratesCounter
|
||||
return (string) $payment_number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Project Number Generator.
|
||||
* @param Client $client
|
||||
* @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.
|
||||
*
|
||||
@ -313,6 +274,27 @@ trait GeneratesCounter
|
||||
return $vendor_number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Project Number Generator.
|
||||
* @param Project $project
|
||||
* @return string The project number
|
||||
*/
|
||||
public function getNextProjectNumber(Project $project) :string
|
||||
{
|
||||
|
||||
$this->resetCompanyCounters($project->company);
|
||||
|
||||
$counter = $project->company->settings->project_number_counter;
|
||||
$setting_entity = $project->company->settings->project_number_counter;
|
||||
|
||||
$project_number = $this->checkEntityNumber(Project::class, $project, $counter, $project->company->settings->counter_padding, $project->company->settings->project_number_pattern);
|
||||
|
||||
$this->incrementCounter($project->company, 'project_number_counter');
|
||||
|
||||
return $project_number;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the next task number.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user