Ejemplo n.º 1
0
        private void PrometProdajneRobe(bool pice, bool hrana, bool stavke)
        {
            RecLineChars = Convert.ToInt16(DTsetting.Rows[0]["broj_slova_na_racunu"].ToString());

            string podgrupa_pice = "";

            if (pice)
            {
                podgrupa_pice = " AND roba.id_podgrupa <> '1'";
            }
            string podgrupa_hrana = "";

            if (hrana)
            {
                podgrupa_hrana = " AND roba.id_podgrupa <> '2'";
            }

            string sql = "SELECT " +
                         " racun_stavke.kolicina," +
                         " grupa.grupa," +
                         " racun_stavke.sifra_robe," +
                         " racun_stavke.mpc," +
                         " racun_stavke.porez_potrosnja," +
                         " racun_stavke.porez," +
                         " racuni.nacin_placanja," +
                         //" racuni.ukupno_kartice," +
                         //" racuni.ukupno_virman," +
                         " roba.naziv" +
                         " FROM racun_stavke" +
                         " LEFT JOIN racuni ON racuni.broj_racuna=racun_stavke.broj_racuna  AND racuni.id_ducan=racun_stavke.id_ducan AND racuni.id_kasa=racun_stavke.id_blagajna" +
                         " LEFT JOIN roba ON roba.sifra=racun_stavke.sifra_robe" +
                         " LEFT JOIN grupa ON grupa.id_grupa=roba.id_grupa" +
                         " WHERE  racuni.datum_racuna>'" + Convert.ToDateTime(datumOD).ToString("yyyy-MM-dd H:mm:ss") + "' AND racuni.datum_racuna<'" + Convert.ToDateTime(datumDO).ToString("yyyy-MM-dd H:mm:ss") + "' " +
                         " AND racun_stavke.id_ducan='" + Util.Korisno.idDucan + "' AND racun_stavke.id_blagajna='" + Util.Korisno.idKasa + "' " +
                         " " + podgrupa_hrana + podgrupa_pice +
                         " " + " ORDER BY grupa.grupa";

            DataTable DT = classSQL.select(sql, "racun_stavke").Tables[0];

            decimal kol        = 0;
            decimal pnp        = 0;
            decimal pdv        = 0;
            decimal mpc        = 0;
            decimal pnpUKUPNO  = 0;
            decimal pdvUKUPNO  = 0;
            decimal SVE_UKUPNO = 0;
            decimal OSNOVICA   = 0;
            string  g          = "";

            if (DTpdv.Columns["stopa"] == null)
            {
                DTpdv.Columns.Add("stopa");
                DTpdv.Columns.Add("iznos");
            }

            if (DTartikli.Columns["sifra"] == null)
            {
                DTartikli.Columns.Add("sifra");
                DTartikli.Columns.Add("kolicina");
                DTartikli.Columns.Add("mpc");
                DTartikli.Columns.Add("naziv");
            }

            PrintTextLine(DT_tvr.Rows[0]["skraceno_ime"].ToString());
            PrintTextLine("Adresa: " + DT_tvr.Rows[0]["adresa"].ToString());
            if (DT_tvr.Rows[0]["poslovnica_adresa"].ToString() != "")
            {
                PrintTextLine(DT_tvr.Rows[0]["poslovnica_adresa"].ToString());
            }
            PrintTextLine("Telefon: " + DT_tvr.Rows[0]["tel"].ToString());
            PrintTextLine("Datum: " + DateTime.Now);
            PrintTextLine("OIB: " + DT_tvr.Rows[0]["oib"].ToString());
            PrintTextLine("OD: " + datumOD);
            PrintTextLine("DO: " + datumDO);
            PrintTextLine("POLOG: " + blagMinimum);
            PrintTextLine(new string('-', RecLineChars));

            if (DTpdvN.Columns["stopa"] == null)
            {
                DTpdvN.Columns.Add("stopa");
                DTpdvN.Columns.Add("iznos");
                DTpdvN.Columns.Add("nacin");
                DTpdvN.Columns.Add("osnovica");
            }
            else
            {
                DTpdvN.Clear();
            }

            if (DTosnovica.Columns["osnovica"] == null)
            {
                DTosnovica.Columns.Add("osnovica");
                DTosnovica.Columns.Add("nacin");
            }
            else
            {
                DTosnovica.Clear();
            }

            decimal UG = 0;
            decimal UK = 0;
            decimal UV = 0;
            decimal UO = 0;

            foreach (DataRow row in DT.Rows)
            {
                kol = Convert.ToDecimal(row["kolicina"].ToString());
                mpc = Convert.ToDecimal(row["mpc"].ToString());
                pnp = Convert.ToDecimal(row["porez_potrosnja"].ToString());
                pdv = Convert.ToDecimal(row["porez"].ToString());

                //Ovaj kod dobiva PDV
                decimal PreracunataStopaPDV = Convert.ToDecimal((100 * pdv) / (100 + pdv + pnp));
                decimal ppdv = (((mpc * kol) * PreracunataStopaPDV) / 100);
                pdvUKUPNO = ppdv + pdvUKUPNO;

                //Ovaj kod dobiva porez na potrošnju
                decimal PreracunataStopaPorezNaPotrosnju = Convert.ToDecimal((100 * pnp) / (100 + pdv + pnp));
                decimal ppnp = (((mpc * kol) * PreracunataStopaPorezNaPotrosnju) / 100);
                pnpUKUPNO = ppnp + pnpUKUPNO;

                SVE_UKUPNO = (mpc * kol) + SVE_UKUPNO;

                if (row["nacin_placanja"].ToString() == "G")
                {
                    StopePDVaN(pdv, ppdv, "G", ((mpc * kol) - ((ppdv) + (ppnp))));
                    UG = (mpc * kol) + UG;
                }
                else if (row["nacin_placanja"].ToString() == "K")
                {
                    StopePDVaN(pdv, ppdv, "K", ((mpc * kol) - ((ppdv) + (ppnp))));
                    UK = (mpc * kol) + UK;
                }
                else if (row["nacin_placanja"].ToString() == "T")
                {
                    StopePDVaN(pdv, ppdv, "T", ((mpc * kol) - ((ppdv) + (ppnp))));
                    UV = (mpc * kol) + UV;
                }
                else if (row["nacin_placanja"].ToString() == "O")
                {
                    StopePDVaN(pdv, ppdv, "O", ((mpc * kol) - ((ppdv) + (ppnp))));
                    UO = (mpc * kol) + UO;
                }

                string ajjj = row["nacin_placanja"].ToString();

                Artikli(row["naziv"].ToString(), kol, row["naziv"].ToString(), mpc.ToString());
                StopePDVa(pdv, ((mpc * kol) * PreracunataStopaPDV) / 100);

                OSNOVICA = ((mpc * kol) - ((ppdv) + (ppnp))) + OSNOVICA;
            }

            int a = Convert.ToInt16(DTsetting.Rows[0]["ispred_artikl"].ToString()) - 3;
            int k = Convert.ToInt16(DTsetting.Rows[0]["ispred_kolicine"].ToString()) + 3;
            int c = Convert.ToInt16(DTsetting.Rows[0]["ispred_cijene"].ToString());
            int s = Convert.ToInt16(DTsetting.Rows[0]["ispred_ukupno"].ToString()) + 3;

            PrintTextLine(String.Empty);
            PrintText(TruncateAt("STAVKA".PadRight(a), a));
            PrintText(TruncateAt("KOL".PadLeft(k), k));
            PrintText(TruncateAt("CIJENA".PadLeft(c), c));
            PrintText(TruncateAt("UKUPNO".PadLeft(s), s));
            PrintText("\r\n");
            PrintTextLine(new string('=', RecLineChars));

            for (int i = 0; i < DTartikli.Rows.Count; i++)
            {
                PrintText(TruncateAt(DTartikli.Rows[i]["naziv"].ToString().PadRight(a), a));
                PrintText(TruncateAt(Convert.ToDecimal(DTartikli.Rows[i]["kolicina"].ToString()).ToString("#0.00").PadLeft(k), k));
                PrintText(TruncateAt(Convert.ToDecimal(DTartikli.Rows[i]["mpc"].ToString()).ToString("#0.00").PadLeft(c), c));
                PrintTextLine(TruncateAt((Convert.ToDecimal(DTartikli.Rows[i]["mpc"].ToString()) * Convert.ToDecimal(DTartikli.Rows[i]["kolicina"].ToString())).ToString("#0.00").PadLeft(s), s));
            }

            PrintTextLine("");
            PrintTextLine(new string('-', RecLineChars));

            //PrintTextLine("OSNOVICA: " + OSNOVICA.ToString("#0.000"));
            PrintTextLine("PNP ukupno:       " + pnpUKUPNO.ToString("#0.000"));

            //for(int i=0; i<DTpdv.Rows.Count; i++)
            //{
            //    PrintTextLine("PDV " + DTpdv.Rows[i]["stopa"].ToString() + "%: " + Convert.ToDecimal(DTpdv.Rows[i]["iznos"].ToString()).ToString("#0.00"));
            //}

            //GOTOVINA
            if (UG > 0)
            {
                PrintTextLine(new string('-', RecLineChars));
                PrintTextLine("UKUPNO GOTOVINA:  " + UG.ToString("#0.000"));
                //for (int i = 0; i < DTosnovica.Rows.Count; i++)
                //{
                //    if (DTosnovica.Rows[i]["nacin"].ToString() == "G")
                //        PrintTextLine("OSNOVICA: " + Convert.ToDecimal(DTosnovica.Rows[i]["osnovica"].ToString()).ToString("#0.00"));
                //}
                for (int i = 0; i < DTpdvN.Rows.Count; i++)
                {
                    if (DTpdvN.Rows[i]["nacin"].ToString() == "G")
                    {
                        PrintTextLine("OSNOVICA PDV " + DTpdvN.Rows[i]["stopa"].ToString() + "%: " + Convert.ToDecimal(DTpdvN.Rows[i]["osnovica"].ToString()).ToString("#0.000"));
                        PrintTextLine("PDV " + DTpdvN.Rows[i]["stopa"].ToString() + "%:          " + Convert.ToDecimal(DTpdvN.Rows[i]["iznos"].ToString()).ToString("#0.000"));
                    }
                }
            }

            //KARTICA
            if (UK > 0)
            {
                PrintTextLine(new string('-', RecLineChars));
                PrintTextLine("UKUPNO KARTICE:  " + UK.ToString("#0.000"));
                //for (int i = 0; i < DTosnovica.Rows.Count; i++)
                //{
                //    if (DTosnovica.Rows[i]["nacin"].ToString() == "K")
                //        PrintTextLine("OSNOVICA: " + Convert.ToDecimal(DTosnovica.Rows[i]["osnovica"].ToString()).ToString("#0.00"));
                //}
                for (int i = 0; i < DTpdvN.Rows.Count; i++)
                {
                    if (DTpdvN.Rows[i]["nacin"].ToString() == "K")
                    {
                        PrintTextLine("OSNOVICA PDV " + DTpdvN.Rows[i]["stopa"].ToString() + "%: " + Convert.ToDecimal(DTpdvN.Rows[i]["osnovica"].ToString()).ToString("#0.000"));
                        PrintTextLine("PDV " + DTpdvN.Rows[i]["stopa"].ToString() + "%:          " + Convert.ToDecimal(DTpdvN.Rows[i]["iznos"].ToString()).ToString("#0.000"));
                    }
                }
            }

            //VIRMAN
            if (UV > 0)
            {
                PrintTextLine(new string('-', RecLineChars));
                PrintTextLine("UKUPNO VIRMAN:  " + UV.ToString("#0.000"));
                //for (int i = 0; i < DTosnovica.Rows.Count; i++)
                //{
                //    if (DTosnovica.Rows[i]["nacin"].ToString() == "T")
                //        PrintTextLine("OSNOVICA: " + Convert.ToDecimal(DTosnovica.Rows[i]["osnovica"].ToString()).ToString("#0.00"));
                //}
                for (int i = 0; i < DTpdvN.Rows.Count; i++)
                {
                    if (DTpdvN.Rows[i]["nacin"].ToString() == "T")
                    {
                        PrintTextLine("OSNOVICA PDV " + DTpdvN.Rows[i]["stopa"].ToString() + "%: " + Convert.ToDecimal(DTpdvN.Rows[i]["osnovica"].ToString()).ToString("#0.000"));
                        PrintTextLine("PDV " + DTpdvN.Rows[i]["stopa"].ToString() + "%:          " + Convert.ToDecimal(DTpdvN.Rows[i]["iznos"].ToString()).ToString("#0.000"));
                    }
                }
            }

            //ostalo
            if (UO > 0)
            {
                PrintTextLine(new string('-', RecLineChars));
                PrintTextLine("UKUPNO OSTALO:    " + UO.ToString("#0.000"));

                for (int i = 0; i < DTpdvN.Rows.Count; i++)
                {
                    if (DTpdvN.Rows[i]["nacin"].ToString() == "O")
                    {
                        PrintTextLine("OSNOVICA PDV " + DTpdvN.Rows[i]["stopa"].ToString() + "%: " + Convert.ToDecimal(DTpdvN.Rows[i]["osnovica"].ToString()).ToString("#0.000"));
                        PrintTextLine("PDV " + DTpdvN.Rows[i]["stopa"].ToString() + "%:          " + Convert.ToDecimal(DTpdvN.Rows[i]["iznos"].ToString()).ToString("#0.000"));
                    }
                }
            }

            PrintTextLine(new string('-', RecLineChars));

            PrintTextLine("OSNOVICA UKUPNO:  " + OSNOVICA.ToString("#0.00"));
            for (int i = 0; i < DTpdv.Rows.Count; i++)
            {
                PrintTextLine("PDV " + DTpdv.Rows[i]["stopa"].ToString() + "% UKUPNO:   " + Convert.ToDecimal(DTpdv.Rows[i]["iznos"].ToString()).ToString("#0.00"));
            }
            PrintTextLine("SVE UKUPNO:       " + SVE_UKUPNO.ToString("#0.00"));

            System.Drawing.Text.PrivateFontCollection privateFonts = new PrivateFontCollection();
            privateFonts.AddFontFile("Slike/msgothic.ttc");
            System.Drawing.Font font = new Font(privateFonts.Families[0], 11);

            rtb.Font = font;
            rtb.Text = tekst;
        }
