Merge pull request #4205 from turbo124/v5-develop

Fix for date localization
This commit is contained in:
David Bomba 2020-10-24 14:40:20 +11:00 committed by GitHub
commit 7f141259da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
28 changed files with 153 additions and 42 deletions

View File

@ -112,6 +112,7 @@ class CreateSingleAccount extends Command
$company = Company::factory()->create([ $company = Company::factory()->create([
'account_id' => $account->id, 'account_id' => $account->id,
'slack_webhook_url' => config('ninja.notification.slack'), 'slack_webhook_url' => config('ninja.notification.slack'),
'use_credits_payment' => 'always',
]); ]);
$account->default_company_id = $company->id; $account->default_company_id = $company->id;

View File

@ -207,7 +207,7 @@ class BaseController extends Controller
$query->whereNotNull('updated_at')->with('documents'); $query->whereNotNull('updated_at')->with('documents');
}, },
'company.clients' => function ($query) use ($updated_at) { 'company.clients' => function ($query) use ($updated_at) {
$query->where('clients.updated_at', '>=', $updated_at)->with('contacts.company', 'gateway_tokens','documents','company'); $query->where('clients.updated_at', '>=', $updated_at)->with('contacts.company', 'gateway_tokens','documents');
}, },
'company.company_gateways' => function ($query) { 'company.company_gateways' => function ($query) {
$query->whereNotNull('updated_at'); $query->whereNotNull('updated_at');

View File

@ -52,10 +52,9 @@ class Kernel extends HttpKernel
], ],
'api' => [ 'api' => [
'throttle:60,1', 'throttle:300,1',
'bindings', 'bindings',
'query_logging', 'query_logging',
//\App\Http\Middleware\StartupCheck::class,
\App\Http\Middleware\Cors::class, \App\Http\Middleware\Cors::class,
], ],
'contact' => [ 'contact' => [
@ -75,7 +74,7 @@ class Kernel extends HttpKernel
\App\Http\Middleware\QueryLogging::class, \App\Http\Middleware\QueryLogging::class,
], ],
'shop' => [ 'shop' => [
'throttle:60,1', 'throttle:120,1',
'bindings', 'bindings',
'query_logging', 'query_logging',
], ],

View File

@ -54,6 +54,7 @@ class QueryLogging
// if($count > 50) // if($count > 50)
// Log::info($queries); // Log::info($queries);
} }
} }

View File

@ -46,16 +46,7 @@ class UpdateExpenseRequest extends Request
$rules['number'] = 'unique:expenses,number,'.$this->id.',id,company_id,'.$this->expense->company_id; $rules['number'] = 'unique:expenses,number,'.$this->id.',id,company_id,'.$this->expense->company_id;
} }
$contacts = request('contacts'); return $this->globalRules($rules);
if (is_array($contacts)) {
// for ($i = 0; $i < count($contacts); $i++) {
// // $rules['contacts.' . $i . '.email'] = 'nullable|email|unique:client_contacts,email,' . isset($contacts[$i]['id'].',company_id,'.$this->company_id);
// //$rules['contacts.' . $i . '.email'] = 'nullable|email';
// }
}
return $rules;
} }
public function messages() public function messages()
@ -72,6 +63,8 @@ class UpdateExpenseRequest extends Request
{ {
$input = $this->all(); $input = $this->all();
$input = $this->decodePrimaryKeys($input);
$this->replace($input); $this->replace($input);
} }
} }

View File

@ -34,7 +34,6 @@ class StoreProjectRequest extends Request
{ {
$rules = []; $rules = [];
//$rules['name'] ='required|unique:projects,name,null,null,company_id,'.auth()->user()->companyId();
$rules['name'] = 'required'; $rules['name'] = 'required';
$rules['client_id'] = 'required|exists:clients,id,company_id,'.auth()->user()->company()->id; $rules['client_id'] = 'required|exists:clients,id,company_id,'.auth()->user()->company()->id;
@ -48,7 +47,6 @@ class StoreProjectRequest extends Request
if (array_key_exists('client_id', $input) && is_string($input['client_id'])) { if (array_key_exists('client_id', $input) && is_string($input['client_id'])) {
$input['client_id'] = $this->decodePrimaryKey($input['client_id']); $input['client_id'] = $this->decodePrimaryKey($input['client_id']);
} }
$this->replace($input); $this->replace($input);
} }

View File

