mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-11 05:32:39 +01:00
commit
49aa2c8409
@ -122,25 +122,23 @@ class InvoiceItemSum
|
|||||||
|
|
||||||
$item_tax += $item_tax_rate1_total;
|
$item_tax += $item_tax_rate1_total;
|
||||||
|
|
||||||
if ($item_tax_rate1_total > 0) {
|
if($item_tax_rate1_total != 0)
|
||||||
$this->groupTax($this->item->tax_name1, $this->item->tax_rate1, $item_tax_rate1_total);
|
$this->groupTax($this->item->tax_name1, $this->item->tax_rate1, $item_tax_rate1_total);
|
||||||
}
|
|
||||||
|
|
||||||
$item_tax_rate2_total = $this->calcAmountLineTax($this->item->tax_rate2, $amount);
|
$item_tax_rate2_total = $this->calcAmountLineTax($this->item->tax_rate2, $amount);
|
||||||
|
|
||||||
$item_tax += $item_tax_rate2_total;
|
$item_tax += $item_tax_rate2_total;
|
||||||
|
|
||||||
if ($item_tax_rate2_total > 0) {
|
if($item_tax_rate2_total != 0)
|
||||||
$this->groupTax($this->item->tax_name2, $this->item->tax_rate2, $item_tax_rate2_total);
|
$this->groupTax($this->item->tax_name2, $this->item->tax_rate2, $item_tax_rate2_total);
|
||||||
}
|
|
||||||
|
|
||||||
$item_tax_rate3_total = $this->calcAmountLineTax($this->item->tax_rate3, $amount);
|
$item_tax_rate3_total = $this->calcAmountLineTax($this->item->tax_rate3, $amount);
|
||||||
|
|
||||||
$item_tax += $item_tax_rate3_total;
|
$item_tax += $item_tax_rate3_total;
|
||||||
|
|
||||||
if ($item_tax_rate3_total > 0) {
|
if($item_tax_rate3_total != 0)
|
||||||
$this->groupTax($this->item->tax_name3, $this->item->tax_rate3, $item_tax_rate3_total);
|
$this->groupTax($this->item->tax_name3, $this->item->tax_rate3, $item_tax_rate3_total);
|
||||||
}
|
|
||||||
|
|
||||||
$this->setTotalTaxes($this->formatValue($item_tax, $this->currency->precision));
|
$this->setTotalTaxes($this->formatValue($item_tax, $this->currency->precision));
|
||||||
|
|
||||||
|
@ -119,25 +119,23 @@ class InvoiceItemSumInclusive
|
|||||||
|
|
||||||
$item_tax += $this->formatValue($item_tax_rate1_total, $this->currency->precision);
|
$item_tax += $this->formatValue($item_tax_rate1_total, $this->currency->precision);
|
||||||
|
|
||||||
if ($item_tax_rate1_total > 0) {
|
if($item_tax_rate1_total != 0)
|
||||||
$this->groupTax($this->item->tax_name1, $this->item->tax_rate1, $item_tax_rate1_total);
|
$this->groupTax($this->item->tax_name1, $this->item->tax_rate1, $item_tax_rate1_total);
|
||||||
}
|
|
||||||
|
|
||||||
$item_tax_rate2_total = $this->calcInclusiveLineTax($this->item->tax_rate2, $amount);
|
$item_tax_rate2_total = $this->calcInclusiveLineTax($this->item->tax_rate2, $amount);
|
||||||
|
|
||||||
$item_tax += $this->formatValue($item_tax_rate2_total, $this->currency->precision);
|
$item_tax += $this->formatValue($item_tax_rate2_total, $this->currency->precision);
|
||||||
|
|
||||||
if ($item_tax_rate2_total > 0) {
|
if($item_tax_rate2_total != 0)
|
||||||
$this->groupTax($this->item->tax_name2, $this->item->tax_rate2, $item_tax_rate2_total);
|
$this->groupTax($this->item->tax_name2, $this->item->tax_rate2, $item_tax_rate2_total);
|
||||||
}
|
|
||||||
|
|
||||||
$item_tax_rate3_total = $this->calcInclusiveLineTax($this->item->tax_rate3, $amount);
|
$item_tax_rate3_total = $this->calcInclusiveLineTax($this->item->tax_rate3, $amount);
|
||||||
|
|
||||||
$item_tax += $this->formatValue($item_tax_rate3_total, $this->currency->precision);
|
$item_tax += $this->formatValue($item_tax_rate3_total, $this->currency->precision);
|
||||||
|
|
||||||
if ($item_tax_rate3_total > 0) {
|
if($item_tax_rate3_total != 0)
|
||||||
$this->groupTax($this->item->tax_name3, $this->item->tax_rate3, $item_tax_rate3_total);
|
$this->groupTax($this->item->tax_name3, $this->item->tax_rate3, $item_tax_rate3_total);
|
||||||
}
|
|
||||||
|
|
||||||
$this->setTotalTaxes($this->formatValue($item_tax, $this->currency->precision));
|
$this->setTotalTaxes($this->formatValue($item_tax, $this->currency->precision));
|
||||||
|
|
||||||
@ -225,7 +223,12 @@ class InvoiceItemSumInclusive
|
|||||||
$item_tax = 0;
|
$item_tax = 0;
|
||||||
|
|
||||||
foreach ($this->line_items as $this->item) {
|
foreach ($this->line_items as $this->item) {
|
||||||
$amount = $this->item->line_total - ($this->item->line_total * ($this->invoice->discount / $this->sub_total));
|
|
||||||
|
if($this->sub_total == 0)
|
||||||
|
$amount = $this->item->line_total;
|
||||||
|
else
|
||||||
|
$amount = $this->item->line_total - ($this->item->line_total * ($this->invoice->discount / $this->sub_total));
|
||||||
|
|
||||||
$item_tax_rate1_total = $this->calcInclusiveLineTax($this->item->tax_rate1, $amount);
|
$item_tax_rate1_total = $this->calcInclusiveLineTax($this->item->tax_rate1, $amount);
|
||||||
|
|
||||||
$item_tax += $item_tax_rate1_total;
|
$item_tax += $item_tax_rate1_total;
|
||||||
|
@ -35,10 +35,9 @@ class InvoiceWorkflowSettings implements ShouldQueue
|
|||||||
* @param Invoice $invoice
|
* @param Invoice $invoice
|
||||||
* @param Client|null $client
|
* @param Client|null $client
|
||||||
*/
|
*/
|
||||||
public function __construct(Invoice $invoice, Client $client = null)
|
public function __construct(Invoice $invoice)
|
||||||
{
|
{
|
||||||
$this->invoice = $invoice;
|
$this->invoice = $invoice;
|
||||||
$this->client = $client ?? $invoice->client;
|
|
||||||
$this->base_repository = new BaseRepository();
|
$this->base_repository = new BaseRepository();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,6 +48,8 @@ class InvoiceWorkflowSettings implements ShouldQueue
|
|||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
|
$this->client = $this->invoice->client;
|
||||||
|
|
||||||
if ($this->client->getSetting('auto_archive_invoice')) {
|
if ($this->client->getSetting('auto_archive_invoice')) {
|
||||||
/* Throws: Payment amount xxx does not match invoice totals. */
|
/* Throws: Payment amount xxx does not match invoice totals. */
|
||||||
$this->base_repository->archive($this->invoice);
|
$this->base_repository->archive($this->invoice);
|
||||||
|
@ -205,7 +205,7 @@ class Import implements ShouldQueue
|
|||||||
|
|
||||||
$this->setInitialCompanyLedgerBalances();
|
$this->setInitialCompanyLedgerBalances();
|
||||||
|
|
||||||
$this->fixClientBalances();
|
// $this->fixClientBalances();
|
||||||
|
|
||||||
Mail::to($this->user)
|
Mail::to($this->user)
|
||||||
->send(new MigrationCompleted($this->company));
|
->send(new MigrationCompleted($this->company));
|
||||||
@ -779,6 +779,14 @@ class Import implements ShouldQueue
|
|||||||
CreditFactory::create($this->company->id, $modified['user_id'])
|
CreditFactory::create($this->company->id, $modified['user_id'])
|
||||||
);
|
);
|
||||||
|
|
||||||
|
//remove credit balance from ledger
|
||||||
|
if($credit->balance > 0 && $credit->client->balance > 0){
|
||||||
|
$client = $credit->client;
|
||||||
|
$client->balance -= $credit->balance;
|
||||||
|
$client->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
$key = "credits_{$resource['id']}";
|
$key = "credits_{$resource['id']}";
|
||||||
|
|
||||||
$this->ids['credits'][$key] = [
|
$this->ids['credits'][$key] = [
|
||||||
@ -1434,19 +1442,19 @@ class Import implements ShouldQueue
|
|||||||
/* In V4 we use negative invoices (credits) and add then into the client balance. In V5, these sit off ledger and are applied later.
|
/* In V4 we use negative invoices (credits) and add then into the client balance. In V5, these sit off ledger and are applied later.
|
||||||
This next section will check for credit balances and reduce the client balance so that the V5 balances are correct
|
This next section will check for credit balances and reduce the client balance so that the V5 balances are correct
|
||||||
*/
|
*/
|
||||||
private function fixClientBalances()
|
// private function fixClientBalances()
|
||||||
{
|
// {
|
||||||
|
|
||||||
Client::cursor()->each(function ($client) {
|
// Client::cursor()->each(function ($client) {
|
||||||
|
|
||||||
$credit_balance = $client->credits->where('is_deleted', false)->sum('balance');
|
// $credit_balance = $client->credits->where('is_deleted', false)->sum('balance');
|
||||||
|
|
||||||
if($credit_balance > 0){
|
// if($credit_balance > 0){
|
||||||
$client->balance += $credit_balance;
|
// $client->balance += $credit_balance;
|
||||||
$client->save();
|
// $client->save();
|
||||||
}
|
// }
|
||||||
|
|
||||||
});
|
// });
|
||||||
|
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
@ -92,6 +92,10 @@ class PaymentMigrationRepository extends BaseRepository
|
|||||||
}
|
}
|
||||||
|
|
||||||
$payment->status_id = $data['status_id'];
|
$payment->status_id = $data['status_id'];
|
||||||
|
|
||||||
|
if($payment->status_id == Payment::STATUS_CANCELLED)
|
||||||
|
$payment->is_deleted = true;
|
||||||
|
|
||||||
$payment->deleted_at = $data['deleted_at'] ?: null;
|
$payment->deleted_at = $data['deleted_at'] ?: null;
|
||||||
$payment->save();
|
$payment->save();
|
||||||
|
|
||||||
@ -113,20 +117,26 @@ class PaymentMigrationRepository extends BaseRepository
|
|||||||
|
|
||||||
$payment->invoices()->saveMany($invoices);
|
$payment->invoices()->saveMany($invoices);
|
||||||
|
|
||||||
$payment->invoices->each(function ($inv) use ($invoice_totals, $refund_totals) {
|
$payment->invoices->each(function ($inv) use ($invoice_totals, $refund_totals, $payment) {
|
||||||
|
|
||||||
$inv->pivot->amount = $invoice_totals;
|
|
||||||
$inv->pivot->refunded = $refund_totals;
|
|
||||||
$inv->pivot->save();
|
|
||||||
|
|
||||||
$inv->paid_to_date += $invoice_totals;
|
if($payment->status_id != Payment::STATUS_CANCELLED || !$payment->is_deleted)
|
||||||
|
{
|
||||||
|
$inv->pivot->amount = $invoice_totals;
|
||||||
|
$inv->pivot->refunded = $refund_totals;
|
||||||
|
$inv->pivot->save();
|
||||||
|
|
||||||
if($inv->balance > 0)
|
$inv->paid_to_date += $invoice_totals;
|
||||||
$inv->balance -= $invoice_totals;
|
$inv->balance -= $invoice_totals;
|
||||||
|
|
||||||
$inv->balance = max(0, $inv->balance);
|
|
||||||
|
|
||||||
$inv->save();
|
if($inv->status_id == Invoice::STATUS_PAID)
|
||||||
|
$inv->balance = 0;
|
||||||
|
|
||||||
|
// if($inv->balance > 0)
|
||||||
|
// $inv->balance = max(0, $inv->balance);
|
||||||
|
|
||||||
|
$inv->save();
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
namespace App\Services\Invoice;
|
namespace App\Services\Invoice;
|
||||||
|
|
||||||
use App\Jobs\Entity\CreateEntityPdf;
|
use App\Jobs\Entity\CreateEntityPdf;
|
||||||
|
use App\Jobs\Invoice\InvoiceWorkflowSettings;
|
||||||
use App\Jobs\Util\UnlinkFile;
|
use App\Jobs\Util\UnlinkFile;
|
||||||
use App\Models\CompanyGateway;
|
use App\Models\CompanyGateway;
|
||||||
use App\Models\Expense;
|
use App\Models\Expense;
|
||||||
@ -239,6 +240,9 @@ class InvoiceService
|
|||||||
public function updateStatus()
|
public function updateStatus()
|
||||||
{
|
{
|
||||||
if ((int)$this->invoice->balance == 0) {
|
if ((int)$this->invoice->balance == 0) {
|
||||||
|
|
||||||
|
InvoiceWorkflowSettings::dispatch($this->invoice);
|
||||||
|
|
||||||
$this->setStatus(Invoice::STATUS_PAID);
|
$this->setStatus(Invoice::STATUS_PAID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ namespace App\Services\Invoice;
|
|||||||
use App\Events\Invoice\InvoiceWasPaid;
|
use App\Events\Invoice\InvoiceWasPaid;
|
||||||
use App\Events\Payment\PaymentWasCreated;
|
use App\Events\Payment\PaymentWasCreated;
|
||||||
use App\Factory\PaymentFactory;
|
use App\Factory\PaymentFactory;
|
||||||
|
use App\Jobs\Invoice\InvoiceWorkflowSettings;
|
||||||
use App\Jobs\Payment\EmailPayment;
|
use App\Jobs\Payment\EmailPayment;
|
||||||
use App\Models\Invoice;
|
use App\Models\Invoice;
|
||||||
use App\Models\Payment;
|
use App\Models\Payment;
|
||||||
@ -90,6 +91,8 @@ class MarkPaid extends AbstractService
|
|||||||
->updatePaidToDate($payment->amount)
|
->updatePaidToDate($payment->amount)
|
||||||
->save();
|
->save();
|
||||||
|
|
||||||
|
InvoiceWorkflowSettings::dispatchNow($this->invoice);
|
||||||
|
|
||||||
return $this->invoice;
|
return $this->invoice;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -275,6 +275,7 @@ class InvoiceInclusiveTest extends TestCase
|
|||||||
$this->assertEquals($this->invoice_calc->getSubTotal(), 19);
|
$this->assertEquals($this->invoice_calc->getSubTotal(), 19);
|
||||||
$this->assertEquals($this->invoice_calc->getTotalDiscount(), 0.95);
|
$this->assertEquals($this->invoice_calc->getTotalDiscount(), 0.95);
|
||||||
$this->assertEquals($this->invoice_calc->getTotalTaxes(), 4.92);
|
$this->assertEquals($this->invoice_calc->getTotalTaxes(), 4.92);
|
||||||
|
nlog($this->invoice_calc->getTaxMap());
|
||||||
$this->assertEquals(count($this->invoice_calc->getTaxMap()), 1);
|
$this->assertEquals(count($this->invoice_calc->getTaxMap()), 1);
|
||||||
$this->assertEquals($this->invoice_calc->getTotal(), 18.05);
|
$this->assertEquals($this->invoice_calc->getTotal(), 18.05);
|
||||||
$this->assertEquals($this->invoice_calc->getBalance(), 18.05);
|
$this->assertEquals($this->invoice_calc->getBalance(), 18.05);
|
||||||
|
Loading…
Reference in New Issue
Block a user