private void AddMeanGageHeight(DischargeActivity dischargeActivity, decimal stage, UnitSystem unitSystem)
        {
            var measurement           = new Measurement(stage.AsDouble(), unitSystem.DistanceUnitId);
            var gageHeightMeasurement = new GageHeightMeasurement(measurement, _fieldVisitInfo.StartDate);

            dischargeActivity.GageHeightMeasurements.Add(gageHeightMeasurement);
        }
            public object Compute(
                object d1,
                object d2)
            {
                decimal s1 = _convOne.CoerceBoxed(d1).AsDecimal();
                decimal s2 = _convTwo.CoerceBoxed(d2).AsDecimal();

                if (s2 == 0.0m)
                {
                    if (_divisionByZeroReturnsNull)
                    {
                        return(null);
                    }

                    var result = s1.AsDouble() / 0;
                    return(new decimal(result));
                }

                return(DoDivide(s1, s2));
            }
예제 #3
0
        public void InsertDebt(TransactionViewModel transaction, decimal purchasingPrice, int userID)
        {
            DateTime  serverTime = DateTime.Now;
            Reference transactionReferenceTable = _referenceRepository.GetMany(c => c.Code == DbConstant.REF_TRANSTBL_PURCHASING).FirstOrDefault();

            transaction.CreateDate       = serverTime;
            transaction.ModifyDate       = serverTime;
            transaction.CreateUserId     = userID;
            transaction.ModifyUserId     = userID;
            transaction.TransactionDate  = serverTime;
            transaction.TotalTransaction = purchasingPrice.AsDouble();
            transaction.ReferenceTableId = transactionReferenceTable.Id;
            transaction.Status           = (int)DbConstant.DefaultDataStatus.Active;
            transaction.Description      = "Pembayaran hutang";

            Transaction entity = new Transaction();

            Map(transaction, entity);
            Transaction transactionInserted = _transactionRepository.Add(entity);

            Purchasing purchasingEntity = _purchasingRepository.GetById(transaction.PrimaryKeyValue);

            purchasingEntity.TotalHasPaid += transaction.TotalPayment.AsDecimal();
            if (purchasingEntity.TotalHasPaid == purchasingEntity.TotalPrice)
            {
                purchasingEntity.PaymentStatus = (int)DbConstant.PaymentStatus.Settled;
            }
            _purchasingRepository.Update(purchasingEntity);

            Reference paymentMethod = _referenceRepository.GetById(transaction.PaymentMethodId);

            switch (paymentMethod.Code)
            {
            case DbConstant.REF_DEBT_PAYMENTMETHOD_BANK_EKONOMI:
            case DbConstant.REF_DEBT_PAYMENTMETHOD_BANK_BCA1:
            case DbConstant.REF_DEBT_PAYMENTMETHOD_BANK_BCA2:
            {
                // Bank Kredit --> Karena berkurang
                TransactionDetail detailBank = new TransactionDetail();
                detailBank.Credit = transaction.TotalPayment.AsDecimal();
                if (paymentMethod.Code == DbConstant.REF_DEBT_PAYMENTMETHOD_BANK_EKONOMI)
                {
                    detailBank.JournalId = _journalMasterRepository.GetMany(j => j.Code == "1.01.02.01").FirstOrDefault().Id;
                }
                else if (paymentMethod.Code == DbConstant.REF_DEBT_PAYMENTMETHOD_BANK_BCA1)
                {
                    detailBank.JournalId = _journalMasterRepository.GetMany(j => j.Code == "1.01.02.02").FirstOrDefault().Id;
                }
                else if (paymentMethod.Code == DbConstant.REF_DEBT_PAYMENTMETHOD_BANK_BCA2)
                {
                    detailBank.JournalId = _journalMasterRepository.GetMany(j => j.Code == "1.01.02.03").FirstOrDefault().Id;
                }
                detailBank.Parent = transactionInserted;
                _transactionDetailRepository.Add(detailBank);
                break;
            }

            case DbConstant.REF_DEBT_PAYMENTMETHOD_KAS:
                // Kas Kredit --> Karena berkurang
                TransactionDetail detailKas = new TransactionDetail();
                detailKas.Credit    = transaction.TotalPayment.AsDecimal();
                detailKas.JournalId = _journalMasterRepository.GetMany(j => j.Code == "1.01.01.01").FirstOrDefault().Id;
                detailKas.Parent    = transactionInserted;
                _transactionDetailRepository.Add(detailKas);
                break;
            }

            TransactionDetail detailDebt = new TransactionDetail();

            detailDebt.Debit     = transaction.TotalPayment.AsDecimal();
            detailDebt.JournalId = _journalMasterRepository.GetMany(j => j.Code == "2.01.01.01").FirstOrDefault().Id;
            detailDebt.Parent    = transactionInserted;
            _transactionDetailRepository.Add(detailDebt);
            _unitOfWork.SaveChanges();
        }
        public List <InvoiceSparepartViewModel> GetInvoiceSparepartList(int invoiceID)
        {
            List <InvoiceSparepartViewModel> result            = new List <InvoiceSparepartViewModel>();
            List <InvoiceDetail>             listInvoiceDetail = _invoiceDetailRepository.GetMany(x => x.InvoiceId == invoiceID).ToList();

            //int[] sparepartIDs = listInvoiceDetail.Select(x => x.SPKDetailSparepartDetail.SPKDetailSparepart.SparepartId).Distinct().ToArray();
            //foreach (var sparepartID in sparepartIDs)
            //{
            //    result.Add(new InvoiceSparepartViewModel
            //    {
            //        SparepartName = _sparepartRepository.GetById(sparepartID).Name,
            //        Qty = listInvoiceDetail.Where(x => x.SPKDetailSparepartDetail.SPKDetailSparepart.SparepartId == sparepartID).Count(),
            //        SubTotalPrice = listInvoiceDetail.Where(x => x.SPKDetailSparepartDetail.SPKDetailSparepart.SparepartId == sparepartID).Sum(x => x.SubTotalPrice),
            //        SparepartCode = _sparepartRepository.GetById(sparepartID).Code,
            //        UnitCategoryName = _sparepartRepository.GetById(sparepartID).UnitReference.Name,
            //    });
            //}

            foreach (InvoiceDetail invoiceDetail in listInvoiceDetail)
            {
                double itemPrice = 0;

                if (invoiceDetail.SPKDetailSparepartDetail.SparepartManualTransactionId > 0)
                {
                    itemPrice = decimal.ToDouble(invoiceDetail.SPKDetailSparepartDetail.SparepartManualTransaction.Price);
                }
                else if (invoiceDetail.SPKDetailSparepartDetail.PurchasingDetailId > 0)
                {
                    itemPrice = decimal.ToDouble(invoiceDetail.SPKDetailSparepartDetail.PurchasingDetail.Price);
                }

                result.Add(new InvoiceSparepartViewModel
                {
                    SparepartName    = invoiceDetail.SPKDetailSparepartDetail.SPKDetailSparepart.Sparepart.Name,
                    Qty              = invoiceDetail.SPKDetailSparepartDetail.SPKDetailSparepart.TotalQuantity,
                    SubTotalPrice    = decimal.ToDouble(invoiceDetail.SPKDetailSparepartDetail.SPKDetailSparepart.TotalPrice),
                    SparepartCode    = invoiceDetail.SPKDetailSparepartDetail.SPKDetailSparepart.Sparepart.Code,
                    UnitCategoryName = invoiceDetail.SPKDetailSparepartDetail.SPKDetailSparepart.Sparepart.UnitReference.Name,
                    ItemPrice        = itemPrice
                });
            }

            Invoice invoice = _invoiceRepository.GetById(invoiceID);

            if (invoice.SPK.isContractWork)
            {
                result.Add(new InvoiceSparepartViewModel
                {
                    SparepartName    = "Borongan",
                    Qty              = 1,
                    SubTotalPrice    = (invoice.SPK.ContractWorkFee * (0.2).AsDecimal()).AsDouble(),
                    SparepartCode    = "Biaya Tukang",
                    UnitCategoryName = "",
                });
            }
            else
            {
                decimal ServiceFee = 0;

                TimeSpan SPKTimeSpan    = invoice.CreateDate - invoice.SPK.CreateDate;
                int      SPKWorkingDays = Math.Ceiling(SPKTimeSpan.TotalDays).AsInteger();

                for (int i = 0; i < SPKWorkingDays; i++)
                {
                    List <Mechanic> involvedMechanic = (from sched in _spkScheduleRepository.GetMany(sc => sc.CreateDate.Day == invoice.SPK.CreateDate.Day + i && sc.SPKId == invoice.SPK.Id).ToList()
                                                        select sched.Mechanic).ToList();

                    foreach (Mechanic mechanic in involvedMechanic)
                    {
                        int mechanicJobForToday = _spkScheduleRepository.GetMany(sc => sc.CreateDate.Day == invoice.SPK.CreateDate.Day + i && sc.MechanicId == mechanic.Id).Count();

                        decimal mechanicFeeForToday = mechanic.BaseFee / mechanicJobForToday;

                        result.Add(new InvoiceSparepartViewModel
                        {
                            SparepartName    = mechanic.Name,
                            Qty              = 1,
                            SubTotalPrice    = mechanicFeeForToday.AsDouble(),
                            SparepartCode    = "Biaya Tukang",
                            UnitCategoryName = "",
                        });
                    }
                }
            }
            return(result);
        }
