Merge pull request #4643 from turbo124/v5-develop

Fixes for tax precision
This commit is contained in:
David Bomba 2021-01-07 17:09:08 +11:00 committed by GitHub
commit 31dd8b2d77
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 49 additions and 17 deletions

View File

@ -227,7 +227,7 @@ class CreateSingleAccount extends Command
$settings = $client->settings; $settings = $client->settings;
$settings->currency_id = "1"; $settings->currency_id = "1";
$settings->use_credits_payment = "always"; // $settings->use_credits_payment = "always";
$client->settings = $settings; $client->settings = $settings;

View File

@ -258,8 +258,10 @@ class CompanySettings extends BaseSettings
public $client_portal_allow_over_payment = false; //@implemented public $client_portal_allow_over_payment = false; //@implemented
public $use_credits_payment = 'off'; //always, option, off //@implemented public $use_credits_payment = 'off'; //always, option, off //@implemented
public $hide_empty_columns_on_pdf = false;
public static $casts = [ public static $casts = [
'hide_empty_columns_on_pdf' => 'bool',
'enable_reminder_endless' => 'bool', 'enable_reminder_endless' => 'bool',
'use_credits_payment' => 'string', 'use_credits_payment' => 'string',
'recurring_invoice_number_pattern' => 'string', 'recurring_invoice_number_pattern' => 'string',

View File

@ -151,7 +151,7 @@ class InvoiceItemSum
$key = str_replace(' ', '', $tax_name.$tax_rate); $key = str_replace(' ', '', $tax_name.$tax_rate);
$group_tax = ['key' => $key, 'total' => $tax_total, 'tax_name' => $tax_name.' '.$tax_rate.'%']; $group_tax = ['key' => $key, 'total' => $tax_total, 'tax_name' => $tax_name.' '.floatval($tax_rate).'%'];
$this->tax_collection->push(collect($group_tax)); $this->tax_collection->push(collect($group_tax));
} }

View File

@ -111,19 +111,19 @@ class InvoiceSum
if ($this->invoice->tax_rate1 > 0) { if ($this->invoice->tax_rate1 > 0) {
$tax = $this->taxer($this->total, $this->invoice->tax_rate1); $tax = $this->taxer($this->total, $this->invoice->tax_rate1);
$this->total_taxes += $tax; $this->total_taxes += $tax;
$this->total_tax_map[] = ['name' => $this->invoice->tax_name1.' '.$this->invoice->tax_rate1.'%', 'total' => $tax]; $this->total_tax_map[] = ['name' => $this->invoice->tax_name1.' '.floatval($this->invoice->tax_rate1).'%', 'total' => $tax];
} }
if ($this->invoice->tax_rate2 > 0) { if ($this->invoice->tax_rate2 > 0) {
$tax = $this->taxer($this->total, $this->invoice->tax_rate2); $tax = $this->taxer($this->total, $this->invoice->tax_rate2);
$this->total_taxes += $tax; $this->total_taxes += $tax;
$this->total_tax_map[] = ['name' => $this->invoice->tax_name2.' '.$this->invoice->tax_rate2.'%', 'total' => $tax]; $this->total_tax_map[] = ['name' => $this->invoice->tax_name2.' '.floatval($this->invoice->tax_rate2).'%', 'total' => $tax];
} }
if ($this->invoice->tax_rate3 > 0) { if ($this->invoice->tax_rate3 > 0) {
$tax = $this->taxer($this->total, $this->invoice->tax_rate3); $tax = $this->taxer($this->total, $this->invoice->tax_rate3);
$this->total_taxes += $tax; $this->total_taxes += $tax;
$this->total_tax_map[] = ['name' => $this->invoice->tax_name3.' '.$this->invoice->tax_rate3.'%', 'total' => $tax]; $this->total_tax_map[] = ['name' => $this->invoice->tax_name3.' '.floatval($this->invoice->tax_rate3).'%', 'total' => $tax];
} }
return $this; return $this;

View File

