Bulk updates

This commit is contained in:
David Bomba 2024-04-25 16:31:15 +10:00
parent 4dedfd616b
commit 108ca2633d
6 changed files with 51 additions and 19 deletions

View File

@ -266,6 +266,8 @@ class ClientController extends BaseController
$this->client_repo->bulkUpdate($clients, $request->column, $request->new_value);
return $this->listResponse(Client::query()->withTrashed()->company()->whereIn('id', $request->ids));
}
$clients->each(function ($client) use ($action, $user) {

View File

@ -18,17 +18,6 @@ use Illuminate\Validation\Rule;
class BulkClientRequest extends Request
{
use MakesHash;
private array $bulk_update_columns = [
'public_notes',
'industry_id',
'size_id',
'country_id',
'custom_value1',
'custom_value2',
'custom_value3',
'custom_value4',
];
/**
* Determine if the user is authorized to make this request.
@ -52,8 +41,8 @@ class BulkClientRequest extends Request
'template_id' => 'sometimes|string',
'group_settings_id' => ['required_if:action,assign_group',Rule::exists('group_settings', 'id')->where('company_id', $user->company()->id)],
'send_email' => 'sometimes|bool',
'column' => ['required_if:action,bulk_update','string', Rule::in($this->client_bulk_update_columns)],
'new_value' => ['required_id:action,bulk_update|string'],
'column' => ['required_if:action,bulk_update', 'string', Rule::in(\App\Models\Client::$bulk_update_columns)],
'new_value' => ['required_if:action,bulk_update|string'],
];
}

View File

@ -220,12 +220,17 @@ class Client extends BaseModel implements HasLocalePreference
'routing_id',
];
// public function scopeExclude($query)
// {
// $query->makeHidden(['balance','paid_to_date']);
public static array $bulk_update_columns = [
'public_notes',
'industry_id',
'size_id',
'country_id',
'custom_value1',
'custom_value2',
'custom_value3',
'custom_value4',
];
// return $query;
// }
public function getEntityType()
{

View File

@ -102,7 +102,12 @@ class ZugferdEDokument extends AbstractService
$this->xdocument->setDocumentShipToAddress($client->shipping_address1, $client->shipping_address2, "", $client->shipping_postal_code, $client->shipping_city, $client->shipping_country->iso_3166_2, $client->shipping_state);
}
$this->xdocument->addDocumentPaymentMean(68, ctrans("texts.xinvoice_online_payment"));
//Payment Means - Switcher
if($company->settings->custom_value1 == '42'){
$this->xdocument->addDocumentPaymentMean(typecode: 42, payeeIban: $company->settings->custom_value2, payeeAccountName: $company->settings->custom_value4, payeeBic: $company->settings->custom_value3);
}
else
$this->xdocument->addDocumentPaymentMean(68, ctrans("texts.xinvoice_online_payment"));
if (str_contains($company->getSetting('vat_number'), "/")) {
$this->xdocument->addDocumentSellerTaxRegistration("FC", $company->getSetting('vat_number'));

View File

@ -127,6 +127,10 @@ class Statics
$data['templates'] = Cache::get('templates');
}
$data['bulk_updates'] = [
'client' => \App\Models\Client::$bulk_update_columns,
];
return $data;
}
}

View File

@ -59,6 +59,33 @@ class ClientApiTest extends TestCase
Model::reguard();
}
public function testBulkUpdates()
{
Client::factory()->count(3)->create([
"company_id" => $this->company->id,
"user_id" => $this->user->id,
]);
$client_count = Client::query()->where('company_id', $this->company->id)->count();
$data = [
"column" => "public_notes",
"new_value" => "THISISABULKUPDATE",
"action" => "bulk_update",
"ids" => Client::where('company_id', $this->company->id)->get()->pluck("hashed_id")
];
$response = $this->withHeaders([
'X-API-TOKEN' => $this->token,
])->postJson("/api/v1/clients/bulk", $data);
$response->assertStatus(200);
$this->assertEquals($client_count, Client::query()->where('public_notes', "THISISABULKUPDATE")->where('company_id', $this->company->id)->count());
}
public function testCountryCodeValidation()
{