Example #1
0
        public async Task <data.InvoiceLine> Add(data.InvoiceContext db, InvoiceLineAdd add)
        {
            try
            {
                var newInvoiceLine = new data.InvoiceLine();
                newInvoiceLine.LineTotal   = add.LineTotal;
                newInvoiceLine.Notes       = add.Notes;
                newInvoiceLine.Product     = add.Product;
                newInvoiceLine.ProductCode = add.ProductCode;
                newInvoiceLine.Quantity    = add.Quantity;
                newInvoiceLine.SubTotal    = add.SubTotal;
                newInvoiceLine.TaxExempt   = add.TaxExempt;
                newInvoiceLine.TaxTotal    = add.TaxTotal;
                newInvoiceLine.UnitCost    = add.UnitCost;
                var invoiceLookup = await db.Invoices.FirstOrDefaultAsync(w => w.InvoiceId == add.InvoiceInvoiceId);

                if (invoiceLookup != null)
                {
                    newInvoiceLine.Invoice = invoiceLookup;
                }
                db.InvoiceLines.Add(newInvoiceLine);
                return(newInvoiceLine);
            }
            catch (Exception e)
            {
                LogFactory.GetLogger().Log(LogLevel.Error, e);
                return(null);
            }
        }
Example #2
0
        public InvoiceLineAdd GetInvoiceLineAdd()
        {
            var result = new InvoiceLineAdd();

            result.InvoiceLineId    = InvoiceLineView.InvoiceLineId;
            result.LineTotal        = InvoiceLineView.LineTotal;
            result.Notes            = InvoiceLineView.Notes;
            result.Product          = InvoiceLineView.Product;
            result.ProductCode      = InvoiceLineView.ProductCode;
            result.Quantity         = InvoiceLineView.Quantity;
            result.SubTotal         = InvoiceLineView.SubTotal;
            result.TaxExempt        = InvoiceLineView.TaxExempt;
            result.TaxTotal         = InvoiceLineView.TaxTotal;
            result.UnitCost         = InvoiceLineView.UnitCost;
            result.InvoiceInvoiceId = InvoiceLineView.InvoiceInvoiceId;
            return(result);
        }
Example #3
0
        // Add Transaction Code
        public async Task <InvoiceLineView> Add(InvoiceLineAdd add)
        {
            try
            {
                using (var db = new data.InvoiceContext())
                {
                    var result = await Add(db, add);

                    await db.SaveChangesAsync();

                    return((InvoiceLineView)result);
                }
            }
            catch (Exception e)
            {
                LogFactory.GetLogger().Log(LogLevel.Error, e);
                return(null);
            }
        }
Example #4
0
        public async Task <InvoiceLineView> InvoiceLineAdd(InvoiceLineAdd add)
        {
            try
            {
                string json = "";

                var client = new HttpClient();

                using (var ms = new MemoryStream())
                {
                    var serializer = new DataContractJsonSerializer(typeof(InvoiceLineAdd));
                    serializer.WriteObject(ms, add);
                    ms.Position = 0;
                    StreamReader sr = new StreamReader(ms);
                    json = sr.ReadToEnd();
                }

                var stream = await client.PostAsync("http://localhost:44443/api/invoiceLine", new StringContent(json, Encoding.UTF8, "application/json"));

                using (var ms = new MemoryStream())
                {
                    var serializer = new DataContractJsonSerializer(typeof(InvoiceLineView), new DataContractJsonSerializerSettings()
                    {
                        DateTimeFormat = new DateTimeFormat("yyyy-MM-dd'T'HH:mm:ss")
                    });
                    await stream.Content.CopyToAsync(ms);

                    ms.Position = 0;
                    var view = serializer.ReadObject(ms) as InvoiceLineView;
                    return(view);
                }
            }
            catch (Exception e)
            {
                LogFactory.GetLogger().Log(LogLevel.Error, e);
                return(null);
            }
        }
