Exemplo n.º 1
0
 //Equates to a QuickBooks customer
 private long EnterBCOrderBillingAddress()
 {
     using (PreferredFloristDBDataContext pfDB = new PreferredFloristDBDataContext())
     {
         var bcOrderAddressObj = new Site_Manager.DataModel.BC_BillingAddress();
         bcOrderAddressObj.bc_order_id = bcOrder.id;
         bcOrderAddressObj.city = bcOrder.billing_address.city;
         bcOrderAddressObj.company = bcOrder.billing_address.company;
         bcOrderAddressObj.country = bcOrder.billing_address.country;
         bcOrderAddressObj.country_iso2 = bcOrder.billing_address.country_iso2;
         bcOrderAddressObj.email = bcOrder.billing_address.email;
         bcOrderAddressObj.first_name = bcOrder.billing_address.first_name;
         bcOrderAddressObj.last_name = bcOrder.billing_address.last_name;
         var validateField = new ValidateFieldLength();
         bcOrderAddressObj.phone = validateField.PhoneNumber(bcOrder.billing_address.phone);
         bcOrderAddressObj.state = bcOrder.billing_address.state;
         bcOrderAddressObj.street_1 = bcOrder.billing_address.street_1;
         bcOrderAddressObj.street_2 = bcOrder.billing_address.street_2;
         bcOrderAddressObj.zip = bcOrder.billing_address.zip;
         if (null != bcOrder.total_tax && bcOrder.total_tax > 0)
         {
             bcOrderAddressObj.IsTaxable = true;
         }
         else
         {
             bcOrderAddressObj.IsTaxable = false;
         }
         var GetAccountNumber = new GetNextIDNumber();
         bcOrderAddressObj.PF_accountNumber = GetAccountNumber.GetCustomerNumber();
         pfDB.BC_BillingAddresses.InsertOnSubmit(bcOrderAddressObj);
         pfDB.SubmitChanges();
         return (long)bcOrderAddressObj.PF_accountNumber;
     }
 }
