コード例 #1
0
        public void InsertTest()
        {
            using (var trans = TransHelper.NewScope())
            {
                //  arrange
                var expected = StokInDataFactory();

                //  act
                _stokInDal.Insert(expected);

                //  assert
            }
        }
コード例 #2
0
        public void AddStok(string brgID, decimal qty, double hpp,
                            string tgl, string jam, string trsMasukID,
                            string trsDOID, string jenisMutasiID)
        {
            #region VALIDASI-INPUT
            //  validasi brg
            var brg = _brgBL.GetData(brgID);
            if (brg == null)
            {
                var errMsg = string.Format("BrgID invalid: {0}", brgID);
                throw new ArgumentException(errMsg);
            }

            //  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 PERSIAPAN-ID-TABLE
            //  contoh StokInID = SI.1901.00031
            var prefixStokIn = PREFIX_STOK_IN + DateTime.Now.ToString(".yyMM.");
            var stokInID     = _paramNoBL.GenNewID(prefixStokIn, 12);
            //  contoh StokInOutID = SI.1901.00031.001
            var prefixStokInOut = stokInID + ".";
            var stokInOutID     = _paramNoBL.GenNewID(prefixStokInOut, 16);
            //  contoh StokControlID = DO.1901.00021-B5431
            var stokControlID = string.Format("{0}-{1}", trsDOID, brgID);
            #endregion

            #region PROSES-INSERT-DATA
            using (var trans = TransHelper.NewScope())
            {
                var stokIn = new StokInModel
                {
                    StokInID = stokInID,
                    BrgID    = brgID,

                    TglMasuk   = tgl,
                    JamMasuk   = jam,
                    TrsMasukID = trsMasukID,

                    QtyIn    = qty,
                    QtySaldo = qty,
                    Hpp      = hpp,

                    StokControlID = stokControlID,
                    TrsDOID       = trsDOID,
                };
                _stokInDal.Insert(stokIn);

                var stokInOut = new StokInOutModel
                {
                    StokInID    = stokInID,
                    StokInOutID = stokInOutID,

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

                    QtyIn     = qty,
                    QtyOut    = 0,
                    Hpp       = hpp,
                    HargaJual = 0
                };
                _stokInOutDal.Insert(stokInOut);
                trans.Complete();
            }
            #endregion
        }