Example #5
0
        public QBXMLMsgsRs buildInvoiceAddRqXML(string customer, DateTime txnDate, string refNumber)
        {
            InvoiceAddRqType req = new InvoiceAddRqType();

            req.InvoiceAdd                      = new InvoiceAdd();
            req.InvoiceAdd.TemplateRef          = new TemplateRef();
            req.InvoiceAdd.TemplateRef.FullName = customer;
            req.InvoiceAdd.CustomerRef          = new CustomerRef();
            req.InvoiceAdd.CustomerRef.FullName = customer;
            req.InvoiceAdd.Other                = "tttt";

            if (txnDate != null)
            {
                req.InvoiceAdd.TxnDate = txnDate.ToString("yyyy-MM-dd");
            }
            if (!string.IsNullOrEmpty(refNumber))
            {
                req.InvoiceAdd.RefNumber = refNumber;
            }
            //string requestXML = "";

            ////if (!validateInput()) return null;

            ////GET ALL INPUT INTO XML
            //XmlDocument xmlDoc = new XmlDocument();
            //XmlElement qbXMLMsgsRq = buildRqEnvelope(xmlDoc, maxVersion);
            //qbXMLMsgsRq.SetAttribute("onError", "stopOnError");
            //XmlElement InvoiceAddRq = xmlDoc.CreateElement("InvoiceAddRq");
            //qbXMLMsgsRq.AppendChild(InvoiceAddRq);
            //XmlElement InvoiceAdd = xmlDoc.CreateElement("InvoiceAdd");
            //InvoiceAddRq.AppendChild(InvoiceAdd);

            //// CustomerRef -> FullName
            //if (comboBox_Customer.Text != "")
            //{
            //	XmlElement Element_CustomerRef = xmlDoc.CreateElement("CustomerRef");
            //	InvoiceAdd.AppendChild(Element_CustomerRef);
            //	XmlElement Element_CustomerRef_FullName = xmlDoc.CreateElement("FullName");
            //	Element_CustomerRef.AppendChild(Element_CustomerRef_FullName).InnerText = comboBox_Customer.Text;
            //}


            // RefNumber
            //if (textBox_RefNumber.Text != "")
            //{
            //	XmlElement Element_RefNumber = xmlDoc.CreateElement("RefNumber");
            //	InvoiceAdd.AppendChild(Element_RefNumber).InnerText = textBox_RefNumber.Text;
            //}

            // BillAddress

/*
 *                      if (label_BillTo.Text != "")
 *                      {
 *                              string[] BillAddress = label_BillTo.Text.Split('\n');
 *                              XmlElement Element_BillAddress = xmlDoc.CreateElement("BillAddress");
 *                              InvoiceAdd.AppendChild(Element_BillAddress);
 *                              for (int i = 0; i < BillAddress.Length; i++)
 *                              {
 *                                      if (BillAddress[i] != "" || BillAddress[i] != null)
 *                                      {
 *                                              XmlElement Element_Addr = xmlDoc.CreateElement("Addr" + (i + 1));
 *                                              Element_BillAddress.AppendChild(Element_Addr).InnerText = BillAddress[i];
 *                                      }
 *                              }
 *                      }
 *
 *                      // TermsRef -> FullName
 *                      bool termsAvailable = false;
 *                      if (comboBox_Terms.Text != "")
 *                      {
 *                              termsAvailable = true;
 *                              XmlElement Element_TermsRef = xmlDoc.CreateElement("TermsRef");
 *                              InvoiceAdd.AppendChild(Element_TermsRef);
 *                              XmlElement Element_TermsRef_FullName = xmlDoc.CreateElement("FullName");
 *                              Element_TermsRef.AppendChild(Element_TermsRef_FullName).InnerText = comboBox_Terms.Text;
 *                      }
 *
 *                      // DueDate
 *                      if (termsAvailable)
 *                      {
 *                              DateTime DT_DueDate = System.DateTime.Today;
 *                              double dueInDays = getDueInDays();
 *                              DT_DueDate = DT_TxnDate.AddDays(dueInDays);
 *                              string DueDate = getDateString(DT_DueDate);
 *                              XmlElement Element_DueDate = xmlDoc.CreateElement("DueDate");
 *                              InvoiceAdd.AppendChild(Element_DueDate).InnerText = DueDate;
 *                      }
 *
 *                      // CustomerMsgRef -> FullName
 *                      if (comboBox_CustomerMessage.Text != "")
 *                      {
 *                              XmlElement Element_CustomerMsgRef = xmlDoc.CreateElement("CustomerMsgRef");
 *                              InvoiceAdd.AppendChild(Element_CustomerMsgRef);
 *                              XmlElement Element_CustomerMsgRef_FullName = xmlDoc.CreateElement("FullName");
 *                              Element_CustomerMsgRef.AppendChild(Element_CustomerMsgRef_FullName).InnerText = comboBox_CustomerMessage.Text;
 *                      }
 *
 *                      // ExchangeRate
 *                      if (textBox_ExchangeRate.Text != "")
 *                      {
 *                              XmlElement Element_ExchangeRate = xmlDoc.CreateElement("ExchangeRate");
 *                              InvoiceAdd.AppendChild(Element_ExchangeRate).InnerText = textBox_ExchangeRate.Text;
 *                      }
 */
            //Line Items

            List <InvoiceLineAdd> lineItems = new List <InvoiceLineAdd>();

            InvoiceLineAdd line = new InvoiceLineAdd();

//			ItemRef
            line.ItemRef           = new ItemRef();
            line.ItemRef.FullName  = "Labor";
            line.Desc              = "Test";
            line.ClassRef          = new ClassRef();
            line.ClassRef.FullName = "Home Depot:Atlanta:Hard Surface";
            line.Amount            = "123456.78";
            line.IsTaxable         = "false";
            lineItems.Add(line);
            line                   = new InvoiceLineAdd();
            line.ItemRef           = new ItemRef();
            line.ItemRef.FullName  = "Back Charge";
            line.Desc              = "Smith James";
            line.ClassRef          = new ClassRef();
            line.ClassRef.FullName = "Home Depot:Atlanta:Hard Surface";
            line.Amount            = "-543.21";
            line.IsTaxable         = "false";
            lineItems.Add(line);
            req.InvoiceAdd.Items = lineItems.ToArray();;



            //XmlElement Element_InvoiceLineAdd;
            //for (int x = 1; x < 6; x++)
            //{
            //	Element_InvoiceLineAdd = xmlDoc.CreateElement("InvoiceLineAdd");
            //	InvoiceAdd.AppendChild(Element_InvoiceLineAdd);

            //	string[] lineItem = getLineItem(x);
            //	if (lineItem[0] != "")
            //	{
            //		XmlElement Element_InvoiceLineAdd_ItemRef = xmlDoc.CreateElement("ItemRef");
            //		Element_InvoiceLineAdd.AppendChild(Element_InvoiceLineAdd_ItemRef);
            //		XmlElement Element_InvoiceLineAdd_ItemRef_FullName = xmlDoc.CreateElement("FullName");
            //		Element_InvoiceLineAdd_ItemRef.AppendChild(Element_InvoiceLineAdd_ItemRef_FullName).InnerText = lineItem[0];
            //	}
            //	if (lineItem[1] != "")
            //	{
            //		XmlElement Element_InvoiceLineAdd_Desc = xmlDoc.CreateElement("Desc");
            //		Element_InvoiceLineAdd.AppendChild(Element_InvoiceLineAdd_Desc).InnerText = lineItem[1];
            //	}
            //	if (lineItem[2] != "")
            //	{
            //		XmlElement Element_InvoiceLineAdd_Quantity = xmlDoc.CreateElement("Quantity");
            //		Element_InvoiceLineAdd.AppendChild(Element_InvoiceLineAdd_Quantity).InnerText = lineItem[2];
            //	}
            //	if (lineItem[3] != "")
            //	{
            //		XmlElement Element_InvoiceLineAdd_Rate = xmlDoc.CreateElement("Rate");
            //		Element_InvoiceLineAdd.AppendChild(Element_InvoiceLineAdd_Rate).InnerText = lineItem[3];
            //	}
            //	if (lineItem[4] != "")
            //	{
            //		XmlElement Element_InvoiceLineAdd_Amount = xmlDoc.CreateElement("Amount");
            //		Element_InvoiceLineAdd.AppendChild(Element_InvoiceLineAdd_Amount).InnerText = lineItem[4];
            //	}
            //}


            //InvoiceAddRq.SetAttribute("requestID", "99");
            //requestXML = xmlDoc.OuterXml;

            //return requestXML;



            InvoiceAddRsType resp;
            QBXMLMsgsRs      r = this.Transmit(req, out resp);

            return(r);
        }