public void Reject(PurchasingViewModel purchasing, int userID)
 {
     using (var trans = _unitOfWork.BeginTransaction())
     {
         try
         {
             List <PurchasingDetail> listPurchasingDetail = _purchasingDetailRepository
                                                            .GetMany(c => c.PurchasingId == purchasing.Id).ToList();
             foreach (var purchasingDetail in listPurchasingDetail)
             {
                 purchasingDetail.Status       = (int)DbConstant.PurchasingStatus.Deleted;
                 purchasingDetail.ModifyUserId = userID;
                 purchasingDetail.ModifyDate   = DateTime.Now;
                 _purchasingDetailRepository.Update(purchasingDetail);
             }
             Purchasing entity = _purchasingRepository.GetById(purchasing.Id);
             entity.Status       = (int)DbConstant.PurchasingStatus.Deleted;
             entity.ModifyUserId = userID;
             entity.ModifyDate   = DateTime.Now;
             _purchasingRepository.Update(entity);
             _unitOfWork.SaveChanges();
             trans.Commit();
         }
         catch (Exception ex)
         {
             trans.Rollback();
             throw;
         }
     }
 }
        public async Task <ActionResult> Create(int?store_id, int?modelId, int?PhoneId)
        {
            ViewBag.Stores    = util.GetAllStores();
            ViewBag.Companies = util.GetAllCompany();
            if (store_id != null)
            {
                PurchasingViewModel p = new PurchasingViewModel();
                if (modelId != null && PhoneId != null)
                {
                    p.modelId = (int)modelId;
                    p.Phoneid = (int)PhoneId;
                }
                p.store_id = (int)store_id;
                return(View(p));
            }
            else
            {
                var user = await userManager.GetUserAsync(User);

                if (user.store_id != null)
                {
                    PurchasingViewModel p = new PurchasingViewModel();
                    p.store_id = (int)user.store_id;
                    return(View(p));
                }
            }

            return(View());
        }
        public async Task <ActionResult> Create(PurchasingViewModel model)
        {
            try
            {
                // TODO: Add insert logic here
                if (ModelState.IsValid)
                {
                    var user = await userManager.GetUserAsync(User);

                    model.takenBy = user.Id;
                    int id = await iPurchasingRepositery.addPurchasing(model, Url);

                    if (id == 0)
                    {
                        return(View("Error"));
                    }
                    return(RedirectToAction("Details", new { id = id }));
                }
                ViewBag.Stores    = util.GetAllStores();
                ViewBag.Companies = util.GetAllCompany();
                return(View(model));
            }
            catch (Exception e)
            {
                return(View("Error"));
            }
        }
Example #4
0
        public PurchasingViewModel GetSelectedPurchasingByTransaction(int purchasingID)
        {
            Purchasing purchasing = _purchasingRepository
                                    .GetById(purchasingID);
            PurchasingViewModel mappedResult = new PurchasingViewModel();

            return(Map(purchasing, mappedResult));
        }