Ejemplo n.º 2
0
        private void PrometRobe()
        {
            string sql1 = "SELECT " +
                          " podaci_tvrtka.ime_tvrtke," +
                          " podaci_tvrtka.skraceno_ime," +
                          " 'OIB: ' + podaci_tvrtka.oib AS oib," +
                          " podaci_tvrtka.tel," +
                          " podaci_tvrtka.fax," +
                          " podaci_tvrtka.mob," +
                          " podaci_tvrtka.iban," +
                          " podaci_tvrtka.adresa," +
                          " podaci_tvrtka.vl," +
                          " podaci_tvrtka.poslovnica_adresa," +
                          " podaci_tvrtka.poslovnica_grad," +
                          " podaci_tvrtka.email," +
                          " podaci_tvrtka.naziv_fakture," +
                          " podaci_tvrtka.text_bottom," +
                          " grad.grad + '' + grad.posta AS grad" +
                          " FROM podaci_tvrtka" +
                          " LEFT JOIN grad ON grad.id_grad=podaci_tvrtka.id_grad" +
                          "";

            classSQL.CeAdatpter(sql1).Fill(dSRpodaciTvrtke, "DTRpodaciTvrtke");

            ukupno_rabat = 0;

            string skl = "";

            if (id_podgrupa != null)
            {
                skl = " AND roba.id_podgrupa='" + id_podgrupa + "'";
            }

            string duc = "";

            if (ducan != null)
            {
                duc = " AND racuni.id_ducan='" + ducan + "'";
            }

            string blag = "";

            if (blagajnik != null)
            {
                blag = " AND racuni.id_blagajnik='" + blagajnik + "'";
            }

            string art = "";

            if (artikl != null)
            {
                art = " AND racun_stavke.sifra_robe='" + artikl + "'";
            }

            string gr = "";

            if (grupa != null)
            {
                gr = " AND grupa.id_grupa='" + grupa + "'";
            }

            string sql = "SELECT " +
                         " racun_stavke.kolicina," +
                         " grupa.grupa," +
                         " racun_stavke.sifra_robe," +
                         " racun_stavke.mpc," +
                         " racun_stavke.porez_potrosnja," +
                         " racun_stavke.porez," +
                         " racun_stavke.rabat," +
                         " racuni.nacin_placanja," +
                         " roba.naziv," +
                         " roba.jm" +
                         " FROM racun_stavke" +
                         " LEFT JOIN racuni ON racuni.broj_racuna=racun_stavke.broj_racuna AND racuni.id_ducan=racun_stavke.id_ducan AND racuni.id_kasa=racun_stavke.id_blagajna" +
                         " LEFT JOIN roba ON roba.sifra=racun_stavke.sifra_robe" +
                         " LEFT JOIN grupa ON grupa.id_grupa=roba.id_grupa" +
                         " WHERE  racuni.datum_racuna>'" + datumOD.ToString("yyyy-MM-dd H:mm:ss") + "' AND racuni.datum_racuna<'" + datumDO.ToString("yyyy-MM-dd H:mm:ss") + "'" +
                         " " + skl + blag + duc + art + gr + " ORDER BY grupa";
            DataTable DT = classSQL.select(sql, "racun_stavke").Tables[0];

            decimal kol        = 0;
            decimal pnp        = 0;
            decimal pdv        = 0;
            decimal mpc        = 0;
            decimal pnpUKUPNO  = 0;
            decimal pdvUKUPNO  = 0;
            decimal SVE_UKUPNO = 0;
            decimal OSNOVICA   = 0;
            string  g          = "";

            if (DTpdv.Columns["stopa"] == null)
            {
                DTpdv.Columns.Add("stopa");
                DTpdv.Columns.Add("iznos");
            }

            if (DTpdvN.Columns["stopa"] == null)
            {
                DTpdvN.Columns.Add("stopa");
                DTpdvN.Columns.Add("iznos");
                DTpdvN.Columns.Add("nacin");
                DTpdvN.Columns.Add("osnovica");
            }
            else
            {
                DTpdvN.Clear();
            }

            //if (DTosnovica.Columns["osnovica"] == null)
            //{
            //    DTosnovica.Columns.Add("osnovica");
            //    DTosnovica.Columns.Add("nacin");
            //}
            //else
            //{
            //    DTosnovica.Clear();
            //}

            decimal UG    = 0;
            decimal UK    = 0;
            decimal UV    = 0;
            decimal rabat = 0;

            foreach (DataRow row in DT.Rows)
            {
                kol = Convert.ToDecimal(row["kolicina"].ToString());
                mpc = Convert.ToDecimal(row["mpc"].ToString());
                pnp = Convert.ToDecimal(row["porez_potrosnja"].ToString());
                pdv = Convert.ToDecimal(row["porez"].ToString());

                rabat        = Convert.ToDecimal(row["rabat"].ToString());
                ukupno_rabat = (mpc * rabat / 100) + ukupno_rabat;
                mpc          = mpc - (mpc * rabat / 100);

                //Ovaj kod dobiva PDV
                decimal PreracunataStopaPDV = Convert.ToDecimal((100 * pdv) / (100 + pdv + pnp));
                decimal ppdv = (((mpc * kol) * PreracunataStopaPDV) / 100);
                pdvUKUPNO = ppdv + pdvUKUPNO;

                //Ovaj kod dobiva porez na potrošnju
                decimal PreracunataStopaPorezNaPotrosnju = Convert.ToDecimal((100 * pnp) / (100 + pdv + pnp));
                decimal ppnp = (((mpc * kol) * PreracunataStopaPorezNaPotrosnju) / 100);
                pnpUKUPNO = ppnp + pnpUKUPNO;

                SVE_UKUPNO = (mpc * kol) + SVE_UKUPNO;

                if (row["nacin_placanja"].ToString() == "G")
                {
                    StopePDVaN(pdv, ppdv, "G", ((mpc * kol) - ((ppdv) + (ppnp))));
                    UG = (mpc * kol) + UG;
                }
                else if (row["nacin_placanja"].ToString() == "K")
                {
                    StopePDVaN(pdv, ppdv, "K", ((mpc * kol) - ((ppdv) + (ppnp))));
                    UK = (mpc * kol) + UK;
                }
                else if (row["nacin_placanja"].ToString() == "T")
                {
                    StopePDVaN(pdv, ppdv, "T", ((mpc * kol) - ((ppdv) + (ppnp))));
                    UV = (mpc * kol) + UV;
                }

                string ajjj = row["nacin_placanja"].ToString();
                Artikli(row["naziv"].ToString(), kol, row["sifra_robe"].ToString(), mpc, row["jm"].ToString(), ppnp, ppdv);
                StopePDVa(pdv, ((mpc * kol) * PreracunataStopaPDV) / 100);

                OSNOVICA = ((mpc * kol) - ((ppdv) + (ppnp))) + OSNOVICA;
            }

            //////////////////////////////////////////////////////////////////////////////////////////////////////////////////

            string year = "";

            string s = "";

            if (skladiste != null)
            {
                s = "\r\nSkladište: " + skladiste;
            }

            string b = "";

            if (blagajnik != null)
            {
                b = "\r\nBlagajnik: " + blagajnik;
            }

            string a = "";

            if (artikl != null)
            {
                a = "\r\nArtikl: " + artikl;
            }
            string pdv_ispis = "";

            for (int p = 0; p < DTpdv.Rows.Count; p++)
            {
                pdv_ispis += "PDV " + DTpdv.Rows[p]["stopa"].ToString() + "%: " + Convert.ToDecimal(DTpdv.Rows[p]["iznos"].ToString()).ToString("#0.000") + "\r\n";
            }

            string stope = "";

            if (ukupno_rabat > 0)
            {
                stope += "\r\n\r\nUKUPNO RABAT:     " + ukupno_rabat.ToString("#0.00") + "\r\n";
            }
            stope += "PNP ukupno:       " + pnpUKUPNO.ToString("#0.000") + "\r\n";

            //for(int i=0; i<DTpdv.Rows.Count; i++)
            //{
            //    PrintTextLine("PDV " + DTpdv.Rows[i]["stopa"].ToString() + "%: " + Convert.ToDecimal(DTpdv.Rows[i]["iznos"].ToString()).ToString("#0.00"));
            //}

            //GOTOVINA
            if (UG > 0)
            {
                stope += "UKUPNO GOTOVINA:  " + UG.ToString("#0.000") + "\r\n";
                //for (int i = 0; i < DTosnovica.Rows.Count; i++)
                //{
                //    if (DTosnovica.Rows[i]["nacin"].ToString() == "G")
                //        PrintTextLine("OSNOVICA: " + Convert.ToDecimal(DTosnovica.Rows[i]["osnovica"].ToString()).ToString("#0.00"));
                //}
                for (int i = 0; i < DTpdvN.Rows.Count; i++)
                {
                    if (DTpdvN.Rows[i]["nacin"].ToString() == "G")
                    {
                        stope += "OSNOVICA PDV " + DTpdvN.Rows[i]["stopa"].ToString() + "%: " + Convert.ToDecimal(DTpdvN.Rows[i]["osnovica"].ToString()).ToString("#0.000") + "\r\n";
                        stope += "PDV " + DTpdvN.Rows[i]["stopa"].ToString() + "%:          " + Convert.ToDecimal(DTpdvN.Rows[i]["iznos"].ToString()).ToString("#0.000") + "\r\n";
                    }
                }
            }

            //KARTICA
            if (UK > 0)
            {
                stope += "UKUPNO KARTICE:   " + UK.ToString("#0.000") + "\r\n";
                //for (int i = 0; i < DTosnovica.Rows.Count; i++)
                //{
                //    if (DTosnovica.Rows[i]["nacin"].ToString() == "K")
                //        PrintTextLine("OSNOVICA: " + Convert.ToDecimal(DTosnovica.Rows[i]["osnovica"].ToString()).ToString("#0.00"));
                //}
                for (int i = 0; i < DTpdvN.Rows.Count; i++)
                {
                    if (DTpdvN.Rows[i]["nacin"].ToString() == "K")
                    {
                        stope += "OSNOVICA PDV " + DTpdvN.Rows[i]["stopa"].ToString() + "%: " + Convert.ToDecimal(DTpdvN.Rows[i]["osnovica"].ToString()).ToString("#0.000") + "\r\n";
                        stope += "PDV " + DTpdvN.Rows[i]["stopa"].ToString() + "%:          " + Convert.ToDecimal(DTpdvN.Rows[i]["iznos"].ToString()).ToString("#0.000") + "\r\n";
                    }
                }
            }

            //VIRMAN
            if (UV > 0)
            {
                stope += "UKUPNO VIRMAN:    " + UV.ToString("#0.000") + "\r\n";
                //for (int i = 0; i < DTosnovica.Rows.Count; i++)
                //{
                //    if (DTosnovica.Rows[i]["nacin"].ToString() == "T")
                //        PrintTextLine("OSNOVICA: " + Convert.ToDecimal(DTosnovica.Rows[i]["osnovica"].ToString()).ToString("#0.00"));
                //}
                for (int i = 0; i < DTpdvN.Rows.Count; i++)
                {
                    if (DTpdvN.Rows[i]["nacin"].ToString() == "T")
                    {
                        stope += "OSNOVICA PDV " + DTpdvN.Rows[i]["stopa"].ToString() + "%: " + Convert.ToDecimal(DTpdvN.Rows[i]["osnovica"].ToString()).ToString("#0.000") + "\r\n";
                        stope += "PDV " + DTpdvN.Rows[i]["stopa"].ToString() + "%:          " + Convert.ToDecimal(DTpdvN.Rows[i]["iznos"].ToString()).ToString("#0.000") + "\r\n";
                    }
                }
            }

            stope += "OSNOVICA UKUPNO:  " + OSNOVICA.ToString("#0.00") + "\r\n";
            for (int i = 0; i < DTpdv.Rows.Count; i++)
            {
                stope += "PDV " + DTpdv.Rows[i]["stopa"].ToString() + "% UKUPNO:   " + Convert.ToDecimal(DTpdv.Rows[i]["iznos"].ToString()).ToString("#0.00") + "\r\n";
            }
            stope += "SVE UKUPNO:       " + SVE_UKUPNO.ToString("#0.00") + "\r\n";

            //string odabrano "OD DATUMA: "+datumOD.ToString()+"DO DATUM:"+datumDO.ToString();

            string sql_liste_string = "SELECT " +
                                      " 'Šifra' AS tbl1," +
                                      " 'Naziv' AS tbl2," +
                                      " 'JMJ' AS tbl3," +
                                      " 'PNP iznos' AS tbl4," +
                                      " 'PDV iznos' AS tbl5," +
                                      " 'Količina' AS tbl6," +
                                      " 'Od datuma:" + datumOD.ToString("dd.MM.yyyy") + " - " + datumDO.ToString("dd.MM.yyyy") + "' AS skladiste," +
                                      " 'Ukupno porez%' AS tbl7," +
                                      " 'MPC' AS tbl8," +
                                      " 'ne' AS string6," +
                                      " '" + stope + "' AS komentar," +
                                      " '" + s + "' AS skladiste," +
                                      " '" + DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + "' AS datum1," +
                                      " CAST ('Promet po robi ' AS nvarchar) AS naslov," +
                                      " '\r\nOd datuma:" + datumOD.ToString("dd.MM.yyyy") + " - " + datumDO.ToString("dd.MM.yyyy") + s + b + a + "' AS komentar" +
                                      "";

            if (classSQL.remoteConnectionString == "")
            {
                classSQL.CeAdatpter(sql_liste_string).Fill(dSRlisteTekst, "DTlisteTekst");
            }
            else
            {
                classSQL.NpgAdatpter(sql_liste_string.Replace("nvarchar", "varchar")).Fill(dSRlisteTekst, "DTlisteTekst");
            }
        }
