Task imports

This commit is contained in:
David Bomba 2023-11-20 15:31:40 +11:00
parent aaa84c9c92
commit 4db163c4e1
7 changed files with 19 additions and 9 deletions

View File

@ -22,7 +22,10 @@ class ImportRequest extends Request
*/
public function authorize() : bool
{
return auth()->user()->isAdmin();
/** @var \App\Models\User $user */
$user = auth()->user();
return $user->isAdmin();
}
public function rules()

View File

@ -24,7 +24,7 @@ class TaskMap
4 => 'client.name',
5 => 'client.email',
6 => 'task.description',
7 => 'task.is_billable',
7 => 'task.billable',
8 => 'task.start_date',
9 => 'task.end_date',
10 => 'task.start_time',

View File

@ -162,11 +162,12 @@ class BaseImport
private function groupTasks($csvData, $key)
{
nlog($csvData[0]);
if (! $key || count(array_column($csvData, $key)) == 0) {
if (! $key || !is_array($csvData) || count($csvData) == 0 || !isset($csvData[0]['task.number']) || empty($csvData[0]['task.number'])) {
return $csvData;
}
// Group by tasks.
$grouped = [];
@ -495,7 +496,7 @@ class BaseImport
];
}
}
nlog($count);
return $count;
}

View File

@ -77,7 +77,7 @@ class BaseTransformer
}
public function getString($data, $field)
{
{
return isset($data[$field]) && $data[$field] ? trim($data[$field]) : '';
}
@ -179,6 +179,7 @@ class BaseTransformer
public function getClient($client_name, $client_email)
{
if (! empty($client_name)) {
$client_id_search = Client::query()->where('company_id', $this->company->id)
->where('is_deleted', false)

View File

@ -29,8 +29,11 @@ class TaskTransformer extends BaseTransformer
{
$this->stubbed_timestamp = time();
$task_data = reset($task_items_data);
if(count($task_items_data) == count($task_items_data, COUNT_RECURSIVE))
$task_data = $task_items_data;
else
$task_data = reset($task_items_data);
$clientId = $this->getClient(
$this->getString($task_data, 'client.name'),
$this->getString($task_data, 'client.email')

View File

@ -74,7 +74,7 @@ class CSVIngest implements ShouldQueue
$engine = $this->bootEngine();
foreach (['client', 'product', 'invoice', 'payment', 'vendor', 'expense', 'quote', 'bank_transaction', 'recurring_invoice'] as $entity) {
foreach (['client', 'product', 'invoice', 'payment', 'vendor', 'expense', 'quote', 'bank_transaction', 'recurring_invoice', 'task'] as $entity) {
$engine->import($entity);
}

View File

@ -83,6 +83,8 @@ class InstantPayment
->with(['message' => 'No payable invoices selected.']);
}
$invoices = Invoice::query()->whereIn('id', $this->transformKeys($payable_invoices->pluck('invoice_id')->toArray()))->withTrashed()->get();
$client = $invoices->first()->client;
$settings = $client->getMergedSettings();