Пример #1
0
        public void BeforeApplyChanges(EntityDbHelper dbHelper, Entity entity)
        {
            base.BeforeApplyChanges(dbHelper, entity);

            //DebugHelper.Break();

            var salesCaseStatus_OpenID = OptionSetHelper.GetOptionSetItemID("crm.SalesCaseStatuses", "Open");
            var salesCaseStatus_WonID  = OptionSetHelper.GetOptionSetItemID("crm.SalesCaseStatuses", "Won");

            if (entity.ChangeStatus == "Delete" ||
                entity.FieldValues["Status"].ToString() == salesCaseStatus_OpenID.ToString() ||
                entity.FieldValues["Status"].ToString() == salesCaseStatus_WonID.ToString())
            {
                var salesCaseLoseInfoEntity = dbHelper.FetchSingle("crm.SalesCaseLoseInfo",
                                                                   string.Format(@"SalesCase = '{0}'", entity.GetFieldValue <Guid>("ID")), null);
                if (salesCaseLoseInfoEntity != null)
                {
                    dbHelper.DeleteEntity(salesCaseLoseInfoEntity);
                }
            }

            if (entity.ChangeStatus == "Delete")
            {
                var salesCaseStageChangeHistoryEntityList = dbHelper.FetchMultiple("crm.SalesCaseStageChangeHistory",
                                                                                   string.Format(@"SalesCase = '{0}'", entity.GetFieldValue <Guid>("ID")), null, null, null, null);
                if (salesCaseStageChangeHistoryEntityList.Entities.Count != 0)
                {
                    foreach (Entity salesCaseStageChangeHistoryEntity in salesCaseStageChangeHistoryEntityList.Entities)
                    {
                        dbHelper.DeleteEntity(salesCaseStageChangeHistoryEntity);
                    }
                }

                var salesCaseOwnerUserChangeHistoryEntityList = dbHelper.FetchMultiple("crm.SalesCaseOwnerUserChangeHistory",
                                                                                       string.Format(@"SalesCase = '{0}'", entity.GetFieldValue <Guid>("ID")), null, null, null, null);
                if (salesCaseOwnerUserChangeHistoryEntityList.Entities.Count != 0)
                {
                    foreach (Entity salesCaseOwnerUserChangeHistoryEntity in salesCaseOwnerUserChangeHistoryEntityList.Entities)
                    {
                        dbHelper.DeleteEntity(salesCaseOwnerUserChangeHistoryEntity);
                    }
                }

                var salesCaseStatusChangeHistoryEntityList = dbHelper.FetchMultiple("crm.SalesCaseStatusChangeHistory",
                                                                                    string.Format(@"SalesCase = '{0}'", entity.GetFieldValue <Guid>("ID")), null, null, null, null);
                if (salesCaseStatusChangeHistoryEntityList.Entities.Count != 0)
                {
                    foreach (Entity salesCaseStatusChangeHistoryEntity in salesCaseStatusChangeHistoryEntityList.Entities)
                    {
                        dbHelper.DeleteEntity(salesCaseStatusChangeHistoryEntity);
                    }
                }
            }
        }
Пример #2
0
        public override void BeforeApplyChanges(EntityDbHelper dbHelper, Entity entity)
        {
            base.BeforeApplyChanges(dbHelper, entity);

            if (entity.ChangeStatus == EntityChangeTypes.Delete)
            {
                var workflowDefID            = entity.GetFieldValue <Guid>("ID");
                var workflowStageOrgPostions = dbHelper.FetchMultiple("cmn.WorkflowStageOrgPostion",
                                                                      string.Format("WorkflowDef = '{0}'", workflowDefID.ToString()), null, null, null, null).Entities;

                foreach (Entity workflowStageOrgPostion in workflowStageOrgPostions)
                {
                    dbHelper.DeleteEntity(workflowStageOrgPostion);
                }
            }

            if (entity.ChangeStatus != EntityChangeTypes.Delete)
            {
                var workflowFormID = entity.GetFieldValue <Guid>("WorkflowForm");

                if (dbHelper.EntityExists("cmn.WorkflowDef",
                                          string.Format("WorkflowForm = '{0}' and ID <> '{1}'",
                                                        workflowFormID, entity.GetFieldValue <Guid>("ID"))))
                {
                    throw new AfwException("برای این فرم، گردش کار دیگری تعریف شده است.");
                }
            }
        }
