private void cmdApprove_Click(object sender, EventArgs e)
        {
            Guid      doID = (Guid)dataGridView1.SelectedCells[0].OwningRow.Cells["RowID"].Value;
            DataTable dt   = new DataTable();

            try
            {
                using (Database db = new Database())
                {
                    db.Commands.Add(db.CreateCommand("usp_NotaPenjualan_LIST_FILTER_DOID"));
                    db.Commands[0].Parameters.Add(new Parameter("@doID", SqlDbType.UniqueIdentifier, doID));
                    dt = db.Commands[0].ExecuteDataTable();
                }

                if (dt.Rows.Count > 0 && !SecurityManager.AskPasswordManager())
                {
                    MessageBox.Show("Anda tidak berwenang untuk ACC ulang");
                    return;
                }

                Guid     headerID = (Guid)dataGridView1.SelectedCells[0].OwningRow.Cells["RowID"].Value;
                string   kodeToko = dataGridView1.SelectedCells[0].OwningRow.Cells["KodeToko"].Value.ToString();
                DateTime tglDo = (DateTime)dataGridView1.SelectedCells[0].OwningRow.Cells["TglDO"].Value;
                string   noNota, noACCDO, ACCOleh, lokasiDatabase, lokasiDataKasir, lokasiApp, nPrint;
                double   Plafon, Gbc = 0, dDibayar, NilaiDO, dDebet;

                lokasiDatabase  = LookupInfo.GetValue("VACCDO", "PIUTANG_PATH");
                lokasiDataKasir = LookupInfo.GetValue("VACCDO", "KASIR_PATH");
                //lokasiApp = LookupInfo.GetValue("VACCDO", "STOK_PATH");
                lokasiApp = Application.StartupPath + "\\v_accdo_ISA\\";

                ///////////////////// Fefe Part //////////////////////
                DataTable dtPL = new DataTable();
                DataTable dtOP = new DataTable();
                DataTable dtT  = new DataTable();

                if (initPerusahaan.Substring(1, 0) == "0")
                {
                    initPerusahaan = "C";
                }
                else
                {
                    initPerusahaan = "0";
                }

                using (Database db = new Database())
                {
                    //db.Commands.Add(db.CreateCommand("usp_OrderPenjualanDetailPos_LIST"));
                    //db.Commands[0].Parameters.Add(new Parameter("@headerID", SqlDbType.UniqueIdentifier, headerID));
                    //dtPL = db.Commands[0].ExecuteDataTable();

                    //if (dtPL.Rows.Count == 0)
                    //{
                    //    NilaiDO = 0;
                    //}
                    //else
                    //{
                    //    NilaiDO = double.Parse(dtPL.Compute("SUM(HrgNet)", "").ToString());//Tools.isNull(dt.Rows[0]["HrgNet"], "").ToString();
                    //}
                    db.Commands.Add(db.CreateCommand("usp_OrderPenjualanPos_LIST"));
                    db.Commands[0].Parameters.Add(new Parameter("@RowID", SqlDbType.UniqueIdentifier, headerID));
                    dtOP    = db.Commands[0].ExecuteDataTable();
                    noNota  = Tools.isNull(dtOP.Rows[0]["NoACCPiutang"], "").ToString();
                    nPrint  = dtOP.Rows[0]["NPrint"].ToString();
                    NilaiDO = double.Parse(dtOP.Rows[0]["RpNet"].ToString());

                    db.Commands.Add(db.CreateCommand("usp_Toko_LIST"));
                    db.Commands[1].Parameters.Add(new Parameter("@kodeToko", SqlDbType.VarChar, kodeToko));
                    dtT    = db.Commands[1].ExecuteDataTable();
                    Plafon = Convert.ToDouble(dtT.Rows[0]["Plafon"]);
                }
                //GENERATE Nomor Acc
                DataTable dtNum    = Tools.GetGeneralNumerator(docNO);
                int       lebar    = int.Parse(dtNum.Rows[0]["Lebar"].ToString());
                int       iNomor   = int.Parse(dtNum.Rows[0]["Nomor"].ToString());
                string    depan    = Tools.GeneralInitial();
                string    belakang = dtNum.Rows[0]["Belakang"].ToString();
                iNomor++;
                string strNoACC = Tools.FormatNumerator(iNomor, lebar, depan, belakang);
                strNoACC = strNoACC.Substring(3, 6);

                DataTable dt1 = new DataTable();
                using (Database db = new Database())
                {
                    db.Commands.Add(db.CreateCommand("usp_Toko_LIST"));
                    db.Commands[0].Parameters.Add(new Parameter("@kodeToko", SqlDbType.VarChar, kodeToko));
                    dt1 = db.Commands[0].ExecuteDataTable();

                    if (dt1.Rows.Count > 0)
                    {
                        db.Commands.Add(db.CreateCommand("usp_fnCekPlafon"));
                        db.Commands[1].Parameters.Add(new Parameter("@kodeToko", SqlDbType.VarChar, kodeToko));
                        db.Commands[1].Parameters.Add(new Parameter("@rowID", SqlDbType.UniqueIdentifier, headerID));
                        dt1 = db.Commands[1].ExecuteDataTable();
                        if (dt1.Rows.Count > 0)
                        {
                            Plafon = Convert.ToDouble(dt1.Rows[0]["Plafon"]);
                        }
                    }
                    db.Commands.Add(db.CreateCommand("usp_vwDebetDibayarbankGiroTolak"));
                    db.Commands[2].Parameters.Add(new Parameter("@kodeToko", SqlDbType.VarChar, kodeToko));
                    dt1 = db.Commands[2].ExecuteDataTable();
                    if (dt1.Rows.Count > 0)
                    {
                        dDebet   = Convert.ToDouble(dt1.Rows[0]["Debet"]);
                        dDibayar = Convert.ToDouble(dt1.Rows[0]["Dibayar"]);
                    }
                    else
                    {
                        dDebet   = 0;
                        dDibayar = 0;
                    }

                    if (dDebet - dDibayar > 0)
                    {
                        Gbc = Gbc + dDebet;
                    }

                    noACCDO = string.Empty;
                    ACCOleh = SecurityManager.UserID;
                }
                System.Diagnostics.Process proc = new System.Diagnostics.Process();
                proc.EnableRaisingEvents = false;
                proc.StartInfo.FileName  = lokasiApp + "v_accdo_ISA_Pos.exe";
                proc.StartInfo.Arguments = Plafon.ToString() + " " + kodeToko + " " + ACCOleh + " " + NilaiDO.ToString() + " " + headerID.ToString() + " " + strNoACC + " " + initPerusahaan + " " + tglDo.ToString("dd/MM/yyyy") + " " + lokasiDatabase + " " + lokasiDataKasir + " " + lokasiApp + " " + host + " " + nPrint;
                proc.Start();
                proc.WaitForExit();
                //RefreshDataSeluruhnya();
                //dataGridView1.FindRow("RowID", doID.ToString());
                RefreshRowDataDO(doID.ToString());
            }
            catch (Exception ex)
            {
                Error.LogError(ex);
            }
        }
