Beispiel #1
0
        public BPKasModel Generate(PenjualanModel penjualan)
        {
            var bpKas = new BPKasModel
            {
                BPKasID       = penjualan.PenjualanID,
                Tgl           = penjualan.TglPenjualan,
                Jam           = penjualan.JamPenjualan,
                Keterangan    = string.Format("Penjualan {0} a/n {1}", penjualan.PenjualanID, penjualan.BuyerName),
                NilaiTotalKas = 0
            };
            var listBpKasDetil = new List <BPKasDetilModel>();

            //  update jenisKasID di detil penjualan
            foreach (var item in penjualan.ListBayar)
            {
                var jenisBayar = _jenisBayarBL.GetData(item.JenisBayarID);
                var jenisKas   = _jenisKasBL.GetData(jenisBayar.JenisKasID);
                item.JenisKasID   = jenisKas.JenisKasID;
                item.JenisKasName = jenisKas.JenisKasName;
            }

            var listJenisKas = _jenisKasBL.ListData();
            int noUrut       = 1;

            foreach (var item in listJenisKas)
            {
                var bpKasDetil = new BPKasDetilModel
                {
                    BPKasID       = penjualan.PenjualanID,
                    BPKasDetilID  = penjualan.PenjualanID + '-' + noUrut.ToString().PadLeft(2, '0'),
                    JenisKasID    = item.JenisKasID,
                    JenisKasName  = item.JenisKasName,
                    NilaiKasMasuk = penjualan.ListBayar
                                    .Where(x => x.JenisKasID == item.JenisKasID)
                                    .Sum(x => x.NilaiBayar),
                };
                noUrut++;
                if (bpKasDetil.NilaiKasMasuk != 0)
                {
                    listBpKasDetil.Add(bpKasDetil);
                }
            }
            bpKas.ListDetil = listBpKasDetil;
            var result = Save(bpKas);

            return(result);
        }
        public ReturDepositModel Save(ReturDepositModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            //  validate depositID
            var deposit = _depositBL.GetData(model.DepositID);

            if (deposit == null)
            {
                throw new ArgumentException("DepositID invalid");
            }
            else
            {
                model.PihakKeduaName = deposit.PihakKeduaName;
            }

            //  validate jenisKas
            var jenisKas = _jenisKasBL.GetData(model.JenisKasID);

            if (jenisKas == null)
            {
                throw new ArgumentException("JenisKasID invalid");
            }
            else
            {
                model.JenisKasName = jenisKas.JenisKasName;
            }

            //  cek nilai retur harus antara 0 dan sisa deposit
            if (model.NilaiReturDeposit > model.NilaiSisaDeposit)
            {
                throw new ArgumentException("NilaiReturDeposit Invalid");
            }
            if (model.NilaiReturDeposit <= 0)
            {
                throw new ArgumentException("NilaiReturDeposit Invalid minus");
            }

            //  proses simpan
            using (var trans = TransHelper.NewScope())
            {
                if (model.ReturDepositID.Trim() == "")
                {
                    model.ReturDepositID = GenNewID();
                }

                // hapus data lama
                _returDepositDal.Delete(model.ReturDepositID);
                //  simpan data baru
                _returDepositDal.Insert(model);

                trans.Complete();
            }
            return(model);
        }
Beispiel #3
0
        public KasBonModel Save(KasBonModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            if (model.NilaiKasBon <= 0)
            {
                throw new ArgumentException("Nilai KasBon invalid");
            }

            var jenisKasBon = _jenisKasBonBL.GetData(model.PihakKeduaID);

            if (jenisKasBon == null)
            {
                throw new ArgumentException("PihakKeduaID invalid");
            }

            var jenisKas = _jenisKasBL.GetData(model.JenisKasID);

            if (jenisKas == null)
            {
                throw new ArgumentException("JenisKasID invalid");
            }

            bool isNew = false;

            if (model.KasBonID.Trim() == "")
            {
                isNew = true;
            }

            using (var trans = TransHelper.NewScope())
            {
                if (isNew)
                {
                    model.KasBonID = GenNewID();
                    _kasBonDal.Insert(model);
                }
                else
                {
                    _kasBonDal.Update(model);
                }
                trans.Complete();
            }

            return(model);
        }
Beispiel #4
0
        public BiayaModel Save(BiayaModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            if (model.NilaiBiaya <= 0)
            {
                throw new ArgumentException("Nilai Biaya invalid");
            }

            var jenisBiaya = _jenisBiayaBL.GetData(model.JenisBiayaID);

            if (jenisBiaya == null)
            {
                throw new ArgumentException("JenisBiayaID invalid");
            }

            var jenisKas = _jenisKasBL.GetData(model.JenisKasID);

            if (jenisKas == null)
            {
                throw new ArgumentException("JenisKasID invalid");
            }

            if (model.BiayaID.Trim() == "")
            {
                model.BiayaID = GenNewID();
            }

            using (var trans = TransHelper.NewScope())
            {
                //  hapus data lama
                _biayaDal.Delete(model.BiayaID);
                //  simpan data baru
                _biayaDal.Insert(model);

                trans.Complete();
            }

            return(model);
        }