/// <summary>
    /// Sets the part and class type types based on parameters, then instantiates it within the grave.
    /// </summary>
    /// <param name="_pt"> The part type to add </param>
    /// <param name="_ct"> The Class type to add </param>
    public void SetBodyPart(Part_Type _pt, Class_Type _ct)
    {
        switch (_pt)
        {
        case Part_Type.head:
            m_bodyPart = m_head;
            break;

        case Part_Type.left_arm:
            m_bodyPart = m_leftArm;

            break;

        case Part_Type.right_arm:
            m_bodyPart = m_rightArm;

            break;

        case Part_Type.left_leg:
            m_bodyPart = m_leftLeg;

            break;

        case Part_Type.right_leg:
            m_bodyPart = m_rightLeg;

            break;

        case Part_Type.torso:
            m_bodyPart = m_torso;

            break;

        default:
            Debug.LogError("_pt was incorrectly formatted. Output was: " + _pt.ToString());
            break;
        }

        m_bodyPart = Instantiate(m_bodyPart);
        ///Test/debug
        //   m_bodyPart = GameObject.CreatePrimitive(PrimitiveType.Cube);
        ///set the new body part to the position of this gameobject
        m_bodyPart.transform.position = transform.position;
        //m_bodyPart.AddComponent<BodyPart>();
        //m_bodyPart.AddComponent<Interactable>();
        //m_bodyPart.AddComponent<Throwable>();

        m_bodyPart.GetComponent <BodyPart>().m_class_Type = _ct;
        Rigidbody rb = m_bodyPart.GetComponent <Rigidbody>();

        //     rb.useGravity = false;
        //     rb.constraints = RigidbodyConstraints.FreezeAll;
        //     m_bodyPart.GetComponent<BodyPart>().m_part_Type = _pt;
        //     m_bodyPart.GetComponent<BodyPart>().m_class_Type = _ct;
        m_bodyPart.transform.SetParent(transform);
        m_bodyPart.SetActive(false);


        m_bodyPart.name = "Body Part: " + m_bodyPart.GetComponent <BodyPart>().m_part_Type + " (" + m_bodyPart.GetComponent <BodyPart>().m_class_Type + ")";
    }
Beispiel #2
0
    /// <summary>
    /// Sets up each grave with a class and part type and adds text to the gravestone
    /// </summary>
    private void Setup()
    {
        int counter = 0;

        int _knightCounter = 0;
        int _bersCounter   = 0;
        int _thiefCounter  = 0;

        foreach (GameObject go in m_graveSpots)
        {
            Grave      _grave      = go.GetComponentInChildren <Grave>();
            Gravestone _gravestone = go.GetComponentInChildren <Gravestone>();
            int        _idx        = UnityEngine.Random.Range(0, Enum.GetValues(typeof(Part_Type)).Length);

            Part_Type _pt = (Part_Type)_idx;
            int       idx = UnityEngine.Random.Range(0, Enum.GetValues(typeof(Class_Type)).Length);

            Class_Type _ct = (Class_Type)idx;
            switch (_ct)
            {
            case Class_Type.berserker:
                _bersCounter++;
                counter = _bersCounter;
                break;

            case Class_Type.knight:
                _knightCounter++;
                counter = _knightCounter;

                break;

            case Class_Type.thief:
                _thiefCounter++;
                counter = _thiefCounter;

                break;
            }
            ///Debug
            //    _ct = Class_Type.knight;
            ///Set text on grave
            string _ctName = _ct.ToString();

            string query     = $"(//*[@id='FriendlyUnits']//*[@id='{_ctName}']//*[@id='GraveText'])[{counter}]";
            string graveText = XMLManager.Instance.ReadSingleNodeData(query);

            if (graveText == null)
            {
                Debug.LogError("text not found for: " + _ctName + " dummy text set.");
                graveText = "Dummy Text for: " + _ctName;
            }

            _gravestone.SetCanvasText(graveText);

            ///Add body part to grave
            _grave.SetBodyPart(_pt, _ct);
        }
    }
