private void cmdSAVE_Click(object sender, EventArgs e)
        {
            if (txtNoKoreksi.Text == "")
            {
                MessageBox.Show("No Koreksi tidah boleh kosong");
                return;
            }

            if (txtQtyNota2.GetIntValue - txtQtyNota1.GetIntValue == 0)
            {
                ErrorProvider ep = new ErrorProvider();
                ep.SetError(txtQtyNota2, "Tidak bisa diisi dengan nilai sama dengan Qty Nota sebelumnya!");
                return;
            }
            try
            {
                GlobalVar.LastClosingDate = (DateTime)txtTglKoreksi.DateValue;
                if (txtTglKoreksi.DateValue <= GlobalVar.LastClosingDate)
                {
                    throw new Exception(String.Format(ISA.Toko.Messages.Error.AlreadyClosingPJT, GlobalVar.LastClosingDate));
                }
                double hrgKoreksi = double.Parse(txtHrgNetto2.Text) - double.Parse(txtHrgNetto1.Text);
                int    qtyKoreksi = txtQtyNota2.GetIntValue - txtQtyNota1.GetIntValue;
                if (qtyKoreksi < 0)
                {
                    #region "Stok Minus Lock New"

                    using (Stock st = new Stock())
                    {
                        st.AddList(_dtReturJualDetail.Rows[0]["BarangID"].ToString(), "", Math.Abs(qtyKoreksi));


                        // pass = st.Pass();
                        if (!st.Pass())
                        {
                            MessageBox.Show("Tidak Bisa Proses,\n nilai transaksi menyebabkan stok minus! ", "Warning");


                            st.ReportMinus();
                            if (MessageBox.Show("Cetak Form Opname?", "Opname", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                            {
                                st.PrintOutMinus();
                            }

                            this.Close();
                            return;
                        }
                    }

                    #endregion
                }
                this.Cursor = Cursors.WaitCursor;
                _rowID      = Guid.NewGuid();
                using (Database db = new Database())
                {
                    db.Commands.Add(db.CreateCommand("usp_KoreksiReturPenjualan_INSERT"));
                    db.Commands[0].Parameters.Add(new Parameter("@rowID", SqlDbType.UniqueIdentifier, _rowID));
                    db.Commands[0].Parameters.Add(new Parameter("@recordID", SqlDbType.VarChar, Tools.CreateFingerPrint()));
                    db.Commands[0].Parameters.Add(new Parameter("@returJualDetailID", SqlDbType.UniqueIdentifier, _dtReturJualDetail.Rows[0]["RowID"]));
                    db.Commands[0].Parameters.Add(new Parameter("@returJualDetailRecID", SqlDbType.VarChar, _dtReturJualDetail.Rows[0]["RecordID"]));
                    db.Commands[0].Parameters.Add(new Parameter("@tglKoreksi", SqlDbType.DateTime, txtTglKoreksi.DateValue));
                    db.Commands[0].Parameters.Add(new Parameter("@barangID", SqlDbType.VarChar, _dtReturJualDetail.Rows[0]["BarangID"]));
                    db.Commands[0].Parameters.Add(new Parameter("@noKoreksi", SqlDbType.VarChar, txtNoKoreksi.Text));
                    db.Commands[0].Parameters.Add(new Parameter("@qtyNotaBaru", SqlDbType.Int, txtQtyNota2.GetIntValue));
                    db.Commands[0].Parameters.Add(new Parameter("@hrgJualBaru", SqlDbType.Money, double.Parse(txtHrgSatuan2.Text)));
                    db.Commands[0].Parameters.Add(new Parameter("@catatan", SqlDbType.VarChar, txtCatatan2.Text));
                    db.Commands[0].Parameters.Add(new Parameter("@kodeToko", SqlDbType.VarChar, _dtReturJual.Rows[0]["KodeToko"]));
                    db.Commands[0].Parameters.Add(new Parameter("@sumber", SqlDbType.VarChar, "NRJ"));
                    db.Commands[0].Parameters.Add(new Parameter("@linkID", SqlDbType.VarChar, ""));
                    db.Commands[0].Parameters.Add(new Parameter("@hrgJualKoreksi", SqlDbType.Money, hrgKoreksi));
                    db.Commands[0].Parameters.Add(new Parameter("@qtyNotaKoreksi", SqlDbType.Int, qtyKoreksi));
                    db.Commands[0].Parameters.Add(new Parameter("@syncFlag", SqlDbType.Bit, 0));
                    db.Commands[0].Parameters.Add(new Parameter("@lastUpdatedBy", SqlDbType.VarChar, SecurityManager.UserID));
                    db.Commands[0].ExecuteNonQuery();
                }
                this.DialogResult = DialogResult.OK;
                MessageBox.Show("Data telah disimpan");
                this.Close();
            }
            catch (Exception ex)
            {
                Error.LogError(ex);
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }
Ejemplo n.º 2
0
        private void InsertKoreksi()
        {
            try
            {
                double hrgKoreksi = double.Parse(txtHrgNet2.Text) - double.Parse(txtHrgNet1.Text);
                int    qtyKoreksi = txtQtyNota2.GetIntValue - txtQtyNota1.GetIntValue;
                #region "Stok Minus Lock New"
                if (qtyKoreksi < 0)
                {
                    using (Stock st = new Stock())
                    {
                        st.AddList(dtNotaBeliDetail.Rows[0]["BarangID"].ToString(), "", Math.Abs(qtyKoreksi));

                        if (!st.Pass())
                        {
                            MessageBox.Show("Tidak Bisa Proses,\n nilai transaksi menyebabkan stok minus! ", "Warning");


                            st.ReportMinus();
                            if (MessageBox.Show("Cetak Form Opname?", "Opname", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                            {
                                st.PrintOutMinus();
                            }

                            this.Close();
                            return;
                        }
                    }
                }

                #endregion

                this.Cursor = Cursors.WaitCursor;
                _rowID      = Guid.NewGuid();
                using (Database db = new Database())
                {
                    db.Commands.Add(db.CreateCommand("usp_KoreksiPembelian_INSERT"));
                    db.Commands[0].Parameters.Add(new Parameter("@rowID", SqlDbType.UniqueIdentifier, _rowID));
                    db.Commands[0].Parameters.Add(new Parameter("@recordID", SqlDbType.VarChar, Tools.CreateFingerPrint()));
                    db.Commands[0].Parameters.Add(new Parameter("@notaBeliDetailID", SqlDbType.UniqueIdentifier, dtNotaBeliDetail.Rows[0]["RowID"]));
                    db.Commands[0].Parameters.Add(new Parameter("@notaBeliDetailRecID", SqlDbType.VarChar, dtNotaBeliDetail.Rows[0]["RecordID"]));
                    db.Commands[0].Parameters.Add(new Parameter("@barangID", SqlDbType.VarChar, dtNotaBeliDetail.Rows[0]["BarangID"]));
                    db.Commands[0].Parameters.Add(new Parameter("@tglKoreksi", SqlDbType.DateTime, txtTglKoreksi.DateValue));
                    db.Commands[0].Parameters.Add(new Parameter("@noKoreksi", SqlDbType.VarChar, txtNoKoreksi.Text));
                    db.Commands[0].Parameters.Add(new Parameter("@qtyNotaBaru", SqlDbType.Int, txtQtyNota2.GetIntValue));
                    db.Commands[0].Parameters.Add(new Parameter("@hrgBeliBaru", SqlDbType.Money, double.Parse(txtHrgBeli2.Text)));
                    db.Commands[0].Parameters.Add(new Parameter("@catatan", SqlDbType.VarChar, txtCatatan.Text));
                    db.Commands[0].Parameters.Add(new Parameter("@pemasok", SqlDbType.VarChar, dtNotaBeliDetail.Rows[0]["Pemasok"]));
                    db.Commands[0].Parameters.Add(new Parameter("@sumber", SqlDbType.VarChar, "NPB"));
                    db.Commands[0].Parameters.Add(new Parameter("@linkID", SqlDbType.VarChar, ""));
                    db.Commands[0].Parameters.Add(new Parameter("@hrgBeliKoreksi", SqlDbType.Money, hrgKoreksi));
                    db.Commands[0].Parameters.Add(new Parameter("@qtyNotaKoreksi", SqlDbType.Int, qtyKoreksi));
                    db.Commands[0].Parameters.Add(new Parameter("@syncFlag", SqlDbType.Bit, 0));
                    db.Commands[0].Parameters.Add(new Parameter("@lastUpdatedBy", SqlDbType.VarChar, SecurityManager.UserID));
                    db.Commands[0].ExecuteNonQuery();
                }
                this.DialogResult = DialogResult.OK;
                MessageBox.Show("Data telah disimpan");
            }
            catch (Exception ex)
            {
                Error.LogError(ex);
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }
Ejemplo n.º 3
0
        private void cmdSave_Click(object sender, EventArgs e)
        {
            switch (formMode)
            {
            case enumFormMode.New:
                try
                {
                    this.Cursor = Cursors.WaitCursor;
                    if (lookupStock.BarangID == "")
                    {
                        lookupStock.Focus();
                        return;
                    }

                    if (txtQtyDO.GetIntValue <= 0 || txtQtyKirim.GetIntValue < 0)
                    {
                        txtQtyDO.Focus();
                        return;
                    }

                    #region "Stok Minus Lock New"

                    using (Stock st = new Stock())
                    {
                        st.AddList(lookupStock.BarangID, "", txtQtyKirim.GetIntValue);
                        // pass = st.Pass();
                        if (!st.Pass())
                        {
                            MessageBox.Show("Tidak Bisa Proses,\n nilai transaksi menyebabkan stok minus! ", "Warning");
                            st.ReportMinus();

                            if (MessageBox.Show("Cetak Form Opname?", "Opname", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                            {
                                st.PrintOutMinus();
                            }

                            txtQtyKirim.Focus();
                            txtQtyKirim.SelectAll();
                            return;
                        }
                    }
                    #endregion

                    using (Database db = new Database())
                    {
                        DataTable dt = new DataTable();
                        db.Commands.Add(db.CreateCommand("usp_AntarGudangDetail_Insert"));
                        db.Commands[0].Parameters.Add(new Parameter("@RowID", SqlDbType.UniqueIdentifier, Guid.NewGuid()));
                        db.Commands[0].Parameters.Add(new Parameter("@HeaderID", SqlDbType.UniqueIdentifier, _HeaderID));
                        db.Commands[0].Parameters.Add(new Parameter("@RecordID", SqlDbType.VarChar, Tools.CreateFingerPrint()));
                        db.Commands[0].Parameters.Add(new Parameter("@TransactionID", SqlDbType.VarChar, _TransactionID));
                        db.Commands[0].Parameters.Add(new Parameter("@QtyDO", SqlDbType.Int, txtQtyDO.GetIntValue));
                        db.Commands[0].Parameters.Add(new Parameter("@QtyKirim", SqlDbType.Int, txtQtyKirim.GetIntValue));
                        db.Commands[0].Parameters.Add(new Parameter("@QtyTerima", SqlDbType.Int, txtQtyTerima.GetIntValue));
                        db.Commands[0].Parameters.Add(new Parameter("@KodeBarang", SqlDbType.VarChar, lookupStock.BarangID));
                        db.Commands[0].Parameters.Add(new Parameter("@Catatan", SqlDbType.VarChar, txtCatatan.Text));
                        db.Commands[0].Parameters.Add(new Parameter("@Ongkos", SqlDbType.Int, 0));
                        db.Commands[0].Parameters.Add(new Parameter("@lastUpdatedBy", SqlDbType.VarChar, SecurityManager.UserID));
                        dt = db.Commands[0].ExecuteDataTable();

                        if (dt.Rows.Count > 0)
                        {
                            MessageBox.Show("Kode barang:" + lookupStock.BarangID + " tidak bisa diinput dua kali");
                            lookupStock.Focus();
                            return;
                        }
                    }

                    using (Database db = new Database())
                    {
                        db.Commands.Add(db.CreateCommand("psp_StokGudang_Recalculation"));
                        db.Commands[0].Parameters.Add(new Parameter("@gudangID", SqlDbType.VarChar, GlobalVar.Gudang));
                        db.Commands[0].Parameters.Add(new Parameter("@barangID", SqlDbType.VarChar, lookupStock.BarangID));
                        db.Commands[0].Parameters.Add(new Parameter("@lastUpdatedBy", SqlDbType.VarChar, SecurityManager.UserID));
                        db.Commands[0].ExecuteNonQuery();
                    }
                    this.DialogResult = DialogResult.OK;
                    if (this.DialogResult == DialogResult.OK)
                    {
                        if (this.Caller is frmAntarGudang)
                        {
                            ArusStock.frmAntarGudang frmcaller = (ArusStock.frmAntarGudang) this.Caller;
                            frmcaller.RefreshDetail();
                            frmcaller.FindDetail("RowIDD", _RowID.ToString());
                        }
                    }
                    cmdClose.PerformClick();
                }
                catch (Exception ex)
                {
                    Error.LogError(ex);
                }
                finally
                {
                    this.Cursor = Cursors.Default;
                }
                break;

            case enumFormMode.Update:
                try
                {
                    this.Cursor = Cursors.WaitCursor;
                    #region "Stok Minus Lock Update"
                    if (_DrGudang == GlobalVar.Gudang)
                    {
                        using (Stock st = new Stock())
                        {
                            st.AddList(lookupStock.BarangID, "", txtQtyKirim.GetIntValue - VBefore);
                            // pass = st.Pass();
                            if (!st.Pass())
                            {
                                MessageBox.Show("Tidak Bisa Proses ", "Warning");
                                st.ReportMinus();

                                if (MessageBox.Show("Cetak Form Opname?", "Opname", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                                {
                                    st.PrintOutMinus();
                                }

                                txtQtyKirim.Focus();
                                txtQtyKirim.SelectAll();
                                return;
                            }
                        }
                    }



                    #endregion

                    using (Database db = new Database())
                    {
                        DataTable dt = new DataTable();
                        db.Commands.Add(db.CreateCommand("usp_AntarGudangDetail_Update"));
                        db.Commands[0].Parameters.Add(new Parameter("@RowID", SqlDbType.UniqueIdentifier, _RowID));
                        db.Commands[0].Parameters.Add(new Parameter("@HeaderID", SqlDbType.UniqueIdentifier, _HeaderID));
                        db.Commands[0].Parameters.Add(new Parameter("@QtyDO", SqlDbType.Int, txtQtyDO.GetIntValue));
                        db.Commands[0].Parameters.Add(new Parameter("@QtyKirim", SqlDbType.Int, txtQtyKirim.GetIntValue));
                        db.Commands[0].Parameters.Add(new Parameter("@QtyTerima", SqlDbType.Int, txtQtyTerima.GetIntValue));
                        db.Commands[0].Parameters.Add(new Parameter("@KodeBarang", SqlDbType.VarChar, lookupStock.BarangID));
                        db.Commands[0].Parameters.Add(new Parameter("@Catatan", SqlDbType.VarChar, txtCatatan.Text));
                        db.Commands[0].Parameters.Add(new Parameter("@lastUpdatedBy", SqlDbType.VarChar, SecurityManager.UserID));

                        dt = db.Commands[0].ExecuteDataTable();
                        if (dt.Rows.Count > 0)
                        {
                            MessageBox.Show("Kode barang:" + lookupStock.BarangID + " tidak bisa diinput dua kali");
                            lookupStock.Focus();
                            return;
                        }
                    }

                    using (Database db = new Database())
                    {
                        db.Commands.Add(db.CreateCommand("psp_StokGudang_Recalculation"));
                        db.Commands[0].Parameters.Add(new Parameter("@gudangID", SqlDbType.VarChar, GlobalVar.Gudang));
                        db.Commands[0].Parameters.Add(new Parameter("@barangID", SqlDbType.VarChar, lookupStock.BarangID));
                        db.Commands[0].Parameters.Add(new Parameter("@lastUpdatedBy", SqlDbType.VarChar, SecurityManager.UserID));
                        db.Commands[0].ExecuteNonQuery();
                    }
                }
                catch (Exception ex)
                {
                    Error.LogError(ex);
                }
                finally
                {
                    this.Cursor = Cursors.Default;
                }
                break;
            }

            this.DialogResult = DialogResult.OK;

            if (formMode == enumFormMode.New)
            {
                //MessageBox.Show("Data telah tersimpan");
                lookupStock.NamaStock = "";
                lookupStock.BarangID  = "";
                txtCatatan.Text       = "";
                txtQtyDO.Text         = "0";
                txtQtyKirim.Text      = "0";
                txtQtyTerima.Text     = "0";
            }
            else
            {
                cmdClose.PerformClick();
            }
        }
Ejemplo n.º 4
0
        private void cmdSave_Click(object sender, EventArgs e)
        {
            if (!ValidateInput())
            {
                return;
            }

            try
            {
                this.Cursor = Cursors.WaitCursor;
                _notaIDBaru = Guid.Empty;
                string notaRecID = "";
                string catatan   = cboKategori.SelectedValue.ToString() + " " + txtCatatan.Text;
                if (cboKodeRetur.SelectedValue.ToString() == "1")
                {
                    _notaIDBaru = (Guid)dtNota.Rows[0]["RowID"];
                    notaRecID   = dtNota.Rows[0]["RecordID"].ToString();
                }

                switch (_formMode)
                {
                case enumFormMode.New:
                    #region "Stok Minus Lock New"

                    using (Stock st = new Stock())
                    {
                        st.AddList(lookupStock.BarangID, "", txtQtyGudang.GetIntValue);


                        // pass = st.Pass();
                        if (!st.Pass())
                        {
                            MessageBox.Show("Tidak Bisa Proses,\n nilai transaksi menyebabkan stok minus! ", "Warning");


                            st.ReportMinus();
                            if (MessageBox.Show("Cetak Form Opname?", "Opname", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                            {
                                st.PrintOutMinus();
                            }

                            this.Close();
                            return;
                        }
                    }
                    #endregion
                    _rowID = Guid.NewGuid();
                    using (Database db = new Database())
                    {
                        db.Commands.Add(db.CreateCommand("usp_ReturPembelianDetail_INSERT"));
                        db.Commands[0].Parameters.Add(new Parameter("@rowID", SqlDbType.UniqueIdentifier, _rowID));
                        db.Commands[0].Parameters.Add(new Parameter("@headerID", SqlDbType.UniqueIdentifier, _headerID));
                        db.Commands[0].Parameters.Add(new Parameter("@notaBeliDetailID", SqlDbType.UniqueIdentifier, _notaIDBaru));
                        db.Commands[0].Parameters.Add(new Parameter("@recordID", SqlDbType.VarChar, Tools.CreateFingerPrint()));
                        db.Commands[0].Parameters.Add(new Parameter("@returID", SqlDbType.VarChar, dtReturHeader.Rows[0]["ReturID"]));
                        db.Commands[0].Parameters.Add(new Parameter("@notaBeliDetailRecID", SqlDbType.VarChar, notaRecID));
                        db.Commands[0].Parameters.Add(new Parameter("@barangID", SqlDbType.VarChar, lookupStock.BarangID));
                        db.Commands[0].Parameters.Add(new Parameter("@KodeRetur", SqlDbType.VarChar, cboKodeRetur.SelectedValue.ToString()));
                        db.Commands[0].Parameters.Add(new Parameter("@qtyGudang", SqlDbType.Int, txtQtyGudang.GetIntValue));
                        db.Commands[0].Parameters.Add(new Parameter("@qtyTerima", SqlDbType.Int, txtQtyGudang.GetIntValue));
                        db.Commands[0].Parameters.Add(new Parameter("@hrgBeli", SqlDbType.Money, double.Parse(txtHrgBeli.Text)));
                        db.Commands[0].Parameters.Add(new Parameter("@hrgNet", SqlDbType.Money, 0));
                        db.Commands[0].Parameters.Add(new Parameter("@hrgPokok", SqlDbType.Money, double.Parse(txtHrgBeli.Text)));
                        db.Commands[0].Parameters.Add(new Parameter("@hppSolo", SqlDbType.Money, double.Parse(txtHrgBeli.Text)));
                        db.Commands[0].Parameters.Add(new Parameter("@catatan", SqlDbType.VarChar, catatan));
                        db.Commands[0].Parameters.Add(new Parameter("@TglKeluar", SqlDbType.DateTime, dtReturHeader.Rows[0]["TglKeluar"]));
                        db.Commands[0].Parameters.Add(new Parameter("@kodeGudang", SqlDbType.VarChar, GlobalVar.Gudang));
                        db.Commands[0].Parameters.Add(new Parameter("@SyncFlag", SqlDbType.Bit, 0));
                        db.Commands[0].Parameters.Add(new Parameter("@lastUpdatedBy", SqlDbType.VarChar, SecurityManager.UserID));
                        db.Commands[0].ExecuteDataTable();
                    }
                    this.DialogResult = DialogResult.OK;
                    MessageBox.Show("Data telah disimpan");
                    this.Clear();
                    lookupStock.Focus();
                    break;

                case enumFormMode.Update:
                    #region "Stok Minus Lock New"

                    using (Stock st = new Stock())
                    {
                        st.AddList(lookupStock.BarangID, "", txtQtyGudang.GetIntValue - _qtyBefore);


                        // pass = st.Pass();
                        if (!st.Pass())
                        {
                            MessageBox.Show("Tidak Bisa Proses ", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);


                            st.ReportMinus();
                            if (MessageBox.Show("Cetak Form Opname?", "Opname", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                            {
                                st.PrintOutMinus();
                            }

                            this.Close();
                            return;
                        }
                    }
                    #endregion
                    using (Database db = new Database())
                    {
                        db.Commands.Add(db.CreateCommand("usp_ReturPembelianDetail_UPDATE"));
                        db.Commands[0].Parameters.Add(new Parameter("@rowID", SqlDbType.UniqueIdentifier, _rowID));
                        db.Commands[0].Parameters.Add(new Parameter("@headerID", SqlDbType.UniqueIdentifier, _headerID));
                        db.Commands[0].Parameters.Add(new Parameter("@notaBeliDetailID", SqlDbType.UniqueIdentifier, _notaIDBaru));
                        db.Commands[0].Parameters.Add(new Parameter("@recordID", SqlDbType.VarChar, dtReturDetail.Rows[0]["RecordID"]));
                        db.Commands[0].Parameters.Add(new Parameter("@returID", SqlDbType.VarChar, dtReturDetail.Rows[0]["ReturID"]));
                        db.Commands[0].Parameters.Add(new Parameter("@notaBeliDetailRecID", SqlDbType.VarChar, notaRecID));
                        db.Commands[0].Parameters.Add(new Parameter("@barangID", SqlDbType.VarChar, lookupStock.BarangID));
                        db.Commands[0].Parameters.Add(new Parameter("@KodeRetur", SqlDbType.VarChar, cboKodeRetur.SelectedValue.ToString()));
                        db.Commands[0].Parameters.Add(new Parameter("@qtyGudang", SqlDbType.Int, txtQtyGudang.GetIntValue));
                        db.Commands[0].Parameters.Add(new Parameter("@qtyTerima", SqlDbType.Int, txtQtyGudang.GetIntValue));
                        db.Commands[0].Parameters.Add(new Parameter("@hrgBeli", SqlDbType.Money, double.Parse(txtHrgBeli.Text)));
                        db.Commands[0].Parameters.Add(new Parameter("@hrgNet", SqlDbType.Money, 0));
                        db.Commands[0].Parameters.Add(new Parameter("@hrgPokok", SqlDbType.Money, double.Parse(txtHrgBeli.Text)));
                        db.Commands[0].Parameters.Add(new Parameter("@hppSolo", SqlDbType.Money, double.Parse(txtHrgBeli.Text)));
                        db.Commands[0].Parameters.Add(new Parameter("@catatan", SqlDbType.VarChar, catatan));
                        db.Commands[0].Parameters.Add(new Parameter("@TglKeluar", SqlDbType.DateTime, dtReturDetail.Rows[0]["TglKeluar"]));
                        db.Commands[0].Parameters.Add(new Parameter("@kodeGudang", SqlDbType.VarChar, GlobalVar.Gudang));
                        db.Commands[0].Parameters.Add(new Parameter("@lastUpdatedBy", SqlDbType.VarChar, SecurityManager.UserID));
                        db.Commands[0].ExecuteDataTable();
                    }
                    this.DialogResult = DialogResult.OK;
                    MessageBox.Show("Data telah disimpan");
                    this.Close();
                    break;
                }
            }
            catch (Exception ex)
            {
                Error.LogError(ex);
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }
        private void InsertDataTypeSeimbang()
        {
            if (ctr < 2)
            {
                if (kodeBarang[0] == lookupStock1.BarangID && ctr == 1)
                {
                    MessageBox.Show("Kode Barang: " + lookupStock1.BarangID + " tidak dapat diinput lebih dari satu kali");
                    lookupStock1.Focus();
                    return;
                }

                newGuid[ctr]    = Guid.NewGuid();
                qtyMutasi[ctr]  = txtJumlah.GetIntValue;
                kodeBarang[ctr] = lookupStock1.BarangID;
                keterangan[ctr] = txtCatatan.Text;

                txtJumlah.Text  = "-" + txtJumlah.Text;
                txtCatatan.Text = string.Empty;
                lookupStock1.ResetAll();

                txtJumlah.Enabled = false;

                ctr++;

                if (ctr == 2)
                {
                    #region "Stok Minus Lock New"

                    using (Stock st = new Stock())
                    {
                        st.AddList(kodeBarang[1], "", Math.Abs(qtyMutasi[1]));
                        // pass = st.Pass();
                        if (!st.Pass())
                        {
                            MessageBox.Show("Tidak Bisa Proses,\n nilai transaksi menyebabkan stok minus! ", "Warning");
                            st.ReportMinus();

                            if (MessageBox.Show("Cetak Form Opname?", "Opname", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                            {
                                st.PrintOutMinus();
                            }

                            this.DialogResult = DialogResult.No;
                            cmdCancel.PerformClick();
                            return;
                        }
                    }



                    #endregion
                    try
                    {
                        this.Cursor = Cursors.WaitCursor;
                        using (Database db = new Database())
                        {
                            //_rowID = ;


                            DataTable dt = new DataTable();
                            db.Commands.Add(db.CreateCommand("usp_MutasiDetail_Insert"));

                            for (int i = 0; i <= 1; i++)
                            {
                                db.Commands[0].Parameters.Clear();
                                db.Commands[0].Parameters.Add(new Parameter("@RowID", SqlDbType.UniqueIdentifier, newGuid[i]));
                                db.Commands[0].Parameters.Add(new Parameter("@HeaderID", SqlDbType.UniqueIdentifier, _headerID));
                                db.Commands[0].Parameters.Add(new Parameter("@MutasiID", SqlDbType.VarChar, _MutasiID));
                                db.Commands[0].Parameters.Add(new Parameter("@QtyMutasi", SqlDbType.Int, qtyMutasi[i]));
                                db.Commands[0].Parameters.Add(new Parameter("@KodeBarang", SqlDbType.VarChar, kodeBarang[i]));
                                db.Commands[0].Parameters.Add(new Parameter("@Keterangan", SqlDbType.VarChar, keterangan[i]));
                                db.Commands[0].Parameters.Add(new Parameter("@SyncFlag", SqlDbType.Bit, 0));
                                db.Commands[0].Parameters.Add(new Parameter("@RecordID", SqlDbType.VarChar, Tools.CreateFingerPrint()));
                                db.Commands[0].Parameters.Add(new Parameter("@lastUpdatedBy", SqlDbType.VarChar, SecurityManager.UserID));
                                db.Commands[0].Parameters.Add(new Parameter("@kdGudang", SqlDbType.VarChar, GlobalVar.Gudang));
                                dt = db.Commands[0].ExecuteDataTable();
                            }

                            this.DialogResult = DialogResult.OK;
                            CloseForm();
                            cmdCancel.PerformClick();
                        }
                    }
                    catch (System.Exception ex)
                    {
                        Error.LogError(ex);
                    }
                    finally
                    {
                        this.Cursor = Cursors.Default;
                    }
                }
            }
        }
Ejemplo n.º 6
0
        private void cmdAdd_Click(object sender, EventArgs e)

        {
            ///MessageBox.Show(Tools.AutoNumbering("NoNota", "ISADBDepoRetail.dbo.NotaPenjualan").ToString());
            //return;
            dt.AcceptChanges();
            double _totalHrg    = 0;// double.Parse(dt.Compute("SUM(TotalHrg)", string.Empty).ToString());
            int    x            = 0;
            double _disc1       = 0;
            double _disc2       = 0;
            double _disc3       = 0;
            double _discFormula = 0;
            double _harga3D     = 0;
            bool   isBonusan    = false;

            if (!Validasichecker())
            {
                return;
            }

            #region "Stok Minus Lock New"

            DataRow[] dr1 = dt.Select("QtySisa>0 AND StatusDO='BOLEH'");
            using (Stock st = new Stock())
            {
                foreach (DataRow drd in dr1)
                {
                    st.AddList(drd["BarangID"].ToString(), "", Convert.ToInt32(drd["QtySisa"]));
                }
                // pass = st.Pass();
                if (!st.Pass())
                {
                    MessageBox.Show("Tidak Bisa Proses,\n nilai transaksi menyebabkan stok minus! ", "Warning");

                    if (MessageBox.Show("Batal Seluruh Nota  ?", "Batal", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        st.ReportMinus();
                        if (MessageBox.Show("Cetak Form Opname?", "Opname", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                        {
                            st.PrintOutMinus();
                        }
                        this.DialogResult = DialogResult.No;
                        this.Close();
                        return;
                    }
                    else
                    {
                        st.ReportMinus();
                        if (MessageBox.Show("Cetak Form Opname?", "Opname", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                        {
                            st.PrintOutMinus();
                        }

                        for (int i = 0; i < st.GetListBarangs.Count; i++)
                        {
                            if (st.ListBarangs(i).SaldoStok - st.ListBarangs(i).QtyTrans < 0)
                            {
                                var rows = dt.Select("BarangID='" + st.ListBarangs(i).KodeBarang + "'");

                                foreach (var row in rows)
                                {
                                    row.Delete();
                                }
                                dt.AcceptChanges();
                            }
                        }
                    }
                }
            }


            int sum = 0;
            for (int i = 0; i < dataGridDetailDO.Rows.Count; ++i)
            {
                sum += Convert.ToInt32(dataGridDetailDO.Rows[i].Cells["QtyNota"].Value);
            }
            if (sum == 0)
            {
                MessageBox.Show("Tidak bisa simpan record dengan Qty. Nota = 0. Mohon diisi Qty. Nota atau batalkan", "Cak Qty Nota");
                return;
            }

            #endregion


            //#region RpaccPiutang
            //DataTable dtt = new DataTable();
            //dtt = dt.Copy();
            //dr1 = dtt.Select("QtySisa>0 AND StatusDO='BOLEH'");
            //double _RpDO = 0;
            //int xx = 0;
            //foreach (DataRow drr in dr1)
            //{
            //    xx++;
            //    double qtDo = double.Parse(Tools.isNull(drr["QtySisa"], "0").ToString());
            //    double Hrjl = double.Parse(Tools.isNull(drr["HrgJual"], "0").ToString());
            //    double RpDo = qtDo * Hrjl;
            //    _disc1 = double.Parse(Tools.isNull(drr["Disc1"], "0").ToString());
            //    _disc2 = double.Parse(Tools.isNull(drr["Disc2"], "0").ToString());
            //    _disc3 = double.Parse(Tools.isNull(drr["Disc3"], "0").ToString());
            //    if (drr["DiscFormula"].ToString() == string.Empty)
            //    {
            //        _discFormula = 0;
            //    }

            //    DataTable dtNet3 = new DataTable();
            //    using (Database db = new Database())
            //    {
            //        db.Commands.Add(db.CreateCommand("usp_GetNet3Disc"));
            //        db.Commands[0].Parameters.Add(new Parameter("@jmlHrg", SqlDbType.Money, RpDo));
            //        db.Commands[0].Parameters.Add(new Parameter("@disc1", SqlDbType.Decimal, _disc1));
            //        db.Commands[0].Parameters.Add(new Parameter("@disc2", SqlDbType.Decimal, _disc2));
            //        db.Commands[0].Parameters.Add(new Parameter("@disc3", SqlDbType.Decimal, _disc3));
            //        db.Commands[0].Parameters.Add(new Parameter("@discFormula", SqlDbType.VarChar, _discFormula));
            //        dtNet3 = db.Commands[0].ExecuteDataTable();
            //    }

            //    if (drr["BarangID"].ToString().Substring(0, 3).Equals("FXB"))
            //        _RpDO = _RpDO + 0;
            //    else
            //        _RpDO = _RpDO + double.Parse(Tools.isNull(dtNet3.Rows[0]["HrgNet3Disc"], "0").ToString());
            //}


            //if (_RpDO > _rpSisaACCPiutang)
            //{
            //    MessageBox.Show("Nilai Nota Rp. " + _RpDO + "\n  Lebih besar dari nilai ACC piutang Rp. "
            //        + _rpACCPiutang + "\nProsess pembuatan nota tidak dapat dilanjutkan");
            //    this.DialogResult = DialogResult.No;
            //    this.Close();
            //    return;
            //}


            //if (xx==0)
            //{
            //    DataTable dtBonus = new DataTable();
            //    dtBonus = dt.Copy();
            //    DataRow[] drBonus = dtBonus.Select("BarangID LIKE 'FXB%'");

            //    if (dt.Rows.Count > 0 && drBonus.Length == dt.Rows.Count)
            //    {
            //        isBonusan = true;
            //    }

            //    if (!isBonusan)
            //    {
            //        MessageBox.Show("Nilai DO : 0 \nProsess pembuatan nota tidak dapat dilanjutkan");
            //        this.DialogResult = DialogResult.No;
            //        this.Close();
            //        return;
            //    }
            //}
            //#endregion


            //for (x=0; x < dt.Rows.Count; x++)
            //{
            //    double qtDo = double.Parse(Tools.isNull(dt.Rows[x]["QtySisa"], "0").ToString());
            //    double Hrjl = double.Parse(Tools.isNull(dt.Rows[x]["HrgJual"], "0").ToString());
            //    _totalHrg   = qtDo * Hrjl;
            //    //_totalHrg = double.Parse(Tools.isNull(dt.Rows[x]["TotalHrg"], "").ToString());
            //    _disc1 = double.Parse(Tools.isNull(dt.Rows[x]["Disc1"], "").ToString());
            //    _disc2 = double.Parse(Tools.isNull(dt.Rows[x]["Disc2"], "").ToString());
            //    _disc3 = double.Parse(Tools.isNull(dt.Rows[x]["Disc3"], "").ToString());
            //    if (dt.Rows[x]["DiscFormula"].ToString() == string.Empty)
            //    {
            //        _discFormula = 0;
            //    }

            //    DataTable dtNet3Disc = new DataTable();
            //    using (Database db = new Database())
            //    {
            //        db.Commands.Add(db.CreateCommand("usp_GetNet3Disc"));
            //        db.Commands[0].Parameters.Add(new Parameter("@jmlHrg", SqlDbType.Money, _totalHrg));
            //        db.Commands[0].Parameters.Add(new Parameter("@disc1", SqlDbType.Decimal, _disc1));
            //        db.Commands[0].Parameters.Add(new Parameter("@disc2", SqlDbType.Decimal, _disc2));
            //        db.Commands[0].Parameters.Add(new Parameter("@disc3", SqlDbType.Decimal, _disc3));
            //        db.Commands[0].Parameters.Add(new Parameter("@discFormula", SqlDbType.VarChar, _discFormula));
            //        dtNet3Disc = db.Commands[0].ExecuteDataTable();
            //    }
            //    if (dt.Rows[x]["BarangID"].ToString().Substring(0, 3).Equals("FXB"))
            //        _harga3D =_harga3D+ 0;
            //    else
            //        _harga3D = _harga3D + double.Parse(Tools.isNull(dtNet3Disc.Rows[0]["HrgNet3Disc"], "0").ToString());
            //}

            double _totalHrgNota = _harga3D;
            string cCab1         = dtDO.Rows[0]["Cabang1"].ToString().Trim();
            string cCab2         = dtDO.Rows[0]["Cabang2"].ToString().Trim();

            //if (_totalHrgNota > _rpSisaACCPiutang)
            //{
            //    if (cCab1 == GlobalVar.CabangID || cCab2 == GlobalVar.CabangID)
            //    {
            //        MessageBox.Show("Nilai Nota Rp. " + _totalHrgNota + "\nlebih besar dari nilai ACC piutang Rp. "
            //            + _rpACCPiutang + "\nProsess pembuatan nota tidak dapat dilanjutkan");
            //        return;
            //    }
            //}

            cCab1 = dtDO.Rows[0]["Cabang1"].ToString().Trim();
            if (cCab1 == GlobalVar.CabangID)
            {
                //if (dtDO.Rows[0]["NoACCPiutang"].ToString() != "BONUSAN")
                //{
                //    if (_totalHrgNota > TokoPlafon.SisaPlafon(_kodeToko, _transType))
                //    {
                //        MessageBox.Show("Tidak bisa buat nota. Nilai Nota melebihi Sisa Plafon toko. \n" +
                //                        "Silahkan melakukan pengajuan plafon ke PS HO");
                //        this.DialogResult = DialogResult.No;
                //        return;
                //    }
                //}
            }

            try
            {
                int k; int l;
                k = 0; l = 0;
                _notaHeaderRowID = Guid.NewGuid();
                string _notaHeaderRecID = Tools.CreateShortFingerPrint(k);
                string _notaDetailRecID = string.Empty;
                // Add new Nota Penjualan Header
                this.Cursor = Cursors.WaitCursor;
                string temp = string.Empty;
                //Generate Nomor Nota
                string kodeNota  = "";
                string nomorNota = "";
                string PTpattern = "KH,TH,KL,TL";


                string    depan    = "";
                string    belakang = "";
                int       iNomor;
                int       lebar;
                int       lebarOriginal = 0;
                int       ctr           = 0;
                int       lastCtr       = 0;
                int       ctrBef        = 0;
                DataTable dtNum;
                int       countRows = 0;

                if (IsTokoPT())
                {
                    string transType = _transType;
                    if (PTpattern.Contains(transType))
                    {
                        kodeNota = "NOMOR_NOTA_TAX_2";
                    }
                    else
                    {
                        kodeNota = "NOMOR_NOTA_TAX";
                    }
                    depan = GetInitialPT();
                }
                else
                {
                    if (Tools.Left(dtDO.Rows[0]["Cabang1"].ToString(), 1) == "9")
                    {
                        kodeNota = "NOMOR_NOTA_PS";
                    }
                    else
                    {
                        kodeNota = "NOMOR_NOTA";
                    }

                    depan = Tools.GeneralInitial();
                }

                if (DateTime.Today <= GlobalVar.LastClosingDate)
                {
                    throw new Exception(string.Format(ISA.Toko.Messages.Error.AlreadyClosingPJT, GlobalVar.LastClosingDate));
                }
                //dtNum = Tools.GetGeneralNumerator(kodeNota, depan);
                //lebarOriginal = int.Parse(dtNum.Rows[0]["Lebar"].ToString());
                //lebar = lebarOriginal;
                //iNomor = int.Parse(dtNum.Rows[0]["Nomor"].ToString());

                //belakang = dtNum.Rows[0]["Belakang"].ToString();
                //iNomor++;
                //nomorNota = Tools.AutoNumbering("NoNota", "ISADBDepoRetail.dbo.NotaPenjualan");
                nomorNota = _NoDo;

                //PROSES NOTA
                using (Database db = new Database())
                {
                    db.Commands.Add(db.CreateCommand("usp_NotaPenjualan_INSERT"));    //udah cek heri

                    db.Commands[0].Parameters.Add(new Parameter("@rowID", SqlDbType.UniqueIdentifier, _notaHeaderRowID));
                    db.Commands[0].Parameters.Add(new Parameter("@recID", SqlDbType.VarChar, _notaHeaderRecID));     //_notaHeaderRecID));
                    db.Commands[0].Parameters.Add(new Parameter("@DOID", SqlDbType.UniqueIdentifier, _doID));
                    db.Commands[0].Parameters.Add(new Parameter("@htrID", SqlDbType.VarChar, _doHtrID));
                    db.Commands[0].Parameters.Add(new Parameter("@noSJ", SqlDbType.VarChar, nomorNota));    //Tools.GetGeneralNumerator("NOMOR_NOTA").Rows[0].ToString()));

                    db.Commands[0].Parameters.Add(new Parameter("@noNota", SqlDbType.VarChar, nomorNota));
                    db.Commands[0].Parameters.Add(new Parameter("@tglNota", SqlDbType.DateTime, GlobalVar.DateOfServer));
                    db.Commands[0].Parameters.Add(new Parameter("@tglSJ", SqlDbType.DateTime, DateTime.Today));
                    db.Commands[0].Parameters.Add(new Parameter("@tglTerima", SqlDbType.DateTime, SqlDateTime.Null));
                    db.Commands[0].Parameters.Add(new Parameter("@tglSerahTerimaChecker", SqlDbType.DateTime, SqlDateTime.Null));
                    db.Commands[0].Parameters.Add(new Parameter("@cabang1", SqlDbType.VarChar, dtDO.Rows[0]["Cabang1"]));
                    db.Commands[0].Parameters.Add(new Parameter("@cabang2", SqlDbType.VarChar, dtDO.Rows[0]["Cabang2"]));
                    db.Commands[0].Parameters.Add(new Parameter("@cabang3", SqlDbType.VarChar, dtDO.Rows[0]["Cabang3"]));
                    db.Commands[0].Parameters.Add(new Parameter("@kodeSales", SqlDbType.VarChar, dtDO.Rows[0]["KodeSales"]));
                    db.Commands[0].Parameters.Add(new Parameter("@kodeToko", SqlDbType.VarChar, dtDO.Rows[0]["KodeToko"]));
                    db.Commands[0].Parameters.Add(new Parameter("@alamatKirim", SqlDbType.VarChar, ""));
                    db.Commands[0].Parameters.Add(new Parameter("@kota", SqlDbType.VarChar, ""));
                    db.Commands[0].Parameters.Add(new Parameter("@isClosed", SqlDbType.Bit, 0));
                    db.Commands[0].Parameters.Add(new Parameter("@catatan1", SqlDbType.VarChar, _Cat1));
                    db.Commands[0].Parameters.Add(new Parameter("@catatan2", SqlDbType.VarChar, _Cat2));
                    db.Commands[0].Parameters.Add(new Parameter("@catatan3", SqlDbType.VarChar, _Cat3));
                    db.Commands[0].Parameters.Add(new Parameter("@catatan4", SqlDbType.VarChar, _Cat4));
                    db.Commands[0].Parameters.Add(new Parameter("@catatan5", SqlDbType.VarChar, _Cat5));
                    db.Commands[0].Parameters.Add(new Parameter("@syncFlag", SqlDbType.Bit, 0));
                    db.Commands[0].Parameters.Add(new Parameter("@linkID", SqlDbType.VarChar, ""));
                    db.Commands[0].Parameters.Add(new Parameter("@nPrint", SqlDbType.Int, 0));
                    db.Commands[0].Parameters.Add(new Parameter("@transactionType", SqlDbType.VarChar, _transType));
                    db.Commands[0].Parameters.Add(new Parameter("@hariKredit", SqlDbType.Int, _hariKredit));
                    db.Commands[0].Parameters.Add(new Parameter("@hariKirim", SqlDbType.Int, dtDO.Rows[0]["HariKirim"]));
                    db.Commands[0].Parameters.Add(new Parameter("@hariSales", SqlDbType.Int, dtDO.Rows[0]["HariSales"]));
                    db.Commands[0].Parameters.Add(new Parameter("@checker1", SqlDbType.UniqueIdentifier, lookupStafAdm1.RowID));
                    db.Commands[0].Parameters.Add(new Parameter("@checker2", SqlDbType.UniqueIdentifier, lookupStafAdm2.RowID));
                    db.Commands[0].Parameters.Add(new Parameter("@lastUpdatedBy", SqlDbType.VarChar, SecurityManager.UserID));


                    countRows = dt.Rows.Count;
                    DataRow[] dr = dt.Select("QtySisa>0 AND StatusDO='BOLEH'");

                    int a = 0;
                    foreach (DataRow drd in dr)
                    {
                        a++;
                    }

                    lastCtr = a;


                    db.BeginTransaction();
                    for (int j = 0; j < db.Commands.Count; j++)
                    {
                        db.Commands[j].ExecuteNonQuery();
                    }
                    db.CommitTransaction();

                    int counter = 0;
                    for (int i = 0; i < countRows; i++)
                    {
                        db.Commands.Clear();

                        int _qtySisa = (int)dataGridDetailDO.Rows[i].Cells["QtySisa"].Value;
                        int _qtyMin  = (int)dataGridDetailDO.Rows[i].Cells["QtyMin"].Value;

                        Guid   _doDetailID = (Guid)dataGridDetailDO.Rows[i].Cells["DetailRowID"].Value;
                        string _StatusDO   = dataGridDetailDO.Rows[i].Cells["StatusDO"].Value.ToString();

                        //db.Commands.Clear();

                        int _qtyNota = Convert.ToInt32(dataGridDetailDO.Rows[i].Cells["QtyNota"].Value);
                        if (_qtyNota > 0)
                        {
                            if (_qtySisa > 0 && _StatusDO.Equals("BOLEH") || isBonusan)
                            {
                                _notaDetailRecID = Tools.CreateShortFingerPrint(counter + 1);

                                temp = _notaDetailRecID;

                                db.Commands.Add(db.CreateCommand("usp_NotaPenjualanDetail_INSERT"));     // udah cek heri

                                db.Commands[0].Parameters.Add(new Parameter("@rowID", SqlDbType.UniqueIdentifier, Guid.NewGuid()));
                                db.Commands[0].Parameters.Add(new Parameter("@headerID", SqlDbType.UniqueIdentifier, _notaHeaderRowID));
                                db.Commands[0].Parameters.Add(new Parameter("@recID", SqlDbType.VarChar, _notaDetailRecID));
                                db.Commands[0].Parameters.Add(new Parameter("@htrID", SqlDbType.VarChar, _notaHeaderRecID));
                                db.Commands[0].Parameters.Add(new Parameter("@doID", SqlDbType.UniqueIdentifier, _doID));
                                db.Commands[0].Parameters.Add(new Parameter("@doDetailID", SqlDbType.UniqueIdentifier, _doDetailID));
                                db.Commands[0].Parameters.Add(new Parameter("@barangID", SqlDbType.VarChar, dataGridDetailDO.Rows[i].Cells["BarangID"].Value));
                                db.Commands[0].Parameters.Add(new Parameter("@kodeGudang", SqlDbType.VarChar, GlobalVar.Gudang));
                                db.Commands[0].Parameters.Add(new Parameter("@qtySJ", SqlDbType.Int, _qtySisa));
                                db.Commands[0].Parameters.Add(new Parameter("@hrgJual", SqlDbType.Money, dataGridDetailDO.Rows[i].Cells["HrgJual"].Value));
                                db.Commands[0].Parameters.Add(new Parameter("@disc1", SqlDbType.Decimal, dataGridDetailDO.Rows[i].Cells["DetailDisc1"].Value));
                                db.Commands[0].Parameters.Add(new Parameter("@disc2", SqlDbType.Decimal, dataGridDetailDO.Rows[i].Cells["DetailDisc2"].Value));
                                db.Commands[0].Parameters.Add(new Parameter("@disc3", SqlDbType.Decimal, dataGridDetailDO.Rows[i].Cells["DetailDisc3"].Value));
                                db.Commands[0].Parameters.Add(new Parameter("@discFormula", SqlDbType.VarChar, dataGridDetailDO.Rows[i].Cells["DetailDiscFormula"].Value));
                                db.Commands[0].Parameters.Add(new Parameter("@pot", SqlDbType.Money, dataGridDetailDO.Rows[i].Cells["Pot"].Value));
                                db.Commands[0].Parameters.Add(new Parameter("@qtyNota", SqlDbType.Int, _qtyNota));
                                db.Commands[0].Parameters.Add(new Parameter("@qtyKoli", SqlDbType.Int, 0));
                                db.Commands[0].Parameters.Add(new Parameter("@koliAwal", SqlDbType.Int, 0));
                                db.Commands[0].Parameters.Add(new Parameter("@koliAkhir", SqlDbType.Int, 0));
                                db.Commands[0].Parameters.Add(new Parameter("@noKoli", SqlDbType.VarChar, dataGridDetailDO.Rows[i].Cells["NoKoli"].Value.ToString()));
                                db.Commands[0].Parameters.Add(new Parameter("@catatan", SqlDbType.VarChar, dataGridDetailDO.Rows[i].Cells["Catatan"].Value.ToString()));
                                db.Commands[0].Parameters.Add(new Parameter("@syncFlag", SqlDbType.Bit, 0));
                                db.Commands[0].Parameters.Add(new Parameter("@ketKoli", SqlDbType.VarChar, ""));
                                db.Commands[0].Parameters.Add(new Parameter("@lastUpdatedBy", SqlDbType.VarChar, SecurityManager.UserID));
                                //tambahan fefe
                                db.Commands[0].Parameters.Add(new Parameter("@NPackingListPrint", SqlDbType.VarChar, ""));
                                ctr++;
                                counter++;
                            }


                            //EXECUTE ALL COMMANDS
                            db.BeginTransaction();
                            for (int j = 0; j < db.Commands.Count; j++)
                            {
                                db.Commands[j].ExecuteNonQuery();
                            }
                            db.CommitTransaction();
                        }
                        #region Insert Nota
                        if ((ctr % 20 == 0) && (ctr != 0) && (ctr != lastCtr) && (ctr != ctrBef))
                        {
                            //lastCtr = ctr;
                            ctrBef           = ctr;
                            _notaHeaderRowID = Guid.NewGuid();
                            _notaHeaderRecID = Tools.CreateShortFingerPrint(k);

                            //dtNum = Tools.GetGeneralNumerator(kodeNota);
                            //lebarOriginal = int.Parse(dtNum.Rows[0]["Lebar"].ToString());
                            ////lebar = lebarOriginal - 3;
                            ////Update 2013-05-28
                            //lebar = lebarOriginal;
                            //iNomor = int.Parse(dtNum.Rows[0]["Nomor"].ToString());

                            //belakang = dtNum.Rows[0]["Belakang"].ToString();
                            //iNomor++;
                            ////nomorNota = Tools.FormatNumerator(iNomor, lebar, depan, belakang);
                            //nomorNota = Tools.AutoNumbering("NoNota", "SADBDepoRetail.dbo.NotaPenjualan");
                            nomorNota = _NoDo;
                            db.Commands.Clear();
                            db.Commands.Add(db.CreateCommand("usp_NotaPenjualan_INSERT"));     //udah cek heri

                            db.Commands[0].Parameters.Add(new Parameter("@rowID", SqlDbType.UniqueIdentifier, _notaHeaderRowID));
                            db.Commands[0].Parameters.Add(new Parameter("@recID", SqlDbType.VarChar, _notaHeaderRecID));
                            db.Commands[0].Parameters.Add(new Parameter("@DOID", SqlDbType.UniqueIdentifier, _doID));
                            db.Commands[0].Parameters.Add(new Parameter("@htrID", SqlDbType.VarChar, _doHtrID));
                            db.Commands[0].Parameters.Add(new Parameter("@noSJ", SqlDbType.VarChar, nomorNota));    //Tools.GetGeneralNumerator("NOMOR_NOTA").Rows[0].ToString()));
                            db.Commands[0].Parameters.Add(new Parameter("@noNota", SqlDbType.VarChar, ""));
                            db.Commands[0].Parameters.Add(new Parameter("@tglNota", SqlDbType.DateTime, SqlDateTime.Null));
                            db.Commands[0].Parameters.Add(new Parameter("@tglSJ", SqlDbType.DateTime, DateTime.Today));
                            db.Commands[0].Parameters.Add(new Parameter("@tglTerima", SqlDbType.DateTime, SqlDateTime.Null));
                            db.Commands[0].Parameters.Add(new Parameter("@tglSerahTerimaChecker", SqlDbType.DateTime, SqlDateTime.Null));
                            db.Commands[0].Parameters.Add(new Parameter("@cabang1", SqlDbType.VarChar, dtDO.Rows[0]["Cabang1"]));
                            db.Commands[0].Parameters.Add(new Parameter("@cabang2", SqlDbType.VarChar, dtDO.Rows[0]["Cabang2"]));
                            db.Commands[0].Parameters.Add(new Parameter("@cabang3", SqlDbType.VarChar, dtDO.Rows[0]["Cabang3"]));
                            db.Commands[0].Parameters.Add(new Parameter("@kodeSales", SqlDbType.VarChar, dtDO.Rows[0]["KodeSales"]));
                            db.Commands[0].Parameters.Add(new Parameter("@kodeToko", SqlDbType.VarChar, dtDO.Rows[0]["KodeToko"]));
                            db.Commands[0].Parameters.Add(new Parameter("@alamatKirim", SqlDbType.VarChar, ""));
                            db.Commands[0].Parameters.Add(new Parameter("@kota", SqlDbType.VarChar, ""));
                            db.Commands[0].Parameters.Add(new Parameter("@isClosed", SqlDbType.Bit, 0));
                            db.Commands[0].Parameters.Add(new Parameter("@catatan1", SqlDbType.VarChar, _Cat1));
                            db.Commands[0].Parameters.Add(new Parameter("@catatan2", SqlDbType.VarChar, _Cat2));
                            db.Commands[0].Parameters.Add(new Parameter("@catatan3", SqlDbType.VarChar, _Cat3));
                            db.Commands[0].Parameters.Add(new Parameter("@catatan4", SqlDbType.VarChar, _Cat4));
                            db.Commands[0].Parameters.Add(new Parameter("@catatan5", SqlDbType.VarChar, _Cat5));
                            db.Commands[0].Parameters.Add(new Parameter("@syncFlag", SqlDbType.Bit, 0));
                            db.Commands[0].Parameters.Add(new Parameter("@linkID", SqlDbType.VarChar, ""));
                            db.Commands[0].Parameters.Add(new Parameter("@nPrint", SqlDbType.Int, 0));
                            db.Commands[0].Parameters.Add(new Parameter("@transactionType", SqlDbType.VarChar, _transType));
                            db.Commands[0].Parameters.Add(new Parameter("@hariKredit", SqlDbType.Int, _hariKredit));
                            db.Commands[0].Parameters.Add(new Parameter("@hariKirim", SqlDbType.Int, dtDO.Rows[0]["HariKirim"]));
                            db.Commands[0].Parameters.Add(new Parameter("@hariSales", SqlDbType.Int, dtDO.Rows[0]["HariSales"]));
                            db.Commands[0].Parameters.Add(new Parameter("@checker1", SqlDbType.UniqueIdentifier, lookupStafAdm1.RowID));
                            db.Commands[0].Parameters.Add(new Parameter("@checker2", SqlDbType.UniqueIdentifier, lookupStafAdm2.RowID));
                            db.Commands[0].Parameters.Add(new Parameter("@lastUpdatedBy", SqlDbType.VarChar, SecurityManager.UserID));

                            //db.Commands.Add(db.CreateCommand("usp_Numerator_UPDATE"));
                            //db.Commands[1].Parameters.Add(new Parameter("@doc", SqlDbType.VarChar, kodeNota));
                            //db.Commands[1].Parameters.Add(new Parameter("@depan", SqlDbType.VarChar, depan));
                            //db.Commands[1].Parameters.Add(new Parameter("@belakang", SqlDbType.VarChar, belakang));
                            //db.Commands[1].Parameters.Add(new Parameter("@nomor", SqlDbType.Int, iNomor));
                            //db.Commands[1].Parameters.Add(new Parameter("@lebar", SqlDbType.VarChar, lebarOriginal));
                            //db.Commands[1].Parameters.Add(new Parameter("@lastUpdatedBy", SqlDbType.VarChar, SecurityManager.UserID));

                            countRows = dt.Rows.Count;

                            db.BeginTransaction();
                            for (int j = 0; j < db.Commands.Count; j++)
                            {
                                db.Commands[0].ExecuteNonQuery();
                            }
                            db.CommitTransaction();
                        }
                        k++;
                        #endregion

                        #region recalculate
                        string barangID = dataGridDetailDO.Rows[i].Cells["BarangID"].Value.ToString();
                        string gudang   = GlobalVar.Gudang;
                        Recalculate(barangID, gudang);
                        //MessageBox.Show("Proses RECALCULATE Selesai");
                        this.Cursor = Cursors.Default;

                        #endregion
                    }
                    this.DialogResult = DialogResult.OK;
                    MessageBox.Show(Messages.Confirm.UpdateSuccess + "\nNomor Nota: " + nomorNota);
                }
            }
            catch (Exception ex)
            {
                Error.LogError(ex);
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
            frmNotaJualBrowser frmCaller = (frmNotaJualBrowser)this.Caller;
            frmCaller.RefreshDataNotaJual();
            //}
            this.Close();
        }
Ejemplo n.º 7
0
        private void cmdSAVE_Click(object sender, EventArgs e)
        {
            if (!ValidateInput())
            {
                return;
            }

            try
            {
                GlobalVar.LastClosingDate = (DateTime)txtTglKoreksi.DateValue;
                if ((DateTime)txtTglKoreksi.DateValue <= GlobalVar.LastClosingDate)
                {
                    throw new Exception(string.Format(ISA.Toko.Messages.Error.AlreadyClosingPJT, GlobalVar.LastClosingDate));
                }
                double hrgKoreksi = double.Parse(txtHrgNet2.Text) - double.Parse(txtHrgNet1.Text);
                int    qtyKoreksi = txtQtyNota2.GetIntValue - txtQtyNota1.GetIntValue;
                this.Cursor = Cursors.WaitCursor;

                #region "Stok Minus Lock New"
                if (qtyKoreksi > 0)
                {
                    using (Stock st = new Stock())
                    {
                        st.AddList(dtReturBeliDetail.Rows[0]["BarangID"].ToString(), "", qtyKoreksi);

                        if (!st.Pass())
                        {
                            MessageBox.Show("Tidak Bisa Proses,\n nilai transaksi menyebabkan stok minus! ", "Warning");


                            st.ReportMinus();
                            if (MessageBox.Show("Cetak Form Opname?", "Opname", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                            {
                                st.PrintOutMinus();
                            }

                            this.Close();
                            return;
                        }
                    }
                }

                #endregion

                _rowID = Guid.NewGuid();
                DataTable dtMessage = new DataTable();
                using (Database db = new Database())
                {
                    db.Commands.Add(db.CreateCommand("usp_KoreksiReturPembelian_INSERT"));
                    db.Commands[0].Parameters.Add(new Parameter("@rowID", SqlDbType.UniqueIdentifier, _rowID));
                    db.Commands[0].Parameters.Add(new Parameter("@recordID", SqlDbType.VarChar, Tools.CreateFingerPrint()));
                    db.Commands[0].Parameters.Add(new Parameter("@returBeliDetailID", SqlDbType.UniqueIdentifier, dtReturBeliDetail.Rows[0]["RowID"]));
                    db.Commands[0].Parameters.Add(new Parameter("@returBeliDetailRecID", SqlDbType.VarChar, dtReturBeliDetail.Rows[0]["RecordID"]));
                    db.Commands[0].Parameters.Add(new Parameter("@barangID", SqlDbType.VarChar, dtReturBeliDetail.Rows[0]["BarangID"]));
                    db.Commands[0].Parameters.Add(new Parameter("@tglKoreksi", SqlDbType.DateTime, txtTglKoreksi.DateValue));
                    db.Commands[0].Parameters.Add(new Parameter("@qtyNotaBaru", SqlDbType.Int, txtQtyNota2.GetIntValue));
                    db.Commands[0].Parameters.Add(new Parameter("@hrgBeliBaru", SqlDbType.Money, double.Parse(txtHrgBeli2.Text)));
                    db.Commands[0].Parameters.Add(new Parameter("@catatan", SqlDbType.VarChar, txtCatatan.Text));
                    db.Commands[0].Parameters.Add(new Parameter("@pemasok", SqlDbType.VarChar, dtReturBeliDetail.Rows[0]["Pemasok"]));
                    db.Commands[0].Parameters.Add(new Parameter("@sumber", SqlDbType.VarChar, "NRB"));
                    db.Commands[0].Parameters.Add(new Parameter("@linkID", SqlDbType.VarChar, ""));
                    db.Commands[0].Parameters.Add(new Parameter("@hrgBeliKoreksi", SqlDbType.Money, hrgKoreksi));
                    db.Commands[0].Parameters.Add(new Parameter("@qtyNotaKoreksi", SqlDbType.Int, qtyKoreksi));
                    db.Commands[0].Parameters.Add(new Parameter("@syncFlag", SqlDbType.Bit, 0));
                    db.Commands[0].Parameters.Add(new Parameter("@lastUpdatedBy", SqlDbType.VarChar, SecurityManager.UserID));
                    dtMessage = db.Commands[0].ExecuteDataTable();

                    if (dtMessage.Rows.Count > 0)
                    {
                        if (dtMessage.Rows[0]["pesan"].ToString() == "Data Berhasil Insert")
                        {
                            this.DialogResult = DialogResult.OK;
                            this.Close();
                        }
                        else
                        {
                            MessageBox.Show(dtMessage.Rows[0]["pesan"].ToString()); return;
                        }
                        //if (dt.Rows[0]["pesan"].ToString() == "Data Sudah Ada")
                        //{
                        //    txtKode.Text = string.Empty;
                        //    txtKode.Focus();
                        //    return;
                        //}
                    }
                }
                //this.DialogResult = DialogResult.OK;
                //MessageBox.Show("Data telah disimpan");
                //this.Close();
            }
            catch (Exception ex)
            {
                Error.LogError(ex);
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }