diff --git a/app/DataMapper/Analytics/EmailSuccess.php b/app/DataMapper/Analytics/EmailSuccess.php index a84514a68503..eef7f75de361 100644 --- a/app/DataMapper/Analytics/EmailSuccess.php +++ b/app/DataMapper/Analytics/EmailSuccess.php @@ -69,8 +69,15 @@ class EmailSuccess extends GenericMixedMetric */ public $string_metric7 = ''; - public function __construct($string_metric7) + /** + * Subject + * @var string + */ + public $string_metric8 = ''; + + public function __construct($string_metric7 = '', $string_metric8 = '') { $this->string_metric7 = $string_metric7; + $this->string_metric8 = $string_metric8; } } diff --git a/app/Filters/CreditFilters.php b/app/Filters/CreditFilters.php index a69daa60ddd4..a4dd3f33bf46 100644 --- a/app/Filters/CreditFilters.php +++ b/app/Filters/CreditFilters.php @@ -48,6 +48,10 @@ class CreditFilters extends QueryFilters $credit_filters[] = Credit::STATUS_DRAFT; } + if (in_array('sent', $status_parameters)) { + $credit_filters[] = Credit::STATUS_SENT; + } + if (in_array('partial', $status_parameters)) { $credit_filters[] = Credit::STATUS_PARTIAL; } @@ -97,6 +101,21 @@ class CreditFilters extends QueryFilters }); } + public function applicable(string $value = ''): Builder + { + if (strlen($value) == 0) { + return $this->builder; + } + + return $this->builder->where(function ($query){ + $query->whereIn('status_id', [Credit::STATUS_SENT, Credit::STATUS_PARTIAL]) + ->where('balance', '>', 0) + ->where(function ($q){ + $q->whereNull('due_date')->orWhere('due_date', '>', now()); + }); + }); + } + public function number(string $number = ''): Builder { if (strlen($number) == 0) { diff --git a/app/Jobs/Mail/NinjaMailerJob.php b/app/Jobs/Mail/NinjaMailerJob.php index a20efd9bf7ac..4ecc5bc456d6 100644 --- a/app/Jobs/Mail/NinjaMailerJob.php +++ b/app/Jobs/Mail/NinjaMailerJob.php @@ -140,7 +140,7 @@ class NinjaMailerJob implements ShouldQueue /* Count the amount of emails sent across all the users accounts */ Cache::increment("email_quota".$this->company->account->key); - LightLogs::create(new EmailSuccess($this->nmo->company->company_key)) + LightLogs::create(new EmailSuccess($this->nmo->company->company_key, $this->nmo->mailable->subject)) ->send(); } catch(\Symfony\Component\Mime\Exception\RfcComplianceException $e) { diff --git a/app/Services/Email/AdminEmail.php b/app/Services/Email/AdminEmail.php index 2a245337fa72..0555cb8afc80 100644 --- a/app/Services/Email/AdminEmail.php +++ b/app/Services/Email/AdminEmail.php @@ -141,7 +141,7 @@ class AdminEmail implements ShouldQueue Cache::increment("email_quota".$this->company->account->key); - LightLogs::create(new EmailSuccess($this->company->company_key)) + LightLogs::create(new EmailSuccess($this->company->company_key, $this->mailable->subject)) ->send(); } catch(\Symfony\Component\Mime\Exception\RfcComplianceException $e) { diff --git a/app/Services/Email/Email.php b/app/Services/Email/Email.php index 1373fb726db6..4427a16759c1 100644 --- a/app/Services/Email/Email.php +++ b/app/Services/Email/Email.php @@ -253,7 +253,7 @@ class Email implements ShouldQueue Cache::increment("email_quota".$this->company->account->key); - LightLogs::create(new EmailSuccess($this->company->company_key)) + LightLogs::create(new EmailSuccess($this->company->company_key, $this->mailable->subject)) ->send(); } catch(\Symfony\Component\Mime\Exception\RfcComplianceException $e) { diff --git a/app/Services/Invoice/GetInvoicePdf.php b/app/Services/Invoice/GetInvoicePdf.php index 736df18c9d26..a520ef6d1430 100644 --- a/app/Services/Invoice/GetInvoicePdf.php +++ b/app/Services/Invoice/GetInvoicePdf.php @@ -18,6 +18,7 @@ use App\Services\AbstractService; class GetInvoicePdf extends AbstractService { + public function __construct(public Invoice $invoice, public ?ClientContact $contact = null) { } diff --git a/app/Services/Recurring/GetInvoicePdf.php b/app/Services/Recurring/GetInvoicePdf.php index 019d094e6fdc..baab02cd7438 100644 --- a/app/Services/Recurring/GetInvoicePdf.php +++ b/app/Services/Recurring/GetInvoicePdf.php @@ -18,7 +18,7 @@ use App\Services\AbstractService; class GetInvoicePdf extends AbstractService { - public function __construct(public $entity, public ClientContact $contact = null) + public function __construct(public $entity, public ?ClientContact $contact = null) { } diff --git a/app/Services/Report/TaxSummaryReport.php b/app/Services/Report/TaxSummaryReport.php index 3f1b67512e7f..92453e88d59f 100644 --- a/app/Services/Report/TaxSummaryReport.php +++ b/app/Services/Report/TaxSummaryReport.php @@ -54,7 +54,7 @@ class TaxSummaryReport extends BaseExport } public function run() - { + {nlog($this->input); MultiDB::setDb($this->company->db); App::forgetInstance('translator'); App::setLocale($this->company->locale()); @@ -67,9 +67,6 @@ class TaxSummaryReport extends BaseExport $this->csv->insertOne([]); $this->csv->insertOne([]); $this->csv->insertOne([]); - $this->csv->insertOne([ctrans('texts.tax_summary')]); - $this->csv->insertOne([ctrans('texts.created_on'),' ',$this->translateDate(now()->format('Y-m-d'), $this->company->date_format(), $this->company->locale())]); - $this->csv->insertOne([ctrans('texts.date_range'),' ',$this->translateDate($this->input['start_date'], $this->company->date_format(), $this->company->locale()),' - ',$this->translateDate($this->input['end_date'], $this->company->date_format(), $this->company->locale())]); if (count($this->input['report_keys']) == 0) { $this->input['report_keys'] = $this->report_keys; @@ -84,6 +81,12 @@ class TaxSummaryReport extends BaseExport $query = $this->addDateRange($query); + $this->csv->insertOne([ctrans('texts.tax_summary')]); + $this->csv->insertOne([ctrans('texts.created_on'),' ',$this->translateDate(now()->format('Y-m-d'), $this->company->date_format(), $this->company->locale())]); + $this->csv->insertOne([ctrans('texts.date_range'),' ',$this->translateDate($this->start_date, $this->company->date_format(), $this->company->locale()),' - ',$this->translateDate($this->end_date, $this->company->date_format(), $this->company->locale())]); + + + $query = $this->filterByClients($query); $accrual_map = []; $cash_map = []; diff --git a/tests/Feature/CreditTest.php b/tests/Feature/CreditTest.php index f67aa96db9b4..dd2fc2800771 100644 --- a/tests/Feature/CreditTest.php +++ b/tests/Feature/CreditTest.php @@ -42,7 +42,110 @@ class CreditTest extends TestCase $this->makeTestData(); } + public function testApplicableFilters() + { + Credit::where('company_id',$this->company->id)->cursor()->each(function ($c){ $c->forceDelete(); }); + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + ])->get('/api/v1/credits'); + + $response->assertStatus(200); + $arr = $response->json(); + $this->assertCount(0, $arr['data']); + + $c = Credit::factory()->create([ + 'user_id' => $this->user->id, + 'company_id' => $this->company->id, + 'client_id' => $this->client->id, + 'status_id' => Credit::STATUS_DRAFT, + 'due_date' => null, + 'date' => now(), + ]); + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + ])->get('/api/v1/credits'); + + $response->assertStatus(200); + $arr = $response->json(); + + $this->assertCount(1, $arr['data']); + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + ])->get('/api/v1/credits?applicable=true'); + + $response->assertStatus(200); + $arr = $response->json(); + + $this->assertCount(0, $arr['data']); + + $c->status_id = Credit::STATUS_SENT; + $c->amount = 20; + $c->balance = 20; + $c->save(); + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + ])->get('/api/v1/credits?applicable=true'); + + $response->assertStatus(200); + $arr = $response->json(); + $this->assertCount(1, $arr['data']); + + $c->status_id = Credit::STATUS_SENT; + $c->amount = 20; + $c->balance = 20; + $c->due_date = now()->subYear(); + $c->save(); + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + ])->get('/api/v1/credits?applicable=true'); + + $response->assertStatus(200); + $arr = $response->json(); + $this->assertCount(0, $arr['data']); + + $c->status_id = Credit::STATUS_SENT; + $c->amount = 20; + $c->balance = 20; + $c->due_date = now()->addYear(); + $c->save(); + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + ])->get('/api/v1/credits?applicable=true'); + + $response->assertStatus(200); + $arr = $response->json(); + $this->assertCount(1, $arr['data']); + + $c->status_id = Credit::STATUS_APPLIED; + $c->amount = 20; + $c->balance = 20; + $c->due_date = now()->addYear(); + $c->save(); + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + ])->get('/api/v1/credits?applicable=true'); + + $response->assertStatus(200); + $arr = $response->json(); + $this->assertCount(0, $arr['data']); + + + + } public function testQuoteDownloadPDF() {