1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 05:02:36 +01:00
This commit is contained in:
David Bomba 2024-03-13 10:36:41 +11:00
parent 1de5bbfdc4
commit 1b999dd7d9
8 changed files with 6982 additions and 6520 deletions

View File

@ -978,6 +978,16 @@ class CheckData extends Command
}); });
$cus = CompanyUser::withTrashed()
->whereHas("user", function ($query) {
$query->whereColumn("users.account_id", "!=", "company_user.account_id");
})->pluck('id')->implode(",");
$this->logMessage("Cross Linked CompanyUser ids # {$cus}");
} }
} }

View File

@ -271,6 +271,7 @@ class InvitationController extends Controller
->with('contact.client') ->with('contact.client')
->firstOrFail(); ->firstOrFail();
if ($invitation->contact->trashed()) { if ($invitation->contact->trashed()) {
$invitation->contact->restore(); $invitation->contact->restore();
} }
@ -294,7 +295,10 @@ class InvitationController extends Controller
'payable_invoices' => [ 'payable_invoices' => [
['invoice_id' => $invitation->invoice->hashed_id, 'amount' => $amount], ['invoice_id' => $invitation->invoice->hashed_id, 'amount' => $amount],
], ],
'signature' => false 'signature' => false,
'contact_first_name' => $invitation->contact->first_name ?? '',
'contact_last_name' => $invitation->contact->last_name ?? '',
'contact_email' => $invitation->contact->email ?? ''
]; ];
$request->replace($data); $request->replace($data);

View File

@ -59,20 +59,6 @@ class StoreClientRequest extends Request
$rules['file'] = $this->file_validation; $rules['file'] = $this->file_validation;
} }
if (isset($this->number)) {
$rules['number'] = Rule::unique('clients')->where('company_id', $user->company()->id);
}
$rules['country_id'] = 'integer|nullable';
if (isset($this->currency_code)) {
$rules['currency_code'] = 'sometimes|exists:currencies,code';
}
if (isset($this->country_code)) {
$rules['country_code'] = new CountryCodeExistsRule();
}
/* Ensure we have a client name, and that all emails are unique*/ /* Ensure we have a client name, and that all emails are unique*/
//$rules['name'] = 'required|min:1'; //$rules['name'] = 'required|min:1';
$rules['settings'] = new ValidClientGroupSettingsRule(); $rules['settings'] = new ValidClientGroupSettingsRule();
@ -97,6 +83,9 @@ class StoreClientRequest extends Request
$rules['number'] = ['bail', 'nullable', Rule::unique('clients')->where('company_id', $user->company()->id)]; $rules['number'] = ['bail', 'nullable', Rule::unique('clients')->where('company_id', $user->company()->id)];
$rules['id_number'] = ['bail', 'nullable', Rule::unique('clients')->where('company_id', $user->company()->id)]; $rules['id_number'] = ['bail', 'nullable', Rule::unique('clients')->where('company_id', $user->company()->id)];
$rules['classification'] = 'bail|sometimes|nullable|in:individual,business,company,partnership,trust,charity,government,other'; $rules['classification'] = 'bail|sometimes|nullable|in:individual,business,company,partnership,trust,charity,government,other';
$rules['shipping_country_id'] = 'integer|nullable|exists:countries,id';
$rules['number'] = ['sometimes', 'nullable', 'bail', Rule::unique('clients')->where('company_id', $user->company()->id)];
$rules['country_id'] = 'integer|nullable|exists:countries,id';
return $rules; return $rules;
} }
@ -144,7 +133,11 @@ class StoreClientRequest extends Request
} else { } else {
$input['settings']['currency_id'] = (string) $user->company()->settings->currency_id; $input['settings']['currency_id'] = (string) $user->company()->settings->currency_id;
} }
} elseif (! array_key_exists('currency_id', $input['settings'])) { }
elseif (! array_key_exists('currency_id', $input['settings'])) {
$input['settings']['currency_id'] = (string) $user->company()->settings->currency_id;
}
elseif (empty($input['settings']['currency_id']) ?? true) {
$input['settings']['currency_id'] = (string) $user->company()->settings->currency_id; $input['settings']['currency_id'] = (string) $user->company()->settings->currency_id;
} }
@ -160,10 +153,13 @@ class StoreClientRequest extends Request
} }
} }
// allow setting country_id by iso code
if (isset($input['country_code'])) { if (isset($input['country_code'])) {
$input['country_id'] = $this->getCountryCode($input['country_code']); $input['country_id'] = $this->getCountryCode($input['country_code']);
} }
// allow setting country_id by iso code
if (isset($input['shipping_country_code'])) { if (isset($input['shipping_country_code'])) {
$input['shipping_country_id'] = $this->getCountryCode($input['shipping_country_code']); $input['shipping_country_id'] = $this->getCountryCode($input['shipping_country_code']);
} }
@ -173,10 +169,14 @@ class StoreClientRequest extends Request
unset($input['number']); unset($input['number']);
} }
// prevent xss injection
if (array_key_exists('name', $input)) { if (array_key_exists('name', $input)) {
$input['name'] = strip_tags($input['name']); $input['name'] = strip_tags($input['name']);
} }
//If you want to validate, the prop must be set.
$input['id'] = null;
$this->replace($input); $this->replace($input);
} }

