public ActionResult Save(OrderMasterFull vm)
 {
     int pk = OrderService.fnSaveOrder(vm);
     TempData["SaveResult"] = "Order Information updated at " + DateTime.Now;
     return RedirectToAction("Edit", new { id = pk });
 }
示例#2
0
        public static bool fnIsSDN(OrderMasterFull vm)
        {
            var filecontent = System.IO.File.ReadAllText(HttpContext.Current.Server.MapPath("~/Content/sdnlist.txt"));

            if (filecontent.Contains(vm.company))
            {
                return true;
            }

            if (!String.IsNullOrEmpty(vm.street) && filecontent.Contains(vm.street))
            {
                return true;
            }

            if (!String.IsNullOrEmpty(vm.attention) && filecontent.Contains(vm.attention))
            {
                return true;
            }

            return false;
        }
示例#3
0
        public static OrderMasterFull fnFillOrder(int id)
        {
            using (var db = new EF.CMCSQL03Entities())
            {
                OrderMasterFull o = new OrderMasterFull();
                var q = (from t in db.tblOrderMaster
                         where t.OrderID == id
                         select t).FirstOrDefault();

                o.itemscount = (from t in db.tblOrderItem where t.OrderID == id select t).Count();
                o.transcount = (from t in db.tblOrderTrans where t.OrderID == id select t).Count();

                var cl = db.tblClient.Find(q.ClientID);
                o.clientname = cl.ClientName;
                o.clientcode = cl.ClientCode;
                o.logofilename = cl.LogoFileName;

                // Fill lists buried in object
                o.ListOfSalesReps = fnListOfSalesReps(o.clientid);
                o.ListOfCountries = fnListOfCountries();
                o.ListOfEndUses = fnListOfEndUses(o.clientid);
                o.ListOfShipVias = fnListOfShipVias();
                o.ListOfBillingGroups = fnListOfBillingGroups(cl.ClientID);

                o.orderid = q.OrderID;
                o.clientid = q.ClientID;
                o.orderstatus = q.OrderStatus;
                o.customer = q.Customer;
                o.cmcorder = Convert.ToInt32(q.CMCOrder);
                o.weborderid = Convert.ToInt32(q.WebOrderID);
                o.cmclegacynumber = q.CMCLegacyNum;
                o.custordnum = q.CustOrdNum;
                o.custsapnum = q.CustSapNum;
                o.custrefnum = q.CustRefNum;
                o.ordertype = q.OrderType;
                o.orderdate = q.OrderDate;
                o.company = q.Company;
                o.street = q.Street; o.street2 = q.Street2; o.street3 = q.Street3; o.city = q.City; o.state = q.State; o.Zip = q.Zip;
                o.country = q.Country; o.attention = q.Attention; o.email = q.Email; o.salesrep = q.SalesRep; o.sales_email = q.SalesEmail;
                o.req = q.Req; o.reqphone = q.ReqPhone; o.reqfax = q.ReqFax; o.reqemail = q.ReqEmail; o.enduse = q.EndUse; o.shipvia = q.ShipVia;
                o.shipacct = q.ShipAcct; o.phone = q.Phone; o.source = q.Source; o.fax = q.Fax; o.tracking = q.Tracking; o.special = q.Special;
                o.specialinternal = q.SpecialInternal; o.lit = Convert.ToBoolean(q.Lit); o.region = q.Region; o.coa = Convert.ToBoolean(q.COA);
                o.tds = Convert.ToBoolean(q.TDS); o.cid = q.CID; o.custacct = q.CustAcct; o.acode = q.ACode;
                o.importfile = q.ImportFile;

                if (q.ImportDateLine.HasValue)
                {
                    o.importdateline = Convert.ToDateTime(q.ImportDateLine);
                }
                else
                {
                    o.importdateline = null;
                }

                o.timing = q.Timing; o.volume = q.Volume; o.samplerack = Convert.ToBoolean(q.SampleRack); o.cmcuser = q.CMCUser;
                o.customerreference = q.CustomerReference;
                o.totalorderweight = q.TotalOrderWeight;
                o.spstaxid = q.SPSTaxID; o.spscurrency = q.SPSCurrency; o.spsshippedwt = q.SPSShippedWt; o.spsfreightcost = q.SPSFreightCost;
                o.invoicecompany = q.InvoiceCompany; o.invoicetitle = q.InvoiceTitle; o.invoicefirstname = q.InvoiceFirstName; o.invoicelastname = q.InvoiceLastName;
                o.invoiceaddress1 = q.InvoiceAddress1; o.invoiceaddress2 = q.InvoiceAddress2; o.invoiceaddress3 = q.InvoiceAddress3; o.invoicecity = q.InvoiceCity;
                o.invoicestateprov = q.InvoiceStateProv; o.invoicepostalcode = q.InvoicePostalCode; o.invoicecountry = q.InvoiceCountry; o.invoicephone = q.InvoicePhone;
                o.custordertype = q.CustOrderType;

                o.custrequestdate = null;
                if (q.CustRequestDate.HasValue)
                { o.custrequestdate = q.CustRequestDate; }

                o.approvaldate = null;
                if (q.ApprovalDate.HasValue)
                { o.approvaldate = q.ApprovalDate; }

                o.requesteddeliverydate = null;
                if (q.RequestedDeliveryDate.HasValue)
                { o.requesteddeliverydate = q.RequestedDeliveryDate; }

                o.custtotalitems = Convert.ToInt32(q.CustTotalItems);
                o.custrequestedcarrier = q.CustRequestedCarrier;
                o.legacyid = Convert.ToInt32(q.LegacyID);
                o.salesrepphone = q.SalesRepPhone;
                o.salesrepterritory = q.SalesRepTerritory;
                o.marketingrep = q.MarketingRep;
                o.marketingrepemail = q.MarketingRepEmail;
                o.distributor = q.Distributor;
                o.preferredcarrier = q.PreferredCarrier;
                o.approvalneeded = Convert.ToBoolean(q.ApprovalNeeded);

                o.CreateUser = q.CreateUser;
                o.CreateDate = q.CreateDate;
                o.UpdateUser = q.UpdateUser;
                o.UpdateDate = q.UpdateDate;
                o.billinggroup = q.BillingGroup;

                o.IsSDN = q.IsSDN;

                return o;
            }
        }
