|
|
@@ -8,10 +8,34 @@ class Route_UrlAction_JPK extends RouteBase {
|
|
|
private $REFERER, $LAST_REFERER;
|
|
|
private $JPK, $BO;
|
|
|
private $NIPerrors = array();
|
|
|
- private $JPK_VAT_Wariant = null;
|
|
|
+ private $JPK_wersjaSchemy = null;
|
|
|
+
|
|
|
private $tns = [
|
|
|
- 2 => "http://jpk.mf.gov.pl/wzor/2016/10/26/10261/",
|
|
|
- 3 => "http://jpk.mf.gov.pl/wzor/2017/11/13/1113/",
|
|
|
+ 'JPK_VAT (2)' => "http://jpk.mf.gov.pl/wzor/2016/10/26/10261/",
|
|
|
+ 'JPK_VAT (3)' => "http://jpk.mf.gov.pl/wzor/2017/11/13/1113/",
|
|
|
+ 'JPK_V7M (1)' => "http://crd.gov.pl/wzor/2020/05/08/9393/",
|
|
|
+ 'JPK_V7K (1)' => "http://crd.gov.pl/wzor/2020/05/08/9394/",
|
|
|
+ ];
|
|
|
+
|
|
|
+
|
|
|
+ private $JPK_Wariant = [
|
|
|
+ '1-0' => 2,
|
|
|
+ '1-1' => 3,
|
|
|
+ '1-2E' => 1,
|
|
|
+ ];
|
|
|
+
|
|
|
+ private $kodySystemowe = [
|
|
|
+ 'JPK_VAT (2)' => '1-0',
|
|
|
+ 'JPK_VAT (3)' => '1-1',
|
|
|
+ 'JPK_V7M (1)' => '1-2E',
|
|
|
+ 'JPK_V7K (1)' => '1-2E',
|
|
|
+ ];
|
|
|
+
|
|
|
+ private $xsd = [
|
|
|
+ 'JPK_VAT (2)' => 'Schemat_JPK_VAT(2)_v1-0.xsd',
|
|
|
+ 'JPK_VAT (3)' => 'Schemat_JPK_VAT(3)_v1-1.xsd',
|
|
|
+ 'JPK_V7M (1)' => 'Schemat_JPK_V7M(1)_v1-2E.xsd',
|
|
|
+ 'JPK_V7K (1)' => 'Schemat_JPK_V7K(1)_v1-2E.xsd',
|
|
|
];
|
|
|
|
|
|
public function handleAuth() {
|
|
|
@@ -30,7 +54,7 @@ class Route_UrlAction_JPK extends RouteBase {
|
|
|
else throw new Exception("Błąd spójności danych");
|
|
|
if ($this->JPK['A_STATUS'] != 'WAITING') {
|
|
|
if (!$this->JPK['MONTH']) throw new Exception("Błąd daty w rekordzie JPK_VAT");
|
|
|
- $this->JPK_VAT_Wariant = self::getWariant($this->JPK['MONTH']);
|
|
|
+ $this->JPK_wersjaSchemy = self::getWersjaSchemy($this->JPK['MONTH']);
|
|
|
}
|
|
|
} catch (Exception $e) {
|
|
|
SE_Layout::gora();
|
|
|
@@ -46,10 +70,12 @@ class Route_UrlAction_JPK extends RouteBase {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private static function getWariant($month) {
|
|
|
- $year = date("Y", strtotime($month));
|
|
|
- if ($year < 2018) return 2;
|
|
|
- else return 3;
|
|
|
+ private static function getWersjaSchemy($month) {
|
|
|
+ $_year = date("Y", strtotime($month));
|
|
|
+ $_month = date("m", strtotime($month));
|
|
|
+ if ($_year < 2018) return '1-0';
|
|
|
+ elseif ($_year < 2020 || ($_year == 2020 && $_month < 10)) return '1-1';
|
|
|
+ else return '1-2E';
|
|
|
}
|
|
|
|
|
|
private function initialize() {
|
|
|
@@ -64,19 +90,19 @@ class Route_UrlAction_JPK extends RouteBase {
|
|
|
switch ($purpose) {
|
|
|
case "1":
|
|
|
$lastMonth = DB::getPDO()->fetchValue("select max(MONTH) from JPK where ID_BILLING_OWNER='{$this->JPK['ID_BILLING_OWNER']}' and TYPE='{$this->JPK['TYPE']}'
|
|
|
- and ((MONTH < '2018-01' and PURPOSE='1') or (MONTH >= '2018-01' and PURPOSE = '0'))");
|
|
|
+ and (((MONTH < '2018-01' or MONTH >= '2020-10') and PURPOSE='1') or (MONTH >= '2018-01' and MONTH < '2020-10' and PURPOSE = '0'))");
|
|
|
if (strtotime($month) <= strtotime($lastMonth)) throw new Exception("błędny miesiąc (deklaracja z tego okresu lub późniejszego już istnieje)");
|
|
|
break;
|
|
|
case "2":
|
|
|
$JPKexists = DB::getPDO()->fetchValue("select ID from JPK where ID_BILLING_OWNER='{$this->JPK['ID_BILLING_OWNER']}' and TYPE='{$this->JPK['TYPE']}' and MONTH='{$month}'
|
|
|
- and ((MONTH < '2018-01' and PURPOSE='1') or (MONTH >= '2018-01' and PURPOSE = 0))");
|
|
|
+ and (((MONTH < '2018-01' or MONTH >= '2020-10') and PURPOSE='1') or (MONTH >= '2018-01' and MONTH < '2020-10' and PURPOSE = 0))");
|
|
|
if (!$JPKexists) throw new Exception("brak deklaracji z tego okresu - nie ma czego korygować");
|
|
|
break;
|
|
|
default:
|
|
|
throw new Exception("błędne określenie celu złożenia deklaracji");
|
|
|
}
|
|
|
|
|
|
- if (self::getWariant($month) > 2) {
|
|
|
+ if (self::getWersjaSchemy($month) == '1-1') {
|
|
|
if ($purpose == 1) $purpose = (int) 0;
|
|
|
else $purpose = DB::getPDO()->fetchValue("select max(PURPOSE) + 1 from JPK where ID_BILLING_OWNER='{$this->JPK['ID_BILLING_OWNER']}' and TYPE='{$this->JPK['TYPE']}' and MONTH='{$month}'");
|
|
|
}
|
|
|
@@ -110,6 +136,7 @@ class Route_UrlAction_JPK extends RouteBase {
|
|
|
<?php
|
|
|
}
|
|
|
} else {
|
|
|
+ $month = date('Y-m', strtotime('-1 month'));
|
|
|
?>
|
|
|
<div class="container" style="margin-top:20px">
|
|
|
<form class="form-horizontal" method="post">
|
|
|
@@ -126,7 +153,7 @@ class Route_UrlAction_JPK extends RouteBase {
|
|
|
<label class="col-sm-3 control-label">Miesiąc, którego dotyczy deklaracja</label>
|
|
|
<div class="col-sm-2">
|
|
|
<div class="input-group">
|
|
|
- <input type="text" id="MONTH" class="form-control se_type-date" name="MONTH" value="2017-01" maxlength="7"/>
|
|
|
+ <input type="text" id="MONTH" class="form-control se_type-date" name="MONTH" value="<?=$month?>" max="<?=$month?>" maxlength="7"/>
|
|
|
<span class="input-group-addon">
|
|
|
<span class="glyphicon glyphicon-calendar"/>
|
|
|
</span>
|
|
|
@@ -175,8 +202,9 @@ format: 'YYYY-MM'
|
|
|
}
|
|
|
|
|
|
private $fieldsDescrJPK_VAT = [
|
|
|
- 2 => [
|
|
|
+ '1-0' => [
|
|
|
"KodFormularza" => "Kod formularza",
|
|
|
+ "kodSystemowy" => "Kod systemowy",
|
|
|
"WariantFormularza" => "Wariant formularza",
|
|
|
"CelZlozenia" => "Cel złożenia",
|
|
|
"DataWytworzeniaJPK" => "Data wytworzenia JPK",
|
|
|
@@ -202,8 +230,9 @@ format: 'YYYY-MM'
|
|
|
"LiczbaWierszyZakupow" => "Liczba dokumentów zakupu",
|
|
|
"PodatekNaliczony" => "Podatek naliczony",
|
|
|
],
|
|
|
- 3 => [
|
|
|
+ '1-1' => [
|
|
|
"KodFormularza" => "Kod formularza",
|
|
|
+ "kodSystemowy" => "Kod systemowy",
|
|
|
"WariantFormularza" => "Wariant formularza",
|
|
|
"CelZlozenia" => "Cel złożenia",
|
|
|
"DataWytworzeniaJPK" => "Data wytworzenia JPK",
|
|
|
@@ -218,6 +247,26 @@ format: 'YYYY-MM'
|
|
|
"LiczbaWierszyZakupow" => "Liczba dokumentów zakupu",
|
|
|
"PodatekNaliczony" => "Podatek naliczony",
|
|
|
],
|
|
|
+ '1-2E' => [
|
|
|
+ "KodFormularza" => "Kod formularza",
|
|
|
+ "kodSystemowy" => "Kod systemowy",
|
|
|
+ "WariantFormularza" => "Wariant formularza",
|
|
|
+ "DataWytworzeniaJPK" => "Data wytworzenia JPK",
|
|
|
+ "NazwaSystemu" => "Nazwa systemu",
|
|
|
+ "CelZlozenia" => "Cel złożenia",
|
|
|
+ "KodUrzedu" => "Kod urzędu",
|
|
|
+ "Rok" => "Rok",
|
|
|
+ "Miesiac" => "Miesiąc",
|
|
|
+ "NIP" => "NIP",
|
|
|
+ "PelnaNazwa" => "Pełna nazwa",
|
|
|
+ "Email" => "Adres email",
|
|
|
+ "Deklaracja" => "Deklaracja VAT",
|
|
|
+ "LiczbaWierszySprzedazy" => "Liczba dokumenów sprzedaży",
|
|
|
+ "PodatekNalezny" => "Podatek należny",
|
|
|
+ "LiczbaWierszyZakupow" => "Liczba dokumentów zakupu",
|
|
|
+ "PodatekNaliczony" => "Podatek naliczony",
|
|
|
+
|
|
|
+ ],
|
|
|
];
|
|
|
|
|
|
private static function getNamespaces($xml) {
|
|
|
@@ -237,12 +286,13 @@ format: 'YYYY-MM'
|
|
|
$summaryJPK_VAT = $this->getSummaryJPK_VAT($xml);
|
|
|
|
|
|
$result['KodFormularza'] = $xml->xpath('/tns:JPK/tns:Naglowek/tns:KodFormularza')[0];
|
|
|
+ $result['kodSystemowy'] = $xml->xpath('/tns:JPK/tns:Naglowek/tns:KodFormularza/@kodSystemowy')[0];
|
|
|
$result['WariantFormularza'] = $xml->xpath('/tns:JPK/tns:Naglowek/tns:WariantFormularza')[0];
|
|
|
$result['CelZlozenia'] = $xml->xpath('/tns:JPK/tns:Naglowek/tns:CelZlozenia')[0];
|
|
|
$result['DataWytworzeniaJPK'] = $xml->xpath('/tns:JPK/tns:Naglowek/tns:DataWytworzeniaJPK')[0];
|
|
|
- $result['DataOd'] = $xml->xpath('/tns:JPK/tns:Naglowek/tns:DataOd')[0];
|
|
|
- $result['DataDo'] = $xml->xpath('/tns:JPK/tns:Naglowek/tns:DataDo')[0];
|
|
|
- if ($this->JPK_VAT_Wariant == 2) {
|
|
|
+ if ($this->JPK_wersjaSchemy == '1-0') {
|
|
|
+ $result['DataOd'] = $xml->xpath('/tns:JPK/tns:Naglowek/tns:DataOd')[0];
|
|
|
+ $result['DataDo'] = $xml->xpath('/tns:JPK/tns:Naglowek/tns:DataDo')[0];
|
|
|
$result['DomyslnyKodWaluty'] = $xml->xpath('/tns:JPK/tns:Naglowek/tns:DomyslnyKodWaluty')[0];
|
|
|
$result['KodUrzedu'] = $xml->xpath('/tns:JPK/tns:Naglowek/tns:KodUrzedu')[0];
|
|
|
$result['NIP'] = $xml->xpath('/tns:JPK/tns:Podmiot1/tns:IdentyfikatorPodmiotu/etd:NIP')[0];
|
|
|
@@ -258,16 +308,36 @@ format: 'YYYY-MM'
|
|
|
$result['Miejscowosc'] = $xml->xpath('/tns:JPK/tns:Podmiot1/tns:AdresPodmiotu/tns:Miejscowosc')[0];
|
|
|
$result['KodPocztowy'] = $xml->xpath('/tns:JPK/tns:Podmiot1/tns:AdresPodmiotu/tns:KodPocztowy')[0];
|
|
|
$result['Poczta'] = $xml->xpath('/tns:JPK/tns:Podmiot1/tns:AdresPodmiotu/tns:Poczta')[0];
|
|
|
- } elseif ($this->JPK_VAT_Wariant == 3) {
|
|
|
+ $result['LiczbaWierszySprzedazy'] = $summaryJPK_VAT['LiczbaWierszySprzedazy'] ?: "";
|
|
|
+ $result['PodatekNalezny'] = $summaryJPK_VAT['LiczbaWierszySprzedazy'] ? number_format($summaryJPK_VAT['PodatekNalezny'], 2, ',', '.'): "";
|
|
|
+ $result['LiczbaWierszyZakupow'] = $summaryJPK_VAT['LiczbaWierszyZakupow'] ?: "";
|
|
|
+ $result['PodatekNaliczony'] = $summaryJPK_VAT['LiczbaWierszyZakupow'] ? number_format($summaryJPK_VAT['PodatekNaliczony'], 2, ',', '.'): "";
|
|
|
+ } elseif ($this->JPK_wersjaSchemy == '1-1') {
|
|
|
+ $result['DataOd'] = $xml->xpath('/tns:JPK/tns:Naglowek/tns:DataOd')[0];
|
|
|
+ $result['DataDo'] = $xml->xpath('/tns:JPK/tns:Naglowek/tns:DataDo')[0];
|
|
|
$result['NazwaSystemu'] = $xml->xpath('/tns:JPK/tns:Naglowek/tns:NazwaSystemu')[0];
|
|
|
$result['NIP'] = $xml->xpath('/tns:JPK/tns:Podmiot1/tns:NIP')[0];
|
|
|
$result['PelnaNazwa'] = $xml->xpath('/tns:JPK/tns:Podmiot1/tns:PelnaNazwa')[0];
|
|
|
$result['Email'] = $xml->xpath('/tns:JPK/tns:Podmiot1/tns:Email')[0];
|
|
|
+ $result['LiczbaWierszySprzedazy'] = $summaryJPK_VAT['LiczbaWierszySprzedazy'] ?: "";
|
|
|
+ $result['PodatekNalezny'] = $summaryJPK_VAT['LiczbaWierszySprzedazy'] ? number_format($summaryJPK_VAT['PodatekNalezny'], 2, ',', '.'): "";
|
|
|
+ $result['LiczbaWierszyZakupow'] = $summaryJPK_VAT['LiczbaWierszyZakupow'] ?: "";
|
|
|
+ $result['PodatekNaliczony'] = $summaryJPK_VAT['LiczbaWierszyZakupow'] ? number_format($summaryJPK_VAT['PodatekNaliczony'], 2, ',', '.'): "";
|
|
|
+ } elseif ($this->JPK_wersjaSchemy == '1-2E') {
|
|
|
+
|
|
|
+ $result['KodUrzedu'] = $xml->xpath('/tns:JPK/tns:Naglowek/tns:KodUrzedu')[0];
|
|
|
+ $result['Rok'] = $xml->xpath('/tns:JPK/tns:Naglowek/tns:Rok')[0];
|
|
|
+ $result['Miesiac'] = $xml->xpath('/tns:JPK/tns:Naglowek/tns:Miesiac')[0];
|
|
|
+ $result['NazwaSystemu'] = $xml->xpath('/tns:JPK/tns:Naglowek/tns:NazwaSystemu')[0];
|
|
|
+ $result['NIP'] = $xml->xpath('/tns:JPK/tns:Podmiot1/tns:OsobaNiefizyczna/tns:NIP')[0];
|
|
|
+ $result['PelnaNazwa'] = $xml->xpath('/tns:JPK/tns:Podmiot1/tns:OsobaNiefizyczna/tns:PelnaNazwa')[0];
|
|
|
+ $result['Email'] = $xml->xpath('/tns:JPK/tns:Podmiot1/tns:OsobaNiefizyczna/tns:Email')[0];
|
|
|
+ $result['Deklaracja'] = $xml->xpath('/tns:JPK/tns:Deklaracja') ? "Tak" : "Nie";
|
|
|
+ $result['LiczbaWierszySprzedazy'] = $summaryJPK_VAT['LiczbaWierszySprzedazy'];
|
|
|
+ $result['PodatekNalezny'] = number_format($summaryJPK_VAT['PodatekNalezny'], 2, ',', '.');
|
|
|
+ $result['LiczbaWierszyZakupow'] = $summaryJPK_VAT['LiczbaWierszyZakupow'];
|
|
|
+ $result['PodatekNaliczony'] = number_format($summaryJPK_VAT['PodatekNaliczony'], 2, ',', '.');
|
|
|
}
|
|
|
- $result['LiczbaWierszySprzedazy'] = $summaryJPK_VAT['LiczbaWierszySprzedazy'] ?: "";
|
|
|
- $result['PodatekNalezny'] = $summaryJPK_VAT['LiczbaWierszySprzedazy'] ? number_format($summaryJPK_VAT['PodatekNalezny'], 2, ',', '.'): "";
|
|
|
- $result['LiczbaWierszyZakupow'] = $summaryJPK_VAT['LiczbaWierszyZakupow'] ?: "";
|
|
|
- $result['PodatekNaliczony'] = $summaryJPK_VAT['LiczbaWierszyZakupow'] ? number_format($summaryJPK_VAT['PodatekNaliczony'], 2, ',', '.'): "";
|
|
|
|
|
|
return $result;
|
|
|
}
|
|
|
@@ -284,7 +354,7 @@ format: 'YYYY-MM'
|
|
|
<td width="27%">L1
|
|
|
<?php
|
|
|
if ($this->JPK['IN_L1']) {
|
|
|
- echo UI::h('a', [
|
|
|
+ echo '<br/>' . UI::h('a', [
|
|
|
'class' => "btn btn-xs btn-default",
|
|
|
'target' => "_blank",
|
|
|
'href' => $this->getLink('exportL1JPK', [ 'ID_JPK' => V::get('ID_JPK',0,$_GET,'int') ]),
|
|
|
@@ -310,7 +380,7 @@ format: 'YYYY-MM'
|
|
|
$OUT_MERGED = $this->showJPK_VAT($xmlOUT_MERGED);
|
|
|
}
|
|
|
|
|
|
- foreach ($this->fieldsDescrJPK_VAT[$this->JPK_VAT_Wariant] as $fieldKey => $fieldName) {
|
|
|
+ foreach ($this->fieldsDescrJPK_VAT[$this->JPK_wersjaSchemy] as $fieldKey => $fieldName) {
|
|
|
echo "<tr><td>{$fieldName}</td><td>";
|
|
|
if ($this->JPK['IN_INSERT']) echo $IN_INSERT[$fieldKey];
|
|
|
echo "</td><td>";
|
|
|
@@ -332,8 +402,9 @@ format: 'YYYY-MM'
|
|
|
$xml = simplexml_load_string($this->JPK['IN_L1']);
|
|
|
$ns = $xml->getNamespaces(true);
|
|
|
$this->validateJPK_VAT($xml);
|
|
|
- if ($this->JPK_VAT_Wariant == 2) $pelnaNazwa = $xml->Podmiot1->IdentyfikatorPodmiotu->children($ns['etd'])->PelnaNazwa;
|
|
|
- elseif ($this->JPK_VAT_Wariant == 3) $pelnaNazwa = $xml->Podmiot1->PelnaNazwa;
|
|
|
+ if ($this->JPK_wersjaSchemy == '1-0') $pelnaNazwa = $xml->Podmiot1->IdentyfikatorPodmiotu->children($ns['etd'])->PelnaNazwa;
|
|
|
+ elseif ($this->JPK_wersjaSchemy == '1-1') $pelnaNazwa = $xml->Podmiot1->PelnaNazwa;
|
|
|
+ elseif ($this->JPK_wersjaSchemy == '1-2E') $pelnaNazwa = $xml->Podmiot1->OsobaNiefizyczna->PelnaNazwa;
|
|
|
$fileName = preg_replace("/[: \.]/", "_", "JPK_VAT_{$this->JPK['MONTH']}_L1_" . str_replace('"', '', $pelnaNazwa)) . ".xml";
|
|
|
$output = $xml->asXml();
|
|
|
header("Content-Type: application/xml");
|
|
|
@@ -350,8 +421,9 @@ format: 'YYYY-MM'
|
|
|
$xml = simplexml_load_string($this->JPK['OUT_MERGED']);
|
|
|
$ns = $xml->getNamespaces(true);
|
|
|
$this->validateJPK_VAT($xml);
|
|
|
- if ($this->JPK_VAT_Wariant == 2) $pelnaNazwa = $xml->Podmiot1->IdentyfikatorPodmiotu->children($ns['etd'])->PelnaNazwa;
|
|
|
- elseif ($this->JPK_VAT_Wariant == 3) $pelnaNazwa = $xml->Podmiot1->PelnaNazwa;
|
|
|
+ if ($this->JPK_wersjaSchemy == '1-0') $pelnaNazwa = $xml->Podmiot1->IdentyfikatorPodmiotu->children($ns['etd'])->PelnaNazwa;
|
|
|
+ elseif ($this->JPK_wersjaSchemy == '1-1') $pelnaNazwa = $xml->Podmiot1->PelnaNazwa;
|
|
|
+ elseif ($this->JPK_wersjaSchemy == '1-2E') $pelnaNazwa = $xml->Podmiot1->OsobaNiefizyczna->PelnaNazwa;
|
|
|
$fileName = preg_replace("/[: \.]/", "_", "JPK_VAT_{$this->JPK['MONTH']}_" . str_replace('"', '', $pelnaNazwa)) . ".xml";
|
|
|
$output = $xml->asXml();
|
|
|
header("Content-Type: application/xml");
|
|
|
@@ -380,7 +452,7 @@ format: 'YYYY-MM'
|
|
|
<div class="container" style="margin-top:20px">
|
|
|
<form class="form-horizontal" method="post" target="_blank">
|
|
|
<legend>
|
|
|
- Podgląd deklaracjii JPK :: <?=$this->JPK['TYPE']?> - <?=$this->JPK['MONTH'] . " (" . ((($this->JPK_VAT_Wariant == 2 && $this->JPK['PURPOSE'] == 1) || ($this->JPK_VAT_Wariant == 3 && $this->JPK['PURPOSE'] == 0)) ? "pierwsze złożenie" : "korekta") . ")"?>
|
|
|
+ Podgląd deklaracjii JPK :: <?=$this->JPK['TYPE']?> - <?=$this->JPK['MONTH'] . " (" . ((($this->JPK_wersjaSchemy != '1-1' && $this->JPK['PURPOSE'] == 1) || ($this->JPK_wersjaSchemy == '1-1' && $this->JPK['PURPOSE'] == 0)) ? "pierwsze złożenie" : "korekta") . ")"?>
|
|
|
<span class="pull-right">
|
|
|
<?=$this->BO['name1']?>
|
|
|
</span>
|
|
|
@@ -412,7 +484,7 @@ format: 'YYYY-MM'
|
|
|
<div class="container" style="margin-top:20px">
|
|
|
<form class="form-horizontal" method="post" enctype="multipart/form-data">
|
|
|
<legend>
|
|
|
- Edycja deklaracji JPK :: <?=$this->JPK['TYPE']?> - <?=$this->JPK['MONTH']." (".((($this->JPK_VAT_Wariant == 2 && $this->JPK['PURPOSE'] == 1) || ($this->JPK_VAT_Wariant == 3 && $this->JPK['PURPOSE'] == 0)) ? "pierwsze złożenie" : "korekta").")"?>
|
|
|
+ Edycja deklaracji JPK :: <?=$this->JPK['TYPE']?> - <?=$this->JPK['MONTH']." (".((($this->JPK_wersjaSchemy != '1-1' && $this->JPK['PURPOSE'] == 1) || ($this->JPK_wersjaSchemy == '1-1' && $this->JPK['PURPOSE'] == 0)) ? "pierwsze złożenie" : "korekta").")"?>
|
|
|
<span class="pull-right">
|
|
|
<?=$this->BO['name1']?>
|
|
|
</span>
|
|
|
@@ -517,13 +589,30 @@ format: 'YYYY-MM'
|
|
|
}
|
|
|
|
|
|
private function getSummaryJPK_VAT($xml) {
|
|
|
- $ns = $xml->getNamespaces(true);
|
|
|
- $tns = $this->tns[$this->JPK_VAT_Wariant];
|
|
|
+ $ns = self::getNamespaces($xml);
|
|
|
+// $ns = $xml->getNamespaces(true);
|
|
|
+ $tns = $this->tns[(string) $xml->xpath('//tns:Naglowek/tns:KodFormularza/@kodSystemowy')[0]];
|
|
|
if (array_search($tns, $ns) === false) throw new Exception("Błąd struktury pliku XML - błędny namespace");
|
|
|
|
|
|
- $PodatekNaleznyFields = array("K_16" => "1", "K_18" => "1", "K_20" => "1", "K_24" => "1", "K_26" => "1", "K_28" => "1",
|
|
|
- "K_30" => "1", "K_33" => "1", "K_35" => "1", "K_36" => "1", "K_37" => "1", "K_38" => "-1", "K_39" => "-1");
|
|
|
- $PodatekNaliczonyFields = array("K_44" => 1, "K_46" => 1, "K_47" => 1, "K_48" => 1, "K_49" => 1, "K_50" => 1);
|
|
|
+ switch ($this->JPK_wersjaSchemy) {
|
|
|
+ case '1-0':
|
|
|
+ case '1-1':
|
|
|
+ $PodatekNaleznyFields = array("K_16" => "1", "K_18" => "1", "K_20" => "1", "K_24" => "1", "K_26" => "1", "K_28" => "1",
|
|
|
+ "K_30" => "1", "K_33" => "1", "K_35" => "1", "K_36" => "1", "K_37" => "1", "K_38" => "-1", "K_39" => "-1");
|
|
|
+ $PodatekNaliczonyFields = array("K_44" => 1, "K_46" => 1, "K_47" => 1, "K_48" => 1, "K_49" => 1, "K_50" => 1);
|
|
|
+ $ewidencjaXpath = '/tns:JPK';
|
|
|
+ $Sprzedaz = $xml->SprzedazWiersz;
|
|
|
+ $Zakup = $xml->ZakupWiersz;
|
|
|
+ break;
|
|
|
+ case '1-2E':
|
|
|
+ $PodatekNaleznyFields = array("K_16" => "1", "K_18" => "1", "K_20" => "1", "K_24" => "1", "K_26" => "1", "K_28" => "1",
|
|
|
+ "K_30" => "1", "K_32" => "1", "K_33" => "1", "K_34" => "1", "K_35" => "-1", "K_36" => "-1");
|
|
|
+ $PodatekNaliczonyFields = array("K_41" => 1, "K_43" => 1, "K_44" => 1, "K_45" => 1, "K_46" => 1, "K_47" => 1);
|
|
|
+ $ewidencjaXpath = '/tns:JPK/tns:Ewidencja';
|
|
|
+ $Sprzedaz = $xml->Ewidencja->SprzedazWiersz;
|
|
|
+ $Zakup = $xml->Ewidencja->ZakupWiersz;
|
|
|
+ break;
|
|
|
+ }
|
|
|
|
|
|
$result = array(
|
|
|
"LiczbaWierszySprzedazy" => 0,
|
|
|
@@ -531,26 +620,27 @@ format: 'YYYY-MM'
|
|
|
"LiczbaWierszyZakupow" => 0,
|
|
|
"PodatekNaliczony" => 0);
|
|
|
|
|
|
- foreach ($xml->children($tns)->SprzedazWiersz as $SprzedazWiersz) {
|
|
|
+ foreach ($Sprzedaz as $SprzedazWiersz) {
|
|
|
+ $result["LiczbaWierszySprzedazy"]++;
|
|
|
+ if ($SprzedazWiersz->children($tns)->FP) continue;
|
|
|
foreach ($PodatekNaleznyFields as $PodatekNaleznyField => $sign) {
|
|
|
- if (isset($SprzedazWiersz->children($tns)->$PodatekNaleznyField)) {
|
|
|
- $result["PodatekNalezny"] += round((float) $SprzedazWiersz->children($tns)->$PodatekNaleznyField * $sign, 2);
|
|
|
+ if (isset($SprzedazWiersz->$PodatekNaleznyField)) {
|
|
|
+ $result["PodatekNalezny"] += round((float) $SprzedazWiersz->$PodatekNaleznyField * $sign, 2);
|
|
|
}
|
|
|
}
|
|
|
- $result["LiczbaWierszySprzedazy"]++;
|
|
|
}
|
|
|
|
|
|
- foreach ($xml->children($tns)->ZakupWiersz as $ZakupWiersz) {
|
|
|
+ foreach ($Zakup as $ZakupWiersz) {
|
|
|
foreach ($PodatekNaliczonyFields as $PodatekNaliczonyField => $sign) {
|
|
|
- if (isset($ZakupWiersz->children($tns)->$PodatekNaliczonyField)) {
|
|
|
- $result["PodatekNaliczony"] += round((float) $ZakupWiersz->children($tns)->$PodatekNaliczonyField * $sign, 2);
|
|
|
+ if (isset($ZakupWiersz->$PodatekNaliczonyField)) {
|
|
|
+ $result["PodatekNaliczony"] += round((float) $ZakupWiersz->$PodatekNaliczonyField * $sign, 2);
|
|
|
}
|
|
|
}
|
|
|
$result["LiczbaWierszyZakupow"]++;
|
|
|
}
|
|
|
|
|
|
- $result["PodatekNalezny"] = round($result["PodatekNalezny"], 2);
|
|
|
- $result["PodatekNaliczony"] = round($result["PodatekNaliczony"], 2);
|
|
|
+ $result["PodatekNalezny"] = number_format(round($result["PodatekNalezny"], 2), 2, '.', '');
|
|
|
+ $result["PodatekNaliczony"] = number_format(round($result["PodatekNaliczony"], 2), 2, '.', '');
|
|
|
return $result;
|
|
|
}
|
|
|
|
|
|
@@ -558,29 +648,59 @@ format: 'YYYY-MM'
|
|
|
$ns = self::getNamespaces($xml);
|
|
|
|
|
|
if ($xml->xpath('/tns:JPK/tns:Naglowek/tns:KodFormularza')[0] != "JPK_VAT") throw new Exception("Błędny typ deklaracji JPK");
|
|
|
- if ($xml->xpath('/tns:JPK/tns:Naglowek/tns:WariantFormularza')[0] != $this->JPK_VAT_Wariant) throw new Exception("Błędna wersja deklaracji JPK");
|
|
|
- if ($this->JPK_VAT_Wariant == 2) {
|
|
|
- if ($xml->xpath('/tns:JPK/tns:Naglowek/tns:CelZlozenia')[0] != $this->JPK['PURPOSE']) throw new Exception("Niezgodny cel złożenia deklaracji JPK");
|
|
|
- } elseif ($this->JPK_VAT_Wariant == 3) {
|
|
|
- if (((int) $xml->xpath('/tns:JPK/tns:Naglowek/tns:CelZlozenia')[0]) xor ((int) $this->JPK['PURPOSE'])) throw new Exception("Niezgodny cel złożenia deklaracji JPK");
|
|
|
+ $kodSystemowy = (string) $xml->xpath('/tns:JPK/tns:Naglowek/tns:KodFormularza/@kodSystemowy')[0];
|
|
|
+ if ($this->kodySystemowe[$kodSystemowy] != $this->JPK_wersjaSchemy) throw new Exception("Niewlasciwy kod systemowy deklaracji JPK");
|
|
|
+ if ($xml->xpath('/tns:JPK/tns:Naglowek/tns:WariantFormularza')[0] != $this->JPK_Wariant[$this->JPK_wersjaSchemy]) throw new Exception("Błędna wersja deklaracji JPK");
|
|
|
+
|
|
|
+ switch ($this->JPK_wersjaSchemy) {
|
|
|
+ case '1-0':
|
|
|
+ case '1-2E':
|
|
|
+ if ($xml->xpath('/tns:JPK/tns:Naglowek/tns:CelZlozenia')[0] != $this->JPK['PURPOSE']) throw new Exception("Niezgodny cel zlozenia deklaracji JPK");
|
|
|
+ break;
|
|
|
+ case '1-1':
|
|
|
+ if (((int) $xml->xpath('/tns:JPK/tns:Naglowek/tns:CelZlozenia')[0]) xor ((int) $this->JPK['PURPOSE'])) throw new Exception("Niezgodny cel zlozenia deklaracji JPK");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ switch ($this->JPK_wersjaSchemy) {
|
|
|
+ case '1-0':
|
|
|
+ case '1-1':
|
|
|
+ if ($xml->xpath('/tns:JPK/tns:Naglowek/tns:DataOd')[0] != ($this->JPK['MONTH'] . "-01")) throw new Exception("Bledna data 'od' deklaracji JPK");
|
|
|
+ if ($xml->xpath('/tns:JPK/tns:Naglowek/tns:DataDo')[0] != date("Y-m-d", strtotime($xml->xpath('/tns:JPK/tns:Naglowek/tns:DataOd')[0] . " + 1 month - 1 day"))) throw new Exception("Bledna data 'do' deklaracji JPK");
|
|
|
+ $ewidencjaXpath = '/tns:JPK';
|
|
|
+ break;
|
|
|
+ case '1-2E':
|
|
|
+ if ($xml->xpath('/tns:JPK/tns:Naglowek/tns:Rok')[0] != date('Y', strtotime($this->JPK['MONTH']))) throw new Exception("Bledny rok w deklaracji JPK");
|
|
|
+ if ($xml->xpath('/tns:JPK/tns:Naglowek/tns:Miesiac')[0] != date('m', strtotime($this->JPK['MONTH']))) throw new Exception("Bledny miesiac w deklaracji JPK");
|
|
|
+ $ewidencjaXpath = '/tns:JPK/tns:Ewidencja';
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ throw new Exception("Bledna wersja schemy");
|
|
|
}
|
|
|
- if ($xml->xpath('/tns:JPK/tns:Naglowek/tns:DataOd')[0] != ($this->JPK['MONTH'] . "-01")) throw new Exception("Błędna data 'od' deklaracji JPK");
|
|
|
- if ($xml->xpath('/tns:JPK/tns:Naglowek/tns:DataDo')[0] != date("Y-m-d", strtotime($xml->xpath('/tns:JPK/tns:Naglowek/tns:DataOd')[0] . " + 1 month - 1 day"))) throw new Exception("Błędna data 'do' deklaracji JPK");
|
|
|
- if ($this->JPK_VAT_Wariant == 2) {
|
|
|
- if ($xml->xpath('/tns:JPK/tns:Naglowek/tns:DomyslnyKodWaluty')[0] != "PLN") throw new Exception("Błędna waluta deklaracji JPK");
|
|
|
- if (trim(str_replace('-', '', $xml->xpath('/tns:JPK/tns:Podmiot1/tns:IdentyfikatorPodmiotu/etd:NIP')[0])) != trim(str_replace('-', '', $this->BO['nip']))) throw new Exception("Niezgodny NIP podmiotu w deklaracji JPK");
|
|
|
- } elseif ($this->JPK_VAT_Wariant == 3) {
|
|
|
- if (trim(str_replace('-', '', $xml->xpath('/tns:JPK/tns:Podmiot1/tns:NIP')[0])) != trim(str_replace('-', '', $this->BO['nip']))) throw new Exception("Niezgodny NIP podmiotu w deklaracji JPK");
|
|
|
- if (!$xml->Podmiot1->Email) unset($xml->Podmiot1->Email);
|
|
|
+
|
|
|
+ switch ($this->JPK_wersjaSchemy) {
|
|
|
+ case '1-0':
|
|
|
+ if ($xml->xpath('/tns:JPK/tns:Naglowek/tns:DomyslnyKodWaluty')[0] != "PLN") throw new Exception("Bledna waluta deklaracji JPK");
|
|
|
+ if (trim(str_replace('-', '', $xml->xpath('/tns:JPK/tns:Podmiot1/tns:IdentyfikatorPodmiotu/etd:NIP')[0])) != trim(str_replace('-', '', $this->BO['nip']))) throw new Exception("Niezgodny NIP podmiotu w deklaracji JPK");
|
|
|
+ break;
|
|
|
+ case '1-1':
|
|
|
+ if (trim(str_replace('-', '', $xml->xpath('/tns:JPK/tns:Podmiot1/tns:NIP')[0])) != trim(str_replace('-', '', $this->BO['nip']))) throw new Exception("Niezgodny NIP podmiotu w deklaracji JPK");
|
|
|
+ if (!$xml->Podmiot1->Email) unset($xml->Podmiot1->Email);
|
|
|
+ break;
|
|
|
+ case '1-2E':
|
|
|
+ if (trim(str_replace('-', '', $xml->xpath('/tns:JPK/tns:Podmiot1/tns:OsobaNiefizyczna/tns:NIP')[0])) != trim(str_replace('-', '', $this->BO['nip']))) throw new Exception("Niezgodny NIP podmiotu w deklaracji JPK");
|
|
|
+ if (!$xml->xpath('/tns:JPK/tns:Podmiot1/tns:OsobaNiefizyczna/tns:Email')) throw new Exception("Brak adresu email");
|
|
|
+ break;
|
|
|
}
|
|
|
+
|
|
|
$summaryJPK_VAT = $this->getSummaryJPK_VAT($xml);
|
|
|
if ($summaryJPK_VAT["LiczbaWierszySprzedazy"]) {
|
|
|
- if ($xml->xpath('/tns:JPK/tns:SprzedazCtrl/tns:LiczbaWierszySprzedazy')[0] != $summaryJPK_VAT["LiczbaWierszySprzedazy"]) throw new Exception("Brak spójności liczby wierszy sprzedaży w deklaracji JPK");
|
|
|
- if (((float) $xml->xpath('/tns:JPK/tns:SprzedazCtrl/tns:PodatekNalezny')[0]) != $summaryJPK_VAT["PodatekNalezny"]) throw new Exception("Brak spójności wartości podatku należnego w deklaracji JPK");
|
|
|
+ if ($xml->xpath($ewidencjaXpath . '/tns:SprzedazCtrl/tns:LiczbaWierszySprzedazy')[0] != $summaryJPK_VAT["LiczbaWierszySprzedazy"]) throw new Exception("Brak spójności liczby wierszy sprzedaży w deklaracji JPK");
|
|
|
+ if (((float) $xml->xpath($ewidencjaXpath . '/tns:SprzedazCtrl/tns:PodatekNalezny')[0]) != $summaryJPK_VAT["PodatekNalezny"]) throw new Exception("Brak spójności wartości podatku należnego w deklaracji JPK");
|
|
|
}
|
|
|
if ($summaryJPK_VAT["LiczbaWierszyZakupow"]) {
|
|
|
- if ($xml->xpath('/tns:JPK/tns:ZakupCtrl/tns:LiczbaWierszyZakupow')[0] != $summaryJPK_VAT["LiczbaWierszyZakupow"]) throw new Exception("Brak spójności liczby wierszy zakupów w deklaracji JPK");
|
|
|
- if (((float) $xml->xpath('/tns:JPK/tns:ZakupCtrl/tns:PodatekNaliczony')[0]) != $summaryJPK_VAT["PodatekNaliczony"]) throw new Exception("Brak spójności wartości podatku naliczonego w deklaracji JPK");
|
|
|
+ if ($xml->xpath($ewidencjaXpath . '/tns:ZakupCtrl/tns:LiczbaWierszyZakupow')[0] != $summaryJPK_VAT["LiczbaWierszyZakupow"]) throw new Exception("Brak spójności liczby wierszy zakupów w deklaracji JPK");
|
|
|
+ if (((float) $xml->xpath($ewidencjaXpath . '/tns:ZakupCtrl/tns:PodatekNaliczony')[0]) != $summaryJPK_VAT["PodatekNaliczony"]) throw new Exception("Brak spójności wartości podatku naliczonego w deklaracji JPK");
|
|
|
}
|
|
|
|
|
|
set_error_handler(function ($errno, $errstr, $errfile, $errline) {
|
|
|
@@ -599,13 +719,8 @@ format: 'YYYY-MM'
|
|
|
|
|
|
restore_error_handler();
|
|
|
|
|
|
- $xsd = [
|
|
|
- 2 => 'Schemat_JPK_VAT(2)_v1-0.xsd',
|
|
|
- 3 => 'Schemat_JPK_VAT(3)_v1-1.xsd',
|
|
|
- ];
|
|
|
-
|
|
|
libxml_use_internal_errors(true);
|
|
|
- if (!$dom->schemaValidate(APP_PATH_SCHEMA . "/jpk/" . $xsd[$this->JPK_VAT_Wariant])) {
|
|
|
+ if (!$dom->schemaValidate(APP_PATH_SCHEMA . "/jpk/" . $this->xsd[$kodSystemowy])) {
|
|
|
$errors = '';
|
|
|
foreach (libxml_get_errors() as $libxml_error) $errors .= "<br/>{$libxml_error->message}";
|
|
|
throw new Exception("Plik JPK niezgodny ze schematem XSD{$errors}<pre>" . htmlentities($dom->saveXML()) . "</pre>");
|
|
|
@@ -699,10 +814,11 @@ format: 'YYYY-MM'
|
|
|
|
|
|
private function import_l1_jpk() {
|
|
|
|
|
|
- $xmlSchemaWarianty = [];
|
|
|
- $xmlSchemaWarianty[2] = <<<EOT
|
|
|
+ switch ($this->JPK_wersjaSchemy) {
|
|
|
+ case '1-0':
|
|
|
+ $xmlSchema = <<<EOT
|
|
|
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
|
|
|
-<JPK xmlns="{$this->tns[$this->JPK_VAT_Wariant]}" xmlns:etd="http://crd.gov.pl/xml/schematy/dziedzinowe/mf/2016/01/25/eD/DefinicjeTypy/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
|
|
+<JPK xmlns="{$this->tns['JPK_VAT (2)']}" xmlns:etd="http://crd.gov.pl/xml/schematy/dziedzinowe/mf/2016/01/25/eD/DefinicjeTypy/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
|
|
<Naglowek>
|
|
|
<KodFormularza kodSystemowy="JPK_VAT (2)" wersjaSchemy="1-0">JPK_VAT</KodFormularza>
|
|
|
<WariantFormularza>2</WariantFormularza>
|
|
|
@@ -734,10 +850,11 @@ format: 'YYYY-MM'
|
|
|
</Podmiot1>
|
|
|
</JPK>
|
|
|
EOT;
|
|
|
-
|
|
|
- $xmlSchemaWarianty[3] = <<<EOT
|
|
|
-<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
|
|
|
-<JPK xmlns="{$this->tns[$this->JPK_VAT_Wariant]}" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
|
|
+ break;
|
|
|
+ case '1-1':
|
|
|
+ $xmlSchema = <<<EOT
|
|
|
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
|
|
+<JPK xmlns="{$this->tns['JPK_VAT (3)']}" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
|
|
<Naglowek>
|
|
|
<KodFormularza kodSystemowy="JPK_VAT (3)" wersjaSchemy="1-1">JPK_VAT</KodFormularza>
|
|
|
<WariantFormularza>3</WariantFormularza>
|
|
|
@@ -754,8 +871,32 @@ EOT;
|
|
|
</Podmiot1>
|
|
|
</JPK>
|
|
|
EOT;
|
|
|
-
|
|
|
- $xmlSchema = $xmlSchemaWarianty[$this->JPK_VAT_Wariant];
|
|
|
+ break;
|
|
|
+ case '1-2E':
|
|
|
+ $xmlSchema = <<<EOT
|
|
|
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
|
|
+<JPK xmlns="{$this->tns['JPK_V7M (1)']}" xmlns:etd="http://crd.gov.pl/xml/schematy/dziedzinowe/mf/2020/03/11/eD/DefinicjeTypy/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
|
|
+ <Naglowek>
|
|
|
+ <KodFormularza kodSystemowy="JPK_V7M (1)" wersjaSchemy="1-2E">JPK_VAT</KodFormularza>
|
|
|
+ <WariantFormularza>1</WariantFormularza>
|
|
|
+ <DataWytworzeniaJPK/>
|
|
|
+ <NazwaSystemu>Procesy5</NazwaSystemu>
|
|
|
+ <CelZlozenia poz="P_7"></CelZlozenia>
|
|
|
+ <KodUrzedu/>
|
|
|
+ <Rok/>
|
|
|
+ <Miesiac/>
|
|
|
+ </Naglowek>
|
|
|
+ <Podmiot1 rola="Podatnik">
|
|
|
+ <OsobaNiefizyczna>
|
|
|
+ <NIP/>
|
|
|
+ <PelnaNazwa/>
|
|
|
+ <Email/>
|
|
|
+ </OsobaNiefizyczna>
|
|
|
+ </Podmiot1>
|
|
|
+</JPK>
|
|
|
+EOT;
|
|
|
+ break;
|
|
|
+ }
|
|
|
|
|
|
// bfp.ID_SERVICES -> SERVICES.ID (NAME_LIST_SERVICES: NET, TV, VOIP)
|
|
|
$queryFVAT = <<<EOT
|
|
|
@@ -766,6 +907,8 @@ if (bu.TAXPAYER_ID_BILLING_USERS > 0, concat(bua_tp.P_ADDRESS_STREET,' ',bua_tp.
|
|
|
bf.SELL_DATE AS 'DataWystawienia',
|
|
|
concat(bn.NUMBER,'/',bn.ID_BILLING_PREFIXES) AS 'DowodSprzedazy',
|
|
|
if (bu.TAXPAYER_ID_BILLING_USERS > 0, if(bua_tp.is_firma=0,'Brak',coalesce(bua_tp.P_NIP,'')), if(bua.is_firma=0,'Brak',coalesce(bua.P_NIP,''))) AS 'NrKontrahenta',
|
|
|
+coalesce(ls.EE, 0) as EE,
|
|
|
+bua.PODMIOT_POWIAZANY as TP,
|
|
|
round(bfp.AMMOUNT * bfp.PRICE, 2) as Netto,
|
|
|
round(round(bfp.AMMOUNT * bfp.PRICE, 2) * bfp.VAT/100, 2) as VAT,
|
|
|
bfp.VAT_NAME as 'VAT_NAME'
|
|
|
@@ -775,6 +918,8 @@ join BILLS_FVAT_POS bfp on bf.ID=bfp.ID_BILLS_FVAT
|
|
|
join BILLING_USERS_ADD bua on bua.id_users=bn.ID_BILLING_USERS
|
|
|
join BILLING_USERS bu on bu.ID=bn.ID_BILLING_USERS
|
|
|
left join BILLING_USERS_ADD bua_tp on bu.TAXPAYER_ID_BILLING_USERS = bua_tp.id_users
|
|
|
+left join SERVICES s on bfp.ID_SERVICES = s.ID
|
|
|
+left join LIST_SERVICES ls on s.NAME_LIST_SERVICES = ls.name
|
|
|
where bn.ID_BILLING_NUMBERS_TYPE='1' and bf.BILL_DATE like '{$this->JPK['MONTH']}%'
|
|
|
and bu.BILLING_OWNER='{$this->BO['ID']}'
|
|
|
order by bf.BILL_DATE,bn.ID
|
|
|
@@ -784,12 +929,14 @@ EOT;
|
|
|
$queryKORV = <<<EOT
|
|
|
select
|
|
|
bn.ID AS BN_ID,
|
|
|
-concat(bua.P_NAME, if(bua.P_NAME_SECOND='','',concat(' ',bua.P_NAME_SECOND))) AS NazwaKontrahenta,
|
|
|
-concat(bua.P_ADDRESS_STREET,' ',bua.P_ADDRESS_HOUSE, if(bua.P_ADDRESS_HOME='','',concat('/',bua.P_ADDRESS_HOME)),', ',P_ADDRESS_POST_CODE,' ',P_ADDRESS_CITY) AS AdresKontrahenta,
|
|
|
+if (bu.TAXPAYER_ID_BILLING_USERS > 0, concat(bua_tp.P_NAME, if(bua_tp.P_NAME_SECOND='','',concat(' ',bua_tp.P_NAME_SECOND))), concat(bua.P_NAME, if(bua.P_NAME_SECOND='','',concat(' ',bua.P_NAME_SECOND)))) AS NazwaKontrahenta,
|
|
|
+if (bu.TAXPAYER_ID_BILLING_USERS > 0, concat(bua_tp.P_ADDRESS_STREET,' ',bua_tp.P_ADDRESS_HOUSE, if(bua_tp.P_ADDRESS_HOME='','',concat('/',bua_tp.P_ADDRESS_HOME)),', ',bua_tp.P_ADDRESS_POST_CODE,' ',bua_tp.P_ADDRESS_CITY), concat(bua.P_ADDRESS_STREET,' ',bua.P_ADDRESS_HOUSE, if(bua.P_ADDRESS_HOME='','',concat('/',bua.P_ADDRESS_HOME)),', ',bua.P_ADDRESS_POST_CODE,' ',bua.P_ADDRESS_CITY)) AS AdresKontrahenta,
|
|
|
bk.BILL_DATE AS 'DataWystawienia',
|
|
|
bk.SELL_DATE AS 'DataSprzedazy',
|
|
|
concat(bn.NUMBER,'/',bn.ID_BILLING_PREFIXES) AS 'DowodSprzedazy',
|
|
|
-if(is_firma=0,'Brak',coalesce(bua.P_NIP,'')) AS 'NrKontrahenta',
|
|
|
+if (bu.TAXPAYER_ID_BILLING_USERS > 0, if(bua_tp.is_firma=0,'Brak',coalesce(bua_tp.P_NIP,'')), if(bua.is_firma=0,'Brak',coalesce(bua.P_NIP,''))) AS 'NrKontrahenta',
|
|
|
+coalesce(ls.EE) as EE,
|
|
|
+bua.PODMIOT_POWIAZANY as TP,
|
|
|
bkp.AMMOUNT AS AMMOUNT,
|
|
|
bkp.PRICE AS PRICE,
|
|
|
bkp.VAT AS VAT,
|
|
|
@@ -804,6 +951,9 @@ join BILLS_KORV bk on bn.ID=bk.ID_BILLING_NUMBERS
|
|
|
join BILLS_KORV_POS bkp on bk.ID=bkp.ID_BILLS_FVAT
|
|
|
join BILLING_USERS_ADD bua on bua.id_users=bn.ID_BILLING_USERS
|
|
|
join BILLING_USERS bu on bu.ID=bn.ID_BILLING_USERS
|
|
|
+left join BILLING_USERS_ADD bua_tp on bu.TAXPAYER_ID_BILLING_USERS = bua_tp.id_users
|
|
|
+left join SERVICES s on bkp.ID_SERVICES = s.ID
|
|
|
+left join LIST_SERVICES ls on s.NAME_LIST_SERVICES = ls.name
|
|
|
where bn.ID_BILLING_NUMBERS_TYPE='3'
|
|
|
and bk.BILL_DATE like '{$this->JPK['MONTH']}%'
|
|
|
and bkp.TYP_KOREKTY IS NOT NULL
|
|
|
@@ -831,9 +981,15 @@ EOT;
|
|
|
|
|
|
$xml->Naglowek->CelZlozenia = $this->JPK['PURPOSE'];
|
|
|
$xml->Naglowek->DataWytworzeniaJPK = date("Y-m-d\TH:i:s");
|
|
|
- $xml->Naglowek->DataOd = $this->JPK['MONTH'] . "-01";
|
|
|
- $xml->Naglowek->DataDo = date("Y-m-d", strtotime($xml->Naglowek->DataOd . "+ 1 month - 1 day"));
|
|
|
- if ($this->JPK_VAT_Wariant == 2) {
|
|
|
+ if ($this->JPK_wersjaSchemy == '1-0' || $this->JPK_wersjaSchemy == '1-1') {
|
|
|
+ $xml->Naglowek->DataOd = $this->JPK['MONTH'] . "-01";
|
|
|
+ $xml->Naglowek->DataDo = date("Y-m-d", strtotime($xml->Naglowek->DataOd . "+ 1 month - 1 day"));
|
|
|
+ } elseif ($this->JPK_wersjaSchemy == '1-2E') {
|
|
|
+ $xml->Naglowek->Rok = date('Y', strtotime($this->JPK['MONTH']));
|
|
|
+ $xml->Naglowek->Miesiac = date('m', strtotime($this->JPK['MONTH']));
|
|
|
+ }
|
|
|
+ $mailRegex = '/^(?!(?:(?:\x22?\x5C[\x00-\x7E]\x22?)|(?:\x22?[^\x5C\x22]\x22?)){255,})(?!(?:(?:\x22?\x5C[\x00-\x7E]\x22?)|(?:\x22?[^\x5C\x22]\x22?)){65,}@)(?:(?:[\x21\x23-\x27\x2A\x2B\x2D\x2F-\x39\x3D\x3F\x5E-\x7E]+)|(?:\x22(?:[\x01-\x08\x0B\x0C\x0E-\x1F\x21\x23-\x5B\x5D-\x7F]|(?:\x5C[\x00-\x7F]))*\x22))(?:\.(?:(?:[\x21\x23-\x27\x2A\x2B\x2D\x2F-\x39\x3D\x3F\x5E-\x7E]+)|(?:\x22(?:[\x01-\x08\x0B\x0C\x0E-\x1F\x21\x23-\x5B\x5D-\x7F]|(?:\x5C[\x00-\x7F]))*\x22)))*@(?:(?:(?!.*[^.]{64,})(?:(?:(?:xn--)?[a-z0-9]+(?:-[a-z0-9]+)*\.){1,126}){1,}(?:(?:[a-z][a-z0-9]*)|(?:(?:xn--)[a-z0-9]+))(?:-[a-z0-9]+)*)|(?:\[(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){7})|(?:(?!(?:.*[a-f0-9][:\]]){7,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?)))|(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){5}:)|(?:(?!(?:.*[a-f0-9]:){5,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3}:)?)))?(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))(?:\.(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))){3}))\]))$/iD';
|
|
|
+ if ($this->JPK_wersjaSchemy == '1-0') {
|
|
|
if (!($xml->Naglowek->KodUrzedu = $this->BO['kodUrzeduSkarbowego'])) throw new Exception("blędne dane podmiotu - brak kodu urzędu skarbowego");
|
|
|
if (!($xml->Podmiot1->IdentyfikatorPodmiotu->children($ns['etd'])->NIP = trim(str_replace("-", "", $this->BO['nip'])))) throw new Exception("blędne dane podmiotu - brak NIP");
|
|
|
if (!($xml->Podmiot1->IdentyfikatorPodmiotu->children($ns['etd'])->PelnaNazwa = $this->BO['name1'])) throw new Exception("blędne dane podmiotu - brak nazwy podmiotu");
|
|
|
@@ -849,12 +1005,20 @@ EOT;
|
|
|
if (!($xml->Podmiot1->AdresPodmiotu->Miejscowosc = $this->BO['miasto'])) throw new Exception("blędne dane podmiotu - brak nazwy miejscowości");
|
|
|
if (!($xml->Podmiot1->AdresPodmiotu->KodPocztowy = $this->BO['kod'])) unset($xml->Podmiot1->AdresPodmiotu->KodPocztowy);
|
|
|
if (!($xml->Podmiot1->AdresPodmiotu->Poczta = $this->BO['poczta'])) unset($xml->Podmiot1->AdresPodmiotu->Poczta);
|
|
|
- } elseif ($this->JPK_VAT_Wariant == 3) {
|
|
|
+ $ewidencja = $xml;
|
|
|
+ } elseif ($this->JPK_wersjaSchemy == '1-1') {
|
|
|
if (!($xml->Podmiot1->NIP = trim(str_replace("-", "", $this->BO['nip'])))) throw new Exception("blędne dane podmiotu - brak NIP");
|
|
|
if (!($xml->Podmiot1->PelnaNazwa = $this->BO['name1'])) throw new Exception("blędne dane podmiotu - brak nazwy podmiotu");
|
|
|
- $mailRegex = '/^(?!(?:(?:\x22?\x5C[\x00-\x7E]\x22?)|(?:\x22?[^\x5C\x22]\x22?)){255,})(?!(?:(?:\x22?\x5C[\x00-\x7E]\x22?)|(?:\x22?[^\x5C\x22]\x22?)){65,}@)(?:(?:[\x21\x23-\x27\x2A\x2B\x2D\x2F-\x39\x3D\x3F\x5E-\x7E]+)|(?:\x22(?:[\x01-\x08\x0B\x0C\x0E-\x1F\x21\x23-\x5B\x5D-\x7F]|(?:\x5C[\x00-\x7F]))*\x22))(?:\.(?:(?:[\x21\x23-\x27\x2A\x2B\x2D\x2F-\x39\x3D\x3F\x5E-\x7E]+)|(?:\x22(?:[\x01-\x08\x0B\x0C\x0E-\x1F\x21\x23-\x5B\x5D-\x7F]|(?:\x5C[\x00-\x7F]))*\x22)))*@(?:(?:(?!.*[^.]{64,})(?:(?:(?:xn--)?[a-z0-9]+(?:-[a-z0-9]+)*\.){1,126}){1,}(?:(?:[a-z][a-z0-9]*)|(?:(?:xn--)[a-z0-9]+))(?:-[a-z0-9]+)*)|(?:\[(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){7})|(?:(?!(?:.*[a-f0-9][:\]]){7,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?)))|(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){5}:)|(?:(?!(?:.*[a-f0-9]:){5,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3}:)?)))?(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))(?:\.(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))){3}))\]))$/iD';
|
|
|
if (preg_match($mailRegex, $this->BO['BILLING_OWNER_EMAIL'])) $xml->Podmiot1->Email = $this->BO['BILLING_OWNER_EMAIL'];
|
|
|
else unset($xml->Podmiot1->Email);
|
|
|
+ $ewidencja = $xml;
|
|
|
+ } elseif ($this->JPK_wersjaSchemy == '1-2E') {
|
|
|
+ if (!($xml->Naglowek->KodUrzedu = $this->BO['kodUrzeduSkarbowego'])) throw new Exception("blędne dane podmiotu - brak kodu urzędu skarbowego");
|
|
|
+ if (!($xml->Podmiot1->OsobaNiefizyczna->NIP = trim(str_replace("-", "", $this->BO['nip'])))) throw new Exception("blędne dane podmiotu - brak NIP");
|
|
|
+ if (!($xml->Podmiot1->OsobaNiefizyczna->PelnaNazwa = $this->BO['name1'])) throw new Exception("blędne dane podmiotu - brak nazwy podmiotu");
|
|
|
+ if (preg_match($mailRegex, $this->BO['BILLING_OWNER_EMAIL'])) $xml->Podmiot1->OsobaNiefizyczna->Email = $this->BO['BILLING_OWNER_EMAIL'];
|
|
|
+ else throw new Exception("błędne dane podmiotu - brak luk błędny adres email");
|
|
|
+ $ewidencja = $xml->addChild('Ewidencja');
|
|
|
}
|
|
|
|
|
|
$data = array();
|
|
|
@@ -864,9 +1028,15 @@ EOT;
|
|
|
foreach ($result as $row) {
|
|
|
$data[$row['BN_ID']][0]['NrKontrahenta'] = trim(str_replace("-", "", $row['NrKontrahenta']));
|
|
|
$data[$row['BN_ID']][0]['NazwaKontrahenta'] = $row['NazwaKontrahenta'];
|
|
|
- $data[$row['BN_ID']][0]['AdresKontrahenta'] = $row['AdresKontrahenta'];
|
|
|
+ if ($this->JPK_wersjaSchemy == '1-0' || $this->JPK_wersjaSchemy == '1-1') {
|
|
|
+ $data[$row['BN_ID']][0]['AdresKontrahenta'] = $row['AdresKontrahenta'];
|
|
|
+ }
|
|
|
$data[$row['BN_ID']][0]['DowodSprzedazy'] = $row['DowodSprzedazy'];
|
|
|
$data[$row['BN_ID']][0]['DataWystawienia'] = $row['DataWystawienia'];
|
|
|
+ if ($this->JPK_wersjaSchemy == '1-2E') {
|
|
|
+ if ($row['EE']) $data[$row['BN_ID']][0]['EE'] += $row['EE'];
|
|
|
+ if ($row['TP']) $data[$row['BN_ID']][0]['TP'] = $row['TP'];
|
|
|
+ }
|
|
|
if (!in_array($row['VAT_NAME'],array_keys($xmlVAT))) throw new Exception("Problem ze stawką VAT (1) - {$row['VAT_NAME']}");
|
|
|
foreach ($xmlVAT[$row['VAT_NAME']]['netto'] as $netto) $data[$row['BN_ID']][1][$netto] += $row['Netto'];
|
|
|
if ($row['VAT'] > 0) {
|
|
|
@@ -880,10 +1050,16 @@ EOT;
|
|
|
foreach ($result as $row) {
|
|
|
$data[$row['BN_ID']][0]['NrKontrahenta'] = trim(str_replace("-", "", $row['NrKontrahenta']));
|
|
|
$data[$row['BN_ID']][0]['NazwaKontrahenta'] = $row['NazwaKontrahenta'];
|
|
|
- $data[$row['BN_ID']][0]['AdresKontrahenta'] = $row['AdresKontrahenta'];
|
|
|
+ if ($this->JPK_wersjaSchemy == '1-0' || $this->JPK_wersjaSchemy == '1-1') {
|
|
|
+ $data[$row['BN_ID']][0]['AdresKontrahenta'] = $row['AdresKontrahenta'];
|
|
|
+ }
|
|
|
$data[$row['BN_ID']][0]['DowodSprzedazy'] = $row['DowodSprzedazy'];
|
|
|
$data[$row['BN_ID']][0]['DataWystawienia'] = $row['DataWystawienia'];
|
|
|
$data[$row['BN_ID']][0]['DataSprzedazy'] = $row['DataSprzedazy'];
|
|
|
+ if ($this->JPK_wersjaSchemy == '1-2E') {
|
|
|
+ if ($row['EE']) $data[$row['BN_ID']][0]['EE'] += $row['EE'];
|
|
|
+ if ($row['TP']) $data[$row['BN_ID']][0]['TP'] = $row['TP'];
|
|
|
+ }
|
|
|
if (!(in_array($row['VAT_NAME'], array_keys($xmlVAT)) && in_array($row['N_VAT_NAME'], array_keys($xmlVAT)))) throw new Exception("Problem ze stawką VAT (3) - {$row['VAT_NAME']}");
|
|
|
if ((($row['VAT'] > 0) && !(isset($xmlVAT[$row['VAT_NAME']]['vat']))) || (($row['N_VAT'] > 0) && !(isset($xmlVAT[$row['N_VAT_NAME']]['vat'])))) throw new Exception("Problem ze stawką VAT (4) - {$row['VAT_NAME']}");
|
|
|
if ($row['VAT_NAME'] == $row['N_VAT_NAME']) {
|
|
|
@@ -918,8 +1094,9 @@ EOT;
|
|
|
$i = 0;
|
|
|
foreach ($data as $pos) {
|
|
|
$this->validateNIP($pos[0]['NrKontrahenta'], $pos[0]['NazwaKontrahenta'], 'Sprzedaż L1');
|
|
|
- $x = $xml->addChild('SprzedazWiersz');
|
|
|
- if ($this->JPK_VAT_Wariant == 2) $x->addAttribute('typ', 'G');
|
|
|
+ if (isset($pos[0]['EE'])) $pos[0]['EE'] = 1;
|
|
|
+ $x = $ewidencja->addChild('SprzedazWiersz');
|
|
|
+ if ($this->JPK_wersjaSchemy == '1-0') $x->addAttribute('typ', 'G');
|
|
|
$x->addChild('LpSprzedazy', ++$i);
|
|
|
ksort($pos[1]);
|
|
|
foreach ($pos as $subpos) foreach ($subpos as $key => $value) {
|
|
|
@@ -929,8 +1106,14 @@ EOT;
|
|
|
}
|
|
|
if ($this->NIPerrors) throw new Exception("Błędne numery NIP:<br/>" . implode("<br/>", $this->NIPerrors));
|
|
|
|
|
|
- $xml->SprzedazCtrl->LiczbaWierszySprzedazy = count($data);
|
|
|
- $xml->SprzedazCtrl->PodatekNalezny = $allVAT;
|
|
|
+ $ewidencja->SprzedazCtrl->LiczbaWierszySprzedazy = count($data);
|
|
|
+ $ewidencja->SprzedazCtrl->PodatekNalezny = number_format($allVAT, 2, '.', '');
|
|
|
+
|
|
|
+ if ($this->JPK_wersjaSchemy == '1-2E') {
|
|
|
+ $zakupCtrl = $ewidencja->addChild('ZakupCtrl');
|
|
|
+ $zakupCtrl->LiczbaWierszyZakupow = '0';
|
|
|
+ $zakupCtrl->PodatekNaliczony = '0.00';
|
|
|
+ }
|
|
|
|
|
|
$this->validateJPK_VAT($xml);
|
|
|
|
|
|
@@ -1002,50 +1185,65 @@ EOT;
|
|
|
}
|
|
|
|
|
|
private function generate_merged_jpk() {
|
|
|
+ try {
|
|
|
+ if (!($this->JPK['IN_INSERT'] && $this->JPK['IN_L1'])) throw new Exception("Błąd danych");
|
|
|
+ $xmlInsert = simplexml_load_string($this->JPK['IN_INSERT']);
|
|
|
+ self::removeTnsNamespace($xmlInsert);
|
|
|
+ $xmlL1 = simplexml_load_string($this->JPK['IN_L1']);
|
|
|
+ $kodSystemowy = (string) $xmlInsert->Naglowek->KodFormularza->attributes()['kodSystemowy'];
|
|
|
+ $tns = $this->tns[$kodSystemowy];
|
|
|
|
|
|
- $xmlSchemaWariant = [];
|
|
|
- $xmlSchemaWariant[2] = <<<EOT
|
|
|
+ switch ($this->JPK_wersjaSchemy) {
|
|
|
+ case '1-0':
|
|
|
+ $xmlSchema = <<<EOT
|
|
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
|
|
-<JPK xmlns="{$this->tns[$this->JPK_VAT_Wariant]}" xmlns:etd="http://crd.gov.pl/xml/schematy/dziedzinowe/mf/2016/01/25/eD/DefinicjeTypy/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
|
|
+<JPK xmlns="{$tns}" xmlns:etd="http://crd.gov.pl/xml/schematy/dziedzinowe/mf/2016/01/25/eD/DefinicjeTypy/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
|
|
</JPK>
|
|
|
EOT;
|
|
|
- $xmlSchemaWariant[3] = <<<EOT
|
|
|
+ break;
|
|
|
+ case '1-1':
|
|
|
+ $xmlSchema = <<<EOT
|
|
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
|
|
-<JPK xmlns="{$this->tns[$this->JPK_VAT_Wariant]}" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
|
|
+<JPK xmlns="{$tns}" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
|
|
</JPK>
|
|
|
EOT;
|
|
|
- $xmlSchema = $xmlSchemaWariant[$this->JPK_VAT_Wariant];
|
|
|
-
|
|
|
- $xml_append = function(SimpleXMLElement $to, SimpleXMLElement $from) {
|
|
|
- $toDom = dom_import_simplexml($to);
|
|
|
- $fromDom = dom_import_simplexml($from);
|
|
|
- $toDom->appendChild($toDom->ownerDocument->importNode($fromDom, true));
|
|
|
- };
|
|
|
+ break;
|
|
|
+ case '1-2E':
|
|
|
+ $xmlSchema = <<<EOT
|
|
|
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
|
|
+<JPK xmlns="{$tns}" xmlns:etd="http://crd.gov.pl/xml/schematy/dziedzinowe/mf/2020/03/11/eD/DefinicjeTypy/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
|
|
+</JPK>
|
|
|
+EOT;
|
|
|
+ break;
|
|
|
+ }
|
|
|
|
|
|
- try {
|
|
|
- if (!($this->JPK['IN_INSERT'] && $this->JPK['IN_L1'])) throw new Exception("Błąd danych");
|
|
|
+ $xml_append = function(SimpleXMLElement $to, SimpleXMLElement $from) {
|
|
|
+ $toDom = dom_import_simplexml($to);
|
|
|
+ $fromDom = dom_import_simplexml($from);
|
|
|
+ $toDom->appendChild($toDom->ownerDocument->importNode($fromDom, true));
|
|
|
+ };
|
|
|
|
|
|
- $xmlInsert = simplexml_load_string($this->JPK['IN_INSERT']);
|
|
|
- self::removeTnsNamespace($xmlInsert);
|
|
|
- $xmlL1 = simplexml_load_string($this->JPK['IN_L1']);
|
|
|
$xml = simplexml_load_string($xmlSchema);
|
|
|
- $tns = $this->tns[$this->JPK_VAT_Wariant];
|
|
|
|
|
|
switch (V::get('SRC_PODMIOT','',$_POST)) {
|
|
|
case "Insert":
|
|
|
- $xml_append($xml, $xmlInsert->children($tns)->Naglowek);
|
|
|
- $xml_append($xml, $xmlInsert->children($tns)->Podmiot1);
|
|
|
- if ($this->JPK_VAT_Wariant == 3) {
|
|
|
+ $xml_append($xml, $xmlInsert->Naglowek);
|
|
|
+ $xml_append($xml, $xmlInsert->Podmiot1);
|
|
|
+ if ($this->JPK_wersjaSchemy == '1-1' || $this->JPK_wersjaSchemy == '1-2E') {
|
|
|
$xml->Naglowek->NazwaSystemu .= "; " . $xmlL1->Naglowek->NazwaSystemu;
|
|
|
- if ((!isset($xml->Podmiot1->Email)) && isset($xmlL1->Podmiot1->Email)) $xml->Podmiot1->Email = $xmlL1->Podmiot1->Email;
|
|
|
+ if ($this->JPK_wersjaSchemy == '1-1' ) {
|
|
|
+ if ((!isset($xml->Podmiot1->Email)) && isset($xmlL1->Podmiot1->Email)) $xml->Podmiot1->Email = $xmlL1->Podmiot1->Email;
|
|
|
+ }
|
|
|
}
|
|
|
break;
|
|
|
case "L1":
|
|
|
- $xml_append($xml, $xmlL1->children($tns)->Naglowek);
|
|
|
- $xml_append($xml, $xmlL1->children($tns)->Podmiot1);
|
|
|
- if ($this->JPK_VAT_Wariant == 3) {
|
|
|
+ $xml_append($xml, $xmlL1->Naglowek);
|
|
|
+ $xml_append($xml, $xmlL1->Podmiot1);
|
|
|
+ if ($this->JPK_wersjaSchemy == '1-1' || $this->JPK_wersjaSchemy == '1-2E') {
|
|
|
$xml->Naglowek->NazwaSystemu .= "; " . $xmlInsert->Naglowek->NazwaSystemu;
|
|
|
- if ((!isset($xml->Podmiot1->Email)) && isset($xmlInsert->Podmiot1->Email)) $xml->Podmiot1->Email = $xmlInsert->Podmiot1->Email;
|
|
|
+ if ($this->JPK_wersjaSchemy == '1-1' ) {
|
|
|
+ if ((!isset($xml->Podmiot1->Email)) && isset($xmlInsert->Podmiot1->Email)) $xml->Podmiot1->Email = $xmlInsert->Podmiot1->Email;
|
|
|
+ }
|
|
|
}
|
|
|
break;
|
|
|
default:
|
|
|
@@ -1055,39 +1253,62 @@ EOT;
|
|
|
$xml->Naglowek->DataWytworzeniaJPK = date("Y-m-d\TH:i:s");
|
|
|
$xml->Naglowek->CelZlozenia = $this->JPK['PURPOSE'];
|
|
|
|
|
|
- $i = 0;
|
|
|
- foreach ($xmlInsert->SprzedazWiersz as $sprzedazWiersz) {
|
|
|
+ if ($xmlInsert->Deklaracja) $xml_append($xml, $xmlInsert->Deklaracja);
|
|
|
+
|
|
|
+ switch ($this->JPK_wersjaSchemy) {
|
|
|
+ case '1-0':
|
|
|
+ case '1-1':
|
|
|
+ $ewidencja = $xml;
|
|
|
+ $ewidencjaInsert = $xmlInsert;
|
|
|
+ $ewidencjaL1 = $xmlL1;
|
|
|
+ $ctrl = false;
|
|
|
+ break;
|
|
|
+ case '1-2E':
|
|
|
+ $ewidencja = $xml->addChild("Ewidencja");
|
|
|
+ $ewidencjaInsert = simplexml_load_string($xmlInsert->Ewidencja->asXml());
|
|
|
+ $ewidencjaL1 = simplexml_load_string($xmlL1->Ewidencja->asXml());
|
|
|
+ $ctrl = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ $si = 0;
|
|
|
+ foreach ($ewidencjaInsert->SprzedazWiersz as $sprzedazWiersz) {
|
|
|
$this->validateNIP($sprzedazWiersz->NrKontrahenta, $sprzedazWiersz->NazwaKontrahenta, "Sprzedaż Insert");
|
|
|
- $sprzedazWiersz->LpSprzedazy = ++$i;
|
|
|
- $xml_append($xml, $sprzedazWiersz);
|
|
|
+ $sprzedazWiersz->LpSprzedazy = ++$si;
|
|
|
+ $xml_append($ewidencja, $sprzedazWiersz);
|
|
|
}
|
|
|
- foreach ($xmlL1->SprzedazWiersz as $sprzedazWiersz) {
|
|
|
+ foreach ($ewidencjaL1->SprzedazWiersz as $sprzedazWiersz) {
|
|
|
$this->validateNIP($sprzedazWiersz->NrKontrahenta, $sprzedazWiersz->NazwaKontrahenta, "Sprzedaż L1");
|
|
|
- $sprzedazWiersz->LpSprzedazy = ++$i;
|
|
|
- $xml_append($xml, $sprzedazWiersz);
|
|
|
+ $sprzedazWiersz->LpSprzedazy = ++$si;
|
|
|
+ $xml_append($ewidencja, $sprzedazWiersz);
|
|
|
}
|
|
|
- $xml->addChild("SprzedazCtrl");
|
|
|
+ if ($si || $ctrl) $ewidencja->addChild("SprzedazCtrl");
|
|
|
|
|
|
- $i = 0;
|
|
|
- foreach ($xmlInsert->ZakupWiersz as $zakupWiersz) {
|
|
|
+ $zi = 0;
|
|
|
+ foreach ($ewidencjaInsert->ZakupWiersz as $zakupWiersz) {
|
|
|
$this->validateNIP($zakupWiersz->NrDostawcy, $zakupWiersz->NazwaDostawcy, "Zakup Insert");
|
|
|
- $zakupWiersz->LpZakupu = ++$i;
|
|
|
- $xml_append($xml, $zakupWiersz);
|
|
|
+ $zakupWiersz->LpZakupu = ++$zi;
|
|
|
+ $xml_append($ewidencja, $zakupWiersz);
|
|
|
}
|
|
|
- foreach ($xmlL1->ZakupWiersz as $zakupWiersz) {
|
|
|
+ foreach ($ewidencjaL1->ZakupWiersz as $zakupWiersz) {
|
|
|
$this->validateNIP($zakupWiersz->NrDostawcy, $zakupWiersz->NazwaDostawcy, "Zakup L1");
|
|
|
- $zakupWiersz->LpZakupu = ++$i;
|
|
|
- $xml_append($xml, $zakupWiersz);
|
|
|
+ $zakupWiersz->LpZakupu = ++$zi;
|
|
|
+ $xml_append($ewidencja, $zakupWiersz);
|
|
|
}
|
|
|
- $xml->addChild("ZakupCtrl");
|
|
|
+ if ($zi || $ctrl) $ewidencja->addChild("ZakupCtrl");
|
|
|
|
|
|
if ($this->NIPerrors) throw new Exception("Błędne numery NIP:<br/>" . implode("<br/>", $this->NIPerrors));
|
|
|
|
|
|
$sumaryJPK_VAT = $this->getSummaryJPK_VAT($xml);
|
|
|
- $xml->SprzedazCtrl->LiczbaWierszySprzedazy = $sumaryJPK_VAT['LiczbaWierszySprzedazy'];
|
|
|
- $xml->SprzedazCtrl->PodatekNalezny = $sumaryJPK_VAT['PodatekNalezny'];
|
|
|
- $xml->ZakupCtrl->LiczbaWierszyZakupow = $sumaryJPK_VAT['LiczbaWierszyZakupow'];
|
|
|
- $xml->ZakupCtrl->PodatekNaliczony = $sumaryJPK_VAT['PodatekNaliczony'];
|
|
|
+ if ($si || $ctrl) {
|
|
|
+ $ewidencja->SprzedazCtrl->LiczbaWierszySprzedazy = $sumaryJPK_VAT['LiczbaWierszySprzedazy'];
|
|
|
+ $ewidencja->SprzedazCtrl->PodatekNalezny = $sumaryJPK_VAT['PodatekNalezny'];
|
|
|
+ }
|
|
|
+ if ($zi || $ctrl) {
|
|
|
+ $ewidencja->ZakupCtrl->LiczbaWierszyZakupow = $sumaryJPK_VAT['LiczbaWierszyZakupow'];
|
|
|
+ $ewidencja->ZakupCtrl->PodatekNaliczony = $sumaryJPK_VAT['PodatekNaliczony'];
|
|
|
+ }
|
|
|
+
|
|
|
$this->validateJPK_VAT($xml);
|
|
|
|
|
|
$sqlObj = new stdClass();
|