Ejemplo n.º 1
0
        private static BLL.OrderDetail GetOrderDetail(int?orderID, IEnumerable <ApprovedOrderDetail> plitsApprovedOrderDetails)
        {
            var hcmisOrderDetail = new BLL.OrderDetail();

            //var plitsApprovedOrderDetails = plitsApprovedOrderDetail as List<ApprovedOrderDetail> ?? plitsApprovedOrderDetail.ToList();
            foreach (var plitsOrderDetail in plitsApprovedOrderDetails)
            {
                hcmisOrderDetail.AddNew();
                hcmisOrderDetail.ItemID            = plitsOrderDetail.PharmaceuticalId;
                hcmisOrderDetail.HACTOrderDetailID = plitsOrderDetail.Id;
                hcmisOrderDetail.Pack = Convert.ToDecimal(plitsOrderDetail.ApprovedQty);

                BLL.ItemUnit iu = new ItemUnit();
                iu.LoadAllForItem(plitsOrderDetail.PharmaceuticalId); //Just load it by item id.  This loads a collection but we just pick and use the first one. :)

                if (iu.RowCount == 0)
                {
                    hcmisOrderDetail.QtyPerPack = iu.QtyPerUnit;
                    hcmisOrderDetail.Quantity   = hcmisOrderDetail.Pack * iu.QtyPerUnit;
                    hcmisOrderDetail.UnitID     = iu.ID;
                    throw new Exception(string.Format("IU Not Configured correctly for item: {0}",
                                                      plitsOrderDetail.PharmaceuticalId));
                }

                hcmisOrderDetail.QtyPerPack = iu.QtyPerUnit;
                hcmisOrderDetail.Quantity   = hcmisOrderDetail.Pack * iu.QtyPerUnit;
                hcmisOrderDetail.UnitID     = iu.ID;
            }


            return(hcmisOrderDetail);
        }
Ejemplo n.º 2
0
        public ItemModel(string name, string description, decimal quantity, ItemUnit itemunit, decimal cost)
        {
            ItemName  = name;
            ItemPrice = cost.ToString() + "PLN";
            if (description != null)
            {
                ItemDescription = description;
            }
            else
            {
                ItemDescription = "";
            }
            switch (itemunit)
            {
            case ItemUnit.m:
                Quantity = quantity + " m";
                break;

            case ItemUnit.piece:
                Quantity = quantity.ToString();
                break;

            default:
                break;
            }
        }
        private void Btn_unSelectedItem_Click(object sender, RoutedEventArgs e)
        {//unselect item
            try
            {
                itemUnitOffer = dg_selectedItems.SelectedItem as ItemUnitOffer;
                ItemUnit i = new ItemUnit();
                if (itemUnitOffer != null)
                {
                    i = allItemsSource.Where(s => s.itemUnitId == itemUnitOffer.iuId.Value).FirstOrDefault();

                    allItems.Add(i);

                    selectedItems.Remove(itemUnitOffer);

                    dg_allItems.ItemsSource      = allItems;
                    dg_selectedItems.ItemsSource = selectedItems;

                    dg_allItems.Items.Refresh();
                    dg_selectedItems.Items.Refresh();
                }
            }
            catch (Exception ex)
            {
                SectionData.ExceptionMessage(ex, this);
            }
        }
        private void Btn_selectedItem_Click(object sender, RoutedEventArgs e)
        {//select item
            try
            {
                itemUnit = dg_allItems.SelectedItem as ItemUnit;
                if (itemUnit != null)
                {
                    ItemUnitOffer iUO = new ItemUnitOffer();
                    iUO.ioId         = 0;
                    iUO.iuId         = itemUnit.itemUnitId;
                    iUO.offerId      = offerId;
                    iUO.createUserId = MainWindow.userID;
                    iUO.quantity     = 1;
                    iUO.offerName    = offer.name;
                    iUO.unitName     = itemUnit.unitName;
                    iUO.itemName     = itemUnit.itemName;
                    iUO.itemId       = itemUnit.itemId;
                    iUO.unitId       = itemUnit.unitId;

                    allItems.Remove(itemUnit);
                    selectedItems.Add(iUO);

                    dg_allItems.ItemsSource      = allItems;
                    dg_selectedItems.ItemsSource = selectedItems;

                    dg_allItems.Items.Refresh();
                    dg_selectedItems.Items.Refresh();
                }
            }
            catch (Exception ex)
            {
                SectionData.ExceptionMessage(ex, this);
            }
        }
Ejemplo n.º 5
0
        public async Task <ActionResult> Edit(ItemUnit itemUnit)
        {
            var item = db.ItemUnits.Where(x => x.Name == itemUnit.Name && x.Id != itemUnit.Id);

            if (item.Count() == 0)
            {
                if (ModelState.IsValid)
                {
                    db.Entry(itemUnit).State = EntityState.Modified;
                    await db.SaveChangesAsync();

                    return(RedirectToAction("Create"));
                }
            }

            else
            {
                ViewBag.Duplicate = "Already Exist";
            }


            ItemUnitViewModel ItemUnitViewModel = new ItemUnitViewModel();

            ItemUnitViewModel.ItemUnits = db.ItemUnits.ToList();
            ItemUnitViewModel.Id        = itemUnit.Id;
            ItemUnitViewModel.Name      = itemUnit.Name;
            return(View(ItemUnitViewModel));
        }
