Refactor date parsing in importes

This commit is contained in:
David Bomba 2024-05-05 07:36:54 +10:00
parent e374b12fb4
commit 526d86c5a3
11 changed files with 26 additions and 47 deletions

View File

@ -208,7 +208,7 @@ class CheckData extends Command
->cursor()
->each(function ($client) {
if ($client->recurring_invoices()->where('is_deleted', 0)->where('deleted_at', null)->count() > 1) {
$this->logMessage("Duplicate Recurring Invoice => {$client->custom_value1}");
$this->logMessage("Duplicate Recurring Invoice => {$client->custom_value1} || {$client->id}}");
}
});
}

View File

@ -42,7 +42,7 @@ class ExpenseTransformer extends BaseTransformer
'client_id' => isset($data['expense.client'])
? $this->getClientId($data['expense.client'])
: null,
'date' => strlen($this->getString($data, 'expense.date') > 1) ? date('Y-m-d', strtotime(str_replace("/", "-", $data['expense.date']))) : now()->format('Y-m-d'),
'date' => strlen($this->getString($data, 'expense.date') > 1) ? $this->parseDate($data['expense.date']) : now()->format('Y-m-d'),
'public_notes' => $this->getString($data, 'expense.public_notes'),
'private_notes' => $this->getString($data, 'expense.private_notes'),
'category_id' => isset($data['expense.category'])
@ -55,7 +55,7 @@ class ExpenseTransformer extends BaseTransformer
? $this->getPaymentTypeId($data['expense.payment_type'])
: null,
'payment_date' => isset($data['expense.payment_date'])
? date('Y-m-d', strtotime(str_replace("/", "-", $data['expense.payment_date'])))
? $this->parseDate($data['expense.payment_date'])
: null,
'custom_value1' => $this->getString($data, 'expense.custom_value1'),
'custom_value2' => $this->getString($data, 'expense.custom_value2'),

View File

