Пример #1
0
        private double GetTotalNota(ReturBeliProduk obj)
        {
            var total = obj.item_retur.Where(f => f.Produk != null && f.entity_state != EntityState.Deleted)
                        .Sum(f => f.jumlah_retur * f.harga);

            return(Math.Round(total, MidpointRounding.AwayFromZero));
        }
Пример #2
0
        private double GetTotalNota(ReturBeliProduk obj)
        {
            var total = obj.item_retur.Where(f => f.Produk != null && f.entity_state != EntityState.Deleted)
                        .Sum(f => f.jumlah_retur * f.harga);

            return(total);
        }
Пример #3
0
        public int Update(ReturBeliProduk obj)
        {
            var result = 0;

            try
            {
                _context.BeginTransaction();

                var transaction = _context.transaction;

                obj.total_nota = GetTotalNota(obj);

                // update header
                result = _context.db.Update <ReturBeliProduk>(obj, transaction) ? 1 : 0;

                // delete detail
                foreach (var item in obj.item_retur_deleted)
                {
                    result = _context.db.Delete <ItemReturBeliProduk>(item, transaction) ? 1 : 0;
                }

                // insert/update detail
                foreach (var item in obj.item_retur.Where(f => f.Produk != null))
                {
                    item.retur_beli_produk_id = obj.retur_beli_produk_id;
                    item.pengguna_id          = obj.pengguna_id;

                    if (item.entity_state == EntityState.Added)
                    {
                        item.item_retur_beli_produk_id = _context.GetGUID();
                        _context.db.Insert <ItemReturBeliProduk>(item, transaction);

                        result = 1;
                    }
                    else if (item.entity_state == EntityState.Modified)
                    {
                        result = _context.db.Update <ItemReturBeliProduk>(item, transaction) ? 1 : 0;
                    }

                    // update entity state
                    item.entity_state = EntityState.Unchanged;
                }

                _context.Commit();

                LogicalThreadContext.Properties["NewValue"] = obj.ToJson();
                _log.Info("Update data");

                result = 1;
            }
            catch (Exception ex)
            {
                _log.Error("Error:", ex);
            }

            return(result);
        }
Пример #4
0
        public ReturBeliProduk GetByID(string id)
        {
            ReturBeliProduk obj = null;

            using (IDapperContext context = new DapperContext())
            {
                _unitOfWork = new UnitOfWork(context, _log);
                obj         = _unitOfWork.ReturBeliProdukRepository.GetByID(id);
            }

            return(obj);
        }
Пример #5
0
        public int Delete(ReturBeliProduk obj)
        {
            var result = 0;

            using (IDapperContext context = new DapperContext())
            {
                _unitOfWork = new UnitOfWork(context, _log);
                result      = _unitOfWork.ReturBeliProdukRepository.Delete(obj);
            }

            return(result);
        }
Пример #6
0
        public int Update(ReturBeliProduk obj)
        {
            var result = 0;

            using (IDapperContext context = new DapperContext())
            {
                IUnitOfWork uow = new UnitOfWork(context, _log);
                result = uow.ReturBeliProdukRepository.Update(obj);
            }

            return(result);
        }
        public FrmEntryReturPembelianProduk(string header, ReturBeliProduk retur, IReturBeliProdukBll bll)
            : base()
        {
            InitializeComponent();
            ColorManagerHelper.SetTheme(this, this);

            base.SetHeader(header);
            base.SetButtonSelesaiToBatal();
            this._bll      = bll;
            this._retur    = retur;
            this._supplier = retur.Supplier;
            this._beli     = retur.BeliProduk;
            this._log      = MainProgram.log;
            this._pengguna = MainProgram.pengguna;

            txtNota.Text    = this._retur.nota;
            txtNota.Enabled = false;

            dtpTanggal.Value   = (DateTime)this._retur.tanggal;
            txtSupplier.Text   = this._supplier.nama_supplier;
            txtKeterangan.Text = this._retur.keterangan;

            if (this._beli != null)
            {
                txtNotaBeli.Text    = this._beli.nota;
                txtNotaBeli.Enabled = false;

                LoadItemBeli(this._beli);
            }

            // simpan data lama
            _listOfItemReturOld.Clear();
            foreach (var item in this._retur.item_retur)
            {
                _listOfItemReturOld.Add(new ItemReturBeliProduk
                {
                    item_retur_beli_produk_id = item.item_retur_beli_produk_id,
                    jumlah_retur = item.jumlah_retur,
                    harga        = item.harga
                });
            }

            _listOfItemRetur = this._retur.item_retur;
            _listOfItemRetur.Add(new ItemReturBeliProduk()); // add dummy objek

            InitGridControl(gridControl);

            RefreshTotal();
        }
