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