Beispiel #3
0
        // POST: api/CustomerQuote
        public string Post(HttpRequestMessage value)
        {
            try
            {
                Model.Client_Quote client = new Model.Client_Quote();

                string  message = HttpContext.Current.Server.UrlDecode(value.Content.ReadAsStringAsync().Result).Substring(5);
                JObject json    = JObject.Parse(message);

                JObject clientDetails = (JObject)json["client"];
                JArray  parts         = (JArray)clientDetails["details"];
                string  action        = (string)json["action"];

                int key = db.Client_Quote.Count() == 0 ? 1 : (from t in db.Client_Quote
                                                              orderby t.Client_Quote_ID descending
                                                              select t.Client_Quote_ID).First() + 1;
                client.Client_Quote_ID          = key;
                client.Client_ID                = (int)clientDetails["Client_ID"];
                client.Contact_ID               = (int)clientDetails["Contact_ID"];
                client.Date                     = (DateTime)clientDetails["Date"];
                client.Client_Quote_Expiry_Date = (DateTime)clientDetails["Client_Quote_Expiry_Date"];


                db.Client_Quote.Add(client);

                foreach (JObject part in parts)
                {
                    Client_Quote_Detail cqd = new Client_Quote_Detail();
                    cqd.Quantity                 = (int)part["Quantity"];
                    cqd.Part_Price               = (decimal)part["Part_Price"];
                    cqd.Client_Discount_Rate     = (double)part["Client_Discount_Rate"];
                    cqd.Settlement_Discount_Rate = (double)clientDetails["Settlement_Discount_Rate"];
                    cqd.Client_Quote_ID          = key;
                    cqd.Part_Type_ID             = (int)part["Part_Type_ID"];

                    db.Client_Quote_Detail.Add(cqd);
                }

                bool flag = true;

                if (action == "email")
                {
                    Client_Contact_Person_Detail cl = new Client_Contact_Person_Detail();
                    cl = (from p in db.Client_Contact_Person_Detail
                          where p.Contact_ID == client.Contact_ID
                          select p).First();

                    string to      = cl.Email_Address;
                    string subject = "WME Quote #" + key;

                    DateTime expiry = (DateTime)clientDetails["Client_Quote_Expiry_Date"];
                    string   body   = "Walter Meano Engineering Quote #" + key + "\nThe quote is valid until " + expiry.ToShortDateString() + "\n\nItems on Quote:\n";

                    foreach (JObject part in parts)
                    {
                        Part_Type pt      = new Part_Type();
                        int       part_id = (int)part["Part_Type_ID"];
                        pt = (from p in db.Part_Type
                              where p.Part_Type_ID == part_id
                              select p).First();

                        body += pt.Abbreviation + " - " + pt.Name + "\t\tx" + (int)part["Quantity"] + "\tR " + (decimal)part["Part_Price"] + " per unit\n";
                    }

                    flag = Email.SendEmail(to, subject, body);
                }

                db.SaveChanges();

                string s = "";
                if (flag == false)
                {
                    s += "If the quote has not been emailed successfully you will receive an email notifying you of this in a few minutes.";
                }

                return("true|Customer Quote #" + key + " successfully added. " + s + "|" + key);
            }
            catch (Exception e)
            {
                ExceptionLog.LogException(e, "CustomerQuoteController POST");
                return("false|An error has occured adding the Customer Quote to the system.");
            }
        }
        private void generateUniqueParts(int how_many, int part_type_ID, int parent_ID, int job_card_detail_ID, string type)
        {
            if (type == "Ordering")
            {
                //(Armand) Check for parts that are in-stock and not tied to any other client order
                List <Part> in_stock_parts = null;
                var         parts          = (from p in db.Parts
                                              where p.Part_Type_ID == part_type_ID && p.Part_Status_ID == 3
                                              select p).ToList();

                foreach (Part part in parts)
                {
                    if ((from p in db.Job_Card_Detail
                         where p.Parts.Contains(part) && p.Job_Card.Job_Card_Priority_ID == 1
                         select p) == null)
                    {
                        in_stock_parts.Add(part);
                    }
                }

                if (in_stock_parts != null)
                {
                    foreach (Part part in in_stock_parts)
                    {
                        //now we assign the part to this job card
                        assignAvailableParts(part.Part_ID, job_card_detail_ID);
                        how_many--;
                    }
                }
            }


            //(Armand) Check for cancelled parts
            List <Part> cancelled_parts = null;

            cancelled_parts = (from p in db.Parts
                               where p.Part_Type_ID == part_type_ID && p.Part_Status_ID == 5
                               select p).ToList();

            if (cancelled_parts != null)
            {
                foreach (Part part in cancelled_parts)
                {
                    Part p = new Part();
                    p = (from d in db.Parts
                         where d.Part_ID == part.Part_ID
                         select d).First();

                    if (p.Part_Stage == 1)
                    {
                        p.Part_Status_ID = 1;
                    }
                    else
                    {
                        p.Part_Status_ID = 2;
                    }

                    db.SaveChanges();

                    assignAvailableParts(part.Part_ID, job_card_detail_ID);
                    how_many--;
                }
            }

            //Now to make new parts
            for (int k = 0; k < how_many; k++)
            {
                Part_Type pt = new Part_Type();
                pt = (from p in db.Part_Type
                      where p.Part_Type_ID == part_type_ID
                      select p).First();


                //(Armand) Get the abbreviation for the part_type
                string abbreviation = pt.Abbreviation;

                //(Armand) Generate the new number;
                Random rand   = new Random();
                int    num    = 0;
                string serial = "";

                while (true)
                {
                    num    = rand.Next(1, 999999999);
                    serial = abbreviation + "-" + Convert.ToString(num);

                    if ((from p in db.Parts
                         where p.Part_Serial == serial
                         select p).Count() == 0)
                    {
                        break;
                    }
                }


                int partkey = db.Parts.Count() == 0 ? 1 : (from t in db.Parts
                                                           orderby t.Part_ID descending
                                                           select t.Part_ID).First() + 1;

                Part newpart = new Part();
                newpart.Part_ID        = partkey;
                newpart.Part_Serial    = serial;
                newpart.Part_Stage     = 1;
                newpart.Parent_ID      = parent_ID;
                newpart.Part_Type_ID   = part_type_ID;
                newpart.Part_Status_ID = 1;
                newpart.Date_Added     = DateTime.Now;
                newpart.Cost_Price     = 0;

                db.Parts.Add(newpart);
                db.SaveChanges();

                assignAvailableParts(partkey, job_card_detail_ID);
            }
        }