Пример #8
0
        public int Delete(ReturBeliProduk obj)
        {
            var result = 0;

            try
            {
                result = _context.db.Delete <ReturBeliProduk>(obj) ? 1 : 0;
            }
            catch (Exception ex)
            {
                _log.Error("Error:", ex);
            }

            return(result);
        }
Пример #9
0
        public int Update(ReturBeliProduk obj, ref ValidationError validationError)
        {
            var validatorResults = _validator.Validate(obj);

            if (!validatorResults.IsValid)
            {
                foreach (var failure in validatorResults.Errors)
                {
                    validationError.Message      = failure.ErrorMessage;
                    validationError.PropertyName = failure.PropertyName;
                    return(0);
                }
            }

            return(Update(obj));
        }
Пример #10
0
        public int Save(ReturBeliProduk obj)
        {
            var result = 0;

            try
            {
                _context.BeginTransaction();

                var transaction = _context.transaction;

                obj.retur_beli_produk_id = _context.GetGUID();

                obj.total_nota = GetTotalNota(obj);

                // insert header
                _context.db.Insert <ReturBeliProduk>(obj, transaction);

                // insert detil
                foreach (var item in obj.item_retur.Where(f => f.Produk != null))
                {
                    if (item.produk_id.Length > 0)
                    {
                        item.item_retur_beli_produk_id = _context.GetGUID();
                        item.retur_beli_produk_id      = obj.retur_beli_produk_id;
                        item.pengguna_id = obj.pengguna_id;

                        _context.db.Insert <ItemReturBeliProduk>(item, transaction);

                        // update entity state
                        item.entity_state = EntityState.Unchanged;
                    }
                }

                _context.Commit();

                LogicalThreadContext.Properties["NewValue"] = obj.ToJson();
                _log.Info("Tambah data");

                result = 1;
            }
            catch (Exception ex)
            {
                _log.Error("Error:", ex);
            }

            return(result);
        }
Пример #11
0
        public void SaveTest()
        {
            var obj = new ReturBeliProduk
            {
                beli_produk_id = "27d40236-c8ab-44be-bc47-7a9bbd68c31e",
                supplier_id    = "af01c916-7976-4518-a563-9d2a1851a912",
                nota           = _bll.GetLastNota(),
                tanggal        = DateTime.Today,
                keterangan     = "keterangan header"
            };

            var listOfItemBeli = new List <ItemReturBeliProduk>();

            listOfItemBeli.Add(new ItemReturBeliProduk {
                item_beli_id = "a53a632c-2759-4d85-acc6-0cbb18a0c88b", Produk = new Produk {
                    produk_id = "6e587b32-9d87-4ec3-8e7c-ce15c7b0aecd"
                }, produk_id = "6e587b32-9d87-4ec3-8e7c-ce15c7b0aecd", harga = 50000, jumlah = 4, jumlah_retur = 2
            });
            listOfItemBeli.Add(new ItemReturBeliProduk {
                item_beli_id = "c414c56c-fd01-4e88-bae1-96bfe0f8196a", Produk = new Produk {
                    produk_id = "d7e888eb-6f9b-43ef-9a72-212588d2fb38"
                }, produk_id = "d7e888eb-6f9b-43ef-9a72-212588d2fb38", harga = 2500, jumlah = 2, jumlah_retur = 1
            });

            obj.item_retur = listOfItemBeli; // menghubungkan retur dan item retur

            var validationError = new ValidationError();

            var result = _bll.Save(obj, ref validationError);

            Console.WriteLine("Error : " + validationError.Message);

            Assert.IsTrue(result != 0);

            var newObj = _bll.GetByID(obj.retur_beli_produk_id);

            Assert.IsNotNull(newObj);
            Assert.AreEqual(obj.retur_beli_produk_id, newObj.retur_beli_produk_id);
            Assert.AreEqual(obj.beli_produk_id, newObj.beli_produk_id);
            Assert.AreEqual(obj.pengguna_id, newObj.pengguna_id);
            Assert.AreEqual(obj.supplier_id, newObj.supplier_id);
            Assert.AreEqual(obj.nota, newObj.nota);
            Assert.AreEqual(obj.tanggal, newObj.tanggal);
            Assert.AreEqual(obj.keterangan, newObj.keterangan);
            Assert.AreEqual(obj.total_nota, newObj.total_nota);
        }
