function C_REPORT(&$My_POST, &$DB, $XML_Variants, $grup)
 {
     global $braki;
     global $VIKA_braki;
     global $LVM_braki;
     global $VIKA_LVM_braki;
     global $sugas;
     global $lang;
     global $translate;
     if ($lang != "RUS") {
         $lang = "LAT";
     }
     $this->DB = $DB;
     $this->XML_Variants = $XML_Variants;
     $this->sugas = $sugas;
     $this->MyPOST = $My_POST;
     $this->grup = $grup;
     if (strrpos($this->MyPOST['pavadzime'], "KRVII") === false) {
         $this->braki = $VIKA_braki;
         $LVM_braki = $VIKA_LVM_braki;
     } else {
         $this->braki = $braki;
     }
     $this->XMLVARS();
     $this->SetParam();
     $this->mtipi['auto'] = $translate['auto_nr2'][$lang];
     $this->mtipi['brakis'] = $translate['brakis'][$lang];
     $this->mtipi['cenu_matrica'] = $translate['cenu_matrica2'][$lang];
     $this->mtipi['kad_piegad'] = $translate['datums2'][$lang];
     $this->mtipi['mind_pirms_red'] = $translate['diametrs2'][$lang];
     $this->mtipi['fsc'] = $translate['fsc2'][$lang];
     $this->mtipi['garums'] = $translate['garums2'][$lang];
     $this->mtipi['kravas_id'] = $translate['kravas_id2'][$lang];
     $this->mtipi['pavadzime.pavadzime'] = $translate['pavadzime2'][$lang];
     $this->mtipi['piegad_kods'] = $translate['piegadatajs2'][$lang];
     $this->mtipi['soferis'] = $translate['soferis2'][$lang];
     $this->mtipi['suga'] = $translate['suga2'][$lang];
     $this->mtipi['skira'] = $translate['skira2'][$lang];
     $this->mtipi['iecirknis'] = $translate['iecirknis2'][$lang];
     if ($_SERVER['REQUEST_METHOD'] == 'POST' && $this->XML_Variants) {
         //			if(trim($this->MyPOST['pieg_lig_num'])=='') $this->ERRORS.= "Nav norādīts PIEGĀDES LĪGUMA numurs!<br><br>";
         if (trim($this->MyPOST['pavadzime']) != '') {
             if (!GetFromPavadzime($this->MyPOST['pavadzime'], 'pavadzime', 'bsw_pavadzime')) {
                 $this->ERRORS .= "Norādīts NEEKSISTĒJOŠS PAVADZĪMES numurs!<br><br>";
             }
         } else {
             $this->ERRORS .= "Nav norādīts PAVADZĪMES numurs!<br><br>";
         }
     }
     if ($this->MyPOST[subm] && !$this->ERRORS) {
         // --------------------cik grup??anas l?me?i izmantoti ----------------------------
         $this->lsk = 0;
         while ($this->MyPOST["gtype" . $this->grup . ($this->lsk + 1)] != '') {
             $this->lsk++;
         }
         // --------------------cik grup??anas l?me?i izmantoti ----------------------------
         // Pārbauda vai nav vairāku pavazdīmju ar šādu numuru
         if ($this->MyPOST['pavadzime'] && !$this->MyPOST[pavadzime_id]) {
             $pav_test_query = "select count(*) as x from bsw_pavadzime where pavadzime = '" . trim($this->MyPOST['pavadzime']) . "'";
             if ($this->MyPOST[datums_no] != '') {
                 $pav_test_query = $pav_test_query . " and kad_piegad >= '" . $this->MyPOST[datums_no] . "' ";
             }
             if ($this->MyPOST[datums_lidz] != '') {
                 $pav_test_query = $pav_test_query . " and kad_piegad <= '" . $this->MyPOST[datums_lidz] . "' ";
             }
             $r = $this->DB->query($pav_test_query);
             if ($m = $this->DB->get_row($r)) {
                 if ($m[x] > 1) {
                     $this->ERRORS .= "<font color=red>Eksistē " . $m[x] . " pavadzīmes ar numuru " . $this->MyPOST['pavadzime'] . "!</font><br><br>";
                 }
             }
         }
         //$query = " from balkis,pavadzime where balkis.pavadzime = pavadzime.id ";
         if ($this->MyPOST[datums_no_diena] != '' || $this->MyPOST[pavadzime_id]) {
             //
             $query = " from bsw_balkis_temp INNER JOIN bsw_pavadzime ON bsw_balkis_temp.pavadzime = bsw_pavadzime.id WHERE 1=1 ";
         } else {
             $query = " from bsw_balkis_temp INNER JOIN bsw_pavadzime ON bsw_balkis_temp.pavadzime = bsw_pavadzime.id WHERE 1=1 ";
         }
         // nosac?jumi
         if ($this->MyPOST[datums_no_diena] != '') {
             $query = $query . " and bsw_balkis.datums_laiks >= '" . $this->MyPOST[datums_no_gads] . "-" . $this->MyPOST[datums_no_menesis] . "-" . $this->MyPOST[datums_no_diena] . " 00:00:00' ";
         }
         if ($this->MyPOST[datums_lidz_diena] != '') {
             $query = $query . " and bsw_balkis.datums_laiks <= '" . $this->MyPOST[datums_lidz_gads] . "-" . $this->MyPOST[datums_lidz_menesis] . "-" . $this->MyPOST[datums_lidz_diena] . " 00:00:00' ";
         }
         if ($this->MyPOST[piegad_grupa]) {
             $query = $query . " and bsw_pavadzime.piegad_grupa like '" . $this->MyPOST[piegad_grupa] . "%'";
         }
         if ($this->MyPOST[piegadataju_kods]) {
             $query = $query . " and bsw_pavadzime.piegad_kods = '" . $this->MyPOST[piegadataju_kods] . "'";
         }
         if ($this->MyPOST[pavadzime]) {
             $query = $query . " and bsw_pavadzime.pavadzime = '" . $this->MyPOST[pavadzime] . "'";
         }
         if ($this->MyPOST[pavadzime_id]) {
             $query = $query . " and bsw_pavadzime.id = '" . $this->MyPOST[pavadzime_id] . "'";
         }
         if ($this->MyPOST[suga] != '') {
             $query = $query . " and suga = '" . $this->MyPOST[suga] . "'";
         }
         if ($this->MyPOST[cirsmas_kods] != '') {
             $query = $query . " and cirsmas_kods like '" . $this->MyPOST[cirsmas_kods] . "'";
         }
         if ($this->MyPOST[brakis] != '') {
             $query = $query . " and brakis = '" . $this->MyPOST[brakis] . "'";
         }
         if ($this->MyPOST[fsc] != '') {
             $query = $query . " and fsc = '" . $this->MyPOST[fsc] . "'";
         }
         if ($this->MyPOST[kravas_id]) {
             $query = $query . " and kravas_id = '" . $this->MyPOST[kravas_id] . "'";
         }
         if ($this->MyPOST[auto]) {
             $query = $query . " and auto = '" . $this->MyPOST[auto] . "'";
         }
         if ($this->MyPOST[soferis]) {
             $query = $query . " and soferis = '" . $this->MyPOST[soferis] . "'";
         }
         if ($this->MyPOST[cenu_matrica]) {
             $query = $query . " and cenu_matrica = '" . $this->MyPOST[cenu_matrica] . "'";
         }
         if ($this->MyPOST[skira]) {
             $query = $query . " and skira = '" . $this->MyPOST[skira] . "'";
         }
         if (trim($this->MyPOST['batch_fails']) != '') {
             $query = $query . " and batch_fails in(" . $this->MyPOST[batch_fails] . ")";
         }
         if (trim($this->MyPOST['iecirknis_pieg']) != '') {
             $query = $query . " and LOWER(iecirknis_pieg)=LOWER('" . trim($this->MyPOST['iecirknis_pieg']) . "')";
         }
         $query2 = str_replace("bsw_balkis_temp", "bsw_balkis", $query);
         if ($this->MyPOST[datums_no_diena] != '') {
             $this->DB->query("DELETE FROM bsw_balkis_temp");
             $this->DB->query("INSERT INTO bsw_balkis_temp (SELECT bsw_balkis.id,bsw_balkis.pavadzime,bsw_balkis.nelieto,bsw_balkis.datums_laiks,bsw_balkis.mind_pirms_red,bsw_balkis.garums,bsw_balkis.suga,bsw_balkis.skira,bsw_balkis.miza,bsw_balkis.mind_pec_red,bsw_balkis.gar_pec_red,bsw_balkis.mind_miza,IF(bsw_balkis.gar_pec_red < 360 AND bsw_balkis.suga = 2 AND bsw_balkis.skira < 9,'009',bsw_balkis.brakis),bsw_balkis.maxd_miza,bsw_balkis.kabata,bsw_balkis.tilpums,bsw_balkis.tilpums_scan,bsw_balkis.import_type,bsw_balkis.import_id " . $query2 . ")");
             $query = " from bsw_balkis_temp INNER JOIN bsw_pavadzime ON bsw_balkis_temp.pavadzime = bsw_pavadzime.id WHERE 1=1 ";
             //      echo "INSERT INTO bsw_balkis_temp (SELECT bsw_balkis.id,bsw_balkis.pavadzime,bsw_balkis.nelieto,bsw_balkis.datums_laiks,bsw_balkis.mind_pirms_red,bsw_balkis.garums,bsw_balkis.suga,bsw_balkis.skira,bsw_balkis.miza,bsw_balkis.mind_pec_red,bsw_balkis.gar_pec_red,bsw_balkis.mind_miza,IF(bsw_balkis.gar_pec_red < 360 AND bsw_balkis.suga = 2 AND bsw_balkis.skira < 9,'009',bsw_balkis.brakis),bsw_balkis.maxd_miza,bsw_balkis.kabata,bsw_balkis.tilpums,bsw_balkis.tilpums_scan,bsw_balkis.import_type,bsw_balkis.import_id " . $query2 . ")";
             //  die();
         }
         if ($this->MyPOST[pavadzime]) {
             $this->DB->query("DELETE FROM bsw_balkis_temp");
             $this->DB->query("INSERT INTO bsw_balkis_temp (SELECT bsw_balkis.id,bsw_balkis.pavadzime,bsw_balkis.nelieto,bsw_balkis.datums_laiks,bsw_balkis.mind_pirms_red,bsw_balkis.garums,bsw_balkis.suga,bsw_balkis.skira,bsw_balkis.miza,bsw_balkis.mind_pec_red,bsw_balkis.gar_pec_red,bsw_balkis.mind_miza,IF(bsw_balkis.gar_pec_red < 360 AND bsw_balkis.suga = 2 AND bsw_balkis.skira < 9,'009',bsw_balkis.brakis),bsw_balkis.maxd_miza,bsw_balkis.kabata,bsw_balkis.tilpums,bsw_balkis.tilpums_scan,bsw_balkis.import_type,bsw_balkis.import_id " . $query2 . ")");
             //      echo "INSERT INTO bsw_balkis_temp (SELECT bsw_balkis.id,bsw_balkis.pavadzime,bsw_balkis.nelieto,bsw_balkis.datums_laiks,bsw_balkis.mind_pirms_red,bsw_balkis.garums,bsw_balkis.suga,bsw_balkis.skira,bsw_balkis.miza,bsw_balkis.mind_pec_red,bsw_balkis.gar_pec_red,bsw_balkis.mind_miza,IF(bsw_balkis.gar_pec_red > 460,bsw_balkis.brakis,'009'),bsw_balkis.maxd_miza,bsw_balkis.kabata,bsw_balkis.tilpums,bsw_balkis.tilpums_scan,bsw_balkis.import_type,bsw_balkis.import_id " . $query2 . ")";
             //Pievienoju pārbaudi uz baļķu esamību pavadzīmē 2010-03-09, Ervīns
             if (mysql_affected_rows() == 0) {
                 $this->ERRORS .= "<font color=red>Pavadzīmē " . $this->MyPOST['pavadzime'] . " nav neviens baļķis!</font><br><br>";
                 return false;
             }
             $query = " from bsw_balkis_temp INNER JOIN bsw_pavadzime ON bsw_balkis_temp.pavadzime = bsw_pavadzime.id WHERE 1=1 ";
         }
         $rtest = $this->DB->query("select count(*) as x " . $query);
         if ($m = $this->DB->get_row($rtest)) {
             if ($m[x] > 1) {
                 $correct_count = $m[x];
             } else {
                 $correct_count = 0;
             }
         }
         $this->arr[-1] = array();
         // izejas masīva headeri
         if ($this->XML_Variants) {
             $diam__ = false;
             // p?rbaudei vai vajadz?g?s grup??anas XML atskaitei iesl?gtas
             $gar__ = false;
         }
         // pirmās kolonnas atskaitei ko izvēlējies lietotājs
         //var_dump($this->MyPOST);
         //print_r($this->MyPOST);
         for ($i = 0; $i < $this->lsk; $i++) {
             $this->arr[-1][$i] = $this->mtipi[$this->MyPOST["gtype" . $this->grup . ($i + 1)]];
             if ($this->XML_Variants) {
                 //echo "<br>gtype".($i+1)." gvalues".($i+1)." gvalues".($i+1)."_1"." gvalues".($i+1)."_2";
                 $this->arr[-1][$i] = $this->MyPOST["gtype" . $this->grup . ($i + 1)];
                 if ($this->MyPOST["gtype" . $this->grup . ($i + 1)] == 'mind_pirms_red') {
                     //echo '****************mind_pirms_red*************';
                     //						$this->MyPOST["gvalues".$this->grup.($i+1)]=str_replace("b0-139","b0-59,b60-99,b100-119,b120-139",$this->MyPOST["gvalues".$this->grup.($i+1)]);
                     $this->MyPOST["gvalues" . $this->grup . ($i + 1)] = $this->MyPOST["gvalues" . $this->grup . ($i + 1)];
                     //						echo $this->MyPOST["gvalues".$this->grup.($i+1)];
                     //						$this->MyPOST["gvalues".$this->grup.($i+1)."_1"]=LVM_distribution($this->MyPOST["gvalues".$this->grup.($i+1)."_1"],1);
                     $this->MyPOST["gvalues" . $this->grup . ($i + 1) . "_1"] = $this->MyPOST["gvalues" . $this->grup . ($i + 1) . "_1"];
                     //						$this->MyPOST["gvalues".$this->grup.($i+1)."_2"]=LVM_distribution($this->MyPOST["gvalues".$this->grup.($i+1)."_2"],2);
                     $this->MyPOST["gvalues" . $this->grup . ($i + 1) . "_2"] = $this->MyPOST["gvalues" . $this->grup . ($i + 1) . "_2"];
                     //echo "<br> IN mind_pirms_red "."gtype".($i+1)."invalue [".(($this->MyPOST["gvalues".($i+1)]) || ($this->MyPOST["gvalues".($i+1)."_1"]) || ($this->MyPOST["gvalues".($i+1)."_2]"]))."]";
                     if ($this->MyPOST["gvalues" . $this->grup . ($i + 1)] || $this->MyPOST["gvalues" . $this->grup . ($i + 1) . "_1"] || $this->MyPOST["gvalues" . $this->grup . ($i + 1) . "_2"]) {
                         //echo "<br> IN "."gvalues".($i+1);
                         $diam__ = true;
                     }
                 }
                 if ($this->MyPOST["gtype" . $this->grup . ($i + 1)] == 'garums') {
                     $gar__ = true;
                 }
                 if ($this->MyPOST["gtype" . $this->grup . ($i + 1)] == 'brakis') {
                     $brak__ = true;
                 }
             } else {
                 if ($this->MyPOST["gtype" . $this->grup . ($i + 1)] == "bsw_pavadzime.pavadzime") {
                     $this->arr[-1][$i] = $this->mtipi['bsw_pavadzime.pavadzime'];
                 }
                 //kaut k?ds exception
             }
         }
         //print_r($this->MyPOST);
         // pēdējās kolonnas kas visām atskaitēm vienādas
         $this->arr[-1][$i] = $translate['skaits'][$lang];
         $i++;
         $this->arr[-1][$i] = $translate['bruto'][$lang] . " m3";
         $i++;
         $this->arr[-1][$i] = $translate['virsmers'][$lang] . " m3";
         $i++;
         $this->arr[-1][$i] = $translate['redukcija'][$lang] . " m3";
         $i++;
         $this->arr[-1][$i] = $translate['brakis'][$lang] . " m3";
         $i++;
         $this->arr[-1][$i] = $translate['neto'][$lang] . " m3";
         $i++;
         // $i - tagad kolonnu skaits //
         //$this->arr[-1] - kolonnu nosaukumi un izvad?m? inform?cija atskait? v?l?k.
         $this->rowclosed = true;
         $summa = new CSumma();
         $this->arr_index = 0;
         // $query - satur nosac?jumus,kas jaliek gala katram selektam, nosacijumi izveidoti no formas Nosacijumiem
         if (!$this->ERRORS) {
             // rekurs?v?s funkcijas izsaukums
             $this->print_level(1, $query, $summa, false, 0, '');
         }
         // kopsumma
         ++$this->arr_index;
         $this->arr[$this->arr_index] = array();
         $this->arr[$this->arr_index][-1] = $translate['v_kopa'][$lang];
         $this->arr[$this->arr_index][summa] = $summa;
         if ($this->XML_Variants) {
             if (!$gar__) {
                 $this->ERRORS .= "Kļūda! Netiek izmantota grupēšana pēc GARUMA!<br><br>";
             }
             if (!$diam__) {
                 $this->ERRORS .= "Kļūda! Netiek izmantota grupēšana pēc DIAMETRA vai arī garuma intervālu robežas neatbilst standartam!<br><br>";
             }
             if (!$brak__) {
                 $this->ERRORS .= "Kļūda! Netiek izmantota grupēšana pēc BRĀĶA!<br><br>";
             }
             //labots sakarā ar vairākām grupēšanām XML atskaitē
             $this->arr[$this->arr_index][correct_count] = $correct_count;
             //if ($correct_count != $summa->skaits) $this->ERRORS.= "Kļūda grupēšanā! Sagrupēti ".(int)$summa->skaits." baļķi no $correct_count.<br><br>";
         }
     }
     //$this->ErrorCheck(); //
     if ($this->ERRORS) {
         return false;
     }
 }
 function C_REPORT(&$My_POST, &$DB, $XML_Variants)
 {
     global $braki;
     global $sugas;
     global $VIKA_braki;
     global $LVM_braki;
     global $VIKA_LVM_braki;
     $this->DB = $DB;
     $this->XML_Variants = $XML_Variants;
     $this->sugas = $sugas;
     $this->MyPOST = $My_POST;
     if (strrpos($this->MyPOST['pavadzime'], "KRVII") === false) {
         $this->braki = $VIKA_braki;
         $LVM_braki = $VIKA_LVM_braki;
     } else {
         $this->braki = $braki;
     }
     $this->XMLVARS();
     $this->SetParam();
     $this->mtipi['auto'] = "Auto nr";
     $this->mtipi['brakis'] = "Brāķis";
     $this->mtipi['cenu_matrica'] = "Cenu matrica";
     $this->mtipi['kad_piegad'] = "Datums";
     $this->mtipi['mind_pirms_red'] = "Diametrs";
     $this->mtipi['fsc'] = "FSC";
     $this->mtipi['garums'] = "Garums";
     $this->mtipi['kravas_id'] = "Kravas ID";
     $this->mtipi['pavadzime.pavadzime'] = "Pavadzīme";
     $this->mtipi['piegad_kods'] = "Piegādātājs";
     $this->mtipi['soferis'] = "Šoferis";
     $this->mtipi['suga'] = "Suga";
     $this->mtipi['skira'] = "Šķira";
     $this->mtipi['iecirknis'] = "Iecirknis";
     if ($_SERVER['REQUEST_METHOD'] == 'POST' && $this->XML_Variants) {
         if (trim($this->MyPOST['pieg_lig_num']) == '') {
             $this->ERRORS .= "Nav norādīts PIEGĀDES LĪGUMA numurs!<br><br>";
         }
         if (trim($this->MyPOST['pavadzime']) != '') {
             if (!GetFromPavadzime($this->MyPOST['pavadzime'], 'pavadzime')) {
                 $this->ERRORS .= "Norādīts NEEKSISTĒJOŠS PAVADZĪMES numurs!<br><br>";
             }
         } else {
             $this->ERRORS .= "Nav norādīts PAVADZĪMES numurs!<br><br>";
         }
     }
     if ($this->MyPOST[subm] && !$this->ERRORS) {
         // --------------------cik grup??anas l?me?i izmantoti ----------------------------
         $this->lsk = 0;
         while ($this->MyPOST["gtype" . ($this->lsk + 1)] != '') {
             $this->lsk++;
         }
         // --------------------cik grup??anas l?me?i izmantoti ----------------------------
         // Pārbauda vai nav vairāku pavazdīmju ar šādu numuru
         if ($this->MyPOST['pavadzime'] && !$this->MyPOST[pavadzime_id]) {
             $pav_test_query = "select count(*) as x from pavadzime where pavadzime = '" . trim($this->MyPOST['pavadzime']) . "'";
             if ($this->MyPOST[datums_no] != '') {
                 $pav_test_query = $pav_test_query . " and kad_piegad >= '" . $this->MyPOST[datums_no] . "' ";
             }
             if ($this->MyPOST[datums_lidz] != '') {
                 $pav_test_query = $pav_test_query . " and kad_piegad <= '" . $this->MyPOST[datums_lidz] . "' ";
             }
             $r = $this->DB->query($pav_test_query);
             if ($m = $this->DB->get_row($r)) {
                 if ($m[x] > 1) {
                     $this->ERRORS .= "<font color=red>Eksistē " . $m[x] . " pavadzīmes ar numuru " . $this->MyPOST['pavadzime'] . "!</font><br><br>";
                 }
             }
         }
         $query = " from balkis,pavadzime where balkis.pavadzime = pavadzime.id ";
         // nosac?jumi
         if ($this->MyPOST[datums_no_diena] != '') {
             $query = $query . " and kad_piegad >= '" . $this->MyPOST[datums_no_gads] . "-" . $this->MyPOST[datums_no_menesis] . "-" . $this->MyPOST[datums_no_diena] . "' ";
         }
         if ($this->MyPOST[datums_lidz_diena] != '') {
             $query = $query . " and kad_piegad <= '" . $this->MyPOST[datums_lidz_gads] . "-" . $this->MyPOST[datums_lidz_menesis] . "-" . $this->MyPOST[datums_lidz_diena] . "' ";
         }
         if ($this->MyPOST[piegad_grupa]) {
             $query = $query . " and pavadzime.piegad_grupa like '" . $this->MyPOST[piegad_grupa] . "%'";
         }
         if ($this->MyPOST[pavadzime]) {
             $query = $query . " and pavadzime.pavadzime = '" . $this->MyPOST[pavadzime] . "'";
         }
         if ($this->MyPOST[pavadzime_id]) {
             $query = $query . " and pavadzime.id = '" . $this->MyPOST[pavadzime_id] . "'";
         }
         if ($this->MyPOST[suga] != '') {
             $query = $query . " and suga = '" . $this->MyPOST[suga] . "'";
         }
         if ($this->MyPOST[cirsmas_kods] != '') {
             $query = $query . " and cirsmas_kods like '" . $this->MyPOST[cirsmas_kods] . "'";
         }
         if ($this->MyPOST[brakis] != '') {
             $query = $query . " and brakis = '" . $this->MyPOST[brakis] . "'";
         }
         if ($this->MyPOST[fsc] != '') {
             $query = $query . " and fsc = '" . $this->MyPOST[fsc] . "'";
         }
         if ($this->MyPOST[kravas_id]) {
             $query = $query . " and kravas_id = '" . $this->MyPOST[kravas_id] . "'";
         }
         if ($this->MyPOST[auto]) {
             $query = $query . " and auto = '" . $this->MyPOST[auto] . "'";
         }
         if ($this->MyPOST[soferis]) {
             $query = $query . " and soferis = '" . $this->MyPOST[soferis] . "'";
         }
         if ($this->MyPOST[cenu_matrica]) {
             $query = $query . " and cenu_matrica = '" . $this->MyPOST[cenu_matrica] . "'";
         }
         if ($this->MyPOST[skira]) {
             $query = $query . " and skira = '" . $this->MyPOST[skira] . "'";
         }
         if (trim($this->MyPOST['batch_fails']) != '') {
             $query = $query . " and batch_fails in(" . $this->MyPOST[batch_fails] . ")";
         }
         if (trim($this->MyPOST['iecirknis_pieg']) != '') {
             $query = $query . " and LOWER(iecirknis_pieg)=LOWER('" . trim($this->MyPOST['iecirknis_pieg']) . "')";
         }
         $rtest = $this->DB->query("select count(*) as x " . $query);
         if ($m = $this->DB->get_row($rtest)) {
             if ($m[x] > 1) {
                 $correct_count = $m[x];
             } else {
                 $correct_count = 0;
             }
         }
         $this->arr[-1] = array();
         // izejas masīva headeri
         if ($this->XML_Variants) {
             $diam__ = false;
             // p?rbaudei vai vajadz?g?s grup??anas XML atskaitei iesl?gtas
             $gar__ = false;
         }
         // pirmās kolonnas atskaitei ko izvēlējies lietotājs
         for ($i = 0; $i < $this->lsk; $i++) {
             $this->arr[-1][$i] = $this->mtipi[$this->MyPOST["gtype" . ($i + 1)]];
             if ($this->XML_Variants) {
                 $this->arr[-1][$i] = $this->MyPOST["gtype" . ($i + 1)];
                 if ($this->MyPOST["gtype" . ($i + 1)] == 'mind_pirms_red') {
                     $this->MyPOST["gvalues" . ($i + 1)] = LVM_distribution($this->MyPOST["gvalues" . ($i + 1)]);
                     $this->MyPOST["gvalues" . ($i + 1) . "_1"] = LVM_distribution($this->MyPOST["gvalues" . ($i + 1) . "_1"]);
                     $this->MyPOST["gvalues" . ($i + 1) . "_2"] = LVM_distribution($this->MyPOST["gvalues" . ($i + 1) . "_2"]);
                     if ($this->MyPOST["gvalues" . ($i + 1)] || $this->MyPOST["gvalues" . ($i + 1) . "_1"] || $this->MyPOST["gvalues" . ($i + 1) . "_2]"]) {
                         $diam__ = true;
                     }
                 }
                 if ($this->MyPOST["gtype" . ($i + 1)] == 'garums') {
                     $gar__ = true;
                 }
                 if ($this->MyPOST["gtype" . ($i + 1)] == 'brakis') {
                     $brak__ = true;
                 }
             } else {
                 if ($this->MyPOST["gtype" . ($i + 1)] == "pavadzime.pavadzime") {
                     $this->arr[-1][$i] = $this->mtipi['pavadzime.pavadzime'];
                 }
                 //kaut k?ds exception
             }
         }
         // pēdējās kolonnas kas visām atskaitēm vienādas
         $this->arr[-1][$i] = "Skaits";
         $i++;
         $this->arr[-1][$i] = "Bruto m3";
         $i++;
         //$this->arr[-1][$i]="Virsmērs m3";
         //$i++;
         //$this->arr[-1][$i]="Redukcija m3";
         //$i++;
         //$this->arr[-1][$i]="Brāķis m3";
         //$i++;
         //$this->arr[-1][$i]="Neto m3";
         //$i++;						// $i - tagad kolonnu skaits //
         //$this->arr[-1] - kolonnu nosaukumi un izvad?m? inform?cija atskait? v?l?k.
         $this->rowclosed = true;
         $summa = new CSumma();
         $this->arr_index = 0;
         // $query - satur nosac?jumus,kas jaliek gala katram selektam, nosacijumi izveidoti no formas Nosacijumiem
         if (!$this->ERRORS) {
             // rekurs?v?s funkcijas izsaukums
             $this->print_level(1, $query, $summa, false, 0);
         }
         // kopsumma
         ++$this->arr_index;
         $this->arr[$this->arr_index] = array();
         $this->arr[$this->arr_index][-1] = "Viss kopā";
         $this->arr[$this->arr_index][summa] = $summa;
         if ($this->XML_Variants) {
             if (!$gar__) {
                 $this->ERRORS .= "Kļūda! Netiek izmantota grupēšana pēc GARUMA!<br><br>";
             }
             if (!$diam__) {
                 $this->ERRORS .= "Kļūda! Netiek izmantota grupēšana pēc DIAMETRA vai arī garuma intervālu robežas neatbilst standartam!<br><br>";
             }
             if (!$brak__) {
                 $this->ERRORS .= "Kļūda! Netiek izmantota grupēšana pēc BRĀĶA!<br><br>";
             }
             if ($correct_count != $summa->skaits) {
                 $this->ERRORS .= "Kļūda grupēšanā! Sagrupēti " . (int) $summa->skaits . " baļķi no {$correct_count}.<br><br>";
             }
         }
     }
     //$this->ErrorCheck(); //
     if ($this->ERRORS) {
         return false;
     }
 }
 function C_REPORT($My_POST, &$DB, $isXML, $table_pref, $tmp_firm, $isPDF, $subMakeAll)
 {
     global $braki;
     global $sugas;
     global $arrPrintOut;
     global $RowCount;
     global $tmpDiamGroup;
     global $firmCode;
     global $lang;
     global $translate;
     global $tblName;
     global $firmCode;
     global $GroupOrder;
     global $tmpAllGroup;
     global $regSuperSum;
     global $report_XML;
     global $report_PDF;
     global $isAllReport;
     $this->tblName = $table_pref;
     $lang = "LAT";
     $this->report_XML = $isXML;
     $this->report_PDF = $isPDF;
     $this->isAllReport = $subMakeAll;
     //--------------------------------------------------------------------------------
     //--------------------------------------------------------------------------------
     $this->firmCode = $tmp_firm;
     $this->DB = $DB;
     $this->sugas = getSupremeSugas($getSuga = true, $isXML);
     $this->braki = corrTrueDeffectCode($this->firmCode, $isXML);
     $this->MyPOST = array_filter($My_POST);
     $this->RowCount = 0;
     $this->arrPrintOut = array();
     $this->tmpDiamGroup = array();
     $this->tmpGarGroup = array();
     $this->tmpSugaGroup = array();
     $this->tmpSkiraGroup = array();
     $this->tmpBrakGroup = array();
     $this->tmpNomGarGroup = array();
     $this->tmpNomGarBrakGroup = array();
     $this->tmpVirsmGroup = array();
     $this->tmpKoefGroup = array();
     $this->tmpRaukGroup = array();
     $this->GroupOrder = array();
     $this->tmpAllGroup = array();
     //fb($this->MyPOST,'POST_D');
     foreach ($this->MyPOST as $key => $tmpPOST) {
         if ($tmpPOST == 'mind_pirms_red') {
             $this->GroupOrder[substr($key, -1, 1)] = 'mind_pirms_red';
             $tmp_GValueInit = substr($key, 5, 2);
             $grupSK = substr($tmp_GValueInit, 0, 1);
             $this->tmpAllGroup[$grupSK]['mind_pirms_red'][0] = $this->MyPOST["gvalues" . $tmp_GValueInit];
             $this->tmpAllGroup[$grupSK]['mind_pirms_red'][1] = $this->MyPOST["gvalues" . $tmp_GValueInit . "_1"];
             $this->tmpAllGroup[$grupSK]['mind_pirms_red'][2] = $this->MyPOST["gvalues" . $tmp_GValueInit . "_2"];
         }
         if ($tmpPOST == 'garums') {
             $this->GroupOrder[substr($key, -1, 1)] = 'garums';
             $tmp_GValueInit = substr($key, 5, 2);
             $grupSK = substr($tmp_GValueInit, 0, 1);
             $this->tmpAllGroup[$grupSK]['garums'][0] = $this->MyPOST["gvalues" . $tmp_GValueInit];
             $this->tmpAllGroup[$grupSK]['garums'][1] = $this->MyPOST["gvalues" . $tmp_GValueInit . "_1"];
             $this->tmpAllGroup[$grupSK]['garums'][2] = $this->MyPOST["gvalues" . $tmp_GValueInit . "_2"];
         }
         if ($tmpPOST == 'suga') {
             $this->GroupOrder[substr($key, -1, 1)] = 'suga';
             $tmp_GValueInit = substr($key, 5, 2);
             $grupSK = substr($tmp_GValueInit, 0, 1);
             $this->tmpAllGroup[$grupSK]['suga'][0] = $this->MyPOST["gvalues" . $tmp_GValueInit];
             $this->tmpAllGroup[$grupSK]['suga'][1] = $this->MyPOST["gvalues" . $tmp_GValueInit . "_1"];
             $this->tmpAllGroup[$grupSK]['suga'][2] = $this->MyPOST["gvalues" . $tmp_GValueInit . "_2"];
         }
         if ($tmpPOST == 'skira') {
             $this->GroupOrder[substr($key, -1, 1)] = 'skira';
             $tmp_GValueInit = substr($key, 5, 2);
             $grupSK = substr($tmp_GValueInit, 0, 1);
             $this->tmpAllGroup[$grupSK]['skira'][0] = $this->MyPOST["gvalues" . $tmp_GValueInit];
             $this->tmpAllGroup[$grupSK]['skira'][1] = $this->MyPOST["gvalues" . $tmp_GValueInit . "_1"];
             $this->tmpAllGroup[$grupSK]['skira'][2] = $this->MyPOST["gvalues" . $tmp_GValueInit . "_2"];
         }
         if ($tmpPOST == 'brakis') {
             $this->GroupOrder[substr($key, -1, 1)] = 'brakis';
             $tmp_GValueInit = substr($key, 5, 2);
             $grupSK = substr($tmp_GValueInit, 0, 1);
             $this->tmpAllGroup[$grupSK]['brakis'][0] = $this->MyPOST["gvalues" . $tmp_GValueInit];
             $this->tmpAllGroup[$grupSK]['brakis'][1] = $this->MyPOST["gvalues" . $tmp_GValueInit . "_1"];
             $this->tmpAllGroup[$grupSK]['brakis'][2] = $this->MyPOST["gvalues" . $tmp_GValueInit . "_2"];
         }
         //---------------------------------------------------------------------------------
         if (substr($key, 0, 7) == 'raukums') {
             $tmp_GValueInit = substr($key, 7, 1);
             $grupSK = substr($tmp_GValueInit, 0, 1);
             $this->tmpRaukGroup[$grupSK][0] = $this->MyPOST["raukums" . $tmp_GValueInit];
             $this->tmpRaukGroup[$grupSK][1] = $this->MyPOST["raukums" . $tmp_GValueInit . "_1"];
             $this->tmpRaukGroup[$grupSK][2] = $this->MyPOST["raukums" . $tmp_GValueInit . "_2"];
         }
         if (substr($key, 0, 8) == 'virsmeri') {
             $tmp_GValueInit = substr($key, 8, 1);
             $grupSK = substr($tmp_GValueInit, 0, 1);
             $this->tmpNomGarGroup[$grupSK][0] = $this->MyPOST["virsmeri" . $tmp_GValueInit];
             $this->tmpNomGarGroup[$grupSK][1] = $this->MyPOST["virsmeri" . $tmp_GValueInit . "_1"];
             $this->tmpNomGarGroup[$grupSK][2] = $this->MyPOST["virsmeri" . $tmp_GValueInit . "_2"];
         }
         if (substr($key, 0, 15) == 'virsmeri_brakim') {
             $tmp_GValueInit = substr($key, 15, 1);
             $grupSK = substr($tmp_GValueInit, 0, 1);
             $this->tmpNomGarBrakGroup[$grupSK][0] = $this->MyPOST["virsmeri_brakim" . $tmp_GValueInit];
             $this->tmpNomGarBrakGroup[$grupSK][1] = $this->MyPOST["virsmeri_brakim" . $tmp_GValueInit . "_1"];
             $this->tmpNomGarBrakGroup[$grupSK][2] = $this->MyPOST["virsmeri_brakim" . $tmp_GValueInit . "_2"];
         }
         if (substr($key, 0, 8) == 'virsmers') {
             $tmp_GValueInit = substr($key, 8, 1);
             $grupSK = substr($tmp_GValueInit, 0, 1);
             $this->tmpVirsmGroup[$grupSK][0] = $this->MyPOST["virsmers" . $tmp_GValueInit];
             $this->tmpVirsmGroup[$grupSK][1] = $this->MyPOST["virsmers" . $tmp_GValueInit . "_1"];
             $this->tmpVirsmGroup[$grupSK][2] = $this->MyPOST["virsmers" . $tmp_GValueInit . "_2"];
         }
         if (substr($key, 0, 11) == 'koeficients') {
             $tmp_GValueInit = substr($key, 11, 1);
             $grupSK = substr($tmp_GValueInit, 0, 1);
             $this->tmpKoefGroup[$grupSK][0] = $this->MyPOST["koeficients" . $tmp_GValueInit];
             $this->tmpKoefGroup[$grupSK][1] = $this->MyPOST["koeficients" . $tmp_GValueInit . "_1"];
             $this->tmpKoefGroup[$grupSK][2] = $this->MyPOST["koeficients" . $tmp_GValueInit . "_2"];
         }
     }
     //Pārbaude uz pavadzīmes numuru-----------------------------------------------------------------
     if ($_SERVER['REQUEST_METHOD'] == 'POST') {
         if (trim($this->MyPOST['pavadzime']) != '') {
             if (!GetFromPavadzime($this->MyPOST['pavadzime'], 'pavadzime', "{$this->tblName}pavadzime")) {
                 $arrErrorMsgSystem = '001-Nav pavadzīmes';
             }
         } else {
             $arrErrorMsgSystem = '002-Nav pavadzīmes';
         }
     }
     //----------------------------------------------------------------------------------------------
     if ($this->MyPOST[subm] && !$this->ERRORS) {
         // --------------------cik grup??anas l?me?i izmantoti ----------------------------
         $this->lsk = 0;
         while ($this->MyPOST["gtype" . $this->grup . ($this->lsk + 1)] != '') {
             $this->lsk++;
         }
         // --------------------cik grup??anas l?me?i izmantoti ----------------------------
         // Pārbauda vai nav vairāku pavazdīmju ar šādu numuru
         if ($this->MyPOST['pavadzime'] && !$this->MyPOST[pavadzime_id]) {
             $pav_test_query = "select count(*) as x from {$this->tblName}pavadzime where pavadzime = '" . trim($this->MyPOST['pavadzime']) . "'";
             if ($this->MyPOST[datums_no] != '') {
                 $pav_test_query = $pav_test_query . " and kad_piegad >= '" . $this->MyPOST[datums_no] . "' ";
             }
             if ($this->MyPOST[datums_lidz] != '') {
                 $pav_test_query = $pav_test_query . " and kad_piegad <= '" . $this->MyPOST[datums_lidz] . "' ";
             }
             $r = $this->DB->query($pav_test_query);
             if ($m = $this->DB->get_row($r)) {
                 if ($m[x] > 1) {
                     $this->ERRORS .= "<font color=red>Eksistē " . $m[x] . " pavadzīmes ar numuru " . $this->MyPOST['pavadzime'] . "!</font><br><br>";
                 }
             }
         }
         //Pārbaude, vai ņemt no kopējās tabulas datus----------------------------------------------------
         if ($this->MyPOST[datums_no_diena] != '' || $this->MyPOST[pavadzime_id]) {
             //
             $query = " from " . $this->tblName . "balkis_temp INNER JOIN " . $this->tblName . "pavadzime ON " . $this->tblName . "balkis_temp.pavadzime = " . $this->tblName . "pavadzime.id WHERE 1=1 ";
         } else {
             $query = " from " . $this->tblName . "balkis INNER JOIN " . $this->tblName . "pavadzime ON " . $this->tblName . "balkis.pavadzime = " . $this->tblName . "pavadzime.id WHERE 1=1 ";
         }
         //-----------------------------------------------------------------------------------------------
         if ($this->MyPOST[datums_no_diena] != '') {
             $query = $query . " and kad_piegad >= '" . $this->MyPOST[datums_no_gads] . "-" . $this->MyPOST[datums_no_menesis] . "-" . $this->MyPOST[datums_no_diena] . " 00:00:00' ";
         }
         if ($this->MyPOST[datums_lidz_diena] != '') {
             $query = $query . " and kad_piegad <= '" . $this->MyPOST[datums_lidz_gads] . "-" . $this->MyPOST[datums_lidz_menesis] . "-" . $this->MyPOST[datums_lidz_diena] . " 00:00:00' ";
         }
         if ($this->MyPOST[piegad_grupa]) {
             $query = $query . " and {$this->tblName}pavadzime.piegad_grupa like '" . $this->MyPOST[piegad_grupa] . "%'";
         }
         if ($this->MyPOST[piegadataju_kods]) {
             $query = $query . " and {$this->tblName}pavadzime.piegad_kods = '" . $this->MyPOST[piegadataju_kods] . "'";
         }
         if ($this->MyPOST[pavadzime]) {
             $query = $query . " and {$this->tblName}pavadzime.pavadzime = '" . $this->MyPOST[pavadzime] . "'";
         }
         if ($this->MyPOST[pavadzime_id]) {
             $query = $query . " and {$this->tblName}pavadzime.id = '" . $this->MyPOST[pavadzime_id] . "'";
         }
         if ($this->MyPOST[suga] != '') {
             $query = $query . " and suga = '" . $this->MyPOST[suga] . "'";
         }
         if ($this->MyPOST[cirsmas_kods] != '') {
             $query = $query . " and cirsmas_kods like '%" . $this->MyPOST[cirsmas_kods] . "%'";
         }
         if ($this->MyPOST[brakis] != '') {
             $query = $query . " and brakis = '" . $this->MyPOST[brakis] . "'";
         }
         if ($this->MyPOST[fsc] != '') {
             $query = $query . " and fsc = '" . $this->MyPOST[fsc] . "'";
         }
         if ($this->MyPOST[kravas_id]) {
             $query = $query . " and kravas_id = '" . $this->MyPOST[kravas_id] . "'";
         }
         if ($this->MyPOST[auto]) {
             $query = $query . " and auto = '" . $this->MyPOST[auto] . "'";
         }
         if ($this->MyPOST[soferis]) {
             $query = $query . " and soferis = '" . $this->MyPOST[soferis] . "'";
         }
         if ($this->MyPOST[cenu_matrica]) {
             $query = $query . " and cenu_matrica = '" . $this->MyPOST[cenu_matrica] . "'";
         }
         if ($this->MyPOST[skira]) {
             $query = $query . " and skira = '" . $this->MyPOST[skira] . "'";
         }
         if (trim($this->MyPOST['batch_fails']) != '') {
             $query = $query . " and batch_fails in(" . $this->MyPOST[batch_fails] . ")";
         }
         if (trim($this->MyPOST['iecirknis_pieg']) != '') {
             $query = $query . " and LOWER(iecirknis_pieg)=LOWER('" . trim($this->MyPOST['iecirknis_pieg']) . "')";
         }
         $query = $query . " and opcija IN ('A','L')";
         $query2 = str_replace("{$this->tblName}balkis_temp", "{$this->tblName}balkis", $query);
         //      echo $query;
         if ($this->MyPOST[datums_no_diena] != '') {
             $this->DB->query("DELETE FROM {$this->tblName}balkis_temp");
             $this->DB->query("INSERT INTO {$this->tblName}balkis_temp (SELECT {$this->tblName}balkis.* " . $query2 . ")");
             $query = " from {$this->tblName}balkis_temp INNER JOIN {$this->tblName}pavadzime ON {$this->tblName}balkis_temp.pavadzime = {$this->tblName}pavadzime.id WHERE 1=1 ";
             //      echo "INSERT INTO {$this->tblName}balkis_temp (SELECT {$this->tblName}balkis.* " . $query2 . ")";
         }
         if ($this->MyPOST[pavadzime]) {
             $this->DB->query("DELETE FROM {$this->tblName}balkis_temp");
             if ($this->firmCode != 26) {
                 $this->DB->query("INSERT INTO {$this->tblName}balkis_temp (SELECT {$this->tblName}balkis.* " . $query2 . ")");
             } else {
                 $tmpCilinderFilter_query = $this->DB->query("SELECT {$this->tblName}balkis.* " . $query2);
                 while ($tmpCilinderFilter_arr = mysql_fetch_assoc($tmpCilinderFilter_query)) {
                     $balkis_id_qry = $tmpCilinderFilter_arr['id'];
                     $pavadzime_qry = $tmpCilinderFilter_arr['pavadzime'];
                     $nelieto_qry = $tmpCilinderFilter_arr['nelieto'];
                     $datums_laiks_qry = $tmpCilinderFilter_arr['datums_laiks'];
                     $suga_qry = $tmpCilinderFilter_arr['suga'];
                     $skira_qry = $tmpCilinderFilter_arr['skira'];
                     $miza_qry = $tmpCilinderFilter_arr['miza'];
                     $balkis_garums_pirms_red_tmp = $tmpCilinderFilter_arr['garums'];
                     $kabata_qry = $tmpCilinderFilter_arr['kabata'];
                     $tilpums_tmp_bruto = $tmpCilinderFilter_arr['tilpums_scan'];
                     $tilpums_tmp_neto = $tmpCilinderFilter_arr['tilpums'];
                     $tilpums_tmp_virsmers = $tilpums_tmp_bruto - $tilpums_tmp_neto;
                     for ($icCount = 0; $icCount < 4; $icCount++) {
                         $insertBOOL = false;
                         if ($icCount == 0 && $tmpCilinderFilter_arr['1_cilindra_tilpums'] > 0) {
                             $insertBOOL = true;
                             $balkis_diam_pirms_red_tmp = $tmpCilinderFilter_arr['mind_pec_red'];
                             $balkis_tilpums_tmp = ($tmpCilinderFilter_arr['1_cilindra_tilpums'] + $tilpums_tmp_virsmers) / 1000;
                             $balkis_tilpums_neto_tmp = $tmpCilinderFilter_arr['1_cilindra_tilpums'] / 1000;
                             //              $balkis_tilpums_tmp = $tmpCilinderFilter_arr['1_cilindra_tilpums']/1000;
                             $balkis_brakis_tmp = $tmpCilinderFilter_arr['brakis'];
                         }
                         if ($icCount == 1 && $tmpCilinderFilter_arr['2_cilindra_tilpums'] > 0) {
                             $insertBOOL = true;
                             $balkis_diam_pirms_red_tmp = $tmpCilinderFilter_arr['mind_miza'];
                             $balkis_tilpums_tmp = $tmpCilinderFilter_arr['2_cilindra_tilpums'] / 1000;
                             $balkis_tilpums_neto_tmp = $tmpCilinderFilter_arr['2_cilindra_tilpums'] / 1000;
                             $balkis_brakis_tmp = $tmpCilinderFilter_arr['brakis2'];
                         }
                         if ($icCount == 2 && $tmpCilinderFilter_arr['3_cilindra_tilpums'] > 0) {
                             $insertBOOL = true;
                             $balkis_diam_pirms_red_tmp = $tmpCilinderFilter_arr['maxd_miza'];
                             $balkis_tilpums_tmp = $tmpCilinderFilter_arr['3_cilindra_tilpums'] / 1000;
                             $balkis_tilpums_neto_tmp = $tmpCilinderFilter_arr['3_cilindra_tilpums'] / 1000;
                             $balkis_brakis_tmp = $tmpCilinderFilter_arr['brakis3'];
                         }
                         if ($icCount == 3 && $tmpCilinderFilter_arr['4_cilindra_tilpums'] > 0) {
                             $insertBOOL = true;
                             $balkis_diam_pirms_red_tmp = $tmpCilinderFilter_arr['diametrs5'];
                             $balkis_tilpums_tmp = $tmpCilinderFilter_arr['4_cilindra_tilpums'] / 1000;
                             $balkis_tilpums_neto_tmp = $tmpCilinderFilter_arr['4_cilindra_tilpums'] / 1000;
                             $balkis_brakis_tmp = $tmpCilinderFilter_arr['brakis4'];
                         }
                         if ($insertBOOL) {
                             $subQueryIns = "INSERT INTO {$this->tblName}balkis_temp (pavadzime,nelieto,datums_laiks,mind_pirms_red,garums,suga,skira,miza,mind_pec_red,gar_pec_red,mind_miza,brakis,maxd_miza,kabata,tilpums,tilpums_scan,import_id) VALUES ({$pavadzime_qry},'{$nelieto_qry}','{$datums_laiks_qry}',{$balkis_diam_pirms_red_tmp},{$balkis_garums_pirms_red_tmp},'{$suga_qry}','{$skira_qry}','{$miza_qry}',{$balkis_diam_pirms_red_tmp},{$balkis_garums_pirms_red_tmp},{$balkis_diam_pirms_red_tmp},'{$balkis_brakis_tmp}',{$balkis_diam_pirms_red_tmp},'{$kabata_qry}',{$balkis_tilpums_tmp},{$balkis_tilpums_neto_tmp},{$balkis_id_qry})";
                             $this->DB->query($subQueryIns);
                         }
                         //            echo $subQueryIns.'<br />';
                     }
                 }
             }
             if (mysql_affected_rows() == 0) {
                 $arrErrorMsgSystem = '003-Nav baļķu';
                 return false;
             }
             $query = " from {$this->tblName}balkis_temp INNER JOIN {$this->tblName}pavadzime ON {$this->tblName}balkis_temp.pavadzime = {$this->tblName}pavadzime.id WHERE 1=1 ";
         }
         $this->constrByMask($this->MyPOST[pavadzime_id]);
     }
 }
