mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-11-04 04:07:32 -05:00 
			
		
		
		
	Merge pull request #4643 from turbo124/v5-develop
Fixes for tax precision
This commit is contained in:
		
						commit
						31dd8b2d77
					
				@ -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;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -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',
 | 
				
			||||||
 | 
				
			|||||||
@ -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));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
@ -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;
 | 
				
			||||||
 | 
				
			|||||||
@ -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;
 | 
				
			||||||
 | 
				
			|||||||
@ -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();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
				
			|||||||
@ -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);
 | 
				
			||||||
 | 
				
			|||||||
@ -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);
 | 
				
			||||||
 | 
				
			|||||||
@ -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 = [
 | 
				
			||||||
 | 
				
			|||||||
@ -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);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -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
 | 
				
			||||||
        ];
 | 
					        ];
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -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'] = '';
 | 
				
			||||||
 | 
				
			|||||||
@ -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');
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user