示例#4
0
        public static OrderMasterFull fnCreateOrder(int id)
        {
            // id=clientid
            using (var db = new EF.CMCSQL03Entities())
            {
                // populate the minimum fields needed for the View
                OrderMasterFull vm = new OrderMasterFull();
                vm.orderid = -1;
                vm.clientid = id;
                var cl = db.tblClient.Find(vm.clientid);
                vm.clientname = cl.ClientName;
                vm.logofilename = cl.LogoFileName;
                vm.orderstatus = "z";
                vm.orderdate = System.DateTime.Now;
                //vm.ListOfDivisions = fnListOfDivisions(id);
                //vm.ListOfOrderTypes = fnListOfOrderTypes();
                vm.ListOfSalesReps = fnListOfSalesReps(id);
                //vm.ListOfOrderSources = fnListOfOrderSources();
                vm.ListOfCountries = fnListOfCountries();
                vm.ListOfEndUses = fnListOfEndUses(id);
                vm.ListOfShipVias = fnListOfShipVias();
                vm.ListOfBillingGroups = fnListOfBillingGroups(id);
                vm.CreateUser = HttpContext.Current.User.Identity.Name;
                vm.CreateDate = System.DateTime.Now;

                vm.IsSDN = false;
                return vm;
            }
        }
示例#5
0
        public static void fnSaveOrderPostUpdate(OrderMasterFull vm)
        {
            // changes to order record after it is saved
            using (var db = new EF.CMCSQL03Entities())
            {
                bool ShowAlert = false;
                // string sCommand = "";
                var q = (from t in db.tblOrderMaster where t.OrderID == vm.orderid select t).FirstOrDefault();

                var qCountry = (from t in db.tblCountry
                                where t.Country == vm.country && t.DoNotShip == true
                                select t).FirstOrDefault();

                if (qCountry != null)
                {
                    // flag the order record and the item records that are yet to be allocated
                    q.IsSDN = true;
                    var orderitems = (from t in db.tblOrderItem
                                      where t.OrderID == vm.orderid && t.AllocateStatus == null
                                      select t).ToList();

                    foreach (var item in orderitems)
                    {
                        item.CSAllocate = false;
                        db.SaveChanges();
                    }

                    ShowAlert = true;
                }

                if (fnIsSDN(vm) == true)
                {
                    // flag the order record and the item records that are yet to be allocated (again maybe)
                    q.IsSDN = true;
                    var orderitems = (from t in db.tblOrderItem
                                      where t.OrderID == vm.orderid && t.AllocateStatus == null
                                      select t).ToList();

                    foreach (var item in orderitems)
                    {
                        item.CSAllocate = false;
                        db.SaveChanges();
                    }

                    ShowAlert = true;
                }

                if (vm.country != "0")
                {
                    var qCountry2 = (from t in db.tblCountry
                                     where t.Country == vm.country
                                     select t).FirstOrDefault(); // need the ID

                    var qCeaseShipOffset = (from t in db.tblCeaseShipOffSet
                                            where t.ClientID == vm.clientid && t.CountryID == qCountry2.CountryID
                                            select t).FirstOrDefault();

                    if (qCeaseShipOffset != null)
                    {
                        q.CeaseShipOffset = qCeaseShipOffset.OffsetDays;
                    }
                }

                db.SaveChanges();

                if (ShowAlert == true)
                {
                    // do something , return js alert ???
                }
            }
        }
