コード例 #1
0
        public void ListDataByStokControl()
        {
            using (var trans = TransHelper.NewScope())
            {
                //  arrange
                var item1 = StokInDataFactory();
                _stokInDal.Insert(item1);
                var item2 = StokInDataFactory2();
                item2.StokControlID = item1.StokControlID;
                _stokInDal.Insert(item2);
                var expected = new List <StokInModel>
                {
                    item1, item2
                };

                //  act
                var actual = _stokInDal.ListDataByStokControl(item1.StokControlID);

                //  assert
                actual.Should().BeEquivalentTo(expected,
                                               config => config
                                               .Excluding(x => x.BrgName));
            }
        }
コード例 #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
        }