/// <summary> /// Updating invoice status and payment date /// on accepting discount /// Date: 25 June 2019 /// Developer: Shreyans Khandelwal (0538) /// </summary> /// <param name="invoiceId"></param> /// <param name="paymentDate"></param> /// <returns></returns> private bool UpdateInvoice(long?invoiceId, decimal amountPaid, decimal discountAmount, DateTime paymentdate, Int32 InvoiceStatus, decimal?AvailableLimits, bool?IsUnLimited) { try { var invoice = (from data in finocartEntities.Invoice where data.InvoiceID == invoiceId select data).FirstOrDefault(); invoice.InvoiceStatus = InvoiceStatus; if (invoice.FinoLimUnLim != "FinoLim" && invoice.FinoLimUnLim != "FinoUnLim") { invoice.PaymentDate = paymentdate; } invoice.AmountPaid = Math.Round(amountPaid); invoice.Earning = Math.Round(discountAmount); invoice.InvoiceApprovalDate = DateTime.Now.Date; if (IsUnLimited != true && AvailableLimits != null) { invoice.Limits = AvailableLimits.ToString(); } else { invoice.Limits = "Unlimited"; } finocartEntities.SaveChanges(); return(true); } catch (Exception ex) { throw ex; } }
/// <summary> /// Saving vendor from SAP to Database /// Date: 20 June 2019 /// Developer: Shreyans Khandelwal (0538) /// </summary> public void SaveVendor() { try { VendorDetail vendorDetail = new VendorDetail(); //vendorDetail = objSapVendor.GetVendor(); vendorDetail.PanNumber = "0192873661"; int venId = 0; bool addAssoCompany = false; //allowing to add vendor only if PAN number is available if (!string.IsNullOrEmpty(vendorDetail.PanNumber)) { //checking if vendor already exist on basis of PAN number var vendorId = (from data in finocartEntities.Company where data.Pan_number == vendorDetail.PanNumber select data.CompanyID).FirstOrDefault(); //if vendor exist linking it to new company if (vendorId > 0) { var vendorAssociate = (from data in finocartEntities.VendorAssociatedCompany where data.VendorId == vendorId && data.CompanyId == 5678 select data).FirstOrDefault(); if (vendorAssociate == null) { venId = vendorId; addAssoCompany = true; } } //If vendor does not exist adding it to DB else { vendorDetail.InstretedAs = (from data in finocartEntities.LookupDetails where data.LookupValue == "Vendor" && data.LookupFor == "AccessView" select data.ID).FirstOrDefault(); Company company = MapCompany(vendorDetail); finocartEntities.Company.Add(company); finocartEntities.SaveChanges(); addAssoCompany = true; venId = company.CompanyID; } //Linking vendor to the company if (addAssoCompany) { if (!finocartEntities.VendorAssociatedCompany.Where(data => data.VendorId == venId && data.CompanyId == 57).Any()) { VendorAssociatedCompany vendorAssociatedCompany = new VendorAssociatedCompany(); vendorAssociatedCompany.VendorId = venId; vendorAssociatedCompany.CompanyId = 57; finocartEntities.VendorAssociatedCompany.Add(vendorAssociatedCompany); finocartEntities.SaveChanges(); } } } } catch (Exception ex) { logger.WriteLog(ex); throw ex; } }
/// <summary> /// Sending notification to vendor /// on approval of invoice /// Date: 26 June 2019 /// Developer: Shreyans Khandelwal (0538) /// </summary> /// <returns></returns> public bool SendNotification(int companyId, string messageType, int billId, decimal billAmount) { try { bool insert = false; string message = GetMessage(messageType, billId, billAmount); List <int> userId = GetUserForNotification(companyId, messageType); List <Notification> lstNotification = new List <Notification>(); foreach (var id in userId) { Notification notification = new Notification(); notification.CreatedOn = DateTime.Now; notification.Description = message; notification.UserID = id; lstNotification.Add(notification); insert = true; } if (insert) { finocartEntities.Notification.AddRange(lstNotification); finocartEntities.SaveChanges(); } return(true); } catch (Exception ex) { throw ex; } }