public InvoiceViewModel GetInvoiceDetail(int agentId, int masterPNRId) { StringBuilder builder = new StringBuilder(); GetMasterPNRDetail(agentId, masterPNRId); var masterPnrDetails = _ent.TBO_MasterPNRs.Where(x => x.MPNRId == masterPNRId).FirstOrDefault(); var pnrDetails = _ent.TBO_PNRs.ToList().FindAll(id => id.MPNRId == masterPNRId).Select(x => x.PNRId).ToList(); InvoiceViewModel viewModel = new InvoiceViewModel(); int pnrcount = pnrDetails.Count; foreach (var pnr in pnrDetails) { InvoicePNRDetailModel model = new InvoicePNRDetailModel(); var agentdetail = GetAgentDetail(agentId); var pnrDetail = GetPNRDetailById((int)pnr); var paxDetailByPNRId = GetPassengerDetails((int)pnrDetail.PNRId); model.AgencyDetail = agentdetail; model.BilledBy = "Travel Planner Pvt.Ltd"; model.TicketedToAgent = agentdetail.AgencyName; model.BilledByAgent = agentdetail.AgencyName; model.TicketedToPassenger = paxDetailByPNRId.FirstOrDefault().FirstName + paxDetailByPNRId.FirstOrDefault().LastName; model.PNRId = (int)pnrDetail.PNRId; model.PNR = pnrDetail.RecLoc; model.InvoiceDate = createdDate; model.VendorDetail = GetVendorDetail(); model.InvoiceNo = "AH" + GetVoucherByTransactionRef(masterPNRId).ToString().PadLeft(4, '0'); InvoiceItineraryDetailModel itinerary = new InvoiceItineraryDetailModel(); var sectorDetail = GetPNRSectorDetail((int)pnr); model.TravelDate = sectorDetail.DepartDate; List <int> segDepCityIdList = new List <int>(); ; var segmentdetail = GetSegmentDetail((int)sectorDetail.SectorId); int departcityid = 0; int arrivecityid = 1; foreach (TBO_PNRsegments segment in segmentdetail) { departcityid = segmentdetail[0].DepartCityId; arrivecityid = segment.ArrivalCityId; segDepCityIdList.Add(segment.DepartCityId); InvoiceItinerarySegment invoiceSegment = new InvoiceItinerarySegment(); var airlineDetail = GetAirlineDetailById(segment.AirlineId); invoiceSegment.Airline = airlineDetail.AirlineName; invoiceSegment.AirlineCode = airlineDetail.AirlineCode; invoiceSegment.FlightNo = segment.FlightNumber; invoiceSegment.Class = segment.BIC; itinerary.Segments.Add(invoiceSegment); } if (departcityid != arrivecityid) { model.Journey = "OneWay"; } else { model.Journey = "RoundTrip"; } string sector = string.Empty; foreach (var cityId in segDepCityIdList) { sector += GetCityDetailsByCityId(cityId).CityCode + " - "; } if (model.Journey == "OneWay") { sector += GetCityDetailsByCityId(sectorDetail.DestinationCityId).CityCode; } if (model.Journey == "RoundTrip") { sector += GetCityDetailsByCityId(sectorDetail.DepartCityId).CityCode; } itinerary.Sector = sector; double grossAmt = 0; double discountAmt = 0; double serviceTax = 0; double transFee = 0; var paxDetail = GetPassengerDetails((int)pnr); int paxcounter = paxDetail.Count; foreach (TBO_Passengers pax in paxDetail) { InvoicePassenger invPax = new InvoicePassenger(); invPax.PassengerName = pax.FirstName + " " + pax.MiddleName + " " + pax.LastName; invPax.PassengerType = GetPassengerTypeById(pax.PassengerTypeId).PassengerTypeName; var pnrtickets = GetPNRTickets((int)pax.PassengerId); if (pnrtickets != null) { invPax.Fare = pnrtickets.SellingBaseFare; invPax.OtherCharge = pnrtickets.SellingOtherCharges; invPax.FuelSurcharge = pnrtickets.SellingFSC; invPax.ServiceCharge = pnrtickets.ServiceCharge; invPax.Tax = pnrtickets.SellingTax + pnrtickets.SellingAdditionalTxnFee + pnrtickets.MarkupAmount; grossAmt += invPax.Fare + invPax.OtherCharge + invPax.Tax + invPax.FuelSurcharge; invPax.MarkupAmount = pnrtickets.MarkupAmount; itinerary.TicketNo = pnrtickets.TicketNumber; discountAmt = pnrtickets.DiscountAmount; serviceTax = pnrtickets.SellingServiceTax; transFee += pnrtickets.SellingAirlineTransFee; model.AgentAirlineMarkUp = pnrtickets.MarkupAmount; model.TicketStatusId = pnrtickets.TicketStatusId; model.NetAmount = pnrtickets.BaseFare - pnrtickets.DiscountAmount + pnrtickets.FSC + pnrtickets.Tax + pnrtickets.MarkupAmount + pnrtickets.OtherCharges + pnrtickets.ServiceTax + pnrtickets.ServiceCharge + pnrtickets.AirlineTransFee + pnrtickets.AdditionalTxnFee; } itinerary.PassengerDetail.Add(invPax); } model.ItineraryDetails.Add(itinerary); model.GrossAmount = grossAmt; model.CommissionEarned = discountAmt; model.ServiceTax = serviceTax; model.TransactionFee = transFee; model.NetReceivable = model.NetAmount; viewModel.PNRDetails.Add(model); } return(viewModel); }
public InvoiceViewModel GetInvoiceDetailMain(int masterPNRId) { var masterPnrDetails = _ent.TBO_MasterPNRs.Where(x => x.MPNRId == masterPNRId).FirstOrDefault(); var OldPnrDetails = _ent.PNRs.Where(x => x.PNRId == masterPNRId).FirstOrDefault(); if (masterPnrDetails == null) { GetPNRDetail(OldPnrDetails.AgentId, masterPNRId); } else { GetMasterPNRDetail(masterPnrDetails.AgentId, masterPNRId); } var pnrDetails = _ent.TBO_PNRs.Where(x => x.MPNRId == masterPNRId).Select(x => x.PNRId).ToList(); if (pnrDetails.Count == 0) { var pnrsDetail = _ent.PNRs.Where(x => x.PNRId == masterPNRId).Select(x => x.PNRId).ToList(); InvoiceViewModel viewModel = new InvoiceViewModel(); viewModel.ServiceProviderId = OldPnrDetails.ServiceProviderId; int pnrcount = pnrsDetail.Count; foreach (var pnr in pnrsDetail) { InvoicePNRDetailModel model = new InvoicePNRDetailModel(); var agentdetail = GetVendorDistributorDetail(OldPnrDetails.AgentId); var pnrDetail = GetOldPNRDetailById((int)pnr); var paxDetailByPNRId = GetOldPassengerDetails((int)pnrDetail.PNRId); model.AgencyDetail = agentdetail; // model.BilledBy = "Travel Planner Pvt.Ltd"; model.TicketedToAgent = agentdetail.AgencyName; model.BilledByAgent = agentdetail.AgencyName; model.TicketedToPassenger = paxDetailByPNRId.FirstOrDefault().FirstName + paxDetailByPNRId.FirstOrDefault().LastName; model.PNRId = (int)pnrDetail.PNRId; model.PNR = pnrDetail.GDSRefrenceNumber; model.InvoiceDate = createdDate; model.VendorDetail = GetVendorBranchDetail(OldPnrDetails.AgentId); model.BilledBy = model.VendorDetail.VendorName; model.InvoiceNo = GetVoucherByTransactionRef(masterPNRId).ToString().PadLeft(4, '0'); InvoiceItineraryDetailModel itinerary = new InvoiceItineraryDetailModel(); var sectorDetail = GetOldPNRSectorDetail((int)pnrDetail.PNRId); model.TravelDate = sectorDetail.DepartDate; List <int> segDepCityIdList = new List <int>(); var segmentdetail = GetOldSegmentDetail((int)pnrDetail.PNRId); int departcityid = 0; int arrivecityid = 1; foreach (PNRSegments segment in segmentdetail) { departcityid = segmentdetail[0].DepartCityId; arrivecityid = segment.ArriveCityId; segDepCityIdList.Add(segment.DepartCityId); InvoiceItinerarySegment invoiceSegment = new InvoiceItinerarySegment(); var airlineDetail = GetAirlineDetailById(segment.AirlineId); invoiceSegment.Airline = airlineDetail.AirlineName; invoiceSegment.AirlineCode = airlineDetail.AirlineCode; invoiceSegment.FlightNo = segment.FlightNumber; invoiceSegment.Class = segment.BIC; invoiceSegment.DepartureDate = segment.DepartDate.ToString(); itinerary.Segments.Add(invoiceSegment); } if (departcityid != arrivecityid) { model.Journey = "OneWay"; } else { model.Journey = "RoundTrip"; } string sector = string.Empty; foreach (var cityId in segDepCityIdList) { sector += GetCityDetailsByCityId(cityId).CityCode + " - "; } if (model.Journey == "OneWay") { sector += GetCityDetailsByCityId(sectorDetail.DestinationCityId).CityCode; } if (model.Journey == "RoundTrip") { sector += GetCityDetailsByCityId(sectorDetail.DepartCityId).CityCode; } itinerary.Sector = sector; double grossAmt = 0; double discountAmt = 0; double serviceTax = 0; double transFee = 0; var paxDetail = GetOldPassengerDetails((int)pnr); int paxcounter = paxDetail.Count; foreach (Passengers pax in paxDetail) { InvoicePassenger invPax = new InvoicePassenger(); invPax.PassengerName = pax.FirstName + " " + pax.MiddleName + " " + pax.LastName; invPax.PassengerType = GetPassengerTypeById(pax.PassengerTypeId).PassengerTypeName; var pnrtickets = GetOldPNRTickets((int)pax.PassengerId); if (pnrtickets != null) { model.Currency = pnrtickets.Currency; invPax.FxRate = pnrtickets.LCY_FX_Rate; if (invPax.FxRate == 0) { invPax.FxRate = 1; } if (model.Currency != "USD") { invPax.Fare = (pnrtickets.Fare + pnrtickets.MarkupAmount) * invPax.FxRate; invPax.OtherCharge = pnrtickets.FSC * invPax.FxRate; invPax.FuelSurcharge = pnrtickets.FSC * invPax.FxRate; invPax.ServiceCharge = pnrtickets.ServiceCharge * invPax.FxRate; invPax.Tax = (pnrtickets.TaxAmount + pnrtickets.ServiceCharge + pnrtickets.FSC) * invPax.FxRate; //+ pnrtickets.MarkupAmount; grossAmt += invPax.Fare + invPax.OtherCharge + invPax.Tax + invPax.FuelSurcharge; // + invPax.ServiceCharge invPax.MarkupAmount = pnrtickets.MarkupAmount * invPax.FxRate; model.AgentAirlineMarkUp = pnrtickets.MarkupAmount * invPax.FxRate; discountAmt += pnrtickets.DiscountAmount * invPax.FxRate; } else { invPax.Fare = pnrtickets.Fare + pnrtickets.MarkupAmount; invPax.OtherCharge = pnrtickets.FSC; invPax.FuelSurcharge = pnrtickets.FSC; invPax.ServiceCharge = pnrtickets.ServiceCharge; invPax.Tax = pnrtickets.TaxAmount + pnrtickets.ServiceCharge + pnrtickets.FSC; //+ pnrtickets.MarkupAmount; grossAmt += invPax.Fare + invPax.OtherCharge + invPax.Tax + invPax.FuelSurcharge; // + invPax.ServiceCharge invPax.MarkupAmount = pnrtickets.MarkupAmount; model.AgentAirlineMarkUp = pnrtickets.MarkupAmount; discountAmt += pnrtickets.DiscountAmount; } itinerary.TicketNo = pnrtickets.TicketNumber; invPax.TicketNo = pnrtickets.TicketNumber; serviceTax += 0; transFee += 0; model.TicketStatusId = pnrtickets.TicketStatusId; } itinerary.PassengerDetail.Add(invPax); } model.ItineraryDetails.Add(itinerary); model.GrossAmount = grossAmt; string aaa = discountAmt.ToString(); if (!aaa.Contains("-")) { model.CommissionEarned = discountAmt; } if (aaa.Contains("-")) { string bbb = aaa.TrimStart('-'); model.TransactionFee = Convert.ToDouble(bbb) + transFee; } else { model.TransactionFee = transFee; } model.ServiceTax = serviceTax; model.TaxDeductionAtSource = Math.Ceiling(discountAmt * 0.1); model.NetAmount = model.GrossAmount - model.CommissionEarned + model.ServiceTax + model.TransactionFee; model.NetReceivable = model.NetAmount; viewModel.PNRDetails.Add(model); } return(viewModel); } else { InvoiceViewModel viewModel = new InvoiceViewModel(); viewModel.ServiceProviderId = masterPnrDetails.ServiceProviderId; int pnrcount = pnrDetails.Count; foreach (var pnr in pnrDetails) { InvoicePNRDetailModel model = new InvoicePNRDetailModel(); var agentdetail = GetVendorDistributorDetail(masterPnrDetails.AgentId); var pnrDetail = GetPNRDetailById((int)pnr); var paxDetailByPNRId = GetPassengerDetails((int)pnrDetail.PNRId); model.AgencyDetail = agentdetail; //model.BilledBy = "Travel Planner Pvt.Ltd"; model.TicketedToAgent = agentdetail.AgencyName; model.BilledByAgent = agentdetail.AgencyName; model.TicketedToPassenger = paxDetailByPNRId.FirstOrDefault().FirstName + paxDetailByPNRId.FirstOrDefault().LastName; model.PNRId = (int)pnrDetail.PNRId; model.PNR = pnrDetail.RecLoc; model.InvoiceDate = createdDate; model.VendorDetail = GetVendorBranchDetail(masterPnrDetails.AgentId); model.BilledBy = model.VendorDetail.VendorName; model.InvoiceNo = GetVoucherByTransactionRef(masterPNRId).ToString().PadLeft(4, '0'); InvoiceItineraryDetailModel itinerary = new InvoiceItineraryDetailModel(); var sectorDetail = GetPNRSectorDetail((int)pnrDetail.PNRId); model.TravelDate = sectorDetail.DepartDate; List <int> segDepCityIdList = new List <int>(); var segmentdetail = GetSegmentDetail((int)pnrDetail.PNRId); int departcityid = 0; int arrivecityid = 1; foreach (TBO_PNRsegments segment in segmentdetail) { departcityid = segmentdetail[0].DepartCityId; arrivecityid = segment.ArrivalCityId; segDepCityIdList.Add(segment.DepartCityId); InvoiceItinerarySegment invoiceSegment = new InvoiceItinerarySegment(); var airlineDetail = GetAirlineDetailById(segment.AirlineId); invoiceSegment.Airline = airlineDetail.AirlineName; invoiceSegment.AirlineCode = airlineDetail.AirlineCode; invoiceSegment.FlightNo = segment.FlightNumber; invoiceSegment.Class = segment.BIC; invoiceSegment.DepartureDate = segment.DepartDate.ToString(); itinerary.Segments.Add(invoiceSegment); } if (departcityid != arrivecityid) { model.Journey = "OneWay"; } else { model.Journey = "RoundTrip"; } string sector = string.Empty; foreach (var cityId in segDepCityIdList) { sector += GetCityDetailsByCityId(cityId).CityCode + " - "; } if (model.Journey == "OneWay") { sector += GetCityDetailsByCityId(sectorDetail.DestinationCityId).CityCode; } if (model.Journey == "RoundTrip") { sector += GetCityDetailsByCityId(sectorDetail.DepartCityId).CityCode; } itinerary.Sector = sector; double grossAmt = 0; double discountAmt = 0; double serviceTax = 0; double agentServiceCharge = 0; double transFee = 0; double totalCalculatedDiscount = 0; double totalSummedDiscount = 0; double totalTranFee = 0; var paxDetail = GetPassengerDetails((int)pnr); int paxcounter = paxDetail.Count; foreach (TBO_Passengers pax in paxDetail) { InvoicePassenger invPax = new InvoicePassenger(); invPax.PassengerName = pax.FirstName + " " + pax.MiddleName + " " + pax.LastName; invPax.PassengerType = GetPassengerTypeById(pax.PassengerTypeId).PassengerTypeName; var pnrtickets = GetPNRTickets((int)pax.PassengerId); if (pnrtickets != null) { model.Currency = pnrtickets.Currency; invPax.FxRate = pnrtickets.LCY_FX_Rate; if (invPax.FxRate == 0) { invPax.FxRate = 1; } if (model.Currency != "USD") { invPax.Fare = pnrtickets.SellingBaseFare * invPax.FxRate; invPax.OtherCharge = pnrtickets.SellingOtherCharges * invPax.FxRate; invPax.FuelSurcharge = pnrtickets.SellingFSC * invPax.FxRate; invPax.ServiceCharge = pnrtickets.ServiceCharge * invPax.FxRate; if (viewModel.ServiceProviderId == 5) //TBO ALREADY CONTAIN FSC ON TAX { invPax.Tax = (pnrtickets.SellingTax + pnrtickets.SellingAdditionalTxnFee) * invPax.FxRate; //+ pnrtickets.MarkupAmount; } else { invPax.Tax = (pnrtickets.SellingTax + pnrtickets.SellingAdditionalTxnFee + pnrtickets.SellingFSC) * invPax.FxRate; //+ pnrtickets.MarkupAmount; } grossAmt += invPax.Fare + invPax.OtherCharge + invPax.Tax; // + invPax.ServiceCharge invPax.MarkupAmount = pnrtickets.MarkupAmount * invPax.FxRate; discountAmt += pnrtickets.DiscountAmount * invPax.FxRate; totalCalculatedDiscount = pnrtickets.DiscountAmount > 0 ? pnrtickets.DiscountAmount : 0; totalTranFee += (pnrtickets.DiscountAmount < 0 ? Math.Abs(pnrtickets.DiscountAmount) : 0); if (masterPnrDetails.isBranchByPassDeal == false) { totalCalculatedDiscount = pnrtickets.BranchDealAmount < 0 ? Math.Abs(pnrtickets.BranchDealAmount) : 0; totalTranFee += (pnrtickets.BranchDealAmount > 0 ? Math.Abs(pnrtickets.BranchDealAmount) : 0); } //if (masterPnrDetails.isDistributorByPassDeal == false) //{ // totalCalculatedDiscount = pnrtickets.DistrubutorDealAmount < 0 ? Math.Abs(pnrtickets.DistrubutorDealAmount) : 0; // totalTranFee += (pnrtickets.DistrubutorDealAmount > 0 ? Math.Abs(pnrtickets.DistrubutorDealAmount) : 0); //} //totalCalculatedDiscount += (pnrtickets.DiscountAmount > 0 ? pnrtickets.DiscountAmount : 0 + // (pnrtickets.BranchDealAmount < 0 ? Math.Abs(pnrtickets.BranchDealAmount) : 0) + // (pnrtickets.DistrubutorDealAmount < 0 ? Math.Abs(pnrtickets.DistrubutorDealAmount) : 0)); //totalTranFee += ((pnrtickets.DiscountAmount < 0 ? Math.Abs(pnrtickets.DiscountAmount) : 0) + // (pnrtickets.BranchDealAmount > 0 ? Math.Abs(pnrtickets.BranchDealAmount) : 0) + // (pnrtickets.DistrubutorDealAmount > 0 ? Math.Abs(pnrtickets.DistrubutorDealAmount) : 0)); serviceTax += pnrtickets.SellingServiceTax * invPax.FxRate; agentServiceCharge += (pnrtickets.ServiceCharge * invPax.FxRate); transFee += pnrtickets.SellingAirlineTransFee * invPax.FxRate; model.AgentAirlineMarkUp = pnrtickets.MarkupAmount * invPax.FxRate; } else { invPax.Fare = pnrtickets.SellingBaseFare; invPax.OtherCharge = pnrtickets.SellingOtherCharges; invPax.FuelSurcharge = pnrtickets.SellingFSC; invPax.ServiceCharge = pnrtickets.ServiceCharge; if (viewModel.ServiceProviderId == 5) //TBO ALREADY CONTAIN FSC ON TAX { invPax.Tax = (pnrtickets.SellingTax + pnrtickets.SellingAdditionalTxnFee); //+ pnrtickets.MarkupAmount; } else { invPax.Tax = (pnrtickets.SellingTax + pnrtickets.SellingAdditionalTxnFee + pnrtickets.SellingFSC); //+ pnrtickets.MarkupAmount; } grossAmt += invPax.Fare + invPax.OtherCharge + invPax.Tax; // + invPax.ServiceCharge invPax.MarkupAmount = pnrtickets.MarkupAmount; discountAmt += pnrtickets.DiscountAmount; totalCalculatedDiscount = pnrtickets.DiscountAmount > 0 ? pnrtickets.DiscountAmount : 0; totalTranFee = (pnrtickets.DiscountAmount < 0 ? Math.Abs(pnrtickets.DiscountAmount) : 0); if (masterPnrDetails.isBranchByPassDeal == false) { totalCalculatedDiscount = pnrtickets.BranchDealAmount < 0 ? Math.Abs(pnrtickets.BranchDealAmount) : 0; totalTranFee += (pnrtickets.BranchDealAmount > 0 ? Math.Abs(pnrtickets.BranchDealAmount) : 0); } //if (masterPnrDetails.isDistributorByPassDeal == false) //{ // totalCalculatedDiscount = pnrtickets.DistrubutorDealAmount < 0 ? Math.Abs(pnrtickets.DistrubutorDealAmount) : 0; // totalTranFee += (pnrtickets.DistrubutorDealAmount > 0 ? Math.Abs(pnrtickets.DistrubutorDealAmount) : 0); //} //totalCalculatedDiscount += (pnrtickets.DiscountAmount > 0 ? pnrtickets.DiscountAmount : 0 + // (pnrtickets.BranchDealAmount < 0 ? Math.Abs(pnrtickets.BranchDealAmount) : 0) + // (pnrtickets.DistrubutorDealAmount < 0 ? Math.Abs(pnrtickets.DistrubutorDealAmount) : 0)); //totalTranFee += ((pnrtickets.DiscountAmount < 0 ? Math.Abs(pnrtickets.DiscountAmount) : 0) + // (pnrtickets.BranchDealAmount > 0 ? Math.Abs(pnrtickets.BranchDealAmount) : 0) + // (pnrtickets.DistrubutorDealAmount > 0 ? Math.Abs(pnrtickets.DistrubutorDealAmount) : 0)); serviceTax += pnrtickets.SellingServiceTax; agentServiceCharge += (pnrtickets.ServiceCharge); transFee += pnrtickets.SellingAirlineTransFee; model.AgentAirlineMarkUp = pnrtickets.MarkupAmount; } totalSummedDiscount += totalCalculatedDiscount; itinerary.TicketNo = pnrtickets.TicketNumber; invPax.TicketNo = pnrtickets.TicketNumber; model.AgentAirlineMarkUp = pnrtickets.MarkupAmount; model.TicketStatusId = pnrtickets.TicketStatusId; } itinerary.PassengerDetail.Add(invPax); } model.ItineraryDetails.Add(itinerary); model.GrossAmount = grossAmt; model.CommissionEarned = totalSummedDiscount; model.TransactionFee = totalTranFee + transFee; //string aaa = discountAmt.ToString(); //if (!aaa.Contains("-")) //{ // model.CommissionEarned = discountAmt; //} //if (aaa.Contains("-")) //{ // string bbb = aaa.TrimStart('-'); // model.TransactionFee = Convert.ToDouble(bbb) + transFee; //} //else //{ // model.TransactionFee = transFee; //} model.ServiceTax = serviceTax; model.TaxDeductionAtSource = Math.Ceiling(totalSummedDiscount * 0.1); model.NetAmount = model.GrossAmount - model.CommissionEarned + model.ServiceTax + model.TransactionFee; model.NetReceivable = model.NetAmount; viewModel.PNRDetails.Add(model); } return(viewModel); } }