コード例 #1
0
ファイル: Repository.cs プロジェクト: Jagjeet1987/SampleBill
 public void Insert(T entity)
 {
     if (entity == null)
     {
         throw new ArgumentNullException("entity");
     }
     _Entities.Add(entity);
     _context.SaveChanges();
 }
コード例 #2
0
        public static Boolean VoucherLedgerGroupMap(AccountingDbContext accountingdbcontext, List <VoucherLedgerGroupMapModel> voucherLedgerMapData, RbacUser currentUser)
        {
            try
            {
                if (voucherLedgerMapData != null)
                {
                    ///  VoucherLedgerGroupMapModel vouchMap = new VoucherLedgerGroupMapModel();

                    for (int i = 0; i < voucherLedgerMapData.Count; i++)
                    {
                        voucherLedgerMapData[i].CreatedOn = DateTime.Now;
                        accountingdbcontext.VoucherLedgerGroupMaps.Add(voucherLedgerMapData[i]);
                    }

                    int j = accountingdbcontext.SaveChanges();
                    return((j > 0) ? true : false);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #3
0
 //update fiscal year will update only isActive
 public static void UpdateFiscalYear(FiscalYearModel fiscal, AccountingDbContext accDbContext)
 {
     try
     {
         accDbContext.FiscalYears.Attach(fiscal);
         accDbContext.Entry(fiscal).Property(x => x.IsActive).IsModified = true;
         accDbContext.SaveChanges();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
コード例 #4
0
 public static void AddFiscalYear(FiscalYearModel fiscal, AccountingDbContext accDbContext)
 {
     try
     {
         fiscal.CreatedOn = System.DateTime.Now;
         accDbContext.FiscalYears.Add(fiscal);
         accDbContext.SaveChanges();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
コード例 #5
0
 //here we are updating only IsTransferedToAcc
 public static void UpdateBillingSync(SyncBillingAccountingModel sync, AccountingDbContext accDbContext)
 {
     try
     {
         sync.IsTransferedToAcc = true;
         accDbContext.SyncBillingAccounting.Attach(sync);
         accDbContext.Entry(sync).Property(a => a.IsTransferedToAcc).IsModified = true;
         accDbContext.SaveChanges();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
コード例 #6
0
        public static void AddTransaction(TransactionModel txn, AccountingDbContext accDbContext)
        {
            try
            {
                txn.CreatedOn = System.DateTime.Now;
                txn.TransactionItems.ForEach(txnItem =>
                {
                    txnItem.CreatedOn = System.DateTime.Now;
                });

                accDbContext.Transactions.Add(txn);
                accDbContext.SaveChanges();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #7
0
 public static Boolean AddLedgerGroup(AccountingDbContext accountingdbcontext, LedgerGroupModel ledgerGroupData, RbacUser currentUser)
 {
     try
     {
         if (ledgerGroupData != null)
         {
             ledgerGroupData.CreatedOn = System.DateTime.Now;
             ledgerGroupData.CreatedBy = currentUser.UserId;
             accountingdbcontext.LedgerGroups.Add(ledgerGroupData);
             int i = accountingdbcontext.SaveChanges();
             return((i > 0) ? true : false);
         }
         else
         {
             return(false);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
コード例 #8
0
        //public static Boolean AccountClosureTransaction(AccountClosureVM closureVM, AccountingDbContext accountingDb)
        //{
        //    using (var dbContextTransaction = accountingDb.Database.BeginTransaction())
        //    {
        //        try
        //        {
        //            FiscalYearModel fy = accountingDb.FiscalYears.Where(a => a.IsActive == true).FirstOrDefault();

        //            if (fy != null)
        //            {
        //                fy.IsActive = false;
        //                UpdateFiscalYear(fy, accountingDb);
        //            }

        //            AddFiscalYear(closureVM.nextFiscalYear, accountingDb);

        //            closureVM.TnxModel.FiscalyearId = closureVM.nextFiscalYear.FiscalYearId;
        //            closureVM.TnxModel.VoucherId = 1;
        //            AddTransaction(closureVM.TnxModel, accountingDb);
        //            dbContextTransaction.Commit();
        //            return true;
        //        }
        //        catch (Exception ex)
        //        {
        //            dbContextTransaction.Rollback();
        //            throw ex;
        //        }
        //    }
        //}

        #region account closure
        //Ajay 24-10-2018
        public static bool AccountClosure(FiscalYearModel fiscalYear, AccountingDbContext accountingDBContext)
        {
            using (var dbContextTransaction = accountingDBContext.Database.BeginTransaction())
            {
                try
                {
                    //get active fiscal year and deactive it
                    FiscalYearModel fy = accountingDBContext.FiscalYears.Where(a => a.IsActive == true).FirstOrDefault();
                    if (fy != null)
                    {
                        fy.IsActive = false;
                        UpdateFiscalYear(fy, accountingDBContext);
                    }
                    //add new fiscal year
                    AddFiscalYear(fiscalYear, accountingDBContext);
                    //get active ledgers with primary group Assets or Liabialities
                    var ledgers = (from led in accountingDBContext.Ledgers
                                   join ledGrp in accountingDBContext.LedgerGroups on led.LedgerGroupId equals ledGrp.LedgerGroupId
                                   where led.IsActive == true   // && (ledGrp.PrimaryGroup == "Assets" || ledGrp.PrimaryGroup == "Liabilities")
                                   select new
                    {
                        led.LedgerId,
                        led.OpeningBalance,
                        led.DrCr,
                        ledGrp.PrimaryGroup
                    }).ToList();

                    ledgers.ForEach(ledger =>
                    {
                        LedgerBalanceHistoryModel ledgerBalanceHistory = new LedgerBalanceHistoryModel();
                        LedgerModel led = accountingDBContext.Ledgers.Where(x => x.LedgerId == ledger.LedgerId).FirstOrDefault();
                        //calculate closing balance
                        if (ledger.PrimaryGroup == "Assets" || ledger.PrimaryGroup == "Liabilities")
                        {
                            double drAmount = accountingDBContext.TransactionItems
                                              .Where(x => x.LedgerId == ledger.LedgerId && x.DrCr == true)
                                              .Select(x => x.Amount).Sum().GetValueOrDefault();
                            double crAmount = accountingDBContext.TransactionItems
                                              .Where(x => x.LedgerId == ledger.LedgerId && x.DrCr == false)
                                              .Select(x => x.Amount).Sum().GetValueOrDefault();

                            if (led.DrCr == true)
                            {
                                drAmount = drAmount + led.OpeningBalance.Value;
                            }
                            if (led.DrCr == false)
                            {
                                crAmount = crAmount + led.OpeningBalance.Value;
                            }
                            if (drAmount > crAmount)
                            {
                                ledgerBalanceHistory.ClosingDrCr    = true;
                                ledgerBalanceHistory.ClosingBalance = drAmount - crAmount;

                                led.OpeningBalance = drAmount - crAmount;
                                led.DrCr           = true;
                            }
                            if (drAmount < crAmount)
                            {
                                ledgerBalanceHistory.ClosingDrCr    = false;
                                ledgerBalanceHistory.ClosingBalance = crAmount - drAmount;

                                led.OpeningBalance = crAmount - drAmount;
                                led.DrCr           = false;
                            }
                        }


                        //adding ledgerBalanceHistory
                        ledgerBalanceHistory.FiscalYearId   = accountingDBContext.FiscalYears.Where(a => a.IsActive == true).FirstOrDefault().FiscalYearId;
                        ledgerBalanceHistory.LedgerId       = ledger.LedgerId;
                        ledgerBalanceHistory.OpeningBalance = ledger.OpeningBalance;
                        ledgerBalanceHistory.OpeningDrCr    = led.DrCr;
                        ledgerBalanceHistory.CreatedOn      = DateTime.Now;
                        ledgerBalanceHistory.CreatedBy      = fiscalYear.CreatedBy;
                        accountingDBContext.LedgerBalanceHistory.Add(ledgerBalanceHistory);
                        accountingDBContext.SaveChanges();


                        //updating ledger opening balance
                        accountingDBContext.Ledgers.Attach(led);
                        accountingDBContext.Entry(led).Property(x => x.OpeningBalance).IsModified = true;
                        accountingDBContext.Entry(led).Property(x => x.DrCr).IsModified           = true;
                        accountingDBContext.SaveChanges();
                    });



                    dbContextTransaction.Commit();
                    return(true);
                }
                catch (Exception ex)
                {
                    dbContextTransaction.Rollback();
                    throw ex;
                }
            }
        }
コード例 #9
0
        public void CreateUniversalBulkPayment(List <CreateUniversalBulkPaymentInputDto> input)
        {
            Logger.Info("CreateUniversalBulkPayment() - Started.");

            var           transNo            = new JObject();
            List <int>    listPayTypeID      = new List <int>();
            List <string> listOthersTypeCode = new List <string>();

            foreach (var dataInput in input)
            {
                int payNo = 0;

                var accCode    = (from A in _msAccountRepo.GetAll() where A.Id == dataInput.accID select A.accCode).FirstOrDefault();
                var bookCode   = (from A in _trBookingHeaderRepo.GetAll() where A.Id == dataInput.bookingHeaderID select A.bookCode).FirstOrDefault();
                var coCode     = (from A in _msAccountRepo.GetAll() where A.Id == dataInput.accID select A.devCode).FirstOrDefault();
                var payForCode = (from A in _lkPayForRepo.GetAll() where A.Id == dataInput.payForID select A.payForCode).FirstOrDefault();


                var dataInputTransNo = new GenerateTransNoInputDto
                {
                    accID    = dataInput.accID,
                    entityID = 1
                };

                transNo = _iPSASScheduleAppService.GenerateTransNo(dataInputTransNo);

                #region createTrPaymentHeader

                var combineCode = (from A in _trBookingDetailRepo.GetAll()
                                   join B in _msCompanyRepo.GetAll() on A.coCode equals B.coCode
                                   join C in _msAccountRepo.GetAll() on B.Id equals C.coID
                                   where A.bookingHeaderID == dataInput.bookingHeaderID && C.Id == dataInput.accID
                                   select A.combineCode).FirstOrDefault();

                var dataInputPaymentHeader = new CreatePaymentHeaderInputDto
                {
                    entityID        = 1,
                    accountID       = dataInput.accID,
                    bookingHeaderID = dataInput.bookingHeaderID == null ? null : dataInput.bookingHeaderID,
                    clearDate       = dataInput.clearDate,
                    combineCode     = combineCode == null ? "1" : combineCode, //wait
                    ket             = "-",
                    payForID        = dataInput.payForID,
                    paymentDate     = DateTime.Now,
                    transNo         = transNo.GetValue("transNo").ToString(),
                    controlNo       = transNo.GetValue("transNo").ToString(),
                    isSms           = false,
                    hadMail         = false
                };

                int paymentHeaderId = _iInputPaymentAppService.CreateTrPaymentHeader(dataInputPaymentHeader);

                #endregion

                foreach (var dataInputPayment in dataInput.dataForPayment)
                {
                    var checkMsMapping = (from a in _contextAccounting.MS_Mapping.ToList()
                                          join b in _contextPropertySystem.LK_PayFor on a.payForCode equals b.payForCode
                                          join c in _contextPropertySystem.LK_PayType on a.payTypeCode equals c.payTypeCode
                                          where b.Id == dataInput.payForID && c.Id == dataInputPayment.payTypeID && a.othersTypeCode == dataInputPayment.othersTypeCode
                                          select a).FirstOrDefault();

                    #region createTrPaymentBulk

                    var dataCreateTrPaymentBulk = new CreateTrPaymentBulkInputDto
                    {
                        bulkPaymentKey  = dataInput.bookCode + "#" + dataInput.psCode + "#" + dataInput.clearDate.Date + "#" + dataInputPayment.othersTypeCode,
                        bookingHeaderID = dataInput.bookingHeaderID,
                        clearDate       = dataInput.clearDate,
                        psCode          = dataInput.psCode,
                        name            = dataInput.name,
                        payForID        = dataInput.payForID,
                        payTypeID       = dataInputPayment.payTypeID,
                        othersTypeID    = dataInputPayment.othersTypeID,
                        unitID          = dataInput.unitID,
                        amount          = dataInputPayment.amount
                    };
                    CreateTrPaymentBulk(dataCreateTrPaymentBulk);

                    #endregion

                    #region createTrPaymentDetail

                    payNo++;

                    var dataInsertPaymentDetail = new CreatePaymentDetailInputDto
                    {
                        bankName        = "-",
                        chequeNo        = "-",
                        dueDate         = dataInput.clearDate,
                        entityID        = 1,
                        ket             = dataInput.name,
                        othersTypeCode  = dataInputPayment.othersTypeCode,
                        paymentHeaderID = paymentHeaderId,
                        payNo           = payNo,
                        payTypeID       = dataInputPayment.payTypeID,
                        status          = "C"
                    };

                    int paymentDetailId = _iInputPaymentAppService.CreateTrPaymentDetail(dataInsertPaymentDetail);


                    #region createTrPaymentDetailAlloc

                    foreach (var dataAlloc in dataInputPayment.dataAllocList)
                    {
                        var dataInputDetailAlloc = new CreatePaymentDetailAllocInputDto
                        {
                            entityID        = 1,
                            netAmt          = dataAlloc.amount == 0 ? dataAlloc.amountPerSchedNo / (decimal)(1 + dataInput.pctTax) : (dataAlloc.amountPerSchedNo - dataAlloc.amount) / (decimal)(1 + dataInput.pctTax),
                            vatAmt          = dataAlloc.amount == 0 ? (dataAlloc.amountPerSchedNo / (decimal)(1 + dataInput.pctTax)) * (decimal)dataInput.pctTax : ((dataAlloc.amountPerSchedNo - dataAlloc.amount) / (decimal)(1 + dataInput.pctTax)) * (decimal)dataInput.pctTax,
                            paymentDetailID = paymentDetailId,
                            schedNo         = dataAlloc.schedNo
                        };
                        _iInputPaymentAppService.CreateTrPaymentDetailAlloc(dataInputDetailAlloc);
                    }

                    #endregion

                    #region Accounting
                    //if (checkMsMapping != null)
                    //{
                    //    var dataInputJournalCode = new GenerateJurnalInputDto
                    //    {
                    //        accCode = accCode,
                    //        bookCode = bookCode,
                    //        coCode = coCode,
                    //        transNo = transNo.GetValue("transNo").ToString(),
                    //        payNo = payNo
                    //    };

                    //    var journalCode = _iInputPaymentAppService.GenerateJurnalCode(dataInputJournalCode);

                    //    #region createTrPaymentDetailJournal

                    //    var dataToInsertTRPaymentDetailJournal = new CreateAccountingTrPaymentDetailJournalInputDto
                    //    {
                    //        accCode = accCode,
                    //        bookCode = bookCode,
                    //        entityCode = "1",
                    //        payNo = payNo,
                    //        transNo = transNo.GetValue("transNo").ToString(),
                    //        journalCode = journalCode.GetValue("journalCode").ToString()
                    //    };

                    //    _iInputPaymentAppService.CreateAccountingTrPaymentDetailJournal(dataToInsertTRPaymentDetailJournal);

                    //    #endregion

                    //    #region createTrJournal

                    //    var getMsJournal = (from a in _contextAccounting.MS_JournalType.ToList()
                    //                        where a.journalTypeCode == checkMsMapping.journalTypeCode
                    //                        select new
                    //                        {
                    //                            a.COACodeFIN,
                    //                            a.amtTypeCode,
                    //                            a.ACCAlloc
                    //                        }).ToList();

                    //    foreach (var dataJournal in getMsJournal)
                    //    {
                    //        decimal debit = 0;
                    //        decimal kredit = 0;
                    //        if (dataJournal.ACCAlloc < 0)
                    //        {
                    //            if (dataJournal.amtTypeCode == "1")
                    //            {
                    //                debit = 0;
                    //                kredit = dataInputPayment.amount;
                    //            }

                    //            else if (dataJournal.amtTypeCode == "2")
                    //            {
                    //                debit = 0;
                    //                kredit = dataInputPayment.amount / (1 + (decimal)dataInput.pctTax);
                    //            }

                    //            else if (dataJournal.amtTypeCode == "3")
                    //            {
                    //                debit = 0;
                    //                kredit = (dataInputPayment.amount / (1 + (decimal)dataInput.pctTax)) * (decimal)dataInput.pctTax;
                    //            }
                    //        }
                    //        else
                    //        {
                    //            if (dataJournal.amtTypeCode == "1")
                    //            {
                    //                debit = dataInputPayment.amount;
                    //                kredit = 0;
                    //            }

                    //            if (dataJournal.amtTypeCode == "2")
                    //            {
                    //                debit = dataInputPayment.amount / (1 + (decimal)dataInput.pctTax);
                    //                kredit = 0;
                    //            }

                    //            if (dataJournal.amtTypeCode == "3")
                    //            {
                    //                debit = (dataInputPayment.amount / (1 + (decimal)dataInput.pctTax)) * (decimal)dataInput.pctTax;
                    //                kredit = 0;
                    //            }
                    //        }

                    //        var dataToInsertTrJournal = new CreateTrJournalInputDto
                    //        {
                    //            COACodeAcc = "-",
                    //            COACodeFIN = dataJournal.COACodeFIN,
                    //            entityCode = "1",
                    //            journalCode = journalCode.GetValue("journalCode").ToString(),
                    //            journalDate = DateTime.Now,
                    //            debit = debit,
                    //            kredit = kredit,
                    //            remarks = "-",
                    //        };

                    //        _iInputPaymentAppService.CreateTrJournal(dataToInsertTrJournal);
                    //    }

                    //    #endregion
                    //}

                    #endregion

                    #endregion

                    listPayTypeID.Add(dataInputPayment.payTypeID);
                    listOthersTypeCode.Add(dataInputPayment.othersTypeCode);
                }

                #region TAX

                //    var payTypeCode = (from A in _lkPayTypeRepo.GetAll() where listPayTypeID.Contains(A.Id) select A.payTypeCode).ToList();

                //    var getPaymentHeaderForUpdate = (from a in _trPaymentHeaderRepo.GetAll()
                //                                     where a.Id == paymentHeaderId
                //                                     select a).FirstOrDefault();


                //    List<string> listCheckPayForCode = new List<string>
                //{
                //    "PMT", "OTP"
                //};

                //    List<string> listCheckPayTypeCode = new List<string>
                //{
                //    "CSH", "CRE", "GRO", "STN", "TRN", "CHQ", "DBT", "ADJ", "ADB", "ADC", "VRT"
                //};

                //    List<string> listCheckOthersTypeCode = new List<string>
                //{
                //    "ALH", "PMT", "ALI", "KPR", "BFE", "LHL", "DEP", "AD1", "AD2", "ADR", "BNK", "BPS", "LHA", "PAF"
                //};

                //    var updatePaymentHeader = getPaymentHeaderForUpdate.MapTo<TR_PaymentHeader>();

                //    if (listCheckPayForCode.Contains(payForCode) && listCheckPayTypeCode.Intersect(payTypeCode).Any() && listCheckOthersTypeCode.Intersect(listOthersTypeCode).Any())
                //    {
                //        var checkBatchPajakStock = (from a in _contextTAX.msBatchPajakStock.ToList()
                //                                    where a.CoCode == coCode && a.IsAvailable == true && a.YearPeriod == DateTime.Now.Year.ToString()
                //                                    orderby a.BatchID
                //                                    select a).FirstOrDefault();

                //        decimal totalAmountAll = dataInput.dataForPayment.Sum(x => x.amount);

                //        //done
                //        if (checkBatchPajakStock != null)
                //        {
                //            var FPCode = "010." + checkBatchPajakStock.FPBranchCode + "-" + checkBatchPajakStock.FPYear + "." + checkBatchPajakStock.FPNo;

                //            var dataToInsertTrFpHeader = new CreateTAXTrFPHeaderInputDto
                //            {
                //                accCode = accCode,
                //                coCode = coCode,
                //                entityCode = "1",
                //                discAmount = 0,
                //                DPAmount = 0,
                //                FPBranchCode = checkBatchPajakStock.FPBranchCode,
                //                unitPriceAmt = 0,
                //                userAddress = input.address,
                //                FPTransCode = "01",
                //                FPStatCode = "0",
                //                FPYear = checkBatchPajakStock.FPYear,
                //                FPNo = checkBatchPajakStock.FPNo,
                //                FPType = "1",
                //                transDate = DateTime.Now,
                //                unitCode = dataInput.unitCode,
                //                unitNo = input.unitNo,
                //                sourceCode = "PSY",
                //                priceType = "1",
                //                transNo = input.transNo,
                //                rentalCode = "-",
                //                paymentCode = "-",
                //                payNo = 0,
                //                pmtBatchNo = "-",
                //                FPCode = FPCode,
                //                unitPriceVat = 0,
                //                vatAmt = (totalAmountAll / (1 + (decimal)dataInput.pctTax)) * (decimal)dataInput.pctTax, //netAmt * pctTax
                //                name = dataInput.name,
                //                NPWP = input.NPWP,
                //                psCode = dataInput.psCode
                //            };

                //            CreateTAXTrFPHeader(dataToInsertTrFpHeader);

                //            var unitName = (from a in _msUnitCodeRepo.GetAll()
                //                            where a.unitCode == input.unitCode
                //                            select new { a.unitName, a.Id }).FirstOrDefault();

                //            var unitNo = (from a in _msUnitRepo.GetAll()
                //                          where a.unitCodeID == unitName.Id
                //                          select a.unitNo).ToString();

                //            var dataToInsertTrFpDetail = new CreateTAXTrFPDetailInputDto
                //            {
                //                coCode = coCode,
                //                entityCode = "1",
                //                FPCode = FPCode,
                //                transNo = 1,
                //                currencyCode = "Rp",
                //                currencyRate = 1,
                //                transDesc = "Lantai " + unitName.unitName + " No. " + unitNo + " (" + input.transNo + ")",
                //                transAmount = totalAmountAll / 1 + (decimal)dataInput.pctTax
                //            };

                //            CreateTAXTrFPDetail(dataToInsertTrFpDetail);

                //            var getBatchPajakStock = (from a in _contextTAX.msBatchPajakStock.ToList()
                //                                      where a.BatchID == checkBatchPajakStock.BatchID
                //                                      select a).FirstOrDefault();

                //            var updateBatchPajakStock = getBatchPajakStock.MapTo<msBatchPajakStock>();
                //            updateBatchPajakStock.IsAvailable = false;
                //            _contextTAX.msBatchPajakStock.Update(updateBatchPajakStock);

                //            updatePaymentHeader.isFP = "1";
                //            _trPaymentHeaderRepo.Update(updatePaymentHeader);
                //        }
                //        //kehabisan FP
                //        else
                //        {
                //            updatePaymentHeader.isFP = "2";
                //            _trPaymentHeaderRepo.Update(updatePaymentHeader);
                //        }
                //    }
                //    //no TAX
                //    else
                //    {
                //        updatePaymentHeader.isFP = "3";
                //        _trPaymentHeaderRepo.Update(updatePaymentHeader);
                //    }

                #endregion

                #region updateBookingSchedule

                var getDataShedule = (from a in _trBookingDetailScheduleRepo.GetAll()
                                      join b in _trBookingDetailRepo.GetAll() on a.bookingDetailID equals b.Id
                                      join c in _msAccountRepo.GetAll() on b.coCode equals c.devCode
                                      join d in _lkAllocRepo.GetAll() on a.allocID equals d.Id
                                      where b.bookingHeaderID == dataInput.bookingHeaderID && c.Id == dataInput.accID && d.payForID == dataInput.payForID
                                      select a).ToList();

                var getDataSheduleGroupSchedNo = (from a in getDataShedule
                                                  group a by new
                {
                    a.schedNo
                } into G
                                                  select new
                {
                    netAmt = G.Sum(x => x.netAmt),
                    vatAmt = G.Sum(x => x.vatAmt),
                    G.Key.schedNo
                }).ToList();

                var getTotalAmount = (from x in _trBookingDetailRepo.GetAll()
                                      where x.bookingHeaderID == dataInput.bookingHeaderID
                                      group x by new { x.bookingHeaderID } into G
                                      select new
                {
                    bookHeaderID = G.Key.bookingHeaderID,
                    TotalNetNetPrice = G.Sum(d => d.netNetPrice)
                }).FirstOrDefault();

                foreach (var dataScheduleGroupSchedNo in getDataSheduleGroupSchedNo)
                {
                    var getDataSchedulePerSchedNo = (from a in getDataShedule
                                                     where a.schedNo == dataScheduleGroupSchedNo.schedNo
                                                     select a).ToList();

                    foreach (var dataSchedulePerSchedNo in getDataSchedulePerSchedNo)
                    {
                        var getPercentage = (from x in _trBookingDetailRepo.GetAll()
                                             where x.bookingHeaderID == dataInput.bookingHeaderID && x.Id == dataSchedulePerSchedNo.bookingDetailID
                                             select new
                        {
                            x.bookingHeaderID,
                            netNetPrice = x.netNetPrice / getTotalAmount.TotalNetNetPrice
                        }).FirstOrDefault();

                        var getDataAmtForUpdate = (from a in dataInput.dataScheduleList
                                                   where a.schedNo == dataSchedulePerSchedNo.schedNo
                                                   select new
                        {
                            netOut = a.amount == 0 ? a.amount * getPercentage.netNetPrice : (a.amount / (decimal)(1 + dataInput.pctTax)) * getPercentage.netNetPrice,
                            vatOut = a.amount == 0 ? a.amount * getPercentage.netNetPrice : ((a.amount / (decimal)(1 + dataInput.pctTax)) * (decimal)dataInput.pctTax) * getPercentage.netNetPrice,
                        }).FirstOrDefault();

                        if (getDataAmtForUpdate != null)
                        {
                            var updateBookingSchedule = dataSchedulePerSchedNo.MapTo <TR_BookingDetailSchedule>();

                            updateBookingSchedule.netOut = getDataAmtForUpdate.netOut;
                            updateBookingSchedule.vatOut = getDataAmtForUpdate.vatOut;

                            _trBookingDetailScheduleRepo.Update(updateBookingSchedule);
                        }
                    }
                }
                #endregion
            }


            _contextAccounting.SaveChanges();

            Logger.Info("CreateUniversalBulkPayment() - Finished.");
        }
コード例 #10
0
        public string Update(/*string reqType*/)
        {
            DanpheHTTPResponse <object> responseData = new DanpheHTTPResponse <object>();

            AccountingDbContext accountingDBContext = new AccountingDbContext(connString);


            try
            {
                //string str = Request.Form.Keys.First<string>();
                string   str         = this.ReadPostData();
                string   reqType     = this.ReadQueryStringData("reqType");
                RbacUser currentUser = HttpContext.Session.Get <RbacUser>("currentuser");
                if (!String.IsNullOrEmpty(str))
                {
                    if (reqType == "itemISActive")
                    {
                        ItemModel item = DanpheJSONConvert.DeserializeObject <ItemModel>(str);
                        accountingDBContext.Items.Attach(item);
                        accountingDBContext.Entry(item).Property(x => x.IsActive).IsModified = true;
                        accountingDBContext.SaveChanges();
                        responseData.Results = item;
                        responseData.Status  = "OK";
                    }
                    else if (reqType == "ledgerISActive")
                    {
                        LedgerModel ledger = DanpheJSONConvert.DeserializeObject <LedgerModel>(str);
                        accountingDBContext.Ledgers.Attach(ledger);
                        accountingDBContext.Entry(ledger).Property(x => x.IsActive).IsModified = true;
                        accountingDBContext.SaveChanges();
                        responseData.Results = ledger;
                        responseData.Status  = "OK";
                    }
                    else if (reqType == "updateLedgerGrpIsActive")
                    {
                        LedgerGroupModel ledgerGrp = DanpheJSONConvert.DeserializeObject <LedgerGroupModel>(str);
                        accountingDBContext.LedgerGroups.Attach(ledgerGrp);
                        accountingDBContext.Entry(ledgerGrp).Property(x => x.IsActive).IsModified = true;
                        accountingDBContext.SaveChanges();
                        responseData.Status  = "OK";
                        responseData.Results = ledgerGrp;
                    }
                    else if (reqType == "updateLedgerGroup")
                    {
                        LedgerGroupModel ledgerGroup = DanpheJSONConvert.DeserializeObject <LedgerGroupModel>(str);
                        var ledgerGrp = accountingDBContext.LedgerGroups.Where(x => x.LedgerGroupId == ledgerGroup.LedgerGroupId).FirstOrDefault();
                        if (ledgerGrp != null)
                        {
                            ledgerGrp.COA             = ledgerGroup.COA;
                            ledgerGrp.Description     = ledgerGroup.Description;
                            ledgerGrp.IsActive        = ledgerGroup.IsActive;
                            ledgerGrp.LedgerGroupName = ledgerGroup.LedgerGroupName;
                            ledgerGrp.ModifiedBy      = ledgerGroup.ModifiedBy;
                            ledgerGrp.ModifiedOn      = System.DateTime.Now;
                            ledgerGrp.PrimaryGroup    = ledgerGroup.PrimaryGroup;

                            accountingDBContext.LedgerGroups.Attach(ledgerGrp);
                            accountingDBContext.Entry(ledgerGrp).Property(x => x.COA).IsModified             = true;
                            accountingDBContext.Entry(ledgerGrp).Property(x => x.Description).IsModified     = true;
                            accountingDBContext.Entry(ledgerGrp).Property(x => x.IsActive).IsModified        = true;
                            accountingDBContext.Entry(ledgerGrp).Property(x => x.LedgerGroupName).IsModified = true;
                            accountingDBContext.Entry(ledgerGrp).Property(x => x.ModifiedBy).IsModified      = true;
                            accountingDBContext.Entry(ledgerGrp).Property(x => x.ModifiedOn).IsModified      = true;
                            accountingDBContext.Entry(ledgerGrp).Property(x => x.PrimaryGroup).IsModified    = true;
                            accountingDBContext.SaveChanges();
                            responseData.Results = ledgerGrp;
                            responseData.Status  = "OK";
                        }
                        else
                        {
                            responseData.Status = "Failed";
                        }
                    }
                    else if (reqType == "updateFiscalYearStatus")
                    {
                        FiscalYearModel fiscalYearModel = DanpheJSONConvert.DeserializeObject <FiscalYearModel>(str);
                        accountingDBContext.FiscalYears.Attach(fiscalYearModel);
                        accountingDBContext.Entry(fiscalYearModel).Property(x => x.IsActive).IsModified = true;
                        accountingDBContext.SaveChanges();
                        responseData.Status  = "OK";
                        responseData.Results = fiscalYearModel;
                    }
                    else if (reqType == "updateCostCenterItemStatus")
                    {
                        CostCenterItemModel ccImodel = DanpheJSONConvert.DeserializeObject <CostCenterItemModel>(str);
                        accountingDBContext.CostCenterItems.Attach(ccImodel);
                        accountingDBContext.Entry(ccImodel).Property(x => x.IsActive).IsModified = true;
                        accountingDBContext.SaveChanges();
                        responseData.Status  = "OK";
                        responseData.Results = ccImodel;
                    }
                    else if (reqType == "updateLedgerGrpCategoryIsActive")
                    {
                        LedgerGroupCategoryModel ledgerGrpCat = DanpheJSONConvert.DeserializeObject <LedgerGroupCategoryModel>(str);
                        accountingDBContext.LedgerGroupsCategory.Attach(ledgerGrpCat);
                        accountingDBContext.Entry(ledgerGrpCat).Property(x => x.IsActive).IsModified = true;
                        accountingDBContext.SaveChanges();
                        responseData.Status  = "OK";
                        responseData.Results = ledgerGrpCat;
                    }
                    else if (reqType == "UpdateLedger")
                    {
                        LedgerModel ledger = DanpheJSONConvert.DeserializeObject <LedgerModel>(str);
                        var         led    = accountingDBContext.Ledgers.Where(s => s.LedgerId == ledger.LedgerId).FirstOrDefault();
                        if (led != null)
                        {
                            led.IsActive               = ledger.IsActive;
                            led.LedgerName             = ledger.LedgerName;
                            led.OpeningBalance         = ledger.OpeningBalance;
                            led.Description            = ledger.Description;
                            led.IsCostCenterApplicable = ledger.IsCostCenterApplicable;
                            led.DrCr = ledger.DrCr;
                            accountingDBContext.Ledgers.Attach(led);
                            accountingDBContext.Entry(led).Property(x => x.IsActive).IsModified               = true;
                            accountingDBContext.Entry(led).Property(x => x.LedgerName).IsModified             = true;
                            accountingDBContext.Entry(led).Property(x => x.Description).IsModified            = true;
                            accountingDBContext.Entry(led).Property(x => x.DrCr).IsModified                   = true;
                            accountingDBContext.Entry(led).Property(x => x.IsCostCenterApplicable).IsModified = true;
                            accountingDBContext.Entry(led).Property(x => x.OpeningBalance).IsModified         = true;
                            accountingDBContext.SaveChanges();
                            responseData.Status  = "OK";
                            responseData.Results = led;
                        }
                        else
                        {
                            responseData.Status = "Failed";
                        }
                    }

                    else if (reqType == "UpdateVoucherHead")
                    {
                        VoucherHeadModel voucher = DanpheJSONConvert.DeserializeObject <VoucherHeadModel>(str);
                        var voucherHead          = accountingDBContext.VoucherHeads.Where(s => s.VoucherHeadId == voucher.VoucherHeadId).FirstOrDefault();
                        if (voucherHead != null)
                        {
                            voucherHead.IsActive        = voucher.IsActive;
                            voucherHead.VoucherHeadName = voucher.VoucherHeadName;
                            voucherHead.Description     = voucher.Description;
                            voucherHead.ModifiedOn      = System.DateTime.Now;
                            voucherHead.ModifiedBy      = voucher.ModifiedBy;
                            accountingDBContext.VoucherHeads.Attach(voucherHead);
                            accountingDBContext.Entry(voucherHead).Property(x => x.IsActive).IsModified        = true;
                            accountingDBContext.Entry(voucherHead).Property(x => x.VoucherHeadName).IsModified = true;
                            accountingDBContext.Entry(voucherHead).Property(x => x.Description).IsModified     = true;
                            accountingDBContext.Entry(voucherHead).Property(x => x.ModifiedOn).IsModified      = true;
                            accountingDBContext.Entry(voucherHead).Property(x => x.ModifiedBy).IsModified      = true;
                            accountingDBContext.SaveChanges();
                            responseData.Status  = "OK";
                            responseData.Results = voucherHead;
                        }
                        else
                        {
                            responseData.Status = "Failed";
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                responseData.Status       = "Failed";
                responseData.ErrorMessage = ex.Message + " exception details:" + ex.ToString();
            }
            return(DanpheJSONConvert.SerializeObject(responseData, true));
        }
コード例 #11
0
        public string Post()
        {
            //if reqtype=employee, then use masterdbcontext.employee.add  and so on for others.

            DanpheHTTPResponse <object> responseData = new DanpheHTTPResponse <object>(); //type 'object' since we have variable return types

            responseData.Status = "OK";                                                   //by default status would be OK, hence assigning at the top
            AccountingDbContext accountingDBContext = new AccountingDbContext(connString);
            RbacUser            currentUser         = HttpContext.Session.Get <RbacUser>("currentuser");

            try
            {
                string str         = this.ReadPostData();
                string reqType     = this.ReadQueryStringData("reqType");
                string companyName = this.ReadQueryStringData("companyName");

                if (reqType == "AddLedgers")
                {
                    LedgerModel ledger = DanpheJSONConvert.DeserializeObject <LedgerModel>(str);
                    if (accountingDBContext.Ledgers.Any(r => r.LedgerGroupId == ledger.LedgerGroupId && r.LedgerName == ledger.LedgerName))
                    {
                        responseData.Status = "Failed";
                    }
                    else
                    {
                        ledger.CreatedOn = System.DateTime.Now;
                        accountingDBContext.Ledgers.Add(ledger);
                        accountingDBContext.SaveChanges();
                        if (ledger.LedgerType == "pharmacysupplier")
                        {
                            LedgerMappingModel ledgerMapping = new LedgerMappingModel();
                            ledgerMapping.LedgerId    = ledger.LedgerId;
                            ledgerMapping.LedgerType  = ledger.LedgerType;
                            ledgerMapping.ReferenceId = (int)ledger.LedgerReferenceId;
                            accountingDBContext.LedgerMappings.Add(ledgerMapping);
                        }
                        accountingDBContext.SaveChanges();
                        responseData.Results = ledger;
                        responseData.Status  = "OK";
                    }
                }
                if (reqType == "AddLedgersList")
                {
                    List <LedgerModel> Ledgrs = DanpheJSONConvert.DeserializeObject <List <LedgerModel> >(str);
                    //if (accountingDBContext.Ledgers.Any(r => r.LedgerGroupId == ledger.LedgerGroupId && r.LedgerName == ledger.LedgerName))
                    //{
                    //    responseData.Status = "Failed";
                    //}
                    //else
                    //{
                    Ledgrs.ForEach(ledger =>
                    {
                        ledger.CreatedOn = System.DateTime.Now;
                        accountingDBContext.Ledgers.Add(ledger);
                        accountingDBContext.SaveChanges();
                        if (ledger.LedgerType == "pharmacysupplier")
                        {
                            LedgerMappingModel ledgerMapping = new LedgerMappingModel();
                            ledgerMapping.LedgerId           = ledger.LedgerId;
                            ledgerMapping.LedgerType         = ledger.LedgerType;
                            ledgerMapping.ReferenceId        = (int)ledger.LedgerReferenceId;
                            accountingDBContext.LedgerMappings.Add(ledgerMapping);
                        }
                    });

                    accountingDBContext.SaveChanges();
                    responseData.Results = Ledgrs;
                    responseData.Status  = "OK";
                    //}
                }
                else if (reqType == "AddVouchers")
                {
                    VoucherModel voucher = DanpheJSONConvert.DeserializeObject <VoucherModel>(str);
                    voucher.CreatedOn = System.DateTime.Now;
                    voucher.CreatedBy = currentUser.UserId;
                    accountingDBContext.Vouchers.Add(voucher);
                    accountingDBContext.SaveChanges();
                    responseData.Results = voucher;
                    responseData.Status  = "OK";
                }

                else if (reqType == "AddVoucherHead")
                {
                    VoucherHeadModel voucherHead = DanpheJSONConvert.DeserializeObject <VoucherHeadModel>(str);
                    if (accountingDBContext.VoucherHeads.Any(x => x.VoucherHeadId == voucherHead.VoucherHeadId && x.VoucherHeadName == voucherHead.VoucherHeadName))
                    {
                        responseData.Status = "Failed";
                    }
                    else
                    {
                        voucherHead.CreatedOn = System.DateTime.Now;
                        voucherHead.CreatedBy = currentUser.UserId;
                        accountingDBContext.VoucherHeads.Add(voucherHead);
                        accountingDBContext.SaveChanges();
                        responseData.Results = voucherHead;
                        responseData.Status  = "OK";
                    }
                }
                else if (reqType == "AddItems")
                {
                    ItemModel item = DanpheJSONConvert.DeserializeObject <ItemModel>(str);
                    item.CreatedOn = System.DateTime.Now;
                    accountingDBContext.Items.Add(item);
                    accountingDBContext.SaveChanges();
                    var itemWithLedgerName = (from led in accountingDBContext.Ledgers
                                              where led.LedgerId == item.LedgerId
                                              select new
                    {
                        ItemId = item.ItemId,
                        ItemName = item.ItemName,
                        AvailableQuantity = item.AvailableQuantity,
                        IsActive = item.IsActive,
                        Description = item.Description,
                        LedgerId = item.LedgerId,
                        LedgerName = led.LedgerName
                    }
                                              );
                    responseData.Results = itemWithLedgerName;
                    responseData.Status  = "OK";
                }
                else if (reqType == "AddLedgersGroup")
                {
                    LedgerGroupModel ledgerGrpData = DanpheJSONConvert.DeserializeObject <LedgerGroupModel>(str);
                    if (accountingDBContext.LedgerGroups.Any(r => r.LedgerGroupName == ledgerGrpData.LedgerGroupName && r.COA == ledgerGrpData.COA && r.PrimaryGroup == ledgerGrpData.PrimaryGroup))
                    {
                        responseData.Status = "Failed";
                    }
                    else
                    {
                        ledgerGrpData.CreatedOn = DateTime.Now;
                        ledgerGrpData.CreatedBy = currentUser.UserId;
                        accountingDBContext.LedgerGroups.Add(ledgerGrpData);
                        accountingDBContext.SaveChanges();
                        responseData.Results = ledgerGrpData;
                        responseData.Status  = "OK";
                    }
                }
                else if (reqType == "manageVoucherWithLedgegroup")
                {
                    List <VoucherLedgerGroupMapModel> mappedData = DanpheJSONConvert.DeserializeObject <List <VoucherLedgerGroupMapModel> >(str);
                    var postMappedLedgerGroup = new List <VoucherLedgerGroupMapModel>();
                    var putMappedLedgerGroup  = new List <VoucherLedgerGroupMapModel>();
                    //map and separate two list for add and update
                    mappedData.ForEach(x =>
                    {
                        if (x.actionName == "post")
                        {
                            x.CreatedOn = DateTime.Now;
                            x.CreatedBy = currentUser.UserId;
                            postMappedLedgerGroup.Add(x);
                        }
                        else if (x.actionName == "put")
                        {
                            putMappedLedgerGroup.Add(x);
                        }
                    });
                    //update
                    foreach (var itm in putMappedLedgerGroup)
                    {
                        accountingDBContext.VoucherLedgerGroupMaps.Attach(itm);
                        accountingDBContext.Entry(itm).Property(x => x.IsActive).IsModified = true;
                    }
                    accountingDBContext.SaveChanges();

                    //add
                    foreach (var itm in postMappedLedgerGroup)
                    {
                        accountingDBContext.VoucherLedgerGroupMaps.Add(itm);
                    }
                    accountingDBContext.SaveChanges();
                    responseData.Status = "OK";
                }
                else if (reqType == "AddFiscalYear")
                {
                    FiscalYearModel fsModel = DanpheJSONConvert.DeserializeObject <FiscalYearModel>(str);

                    var checkFiscalYear = (from fs in accountingDBContext.FiscalYears
                                           where ((fs.FiscalYearName == fsModel.FiscalYearName) && (fs.IsActive == true))
                                           select fs).FirstOrDefault();
                    if (checkFiscalYear != null)
                    {
                        fsModel = null;
                        responseData.Results = fsModel;
                    }
                    else
                    {
                        fsModel.CreatedOn = System.DateTime.Now;
                        fsModel.CreatedBy = currentUser.UserId;
                        accountingDBContext.FiscalYears.Add(fsModel);
                        accountingDBContext.SaveChanges();

                        var fiscalCurtData = (from fisCal in accountingDBContext.FiscalYears
                                              where fisCal.FiscalYearId == fsModel.FiscalYearId
                                              select new
                        {
                            FiscalYearId = fisCal.FiscalYearId,
                            FiscalYearName = fisCal.FiscalYearName,
                            StartYear = fisCal.StartDate,
                            EndYear = fisCal.EndDate,
                            Description = fisCal.Description,
                            IsActive = fisCal.IsActive,
                        });
                        responseData.Results = fiscalCurtData;
                    }
                    responseData.Status = "OK";
                }
                else if (reqType == "AddCostCenterItem")
                {
                    CostCenterItemModel costCenterMod = DanpheJSONConvert.DeserializeObject <CostCenterItemModel>(str);
                    costCenterMod.CreatedOn = System.DateTime.Now;
                    costCenterMod.CreatedBy = currentUser.UserId;
                    accountingDBContext.CostCenterItems.Add(costCenterMod);
                    accountingDBContext.SaveChanges();

                    var curtCostCenterItmData = (from costCenterItm in accountingDBContext.CostCenterItems
                                                 where costCenterItm.CostCenterItemId == costCenterMod.CostCenterItemId
                                                 select new
                    {
                        CostCenterItemId = costCenterItm.CostCenterItemId,
                        CostCenterItemName = costCenterItm.CostCenterItemName,
                        Description = costCenterItm.Description,
                        IsActive = costCenterItm.IsActive,
                    });
                    responseData.Status  = "OK";
                    responseData.Results = curtCostCenterItmData;
                }
                else if (reqType == "AddLedgerGroupCategory")
                {
                    LedgerGroupCategoryModel ledGrpCatMod = DanpheJSONConvert.DeserializeObject <LedgerGroupCategoryModel>(str);
                    ledGrpCatMod.CreatedOn = System.DateTime.Now;
                    ledGrpCatMod.CreatedBy = currentUser.UserId;
                    accountingDBContext.LedgerGroupsCategory.Add(ledGrpCatMod);
                    accountingDBContext.SaveChanges();

                    var curtLedGrpCategoryData = (from ledgrpCat in accountingDBContext.LedgerGroupsCategory
                                                  join chartOfAcc in accountingDBContext.ChartOfAccounts on ledgrpCat.ChartOfAccountId equals chartOfAcc.ChartOfAccountId
                                                  where ledgrpCat.LedgerGroupCategoryId == ledGrpCatMod.LedgerGroupCategoryId
                                                  select new
                    {
                        LedgerGroupCategoryId = ledgrpCat.LedgerGroupCategoryId,
                        LedgerGroupCategoryName = ledgrpCat.LedgerGroupCategoryName,
                        ChartOfAccountName = chartOfAcc.ChartOfAccountName,
                        Description = ledgrpCat.Description,
                        IsActive = ledgrpCat.IsActive,
                        IsDebit = ledgrpCat.IsDebit,
                    });
                    responseData.Status  = "OK";
                    responseData.Results = curtLedGrpCategoryData;
                }
            }
            catch (Exception ex)
            {
                responseData.Status       = "Failed";
                responseData.ErrorMessage = ex.Message + " exception details:" + ex.ToString();
            }

            return(DanpheJSONConvert.SerializeObject(responseData, true));
        }
コード例 #12
0
 public void InsertToDb <T>(List <T> data) where T : class
 {
     db.Set <T>().AddRange(data);
     db.SaveChanges();
 }