Beispiel #5
0
        // POST: api/SupplierOrder
        public string Post(HttpRequestMessage value)
        {
            try
            {
                Model.Supplier_Order supplier = new Model.Supplier_Order();

                string  message      = HttpContext.Current.Server.UrlDecode(value.Content.ReadAsStringAsync().Result).Substring(5);
                JObject json         = JObject.Parse(message);
                JObject orderDetails = (JObject)json["order"];
                string  type         = (string)json["type"];
                string  action       = (string)json["action"];

                int key = db.Supplier_Order.Count() == 0 ? 1 : (from t in db.Supplier_Order
                                                                orderby t.Supplier_Order_ID descending
                                                                select t.Supplier_Order_ID).First() + 1;

                supplier.Supplier_Order_ID        = key;
                supplier.Supplier_Order_Status_ID = (int)orderDetails["Supplier_Order_Status_ID"];
                supplier.Date        = (DateTime)orderDetails["Date"];
                supplier.Supplier_ID = (int)orderDetails["Supplier_ID"];

                db.Supplier_Order.Add(supplier);

                if (type == "AdHoc")
                {
                    JArray componentDetails   = (JArray)json["components"];
                    JArray partTypeDetails    = (JArray)json["parts"];
                    JArray RawMaterialDetails = (JArray)json["raw"];

                    if (componentDetails != null)
                    {
                        foreach (JObject comp in componentDetails)
                        {
                            Supplier_Order_Component cs = new Supplier_Order_Component();
                            cs.Component_ID       = (int)comp["Component_ID"];
                            cs.Supplier_Order_ID  = key;
                            cs.Quantity_Requested = (int)comp["Quantity_Requested"];
                            cs.Quantity_Received  = 0;
                            cs.Price = (decimal)comp["Price"];

                            db.Supplier_Order_Component.Add(cs);
                        }
                    }

                    if (partTypeDetails != null)
                    {
                        foreach (JObject part in partTypeDetails)
                        {
                            Supplier_Order_Detail_Part ps = new Supplier_Order_Detail_Part();
                            ps.Part_Type_ID      = (int)part["Part_Type_ID"];
                            ps.Supplier_Order_ID = key;
                            ps.Quantity          = (int)part["Quantity"];
                            ps.Quantity_Received = 0;
                            ps.Price             = (decimal)part["Price"];

                            db.Supplier_Order_Detail_Part.Add(ps);
                        }
                    }

                    if (RawMaterialDetails != null)
                    {
                        foreach (JObject raw in RawMaterialDetails)
                        {
                            Supplier_Order_Detail_Raw_Material rms = new Supplier_Order_Detail_Raw_Material();
                            rms.Raw_Material_ID   = (int)raw["Raw_Material_ID"];
                            rms.Supplier_Order_ID = key;
                            rms.Quantity          = (int)raw["Quantity"];
                            rms.Price             = (decimal)raw["Price"];
                            rms.Quantity_Received = 0;
                            rms.Dimensions        = (string)raw["Dimensions"];

                            db.Supplier_Order_Detail_Raw_Material.Add(rms);
                        }
                    }
                }
                else
                {
                    JArray componentDetails   = (JArray)json["components"];
                    JArray partTypeDetails    = (JArray)json["parts"];
                    JArray RawMaterialDetails = (JArray)json["raw"];

                    int quoteID = (int)orderDetails["Supplier_Quote_ID"];

                    Supplier_Quote sq = new Supplier_Quote();
                    sq = (from p in db.Supplier_Quote
                          where p.Supplier_Quote_ID == quoteID
                          select p).First();

                    supplier.Supplier_Quote.Add(sq);

                    if (componentDetails != null)
                    {
                        foreach (JObject comp in componentDetails)
                        {
                            Supplier_Order_Component cs = new Supplier_Order_Component();
                            cs.Component_ID       = (int)comp["Component_ID"];
                            cs.Supplier_Order_ID  = key;
                            cs.Quantity_Requested = (int)comp["Quantity_Requested"];
                            cs.Quantity_Received  = 0;
                            cs.Price = (decimal)comp["Price"];

                            db.Supplier_Order_Component.Add(cs);
                        }
                    }

                    if (partTypeDetails != null)
                    {
                        foreach (JObject part in partTypeDetails)
                        {
                            Supplier_Order_Detail_Part ps = new Supplier_Order_Detail_Part();
                            ps.Part_Type_ID      = (int)part["Part_Type_ID"];
                            ps.Supplier_Order_ID = key;
                            ps.Quantity          = (int)part["Quantity"];
                            ps.Quantity_Received = 0;
                            ps.Price             = (decimal)part["Price"];

                            db.Supplier_Order_Detail_Part.Add(ps);
                        }
                    }

                    if (RawMaterialDetails != null)
                    {
                        foreach (JObject raw in RawMaterialDetails)
                        {
                            Supplier_Order_Detail_Raw_Material rms = new Supplier_Order_Detail_Raw_Material();
                            rms.Raw_Material_ID   = (int)raw["Raw_Material_ID"];
                            rms.Supplier_Order_ID = key;
                            rms.Quantity          = (int)raw["Quantity"];
                            rms.Price             = (decimal)raw["Price"];
                            rms.Quantity_Received = 0;
                            rms.Dimensions        = (string)raw["Dimensions"];

                            db.Supplier_Order_Detail_Raw_Material.Add(rms);
                        }
                    }
                }

                db.SaveChanges();

                if (action == "email")
                {
                    JArray componentDetails   = (JArray)json["components"];
                    JArray partTypeDetails    = (JArray)json["parts"];
                    JArray RawMaterialDetails = (JArray)json["raw"];

                    Model.Supplier sup = new Model.Supplier();
                    sup = (from p in db.Suppliers
                           where p.Supplier_ID == supplier.Supplier_ID
                           select p).First();

                    string to      = sup.Email;
                    string subject = "WME Supplier Order #" + key;

                    String orderDate = supplier.Date.ToShortDateString();
                    string body      = "Walter Meano Engineering Supplier Order #" + key + "\nThe order was placed on " + orderDate + "\n\nItems in Order:\n";

                    if (componentDetails != null)
                    {
                        foreach (JObject comp in componentDetails)
                        {
                            Component cs      = new Component();
                            int       comp_id = (int)comp["Component_ID"];
                            cs = (from p in db.Components
                                  where p.Component_ID == comp_id
                                  select p).First();

                            body += cs.Name + "\t\tx" + (int)comp["Quantity_Requested"] + "\n";
                        }
                    }

                    if (partTypeDetails != null)
                    {
                        foreach (JObject part in partTypeDetails)
                        {
                            Part_Type pt      = new Part_Type();
                            int       part_id = (int)part["Part_Type_ID"];
                            pt = (from p in db.Part_Type
                                  where p.Part_Type_ID == part_id
                                  select p).First();

                            body += pt.Name + "\t\tx" + (int)part["Quantity"] + "\n";
                        }
                    }

                    if (RawMaterialDetails != null)
                    {
                        foreach (JObject raw in RawMaterialDetails)
                        {
                            Raw_Material raw2   = new Raw_Material();
                            int          raw_id = (int)raw["Raw_Material_ID"];
                            raw2 = (from p in db.Raw_Material
                                    where p.Raw_Material_ID == raw_id
                                    select p).First();

                            body += raw2.Name + "\t\tx" + (int)raw["Quantity"] + "\n";
                        }
                    }

                    Email.SendEmail(to, subject, body);
                }

                return("true|Supplier Purchase Order #" + key + " successfully added.");
            }
            catch (Exception e)
            {
                ExceptionLog.LogException(e, "SupplierOrderController POST");
                return("false|An error has occured adding the Supplier Order to the system.");
            }
        }