Ejemplo n.º 3
0
        private void PrometProdajneRobe()
        {
            string duc = "";

            if (ducan != null)
            {
                duc = " AND racuni.id_ducan='" + ducan + "'";
            }

            string blag = "";

            if (blagajnik != null)
            {
                blag = " AND racuni.id_blagajnik='" + blagajnik + "'";
                p3   = new ReportParameter("blagajnik", GetZaposlenikName());
            }
            else
            {
                p3 = new ReportParameter("blagajnik", "");
            }

            string art = "";

            if (artikl != null)
            {
                art = " AND racun_stavke.sifra_robe='" + artikl + "'";
            }

            string gr = "";

            if (grupa != null)
            {
                gr = " AND grupa.id_grupa='" + grupa + "'";
            }

            string sql = string.Format(@"SELECT
                racun_stavke.kolicina,
                grupa.grupa,
                racun_stavke.sifra_robe,
                racun_stavke.mpc,
                racun_stavke.porez_potrosnja,
                racun_stavke.porez,
                racuni.nacin_placanja,
                racuni.datum_racuna,
                roba.naziv
                FROM racun_stavke
                LEFT JOIN racuni ON racuni.broj_racuna=racun_stavke.broj_racuna AND racuni.id_ducan=racun_stavke.id_ducan AND racuni.id_kasa=racun_stavke.id_blagajna
                LEFT JOIN roba ON roba.sifra=racun_stavke.sifra_robe
                LEFT JOIN grupa ON grupa.id_grupa=roba.id_grupa
                WHERE  racuni.datum_racuna >= '{0}' AND racuni.datum_racuna <= '{1}'
                {2}{3}{4}{5}
                ORDER BY racuni.datum_racuna ASC;",
                                       datumOD.ToString("yyyy-MM-dd H:mm:ss"),
                                       datumDO.ToString("yyyy-MM-dd H:mm:ss"),
                                       blag, duc, art, gr);
            DataTable DT = classSQL.select(sql, "racun_stavke").Tables[0];

            sql = @"SELECT '' AS string1,CAST(racuni.datum_racuna AS DATE) as datum,
                CAST(REPLACE(racun_stavke.porez,',','.') AS DECIMAL) as stopa,CAST(REPLACE(racun_stavke.porez_potrosnja,',','.') AS DECIMAL) as stopa_pnp,
                ROUND(SUM(
	                ((CAST(racun_stavke.mpc AS DECIMAL)-
	                ((CAST(racun_stavke.mpc AS DECIMAL)*
	                CAST(REPLACE(racun_stavke.rabat,',','.') AS DECIMAL)/100)))/
	                (1zbroj((CAST(REPLACE(racun_stavke.porez,',','.') AS DECIMAL)zbrojCAST(REPLACE(racun_stavke.porez_potrosnja,',','.') AS DECIMAL))/100)))*CAST(REPLACE(racun_stavke.kolicina,',','.') AS DECIMAL)
                ),4) AS osnovica,
                ROUND(SUM(
	                ((CAST(racun_stavke.mpc AS DECIMAL)-
	                ((CAST(racun_stavke.mpc AS DECIMAL)*
	                CAST(REPLACE(racun_stavke.rabat,',','.') AS DECIMAL)/100)))*CAST(REPLACE(racun_stavke.kolicina,',','.') AS DECIMAL))*
	                ((100*CAST(REPLACE(racun_stavke.porez,',','.') AS DECIMAL))/(100zbrojCAST(REPLACE(racun_stavke.porez,',','.') AS DECIMAL)zbrojCAST(REPLACE(racun_stavke.porez_potrosnja,',','.') AS DECIMAL)))/100
                ),4) AS decimal1,
                ROUND(SUM(
	                ((CAST(racun_stavke.mpc AS DECIMAL)-
	                ((CAST(racun_stavke.mpc AS DECIMAL)*
	                CAST(REPLACE(racun_stavke.rabat,',','.') AS DECIMAL)/100)))*CAST(REPLACE(racun_stavke.kolicina,',','.') AS DECIMAL))*
	                ((100*CAST(REPLACE(racun_stavke.porez_potrosnja,',','.') AS DECIMAL))/(100zbrojCAST(REPLACE(racun_stavke.porez,',','.') AS DECIMAL)zbrojCAST(REPLACE(racun_stavke.porez_potrosnja,',','.') AS DECIMAL)))/100
                ),4) AS decimal2,
                ROUND(SUM(
	                (CAST(racun_stavke.mpc AS DECIMAL)-
	                ((CAST(racun_stavke.mpc AS DECIMAL)*
	                CAST(REPLACE(racun_stavke.rabat,',','.') AS DECIMAL)/100)))*CAST(REPLACE(racun_stavke.kolicina,',','.') AS DECIMAL)
                ),4) AS iznos
                FROM racun_stavke
                LEFT JOIN racuni ON racuni.broj_racuna=racun_stavke.broj_racuna AND racuni.id_ducan=racun_stavke.id_ducan AND racuni.id_kasa=racun_stavke.id_blagajna
                LEFT JOIN roba ON roba.sifra=racun_stavke.sifra_robe
                LEFT JOIN grupa ON grupa.id_grupa=roba.id_grupa
                WHERE  racuni.datum_racuna >= '" + datumOD.ToString("yyyy-MM-dd H:mm:ss") + "' AND racuni.datum_racuna <= '" + datumDO.ToString("yyyy-MM-dd H:mm:ss") + "' " + blag + duc + art + gr +
                  " GROUP BY CAST(REPLACE(racun_stavke.porez,',','.') AS DECIMAL),CAST(REPLACE(racun_stavke.porez_potrosnja,',','.') AS DECIMAL),CAST(racuni.datum_racuna AS DATE) ORDER BY datum";

            classSQL.NpgAdatpter(sql).Fill(dSstope, "DTstope");

            int     __pnp, __pdv;
            decimal __Dpnp, __Dpdv;

            foreach (DataRow r in dSstope.Tables[0].Rows)
            {
                decimal.TryParse(r["stopa_pnp"].ToString(), out __Dpnp);
                decimal.TryParse(r["stopa"].ToString(), out __Dpdv);

                __pnp = Convert.ToInt16(__Dpnp);
                __pdv = Convert.ToInt16(__Dpdv);

                if (__pnp > 0)
                {
                    r["string1"] = "Porez " + __pdv.ToString() + "+" + __pnp.ToString() + "%";
                }
                else
                {
                    r["string1"] = "Porez " + __pdv.ToString() + "%";
                }
            }

            decimal kol        = 0;
            decimal pnp        = 0;
            decimal pdv        = 0;
            decimal mpc        = 0;
            decimal pnpUKUPNO  = 0;
            decimal pdvUKUPNO  = 0;
            decimal SVE_UKUPNO = 0;
            decimal OSNOVICA   = 0;
            string  g          = "";

            if (DTpdv.Columns["stopa"] == null)
            {
                DTpdv.Columns.Add("stopa");
                DTpdv.Columns.Add("iznos");
            }

            if (DTartikli.Columns["sifra"] == null)
            {
                DTartikli.Columns.Add("sifra");
                DTartikli.Columns.Add("kolicina");
                DTartikli.Columns.Add("mpc");
                DTartikli.Columns.Add("naziv");
            }

            if (DTpdvN.Columns["stopa"] == null)
            {
                DTpdvN.Columns.Add("stopa");
                DTpdvN.Columns.Add("iznos");
                DTpdvN.Columns.Add("nacin");
                DTpdvN.Columns.Add("osnovica");
            }
            else
            {
                DTpdvN.Clear();
            }

            int oo = DT.Rows.Count;

            foreach (DataRow row in DT.Rows)
            {
                kol = Convert.ToDecimal(row["kolicina"].ToString());
                mpc = Convert.ToDecimal(row["mpc"].ToString());
                pnp = Convert.ToDecimal(row["porez_potrosnja"].ToString());
                pdv = Convert.ToDecimal(row["porez"].ToString());

                //Ovaj kod dobiva PDV
                decimal PreracunataStopaPDV = Convert.ToDecimal((100 * pdv) / (100 + pdv + pnp));
                decimal ppdv = Math.Round((((mpc * kol) * PreracunataStopaPDV) / 100), 4);
                pdvUKUPNO = Math.Round((ppdv + pdvUKUPNO), 4);

                //Ovaj kod dobiva porez na potrošnju
                decimal PreracunataStopaPorezNaPotrosnju = Convert.ToDecimal((100 * pnp) / (100 + pdv + pnp));
                decimal ppnp = Math.Round((((mpc * kol) * PreracunataStopaPorezNaPotrosnju) / 100), 4);
                pnpUKUPNO = Math.Round((ppnp + pnpUKUPNO), 4);

                SVE_UKUPNO = Math.Round(((mpc * kol) + SVE_UKUPNO), 4);

                decimal UG = 0;
                decimal UK = 0;
                decimal UV = 0;
                decimal UO = 0;

                if (row["nacin_placanja"].ToString() == "G" || row["nacin_placanja"].ToString() == "")
                {
                    StopePDVaN(pdv, ppdv, "G", Math.Round(((mpc * kol) - ((ppdv) + (ppnp))), 4));
                    UG = Math.Round((mpc * kol), 4);
                }
                else if (row["nacin_placanja"].ToString() == "K")
                {
                    StopePDVaN(pdv, ppdv, "K", Math.Round(((mpc * kol) - ((ppdv) + (ppnp))), 4));
                    UK = Math.Round((mpc * kol), 4);
                }
                else if (row["nacin_placanja"].ToString() == "T")
                {
                    StopePDVaN(pdv, ppdv, "T", Math.Round(((mpc * kol) - ((ppdv) + (ppnp))), 4));
                    UV = Math.Round((mpc * kol), 4);
                }
                else if (row["nacin_placanja"].ToString() == "O")
                {
                    StopePDVaN(pdv, ppdv, "O", Math.Round(((mpc * kol) - ((ppdv) + (ppnp))), 4));
                    UO = Math.Round((mpc * kol), 4);
                }

                string ajjj = row["nacin_placanja"].ToString();

                DateTime d = Convert.ToDateTime(row["datum_racuna"].ToString());
                decimal  o = Math.Round(((mpc * kol) - ((ppdv) + (ppnp))), 4);
                decimal  p = Math.Round((((mpc * kol) * PreracunataStopaPDV) / 100), 4);

                Artikli(d.ToString("dd.MM.yyyy"), o, p, ppnp, mpc * kol, UG, UK, UV, UO);

                StopePDVa(pdv, Math.Round((((mpc * kol) * PreracunataStopaPDV) / 100), 4));

                OSNOVICA = Math.Round(((mpc * kol) - ((ppdv) + (ppnp))), 4) + OSNOVICA;
            }

            string porezi = "";

            for (int i = 0; i < DTpdvN.Rows.Count; i++)
            {
                //if (Convert.ToDecimal(DTpdvN.Rows[i]["stopa"].ToString()) > 0)
                {
                    string nacin_pplacanja = "";

                    if (DTpdvN.Rows[i]["nacin"].ToString().ToUpper() == "G")
                    {
                        nacin_pplacanja = "GOTOVINA: ";
                    }
                    else if (DTpdvN.Rows[i]["nacin"].ToString().ToUpper() == "T")
                    {
                        nacin_pplacanja = "TRANSAKCIJSKI RAČUN: ";
                    }
                    else if (DTpdvN.Rows[i]["nacin"].ToString().ToUpper() == "O")
                    {
                        nacin_pplacanja = "OSTALO: ";
                    }
                    else if (DTpdvN.Rows[i]["nacin"].ToString().ToUpper() == "K")
                    {
                        nacin_pplacanja = "KARTICE: ";
                    }

                    porezi += "Način plačanja: " + nacin_pplacanja +
                              "\r\nOsnovica za stopu od " + DTpdvN.Rows[i]["stopa"].ToString() + " %: " + Math.Round(Convert.ToDecimal(DTpdvN.Rows[i]["osnovica"].ToString()), 3).ToString("#0.00") + "" +
                              "\r\nIznos poreza za stopu od " + DTpdvN.Rows[i]["stopa"].ToString() + " %: " + Math.Round(Convert.ToDecimal(DTpdvN.Rows[i]["iznos"].ToString()), 3).ToString("#0.00") +
                              "\r\n\r\n";
                }
            }

            p1 = new ReportParameter("datum", "Od datuma: " + datumOD.ToString("dd.MM.yyyy") + " do datuma " + datumDO.ToString("dd.MM.yyyy"));
            p2 = new ReportParameter("stope_poreza", porezi);
            this.reportViewer1.LocalReport.EnableExternalImages = true;
            this.reportViewer1.LocalReport.SetParameters(new ReportParameter[] { p1, p2, p3 });
        }