Ejemplo n.º 6
0
        public static bool IsExistCOGS(Session session, ItemUnit itemUnit, CurrencyType currencyType)
        {
            bool result = false;

            try
            {
                CriteriaOperator criteria_0 = new BinaryOperator("ItemUnitId", itemUnit, BinaryOperatorType.Equal);
                CriteriaOperator criteria_1 = new BinaryOperator("CurrencyId.CurrencyTypeId.CurrencyTypeId", currencyType.CurrencyTypeId, BinaryOperatorType.Equal);
                CriteriaOperator criteria   = new GroupOperator(GroupOperatorType.And, criteria_0, criteria_1);
                COGS             cogs       = session.FindObject <COGS>(criteria);
                if (cogs == null)
                {
                    result = false;
                }
                else
                {
                    result = true;
                }
            }
            catch (Exception)
            {
                return(result);
            }
            return(result);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// The save button should be active only when the date is Sene 30 or in the month of Hamle.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void YearEndProcess_Load(object sender, EventArgs e)
        {
            var ethDate = new EthiopianDate.EthiopianDate();

            lkCommodityTypes.Properties.DataSource = BLL.Type.GetAllTypes();
            lkCommodityTypes.ItemIndex             = 0;
            btnSave.Enabled = false;
            var unit     = new ItemUnit();
            var allunits = unit.GetAllUnits();

            unitBindingSource.DataSource = allunits.DefaultView;
            var unitcolumn = ((GridView)grdYearEnd.MainView).Columns[9];

            switch (VisibilitySetting.HandleUnits)
            {
            case 1:
                unitcolumn.Visible = false;
                break;

            case 2:
                unitcolumn.Visible = true;
                break;

            default:
                unitcolumn.Visible = true;
                break;
            }
            var str = new Stores();

            str.GetActiveStores();

            cboStores.Properties.DataSource = str.DefaultView;
            cboStores.ItemIndex             = 0;
            dtDate.CustomFormat             = "MMMM dd, yyyy";
        }
Ejemplo n.º 8
0
        public void ChangeItemName(string[] @params, TPlayObject PlayObject)
        {
            int    nMakeIndex;
            int    nItemIndex;
            string sMakeIndex = @params.Length > 0 ? @params[0] : "";
            string sItemIndex = @params.Length > 1 ? @params[1] : "";
            string sItemName  = @params.Length > 2 ? @params[2] : "";

            if ((PlayObject.m_btPermission < 6))
            {
                return;
            }
            if ((sMakeIndex == "") || (sItemIndex == "") || (sItemName == ""))
            {
                PlayObject.SysMsg("命令格式: @" + this.Attributes.Name + " 物品编号 物品ID号 物品名称", TMsgColor.c_Red, TMsgType.t_Hint);
                return;
            }
            nMakeIndex = HUtil32.Str_ToInt(sMakeIndex, -1);
            nItemIndex = HUtil32.Str_ToInt(sItemIndex, -1);
            if ((nMakeIndex <= 0) || (nItemIndex < 0))
            {
                PlayObject.SysMsg("命令格式: @" + this.Attributes.Name + " 物品编号 物品ID号 物品名称", TMsgColor.c_Red, TMsgType.t_Hint);
                return;
            }
            if (ItemUnit.AddCustomItemName(nMakeIndex, nItemIndex, sItemName))
            {
                ItemUnit.SaveCustomItemName();
                PlayObject.SysMsg("物品名称设置成功。", TMsgColor.c_Green, TMsgType.t_Hint);
                return;
            }
            PlayObject.SysMsg("此物品,已经设置了其它的名称!!!", TMsgColor.c_Red, TMsgType.t_Hint);
        }
Ejemplo n.º 9
0
        public async Task <ActionResult> Create(ItemUnit itemUnit)
        {
            var item = db.ItemUnits.Where(x => x.Name == itemUnit.Name);

            if (item.Count() == 0)
            {
                if (ModelState.IsValid)
                {
                    itemUnit.Id = Guid.NewGuid();
                    db.ItemUnits.Add(itemUnit);
                    await db.SaveChangesAsync();

                    return(RedirectToAction("Create"));
                }
            }

            else
            {
                ViewBag.Duplicate = "Already Exist";
            }
            ItemUnitViewModel ItemUnitViewModel = new ItemUnitViewModel();

            ItemUnitViewModel.ItemUnits = db.ItemUnits.ToList();
            ItemUnitViewModel.Id        = itemUnit.Id;
            ItemUnitViewModel.Name      = itemUnit.Name;
            return(View(ItemUnitViewModel));
        }
Ejemplo n.º 10
0
 public void AddItem(ItemUnit item)
 {
     Debug.Log(item.Item());
     //wrapper class : Item Unit (Drag And Drop Item)
     //unit.RemoveFirstItem();
     unit.AddItemInFreeCell(item.Item());
 }
        private void LoadMaster()
        {
            //Populate Item Name
            Item item = new Item();

            item.LoadByPrimaryKey(ItemID);
            txtitem.Text = item.FullItemName;

            //Populate Manufacturer
            Manufacturer mf = new Manufacturer();

            mf.LoadByPrimaryKey(ManufacturerID);
            txtManufacturer.Text = mf.Name;

            //Populate Unit
            ItemUnit unit = new ItemUnit();

            unit.LoadByPrimaryKey(UnitID);
            txtUnit.Text = unit.Text;

            //Populate Account
            Account Account = new Account();

            Account.LoadByPrimaryKey(StoreID);
            txtAccount.Text = Account.Name;
            if (BLL.Settings.IsCenter)
            {
                layoutSellingPrice.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
            }
        }
        private void LoadUnitsForChange()
        {
            ItemUnit itemUnit = new ItemUnit();

            itemUnit.LoadAllForItem(ItemIDTo);
            lkUnitTo.Properties.DataSource = itemUnit.DefaultView;
        }
Ejemplo n.º 13
0
        private void AddEdgeRewardItemCommandExecute()
        {
            var itemUnit = new ItemUnit(NewRewardEdgeItemType.ItemType, NewRewardEdgeItemTypeCount);

            SelectedEdge.AddRecievedUnit(itemUnit);
            AddEdgeRewardItemCommand.RaiseCanExecuteChanged();
        }
Ejemplo n.º 14
0
        public InventoryLedger GetPreviousInventoryLedger(Session session, DateTime IssueDate, Guid InventoryId, Guid AccountId, Guid LotID, Guid ItemUnitId)
        {
            InventoryLedger result = null;

            try
            {
                NAS.DAL.Nomenclature.Inventory.Inventory inventory = session.GetObjectByKey <NAS.DAL.Nomenclature.Inventory.Inventory>(InventoryId);
                Account  account  = session.GetObjectByKey <Account>(AccountId);
                Lot      lot      = session.GetObjectByKey <Lot>(LotID);
                ItemUnit itemUnit = session.GetObjectByKey <ItemUnit>(ItemUnitId);
                if (inventory == null || account == null || lot == null || itemUnit == null)
                {
                    return(null);
                }

                CriteriaOperator criteria_RowStatus = new BinaryOperator("RowStatus", Constant.ROWSTATUS_ACTIVE, BinaryOperatorType.GreaterOrEqual);
                CriteriaOperator criteria_IssueDate = new BinaryOperator("IssueDate", IssueDate, BinaryOperatorType.LessOrEqual);
                CriteriaOperator criteria_Inventory = new BinaryOperator("InventoryId", inventory, BinaryOperatorType.Equal);
                CriteriaOperator criteria_Account   = new BinaryOperator("AccountId", account, BinaryOperatorType.Equal);
                CriteriaOperator criteria_Lot       = new BinaryOperator("LotId", lot, BinaryOperatorType.Equal);
                CriteriaOperator criteria_ItemUnit  = new BinaryOperator("ItemUnitId", itemUnit, BinaryOperatorType.Equal);

                CriteriaOperator criteria = CriteriaOperator.And(criteria_IssueDate, criteria_RowStatus, criteria_Inventory, criteria_Account, criteria_Lot, criteria_ItemUnit);

                XPCollection <InventoryLedger> inventoryLedgerCol = new XPCollection <InventoryLedger>(session, criteria);
            }
            catch (Exception)
            {
                return(result);
            }
            return(result);
        }
Ejemplo n.º 15
0
        public InventoryLedger GetNewestInventoryLedgerByDate(Session session, Guid _ItemUnitId, Guid _InventoryId, DateTime _IssueDate)
        {
            try
            {
                ItemUnit _ItemUnit = session.GetObjectByKey <ItemUnit>(_ItemUnitId);
                NAS.DAL.Nomenclature.Inventory.Inventory _Inventory = session.GetObjectByKey <NAS.DAL.Nomenclature.Inventory.Inventory>(_InventoryId);

                if (_ItemUnit == null || _Inventory == null)
                {
                    return(null);
                }

                CriteriaOperator criteria_RowStatus = new BinaryOperator("RowStatus", Constant.ROWSTATUS_ACTIVE, BinaryOperatorType.GreaterOrEqual);
                CriteriaOperator criteria_ItemUnit  = new BinaryOperator("ItemUnitId", _ItemUnit, BinaryOperatorType.Equal);
                CriteriaOperator criteria_Inventory = new BinaryOperator("InventoryId", _Inventory, BinaryOperatorType.Equal);
                CriteriaOperator criteria_IssueDate = new BinaryOperator("IssueDate", _IssueDate, BinaryOperatorType.LessOrEqual);

                CriteriaOperator criteria = CriteriaOperator.And(criteria_Inventory, criteria_ItemUnit, criteria_RowStatus);
                XPCollection <InventoryLedger> InventoryLedgerCol = new XPCollection <InventoryLedger>(session, criteria);
                InventoryLedgerCol.Sorting.Add(new SortProperty("IssueDate", SortingDirection.Descending));
                InventoryLedgerCol.Sorting.Add(new SortProperty("CreateDate", SortingDirection.Descending));
                InventoryLedger newestLedger = InventoryLedgerCol.FirstOrDefault();
                return(newestLedger);
            }
            catch (Exception)
            {
                return(null);
            }
        }
Ejemplo n.º 16
0
    public ItemUnit GetItem()
    {
        ItemUnit item = Instantiate(prefabItem);

        item.status = list[Random.Range(0, list.Count)];
        return(item);
    }
        public void CreateDetailTransactionsForErrorCorrection(Order order, BLL.PickList picklist,
                                        Issue stvLog, int receiptPalletId, int receiptID, User user, DateTime convertedEthDate
                                        , int newItemId, int newUnitId, int newManufacturerId, decimal pickedPack
                                        , decimal Convertedpack, int confirmationStatusId, bool changeExpiryDate
                                        , DateTime? ExpiryDate, bool changeBatchNo, string batchNo)
        {
            //Load the ReceivePallet First From that we Get the Information that We need
            ReceivePallet receivePalletOriginal = new ReceivePallet();
            receivePalletOriginal.LoadByPrimaryKey(receiptPalletId);

            ReceiveDoc receiveDocOriginal = new ReceiveDoc();
            receiveDocOriginal.LoadByPrimaryKey(receivePalletOriginal.ReceiveID);

            //Load ItemUnit Detail for For ItemUnit Change;
            ItemUnit newItemUnit = new ItemUnit();
            newItemUnit.LoadByPrimaryKey(newUnitId);

              // Generate PicklistDetail With OrderDetail information
            PickListService pickListService = new PickListService();
            PickListDetail pickListDetail = pickListService.CreatePicklistDetailWithOrder(receiveDocOriginal, receivePalletOriginal, order, picklist,
                                                          pickedPack);
            // Generate IssueDoc from picklistDetail and substract the quantity from receiveDoc
            IssueService issueService = new IssueService();
            issueService.CreateIssueFromPicklist(pickListDetail, order, convertedEthDate, stvLog, user);

            if (Convertedpack > 0)
            {
                //duplicate The ReceiveDoc and ReceiptPallet
                ReceiveService receiveService = new ReceiveService();
                receiveService.CloneReceiveForErrorCorrection(confirmationStatusId, receivePalletOriginal, receiveDocOriginal
                                                                , Convertedpack, user, newItemId
                                                                , receiveDocOriginal.StoreID, receiptID
                                                                , newManufacturerId, newItemUnit, convertedEthDate,changeExpiryDate,ExpiryDate,changeBatchNo,batchNo);
            }
        }
Ejemplo n.º 18
0
 /// <summary>
 /// 检查当前输入的药品是否满足处方规则
 /// </summary>
 /// <param name="druggery">药品对象</param>
 /// <param name="amount">数量</param>
 /// <param name="unit">当前数量使用的单位</param>
 public void CheckDruggery(Druggery druggery, decimal amount, ItemUnit unit)
 {
     if (m_HadInitialized && (druggery != null) && druggery.KeyInitialized)
     {
         CheckItemOrDruggery(true, druggery.Catalog.Code, druggery.ProductSerialNo, druggery.Code);
         CheckItemAmount(druggery.ProductSerialNo, druggery.Code, amount, unit, druggery.SpecUnit, druggery.WardUnit);
     }
 }
Ejemplo n.º 19
0
 public void AddItem(ItemUnit _item)
 {
     if (_item == null)
     {
         Debug.LogWarning("!!!!!!!!!!!???????????");
         return;
     }
     GetComponent <DragAndDropCell>().AddItem(_item.Item());
 }
Ejemplo n.º 20
0
 /// <summary>
 /// 检查当前输入的项目是否满足处方规则
 /// </summary>
 /// <param name="item">项目对象</param>
 /// <param name="amount">数量</param>
 /// <param name="unit">当前数量使用的单位</param>
 public void CheckItem(ChargeItem item, decimal amount, ItemUnit unit)
 {
     if (m_HadInitialized && (item != null) && item.KeyInitialized)
     {
         string itemKind = Convert.ToInt32(item.Kind).ToString();
         CheckItemOrDruggery(false, itemKind, 0, item.Code);
         CheckItemAmount(0, item.Code, amount, unit, item.BaseUnit, item.BaseUnit);
     }
 }
Ejemplo n.º 21
0
        public ActionResult Create(ItemUnit u)
        {
            u.StatusActive = true;
            context.ItemUnits.Add(u);
            context.SaveChanges();

            TempData["SuccessMSG"] = "You have successfully added Unit.";
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 22
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="uow"></param>
        /// <param name="credit"></param>
        /// <param name="debit"></param>
        /// <param name="createDate"></param>
        /// <param name="price"></param>
        /// <param name="issueDate"></param>
        /// <param name="inventoryTransactionId"></param>
        /// <param name="inventoryId"></param>
        /// <param name="itemUnitId"></param>
        /// <param name="CurrencyId"></param>
        public void CreateCOGS(
            Session session,
            double credit,
            double debit,
            DateTime createDate,
            double price,
            DateTime issueDate,
            Guid inventoryTransactionId,
            Guid inventoryId,
            Guid itemUnitId,
            Guid currencyId)
        {
            InventoryTransaction transaction = session.GetObjectByKey <InventoryTransaction>(inventoryTransactionId);

            if (transaction == null)
            {
                throw new Exception("The InventoryTransaction is not exist in system");
            }

            NAS.DAL.Nomenclature.Inventory.Inventory inventory =
                session.GetObjectByKey <NAS.DAL.Nomenclature.Inventory.Inventory>(inventoryId);
            if (inventory == null)
            {
                throw new Exception("The Inventory is not exist in system");
            }

            ItemUnit itemUnit = session.GetObjectByKey <ItemUnit>(itemUnitId);

            if (itemUnit == null)
            {
                throw new Exception("The ItemUnit is not exist in system");
            }

            Currency currency = session.GetObjectByKey <Currency>(currencyId);

            if (currency == null)
            {
                throw new Exception("The Currency is not exist in system");
            }

            COGS cogs = new COGS(session);

            cogs.Balance                = 0;
            cogs.Total                  = 0;
            cogs.Credit                 = credit;
            cogs.Debit                  = debit;
            cogs.CreateDate             = createDate;
            cogs.UpdateDate             = createDate;
            cogs.Price                  = price;
            cogs.Assumption             = 1;
            cogs.IssueDate              = issueDate;
            cogs.InventoryTransactionId = transaction;
            cogs.InventoryId            = inventory;
            cogs.ItemUnitId             = itemUnit;
            cogs.CurrencyId             = currency;
            cogs.Save();
        }
Ejemplo n.º 23
0
        public async Task <ActionResult> DeleteConfirmed(Guid id)
        {
            ItemUnit itemUnit = await db.ItemUnits.FindAsync(id);

            db.ItemUnits.Remove(itemUnit);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 24
0
    private void UpdateItem()
    {
        ItemUnit old = item;

        item = GetComponentInChildren <ItemUnit>();
        if (old != item)
        {
            OnChanged?.Invoke(item);
        }
    }
        // Load Filter
        // Construct the General Filter String

        private void LoadUnitsForSelectedItem()
        {
            ItemUnit itemUnit = new ItemUnit();

            if (ShowOnlyReceivedItemUnit)
            {
                itemUnit.LoadReceivedByItemID(ItemID);
            }
            lkUnit.Properties.DataSource = itemUnit.DefaultView;
        }
Ejemplo n.º 26
0
        public bool DeleteItemUnit(ItemUnit data)
        {
            SqlParameter[] sqlParameters = new SqlParameter[]
            {
                new SqlParameter("@ItemUnitID", data.ItemUnitID)
            };

            this.Context.ExecuteDataFromProcedure("ItemUnitDelete", sqlParameters);

            return(true);
        }
Ejemplo n.º 27
0
 public static Tbl_ItemUnit MapFrom(this ItemUnit item)
 {
     return(new Tbl_ItemUnit
     {
         Id = item.Id,
         NameAr = item.NameAr,
         NameEn = item.NameEn,
         Created_At = item.Id <= 0 ? DateTime.Now : default(DateTime?),
         Updated_At = item.Id > 0 ? DateTime.Now : default(DateTime?),
     });
 }
Ejemplo n.º 28
0
 public ActionResult Edit(ItemUnit u)
 {
     if (ModelState.IsValid)
     {
         context.Entry(u).State = EntityState.Modified;
         context.SaveChanges();
         TempData["SuccessMSG"] = "You have successfully updated Unit.";
         return(RedirectToAction("Index"));
     }
     return(View());
 }
Ejemplo n.º 29
0
        protected void cboItem_ItemRequestedByValue(object source, ListEditItemRequestedByValueEventArgs e)
        {
            ASPxComboBox comboItemUnit = source as ASPxComboBox;
            ItemUnit     obj           = session.GetObjectByKey <ItemUnit>(e.Value);

            if (obj != null)
            {
                comboItemUnit.DataSource = new ItemUnit[] { obj };
                comboItemUnit.DataBindItems();
            }
        }
Ejemplo n.º 30
0
        public void SettingInit(ASPxButton SourceButton, ASPxComboBox SourceComboBox)
        {
            initCommonJavascript();

            if (SourceComboBox == null)
            {
                SourceButton.ClientSideEvents.Click =
                    "function(s, e){ " +
                    string.Format("{0}.PerformCallback('Show');", MainControlClientName) +
                    " }";
            }
            else
            {
                SourceButton.ClientSideEvents.Click =
                    "function(s, e){ " +
                    "var validated = ASPxClientEdit.ValidateEditorsInContainer(" +
                    SourceComboBox.ClientID +
                    ".GetMainElement(), null, true); if (validated) {" +
                    string.Format("{0}.PerformCallback('Show');", MainControlClientName) +
                    " }}";
            }

            DevExpress.Web.ASPxGridView.ASPxGridView grd = (SourceButton.NamingContainer as
                                                            DevExpress.Web.ASPxGridView.GridViewHeaderTemplateContainer).Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent as
                                                           DevExpress.Web.ASPxGridView.ASPxGridView;
            ImportedItemUnitId = Guid.Empty;
            if (grd == null)
            {
                return;
            }

            this.ComboBoxItemUnit = SourceComboBox;

            ItemUnit itemUnit = null;

            if (grd.EditingRowVisibleIndex >= 0)
            {
                ImportedItemUnitId = Guid.Parse(grd.GetRowValues(grd.EditingRowVisibleIndex, "ItemUnitId!Key").ToString());
                itemUnit           = session.GetObjectByKey <ItemUnit>(ImportedItemUnitId);
            }
            else if (grd.IsNewRowEditing && this.ComboBoxItemUnit != null)
            {
                itemUnit = session.GetObjectByKey <ItemUnit>(this.ComboBoxItemUnit.Value);
                if (itemUnit == null)
                {
                    itemUnit = session.GetObjectByKey <ItemUnit>(this.ComboBoxItemUnit.Value);
                }
            }

            if (itemUnit != null)
            {
                lblItem.Text = itemUnit.ItemId.Code;
            }
        }
        private async Task setToquantityMessage()
        {
            int quantity = 0;
            int remain   = 0;

            if (tb_fromQuantity.Text != "")
            {
                quantity = int.Parse(tb_fromQuantity.Text);
            }
            if (quantity != 0 && tb_fromQuantity.Text != "" && cb_fromUnit.SelectedIndex != -1 && cb_toUnit.SelectedIndex != -1)
            {
                isSmall = smallUnits.Find(x => x.itemUnitId == (int)cb_toUnit.SelectedValue);
                if (isSmall != null) // from-unit is bigger than to-unit
                {
                    _ConversionQuantity = await itemUnit.largeToSmallUnitQuan((int)cb_fromUnit.SelectedValue, (int)cb_toUnit.SelectedValue);

                    _ToQuantity   = quantity * _ConversionQuantity;
                    _FromUnit     = "";
                    _FromQuantity = quantity;
                }
                else
                {
                    _ConversionQuantity = await itemUnit.smallToLargeUnit((int)cb_fromUnit.SelectedValue, (int)cb_toUnit.SelectedValue);

                    if (_ConversionQuantity != 0)
                    {
                        _ToQuantity = quantity / _ConversionQuantity;
                        remain      = quantity - (_ToQuantity * _ConversionQuantity); // get remain quantity which cannot be changeed
                    }
                    _FromUnit     = remain.ToString() + " " + cb_fromUnit.Text;
                    _FromQuantity = quantity - remain;
                }
                _ToUnit = _ToQuantity.ToString() + " " + cb_toUnit.Text;
            }

            //_ToQuantity = quantity * conversionQuantity;

            //if (cb_fromUnit.SelectedIndex != -1 && isSmall != null)
            //{
            //    _FromUnit = _ToQuantity.ToString() + " " + cb_fromUnit.Text;
            //    txt_toQuantity.Text = _FromUnit;
            //}

            //if (cb_toUnit.SelectedIndex != -1)
            //{
            //    if(isSmall != null) // from large to small
            //        _ToUnit = _ToQuantity.ToString() + " " + units[cb_toUnit.SelectedIndex].mainUnit;
            //    else if(cb_fromUnit.SelectedIndex != -1)
            //        _FromUnit = remain.ToString() + " " + units[cb_fromUnit.SelectedIndex].mainUnit;
            //}
            txt_toQuantity.Text          = _FromUnit;
            txt_toQuantityRemainder.Text = _ToUnit;
        }
        private ReceiveDoc CreateReceiveDocForInventory(Inventory inventory, int confirmationStatusID, decimal foundQty, int receiptID, DateTime convertedEthDate, User user,string remark)
        {
            ReceiveDoc newReceiveDoc = new ReceiveDoc();
            newReceiveDoc.AddNew();

            newReceiveDoc.SetColumn("BatchNo", inventory.GetColumn("BatchNo"));
            newReceiveDoc.ItemID = inventory.ItemID;
            newReceiveDoc.ManufacturerId = inventory.ManufacturerID;
            newReceiveDoc.SetColumn("UnitID", inventory.UnitID);
            if (!inventory.IsColumnNull("SupplierID"))
                newReceiveDoc.SupplierID = inventory.SupplierID;
            BLL.ItemUnit iu = new ItemUnit();
            iu.LoadByPrimaryKey(inventory.UnitID);
            newReceiveDoc.Quantity = newReceiveDoc.QuantityLeft = foundQty*iu.QtyPerUnit;
            newReceiveDoc.NoOfPack = foundQty;
            newReceiveDoc.InvoicedNoOfPack = foundQty;
            newReceiveDoc.QtyPerPack = iu.QtyPerUnit;
            newReceiveDoc.Date = convertedEthDate;
            newReceiveDoc.SetColumn("ExpDate", inventory.GetColumn("ExpiryDate"));
            newReceiveDoc.Out = false;
            newReceiveDoc.ReceivedBy = user.UserName;
            newReceiveDoc.StoreID = inventory.ActivityID;
            newReceiveDoc.SetColumn("LocalBatchNo", inventory.GetColumn("BatchNo"));
            newReceiveDoc.RefNo = receiptID.ToString();
            newReceiveDoc.SetColumn("Cost", inventory.GetColumn("Cost"));
            newReceiveDoc.SetColumn("IsApproved", DBNull.Value);
            newReceiveDoc.EurDate = DateTimeHelper.ServerDateTime;
            newReceiveDoc.SetColumn("SellingPrice", inventory.GetColumn("SellingPrice"));
            newReceiveDoc.SetColumn("UnitCost", inventory.GetColumn("Cost"));
            newReceiveDoc.SetColumn("Cost", inventory.GetColumn("Cost"));
            newReceiveDoc.SetColumn("PricePerPack", inventory.GetColumn("Cost"));
            newReceiveDoc.SetColumn("DeliveryNote", DBNull.Value);
            newReceiveDoc.Confirmed = true;
            newReceiveDoc.ConfirmedDateTime = DateTimeHelper.ServerDateTime;
            newReceiveDoc.ReturnedStock = false;
            newReceiveDoc.ReceiptID = receiptID;
            newReceiveDoc.SetColumn("Margin", inventory.GetColumn("Margin"));
            newReceiveDoc.RefNo = "BeginningBalance";
            if(!string.IsNullOrEmpty(remark))
            newReceiveDoc.IsDamaged = false;
            if (!string.IsNullOrEmpty(remark))
            {
                newReceiveDoc.Remark = remark;
            }
            newReceiveDoc.Save();

            //Now Save the ReceiveDocConfirmation

            ReceiveDocConfirmation rdConf = new ReceiveDocConfirmation();
            rdConf.AddNew();
            rdConf.ReceiveDocID = newReceiveDoc.ID;
            rdConf.ReceivedByUserID = user.ID;
            rdConf.ReceiptConfirmationStatusID = confirmationStatusID;
            rdConf.Save();

            return newReceiveDoc;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="inventory"></param>
        /// <param name="palletLocation">Please note that the pallet location passed here is going to be used for the sound qty.  A quarantine location in the physical store that the pallet location exists is chosen for the damaged location.  For now, we're using the same pallet location for the expired quantity as well. (Only if the location type is free)</param>
        /// <param name="confirmationStatusID"></param>
        /// <param name="receipt"></param>
        /// <param name="user"></param>
        /// <param name="convertedEthDate"></param>
        /// <param name="remark"></param>
        internal void CreateReceiveEntriesForInventory(Inventory inventory, PalletLocation palletLocation, int confirmationStatusID, Receipt receipt, User user, DateTime convertedEthDate, string remark)
        {
            //Now Save the receive doc entry
            decimal soundQty = inventory.IsColumnNull("InventorySoundQuantity") ? 0 : inventory.InventorySoundQuantity;
            decimal damagedQty = inventory.IsColumnNull("InventoryDamagedQuantity") ? 0 : inventory.InventoryDamagedQuantity;
            decimal expQty = inventory.IsColumnNull("InventoryExpiredQuantity") ? 0 : inventory.InventoryExpiredQuantity;

            //As per the design of the Inventory object, expired and sound cannot be passed using a single object: Why? There's a data memeber for Expiry Date which can only hold one value.
            decimal soundOrExpiredQty = soundQty + expQty;
            decimal totalFoundQty = soundOrExpiredQty + damagedQty;

            ReceiveDoc newReceiveDoc = CreateReceiveDocForInventory(inventory, confirmationStatusID, totalFoundQty,
                                                                    receipt.ID, convertedEthDate, user, remark);

            ReceivePallet newReceivePallet = new ReceivePallet();
            BLL.ItemUnit iu = new ItemUnit();
            iu.LoadByPrimaryKey(inventory.UnitID);

            if (soundOrExpiredQty > 0)
            {
                newReceivePallet.AddNew();
                newReceivePallet.ReceiveID = newReceiveDoc.ID;
                newReceivePallet.ReceivedQuantity = newReceivePallet.Balance = soundOrExpiredQty*iu.QtyPerUnit;
                newReceivePallet.ReservedStock = 0;
                newReceivePallet.PalletID = palletLocation.PalletID;
                newReceivePallet.PalletLocationID = palletLocation.ID;
            }

            if(damagedQty>0)
            {
                newReceivePallet.AddNew();
                newReceivePallet.ReceiveID = newReceiveDoc.ID;
                newReceivePallet.ReceivedQuantity = newReceivePallet.Balance = damagedQty*iu.QtyPerUnit;
                newReceivePallet.ReservedStock = 0;

                if(palletLocation.StorageTypeID==Convert.ToInt32(BLL.StorageType.Quaranteen)) //Was the original pallet stored in a quarantine location?
                {
                    newReceivePallet.PalletID = palletLocation.PalletID;
                    newReceivePallet.PalletLocationID = palletLocation.ID;
                }
                else //The original pallet was not marked as a quarantine or suspension location.  Meaning we need to choose a quarantine location in the same physical store as the original pallet location.
                {
                    BLL.PalletLocation plQuarantine = new PalletLocation();
                    plQuarantine.LoadFirstOrDefault(palletLocation.PhysicalStoreID,
                                                    Convert.ToInt32((StorageType.Quaranteen)));
                    if(plQuarantine.RowCount>0) //There is already quarantine location.
                    {
                        //Pick the first quarantine location.
                        if(plQuarantine.IsColumnNull("PalletID"))
                        {
                            //TODO: Create a Pallet.
                        }

                        newReceivePallet.PalletID = plQuarantine.PalletID;
                        newReceivePallet.PalletLocationID = plQuarantine.ID;
                    }
                    else
                    {
                        //There is no quarantine locaiton in the physical store: This is basically bad news.  We let them know that this is unacceptable.
                        throw new Exception("Please create a quarantine storage location for this store");
                    }
                }
            }
            newReceivePallet.IsOriginalReceive = true;
            newReceivePallet.Save();
        }
        public ReceiveDoc CreateInventoryReceive(Inventory inventory,int receiptID,Inventory.QuantityType quantityType,DateTime ethiopianDate,User user)
        {
            ItemUnit itemUnit = new ItemUnit();
            itemUnit.LoadByPrimaryKey(inventory.UnitID);

            ReceiveDoc receiveDoc = new ReceiveDoc();
            receiveDoc.AddNew();
            receiveDoc.ItemID = inventory.ItemID;
            receiveDoc.UnitID = inventory.UnitID;
            receiveDoc.ManufacturerId = inventory.ManufacturerID;

            receiveDoc.StoreID = inventory.ActivityID;
            receiveDoc.Date = ethiopianDate;
            receiveDoc.EurDate = DateTimeHelper.ServerDateTime;
            receiveDoc.PhysicalStoreID = inventory.PhysicalStoreID;
            receiveDoc.SetColumn("BatchNo", inventory.GetColumn("BatchNo"));
            decimal quantity = quantityType == Inventory.QuantityType.Sound
                                   ? inventory.InventorySoundQuantity
                                   : quantityType == Inventory.QuantityType.Damaged
                                    ? inventory.InventoryDamagedQuantity :inventory.InventoryExpiredQuantity;

            if(quantityType == Inventory.QuantityType.Damaged) receiveDoc.ShortageReasonID = ShortageReasons.Constants.DAMAGED;
            receiveDoc.Quantity = receiveDoc.QuantityLeft = quantity * itemUnit.QtyPerUnit;
            receiveDoc.NoOfPack = receiveDoc.InvoicedNoOfPack = quantity;
            receiveDoc.QtyPerPack = itemUnit.QtyPerUnit;
            receiveDoc.SetColumn("ExpDate", inventory.GetColumn("ExpiryDate"));

            receiveDoc.Out = false;

            receiveDoc.ReceivedBy = user.UserName;

            receiveDoc.StoreID = inventory.ActivityID;
            receiveDoc.RefNo = "BeginningBalance";
            decimal cost = 0;
            decimal margin = 0;

            if (!inventory.IsColumnNull("Cost"))
            {
                cost = inventory.Cost;
            }

            if(!inventory.IsColumnNull("Margin"))
            {
                margin = inventory.Margin;
            }

            receiveDoc.Cost = Convert.ToDouble(cost);
            receiveDoc.PricePerPack = Convert.ToDouble(cost);
            receiveDoc.UnitCost = cost;
            receiveDoc.Margin = Convert.ToDouble(margin);
            receiveDoc.SellingPrice = Convert.ToDouble(BLL.Settings.IsCenter ? cost : cost * (1 + margin));
            receiveDoc.SupplierID = 2; //TODO: HARDCODE WARNING WARNING WARNING
            receiveDoc.DeliveryNote = false;
            receiveDoc.Confirmed = true;
            receiveDoc.ConfirmedDateTime = DateTimeHelper.ServerDateTime;
            receiveDoc.ReturnedStock = false;
            receiveDoc.ReceiptID = receiptID;
            receiveDoc.RefNo = "BeginningBalance";
            receiveDoc.InventoryPeriodID = inventory.InventoryPeriodID;
            receiveDoc.IsDamaged = (quantityType == Inventory.QuantityType.Damaged ||
                                   quantityType == Inventory.QuantityType.Expired);
            receiveDoc.Save();

            //Now Save the ReceiveDocConfirmation

            ReceiveDocConfirmation rdConf = new ReceiveDocConfirmation();
            rdConf.AddNew();
            rdConf.ReceiveDocID = receiveDoc.ID;
            rdConf.ReceivedByUserID = user.ID;
            rdConf.ReceiptConfirmationStatusID = ReceiptConfirmationStatus.Constants.RECEIVE_QUANTITY_CONFIRMED;
            rdConf.Save();

            //TODO: Create Receive Pallet Here
            PalletLocation palletLocation = new PalletLocation();

            palletLocation.LoadByPrimaryKey(quantityType != Inventory.QuantityType.Damaged
                                                ? inventory.PalletLocationID
                                                : inventory.DamagedPalletLocationID);

            ReceivePallet receivePallet = new ReceivePallet();
            receivePallet.AddNew();
            receivePallet.Balance = quantity * itemUnit.QtyPerUnit;
            receivePallet.ReceivedQuantity = quantity * itemUnit.QtyPerUnit;
            receivePallet.ReservedStock = 0;
            receivePallet.ReceiveID = receiveDoc.ID;

            if(palletLocation.IsColumnNull("PalletID"))
            {
                Pallet pallet = new Pallet();
                pallet.AddNew();
                pallet.Save();
                palletLocation.PalletID = pallet.ID;
                palletLocation.Save();
            }

            receivePallet.PalletID = palletLocation.PalletID;
            receivePallet.PalletLocationID =palletLocation.ID;
            receivePallet.BoxSize = 0;
            receivePallet.IsOriginalReceive = true;
            receivePallet.Save();

            return receiveDoc;
        }
        public void CloneReceiveForErrorCorrection(int confirmationStatusID, ReceivePallet receivePallet, ReceiveDoc receiveDoc, decimal pack, User user, int itemId, int storeId, int receiptId, int manufacturerId, ItemUnit itemUnit, DateTime convertedEthDate, bool changeExpiryDate = false, DateTime? ExpiryDate = null, bool changeBatchNo = false, string batchNo = null)
        {
            var newReceiveDoc = receiveDoc.Clone();

            newReceiveDoc.ItemID = itemId;

            if (changeBatchNo)
            {
                newReceiveDoc.BatchNo = batchNo;
            }

            if (changeExpiryDate)
            {
                if (ExpiryDate.HasValue)
                {
                    newReceiveDoc.ExpDate = ExpiryDate.Value;
                }
                else
                {
                    newReceiveDoc.SetColumnNull("ExpDate");
                }
            }

            newReceiveDoc.ManufacturerId = manufacturerId;
            newReceiveDoc.SetColumn("UnitID", itemUnit.ID);
            newReceiveDoc.Quantity = pack * itemUnit.QtyPerUnit;
            newReceiveDoc.QuantityLeft = pack * itemUnit.QtyPerUnit;
            newReceiveDoc.NoOfPack = pack;
            newReceiveDoc.InvoicedNoOfPack = pack;
            newReceiveDoc.QtyPerPack = itemUnit.QtyPerUnit;
            newReceiveDoc.Date = convertedEthDate;
            newReceiveDoc.ReceivedBy = user.UserName;
            newReceiveDoc.StoreID = storeId;
            newReceiveDoc.RefNo = receiptId.ToString();
            newReceiveDoc.EurDate = DateTimeHelper.ServerDateTime;
            newReceiveDoc.Confirmed = true;
            newReceiveDoc.ConfirmedDateTime = DateTimeHelper.ServerDateTime;
            newReceiveDoc.ReturnedStock = false;
            newReceiveDoc.ReceiptID = receiptId;

            newReceiveDoc.Save();

            //Now Save the ReceiveDocConfirmation

            ReceiveDocConfirmation rdConf = new ReceiveDocConfirmation();
            rdConf.AddNew();
            rdConf.ReceiveDocID = newReceiveDoc.ID;
            rdConf.ReceivedByUserID = user.ID;
            rdConf.ReceiptConfirmationStatusID = confirmationStatusID;
            rdConf.Save();

            ReceivePallet newReceivePallet = new ReceivePallet();
            newReceivePallet.AddNew();
            newReceivePallet.ReceiveID = newReceiveDoc.ID;
            newReceivePallet.ReceivedQuantity = pack * itemUnit.QtyPerUnit;
            newReceivePallet.Balance = pack * itemUnit.QtyPerUnit;
            newReceivePallet.ReservedStock = 0;
            newReceivePallet.BoxSize = 0;
            newReceivePallet.PalletID = receivePallet.PalletID;
            newReceivePallet.IsOriginalReceive = true;
            if (!receivePallet.IsColumnNull("PalletLocationID"))
            {
                newReceivePallet.PalletLocationID = receivePallet.PalletLocationID;
            }
            newReceivePallet.Save();
        }