Example #5
0
        public PurchasingViewModel GetLatestPurchasingInfo(int purchasingID)
        {
            Purchasing purchasing = _purchasingRepository
                                    .GetById(purchasingID);
            PurchasingViewModel mappedResult = new PurchasingViewModel();

            return(Map(purchasing, mappedResult));
        }
 public override void RefreshDataView()
 {
     if (!bgwMain.IsBusy)
     {
         MethodBase.GetCurrentMethod().Info("Fecthing Purchasing data...");
         _selectedPurchasing = null;
         FormHelpers.CurrentMainForm.UpdateStatusInformation("Memuat data pembelian...", false);
         bgwMain.RunWorkerAsync();
     }
 }
        public void InsertPurchasingMethod(PurchasingViewModel purchasing, List <PurchasingDetailViewModel> purchasingDetails, int userID)
        {
            DateTime serverTime = DateTime.Now;

            purchasing.CreateDate      = serverTime;
            purchasing.CreateUserId    = userID;
            purchasing.ModifyUserId    = userID;
            purchasing.ModifyDate      = serverTime;
            purchasing.Status          = (int)DbConstant.PurchasingStatus.NotVerified;
            purchasing.PaymentMethodId = _referenceRepository.GetMany(c => c.Code == DbConstant.REF_PURCHASE_PAYMENTMETHOD_UTANG).FirstOrDefault().Id;
            purchasing.TotalHasPaid    = 0;

            string code = "PRC" + "-" + serverTime.Month.ToString() + serverTime.Day.ToString() + "-";
            //get total purchasing created today
            List <Purchasing> todayPCR = _purchasingRepository.GetMany(s => s.Code.ToString().Contains(code) && s.CreateDate.Year == serverTime.Year).ToList();

            code            = code + (todayPCR.Count + 1);
            purchasing.Code = code;

            Purchasing entity = new Purchasing();

            Map(purchasing, entity);

            _purchasingRepository.AttachNavigation(entity.CreateUser);
            _purchasingRepository.AttachNavigation(entity.ModifyUser);
            _purchasingRepository.AttachNavigation(entity.PaymentMethod);
            _purchasingRepository.AttachNavigation(entity.Supplier);
            Purchasing purchasingInserted = _purchasingRepository.Add(entity);

            _unitOfWork.SaveChanges();

            foreach (var itemPurchasingDetail in purchasingDetails)
            {
                PurchasingDetail newPurchasingDetail = new PurchasingDetail();
                newPurchasingDetail.CreateDate   = serverTime;
                newPurchasingDetail.CreateUserId = userID;
                newPurchasingDetail.ModifyUserId = userID;
                newPurchasingDetail.ModifyDate   = serverTime;
                newPurchasingDetail.PurchasingId = purchasingInserted.Id;
                newPurchasingDetail.SparepartId  = itemPurchasingDetail.SparepartId;
                newPurchasingDetail.Qty          = itemPurchasingDetail.Qty;
                newPurchasingDetail.Price        = itemPurchasingDetail.Price;
                newPurchasingDetail.SerialNumber = itemPurchasingDetail.SerialNumber;
                newPurchasingDetail.Status       = (int)DbConstant.PurchasingStatus.NotVerified;

                _purchasingDetailRepository.AttachNavigation(newPurchasingDetail.CreateUser);
                _purchasingDetailRepository.AttachNavigation(newPurchasingDetail.ModifyUser);
                _purchasingDetailRepository.AttachNavigation(newPurchasingDetail.Purchasing);
                _purchasingDetailRepository.AttachNavigation(newPurchasingDetail.Sparepart);
                PurchasingDetail purchasingDetailInserted = _purchasingDetailRepository.Add(newPurchasingDetail);
            }
            _unitOfWork.SaveChanges();
            Recalculate(purchasingInserted);
        }
 public void InsertPurchasing(PurchasingViewModel purchasing, List <PurchasingDetailViewModel> purchasingDetails, int userID)
 {
     using (var trans = _unitOfWork.BeginTransaction())
     {
         try
         {
             InsertPurchasingMethod(purchasing, purchasingDetails, userID);
             trans.Commit();
         }
         catch (Exception ex)
         {
             trans.Rollback();
             throw;
         }
     }
 }