@ -94,10 +94,7 @@ class InvoiceTransformer extends BaseTransformer
),
'footer' => $this->getString($invoice_data, 'invoice.footer'),
'partial' => $this->getFloat($invoice_data, 'invoice.partial') > 0 ?: null,
'partial_due_date' => $this->getString(
$invoice_data,
'invoice.partial_due_date'
),
'partial_due_date' => isset($invoice_data['invoice.partial_due_date']) ? $this->parseDate($invoice_data['invoice.partial_due_date']) : null,
'custom_surcharge1' => $this->getFloat(
$invoice_data,
'invoice.custom_surcharge1'

View File

@ -56,10 +56,10 @@ class QuoteTransformer extends BaseTransformer
'discount' => $this->getFloat($quote_data, 'quote.discount'),
'po_number' => $this->getString($quote_data, 'quote.po_number'),
'date' => isset($quote_data['quote.date'])
? date('Y-m-d', strtotime(str_replace("/", "-", $quote_data['quote.date'])))
? $this->parseDate($quote_data['quote.date'])
: now()->format('Y-m-d'),
'due_date' => isset($quote_data['quote.due_date'])
? date('Y-m-d', strtotime(str_replace("/", "-", $quote_data['quote.due_date'])))
? $this->parseDate($quote_data['quote.due_date'])
: null,
'terms' => $this->getString($quote_data, 'quote.terms'),
'public_notes' => $this->getString(
@ -94,10 +94,7 @@ class QuoteTransformer extends BaseTransformer
),
'footer' => $this->getString($quote_data, 'quote.footer'),
'partial' => $this->getFloat($quote_data, 'quote.partial'),
'partial_due_date' => $this->getString(
$quote_data,
'quote.partial_due_date'
),
'partial_due_date' => isset($invoice_data['quote.partial_due_date']) ? $this->parseDate($quote_data['quote.partial_due_date']) : null,
'custom_surcharge1' => $this->getString(
$quote_data,
'quote.custom_surcharge1'
@ -139,10 +136,7 @@ class QuoteTransformer extends BaseTransformer
$transformed['payments'] = [
[
'date' => isset($quote_data['payment.date'])
? date(
'Y-m-d',
strtotime($quote_data['payment.date'])
)
? $this->parseDate($quote_data['payment.date'])
: date('y-m-d'),
'transaction_reference' => $this->getString(
$quote_data,
@ -158,10 +152,7 @@ class QuoteTransformer extends BaseTransformer
$transformed['payments'] = [
[
'date' => isset($quote_data['payment.date'])
? date(
'Y-m-d',
strtotime($quote_data['payment.date'])
)
? $this->parseDate($quote_data['payment.date'])
: date('y-m-d'),
'transaction_reference' => $this->getString(
$quote_data,
@ -181,10 +172,7 @@ class QuoteTransformer extends BaseTransformer
$transformed['payments'] = [
[
'date' => isset($quote_data['payment.date'])
? date(
'Y-m-d',
strtotime($quote_data['payment.date'])
)
? $this->parseDate($quote_data['payment.date'])
: date('y-m-d'),
'transaction_reference' => $this->getString(
$quote_data,

View File

@ -65,9 +65,7 @@ class RecurringInvoiceTransformer extends BaseTransformer
'next_send_date_client' => isset($invoice_data['invoice.next_send_date'])
? $this->parseDate($invoice_data['invoice.next_send_date'])
: now()->format('Y-m-d'),
'due_date' => isset($invoice_data['invoice.due_date'])
? $this->parseDate($invoice_data['invoice.due_date'])
: null,
'due_date' => isset($invoice_data['invoice.due_date']) ? $this->parseDate($invoice_data['invoice.due_date']) : null,
'terms' => $this->getString($invoice_data, 'invoice.terms'),
'due_date_days' => 'terms',
'public_notes' => $this->getString(
@ -102,10 +100,7 @@ class RecurringInvoiceTransformer extends BaseTransformer
),
'footer' => $this->getString($invoice_data, 'invoice.footer'),
'partial' => $this->getFloat($invoice_data, 'invoice.partial') > 0 ?: null,
'partial_due_date' => $this->getString(
$invoice_data,
'invoice.partial_due_date'
),
'partial_due_date' => isset($invoice_data['invoice.partial_due_date']) ? $this->parseDate($invoice_data['invoice.partial_due_date']) : null,
'custom_surcharge1' => $this->getString(
$invoice_data,
'invoice.custom_surcharge1'

View File

@ -42,8 +42,7 @@ class InvoiceTransformer extends BaseTransformer
'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' ),
'date' => isset($invoice_data['Date Issued']) ? $this->parseDate($invoice_data['Date Issued']) : null,
'amount' => 0,
'status_id' => $invoiceStatusMap[$status =
strtolower($this->getString($invoice_data, 'Invoice Status'))] ?? Invoice::STATUS_SENT,
@ -70,7 +69,7 @@ class InvoiceTransformer extends BaseTransformer
if (! empty($invoice_data['Date Paid'])) {
$transformed['payments'] = [[
'date' => date('Y-m-d', strtotime($invoice_data['Date Paid'])),
'date' => $this->parseDate($invoice_data['Date Paid']),
'amount' => $transformed['amount'],
]];
}

View File

@ -45,7 +45,7 @@ class InvoiceTransformer extends BaseTransformer
'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,
'date' => isset($invoice_data['DocumentDate']) ? $this->parseDate($invoice_data['DocumentDate']) : null,
// 'currency_id' => $this->getCurrencyByCode( $invoice_data, 'Currency' ),
'amount' => $this->getFloat($invoice_data, 'TotalAmount'),
'status_id' => $invoiceStatusMap[$status =
@ -92,7 +92,7 @@ class InvoiceTransformer extends BaseTransformer
if (! empty($invoice_data['Date Paid'])) {
$transformed['payments'] = [
[
'date' => date('Y-m-d', strtotime($invoice_data['DatePaid'])),
'date' => $this->parseDate($invoice_data['DatePaid']),
'amount' => $this->getFloat($invoice_data, 'Payments'),
],
];

View File

@ -35,8 +35,8 @@ class InvoiceTransformer extends BaseTransformer
'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,
'date' => isset($data['Date']) ? $this->parseDate($data['Date']) : null,
'due_date' => isset($data['Due']) ? $this->parseDate($data['Due']) : null,
'status_id' => Invoice::STATUS_SENT,
'line_items' => [
[

View File

@ -43,7 +43,7 @@ class ExpenseTransformer extends BaseTransformer
'vendor_id' => $this->getVendorIdOrCreate($this->getString($data, 'Vendor')),
'number' => $this->getString($data, 'Bill Number'),
'public_notes' => $this->getString($data, 'Notes / Memo'),
'date' => date('Y-m-d', strtotime($data['Transaction Date Added'])) ?: now()->format('Y-m-d'), //27-01-2022
'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,

View File

@ -49,10 +49,10 @@ class InvoiceTransformer extends BaseTransformer
'company_id' => $this->company->id,
'client_id' => $this->getClient($customer_name = $this->getString($invoice_data, $customer_key), null),
'number' => $invoice_number = $this->getString($invoice_data, 'Invoice Number'),
'date' => date('Y-m-d', strtotime($invoice_data[$date_key])) ?: now()->format('Y-m-d'), //27-01-2022
'date' => $this->parseDate($invoice_data[$date_key]) ?: now()->format('Y-m-d'), //27-01-2022
'currency_id' => $this->getCurrencyByCode($invoice_data, 'Currency'),
'status_id' => Invoice::STATUS_SENT,
'due_date' => array_key_exists('Due Date', $invoice_data) ? date('Y-m-d', strtotime($invoice_data['Due Date'])) : null,
'due_date' => array_key_exists('Due Date', $invoice_data) ? $this->parseDate($invoice_data['Due Date']) : null,
];
$line_items = [];
@ -81,7 +81,7 @@ class InvoiceTransformer extends BaseTransformer
} elseif (array_key_exists('Account Type', $record) && $record['Account Type'] === 'System Receivable Invoice') {
// This is a payment
$payments[] = [
'date' => date('Y-m-d', strtotime($invoice_data[$date_key])),
'date' => $this->parseDate($invoice_data[$date_key]),
'amount' => $this->getFloat($record, 'Amount (One column)'),
];
} else {
@ -103,7 +103,7 @@ class InvoiceTransformer extends BaseTransformer
if (array_key_exists('Invoice Paid', $record) && $record['Invoice Paid'] > 0) {
$payments[] = [
'date' => date('Y-m-d', strtotime($record['Last Payment Date'])),
'date' => $this->parseDate($record['Last Payment Date']),
'amount' => $this->getFloat($record, 'Invoice Paid'),
];
}

View File

@ -43,8 +43,8 @@ class InvoiceTransformer extends BaseTransformer
// 'client_id' => $this->getClient($this->getString($invoice_data, 'Customer ID'), $this->getString($invoice_data, 'Primary Contact EmailID')),
'client_id' => $this->harvestClient($invoice_data),
'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,
'date' => isset($invoice_data['Invoice Date']) ? $this->parseDate($invoice_data['Invoice Date']) : null,
'due_date' => isset($invoice_data['Due Date']) ? $this->parseDate($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'),
@ -74,7 +74,7 @@ class InvoiceTransformer extends BaseTransformer
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'),
'date' => isset($invoice_data['Last Payment Date']) ? $this->parseDate($invoice_data['Invoice Date']) : date('Y-m-d'),
'amount' => $transformed['amount'] - $transformed['balance'],
]];
}