/// <summary> /// SFDC User information mapped into Operator table /// </summary> /// <param name="SFDCUsers"></param> /// <returns></returns> public List <SFDCBillingLines> GetBillingInformationusingIds(List <int> BillingIds) { List <SFDCBillingLines> result = new List <SFDCBillingLines>(); using (NDISINT18Apr2021Context dbc = new NDISINT18Apr2021Context(this._integrationAppSettings)) { var objBillingLinesList = dbc.BillingLinesNews.Where(u => BillingIds.Any(k => k == u.BillingId)).ToList(); if (objBillingLinesList != null) { foreach (var bl in objBillingLinesList) { var customerTrip = dbc.BillingCustomerTrips.Where(k => k.CustomerTripId == bl.CustomerTripId).FirstOrDefault();//done var customer = dbc.Customers.Where(k => k.CustId == customerTrip.CustomerId).FirstOrDefault(); var Trip = dbc.Trips.Where(k => k.TripId == bl.TripId).FirstOrDefault(); var drivers = dbc.Drivers.Where(k => k.DriverId == (Trip.DriverId ?? 0)).FirstOrDefault(); var cslines = dbc.CustomerServiceLines.Where(k => k.ServiceAgreementCustomerId == customerTrip.CustomerId && k.ServiceAgreementId == bl.ServiceAgreementId && k.ServiceAgreementItemId == bl.ServiceAgreementItemId).FirstOrDefault(); var SFRate = dbc.SalesforceRates.Where(k => k.SalesforceRatesId == bl.SalesforceRatesId).FirstOrDefault(); SFDCBillingLines bls = new SFDCBillingLines(); bls.BillingID = bl.BillingId; bls.enrtcr__Client__c = customer.CustomerId.ToString(); bls.enrtcr__Date__c = customerTrip?.StartDate.ToString(); // Automatic from Trip bls.enrtcr__Quantity__c = Math.Round((decimal)(customerTrip?.CustomerKm ?? 0), 1); //Actual Distance (Km) from Trip if (bl?.ServiceAgreementItemId != null) { bls.enrtcr__Support_Contract_Item__c = bl?.ServiceAgreementItemId ?? ""; } if (bl?.ServiceAgreementId != null) { bls.enrtcr__Support_Contract__c = bl?.ServiceAgreementId ?? ""; } if (cslines != null) { bls.enrtcr__Site__c = cslines?.SiteId ?? null; //site bls.enrtcr__Support_CategoryId__c = cslines?.CategoryItemId ?? ""; //CategoryItem bls.enrtcr__Site_Service_Program__c = cslines?.SiteServiceProgramId ?? ""; //Site Service Program; } bls.enrtcr__Rate__c = SFRate?.RateId ?? ""; //ob.UnitOfMeasure.ToString(); bls.enrtcr__Worker__c = drivers?.SalesForceUserId; //worker bls.enrtcr__Client_Rep_Accepted__c = true; //client rep accepted bls.enrtcr__Use_Negotiated_Rate__c = true; //nogotitiated if (bl.AllowNegotiation == true) { bls.enrtcr__Negotiated_Rate_Ex_GST__c = Math.Round((decimal)(bl.BlendedRate ?? 0), 2); //Nogotiated Rate GST bls.enrtcr__Negotiated_Rate_GST__c = (decimal)(00.00); //Nogotiated Rate GST } //if (drivers?.SalesForceUserId != "121") result.Add(bls); } } } return(result); }
/// <summary> /// SFDC User information mapped into Operator table /// </summary> /// <param name="SFDCUsers"></param> /// <returns></returns> public List <SFDCBillingLines> GetBillingInformation() { List <SFDCBillingLines> result = new List <SFDCBillingLines>(); using (NDISINT18Apr2021Context dbc = new NDISINT18Apr2021Context(this._integrationAppSettings)) { var objs = dbc.BillingLines.Where(k => k.Approved == true).ToList(); var objBillingLinesList = dbc.BillingLines.Where(k => k.Approved == true).ToList(); var objCustomerList = dbc.Customers.ToList(); var objCustomerServiceLineList = dbc.CustomerServiceLines.ToList(); var objTripList = dbc.Trips.ToList(); var objDriverList = dbc.Drivers.ToList(); foreach (var bl in objBillingLinesList) { var trip = objTripList.FirstOrDefault(k => k.TripId == bl.TripId); var cslines = objCustomerServiceLineList.FirstOrDefault(k => k.ServiceAgreementId == bl.ServiceAgreementId && k.ServiceAgreementItemId == bl.ServiceAgreementItemId); var drivers = objDriverList.FirstOrDefault(k => k.DriverId == bl.DriverId); SFDCBillingLines bls = new SFDCBillingLines(); bls.enrtcr__Client__c = bl.CustomerId.ToString(); bls.enrtcr__Date__c = trip?.StartDate.ToString(); // Automatic from Trip bls.enrtcr__Quantity__c = (int)(trip?.TotalKm ?? 0); //Actual Distance (Km) from Trip bls.enrtcr__Support_Contract_Item__c = bl?.ServiceAgreementId ?? ""; bls.enrtcr__Support_Contract__c = bl?.ServiceAgreementItemId ?? ""; bls.enrtcr__Site__c = cslines?.SiteId ?? null; //site bls.enrtcr__Support_CategoryId__c = cslines?.ServiceId ?? ""; //service bls.enrtcr__Site_Service_Program__c = cslines?.ServiceName ?? ""; //Site Service Program; bls.enrtcr__Rate__c = bl?.Rate.ToString(); //ob.UnitOfMeasure.ToString(); bls.enrtcr__Worker__c = drivers?.SalesForceUserId; //worker bls.enrtcr__Client_Rep_Accepted__c = true; //client rep accepted bls.enrtcr__Use_Negotiated_Rate__c = true; //nogotitiated bls.enrtcr__Negotiated_Rate_Ex_GST__c = (decimal)(00.00); //Nogotiated Rate GST bls.enrtcr__Negotiated_Rate_GST__c = (decimal)(00.00); //Nogotiated Rate GST result.Add(bls); } } return(result); }