Пример #3
0
        public override void AfterApplyChanges(EntityDbHelper dbHelper, Entity entity)
        {
            base.AfterApplyChanges(dbHelper, entity);

            //در صورت تیک خوردن تنظیمات در گروه فرعی، تیک ها در تعریف کالا ها هم زده می شوند.
            if (entity.ChangeStatus.IsIn(EntityChangeTypes.Add, EntityChangeTypes.Modify))
            {
                var stuffDefs = dbHelper.FetchMultiple("cmn.StuffDef", string.Format("SubCategory = '{0}'", entity.GetFieldValue <Guid>("ID")), null, null, null, null).Entities;

                foreach (var stuffDef in stuffDefs)
                {
                    if (entity.GetFieldValue <bool>("HideInProforma") == true)
                    {
                        stuffDef.SetFieldValue("HideInProforma", true);
                    }
                    if (entity.GetFieldValue <bool>("HideInInvoice") == true)
                    {
                        stuffDef.SetFieldValue("HideInInvoice", true);
                    }
                    if (entity.GetFieldValue <bool>("HideInStockTransfer") == true)
                    {
                        stuffDef.SetFieldValue("HideInStockTransfer", true);
                    }
                    if (entity.GetFieldValue <bool>("DarayeMaliatBarArzesheAfzudeh") == true)
                    {
                        stuffDef.SetFieldValue("DarayeMaliatBarArzesheAfzudeh", true);
                    }

                    dbHelper.UpdateEntity(stuffDef);
                }
            }
        }
Пример #4
0
        public override void BeforeApplyChanges(EntityDbHelper dbHelper, Entity entity)
        {
            base.BeforeApplyChanges(dbHelper, entity);

            if (entity.ChangeStatus == EntityChangeTypes.Add)
            {
                var lastOpNumber = cmn.Instance.GetFieldMaxIntValue("OpNumber", "wm_WarehouseHybridOperations", null);
                entity.SetFieldValue("OpNumber", lastOpNumber + 1);
            }

            if (entity.ChangeStatus.IsIn(EntityChangeTypes.Add, EntityChangeTypes.Modify))
            {
                foreach (var ghabzOrHavaleItem in entity.GetFieldValue <EntityList>("WarehouseHybridOperationItems").Entities)
                {
                    if (ghabzOrHavaleItem.FieldExists("Stuff_Entity"))
                    {
                        ghabzOrHavaleItem.RemoveField("Stuff_Entity");
                    }
                }
            }

            if (entity.ChangeStatus == EntityChangeTypes.Delete)
            {
                var ghabzOrHavaleList = dbHelper.FetchMultiple("wm.GhabzOrHavale",
                                                               string.Format("RefDoc_WarehouseHybridOperation = '{0}'", entity.GetFieldValue <Guid>("ID")),
                                                               null, null, null, null);

                foreach (var ghabzOrHavale in ghabzOrHavaleList.Entities)
                {
                    dbHelper.DeleteEntity(ghabzOrHavale);
                }
            }
        }
Пример #5
0
        public override void BeforeApplyChanges(EntityDbHelper dbHelper, Entity entity)
        {
            base.BeforeApplyChanges(dbHelper, entity);

            //DebugHelper.Break();

            if (entity.ChangeStatus != EntityChangeTypes.Delete)
            {
                var workflowDefID  = entity.GetFieldValue <Guid>("WorkflowDef");
                var stageOrder     = entity.GetFieldValue <int>("StageOrder");
                var systemActionID = entity.GetFieldValue <Guid?>("SystemAction");

                var workflowStages = dbHelper.FetchMultiple("cmn.WorkflowStage",
                                                            string.Format("WorkflowDef = '{0}'", workflowDefID), null, null, null, null).Entities;

                if (workflowStages.Any(o => o.GetFieldValue <int>("StageOrder") == stageOrder &&
                                       o.GetFieldValue <Guid>("ID") != entity.GetFieldValue <Guid>("ID")))
                {
                    throw new AfwException("شماره مرحله تکراری است.");
                }

                if (systemActionID != null &&
                    workflowStages.Any(o => o.GetFieldValue <Guid?>("SystemAction") == systemActionID &&
                                       o.GetFieldValue <Guid>("ID") != entity.GetFieldValue <Guid>("ID")))
                {
                    throw new AfwException("این عمیلات سیستمی برای مرحله دیگری انتخاب شده است.");
                }
            }
        }
Пример #6
0
        public override void AfterApplyChanges(EntityDbHelper dbHelper, Entity entity)
        {
            base.AfterApplyChanges(dbHelper, entity);

            if (entity.ChangeStatus == EntityChangeTypes.Delete)
            {
                return;
            }

            var relatedReserveItem   = entity.GetFieldValue <Guid>("ID");
            var relatedReserveEntity = entity;

            if (entity.GetFieldValue <Guid?>("Unreserve_RelatedReserveItem") != null)
            {
                relatedReserveItem   = entity.GetFieldValue <Guid>("Unreserve_RelatedReserveItem");
                relatedReserveEntity = dbHelper.FetchSingleByID("wm.WarehouseInventoryReserveListItem", relatedReserveItem, null);
            }
            var unreserve_RelatedItems = dbHelper.FetchMultiple("wm.WarehouseInventoryReserveListItem",
                                                                string.Format("Unreserve_RelatedReserveItem = '{0}'", relatedReserveItem), null, null, null, null);

            var quantitySum = 0;

            for (int i = 0; i < unreserve_RelatedItems.Entities.Count; i++)
            {
                quantitySum += unreserve_RelatedItems.Entities[i].GetFieldValue <int>("Quantity");
            }

            if (quantitySum > relatedReserveEntity.GetFieldValue <int>("Quantity"))
            {
                throw new AfwException("تعداد کل کالاهای برگشتی این رزرو بیشتر از تعداد اولیه رزرو است");
            }
        }
Пример #7
0
        public override void BeforeApplyChanges(EntityDbHelper dbHelper, Entity entity)
        {
            base.BeforeApplyChanges(dbHelper, entity);

            //DebugHelper.Break();

            if (entity.ChangeStatus == EntityChangeTypes.Delete)
            {
                var personRoleRelations = dbHelper.FetchMultiple("cmn.PersonRoleRelation", string.Format("Person = '{0}'", entity.FieldValues["ID"].ToString()), null, null, null, null);
                foreach (Entity personRoleRelationEntity in personRoleRelations.Entities)
                {
                    dbHelper.DeleteEntity(personRoleRelationEntity);
                }

                var roles = dbHelper.FetchMultiple("cmn.PersonRole", null, null, null, null, null).Entities;
                foreach (var role in roles)
                {
                    var roleName       = role.GetFieldValue <string>("Name");
                    var roleInfoEntity = dbHelper.FetchSingle("cmn.Person_" + roleName + "Info", string.Format("Person = '{0}'", entity.FieldValues["ID"].ToString()), null);

                    if (roleInfoEntity != null)
                    {
                        dbHelper.DeleteEntity(roleInfoEntity);
                    }
                }

                var personGroupRelations = dbHelper.FetchMultiple("cmn.PersonGroupRelation", string.Format("Person = '{0}'", entity.FieldValues["ID"].ToString()), null, null, null, null);
                foreach (Entity personGroupRelationEntity in personGroupRelations.Entities)
                {
                    dbHelper.DeleteEntity(personGroupRelationEntity);
                }
            }
            else
            {
                entity.SetFieldValue("StoredDisplayText", CalculateStoredDisplayText(entity));
            }

            //else if(entity.ChangeStatus == EntityChangeTypes.Add)
            //{
            //    //var entityList = AreExistPersonCodes(dbHelper, entity);
            //    //if (entityList != null)

            //}
        }
