1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-16 16:13:20 +01:00
invoiceninja/app/Import/Transformer/Csv/ExpenseTransformer.php

80 lines
3.3 KiB
PHP
Raw Normal View History

2022-02-03 08:53:39 +01:00
<?php
/**
2023-05-01 00:07:41 +02:00
* Invoice Ninja (https://invoiceninja.com).
2022-02-03 08:53:39 +01:00
*
2023-05-01 00:07:41 +02:00
* @link https://github.com/invoiceninja/invoiceninja source repository
2022-02-03 08:53:39 +01:00
*
2023-05-01 00:07:41 +02:00
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
2022-02-03 08:53:39 +01:00
*
* @license https://www.elastic.co/licensing/elastic-license
*/
2022-02-03 08:53:39 +01:00
namespace App\Import\Transformer\Csv;
use App\Import\Transformer\BaseTransformer;
/**
* Class InvoiceTransformer.
*/
class ExpenseTransformer extends BaseTransformer
{
/**
* @param $data
*
* @return bool|array
*/
public function transform($data)
{
$clientId = isset($data['expense.client'])
? $this->getClientId($data['expense.client'])
: null;
2022-02-03 08:53:39 +01:00
return [
'company_id' => $this->company->id,
2022-11-02 03:48:32 +01:00
'amount' => abs($this->getFloat($data, 'expense.amount')),
'currency_id' => $this->getCurrencyByCode(
$data,
'expense.currency_id'
),
'vendor_id' => isset($data['expense.vendor'])
? $this->getVendorId($data['expense.vendor'])
: null,
'client_id' => isset($data['expense.client'])
? $this->getClientId($data['expense.client'])
: null,
2023-02-16 02:36:09 +01:00
'date' => strlen($this->getString($data, 'expense.date') > 1) ? date('Y-m-d', strtotime(str_replace("/", "-", $data['expense.date']))) : now()->format('Y-m-d'),
'public_notes' => $this->getString($data, 'expense.public_notes'),
'private_notes' => $this->getString($data, 'expense.private_notes'),
'category_id' => isset($data['expense.category'])
? $this->getExpenseCategoryId($data['expense.category'])
: null,
'project_id' => isset($data['expense.project'])
? $this->getProjectId($data['expense.project'], $clientId)
: null,
'payment_type_id' => isset($data['expense.payment_type'])
? $this->getPaymentTypeId($data['expense.payment_type'])
: null,
'payment_date' => isset($data['expense.payment_date'])
2023-02-16 02:36:09 +01:00
? date('Y-m-d', strtotime(str_replace("/", "-", $data['expense.payment_date'])))
: null,
'custom_value1' => $this->getString($data, 'expense.custom_value1'),
'custom_value2' => $this->getString($data, 'expense.custom_value2'),
'custom_value3' => $this->getString($data, 'expense.custom_value3'),
'custom_value4' => $this->getString($data, 'expense.custom_value4'),
'transaction_reference' => $this->getString(
$data,
'expense.transaction_reference'
),
'should_be_invoiced' => $clientId ? true : false,
2022-10-06 05:28:57 +02:00
'uses_inclusive_taxes' => (bool) $this->getString($data, 'expense.uses_inclusive_taxes'),
'tax_name1' => $this->getString($data, 'expense.tax_name1'),
'tax_rate1' => $this->getFloat($data, 'expense.tax_rate1'),
'tax_name2' => $this->getString($data, 'expense.tax_name2'),
'tax_rate2' => $this->getFloat($data, 'expense.tax_rate2'),
'tax_name3' => $this->getString($data, 'expense.tax_name3'),
'tax_rate3' => $this->getFloat($data, 'expense.tax_rate3'),
];
}
2022-02-03 08:53:39 +01:00
}