Example #9
0
        public async Task <int> addPurchasing(PurchasingViewModel c, IUrlHelper Url)
        {
            bool res = false;
            // var price = context.BrandModel.Select(x => new { x.Price, x.modelId }).FirstOrDefault(x => x.modelId == c.modelId);
            Purchasing model = new Purchasing()
            {
                Date      = c.Date,
                Quantity  = c.Quantity,
                Amount    = c.Amount,
                modelId   = c.modelId,
                vendor_id = c.vendor_id,
                store_id  = c.store_id,
                takenBy   = c.takenBy,
            };

            context.Purchasings.Add(model);
            context.SaveChanges();
            res = util.updateSingleQuantity(c.modelId, c.Quantity, c.store_id, "Add");
            if (res == false)
            {
                return(0);
            }
            string StoreName = util.GetAllStores().FirstOrDefault(x => x.store_id == c.store_id).StoreName;
            var    users     = UserManager.Users.Where(x => x.store_id == c.store_id).ToList();

            NotificationsViewModel n = new NotificationsViewModel();

            n.heading = "Purchasing #" + model.purchase_id;
            n.Text    = "Items Purchased By " + c.takenBy;
            n.Url     = Url.Action("Details", "Purchasing", new { id = model.purchase_id });
            n.read    = false;
            n.When    = DateTime.Now;
            await _hubContext.Clients.Groups(StoreName).SendAsync("RecieveNotification", n);

            foreach (var em in users)
            {
                n.UserId = em.Id;
                await util.AddNotification(n);
            }
            context.SaveChanges();
            return(model.purchase_id);
        }
        private void bgwMain_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (e.Result is Exception)
            {
                this.ShowError("Proses memuat data gagal!");
            }

            if (gvPurchasing.RowCount > 0)
            {
                SelectedPurchasing = gvPurchasing.GetRow(0) as PurchasingViewModel;
                if (this.SelectedPurchasing != null)
                {
                    if (this.SelectedPurchasing.Status == (int)DbConstant.PurchasingStatus.NotVerified)
                    {
                        cmsEditData.Visible = true;
                        persetujuanPembelianToolStripMenuItem.Visible = true;
                        lihatSelengkapnyaToolStripMenuItem.Visible    = false;
                        cmsPrint.Visible     = false;
                        cmsAddReturn.Visible = false;
                    }
                    else if (this.SelectedPurchasing.Status == (int)DbConstant.PurchasingStatus.HasReturn)
                    {
                        cmsEditData.Visible = false;
                        persetujuanPembelianToolStripMenuItem.Visible = false;
                        lihatSelengkapnyaToolStripMenuItem.Visible    = true;
                        cmsPrint.Visible     = true;
                        cmsAddReturn.Visible = false;
                    }
                    else
                    {
                        cmsEditData.Visible = false;
                        persetujuanPembelianToolStripMenuItem.Visible = false;
                        lihatSelengkapnyaToolStripMenuItem.Visible    = true;
                        cmsPrint.Visible     = true;
                        cmsAddReturn.Visible = true;
                    }
                }
            }

            FormHelpers.CurrentMainForm.UpdateStatusInformation("Memuat data pembelian selesai", true);
        }
        public void Approve(PurchasingViewModel purchasing, int userID)
        {
            using (var trans = _unitOfWork.BeginTransaction())
            {
                try
                {
                    DateTime serverTime = DateTime.Now;

                    Reference transactionReferenceTable = _referenceRepository.GetMany(c => c.Code == DbConstant.REF_TRANSTBL_PURCHASING).FirstOrDefault();

                    List <PurchasingDetail> listPurchasingDetail = _purchasingDetailRepository
                                                                   .GetMany(c => c.PurchasingId == purchasing.Id).ToList();
                    foreach (var purchasingDetail in listPurchasingDetail)
                    {
                        Sparepart sparepartDB = _sparepartRepository.GetById(purchasingDetail.SparepartId);

                        for (int i = 1; i <= purchasingDetail.Qty; i++)
                        {
                            if (!string.IsNullOrEmpty(purchasingDetail.SerialNumber))
                            {
                                SpecialSparepartDetail wd = new SpecialSparepartDetail();
                                wd.PurchasingDetail = purchasingDetail;
                                wd.SerialNumber     = purchasingDetail.SerialNumber;
                                wd.CreateUserId     = userID;
                                wd.CreateDate       = serverTime;
                                wd.ModifyUserId     = userID;
                                wd.ModifyDate       = serverTime;
                                wd.SparepartId      = sparepartDB.Id;
                                wd.Status           = (int)DbConstant.WheelDetailStatus.Ready;

                                _specialSparepartDetailRepository.AttachNavigation(purchasingDetail.CreateUser);
                                _specialSparepartDetailRepository.AttachNavigation(purchasingDetail.ModifyUser);
                                _specialSparepartDetailRepository.AttachNavigation(purchasingDetail);
                                _specialSparepartDetailRepository.AttachNavigation(purchasingDetail.Sparepart);;
                                _specialSparepartDetailRepository.Add(wd);
                            }
                        }

                        purchasingDetail.Status       = (int)DbConstant.PurchasingStatus.Active;
                        purchasingDetail.QtyRemaining = purchasingDetail.Qty;
                        _purchasingDetailRepository.AttachNavigation(purchasingDetail.CreateUser);
                        _purchasingDetailRepository.AttachNavigation(purchasingDetail.ModifyUser);
                        _purchasingDetailRepository.AttachNavigation(purchasingDetail.Purchasing);
                        _purchasingDetailRepository.AttachNavigation(purchasingDetail.Sparepart);
                        _purchasingDetailRepository.Update(purchasingDetail);

                        Sparepart sparepart = _sparepartRepository.GetById(purchasingDetail.SparepartId);
                        sparepart.StockQty += purchasingDetail.Qty;

                        _sparepartRepository.AttachNavigation(sparepart.CreateUser);
                        _sparepartRepository.AttachNavigation(sparepart.ModifyUser);
                        _sparepartRepository.AttachNavigation(sparepart.CategoryReference);
                        _sparepartRepository.AttachNavigation(sparepart.UnitReference);
                        _sparepartRepository.Update(sparepart);

                        SparepartStockCard stockCard = new SparepartStockCard();
                        stockCard.CreateUserId     = userID;
                        stockCard.PurchaseDate     = serverTime;
                        stockCard.PrimaryKeyValue  = purchasing.Id;
                        stockCard.ReferenceTableId = transactionReferenceTable.Id;
                        stockCard.SparepartId      = sparepart.Id;
                        stockCard.Description      = "Purchasing";
                        stockCard.QtyIn            = purchasingDetail.Qty;
                        stockCard.QtyInPrice       = Convert.ToDouble(purchasingDetail.Price * purchasingDetail.Qty);
                        SparepartStockCard lastStockCard  = _sparepartStokCardRepository.RetrieveLastCard(sparepart.Id);
                        double             lastStock      = 0;
                        double             lastStockPrice = 0;
                        if (lastStockCard != null)
                        {
                            lastStock      = lastStockCard.QtyLast;
                            lastStockPrice = lastStockCard.QtyLastPrice;
                        }
                        stockCard.QtyFirst      = lastStock;
                        stockCard.QtyFirstPrice = lastStockPrice;
                        stockCard.QtyLast       = lastStock + stockCard.QtyIn;
                        stockCard.QtyLastPrice  = lastStockPrice + stockCard.QtyInPrice;
                        _sparepartStokCardRepository.AttachNavigation(stockCard.CreateUser);
                        _sparepartStokCardRepository.AttachNavigation(stockCard.Sparepart);
                        _sparepartStokCardRepository.AttachNavigation(stockCard.ReferenceTable);
                        stockCard = _sparepartStokCardRepository.Add(stockCard);
                        _unitOfWork.SaveChanges();


                        SparepartStockCardDetail stockCardDtail = new SparepartStockCardDetail();
                        stockCardDtail.ParentStockCard = stockCard;
                        stockCardDtail.PricePerItem    = Convert.ToDouble(purchasingDetail.Price);
                        stockCardDtail.QtyIn           = purchasingDetail.Qty;
                        stockCardDtail.QtyInPrice      = Convert.ToDouble(purchasingDetail.Price * purchasingDetail.Qty);
                        SparepartStockCardDetail lastStockCardDetail = _sparepartStokCardDetailRepository.RetrieveLastCardDetailByPurchasingId(sparepart.Id, purchasing.Id);
                        double lastStockDetail      = 0;
                        double lastStockDetailPrice = 0;
                        if (lastStockCardDetail != null)
                        {
                            lastStockDetail      = lastStockCardDetail.QtyLast;
                            lastStockDetailPrice = lastStockCardDetail.QtyLastPrice;
                        }
                        stockCardDtail.QtyFirst      = lastStockDetail;
                        stockCardDtail.QtyFirstPrice = lastStockDetailPrice;
                        stockCardDtail.QtyLast       = lastStockDetail + stockCardDtail.QtyIn;
                        stockCardDtail.QtyLastPrice  = lastStockDetailPrice + stockCardDtail.QtyInPrice;
                        stockCardDtail.PurchasingId  = purchasing.Id;
                        _sparepartStokCardDetailRepository.AttachNavigation(stockCardDtail.ParentStockCard);
                        _sparepartStokCardDetailRepository.Add(stockCardDtail);
                        _unitOfWork.SaveChanges();
                    }

                    Reference refSelected = _referenceRepository.GetById(purchasing.PaymentMethodId);
                    purchasing.Status = (int)DbConstant.PurchasingStatus.Active;
                    if (refSelected != null &&
                        (refSelected.Code == DbConstant.REF_PURCHASE_PAYMENTMETHOD_BANK_EKONOMI ||
                         refSelected.Code == DbConstant.REF_PURCHASE_PAYMENTMETHOD_BANK_BCA1 ||
                         refSelected.Code == DbConstant.REF_PURCHASE_PAYMENTMETHOD_BANK_BCA2 ||
                         refSelected.Code == DbConstant.REF_PURCHASE_PAYMENTMETHOD_KAS)
                        )
                    {
                        purchasing.TotalHasPaid = purchasing.TotalPrice;
                    }

                    if (purchasing.TotalHasPaid != purchasing.TotalPrice)
                    {
                        purchasing.PaymentStatus = (int)DbConstant.PaymentStatus.NotSettled;
                    }
                    else
                    {
                        purchasing.PaymentStatus = (int)DbConstant.PaymentStatus.Settled;
                    }
                    Purchasing entity = _purchasingRepository.GetById(purchasing.Id);
                    //Map(purchasing, entity);
                    entity.PaymentStatus   = purchasing.PaymentStatus;
                    entity.Status          = purchasing.Status;
                    entity.TotalHasPaid    = purchasing.TotalHasPaid;
                    entity.TotalPrice      = purchasing.TotalPrice;
                    entity.PaymentMethodId = purchasing.PaymentMethodId;
                    _purchasingRepository.AttachNavigation(entity.CreateUser);
                    _purchasingRepository.AttachNavigation(entity.ModifyUser);
                    _purchasingRepository.AttachNavigation(entity.PaymentMethod);
                    _purchasingRepository.AttachNavigation(entity.Supplier);
                    _purchasingRepository.Update(entity);
                    _unitOfWork.SaveChanges();

                    Transaction transaction = new Transaction();
                    transaction.TransactionDate  = purchasing.Date;
                    transaction.TotalPayment     = Convert.ToDouble(purchasing.TotalHasPaid);
                    transaction.TotalTransaction = Convert.ToDouble(purchasing.TotalPrice);
                    transaction.ReferenceTableId = transactionReferenceTable.Id;
                    transaction.PrimaryKeyValue  = purchasing.Id;
                    transaction.CreateDate       = serverTime;
                    transaction.CreateUserId     = userID;
                    transaction.ModifyUserId     = userID;
                    transaction.ModifyDate       = serverTime;
                    transaction.Status           = (int)DbConstant.DefaultDataStatus.Active;
                    transaction.Description      = "Pembelian sparepart";
                    transaction.PaymentMethodId  = purchasing.PaymentMethodId;

                    _transactionRepository.AttachNavigation(transaction.CreateUser);
                    _transactionRepository.AttachNavigation(transaction.ModifyUser);
                    _transactionRepository.AttachNavigation(transaction.PaymentMethod);
                    _transactionRepository.AttachNavigation(transaction.ReferenceTable);
                    Transaction transactionInserted = _transactionRepository.Add(transaction);
                    _unitOfWork.SaveChanges();

                    switch (refSelected.Code)
                    {
                    case DbConstant.REF_PURCHASE_PAYMENTMETHOD_BANK_EKONOMI:
                    case DbConstant.REF_PURCHASE_PAYMENTMETHOD_BANK_BCA1:
                    case DbConstant.REF_PURCHASE_PAYMENTMETHOD_BANK_BCA2:
                    {
                        // Bank Kredit --> Karena berkurang
                        TransactionDetail detailBank = new TransactionDetail();
                        detailBank.Credit = purchasing.TotalHasPaid;
                        if (refSelected.Code == DbConstant.REF_PURCHASE_PAYMENTMETHOD_BANK_EKONOMI)
                        {
                            detailBank.JournalId = _journalMasterRepository.GetMany(j => j.Code == "1.01.02.01").FirstOrDefault().Id;
                        }
                        else if (refSelected.Code == DbConstant.REF_PURCHASE_PAYMENTMETHOD_BANK_BCA1)
                        {
                            detailBank.JournalId = _journalMasterRepository.GetMany(j => j.Code == "1.01.02.02").FirstOrDefault().Id;
                        }
                        else if (refSelected.Code == DbConstant.REF_PURCHASE_PAYMENTMETHOD_BANK_BCA2)
                        {
                            detailBank.JournalId = _journalMasterRepository.GetMany(j => j.Code == "1.01.02.03").FirstOrDefault().Id;
                        }
                        detailBank.ParentId = transactionInserted.Id;

                        _transactionDetailRepository.AttachNavigation(detailBank.Journal);
                        _transactionDetailRepository.AttachNavigation(detailBank.Parent);
                        _transactionDetailRepository.Add(detailBank);
                        break;
                    }

                    case DbConstant.REF_PURCHASE_PAYMENTMETHOD_KAS:
                        // Kas Kredit --> Karena berkurang
                        TransactionDetail detailKas = new TransactionDetail();
                        detailKas.Credit    = purchasing.TotalHasPaid;
                        detailKas.JournalId = _journalMasterRepository.GetMany(j => j.Code == "1.01.01.01").FirstOrDefault().Id;
                        detailKas.ParentId  = transactionInserted.Id;

                        _transactionDetailRepository.AttachNavigation(detailKas.Journal);
                        _transactionDetailRepository.AttachNavigation(detailKas.Parent);
                        _transactionDetailRepository.Add(detailKas);
                        break;

                    case DbConstant.REF_PURCHASE_PAYMENTMETHOD_UANGMUKA_KAS:
                        // Kas Kredit --> Karena berkurang
                        TransactionDetail detailKasKarenaUangMuka = new TransactionDetail();
                        detailKasKarenaUangMuka.Credit    = purchasing.TotalHasPaid;
                        detailKasKarenaUangMuka.JournalId = _journalMasterRepository.GetMany(j => j.Code == "1.01.01.01").FirstOrDefault().Id;
                        detailKasKarenaUangMuka.ParentId  = transactionInserted.Id;

                        _transactionDetailRepository.AttachNavigation(detailKasKarenaUangMuka.Journal);
                        _transactionDetailRepository.AttachNavigation(detailKasKarenaUangMuka.Parent);
                        _transactionDetailRepository.Add(detailKasKarenaUangMuka);

                        // Uang Muka Debit --> Karena bertambah
                        TransactionDetail detailUangMukaBertambahKarenaKas = new TransactionDetail();
                        detailUangMukaBertambahKarenaKas.Debit     = purchasing.TotalHasPaid;
                        detailUangMukaBertambahKarenaKas.JournalId = _journalMasterRepository.GetMany(j => j.Code == "1.01.05.01.01").FirstOrDefault().Id;
                        detailUangMukaBertambahKarenaKas.ParentId  = transactionInserted.Id;

                        _transactionDetailRepository.AttachNavigation(detailUangMukaBertambahKarenaKas.Journal);
                        _transactionDetailRepository.AttachNavigation(detailUangMukaBertambahKarenaKas.Parent);
                        _transactionDetailRepository.Add(detailUangMukaBertambahKarenaKas);

                        // Uang Muka Kredit --> Karena berkurang
                        TransactionDetail detailUangMukaBerkurangKarenaKas = new TransactionDetail();
                        detailUangMukaBerkurangKarenaKas.Credit    = purchasing.TotalHasPaid;
                        detailUangMukaBerkurangKarenaKas.JournalId = _journalMasterRepository.GetMany(j => j.Code == "1.01.05.01.01").FirstOrDefault().Id;
                        detailUangMukaBerkurangKarenaKas.ParentId  = transactionInserted.Id;

                        _transactionDetailRepository.AttachNavigation(detailUangMukaBerkurangKarenaKas.Journal);
                        _transactionDetailRepository.AttachNavigation(detailUangMukaBerkurangKarenaKas.Parent);
                        _transactionDetailRepository.Add(detailUangMukaBerkurangKarenaKas);
                        break;

                    case DbConstant.REF_PURCHASE_PAYMENTMETHOD_UANGMUKA_BANK_EKONOMI:
                    case DbConstant.REF_PURCHASE_PAYMENTMETHOD_UANGMUKA_BANK_BCA1:
                    case DbConstant.REF_PURCHASE_PAYMENTMETHOD_UANGMUKA_BANK_BCA2:
                    {
                        // Bank Kredit --> Karena berkurang
                        TransactionDetail detailBankKarenaUangMuka = new TransactionDetail();
                        detailBankKarenaUangMuka.Credit = purchasing.TotalHasPaid;
                        if (refSelected.Code == DbConstant.REF_PURCHASE_PAYMENTMETHOD_UANGMUKA_BANK_EKONOMI)
                        {
                            detailBankKarenaUangMuka.JournalId = _journalMasterRepository.GetMany(j => j.Code == "1.01.02.01").FirstOrDefault().Id;
                        }
                        else if (refSelected.Code == DbConstant.REF_PURCHASE_PAYMENTMETHOD_UANGMUKA_BANK_BCA1)
                        {
                            detailBankKarenaUangMuka.JournalId = _journalMasterRepository.GetMany(j => j.Code == "1.01.02.02").FirstOrDefault().Id;
                        }
                        else if (refSelected.Code == DbConstant.REF_PURCHASE_PAYMENTMETHOD_UANGMUKA_BANK_BCA2)
                        {
                            detailBankKarenaUangMuka.JournalId = _journalMasterRepository.GetMany(j => j.Code == "1.01.02.03").FirstOrDefault().Id;
                        }
                        detailBankKarenaUangMuka.ParentId = transactionInserted.Id;

                        _transactionDetailRepository.AttachNavigation(detailBankKarenaUangMuka.Journal);
                        _transactionDetailRepository.AttachNavigation(detailBankKarenaUangMuka.Parent);
                        _transactionDetailRepository.Add(detailBankKarenaUangMuka);

                        // Uang Muka Debit --> Karena bertambah
                        TransactionDetail detailUangMukaBertambahKarenaBank = new TransactionDetail();
                        detailUangMukaBertambahKarenaBank.Debit     = purchasing.TotalHasPaid;
                        detailUangMukaBertambahKarenaBank.JournalId = _journalMasterRepository.GetMany(j => j.Code == "1.01.05.01.01").FirstOrDefault().Id;
                        detailUangMukaBertambahKarenaBank.ParentId  = transactionInserted.Id;

                        _transactionDetailRepository.AttachNavigation(detailUangMukaBertambahKarenaBank.Journal);
                        _transactionDetailRepository.AttachNavigation(detailUangMukaBertambahKarenaBank.Parent);
                        _transactionDetailRepository.Add(detailUangMukaBertambahKarenaBank);

                        // Uang Muka Kredit --> Karena berkurang
                        TransactionDetail detailUangMukaBerkurangKarenaBank = new TransactionDetail();
                        detailUangMukaBerkurangKarenaBank.Credit    = purchasing.TotalHasPaid;
                        detailUangMukaBerkurangKarenaBank.JournalId = _journalMasterRepository.GetMany(j => j.Code == "1.01.05.01.01").FirstOrDefault().Id;
                        detailUangMukaBerkurangKarenaBank.ParentId  = transactionInserted.Id;

                        _transactionDetailRepository.AttachNavigation(detailUangMukaBerkurangKarenaBank.Journal);
                        _transactionDetailRepository.AttachNavigation(detailUangMukaBerkurangKarenaBank.Parent);
                        _transactionDetailRepository.Add(detailUangMukaBerkurangKarenaBank);
                        break;
                    }

                    case DbConstant.REF_PURCHASE_PAYMENTMETHOD_UTANG:
                        TransactionDetail utang = new TransactionDetail();
                        utang.Credit    = purchasing.TotalPrice - purchasing.TotalHasPaid;
                        utang.JournalId = _journalMasterRepository.GetMany(j => j.Code == "2.01.01.01").FirstOrDefault().Id;
                        utang.ParentId  = transactionInserted.Id;

                        _transactionDetailRepository.AttachNavigation(utang.Journal);
                        _transactionDetailRepository.AttachNavigation(utang.Parent);
                        _transactionDetailRepository.Add(utang);
                        break;
                    }

                    if (refSelected.Code == DbConstant.REF_PURCHASE_PAYMENTMETHOD_UANGMUKA_BANK_EKONOMI ||
                        refSelected.Code == DbConstant.REF_PURCHASE_PAYMENTMETHOD_UANGMUKA_BANK_BCA1 ||
                        refSelected.Code == DbConstant.REF_PURCHASE_PAYMENTMETHOD_UANGMUKA_BANK_BCA2 ||
                        refSelected.Code == DbConstant.REF_PURCHASE_PAYMENTMETHOD_UANGMUKA_KAS)
                    {
                        if (purchasing.TotalPrice > purchasing.TotalHasPaid)
                        {
                            // Utang Kredit --> Karena bertambah
                            TransactionDetail utang = new TransactionDetail();
                            utang.Credit    = purchasing.TotalPrice - purchasing.TotalHasPaid;
                            utang.JournalId = _journalMasterRepository.GetMany(j => j.Code == "2.01.01.01").FirstOrDefault().Id;
                            utang.ParentId  = transactionInserted.Id;

                            _transactionDetailRepository.AttachNavigation(utang.Journal);
                            _transactionDetailRepository.AttachNavigation(utang.Parent);
                            _transactionDetailRepository.Add(utang);
                        }
                    }

                    // Sparepart Debit --> Karena bertambah
                    TransactionDetail detailSparepart = new TransactionDetail();
                    detailSparepart.Debit     = purchasing.TotalPrice;
                    detailSparepart.JournalId = _journalMasterRepository.GetMany(j => j.Code == "1.01.04.01").FirstOrDefault().Id;
                    detailSparepart.ParentId  = transactionInserted.Id;

                    _transactionDetailRepository.AttachNavigation(detailSparepart.Journal);
                    _transactionDetailRepository.AttachNavigation(detailSparepart.Parent);
                    _transactionDetailRepository.Add(detailSparepart);

                    _unitOfWork.SaveChanges();

                    trans.Commit();
                }
                catch (Exception ex)
                {
                    trans.Rollback();
                    throw;
                }
            }
        }