Beispiel #6
0
        // PUT: api/ReceiveSupplierOrder/5
        public string Put(int id, HttpRequestMessage value)
        {
            try
            {
                string  message = HttpContext.Current.Server.UrlDecode(value.Content.ReadAsStringAsync().Result).Substring(5);
                JObject json    = JObject.Parse(message);
                JArray  cs      = (JArray)json["cs"];
                JArray  ps      = (JArray)json["ps"];
                JArray  rms     = (JArray)json["rms"];

                var so = (from p in db.Supplier_Order
                          where p.Supplier_Order_ID == id
                          select p).First();

                bool rawAll  = true;
                bool partAll = true;
                bool compAll = true;

                foreach (JObject comp in cs)
                {
                    int component_id             = (int)comp["Component_ID"];
                    Supplier_Order_Component soc = new Supplier_Order_Component();
                    soc = (from p in db.Supplier_Order_Component
                           where p.Supplier_Order_ID == id && p.Component_ID == component_id
                           select p).First();
                    int quantity    = soc.Quantity_Received;
                    int newquantity = (int)comp["Quantity_Received"] - quantity;

                    soc.Quantity_Received = (int)comp["Quantity_Received"];
                    soc.Supplier_Order    = so;

                    Component c = new Component();
                    c = (from p in db.Components
                         where p.Component_ID == component_id
                         select p).First();
                    c.Quantity += newquantity;

                    if (soc.Quantity_Requested != soc.Quantity_Received)
                    {
                        compAll = false;
                    }
                }

                foreach (JObject part in ps)
                {
                    int component_id = (int)part["Part_Type_ID"];
                    Supplier_Order_Detail_Part soc = new Supplier_Order_Detail_Part();
                    soc = (from p in db.Supplier_Order_Detail_Part
                           where p.Supplier_Order_ID == id && p.Part_Type_ID == component_id
                           select p).First();

                    int quantity    = soc.Quantity_Received;
                    int newquantity = (int)part["Quantity_Received"] - quantity;
                    soc.Quantity_Received = (int)part["Quantity_Received"];

                    int key = db.Parts.Count() == 0 ? 1 : (from t in db.Parts
                                                           orderby t.Part_ID descending
                                                           select t.Part_ID).First() + 1;

                    if (soc.Quantity != soc.Quantity_Received)
                    {
                        partAll = false;
                    }

                    for (int x = 0; x < newquantity; x++)
                    {
                        string abbreviation = soc.Part_Type.Abbreviation;

                        //(Armand) Generate the new number;
                        Random rand   = new Random();
                        int    num    = 0;
                        string serial = "";

                        while (true)
                        {
                            num    = rand.Next(1, 999999999);
                            serial = abbreviation + "-" + Convert.ToString(num);

                            if ((from d in db.Parts
                                 where d.Part_Serial == serial
                                 select d).Count() == 0)
                            {
                                break;
                            }
                        }

                        Part p = new Part();
                        p.Parent_ID      = 0;
                        p.Part_Serial    = serial;
                        p.Part_Status_ID = 1;
                        p.Part_Type_ID   = component_id;
                        p.Part_ID        = key;
                        key++;
                        p.Part_Stage = 0;
                        p.Date_Added = DateTime.Now;
                        p.Cost_Price = (decimal)part["Price"];
                        p.Supplier_Order.Add(so);
                        db.Parts.Add(p);
                    }
                }

                foreach (JObject raw in rms)
                {
                    int component_id = (int)raw["Raw_Material_ID"];
                    Supplier_Order_Detail_Raw_Material soc = new Supplier_Order_Detail_Raw_Material();
                    soc = (from p in db.Supplier_Order_Detail_Raw_Material
                           where p.Supplier_Order_ID == id && p.Raw_Material_ID == component_id
                           select p).First();

                    int quantity    = soc.Quantity_Received;
                    int newquantity = (int)raw["Quantity_Received"] - quantity;
                    soc.Quantity_Received = (int)raw["Quantity_Received"];

                    int key = db.Unique_Raw_Material.Count() == 0 ? 1 : (from t in db.Unique_Raw_Material
                                                                         orderby t.Unique_Raw_Material_ID descending
                                                                         select t.Unique_Raw_Material_ID).First() + 1;

                    if (soc.Quantity != soc.Quantity_Received)
                    {
                        rawAll = false;
                    }

                    for (int x = 0; x < newquantity; x++)
                    {
                        Unique_Raw_Material p = new Unique_Raw_Material();
                        p.Unique_Raw_Material_ID = key;
                        key++;
                        p.Cost_Price        = (decimal)raw["Price"];
                        p.Date_Added        = DateTime.Now;
                        p.Raw_Material_ID   = component_id;
                        p.Dimension         = (string)raw["Dimensions"];
                        p.Quality           = "";
                        p.Supplier_Order_ID = id;

                        db.Unique_Raw_Material.Add(p);
                    }
                }

                if (rawAll && partAll && compAll)
                {
                    so.Supplier_Order_Status_ID = 5;
                }
                else
                {
                    so.Supplier_Order_Status_ID = 2;

                    string to      = so.Supplier.Email;
                    string subject = "WME Supplier Order #" + so.Supplier_Order_ID + " Back Order";

                    String orderDate = DateTime.Now.ToShortDateString();
                    string body      = "Walter Meano Engineering Supplier Order #" + so.Supplier_Order_ID + "\nThe order was partially received on " + orderDate + "\n\nThe following items still need to be delivered:\n";

                    foreach (JObject comp in cs)
                    {
                        int component_id             = (int)comp["Component_ID"];
                        Supplier_Order_Component soc = new Supplier_Order_Component();
                        soc = (from p in db.Supplier_Order_Component
                               where p.Supplier_Order_ID == id && p.Component_ID == component_id
                               select p).First();
                        int quantity     = soc.Quantity_Received;
                        int quantityLeft = soc.Quantity_Requested - quantity;

                        if (quantityLeft != 0)
                        {
                            Component c = new Component();
                            c = (from p in db.Components
                                 where p.Component_ID == component_id
                                 select p).First();

                            body += c.Name + "\t\tx" + quantityLeft + "\n";
                        }
                    }

                    foreach (JObject part in ps)
                    {
                        int component_id = (int)part["Part_Type_ID"];
                        Supplier_Order_Detail_Part soc = new Supplier_Order_Detail_Part();
                        soc = (from p in db.Supplier_Order_Detail_Part
                               where p.Supplier_Order_ID == id && p.Part_Type_ID == component_id
                               select p).First();

                        int quantity     = soc.Quantity_Received;
                        int quantityLeft = soc.Quantity - quantity;

                        if (quantityLeft != 0)
                        {
                            Part_Type c = new Part_Type();
                            c = (from p in db.Part_Type
                                 where p.Part_Type_ID == component_id
                                 select p).First();

                            body += c.Name + "\t\tx" + quantityLeft + "\n";
                        }
                    }

                    foreach (JObject raw in rms)
                    {
                        int component_id = (int)raw["Raw_Material_ID"];
                        Supplier_Order_Detail_Raw_Material soc = new Supplier_Order_Detail_Raw_Material();
                        soc = (from p in db.Supplier_Order_Detail_Raw_Material
                               where p.Supplier_Order_ID == id && p.Raw_Material_ID == component_id
                               select p).First();

                        int quantity     = soc.Quantity_Received;
                        int quantityLeft = soc.Quantity - quantity;

                        if (quantityLeft != 0)
                        {
                            Raw_Material c = new Raw_Material();
                            c = (from p in db.Raw_Material
                                 where p.Raw_Material_ID == component_id
                                 select p).First();

                            body += c.Name + "\t\tx" + quantityLeft + "\n";
                        }
                    }

                    Email.SendEmail(to, subject, body);
                }

                db.SaveChanges();
                return("true|Supplier Purchase Order successfully received.");
            }
            catch (Exception e)
            {
                ExceptionLog.LogException(e, "ReceiveSupplierOrderController");
                return("false|An error has occured receiving the Supplier Purchase Order on the system.");
            }
        }