Пример #8
0
        public void BeforeApplyChanges(EntityDbHelper dbHelper, Entity entity)
        {
            base.BeforeApplyChanges(dbHelper, entity);

            using (var tranManager = new DbTransactionManager(dbHelper))
            {
                if (entity.ChangeStatus == EntityChangeTypes.Modify)
                {
                    var leadEntity    = dbHelper.FetchSingleByID("crm.Lead", entity.GetFieldValue <Guid>("ID"), null);
                    var workflowStage = leadEntity.GetFieldValue <Guid?>("WorkflowStage");

                    var newWorkflowStage = entity.GetFieldValue <Guid?>("WorkflowStage");

                    if (workflowStage != newWorkflowStage)
                    {
                        var workflowStageEntity = dbHelper.FetchSingle("cmn.WorkflowStage", string.Format("ID = '{0}'", workflowStage.ToString()), null);
                        var workflowDef         = dbHelper.FetchSingle("cmn.WorkflowDef", string.Format("ID = '{0}'", workflowStageEntity.GetFieldValue <Guid>("WorkflowDef").ToString()), null);
                        var systemAction        = workflowStageEntity.GetFieldValue <Guid?>("SystemAction");

                        if (systemAction != null)
                        {
                            //DebugHelper.Break();
                            var systemActionEntity = dbHelper.FetchSingle("cmn.WorkfolwSystemAction", string.Format("ID = '{0}'", systemAction), null);
                            var stages             = dbHelper.FetchMultiple("cmn.WorkflowStage", string.Format("WorkflowDef = '{0}'", workflowDef.GetFieldValue <Guid>("ID")), "StageOrder", null, null, null);
                            for (int i = 0; i < stages.Entities.Count(); i++)
                            {
                                if (stages.Entities[i].GetFieldValue <Guid>("ID") == workflowStage)
                                {
                                    if (stages.Entities[i + 1].GetFieldValue <Guid>("ID") == newWorkflowStage)
                                    {
                                        var systemActionName = systemActionEntity.GetFieldValue <string>("Name");
                                        if (systemActionName == "CreateSalesCase")
                                        {
                                            ValidateLeadForQualify(entity);
                                            DoQualifyLead(entity);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                tranManager.Commit();
            }
        }
        public override void BeforeApplyChanges(EntityDbHelper dbHelper, Entity entity)
        {
            base.BeforeApplyChanges(dbHelper, entity);

            if (entity.ChangeStatus != EntityChangeTypes.Delete)
            {
                var workflowStageID = entity.GetFieldValue <Guid>("WorkflowStage");
                var orgPostionID    = entity.GetFieldValue <Guid>("OrgPostion");

                var workflowStageOrgPostions = dbHelper.FetchMultiple("cmn.WorkflowStageOrgPostion",
                                                                      string.Format("WorkflowStage = '{0}'", workflowStageID), null, null, null, null).Entities;

                if (workflowStageOrgPostions.Any(o => o.GetFieldValue <Guid>("WorkflowStage") == workflowStageID &&
                                                 o.GetFieldValue <Guid>("OrgPostion") == orgPostionID &&
                                                 o.GetFieldValue <Guid>("ID") != entity.GetFieldValue <Guid>("ID")))
                {
                    throw new AfwException("این رکورد قبلا ثبت شده است.");
                }
            }
        }
Пример #10
0
        public override void AfterApplyChanges(EntityDbHelper dbHelper, Entity entity)
        {
            base.AfterApplyChanges(dbHelper, entity);

            var accDocID = entity.GetFieldValue <Guid>("AccDoc");

            if (entity.ChangeStatus.IsIn(EntityChangeTypes.Add, EntityChangeTypes.Modify))
            {
                var refOpFieldName = GetRefOpFieldName(entity);
                if (refOpFieldName != null)
                {
                    var existingDocItem = dbHelper.FetchMultiple("acc.AccDocItem",
                                                                 string.Format("{0} = '{1}' and ID <> '{2}' and AccDoc <> '{3}'",
                                                                               refOpFieldName,
                                                                               entity.GetFieldValue <Guid>(refOpFieldName),
                                                                               entity.GetFieldValue <Guid>("ID"),
                                                                               accDocID),
                                                                 null, 1, 1, new string[] { "AccDoc" });

                    if (existingDocItem.Entities.Count > 0)
                    {
                        throw new AfwException("سند حسابداری با شماره مرجع {0} برای این عملیات موجود است.",
                                               existingDocItem.Entities[0].GetFieldValue <Entity>("AccDoc_Entity").GetFieldValue <int>("DocNo"));
                    }
                }
            }

            if (entity.ChangeStatus.IsIn(EntityChangeTypes.Add, EntityChangeTypes.Delete))
            {
                var query = string.Format(@"
                    update AccDocItem
                    set RowNo = NewSortedRowNo
                    from (
                           select RowNo, row_number() over(order by CreationTime) as NewSortedRowNo
                           from acc_AccDocItems
	                       where AccDoc = '{0}'
                    ) AccDocItem", accDocID);

                dbHelper.AdoDbHelper.ExecuteNonQuery(query);
            }
        }
Пример #11
0
        //public void CreateReceiveReceipt(string payedAmount, string payType, string issueDate, string bankName, Guid customerID, EntityDbHelper dbHelper)
        //{
        //    // Create ReceiveReceipt
        //    var financialYearID = new FinancialYearBL().GetUserActiveFinancialYearID();
        //    var financialGroupID = dbHelper.FetchMultiple("cmn.FinancialGroup", "IsDefault = 1", null, null, null, null).Entities[0].GetFieldValue<Guid>("ID");
        //    var lastReceiptNumber = cmn.Instance.GetFieldMaxIntValue("ReceiptNumber", "rp_ReceiveReceipts", string.Format("FinancialYear = '{0}'", financialYearID));

        //    var receiveReceipt = dbHelper.CreateNewEntity("rp.ReceiveReceipt");
        //    receiveReceipt.SetFieldValue("FinancialYear", financialYearID);
        //    receiveReceipt.SetFieldValue("FinancialGroup", financialGroupID);
        //    receiveReceipt.SetFieldValue("Payer", customerID);
        //    receiveReceipt.SetFieldValue("ReceiptDate", issueDate);
        //    receiveReceipt.SetFieldValue("TotalAmount", payedAmount);
        //    receiveReceipt.SetFieldValue("Description", "رسید دریافت از طریق وب سرویس ترازنگار");
        //    receiveReceipt.SetFieldValue("ReceiptNumber", lastReceiptNumber + 1);

        //    dbHelper.ApplyChanges(receiveReceipt);

        //    // Create ReceiveReceiptItems

        //    var receiveReceiptItem = dbHelper.CreateNewEntity("rp.ReceiveReceiptItem");
        //    receiveReceiptItem.SetFieldValue("ReceiveReceipt", receiveReceipt.GetFieldValue<Guid>("ID"));

        //    var receiveType = dbHelper.FetchSingle("rp.ReceiveType", string.Format("Name = '{0}'", payType), null);

        //    if (payType == "Havale")
        //    {
        //        if (receiveType != null)
        //        {
        //            var receiveTypeID = receiveType.GetFieldValue<Guid>("ID");
        //            receiveReceiptItem.SetFieldValue("ReceiveType", receiveTypeID);

        //            var financialOpKind = dbHelper.FetchSingle("sacc.FinancialOpKind", "Name = 'VarizBeSaderat'", null);
        //            if (financialOpKind != null)
        //            {
        //                var financialOpKindID = financialOpKind.GetFieldValue<Guid>("ID");
        //                receiveReceiptItem.SetFieldValue("FinancialOpKind", financialOpKindID);

        //                var naghdeDaryafti = dbHelper.CreateNewEntity("rp.NaghdeDaryafti");
        //                receiveReceiptItem.SetFieldValue("FinancialItem_Naghd", naghdeDaryafti.GetFieldValue<Guid>("ID"));

        //                var cash = dbHelper.FetchMultiple("sacc.Cash", null, null, null, null, null);
        //                naghdeDaryafti.SetFieldValue("Payer", customerID);
        //                naghdeDaryafti.SetFieldValue("Amount", payedAmount);
        //                naghdeDaryafti.SetFieldValue("Cash", cash.Entities[0].GetFieldValue<Guid>("ID"));

        //                naghdeDaryafti.SetFieldValue("Description", "دریافت نقدی از طریق وب سرویس");

        //                dbHelper.ApplyChanges(naghdeDaryafti);
        //                dbHelper.ApplyChanges(receiveReceiptItem);
        //            }
        //        }
        //    }
        //    else if (payType == "Naghd")
        //    {
        //        if (receiveType != null)
        //        {
        //            var receiveTypeID = receiveType.GetFieldValue<Guid>("ID");
        //            receiveReceiptItem.SetFieldValue("ReceiveType", receiveTypeID);

        //            var financialOpKind = dbHelper.FetchSingle("sacc.FinancialOpKind", "Name = 'DaryaftNaghdi'", null);
        //            if (financialOpKind != null)
        //            {
        //                var financialOpKindID = financialOpKind.GetFieldValue<Guid>("ID");
        //                receiveReceiptItem.SetFieldValue("FinancialOpKind", financialOpKindID);

        //                var naghdeDaryafti = dbHelper.CreateNewEntity("rp.NaghdeDaryafti");
        //                receiveReceiptItem.SetFieldValue("FinancialItem_Naghd", naghdeDaryafti.GetFieldValue<Guid>("ID"));

        //                var cash = dbHelper.FetchMultiple("sacc.Cash", null, null, null, null, null);
        //                naghdeDaryafti.SetFieldValue("Payer", customerID);
        //                naghdeDaryafti.SetFieldValue("Amount", payedAmount);
        //                naghdeDaryafti.SetFieldValue("Cash", cash.Entities[0].GetFieldValue<Guid>("ID"));

        //                naghdeDaryafti.SetFieldValue("Description", "دریافت نقدی از طریق وب سرویس");

        //                dbHelper.ApplyChanges(naghdeDaryafti);
        //                dbHelper.ApplyChanges(receiveReceiptItem);
        //            }
        //        }
        //    }



        //}

        public void CreateAccDoc(Entity accDocEntity, decimal payedAmount, string issueDate, EntityDbHelper dbHelper)
        {
            var balanceStatusID = OptionSetHelper.GetOptionSetItemID("acc.BalanceStatus", "Balance");
            var docStatusID     = OptionSetHelper.GetOptionSetItemID("acc.DocStatus", "NotChecked");

            var docKindID        = new DocKindBL().GetDocKindID("ComposeDoc");
            var financialYearID  = new FinancialYearBL().GetUserActiveFinancialYearID();
            var financialGroupID = dbHelper.FetchMultiple("cmn.FinancialGroup", "IsDefault = 1", null, null, null, null).Entities[0].GetFieldValue <Guid>("ID");

            accDocEntity.SetFieldValue("IssueDate", issueDate);
            accDocEntity.SetFieldValue("FinancialYear", financialYearID);
            accDocEntity.SetFieldValue("FinancialGroup", financialGroupID);
            accDocEntity.SetFieldValue("DocKind", docKindID);
            accDocEntity.SetFieldValue("IsAutoGenerated", false);
            accDocEntity.SetFieldValue("BalanceStatus", balanceStatusID);
            accDocEntity.SetFieldValue("DocStatus", docStatusID);
            accDocEntity.SetFieldValue("RemainingAmount", payedAmount);
            accDocEntity.SetFieldValue("IsActive", 1);
            accDocEntity.SetFieldValue("Description", "سند تولید شده از طریق وب سرویس");
            dbHelper.ApplyChanges(accDocEntity);
        }
        public override void BeforeApplyChanges(EntityDbHelper dbHelper, Entity entity)
        {
            base.BeforeApplyChanges(dbHelper, entity);

            if (entity.ChangeStatus == EntityChangeTypes.Add)
            {
                var lastOpNumber = cmn.Instance.GetFieldMaxIntValue("OpNumber", "wm_StuffStatusChangeAndTransfers", null);
                entity.SetFieldValue("OpNumber", lastOpNumber + 1);
            }

            if (entity.ChangeStatus.IsIn(EntityChangeTypes.Add, EntityChangeTypes.Modify))
            {
                foreach (var ghabzOrHavaleItem in entity.GetFieldValue <EntityList>("StuffStatusChangeAndTransferItems").Entities)
                {
                    if (ghabzOrHavaleItem.FieldExists("Stuff_Entity"))
                    {
                        ghabzOrHavaleItem.RemoveField("Stuff_Entity");
                    }
                }
            }

            if (entity.ChangeStatus == EntityChangeTypes.Delete)
            {
                var ghabzOrHavaleEntityList = dbHelper.FetchMultiple("wm.GhabzOrHavale",
                                                                     string.Format("RefDoc_StuffStatusChangeAndTransfer = '{0}'", entity.GetFieldValue <Guid>("ID")), null, null, null, null).Entities;
                foreach (var ghabzOrHavale in ghabzOrHavaleEntityList)
                {
                    dbHelper.DeleteEntity(ghabzOrHavale);
                }
            }

            if (entity.ChangeStatus == EntityChangeTypes.Delete)
            {
                //acc.Instance.DeleteAccDocDetail(entity.GetFieldValue<Guid?>("AccDoc"), "RefOp_StuffStatusChangeAndTransfer", invoiceID);
            }
        }
Пример #13
0
        public Entity FetchOrCreateStuff(ref Entity stuffMainCategory, string stuffCode, string stuffName, EntityDbHelper dbHelper)
        {
            var stuffEntity = dbHelper.CreateNewEntity("cmn.Stuff");

            var stuffDefEntity = dbHelper.FetchSingle("cmn.StuffDef", string.Format("Code = '{0}' and Name = N'{1}'", stuffCode, stuffName), null);

            if (stuffDefEntity == null)
            {
                // دریافت گروه های اصلی کالا که کدینگ حسابداری برای آنها ثبت شده است
                var stuffMainCategoryEntityList = dbHelper.FetchMultiple("cmn.StuffMainCategory", "Account is not null", null, null, null, null);
                if (stuffMainCategoryEntityList.Entities.Count > 0)
                {
                    // اولین گروه اصلی کالا که کدینگ حسابداری برای آن ثبت شده است
                    stuffMainCategory = stuffMainCategoryEntityList.Entities[0];
                    var stuffMainCategoryFirstID = stuffMainCategory.GetFieldValue <Guid>("ID");

                    // دریافت گروه های فرعی کالا که کدینگ حسابداری دارند
                    var stuffSubCategoryEntityList = dbHelper.FetchMultiple("cmn.StuffSubCategory",
                                                                            string.Format("MainCategory = '{0}'", stuffMainCategoryFirstID), null, null, null, null);

                    var mainMeasurementUnitEntityList = dbHelper.FetchMultiple("cmn.MeasurementUnit", null, null, null, null, null);

                    if (stuffSubCategoryEntityList.Entities.Count > 0 && mainMeasurementUnitEntityList.Entities.Count > 0)
                    {
                        // شناسه اولین گروه فرعی کالا
                        var subCategoryID = stuffSubCategoryEntityList.Entities[0].GetFieldValue <Guid>("ID");
                        // شناسه اولین واحد کالا
                        var mainMeasurementUnitID = mainMeasurementUnitEntityList.Entities[0].GetFieldValue <Guid>("ID");

                        var newStuffDef = dbHelper.CreateNewEntity("cmn.StuffDef");
                        newStuffDef.SetFieldValue("Code", stuffCode);
                        newStuffDef.SetFieldValue("Name", stuffName);
                        newStuffDef.SetFieldValue("HideInProforma", 0);
                        newStuffDef.SetFieldValue("HideInInvoice", 0);
                        newStuffDef.SetFieldValue("HideInStockTransfer", 0);
                        newStuffDef.SetFieldValue("DarayeMaliatBarArzesheAfzudeh", 0);
                        newStuffDef.SetFieldValue("SetUnitPriceOnlyFromPricesList", 0);
                        newStuffDef.SetFieldValue("SubCategory", subCategoryID);
                        newStuffDef.SetFieldValue("MainMeasurementUnit", mainMeasurementUnitID);
                        dbHelper.ApplyChanges(newStuffDef);

                        // فعلا در نرم افزار به ازای یک تعریف کالا یک کالا نیز وجود دارد که ما اولین آیتم آن را برمیگردانیم که بعدا قرار است یک لیست برگردانده شود
                        var stuffList = dbHelper.FetchMultiple("cmn.Stuff", string.Format("StuffDef = '{0}'", stuffDefEntity.GetFieldValue <Guid>("ID")), null, null, null, null);
                        stuffEntity = stuffList.Entities[0];
                    }
                }
            }
            else
            {
                // فعلا در نرم افزار به ازای یک تعریف کالا یک کالا نیز وجود دارد که ما اولین آیتم آن را برمیگردانیم که بعدا قرار است یک لیست برگردانده شود
                var stuffList = dbHelper.FetchMultiple("cmn.Stuff", string.Format("StuffDef = '{0}'", stuffDefEntity.GetFieldValue <Guid>("ID")), null, null, null, null);
                stuffEntity = stuffList.Entities[0];

                var subCategoryID    = stuffDefEntity.GetFieldValue <Guid>("SubCategory");
                var stuffSubCategory = dbHelper.FetchSingle("cmn.StuffSubCategory", string.Format("ID = '{0}'", subCategoryID), null);
                stuffMainCategory = dbHelper.FetchSingle("cmn.StuffMainCategory",
                                                         string.Format("ID = '{0}'", stuffSubCategory.GetFieldValue <Guid>("MainCategory")), null);
            }

            return(stuffEntity);
        }
Пример #14
0
        public override void BeforeApplyChanges(EntityDbHelper dbHelper, Entity entity)
        {
            if (wm.Instance.IsRunningUnvaluation)
            {
                LoadOldEntityOnBeforeApplyChanges = false;
            }

            base.BeforeApplyChanges(dbHelper, entity);

            if (wm.Instance.IsRunningUnvaluation)
            {
                return;
            }

            var vazeyatRialiNashodeID    = OptionSetHelper.GetOptionSetItemID("wm.VaziyatRialiAsnadAnbar", "RialiNashode");
            var vazeyatRialiSanadShodeID = OptionSetHelper.GetOptionSetItemID("wm.VaziyatRialiAsnadAnbar", "SanadShode");
            var oldGhabzOrHavaleEntity   = dbHelper.FetchSingleByID("wm.GhabzOrHavale", entity.GetFieldValue <Guid>("ID"), null);

            if (entity.ChangeStatus.IsIn(EntityChangeTypes.Delete, EntityChangeTypes.Modify))
            {
                if (oldGhabzOrHavaleEntity.GetFieldValue <Guid>("VazeyatRialiShodan") != vazeyatRialiNashodeID)
                {
                    wm.Instance.InventoryValuationBL.CheckValuationPermission();

                    if (entity.GetFieldValue <Guid>("VazeyatRialiShodan") == vazeyatRialiSanadShodeID &&
                        oldGhabzOrHavaleEntity.GetFieldValue <Guid>("VazeyatRialiShodan") != vazeyatRialiSanadShodeID &&
                        oldGhabzOrHavaleEntity.GetFieldValue <Guid?>("AccDoc") == null)
                    {
                        if (entity.GetFieldValue <Guid?>("AccDoc") == null)
                        {
                            throw new AfwException("AccDoc Is not set but VazeyatRialiShodan is set to 'SanadShode'");
                        }
                    }
                    else if (entity.GetFieldValue <Guid>("VazeyatRialiShodan") != vazeyatRialiNashodeID)
                    {
                        throw new AfwException("برای تغییر سند انبار ابتدا آن را از حالت ریالی خارج نمایید.");
                    }
                }
            }
            else if (entity.ChangeStatus == EntityChangeTypes.Add)
            {
                entity.SetFieldValue("VazeyatRialiShodan", vazeyatRialiNashodeID);
            }

            var ghabzOrHavaleTypeEntity = dbHelper.FetchSingleByID("wm.GhabzOrHavaleType", entity.GetFieldValue <Guid>("GhabzOrHavaleType"), null);
            var warehouseDocName        = OptionSetHelper.GetOptionSetItemName(ghabzOrHavaleTypeEntity.GetFieldValue <Guid>("WarehouseDocType"));
            var stuffLocationID         = entity.GetFieldValue <Guid?>("StuffLocation");

            if (entity.ChangeStatus != EntityChangeTypes.Delete)
            {
                CompareRefDocItemsWithGhabzOrHavaleItems(entity);
            }

            if (entity.ChangeStatus == EntityChangeTypes.Delete)
            {
                string masterOpName;
                Guid?  masterOpId;
                GetMasterOpInfo(entity, out masterOpName, out masterOpId);

                if (masterOpId != null && masterOpId != wm.Instance.DeletingOpID)
                {
                    var referenceDocTypeEntity = dbHelper.FetchSingleByID("wm.ReferenceDocType", entity.GetFieldValue <Guid>("ReferenceDocType"), null);
                    throw new AfwException("امکان حذف و ویرایش رسید/حواله مربوط به '{0}' وجود ندارد.", referenceDocTypeEntity.GetFieldValue <string>("Title"));
                }

                var dependedGhabzOrHavaleEntities = dbHelper.FetchMultiple("wm.GhabzOrHavale", string.Format("WareHouseDocRialiReference = '{0}'", entity.GetFieldValue <Guid>("ID")), null, null, null, null).Entities;

                if (dependedGhabzOrHavaleEntities.Count > 0)
                {
                    string ghabzOrHavaleNumbers = dependedGhabzOrHavaleEntities[0].GetFieldValue <int>("GhabzOrHavaleNumber").ToString();

                    for (int i = 1; i < dependedGhabzOrHavaleEntities.Count; i++)
                    {
                        ghabzOrHavaleNumbers += ", " + dependedGhabzOrHavaleEntities[i].GetFieldValue <int>("GhabzOrHavaleNumber");
                    }

                    throw new AfwException("امکان حذف به دلیل رفرنس ریالی بودن رسید/ حواله انتخاب شده وجود ندارد.\r\nابتدا رسید / حواله به {0} : {1} را حذف نمایید.",
                                           dependedGhabzOrHavaleEntities.Count > 1 ? "شماره های" : "شماره", ghabzOrHavaleNumbers);
                }
            }
        }
Пример #15
0
        public override void BeforeApplyChanges(EntityDbHelper dbHelper, Entity entity)
        {
            base.BeforeApplyChanges(dbHelper, entity);

            if (entity.ChangeStatus == EntityChangeTypes.Add)
            {
                var lastOpNumber = cmn.Instance.GetFieldMaxIntValue("OpNumber", "wm_MontageOrDemontages",
                                                                    string.Format("OpType = '{0}'", entity.GetFieldValue <Guid>("OpType")));
                entity.SetFieldValue("OpNumber", lastOpNumber + 1);
            }

            if (entity.ChangeStatus.IsIn(EntityChangeTypes.Add, EntityChangeTypes.Modify))
            {
                var stuffComponents = entity.GetFieldValue <EntityList>("StuffComponents").Entities;

                foreach (var stuffComponent in stuffComponents)
                {
                    if (stuffComponent.FieldExists("Stuff_Entity"))
                    {
                        stuffComponent.RemoveField("Stuff_Entity");
                    }
                }

                if (entity.GetFieldValue <Guid>("OpType") == OptionSetHelper.GetOptionSetItemID("wm.MontageOrDemontage", "Demontage"))
                {
                    int valuationPercentSum = 0;
                    foreach (var stuffComponent in stuffComponents)
                    {
                        if (stuffComponent.GetFieldValue <int?>("Demontage_ValuationPercent") == null)
                        {
                            throw new AfwException("درصد ریالی برای سطر {0} وارد نشده است.\r\nدرصد ریالی یا باید برای همه سطر ها وارد شود و یا برای هیچ سطری وارد نشود.", stuffComponent.GetFieldValue <int>("RowNumber"));
                        }

                        valuationPercentSum += stuffComponent.GetFieldValue <int>("Demontage_ValuationPercent");
                    }

                    if (valuationPercentSum != 100)
                    {
                        throw new AfwException("مجموع درصد ریالی اجزاء باید برابر با 100 باشد.");
                    }
                }
            }

            if (entity.ChangeStatus == EntityChangeTypes.Delete)
            {
                var ghabzOrHavaleEntities = dbHelper.FetchMultiple("wm.GhabzOrHavale",
                                                                   string.Format("RefDoc_MontageOp = '{0}' or RefDoc_DemontageOp = '{0}'",
                                                                                 entity.GetFieldValue <Guid>("ID")), null, null, null, null).Entities;

                var resid = ghabzOrHavaleEntities.FirstOrDefault(o => o.GetFieldValue <Guid?>("WareHouseDocRialiReference") != null);
                if (resid == null)
                {
                    throw new AfwException("resid of montage or demontage op not found.");
                }
                dbHelper.DeleteEntity(resid);

                var havale = ghabzOrHavaleEntities.FirstOrDefault(o => o.GetFieldValue <Guid?>("WareHouseDocRialiReference") == null);
                if (havale == null)
                {
                    throw new AfwException("havale of montage or demontage op not found.");
                }
                dbHelper.DeleteEntity(havale);
            }
        }