diff --git a/app/Console/Commands/CheckData.php b/app/Console/Commands/CheckData.php index 0b7128dc78f8..70458bf8c5ca 100644 --- a/app/Console/Commands/CheckData.php +++ b/app/Console/Commands/CheckData.php @@ -814,7 +814,7 @@ ORDER BY clients.id; { $client = Client::withTrashed()->find($_client->id); - $invoice_balance = $client->invoices()->where('is_deleted', false)->where('status_id', '>', 1)->sum('balance'); + $invoice_balance = $client->invoices()->where('is_deleted', false)->whereIn('status_id', [2,3])->sum('balance'); $ledger = CompanyLedger::where('client_id', $client->id)->orderBy('id', 'DESC')->first(); @@ -850,7 +850,7 @@ ORDER BY clients.id; $this->wrong_paid_to_dates = 0; foreach (Client::where('is_deleted', 0)->where('clients.updated_at', '>', now()->subDays(2))->cursor() as $client) { - $invoice_balance = $client->invoices()->where('is_deleted', false)->where('status_id', '>', 1)->sum('balance'); + $invoice_balance = $client->invoices()->where('is_deleted', false)->whereIn('status_id', [2,3])->sum('balance'); $ledger = CompanyLedger::where('client_id', $client->id)->orderBy('id', 'DESC')->first(); if ($ledger && number_format($ledger->balance, 4) != number_format($client->balance, 4)) { diff --git a/app/Export/CSV/BaseExport.php b/app/Export/CSV/BaseExport.php index 3188ad2a8557..b82d43a32134 100644 --- a/app/Export/CSV/BaseExport.php +++ b/app/Export/CSV/BaseExport.php @@ -72,6 +72,12 @@ class BaseExport foreach($this->input['report_keys'] as $value){ $key = array_search ($value, $this->entity_keys); + $key = str_replace("item.", "", $key); + $key = str_replace("invoice.", "", $key); + $key = str_replace("client.", "", $key); + $key = str_replace("contact.", "", $key); + + $header[] = ctrans("texts.{$key}"); } diff --git a/app/Export/CSV/ClientExport.php b/app/Export/CSV/ClientExport.php index da4f0011c404..783bd73274eb 100644 --- a/app/Export/CSV/ClientExport.php +++ b/app/Export/CSV/ClientExport.php @@ -78,6 +78,46 @@ class ClientExport extends BaseExport 'email' => 'contact.email', ]; + protected array $all_keys = [ + 'client.address1', + 'client.address2', + 'client.balance', + 'client.city', + 'client.country_id', + 'client.credit_balance', + 'client.custom_value1', + 'client.custom_value2', + 'client.custom_value3', + 'client.custom_value4', + 'client.id_number', + 'client.industry_id', + 'client.last_login', + 'client.name', + 'client.number', + 'client.paid_to_date', + 'client.phone', + 'client.postal_code', + 'client.private_notes', + 'client.public_notes', + 'client.shipping_address1', + 'client.shipping_address2', + 'client.shipping_city', + 'client.shipping_country_id', + 'client.shipping_postal_code', + 'client.shipping_state', + 'client.state', + 'client.vat_number', + 'client.website', + // 'client.currency', + 'contact.first_name', + 'contact.last_name', + 'contact.phone', + 'contact.custom_value1', + 'contact.custom_value2', + 'contact.custom_value3', + 'contact.custom_value4', + 'contact.email', + ]; private array $decorate_keys = [ 'client.country_id', 'client.shipping_country_id', @@ -105,6 +145,9 @@ class ClientExport extends BaseExport //load the CSV document from a string $this->csv = Writer::createFromString(); + if(count($this->input['report_keys']) == 0) + $this->input['report_keys'] = $this->all_keys; + //insert the header $this->csv->insertOne($this->buildHeader()); diff --git a/app/Export/CSV/ContactExport.php b/app/Export/CSV/ContactExport.php index d3f95822b998..8e5030b4b551 100644 --- a/app/Export/CSV/ContactExport.php +++ b/app/Export/CSV/ContactExport.php @@ -74,6 +74,49 @@ class ContactExport extends BaseExport 'email' => 'contact.email', ]; + + protected array $all_keys = [ + 'client.address1', + 'client.address2', + 'client.balance', + 'client.city', + 'client.country_id', + 'client.credit_balance', + 'client.custom_value1', + 'client.custom_value2', + 'client.custom_value3', + 'client.custom_value4', + 'client.id_number', + 'client.industry_id', + 'client.last_login', + 'client.name', + 'client.number', + 'client.paid_to_date', + 'client.phone', + 'client.postal_code', + 'client.private_notes', + 'client.public_notes', + 'client.shipping_address1', + 'client.shipping_address2', + 'client.shipping_city', + 'client.shipping_country_id', + 'client.shipping_postal_code', + 'client.shipping_state', + 'client.state', + 'client.vat_number', + 'client.website', + 'client.currency', + 'contact.first_name', + 'contact.last_name', + 'contact.phone', + 'contact.custom_value1', + 'contact.custom_value2', + 'contact.custom_value3', + 'contact.custom_value4', + 'contact.email', + ]; + + private array $decorate_keys = [ 'client.country_id', 'client.shipping_country_id', @@ -101,6 +144,9 @@ class ContactExport extends BaseExport //load the CSV document from a string $this->csv = Writer::createFromString(); + if(count($this->input['report_keys']) == 0) + $this->input['report_keys'] = $this->all_keys; + //insert the header $this->csv->insertOne($this->buildHeader()); @@ -115,7 +161,6 @@ class ContactExport extends BaseExport }); - return $this->csv->toString(); } diff --git a/app/Export/CSV/CreditExport.php b/app/Export/CSV/CreditExport.php index 13ab31ca71da..72dbebc4f470 100644 --- a/app/Export/CSV/CreditExport.php +++ b/app/Export/CSV/CreditExport.php @@ -68,6 +68,45 @@ class CreditExport extends BaseExport 'currency' => 'currency' ]; + protected array $all_keys = [ + 'amount', + 'balance', + 'client_id', + 'custom_surcharge1', + 'custom_surcharge2', + 'custom_surcharge3', + 'custom_surcharge4', + 'country_id', + 'custom_value1', + 'custom_value2', + 'custom_value3', + 'custom_value4', + 'date', + 'discount', + 'due_date', + 'exchange_rate', + 'footer', + 'invoice_id', + 'number', + 'paid_to_date', + 'partial', + 'partial_due_date', + 'po_number', + 'private_notes', + 'public_notes', + 'status_id', + 'tax_name1', + 'tax_name2', + 'tax_name3', + 'tax_rate1', + 'tax_rate2', + 'tax_rate3', + 'terms', + 'total_taxes', + 'currency' + ]; + + private array $decorate_keys = [ 'country', 'client', @@ -97,6 +136,9 @@ class CreditExport extends BaseExport //insert the header $this->csv->insertOne($this->buildHeader()); + if(count($this->input['report_keys']) == 0) + $this->input['report_keys'] = $this->all_keys; + $query = Credit::query() ->withTrashed() ->with('client')->where('company_id', $this->company->id) diff --git a/app/Export/CSV/DocumentExport.php b/app/Export/CSV/DocumentExport.php index 74bb8149d571..a782bc1151b1 100644 --- a/app/Export/CSV/DocumentExport.php +++ b/app/Export/CSV/DocumentExport.php @@ -39,6 +39,14 @@ class DocumentExport extends BaseExport 'created_at' => 'created_at', ]; + protected array $all_keys = [ + 'record_type', + 'record_name', + 'name', + 'type', + 'created_at', + ]; + private array $decorate_keys = [ ]; @@ -62,6 +70,9 @@ class DocumentExport extends BaseExport //load the CSV document from a string $this->csv = Writer::createFromString(); + if(count($this->input['report_keys']) == 0) + $this->input['report_keys'] = $this->all_keys; + //insert the header $this->csv->insertOne($this->buildHeader()); diff --git a/app/Export/CSV/ExpenseExport.php b/app/Export/CSV/ExpenseExport.php index c7b0bb36179a..6d202556ade9 100644 --- a/app/Export/CSV/ExpenseExport.php +++ b/app/Export/CSV/ExpenseExport.php @@ -63,6 +63,40 @@ class ExpenseExport extends BaseExport 'invoice' => 'invoice_id', ]; + protected array $all_keys = [ + 'amount', + 'category_id', + 'client_id', + 'custom_value1', + 'custom_value2', + 'custom_value3', + 'custom_value4', + 'currency_id', + 'date', + 'exchange_rate', + 'foreign_amount', + 'invoice_currency_id', + 'payment_date', + 'number', + 'payment_type_id', + 'private_notes', + 'project_id', + 'public_notes', + 'tax_amount1', + 'tax_amount2', + 'tax_amount3', + 'tax_name1', + 'tax_name2', + 'tax_name3', + 'tax_rate1', + 'tax_rate2', + 'tax_rate3', + 'transaction_reference', + 'vendor_id', + 'invoice_id', + ]; + + private array $decorate_keys = [ 'client', 'currency', @@ -92,6 +126,9 @@ class ExpenseExport extends BaseExport //load the CSV document from a string $this->csv = Writer::createFromString(); + if(count($this->input['report_keys']) == 0) + $this->input['report_keys'] = $this->all_keys; + //insert the header $this->csv->insertOne($this->buildHeader()); diff --git a/app/Export/CSV/InvoiceExport.php b/app/Export/CSV/InvoiceExport.php index 9ee104dee8d6..cae539d566b6 100644 --- a/app/Export/CSV/InvoiceExport.php +++ b/app/Export/CSV/InvoiceExport.php @@ -66,6 +66,43 @@ class InvoiceExport extends BaseExport 'currency' => 'client_id' ]; + + protected array $all_keys = [ + 'amount', + 'balance', + 'client_id', + 'custom_surcharge1', + 'custom_surcharge2', + 'custom_surcharge3', + 'custom_surcharge4', + 'custom_value1', + 'custom_value2', + 'custom_value3', + 'custom_value4', + 'date', + 'discount', + 'due_date', + 'exchange_rate', + 'footer', + 'number', + 'paid_to_date', + 'partial', + 'partial_due_date', + 'po_number', + 'private_notes', + 'public_notes', + 'status_id', + 'tax_name1', + 'tax_name2', + 'tax_name3', + 'tax_rate1', + 'tax_rate2', + 'tax_rate3', + 'terms', + 'total_taxes', + 'client_id' + ]; + private array $decorate_keys = [ 'country', 'client', @@ -92,6 +129,9 @@ class InvoiceExport extends BaseExport //load the CSV document from a string $this->csv = Writer::createFromString(); + if(count($this->input['report_keys']) == 0) + $this->input['report_keys'] = $this->all_keys; + //insert the header $this->csv->insertOne($this->buildHeader()); diff --git a/app/Export/CSV/InvoiceItemExport.php b/app/Export/CSV/InvoiceItemExport.php index 6c060788a9d2..a70cf3328065 100644 --- a/app/Export/CSV/InvoiceItemExport.php +++ b/app/Export/CSV/InvoiceItemExport.php @@ -85,6 +85,61 @@ class InvoiceItemExport extends BaseExport 'invoice4' => 'item.custom_value4', ]; + protected array $all_keys = [ + 'amount', + 'balance', + 'client_id', + 'custom_surcharge1', + 'custom_surcharge2', + 'custom_surcharge3', + 'custom_surcharge4', + 'custom_value1', + 'custom_value2', + 'custom_value3', + 'custom_value4', + 'date', + 'discount', + 'due_date', + 'exchange_rate', + 'footer', + 'number', + 'paid_to_date', + 'partial', + 'partial_due_date', + 'po_number', + 'private_notes', + 'public_notes', + 'status_id', + 'tax_name1', + 'tax_name2', + 'tax_name3', + 'tax_rate1', + 'tax_rate2', + 'tax_rate3', + 'terms', + 'total_taxes', + // 'currency_id', + 'item.quantity', + 'item.cost', + 'item.product_key', + 'item.product_cost', + 'item.notes', + 'item.discount', + 'item.is_amount_discount', + 'item.tax_rate1', + 'item.tax_rate2', + 'item.tax_rate3', + 'item.tax_name1', + 'item.tax_name2', + 'item.tax_name3', + 'item.line_total', + 'item.gross_line_total', + 'item.custom_value1', + 'item.custom_value2', + 'item.custom_value3', + 'item.custom_value4', + ]; + private array $decorate_keys = [ 'client', 'currency', @@ -109,6 +164,9 @@ class InvoiceItemExport extends BaseExport //load the CSV document from a string $this->csv = Writer::createFromString(); + if(count($this->input['report_keys']) == 0) + $this->input['report_keys'] = ksort($this->all_keys); + //insert the header $this->csv->insertOne($this->buildHeader()); diff --git a/app/Export/CSV/PaymentExport.php b/app/Export/CSV/PaymentExport.php index 6638a21eec81..86a8d1be9c67 100644 --- a/app/Export/CSV/PaymentExport.php +++ b/app/Export/CSV/PaymentExport.php @@ -54,6 +54,28 @@ class PaymentExport extends BaseExport 'vendor' => 'vendor_id', ]; + protected array $all_keys = [ + 'amount', + 'applied', + 'client_id', + 'currency_id', + 'custom_value1', + 'custom_value2', + 'custom_value3', + 'custom_value4', + 'date', + 'exchange_currency_id', + 'gateway_type_id', + 'number', + 'private_notes', + 'project_id', + 'refunded', + 'status_id', + 'transaction_reference', + 'type_id', + 'vendor_id', + ]; + private array $decorate_keys = [ 'vendor', 'status', @@ -83,6 +105,9 @@ class PaymentExport extends BaseExport //load the CSV document from a string $this->csv = Writer::createFromString(); + if(count($this->input['report_keys']) == 0) + $this->input['report_keys'] = $this->all_keys; + //insert the header $this->csv->insertOne($this->buildHeader()); diff --git a/app/Export/CSV/ProductExport.php b/app/Export/CSV/ProductExport.php index bf4c6b5cf1cd..bf02fd1acd63 100644 --- a/app/Export/CSV/ProductExport.php +++ b/app/Export/CSV/ProductExport.php @@ -52,6 +52,26 @@ class ProductExport extends BaseExport 'tax_name3' => 'tax_name3', ]; + protected array $all_keys = [ + 'project_id', + 'vendor_id', + 'custom_value1', + 'custom_value2', + 'custom_value3', + 'custom_value4', + 'product_key', + 'notes', + 'cost', + 'price', + 'quantity', + 'tax_rate1', + 'tax_rate2', + 'tax_rate3', + 'tax_name1', + 'tax_name2', + 'tax_name3', + ]; + private array $decorate_keys = [ 'vendor', 'project', @@ -76,6 +96,9 @@ class ProductExport extends BaseExport //load the CSV document from a string $this->csv = Writer::createFromString(); + if(count($this->input['report_keys']) == 0) + $this->input['report_keys'] = $this->all_keys; + //insert the header $this->csv->insertOne($this->buildHeader()); diff --git a/app/Export/CSV/QuoteExport.php b/app/Export/CSV/QuoteExport.php index 71eaec9e593c..f4589e1b15e5 100644 --- a/app/Export/CSV/QuoteExport.php +++ b/app/Export/CSV/QuoteExport.php @@ -67,6 +67,44 @@ class QuoteExport extends BaseExport 'invoice' => 'invoice_id', ]; + protected array $all_keys = [ + 'amount', + 'balance', + 'client_id', + 'custom_surcharge1', + 'custom_surcharge2', + 'custom_surcharge3', + 'custom_surcharge4', + 'custom_value1', + 'custom_value2', + 'custom_value3', + 'custom_value4', + 'date', + 'discount', + 'due_date', + 'exchange_rate', + 'footer', + 'number', + 'paid_to_date', + 'partial', + 'partial_due_date', + 'po_number', + 'private_notes', + 'public_notes', + 'status_id', + 'tax_name1', + 'tax_name2', + 'tax_name3', + 'tax_rate1', + 'tax_rate2', + 'tax_rate3', + 'terms', + 'total_taxes', + 'client_id', + 'invoice_id', + ]; + + private array $decorate_keys = [ 'client', 'currency', @@ -92,6 +130,9 @@ class QuoteExport extends BaseExport //load the CSV document from a string $this->csv = Writer::createFromString(); + if(count($this->input['report_keys']) == 0) + $this->input['report_keys'] = $this->all_keys; + //insert the header $this->csv->insertOne($this->buildHeader()); diff --git a/app/Export/CSV/QuoteItemExport.php b/app/Export/CSV/QuoteItemExport.php index aa4f15b65579..bb6e499394f0 100644 --- a/app/Export/CSV/QuoteItemExport.php +++ b/app/Export/CSV/QuoteItemExport.php @@ -85,6 +85,61 @@ class QuoteItemExport extends BaseExport 'invoice4' => 'item.custom_value4', ]; + protected array $all_keys = [ + 'amount', + 'balance', + 'client_id', + 'custom_surcharge1', + 'custom_surcharge2', + 'custom_surcharge3', + 'custom_surcharge4', + 'custom_value1', + 'custom_value2', + 'custom_value3', + 'custom_value4', + 'date', + 'discount', + 'due_date', + 'exchange_rate', + 'footer', + 'number', + 'paid_to_date', + 'partial', + 'partial_due_date', + 'po_number', + 'private_notes', + 'public_notes', + 'status_id', + 'tax_name1', + 'tax_name2', + 'tax_name3', + 'tax_rate1', + 'tax_rate2', + 'tax_rate3', + 'terms', + 'total_taxes', + 'currency_id', + 'item.quantity', + 'item.cost', + 'item.product_key', + 'item.product_cost', + 'item.notes', + 'item.discount', + 'item.is_amount_discount', + 'item.tax_rate1', + 'item.tax_rate2', + 'item.tax_rate3', + 'item.tax_name1', + 'item.tax_name2', + 'item.tax_name3', + 'item.line_total', + 'item.gross_line_total', + 'item.custom_value1', + 'item.custom_value2', + 'item.custom_value3', + 'item.custom_value4', + ]; + private array $decorate_keys = [ 'client', 'currency', @@ -109,6 +164,9 @@ class QuoteItemExport extends BaseExport //load the CSV document from a string $this->csv = Writer::createFromString(); + if(count($this->input['report_keys']) == 0) + $this->input['report_keys'] = $this->all_keys; + //insert the header $this->csv->insertOne($this->buildHeader()); diff --git a/app/Export/CSV/RecurringInvoiceExport.php b/app/Export/CSV/RecurringInvoiceExport.php index 09e5b1ff142b..81738e80d5d5 100644 --- a/app/Export/CSV/RecurringInvoiceExport.php +++ b/app/Export/CSV/RecurringInvoiceExport.php @@ -68,6 +68,44 @@ class RecurringInvoiceExport extends BaseExport 'project' => 'project_id', ]; + protected array $all_keys = [ + 'amount', + 'balance', + 'client_id', + 'custom_surcharge1', + 'custom_surcharge2', + 'custom_surcharge3', + 'custom_surcharge4', + 'custom_value1', + 'custom_value2', + 'custom_value3', + 'custom_value4', + 'date', + 'discount', + 'due_date', + 'exchange_rate', + 'footer', + 'number', + 'paid_to_date', + 'partial', + 'partial_due_date', + 'po_number', + 'private_notes', + 'public_notes', + 'status_id', + 'tax_name1', + 'tax_name2', + 'tax_name3', + 'tax_rate1', + 'tax_rate2', + 'tax_rate3', + 'terms', + 'total_taxes', + 'client_id', + 'vendor_id', + 'project_id', + ]; + private array $decorate_keys = [ 'country', 'client', @@ -96,6 +134,9 @@ class RecurringInvoiceExport extends BaseExport //load the CSV document from a string $this->csv = Writer::createFromString(); + if(count($this->input['report_keys']) == 0) + $this->input['report_keys'] = $this->all_keys; + //insert the header $this->csv->insertOne($this->buildHeader()); diff --git a/app/Export/CSV/TaskExport.php b/app/Export/CSV/TaskExport.php index fc95b5f8f498..5ccdfa5d54d0 100644 --- a/app/Export/CSV/TaskExport.php +++ b/app/Export/CSV/TaskExport.php @@ -52,6 +52,23 @@ class TaskExport extends BaseExport 'client' => 'client_id', ]; + protected array $all_keys = [ + 'start_date', + 'end_date', + 'duration', + 'rate', + 'number', + 'description', + 'custom_value1', + 'custom_value2', + 'custom_value3', + 'custom_value4', + 'status_id', + 'project_id', + 'invoice_id', + 'client_id', + ]; + private array $decorate_keys = [ 'status', 'project', @@ -83,6 +100,10 @@ class TaskExport extends BaseExport //load the CSV document from a string $this->csv = Writer::createFromString(); + + if(count($this->input['report_keys']) == 0) + $this->input['report_keys'] = $this->all_keys; + //insert the header $this->csv->insertOne($this->buildHeader()); diff --git a/app/Import/Providers/Csv.php b/app/Import/Providers/Csv.php index 5ca64b49a2c1..34c85e241dd9 100644 --- a/app/Import/Providers/Csv.php +++ b/app/Import/Providers/Csv.php @@ -43,6 +43,7 @@ use Symfony\Component\HttpFoundation\ParameterBag; class Csv extends BaseImport implements ImportInterface { + public array $entity_count = []; public function import(string $entity) diff --git a/app/Jobs/Import/CSVIngest.php b/app/Jobs/Import/CSVIngest.php index 3352b76a8c86..6a7c4e0032a5 100644 --- a/app/Jobs/Import/CSVIngest.php +++ b/app/Jobs/Import/CSVIngest.php @@ -69,6 +69,8 @@ class CSVIngest implements ShouldQueue { MultiDB::setDb( $this->company->db ); + set_time_limit(0); + $engine = $this->bootEngine($this->import_type); foreach ( [ 'client', 'product', 'invoice', 'payment', 'vendor', 'expense' ] as $entity ) {