Ejemplo n.º 4
0
        private void PrometProdajneRobe()
        {
            string duc = "";

            if (ducan != null)
            {
                duc = " AND racuni.id_ducan='" + ducan + "'";
            }

            string kas = "";

            if (kasa != null)
            {
                kas = " AND racuni.id_kasa='" + kasa + "'";
            }

            string blag = "";

            if (blagajnik != null)
            {
                blag = " AND racuni.id_blagajnik='" + blagajnik + "'";
            }

            string art = "";

            if (artikl != null)
            {
                art = " AND racun_stavke.sifra_robe='" + artikl + "'";
            }

            string gr = "";

            if (grupa != null)
            {
                gr = " AND roba.id_grupa='" + grupa + "'";
            }

            string sql = "SELECT " +
                         " racun_stavke.kolicina," +
                         " grupa.grupa," +
                         " racun_stavke.sifra_robe," +
                         " racun_stavke.mpc," +
                         " racun_stavke.porez_potrosnja," +
                         " racun_stavke.porez," +
                         " racun_stavke.rabat," +
                         " racuni.nacin_placanja," +
                         " racuni.datum_racuna," +
                         " roba.naziv" +
                         " FROM racun_stavke" +
                         " LEFT JOIN racuni ON racuni.broj_racuna=racun_stavke.broj_racuna AND racuni.id_kasa=racun_stavke.id_kasa AND racuni.id_ducan=racun_stavke.id_ducan" +
                         " LEFT JOIN roba ON roba.sifra=racun_stavke.sifra_robe" +
                         " LEFT JOIN grupa ON grupa.id_grupa=roba.id_grupa" +
                         " WHERE  racuni.datum_racuna>'" + datumOD.ToString("yyyy-MM-dd H:mm:ss") + "' AND racuni.datum_racuna<'" + datumDO.ToString("yyyy-MM-dd H:mm:ss") + "'" +
                         " " + blag + duc + kas + art + gr + "  ORDER BY racuni.datum_racuna ASC";
            DataTable DT = classSQL.select(sql, "racun_stavke").Tables[0];

            decimal kol        = 0;
            decimal pnp        = 0;
            decimal pdv        = 0;
            decimal mpc        = 0;
            decimal rabat      = 0;
            decimal pnpUKUPNO  = 0;
            decimal pdvUKUPNO  = 0;
            decimal SVE_UKUPNO = 0;
            decimal OSNOVICA   = 0;
            string  g          = "";

            if (DTpdv.Columns["stopa"] == null)
            {
                DTpdv.Columns.Add("stopa");
                DTpdv.Columns.Add("iznos");
            }

            if (DTartikli.Columns["sifra"] == null)
            {
                DTartikli.Columns.Add("sifra");
                DTartikli.Columns.Add("kolicina");
                DTartikli.Columns.Add("mpc");
                DTartikli.Columns.Add("naziv");
            }

            if (DTpdvN.Columns["stopa"] == null)
            {
                DTpdvN.Columns.Add("stopa");
                DTpdvN.Columns.Add("iznos");
                DTpdvN.Columns.Add("nacin");
                DTpdvN.Columns.Add("osnovica");
            }
            else
            {
                DTpdvN.Clear();
            }

            int oo = DT.Rows.Count;

            foreach (DataRow row in DT.Rows)
            {
                kol   = Convert.ToDecimal(row["kolicina"].ToString());
                mpc   = Convert.ToDecimal(row["mpc"].ToString());
                pnp   = Convert.ToDecimal(row["porez_potrosnja"].ToString());
                pdv   = Convert.ToDecimal(row["porez"].ToString());
                rabat = Convert.ToDecimal(row["rabat"].ToString()) / 100;
                if (row["sifra_robe"].ToString() == "!popustABS")
                {
                    rabat = -1 * mpc;
                }
                else
                {
                    rabat  = mpc * rabat;
                    mpc   -= rabat;
                    rabat *= kol;
                }

                //Ovaj kod dobiva PDV
                decimal PreracunataStopaPDV = Convert.ToDecimal((100 * pdv) / (100 + pdv + pnp));
                decimal ppdv = (((mpc * kol) * PreracunataStopaPDV) / 100);
                pdvUKUPNO = ppdv + pdvUKUPNO;

                //Ovaj kod dobiva porez na potrošnju
                decimal PreracunataStopaPorezNaPotrosnju = Convert.ToDecimal((100 * pnp) / (100 + pdv + pnp));
                decimal ppnp = (((mpc * kol) * PreracunataStopaPorezNaPotrosnju) / 100);
                pnpUKUPNO = ppnp + pnpUKUPNO;

                SVE_UKUPNO = (mpc * kol) + SVE_UKUPNO;

                decimal UG = 0;
                decimal UK = 0;
                decimal UV = 0;
                decimal UO = 0;

                if (row["nacin_placanja"].ToString() == "G")
                {
                    StopePDVaN(pdv, ppdv, "G", ((mpc * kol) - ((ppdv) + (ppnp))));
                    UG = (mpc * kol);
                }
                else if (row["nacin_placanja"].ToString() == "K")
                {
                    StopePDVaN(pdv, ppdv, "K", ((mpc * kol) - ((ppdv) + (ppnp))));
                    UK = (mpc * kol);
                }
                else if (row["nacin_placanja"].ToString() == "T")
                {
                    StopePDVaN(pdv, ppdv, "T", ((mpc * kol) - ((ppdv) + (ppnp))));
                    UV = (mpc * kol);
                }
                else if (row["nacin_placanja"].ToString() == "O")
                {
                    StopePDVaN(pdv, ppdv, "O", ((mpc * kol) - ((ppdv) + (ppnp))));
                    UO = (mpc * kol);
                }

                string ajjj = row["nacin_placanja"].ToString();

                DateTime d = Convert.ToDateTime(row["datum_racuna"].ToString());
                decimal  o = ((mpc * kol) - ((ppdv) + (ppnp)));
                decimal  p = ((mpc * kol) * PreracunataStopaPDV) / 100;

                //TO DO: tu trebam napraviti kaj bu dobil min i max br rac
                string sOdDo = "select coalesce(min(racuni.broj_racuna::integer)::text || ' - ' || max(racuni.broj_racuna::integer)::text, '') as oddo FROM racun_stavke" +
                               " LEFT JOIN racuni ON racuni.broj_racuna=racun_stavke.broj_racuna AND racuni.id_kasa=racun_stavke.id_kasa AND racuni.id_ducan=racun_stavke.id_ducan" +
                               " LEFT JOIN roba ON roba.sifra=racun_stavke.sifra_robe" +
                               " LEFT JOIN grupa ON grupa.id_grupa=roba.id_grupa where cast(datum_racuna as date) = '" + d.ToString("yyyy-MM-dd") + "'" + blag + duc + kas + art + gr;
                DataSet dsOdDo = classSQL.select(sOdDo, "racuni");
                Artikli(d.ToString("dd.MM.yyyy"), dsOdDo.Tables[0].Rows[0][0].ToString(), o, p, ppnp, mpc * kol, UG, UK, UV, UO, rabat);

                StopePDVa(pdv, ((mpc * kol) * PreracunataStopaPDV) / 100);
                OSNOVICA = ((mpc * kol) - ((ppdv) + (ppnp))) + OSNOVICA;
            }

            string porezi = "";

            for (int i = 0; i < DTpdvN.Rows.Count; i++)
            {
                if (Convert.ToDecimal(DTpdvN.Rows[i]["stopa"].ToString()) > 0)
                {
                    string nacin_pplacanja = "";

                    if (DTpdvN.Rows[i]["nacin"].ToString().ToUpper() == "G")
                    {
                        nacin_pplacanja = "GOTOVINA: ";
                    }
                    else if (DTpdvN.Rows[i]["nacin"].ToString().ToUpper() == "T")
                    {
                        nacin_pplacanja = "TRANSAKCIJSKI RAČUN: ";
                    }
                    else if (DTpdvN.Rows[i]["nacin"].ToString().ToUpper() == "O")
                    {
                        nacin_pplacanja = "OSTALO: ";
                    }
                    else if (DTpdvN.Rows[i]["nacin"].ToString().ToUpper() == "K")
                    {
                        nacin_pplacanja = "KARTICE: ";
                    }

                    porezi += "Način plačanja: " + nacin_pplacanja +
                              "\r\nOsnovica " + DTpdvN.Rows[i]["stopa"].ToString() + " %: " + Math.Round(Convert.ToDecimal(DTpdvN.Rows[i]["osnovica"].ToString()), 3).ToString("#0.00") + "" +
                              "\r\nIznos " + Math.Round(Convert.ToDecimal(DTpdvN.Rows[i]["iznos"].ToString()), 3).ToString("#0.00") +
                              "\r\n\r\n";
                }
            }

            p1 = new ReportParameter("datum", "Od datuma: " + datumOD.ToString("dd.MM.yyyy") + " do datuma " + datumDO.ToString("dd.MM.yyyy"));
            p2 = new ReportParameter("stope_poreza", porezi);
            this.reportViewer1.LocalReport.EnableExternalImages = true;
            this.reportViewer1.LocalReport.SetParameters(new ReportParameter[] { p1, p2 });
        }
