private DataTable GetDataTable()
        {
            //InvoiceSupplierCollection isC = new InvoiceSupplierCollection();
            InvoiceSupplierQuery isQ = new InvoiceSupplierQuery("a");
            isQ.es2.Connection.Name = "KENCANA";
            InvoiceSupplierItemQuery isiQ = new InvoiceSupplierItemQuery("b");
            isiQ.es2.Connection.Name = "KENCANA";
            SupplierQuery sQ = new SupplierQuery("c");
            sQ.es2.Connection.Name = "KENCANA";
            isQ.Select(
            isQ.InvoiceNo, sQ.SupplierName, isQ.InvoiceNotes, isiQ.TransactionNo.As("NO_POR"), isiQ.VerifyAmount, isiQ.PaymentAmount, isiQ.BankAccountNo.As("NO_BG"), isiQ.PPnAmount,
            isiQ.PPh22Amount, isiQ.PPh23Amount,isQ.Isproces)
            .InnerJoin(isiQ).On(isiQ.InvoiceNo == isQ.InvoiceNo)
            .InnerJoin(sQ).On(sQ.SupplierID == isQ.SupplierID)
            .Where(isQ.SRPayableStatus=="2" && isQ.IsVoid == false);
            //isC.Load(isQ);

            //foreach (InvoiceSupplier iS in isC)
            //{
                
            //}
            
            DataTable dt = new DataTable();
            try
            {
                dt = isQ.LoadDataTable();
            }
            catch (Exception ex)
            {
                string error = ex.Message;
            }
            return dt;
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["invoiceno"] == null)
            {
                X.AddScript("parentAutoLoadControl.close();");                
            }
            invoiceNo = Request.QueryString["invoiceno"].ToString().Trim();

            this.storeKa.DataSource = this.GetDataTableKA();
            this.storeKas.DataSource = this.GetDataTableKas();
            this.storeKa.DataBind();
            this.storeKas.DataBind();

            try
            {
                InvoiceSupplierCollection iSC = new InvoiceSupplierCollection();
                iSC.es.Connection.Name = "KENCANA";
                InvoiceSupplierQuery isQ = new InvoiceSupplierQuery("a");
                isQ.es2.Connection.Name = "KENCANA";
                InvoiceSupplierItemQuery isiQ = new InvoiceSupplierItemQuery("b");
                isiQ.es2.Connection.Name = "KENCANA";
                SupplierQuery sQ = new SupplierQuery("c");
                sQ.es2.Connection.Name = "KENCANA";
                isQ.Select(
                isQ.InvoiceNo, sQ.SupplierName, isQ.InvoiceNotes,isQ.InvoiceDate, isiQ.TransactionNo.As("NO_POR"), isiQ.VerifyAmount, isiQ.PaymentAmount, isiQ.BankAccountNo.As("NO_BG"), isiQ.PPnAmount,
                isiQ.PPh22Amount, isiQ.PPh23Amount, isQ.Isproces)
                .InnerJoin(isiQ).On(isiQ.InvoiceNo == isQ.InvoiceNo)
                .InnerJoin(sQ).On(sQ.SupplierID == isQ.SupplierID)
                .Where((isQ.Isproces == false || isQ.Isproces.IsNull()) && isQ.InvoiceNo == invoiceNo);
                isQ.es.Top = 1;
                iSC.Load(isQ);
                if (iSC.Count > 0)
                {
                    foreach (InvoiceSupplier InvSup in iSC)
                    {
                        decimal? tmp = 0;
                        decimal PaymentAmount = 0;
                        decimal PPnAmount = 0;
                        decimal PPh22Amount = 0;
                        decimal PPh23Amount = 0;                                               

                        txtTransInvoiceNo.Text = invoiceNo;
                        txtPpnInvoiceNo.Text = invoiceNo;
                        txtPphInvoiceNo.Text = invoiceNo;
                        txtTransInvoiceNote.Text = InvSup.InvoiceNotes;
                        txtPPhInvoiceNote.Text = InvSup.InvoiceNotes;
                        txtPPnInvoiceNote.Text = InvSup.InvoiceNotes;
                        dfTransInvoiceDate.SelectedDate = (DateTime)InvSup.InvoiceDate;
                        dfPPnInvoiceDate.SelectedDate = (DateTime)InvSup.InvoiceDate;
                        dfPPhInvoiceDate.SelectedDate = (DateTime)InvSup.InvoiceDate;
                        tmp = (decimal?) InvSup.GetColumn(InvoiceSupplierItemMetadata.ColumnNames.PaymentAmount);
                        if (tmp == null)
                            PaymentAmount = 0;
                        else
                            PaymentAmount = (decimal)tmp;
                        tmp = (decimal?)InvSup.GetColumn(InvoiceSupplierItemMetadata.ColumnNames.PPnAmount);
                        if (tmp == null)
                            PPnAmount = 0;
                        else
                            PPnAmount = (decimal)tmp;
                        tmp = (decimal?)InvSup.GetColumn(InvoiceSupplierItemMetadata.ColumnNames.PPh22Amount);
                        if (tmp == null)
                            PPh22Amount = 0;
                        else
                            PPh22Amount = (decimal)tmp;
                        tmp = (decimal?)InvSup.GetColumn(InvoiceSupplierItemMetadata.ColumnNames.PPh23Amount);
                        if (tmp == null)
                            PPh23Amount = 0;
                        else
                            PPh23Amount = (decimal)tmp;
                        //txtTransCreditAmount.Text = PaymentAmount.ToString();
                        txtTransDebitAmount.Text = PaymentAmount.ToString();
                        txtPPnCreditAmount.Text = PPnAmount.ToString();

                        if (PPh22Amount > PPh23Amount && PPh23Amount <= 0)
                        {
                            txtPPhCreditAmount.Text = PPh22Amount.ToString();
                            chkPPh22.Checked = true;
                        }
                        if (PPh23Amount > PPh22Amount && PPh22Amount <= 0)
                        {
                            txtPPhCreditAmount.Text = PPh23Amount.ToString();
                            chkPPh22.Checked = false;
                        }

                        txtTransBG.Text = (string)InvSup.GetColumn("BG");
                        txtPPnBG.Text = (string)InvSup.GetColumn("BG");
                        txtPPhBG.Text = (string)InvSup.GetColumn("BG");
                        txtTransSupplierName.Text = (string)InvSup.GetColumn(SupplierMetadata.ColumnNames.SupplierName);
                        txtPPnSupplierName.Text = (string)InvSup.GetColumn(SupplierMetadata.ColumnNames.SupplierName);
                        txtPPhSupplierName.Text = (string)InvSup.GetColumn(SupplierMetadata.ColumnNames.SupplierName);
                    }
                }


                //InvoiceSupplier iS = new InvoiceSupplier();
                //iS.es.Connection.Name = "KENCANA";
                //if (iS.LoadByPrimaryKey(invoiceNo))
                //{
                //    txtTransInvoiceNo.Text = invoiceNo;
                //    txtPpnInvoiceNo.Text = invoiceNo;
                //    txtPphInvoiceNo.Text = invoiceNo;
                //    txtTransInvoiceNote.Text = iS.InvoiceNotes;
                //    dfTransInvoiceDate.SelectedDate = (DateTime) iS.InvoiceDate;
                     
                //}
            }
            catch (Exception ex)
            {
                string error = ex.Message;
            }
        }