Beispiel #7
0
        // POST: api/CustomerOrder
        public string Post(HttpRequestMessage value)
        {
            //    try
            //    {
            Model.Client_Order co = new Model.Client_Order();

            string  message = HttpContext.Current.Server.UrlDecode(value.Content.ReadAsStringAsync().Result).Substring(5);
            JObject json    = JObject.Parse(message);

            JObject orderDetails = (JObject)json["client"];
            JArray  parts        = (JArray)orderDetails["details"];
            string  todo         = (string)json["action"];

            int key = db.Client_Order.Count() == 0 ? 1 : (from t in db.Client_Order
                                                          orderby t.Client_Order_ID descending
                                                          select t.Client_Order_ID).First() + 1;

            co.Client_Order_ID          = key;
            co.Date                     = (DateTime)orderDetails["Date"];
            co.Reference_ID             = (string)orderDetails["Reference_ID"];
            co.Contact_ID               = (int)orderDetails["Contact_ID"];
            co.Client_ID                = (int)orderDetails["Client_ID"];
            co.Settlement_Discount_Rate = (double)orderDetails["Settlement_Discount_Rate"];
            co.Client_Order_Type_ID     = (int)orderDetails["Client_Order_Type_ID"];
            co.Client_Order_Status_ID   = 1;
            co.Settlement_Discount_Rate = (double)orderDetails["Settlement_Discount_Rate"];
            co.Delivery_Method_ID       = (int)orderDetails["Delivery_Method_ID"];
            co.VAT_Inclu                = Convert.ToBoolean((string)orderDetails["VAT_Inclu"]);
            co.Comment                  = (string)orderDetails["Comment"];

            string errorString = "false|";
            bool   error       = false;

            if ((from t in db.Client_Order
                 where t.Reference_ID == co.Reference_ID
                 select t).Count() != 0)
            {
                error        = true;
                errorString += "The Customer Order Reference entered already exists on the system. ";
            }

            if (error)
            {
                return(errorString);
            }

            Job_Card jc      = new Job_Card();
            int      job_key = db.Job_Card.Count() == 0 ? 1 : (from t in db.Job_Card
                                                               orderby t.Job_Card_ID descending
                                                               select t.Job_Card_ID).First() + 1;

            jc.Job_Card_ID          = job_key;
            jc.Job_Card_Date        = (DateTime)orderDetails["Date"];
            jc.Job_Card_Status_ID   = 1;
            jc.Job_Card_Priority_ID = 1;
            co.Job_Card_ID          = job_key;

            db.Client_Order.Add(co);
            db.Job_Card.Add(jc);
            db.SaveChanges();

            int detail_key = db.Job_Card_Detail.Count() == 0 ? 1 : (from t in db.Job_Card_Detail
                                                                    orderby t.Job_Card_Details_ID descending
                                                                    select t.Job_Card_Details_ID).First() + 1;

            int co_key = db.Client_Order_Detail.Count() == 0 ? 1 : (from t in db.Client_Order_Detail
                                                                    orderby t.Client_Order_Detail_ID descending
                                                                    select t.Client_Order_Detail_ID).First() + 1;

            foreach (JObject part in parts)
            {
                Client_Order_Detail cqd = new Client_Order_Detail();
                cqd.Part_Type_ID           = (int)part["Part_Type_ID"];
                cqd.Quantity               = (int)part["Quantity"];
                cqd.Quantity_Delivered     = 0;
                cqd.Part_Price             = (decimal)part["Part_Price"];
                cqd.Client_Discount_Rate   = (double)part["Client_Discount_Rate"];
                cqd.Client_Order_ID        = key;
                cqd.Client_Order_Detail_ID = co_key;
                co_key++;

                db.Client_Order_Detail.Add(cqd);

                Job_Card_Detail jcd = new Job_Card_Detail();
                jcd.Job_Card_Details_ID = detail_key;
                detail_key++;

                jcd.Part_Type_ID = (int)part["Part_Type_ID"];
                jcd.Job_Card_ID  = job_key;
                jcd.Non_Manual   = false;
                jcd.Quantity     = (int)part["Quantity"];

                db.Job_Card_Detail.Add(jcd);
                db.SaveChanges();

                //2. Handle child dependencies
                checkForChildren(jcd.Part_Type_ID, jcd.Quantity, job_key, "Ordering");

                generateUniqueParts(jcd.Quantity, jcd.Part_Type_ID, 0, detail_key - 1, "Ordering");
            }

            db.SaveChanges();

            if (todo == "email")
            {
                Client_Contact_Person_Detail cl = new Client_Contact_Person_Detail();
                cl = (from p in db.Client_Contact_Person_Detail
                      where p.Contact_ID == co.Contact_ID
                      select p).First();

                string to      = cl.Email_Address;
                string subject = "WME Order #" + key;

                String orderDate = co.Date.ToShortDateString();
                string body      = "Walter Meano Engineering Order #" + key + "\nThe order was placed on " + orderDate + "\n\nItems on Order:\n";

                foreach (JObject part in parts)
                {
                    Part_Type pt      = new Part_Type();
                    int       part_id = (int)part["Part_Type_ID"];
                    pt = (from p in db.Part_Type
                          where p.Part_Type_ID == part_id
                          select p).First();

                    body += pt.Abbreviation + " - " + pt.Name + "\t\tx" + (int)part["Quantity"] + "\tR " + (decimal)part["Part_Price"] + " per unit\n";
                }

                Email.SendEmail(to, subject, body);
            }

            return("true|Order #" + key + " has been placed.");

            /*         var return_message = sendSms((int)orderDetails["Contact_ID"], key);
             *
             *       return return_message;
             *   }
             *   catch(Exception e)
             *   {
             *       ExceptionLog.LogException(e, "CustomerOrderController POST");
             *       return "false|An error has occured adding the Customer Order to the system.";
             *   }*/
        }
