Пример #1
0
        private void bgWork_1_DoWork(object sender, DoWorkEventArgs e)
        {
            lblInfoPencarian.SafeControlInvoke(Label => lblInfoPencarian.Visible = true);
            lblInfoPencarian.SafeControlInvoke(Label => lblInfoPencarian.Text = "Proses Perhitungan Data");

            string strKode = "";
            string strNomor = "";
            string strHari = "";

            cmbKode.SafeControlInvoke(ComboBox => strKode =  cmbKode.Text);
            txtNomor.SafeControlInvoke(TextBox => strNomor = txtNomor.Text);
            txtHari.SafeControlInvoke(TextBox => strHari = txtHari.Text);

            if (strKode != "")
            {

                string strJudulNo = "NOMOR : " + strNomor + "/RET/RSU";
                string strJudulHr = "HARI  : " + strHari;

                if (strKode == "KELOMPOK TARIP")
                {

                    if (grpKelTarip.Count > 0)
                    {

                        foreach (var fetch in grpKelTarip)
                        {

                            lstTransak itemTransak = new lstTransak();
                            itemTransak.strUraian = fetch.strIdBl_KelTarip;
                            itemTransak.dblJSum = 0;
                            itemTransak.dblJPum = 0;
                            itemTransak.dblJaum = 0;
                            itemTransak.dblJSAsk = 0;
                            itemTransak.dblJPAsk = 0;
                            itemTransak.dblJAAsk = 0;
                            itemTransak.dblJSPav = 0;
                            itemTransak.dblJPPav = 0;
                            itemTransak.dblJAPav = 0;
                            grpTransak.Add(itemTransak);
                        }
                    }

                    /* UMUM */
                    if (grpKasum.Count > 0)
                    {
                        var Kasumum = (from x in grpKasum
                                       group x by new
                                       {
                                           x.strIdBl_KelTarip,
                                           x.strIdBl_Komponen,
                                           x.intLapUrut
                                       } into groupKasum
                                       select new
                                       {
                                           KelTarip = groupKasum.Key.strIdBl_KelTarip,
                                           Komponen = groupKasum.Key.strIdBl_Komponen,
                                           LapUrut = groupKasum.Key.intLapUrut,
                                           Tunainya = groupKasum.Sum(x => x.dblTunainya)
                                       }).ToList();

                        int intUrutan = 0;
                        foreach (var fetchTransak in grpTransak)
                        {
                            foreach (var fetchKasUmum in Kasumum)
                            {
                                if (fetchTransak.strUraian == fetchKasUmum.KelTarip)
                                {
                                    if (fetchKasUmum.LapUrut == 1)
                                        grpTransak[intUrutan].dblJSum = fetchKasUmum.Tunainya;
                                    else if (fetchKasUmum.LapUrut == 2)
                                        grpTransak[intUrutan].dblJPum = fetchKasUmum.Tunainya;
                                    else if (fetchKasUmum.LapUrut == 3)
                                        grpTransak[intUrutan].dblJaum = fetchKasUmum.Tunainya;
                                }
                            }
                            intUrutan++;
                        }
                    }

                    /* gak setor bu netty */
                    if (grpKasAskes.Count > 0)
                    {
                        var Kasaskes = (from x in grpKasAskes select x.dblTunai).Sum();
                        if (grpAdmAkses.Count > 0)
                        {
                            var AdmAskes = (from x in grpAdmAkses select x.dblJumlah).Sum();
                            int intUrut = 0;
                            foreach (var fetchTransak in grpTransak)
                            {
                                if (fetchTransak.strUraian == "IUR BEA ASKES")
                                    grpTransak[intUrut].dblJSum = Kasaskes - AdmAskes;

                                if (fetchTransak.strUraian == "JASA ADMINISTRASI")
                                    grpTransak[intUrut].dblJPum = grpTransak[intUrut].dblJPum + AdmAskes;
                                intUrut++;
                            }
                        }
                        else
                        {
                            int intUrut = 0;
                            foreach (var fetchTransak in grpTransak)
                            {
                                if (fetchTransak.strUraian == "IUR BEA ASKES")
                                    grpTransak[intUrut].dblJSum = Kasaskes;

                                intUrut++;
                            }
                        } /* EOF if (grpAdmAkses.Count > 0) */
                    } /* EOF if (grpKasAskes.Count > 0) */
                    else
                    {
                        int intUrut = 0;
                        foreach (var fetchTransak in grpTransak)
                        {
                            if (fetchTransak.strUraian == "IUR BEA ASKES")
                                grpTransak[intUrut].dblJSum = 0;

                            intUrut++;
                        }
                    } /* EOF  if (grpKasAskes.Count > 0) */

                    /* ASKES GAKIN */
                    if (grpKasAskin.Count > 0)
                    {

                        var Gakin = from x in grpKasAskin
                                    group x by new
                                    {
                                        x.strIdBl_KelTarip,
                                        x.strIdBl_Komponen,
                                        x.intLapUrut
                                    }
                                        into groupKasAskin
                                        select new
                                        {
                                            KelTarip = groupKasAskin.Key.strIdBl_KelTarip,
                                            Komponen = groupKasAskin.Key.strIdBl_Komponen,
                                            Lapurut = groupKasAskin.Key.intLapUrut,
                                            Tunainya = groupKasAskin.Sum(x => x.dblTunainya)
                                        };

                        int intNoUrut = 0;
                        foreach (var fetchTransak in grpTransak)
                        {
                            foreach (var fetchGakin in Gakin)
                            {
                                if (fetchTransak.strUraian == fetchGakin.KelTarip)
                                {
                                    if (fetchGakin.Lapurut == 1)
                                        grpTransak[intNoUrut].dblJSum = grpTransak[intNoUrut].dblJSum + fetchGakin.Tunainya;
                                    else if (fetchGakin.Lapurut == 2)
                                        grpTransak[intNoUrut].dblJPum = grpTransak[intNoUrut].dblJSum + fetchGakin.Tunainya;
                                    else if (fetchGakin.Lapurut == 3)
                                        grpTransak[intNoUrut].dblJaum = grpTransak[intNoUrut].dblJSum + fetchGakin.Tunainya;
                                }

                            }

                            intNoUrut++;
                        }
                    } /* if (grpKasAskin.Count > 0) */

                    /* ASKES JAMKESMAS */
                    if (grpKasJamkesmas.Count > 0)
                    {

                        var KASJKM = from x in grpKasJamkesmas
                                     group x by new
                                     {
                                         x.strIdBl_KelTarip,
                                         x.strIdBl_Komponen,
                                         x.intLapUrut
                                     }
                                         into groupKasJamkesmas
                                         select new
                                         {
                                             KelTarip = groupKasJamkesmas.Key.strIdBl_KelTarip,
                                             Komponen = groupKasJamkesmas.Key.strIdBl_Komponen,
                                             Lapurut = groupKasJamkesmas.Key.intLapUrut,
                                             Tunainya = groupKasJamkesmas.Sum(x => x.dblTunainya)
                                         };

                        int intUrut = 0;
                        foreach (var fetchTransak in grpTransak)
                        {
                            foreach (var fetchKASJKM in KASJKM)
                            {
                                if (fetchTransak.strUraian == fetchKASJKM.KelTarip)
                                {
                                    if (fetchKASJKM.Lapurut == 1)
                                        grpTransak[intUrut].dblJSum = grpTransak[intUrut].dblJSum + fetchKASJKM.Tunainya;
                                    else if (fetchKASJKM.Lapurut == 2)
                                        grpTransak[intUrut].dblJPum = grpTransak[intUrut].dblJPum + fetchKASJKM.Tunainya;
                                    else if (fetchKASJKM.Lapurut == 3)
                                        grpTransak[intUrut].dblJaum = grpTransak[intUrut].dblJaum + fetchKASJKM.Tunainya;
                                }
                            }

                            intUrut++;
                        }

                    } /* EOF if (grpKasJamkesmas.Count > 0) */

                    /* ASKES JAMKESDA */
                    if (grpKasJamkesda.Count > 0)
                    {
                        var KASJKD = from x in grpKasJamkesda
                                     group x by new
                                     {
                                         x.strIdBl_KelTarip,
                                         x.strIdBl_Komponen,
                                         x.intLapUrut
                                     }
                                         into groupKasJamkesda
                                         select new
                                         {
                                             KelTarip = groupKasJamkesda.Key.strIdBl_KelTarip,
                                             Komponen = groupKasJamkesda.Key.strIdBl_Komponen,
                                             LapUrut = groupKasJamkesda.Key.intLapUrut,
                                             Tunainya = groupKasJamkesda.Sum(x => x.dblTunainya)
                                         };

                        int intUrut = 0;
                        foreach (var fetchTransak in grpTransak)
                        {
                            foreach (var fetchKASJKD in KASJKD)
                            {
                                if (fetchTransak.strUraian == fetchKASJKD.KelTarip)
                                {
                                    if (fetchKASJKD.LapUrut == 1)
                                        grpTransak[intUrut].dblJSum = grpTransak[intUrut].dblJSum + fetchKASJKD.Tunainya;
                                    else if (fetchKASJKD.LapUrut == 2)
                                        grpTransak[intUrut].dblJPum = grpTransak[intUrut].dblJPum + fetchKASJKD.Tunainya;
                                    else if (fetchKASJKD.LapUrut == 3)
                                        grpTransak[intUrut].dblJaum = grpTransak[intUrut].dblJaum + fetchKASJKD.Tunainya;
                                }
                            }

                            intUrut++;
                        }

                    } /* EOF if (grpKasJamkesda.Count > 0) */

                    /* KAS LAIN */
                    if (grpKasLain.Count > 0)
                    {
                        var KASLAIN = from x in grpKasLain
                                      group x by new
                                      {
                                          x.strIdBl_KelTarip,
                                          x.strIdBl_Komponen,
                                          x.intLapUrut
                                      }
                                          into groupKasLain
                                          select new
                                          {
                                              KelTarip = groupKasLain.Key.strIdBl_KelTarip,
                                              Komponen = groupKasLain.Key.strIdBl_Komponen,
                                              LapUrut = groupKasLain.Key.intLapUrut,
                                              Tunainya = groupKasLain.Sum(x => x.dblTunainya)
                                          };

                        int intUrut = 0;
                        foreach (var fetchTransak in grpTransak)
                        {
                            foreach (var fetchKasLain in KASLAIN)
                            {
                                if (fetchTransak.strUraian == fetchKasLain.KelTarip)
                                {
                                    if (fetchKasLain.LapUrut == 1)
                                        grpTransak[intUrut].dblJSum = grpTransak[intUrut].dblJSum + fetchKasLain.Tunainya;
                                    else if (fetchKasLain.LapUrut == 2)
                                        grpTransak[intUrut].dblJPum = grpTransak[intUrut].dblJPum + fetchKasLain.Tunainya;
                                    else if (fetchKasLain.LapUrut == 3)
                                        grpTransak[intUrut].dblJaum = grpTransak[intUrut].dblJaum + fetchKasLain.Tunainya;
                                }
                            }

                            intUrut++;
                        }

                    } /* EOF if (grpKasLain.Count > 0) */

                }
                else if (strKode == "UNIT KERJA")
                {

                    var SMFUm = (from x in grpKasum select x.strIdMR_TSMF).Distinct();
                    var SMFKin = (from x in grpKasAskin select x.strIdMR_TSMF).Distinct();
                    var SMFJKM = (from x in grpKasJamkesmas select x.strIdMR_TSMF).Distinct();
                    var SMFJKD = (from x in grpKasJamkesda select x.strIdMR_TSMF).Distinct();
                    var SMFLain = (from x in grpKasLain select x.strIdMR_TSMF).Distinct();

                    if (SMFUm.Count() > 0)
                    {
                        foreach (var fetchSMFUm in SMFUm)
                        {
                            lstTransak itemTransak = new lstTransak();
                            itemTransak.strUraian = fetchSMFUm;
                            itemTransak.dblJSum = 0;
                            itemTransak.dblJPum = 0;
                            itemTransak.dblJaum = 0;
                            itemTransak.dblJSAsk = 0;
                            itemTransak.dblJPAsk = 0;
                            itemTransak.dblJAAsk = 0;
                            itemTransak.dblJSPav = 0;
                            itemTransak.dblJPPav = 0;
                            itemTransak.dblJAPav = 0;
                            grpTransak.Add(itemTransak);
                        }
                    }

                    /* ASKES GAKIN*/
                    if (grpTransak.Count > 0)
                    {
                        if (SMFKin.Count() > 0)
                        {
                            foreach (var fetchSMFKin in SMFKin)
                            {
                                foreach (var fetchTransak in grpTransak)
                                {
                                    if (fetchSMFKin == fetchTransak.strUraian)
                                    {
                                        lstTransak itemTransak = new lstTransak();
                                        itemTransak.strUraian = fetchSMFKin;
                                        itemTransak.dblJSum = 0;
                                        itemTransak.dblJPum = 0;
                                        itemTransak.dblJaum = 0;
                                        itemTransak.dblJSAsk = 0;
                                        itemTransak.dblJPAsk = 0;
                                        itemTransak.dblJAAsk = 0;
                                        itemTransak.dblJSPav = 0;
                                        itemTransak.dblJPPav = 0;
                                        itemTransak.dblJAPav = 0;
                                        grpTransak.Add(itemTransak);
                                    }
                                }
                            }
                        } /* EOF if (SMFKin.Count() > 0) */
                    } /* EOF if (grpTransak.Count > 0) */
                    else
                    {
                        if (SMFKin.Count() > 0)
                        {
                            foreach (var fetchSMFKin in SMFKin)
                            {
                                lstTransak itemTransak = new lstTransak();
                                itemTransak.strUraian = fetchSMFKin;
                                itemTransak.dblJSum = 0;
                                itemTransak.dblJPum = 0;
                                itemTransak.dblJaum = 0;
                                itemTransak.dblJSAsk = 0;
                                itemTransak.dblJPAsk = 0;
                                itemTransak.dblJAAsk = 0;
                                itemTransak.dblJSPav = 0;
                                itemTransak.dblJPPav = 0;
                                itemTransak.dblJAPav = 0;
                                grpTransak.Add(itemTransak);
                            }
                        }
                    }/* EOF ELSE if (grpTransak.Count > 0) */
                    /* EOF ASKES GAKIN*/

                    /* ASKES JAMKESMAS*/
                    if (grpTransak.Count > 0)
                    {
                        if (SMFJKM.Count() > 0)
                        {
                            foreach (var fetchSMFJKM in SMFJKM)
                            {
                                foreach (var fetchTransak in grpTransak)
                                {
                                    if (fetchSMFJKM == fetchTransak.strUraian)
                                    {
                                        lstTransak itemTransak = new lstTransak();
                                        itemTransak.strUraian = fetchSMFJKM;
                                        itemTransak.dblJSum = 0;
                                        itemTransak.dblJPum = 0;
                                        itemTransak.dblJaum = 0;
                                        itemTransak.dblJSAsk = 0;
                                        itemTransak.dblJPAsk = 0;
                                        itemTransak.dblJAAsk = 0;
                                        itemTransak.dblJSPav = 0;
                                        itemTransak.dblJPPav = 0;
                                        itemTransak.dblJAPav = 0;
                                        grpTransak.Add(itemTransak);
                                    }
                                }
                            }
                        } /* EOF if (SMFKin.Count() > 0) */
                    } /* EOF if (grpTransak.Count > 0) */
                    else
                    {
                        if (SMFJKM.Count() > 0)
                        {
                            foreach (var fetchSMFJKM in SMFJKM)
                            {
                                lstTransak itemTransak = new lstTransak();
                                itemTransak.strUraian = fetchSMFJKM;
                                itemTransak.dblJSum = 0;
                                itemTransak.dblJPum = 0;
                                itemTransak.dblJaum = 0;
                                itemTransak.dblJSAsk = 0;
                                itemTransak.dblJPAsk = 0;
                                itemTransak.dblJAAsk = 0;
                                itemTransak.dblJSPav = 0;
                                itemTransak.dblJPPav = 0;
                                itemTransak.dblJAPav = 0;
                                grpTransak.Add(itemTransak);
                            }
                        }
                    }/* EOF ELSE if (grpTransak.Count > 0) */

                    /* EOF ASKES JAMKESMAS*/

                    /* ASKES JAMKESDA*/
                    if (grpTransak.Count > 0)
                    {
                        if (SMFJKD.Count() > 0)
                        {
                            foreach (var fetchSMFJKD in SMFJKD)
                            {
                                foreach (var fetchTransak in grpTransak)
                                {
                                    if (fetchSMFJKD == fetchTransak.strUraian)
                                    {
                                        lstTransak itemTransak = new lstTransak();
                                        itemTransak.strUraian = fetchSMFJKD;
                                        itemTransak.dblJSum = 0;
                                        itemTransak.dblJPum = 0;
                                        itemTransak.dblJaum = 0;
                                        itemTransak.dblJSAsk = 0;
                                        itemTransak.dblJPAsk = 0;
                                        itemTransak.dblJAAsk = 0;
                                        itemTransak.dblJSPav = 0;
                                        itemTransak.dblJPPav = 0;
                                        itemTransak.dblJAPav = 0;
                                        grpTransak.Add(itemTransak);
                                    }
                                }
                            }
                        } /* EOF if (SMFKin.Count() > 0) */
                    } /* EOF if (grpTransak.Count > 0) */
                    else
                    {
                        if (SMFJKD.Count() > 0)
                        {
                            foreach (var fetchSMFJKD in SMFJKD)
                            {
                                lstTransak itemTransak = new lstTransak();
                                itemTransak.strUraian = fetchSMFJKD;
                                itemTransak.dblJSum = 0;
                                itemTransak.dblJPum = 0;
                                itemTransak.dblJaum = 0;
                                itemTransak.dblJSAsk = 0;
                                itemTransak.dblJPAsk = 0;
                                itemTransak.dblJAAsk = 0;
                                itemTransak.dblJSPav = 0;
                                itemTransak.dblJPPav = 0;
                                itemTransak.dblJAPav = 0;
                                grpTransak.Add(itemTransak);
                            }
                        }
                    }/* EOF ELSE if (grpTransak.Count > 0) */

                    /* EOF ASKES JAMKESDA*/

                    /* KAS LAIN*/
                    if (grpTransak.Count > 0)
                    {
                        if (SMFLain.Count() > 0)
                        {
                            foreach (var fetchSMFLain in SMFLain)
                            {
                                foreach (var fetchTransak in grpTransak)
                                {
                                    if (fetchSMFLain == fetchTransak.strUraian)
                                    {
                                        lstTransak itemTransak = new lstTransak();
                                        itemTransak.strUraian = fetchSMFLain;
                                        itemTransak.dblJSum = 0;
                                        itemTransak.dblJPum = 0;
                                        itemTransak.dblJaum = 0;
                                        itemTransak.dblJSAsk = 0;
                                        itemTransak.dblJPAsk = 0;
                                        itemTransak.dblJAAsk = 0;
                                        itemTransak.dblJSPav = 0;
                                        itemTransak.dblJPPav = 0;
                                        itemTransak.dblJAPav = 0;
                                        grpTransak.Add(itemTransak);
                                    }
                                }
                            }
                        } /* EOF if (SMFKin.Count() > 0) */
                    } /* EOF if (grpTransak.Count > 0) */
                    else
                    {
                        if (SMFLain.Count() > 0)
                        {
                            foreach (var fetchSMFLain in SMFLain)
                            {
                                lstTransak itemTransak = new lstTransak();
                                itemTransak.strUraian = fetchSMFLain;
                                itemTransak.dblJSum = 0;
                                itemTransak.dblJPum = 0;
                                itemTransak.dblJaum = 0;
                                itemTransak.dblJSAsk = 0;
                                itemTransak.dblJPAsk = 0;
                                itemTransak.dblJAAsk = 0;
                                itemTransak.dblJSPav = 0;
                                itemTransak.dblJPPav = 0;
                                itemTransak.dblJAPav = 0;
                                grpTransak.Add(itemTransak);
                            }
                        }
                    }/* EOF ELSE if (grpTransak.Count > 0) */

                    /* EOF KAS LAIN*/

                    if (grpTransak.Count > 0)
                    {
                        /* UMUM */
                        if (grpKasum.Count > 0)
                        {
                            var Kasumum = from x in grpKasum
                                          group x by new
                                          {
                                              x.strIdMR_TSMF,
                                              x.strIdBl_Komponen,
                                              x.intLapUrut
                                          } into groupKasum
                                          select new
                                          {
                                              TSMF = groupKasum.Key.strIdMR_TSMF,
                                              Komponen = groupKasum.Key.strIdBl_Komponen,
                                              LapUrut = groupKasum.Key.intLapUrut,
                                              Tunainya = groupKasum.Sum(x => x.dblTunainya)
                                          };

                            int intUrut = 0;
                            foreach (var fetchTransak in grpTransak)
                            {
                                foreach (var fetchKasUmum in Kasumum)
                                {
                                    if (fetchTransak.strUraian == fetchKasUmum.TSMF)
                                    {
                                        if (fetchKasUmum.LapUrut == 1)
                                            grpTransak[intUrut].dblJSum = fetchKasUmum.Tunainya;
                                        else if (fetchKasUmum.LapUrut == 2)
                                            grpTransak[intUrut].dblJPum = fetchKasUmum.Tunainya;
                                        else if (fetchKasUmum.LapUrut == 3)
                                            grpTransak[intUrut].dblJaum = fetchKasUmum.Tunainya;
                                    }
                                }
                                intUrut++;
                            }
                        } /* EOF if (grpKasum.Count > 0) */
                        /* EOF UMUM */

                        /* KASASK */

                        if (grpKasAskes.Count > 0)
                        {
                            var Kasaskes = (from x in grpKasAskes
                                            select x.dblTunai).Sum();

                            if (Kasaskes > 0)
                            {
                                var Admaskes = (from x in grpAdmAkses
                                                select x.dblJumlah).Sum();
                                if (Admaskes > 0)
                                {
                                    int intUrut = 0;
                                    foreach (var fetchTransak in grpTransak)
                                    {
                                        if (fetchTransak.strUraian == "ASKES")
                                        {
                                            grpTransak[intUrut].dblJSum = Kasaskes - Admaskes;
                                        }

                                        if (fetchTransak.strUraian == "ADMINISTRASI")
                                        {
                                            grpTransak[intUrut].dblJPum = Kasaskes + Admaskes;
                                        }
                                        intUrut++;
                                    }
                                } /* EOF if (Admaskes > 0) */
                                else
                                {
                                    int intUrut = 0;
                                    foreach (var fetchTransak in grpTransak)
                                    {
                                        if (fetchTransak.strUraian == "ASKES")
                                        {
                                            grpTransak[intUrut].dblJSum = Kasaskes;
                                        }
                                        intUrut++;
                                    }
                                } /* EOF ELSE if (Admaskes > 0) */

                            } /* EOF if (Kasaskes > 0) */
                            else
                            {
                                int intUrut = 0;
                                foreach (var fetchTransak in grpTransak)
                                {
                                    if (fetchTransak.strUraian == "ASKES")
                                    {
                                        grpTransak[intUrut].dblJSum = 0;
                                    }
                                    intUrut++;
                                }
                            } /* EOF ELSE if (Kasaskes > 0) */
                        }
                        /* EOF KASASK */

                        /* ASKES GAKIN */
                        if (grpKasAskin.Count > 0)
                        {
                            var Kasaskin = from x in grpKasAskin
                                           group x by new
                                           {
                                               x.strIdMR_TSMF,
                                               x.strIdBl_Komponen,
                                               x.intLapUrut
                                           } into groupKasaskin
                                           select new
                                           {
                                               TSMF = groupKasaskin.Key.strIdMR_TSMF,
                                               Komponen = groupKasaskin.Key.strIdBl_Komponen,
                                               LapUrut = groupKasaskin.Key.intLapUrut,
                                               Tunainya = groupKasaskin.Sum(x => x.dblTunainya)
                                           };

                            int intUrut = 0;
                            foreach (var fetchTransak in grpTransak)
                            {
                                foreach (var fetchKasaskin in Kasaskin)
                                {
                                    if (fetchTransak.strUraian == fetchKasaskin.TSMF)
                                    {
                                        if (fetchKasaskin.LapUrut == 1)
                                            grpTransak[intUrut].dblJSum = fetchKasaskin.Tunainya;
                                        else if (fetchKasaskin.LapUrut == 2)
                                            grpTransak[intUrut].dblJPum = fetchKasaskin.Tunainya;
                                        else if (fetchKasaskin.LapUrut == 3)
                                            grpTransak[intUrut].dblJaum = fetchKasaskin.Tunainya;
                                    }
                                }
                                intUrut++;
                            }
                        } /* EOF if (grpKasAskin.Count > 0) */
                        /* ASKES GAKIN */

                        /* ASKES JAMKESMAS */
                        if (grpKasJamkesmas.Count > 0)
                        {
                            var KasJamkesmas = from x in grpKasJamkesmas
                                               group x by new
                                               {
                                                   x.strIdMR_TSMF,
                                                   x.strIdBl_Komponen,
                                                   x.intLapUrut
                                               } into groupKasJamkesmas
                                               select new
                                               {
                                                   TSMF = groupKasJamkesmas.Key.strIdMR_TSMF,
                                                   Komponen = groupKasJamkesmas.Key.strIdBl_Komponen,
                                                   LapUrut = groupKasJamkesmas.Key.intLapUrut,
                                                   Tunainya = groupKasJamkesmas.Sum(x => x.dblTunainya)
                                               };

                            int intUrut = 0;
                            foreach (var fetchTransak in grpTransak)
                            {
                                foreach (var fetchKasJamkesmas in KasJamkesmas)
                                {
                                    if (fetchTransak.strUraian == fetchKasJamkesmas.TSMF)
                                    {
                                        if (fetchKasJamkesmas.LapUrut == 1)
                                            grpTransak[intUrut].dblJSum = fetchKasJamkesmas.Tunainya;
                                        else if (fetchKasJamkesmas.LapUrut == 2)
                                            grpTransak[intUrut].dblJPum = fetchKasJamkesmas.Tunainya;
                                        else if (fetchKasJamkesmas.LapUrut == 3)
                                            grpTransak[intUrut].dblJaum = fetchKasJamkesmas.Tunainya;
                                    }
                                }
                                intUrut++;
                            }
                        } /* EOF if (grpKasJamkesmas.Count > 0) */
                        /* EOF ASKES JAMKESMAS */

                        /* ASKES JAMKESDA */
                        if (grpKasJamkesda.Count > 0)
                        {
                            var KasJamkesda = from x in grpKasJamkesda
                                              group x by new
                                              {
                                                  x.strIdMR_TSMF,
                                                  x.strIdBl_Komponen,
                                                  x.intLapUrut
                                              } into groupKasJamkesda
                                              select new
                                              {
                                                  TSMF = groupKasJamkesda.Key.strIdMR_TSMF,
                                                  Komponen = groupKasJamkesda.Key.strIdBl_Komponen,
                                                  LapUrut = groupKasJamkesda.Key.intLapUrut,
                                                  Tunainya = groupKasJamkesda.Sum(x => x.dblTunainya)
                                              };

                            int intUrut = 0;
                            foreach (var fetchTransak in grpTransak)
                            {
                                foreach (var fetchKasJamkesda in KasJamkesda)
                                {
                                    if (fetchTransak.strUraian == fetchKasJamkesda.TSMF)
                                    {
                                        if (fetchKasJamkesda.LapUrut == 1)
                                            grpTransak[intUrut].dblJSum = fetchKasJamkesda.Tunainya;
                                        else if (fetchKasJamkesda.LapUrut == 2)
                                            grpTransak[intUrut].dblJPum = fetchKasJamkesda.Tunainya;
                                        else if (fetchKasJamkesda.LapUrut == 3)
                                            grpTransak[intUrut].dblJaum = fetchKasJamkesda.Tunainya;
                                    }
                                }
                                intUrut++;
                            }
                        } /* EOF if (grpKasJamkesda.Count > 0) */
                        /* EOF ASKES JAMKESDA */

                        /* KAS LAIN*/
                        if (grpKasLain.Count > 0)
                        {
                            var KasLain = from x in grpKasLain
                                          group x by new
                                          {
                                              x.strIdMR_TSMF,
                                              x.strIdBl_Komponen,
                                              x.intLapUrut
                                          } into groupKasLain
                                          select new
                                          {
                                              TSMF = groupKasLain.Key.strIdMR_TSMF,
                                              Komponen = groupKasLain.Key.strIdBl_Komponen,
                                              LapUrut = groupKasLain.Key.intLapUrut,
                                              Tunainya = groupKasLain.Sum(x => x.dblTunainya)
                                          };

                            int intUrut = 0;
                            foreach (var fetchTransak in grpTransak)
                            {
                                foreach (var fetchKasLain in KasLain)
                                {
                                    if (fetchTransak.strUraian == fetchKasLain.TSMF)
                                    {
                                        if (fetchKasLain.LapUrut == 1)
                                            grpTransak[intUrut].dblJSum = fetchKasLain.Tunainya;
                                        else if (fetchKasLain.LapUrut == 2)
                                            grpTransak[intUrut].dblJPum = fetchKasLain.Tunainya;
                                        else if (fetchKasLain.LapUrut == 3)
                                            grpTransak[intUrut].dblJaum = fetchKasLain.Tunainya;
                                    }
                                }
                                intUrut++;
                            }
                        } /* EOF if (grpKasLain.Count > 0) */
                        /* EOF KAS LAIN */

                        /* PERLU DI SORTING SESUAI URIAN PADA TRANSAK*/

                    } /* EOF if (grpTransak.Count > 0) */

                } /* EOF if (strKode == "BLABLABLA") */

                //MessageBox.Show("strKode == ADA");

            } /* EOF if (strKode != "") */
            else
            {
                //MessageBox.Show("strKode == KOSONG");
            }

            /*MEMULAI FETCHING TRANSAK*/
            FileInfo newFile = new FileInfo("E:" + @"\sample1.xlsx");
            if (newFile.Exists)
            {
                newFile.Delete();  // ensures we create a new workbook
                newFile = new FileInfo("E:" + @"\sample1.xlsx");
            }

            using (ExcelPackage package = new ExcelPackage(newFile))
            {

                ExcelWorksheet worksheet = package.Workbook.Worksheets.Add(strKode);

                /*
                    public string strUraian { get; set; }
                    public double dblJSum { get; set; }
                    public double dblJPum { get; set; }
                    public double dblJaum { get; set; }
                    public double dblJSAsk { get; set; }
                    public double dblJPAsk { get; set; }
                    public double dblJAAsk { get; set; }
                    public double dblJSPav { get; set; }
                    public double dblJPPav { get; set; }
                    public double dblJAPav { get; set; }
                    */

                //Add the headers
                worksheet.Cells[1, 1].Value = "Uraian";
                worksheet.Cells[1, 2].Value = "JSUM";
                worksheet.Cells[1, 3].Value = "JPUM";
                worksheet.Cells[1, 4].Value = "JAUM";
                worksheet.Cells[1, 5].Value = "JSASK";
                worksheet.Cells[1, 6].Value = "JPASK";
                worksheet.Cells[1, 7].Value = "JAASK";
                worksheet.Cells[1, 8].Value = "JSPAV";
                worksheet.Cells[1, 9].Value = "JPPAV";
                worksheet.Cells[1, 10].Value = "JAPAV";

                int intStartRow = 2;

                foreach (var fetchTransak in grpTransak)
                {
                    worksheet.Cells[intStartRow, 1].Value = fetchTransak.strUraian;
                    worksheet.Cells[intStartRow, 2].Value = fetchTransak.dblJSum.ToString();
                    worksheet.Cells[intStartRow, 3].Value = fetchTransak.dblJPum.ToString();
                    worksheet.Cells[intStartRow, 4].Value = fetchTransak.dblJaum.ToString();
                    worksheet.Cells[intStartRow, 5].Value = fetchTransak.dblJSAsk.ToString();
                    worksheet.Cells[intStartRow, 6].Value = fetchTransak.dblJPAsk.ToString();
                    worksheet.Cells[intStartRow, 7].Value = fetchTransak.dblJAAsk.ToString();
                    worksheet.Cells[intStartRow, 8].Value = fetchTransak.dblJSPav.ToString();
                    worksheet.Cells[intStartRow, 9].Value = fetchTransak.dblJPPav.ToString();
                    worksheet.Cells[intStartRow, 10].Value = fetchTransak.dblJAPav.ToString();

                    intStartRow++;
                }

                package.Save();

            }

            lblInfoPencarian.SafeControlInvoke(Label => lblInfoPencarian.Visible = false);
            lblInfoPencarian.SafeControlInvoke(Label => lblInfoPencarian.Text = "");
        }