Ejemplo n.º 5
0
        private void PrometProdajneRobe()
        {
            promjenaCijene();
            string duc = "";

            if (ducan != null)
            {
                duc = " AND racuni.id_ducan='" + ducan + "'";
            }

            string kas = "";

            if (kasa != null)
            {
                kas = " AND racuni.id_kasa='" + kasa + "'";
            }

            string blag = "";

            if (blagajnik != null)
            {
                blag = " AND racuni.id_blagajnik='" + blagajnik + "'";
            }

            string art = "";

            if (artikl != null)
            {
                art = " AND racun_stavke.sifra_robe='" + artikl + "'";
            }

            string gr = "";

            if (grupa != null)
            {
                gr = " AND grupa.id_grupa='" + grupa + "'";
            }

            string sql = "SELECT " +
                         " racun_stavke.kolicina," +
                         " grupa.grupa," +
                         " racun_stavke.sifra_robe," +
                         " racun_stavke.mpc," +
                         " racun_stavke.porez_potrosnja," +
                         " racun_stavke.porez," +
                         " racun_stavke.rabat," +
                         " racuni.nacin_placanja," +
                         " racuni.datum_racuna," +
                         " roba.naziv" +
                         " FROM racun_stavke" +
                         " LEFT JOIN racuni ON racuni.broj_racuna=racun_stavke.broj_racuna AND racuni.id_kasa=racun_stavke.id_kasa AND racuni.id_ducan=racun_stavke.id_ducan" +
                         " LEFT JOIN roba ON roba.sifra=racun_stavke.sifra_robe" +
                         " LEFT JOIN grupa ON grupa.id_grupa=roba.id_grupa" +
                         " WHERE  racuni.datum_racuna>'" + datumOD.ToString("yyyy-MM-dd H:mm:ss") + "' AND racuni.datum_racuna<'" + datumDO.ToString("yyyy-MM-dd H:mm:ss") + "'" +
                         " " + blag + duc + kas + art + gr + "  ORDER BY racuni.datum_racuna ASC";
            DataTable DT = classSQL.select(sql, "racun_stavke").Tables[0];

            decimal kol        = 0;
            decimal pnp        = 0;
            decimal pdv        = 0;
            decimal mpc        = 0;
            decimal rabat      = 0;
            decimal pnpUKUPNO  = 0;
            decimal pdvUKUPNO  = 0;
            decimal SVE_UKUPNO = 0;
            decimal OSNOVICA   = 0;
            string  g          = "";

            if (DTpdv.Columns["stopa"] == null)
            {
                DTpdv.Columns.Add("stopa");
                DTpdv.Columns.Add("iznos");
            }

            if (DTartikli.Columns["sifra"] == null)
            {
                DTartikli.Columns.Add("sifra");
                DTartikli.Columns.Add("kolicina");
                DTartikli.Columns.Add("mpc");
                DTartikli.Columns.Add("naziv");
            }

            if (DTpdvN.Columns["stopa"] == null)
            {
                DTpdvN.Columns.Add("stopa");
                DTpdvN.Columns.Add("iznos");
                DTpdvN.Columns.Add("nacin");
                DTpdvN.Columns.Add("osnovica");
            }
            else
            {
                DTpdvN.Clear();
            }

            int oo = DT.Rows.Count;

            foreach (DataRow row in DT.Rows)
            {
                kol   = Convert.ToDecimal(row["kolicina"].ToString());
                mpc   = Convert.ToDecimal(row["mpc"].ToString());
                pnp   = Convert.ToDecimal(row["porez_potrosnja"].ToString());
                pdv   = Convert.ToDecimal(row["porez"].ToString());
                rabat = Convert.ToDecimal(row["rabat"].ToString()) / 100;
                if (row["sifra_robe"].ToString() == "!popustABS")
                {
                    rabat = -1 * mpc;
                }
                else
                {
                    rabat = mpc * rabat; mpc -= rabat; rabat *= kol;
                }

                //Ovaj kod dobiva PDV
                decimal PreracunataStopaPDV = Convert.ToDecimal((100 * pdv) / (100 + pdv + pnp));
                decimal ppdv = (((mpc * kol) * PreracunataStopaPDV) / 100);
                pdvUKUPNO = ppdv + pdvUKUPNO;

                //Ovaj kod dobiva porez na potrošnju
                decimal PreracunataStopaPorezNaPotrosnju = Convert.ToDecimal((100 * pnp) / (100 + pdv + pnp));
                decimal ppnp = (((mpc * kol) * PreracunataStopaPorezNaPotrosnju) / 100);
                pnpUKUPNO = ppnp + pnpUKUPNO;

                SVE_UKUPNO = (mpc * kol) + SVE_UKUPNO;

                decimal UG = 0;
                decimal UK = 0;
                decimal UV = 0;
                decimal UO = 0;

                if (row["nacin_placanja"].ToString() == "G")
                {
                    StopePDVaN(pdv, ppdv, "G", ((mpc * kol) - ((ppdv) + (ppnp))));
                    UG = (mpc * kol);
                }
                else if (row["nacin_placanja"].ToString() == "K")
                {
                    StopePDVaN(pdv, ppdv, "K", ((mpc * kol) - ((ppdv) + (ppnp))));
                    UK = (mpc * kol);
                }
                else if (row["nacin_placanja"].ToString() == "T")
                {
                    StopePDVaN(pdv, ppdv, "T", ((mpc * kol) - ((ppdv) + (ppnp))));
                    UV = (mpc * kol);
                }
                else if (row["nacin_placanja"].ToString() == "O")
                {
                    StopePDVaN(pdv, ppdv, "O", ((mpc * kol) - ((ppdv) + (ppnp))));
                    UO = (mpc * kol);
                }

                string ajjj = row["nacin_placanja"].ToString();

                DateTime d = Convert.ToDateTime(row["datum_racuna"].ToString());
                decimal  o = ((mpc * kol) - ((ppdv) + (ppnp)));
                decimal  p = ((mpc * kol) * PreracunataStopaPDV) / 100;

                Artikli(d.ToString("dd.MM.yyyy"), o, p, ppnp, mpc * kol, UG, UK, UV, UO, rabat);

                StopePDVa(pdv, ((mpc * kol) * PreracunataStopaPDV) / 100);

                OSNOVICA = ((mpc * kol) - ((ppdv) + (ppnp))) + OSNOVICA;
            }

            string porezi = "";

            for (int i = 0; i < DTpdvN.Rows.Count; i++)
            {
                if (Convert.ToDecimal(DTpdvN.Rows[i]["stopa"].ToString()) >= 0)
                {
                    string nacin_pplacanja = "";

                    if (DTpdvN.Rows[i]["nacin"].ToString().ToUpper() == "G")
                    {
                        nacin_pplacanja = "GOTOVINA: ";
                    }
                    else if (DTpdvN.Rows[i]["nacin"].ToString().ToUpper() == "T")
                    {
                        nacin_pplacanja = "TRANSAKCIJSKI RAČUN: ";
                    }
                    else if (DTpdvN.Rows[i]["nacin"].ToString().ToUpper() == "O")
                    {
                        nacin_pplacanja = "OSTALO: ";
                    }
                    else if (DTpdvN.Rows[i]["nacin"].ToString().ToUpper() == "K")
                    {
                        nacin_pplacanja = "KARTICE: ";
                    }

                    porezi += "Način plačanja: " + nacin_pplacanja +
                              "\r\nOsnovica " + DTpdvN.Rows[i]["stopa"].ToString() + " %: " + Math.Round(Convert.ToDecimal(DTpdvN.Rows[i]["osnovica"].ToString()), 3).ToString("#0.00") + "" +
                              "\r\nIznos " + Math.Round(Convert.ToDecimal(DTpdvN.Rows[i]["iznos"].ToString()), 3).ToString("#0.00") +
                              "\r\n\r\n";
                }
            }

            foreach (DataRow row in dSRliste.Tables[0].Rows)
            {
                ttekst += "\r\n" + "Datum: " + row["sifra"].ToString() + "\r\n" +
                          "Osnovica: " + Math.Round(Convert.ToDecimal(row["cijena1"].ToString()), 2) + vrati_razmake(row["cijena1"].ToString(), 10) +
                          "PDV:           " + Math.Round(Convert.ToDecimal(row["cijena2"].ToString()), 2) + "\r\n" +
                          "Mpc:      " + Math.Round(Convert.ToDecimal(row["cijena5"].ToString()), 2) + vrati_razmake(row["cijena5"].ToString(), 10) +
                          "Gotovina:      " + Math.Round(Convert.ToDecimal(row["cijena6"].ToString()), 2) + "\r\n" +
                          "Kartice:  " + Math.Round(Convert.ToDecimal(row["cijena7"].ToString()), 2) + vrati_razmake(row["cijena7"].ToString(), 10) +
                          "Transakcijski: " + Math.Round(Convert.ToDecimal(row["cijena8"].ToString()), 2) + "\r\n" +
                          "Ostalo:   " + Math.Round(Convert.ToDecimal(row["cijena9"].ToString()), 2) + vrati_razmake(row["cijena9"].ToString(), 10) +
                          "Rabat:         " + Math.Round(Convert.ToDecimal(row["rabat1"].ToString()), 2) + "\r\n";
            }
            ttekst += "\r\n\r\n" + porezi;
            //rtb.Text = ttekst;
            //print(ttekst);
        }
