mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-09-20 00:11:35 +02:00
Working on import
This commit is contained in:
parent
636a2beada
commit
73a0192446
@ -109,8 +109,8 @@ class DashboardController extends BaseController
|
||||
->leftJoin('contacts', 'contacts.client_id', '=', 'clients.id')
|
||||
->leftJoin('invoices', 'invoices.id', '=', 'payments.invoice_id')
|
||||
->where('payments.account_id', '=', Auth::user()->account_id)
|
||||
->where('payments.deleted_at', '=', null)
|
||||
->where('invoices.deleted_at', '=', null)
|
||||
->where('payments.is_deleted', '=', false)
|
||||
->where('invoices.is_deleted', '=', false)
|
||||
->where('clients.deleted_at', '=', null)
|
||||
->where('contacts.deleted_at', '=', null)
|
||||
->where('contacts.is_primary', '=', true)
|
||||
|
@ -1,5 +1,6 @@
|
||||
<?php namespace app\Http\Controllers;
|
||||
|
||||
use Exception;
|
||||
use Input;
|
||||
use Session;
|
||||
use Redirect;
|
||||
@ -25,14 +26,11 @@ class ImportController extends BaseController
|
||||
}
|
||||
}
|
||||
$imported_files = $this->importService->import(Input::get('source'), $files);
|
||||
} catch (Exception $e) {
|
||||
Session::flash('error', $e->getMessage());
|
||||
|
||||
return Redirect::to('/settings/'.ACCOUNT_IMPORT_EXPORT);
|
||||
Session::flash('message', trans('texts.imported_file').' - '.$imported_files);
|
||||
} catch (Exception $exception) {
|
||||
Session::flash('error', $exception->getMessage());
|
||||
}
|
||||
|
||||
Session::flash('message', trans('texts.imported_file').' - '.$imported_files);
|
||||
|
||||
return Redirect::to('/settings/'.ACCOUNT_IMPORT_EXPORT);
|
||||
}
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ class CreateClientRequest extends Request
|
||||
|
||||
public function validator($factory)
|
||||
{
|
||||
// support submiting the form with a single client record
|
||||
// support submiting the form with a single contact record
|
||||
$input = $this->input();
|
||||
if (isset($input['contact'])) {
|
||||
$input['contacts'] = [$input['contact']];
|
||||
|
@ -27,7 +27,7 @@ class PaymentRepository extends BaseRepository
|
||||
->where('clients.deleted_at', '=', null)
|
||||
->where('contacts.is_primary', '=', true)
|
||||
->where('contacts.deleted_at', '=', null)
|
||||
->where('invoices.deleted_at', '=', null)
|
||||
->where('invoices.is_deleted', '=', false)
|
||||
->select('payments.public_id',
|
||||
'payments.transaction_reference',
|
||||
'clients.name as client_name',
|
||||
|
@ -3,11 +3,13 @@
|
||||
use Excel;
|
||||
use Cache;
|
||||
use Exception;
|
||||
use Auth;
|
||||
use League\Fractal\Manager;
|
||||
use App\Ninja\Repositories\ClientRepository;
|
||||
use App\Ninja\Repositories\InvoiceRepository;
|
||||
use App\Ninja\Repositories\PaymentRepository;
|
||||
use App\Ninja\Serializers\ArraySerializer;
|
||||
use App\Models\Client;
|
||||
|
||||
class ImportService
|
||||
{
|
||||
@ -33,9 +35,6 @@ class ImportService
|
||||
//IMPORT_ZOHO,
|
||||
];
|
||||
|
||||
/**
|
||||
* FreshBooksDataImporterService constructor.
|
||||
*/
|
||||
public function __construct(Manager $manager, ClientRepository $clientRepo, InvoiceRepository $invoiceRepo, PaymentRepository $paymentRepo)
|
||||
{
|
||||
$this->fractal = $manager;
|
||||
@ -61,7 +60,14 @@ class ImportService
|
||||
$transformer = new $transformerClassName;
|
||||
|
||||
Excel::load($file, function($reader) use ($source, $entityType, $transformer) {
|
||||
|
||||
|
||||
if ($entityType === ENTITY_CLIENT) {
|
||||
$totalClients = count($reader->all()) + Client::scope()->withTrashed()->count();
|
||||
if ($totalClients > Auth::user()->getMaxNumClients()) {
|
||||
throw new Exception(trans('texts.limit_clients', ['count' => Auth::user()->getMaxNumClients()]));
|
||||
}
|
||||
}
|
||||
|
||||
$maps = $this->createMaps();
|
||||
|
||||
$reader->each(function($row) use ($source, $entityType, $transformer, $maps) {
|
||||
@ -71,7 +77,7 @@ class ImportService
|
||||
|
||||
// if the invoice is paid we'll also create a payment record
|
||||
if ($entityType === ENTITY_INVOICE && isset($data['paid']) && $data['paid']) {
|
||||
$class = self::getTransformerClassName($source, 'payment');
|
||||
$class = self::getTransformerClassName($source, ENTITY_PAYMENT);
|
||||
$paymentTransformer = new $class;
|
||||
$row->client_id = $data['client_id'];
|
||||
$row->invoice_id = $entity->public_id;
|
||||
|
Loading…
Reference in New Issue
Block a user