public void ProceesData_Click(string invoiceNo)
        {
            tm1.StartAll();
            HttpContext.Current.Session["isProcess"] = false;
            gpInvoices.Title = invoiceNo;
            InvoiceSupplier iS = new InvoiceSupplier();
            iS.es.Connection.Name = "KENCANA";
            if (iS.LoadByPrimaryKey(invoiceNo))
            {
                gpInvoices.Title = iS.InvoiceNotes + " " + iS.SupplierID;
            }

            var win = new Window()
            {
                ID = "window1",
                Title = "Proses Invoice Number : " + invoiceNo,
                Width = Unit.Pixel(800),
                Height = Unit.Pixel(600),
                Modal = true,
                AutoRender = false,
                Collapsible = false,
                Maximizable = false,
                Hidden = true, 
                Draggable = false, 
                Resizable = false
            };
            win.AutoLoad.Url = "~/Transaksi/TransaksiTarikDataPembayaranProcess.aspx?invoiceno=" + invoiceNo;
            win.AutoLoad.Mode = Ext.Net.LoadMode.IFrame;
            win.AutoLoad.ShowMask = true;            
            //win.Center();
            //win.Show();

            //this.Form.Controls.Add(win);
            win.Render(this.Form);
            win.Show();
        }
        public void SaveData()
        {
            //Validasi
            if (string.IsNullOrEmpty(txtTransInvoiceNo.Text) || string.IsNullOrEmpty(cmbTransKa.SelectedItem.Value)
                || string.IsNullOrEmpty(txtTransInvoiceNote.Text) || string.IsNullOrEmpty(dfTransInvoiceDate.SelectedDate.ToShortDateString())
                || string.IsNullOrEmpty(cmbTransKasId.SelectedItem.Value))
            {
                X.Msg.Alert("Error on Transaction Tab", "Please fill neccessary field").Show();
                return;
            }
            if (string.IsNullOrEmpty(txtPpnInvoiceNo.Text) || string.IsNullOrEmpty(cmbPPnKa.SelectedItem.Value)
                || string.IsNullOrEmpty(txtPPnInvoiceNote.Text) || string.IsNullOrEmpty(dfPPnInvoiceDate.SelectedDate.ToShortDateString())
                || string.IsNullOrEmpty(cmbPPnKas.SelectedItem.Value))
            {
                X.Msg.Alert("Error on PPN Tab", "Please fill neccessary field").Show();
                return;
            }
            if (string.IsNullOrEmpty(txtPphInvoiceNo.Text) || string.IsNullOrEmpty(cmbPPhKa.SelectedItem.Value)
                || string.IsNullOrEmpty(txtPPhInvoiceNote.Text) || string.IsNullOrEmpty(dfPPhInvoiceDate.SelectedDate.ToShortDateString())
                || string.IsNullOrEmpty(cmbPPhKas.SelectedItem.Value))
            {
                X.Msg.Alert("Error on PPh Tab", "Please fill neccessary field").Show();
                return;
            }

            // Save Transaksi ke Tabel Trans RSCM_BKU
            int transMonth = dfTransInvoiceDate.SelectedDate.Month;
            string month = transMonth.ToString().Trim();
            if (month.Length == 1)
                month = "0" + month;
            string year = dfTransInvoiceDate.SelectedDate.Year.ToString().Trim();            
            string autonumber = string.Empty;

            Trans Trans = new Trans();
            Trans.es.Connection.Name = "LIVE";
            //Auto Number 
            AutoNumberingQuery anQ = new AutoNumberingQuery();
            anQ.es2.Connection.Name = "LIVE";
            anQ.SelectAll();
            anQ.Where(anQ.KaMonth == month, anQ.KaYear == year);
            AutoNumberingCollection anColl = new AutoNumberingCollection();

            anColl.Load(anQ);

            decimal DebitAmount = 0;
            decimal CreditAmount = 0;

            if (anColl.Count == 0)
            {
                AutoNumbering aN = new AutoNumbering();
                aN.es.Connection.Name = "LIVE";                
                aN.KaYear = DateTime.Now.Year.ToString().Trim();
                aN.KaMonth = month;
                aN.LastNumber = 3;
                aN.PrefixNumber = "000";
                //AutoNumbering an = new AutoNumbering { KaYear = DateTime.Now.Year.ToString().Trim(), KaMonth = month, LastNumber = 1, PrefixNumber = "000" };
                autonumber = String.Format("{0}{1}{2}-0001", autonumber, DateTime.Now.Year.ToString().Trim(), month);
                //an.Save();
                string autonumberPpn = String.Format("{0}{1}{2}-0002", string.Empty, DateTime.Now.Year.ToString().Trim(), month);
                string autonumberPph = String.Format("{0}{1}{2}-0003", string.Empty, DateTime.Now.Year.ToString().Trim(), month);
                aN.Save();
                try
                {
                    //Transaksi                                       
                    Trans.KaCode = cmbTransKa.SelectedItem.Value;
                    Trans.TransNumber = autonumber.ToUpper();
                    Trans.CekBgNumber = txtTransBG.Text;
                    if (string.IsNullOrEmpty(txtTransDebitAmount.Text.Trim()))
                        DebitAmount = 0;
                    else
                    {
                        if (!decimal.TryParse(txtTransDebitAmount.Text.Trim(),out DebitAmount))
                            DebitAmount = 0;
                    }
                    if (string.IsNullOrEmpty(txtTransCreditAmount.Text.Trim()))
                        CreditAmount = 0;
                    else
                    {
                        if (!decimal.TryParse(txtTransCreditAmount.Text.Trim(), out CreditAmount))
                            CreditAmount = 0;
                    }

                    Trans.DebitAmount = DebitAmount;
                    Trans.CreditAmount = CreditAmount;
                    Trans.Descript = txtTransInvoiceNo.Text + " - " + txtTransInvoiceNote.Text;
                    Trans.KasId = cmbTransKasId.SelectedItem.Value;
                    Trans.TransDate = dfTransInvoiceDate.SelectedDate;
                    Trans.UserInsert = (string)HttpContext.Current.Session["UserId"];
                    Trans.TglInsert = DateTime.Now;
                    Trans.PeriodId = (Int32)HttpContext.Current.Session["_periodeId"];
                    //Trans.PeriodId = 1;
                    Trans.Isverified = false;
                    Trans.IsClosed = false;
                    Trans.Save();

                    
                    //PPn
                    Trans TransPpn = new Trans();                    
                    TransPpn.es.Connection.Name = "LIVE"; 
                    
                    TransPpn.KaCode = cmbPPnKa.SelectedItem.Value;
                    TransPpn.TransNumber = autonumberPpn.ToUpper();
                    TransPpn.CekBgNumber = txtPPnBG.Text;
                    if (string.IsNullOrEmpty(txtPPnDebitAmount.Text.Trim()))
                        DebitAmount = 0;
                    else
                    {
                        if (!decimal.TryParse(txtPPnDebitAmount.Text.Trim(), out DebitAmount))
                            DebitAmount = 0;
                    }
                    if (string.IsNullOrEmpty(txtPPnCreditAmount.Text.Trim()))
                        CreditAmount = 0;
                    else
                    {
                        if (!decimal.TryParse(txtPPnCreditAmount.Text.Trim(), out CreditAmount))
                            CreditAmount = 0;
                    }
                    TransPpn.DebitAmount = DebitAmount;
                    TransPpn.CreditAmount = CreditAmount;
                    TransPpn.Descript = "Terima PPN dari " + txtPPnSupplierName.Text;
                    TransPpn.KasId = cmbPPnKas.SelectedItem.Value;
                    TransPpn.TransDate = dfPPnInvoiceDate.SelectedDate;
                    TransPpn.UserInsert = (string)HttpContext.Current.Session["UserId"];
                    TransPpn.TglInsert = DateTime.Now;
                    TransPpn.PeriodId = (Int32)HttpContext.Current.Session["_periodeId"];
                    //TransPpn.PeriodId = 1;
                    TransPpn.Isverified = false;
                    TransPpn.IsClosed = false;
                    TransPpn.Save();
                    
                    //PPh
                    Trans TransPph = new Trans(); 
                    TransPph.es.Connection.Name = "LIVE";
                    TransPph.KaCode = cmbPPhKa.SelectedItem.Value;
                    TransPph.TransNumber = autonumberPph.ToUpper();
                    TransPph.CekBgNumber = txtPPhBG.Text;
                    if (string.IsNullOrEmpty(txtPPhDebitAmount.Text.Trim()))
                        DebitAmount = 0;
                    else
                    {
                        if (!decimal.TryParse(txtPPhDebitAmount.Text.Trim(), out DebitAmount))
                            DebitAmount = 0;
                    }
                    if (string.IsNullOrEmpty(txtPPhCreditAmount.Text.Trim()))
                        CreditAmount = 0;
                    else
                    {
                        if (!decimal.TryParse(txtPPhCreditAmount.Text.Trim(), out CreditAmount))
                            CreditAmount = 0;
                    }
                    TransPph.DebitAmount = DebitAmount;
                    TransPph.CreditAmount = CreditAmount;
                    if (chkPPh22.Checked)
                        TransPph.Descript = "Terima PPh 22 dari " + txtPPhSupplierName.Text;
                    else
                        TransPph.Descript = "Terima PPh 23 dari " + txtPPhSupplierName.Text;
                    TransPph.KasId = cmbPPhKas.SelectedItem.Value;
                    TransPph.TransDate = dfPPhInvoiceDate.SelectedDate;
                    TransPph.UserInsert = (string)HttpContext.Current.Session["UserId"];
                    TransPph.TglInsert = DateTime.Now;
                    TransPph.PeriodId = (Int32)HttpContext.Current.Session["_periodeId"];
                    //TransPph.PeriodId = 1;
                    TransPph.Isverified = false;
                    TransPph.IsClosed = false;
                    TransPph.Save();                    
                }
                catch (Exception ex)
                {
                    X.Msg.Alert("Error", ex.Message).Show();
                }                
            }
            else
                foreach (AutoNumbering aa in anColl)
                {
                    string i = (aa.LastNumber + 1).ToString().Trim();
                    if (i.Length == 1)
                        autonumber = String.Format("{0}{1}{2}-000{3}", autonumber, aa.KaYear, aa.KaMonth, i);
                    if (i.Length == 2)
                        autonumber = String.Format("{0}{1}{2}-00{3}", autonumber, aa.KaYear, aa.KaMonth, i);
                    if (i.Length == 3)
                        autonumber = String.Format("{0}{1}{2}-0{3}", autonumber, aa.KaYear, aa.KaMonth, i);
                    if (i.Length == 4)
                        autonumber = String.Format("{0}{1}{2}-{3}", autonumber, aa.KaYear, aa.KaMonth, i);

                    string j = (aa.LastNumber + 2).ToString().Trim();
                    string autonumberPPn = string.Empty; 
                    if (j.Length == 1)
                        autonumberPPn = String.Format("{0}{1}{2}-000{3}", autonumberPPn, aa.KaYear, aa.KaMonth, j);
                    if (j.Length == 2)
                        autonumberPPn = String.Format("{0}{1}{2}-00{3}", autonumberPPn, aa.KaYear, aa.KaMonth, j);
                    if (j.Length == 3)
                        autonumberPPn = String.Format("{0}{1}{2}-0{3}", autonumberPPn, aa.KaYear, aa.KaMonth, j);
                    if (j.Length == 4)
                        autonumberPPn = String.Format("{0}{1}{2}-{3}", autonumberPPn, aa.KaYear, aa.KaMonth, j);

                    string k = (aa.LastNumber + 3).ToString().Trim();
                    string autonumberPPh = string.Empty; 
                    if (k.Length == 1)
                        autonumberPPh = String.Format("{0}{1}{2}-000{3}", autonumberPPh, aa.KaYear, aa.KaMonth, k);
                    if (k.Length == 2)
                        autonumberPPh = String.Format("{0}{1}{2}-00{3}", autonumberPPh, aa.KaYear, aa.KaMonth, k);
                    if (k.Length == 3)
                        autonumberPPh = String.Format("{0}{1}{2}-0{3}", autonumberPPh, aa.KaYear, aa.KaMonth, k);
                    if (k.Length == 4)
                        autonumberPPh = String.Format("{0}{1}{2}-{3}", autonumberPPh, aa.KaYear, aa.KaMonth, k);

                    AutoNumbering anb = new AutoNumbering();
                    anb.es.Connection.Name = "LIVE";                    
                    if (anb.LoadByPrimaryKey((long)aa.Id))
                    {
                        anb.LastNumber = aa.LastNumber + 3;

                        try
                        {
                            //Transaksi                            
                            Trans.KaCode = cmbTransKa.SelectedItem.Value;
                            Trans.TransNumber = autonumber.ToUpper();
                            Trans.CekBgNumber = txtTransBG.Text;
                            if (string.IsNullOrEmpty(txtTransDebitAmount.Text.Trim()))
                                DebitAmount = 0;
                            else
                            {
                                if (!decimal.TryParse(txtTransDebitAmount.Text.Trim(), out DebitAmount))
                                    DebitAmount = 0;
                            }
                            if (string.IsNullOrEmpty(txtTransCreditAmount.Text.Trim()))
                                CreditAmount = 0;
                            else
                            {
                                if (!decimal.TryParse(txtTransCreditAmount.Text.Trim(), out CreditAmount))
                                    CreditAmount = 0;
                            }

                            Trans.DebitAmount = DebitAmount;
                            Trans.CreditAmount = CreditAmount;
                            Trans.Descript = txtTransInvoiceNo.Text + " - " + txtTransInvoiceNote.Text;
                            Trans.KasId = cmbTransKasId.SelectedItem.Value;
                            Trans.TransDate = dfTransInvoiceDate.SelectedDate;
                            Trans.UserInsert = (string)HttpContext.Current.Session["UserId"];
                            Trans.TglInsert = DateTime.Now;
                            Trans.PeriodId = (Int32)HttpContext.Current.Session["_periodeId"];
                            //Trans.PeriodId = 1;
                            Trans.Isverified = false;
                            Trans.IsClosed = false;
                            Trans.Save();

                            //PPn
                            Trans TransPpn = new BusinessObjects.Trans();
                            TransPpn.es.Connection.Name = "LIVE";
                            
                            TransPpn.KaCode = cmbPPnKa.SelectedItem.Value;
                            TransPpn.TransNumber = autonumberPPn.ToUpper();
                            TransPpn.CekBgNumber = txtPPnBG.Text;
                            if (string.IsNullOrEmpty(txtPPnDebitAmount.Text.Trim()))
                                DebitAmount = 0;
                            else
                            {
                                if (!decimal.TryParse(txtPPnDebitAmount.Text.Trim(), out DebitAmount))
                                    DebitAmount = 0;
                            }
                            if (string.IsNullOrEmpty(txtPPnCreditAmount.Text.Trim()))
                                CreditAmount = 0;
                            else
                            {
                                if (!decimal.TryParse(txtPPnCreditAmount.Text.Trim(), out CreditAmount))
                                    CreditAmount = 0;
                            }
                            TransPpn.DebitAmount = DebitAmount;
                            TransPpn.CreditAmount = CreditAmount;
                            TransPpn.Descript = "Terima PPN dari " + txtPPnSupplierName.Text;
                            TransPpn.KasId = cmbPPnKas.SelectedItem.Value;
                            TransPpn.TransDate = dfPPnInvoiceDate.SelectedDate;
                            TransPpn.UserInsert = (string)HttpContext.Current.Session["UserId"];
                            TransPpn.TglInsert = DateTime.Now;
                            TransPpn.PeriodId = (Int32)HttpContext.Current.Session["_periodeId"];
                            //TransPpn.PeriodId = 1;
                            TransPpn.Isverified = false;
                            TransPpn.IsClosed = false;
                            TransPpn.Save();

                            //PPh
                            BusinessObjects.Trans TransPPh = new BusinessObjects.Trans();
                            TransPPh.es.Connection.Name = "LIVE";
                            
                            TransPPh.KaCode = cmbPPhKa.SelectedItem.Value;
                            TransPPh.TransNumber = autonumberPPh.ToUpper();
                            TransPPh.CekBgNumber = txtPPhBG.Text;
                            if (string.IsNullOrEmpty(txtPPhDebitAmount.Text.Trim()))
                                DebitAmount = 0;
                            else
                            {
                                if (!decimal.TryParse(txtPPhDebitAmount.Text.Trim(), out DebitAmount))
                                    DebitAmount = 0;
                            }
                            if (string.IsNullOrEmpty(txtPPhCreditAmount.Text.Trim()))
                                CreditAmount = 0;
                            else
                            {
                                if (!decimal.TryParse(txtPPhCreditAmount.Text.Trim(), out CreditAmount))
                                    CreditAmount = 0;
                            }
                            TransPPh.DebitAmount = DebitAmount;
                            TransPPh.CreditAmount = CreditAmount;
                            if (chkPPh22.Checked)
                                TransPPh.Descript = "Terima PPh 22 dari " + txtPPhSupplierName.Text;
                            else
                                TransPPh.Descript = "Terima PPh 23 dari " + txtPPhSupplierName.Text;
                            TransPPh.KasId = cmbPPnKas.SelectedItem.Value;
                            TransPPh.TransDate = dfPPnInvoiceDate.SelectedDate;
                            TransPPh.UserInsert = (string)HttpContext.Current.Session["UserId"];
                            TransPPh.TglInsert = DateTime.Now;
                            TransPPh.PeriodId = (Int32)HttpContext.Current.Session["_periodeId"];
                            //TransPPh.PeriodId = 1;
                            TransPPh.Isverified = false;
                            TransPPh.IsClosed = false;
                            TransPPh.Save();

                            anb.LastNumber = aa.LastNumber + 3;
                            anb.Save();
                        }
                        catch (Exception ex)
                        {
                            X.Msg.Alert("Error", ex.Message).Show();
                        }                        
                    }
                }
            //Save PPn ke Tabel Trans RSCM_BKU


            InvoiceSupplier inSu = new InvoiceSupplier();
            inSu.es.Connection.Name = "KENCANA";
            if (inSu.LoadByPrimaryKey(invoiceNo))
            {
                inSu.Isproces = true;
                inSu.Save();
            }
            HttpContext.Current.Session["isProcess"] = true;
            X.AddScript("parentAutoLoadControl.close();");            
        }