Beispiel #4
0
function print_report($grup)
{
    $DB_CON = new C_DB('localhost', DATABASE, LOGIN, PWD);
    $C_REP = new C_REPORT($_POST, $DB_CON, true, $grup);
    global $arrsum;
    //echo '$grup = ' . $grup;
    //print_r ($C_REP->arr);
    if ($grup == 1) {
        $arrsum = $C_REP->arr[count($C_REP->arr) - 1];
    } else {
        $arrsum[summa]->skaits = $arrsum[summa]->skaits + $C_REP->arr[count($C_REP->arr) - 1][summa]->skaits;
    }
    if ($grup == $_POST['grup']) {
        if ($arrsum[summa]->skaits != $arrsum[correct_count]) {
            $C_REP->ERRORS .= "Kļūda grupēšanā! Sagrupēti " . (int) $arrsum[summa]->skaits . " baļķi no " . $arrsum[correct_count] . ".<br><br>";
        }
    }
    /////////////////////////////////////////////////////////////////////////
    $_POST['pavadzime_head'] = $_POST['pavadzime'];
    set_param('akts_nr', $_POST['akts_nr_head']);
    set_param('pircejs_head', $_POST['pircejs_head']);
    set_param('pircejs_regnum', $_POST['pircejs_regnum']);
    set_param('pardevejs_head', $_POST['pardevejs_head']);
    set_param('pardevejs_regnum', $_POST['pardevejs_regnum']);
    set_param('pieg_lig_num', $_POST['pieg_lig_num']);
    set_param('datums', $_POST['datums_head']);
    set_param('iecirknis', $_POST['iecirknis_head']);
    set_param('pavadzime_head', $_POST['pavadzime_head']);
    set_param('transport_firm', $_POST['transport_firm']);
    set_param('auto', $_POST['auto_head']);
    set_param('soferis', $_POST['soferis_head']);
    set_param('vieta', $_POST['vieta_head']);
    set_param('piezimes', $_POST['piezimes_head']);
    set_param('atbildigais', $_POST['atbildigais_head']);
    set_param('custom11', $_POST['custom11_head']);
    set_param('custom12', $_POST['custom12_head']);
    $xml_vars['gvalues' . $grup . '1'] = $_POST['gvalues' . $grup . '1'];
    $xml_vars['gvalues' . $grup . '1_1'] = $_POST['gvalues' . $grup . '1_1'];
    $xml_vars['gvalues' . $grup . '1_2'] = $_POST['gvalues' . $grup . '1_2'];
    $xml_vars['gvalues' . $grup . '2'] = $_POST['gvalues' . $grup . '2'];
    $xml_vars['gvalues' . $grup . '2_1'] = $_POST['gvalues' . $grup . '2_1'];
    $xml_vars['gvalues' . $grup . '2_2'] = $_POST['gvalues' . $grup . '2_2'];
    $xml_vars['gvalues' . $grup . '3'] = $_POST['gvalues' . $grup . '3'];
    $xml_vars['gvalues' . $grup . '3_1'] = $_POST['gvalues' . $grup . '3_1'];
    $xml_vars['gvalues' . $grup . '3_2'] = $_POST['gvalues' . $grup . '3_2'];
    $xml_vars['gvalues' . $grup . '4'] = $_POST['gvalues' . $grup . '4'];
    $xml_vars['gvalues' . $grup . '4_1'] = $_POST['gvalues' . $grup . '4_1'];
    $xml_vars['gvalues' . $grup . '4_2'] = $_POST['gvalues' . $grup . '4_2'];
    $xml_vars['virsmeri' . $grup] = $_POST['virsmeri' . $grup];
    $xml_vars['virsmeri' . $grup . '_1'] = $_POST['virsmeri' . $grup . '_1'];
    $xml_vars['virsmeri' . $grup . '_2'] = $_POST['virsmeri' . $grup . '_2'];
    $xml_vars['koeficients' . $grup] = $_POST['koeficients' . $grup];
    $xml_vars['koeficients' . $grup . '_1'] = $_POST['koeficients' . $grup . '_1'];
    $xml_vars['koeficients' . $grup . '_2'] = $_POST['koeficients' . $grup . '_2'];
    $xml_vars['raukums' . $grup] = $_POST['raukums' . $grup];
    $xml_vars['raukums' . $grup . '_1'] = $_POST['raukums' . $grup . '_1'];
    $xml_vars['raukums' . $grup . '_2'] = $_POST['raukums' . $grup . '_2'];
    $xml_vars['pavadzime'] = $_POST['pavadzime'];
    /////////////////////////////////////////////////////////////////////////
    if ($C_REP->ERRORS) {
        ?>
<head>
					 <title>Kļūda!</title>
					 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
					</head>
					
					<center>
					<STYLE TYPE="text/css">
					  TD { font-size: 12px; }
					</STYLE>
					</style>
					<body>
						<center><br><br>
						<b><font color=red>Kļūda!</font></b>
						<br><br>
						<?php 
        echo $C_REP->ERRORS;
        ?>
						</center>
						<br><br>
						<input type=button value="Atkārtot" onclick="history.back(-1)">
					</body>
					</html>
			<?php 
        exit;
    }
    //echo $C_REP->GetHTML();
    //exit();
    //create header///
    //header ("Content-type: text/xml");
    //header ("Content-type: file");
    //header ("Content-Disposition: attachment; filename=".$_POST['pavadzime'].".xml");
    if (!$_POST['pavadzime_id']) {
        $_POST['pavadzime_id'] = GetFromPavadzime($_POST['pavadzime'], 'id');
    }
    $pavadz_datums = GetFromPavadzimeID($_POST['pavadzime_id'], 'kad_piegad', 'vikawood_pavadzime');
    if ($pavadz_datums == '0000-00-00') {
        $pavadz_datums = false;
    }
    if (!$pavadz_datums) {
        $pavadz_datums = GetPavadzimeDatumsID($_POST['pavadzime_id']);
        if ($pavadz_datums == '0000-00-00') {
            $pavadz_datums = '';
        }
        $pavadz_datums = str_replace('.', '-', $pavadz_datums);
    }
    if ($pavadz_datums) {
        $pavadz_datums = substr($pavadz_datums, 0, 10);
    }
    if (!$uzmerisanas_datums) {
        $uzmerisanas_datums = GetUzmerisanasDatumsID($_POST['pavadzime_id']);
        if ($uzmerisanas_datums == '0000-00-00') {
            $uzmerisanas_datums = '';
        }
        $uzmerisanas_datums = str_replace('.', '-', $uzmerisanas_datums);
    }
    if ($uzmerisanas_datums) {
        $uzmerisanas_datums = substr($uzmerisanas_datums, 0, 10);
    }
    $arr = $C_REP->GetDataArray();
    $lsk = 5;
    $output = "";
    if ($_POST['grup'] == 1) {
        $output = $output . '<?xml version="1.0" encoding="UTF-8"?>';
        $output = $output . "<Invoice>";
        $output = $output . "\t<EntryDate>" . trim($_POST['datums_head']) . "</EntryDate>";
        $output = $output . "\t<InvoiceNumber>" . $_POST['pavadzime_head'] . "</InvoiceNumber>";
        $output = $output . "\t<InvoiceDate>" . $pavadz_datums . "</InvoiceDate>";
        $output = $output . "\t<ContractNumber>" . $_POST['pieg_lig_num'] . "</ContractNumber>";
        $output = $output . "\t<MeasurerDocNr>" . $_POST['akts_nr_head'] . "</MeasurerDocNr>";
        $output = $output . "\t<Supplier>";
        $output = $output . "\t\t<Name>" . $_POST['pardevejs_head'] . "</Name>";
        $output = $output . "\t\t<RegNr>" . $_POST['pardevejs_regnum'] . "</RegNr>";
        $output = $output . "\t</Supplier>";
        $output = $output . "\t<Reciever>";
        $output = $output . "\t\t<Name>" . $_POST['pircejs_head'] . "</Name>";
        $output = $output . "\t\t<RegNr>" . $_POST['pircejs_regnum'] . "</RegNr>";
        $output = $output . "\t</Reciever>";
        $output = $output . "\t<Carrier>";
        if ($_POST['transport_firm']) {
            $output = $output . "<FirmName>" . $_POST['transport_firm'] . "</FirmName>";
        } else {
            $rAuto = mysql_query("select * from auto where numurs = '" . GetFromPavadzimeID($_POST['pavadzime_id'], 'auto', 'vikawood_pavadzime') . "'");
            if (mysql_num_rows($rAuto) > 0) {
                $mAuto = mysql_fetch_array($rAuto);
                $parvadatajs_id = $mAuto['parvadatajs'];
                $rParvadatajs = mysql_query("select * from parvadatajs where id = {$parvadatajs_id}");
                $mParvadatajs = mysql_fetch_array($rParvadatajs);
                $output = $output . "<FirmName>" . $mParvadatajs['nosaukums'] . "</FirmName>";
            }
        }
        $output = $output . "<TruckNumber>" . trim(GetFromPavadzimeID($_POST['pavadzime_id'], 'auto', 'vikawood_pavadzime')) . "</TruckNumber> ";
        $output = $output . "<Driver>" . GetFromPavadzimeID($_POST['pavadzime_id'], 'soferis', 'vikawood_pavadzime') . "</Driver>";
        $output = $output . "</Carrier>";
        $output = $output . "<Measuring>";
        $output = $output . "\t<MeasuringDate>" . $uzmerisanas_datums . "</MeasuringDate>";
        $output = $output . "\t<OperatorName>VMF Latvia</OperatorName>";
        $output = $output . "\t<MeasureMethod>I</MeasureMethod>";
        $output = $output . "</Measuring>";
        $output = $output . "<AssortmOrigin> ";
        $output = $output . "\t<FSCNumber>" . GetFromPavadzimeID($_POST['pavadzime_id'], 'fsc', 'vikawood_pavadzime') . "</FSCNumber>";
        $output = $output . "\t<SlashCode>" . GetFromPavadzimeID($_POST['pavadzime_id'], 'cirsmas_kods', 'vikawood_pavadzime') . "</SlashCode>";
        $output = $output . "</AssortmOrigin >";
    }
    if ($lsk > 1) {
        for ($j = $lsk - 2; $j >= 0; $j--) {
            $v = $arr[0][$j];
            for ($i = 0; $i < count($arr); $i++) {
                // iekopējam ja tukšs
                if ($arr[$i][$j] == "" && $arr[$i][$j + 1] != "") {
                    $arr[$i][$j] = $v;
                }
                // ja nav tukšs paņem vērtību
                if ($arr[$i][$j] != "") {
                    $v = $arr[$i][$j];
                }
            }
        }
    }
    /// drukājam tabulu
    for ($i = 0; $i < count($arr); $i++) {
        if ($arr[$i][summa]->skaits != 0 && !$arr[$i][-1]) {
            $output = $output . "\n\n<DataRow>\n";
            $output = $output . "<AssortmentGroup>ZB</AssortmentGroup>\n";
            $refused = false;
            $caurm_kods = '';
            for ($j = 0; $j < $lsk; $j++) {
                switch ($arr[-1][$j]) {
                    case 'suga':
                        //$arr[$i][$j]=$LVM_sugas[$arr[$i][$j]]; // pārveidojam uz LVM sugām P:E
                        $output = $output . "<Specie>" . $arr[$i][$j] . "</Specie>\n";
                        break;
                    case 'brakis':
                        if (round($arr[$i][summa]->brakis, 3) > 0 && trim($arr[$i][$j]) == "") {
                            $arr[$i][$j] = "D";
                        }
                        if ($arr[$i][$j] != '') {
                            $refused = true;
                            $output = $output . "<RejectReason>" . $arr[$i][$j] . "</RejectReason>\n";
                        }
                        break;
                    case 'mind_pirms_red':
                        $SG = trim($arr[$i][$j]);
                        if ($SG == '0-79') {
                            $SG = "M";
                        }
                        //echo $SG . '<br />';
                        if ($SG == '120-129' || $SG == '130-139') {
                            $SG = '120-139';
                        }
                        $output = $output . "<SizeGroup>" . $SG . "</SizeGroup>\n";
                        $caurm_kods = trim($arr[$i][$j]);
                        if ($caurm_kods == '120-129' || $caurm_kods == '130-139') {
                            $caurm_kods = '120-139';
                        }
                        break;
                    case 'garums':
                        $a = explode('-', $arr[$i][$j]);
                        $output = $output . "<Length>\n<LowerLimit>{$a['0']}</LowerLimit>\n<UpperLimit>{$a['1']}</UpperLimit>\n</Length>\n";
                        break;
                    case 'cenu_matrica':
                        $output = $output . "<Price>" . $arr[$i][$j] . "</Price>\n";
                    default:
                        //echo "<kaut_kas>".$arr[$i][$j]."</kaut_kas>\n";
                }
            }
            //echo "<td align=right>".round($arr[$i][summa]->bruto,3)."</td><td width=5>";
            $output = $output . "<Assortment>" . get_LVM_asort_kods_no_caurm_kods($caurm_kods) . "</Assortment>";
            $output = $output . "<Overlength>" . round($arr[$i][summa]->virsmers, 3) . "</Overlength>\n";
            $output = $output . "<LengthReduction>" . round($arr[$i][summa]->redukcija_d + $arr[$i][summa]->redukcija_l, 3) . "</LengthReduction>\n";
            if ($refused) {
                $volume = round($arr[$i][summa]->brakis, 3);
            } else {
                $volume = round($arr[$i][summa]->neto, 3);
            }
            $output = $output . "<NetVolume>" . $volume . "</NetVolume>\n";
            $output = $output . "<Count>" . round($arr[$i][summa]->skaits, 3) . "</Count>\n";
            $output = $output . "<NotAgreed>0</NotAgreed>\n";
            $output = $output . "</DataRow>";
        }
    }
    if ($grup == $_POST['grup']) {
        $output = $output . "</Invoice>";
    }
    return $output;
}