public Bill Map(Bill bill, BillLineItem lineItem = null, Payment payment = null) { if (!_cache.TryGetValue(bill.ID, out Bill result)) { _cache[bill.ID] = bill; result = bill; } if ((payment?.ID ?? 0) > 0 && !_paymentCache.ContainsKey(payment.ID)) { _paymentCache[payment.ID] = payment; if (result.Payments == null) { result.Payments = new List <Payment>(); } result.Payments.Add(payment); } if ((lineItem?.ID ?? 0) > 0 && !_lineItemCache.ContainsKey(lineItem.ID)) { _lineItemCache[lineItem.ID] = lineItem; if (result.LineItems == null) { result.LineItems = new List <BillLineItem>(); } result.LineItems.Add(lineItem); } return(result); }
public async Task <long> InsertBillLineItem(BillLineItem lineItem) { var param = new DynamicParameters(); param.Add("@SectionIndex", lineItem.SectionIndex); param.Add("@Section", lineItem.Section); param.Add("@Index", lineItem.Index); param.Add("@CodeID", lineItem.CodeID); param.Add("@Code", lineItem.Code); param.Add("@Descr", lineItem.Descr); param.Add("@Qty", lineItem.Qty); param.Add("@UnitPrice", lineItem.UnitPrice); param.Add("@Amount", lineItem.Amount); param.Add("@GSTAMount", lineItem.GSTAmount); param.Add("@GST", lineItem.GST); param.Add("@WillRecord", lineItem.WillRecord); param.Add("@BillID", lineItem.BillID); param.Add("@ID", dbType: DbType.Int64, direction: ParameterDirection.Output); await SqlMapper.ExecuteAsync(_unitOfWork.Connection, "InsertBillLineItem", param, commandType : CommandType.StoredProcedure, transaction : _unitOfWork.Transaction); return(param.Get <long>("@ID")); }
public static void AddLineItem(this Bill bill, BillLineItem lineItem) { if (bill.LineItems == null) { bill.LineItems = new List <BillLineItem>(); } lineItem.Index = bill.LineItems.Count() + 1; bill.LineItems.Add(lineItem); }
public async Task <Bill> Generate() { var amount = 0M; var gstAmount = 0M; var gst = await _context.GST(); var lineItems = new List <BillLineItem>(); lineItems.AddRange(await new Stage1BillAddOn(_dbContext).Generate(_request)); lineItems.AddRange(await new ApplicationFee(_context).Generate(_request)); lineItems.AddRange(await new CertificateFee(_context).Generate(_request)); lineItems.AddRange(await new ProductFee(_context).Generate(_request)); lineItems.AddRange(await new DeductionsAddOn(_dbContext).Generate(_request)); for (int i = 0; i < lineItems.Count; i++) { BillLineItem lineItem = lineItems[i]; lineItem.Index = i + 1; amount += lineItem.Amount; gstAmount += lineItem.GSTAmount; } return(new Bill { Status = BillStatus.Draft, Type = _request.Type, RequestType = _request.RequestType, RefNo = Guid.NewGuid().ToString(), Amount = amount, GSTAmount = gstAmount, GST = gst, RequestID = _request.RequestID, RefID = _request.RefID, CustomerID = _request.CustomerID, CustomerName = _request.CustomerName, IssuedOn = _request.ReferenceDate, LineItems = lineItems }); }
public Payment Map(Payment payment, Bill bill = null, BillLineItem billLineItem = null, Note note = null, Attachment attachment = null, Officer officer = null, Log log = null, Person contactPerson = null, Bank bank = null, ContactInfo contactInfo = null) { if (!_cache.TryGetValue(payment.ID, out Payment result)) { if (bank?.ID > 0) { payment.Bank = bank; } result = payment; _cache[payment.ID] = payment; } Bill outBill = null; if ((bill?.ID ?? 0) > 0 && !_billCache.TryGetValue(bill.ID, out outBill)) { _billCache[bill.ID] = bill; outBill = bill; if (result.Bills == null) { result.Bills = new List <Bill>(); } result.Bills.Add(bill); } if ((billLineItem?.ID ?? 0) > 0 && !_billLineItemCache.ContainsKey(billLineItem.ID)) { _billLineItemCache[billLineItem.ID] = billLineItem; if (outBill.LineItems == null) { outBill.LineItems = new List <BillLineItem>(); } outBill.LineItems.Add(billLineItem); } Note outNote = null; if ((note?.ID ?? 0) > 0 && !_noteCache.TryGetValue(note.ID, out outNote)) { if (!string.IsNullOrEmpty(officer?.Name)) { note.Officer = officer; } _noteCache[note.ID] = note; outNote = note; if (result.Notes == null) { result.Notes = new List <Note>(); } result.Notes.Add(note); } if (attachment?.ID > 0 && !(outNote.Attachments?.Any(e => e.ID == attachment.ID) ?? false)) { if (outNote.Attachments == null) { outNote.Attachments = new List <Attachment>(); } outNote.Attachments.Add(attachment); } if (log?.ID > 0 && !(result.Logs?.Any(e => e.ID == log.ID) ?? false)) { if (result.Logs == null) { result.Logs = new List <Log>(); } result.Logs.Add(log); } Person outContactPerson = null; if (contactPerson?.ID != null && contactPerson.ID != Guid.Empty && !_personCache.TryGetValue(contactPerson.ID, out outContactPerson)) { _personCache[contactPerson.ID] = contactPerson; outContactPerson = contactPerson; payment.ContactPerson = contactPerson; } if ((contactInfo?.ID ?? 0L) != 0L && !_contactInfoCache.ContainsKey(contactInfo.ID)) { _contactInfoCache[contactInfo.ID] = contactInfo; if (outContactPerson.ContactInfos == null) { outContactPerson.ContactInfos = new List <ContactInfo>(); } outContactPerson.ContactInfos.Add(contactInfo); } return(result); }
public string InsertUom(ref QuickbooksQueries quickbooksQueries, ref BillLineItem item) { XmlDocument inputXMLDoc; XmlElement qbXMLMsgsRq; QuickbooksUtils.BuildXMLQueryBase(out inputXMLDoc, out qbXMLMsgsRq); // Mark as query type XmlElement InvoicesAddRq = inputXMLDoc.CreateElement("UnitOfMeasureSetAddRq"); qbXMLMsgsRq.AppendChild(InvoicesAddRq); XmlElement invoiceXML = inputXMLDoc.CreateElement("UnitOfMeasureSetAdd"); InvoicesAddRq.AppendChild(invoiceXML); XmlElement name = inputXMLDoc.CreateElement("Name"); name.InnerText = item.unidad.Substring(0, Math.Min(30, item.unidad.Length)); invoiceXML.AppendChild(name); XmlElement unitType = inputXMLDoc.CreateElement("UnitOfMeasureType"); unitType.InnerText = "Other"; invoiceXML.AppendChild(unitType); XmlElement baseUnit = inputXMLDoc.CreateElement("BaseUnit"); invoiceXML.AppendChild(baseUnit); XmlElement baseUnitName = inputXMLDoc.CreateElement("Name"); baseUnitName.InnerText = item.unidad.Substring(0, Math.Min(30, item.unidad.Length)); baseUnit.AppendChild(baseUnitName); XmlElement abbr = inputXMLDoc.CreateElement("Abbreviation"); abbr.InnerText = item.claveunidad; baseUnit.AppendChild(abbr); string updateResponse; UomAdder uomAdder = new UomAdder(); if (quickbooksQueries.QueryQB(inputXMLDoc.OuterXml, out updateResponse)) { QuicbooksResponse qbResultUpdateInvoice = new QuicbooksResponse(updateResponse, "UnitOfMeasureSetAddRs"); if (qbResultUpdateInvoice.GetNumberOfResulst() > 0) { if (qbResultUpdateInvoice.success) { // Grab the ListID for the new vendor //XmlNode ClientNode = qbResultUpdateInvoice.GetXmlNodeList().Item(0).ChildNodes.Item(0); //msg = "Item created"; XmlNodeList responseNodeList = qbResultUpdateInvoice.GetXmlNodeList().Item(0).ChildNodes; foreach (XmlNode responseNode in responseNodeList) { UnitMeasure newUom = new UnitMeasure(); //Here is some weird behavior foreach (XmlNode childNode in responseNode.ChildNodes) { if (childNode.Name == "ListID") { newUom.listId = childNode.InnerText; } if (childNode.Name == "Name") { newUom.name = childNode.InnerText; } } if (responseNode["BaseUnit"] != null) { foreach (XmlNode DataRowNode in responseNode["BaseUnit"]) { if (DataRowNode.Name == "Name") { newUom.baseUnitName = DataRowNode.InnerText; } if (DataRowNode.Name == "Abbreviation") { newUom.abbreviation = DataRowNode.InnerText; } } } if (!String.IsNullOrEmpty(newUom.abbreviation)) { //itemlistId = new_item.listId; //Items[new_item.productKey] = new_item; quickbooksQueries.Uoms[newUom.abbreviation] = newUom; return(null); } else { return("Item no tiene List id " + newUom.name); } } } else { //Random rnd = new Random(); //Makes recursive insertion tries 5 times // Misssing loop of 5 :/ //client.nombre = client.nombre + " - " + rnd.ToString(); //string clientAdderResult = clientAdder.InsertClient(ref quickbooksQueries, ref client); //string msg = "No se puede agregar proveedor " + ; //string msg; msg = "Agregado " + vendor.nombre; return("No se puede agregar unit"); } } else { return("Quickbooks regresó una respuesta vacía al agregar " + item.descripcion); } } else { return("Se produjo un error al agregar insertar " + item.descripcion + ": " + quickbooksQueries.lastError); } return("ERror"); }