Esempio n. 1
0
        private void BuildInvoiceAddRq(IMsgSetRequest requestMsgSet)
        {
            IInvoiceAdd invoiceAddRq = requestMsgSet.AppendInvoiceAddRq();

            invoiceAddRq.CustomerRef.FullName.SetValue("City");
            invoiceAddRq.Other.SetValue("12345");
            invoiceAddRq.TxnDate.SetValue(DateTime.Now);

            IORInvoiceLineAdd oRInvoiceLineAddList     = invoiceAddRq.ORInvoiceLineAddList.Append();
            string            orInvoiceListElementType = "InvoiceLineAdd";

            if (orInvoiceListElementType == "InvoiceLineAdd")
            {
                // oRInvoiceLineAddList.InvoiceLineAdd.ItemRef.FullName.SetValue("Storage");
                oRInvoiceLineAddList.InvoiceLineAdd.Desc.SetValue("January Storage");
                // oRInvoiceLineAddList.InvoiceLineAdd.Quantity.SetValue(2);
                // oRInvoiceLineAddList.InvoiceLineAdd.Amount.SetValue(9.99);
                // oRInvoiceLineAddList.InvoiceLineAdd.UnitOfMeasure.SetValue("each");
                //  oRInvoiceLineAddList.InvoiceLineAdd.ORRatePriceLevel.Rate.SetValue(9.99);
            }

            // Add blank line
            var invLine3 = invoiceAddRq.ORInvoiceLineAddList.Append();
            var line3    = invLine3.InvoiceLineAdd;

            line3.Desc.SetEmpty();



            IORInvoiceLineAdd oRInvoiceLineAddList2 = invoiceAddRq.ORInvoiceLineAddList.Append();
            var invoiceLineAdd2 = oRInvoiceLineAddList2.InvoiceLineAdd;

            if (orInvoiceListElementType == "InvoiceLineAdd")
            {
                invoiceLineAdd2.ItemRef.FullName.SetValue("Storage");
                invoiceLineAdd2.Desc.SetValue("Test Transaction Item");
                invoiceLineAdd2.Quantity.SetValue(2);
                // oRInvoiceLineAddList.InvoiceLineAdd.Amount.SetValue(9.99);
                // oRInvoiceLineAddList.InvoiceLineAdd.UnitOfMeasure.SetValue("each");
                invoiceLineAdd2.ORRatePriceLevel.Rate.SetValue(9.99);
            }
            //invoiceAddRq.IncludeRetElementList.Add("ab");



            Console.WriteLine(requestMsgSet.ToXMLString());
        }