예제 #5
0
        public void InsertPurchaseReturnFunc(int purchasingID, List <ReturnViewModel> listReturn, int userID)
        {
            DateTime serverTime = DateTime.Now;

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

            PurchaseReturn purchaseReturn = new PurchaseReturn();

            purchaseReturn.CreateDate   = serverTime;
            purchaseReturn.CreateUserId = userID;
            purchaseReturn.ModifyDate   = serverTime;
            purchaseReturn.ModifyUserId = userID;
            purchaseReturn.PurchasingId = purchasingID;
            purchaseReturn.Date         = serverTime;
            purchaseReturn.Status       = (int)DbConstant.DefaultDataStatus.Active;

            string code = "PRR" + "-" + serverTime.Month.ToString() + serverTime.Day.ToString() + "-";
            //get total purchasing return created today
            List <PurchaseReturn> todayPRR = _purchaseReturnRepository.GetMany(s => s.Code.ToString().Contains(code) && s.CreateDate.Year == serverTime.Year).ToList();

            code = code + (todayPRR.Count + 1);
            purchaseReturn.Code = code;

            _purchaseReturnRepository.AttachNavigation(purchaseReturn.CreateUser);
            _purchaseReturnRepository.AttachNavigation(purchaseReturn.ModifyUser);
            _purchaseReturnRepository.AttachNavigation(purchaseReturn.Purchasing);
            purchaseReturn = _purchaseReturnRepository.Add(purchaseReturn);


            _unitOfWork.SaveChanges();

            List <PurchaseReturnDetail> listReturnDetail = new List <PurchaseReturnDetail>();

            decimal totalTransaction = 0;

            foreach (var itemReturn in listReturn)
            {
                PurchasingDetail purchasingDetail = _purchasingDetailRepository.GetMany(x => x.Id == itemReturn.PurchasingDetailId).FirstOrDefault();
                listReturnDetail.Add(new PurchaseReturnDetail
                {
                    CreateDate         = serverTime,
                    CreateUserId       = userID,
                    ModifyDate         = serverTime,
                    ModifyUserId       = userID,
                    PurchaseReturnId   = purchaseReturn.Id,
                    PurchasingDetailId = purchasingDetail.Id,
                    Qty    = itemReturn.ReturQty,
                    Status = (int)DbConstant.DefaultDataStatus.Active
                });
                itemReturn.PricePerItem = purchasingDetail.Price;
                if (itemReturn.ReturQty > 0)
                {
                    totalTransaction += itemReturn.ReturQty * purchasingDetail.Price;

                    purchasingDetail.QtyRemaining -= itemReturn.ReturQty;

                    SpecialSparepartDetail spDetail = _specialSparepartDetailRepository.GetMany(x => x.PurchasingDetailId == purchasingDetail.Id).FirstOrDefault();
                    if (spDetail != null)
                    {
                        spDetail.Status = (int)DbConstant.WheelDetailStatus.Deleted;
                        _specialSparepartDetailRepository.AttachNavigation(spDetail.CreateUser);
                        _specialSparepartDetailRepository.AttachNavigation(spDetail.ModifyUser);
                        _specialSparepartDetailRepository.AttachNavigation(spDetail.PurchasingDetail);
                        _specialSparepartDetailRepository.AttachNavigation(spDetail.Sparepart);
                        _specialSparepartDetailRepository.AttachNavigation(spDetail.SparepartManualTransaction);
                        _specialSparepartDetailRepository.Update(spDetail);
                    }
                }

                _purchasingDetailRepository.AttachNavigation(purchasingDetail.CreateUser);
                _purchasingDetailRepository.AttachNavigation(purchasingDetail.ModifyUser);
                _purchasingDetailRepository.AttachNavigation(purchasingDetail.Purchasing);
                _purchasingDetailRepository.AttachNavigation(purchasingDetail.Sparepart);
                _purchasingDetailRepository.Update(purchasingDetail);
                _unitOfWork.SaveChanges();
            }

            List <ReturnViewModel> listReturnGroup = listReturn
                                                     .GroupBy(l => l.SparepartId)
                                                     .Select(cl => new ReturnViewModel
            {
                SparepartId  = cl.First().SparepartId,
                ReturQty     = cl.Sum(c => c.ReturQty),
                SubTotalFee  = cl.Sum(c => c.PricePerItem * c.ReturQty),
                PricePerItem = cl.First().PricePerItem,
            }).ToList();

            foreach (var itemReturnGroup in listReturnGroup)
            {
                Sparepart sparepart = _sparepartRepository.GetById(itemReturnGroup.SparepartId);
                sparepart.ModifyDate   = serverTime;
                sparepart.ModifyUserId = userID;
                sparepart.StockQty    -= itemReturnGroup.ReturQty;

                _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  = purchaseReturn.Id;
                stockCard.ReferenceTableId = transactionReferenceTable.Id;
                stockCard.SparepartId      = sparepart.Id;
                stockCard.Description      = "Retur Pembelian";
                stockCard.QtyOut           = itemReturnGroup.ReturQty;
                stockCard.QtyOutPrice      = Convert.ToDouble(itemReturnGroup.SubTotalFee);
                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.QtyOut;
                stockCard.QtyLastPrice  = lastStockPrice - stockCard.QtyOutPrice;
                _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(itemReturnGroup.PricePerItem);
                stockCardDtail.QtyOut          = itemReturnGroup.ReturQty;
                stockCardDtail.QtyOutPrice     = Convert.ToDouble(itemReturnGroup.SubTotalFee);
                SparepartStockCardDetail lastStockCardDetail = _sparepartStokCardDetailRepository.RetrieveLastCardDetailByPurchasingId(sparepart.Id, purchasingID);
                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.QtyOut;
                stockCardDtail.QtyLastPrice  = lastStockDetailPrice - stockCardDtail.QtyOutPrice;
                stockCardDtail.PurchasingId  = purchasingID;

                _sparepartStokCardDetailRepository.AttachNavigation(stockCardDtail.ParentStockCard);
                _sparepartStokCardDetailRepository.Add(stockCardDtail);
                _unitOfWork.SaveChanges();
            }

            Purchasing purchasing = _purchasingRepository.GetById(purchaseReturn.PurchasingId);

            purchasing.Status = (int)DbConstant.PurchasingStatus.HasReturn;
            if (purchasing.TotalPrice != purchasing.TotalHasPaid && (purchasing.TotalPrice - purchasing.TotalHasPaid) >= totalTransaction)
            {
                purchasing.TotalHasPaid += totalTransaction;
            }

            if (purchasing.TotalPrice == purchasing.TotalHasPaid)
            {
                purchasing.PaymentStatus = (int)DbConstant.PaymentStatus.Settled;
            }
            else
            {
                purchasing.PaymentStatus = (int)DbConstant.PaymentStatus.NotSettled;
            }

            _purchasingRepository.AttachNavigation(purchasing.CreateUser);
            _purchasingRepository.AttachNavigation(purchasing.ModifyUser);
            _purchasingRepository.AttachNavigation(purchasing.PaymentMethod);
            _purchasingRepository.AttachNavigation(purchasing.Supplier);

            _unitOfWork.SaveChanges();

            foreach (var itemReturnDetail in listReturnDetail)
            {
                _purchaseReturnDetailRepository.AttachNavigation(itemReturnDetail.CreateUser);
                _purchaseReturnRepository.AttachNavigation(itemReturnDetail.ModifyUser);
                _purchaseReturnRepository.AttachNavigation(itemReturnDetail.PurchaseReturn);
                _purchaseReturnRepository.AttachNavigation(itemReturnDetail.PurchasingDetail);
                _purchaseReturnDetailRepository.Add(itemReturnDetail);
            }

            _unitOfWork.SaveChanges();

            Transaction transaction = new Transaction();

            transaction.CreateDate       = serverTime;
            transaction.CreateUserId     = userID;
            transaction.ModifyDate       = serverTime;
            transaction.ModifyUserId     = userID;
            transaction.PrimaryKeyValue  = purchaseReturn.Id;
            transaction.ReferenceTableId = transactionReferenceTable.Id;
            transaction.TotalPayment     = totalTransaction.AsDouble();
            transaction.TotalTransaction = totalTransaction.AsDouble();
            transaction.Status           = (int)DbConstant.DefaultDataStatus.Active;
            transaction.Description      = "Retur Pembelian";
            transaction.TransactionDate  = serverTime;

            _transactionRepository.AttachNavigation(transaction.CreateUser);
            _transactionRepository.AttachNavigation(transaction.ModifyUser);
            _transactionRepository.AttachNavigation(transaction.PaymentMethod);
            _transactionRepository.AttachNavigation(transaction.ReferenceTable);
            transaction = _transactionRepository.Add(transaction);

            _unitOfWork.SaveChanges();

            TransactionDetail transDebit = new TransactionDetail();

            transDebit.Debit     = totalTransaction;
            transDebit.ParentId  = transaction.Id;
            transDebit.JournalId = _journalMasterRepository.GetMany(j => j.Code == "2.01.01.01").FirstOrDefault().Id;

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

            TransactionDetail transCredit = new TransactionDetail();

            transCredit.Credit    = totalTransaction;
            transCredit.ParentId  = transaction.Id;
            transCredit.JournalId = _journalMasterRepository.GetMany(j => j.Code == "1.01.04.01").FirstOrDefault().Id;

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

            _unitOfWork.SaveChanges();
        }