Beispiel #2
0
        //public frmPlafon(Form caller,Guid headerID)
        //{
        //    InitializeComponent();
        //    formMode = enumFormMode.Update;
        //    _headerID=headerID;
        //    this.Caller = caller;
        //}

        private void frmPlafon_Load(object sender, EventArgs e)
        {
            rdbPenuh.Checked = true;
            string noNota;
            string noACCDO;
            double Plafon, RpJual, Saldo, Gbc, Tolak, Ovd, Debet, Kredit;

            if (formMode == enumFormMode.New)
            {
                try
                {
                    DataTable dt   = new DataTable();
                    DataTable dtOP = new DataTable();
                    DataTable dtT  = new DataTable();

                    using (Database db = new Database())
                    {
                        db.Commands.Add(db.CreateCommand("usp_OrderPenjualanDetail_LIST_FILTER_HEADERID"));
                        db.Commands[0].Parameters.Add(new Parameter("@headerID", SqlDbType.UniqueIdentifier, _headerID));
                        dt = db.Commands[0].ExecuteDataTable();

                        if (dt.Rows.Count == 0)
                        {
                            txtNilaiDO.Text = "0";
                        }
                        else
                        {
                            txtNilaiDO.Text = dt.Compute("SUM(HrgNet)", "").ToString();//Tools.isNull(dt.Rows[0]["HrgNet"], "").ToString();
                        }

                        db.Commands.Add(db.CreateCommand("usp_OrderPenjualan_LIST"));
                        db.Commands[1].Parameters.Add(new Parameter("@RowID", SqlDbType.UniqueIdentifier, _headerID));
                        dtOP   = db.Commands[1].ExecuteDataTable();
                        noNota = Tools.isNull(dtOP.Rows[0]["NoACCPiutang"], "").ToString();

                        db.Commands.Add(db.CreateCommand("usp_Toko_LIST"));
                        db.Commands[2].Parameters.Add(new Parameter("@kodeToko", SqlDbType.VarChar, _kodeToko));
                        dtT    = db.Commands[2].ExecuteDataTable();
                        Plafon = Convert.ToDouble(dtT.Rows[0]["Plafon"]);
                    }
                    if (noNota != "")
                    {
                        noACCDO              = Tools.isNull(dtOP.Rows[0]["NoACCPiutang"], "").ToString();
                        Plafon               = Convert.ToDouble(dtOP.Rows[0]["RpPlafonToko"]);
                        Saldo                = Convert.ToDouble(dtOP.Rows[0]["RpPiutangTerakhir"]);
                        Tolak                = Convert.ToDouble(dtOP.Rows[0]["RpGiroTolakTerakhir"]);
                        Ovd                  = Convert.ToDouble(dtOP.Rows[0]["RpOverdue"]);
                        txtPlafon.Text       = Plafon.ToString();
                        txtSaldoAkhir.Text   = (Saldo + Tolak).ToString();
                        txtSisaPlafon.Text   = (Plafon - Saldo).ToString();
                        txtNilaiOverdue.Text = Ovd.ToString();

                        txtACCOleh.Text = SecurityManager.UserID;
                    }
                    else
                    {
                        Tolak = 0;
                        DataTable dt1 = new DataTable();
                        try
                        {
                            using (Database db = new Database())
                            {
                                db.Commands.Add(db.CreateCommand("usp_Toko_LIST"));
                                db.Commands[0].Parameters.Add(new Parameter("@kodeToko", SqlDbType.VarChar, _kodeToko));
                                dt1 = db.Commands[0].ExecuteDataTable();

                                if (dt1.Rows.Count > 0)
                                {
                                    db.Commands.Add(db.CreateCommand("usp_fnCekPlafon"));
                                    db.Commands[1].Parameters.Add(new Parameter("@kodeToko", SqlDbType.VarChar, _kodeToko));
                                    db.Commands[1].Parameters.Add(new Parameter("@rowID", SqlDbType.UniqueIdentifier, _headerID));
                                    dt1 = db.Commands[1].ExecuteDataTable();
                                    if (dt1.Rows.Count > 0)
                                    {
                                        Plafon = Convert.ToDouble(dt1.Rows[0]["Plafon"]);
                                    }
                                    //Plafon = 2000000;
                                }
                                db.Commands.Add(db.CreateCommand("usp_vwRpJualkartuPiutang"));
                                db.Commands[2].Parameters.Add(new Parameter("@kodeToko", SqlDbType.VarChar, _kodeToko));
                                dt1 = db.Commands[2].ExecuteDataTable();
                                if (dt1.Rows.Count > 0)
                                {//RpJual
                                    RpJual = Convert.ToDouble(dt1.Rows[0]["RpJual"]);
                                }
                                else
                                {
                                    RpJual = 0;
                                }

                                db.Commands.Add(db.CreateCommand("usp_vwDebetKreditDetailPiutang"));
                                db.Commands[3].Parameters.Add(new Parameter("@kodeToko", SqlDbType.VarChar, _kodeToko));
                                dt1 = db.Commands[3].ExecuteDataTable();
                                if (dt1.Rows.Count > 0)
                                {
                                    Debet  = Convert.ToDouble(dt1.Rows[0]["Debet"]);
                                    Kredit = Convert.ToDouble(dt1.Rows[0]["Kredit"]);
                                }
                                else
                                {
                                    Debet  = 0;
                                    Kredit = 0;
                                }
                                //Saldo
                                Saldo = (RpJual + Debet) - Kredit;

                                db.Commands.Add(db.CreateCommand("usp_vwNominalgiro"));
                                db.Commands[4].Parameters.Add(new Parameter("@kodeToko", SqlDbType.VarChar, _kodeToko));
                                dt1 = db.Commands[4].ExecuteDataTable();
                                if (dt1.Rows.Count > 0)
                                {
                                    Gbc = Convert.ToDouble(dt1.Rows[0]["Gbc"]);
                                }
                                else
                                {
                                    Gbc = 0;
                                }

                                db.Commands.Add(db.CreateCommand("usp_vwDebetDibayarbankGiroTolak"));
                                db.Commands[5].Parameters.Add(new Parameter("@kodeToko", SqlDbType.VarChar, _kodeToko));
                                dt1 = db.Commands[5].ExecuteDataTable();
                                double dDebet, dDibayar;
                                if (dt1.Rows.Count > 0)
                                {
                                    dDebet   = Convert.ToDouble(dt1.Rows[0]["Debet"]);
                                    dDibayar = Convert.ToDouble(dt1.Rows[0]["Dibayar"]);
                                }
                                else
                                {
                                    dDebet   = 0;
                                    dDibayar = 0;
                                }

                                if (dDebet - dDibayar > 0)
                                {
                                    Gbc = Gbc + dDebet;
                                }

                                //Saldo
                                Saldo = Saldo + (Gbc - dDibayar);

                                db.Commands.Add(db.CreateCommand("usp_vwOVD"));
                                db.Commands[6].Parameters.Add(new Parameter("@kodeToko", SqlDbType.VarChar, _kodeToko));
                                db.Commands[6].Parameters.Add(new Parameter("@tgljatuhTempo", SqlDbType.VarChar, _tglDo));
                                dt1 = db.Commands[6].ExecuteDataTable();
                                if (dt1.Rows.Count > 0)
                                {
                                    Ovd = Convert.ToDouble(dt1.Rows[0]["OVD"]);
                                }
                                else
                                {
                                    Ovd = 0;
                                }
                                //Ovd
                                Ovd = Ovd + (RpJual - Kredit);

                                //else
                                //{

                                //    Plafon = 2000000;
                                //    Saldo = 2000000;
                                //    Tolak = 0;
                                //    Ovd = 0;
                                //}

                                txtPlafon.Text       = Plafon.ToString();
                                txtSaldoAkhir.Text   = (Saldo + Tolak).ToString();
                                txtSisaPlafon.Text   = (Plafon - Saldo).ToString();
                                txtNilaiOverdue.Text = Ovd.ToString();

                                txtACCOleh.Text = SecurityManager.UserID;
                            }
                        }
                        catch (Exception ex)
                        {
                            Error.LogError(ex);
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }