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

View File

@ -54,16 +54,16 @@ class InvoiceTransformer extends BaseTransformer {
$line_items[] = [ $line_items[] = [
'product_key' => $this->getString( $record, 'Item Name' ), 'product_key' => $this->getString( $record, 'Item Name' ),
'notes' => $this->getString( $record, 'Item Description' ), 'notes' => $this->getString( $record, 'Item Description' ),
'cost' => $this->getFloat( $record, 'Rate' ), 'cost' => $this->getFreshbookQuantityFloat( $record, 'Rate' ),
'quantity' => $this->getFloat( $record, 'Quantity' ), 'quantity' => $this->getFreshbookQuantityFloat( $record, 'Quantity' ),
'discount' => $this->getFloat( $record, 'Discount Percentage' ), 'discount' => $this->getFreshbookQuantityFloat( $record, 'Discount Percentage' ),
'is_amount_discount' => false, 'is_amount_discount' => false,
'tax_name1' => $this->getString( $record, 'Tax 1 Type' ), '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_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; $transformed['line_items'] = $line_items;
@ -78,9 +78,9 @@ class InvoiceTransformer extends BaseTransformer {
} }
/** @return float */ /** @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' => [], 'tax_names' => [],
]; ];
$clients = Client::scope()->get(); $clients = Client::where('company_id', $this->company->id)->cursor()->each(function ($client){
foreach ( $clients as $client ) {
$this->addClientToMaps( $client ); $this->addClientToMaps( $client );
} });
$contacts = ClientContact::scope()->get(); $contacts = ClientContact::where('company_id', $this->company->id)->cursor()->each(function ($contact){
foreach ( $contacts as $contact ) {
$this->addContactToMaps( $contact ); $this->addContactToMaps( $contact );
} });
$invoices = Invoice::scope()->get(); $invoices = Invoice::where('company_id', $this->company->id)->cursor()->each(function ($invoice){
foreach ( $invoices as $invoice ) {
$this->addInvoiceToMaps( $invoice ); $this->addInvoiceToMaps( $invoice );
} });
$products = Product::scope()->get(); $products = Product::where('company_id', $this->company->id)->cursor()->each(function ($product){
foreach ( $products as $product ) {
$this->addProductToMaps( $product ); $this->addProductToMaps( $product );
} });
$projects = Project::scope()->get(); $projects = Project::where('company_id', $this->company->id)->cursor()->each(function ($project){
foreach ( $projects as $project ) {
$this->addProjectToMaps( $project ); $this->addProjectToMaps( $project );
} });
$countries = Country::all(); $countries = Country::all();
foreach ( $countries as $country ) { foreach ( $countries as $country ) {
@ -481,17 +476,16 @@ class CSVImport implements ShouldQueue {
$this->maps['payment_types'][ strtolower( $payment_type->name ) ] = $payment_type->id; $this->maps['payment_types'][ strtolower( $payment_type->name ) ] = $payment_type->id;
} }
$vendors = Vendor::scope()->get(); $vendors = Vendor::where('company_id', $this->company->id)->cursor()->each(function ($vendor){
foreach ( $vendors as $vendor ) {
$this->addVendorToMaps( $vendor ); $this->addVendorToMaps( $vendor );
} });
$expenseCaegories = ExpenseCategory::scope()->get(); $expenseCaegories = ExpenseCategory::where('company_id', $this->company->id)->get();
foreach ( $expenseCaegories as $category ) { foreach ( $expenseCaegories as $category ) {
$this->addExpenseCategoryToMaps( $category ); $this->addExpenseCategoryToMaps( $category );
} }
$taxRates = TaxRate::scope()->get(); $taxRates = TaxRate::where('company_id', $this->company->id)->get();
foreach ( $taxRates as $taxRate ) { foreach ( $taxRates as $taxRate ) {
$name = trim( strtolower( $taxRate->name ) ); $name = trim( strtolower( $taxRate->name ) );
$this->maps['tax_rates'][ $name ] = $taxRate->rate; $this->maps['tax_rates'][ $name ] = $taxRate->rate;