mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Fixes for invoice 2 go imports
This commit is contained in:
parent
1f7f7e5789
commit
35b1aaf507
@ -272,9 +272,9 @@ class BaseTransformer
|
||||
/**
|
||||
* @param $email
|
||||
*
|
||||
* @return ?Contact
|
||||
* @return ?ClientContact
|
||||
*/
|
||||
public function getContact($email)
|
||||
public function getContact($email): ?ClientContact
|
||||
{
|
||||
$contact = ClientContact::where('company_id', $this->company->id)
|
||||
->whereRaw("LOWER(REPLACE(`email`, ' ' ,'')) = ?", [
|
||||
|
@ -61,8 +61,14 @@ class InvoiceTransformer extends BaseTransformer
|
||||
],
|
||||
];
|
||||
|
||||
$client_id =
|
||||
$this->getClient($this->getString($invoice_data, 'Name'), $this->getString($invoice_data, 'EmailRecipient'));
|
||||
$client_id = null;
|
||||
|
||||
if($this->hasClient($this->getString($invoice_data, 'Name') || $this->getContact($this->getString($invoice_data, 'EmailRecipient'))))
|
||||
{
|
||||
|
||||
$client_id = $this->getClient($this->getString($invoice_data, 'Name'), $this->getString($invoice_data, 'EmailRecipient'));
|
||||
|
||||
}
|
||||
|
||||
if ($client_id) {
|
||||
$transformed['client_id'] = $client_id;
|
||||
|
@ -46,7 +46,6 @@ class EmailProductSalesReport
|
||||
$data['clients'] = $this->transformKeys($this->scheduler->parameters['clients']);
|
||||
}
|
||||
|
||||
|
||||
$data = [
|
||||
'start_date' => $start_end_dates[0],
|
||||
'end_date' => $start_end_dates[1],
|
||||
@ -57,6 +56,8 @@ class EmailProductSalesReport
|
||||
$export = (new ProductSalesExport($this->scheduler->company, $data));
|
||||
$csv = $export->run();
|
||||
|
||||
//todo - potentially we send this to more than one user.
|
||||
|
||||
$nmo = new NinjaMailerObject;
|
||||
$nmo->mailable = new DownloadReport($this->scheduler->company, $csv, $this->file_name);
|
||||
$nmo->company = $this->scheduler->company;
|
||||
@ -65,7 +66,6 @@ class EmailProductSalesReport
|
||||
|
||||
NinjaMailerJob::dispatch($nmo);
|
||||
|
||||
|
||||
//calculate next run dates;
|
||||
$this->scheduler->calculateNextRun();
|
||||
|
||||
|
@ -122,6 +122,7 @@ class Invoice2GoTest extends TestCase
|
||||
|
||||
$this->assertInstanceOf(Client::class, $client);
|
||||
$this->assertEquals('840', $client->country_id);
|
||||
$this->assertEquals('wade@projectx.net', $client->contacts->first()->email);
|
||||
$this->assertEquals('2584 Sesame Street', $client->address1);
|
||||
|
||||
$this->assertTrue($base_transformer->hasInvoice('1'));
|
||||
|
@ -26,6 +26,7 @@ use App\Services\Scheduler\SchedulerService;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Illuminate\Foundation\Testing\WithoutEvents;
|
||||
use App\Services\Scheduler\EmailStatementService;
|
||||
use App\Services\Scheduler\EmailProductSalesReport;
|
||||
use Illuminate\Routing\Middleware\ThrottleRequests;
|
||||
|
||||
/**
|
||||
@ -75,6 +76,39 @@ class SchedulerTest extends TestCase
|
||||
])->postJson('/api/v1/task_schedulers', $data);
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
$arr = $response->json();
|
||||
|
||||
$id = $this->decodePrimaryKey($arr['data']['id']);
|
||||
$scheduler = Scheduler::find($id);
|
||||
|
||||
$this->assertNotNull($scheduler);
|
||||
|
||||
$export = (new EmailProductSalesReport($scheduler))->run();
|
||||
|
||||
$this->assertEquals(now()->addMonth()->format('Y-m-d'), $scheduler->next_run->format('Y-m-d'));
|
||||
|
||||
}
|
||||
|
||||
public function testProductSalesReportStore()
|
||||
{
|
||||
$data = [
|
||||
'name' => 'A test product sales scheduler',
|
||||
'frequency_id' => RecurringInvoice::FREQUENCY_MONTHLY,
|
||||
'next_run' => now()->format('Y-m-d'),
|
||||
'template' => 'email_product_sales_report',
|
||||
'parameters' => [
|
||||
'date_range' => EmailStatement::LAST_MONTH,
|
||||
'clients' => [],
|
||||
],
|
||||
];
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->postJson('/api/v1/task_schedulers', $data);
|
||||
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user