Exemplo n.º 1
0
        public QuotationMaster ConverToQuote()
        {
            QuotationMaster quote = new QuotationMaster();

            quote.quoteNo         = this.QuoteNo;
            quote.quoteId         = this.QuoteId;
            quote.quoteToErpId    = this.QuoteToErpId != null? this.QuoteToErpId: "";
            quote.quoteToRowId    = this.QuoteToRowId;
            quote.siebelRBU       = this.SiebelRBU;
            quote.quoteDate       = this.QuoteDate;
            quote.expiredDate     = TimeHelper.ConvertToSystemTime(this.ExpiredDate, this.Region);
            quote.createdBy       = this.CreatedBy;
            quote.createdDate     = this.CreatedDate;
            quote.LastUpdatedBy   = this.LastUpdatedBy;
            quote.LastUpdatedDate = this.LastUpdatedDate;
            quote.deliveryDate    = this.DeliveryDate;
            quote.reqDate         = this.ReqDate;
            quote.DOCSTATUS       = this.DOCSTATUS;
            quote.PODate          = this.PoDate;
            quote.Revision_Number = this.RevisionNumber;
            quote.Active          = this.Active = true;
            quote.tax             = this.Tax;
            quote.isRepeatedOrder = this.IsRepeatedOrder;
            quote.PO_NO           = string.IsNullOrEmpty(this.PoNo) ? "" : this.PoNo.Trim().Replace("'", "''");
            quote.DIST_CHAN       = this.DistChan;
            quote.DIVISION        = this.Division;
            quote.currency        = this.Currency;
            quote.org             = this.Org;
            quote.SALESOFFICE     = this.SalesOffice;
            quote.SALESGROUP      = this.SalesGroup;
            quote.customId        = string.IsNullOrEmpty(this.Description) ? "" : this.Description.Trim().Replace("'", "''");
            quote.salesRowId      = string.IsNullOrEmpty(this.SalesRowId) ? "" : this.SalesRowId.Trim().Replace("'", "''");
            quote.salesEmail      = this.InSideSales;
            quote.quoteToName     = string.IsNullOrEmpty(this.QuoteToName) ? "" : this.QuoteToName.Trim().Replace("'", "''");
            quote.relatedInfo     = string.IsNullOrEmpty(this.ApprovalReason) ? "" : this.ApprovalReason.Trim().Replace("'", "''");
            quote.quoteNote       = string.IsNullOrEmpty(this.QuoteNote) ? "" : this.QuoteNote.Trim().Replace("'", "''");
            //quote.QuotationExtensionNew.Warranty = string.IsNullOrEmpty(this.Warranty) ? "" : this.Warranty.Trim().Replace("'", "''");
            quote.freight         = this.Freight;
            quote.INCO1           = this.Inco1;
            quote.INCO2           = this.Inco2;
            quote.OriginalQuoteID = this.OriginalQuoteID;
            quote.paymentTerm     = this.PaymentTerm;
            //quote.INCO1 = Advantech.Myadvantech.DataAccess.DataCore.MyAdvantech.SAPCompanyHelper.GetSAPDIMCompanyByID(this.QuoteToErpId).FirstOrDefault();
            quote.Remark = string.IsNullOrEmpty(this.Remark) ? "" : this.Remark.Trim().Replace("'", "''");

            var quoteExten = new QuotationExtensionNew();

            quoteExten.QuoteID          = this.QuoteId;
            quoteExten.GeneralRate      = 0.24m;
            quoteExten.Warranty         = this.Warranty;
            quoteExten.BelowGP          = false;
            quote.QuotationExtensionNew = quoteExten;

            var quotePartners = new List <EQPARTNER>();

            if (this.SoldToPartner != null)
            {
                quotePartners.Add(this.SoldToPartner);
            }
            if (this.ShipToPartner != null)
            {
                quotePartners.Add(this.ShipToPartner);
            }
            if (this.BillToPartner != null)
            {
                quotePartners.Add(this.BillToPartner);
            }
            if (this.EndCustomer != null && !string.IsNullOrEmpty(this.EndCustomer.ERPID))  //Alex 20180712: For ACN, only endcutomer with epr id will be added to eqparters.
            {
                quotePartners.Add(this.EndCustomer);
            }

            foreach (var item in this.ExtraTermsAndConditionOptions)
            {
                EQPARTNER e = new EQPARTNER();
                if (item.Selected == true)
                {
                    e.QUOTEID = this.QuoteId;
                    e.NAME    = item.Name;
                    e.TYPE    = item.Type;
                    quotePartners.Add(e);
                }
            }

            if (this.SalesRepresentatives != null)
            {
                int count = 1;
                foreach (var sales in this.SalesRepresentatives)
                {
                    EQPARTNER partner_sales = new EQPARTNER();
                    partner_sales.QUOTEID = this.QuoteId;
                    partner_sales.ERPID   = sales.SalesCode;
                    partner_sales.NAME    = sales.Email;
                    if (count == 1)
                    {
                        partner_sales.TYPE = "E";
                    }
                    if (count == 2)
                    {
                        partner_sales.TYPE = "E2";
                    }
                    if (count == 3)
                    {
                        partner_sales.TYPE = "E3";
                    }

                    quotePartners.Add(partner_sales);
                    count += 1;
                }
            }
            quote.QuotationPartner = quotePartners;
            quote.QuotationDetail  = this.QuoteItems
                                     .Select(x => new QuotationDetail()
            {
                quoteId                   = x.QuoteId,
                line_No                   = x.LineNo,
                partNo                    = x.PartNo,
                description               = x.Description,
                listPrice                 = x.ListPrice,
                unitPrice                 = x.UnitPrice,
                newUnitPrice              = x.QuotingPrice,
                itp                       = x.Itp,
                newItp                    = x.NewItp,
                qty                       = x.Qty,
                sprNo                     = x.SprNo,
                HigherLevel               = x.HigherLevel,
                DMF_Flag                  = x.DMF_Flag,
                ItemType                  = x.ItemType,
                deliveryPlant             = x.DeliveryPlant,
                NCNR                      = Convert.ToInt32(x.NCNR),
                RecyclingFee              = x.RecyclingFee,
                category                  = string.IsNullOrEmpty(x.Category) ? "" : x.Category.Trim().Replace("'", "''"),
                classABC                  = string.IsNullOrEmpty(x.ClassABC) ? "" : x.ClassABC.Trim().Replace("'", "''"),
                rohs                      = x.Rohs,
                ewFlag                    = x.EWFlag,
                reqDate                   = x.RequiredDate,
                dueDate                   = x.DueDate,
                satisfyFlag               = x.SatisfyFlag,
                canBeConfirmed            = x.CanBeConfirmed,
                custMaterial              = x.CusMaterial == null?"": x.CusMaterial,
                inventory                 = x.Inventory,
                modelNo                   = string.IsNullOrEmpty(x.ModelNo) ? "" : x.ModelNo.Trim().Replace("'", "''"),
                VirtualPartNo             = x.VirtualPartNo,
                RECFIGID                  = string.IsNullOrEmpty(x.Recfigid) ? "" : x.Recfigid.Trim().Replace("'", "''"),
                SequenceNo                = x.SequenceNo,
                OriginalSalesDiscountRate = x.SalesDiscountRate,
            })
                                     .ToList();

            if (!string.IsNullOrEmpty(this.OptyId))
            {
                optyQuote oppty = new optyQuote();
                oppty.optyId           = this.OptyId;
                oppty.quoteId          = this.QuoteId;
                oppty.optyName         = this.OptyName ?? "";
                oppty.optyStage        = this.OptyStage ?? "";
                oppty.Opty_Owner_Email = AppContext.UserEmail ?? "";
                quote.QuotationOpty    = new optyQuote();
                quote.QuotationOpty    = oppty;
            }

            if (this.QuoteApproval.QuoteApprovalList != null)
            {
                quote.WaitingApprovals = this.QuoteApproval.QuoteApprovalList.ToList();
            }
            return(quote);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Use eStore B+B function to calcaulate freight
        /// </summary>
        /// <returns></returns>
        public static Tuple <bool, Response> CalculateBBFreightByQuotationDetail(EQPARTNER _Shipto, EQPARTNER _Billto, List <QuotationDetail> _QuoteDetails)
        {
            shippingrate target = new shippingrate();

            target.Timeout = 30000;
            //target.Url = "http://buy.advantech.com/services/shippingrate.asmx"; AUS eStore URL

            DataAccess.bbeStoreFreightAPI.Order order = new DataAccess.bbeStoreFreightAPI.Order();
            order.StoreId = "ABB";

            // Shipto settings
            Address shipto = new Address();

            if (_Shipto != null)
            {
                shipto.Countrycode = _Shipto.COUNTRY;
                shipto.Zipcode     = _Shipto.ZIPCODE;
                shipto.StateCode   = _Shipto.STATE;
                order.Shipto       = shipto;
            }

            // Bill to settings
            Address billto = new Address();

            if (_Billto != null)
            {
                billto.Countrycode = _Billto.COUNTRY;
                billto.Zipcode     = _Billto.ZIPCODE;
                billto.StateCode   = _Billto.STATE;
                order.Billto       = billto;
            }

            // Loose Items settings
            List <Item>            items      = new List <Item>();
            List <QuotationDetail> LooseItems = _QuoteDetails.Where(q => q.ItemType == (int)LineItemType.LooseItem).ToList();

            if (LooseItems.Count > 0)
            {
                foreach (QuotationDetail LooseItem in LooseItems)
                {
                    items.Add(new Item()
                    {
                        ProductID = LooseItem.partNo,
                        Qty       = (int)LooseItem.qty
                    });
                }
            }

            // System Items settings
            List <ConfigSystem>    systems     = new List <ConfigSystem>();
            List <QuotationDetail> ParentItems = _QuoteDetails.Where(q => q.ItemType == (int)LineItemType.BTOSParent).ToList();

            foreach (QuotationDetail ParentItem in ParentItems)
            {
                int          _sys1Qty = 1;
                ConfigSystem _sys1    = new ConfigSystem();
                _sys1.Qty       = (int)ParentItem.qty;
                _sys1.ProductID = ParentItem.partNo;
                _sys1Qty        = _sys1.Qty;

                List <QuotationDetail> ChildItems = _QuoteDetails.Where(q => q.ItemType == (int)LineItemType.BTOSChild && q.HigherLevel == ParentItem.line_No).ToList();
                List <Item>            _ds        = new List <Item>();
                foreach (QuotationDetail ChildItem in ChildItems)
                {
                    _ds.Add(new Item()
                    {
                        ProductID = ChildItem.partNo,
                        Qty       = (Int32)Math.Ceiling((double)(Convert.ToDouble(ChildItem.qty / (double)_sys1Qty)))
                    });
                }

                _sys1.Details = _ds.ToArray();
                systems.Add(_sys1);
            }
            order.Items   = items.ToArray();
            order.Systems = systems.ToArray();



            Response actual;

            actual = target.getShippingRate(order);
            if (actual != null && actual.Status == "1")
            {
                return(new Tuple <bool, Response>(true, actual));
            }
            else
            {
                return(new Tuple <bool, Response>(false, actual));
            }
        }