|
|
@@ -7,6 +7,7 @@ class Route_UrlAction_JPK extends RouteBase {
|
|
|
|
|
|
private $REFERER, $LAST_REFERER;
|
|
|
private $JPK, $BO;
|
|
|
+ private $NIPerrors = array();
|
|
|
|
|
|
public function handleAuth() {
|
|
|
if (!User::logged()) {
|
|
|
@@ -562,6 +563,28 @@ format: 'YYYY-MM'
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private function validateNIP($nip_orig, $name, $type) {
|
|
|
+ $nip = str_replace("-", "", trim($nip_orig));
|
|
|
+ $error = false;
|
|
|
+ if ($nip == "" || $nip == "Brak") return true;
|
|
|
+
|
|
|
+ $prefix = substr($nip, 0, 2);
|
|
|
+ if (!is_numeric($prefix)) $nip = substr($nip, 2);
|
|
|
+ else $prefix = null;
|
|
|
+
|
|
|
+ if ($prefix && $prefix != "PL") return true;
|
|
|
+ if (strlen($nip) != 10 || (!is_numeric($nip))) $error = true;
|
|
|
+ else {
|
|
|
+ $control = (($nip[0] * 6 + $nip[1] * 5 + $nip[2] * 7 + $nip[3] * 2 + $nip[4] * 3 + $nip[5] * 4 + $nip[6] * 5 + $nip[7] * 6 + $nip[8] * 7) % 11 ) % 10;
|
|
|
+ $error = ($control != $nip[9]);
|
|
|
+ }
|
|
|
+ if ($error) {
|
|
|
+ $this->NIPerrors[] = "NIP: {$nip_orig}, nazwa: {$name}, rodzaj dokumentu: {$type}";
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
private function import_l1_jpk() {
|
|
|
|
|
|
$xmlSchema = <<<EOT
|
|
|
@@ -628,7 +651,7 @@ concat(bua.P_ADDRESS_STREET,' ',bua.P_ADDRESS_HOUSE, if(bua.P_ADDRESS_HOME='',''
|
|
|
bk.BILL_DATE AS 'DataWystawienia',
|
|
|
bk.SELL_DATE AS 'DataSprzedazy',
|
|
|
concat(bn.NUMBER,'/',bn.ID_BILLING_PREFIXES) AS 'DowodSprzedazy',
|
|
|
-if(coalesce(bua.P_NIP,'')='','Nie dotyczy',coalesce(bua.P_NIP,'')) AS 'NrKontrahenta',
|
|
|
+if(is_firma=0,'Brak',coalesce(bua.P_NIP,'')) AS 'NrKontrahenta',
|
|
|
bkp.AMMOUNT AS AMMOUNT,
|
|
|
bkp.PRICE AS PRICE,
|
|
|
bkp.VAT AS VAT,
|
|
|
@@ -692,7 +715,7 @@ EOT;
|
|
|
|
|
|
$result = DB::getPDO(931)->fetchall($queryFVAT);
|
|
|
foreach ($result as $row) {
|
|
|
- $data[$row['BN_ID']][0]['NrKontrahenta'] = $row['NrKontrahenta'];
|
|
|
+ $data[$row['BN_ID']][0]['NrKontrahenta'] = trim($row['NrKontrahenta']);
|
|
|
$data[$row['BN_ID']][0]['NazwaKontrahenta'] = $row['NazwaKontrahenta'];
|
|
|
$data[$row['BN_ID']][0]['AdresKontrahenta'] = $row['AdresKontrahenta'];
|
|
|
$data[$row['BN_ID']][0]['DowodSprzedazy'] = $row['DowodSprzedazy'];
|
|
|
@@ -708,7 +731,7 @@ EOT;
|
|
|
|
|
|
$result = DB::getPDO(931)->fetchall($queryKORV);
|
|
|
foreach ($result as $row) {
|
|
|
- $data[$row['BN_ID']][0]['NrKontrahenta'] = $row['NrKontrahenta'];
|
|
|
+ $data[$row['BN_ID']][0]['NrKontrahenta'] = trim($row['NrKontrahenta']);
|
|
|
$data[$row['BN_ID']][0]['NazwaKontrahenta'] = $row['NazwaKontrahenta'];
|
|
|
$data[$row['BN_ID']][0]['AdresKontrahenta'] = $row['AdresKontrahenta'];
|
|
|
$data[$row['BN_ID']][0]['DowodSprzedazy'] = $row['DowodSprzedazy'];
|
|
|
@@ -748,6 +771,7 @@ EOT;
|
|
|
|
|
|
$i = 0;
|
|
|
foreach ($data as $pos) {
|
|
|
+ $this->validateNIP($pos[0]['NrKontrahenta'], $pos[0]['NazwaKontrahenta'], 'Sprzedaż L1');
|
|
|
$x = $xml->addChild('SprzedazWiersz');
|
|
|
$x->addAttribute('typ', 'G');
|
|
|
$x->addChild('LpSprzedazy', ++$i);
|
|
|
@@ -757,6 +781,7 @@ EOT;
|
|
|
if (!strlen($x->$key)) addCdata($x->$key, $value);
|
|
|
}
|
|
|
}
|
|
|
+ if ($this->NIPerrors) throw new Exception("Błędne numery NIP:<br/>" . implode("<br/>", $this->NIPerrors));
|
|
|
|
|
|
$xml->SprzedazCtrl->LiczbaWierszySprzedazy = count($data);
|
|
|
$xml->SprzedazCtrl->PodatekNalezny = $allVAT;
|
|
|
@@ -855,10 +880,12 @@ EOT;
|
|
|
|
|
|
$i = 0;
|
|
|
foreach ($xmlInsert->SprzedazWiersz as $sprzedazWiersz) {
|
|
|
+ $this->validateNIP($sprzedazWiersz->NrKontrahenta, $sprzedazWiersz->NazwaKontrahenta, "Sprzedaż Insert");
|
|
|
$sprzedazWiersz->LpSprzedazy = ++$i;
|
|
|
xml_append($xml, $sprzedazWiersz);
|
|
|
}
|
|
|
foreach ($xmlL1->SprzedazWiersz as $sprzedazWiersz) {
|
|
|
+ $this->validateNIP($sprzedazWiersz->NrKontrahenta, $sprzedazWiersz->NazwaKontrahenta, "Sprzedaż L1");
|
|
|
$sprzedazWiersz->LpSprzedazy = ++$i;
|
|
|
xml_append($xml, $sprzedazWiersz);
|
|
|
}
|
|
|
@@ -866,15 +893,19 @@ EOT;
|
|
|
|
|
|
$i = 0;
|
|
|
foreach ($xmlInsert->ZakupWiersz as $zakupWiersz) {
|
|
|
+ $this->validateNIP($zakupWiersz->NrDostawcy, $zakupWiersz->NazwaDostawcy, "Zakup Insert");
|
|
|
$zakupWiersz->LpZakupu = ++$i;
|
|
|
xml_append($xml, $zakupWiersz);
|
|
|
}
|
|
|
foreach ($xmlL1->ZakupWiersz as $zakupWiersz) {
|
|
|
+ $this->validateNIP($zakupWiersz->NrDostawcy, $zakupWiersz->NazwaDostawcy, "Zakup L1");
|
|
|
$zakupWiersz->LpZakupu = ++$i;
|
|
|
xml_append($xml, $zakupWiersz);
|
|
|
}
|
|
|
$xml->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'];
|