Пример #2
0
        private void bgWorkLoadFromDB_DoWork(object sender, DoWorkEventArgs e)
        {
            /*CLEAN DATA*/

            grpLstKASUM.Clear();
            //grpLstKASASKIN.Clear();
            grpLstKASJKM.Clear();
            grpLstKASJKD.Clear();
            grpKelTarip.Clear();
            grpLstReg.Clear();
            grpTransak.Clear();
            grpTransaknya.Clear();
            grpTind.Clear();

            dtpFilterTgl1.SafeControlInvoke(DateTimePicker => dtpFilterTgl1.Enabled = false);
            dtpFilterTgl2.SafeControlInvoke(DateTimePicker => dtpFilterTgl2.Enabled = false);
            cmbJenisLaporan.SafeControlInvoke(ComboBox => cmbJenisLaporan.Enabled = false);
            cmbUnit.SafeControlInvoke(ComboBox => cmbUnit.Enabled = false);
            btnCari.SafeControlInvoke(Button => btnCari.Enabled = false);
            lblInfoPencarian.SafeControlInvoke(Label => lblInfoPencarian.Visible = true);
            cmbPilihanExport.SafeControlInvoke(ComboBox => cmbPilihanExport.Enabled = false);
            btnExport.SafeControlInvoke(Button => btnExport.Enabled = false);
            btnTampilkan.SafeControlInvoke(Button => btnTampilkan.Enabled = false);

            this.strErr = "";
            C4Module.MainModule.strRegKey = halamanUtama.FULL_REG_CONN;

            SqlConnection conn = modDb.pbconnKoneksiSQL(ref strErr);
            if (strErr != "")
            {
                tmrBlink.Enabled = false;
                tmrBlink.Stop();
                lblInfoPencarian.SafeControlInvoke(Label => lblInfoPencarian.Visible = false);
                modMsg.pvDlgErr(modMsg.IS_DEV, strErr, modMsg.DB_CON, modMsg.TITLE_ERR);
                return;
            }

            lblInfoPencarian.SafeControlInvoke(Label => lblInfoPencarian.Text = "Proses Load - KELOMPOK TARIP");
            this.strQuerySQL = "SELECT Idbl_keltarip,Urutan,Lapjp,Rekapjp "+
                               "FROM BL_KELTARIP WITH (NOLOCK) "+
                               "WHERE lapjp <> '-' "+
                               "ORDER BY lapjp, urutan";

            SqlDataReader reader = modDb.pbreaderSQL(conn, strQuerySQL, ref strErr);
            if (strErr != "")
            {
                tmrBlink.Enabled = false;
                tmrBlink.Stop();
                lblInfoPencarian.SafeControlInvoke(Label => lblInfoPencarian.Visible = false);
                modMsg.pvDlgErr(modMsg.IS_DEV, strErr, modMsg.DB_GET, modMsg.TITLE_ERR);
                conn.Close();
                return;
            }

            if (reader.HasRows)
            {
                while (reader.Read())
                {

                    lstKelTarip itemKelTarip = new lstKelTarip();
                    itemKelTarip.strIdBl_KelTarip = modMain.pbstrgetCol(reader, 0, ref strErr, "");
                    itemKelTarip.intUrutan = Convert.ToInt32(modMain.pbstrgetCol(reader, 1, ref strErr, ""));
                    itemKelTarip.strLapJP = modMain.pbstrgetCol(reader, 2, ref strErr, "");
                    itemKelTarip.strRekapJP = modMain.pbstrgetCol(reader, 3, ref strErr, "");

                    grpKelTarip.Add(itemKelTarip);

                }
            }

            reader.Close();

            intWaktuLoad = 0;
            intPenandaProses = 1;
            tmrWaktuLoad.Enabled = true;
            tmrWaktuLoad.Start();

            /* QUERY KASUM */
            this.strQuerySQL = "SELECT " +
                                    "BL_TRANSAKSI_1.Regbilling, " +                                              //0
                                    "MR_PASIEN.Nama, " +                                                         //1
                                    "MR_TRUANGAN.ruangan, " +                                                    //2
                                    "BL_TRANSAKSI_1.Jumlah, " +                                                  //3
                                    "BL_TRANSAKSI_1.subsidi, " +                                                 //4
                                    "BL_TRANSAKSI_1.tunai, " +                                                   //5
                                    "BL_TRANSAKSIDETAIL_1.Idbl_komponen, " +                                     //6
                                    "BL_TRANSAKSIDETAIL_1.Nilai, " +                                             //7
                                    "BL_TRANSAKSIDETAIL_1.Ringan, " +                                            //8
                                    "BL_KELTARIP.urutan, " +                                                     //9
                                    "BL_KELTARIP.rekapjp," +                                                     //10
                                    "BL_TRANSAKSIDETAIL_1.Nilai - BL_TRANSAKSIDETAIL_1.Ringan as tunainya , " +  //11
                                    "BL_TRANSAKSIDETAIL_1.Noambil, " +                                           //12
                                    "BL_TRANSAKSIDETAIL_1.tglambil, " +                                          //13
                                    "BL_KELTARIP.Idbl_keltarip, " +                                              //14
                                    "BL_KELTARIP.Lapjp, " +                                                      //15
                                    "BL_TRANSAKSI_1.idmr_tsmf, " +                                               //16
                                    "MR_SMFTARIP.idmr_tupf, " +                                                  //17
                                    "BL_TRANSAKSI_1.idbl_tarip, " +                                              //18
                                    "BL_TRANSAKSI_1.uraiantarip, " +                                             //19
                                    "BL_TRANSAKSI_1.jml_kasus_tarip, " +                                         //20
                                    "BL_TRANSAKSI_1.idbl_transaksi, " +                                          //21
                                    "BL_KASUMUM.Idbl_Pembayaran, " +                                             //22
                                    "BL_TRANSAKSI_1.Tgltransaksi, " +                                            //23
                                    "BL_KASUMUM.Tanggal, " +                                                     //24
                                    "BL_TARIP.Idmr_jeniskelas, " +                                               //25
                                    "BL_TRANSAKSI_1.Idmr_truangan, " +                                           //26
                                    "BL_TRANSAKSIDETAIL_1.idmr_dokter, " +                                                  //27
                                    "MR_DOKTER.Nama " +                                                          //28
                               "FROM BL_KELTARIP  With (nolock) "+
                               "INNER JOIN BL_TRANSAKSI_1 " +
                               "INNER JOIN BL_TRANSAKSIDETAIL_1 "+
                                    "ON BL_TRANSAKSI_1.idbl_transaksi = BL_TRANSAKSIDETAIL_1.Idbl_transaksi "+
                               "INNER JOIN BL_TARIP "+
                                    "ON BL_TRANSAKSI_1.idbl_tarip = BL_TARIP.IdBl_tarip "+
                                    "ON BL_KELTARIP.Idbl_keltarip = BL_TARIP.Idbl_keltarip "+
                               "INNER JOIN MR_SMFTARIP "+
                                    "ON BL_TRANSAKSI_1.idmr_tsmf = MR_SMFTARIP.idmr_tsmf "+
                               "INNER JOIN BL_KASUMUM "+
                                    "ON BL_TRANSAKSI_1.idbl_pembayaran = BL_KASUMUM.Idbl_Pembayaran "+
                                    " AND BL_TRANSAKSI_1.idmr_mutasipasien = BL_KASUMUM.idmr_mutasipasien "+
                               "INNER JOIN MR_PASIEN "+
                                    "ON BL_KASUMUM.Idmr_pasien = MR_PASIEN.IDMR_PASIEN "+
                               "INNER JOIN MR_TRUANGAN "+
                                    "ON BL_KASUMUM.Idmr_truangan = MR_TRUANGAN.idmr_truangan "+
                               "LEFT JOIN MR_DOKTER " +
                                    "ON BL_TRANSAKSIDETAIL_1.idmr_dokter = MR_DOKTER.idmr_dokter " +
                               "WHERE (BL_TRANSAKSI_1.Batal <> 'Y') " +
                                    "AND (BL_KASUMUM.Batal = '') " +
                                    " AND (BL_TRANSAKSIDETAIL_1.Idbl_komponen <> 'JASA SARANA') "+
                                    " AND BL_KASUMUM.Tanggal between '" + dtpFilterTgl1.Value.ToString("MM/dd/yyyy 00:00:00") +
                                        "' AND '" + dtpFilterTgl2.Value.ToString("MM/dd/yyyy 23:59:59") +  "' "+
                                    " AND BL_TARIP.pisahsetor = '' "+
                                    " AND BL_TRANSAKSIDETAIL_1.noambil <> 999 "+
                                    " AND BL_TRANSAKSI_1.idmr_tsmf <> 'DARAH' "+
                                    " AND BL_TRANSAKSI_1.idmr_tsmf <> 'PENDORONG'"+
                                    " AND BL_TRANSAKSI_1.idmr_tsmf <> 'OBAT/ALKES-FARMASI' "+
                                    " AND BL_TRANSAKSI_1.idmr_tsmf <> 'OBAT/ALKES-KPRI'"+
                                    " AND BL_TRANSAKSI_1.idbl_pembayaran > 0 "+
                                    " AND BL_KELTARIP.Lapjp <> '-'";

            reader = modDb.pbreaderSQL(conn, strQuerySQL, ref strErr);
            if (strErr != "")
            {
                tmrBlink.Enabled = false;
                tmrBlink.Stop();
                lblInfoPencarian.SafeControlInvoke(Label => lblInfoPencarian.Visible = false);
                modMsg.pvDlgErr(modMsg.IS_DEV, strErr, modMsg.DB_GET, modMsg.TITLE_ERR);
                conn.Close();
                return;
            }

            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    lstKASUM itemKASUM = new lstKASUM();

                    itemKASUM.strRegBilling = modMain.pbstrgetCol(reader, 0, ref strErr, "");
                    itemKASUM.strNama = modMain.pbstrgetCol(reader, 1, ref strErr, "");
                    itemKASUM.strRuangan = modMain.pbstrgetCol(reader, 2, ref strErr, "");
                    itemKASUM.dblJumlah = Convert.ToDouble(modMain.pbstrgetCol(reader, 3, ref strErr, ""));
                    itemKASUM.dblSubsidi = Convert.ToDouble(modMain.pbstrgetCol(reader, 4, ref strErr, ""));
                    itemKASUM.dblTunai = Convert.ToDouble(modMain.pbstrgetCol(reader, 5, ref strErr, ""));
                    itemKASUM.strIdBl_Komponen = modMain.pbstrgetCol(reader, 6, ref strErr, "");
                    itemKASUM.dblNilai = Convert.ToDouble(modMain.pbstrgetCol(reader, 7, ref strErr, ""));
                    itemKASUM.dblRingan = Convert.ToDouble(modMain.pbstrgetCol(reader, 8, ref strErr, ""));
                    itemKASUM.dblUrutan = Convert.ToDouble(modMain.pbstrgetCol(reader, 9, ref strErr, ""));
                    itemKASUM.strRekapJp = modMain.pbstrgetCol(reader, 10, ref strErr, "");
                    itemKASUM.dblTunainya = Convert.ToDouble(modMain.pbstrgetCol(reader, 11, ref strErr, ""));
                    itemKASUM.dblNoAmbil = Convert.ToDouble(modMain.pbstrgetCol(reader, 12, ref strErr, ""));
                    itemKASUM.dtTglAmbil = Convert.ToDateTime(modMain.pbstrgetCol(reader, 13, ref strErr, ""));
                    itemKASUM.strIdBl_KelTarip = modMain.pbstrgetCol(reader, 14, ref strErr, "");
                    itemKASUM.strLapJP = modMain.pbstrgetCol(reader, 15, ref strErr, "");
                    itemKASUM.strIdMR_TSMF = modMain.pbstrgetCol(reader, 16, ref strErr, "");
                    itemKASUM.strIdMR_TUPF = modMain.pbstrgetCol(reader, 17, ref strErr, "");
                    itemKASUM.strIdBl_Tarip = modMain.pbstrgetCol(reader, 18, ref strErr, "");
                    itemKASUM.strUraianTarip = modMain.pbstrgetCol(reader, 19, ref strErr, "");
                    itemKASUM.dblJumlahKasusTarip = Convert.ToDouble(modMain.pbstrgetCol(reader, 20, ref strErr, ""));
                    itemKASUM.strIdBl_Transaksi = modMain.pbstrgetCol(reader, 21, ref strErr, "");
                    itemKASUM.strIdBl_Pembayaran = modMain.pbstrgetCol(reader, 22, ref strErr, "");
                    itemKASUM.dtTglTransaksi = Convert.ToDateTime(modMain.pbstrgetCol(reader, 23, ref strErr, ""));
                    itemKASUM.dtTgl = Convert.ToDateTime(modMain.pbstrgetCol(reader, 24, ref strErr, ""));
                    itemKASUM.strIdMR_JenisKelas = modMain.pbstrgetCol(reader, 25, ref strErr, "");
                    itemKASUM.strIdMR_Ruangan = modMain.pbstrgetCol(reader, 26, ref strErr, "");
                    itemKASUM.strIdMR_Dokter = modMain.pbstrgetCol(reader, 27, ref strErr, "");
                    itemKASUM.strNamaDokter = modMain.pbstrgetCol(reader, 28, ref strErr, "");

                    grpLstKASUM.Add(itemKASUM);
                }
            }

            reader.Close();
            conn.Close();

            if (grpLstKASUM.Count > 0)
            {
                /*JIKA DITEMUKAN DATA PADA grpLstKASUM maka lakukan perhitungan disini*/

                var KasumJP = (from fetch in grpLstKASUM
                               where (fetch.strIdBl_Komponen == "JASA PELAYANAN" && fetch.dblTunainya > 0)
                               group fetch by new
                               {
                                   fetch.strRegBilling,
                                   fetch.strNama,
                                   fetch.strIdBl_Komponen,
                                   fetch.strLapJP,
                                   fetch.strIdMR_TUPF,
                                   fetch.strIdMR_TSMF,
                                   fetch.strRuangan
                                } into groupData
                              select new
                              {
                                  regBilling = groupData.Key.strRegBilling,
                                    Nama = groupData.Key.strNama,
                                    Ruangan = groupData.Key.strRuangan,
                                    TUPF = groupData.Key.strIdMR_TUPF,
                                    IdBl_Komponen = groupData.Key.strIdBl_Komponen,
                                    IdMR_TSMF = groupData.Key.strIdMR_TSMF,
                                    tunainya = groupData.Sum(fetchKasum => fetchKasum.dblTunainya),
                                    LapJP = groupData.Key.strLapJP
                              }).OrderBy(groupData => groupData.regBilling).ToList();

                var KasumJA = (from fetch in grpLstKASUM
                               where (fetch.strIdBl_Komponen != "JASA PELAYANAN" && fetch.dblTunainya > 0)
                               group fetch by new
                               {
                                   fetch.strRegBilling,
                                   fetch.strNama,
                                   fetch.strIdBl_Komponen,
                                   fetch.strLapJP,
                                   fetch.strIdMR_TUPF,
                                   fetch.strIdMR_TSMF,
                                   fetch.strRuangan
                               } into groupData
                               select new
                               {
                                   regBilling = groupData.Key.strRegBilling,
                                   Nama = groupData.Key.strNama,
                                   Ruangan = groupData.Key.strRuangan,
                                   TUPF = groupData.Key.strIdMR_TUPF,
                                   IdBl_Komponen = groupData.Key.strIdBl_Komponen,
                                   IdMR_TSMF = groupData.Key.strIdMR_TSMF,
                                   tunainya = groupData.Sum(fetchKasum => fetchKasum.dblTunainya),
                                   LapJP = groupData.Key.strLapJP
                               }).OrderBy(groupData => groupData.regBilling).ToList();

                var reg = (from fetch in grpLstKASUM
                          select new
                          {
                              Regbilling = fetch.strRegBilling,
                              Nama = fetch.strNama,
                              Ruangan = fetch.strRuangan,
                              idmr_tupf = fetch.strIdMR_TUPF,
                              idmr_tsmf = fetch.strIdMR_TSMF
                          }).Distinct().OrderBy( a => a.Regbilling).ToList();

                if (reg.Count > 0)
                {
                    foreach (var fetch in reg)
                    {
                        lstTransak itemTransak = new lstTransak();
                        itemTransak.strRegbilling = fetch.Regbilling;
                        itemTransak.strNama = fetch.Nama;
                        itemTransak.strRuangan = fetch.Ruangan;
                        itemTransak.strUnit = fetch.idmr_tupf;
                        itemTransak.strSMF = fetch.idmr_tsmf;
                        itemTransak.dblKonsul = 0;
                        itemTransak.dblVisite = 0;
                        itemTransak.dblOperasi = 0;
                        itemTransak.dblTindakan = 0;
                        itemTransak.dblDiagelect = 0;
                        itemTransak.dblPemRK = 0;
                        grpTransak.Add(itemTransak);
                    }
                }

                if (grpTransak.Count > 0)
                {
                    /*JASA PELAYANAN*/
                    foreach (var fetchKasumJP in KasumJP)
                    {

                        if (fetchKasumJP.LapJP.Substring(0, 1) == "1")
                        {
                            int intUrut = 0;
                            foreach (var fetchTransak in grpTransak)
                            {
                                if (fetchTransak.strRegbilling == fetchKasumJP.regBilling
                                    && fetchKasumJP.LapJP.Substring(0, 1) == "1"
                                    && fetchTransak.strRuangan == fetchKasumJP.Ruangan
                                    && fetchTransak.strSMF == fetchKasumJP.IdMR_TSMF)
                                {
                                    grpTransak[intUrut].dblKonsul = grpTransak[intUrut].dblKonsul + fetchKasumJP.tunainya;
                                    //fetchTransak.dblKonsul = fetchTransak.dblKonsul + fetchKasumJP.tunainya;
                                }
                                intUrut++;
                            } /* EOF foreach (var fetchTransak in grpTransak) */
                        } /* EOF if (fetchKasumJP.LapJP.Substring(1, 1) == "1") */

                        else if (fetchKasumJP.LapJP.Substring(0, 1) == "2")
                        {
                            int intUrut = 0;
                            foreach (var fetchTransak in grpTransak)
                            {
                                if (fetchTransak.strRegbilling == fetchKasumJP.regBilling
                                    && fetchKasumJP.LapJP.Substring(0, 1) == "2"
                                    && fetchTransak.strRuangan == fetchKasumJP.Ruangan
                                    && fetchTransak.strSMF == fetchKasumJP.IdMR_TSMF)
                                {
                                    grpTransak[intUrut].dblVisite = grpTransak[intUrut].dblVisite + fetchKasumJP.tunainya;
                                }
                                intUrut++;
                            } /* EOF foreach (var fetchTransak in grpTransak) */

                        } /* EOF else if (fetchKasumJP.LapJP.Substring(1, 1) == "2") */
                        else if (fetchKasumJP.LapJP.Substring(0, 1) == "3")
                        {
                            int intUrut = 0;
                            foreach (var fetchTransak in grpTransak)
                            {
                                if (fetchTransak.strRegbilling == fetchKasumJP.regBilling
                                    && fetchKasumJP.LapJP.Substring(0, 1) == "3"
                                    && fetchTransak.strRuangan == fetchKasumJP.Ruangan
                                    && fetchTransak.strSMF == fetchKasumJP.IdMR_TSMF)
                                {
                                    grpTransak[intUrut].dblOperasi = grpTransak[intUrut].dblOperasi + fetchKasumJP.tunainya;
                                }
                                intUrut++;
                            } /* EOF foreach (var fetchTransak in grpTransak) */

                        } /* EOF else if (fetchKasumJP.LapJP.Substring(1, 1) == "3") */
                        else if (fetchKasumJP.LapJP.Substring(0, 1) == "4")
                        {
                            int intUrut = 0;
                            foreach (var fetchTransak in grpTransak)
                            {
                                if (fetchTransak.strRegbilling == fetchKasumJP.regBilling
                                    && fetchKasumJP.LapJP.Substring(0, 1) == "4"
                                    && fetchTransak.strRuangan == fetchKasumJP.Ruangan
                                    && fetchTransak.strSMF == fetchKasumJP.IdMR_TSMF)
                                {
                                    grpTransak[intUrut].dblTindakan = grpTransak[intUrut].dblTindakan + fetchKasumJP.tunainya;
                                }
                                intUrut++;
                            } /* EOF foreach (var fetchTransak in grpTransak) */

                        } /* EOF else if (fetchKasumJP.LapJP.Substring(1, 1) == "4") */
                        else if (fetchKasumJP.LapJP.Substring(0, 1) == "5")
                        {
                            int intUrut = 0;
                            foreach (var fetchTransak in grpTransak)
                            {
                                if (fetchTransak.strRegbilling == fetchKasumJP.regBilling
                                    && fetchKasumJP.LapJP.Substring(0, 1) == "5"
                                    && fetchTransak.strRuangan == fetchKasumJP.Ruangan
                                    && fetchTransak.strSMF == fetchKasumJP.IdMR_TSMF)
                                {
                                    grpTransak[intUrut].dblDiagelect = grpTransak[intUrut].dblDiagelect + fetchKasumJP.tunainya;
                                }
                                intUrut++;
                            } /* EOF foreach (var fetchTransak in grpTransak) */

                        } /* EOF else if (fetchKasumJP.LapJP.Substring(1, 1) == "5") */
                        else if (fetchKasumJP.LapJP.Substring(0, 1) == "6")
                        {
                            int intUrut = 0;
                            foreach (var fetchTransak in grpTransak)
                            {
                                if (fetchTransak.strRegbilling == fetchKasumJP.regBilling
                                    && fetchKasumJP.LapJP.Substring(0, 1) == "6"
                                    && fetchTransak.strRuangan == fetchKasumJP.Ruangan
                                    && fetchTransak.strSMF == fetchKasumJP.IdMR_TSMF)
                                {
                                    grpTransak[intUrut].dblPemRK = grpTransak[intUrut].dblPemRK + fetchKasumJP.tunainya;
                                }
                                intUrut++;
                            } /* EOF foreach (var fetchTransak in grpTransak) */

                        } /* EOF else if (fetchKasumJP.LapJP.Substring(1, 1) == "6") */

                        /* 2 SAMPAI 6 */

                    } /* EOF foreach (var fetchKasumJP in KasumJP) */

                    /*JASA ANASTHESI*/

                    if (KasumJA.Count > 0)
                    {
                        foreach (var fetchKasumJA in KasumJA)
                        {

                            lstTransak itemTransak = new lstTransak();
                            itemTransak.strRegbilling = fetchKasumJA.regBilling;
                            itemTransak.strNama = fetchKasumJA.Nama;
                            itemTransak.strRuangan = fetchKasumJA.Ruangan;
                            itemTransak.strUnit = "ANASTHESI";
                            itemTransak.strSMF = fetchKasumJA.IdMR_TSMF;
                            itemTransak.dblKonsul = 0;
                            itemTransak.dblVisite = 0;
                            itemTransak.dblOperasi = fetchKasumJA.tunainya;
                            itemTransak.dblTindakan = 0;
                            itemTransak.dblDiagelect = 0;
                            itemTransak.dblPemRK = 0;

                            grpTransak.Add(itemTransak);

                        } /* EOF foreach (var fetchKasumJA in KasumJA) */
                    }

                } /* EOF if (grpTransak.Count > 0) */

            } /* EOF if(grpLstKasum.Count > 0) */

            intWaktuLoad = 0;
            intPenandaProses = 2;

            ///* QUERY ASKESGAKIN*/
            //this.strQuerySQL = " SELECT  " +
            //                        "BL_TRANSAKSI.Regbilling, " +                                            //0
            //                        "MR_PASIEN.Nama, " +                                                     //1
            //                        "MR_TRUANGAN.ruangan, " +                                                //2
            //                        "BL_TRANSAKSI.Jumlah, " +                                                //3
            //                        "BL_TRANSAKSI.subsidi, " +                                               //4
            //                        "BL_TRANSAKSI.tunai, " +                                                 //5
            //                        "BL_TRANSAKSIDETAIL.Idbl_komponen, " +                                   //6
            //                        "BL_TRANSAKSIDETAIL.Nilai, " +                                           //7
            //                        "BL_TRANSAKSIDETAIL.Ringan, " +                                          //8
            //                        "BL_KELTARIP.urutan, " +                                                 //9
            //                        "BL_KELTARIP.rekapjp," +                                                 //10
            //                        "BL_TRANSAKSIDETAIL.Nilai - BL_TRANSAKSIDETAIL.Ringan as tunainya , " +  //11
            //                        "BL_TRANSAKSIDETAIL.Noambil, " +                                         //12
            //                        "BL_TRANSAKSIDETAIL.tglambil, " +                                        //13
            //                        "BL_KELTARIP.Idbl_keltarip, " +                                          //14
            //                        "BL_KELTARIP.Lapjp, " +                                                  //15
            //                        "BL_TRANSAKSI.idmr_tsmf, " +                                             //16
            //                        "MR_SMFTARIP.idmr_tupf, " +                                              //17
            //                        "BL_TRANSAKSI.idbl_tarip, " +                                            //18
            //                        "BL_TRANSAKSI.uraiantarip, " +                                           //19
            //                        "BL_TRANSAKSI.jml_kasus_tarip, " +                                       //20
            //                        "BL_TRANSAKSI.idbl_transaksi, " +                                        //21
            //                        "BL_KASASKES.Idbl_Pembayaran, " +                                        //22
            //                        "BL_TRANSAKSI.Tgltransaksi, " +                                          //23
            //                        "BL_KASASKES.Tanggal, " +                                                //24
            //                        "BL_TARIP.Idmr_jeniskelas, " +                                           //25
            //                        "BL_TRANSAKSI.Idmr_truangan, " +                                         //26
            //                        "BL_TRANSAKSIDETAIL.Idmr_dokter, " +                                             //27
            //                        "MR_DOKTER.Nama " +                                                     //28
            //                   " FROM BL_KELTARIP With (nolock)  " +
            //                   " INNER JOIN BL_TRANSAKSI " +
            //                   " INNER JOIN BL_TRANSAKSIDETAIL " +
            //                        "ON BL_TRANSAKSI.idbl_transaksi = BL_TRANSAKSIDETAIL.Idbl_transaksi " +
            //                   " INNER JOIN BL_TARIP " +
            //                        "ON BL_TRANSAKSI.idbl_tarip = BL_TARIP.IdBl_tarip " +
            //                        "ON BL_KELTARIP.Idbl_keltarip = BL_TARIP.Idbl_keltarip " +
            //                   " INNER JOIN MR_SMFTARIP " +
            //                        "ON BL_TRANSAKSI.idmr_tsmf = MR_SMFTARIP.idmr_tsmf " +
            //                   " INNER JOIN BL_KASASKES " +
            //                        "ON BL_TRANSAKSI.idbl_pembayaran = BL_KASASKES.Idbl_Pembayaran " +
            //                            "AND BL_TRANSAKSI.idmr_mutasipasien = BL_KASASKES.idmr_mutasipasien " +
            //                   " INNER JOIN MR_PASIEN " +
            //                        "ON BL_KASASKES.Idmr_pasien = MR_PASIEN.IDMR_PASIEN " +
            //                   " INNER JOIN MR_TRUANGAN " +
            //                        "ON BL_KASASKES.Idmr_truangan = MR_TRUANGAN.idmr_truangan " +
            //                   " INNER JOIN MR_SJASKES " +
            //                        "ON BL_KASASKES.idmr_mutasipasien = MR_SJASKES.idmr_mutasipasien " +
            //                   "INNER JOIN MR_DOKTER " +
            //                        "ON MR_DOKTER.Idmr_dokter = BL_TRANSAKSIDETAIL.Idmr_dokter " +
            //                   " WHERE (BL_TRANSAKSI.Batal <> 'Y') " +
            //                      " AND (BL_KASASKES.Batal = '') " +
            //                      " AND (MR_SJASKES.BATAL = '') " +
            //                      " AND MR_SJASKES.idmr_tstatus = 'ASKESGAKIN' " +
            //                      " AND (BL_TRANSAKSIDETAIL.Idbl_komponen <> 'JASA SARANA') " +
            //                      " AND BL_KASASKES.Tanggal BETWEEN '" + dtpFilterTgl1.Value.ToString("MM/dd/yyyy 00:00:00") +
            //                        "' and '" + dtpFilterTgl2.Value.ToString("MM/dd/yyyy 23:59:59") + "' " +
            //                      " AND BL_TARIP.pisahsetor = '' AND BL_KASASKES.jumlah > 0 " +
            //                      " AND BL_TRANSAKSIDETAIL.noambil <> 999 " +
            //                      " AND BL_TRANSAKSI.idmr_tsmf <> 'DARAH' and BL_TRANSAKSI.idmr_tsmf <> 'PENDORONG'" +
            //                      " AND BL_TRANSAKSI.idmr_tsmf <> 'OBAT/ALKES-FARMASI' " +
            //                      " AND BL_TRANSAKSI.idmr_tsmf <> 'OBAT/ALKES-KPRI'" +
            //                      " AND BL_TRANSAKSI.idbl_pembayaran > 0 AND BL_KELTARIP.Lapjp <> '-'";

            //conn = modDb.pbconnKoneksiSQL(ref strErr);
            //if (strErr != "")
            //{
            //    tmrBlink.Enabled = false;
            //    tmrBlink.Stop();
            //    lblInfoPencarian.SafeControlInvoke(Label => lblInfoPencarian.Visible = false);
            //    modMsg.pvDlgErr(modMsg.IS_DEV, strErr, modMsg.DB_CON, modMsg.TITLE_ERR);
            //    return;
            //}

            //reader = modDb.pbreaderSQL(conn, strQuerySQL, ref strErr);
            //if (strErr != "")
            //{
            //    tmrBlink.Enabled = false;
            //    tmrBlink.Stop();
            //    lblInfoPencarian.SafeControlInvoke(Label => lblInfoPencarian.Visible = false);
            //    modMsg.pvDlgErr(modMsg.IS_DEV, strErr, modMsg.DB_GET, modMsg.TITLE_ERR);
            //    conn.Close();
            //    return;
            //}

            //if (reader.HasRows)
            //{
            //    while (reader.Read())
            //    {
            //        lstKASASKIN itemKASASKIN = new lstKASASKIN();

            //        itemKASASKIN.strRegBilling = modMain.pbstrgetCol(reader, 0, ref strErr, "");
            //        itemKASASKIN.strNama = modMain.pbstrgetCol(reader, 1, ref strErr, "");
            //        itemKASASKIN.strRuangan = modMain.pbstrgetCol(reader, 2, ref strErr, "");
            //        itemKASASKIN.dblJumlah = Convert.ToDouble(modMain.pbstrgetCol(reader, 3, ref strErr, ""));
            //        itemKASASKIN.dblSubsidi = Convert.ToDouble(modMain.pbstrgetCol(reader, 4, ref strErr, ""));
            //        itemKASASKIN.dblTunai = Convert.ToDouble(modMain.pbstrgetCol(reader, 5, ref strErr, ""));
            //        itemKASASKIN.strIdBl_Komponen = modMain.pbstrgetCol(reader, 6, ref strErr, "");
            //        itemKASASKIN.dblNilai = Convert.ToDouble(modMain.pbstrgetCol(reader, 7, ref strErr, ""));
            //        itemKASASKIN.dblRingan = Convert.ToDouble(modMain.pbstrgetCol(reader, 8, ref strErr, ""));
            //        itemKASASKIN.dblUrutan = Convert.ToDouble(modMain.pbstrgetCol(reader, 9, ref strErr, ""));
            //        itemKASASKIN.strRekapJp = modMain.pbstrgetCol(reader, 10, ref strErr, "");
            //        itemKASASKIN.dblTunainya = Convert.ToDouble(modMain.pbstrgetCol(reader, 11, ref strErr, ""));
            //        itemKASASKIN.dblNoAmbil = Convert.ToDouble(modMain.pbstrgetCol(reader, 12, ref strErr, ""));
            //        itemKASASKIN.dtTglAmbil = Convert.ToDateTime(modMain.pbstrgetCol(reader, 13, ref strErr, ""));
            //        itemKASASKIN.strIdBl_KelTarip = modMain.pbstrgetCol(reader, 14, ref strErr, "");
            //        itemKASASKIN.strLapJP = modMain.pbstrgetCol(reader, 15, ref strErr, "");
            //        itemKASASKIN.strIdMR_TSMF = modMain.pbstrgetCol(reader, 16, ref strErr, "");
            //        itemKASASKIN.strIdMR_TUPF = modMain.pbstrgetCol(reader, 17, ref strErr, "");
            //        itemKASASKIN.strIdBl_Tarip = modMain.pbstrgetCol(reader, 18, ref strErr, "");
            //        itemKASASKIN.strUraianTarip = modMain.pbstrgetCol(reader, 19, ref strErr, "");
            //        itemKASASKIN.dblJumlahKasusTarip = Convert.ToDouble(modMain.pbstrgetCol(reader, 20, ref strErr, ""));
            //        itemKASASKIN.strIdBl_Transaksi = modMain.pbstrgetCol(reader, 21, ref strErr, "");
            //        itemKASASKIN.strIdBl_Pembayaran = modMain.pbstrgetCol(reader, 22, ref strErr, "");
            //        itemKASASKIN.dtTglTransaksi = Convert.ToDateTime(modMain.pbstrgetCol(reader, 23, ref strErr, ""));
            //        itemKASASKIN.dtTgl = Convert.ToDateTime(modMain.pbstrgetCol(reader, 24, ref strErr, ""));
            //        itemKASASKIN.strIdMR_JenisKelas = modMain.pbstrgetCol(reader, 25, ref strErr, "");
            //        itemKASASKIN.strIdMR_Ruangan = modMain.pbstrgetCol(reader, 26, ref strErr, "");
            //        itemKASASKIN.strIdMR_Dokter = modMain.pbstrgetCol(reader, 27, ref strErr, "");
            //        itemKASASKIN.strNamaDokter = modMain.pbstrgetCol(reader, 28, ref strErr, "");

            //        grpLstKASASKIN.Add(itemKASASKIN);
            //    }
            //}
            //reader.Close();
            //conn.Close();

            ////MessageBox.Show(grpLstKASASKIN.Count.ToString());

            //if (grpLstKASASKIN.Count > 0)
            //{

            //    var KaskinJP = (from fetch in grpLstKASASKIN
            //                   where (fetch.strIdBl_Komponen == "JASA PELAYANAN" && fetch.dblTunainya > 0)
            //                   group fetch by new
            //                   {
            //                       fetch.strRegBilling,
            //                       fetch.strNama,
            //                       fetch.strIdBl_Komponen,
            //                       fetch.strLapJP,
            //                       fetch.strIdMR_TUPF,
            //                       fetch.strIdMR_TSMF,
            //                       fetch.strRuangan
            //                   } into groupData
            //                   select new
            //                   {
            //                       regBilling = groupData.Key.strRegBilling,
            //                       Nama = groupData.Key.strNama,
            //                       Ruangan = groupData.Key.strRuangan,
            //                       TUPF = groupData.Key.strIdMR_TUPF,
            //                       IdBl_Komponen = groupData.Key.strIdBl_Komponen,
            //                       IdMR_TSMF = groupData.Key.strIdMR_TSMF,
            //                       tunainya = groupData.Sum(fetchKasum => fetchKasum.dblTunainya),
            //                       LapJP = groupData.Key.strLapJP
            //                   }).OrderBy(groupData => groupData.regBilling).ToList();

            //    var KaskinJA = (from fetch in grpLstKASASKIN
            //                   where (fetch.strIdBl_Komponen != "JASA PELAYANAN" && fetch.dblTunainya > 0)
            //                   group fetch by new
            //                   {
            //                       fetch.strRegBilling,
            //                       fetch.strNama,
            //                       fetch.strIdBl_Komponen,
            //                       fetch.strLapJP,
            //                       fetch.strIdMR_TUPF,
            //                       fetch.strIdMR_TSMF,
            //                       fetch.strRuangan
            //                   } into groupData
            //                   select new
            //                   {
            //                       regBilling = groupData.Key.strRegBilling,
            //                       Nama = groupData.Key.strNama,
            //                       Ruangan = groupData.Key.strRuangan,
            //                       TUPF = groupData.Key.strIdMR_TUPF,
            //                       IdBl_Komponen = groupData.Key.strIdBl_Komponen,
            //                       IdMR_TSMF = groupData.Key.strIdMR_TSMF,
            //                       tunainya = groupData.Sum(fetchKasum => fetchKasum.dblTunainya),
            //                       LapJP = groupData.Key.strLapJP
            //                   }).OrderBy(groupData => groupData.regBilling).ToList();

            //    var reg = (from fetch in grpLstKASASKIN
            //               select new
            //               {
            //                   Regbilling = fetch.strRegBilling,
            //                   Nama = fetch.strNama,
            //                   Ruangan = fetch.strRuangan,
            //                   idmr_tupf = fetch.strIdMR_TUPF,
            //                   idmr_tsmf = fetch.strIdMR_TSMF
            //               }).Distinct().OrderBy(a => a.Regbilling).ToList();

            //    if (reg.Count > 0)
            //    {
            //        foreach (var fetch in reg)
            //        {
            //            lstTransak itemTransak = new lstTransak();
            //            itemTransak.strRegbilling = fetch.Regbilling;
            //            itemTransak.strNama = fetch.Nama;
            //            itemTransak.strRuangan = fetch.Ruangan;
            //            itemTransak.strUnit = fetch.idmr_tupf;
            //            itemTransak.strSMF = fetch.idmr_tsmf;
            //            itemTransak.dblKonsul = 0;
            //            itemTransak.dblVisite = 0;
            //            itemTransak.dblOperasi = 0;
            //            itemTransak.dblTindakan = 0;
            //            itemTransak.dblDiagelect = 0;
            //            itemTransak.dblPemRK = 0;
            //            grpTransak.Add(itemTransak);
            //        }
            //    }

            //    if (grpTransak.Count > 0)
            //    {
            //        /*JASA PELAYANAN*/
            //        foreach (var fetch in KaskinJP)
            //        {

            //            if (fetch.LapJP.Substring(0, 1) == "1")
            //            {
            //                int intUrut = 0;
            //                foreach (var fetchTransak in grpTransak)
            //                {
            //                    if (fetchTransak.strRegbilling == fetch.regBilling
            //                        && fetch.LapJP.Substring(0, 1) == "1"
            //                        && fetchTransak.strRuangan == fetch.Ruangan
            //                        && fetchTransak.strSMF == fetch.IdMR_TSMF)
            //                    {
            //                        grpTransak[intUrut].dblKonsul = grpTransak[intUrut].dblKonsul + fetch.tunainya;
            //                        //fetchTransak.dblKonsul = fetchTransak.dblKonsul + fetchKasumJP.tunainya;
            //                    }
            //                    intUrut++;
            //                } /* EOF foreach (var fetchTransak in grpTransak) */
            //            } /* EOF if (fetchKasumJP.LapJP.Substring(1, 1) == "1") */

            //            else if (fetch.LapJP.Substring(0, 1) == "2")
            //            {
            //                int intUrut = 0;
            //                foreach (var fetchTransak in grpTransak)
            //                {
            //                    if (fetchTransak.strRegbilling == fetch.regBilling
            //                        && fetch.LapJP.Substring(0, 1) == "2"
            //                        && fetchTransak.strRuangan == fetch.Ruangan
            //                        && fetchTransak.strSMF == fetch.IdMR_TSMF)
            //                    {
            //                        grpTransak[intUrut].dblVisite = grpTransak[intUrut].dblVisite + fetch.tunainya;
            //                    }
            //                    intUrut++;
            //                } /* EOF foreach (var fetchTransak in grpTransak) */

            //            } /* EOF else if (fetchKasumJP.LapJP.Substring(1, 1) == "2") */
            //            else if (fetch.LapJP.Substring(0, 1) == "3")
            //            {
            //                int intUrut = 0;
            //                foreach (var fetchTransak in grpTransak)
            //                {
            //                    if (fetchTransak.strRegbilling == fetch.regBilling
            //                        && fetch.LapJP.Substring(0, 1) == "3"
            //                        && fetchTransak.strRuangan == fetch.Ruangan
            //                        && fetchTransak.strSMF == fetch.IdMR_TSMF)
            //                    {
            //                        grpTransak[intUrut].dblOperasi = grpTransak[intUrut].dblOperasi + fetch.tunainya;
            //                    }
            //                    intUrut++;
            //                } /* EOF foreach (var fetchTransak in grpTransak) */

            //            } /* EOF else if (fetchKasumJP.LapJP.Substring(1, 1) == "3") */
            //            else if (fetch.LapJP.Substring(0, 1) == "4")
            //            {
            //                int intUrut = 0;
            //                foreach (var fetchTransak in grpTransak)
            //                {
            //                    if (fetchTransak.strRegbilling == fetch.regBilling
            //                        && fetch.LapJP.Substring(0, 1) == "4"
            //                        && fetchTransak.strRuangan == fetch.Ruangan
            //                        && fetchTransak.strSMF == fetch.IdMR_TSMF)
            //                    {
            //                        grpTransak[intUrut].dblTindakan = grpTransak[intUrut].dblTindakan + fetch.tunainya;
            //                    }
            //                    intUrut++;
            //                } /* EOF foreach (var fetchTransak in grpTransak) */

            //            } /* EOF else if (fetchKasumJP.LapJP.Substring(1, 1) == "4") */
            //            else if (fetch.LapJP.Substring(0, 1) == "5")
            //            {
            //                int intUrut = 0;
            //                foreach (var fetchTransak in grpTransak)
            //                {
            //                    if (fetchTransak.strRegbilling == fetch.regBilling
            //                        && fetch.LapJP.Substring(0, 1) == "5"
            //                        && fetchTransak.strRuangan == fetch.Ruangan
            //                        && fetchTransak.strSMF == fetch.IdMR_TSMF)
            //                    {
            //                        grpTransak[intUrut].dblDiagelect = grpTransak[intUrut].dblDiagelect + fetch.tunainya;
            //                    }
            //                    intUrut++;
            //                } /* EOF foreach (var fetchTransak in grpTransak) */

            //            } /* EOF else if (fetchKasumJP.LapJP.Substring(1, 1) == "5") */
            //            else if (fetch.LapJP.Substring(0, 1) == "6")
            //            {
            //                int intUrut = 0;
            //                foreach (var fetchTransak in grpTransak)
            //                {
            //                    if (fetchTransak.strRegbilling == fetch.regBilling
            //                        && fetch.LapJP.Substring(0, 1) == "6"
            //                        && fetchTransak.strRuangan == fetch.Ruangan
            //                        && fetchTransak.strSMF == fetch.IdMR_TSMF)
            //                    {
            //                        grpTransak[intUrut].dblPemRK = grpTransak[intUrut].dblPemRK + fetch.tunainya;
            //                    }
            //                    intUrut++;
            //                } /* EOF foreach (var fetchTransak in grpTransak) */

            //            } /* EOF else if (fetchKasumJP.LapJP.Substring(1, 1) == "6") */

            //            /* 2 SAMPAI 6 */

            //        } /* EOF foreach (var fetchKasumJP in KasumJP) */

            //        /*JASA ANASTHESI*/
            //        foreach (var fetch in KaskinJA)
            //        {

            //            lstTransak itemTransak = new lstTransak();
            //            itemTransak.strRegbilling = fetch.regBilling;
            //            itemTransak.strNama = fetch.Nama;
            //            itemTransak.strRuangan = fetch.Ruangan;
            //            itemTransak.strUnit = "ANASTHESI";
            //            itemTransak.strSMF = fetch.IdMR_TSMF;
            //            itemTransak.dblKonsul = 0;
            //            itemTransak.dblVisite = 0;
            //            itemTransak.dblOperasi = fetch.tunainya;
            //            itemTransak.dblTindakan = 0;
            //            itemTransak.dblDiagelect = 0;
            //            itemTransak.dblPemRK = 0;

            //            grpTransak.Add(itemTransak);

            //        } /* EOF foreach (var fetchKasumJA in KasumJA) */

            //    } /* EOF if (grpTransak.Count > 0) */

            //} /* EOF  if (grpLstKASASKIN.Count > 0) */

            intWaktuLoad = 0;
            intPenandaProses = 3;

            /* QUERY ASKES JAMKESMAS*/
            this.strQuerySQL = "SELECT  " +
                                    "BL_TRANSAKSI.Regbilling, " +                                            //0
                                    "MR_PASIEN.Nama, " +                                                     //1
                                    "MR_TRUANGAN.ruangan, " +                                                //2
                                    "BL_TRANSAKSI.Jumlah, " +                                                //3
                                    "BL_TRANSAKSI.subsidi, " +                                               //4
                                    "BL_TRANSAKSI.tunai, " +                                                 //5
                                    "BL_TRANSAKSIDETAIL.Idbl_komponen, " +                                   //6
                                    "BL_TRANSAKSIDETAIL.Nilai, " +                                           //7
                                    "BL_TRANSAKSIDETAIL.Ringan, " +                                          //8
                                    "BL_KELTARIP.urutan, " +                                                 //9
                                    "BL_KELTARIP.rekapjp," +                                                 //10
                                    "BL_TRANSAKSIDETAIL.Nilai - BL_TRANSAKSIDETAIL.Ringan as tunainya , " +  //11
                                    "BL_TRANSAKSIDETAIL.Noambil," +                                          //12
                                    "BL_TRANSAKSIDETAIL.tglambil, " +                                        //13
                                    "BL_KELTARIP.Idbl_keltarip, " +                                          //14
                                    "BL_KELTARIP.Lapjp, " +                                                  //15
                                    "BL_TRANSAKSI.idmr_tsmf, " +                                             //16
                                    "MR_SMFTARIP.idmr_tupf, " +                                              //17
                                    "BL_TRANSAKSI.idbl_tarip, " +                                            //18
                                    "BL_TRANSAKSI.uraiantarip, " +                                           //19
                                    "BL_TRANSAKSI.jml_kasus_tarip, " +                                       //20
                                    "BL_TRANSAKSI.idbl_transaksi, " +                                        //21
                                    "BL_KASASKES.Idbl_Pembayaran, " +                                        //22
                                    "BL_TRANSAKSI.Tgltransaksi, " +                                          //23
                                    "BL_KASASKES.Tanggal, " +                                                //24
                                    "BL_TARIP.Idmr_jeniskelas, " +                                           //25
                                    "BL_TRANSAKSI.Idmr_truangan, " +                                         //26
                                    "MR_DOKTER.Idmr_dokter, " +                                             //27
                                    "MR_DOKTER.Nama " +                                                     //28
                               "FROM BL_KELTARIP With (nolock)  " +
                               "INNER JOIN BL_TRANSAKSI " +
                               "INNER JOIN BL_TRANSAKSIDETAIL " +
                                    "ON BL_TRANSAKSI.idbl_transaksi = BL_TRANSAKSIDETAIL.Idbl_transaksi " +
                               "INNER JOIN BL_TARIP " +
                                    "ON BL_TRANSAKSI.idbl_tarip = BL_TARIP.IdBl_tarip " +
                                    "ON BL_KELTARIP.Idbl_keltarip = BL_TARIP.Idbl_keltarip " +
                               "INNER JOIN MR_SMFTARIP " +
                                    "ON BL_TRANSAKSI.idmr_tsmf = MR_SMFTARIP.idmr_tsmf " +
                               "INNER JOIN BL_KASASKES " +
                                    "ON BL_TRANSAKSI.idbl_pembayaran = BL_KASASKES.Idbl_Pembayaran " +
                                    "AND BL_TRANSAKSI.idmr_mutasipasien = BL_KASASKES.idmr_mutasipasien " +
                               "INNER JOIN MR_PASIEN " +
                                    "ON BL_KASASKES.Idmr_pasien = MR_PASIEN.IDMR_PASIEN " +
                               "INNER JOIN MR_TRUANGAN " +
                                    "ON BL_KASASKES.Idmr_truangan = MR_TRUANGAN.idmr_truangan " +
                               "INNER JOIN MR_SJASKES " +
                                    "ON BL_KASASKES.idmr_mutasipasien = MR_SJASKES.idmr_mutasipasien " +
                               "INNER JOIN MR_DOKTER " +
                                    "ON MR_DOKTER.Idmr_dokter = BL_TRANSAKSIDETAIL.Idmr_dokter " +
                               "WHERE (BL_TRANSAKSI.Batal <> 'Y') AND (BL_KASASKES.Batal = '') " +
                                  " AND (MR_SJASKES.BATAL = '') AND MR_SJASKES.idmr_tstatus = 'ASKESJAMKESMAS' " +
                                  " AND (BL_TRANSAKSIDETAIL.Idbl_komponen <> 'JASA SARANA') " +
                                  " AND BL_KASASKES.Tanggal between '" + dtpFilterTgl1.Value.ToString("MM/dd/yyyy 00:00:00") +
                                    "' AND '" + dtpFilterTgl2.Value.ToString("MM/dd/yyyy 23:59:59") + "' " +
                                  " AND BL_TARIP.pisahsetor = '' and BL_KASASKES.jumlah > 0 " +
                                  " AND BL_TRANSAKSIDETAIL.noambil <> 999 " +
                                  " AND BL_TRANSAKSI.idmr_tsmf <> 'DARAH' AND BL_TRANSAKSI.idmr_tsmf <> 'PENDORONG'" +
                                  " AND BL_TRANSAKSI.idmr_tsmf <> 'OBAT/ALKES-FARMASI' " +
                                  " AND BL_TRANSAKSI.idmr_tsmf <> 'OBAT/ALKES-KPRI'" +
                                  " AND BL_TRANSAKSI.idbl_pembayaran > 0 and BL_KELTARIP.Lapjp <> '-'";

            conn = modDb.pbconnKoneksiSQL(ref strErr);
            if (strErr != "")
            {
                tmrBlink.Enabled = false;
                tmrBlink.Stop();
                lblInfoPencarian.SafeControlInvoke(Label => lblInfoPencarian.Visible = false);
                modMsg.pvDlgErr(modMsg.IS_DEV, strErr, modMsg.DB_CON, modMsg.TITLE_ERR);
                return;
            }

            reader = modDb.pbreaderSQL(conn, strQuerySQL, ref strErr);
            if (strErr != "")
            {
                tmrBlink.Enabled = false;
                tmrBlink.Stop();
                lblInfoPencarian.SafeControlInvoke(Label => lblInfoPencarian.Visible = false);
                modMsg.pvDlgErr(modMsg.IS_DEV, strErr, modMsg.DB_GET, modMsg.TITLE_ERR);
                conn.Close();
                return;
            }

            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    lstKASJKM itemKASJKM = new lstKASJKM();

                    itemKASJKM.strRegBilling = modMain.pbstrgetCol(reader, 0, ref strErr, "");
                    itemKASJKM.strNama = modMain.pbstrgetCol(reader, 1, ref strErr, "");
                    itemKASJKM.strRuangan = modMain.pbstrgetCol(reader, 2, ref strErr, "");
                    itemKASJKM.dblJumlah = Convert.ToDouble(modMain.pbstrgetCol(reader, 3, ref strErr, ""));
                    itemKASJKM.dblSubsidi = Convert.ToDouble(modMain.pbstrgetCol(reader, 4, ref strErr, ""));
                    itemKASJKM.dblTunai = Convert.ToDouble(modMain.pbstrgetCol(reader, 5, ref strErr, ""));
                    itemKASJKM.strIdBl_Komponen = modMain.pbstrgetCol(reader, 6, ref strErr, "");
                    itemKASJKM.dblNilai = Convert.ToDouble(modMain.pbstrgetCol(reader, 7, ref strErr, ""));
                    itemKASJKM.dblRingan = Convert.ToDouble(modMain.pbstrgetCol(reader, 8, ref strErr, ""));
                    itemKASJKM.dblUrutan = Convert.ToDouble(modMain.pbstrgetCol(reader, 9, ref strErr, ""));
                    itemKASJKM.strRekapJp = modMain.pbstrgetCol(reader, 10, ref strErr, "");
                    itemKASJKM.dblTunainya = Convert.ToDouble(modMain.pbstrgetCol(reader, 11, ref strErr, ""));
                    itemKASJKM.dblNoAmbil = Convert.ToDouble(modMain.pbstrgetCol(reader, 12, ref strErr, ""));
                    itemKASJKM.dtTglAmbil = Convert.ToDateTime(modMain.pbstrgetCol(reader, 13, ref strErr, ""));
                    itemKASJKM.strIdBl_KelTarip = modMain.pbstrgetCol(reader, 14, ref strErr, "");
                    itemKASJKM.strLapJP = modMain.pbstrgetCol(reader, 15, ref strErr, "");
                    itemKASJKM.strIdMR_TSMF = modMain.pbstrgetCol(reader, 16, ref strErr, "");
                    itemKASJKM.strIdMR_TUPF = modMain.pbstrgetCol(reader, 17, ref strErr, "");
                    itemKASJKM.strIdBl_Tarip = modMain.pbstrgetCol(reader, 18, ref strErr, "");
                    itemKASJKM.strUraianTarip = modMain.pbstrgetCol(reader, 19, ref strErr, "");
                    itemKASJKM.dblJumlahKasusTarip = Convert.ToDouble(modMain.pbstrgetCol(reader, 20, ref strErr, ""));
                    itemKASJKM.strIdBl_Transaksi = modMain.pbstrgetCol(reader, 21, ref strErr, "");
                    itemKASJKM.strIdBl_Pembayaran = modMain.pbstrgetCol(reader, 22, ref strErr, "");
                    itemKASJKM.dtTglTransaksi = Convert.ToDateTime(modMain.pbstrgetCol(reader, 23, ref strErr, ""));
                    itemKASJKM.dtTgl = Convert.ToDateTime(modMain.pbstrgetCol(reader, 24, ref strErr, ""));
                    itemKASJKM.strIdMR_JenisKelas = modMain.pbstrgetCol(reader, 25, ref strErr, "");
                    itemKASJKM.strIdMR_Ruangan = modMain.pbstrgetCol(reader, 26, ref strErr, "");
                    itemKASJKM.strIdMR_Dokter = modMain.pbstrgetCol(reader, 27, ref strErr, "");
                    itemKASJKM.strNamaDokter = modMain.pbstrgetCol(reader, 28, ref strErr, "");

                    grpLstKASJKM.Add(itemKASJKM);
                }
            }

            reader.Close();
            conn.Close();

            if (grpLstKASJKM.Count > 0)
            {

                var KasJKMJP = (from fetch in grpLstKASJKM
                                where (fetch.strIdBl_Komponen == "JASA PELAYANAN" && fetch.dblTunainya > 0)
                                group fetch by new
                                {
                                    fetch.strRegBilling,
                                    fetch.strNama,
                                    fetch.strIdBl_Komponen,
                                    fetch.strLapJP,
                                    fetch.strIdMR_TUPF,
                                    fetch.strIdMR_TSMF,
                                    fetch.strRuangan
                                } into groupData
                                select new
                                {
                                    regBilling = groupData.Key.strRegBilling,
                                    Nama = groupData.Key.strNama,
                                    Ruangan = groupData.Key.strRuangan,
                                    TUPF = groupData.Key.strIdMR_TUPF,
                                    IdBl_Komponen = groupData.Key.strIdBl_Komponen,
                                    IdMR_TSMF = groupData.Key.strIdMR_TSMF,
                                    tunainya = groupData.Sum(fetchKasum => fetchKasum.dblTunainya),
                                    LapJP = groupData.Key.strLapJP
                                }).OrderBy(groupData => groupData.regBilling).ToList();

                var KasJKMJA = (from fetch in grpLstKASJKM
                                where (fetch.strIdBl_Komponen != "JASA PELAYANAN" && fetch.dblTunainya > 0)
                                group fetch by new
                                {
                                    fetch.strRegBilling,
                                    fetch.strNama,
                                    fetch.strIdBl_Komponen,
                                    fetch.strLapJP,
                                    fetch.strIdMR_TUPF,
                                    fetch.strIdMR_TSMF,
                                    fetch.strRuangan
                                } into groupData
                                select new
                                {
                                    regBilling = groupData.Key.strRegBilling,
                                    Nama = groupData.Key.strNama,
                                    Ruangan = groupData.Key.strRuangan,
                                    TUPF = groupData.Key.strIdMR_TUPF,
                                    IdBl_Komponen = groupData.Key.strIdBl_Komponen,
                                    IdMR_TSMF = groupData.Key.strIdMR_TSMF,
                                    tunainya = groupData.Sum(fetchKasum => fetchKasum.dblTunainya),
                                    LapJP = groupData.Key.strLapJP
                                }).OrderBy(groupData => groupData.regBilling).ToList();

                var reg = (from fetch in grpLstKASJKM
                           select new
                           {
                               Regbilling = fetch.strRegBilling,
                               Nama = fetch.strNama,
                               Ruangan = fetch.strRuangan,
                               idmr_tupf = fetch.strIdMR_TUPF,
                               idmr_tsmf = fetch.strIdMR_TSMF
                           }).Distinct().OrderBy(a => a.Regbilling).ToList();

                if (reg.Count > 0)
                {
                    foreach (var fetch in reg)
                    {
                        lstTransak itemTransak = new lstTransak();
                        itemTransak.strRegbilling = fetch.Regbilling;
                        itemTransak.strNama = fetch.Nama;
                        itemTransak.strRuangan = fetch.Ruangan;
                        itemTransak.strUnit = fetch.idmr_tupf;
                        itemTransak.strSMF = fetch.idmr_tsmf;
                        itemTransak.dblKonsul = 0;
                        itemTransak.dblVisite = 0;
                        itemTransak.dblOperasi = 0;
                        itemTransak.dblTindakan = 0;
                        itemTransak.dblDiagelect = 0;
                        itemTransak.dblPemRK = 0;
                        grpTransak.Add(itemTransak);
                    }
                }

                if (grpTransak.Count > 0)
                {
                    /*JASA PELAYANAN*/
                    foreach (var fetch in KasJKMJP)
                    {

                        if (fetch.LapJP.Substring(0, 1) == "1")
                        {
                            int intUrut = 0;
                            foreach (var fetchTransak in grpTransak)
                            {
                                if (fetchTransak.strRegbilling == fetch.regBilling
                                    && fetch.LapJP.Substring(0, 1) == "1"
                                    && fetchTransak.strRuangan == fetch.Ruangan
                                    && fetchTransak.strSMF == fetch.IdMR_TSMF)
                                {
                                    grpTransak[intUrut].dblKonsul = grpTransak[intUrut].dblKonsul + fetch.tunainya;
                                    //fetchTransak.dblKonsul = fetchTransak.dblKonsul + fetchKasumJP.tunainya;
                                }
                                intUrut++;
                            } /* EOF foreach (var fetchTransak in grpTransak) */
                        } /* EOF if (fetchKasumJP.LapJP.Substring(1, 1) == "1") */

                        else if (fetch.LapJP.Substring(0, 1) == "2")
                        {
                            int intUrut = 0;
                            foreach (var fetchTransak in grpTransak)
                            {
                                if (fetchTransak.strRegbilling == fetch.regBilling
                                    && fetch.LapJP.Substring(0, 1) == "2"
                                    && fetchTransak.strRuangan == fetch.Ruangan
                                    && fetchTransak.strSMF == fetch.IdMR_TSMF)
                                {
                                    grpTransak[intUrut].dblVisite = grpTransak[intUrut].dblVisite + fetch.tunainya;
                                }
                                intUrut++;
                            } /* EOF foreach (var fetchTransak in grpTransak) */

                        } /* EOF else if (fetchKasumJP.LapJP.Substring(1, 1) == "2") */
                        else if (fetch.LapJP.Substring(0, 1) == "3")
                        {
                            int intUrut = 0;
                            foreach (var fetchTransak in grpTransak)
                            {
                                if (fetchTransak.strRegbilling == fetch.regBilling
                                    && fetch.LapJP.Substring(0, 1) == "3"
                                    && fetchTransak.strRuangan == fetch.Ruangan
                                    && fetchTransak.strSMF == fetch.IdMR_TSMF)
                                {
                                    grpTransak[intUrut].dblOperasi = grpTransak[intUrut].dblOperasi + fetch.tunainya;
                                }
                                intUrut++;
                            } /* EOF foreach (var fetchTransak in grpTransak) */

                        } /* EOF else if (fetchKasumJP.LapJP.Substring(1, 1) == "3") */
                        else if (fetch.LapJP.Substring(0, 1) == "4")
                        {
                            int intUrut = 0;
                            foreach (var fetchTransak in grpTransak)
                            {
                                if (fetchTransak.strRegbilling == fetch.regBilling
                                    && fetch.LapJP.Substring(0, 1) == "4"
                                    && fetchTransak.strRuangan == fetch.Ruangan
                                    && fetchTransak.strSMF == fetch.IdMR_TSMF)
                                {
                                    grpTransak[intUrut].dblTindakan = grpTransak[intUrut].dblTindakan + fetch.tunainya;
                                }
                                intUrut++;
                            } /* EOF foreach (var fetchTransak in grpTransak) */

                        } /* EOF else if (fetchKasumJP.LapJP.Substring(1, 1) == "4") */
                        else if (fetch.LapJP.Substring(0, 1) == "5")
                        {
                            int intUrut = 0;
                            foreach (var fetchTransak in grpTransak)
                            {
                                if (fetchTransak.strRegbilling == fetch.regBilling
                                    && fetch.LapJP.Substring(0, 1) == "5"
                                    && fetchTransak.strRuangan == fetch.Ruangan
                                    && fetchTransak.strSMF == fetch.IdMR_TSMF)
                                {
                                    grpTransak[intUrut].dblDiagelect = grpTransak[intUrut].dblDiagelect + fetch.tunainya;
                                }
                                intUrut++;
                            } /* EOF foreach (var fetchTransak in grpTransak) */

                        } /* EOF else if (fetchKasumJP.LapJP.Substring(1, 1) == "5") */
                        else if (fetch.LapJP.Substring(0, 1) == "6")
                        {
                            int intUrut = 0;
                            foreach (var fetchTransak in grpTransak)
                            {
                                if (fetchTransak.strRegbilling == fetch.regBilling
                                    && fetch.LapJP.Substring(0, 1) == "6"
                                    && fetchTransak.strRuangan == fetch.Ruangan
                                    && fetchTransak.strSMF == fetch.IdMR_TSMF)
                                {
                                    grpTransak[intUrut].dblPemRK = grpTransak[intUrut].dblPemRK + fetch.tunainya;
                                }
                                intUrut++;
                            } /* EOF foreach (var fetchTransak in grpTransak) */

                        } /* EOF else if (fetchKasumJP.LapJP.Substring(1, 1) == "6") */

                        /* 2 SAMPAI 6 */

                    } /* EOF foreach (var fetchKasumJP in KasumJP) */

                    /*JASA ANASTHESI*/
                    foreach (var fetch in KasJKMJA)
                    {

                        lstTransak itemTransak = new lstTransak();
                        itemTransak.strRegbilling = fetch.regBilling;
                        itemTransak.strNama = fetch.Nama;
                        itemTransak.strRuangan = fetch.Ruangan;
                        itemTransak.strUnit = "ANASTHESI";
                        itemTransak.strSMF = fetch.IdMR_TSMF;
                        itemTransak.dblKonsul = 0;
                        itemTransak.dblVisite = 0;
                        itemTransak.dblOperasi = fetch.tunainya;
                        itemTransak.dblTindakan = 0;
                        itemTransak.dblDiagelect = 0;
                        itemTransak.dblPemRK = 0;

                        grpTransak.Add(itemTransak);

                    } /* EOF foreach (var fetch in KasJKMJA) */

                } /* EOF if (grpTransak.Count > 0) */

            } /* EOF  if (grpLstKasJKM.Count > 0) */

            intWaktuLoad = 0;
            intPenandaProses = 4;

            /* QUERY ASKES JAMKESDA*/
            this.strQuerySQL = "SELECT  " +
                                    "BL_TRANSAKSI.Regbilling, " +                                            //0
                                    "MR_PASIEN.Nama, " +                                                     //1
                                    "MR_TRUANGAN.ruangan, " +                                               //2
                                    "BL_TRANSAKSI.Jumlah, " +                                                //3
                                    "BL_TRANSAKSI.subsidi, " +                                               //4
                                    "BL_TRANSAKSI.tunai, " +                                                //5
                                    "BL_TRANSAKSIDETAIL.Idbl_komponen, " +                                   //6
                                    "BL_TRANSAKSIDETAIL.Nilai, " +                                          //7
                                    "BL_TRANSAKSIDETAIL.Ringan, " +                                          //8
                                    "BL_KELTARIP.urutan, " +                                                 //9
                                    "BL_KELTARIP.rekapjp," +                                                //10
                                    "BL_TRANSAKSIDETAIL.Nilai - BL_TRANSAKSIDETAIL.Ringan as tunainya , " + //11
                                    "BL_TRANSAKSIDETAIL.Noambil," +                                          //12
                                    "BL_TRANSAKSIDETAIL.tglambil, " +                                       //13
                                    "BL_KELTARIP.Idbl_keltarip, " +                                          //14
                                    "BL_KELTARIP.Lapjp, " +                                                  //15
                                    "BL_TRANSAKSI.idmr_tsmf, " +                                            //16
                                    "MR_SMFTARIP.idmr_tupf, " +                                              //17
                                    "BL_TRANSAKSI.idbl_tarip, " +                                            //18
                                    "BL_TRANSAKSI.uraiantarip, " +                                          //19
                                    "BL_TRANSAKSI.jml_kasus_tarip, " +                                       //20
                                    "BL_TRANSAKSI.idbl_transaksi, " +                                       //21
                                    "BL_KASASKES.Idbl_Pembayaran, " +                                        //22
                                    "BL_TRANSAKSI.Tgltransaksi, " +                                          //23
                                    "BL_KASASKES.Tanggal, " +                                               //24
                                    "BL_TARIP.Idmr_jeniskelas, " +                                           //25
                                    "BL_TRANSAKSI.Idmr_truangan, " +                                        //26
                                    "MR_DOKTER.Idmr_dokter, " +                                             //27
                                    "MR_DOKTER.Nama " +                                                     //28
                                " FROM BL_KELTARIP With (nolock)  " +
                                " INNER JOIN BL_TRANSAKSI " +
                                " INNER JOIN BL_TRANSAKSIDETAIL "+
                                        "ON BL_TRANSAKSI.idbl_transaksi = BL_TRANSAKSIDETAIL.Idbl_transaksi " +
                                " INNER JOIN BL_TARIP " +
                                        "ON BL_TRANSAKSI.idbl_tarip = BL_TARIP.IdBl_tarip " +
                                        "ON BL_KELTARIP.Idbl_keltarip = BL_TARIP.Idbl_keltarip " +
                                " INNER JOIN MR_SMFTARIP " +
                                        "ON BL_TRANSAKSI.idmr_tsmf = MR_SMFTARIP.idmr_tsmf " +
                                " INNER JOIN BL_KASASKES " +
                                        "ON BL_TRANSAKSI.idbl_pembayaran = BL_KASASKES.Idbl_Pembayaran " +
                                  " AND BL_TRANSAKSI.idmr_mutasipasien = BL_KASASKES.idmr_mutasipasien " +
                                " INNER JOIN MR_PASIEN ON BL_KASASKES.Idmr_pasien = MR_PASIEN.IDMR_PASIEN " +
                                " INNER JOIN MR_TRUANGAN ON BL_KASASKES.Idmr_truangan = MR_TRUANGAN.idmr_truangan " +
                                " INNER JOIN MR_SJASKES ON BL_KASASKES.idmr_mutasipasien = MR_SJASKES.idmr_mutasipasien " +
                                "INNER JOIN MR_DOKTER " +
                                    "ON MR_DOKTER.Idmr_dokter = BL_TRANSAKSIDETAIL.Idmr_dokter " +
                                " WHERE (BL_TRANSAKSI.Batal <> 'Y') AND (BL_KASASKES.Batal = '') " +
                                  " AND (MR_SJASKES.BATAL = '') and MR_SJASKES.idmr_tstatus = 'ASKESJAMKESDA' " +
                                  " AND (BL_TRANSAKSIDETAIL.Idbl_komponen <> 'JASA SARANA') " +
                                  " AND BL_KASASKES.Tanggal between '" + dtpFilterTgl1.Value.ToString("MM/dd/yyyy 00:00:00") +
                                  "' and '" + dtpFilterTgl2.Value.ToString("MM/dd/yyyy 23:59:59") + "' " +
                                  " AND BL_TARIP.pisahsetor = '' AND BL_KASASKES.jumlah > 0 " +
                                  " AND BL_TRANSAKSIDETAIL.noambil <> 999 " +
                                  " AND BL_TRANSAKSI.idmr_tsmf <> 'DARAH' and BL_TRANSAKSI.idmr_tsmf <> 'PENDORONG'" +
                                  " AND BL_TRANSAKSI.idmr_tsmf <> 'OBAT/ALKES-FARMASI' " +
                                  " AND BL_TRANSAKSI.idmr_tsmf <> 'OBAT/ALKES-KPRI'" +
                                  " AND BL_TRANSAKSI.idbl_pembayaran > 0 and BL_KELTARIP.Lapjp <> '-'";

            conn = modDb.pbconnKoneksiSQL(ref strErr);
            if (strErr != "")
            {
                tmrBlink.Enabled = false;
                tmrBlink.Stop();
                lblInfoPencarian.SafeControlInvoke(Label => lblInfoPencarian.Visible = false);
                modMsg.pvDlgErr(modMsg.IS_DEV, strErr, modMsg.DB_CON, modMsg.TITLE_ERR);
                return;
            }

            reader = modDb.pbreaderSQL(conn, strQuerySQL, ref strErr);
            if (strErr != "")
            {
                tmrBlink.Enabled = false;
                tmrBlink.Stop();
                lblInfoPencarian.SafeControlInvoke(Label => lblInfoPencarian.Visible = false);
                modMsg.pvDlgErr(modMsg.IS_DEV, strErr, modMsg.DB_GET, modMsg.TITLE_ERR);
                conn.Close();
                return;
            }

            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    lstKASJKD itemKASJKD = new lstKASJKD();

                    itemKASJKD.strRegBilling = modMain.pbstrgetCol(reader, 0, ref strErr, "");
                    itemKASJKD.strNama = modMain.pbstrgetCol(reader, 1, ref strErr, "");
                    itemKASJKD.strRuangan = modMain.pbstrgetCol(reader, 2, ref strErr, "");
                    itemKASJKD.dblJumlah = Convert.ToDouble(modMain.pbstrgetCol(reader, 3, ref strErr, ""));
                    itemKASJKD.dblSubsidi = Convert.ToDouble(modMain.pbstrgetCol(reader, 4, ref strErr, ""));
                    itemKASJKD.dblTunai = Convert.ToDouble(modMain.pbstrgetCol(reader, 5, ref strErr, ""));
                    itemKASJKD.strIdBl_Komponen = modMain.pbstrgetCol(reader, 6, ref strErr, "");
                    itemKASJKD.dblNilai = Convert.ToDouble(modMain.pbstrgetCol(reader, 7, ref strErr, ""));
                    itemKASJKD.dblRingan = Convert.ToDouble(modMain.pbstrgetCol(reader, 8, ref strErr, ""));
                    itemKASJKD.dblUrutan = Convert.ToDouble(modMain.pbstrgetCol(reader, 9, ref strErr, ""));
                    itemKASJKD.strRekapJp = modMain.pbstrgetCol(reader, 10, ref strErr, "");
                    itemKASJKD.dblTunainya = Convert.ToDouble(modMain.pbstrgetCol(reader, 11, ref strErr, ""));
                    itemKASJKD.dblNoAmbil = Convert.ToDouble(modMain.pbstrgetCol(reader, 12, ref strErr, ""));
                    itemKASJKD.dtTglAmbil = Convert.ToDateTime(modMain.pbstrgetCol(reader, 13, ref strErr, ""));
                    itemKASJKD.strIdBl_KelTarip = modMain.pbstrgetCol(reader, 14, ref strErr, "");
                    itemKASJKD.strLapJP = modMain.pbstrgetCol(reader, 15, ref strErr, "");
                    itemKASJKD.strIdMR_TSMF = modMain.pbstrgetCol(reader, 16, ref strErr, "");
                    itemKASJKD.strIdMR_TUPF = modMain.pbstrgetCol(reader, 17, ref strErr, "");
                    itemKASJKD.strIdBl_Tarip = modMain.pbstrgetCol(reader, 18, ref strErr, "");
                    itemKASJKD.strUraianTarip = modMain.pbstrgetCol(reader, 19, ref strErr, "");
                    itemKASJKD.dblJumlahKasusTarip = Convert.ToDouble(modMain.pbstrgetCol(reader, 20, ref strErr, ""));
                    itemKASJKD.strIdBl_Transaksi = modMain.pbstrgetCol(reader, 21, ref strErr, "");
                    itemKASJKD.strIdBl_Pembayaran = modMain.pbstrgetCol(reader, 22, ref strErr, "");
                    itemKASJKD.dtTglTransaksi = Convert.ToDateTime(modMain.pbstrgetCol(reader, 23, ref strErr, ""));
                    itemKASJKD.dtTgl = Convert.ToDateTime(modMain.pbstrgetCol(reader, 24, ref strErr, ""));
                    itemKASJKD.strIdMR_JenisKelas = modMain.pbstrgetCol(reader, 25, ref strErr, "");
                    itemKASJKD.strIdMR_Ruangan = modMain.pbstrgetCol(reader, 26, ref strErr, "");
                    itemKASJKD.strIdMR_Dokter = modMain.pbstrgetCol(reader, 27, ref strErr, "");
                    itemKASJKD.strNamaDokter = modMain.pbstrgetCol(reader, 28, ref strErr, "");

                    grpLstKASJKD.Add(itemKASJKD);
                }
            }

            reader.Close();
            conn.Close();

            if (grpLstKASJKD.Count > 0)
            {

                var KasJKDJP = (from fetch in grpLstKASJKD
                                where (fetch.strIdBl_Komponen == "JASA PELAYANAN" && fetch.dblTunainya > 0)
                                group fetch by new
                                {
                                    fetch.strRegBilling,
                                    fetch.strNama,
                                    fetch.strIdBl_Komponen,
                                    fetch.strLapJP,
                                    fetch.strIdMR_TUPF,
                                    fetch.strIdMR_TSMF,
                                    fetch.strRuangan
                                } into groupData
                                select new
                                {
                                    regBilling = groupData.Key.strRegBilling,
                                    Nama = groupData.Key.strNama,
                                    Ruangan = groupData.Key.strRuangan,
                                    TUPF = groupData.Key.strIdMR_TUPF,
                                    IdBl_Komponen = groupData.Key.strIdBl_Komponen,
                                    IdMR_TSMF = groupData.Key.strIdMR_TSMF,
                                    tunainya = groupData.Sum(fetchKasum => fetchKasum.dblTunainya),
                                    LapJP = groupData.Key.strLapJP
                                }).OrderBy(groupData => groupData.regBilling).ToList();

                var KasJKDJA = (from fetch in grpLstKASJKD
                                where (fetch.strIdBl_Komponen != "JASA PELAYANAN" && fetch.dblTunainya > 0)
                                group fetch by new
                                {
                                    fetch.strRegBilling,
                                    fetch.strNama,
                                    fetch.strIdBl_Komponen,
                                    fetch.strLapJP,
                                    fetch.strIdMR_TUPF,
                                    fetch.strIdMR_TSMF,
                                    fetch.strRuangan
                                } into groupData
                                select new
                                {
                                    regBilling = groupData.Key.strRegBilling,
                                    Nama = groupData.Key.strNama,
                                    Ruangan = groupData.Key.strRuangan,
                                    TUPF = groupData.Key.strIdMR_TUPF,
                                    IdBl_Komponen = groupData.Key.strIdBl_Komponen,
                                    IdMR_TSMF = groupData.Key.strIdMR_TSMF,
                                    tunainya = groupData.Sum(fetchKasum => fetchKasum.dblTunainya),
                                    LapJP = groupData.Key.strLapJP
                                }).OrderBy(groupData => groupData.regBilling).ToList();

                var reg = (from fetch in grpLstKASJKD
                           select new
                           {
                               Regbilling = fetch.strRegBilling,
                               Nama = fetch.strNama,
                               Ruangan = fetch.strRuangan,
                               idmr_tupf = fetch.strIdMR_TUPF,
                               idmr_tsmf = fetch.strIdMR_TSMF
                           }).Distinct().OrderBy(a => a.Regbilling).ToList();

                if (reg.Count > 0)
                {
                    foreach (var fetch in reg)
                    {
                        lstTransak itemTransak = new lstTransak();
                        itemTransak.strRegbilling = fetch.Regbilling;
                        itemTransak.strNama = fetch.Nama;
                        itemTransak.strRuangan = fetch.Ruangan;
                        itemTransak.strUnit = fetch.idmr_tupf;
                        itemTransak.strSMF = fetch.idmr_tsmf;
                        itemTransak.dblKonsul = 0;
                        itemTransak.dblVisite = 0;
                        itemTransak.dblOperasi = 0;
                        itemTransak.dblTindakan = 0;
                        itemTransak.dblDiagelect = 0;
                        itemTransak.dblPemRK = 0;
                        grpTransak.Add(itemTransak);
                    }
                }

                if (grpTransak.Count > 0)
                {
                    /*JASA PELAYANAN*/
                    foreach (var fetch in KasJKDJP)
                    {

                        if (fetch.LapJP.Substring(0, 1) == "1")
                        {
                            int intUrut = 0;
                            foreach (var fetchTransak in grpTransak)
                            {
                                if (fetchTransak.strRegbilling == fetch.regBilling
                                    && fetch.LapJP.Substring(0, 1) == "1"
                                    && fetchTransak.strRuangan == fetch.Ruangan
                                    && fetchTransak.strSMF == fetch.IdMR_TSMF)
                                {
                                    grpTransak[intUrut].dblKonsul = grpTransak[intUrut].dblKonsul + fetch.tunainya;
                                    //fetchTransak.dblKonsul = fetchTransak.dblKonsul + fetchKasumJP.tunainya;
                                }
                                intUrut++;
                            } /* EOF foreach (var fetchTransak in grpTransak) */
                        } /* EOF if (fetchKasumJP.LapJP.Substring(1, 1) == "1") */

                        else if (fetch.LapJP.Substring(0, 1) == "2")
                        {
                            int intUrut = 0;
                            foreach (var fetchTransak in grpTransak)
                            {
                                if (fetchTransak.strRegbilling == fetch.regBilling
                                    && fetch.LapJP.Substring(0, 1) == "2"
                                    && fetchTransak.strRuangan == fetch.Ruangan
                                    && fetchTransak.strSMF == fetch.IdMR_TSMF)
                                {
                                    grpTransak[intUrut].dblVisite = grpTransak[intUrut].dblVisite + fetch.tunainya;
                                }
                                intUrut++;
                            } /* EOF foreach (var fetchTransak in grpTransak) */

                        } /* EOF else if (fetchKasumJP.LapJP.Substring(1, 1) == "2") */
                        else if (fetch.LapJP.Substring(0, 1) == "3")
                        {
                            int intUrut = 0;
                            foreach (var fetchTransak in grpTransak)
                            {
                                if (fetchTransak.strRegbilling == fetch.regBilling
                                    && fetch.LapJP.Substring(0, 1) == "3"
                                    && fetchTransak.strRuangan == fetch.Ruangan
                                    && fetchTransak.strSMF == fetch.IdMR_TSMF)
                                {
                                    grpTransak[intUrut].dblOperasi = grpTransak[intUrut].dblOperasi + fetch.tunainya;
                                }
                                intUrut++;
                            } /* EOF foreach (var fetchTransak in grpTransak) */

                        } /* EOF else if (fetchKasumJP.LapJP.Substring(1, 1) == "3") */
                        else if (fetch.LapJP.Substring(0, 1) == "4")
                        {
                            int intUrut = 0;
                            foreach (var fetchTransak in grpTransak)
                            {
                                if (fetchTransak.strRegbilling == fetch.regBilling
                                    && fetch.LapJP.Substring(0, 1) == "4"
                                    && fetchTransak.strRuangan == fetch.Ruangan
                                    && fetchTransak.strSMF == fetch.IdMR_TSMF)
                                {
                                    grpTransak[intUrut].dblTindakan = grpTransak[intUrut].dblTindakan + fetch.tunainya;
                                }
                                intUrut++;
                            } /* EOF foreach (var fetchTransak in grpTransak) */

                        } /* EOF else if (fetchKasumJP.LapJP.Substring(1, 1) == "4") */
                        else if (fetch.LapJP.Substring(0, 1) == "5")
                        {
                            int intUrut = 0;
                            foreach (var fetchTransak in grpTransak)
                            {
                                if (fetchTransak.strRegbilling == fetch.regBilling
                                    && fetch.LapJP.Substring(0, 1) == "5"
                                    && fetchTransak.strRuangan == fetch.Ruangan
                                    && fetchTransak.strSMF == fetch.IdMR_TSMF)
                                {
                                    grpTransak[intUrut].dblDiagelect = grpTransak[intUrut].dblDiagelect + fetch.tunainya;
                                }
                                intUrut++;
                            } /* EOF foreach (var fetchTransak in grpTransak) */

                        } /* EOF else if (fetchKasumJP.LapJP.Substring(1, 1) == "5") */
                        else if (fetch.LapJP.Substring(0, 1) == "6")
                        {
                            int intUrut = 0;
                            foreach (var fetchTransak in grpTransak)
                            {
                                if (fetchTransak.strRegbilling == fetch.regBilling
                                    && fetch.LapJP.Substring(0, 1) == "6"
                                    && fetchTransak.strRuangan == fetch.Ruangan
                                    && fetchTransak.strSMF == fetch.IdMR_TSMF)
                                {
                                    grpTransak[intUrut].dblPemRK = grpTransak[intUrut].dblPemRK + fetch.tunainya;
                                }
                                intUrut++;
                            } /* EOF foreach (var fetchTransak in grpTransak) */

                        } /* EOF else if (fetchKasumJP.LapJP.Substring(1, 1) == "6") */

                        /* 2 SAMPAI 6 */

                    } /* EOF foreach (var fetchKasumJP in KasumJP) */

                    /*JASA ANASTHESI*/
                    foreach (var fetch in KasJKDJA)
                    {

                        lstTransak itemTransak = new lstTransak();
                        itemTransak.strRegbilling = fetch.regBilling;
                        itemTransak.strNama = fetch.Nama;
                        itemTransak.strRuangan = fetch.Ruangan;
                        itemTransak.strUnit = "ANASTHESI";
                        itemTransak.strSMF = fetch.IdMR_TSMF;
                        itemTransak.dblKonsul = 0;
                        itemTransak.dblVisite = 0;
                        itemTransak.dblOperasi = fetch.tunainya;
                        itemTransak.dblTindakan = 0;
                        itemTransak.dblDiagelect = 0;
                        itemTransak.dblPemRK = 0;

                        grpTransak.Add(itemTransak);

                    } /* EOF foreach (var fetch in KasJKMJA) */

                } /* EOF if (grpTransak.Count > 0) */

            } /* EOF  if (grpLstKasJKM.Count > 0) */

            tmrWaktuLoad.Stop();
            tmrWaktuLoad.Enabled = false;

            if (grpTransak.Count > 0)
            {
                var transaknya = (from x in grpTransak
                                  group x by new
                                  {
                                      x.strRegbilling,
                                      x.strUnit,
                                      x.strRuangan,
                                      x.strNama
                                  } into groupTransak
                                  select new
                                  {
                                      regBilling = groupTransak.Key.strRegbilling,
                                      Nama = groupTransak.Key.strNama,
                                      Ruangan = groupTransak.Key.strRuangan,
                                      Unit = groupTransak.Key.strUnit,
                                      konsul = groupTransak.Sum(x => x.dblKonsul),
                                      visite = groupTransak.Sum(x => x.dblVisite),
                                      operasi = groupTransak.Sum(x => x.dblOperasi),
                                      tindakan = groupTransak.Sum(x => x.dblTindakan),
                                      diagelect = groupTransak.Sum(x => x.dblDiagelect),
                                      pemrk = groupTransak.Sum(x => x.dblPemRK)
                                  }).ToList();

                foreach (var fetch in transaknya)
                {

                    lstTransaknya itemTransaknya = new lstTransaknya();
                    itemTransaknya.strRegBilling = fetch.regBilling;
                    itemTransaknya.strNama = fetch.Nama;
                    itemTransaknya.strRuangan = fetch.Ruangan;
                    itemTransaknya.strUnit = fetch.Unit;
                    itemTransaknya.dblKonsul = fetch.konsul;
                    itemTransaknya.dblVisite = fetch.visite;
                    itemTransaknya.dblOperasi = fetch.operasi;
                    itemTransaknya.dblTindakan = fetch.tindakan;
                    itemTransaknya.dblDiagelect = fetch.diagelect;
                    itemTransaknya.dblPemRK = fetch.pemrk;

                    grpTransaknya.Add(itemTransaknya);

                }

            }

            if (grpKelTarip.Count > 0)
            {

                var xsatu = (from x in grpKelTarip
                             where x.strIdBl_KelTarip.Substring(1, 1) == "1"
                             select x.strLapJP);

                var xdua = from x in grpKelTarip
                           where x.strIdBl_KelTarip.Substring(1, 1) == "2"
                           select x.strLapJP;

                var xtiga = from x in grpKelTarip
                            where x.strIdBl_KelTarip.Substring(1, 1) == "3"
                            select x.strLapJP;

                var xempat = from x in grpKelTarip
                             where x.strIdBl_KelTarip.Substring(1, 1) == "4"
                             select x.strLapJP;

                var xlima = from x in grpKelTarip
                            where x.strIdBl_KelTarip.Substring(1, 1) == "5"
                            select x.strLapJP;

                var xenam = from x in grpKelTarip
                            where x.strIdBl_KelTarip.Substring(1, 1) == "6"
                            select x.strLapJP;

            }

            //conn.Close();

            lblInfoPencarian.SafeControlInvoke(Label => lblInfoPencarian.Text = "Proses Load - SELESAI");
            dtpFilterTgl1.SafeControlInvoke(DateTimePicker => dtpFilterTgl1.Enabled = false);
            dtpFilterTgl2.SafeControlInvoke(DateTimePicker => dtpFilterTgl2.Enabled = false);
            cmbJenisLaporan.SafeControlInvoke(ComboBox => cmbJenisLaporan.Enabled = true);
            cmbUnit.SafeControlInvoke(ComboBox => cmbUnit.Enabled = true);
            btnCari.SafeControlInvoke(Button => btnCari.Enabled = true);
            btnCari.SafeControlInvoke(Button => btnCari.Text = "Pilih Tanggal");
            cmbJenisLaporan.SafeControlInvoke(ComboBox => cmbJenisLaporan.Focus());
            cmbPilihanExport.SafeControlInvoke(ComboBox => cmbPilihanExport.Enabled = true);
            btnExport.SafeControlInvoke(Button => btnExport.Enabled = true);
            btnTampilkan.SafeControlInvoke(Button => btnTampilkan.Enabled = true);
        }