mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Fixes some bugs and finished refactoring for calc method
This commit is contained in:
parent
d079a02bff
commit
3239431faa
@ -96,96 +96,6 @@ class CreateXInvoice implements ShouldQueue
|
|||||||
|
|
||||||
|
|
||||||
//Create line items and calculate taxes
|
//Create line items and calculate taxes
|
||||||
$taxtype1 = "";
|
|
||||||
switch ($company->tax_type1){
|
|
||||||
case "ZeroRate":
|
|
||||||
$taxtype1 = "Z";
|
|
||||||
break;
|
|
||||||
case "Tax Exempt":
|
|
||||||
$taxtype1 = "E";
|
|
||||||
break;
|
|
||||||
case "Reversal of tax liabilty":
|
|
||||||
$taxtype1 = "AE";
|
|
||||||
break;
|
|
||||||
case "intra-community delivery":
|
|
||||||
$taxtype1 = "K";
|
|
||||||
break;
|
|
||||||
case "Out of EU":
|
|
||||||
$taxtype1 = "G";
|
|
||||||
break;
|
|
||||||
case "Outside the tax scope":
|
|
||||||
$taxtype1 = "O";
|
|
||||||
break;
|
|
||||||
case "Canary Islands":
|
|
||||||
$taxtype1 = "L";
|
|
||||||
break;
|
|
||||||
case "Ceuta / Melila":
|
|
||||||
$taxtype1 = "M";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
$taxtype1 = "S";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
$taxtype2 = "";
|
|
||||||
switch ($company->tax_type2){
|
|
||||||
case "ZeroRate":
|
|
||||||
$taxtype2 = "Z";
|
|
||||||
break;
|
|
||||||
case "Tax Exempt":
|
|
||||||
$taxtype2 = "E";
|
|
||||||
break;
|
|
||||||
case "Reversal of tax liabilty":
|
|
||||||
$taxtype2 = "AE";
|
|
||||||
break;
|
|
||||||
case "intra-community delivery":
|
|
||||||
$taxtype2 = "K";
|
|
||||||
break;
|
|
||||||
case "Out of EU":
|
|
||||||
$taxtype2 = "G";
|
|
||||||
break;
|
|
||||||
case "Outside the tax scope":
|
|
||||||
$taxtype2 = "O";
|
|
||||||
break;
|
|
||||||
case "Canary Islands":
|
|
||||||
$taxtype2 = "L";
|
|
||||||
break;
|
|
||||||
case "Ceuta / Melila":
|
|
||||||
$taxtype2 = "M";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
$taxtype2 = "S";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
$taxtype3 = "";
|
|
||||||
switch ($company->tax_type3){
|
|
||||||
case "ZeroRate":
|
|
||||||
$taxtype3 = "Z";
|
|
||||||
break;
|
|
||||||
case "Tax Exempt":
|
|
||||||
$taxtype3 = "E";
|
|
||||||
break;
|
|
||||||
case "Reversal of tax liabilty":
|
|
||||||
$taxtype3 = "AE";
|
|
||||||
break;
|
|
||||||
case "intra-community delivery":
|
|
||||||
$taxtype3 = "K";
|
|
||||||
break;
|
|
||||||
case "Out of EU":
|
|
||||||
$taxtype3 = "G";
|
|
||||||
break;
|
|
||||||
case "Outside the tax scope":
|
|
||||||
$taxtype3 = "O";
|
|
||||||
break;
|
|
||||||
case "Canary Islands":
|
|
||||||
$taxtype3 = "L";
|
|
||||||
break;
|
|
||||||
case "Ceuta / Melila":
|
|
||||||
$taxtype3 = "M";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
$taxtype3 = "S";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
foreach ($invoice->line_items as $index => $item){
|
foreach ($invoice->line_items as $index => $item){
|
||||||
$xrechnung->addNewPosition($index)
|
$xrechnung->addNewPosition($index)
|
||||||
->setDocumentPositionProductDetails($item->notes)
|
->setDocumentPositionProductDetails($item->notes)
|
||||||
@ -197,52 +107,50 @@ class CreateXInvoice implements ShouldQueue
|
|||||||
else{
|
else{
|
||||||
$xrechnung->setDocumentPositionQuantity($item->quantity, "H87");
|
$xrechnung->setDocumentPositionQuantity($item->quantity, "H87");
|
||||||
}
|
}
|
||||||
// According to european law, each artical can only have one tax percentage
|
|
||||||
if (empty($item->tax_name1) && empty($item->tax_name2) && empty($item->tax_name3)){
|
// According to european law, each line item can only have one tax rate
|
||||||
if (!empty($invoice->tax_name1)){
|
if (!empty($item->tax_name1)){
|
||||||
$xrechnung->addDocumentPositionTax($taxtype1, 'VAT', $invoice->tax_rate1);
|
$xrechnung->addDocumentPositionTax(getTaxType($item->tax_name1), 'VAT', $item->tax_rate1);
|
||||||
}
|
}
|
||||||
elseif (!empty($invoice->tax_name2)){
|
elseif (!empty($item->tax_name2)){
|
||||||
$xrechnung->addDocumentPositionTax($taxtype2, 'VAT', $invoice->tax_rate2);
|
$xrechnung->addDocumentPositionTax(getTaxType($item->tax_name2), 'VAT', $item->tax_rate2);
|
||||||
}
|
}
|
||||||
elseif (!empty($invoice->tax_name3)){
|
elseif (!empty($item->tax_name3)){
|
||||||
$xrechnung->addDocumentPositionTax($taxtype3, 'VAT', $invoice->tax_rate3);
|
$xrechnung->addDocumentPositionTax(getTaxType($item->tax_name3), 'VAT', $item->tax_rate3);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
nlog("Can't add correct tax position");
|
nlog("Can't add correct tax position");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!empty($invoice->tax_name1)){
|
||||||
|
$xrechnung->addDocumentPositionTax(getTaxType($invoice->tax_name1), 'VAT', $invoice->tax_rate1);
|
||||||
}
|
}
|
||||||
else {
|
elseif (!empty($invoice->tax_name2)){
|
||||||
if ($item->tax_name1 != "" && $item->tax_name2 == "" && $item->tax_name3 == ""){
|
$xrechnung->addDocumentPositionTax(getTaxType($invoice->tax_name2), 'VAT', $invoice->tax_rate2);
|
||||||
$xrechnung->addDocumentPositionTax($taxtype1, 'VAT', $item->tax_rate1);
|
|
||||||
}
|
|
||||||
elseif ($item->tax_name1 == "" && $item->tax_name2 != "" && $item->tax_name3 == ""){
|
|
||||||
$xrechnung->addDocumentPositionTax($taxtype2, 'VAT', $item->tax_rate2);
|
|
||||||
}
|
|
||||||
elseif ($item->tax_name1 == "" && $item->tax_name2 == "" && $item->tax_name3 != ""){
|
|
||||||
$xrechnung->addDocumentPositionTax($taxtype3, 'VAT', $item->tax_rate3);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
elseif (!empty($invoice->tax_name3)){
|
||||||
|
$xrechnung->addDocumentPositionTax(getTaxType($invoice->tax_name3), 'VAT', $item->tax_rate3);
|
||||||
|
} else{
|
||||||
|
nlog("Can't add correct tax position");}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if ($invoice->isPartial()){
|
if ($invoice->isPartial()){
|
||||||
$xrechnung->setDocumentSummation($invoice->amount, $invoice->amount-$invoice->balance, $invoicingdata->getSubTotal(), $invoicingdata->getTotalSurcharges(), $invoicingdata->getTotalDiscount(), $invoicingdata->getSubTotal(), $invoicingdata->getItemTotalTaxes(), null, $invoice->partial);
|
$xrechnung->setDocumentSummation($invoice->amount, $invoice->amount-$invoice->balance, $invoicingdata->getSubTotal(), $invoicingdata->getTotalSurcharges(), $invoicingdata->getTotalDiscount(), $invoicingdata->getSubTotal(), $invoicingdata->getItemTotalTaxes(), null, $invoice->partial);
|
||||||
} else {
|
} else {
|
||||||
$xrechnung->setDocumentSummation($invoice->amount, $invoice->amount-$invoice->balance, $invoicingdata->getSubTotal(), $invoicingdata->getTotalSurcharges(), $invoicingdata->getTotalDiscount(), $invoicingdata->getSubTotal(), $invoicingdata->getItemTotalTaxes(), null, 0.0);
|
$xrechnung->setDocumentSummation($invoice->amount, $invoice->amount-$invoice->balance, $invoicingdata->getSubTotal(), $invoicingdata->getTotalSurcharges(), $invoicingdata->getTotalDiscount(), $invoicingdata->getSubTotal(), $invoicingdata->getItemTotalTaxes(), null, 0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count($invoicingdata->getTaxMap()) > 0){
|
foreach ($invoicingdata->getTaxMap() as $item){
|
||||||
$tax = explode(" ", $invoicingdata->getTaxMap()[0]["name"]);
|
$tax = explode(" ", $item["name"]);
|
||||||
$xrechnung->addDocumentTax($taxtype1, "VAT", $invoicingdata->getTaxMap()[0]["total"]/(explode("%", end($tax))[0]/100), $invoicingdata->getTaxMap()[0]["total"], explode("%", end($tax))[0]);
|
$xrechnung->addDocumentTax(getTaxType(""), "VAT", $item["total"]/(explode("%", end($tax))[0]/100), $item["total"], explode("%", end($tax))[0]);
|
||||||
|
// TODO: Add correct tax type within getTaxType
|
||||||
}
|
}
|
||||||
if (count($invoicingdata->getTaxMap()) > 1) {
|
foreach ($invoicingdata->getTotalTaxMap() as $item){
|
||||||
$tax = explode(" ", $invoicingdata->getTaxMap()[1]["name"]);
|
$tax = explode(" ", $item["name"]);
|
||||||
$xrechnung->addDocumentTax($taxtype2, "VAT", $invoicingdata->getTaxMap()[1]["total"]/(explode("%", end($tax))[0]/100), $invoicingdata->getTaxMap()[1]["total"], explode("%", end($tax))[0]);
|
$xrechnung->addDocumentTax(getTaxType(""), "VAT", $item["total"]/(explode("%", end($tax))[0]/100), $item["total"], explode("%", end($tax))[0]);
|
||||||
}
|
// TODO: Add correct tax type within getTaxType
|
||||||
if (count($invoicingdata->getTaxMap()) > 2) {
|
|
||||||
$tax = explode(" ", $invoicingdata->getTaxMap()[2]["name"]);
|
|
||||||
$xrechnung->addDocumentTax($taxtype3, "VAT", $invoicingdata->getTaxMap()[2]["total"]/(explode("%", end($tax))[0]/100), $invoicingdata->getTaxMap()[2]["total"], explode("%", end($tax))[0]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$disk = config('filesystems.default');
|
$disk = config('filesystems.default');
|
||||||
@ -270,3 +178,38 @@ class CreateXInvoice implements ShouldQueue
|
|||||||
return $client->invoice_filepath($invoice->invitations->first()).$invoice->getFileName("xml");
|
return $client->invoice_filepath($invoice->invitations->first()).$invoice->getFileName("xml");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getTaxType(string $name)
|
||||||
|
{
|
||||||
|
$taxtype = "";
|
||||||
|
switch ($name){
|
||||||
|
case "ZeroRate":
|
||||||
|
$taxtype = "Z";
|
||||||
|
break;
|
||||||
|
case "Tax Exempt":
|
||||||
|
$taxtype = "E";
|
||||||
|
break;
|
||||||
|
case "Reversal of tax liabilty":
|
||||||
|
$taxtype = "AE";
|
||||||
|
break;
|
||||||
|
case "intra-community delivery":
|
||||||
|
$taxtype = "K";
|
||||||
|
break;
|
||||||
|
case "Out of EU":
|
||||||
|
$taxtype = "G";
|
||||||
|
break;
|
||||||
|
case "Outside the tax scope":
|
||||||
|
$taxtype = "O";
|
||||||
|
break;
|
||||||
|
case "Canary Islands":
|
||||||
|
$taxtype = "L";
|
||||||
|
break;
|
||||||
|
case "Ceuta / Melila":
|
||||||
|
$taxtype = "M";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$taxtype = "S";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return $taxtype;
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user