mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-08 22:14:33 -04:00
commit
4222f28cd6
@ -14,6 +14,7 @@ namespace App\Http\Controllers;
|
|||||||
use App\Http\Requests\Import\ImportRequest;
|
use App\Http\Requests\Import\ImportRequest;
|
||||||
use App\Http\Requests\Import\PreImportRequest;
|
use App\Http\Requests\Import\PreImportRequest;
|
||||||
use App\Jobs\Import\CSVImport;
|
use App\Jobs\Import\CSVImport;
|
||||||
|
use App\Jobs\Import\CSVIngest;
|
||||||
use Illuminate\Http\UploadedFile;
|
use Illuminate\Http\UploadedFile;
|
||||||
use Illuminate\Support\Facades\Cache;
|
use Illuminate\Support\Facades\Cache;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
@ -116,7 +117,9 @@ class ImportController extends Controller {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CSVImport::dispatch( $data, auth()->user()->company() );
|
unset($data['files']);
|
||||||
|
// CSVImport::dispatch( $data, auth()->user()->company() );
|
||||||
|
CSVIngest::dispatch( $data, auth()->user()->company() );
|
||||||
|
|
||||||
return response()->json( [ 'message' => ctrans( 'texts.import_started' ) ], 200 );
|
return response()->json( [ 'message' => ctrans( 'texts.import_started' ) ], 200 );
|
||||||
}
|
}
|
||||||
|
@ -29,12 +29,14 @@ class CheckClientExistence
|
|||||||
public function handle(Request $request, Closure $next)
|
public function handle(Request $request, Closure $next)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
if(session()->has('multiple_contacts'))
|
||||||
|
return $next($request);
|
||||||
|
|
||||||
$multiple_contacts = ClientContact::query()
|
$multiple_contacts = ClientContact::query()
|
||||||
->with('client.gateway_tokens','company')
|
->with('client.gateway_tokens','company')
|
||||||
->where('email', auth()->guard('contact')->user()->email)
|
->where('email', auth()->guard('contact')->user()->email)
|
||||||
->whereNotNull('email')
|
->whereNotNull('email')
|
||||||
->where('email', '<>', '')
|
->where('email', '<>', '')
|
||||||
// ->whereNull('deleted_at')
|
|
||||||
->distinct('company_id')
|
->distinct('company_id')
|
||||||
->distinct('email')
|
->distinct('email')
|
||||||
->whereNotNull('company_id')
|
->whereNotNull('company_id')
|
||||||
|
@ -80,6 +80,8 @@ class BaseImport
|
|||||||
|
|
||||||
public function getCsvData($entity_type)
|
public function getCsvData($entity_type)
|
||||||
{
|
{
|
||||||
|
nlog("get csv data = entity name = " . $entity_type);
|
||||||
|
|
||||||
$base64_encoded_csv = Cache::pull($this->hash . '-' . $entity_type);
|
$base64_encoded_csv = Cache::pull($this->hash . '-' . $entity_type);
|
||||||
if (empty($base64_encoded_csv)) {
|
if (empty($base64_encoded_csv)) {
|
||||||
return null;
|
return null;
|
||||||
@ -123,6 +125,9 @@ class BaseImport
|
|||||||
|
|
||||||
private function groupInvoices($csvData, $key)
|
private function groupInvoices($csvData, $key)
|
||||||
{
|
{
|
||||||
|
if(!$key)
|
||||||
|
return $csvData;
|
||||||
|
|
||||||
// Group by invoice.
|
// Group by invoice.
|
||||||
$grouped = [];
|
$grouped = [];
|
||||||
|
|
||||||
@ -154,12 +159,7 @@ class BaseImport
|
|||||||
try {
|
try {
|
||||||
|
|
||||||
$entity = $this->transformer->transform($record);
|
$entity = $this->transformer->transform($record);
|
||||||
/** @var \App\Http\Requests\Request $request */
|
$validator = $this->request_name::runFormRequest($entity);
|
||||||
$request = new $this->request_name();
|
|
||||||
|
|
||||||
// Pass entity data to request so it can be validated
|
|
||||||
$request->query = $request->request = new ParameterBag($entity);
|
|
||||||
$validator = Validator::make($entity, $request->rules());
|
|
||||||
|
|
||||||
if ($validator->fails()) {
|
if ($validator->fails()) {
|
||||||
$this->error_array[$entity_type][] = [
|
$this->error_array[$entity_type][] = [
|
||||||
@ -220,8 +220,9 @@ class BaseImport
|
|||||||
foreach ($invoices as $raw_invoice) {
|
foreach ($invoices as $raw_invoice) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
$invoice_data = $invoice_transformer->transform($raw_invoice);
|
$invoice_data = $invoice_transformer->transform($raw_invoice);
|
||||||
nlog($invoice_data);
|
|
||||||
$invoice_data['line_items'] = $this->cleanItems(
|
$invoice_data['line_items'] = $this->cleanItems(
|
||||||
$invoice_data['line_items'] ?? []
|
$invoice_data['line_items'] ?? []
|
||||||
);
|
);
|
||||||
@ -247,10 +248,8 @@ class BaseImport
|
|||||||
unset($invoice_data['client']);
|
unset($invoice_data['client']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$validator = Validator::make(
|
$validator = $this->request_name::runFormRequest($invoice_data);
|
||||||
$invoice_data,
|
|
||||||
(new StoreInvoiceRequest())->rules()
|
|
||||||
);
|
|
||||||
if ($validator->fails()) {
|
if ($validator->fails()) {
|
||||||
$this->error_array['invoice'][] = [
|
$this->error_array['invoice'][] = [
|
||||||
'invoice' => $invoice_data,
|
'invoice' => $invoice_data,
|
||||||
@ -519,22 +518,41 @@ class BaseImport
|
|||||||
|
|
||||||
public function preTransform(array $data, $entity_type)
|
public function preTransform(array $data, $entity_type)
|
||||||
{
|
{
|
||||||
if (empty($this->column_map[$entity_type])) {
|
//sort the array by key
|
||||||
|
// $keys = $this->column_map[$entity_type];
|
||||||
|
|
||||||
|
$keys = array_shift( $data );
|
||||||
|
ksort($keys);
|
||||||
|
|
||||||
|
return array_map( function ( $values ) use ( $keys ) {
|
||||||
|
return array_combine( $keys, $values );
|
||||||
|
}, $data );
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function preTransformCsv(array $data, $entity_type)
|
||||||
|
{
|
||||||
|
|
||||||
|
if ( empty( $this->column_map[ $entity_type ] ) ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->skip_header) {
|
if ( $this->skip_header ) {
|
||||||
array_shift($data);
|
array_shift( $data );
|
||||||
}
|
}
|
||||||
|
|
||||||
//sort the array by key
|
//sort the array by key
|
||||||
$keys = $this->column_map[$entity_type];
|
$keys = $this->column_map[ $entity_type ];
|
||||||
ksort($keys);
|
ksort( $keys );
|
||||||
|
|
||||||
|
$data = array_map( function ( $row ) use ( $keys ) {
|
||||||
|
return array_combine( $keys, array_intersect_key( $row, $keys ) );
|
||||||
|
}, $data );
|
||||||
|
|
||||||
$data = array_map(function ($row) use ($keys) {
|
|
||||||
return array_combine($keys, array_intersect_key($row, $keys));
|
|
||||||
}, $data);
|
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -71,7 +71,8 @@ class Csv extends BaseImport implements ImportInterface
|
|||||||
|
|
||||||
$data = $this->getCsvData($entity_type);
|
$data = $this->getCsvData($entity_type);
|
||||||
|
|
||||||
$data = $this->preTransform($data, $entity_type);
|
if(is_array($data))
|
||||||
|
$data = $this->preTransformCsv($data, $entity_type);
|
||||||
|
|
||||||
if (empty($data)) {
|
if (empty($data)) {
|
||||||
$this->entity_count['clients'] = 0;
|
$this->entity_count['clients'] = 0;
|
||||||
@ -98,7 +99,8 @@ class Csv extends BaseImport implements ImportInterface
|
|||||||
|
|
||||||
$data = $this->getCsvData($entity_type);
|
$data = $this->getCsvData($entity_type);
|
||||||
|
|
||||||
$data = $this->preTransform($data, $entity_type);
|
if(is_array($data))
|
||||||
|
$data = $this->preTransformCsv($data, $entity_type);
|
||||||
|
|
||||||
if (empty($data)) {
|
if (empty($data)) {
|
||||||
$this->entity_count['products'] = 0;
|
$this->entity_count['products'] = 0;
|
||||||
@ -125,7 +127,8 @@ class Csv extends BaseImport implements ImportInterface
|
|||||||
|
|
||||||
$data = $this->getCsvData($entity_type);
|
$data = $this->getCsvData($entity_type);
|
||||||
|
|
||||||
$data = $this->preTransform($data, $entity_type);
|
if(is_array($data))
|
||||||
|
$data = $this->preTransformCsv($data, $entity_type);
|
||||||
|
|
||||||
if (empty($data)) {
|
if (empty($data)) {
|
||||||
$this->entity_count['invoices'] = 0;
|
$this->entity_count['invoices'] = 0;
|
||||||
@ -152,7 +155,8 @@ class Csv extends BaseImport implements ImportInterface
|
|||||||
|
|
||||||
$data = $this->getCsvData($entity_type);
|
$data = $this->getCsvData($entity_type);
|
||||||
|
|
||||||
$data = $this->preTransform($data, $entity_type);
|
if(is_array($data))
|
||||||
|
$data = $this->preTransformCsv($data, $entity_type);
|
||||||
|
|
||||||
if (empty($data)) {
|
if (empty($data)) {
|
||||||
$this->entity_count['payments'] = 0;
|
$this->entity_count['payments'] = 0;
|
||||||
@ -179,7 +183,8 @@ class Csv extends BaseImport implements ImportInterface
|
|||||||
|
|
||||||
$data = $this->getCsvData($entity_type);
|
$data = $this->getCsvData($entity_type);
|
||||||
|
|
||||||
$data = $this->preTransform($data, $entity_type);
|
if(is_array($data))
|
||||||
|
$data = $this->preTransformCsv($data, $entity_type);
|
||||||
|
|
||||||
if (empty($data)) {
|
if (empty($data)) {
|
||||||
$this->entity_count['vendors'] = 0;
|
$this->entity_count['vendors'] = 0;
|
||||||
@ -206,7 +211,8 @@ class Csv extends BaseImport implements ImportInterface
|
|||||||
|
|
||||||
$data = $this->getCsvData($entity_type);
|
$data = $this->getCsvData($entity_type);
|
||||||
|
|
||||||
$data = $this->preTransform($data, $entity_type);
|
if(is_array($data))
|
||||||
|
$data = $this->preTransformCsv($data, $entity_type);
|
||||||
|
|
||||||
if (empty($data)) {
|
if (empty($data)) {
|
||||||
$this->entity_count['expenses'] = 0;
|
$this->entity_count['expenses'] = 0;
|
||||||
|
@ -10,6 +10,104 @@
|
|||||||
*/
|
*/
|
||||||
namespace App\Import\Providers;
|
namespace App\Import\Providers;
|
||||||
|
|
||||||
|
use App\Factory\ClientFactory;
|
||||||
|
use App\Factory\InvoiceFactory;
|
||||||
|
use App\Http\Requests\Client\StoreClientRequest;
|
||||||
|
use App\Http\Requests\Invoice\StoreInvoiceRequest;
|
||||||
|
use App\Import\Transformer\Freshbooks\ClientTransformer;
|
||||||
|
use App\Import\Transformer\Freshbooks\InvoiceTransformer;
|
||||||
|
use App\Repositories\ClientRepository;
|
||||||
|
use App\Repositories\InvoiceRepository;
|
||||||
|
|
||||||
class Freshbooks extends BaseImport
|
class Freshbooks extends BaseImport
|
||||||
{
|
{
|
||||||
|
|
||||||
|
public array $entity_count = [];
|
||||||
|
|
||||||
|
public function import(string $entity)
|
||||||
|
{
|
||||||
|
if (
|
||||||
|
in_array($entity, [
|
||||||
|
'client',
|
||||||
|
'invoice',
|
||||||
|
// 'product',
|
||||||
|
// 'payment',
|
||||||
|
// 'vendor',
|
||||||
|
// 'expense',
|
||||||
|
])
|
||||||
|
) {
|
||||||
|
$this->{$entity}();
|
||||||
|
}
|
||||||
|
|
||||||
|
//collate any errors
|
||||||
|
|
||||||
|
$this->finalizeImport();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function client()
|
||||||
|
{
|
||||||
|
$entity_type = 'client';
|
||||||
|
|
||||||
|
$data = $this->getCsvData($entity_type);
|
||||||
|
$data = $this->preTransform($data, $entity_type);
|
||||||
|
|
||||||
|
if (empty($data)) {
|
||||||
|
$this->entity_count['clients'] = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->request_name = StoreClientRequest::class;
|
||||||
|
$this->repository_name = ClientRepository::class;
|
||||||
|
$this->factory_name = ClientFactory::class;
|
||||||
|
|
||||||
|
$this->repository = app()->make($this->repository_name);
|
||||||
|
$this->repository->import_mode = true;
|
||||||
|
|
||||||
|
$this->transformer = new ClientTransformer($this->company);
|
||||||
|
|
||||||
|
$client_count = $this->ingest($data, $entity_type);
|
||||||
|
|
||||||
|
$this->entity_count['clients'] = $client_count;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function invoice() {
|
||||||
|
|
||||||
|
//make sure we update and create products with wave
|
||||||
|
$initial_update_products_value = $this->company->update_products;
|
||||||
|
$this->company->update_products = true;
|
||||||
|
|
||||||
|
$this->company->save();
|
||||||
|
|
||||||
|
$entity_type = 'invoice';
|
||||||
|
|
||||||
|
$data = $this->getCsvData($entity_type);
|
||||||
|
|
||||||
|
$data = $this->preTransform($data, $entity_type);
|
||||||
|
|
||||||
|
if (empty($data)) {
|
||||||
|
$this->entity_count['invoices'] = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->request_name = StoreInvoiceRequest::class;
|
||||||
|
$this->repository_name = InvoiceRepository::class;
|
||||||
|
$this->factory_name = InvoiceFactory::class;
|
||||||
|
|
||||||
|
$this->repository = app()->make($this->repository_name);
|
||||||
|
$this->repository->import_mode = true;
|
||||||
|
|
||||||
|
$this->transformer = new InvoiceTransformer($this->company);
|
||||||
|
|
||||||
|
$invoice_count = $this->ingestInvoices($data, 'Invoice #');
|
||||||
|
|
||||||
|
$this->entity_count['invoices'] = $invoice_count;
|
||||||
|
|
||||||
|
$this->company->update_products = $initial_update_products_value;
|
||||||
|
$this->company->save();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,75 @@
|
|||||||
*/
|
*/
|
||||||
namespace App\Import\Providers;
|
namespace App\Import\Providers;
|
||||||
|
|
||||||
|
use App\Factory\ClientFactory;
|
||||||
|
use App\Factory\InvoiceFactory;
|
||||||
|
use App\Http\Requests\Client\StoreClientRequest;
|
||||||
|
use App\Http\Requests\Invoice\StoreInvoiceRequest;
|
||||||
|
use App\Import\Transformer\Invoice2Go\InvoiceTransformer;
|
||||||
|
use App\Repositories\ClientRepository;
|
||||||
|
use App\Repositories\InvoiceRepository;
|
||||||
|
|
||||||
class Invoice2Go extends BaseImport
|
class Invoice2Go extends BaseImport
|
||||||
{
|
{
|
||||||
|
public array $entity_count = [];
|
||||||
|
|
||||||
|
public function import(string $entity)
|
||||||
|
{
|
||||||
|
if (
|
||||||
|
in_array($entity, [
|
||||||
|
//'client',
|
||||||
|
'invoice',
|
||||||
|
// 'product',
|
||||||
|
// 'payment',
|
||||||
|
// 'vendor',
|
||||||
|
// 'expense',
|
||||||
|
])
|
||||||
|
) {
|
||||||
|
$this->{$entity}();
|
||||||
|
}
|
||||||
|
|
||||||
|
//collate any errors
|
||||||
|
|
||||||
|
$this->finalizeImport();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function invoice() {
|
||||||
|
|
||||||
|
//make sure we update and create products with wave
|
||||||
|
$initial_update_products_value = $this->company->update_products;
|
||||||
|
$this->company->update_products = true;
|
||||||
|
|
||||||
|
$this->company->save();
|
||||||
|
|
||||||
|
$entity_type = 'invoice';
|
||||||
|
|
||||||
|
$data = $this->getCsvData($entity_type);
|
||||||
|
|
||||||
|
$data = $this->preTransform($data, 'invoice');
|
||||||
|
|
||||||
|
if (empty($data)) {
|
||||||
|
$this->entity_count['invoices'] = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->request_name = StoreInvoiceRequest::class;
|
||||||
|
$this->repository_name = InvoiceRepository::class;
|
||||||
|
$this->factory_name = InvoiceFactory::class;
|
||||||
|
|
||||||
|
$this->repository = app()->make($this->repository_name);
|
||||||
|
$this->repository->import_mode = true;
|
||||||
|
|
||||||
|
$this->transformer = new InvoiceTransformer($this->company);
|
||||||
|
|
||||||
|
$invoice_count = $this->ingestInvoices($data, false);
|
||||||
|
|
||||||
|
$this->entity_count['invoices'] = $invoice_count;
|
||||||
|
|
||||||
|
$this->company->update_products = $initial_update_products_value;
|
||||||
|
$this->company->save();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -10,7 +10,101 @@
|
|||||||
*/
|
*/
|
||||||
namespace App\Import\Providers;
|
namespace App\Import\Providers;
|
||||||
|
|
||||||
|
use App\Factory\ClientFactory;
|
||||||
|
use App\Factory\InvoiceFactory;
|
||||||
|
use App\Http\Requests\Client\StoreClientRequest;
|
||||||
|
use App\Http\Requests\Invoice\StoreInvoiceRequest;
|
||||||
|
use App\Import\Transformer\Invoicely\ClientTransformer;
|
||||||
|
use App\Import\Transformer\Invoicely\InvoiceTransformer;
|
||||||
|
use App\Repositories\ClientRepository;
|
||||||
|
use App\Repositories\InvoiceRepository;
|
||||||
|
|
||||||
class Invoicely extends BaseImport
|
class Invoicely extends BaseImport
|
||||||
{
|
{
|
||||||
|
public function import(string $entity)
|
||||||
|
{
|
||||||
|
if (
|
||||||
|
in_array($entity, [
|
||||||
|
'client',
|
||||||
|
'invoice',
|
||||||
|
// 'product',
|
||||||
|
// 'payment',
|
||||||
|
// 'vendor',
|
||||||
|
// 'expense',
|
||||||
|
])
|
||||||
|
) {
|
||||||
|
$this->{$entity}();
|
||||||
|
}
|
||||||
|
|
||||||
|
//collate any errors
|
||||||
|
|
||||||
|
$this->finalizeImport();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function client()
|
||||||
|
{
|
||||||
|
$entity_type = 'client';
|
||||||
|
|
||||||
|
$data = $this->getCsvData($entity_type);
|
||||||
|
|
||||||
|
$data = $this->preTransform($data, $entity_type);
|
||||||
|
|
||||||
|
if (empty($data)) {
|
||||||
|
$this->entity_count['clients'] = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->request_name = StoreClientRequest::class;
|
||||||
|
$this->repository_name = ClientRepository::class;
|
||||||
|
$this->factory_name = ClientFactory::class;
|
||||||
|
|
||||||
|
$this->repository = app()->make($this->repository_name);
|
||||||
|
$this->repository->import_mode = true;
|
||||||
|
|
||||||
|
$this->transformer = new ClientTransformer($this->company);
|
||||||
|
|
||||||
|
$client_count = $this->ingest($data, $entity_type);
|
||||||
|
|
||||||
|
$this->entity_count['clients'] = $client_count;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function invoice() {
|
||||||
|
|
||||||
|
//make sure we update and create products with wave
|
||||||
|
$initial_update_products_value = $this->company->update_products;
|
||||||
|
$this->company->update_products = true;
|
||||||
|
|
||||||
|
$this->company->save();
|
||||||
|
|
||||||
|
$entity_type = 'invoice';
|
||||||
|
|
||||||
|
$data = $this->getCsvData($entity_type);
|
||||||
|
|
||||||
|
$data = $this->preTransform($data, $entity_type);
|
||||||
|
|
||||||
|
if (empty($data)) {
|
||||||
|
$this->entity_count['invoices'] = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->request_name = StoreInvoiceRequest::class;
|
||||||
|
$this->repository_name = InvoiceRepository::class;
|
||||||
|
$this->factory_name = InvoiceFactory::class;
|
||||||
|
|
||||||
|
$this->repository = app()->make($this->repository_name);
|
||||||
|
$this->repository->import_mode = true;
|
||||||
|
|
||||||
|
$this->transformer = new InvoiceTransformer($this->company);
|
||||||
|
|
||||||
|
$invoice_count = $this->ingestInvoices($data, false);
|
||||||
|
|
||||||
|
$this->entity_count['invoices'] = $invoice_count;
|
||||||
|
|
||||||
|
$this->company->update_products = $initial_update_products_value;
|
||||||
|
$this->company->save();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -218,8 +218,6 @@ class Wave extends BaseImport implements ImportInterface
|
|||||||
|
|
||||||
$expenses = $this->groupExpenses($data);
|
$expenses = $this->groupExpenses($data);
|
||||||
|
|
||||||
// nlog($expenses);
|
|
||||||
// exit;
|
|
||||||
foreach ($expenses as $raw_expense) {
|
foreach ($expenses as $raw_expense) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -10,7 +10,103 @@
|
|||||||
*/
|
*/
|
||||||
namespace App\Import\Providers;
|
namespace App\Import\Providers;
|
||||||
|
|
||||||
|
use App\Factory\ClientFactory;
|
||||||
|
use App\Factory\InvoiceFactory;
|
||||||
|
use App\Http\Requests\Client\StoreClientRequest;
|
||||||
|
use App\Http\Requests\Invoice\StoreInvoiceRequest;
|
||||||
|
use App\Import\Transformer\Zoho\ClientTransformer;
|
||||||
|
use App\Import\Transformer\Zoho\InvoiceTransformer;
|
||||||
|
use App\Repositories\ClientRepository;
|
||||||
|
use App\Repositories\InvoiceRepository;
|
||||||
|
|
||||||
class Zoho extends BaseImport
|
class Zoho extends BaseImport
|
||||||
{
|
{
|
||||||
|
public array $entity_count = [];
|
||||||
|
|
||||||
|
public function import(string $entity)
|
||||||
|
{
|
||||||
|
if (
|
||||||
|
in_array($entity, [
|
||||||
|
'client',
|
||||||
|
'invoice',
|
||||||
|
// 'product',
|
||||||
|
// 'payment',
|
||||||
|
// 'vendor',
|
||||||
|
// 'expense',
|
||||||
|
])
|
||||||
|
) {
|
||||||
|
$this->{$entity}();
|
||||||
|
}
|
||||||
|
|
||||||
|
//collate any errors
|
||||||
|
|
||||||
|
$this->finalizeImport();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function client()
|
||||||
|
{
|
||||||
|
$entity_type = 'client';
|
||||||
|
|
||||||
|
$data = $this->getCsvData($entity_type);
|
||||||
|
|
||||||
|
$data = $this->preTransform($data, $entity_type);
|
||||||
|
|
||||||
|
if (empty($data)) {
|
||||||
|
$this->entity_count['clients'] = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->request_name = StoreClientRequest::class;
|
||||||
|
$this->repository_name = ClientRepository::class;
|
||||||
|
$this->factory_name = ClientFactory::class;
|
||||||
|
|
||||||
|
$this->repository = app()->make($this->repository_name);
|
||||||
|
$this->repository->import_mode = true;
|
||||||
|
|
||||||
|
$this->transformer = new ClientTransformer($this->company);
|
||||||
|
|
||||||
|
$client_count = $this->ingest($data, $entity_type);
|
||||||
|
|
||||||
|
$this->entity_count['clients'] = $client_count;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function invoice() {
|
||||||
|
|
||||||
|
//make sure we update and create products with wave
|
||||||
|
$initial_update_products_value = $this->company->update_products;
|
||||||
|
$this->company->update_products = true;
|
||||||
|
|
||||||
|
$this->company->save();
|
||||||
|
|
||||||
|
$entity_type = 'invoice';
|
||||||
|
|
||||||
|
$data = $this->getCsvData($entity_type);
|
||||||
|
|
||||||
|
$data = $this->preTransform($data, $entity_type);
|
||||||
|
|
||||||
|
if (empty($data)) {
|
||||||
|
$this->entity_count['invoices'] = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->request_name = StoreInvoiceRequest::class;
|
||||||
|
$this->repository_name = InvoiceRepository::class;
|
||||||
|
$this->factory_name = InvoiceFactory::class;
|
||||||
|
|
||||||
|
$this->repository = app()->make($this->repository_name);
|
||||||
|
$this->repository->import_mode = true;
|
||||||
|
|
||||||
|
$this->transformer = new InvoiceTransformer($this->company);
|
||||||
|
|
||||||
|
$invoice_count = $this->ingestInvoices($data, 'Invoice Number');
|
||||||
|
|
||||||
|
$this->entity_count['invoices'] = $invoice_count;
|
||||||
|
|
||||||
|
$this->company->update_products = $initial_update_products_value;
|
||||||
|
$this->company->save();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -65,7 +65,9 @@ class BaseTransformer
|
|||||||
|
|
||||||
public function getClient($client_name, $client_email)
|
public function getClient($client_name, $client_email)
|
||||||
{
|
{
|
||||||
// nlog("searching for {$client_name} with email {$client_email}");
|
|
||||||
|
if(!empty($client_name))
|
||||||
|
{
|
||||||
|
|
||||||
$client_id_search = $this->company
|
$client_id_search = $this->company
|
||||||
->clients()
|
->clients()
|
||||||
@ -84,7 +86,7 @@ class BaseTransformer
|
|||||||
// nlog("found via name {$client_name_search->first()->id}");
|
// nlog("found via name {$client_name_search->first()->id}");
|
||||||
return $client_name_search->first()->id;
|
return $client_name_search->first()->id;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (!empty($client_email)) {
|
if (!empty($client_email)) {
|
||||||
$contacts = ClientContact::where(
|
$contacts = ClientContact::where(
|
||||||
'company_id',
|
'company_id',
|
||||||
|
55
app/Import/Transformer/Freshbooks/ClientTransformer.php
Normal file
55
app/Import/Transformer/Freshbooks/ClientTransformer.php
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Invoice Ninja (https://clientninja.com).
|
||||||
|
*
|
||||||
|
* @link https://github.com/clientninja/clientninja source repository
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2021. client Ninja LLC (https://clientninja.com)
|
||||||
|
*
|
||||||
|
* @license https://www.elastic.co/licensing/elastic-license
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Import\Transformer\Freshbooks;
|
||||||
|
|
||||||
|
use App\Import\ImportException;
|
||||||
|
use App\Import\Transformer\BaseTransformer;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class ClientTransformer.
|
||||||
|
*/
|
||||||
|
class ClientTransformer extends BaseTransformer {
|
||||||
|
/**
|
||||||
|
* @param $data
|
||||||
|
*
|
||||||
|
* @return array|bool
|
||||||
|
*/
|
||||||
|
public function transform( $data ) {
|
||||||
|
if ( isset( $data['Organization'] ) && $this->hasClient( $data['Organization'] ) ) {
|
||||||
|
throw new ImportException('Client already exists');
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'company_id' => $this->company->id,
|
||||||
|
'name' => $this->getString( $data, 'Organization' ),
|
||||||
|
'phone' => $this->getString( $data, 'Phone' ),
|
||||||
|
'address1' => $this->getString( $data, 'Street' ),
|
||||||
|
'city' => $this->getString( $data, 'City' ),
|
||||||
|
'state' => $this->getString( $data, 'Province/State' ),
|
||||||
|
'postal_code' => $this->getString( $data, 'Postal Code' ),
|
||||||
|
'country_id' => isset( $data['Country'] ) ? $this->getCountryId( $data['Country'] ) : null,
|
||||||
|
'private_notes' => $this->getString( $data, 'Notes' ),
|
||||||
|
'credit_balance' => 0,
|
||||||
|
'settings' => new \stdClass,
|
||||||
|
'client_hash' => Str::random( 40 ),
|
||||||
|
'contacts' => [
|
||||||
|
[
|
||||||
|
'first_name' => $this->getString( $data, 'First Name' ),
|
||||||
|
'last_name' => $this->getString( $data, 'Last Name' ),
|
||||||
|
'email' => $this->getString( $data, 'Email' ),
|
||||||
|
'phone' => $this->getString( $data, 'Phone' ),
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
86
app/Import/Transformer/Freshbooks/InvoiceTransformer.php
Normal file
86
app/Import/Transformer/Freshbooks/InvoiceTransformer.php
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* client Ninja (https://clientninja.com).
|
||||||
|
*
|
||||||
|
* @link https://github.com/clientninja/clientninja source repository
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2021. client Ninja LLC (https://clientninja.com)
|
||||||
|
*
|
||||||
|
* @license https://www.elastic.co/licensing/elastic-license
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Import\Transformer\Freshbooks;
|
||||||
|
|
||||||
|
use App\Import\ImportException;
|
||||||
|
use App\Import\Transformer\BaseTransformer;
|
||||||
|
use App\Models\Invoice;
|
||||||
|
use App\Utils\Number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class InvoiceTransformer.
|
||||||
|
*/
|
||||||
|
class InvoiceTransformer extends BaseTransformer {
|
||||||
|
/**
|
||||||
|
* @param $line_items_data
|
||||||
|
*
|
||||||
|
* @return bool|array
|
||||||
|
*/
|
||||||
|
public function transform( $line_items_data ) {
|
||||||
|
$invoice_data = reset( $line_items_data );
|
||||||
|
|
||||||
|
if ( $this->hasInvoice( $invoice_data['Invoice #'] ) ) {
|
||||||
|
throw new ImportException( 'Invoice number already exists' );
|
||||||
|
}
|
||||||
|
|
||||||
|
$invoiceStatusMap = [
|
||||||
|
'sent' => Invoice::STATUS_SENT,
|
||||||
|
'draft' => Invoice::STATUS_DRAFT,
|
||||||
|
];
|
||||||
|
|
||||||
|
$transformed = [
|
||||||
|
'company_id' => $this->company->id,
|
||||||
|
'client_id' => $this->getClient( $this->getString( $invoice_data, 'Client Name' ), null ),
|
||||||
|
'number' => $this->getString( $invoice_data, 'Invoice #' ),
|
||||||
|
'date' => isset( $invoice_data['Date Issued'] ) ? date( 'Y-m-d', strtotime( $invoice_data['Date Issued'] ) ) : null,
|
||||||
|
// 'currency_id' => $this->getCurrencyByCode( $invoice_data, 'Currency' ),
|
||||||
|
'amount' => 0,
|
||||||
|
'status_id' => $invoiceStatusMap[ $status =
|
||||||
|
strtolower( $this->getString( $invoice_data, 'Invoice Status' ) ) ] ?? Invoice::STATUS_SENT,
|
||||||
|
// 'viewed' => $status === 'viewed',
|
||||||
|
];
|
||||||
|
|
||||||
|
$line_items = [];
|
||||||
|
foreach ( $line_items_data as $record ) {
|
||||||
|
$line_items[] = [
|
||||||
|
'product_key' => $this->getString( $record, 'Item Name' ),
|
||||||
|
'notes' => $this->getString( $record, 'Item Description' ),
|
||||||
|
'cost' => $this->getFreshbookQuantityFloat( $record, 'Rate' ),
|
||||||
|
'quantity' => $this->getFreshbookQuantityFloat( $record, 'Quantity' ),
|
||||||
|
'discount' => $this->getFreshbookQuantityFloat( $record, 'Discount Percentage' ),
|
||||||
|
'is_amount_discount' => false,
|
||||||
|
'tax_name1' => $this->getString( $record, 'Tax 1 Type' ),
|
||||||
|
'tax_rate1' => $this->getFreshbookQuantityFloat( $record, 'Tax 1 Amount' ),
|
||||||
|
'tax_name2' => $this->getString( $record, 'Tax 2 Type' ),
|
||||||
|
'tax_rate2' => $this->getFreshbookQuantityFloat( $record, 'Tax 2 Amount' ),
|
||||||
|
];
|
||||||
|
$transformed['amount'] += $this->getFreshbookQuantityFloat( $record, 'Line Total' );
|
||||||
|
}
|
||||||
|
$transformed['line_items'] = $line_items;
|
||||||
|
|
||||||
|
if ( ! empty( $invoice_data['Date Paid'] ) ) {
|
||||||
|
$transformed['payments'] = [[
|
||||||
|
'date' => date( 'Y-m-d', strtotime( $invoice_data['Date Paid'] ) ),
|
||||||
|
'amount' => $transformed['amount'],
|
||||||
|
]];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $transformed;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return float */
|
||||||
|
public function getFreshbookQuantityFloat($data, $field)
|
||||||
|
{
|
||||||
|
return $data[$field];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
94
app/Import/Transformer/Invoice2Go/InvoiceTransformer.php
Normal file
94
app/Import/Transformer/Invoice2Go/InvoiceTransformer.php
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* client Ninja (https://clientninja.com).
|
||||||
|
*
|
||||||
|
* @link https://github.com/clientninja/clientninja source repository
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2021. client Ninja LLC (https://clientninja.com)
|
||||||
|
*
|
||||||
|
* @license https://www.elastic.co/licensing/elastic-license
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Import\Transformer\Invoice2Go;
|
||||||
|
|
||||||
|
use App\Import\ImportException;
|
||||||
|
use App\Import\Transformer\BaseTransformer;
|
||||||
|
use App\Models\Invoice;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class InvoiceTransformer.
|
||||||
|
*/
|
||||||
|
class InvoiceTransformer extends BaseTransformer {
|
||||||
|
/**
|
||||||
|
* @param $line_items_data
|
||||||
|
*
|
||||||
|
* @return bool|array
|
||||||
|
*/
|
||||||
|
public function transform( $invoice_data ) {
|
||||||
|
|
||||||
|
if ( $this->hasInvoice( $invoice_data['DocumentNumber'] ) ) {
|
||||||
|
throw new ImportException( 'Invoice number already exists' );
|
||||||
|
}
|
||||||
|
|
||||||
|
$invoiceStatusMap = [
|
||||||
|
'unsent' => Invoice::STATUS_DRAFT,
|
||||||
|
'sent' => Invoice::STATUS_SENT,
|
||||||
|
];
|
||||||
|
|
||||||
|
$transformed = [
|
||||||
|
'company_id' => $this->company->id,
|
||||||
|
'number' => $this->getString( $invoice_data, 'DocumentNumber' ),
|
||||||
|
'notes' => $this->getString( $invoice_data, 'Comment' ),
|
||||||
|
'date' => isset( $invoice_data['DocumentDate'] ) ? date( 'Y-m-d', strtotime( $invoice_data['DocumentDate'] ) ) : null,
|
||||||
|
// 'currency_id' => $this->getCurrencyByCode( $invoice_data, 'Currency' ),
|
||||||
|
'amount' => $this->getFloat( $invoice_data, 'TotalAmount' ),
|
||||||
|
'status_id' => $invoiceStatusMap[ $status =
|
||||||
|
strtolower( $this->getString( $invoice_data, 'DocumentStatus' ) ) ] ?? Invoice::STATUS_SENT,
|
||||||
|
// 'viewed' => $status === 'viewed',
|
||||||
|
'line_items' => [
|
||||||
|
[
|
||||||
|
'cost' => $this->getFloat( $invoice_data, 'TotalAmount' ),
|
||||||
|
'quantity' => 1,
|
||||||
|
'discount' => $this->getFloat( $invoice_data, 'DiscountValue' ),
|
||||||
|
'is_amount_discount' => false,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
$client_id =
|
||||||
|
$this->getClient( $this->getString( $invoice_data, 'Name' ), $this->getString( $invoice_data, 'EmailRecipient' ) );
|
||||||
|
|
||||||
|
if ( $client_id ) {
|
||||||
|
$transformed['client_id'] = $client_id;
|
||||||
|
} else {
|
||||||
|
|
||||||
|
$settings = new \stdClass;
|
||||||
|
$settings->currency_id = $this->getCurrencyByCode( $invoice_data, 'Currency' );
|
||||||
|
|
||||||
|
$transformed['client'] = [
|
||||||
|
'name' => $this->getString( $invoice_data, 'Name' ),
|
||||||
|
'address1' => $this->getString( $invoice_data, 'DocumentRecipientAddress' ),
|
||||||
|
'shipping_address1' => $this->getString( $invoice_data, 'ShipAddress' ),
|
||||||
|
'credit_balance' => 0,
|
||||||
|
'settings' => $settings,
|
||||||
|
'client_hash' => Str::random( 40 ),
|
||||||
|
'contacts' => [
|
||||||
|
[
|
||||||
|
'email' => $this->getString( $invoice_data, 'EmailRecipient' ),
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
if ( ! empty( $invoice_data['Date Paid'] ) ) {
|
||||||
|
$transformed['payments'] = [
|
||||||
|
[
|
||||||
|
'date' => date( 'Y-m-d', strtotime( $invoice_data['DatePaid'] ) ),
|
||||||
|
'amount' => $this->getFloat( $invoice_data, 'Payments' ),
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $transformed;
|
||||||
|
}
|
||||||
|
}
|
50
app/Import/Transformer/Invoicely/ClientTransformer.php
Normal file
50
app/Import/Transformer/Invoicely/ClientTransformer.php
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Invoice Ninja (https://clientninja.com).
|
||||||
|
*
|
||||||
|
* @link https://github.com/clientninja/clientninja source repository
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2021. client Ninja LLC (https://clientninja.com)
|
||||||
|
*
|
||||||
|
* @license https://www.elastic.co/licensing/elastic-license
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Import\Transformer\Invoicely;
|
||||||
|
|
||||||
|
use App\Import\ImportException;
|
||||||
|
use App\Import\Transformer\BaseTransformer;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class ClientTransformer.
|
||||||
|
*/
|
||||||
|
class ClientTransformer extends BaseTransformer {
|
||||||
|
/**
|
||||||
|
* @param $data
|
||||||
|
*
|
||||||
|
* @return array|bool
|
||||||
|
*/
|
||||||
|
public function transform( $data ) {
|
||||||
|
if ( isset( $data['Client Name'] ) && $this->hasClient( $data['Client Name'] ) ) {
|
||||||
|
throw new ImportException('Client already exists');
|
||||||
|
}
|
||||||
|
|
||||||
|
$transformed = [
|
||||||
|
'company_id' => $this->company->id,
|
||||||
|
'name' => $this->getString( $data, 'Client Name' ),
|
||||||
|
'phone' => $this->getString( $data, 'Phone' ),
|
||||||
|
'country_id' => isset( $data['Country'] ) ? $this->getCountryIdBy2( $data['Country'] ) : null,
|
||||||
|
'credit_balance' => 0,
|
||||||
|
'settings' => new \stdClass,
|
||||||
|
'client_hash' => Str::random( 40 ),
|
||||||
|
'contacts' => [
|
||||||
|
[
|
||||||
|
'email' => $this->getString( $data, 'Email' ),
|
||||||
|
'phone' => $this->getString( $data, 'Phone' ),
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
return $transformed;
|
||||||
|
}
|
||||||
|
}
|
58
app/Import/Transformer/Invoicely/InvoiceTransformer.php
Normal file
58
app/Import/Transformer/Invoicely/InvoiceTransformer.php
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* client Ninja (https://clientninja.com).
|
||||||
|
*
|
||||||
|
* @link https://github.com/clientninja/clientninja source repository
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2021. client Ninja LLC (https://clientninja.com)
|
||||||
|
*
|
||||||
|
* @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' );
|
||||||
|
}
|
||||||
|
|
||||||
|
$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,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
if ( strtolower( $data['Status'] ) === 'paid' ) {
|
||||||
|
$transformed['payments'] = [
|
||||||
|
[
|
||||||
|
'date' => date( 'Y-m-d' ),
|
||||||
|
'amount' => $amount,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $transformed;
|
||||||
|
}
|
||||||
|
}
|
72
app/Import/Transformer/Zoho/ClientTransformer.php
Normal file
72
app/Import/Transformer/Zoho/ClientTransformer.php
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Invoice Ninja (https://clientninja.com).
|
||||||
|
*
|
||||||
|
* @link https://github.com/clientninja/clientninja source repository
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2021. client Ninja LLC (https://clientninja.com)
|
||||||
|
*
|
||||||
|
* @license https://www.elastic.co/licensing/elastic-license
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Import\Transformer\Zoho;
|
||||||
|
|
||||||
|
use App\Import\ImportException;
|
||||||
|
use App\Import\Transformer\BaseTransformer;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class ClientTransformer.
|
||||||
|
*/
|
||||||
|
class ClientTransformer extends BaseTransformer {
|
||||||
|
/**
|
||||||
|
* @param $data
|
||||||
|
*
|
||||||
|
* @return array|bool
|
||||||
|
*/
|
||||||
|
public function transform( $data ) {
|
||||||
|
if ( isset( $data['Company Name'] ) && $this->hasClient( $data['Company Name'] ) ) {
|
||||||
|
throw new ImportException( 'Client already exists' );
|
||||||
|
}
|
||||||
|
|
||||||
|
$settings = new \stdClass;
|
||||||
|
$settings->currency_id = (string) $this->getCurrencyByCode( $data, 'Currency' );
|
||||||
|
|
||||||
|
if ( strval( $data['Payment Terms'] ?? '' ) > 0 ) {
|
||||||
|
$settings->payment_terms = $data['Payment Terms'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'company_id' => $this->company->id,
|
||||||
|
'name' => $this->getString( $data, 'Company Name' ),
|
||||||
|
'phone' => $this->getString( $data, 'Phone' ),
|
||||||
|
'private_notes' => $this->getString( $data, 'Notes' ),
|
||||||
|
'website' => $this->getString( $data, 'Website' ),
|
||||||
|
'id_number' => $this->getString( $data, 'Customer ID'),
|
||||||
|
'address1' => $this->getString( $data, 'Billing Address' ),
|
||||||
|
'address2' => $this->getString( $data, 'Billing Street2' ),
|
||||||
|
'city' => $this->getString( $data, 'Billing City' ),
|
||||||
|
'state' => $this->getString( $data, 'Billing State' ),
|
||||||
|
'postal_code' => $this->getString( $data, 'Billing Code' ),
|
||||||
|
'country_id' => isset( $data['Billing Country'] ) ? $this->getCountryId( $data['Billing Country'] ) : null,
|
||||||
|
|
||||||
|
'shipping_address1' => $this->getString( $data, 'Shipping Address' ),
|
||||||
|
'shipping_address2' => $this->getString( $data, 'Shipping Street2' ),
|
||||||
|
'shipping_city' => $this->getString( $data, 'Shipping City' ),
|
||||||
|
'shipping_state' => $this->getString( $data, 'Shipping State' ),
|
||||||
|
'shipping_postal_code' => $this->getString( $data, 'Shipping Code' ),
|
||||||
|
'shipping_country_id' => isset( $data['Shipping Country'] ) ? $this->getCountryId( $data['Shipping Country'] ) : null,
|
||||||
|
'credit_balance' => 0,
|
||||||
|
'settings' => $settings,
|
||||||
|
'client_hash' => Str::random( 40 ),
|
||||||
|
'contacts' => [
|
||||||
|
[
|
||||||
|
'first_name' => $this->getString( $data, 'First Name' ),
|
||||||
|
'last_name' => $this->getString( $data, 'Last Name' ),
|
||||||
|
'email' => $this->getString( $data, 'EmailID' ),
|
||||||
|
'phone' => $this->getString( $data, 'Phone' ),
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
78
app/Import/Transformer/Zoho/InvoiceTransformer.php
Normal file
78
app/Import/Transformer/Zoho/InvoiceTransformer.php
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* client Ninja (https://clientninja.com).
|
||||||
|
*
|
||||||
|
* @link https://github.com/clientninja/clientninja source repository
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2021. client Ninja LLC (https://clientninja.com)
|
||||||
|
*
|
||||||
|
* @license https://www.elastic.co/licensing/elastic-license
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Import\Transformer\Zoho;
|
||||||
|
|
||||||
|
use App\Import\ImportException;
|
||||||
|
use App\Import\Transformer\BaseTransformer;
|
||||||
|
use App\Models\Invoice;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class InvoiceTransformer.
|
||||||
|
*/
|
||||||
|
class InvoiceTransformer extends BaseTransformer {
|
||||||
|
/**
|
||||||
|
* @param $line_items_data
|
||||||
|
*
|
||||||
|
* @return bool|array
|
||||||
|
*/
|
||||||
|
public function transform( $line_items_data ) {
|
||||||
|
$invoice_data = reset( $line_items_data );
|
||||||
|
|
||||||
|
if ( $this->hasInvoice( $invoice_data['Invoice Number'] ) ) {
|
||||||
|
throw new ImportException( 'Invoice number already exists' );
|
||||||
|
}
|
||||||
|
|
||||||
|
$invoiceStatusMap = [
|
||||||
|
'sent' => Invoice::STATUS_SENT,
|
||||||
|
'draft' => Invoice::STATUS_DRAFT,
|
||||||
|
];
|
||||||
|
|
||||||
|
$transformed = [
|
||||||
|
'company_id' => $this->company->id,
|
||||||
|
'client_id' => $this->getClient( $this->getString( $invoice_data, 'Customer ID' ), null ),
|
||||||
|
'number' => $this->getString( $invoice_data, 'Invoice Number' ),
|
||||||
|
'date' => isset( $invoice_data['Invoice Date'] ) ? date( 'Y-m-d', strtotime( $invoice_data['Invoice Date'] ) ) : null,
|
||||||
|
'due_date' => isset( $invoice_data['Due Date'] ) ? date( 'Y-m-d', strtotime( $invoice_data['Due Date'] ) ) : null,
|
||||||
|
'po_number' => $this->getString( $invoice_data, 'PurchaseOrder' ),
|
||||||
|
'public_notes' => $this->getString( $invoice_data, 'Notes' ),
|
||||||
|
'currency_id' => $this->getCurrencyByCode( $invoice_data, 'Currency' ),
|
||||||
|
'amount' => $this->getFloat( $invoice_data, 'Total' ),
|
||||||
|
'balance' => $this->getFloat( $invoice_data, 'Balance' ),
|
||||||
|
'status_id' => $invoiceStatusMap[ $status =
|
||||||
|
strtolower( $this->getString( $invoice_data, 'Invoice Status' ) ) ] ?? Invoice::STATUS_SENT,
|
||||||
|
// 'viewed' => $status === 'viewed',
|
||||||
|
];
|
||||||
|
|
||||||
|
$line_items = [];
|
||||||
|
foreach ( $line_items_data as $record ) {
|
||||||
|
$line_items[] = [
|
||||||
|
'product_key' => $this->getString( $record, 'Item Name' ),
|
||||||
|
'notes' => $this->getString( $record, 'Item Description' ),
|
||||||
|
'cost' => round($this->getFloat( $record, 'Item Price' ),2),
|
||||||
|
'quantity' => $this->getFloat( $record, 'Quantity' ),
|
||||||
|
'discount' => $this->getString( $record, 'Discount Amount' ),
|
||||||
|
'is_amount_discount' => true,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
$transformed['line_items'] = $line_items;
|
||||||
|
|
||||||
|
if ( $transformed['balance'] < $transformed['amount'] ) {
|
||||||
|
$transformed['payments'] = [[
|
||||||
|
'date' => isset( $invoice_data['Last Payment Date'] ) ? date( 'Y-m-d', strtotime( $invoice_data['Invoice Date'] ) ) : date( 'Y-m-d' ),
|
||||||
|
'amount' => $transformed['amount'] - $transformed['balance'],
|
||||||
|
]];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $transformed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -37,7 +37,9 @@ class CSVIngest implements ShouldQueue {
|
|||||||
|
|
||||||
public ?string $skip_header;
|
public ?string $skip_header;
|
||||||
|
|
||||||
public array $column_map;
|
public $column_map;
|
||||||
|
|
||||||
|
public array $request;
|
||||||
|
|
||||||
public function __construct( array $request, Company $company ) {
|
public function __construct( array $request, Company $company ) {
|
||||||
$this->company = $company;
|
$this->company = $company;
|
||||||
|
@ -267,8 +267,8 @@ class BraintreePaymentDriver extends BaseDriver
|
|||||||
|
|
||||||
nlog("braintree webhook");
|
nlog("braintree webhook");
|
||||||
|
|
||||||
if($webhookNotification)
|
// if($webhookNotification)
|
||||||
nlog($webhookNotification->kind);
|
// nlog($webhookNotification->kind);
|
||||||
|
|
||||||
// // Example values for webhook notification properties
|
// // Example values for webhook notification properties
|
||||||
// $message = $webhookNotification->kind; // "subscription_went_past_due"
|
// $message = $webhookNotification->kind; // "subscription_went_past_due"
|
||||||
|
@ -57,7 +57,7 @@ class Token
|
|||||||
|
|
||||||
$header['signature'] = $this->payfast->generateTokenSignature(array_merge($body, $header));
|
$header['signature'] = $this->payfast->generateTokenSignature(array_merge($body, $header));
|
||||||
|
|
||||||
nlog($header['signature']);
|
// nlog($header['signature']);
|
||||||
|
|
||||||
$result = $this->send($header, $body, $cgt->token);
|
$result = $this->send($header, $body, $cgt->token);
|
||||||
|
|
||||||
@ -95,7 +95,7 @@ class Token
|
|||||||
$parameter_string = rtrim( $parameter_string, '&' );
|
$parameter_string = rtrim( $parameter_string, '&' );
|
||||||
}
|
}
|
||||||
|
|
||||||
nlog($parameter_string);
|
// nlog($parameter_string);
|
||||||
|
|
||||||
return $parameter_string;
|
return $parameter_string;
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ use WePayCommon;
|
|||||||
$data = $request->all();
|
$data = $request->all();
|
||||||
// authorize the credit card
|
// authorize the credit card
|
||||||
|
|
||||||
nlog($data);
|
// nlog($data);
|
||||||
/*
|
/*
|
||||||
'_token' => '1Fk5CRj34up5ntKPvrFyMIAJhDdUNF3boqT3iIN3',
|
'_token' => '1Fk5CRj34up5ntKPvrFyMIAJhDdUNF3boqT3iIN3',
|
||||||
'company_gateway_id' => '39',
|
'company_gateway_id' => '39',
|
||||||
|
@ -46,8 +46,6 @@ class GetCreditPdf extends AbstractService
|
|||||||
|
|
||||||
$file_path = CreateEntityPdf::dispatchNow($this->invitation);
|
$file_path = CreateEntityPdf::dispatchNow($this->invitation);
|
||||||
|
|
||||||
nlog($file_path);
|
|
||||||
return $file_path;
|
return $file_path;
|
||||||
// return Storage::disk($disk)->path($file_path);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -122,6 +122,31 @@
|
|||||||
})}
|
})}
|
||||||
);
|
);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@if($company && $company->google_analytics_key)
|
||||||
|
<script>
|
||||||
|
(function (i, s, o, g, r, a, m) {
|
||||||
|
i['GoogleAnalyticsObject'] = r;
|
||||||
|
i[r] = i[r] || function () {
|
||||||
|
(i[r].q = i[r].q || []).push(arguments)
|
||||||
|
}, i[r].l = 1 * new Date();
|
||||||
|
a = s.createElement(o),
|
||||||
|
m = s.getElementsByTagName(o)[0];
|
||||||
|
a.async = 1;
|
||||||
|
a.src = g;
|
||||||
|
m.parentNode.insertBefore(a, m)
|
||||||
|
})(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');
|
||||||
|
|
||||||
|
ga('create', '{{ $company->google_analytics_key }}', 'auto');
|
||||||
|
ga('set', 'anonymizeIp', true);
|
||||||
|
ga('send', 'pageview');
|
||||||
|
|
||||||
|
function trackEvent(category, action) {
|
||||||
|
ga('send', 'event', category, action, this.src);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
@endif
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
<footer>
|
<footer>
|
||||||
|
@ -29,7 +29,7 @@ Route::get('error', 'ClientPortal\ContactHashLoginController@errorPage')->name('
|
|||||||
Route::get('client/payment/{contact_key}/{payment_id}', 'ClientPortal\InvitationController@paymentRouter')->middleware(['domain_db','contact_key_login']);
|
Route::get('client/payment/{contact_key}/{payment_id}', 'ClientPortal\InvitationController@paymentRouter')->middleware(['domain_db','contact_key_login']);
|
||||||
Route::get('client/ninja/{contact_key}/{company_key}', 'ClientPortal\NinjaPlanController@index')->name('client.ninja_contact_login')->middleware(['domain_db']);
|
Route::get('client/ninja/{contact_key}/{company_key}', 'ClientPortal\NinjaPlanController@index')->name('client.ninja_contact_login')->middleware(['domain_db']);
|
||||||
|
|
||||||
Route::group(['middleware' => ['auth:contact', 'locale', 'domain_db'], 'prefix' => 'client', 'as' => 'client.'], function () {
|
Route::group(['middleware' => ['auth:contact', 'locale', 'domain_db','check_client_existence'], 'prefix' => 'client', 'as' => 'client.'], function () {
|
||||||
Route::get('dashboard', 'ClientPortal\DashboardController@index')->name('dashboard'); // name = (dashboard. index / create / show / update / destroy / edit
|
Route::get('dashboard', 'ClientPortal\DashboardController@index')->name('dashboard'); // name = (dashboard. index / create / show / update / destroy / edit
|
||||||
|
|
||||||
Route::get('plan', 'ClientPortal\NinjaPlanController@plan')->name('plan'); // name = (dashboard. index / create / show / update / destroy / edit
|
Route::get('plan', 'ClientPortal\NinjaPlanController@plan')->name('plan'); // name = (dashboard. index / create / show / update / destroy / edit
|
||||||
|
207
tests/Feature/Import/Freshbooks/FreshbooksTest.php
Normal file
207
tests/Feature/Import/Freshbooks/FreshbooksTest.php
Normal file
@ -0,0 +1,207 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Invoice Ninja (https://invoiceninja.com).
|
||||||
|
*
|
||||||
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
||||||
|
*
|
||||||
|
* @license https://opensource.org/licenses/AAL
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Tests\Feature\Import\Freshbooks;
|
||||||
|
|
||||||
|
use App\Import\Providers\BaseImport;
|
||||||
|
use App\Import\Providers\Freshbooks;
|
||||||
|
use App\Import\Providers\Zoho;
|
||||||
|
use App\Import\Transformer\BaseTransformer;
|
||||||
|
use App\Models\Client;
|
||||||
|
use App\Models\Invoice;
|
||||||
|
use App\Models\Product;
|
||||||
|
use App\Models\Vendor;
|
||||||
|
use App\Utils\Traits\MakesHash;
|
||||||
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||||
|
use Illuminate\Routing\Middleware\ThrottleRequests;
|
||||||
|
use Illuminate\Support\Facades\Cache;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
use Tests\MockAccountData;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @covers App\Import\Providers\Freshbooks
|
||||||
|
*/
|
||||||
|
class FreshbooksTest extends TestCase
|
||||||
|
{
|
||||||
|
use MakesHash;
|
||||||
|
use MockAccountData;
|
||||||
|
use DatabaseTransactions;
|
||||||
|
|
||||||
|
public function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->withoutMiddleware(ThrottleRequests::class);
|
||||||
|
|
||||||
|
config(['database.default' => config('ninja.db.default')]);
|
||||||
|
|
||||||
|
$this->makeTestData();
|
||||||
|
|
||||||
|
$this->withoutExceptionHandling();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testClientFreshbooksImport()
|
||||||
|
{
|
||||||
|
$csv = file_get_contents(
|
||||||
|
base_path() . '/tests/Feature/Import/freshbooks_clients.csv'
|
||||||
|
);
|
||||||
|
$hash = Str::random(32);
|
||||||
|
|
||||||
|
$column_map = [
|
||||||
|
0 => 'Organization',
|
||||||
|
1 => 'First Name',
|
||||||
|
2 => 'Last Name',
|
||||||
|
3 => 'Email',
|
||||||
|
4 => 'Phone',
|
||||||
|
5 => 'Street',
|
||||||
|
6 => 'City',
|
||||||
|
7 => 'Province/State',
|
||||||
|
8 => 'Country',
|
||||||
|
9 => 'Postal Code',
|
||||||
|
10 => 'Notes',
|
||||||
|
];
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'hash' => $hash,
|
||||||
|
'column_map' => ['client' => ['mapping' => $column_map]],
|
||||||
|
'skip_header' => true,
|
||||||
|
'import_type' => 'freshbooks',
|
||||||
|
];
|
||||||
|
|
||||||
|
Cache::put($hash . '-client', base64_encode($csv), 360);
|
||||||
|
|
||||||
|
$csv_importer = new Freshbooks($data, $this->company);
|
||||||
|
|
||||||
|
$count = $csv_importer->import('client');
|
||||||
|
|
||||||
|
$base_transformer = new BaseTransformer($this->company);
|
||||||
|
|
||||||
|
$this->assertTrue($base_transformer->hasClient('Marge Simpson'));
|
||||||
|
$this->assertTrue($base_transformer->hasClient('X-Men'));
|
||||||
|
|
||||||
|
$client_id = $base_transformer->getClient('', 'marge@simpsons.com');
|
||||||
|
|
||||||
|
$client = Client::find($client_id);
|
||||||
|
|
||||||
|
$this->assertInstanceOf(Client::class, $client);
|
||||||
|
$this->assertEquals('840', $client->country_id);
|
||||||
|
$this->assertEquals('867-5309', $client->phone);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testInvoiceZohoImport()
|
||||||
|
{
|
||||||
|
$csv = file_get_contents(
|
||||||
|
base_path() . '/tests/Feature/Import/freshbooks_clients.csv'
|
||||||
|
);
|
||||||
|
$hash = Str::random(32);
|
||||||
|
|
||||||
|
$column_map = [
|
||||||
|
0 => 'Organization',
|
||||||
|
1 => 'First Name',
|
||||||
|
2 => 'Last Name',
|
||||||
|
3 => 'Email',
|
||||||
|
4 => 'Phone',
|
||||||
|
5 => 'Street',
|
||||||
|
6 => 'City',
|
||||||
|
7 => 'Province/State',
|
||||||
|
8 => 'Country',
|
||||||
|
9 => 'Postal Code',
|
||||||
|
10 => 'Notes',
|
||||||
|
];
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'hash' => $hash,
|
||||||
|
'column_map' => ['client' => ['mapping' => $column_map]],
|
||||||
|
'skip_header' => true,
|
||||||
|
'import_type' => 'freshbooks',
|
||||||
|
];
|
||||||
|
|
||||||
|
Cache::put($hash . '-client', base64_encode($csv), 360);
|
||||||
|
|
||||||
|
$csv_importer = new Freshbooks($data, $this->company);
|
||||||
|
|
||||||
|
$count = $csv_importer->import('client');
|
||||||
|
|
||||||
|
$base_transformer = new BaseTransformer($this->company);
|
||||||
|
|
||||||
|
$this->assertTrue($base_transformer->hasClient('Marge Simpson'));
|
||||||
|
$this->assertTrue($base_transformer->hasClient('X-Men'));
|
||||||
|
|
||||||
|
$client_id = $base_transformer->getClient('', 'marge@simpsons.com');
|
||||||
|
|
||||||
|
$client = Client::find($client_id);
|
||||||
|
|
||||||
|
$this->assertInstanceOf(Client::class, $client);
|
||||||
|
$this->assertEquals('840', $client->country_id);
|
||||||
|
$this->assertEquals('867-5309', $client->phone);
|
||||||
|
|
||||||
|
//now import the invoices
|
||||||
|
|
||||||
|
$csv = file_get_contents(
|
||||||
|
base_path() . '/tests/Feature/Import/freshbooks_invoices.csv'
|
||||||
|
);
|
||||||
|
$hash = Str::random(32);
|
||||||
|
|
||||||
|
$column_map = [
|
||||||
|
0 => 'Client Name',
|
||||||
|
1 => 'Invoice #',
|
||||||
|
2 => 'Date Issued',
|
||||||
|
3 => 'Invoice Status',
|
||||||
|
4 => 'Date Paid',
|
||||||
|
5 => 'Item Name',
|
||||||
|
6 => 'Item Description',
|
||||||
|
7 => 'Rate',
|
||||||
|
8 => 'Quantity',
|
||||||
|
9 => 'Discount Percentage',
|
||||||
|
10 => 'Line Subtotal',
|
||||||
|
11 => 'Tax 1 Type',
|
||||||
|
12 => 'Tax 1 Amount',
|
||||||
|
13 => 'Tax 2 Type',
|
||||||
|
14 => 'Tax 2 Amount',
|
||||||
|
15 => 'Line Total',
|
||||||
|
16 => 'Currency',
|
||||||
|
];
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'hash' => $hash,
|
||||||
|
'column_map' => ['invoice' => ['mapping' => $column_map]],
|
||||||
|
'skip_header' => true,
|
||||||
|
'import_type' => 'freshbooks',
|
||||||
|
];
|
||||||
|
|
||||||
|
Cache::put($hash . '-invoice', base64_encode($csv), 360);
|
||||||
|
|
||||||
|
$csv_importer = new Freshbooks($data, $this->company);
|
||||||
|
|
||||||
|
$count = $csv_importer->import('invoice');
|
||||||
|
|
||||||
|
$base_transformer = new BaseTransformer($this->company);
|
||||||
|
|
||||||
|
$this->assertTrue($base_transformer->hasInvoice("0000001"));
|
||||||
|
$invoice_id = $base_transformer->getInvoiceId("0000001");
|
||||||
|
$invoice = Invoice::find($invoice_id);
|
||||||
|
|
||||||
|
$this->assertEquals(7890 , $invoice->amount);
|
||||||
|
$this->assertEquals(2 , $invoice->status_id);
|
||||||
|
$this->assertEquals(7890 , $invoice->balance);
|
||||||
|
$this->assertEquals(3 , count($invoice->line_items));
|
||||||
|
|
||||||
|
$this->assertFalse($invoice->payments()->exists());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
147
tests/Feature/Import/Invoice2Go/Invoice2GoTest.php
Normal file
147
tests/Feature/Import/Invoice2Go/Invoice2GoTest.php
Normal file
@ -0,0 +1,147 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Invoice Ninja (https://invoiceninja.com).
|
||||||
|
*
|
||||||
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
||||||
|
*
|
||||||
|
* @license https://opensource.org/licenses/AAL
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Tests\Feature\Import\Invoice2Go;
|
||||||
|
|
||||||
|
use App\Import\Providers\BaseImport;
|
||||||
|
use App\Import\Providers\Freshbooks;
|
||||||
|
use App\Import\Providers\Invoice2Go;
|
||||||
|
use App\Import\Providers\Zoho;
|
||||||
|
use App\Import\Transformer\BaseTransformer;
|
||||||
|
use App\Models\Client;
|
||||||
|
use App\Models\Invoice;
|
||||||
|
use App\Models\Product;
|
||||||
|
use App\Models\Vendor;
|
||||||
|
use App\Utils\Traits\MakesHash;
|
||||||
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||||
|
use Illuminate\Routing\Middleware\ThrottleRequests;
|
||||||
|
use Illuminate\Support\Facades\Cache;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
use Tests\MockAccountData;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @covers App\Import\Providers\Invoice2Go
|
||||||
|
*/
|
||||||
|
class Invoice2GoTest extends TestCase
|
||||||
|
{
|
||||||
|
use MakesHash;
|
||||||
|
use MockAccountData;
|
||||||
|
use DatabaseTransactions;
|
||||||
|
|
||||||
|
public function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->withoutMiddleware(ThrottleRequests::class);
|
||||||
|
|
||||||
|
config(['database.default' => config('ninja.db.default')]);
|
||||||
|
|
||||||
|
$this->makeTestData();
|
||||||
|
|
||||||
|
$this->withoutExceptionHandling();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testInvoice2GoImport()
|
||||||
|
{
|
||||||
|
$csv = file_get_contents(
|
||||||
|
base_path() . '/tests/Feature/Import/i2g_invoices.csv'
|
||||||
|
);
|
||||||
|
$hash = Str::random(32);
|
||||||
|
|
||||||
|
$column_map = [
|
||||||
|
0 => 'Id',
|
||||||
|
1 => 'AccountId',
|
||||||
|
2 => 'State',
|
||||||
|
3 => 'LastUpdated',
|
||||||
|
4 => 'CreatedDate',
|
||||||
|
5 => 'DocumentDate',
|
||||||
|
6 => 'DocumentNumber',
|
||||||
|
7 => 'Comment',
|
||||||
|
8 => 'Name',
|
||||||
|
9 => 'EmailRecipient',
|
||||||
|
10 => 'DocumentStatus',
|
||||||
|
11 => 'OutputStatus',
|
||||||
|
12 => 'PartPayment',
|
||||||
|
13 => 'DocumentRecipientAddress',
|
||||||
|
14 => 'ShipDate',
|
||||||
|
15 => 'ShipAddress',
|
||||||
|
16 => 'ShipAmount',
|
||||||
|
17 => 'ShipTrackingNumber',
|
||||||
|
18 => 'ShipVia',
|
||||||
|
19 => 'ShipFob',
|
||||||
|
20 => 'StyleName',
|
||||||
|
21 => 'DatePaid',
|
||||||
|
22 => 'CustomField',
|
||||||
|
23 => 'DiscountType',
|
||||||
|
24 => 'Discount',
|
||||||
|
25 => 'DiscountValue',
|
||||||
|
26 => 'Taxes',
|
||||||
|
27 => 'WithholdingTaxName',
|
||||||
|
28 => 'WithholdingTaxRate',
|
||||||
|
29 => 'TermsOld',
|
||||||
|
30 => 'Payments',
|
||||||
|
31 => 'Items',
|
||||||
|
32 => 'CurrencyCode',
|
||||||
|
33 => 'TotalAmount',
|
||||||
|
34 => 'BalanceDueAmount',
|
||||||
|
35 => 'AmountPaidAmount',
|
||||||
|
36 => 'DiscountAmount',
|
||||||
|
37 => 'SubtotalAmount',
|
||||||
|
38 => 'TotalTaxAmount',
|
||||||
|
39 => 'WithholdingTaxAmount',
|
||||||
|
];
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'hash' => $hash,
|
||||||
|
'column_map' => ['invoice' => ['mapping' => $column_map]],
|
||||||
|
'skip_header' => true,
|
||||||
|
'import_type' => 'invoice2go',
|
||||||
|
];
|
||||||
|
|
||||||
|
Cache::put($hash . '-invoice', base64_encode($csv), 360);
|
||||||
|
|
||||||
|
$csv_importer = new Invoice2Go($data, $this->company);
|
||||||
|
|
||||||
|
$count = $csv_importer->import('invoice');
|
||||||
|
|
||||||
|
$base_transformer = new BaseTransformer($this->company);
|
||||||
|
|
||||||
|
$this->assertTrue($base_transformer->hasClient('Barry Gordon'));
|
||||||
|
$this->assertTrue($base_transformer->hasClient('James Gordon'));
|
||||||
|
$this->assertTrue($base_transformer->hasClient('Deadpool Inc'));
|
||||||
|
$this->assertTrue($base_transformer->hasClient('Daily Planet'));
|
||||||
|
|
||||||
|
$client_id = $base_transformer->getClient('', 'wade@projectx.net');
|
||||||
|
|
||||||
|
$client = Client::find($client_id);
|
||||||
|
|
||||||
|
$this->assertInstanceOf(Client::class, $client);
|
||||||
|
$this->assertEquals('840', $client->country_id);
|
||||||
|
$this->assertEquals('2584 Sesame Street', $client->address1);
|
||||||
|
|
||||||
|
$this->assertTrue($base_transformer->hasInvoice("1"));
|
||||||
|
$this->assertTrue($base_transformer->hasInvoice("2"));
|
||||||
|
$this->assertTrue($base_transformer->hasInvoice("3"));
|
||||||
|
$this->assertTrue($base_transformer->hasInvoice("4"));
|
||||||
|
$invoice_id = $base_transformer->getInvoiceId("1");
|
||||||
|
$invoice = Invoice::find($invoice_id);
|
||||||
|
|
||||||
|
$this->assertEquals(953.55, $invoice->amount);
|
||||||
|
$this->assertEquals(1 , $invoice->status_id);
|
||||||
|
$this->assertEquals(0, $invoice->balance);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
181
tests/Feature/Import/Invoicely/InvoicelyTest.php
Normal file
181
tests/Feature/Import/Invoicely/InvoicelyTest.php
Normal file
@ -0,0 +1,181 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Invoice Ninja (https://invoiceninja.com).
|
||||||
|
*
|
||||||
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
||||||
|
*
|
||||||
|
* @license https://opensource.org/licenses/AAL
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Tests\Feature\Import\Invoicely;
|
||||||
|
|
||||||
|
use App\Import\Providers\BaseImport;
|
||||||
|
use App\Import\Providers\Invoicely;
|
||||||
|
use App\Import\Providers\Zoho;
|
||||||
|
use App\Import\Transformer\BaseTransformer;
|
||||||
|
use App\Models\Client;
|
||||||
|
use App\Models\Invoice;
|
||||||
|
use App\Models\Product;
|
||||||
|
use App\Models\Vendor;
|
||||||
|
use App\Utils\Traits\MakesHash;
|
||||||
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||||
|
use Illuminate\Routing\Middleware\ThrottleRequests;
|
||||||
|
use Illuminate\Support\Facades\Cache;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
use Tests\MockAccountData;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @covers App\Import\Providers\Invoicely
|
||||||
|
*/
|
||||||
|
class InvoicelyTest extends TestCase
|
||||||
|
{
|
||||||
|
use MakesHash;
|
||||||
|
use MockAccountData;
|
||||||
|
use DatabaseTransactions;
|
||||||
|
|
||||||
|
public function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->withoutMiddleware(ThrottleRequests::class);
|
||||||
|
|
||||||
|
config(['database.default' => config('ninja.db.default')]);
|
||||||
|
|
||||||
|
$this->makeTestData();
|
||||||
|
|
||||||
|
$this->withoutExceptionHandling();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testClientInvoicelyImport()
|
||||||
|
{
|
||||||
|
$csv = file_get_contents(
|
||||||
|
base_path() . '/tests/Feature/Import/invoicely_clients.csv'
|
||||||
|
);
|
||||||
|
$hash = Str::random(32);
|
||||||
|
|
||||||
|
$column_map = [
|
||||||
|
0 => 'Client Name',
|
||||||
|
1 => 'Email',
|
||||||
|
2 => 'Phone',
|
||||||
|
3 => 'Country',
|
||||||
|
];
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'hash' => $hash,
|
||||||
|
'column_map' => ['client' => ['mapping' => $column_map]],
|
||||||
|
'skip_header' => true,
|
||||||
|
'import_type' => 'invoicely',
|
||||||
|
];
|
||||||
|
|
||||||
|
Cache::put($hash . '-client', base64_encode($csv), 360);
|
||||||
|
|
||||||
|
$csv_importer = new Invoicely($data, $this->company);
|
||||||
|
|
||||||
|
$count = $csv_importer->import('client');
|
||||||
|
|
||||||
|
$base_transformer = new BaseTransformer($this->company);
|
||||||
|
|
||||||
|
$this->assertTrue($base_transformer->hasClient('Alexander Hamilton'));
|
||||||
|
$this->assertTrue($base_transformer->hasClient('Bruce Wayne'));
|
||||||
|
|
||||||
|
$client_id = $base_transformer->getClient('', 'alexander@iamhamllton.com');
|
||||||
|
|
||||||
|
$client = Client::find($client_id);
|
||||||
|
|
||||||
|
$this->assertInstanceOf(Client::class, $client);
|
||||||
|
$this->assertEquals('5558675309', $client->phone);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testInvoiceInvoicelyImport()
|
||||||
|
{
|
||||||
|
|
||||||
|
$csv = file_get_contents(
|
||||||
|
base_path() . '/tests/Feature/Import/invoicely_clients.csv'
|
||||||
|
);
|
||||||
|
$hash = Str::random(32);
|
||||||
|
|
||||||
|
$column_map = [
|
||||||
|
0 => 'Client Name',
|
||||||
|
1 => 'Email',
|
||||||
|
2 => 'Phone',
|
||||||
|
3 => 'Country',
|
||||||
|
];
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'hash' => $hash,
|
||||||
|
'column_map' => ['client' => ['mapping' => $column_map]],
|
||||||
|
'skip_header' => true,
|
||||||
|
'import_type' => 'invoicely',
|
||||||
|
];
|
||||||
|
|
||||||
|
Cache::put($hash . '-client', base64_encode($csv), 360);
|
||||||
|
|
||||||
|
$csv_importer = new Invoicely($data, $this->company);
|
||||||
|
|
||||||
|
$count = $csv_importer->import('client');
|
||||||
|
|
||||||
|
$base_transformer = new BaseTransformer($this->company);
|
||||||
|
|
||||||
|
$this->assertTrue($base_transformer->hasClient('Alexander Hamilton'));
|
||||||
|
$this->assertTrue($base_transformer->hasClient('Bruce Wayne'));
|
||||||
|
|
||||||
|
$client_id = $base_transformer->getClient('', 'alexander@iamhamllton.com');
|
||||||
|
|
||||||
|
$client = Client::find($client_id);
|
||||||
|
|
||||||
|
$this->assertInstanceOf(Client::class, $client);
|
||||||
|
$this->assertEquals('5558675309', $client->phone);
|
||||||
|
//now import the invoices
|
||||||
|
|
||||||
|
$csv = file_get_contents(
|
||||||
|
base_path() . '/tests/Feature/Import/invoicely_invoices.csv'
|
||||||
|
);
|
||||||
|
$hash = Str::random(32);
|
||||||
|
|
||||||
|
$column_map = [
|
||||||
|
0 => 'Date',
|
||||||
|
1 => 'Due',
|
||||||
|
2 => 'Details',
|
||||||
|
3 => 'Client',
|
||||||
|
4 => 'Status',
|
||||||
|
5 => 'Total',
|
||||||
|
];
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'hash' => $hash,
|
||||||
|
'column_map' => ['invoice' => ['mapping' => $column_map]],
|
||||||
|
'skip_header' => true,
|
||||||
|
'import_type' => 'invoicely',
|
||||||
|
];
|
||||||
|
|
||||||
|
Cache::put($hash . '-invoice', base64_encode($csv), 360);
|
||||||
|
|
||||||
|
$csv_importer = new Invoicely($data, $this->company);
|
||||||
|
|
||||||
|
$count = $csv_importer->import('invoice');
|
||||||
|
|
||||||
|
$base_transformer = new BaseTransformer($this->company);
|
||||||
|
nlog($count);
|
||||||
|
$this->assertTrue($base_transformer->hasInvoice("INV-1"));
|
||||||
|
|
||||||
|
$invoice_id = $base_transformer->getInvoiceId("INV-1");
|
||||||
|
$invoice = Invoice::find($invoice_id);
|
||||||
|
|
||||||
|
$this->assertEquals(1020 , $invoice->amount);
|
||||||
|
$this->assertEquals(2 , $invoice->status_id);
|
||||||
|
$this->assertEquals(1020 , $invoice->balance);
|
||||||
|
$this->assertEquals(1 , count($invoice->line_items));
|
||||||
|
|
||||||
|
$this->assertFalse($invoice->payments()->exists());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -9,7 +9,7 @@
|
|||||||
* @license https://opensource.org/licenses/AAL
|
* @license https://opensource.org/licenses/AAL
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Tests\Feature\Import\CSV;
|
namespace Tests\Feature\Import\Wave;
|
||||||
|
|
||||||
use App\Import\Providers\BaseImport;
|
use App\Import\Providers\BaseImport;
|
||||||
use App\Import\Providers\Wave;
|
use App\Import\Providers\Wave;
|
||||||
|
345
tests/Feature/Import/Zoho/ZohoTest.php
Normal file
345
tests/Feature/Import/Zoho/ZohoTest.php
Normal file
@ -0,0 +1,345 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Invoice Ninja (https://invoiceninja.com).
|
||||||
|
*
|
||||||
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
||||||
|
*
|
||||||
|
* @license https://opensource.org/licenses/AAL
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Tests\Feature\Import\Zoho;
|
||||||
|
|
||||||
|
use App\Import\Providers\BaseImport;
|
||||||
|
use App\Import\Providers\Zoho;
|
||||||
|
use App\Import\Transformer\BaseTransformer;
|
||||||
|
use App\Models\Client;
|
||||||
|
use App\Models\Invoice;
|
||||||
|
use App\Models\Product;
|
||||||
|
use App\Models\Vendor;
|
||||||
|
use App\Utils\Traits\MakesHash;
|
||||||
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||||
|
use Illuminate\Routing\Middleware\ThrottleRequests;
|
||||||
|
use Illuminate\Support\Facades\Cache;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
use Tests\MockAccountData;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @covers App\Import\Providers\Zoho
|
||||||
|
*/
|
||||||
|
class ZohoTest extends TestCase
|
||||||
|
{
|
||||||
|
use MakesHash;
|
||||||
|
use MockAccountData;
|
||||||
|
use DatabaseTransactions;
|
||||||
|
|
||||||
|
public function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->withoutMiddleware(ThrottleRequests::class);
|
||||||
|
|
||||||
|
config(['database.default' => config('ninja.db.default')]);
|
||||||
|
|
||||||
|
$this->makeTestData();
|
||||||
|
|
||||||
|
$this->withoutExceptionHandling();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testClientZohoImport()
|
||||||
|
{
|
||||||
|
$csv = file_get_contents(
|
||||||
|
base_path() . '/tests/Feature/Import/zoho_contacts.csv'
|
||||||
|
);
|
||||||
|
$hash = Str::random(32);
|
||||||
|
|
||||||
|
$column_map = [
|
||||||
|
0 => 'Created Time',
|
||||||
|
1 => 'Last Modified Time',
|
||||||
|
2 => 'Display Name',
|
||||||
|
3 => 'Company Name',
|
||||||
|
4 => 'Salutation',
|
||||||
|
5 => 'First Name',
|
||||||
|
6 => 'Last Name',
|
||||||
|
7 => 'Phone',
|
||||||
|
8 => 'Currency Code',
|
||||||
|
9 => 'Notes',
|
||||||
|
10 => 'Website',
|
||||||
|
11 => 'Status',
|
||||||
|
12 => 'Credit Limit',
|
||||||
|
13 => 'Customer Sub Type',
|
||||||
|
14 => 'Billing Attention',
|
||||||
|
15 => 'Billing Address',
|
||||||
|
16 => 'Billing Street2',
|
||||||
|
17 => 'Billing City',
|
||||||
|
18 => 'Billing State',
|
||||||
|
19 => 'Billing Country',
|
||||||
|
20 => 'Billing Code',
|
||||||
|
21 => 'Billing Phone',
|
||||||
|
22 => 'Billing Fax',
|
||||||
|
23 => 'Shipping Attention',
|
||||||
|
24 => 'Shipping Address',
|
||||||
|
25 => 'Shipping Street2',
|
||||||
|
26 => 'Shipping City',
|
||||||
|
27 => 'Shipping State',
|
||||||
|
28 => 'Shipping Country',
|
||||||
|
29 => 'Shipping Code',
|
||||||
|
30 => 'Shipping Phone',
|
||||||
|
31 => 'Shipping Fax',
|
||||||
|
32 => 'Skype Identity',
|
||||||
|
33 => 'Facebook',
|
||||||
|
34 => 'Twitter',
|
||||||
|
35 => 'Department',
|
||||||
|
36 => 'Designation',
|
||||||
|
37 => 'Price List',
|
||||||
|
38 => 'Payment Terms',
|
||||||
|
39 => 'Payment Terms Label',
|
||||||
|
40 => 'Last Sync Time',
|
||||||
|
41 => 'Owner Name',
|
||||||
|
42 => 'EmailID',
|
||||||
|
43 => 'MobilePhone',
|
||||||
|
44 => 'Customer ID',
|
||||||
|
45 => 'Customer Name',
|
||||||
|
46 => 'Contact Type',
|
||||||
|
47 => 'Customer Address ID',
|
||||||
|
48 => 'Source',
|
||||||
|
49 => 'Reference ID',
|
||||||
|
50 => 'Payment Reminder',
|
||||||
|
];
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'hash' => $hash,
|
||||||
|
'column_map' => ['client' => ['mapping' => $column_map]],
|
||||||
|
'skip_header' => true,
|
||||||
|
'import_type' => 'zoho',
|
||||||
|
];
|
||||||
|
|
||||||
|
Cache::put($hash . '-client', base64_encode($csv), 360);
|
||||||
|
|
||||||
|
$csv_importer = new Zoho($data, $this->company);
|
||||||
|
|
||||||
|
$count = $csv_importer->import('client');
|
||||||
|
|
||||||
|
$base_transformer = new BaseTransformer($this->company);
|
||||||
|
|
||||||
|
$this->assertTrue($base_transformer->hasClient('Defenders'));
|
||||||
|
$this->assertTrue($base_transformer->hasClient('Avengers'));
|
||||||
|
$this->assertTrue($base_transformer->hasClient('Highlander'));
|
||||||
|
$this->assertTrue($base_transformer->hasClient('Simpsons Baking Co'));
|
||||||
|
|
||||||
|
$client_id = $base_transformer->getClient('', 'jessica@jones.net');
|
||||||
|
|
||||||
|
$client = Client::find($client_id);
|
||||||
|
|
||||||
|
$this->assertInstanceOf(Client::class, $client);
|
||||||
|
$this->assertEquals('1', $client->settings->currency_id);
|
||||||
|
$this->assertEquals('888-867-5309', $client->phone);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testInvoiceZohoImport()
|
||||||
|
{
|
||||||
|
//first import all the clients
|
||||||
|
$csv = file_get_contents(
|
||||||
|
base_path() . '/tests/Feature/Import/zoho_contacts.csv'
|
||||||
|
);
|
||||||
|
$hash = Str::random(32);
|
||||||
|
|
||||||
|
$column_map = [
|
||||||
|
0 => 'Created Time',
|
||||||
|
1 => 'Last Modified Time',
|
||||||
|
2 => 'Display Name',
|
||||||
|
3 => 'Company Name',
|
||||||
|
4 => 'Salutation',
|
||||||
|
5 => 'First Name',
|
||||||
|
6 => 'Last Name',
|
||||||
|
7 => 'Phone',
|
||||||
|
8 => 'Currency Code',
|
||||||
|
9 => 'Notes',
|
||||||
|
10 => 'Website',
|
||||||
|
11 => 'Status',
|
||||||
|
12 => 'Credit Limit',
|
||||||
|
13 => 'Customer Sub Type',
|
||||||
|
14 => 'Billing Attention',
|
||||||
|
15 => 'Billing Address',
|
||||||
|
16 => 'Billing Street2',
|
||||||
|
17 => 'Billing City',
|
||||||
|
18 => 'Billing State',
|
||||||
|
19 => 'Billing Country',
|
||||||
|
20 => 'Billing Code',
|
||||||
|
21 => 'Billing Phone',
|
||||||
|
22 => 'Billing Fax',
|
||||||
|
23 => 'Shipping Attention',
|
||||||
|
24 => 'Shipping Address',
|
||||||
|
25 => 'Shipping Street2',
|
||||||
|
26 => 'Shipping City',
|
||||||
|
27 => 'Shipping State',
|
||||||
|
28 => 'Shipping Country',
|
||||||
|
29 => 'Shipping Code',
|
||||||
|
30 => 'Shipping Phone',
|
||||||
|
31 => 'Shipping Fax',
|
||||||
|
32 => 'Skype Identity',
|
||||||
|
33 => 'Facebook',
|
||||||
|
34 => 'Twitter',
|
||||||
|
35 => 'Department',
|
||||||
|
36 => 'Designation',
|
||||||
|
37 => 'Price List',
|
||||||
|
38 => 'Payment Terms',
|
||||||
|
39 => 'Payment Terms Label',
|
||||||
|
40 => 'Last Sync Time',
|
||||||
|
41 => 'Owner Name',
|
||||||
|
42 => 'EmailID',
|
||||||
|
43 => 'MobilePhone',
|
||||||
|
44 => 'Customer ID',
|
||||||
|
45 => 'Customer Name',
|
||||||
|
46 => 'Contact Type',
|
||||||
|
47 => 'Customer Address ID',
|
||||||
|
48 => 'Source',
|
||||||
|
49 => 'Reference ID',
|
||||||
|
50 => 'Payment Reminder',
|
||||||
|
];
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'hash' => $hash,
|
||||||
|
'column_map' => ['client' => ['mapping' => $column_map]],
|
||||||
|
'skip_header' => true,
|
||||||
|
'import_type' => 'zoho',
|
||||||
|
];
|
||||||
|
|
||||||
|
Cache::put($hash . '-client', base64_encode($csv), 360);
|
||||||
|
|
||||||
|
$csv_importer = new Zoho($data, $this->company);
|
||||||
|
|
||||||
|
$count = $csv_importer->import('client');
|
||||||
|
|
||||||
|
//now import the invoices
|
||||||
|
|
||||||
|
$csv = file_get_contents(
|
||||||
|
base_path() . '/tests/Feature/Import/zoho_invoices.csv'
|
||||||
|
);
|
||||||
|
$hash = Str::random(32);
|
||||||
|
|
||||||
|
$column_map = [
|
||||||
|
0 => 'Invoice Date',
|
||||||
|
1 => 'Invoice ID',
|
||||||
|
2 => 'Invoice Number',
|
||||||
|
3 => 'Estimate Number',
|
||||||
|
4 => 'Invoice Status',
|
||||||
|
5 => 'Customer Name',
|
||||||
|
6 => 'Company Name',
|
||||||
|
7 => 'Customer ID',
|
||||||
|
8 => 'Branch ID',
|
||||||
|
9 => 'Branch Name',
|
||||||
|
10 => 'Due Date',
|
||||||
|
11 => 'Expected Payment Date',
|
||||||
|
12 => 'PurchaseOrder',
|
||||||
|
13 => 'Template Name',
|
||||||
|
14 => 'Currency Code',
|
||||||
|
15 => 'Exchange Rate',
|
||||||
|
16 => 'Discount Type',
|
||||||
|
17 => 'Is Discount Before Tax',
|
||||||
|
18 => 'Entity Discount Percent',
|
||||||
|
19 => 'Entity Discount Amount',
|
||||||
|
20 => 'Item Name',
|
||||||
|
21 => 'Item Desc',
|
||||||
|
22 => 'Quantity',
|
||||||
|
23 => 'Usage unit',
|
||||||
|
24 => 'Item Price',
|
||||||
|
25 => 'Discount',
|
||||||
|
26 => 'Discount Amount',
|
||||||
|
27 => 'Expense Reference ID',
|
||||||
|
28 => 'Project ID',
|
||||||
|
29 => 'Project Name',
|
||||||
|
30 => 'Item Total',
|
||||||
|
31 => 'SubTotal',
|
||||||
|
32 => 'Total',
|
||||||
|
33 => 'Balance',
|
||||||
|
34 => 'Shipping Charge',
|
||||||
|
35 => 'Adjustment',
|
||||||
|
36 => 'Adjustment Description',
|
||||||
|
37 => 'Round Off',
|
||||||
|
38 => 'Sales person',
|
||||||
|
39 => 'Payment Terms',
|
||||||
|
40 => 'Payment Terms Label',
|
||||||
|
41 => 'Last Payment Date',
|
||||||
|
42 => 'Notes',
|
||||||
|
43 => 'Terms & Conditions',
|
||||||
|
44 => 'Subject',
|
||||||
|
45 => 'LateFee Name',
|
||||||
|
46 => 'LateFee Type',
|
||||||
|
47 => 'LateFee Rate',
|
||||||
|
48 => 'LateFee Amount',
|
||||||
|
49 => 'LateFee Frequency',
|
||||||
|
50 => 'WriteOff Date',
|
||||||
|
51 => 'WriteOff Exchange Rate',
|
||||||
|
52 => 'WriteOff Amount',
|
||||||
|
53 => 'Recurrence Name',
|
||||||
|
54 => 'PayPal',
|
||||||
|
55 => 'Authorize.Net',
|
||||||
|
56 => 'Google Checkout',
|
||||||
|
57 => 'Payflow Pro',
|
||||||
|
58 => 'Stripe',
|
||||||
|
59 => '2Checkout',
|
||||||
|
60 => 'Braintree',
|
||||||
|
61 => 'Forte',
|
||||||
|
62 => 'WorldPay',
|
||||||
|
63 => 'Payments Pro',
|
||||||
|
64 => 'Square',
|
||||||
|
65 => 'WePay',
|
||||||
|
66 => 'Razorpay',
|
||||||
|
67 => 'GoCardless',
|
||||||
|
68 => 'Partial Payments',
|
||||||
|
69 => 'Billing Address',
|
||||||
|
70 => 'Billing City',
|
||||||
|
71 => 'Billing State',
|
||||||
|
72 => 'Billing Country',
|
||||||
|
73 => 'Billing Code',
|
||||||
|
74 => 'Billing Fax',
|
||||||
|
75 => 'Billing Phone',
|
||||||
|
76 => 'Shipping Address',
|
||||||
|
77 => 'Shipping City',
|
||||||
|
78 => 'Shipping State',
|
||||||
|
79 => 'Shipping Country',
|
||||||
|
80 => 'Shipping Code',
|
||||||
|
81 => 'Shipping Fax',
|
||||||
|
82 => 'Shipping Phone Number',
|
||||||
|
];
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'hash' => $hash,
|
||||||
|
'column_map' => ['invoice' => ['mapping' => $column_map]],
|
||||||
|
'skip_header' => true,
|
||||||
|
'import_type' => 'zoho',
|
||||||
|
];
|
||||||
|
|
||||||
|
Cache::put($hash . '-invoice', base64_encode($csv), 360);
|
||||||
|
|
||||||
|
$csv_importer = new Zoho($data, $this->company);
|
||||||
|
|
||||||
|
$count = $csv_importer->import('invoice');
|
||||||
|
|
||||||
|
$base_transformer = new BaseTransformer($this->company);
|
||||||
|
|
||||||
|
$this->assertTrue($base_transformer->hasInvoice("INV-000001"));
|
||||||
|
$this->assertTrue($base_transformer->hasInvoice("INV-000002"));
|
||||||
|
$this->assertTrue($base_transformer->hasInvoice("INV-000003"));
|
||||||
|
|
||||||
|
$invoice_id = $base_transformer->getInvoiceId("INV-000003");
|
||||||
|
$invoice = Invoice::find($invoice_id);
|
||||||
|
|
||||||
|
$this->assertEquals(390 , $invoice->amount);
|
||||||
|
$this->assertEquals(1 , $invoice->status_id);
|
||||||
|
$this->assertEquals(0 , $invoice->balance);
|
||||||
|
$this->assertEquals(4 , count($invoice->line_items));
|
||||||
|
|
||||||
|
$this->assertFalse($invoice->payments()->exists());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user