1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-11 13:42:49 +01:00
invoiceninja/app/Import/Transformer/Invoicely/InvoiceTransformer.php

61 lines
1.7 KiB
PHP
Raw Normal View History

2022-02-17 02:12:51 +01:00
<?php
/**
2023-05-01 00:07:41 +02:00
* Invoice Ninja (https://invoiceninja.com).
2022-02-17 02:12:51 +01:00
*
2023-05-01 00:07:41 +02:00
* @link https://github.com/invoiceninja/invoiceninja source repository
2022-02-17 02:12:51 +01:00
*
2023-05-01 00:07:41 +02:00
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
2022-02-17 02:12:51 +01:00
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Import\Transformer\Invoicely;
use App\Import\ImportException;
use App\Import\Transformer\BaseTransformer;
use App\Models\Invoice;
/**
* Class InvoiceTransformer.
*/
class InvoiceTransformer extends BaseTransformer
{
/**
* @param $data
*
* @return bool|array
*/
public function transform($data)
{
if ($this->hasInvoice($data['Details'])) {
throw new ImportException('Invoice number already exists');
}
2022-02-17 02:12:51 +01:00
$transformed = [
'company_id' => $this->company->id,
'client_id' => $this->getClient($this->getString($data, 'Client'), null),
'number' => $this->getString($data, 'Details'),
'date' => isset($data['Date']) ? date('Y-m-d', strtotime($data['Date'])) : null,
'due_date' => isset($data['Due']) ? date('Y-m-d', strtotime($data['Due'])) : null,
'status_id' => Invoice::STATUS_SENT,
'line_items' => [
[
'cost' => $amount = $this->getFloat($data, 'Total'),
'quantity' => 1,
],
],
];
2022-02-17 02:12:51 +01:00
if (strtolower($data['Status']) === 'paid') {
$transformed['payments'] = [
[
'date' => date('Y-m-d'),
'amount' => $amount,
],
];
}
2022-02-17 02:12:51 +01:00
return $transformed;
}
2022-02-17 02:12:51 +01:00
}