public Int32 PostCollection() { try { var currentUser = from d in db.MstUsers where d.AspNetId == User.Identity.GetUserId() select d; if (currentUser.Any()) { string newCollectionNumber = "0000000001"; var lastCollection = from d in db.TrnCollections.OrderByDescending(d => d.Id) select d; if (lastCollection.Any()) { Int32 nextCollection = Convert.ToInt32(lastCollection.FirstOrDefault().CollectionNumber) + 1; newCollectionNumber = padNumWithZero(nextCollection, 10); } Int32 defaultCustomer = 0; var customer = from d in db.MstCustomers select d; if (customer.Any()) { defaultCustomer = customer.FirstOrDefault().Id; } Data.TrnCollection newCollection = new Data.TrnCollection() { CollectionNumber = newCollectionNumber, CollectionDate = DateTime.Today, ManualNumber = "NA", CustomerId = defaultCustomer, Particulars = "NA", PreparedBy = currentUser.FirstOrDefault().Id, CheckedBy = currentUser.FirstOrDefault().Id, ApprovedBy = currentUser.FirstOrDefault().Id, IsLocked = false, CreatedBy = currentUser.FirstOrDefault().Id, CreatedDateTime = DateTime.Today, UpdatedBy = currentUser.FirstOrDefault().Id, UpdatedDateTime = DateTime.Today }; db.TrnCollections.InsertOnSubmit(newCollection); db.SubmitChanges(); return(newCollection.Id); } else { return(0); } } catch (Exception e) { Debug.WriteLine(e); return(0); } }
private void Tender_OnClick(object sender, EventArgs e) { try { int salesId = currentSales.Id; decimal amountChange = 0, totalTenderAmount = 0; var salesCurrent = from d in db.TrnSales where d.Id.Equals(salesId) select d; var lastCollectionNumber = db.TrnCollections.OrderByDescending(d => d.Id).Select(d => d.CollectionNumber).First(); string collectionNumber = lastCollectionNumber.ToString(); string removeSubstring = "001-0001-"; string lastSN = collectionNumber.Replace(removeSubstring, ""); int salesnumber = Convert.ToInt32(lastSN) + 1; string defaultSINumber = FillLeadingZeroes(salesnumber, 6); string newCollectionNumber = salesCurrent.FirstOrDefault().MstTerminal.Terminal + "-" + salesCurrent.FirstOrDefault().MstPeriod.Period + "-" + defaultSINumber; totalTenderAmount = GetTenderTotalAmount(); amountChange = Convert.ToDecimal(totalTenderAmount) - salesCurrent.FirstOrDefault().Amount; Data.TrnCollection newCollection = new Data.TrnCollection { PeriodId = salesCurrent.FirstOrDefault().PeriodId, CollectionDate = DateTime.Now.Date, CollectionNumber = newCollectionNumber, TerminalId = salesCurrent.FirstOrDefault().TerminalId, ManualORNumber = newCollectionNumber, CustomerId = salesCurrent.FirstOrDefault().CustomerId, Remarks = salesCurrent.FirstOrDefault().Remarks, SalesId = salesCurrent.FirstOrDefault().Id, SalesBalanceAmount = salesCurrent.FirstOrDefault().Amount, Amount = salesCurrent.FirstOrDefault().Amount, TenderAmount = totalTenderAmount, ChangeAmount = amountChange, PreparedBy = salesCurrent.FirstOrDefault().PreparedBy, CheckedBy = salesCurrent.FirstOrDefault().PreparedBy, ApprovedBy = salesCurrent.FirstOrDefault().PreparedBy, IsCancelled = false, IsLocked = true, EntryUserId = salesCurrent.FirstOrDefault().PreparedBy, EntryDateTime = DateTime.Now.Date, UpdateUserId = salesCurrent.FirstOrDefault().PreparedBy, UpdateDateTime = DateTime.Now.Date, PostCode = null }; db.TrnCollections.InsertOnSubmit(newCollection); db.SubmitChanges(); InsertCollectionLines(newCollection.Id); LockSales(); posForm.AutoGenerateNewSalesAfterTender(); Close(); } catch (Exception ex) { Debug.Write(ex); } }
public long Save(POCO.TrnCollection t) { Data.TrnCollection result = new Data.TrnCollection(); var mappingProfile = new MappingProfileForTrnCollectionReverse(); using (var ctx = new posDataContext()) { if (t.Id != 0) { //TODO: Start collection view on Xamarin Project } else { var preORNumber = ctx.TrnCollections?.Where(x => x.CollectionNumber != "NA")?.Max(x => x.CollectionNumber) ?? "001-0001-000000"; var splitORNumber = preORNumber.Split('-'); var maxORNumber = long.Parse(splitORNumber[2]); var newORNumberLng = maxORNumber + 1000001; var newORNumber = $"001-0001-{newORNumberLng.ToString().Substring(1, 6)}"; t.PeriodId = 1; t.CollectionNumber = newORNumber; t.ManualORNumber = newORNumber; t.TerminalId = 1; t.PreparedBy = 1; t.CheckedBy = 1; t.ApprovedBy = 1; t.IsCancelled = false; t.IsLocked = true; t.EntryUserId = 1; t.EntryDateTime = DateTime.Now; t.UpdateUserId = 1; t.UpdateDateTime = DateTime.Now; result = mappingProfile.mapper.Map <Data.TrnCollection>(t); ctx.TrnCollections?.InsertOnSubmit(result); } ctx.SubmitChanges(); } return(result?.Id ?? 0); }
public Int32 insertCollection(Models.TrnCollection collection) { try { var userId = (from d in db.MstUsers where d.UserId == User.Identity.GetUserId() select d.Id).SingleOrDefault(); var lastORNumber = from d in db.TrnCollections.OrderByDescending(d => d.Id) where d.BranchId == currentBranchId() select d; var ORNumberResult = "0000000001"; if (lastORNumber.Any()) { var ORNumber = Convert.ToInt32(lastORNumber.FirstOrDefault().ORNumber) + 0000000001; ORNumberResult = zeroFill(ORNumber, 10); } Data.TrnCollection newCollection = new Data.TrnCollection(); newCollection.BranchId = currentBranchId(); newCollection.ORNumber = ORNumberResult; newCollection.ORDate = DateTime.Today; newCollection.CustomerId = (from d in db.MstArticles where d.ArticleTypeId == 2 select d.Id).FirstOrDefault(); newCollection.Particulars = "NA"; newCollection.ManualORNumber = "NA"; newCollection.PreparedById = userId; newCollection.CheckedById = userId; newCollection.ApprovedById = userId; newCollection.IsLocked = false; newCollection.CreatedById = userId; newCollection.CreatedDateTime = DateTime.Now; newCollection.UpdatedById = userId; newCollection.UpdatedDateTime = DateTime.Now; db.TrnCollections.InsertOnSubmit(newCollection); db.SubmitChanges(); return(newCollection.Id); } catch { return(0); } }
public Int32 postCollection() { try { Data.TrnCollection newCollection = new Data.TrnCollection(); newCollection.PeriodId = PeriodId(); newCollection.CollectionDate = DateTime.Today; newCollection.CollectionNumber = "n/a"; newCollection.TerminalId = TerminalId(); newCollection.ManualORNumber = "n/a"; newCollection.CustomerId = CustomerId(); newCollection.Remarks = "n/a"; newCollection.SalesId = 0; newCollection.SalesBalanceAmount = 0; newCollection.Amount = 0; newCollection.TenderAmount = 0; newCollection.ChangeAmount = 0; newCollection.PreparedBy = UserId(); newCollection.CheckedBy = UserId(); newCollection.ApprovedBy = UserId(); newCollection.IsCancelled = false; newCollection.IsLocked = false; newCollection.EntryUserId = UserId(); newCollection.EntryDateTime = DateTime.Today; newCollection.UpdateUserId = UserId(); newCollection.UpdateDateTime = DateTime.Today; db.TrnCollections.InsertOnSubmit(newCollection); db.SubmitChanges(); return(newCollection.Id); } catch (Exception e) { return(0); } }
public HttpResponseMessage AddFolderMonitoringCollection(List <Entities.FolderMonitoringTrnCollection> folderMonitoringTrnCollectionObjects) { try { if (folderMonitoringTrnCollectionObjects.Any()) { foreach (var folderMonitoringTrnCollectionObject in folderMonitoringTrnCollectionObjects) { Boolean isBranchExist = false, isCustomerExist = false, isUserExist = false, isAccountExist = false, isArticleExist = false, isSalesInvoiceExist = false, isPayTypeExist = false, isDepositoryBankExist = false; IQueryable <Data.TrnSalesInvoice> salesInvoice = null; var branch = from d in db.MstBranches where d.BranchCode.Equals(folderMonitoringTrnCollectionObject.BranchCode) select d; if (branch.Any()) { isBranchExist = true; if (!folderMonitoringTrnCollectionObject.SINumber.Equals("") || !folderMonitoringTrnCollectionObject.SINumber.Equals("NA")) { salesInvoice = from d in db.TrnSalesInvoices where d.BranchId == branch.FirstOrDefault().Id&& d.SINumber.Equals(folderMonitoringTrnCollectionObject.SINumber) && d.IsLocked == true select d; if (salesInvoice.Any()) { isSalesInvoiceExist = true; } } } var customer = from d in db.MstArticles where d.ArticleTypeId == 2 && d.ManualArticleCode.Equals(folderMonitoringTrnCollectionObject.CustomerCode) && d.IsLocked == true select d; if (customer.Any()) { isCustomerExist = true; } var user = from d in db.MstUsers where d.UserName.Equals(folderMonitoringTrnCollectionObject.UserCode) select d; if (user.Any()) { isUserExist = true; } List <easyfis.Entities.MstArticle> listArticles = new List <easyfis.Entities.MstArticle>(); var account = from d in db.MstAccounts where d.AccountCode.Equals(folderMonitoringTrnCollectionObject.AccountCode) select d; if (account.Any()) { isAccountExist = true; var accountArticleTypes = from d in db.MstAccountArticleTypes where d.AccountId == Convert.ToInt32(account.FirstOrDefault().Id) select d; if (accountArticleTypes.Any()) { foreach (var accountArticleType in accountArticleTypes) { var articles = from d in db.MstArticles where d.ArticleTypeId == accountArticleType.ArticleTypeId && d.IsLocked == true select d; if (articles.Any()) { foreach (var articleObject in articles) { listArticles.Add(new easyfis.Entities.MstArticle() { Id = articleObject.Id, ManualArticleCode = articleObject.ManualArticleCode, Article = articleObject.Article }); } } } } } var article = from d in listArticles where d.ManualArticleCode.Equals(folderMonitoringTrnCollectionObject.ArticleCode) select d; if (article.Any()) { isArticleExist = true; } var payType = from d in db.MstPayTypes where d.PayType.Equals(folderMonitoringTrnCollectionObject.PayType) select d; if (payType.Any()) { isPayTypeExist = true; } var depositoryBank = from d in db.MstArticles where d.ArticleTypeId == 5 && d.ManualArticleCode.Equals(folderMonitoringTrnCollectionObject.DepositoryBankCode) select d; if (depositoryBank.Any()) { isDepositoryBankExist = true; } if (isBranchExist && isCustomerExist && isUserExist && isAccountExist && isArticleExist && isPayTypeExist && isDepositoryBankExist) { Int32 ORId = 0; var currentCollection = from d in db.TrnCollections where d.BranchId == branch.FirstOrDefault().Id&& d.ManualORNumber.Equals(folderMonitoringTrnCollectionObject.ManualORNumber) && d.IsLocked == true select d; if (currentCollection.Any()) { ORId = currentCollection.FirstOrDefault().Id; var unlockCollection = currentCollection.FirstOrDefault(); unlockCollection.IsLocked = false; unlockCollection.UpdatedById = user.FirstOrDefault().Id; unlockCollection.UpdatedDateTime = Convert.ToDateTime(folderMonitoringTrnCollectionObject.CreatedDateTime); db.SubmitChanges(); journal.DeleteOfficialReceiptJournal(ORId); } else { var defaultORNumber = "0000000001"; var lastCollection = from d in db.TrnCollections.OrderByDescending(d => d.Id) where d.BranchId == branch.FirstOrDefault().Id select d; if (lastCollection.Any()) { var ORNumber = Convert.ToInt32(lastCollection.FirstOrDefault().ORNumber) + 0000000001; defaultORNumber = FillLeadingZeroes(ORNumber, 10); } Data.TrnCollection newCollection = new Data.TrnCollection { BranchId = branch.FirstOrDefault().Id, ORNumber = defaultORNumber, ORDate = Convert.ToDateTime(folderMonitoringTrnCollectionObject.ORDate), ManualORNumber = folderMonitoringTrnCollectionObject.ManualORNumber, CustomerId = customer.FirstOrDefault().Id, Particulars = folderMonitoringTrnCollectionObject.Remarks, PreparedById = user.FirstOrDefault().Id, CheckedById = user.FirstOrDefault().Id, ApprovedById = user.FirstOrDefault().Id, Status = null, IsCancelled = false, IsPrinted = false, IsLocked = false, CreatedById = user.FirstOrDefault().Id, CreatedDateTime = Convert.ToDateTime(folderMonitoringTrnCollectionObject.CreatedDateTime), UpdatedById = user.FirstOrDefault().Id, UpdatedDateTime = Convert.ToDateTime(folderMonitoringTrnCollectionObject.CreatedDateTime) }; db.TrnCollections.InsertOnSubmit(newCollection); db.SubmitChanges(); ORId = newCollection.Id; } Int32?SIId = null; if (isSalesInvoiceExist) { SIId = salesInvoice.FirstOrDefault().Id; } Data.TrnCollectionLine newCollectionLine = new Data.TrnCollectionLine { ORId = ORId, BranchId = branch.FirstOrDefault().Id, AccountId = account.FirstOrDefault().Id, ArticleId = article.FirstOrDefault().Id, SIId = SIId, Particulars = folderMonitoringTrnCollectionObject.Particulars, Amount = folderMonitoringTrnCollectionObject.Amount, PayTypeId = payType.FirstOrDefault().Id, CheckNumber = folderMonitoringTrnCollectionObject.CheckNumber, CheckDate = Convert.ToDateTime(folderMonitoringTrnCollectionObject.CheckDate), CheckBank = folderMonitoringTrnCollectionObject.CheckBank, DepositoryBankId = depositoryBank.FirstOrDefault().Id, IsClear = folderMonitoringTrnCollectionObject.IsClear }; db.TrnCollectionLines.InsertOnSubmit(newCollectionLine); db.SubmitChanges(); var collection = from d in db.TrnCollections where d.Id == ORId && d.IsLocked == false select d; if (collection.Any()) { var lockCollection = collection.FirstOrDefault(); lockCollection.IsLocked = true; lockCollection.UpdatedById = user.FirstOrDefault().Id; lockCollection.UpdatedDateTime = Convert.ToDateTime(folderMonitoringTrnCollectionObject.CreatedDateTime); db.SubmitChanges(); var collectionLines = from d in lockCollection.TrnCollectionLines where d.SIId != null select d; if (collectionLines.Any()) { foreach (var collectionLine in collectionLines) { accountsReceivable.UpdateAccountsReceivable(Convert.ToInt32(collectionLine.SIId)); } } journal.InsertOfficialReceiptJournal(ORId); } } } return(Request.CreateResponse(HttpStatusCode.OK)); } else { return(Request.CreateResponse(HttpStatusCode.NotFound, "No data found.")); } } catch (Exception ex) { Debug.WriteLine(ex); return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Something's went wrong from the server.")); } }
public HttpResponseMessage AddCollection() { try { var currentUser = from d in db.MstUsers where d.UserId == User.Identity.GetUserId() select d; if (currentUser.Any()) { var currentUserId = currentUser.FirstOrDefault().Id; var currentBranchId = currentUser.FirstOrDefault().BranchId; var userForms = from d in db.MstUserForms where d.UserId == currentUserId && d.SysForm.FormName.Equals("CollectionList") select d; if (userForms.Any()) { if (userForms.FirstOrDefault().CanAdd) { var defaultORNumber = "0000000001"; var lastCollection = from d in db.TrnCollections.OrderByDescending(d => d.Id) where d.BranchId == currentBranchId select d; if (lastCollection.Any()) { var ORNumber = Convert.ToInt32(lastCollection.FirstOrDefault().ORNumber) + 0000000001; defaultORNumber = FillLeadingZeroes(ORNumber, 10); } var customers = from d in db.MstArticles.OrderBy(d => d.Article) where d.ArticleTypeId == 2 && d.IsLocked == true select d; if (customers.Any()) { var users = from d in db.MstUsers.OrderBy(d => d.FullName) where d.IsLocked == true select d; if (users.Any()) { Data.TrnCollection newCollection = new Data.TrnCollection { BranchId = currentBranchId, ORNumber = defaultORNumber, ORDate = DateTime.Today, ManualORNumber = "NA", CustomerId = customers.FirstOrDefault().Id, Particulars = "NA", PreparedById = currentUserId, CheckedById = currentUserId, ApprovedById = currentUserId, IsLocked = false, CreatedById = currentUserId, CreatedDateTime = DateTime.Now, UpdatedById = currentUserId, UpdatedDateTime = DateTime.Now }; db.TrnCollections.InsertOnSubmit(newCollection); db.SubmitChanges(); return(Request.CreateResponse(HttpStatusCode.OK, newCollection.Id)); } else { return(Request.CreateResponse(HttpStatusCode.NotFound, "No user found. Please setup more users for all transactions.")); } } else { return(Request.CreateResponse(HttpStatusCode.NotFound, "No customer found. Please setup more customers for all transactions.")); } } else { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Sorry. You have no rights to add collection.")); } } else { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Sorry. You have no access for this collection page.")); } } else { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Theres no current user logged in.")); } } catch (Exception e) { Debug.WriteLine(e); return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Something's went wrong from the server.")); } }
public List <Entities.ReturnedDocument> QuintaIntegrationAddSalesInvoice(Entities.RootObject objRoot) { try { List <Entities.ReturnedDocument> listSINumber = new List <Entities.ReturnedDocument>(); var branch = from d in db.MstBranches select d; if (branch.Any()) { Int32 currentBranchId = branch.FirstOrDefault().Id; if (objRoot.TRN.Any()) { foreach (var objSales in objRoot.TRN) { if (objSales != null) { Boolean unitExist = false; var units = from d in db.MstUnits select d; if (units.Any()) { unitExist = true; } Boolean termExist = false; var terms = from d in db.MstTerms where d.Term.Equals(objRoot.DefaultTerm) select d; if (terms.Any()) { termExist = true; } Boolean userExist = false; var users = from d in db.MstUsers where d.UserName.Equals("admin") select d; if (users.Any()) { userExist = true; } Int32 customerId = 0; var customers = from d in db.MstArticles where d.ManualArticleCode.Equals(objSales.ACI) && d.ArticleTypeId == 2 select d; if (customers.Any()) { customerId = customers.FirstOrDefault().Id; } else { var defaultCustomerCode = "0000000001"; var lastCustomer = from d in db.MstArticles.OrderByDescending(d => d.Id) where d.ArticleTypeId == 2 select d; if (lastCustomer.Any()) { var customerCode = Convert.ToInt32(lastCustomer.FirstOrDefault().ArticleCode) + 0000000001; defaultCustomerCode = ZeroFill(customerCode, 10); } var articleGroups = from d in db.MstArticleGroups where d.ArticleTypeId == 2 select d; if (articleGroups.Any()) { Data.MstArticle newCustomer = new Data.MstArticle { ArticleCode = defaultCustomerCode, ManualArticleCode = objSales.ACI, Article = objSales.ACC, Category = "NA", ArticleTypeId = 2, ArticleGroupId = articleGroups.FirstOrDefault().Id, AccountId = articleGroups.FirstOrDefault().AccountId, SalesAccountId = articleGroups.FirstOrDefault().SalesAccountId, CostAccountId = articleGroups.FirstOrDefault().CostAccountId, AssetAccountId = articleGroups.FirstOrDefault().AssetAccountId, ExpenseAccountId = articleGroups.FirstOrDefault().ExpenseAccountId, UnitId = units.FirstOrDefault().Id, OutputTaxId = db.MstTaxTypes.FirstOrDefault().Id, InputTaxId = db.MstTaxTypes.FirstOrDefault().Id, WTaxTypeId = db.MstTaxTypes.FirstOrDefault().Id, Price = 0, Cost = 0, IsInventory = false, IsConsignment = false, ConsignmentCostPercentage = 0, ConsignmentCostValue = 0, Particulars = "NA", Address = "NA", TermId = terms.FirstOrDefault().Id, ContactNumber = "NA", ContactPerson = "NA", EmailAddress = "NA", TaxNumber = "NA", CreditLimit = 0, DateAcquired = DateTime.Now, UsefulLife = 0, SalvageValue = 0, ManualArticleOldCode = "NA", Kitting = 0, DefaultSupplierId = null, StockLevelQuantity = 0, ReorderQuantity = 0, IsLocked = true, CreatedById = users.FirstOrDefault().Id, CreatedDateTime = DateTime.Now, UpdatedById = users.FirstOrDefault().Id, UpdatedDateTime = DateTime.Now }; db.MstArticles.InsertOnSubmit(newCustomer); db.SubmitChanges(); customerId = newCustomer.Id; } } Boolean taxTypeExist = false; var taxTypes = from d in db.MstTaxTypes select d; if (taxTypes.Any()) { taxTypeExist = true; } Boolean discountExist = false; var discounts = from d in db.MstDiscounts where d.Discount.Equals(objRoot.DefaultDiscount) select d; if (discounts.Any()) { discountExist = true; } if (userExist) { if (termExist) { if (customerId != 0) { Int32 salesInvoiceId = 0; var SINumberResult = "0000000001"; var lastSalesInvoice = from d in db.TrnSalesInvoices.OrderByDescending(d => d.Id) where d.BranchId == currentBranchId select d; if (lastSalesInvoice.Any()) { var SINumber = Convert.ToInt32(lastSalesInvoice.FirstOrDefault().SINumber) + 0000000001; SINumberResult = ZeroFill(SINumber, 10); } Data.TrnSalesInvoice addSalesInvoice = new Data.TrnSalesInvoice { BranchId = currentBranchId, SINumber = SINumberResult, SIDate = Convert.ToDateTime(objSales.TDT), CustomerId = customerId, TermId = terms.FirstOrDefault().Id, DocumentReference = objSales.FTN, ManualSINumber = objSales.FTN, Remarks = "NA", Amount = objSales.NAM, PaidAmount = 0, AdjustmentAmount = 0, BalanceAmount = objSales.NAM, SoldById = users.FirstOrDefault().Id, PreparedById = users.FirstOrDefault().Id, CheckedById = users.FirstOrDefault().Id, ApprovedById = users.FirstOrDefault().Id, IsLocked = true, CreatedById = users.FirstOrDefault().Id, CreatedDateTime = DateTime.Now, UpdatedById = users.FirstOrDefault().Id, UpdatedDateTime = DateTime.Now }; db.TrnSalesInvoices.InsertOnSubmit(addSalesInvoice); db.SubmitChanges(); salesInvoiceId = addSalesInvoice.Id; listSINumber.Add(new Entities.ReturnedDocument() { SINumber = addSalesInvoice.SINumber, ManualSINumber = addSalesInvoice.ManualSINumber }); if (salesInvoiceId != 0) { Int32 itemId = 0; var items = from d in db.MstArticles where d.ManualArticleCode.Equals(objSales.SAI) && d.ArticleTypeId == 1 select d; if (items.Any()) { itemId = items.FirstOrDefault().Id; } else { var defaultItemCode = "0000000001"; var lastItem = from d in db.MstArticles.OrderByDescending(d => d.Id) where d.ArticleTypeId == 1 select d; if (lastItem.Any()) { var itemCode = Convert.ToInt32(lastItem.FirstOrDefault().ArticleCode) + 0000000001; defaultItemCode = ZeroFill(itemCode, 10); } var articleGroups = from d in db.MstArticleGroups where d.ArticleTypeId == 1 select d; if (articleGroups.Any()) { Data.MstArticle newItem = new Data.MstArticle { ArticleCode = defaultItemCode, ManualArticleCode = objSales.SAI, Article = objSales.SAM, Category = "NA", ArticleTypeId = 1, ArticleGroupId = articleGroups.FirstOrDefault().Id, AccountId = articleGroups.FirstOrDefault().AccountId, SalesAccountId = articleGroups.FirstOrDefault().SalesAccountId, CostAccountId = articleGroups.FirstOrDefault().CostAccountId, AssetAccountId = articleGroups.FirstOrDefault().AssetAccountId, ExpenseAccountId = articleGroups.FirstOrDefault().ExpenseAccountId, UnitId = units.FirstOrDefault().Id, OutputTaxId = taxTypes.Where(d => d.TaxType.Equals(objRoot.DefaultVatOutput)).FirstOrDefault().Id, InputTaxId = taxTypes.Where(d => d.TaxType.Equals(objRoot.DefaultVatInput)).FirstOrDefault().Id, WTaxTypeId = taxTypes.Where(d => d.TaxType.Equals(objRoot.DefaultWTax)).FirstOrDefault().Id, Price = objSales.NAM, Cost = 0, IsInventory = false, IsConsignment = false, ConsignmentCostPercentage = 0, ConsignmentCostValue = 0, Particulars = "NA", Address = "NA", TermId = terms.FirstOrDefault().Id, ContactNumber = "NA", ContactPerson = "NA", EmailAddress = "NA", TaxNumber = "NA", CreditLimit = 0, DateAcquired = DateTime.Now, UsefulLife = 0, SalvageValue = 0, ManualArticleOldCode = "NA", Kitting = 0, DefaultSupplierId = null, StockLevelQuantity = 0, ReorderQuantity = 0, IsLocked = true, CreatedById = users.FirstOrDefault().Id, CreatedDateTime = DateTime.Now, UpdatedById = users.FirstOrDefault().Id, UpdatedDateTime = DateTime.Now }; db.MstArticles.InsertOnSubmit(newItem); db.SubmitChanges(); itemId = newItem.Id; Data.MstArticleUnit newItemUnitConversion = new Data.MstArticleUnit { ArticleId = Convert.ToInt32(itemId), UnitId = units.FirstOrDefault().Id, Multiplier = 1, IsCountUnit = false }; db.MstArticleUnits.InsertOnSubmit(newItemUnitConversion); db.SubmitChanges(); Data.MstArticlePrice newItemPrice = new Data.MstArticlePrice { ArticleId = Convert.ToInt32(itemId), PriceDescription = "SRP", Price = objSales.NAM, Remarks = "NA" }; db.MstArticlePrices.InsertOnSubmit(newItemPrice); db.SubmitChanges(); } } if (itemId != 0) { if (unitExist) { if (taxTypeExist) { if (discountExist) { Int32?itemInventoryId = null; var articleInventory = from d in db.MstArticleInventories where d.BranchId == currentBranchId && d.ArticleId == itemId select d; if (articleInventory.Any()) { itemInventoryId = articleInventory.FirstOrDefault().Id; } var conversionUnit = from d in db.MstArticleUnits where d.ArticleId == itemId && d.UnitId == items.FirstOrDefault().UnitId select d; if (conversionUnit.Any()) { Decimal baseQuantity = 1; Decimal basePrice = objSales.NAM; if (conversionUnit.FirstOrDefault().Multiplier > 0) { baseQuantity = 1 * (1 / conversionUnit.FirstOrDefault().Multiplier); } if (baseQuantity > 0) { basePrice = objSales.NAM / baseQuantity; } Data.TrnSalesInvoiceItem newSalesInvoiceItem = new Data.TrnSalesInvoiceItem { SIId = salesInvoiceId, ItemId = itemId, ItemInventoryId = itemInventoryId, Particulars = "NA", UnitId = units.FirstOrDefault().Id, Quantity = 1, Price = objSales.NAM, DiscountId = discounts.FirstOrDefault().Id, DiscountRate = discounts.FirstOrDefault().DiscountRate, DiscountAmount = 0, NetPrice = objSales.NAM, Amount = objSales.NAM, VATId = items.FirstOrDefault().OutputTaxId, VATPercentage = items.FirstOrDefault().MstTaxType.TaxRate, VATAmount = (objSales.NAM / (1 + (items.FirstOrDefault().MstTaxType.TaxRate / 100))) * (items.FirstOrDefault().MstTaxType.TaxRate / 100), BaseUnitId = items.FirstOrDefault().UnitId, BaseQuantity = baseQuantity, BasePrice = basePrice, SalesItemTimeStamp = DateTime.Now }; db.TrnSalesInvoiceItems.InsertOnSubmit(newSalesInvoiceItem); db.SubmitChanges(); } } } } } var currentSalesInvoice = from d in db.TrnSalesInvoices where d.Id == salesInvoiceId select d; if (currentSalesInvoice.Any()) { Decimal salesAmount = 0; Decimal paidAmount = currentSalesInvoice.FirstOrDefault().PaidAmount; Decimal adjustmentAmount = currentSalesInvoice.FirstOrDefault().AdjustmentAmount; var salesInvoiceItems = from d in db.TrnSalesInvoiceItems where d.SIId == salesInvoiceId select d; if (salesInvoiceItems.Any()) { salesAmount = salesInvoiceItems.Sum(d => d.Amount); } var updateSalesInvoiceAmount = currentSalesInvoice.FirstOrDefault(); updateSalesInvoiceAmount.Amount = salesAmount; updateSalesInvoiceAmount.BalanceAmount = (salesAmount - paidAmount) + adjustmentAmount; db.SubmitChanges(); } inventory.InsertSalesInvoiceInventory(Convert.ToInt32(salesInvoiceId)); journal.InsertSalesInvoiceJournal(Convert.ToInt32(salesInvoiceId)); if (currentSalesInvoice.Any()) { var defaultORNumber = "0000000001"; var lastCollection = from d in db.TrnCollections.OrderByDescending(d => d.Id) where d.BranchId == currentBranchId select d; if (lastCollection.Any()) { var ORNumber = Convert.ToInt32(lastCollection.FirstOrDefault().ORNumber) + 0000000001; defaultORNumber = ZeroFill(ORNumber, 10); } Data.TrnCollection newCollection = new Data.TrnCollection { BranchId = currentBranchId, ORNumber = defaultORNumber, ORDate = Convert.ToDateTime(objSales.ADT), ManualORNumber = "NA", CustomerId = customers.FirstOrDefault().Id, Particulars = "NA", PreparedById = users.FirstOrDefault().Id, CheckedById = users.FirstOrDefault().Id, ApprovedById = users.FirstOrDefault().Id, IsLocked = true, CreatedById = users.FirstOrDefault().Id, CreatedDateTime = DateTime.Now, UpdatedById = users.FirstOrDefault().Id, UpdatedDateTime = DateTime.Now }; db.TrnCollections.InsertOnSubmit(newCollection); db.SubmitChanges(); Boolean payTypeExist = false; var payTypes = from d in db.MstPayTypes select d; if (payTypes.Any()) { payTypeExist = true; } Boolean bankExist = false; var banks = from d in db.MstArticles where d.ArticleTypeId == 5 select d; if (banks.Any()) { bankExist = true; } if (payTypeExist) { if (bankExist) { Data.TrnCollectionLine newCollectionLine = new Data.TrnCollectionLine { ORId = newCollection.Id, BranchId = currentBranchId, AccountId = currentSalesInvoice.FirstOrDefault().MstArticle.AccountId, ArticleId = currentSalesInvoice.FirstOrDefault().CustomerId, SIId = currentSalesInvoice.FirstOrDefault().Id, Particulars = currentSalesInvoice.FirstOrDefault().Remarks, Amount = objSales.NAM, PayTypeId = payTypes.FirstOrDefault().Id, CheckNumber = "NA", CheckDate = DateTime.Today, CheckBank = "NA", DepositoryBankId = banks.FirstOrDefault().Id, IsClear = true }; db.TrnCollectionLines.InsertOnSubmit(newCollectionLine); db.SubmitChanges(); journal.InsertOfficialReceiptJournal(Convert.ToInt32(newCollection.Id)); accountsReceivable.UpdateAccountsReceivable(currentSalesInvoice.FirstOrDefault().Id); } } } } } } } } } } return(listSINumber.ToList()); } else { return(new List <Entities.ReturnedDocument>()); } } catch (Exception e) { Debug.WriteLine(e); return(new List <Entities.ReturnedDocument>()); } }
public Int32 insertCollection(Models.TrnCollection collection) { try { var userId = (from d in db.MstUsers where d.UserId == User.Identity.GetUserId() select d.Id).SingleOrDefault(); var lastORNumber = from d in db.TrnCollections.OrderByDescending(d => d.Id) select d; var ORNumberResult = "0000000001"; if (lastORNumber.Any()) { var ORNumber = Convert.ToInt32(lastORNumber.FirstOrDefault().ORNumber) + 0000000001; ORNumberResult = zeroFill(ORNumber, 10); } Data.TrnCollection newCollection = new Data.TrnCollection(); newCollection.BranchId = currentBranchId(); newCollection.ORNumber = ORNumberResult; newCollection.ORDate = DateTime.Today; newCollection.CustomerId = (from d in db.MstArticles where d.ArticleTypeId == 2 select d.Id).FirstOrDefault(); newCollection.Particulars = "NA"; newCollection.ManualORNumber = "NA"; newCollection.PreparedById = userId; newCollection.CheckedById = userId; newCollection.ApprovedById = userId; newCollection.IsLocked = false; newCollection.CreatedById = userId; newCollection.CreatedDateTime = DateTime.Now; newCollection.UpdatedById = userId; newCollection.UpdatedDateTime = DateTime.Now; db.TrnCollections.InsertOnSubmit(newCollection); db.SubmitChanges(); return newCollection.Id; } catch { return 0; } }
public int Post(Models.TrnCollection collection) { try { var isLocked = true; var identityUserId = User.Identity.GetUserId(); var mstUserId = (from d in db.MstUsers where "" + d.Id == identityUserId select d.Id).SingleOrDefault(); var date = DateTime.Now; Data.TrnCollection newCollection = new Data.TrnCollection(); // newCollection.PeriodId = collection.PeriodId; newCollection.CollectionDate = Convert.ToDateTime(collection.CollectionDate); newCollection.CollectionNumber = collection.CollectionNumber; newCollection.TerminalId = collection.TerminalId; newCollection.ManualORNumber = collection.ManualORNumber; newCollection.CustomerId = collection.CustomerId; newCollection.Remarks = collection.Remarks; newCollection.SalesId = collection.SalesId; newCollection.SalesBalanceAmount = collection.SalesBalanceAmount; newCollection.Amount = collection.Amount; newCollection.TenderAmount = collection.TenderAmount; newCollection.ChangeAmount = collection.ChangeAmount; newCollection.PreparedBy = collection.PreparedBy; newCollection.CheckedBy = collection.CheckedBy; newCollection.ApprovedBy = collection.ApprovedBy; newCollection.IsCancelled = collection.IsCancelled; newCollection.IsLocked = isLocked; newCollection.EntryUserId = mstUserId; newCollection.EntryDateTime = date; newCollection.UpdateUserId = mstUserId; newCollection.UpdateDateTime = date; // db.TrnCollections.InsertOnSubmit(newCollection); db.SubmitChanges(); return newCollection.Id; } catch { return 0; } }
public HttpResponseMessage AddFolderMonitoringCollection(List <Entities.FolderMonitoringTrnCollection> folderMonitoringTrnCollectionObjects) { try { if (folderMonitoringTrnCollectionObjects.Any()) { String returnMessage = ""; List <Entities.FolderMonitoringTrnCollectionHeader> newFolderMonitoringTrnCollectionHeaders = new List <Entities.FolderMonitoringTrnCollectionHeader>(); List <Entities.FolderMonitoringTrnCollectionLine> newFolderMonitoringTrnCollectionLines = new List <Entities.FolderMonitoringTrnCollectionLine>(); Boolean isDataValid = false; foreach (var folderMonitoringTrnCollectionObject in folderMonitoringTrnCollectionObjects) { Boolean isBranchExist = false, isCustomerExist = false, isUserExist = false, isAccountExist = false, isArticleExist = false, isLineBranchExist = false, isPayTypeExist = false, isDepositoryBankExist = false; var branch = from d in db.MstBranches where d.BranchCode.Equals(folderMonitoringTrnCollectionObject.BranchCode) select d; if (branch.Any()) { isBranchExist = true; } var customer = from d in db.MstArticles where d.ArticleTypeId == 2 && d.ManualArticleCode.Equals(folderMonitoringTrnCollectionObject.CustomerCode) && d.IsLocked == true select d; if (customer.Any()) { isCustomerExist = true; } var user = from d in db.MstUsers where d.UserName.Equals(folderMonitoringTrnCollectionObject.UserCode) select d; if (user.Any()) { isUserExist = true; } var lineBranch = from d in db.MstBranches where d.BranchCode.Equals(folderMonitoringTrnCollectionObject.LineBranchCode) select d; if (lineBranch.Any()) { isLineBranchExist = true; } List <easyfis.Entities.MstArticle> listArticles = new List <easyfis.Entities.MstArticle>(); var account = from d in db.MstAccounts where d.AccountCode.Equals(folderMonitoringTrnCollectionObject.AccountCode) select d; if (account.Any()) { isAccountExist = true; var accountArticleTypes = from d in db.MstAccountArticleTypes where d.AccountId == Convert.ToInt32(account.FirstOrDefault().Id) group d by d.ArticleTypeId into g select g; if (accountArticleTypes.Any()) { foreach (var accountArticleType in accountArticleTypes) { var articles = from d in db.MstArticles where d.ArticleTypeId == accountArticleType.Key && d.IsLocked == true select d; if (articles.Any()) { foreach (var articleObject in articles) { listArticles.Add(new easyfis.Entities.MstArticle() { Id = articleObject.Id, ManualArticleCode = articleObject.ManualArticleCode, Article = articleObject.Article }); } } } } } var article = from d in listArticles where d.ManualArticleCode.Equals(folderMonitoringTrnCollectionObject.ArticleCode) select d; if (article.Any()) { isArticleExist = true; } var payType = from d in db.MstPayTypes where d.PayType.Equals(folderMonitoringTrnCollectionObject.PayType) select d; if (payType.Any()) { isPayTypeExist = true; } var depositoryBank = from d in db.MstArticles where d.ArticleTypeId == 5 && d.ManualArticleCode.Equals(folderMonitoringTrnCollectionObject.DepositoryBankCode) select d; if (depositoryBank.Any()) { isDepositoryBankExist = true; } if (!isBranchExist) { returnMessage = "Invalid Branch Code: " + folderMonitoringTrnCollectionObject.BranchCode; isDataValid = false; break; } else if (!isCustomerExist) { returnMessage = "Invalid Customer Code: " + folderMonitoringTrnCollectionObject.CustomerCode; isDataValid = false; break; } else if (!isUserExist) { returnMessage = "Invalid User Code: " + folderMonitoringTrnCollectionObject.UserCode; isDataValid = false; break; } else if (!isLineBranchExist) { returnMessage = "Invalid Line Branch Code: " + folderMonitoringTrnCollectionObject.LineBranchCode; isDataValid = false; break; } else if (!isAccountExist) { returnMessage = "Invalid Account Code: " + folderMonitoringTrnCollectionObject.AccountCode; isDataValid = false; break; } else if (!isArticleExist) { returnMessage = "Invalid Article Code: " + folderMonitoringTrnCollectionObject.ArticleCode; isDataValid = false; break; } else if (!isPayTypeExist) { returnMessage = "Invalid Pay Type: " + folderMonitoringTrnCollectionObject.PayType; isDataValid = false; break; } else if (!isDepositoryBankExist) { returnMessage = "Invalid Depository Bank Code: " + folderMonitoringTrnCollectionObject.DepositoryBankCode; isDataValid = false; break; } else { var collection = from d in db.TrnCollections where d.BranchId == branch.FirstOrDefault().Id && d.ManualORNumber.Equals(folderMonitoringTrnCollectionObject.ManualORNumber) && d.IsLocked == true select d; if (collection.Any()) { returnMessage = "This Manual OR No. " + folderMonitoringTrnCollectionObject.ManualORNumber + " is already exist!"; isDataValid = false; break; } else { Int32?SIId = null; if (!folderMonitoringTrnCollectionObject.ManualSINumber.Equals("") || !folderMonitoringTrnCollectionObject.ManualSINumber.Equals("NA")) { var salesInvoice = from d in db.TrnSalesInvoices where d.BranchId == branch.FirstOrDefault().Id && d.ManualSINumber.Equals(folderMonitoringTrnCollectionObject.ManualSINumber) && d.IsLocked == true select d; if (salesInvoice.Any()) { SIId = salesInvoice.FirstOrDefault().Id; } } var folderMonitoringTrnCollectionHeader = from d in newFolderMonitoringTrnCollectionHeaders where d.BranchId == branch.FirstOrDefault().Id && d.ManualORNumber.Equals(folderMonitoringTrnCollectionObject.ManualORNumber) select d; if (folderMonitoringTrnCollectionHeader.Any()) { var currentFolderMonitoringTrnCollectionHeader = folderMonitoringTrnCollectionHeader.FirstOrDefault(); currentFolderMonitoringTrnCollectionHeader.ListFolderMonitoringTrnCollectionLines.Add(new Entities.FolderMonitoringTrnCollectionLine() { ManualORNumber = folderMonitoringTrnCollectionObject.ManualORNumber, BranchId = lineBranch.FirstOrDefault().Id, AccountId = account.FirstOrDefault().Id, ArticleId = article.FirstOrDefault().Id, SIId = SIId, Particulars = folderMonitoringTrnCollectionObject.Particulars, Amount = folderMonitoringTrnCollectionObject.Amount, PayTypeId = payType.FirstOrDefault().Id, CheckNumber = folderMonitoringTrnCollectionObject.CheckNumber, CheckDate = Convert.ToDateTime(folderMonitoringTrnCollectionObject.CheckDate), CheckBank = folderMonitoringTrnCollectionObject.CheckBank, IsClear = folderMonitoringTrnCollectionObject.IsClear }); } else { newFolderMonitoringTrnCollectionLines = new List <Entities.FolderMonitoringTrnCollectionLine> { new Entities.FolderMonitoringTrnCollectionLine() { ManualORNumber = folderMonitoringTrnCollectionObject.ManualORNumber, BranchId = lineBranch.FirstOrDefault().Id, AccountId = account.FirstOrDefault().Id, ArticleId = article.FirstOrDefault().Id, SIId = SIId, Particulars = folderMonitoringTrnCollectionObject.Particulars, Amount = folderMonitoringTrnCollectionObject.Amount, PayTypeId = payType.FirstOrDefault().Id, CheckNumber = folderMonitoringTrnCollectionObject.CheckNumber, CheckDate = Convert.ToDateTime(folderMonitoringTrnCollectionObject.CheckDate), CheckBank = folderMonitoringTrnCollectionObject.CheckBank, IsClear = folderMonitoringTrnCollectionObject.IsClear } }; if (newFolderMonitoringTrnCollectionLines.Any()) { newFolderMonitoringTrnCollectionHeaders.Add(new Entities.FolderMonitoringTrnCollectionHeader() { BranchId = branch.FirstOrDefault().Id, ORNumber = "0000000000", ORDate = Convert.ToDateTime(folderMonitoringTrnCollectionObject.ORDate), CustomerId = customer.FirstOrDefault().Id, Particulars = folderMonitoringTrnCollectionObject.Remarks, ManualORNumber = folderMonitoringTrnCollectionObject.ManualORNumber, PreparedById = user.FirstOrDefault().Id, CheckedById = user.FirstOrDefault().Id, ApprovedById = user.FirstOrDefault().Id, Status = null, IsCancelled = false, IsPrinted = false, IsLocked = false, CreatedById = user.FirstOrDefault().Id, CreatedDateTime = Convert.ToDateTime(folderMonitoringTrnCollectionObject.CreatedDateTime), UpdatedById = user.FirstOrDefault().Id, UpdatedDateTime = Convert.ToDateTime(folderMonitoringTrnCollectionObject.CreatedDateTime), ListFolderMonitoringTrnCollectionLines = newFolderMonitoringTrnCollectionLines }); } } isDataValid = true; } } } if (isDataValid) { if (newFolderMonitoringTrnCollectionHeaders.Any()) { foreach (var newFolderMonitoringTrnCollectionHeader in newFolderMonitoringTrnCollectionHeaders) { Int32 ORId = 0; var defaultORNumber = "0000000001"; var lastCollection = from d in db.TrnCollections.OrderByDescending(d => d.Id) where d.BranchId == newFolderMonitoringTrnCollectionHeader.BranchId select d; if (lastCollection.Any()) { var ORNumber = Convert.ToInt32(lastCollection.FirstOrDefault().ORNumber) + 0000000001; defaultORNumber = FillLeadingZeroes(ORNumber, 10); } Data.TrnCollection newCollection = new Data.TrnCollection { BranchId = newFolderMonitoringTrnCollectionHeader.BranchId, ORNumber = defaultORNumber, ORDate = newFolderMonitoringTrnCollectionHeader.ORDate, ManualORNumber = newFolderMonitoringTrnCollectionHeader.ManualORNumber, CustomerId = newFolderMonitoringTrnCollectionHeader.CustomerId, Particulars = newFolderMonitoringTrnCollectionHeader.Particulars, PreparedById = newFolderMonitoringTrnCollectionHeader.PreparedById, CheckedById = newFolderMonitoringTrnCollectionHeader.CheckedById, ApprovedById = newFolderMonitoringTrnCollectionHeader.ApprovedById, Status = newFolderMonitoringTrnCollectionHeader.Status, IsCancelled = newFolderMonitoringTrnCollectionHeader.IsCancelled, IsPrinted = newFolderMonitoringTrnCollectionHeader.IsPrinted, IsLocked = newFolderMonitoringTrnCollectionHeader.IsLocked, CreatedById = newFolderMonitoringTrnCollectionHeader.CreatedById, CreatedDateTime = newFolderMonitoringTrnCollectionHeader.CreatedDateTime, UpdatedById = newFolderMonitoringTrnCollectionHeader.UpdatedById, UpdatedDateTime = newFolderMonitoringTrnCollectionHeader.UpdatedDateTime }; db.TrnCollections.InsertOnSubmit(newCollection); db.SubmitChanges(); ORId = newCollection.Id; if (newFolderMonitoringTrnCollectionHeader.ListFolderMonitoringTrnCollectionLines.Any()) { foreach (var listFolderMonitoringTrnCollectionLine in newFolderMonitoringTrnCollectionHeader.ListFolderMonitoringTrnCollectionLines) { Data.TrnCollectionLine newCollectionLine = new Data.TrnCollectionLine { ORId = ORId, BranchId = listFolderMonitoringTrnCollectionLine.BranchId, AccountId = listFolderMonitoringTrnCollectionLine.AccountId, ArticleId = listFolderMonitoringTrnCollectionLine.ArticleId, SIId = listFolderMonitoringTrnCollectionLine.SIId, Particulars = listFolderMonitoringTrnCollectionLine.Particulars, Amount = listFolderMonitoringTrnCollectionLine.Amount, PayTypeId = listFolderMonitoringTrnCollectionLine.PayTypeId, CheckNumber = listFolderMonitoringTrnCollectionLine.CheckNumber, CheckDate = listFolderMonitoringTrnCollectionLine.CheckDate, CheckBank = listFolderMonitoringTrnCollectionLine.CheckBank, DepositoryBankId = listFolderMonitoringTrnCollectionLine.DepositoryBankId, IsClear = listFolderMonitoringTrnCollectionLine.IsClear }; db.TrnCollectionLines.InsertOnSubmit(newCollectionLine); } db.SubmitChanges(); } var collection = from d in db.TrnCollections where d.Id == ORId select d; if (collection.Any()) { var lockCollection = collection.FirstOrDefault(); lockCollection.IsLocked = true; db.SubmitChanges(); journal.InsertOfficialReceiptJournal(ORId); } var collectionLines = from d in db.TrnCollectionLines where d.ORId == ORId && d.SIId != null && d.TrnCollection.IsLocked == true select d; if (collectionLines.Any()) { foreach (var collectionLine in collectionLines) { accountsReceivable.UpdateAccountsReceivable(Convert.ToInt32(collectionLine.SIId)); } } } } } return(Request.CreateResponse(HttpStatusCode.OK, returnMessage)); } else { return(Request.CreateResponse(HttpStatusCode.NotFound, "Data Source is Invalid or Empty.")); } } catch (Exception ex) { Debug.WriteLine(ex); return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Backend Error: " + ex.Message)); } }
public HttpResponseMessage AddCollection(ApiModels.TrnCollectionModel objCollection) { try { var currentUser = from d in db.MstUsers where d.AspNetUserId == User.Identity.GetUserId() select d; var customer = from d in db.MstCustomers where d.Id == objCollection.CustomerId select d; if (customer.Any() == false) { return(Request.CreateResponse(HttpStatusCode.NotFound, "Customer not found.")); } var loan = from d in db.TrnLoans where d.Id == objCollection.LoanId && d.CustomerId == customer.FirstOrDefault().Id select d; if (loan.Any() == false) { return(Request.CreateResponse(HttpStatusCode.NotFound, "Loan transaction not found.")); } var payType = from d in db.MstPayTypes where d.Id == objCollection.PayTypeId select d; if (payType.Any() == false) { return(Request.CreateResponse(HttpStatusCode.NotFound, "Pay type not found.")); } var collector = from d in db.MstCollectors where d.Id == objCollection.CollectorId select d; if (collector.Any() == false) { return(Request.CreateResponse(HttpStatusCode.NotFound, "Collector not found.")); } var collectionNumber = "0000000001"; var lastCollection = from d in db.TrnCollections.OrderByDescending(d => d.Id) select d; if (lastCollection.Any()) { var lastCollectionNumber = Convert.ToInt32(lastCollection.FirstOrDefault().CollectionNumber) + 0000000001; collectionNumber = LeadingZeroes(lastCollectionNumber, 10); } Data.TrnCollection newCollection = new Data.TrnCollection() { CollectionNumber = collectionNumber, CollectionDate = Convert.ToDateTime(objCollection.CollectionDate), ManualCollectionNumber = collectionNumber, CustomerId = customer.FirstOrDefault().Id, LoanId = loan.FirstOrDefault().Id, PayTypeId = payType.FirstOrDefault().Id, PaymayaAccountNumber = objCollection.PaymayaAccountNumber, GCashAccountNumber = objCollection.GCashAccountNumber, CreditCardNumber = objCollection.CreditCardNumber, CreditCardName = objCollection.CreditCardName, CheckNumber = objCollection.CheckNumber, CheckDate = Convert.ToDateTime(objCollection.CheckDate), CheckBank = objCollection.CheckBank, PaidAmount = objCollection.PaidAmount, PenaltyAmount = objCollection.PenaltyAmount, Remarks = objCollection.Remarks, CollectorId = collector.FirstOrDefault().Id, IsLocked = true, CreatedByUserId = currentUser.FirstOrDefault().Id, CreatedDateTime = DateTime.Now, UpdatedByUserId = currentUser.FirstOrDefault().Id, UpdatedDateTime = DateTime.Now }; db.TrnCollections.InsertOnSubmit(newCollection); db.SubmitChanges(); UpdateLoanTransaction(loan.FirstOrDefault().Id); return(Request.CreateResponse(HttpStatusCode.OK)); } catch (Exception ex) { return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message)); } }