mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Working on importing expenses
This commit is contained in:
parent
47137e60df
commit
7bd4026e4c
@ -31,6 +31,7 @@ class Expense extends EntityModel
|
||||
'client_id',
|
||||
'vendor_id',
|
||||
'expense_currency_id',
|
||||
'expense_date',
|
||||
'invoice_currency_id',
|
||||
'amount',
|
||||
'foreign_amount',
|
||||
@ -46,6 +47,29 @@ class Expense extends EntityModel
|
||||
'tax_name2',
|
||||
];
|
||||
|
||||
public static function getImportColumns()
|
||||
{
|
||||
return [
|
||||
'client',
|
||||
'vendor',
|
||||
'amount',
|
||||
'public_notes',
|
||||
'category',
|
||||
'expense_date',
|
||||
];
|
||||
}
|
||||
|
||||
public static function getImportMap()
|
||||
{
|
||||
return [
|
||||
'amount|total' => 'amount',
|
||||
'category' => 'category',
|
||||
'client' => 'client',
|
||||
'vendor' => 'vendor',
|
||||
'notes|details' => 'public_notes',
|
||||
'date' => 'expense_date',
|
||||
];
|
||||
}
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
|
49
app/Ninja/Import/CSV/ExpenseTransformer.php
Normal file
49
app/Ninja/Import/CSV/ExpenseTransformer.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php namespace App\Ninja\Import\CSV;
|
||||
|
||||
use App\Ninja\Import\BaseTransformer;
|
||||
use League\Fractal\Resource\Item;
|
||||
|
||||
/**
|
||||
* Class InvoiceTransformer
|
||||
*/
|
||||
class ExpenseTransformer extends BaseTransformer
|
||||
{
|
||||
/**
|
||||
* @param $data
|
||||
* @return bool|Item
|
||||
*/
|
||||
public function transform($data)
|
||||
{
|
||||
return new Item($data, function ($data) {
|
||||
return [
|
||||
'amount' => isset($data->amount) ? (float) $data->amount : null,
|
||||
'vendor_id' => isset($data->vendor) ? $this->getVendorId($data->vendor) : null,
|
||||
'expense_date' => isset($data->expense_date) ? date('Y-m-d', strtotime($data->expense_date)) : null,
|
||||
'public_notes' => $this->getString($data, 'public_notes'),
|
||||
];
|
||||
});
|
||||
|
||||
/*
|
||||
return new Item($data, function ($data) {
|
||||
return [
|
||||
'client_id' => $this->getClientId($data->name),
|
||||
'invoice_number' => isset($data->invoice_number) ? $this->getInvoiceNumber($data->invoice_number) : null,
|
||||
'paid' => isset($data->paid) ? (float) $data->paid : null,
|
||||
'po_number' => $this->getString($data, 'po_number'),
|
||||
'terms' => $this->getString($data, 'terms'),
|
||||
'public_notes' => $this->getString($data, 'public_notes'),
|
||||
'invoice_date_sql' => isset($data->invoice_date) ? $data->invoice_date : null,
|
||||
'invoice_items' => [
|
||||
[
|
||||
'product_key' => '',
|
||||
'notes' => $this->getString($data, 'notes'),
|
||||
'cost' => isset($data->amount) ? (float) $data->amount : null,
|
||||
'qty' => 1,
|
||||
]
|
||||
],
|
||||
];
|
||||
});
|
||||
*/
|
||||
|
||||
}
|
||||
}
|
@ -15,9 +15,12 @@ use App\Ninja\Repositories\ClientRepository;
|
||||
use App\Ninja\Repositories\InvoiceRepository;
|
||||
use App\Ninja\Repositories\PaymentRepository;
|
||||
use App\Ninja\Repositories\ProductRepository;
|
||||
use App\Ninja\Repositories\ExpenseRepository;
|
||||
use App\Ninja\Repositories\VendorRepository;
|
||||
use App\Ninja\Serializers\ArraySerializer;
|
||||
use App\Models\Client;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Expense;
|
||||
use App\Models\EntityModel;
|
||||
|
||||
/**
|
||||
@ -110,7 +113,9 @@ class ImportService
|
||||
InvoiceRepository $invoiceRepo,
|
||||
PaymentRepository $paymentRepo,
|
||||
ContactRepository $contactRepo,
|
||||
ProductRepository $productRepo
|
||||
ProductRepository $productRepo,
|
||||
ExpenseRepository $expenseRepo,
|
||||
VendorRepository $vendorRepo
|
||||
)
|
||||
{
|
||||
$this->fractal = $manager;
|
||||
@ -121,6 +126,8 @@ class ImportService
|
||||
$this->paymentRepo = $paymentRepo;
|
||||
$this->contactRepo = $contactRepo;
|
||||
$this->productRepo = $productRepo;
|
||||
$this->expenseRepo = $expenseRepo;
|
||||
$this->vendorRepo = $vendorRepo;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -462,12 +469,11 @@ class ImportService
|
||||
$title = strtolower($headers[$i]);
|
||||
$mapped[$i] = '';
|
||||
|
||||
if ($hasHeaders) {
|
||||
foreach ($map as $search => $column) {
|
||||
if ($this->checkForMatch($title, $search)) {
|
||||
$mapped[$i] = $column;
|
||||
break;
|
||||
}
|
||||
foreach ($map as $search => $column) {
|
||||
if ($this->checkForMatch($title, $search)) {
|
||||
$hasHeaders = true;
|
||||
$mapped[$i] = $column;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -668,6 +674,8 @@ class ImportService
|
||||
'currencies' => [],
|
||||
'client_ids' => [],
|
||||
'invoice_ids' => [],
|
||||
'vendors' => [],
|
||||
'expense_categories' => [],
|
||||
];
|
||||
|
||||
$clients = $this->clientRepo->all();
|
||||
@ -695,6 +703,11 @@ class ImportService
|
||||
foreach ($currencies as $currency) {
|
||||
$this->maps['currencies'][strtolower($currency->code)] = $currency->id;
|
||||
}
|
||||
|
||||
$vendors = $this->vendorRepo->all();
|
||||
foreach ($vendors as $vendor) {
|
||||
$this->maps['vendor'][strtolower($vendor->name)] = $vendor->id;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -729,4 +742,9 @@ class ImportService
|
||||
$this->maps['product'][$key] = $product->id;
|
||||
}
|
||||
}
|
||||
|
||||
private function addExpenseToMaps(Expense $expense)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
|
@ -2142,6 +2142,9 @@ $LANG = array(
|
||||
'enable_recurring' => 'Enable Recurring',
|
||||
'disable_recurring' => 'Disable Recurring',
|
||||
'text' => 'Text',
|
||||
'expense_will_create' => 'expense will be created',
|
||||
'expenses_will_create' => 'expenses will be created',
|
||||
'created_expenses' => 'Successfully created :count expense(s)',
|
||||
|
||||
);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user