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);
        }