示例#6
0
        public static int fnSaveOrder(OrderMasterFull vm)
        {
            fnArchiveOrderMaster(vm.orderid);

            // Take a ViewModel and Insert/Update DB / Return the PK
            using (var db = new MvcPhoenix.EF.CMCSQL03Entities())
            {
                if (vm.orderid == -1)
                {
                    vm.orderid = fnNewOrderID();
                }

                // update time stamps
                vm.UpdateUser = HttpContext.Current.User.Identity.Name;
                vm.UpdateDate = System.DateTime.Now;

                var q = (from t in db.tblOrderMaster where t.OrderID == vm.orderid select t).FirstOrDefault();

                q.OrderDate = vm.orderdate;
                q.ClientID = vm.clientid;
                q.Customer = vm.customer;
                q.CMCOrder = vm.cmcorder;
                q.WebOrderID = vm.weborderid;
                q.CMCLegacyNum = vm.cmclegacynumber;
                q.CustOrdNum = vm.custordnum;
                q.CustSapNum = vm.custsapnum;
                q.CustRefNum = vm.custrefnum;
                q.OrderType = vm.ordertype;
                q.OrderDate = vm.orderdate;
                q.Company = vm.company;
                q.Street = vm.street;
                q.Street2 = vm.street2;
                q.Street3 = vm.street3;
                q.City = vm.city;
                q.State = vm.state;
                q.Zip = vm.Zip;
                q.Country = vm.country;
                q.Attention = vm.attention;
                q.Email = vm.email;
                q.SalesRep = vm.salesrep;
                q.SalesEmail = vm.sales_email;
                q.Req = vm.req;
                q.ReqPhone = vm.reqphone;
                q.ReqFax = vm.reqfax;
                q.ReqEmail = vm.reqemail;
                q.EndUse = vm.enduse;
                q.ShipVia = vm.shipvia;
                q.ShipAcct = vm.shipacct;
                q.Phone = vm.phone;
                q.Source = vm.source;
                q.Fax = vm.fax;
                q.Tracking = vm.tracking;
                q.Special = vm.special;
                q.SpecialInternal = vm.specialinternal;
                q.Lit = Convert.ToBoolean(vm.lit);
                q.Region = vm.region;
                q.COA = vm.coa;
                q.TDS = vm.tds;
                q.CID = vm.cid;
                q.CustAcct = vm.custacct;
                q.ACode = vm.acode;
                q.ImportFile = vm.importfile;
                q.ImportDateLine = vm.importdateline;
                q.Timing = vm.timing;
                q.Volume = vm.volume;
                q.SampleRack = Convert.ToBoolean(vm.samplerack);
                q.CMCUser = vm.cmcuser;
                q.CustomerReference = vm.customerreference;
                q.TotalOrderWeight = (vm.totalorderweight);
                q.SPSTaxID = vm.spstaxid;
                q.SPSCurrency = vm.spscurrency;
                q.SPSShippedWt = vm.spsshippedwt;
                q.SPSFreightCost = vm.spsfreightcost;
                q.InvoiceCompany = vm.invoicecompany;
                q.InvoiceTitle = vm.invoicetitle;
                q.InvoiceFirstName = vm.invoicefirstname;
                q.InvoiceLastName = vm.invoicelastname;
                q.InvoiceAddress1 = vm.invoiceaddress1;
                q.InvoiceAddress2 = vm.invoiceaddress2;
                q.InvoiceAddress3 = vm.invoiceaddress3;
                q.InvoiceCity = vm.invoicecity;
                q.InvoiceStateProv = vm.invoicestateprov;
                q.InvoicePostalCode = vm.invoicepostalcode;
                q.InvoiceCountry = vm.invoicecountry;
                q.InvoicePhone = vm.invoicephone;
                q.CustOrderType = vm.custordertype;
                q.CustRequestDate = vm.custrequestdate;
                q.ApprovalDate = vm.approvaldate;
                q.RequestedDeliveryDate = vm.requesteddeliverydate;
                q.CustTotalItems = vm.custtotalitems;
                q.CustRequestedCarrier = vm.custrequestedcarrier;
                q.LegacyID = (vm.legacyid);
                q.SalesRepPhone = vm.salesrepphone;
                q.SalesRepTerritory = vm.salesrepterritory;
                q.MarketingRep = vm.marketingrep;
                q.MarketingRepEmail = vm.marketingrepemail;
                q.Distributor = vm.distributor;
                q.PreferredCarrier = vm.preferredcarrier;
                q.ApprovalNeeded = vm.approvalneeded;

                q.UpdateUser = vm.UpdateUser;
                q.UpdateDate = vm.UpdateDate;
                q.CreateUser = vm.CreateUser;
                q.CreateDate = vm.CreateDate;
                q.BillingGroup = vm.billinggroup;

                // reset the value
                q.IsSDN = false;

                db.SaveChanges();

                fnSaveOrderPostUpdate(vm);

                return vm.orderid;
            }
        }