Esempio n. 2
0
        protected override void Action(QBSessionManager sessionManager, IMsgSetRequest request)
        {
            // Add the request to the message set request object
            IInvoiceAdd invoiceAdd = request.AppendInvoiceAddRq();

            invoiceAdd.CustomerRef.FullName.SetValue(Invoice.CustomerName);

            foreach (var item in Invoice.Items)
            {
                IInvoiceLineAdd invoiceLineAdd = invoiceAdd.ORInvoiceLineAddList.Append().InvoiceLineAdd;
                invoiceLineAdd.ItemRef.FullName.SetValue(item.ItemName);
                invoiceLineAdd.Desc.SetValue(item.Description);
                var price = (double)item.Price;
                invoiceLineAdd.ORRatePriceLevel.Rate.SetValue(price);
                invoiceLineAdd.Quantity.SetValue(Convert.ToDouble(1));
                invoiceLineAdd.Amount.SetValue(price);
            }
            var       responseMsgSet = sessionManager.DoRequests(request);
            IResponse response       = responseMsgSet.ResponseList.GetAt(0);

            StatusCode = response.StatusCode;
        }
        void BuildInvoiceAddRq(IMsgSetRequest requestMsgSet, Site_Manager.DataModel.BC_BillingAddress customer, QBRequest wqObject)
        {
            IInvoiceAdd InvoiceAddRq = requestMsgSet.AppendInvoiceAddRq();
            var invoice = new Site_Manager.DataModel.BC_Order();
            using (PreferredFloristDBDataContext pfDB = new PreferredFloristDBDataContext())
            {
                invoice = pfDB.BC_Orders.FirstOrDefault(p => p.pfOrderID == wqObject.InvoiceNumber);
            }
            InvoiceAddRq.defMacro.SetValue("1234");
            //Set field value for ListID
            InvoiceAddRq.CustomerRef.ListID.SetValue(wqObject.QBListID);
            //Set field value for FullName
            InvoiceAddRq.ARAccountRef.FullName.SetValue("Accounts Receivable");
            InvoiceAddRq.ClassRef.FullName.SetValue(String.Format("{0}:Orders",wqObject.QBClass));
            //Set field value for FullName
            InvoiceAddRq.TemplateRef.FullName.SetValue("PF Invoice Template");
            //Set field value for TxnDate   DateTime.Parse("12/15/2007")
            if ((invoice.Date_Created == null))
                InvoiceAddRq.TxnDate.SetValue(Convert.ToDateTime(System.DateTime.Now.ToShortDateString()));
            else
                InvoiceAddRq.TxnDate.SetValue(Convert.ToDateTime(invoice.Date_Created.ToString()));
               //Set field value for RefNumber
            InvoiceAddRq.RefNumber.SetValue(wqObject.InvoiceNumber.ToString());
            InvoiceAddRq.RefNumber.SetValue(String.Format("{0}-{1}", wqObject.SiteID, wqObject.BC_OrderID));
            //Set field value for Addr1
            InvoiceAddRq.BillAddress.Addr1.SetValue(String.Format("{0} {1}", customer.first_name, customer.last_name));
            //Set field value for Addr2
            InvoiceAddRq.BillAddress.Addr2.SetValue(customer.street_1);
            //Set field value for City
            InvoiceAddRq.BillAddress.City.SetValue(customer.city);
            //Set field value for State
            InvoiceAddRq.BillAddress.State.SetValue(customer.state);
            //Set field value for PostalCode
            InvoiceAddRq.BillAddress.PostalCode.SetValue(customer.zip);
            //Set field value for Country
            InvoiceAddRq.BillAddress.Country.SetValue(customer.country);
            InvoiceAddRq.IsPending.SetValue(false);
            //Set field value for PONumber
            InvoiceAddRq.PONumber.SetValue(String.Empty);
            //Set field value for FullName
            InvoiceAddRq.TermsRef.FullName.SetValue("Due on receipt");
             //Set field value for ShipDate DateTime.Parse("12/15/2007")
            InvoiceAddRq.ShipDate.SetValue((invoice.Date_Created == null) ? Convert.ToDateTime(System.DateTime.Now.ToShortDateString()) : Convert.ToDateTime(invoice.Date_Created.ToString()));
            ////Set field value for ListID
            //InvoiceAddRq.ShipMethodRef.ListID.SetValue("200000-1011023419");
            //Set field value for FullName
            //InvoiceAddRq.ShipMethodRef.FullName.SetValue("ab");
            //Set field value for FullName
            InvoiceAddRq.ItemSalesTaxRef.FullName.SetValue("In State");
            //Set field value for FullName
            InvoiceAddRq.CustomerMsgRef.FullName.SetValue("Thank you for shopping at preferredflorist.com");
            //Set field value for IsToBePrinted
            InvoiceAddRq.IsToBePrinted.SetValue(false);
            //Set field value for IsToBeEmailed
            //InvoiceAddRq.IsToBeEmailed.SetValue(isValid);
            InvoiceAddRq.IsToBeEmailed.SetValue(false);
            //InvoiceAddRq.FOB.SetValue(invoice.CustomerJobNumber);
            //InvoiceAddRq.Other.SetValue(invoice.WorkOrderNumber.ToString());

            using (var db = new PreferredFloristDBDataContext())
            {
                int countOfInvolis = 0;
                var bagOfInvolis = from pi in db.BC_OrderLineItems
                                   where pi.PFOrderID == wqObject.InvoiceNumber
                                   select pi;
                countOfInvolis = bagOfInvolis.Count();
                if (countOfInvolis > 0)
                {
                    foreach (Site_Manager.DataModel.BC_OrderLineItem involi in bagOfInvolis)
                    {
                        IORInvoiceLineAdd ORInvoiceLineAddListElement1 = InvoiceAddRq.ORInvoiceLineAddList.Append();
                        string ORInvoiceLineAddListElementType2 = "InvoiceLineAdd";
                        if (ORInvoiceLineAddListElementType2 == "InvoiceLineAdd")
                        {
                            ORInvoiceLineAddListElement1.InvoiceLineAdd.ItemRef.FullName.SetValue("Product");

                            //Get the value of the card sentiment, card signature, verse, ribbon etc.
                            var bagOfProductOptions = from pi in db.BC_OrderProductOptions
                                                      where pi.PF_Line_Item_ID == involi.pf_line_item_id
                                                      orderby pi.option_id ascending
                                                      select pi;
                            var prodOptsText = new StringBuilder();
                            foreach (Site_Manager.DataModel.BC_OrderProductOption oPo in bagOfProductOptions)
                            {
                                prodOptsText.Append(String.Format("{0}:\r\n", oPo.display_name));
                                prodOptsText.Append(String.Format("{0}:\r\n\r\n", oPo.value));
                            }
                            //Set field value for Desc
                            ORInvoiceLineAddListElement1.InvoiceLineAdd.Desc.SetValue(String.Format("{0}   {1}\r\n\r\n{2}\r\n\r\n", involi.sku, involi.name, prodOptsText));
                            //Set field value for Quantity
                            ORInvoiceLineAddListElement1.InvoiceLineAdd.Quantity.SetValue(Convert.ToInt32(involi.quantity));

                            ORInvoiceLineAddListElement1.InvoiceLineAdd.ORRatePriceLevel.Rate.SetValue(Convert.ToDouble(involi.price_ex_tax));
                            if (null == customer.IsTaxable || customer.IsTaxable == false)
                            {
                                ORInvoiceLineAddListElement1.InvoiceLineAdd.SalesTaxCodeRef.FullName.SetValue("Non");
                            }
                            else
                            {
                                ORInvoiceLineAddListElement1.InvoiceLineAdd.SalesTaxCodeRef.FullName.SetValue("Tax");
                            }
                            ORInvoiceLineAddListElement1.InvoiceLineAdd.Other1.SetValue(involi.sku);

                        }
                    }

                    //Add order coupons if there are any
                    if (invoice.coupon_discount > 0)
                    {
                        int countOfCoupons = 0;
                        var bagOfCoupons = from pi in db.BC_OrderCoupons
                                           where pi.pf_Order_ID == wqObject.InvoiceNumber
                                           select pi;
                        countOfCoupons = bagOfCoupons.Count();
                        if (countOfCoupons > 0)
                        {
                            foreach (Site_Manager.DataModel.BC_OrderCoupon couponLi in bagOfCoupons)
                            {
                                IORInvoiceLineAdd ORInvoiceLineAddListElement1 = InvoiceAddRq.ORInvoiceLineAddList.Append();
                                string ORInvoiceLineAddListElementType2 = "InvoiceLineAdd";
                                if (ORInvoiceLineAddListElementType2 == "InvoiceLineAdd")
                                {
                                    ORInvoiceLineAddListElement1.InvoiceLineAdd.ItemRef.FullName.SetValue("Coupon");
                                    //Set field value for Desc
                                    ORInvoiceLineAddListElement1.InvoiceLineAdd.Desc.SetValue(couponLi.code);
                                    //Set field value for Quantity
                                    //ORInvoiceLineAddListElement1.InvoiceLineAdd.Quantity.SetValue(1); //Cannot set quantity for item of this type

                                    ORInvoiceLineAddListElement1.InvoiceLineAdd.ORRatePriceLevel.Rate.SetValue(Convert.ToDouble(invoice.coupon_discount));
                                    if (null == customer.IsTaxable || customer.IsTaxable == false)
                                    {
                                        ORInvoiceLineAddListElement1.InvoiceLineAdd.SalesTaxCodeRef.FullName.SetValue("Non");
                                    }
                                    else
                                    {
                                        ORInvoiceLineAddListElement1.InvoiceLineAdd.SalesTaxCodeRef.FullName.SetValue("Tax");
                                    }
                                    ORInvoiceLineAddListElement1.InvoiceLineAdd.Other1.SetValue(couponLi.code);
                                }
                            }
                        }
                    }

                        //Add Service Fee. Note: in some of the earlier stores, the handling fee was billed as shipping

                        if (invoice.handling_cost_ex_tax > 0)
                        {
                            IORInvoiceLineAdd ORInvoiceLineAddListElement1 = InvoiceAddRq.ORInvoiceLineAddList.Append();
                            ORInvoiceLineAddListElement1.InvoiceLineAdd.ItemRef.FullName.SetValue("Service Fee");
                            //Set field value for Desc
                            ORInvoiceLineAddListElement1.InvoiceLineAdd.Desc.SetValue("Service Fee");
                            //Set field value for Quantity
                            ORInvoiceLineAddListElement1.InvoiceLineAdd.Quantity.SetValue(1);
                            //ORInvoiceLineAddListElement1.InvoiceLineAdd.Other1.SetValue(dr["PartNumber"].ToString());

                            ORInvoiceLineAddListElement1.InvoiceLineAdd.Amount.SetValue(Convert.ToDouble(invoice.handling_cost_ex_tax));
                            if (invoice.handling_cost_tax > 0)
                            {
                                ORInvoiceLineAddListElement1.InvoiceLineAdd.SalesTaxCodeRef.FullName.SetValue("Tax");
                            }
                            else
                            {
                                ORInvoiceLineAddListElement1.InvoiceLineAdd.SalesTaxCodeRef.FullName.SetValue("Non");                            }
                        }

                        if (invoice.shipping_cost_ex_tax > 0) // Note: in some of the earlier stores, the handling fee was billed as shipping
                        {
                            IORInvoiceLineAdd ORInvoiceLineAddListElement1 = InvoiceAddRq.ORInvoiceLineAddList.Append();
                            ORInvoiceLineAddListElement1.InvoiceLineAdd.ItemRef.FullName.SetValue("Shipping");
                            //Set field value for Desc
                            ORInvoiceLineAddListElement1.InvoiceLineAdd.Desc.SetValue("Shipping");
                            //Set field value for Quantity
                            ORInvoiceLineAddListElement1.InvoiceLineAdd.Quantity.SetValue(1);

                            ORInvoiceLineAddListElement1.InvoiceLineAdd.Amount.SetValue(Convert.ToDouble(invoice.shipping_cost_ex_tax));
                            if (invoice.shipping_cost_tax > 0)
                            {
                                ORInvoiceLineAddListElement1.InvoiceLineAdd.SalesTaxCodeRef.FullName.SetValue("Tax");
                            }
                            else
                            {
                                ORInvoiceLineAddListElement1.InvoiceLineAdd.SalesTaxCodeRef.FullName.SetValue("Non"); //////////////////HEEEEEEEEEEEEEEY??????????????????
                            }
                        }

                        //Add Order Discounts
                        if (!(String.IsNullOrEmpty(invoice.discount_amount.ToString())) && invoice.discount_amount > 0)
                        {
                            Decimal aCredit = invoice.discount_amount > 0 ? (decimal)invoice.discount_amount : 0;
                            IORInvoiceLineAdd ORInvoiceLineAddListElement1 = InvoiceAddRq.ORInvoiceLineAddList.Append();
                            ORInvoiceLineAddListElement1.InvoiceLineAdd.ItemRef.FullName.SetValue("Discount");
                            //Set field value for Desc
                            ORInvoiceLineAddListElement1.InvoiceLineAdd.Desc.SetValue("Discount");

                            ORInvoiceLineAddListElement1.InvoiceLineAdd.Amount.SetValue(Convert.ToDouble(aCredit));
                            if (null == customer.IsTaxable || customer.IsTaxable == false)
                            {
                                ORInvoiceLineAddListElement1.InvoiceLineAdd.SalesTaxCodeRef.FullName.SetValue("Non");
                            }
                            else
                            {
                                ORInvoiceLineAddListElement1.InvoiceLineAdd.SalesTaxCodeRef.FullName.SetValue("Tax");
                            }
                        }
                }
            }
        }