Exemplo n.º 2
0
 private Boolean EnterBCOrder(string storeName)
 {
     bool orderHasCoupons = false;
     long result = CheckForExistingBCOrder(storeName);
     if (result == 0)
     {
         using (PreferredFloristDBDataContext pfDB = new PreferredFloristDBDataContext())
         {
             var bcOrderObj = new Site_Manager.DataModel.BC_Order();
             bcOrderObj.bc_store_name = storeName;
             bcOrderObj.base_handling_cost = bcOrder.base_handling_cost;
             bcOrderObj.base_shipping_cost = bcOrder.base_shipping_cost;
             bcOrderObj.base_wrapping_cost = bcOrder.base_wrapping_cost;
             bcOrderObj.coupon_discount = bcOrder.coupon_discount;
             if (bcOrder.coupon_discount > 0) { orderHasCoupons = true; };
             bcOrderObj.currency_code = bcOrder.currency_code;
             bcOrderObj.currency_exchange_rate = bcOrder.currency_exchange_rate;
             bcOrderObj.currency_id = bcOrder.currency_id;
             bcOrderObj.customer_id = bcOrder.customer_id;
             var getPFOrderNumber = new GetNextIDNumber();
             bcOrderObj.pfOrderID = getPFOrderNumber.GetPFOrderNumber();
             pfOrderID = (long)bcOrderObj.pfOrderID;
             bcOrderObj.customer_message = bcOrder.customer_message;
             var joshBD = Convert.ToDateTime("02-16-1983");
             bcOrderObj.Date_Created = bcOrder.Date_Created < joshBD ? joshBD : bcOrder.Date_Created;
             bcOrderObj.Date_Modified = bcOrder.Date_Modified < joshBD ? joshBD : bcOrder.Date_Modified;
             bcOrderObj.Date_Shipped = bcOrder.Date_Shipped < joshBD ? joshBD : bcOrder.Date_Shipped;
             bcOrderObj.requested_delivery_date = FindDeliveryDate(bcOrder.customer_message);
             bcOrderObj.default_currency_code = bcOrder.default_currency_code;
             bcOrderObj.default_currency_id = bcOrder.default_currency_id;
             bcOrderObj.discount_amount = bcOrder.discount_amount;
             bcOrderObj.geoip_country = bcOrder.geoip_country;
             bcOrderObj.geoip_country_iso2 = bcOrder.geoip_country_iso2;
             bcOrderObj.gift_certificate_amount = bcOrder.gift_certificate_amount;
             bcOrderObj.handling_cost_ex_tax = bcOrder.handling_cost_ex_tax;
             bcOrderObj.handling_cost_inc_tax = bcOrder.handling_cost_inc_tax;
             bcOrderObj.handling_cost_tax = bcOrder.handling_cost_tax;
             bcOrderObj.handling_cost_tax_class_id = bcOrder.handling_cost_tax_class_id;
             bcOrderObj.id = bcOrder.id;
             bcOrderObj.ip_address = bcOrder.ip_address;
             bcOrderObj.is_deleted = bcOrder.is_deleted;
             bcOrderObj.items_shipped = bcOrder.items_shipped;
             bcOrderObj.items_total = bcOrder.items_total;
             bcOrderObj.order_is_digital = bcOrder.order_is_digital;
             bcOrderObj.payment_method = bcOrder.payment_method;
             bcOrderObj.payment_provider_id = bcOrder.payment_provider_id;
             bcOrderObj.payment_status = bcOrder.payment_status;
             bcOrderObj.refunded_amount = bcOrder.refunded_amount;
             bcOrderObj.shipping_address_count = bcOrder.shipping_address_count;
             bcOrderObj.shipping_cost_ex_tax = bcOrder.shipping_cost_ex_tax;
             bcOrderObj.shipping_cost_inc_tax = bcOrder.shipping_cost_inc_tax;
             bcOrderObj.shipping_cost_tax = bcOrder.shipping_cost_tax;
             bcOrderObj.shipping_cost_tax_class_id = bcOrder.shipping_cost_tax_class_id;
             bcOrderObj.staff_notes = bcOrder.staff_notes;
             /*  0 Incomplete
              *  1 Pending
              *  2 Shipped
              *  3 Partially Shipped
              *  4 Refunded
              *  5 Cancelled
              *  6 Declined
              *  7 Awaiting Payment
              *  8 Awaiting Pickup
              *  9 Awaiting Shipment
              *  10 Completed
              *  11 Awaiting Fulfillment
              *  12 Manual Verification Required
              */
             bcOrderObj.status = bcOrder.status;
             bcOrderObj.status_id = bcOrder.status_id;
             bcOrderObj.store_credit_amount = bcOrder.store_credit_amount;
             bcOrderObj.subtotal_ex_tax = bcOrder.subtotal_ex_tax;
             bcOrderObj.subtotal_inc_tax = bcOrder.subtotal_inc_tax;
             bcOrderObj.subtotal_tax = bcOrder.subtotal_tax;
             bcOrderObj.total_ex_tax = bcOrder.total_inc_tax - bcOrder.total_tax;
             bcOrderObj.total_inc_tax = bcOrder.total_inc_tax;
             bcOrderObj.total_tax = bcOrder.total_tax;
             bcOrderObj.wrapping_cost_ex_tax = bcOrder.wrapping_cost_ex_tax;
             bcOrderObj.wrapping_cost_inc_tax = bcOrder.wrapping_cost_inc_tax;
             bcOrderObj.wrapping_cost_tax = bcOrder.wrapping_cost_tax;
             bcOrderObj.wrapping_cost_tax_class_id = bcOrder.wrapping_cost_tax_class_id;
             decimal orderTotal = bcOrder.total_inc_tax;
             bcOrderObj.merchant_fee = orderTotal * .03M;
             pfDB.BC_Orders.InsertOnSubmit(bcOrderObj);
             pfDB.SubmitChanges();
             var orderListObj = (from e1 in pfDB.BC_OrderLists where e1.bc_order_id == bcOrder.id && e1.bc_store_name == storeName select e1).SingleOrDefault();
             orderListObj.requested_delivery_date = bcOrderObj.requested_delivery_date;
             pfDB.SubmitChanges();
         }
     }
     return orderHasCoupons;
 }
        public QBRequest DoInvoiceAdd(QBRequest wqObject)
        {
            bool sessionBegun = false;
            bool connectionOpen = false;

            //Create the session Manager object
            var sessionManager = new Interop.QBFC11.QBSessionManager();

                    try
                    {
                        IMsgSetRequest requestMsgSet = sessionManager.CreateMsgSetRequest("US", wqObject.QBVersion, 0);  //originally was 7 qbxml version supported # 1.1 March 2002 # 2.0 November 2002 # 2.1 June 2003 # 3.0 November 2003 # 4.0 November 2004 # 4.1 June 2005 # 5.0 November 2005 # 6.0 October 2006
                        requestMsgSet.Attributes.OnError = ENRqOnError.roeContinue;
                        try
                        {
                            using (var db = new PreferredFloristDBDataContext())
                            {
                                customer = db.BC_BillingAddresses.FirstOrDefault(p => p.PF_accountNumber == wqObject.CustomerID);
                            }
                        }
                        catch (Exception ex)
                        {
                            CatchHandler ch = new CatchHandler();
                            ch.CaptureError(ex);
                        }
                        BuildInvoiceAddRq(requestMsgSet, customer, wqObject);

                        //Connect to QuickBooks and begin a session
                        sessionManager.OpenConnection("", "Site Manager");
                        connectionOpen = true;
                        try { sessionManager.BeginSession("", ENOpenMode.omMultiUser); }
                        catch { sessionManager.BeginSession("", ENOpenMode.omSingleUser); }
                        sessionBegun = true;

                        //Send the request and get the response from QuickBooks
                        IMsgSetResponse responseMsgSet = sessionManager.DoRequests(requestMsgSet);

                        //End the session and close the connection to QuickBooks
                        sessionManager.EndSession();
                        sessionBegun = false;
                        sessionManager.CloseConnection();
                        connectionOpen = false;

                        WalkInvoiceAddRs(responseMsgSet);

                    }
                    catch (Exception ex)
                    {
                        if (sessionBegun)
                        {
                            sessionManager.EndSession();

                        }
                        if (connectionOpen)
                        {
                            sessionManager.CloseConnection();
                        }
                        qbTranasctionResponse = 99;
                        qbTransactionResponseDetail = String.Format("AddInvoiceInQuickBooks failed. {0} {1}", ex.InnerException.Message, qbTransactionResponseDetail);
                        CatchHandler ch = new CatchHandler();
                        ch.CaptureError(ex);

                    }
                    wqObject.QBListID = qbListIDforThisTransaction;
                    wqObject.Status = qbTranasctionResponse;
                    wqObject.StatusMessage = qbTransactionResponseDetail;
                    return wqObject;
        }
Exemplo n.º 4
0
        private long CheckForExistingBCOrder(string storeName)
        {
            using (var pfDB = new PreferredFloristDBDataContext())
            {
                var orderObj = from pi in pfDB.BC_Orders
                               where pi.id == bcOrder.id &&
                                     pi.bc_store_name == storeName
                              select pi;

                if (orderObj == null)
                {
                    return 0;
                }
                else
                {
                    return Convert.ToInt64(orderObj.Count(p => p.bc_store_name == storeName));
                }
            }
        }
        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");
                            }
                        }
                }
            }
        }