1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-13 22:54:25 +01:00

Fixes for freshbooks import

This commit is contained in:
David Bomba 2021-12-11 08:32:24 +11:00
parent 5a98fe3925
commit 0cebfd1f56
3 changed files with 27 additions and 30 deletions

View File

@ -72,7 +72,7 @@ class Kernel extends HttpKernel
ConvertEmptyStringsToNull::class,
TrustProxies::class,
// \Fruitcake\Cors\HandleCors::class,
Cors::class,
// Cors::class,
];
@ -95,6 +95,7 @@ class Kernel extends HttpKernel
'api' => [
'throttle:300,1',
'bindings',
'cors',
'query_logging',
],
'contact' => [
@ -116,6 +117,7 @@ class Kernel extends HttpKernel
'throttle:120,1',
'bindings',
'query_logging',
'cors',
],
];
@ -132,6 +134,7 @@ class Kernel extends HttpKernel
'bindings' => SubstituteBindings::class,
'cache.headers' => SetCacheHeaders::class,
'can' => Authorize::class,
'cors' => Cors::class,
'guest' => RedirectIfAuthenticated::class,
'signed' => ValidateSignature::class,
'throttle' => ThrottleRequests::class,

View File

@ -54,16 +54,16 @@ class InvoiceTransformer extends BaseTransformer {
$line_items[] = [
'product_key' => $this->getString( $record, 'Item Name' ),
'notes' => $this->getString( $record, 'Item Description' ),
'cost' => $this->getFloat( $record, 'Rate' ),
'quantity' => $this->getFloat( $record, 'Quantity' ),
'discount' => $this->getFloat( $record, 'Discount Percentage' ),
'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->getFloat( $record, 'Tax 1 Amount' ),
'tax_rate1' => $this->getFreshbookQuantityFloat( $record, 'Tax 1 Amount' ),
'tax_name2' => $this->getString( $record, 'Tax 2 Type' ),
'tax_rate2' => $this->getFloat( $record, 'Tax 2 Amount' ),
'tax_rate2' => $this->getFreshbookQuantityFloat( $record, 'Tax 2 Amount' ),
];
$transformed['amount'] += $this->getFloat( $record, 'Line Total' );
$transformed['amount'] += $this->getFreshbookQuantityFloat( $record, 'Line Total' );
}
$transformed['line_items'] = $line_items;
@ -78,9 +78,9 @@ class InvoiceTransformer extends BaseTransformer {
}
/** @return float */
public function getFloat($data, $field)
public function getFreshbookQuantityFloat($data, $field)
{
return Number::parseFloat($data[$field]);
return $data[$field];
}
}

View File

@ -440,30 +440,25 @@ class CSVImport implements ShouldQueue {
'tax_names' => [],
];
$clients = Client::scope()->get();
foreach ( $clients as $client ) {
$clients = Client::where('company_id', $this->company->id)->cursor()->each(function ($client){
$this->addClientToMaps( $client );
}
});
$contacts = ClientContact::scope()->get();
foreach ( $contacts as $contact ) {
$contacts = ClientContact::where('company_id', $this->company->id)->cursor()->each(function ($contact){
$this->addContactToMaps( $contact );
}
});
$invoices = Invoice::scope()->get();
foreach ( $invoices as $invoice ) {
$invoices = Invoice::where('company_id', $this->company->id)->cursor()->each(function ($invoice){
$this->addInvoiceToMaps( $invoice );
}
});
$products = Product::scope()->get();
foreach ( $products as $product ) {
$products = Product::where('company_id', $this->company->id)->cursor()->each(function ($product){
$this->addProductToMaps( $product );
}
});
$projects = Project::scope()->get();
foreach ( $projects as $project ) {
$projects = Project::where('company_id', $this->company->id)->cursor()->each(function ($project){
$this->addProjectToMaps( $project );
}
});
$countries = Country::all();
foreach ( $countries as $country ) {
@ -481,17 +476,16 @@ class CSVImport implements ShouldQueue {
$this->maps['payment_types'][ strtolower( $payment_type->name ) ] = $payment_type->id;
}
$vendors = Vendor::scope()->get();
foreach ( $vendors as $vendor ) {
$vendors = Vendor::where('company_id', $this->company->id)->cursor()->each(function ($vendor){
$this->addVendorToMaps( $vendor );
}
});
$expenseCaegories = ExpenseCategory::scope()->get();
$expenseCaegories = ExpenseCategory::where('company_id', $this->company->id)->get();
foreach ( $expenseCaegories as $category ) {
$this->addExpenseCategoryToMaps( $category );
}
$taxRates = TaxRate::scope()->get();
$taxRates = TaxRate::where('company_id', $this->company->id)->get();
foreach ( $taxRates as $taxRate ) {
$name = trim( strtolower( $taxRate->name ) );
$this->maps['tax_rates'][ $name ] = $taxRate->rate;