mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 21:22:58 +01:00
commit
1bbbc46b86
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
@ -18,6 +18,7 @@ use App\Services\AbstractService;
|
||||
|
||||
class GetInvoicePdf extends AbstractService
|
||||
{
|
||||
|
||||
public function __construct(public Invoice $invoice, public ?ClientContact $contact = null)
|
||||
{
|
||||
}
|
||||
|
@ -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)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -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 = [];
|
||||
|
@ -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()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user