@ -38,6 +38,10 @@ class UpdateProjectRequest extends Request
{ {
$input = $this->all(); $input = $this->all();
if (array_key_exists('client_id', $input) && is_string($input['client_id'])) {
unset($input['client_id']);
}
$this->replace($input); $this->replace($input);
} }
} }

View File

@ -63,7 +63,7 @@ class Request extends FormRequest
private function vendor_id($rules) private function vendor_id($rules)
{ {
$rules['vendor_id'] = 'bail|sometimes|exists:vendors,id,company_id,'.auth()->user()->company()->id; $rules['vendor_id'] = 'bail|nullable|sometimes|exists:vendors,id,company_id,'.auth()->user()->company()->id;
return $rules; return $rules;
} }

View File

@ -82,7 +82,7 @@ class BaseMailerJob implements ShouldQueue
public function failed($exception = null) public function failed($exception = null)
{ {
info('the job failed'); // info('the job failed');
$job_failure = new EmailFailure(); $job_failure = new EmailFailure();
$job_failure->string_metric5 = get_parent_class($this); $job_failure->string_metric5 = get_parent_class($this);

View File

@ -240,7 +240,6 @@ class Client extends BaseModel implements HasLocalePreference
return $item->id == $this->getSetting('date_format_id'); return $item->id == $this->getSetting('date_format_id');
})->first()->format; })->first()->format;
//return DateFormat::find($this->getSetting('date_format_id'))->format;
} }
public function currency() public function currency()

View File

@ -11,7 +11,7 @@ use Laracasts\Presenter\PresentableTrait;
*/ */
class Project extends BaseModel class Project extends BaseModel
{ {
// Expense Categories
use SoftDeletes; use SoftDeletes;
use PresentableTrait; use PresentableTrait;
use Filterable; use Filterable;

View File

@ -201,7 +201,7 @@ class AuthorizeCreditCard
private function processFailedResponse($data, $request) private function processFailedResponse($data, $request)
{ {
//dd($data); //dd($data);
info(print_r($data, 1)); // info(print_r($data, 1));
} }
private function formatGatewayResponse($data, $vars) private function formatGatewayResponse($data, $vars)

View File

@ -55,6 +55,19 @@ class CreditService
return $this; return $this;
} }
public function setCalculatedStatus()
{
if((int)$this->credit->balance == 0)
$this->credit->status_id = Credit::STATUS_APPLIED;
elseif((string)$this->credit->amount == (string)$this->credit->balance)
$this->credit->status_id = Credit::STATUS_SENT;
elseif($this->credit->balance > 0)
$this->credit->status_id = Credit::STATUS_PARTIAL;
return $this;
}
public function markSent() public function markSent()
{ {
$this->credit = (new MarkSent($this->credit->client, $this->credit))->run(); $this->credit = (new MarkSent($this->credit->client, $this->credit))->run();
@ -69,6 +82,13 @@ class CreditService
return $this; return $this;
} }
public function adjustBalance($adjustment)
{
$this->credit->balance += $adjustment;
return $this;
}
/** /**
* Saves the credit. * Saves the credit.
* @return Credit object * @return Credit object

View File

@ -56,7 +56,7 @@ class AutoBillInvoice extends AbstractService
//if the credits cover the payments, we stop here, build the payment with credits and exit early //if the credits cover the payments, we stop here, build the payment with credits and exit early
if($this->invoice->company->use_credits_payment == 'always' || $this->invoice->company->use_credits_payment == 'option') if($this->invoice->company->use_credits_payment != 'off')
$this->applyCreditPayment(); $this->applyCreditPayment();
info("partial = {$this->invoice->partial}"); info("partial = {$this->invoice->partial}");
@ -68,7 +68,7 @@ class AutoBillInvoice extends AbstractService
elseif($this->invoice->balance > 0) elseif($this->invoice->balance > 0)
$amount = $this->invoice->balance; $amount = $this->invoice->balance;
else else
return $this->finalizePaymentUsingCredits(); return $this->invoice;
info("balance remains to be paid!!"); info("balance remains to be paid!!");
@ -127,8 +127,11 @@ class AutoBillInvoice extends AbstractService
$current_credit = Credit::find($credit['credit_id']); $current_credit = Credit::find($credit['credit_id']);
$payment->credits()->attach($current_credit->id, ['amount' => $credit['amount']]); $payment->credits()->attach($current_credit->id, ['amount' => $credit['amount']]);
info("adjusting credit balance {$current_credit->balance} by this amount ". $credit['amount']);
$current_credit->balance -= $credit['amount']; $current_credit->balance -= $credit['amount'];
$current_credit->save();
$current_credit->service()->setCalculatedStatus()->save();
// $this->applyPaymentToCredit($current_credit, $credit['amount']); // $this->applyPaymentToCredit($current_credit, $credit['amount']);
} }
@ -147,9 +150,9 @@ class AutoBillInvoice extends AbstractService
->updateCreditBalance($amount * -1, 'Credits used to pay down Invoice ' . $this->invoice->number) ->updateCreditBalance($amount * -1, 'Credits used to pay down Invoice ' . $this->invoice->number)
->save(); ->save();
event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars())); event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars()));
return $this->invoice->service()->setStatus(Invoice::STATUS_PAID)->save(); return $this->invoice->service()->setCalculatedStatus()->save();
} }
/** /**
@ -169,6 +172,8 @@ class AutoBillInvoice extends AbstractService
$available_credit_balance = $available_credits->sum('balance'); $available_credit_balance = $available_credits->sum('balance');
info("available credit balance = {$available_credit_balance}");
if((int)$available_credit_balance == 0) if((int)$available_credit_balance == 0)
return; return;
@ -217,7 +222,7 @@ class AutoBillInvoice extends AbstractService
} }
} }
$this->finalizePaymentUsingCredits();
return $this; return $this;
} }

View File

@ -210,6 +210,16 @@ class InvoiceService
return $this; return $this;
} }
public function setCalculatedStatus()
{
if((int)$this->invoice->balance == 0)
$this->setStatus(Invoice::STATUS_PAID);
elseif($this->invoice->balance > 0 && $this->invoice->balance < $this->invoice->amount)
$this->setStatus(Invoice::STATUS_PARTIAL);
return $this;
}
public function updateStatus() public function updateStatus()
{ {
info("invoice balance = {$this->invoice->balance}"); info("invoice balance = {$this->invoice->balance}");

View File

@ -241,6 +241,7 @@ class RefundPayment
$adjustment_amount += $refunded_invoice['amount']; $adjustment_amount += $refunded_invoice['amount'];
$client->balance += $refunded_invoice['amount']; $client->balance += $refunded_invoice['amount'];
//$client->paid_to_date -= $refunded_invoice['amount'];//todo refund balancing
$client->save(); $client->save();
//todo adjust ledger balance here? or after and reference the credit and its total //todo adjust ledger balance here? or after and reference the credit and its total
@ -251,7 +252,8 @@ class RefundPayment
// $this->credit_note->ledger()->updateCreditBalance($adjustment_amount, $ledger_string); // $this->credit_note->ledger()->updateCreditBalance($adjustment_amount, $ledger_string);
$client = $this->payment->client->fresh(); $client = $this->payment->client->fresh();
$client->service()->updatePaidToDate(-1 * $this->total_refund)->save(); //$client->service()->updatePaidToDate(-1 * $this->total_refund)->save();
$client->service()->updatePaidToDate(-1 * $refunded_invoice['amount'])->save();
} }
return $this; return $this;

View File

@ -293,7 +293,7 @@ trait PdfMakerUtilities
$this->document->getElementById('repeat-content')->appendChild($clone); $this->document->getElementById('repeat-content')->appendChild($clone);
} }
info($this->data['options']); // info($this->data['options']);
if ( if (
$header = $this->document->getElementById('header') && $header = $this->document->getElementById('header') &&

View File

@ -144,6 +144,9 @@ class CompanyTransformer extends EntityTransformer
'enable_shop_api' => (bool) $company->enable_shop_api, 'enable_shop_api' => (bool) $company->enable_shop_api,
'mark_expenses_invoiceable'=> (bool) $company->mark_expenses_invoiceable, 'mark_expenses_invoiceable'=> (bool) $company->mark_expenses_invoiceable,
'mark_expenses_paid' => (bool) $company->mark_expenses_paid, 'mark_expenses_paid' => (bool) $company->mark_expenses_paid,
'invoice_expense_documents' => (bool) $company->invoice_expense_documents,
'invoice_task_timelog' => (bool) $company->invoice_task_timelog,
'auto_start_tasks' => (bool) $company->auto_start_tasks,
'use_credits_payment' => (string) $company->use_credits_payment, 'use_credits_payment' => (string) $company->use_credits_payment,
]; ];
} }

View File

@ -15,10 +15,13 @@ namespace App\Utils;
use App\Designs\Designer; use App\Designs\Designer;
use App\Models\Country; use App\Models\Country;
use App\Utils\Number; use App\Utils\Number;
use App\Utils\Traits\MakesDates;
use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\App;
class HtmlEngine class HtmlEngine
{ {
use MakesDates;
public $entity; public $entity;
public $invitation; public $invitation;
@ -172,10 +175,10 @@ class HtmlEngine
$data['$taxes'] = ['value' => Number::formatMoney($this->entity_calc->getItemTotalTaxes(), $this->client) ?: '&nbsp;', 'label' => ctrans('texts.taxes')]; $data['$taxes'] = ['value' => Number::formatMoney($this->entity_calc->getItemTotalTaxes(), $this->client) ?: '&nbsp;', 'label' => ctrans('texts.taxes')];
$data['$invoice.taxes'] = &$data['$taxes']; $data['$invoice.taxes'] = &$data['$taxes'];
$data['$invoice.custom1'] = ['value' => $this->entity->custom_value1 ?: '&nbsp;', 'label' => $this->makeCustomField('invoice1')]; $data['$invoice.custom1'] = ['value' => $this->formatCustomFieldValue('invoice1', $this->entity->custom_value1) ?: '&nbsp;', 'label' => $this->makeCustomField('invoice1')];
$data['$invoice.custom2'] = ['value' => $this->entity->custom_value2 ?: '&nbsp;', 'label' => $this->makeCustomField('invoice2')]; $data['$invoice.custom2'] = ['value' => $this->formatCustomFieldValue('invoice2', $this->entity->custom_value2) ?: '&nbsp;', 'label' => $this->makeCustomField('invoice2')];
$data['$invoice.custom3'] = ['value' => $this->entity->custom_value3 ?: '&nbsp;', 'label' => $this->makeCustomField('invoice3')]; $data['$invoice.custom3'] = ['value' => $this->formatCustomFieldValue('invoice3', $this->entity->custom_value3) ?: '&nbsp;', 'label' => $this->makeCustomField('invoice3')];
$data['$invoice.custom4'] = ['value' => $this->entity->custom_value4 ?: '&nbsp;', 'label' => $this->makeCustomField('invoice4')]; $data['$invoice.custom4'] = ['value' => $this->formatCustomFieldValue('invoice4', $this->entity->custom_value4) ?: '&nbsp;', 'label' => $this->makeCustomField('invoice4')];
$data['$invoice.public_notes'] = ['value' => $this->entity->public_notes ?: '&nbsp;', 'label' => ctrans('texts.public_notes')]; $data['$invoice.public_notes'] = ['value' => $this->entity->public_notes ?: '&nbsp;', 'label' => ctrans('texts.public_notes')];
$data['$entity.public_notes'] = &$data['$invoice.public_notes']; $data['$entity.public_notes'] = &$data['$invoice.public_notes'];
@ -481,6 +484,7 @@ class HtmlEngine
if ($custom_fields && property_exists($custom_fields, $field)) { if ($custom_fields && property_exists($custom_fields, $field)) {
$custom_field = $custom_fields->{$field}; $custom_field = $custom_fields->{$field};
$custom_field_parts = explode('|', $custom_field); $custom_field_parts = explode('|', $custom_field);
return $custom_field_parts[0]; return $custom_field_parts[0];
@ -489,6 +493,28 @@ class HtmlEngine
return ''; return '';
} }
private function formatCustomFieldValue($field, $value) :string
{
$custom_fields = $this->company->custom_fields;
$custom_field = '';
if ($custom_fields && property_exists($custom_fields, $field)) {
$custom_field = $custom_fields->{$field};
$custom_field_parts = explode('|', $custom_field);
$custom_field = $custom_field_parts[1];
}
switch ($custom_field) {
case 'date':
return $this->formatDate($value, $this->client->date_format());
break;
default:
return $value;
break;
}
}
private function makeTotalTaxes() :string private function makeTotalTaxes() :string
{ {
$data = ''; $data = '';

12
composer.lock generated
View File

@ -3879,16 +3879,16 @@
}, },
{ {
"name": "nesbot/carbon", "name": "nesbot/carbon",
"version": "2.41.3", "version": "2.41.4",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/briannesbitt/Carbon.git", "url": "https://github.com/briannesbitt/Carbon.git",
"reference": "e148788eeae9b9b7b87996520358b86faad37b52" "reference": "6571aec754a648ef476a8d8f57993f7bc965afe4"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/e148788eeae9b9b7b87996520358b86faad37b52", "url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/6571aec754a648ef476a8d8f57993f7bc965afe4",
"reference": "e148788eeae9b9b7b87996520358b86faad37b52", "reference": "6571aec754a648ef476a8d8f57993f7bc965afe4",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -3964,7 +3964,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2020-10-12T20:36:09+00:00" "time": "2020-10-22T07:28:05+00:00"
}, },
{ {
"name": "nikic/php-parser", "name": "nikic/php-parser",
@ -6588,7 +6588,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2020-10-07T15:23:00+00:00" "time": "2020-09-18T14:27:32+00:00"
}, },
{ {
"name": "symfony/css-selector", "name": "symfony/css-selector",

View File

@ -181,6 +181,7 @@ return [
App\Providers\MultiDBProvider::class, App\Providers\MultiDBProvider::class,
App\Providers\ClientPortalServiceProvider::class, App\Providers\ClientPortalServiceProvider::class,
App\Providers\NinjaTranslationServiceProvider::class, App\Providers\NinjaTranslationServiceProvider::class,
], ],
/* /*

View File

@ -0,0 +1,30 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CompanyTableFields extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('companies', function(Blueprint $table){
$table->boolean('invoice_task_timelog')->default(true);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}

View File

@ -14,6 +14,7 @@ use Faker\Factory;
use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\MockAccountData; use Tests\MockAccountData;
use Tests\TestCase; use Tests\TestCase;
use Illuminate\Routing\Middleware\ThrottleRequests;
/** /**
* @test * @test
@ -31,6 +32,11 @@ class ActivityApiTest extends TestCase
$this->makeTestData(); $this->makeTestData();
$this->withoutMiddleware(
ThrottleRequests::class
);
} }
public function testActivityGet() public function testActivityGet()

View File

@ -516,7 +516,8 @@ class ClientTest extends TestCase
$response->assertStatus(200); $response->assertStatus(200);
$arr = $response->json(); $arr = $response->json();
info($arr);
$this->client = Client::find($this->decodePrimaryKey($arr['data']['id'])); $this->client = Client::find($this->decodePrimaryKey($arr['data']['id']));
$this->client->fresh(); $this->client->fresh();

View File

@ -172,6 +172,6 @@ class CompanyGatewayResolutionTest extends TestCase
$this->assertEquals(4, count($this->cg->driver($this->client)->gatewayTypes())); $this->assertEquals(4, count($this->cg->driver($this->client)->gatewayTypes()));
info(print_r($this->client->getPaymentMethods(10),1)); // info(print_r($this->client->getPaymentMethods(10),1));
} }
} }

View File

@ -29,6 +29,7 @@ use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Session; use Illuminate\Support\Facades\Session;
use Tests\MockAccountData; use Tests\MockAccountData;
use Tests\TestCase; use Tests\TestCase;
use Illuminate\Routing\Middleware\ThrottleRequests;
/** /**
* @test * @test
@ -51,6 +52,11 @@ class PaymentTermsApiTest extends TestCase
$this->faker = \Faker\Factory::create(); $this->faker = \Faker\Factory::create();
Model::reguard(); Model::reguard();
$this->withoutMiddleware(
ThrottleRequests::class
);
} }
public function testPaymentTermsGet() public function testPaymentTermsGet()

View File

@ -1295,7 +1295,7 @@ $contact = ClientContact::factory()->create([
$payment = Payment::find($this->decodePrimaryKey($payment_id))->first(); $payment = Payment::find($this->decodePrimaryKey($payment_id))->first();
info($payment); // info($payment);
$this->assertNotNull($payment); $this->assertNotNull($payment);
$this->assertNotNull($payment->invoices()); $this->assertNotNull($payment->invoices());

View File

@ -13,6 +13,7 @@ namespace Tests\Feature;
use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\MockAccountData; use Tests\MockAccountData;
use Tests\TestCase; use Tests\TestCase;
use Illuminate\Routing\Middleware\ThrottleRequests;
/** /**
* @test * @test
@ -28,6 +29,11 @@ class PingTest extends TestCase
parent::setUp(); parent::setUp();
$this->makeTestData(); $this->makeTestData();
$this->withoutMiddleware(
ThrottleRequests::class
);
} }
public function testPingEndPoint() public function testPingEndPoint()