Skip to content

Commit

Permalink
Merge pull request #8659 from turbo124/v5-stable
Browse files Browse the repository at this point in the history
v5.6.20
  • Loading branch information
turbo124 committed Jul 22, 2023
2 parents 7f9b784 + a385bab commit 45e9c69
Show file tree
Hide file tree
Showing 102 changed files with 333,895 additions and 333,253 deletions.
2 changes: 1 addition & 1 deletion VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.6.19
5.6.20
3 changes: 1 addition & 2 deletions app/Export/CSV/ActivityExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@

class ActivityExport extends BaseExport
{
private Company $company;


private $entity_transformer;

public string $date_key = 'created_at';
Expand Down
138 changes: 127 additions & 11 deletions app/Export/CSV/BaseExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@

use App\Utils\Number;
use App\Models\Client;
use App\Models\Company;
use App\Models\Expense;
use App\Models\Invoice;
use App\Models\GatewayType;
use App\Models\Payment;
use League\Fractal\Manager;
use Illuminate\Support\Carbon;
use App\Utils\Traits\MakesHash;
use App\Transformers\ClientTransformer;
use App\Transformers\TaskTransformer;
use App\Transformers\PaymentTransformer;
use Illuminate\Database\Eloquent\Builder;
use League\Fractal\Serializer\ArraySerializer;
Expand All @@ -29,6 +29,8 @@ class BaseExport
{
use MakesHash;

public Company $company;

public array $input;

public string $date_key = '';
Expand Down Expand Up @@ -136,6 +138,35 @@ class BaseExport
"user" => "invoice.user_id",
];

protected array $recurring_invoice_report_keys = [
"invoice_number" => "recurring_invoice.number",
"amount" => "recurring_invoice.amount",
"balance" => "recurring_invoice.balance",
"paid_to_date" => "recurring_invoice.paid_to_date",
"po_number" => "recurring_invoice.po_number",
"date" => "recurring_invoice.date",
"due_date" => "recurring_invoice.due_date",
"terms" => "recurring_invoice.terms",
"footer" => "recurring_invoice.footer",
"status" => "recurring_invoice.status",
"public_notes" => "recurring_invoice.public_notes",
"private_notes" => "recurring_invoice.private_notes",
"uses_inclusive_taxes" => "recurring_invoice.uses_inclusive_taxes",
"is_amount_discount" => "recurring_invoice.is_amount_discount",
"partial" => "recurring_invoice.partial",
"partial_due_date" => "recurring_invoice.partial_due_date",
"surcharge1" => "recurring_invoice.custom_surcharge1",
"surcharge2" => "recurring_invoice.custom_surcharge2",
"surcharge3" => "recurring_invoice.custom_surcharge3",
"surcharge4" => "recurring_invoice.custom_surcharge4",
"exchange_rate" => "recurring_invoice.exchange_rate",
"tax_amount" => "recurring_invoice.total_taxes",
"assigned_user" => "recurring_invoice.assigned_user_id",
"user" => "recurring_invoice.user_id",
"frequency_id" => "recurring_invoice.frequency_id",
"next_send_date" => "recurring_invoice.next_send_date"
];

protected array $purchase_order_report_keys = [
'amount' => 'purchase_order.amount',
'balance' => 'purchase_order.balance',
Expand Down Expand Up @@ -193,13 +224,17 @@ class BaseExport
];

protected array $quote_report_keys = [
"quote_number" => "quote.number",
'custom_value1' => 'quote.custom_value1',
'custom_value2' => 'quote.custom_value2',
'custom_value3' => 'quote.custom_value3',
'custom_value4' => 'quote.custom_value4',
"number" => "quote.number",
"amount" => "quote.amount",
"balance" => "quote.balance",
"paid_to_date" => "quote.paid_to_date",
"po_number" => "quote.po_number",
"date" => "quote.date",
"due_date" => "quote.due_date",
"valid_until" => "quote.due_date",
"terms" => "quote.terms",
"footer" => "quote.footer",
"status" => "quote.status",
Expand Down Expand Up @@ -314,8 +349,6 @@ class BaseExport
'custom_value4' => 'task.custom_value4',
'status' => 'task.status_id',
'project' => 'task.project_id',
'invoice' => 'task.invoice_id',
'client' => 'task.client_id',
];

protected function filterByClients($query)
Expand Down Expand Up @@ -347,8 +380,11 @@ protected function resolveKey($key, $entity, $transformer) :string
'vendor' => $value = $this->resolveVendorKey($parts[1], $entity, $transformer),
'vendor_contact' => $value = $this->resolveVendorContactKey($parts[1], $entity, $transformer),
'invoice' => $value = $this->resolveInvoiceKey($parts[1], $entity, $transformer),
'recurring_invoice' => $value = $this->resolveInvoiceKey($parts[1], $entity, $transformer),
'quote' => $value = $this->resolveQuoteKey($parts[1], $entity, $transformer),
'purchase_order' => $value = $this->resolvePurchaseOrderKey($parts[1], $entity, $transformer),
'payment' => $value = $this->resolvePaymentKey($parts[1], $entity, $transformer),
'task' => $value = $this->resolveTaskKey($parts[1], $entity, $transformer),
default => $value = ''
};