Пример #12
0
        public int Delete(ReturBeliProduk obj)
        {
            var result = 0;

            try
            {
                result = _context.db.Delete <ReturBeliProduk>(obj) ? 1 : 0;

                if (result > 0)
                {
                    LogicalThreadContext.Properties["OldValue"] = obj.ToJson();
                    _log.Info("Hapus data");
                }
            }
            catch (Exception ex)
            {
                _log.Error("Error:", ex);
            }

            return(result);
        }
Пример #13
0
        public ReturBeliProduk GetByID(string id)
        {
            ReturBeliProduk obj = null;

            try
            {
                _sql = SQL_TEMPLATE.Replace("{WHERE}", "WHERE t_retur_beli_produk.retur_beli_produk_id = @id");
                _sql = _sql.Replace("{ORDER BY}", "");

                obj = MappingRecordToObject(_sql, new { id }).SingleOrDefault();

                if (obj != null)
                {
                    // load item retur
                    obj.item_retur = GetItemRetur(obj.retur_beli_produk_id);
                }
            }
            catch (Exception ex)
            {
                _log.Error("Error:", ex);
            }

            return(obj);
        }
        protected override void Simpan()
        {
            if (this._supplier == null || txtSupplier.Text.Length == 0)
            {
                MsgHelper.MsgWarning("'Supplier' tidak boleh kosong !");
                txtSupplier.Focus();

                return;
            }

            var total = SumGrid(this._listOfItemRetur);

            if (!(total > 0))
            {
                MsgHelper.MsgWarning("Anda belum melengkapi inputan data produk !");
                return;
            }

            if (!MsgHelper.MsgKonfirmasi("Apakah proses ingin dilanjutkan ?"))
            {
                return;
            }

            if (_isNewData)
            {
                _retur = new ReturBeliProduk();
            }

            _retur.beli_produk_id = this._beli.beli_produk_id;
            _retur.BeliProduk     = this._beli;
            _retur.pengguna_id    = this._pengguna.pengguna_id;
            _retur.Pengguna       = this._pengguna;
            _retur.supplier_id    = this._supplier.supplier_id;
            _retur.Supplier       = this._supplier;
            _retur.nota           = txtNota.Text;
            _retur.tanggal        = dtpTanggal.Value;
            _retur.keterangan     = txtKeterangan.Text;

            _retur.item_retur = this._listOfItemRetur.Where(f => f.Produk != null).ToList();

            if (!_isNewData) // update
            {
                _retur.item_retur_deleted = _listOfItemReturDeleted;
            }

            var result          = 0;
            var validationError = new ValidationError();

            using (new StCursor(Cursors.WaitCursor, new TimeSpan(0, 0, 0, 0)))
            {
                if (_isNewData)
                {
                    result = _bll.Save(_retur, ref validationError);
                }
                else
                {
                    result = _bll.Update(_retur, ref validationError);
                }

                if (result > 0)
                {
                    Listener.Ok(this, _isNewData, _retur);

                    _supplier = null;
                    _listOfItemRetur.Clear();
                    _listOfItemReturDeleted.Clear();

                    this.Close();
                }
                else
                {
                    if (validationError.Message.NullToString().Length > 0)
                    {
                        MsgHelper.MsgWarning(validationError.Message);
                        base.SetFocusObject(validationError.PropertyName, this);
                    }
                    else
                    {
                        MsgHelper.MsgUpdateError();
                    }
                }
            }
        }