private void btnAddSparepart_Click(object sender, EventArgs e)
        {
            if (_presenter.IsUsedSparepartRequired() && !ckeIsReturnRequired.Checked)
            {
                this.ShowWarning("Pastikan barang bekas sudah diterima.");
                return;
            }

            if (SparepartToInsert == null || txtQty.Text == "0" || string.IsNullOrEmpty(txtQty.Text))
            {
                this.ShowWarning("Sparepart atau Jumlah harus diisi.");
                return;
            }

            int duplicateSparepartFound = SPKSparepartList.Where(s => s.Sparepart.Id == SparepartToInsert.Id).Count();

            if (duplicateSparepartFound < 1)
            {
                int pendingRequestSparepart = _presenter.getPendingSparpartQty();

                if (this.SparepartQty + pendingRequestSparepart <= SparepartToInsert.StockQty)
                {
                    _presenter.PopulateSparepartDetail();

                    decimal totalPrice = 0;

                    List <SPKDetailSparepartDetailViewModel> SelectedSPKSparepartDetailList = SPKSparepartDetailList.Where(x => x.SPKDetailSparepartId == SparepartId).ToList();

                    if (SelectedSPKSparepartDetailList != null && SelectedSPKSparepartDetailList.Count > 0)
                    {
                        foreach (var item in SelectedSPKSparepartDetailList)
                        {
                            if (item.PurchasingDetailId > 0)
                            {
                                totalPrice += item.PurchasingDetail.Price * item.Qty;
                            }
                            else if (item.SparepartManualTransactionId > 0)
                            {
                                totalPrice += item.SparepartManualTransaction.Price * item.Qty;
                            }
                        }

                        SPKSparepartList.Add(new SPKDetailSparepartViewModel
                        {
                            Sparepart     = SparepartToInsert,
                            SparepartId   = SparepartId,
                            TotalQuantity = SparepartQty,
                            TotalPrice    = totalPrice
                        });

                        RefreshSparepartGrid();
                        CalculateTotalSparepart();
                    }
                    else
                    {
                        this.ShowError(string.Format("Sparepart tidak tersedia di data pengaturan stok maupun pembelian"));
                    }
                }
                else
                {
                    this.ShowError(string.Format("Jumlah sparepart yang dimasukkan melebihi stok yang ada! \n Stok yang diminta : {0} \n Permintaan tertunda : {1} \n Stok tersedia : {2}", SparepartQty, pendingRequestSparepart, SparepartToInsert.StockQty));
                }
            }
            else
            {
                this.ShowError("Sparepart yang dimasukkan dalam daftar tidak boleh ada yang sama!");
            }

            ClearSparepart();
        }
        private void btnChangeWheel_Click(object sender, EventArgs e)
        {
            SPKWheelChange editor = Bootstrapper.Resolve <SPKWheelChange>();

            editor.SelectedSPK = this.SelectedSPK;
            editor.VehicleId   = this.VehicleId;

            if (this.VehicleWheelList != null)
            {
                editor.VehicleWheelList = this.VehicleWheelList;
            }

            editor.ShowDialog(this);
            this.VehicleWheelList = editor.VehicleWheelList;

            foreach (VehicleWheelViewModel vw in VehicleWheelList.Where(w => w.ReplaceWithWheelDetailId > 0))
            {
                if (!SPKSparepartList.Any(sp => sp.SparepartId == vw.SparepartId))
                {
                    this.SPKSparepartList.Add(new SPKDetailSparepartViewModel
                    {
                        Sparepart = new SparepartViewModel
                        {
                            Id   = vw.SparepartId,
                            Name = vw.ReplaceWithWheelDetailName,
                            Code = vw.WheelDetail.Sparepart.Code
                        },
                        SparepartId = vw.SparepartId,
                    });
                }

                //temp remove by Tegar

                SpecialSparepartDetailViewModel changedVwDetail = _presenter.GetSpecialSparepartDetail(vw.ReplaceWithWheelDetailId);
                if (changedVwDetail.PurchasingDetail != null)
                {
                    if (!SPKSparepartDetailList.Any(spd => spd.PurchasingDetail != null && spd.PurchasingDetailId == changedVwDetail.PurchasingDetailId))
                    {
                        this.SPKSparepartDetailList.Add(new SPKDetailSparepartDetailViewModel
                        {
                            PurchasingDetailId       = changedVwDetail.PurchasingDetailId,
                            PurchasingDetail         = changedVwDetail.PurchasingDetail,
                            SpecialSparepartDetailId = changedVwDetail.Id,
                            SpecialSparepartDetail   = changedVwDetail,
                            SPKDetailSparepartId     = changedVwDetail.SparepartId,
                            Qty = 1
                        });
                    }
                    else
                    {
                        SPKDetailSparepartDetailViewModel detail = SPKSparepartDetailList.Where(spd => spd.PurchasingDetail != null && spd.PurchasingDetailId == changedVwDetail.PurchasingDetailId).FirstOrDefault();
                        detail.Qty += 1;
                    }
                }

                if (changedVwDetail.SparepartManualTransaction != null)
                {
                    if (!SPKSparepartDetailList.Any(spd => spd.SparepartManualTransaction != null && spd.SparepartManualTransactionId == changedVwDetail.SparepartManualTransactionId))
                    {
                        this.SPKSparepartDetailList.Add(new SPKDetailSparepartDetailViewModel
                        {
                            SparepartManualTransactionId = changedVwDetail.SparepartManualTransactionId,
                            SparepartManualTransaction   = changedVwDetail.SparepartManualTransaction,
                            SpecialSparepartDetailId     = changedVwDetail.Id,
                            SpecialSparepartDetail       = changedVwDetail,
                            SPKDetailSparepartId         = changedVwDetail.SparepartId,
                            Qty = 1
                        });
                    }
                    else
                    {
                        SPKDetailSparepartDetailViewModel detail = SPKSparepartDetailList.Where(spd => spd.SparepartManualTransaction != null && spd.SparepartManualTransactionId == changedVwDetail.SparepartManualTransactionId).FirstOrDefault();
                        detail.Qty += 1;
                    }
                }

                SPKDetailSparepartViewModel spkSp = SPKSparepartList.Where(sp => sp.SparepartId == vw.SparepartId).FirstOrDefault();

                if (spkSp != null)
                {
                    spkSp.TotalQuantity++;
                    spkSp.TotalPrice = spkSp.TotalPrice + vw.Price;
                }
            }

            RefreshSparepartGrid();
            CalculateTotalSparepart();
        }