Expand Down Expand Up @@ -414,6 +450,22 @@ private function resolveExpenseKey($column, $entity, $transformer)

}

private function resolveTaskKey($column, $entity, $transformer)
{
nlog("searching for {$column}");

$transformed_entity = $transformer->transform($entity);

if(array_key_exists($column, $transformed_entity)) {
return $transformed_entity[$column];
}

return '';

}



private function resolveVendorKey($column, $entity, $transformer)
{

Expand Down Expand Up @@ -511,6 +563,20 @@ private function resolvePurchaseOrderKey($column, $entity, $transformer)
return '';
}

private function resolveQuoteKey($column, $entity, $transformer)
{
nlog("searching for {$column}");

$transformed_entity = $transformer->transform($entity);

if(array_key_exists($column, $transformed_entity)) {
return $transformed_entity[$column];
}

return '';

}

private function resolveInvoiceKey($column, $entity, $transformer)
{
nlog("searching for {$column}");
Expand All @@ -537,7 +603,23 @@ private function resolveInvoiceKey($column, $entity, $transformer)

}

$transformed_invoice = $transformer->transform($entity);
if($transformer instanceof TaskTransformer) {
$transformed_invoice = $transformer->includeInvoice($entity);

if(!$transformed_invoice)
return '';

$manager = new Manager();
$manager->setSerializer(new ArraySerializer());
$transformed_invoice = $manager->createData($transformed_invoice)->toArray();

}

if(array_key_exists($column, $transformed_invoice)) {
return $transformed_invoice[$column];
} elseif (array_key_exists(str_replace("invoice.", "", $column), $transformed_invoice)) {
return $transformed_invoice[$column];
}

if($column == 'status')
return $entity->stringStatus($entity->status_id);
Expand Down Expand Up @@ -707,8 +789,27 @@ protected function addDateRange($query)
$this->end_date = now()->startOfDay()->format('Y-m-d');
return $query->whereBetween($this->date_key, [now()->subDays(365), now()])->orderBy($this->date_key, 'ASC');
case 'this_year':
$this->start_date = now()->startOfYear()->format('Y-m-d');
$this->end_date = now()->format('Y-m-d');

$first_month_of_year = $this->company->getSetting('first_month_of_year') ?? 1;
$fin_year_start = now()->createFromDate(now()->year, $first_month_of_year, 1);

if(now()->lt($fin_year_start))
$fin_year_start->subYearNoOverflow();

$this->start_date = $fin_year_start->format('Y-m-d');
$this->end_date = $fin_year_start->copy()->addYear()->subDay()->format('Y-m-d');
return $query->whereBetween($this->date_key, [now()->startOfYear(), now()])->orderBy($this->date_key, 'ASC');
case 'last_year':

$first_month_of_year = $this->company->getSetting('first_month_of_year') ?? 1;
$fin_year_start = now()->createFromDate(now()->year, $first_month_of_year, 1);
$fin_year_start->subYearNoOverflow();

if(now()->subYear()->lt($fin_year_start))
$fin_year_start->subYearNoOverflow();

$this->start_date = $fin_year_start->format('Y-m-d');
$this->end_date = $fin_year_start->copy()->addYear()->subDay()->format('Y-m-d');
return $query->whereBetween($this->date_key, [now()->startOfYear(), now()])->orderBy($this->date_key, 'ASC');
case 'custom':
$this->start_date = $custom_start_date->format('Y-m-d');
Expand Down Expand Up @@ -743,6 +844,11 @@ public function buildHeader() :array
$key = array_search($value, $this->invoice_report_keys);
}

if(!$key) {
$prefix = ctrans('texts.recurring_invoice')." ";
$key = array_search($value, $this->recurring_invoice_report_keys);
}

if(!$key) {
$prefix = ctrans('texts.payment')." ";
$key = array_search($value, $this->payment_report_keys);
Expand Down Expand Up @@ -790,6 +896,7 @@ public function buildHeader() :array

$key = str_replace('item.', '', $key);
$key = str_replace('recurring_invoice.', '', $key);
$key = str_replace('purchase_order.', '', $key);
$key = str_replace('invoice.', '', $key);
$key = str_replace('quote.', '', $key);
$key = str_replace('credit.', '', $key);
Expand All @@ -800,9 +907,18 @@ public function buildHeader() :array
$key = str_replace('payment.', '', $key);
$key = str_replace('expense.', '', $key);

$header[] = "{$prefix}" . ctrans("texts.{$key}");
if(in_array($key, ['quote1','quote2','quote3','quote4','credit1','credit2','credit3','credit4','purchase_order1','purchase_order2','purchase_order3','purchase_order4']))
{
$number = substr($key, -1);
$header[] = ctrans('texts.item') . " ". ctrans("texts.custom_value{$number}");
}
else
{
$header[] = "{$prefix}" . ctrans("texts.{$key}");
}
}
// nlog($header);

// nlog($header);

return $header;
}
Expand Down
6 changes: 2 additions & 4 deletions app/Export/CSV/ClientExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@

class ClientExport extends BaseExport
{
private $company;

private $client_transformer;

private $contact_transformer;
Expand Down Expand Up @@ -172,8 +170,8 @@ private function decorateAdvancedFields(Client $client, array $entity) :array
$entity['shipping_country'] = $client->shipping_country ? ctrans("texts.country_{$client->shipping_country->name}") : '';
}

if (in_array('client.currency', $this->input['report_keys'])) {
$entity['currency'] = $client->currency() ? $client->currency()->code : $client->company->currency()->code;
if (in_array('client.currency_id', $this->input['report_keys'])) {
$entity['client.currency_id'] = $client->currency() ? $client->currency()->code : $client->company->currency()->code;
}

if (in_array('client.industry_id', $this->input['report_keys'])) {
Expand Down
1 change: 0 additions & 1 deletion app/Export/CSV/ContactExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

class ContactExport extends BaseExport
{
private Company $company;

private ClientTransformer $client_transformer;

Expand Down
1 change: 0 additions & 1 deletion app/Export/CSV/CreditExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

class CreditExport extends BaseExport
{
private Company $company;

private CreditTransformer $credit_transformer;

Expand Down
1 change: 0 additions & 1 deletion app/Export/CSV/DocumentExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

class DocumentExport extends BaseExport
{
private Company $company;

private $entity_transformer;

Expand Down
1 change: 0 additions & 1 deletion app/Export/CSV/ExpenseExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

class ExpenseExport extends BaseExport
{
private Company $company;

private $expense_transformer;

Expand Down
2 changes: 0 additions & 2 deletions app/Export/CSV/InvoiceExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@

class InvoiceExport extends BaseExport
{
private Company $company;

private $invoice_transformer;

public string $date_key = 'date';
Expand Down
1 change: 0 additions & 1 deletion app/Export/CSV/InvoiceItemExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

class InvoiceItemExport extends BaseExport
{
private Company $company;

private $invoice_transformer;

Expand Down
2 changes: 0 additions & 2 deletions app/Export/CSV/PaymentExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@

class PaymentExport extends BaseExport
{
private Company $company;

private $entity_transformer;

public string $date_key = 'date';
Expand Down
2 changes: 0 additions & 2 deletions app/Export/CSV/ProductExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@

class ProductExport extends BaseExport
{
private Company $company;

private $entity_transformer;

public string $date_key = 'created_at';
Expand Down
2 changes: 0 additions & 2 deletions app/Export/CSV/ProductSalesExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@

class ProductSalesExport extends BaseExport
{
private Company $company;

public string $date_key = 'created_at';

protected Collection $products;
Expand Down

0 comments on commit 45e9c69

Please sign in to comment.