private void ViewStockCorrectionDetail(StockCorrection stockCorrection)
        {
            txtID.Text = stockCorrection.ID.ToString();
            txtStockCorrectionId.Text = stockCorrection.ID.ToString();
            lblCode.Text = stockCorrection.Code;

            dtpDate.Text = stockCorrection.Date.ToShortDateString();

            txtNotes.Text = stockCorrection.Notes;
        }
        private void PopulateStockCorrection(StockCorrection stockCorrection)
        {
            var item = new ListViewItem(stockCorrection.ID.ToString());

            item.SubItems.Add(stockCorrection.Date.ToString("dd/MM/yyyy"));
            item.SubItems.Add(stockCorrection.Code);
            item.SubItems.Add(stockCorrection.CreatedDate.ToString("dd/MM/yyyy"));
            item.SubItems.Add(stockCorrection.CreatedBy);
            item.SubItems.Add(stockCorrection.ModifiedDate.ToString("dd/MM/yyyy"));
            item.SubItems.Add(stockCorrection.ModifiedBy);
            lvwStockCorrection.Items.Add(item);
        }
        public void UpdateHeader(IEntityManager em, Transaction tx, StockCorrection stockCorrection)
        {
            string[] columns = { "CorrectionDate", "Notes", "PrintCounter",
                                 "ModifiedDate",   "ModifiedBy" };

            object[] values = { stockCorrection.Date.ToShortDateString(), stockCorrection.Notes, stockCorrection.PrintCounter,
                                DateTime.Now.ToShortDateString(),         Store.ActiveUser };

            var q = new Query().Select(columns).From(tableName).Update(values)
                    .Where("CorrectionCode").Equal(stockCorrection.Code);

            em.ExecuteNonQuery(q.ToSql(), tx);
        }
        public void SaveHeader(IEntityManager em, Transaction tx, StockCorrection stockCorrection)
        {
            string[] columns = { "ID",          "CorrectionCode", "CorrectionDate", "Notes", "PrintCounter",
                                 "CreatedDate", "CreatedBy" };

            object[] values = { Guid.NewGuid(),                   stockCorrection.Code, stockCorrection.Date.ToShortDateString(), stockCorrection.Notes,
                                stockCorrection.PrintCounter,
                                DateTime.Now.ToShortDateString(), Store.ActiveUser };

            var q = new Query().Select(columns).From(tableName).Insert(values);

            em.ExecuteNonQuery(q.ToSql(), tx);
        }
        public void Update(StockCorrection stockCorrection)
        {
            Transaction tx = null;

            try
            {
                using (var em = EntityManagerFactory.CreateInstance(ds))
                {
                    tx = em.BeginTransaction();

                    string[] columns = { "CorrectionCode", "CorrectionDate", "Notes", "PrintCounter",
                                         "ModifiedDate",   "ModifiedBy" };

                    object[] values = { stockCorrection.Code,             stockCorrection.Date, stockCorrection.Notes,
                                        stockCorrection.PrintCounter,
                                        DateTime.Now.ToShortDateString(), Store.ActiveUser };

                    var q = new Query().Select(columns).From(tableName).Update(values)
                            .Where("ID").Equal("{" + stockCorrection.ID + "}");

                    em.ExecuteNonQuery(q.ToSql(), tx);

                    ////detail dihapus -> update qty
                    var list = stockCorrectionItemRepository.GetByStockCorrectionId(stockCorrection.ID);
                    foreach (var stockCorrectionItem in list)
                    {
                        productQtyRepository.UpdateQtyCorrection(Store.ActiveMonth, Store.ActiveYear, stockCorrectionItem.ProductId, stockCorrectionItem.QtyPlus, stockCorrectionItem.QtyMinus, false);
                    }

                    stockCorrectionItemRepository.Delete(em, tx, stockCorrection.ID);

                    foreach (var stockCorrectionItem in stockCorrection.StockCorrectionItems)
                    {
                        stockCorrectionItem.StockCorrectionId = stockCorrection.ID;

                        stockCorrectionItemRepository.Save(em, tx, stockCorrectionItem);

                        ////update product
                        productQtyRepository.UpdateQtyCorrection(Store.ActiveMonth, Store.ActiveYear, stockCorrectionItem.ProductId, stockCorrectionItem.QtyPlus, stockCorrectionItem.QtyMinus, true);
                    }

                    tx.Commit();
                }
            }
            catch (Exception ex)
            {
                tx.Rollback();

                throw ex;
            }
        }
        private void tsbDelete_Click(object sender, EventArgs e)
        {
            var userAccess = userAccessRepository.GetAll();

            bool isAllowed = userAccess.Exists(u => u.FullName == Store.ActiveUser &&
                                               u.ObjectName == "Koreksi Stok" && u.IsDelete);

            if (isAllowed == false && Store.IsAdministrator == false)
            {
                MessageBox.Show("Anda tidak dapat merubah", "Perhatian", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                if (Store.IsPeriodClosed)
                {
                    MessageBox.Show("Tidak dapat menambah/ubah/hapus \n\n Periode : " + Store.GetMonthName(Store.ActiveMonth) + " " + Store.ActiveYear + "\n\n" + "Sudah Tutup Buku", "Perhatian",
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    StockCorrection stockCorrection = stockCorrectionRepository.GetById(new Guid(txtID.Text));
                    if (stockCorrection.Notes.Contains("DIBATALKAN"))
                    {
                        MessageBox.Show("Sudah pernah di hapus ", "Perhatian",
                                        MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }

                    else
                    {
                        if (MessageBox.Show("Anda yakin ingin menghapus '" + lblCode.Text + "'", "Perhatian",
                                            MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                        {
                            var stockCorrection1 = new StockCorrection();
                            stockCorrection1.ID    = new Guid(txtID.Text);
                            stockCorrection1.Notes = txtNotes.Text;

                            stockCorrectionRepository.Delete(stockCorrection1);
                            GetLastStockCorrection();
                        }

                        if (lvwStockCorrection.Items.Count == 0)
                        {
                            tsbEdit.Enabled   = false;
                            tsbDelete.Enabled = false;
                        }
                    }
                }
            }
        }
        public void UpdatePrintCounter(string stockCorrectionCode)
        {
            int printCounter = 0;

            using (var em = EntityManagerFactory.CreateInstance(ds))
            {
                StockCorrection stockCorrection = GetByCode(stockCorrectionCode);
                if (stockCorrection != null)
                {
                    printCounter = stockCorrection.PrintCounter + 1;
                    string sql = "UPDATE " + tableName + " SET PrintCounter = " + printCounter + " WHERE CorrectionCode='" + stockCorrectionCode + "'";
                    em.ExecuteNonQuery(sql);
                }
            }
        }
        public void Delete(StockCorrection stockCorrection)
        {
            Transaction tx = null;

            try
            {
                using (var em = EntityManagerFactory.CreateInstance(ds))
                {
                    tx = em.BeginTransaction();

                    String notes = "";
                    if (stockCorrection.Notes != "")
                    {
                        notes = "DIBATALKAN - " + stockCorrection.Notes;
                    }
                    else
                    {
                        notes = "DIBATALKAN";
                    }

                    string[] columns = { "Notes",
                                         "ModifiedDate", "ModifiedBy" };

                    object[] values = { notes,
                                        DateTime.Now.ToShortDateString(), Store.ActiveUser };

                    var q = new Query().Select(columns).From(tableName).Update(values)
                            .Where("ID").Equal("{" + stockCorrection.ID + "}");

                    em.ExecuteNonQuery(q.ToSql(), tx);

                    var itemList = stockCorrectionItemRepository.GetByStockCorrectionId(stockCorrection.ID);
                    foreach (var stockCorrectionItems in itemList)
                    {
                        stockCorrectionItemRepository.Delete(em, tx, stockCorrectionItems);

                        //productQtyRepository.UpdateQtyOut(Store.ActiveMonth, Store.ActiveYear, stockCorrectionItems.ProductId, stockCorrectionItems.Qty, false);
                    }

                    tx.Commit();
                }
            }
            catch (Exception ex)
            {
                tx.Rollback();
                throw ex;
            }
        }
        public StockCorrection GetLast(int month, int year)
        {
            StockCorrection stockCorrection = null;

            using (var em = EntityManagerFactory.CreateInstance(ds))
            {
                string sql = "SELECT TOP 1 ID, CorrectionCode, CorrectionDate, Notes, PrintCounter, "
                             + "CreatedDate, ModifiedDate, CreatedBy, ModifiedBy "
                             + "FROM "
                             + "StockCorrection "
                             + "WHERE Month(CorrectionDate)=" + month + " AND Year(CorrectionDate)=" + year
                             + " ORDER BY CorrectionCode DESC";

                stockCorrection = em.ExecuteObject <StockCorrection>(sql, new StockCorrectionMapper());
            }

            return(stockCorrection);
        }
        public void Save(StockCorrection stockCorrection)
        {
            Transaction tx = null;

            try
            {
                using (var em = EntityManagerFactory.CreateInstance(ds))
                {
                    tx = em.BeginTransaction();

                    Guid ID = Guid.NewGuid();

                    string[] columns = { "ID",          "CorrectionCode", "CorrectionDate", "Notes", "PrintCounter",
                                         "CreatedDate", "CreatedBy" };

                    object[] values = { ID,                               stockCorrection.Code, stockCorrection.Date.ToShortDateString(), stockCorrection.Notes,
                                        stockCorrection.PrintCounter,
                                        DateTime.Now.ToShortDateString(), Store.ActiveUser };

                    var q = new Query().Select(columns).From(tableName).Insert(values);

                    em.ExecuteNonQuery(q.ToSql(), tx);

                    foreach (var stockCorrectionItems in stockCorrection.StockCorrectionItems)
                    {
                        stockCorrectionItems.StockCorrectionId = ID;

                        stockCorrectionItemRepository.Save(em, tx, stockCorrectionItems);

                        //update product
                        productQtyRepository.UpdateQtyCorrection(Store.ActiveMonth, Store.ActiveYear, stockCorrectionItems.ProductId, stockCorrectionItems.QtyPlus, stockCorrectionItems.QtyMinus, true);
                    }

                    recordCounterRepository.UpdateStockCorrectionCounter(stockCorrection.Date.Month, stockCorrection.Date.Year);

                    tx.Commit();
                }
            }
            catch (Exception ex)
            {
                tx.Rollback();
                throw ex;
            }
        }
        public StockCorrection GetByCode(string code)
        {
            StockCorrection stockCorrection = null;

            using (var em = EntityManagerFactory.CreateInstance(ds))
            {
                string sql = "SELECT ID, CorrectionCode, CorrectionDate, Notes, PrintCounter, "
                             + "CreatedDate, ModifiedDate, CreatedBy, ModifiedBy "
                             + "FROM "
                             + "StockCorrection "
                             + "WHERE "
                             + "CorrectionCode='" + code + "'";


                stockCorrection = em.ExecuteObject <StockCorrection>(sql, new StockCorrectionMapper());
            }

            return(stockCorrection);
        }
Exemple #12
0
        private void tsbEdit_Click(object sender, EventArgs e)
        {
            var userAccess = userAccessRepository.GetAll();

            bool isAllowed = userAccess.Exists(u => u.FullName == Store.ActiveUser &&
                                               u.ObjectName == "Koreksi Stok" && u.IsEdit);

            if (isAllowed == false && Store.IsAdministrator == false)
            {
                MessageBox.Show("Anda tidak dapat merubah", "Perhatian", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                if (Store.IsPeriodClosed)
                {
                    MessageBox.Show("Tidak dapat menambah/ubah/hapus \n\n Periode : " + Store.GetMonthName(Store.ActiveMonth) + " " + Store.ActiveYear + "\n\n" + "Sudah Tutup Buku", "Perhatian",
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    StockCorrection stockCorrection = stockCorrectionRepository.GetById(new Guid(txtID.Text));

                    if (stockCorrection.Notes.Contains("DIBATALKAN"))
                    {
                        MessageBox.Show("Sudah pernah di hapus ", "Perhatian",
                                        MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        formMode  = FormMode.Edit;
                        this.Text = "Koreksi Stok - Edit";

                        EnableFormForEdit();
                    }
                }
            }
        }
        public StockCorrection GetById(Guid id)
        {
            StockCorrection stockCorrection = null;

            using (var em = EntityManagerFactory.CreateInstance(ds))
            {
                string sql = "SELECT ID, CorrectionCode, CorrectionDate, "
                             + "Notes, PrintCounter, "
                             + "CreatedDate,ModifiedDate, CreatedBy, ModifiedBy "
                             + "FROM "
                             + "StockCorrection "
                             + "WHERE "
                             + "ID='{" + id + "}'";

                stockCorrection = em.ExecuteObject <StockCorrection>(sql, new StockCorrectionMapper());

                if (stockCorrection != null)
                {
                    stockCorrection.StockCorrectionItems = stockCorrectionItemRepository.GetByStockCorrectionId(stockCorrection.ID);
                }
            }

            return(stockCorrection);
        }
Exemple #14
0
        private void SaveStockCorrection()
        {
            if (dtpDate.Value.Month != Store.ActiveMonth || dtpDate.Value.Year != Store.ActiveYear)
            {
                MessageBox.Show("Tanggal diluar periode aktif", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            else if (lvwStockCorrection.Items.Count == 0)
            {
                MessageBox.Show("Detail tidak boleh kosong", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                var stockCorrection = new StockCorrection();

                stockCorrection.Code      = lblCode.Text;
                stockCorrection.Date      = dtpDate.Value;
                stockCorrection.Notes     = txtNotes.Text;
                stockCorrection.CreatedBy = string.Empty;

                var stockCorrectionItems = new List <StockCorrectionItem>();

                foreach (ListViewItem item in lvwStockCorrection.Items)
                {
                    string productId  = item.SubItems[0].Text;
                    string qtyPlus    = item.SubItems[3].Text;
                    string qtyMinus   = item.SubItems[4].Text;
                    string valuePlus  = item.SubItems[5].Text;
                    string valueMinus = item.SubItems[6].Text;

                    StockCorrectionItem si = new StockCorrectionItem();

                    si.ProductId  = new Guid(productId);
                    si.QtyPlus    = int.Parse(qtyPlus.Replace(".", ""));
                    si.QtyMinus   = int.Parse(qtyMinus.Replace(".", ""));
                    si.ValuePlus  = decimal.Parse(valuePlus.Replace(".", ""));
                    si.ValueMinus = decimal.Parse(valueMinus.Replace(".", ""));
                    si.Notes      = "";

                    stockCorrectionItems.Add(si);
                }


                stockCorrection.StockCorrectionItems = stockCorrectionItems;


                if (formMode == FormMode.Add)
                {
                    stockCorrectionRepository.Save(stockCorrection);
                    ShowStockCorrectionReport();
                    GetLastStockCorrection();
                }
                else if (formMode == FormMode.Edit)
                {
                    stockCorrection.ID         = new Guid(txtID.Text);
                    stockCorrection.ModifiedBy = Store.ActiveUser;
                    stockCorrection.Notes      = txtNotes.Text;

                    stockCorrectionRepository.Update(stockCorrection);
                    ShowStockCorrectionReport();
                }

                LoadStockCorrectionItems(new Guid(txtID.Text));
                DisableForm();
                formMode = FormMode.View;

                FillCode();
                this.Text = "Koreksi Stok";
            }
        }