@ -122,19 +122,19 @@ class InvoiceSumInclusive
$tax = $this->calcInclusiveLineTax($this->invoice->tax_rate1, $amount); $tax = $this->calcInclusiveLineTax($this->invoice->tax_rate1, $amount);
$this->total_taxes += $tax; $this->total_taxes += $tax;
$this->total_tax_map[] = ['name' => $this->invoice->tax_name1.' '.$this->invoice->tax_rate1.'%', 'total' => $tax]; $this->total_tax_map[] = ['name' => $this->invoice->tax_name1.' '.floatval($this->invoice->tax_rate1).'%', 'total' => $tax];
} }
if ($this->invoice->tax_rate2 > 0) { if ($this->invoice->tax_rate2 > 0) {
$tax = $this->calcInclusiveLineTax($this->invoice->tax_rate2, $amount); $tax = $this->calcInclusiveLineTax($this->invoice->tax_rate2, $amount);
$this->total_taxes += $tax; $this->total_taxes += $tax;
$this->total_tax_map[] = ['name' => $this->invoice->tax_name2.' '.$this->invoice->tax_rate2.'%', 'total' => $tax]; $this->total_tax_map[] = ['name' => $this->invoice->tax_name2.' '.floatval($this->invoice->tax_rate2).'%', 'total' => $tax];
} }
if ($this->invoice->tax_rate3 > 0) { if ($this->invoice->tax_rate3 > 0) {
$tax = $this->calcInclusiveLineTax($this->invoice->tax_rate3, $amount); $tax = $this->calcInclusiveLineTax($this->invoice->tax_rate3, $amount);
$this->total_taxes += $tax; $this->total_taxes += $tax;
$this->total_tax_map[] = ['name' => $this->invoice->tax_name3.' '.$this->invoice->tax_rate3.'%', 'total' => $tax]; $this->total_tax_map[] = ['name' => $this->invoice->tax_name3.' '.floatval($this->invoice->tax_rate3).'%', 'total' => $tax];
} }
return $this; return $this;

View File

@ -205,6 +205,9 @@ class PaymentController extends Controller
$credit_totals = $first_invoice->client->getSetting('use_credits_payment') == 'off' ? 0 : $first_invoice->client->service()->getCreditBalance(); $credit_totals = $first_invoice->client->getSetting('use_credits_payment') == 'off' ? 0 : $first_invoice->client->service()->getCreditBalance();
$starting_invoice_amount = $first_invoice->amount; $starting_invoice_amount = $first_invoice->amount;
nlog($credit_totals);
nlog($first_invoice->client->getSetting('use_credits_payment'));
if ($gateway) { if ($gateway) {
$first_invoice->service()->addGatewayFee($gateway, $payment_method_id, $invoice_totals)->save(); $first_invoice->service()->addGatewayFee($gateway, $payment_method_id, $invoice_totals)->save();
} }

View File