Ejemplo n.º 6
0
        /// <summary>
        ///
        /// </summary>
        private void PrometProdajneRobe()
        {
            decimal popustArtikl5000 = 0;
            string  skl = "";

            if (podgrupa != null)
            {
                skl = " AND roba.id_podgrupa='" + podgrupa + "'";
            }

            string duc = "";

            if (ducan != null)
            {
                duc = " AND racuni.id_ducan='" + ducan + "'";
            }

            string blag = "";

            if (blagajnik != null)
            {
                blag = " AND racuni.id_blagajnik='" + blagajnik + "'";
            }

            string blagajnaUvijet = "";

            if (blagajna != null)
            {
                blagajnaUvijet = " AND racuni.id_kasa='" + blagajna + "'";
            }

            string art = "";

            if (artikl != null)
            {
                art = " AND racun_stavke.sifra_robe='" + artikl + "'";
            }

            string gr = "";

            if (grupa != null)
            {
                gr = " AND grupa.id_grupa='" + grupa + "'";
            }

            string query = $@"SELECT CAST(racun_stavke.broj_racuna AS int)
	                        ,roba.naziv 
	                        ,racun_stavke.kolicina
	                        ,racun_stavke.sifra_robe
	                        ,CAST(racun_stavke.mpc AS numeric)
	                        ,racun_stavke.porez_potrosnja
	                        ,racun_stavke.porez
	                        ,racun_stavke.rabat
	                        ,racuni.nacin_placanja
                        FROM racun_stavke 
                        LEFT JOIN racuni ON racuni.broj_racuna=racun_stavke.broj_racuna AND racuni.id_ducan=racun_stavke.id_ducan AND racuni.id_kasa=racun_stavke.id_blagajna AND racuni.godina=racun_stavke.godina 
                        LEFT JOIN roba ON roba.sifra=racun_stavke.sifra_robe 
                        LEFT JOIN grupa ON grupa.id_grupa=roba.id_grupa 
                        WHERE racuni.datum_racuna>'{datumOD.ToString("yyyy-MM-dd H:mm:ss")}' AND racuni.datum_racuna<'{datumDO.ToString("yyyy-MM-dd H:mm:ss")}' {skl + blag + duc + art + gr + blagajnaUvijet}
                        UNION ALL
                        SELECT faktura_stavke.broj_fakture
	                        ,roba.naziv 
	                        ,faktura_stavke.kolicina
	                        ,faktura_stavke.sifra AS sifra_robe
	                        ,CAST(faktura_stavke.mpc AS numeric)
	                        ,faktura_stavke.porez_potrosnja
	                        ,faktura_stavke.porez
	                        ,faktura_stavke.rabat
	                        ,'F' AS nacin_placanja
                        FROM faktura_stavke
                        LEFT JOIN fakture ON fakture.broj_fakture = faktura_stavke.broj_fakture
                        LEFT JOIN roba ON roba.sifra = faktura_stavke.sifra
                        LEFT JOIN grupa ON grupa.id_grupa = roba.id_grupa
                        WHERE fakture.date>'{datumOD.ToString("yyyy-MM-dd H:mm:ss")}' AND fakture.date<'{datumDO.ToString("yyyy-MM-dd H:mm:ss")}'
                        UNION ALL
                        SELECT otpremnica_stavke.broj_otpremnice
	                        ,roba.naziv 
	                        ,CAST(otpremnica_stavke.kolicina AS varchar)
	                        ,otpremnica_stavke.sifra_robe
	                        ,otpremnica_stavke.vpc AS mpc
	                        ,CAST(otpremnica_stavke.porez_potrosnja AS varchar)
	                        ,CAST(otpremnica_stavke.porez AS varchar)
	                        ,CAST(otpremnica_stavke.rabat AS varchar)
	                        ,'OT' AS nacin_placanja
                        FROM otpremnica_stavke
                        LEFT JOIN otpremnice ON otpremnice.broj_otpremnice = otpremnica_stavke.broj_otpremnice
                        LEFT JOIN roba ON roba.sifra = otpremnica_stavke.sifra_robe
                        LEFT JOIN grupa ON grupa.id_grupa = roba.id_grupa
                        WHERE otpremnice.datum>'{datumOD.ToString("yyyy-MM-dd H:mm:ss")}' AND otpremnice.datum<'{datumDO.ToString("yyyy-MM-dd H:mm:ss")}'";

            DataTable DTracuni = classSQL.select(query, "racun_stavke").Tables[0];

            string popustiQuery = "SELECT " +
                                  " count(*) as count," +
                                  " racun_stavke.broj_racuna" +
                                  " FROM racun_stavke" +
                                  " LEFT JOIN racuni ON racuni.broj_racuna=racun_stavke.broj_racuna AND racuni.id_ducan=racun_stavke.id_ducan AND racuni.id_kasa=racun_stavke.id_blagajna AND racuni.godina=racun_stavke.godina" +
                                  " LEFT JOIN roba ON roba.sifra=racun_stavke.sifra_robe" +
                                  " LEFT JOIN grupa ON grupa.id_grupa=roba.id_grupa" +
                                  " WHERE  racuni.datum_racuna>'" + datumOD.ToString("yyyy-MM-dd H:mm:ss") + "' AND racuni.datum_racuna<'" + datumDO.ToString("yyyy-MM-dd H:mm:ss") + "'" +
                                  " " + skl + blag + duc + art + gr + blagajnaUvijet + " GROUP BY racun_stavke.broj_racuna HAVING count(*) > 1";
            DataTable DTpopusti = classSQL.select(popustiQuery, "racun_stavke").Tables[0];

            decimal rabat      = 0;
            decimal kol        = 0;
            decimal pnp        = 0;
            decimal pdv        = 0;
            decimal mpc        = 0;
            decimal pnpUKUPNO  = 0;
            decimal pdvUKUPNO  = 0;
            decimal SVE_UKUPNO = 0;
            decimal OSNOVICA   = 0;
            string  g          = "";

            if (DTpdv.Columns["stopa"] == null)
            {
                DTpdv.Columns.Add("stopa");
                DTpdv.Columns.Add("iznos");
            }

            if (DTartikli.Columns["sifra"] == null)
            {
                DTartikli.Columns.Add("sifra");
                DTartikli.Columns.Add("kolicina");
                DTartikli.Columns.Add("mpc");
                DTartikli.Columns.Add("naziv");
            }

            if (DT_tvr.Rows[0]["skraceno_ime"].ToString().Contains(";"))
            {
                string[] adresas = DT_tvr.Rows[0]["skraceno_ime"].ToString().Split(';');

                foreach (string item in adresas)
                {
                    PrintTextLine(item);
                }
            }
            else
            {
                PrintTextLine(DT_tvr.Rows[0]["skraceno_ime"].ToString());
            }

            PrintTextLine("Telefon: " + DT_tvr.Rows[0]["tel"].ToString());
            PrintTextLine("Datum: " + DateTime.Now);
            PrintTextLine("OIB: " + DT_tvr.Rows[0]["oib"].ToString());
            PrintTextLine("OD: " + datumOD.ToString("dd.MM.yyyy H:mm:ss"));
            PrintTextLine("DO: " + datumDO.ToString("dd.MM.yyyy H:mm:ss"));
            PrintTextLine(new string('-', RecLineChars));

            if (DTpdvN.Columns["stopa"] == null)
            {
                DTpdvN.Columns.Add("stopa");
                DTpdvN.Columns.Add("iznos");
                DTpdvN.Columns.Add("nacin");
                DTpdvN.Columns.Add("osnovica");
            }
            else
            {
                DTpdvN.Clear();
            }

            // Ukupne vrijednosti
            decimal       UG      = 0;
            decimal       UGSP    = 0;
            decimal       UK      = 0;
            decimal       UKBP    = 0;
            decimal       UP      = 0;
            decimal       UKSP    = 0;
            decimal       UF      = 0;
            decimal       UOT     = 0;
            decimal       UV      = 0;
            decimal       UO      = 0;
            List <string> listaId = new List <string>();

            string[] oibZaPopust = new string[] { "67660751355", "99731647274", "38799206384" };

            foreach (DataRow row in DTpopusti.Rows)
            {
                listaId.Add(row["broj_racuna"].ToString());
            }

            foreach (DataRow row in DTracuni.Rows)
            {
                if (!oibZaPopust.Contains(Util.Korisno.oibTvrtke) || (oibZaPopust.Contains(Util.Korisno.oibTvrtke)))
                {
                    decimal.TryParse(row["kolicina"].ToString().Replace(',', '.'), NumberStyles.Any, CultureInfo.InvariantCulture, out kol);
                    decimal.TryParse(row["mpc"].ToString().Replace(',', '.'), NumberStyles.Any, CultureInfo.InvariantCulture, out mpc);
                    decimal.TryParse(row["porez_potrosnja"].ToString().Replace(',', '.'), NumberStyles.Any, CultureInfo.InvariantCulture, out pnp);
                    decimal.TryParse(row["porez"].ToString().Replace(',', '.'), NumberStyles.Any, CultureInfo.InvariantCulture, out pdv);
                    decimal.TryParse(row["rabat"].ToString().Replace(',', '.'), NumberStyles.Any, CultureInfo.InvariantCulture, out rabat);

                    if (row["nacin_placanja"].ToString() == "OT")
                    {
                        DataTable DTroba = Global.Database.GetRoba(row["sifra_robe"].ToString());
                        if (DTroba?.Rows.Count > 0)
                        {
                            decimal.TryParse(DTroba.Rows[0]["mpc"].ToString().Replace(',', '.'), NumberStyles.Any, CultureInfo.InvariantCulture, out mpc);
                        }
                    }

                    mpc          = mpc - (mpc * rabat / 100);
                    ukupno_rabat = ((mpc * rabat / 100) * kol) + ukupno_rabat;

                    //Ovaj kod dobiva PDV
                    decimal PreracunataStopaPDV = Convert.ToDecimal((100 * pdv) / (100 + pdv + pnp));
                    decimal ppdv = (((mpc * kol) * PreracunataStopaPDV) / 100);
                    pdvUKUPNO = ppdv + pdvUKUPNO;

                    //Ovaj kod dobiva porez na potrošnju
                    decimal PreracunataStopaPorezNaPotrosnju = Convert.ToDecimal((100 * pnp) / (100 + pdv + pnp));
                    decimal ppnp = (((mpc * kol) * PreracunataStopaPorezNaPotrosnju) / 100);
                    pnpUKUPNO = ppnp + pnpUKUPNO;

                    SVE_UKUPNO = (mpc * kol) + SVE_UKUPNO;

                    if (row["nacin_placanja"].ToString() == "G")
                    {
                        if (row["sifra_robe"].ToString() != "5000")
                        {
                            StopePDVaN(pdv, ppdv, "G", ((mpc * kol) - ((ppdv) + (ppnp))));
                            UG   = (mpc * kol) + UG;
                            UKBP = (mpc * kol) + UKBP;
                        }
                        else
                        {
                            UGSP = (mpc * kol) + UGSP;
                            UP   = (mpc * kol) + UP;
                        }
                    }
                    else if (row["nacin_placanja"].ToString() == "K")
                    {
                        if (row["sifra_robe"].ToString() != "5000")
                        {
                            StopePDVaN(pdv, ppdv, "K", ((mpc * kol) - ((ppdv) + (ppnp))));
                            UK   = (mpc * kol) + UK;
                            UKBP = (mpc * kol) + UKBP;
                        }
                        else
                        {
                            UKSP = (mpc * kol) + UKSP;
                            UP   = (mpc * kol) + UP;
                        }
                    }
                    else if (row["nacin_placanja"].ToString() == "F")
                    {
                        StopePDVaN(pdv, ppdv, "F", ((mpc * kol) - ((ppdv) + (ppnp))));
                        UF += (mpc * kol);
                    }
                    else if (row["nacin_placanja"].ToString() == "OT")
                    {
                        StopePDVaN(pdv, ppdv, "OT", ((mpc * kol) - ((ppdv) + (ppnp))));
                        UOT += (mpc * kol);
                    }
                    else if (row["nacin_placanja"].ToString() == "T")
                    {
                        StopePDVaN(pdv, ppdv, "T", ((mpc * kol) - ((ppdv) + (ppnp))));
                        UV = (mpc * kol) + UV;
                    }
                    else if (row["nacin_placanja"].ToString() == "O")
                    {
                        StopePDVaN(pdv, ppdv, "O", ((mpc * kol) - ((ppdv) + (ppnp))));
                        UO = (mpc * kol) + UO;
                    }

                    string ajjj = row["nacin_placanja"].ToString();

                    if (rabat > 0)
                    {
                        Artikli(row["naziv"].ToString(), kol, "R_" + row["sifra_robe"].ToString(), mpc.ToString());
                    }
                    else
                    {
                        Artikli(row["naziv"].ToString(), kol, row["sifra_robe"].ToString(), mpc.ToString());
                    }

                    StopePDVa(pdv, ((mpc * kol) * PreracunataStopaPDV) / 100);

                    OSNOVICA = ((mpc * kol) - ((ppdv) + (ppnp))) + OSNOVICA;
                }
                else
                {
                    decimal pa5000 = 0;
                    decimal ko5000 = 0;
                    if (decimal.TryParse(row["mpc"].ToString(), out pa5000) && decimal.TryParse(row["kolicina"].ToString(), out ko5000))
                    {
                        popustArtikl5000 += (pa5000 * ko5000);
                    }
                }
            }

            ukupno_rabat += (popustArtikl5000 < 0 ? (popustArtikl5000 * -1) : popustArtikl5000 * -1);

            int a = Convert.ToInt16(DTsetting.Rows[0]["ispred_artikl"].ToString()) - 2;
            int k = Convert.ToInt16(DTsetting.Rows[0]["ispred_kolicine"].ToString()) + 1;
            int c = Convert.ToInt16(DTsetting.Rows[0]["ispred_cijene"].ToString());
            int s = Convert.ToInt16(DTsetting.Rows[0]["ispred_ukupno"].ToString()) + 1;

            if (ispis_stavka)
            {
                PrintTextLine(String.Empty);
                PrintText(TruncateAt("STAVKA".PadRight(a), a));
                PrintText(TruncateAt("KOL".PadLeft(k), k));
                PrintText(TruncateAt("CIJENA".PadLeft(c), c));
                PrintText(TruncateAt("UKUPNO".PadLeft(s), s));
                PrintText("\r\n");
                PrintTextLine(new string('=', RecLineChars));

                if (DTartikli.Rows.Count > 0)
                {
                    DataView dv = DTartikli.DefaultView;
                    dv.Sort   = "naziv";
                    DTartikli = dv.ToTable();
                }

                for (int i = 0; i < DTartikli.Rows.Count; i++)
                {
                    if (!oibZaPopust.Contains(Util.Korisno.oibTvrtke) || (oibZaPopust.Contains(Util.Korisno.oibTvrtke) && DTartikli.Rows[i]["sifra"].ToString() != "5000"))
                    {
                        try
                        {
                            if (ispis_sifra)
                            {
                                string stavka = DTartikli.Rows[i]["sifra"].ToString() + "/" + DTartikli.Rows[i]["naziv"].ToString();
                                if (DTpostavke.Rows[0]["ispis_cijele_stavke"].ToString() != "1")
                                {
                                    PrintText(TruncateAt(stavka.PadRight(a), a));
                                }
                                else
                                {
                                    PrintTextLine(stavka.Length > 25 ? stavka.Substring(0, 25).TrimEnd() + "." : stavka);
                                    //tekst += classOstalo.SvavkaZaPrinter(stavka, a);
                                }
                            }
                            else
                            {
                                if (DTpostavke.Rows[0]["ispis_cijele_stavke"].ToString() != "1")
                                {
                                    PrintText(TruncateAt(DTartikli.Rows[i]["naziv"].ToString().PadRight(a), a));
                                }
                                else
                                {
                                    tekst += classOstalo.SvavkaZaPrinter(DTartikli.Rows[i]["naziv"].ToString(), a);
                                }
                            }
                        }
                        catch (Exception)
                        {
                            PrintText(TruncateAt(artikl.PadRight(a), a));
                        }

                        PrintText(TruncateAt(String.Empty.PadRight(a), a));
                        PrintText(TruncateAt(Convert.ToDecimal(DTartikli.Rows[i]["kolicina"].ToString()).ToString("#0.00").PadLeft(k), k));
                        PrintText(TruncateAt(Convert.ToDecimal(DTartikli.Rows[i]["mpc"].ToString()).ToString("#0.00").PadLeft(c), c));
                        PrintTextLine(TruncateAt((Convert.ToDecimal(DTartikli.Rows[i]["mpc"].ToString()) * Convert.ToDecimal(DTartikli.Rows[i]["kolicina"].ToString())).ToString("#0.00").PadLeft(s), s));
                    }
                }

                PrintTextLine("");
                PrintTextLine(new string('-', RecLineChars));
            }

            PrintTextLine("PNP ukupno:       " + pnpUKUPNO.ToString("#0.00"));

            // GOTOVINA
            if (UG > 0)
            {
                PrintTextLine(new string('-', RecLineChars));
                PrintTextLine("UKUPNO GOTOVINA:  " + UG.ToString("#0.00"));
                for (int i = 0; i < DTpdvN.Rows.Count; i++)
                {
                    if (DTpdvN.Rows[i]["nacin"].ToString() == "G")
                    {
                        PrintTextLine("OSNOVICA PDV " + DTpdvN.Rows[i]["stopa"].ToString() + "%: " + Convert.ToDecimal(DTpdvN.Rows[i]["osnovica"].ToString()).ToString("#0.00"));
                        PrintTextLine("PDV " + DTpdvN.Rows[i]["stopa"].ToString() + "%:          " + Convert.ToDecimal(DTpdvN.Rows[i]["iznos"].ToString()).ToString("#0.00"));
                    }
                }
            }

            // KARTICA
            if (UK > 0)
            {
                PrintTextLine(new string('-', RecLineChars));
                PrintTextLine("UKUPNO KARTICE:   " + UK.ToString("#0.00"));
                for (int i = 0; i < DTpdvN.Rows.Count; i++)
                {
                    if (DTpdvN.Rows[i]["nacin"].ToString() == "K")
                    {
                        PrintTextLine("OSNOVICA PDV " + DTpdvN.Rows[i]["stopa"].ToString() + "%: " + Convert.ToDecimal(DTpdvN.Rows[i]["osnovica"].ToString()).ToString("#0.00"));
                        PrintTextLine("PDV " + DTpdvN.Rows[i]["stopa"].ToString() + "%:          " + Convert.ToDecimal(DTpdvN.Rows[i]["iznos"].ToString()).ToString("#0.00"));

                        // TODO ispisati po karticama ako ih ima.

                        string sqlllol = string.Format(@"drop table if exists tempPoKarticama;
create temporary table tempPoKarticama as
select round(avg(karticaID)) as kartica, pdv as stopa, naziv, sum((mpc - (mpc*rabat/100)) * kolicina) as ukupno,
(sum((((mpc - (mpc * rabat / 100)) * kolicina) * ((100 * pdv) / (100 zbroj pdv zbroj pnp))) / 100)) as pdv,
(sum((((mpc - (mpc * rabat / 100)) * kolicina) * ((100 * pnp) / (100 zbroj pdv zbroj pnp))) / 100)) as pnp
from (
	select rs.sifra_robe as sifra, replace(rs.kolicina, ',','.')::numeric as kolicina, rs.mpc::numeric as mpc, replace(rs.porez_potrosnja, ',','.')::numeric as pnp, replace(rs.porez, ',','.')::numeric as pdv, replace(rs.rabat, ',','.')::numeric as rabat, r.nacin_placanja, r.karticaID, case when coalesce(k.naziv, '') = '' then 'Ostale kartice' else k.naziv end as naziv
	from racun_stavke rs
	left join racuni r on rs.broj_racuna = r.broj_racuna and rs.id_ducan = r.id_ducan and rs.id_blagajna = r.id_kasa
	left join kartice k on r.karticaID = k.id
    LEFT JOIN roba ro ON ro.sifra=rs.sifra_robe
	LEFT JOIN grupa g ON g.id_grupa=ro.id_grupa
	where r.datum_racuna between '"     + datumOD.ToString("yyyy-MM-dd H:mm:ss") + @".000000' and '" + datumDO.ToString("yyyy-MM-dd H:mm:ss") + @".999999'
" + skl.Replace("roba.", "ro.") + blag.Replace("racuni.", "r.") + duc.Replace("racuni.", "r.") + art.Replace("racun_stavke.", "rs.") + gr.Replace("grupa.", "g.") + blagajnaUvijet.Replace("racuni.", "r.") + @"
) prodano
where nacin_placanja = 'K'
group by naziv, pdv;

select *
from (
select *
from tempPoKarticama where kartica > 0
union
select *
from tempPoKarticama where kartica = 0
) x
where x.stopa = {0}", DTpdvN.Rows[i]["stopa"].ToString().Replace(',', '.'));

                        DataTable dtPoKarticama = classSQL.select(sqlllol, "racuni").Tables[0];
                        if (dtPoKarticama != null)
                        {
                            foreach (DataRow drRow in dtPoKarticama.Rows)
                            {
                                decimal osnovica = (Convert.ToDecimal(drRow["ukupno"].ToString()) - Convert.ToDecimal(drRow["pnp"].ToString()) - Convert.ToDecimal(drRow["pdv"].ToString()));
                                PrintTextLine("   " + drRow["naziv"]);
                                PrintTextLine("   OSNOVICA PDV " + Convert.ToDecimal(drRow["stopa"]).ToString("#0.00") + "%: " + osnovica.ToString("#0.00"));
                                PrintTextLine("   PDV " + Convert.ToDecimal(drRow["stopa"]).ToString("#0.00") + "%:          " + Convert.ToDecimal(drRow["pdv"].ToString()).ToString("#0.00"));
                            }
                        }
                    }
                }
            }

            // FAKTURE
            if (UF > 0)
            {
                PrintTextLine(new string('-', RecLineChars));
                PrintTextLine("UKUPNO FAKTURE:    " + UF.ToString("#0.00"));
                for (int i = 0; i < DTpdvN.Rows.Count; i++)
                {
                    if (DTpdvN.Rows[i]["nacin"].ToString() == "F")
                    {
                        PrintTextLine("OSNOVICA PDV " + DTpdvN.Rows[i]["stopa"].ToString() + "%: " + Convert.ToDecimal(DTpdvN.Rows[i]["osnovica"].ToString()).ToString("#0.00"));
                        PrintTextLine("PDV " + DTpdvN.Rows[i]["stopa"].ToString() + "%:          " + Convert.ToDecimal(DTpdvN.Rows[i]["iznos"].ToString()).ToString("#0.00"));
                    }
                }
            }

            // OTPREMNICE
            if (UOT > 0)
            {
                PrintTextLine(new string('-', RecLineChars));
                PrintTextLine("UKUPNO OTPREMNICE:    " + UOT.ToString("#0.00"));
                for (int i = 0; i < DTpdvN.Rows.Count; i++)
                {
                    if (DTpdvN.Rows[i]["nacin"].ToString() == "OT")
                    {
                        PrintTextLine("OSNOVICA PDV " + DTpdvN.Rows[i]["stopa"].ToString() + "%:     " + Convert.ToDecimal(DTpdvN.Rows[i]["osnovica"].ToString()).ToString("#0.00"));
                        PrintTextLine("PDV " + DTpdvN.Rows[i]["stopa"].ToString() + "%:              " + Convert.ToDecimal(DTpdvN.Rows[i]["iznos"].ToString()).ToString("#0.00"));
                    }
                }
            }

            // VIRMAN
            if (UV > 0)
            {
                PrintTextLine(new string('-', RecLineChars));
                PrintTextLine("UKUPNO VIRMAN:    " + UV.ToString("#0.00"));
                for (int i = 0; i < DTpdvN.Rows.Count; i++)
                {
                    if (DTpdvN.Rows[i]["nacin"].ToString() == "T")
                    {
                        PrintTextLine("OSNOVICA PDV " + DTpdvN.Rows[i]["stopa"].ToString() + "%: " + Convert.ToDecimal(DTpdvN.Rows[i]["osnovica"].ToString()).ToString("#0.00"));
                        PrintTextLine("PDV " + DTpdvN.Rows[i]["stopa"].ToString() + "%:          " + Convert.ToDecimal(DTpdvN.Rows[i]["iznos"].ToString()).ToString("#0.00"));
                    }
                }
            }

            // OSTALO
            if (UO > 0)
            {
                PrintTextLine(new string('-', RecLineChars));
                PrintTextLine("UKUPNO OSTALO" + (Class.PodaciTvrtka.oibTvrtke == "98816793336" ? " - FOODEX" : "") + ":    " + UO.ToString("#0.00"));

                for (int i = 0; i < DTpdvN.Rows.Count; i++)
                {
                    if (DTpdvN.Rows[i]["nacin"].ToString() == "O")
                    {
                        PrintTextLine("OSNOVICA PDV " + DTpdvN.Rows[i]["stopa"].ToString() + "%: " + Convert.ToDecimal(DTpdvN.Rows[i]["osnovica"].ToString()).ToString("#0.00"));
                        PrintTextLine("PDV " + DTpdvN.Rows[i]["stopa"].ToString() + "%:          " + Convert.ToDecimal(DTpdvN.Rows[i]["iznos"].ToString()).ToString("#0.00"));
                    }
                }
            }

            PrintTextLine(new string('-', RecLineChars));
            if (!oibZaPopust.Contains(Util.Korisno.oibTvrtke))
            {
                PrintTextLine("OSNOVICA UKUPNO:  " + OSNOVICA.ToString("#0.00"));
            }
            else
            {
                PrintTextLine("UKUPNO BEZ POPUSTA:  " + UKBP.ToString("#0.00"));
            }
            for (int i = 0; i < DTpdv.Rows.Count; i++)
            {
                PrintTextLine("PDV " + DTpdv.Rows[i]["stopa"].ToString() + "% UKUPNO:     " + Math.Truncate(Convert.ToDecimal(DTpdv.Rows[i]["iznos"].ToString()) * 100) / 100);
            }

            string    queryPopust = $@"";
            DataTable DTpopust    = classSQL.select(query, "racun_stavke").Tables[0];

            if (!oibZaPopust.Contains(Util.Korisno.oibTvrtke))
            {
                PrintTextLine("UKUPNO RABAT:     " + ukupno_rabat.ToString("#0.00"));
                PrintTextLine("SVE UKUPNO:       " + SVE_UKUPNO.ToString("#0.00"));
            }
            else
            {
                PrintTextLine("UKUPNO POPUST:      " + (UP * -1).ToString("#0.00"));
                if (UGSP < 0)
                {
                    decimal ukupnoGotovinaSaPopustom = UG + UGSP;
                    if (ukupnoGotovinaSaPopustom > 0)
                    {
                        PrintTextLine("UKUPNO GOTOVINA SA POPUSTOM:  " + ukupnoGotovinaSaPopustom.ToString("#0.00"));
                    }
                }
                if (UGSP < 0)
                {
                    decimal ukupnoKarticaSaPopustom = UK + UKSP;
                    if (ukupnoKarticaSaPopustom > 0)
                    {
                        PrintTextLine("UKUPNO KARTICA SA POPUSTOM: " + ukupnoKarticaSaPopustom.ToString("#0.00"));
                    }
                }
                PrintTextLine("UKUPNO S POPUSTOM:  " + (SVE_UKUPNO - ukupno_rabat).ToString("#0.00"));
            }

            System.Drawing.Text.PrivateFontCollection privateFonts = new PrivateFontCollection();
            privateFonts.AddFontFile("Slike/msgothic.ttc");
            System.Drawing.Font font = new Font(privateFonts.Families[0], 11);

            rtb.Font = font;
            rtb.Text = tekst;
        }