예제 #1
0
        public void UpdateTest()
        {
            using (var trans = TransHelper.NewScope())
            {
                //  arrange
                var expected = StokInDataFactory();

                //  act
                _stokInDal.Update(expected);

                //  assert
            }
        }
예제 #2
0
        public void RemoveStok(string stokControlID, decimal qty, double hargaJual,
                               string tgl, string jam, string trsReffID,
                               string jenisMutasiID)
        {
            #region VALIDASI-INPUT
            //  cek jenis mutasi
            var jenisMutasi = _jenisMutasiBL.GetData(jenisMutasiID);
            if (jenisMutasi == null)
            {
                var errMsg = string.Format("JenisMutasiID invalid : {0}", jenisMutasiID);
                throw new ArgumentException(errMsg);
            }
            if (!jenisMutasi.IsBrgMasuk)
            {
                var errMsg = string.Format("JenisMutasiID invalid bukan BrgMasuk: {0}", jenisMutasiID);
                throw new ArgumentException(errMsg);
            }

            //  validasi tgl
            if (!tgl.IsValidTgl("dd-MM-yyyy"))
            {
                var errMsg = string.Format("Tgl invalid: {0}", tgl);
                throw new ArgumentException(errMsg);
            }
            //  validasi jam
            if (!tgl.IsValidJam("HH:mm:ss"))
            {
                var errMsg = string.Format("Jam invalid: {0}", jam);
                throw new ArgumentException(errMsg);
            }
            #endregion

            #region CEK-SALDO-STOK
            //  ambil semua StokIn yang StokControlID-nya sesuai parameter
            var listStokIn = _stokInDal.ListDataByStokControl(stokControlID);
            if (listStokIn == null)
            {
                throw new ArgumentException("StokControlID invalid");
            }
            //  sum qty saldo dan bandingkan
            var qtySaldo = listStokIn.Sum(x => x.QtySaldo);
            if (qtySaldo < qty)
            {
                throw new ArgumentException("Qty tidak mencukupi");
            }
            #endregion

            #region INSERT-STOK-IN-OUT
            var qtyRemoveSisa = qty;
            foreach (var item in listStokIn)
            {
                //  tentukan qty remove stok per StokIn
                decimal qtyRemove = 0;
                if (item.QtySaldo <= qtyRemoveSisa)
                {
                    qtyRemove = item.QtySaldo;
                }
                else
                {
                    qtyRemove = qtyRemoveSisa;
                }
                item.QtySaldo -= qtyRemove;
                qtyRemoveSisa -= qtyRemove;

                //  update saldo (StokIn)
                _stokInDal.Update(item);

                //  update detil history (StokInOut)
                var prefixStokInOut = item.StokInID + ".";
                var stokInOutID     = _paramNoBL.GenNewID(prefixStokInOut, 16);
                var stokInOut       = new StokInOutModel
                {
                    StokInID    = item.StokInID,
                    StokInOutID = stokInOutID,

                    TglTrs        = tgl,
                    JamTrs        = jam,
                    ReffTrsID     = trsReffID,
                    JenisMutasiID = jenisMutasiID,

                    QtyIn     = 0,
                    QtyOut    = qtyRemove,
                    Hpp       = item.Hpp,
                    HargaJual = hargaJual
                };
                _stokInOutDal.Insert(stokInOut);

                //  jika sudah berhasil remove sesuai qty, keluar
                if (qtyRemoveSisa <= 0)
                {
                    break;
                }
            }
            #endregion
        }