@ -45,7 +45,6 @@ class Company extends BaseModel
protected $presenter = CompanyPresenter::class; protected $presenter = CompanyPresenter::class;
protected $fillable = [ protected $fillable = [
'hide_empty_columns_on_pdf',
'calculate_expense_tax_by_amount', 'calculate_expense_tax_by_amount',
'invoice_expense_documents', 'invoice_expense_documents',
'invoice_task_documents', 'invoice_task_documents',
@ -378,6 +377,11 @@ class Company extends BaseModel
return $this->hasMany(SystemLog::class)->orderBy('id', 'DESC')->take(50); return $this->hasMany(SystemLog::class)->orderBy('id', 'DESC')->take(50);
} }
public function system_log_relation()
{
return $this->hasMany(SystemLog::class)->orderBy('id', 'DESC');
}
public function tokens_hashed() public function tokens_hashed()
{ {
return $this->hasMany(CompanyToken::class); return $this->hasMany(CompanyToken::class);

View File

@ -11,6 +11,7 @@
namespace App\Models; namespace App\Models;
use App\Models\GatewayType;
use App\PaymentDrivers\BasePaymentDriver; use App\PaymentDrivers\BasePaymentDriver;
use App\Utils\Number; use App\Utils\Number;
use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Eloquent\SoftDeletes;
@ -58,10 +59,12 @@ class CompanyGateway extends BaseModel
16 => ['card' => 'images/credit_cards/Test-Discover-Icon.png', 'text' => 'Discover'], 16 => ['card' => 'images/credit_cards/Test-Discover-Icon.png', 'text' => 'Discover'],
]; ];
// public function getFeesAndLimitsAttribute() public $gateway_consts = [
// { '38f2c48af60c7dd69e04248cbb24c36e' => 300,
// return json_decode($this->attributes['fees_and_limits']); 'd14dd26a37cecc30fdd65700bfb55b23' => 301,
// } '3758e7f7c6f4cecf0f4f348b9a00f456' => 304,
'3b6621f970ab18887c4f6dca78d3f8bb' => 305,
];
protected $touches = []; protected $touches = [];
@ -70,6 +73,15 @@ class CompanyGateway extends BaseModel
return self::class; return self::class;
} }
public function system_logs()
{
return $this->company
->system_log_relation
->where('type_id', $this->gateway_consts[$this->gateway->key])
->take(50);
}
public function company() public function company()
{ {
return $this->belongsTo(Company::class); return $this->belongsTo(Company::class);

View File

@ -161,8 +161,6 @@ class PayPalExpressPaymentDriver extends BaseDriver
$data = $response->getData(); $data = $response->getData();
nlog($data);
PaymentFailureMailer::dispatch($this->client, $response->getMessage(), $this->client->company, $this->payment_hash->data->amount); PaymentFailureMailer::dispatch($this->client, $response->getMessage(), $this->client->company, $this->payment_hash->data->amount);
$message = [ $message = [

View File

@ -12,6 +12,8 @@
namespace App\Transformers; namespace App\Transformers;
use App\Models\CompanyGateway; use App\Models\CompanyGateway;
use App\Models\SystemLog;
use App\Transformers\SystemLogTransformer;
use App\Utils\Traits\MakesHash; use App\Utils\Traits\MakesHash;
use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Eloquent\SoftDeletes;
use stdClass; use stdClass;
@ -33,6 +35,7 @@ class CompanyGatewayTransformer extends EntityTransformer
* @var array * @var array
*/ */
protected $availableIncludes = [ protected $availableIncludes = [
'system_logs',
'gateway', 'gateway',
]; ];
@ -81,4 +84,11 @@ class CompanyGatewayTransformer extends EntityTransformer
return $this->includeItem($company_gateway->gateway, $transformer, Gateway::class); return $this->includeItem($company_gateway->gateway, $transformer, Gateway::class);
} }
public function includeSystemLogs(CompanyGateway $company_gateway)
{
$transformer = new SystemLogTransformer($this->serializer);
return $this->includeCollection($company_gateway->system_logs(), $transformer, SystemLog::class);
}
} }

View File

@ -149,7 +149,7 @@ class CompanyTransformer extends EntityTransformer
'default_task_is_date_based' => (bool)$company->default_task_is_date_based, 'default_task_is_date_based' => (bool)$company->default_task_is_date_based,
'enable_product_discount' => (bool)$company->enable_product_discount, 'enable_product_discount' => (bool)$company->enable_product_discount,
'calculate_expense_tax_by_amount' =>(bool)$company->calculate_expense_tax_by_amount, 'calculate_expense_tax_by_amount' =>(bool)$company->calculate_expense_tax_by_amount,
'hide_empty_columns_on_pdf' => (bool) $company->hide_empty_columns_on_pdf, 'hide_empty_columns_on_pdf' => false, //@deprecate
]; ];
} }

View File

@ -604,7 +604,7 @@ trait MakesInvoiceValues
if ($item->is_amount_discount) { if ($item->is_amount_discount) {
$data[$key][$table_type.'.discount'] = Number::formatMoney($item->discount, $this->client); $data[$key][$table_type.'.discount'] = Number::formatMoney($item->discount, $this->client);
} else { } else {
$data[$key][$table_type.'.discount'] = $item->discount.'%'; $data[$key][$table_type.'.discount'] = floatval($item->discount).'%';
} }
} else { } else {
$data[$key][$table_type.'.discount'] = ''; $data[$key][$table_type.'.discount'] = '';

View File

@ -144,6 +144,9 @@ class ImproveDecimalResolution extends Migration
$table->integer('status_order')->nullable(); $table->integer('status_order')->nullable();
}); });
Schema::table('companies', function (Blueprint $table) {
$table->dropColumn('hide_empty_columns_on_pdf');
});
} }
/** /**