Beispiel #8
0
        // POST: api/Invoice
        public string Post(HttpRequestMessage value)
        {
            try
            {
                Model.Invoice inv = new Model.Invoice();

                string  message = HttpContext.Current.Server.UrlDecode(value.Content.ReadAsStringAsync().Result).Substring(5);
                JObject json    = JObject.Parse(message);
                string  action  = (string)json["action"];

                int key = db.Invoices.Count() == 0 ? 1 : (from t in db.Invoices
                                                          orderby t.Invoice_ID descending
                                                          select t.Invoice_ID).First() + 1;

                inv.Invoice_ID        = key;
                inv.Invoice_Date      = (DateTime)json["Invoice_Date"];
                inv.Invoice_Status_ID = 1;
                inv.Delivery_Note_ID  = (int)json["Delivery_Note_ID"];
                inv.amount_noVat      = (decimal)json["amount_noVat"];
                inv.amount_Vat        = (decimal)json["amount_Vat"];

                string errorString = "false|";
                bool   error       = false;

                if ((from t in db.Invoices
                     where t.Delivery_Note_ID == inv.Delivery_Note_ID
                     select t).Count() != 0)
                {
                    error        = true;
                    errorString += "The Delivery Note Number already has an Invoice on the system. ";
                }

                if (error)
                {
                    return(errorString);
                }

                db.Invoices.Add(inv);
                db.SaveChanges();

                if (action == "email")
                {
                    string to      = (string)json["email"];
                    string subject = "WME Invoice #" + key;

                    String orderDate = inv.Invoice_Date.ToShortDateString();
                    string body      = "Walter Meano Engineering Invoice #" + key + "\nThe invoice was generated on " + orderDate + "\n\nItems payable:\n";

                    List <Delivery_Note_Details> parts = (from p in db.Delivery_Note_Details
                                                          where p.Delivery_Note_ID == inv.Delivery_Note_ID
                                                          select p).ToList();

                    foreach (Delivery_Note_Details part in parts)
                    {
                        Part_Type partDetails = (from p in db.Delivery_Note_Details
                                                 where p.Delivery_Note_ID == inv.Delivery_Note_ID
                                                 select p.Client_Order_Detail.Part_Type).First();
                        body += partDetails.Name + "\t\tx" + part.Quantity_Delivered + "\t" + part.Client_Order_Detail.Part_Price + " per unit\n";
                    }

                    body += "\nAmount payable VAT Excl.:\t" + inv.amount_noVat;
                    body += "\nAmount payable VAT Incl.:\t" + inv.amount_Vat;

                    Email.SendEmail(to, subject, body);
                }

                return("true|Invoice #" + key + " successfully added.|" + key);
            }
            catch (Exception e)
            {
                ExceptionLog.LogException(e, "InvoiceController POST");
                return("false|An error has occured adding the Invoice to the system.");
            }
        }