public PurchaseOrder(int id, Supplier supplier, string deliverAdd, string attn, DateTime expectedDate, DateTime createdDate, Employee createdBy, DateTime approvedDate, Employee approvedBy, int status, string deliveryOrderNo, DateTime deliveryDate, Employee acceptedBy)
 {
     this.Id = id;
     this.Supplier = supplier;
     this.DeliverAddress = deliverAdd;
     this.Attn = attn;
     this.ExpectedDate = expectedDate;
     this.CreatedDate = createdDate;
     this.CreatedBy = createdBy;
     this.ApprovedDate = approvedDate;
     this.ApprovedBy = approvedBy;
     this.Status = status;
     this.DeliveryOrderNumber = deliveryOrderNo;
     this.DeliveryDate = deliveryDate;
     this.AcceptedBy = acceptedBy;
 }
        /// <summary>
        ///  Logically delete the Supplier by setting the status to 2 in the Supplier table
        ///   Return Constants.DB_STATUS
        /// </summary>
        /// <param name="supplier"></param>
        /// <returns></returns>
        public Constants.DB_STATUS Delete(Supplier supplier)
        {
            Constants.DB_STATUS status = Constants.DB_STATUS.UNKNOWN;

            try
            {
                supplierObj = inventory.Suppliers.Where(iObj => iObj.Id == supplier.Id).First();
                supplierObj.Status = 2;
                inventory.SaveChanges();
                status = Constants.DB_STATUS.SUCCESSFULL;
            }
            catch (Exception e)
            {
                status = Constants.DB_STATUS.FAILED;
            }
            return status;
        }
 /// <summary>
 /// Create a new Supplier object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="name">Initial value of the Name property.</param>
 /// <param name="priority">Initial value of the Priority property.</param>
 /// <param name="contactName">Initial value of the ContactName property.</param>
 /// <param name="phoneNumber">Initial value of the PhoneNumber property.</param>
 /// <param name="faxNumber">Initial value of the FaxNumber property.</param>
 /// <param name="address">Initial value of the Address property.</param>
 /// <param name="createdDate">Initial value of the CreatedDate property.</param>
 /// <param name="status">Initial value of the Status property.</param>
 public static Supplier CreateSupplier(global::System.String id, global::System.String name, global::System.Int32 priority, global::System.String contactName, global::System.String phoneNumber, global::System.String faxNumber, global::System.String address, global::System.DateTime createdDate, global::System.Int32 status)
 {
     Supplier supplier = new Supplier();
     supplier.Id = id;
     supplier.Name = name;
     supplier.Priority = priority;
     supplier.ContactName = contactName;
     supplier.PhoneNumber = phoneNumber;
     supplier.FaxNumber = faxNumber;
     supplier.Address = address;
     supplier.CreatedDate = createdDate;
     supplier.Status = status;
     return supplier;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the Suppliers EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToSuppliers(Supplier supplier)
 {
     base.AddObject("Suppliers", supplier);
 }
 /// <summary>
 /// Retrieve the Supplier information according to the Supplier Parameter 
 /// </summary>
 /// <param name="supplier"></param>
 /// <returns></returns>
 public Supplier GetSupplier(Supplier supplier)
 {
     supplierObj = inventory.Suppliers.Where(iObj => iObj.Id == supplier.Id).First();
     if (!supplierObj.Equals(null))
         return supplierObj;
     return null;
 }
        /// <summary>
        /// Update Supplier data to the Supplier Table according to the Supplier Parameter
        ///  Return Constants.DB_STATUS
        /// </summary>
        /// <param name="supplier"></param>
        /// <returns></returns>
        public Constants.DB_STATUS Update(Supplier supplier)
        {
            Constants.DB_STATUS status = Constants.DB_STATUS.UNKNOWN;

            try
            {
                supplierObj = inventory.Suppliers.Where(iObj => iObj.Id == supplier.Id).First();
                if (!supplierObj.Equals(null))
                {
                    Employee createdBy = inventory.Employees.Where(e => e.Id == supplier.CreatedBy.Id).First();
                    supplierObj.Id = supplier.Id;
                    supplierObj.Name = supplier.Name;
                    supplierObj.Priority = supplier.Priority;
                    supplierObj.ContactName = supplier.ContactName;
                    supplierObj.PhoneNumber = supplier.PhoneNumber;
                    supplierObj.FaxNumber = supplier.FaxNumber;
                    supplierObj.Address = supplier.Address;
                    supplierObj.GstRegistrationNumber = supplier.GstRegistrationNumber;
                    supplierObj.CreatedDate = supplier.CreatedDate;
                    supplierObj.CreatedBy = createdBy;

                    inventory.SaveChanges();
                    status = Constants.DB_STATUS.SUCCESSFULL;
                }
            }
            catch (Exception e)
            {
                status = Constants.DB_STATUS.FAILED;
            }

            return status;
        }
        /// <summary>
        ///  Insert Supplier data to the Supplier Table according to the Supplier Parameter
        ///   Return Constants.DB_STATUS
        /// </summary>
        /// <param name="newSupplier"></param>
        /// <returns></returns>
        public Constants.DB_STATUS Insert(Supplier newSupplier)
        {
            Constants.DB_STATUS status = Constants.DB_STATUS.UNKNOWN;

            try
            {
                Employee employee = inventory.Employees.Where(eObj => eObj.Id == 1).First();
                newSupplier.CreatedBy = employee;
                inventory.AddToSuppliers(newSupplier);
                inventory.SaveChanges();
                status = Constants.DB_STATUS.SUCCESSFULL;
            }
            catch (Exception e)
            {
                status = Constants.DB_STATUS.FAILED;
            }

            return status;
        }
        public Constants.ACTION_STATUS SelectSave(string supplierCode, string deliveryAddress, string attn, DateTime expectedDate)
        {
            Constants.ACTION_STATUS saveStatus = Constants.ACTION_STATUS.UNKNOWN;

            Supplier supplier = new Supplier();
            supplier.Id = supplierCode;
            supplier = supplierBroker.GetSupplier(supplier);
            purchaseOrder.Supplier = supplier;

            purchaseOrder.DeliverAddress = deliveryAddress;
            purchaseOrder.Attn = attn;
            purchaseOrder.ExpectedDate = expectedDate;

            PurchaseOrderDetail purchaseOrderDetail;
            int addedDetail = 0;

            // reorder item
            foreach (Item temp in reorderList)
            {
                item = new Item();
                item.Id = temp.Id;
                item = itemBroker.GetItem(item);

                purchaseOrderDetail = new PurchaseOrderDetail(purchaseOrderBroker.GetPurchaseOrderDetailId() + (addedDetail++), purchaseOrder, item, temp.Cost, temp.ReorderQty, 0);

                purchaseOrder.PurchaseOrderDetails.Add(purchaseOrderDetail);
            }

            // manually added item
            foreach (Item item in addedItemList.Keys)
            {
                purchaseOrderDetail = new PurchaseOrderDetail(purchaseOrderBroker.GetPurchaseOrderDetailId() + (addedDetail++), purchaseOrder, item, (decimal)Converter.objToDouble(addedItemList[item][1]), Converter.objToInt(addedItemList[item][0]), 0);

                purchaseOrder.PurchaseOrderDetails.Add(purchaseOrderDetail);
            }

            if (purchaseOrderBroker.Insert(purchaseOrder) == Constants.DB_STATUS.SUCCESSFULL)
            {
                saveStatus = Constants.ACTION_STATUS.SUCCESS;
            }
            else
            {
                saveStatus = Constants.ACTION_STATUS.FAIL;
            }

            return saveStatus;
        }
        /// <summary>
        /// Get the Suppliert List according to the Item
        /// </summary>
        /// <param name="item"></param>
        /// <returns>
        /// List of supplier list
        /// </returns>
        public List<Supplier> GetPrioritySupplier(Item item)
        {
            try
            {
                supplierList = new List<Supplier>();
                SupplierBroker supplierBroker = new SupplierBroker(this.inventory);

                itemPriceList = inventory.ItemPrices.Where(itemPrice => itemPrice.ItemId == item.Id).ToList<ItemPrice>();

                Supplier supplier;

                foreach (ItemPrice itemPrice in itemPriceList)
                {
                    supplier = new Supplier();
                    supplier.Id = itemPrice.SupplierId;
                    supplier = supplierBroker.GetSupplier(supplier);

                    supplierList.Add(supplier);
                }

                supplierList.Sort();

            }
            catch (Exception e)
            {
                supplierList = null;
            }
            return supplierList;
        }