View File

@ -60,17 +60,11 @@ class UpdateClientRequest extends Request
$rules['company_logo'] = 'mimes:jpeg,jpg,png,gif|max:10000'; $rules['company_logo'] = 'mimes:jpeg,jpg,png,gif|max:10000';
$rules['industry_id'] = 'integer|nullable'; $rules['industry_id'] = 'integer|nullable';
$rules['size_id'] = 'integer|nullable'; $rules['size_id'] = 'integer|nullable';
$rules['country_id'] = 'integer|nullable'; $rules['country_id'] = 'integer|nullable|exists:countries,id';
$rules['shipping_country_id'] = 'integer|nullable'; $rules['shipping_country_id'] = 'integer|nullable|exists:countries,id';
$rules['classification'] = 'bail|sometimes|nullable|in:individual,business,company,partnership,trust,charity,government,other'; $rules['classification'] = 'bail|sometimes|nullable|in:individual,business,company,partnership,trust,charity,government,other';
$rules['id_number'] = ['sometimes', 'bail', Rule::unique('clients')->where('company_id', $user->company()->id)->ignore($this->client->id)];
if ($this->id_number) { $rules['number'] = ['sometimes', 'bail', Rule::unique('clients')->where('company_id', $user->company()->id)->ignore($this->client->id)];
$rules['id_number'] = Rule::unique('clients')->where('company_id', $user->company()->id)->ignore($this->client->id);
}
if ($this->number) {
$rules['number'] = Rule::unique('clients')->where('company_id', $user->company()->id)->ignore($this->client->id);
}
$rules['settings'] = new ValidClientGroupSettingsRule(); $rules['settings'] = new ValidClientGroupSettingsRule();
$rules['contacts'] = 'array'; $rules['contacts'] = 'array';
@ -112,6 +106,9 @@ class UpdateClientRequest extends Request
if (array_key_exists('settings', $input) && ! array_key_exists('currency_id', $input['settings'])) { if (array_key_exists('settings', $input) && ! array_key_exists('currency_id', $input['settings'])) {
$input['settings']['currency_id'] = (string) $user->company()->settings->currency_id; $input['settings']['currency_id'] = (string) $user->company()->settings->currency_id;
} }
elseif (empty($input['settings']['currency_id']) ?? true) {
$input['settings']['currency_id'] = (string) $user->company()->settings->currency_id;
}
if (isset($input['language_code'])) { if (isset($input['language_code'])) {
$input['settings']['language_id'] = $this->getLanguageId($input['language_code']); $input['settings']['language_id'] = $this->getLanguageId($input['language_code']);
@ -127,9 +124,35 @@ class UpdateClientRequest extends Request
$input['name'] = strip_tags($input['name']); $input['name'] = strip_tags($input['name']);
} }
// allow setting country_id by iso code
if (isset($input['country_code'])) {
$input['country_id'] = $this->getCountryCode($input['country_code']);
}
// allow setting country_id by iso code
if (isset($input['shipping_country_code'])) {
$input['shipping_country_id'] = $this->getCountryCode($input['shipping_country_code']);
}
$this->replace($input); $this->replace($input);
} }
private function getCountryCode($country_code)
{
$countries = Cache::get('countries');
$country = $countries->filter(function ($item) use ($country_code) {
return $item->iso_3166_2 == $country_code || $item->iso_3166_3 == $country_code;
})->first();
if ($country) {
return (string) $country->id;
}
return '';
}
private function getLanguageId($language_code) private function getLanguageId($language_code)
{ {
$languages = Cache::get('languages'); $languages = Cache::get('languages');

View File

@ -44,7 +44,6 @@ class InstantPayment
public function run() public function run()
{ {
nlog($this->request->all());
$cc = auth()->guard('contact')->user(); $cc = auth()->guard('contact')->user();

View File

@ -622,6 +622,33 @@ class HtmlEngine
$data['$task.task3'] = ['value' => '', 'label' => $this->helpers->makeCustomField($this->company->custom_fields, 'task3')]; $data['$task.task3'] = ['value' => '', 'label' => $this->helpers->makeCustomField($this->company->custom_fields, 'task3')];
$data['$task.task4'] = ['value' => '', 'label' => $this->helpers->makeCustomField($this->company->custom_fields, 'task4')]; $data['$task.task4'] = ['value' => '', 'label' => $this->helpers->makeCustomField($this->company->custom_fields, 'task4')];
if($this->entity->vendor) {
$data['$vendor_name'] = ['value' => $this->entity->vendor->present()->name() ?: ' ', 'label' => ctrans('texts.vendor_name')];
$data['$vendor.name'] = &$data['$vendor_name'];
$data['$vendor'] = &$data['$vendor_name'];
$data['$vendor.address1'] = ['value' => $this->entity->vendor->address1 ?: ' ', 'label' => ctrans('texts.address1')];
$data['$vendor.address2'] = ['value' => $this->entity->vendor->address2 ?: ' ', 'label' => ctrans('texts.address2')];
$data['$vendor.id_number'] = ['value' => $this->entity->vendor->id_number ?: ' ', 'label' => ctrans('texts.id_number')];
$data['$vendor.number'] = ['value' => $this->entity->vendor->number ?: ' ', 'label' => ctrans('texts.number')];
$data['$vendor.vat_number'] = ['value' => $this->entity->vendor->vat_number ?: ' ', 'label' => ctrans('texts.vat_number')];
$data['$vendor.website'] = ['value' => $this->entity->vendor->present()->website() ?: ' ', 'label' => ctrans('texts.website')];
$data['$vendor.phone'] = ['value' => $this->entity->vendor->present()->phone() ?: ' ', 'label' => ctrans('texts.phone')];
$data['$vendor.country'] = ['value' => isset($this->entity->vendor->country->name) ? ctrans('texts.country_' . $this->entity->vendor->country->name) : '', 'label' => ctrans('texts.country')];
$data['$vendor.country_2'] = ['value' => isset($this->entity->vendor->country) ? $this->entity->vendor->country->iso_3166_2 : '', 'label' => ctrans('texts.country')];
$data['$vendor_address'] = ['value' => $this->entity->vendor->present()->address() ?: ' ', 'label' => ctrans('texts.address')];
$data['$vendor.address'] = &$data['$vendor_address'];
$data['$vendor.postal_code'] = ['value' => $this->entity->vendor->postal_code ?: ' ', 'label' => ctrans('texts.postal_code')];
$data['$vendor.public_notes'] = ['value' => $this->entity->vendor->public_notes ?: ' ', 'label' => ctrans('texts.notes')];
$data['$vendor.city'] = ['value' => $this->entity->vendor->city ?: ' ', 'label' => ctrans('texts.city')];
$data['$vendor.state'] = ['value' => $this->entity->vendor->state ?: ' ', 'label' => ctrans('texts.state')];
$data['$vendor.city_state_postal'] = ['value' => $this->entity->vendor->present()->cityStateZip($this->entity->vendor->city, $this->entity->vendor->state, $this->entity->vendor->postal_code, false) ?: ' ', 'label' => ctrans('texts.city_state_postal')];
$data['$vendor.postal_city_state'] = ['value' => $this->entity->vendor->present()->cityStateZip($this->entity->vendor->city, $this->entity->vendor->state, $this->entity->vendor->postal_code, true) ?: ' ', 'label' => ctrans('texts.postal_city_state')];
$data['$vendor.postal_city'] = ['value' => $this->entity->vendor->present()->cityStateZip($this->entity->vendor->city, null, $this->entity->vendor->postal_code, true) ?: ' ', 'label' => ctrans('texts.postal_city')];
}
if ($this->settings->signature_on_pdf) { if ($this->settings->signature_on_pdf) {
$data['$contact.signature'] = ['value' => $this->invitation->signature_base64, 'label' => ctrans('texts.signature')]; $data['$contact.signature'] = ['value' => $this->invitation->signature_base64, 'label' => ctrans('texts.signature')];
$data['$contact.signature_date'] = ['value' => $this->translateDate($this->invitation->signature_date, $this->client->date_format(), $this->client->locale()), 'label' => ctrans('texts.date')]; $data['$contact.signature_date'] = ['value' => $this->translateDate($this->invitation->signature_date, $this->client->date_format(), $this->client->locale()), 'label' => ctrans('texts.date')];

File diff suppressed because it is too large Load Diff

View File

@ -59,6 +59,409 @@ class ClientApiTest extends TestCase
Model::reguard(); Model::reguard();
} }
public function testCountryCodeValidation()
{
$data = [
'name' => 'name of client',
'country_code' => 'USA',
'id_number' => 'x-1-11a'
];
$response = $this->withHeaders([
'X-API-TOKEN' => $this->token,
])->postJson("/api/v1/clients/", $data)
->assertStatus(200);
$arr = $response->json();
$this->assertEquals("840", $arr['data']['country_id']);
$data = [
'name' => 'name of client',
'country_code' => 'aaaaaaaaaa',
'id_number' => 'x-1-11a'
];
$response = $this->withHeaders([
'X-API-TOKEN' => $this->token,
])->postJson("/api/v1/clients/", $data)
->assertStatus(422);
$this->assertEquals($this->company->settings->country_id, $arr['data']['country_id']);
$data = [
'name' => 'name of client',
'country_code' => 'aaaaaaaaaa',
];
$response = $this->withHeaders([
'X-API-TOKEN' => $this->token,
])->putJson("/api/v1/clients/".$this->client->hashed_id, $data)
->assertStatus(200);
$this->assertEquals($this->company->settings->country_id, $arr['data']['country_id']);
}
public function testIdNumberPutValidation()
{
$data = [
'name' => 'name of client',
'country_id' => '840',
'id_number' => 'x-1-11a'
];
$response = $this->withHeaders([
'X-API-TOKEN' => $this->token,
])->putJson("/api/v1/clients/".$this->client->hashed_id, $data)
->assertStatus(200);
$data = [
'name' => 'name of client',
'country_id' => '840',
];
$response = $this->withHeaders([
'X-API-TOKEN' => $this->token,
])->postJson("/api/v1/clients/", $data)
->assertStatus(200);
$arr = $response->json();
$data = [
'name' => 'name of client',
'country_id' => '840',
'id_number' => 'x-1-11a'
];
$response = $this->withHeaders([
'X-API-TOKEN' => $this->token,
])->putJson("/api/v1/clients/".$arr['data']['id'], $data)
->assertStatus(422);
}
public function testNumberPutValidation()
{
$data = [
'name' => 'name of client',
'country_id' => '840',
'number' => 'x-1-11a'
];
$response = $this->withHeaders([
'X-API-TOKEN' => $this->token,
])->putJson("/api/v1/clients/".$this->client->hashed_id, $data)
->assertStatus(200);
$data = [
'name' => 'name of client',
'country_id' => '840',
];
$response = $this->withHeaders([
'X-API-TOKEN' => $this->token,
])->postJson("/api/v1/clients/", $data)
->assertStatus(200);
$arr = $response->json();
$data = [
'name' => 'name of client',
'country_id' => '840',
'number' => 'x-1-11a'
];
$response = $this->withHeaders([
'X-API-TOKEN' => $this->token,
])->putJson("/api/v1/clients/".$arr['data']['id'], $data)
->assertStatus(422);
}
public function testNumberValidation()
{
$data = [
'name' => 'name of client',
'country_id' => '840',
'number' => 'x-1-11'
];
$response = $this->withHeaders([
'X-API-TOKEN' => $this->token,
])->postJson("/api/v1/clients/",$data)
->assertStatus(200);
$arr = $response->json();
$this->assertEquals("x-1-11", $arr['data']['number']);
$data = [
'name' => 'name of client',
'country_id' => '840',
'number' => 'x-1-11'
];
$response = $this->withHeaders([
'X-API-TOKEN' => $this->token,
])->postJson("/api/v1/clients/", $data)
->assertStatus(422);
$data = [
'name' => 'name of client',
'country_id' => '840',
'number' => ''
];
$response = $this->withHeaders([
'X-API-TOKEN' => $this->token,
])->postJson("/api/v1/clients/", $data)
->assertStatus(200);
$data = [
'name' => 'name of client',
'country_id' => '840',
'number' => null
];
$response = $this->withHeaders([
'X-API-TOKEN' => $this->token,
])->postJson("/api/v1/clients/", $data)
->assertStatus(200);
}
public function testCountryStore4()
{
$data = [
'name' => 'name of client',
'country_id' => '840',
];
$response = $this->withHeaders([
'X-API-TOKEN' => $this->token,
])->putJson("/api/v1/clients/".$this->client->hashed_id,$data)
->assertStatus(200);
$arr = $response->json();
$this->assertEquals("840", $arr['data']['country_id']);
}
public function testCountryStore3()
{
$data = [
'name' => 'name of client',
'country_id' => 'A',
];
$response = $this->withHeaders([
'X-API-TOKEN' => $this->token,
])->putJson("/api/v1/clients/".$this->client->hashed_id,$data)
->assertStatus(422);
}
public function testCountryStore2()
{
$data = [
'name' => 'name of client',
'country_id' => 'A',
];
$response = $this->withHeaders([
'X-API-TOKEN' => $this->token,
])->postJson("/api/v1/clients/",$data)
->assertStatus(422);
}
public function testCountryStore()
{
$data = [
'name' => 'name of client',
'country_id' => '8',
];
$response = $this->withHeaders([
'X-API-TOKEN' => $this->token,
])->postJson("/api/v1/clients/",$data)
->assertStatus(200);
$arr = $response->json();
$this->assertEquals("8", $arr['data']['country_id']);
}
public function testCurrencyStores8()
{
$data = [
'name' => 'name of client',
'settings' => [
'currency_id' => '2'
],
];
$response = $this->withHeaders([
'X-API-TOKEN' => $this->token,
])->postJson("/api/v1/clients/",$data)
->assertStatus(200);
$arr = $response->json();
$this->assertEquals("2", $arr['data']['settings']['currency_id']);
}
public function testCurrencyStores7()
{
$data = [
'name' => 'name of client',
'settings' => [
'currency_id' => '2'
],
];
$response = $this->withHeaders([
'X-API-TOKEN' => $this->token,
])->putJson("/api/v1/clients/".$this->client->hashed_id,$data)
->assertStatus(200);
$arr = $response->json();
$this->assertEquals("2", $arr['data']['settings']['currency_id']);
}
public function testCurrencyStores6()
{
$data = [
'name' => 'name of client',
'settings' => [
'currency_id' => '1'
],
];
$response = $this->withHeaders([
'X-API-TOKEN' => $this->token,
])->putJson("/api/v1/clients/".$this->client->hashed_id,$data)
->assertStatus(200);
$arr = $response->json();
$this->assertEquals("1", $arr['data']['settings']['currency_id']);
}
public function testCurrencyStores5()
{
$data = [
'name' => 'name of client',
'settings' => [
'currency_id' => ''
],
];
$response = $this->withHeaders([
'X-API-TOKEN' => $this->token,
])->putJson("/api/v1/clients/".$this->client->hashed_id,$data)
->assertStatus(200);
$arr = $response->json();
$this->assertEquals($this->company->settings->currency_id, $arr['data']['settings']['currency_id']);
}
public function testCurrencyStores4()
{
$data = [
'name' => 'name of client',
'settings' => [
'currency_id' => 'A'
],
];
$response = $this->withHeaders([
'X-API-TOKEN' => $this->token,
])->putJson("/api/v1/clients/".$this->client->hashed_id,$data)
->assertStatus(422);
$arr = $response->json();
// $this->assertEquals($this->company->settings->currency_id, $arr['data']['settings']['currency_id']);
}
public function testCurrencyStores3()
{
$data = [
'name' => 'name of client',
'settings' => [
'currency_id' => 'A'
],
];
$response = $this->withHeaders([
'X-API-TOKEN' => $this->token,
])->postJson("/api/v1/clients",$data)
->assertStatus(422);
$arr = $response->json();
// $this->assertEquals($this->company->settings->currency_id, $arr['data']['settings']['currency_id']);
}
public function testCurrencyStores2()
{
$data = [
'name' => 'name of client',
'settings' => [
'currency_id' => ''
],
];
$response = $this->withHeaders([
'X-API-TOKEN' => $this->token,
])->postJson("/api/v1/clients",$data)
->assertStatus(200);
$arr = $response->json();
$this->assertEquals($this->company->settings->currency_id, $arr['data']['settings']['currency_id']);
}
public function testCurrencyStores()
{
$data = [
'name' => 'name of client',
'settings' => [],
];
$response = $this->withHeaders([
'X-API-TOKEN' => $this->token,
])->postJson("/api/v1/clients",$data)
->assertStatus(200);
$arr = $response->json();
$this->assertEquals($this->company->settings->currency_id, $arr['data']['settings']['currency_id']);
}
public function testDocumentValidation() public function testDocumentValidation()
{ {
$data = [ $data = [
@ -907,7 +1310,7 @@ $this->assertCount(7, $arr['data']);
'X-API-TOKEN' => $this->token, 'X-API-TOKEN' => $this->token,
])->post('/api/v1/clients/', $data); ])->post('/api/v1/clients/', $data);
$response->assertStatus(302); $response->assertStatus(200);
} }
public function testClientPost() public function testClientPost()
@ -1063,7 +1466,7 @@ $this->assertCount(7, $arr['data']);
$response = $this->withHeaders([ $response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'), 'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token, 'X-API-TOKEN' => $this->token,
])->post('/api/v1/clients/', $data); ])->postJson('/api/v1/clients/', $data);
$response->assertStatus(200); $response->assertStatus(200);
} }
@ -1079,9 +1482,11 @@ $this->assertCount(7, $arr['data']);
$response = $this->withHeaders([ $response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'), 'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token, 'X-API-TOKEN' => $this->token,
])->post('/api/v1/clients/', $data); ])->postJson('/api/v1/clients/', $data);
$response->assertStatus(302); $arr = $response->json();
$this->assertEquals($this->company->settings->country_id, $arr['data']['country_id']);
} }
public function testRoundingDecimalsTwo() public function testRoundingDecimalsTwo()