public Boolean Iosi(string DoDatuma, string Konto, int Komitent) { Boolean vrati = true; int KRAJ = 0; string OdDatuma = ""; string sselect = ""; decimal pom = 0; ////Dim rsKumulativ As New ADODB.Recordset ////rsKumulativ.CursorLocation = adUseClient ////Dim cmd As New ADODB.Command ////Set cmd.ActiveConnection = cnn1 ////cmd.CommandType = adCmdText ////cmd.CommandTimeout = 0 //ivana 18.8.2021. // if (Konto.Trim() == "") return false; OdDatuma = "01.01." + Convert.ToString(Convert.ToDateTime(DoDatuma).Year); sql = "Drop table Iosi"; //Djora 14.07.21 //int rez = db.ReturnInt(sql, 0); int rez = db.ReturnInt2(sql, 0); sselect = " select g.iidd as iid,g.konto,k.Nazivkom,s.oznval,g.datum,g.opisknj,g.duguje,"; sselect += "g.potrazuje,g.saldo,k.Adresa,k.Mesto,k.Ptt,ko.AvPZnak, g.NazivOrg, g.id_komitentiview,k.PIB "; sselect += " INTO iosi "; sselect += " FROM GlavnaKnjiga as g WITH (NOLOCK), KomitentiTotali as k WITH (NOLOCK),Kontni as ko WITH(NOLOCK),SifrarnikValuta as s WITH(NOLOCK) "; sselect += " where g.NazivOrg = '" + Program.imeFirme + "' and ko.konto = g.konto "; sselect += " AND s.ID_SifrarnikValuta=g.ID_SifrarnikValuta "; sselect += " and k.ID_KomitentiTotali= g.ID_KomitentiView and g.OpisKnj not like '%/s%' "; sselect += " and datum>='" + OdDatuma.Trim() + "' and datum<='" + DoDatuma.Trim() + "'"; if (Komitent > 1) { sselect += " and k.ID_KomitentiTotali=" + Komitent.ToString(); } if (Konto.Trim() != "") { sselect += " and g.Konto='" + Konto.Trim() + "'"; } SqlCommand cmd = new SqlCommand(sselect); string message = db.Comanda(cmd); if (message != "") { MessageBox.Show(message); } // Jovana 22.09.21 if (Konto.Trim() == "") { return(false); } sselect = ""; if (Konto.Substring(0, 1) == "2" || Konto.Substring(0, 1) == "1" || Konto.Substring(0, 1) == "0") { sselect = " SELECT SUM(duguje - potrazuje) AS saldo From Iosi "; } else { if (Konto.Substring(0, 1) == "4") { sselect = " SELECT SUM(potrazuje-duguje ) AS saldo From Iosi "; } } DataTable k = db.ReturnDataTable(sselect); if (k.Rows.Count > 0) { if (string.IsNullOrEmpty((k.Rows[0]["saldo"].ToString()))) { pom = 0; } else { pom = Convert.ToDecimal(k.Rows[0]["saldo"].ToString()); } } else { vrati = false; } KRAJ = 0; sselect = "select * from Iosi order by datum DESC "; k = db.ReturnDataTable(sselect); for (int i = 0; i < k.Rows.Count; i++) { if (KRAJ == 1) { //Djora 15.07.21 //t.Rows[0]["iid"] = 0; //k.Rows[0]["iid"] = 0; //Djora 15.07.21 poc cmd = new SqlCommand("update iosi set iid=0 where iid=" + k.Rows[i]["iid"].ToString()); message = db.Comanda(cmd); //Djora 15.07.21 kraj } else if (Konto.Substring(0, 1) == "2" || Konto.Substring(0, 1) == "1" || Konto.Substring(0, 1) == "0") // dugovna konta { //Djora 22.09.21 //if (Convert.ToDecimal(k.Rows[i]["Duguje"].ToString()) >= 0) if (!(Convert.ToDecimal(k.Rows[i]["Duguje"].ToString()) < 0)) { pom -= Convert.ToDecimal(k.Rows[i]["Duguje"].ToString()); } if (pom <= 0) { if (pom == 0) { } else { pom += Convert.ToDecimal(k.Rows[i]["Duguje"].ToString()); k.Rows[i]["Duguje"] = pom; //Djora 22.09.21 UpdateTabele(k.Rows[i]["iid"].ToString(), k.Rows[i]["Duguje"].ToString()); } KRAJ = 1; } } else //potrazna konta { if (Convert.ToDecimal(k.Rows[i]["Potrazuje"].ToString()) >= 0) { pom -= Convert.ToDecimal(k.Rows[i]["Potrazuje"].ToString()); k.Rows[i]["Duguje"] = k.Rows[i]["Potrazuje"]; //Djora 22.09.21 UpdateTabele(k.Rows[i]["iid"].ToString(), k.Rows[i]["Duguje"].ToString()); } } if (pom <= 0) { if (pom == 0) { } else { pom += Convert.ToDecimal(k.Rows[i]["Potrazuje"].ToString()); k.Rows[i]["Duguje"] = pom; //Djora 22.09.21 UpdateTabele(k.Rows[i]["iid"].ToString(), k.Rows[i]["Duguje"].ToString()); } KRAJ = 1; } //rsKumulativ.Update // rsKumulativ.MoveNext } //Djora 15.07.21 pocetak --------------------------------------- cmd = new SqlCommand("delete from Iosi where iid = 0"); message = db.Comanda(cmd); cmd = new SqlCommand("delete from Iosi where ( duguje<0.1)"); message = db.Comanda(cmd); DataTable tu = db.ReturnDataTable("select iid from Iosi"); if (tu.Rows.Count == 0) { vrati = false; } //Djora 15.07.21 kraj -------------------------------------------- return(vrati); }