예제 #1
0
        public void RepairCOGS(Session session, Guid COGSId)
        {
            COGS currentCOGS = session.GetObjectByKey <COGS>(COGSId);

            if (currentCOGS == null)
            {
                return;
            }
            if (currentCOGS.InventoryTransactionId is InventoryTransactionBalanceForward)
            {
                currentCOGS.Amount    = 0;
                currentCOGS.Total     = currentCOGS.Balance * currentCOGS.Price;
                currentCOGS.COGSPrice = currentCOGS.Price;
                currentCOGS.Save();
                return;
            }
            COGS previousCOGS = GetPreviousCOGS(session, COGSId);

            if (previousCOGS == null)
            {
                if (currentCOGS.Debit == 0 && currentCOGS.Credit != 0)
                {
                    currentCOGS.Balance = currentCOGS.Debit - currentCOGS.Credit;
                    currentCOGS.Save();
                    return;
                }
                else if (currentCOGS.Debit != 0 && currentCOGS.Credit == 0)
                {
                    currentCOGS.Balance   = currentCOGS.Debit - currentCOGS.Credit;
                    currentCOGS.Amount    = currentCOGS.Price * currentCOGS.Debit;
                    currentCOGS.Total     = currentCOGS.Balance * currentCOGS.Price;
                    currentCOGS.COGSPrice = currentCOGS.Price;
                    currentCOGS.Save();
                }
                else if (currentCOGS.Debit == 0 && currentCOGS.Credit == 0)
                {
                    currentCOGS.Amount    = currentCOGS.Price * currentCOGS.Balance;
                    currentCOGS.Total     = currentCOGS.Amount;
                    currentCOGS.COGSPrice = currentCOGS.Price;
                    currentCOGS.Save();
                }
            }
            else
            {
                currentCOGS.Balance = previousCOGS.Balance + currentCOGS.Debit - currentCOGS.Credit;
                if (currentCOGS.Debit == 0 && currentCOGS.Credit != 0)
                {
                    currentCOGS.Price = previousCOGS.COGSPrice;
                }
                currentCOGS.Amount    = currentCOGS.Price * (currentCOGS.Debit - currentCOGS.Credit);
                currentCOGS.Total     = previousCOGS.Total + currentCOGS.Amount;
                currentCOGS.COGSPrice = currentCOGS.Total / currentCOGS.Balance;
                currentCOGS.Save();
            }
        }
예제 #2
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();
        }
예제 #3
0
        public void CreateInitCOGS(Session session, ItemUnit itemUnit, CurrencyType currencyType)
        {
            if (IsExistCOGS(session, itemUnit, currencyType))
            {
                return;
            }
            COGS result = new COGS(session);

            try
            {
                CriteriaOperator criteria   = new BinaryOperator("IsDefault", true, BinaryOperatorType.Equal);
                CriteriaOperator criteria_0 = new BinaryOperator("Code", "NAAN_DEFAULT", BinaryOperatorType.Equal);
                Currency         currency   = new XPCollection <Currency>(session, currencyType.Currencies, criteria).FirstOrDefault();
                if (currency != null)
                {
                    result.Amount      = 0;
                    result.Assumption  = 1;
                    result.Balance     = 0;
                    result.COGSPrice   = 0;
                    result.CreateDate  = DateTime.Now;
                    result.Credit      = 0;
                    result.CurrencyId  = currency;
                    result.Debit       = 0;
                    result.Description = "";
                    result.InventoryId = session.FindObject <NAS.DAL.Nomenclature.Inventory.Inventory>(criteria_0);
                    result.IsOriginal  = true;
                    result.IssueDate   = DateTime.Now;
                    result.ItemUnitId  = itemUnit;
                    result.Price       = 0;
                    result.Total       = 0;
                    result.UpdateDate  = DateTime.Now;
                    result.Save();
                }
            }
            catch (Exception)
            {
                return; // result;
            }
            return;     // result;
        }