Improvements for Wave imports

This commit is contained in:
David Bomba 2024-07-24 14:01:46 +10:00
parent d6a4f4b4ca
commit 210a25b9ba
4 changed files with 25 additions and 14 deletions

View File

@ -85,7 +85,7 @@ class ImportController extends Controller
$contents = $this->convertEncoding($contents);
// Store the csv in cache with an expiry of 10 minutes
Cache::put($hash.'-'.$entityType, base64_encode($contents), 600);
Cache::put($hash.'-'.$entityType, base64_encode($contents), 1200);
// Parse CSV
$csv_array = $this->getCsvData($contents);

View File

@ -98,7 +98,7 @@ class BaseImport
}
/** @var string $base64_encoded_csv */
$base64_encoded_csv = Cache::pull($this->hash.'-'.$entity_type);
$base64_encoded_csv = Cache::get($this->hash.'-'.$entity_type);
if (empty($base64_encoded_csv)) {
return null;

View File

@ -172,7 +172,7 @@ class Wave extends BaseImport implements ImportInterface
{
$entity_type = 'expense';
$data = $this->getCsvData($entity_type);
$data = $this->getCsvData('invoice');
if (!$data) {
$this->entity_count['expense'] = 0;
@ -244,14 +244,17 @@ class Wave extends BaseImport implements ImportInterface
if (empty($expense_data['vendor_id'])) {
$vendor_data['user_id'] = $this->getUserIDForRecord($expense_data);
$vendor_repository->save(
['name' => $raw_expense['Vendor Name']],
$vendor = VendorFactory::create(
$this->company->id,
$vendor_data['user_id']
)
);
$expense_data['vendor_id'] = $vendor->id;
if(isset($raw_expense['Vendor Name']) || isset($raw_expense['Vendor']))
{
$vendor_repository->save(
['name' => isset($raw_expense['Vendor Name']) ? $raw_expense['Vendor Name'] : isset($raw_expense['Vendor'])],
$vendor = VendorFactory::create(
$this->company->id,
$vendor_data['user_id']
)
);
$expense_data['vendor_id'] = $vendor->id;
}
}
$validator = Validator::make(

View File

@ -36,18 +36,26 @@ class ExpenseTransformer extends BaseTransformer
$total_tax += floatval($record['Sales Tax Amount']);
}
$tax_rate = round(($total_tax / $amount) * 100, 3);
$tax_rate = $total_tax > 0 ? round(($total_tax / $amount) * 100, 3) : 0;
if(isset($data['Notes / Memo']) && strlen($data['Notes / Memo']) > 1)
$public_notes = $data['Notes / Memo'];
elseif (isset($data['Transaction Description']) && strlen($data['Transaction Description']) > 1)
$public_notes = $data['Transaction Description'];
else
$public_notes = '';
$transformed = [
'company_id' => $this->company->id,
'vendor_id' => $this->getVendorIdOrCreate($this->getString($data, 'Vendor')),
'number' => $this->getString($data, 'Bill Number'),
'public_notes' => $this->getString($data, 'Notes / Memo'),
'public_notes' => $public_notes,
'date' => $this->parseDate($data['Transaction Date Added']) ?: now()->format('Y-m-d'), //27-01-2022
'currency_id' => $this->company->settings->currency_id,
'category_id' => $this->getOrCreateExpenseCategry($data['Account Name']),
'amount' => $amount,
'tax_name1' => $data['Sales Tax Name'],
'tax_name1' => isset($data['Sales Tax Name']) ? $data['Sales Tax Name'] : '',
'tax_rate1' => $tax_rate,
];